@poppinss/utils 4.0.4 → 6.0.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.
Files changed (110) hide show
  1. package/README.md +661 -873
  2. package/build/index.d.ts +16 -10
  3. package/build/index.js +21 -53
  4. package/build/lodash/main.cjs +37 -0
  5. package/build/src/{Helpers/base64.d.ts → base64.d.ts} +7 -23
  6. package/build/src/{Helpers/base64.js → base64.js} +9 -22
  7. package/build/src/compose.d.ts +17 -0
  8. package/build/src/compose.js +3 -0
  9. package/build/src/{defineStaticProperty.d.ts → define_static_property.d.ts} +2 -6
  10. package/build/src/define_static_property.js +21 -0
  11. package/build/src/exception.d.ts +16 -0
  12. package/build/src/exception.js +29 -0
  13. package/build/src/flatten.d.ts +1 -1
  14. package/build/src/flatten.js +4 -13
  15. package/build/src/fs_import_all.d.ts +3 -0
  16. package/build/src/fs_import_all.js +28 -0
  17. package/build/src/fs_read_all.d.ts +3 -0
  18. package/build/src/fs_read_all.js +55 -0
  19. package/build/src/is_script_file.d.ts +1 -0
  20. package/build/src/is_script_file.js +12 -0
  21. package/build/src/json/main.d.ts +7 -0
  22. package/build/src/json/main.js +6 -0
  23. package/build/src/json/safe_parse.d.ts +2 -0
  24. package/build/src/json/safe_parse.js +7 -0
  25. package/build/src/json/safe_stringify.d.ts +2 -0
  26. package/build/src/json/safe_stringify.js +18 -0
  27. package/build/src/message_builder.d.ts +5 -0
  28. package/build/src/message_builder.js +43 -0
  29. package/build/src/natural_sort.d.ts +1 -0
  30. package/build/src/natural_sort.js +3 -0
  31. package/build/src/object_builder.d.ts +10 -0
  32. package/build/src/object_builder.js +31 -0
  33. package/build/src/{Helpers/safeEqual.d.ts → safe_equal.d.ts} +1 -4
  34. package/build/src/safe_equal.js +14 -0
  35. package/build/src/slash.d.ts +1 -5
  36. package/build/src/slash.js +1 -24
  37. package/build/src/string/bytes.d.ts +6 -0
  38. package/build/src/string/bytes.js +12 -0
  39. package/build/src/string/change_case.d.ts +13 -0
  40. package/build/src/string/change_case.js +75 -0
  41. package/build/src/string/excerpt.d.ts +4 -0
  42. package/build/src/string/excerpt.js +10 -0
  43. package/build/src/string/interpolate.d.ts +1 -0
  44. package/build/src/{Helpers → string}/interpolate.js +1 -22
  45. package/build/src/string/main.d.ts +46 -0
  46. package/build/src/string/main.js +42 -0
  47. package/build/src/string/milliseconds.d.ts +5 -0
  48. package/build/src/string/milliseconds.js +16 -0
  49. package/build/src/string/ordinal.d.ts +1 -0
  50. package/build/src/string/ordinal.js +21 -0
  51. package/build/src/string/pluralize.d.ts +12 -0
  52. package/build/src/string/pluralize.js +12 -0
  53. package/build/src/string/random.d.ts +1 -0
  54. package/build/src/string/random.js +7 -0
  55. package/build/src/string/seconds.d.ts +5 -0
  56. package/build/src/string/seconds.js +16 -0
  57. package/build/src/string/slugify.d.ts +2 -0
  58. package/build/src/string/slugify.js +2 -0
  59. package/build/src/string/to_sentence.d.ts +5 -0
  60. package/build/src/string/to_sentence.js +13 -0
  61. package/build/src/string/truncate.d.ts +4 -0
  62. package/build/src/string/truncate.js +10 -0
  63. package/build/src/types.d.ts +14 -0
  64. package/build/src/types.js +1 -0
  65. package/lodash/lodash.types.d.ts +44 -0
  66. package/package.json +70 -82
  67. package/build/helpers.d.ts +0 -1
  68. package/build/helpers.js +0 -25
  69. package/build/src/Exception.d.ts +0 -17
  70. package/build/src/Exception.js +0 -68
  71. package/build/src/Helpers/MessageBuilder.d.ts +0 -28
  72. package/build/src/Helpers/MessageBuilder.js +0 -97
  73. package/build/src/Helpers/ObjectBuilder.d.ts +0 -46
  74. package/build/src/Helpers/ObjectBuilder.js +0 -75
  75. package/build/src/Helpers/compose.d.ts +0 -21
  76. package/build/src/Helpers/compose.js +0 -20
  77. package/build/src/Helpers/fsReadAll.d.ts +0 -4
  78. package/build/src/Helpers/fsReadAll.js +0 -23
  79. package/build/src/Helpers/index.d.ts +0 -14
  80. package/build/src/Helpers/index.js +0 -62
  81. package/build/src/Helpers/interpolate.d.ts +0 -7
  82. package/build/src/Helpers/requireAll.d.ts +0 -8
  83. package/build/src/Helpers/requireAll.js +0 -65
  84. package/build/src/Helpers/resolveDir.d.ts +0 -5
  85. package/build/src/Helpers/resolveDir.js +0 -46
  86. package/build/src/Helpers/resolveFrom.d.ts +0 -5
  87. package/build/src/Helpers/resolveFrom.js +0 -27
  88. package/build/src/Helpers/safeEqual.js +0 -42
  89. package/build/src/Helpers/string.d.ts +0 -124
  90. package/build/src/Helpers/string.js +0 -328
  91. package/build/src/Helpers/types.d.ts +0 -86
  92. package/build/src/Helpers/types.js +0 -161
  93. package/build/src/ManagerConfigValidator.d.ts +0 -20
  94. package/build/src/ManagerConfigValidator.js +0 -55
  95. package/build/src/defineStaticProperty.js +0 -57
  96. package/build/src/esmRequire.d.ts +0 -5
  97. package/build/src/esmRequire.js +0 -20
  98. package/build/src/esmResolver.d.ts +0 -1
  99. package/build/src/esmResolver.js +0 -15
  100. package/build/src/fast-safe-stringify.d.ts +0 -2
  101. package/build/src/fast-safe-stringify.js +0 -101
  102. package/build/src/isScriptFile.d.ts +0 -5
  103. package/build/src/isScriptFile.js +0 -28
  104. package/build/src/lodash.d.ts +0 -13
  105. package/build/src/lodash.js +0 -39
  106. package/build/src/safeParse.d.ts +0 -5
  107. package/build/src/safeParse.js +0 -42
  108. package/build/src/safeStringify.d.ts +0 -5
  109. package/build/src/safeStringify.js +0 -39
  110. package/types/lodash.types.d.ts +0 -65
