@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.
- package/README.md +661 -873
- package/build/index.d.ts +16 -10
- package/build/index.js +21 -53
- package/build/lodash/main.cjs +37 -0
- package/build/src/{Helpers/base64.d.ts → base64.d.ts} +7 -23
- package/build/src/{Helpers/base64.js → base64.js} +9 -22
- package/build/src/compose.d.ts +17 -0
- package/build/src/compose.js +3 -0
- package/build/src/{defineStaticProperty.d.ts → define_static_property.d.ts} +2 -6
- package/build/src/define_static_property.js +21 -0
- package/build/src/exception.d.ts +16 -0
- package/build/src/exception.js +29 -0
- package/build/src/flatten.d.ts +1 -1
- package/build/src/flatten.js +4 -13
- package/build/src/fs_import_all.d.ts +3 -0
- package/build/src/fs_import_all.js +28 -0
- package/build/src/fs_read_all.d.ts +3 -0
- package/build/src/fs_read_all.js +55 -0
- package/build/src/is_script_file.d.ts +1 -0
- package/build/src/is_script_file.js +12 -0
- package/build/src/json/main.d.ts +7 -0
- package/build/src/json/main.js +6 -0
- package/build/src/json/safe_parse.d.ts +2 -0
- package/build/src/json/safe_parse.js +7 -0
- package/build/src/json/safe_stringify.d.ts +2 -0
- package/build/src/json/safe_stringify.js +18 -0
- package/build/src/message_builder.d.ts +5 -0
- package/build/src/message_builder.js +43 -0
- package/build/src/natural_sort.d.ts +1 -0
- package/build/src/natural_sort.js +3 -0
- package/build/src/object_builder.d.ts +10 -0
- package/build/src/object_builder.js +31 -0
- package/build/src/{Helpers/safeEqual.d.ts → safe_equal.d.ts} +1 -4
- package/build/src/safe_equal.js +14 -0
- package/build/src/slash.d.ts +1 -5
- package/build/src/slash.js +1 -24
- package/build/src/string/bytes.d.ts +6 -0
- package/build/src/string/bytes.js +12 -0
- package/build/src/string/change_case.d.ts +13 -0
- package/build/src/string/change_case.js +75 -0
- package/build/src/string/excerpt.d.ts +4 -0
- package/build/src/string/excerpt.js +10 -0
- package/build/src/string/interpolate.d.ts +1 -0
- package/build/src/{Helpers → string}/interpolate.js +1 -22
- package/build/src/string/main.d.ts +46 -0
- package/build/src/string/main.js +42 -0
- package/build/src/string/milliseconds.d.ts +5 -0
- package/build/src/string/milliseconds.js +16 -0
- package/build/src/string/ordinal.d.ts +1 -0
- package/build/src/string/ordinal.js +21 -0
- package/build/src/string/pluralize.d.ts +12 -0
- package/build/src/string/pluralize.js +12 -0
- package/build/src/string/random.d.ts +1 -0
- package/build/src/string/random.js +7 -0
- package/build/src/string/seconds.d.ts +5 -0
- package/build/src/string/seconds.js +16 -0
- package/build/src/string/slugify.d.ts +2 -0
- package/build/src/string/slugify.js +2 -0
- package/build/src/string/to_sentence.d.ts +5 -0
- package/build/src/string/to_sentence.js +13 -0
- package/build/src/string/truncate.d.ts +4 -0
- package/build/src/string/truncate.js +10 -0
- package/build/src/types.d.ts +14 -0
- package/build/src/types.js +1 -0
- package/lodash/lodash.types.d.ts +44 -0
- package/package.json +70 -82
- package/build/helpers.d.ts +0 -1
- package/build/helpers.js +0 -25
- package/build/src/Exception.d.ts +0 -17
- package/build/src/Exception.js +0 -68
- package/build/src/Helpers/MessageBuilder.d.ts +0 -28
- package/build/src/Helpers/MessageBuilder.js +0 -97
- package/build/src/Helpers/ObjectBuilder.d.ts +0 -46
- package/build/src/Helpers/ObjectBuilder.js +0 -75
- package/build/src/Helpers/compose.d.ts +0 -21
- package/build/src/Helpers/compose.js +0 -20
- package/build/src/Helpers/fsReadAll.d.ts +0 -4
- package/build/src/Helpers/fsReadAll.js +0 -23
- package/build/src/Helpers/index.d.ts +0 -14
- package/build/src/Helpers/index.js +0 -62
- package/build/src/Helpers/interpolate.d.ts +0 -7
- package/build/src/Helpers/requireAll.d.ts +0 -8
- package/build/src/Helpers/requireAll.js +0 -65
- package/build/src/Helpers/resolveDir.d.ts +0 -5
- package/build/src/Helpers/resolveDir.js +0 -46
- package/build/src/Helpers/resolveFrom.d.ts +0 -5
- package/build/src/Helpers/resolveFrom.js +0 -27
- package/build/src/Helpers/safeEqual.js +0 -42
- package/build/src/Helpers/string.d.ts +0 -124
- package/build/src/Helpers/string.js +0 -328
- package/build/src/Helpers/types.d.ts +0 -86
- package/build/src/Helpers/types.js +0 -161
- package/build/src/ManagerConfigValidator.d.ts +0 -20
- package/build/src/ManagerConfigValidator.js +0 -55
- package/build/src/defineStaticProperty.js +0 -57
- package/build/src/esmRequire.d.ts +0 -5
- package/build/src/esmRequire.js +0 -20
- package/build/src/esmResolver.d.ts +0 -1
- package/build/src/esmResolver.js +0 -15
- package/build/src/fast-safe-stringify.d.ts +0 -2
- package/build/src/fast-safe-stringify.js +0 -101
- package/build/src/isScriptFile.d.ts +0 -5
- package/build/src/isScriptFile.js +0 -28
- package/build/src/lodash.d.ts +0 -13
- package/build/src/lodash.js +0 -39
- package/build/src/safeParse.d.ts +0 -5
- package/build/src/safeParse.js +0 -42
- package/build/src/safeStringify.d.ts +0 -5
- package/build/src/safeStringify.js +0 -39
- package/types/lodash.types.d.ts +0 -65
package/package.json
CHANGED
|
@@ -1,99 +1,87 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@poppinss/utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-0",
|
|
4
4
|
"description": "Handy utilities for repetitive work",
|
|
5
5
|
"main": "build/index.js",
|
|
6
|
+
"type": "module",
|
|
6
7
|
"files": [
|
|
7
8
|
"build/src",
|
|
9
|
+
"lodash",
|
|
10
|
+
"build/lodash",
|
|
8
11
|
"build/index.d.ts",
|
|
9
|
-
"build/index.js"
|
|
10
|
-
"types",
|
|
11
|
-
"build/helpers.d.ts",
|
|
12
|
-
"build/helpers.js"
|
|
12
|
+
"build/index.js"
|
|
13
13
|
],
|
|
14
|
+
"exports": {
|
|
15
|
+
".": "./build/index.js",
|
|
16
|
+
"./lodash": {
|
|
17
|
+
"types": "./lodash/lodash.types.d.ts",
|
|
18
|
+
"node": "./build/lodash/main.cjs"
|
|
19
|
+
},
|
|
20
|
+
"./string": "./build/src/string/main.js",
|
|
21
|
+
"./json": "./build/src/json/main.js",
|
|
22
|
+
"./types": "./build/src/types.js"
|
|
23
|
+
},
|
|
14
24
|
"scripts": {
|
|
15
|
-
"mrm": "mrm --preset=@adonisjs/mrm-preset",
|
|
16
25
|
"pretest": "npm run lint",
|
|
17
|
-
"test": "
|
|
18
|
-
"
|
|
26
|
+
"test": "npm run build:lodash && npm run vscode:test",
|
|
27
|
+
"build:lodash": "lodash include=\"pick,omit,has,get,set,unset,mergeWith,merge,size,clone,cloneDeep,toPath\" --production && move-file ./lodash.custom.min.js build/lodash/main.cjs",
|
|
28
|
+
"vscode:test": "node --loader=ts-node/esm bin/test.ts",
|
|
29
|
+
"clean": "del-cli build",
|
|
19
30
|
"compile": "npm run lint && npm run clean && tsc",
|
|
20
|
-
"build": "npm run compile",
|
|
21
|
-
"
|
|
22
|
-
"release": "np --message=\"chore(release): %s\"",
|
|
31
|
+
"build": "npm run compile && npm run build:lodash",
|
|
32
|
+
"release": "np",
|
|
23
33
|
"version": "npm run build",
|
|
24
|
-
"
|
|
25
|
-
"prepublishOnly": "npm run build",
|
|
34
|
+
"prepublishOnly": "npm run build && cd build && node bin/test.js",
|
|
26
35
|
"lint": "eslint . --ext=.ts",
|
|
27
|
-
"
|
|
36
|
+
"format": "prettier --write .",
|
|
37
|
+
"sync-labels": "github-label-sync --labels .github/labels.json poppinss/utils"
|
|
28
38
|
},
|
|
29
39
|
"keywords": [
|
|
30
|
-
"
|
|
40
|
+
"toolkit",
|
|
41
|
+
"utilities"
|
|
31
42
|
],
|
|
32
43
|
"author": "virk,poppinss",
|
|
33
44
|
"license": "MIT",
|
|
34
45
|
"devDependencies": {
|
|
35
|
-
"@
|
|
36
|
-
"@
|
|
37
|
-
"@
|
|
38
|
-
"@
|
|
39
|
-
"@
|
|
40
|
-
"@
|
|
41
|
-
"@
|
|
42
|
-
"@
|
|
43
|
-
"@types/
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"eslint": "^8.
|
|
46
|
+
"@commitlint/cli": "^17.1.2",
|
|
47
|
+
"@commitlint/config-conventional": "^17.1.0",
|
|
48
|
+
"@japa/assert": "^1.3.6",
|
|
49
|
+
"@japa/expect-type": "^1.0.1",
|
|
50
|
+
"@japa/run-failed-tests": "^1.1.0",
|
|
51
|
+
"@japa/runner": "^2.2.1",
|
|
52
|
+
"@japa/spec-reporter": "^1.3.1",
|
|
53
|
+
"@swc/core": "^1.3.3",
|
|
54
|
+
"@types/fs-extra": "^9.0.13",
|
|
55
|
+
"@types/node": "^18.7.19",
|
|
56
|
+
"del-cli": "^5.0.0",
|
|
57
|
+
"eslint": "^8.24.0",
|
|
47
58
|
"eslint-config-prettier": "^8.5.0",
|
|
48
|
-
"eslint-plugin-adonis": "^
|
|
49
|
-
"eslint-plugin-prettier": "^4.
|
|
59
|
+
"eslint-plugin-adonis": "^3.0.2",
|
|
60
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
61
|
+
"fs-extra": "^10.1.0",
|
|
50
62
|
"github-label-sync": "^2.2.0",
|
|
51
|
-
"husky": "^
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
"exclude": [
|
|
60
|
-
"test"
|
|
61
|
-
],
|
|
62
|
-
"extension": [
|
|
63
|
-
".ts"
|
|
64
|
-
]
|
|
65
|
-
},
|
|
66
|
-
"config": {
|
|
67
|
-
"commitizen": {
|
|
68
|
-
"path": "cz-conventional-changelog"
|
|
69
|
-
}
|
|
70
|
-
},
|
|
71
|
-
"np": {
|
|
72
|
-
"contents": ".",
|
|
73
|
-
"anyBranch": false
|
|
63
|
+
"husky": "^8.0.1",
|
|
64
|
+
"lodash": "^4.17.21",
|
|
65
|
+
"lodash-cli": "^4.17.5",
|
|
66
|
+
"move-file-cli": "^3.0.0",
|
|
67
|
+
"np": "^7.6.2",
|
|
68
|
+
"prettier": "^2.7.1",
|
|
69
|
+
"ts-node": "^10.9.1",
|
|
70
|
+
"typescript": "^4.8.3"
|
|
74
71
|
},
|
|
75
72
|
"dependencies": {
|
|
76
|
-
"@
|
|
73
|
+
"@lukeed/ms": "^2.0.0",
|
|
77
74
|
"@types/bytes": "^3.1.1",
|
|
78
|
-
"@types/
|
|
75
|
+
"@types/pluralize": "^0.0.29",
|
|
79
76
|
"bytes": "^3.1.2",
|
|
80
|
-
"
|
|
81
|
-
"cuid": "^2.1.8",
|
|
77
|
+
"case-anything": "^2.1.10",
|
|
82
78
|
"flattie": "^1.1.0",
|
|
83
|
-
"fs-readdir-recursive": "^1.1.0",
|
|
84
|
-
"he": "^1.2.0",
|
|
85
|
-
"kind-of": "^6.0.3",
|
|
86
|
-
"lodash": "^4.17.21",
|
|
87
|
-
"ms": "^2.1.3",
|
|
88
79
|
"pluralize": "^8.0.0",
|
|
89
|
-
"
|
|
90
|
-
"
|
|
80
|
+
"safe-stable-stringify": "^2.4.0",
|
|
81
|
+
"secure-json-parse": "^2.5.0",
|
|
82
|
+
"slash": "^4.0.0",
|
|
91
83
|
"slugify": "^1.6.5",
|
|
92
|
-
"truncatise": "0.0.8"
|
|
93
|
-
},
|
|
94
|
-
"directories": {
|
|
95
|
-
"doc": "docs",
|
|
96
|
-
"test": "test"
|
|
84
|
+
"truncatise": "^0.0.8"
|
|
97
85
|
},
|
|
98
86
|
"repository": {
|
|
99
87
|
"type": "git",
|
|
@@ -106,11 +94,9 @@
|
|
|
106
94
|
"eslintConfig": {
|
|
107
95
|
"extends": [
|
|
108
96
|
"plugin:adonis/typescriptPackage",
|
|
109
|
-
"prettier",
|
|
110
97
|
"prettier"
|
|
111
98
|
],
|
|
112
99
|
"plugins": [
|
|
113
|
-
"prettier",
|
|
114
100
|
"prettier"
|
|
115
101
|
],
|
|
116
102
|
"rules": {
|
|
@@ -135,17 +121,19 @@
|
|
|
135
121
|
"arrowParens": "always",
|
|
136
122
|
"printWidth": 100
|
|
137
123
|
},
|
|
138
|
-
"
|
|
139
|
-
"
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
"
|
|
145
|
-
"
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
"
|
|
124
|
+
"commitlint": {
|
|
125
|
+
"extends": [
|
|
126
|
+
"@commitlint/config-conventional"
|
|
127
|
+
]
|
|
128
|
+
},
|
|
129
|
+
"publishConfig": {
|
|
130
|
+
"access": "public",
|
|
131
|
+
"tag": "next"
|
|
132
|
+
},
|
|
133
|
+
"np": {
|
|
134
|
+
"message": "chore(release): %s",
|
|
135
|
+
"tag": "next",
|
|
136
|
+
"branch": "main",
|
|
137
|
+
"anyBranch": false
|
|
150
138
|
}
|
|
151
139
|
}
|
package/build/helpers.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './src/Helpers';
|
package/build/helpers.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
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
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
13
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
14
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
15
|
-
}
|
|
16
|
-
Object.defineProperty(o, k2, desc);
|
|
17
|
-
}) : (function(o, m, k, k2) {
|
|
18
|
-
if (k2 === undefined) k2 = k;
|
|
19
|
-
o[k2] = m[k];
|
|
20
|
-
}));
|
|
21
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
22
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
23
|
-
};
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
__exportStar(require("./src/Helpers"), exports);
|
package/build/src/Exception.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Extended Error object with the option to set error `status` and `code`.
|
|
3
|
-
* At AdonisJs, we prefer exceptions with proper error codes to handle
|
|
4
|
-
* them without relying on message pattern matching.
|
|
5
|
-
*
|
|
6
|
-
* ```js
|
|
7
|
-
* new Exception('message', 500, 'E_RUNTIME_EXCEPTION')
|
|
8
|
-
* ```
|
|
9
|
-
*/
|
|
10
|
-
export declare class Exception extends Error {
|
|
11
|
-
name: string;
|
|
12
|
-
message: string;
|
|
13
|
-
help?: string;
|
|
14
|
-
code?: string;
|
|
15
|
-
status: number;
|
|
16
|
-
constructor(message: string, status?: number, code?: string);
|
|
17
|
-
}
|
package/build/src/Exception.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
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.Exception = void 0;
|
|
12
|
-
/**
|
|
13
|
-
* Extended Error object with the option to set error `status` and `code`.
|
|
14
|
-
* At AdonisJs, we prefer exceptions with proper error codes to handle
|
|
15
|
-
* them without relying on message pattern matching.
|
|
16
|
-
*
|
|
17
|
-
* ```js
|
|
18
|
-
* new Exception('message', 500, 'E_RUNTIME_EXCEPTION')
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
class Exception extends Error {
|
|
22
|
-
constructor(message, status = 500, code) {
|
|
23
|
-
super(message);
|
|
24
|
-
/**
|
|
25
|
-
* Set error message
|
|
26
|
-
*/
|
|
27
|
-
Object.defineProperty(this, 'message', {
|
|
28
|
-
configurable: true,
|
|
29
|
-
enumerable: false,
|
|
30
|
-
value: code ? `${code}: ${message}` : message,
|
|
31
|
-
writable: true,
|
|
32
|
-
});
|
|
33
|
-
/**
|
|
34
|
-
* Set error name as a public property
|
|
35
|
-
*/
|
|
36
|
-
Object.defineProperty(this, 'name', {
|
|
37
|
-
configurable: true,
|
|
38
|
-
enumerable: false,
|
|
39
|
-
value: this.constructor.name,
|
|
40
|
-
writable: true,
|
|
41
|
-
});
|
|
42
|
-
/**
|
|
43
|
-
* Set status as a public property
|
|
44
|
-
*/
|
|
45
|
-
Object.defineProperty(this, 'status', {
|
|
46
|
-
configurable: true,
|
|
47
|
-
enumerable: false,
|
|
48
|
-
value: status,
|
|
49
|
-
writable: true,
|
|
50
|
-
});
|
|
51
|
-
/**
|
|
52
|
-
* Set error code as a public property (only when defined)
|
|
53
|
-
*/
|
|
54
|
-
if (code) {
|
|
55
|
-
Object.defineProperty(this, 'code', {
|
|
56
|
-
configurable: true,
|
|
57
|
-
enumerable: false,
|
|
58
|
-
value: code,
|
|
59
|
-
writable: true,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Update the stack trace
|
|
64
|
-
*/
|
|
65
|
-
Error.captureStackTrace(this, this.constructor);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
exports.Exception = Exception;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Message builder exposes an API to JSON.stringify values by encoding purpose
|
|
3
|
-
* and expiryDate inside them. It returns a readable string, which is the
|
|
4
|
-
* output of `JSON.stringify`.
|
|
5
|
-
*
|
|
6
|
-
* Why use this over `JSON.stringify`?
|
|
7
|
-
*
|
|
8
|
-
* - It protects you from JSON poisioning
|
|
9
|
-
* - Allows encoding expiry dates to the message. It means, the message builer is
|
|
10
|
-
* helpful, when you want to encode a message and pass it around, but also control
|
|
11
|
-
* the TTL of the message
|
|
12
|
-
* - Allows encoding purpose. Again, useful for distribution.
|
|
13
|
-
*/
|
|
14
|
-
export declare class MessageBuilder {
|
|
15
|
-
private getExpiryDate;
|
|
16
|
-
/**
|
|
17
|
-
* Returns a boolean telling, if message has been expired or not
|
|
18
|
-
*/
|
|
19
|
-
private isExpired;
|
|
20
|
-
/**
|
|
21
|
-
* Builds a message by encoding expiry and purpose inside it
|
|
22
|
-
*/
|
|
23
|
-
build(message: any, expiresIn?: string | number, purpose?: string): string;
|
|
24
|
-
/**
|
|
25
|
-
* Verifies the message for expiry and purpose
|
|
26
|
-
*/
|
|
27
|
-
verify<T extends any>(message: any, purpose?: string): null | T;
|
|
28
|
-
}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* @adonisjs/encryption
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
11
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.MessageBuilder = void 0;
|
|
15
|
-
const ms_1 = __importDefault(require("ms"));
|
|
16
|
-
const safeParse_1 = require("../safeParse");
|
|
17
|
-
const safeStringify_1 = require("../safeStringify");
|
|
18
|
-
/**
|
|
19
|
-
* Message builder exposes an API to JSON.stringify values by encoding purpose
|
|
20
|
-
* and expiryDate inside them. It returns a readable string, which is the
|
|
21
|
-
* output of `JSON.stringify`.
|
|
22
|
-
*
|
|
23
|
-
* Why use this over `JSON.stringify`?
|
|
24
|
-
*
|
|
25
|
-
* - It protects you from JSON poisioning
|
|
26
|
-
* - Allows encoding expiry dates to the message. It means, the message builer is
|
|
27
|
-
* helpful, when you want to encode a message and pass it around, but also control
|
|
28
|
-
* the TTL of the message
|
|
29
|
-
* - Allows encoding purpose. Again, useful for distribution.
|
|
30
|
-
*/
|
|
31
|
-
class MessageBuilder {
|
|
32
|
-
getExpiryDate(expiresIn) {
|
|
33
|
-
if (!expiresIn) {
|
|
34
|
-
return undefined;
|
|
35
|
-
}
|
|
36
|
-
const expiryMs = typeof expiresIn === 'string' ? (0, ms_1.default)(expiresIn) : expiresIn;
|
|
37
|
-
if (expiryMs === undefined || expiryMs === null) {
|
|
38
|
-
throw new Error(`Invalid value for expiresIn "${expiresIn}"`);
|
|
39
|
-
}
|
|
40
|
-
return new Date(Date.now() + expiryMs);
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Returns a boolean telling, if message has been expired or not
|
|
44
|
-
*/
|
|
45
|
-
isExpired(message) {
|
|
46
|
-
if (!message.expiryDate) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
try {
|
|
50
|
-
const expiryDate = new Date(message.expiryDate);
|
|
51
|
-
return isNaN(expiryDate.getTime()) || expiryDate < new Date();
|
|
52
|
-
}
|
|
53
|
-
catch (error) {
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Builds a message by encoding expiry and purpose inside it
|
|
59
|
-
*/
|
|
60
|
-
build(message, expiresIn, purpose) {
|
|
61
|
-
const expiryDate = this.getExpiryDate(expiresIn);
|
|
62
|
-
return (0, safeStringify_1.safeStringify)({ message, purpose, expiryDate });
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Verifies the message for expiry and purpose
|
|
66
|
-
*/
|
|
67
|
-
verify(message, purpose) {
|
|
68
|
-
const parsed = (0, safeParse_1.safeParse)(message);
|
|
69
|
-
/**
|
|
70
|
-
* Safe parse returns the value as it is when unable to JSON.parse it. However, in
|
|
71
|
-
* our case if value was correctly parsed, it should never match the input
|
|
72
|
-
*/
|
|
73
|
-
if (parsed === message) {
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Missing ".message" property
|
|
78
|
-
*/
|
|
79
|
-
if (!parsed.message) {
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Ensure purposes are same.
|
|
84
|
-
*/
|
|
85
|
-
if (parsed.purpose !== purpose) {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Ensure isn't expired
|
|
90
|
-
*/
|
|
91
|
-
if (this.isExpired(parsed)) {
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
return parsed.message;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
exports.MessageBuilder = MessageBuilder;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A simple class to build an object incrementally. It is helpful when you
|
|
3
|
-
* want to add properties to the object conditionally.
|
|
4
|
-
*
|
|
5
|
-
* Instead of writing
|
|
6
|
-
* ```
|
|
7
|
-
* const obj = {
|
|
8
|
-
* ...(user.id ? { id: user.id } : {}),
|
|
9
|
-
* ...(user.firstName && user.lastName ? { name: `${user.firstName} ${user.lastName}` } : {}),
|
|
10
|
-
* }
|
|
11
|
-
* ```
|
|
12
|
-
*
|
|
13
|
-
* You can write
|
|
14
|
-
*
|
|
15
|
-
* const obj = new ObjectBuilder()
|
|
16
|
-
* .add('id', user.id)
|
|
17
|
-
* .add(
|
|
18
|
-
* 'fullName',
|
|
19
|
-
* user.firstName && user.lastName ? `${user.firstName} ${user.lastName}` : undefined
|
|
20
|
-
* )
|
|
21
|
-
* .value
|
|
22
|
-
*/
|
|
23
|
-
export declare class ObjectBuilder {
|
|
24
|
-
private ignoreNull?;
|
|
25
|
-
value: any;
|
|
26
|
-
constructor(ignoreNull?: boolean | undefined);
|
|
27
|
-
/**
|
|
28
|
-
* Add value to the property.
|
|
29
|
-
*
|
|
30
|
-
* - Undefined values are ignored
|
|
31
|
-
* - Null values are ignored, when `ignoreNull` is set to true
|
|
32
|
-
*/
|
|
33
|
-
add(key: string, value: any): this;
|
|
34
|
-
/**
|
|
35
|
-
* Remove value from the object
|
|
36
|
-
*/
|
|
37
|
-
remove(key: string): this;
|
|
38
|
-
/**
|
|
39
|
-
* Find if a value exists
|
|
40
|
-
*/
|
|
41
|
-
has(key: string): boolean;
|
|
42
|
-
/**
|
|
43
|
-
* Get the existing value
|
|
44
|
-
*/
|
|
45
|
-
get<T extends any>(key: string): T;
|
|
46
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
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.ObjectBuilder = void 0;
|
|
12
|
-
/**
|
|
13
|
-
* A simple class to build an object incrementally. It is helpful when you
|
|
14
|
-
* want to add properties to the object conditionally.
|
|
15
|
-
*
|
|
16
|
-
* Instead of writing
|
|
17
|
-
* ```
|
|
18
|
-
* const obj = {
|
|
19
|
-
* ...(user.id ? { id: user.id } : {}),
|
|
20
|
-
* ...(user.firstName && user.lastName ? { name: `${user.firstName} ${user.lastName}` } : {}),
|
|
21
|
-
* }
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* You can write
|
|
25
|
-
*
|
|
26
|
-
* const obj = new ObjectBuilder()
|
|
27
|
-
* .add('id', user.id)
|
|
28
|
-
* .add(
|
|
29
|
-
* 'fullName',
|
|
30
|
-
* user.firstName && user.lastName ? `${user.firstName} ${user.lastName}` : undefined
|
|
31
|
-
* )
|
|
32
|
-
* .value
|
|
33
|
-
*/
|
|
34
|
-
class ObjectBuilder {
|
|
35
|
-
constructor(ignoreNull) {
|
|
36
|
-
this.ignoreNull = ignoreNull;
|
|
37
|
-
this.value = {};
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Add value to the property.
|
|
41
|
-
*
|
|
42
|
-
* - Undefined values are ignored
|
|
43
|
-
* - Null values are ignored, when `ignoreNull` is set to true
|
|
44
|
-
*/
|
|
45
|
-
add(key, value) {
|
|
46
|
-
if (value === undefined) {
|
|
47
|
-
return this;
|
|
48
|
-
}
|
|
49
|
-
if (this.ignoreNull === true && value === null) {
|
|
50
|
-
return this;
|
|
51
|
-
}
|
|
52
|
-
this.value[key] = value;
|
|
53
|
-
return this;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Remove value from the object
|
|
57
|
-
*/
|
|
58
|
-
remove(key) {
|
|
59
|
-
delete this.value[key];
|
|
60
|
-
return this;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Find if a value exists
|
|
64
|
-
*/
|
|
65
|
-
has(key) {
|
|
66
|
-
return this.get(key) !== undefined;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Get the existing value
|
|
70
|
-
*/
|
|
71
|
-
get(key) {
|
|
72
|
-
return this.value[key];
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
exports.ObjectBuilder = ObjectBuilder;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
declare type Constructor = new (...args: any[]) => any;
|
|
2
|
-
/**
|
|
3
|
-
* Converting unions to intersection
|
|
4
|
-
*/
|
|
5
|
-
declare type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never;
|
|
6
|
-
/**
|
|
7
|
-
* Normalizes constructor to work with mixins. There is an open bug for mixins
|
|
8
|
-
* to allow constructors other than `...args: any[]`
|
|
9
|
-
*
|
|
10
|
-
* https://github.com/microsoft/TypeScript/issues/37142
|
|
11
|
-
*/
|
|
12
|
-
export declare type NormalizeConstructor<T extends Constructor> = {
|
|
13
|
-
new (...args: any[]): InstanceType<T>;
|
|
14
|
-
} & Omit<T, 'constructor'>;
|
|
15
|
-
/**
|
|
16
|
-
* Compose a class by applying mixins to it.
|
|
17
|
-
* The code is inspired by https://justinfagnani.com/2015/12/21/real-mixins-with-javascript-classes/, its
|
|
18
|
-
* just that I have added the support for static types too.
|
|
19
|
-
*/
|
|
20
|
-
export declare const compose: <SuperClass extends Constructor, M extends ((superclass: SuperClass) => Constructor)[]>(superclass: SuperClass, ...mixins: M) => SuperClass & UnionToIntersection<ReturnType<M[number]>>;
|
|
21
|
-
export {};
|
|
@@ -1,20 +0,0 @@
|
|
|
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.compose = void 0;
|
|
12
|
-
/**
|
|
13
|
-
* Compose a class by applying mixins to it.
|
|
14
|
-
* The code is inspired by https://justinfagnani.com/2015/12/21/real-mixins-with-javascript-classes/, its
|
|
15
|
-
* just that I have added the support for static types too.
|
|
16
|
-
*/
|
|
17
|
-
const compose = (superclass, ...mixins) => {
|
|
18
|
-
return mixins.reduce((c, mixin) => mixin(c), superclass);
|
|
19
|
-
};
|
|
20
|
-
exports.compose = compose;
|
|
@@ -1,23 +0,0 @@
|
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
11
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.fsReadAll = void 0;
|
|
15
|
-
const fs_readdir_recursive_1 = __importDefault(require("fs-readdir-recursive"));
|
|
16
|
-
const isScriptFile_1 = require("../isScriptFile");
|
|
17
|
-
/**
|
|
18
|
-
* Returns an array of file paths from the given location.
|
|
19
|
-
*/
|
|
20
|
-
function fsReadAll(location, callback) {
|
|
21
|
-
return (0, fs_readdir_recursive_1.default)(location).filter(typeof callback === 'function' ? callback : isScriptFile_1.isScriptFile);
|
|
22
|
-
}
|
|
23
|
-
exports.fsReadAll = fsReadAll;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export { default as cuid } from 'cuid';
|
|
2
|
-
export * as file from '@poppinss/file-generator';
|
|
3
|
-
export { base64 } from './base64';
|
|
4
|
-
export { compose, NormalizeConstructor } from './compose';
|
|
5
|
-
export { fsReadAll } from './fsReadAll';
|
|
6
|
-
export { interpolate } from './interpolate';
|
|
7
|
-
export { MessageBuilder } from './MessageBuilder';
|
|
8
|
-
export { ObjectBuilder } from './ObjectBuilder';
|
|
9
|
-
export { requireAll } from './requireAll';
|
|
10
|
-
export { resolveDir } from './resolveDir';
|
|
11
|
-
export { resolveFrom } from './resolveFrom';
|
|
12
|
-
export { safeEqual } from './safeEqual';
|
|
13
|
-
export * as string from './string';
|
|
14
|
-
export * as types from './types';
|