@visulima/string 3.0.0 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/LICENSE.md +55 -129
- package/README.md +2 -2
- package/dist/align-text.d.ts +29 -29
- package/dist/align-text.js +2 -2
- package/dist/case/camel-case.d.ts +16 -16
- package/dist/case/camel-case.js +1 -1
- package/dist/case/capital-case.d.ts +13 -13
- package/dist/case/capital-case.js +1 -1
- package/dist/case/constant-case.d.ts +13 -13
- package/dist/case/constant-case.js +1 -1
- package/dist/case/dot-case.d.ts +13 -13
- package/dist/case/dot-case.js +1 -1
- package/dist/case/flat-case.d.ts +11 -11
- package/dist/case/flat-case.js +1 -1
- package/dist/case/flip-case.d.ts +14 -14
- package/dist/case/flip-case.js +1 -1
- package/dist/case/identify-case.d.ts +14 -14
- package/dist/case/identify-case.js +1 -1
- package/dist/case/index.d.ts +7 -7
- package/dist/case/index.js +1 -1
- package/dist/case/kebab-case.d.ts +22 -22
- package/dist/case/kebab-case.js +1 -1
- package/dist/case/lower-first.d.ts +12 -12
- package/dist/case/lower-first.js +1 -1
- package/dist/case/no-case.d.ts +13 -13
- package/dist/case/no-case.js +1 -1
- package/dist/case/pascal-case.d.ts +16 -16
- package/dist/case/pascal-case.js +1 -1
- package/dist/case/pascal-snake-case.d.ts +13 -13
- package/dist/case/pascal-snake-case.js +1 -1
- package/dist/case/path-case.d.ts +13 -13
- package/dist/case/path-case.js +1 -1
- package/dist/case/sentence-case.d.ts +13 -13
- package/dist/case/sentence-case.js +1 -1
- package/dist/case/snake-case.d.ts +13 -13
- package/dist/case/snake-case.js +1 -1
- package/dist/case/split-by-case.d.ts +20 -20
- package/dist/case/split-by-case.js +1 -1
- package/dist/case/title-case.d.ts +11 -11
- package/dist/case/title-case.js +1 -1
- package/dist/case/train-case.d.ts +13 -13
- package/dist/case/train-case.js +1 -1
- package/dist/case/upper-first.d.ts +12 -12
- package/dist/case/upper-first.js +1 -1
- package/dist/closest-string.d.ts +28 -28
- package/dist/closest-string.js +1 -1
- package/dist/compare-similarity.d.ts +33 -33
- package/dist/compare-similarity.js +1 -1
- package/dist/count-occurrences.d.ts +6 -6
- package/dist/count-occurrences.js +1 -1
- package/dist/direction.d.ts +4 -4
- package/dist/direction.js +1 -1
- package/dist/east-asian-width.d.ts +25 -15
- package/dist/east-asian-width.js +1 -1
- package/dist/excerpt.d.ts +18 -18
- package/dist/excerpt.js +55 -44
- package/dist/get-string-truncated-width.d.ts +131 -131
- package/dist/get-string-truncated-width.js +1 -1
- package/dist/get-string-width.d.ts +56 -56
- package/dist/indent.d.ts +11 -8
- package/dist/indent.js +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/dist/is-fullwidth-code-point.d.ts +4 -4
- package/dist/is-fullwidth-code-point.js +1 -1
- package/dist/levenshtein.d.ts +19 -19
- package/dist/levenshtein.js +1 -1
- package/dist/native-string-types.d.ts +212 -228
- package/dist/outdent.d.ts +64 -64
- package/dist/outdent.js +1 -1
- package/dist/packem_shared/{_isFullWidth-Dqc3MWgl.js → _isFullWidth-dWWDw5Is.js} +1 -1
- package/dist/packem_shared/ansi-state-tracker-BFhXTS-5.js +1 -0
- package/dist/packem_shared/closest-CSX4px2F.js +1 -0
- package/dist/packem_shared/constants-BGGeBKGT.js +1 -0
- package/dist/packem_shared/dedent-CDXp3nZQ.js +1 -0
- package/dist/packem_shared/eastAsianWidth-DACe9Ds2.js +1 -0
- package/dist/packem_shared/generate-cache-key-th9N8-CB.js +1 -0
- package/dist/packem_shared/indent-CY079Qyq.js +1 -0
- package/dist/packem_shared/joinSegments-9qx7xSy7.js +1 -0
- package/dist/packem_shared/{lru-cache-BtMSrYQJ.js → lru-cache-BD25OaEQ.js} +1 -1
- package/dist/packem_shared/normalize-german-eszett-DtW4F-Wg.js +1 -0
- package/dist/packem_shared/redent-lctoaAtw.js +1 -0
- package/dist/packem_shared/strip-vt-control-characters-vMeu7uFw.js +1 -0
- package/dist/packem_shared/types.d-CMNqA5bi.d.ts +402 -0
- package/dist/packem_shared/types.d-LgsTR37y.d.ts +360 -0
- package/dist/replace-string.d.ts +7 -7
- package/dist/replace-string.js +1 -1
- package/dist/slice.d.ts +38 -38
- package/dist/slice.js +1 -1
- package/dist/slugify.d.ts +9 -9
- package/dist/slugify.js +1 -1
- package/dist/test/utils.d.ts +14 -14
- package/dist/test/utils.js +11 -11
- package/dist/test/vitest.d.ts +2 -2
- package/dist/transliterate.d.ts +7 -7
- package/dist/transliterate.js +3 -3
- package/dist/truncate.d.ts +37 -37
- package/dist/truncate.js +1 -1
- package/dist/utilities.d.ts +23 -23
- package/dist/utilities.js +1 -1
- package/dist/word-similarity-sort.d.ts +32 -32
- package/dist/word-similarity-sort.js +1 -1
- package/dist/word-wrap.d.ts +33 -33
- package/dist/word-wrap.js +5 -7
- package/package.json +1 -1
- package/dist/packem_shared/closest-C6YDQs4m.js +0 -1
- package/dist/packem_shared/constants-aPzGW29R.js +0 -1
- package/dist/packem_shared/dedent-CPjAYUXh.js +0 -1
- package/dist/packem_shared/eastAsianWidth-DJV8Kqd-.js +0 -1
- package/dist/packem_shared/generate-cache-key-BqU1Cqwm.js +0 -1
- package/dist/packem_shared/indent-cz8WMI0e.js +0 -1
- package/dist/packem_shared/joinSegments-CaHT-45s.js +0 -1
- package/dist/packem_shared/normalize-german-eszett-hNMwtGjd.js +0 -1
- package/dist/packem_shared/redent-ByOoJ6fN.js +0 -1
- package/dist/packem_shared/types.d-CmNvyl4l.d.ts +0 -360
- package/dist/packem_shared/types.d-fhe030jX.d.ts +0 -402
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
|
-
* Creates a tuple type of specified length filled with a given type.
|
|
4
|
-
* @template L - The desired length of the tuple
|
|
5
|
-
* @template T - The type to fill the tuple with (defaults to unknown)
|
|
6
|
-
* @template Result - Internal accumulator for recursive type building
|
|
7
|
-
* @returns A tuple type of length L filled with type T
|
|
8
|
-
*/
|
|
3
|
+
* Creates a tuple type of specified length filled with a given type.
|
|
4
|
+
* @template L - The desired length of the tuple
|
|
5
|
+
* @template T - The type to fill the tuple with (defaults to unknown)
|
|
6
|
+
* @template Result - Internal accumulator for recursive type building
|
|
7
|
+
* @returns A tuple type of length L filled with type T
|
|
8
|
+
*/
|
|
9
9
|
type TupleOf<L extends number, T = unknown, Result extends any[] = []> = Result["length"] extends L ? Result : TupleOf<L, T, [...Result, T]>;
|
|
10
10
|
/**
|
|
11
|
-
* Internal type for implementing string slicing with both start and end indices.
|
|
12
|
-
* Handles edge cases and type safety for string literal types.
|
|
13
|
-
* @template T - The input string type
|
|
14
|
-
* @template StartIndex - The starting index for the slice
|
|
15
|
-
* @template EndIndex - The ending index for the slice
|
|
16
|
-
* @template Result - Internal accumulator for building the result string
|
|
17
|
-
*/
|
|
11
|
+
* Internal type for implementing string slicing with both start and end indices.
|
|
12
|
+
* Handles edge cases and type safety for string literal types.
|
|
13
|
+
* @template T - The input string type
|
|
14
|
+
* @template StartIndex - The starting index for the slice
|
|
15
|
+
* @template EndIndex - The ending index for the slice
|
|
16
|
+
* @template Result - Internal accumulator for building the result string
|
|
17
|
+
*/
|
|
18
18
|
type InternalSliceType<T extends string, StartIndex extends number, EndIndex extends number, Result extends string = ""> = IsNumberLiteral<EndIndex | StartIndex> extends true ? T extends `${infer Head}${infer Rest}` ? IsStringLiteral<Head> extends true ? StartIndex extends 0 ? EndIndex extends 0 ? Result : InternalSliceType<Rest, 0, Math.Subtract<Math.GetPositiveIndex<T, EndIndex>, 1>, `${Result}${Head}`> : InternalSliceType<Rest, Math.Subtract<Math.GetPositiveIndex<T, StartIndex>, 1>, Math.Subtract<Math.GetPositiveIndex<T, EndIndex>, 1>, Result> : EndIndex | StartIndex extends 0 ? Result : string : IsStringLiteral<T> extends true ? Result : EndIndex | StartIndex extends 0 ? Result : string : string;
|
|
19
19
|
/**
|
|
20
|
-
* Internal type for implementing string slicing with only a start index.
|
|
21
|
-
* Provides type-safe string slicing functionality for string literal types.
|
|
22
|
-
* @template T - The input string type
|
|
23
|
-
* @template StartIndex - The starting index for the slice
|
|
24
|
-
* @template Result - Internal accumulator for building the result string
|
|
25
|
-
*/
|
|
20
|
+
* Internal type for implementing string slicing with only a start index.
|
|
21
|
+
* Provides type-safe string slicing functionality for string literal types.
|
|
22
|
+
* @template T - The input string type
|
|
23
|
+
* @template StartIndex - The starting index for the slice
|
|
24
|
+
* @template Result - Internal accumulator for building the result string
|
|
25
|
+
*/
|
|
26
26
|
type SliceStartType<T extends string, StartIndex extends number, Result extends string = ""> = IsNumberLiteral<StartIndex> extends true ? T extends `${infer Head}${infer Rest}` ? IsStringLiteral<Head> extends true ? StartIndex extends 0 ? T : SliceStartType<Rest, Math.Subtract<Math.GetPositiveIndex<T, StartIndex>, 1>, Result> : string : IsStringLiteral<T> extends true ? Result : StartIndex extends 0 ? Result : string : string;
|
|
27
27
|
type InternalEndsWithType<T extends string, S extends string, P extends number> = All<[IsStringLiteral<S>, IsNumberLiteral<P>]> extends true ? Math.IsNegative<P> extends false ? P extends Length<T> ? IsStringLiteral<T> extends true ? S extends Slice<T, Math.Subtract<Length<T>, Length<S>>, Length<T>> ? true : false : EndsWithNoPositionType<Slice<T, 0, P>, S> : EndsWithNoPositionType<Slice<T, 0, P>, S> : false : boolean;
|
|
28
28
|
/**
|
|
29
|
-
* Internal type for implementing EndsWith functionality without a position parameter.
|
|
30
|
-
* Uses string reversal to check if a string ends with another string.
|
|
31
|
-
* @template T - The string to check
|
|
32
|
-
* @template S - The suffix to check for
|
|
33
|
-
*/
|
|
29
|
+
* Internal type for implementing EndsWith functionality without a position parameter.
|
|
30
|
+
* Uses string reversal to check if a string ends with another string.
|
|
31
|
+
* @template T - The string to check
|
|
32
|
+
* @template S - The suffix to check for
|
|
33
|
+
*/
|
|
34
34
|
type EndsWithNoPositionType<T extends string, S extends string> = StartsWith<Reverse<T>, Reverse<S>>;
|
|
35
35
|
/**
|
|
36
|
-
* Namespace containing type-level mathematical operations.
|
|
37
|
-
* These utilities provide type-safe arithmetic and number manipulation.
|
|
38
|
-
*/
|
|
36
|
+
* Namespace containing type-level mathematical operations.
|
|
37
|
+
* These utilities provide type-safe arithmetic and number manipulation.
|
|
38
|
+
*/
|
|
39
39
|
declare namespace Math {
|
|
40
40
|
type Subtract<A extends number, B extends number> = number extends A | B ? number : TupleOf<A> extends [...infer U, ...TupleOf<B>] ? U["length"] : 0;
|
|
41
41
|
type IsNegative<T extends number> = number extends T ? boolean : `${T}` extends `-${number}` ? true : false;
|
|
@@ -43,235 +43,235 @@ declare namespace Math {
|
|
|
43
43
|
type GetPositiveIndex<T extends string, I extends number> = IsNegative<I> extends false ? I : Subtract<Length<T>, Abs<I>>;
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
46
|
-
* Type predicate that determines if a number type is a literal type rather than the general 'number' type.
|
|
47
|
-
* For example: IsNumberLiteral<42> is true, but IsNumberLiteral<number> is false.
|
|
48
|
-
* @template T - The number type to check
|
|
49
|
-
* @returns true if T is a number literal type, false otherwise
|
|
50
|
-
*/
|
|
46
|
+
* Type predicate that determines if a number type is a literal type rather than the general 'number' type.
|
|
47
|
+
* For example: IsNumberLiteral<42> is true, but IsNumberLiteral<number> is false.
|
|
48
|
+
* @template T - The number type to check
|
|
49
|
+
* @returns true if T is a number literal type, false otherwise
|
|
50
|
+
*/
|
|
51
51
|
type IsNumberLiteral<T extends number> = [T] extends [number] ? ([number] extends [T] ? false : true) : false;
|
|
52
52
|
type IsBooleanLiteral<T extends boolean> = [T] extends [boolean] ? ([boolean] extends [T] ? false : true) : false;
|
|
53
53
|
/**
|
|
54
|
-
* Type-level string reversal utility.
|
|
55
|
-
* Recursively builds the reversed string using template literal types.
|
|
56
|
-
* @template T - The string type to reverse
|
|
57
|
-
* @template Accumulator - Internal accumulator for building the reversed string
|
|
58
|
-
* @returns A type representing the reversed string
|
|
59
|
-
* @example
|
|
60
|
-
* type ReversedHello = Reverse<'hello'> // type ReversedHello = 'olleh'
|
|
61
|
-
*/
|
|
54
|
+
* Type-level string reversal utility.
|
|
55
|
+
* Recursively builds the reversed string using template literal types.
|
|
56
|
+
* @template T - The string type to reverse
|
|
57
|
+
* @template Accumulator - Internal accumulator for building the reversed string
|
|
58
|
+
* @returns A type representing the reversed string
|
|
59
|
+
* @example
|
|
60
|
+
* type ReversedHello = Reverse<'hello'> // type ReversedHello = 'olleh'
|
|
61
|
+
*/
|
|
62
62
|
type Reverse<T extends string, Accumulator extends string = ""> = T extends `${infer Head}${infer Tail}` ? Reverse<Tail, `${Head}${Accumulator}`> : Accumulator extends "" ? T : `${T}${Accumulator}`;
|
|
63
63
|
/**
|
|
64
|
-
* Type predicate that checks if all elements in a boolean array type are the literal 'true'.
|
|
65
|
-
* Distinguishes between literal true/false and the general boolean type.
|
|
66
|
-
* @template T - Array of boolean types to check
|
|
67
|
-
* @returns true if all elements are the literal true, false otherwise
|
|
68
|
-
* @example
|
|
69
|
-
* type AllTrue = All<[true, true]> // type AllTrue = true
|
|
70
|
-
* type NotAllTrue = All<[true, false]> // type NotAllTrue = false
|
|
71
|
-
*/
|
|
64
|
+
* Type predicate that checks if all elements in a boolean array type are the literal 'true'.
|
|
65
|
+
* Distinguishes between literal true/false and the general boolean type.
|
|
66
|
+
* @template T - Array of boolean types to check
|
|
67
|
+
* @returns true if all elements are the literal true, false otherwise
|
|
68
|
+
* @example
|
|
69
|
+
* type AllTrue = All<[true, true]> // type AllTrue = true
|
|
70
|
+
* type NotAllTrue = All<[true, false]> // type NotAllTrue = false
|
|
71
|
+
*/
|
|
72
72
|
type All<BoolArray extends boolean[]> = IsBooleanLiteral<BoolArray[number]> extends true ? BoolArray extends [infer Head extends boolean, ...infer Rest extends boolean[]] ? Head extends true ? All<Rest> : false : true : false;
|
|
73
73
|
/**
|
|
74
|
-
* Type predicate that determines if a string type is a literal type rather than the general 'string' type.
|
|
75
|
-
* @template T - The string type to check
|
|
76
|
-
* @returns true if T is a string literal type, false if it's the general string type
|
|
77
|
-
* @example
|
|
78
|
-
* type IsLiteral = IsStringLiteral<'hello'> // type IsLiteral = true
|
|
79
|
-
* type NotLiteral = IsStringLiteral<string> // type NotLiteral = false
|
|
80
|
-
*/
|
|
74
|
+
* Type predicate that determines if a string type is a literal type rather than the general 'string' type.
|
|
75
|
+
* @template T - The string type to check
|
|
76
|
+
* @returns true if T is a string literal type, false if it's the general string type
|
|
77
|
+
* @example
|
|
78
|
+
* type IsLiteral = IsStringLiteral<'hello'> // type IsLiteral = true
|
|
79
|
+
* type NotLiteral = IsStringLiteral<string> // type NotLiteral = false
|
|
80
|
+
*/
|
|
81
81
|
type IsStringLiteral<T extends string> = [T] extends [string] ? [string] extends [T] ? false : Uppercase<T> extends Uppercase<Lowercase<T>> ? Lowercase<T> extends Lowercase<Uppercase<T>> ? true : false : false : false;
|
|
82
82
|
type IsStringLiteralArray<StringArray extends ReadonlyArray<string>> = IsStringLiteral<StringArray[number]> extends true ? true : false;
|
|
83
83
|
/**
|
|
84
|
-
* Type-safe utility to get the character at a specific index in a string literal type.
|
|
85
|
-
* @template T - The string type to extract a character from
|
|
86
|
-
* @template Index - The numeric index of the desired character
|
|
87
|
-
* @returns The character type at the specified index, or never if the index is invalid
|
|
88
|
-
* @example
|
|
89
|
-
* type FirstChar = CharAt<'hello', 0> // type FirstChar = 'h'
|
|
90
|
-
*/
|
|
84
|
+
* Type-safe utility to get the character at a specific index in a string literal type.
|
|
85
|
+
* @template T - The string type to extract a character from
|
|
86
|
+
* @template Index - The numeric index of the desired character
|
|
87
|
+
* @returns The character type at the specified index, or never if the index is invalid
|
|
88
|
+
* @example
|
|
89
|
+
* type FirstChar = CharAt<'hello', 0> // type FirstChar = 'h'
|
|
90
|
+
*/
|
|
91
91
|
type CharAt<T extends string, Index extends number> = All<[IsStringLiteral<T>, IsNumberLiteral<Index>]> extends true ? Split<T>[Index] : string;
|
|
92
92
|
/**
|
|
93
|
-
* Type-level string concatenation for tuples of string literals.
|
|
94
|
-
* Joins all strings in the tuple into a single string type.
|
|
95
|
-
* @template T - Tuple of string types to concatenate
|
|
96
|
-
* @returns A single string type representing the concatenated result
|
|
97
|
-
* @example
|
|
98
|
-
* type Combined = Concat<['hello', ' ', 'world']> // type Combined = 'hello world'
|
|
99
|
-
*/
|
|
93
|
+
* Type-level string concatenation for tuples of string literals.
|
|
94
|
+
* Joins all strings in the tuple into a single string type.
|
|
95
|
+
* @template T - Tuple of string types to concatenate
|
|
96
|
+
* @returns A single string type representing the concatenated result
|
|
97
|
+
* @example
|
|
98
|
+
* type Combined = Concat<['hello', ' ', 'world']> // type Combined = 'hello world'
|
|
99
|
+
*/
|
|
100
100
|
type Concat<T extends string[]> = Join<T>;
|
|
101
101
|
/**
|
|
102
|
-
* Type-level implementation of string.endsWith() functionality.
|
|
103
|
-
* Checks if a string type ends with another string type at a given position.
|
|
104
|
-
* @template T - The string type to check
|
|
105
|
-
* @template S - The suffix to check for
|
|
106
|
-
* @template P - Optional position at which to end the search
|
|
107
|
-
* @returns A boolean type indicating if T ends with S at position P
|
|
108
|
-
* @example
|
|
109
|
-
* type EndsWithWorld = EndsWith<'hello world', 'world'> // type EndsWithWorld = true
|
|
110
|
-
* type DoesNotEnd = EndsWith<'hello world', 'hello'> // type DoesNotEnd = false
|
|
111
|
-
*/
|
|
102
|
+
* Type-level implementation of string.endsWith() functionality.
|
|
103
|
+
* Checks if a string type ends with another string type at a given position.
|
|
104
|
+
* @template T - The string type to check
|
|
105
|
+
* @template S - The suffix to check for
|
|
106
|
+
* @template P - Optional position at which to end the search
|
|
107
|
+
* @returns A boolean type indicating if T ends with S at position P
|
|
108
|
+
* @example
|
|
109
|
+
* type EndsWithWorld = EndsWith<'hello world', 'world'> // type EndsWithWorld = true
|
|
110
|
+
* type DoesNotEnd = EndsWith<'hello world', 'hello'> // type DoesNotEnd = false
|
|
111
|
+
*/
|
|
112
112
|
type EndsWith<T extends string, S extends string, P extends number | undefined = undefined> = P extends number ? InternalEndsWithType<T, S, P> : EndsWithNoPositionType<T, S>;
|
|
113
113
|
/**
|
|
114
|
-
* Type-level implementation of string.includes() functionality.
|
|
115
|
-
* Determines if one string type contains another string type starting at an optional position.
|
|
116
|
-
* @template T - The string type to search within
|
|
117
|
-
* @template S - The string type to search for
|
|
118
|
-
* @template P - Optional position to start the search from
|
|
119
|
-
* @returns A boolean type indicating if S is found within T starting at P
|
|
120
|
-
* @example
|
|
121
|
-
* type HasWorld = Includes<'hello world', 'world'> // type HasWorld = true
|
|
122
|
-
* type NoWorld = Includes<'hello', 'world'> // type NoWorld = false
|
|
123
|
-
*/
|
|
114
|
+
* Type-level implementation of string.includes() functionality.
|
|
115
|
+
* Determines if one string type contains another string type starting at an optional position.
|
|
116
|
+
* @template T - The string type to search within
|
|
117
|
+
* @template S - The string type to search for
|
|
118
|
+
* @template P - Optional position to start the search from
|
|
119
|
+
* @returns A boolean type indicating if S is found within T starting at P
|
|
120
|
+
* @example
|
|
121
|
+
* type HasWorld = Includes<'hello world', 'world'> // type HasWorld = true
|
|
122
|
+
* type NoWorld = Includes<'hello', 'world'> // type NoWorld = false
|
|
123
|
+
*/
|
|
124
124
|
type Includes<T extends string, S extends string, P extends number = 0> = string extends S | T ? boolean : Math.IsNegative<P> extends false ? P extends 0 ? T extends `${string}${S}${string}` ? true : false : Includes<Slice<T, P>, S> : Includes<T, S>;
|
|
125
125
|
/**
|
|
126
|
-
* Type-level implementation of Array.join() functionality for string tuples.
|
|
127
|
-
* Combines string literal types in a tuple using a delimiter.
|
|
128
|
-
* @template T - Tuple of string types to join
|
|
129
|
-
* @template Delimiter - The delimiter to insert between elements
|
|
130
|
-
* @returns A string type representing the joined result
|
|
131
|
-
* @example
|
|
132
|
-
* type Joined = Join<['a', 'b', 'c'], '.'> // type Joined = 'a.b.c'
|
|
133
|
-
*/
|
|
126
|
+
* Type-level implementation of Array.join() functionality for string tuples.
|
|
127
|
+
* Combines string literal types in a tuple using a delimiter.
|
|
128
|
+
* @template T - Tuple of string types to join
|
|
129
|
+
* @template Delimiter - The delimiter to insert between elements
|
|
130
|
+
* @returns A string type representing the joined result
|
|
131
|
+
* @example
|
|
132
|
+
* type Joined = Join<['a', 'b', 'c'], '.'> // type Joined = 'a.b.c'
|
|
133
|
+
*/
|
|
134
134
|
type Join<T extends ReadonlyArray<string>, Delimiter extends string = ""> = All<[IsStringLiteralArray<T>, IsStringLiteral<Delimiter>]> extends true ? T extends readonly [infer First extends string, ...infer Rest extends string[]] ? Rest extends [] ? First : `${First}${Delimiter}${Join<Rest, Delimiter>}` : "" : string;
|
|
135
135
|
/**
|
|
136
|
-
* Type-level utility to compute the length of a string literal type.
|
|
137
|
-
* @template T - The string type to measure
|
|
138
|
-
* @returns A number literal type representing the string's length
|
|
139
|
-
* @example
|
|
140
|
-
* type Len = Length<'hello'> // type Len = 5
|
|
141
|
-
*/
|
|
136
|
+
* Type-level utility to compute the length of a string literal type.
|
|
137
|
+
* @template T - The string type to measure
|
|
138
|
+
* @returns A number literal type representing the string's length
|
|
139
|
+
* @example
|
|
140
|
+
* type Len = Length<'hello'> // type Len = 5
|
|
141
|
+
*/
|
|
142
142
|
type Length<T extends string> = IsStringLiteral<T> extends true ? Split<T>["length"] : number;
|
|
143
143
|
/**
|
|
144
|
-
* Type-level implementation of string.padEnd() functionality.
|
|
145
|
-
* Adds padding to the end of a string type until it reaches a specified length.
|
|
146
|
-
* @template T - The string type to pad
|
|
147
|
-
* @template Times - Target total length of the padded string
|
|
148
|
-
* @template Pad - The string to use as padding (defaults to space)
|
|
149
|
-
* @returns A string type with the padding added to the end
|
|
150
|
-
* @example
|
|
151
|
-
* type Padded = PadEnd<'hello', 7, '_'> // type Padded = 'hello__'
|
|
152
|
-
*/
|
|
153
|
-
type PadEnd<T extends string, Times extends number = 0, Pad extends string = " "> = All<[IsStringLiteral<Pad | T>, IsNumberLiteral<Times>]> extends true ? Math.IsNegative<Times> extends false ? Math.Subtract<Times, Length<T>> extends infer Missing extends number ? `${T}${Slice<Repeat<Pad, Missing>, 0, Missing>}` : never : T : string;
|
|
144
|
+
* Type-level implementation of string.padEnd() functionality.
|
|
145
|
+
* Adds padding to the end of a string type until it reaches a specified length.
|
|
146
|
+
* @template T - The string type to pad
|
|
147
|
+
* @template Times - Target total length of the padded string
|
|
148
|
+
* @template Pad - The string to use as padding (defaults to space)
|
|
149
|
+
* @returns A string type with the padding added to the end
|
|
150
|
+
* @example
|
|
151
|
+
* type Padded = PadEnd<'hello', 7, '_'> // type Padded = 'hello__'
|
|
152
|
+
*/
|
|
153
|
+
type PadEnd<T extends string, Times extends number = 0, Pad extends string = " "> = All<[IsStringLiteral<Pad | T>, IsNumberLiteral<Times>]> extends true ? Math.IsNegative<Times> extends false ? Math.Subtract<Times, Length<T>> extends (infer Missing extends number) ? `${T}${Slice<Repeat<Pad, Missing>, 0, Missing>}` : never : T : string;
|
|
154
154
|
/**
|
|
155
|
-
* Type-level implementation of string.padStart() functionality.
|
|
156
|
-
* Adds padding to the beginning of a string type until it reaches a specified length.
|
|
157
|
-
* @template T - The string type to pad
|
|
158
|
-
* @template Times - Target total length of the padded string
|
|
159
|
-
* @template Pad - The string to use as padding (defaults to space)
|
|
160
|
-
* @returns A string type with the padding added to the start
|
|
161
|
-
* @example
|
|
162
|
-
* type Padded = PadStart<'hello', 7, '_'> // type Padded = '__hello'
|
|
163
|
-
*/
|
|
164
|
-
type PadStart<T extends string, Times extends number = 0, Pad extends string = " "> = All<[IsStringLiteral<Pad | T>, IsNumberLiteral<Times>]> extends true ? Math.IsNegative<Times> extends false ? Math.Subtract<Times, Length<T>> extends infer Missing extends number ? `${Slice<Repeat<Pad, Missing>, 0, Missing>}${T}` : never : T : string;
|
|
155
|
+
* Type-level implementation of string.padStart() functionality.
|
|
156
|
+
* Adds padding to the beginning of a string type until it reaches a specified length.
|
|
157
|
+
* @template T - The string type to pad
|
|
158
|
+
* @template Times - Target total length of the padded string
|
|
159
|
+
* @template Pad - The string to use as padding (defaults to space)
|
|
160
|
+
* @returns A string type with the padding added to the start
|
|
161
|
+
* @example
|
|
162
|
+
* type Padded = PadStart<'hello', 7, '_'> // type Padded = '__hello'
|
|
163
|
+
*/
|
|
164
|
+
type PadStart<T extends string, Times extends number = 0, Pad extends string = " "> = All<[IsStringLiteral<Pad | T>, IsNumberLiteral<Times>]> extends true ? Math.IsNegative<Times> extends false ? Math.Subtract<Times, Length<T>> extends (infer Missing extends number) ? `${Slice<Repeat<Pad, Missing>, 0, Missing>}${T}` : never : T : string;
|
|
165
165
|
/**
|
|
166
|
-
* Type-level implementation of string.repeat() functionality.
|
|
167
|
-
* Creates a new string type by repeating the input string a specified number of times.
|
|
168
|
-
* @template T - The string type to repeat
|
|
169
|
-
* @template Times - The number of times to repeat the string
|
|
170
|
-
* @returns A string type containing T repeated Times times
|
|
171
|
-
* @example
|
|
172
|
-
* type Repeated = Repeat<'abc', 2> // type Repeated = 'abcabc'
|
|
173
|
-
*/
|
|
166
|
+
* Type-level implementation of string.repeat() functionality.
|
|
167
|
+
* Creates a new string type by repeating the input string a specified number of times.
|
|
168
|
+
* @template T - The string type to repeat
|
|
169
|
+
* @template Times - The number of times to repeat the string
|
|
170
|
+
* @returns A string type containing T repeated Times times
|
|
171
|
+
* @example
|
|
172
|
+
* type Repeated = Repeat<'abc', 2> // type Repeated = 'abcabc'
|
|
173
|
+
*/
|
|
174
174
|
type Repeat<T extends string, Times extends number = 0> = All<[IsStringLiteral<T>, IsNumberLiteral<Times>]> extends true ? Times extends 0 ? "" : Math.IsNegative<Times> extends false ? Join<TupleOf<Times, T>> : never : string;
|
|
175
175
|
/**
|
|
176
|
-
* Type-level implementation of string.replaceAll() functionality.
|
|
177
|
-
* Replaces all occurrences of a substring with another string.
|
|
178
|
-
* @template Sentence - The string type to perform replacements on
|
|
179
|
-
* @template Lookup - The string or RegExp pattern to search for. When a RegExp is used, the result type widens to string.
|
|
180
|
-
* @template Replacement - The string type to replace matches with
|
|
181
|
-
* @returns A string type with all occurrences of Lookup replaced with Replacement. When Lookup is a RegExp, returns string.
|
|
182
|
-
* @example
|
|
183
|
-
* type Replaced = ReplaceAll<'hello hello', 'hello', 'hi'> // type Replaced = 'hi hi'
|
|
184
|
-
*/
|
|
176
|
+
* Type-level implementation of string.replaceAll() functionality.
|
|
177
|
+
* Replaces all occurrences of a substring with another string.
|
|
178
|
+
* @template Sentence - The string type to perform replacements on
|
|
179
|
+
* @template Lookup - The string or RegExp pattern to search for. When a RegExp is used, the result type widens to string.
|
|
180
|
+
* @template Replacement - The string type to replace matches with
|
|
181
|
+
* @returns A string type with all occurrences of Lookup replaced with Replacement. When Lookup is a RegExp, returns string.
|
|
182
|
+
* @example
|
|
183
|
+
* type Replaced = ReplaceAll<'hello hello', 'hello', 'hi'> // type Replaced = 'hi hi'
|
|
184
|
+
*/
|
|
185
185
|
type ReplaceAll<Sentence extends string, Lookup extends RegExp | string, Replacement extends string = ""> = Lookup extends string ? IsStringLiteral<Lookup | Replacement | Sentence> extends true ? Sentence extends `${infer Rest}${Lookup}${infer Rest2}` ? `${Rest}${Replacement}${ReplaceAll<Rest2, Lookup, Replacement>}` : Sentence : string : string;
|
|
186
186
|
/**
|
|
187
|
-
* Type-level implementation of string.replace() functionality.
|
|
188
|
-
* Replaces the first occurrence of a substring with another string.
|
|
189
|
-
* @template Sentence - The string type to perform replacement on
|
|
190
|
-
* @template Lookup - The string or RegExp pattern to search for. When a RegExp is used, the result type widens to string.
|
|
191
|
-
* @template Replacement - The string type to replace the match with
|
|
192
|
-
* @returns A string type with the first occurrence of Lookup replaced with Replacement. When Lookup is a RegExp, returns string.
|
|
193
|
-
* @example
|
|
194
|
-
* type Replaced = Replace<'hello hello', 'hello', 'hi'> // type Replaced = 'hi hello'
|
|
195
|
-
*/
|
|
187
|
+
* Type-level implementation of string.replace() functionality.
|
|
188
|
+
* Replaces the first occurrence of a substring with another string.
|
|
189
|
+
* @template Sentence - The string type to perform replacement on
|
|
190
|
+
* @template Lookup - The string or RegExp pattern to search for. When a RegExp is used, the result type widens to string.
|
|
191
|
+
* @template Replacement - The string type to replace the match with
|
|
192
|
+
* @returns A string type with the first occurrence of Lookup replaced with Replacement. When Lookup is a RegExp, returns string.
|
|
193
|
+
* @example
|
|
194
|
+
* type Replaced = Replace<'hello hello', 'hello', 'hi'> // type Replaced = 'hi hello'
|
|
195
|
+
*/
|
|
196
196
|
type Replace<Sentence extends string, Lookup extends RegExp | string, Replacement extends string = ""> = Lookup extends string ? IsStringLiteral<Lookup | Replacement | Sentence> extends true ? Sentence extends `${infer Rest}${Lookup}${infer Rest2}` ? `${Rest}${Replacement}${Rest2}` : Sentence : string : string;
|
|
197
197
|
/**
|
|
198
|
-
* Type-level implementation of string.slice() functionality.
|
|
199
|
-
* Extracts a portion of a string type between start and end indices.
|
|
200
|
-
* @template T - The string type to slice
|
|
201
|
-
* @template StartIndex - The starting index of the slice
|
|
202
|
-
* @template EndIndex - The ending index of the slice (optional)
|
|
203
|
-
* @returns A string type containing the characters between the indices
|
|
204
|
-
* @example
|
|
205
|
-
* type Sliced = Slice<'hello world', 0, 5> // type Sliced = 'hello'
|
|
206
|
-
* type ToEnd = Slice<'hello world', 6> // type ToEnd = 'world'
|
|
207
|
-
*/
|
|
198
|
+
* Type-level implementation of string.slice() functionality.
|
|
199
|
+
* Extracts a portion of a string type between start and end indices.
|
|
200
|
+
* @template T - The string type to slice
|
|
201
|
+
* @template StartIndex - The starting index of the slice
|
|
202
|
+
* @template EndIndex - The ending index of the slice (optional)
|
|
203
|
+
* @returns A string type containing the characters between the indices
|
|
204
|
+
* @example
|
|
205
|
+
* type Sliced = Slice<'hello world', 0, 5> // type Sliced = 'hello'
|
|
206
|
+
* type ToEnd = Slice<'hello world', 6> // type ToEnd = 'world'
|
|
207
|
+
*/
|
|
208
208
|
type Slice<T extends string, StartIndex extends number = 0, EndIndex extends number | undefined = undefined> = EndIndex extends number ? InternalSliceType<T, StartIndex, EndIndex> : SliceStartType<T, StartIndex>;
|
|
209
209
|
/**
|
|
210
|
-
* Type-level implementation of string.split() functionality.
|
|
211
|
-
* Splits a string type into a tuple of string types based on a delimiter.
|
|
212
|
-
* @template T - The string type to split
|
|
213
|
-
* @template Delimiter - The string type to use as a separator
|
|
214
|
-
* @returns A tuple type containing the split string parts
|
|
215
|
-
* @example
|
|
216
|
-
* type Parts = Split<'a,b,c', ','> // type Parts = ['a', 'b', 'c']
|
|
217
|
-
*/
|
|
210
|
+
* Type-level implementation of string.split() functionality.
|
|
211
|
+
* Splits a string type into a tuple of string types based on a delimiter.
|
|
212
|
+
* @template T - The string type to split
|
|
213
|
+
* @template Delimiter - The string type to use as a separator
|
|
214
|
+
* @returns A tuple type containing the split string parts
|
|
215
|
+
* @example
|
|
216
|
+
* type Parts = Split<'a,b,c', ','> // type Parts = ['a', 'b', 'c']
|
|
217
|
+
*/
|
|
218
218
|
type Split<T extends string, Delimiter extends string = ""> = IsStringLiteral<Delimiter | T> extends true ? T extends `${infer First}${Delimiter}${infer Rest}` ? [First, ...Split<Rest, Delimiter>] : T extends "" ? [] : [T] : string[];
|
|
219
219
|
/**
|
|
220
|
-
* Type-level implementation of string.startsWith() functionality.
|
|
221
|
-
* Checks if a string type begins with another string type at a given position.
|
|
222
|
-
* @template T - The string type to check
|
|
223
|
-
* @template S - The prefix to check for
|
|
224
|
-
* @template P - Optional position at which to start the search
|
|
225
|
-
* @returns A boolean type indicating if T starts with S at position P
|
|
226
|
-
* @example
|
|
227
|
-
* type StartsWithHello = StartsWith<'hello world', 'hello'> // type StartsWithHello = true
|
|
228
|
-
* type DoesNotStart = StartsWith<'hello world', 'world'> // type DoesNotStart = false
|
|
229
|
-
*/
|
|
220
|
+
* Type-level implementation of string.startsWith() functionality.
|
|
221
|
+
* Checks if a string type begins with another string type at a given position.
|
|
222
|
+
* @template T - The string type to check
|
|
223
|
+
* @template S - The prefix to check for
|
|
224
|
+
* @template P - Optional position at which to start the search
|
|
225
|
+
* @returns A boolean type indicating if T starts with S at position P
|
|
226
|
+
* @example
|
|
227
|
+
* type StartsWithHello = StartsWith<'hello world', 'hello'> // type StartsWithHello = true
|
|
228
|
+
* type DoesNotStart = StartsWith<'hello world', 'world'> // type DoesNotStart = false
|
|
229
|
+
*/
|
|
230
230
|
type StartsWith<T extends string, S extends string, P extends number = 0> = All<[IsStringLiteral<S>, IsNumberLiteral<P>]> extends true ? Math.IsNegative<P> extends false ? P extends 0 ? S extends `${infer SHead}${infer SRest}` ? T extends `${infer THead}${infer TRest}` ? IsStringLiteral<SHead | THead> extends true ? THead extends SHead ? StartsWith<TRest, SRest> : false : boolean : IsStringLiteral<T> extends true ? false : boolean : true : StartsWith<Slice<T, P>, S> : StartsWith<T, S> : boolean;
|
|
231
231
|
/**
|
|
232
|
-
* Type-level implementation of string.trimEnd() functionality.
|
|
233
|
-
* Removes whitespace characters from the end of a string type.
|
|
234
|
-
* @template T - The string type to trim
|
|
235
|
-
* @returns A string type with trailing whitespace removed
|
|
236
|
-
* @example
|
|
237
|
-
* type Trimmed = TrimEnd<'hello '> // type Trimmed = 'hello'
|
|
238
|
-
*/
|
|
232
|
+
* Type-level implementation of string.trimEnd() functionality.
|
|
233
|
+
* Removes whitespace characters from the end of a string type.
|
|
234
|
+
* @template T - The string type to trim
|
|
235
|
+
* @returns A string type with trailing whitespace removed
|
|
236
|
+
* @example
|
|
237
|
+
* type Trimmed = TrimEnd<'hello '> // type Trimmed = 'hello'
|
|
238
|
+
*/
|
|
239
239
|
type TrimEnd<T extends string> = T extends `${infer Rest} ` ? TrimEnd<Rest> : T;
|
|
240
240
|
/**
|
|
241
|
-
* Type-level implementation of string.trimStart() functionality.
|
|
242
|
-
* Removes whitespace characters from the beginning of a string type.
|
|
243
|
-
* @template T - The string type to trim
|
|
244
|
-
* @returns A string type with leading whitespace removed
|
|
245
|
-
* @example
|
|
246
|
-
* type Trimmed = TrimStart<' hello'> // type Trimmed = 'hello'
|
|
247
|
-
*/
|
|
241
|
+
* Type-level implementation of string.trimStart() functionality.
|
|
242
|
+
* Removes whitespace characters from the beginning of a string type.
|
|
243
|
+
* @template T - The string type to trim
|
|
244
|
+
* @returns A string type with leading whitespace removed
|
|
245
|
+
* @example
|
|
246
|
+
* type Trimmed = TrimStart<' hello'> // type Trimmed = 'hello'
|
|
247
|
+
*/
|
|
248
248
|
type TrimStart<T extends string> = T extends ` ${infer Rest}` ? TrimStart<Rest> : T;
|
|
249
249
|
/**
|
|
250
|
-
* Type-level implementation of string.trim() functionality.
|
|
251
|
-
* Removes whitespace characters from both ends of a string type.
|
|
252
|
-
* @template T - The string type to trim
|
|
253
|
-
* @returns A string type with both leading and trailing whitespace removed
|
|
254
|
-
* @example
|
|
255
|
-
* type Trimmed = Trim<' hello '> // type Trimmed = 'hello'
|
|
256
|
-
*/
|
|
250
|
+
* Type-level implementation of string.trim() functionality.
|
|
251
|
+
* Removes whitespace characters from both ends of a string type.
|
|
252
|
+
* @template T - The string type to trim
|
|
253
|
+
* @returns A string type with both leading and trailing whitespace removed
|
|
254
|
+
* @example
|
|
255
|
+
* type Trimmed = Trim<' hello '> // type Trimmed = 'hello'
|
|
256
|
+
*/
|
|
257
257
|
type Trim<T extends string> = TrimEnd<TrimStart<T>>;
|
|
258
258
|
/**
|
|
259
|
-
* Type-level implementation of string.toLowerCase() functionality.
|
|
260
|
-
* Converts all alphabetic characters in a string type to lowercase.
|
|
261
|
-
* @template T - The string type to convert
|
|
262
|
-
* @returns A string type with all characters converted to lowercase
|
|
263
|
-
* @example
|
|
264
|
-
* type Lower = ToLowerCase<'HELLO'> // type Lower = 'hello'
|
|
265
|
-
*/
|
|
259
|
+
* Type-level implementation of string.toLowerCase() functionality.
|
|
260
|
+
* Converts all alphabetic characters in a string type to lowercase.
|
|
261
|
+
* @template T - The string type to convert
|
|
262
|
+
* @returns A string type with all characters converted to lowercase
|
|
263
|
+
* @example
|
|
264
|
+
* type Lower = ToLowerCase<'HELLO'> // type Lower = 'hello'
|
|
265
|
+
*/
|
|
266
266
|
type ToLowerCase<T extends string> = IsStringLiteral<T> extends true ? Lowercase<T> : string;
|
|
267
267
|
/**
|
|
268
|
-
* Type-level implementation of string.toUpperCase() functionality.
|
|
269
|
-
* Converts all alphabetic characters in a string type to uppercase.
|
|
270
|
-
* @template T - The string type to convert
|
|
271
|
-
* @returns A string type with all characters converted to uppercase
|
|
272
|
-
* @example
|
|
273
|
-
* type Upper = ToUpperCase<'hello'> // type Upper = 'HELLO'
|
|
274
|
-
*/
|
|
268
|
+
* Type-level implementation of string.toUpperCase() functionality.
|
|
269
|
+
* Converts all alphabetic characters in a string type to uppercase.
|
|
270
|
+
* @template T - The string type to convert
|
|
271
|
+
* @returns A string type with all characters converted to uppercase
|
|
272
|
+
* @example
|
|
273
|
+
* type Upper = ToUpperCase<'hello'> // type Upper = 'HELLO'
|
|
274
|
+
*/
|
|
275
275
|
type ToUpperCase<T extends string> = IsStringLiteral<T> extends true ? Uppercase<T> : string;
|
|
276
276
|
declare global {
|
|
277
277
|
interface String {
|
|
@@ -280,20 +280,17 @@ declare global {
|
|
|
280
280
|
* @param index The zero-based index of the desired character.
|
|
281
281
|
*/
|
|
282
282
|
charAt<T extends string = string, I extends number = number>(this: T, index: I): CharAt<T, I>;
|
|
283
|
-
|
|
284
283
|
/**
|
|
285
284
|
* Returns a string that contains the concatenation of two or more strings.
|
|
286
285
|
* @param strings The strings to append to the end of the string.
|
|
287
286
|
*/
|
|
288
287
|
concat<T extends string = string, S extends string[] | string = string>(this: T, ...strings: S extends string ? [S] : S extends string[] ? S : never): S extends string ? Concat<[T, S]> : S extends string[] ? Concat<[T, ...S]> : never;
|
|
289
|
-
|
|
290
288
|
/**
|
|
291
289
|
* Returns true if the sequence of elements of searchString converted to a String is the
|
|
292
290
|
* same as the corresponding elements of this object (converted to a String) starting at
|
|
293
291
|
* position. Otherwise returns false.
|
|
294
292
|
*/
|
|
295
293
|
endsWith<T extends string = string, S extends string = string, P extends number | undefined = undefined>(this: T, searchString: S, position?: P): EndsWith<T, S, P>;
|
|
296
|
-
|
|
297
294
|
/**
|
|
298
295
|
* Returns true if searchString appears as a substring of the result of converting this
|
|
299
296
|
* object to a String, at one or more positions that are greater than or equal to
|
|
@@ -302,12 +299,10 @@ declare global {
|
|
|
302
299
|
* @param position If position is undefined, 0 is assumed, so as to search all of the String.
|
|
303
300
|
*/
|
|
304
301
|
includes<T extends string = string, S extends string = string, P extends number = 0>(this: T, searchString: S, position?: P): Includes<T, S, P>;
|
|
305
|
-
|
|
306
302
|
/**
|
|
307
303
|
* Returns the length of a String object.
|
|
308
304
|
*/
|
|
309
305
|
length: Length<this>;
|
|
310
|
-
|
|
311
306
|
/**
|
|
312
307
|
* Pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length.
|
|
313
308
|
* The padding is applied from the end (right) of the current string.
|
|
@@ -315,7 +310,6 @@ declare global {
|
|
|
315
310
|
* @param fillString The string to pad the current string with. If this string is too long, it will be truncated and the left-most part will be applied.
|
|
316
311
|
*/
|
|
317
312
|
padEnd<T extends string = string, N extends number = number, P extends string = " ">(this: T, maxLength: N, fillString?: P): PadEnd<T, N, P>;
|
|
318
|
-
|
|
319
313
|
/**
|
|
320
314
|
* Pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length.
|
|
321
315
|
* The padding is applied from the start (left) of the current string.
|
|
@@ -323,61 +317,51 @@ declare global {
|
|
|
323
317
|
* @param fillString The string to pad the current string with. If this string is too long, it will be truncated and the left-most part will be applied.
|
|
324
318
|
*/
|
|
325
319
|
padStart<T extends string = string, N extends number = number, P extends string = " ">(this: T, maxLength: N, fillString?: P): PadStart<T, N, P>;
|
|
326
|
-
|
|
327
320
|
/**
|
|
328
321
|
* Replace text in a string, using a regular expression or search string.
|
|
329
322
|
* @param searchValue A string to search for.
|
|
330
323
|
* @param replaceValue A string containing the text to replace for every successful match of searchValue in this string.
|
|
331
324
|
*/
|
|
332
325
|
replace<T extends string = string, S extends RegExp | string = string, R extends string = string>(this: T, searchValue: S, replaceValue: R): Replace<T, S, R>;
|
|
333
|
-
|
|
334
326
|
/**
|
|
335
327
|
* Replace all instances of a substring in a string, using a regular expression or search string.
|
|
336
328
|
* @param searchValue A string to search for.
|
|
337
329
|
* @param replaceValue A string containing the text to replace for every successful match of searchValue in this string.
|
|
338
330
|
*/
|
|
339
331
|
replaceAll<T extends string = string, S extends RegExp | string = string, R extends string = string>(this: T, searchValue: S, replaceValue: R): ReplaceAll<T, S, R>;
|
|
340
|
-
|
|
341
332
|
/**
|
|
342
333
|
* Returns a section of a string.
|
|
343
334
|
* @param start The index to the beginning of the specified portion of stringObj.
|
|
344
335
|
* @param end The index to the end of the specified portion of stringObj. The substring includes the characters up to, but not including, the character indicated by end.
|
|
345
336
|
*/
|
|
346
337
|
slice<T extends string = string, S extends number = number, E extends number | undefined = undefined>(this: T, start?: S, end?: E): Slice<T, S, E>;
|
|
347
|
-
|
|
348
338
|
/**
|
|
349
339
|
* Split a string into substrings using the specified separator and return them as an array.
|
|
350
340
|
* @param separator A string that identifies character or characters to use in separating the string. If omitted, a single-element array containing the entire string is returned.
|
|
351
341
|
*/
|
|
352
342
|
split<T extends string = string, S extends string = string>(this: T, separator: S): Split<T, S>;
|
|
353
|
-
|
|
354
343
|
/**
|
|
355
344
|
* Returns true if the sequence of elements of searchString converted to a String is the
|
|
356
345
|
* same as the corresponding elements of this object (converted to a String) starting at
|
|
357
346
|
* position. Otherwise returns false.
|
|
358
347
|
*/
|
|
359
348
|
startsWith<T extends string = string, S extends string = string, P extends number = 0>(this: T, searchString: S, position?: P): StartsWith<T, S, P>;
|
|
360
|
-
|
|
361
349
|
/**
|
|
362
350
|
* Converts all alphabetic characters in a string to lowercase.
|
|
363
351
|
*/
|
|
364
352
|
toLowerCase<T extends string = string>(this: T): ToLowerCase<T>;
|
|
365
|
-
|
|
366
353
|
/**
|
|
367
354
|
* Converts all alphabetic characters in a string to uppercase.
|
|
368
355
|
*/
|
|
369
356
|
toUpperCase<T extends string = string>(this: T): ToUpperCase<T>;
|
|
370
|
-
|
|
371
357
|
/**
|
|
372
358
|
* Returns a string with all whitespace removed from both ends of a string.
|
|
373
359
|
*/
|
|
374
360
|
trim<T extends string = string>(this: T): Trim<T>;
|
|
375
|
-
|
|
376
361
|
/**
|
|
377
362
|
* Returns a string with all whitespace removed from the end of a string.
|
|
378
363
|
*/
|
|
379
364
|
trimEnd<T extends string = string>(this: T): TrimEnd<T>;
|
|
380
|
-
|
|
381
365
|
/**
|
|
382
366
|
* Returns a string with all whitespace removed from the start of a string.
|
|
383
367
|
*/
|