@poppinss/utils 6.5.0-3 → 6.5.0-5
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/chunk-OKRMWJO4.js +269 -0
- package/build/chunk-PWRXO3NF.js +63 -0
- package/build/chunk-XHQBV7AF.js +39 -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 +24 -12
- 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 -5
- package/build/src/exceptions/runtime_exception.d.ts +0 -5
- package/build/src/exceptions/runtime_exception.js +0 -5
- 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
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { fileURLToPath } from 'node:url';
|
|
2
|
-
import lodash from '@poppinss/utils/lodash';
|
|
3
|
-
import { extname, relative, sep } from 'node:path';
|
|
4
|
-
import { fsReadAll } from './fs_read_all.js';
|
|
5
|
-
import { isScriptFile } from './is_script_file.js';
|
|
6
|
-
async function importFile(basePath, fileURL, values, options) {
|
|
7
|
-
const filePath = fileURLToPath(fileURL);
|
|
8
|
-
const fileExtension = extname(filePath);
|
|
9
|
-
const collectionKey = relative(basePath, filePath)
|
|
10
|
-
.replace(new RegExp(`${fileExtension}$`), '')
|
|
11
|
-
.split(sep);
|
|
12
|
-
const exportedValue = fileExtension === '.json'
|
|
13
|
-
? await import(fileURL, { assert: { type: 'json' } })
|
|
14
|
-
: await import(fileURL);
|
|
15
|
-
lodash.set(values, options.transformKeys ? options.transformKeys(collectionKey) : collectionKey, exportedValue.default ? exportedValue.default : { ...exportedValue });
|
|
16
|
-
}
|
|
17
|
-
export async function fsImportAll(location, options) {
|
|
18
|
-
options = options || {};
|
|
19
|
-
const collection = {};
|
|
20
|
-
const normalizedLocation = typeof location === 'string' ? location : fileURLToPath(location);
|
|
21
|
-
const files = await fsReadAll(normalizedLocation, {
|
|
22
|
-
filter: isScriptFile,
|
|
23
|
-
...options,
|
|
24
|
-
pathType: 'url',
|
|
25
|
-
});
|
|
26
|
-
await Promise.all(files.map((file) => importFile(normalizedLocation, file, collection, options)));
|
|
27
|
-
return collection;
|
|
28
|
-
}
|
package/build/src/fs_read_all.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { join } from 'node:path';
|
|
2
|
-
import { readdir, stat } from 'node:fs/promises';
|
|
3
|
-
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
4
|
-
import { slash } from './slash.js';
|
|
5
|
-
import { naturalSort } from './natural_sort.js';
|
|
6
|
-
function filterDotFiles(fileName) {
|
|
7
|
-
return fileName[0] !== '.';
|
|
8
|
-
}
|
|
9
|
-
async function readFiles(root, files, options, relativePath) {
|
|
10
|
-
const location = join(root, relativePath);
|
|
11
|
-
const stats = await stat(location);
|
|
12
|
-
if (stats.isDirectory()) {
|
|
13
|
-
let locationFiles = await readdir(location);
|
|
14
|
-
await Promise.all(locationFiles.filter(filterDotFiles).map((file) => {
|
|
15
|
-
return readFiles(root, files, options, join(relativePath, file));
|
|
16
|
-
}));
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
const pathType = options.pathType || 'relative';
|
|
20
|
-
switch (pathType) {
|
|
21
|
-
case 'relative':
|
|
22
|
-
files.push(relativePath);
|
|
23
|
-
break;
|
|
24
|
-
case 'absolute':
|
|
25
|
-
files.push(location);
|
|
26
|
-
break;
|
|
27
|
-
case 'unixRelative':
|
|
28
|
-
files.push(slash(relativePath));
|
|
29
|
-
break;
|
|
30
|
-
case 'unixAbsolute':
|
|
31
|
-
files.push(slash(location));
|
|
32
|
-
break;
|
|
33
|
-
case 'url':
|
|
34
|
-
files.push(pathToFileURL(location).href);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
export async function fsReadAll(location, options) {
|
|
38
|
-
const normalizedLocation = typeof location === 'string' ? location : fileURLToPath(location);
|
|
39
|
-
const normalizedOptions = Object.assign({ absolute: false, sort: naturalSort }, options);
|
|
40
|
-
const files = [];
|
|
41
|
-
try {
|
|
42
|
-
await stat(normalizedLocation);
|
|
43
|
-
}
|
|
44
|
-
catch (error) {
|
|
45
|
-
if (normalizedOptions.ignoreMissingRoot) {
|
|
46
|
-
return [];
|
|
47
|
-
}
|
|
48
|
-
throw error;
|
|
49
|
-
}
|
|
50
|
-
await readFiles(normalizedLocation, files, normalizedOptions, '');
|
|
51
|
-
if (normalizedOptions.filter) {
|
|
52
|
-
return files.filter(normalizedOptions.filter).sort(normalizedOptions.sort);
|
|
53
|
-
}
|
|
54
|
-
return files.sort(normalizedOptions.sort);
|
|
55
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { RuntimeException } from './exceptions/runtime_exception.js';
|
|
2
|
-
export async function importDefault(importFn, filePath) {
|
|
3
|
-
const moduleExports = await importFn();
|
|
4
|
-
if (!('default' in moduleExports)) {
|
|
5
|
-
const errorMessage = filePath
|
|
6
|
-
? `Missing "export default" in module "${filePath}"`
|
|
7
|
-
: `Missing "export default" from lazy import "${importFn}"`;
|
|
8
|
-
throw new RuntimeException(errorMessage, {
|
|
9
|
-
cause: {
|
|
10
|
-
source: importFn,
|
|
11
|
-
},
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
return moduleExports.default;
|
|
15
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isScriptFile(filePath: string): boolean;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { extname } from 'node:path';
|
|
2
|
-
const JS_MODULES = ['.js', '.json', '.cjs', '.mjs'];
|
|
3
|
-
export function isScriptFile(filePath) {
|
|
4
|
-
const ext = extname(filePath);
|
|
5
|
-
if (JS_MODULES.includes(ext)) {
|
|
6
|
-
return true;
|
|
7
|
-
}
|
|
8
|
-
if (ext === '.ts' && !filePath.endsWith('.d.ts')) {
|
|
9
|
-
return true;
|
|
10
|
-
}
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { configure } from 'safe-stable-stringify';
|
|
2
|
-
const stringify = configure({
|
|
3
|
-
bigint: false,
|
|
4
|
-
circularValue: undefined,
|
|
5
|
-
deterministic: false,
|
|
6
|
-
});
|
|
7
|
-
function jsonStringifyReplacer(replacer) {
|
|
8
|
-
return function (key, value) {
|
|
9
|
-
const val = replacer ? replacer.call(this, key, value) : value;
|
|
10
|
-
if (typeof val === 'bigint') {
|
|
11
|
-
return val.toString();
|
|
12
|
-
}
|
|
13
|
-
return val;
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
export function safeStringify(value, replacer, space) {
|
|
17
|
-
return stringify(value, jsonStringifyReplacer(replacer), space);
|
|
18
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import json from './json/main.js';
|
|
2
|
-
import milliseconds from './string/milliseconds.js';
|
|
3
|
-
export class MessageBuilder {
|
|
4
|
-
#getExpiryDate(expiresIn) {
|
|
5
|
-
if (!expiresIn) {
|
|
6
|
-
return undefined;
|
|
7
|
-
}
|
|
8
|
-
const expiryMs = milliseconds.parse(expiresIn);
|
|
9
|
-
return new Date(Date.now() + expiryMs);
|
|
10
|
-
}
|
|
11
|
-
#isExpired(message) {
|
|
12
|
-
if (!message.expiryDate) {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
const expiryDate = new Date(message.expiryDate);
|
|
16
|
-
return Number.isNaN(expiryDate.getTime()) || expiryDate < new Date();
|
|
17
|
-
}
|
|
18
|
-
build(message, expiresIn, purpose) {
|
|
19
|
-
const expiryDate = this.#getExpiryDate(expiresIn);
|
|
20
|
-
return json.safeStringify({ message, purpose, expiryDate });
|
|
21
|
-
}
|
|
22
|
-
verify(message, purpose) {
|
|
23
|
-
const parsed = json.safeParse(message);
|
|
24
|
-
if (typeof parsed !== 'object' || !parsed) {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
if (!parsed.message) {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
if (parsed.purpose !== purpose) {
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
if (this.#isExpired(parsed)) {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
return parsed.message;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function naturalSort(current: string, next: string): number;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { OmitProperties } from './types.js';
|
|
2
|
-
export declare class ObjectBuilder<ReturnType extends Record<string, any>, IgnoreNull extends boolean = false> {
|
|
3
|
-
#private;
|
|
4
|
-
values: ReturnType;
|
|
5
|
-
constructor(initialValue: ReturnType, ignoreNull?: IgnoreNull);
|
|
6
|
-
add<Prop extends string>(key: Prop, value: undefined): this;
|
|
7
|
-
add<Prop extends string, Value>(key: Prop, value: Value): ObjectBuilder<ReturnType & {
|
|
8
|
-
[P in Prop]: Value;
|
|
9
|
-
}, IgnoreNull>;
|
|
10
|
-
remove<K extends keyof ReturnType>(key: K): this;
|
|
11
|
-
has<K extends keyof ReturnType>(key: K): boolean;
|
|
12
|
-
get<K extends keyof ReturnType>(key: K): ReturnType[K];
|
|
13
|
-
toObject(): IgnoreNull extends true ? {
|
|
14
|
-
[K in keyof OmitProperties<ReturnType, null>]: ReturnType[K];
|
|
15
|
-
} : {
|
|
16
|
-
[K in keyof ReturnType]: ReturnType[K];
|
|
17
|
-
};
|
|
18
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
export class ObjectBuilder {
|
|
2
|
-
#ignoreNull;
|
|
3
|
-
values;
|
|
4
|
-
constructor(initialValue, ignoreNull) {
|
|
5
|
-
this.values = initialValue;
|
|
6
|
-
this.#ignoreNull = ignoreNull === true ? true : false;
|
|
7
|
-
}
|
|
8
|
-
add(key, value) {
|
|
9
|
-
if (value === undefined) {
|
|
10
|
-
return this;
|
|
11
|
-
}
|
|
12
|
-
if (this.#ignoreNull === true && value === null) {
|
|
13
|
-
return this;
|
|
14
|
-
}
|
|
15
|
-
;
|
|
16
|
-
this.values[key] = value;
|
|
17
|
-
return this;
|
|
18
|
-
}
|
|
19
|
-
remove(key) {
|
|
20
|
-
delete this.values[key];
|
|
21
|
-
return this;
|
|
22
|
-
}
|
|
23
|
-
has(key) {
|
|
24
|
-
return this.get(key) !== undefined;
|
|
25
|
-
}
|
|
26
|
-
get(key) {
|
|
27
|
-
return this.values[key];
|
|
28
|
-
}
|
|
29
|
-
toObject() {
|
|
30
|
-
return this.values;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
type BufferSafeValue = ArrayBuffer | SharedArrayBuffer | number[] | string | {
|
|
2
|
-
valueOf(): string | object;
|
|
3
|
-
} | {
|
|
4
|
-
[Symbol.toPrimitive](hint: 'string'): string;
|
|
5
|
-
};
|
|
6
|
-
export declare function safeEqual<T extends BufferSafeValue, U extends BufferSafeValue>(trustedValue: T, userInput: U): boolean;
|
|
7
|
-
export {};
|
package/build/src/safe_equal.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Buffer } from 'node:buffer';
|
|
2
|
-
import { timingSafeEqual } from 'node:crypto';
|
|
3
|
-
export function safeEqual(trustedValue, userInput) {
|
|
4
|
-
if (typeof trustedValue === 'string' && typeof userInput === 'string') {
|
|
5
|
-
const trustedLength = Buffer.byteLength(trustedValue);
|
|
6
|
-
const trustedValueBuffer = Buffer.alloc(trustedLength, 0, 'utf-8');
|
|
7
|
-
trustedValueBuffer.write(trustedValue);
|
|
8
|
-
const userValueBuffer = Buffer.alloc(trustedLength, 0, 'utf-8');
|
|
9
|
-
userValueBuffer.write(userInput);
|
|
10
|
-
return (timingSafeEqual(trustedValueBuffer, userValueBuffer) &&
|
|
11
|
-
trustedLength === Buffer.byteLength(userInput));
|
|
12
|
-
}
|
|
13
|
-
return timingSafeEqual(Buffer.from(trustedValue), Buffer.from(userInput));
|
|
14
|
-
}
|
package/build/src/slash.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as slash } from 'slash';
|
package/build/src/slash.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as slash } from 'slash';
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare function titleCase(input: string): string;
|
|
2
|
-
export declare function camelCase(value: string): string;
|
|
3
|
-
export declare function snakeCase(value: string): string;
|
|
4
|
-
export declare function dashCase(value: string, options?: {
|
|
5
|
-
capitalize?: boolean;
|
|
6
|
-
}): string;
|
|
7
|
-
export declare function pascalCase(value: string): string;
|
|
8
|
-
export declare function capitalCase(value: string): string;
|
|
9
|
-
export declare function sentenceCase(value: string): string;
|
|
10
|
-
export declare function dotCase(value: string, options?: {
|
|
11
|
-
lowerCase?: boolean;
|
|
12
|
-
}): string;
|
|
13
|
-
export declare function noCase(value: string, transform?: (part: string, index: number, parts: string[]) => string): string;
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import * as changeCase from 'case-anything';
|
|
2
|
-
const NO_CASE_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g];
|
|
3
|
-
const NO_CASE_STRIP_REGEXP = /[^A-Z0-9]+/gi;
|
|
4
|
-
const SMALL_WORDS = /\b(?:an?d?|a[st]|because|but|by|en|for|i[fn]|neither|nor|o[fnr]|only|over|per|so|some|tha[tn]|the|to|up|upon|vs?\.?|versus|via|when|with|without|yet)\b/i;
|
|
5
|
-
const TOKENS = /[^\s:–—-]+|./g;
|
|
6
|
-
const WHITESPACE = /\s/;
|
|
7
|
-
const IS_MANUAL_CASE = /.(?=[A-Z]|\..)/;
|
|
8
|
-
const ALPHANUMERIC_PATTERN = /[A-Za-z0-9\u00C0-\u00FF]/;
|
|
9
|
-
export function titleCase(input) {
|
|
10
|
-
let output = '';
|
|
11
|
-
let result;
|
|
12
|
-
while ((result = TOKENS.exec(input)) !== null) {
|
|
13
|
-
const { 0: token, index } = result;
|
|
14
|
-
if (!IS_MANUAL_CASE.test(token) &&
|
|
15
|
-
(!SMALL_WORDS.test(token) || index === 0 || index + token.length === input.length) &&
|
|
16
|
-
(input.charAt(index + token.length) !== ':' ||
|
|
17
|
-
WHITESPACE.test(input.charAt(index + token.length + 1)))) {
|
|
18
|
-
output += token.replace(ALPHANUMERIC_PATTERN, (char) => char.toUpperCase());
|
|
19
|
-
continue;
|
|
20
|
-
}
|
|
21
|
-
output += token;
|
|
22
|
-
}
|
|
23
|
-
return output;
|
|
24
|
-
}
|
|
25
|
-
export function camelCase(value) {
|
|
26
|
-
return changeCase.camelCase(value);
|
|
27
|
-
}
|
|
28
|
-
export function snakeCase(value) {
|
|
29
|
-
return changeCase.snakeCase(value);
|
|
30
|
-
}
|
|
31
|
-
export function dashCase(value, options) {
|
|
32
|
-
if (options && options.capitalize) {
|
|
33
|
-
return changeCase.trainCase(value);
|
|
34
|
-
}
|
|
35
|
-
return changeCase.kebabCase(value);
|
|
36
|
-
}
|
|
37
|
-
export function pascalCase(value) {
|
|
38
|
-
return changeCase.pascalCase(value);
|
|
39
|
-
}
|
|
40
|
-
export function capitalCase(value) {
|
|
41
|
-
return changeCase.capitalCase(value);
|
|
42
|
-
}
|
|
43
|
-
export function sentenceCase(value) {
|
|
44
|
-
return noCase(value, (input, index) => {
|
|
45
|
-
const result = input.toLowerCase();
|
|
46
|
-
if (index === 0) {
|
|
47
|
-
return input.charAt(0).toUpperCase() + input.substring(1);
|
|
48
|
-
}
|
|
49
|
-
return result;
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
export function dotCase(value, options) {
|
|
53
|
-
const transformedValue = changeCase.dotNotation(value);
|
|
54
|
-
if (options && options.lowerCase) {
|
|
55
|
-
return transformedValue.toLowerCase();
|
|
56
|
-
}
|
|
57
|
-
return transformedValue;
|
|
58
|
-
}
|
|
59
|
-
export function noCase(value, transform) {
|
|
60
|
-
let result = NO_CASE_SPLIT_REGEXP.reduce((input, regex) => input.replace(regex, '$1\0$2'), value);
|
|
61
|
-
result = result.replace(NO_CASE_STRIP_REGEXP, '\0');
|
|
62
|
-
let start = 0;
|
|
63
|
-
let end = result.length;
|
|
64
|
-
while (result.charAt(start) === '\0') {
|
|
65
|
-
start++;
|
|
66
|
-
}
|
|
67
|
-
while (result.charAt(end - 1) === '\0') {
|
|
68
|
-
end--;
|
|
69
|
-
}
|
|
70
|
-
return result
|
|
71
|
-
.slice(start, end)
|
|
72
|
-
.split('\0')
|
|
73
|
-
.map(transform || ((input) => input.toLowerCase()))
|
|
74
|
-
.join(' ');
|
|
75
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import truncatise from 'truncatise';
|
|
2
|
-
export function excerpt(sentence, charactersLimit, options) {
|
|
3
|
-
return truncatise(sentence, {
|
|
4
|
-
TruncateLength: charactersLimit,
|
|
5
|
-
Strict: options && options.completeWords === true ? false : true,
|
|
6
|
-
StripHTML: true,
|
|
7
|
-
TruncateBy: 'characters',
|
|
8
|
-
Suffix: options && options.suffix,
|
|
9
|
-
});
|
|
10
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function interpolate(input: string, data: any): string;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
function parseProp(data, key) {
|
|
2
|
-
const tokens = key.split('.');
|
|
3
|
-
while (tokens.length) {
|
|
4
|
-
if (data === null || typeof data !== 'object') {
|
|
5
|
-
return;
|
|
6
|
-
}
|
|
7
|
-
const token = tokens.shift();
|
|
8
|
-
data = Object.hasOwn(data, token) ? data[token] : undefined;
|
|
9
|
-
}
|
|
10
|
-
return data;
|
|
11
|
-
}
|
|
12
|
-
export function interpolate(input, data) {
|
|
13
|
-
return input.replace(/(\\)?{{(.*?)}}/g, (_, escapeChar, key) => {
|
|
14
|
-
if (escapeChar) {
|
|
15
|
-
return `{{${key}}}`;
|
|
16
|
-
}
|
|
17
|
-
return parseProp(data, key.trim());
|
|
18
|
-
});
|
|
19
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { parse, format } from '@lukeed/ms';
|
|
2
|
-
export default {
|
|
3
|
-
format(milliseconds, long) {
|
|
4
|
-
return format(milliseconds, long);
|
|
5
|
-
},
|
|
6
|
-
parse(duration) {
|
|
7
|
-
if (typeof duration === 'number') {
|
|
8
|
-
return duration;
|
|
9
|
-
}
|
|
10
|
-
const milliseconds = parse(duration);
|
|
11
|
-
if (milliseconds === undefined) {
|
|
12
|
-
throw new Error(`Invalid duration expression "${duration}"`);
|
|
13
|
-
}
|
|
14
|
-
return milliseconds;
|
|
15
|
-
},
|
|
16
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function ordinal(value: string | number): string;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export function ordinal(value) {
|
|
2
|
-
const transformedValue = Math.abs(typeof value === 'string' ? Number.parseInt(value) : value);
|
|
3
|
-
if (!Number.isFinite(transformedValue) || Number.isNaN(transformedValue)) {
|
|
4
|
-
throw new Error('Cannot ordinalize invalid or infinite numbers');
|
|
5
|
-
}
|
|
6
|
-
const percent = transformedValue % 100;
|
|
7
|
-
if (percent >= 10 && percent <= 20) {
|
|
8
|
-
return `${value}th`;
|
|
9
|
-
}
|
|
10
|
-
const decimal = transformedValue % 10;
|
|
11
|
-
switch (decimal) {
|
|
12
|
-
case 1:
|
|
13
|
-
return `${value}st`;
|
|
14
|
-
case 2:
|
|
15
|
-
return `${value}nd`;
|
|
16
|
-
case 3:
|
|
17
|
-
return `${value}rd`;
|
|
18
|
-
default:
|
|
19
|
-
return `${value}th`;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { default as pluralizePkg } from 'pluralize';
|
|
2
|
-
export declare function pluralize(word: string, count?: number, inclusive?: boolean): string;
|
|
3
|
-
export declare namespace pluralize {
|
|
4
|
-
var addPluralRule: typeof pluralizePkg.addPluralRule;
|
|
5
|
-
var addSingularRule: typeof pluralizePkg.addSingularRule;
|
|
6
|
-
var addIrregularRule: typeof pluralizePkg.addIrregularRule;
|
|
7
|
-
var addUncountableRule: typeof pluralizePkg.addUncountableRule;
|
|
8
|
-
}
|
|
9
|
-
export declare const plural: typeof pluralizePkg.plural;
|
|
10
|
-
export declare const singular: typeof pluralizePkg.singular;
|
|
11
|
-
export declare const isPlural: typeof pluralizePkg.isPlural;
|
|
12
|
-
export declare const isSingular: typeof pluralizePkg.isSingular;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { default as pluralizePkg } from 'pluralize';
|
|
2
|
-
export function pluralize(word, count, inclusive) {
|
|
3
|
-
return pluralizePkg(word, count, inclusive);
|
|
4
|
-
}
|
|
5
|
-
pluralize.addPluralRule = pluralizePkg.addPluralRule;
|
|
6
|
-
pluralize.addSingularRule = pluralizePkg.addSingularRule;
|
|
7
|
-
pluralize.addIrregularRule = pluralizePkg.addIrregularRule;
|
|
8
|
-
pluralize.addUncountableRule = pluralizePkg.addUncountableRule;
|
|
9
|
-
export const plural = pluralizePkg.plural;
|
|
10
|
-
export const singular = pluralizePkg.singular;
|
|
11
|
-
export const isPlural = pluralizePkg.isPlural;
|
|
12
|
-
export const isSingular = pluralizePkg.isSingular;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function random(size: number): string;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { parse, format } from '@lukeed/ms';
|
|
2
|
-
export default {
|
|
3
|
-
format(seconds, long) {
|
|
4
|
-
return format(seconds * 1000, long);
|
|
5
|
-
},
|
|
6
|
-
parse(duration) {
|
|
7
|
-
if (typeof duration === 'number') {
|
|
8
|
-
return duration;
|
|
9
|
-
}
|
|
10
|
-
const milliseconds = parse(duration);
|
|
11
|
-
if (milliseconds === undefined) {
|
|
12
|
-
throw new Error(`Invalid duration expression "${duration}"`);
|
|
13
|
-
}
|
|
14
|
-
return Math.floor(milliseconds / 1000);
|
|
15
|
-
},
|
|
16
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export function sentence(values, options) {
|
|
2
|
-
if (values.length === 0) {
|
|
3
|
-
return '';
|
|
4
|
-
}
|
|
5
|
-
if (values.length === 1) {
|
|
6
|
-
return values[0];
|
|
7
|
-
}
|
|
8
|
-
if (values.length === 2) {
|
|
9
|
-
return `${values[0]}${options?.pairSeparator || ' and '}${values[1]}`;
|
|
10
|
-
}
|
|
11
|
-
const normalized = Object.assign({ separator: ', ', lastSeparator: ', and ' }, options);
|
|
12
|
-
return `${values.slice(0, -1).join(normalized.separator)}${normalized.lastSeparator}${values[values.length - 1]}`;
|
|
13
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import truncatise from 'truncatise';
|
|
2
|
-
export function truncate(sentence, charactersLimit, options) {
|
|
3
|
-
return truncatise(sentence, {
|
|
4
|
-
TruncateLength: charactersLimit,
|
|
5
|
-
Strict: options && options.completeWords === true ? false : true,
|
|
6
|
-
StripHTML: false,
|
|
7
|
-
TruncateBy: 'characters',
|
|
8
|
-
Suffix: options && options.suffix,
|
|
9
|
-
});
|
|
10
|
-
}
|