@wener/utils 1.1.53 → 1.1.54
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/lib/errors/Errors.js +201 -2
- package/lib/index.js +9 -8
- package/lib/io/ArrayBuffers.js +559 -2
- package/lib/langs/parseDate.js +20 -0
- package/package.json +2 -2
- package/src/errors/Errors.ts +106 -1
- package/src/index.ts +10 -8
- package/src/io/ArrayBuffers.ts +676 -1
- package/src/langs/parseDate.ts +13 -0
- package/tsconfig.json +4 -13
- package/lib/errors/Errors.mod.js +0 -206
- package/lib/io/ArrayBuffers.mod.js +0 -531
- package/src/errors/Errors.mod.ts +0 -104
- package/src/io/ArrayBuffers.mod.ts +0 -670
package/tsconfig.json
CHANGED
|
@@ -3,17 +3,13 @@
|
|
|
3
3
|
"moduleResolution": "bundler",
|
|
4
4
|
"target": "ESNext",
|
|
5
5
|
"module": "ESNext",
|
|
6
|
-
"lib": [
|
|
7
|
-
"dom",
|
|
8
|
-
"dom.iterable",
|
|
9
|
-
"ESNext"
|
|
10
|
-
],
|
|
6
|
+
"lib": ["dom", "dom.iterable", "ESNext"],
|
|
11
7
|
"strict": true,
|
|
12
8
|
"sourceMap": true,
|
|
13
9
|
"skipLibCheck": true,
|
|
14
10
|
"esModuleInterop": true,
|
|
15
11
|
"verbatimModuleSyntax": true,
|
|
16
|
-
"erasableSyntaxOnly":
|
|
12
|
+
"erasableSyntaxOnly": false,
|
|
17
13
|
"allowSyntheticDefaultImports": true,
|
|
18
14
|
"noImplicitAny": true,
|
|
19
15
|
"noImplicitReturns": true,
|
|
@@ -27,11 +23,6 @@
|
|
|
27
23
|
"baseUrl": ".",
|
|
28
24
|
"rootDir": "./src"
|
|
29
25
|
},
|
|
30
|
-
"exclude": [
|
|
31
|
-
|
|
32
|
-
],
|
|
33
|
-
"include": [
|
|
34
|
-
"src/types.d.ts",
|
|
35
|
-
"src"
|
|
36
|
-
]
|
|
26
|
+
"exclude": ["node_modules"],
|
|
27
|
+
"include": ["src/types.d.ts", "src"]
|
|
37
28
|
}
|
package/lib/errors/Errors.mod.js
DELETED
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
function _define_property(obj, key, value) {
|
|
2
|
-
if (key in obj) {
|
|
3
|
-
Object.defineProperty(obj, key, {
|
|
4
|
-
value: value,
|
|
5
|
-
enumerable: true,
|
|
6
|
-
configurable: true,
|
|
7
|
-
writable: true
|
|
8
|
-
});
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
obj[key] = value;
|
|
12
|
-
}
|
|
13
|
-
return obj;
|
|
14
|
-
}
|
|
15
|
-
function _instanceof(left, right) {
|
|
16
|
-
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
17
|
-
return !!right[Symbol.hasInstance](left);
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
return left instanceof right;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
function _object_spread(target) {
|
|
24
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
25
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
26
|
-
var ownKeys = Object.keys(source);
|
|
27
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
28
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
|
|
29
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
30
|
-
}));
|
|
31
|
-
}
|
|
32
|
-
ownKeys.forEach(function (key) {
|
|
33
|
-
_define_property(target, key, source[key]);
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
return target;
|
|
37
|
-
}
|
|
38
|
-
function ownKeys(object, enumerableOnly) {
|
|
39
|
-
var keys = Object.keys(object);
|
|
40
|
-
if (Object.getOwnPropertySymbols) {
|
|
41
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
42
|
-
if (enumerableOnly) {
|
|
43
|
-
symbols = symbols.filter(function (sym) {
|
|
44
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
keys.push.apply(keys, symbols);
|
|
48
|
-
}
|
|
49
|
-
return keys;
|
|
50
|
-
}
|
|
51
|
-
function _object_spread_props(target, source) {
|
|
52
|
-
source = source != null ? source : {};
|
|
53
|
-
if (Object.getOwnPropertyDescriptors) {
|
|
54
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
ownKeys(Object(source)).forEach(function (key) {
|
|
58
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
return target;
|
|
62
|
-
}
|
|
63
|
-
import { DetailError, DetailHolder } from "./DetailError.js";
|
|
64
|
-
/*
|
|
65
|
-
https://github.com/tc39/proposal-error-cause
|
|
66
|
-
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause
|
|
67
|
-
Stage 3
|
|
68
|
-
Chrome 93, Safari 15, Node 16.9
|
|
69
|
-
|
|
70
|
-
https://www.npmjs.com/package/pony-cause
|
|
71
|
-
*/ export var BadRequest = create({
|
|
72
|
-
status: 400
|
|
73
|
-
});
|
|
74
|
-
export var Unauthorized = create({
|
|
75
|
-
status: 403
|
|
76
|
-
});
|
|
77
|
-
export var Forbidden = create({
|
|
78
|
-
status: 403
|
|
79
|
-
});
|
|
80
|
-
export var NotFound = create({
|
|
81
|
-
status: 404
|
|
82
|
-
});
|
|
83
|
-
export var InternalServerError = create({
|
|
84
|
-
status: 500
|
|
85
|
-
});
|
|
86
|
-
export var NotImplemented = create({
|
|
87
|
-
status: 501
|
|
88
|
-
});
|
|
89
|
-
export var ServiceUnavailable = create({
|
|
90
|
-
status: 503
|
|
91
|
-
});
|
|
92
|
-
export var IllegalState = create({
|
|
93
|
-
status: 500,
|
|
94
|
-
message: "Illegal State"
|
|
95
|
-
});
|
|
96
|
-
export var UnsupportedOperation = create({
|
|
97
|
-
status: 500,
|
|
98
|
-
message: "Unsupported Operation"
|
|
99
|
-
});
|
|
100
|
-
export var IllegalArgument = create({
|
|
101
|
-
status: 400,
|
|
102
|
-
message: "Illegal Argument"
|
|
103
|
-
});
|
|
104
|
-
export var InvalidType = create({
|
|
105
|
-
status: 400,
|
|
106
|
-
message: "Invalid Type"
|
|
107
|
-
});
|
|
108
|
-
// known errors
|
|
109
|
-
// TypeError when an operation could not be performed, typically (but not exclusively) when a value is not of the expected type.
|
|
110
|
-
// RangeError when a number is not within the correct range allowed.
|
|
111
|
-
// AggregateError when multiple errors need to be reported by an operation, for example by Promise.all().
|
|
112
|
-
// 例如 Promise.any() 会返回一个 AggregateError,其中包含所有 rejected 的 Promise 的错误。
|
|
113
|
-
// EvalError when an error occurs during the evaluation of JavaScript code.
|
|
114
|
-
// ReferenceError when a non-existent variable is referenced.
|
|
115
|
-
// SyntaxError when a syntax error occurs while parsing code in eval().
|
|
116
|
-
// URIError when encodeURI() or decodeURI() are passed invalid parameters.
|
|
117
|
-
// InternalError when an internal error in the JavaScript engine is thrown. E.g. "too much recursion".
|
|
118
|
-
// DOMException when an error occurs in the DOM.
|
|
119
|
-
export var resolvers = [];
|
|
120
|
-
export function create(init) {
|
|
121
|
-
return new DetailHolder(init);
|
|
122
|
-
}
|
|
123
|
-
export function ok(res, o) {
|
|
124
|
-
if (res.ok) {
|
|
125
|
-
return res;
|
|
126
|
-
}
|
|
127
|
-
throw create(_object_spread_props(_object_spread({
|
|
128
|
-
description: res.statusText,
|
|
129
|
-
status: res.status
|
|
130
|
-
}, o), {
|
|
131
|
-
metadata: _object_spread_props(_object_spread({}, o === null || o === void 0 ? void 0 : o.metadata), {
|
|
132
|
-
response: res
|
|
133
|
-
})
|
|
134
|
-
})).asError();
|
|
135
|
-
}
|
|
136
|
-
export function resolve(e) {
|
|
137
|
-
if (_instanceof(e, DetailHolder)) {
|
|
138
|
-
return e;
|
|
139
|
-
}
|
|
140
|
-
if (_instanceof(e, DetailError)) {
|
|
141
|
-
return e.detail;
|
|
142
|
-
}
|
|
143
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
144
|
-
try {
|
|
145
|
-
for (var _iterator = resolvers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
146
|
-
var resolver = _step.value;
|
|
147
|
-
var r = resolver(e);
|
|
148
|
-
if (r) {
|
|
149
|
-
return r;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
catch (err) {
|
|
154
|
-
_didIteratorError = true;
|
|
155
|
-
_iteratorError = err;
|
|
156
|
-
}
|
|
157
|
-
finally {
|
|
158
|
-
try {
|
|
159
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
160
|
-
_iterator.return();
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
finally {
|
|
164
|
-
if (_didIteratorError) {
|
|
165
|
-
throw _iteratorError;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
if (isError(e)) {
|
|
170
|
-
var message = e.message, code = e.code, status = e.status;
|
|
171
|
-
// can get status from NestJS HttpException
|
|
172
|
-
return new DetailHolder({
|
|
173
|
-
message: message,
|
|
174
|
-
status: parseInt(status) || 500,
|
|
175
|
-
code: code,
|
|
176
|
-
cause: e
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
return new DetailHolder({
|
|
180
|
-
message: e.message,
|
|
181
|
-
status: 500,
|
|
182
|
-
cause: e
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Check if the given value is an Error
|
|
187
|
-
* @see https://github.com/tc39/proposal-is-error
|
|
188
|
-
*/ export function isError(e) {
|
|
189
|
-
if ("isError" in Error) {
|
|
190
|
-
// will handle cross-realm
|
|
191
|
-
return Error.isError(e);
|
|
192
|
-
}
|
|
193
|
-
return _instanceof(e, Error);
|
|
194
|
-
}
|
|
195
|
-
export function isAbort(e) {
|
|
196
|
-
if (!isError(e)) {
|
|
197
|
-
return false;
|
|
198
|
-
}
|
|
199
|
-
return e.name === "AbortError";
|
|
200
|
-
}
|
|
201
|
-
export function isTimeout(e) {
|
|
202
|
-
if (!isError(e)) {
|
|
203
|
-
return false;
|
|
204
|
-
}
|
|
205
|
-
return e.name === "TimeoutError" || e.name === "Timeout";
|
|
206
|
-
}
|