@@ -0,0 +1,10 @@
1
+ export declare class ObjectBuilder {
2
+ #private;
3
+ value: Record<any, any>;
4
+ constructor(initialValue?: Record<any, any>, ignoreNull?: boolean);
5
+ add(key: string, value: any): this;
6
+ remove(key: string): this;
7
+ has(key: string): boolean;
8
+ get<T extends any>(key: string): T;
9
+ toObject(): Record<any, any>;
10
+ }
@@ -0,0 +1,31 @@
1
+ export class ObjectBuilder {
2
+ #ignoreNull;
3
+ value = {};
4
+ constructor(initialValue, ignoreNull) {
5
+ this.value = initialValue !== undefined ? 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
+ this.value[key] = value;
16
+ return this;
17
+ }
18
+ remove(key) {
19
+ delete this.value[key];
20
+ return this;
21
+ }
22
+ has(key) {
23
+ return this.get(key) !== undefined;
24
+ }
25
+ get(key) {
26
+ return this.value[key];
27
+ }
28
+ toObject() {
29
+ return this.value;
30
+ }
31
+ }
@@ -3,8 +3,5 @@ declare type BufferSafeValue = ArrayBuffer | SharedArrayBuffer | number[] | stri
3
3
  } | {
4
4
  [Symbol.toPrimitive](hint: 'string'): string;
5
5
  };
