@synstack/str 1.0.1-alpha.0
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/README.md +1 -0
- package/dist/str.index.cjs +441 -0
- package/dist/str.index.cjs.map +1 -0
- package/dist/str.index.d.cts +261 -0
- package/dist/str.index.d.ts +261 -0
- package/dist/str.index.js +384 -0
- package/dist/str.index.js.map +1 -0
- package/package.json +66 -0
- package/src/str.bundle.ts +16 -0
- package/src/str.chainable.ts +291 -0
- package/src/str.index.ts +2 -0
- package/src/str.lib.ts +186 -0
@@ -0,0 +1,261 @@
|
|
1
|
+
export { camelCase, capitalCase, constantCase, dotCase, kebabCase, noCase, pascalCase, pascalSnakeCase, pathCase, sentenceCase, snakeCase, trainCase } from 'change-case';
|
2
|
+
import { Pipeable } from '@synstack/pipe';
|
3
|
+
|
4
|
+
type Stringable = {
|
5
|
+
toString: () => string;
|
6
|
+
};
|
7
|
+
declare class Str extends Pipeable<Str, string> {
|
8
|
+
private readonly text;
|
9
|
+
constructor(text: string);
|
10
|
+
valueOf(): string;
|
11
|
+
toString(): string;
|
12
|
+
instanceOf(): Str;
|
13
|
+
/**
|
14
|
+
* Remove empty lines at the start of the text but leave whitespace on the first line with content
|
15
|
+
*/
|
16
|
+
chopEmptyLinesStart(): Str;
|
17
|
+
/**
|
18
|
+
* Remove empty lines at the end of the text but leave whitespace on the last line with content
|
19
|
+
*/
|
20
|
+
chopEmptyLinesEnd(): Str;
|
21
|
+
/**
|
22
|
+
* Remove all space (\s) characters in lines without content
|
23
|
+
*/
|
24
|
+
trimEmptyLines(): Str;
|
25
|
+
/**
|
26
|
+
* Remove all spaces (\s) characters at the end of lines
|
27
|
+
*/
|
28
|
+
trimLinesTrailingSpaces(): Str;
|
29
|
+
/**
|
30
|
+
* Removes the leading and trailing white space and line terminator characters
|
31
|
+
*/
|
32
|
+
trim(): Str;
|
33
|
+
/**
|
34
|
+
* Removes the leading white space and line terminator characters
|
35
|
+
*/
|
36
|
+
trimStart(): Str;
|
37
|
+
/**
|
38
|
+
* Removes the trailing white space and line terminator characters
|
39
|
+
*/
|
40
|
+
trimEnd(): Str;
|
41
|
+
/**
|
42
|
+
* Split a string into substrings using the specified separator and return them as an array
|
43
|
+
*/
|
44
|
+
split(separator: string | RegExp, limit?: number): Str[];
|
45
|
+
/**
|
46
|
+
* Add line numbers to a string
|
47
|
+
* @param separator The separator to use between the line number and the line content.
|
48
|
+
* Defaults to ":"
|
49
|
+
*/
|
50
|
+
addLineNumbers(separator?: string): Str;
|
51
|
+
/**
|
52
|
+
* Returns the character at the specified index
|
53
|
+
* @return string or undefined if the index is out of bounds
|
54
|
+
*/
|
55
|
+
at(index: number): string | undefined;
|
56
|
+
/**
|
57
|
+
* Returns the length of the string
|
58
|
+
*/
|
59
|
+
length(): number;
|
60
|
+
/**
|
61
|
+
* Indent the string by the specified number of spaces
|
62
|
+
* @param size The number of spaces to indent by
|
63
|
+
* @param char The character to use for indentation. Defaults to " "
|
64
|
+
*/
|
65
|
+
indent(size: number, char?: string): Str;
|
66
|
+
/**
|
67
|
+
* Dedent the string by the specified number of spaces
|
68
|
+
* @param indentation The number of spaces to dedent by.
|
69
|
+
* If not provided, it will be calculated automatically based on the maximum indentation in the string.
|
70
|
+
*/
|
71
|
+
dedent(indentation?: number): Str;
|
72
|
+
/**
|
73
|
+
* Chop the string at the start by the specified number of characters
|
74
|
+
*/
|
75
|
+
chopStart(count: number): Str;
|
76
|
+
/**
|
77
|
+
* Chop the string at the end by the specified number of characters
|
78
|
+
*/
|
79
|
+
chopEnd(count: number): Str;
|
80
|
+
/**
|
81
|
+
* Remove successive newlines of the specified repetition or more
|
82
|
+
* @param maxRepeat the maximum number of newlines to allow
|
83
|
+
*/
|
84
|
+
chopRepeatNewlines(maxRepeat: number): Str;
|
85
|
+
/**
|
86
|
+
* Take the first n characters of the string
|
87
|
+
*/
|
88
|
+
takeStart(count: number): Str;
|
89
|
+
/**
|
90
|
+
* Take the last n characters of the string
|
91
|
+
*/
|
92
|
+
takeEnd(count: number): Str;
|
93
|
+
/**
|
94
|
+
* Returns the last line of the string
|
95
|
+
*/
|
96
|
+
lastLine(): Str;
|
97
|
+
/**
|
98
|
+
* Returns the first line of the string
|
99
|
+
*/
|
100
|
+
firstLine(): Str;
|
101
|
+
/**
|
102
|
+
* Returns the number of leading spaces in the string
|
103
|
+
*/
|
104
|
+
leadingSpacesCount(): number;
|
105
|
+
/**
|
106
|
+
* Returns the indentation level of the string skipping empty lines in the process
|
107
|
+
*/
|
108
|
+
indentation(): number;
|
109
|
+
/**
|
110
|
+
* Returns true if the string is empty or contains only whitespace
|
111
|
+
*/
|
112
|
+
isEmpty(): boolean;
|
113
|
+
/**
|
114
|
+
* Converts the string to camel case
|
115
|
+
*/
|
116
|
+
camelCase(): Str;
|
117
|
+
/**
|
118
|
+
* Converts the string to capital case
|
119
|
+
*/
|
120
|
+
capitalCase(): Str;
|
121
|
+
/**
|
122
|
+
* Converts the string to constant case
|
123
|
+
*/
|
124
|
+
constantCase(): Str;
|
125
|
+
/**
|
126
|
+
* Converts the string to dot case
|
127
|
+
*/
|
128
|
+
dotCase(): Str;
|
129
|
+
/**
|
130
|
+
* Converts the string to kebab case
|
131
|
+
*/
|
132
|
+
kebabCase(): Str;
|
133
|
+
/**
|
134
|
+
* Converts the string to no case
|
135
|
+
*/
|
136
|
+
noCase(): Str;
|
137
|
+
/**
|
138
|
+
* Converts the string to pascal case
|
139
|
+
*/
|
140
|
+
pascalCase(): Str;
|
141
|
+
/**
|
142
|
+
* Converts the string to pascal snake case
|
143
|
+
*/
|
144
|
+
pascalSnakeCase(): Str;
|
145
|
+
/**
|
146
|
+
* Converts the string to path case
|
147
|
+
*/
|
148
|
+
pathCase(): Str;
|
149
|
+
/**
|
150
|
+
* Converts the string to sentence case
|
151
|
+
*/
|
152
|
+
sentenceCase(): Str;
|
153
|
+
/**
|
154
|
+
* Converts the string to snake case
|
155
|
+
*/
|
156
|
+
snakeCase(): Str;
|
157
|
+
/**
|
158
|
+
* Converts the string to train case
|
159
|
+
*/
|
160
|
+
trainCase(): Str;
|
161
|
+
/**
|
162
|
+
* Shorthand for `.toString()`
|
163
|
+
*/
|
164
|
+
get str(): string;
|
165
|
+
}
|
166
|
+
declare const str: (text: Stringable) => Str;
|
167
|
+
|
168
|
+
/**
|
169
|
+
* Remove empty lines at the start of the text but leave whitespace on the first line with content
|
170
|
+
*/
|
171
|
+
declare const chopEmptyLinesStart: (text: string) => string;
|
172
|
+
/**
|
173
|
+
* Remove empty lines at the end of the text but leave whitespace on the last line with content
|
174
|
+
*/
|
175
|
+
declare const chopEmptyLinesEnd: (text: string) => string;
|
176
|
+
/**
|
177
|
+
* Remove all space (\s) characters in lines without content
|
178
|
+
*/
|
179
|
+
declare const trimEmptyLines: (text: string) => string;
|
180
|
+
/**
|
181
|
+
* Remove all space (\s) characters at the end of lines
|
182
|
+
*/
|
183
|
+
declare const trimLinesTrailingSpaces: (text: string) => string;
|
184
|
+
/**
|
185
|
+
* Removes the leading and trailing white space and line terminator characters
|
186
|
+
*/
|
187
|
+
declare const trim: (text: string) => string;
|
188
|
+
/**
|
189
|
+
* Removes the leading white space and line terminator characters
|
190
|
+
*/
|
191
|
+
declare const trimStart: (text: string) => string;
|
192
|
+
/**
|
193
|
+
* Removes the trailing white space and line terminator characters
|
194
|
+
*/
|
195
|
+
declare const trimEnd: (text: string) => string;
|
196
|
+
/**
|
197
|
+
* Split a string into substrings using the specified separator and return them as an array
|
198
|
+
*/
|
199
|
+
declare const split: (text: string, separator: string | RegExp, limit?: number) => string[];
|
200
|
+
/**
|
201
|
+
* Add line numbers to a string
|
202
|
+
* @param text The string to add line numbers to
|
203
|
+
* @param separator The separator to use between the line number and the line content.
|
204
|
+
* Defaults to ":"
|
205
|
+
*/
|
206
|
+
declare const addLineNumbers: (text: string, separator?: string) => string;
|
207
|
+
/**
|
208
|
+
* Returns the indentation level of the string skipping empty lines in the process
|
209
|
+
*/
|
210
|
+
declare const indentation: (text: string) => number;
|
211
|
+
/**
|
212
|
+
* Indent the string by the specified number of spaces
|
213
|
+
* @param size The number of spaces to indent by
|
214
|
+
* @param char The character to use for indentation. Defaults to " "
|
215
|
+
*/
|
216
|
+
declare const indent: (text: string, size: number, char?: string) => string;
|
217
|
+
/**
|
218
|
+
* Dedent the string by the specified number of spaces
|
219
|
+
* @param indentation The number of spaces to dedent by.
|
220
|
+
* If not provided, it will be calculated automatically based on the maximum indentation in the string.
|
221
|
+
*/
|
222
|
+
declare const dedent: (text: string, size?: number) => string;
|
223
|
+
/**
|
224
|
+
* Chop the string at the end by the specified number of characters
|
225
|
+
*/
|
226
|
+
declare const chopEnd: (text: string, count: number) => string;
|
227
|
+
/**
|
228
|
+
* Chop the string at the start by the specified number of characters
|
229
|
+
*/
|
230
|
+
declare const chopStart: (text: string, count: number) => string;
|
231
|
+
/**
|
232
|
+
* Remove successive newlines of the specified repetition or more
|
233
|
+
* @param maxRepeat the maximum number of newlines to allow
|
234
|
+
*/
|
235
|
+
declare const chopRepeatNewlines: (text: string, maxRepeat: number) => string;
|
236
|
+
/**
|
237
|
+
* Take the first n characters of the string
|
238
|
+
*/
|
239
|
+
declare const takeStart: (text: string, count: number) => string;
|
240
|
+
/**
|
241
|
+
* Take the last n characters of the string
|
242
|
+
*/
|
243
|
+
declare const takeEnd: (text: string, count: number) => string;
|
244
|
+
/**
|
245
|
+
* Returns the last line of the string
|
246
|
+
*/
|
247
|
+
declare const lastLine: (text: string) => string;
|
248
|
+
/**
|
249
|
+
* Returns the first line of the string
|
250
|
+
*/
|
251
|
+
declare const firstLine: (text: string) => string;
|
252
|
+
/**
|
253
|
+
* Returns the number of leading spaces in the string
|
254
|
+
*/
|
255
|
+
declare const leadingSpacesCount: (text: string) => number;
|
256
|
+
/**
|
257
|
+
* Returns true if the string is empty or contains only whitespace
|
258
|
+
*/
|
259
|
+
declare const isEmpty: (text: string) => boolean;
|
260
|
+
|
261
|
+
export { Str, addLineNumbers, chopEmptyLinesEnd, chopEmptyLinesStart, chopEnd, chopRepeatNewlines, chopStart, dedent, firstLine, indent, indentation, isEmpty, lastLine, leadingSpacesCount, split, str, takeEnd, takeStart, trim, trimEmptyLines, trimEnd, trimLinesTrailingSpaces, trimStart };
|
@@ -0,0 +1,261 @@
|
|
1
|
+
export { camelCase, capitalCase, constantCase, dotCase, kebabCase, noCase, pascalCase, pascalSnakeCase, pathCase, sentenceCase, snakeCase, trainCase } from 'change-case';
|
2
|
+
import { Pipeable } from '@synstack/pipe';
|
3
|
+
|
4
|
+
type Stringable = {
|
5
|
+
toString: () => string;
|
6
|
+
};
|
7
|
+
declare class Str extends Pipeable<Str, string> {
|
8
|
+
private readonly text;
|
9
|
+
constructor(text: string);
|
10
|
+
valueOf(): string;
|
11
|
+
toString(): string;
|
12
|
+
instanceOf(): Str;
|
13
|
+
/**
|
14
|
+
* Remove empty lines at the start of the text but leave whitespace on the first line with content
|
15
|
+
*/
|
16
|
+
chopEmptyLinesStart(): Str;
|
17
|
+
/**
|
18
|
+
* Remove empty lines at the end of the text but leave whitespace on the last line with content
|
19
|
+
*/
|
20
|
+
chopEmptyLinesEnd(): Str;
|
21
|
+
/**
|
22
|
+
* Remove all space (\s) characters in lines without content
|
23
|
+
*/
|
24
|
+
trimEmptyLines(): Str;
|
25
|
+
/**
|
26
|
+
* Remove all spaces (\s) characters at the end of lines
|
27
|
+
*/
|
28
|
+
trimLinesTrailingSpaces(): Str;
|
29
|
+
/**
|
30
|
+
* Removes the leading and trailing white space and line terminator characters
|
31
|
+
*/
|
32
|
+
trim(): Str;
|
33
|
+
/**
|
34
|
+
* Removes the leading white space and line terminator characters
|
35
|
+
*/
|
36
|
+
trimStart(): Str;
|
37
|
+
/**
|
38
|
+
* Removes the trailing white space and line terminator characters
|
39
|
+
*/
|
40
|
+
trimEnd(): Str;
|
41
|
+
/**
|
42
|
+
* Split a string into substrings using the specified separator and return them as an array
|
43
|
+
*/
|
44
|
+
split(separator: string | RegExp, limit?: number): Str[];
|
45
|
+
/**
|
46
|
+
* Add line numbers to a string
|
47
|
+
* @param separator The separator to use between the line number and the line content.
|
48
|
+
* Defaults to ":"
|
49
|
+
*/
|
50
|
+
addLineNumbers(separator?: string): Str;
|
51
|
+
/**
|
52
|
+
* Returns the character at the specified index
|
53
|
+
* @return string or undefined if the index is out of bounds
|
54
|
+
*/
|
55
|
+
at(index: number): string | undefined;
|
56
|
+
/**
|
57
|
+
* Returns the length of the string
|
58
|
+
*/
|
59
|
+
length(): number;
|
60
|
+
/**
|
61
|
+
* Indent the string by the specified number of spaces
|
62
|
+
* @param size The number of spaces to indent by
|
63
|
+
* @param char The character to use for indentation. Defaults to " "
|
64
|
+
*/
|
65
|
+
indent(size: number, char?: string): Str;
|
66
|
+
/**
|
67
|
+
* Dedent the string by the specified number of spaces
|
68
|
+
* @param indentation The number of spaces to dedent by.
|
69
|
+
* If not provided, it will be calculated automatically based on the maximum indentation in the string.
|
70
|
+
*/
|
71
|
+
dedent(indentation?: number): Str;
|
72
|
+
/**
|
73
|
+
* Chop the string at the start by the specified number of characters
|
74
|
+
*/
|
75
|
+
chopStart(count: number): Str;
|
76
|
+
/**
|
77
|
+
* Chop the string at the end by the specified number of characters
|
78
|
+
*/
|
79
|
+
chopEnd(count: number): Str;
|
80
|
+
/**
|
81
|
+
* Remove successive newlines of the specified repetition or more
|
82
|
+
* @param maxRepeat the maximum number of newlines to allow
|
83
|
+
*/
|
84
|
+
chopRepeatNewlines(maxRepeat: number): Str;
|
85
|
+
/**
|
86
|
+
* Take the first n characters of the string
|
87
|
+
*/
|
88
|
+
takeStart(count: number): Str;
|
89
|
+
/**
|
90
|
+
* Take the last n characters of the string
|
91
|
+
*/
|
92
|
+
takeEnd(count: number): Str;
|
93
|
+
/**
|
94
|
+
* Returns the last line of the string
|
95
|
+
*/
|
96
|
+
lastLine(): Str;
|
97
|
+
/**
|
98
|
+
* Returns the first line of the string
|
99
|
+
*/
|
100
|
+
firstLine(): Str;
|
101
|
+
/**
|
102
|
+
* Returns the number of leading spaces in the string
|
103
|
+
*/
|
104
|
+
leadingSpacesCount(): number;
|
105
|
+
/**
|
106
|
+
* Returns the indentation level of the string skipping empty lines in the process
|
107
|
+
*/
|
108
|
+
indentation(): number;
|
109
|
+
/**
|
110
|
+
* Returns true if the string is empty or contains only whitespace
|
111
|
+
*/
|
112
|
+
isEmpty(): boolean;
|
113
|
+
/**
|
114
|
+
* Converts the string to camel case
|
115
|
+
*/
|
116
|
+
camelCase(): Str;
|
117
|
+
/**
|
118
|
+
* Converts the string to capital case
|
119
|
+
*/
|
120
|
+
capitalCase(): Str;
|
121
|
+
/**
|
122
|
+
* Converts the string to constant case
|
123
|
+
*/
|
124
|
+
constantCase(): Str;
|
125
|
+
/**
|
126
|
+
* Converts the string to dot case
|
127
|
+
*/
|
128
|
+
dotCase(): Str;
|
129
|
+
/**
|
130
|
+
* Converts the string to kebab case
|
131
|
+
*/
|
132
|
+
kebabCase(): Str;
|
133
|
+
/**
|
134
|
+
* Converts the string to no case
|
135
|
+
*/
|
136
|
+
noCase(): Str;
|
137
|
+
/**
|
138
|
+
* Converts the string to pascal case
|
139
|
+
*/
|
140
|
+
pascalCase(): Str;
|
141
|
+
/**
|
142
|
+
* Converts the string to pascal snake case
|
143
|
+
*/
|
144
|
+
pascalSnakeCase(): Str;
|
145
|
+
/**
|
146
|
+
* Converts the string to path case
|
147
|
+
*/
|
148
|
+
pathCase(): Str;
|
149
|
+
/**
|
150
|
+
* Converts the string to sentence case
|
151
|
+
*/
|
152
|
+
sentenceCase(): Str;
|
153
|
+
/**
|
154
|
+
* Converts the string to snake case
|
155
|
+
*/
|
156
|
+
snakeCase(): Str;
|
157
|
+
/**
|
158
|
+
* Converts the string to train case
|
159
|
+
*/
|
160
|
+
trainCase(): Str;
|
161
|
+
/**
|
162
|
+
* Shorthand for `.toString()`
|
163
|
+
*/
|
164
|
+
get str(): string;
|
165
|
+
}
|
166
|
+
declare const str: (text: Stringable) => Str;
|
167
|
+
|
168
|
+
/**
|
169
|
+
* Remove empty lines at the start of the text but leave whitespace on the first line with content
|
170
|
+
*/
|
171
|
+
declare const chopEmptyLinesStart: (text: string) => string;
|
172
|
+
/**
|
173
|
+
* Remove empty lines at the end of the text but leave whitespace on the last line with content
|
174
|
+
*/
|
175
|
+
declare const chopEmptyLinesEnd: (text: string) => string;
|
176
|
+
/**
|
177
|
+
* Remove all space (\s) characters in lines without content
|
178
|
+
*/
|
179
|
+
declare const trimEmptyLines: (text: string) => string;
|
180
|
+
/**
|
181
|
+
* Remove all space (\s) characters at the end of lines
|
182
|
+
*/
|
183
|
+
declare const trimLinesTrailingSpaces: (text: string) => string;
|
184
|
+
/**
|
185
|
+
* Removes the leading and trailing white space and line terminator characters
|
186
|
+
*/
|
187
|
+
declare const trim: (text: string) => string;
|
188
|
+
/**
|
189
|
+
* Removes the leading white space and line terminator characters
|
190
|
+
*/
|
191
|
+
declare const trimStart: (text: string) => string;
|
192
|
+
/**
|
193
|
+
* Removes the trailing white space and line terminator characters
|
194
|
+
*/
|
195
|
+
declare const trimEnd: (text: string) => string;
|
196
|
+
/**
|
197
|
+
* Split a string into substrings using the specified separator and return them as an array
|
198
|
+
*/
|
199
|
+
declare const split: (text: string, separator: string | RegExp, limit?: number) => string[];
|
200
|
+
/**
|
201
|
+
* Add line numbers to a string
|
202
|
+
* @param text The string to add line numbers to
|
203
|
+
* @param separator The separator to use between the line number and the line content.
|
204
|
+
* Defaults to ":"
|
205
|
+
*/
|
206
|
+
declare const addLineNumbers: (text: string, separator?: string) => string;
|
207
|
+
/**
|
208
|
+
* Returns the indentation level of the string skipping empty lines in the process
|
209
|
+
*/
|
210
|
+
declare const indentation: (text: string) => number;
|
211
|
+
/**
|
212
|
+
* Indent the string by the specified number of spaces
|
213
|
+
* @param size The number of spaces to indent by
|
214
|
+
* @param char The character to use for indentation. Defaults to " "
|
215
|
+
*/
|
216
|
+
declare const indent: (text: string, size: number, char?: string) => string;
|
217
|
+
/**
|
218
|
+
* Dedent the string by the specified number of spaces
|
219
|
+
* @param indentation The number of spaces to dedent by.
|
220
|
+
* If not provided, it will be calculated automatically based on the maximum indentation in the string.
|
221
|
+
*/
|
222
|
+
declare const dedent: (text: string, size?: number) => string;
|
223
|
+
/**
|
224
|
+
* Chop the string at the end by the specified number of characters
|
225
|
+
*/
|
226
|
+
declare const chopEnd: (text: string, count: number) => string;
|
227
|
+
/**
|
228
|
+
* Chop the string at the start by the specified number of characters
|
229
|
+
*/
|
230
|
+
declare const chopStart: (text: string, count: number) => string;
|
231
|
+
/**
|
232
|
+
* Remove successive newlines of the specified repetition or more
|
233
|
+
* @param maxRepeat the maximum number of newlines to allow
|
234
|
+
*/
|
235
|
+
declare const chopRepeatNewlines: (text: string, maxRepeat: number) => string;
|
236
|
+
/**
|
237
|
+
* Take the first n characters of the string
|
238
|
+
*/
|
239
|
+
declare const takeStart: (text: string, count: number) => string;
|
240
|
+
/**
|
241
|
+
* Take the last n characters of the string
|
242
|
+
*/
|
243
|
+
declare const takeEnd: (text: string, count: number) => string;
|
244
|
+
/**
|
245
|
+
* Returns the last line of the string
|
246
|
+
*/
|
247
|
+
declare const lastLine: (text: string) => string;
|
248
|
+
/**
|
249
|
+
* Returns the first line of the string
|
250
|
+
*/
|
251
|
+
declare const firstLine: (text: string) => string;
|
252
|
+
/**
|
253
|
+
* Returns the number of leading spaces in the string
|
254
|
+
*/
|
255
|
+
declare const leadingSpacesCount: (text: string) => number;
|
256
|
+
/**
|
257
|
+
* Returns true if the string is empty or contains only whitespace
|
258
|
+
*/
|
259
|
+
declare const isEmpty: (text: string) => boolean;
|
260
|
+
|
261
|
+
export { Str, addLineNumbers, chopEmptyLinesEnd, chopEmptyLinesStart, chopEnd, chopRepeatNewlines, chopStart, dedent, firstLine, indent, indentation, isEmpty, lastLine, leadingSpacesCount, split, str, takeEnd, takeStart, trim, trimEmptyLines, trimEnd, trimLinesTrailingSpaces, trimStart };
|