Handy tagged templates & other string utilities.
To install:
npm i @karmaniverous/string-utilities
Contents:
-
Types
-
Stringifiable
- Represents any value with atoString
method. -
stringifiableZodSchema
- Zod schema representing Stringifiable type. -
isStringifiable
- Returnstrue
when value hastoString
method.
-
-
Transformations
-
normstr
- Normalize a string by converting diacriticals to base characters, removing non-word characters, and converting to lower case. Non-strings return undefined.
-
-
Tagged Template Functions
-
Non-stringifiable to Empty String (
n2e
) - Replaces expressions withouttoString
property with empty strings. -
Some Non-stringifiable to Empty String (
sn2e
) - Returns empty string when any expression has notoString
property. -
Some Non-stringifiable to Null (
sn2n
) - Returnsnull
when any expression has notoString
property. -
Some Non-stringifiable to Undefined (
sn2u
) - Returnsundefined
when any expression has notoString
property.
-
-
Higher-Order Functions
-
Non-stringifiable to Default (
n2d
) - Returns tagged template function that replaces any expression that has notoString
property with a default value. -
Some Non-stringifiable to Default (
sn2d
) - Returns tagged template function that returns a default value when any expression has notoString
property.
-
Built for you with ❤️ on Bali! Find more great tools & templates on my GitHub Profile.