@wener/common 1.0.5 → 2.0.2
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/ChineseResidentIdNo.js +41 -0
- package/lib/cn/ChineseResidentIdNo.mod.js +1 -0
- package/lib/cn/ChineseResidentIdNo.test.js +22 -0
- package/lib/cn/DivisionCode.js +214 -280
- package/lib/cn/DivisionCode.mod.js +1 -0
- package/lib/cn/DivisionCode.test.js +134 -0
- package/lib/cn/Mod11.js +86 -0
- package/lib/cn/Mod31.js +98 -0
- package/lib/cn/UnifiedSocialCreditCode.js +130 -109
- package/lib/cn/UnifiedSocialCreditCode.mod.js +1 -0
- package/lib/cn/UnifiedSocialCreditCode.test.js +16 -0
- package/lib/cn/index.js +1 -4
- package/lib/cn/mod.js +6 -0
- package/lib/cn/types.d.js +0 -2
- package/lib/consola/createStandardConsolaReporter.js +6 -6
- package/lib/consola/formatLogObject.js +147 -34
- 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/dayjs/dayjs.js +38 -0
- package/lib/dayjs/formatDuration.js +58 -0
- package/lib/dayjs/formatDuration.test.js +90 -0
- package/lib/dayjs/index.js +3 -0
- package/lib/dayjs/parseDuration.js +32 -0
- package/lib/decimal/index.js +1 -0
- package/lib/decimal/parseDecimal.js +13 -0
- package/lib/foundation/schema/SexType.js +14 -0
- package/lib/foundation/schema/index.js +1 -0
- package/lib/foundation/schema/parseSexType.js +18 -0
- package/lib/foundation/schema/types.js +5 -0
- 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 +295 -30
- 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/ListQuery.js +119 -0
- package/lib/resource/getTitleOfResource.js +10 -0
- package/lib/resource/index.js +2 -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/index.js +5 -0
- package/lib/resource/schema/types.js +89 -0
- package/lib/resource/schema/types.test.js +14 -0
- package/lib/schema/SchemaRegistry.js +45 -0
- package/lib/schema/SchemaRegistry.mod.js +2 -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 +6 -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/tools/generateSchema.js +197 -39
- package/lib/tools/renderJsonSchemaToMarkdownDoc.js +143 -55
- package/lib/utils/getEstimateProcessTime.js +20 -0
- package/lib/utils/index.js +1 -0
- package/package.json +38 -17
- package/src/cn/ChineseResidentIdNo.mod.ts +7 -0
- package/src/cn/ChineseResidentIdNo.test.ts +18 -0
- package/src/cn/ChineseResidentIdNo.ts +66 -0
- package/src/cn/DivisionCode.mod.ts +7 -0
- package/src/cn/DivisionCode.test.ts +3 -13
- package/src/cn/DivisionCode.ts +132 -195
- package/src/cn/{Mod11Checksum.ts → Mod11.ts} +3 -1
- package/src/cn/{Mod31Checksum.ts → Mod31.ts} +2 -0
- package/src/cn/UnifiedSocialCreditCode.mod.ts +7 -0
- package/src/cn/UnifiedSocialCreditCode.test.ts +2 -2
- package/src/cn/UnifiedSocialCreditCode.ts +105 -125
- package/src/cn/__snapshots__/ChineseResidentIdNo.test.ts.snap +14 -0
- package/src/cn/__snapshots__/UnifiedSocialCreditCode.test.ts.snap +18 -12
- package/src/cn/index.ts +1 -3
- package/src/cn/mod.ts +3 -0
- package/src/consola/formatLogObject.ts +12 -4
- 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/dayjs/dayjs.ts +40 -0
- package/src/dayjs/formatDuration.test.ts +14 -0
- package/src/dayjs/formatDuration.ts +86 -0
- package/src/dayjs/index.ts +3 -0
- package/src/dayjs/parseDuration.ts +40 -0
- package/src/decimal/index.ts +1 -0
- package/src/decimal/parseDecimal.ts +16 -0
- package/src/foundation/schema/SexType.ts +21 -0
- package/src/foundation/schema/index.ts +1 -0
- package/src/foundation/schema/parseSexType.ts +19 -0
- package/src/foundation/schema/types.ts +8 -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/password/Password.ts +2 -2
- package/src/resource/Identifiable.ts +3 -0
- package/src/resource/ListQuery.ts +53 -0
- package/src/resource/getTitleOfResource.tsx +6 -0
- package/src/resource/index.ts +4 -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/index.ts +5 -0
- package/src/resource/schema/types.test.ts +18 -0
- package/src/resource/schema/types.ts +105 -0
- package/src/schema/SchemaRegistry.mod.ts +1 -0
- package/src/schema/SchemaRegistry.ts +46 -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 +7 -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/src/utils/getEstimateProcessTime.ts +36 -0
- package/src/utils/index.ts +1 -0
- package/lib/cn/DivisionCode.js.map +0 -1
- package/lib/cn/Mod11Checksum.js +0 -42
- package/lib/cn/Mod11Checksum.js.map +0 -1
- package/lib/cn/Mod31Checksum.js +0 -48
- package/lib/cn/Mod31Checksum.js.map +0 -1
- package/lib/cn/ResidentIdentityCardNumber.js +0 -50
- package/lib/cn/ResidentIdentityCardNumber.js.map +0 -1
- package/lib/cn/UnifiedSocialCreditCode.js.map +0 -1
- package/lib/cn/formatDate.js +0 -15
- package/lib/cn/formatDate.js.map +0 -1
- package/lib/cn/index.js.map +0 -1
- package/lib/cn/parseSex.js +0 -22
- 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 +0 -10
- package/lib/search/AdvanceSearch.js.map +0 -1
- package/lib/search/formatAdvanceSearch.js +0 -64
- package/lib/search/formatAdvanceSearch.js.map +0 -1
- package/lib/search/index.js +0 -2
- package/lib/search/index.js.map +0 -1
- package/lib/search/optimizeAdvanceSearch.js +0 -89
- package/lib/search/optimizeAdvanceSearch.js.map +0 -1
- package/lib/search/parseAdvanceSearch.js +0 -20
- package/lib/search/parseAdvanceSearch.js.map +0 -1
- package/lib/search/parser.d.js +0 -3
- package/lib/search/parser.d.js.map +0 -1
- package/lib/search/parser.js +0 -3065
- package/lib/search/parser.js.map +0 -1
- package/lib/search/types.d.js +0 -3
- 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
- package/src/cn/ResidentIdentityCardNumber.test.ts +0 -17
- package/src/cn/ResidentIdentityCardNumber.ts +0 -96
- package/src/cn/__snapshots__/ResidentIdentityCardNumber.test.ts.snap +0 -15
- package/src/cn/formatDate.ts +0 -12
- package/src/cn/parseSex.ts +0 -13
- package/src/search/AdvanceSearch.test.ts +0 -149
- package/src/search/AdvanceSearch.ts +0 -14
- package/src/search/Makefile +0 -2
- package/src/search/__snapshots__/AdvanceSearch.test.ts.snap +0 -675
- package/src/search/formatAdvanceSearch.ts +0 -52
- package/src/search/index.ts +0 -1
- package/src/search/optimizeAdvanceSearch.ts +0 -77
- package/src/search/parseAdvanceSearch.ts +0 -23
- package/src/search/parser.d.ts +0 -8
- package/src/search/parser.js +0 -2794
- package/src/search/parser.peggy +0 -237
- package/src/search/types.d.ts +0 -45
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { maybeFunction } from "@wener/utils";
|
|
2
|
-
import {
|
|
2
|
+
import { mapValues, omitBy, pick } from "es-toolkit";
|
|
3
3
|
import { maybeNumber } from "./maybeNumber.js";
|
|
4
|
-
export function resolvePagination(page
|
|
5
|
-
|
|
4
|
+
export function resolvePagination(page) {
|
|
5
|
+
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
6
|
+
var out = omitBy(mapValues(//
|
|
6
7
|
pick(page, [
|
|
7
8
|
"limit",
|
|
8
9
|
"offset",
|
|
@@ -10,27 +11,37 @@ export function resolvePagination(page, options = {}) {
|
|
|
10
11
|
"pageNumber",
|
|
11
12
|
"pageIndex"
|
|
12
13
|
]), // to Number
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
function (v) {
|
|
15
|
+
return maybeNumber(v);
|
|
16
|
+
}), function (v) {
|
|
17
|
+
return v === undefined || v === null;
|
|
18
|
+
});
|
|
19
|
+
var pageSize = out.pageSize;
|
|
15
20
|
if (options.pageSize) {
|
|
16
21
|
pageSize = maybeFunction(options.pageSize, pageSize);
|
|
17
22
|
}
|
|
18
|
-
pageSize
|
|
19
|
-
|
|
20
|
-
let { pageNumber = 1, pageIndex, limit, offset } = out;
|
|
23
|
+
pageSize !== null && pageSize !== void 0 ? pageSize : pageSize = resolvePagination.pageSize;
|
|
24
|
+
var _out_pageNumber = out.pageNumber, pageNumber = _out_pageNumber === void 0 ? 1 : _out_pageNumber, pageIndex = out.pageIndex;
|
|
21
25
|
// page index over page number
|
|
22
26
|
pageNumber = Math.max(pageNumber, 1);
|
|
23
|
-
pageIndex = Math.max(pageIndex
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
pageIndex = Math.max(pageIndex !== null && pageIndex !== void 0 ? pageIndex : pageNumber - 1, 0);
|
|
28
|
+
var _out_limit = out.limit, limit = _out_limit === void 0 ? pageSize : _out_limit, _out_offset = out.offset, offset = _out_offset === void 0 ? pageSize * pageIndex : _out_offset;
|
|
29
|
+
limit = Math.max(1, limit);
|
|
30
|
+
offset = Math.max(0, offset);
|
|
31
|
+
if (options.maxLimit) {
|
|
32
|
+
limit = Math.min(limit, options.maxLimit);
|
|
33
|
+
}
|
|
34
|
+
if (options.maxOffset) {
|
|
35
|
+
offset = Math.min(offset, options.maxOffset);
|
|
36
|
+
}
|
|
26
37
|
pageSize = limit;
|
|
27
38
|
pageIndex = Math.floor(offset / pageSize);
|
|
28
39
|
return {
|
|
29
|
-
limit,
|
|
30
|
-
offset,
|
|
31
|
-
pageSize,
|
|
40
|
+
limit: limit,
|
|
41
|
+
offset: offset,
|
|
42
|
+
pageSize: pageSize,
|
|
32
43
|
pageNumber: pageIndex + 1,
|
|
33
|
-
pageIndex
|
|
44
|
+
pageIndex: pageIndex
|
|
34
45
|
};
|
|
35
46
|
}
|
|
36
|
-
|
|
47
|
+
resolvePagination.pageSize = 20;
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length)
|
|
3
|
+
len = arr.length;
|
|
4
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++)
|
|
5
|
+
arr2[i] = arr[i];
|
|
6
|
+
return arr2;
|
|
7
|
+
}
|
|
8
|
+
function _array_with_holes(arr) {
|
|
9
|
+
if (Array.isArray(arr))
|
|
10
|
+
return arr;
|
|
11
|
+
}
|
|
12
|
+
function _iterable_to_array_limit(arr, i) {
|
|
13
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
14
|
+
if (_i == null)
|
|
15
|
+
return;
|
|
16
|
+
var _arr = [];
|
|
17
|
+
var _n = true;
|
|
18
|
+
var _d = false;
|
|
19
|
+
var _s, _e;
|
|
20
|
+
try {
|
|
21
|
+
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
|
|
22
|
+
_arr.push(_s.value);
|
|
23
|
+
if (i && _arr.length === i)
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
_d = true;
|
|
29
|
+
_e = err;
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
try {
|
|
33
|
+
if (!_n && _i["return"] != null)
|
|
34
|
+
_i["return"]();
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
if (_d)
|
|
38
|
+
throw _e;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return _arr;
|
|
42
|
+
}
|
|
43
|
+
function _non_iterable_rest() {
|
|
44
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
45
|
+
}
|
|
46
|
+
function _sliced_to_array(arr, i) {
|
|
47
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
48
|
+
}
|
|
49
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
50
|
+
if (!o)
|
|
51
|
+
return;
|
|
52
|
+
if (typeof o === "string")
|
|
53
|
+
return _array_like_to_array(o, minLen);
|
|
54
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
55
|
+
if (n === "Object" && o.constructor)
|
|
56
|
+
n = o.constructor.name;
|
|
57
|
+
if (n === "Map" || n === "Set")
|
|
58
|
+
return Array.from(n);
|
|
59
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
|
|
60
|
+
return _array_like_to_array(o, minLen);
|
|
61
|
+
}
|
|
62
|
+
import { expect, test } from "vitest";
|
|
63
|
+
import { resolvePagination } from "./resolvePagination.js";
|
|
64
|
+
test(resolvePagination.name, function () {
|
|
65
|
+
var testCases = [
|
|
66
|
+
[
|
|
67
|
+
"pageSize with null pageIndex",
|
|
68
|
+
{
|
|
69
|
+
pageSize: "10",
|
|
70
|
+
pageIndex: null
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
limit: 10,
|
|
74
|
+
offset: 0,
|
|
75
|
+
pageSize: 10,
|
|
76
|
+
pageNumber: 1,
|
|
77
|
+
pageIndex: 0
|
|
78
|
+
}
|
|
79
|
+
],
|
|
80
|
+
[
|
|
81
|
+
"pageSize with pageIndex",
|
|
82
|
+
{
|
|
83
|
+
pageSize: "10",
|
|
84
|
+
pageIndex: 1
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
limit: 10,
|
|
88
|
+
offset: 10,
|
|
89
|
+
pageSize: 10,
|
|
90
|
+
pageNumber: 2,
|
|
91
|
+
pageIndex: 1
|
|
92
|
+
}
|
|
93
|
+
],
|
|
94
|
+
[
|
|
95
|
+
"pageSize with pageIndex 2",
|
|
96
|
+
{
|
|
97
|
+
pageSize: "10",
|
|
98
|
+
pageIndex: 2
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
limit: 10,
|
|
102
|
+
offset: 20,
|
|
103
|
+
pageSize: 10,
|
|
104
|
+
pageNumber: 3,
|
|
105
|
+
pageIndex: 2
|
|
106
|
+
}
|
|
107
|
+
],
|
|
108
|
+
[
|
|
109
|
+
"limit with null offset",
|
|
110
|
+
{
|
|
111
|
+
limit: "10",
|
|
112
|
+
offset: null
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
limit: 10,
|
|
116
|
+
offset: 0,
|
|
117
|
+
pageSize: 10,
|
|
118
|
+
pageNumber: 1,
|
|
119
|
+
pageIndex: 0
|
|
120
|
+
}
|
|
121
|
+
],
|
|
122
|
+
[
|
|
123
|
+
"limit with offset",
|
|
124
|
+
{
|
|
125
|
+
limit: "10",
|
|
126
|
+
offset: "20"
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
limit: 10,
|
|
130
|
+
offset: 20,
|
|
131
|
+
pageSize: 10,
|
|
132
|
+
pageNumber: 3,
|
|
133
|
+
pageIndex: 2
|
|
134
|
+
}
|
|
135
|
+
],
|
|
136
|
+
[
|
|
137
|
+
"null limit with offset",
|
|
138
|
+
{
|
|
139
|
+
limit: null,
|
|
140
|
+
offset: "20"
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
limit: 20,
|
|
144
|
+
offset: 20,
|
|
145
|
+
pageSize: 20,
|
|
146
|
+
pageNumber: 2,
|
|
147
|
+
pageIndex: 1
|
|
148
|
+
}
|
|
149
|
+
],
|
|
150
|
+
[
|
|
151
|
+
"empty input",
|
|
152
|
+
{},
|
|
153
|
+
{
|
|
154
|
+
limit: 20,
|
|
155
|
+
offset: 0,
|
|
156
|
+
pageSize: 20,
|
|
157
|
+
pageNumber: 1,
|
|
158
|
+
pageIndex: 0
|
|
159
|
+
}
|
|
160
|
+
],
|
|
161
|
+
[
|
|
162
|
+
"negative values",
|
|
163
|
+
{
|
|
164
|
+
pageSize: "-5",
|
|
165
|
+
pageIndex: "-1",
|
|
166
|
+
limit: "-10",
|
|
167
|
+
offset: "-20"
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
limit: 1,
|
|
171
|
+
offset: 0,
|
|
172
|
+
pageSize: 1,
|
|
173
|
+
pageNumber: 1,
|
|
174
|
+
pageIndex: 0
|
|
175
|
+
}
|
|
176
|
+
],
|
|
177
|
+
[
|
|
178
|
+
"custom pageNumber",
|
|
179
|
+
{
|
|
180
|
+
pageNumber: 3,
|
|
181
|
+
pageSize: 15
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
limit: 15,
|
|
185
|
+
offset: 30,
|
|
186
|
+
pageSize: 15,
|
|
187
|
+
pageNumber: 3,
|
|
188
|
+
pageIndex: 2
|
|
189
|
+
}
|
|
190
|
+
]
|
|
191
|
+
];
|
|
192
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
193
|
+
try {
|
|
194
|
+
for (var _iterator = testCases[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
195
|
+
var _step_value = _sliced_to_array(_step.value, 3), description = _step_value[0], input = _step_value[1], expected = _step_value[2];
|
|
196
|
+
var result = resolvePagination(input);
|
|
197
|
+
expect(result, description).toMatchObject(expected);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
catch (err) {
|
|
201
|
+
_didIteratorError = true;
|
|
202
|
+
_iteratorError = err;
|
|
203
|
+
}
|
|
204
|
+
finally {
|
|
205
|
+
try {
|
|
206
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
207
|
+
_iterator.return();
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
finally {
|
|
211
|
+
if (_didIteratorError) {
|
|
212
|
+
throw _iteratorError;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
test("".concat(resolvePagination.name, " with options"), function () {
|
|
218
|
+
expect(resolvePagination({
|
|
219
|
+
pageSize: "200"
|
|
220
|
+
}, {
|
|
221
|
+
maxLimit: 50
|
|
222
|
+
})).toMatchObject({
|
|
223
|
+
pageSize: 50,
|
|
224
|
+
limit: 50
|
|
225
|
+
});
|
|
226
|
+
expect(resolvePagination({}, {
|
|
227
|
+
pageSize: 30
|
|
228
|
+
})).toMatchObject({
|
|
229
|
+
pageSize: 30,
|
|
230
|
+
limit: 30
|
|
231
|
+
});
|
|
232
|
+
});
|
package/lib/data/types.d.js
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import advancedFormat from 'dayjs/plugin/advancedFormat';
|
|
3
|
+
import dayOfYear from 'dayjs/plugin/dayOfYear';
|
|
4
|
+
import duration from 'dayjs/plugin/duration';
|
|
5
|
+
import isBetween from 'dayjs/plugin/isBetween';
|
|
6
|
+
import isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
|
|
7
|
+
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
|
|
8
|
+
import isToday from 'dayjs/plugin/isToday';
|
|
9
|
+
import isTomorrow from 'dayjs/plugin/isTomorrow';
|
|
10
|
+
import isYesterday from 'dayjs/plugin/isYesterday';
|
|
11
|
+
import localeData from 'dayjs/plugin/localeData';
|
|
12
|
+
import objectSupport from 'dayjs/plugin/objectSupport';
|
|
13
|
+
import quarterOfYear from 'dayjs/plugin/quarterOfYear';
|
|
14
|
+
import relativeTime from 'dayjs/plugin/relativeTime';
|
|
15
|
+
import timezone from 'dayjs/plugin/timezone';
|
|
16
|
+
import toObject from 'dayjs/plugin/toObject';
|
|
17
|
+
import utc from 'dayjs/plugin/utc';
|
|
18
|
+
import 'dayjs/locale/zh-cn';
|
|
19
|
+
import 'dayjs/locale/zh';
|
|
20
|
+
dayjs.extend(advancedFormat);
|
|
21
|
+
dayjs.extend(dayOfYear);
|
|
22
|
+
dayjs.extend(duration);
|
|
23
|
+
dayjs.extend(isBetween);
|
|
24
|
+
dayjs.extend(isSameOrAfter);
|
|
25
|
+
dayjs.extend(isSameOrBefore);
|
|
26
|
+
dayjs.extend(isToday);
|
|
27
|
+
dayjs.extend(isTomorrow);
|
|
28
|
+
dayjs.extend(isYesterday);
|
|
29
|
+
dayjs.extend(localeData);
|
|
30
|
+
dayjs.extend(objectSupport);
|
|
31
|
+
dayjs.extend(quarterOfYear);
|
|
32
|
+
dayjs.extend(relativeTime);
|
|
33
|
+
dayjs.extend(timezone);
|
|
34
|
+
dayjs.extend(toObject);
|
|
35
|
+
dayjs.extend(utc);
|
|
36
|
+
dayjs.locale('zh-cn');
|
|
37
|
+
dayjs.tz.setDefault('Asia/Shanghai');
|
|
38
|
+
export { dayjs };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { parseDuration } from "./parseDuration.js";
|
|
2
|
+
export function formatDuration(value, o) {
|
|
3
|
+
var v = parseDuration(value);
|
|
4
|
+
if (v === undefined || v === null) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
var _ref = o || {}, format = _ref.format, humanize = _ref.humanize, iso = _ref.iso;
|
|
8
|
+
// Use local variables instead of modifying o directly
|
|
9
|
+
switch (format) {
|
|
10
|
+
case "human":
|
|
11
|
+
case "humanize":
|
|
12
|
+
humanize = true;
|
|
13
|
+
format = undefined;
|
|
14
|
+
break;
|
|
15
|
+
case "iso":
|
|
16
|
+
iso = true;
|
|
17
|
+
format = undefined;
|
|
18
|
+
break;
|
|
19
|
+
case "auto":
|
|
20
|
+
format = undefined;
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
if (humanize) {
|
|
24
|
+
return v.humanize();
|
|
25
|
+
}
|
|
26
|
+
if (iso) {
|
|
27
|
+
return v.toISOString();
|
|
28
|
+
}
|
|
29
|
+
if (format) {
|
|
30
|
+
return v.format(format);
|
|
31
|
+
}
|
|
32
|
+
// auto format
|
|
33
|
+
// 1h2m3s
|
|
34
|
+
if (v.asDays() > 1) {
|
|
35
|
+
var s = v.toISOString();
|
|
36
|
+
return s.replace("P", "").replace("T", "").toLowerCase();
|
|
37
|
+
}
|
|
38
|
+
{
|
|
39
|
+
var parts = [];
|
|
40
|
+
var h = v.hours();
|
|
41
|
+
var m = v.minutes();
|
|
42
|
+
var s1 = v.seconds();
|
|
43
|
+
var ms = v.milliseconds();
|
|
44
|
+
if (h > 0) {
|
|
45
|
+
parts.push("".concat(h, "h"));
|
|
46
|
+
}
|
|
47
|
+
if (m > 0) {
|
|
48
|
+
parts.push("".concat(m, "m"));
|
|
49
|
+
}
|
|
50
|
+
if (s1 > 0) {
|
|
51
|
+
parts.push("".concat(s1, "s"));
|
|
52
|
+
}
|
|
53
|
+
if (ms > 0 || h === 0 && m === 0 && s1 === 0) {
|
|
54
|
+
parts.push("".concat(ms, "ms"));
|
|
55
|
+
}
|
|
56
|
+
return parts.join("");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length)
|
|
3
|
+
len = arr.length;
|
|
4
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++)
|
|
5
|
+
arr2[i] = arr[i];
|
|
6
|
+
return arr2;
|
|
7
|
+
}
|
|
8
|
+
function _array_with_holes(arr) {
|
|
9
|
+
if (Array.isArray(arr))
|
|
10
|
+
return arr;
|
|
11
|
+
}
|
|
12
|
+
function _iterable_to_array_limit(arr, i) {
|
|
13
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
14
|
+
if (_i == null)
|
|
15
|
+
return;
|
|
16
|
+
var _arr = [];
|
|
17
|
+
var _n = true;
|
|
18
|
+
var _d = false;
|
|
19
|
+
var _s, _e;
|
|
20
|
+
try {
|
|
21
|
+
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
|
|
22
|
+
_arr.push(_s.value);
|
|
23
|
+
if (i && _arr.length === i)
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
_d = true;
|
|
29
|
+
_e = err;
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
try {
|
|
33
|
+
if (!_n && _i["return"] != null)
|
|
34
|
+
_i["return"]();
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
if (_d)
|
|
38
|
+
throw _e;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return _arr;
|
|
42
|
+
}
|
|
43
|
+
function _non_iterable_rest() {
|
|
44
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
45
|
+
}
|
|
46
|
+
function _sliced_to_array(arr, i) {
|
|
47
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
48
|
+
}
|
|
49
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
50
|
+
if (!o)
|
|
51
|
+
return;
|
|
52
|
+
if (typeof o === "string")
|
|
53
|
+
return _array_like_to_array(o, minLen);
|
|
54
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
55
|
+
if (n === "Object" && o.constructor)
|
|
56
|
+
n = o.constructor.name;
|
|
57
|
+
if (n === "Map" || n === "Set")
|
|
58
|
+
return Array.from(n);
|
|
59
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
|
|
60
|
+
return _array_like_to_array(o, minLen);
|
|
61
|
+
}
|
|
62
|
+
import { expect, test } from "vitest";
|
|
63
|
+
import { formatDuration } from "./formatDuration.js";
|
|
64
|
+
test("formatDuration", function () {
|
|
65
|
+
for (var _i = 0, _iter = [
|
|
66
|
+
[
|
|
67
|
+
0,
|
|
68
|
+
"0ms"
|
|
69
|
+
],
|
|
70
|
+
[
|
|
71
|
+
1000,
|
|
72
|
+
"1s"
|
|
73
|
+
],
|
|
74
|
+
[
|
|
75
|
+
1000 * 60,
|
|
76
|
+
"1m"
|
|
77
|
+
],
|
|
78
|
+
[
|
|
79
|
+
1000 * 60 + 1000,
|
|
80
|
+
"1m1s"
|
|
81
|
+
],
|
|
82
|
+
[
|
|
83
|
+
1000 * 60 + 1000 + 1,
|
|
84
|
+
"1m1s1ms"
|
|
85
|
+
]
|
|
86
|
+
]; _i < _iter.length; _i++) {
|
|
87
|
+
var _iter__i = _sliced_to_array(_iter[_i], 2), a = _iter__i[0], b = _iter__i[1];
|
|
88
|
+
expect(formatDuration(a)).toBe(b);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
function _type_of(obj) {
|
|
2
|
+
"@swc/helpers - typeof";
|
|
3
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
4
|
+
}
|
|
5
|
+
import { dayjs } from "./dayjs.js";
|
|
6
|
+
export function parseDuration(value) {
|
|
7
|
+
if (!value && value !== 0) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
var duration;
|
|
11
|
+
if (typeof value === "number") {
|
|
12
|
+
duration = dayjs.duration(value);
|
|
13
|
+
}
|
|
14
|
+
else if (typeof value === "string" && value.startsWith("P")) {
|
|
15
|
+
// PT0S
|
|
16
|
+
duration = dayjs.duration(value);
|
|
17
|
+
}
|
|
18
|
+
else if ((typeof value === "undefined" ? "undefined" : _type_of(value)) === "object" && "value" in value) {
|
|
19
|
+
duration = dayjs.duration(value.value, value.unit);
|
|
20
|
+
}
|
|
21
|
+
else if (dayjs.isDuration(value)) {
|
|
22
|
+
duration = value;
|
|
23
|
+
}
|
|
24
|
+
else if ((typeof value === "undefined" ? "undefined" : _type_of(value)) === "object") {
|
|
25
|
+
duration = dayjs.duration(value);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
console.warn("Invalid duration value:", value);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
return duration;
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { parseDecimal } from "./parseDecimal.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z } from 'zod/v4';
|
|
2
|
+
// Sex 指的是生理性别/生物性别,通常由出生时的生物特征决定
|
|
3
|
+
export var SexType = Object.freeze({
|
|
4
|
+
__proto__: null,
|
|
5
|
+
Male: 'Male',
|
|
6
|
+
Female: 'Female'
|
|
7
|
+
});
|
|
8
|
+
export var SexTypeSchema = z.union([
|
|
9
|
+
//
|
|
10
|
+
z.literal(SexType.Male).describe('男'),
|
|
11
|
+
z.literal(SexType.Female).describe('女')
|
|
12
|
+
]).describe('性别').meta({
|
|
13
|
+
title: 'SexType'
|
|
14
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SexType, SexTypeSchema } from "./SexType.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SexType } from "./SexType.js";
|
|
2
|
+
export function parseSexType(s) {
|
|
3
|
+
if (!s)
|
|
4
|
+
return undefined;
|
|
5
|
+
switch (s.toLowerCase()) {
|
|
6
|
+
case "\u2642":
|
|
7
|
+
case "\u7537":
|
|
8
|
+
case "male":
|
|
9
|
+
case "man":
|
|
10
|
+
return SexType.Male;
|
|
11
|
+
case "\u2640":
|
|
12
|
+
case "\u5973":
|
|
13
|
+
case "female":
|
|
14
|
+
case "woman":
|
|
15
|
+
return SexType.Female;
|
|
16
|
+
}
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
package/lib/index.js
CHANGED