Library API
    Preparing search index...

    Function asText

    • Coerces a value to a cleaned, non-empty string. Returns the trimmed string if valid, otherwise returns undefined (or an optional fallback).

      Parameters

      • str: unknown

        The value to normalize

      Returns string | undefined

      The cleaned string or fallback

      asText('  hello  ');              // 'hello'
      asText(' '); // undefined
      asText(123); // undefined
      asText(' ', 'en-US'); // 'en-US'
      asText(' a \t b \n', null, true); // 'a b'
    • Coerces a value to a cleaned, non-empty string. Returns the trimmed string if valid, otherwise returns undefined (or an optional fallback).

      Parameters

      • str: unknown

        The value to normalize

      • fallback: undefined

        Optional fallback if str is not a valid non-empty string

      • OptionaldeepClean: boolean

        If true, applies trimAll to normalize tabs, newlines, and collapsed spaces

      Returns string | undefined

      The cleaned string or fallback

      asText('  hello  ');              // 'hello'
      asText(' '); // undefined
      asText(123); // undefined
      asText(' ', 'en-US'); // 'en-US'
      asText(' a \t b \n', null, true); // 'a b'
    • Coerces a value to a cleaned, non-empty string. Returns the trimmed string if valid, otherwise returns undefined (or an optional fallback).

      Type Parameters

      • T extends string

      Parameters

      • str: unknown

        The value to normalize

      • fallback: T

        Optional fallback if str is not a valid non-empty string

      • OptionaldeepClean: boolean

        If true, applies trimAll to normalize tabs, newlines, and collapsed spaces

      Returns string

      The cleaned string or fallback

      asText('  hello  ');              // 'hello'
      asText(' '); // undefined
      asText(123); // undefined
      asText(' ', 'en-US'); // 'en-US'
      asText(' a \t b \n', null, true); // 'a b'
    • Coerces a value to a cleaned, non-empty string. Returns the trimmed string if valid, otherwise returns undefined (or an optional fallback).

      Type Parameters

      • T

      Parameters

      • str: unknown

        The value to normalize

      • fallback: T

        Optional fallback if str is not a valid non-empty string

      • OptionaldeepClean: boolean

        If true, applies trimAll to normalize tabs, newlines, and collapsed spaces

      Returns string | T

      The cleaned string or fallback

      asText('  hello  ');              // 'hello'
      asText(' '); // undefined
      asText(123); // undefined
      asText(' ', 'en-US'); // 'en-US'
      asText(' a \t b \n', null, true); // 'a b'