@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.
Files changed (75) hide show
  1. package/README.md +2 -0
  2. package/build/chunk-OKRMWJO4.js +269 -0
  3. package/build/chunk-PWRXO3NF.js +63 -0
  4. package/build/chunk-XHQBV7AF.js +39 -0
  5. package/build/index.d.ts +284 -19
  6. package/build/index.js +372 -23
  7. package/build/src/json/main.d.ts +15 -3
  8. package/build/src/json/main.js +5 -6
  9. package/build/src/string/main.d.ts +121 -15
  10. package/build/src/string/main.js +6 -42
  11. package/build/src/string_builder.d.ts +60 -1
  12. package/build/src/string_builder.js +148 -86
  13. package/build/src/types.d.ts +18 -8
  14. package/build/src/types.js +0 -1
  15. package/package.json +24 -12
  16. package/build/src/base64.d.ts +0 -17
  17. package/build/src/base64.js +0 -35
  18. package/build/src/compose.d.ts +0 -14
  19. package/build/src/compose.js +0 -3
  20. package/build/src/define_static_property.d.ts +0 -7
  21. package/build/src/define_static_property.js +0 -21
  22. package/build/src/exception.d.ts +0 -21
  23. package/build/src/exception.js +0 -40
  24. package/build/src/exceptions/invalid_arguments_exception.d.ts +0 -5
  25. package/build/src/exceptions/invalid_arguments_exception.js +0 -5
  26. package/build/src/exceptions/runtime_exception.d.ts +0 -5
  27. package/build/src/exceptions/runtime_exception.js +0 -5
  28. package/build/src/flatten.d.ts +0 -1
  29. package/build/src/flatten.js +0 -4
  30. package/build/src/fs_import_all.d.ts +0 -3
  31. package/build/src/fs_import_all.js +0 -28
  32. package/build/src/fs_read_all.d.ts +0 -3
  33. package/build/src/fs_read_all.js +0 -55
  34. package/build/src/import_default.d.ts +0 -3
  35. package/build/src/import_default.js +0 -15
  36. package/build/src/is_script_file.d.ts +0 -1
  37. package/build/src/is_script_file.js +0 -12
  38. package/build/src/json/safe_parse.d.ts +0 -2
  39. package/build/src/json/safe_parse.js +0 -7
  40. package/build/src/json/safe_stringify.d.ts +0 -2
  41. package/build/src/json/safe_stringify.js +0 -18
  42. package/build/src/message_builder.d.ts +0 -5
  43. package/build/src/message_builder.js +0 -38
  44. package/build/src/natural_sort.d.ts +0 -1
  45. package/build/src/natural_sort.js +0 -3
  46. package/build/src/object_builder.d.ts +0 -18
  47. package/build/src/object_builder.js +0 -32
  48. package/build/src/safe_equal.d.ts +0 -7
  49. package/build/src/safe_equal.js +0 -14
  50. package/build/src/slash.d.ts +0 -1
  51. package/build/src/slash.js +0 -1
  52. package/build/src/string/bytes.d.ts +0 -6
  53. package/build/src/string/bytes.js +0 -12
  54. package/build/src/string/change_case.d.ts +0 -13
  55. package/build/src/string/change_case.js +0 -75
  56. package/build/src/string/excerpt.d.ts +0 -4
  57. package/build/src/string/excerpt.js +0 -10
  58. package/build/src/string/interpolate.d.ts +0 -1
  59. package/build/src/string/interpolate.js +0 -19
  60. package/build/src/string/milliseconds.d.ts +0 -5
  61. package/build/src/string/milliseconds.js +0 -16
  62. package/build/src/string/ordinal.d.ts +0 -1
  63. package/build/src/string/ordinal.js +0 -21
  64. package/build/src/string/pluralize.d.ts +0 -12
  65. package/build/src/string/pluralize.js +0 -12
  66. package/build/src/string/random.d.ts +0 -1
  67. package/build/src/string/random.js +0 -7
  68. package/build/src/string/seconds.d.ts +0 -5
  69. package/build/src/string/seconds.js +0 -16
  70. package/build/src/string/sentence.d.ts +0 -5
  71. package/build/src/string/sentence.js +0 -13
  72. package/build/src/string/slugify.d.ts +0 -2
  73. package/build/src/string/slugify.js +0 -2
  74. package/build/src/string/truncate.d.ts +0 -4
  75. package/build/src/string/truncate.js +0 -10
