@kcuf/helper-data 0.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/LICENSE +21 -0
- package/README.md +5 -0
- package/dist/cjs/enum/index.js +16 -0
- package/dist/cjs/helper/create-data-with-loading.js +16 -0
- package/dist/cjs/helper/index.js +55 -0
- package/dist/cjs/helper/normalize-boolean.js +12 -0
- package/dist/cjs/helper/normalize-enum.js +13 -0
- package/dist/cjs/helper/normalize-id.js +18 -0
- package/dist/cjs/helper/normalize-number.js +13 -0
- package/dist/cjs/helper/normalize-paged-list-uncertain.js +15 -0
- package/dist/cjs/helper/normalize-paged-list.js +17 -0
- package/dist/cjs/helper/normalize-time.js +12 -0
- package/dist/cjs/index.js +27 -0
- package/dist/cjs/types/base-data.js +5 -0
- package/dist/cjs/types/base-params.js +5 -0
- package/dist/cjs/types/generic.js +5 -0
- package/dist/cjs/types/index.js +38 -0
- package/dist/esm/enum/index.js +11 -0
- package/dist/esm/enum/index.js.map +1 -0
- package/dist/esm/helper/create-data-with-loading.js +11 -0
- package/dist/esm/helper/create-data-with-loading.js.map +1 -0
- package/dist/esm/helper/index.js +8 -0
- package/dist/esm/helper/index.js.map +1 -0
- package/dist/esm/helper/normalize-boolean.js +7 -0
- package/dist/esm/helper/normalize-boolean.js.map +1 -0
- package/dist/esm/helper/normalize-enum.js +8 -0
- package/dist/esm/helper/normalize-enum.js.map +1 -0
- package/dist/esm/helper/normalize-id.js +13 -0
- package/dist/esm/helper/normalize-id.js.map +1 -0
- package/dist/esm/helper/normalize-number.js +8 -0
- package/dist/esm/helper/normalize-number.js.map +1 -0
- package/dist/esm/helper/normalize-paged-list-uncertain.js +10 -0
- package/dist/esm/helper/normalize-paged-list-uncertain.js.map +1 -0
- package/dist/esm/helper/normalize-paged-list.js +12 -0
- package/dist/esm/helper/normalize-paged-list.js.map +1 -0
- package/dist/esm/helper/normalize-time.js +7 -0
- package/dist/esm/helper/normalize-time.js.map +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/types/base-data.js +2 -0
- package/dist/esm/types/base-data.js.map +1 -0
- package/dist/esm/types/base-params.js +2 -0
- package/dist/esm/types/base-params.js.map +1 -0
- package/dist/esm/types/generic.js +2 -0
- package/dist/esm/types/generic.js.map +1 -0
- package/dist/esm/types/index.js +4 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/types/enum/index.d.ts +9 -0
- package/dist/types/helper/create-data-with-loading.d.ts +3 -0
- package/dist/types/helper/index.d.ts +7 -0
- package/dist/types/helper/normalize-boolean.d.ts +4 -0
- package/dist/types/helper/normalize-enum.d.ts +4 -0
- package/dist/types/helper/normalize-id.d.ts +4 -0
- package/dist/types/helper/normalize-number.d.ts +4 -0
- package/dist/types/helper/normalize-paged-list-uncertain.d.ts +4 -0
- package/dist/types/helper/normalize-paged-list.d.ts +5 -0
- package/dist/types/helper/normalize-time.d.ts +4 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/types/base-data.d.ts +46 -0
- package/dist/types/types/base-params.d.ts +13 -0
- package/dist/types/types/generic.d.ts +21 -0
- package/dist/types/types/index.d.ts +3 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Alibaba Cloud
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ELoadingStatus = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* 数据加载状态
|
|
9
|
+
*/
|
|
10
|
+
var ELoadingStatus = exports.ELoadingStatus = /*#__PURE__*/function (ELoadingStatus) {
|
|
11
|
+
ELoadingStatus[ELoadingStatus["IDLE"] = 0] = "IDLE";
|
|
12
|
+
ELoadingStatus[ELoadingStatus["LOADING"] = 1] = "LOADING";
|
|
13
|
+
ELoadingStatus[ELoadingStatus["SUCCESS"] = 2] = "SUCCESS";
|
|
14
|
+
ELoadingStatus[ELoadingStatus["ERROR"] = 3] = "ERROR";
|
|
15
|
+
return ELoadingStatus;
|
|
16
|
+
}({});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = createDataWithLoading;
|
|
7
|
+
var _enum = require("../enum");
|
|
8
|
+
function createDataWithLoading(data) {
|
|
9
|
+
var loading = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _enum.ELoadingStatus.IDLE;
|
|
10
|
+
var error = arguments.length > 2 ? arguments[2] : undefined;
|
|
11
|
+
return {
|
|
12
|
+
loading: loading,
|
|
13
|
+
data: data,
|
|
14
|
+
error: error
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
Object.defineProperty(exports, "createDataWithLoading", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function get() {
|
|
10
|
+
return _createDataWithLoading.default;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(exports, "normalizeBoolean", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function get() {
|
|
16
|
+
return _normalizeBoolean.default;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports, "normalizeEnum", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function get() {
|
|
22
|
+
return _normalizeEnum.default;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(exports, "normalizeId", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function get() {
|
|
28
|
+
return _normalizeId.default;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(exports, "normalizeNumber", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function get() {
|
|
34
|
+
return _normalizeNumber.default;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(exports, "normalizePagedList", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: function get() {
|
|
40
|
+
return _normalizePagedList.default;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
Object.defineProperty(exports, "normalizeTime", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function get() {
|
|
46
|
+
return _normalizeTime.default;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
var _normalizeId = _interopRequireDefault(require("./normalize-id"));
|
|
50
|
+
var _normalizeBoolean = _interopRequireDefault(require("./normalize-boolean"));
|
|
51
|
+
var _normalizeNumber = _interopRequireDefault(require("./normalize-number"));
|
|
52
|
+
var _normalizeEnum = _interopRequireDefault(require("./normalize-enum"));
|
|
53
|
+
var _normalizeTime = _interopRequireDefault(require("./normalize-time"));
|
|
54
|
+
var _normalizePagedList = _interopRequireDefault(require("./normalize-paged-list"));
|
|
55
|
+
var _createDataWithLoading = _interopRequireDefault(require("./create-data-with-loading"));
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = normalizeEnum;
|
|
7
|
+
/**
|
|
8
|
+
* 转枚举
|
|
9
|
+
*/
|
|
10
|
+
function normalizeEnum(value, fallback) {
|
|
11
|
+
var _ref;
|
|
12
|
+
return (_ref = value) !== null && _ref !== void 0 ? _ref : fallback;
|
|
13
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = normalizeId;
|
|
7
|
+
/**
|
|
8
|
+
* 标准化 ID 值
|
|
9
|
+
*/
|
|
10
|
+
function normalizeId(id0) {
|
|
11
|
+
if (typeof id0 === 'string') {
|
|
12
|
+
return id0;
|
|
13
|
+
}
|
|
14
|
+
if (typeof id0 === 'number' && id0 > 0) {
|
|
15
|
+
return id0.toString();
|
|
16
|
+
}
|
|
17
|
+
return '';
|
|
18
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = normalizeNumber;
|
|
7
|
+
/**
|
|
8
|
+
* 标准化数值
|
|
9
|
+
*/
|
|
10
|
+
function normalizeNumber(value) {
|
|
11
|
+
var fallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
12
|
+
return Number(value) || fallback;
|
|
13
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
function normalizePagedListUncertain(list0, page, pageSize, convert) {
|
|
8
|
+
return {
|
|
9
|
+
list: convert ? list0.map(convert) : list0,
|
|
10
|
+
page: page,
|
|
11
|
+
pageSize: pageSize,
|
|
12
|
+
hasMore: list0.length >= pageSize
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
var _default = exports.default = normalizePagedListUncertain;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = normalizePagedList;
|
|
7
|
+
/**
|
|
8
|
+
* 这里我们不知道后端给的数据究竟长什么样,这个方法相对比较普适,业务封装可以在此基础上,通过传入后端对象简化调用
|
|
9
|
+
*/
|
|
10
|
+
function normalizePagedList(list0, total, page, pageSize, convert) {
|
|
11
|
+
return {
|
|
12
|
+
list: convert ? list0.map(convert) : list0,
|
|
13
|
+
total: total,
|
|
14
|
+
page: page,
|
|
15
|
+
pageSize: pageSize
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
LoadingStatus: true
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "LoadingStatus", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function get() {
|
|
12
|
+
return _enum.ELoadingStatus;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
var _helper = require("./helper");
|
|
16
|
+
Object.keys(_helper).forEach(function (key) {
|
|
17
|
+
if (key === "default" || key === "__esModule") return;
|
|
18
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
19
|
+
if (key in exports && exports[key] === _helper[key]) return;
|
|
20
|
+
Object.defineProperty(exports, key, {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function get() {
|
|
23
|
+
return _helper[key];
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
var _enum = require("./enum");
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _baseParams = require("./base-params");
|
|
7
|
+
Object.keys(_baseParams).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _baseParams[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function get() {
|
|
13
|
+
return _baseParams[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _baseData = require("./base-data");
|
|
18
|
+
Object.keys(_baseData).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _baseData[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function get() {
|
|
24
|
+
return _baseData[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
var _generic = require("./generic");
|
|
29
|
+
Object.keys(_generic).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _generic[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function get() {
|
|
35
|
+
return _generic[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 数据加载状态
|
|
3
|
+
*/
|
|
4
|
+
export var ELoadingStatus = /*#__PURE__*/function (ELoadingStatus) {
|
|
5
|
+
ELoadingStatus[ELoadingStatus["IDLE"] = 0] = "IDLE";
|
|
6
|
+
ELoadingStatus[ELoadingStatus["LOADING"] = 1] = "LOADING";
|
|
7
|
+
ELoadingStatus[ELoadingStatus["SUCCESS"] = 2] = "SUCCESS";
|
|
8
|
+
ELoadingStatus[ELoadingStatus["ERROR"] = 3] = "ERROR";
|
|
9
|
+
return ELoadingStatus;
|
|
10
|
+
}({});
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["ELoadingStatus"],"sources":["../../../src/enum/index.ts"],"sourcesContent":["/**\n * 数据加载状态\n */\nexport enum ELoadingStatus {\n IDLE,\n LOADING,\n SUCCESS,\n ERROR\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,WAAYA,cAAc,0BAAdA,cAAc;EAAdA,cAAc,CAAdA,cAAc;EAAdA,cAAc,CAAdA,cAAc;EAAdA,cAAc,CAAdA,cAAc;EAAdA,cAAc,CAAdA,cAAc;EAAA,OAAdA,cAAc;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ELoadingStatus } from '../enum';
|
|
2
|
+
export default function createDataWithLoading(data) {
|
|
3
|
+
var loading = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ELoadingStatus.IDLE;
|
|
4
|
+
var error = arguments.length > 2 ? arguments[2] : undefined;
|
|
5
|
+
return {
|
|
6
|
+
loading: loading,
|
|
7
|
+
data: data,
|
|
8
|
+
error: error
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=create-data-with-loading.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-data-with-loading.js","names":["ELoadingStatus","createDataWithLoading","data","loading","arguments","length","undefined","IDLE","error"],"sources":["../../../src/helper/create-data-with-loading.ts"],"sourcesContent":["import {\n ELoadingStatus\n} from '../enum';\nimport {\n IDataWithLoading\n} from '../types';\n\nexport default function createDataWithLoading<T>(data?: T | null, loading = ELoadingStatus.IDLE, error?: Error | null): IDataWithLoading<T> {\n return {\n loading,\n data,\n error\n };\n}\n"],"mappings":"AAAA,SACEA,cAAc,QACT,SAAS;AAKhB,eAAe,SAASC,qBAAqBA,CAAIC,IAAe,EAA4E;EAAA,IAA1EC,OAAO,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAGJ,cAAc,CAACO,IAAI;EAAA,IAAEC,KAAoB,GAAAJ,SAAA,CAAAC,MAAA,OAAAD,SAAA,MAAAE,SAAA;EACnH,OAAO;IACLH,OAAO,EAAPA,OAAO;IACPD,IAAI,EAAJA,IAAI;IACJM,KAAK,EAALA;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { default as normalizeId } from './normalize-id';
|
|
2
|
+
export { default as normalizeBoolean } from './normalize-boolean';
|
|
3
|
+
export { default as normalizeNumber } from './normalize-number';
|
|
4
|
+
export { default as normalizeEnum } from './normalize-enum';
|
|
5
|
+
export { default as normalizeTime } from './normalize-time';
|
|
6
|
+
export { default as normalizePagedList } from './normalize-paged-list';
|
|
7
|
+
export { default as createDataWithLoading } from './create-data-with-loading';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["default","normalizeId","normalizeBoolean","normalizeNumber","normalizeEnum","normalizeTime","normalizePagedList","createDataWithLoading"],"sources":["../../../src/helper/index.ts"],"sourcesContent":["export { default as normalizeId } from './normalize-id';\nexport { default as normalizeBoolean } from './normalize-boolean';\nexport { default as normalizeNumber } from './normalize-number';\nexport { default as normalizeEnum } from './normalize-enum';\nexport { default as normalizeTime } from './normalize-time';\nexport { default as normalizePagedList } from './normalize-paged-list';\n\nexport { default as createDataWithLoading } from './create-data-with-loading';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,WAAW,QAAQ,gBAAgB;AACvD,SAASD,OAAO,IAAIE,gBAAgB,QAAQ,qBAAqB;AACjE,SAASF,OAAO,IAAIG,eAAe,QAAQ,oBAAoB;AAC/D,SAASH,OAAO,IAAII,aAAa,QAAQ,kBAAkB;AAC3D,SAASJ,OAAO,IAAIK,aAAa,QAAQ,kBAAkB;AAC3D,SAASL,OAAO,IAAIM,kBAAkB,QAAQ,wBAAwB;AAEtE,SAASN,OAAO,IAAIO,qBAAqB,QAAQ,4BAA4B","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize-boolean.js","names":["normalizeBoolean","value","includes"],"sources":["../../../src/helper/normalize-boolean.ts"],"sourcesContent":["/**\n * 将随性的值转成布尔\n */\nexport default function normalizeBoolean(value: number | string): boolean {\n return [1, '1', 'true', 'TRUE'].includes(value);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,eAAe,SAASA,gBAAgBA,CAACC,KAAsB,EAAW;EACxE,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,CAACC,QAAQ,CAACD,KAAK,CAAC;AACjD","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize-enum.js","names":["normalizeEnum","value","fallback","_ref"],"sources":["../../../src/helper/normalize-enum.ts"],"sourcesContent":["/**\n * 转枚举\n */\nexport default function normalizeEnum<E>(value: unknown, fallback: E): E {\n return value as E | undefined ?? fallback;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,eAAe,SAASA,aAAaA,CAAIC,KAAc,EAAEC,QAAW,EAAK;EAAA,IAAAC,IAAA;EACvE,QAAAA,IAAA,GAAOF,KAAK,cAAAE,IAAA,cAAAA,IAAA,GAAqBD,QAAQ;AAC3C","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize-id.js","names":["normalizeId","id0","toString"],"sources":["../../../src/helper/normalize-id.ts"],"sourcesContent":["/**\n * 标准化 ID 值\n */\nexport default function normalizeId(id0: unknown): string {\n if (typeof id0 === 'string') {\n return id0;\n }\n \n if (typeof id0 === 'number' && id0 > 0) {\n return id0.toString();\n }\n \n return '';\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,eAAe,SAASA,WAAWA,CAACC,GAAY,EAAU;EACxD,IAAI,OAAOA,GAAG,KAAK,QAAQ,EAAE;IAC3B,OAAOA,GAAG;EACZ;EAEA,IAAI,OAAOA,GAAG,KAAK,QAAQ,IAAIA,GAAG,GAAG,CAAC,EAAE;IACtC,OAAOA,GAAG,CAACC,QAAQ,CAAC,CAAC;EACvB;EAEA,OAAO,EAAE;AACX","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize-number.js","names":["normalizeNumber","value","fallback","arguments","length","undefined","Number"],"sources":["../../../src/helper/normalize-number.ts"],"sourcesContent":["/**\n * 标准化数值\n */\nexport default function normalizeNumber(value: unknown, fallback = 0): number {\n return Number(value) || fallback;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,eAAe,SAASA,eAAeA,CAACC,KAAc,EAAwB;EAAA,IAAtBC,QAAQ,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC;EAClE,OAAOG,MAAM,CAACL,KAAK,CAAC,IAAIC,QAAQ;AAClC","ignoreList":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
function normalizePagedListUncertain(list0, page, pageSize, convert) {
|
|
2
|
+
return {
|
|
3
|
+
list: convert ? list0.map(convert) : list0,
|
|
4
|
+
page: page,
|
|
5
|
+
pageSize: pageSize,
|
|
6
|
+
hasMore: list0.length >= pageSize
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export default normalizePagedListUncertain;
|
|
10
|
+
//# sourceMappingURL=normalize-paged-list-uncertain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize-paged-list-uncertain.js","names":["normalizePagedListUncertain","list0","page","pageSize","convert","list","map","hasMore","length"],"sources":["../../../src/helper/normalize-paged-list-uncertain.ts"],"sourcesContent":["import {\n IPagedListUncertain\n} from '../types';\n\nfunction normalizePagedListUncertain<T>(list0: T[], page: number, pageSize: number): IPagedListUncertain<T>;\nfunction normalizePagedListUncertain<T0, T>(list0: T0[], page: number, pageSize: number, convert: (o: T0) => T): IPagedListUncertain<T>;\n\nfunction normalizePagedListUncertain<T0, T = T0>(list0: T0[], page: number, pageSize: number, convert?: (o: T0) => T): IPagedListUncertain<T> {\n return {\n list: convert ? list0.map(convert) : list0 as unknown as T[],\n page,\n pageSize,\n hasMore: list0.length >= pageSize\n };\n}\n\nexport default normalizePagedListUncertain;\n"],"mappings":"AAOA,SAASA,2BAA2BA,CAAaC,KAAW,EAAEC,IAAY,EAAEC,QAAgB,EAAEC,OAAsB,EAA0B;EAC5I,OAAO;IACLC,IAAI,EAAED,OAAO,GAAGH,KAAK,CAACK,GAAG,CAACF,OAAO,CAAC,GAAGH,KAAuB;IAC5DC,IAAI,EAAJA,IAAI;IACJC,QAAQ,EAARA,QAAQ;IACRI,OAAO,EAAEN,KAAK,CAACO,MAAM,IAAIL;EAC3B,CAAC;AACH;AAEA,eAAeH,2BAA2B","ignoreList":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 这里我们不知道后端给的数据究竟长什么样,这个方法相对比较普适,业务封装可以在此基础上,通过传入后端对象简化调用
|
|
3
|
+
*/
|
|
4
|
+
export default function normalizePagedList(list0, total, page, pageSize, convert) {
|
|
5
|
+
return {
|
|
6
|
+
list: convert ? list0.map(convert) : list0,
|
|
7
|
+
total: total,
|
|
8
|
+
page: page,
|
|
9
|
+
pageSize: pageSize
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=normalize-paged-list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize-paged-list.js","names":["normalizePagedList","list0","total","page","pageSize","convert","list","map"],"sources":["../../../src/helper/normalize-paged-list.ts"],"sourcesContent":["import {\n IPagedList\n} from '../types';\n\n/**\n * 这里我们不知道后端给的数据究竟长什么样,这个方法相对比较普适,业务封装可以在此基础上,通过传入后端对象简化调用\n */\nexport default function normalizePagedList<T0, T = T0>(list0: T0[], total: number, page: number, pageSize: number, convert?: (o: T0) => T): IPagedList<T> {\n return {\n list: convert ? list0.map(convert) : list0 as unknown as T[],\n total,\n page,\n pageSize\n };\n}\n"],"mappings":"AAIA;AACA;AACA;AACA,eAAe,SAASA,kBAAkBA,CAAaC,KAAW,EAAEC,KAAa,EAAEC,IAAY,EAAEC,QAAgB,EAAEC,OAAsB,EAAiB;EACxJ,OAAO;IACLC,IAAI,EAAED,OAAO,GAAGJ,KAAK,CAACM,GAAG,CAACF,OAAO,CAAC,GAAGJ,KAAuB;IAC5DC,KAAK,EAALA,KAAK;IACLC,IAAI,EAAJA,IAAI;IACJC,QAAQ,EAARA;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize-time.js","names":["normalizeTime","time0","Date"],"sources":["../../../src/helper/normalize-time.ts"],"sourcesContent":["/**\n * 标准化时间\n */\nexport default function normalizeTime(time0: number | string): Date {\n return new Date(time0);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,eAAe,SAASA,aAAaA,CAACC,KAAsB,EAAQ;EAClE,OAAO,IAAIC,IAAI,CAACD,KAAK,CAAC;AACxB","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["ELoadingStatus","LoadingStatus"],"sources":["../../src/index.ts"],"sourcesContent":["export * from './helper';\n\nexport {\n ELoadingStatus as LoadingStatus\n} from './enum';\n\nexport type {\n IBaseParamsPage as BaseParamsPage,\n IBaseParamsPageWithQ as BaseParamsPageWithQ,\n \n IBaseDataId as BaseDataId,\n IBaseDataName as BaseDataName,\n IBaseDataIdName as BaseDataIdName,\n IBaseDataTitle as BaseDataTitle,\n IBaseDataContent as BaseDataContent,\n IBaseDataTimeCreated as BaseDataTimeCreated,\n IBaseDataTimeModified as BaseDataTimeModified,\n IBaseDataTimes as BaseDataTimes,\n \n IPagedList as PagedList,\n IPagedListUncertain as PagedListUncertain,\n \n IDataWithLoading as DataWithLoading\n} from './types';\n"],"mappings":"AAAA,cAAc,UAAU;AAExB,SACEA,cAAc,IAAIC,aAAa,QAC1B,QAAQ","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-data.js","names":[],"sources":["../../../src/types/base-data.ts"],"sourcesContent":["// 基础类型 mixin,用于继承,统一前缀 BaseData\n\n/**\n * 「ID」标准化\n */\nexport interface IBaseDataId {\n id: string;\n}\n\n/**\n * 「名称」标准化\n */\nexport interface IBaseDataName {\n name: string;\n}\n\n/**\n * 「标题」标准化\n */\nexport interface IBaseDataTitle {\n title: string;\n}\n\n/**\n * 「内容」标准化\n */\nexport interface IBaseDataContent {\n content: string;\n}\n\n/**\n * id + name\n */\nexport interface IBaseDataIdName extends IBaseDataId, IBaseDataName {}\n\n/**\n * 「创建时间」标准化\n */\nexport interface IBaseDataTimeCreated {\n timeCreated: Date;\n}\n\n/**\n * 「更新时间」标准化\n */\nexport interface IBaseDataTimeModified {\n timeModified: Date;\n}\n\n/**\n * timeCreated + timeModified\n */\nexport interface IBaseDataTimes extends IBaseDataTimeCreated, IBaseDataTimeModified {}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-params.js","names":[],"sources":["../../../src/types/base-params.ts"],"sourcesContent":["/**\n * 分页参数标准化\n */\nexport interface IBaseParamsPage {\n page?: number;\n pageSize?: number;\n}\n\n/**\n * 带关键词的分页参数标准化\n */\nexport interface IBaseParamsPageWithQ extends IBaseParamsPage {\n q?: string; // 前端「搜素关键字」参数统一为 q\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generic.js","names":[],"sources":["../../../src/types/generic.ts"],"sourcesContent":["import {\n ELoadingStatus\n} from '../enum';\n\n/**\n * 分页数据标准化\n */\nexport interface IPagedList<T> {\n list: T[];\n total: number;\n page: number;\n pageSize: number;\n}\n\n/**\n * 某些分页接口,后端给的数据只有列表,前端需根据返回转成非确定分页列表数据\n */\nexport interface IPagedListUncertain<T> extends Omit<IPagedList<T>, 'total'> {\n hasMore: boolean;\n}\n\nexport interface IDataWithLoading<T> {\n loading: ELoadingStatus;\n data: T | null | undefined;\n error: Error | null | undefined;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/types/index.ts"],"sourcesContent":["export * from './base-params';\nexport * from './base-data';\nexport * from './generic';\n"],"mappings":"AAAA,cAAc,eAAe;AAC7B,cAAc,aAAa;AAC3B,cAAc,WAAW","ignoreList":[]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { default as normalizeId } from './normalize-id';
|
|
2
|
+
export { default as normalizeBoolean } from './normalize-boolean';
|
|
3
|
+
export { default as normalizeNumber } from './normalize-number';
|
|
4
|
+
export { default as normalizeEnum } from './normalize-enum';
|
|
5
|
+
export { default as normalizeTime } from './normalize-time';
|
|
6
|
+
export { default as normalizePagedList } from './normalize-paged-list';
|
|
7
|
+
export { default as createDataWithLoading } from './create-data-with-loading';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { IPagedListUncertain } from '../types';
|
|
2
|
+
declare function normalizePagedListUncertain<T>(list0: T[], page: number, pageSize: number): IPagedListUncertain<T>;
|
|
3
|
+
declare function normalizePagedListUncertain<T0, T>(list0: T0[], page: number, pageSize: number, convert: (o: T0) => T): IPagedListUncertain<T>;
|
|
4
|
+
export default normalizePagedListUncertain;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export * from './helper';
|
|
2
|
+
export { ELoadingStatus as LoadingStatus } from './enum';
|
|
3
|
+
export type { IBaseParamsPage as BaseParamsPage, IBaseParamsPageWithQ as BaseParamsPageWithQ, IBaseDataId as BaseDataId, IBaseDataName as BaseDataName, IBaseDataIdName as BaseDataIdName, IBaseDataTitle as BaseDataTitle, IBaseDataContent as BaseDataContent, IBaseDataTimeCreated as BaseDataTimeCreated, IBaseDataTimeModified as BaseDataTimeModified, IBaseDataTimes as BaseDataTimes, IPagedList as PagedList, IPagedListUncertain as PagedListUncertain, IDataWithLoading as DataWithLoading } from './types';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 「ID」标准化
|
|
3
|
+
*/
|
|
4
|
+
export interface IBaseDataId {
|
|
5
|
+
id: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* 「名称」标准化
|
|
9
|
+
*/
|
|
10
|
+
export interface IBaseDataName {
|
|
11
|
+
name: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 「标题」标准化
|
|
15
|
+
*/
|
|
16
|
+
export interface IBaseDataTitle {
|
|
17
|
+
title: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 「内容」标准化
|
|
21
|
+
*/
|
|
22
|
+
export interface IBaseDataContent {
|
|
23
|
+
content: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* id + name
|
|
27
|
+
*/
|
|
28
|
+
export interface IBaseDataIdName extends IBaseDataId, IBaseDataName {
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 「创建时间」标准化
|
|
32
|
+
*/
|
|
33
|
+
export interface IBaseDataTimeCreated {
|
|
34
|
+
timeCreated: Date;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* 「更新时间」标准化
|
|
38
|
+
*/
|
|
39
|
+
export interface IBaseDataTimeModified {
|
|
40
|
+
timeModified: Date;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* timeCreated + timeModified
|
|
44
|
+
*/
|
|
45
|
+
export interface IBaseDataTimes extends IBaseDataTimeCreated, IBaseDataTimeModified {
|
|
46
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ELoadingStatus } from '../enum';
|
|
2
|
+
/**
|
|
3
|
+
* 分页数据标准化
|
|
4
|
+
*/
|
|
5
|
+
export interface IPagedList<T> {
|
|
6
|
+
list: T[];
|
|
7
|
+
total: number;
|
|
8
|
+
page: number;
|
|
9
|
+
pageSize: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 某些分页接口,后端给的数据只有列表,前端需根据返回转成非确定分页列表数据
|
|
13
|
+
*/
|
|
14
|
+
export interface IPagedListUncertain<T> extends Omit<IPagedList<T>, 'total'> {
|
|
15
|
+
hasMore: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface IDataWithLoading<T> {
|
|
18
|
+
loading: ELoadingStatus;
|
|
19
|
+
data: T | null | undefined;
|
|
20
|
+
error: Error | null | undefined;
|
|
21
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kcuf/helper-data",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Data normalizer helpers and loading stuff to make all frontend data processing sane.",
|
|
5
|
+
"keywords": [],
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"main": "dist/cjs/index.js",
|
|
9
|
+
"module": "dist/esm/index.js",
|
|
10
|
+
"types": "dist/types/index.d.ts",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/justnewbee/kcuf.git"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/justnewbee/kcuf/tree/master/packages-helper/helper-data",
|
|
16
|
+
"bugs": "https://github.com/justnewbee/kcuf/issues",
|
|
17
|
+
"author": {
|
|
18
|
+
"name": "Jianchun Wang",
|
|
19
|
+
"email": "justnewbee@gmail.com"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@babel/cli": "^7.25.9",
|
|
26
|
+
"@babel/core": "^7.26.0",
|
|
27
|
+
"@babel/plugin-transform-runtime": "^7.25.9",
|
|
28
|
+
"@babel/preset-env": "^7.26.0",
|
|
29
|
+
"@babel/preset-typescript": "^7.26.0",
|
|
30
|
+
"rimraf": "^6.0.1",
|
|
31
|
+
"typescript": "^5.6.3",
|
|
32
|
+
"@kcuf/ts-config": "^0.0.1"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@babel/runtime": "^7.24.8"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build:clean": "rimraf dist",
|
|
39
|
+
"build:esm": "ESM=1 babel src -d dist/esm --extensions .ts,.tsx --source-maps",
|
|
40
|
+
"build:cjs": "ESM=0 babel src -d dist/cjs --extensions .ts,.tsx",
|
|
41
|
+
"build:types": "tsc -rootDir src --outDir dist/types --declaration --noEmit false --emitDeclarationOnly --isolatedModules false",
|
|
42
|
+
"build": "pnpm build:esm && pnpm build:cjs && pnpm build:types",
|
|
43
|
+
"watch": "pnpm build:esm -w"
|
|
44
|
+
}
|
|
45
|
+
}
|