@synstack/str 1.0.1-alpha.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
package/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# @synstack/yaml
|
@@ -0,0 +1,441 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __export = (target, all) => {
|
9
|
+
for (var name in all)
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
+
};
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
+
}
|
18
|
+
return to;
|
19
|
+
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
+
|
30
|
+
// src/str.index.ts
|
31
|
+
var str_index_exports = {};
|
32
|
+
__export(str_index_exports, {
|
33
|
+
addLineNumbers: () => addLineNumbers,
|
34
|
+
camelCase: () => import_change_case.camelCase,
|
35
|
+
capitalCase: () => import_change_case.capitalCase,
|
36
|
+
chopEmptyLinesEnd: () => chopEmptyLinesEnd,
|
37
|
+
chopEmptyLinesStart: () => chopEmptyLinesStart,
|
38
|
+
chopEnd: () => chopEnd,
|
39
|
+
chopRepeatNewlines: () => chopRepeatNewlines,
|
40
|
+
chopStart: () => chopStart,
|
41
|
+
constantCase: () => import_change_case.constantCase,
|
42
|
+
dedent: () => dedent,
|
43
|
+
dotCase: () => import_change_case.dotCase,
|
44
|
+
firstLine: () => firstLine,
|
45
|
+
indent: () => indent,
|
46
|
+
indentation: () => indentation,
|
47
|
+
isEmpty: () => isEmpty,
|
48
|
+
kebabCase: () => import_change_case.kebabCase,
|
49
|
+
lastLine: () => lastLine,
|
50
|
+
leadingSpacesCount: () => leadingSpacesCount,
|
51
|
+
noCase: () => import_change_case.noCase,
|
52
|
+
pascalCase: () => import_change_case.pascalCase,
|
53
|
+
pascalSnakeCase: () => import_change_case.pascalSnakeCase,
|
54
|
+
pathCase: () => import_change_case.pathCase,
|
55
|
+
sentenceCase: () => import_change_case.sentenceCase,
|
56
|
+
snakeCase: () => import_change_case.snakeCase,
|
57
|
+
split: () => split,
|
58
|
+
str: () => str,
|
59
|
+
takeEnd: () => takeEnd,
|
60
|
+
takeStart: () => takeStart,
|
61
|
+
trainCase: () => import_change_case.trainCase,
|
62
|
+
trim: () => trim,
|
63
|
+
trimEmptyLines: () => trimEmptyLines,
|
64
|
+
trimEnd: () => trimEnd,
|
65
|
+
trimLinesTrailingSpaces: () => trimLinesTrailingSpaces,
|
66
|
+
trimStart: () => trimStart
|
67
|
+
});
|
68
|
+
module.exports = __toCommonJS(str_index_exports);
|
69
|
+
|
70
|
+
// src/str.bundle.ts
|
71
|
+
var import_change_case = require("change-case");
|
72
|
+
|
73
|
+
// src/str.chainable.ts
|
74
|
+
var import_pipe = require("@synstack/pipe");
|
75
|
+
var changeCase = __toESM(require("change-case"), 1);
|
76
|
+
|
77
|
+
// src/str.lib.ts
|
78
|
+
var chopEmptyLinesStart = (text) => {
|
79
|
+
return text.replace(/^(\s*\n)+/, "");
|
80
|
+
};
|
81
|
+
var chopEmptyLinesEnd = (text) => {
|
82
|
+
return text.replace(/(\n\s*)+$/, "");
|
83
|
+
};
|
84
|
+
var trimEmptyLines = (text) => {
|
85
|
+
return text.replace(/(^|\n)\s+(\n|$)/g, "$1$2");
|
86
|
+
};
|
87
|
+
var trimLinesTrailingSpaces = (text) => {
|
88
|
+
return text.replace(/ +(\n|$)/g, "$1");
|
89
|
+
};
|
90
|
+
var trim = (text) => {
|
91
|
+
return text.trim();
|
92
|
+
};
|
93
|
+
var trimStart = (text) => {
|
94
|
+
return text.trimStart();
|
95
|
+
};
|
96
|
+
var trimEnd = (text) => {
|
97
|
+
return text.trimEnd();
|
98
|
+
};
|
99
|
+
var split = (text, separator, limit) => {
|
100
|
+
return text.split(separator, limit);
|
101
|
+
};
|
102
|
+
var addLineNumbers = (text, separator = ":") => {
|
103
|
+
return text.split("\n").map((line, index) => `${index}${separator}${line}`).join("\n");
|
104
|
+
};
|
105
|
+
var indentation = (text) => {
|
106
|
+
return text.split("\n").reduce((acc, line) => {
|
107
|
+
if (line.trim() === "") return acc;
|
108
|
+
const indentation2 = leadingSpacesCount(line);
|
109
|
+
if (acc === null) return indentation2;
|
110
|
+
return Math.min(acc, indentation2);
|
111
|
+
}, null) ?? 0;
|
112
|
+
};
|
113
|
+
var indent = (text, size, char = " ") => {
|
114
|
+
if (size === 0) return text;
|
115
|
+
const indentStr = char.repeat(size);
|
116
|
+
return text.split("\n").map((line) => indentStr + line).join("\n");
|
117
|
+
};
|
118
|
+
var dedent = (text, size) => {
|
119
|
+
const _size = size ?? indentation(text);
|
120
|
+
if (_size === 0) return text;
|
121
|
+
const regex = new RegExp(`^\\s{1,${_size}}`);
|
122
|
+
return text.split("\n").map((line) => line.replace(regex, "")).join("\n");
|
123
|
+
};
|
124
|
+
var chopEnd = (text, count) => {
|
125
|
+
if (count === 0) return text;
|
126
|
+
return text.slice(0, -count);
|
127
|
+
};
|
128
|
+
var chopStart = (text, count) => {
|
129
|
+
if (count === 0) return text;
|
130
|
+
return text.slice(count);
|
131
|
+
};
|
132
|
+
var chopRepeatNewlines = (text, maxRepeat) => {
|
133
|
+
if (maxRepeat === 0) return text;
|
134
|
+
return text.replace(
|
135
|
+
new RegExp(`
|
136
|
+
{${maxRepeat + 1},}`, "g"),
|
137
|
+
"\n".repeat(maxRepeat)
|
138
|
+
);
|
139
|
+
};
|
140
|
+
var takeStart = (text, count) => {
|
141
|
+
return text.slice(0, count);
|
142
|
+
};
|
143
|
+
var takeEnd = (text, count) => {
|
144
|
+
return text.slice(-count);
|
145
|
+
};
|
146
|
+
var lastLine = (text) => {
|
147
|
+
return text.split("\n").at(-1) ?? "";
|
148
|
+
};
|
149
|
+
var firstLine = (text) => {
|
150
|
+
return text.split("\n").at(0) ?? "";
|
151
|
+
};
|
152
|
+
var leadingSpacesCount = (text) => {
|
153
|
+
return text.match(/^\s+/)?.at(0)?.length ?? 0;
|
154
|
+
};
|
155
|
+
var isEmpty = (text) => {
|
156
|
+
return text.trim() === "";
|
157
|
+
};
|
158
|
+
|
159
|
+
// src/str.chainable.ts
|
160
|
+
var Str = class _Str extends import_pipe.Pipeable {
|
161
|
+
constructor(text) {
|
162
|
+
super();
|
163
|
+
this.text = text;
|
164
|
+
}
|
165
|
+
valueOf() {
|
166
|
+
return this.text;
|
167
|
+
}
|
168
|
+
toString() {
|
169
|
+
return this.text;
|
170
|
+
}
|
171
|
+
instanceOf() {
|
172
|
+
return this;
|
173
|
+
}
|
174
|
+
/**
|
175
|
+
* Remove empty lines at the start of the text but leave whitespace on the first line with content
|
176
|
+
*/
|
177
|
+
chopEmptyLinesStart() {
|
178
|
+
return new _Str(chopEmptyLinesStart(this.text));
|
179
|
+
}
|
180
|
+
/**
|
181
|
+
* Remove empty lines at the end of the text but leave whitespace on the last line with content
|
182
|
+
*/
|
183
|
+
chopEmptyLinesEnd() {
|
184
|
+
return new _Str(chopEmptyLinesEnd(this.text));
|
185
|
+
}
|
186
|
+
/**
|
187
|
+
* Remove all space (\s) characters in lines without content
|
188
|
+
*/
|
189
|
+
trimEmptyLines() {
|
190
|
+
return new _Str(trimEmptyLines(this.text));
|
191
|
+
}
|
192
|
+
/**
|
193
|
+
* Remove all spaces (\s) characters at the end of lines
|
194
|
+
*/
|
195
|
+
trimLinesTrailingSpaces() {
|
196
|
+
return new _Str(trimLinesTrailingSpaces(this.text));
|
197
|
+
}
|
198
|
+
/**
|
199
|
+
* Removes the leading and trailing white space and line terminator characters
|
200
|
+
*/
|
201
|
+
trim() {
|
202
|
+
return new _Str(trim(this.text));
|
203
|
+
}
|
204
|
+
/**
|
205
|
+
* Removes the leading white space and line terminator characters
|
206
|
+
*/
|
207
|
+
trimStart() {
|
208
|
+
return new _Str(trimStart(this.text));
|
209
|
+
}
|
210
|
+
/**
|
211
|
+
* Removes the trailing white space and line terminator characters
|
212
|
+
*/
|
213
|
+
trimEnd() {
|
214
|
+
return new _Str(trimEnd(this.text));
|
215
|
+
}
|
216
|
+
/**
|
217
|
+
* Split a string into substrings using the specified separator and return them as an array
|
218
|
+
*/
|
219
|
+
split(separator, limit) {
|
220
|
+
return split(this.text, separator, limit).map((v) => new _Str(v));
|
221
|
+
}
|
222
|
+
/**
|
223
|
+
* Add line numbers to a string
|
224
|
+
* @param separator The separator to use between the line number and the line content.
|
225
|
+
* Defaults to ":"
|
226
|
+
*/
|
227
|
+
addLineNumbers(separator = ":") {
|
228
|
+
return new _Str(addLineNumbers(this.text, separator));
|
229
|
+
}
|
230
|
+
/**
|
231
|
+
* Returns the character at the specified index
|
232
|
+
* @return string or undefined if the index is out of bounds
|
233
|
+
*/
|
234
|
+
at(index) {
|
235
|
+
return this.text.at(index);
|
236
|
+
}
|
237
|
+
/**
|
238
|
+
* Returns the length of the string
|
239
|
+
*/
|
240
|
+
length() {
|
241
|
+
return this.text.length;
|
242
|
+
}
|
243
|
+
/**
|
244
|
+
* Indent the string by the specified number of spaces
|
245
|
+
* @param size The number of spaces to indent by
|
246
|
+
* @param char The character to use for indentation. Defaults to " "
|
247
|
+
*/
|
248
|
+
indent(size, char = " ") {
|
249
|
+
return new _Str(indent(this.text, size, char));
|
250
|
+
}
|
251
|
+
/**
|
252
|
+
* Dedent the string by the specified number of spaces
|
253
|
+
* @param indentation The number of spaces to dedent by.
|
254
|
+
* If not provided, it will be calculated automatically based on the maximum indentation in the string.
|
255
|
+
*/
|
256
|
+
dedent(indentation2) {
|
257
|
+
return new _Str(dedent(this.text, indentation2));
|
258
|
+
}
|
259
|
+
/**
|
260
|
+
* Chop the string at the start by the specified number of characters
|
261
|
+
*/
|
262
|
+
chopStart(count) {
|
263
|
+
return new _Str(chopStart(this.text, count));
|
264
|
+
}
|
265
|
+
/**
|
266
|
+
* Chop the string at the end by the specified number of characters
|
267
|
+
*/
|
268
|
+
chopEnd(count) {
|
269
|
+
if (count === 0) return this;
|
270
|
+
return new _Str(chopEnd(this.text, count));
|
271
|
+
}
|
272
|
+
/**
|
273
|
+
* Remove successive newlines of the specified repetition or more
|
274
|
+
* @param maxRepeat the maximum number of newlines to allow
|
275
|
+
*/
|
276
|
+
chopRepeatNewlines(maxRepeat) {
|
277
|
+
if (maxRepeat === 0) return this;
|
278
|
+
return new _Str(chopRepeatNewlines(this.text, maxRepeat));
|
279
|
+
}
|
280
|
+
/**
|
281
|
+
* Take the first n characters of the string
|
282
|
+
*/
|
283
|
+
takeStart(count) {
|
284
|
+
return new _Str(takeStart(this.text, count));
|
285
|
+
}
|
286
|
+
/**
|
287
|
+
* Take the last n characters of the string
|
288
|
+
*/
|
289
|
+
takeEnd(count) {
|
290
|
+
return new _Str(takeEnd(this.text, count));
|
291
|
+
}
|
292
|
+
/**
|
293
|
+
* Returns the last line of the string
|
294
|
+
*/
|
295
|
+
lastLine() {
|
296
|
+
return new _Str(lastLine(this.text));
|
297
|
+
}
|
298
|
+
/**
|
299
|
+
* Returns the first line of the string
|
300
|
+
*/
|
301
|
+
firstLine() {
|
302
|
+
return new _Str(firstLine(this.text));
|
303
|
+
}
|
304
|
+
/**
|
305
|
+
* Returns the number of leading spaces in the string
|
306
|
+
*/
|
307
|
+
leadingSpacesCount() {
|
308
|
+
return leadingSpacesCount(this.text);
|
309
|
+
}
|
310
|
+
/**
|
311
|
+
* Returns the indentation level of the string skipping empty lines in the process
|
312
|
+
*/
|
313
|
+
indentation() {
|
314
|
+
return indentation(this.text);
|
315
|
+
}
|
316
|
+
/**
|
317
|
+
* Returns true if the string is empty or contains only whitespace
|
318
|
+
*/
|
319
|
+
isEmpty() {
|
320
|
+
return isEmpty(this.text);
|
321
|
+
}
|
322
|
+
/**
|
323
|
+
* Converts the string to camel case
|
324
|
+
*/
|
325
|
+
camelCase() {
|
326
|
+
return new _Str(changeCase.camelCase(this.text));
|
327
|
+
}
|
328
|
+
/**
|
329
|
+
* Converts the string to capital case
|
330
|
+
*/
|
331
|
+
capitalCase() {
|
332
|
+
return new _Str(changeCase.capitalCase(this.text));
|
333
|
+
}
|
334
|
+
/**
|
335
|
+
* Converts the string to constant case
|
336
|
+
*/
|
337
|
+
constantCase() {
|
338
|
+
return new _Str(changeCase.constantCase(this.text));
|
339
|
+
}
|
340
|
+
/**
|
341
|
+
* Converts the string to dot case
|
342
|
+
*/
|
343
|
+
dotCase() {
|
344
|
+
return new _Str(changeCase.dotCase(this.text));
|
345
|
+
}
|
346
|
+
/**
|
347
|
+
* Converts the string to kebab case
|
348
|
+
*/
|
349
|
+
kebabCase() {
|
350
|
+
return new _Str(changeCase.kebabCase(this.text));
|
351
|
+
}
|
352
|
+
/**
|
353
|
+
* Converts the string to no case
|
354
|
+
*/
|
355
|
+
noCase() {
|
356
|
+
return new _Str(changeCase.noCase(this.text));
|
357
|
+
}
|
358
|
+
/**
|
359
|
+
* Converts the string to pascal case
|
360
|
+
*/
|
361
|
+
pascalCase() {
|
362
|
+
return new _Str(changeCase.pascalCase(this.text));
|
363
|
+
}
|
364
|
+
/**
|
365
|
+
* Converts the string to pascal snake case
|
366
|
+
*/
|
367
|
+
pascalSnakeCase() {
|
368
|
+
return new _Str(changeCase.pascalSnakeCase(this.text));
|
369
|
+
}
|
370
|
+
/**
|
371
|
+
* Converts the string to path case
|
372
|
+
*/
|
373
|
+
pathCase() {
|
374
|
+
return new _Str(changeCase.pathCase(this.text));
|
375
|
+
}
|
376
|
+
/**
|
377
|
+
* Converts the string to sentence case
|
378
|
+
*/
|
379
|
+
sentenceCase() {
|
380
|
+
return new _Str(changeCase.sentenceCase(this.text));
|
381
|
+
}
|
382
|
+
/**
|
383
|
+
* Converts the string to snake case
|
384
|
+
*/
|
385
|
+
snakeCase() {
|
386
|
+
return new _Str(changeCase.snakeCase(this.text));
|
387
|
+
}
|
388
|
+
/**
|
389
|
+
* Converts the string to train case
|
390
|
+
*/
|
391
|
+
trainCase() {
|
392
|
+
return new _Str(changeCase.trainCase(this.text));
|
393
|
+
}
|
394
|
+
/**
|
395
|
+
* Shorthand for `.toString()`
|
396
|
+
*/
|
397
|
+
get str() {
|
398
|
+
return this.toString();
|
399
|
+
}
|
400
|
+
};
|
401
|
+
var str = (text) => {
|
402
|
+
return new Str(text.toString());
|
403
|
+
};
|
404
|
+
// Annotate the CommonJS export names for ESM import in node:
|
405
|
+
0 && (module.exports = {
|
406
|
+
addLineNumbers,
|
407
|
+
camelCase,
|
408
|
+
capitalCase,
|
409
|
+
chopEmptyLinesEnd,
|
410
|
+
chopEmptyLinesStart,
|
411
|
+
chopEnd,
|
412
|
+
chopRepeatNewlines,
|
413
|
+
chopStart,
|
414
|
+
constantCase,
|
415
|
+
dedent,
|
416
|
+
dotCase,
|
417
|
+
firstLine,
|
418
|
+
indent,
|
419
|
+
indentation,
|
420
|
+
isEmpty,
|
421
|
+
kebabCase,
|
422
|
+
lastLine,
|
423
|
+
leadingSpacesCount,
|
424
|
+
noCase,
|
425
|
+
pascalCase,
|
426
|
+
pascalSnakeCase,
|
427
|
+
pathCase,
|
428
|
+
sentenceCase,
|
429
|
+
snakeCase,
|
430
|
+
split,
|
431
|
+
str,
|
432
|
+
takeEnd,
|
433
|
+
takeStart,
|
434
|
+
trainCase,
|
435
|
+
trim,
|
436
|
+
trimEmptyLines,
|
437
|
+
trimEnd,
|
438
|
+
trimLinesTrailingSpaces,
|
439
|
+
trimStart
|
440
|
+
});
|
441
|
+
//# sourceMappingURL=str.index.cjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/str.index.ts","../src/str.bundle.ts","../src/str.chainable.ts","../src/str.lib.ts"],"sourcesContent":["export * from \"./str.bundle\";\nexport type { Str } from \"./str.chainable\";\n","export {\n camelCase,\n capitalCase,\n constantCase,\n dotCase,\n kebabCase,\n noCase,\n pascalCase,\n pascalSnakeCase,\n pathCase,\n sentenceCase,\n snakeCase,\n trainCase,\n} from \"change-case\";\nexport { str } from \"./str.chainable\";\nexport * from \"./str.lib\";\n","import { Pipeable } from \"@synstack/pipe\";\nimport * as changeCase from \"change-case\";\nimport * as lib from \"./str.lib\";\n\nexport type Stringable = {\n toString: () => string;\n};\n\nexport class Str extends Pipeable<Str, string> {\n public constructor(private readonly text: string) {\n super();\n }\n\n public valueOf(): string {\n return this.text;\n }\n\n public toString() {\n return this.text;\n }\n\n public instanceOf(): Str {\n return this;\n }\n\n /**\n * Remove empty lines at the start of the text but leave whitespace on the first line with content\n */\n public chopEmptyLinesStart() {\n return new Str(lib.chopEmptyLinesStart(this.text));\n }\n\n /**\n * Remove empty lines at the end of the text but leave whitespace on the last line with content\n */\n public chopEmptyLinesEnd() {\n return new Str(lib.chopEmptyLinesEnd(this.text));\n }\n\n /**\n * Remove all space (\\s) characters in lines without content\n */\n public trimEmptyLines() {\n return new Str(lib.trimEmptyLines(this.text));\n }\n\n /**\n * Remove all spaces (\\s) characters at the end of lines\n */\n public trimLinesTrailingSpaces() {\n return new Str(lib.trimLinesTrailingSpaces(this.text));\n }\n\n /**\n * Removes the leading and trailing white space and line terminator characters\n */\n public trim() {\n return new Str(lib.trim(this.text));\n }\n\n /**\n * Removes the leading white space and line terminator characters\n */\n public trimStart() {\n return new Str(lib.trimStart(this.text));\n }\n\n /**\n * Removes the trailing white space and line terminator characters\n */\n public trimEnd() {\n return new Str(lib.trimEnd(this.text));\n }\n\n /**\n * Split a string into substrings using the specified separator and return them as an array\n */\n public split(separator: string | RegExp, limit?: number) {\n return lib.split(this.text, separator, limit).map((v) => new Str(v));\n }\n\n /**\n * Add line numbers to a string\n * @param separator The separator to use between the line number and the line content.\n * Defaults to \":\"\n */\n public addLineNumbers(separator: string = \":\") {\n return new Str(lib.addLineNumbers(this.text, separator));\n }\n\n /**\n * Returns the character at the specified index\n * @return string or undefined if the index is out of bounds\n */\n public at(index: number) {\n return this.text.at(index);\n }\n\n /**\n * Returns the length of the string\n */\n public length() {\n return this.text.length;\n }\n\n /**\n * Indent the string by the specified number of spaces\n * @param size The number of spaces to indent by\n * @param char The character to use for indentation. Defaults to \" \"\n */\n public indent(size: number, char: string = \" \") {\n return new Str(lib.indent(this.text, size, char));\n }\n\n /**\n * Dedent the string by the specified number of spaces\n * @param indentation The number of spaces to dedent by.\n * If not provided, it will be calculated automatically based on the maximum indentation in the string.\n */\n public dedent(indentation?: number) {\n return new Str(lib.dedent(this.text, indentation));\n }\n\n /**\n * Chop the string at the start by the specified number of characters\n */\n public chopStart(count: number) {\n return new Str(lib.chopStart(this.text, count));\n }\n\n /**\n * Chop the string at the end by the specified number of characters\n */\n public chopEnd(count: number) {\n if (count === 0) return this;\n return new Str(lib.chopEnd(this.text, count));\n }\n\n /**\n * Remove successive newlines of the specified repetition or more\n * @param maxRepeat the maximum number of newlines to allow\n */\n public chopRepeatNewlines(maxRepeat: number) {\n if (maxRepeat === 0) return this;\n return new Str(lib.chopRepeatNewlines(this.text, maxRepeat));\n }\n\n /**\n * Take the first n characters of the string\n */\n public takeStart(count: number) {\n return new Str(lib.takeStart(this.text, count));\n }\n\n /**\n * Take the last n characters of the string\n */\n public takeEnd(count: number) {\n return new Str(lib.takeEnd(this.text, count));\n }\n\n /**\n * Returns the last line of the string\n */\n public lastLine() {\n return new Str(lib.lastLine(this.text));\n }\n\n /**\n * Returns the first line of the string\n */\n public firstLine() {\n return new Str(lib.firstLine(this.text));\n }\n\n /**\n * Returns the number of leading spaces in the string\n */\n public leadingSpacesCount() {\n return lib.leadingSpacesCount(this.text);\n }\n\n /**\n * Returns the indentation level of the string skipping empty lines in the process\n */\n public indentation() {\n return lib.indentation(this.text);\n }\n\n /**\n * Returns true if the string is empty or contains only whitespace\n */\n public isEmpty() {\n return lib.isEmpty(this.text);\n }\n\n /**\n * Converts the string to camel case\n */\n public camelCase() {\n return new Str(changeCase.camelCase(this.text));\n }\n\n /**\n * Converts the string to capital case\n */\n public capitalCase() {\n return new Str(changeCase.capitalCase(this.text));\n }\n\n /**\n * Converts the string to constant case\n */\n public constantCase() {\n return new Str(changeCase.constantCase(this.text));\n }\n\n /**\n * Converts the string to dot case\n */\n public dotCase() {\n return new Str(changeCase.dotCase(this.text));\n }\n\n /**\n * Converts the string to kebab case\n */\n public kebabCase() {\n return new Str(changeCase.kebabCase(this.text));\n }\n\n /**\n * Converts the string to no case\n */\n public noCase() {\n return new Str(changeCase.noCase(this.text));\n }\n\n /**\n * Converts the string to pascal case\n */\n public pascalCase() {\n return new Str(changeCase.pascalCase(this.text));\n }\n\n /**\n * Converts the string to pascal snake case\n */\n public pascalSnakeCase() {\n return new Str(changeCase.pascalSnakeCase(this.text));\n }\n\n /**\n * Converts the string to path case\n */\n public pathCase() {\n return new Str(changeCase.pathCase(this.text));\n }\n\n /**\n * Converts the string to sentence case\n */\n public sentenceCase() {\n return new Str(changeCase.sentenceCase(this.text));\n }\n\n /**\n * Converts the string to snake case\n */\n public snakeCase() {\n return new Str(changeCase.snakeCase(this.text));\n }\n\n /**\n * Converts the string to train case\n */\n public trainCase() {\n return new Str(changeCase.trainCase(this.text));\n }\n\n /**\n * Shorthand for `.toString()`\n */\n public get str() {\n return this.toString();\n }\n}\n\nexport const str = (text: Stringable) => {\n return new Str(text.toString());\n};\n","/**\n * Remove empty lines at the start of the text but leave whitespace on the first line with content\n */\nexport const chopEmptyLinesStart = (text: string) => {\n return text.replace(/^(\\s*\\n)+/, \"\");\n};\n\n/**\n * Remove empty lines at the end of the text but leave whitespace on the last line with content\n */\nexport const chopEmptyLinesEnd = (text: string) => {\n return text.replace(/(\\n\\s*)+$/, \"\");\n};\n\n/**\n * Remove all space (\\s) characters in lines without content\n */\nexport const trimEmptyLines = (text: string) => {\n return text.replace(/(^|\\n)\\s+(\\n|$)/g, \"$1$2\");\n};\n\n/**\n * Remove all space (\\s) characters at the end of lines\n */\nexport const trimLinesTrailingSpaces = (text: string) => {\n return text.replace(/ +(\\n|$)/g, \"$1\");\n};\n\n/**\n * Removes the leading and trailing white space and line terminator characters\n */\nexport const trim = (text: string) => {\n return text.trim();\n};\n\n/**\n * Removes the leading white space and line terminator characters\n */\nexport const trimStart = (text: string) => {\n return text.trimStart();\n};\n\n/**\n * Removes the trailing white space and line terminator characters\n */\nexport const trimEnd = (text: string) => {\n return text.trimEnd();\n};\n\n/**\n * Split a string into substrings using the specified separator and return them as an array\n */\nexport const split = (\n text: string,\n separator: string | RegExp,\n limit?: number,\n) => {\n return text.split(separator, limit);\n};\n\n/**\n * Add line numbers to a string\n * @param text The string to add line numbers to\n * @param separator The separator to use between the line number and the line content.\n * Defaults to \":\"\n */\nexport const addLineNumbers = (text: string, separator: string = \":\") => {\n return text\n .split(\"\\n\")\n .map((line, index) => `${index}${separator}${line}`)\n .join(\"\\n\");\n};\n\n/**\n * Returns the indentation level of the string skipping empty lines in the process\n */\nexport const indentation = (text: string) => {\n return (\n text.split(\"\\n\").reduce((acc: number | null, line) => {\n if (line.trim() === \"\") return acc;\n const indentation = leadingSpacesCount(line);\n if (acc === null) return indentation;\n return Math.min(acc, indentation);\n }, null) ?? 0\n );\n};\n\n/**\n * Indent the string by the specified number of spaces\n * @param size The number of spaces to indent by\n * @param char The character to use for indentation. Defaults to \" \"\n */\nexport const indent = (text: string, size: number, char: string = \" \") => {\n if (size === 0) return text;\n\n const indentStr = char.repeat(size);\n return text\n .split(\"\\n\")\n .map((line) => indentStr + line)\n .join(\"\\n\");\n};\n\n/**\n * Dedent the string by the specified number of spaces\n * @param indentation The number of spaces to dedent by.\n * If not provided, it will be calculated automatically based on the maximum indentation in the string.\n */\nexport const dedent = (text: string, size?: number) => {\n const _size = size ?? indentation(text);\n if (_size === 0) return text;\n const regex = new RegExp(`^\\\\s{1,${_size}}`);\n return text\n .split(\"\\n\")\n .map((line) => line.replace(regex, \"\"))\n .join(\"\\n\");\n};\n\n/**\n * Chop the string at the end by the specified number of characters\n */\nexport const chopEnd = (text: string, count: number) => {\n if (count === 0) return text;\n return text.slice(0, -count);\n};\n\n/**\n * Chop the string at the start by the specified number of characters\n */\nexport const chopStart = (text: string, count: number) => {\n if (count === 0) return text;\n return text.slice(count);\n};\n\n/**\n * Remove successive newlines of the specified repetition or more\n * @param maxRepeat the maximum number of newlines to allow\n */\nexport const chopRepeatNewlines = (text: string, maxRepeat: number) => {\n if (maxRepeat === 0) return text;\n return text.replace(\n new RegExp(`\\n{${maxRepeat + 1},}`, \"g\"),\n \"\\n\".repeat(maxRepeat),\n );\n};\n\n/**\n * Take the first n characters of the string\n */\nexport const takeStart = (text: string, count: number) => {\n return text.slice(0, count);\n};\n\n/**\n * Take the last n characters of the string\n */\nexport const takeEnd = (text: string, count: number) => {\n return text.slice(-count);\n};\n\n/**\n * Returns the last line of the string\n */\nexport const lastLine = (text: string) => {\n return text.split(\"\\n\").at(-1) ?? \"\";\n};\n\n/**\n * Returns the first line of the string\n */\nexport const firstLine = (text: string) => {\n return text.split(\"\\n\").at(0) ?? \"\";\n};\n\n/**\n * Returns the number of leading spaces in the string\n */\nexport const leadingSpacesCount = (text: string) => {\n return text.match(/^\\s+/)?.at(0)?.length ?? 0;\n};\n\n/**\n * Returns true if the string is empty or contains only whitespace\n */\nexport const isEmpty = (text: string) => {\n return text.trim() === \"\";\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,yBAaO;;;ACbP,kBAAyB;AACzB,iBAA4B;;;ACErB,IAAM,sBAAsB,CAAC,SAAiB;AACnD,SAAO,KAAK,QAAQ,aAAa,EAAE;AACrC;AAKO,IAAM,oBAAoB,CAAC,SAAiB;AACjD,SAAO,KAAK,QAAQ,aAAa,EAAE;AACrC;AAKO,IAAM,iBAAiB,CAAC,SAAiB;AAC9C,SAAO,KAAK,QAAQ,oBAAoB,MAAM;AAChD;AAKO,IAAM,0BAA0B,CAAC,SAAiB;AACvD,SAAO,KAAK,QAAQ,aAAa,IAAI;AACvC;AAKO,IAAM,OAAO,CAAC,SAAiB;AACpC,SAAO,KAAK,KAAK;AACnB;AAKO,IAAM,YAAY,CAAC,SAAiB;AACzC,SAAO,KAAK,UAAU;AACxB;AAKO,IAAM,UAAU,CAAC,SAAiB;AACvC,SAAO,KAAK,QAAQ;AACtB;AAKO,IAAM,QAAQ,CACnB,MACA,WACA,UACG;AACH,SAAO,KAAK,MAAM,WAAW,KAAK;AACpC;AAQO,IAAM,iBAAiB,CAAC,MAAc,YAAoB,QAAQ;AACvE,SAAO,KACJ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