package/README.md CHANGED
@@ -557,6 +557,7 @@ string.bytes.format(1024 * 1024 * 1000, { thousandsSeparator: ',' }) // 1,000MB
557
557
  ```
558
558
 
559
559
  ### String builder
560
+
560
561
  The string builder offers a fluent API for applying a set of transforms on a string value. You can create an instance of the string builder as follows.
561
562
 
562
563
  ```ts
@@ -938,6 +939,7 @@ await Promise.all(
938
939
  ```
939
940
 
940
941
  #### importDefault
942
+
941
943
  A helper function that assert a lazy import function output to have a `default export`, otherwise raises an exception.
942
944
 
943
945
  We use dynamic default exports a lot in AdonisJS apps, so extracting the check to a helper function.
@@ -0,0 +1,269 @@
1
+ import {
2
+ base64,
3
+ milliseconds_default
4
+ } from "./chunk-PWRXO3NF.js";
5
+
6
+ // src/string/bytes.ts
7
+ import bytes from "bytes";
8
+ var bytes_default = {
9
+ format(valueInBytes, options) {
10
+ return bytes.format(valueInBytes, options);
11
+ },
12
+ /**
13
+ * Parse the unit expression to bytes. If the unit value
14
+ * is a number, then it will be returned as it is considering
15
+ * it is already in bytes.
16
+ */
17
+ parse(unit) {
18
+ if (typeof unit === "number") {
19
+ return unit;
20
+ }
21
+ return bytes.parse(unit);
22
+ }
23
+ };
24
+
25
+ // src/string/seconds.ts
26
+ import { parse, format } from "@lukeed/ms";
27
+ var seconds_default = {
28
+ format(seconds, long) {
29
+ return format(seconds * 1e3, long);
30
+ },
31
+ /**
32
+ * Parse time expression string to seconds. The number value
33
+ * is returned as it is, considering it is already in seconds
34
+ */
35
+ parse(duration) {
36
+ if (typeof duration === "number") {
37
+ return duration;
38
+ }
39
+ const milliseconds = parse(duration);
40
+ if (milliseconds === void 0) {
41
+ throw new Error(`Invalid duration expression "${duration}"`);
42
+ }
43
+ return Math.floor(milliseconds / 1e3);
44
+ }
45
+ };
46
+
47
+ // src/string/slugify.ts
48
+ import { default as slugifyPkg } from "slugify";
49
+ var slug = slugifyPkg;
50
+
51
+ // src/string/random.ts
52
+ import { randomBytes } from "node:crypto";
53
+ function random(size) {
54
+ const bits = (size + 1) * 6;
55
+ const buffer = randomBytes(Math.ceil(bits / 8));
56
+ return base64.urlEncode(buffer).slice(0, size);
57
+ }
58
+
59
+ // src/string/excerpt.ts
60
+ import truncatise from "truncatise";
61
+ function excerpt(sentence2, charactersLimit, options) {
62
+ return truncatise(sentence2, {
63
+ TruncateLength: charactersLimit,
64
+ /**
65
+ * Do not complete words when "completeWords" is not explicitly set
66
+ * to true
67
+ */
68
+ Strict: options && options.completeWords === true ? false : true,
69
+ StripHTML: true,
70
+ TruncateBy: "characters",
71
+ Suffix: options && options.suffix
72
+ });
73
+ }
74
+
75
+ // src/string/ordinal.ts
76
+ function ordinal(value) {
77
+ const transformedValue = Math.abs(typeof value === "string" ? Number.parseInt(value) : value);
78
+ if (!Number.isFinite(transformedValue) || Number.isNaN(transformedValue)) {
79
+ throw new Error("Cannot ordinalize invalid or infinite numbers");
80
+ }
81
+ const percent = transformedValue % 100;
82
+ if (percent >= 10 && percent <= 20) {
83
+ return `${value}th`;
84
+ }
85
+ const decimal = transformedValue % 10;
86
+ switch (decimal) {
87
+ case 1:
88
+ return `${value}st`;
89
+ case 2:
90
+ return `${value}nd`;
91
+ case 3:
92
+ return `${value}rd`;
93
+ default:
94
+ return `${value}th`;
95
+ }
96
+ }
97
+
98
+ // src/string/truncate.ts
99
+ import truncatise2 from "truncatise";
100
+ function truncate(sentence2, charactersLimit, options) {
101
+ return truncatise2(sentence2, {
102
+ TruncateLength: charactersLimit,
103
+ /**
104
+ * Do not complete words when "completeWords" is not explicitly set
105
+ * to true
106
+ */
107
+ Strict: options && options.completeWords === true ? false : true,
108
+ StripHTML: false,
109
+ TruncateBy: "characters",
110
+ Suffix: options && options.suffix
111
+ });
112
+ }
113
+
114
+ // src/string/sentence.ts
115
+ function sentence(values, options) {
116
+ if (values.length === 0) {
117
+ return "";
118
+ }
119
+ if (values.length === 1) {
120
+ return values[0];
121
+ }
122
+ if (values.length === 2) {
123
+ return `${values[0]}${options?.pairSeparator || " and "}${values[1]}`;
124
+ }
125
+ const normalized = Object.assign({ separator: ", ", lastSeparator: ", and " }, options);
126
+ return `${values.slice(0, -1).join(normalized.separator)}${normalized.lastSeparator}${values[values.length - 1]}`;
127
+ }
128
+
129
+ // src/string/interpolate.ts
130
+ function parseProp(data, key) {
131
+ const tokens = key.split(".");
132
+ while (tokens.length) {
133
+ if (data === null || typeof data !== "object") {
134
+ return;
135
+ }
136
+ const token = tokens.shift();
137
+ data = Object.hasOwn(data, token) ? data[token] : void 0;
138
+ }
139
+ return data;
140
+ }
141
+ function interpolate(input, data) {
142
+ return input.replace(/(\\)?{{(.*?)}}/g, (_, escapeChar, key) => {
143
+ if (escapeChar) {
144
+ return `{{${key}}}`;
145
+ }
146
+ return parseProp(data, key.trim());
147
+ });
148
+ }
149
+
150
+ // src/string/pluralize.ts
151
+ import { default as pluralizePkg } from "pluralize";
152
+ function pluralize(word, count, inclusive) {
153
+ return pluralizePkg(word, count, inclusive);
154
+ }
155
+ pluralize.addPluralRule = pluralizePkg.addPluralRule;
156
+ pluralize.addSingularRule = pluralizePkg.addSingularRule;
157
+ pluralize.addIrregularRule = pluralizePkg.addIrregularRule;
158
+ pluralize.addUncountableRule = pluralizePkg.addUncountableRule;
159
+ var plural = pluralizePkg.plural;
160
+ var singular = pluralizePkg.singular;
161
+ var isPlural = pluralizePkg.isPlural;
162
+ var isSingular = pluralizePkg.isSingular;
163
+
164
+ // src/string/change_case.ts
165
+ import * as changeCase from "case-anything";
166
+ var NO_CASE_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g];
167
+ var NO_CASE_STRIP_REGEXP = /[^A-Z0-9]+/gi;
168
+ var 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;
169
+ var TOKENS = /[^\s:–—-]+|./g;
170
+ var WHITESPACE = /\s/;
171
+ var IS_MANUAL_CASE = /.(?=[A-Z]|\..)/;
172
+ var ALPHANUMERIC_PATTERN = /[A-Za-z0-9\u00C0-\u00FF]/;
173
+ function titleCase(input) {
174
+ let output = "";
175
+ let result;
176
+ while ((result = TOKENS.exec(input)) !== null) {
177
+ const { 0: token, index } = result;
178
+ if (!IS_MANUAL_CASE.test(token) && (!SMALL_WORDS.test(token) || index === 0 || index + token.length === input.length) && (input.charAt(index + token.length) !== ":" || WHITESPACE.test(input.charAt(index + token.length + 1)))) {
179
+ output += token.replace(ALPHANUMERIC_PATTERN, (char) => char.toUpperCase());
180
+ continue;
181
+ }
182
+ output += token;
183
+ }
184
+ return output;
185
+ }
186
+ function camelCase2(value) {
187
+ return changeCase.camelCase(value);
188
+ }
189
+ function snakeCase2(value) {
190
+ return changeCase.snakeCase(value);
191
+ }
192
+ function dashCase(value, options) {
193
+ if (options && options.capitalize) {
194
+ return changeCase.trainCase(value);
195
+ }
196
+ return changeCase.kebabCase(value);
197
+ }
198
+ function pascalCase2(value) {
199
+ return changeCase.pascalCase(value);
200
+ }
201
+ function capitalCase2(value) {
202
+ return changeCase.capitalCase(value);
203
+ }
204
+ function sentenceCase(value) {
205
+ return noCase(value, (input, index) => {
206
+ const result = input.toLowerCase();
207
+ if (index === 0) {
208
+ return input.charAt(0).toUpperCase() + input.substring(1);
209
+ }
210
+ return result;
211
+ });
212
+ }
213
+ function dotCase(value, options) {
214
+ const transformedValue = changeCase.dotNotation(value);
215
+ if (options && options.lowerCase) {
216
+ return transformedValue.toLowerCase();
217
+ }
218
+ return transformedValue;
219
+ }
220
+ function noCase(value, transform) {
221
+ let result = NO_CASE_SPLIT_REGEXP.reduce((input, regex) => input.replace(regex, "$1\0$2"), value);
222
+ result = result.replace(NO_CASE_STRIP_REGEXP, "\0");
223
+ let start = 0;
224
+ let end = result.length;
225
+ while (result.charAt(start) === "\0") {
226
+ start++;
227
+ }
228
+ while (result.charAt(end - 1) === "\0") {
229
+ end--;
230
+ }
231
+ return result.slice(start, end).split("\0").map(transform || ((input) => input.toLowerCase())).join(" ");
232
+ }
233
+
234
+ // src/string/main.ts
235
+ function condenseWhitespace(value) {
236
+ return value.trim().replace(/\s{2,}/g, " ");
237
+ }
238
+ var string = {
239
+ excerpt,
240
+ truncate,
241
+ slug,
242
+ interpolate,
243
+ plural,
244
+ pluralize,
245
+ singular,
246
+ isPlural,
247
+ isSingular,
248
+ camelCase: camelCase2,
249
+ capitalCase: capitalCase2,
250
+ dashCase,
251
+ dotCase,
252
+ noCase,
253
+ pascalCase: pascalCase2,
254
+ sentenceCase,
255
+ snakeCase: snakeCase2,
256
+ titleCase,
257
+ random,
258
+ sentence,
259
+ condenseWhitespace,
260
+ seconds: seconds_default,
261
+ milliseconds: milliseconds_default,
262
+ bytes: bytes_default,
263
+ ordinal
264
+ };
265
+ var main_default = string;
266
+
267
+ export {
268
+ main_default
269
+ };
@@ -0,0 +1,63 @@
1
+ // src/base64.ts
2
+ var Base64 = class {
3
+ encode(data, encoding) {
4
+ if (typeof data === "string") {
5
+ return Buffer.from(data, encoding).toString("base64");
6
+ }
7
+ return Buffer.from(data).toString("base64");
8
+ }
9
+ decode(encoded, encoding = "utf-8", strict = false) {
10
+ if (Buffer.isBuffer(encoded)) {
11
+ return encoded.toString(encoding);
12
+ }
13
+ const decoded = Buffer.from(encoded, "base64").toString(encoding);
14
+ const isInvalid = this.encode(decoded, encoding) !== encoded;
15
+ if (strict && isInvalid) {
16
+ throw new Error("Cannot decode malformed value");
17
+ }
18
+ return isInvalid ? null : decoded;
19
+ }
20
+ urlEncode(data, encoding) {
21
+ const encoded = typeof data === "string" ? this.encode(data, encoding) : this.encode(data);
22
+ return encoded.replace(/\+/g, "-").replace(/\//g, "_").replace(/\=/g, "");
23
+ }
24
+ urlDecode(encoded, encoding = "utf-8", strict = false) {
25
+ if (Buffer.isBuffer(encoded)) {
26
+ return encoded.toString(encoding);
27
+ }
28
+ const decoded = Buffer.from(encoded, "base64").toString(encoding);
29
+ const isInvalid = this.urlEncode(decoded, encoding) !== encoded;
30
+ if (strict && isInvalid) {
31
+ throw new Error("Cannot urlDecode malformed value");
32
+ }
33
+ return isInvalid ? null : decoded;
34
+ }
35
+ };
36
+ var base64 = new Base64();
37
+
38
+ // src/string/milliseconds.ts
39
+ import { parse, format } from "@lukeed/ms";
40
+ var milliseconds_default = {
41
+ format(milliseconds, long) {
42
+ return format(milliseconds, long);
43
+ },
44
+ /**
45
+ * Parse time expression string to milliseconds. The number value
46
+ * is returned as it is, considering it is already in milliseconds
47
+ */
48
+ parse(duration) {
49
+ if (typeof duration === "number") {
50
+ return duration;
51
+ }
52
+ const milliseconds = parse(duration);
53
+ if (milliseconds === void 0) {
54
+ throw new Error(`Invalid duration expression "${duration}"`);
55
+ }
56
+ return milliseconds;
57
+ }
58
+ };
59
+
60
+ export {
61
+ base64,
62
+ milliseconds_default
63
+ };
@@ -0,0 +1,39 @@
1
+ // src/json/safe_parse.ts
2
+ import { parse } from "secure-json-parse";
3
+ function safeParse(jsonString, reviver) {
4
+ return parse(jsonString, reviver, {
5
+ protoAction: "remove",
6
+ constructorAction: "remove"
7
+ });
8
+ }
9
+
10
+ // src/json/safe_stringify.ts
11
+ import { configure } from "safe-stable-stringify";
12
+ var stringify = configure({
13
+ bigint: false,
14
+ circularValue: void 0,
15
+ deterministic: false
16
+ });
17
+ function jsonStringifyReplacer(replacer) {
18
+ return function(key, value) {
19
+ const val = replacer ? replacer.call(this, key, value) : value;
20
+ if (typeof val === "bigint") {
21
+ return val.toString();
22
+ }
23
+ return val;
24
+ };
25
+ }
26
+ function safeStringify(value, replacer, space) {
27
+ return stringify(value, jsonStringifyReplacer(replacer), space);
28
+ }
29
+
30
+ // src/json/main.ts
31
+ var json = {
32
+ safeParse,
33
+ safeStringify
34
+ };
35
+ var main_default = json;
36
+
37
+ export {
38
+ main_default
39
+ };
package/build/index.d.ts CHANGED
@@ -1,19 +1,284 @@
1
- /// <reference types="@types/node" resolution-mode="require"/>
2
- export { base64 } from './src/base64.js';
3
- export { compose } from './src/compose.js';
4
- export { importDefault } from './src/import_default.js';
5
- export { defineStaticProperty } from './src/define_static_property.js';
6
- export { Exception, createError } from './src/exception.js';
7
- export { flatten } from './src/flatten.js';
8
- export { fsImportAll } from './src/fs_import_all.js';
9
- export { fsReadAll } from './src/fs_read_all.js';
10
- export { isScriptFile } from './src/is_script_file.js';
11
- export { MessageBuilder } from './src/message_builder.js';
12
- export { naturalSort } from './src/natural_sort.js';
13
- export { ObjectBuilder } from './src/object_builder.js';
14
- export { safeEqual } from './src/safe_equal.js';
15
- export { slash } from './src/slash.js';
16
- export { RuntimeException } from './src/exceptions/runtime_exception.js';
17
- export { InvalidArgumentsException } from './src/exceptions/invalid_arguments_exception.js';
18
- export declare function getDirname(url: string | URL): string;
19
- export declare function getFilename(url: string | URL): string;
1
+ import { Constructor as Constructor$1, ImportAllFilesOptions, ReadAllFilesOptions, OmitProperties } from './src/types.js';
2
+ export { default as slash } from 'slash';
3
+
4
+ /**
5
+ * Helper class to base64 encode/decode values with option
6
+ * for url encoding and decoding
7
+ */
8
+ declare class Base64 {
9
+ /**
10
+ * Base64 encode Buffer or string
11
+ */
12
+ encode(arrayBuffer: ArrayBuffer | SharedArrayBuffer): string;
13
+ encode(data: string, encoding?: BufferEncoding): string;
14
+ /**
15
+ * Base64 decode a previously encoded string or Buffer.
16
+ */
17
+ decode(encode: string, encoding: BufferEncoding, strict: true): string;
18
+ decode(encode: string, encoding: undefined, strict: true): string;
19
+ decode(encode: string, encoding?: BufferEncoding, strict?: false): string | null;
20
+ decode(encode: Buffer, encoding?: BufferEncoding): string;
21
+ /**
22
+ * Base64 encode Buffer or string to be URL safe. (RFC 4648)
23
+ */
24
+ urlEncode(arrayBuffer: ArrayBuffer | SharedArrayBuffer): string;
25
+ urlEncode(data: string, encoding?: BufferEncoding): string;
26
+ /**
27
+ * Base64 URL decode a previously encoded string or Buffer. (RFC 4648)
28
+ */
29
+ urlDecode(encode: string, encoding: BufferEncoding, strict: true): string;
30
+ urlDecode(encode: string, encoding: undefined, strict: true): string;
31
+ urlDecode(encode: string, encoding?: BufferEncoding, strict?: false): string | null;
32
+ urlDecode(encode: Buffer, encoding?: BufferEncoding): string;
33
+ }
34
+ declare const base64: Base64;
35
+
36
+ interface UnaryFunction<T, R> {
37
+ (source: T): R;
38
+ }
39
+ /**
40
+ * Compose a class by applying mixins to it.
41
+ * The code is inspired by https://justinfagnani.com/2015/12/21/real-mixins-with-javascript-classes/, its
42
+ * just that I have added the support for static types too.
43
+ */
44
+ declare function compose<T extends Constructor$1, A>(superclass: T, mixin: UnaryFunction<T, A>): A;
45
+ declare function compose<T extends Constructor$1, A, B>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>): B;
46
+ declare function compose<T extends Constructor$1, A, B, C>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>): C;
47
+ declare function compose<T extends Constructor$1, A, B, C, D>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>): D;
48
+ declare function compose<T extends Constructor$1, A, B, C, D, E>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>, mixinE: UnaryFunction<D, E>): E;
49
+ declare function compose<T extends Constructor$1, A, B, C, D, E, F>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>, mixinF: UnaryFunction<E, F>): F;
50
+ declare function compose<T extends Constructor$1, A, B, C, D, E, F, G>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>, mixinF: UnaryFunction<E, F>, mixinG: UnaryFunction<F, G>): G;
51
+ declare function compose<T extends Constructor$1, A, B, C, D, E, F, G, H>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>, mixinF: UnaryFunction<E, F>, mixinG: UnaryFunction<F, G>, mixinH: UnaryFunction<G, H>): H;
52
+ declare function compose<T extends Constructor$1, A, B, C, D, E, F, G, H, I>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>, mixinF: UnaryFunction<E, F>, mixinG: UnaryFunction<F, G>, mixinH: UnaryFunction<G, H>, mixinI: UnaryFunction<H, I>): I;
53
+
54
+ /**
55
+ * Dynamically import a module and ensure it has a default export
56
+ */
57
+ declare function importDefault<T extends object>(importFn: () => Promise<T>, filePath?: string): Promise<T extends {
58
+ default: infer A;
59
+ } ? A : never>;
60
+
61
+ type Constructor = new (...args: any[]) => any;
62
+ type AbstractConstructor = abstract new (...args: any[]) => any;
63
+ /**
64
+ * Define static properties on a class with inheritance in play.
65
+ */
66
+ declare function defineStaticProperty<T extends Constructor | AbstractConstructor, Prop extends keyof T>(self: T, propertyName: Prop, { initialValue, strategy, }: {
67
+ initialValue: T[Prop];
68
+ strategy: 'inherit' | 'define' | ((value: T[Prop]) => T[Prop]);
69
+ }): void;
70
+
71
+ /**
72
+ * Extended Error object with the option to set error `status` and `code`.
73
+ * At AdonisJs, we prefer exceptions with proper error codes to handle
74
+ * them without relying on message pattern matching.
75
+ *
76
+ * ```js
77
+ * new Exception('message', 500, 'E_RUNTIME_EXCEPTION')
78
+ * ```
79
+ */
80
+ declare class Exception extends Error {
81
+ /**
82
+ * Static properties to defined on the exception once
83
+ * and then re-use them
84
+ */
85
+ static help?: string;
86
+ static code?: string;
87
+ static status?: number;
88
+ static message?: string;
89
+ /**
90
+ * Name of the class that raised the exception.
91
+ */
92
+ name: string;
93
+ /**
94
+ * Optional help description for the error. You can use it to define additional
95
+ * human readable information for the error.
96
+ */
97
+ help?: string;
98
+ /**
99
+ * A machine readable error code. This will allow the error handling logic
100
+ * to narrow down exceptions based upon the error code.
101
+ */
102
+ code?: string;
103
+ /**
104
+ * A status code for the error. Usually helpful when converting errors
105
+ * to HTTP responses.
106
+ */
107
+ status: number;
108
+ constructor(message?: string, options?: ErrorOptions & {
109
+ code?: string;
110
+ status?: number;
111
+ });
112
+ get [Symbol.toStringTag](): string;
113
+ toString(): string;
114
+ }
115
+ /**
116
+ * Helper to create anonymous error classes
117
+ */
118
+ declare function createError<T extends any[] = never>(message: string, code: string, status?: number): typeof Exception & T extends never ? {
119
+ new (args?: any, options?: ErrorOptions): Exception;
120
+ } : {
121
+ new (args: T, options?: ErrorOptions): Exception;
122
+ };
123
+
124
+ /**
125
+ * Recursively flatten an object/array.
126
+ */
127
+ declare function flatten<X = Record<string, any>, Y = unknown>(input: Y, glue?: string, keepNullish?: boolean): X;
128
+
129
+ /**
130
+ * Returns an array of file paths from the given location. You can
131
+ * optionally filter and sort files by passing relevant options
132
+ *
133
+ * ```ts
134
+ * await fsReadAll(new URL('./', import.meta.url))
135
+ *
136
+ * await fsReadAll(new URL('./', import.meta.url), {
137
+ * filter: (filePath) => filePath.endsWith('.js')
138
+ * })
139
+
140
+ * await fsReadAll(new URL('./', import.meta.url), {
141
+ * absolute: true,
142
+ * unixPaths: true
143
+ * })
144
+ * ```
145
+ */
146
+ declare function fsImportAll(location: string | URL, options?: ImportAllFilesOptions): Promise<any>;
147
+
148
+ /**
149
+ * Returns an array of file paths from the given location. You can
150
+ * optionally filter and sort files by passing relevant options
151
+ *
152
+ * ```ts
153
+ * await fsReadAll(new URL('./', import.meta.url))
154
+ *
155
+ * await fsReadAll(new URL('./', import.meta.url), {
156
+ * filter: (filePath) => filePath.endsWith('.js')
157
+ * })
158
+
159
+ * await fsReadAll(new URL('./', import.meta.url), {
160
+ * absolute: true,
161
+ * unixPaths: true
162
+ * })
163
+ * ```
164
+ */
165
+ declare function fsReadAll(location: string | URL, options?: ReadAllFilesOptions): Promise<string[]>;
166
+
167
+ /**
168
+ * Returns `true` when file ends with `.js`, `.json` or
169
+ * `.ts` but not `.d.ts`.
170
+ */
171
+ declare function isScriptFile(filePath: string): boolean;
172
+
173
+ /**
174
+ * Message builder exposes an API to "JSON.stringify" values by
175
+ * encoding purpose and expiry date inside them.
176
+ *
177
+ * The return value must be further encrypted to prevent tempering.
178
+ */
179
+ declare class MessageBuilder {
180
+ #private;
181
+ /**
182
+ * Builds a message by encoding expiry date and purpose inside it.
183
+ */
184
+ build(message: any, expiresIn?: string | number, purpose?: string): string;
185
+ /**
186
+ * Verifies the message for expiry and purpose.
187
+ */
188
+ verify<T extends any>(message: any, purpose?: string): null | T;
189
+ }
190
+
191
+ /**
192
+ * Perform natural sorting with "Array.sort()" method
193
+ */
194
+ declare function naturalSort(current: string, next: string): number;
195
+
196
+ /**
197
+ * A simple class to build an object incrementally. It is helpful when you
198
+ * want to add properties to the object conditionally.
199
+ *
200
+ * Instead of writing
201
+ * ```
202
+ * const obj = {
203
+ * ...(user.id ? { id: user.id } : {}),
204
+ * ...(user.firstName && user.lastName ? { name: `${user.firstName} ${user.lastName}` } : {}),
205
+ * }
206
+ * ```
207
+ *
208
+ * You can write
209
+ *
210
+ * const obj = new ObjectBuilder()
211
+ * .add('id', user.id)
212
+ * .add(
213
+ * 'fullName',
214
+ * user.firstName && user.lastName ? `${user.firstName} ${user.lastName}` : undefined
215
+ * )
216
+ * .toObject()
217
+ */
218
+ declare class ObjectBuilder<ReturnType extends Record<string, any>, IgnoreNull extends boolean = false> {
219
+ #private;
220
+ values: ReturnType;
221
+ constructor(initialValue: ReturnType, ignoreNull?: IgnoreNull);
222
+ /**
223
+ * Add a key-value pair to the object
224
+ *
225
+ * - Undefined values are ignored
226
+ * - Null values are ignored, when `ignoreNull` is set to true
227
+ */
228
+ add<Prop extends string>(key: Prop, value: undefined): this;
229
+ add<Prop extends string, Value>(key: Prop, value: Value): ObjectBuilder<ReturnType & {
230
+ [P in Prop]: Value;
231
+ }, IgnoreNull>;
232
+ /**
233
+ * Remove key from the object
234
+ */
235
+ remove<K extends keyof ReturnType>(key: K): this;
236
+ /**
237
+ * Find if a value exists
238
+ */
239
+ has<K extends keyof ReturnType>(key: K): boolean;
240
+ /**
241
+ * Get the existing value for a given key
242
+ */
243
+ get<K extends keyof ReturnType>(key: K): ReturnType[K];
244
+ /**
245
+ * Get the underlying constructed object
246
+ */
247
+ toObject(): IgnoreNull extends true ? {
248
+ [K in keyof OmitProperties<ReturnType, null>]: ReturnType[K];
249
+ } : {
250
+ [K in keyof ReturnType]: ReturnType[K];
251
+ };
252
+ }
253
+
254
+ type BufferSafeValue = ArrayBuffer | SharedArrayBuffer | number[] | string | {
255
+ valueOf(): string | object;
256
+ } | {
257
+ [Symbol.toPrimitive](hint: 'string'): string;
258
+ };
259
+ /**
260
+ * Compare two values to see if they are equal. The comparison is done in
261
+ * a way to avoid timing-attacks.
262
+ */
263
+ declare function safeEqual<T extends BufferSafeValue, U extends BufferSafeValue>(trustedValue: T, userInput: U): boolean;
264
+
265
+ declare class RuntimeException extends Exception {
266
+ static code: string;
267
+ static status: number;
268
+ }
269
+
270
+ declare class InvalidArgumentsException extends Exception {
271
+ static code: string;
272
+ static status: number;
273
+ }
274
+
275
+ /**
276
+ * Get dirname for a given file path URL
277
+ */
278
+ declare function getDirname(url: string | URL): string;
279
+ /**
280
+ * Get filename for a given file path URL
281
+ */
282
+ declare function getFilename(url: string | URL): string;
283
+
284
+ export { Exception, InvalidArgumentsException, MessageBuilder, ObjectBuilder, RuntimeException, base64, compose, createError, defineStaticProperty, flatten, fsImportAll, fsReadAll, getDirname, getFilename, importDefault, isScriptFile, naturalSort, safeEqual };