Str
constStr:object
Defined in: Data/Str.ts:43
Type Declaration
Section titled “Type Declaration”capitalize
Section titled “capitalize”capitalize: (
s) =>string
Converts the first character of a string to uppercase.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”string
Example
Section titled “Example”endsWith
Section titled “endsWith”endsWith: (
suffix) => (s) =>boolean
Returns true when the string ends with the given suffix.
Parameters
Section titled “Parameters”suffix
Section titled “suffix”string
Returns
Section titled “Returns”(s) => boolean
Example
Section titled “Example”includes
Section titled “includes”includes: (
substring) => (s) =>boolean
Returns true when the string contains the given substring.
Parameters
Section titled “Parameters”substring
Section titled “substring”string
Returns
Section titled “Returns”(s) => boolean
Example
Section titled “Example”is:
object
is.empty
Section titled “is.empty”empty: (
s) =>boolean=isEmpty
Returns true when the string is empty.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”boolean
Example
Section titled “Example”is.nonEmpty
Section titled “is.nonEmpty”nonEmpty: (
s) =>s is NonEmptyString=isNonEmpty
Type guard to check if a string is non-empty.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”s is NonEmptyString
isBlank
Section titled “isBlank”isBlank: (
s) =>boolean
Returns true when the string is empty or contains only whitespace.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”boolean
Example
Section titled “Example”length
Section titled “length”length: (
s) =>number
Returns the length of the string.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”number
Example
Section titled “Example”lines: (
s) => 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”NonEmpty
Section titled “NonEmpty”NonEmpty:
object=StrNonEmptyConst
NonEmpty.from
Section titled “NonEmpty.from”from:
object
NonEmpty.from.String
Section titled “NonEmpty.from.String”String: (
s) =>Maybe<NonEmptyString>
Returns Some containing NonEmptyString if the string is not empty, None otherwise.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Example
Section titled “Example”padEnd
Section titled “padEnd”padEnd: (
maxLength,fillString?) => (s) =>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”(s) => string
Example
Section titled “Example”padStart
Section titled “padStart”padStart: (
maxLength,fillString?) => (s) =>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”(s) => string
Example
Section titled “Example”parse:
object
Safe number parsers that return Maybe instead of NaN.
parse.float
Section titled “parse.float”float: (
s) =>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>
Example
Section titled “Example”parse.int
Section titled “parse.int”int: (
s) =>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>
Example
Section titled “Example”parseJson
Section titled “parseJson”parseJson: (
s) =>Result<SyntaxError,unknown>
Safely parses a JSON string, returning a Result<SyntaxError, unknown>.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Result<SyntaxError, unknown>
Example
Section titled “Example”replace
Section titled “replace”replace: (
pattern,replacement) => (s) =>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”(s) => string
Example
Section titled “Example”replaceAll
Section titled “replaceAll”replaceAll: (
pattern,replacement) => (s) =>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”(s) => string
Example
Section titled “Example”slice: (
start,end?) => (s) =>string
Extracts a substring between two indices. Data-last: use in pipe.
Parameters
Section titled “Parameters”number
number
Returns
Section titled “Returns”(s) => string
Example
Section titled “Example”split: (
separator) => (s) => 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”(s) => readonly string[]
Example
Section titled “Example”startsWith
Section titled “startsWith”startsWith: (
prefix) => (s) =>boolean
Returns true when the string starts with the given prefix.
Parameters
Section titled “Parameters”prefix
Section titled “prefix”string
Returns
Section titled “Returns”(s) => boolean
Example
Section titled “Example”toLowerCase
Section titled “toLowerCase”toLowerCase: (
s) =>string
Converts a string to lowercase.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”string
Example
Section titled “Example”toUpperCase
Section titled “toUpperCase”toUpperCase: (
s) =>string
Converts a string to uppercase.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”string
Example
Section titled “Example”trim: (
s) =>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) => (s) =>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”(s) => string
Example
Section titled “Example”uncapitalize
Section titled “uncapitalize”uncapitalize: (
s) =>string
Converts the first character of a string to lower case.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”string
Example
Section titled “Example”words: (
s) => 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[]