Str
constStr:object
Defined in: Data/Str.ts:62
Type Declaration
Section titled “Type Declaration”capitalize
Section titled “capitalize”capitalize: (
text) =>string
Converts the first character of a string to uppercase.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”string
uncapitalize for converting the first character to lowercase.
Example
Section titled “Example”endsWith
Section titled “endsWith”endsWith: (
suffix) => (text) =>boolean
Returns true when the string ends with the given suffix.
Parameters
Section titled “Parameters”suffix
Section titled “suffix”string
Returns
Section titled “Returns”(text) => boolean
startsWith for checking prefix matches.
Example
Section titled “Example”graphemeSize
Section titled “graphemeSize”graphemeSize: (
text) =>number
Returns the number of user-perceived characters (grapheme clusters) in the string, correctly counting emojis and complex Unicode sequences.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”number
size for fast UTF-16 code-unit length.
Example
Section titled “Example”includes
Section titled “includes”includes: (
substring) => (text) =>boolean
Returns true when the string contains the given substring.
Parameters
Section titled “Parameters”substring
Section titled “substring”string
Returns
Section titled “Returns”(text) => boolean
Example
Section titled “Example”is:
object
Predicates and type guards for strings.
is.blank
Section titled “is.blank”blank: (
text) =>boolean=isBlank
Returns true when the string is empty or contains only whitespace.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”boolean
empty for checking zero length without trimming whitespace.
Example
Section titled “Example”is.empty
Section titled “is.empty”empty: (
text) =>boolean=isEmpty
Returns true when the string is empty.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”boolean
nonEmpty for checking if a string contains at least one character.
Example
Section titled “Example”is.nonEmpty
Section titled “is.nonEmpty”nonEmpty: (
text) =>text is NonEmptyString=isNonEmpty
Type guard to check if a string is non-empty.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”text is NonEmptyString
empty for checking if a string has zero length.
lines: (
text) => readonlystring[]
Splits a string into lines, normalising \r\n and \r line endings.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”readonly string[]
Example
Section titled “Example”match: (
pattern) => (text) =>Maybe<RegExpMatchArray>
Matches a string against a regular expression.
Pure and safe: resets pattern.lastIndex = 0 to prevent bugs with stateful /g and /y regexes.
Parameters
Section titled “Parameters”pattern
Section titled “pattern”RegExp
Returns
Section titled “Returns”(text) => Maybe<RegExpMatchArray>
test for boolean validation without extracting capture groups.
Example
Section titled “Example”NonEmpty
Section titled “NonEmpty”NonEmpty:
object=StrNonEmptyConst
Utilities for working with guaranteed non-empty strings (NonEmptyString).
NonEmpty.from
Section titled “NonEmpty.from”from:
object
NonEmpty.from.string
Section titled “NonEmpty.from.string”string: (
text) =>Maybe<NonEmptyString>
Returns Some containing NonEmptyString if the string is not empty, None otherwise.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Maybe<NonEmptyString>
Example
Section titled “Example”padEnd
Section titled “padEnd”padEnd: (
maxLength,fillString?) => (text) =>string
Pads the end of a string to a specified length. Data-last: use in pipe.
Parameters
Section titled “Parameters”maxLength
Section titled “maxLength”number
fillString?
Section titled “fillString?”string
Returns
Section titled “Returns”(text) => string
padStart for padding the left side of a string.
Example
Section titled “Example”padStart
Section titled “padStart”padStart: (
maxLength,fillString?) => (text) =>string
Pads the start of a string to a specified length. Data-last: use in pipe.
Parameters
Section titled “Parameters”maxLength
Section titled “maxLength”number
fillString?
Section titled “fillString?”string
Returns
Section titled “Returns”(text) => string
padEnd for padding the right side of a string.
Example
Section titled “Example”parse:
object
Safe number parsers that return Maybe instead of NaN.
parse.float
Section titled “parse.float”float: (
text) =>Maybe<number>
Parses a string as a floating-point number. Returns None if the result is NaN.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Maybe<number>
int for parsing base-10 integers.
Example
Section titled “Example”parse.int
Section titled “parse.int”int: (
text) =>Maybe<number>
Parses a string as an integer (base 10). Returns None if the result is NaN.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Maybe<number>
float for parsing floating-point numbers.
Example
Section titled “Example”replace
Section titled “replace”replace: (
pattern,replacement) => (text) =>string
Replaces the first occurrence of a pattern in a string. Data-last: use in pipe.
Parameters
Section titled “Parameters”pattern
Section titled “pattern”string | RegExp
replacement
Section titled “replacement”string
Returns
Section titled “Returns”(text) => string
replaceAll for substituting every occurrence instead of only the first.
Example
Section titled “Example”replaceAll
Section titled “replaceAll”replaceAll: (
pattern,replacement) => (text) =>string
Replaces all occurrences of a pattern in a string. Data-last: use in pipe.
Parameters
Section titled “Parameters”pattern
Section titled “pattern”string | RegExp
replacement
Section titled “replacement”string
Returns
Section titled “Returns”(text) => string
replace for substituting only the first occurrence.
Example
Section titled “Example”size: (
text) =>number
Returns the UTF-16 code-unit length of the string.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”number
graphemeSize for counting user-perceived characters/emojis.
Example
Section titled “Example”slice: (
start,end?) => (text) =>string
Extracts a substring between two indices. Data-last: use in pipe.
Parameters
Section titled “Parameters”number
number
Returns
Section titled “Returns”(text) => string
Example
Section titled “Example”split: (
separator) => (text) => readonlystring[]
Splits a string by a separator. Data-last: use in pipe.
Parameters
Section titled “Parameters”separator
Section titled “separator”string | RegExp
Returns
Section titled “Returns”(text) => readonly string[]
Example
Section titled “Example”startsWith
Section titled “startsWith”startsWith: (
prefix) => (text) =>boolean
Returns true when the string starts with the given prefix.
Parameters
Section titled “Parameters”prefix
Section titled “prefix”string
Returns
Section titled “Returns”(text) => boolean
endsWith for checking suffix matches.
Example
Section titled “Example”test: (
pattern) => (text) =>boolean
Tests whether a string matches a regular expression.
Pure and safe: resets pattern.lastIndex = 0 to prevent bugs with stateful /g and /y regexes.
Parameters
Section titled “Parameters”pattern
Section titled “pattern”RegExp
Returns
Section titled “Returns”(text) => boolean
match for extracting capture groups into a Maybe.
Example
Section titled “Example”toLowerCase
Section titled “toLowerCase”toLowerCase: (
text) =>string
Converts a string to lowercase.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”string
toUpperCase for uppercasing characters.
Example
Section titled “Example”toUpperCase
Section titled “toUpperCase”toUpperCase: (
text) =>string
Converts a string to uppercase.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”string
toLowerCase for lowercasing characters.
Example
Section titled “Example”trim: (
text) =>string
Removes leading and trailing whitespace from a string.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”string
Example
Section titled “Example”truncate
Section titled “truncate”truncate: (
options) => (text) =>string
Truncates a string to a maximum length, appending an optional suffix (default "...").
Data-last curried signature.
Parameters
Section titled “Parameters”options
Section titled “options”length
Section titled “length”number
suffix?
Section titled “suffix?”string
Returns
Section titled “Returns”(text) => string
Example
Section titled “Example”uncapitalize
Section titled “uncapitalize”uncapitalize: (
text) =>string
Converts the first character of a string to lower case.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”string
capitalize for converting the first character to uppercase.
Example
Section titled “Example”words: (
text) => readonlystring[]
Splits a string into words on any whitespace boundary, filtering out empty strings.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”readonly string[]