@wener/common 1.0.5 → 2.0.1
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/cn/DivisionCode.js +55 -32
- package/lib/cn/DivisionCode.test.js +140 -0
- package/lib/cn/Mod11Checksum.js +80 -37
- package/lib/cn/Mod31Checksum.js +89 -40
- package/lib/cn/ResidentIdentityCardNumber.js +16 -16
- package/lib/cn/ResidentIdentityCardNumber.test.js +21 -0
- package/lib/cn/UnifiedSocialCreditCode.js +32 -26
- package/lib/cn/UnifiedSocialCreditCode.test.js +16 -0
- package/lib/cn/formatDate.js +5 -7
- package/lib/cn/index.js +0 -1
- package/lib/cn/parseSex.js +0 -2
- package/lib/cn/types.d.js +0 -2
- package/lib/consola/createStandardConsolaReporter.js +6 -6
- package/lib/consola/formatLogObject.js +133 -32
- package/lib/consola/index.js +0 -1
- package/lib/data/formatSort.js +5 -6
- package/lib/data/formatSort.test.js +34 -0
- package/lib/data/index.js +0 -1
- package/lib/data/maybeNumber.js +11 -5
- package/lib/data/parseSort.js +28 -22
- package/lib/data/parseSort.test.js +188 -0
- package/lib/data/resolvePagination.js +27 -16
- package/lib/data/resolvePagination.test.js +232 -0
- package/lib/data/types.d.js +0 -2
- package/lib/index.js +0 -1
- package/lib/jsonschema/JsonSchema.js +78 -52
- package/lib/jsonschema/JsonSchema.test.js +137 -0
- package/lib/jsonschema/index.js +0 -1
- package/lib/jsonschema/types.d.js +5 -3
- package/lib/meta/defineFileType.js +103 -20
- package/lib/meta/defineInit.js +250 -31
- package/lib/meta/defineMetadata.js +140 -24
- package/lib/meta/defineMetadata.test.js +13 -0
- package/lib/meta/index.js +0 -1
- package/lib/password/PHC.js +87 -63
- package/lib/password/PHC.test.js +539 -0
- package/lib/password/Password.js +291 -29
- package/lib/password/Password.test.js +362 -0
- package/lib/password/createArgon2PasswordAlgorithm.js +191 -35
- package/lib/password/createBase64PasswordAlgorithm.js +141 -8
- package/lib/password/createBcryptPasswordAlgorithm.js +168 -13
- package/lib/password/createPBKDF2PasswordAlgorithm.js +228 -46
- package/lib/password/createScryptPasswordAlgorithm.js +211 -55
- package/lib/password/index.js +0 -1
- package/lib/password/server/index.js +0 -1
- package/lib/resource/Identifiable.js +1 -0
- package/lib/resource/getTitleOfResource.js +10 -0
- package/lib/resource/index.js +1 -0
- package/lib/resource/schema/AnyResourceSchema.js +89 -0
- package/lib/resource/schema/BaseResourceSchema.js +29 -0
- package/lib/resource/schema/ResourceActionType.js +118 -0
- package/lib/resource/schema/ResourceStatus.js +93 -0
- package/lib/resource/schema/ResourceType.js +24 -0
- package/lib/resource/schema/SchemaRegistry.js +38 -0
- package/lib/resource/schema/SexType.js +10 -0
- package/lib/resource/schema/types.js +89 -0
- package/lib/resource/schema/types.test.js +14 -0
- package/lib/schema/TypeSchema.d.js +1 -0
- package/lib/schema/createSchemaData.js +173 -0
- package/lib/schema/findJsonSchemaByPath.js +49 -0
- package/lib/schema/getSchemaCache.js +11 -0
- package/lib/schema/getSchemaOptions.js +24 -0
- package/lib/schema/index.js +5 -0
- package/lib/schema/toJsonSchema.js +441 -0
- package/lib/schema/toJsonSchema.test.js +27 -0
- package/lib/schema/validate.js +124 -0
- package/lib/search/AdvanceSearch.js +0 -1
- package/lib/search/AdvanceSearch.test.js +435 -0
- package/lib/search/formatAdvanceSearch.js +41 -27
- package/lib/search/index.js +0 -1
- package/lib/search/optimizeAdvanceSearch.js +79 -25
- package/lib/search/parseAdvanceSearch.js +5 -5
- package/lib/search/parser.d.js +0 -2
- package/lib/search/parser.js +97 -74
- package/lib/search/types.d.js +0 -2
- package/lib/tools/generateSchema.js +197 -39
- package/lib/tools/renderJsonSchemaToMarkdownDoc.js +143 -55
- package/package.json +23 -11
- package/src/data/maybeNumber.ts +5 -1
- package/src/data/resolvePagination.test.ts +1 -1
- package/src/data/resolvePagination.ts +18 -7
- package/src/data/types.d.ts +12 -0
- package/src/jsonschema/JsonSchema.test.ts +17 -0
- package/src/jsonschema/JsonSchema.ts +2 -2
- package/src/jsonschema/types.d.ts +63 -12
- package/src/resource/Identifiable.ts +3 -0
- package/src/resource/getTitleOfResource.tsx +6 -0
- package/src/resource/index.ts +3 -0
- package/src/resource/schema/AnyResourceSchema.ts +113 -0
- package/src/resource/schema/BaseResourceSchema.ts +32 -0
- package/src/resource/schema/ResourceActionType.ts +123 -0
- package/src/resource/schema/ResourceStatus.ts +94 -0
- package/src/resource/schema/ResourceType.ts +25 -0
- package/src/resource/schema/SchemaRegistry.ts +42 -0
- package/src/resource/schema/SexType.ts +13 -0
- package/src/resource/schema/types.test.ts +18 -0
- package/src/resource/schema/types.ts +105 -0
- package/src/schema/TypeSchema.d.ts +32 -0
- package/src/schema/createSchemaData.ts +81 -0
- package/src/schema/findJsonSchemaByPath.ts +37 -0
- package/src/schema/getSchemaCache.ts +21 -0
- package/src/schema/getSchemaOptions.ts +24 -0
- package/src/schema/index.ts +6 -0
- package/src/schema/toJsonSchema.test.ts +37 -0
- package/src/schema/toJsonSchema.ts +200 -0
- package/src/schema/validate.ts +135 -0
- package/src/tools/generateSchema.ts +28 -28
- package/lib/cn/DivisionCode.js.map +0 -1
- package/lib/cn/Mod11Checksum.js.map +0 -1
- package/lib/cn/Mod31Checksum.js.map +0 -1
- package/lib/cn/ResidentIdentityCardNumber.js.map +0 -1
- package/lib/cn/UnifiedSocialCreditCode.js.map +0 -1
- package/lib/cn/formatDate.js.map +0 -1
- package/lib/cn/index.js.map +0 -1
- package/lib/cn/parseSex.js.map +0 -1
- package/lib/cn/types.d.js.map +0 -1
- package/lib/consola/createStandardConsolaReporter.js.map +0 -1
- package/lib/consola/formatLogObject.js.map +0 -1
- package/lib/consola/index.js.map +0 -1
- package/lib/data/formatSort.js.map +0 -1
- package/lib/data/index.js.map +0 -1
- package/lib/data/maybeNumber.js.map +0 -1
- package/lib/data/parseSort.js.map +0 -1
- package/lib/data/resolvePagination.js.map +0 -1
- package/lib/data/types.d.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/jsonschema/JsonSchema.js.map +0 -1
- package/lib/jsonschema/index.js.map +0 -1
- package/lib/jsonschema/types.d.js.map +0 -1
- package/lib/meta/defineFileType.js.map +0 -1
- package/lib/meta/defineInit.js.map +0 -1
- package/lib/meta/defineMetadata.js.map +0 -1
- package/lib/meta/index.js.map +0 -1
- package/lib/password/PHC.js.map +0 -1
- package/lib/password/Password.js.map +0 -1
- package/lib/password/createArgon2PasswordAlgorithm.js.map +0 -1
- package/lib/password/createBase64PasswordAlgorithm.js.map +0 -1
- package/lib/password/createBcryptPasswordAlgorithm.js.map +0 -1
- package/lib/password/createPBKDF2PasswordAlgorithm.js.map +0 -1
- package/lib/password/createScryptPasswordAlgorithm.js.map +0 -1
- package/lib/password/index.js.map +0 -1
- package/lib/password/server/index.js.map +0 -1
- package/lib/search/AdvanceSearch.js.map +0 -1
- package/lib/search/formatAdvanceSearch.js.map +0 -1
- package/lib/search/index.js.map +0 -1
- package/lib/search/optimizeAdvanceSearch.js.map +0 -1
- package/lib/search/parseAdvanceSearch.js.map +0 -1
- package/lib/search/parser.d.js.map +0 -1
- package/lib/search/parser.js.map +0 -1
- package/lib/search/types.d.js.map +0 -1
- package/lib/tools/generateSchema.js.map +0 -1
- package/lib/tools/renderJsonSchemaToMarkdownDoc.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Mod31Checksum } from "./Mod31Checksum.js";
|
|
2
2
|
(function (UnifiedSocialCreditCode) {
|
|
3
|
-
|
|
3
|
+
var CodeLabels = {
|
|
4
4
|
1: {
|
|
5
5
|
label: "\u673A\u6784\u7F16\u5236",
|
|
6
6
|
children: {
|
|
@@ -64,41 +64,46 @@ import { Mod31Checksum } from "./Mod31Checksum.js";
|
|
|
64
64
|
UnifiedSocialCreditCode.pattern = /^([159][1239]|Y1)[0-9]{6}[0-9A-HJ-NP-RTUWXY]{10}$/; // 无 I O Z S V
|
|
65
65
|
UnifiedSocialCreditCode.Checksum = new Mod31Checksum();
|
|
66
66
|
function parse(s) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
l1
|
|
75
|
-
|
|
76
|
-
l2
|
|
67
|
+
var _l1_children;
|
|
68
|
+
var bureau = s[0];
|
|
69
|
+
var subjectType = s[1];
|
|
70
|
+
var division = s.slice(2, 8); // 第3~8位,共6位,正确
|
|
71
|
+
var subject = s.slice(8, 17); // 第9~17位,共9位
|
|
72
|
+
var checksum = s.slice(17, 18); // 第18位,校验码
|
|
73
|
+
var labels = [];
|
|
74
|
+
var l1 = CodeLabels[bureau];
|
|
75
|
+
l1 && labels.push(l1 === null || l1 === void 0 ? void 0 : l1.label);
|
|
76
|
+
var l2 = l1 === null || l1 === void 0 ? void 0 : (_l1_children = l1.children) === null || _l1_children === void 0 ? void 0 : _l1_children[subjectType];
|
|
77
|
+
l2 && labels.push(l2 === null || l2 === void 0 ? void 0 : l2.label);
|
|
77
78
|
return {
|
|
78
|
-
bureau,
|
|
79
|
-
subjectType,
|
|
80
|
-
division,
|
|
81
|
-
subject,
|
|
82
|
-
checksum,
|
|
79
|
+
bureau: bureau,
|
|
80
|
+
subjectType: subjectType,
|
|
81
|
+
division: division,
|
|
82
|
+
subject: subject,
|
|
83
|
+
checksum: checksum,
|
|
83
84
|
codes: [
|
|
84
85
|
bureau,
|
|
85
86
|
subjectType,
|
|
86
87
|
division,
|
|
87
88
|
subject
|
|
88
89
|
],
|
|
89
|
-
labels
|
|
90
|
+
labels: labels
|
|
90
91
|
};
|
|
91
92
|
}
|
|
92
93
|
UnifiedSocialCreditCode.parse = parse;
|
|
93
|
-
function format(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
function format(param) {
|
|
95
|
+
var bureau = param.bureau, subjectType = param.subjectType, division = param.division, subject = param.subject, checksum = param.checksum;
|
|
96
|
+
var base = "".concat(bureau).concat(subjectType).concat(division).concat(subject);
|
|
97
|
+
checksum || (checksum = UnifiedSocialCreditCode.Checksum.compute(base));
|
|
98
|
+
return "".concat(base).concat(checksum);
|
|
97
99
|
}
|
|
98
100
|
UnifiedSocialCreditCode.format = format;
|
|
99
|
-
function next(s
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
function next(s) {
|
|
102
|
+
var delta = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1;
|
|
103
|
+
var sp = s.split("").map(function (v) {
|
|
104
|
+
return UnifiedSocialCreditCode.Checksum.numbers[v];
|
|
105
|
+
});
|
|
106
|
+
for (var i = sp.length - 1; i >= 0; i--) {
|
|
102
107
|
if (delta > 0 && sp[i] < 30 || delta < 0 && sp[i] > 0) {
|
|
103
108
|
sp[i] += delta;
|
|
104
109
|
break;
|
|
@@ -110,9 +115,10 @@ import { Mod31Checksum } from "./Mod31Checksum.js";
|
|
|
110
115
|
sp[i] = 30;
|
|
111
116
|
}
|
|
112
117
|
}
|
|
113
|
-
return sp.map((v)
|
|
118
|
+
return sp.map(function (v) {
|
|
119
|
+
return UnifiedSocialCreditCode.Checksum.chars[v];
|
|
120
|
+
}).join("");
|
|
114
121
|
}
|
|
115
122
|
UnifiedSocialCreditCode.next = next;
|
|
116
123
|
})(UnifiedSocialCreditCode || (UnifiedSocialCreditCode = {}));
|
|
117
124
|
export var UnifiedSocialCreditCode;
|
|
118
|
-
//# sourceMappingURL=UnifiedSocialCreditCode.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { UnifiedSocialCreditCode } from "./UnifiedSocialCreditCode.js";
|
|
3
|
+
describe("UnifiedSocialCreditCode", function () {
|
|
4
|
+
it("should parse", function () {
|
|
5
|
+
for (var _i = 0, _iter = [
|
|
6
|
+
//
|
|
7
|
+
"91330106673959654P",
|
|
8
|
+
"91330106MA2CFLDG4R"
|
|
9
|
+
]; _i < _iter.length; _i++) {
|
|
10
|
+
var a = _iter[_i];
|
|
11
|
+
var out = UnifiedSocialCreditCode.parse(a);
|
|
12
|
+
expect(UnifiedSocialCreditCode.format(out)).toBe(a);
|
|
13
|
+
expect(out).toMatchSnapshot();
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
package/lib/cn/formatDate.js
CHANGED
|
@@ -2,14 +2,12 @@ export function formatDate(date, format) {
|
|
|
2
2
|
switch(format){
|
|
3
3
|
case 'yyyyMMDD':
|
|
4
4
|
{
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return
|
|
5
|
+
var year = date.getFullYear();
|
|
6
|
+
var month = (date.getMonth() + 1).toString().padStart(2, '0');
|
|
7
|
+
var day = date.getDate().toString().padStart(2, '0');
|
|
8
|
+
return "".concat(year).concat(month).concat(day);
|
|
9
9
|
}
|
|
10
10
|
default:
|
|
11
|
-
throw new Error(
|
|
11
|
+
throw new Error("Invalid format");
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
//# sourceMappingURL=formatDate.js.map
|
package/lib/cn/index.js
CHANGED
package/lib/cn/parseSex.js
CHANGED
package/lib/cn/types.d.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { formatLogObject } from "./formatLogObject.js";
|
|
2
|
-
export function createStandardConsolaReporter(
|
|
2
|
+
export function createStandardConsolaReporter() {
|
|
3
|
+
var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, _ref_format = _ref.format, format = _ref_format === void 0 ? formatLogObject : _ref_format;
|
|
3
4
|
return {
|
|
4
|
-
log: (o, ctx)
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
log: function (o, ctx) {
|
|
6
|
+
var out = format(o, ctx);
|
|
7
|
+
var fn = console.log;
|
|
8
|
+
var level = o.level;
|
|
8
9
|
if (level < 1) {
|
|
9
10
|
fn = console.error;
|
|
10
11
|
}
|
|
@@ -15,4 +16,3 @@ export function createStandardConsolaReporter({ format = formatLogObject } = {})
|
|
|
15
16
|
}
|
|
16
17
|
};
|
|
17
18
|
}
|
|
18
|
-
//# sourceMappingURL=createStandardConsolaReporter.js.map
|
|
@@ -1,7 +1,93 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _array_with_holes(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return arr;
|
|
8
|
+
}
|
|
9
|
+
function _array_without_holes(arr) {
|
|
10
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
11
|
+
}
|
|
12
|
+
function _define_property(obj, key, value) {
|
|
13
|
+
if (key in obj) {
|
|
14
|
+
Object.defineProperty(obj, key, {
|
|
15
|
+
value: value,
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true
|
|
19
|
+
});
|
|
20
|
+
} else {
|
|
21
|
+
obj[key] = value;
|
|
22
|
+
}
|
|
23
|
+
return obj;
|
|
24
|
+
}
|
|
25
|
+
function _iterable_to_array(iter) {
|
|
26
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
27
|
+
}
|
|
28
|
+
function _non_iterable_rest() {
|
|
29
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
30
|
+
}
|
|
31
|
+
function _non_iterable_spread() {
|
|
32
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
33
|
+
}
|
|
34
|
+
function _object_spread(target) {
|
|
35
|
+
for(var i = 1; i < arguments.length; i++){
|
|
36
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
37
|
+
var ownKeys = Object.keys(source);
|
|
38
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
39
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
40
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
ownKeys.forEach(function(key) {
|
|
44
|
+
_define_property(target, key, source[key]);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return target;
|
|
48
|
+
}
|
|
49
|
+
function ownKeys(object, enumerableOnly) {
|
|
50
|
+
var keys = Object.keys(object);
|
|
51
|
+
if (Object.getOwnPropertySymbols) {
|
|
52
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
53
|
+
if (enumerableOnly) {
|
|
54
|
+
symbols = symbols.filter(function(sym) {
|
|
55
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
keys.push.apply(keys, symbols);
|
|
59
|
+
}
|
|
60
|
+
return keys;
|
|
61
|
+
}
|
|
62
|
+
function _object_spread_props(target, source) {
|
|
63
|
+
source = source != null ? source : {};
|
|
64
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
65
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
66
|
+
} else {
|
|
67
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
68
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return target;
|
|
72
|
+
}
|
|
73
|
+
function _to_array(arr) {
|
|
74
|
+
return _array_with_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_rest();
|
|
75
|
+
}
|
|
76
|
+
function _to_consumable_array(arr) {
|
|
77
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
78
|
+
}
|
|
79
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
80
|
+
if (!o) return;
|
|
81
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
82
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
83
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
84
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
85
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
86
|
+
}
|
|
87
|
+
import colors from 'chalk';
|
|
88
|
+
import dayjs from 'dayjs';
|
|
89
|
+
import { isDevelopment } from 'std-env';
|
|
90
|
+
var levelColors = {
|
|
5
91
|
trace: colors.gray,
|
|
6
92
|
debug: colors.cyan,
|
|
7
93
|
info: colors.blueBright,
|
|
@@ -17,7 +103,7 @@ const levelColors = {
|
|
|
17
103
|
box: colors.white,
|
|
18
104
|
verbose: colors.green
|
|
19
105
|
};
|
|
20
|
-
|
|
106
|
+
var levelShort = {
|
|
21
107
|
trace: 'TRAC',
|
|
22
108
|
debug: 'DEBG',
|
|
23
109
|
info: 'INFO',
|
|
@@ -33,18 +119,18 @@ const levelShort = {
|
|
|
33
119
|
box: 'BOX ',
|
|
34
120
|
verbose: 'VERB'
|
|
35
121
|
};
|
|
36
|
-
|
|
122
|
+
var start = Date.now();
|
|
37
123
|
export function formatLogObject(o, ctx) {
|
|
38
|
-
|
|
124
|
+
var date = o.date, type = o.type, tag = o.tag;
|
|
39
125
|
type = type === 'log' ? 'info' : type;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
126
|
+
var color = levelColors[type] || colors.white;
|
|
127
|
+
var levelText = levelShort[type] || type.toUpperCase().slice(0, 4); // Get first 4 chars, consistent uppercase
|
|
128
|
+
var line = '';
|
|
129
|
+
var out = [];
|
|
44
130
|
// Timestamp
|
|
45
131
|
if (isDevelopment) {
|
|
46
132
|
// process.hrtime.bigint()
|
|
47
|
-
|
|
133
|
+
var diff = (date.getTime() - start) / 1000;
|
|
48
134
|
out.push(colors.gray(diff.toFixed(3).padStart(7, ' ')));
|
|
49
135
|
} else {
|
|
50
136
|
out.push(colors.gray(dayjs(date).format('YYYY-MM-DD HH:mm:ss.SSS')));
|
|
@@ -53,17 +139,17 @@ export function formatLogObject(o, ctx) {
|
|
|
53
139
|
// Pad to 4 characters
|
|
54
140
|
out.push(color(levelText.padEnd(4, ' ')));
|
|
55
141
|
if (tag) {
|
|
56
|
-
out.push(colors.yellow(
|
|
142
|
+
out.push(colors.yellow("[".concat(tag, "]"))); // Added color for tag
|
|
57
143
|
}
|
|
58
144
|
{
|
|
59
|
-
|
|
145
|
+
var _formatArgs_split = _to_array(formatArgs(o.args, ctx).split('\n')), message = _formatArgs_split[0], additional = _formatArgs_split.slice(1);
|
|
60
146
|
out.push(characterFormat(message));
|
|
61
147
|
line = out.join(' ');
|
|
62
148
|
if (additional.length > 0) {
|
|
63
149
|
line += characterFormat(additional.join('\n'));
|
|
64
150
|
}
|
|
65
151
|
if (type === 'trace') {
|
|
66
|
-
|
|
152
|
+
var _err = new Error('Trace: ' + o.message);
|
|
67
153
|
line += formatStack(_err.stack || '', _err.message);
|
|
68
154
|
}
|
|
69
155
|
}
|
|
@@ -83,20 +169,32 @@ export function formatLogObject(o, ctx) {
|
|
|
83
169
|
}
|
|
84
170
|
function characterFormat(str) {
|
|
85
171
|
return str// highlight backticks
|
|
86
|
-
.replace(/`([^`]+)`/gm, (_, m)
|
|
87
|
-
|
|
172
|
+
.replace(/`([^`]+)`/gm, function(_, m) {
|
|
173
|
+
return colors.cyan(m);
|
|
174
|
+
})// underline underscores
|
|
175
|
+
.replace(/\s+_([^_]+)_\s+/gm, function(_, m) {
|
|
176
|
+
return " ".concat(colors.underline(m), " ");
|
|
177
|
+
});
|
|
88
178
|
}
|
|
89
179
|
function parseStack(stack, message) {
|
|
90
180
|
// const cwd = process.cwd() + sep;
|
|
91
|
-
|
|
181
|
+
var lines = stack.split('\n').splice(message.split('\n').length).map(function(l) {
|
|
182
|
+
return l.trim().replace('file://', '');
|
|
183
|
+
});
|
|
92
184
|
return lines;
|
|
93
185
|
}
|
|
94
186
|
function formatStack(stack, message, opts) {
|
|
95
|
-
|
|
96
|
-
return
|
|
187
|
+
var indent = ' '.repeat(((opts === null || opts === void 0 ? void 0 : opts.errorLevel) || 0) + 1);
|
|
188
|
+
return "\n".concat(indent) + parseStack(stack, message).map(function(line) {
|
|
189
|
+
return ' ' + line.replace(/^at +/, function(m) {
|
|
190
|
+
return colors.gray(m);
|
|
191
|
+
}).replace(/\((.+)\)/, function(_, m) {
|
|
192
|
+
return "(".concat(colors.cyan(m), ")");
|
|
193
|
+
});
|
|
194
|
+
}).join("\n".concat(indent));
|
|
97
195
|
}
|
|
98
196
|
function formatArgs(args, opts) {
|
|
99
|
-
|
|
197
|
+
var _args = args.map(function(arg) {
|
|
100
198
|
if (arg && typeof arg.stack === 'string') {
|
|
101
199
|
return formatError(arg, opts);
|
|
102
200
|
}
|
|
@@ -104,22 +202,25 @@ function formatArgs(args, opts) {
|
|
|
104
202
|
});
|
|
105
203
|
// Only supported with Node >= 10
|
|
106
204
|
// https://nodejs.org/api/util.html#util_util_inspect_object_options
|
|
107
|
-
return formatWithOptions(
|
|
205
|
+
return formatWithOptions.apply(void 0, [
|
|
206
|
+
opts
|
|
207
|
+
].concat(_to_consumable_array(_args)));
|
|
108
208
|
}
|
|
109
|
-
function formatWithOptions(o
|
|
209
|
+
function formatWithOptions(o) {
|
|
210
|
+
for(var _len = arguments.length, params = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
|
|
211
|
+
params[_key - 1] = arguments[_key];
|
|
212
|
+
}
|
|
110
213
|
// import { formatWithOptions } from 'node:util';
|
|
111
214
|
return params.join(' ');
|
|
112
215
|
}
|
|
113
216
|
function formatError(err, opts) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
217
|
+
var _err_message;
|
|
218
|
+
var message = (_err_message = err.message) !== null && _err_message !== void 0 ? _err_message : formatWithOptions(opts, err);
|
|
219
|
+
var stack = err.stack ? formatStack(err.stack, message, opts) : '';
|
|
220
|
+
var level = (opts === null || opts === void 0 ? void 0 : opts.errorLevel) || 0;
|
|
221
|
+
var causedPrefix = level > 0 ? "".concat(' '.repeat(level), "[cause]: ") : '';
|
|
222
|
+
var causedError = err.cause ? '\n\n' + formatError(err.cause, _object_spread_props(_object_spread({}, opts), {
|
|
120
223
|
errorLevel: level + 1
|
|
121
|
-
}) : '';
|
|
224
|
+
})) : '';
|
|
122
225
|
return causedPrefix + message + '\n' + stack + causedError;
|
|
123
226
|
}
|
|
124
|
-
|
|
125
|
-
//# sourceMappingURL=formatLogObject.js.map
|
package/lib/consola/index.js
CHANGED
package/lib/data/formatSort.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
export function formatSort(s) {
|
|
2
|
-
return s.map((
|
|
2
|
+
return s.map(function(param) {
|
|
3
|
+
var field = param.field, order = param.order, nulls = param.nulls;
|
|
3
4
|
if (!field) return '';
|
|
4
|
-
|
|
5
|
+
var r = field;
|
|
5
6
|
if (order) {
|
|
6
|
-
r +=
|
|
7
|
+
r += " ".concat(order);
|
|
7
8
|
}
|
|
8
9
|
if (nulls) {
|
|
9
|
-
r +=
|
|
10
|
+
r += " nulls ".concat(nulls);
|
|
10
11
|
}
|
|
11
12
|
return r;
|
|
12
13
|
}).filter(Boolean);
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
-
//# sourceMappingURL=formatSort.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { formatSort } from "./formatSort.js";
|
|
3
|
+
test("formatSort", function () {
|
|
4
|
+
expect(formatSort([
|
|
5
|
+
{
|
|
6
|
+
field: "name",
|
|
7
|
+
order: "asc"
|
|
8
|
+
}
|
|
9
|
+
])).toEqual([
|
|
10
|
+
"name asc"
|
|
11
|
+
]);
|
|
12
|
+
expect(formatSort([
|
|
13
|
+
{
|
|
14
|
+
field: "age",
|
|
15
|
+
order: "desc",
|
|
16
|
+
nulls: "last"
|
|
17
|
+
}
|
|
18
|
+
])).toEqual([
|
|
19
|
+
"age desc nulls last"
|
|
20
|
+
]);
|
|
21
|
+
expect(formatSort([
|
|
22
|
+
{
|
|
23
|
+
field: "name",
|
|
24
|
+
order: "asc"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
field: "age",
|
|
28
|
+
order: "desc"
|
|
29
|
+
}
|
|
30
|
+
])).toEqual([
|
|
31
|
+
"name asc",
|
|
32
|
+
"age desc"
|
|
33
|
+
]);
|
|
34
|
+
});
|
package/lib/data/index.js
CHANGED
package/lib/data/maybeNumber.js
CHANGED
|
@@ -1,22 +1,28 @@
|
|
|
1
|
+
function _type_of(obj) {
|
|
2
|
+
"@swc/helpers - typeof";
|
|
3
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
4
|
+
}
|
|
1
5
|
export function maybeNumber(v) {
|
|
2
6
|
if (v === null || v === undefined) {
|
|
3
7
|
return undefined;
|
|
4
8
|
}
|
|
5
|
-
switch(typeof v){
|
|
9
|
+
switch(typeof v === "undefined" ? "undefined" : _type_of(v)){
|
|
6
10
|
case 'number':
|
|
7
11
|
return v;
|
|
8
12
|
case 'bigint':
|
|
13
|
+
if (v > BigInt(Number.MAX_SAFE_INTEGER) || v < BigInt(Number.MIN_SAFE_INTEGER)) {
|
|
14
|
+
throw new Error("bigint out of range");
|
|
15
|
+
}
|
|
9
16
|
return Number(v);
|
|
10
17
|
case 'string':
|
|
11
|
-
|
|
18
|
+
v = v.trim();
|
|
19
|
+
if (!v) {
|
|
12
20
|
return undefined;
|
|
13
21
|
}
|
|
14
22
|
}
|
|
15
|
-
|
|
23
|
+
var n = Number(v);
|
|
16
24
|
if (isNaN(n)) {
|
|
17
25
|
return undefined;
|
|
18
26
|
}
|
|
19
27
|
return n;
|
|
20
28
|
}
|
|
21
|
-
|
|
22
|
-
//# sourceMappingURL=maybeNumber.js.map
|
package/lib/data/parseSort.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
function _type_of(obj) {
|
|
2
|
+
"@swc/helpers - typeof";
|
|
3
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
4
|
+
}
|
|
5
|
+
import { arrayOfMaybeArray } from '@wener/utils';
|
|
2
6
|
/**
|
|
3
7
|
* Parses various format of sort specifications into standardized SortRule objects
|
|
4
8
|
*
|
|
@@ -17,13 +21,13 @@ import { arrayOfMaybeArray } from "@wener/utils";
|
|
|
17
21
|
if (!order) {
|
|
18
22
|
return [];
|
|
19
23
|
}
|
|
20
|
-
return arrayOfMaybeArray(order).flatMap((v)
|
|
24
|
+
return arrayOfMaybeArray(order).flatMap(function(v) {
|
|
21
25
|
if (!v) return [];
|
|
22
|
-
if (typeof v === 'object') {
|
|
26
|
+
if ((typeof v === "undefined" ? "undefined" : _type_of(v)) === 'object') {
|
|
23
27
|
if (!v.field) {
|
|
24
28
|
return [];
|
|
25
29
|
}
|
|
26
|
-
|
|
30
|
+
var rule = {
|
|
27
31
|
field: v.field,
|
|
28
32
|
order: normalizeOrder(v.order)
|
|
29
33
|
};
|
|
@@ -32,26 +36,28 @@ import { arrayOfMaybeArray } from "@wener/utils";
|
|
|
32
36
|
}
|
|
33
37
|
return rule;
|
|
34
38
|
}
|
|
35
|
-
return v.split(',').map((v)
|
|
39
|
+
return v.split(',').map(function(v) {
|
|
40
|
+
return v.trim();
|
|
41
|
+
}).filter(Boolean).map(_parse);
|
|
36
42
|
});
|
|
37
43
|
}
|
|
38
44
|
/**
|
|
39
45
|
* Normalizes order values to 'asc' or 'desc'
|
|
40
46
|
*/ function normalizeOrder(order) {
|
|
41
|
-
return order
|
|
47
|
+
return (order === null || order === void 0 ? void 0 : order.toLowerCase()) === 'asc' ? 'asc' : 'desc';
|
|
42
48
|
}
|
|
43
49
|
/**
|
|
44
50
|
* Normalizes nulls values to 'last' or 'first'
|
|
45
51
|
*/ function normalizeNulls(nulls) {
|
|
46
|
-
return nulls
|
|
52
|
+
return (nulls === null || nulls === void 0 ? void 0 : nulls.toLowerCase()) === 'last' ? 'last' : 'first';
|
|
47
53
|
}
|
|
48
54
|
function _parse(v) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
55
|
+
var sp = v.split(/\s+/);
|
|
56
|
+
var field = '';
|
|
57
|
+
var order;
|
|
58
|
+
var nulls;
|
|
53
59
|
// Handle first token which should be the field name (possibly with +/- prefix)
|
|
54
|
-
|
|
60
|
+
var f = sp.shift();
|
|
55
61
|
if (!f) return {
|
|
56
62
|
field: '',
|
|
57
63
|
order: 'asc'
|
|
@@ -64,7 +70,8 @@ function _parse(v) {
|
|
|
64
70
|
}
|
|
65
71
|
// Process remaining tokens
|
|
66
72
|
while(sp.length > 0){
|
|
67
|
-
|
|
73
|
+
var _sp_shift_trim, _sp_shift;
|
|
74
|
+
var token = (_sp_shift = sp.shift()) === null || _sp_shift === void 0 ? void 0 : (_sp_shift_trim = _sp_shift.trim()) === null || _sp_shift_trim === void 0 ? void 0 : _sp_shift_trim.toLowerCase();
|
|
68
75
|
if (!token) continue;
|
|
69
76
|
switch(token){
|
|
70
77
|
case 'asc':
|
|
@@ -72,7 +79,8 @@ function _parse(v) {
|
|
|
72
79
|
order = token;
|
|
73
80
|
break;
|
|
74
81
|
case 'nulls':
|
|
75
|
-
|
|
82
|
+
var _sp_shift_trim1, _sp_shift1;
|
|
83
|
+
nulls = ((_sp_shift1 = sp.shift()) === null || _sp_shift1 === void 0 ? void 0 : (_sp_shift_trim1 = _sp_shift1.trim()) === null || _sp_shift_trim1 === void 0 ? void 0 : _sp_shift_trim1.toLowerCase()) === 'last' ? 'last' : 'first';
|
|
76
84
|
break;
|
|
77
85
|
case 'last':
|
|
78
86
|
case 'first':
|
|
@@ -80,16 +88,14 @@ function _parse(v) {
|
|
|
80
88
|
break;
|
|
81
89
|
}
|
|
82
90
|
}
|
|
83
|
-
order
|
|
91
|
+
order || (order = 'asc');
|
|
84
92
|
// Only include nulls if specified
|
|
85
93
|
return nulls ? {
|
|
86
|
-
field,
|
|
87
|
-
order,
|
|
88
|
-
nulls
|
|
94
|
+
field: field,
|
|
95
|
+
order: order,
|
|
96
|
+
nulls: nulls
|
|
89
97
|
} : {
|
|
90
|
-
field,
|
|
91
|
-
order
|
|
98
|
+
field: field,
|
|
99
|
+
order: order
|
|
92
100
|
};
|
|
93
101
|
}
|
|
94
|
-
|
|
95
|
-
//# sourceMappingURL=parseSort.js.map
|