6
- /**
7
- * Generates a random string for a given size
8
- */
9
- export declare function safeEqual<T extends BufferSafeValue>(value: T, comparisonValue: T): boolean;
6
+ export declare function safeEqual<T extends BufferSafeValue, U extends BufferSafeValue>(trustedValue: T, userInput: U): boolean;
10
7
  export {};
@@ -0,0 +1,14 @@
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
+ }
@@ -1,5 +1 @@
1
- /**
2
- * Convert windows path to unix.
3
- * Copied from https://github.com/sindresorhus/slash as the package is ESM only
4
- */
5
- export declare function slash(filePath: string): string;
1
+ export { default as slash } from 'slash';
@@ -1,24 +1 @@
1
- "use strict";
2
- /*
3
- * @poppinss/utils
4
- *
5
- * (c) Harminder Virk <virk@adonisjs.com>
6
- *
7
- * For the full copyright and license information, please view the LICENSE
8
- * file that was distributed with this source code.
9
- */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.slash = void 0;
12
- /**
13
- * Convert windows path to unix.
14
- * Copied from https://github.com/sindresorhus/slash as the package is ESM only
15
- */
16
- function slash(filePath) {
17
- const isExtendedLengthPath = /^\\\\\?\\/.test(filePath);
18
- const hasNonAscii = /[^\u0000-\u0080]+/.test(filePath); // eslint-disable-line no-control-regex
19
- if (isExtendedLengthPath || hasNonAscii) {
20
- return filePath;
21
- }
22
- return filePath.replace(/\\/g, '/');
23
- }
24
- exports.slash = slash;
1
+ export { default as slash } from 'slash';
@@ -0,0 +1,6 @@
1
+ import { BytesOptions } from 'bytes';
2
+ declare const _default: {
3
+ format(valueInBytes: number, options?: BytesOptions): string;
4
+ parse(unit: string | number): number;
5
+ };
6
+ export default _default;
@@ -0,0 +1,12 @@
1
+ import bytes from 'bytes';
2
+ export default {
3
+ format(valueInBytes, options) {
4
+ return bytes.format(valueInBytes, options);
5
+ },
6
+ parse(unit) {
7
+ if (typeof unit === 'number') {
8
+ return unit;
9
+ }
10
+ return bytes.parse(unit);
11
+ },
12
+ };
@@ -0,0 +1,13 @@
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;
@@ -0,0 +1,75 @@
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
+ }
@@ -0,0 +1,4 @@
1
+ export declare function excerpt(sentence: string, charactersLimit: number, options?: {
2
+ completeWords?: boolean;
3
+ suffix?: string;
4
+ }): string;
@@ -0,0 +1,10 @@
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
+ }
@@ -0,0 +1 @@
1
+ export declare function interpolate(input: string, data: any): string;
@@ -1,23 +1,9 @@
1
- "use strict";
2
- /*
3
- * @poppinss/utils
4
- *
5
- * (c) Harminder Virk <virk@adonisjs.com>
6
- *
7
- * For the full copyright and license information, please view the LICENSE
8
- * file that was distributed with this source code.
9
- */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.interpolate = void 0;
12
1
  function uncurryThis(fn) {
13
2
  return function (...args) {
14
3
  return Function.call.apply(fn, args);
15
4
  };
16
5
  }
17
6
  const hasOwnProperty = uncurryThis(Object.prototype.hasOwnProperty);
