@poppinss/utils 6.5.0-2 → 6.5.0-4
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 +2 -0
- package/build/index.d.ts +284 -19
- package/build/index.js +372 -23
- package/build/src/json/main.d.ts +15 -3
- package/build/src/json/main.js +5 -6
- package/build/src/string/main.d.ts +121 -15
- package/build/src/string/main.js +6 -42
- package/build/src/string_builder.d.ts +60 -1
- package/build/src/string_builder.js +148 -86
- package/build/src/types.d.ts +18 -8
- package/build/src/types.js +0 -1
- package/package.json +56 -64
- package/build/src/base64.d.ts +0 -17
- package/build/src/base64.js +0 -35
- package/build/src/compose.d.ts +0 -14
- package/build/src/compose.js +0 -3
- package/build/src/define_static_property.d.ts +0 -7
- package/build/src/define_static_property.js +0 -21
- package/build/src/exception.d.ts +0 -21
- package/build/src/exception.js +0 -40
- package/build/src/exceptions/invalid_arguments_exception.d.ts +0 -5
- package/build/src/exceptions/invalid_arguments_exception.js +0 -6
- package/build/src/exceptions/runtime_exception.d.ts +0 -5
- package/build/src/exceptions/runtime_exception.js +0 -6
- package/build/src/flatten.d.ts +0 -1
- package/build/src/flatten.js +0 -4
- package/build/src/fs_import_all.d.ts +0 -3
- package/build/src/fs_import_all.js +0 -28
- package/build/src/fs_read_all.d.ts +0 -3
- package/build/src/fs_read_all.js +0 -55
- package/build/src/import_default.d.ts +0 -3
- package/build/src/import_default.js +0 -15
- package/build/src/is_script_file.d.ts +0 -1
- package/build/src/is_script_file.js +0 -12
- package/build/src/json/safe_parse.d.ts +0 -2
- package/build/src/json/safe_parse.js +0 -7
- package/build/src/json/safe_stringify.d.ts +0 -2
- package/build/src/json/safe_stringify.js +0 -18
- package/build/src/message_builder.d.ts +0 -5
- package/build/src/message_builder.js +0 -38
- package/build/src/natural_sort.d.ts +0 -1
- package/build/src/natural_sort.js +0 -3
- package/build/src/object_builder.d.ts +0 -18
- package/build/src/object_builder.js +0 -32
- package/build/src/safe_equal.d.ts +0 -7
- package/build/src/safe_equal.js +0 -14
- package/build/src/slash.d.ts +0 -1
- package/build/src/slash.js +0 -1
- package/build/src/string/bytes.d.ts +0 -6
- package/build/src/string/bytes.js +0 -12
- package/build/src/string/change_case.d.ts +0 -13
- package/build/src/string/change_case.js +0 -75
- package/build/src/string/excerpt.d.ts +0 -4
- package/build/src/string/excerpt.js +0 -10
- package/build/src/string/interpolate.d.ts +0 -1
- package/build/src/string/interpolate.js +0 -19
- package/build/src/string/milliseconds.d.ts +0 -5
- package/build/src/string/milliseconds.js +0 -16
- package/build/src/string/ordinal.d.ts +0 -1
- package/build/src/string/ordinal.js +0 -21
- package/build/src/string/pluralize.d.ts +0 -12
- package/build/src/string/pluralize.js +0 -12
- package/build/src/string/random.d.ts +0 -1
- package/build/src/string/random.js +0 -7
- package/build/src/string/seconds.d.ts +0 -5
- package/build/src/string/seconds.js +0 -16
- package/build/src/string/sentence.d.ts +0 -5
- package/build/src/string/sentence.js +0 -13
- package/build/src/string/slugify.d.ts +0 -2
- package/build/src/string/slugify.js +0 -2
- package/build/src/string/truncate.d.ts +0 -4
- package/build/src/string/truncate.js +0 -10
package/build/index.js
CHANGED
|
@@ -1,24 +1,373 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export { slash } from './src/slash.js';
|
|
17
|
-
export { RuntimeException } from './src/exceptions/runtime_exception.js';
|
|
18
|
-
export { InvalidArgumentsException } from './src/exceptions/invalid_arguments_exception.js';
|
|
19
|
-
export function getDirname(url) {
|
|
20
|
-
return pathDirname(getFilename(url));
|
|
21
|
-
}
|
|
22
|
-
export function getFilename(url) {
|
|
23
|
-
return fileURLToPath(url);
|
|
1
|
+
import {
|
|
2
|
+
base64,
|
|
3
|
+
milliseconds_default
|
|
4
|
+
} from "./chunk-PWRXO3NF.js";
|
|
5
|
+
import {
|
|
6
|
+
main_default
|
|
7
|
+
} from "./chunk-XHQBV7AF.js";
|
|
8
|
+
|
|
9
|
+
// index.ts
|
|
10
|
+
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
11
|
+
import { dirname as pathDirname } from "node:path";
|
|
12
|
+
|
|
13
|
+
// src/compose.ts
|
|
14
|
+
function compose(superclass, ...mixins) {
|
|
15
|
+
return mixins.reduce((c, mixin) => mixin(c), superclass);
|
|
24
16
|
}
|
|
17
|
+
|
|
18
|
+
// src/exception.ts
|
|
19
|
+
import { format } from "node:util";
|
|
20
|
+
var Exception = class extends Error {
|
|
21
|
+
/**
|
|
22
|
+
* Name of the class that raised the exception.
|
|
23
|
+
*/
|
|
24
|
+
name;
|
|
25
|
+
/**
|
|
26
|
+
* A status code for the error. Usually helpful when converting errors
|
|
27
|
+
* to HTTP responses.
|
|
28
|
+
*/
|
|
29
|
+
status;
|
|
30
|
+
constructor(message, options) {
|
|
31
|
+
super(message, options);
|
|
32
|
+
const ErrorConstructor = this.constructor;
|
|
33
|
+
this.name = ErrorConstructor.name;
|
|
34
|
+
this.message = message || ErrorConstructor.message || "";
|
|
35
|
+
this.status = options?.status || ErrorConstructor.status || 500;
|
|
36
|
+
const code = options?.code || ErrorConstructor.code;
|
|
37
|
+
if (code !== void 0) {
|
|
38
|
+
this.code = code;
|
|
39
|
+
}
|
|
40
|
+
const help = ErrorConstructor.help;
|
|
41
|
+
if (help !== void 0) {
|
|
42
|
+
this.help = help;
|
|
43
|
+
}
|
|
44
|
+
Error.captureStackTrace(this, ErrorConstructor);
|
|
45
|
+
}
|
|
46
|
+
get [Symbol.toStringTag]() {
|
|
47
|
+
return this.constructor.name;
|
|
48
|
+
}
|
|
49
|
+
toString() {
|
|
50
|
+
if (this.code) {
|
|
51
|
+
return `${this.name} [${this.code}]: ${this.message}`;
|
|
52
|
+
}
|
|
53
|
+
return `${this.name}: ${this.message}`;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
function createError(message, code, status) {
|
|
57
|
+
return class extends Exception {
|
|
58
|
+
static message = message;
|
|
59
|
+
static code = code;
|
|
60
|
+
static status = status;
|
|
61
|
+
constructor(args, options) {
|
|
62
|
+
super(format(message, ...args || []), options);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// src/exceptions/runtime_exception.ts
|
|
68
|
+
var RuntimeException = class extends Exception {
|
|
69
|
+
static code = "E_RUNTIME_EXCEPTION";
|
|
70
|
+
static status = 500;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// src/import_default.ts
|
|
74
|
+
async function importDefault(importFn, filePath) {
|
|
75
|
+
const moduleExports = await importFn();
|
|
76
|
+
if (!("default" in moduleExports)) {
|
|
77
|
+
const errorMessage = filePath ? `Missing "export default" in module "${filePath}"` : `Missing "export default" from lazy import "${importFn}"`;
|
|
78
|
+
throw new RuntimeException(errorMessage, {
|
|
79
|
+
cause: {
|
|
80
|
+
source: importFn
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return moduleExports.default;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// src/define_static_property.ts
|
|
88
|
+
import lodash from "@poppinss/utils/lodash";
|
|
89
|
+
function defineStaticProperty(self, propertyName, {
|
|
90
|
+
initialValue,
|
|
91
|
+
strategy
|
|
92
|
+
}) {
|
|
93
|
+
if (!self.hasOwnProperty(propertyName)) {
|
|
94
|
+
const value = self[propertyName];
|
|
95
|
+
if (strategy === "define" || value === void 0) {
|
|
96
|
+
Object.defineProperty(self, propertyName, {
|
|
97
|
+
value: initialValue,
|
|
98
|
+
configurable: true,
|
|
99
|
+
enumerable: true,
|
|
100
|
+
writable: true
|
|
101
|
+
});
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
Object.defineProperty(self, propertyName, {
|
|
105
|
+
value: typeof strategy === "function" ? strategy(value) : lodash.cloneDeep(value),
|
|
106
|
+
configurable: true,
|
|
107
|
+
enumerable: true,
|
|
108
|
+
writable: true
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// src/flatten.ts
|
|
114
|
+
import { flattie } from "flattie";
|
|
115
|
+
function flatten(input, glue, keepNullish) {
|
|
116
|
+
return flattie(input, glue, keepNullish);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// src/fs_import_all.ts
|
|
120
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
121
|
+
import lodash2 from "@poppinss/utils/lodash";
|
|
122
|
+
import { extname as extname2, relative, sep } from "node:path";
|
|
123
|
+
|
|
124
|
+
// src/fs_read_all.ts
|
|
125
|
+
import { join } from "node:path";
|
|
126
|
+
import { readdir, stat } from "node:fs/promises";
|
|
127
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
128
|
+
|
|
129
|
+
// src/slash.ts
|
|
130
|
+
import { default as default2 } from "slash";
|
|
131
|
+
|
|
132
|
+
// src/natural_sort.ts
|
|
133
|
+
function naturalSort(current, next) {
|
|
134
|
+
return current.localeCompare(next, void 0, { numeric: true, sensitivity: "base" });
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// src/fs_read_all.ts
|
|
138
|
+
function filterDotFiles(fileName) {
|
|
139
|
+
return fileName[0] !== ".";
|
|
140
|
+
}
|
|
141
|
+
async function readFiles(root, files, options, relativePath) {
|
|
142
|
+
const location = join(root, relativePath);
|
|
143
|
+
const stats = await stat(location);
|
|
144
|
+
if (stats.isDirectory()) {
|
|
145
|
+
let locationFiles = await readdir(location);
|
|
146
|
+
await Promise.all(
|
|
147
|
+
locationFiles.filter(filterDotFiles).map((file) => {
|
|
148
|
+
return readFiles(root, files, options, join(relativePath, file));
|
|
149
|
+
})
|
|
150
|
+
);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const pathType = options.pathType || "relative";
|
|
154
|
+
switch (pathType) {
|
|
155
|
+
case "relative":
|
|
156
|
+
files.push(relativePath);
|
|
157
|
+
break;
|
|
158
|
+
case "absolute":
|
|
159
|
+
files.push(location);
|
|
160
|
+
break;
|
|
161
|
+
case "unixRelative":
|
|
162
|
+
files.push(default2(relativePath));
|
|
163
|
+
break;
|
|
164
|
+
case "unixAbsolute":
|
|
165
|
+
files.push(default2(location));
|
|
166
|
+
break;
|
|
167
|
+
case "url":
|
|
168
|
+
files.push(pathToFileURL(location).href);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
async function fsReadAll(location, options) {
|
|
172
|
+
const normalizedLocation = typeof location === "string" ? location : fileURLToPath(location);
|
|
173
|
+
const normalizedOptions = Object.assign({ absolute: false, sort: naturalSort }, options);
|
|
174
|
+
const files = [];
|
|
175
|
+
try {
|
|
176
|
+
await stat(normalizedLocation);
|
|
177
|
+
} catch (error) {
|
|
178
|
+
if (normalizedOptions.ignoreMissingRoot) {
|
|
179
|
+
return [];
|
|
180
|
+
}
|
|
181
|
+
throw error;
|
|
182
|
+
}
|
|
183
|
+
await readFiles(normalizedLocation, files, normalizedOptions, "");
|
|
184
|
+
if (normalizedOptions.filter) {
|
|
185
|
+
return files.filter(normalizedOptions.filter).sort(normalizedOptions.sort);
|
|
186
|
+
}
|
|
187
|
+
return files.sort(normalizedOptions.sort);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// src/is_script_file.ts
|
|
191
|
+
import { extname } from "node:path";
|
|
192
|
+
var JS_MODULES = [".js", ".json", ".cjs", ".mjs"];
|
|
193
|
+
function isScriptFile(filePath) {
|
|
194
|
+
const ext = extname(filePath);
|
|
195
|
+
if (JS_MODULES.includes(ext)) {
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
if (ext === ".ts" && !filePath.endsWith(".d.ts")) {
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// src/fs_import_all.ts
|
|
205
|
+
async function importFile(basePath, fileURL, values, options) {
|
|
206
|
+
const filePath = fileURLToPath2(fileURL);
|
|
207
|
+
const fileExtension = extname2(filePath);
|
|
208
|
+
const collectionKey = relative(basePath, filePath).replace(new RegExp(`${fileExtension}$`), "").split(sep);
|
|
209
|
+
const exportedValue = fileExtension === ".json" ? await import(fileURL, { assert: { type: "json" } }) : await import(fileURL);
|
|
210
|
+
lodash2.set(
|
|
211
|
+
values,
|
|
212
|
+
options.transformKeys ? options.transformKeys(collectionKey) : collectionKey,
|
|
213
|
+
exportedValue.default ? exportedValue.default : { ...exportedValue }
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
async function fsImportAll(location, options) {
|
|
217
|
+
options = options || {};
|
|
218
|
+
const collection = {};
|
|
219
|
+
const normalizedLocation = typeof location === "string" ? location : fileURLToPath2(location);
|
|
220
|
+
const files = await fsReadAll(normalizedLocation, {
|
|
221
|
+
filter: isScriptFile,
|
|
222
|
+
...options,
|
|
223
|
+
pathType: "url"
|
|
224
|
+
});
|
|
225
|
+
await Promise.all(files.map((file) => importFile(normalizedLocation, file, collection, options)));
|
|
226
|
+
return collection;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// src/message_builder.ts
|
|
230
|
+
var MessageBuilder = class {
|
|
231
|
+
#getExpiryDate(expiresIn) {
|
|
232
|
+
if (!expiresIn) {
|
|
233
|
+
return void 0;
|
|
234
|
+
}
|
|
235
|
+
const expiryMs = milliseconds_default.parse(expiresIn);
|
|
236
|
+
return new Date(Date.now() + expiryMs);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Returns a boolean telling, if message has been expired or not
|
|
240
|
+
*/
|
|
241
|
+
#isExpired(message) {
|
|
242
|
+
if (!message.expiryDate) {
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
const expiryDate = new Date(message.expiryDate);
|
|
246
|
+
return Number.isNaN(expiryDate.getTime()) || expiryDate < /* @__PURE__ */ new Date();
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Builds a message by encoding expiry date and purpose inside it.
|
|
250
|
+
*/
|
|
251
|
+
build(message, expiresIn, purpose) {
|
|
252
|
+
const expiryDate = this.#getExpiryDate(expiresIn);
|
|
253
|
+
return main_default.safeStringify({ message, purpose, expiryDate });
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Verifies the message for expiry and purpose.
|
|
257
|
+
*/
|
|
258
|
+
verify(message, purpose) {
|
|
259
|
+
const parsed = main_default.safeParse(message);
|
|
260
|
+
if (typeof parsed !== "object" || !parsed) {
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
if (!parsed.message) {
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
266
|
+
if (parsed.purpose !== purpose) {
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
if (this.#isExpired(parsed)) {
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
return parsed.message;
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
// src/object_builder.ts
|
|
277
|
+
var ObjectBuilder = class {
|
|
278
|
+
#ignoreNull;
|
|
279
|
+
values;
|
|
280
|
+
constructor(initialValue, ignoreNull) {
|
|
281
|
+
this.values = initialValue;
|
|
282
|
+
this.#ignoreNull = ignoreNull === true ? true : false;
|
|
283
|
+
}
|
|
284
|
+
add(key, value) {
|
|
285
|
+
if (value === void 0) {
|
|
286
|
+
return this;
|
|
287
|
+
}
|
|
288
|
+
if (this.#ignoreNull === true && value === null) {
|
|
289
|
+
return this;
|
|
290
|
+
}
|
|
291
|
+
;
|
|
292
|
+
this.values[key] = value;
|
|
293
|
+
return this;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Remove key from the object
|
|
297
|
+
*/
|
|
298
|
+
remove(key) {
|
|
299
|
+
delete this.values[key];
|
|
300
|
+
return this;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Find if a value exists
|
|
304
|
+
*/
|
|
305
|
+
has(key) {
|
|
306
|
+
return this.get(key) !== void 0;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Get the existing value for a given key
|
|
310
|
+
*/
|
|
311
|
+
get(key) {
|
|
312
|
+
return this.values[key];
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Get the underlying constructed object
|
|
316
|
+
*/
|
|
317
|
+
toObject() {
|
|
318
|
+
return this.values;
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
// src/safe_equal.ts
|
|
323
|
+
import { Buffer } from "node:buffer";
|
|
324
|
+
import { timingSafeEqual } from "node:crypto";
|
|
325
|
+
function safeEqual(trustedValue, userInput) {
|
|
326
|
+
if (typeof trustedValue === "string" && typeof userInput === "string") {
|
|
327
|
+
const trustedLength = Buffer.byteLength(trustedValue);
|
|
328
|
+
const trustedValueBuffer = Buffer.alloc(trustedLength, 0, "utf-8");
|
|
329
|
+
trustedValueBuffer.write(trustedValue);
|
|
330
|
+
const userValueBuffer = Buffer.alloc(trustedLength, 0, "utf-8");
|
|
331
|
+
userValueBuffer.write(userInput);
|
|
332
|
+
return timingSafeEqual(trustedValueBuffer, userValueBuffer) && trustedLength === Buffer.byteLength(userInput);
|
|
333
|
+
}
|
|
334
|
+
return timingSafeEqual(
|
|
335
|
+
Buffer.from(trustedValue),
|
|
336
|
+
Buffer.from(userInput)
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// src/exceptions/invalid_arguments_exception.ts
|
|
341
|
+
var InvalidArgumentsException = class extends Exception {
|
|
342
|
+
static code = "E_INVALID_ARGUMENTS_EXCEPTION";
|
|
343
|
+
static status = 500;
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
// index.ts
|
|
347
|
+
function getDirname(url) {
|
|
348
|
+
return pathDirname(getFilename(url));
|
|
349
|
+
}
|
|
350
|
+
function getFilename(url) {
|
|
351
|
+
return fileURLToPath3(url);
|
|
352
|
+
}
|
|
353
|
+
export {
|
|
354
|
+
Exception,
|
|
355
|
+
InvalidArgumentsException,
|
|
356
|
+
MessageBuilder,
|
|
357
|
+
ObjectBuilder,
|
|
358
|
+
RuntimeException,
|
|
359
|
+
base64,
|
|
360
|
+
compose,
|
|
361
|
+
createError,
|
|
362
|
+
defineStaticProperty,
|
|
363
|
+
flatten,
|
|
364
|
+
fsImportAll,
|
|
365
|
+
fsReadAll,
|
|
366
|
+
getDirname,
|
|
367
|
+
getFilename,
|
|
368
|
+
importDefault,
|
|
369
|
+
isScriptFile,
|
|
370
|
+
naturalSort,
|
|
371
|
+
safeEqual,
|
|
372
|
+
default2 as slash
|
|
373
|
+
};
|
package/build/src/json/main.d.ts
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { JSONReviver, JSONReplacer } from '../types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A drop-in replacement for JSON.parse with prototype poisoning protection.
|
|
5
|
+
*/
|
|
6
|
+
declare function safeParse(jsonString: string, reviver?: JSONReviver): any;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* String Javascript values to a JSON string. Handles circular
|
|
10
|
+
* references and bigints
|
|
11
|
+
*/
|
|
12
|
+
declare function safeStringify(value: any, replacer?: JSONReplacer, space?: string | number): string | undefined;
|
|
13
|
+
|
|
3
14
|
declare const json: {
|
|
4
15
|
safeParse: typeof safeParse;
|
|
5
16
|
safeStringify: typeof safeStringify;
|
|
6
17
|
};
|
|
7
|
-
|
|
18
|
+
|
|
19
|
+
export { json as default };
|
package/build/src/json/main.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import {
|
|
2
|
+
main_default
|
|
3
|
+
} from "../../chunk-XHQBV7AF.js";
|
|
4
|
+
export {
|
|
5
|
+
main_default as default
|
|
6
6
|
};
|
|
7
|
-
export default json;
|
|
@@ -1,22 +1,127 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import * as bytes from 'bytes';
|
|
2
|
+
import * as slugify from 'slugify';
|
|
3
|
+
import pluralizePkg from 'pluralize';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Generates a random string of a given size
|
|
7
|
+
*/
|
|
8
|
+
declare function random(size: number): string;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Truncate a sentence to be under a certain characters limit and strip
|
|
12
|
+
* out HTML tags from it.
|
|
13
|
+
*
|
|
14
|
+
* Optionally, you can force the truncate logic to complete words, which
|
|
15
|
+
* may exceed the defined characters limit.
|
|
16
|
+
*/
|
|
17
|
+
declare function excerpt(sentence: string, charactersLimit: number, options?: {
|
|
18
|
+
completeWords?: boolean;
|
|
19
|
+
suffix?: string;
|
|
20
|
+
}): string;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Ordinalize a give number or string
|
|
24
|
+
*/
|
|
25
|
+
declare function ordinal(value: string | number): string;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Truncate a sentence to be under a certain characters limit.
|
|
29
|
+
*
|
|
30
|
+
* Optionally, you can force the truncate logic to complete words, which
|
|
31
|
+
* may exceed the defined characters limit.
|
|
32
|
+
*/
|
|
33
|
+
declare function truncate(sentence: string, charactersLimit: number, options?: {
|
|
34
|
+
completeWords?: boolean;
|
|
35
|
+
suffix?: string;
|
|
36
|
+
}): string;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Convert an array of values to a sentence.
|
|
40
|
+
*/
|
|
41
|
+
declare function sentence(values: any[], options?: {
|
|
42
|
+
separator?: string;
|
|
43
|
+
pairSeparator?: string;
|
|
44
|
+
lastSeparator?: string;
|
|
45
|
+
}): string;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* A simple function interpolate values inside curly braces.
|
|
49
|
+
*
|
|
50
|
+
* ```
|
|
51
|
+
* interpolate('hello {{ username }}', { username: 'virk' })
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
declare function interpolate(input: string, data: any): string;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Pluralize a word based upon the count. The method returns the
|
|
58
|
+
* singular form when count is 1.
|
|
59
|
+
*/
|
|
60
|
+
declare function pluralize(word: string, count?: number, inclusive?: boolean): string;
|
|
61
|
+
declare namespace pluralize {
|
|
62
|
+
var addPluralRule: typeof pluralizePkg.addPluralRule;
|
|
63
|
+
var addSingularRule: typeof pluralizePkg.addSingularRule;
|
|
64
|
+
var addIrregularRule: typeof pluralizePkg.addIrregularRule;
|
|
65
|
+
var addUncountableRule: typeof pluralizePkg.addUncountableRule;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The method is a copy/paste from the "title-case" package. They have
|
|
70
|
+
* a dependency on "tslib", which I don't want.
|
|
71
|
+
*/
|
|
72
|
+
declare function titleCase(input: string): string;
|
|
73
|
+
/**
|
|
74
|
+
* Convert string to camelcase
|
|
75
|
+
*/
|
|
76
|
+
declare function camelCase(value: string): string;
|
|
77
|
+
/**
|
|
78
|
+
* Convert string to snakecase
|
|
79
|
+
*/
|
|
80
|
+
declare function snakeCase(value: string): string;
|
|
81
|
+
/**
|
|
82
|
+
* Convert string to dashcase
|
|
83
|
+
*/
|
|
84
|
+
declare function dashCase(value: string, options?: {
|
|
85
|
+
capitalize?: boolean;
|
|
86
|
+
}): string;
|
|
87
|
+
/**
|
|
88
|
+
* Convert string to pascal case
|
|
89
|
+
*/
|
|
90
|
+
declare function pascalCase(value: string): string;
|
|
91
|
+
/**
|
|
92
|
+
* Convert string to capital case
|
|
93
|
+
*/
|
|
94
|
+
declare function capitalCase(value: string): string;
|
|
95
|
+
/**
|
|
96
|
+
* Convert string to sentence case
|
|
97
|
+
*/
|
|
98
|
+
declare function sentenceCase(value: string): string;
|
|
99
|
+
/**
|
|
100
|
+
* Convert string to dot case
|
|
101
|
+
*/
|
|
102
|
+
declare function dotCase(value: string, options?: {
|
|
103
|
+
lowerCase?: boolean;
|
|
104
|
+
}): string;
|
|
105
|
+
/**
|
|
106
|
+
* Remove all sort of casing from the string. Copy-pasted from
|
|
107
|
+
* "no-case" package with slight modifications.
|
|
108
|
+
*/
|
|
109
|
+
declare function noCase(value: string, transform?: (part: string, index: number, parts: string[]) => string): string;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Condense multiple whitespaces from a string
|
|
113
|
+
*/
|
|
9
114
|
declare function condenseWhitespace(value: string): string;
|
|
10
115
|
declare const string: {
|
|
11
116
|
excerpt: typeof excerpt;
|
|
12
117
|
truncate: typeof truncate;
|
|
13
|
-
slug: typeof
|
|
118
|
+
slug: typeof slugify.default;
|
|
14
119
|
interpolate: typeof interpolate;
|
|
15
|
-
plural: typeof
|
|
120
|
+
plural: typeof pluralize.plural;
|
|
16
121
|
pluralize: typeof pluralize;
|
|
17
|
-
singular: typeof
|
|
18
|
-
isPlural: typeof
|
|
19
|
-
isSingular: typeof
|
|
122
|
+
singular: typeof pluralize.singular;
|
|
123
|
+
isPlural: typeof pluralize.isPlural;
|
|
124
|
+
isSingular: typeof pluralize.isSingular;
|
|
20
125
|
camelCase: typeof camelCase;
|
|
21
126
|
capitalCase: typeof capitalCase;
|
|
22
127
|
dashCase: typeof dashCase;
|
|
@@ -38,9 +143,10 @@ declare const string: {
|
|
|
38
143
|
parse(duration: string | number): number;
|
|
39
144
|
};
|
|
40
145
|
bytes: {
|
|
41
|
-
format(valueInBytes: number, options?:
|
|
146
|
+
format(valueInBytes: number, options?: bytes.BytesOptions | undefined): string;
|
|
42
147
|
parse(unit: string | number): number;
|
|
43
148
|
};
|
|
44
149
|
ordinal: typeof ordinal;
|
|
45
150
|
};
|
|
46
|
-
|
|
151
|
+
|
|
152
|
+
export { string as default };
|
package/build/src/string/main.js
CHANGED
|
@@ -1,43 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import { truncate } from './truncate.js';
|
|
8
|
-
import milliseconds from './milliseconds.js';
|
|
9
|
-
import { sentence } from './sentence.js';
|
|
10
|
-
import { interpolate } from './interpolate.js';
|
|
11
|
-
import { plural, pluralize, singular, isPlural, isSingular } from './pluralize.js';
|
|
12
|
-
import { noCase, dotCase, dashCase, camelCase, snakeCase, titleCase, pascalCase, capitalCase, sentenceCase, } from './change_case.js';
|
|
13
|
-
function condenseWhitespace(value) {
|
|
14
|
-
return value.trim().replace(/\s{2,}/g, ' ');
|
|
15
|
-
}
|
|
16
|
-
const string = {
|
|
17
|
-
excerpt,
|
|
18
|
-
truncate,
|
|
19
|
-
slug,
|
|
20
|
-
interpolate,
|
|
21
|
-
plural,
|
|
22
|
-
pluralize,
|
|
23
|
-
singular,
|
|
24
|
-
isPlural,
|
|
25
|
-
isSingular,
|
|
26
|
-
camelCase,
|
|
27
|
-
capitalCase,
|
|
28
|
-
dashCase,
|
|
29
|
-
dotCase,
|
|
30
|
-
noCase,
|
|
31
|
-
pascalCase,
|
|
32
|
-
sentenceCase,
|
|
33
|
-
snakeCase,
|
|
34
|
-
titleCase,
|
|
35
|
-
random,
|
|
36
|
-
sentence,
|
|
37
|
-
condenseWhitespace,
|
|
38
|
-
seconds,
|
|
39
|
-
milliseconds,
|
|
40
|
-
bytes,
|
|
41
|
-
ordinal,
|
|
1
|
+
import {
|
|
2
|
+
main_default
|
|
3
|
+
} from "../../chunk-OKRMWJO4.js";
|
|
4
|
+
import "../../chunk-PWRXO3NF.js";
|
|
5
|
+
export {
|
|
6
|
+
main_default as default
|
|
42
7
|
};
|
|
43
|
-
export default string;
|