@webdeveric/utils 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/convert.js +19 -0
- package/dist/cjs/convert.js.map +1 -0
- package/dist/cjs/getOwnKeys.js +1 -4
- package/dist/cjs/getOwnKeys.js.map +1 -1
- package/dist/cjs/getOwnProperties.js +11 -0
- package/dist/cjs/getOwnProperties.js.map +1 -0
- package/dist/cjs/index.js +3 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/isEmpty.js +17 -0
- package/dist/cjs/isEmpty.js.map +1 -0
- package/dist/cjs/normalize.js +2 -2
- package/dist/cjs/normalize.js.map +1 -1
- package/dist/mjs/convert.js +15 -0
- package/dist/mjs/convert.js.map +1 -0
- package/dist/mjs/getOwnKeys.js +1 -4
- package/dist/mjs/getOwnKeys.js.map +1 -1
- package/dist/mjs/getOwnProperties.js +7 -0
- package/dist/mjs/getOwnProperties.js.map +1 -0
- package/dist/mjs/index.js +3 -0
- package/dist/mjs/index.js.map +1 -1
- package/dist/mjs/isEmpty.js +13 -0
- package/dist/mjs/isEmpty.js.map +1 -0
- package/dist/mjs/normalize.js +2 -2
- package/dist/mjs/normalize.js.map +1 -1
- package/dist/types/convert.d.ts +8 -0
- package/dist/types/convert.d.ts.map +1 -0
- package/dist/types/getOwnKeys.d.ts +1 -1
- package/dist/types/getOwnKeys.d.ts.map +1 -1
- package/dist/types/getOwnProperties.d.ts +2 -0
- package/dist/types/getOwnProperties.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/isEmpty.d.ts +2 -0
- package/dist/types/isEmpty.d.ts.map +1 -0
- package/package.json +8 -4
- package/src/convert.ts +30 -0
- package/src/getOwnKeys.ts +2 -5
- package/src/getOwnProperties.ts +6 -0
- package/src/index.ts +3 -0
- package/src/isEmpty.ts +15 -0
- package/src/normalize.ts +2 -2
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convert = void 0;
|
|
4
|
+
const getOwnProperties_js_1 = require("./getOwnProperties.js");
|
|
5
|
+
const getType_js_1 = require("./getType.js");
|
|
6
|
+
const convert = (input, converter) => {
|
|
7
|
+
if (typeof converter === 'function') {
|
|
8
|
+
return converter(input);
|
|
9
|
+
}
|
|
10
|
+
if (typeof converter === 'object' && converter !== null) {
|
|
11
|
+
return (0, getOwnProperties_js_1.getOwnProperties)(converter).reduce((data, key) => {
|
|
12
|
+
data[key] = (0, exports.convert)(input, converter[key]);
|
|
13
|
+
return data;
|
|
14
|
+
}, {});
|
|
15
|
+
}
|
|
16
|
+
throw new TypeError(`${(0, getType_js_1.getType)(converter)} is not a valid converter`);
|
|
17
|
+
};
|
|
18
|
+
exports.convert = convert;
|
|
19
|
+
//# sourceMappingURL=convert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.js","sourceRoot":"","sources":["../../src/convert.ts"],"names":[],"mappings":";;;AAAA,+DAAyD;AACzD,6CAAuC;AAchC,MAAM,OAAO,GAAG,CAAgB,KAAsB,EAAE,SAAsC,EAAU,EAAE;IAC/G,IAAI,OAAO,SAAS,KAAK,UAAU,EAAE;QACnC,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;KACzB;IAED,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,KAAK,IAAI,EAAE;QACvD,OAAO,IAAA,sCAAgB,EAAC,SAAS,CAAC,CAAC,MAAM,CAAkB,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;YACvE,IAAI,CAAE,GAAG,CAAE,GAAG,IAAA,eAAO,EAAC,KAAK,EAAE,SAAS,CAAE,GAAG,CAAE,CAAC,CAAC;YAE/C,OAAO,IAAI,CAAC;QACd,CAAC,EAAE,EAAE,CAAW,CAAC;KAClB;IAED,MAAM,IAAI,SAAS,CAAC,GAAG,IAAA,oBAAO,EAAC,SAAS,CAAC,2BAA2B,CAAC,CAAC;AACxE,CAAC,CAAC;AAdW,QAAA,OAAO,WAclB"}
|
package/dist/cjs/getOwnKeys.js
CHANGED
|
@@ -2,10 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getOwnKeys = void 0;
|
|
4
4
|
function getOwnKeys(data) {
|
|
5
|
-
return
|
|
6
|
-
...Object.getOwnPropertyNames(data),
|
|
7
|
-
...Object.getOwnPropertySymbols(data),
|
|
8
|
-
];
|
|
5
|
+
return Object.keys(data);
|
|
9
6
|
}
|
|
10
7
|
exports.getOwnKeys = getOwnKeys;
|
|
11
8
|
//# sourceMappingURL=getOwnKeys.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getOwnKeys.js","sourceRoot":"","sources":["../../src/getOwnKeys.ts"],"names":[],"mappings":";;;AAAA,SAAgB,UAAU,
|
|
1
|
+
{"version":3,"file":"getOwnKeys.js","sourceRoot":"","sources":["../../src/getOwnKeys.ts"],"names":[],"mappings":";;;AAAA,SAAgB,UAAU,CAAiE,IAAO;IAChG,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAQ,CAAC;AAClC,CAAC;AAFD,gCAEC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getOwnProperties = void 0;
|
|
4
|
+
function getOwnProperties(data) {
|
|
5
|
+
return [
|
|
6
|
+
...Object.getOwnPropertyNames(data),
|
|
7
|
+
...Object.getOwnPropertySymbols(data),
|
|
8
|
+
];
|
|
9
|
+
}
|
|
10
|
+
exports.getOwnProperties = getOwnProperties;
|
|
11
|
+
//# sourceMappingURL=getOwnProperties.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getOwnProperties.js","sourceRoot":"","sources":["../../src/getOwnProperties.ts"],"names":[],"mappings":";;;AAAA,SAAgB,gBAAgB,CAAuB,IAAO;IAC5D,OAAO;QACL,GAAG,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC;QACnC,GAAG,MAAM,CAAC,qBAAqB,CAAC,IAAI,CAAC;KAC/B,CAAC;AACX,CAAC;AALD,4CAKC"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -12,10 +12,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
__exportStar(require("./asArray.js"), exports);
|
|
14
14
|
__exportStar(require("./compose.js"), exports);
|
|
15
|
+
__exportStar(require("./convert.js"), exports);
|
|
15
16
|
__exportStar(require("./delay.js"), exports);
|
|
16
17
|
__exportStar(require("./delayAnimationFrame.js"), exports);
|
|
17
18
|
__exportStar(require("./getOwnKeys.js"), exports);
|
|
19
|
+
__exportStar(require("./getOwnProperties.js"), exports);
|
|
18
20
|
__exportStar(require("./getType.js"), exports);
|
|
21
|
+
__exportStar(require("./isEmpty.js"), exports);
|
|
19
22
|
__exportStar(require("./joinStrings.js"), exports);
|
|
20
23
|
__exportStar(require("./normalize.js"), exports);
|
|
21
24
|
__exportStar(require("./secToString.js"), exports);
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAA6B;AAC7B,+CAA6B;AAC7B,6CAA2B;AAC3B,2DAAyC;AACzC,kDAAgC;AAChC,+CAA6B;AAC7B,mDAAiC;AACjC,iDAA+B;AAC/B,mDAAiC;AACjC,oDAAkC;AAClC,+CAA6B;AAC7B,iDAA+B;AAC/B,mDAAiC;AACjC,6CAA2B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAA6B;AAC7B,+CAA6B;AAC7B,+CAA6B;AAC7B,6CAA2B;AAC3B,2DAAyC;AACzC,kDAAgC;AAChC,wDAAsC;AACtC,+CAA6B;AAC7B,+CAA6B;AAC7B,mDAAiC;AACjC,iDAA+B;AAC/B,mDAAiC;AACjC,oDAAkC;AAClC,+CAA6B;AAC7B,iDAA+B;AAC/B,mDAAiC;AACjC,6CAA2B"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isEmpty = void 0;
|
|
4
|
+
function isEmpty(input) {
|
|
5
|
+
if (typeof input === 'undefined' || input === null || (typeof input === 'string' && !input.length)) {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
if (Array.isArray(input)) {
|
|
9
|
+
return input.length === 0;
|
|
10
|
+
}
|
|
11
|
+
if (typeof input === 'object') {
|
|
12
|
+
return Object.keys(input).length === 0;
|
|
13
|
+
}
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
exports.isEmpty = isEmpty;
|
|
17
|
+
//# sourceMappingURL=isEmpty.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isEmpty.js","sourceRoot":"","sources":["../../src/isEmpty.ts"],"names":[],"mappings":";;;AAAA,SAAgB,OAAO,CAAC,KAAc;IACpC,IAAI,OAAO,KAAK,KAAK,WAAW,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAE,KAAK,CAAC,MAAM,CAAC,EAAE;QACnG,OAAO,IAAI,CAAC;KACb;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACxB,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC;KAC3B;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;KACxC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAdD,0BAcC"}
|
package/dist/cjs/normalize.js
CHANGED
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.normalize = void 0;
|
|
7
7
|
const lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep"));
|
|
8
|
-
const
|
|
8
|
+
const getOwnProperties_js_1 = require("./getOwnProperties.js");
|
|
9
9
|
const getType_js_1 = require("./getType.js");
|
|
10
10
|
/**
|
|
11
11
|
* @example
|
|
@@ -38,7 +38,7 @@ function normalize(input, normalizers) {
|
|
|
38
38
|
}
|
|
39
39
|
if (typeof currentNormalizers === 'object' && currentNormalizers !== null) {
|
|
40
40
|
if (typeof currentRecord === 'object' && currentRecord !== null) {
|
|
41
|
-
return (0,
|
|
41
|
+
return (0, getOwnProperties_js_1.getOwnProperties)(currentNormalizers).reduce((data, key) => {
|
|
42
42
|
data[key] = walk(data[key], currentNormalizers[key]);
|
|
43
43
|
return data;
|
|
44
44
|
}, currentRecord);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize.js","sourceRoot":"","sources":["../../src/normalize.ts"],"names":[],"mappings":";;;;;;AAAA,wEAAyC;AAIzC
|
|
1
|
+
{"version":3,"file":"normalize.js","sourceRoot":"","sources":["../../src/normalize.ts"],"names":[],"mappings":";;;;;;AAAA,wEAAyC;AAIzC,+DAAyD;AACzD,6CAAuC;AAmBvC;;;;;;;;;;;;;;GAcG;AACH,SAAgB,SAAS,CACvB,KAAW,EACX,WAAsE;IAEtE,MAAM,UAAU,GAAG,IAAA,0BAAS,EAAC,KAAK,CAAC,CAAC;IAEpC,MAAM,OAAO,GAA2B,MAAM,CAAC,IAAI,CAAC;QAClD,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,UAAU;QACnB,IAAI,EAAE,EAAE;KACT,CAAC,CAAC;IAEH,MAAM,IAAI,GAAG,CACX,aAA4B,EAC5B,kBAA+F,EAChF,EAAE;QACjB,IAAI,OAAO,kBAAkB,KAAK,WAAW,EAAE;YAC7C,OAAO,aAAa,CAAC;SACtB;QAED,IAAI,OAAO,kBAAkB,KAAK,UAAU,EAAE;YAC5C,OAAO,kBAAkB,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;SACnD;QAED,IAAI,OAAO,kBAAkB,KAAK,QAAQ,IAAI,kBAAkB,KAAK,IAAI,EAAE;YACzE,IAAI,OAAO,aAAa,KAAK,QAAQ,IAAI,aAAa,KAAK,IAAI,EAAE;gBAC/D,OAAO,IAAA,sCAAgB,EAAC,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;oBAC/D,IAAI,CAAE,GAAG,CAAE,GAAG,IAAI,CAAC,IAAI,CAAE,GAAG,CAAE,EAAE,kBAAkB,CAAE,GAAG,CAAE,CAAC,CAAC;oBAE3D,OAAO,IAAI,CAAC;gBACd,CAAC,EAAE,aAAa,CAAC,CAAC;aACnB;SACF;aAAM;YACL,MAAM,IAAI,SAAS,CAAC,2CAA2C,IAAA,oBAAO,EAAC,kBAAkB,CAAC,gBAAgB,CAAC,CAAC;SAC7G;QAED,OAAO,aAAa,CAAC;IACvB,CAAC,CAAC;IAEF,OAAO,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;AACvC,CAAC;AAxCD,8BAwCC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { getOwnProperties } from './getOwnProperties.js';
|
|
2
|
+
import { getType } from './getType.js';
|
|
3
|
+
export const convert = (input, converter) => {
|
|
4
|
+
if (typeof converter === 'function') {
|
|
5
|
+
return converter(input);
|
|
6
|
+
}
|
|
7
|
+
if (typeof converter === 'object' && converter !== null) {
|
|
8
|
+
return getOwnProperties(converter).reduce((data, key) => {
|
|
9
|
+
data[key] = convert(input, converter[key]);
|
|
10
|
+
return data;
|
|
11
|
+
}, {});
|
|
12
|
+
}
|
|
13
|
+
throw new TypeError(`${getType(converter)} is not a valid converter`);
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=convert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.js","sourceRoot":"","sources":["../../src/convert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAcvC,MAAM,CAAC,MAAM,OAAO,GAAG,CAAgB,KAAsB,EAAE,SAAsC,EAAU,EAAE;IAC/G,IAAI,OAAO,SAAS,KAAK,UAAU,EAAE;QACnC,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;KACzB;IAED,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,KAAK,IAAI,EAAE;QACvD,OAAO,gBAAgB,CAAC,SAAS,CAAC,CAAC,MAAM,CAAkB,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;YACvE,IAAI,CAAE,GAAG,CAAE,GAAG,OAAO,CAAC,KAAK,EAAE,SAAS,CAAE,GAAG,CAAE,CAAC,CAAC;YAE/C,OAAO,IAAI,CAAC;QACd,CAAC,EAAE,EAAE,CAAW,CAAC;KAClB;IAED,MAAM,IAAI,SAAS,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,2BAA2B,CAAC,CAAC;AACxE,CAAC,CAAC"}
|
package/dist/mjs/getOwnKeys.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getOwnKeys.js","sourceRoot":"","sources":["../../src/getOwnKeys.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,UAAU,
|
|
1
|
+
{"version":3,"file":"getOwnKeys.js","sourceRoot":"","sources":["../../src/getOwnKeys.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,UAAU,CAAiE,IAAO;IAChG,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAQ,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getOwnProperties.js","sourceRoot":"","sources":["../../src/getOwnProperties.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,gBAAgB,CAAuB,IAAO;IAC5D,OAAO;QACL,GAAG,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC;QACnC,GAAG,MAAM,CAAC,qBAAqB,CAAC,IAAI,CAAC;KAC/B,CAAC;AACX,CAAC"}
|
package/dist/mjs/index.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
export * from './asArray.js';
|
|
2
2
|
export * from './compose.js';
|
|
3
|
+
export * from './convert.js';
|
|
3
4
|
export * from './delay.js';
|
|
4
5
|
export * from './delayAnimationFrame.js';
|
|
5
6
|
export * from './getOwnKeys.js';
|
|
7
|
+
export * from './getOwnProperties.js';
|
|
6
8
|
export * from './getType.js';
|
|
9
|
+
export * from './isEmpty.js';
|
|
7
10
|
export * from './joinStrings.js';
|
|
8
11
|
export * from './normalize.js';
|
|
9
12
|
export * from './secToString.js';
|
package/dist/mjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function isEmpty(input) {
|
|
2
|
+
if (typeof input === 'undefined' || input === null || (typeof input === 'string' && !input.length)) {
|
|
3
|
+
return true;
|
|
4
|
+
}
|
|
5
|
+
if (Array.isArray(input)) {
|
|
6
|
+
return input.length === 0;
|
|
7
|
+
}
|
|
8
|
+
if (typeof input === 'object') {
|
|
9
|
+
return Object.keys(input).length === 0;
|
|
10
|
+
}
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=isEmpty.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isEmpty.js","sourceRoot":"","sources":["../../src/isEmpty.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,OAAO,CAAC,KAAc;IACpC,IAAI,OAAO,KAAK,KAAK,WAAW,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAE,KAAK,CAAC,MAAM,CAAC,EAAE;QACnG,OAAO,IAAI,CAAC;KACb;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACxB,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC;KAC3B;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;KACxC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/mjs/normalize.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import cloneDeep from 'lodash.clonedeep';
|
|
2
|
-
import {
|
|
2
|
+
import { getOwnProperties } from './getOwnProperties.js';
|
|
3
3
|
import { getType } from './getType.js';
|
|
4
4
|
/**
|
|
5
5
|
* @example
|
|
@@ -32,7 +32,7 @@ export function normalize(input, normalizers) {
|
|
|
32
32
|
}
|
|
33
33
|
if (typeof currentNormalizers === 'object' && currentNormalizers !== null) {
|
|
34
34
|
if (typeof currentRecord === 'object' && currentRecord !== null) {
|
|
35
|
-
return
|
|
35
|
+
return getOwnProperties(currentNormalizers).reduce((data, key) => {
|
|
36
36
|
data[key] = walk(data[key], currentNormalizers[key]);
|
|
37
37
|
return data;
|
|
38
38
|
}, currentRecord);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize.js","sourceRoot":"","sources":["../../src/normalize.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,kBAAkB,CAAC;AAIzC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"normalize.js","sourceRoot":"","sources":["../../src/normalize.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,kBAAkB,CAAC;AAIzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAmBvC;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,SAAS,CACvB,KAAW,EACX,WAAsE;IAEtE,MAAM,UAAU,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;IAEpC,MAAM,OAAO,GAA2B,MAAM,CAAC,IAAI,CAAC;QAClD,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,UAAU;QACnB,IAAI,EAAE,EAAE;KACT,CAAC,CAAC;IAEH,MAAM,IAAI,GAAG,CACX,aAA4B,EAC5B,kBAA+F,EAChF,EAAE;QACjB,IAAI,OAAO,kBAAkB,KAAK,WAAW,EAAE;YAC7C,OAAO,aAAa,CAAC;SACtB;QAED,IAAI,OAAO,kBAAkB,KAAK,UAAU,EAAE;YAC5C,OAAO,kBAAkB,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;SACnD;QAED,IAAI,OAAO,kBAAkB,KAAK,QAAQ,IAAI,kBAAkB,KAAK,IAAI,EAAE;YACzE,IAAI,OAAO,aAAa,KAAK,QAAQ,IAAI,aAAa,KAAK,IAAI,EAAE;gBAC/D,OAAO,gBAAgB,CAAC,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;oBAC/D,IAAI,CAAE,GAAG,CAAE,GAAG,IAAI,CAAC,IAAI,CAAE,GAAG,CAAE,EAAE,kBAAkB,CAAE,GAAG,CAAE,CAAC,CAAC;oBAE3D,OAAO,IAAI,CAAC;gBACd,CAAC,EAAE,aAAa,CAAC,CAAC;aACnB;SACF;aAAM;YACL,MAAM,IAAI,SAAS,CAAC,2CAA2C,OAAO,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,CAAC;SAC7G;QAED,OAAO,aAAa,CAAC;IACvB,CAAC,CAAC;IAEF,OAAO,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Builtin } from 'ts-essentials';
|
|
2
|
+
export declare type ConvertFn<SourceType, ReturnType> = (source: Readonly<SourceType>) => ReturnType;
|
|
3
|
+
export declare type ConvertRecord<Input, Output> = {
|
|
4
|
+
[Property in keyof Output]: Output[Property] extends Builtin ? ConvertFn<Input, Output[Property]> : AnyConverter<Input, Output[Property]>;
|
|
5
|
+
};
|
|
6
|
+
export declare type AnyConverter<Input, Output> = ConvertRecord<Input, Output> | ConvertFn<Input, Output>;
|
|
7
|
+
export declare const convert: <Input, Output>(input: Readonly<Input>, converter: AnyConverter<Input, Output>) => Output;
|
|
8
|
+
//# sourceMappingURL=convert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../src/convert.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE7C,oBAAY,SAAS,CAAC,UAAU,EAAE,UAAU,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,UAAU,CAAC,KAAK,UAAU,CAAC;AAE7F,oBAAY,aAAa,CAAC,KAAK,EAAE,MAAM,IAAI;KACxC,QAAQ,IAAI,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,SAAS,OAAO,GACxD,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,GAClC,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;CAC1C,CAAC;AAEF,oBAAY,YAAY,CAAC,KAAK,EAAE,MAAM,IAAI,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAElG,eAAO,MAAM,OAAO,2FAcnB,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function getOwnKeys<T, K extends keyof T>(data: T): K[];
|
|
1
|
+
export declare function getOwnKeys<T extends Parameters<typeof Object.keys>[0], K extends keyof T>(data: T): K[];
|
|
2
2
|
//# sourceMappingURL=getOwnKeys.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getOwnKeys.d.ts","sourceRoot":"","sources":["../../src/getOwnKeys.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"getOwnKeys.d.ts","sourceRoot":"","sources":["../../src/getOwnKeys.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CAAC,CAAC,SAAS,UAAU,CAAC,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,CAEvG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getOwnProperties.d.ts","sourceRoot":"","sources":["../../src/getOwnProperties.ts"],"names":[],"mappings":"AAAA,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,CAKnE"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
export * from './asArray.js';
|
|
2
2
|
export * from './compose.js';
|
|
3
|
+
export * from './convert.js';
|
|
3
4
|
export * from './delay.js';
|
|
4
5
|
export * from './delayAnimationFrame.js';
|
|
5
6
|
export * from './getOwnKeys.js';
|
|
7
|
+
export * from './getOwnProperties.js';
|
|
6
8
|
export * from './getType.js';
|
|
9
|
+
export * from './isEmpty.js';
|
|
7
10
|
export * from './joinStrings.js';
|
|
8
11
|
export * from './normalize.js';
|
|
9
12
|
export * from './secToString.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isEmpty.d.ts","sourceRoot":"","sources":["../../src/isEmpty.ts"],"names":[],"mappings":"AAAA,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAc/C"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webdeveric/utils",
|
|
3
3
|
"description": "Just another collection of utilities.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.11.0",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -10,11 +10,14 @@
|
|
|
10
10
|
"utilities",
|
|
11
11
|
"asArray",
|
|
12
12
|
"compose",
|
|
13
|
+
"convert",
|
|
13
14
|
"delay",
|
|
14
15
|
"delayAnimationFrame",
|
|
15
16
|
"fcrdns",
|
|
16
17
|
"getOwnKeys",
|
|
18
|
+
"getOwnProperties",
|
|
17
19
|
"getType",
|
|
20
|
+
"isEmpty",
|
|
18
21
|
"joinStrings",
|
|
19
22
|
"normalize",
|
|
20
23
|
"secToString",
|
|
@@ -70,12 +73,14 @@
|
|
|
70
73
|
"lint": "eslint ./*.js ./src/ ./test/ --ext .ts --fix",
|
|
71
74
|
"test": "NODE_ENV=test jest",
|
|
72
75
|
"validate": "./bin/validate.cjs",
|
|
76
|
+
"update-keywords": "./bin/update-keywords.mjs",
|
|
73
77
|
"spellcheck": "cspell './{.github,src,test}/**/*.{ts,json}' './*.{md,js}' './package.json'",
|
|
74
78
|
"prepublishOnly": "npm run typecheck && npm run spellcheck && npm run lint && npm test && npm run build"
|
|
75
79
|
},
|
|
76
80
|
"dependencies": {
|
|
77
81
|
"lodash.clonedeep": "^4.5.0",
|
|
78
|
-
"lodash.escaperegexp": "^4.1.2"
|
|
82
|
+
"lodash.escaperegexp": "^4.1.2",
|
|
83
|
+
"ts-essentials": "^9.0.0"
|
|
79
84
|
},
|
|
80
85
|
"devDependencies": {
|
|
81
86
|
"@types/jest": "^27.4.0",
|
|
@@ -88,11 +93,10 @@
|
|
|
88
93
|
"eslint": "^8.0.0",
|
|
89
94
|
"eslint-import-resolver-typescript": "^2.5.0",
|
|
90
95
|
"eslint-plugin-import": "^2.25.4",
|
|
91
|
-
"eslint-plugin-jest": "^
|
|
96
|
+
"eslint-plugin-jest": "^26.0.0",
|
|
92
97
|
"jest": "^27.3.0",
|
|
93
98
|
"jest-ts-webcompat-resolver": "^1.0.0",
|
|
94
99
|
"rimraf": "^3.0.2",
|
|
95
|
-
"ts-essentials": "^9.0.0",
|
|
96
100
|
"ts-jest": "^27.0.7",
|
|
97
101
|
"ts-node": "^10.0.0",
|
|
98
102
|
"typescript": "^4.5.4"
|
package/src/convert.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { getOwnProperties } from './getOwnProperties.js';
|
|
2
|
+
import { getType } from './getType.js';
|
|
3
|
+
|
|
4
|
+
import type { Builtin } from 'ts-essentials';
|
|
5
|
+
|
|
6
|
+
export type ConvertFn<SourceType, ReturnType> = (source: Readonly<SourceType>) => ReturnType;
|
|
7
|
+
|
|
8
|
+
export type ConvertRecord<Input, Output> = {
|
|
9
|
+
[Property in keyof Output]: Output[Property] extends Builtin
|
|
10
|
+
? ConvertFn<Input, Output[Property]>
|
|
11
|
+
: AnyConverter<Input, Output[Property]>;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type AnyConverter<Input, Output> = ConvertRecord<Input, Output> | ConvertFn<Input, Output>;
|
|
15
|
+
|
|
16
|
+
export const convert = <Input, Output>(input: Readonly<Input>, converter: AnyConverter<Input, Output>): Output => {
|
|
17
|
+
if (typeof converter === 'function') {
|
|
18
|
+
return converter(input);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (typeof converter === 'object' && converter !== null) {
|
|
22
|
+
return getOwnProperties(converter).reduce<Partial<Output>>((data, key) => {
|
|
23
|
+
data[ key ] = convert(input, converter[ key ]);
|
|
24
|
+
|
|
25
|
+
return data;
|
|
26
|
+
}, {}) as Output;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
throw new TypeError(`${getType(converter)} is not a valid converter`);
|
|
30
|
+
};
|
package/src/getOwnKeys.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
export function getOwnKeys<T, K extends keyof T>(data: T): K[] {
|
|
2
|
-
return [
|
|
3
|
-
...Object.getOwnPropertyNames(data),
|
|
4
|
-
...Object.getOwnPropertySymbols(data),
|
|
5
|
-
] as K[];
|
|
1
|
+
export function getOwnKeys<T extends Parameters<typeof Object.keys>[0], K extends keyof T>(data: T): K[] {
|
|
2
|
+
return Object.keys(data) as K[];
|
|
6
3
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
export * from './asArray.js';
|
|
2
2
|
export * from './compose.js';
|
|
3
|
+
export * from './convert.js';
|
|
3
4
|
export * from './delay.js';
|
|
4
5
|
export * from './delayAnimationFrame.js';
|
|
5
6
|
export * from './getOwnKeys.js';
|
|
7
|
+
export * from './getOwnProperties.js';
|
|
6
8
|
export * from './getType.js';
|
|
9
|
+
export * from './isEmpty.js';
|
|
7
10
|
export * from './joinStrings.js';
|
|
8
11
|
export * from './normalize.js';
|
|
9
12
|
export * from './secToString.js';
|
package/src/isEmpty.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function isEmpty(input: unknown): boolean {
|
|
2
|
+
if (typeof input === 'undefined' || input === null || (typeof input === 'string' && ! input.length)) {
|
|
3
|
+
return true;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
if (Array.isArray(input)) {
|
|
7
|
+
return input.length === 0;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (typeof input === 'object') {
|
|
11
|
+
return Object.keys(input).length === 0;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return false;
|
|
15
|
+
}
|
package/src/normalize.ts
CHANGED
|
@@ -2,7 +2,7 @@ import cloneDeep from 'lodash.clonedeep';
|
|
|
2
2
|
|
|
3
3
|
import type { Builtin } from 'ts-essentials';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { getOwnProperties } from './getOwnProperties.js';
|
|
6
6
|
import { getType } from './getType.js';
|
|
7
7
|
|
|
8
8
|
export type NormalizeContext<OwnerRecordType> = {
|
|
@@ -63,7 +63,7 @@ export function normalize<Data>(
|
|
|
63
63
|
|
|
64
64
|
if (typeof currentNormalizers === 'object' && currentNormalizers !== null) {
|
|
65
65
|
if (typeof currentRecord === 'object' && currentRecord !== null) {
|
|
66
|
-
return
|
|
66
|
+
return getOwnProperties(currentNormalizers).reduce((data, key) => {
|
|
67
67
|
data[ key ] = walk(data[ key ], currentNormalizers[ key ]);
|
|
68
68
|
|
|
69
69
|
return data;
|