18
- /**
19
- * Parses prop
20
- */
21
7
  function parseProp(data, key) {
22
8
  const tokens = key.split('.');
23
9
  while (tokens.length) {
@@ -29,13 +15,7 @@ function parseProp(data, key) {
29
15
  }
30
16
  return data;
31
17
  }
32
- /**
33
- * A simple function interpolate values inside curly braces.
34
- *
35
- * @example
36
- * `interpolate('hello {{ username }}', { username: 'virk' })`
37
- */
38
- function interpolate(input, data) {
18
+ export function interpolate(input, data) {
39
19
  return input.replace(/(\\)?{{(.*?)}}/g, (_, escapeChar, key) => {
40
20
  if (escapeChar) {
41
21
  return `{{${key}}}`;
@@ -43,4 +23,3 @@ function interpolate(input, data) {
43
23
  return parseProp(data, key.trim());
44
24
  });
45
25
  }
46
- exports.interpolate = interpolate;
@@ -0,0 +1,46 @@
1
+ import { random } from './random.js';
2
+ import { excerpt } from './excerpt.js';
3
+ import { ordinal } from './ordinal.js';
4
+ import { truncate } from './truncate.js';
5
+ import { toSentence } from './to_sentence.js';
6
+ import { interpolate } from './interpolate.js';
7
+ import { pluralize } from './pluralize.js';
8
+ import { noCase, dotCase, dashCase, camelCase, snakeCase, titleCase, pascalCase, capitalCase, sentenceCase } from './change_case.js';
9
+ declare function condenseWhitespace(value: string): string;
10
+ declare const _default: {
11
+ excerpt: typeof excerpt;
12
+ truncate: typeof truncate;
13
+ slug: typeof import("slugify").default;
14
+ interpolate: typeof interpolate;
15
+ plural: typeof import("pluralize").plural;
16
+ pluralize: typeof pluralize;
17
+ singular: typeof import("pluralize").singular;
18
+ isPlural: typeof import("pluralize").isPlural;
19
+ isSingular: typeof import("pluralize").isSingular;
20
+ camelCase: typeof camelCase;
21
+ capitalCase: typeof capitalCase;
22
+ dashCase: typeof dashCase;
23
+ dotCase: typeof dotCase;
24
+ noCase: typeof noCase;
25
+ pascalCase: typeof pascalCase;
26
+ sentenceCase: typeof sentenceCase;
27
+ snakeCase: typeof snakeCase;
28
+ titleCase: typeof titleCase;
29
+ random: typeof random;
30
+ toSentence: typeof toSentence;
31
+ condenseWhitespace: typeof condenseWhitespace;
32
+ seconds: {
33
+ format(seconds: number, long?: boolean | undefined): string;
34
+ parse(duration: string | number): number;
35
+ };
36
+ milliseconds: {
37
+ format(milliseconds: number, long?: boolean | undefined): string;
38
+ parse(duration: string | number): number;
39
+ };
40
+ bytes: {
41
+ format(valueInBytes: number, options?: import("bytes").BytesOptions | undefined): string;
42
+ parse(unit: string | number): number;
43
+ };
44
+ ordinal: typeof ordinal;
45
+ };
46
+ export default _default;
@@ -0,0 +1,42 @@
1
+ import bytes from './bytes.js';
2
+ import seconds from './seconds.js';
3
+ import { slug } from './slugify.js';
4
+ import { random } from './random.js';
5
+ import { excerpt } from './excerpt.js';
6
+ import { ordinal } from './ordinal.js';
7
+ import { truncate } from './truncate.js';
8
+ import milliseconds from './milliseconds.js';
9
+ import { toSentence } from './to_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
+ export default {
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
+ toSentence,
37
+ condenseWhitespace,
38
+ seconds,
39
+ milliseconds,
40
+ bytes,
41
+ ordinal,
42
+ };
@@ -0,0 +1,5 @@
1
+ declare const _default: {
2
+ format(milliseconds: number, long?: boolean): string;
3
+ parse(duration: string | number): number;
4
+ };
5
+ export default _default;
@@ -0,0 +1,16 @@
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) {
12
+ throw new Error(`Invalid duration expression "${duration}"`);
13
+ }
14
+ return milliseconds;
15
+ },
16
+ };
@@ -0,0 +1 @@
1
+ export declare function ordinal(value: string | number): string;
@@ -0,0 +1,21 @@
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
+ }
@@ -0,0 +1,12 @@
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;
@@ -0,0 +1,12 @@
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;
@@ -0,0 +1 @@
1
+ export declare function random(size: number): string;
@@ -0,0 +1,7 @@
1
+ import { randomBytes } from 'node:crypto';
2
+ import { base64 } from '../base64.js';
3
+ export function random(size) {
4
+ const bits = (size + 1) * 6;
5
+ const buffer = randomBytes(Math.ceil(bits / 8));
6
+ return base64.urlEncode(buffer).slice(0, size);
7
+ }
@@ -0,0 +1,5 @@
1
+ declare const _default: {
2
+ format(seconds: number, long?: boolean): string;
3
+ parse(duration: string | number): number;
4
+ };
5
+ export default _default;
@@ -0,0 +1,16 @@
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) {
12
+ throw new Error(`Invalid duration expression "${duration}"`);
13
+ }
14
+ return Math.floor(milliseconds / 1000);
15
+ },
16
+ };
@@ -0,0 +1,2 @@
1
+ import { default as slugifyPkg } from 'slugify';
2
+ export declare const slug: typeof slugifyPkg.default;
@@ -0,0 +1,2 @@
1
+ import { default as slugifyPkg } from 'slugify';
2
+ export const slug = slugifyPkg;
@@ -0,0 +1,5 @@
1
+ export declare function toSentence(values: any[], options?: {
2
+ separator?: string;
3
+ pairSeparator?: string;
4
+ lastSeparator?: string;
5
+ }): string;
@@ -0,0 +1,13 @@
1
+ export function toSentence(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
+ }
@@ -0,0 +1,4 @@
1
+ export declare function truncate(sentence: string, charactersLimit: number, options?: {
2
+ completeWords?: boolean;
3
+ suffix?: string;
4
+ }): string;
@@ -0,0 +1,10 @@
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
+ }
@@ -0,0 +1,14 @@
1
+ declare type ScanFsBaseOptions = {
2
+ ignoreMissingRoot?: boolean;
3
+ filter?: (filePath: string, index: number) => boolean;
4
+ sort?: (current: string, next: string) => number;
5
+ };
6
+ export declare type ImportAllFilesOptions = ScanFsBaseOptions & {
7
+ transformKeys?: (keys: string[]) => string[];
8
+ };
9
+ export declare type ReadAllFilesOptions = ScanFsBaseOptions & {
10
+ pathType?: 'relative' | 'unixRelative' | 'absolute' | 'unixAbsolute' | 'url';
11
+ };
12
+ export declare type JSONReplacer = (this: any, key: string, value: any) => any;
13
+ export declare type JSONReviver = (this: any, key: string, value: any) => any;
14
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,44 @@
1
+ /*
2
+ * @poppinss/utils
3
+ *
4
+ * (c) Poppinss
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+
10
+ type PropertyName = string | number | symbol
11
+ type PropertyNames = PropertyName | ReadonlyArray<PropertyName>
12
+
13
+ /**
14
+ * Instead of using lodash as a dependency (which is around 4MB), we create a
15
+ * customized build of lodash with only the following methods.
16
+ *
17
+ * I know that 4MB is not a huge deal on the server, but I am okay shoving that
18
+ * off, if the work to maintain custom build is not too much.
19
+ *
20
+ * How about Lodash per methods packages?
21
+ * They are out of date from the main lodash. That is the main problem
22
+ */
23
+ declare module '@poppinss/utils/lodash' {
24
+ type LodashMethods = {
25
+ pick: <T>(object: T | null | undefined, ...props: Array<PropertyNames>) => Partial<T>
26
+ omit: <T extends object>(
27
+ object: T | null | undefined,
28
+ ...paths: Array<PropertyNames>
29
+ ) => Partial<T>
30
+ has: <T>(object: T, path: PropertyNames) => boolean
31
+ get: (object: any, path: PropertyNames, defaultValue?: any) => any
32
+ set: (object: any, path: PropertyNames, value: any) => any
33
+ unset: (object: any, path: PropertyNames) => boolean
34
+ mergeWith: (object: any, ...otherArgs: any[]) => any
35
+ merge: (object: any, ...otherArgs: any[]) => any
36
+ size: (collection: object | string | null | undefined) => number
37
+ clone: <T>(value: T) => T
38
+ cloneDeep: <T>(value: T) => T
39
+ toPath: (value: any) => string[]
40
+ }
41
+
42
+ const lodash: LodashMethods
43
+ export default lodash
44
+ }