@ix-xs/node-comfort 1.1.31 → 2.0.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/CHANGELOG.md +190 -0
- package/LICENSE +21 -0
- package/README.md +210 -748
- package/index.js +84 -13
- package/package.json +201 -21
- package/src/Arr.js +901 -0
- package/src/Async.js +585 -0
- package/src/Cache.js +329 -0
- package/src/Checker.js +979 -188
- package/src/Cli.js +1034 -0
- package/src/Color.js +415 -0
- package/src/Crypto.js +707 -0
- package/src/Emitter.js +289 -0
- package/src/Env.js +555 -0
- package/src/FS.js +1483 -768
- package/src/Func.js +692 -0
- package/src/Http.js +538 -0
- package/src/Id.js +418 -0
- package/src/Logger.js +739 -307
- package/src/Num.js +849 -0
- package/src/Obj.js +904 -0
- package/src/SQLite.js +1308 -994
- package/src/Schema.js +1586 -0
- package/src/Str.js +999 -0
- package/src/Sys.js +511 -0
- package/src/Time.js +1323 -0
- package/src/Utils.js +321 -325
- package/src/errors.js +292 -0
- package/types/index.d.ts +693 -120
- package/types/src/Arr.d.ts +562 -0
- package/types/src/Arr.d.ts.map +1 -0
- package/types/src/Async.d.ts +321 -0
- package/types/src/Async.d.ts.map +1 -0
- package/types/src/Cache.d.ts +195 -0
- package/types/src/Cache.d.ts.map +1 -0
- package/types/src/Checker.d.ts +609 -81
- package/types/src/Checker.d.ts.map +1 -1
- package/types/src/Cli.d.ts +582 -0
- package/types/src/Cli.d.ts.map +1 -0
- package/types/src/Color.d.ts +294 -0
- package/types/src/Color.d.ts.map +1 -0
- package/types/src/Crypto.d.ts +534 -0
- package/types/src/Crypto.d.ts.map +1 -0
- package/types/src/Emitter.d.ts +170 -0
- package/types/src/Emitter.d.ts.map +1 -0
- package/types/src/Env.d.ts +382 -0
- package/types/src/Env.d.ts.map +1 -0
- package/types/src/FS.d.ts +709 -201
- package/types/src/FS.d.ts.map +1 -1
- package/types/src/Func.d.ts +455 -0
- package/types/src/Func.d.ts.map +1 -0
- package/types/src/Http.d.ts +374 -0
- package/types/src/Http.d.ts.map +1 -0
- package/types/src/Id.d.ts +200 -0
- package/types/src/Id.d.ts.map +1 -0
- package/types/src/Logger.d.ts +374 -24
- package/types/src/Logger.d.ts.map +1 -1
- package/types/src/Num.d.ts +578 -0
- package/types/src/Num.d.ts.map +1 -0
- package/types/src/Obj.d.ts +475 -0
- package/types/src/Obj.d.ts.map +1 -0
- package/types/src/SQLite.d.ts +647 -305
- package/types/src/SQLite.d.ts.map +1 -1
- package/types/src/Schema.d.ts +940 -0
- package/types/src/Schema.d.ts.map +1 -0
- package/types/src/Str.d.ts +696 -0
- package/types/src/Str.d.ts.map +1 -0
- package/types/src/Sys.d.ts +269 -0
- package/types/src/Sys.d.ts.map +1 -0
- package/types/src/Time.d.ts +664 -0
- package/types/src/Time.d.ts.map +1 -0
- package/types/src/Utils.d.ts +154 -102
- package/types/src/Utils.d.ts.map +1 -1
- package/types/src/errors.d.ts +292 -0
- package/types/src/errors.d.ts.map +1 -0
- package/tsconfig.json +0 -18
- package/types/index.d.ts.map +0 -1
|
@@ -0,0 +1,696 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for `slugify()`.
|
|
3
|
+
*/
|
|
4
|
+
export type SlugifyOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* Placed between words. Defaults to `"-"`.
|
|
7
|
+
*/
|
|
8
|
+
separator?: string | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Lowercase the result. Defaults to `true`.
|
|
11
|
+
*/
|
|
12
|
+
lower?: boolean | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Maximum length, cut on a word boundary when possible.
|
|
15
|
+
*/
|
|
16
|
+
maxLength?: number | undefined;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Options for `truncate()`.
|
|
20
|
+
*/
|
|
21
|
+
export type TruncateOptions = {
|
|
22
|
+
/**
|
|
23
|
+
* Added where the text is cut, and counted in the length. Defaults to `"…"`.
|
|
24
|
+
*/
|
|
25
|
+
omission?: string | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Cut at the previous space rather than inside a word.
|
|
28
|
+
*/
|
|
29
|
+
words?: boolean | undefined;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Options for `template()`.
|
|
33
|
+
*/
|
|
34
|
+
export type TemplateOptions = {
|
|
35
|
+
/**
|
|
36
|
+
* Opening delimiter. Defaults to `"{"`.
|
|
37
|
+
*/
|
|
38
|
+
open?: string | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Closing delimiter. Defaults to `"}"`.
|
|
41
|
+
*/
|
|
42
|
+
close?: string | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Used for missing values. Without it, their placeholders stay as they are.
|
|
45
|
+
*/
|
|
46
|
+
fallback?: string | undefined;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Options for `wrap()`.
|
|
50
|
+
*/
|
|
51
|
+
export type WrapOptions = {
|
|
52
|
+
/**
|
|
53
|
+
* Maximum visible characters per line. Defaults to `80`.
|
|
54
|
+
*/
|
|
55
|
+
width?: number | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Added at the start of every line.
|
|
58
|
+
*/
|
|
59
|
+
indent?: string | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Break words longer than `width` instead of letting them overflow.
|
|
62
|
+
*/
|
|
63
|
+
cut?: boolean | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Line separator. Defaults to `"\n"`.
|
|
66
|
+
*/
|
|
67
|
+
newline?: string | undefined;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Options for `mask()`.
|
|
71
|
+
*/
|
|
72
|
+
export type MaskOptions = {
|
|
73
|
+
/**
|
|
74
|
+
* Characters left visible at the start. Defaults to `0`.
|
|
75
|
+
*/
|
|
76
|
+
start?: number | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Characters left visible at the end. Defaults to `4`.
|
|
79
|
+
*/
|
|
80
|
+
end?: number | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* Mask character. Defaults to `"*"`.
|
|
83
|
+
*/
|
|
84
|
+
char?: string | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* Leave spaces and dashes visible, nice for card numbers.
|
|
87
|
+
*/
|
|
88
|
+
keepSpaces?: boolean | undefined;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* The word forms for `plural()`. Only `other` is required; add the others
|
|
92
|
+
* when your language needs them.
|
|
93
|
+
*/
|
|
94
|
+
export type PluralForms = {
|
|
95
|
+
/**
|
|
96
|
+
* The general plural, like `"files"`.
|
|
97
|
+
*/
|
|
98
|
+
other: string;
|
|
99
|
+
/**
|
|
100
|
+
* Used for `0` in any language, like `"no files"`.
|
|
101
|
+
*/
|
|
102
|
+
zero?: string | undefined;
|
|
103
|
+
/**
|
|
104
|
+
* The singular, like `"file"`. French also uses it for 0.
|
|
105
|
+
*/
|
|
106
|
+
one?: string | undefined;
|
|
107
|
+
/**
|
|
108
|
+
* Dual form (Arabic, Hebrew, Slovenian...).
|
|
109
|
+
*/
|
|
110
|
+
two?: string | undefined;
|
|
111
|
+
/**
|
|
112
|
+
* "Few" form (Polish, Czech, Russian...).
|
|
113
|
+
*/
|
|
114
|
+
few?: string | undefined;
|
|
115
|
+
/**
|
|
116
|
+
* "Many" form (Polish, Russian, Arabic...).
|
|
117
|
+
*/
|
|
118
|
+
many?: string | undefined;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Options for `plural()`.
|
|
122
|
+
*/
|
|
123
|
+
export type PluralOptions = {
|
|
124
|
+
/**
|
|
125
|
+
* Language whose plural rules apply. Defaults to `"en"`.
|
|
126
|
+
*/
|
|
127
|
+
locale?: string | undefined;
|
|
128
|
+
/**
|
|
129
|
+
* Put the formatted count before the word. Defaults to `true`.
|
|
130
|
+
*/
|
|
131
|
+
includeCount?: boolean | undefined;
|
|
132
|
+
/**
|
|
133
|
+
* Use ordinal rules (1st, 2nd, 3rd).
|
|
134
|
+
*/
|
|
135
|
+
ordinal?: boolean | undefined;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Options for `compare()`.
|
|
139
|
+
*/
|
|
140
|
+
export type CompareOptions = {
|
|
141
|
+
/**
|
|
142
|
+
* Language used for alphabetical order. Defaults to the system's.
|
|
143
|
+
*/
|
|
144
|
+
locale?: string | undefined;
|
|
145
|
+
/**
|
|
146
|
+
* Sort numbers naturally, `"file2"` before `"file10"`. Defaults to `true`.
|
|
147
|
+
*/
|
|
148
|
+
numeric?: boolean | undefined;
|
|
149
|
+
/**
|
|
150
|
+
* Which differences count. `"base"` ignores accents and case. Defaults to `"variant"`.
|
|
151
|
+
*/
|
|
152
|
+
sensitivity?: "base" | "accent" | "case" | "variant" | undefined;
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* Options for `closest()`.
|
|
156
|
+
*/
|
|
157
|
+
export type ClosestOptions = {
|
|
158
|
+
/**
|
|
159
|
+
* Minimum similarity (0 to 1) to accept a match. Defaults to `0.4`.
|
|
160
|
+
*/
|
|
161
|
+
threshold?: number | undefined;
|
|
162
|
+
/**
|
|
163
|
+
* Take case into account.
|
|
164
|
+
*/
|
|
165
|
+
caseSensitive?: boolean | undefined;
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* Options for `random()`.
|
|
169
|
+
*/
|
|
170
|
+
export type RandomStringOptions = {
|
|
171
|
+
/**
|
|
172
|
+
* Characters to pick from. Defaults to letters and digits.
|
|
173
|
+
*/
|
|
174
|
+
charset?: string | undefined;
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* Uppercases the first character and lowercases the rest.
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* str.capitalize("hELLO wORLD"); // "Hello world"
|
|
181
|
+
*
|
|
182
|
+
* @param {unknown} input
|
|
183
|
+
* @returns {string}
|
|
184
|
+
*/
|
|
185
|
+
export function capitalize(input: unknown): string;
|
|
186
|
+
/**
|
|
187
|
+
* Uppercases the first letter of each word and leaves the rest alone.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* str.titleCase("the quick brown fox"); // "The Quick Brown Fox"
|
|
191
|
+
* str.titleCase("élodie o'neil"); // "Élodie O'neil"
|
|
192
|
+
*
|
|
193
|
+
* @param {unknown} input
|
|
194
|
+
* @returns {string}
|
|
195
|
+
*/
|
|
196
|
+
export function titleCase(input: unknown): string;
|
|
197
|
+
/**
|
|
198
|
+
* Lowercases everything, then capitalizes the start of each sentence.
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* str.sentenceCase("hELLO WORLD. how ARE you?"); // "Hello world. How are you?"
|
|
202
|
+
*
|
|
203
|
+
* @param {unknown} input
|
|
204
|
+
* @returns {string}
|
|
205
|
+
*/
|
|
206
|
+
export function sentenceCase(input: unknown): string;
|
|
207
|
+
/**
|
|
208
|
+
* Converts to `camelCase`.
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* str.camelCase("user_first-name"); // "userFirstName"
|
|
212
|
+
* str.camelCase("XMLHttpRequest"); // "xmlHttpRequest"
|
|
213
|
+
*
|
|
214
|
+
* @param {unknown} input
|
|
215
|
+
* @returns {string}
|
|
216
|
+
*/
|
|
217
|
+
export function camelCase(input: unknown): string;
|
|
218
|
+
/**
|
|
219
|
+
* Converts to `PascalCase`.
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* str.pascalCase("hello world"); // "HelloWorld"
|
|
223
|
+
*
|
|
224
|
+
* @param {unknown} input
|
|
225
|
+
* @returns {string}
|
|
226
|
+
*/
|
|
227
|
+
export function pascalCase(input: unknown): string;
|
|
228
|
+
/**
|
|
229
|
+
* Converts to `snake_case`.
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* str.snakeCase("helloWorld"); // "hello_world"
|
|
233
|
+
*
|
|
234
|
+
* @param {unknown} input
|
|
235
|
+
* @returns {string}
|
|
236
|
+
*/
|
|
237
|
+
export function snakeCase(input: unknown): string;
|
|
238
|
+
/**
|
|
239
|
+
* Converts to `kebab-case`.
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* str.kebabCase("helloWorld"); // "hello-world"
|
|
243
|
+
*
|
|
244
|
+
* @param {unknown} input
|
|
245
|
+
* @returns {string}
|
|
246
|
+
*/
|
|
247
|
+
export function kebabCase(input: unknown): string;
|
|
248
|
+
/**
|
|
249
|
+
* Converts to `CONSTANT_CASE`.
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* str.constantCase("helloWorld"); // "HELLO_WORLD"
|
|
253
|
+
*
|
|
254
|
+
* @param {unknown} input
|
|
255
|
+
* @returns {string}
|
|
256
|
+
*/
|
|
257
|
+
export function constantCase(input: unknown): string;
|
|
258
|
+
/**
|
|
259
|
+
* Converts to `dot.case`.
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* str.dotCase("userFirstName"); // "user.first.name"
|
|
263
|
+
*
|
|
264
|
+
* @param {unknown} input
|
|
265
|
+
* @returns {string}
|
|
266
|
+
*/
|
|
267
|
+
export function dotCase(input: unknown): string;
|
|
268
|
+
/**
|
|
269
|
+
* Splits text into words. Understands camelCase, snake_case, kebab-case,
|
|
270
|
+
* dots, spaces and punctuation.
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* str.words("helloWorld-foo_bar"); // ["hello", "World", "foo", "bar"]
|
|
274
|
+
*
|
|
275
|
+
* @param {unknown} input
|
|
276
|
+
* @returns {string[]}
|
|
277
|
+
*/
|
|
278
|
+
export function words(input: unknown): string[];
|
|
279
|
+
/**
|
|
280
|
+
* Removes accents (`é` becomes `e`) and spells out special Latin letters
|
|
281
|
+
* (`ß` becomes `ss`, `æ` becomes `ae`).
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* str.deburr("Crème brûlée"); // "Creme brulee"
|
|
285
|
+
* str.deburr("Straße"); // "Strasse"
|
|
286
|
+
*
|
|
287
|
+
* @param {unknown} input
|
|
288
|
+
* @returns {string}
|
|
289
|
+
*/
|
|
290
|
+
export function deburr(input: unknown): string;
|
|
291
|
+
/**
|
|
292
|
+
* Turns text into a URL slug: no accents, lowercase, words joined by dashes.
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* str.slugify("Héllo, World!"); // "hello-world"
|
|
296
|
+
* str.slugify("Crème Brûlée", { separator: "_" }); // "creme_brulee"
|
|
297
|
+
* str.slugify("A very long title", { maxLength: 8 }); // "a-very"
|
|
298
|
+
*
|
|
299
|
+
* @param {unknown} input
|
|
300
|
+
* @param {SlugifyOptions} [options]
|
|
301
|
+
* @returns {string} The slug, possibly empty.
|
|
302
|
+
*/
|
|
303
|
+
export function slugify(input: unknown, options?: SlugifyOptions): string;
|
|
304
|
+
/**
|
|
305
|
+
* Collapses runs of whitespace into single spaces and trims the ends.
|
|
306
|
+
*
|
|
307
|
+
* @example
|
|
308
|
+
* str.squish(" hello \n\t world "); // "hello world"
|
|
309
|
+
*
|
|
310
|
+
* @param {unknown} input
|
|
311
|
+
* @returns {string}
|
|
312
|
+
*/
|
|
313
|
+
export function squish(input: unknown): string;
|
|
314
|
+
/**
|
|
315
|
+
* Removes HTML tags and keeps the text. This is not a sanitizer: to show
|
|
316
|
+
* untrusted text in HTML, use `escapeHTML()`.
|
|
317
|
+
*
|
|
318
|
+
* @example
|
|
319
|
+
* str.stripTags("<p>Hello <b>world</b></p>"); // "Hello world"
|
|
320
|
+
*
|
|
321
|
+
* @param {unknown} input
|
|
322
|
+
* @returns {string}
|
|
323
|
+
*/
|
|
324
|
+
export function stripTags(input: unknown): string;
|
|
325
|
+
/**
|
|
326
|
+
* Escapes `& < > " '` so the text is safe inside HTML content and attributes.
|
|
327
|
+
*
|
|
328
|
+
* @example
|
|
329
|
+
* str.escapeHTML('<a href="x">Tom & Jerry</a>');
|
|
330
|
+
* // "<a href="x">Tom & Jerry</a>"
|
|
331
|
+
*
|
|
332
|
+
* @param {unknown} input
|
|
333
|
+
* @returns {string}
|
|
334
|
+
*/
|
|
335
|
+
export function escapeHTML(input: unknown): string;
|
|
336
|
+
/**
|
|
337
|
+
* Decodes HTML entities: named ones like `&` and ` `, and numeric
|
|
338
|
+
* ones like `é`.
|
|
339
|
+
*
|
|
340
|
+
* @example
|
|
341
|
+
* str.unescapeHTML("Tom & Jerry 😀"); // "Tom & Jerry 😀"
|
|
342
|
+
*
|
|
343
|
+
* @param {unknown} input
|
|
344
|
+
* @returns {string}
|
|
345
|
+
*/
|
|
346
|
+
export function unescapeHTML(input: unknown): string;
|
|
347
|
+
/**
|
|
348
|
+
* Escapes regex special characters so the text matches literally.
|
|
349
|
+
*
|
|
350
|
+
* @example
|
|
351
|
+
* new RegExp(str.escapeRegExp("1+1=2?")).test("1+1=2?"); // true
|
|
352
|
+
*
|
|
353
|
+
* @param {unknown} input
|
|
354
|
+
* @returns {string}
|
|
355
|
+
*/
|
|
356
|
+
export function escapeRegExp(input: unknown): string;
|
|
357
|
+
/**
|
|
358
|
+
* Counts visible characters. Unlike `.length`, an emoji or an accented
|
|
359
|
+
* letter counts as one.
|
|
360
|
+
*
|
|
361
|
+
* @example
|
|
362
|
+
* "👨👩👧".length; // 8
|
|
363
|
+
* str.length("👨👩👧"); // 1
|
|
364
|
+
*
|
|
365
|
+
* @param {unknown} input
|
|
366
|
+
* @returns {number}
|
|
367
|
+
*/
|
|
368
|
+
export function length(input: unknown): number;
|
|
369
|
+
/**
|
|
370
|
+
* Size of the text in bytes once encoded, UTF-8 by default. Useful when a
|
|
371
|
+
* limit is in bytes, like a database column or an HTTP header.
|
|
372
|
+
*
|
|
373
|
+
* @example
|
|
374
|
+
* str.byteLength("é"); // 2
|
|
375
|
+
* str.byteLength("😀"); // 4
|
|
376
|
+
*
|
|
377
|
+
* @param {unknown} input
|
|
378
|
+
* @param {BufferEncoding} [encoding="utf8"]
|
|
379
|
+
* @returns {number}
|
|
380
|
+
*/
|
|
381
|
+
export function byteLength(input: unknown, encoding?: BufferEncoding): number;
|
|
382
|
+
/**
|
|
383
|
+
* Counts how many times `search` appears, without overlaps.
|
|
384
|
+
*
|
|
385
|
+
* @example
|
|
386
|
+
* str.count("banana", "a"); // 3
|
|
387
|
+
* str.count("aaaa", "aa"); // 2
|
|
388
|
+
*
|
|
389
|
+
* @param {unknown} input
|
|
390
|
+
* @param {string} search An empty string gives `0`.
|
|
391
|
+
* @returns {number}
|
|
392
|
+
*/
|
|
393
|
+
export function count(input: unknown, search: string): number;
|
|
394
|
+
/**
|
|
395
|
+
* Shortens text to `length` visible characters, ending with `…` when cut.
|
|
396
|
+
*
|
|
397
|
+
* @example
|
|
398
|
+
* str.truncate("Hello world", 8); // "Hello w…"
|
|
399
|
+
* str.truncate("Hello world", 8, { omission: "..." }); // "Hello..."
|
|
400
|
+
* str.truncate("Hello big world", 12, { words: true }); // "Hello big…"
|
|
401
|
+
*
|
|
402
|
+
* @param {unknown} input
|
|
403
|
+
* @param {number} length Maximum length, omission included.
|
|
404
|
+
* @param {TruncateOptions} [options]
|
|
405
|
+
* @returns {string}
|
|
406
|
+
*/
|
|
407
|
+
export function truncate(input: unknown, length: number, options?: TruncateOptions): string;
|
|
408
|
+
/**
|
|
409
|
+
* Returns the text between `start` and the next `end`, or `undefined` if a
|
|
410
|
+
* marker is missing.
|
|
411
|
+
*
|
|
412
|
+
* @example
|
|
413
|
+
* str.between("Hello [world]!", "[", "]"); // "world"
|
|
414
|
+
*
|
|
415
|
+
* @param {unknown} input
|
|
416
|
+
* @param {string} start
|
|
417
|
+
* @param {string} end
|
|
418
|
+
* @returns {string | undefined}
|
|
419
|
+
*/
|
|
420
|
+
export function between(input: unknown, start: string, end: string): string | undefined;
|
|
421
|
+
/**
|
|
422
|
+
* Splits at the first occurrence of `separator` only.
|
|
423
|
+
*
|
|
424
|
+
* @example
|
|
425
|
+
* str.splitOnce("key=value=more", "="); // ["key", "value=more"]
|
|
426
|
+
* str.splitOnce("novalue", "="); // ["novalue", undefined]
|
|
427
|
+
*
|
|
428
|
+
* @param {unknown} input
|
|
429
|
+
* @param {string} separator
|
|
430
|
+
* @returns {[string, string | undefined]}
|
|
431
|
+
*/
|
|
432
|
+
export function splitOnce(input: unknown, separator: string): [string, string | undefined];
|
|
433
|
+
/**
|
|
434
|
+
* Splits text into lines, whatever the line endings.
|
|
435
|
+
*
|
|
436
|
+
* @example
|
|
437
|
+
* str.lines("a\r\nb\nc"); // ["a", "b", "c"]
|
|
438
|
+
*
|
|
439
|
+
* @param {unknown} input
|
|
440
|
+
* @returns {string[]}
|
|
441
|
+
*/
|
|
442
|
+
export function lines(input: unknown): string[];
|
|
443
|
+
/**
|
|
444
|
+
* Pads the start until the text is `length` characters long.
|
|
445
|
+
*
|
|
446
|
+
* @example
|
|
447
|
+
* str.padStart("7", 3, "0"); // "007"
|
|
448
|
+
*
|
|
449
|
+
* @param {unknown} input
|
|
450
|
+
* @param {number} length
|
|
451
|
+
* @param {string} [char=" "]
|
|
452
|
+
* @returns {string}
|
|
453
|
+
*/
|
|
454
|
+
export function padStart(input: unknown, length: number, char?: string): string;
|
|
455
|
+
/**
|
|
456
|
+
* Pads the end until the text is `length` characters long.
|
|
457
|
+
*
|
|
458
|
+
* @example
|
|
459
|
+
* str.padEnd("ab", 5, "."); // "ab..."
|
|
460
|
+
*
|
|
461
|
+
* @param {unknown} input
|
|
462
|
+
* @param {number} length
|
|
463
|
+
* @param {string} [char=" "]
|
|
464
|
+
* @returns {string}
|
|
465
|
+
*/
|
|
466
|
+
export function padEnd(input: unknown, length: number, char?: string): string;
|
|
467
|
+
/**
|
|
468
|
+
* Centers text within `length` characters. An odd leftover goes to the right.
|
|
469
|
+
*
|
|
470
|
+
* @example
|
|
471
|
+
* str.center("hi", 7, "*"); // "**hi***"
|
|
472
|
+
*
|
|
473
|
+
* @param {unknown} input
|
|
474
|
+
* @param {number} length
|
|
475
|
+
* @param {string} [char=" "]
|
|
476
|
+
* @returns {string}
|
|
477
|
+
*/
|
|
478
|
+
export function center(input: unknown, length: number, char?: string): string;
|
|
479
|
+
/**
|
|
480
|
+
* Indents every non-empty line.
|
|
481
|
+
*
|
|
482
|
+
* @example
|
|
483
|
+
* str.indent("a\nb", 2); // " a\n b"
|
|
484
|
+
* str.indent("a\nb", "> "); // "> a\n> b"
|
|
485
|
+
*
|
|
486
|
+
* @param {unknown} input
|
|
487
|
+
* @param {number | string} [prefix=2] A number of spaces, or the prefix itself.
|
|
488
|
+
* @returns {string}
|
|
489
|
+
*/
|
|
490
|
+
export function indent(input: unknown, prefix?: number | string): string;
|
|
491
|
+
/**
|
|
492
|
+
* Removes the indentation shared by all lines, and blank first and last
|
|
493
|
+
* lines. Works as a template tag, so multi-line strings can follow your
|
|
494
|
+
* code's indentation.
|
|
495
|
+
*
|
|
496
|
+
* @example
|
|
497
|
+
* const sql = str.dedent`
|
|
498
|
+
* SELECT *
|
|
499
|
+
* FROM users
|
|
500
|
+
* WHERE id = ${id}
|
|
501
|
+
* `;
|
|
502
|
+
* // "SELECT *\n FROM users\n WHERE id = 42"
|
|
503
|
+
*
|
|
504
|
+
* @param {unknown} input
|
|
505
|
+
* @param {...unknown} values
|
|
506
|
+
* @returns {string}
|
|
507
|
+
*/
|
|
508
|
+
export function dedent(input: unknown, ...values: unknown[]): string;
|
|
509
|
+
/**
|
|
510
|
+
* Wraps text so no line is longer than `width` visible characters. Existing
|
|
511
|
+
* line breaks are kept.
|
|
512
|
+
*
|
|
513
|
+
* @example
|
|
514
|
+
* str.wrap("The quick brown fox jumps over the lazy dog", 16);
|
|
515
|
+
* // "The quick brown\nfox jumps over\nthe lazy dog"
|
|
516
|
+
*
|
|
517
|
+
* @param {unknown} input
|
|
518
|
+
* @param {WrapOptions | number} [options] Options, or just the width.
|
|
519
|
+
* @returns {string}
|
|
520
|
+
*/
|
|
521
|
+
export function wrap(input: unknown, options?: WrapOptions | number): string;
|
|
522
|
+
/**
|
|
523
|
+
* Reverses text without breaking emoji or accents.
|
|
524
|
+
*
|
|
525
|
+
* @example
|
|
526
|
+
* str.reverse("añ👍🏽"); // "👍🏽ña"
|
|
527
|
+
*
|
|
528
|
+
* @param {unknown} input
|
|
529
|
+
* @returns {string}
|
|
530
|
+
*/
|
|
531
|
+
export function reverse(input: unknown): string;
|
|
532
|
+
/**
|
|
533
|
+
* Hides part of a string, like a card number or a token.
|
|
534
|
+
*
|
|
535
|
+
* @example
|
|
536
|
+
* str.mask("4242424242424242"); // "************4242"
|
|
537
|
+
* str.mask("4242 4242 4242 4242", { keepSpaces: true }); // "**** **** **** 4242"
|
|
538
|
+
* str.mask("secret-token", { start: 2, end: 2, char: "•" }); // "se••••••••en"
|
|
539
|
+
*
|
|
540
|
+
* @param {unknown} input
|
|
541
|
+
* @param {MaskOptions} [options]
|
|
542
|
+
* @returns {string}
|
|
543
|
+
*/
|
|
544
|
+
export function mask(input: unknown, options?: MaskOptions): string;
|
|
545
|
+
/**
|
|
546
|
+
* The initials of a name, in uppercase.
|
|
547
|
+
*
|
|
548
|
+
* @example
|
|
549
|
+
* str.initials("Ada Lovelace"); // "AL"
|
|
550
|
+
* str.initials("jean-luc picard", 3); // "JLP"
|
|
551
|
+
*
|
|
552
|
+
* @param {unknown} input
|
|
553
|
+
* @param {number} [max=2] Maximum number of letters.
|
|
554
|
+
* @returns {string}
|
|
555
|
+
*/
|
|
556
|
+
export function initials(input: unknown, max?: number): string;
|
|
557
|
+
/**
|
|
558
|
+
* Picks the right plural for a count, following the rules of the language,
|
|
559
|
+
* and puts the formatted count in front.
|
|
560
|
+
*
|
|
561
|
+
* @example
|
|
562
|
+
* str.plural(1, { one: "file", other: "files" }); // "1 file"
|
|
563
|
+
* str.plural(1234, { one: "item", other: "items" }); // "1,234 items"
|
|
564
|
+
* str.plural(0, { zero: "no files", one: "file", other: "files" }); // "no files"
|
|
565
|
+
* str.plural(0, { one: "fichier", other: "fichiers" }, { locale: "fr" }); // "0 fichier"
|
|
566
|
+
*
|
|
567
|
+
* @param {number} value
|
|
568
|
+
* @param {PluralForms} forms
|
|
569
|
+
* @param {PluralOptions} [options]
|
|
570
|
+
* @returns {string}
|
|
571
|
+
*/
|
|
572
|
+
export function plural(value: number, forms: PluralForms, options?: PluralOptions): string;
|
|
573
|
+
/**
|
|
574
|
+
* Fills `{placeholders}` with values. Dotted paths like `{user.name}` work,
|
|
575
|
+
* and missing values are left alone unless you give a `fallback`.
|
|
576
|
+
*
|
|
577
|
+
* @example
|
|
578
|
+
* str.template("Hi {name}, you have {count} messages", { name: "Jo", count: 3 });
|
|
579
|
+
* // "Hi Jo, you have 3 messages"
|
|
580
|
+
* str.template("Hello {{ user.name }}", { user: { name: "Ada" } }, { open: "{{", close: "}}" });
|
|
581
|
+
* // "Hello Ada"
|
|
582
|
+
*
|
|
583
|
+
* @param {unknown} input
|
|
584
|
+
* @param {Record<string, any>} data
|
|
585
|
+
* @param {TemplateOptions} [options]
|
|
586
|
+
* @returns {string}
|
|
587
|
+
*/
|
|
588
|
+
export function template(input: unknown, data: Record<string, any>, options?: TemplateOptions): string;
|
|
589
|
+
/**
|
|
590
|
+
* Adds `prefix` unless the text already starts with it.
|
|
591
|
+
*
|
|
592
|
+
* @example
|
|
593
|
+
* str.ensurePrefix("example.com", "https://"); // "https://example.com"
|
|
594
|
+
*
|
|
595
|
+
* @param {unknown} input
|
|
596
|
+
* @param {string} prefix
|
|
597
|
+
* @returns {string}
|
|
598
|
+
*/
|
|
599
|
+
export function ensurePrefix(input: unknown, prefix: string): string;
|
|
600
|
+
/**
|
|
601
|
+
* Adds `suffix` unless the text already ends with it.
|
|
602
|
+
*
|
|
603
|
+
* @example
|
|
604
|
+
* str.ensureSuffix("path/to", "/"); // "path/to/"
|
|
605
|
+
*
|
|
606
|
+
* @param {unknown} input
|
|
607
|
+
* @param {string} suffix
|
|
608
|
+
* @returns {string}
|
|
609
|
+
*/
|
|
610
|
+
export function ensureSuffix(input: unknown, suffix: string): string;
|
|
611
|
+
/**
|
|
612
|
+
* Removes `prefix` if the text starts with it.
|
|
613
|
+
*
|
|
614
|
+
* @example
|
|
615
|
+
* str.removePrefix("https://example.com", "https://"); // "example.com"
|
|
616
|
+
*
|
|
617
|
+
* @param {unknown} input
|
|
618
|
+
* @param {string} prefix
|
|
619
|
+
* @returns {string}
|
|
620
|
+
*/
|
|
621
|
+
export function removePrefix(input: unknown, prefix: string): string;
|
|
622
|
+
/**
|
|
623
|
+
* Removes `suffix` if the text ends with it.
|
|
624
|
+
*
|
|
625
|
+
* @example
|
|
626
|
+
* str.removeSuffix("report.pdf", ".pdf"); // "report"
|
|
627
|
+
*
|
|
628
|
+
* @param {unknown} input
|
|
629
|
+
* @param {string} suffix
|
|
630
|
+
* @returns {string}
|
|
631
|
+
*/
|
|
632
|
+
export function removeSuffix(input: unknown, suffix: string): string;
|
|
633
|
+
/**
|
|
634
|
+
* Compares two strings the way people sort them: numbers in natural order
|
|
635
|
+
* and accents in the right place. Pass it straight to `sort()`.
|
|
636
|
+
*
|
|
637
|
+
* @example
|
|
638
|
+
* ["file10", "file2", "File1"].sort(str.compare); // ["File1", "file2", "file10"]
|
|
639
|
+
* str.compare("a", "A", { sensitivity: "base" }); // 0
|
|
640
|
+
*
|
|
641
|
+
* @param {unknown} a
|
|
642
|
+
* @param {unknown} b
|
|
643
|
+
* @param {CompareOptions} [options]
|
|
644
|
+
* @returns {number} Negative if `a` comes first, positive if `b` does, `0` if equal.
|
|
645
|
+
*/
|
|
646
|
+
export function compare(a: unknown, b: unknown, options?: CompareOptions): number;
|
|
647
|
+
/**
|
|
648
|
+
* The number of single-character edits needed to turn `a` into `b`.
|
|
649
|
+
*
|
|
650
|
+
* @example
|
|
651
|
+
* str.levenshtein("kitten", "sitting"); // 3
|
|
652
|
+
*
|
|
653
|
+
* @param {unknown} a
|
|
654
|
+
* @param {unknown} b
|
|
655
|
+
* @returns {number}
|
|
656
|
+
*/
|
|
657
|
+
export function levenshtein(a: unknown, b: unknown): number;
|
|
658
|
+
/**
|
|
659
|
+
* How alike two strings are, from `0` (nothing in common) to `1` (identical).
|
|
660
|
+
*
|
|
661
|
+
* @example
|
|
662
|
+
* str.similarity("hello", "hallo"); // 0.8
|
|
663
|
+
*
|
|
664
|
+
* @param {unknown} a
|
|
665
|
+
* @param {unknown} b
|
|
666
|
+
* @returns {number}
|
|
667
|
+
*/
|
|
668
|
+
export function similarity(a: unknown, b: unknown): number;
|
|
669
|
+
/**
|
|
670
|
+
* Finds the candidate closest to `input`. Made for "Did you mean...?"
|
|
671
|
+
* suggestions.
|
|
672
|
+
*
|
|
673
|
+
* @example
|
|
674
|
+
* str.closest("instal", ["install", "uninstall", "list"]); // "install"
|
|
675
|
+
* str.closest("xyz", ["install", "list"]); // undefined
|
|
676
|
+
*
|
|
677
|
+
* @param {unknown} input
|
|
678
|
+
* @param {Iterable<string>} candidates
|
|
679
|
+
* @param {ClosestOptions} [options]
|
|
680
|
+
* @returns {string | undefined} `undefined` when nothing is close enough.
|
|
681
|
+
*/
|
|
682
|
+
export function closest(input: unknown, candidates: Iterable<string>, options?: ClosestOptions): string | undefined;
|
|
683
|
+
/**
|
|
684
|
+
* A random string. It relies on `Math.random`, so don't use it for secrets:
|
|
685
|
+
* `nc.id.token()` and `nc.id.nano()` are made for that.
|
|
686
|
+
*
|
|
687
|
+
* @example
|
|
688
|
+
* str.random(); // "aZ3kP9qL0xYb7TcW"
|
|
689
|
+
* str.random(6, { charset: "0123456789" }); // "402917"
|
|
690
|
+
*
|
|
691
|
+
* @param {number} [size=16]
|
|
692
|
+
* @param {RandomStringOptions | string} [options] Options, or the charset itself.
|
|
693
|
+
* @returns {string}
|
|
694
|
+
*/
|
|
695
|
+
export function random(size?: number, options?: RandomStringOptions | string): string;
|
|
696
|
+
//# sourceMappingURL=Str.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Str.d.ts","sourceRoot":"","sources":["../../src/Str.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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