0.3.0 • Published 5 years ago
@perfective/string v0.3.0
String
The @perfective/string package works with the standard JS
String type.
It provides the following functions and additional types.
- Unit functions:
lines(value: string): string[]— creates an array from string split by the newline characters.
- Type guards:
isString<T>(value: T | string): value is stringisNotString<T>(value: T | string): value is T
- Predicates:
isEmpty(value: string): booleanisNotEmpty(value: string): booleanincludes(search: string, position?: number): Unary<string, boolean>endsWith(search: string, length?: number): Unary<string, boolean>startsWith(search: string, from: number = 0): Unary<string, boolean>
- Properties:
length(value: string): number
- Operators:
charAt(index: number): Unary<string, string>concat(...strings: string[]): Unary<string, string>concatTo(value: string): Unary<string | string[], string>lowerCase(value: string): stringpadEnd(length: number, fill?: string): Unary<string, string>padStart(length: number, fill?: string): Unary<string, string>repeat(count: number): Unary<string, string>replace(search: string | RegExp, replacement: string): Unary<string, string>replaceWith(search: string | RegExp, replacement: Replacement): Unary<string, string>slice(start: number, end?: number): Unary<string, string>split(separator: string | RegExp, limit?: number): Unary<string, string[]>trim(value: string): stringupperCase(value: string): string
- Search functions:
indexOf(search: string, from: number = 0): Unary<string, number>lastIndexOf(search: string, from?: number): Unary<string, number>search(search: RegExp): Unary<string, number | -1>
Output— an interface to explicitly requiretoString()method implementationoutput<T extends Output>(value: T | string | null | undefined): stringisOutput<T>(value: Output | T): value is OutputisNotOutput<T>(value: Output | T): value is T
Format:format(template: string, tokens: Tokens | Output[] = {}): Format— creates aFormatrecord converting positional tokens into named.formatted(input: Format): string— replaces input tokens in the input template.
Tokens:tokens(tokens: Output[] | Tokens): Tokens— converts positional tokens (an array ofOutputvalues) into namedTokens.
Utf16CodeUnit:stringFromCharCode(...codes: Utf16CodeUnit[]): stringcharCodeAt(index: number): Unary<string, Utf16CodeUnit>
CodePoint:stringFromCodePoint(...codePoints: CodePoint[]): stringcodePointAt(position: number): Unary<string, CodePoint | undefined>
UnicodeNormalizationForm:normalize(form: UnicodeNormalizationForm = 'NFC'): Unary<string, string>
Full documentation is available in the project repository.
0.3.0
5 years ago
0.2.3
5 years ago
0.2.2
5 years ago
0.2.1
5 years ago
0.2.0
5 years ago
0.2.0-beta.1
5 years ago
0.2.0-beta
5 years ago
0.2.0-alpha.1
5 years ago
0.2.0-alpha
5 years ago
0.1.0
6 years ago