@poppinss/utils 6.5.0-3 → 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 +22 -7
- 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,23 +1,82 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* String builder to transform the string using the fluent API
|
|
3
|
+
*/
|
|
4
|
+
declare class StringBuilder {
|
|
2
5
|
#private;
|
|
3
6
|
constructor(value: string | StringBuilder);
|
|
7
|
+
/**
|
|
8
|
+
* Applies dash case transformation
|
|
9
|
+
*/
|
|
4
10
|
dashCase(): this;
|
|
11
|
+
/**
|
|
12
|
+
* Applies dot case transformation
|
|
13
|
+
*/
|
|
5
14
|
dotCase(): this;
|
|
15
|
+
/**
|
|
16
|
+
* Applies snake case transformation
|
|
17
|
+
*/
|
|
6
18
|
snakeCase(): this;
|
|
19
|
+
/**
|
|
20
|
+
* Applies pascal case transformation
|
|
21
|
+
*/
|
|
7
22
|
pascalCase(): this;
|
|
23
|
+
/**
|
|
24
|
+
* Applies camelcase case transformation
|
|
25
|
+
*/
|
|
8
26
|
camelCase(): this;
|
|
27
|
+
/**
|
|
28
|
+
* Applies capital case transformation
|
|
29
|
+
*/
|
|
9
30
|
capitalCase(): this;
|
|
31
|
+
/**
|
|
32
|
+
* Applies title case transformation
|
|
33
|
+
*/
|
|
10
34
|
titleCase(): this;
|
|
35
|
+
/**
|
|
36
|
+
* Applies sentence case transformation
|
|
37
|
+
*/
|
|
11
38
|
sentenceCase(): this;
|
|
39
|
+
/**
|
|
40
|
+
* Removes all sorts of casing from the string
|
|
41
|
+
*/
|
|
12
42
|
noCase(): this;
|
|
43
|
+
/**
|
|
44
|
+
* Converts value to its plural form
|
|
45
|
+
*/
|
|
13
46
|
plural(): this;
|
|
47
|
+
/**
|
|
48
|
+
* Converts value to its singular form
|
|
49
|
+
*/
|
|
14
50
|
singular(): this;
|
|
51
|
+
/**
|
|
52
|
+
* Converts value to a URL friendly slug
|
|
53
|
+
*/
|
|
15
54
|
slugify(): this;
|
|
55
|
+
/**
|
|
56
|
+
* Removes a given suffix from the string
|
|
57
|
+
*/
|
|
16
58
|
removeSuffix(suffix: string): this;
|
|
59
|
+
/**
|
|
60
|
+
* Adds suffix to the string
|
|
61
|
+
*/
|
|
17
62
|
suffix(suffix: string): this;
|
|
63
|
+
/**
|
|
64
|
+
* Removes a given prefix from the string
|
|
65
|
+
*/
|
|
18
66
|
removePrefix(prefix: string): this;
|
|
67
|
+
/**
|
|
68
|
+
* Adds prefix to the string
|
|
69
|
+
*/
|
|
19
70
|
prefix(prefix: string): this;
|
|
71
|
+
/**
|
|
72
|
+
* Removes extension from the value
|
|
73
|
+
*/
|
|
20
74
|
removeExtension(): this;
|
|
75
|
+
/**
|
|
76
|
+
* Adds extension to the value
|
|
77
|
+
*/
|
|
21
78
|
ext(extension: string): this;
|
|
22
79
|
toString(): string;
|
|
23
80
|
}
|
|
81
|
+
|
|
82
|
+
export { StringBuilder as default };
|
|
@@ -1,86 +1,148 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
1
|
+
import {
|
|
2
|
+
main_default
|
|
3
|
+
} from "../chunk-OKRMWJO4.js";
|
|
4
|
+
import "../chunk-PWRXO3NF.js";
|
|
5
|
+
|
|
6
|
+
// src/string_builder.ts
|
|
7
|
+
import { extname } from "node:path";
|
|
8
|
+
var StringBuilder = class {
|
|
9
|
+
#value;
|
|
10
|
+
constructor(value) {
|
|
11
|
+
this.#value = typeof value === "string" ? value : value.toString();
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Applies dash case transformation
|
|
15
|
+
*/
|
|
16
|
+
dashCase() {
|
|
17
|
+
this.#value = main_default.dashCase(this.#value);
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Applies dot case transformation
|
|
22
|
+
*/
|
|
23
|
+
dotCase() {
|
|
24
|
+
this.#value = main_default.dotCase(this.#value);
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Applies snake case transformation
|
|
29
|
+
*/
|
|
30
|
+
snakeCase() {
|
|
31
|
+
this.#value = main_default.snakeCase(this.#value);
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Applies pascal case transformation
|
|
36
|
+
*/
|
|
37
|
+
pascalCase() {
|
|
38
|
+
this.#value = main_default.pascalCase(this.#value);
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Applies camelcase case transformation
|
|
43
|
+
*/
|
|
44
|
+
camelCase() {
|
|
45
|
+
this.#value = main_default.camelCase(this.#value);
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Applies capital case transformation
|
|
50
|
+
*/
|
|
51
|
+
capitalCase() {
|
|
52
|
+
this.#value = main_default.capitalCase(this.#value);
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Applies title case transformation
|
|
57
|
+
*/
|
|
58
|
+
titleCase() {
|
|
59
|
+
this.#value = main_default.titleCase(this.#value);
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Applies sentence case transformation
|
|
64
|
+
*/
|
|
65
|
+
sentenceCase() {
|
|
66
|
+
this.#value = main_default.sentenceCase(this.#value);
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Removes all sorts of casing from the string
|
|
71
|
+
*/
|
|
72
|
+
noCase() {
|
|
73
|
+
this.#value = main_default.noCase(this.#value);
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Converts value to its plural form
|
|
78
|
+
*/
|
|
79
|
+
plural() {
|
|
80
|
+
this.#value = main_default.pluralize(this.#value);
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Converts value to its singular form
|
|
85
|
+
*/
|
|
86
|
+
singular() {
|
|
87
|
+
this.#value = main_default.singular(this.#value);
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Converts value to a URL friendly slug
|
|
92
|
+
*/
|
|
93
|
+
slugify() {
|
|
94
|
+
this.#value = main_default.slug(this.#value);
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Removes a given suffix from the string
|
|
99
|
+
*/
|
|
100
|
+
removeSuffix(suffix) {
|
|
101
|
+
this.#value = this.#value.replace(new RegExp(`[-_]?${suffix}$`, "i"), "");
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Adds suffix to the string
|
|
106
|
+
*/
|
|
107
|
+
suffix(suffix) {
|
|
108
|
+
this.removeSuffix(suffix);
|
|
109
|
+
this.#value = `${this.#value}${suffix}`;
|
|
110
|
+
return this;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Removes a given prefix from the string
|
|
114
|
+
*/
|
|
115
|
+
removePrefix(prefix) {
|
|
116
|
+
this.#value = this.#value.replace(new RegExp(`^${prefix}[-_]?`, "i"), "");
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Adds prefix to the string
|
|
121
|
+
*/
|
|
122
|
+
prefix(prefix) {
|
|
123
|
+
this.removePrefix(prefix);
|
|
124
|
+
this.#value = `${prefix}${this.#value}`;
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Removes extension from the value
|
|
129
|
+
*/
|
|
130
|
+
removeExtension() {
|
|
131
|
+
this.#value = this.#value.replace(new RegExp(`${extname(this.#value)}$`), "");
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Adds extension to the value
|
|
136
|
+
*/
|
|
137
|
+
ext(extension) {
|
|
138
|
+
this.removeExtension();
|
|
139
|
+
this.#value = `${this.#value}.${extension.replace(/^\./, "")}`;
|
|
140
|
+
return this;
|
|
141
|
+
}
|
|
142
|
+
toString() {
|
|
143
|
+
return this.#value;
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
export {
|
|
147
|
+
StringBuilder as default
|
|
148
|
+
};
|
package/build/src/types.d.ts
CHANGED
|
@@ -1,22 +1,32 @@
|
|
|
1
1
|
type PickKeysByValue<T, V> = {
|
|
2
2
|
[K in keyof T]: T[K] extends V ? K : never;
|
|
3
3
|
}[keyof T];
|
|
4
|
-
|
|
4
|
+
type OmitProperties<T, P> = Omit<T, PickKeysByValue<T, P>>;
|
|
5
5
|
type ScanFsBaseOptions = {
|
|
6
6
|
ignoreMissingRoot?: boolean;
|
|
7
7
|
filter?: (filePath: string, index: number) => boolean;
|
|
8
8
|
sort?: (current: string, next: string) => number;
|
|
9
9
|
};
|
|
10
|
-
|
|
10
|
+
type ImportAllFilesOptions = ScanFsBaseOptions & {
|
|
11
|
+
/**
|
|
12
|
+
* A custom method to transform collection keys
|
|
13
|
+
*/
|
|
11
14
|
transformKeys?: (keys: string[]) => string[];
|
|
12
15
|
};
|
|
13
|
-
|
|
16
|
+
type ReadAllFilesOptions = ScanFsBaseOptions & {
|
|
14
17
|
pathType?: 'relative' | 'unixRelative' | 'absolute' | 'unixAbsolute' | 'url';
|
|
15
18
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
type JSONReplacer = (this: any, key: string, value: any) => any;
|
|
20
|
+
type JSONReviver = (this: any, key: string, value: any) => any;
|
|
21
|
+
type Constructor = new (...args: any[]) => any;
|
|
22
|
+
/**
|
|
23
|
+
* Normalizes constructor to work with mixins. There is an open bug for mixins
|
|
24
|
+
* to allow constructors other than `...args: any[]`
|
|
25
|
+
*
|
|
26
|
+
* https://github.com/microsoft/TypeScript/issues/37142
|
|
27
|
+
*/
|
|
28
|
+
type NormalizeConstructor<T extends Constructor> = {
|
|
20
29
|
new (...args: any[]): InstanceType<T>;
|
|
21
30
|
} & Omit<T, 'constructor'>;
|
|
22
|
-
|
|
31
|
+
|
|
32
|
+
export { Constructor, ImportAllFilesOptions, JSONReplacer, JSONReviver, NormalizeConstructor, OmitProperties, ReadAllFilesOptions };
|
package/build/src/types.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@poppinss/utils",
|
|
3
|
-
"version": "6.5.0-
|
|
3
|
+
"version": "6.5.0-4",
|
|
4
4
|
"description": "Handy utilities for repetitive work",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
"quick:test": "node --loader=ts-node/esm bin/test.ts",
|
|
33
33
|
"clean": "del-cli build",
|
|
34
34
|
"typecheck": "tsc --noEmit",
|
|
35
|
-
"compile": "npm run lint && npm run clean &&
|
|
35
|
+
"compile": "npm run lint && npm run clean && tsup-node",
|
|
36
36
|
"build": "npm run compile && npm run build:lodash",
|
|
37
37
|
"release": "np",
|
|
38
38
|
"version": "npm run build",
|
|
39
|
-
"prepublishOnly": "npm run build
|
|
39
|
+
"prepublishOnly": "npm run build",
|
|
40
40
|
"lint": "eslint . --ext=.ts",
|
|
41
41
|
"format": "prettier --write .",
|
|
42
42
|
"sync-labels": "github-label-sync --labels .github/labels.json poppinss/utils"
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"@types/node": "^20.3.2",
|
|
62
62
|
"c8": "^8.0.0",
|
|
63
63
|
"del-cli": "^5.0.0",
|
|
64
|
-
"eslint": "^8.
|
|
64
|
+
"eslint": "^8.45.0",
|
|
65
65
|
"fs-extra": "^11.1.1",
|
|
66
66
|
"github-label-sync": "^2.3.1",
|
|
67
67
|
"husky": "^8.0.3",
|
|
@@ -69,14 +69,15 @@
|
|
|
69
69
|
"lodash-cli": "^4.17.5",
|
|
70
70
|
"move-file-cli": "^3.0.0",
|
|
71
71
|
"np": "^8.0.4",
|
|
72
|
-
"prettier": "^
|
|
72
|
+
"prettier": "^3.0.0",
|
|
73
73
|
"ts-node": "^10.9.1",
|
|
74
|
+
"tsup": "^7.1.0",
|
|
74
75
|
"typescript": "^5.1.6"
|
|
75
76
|
},
|
|
76
77
|
"dependencies": {
|
|
77
78
|
"@lukeed/ms": "^2.0.1",
|
|
78
79
|
"@types/bytes": "^3.1.1",
|
|
79
|
-
"@types/pluralize": "
|
|
80
|
+
"@types/pluralize": "0.0.30",
|
|
80
81
|
"bytes": "^3.1.2",
|
|
81
82
|
"case-anything": "^2.1.13",
|
|
82
83
|
"flattie": "^1.1.0",
|
|
@@ -124,5 +125,19 @@
|
|
|
124
125
|
"eslintConfig": {
|
|
125
126
|
"extends": "@adonisjs/eslint-config/package"
|
|
126
127
|
},
|
|
127
|
-
"prettier": "@adonisjs/prettier-config"
|
|
128
|
+
"prettier": "@adonisjs/prettier-config",
|
|
129
|
+
"tsup": {
|
|
130
|
+
"entry": [
|
|
131
|
+
"./index.ts",
|
|
132
|
+
"./src/string/main.ts",
|
|
133
|
+
"./src/string_builder.ts",
|
|
134
|
+
"./src/json/main.ts",
|
|
135
|
+
"./src/types.ts"
|
|
136
|
+
],
|
|
137
|
+
"outDir": "./build",
|
|
138
|
+
"clean": true,
|
|
139
|
+
"format": "esm",
|
|
140
|
+
"dts": true,
|
|
141
|
+
"target": "esnext"
|
|
142
|
+
}
|
|
128
143
|
}
|
package/build/src/base64.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/// <reference types="@types/node" resolution-mode="require"/>
|
|
2
|
-
declare class Base64 {
|
|
3
|
-
encode(arrayBuffer: ArrayBuffer | SharedArrayBuffer): string;
|
|
4
|
-
encode(data: string, encoding?: BufferEncoding): string;
|
|
5
|
-
decode(encode: string, encoding: BufferEncoding, strict: true): string;
|
|
6
|
-
decode(encode: string, encoding: undefined, strict: true): string;
|
|
7
|
-
decode(encode: string, encoding?: BufferEncoding, strict?: false): string | null;
|
|
8
|
-
decode(encode: Buffer, encoding?: BufferEncoding): string;
|
|
9
|
-
urlEncode(arrayBuffer: ArrayBuffer | SharedArrayBuffer): string;
|
|
10
|
-
urlEncode(data: string, encoding?: BufferEncoding): string;
|
|
11
|
-
urlDecode(encode: string, encoding: BufferEncoding, strict: true): string;
|
|
12
|
-
urlDecode(encode: string, encoding: undefined, strict: true): string;
|
|
13
|
-
urlDecode(encode: string, encoding?: BufferEncoding, strict?: false): string | null;
|
|
14
|
-
urlDecode(encode: Buffer, encoding?: BufferEncoding): string;
|
|
15
|
-
}
|
|
16
|
-
export declare const base64: Base64;
|
|
17
|
-
export {};
|
package/build/src/base64.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
class Base64 {
|
|
2
|
-
encode(data, encoding) {
|
|
3
|
-
if (typeof data === 'string') {
|
|
4
|
-
return Buffer.from(data, encoding).toString('base64');
|
|
5
|
-
}
|
|
6
|
-
return Buffer.from(data).toString('base64');
|
|
7
|
-
}
|
|
8
|
-
decode(encoded, encoding = 'utf-8', strict = false) {
|
|
9
|
-
if (Buffer.isBuffer(encoded)) {
|
|
10
|
-
return encoded.toString(encoding);
|
|
11
|
-
}
|
|
12
|
-
const decoded = Buffer.from(encoded, 'base64').toString(encoding);
|
|
13
|
-
const isInvalid = this.encode(decoded, encoding) !== encoded;
|
|
14
|
-
if (strict && isInvalid) {
|
|
15
|
-
throw new Error('Cannot decode malformed value');
|
|
16
|
-
}
|
|
17
|
-
return isInvalid ? null : decoded;
|
|
18
|
-
}
|
|
19
|
-
urlEncode(data, encoding) {
|
|
20
|
-
const encoded = typeof data === 'string' ? this.encode(data, encoding) : this.encode(data);
|
|
21
|
-
return encoded.replace(/\+/g, '-').replace(/\//g, '_').replace(/\=/g, '');
|
|
22
|
-
}
|
|
23
|
-
urlDecode(encoded, encoding = 'utf-8', strict = false) {
|
|
24
|
-
if (Buffer.isBuffer(encoded)) {
|
|
25
|
-
return encoded.toString(encoding);
|
|
26
|
-
}
|
|
27
|
-
const decoded = Buffer.from(encoded, 'base64').toString(encoding);
|
|
28
|
-
const isInvalid = this.urlEncode(decoded, encoding) !== encoded;
|
|
29
|
-
if (strict && isInvalid) {
|
|
30
|
-
throw new Error('Cannot urlDecode malformed value');
|
|
31
|
-
}
|
|
32
|
-
return isInvalid ? null : decoded;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
export const base64 = new Base64();
|
package/build/src/compose.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { Constructor } from './types.js';
|
|
2
|
-
interface UnaryFunction<T, R> {
|
|
3
|
-
(source: T): R;
|
|
4
|
-
}
|
|
5
|
-
export declare function compose<T extends Constructor, A>(superclass: T, mixin: UnaryFunction<T, A>): A;
|
|
6
|
-
export declare function compose<T extends Constructor, A, B>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>): B;
|
|
7
|
-
export declare function compose<T extends Constructor, A, B, C>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>): C;
|
|
8
|
-
export declare function compose<T extends Constructor, A, B, C, D>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>): D;
|
|
9
|
-
export declare function compose<T extends Constructor, 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;
|
|
10
|
-
export declare function compose<T extends Constructor, 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;
|
|
11
|
-
export declare function compose<T extends Constructor, 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;
|
|
12
|
-
export declare function compose<T extends Constructor, 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;
|
|
13
|
-
export declare function compose<T extends Constructor, 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;
|
|
14
|
-
export {};
|
package/build/src/compose.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
type Constructor = new (...args: any[]) => any;
|
|
2
|
-
type AbstractConstructor = abstract new (...args: any[]) => any;
|
|
3
|
-
export declare function defineStaticProperty<T extends Constructor | AbstractConstructor, Prop extends keyof T>(self: T, propertyName: Prop, { initialValue, strategy, }: {
|
|
4
|
-
initialValue: T[Prop];
|
|
5
|
-
strategy: 'inherit' | 'define' | ((value: T[Prop]) => T[Prop]);
|
|
6
|
-
}): void;
|
|
7
|
-
export {};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import lodash from '@poppinss/utils/lodash';
|
|
2
|
-
export function defineStaticProperty(self, propertyName, { initialValue, strategy, }) {
|
|
3
|
-
if (!self.hasOwnProperty(propertyName)) {
|
|
4
|
-
const value = self[propertyName];
|
|
5
|
-
if (strategy === 'define' || value === undefined) {
|
|
6
|
-
Object.defineProperty(self, propertyName, {
|
|
7
|
-
value: initialValue,
|
|
8
|
-
configurable: true,
|
|
9
|
-
enumerable: true,
|
|
10
|
-
writable: true,
|
|
11
|
-
});
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
Object.defineProperty(self, propertyName, {
|
|
15
|
-
value: typeof strategy === 'function' ? strategy(value) : lodash.cloneDeep(value),
|
|
16
|
-
configurable: true,
|
|
17
|
-
enumerable: true,
|
|
18
|
-
writable: true,
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
}
|
package/build/src/exception.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export declare class Exception extends Error {
|
|
2
|
-
static help?: string;
|
|
3
|
-
static code?: string;
|
|
4
|
-
static status?: number;
|
|
5
|
-
static message?: string;
|
|
6
|
-
name: string;
|
|
7
|
-
help?: string;
|
|
8
|
-
code?: string;
|
|
9
|
-
status: number;
|
|
10
|
-
constructor(message?: string, options?: ErrorOptions & {
|
|
11
|
-
code?: string;
|
|
12
|
-
status?: number;
|
|
13
|
-
});
|
|
14
|
-
get [Symbol.toStringTag](): string;
|
|
15
|
-
toString(): string;
|
|
16
|
-
}
|
|
17
|
-
export declare function createError<T extends any[] = never>(message: string, code: string, status?: number): typeof Exception & T extends never ? {
|
|
18
|
-
new (args?: any, options?: ErrorOptions): Exception;
|
|
19
|
-
} : {
|
|
20
|
-
new (args: T, options?: ErrorOptions): Exception;
|
|
21
|
-
};
|
package/build/src/exception.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { format } from 'node:util';
|
|
2
|
-
export class Exception extends Error {
|
|
3
|
-
name;
|
|
4
|
-
status;
|
|
5
|
-
constructor(message, options) {
|
|
6
|
-
super(message, options);
|
|
7
|
-
const ErrorConstructor = this.constructor;
|
|
8
|
-
this.name = ErrorConstructor.name;
|
|
9
|
-
this.message = message || ErrorConstructor.message || '';
|
|
10
|
-
this.status = options?.status || ErrorConstructor.status || 500;
|
|
11
|
-
const code = options?.code || ErrorConstructor.code;
|
|
12
|
-
if (code !== undefined) {
|
|
13
|
-
this.code = code;
|
|
14
|
-
}
|
|
15
|
-
const help = ErrorConstructor.help;
|
|
16
|
-
if (help !== undefined) {
|
|
17
|
-
this.help = help;
|
|
18
|
-
}
|
|
19
|
-
Error.captureStackTrace(this, ErrorConstructor);
|
|
20
|
-
}
|
|
21
|
-
get [Symbol.toStringTag]() {
|
|
22
|
-
return this.constructor.name;
|
|
23
|
-
}
|
|
24
|
-
toString() {
|
|
25
|
-
if (this.code) {
|
|
26
|
-
return `${this.name} [${this.code}]: ${this.message}`;
|
|
27
|
-
}
|
|
28
|
-
return `${this.name}: ${this.message}`;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
export function createError(message, code, status) {
|
|
32
|
-
return class extends Exception {
|
|
33
|
-
static message = message;
|
|
34
|
-
static code = code;
|
|
35
|
-
static status = status;
|
|
36
|
-
constructor(args, options) {
|
|
37
|
-
super(format(message, ...(args || [])), options);
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
}
|
package/build/src/flatten.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function flatten<X = Record<string, any>, Y = unknown>(input: Y, glue?: string, keepNullish?: boolean): X;
|
package/build/src/flatten.js
DELETED