webpb 0.0.14 → 0.0.16
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/index.d.ts +7 -0
- package/index.js +12 -5
- package/package.json +17 -16
package/index.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
export type Constructor<T> = {
|
|
2
|
+
new (): T;
|
|
3
|
+
fromAlias<T, D>(this: Constructor<T>, data: Partial<D>): T;
|
|
4
|
+
};
|
|
5
|
+
type AnyObject = Record<string | number, unknown>;
|
|
1
6
|
export interface WebpbMessage {
|
|
2
7
|
webpbMeta(): WebpbMeta;
|
|
3
8
|
toWebpbAlias(): any;
|
|
@@ -16,3 +21,5 @@ export declare function query(pre: string, params: {
|
|
|
16
21
|
export declare function toAlias(data: any, aliases: {
|
|
17
22
|
[key: string]: string;
|
|
18
23
|
}): any;
|
|
24
|
+
export declare function mapValues(record: AnyObject, mapping: (v: unknown) => unknown): AnyObject;
|
|
25
|
+
export {};
|
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toAlias = exports.query = exports.getter = exports.assign = void 0;
|
|
3
|
+
exports.mapValues = exports.toAlias = exports.query = exports.getter = exports.assign = void 0;
|
|
4
4
|
function assign(src, dest, omitted) {
|
|
5
5
|
if (src && typeof src === 'object' && typeof dest === 'object') {
|
|
6
6
|
for (let ks = Object.keys(src), i = 0; i < ks.length; ++i) {
|
|
@@ -40,9 +40,9 @@ function getter(data, path) {
|
|
|
40
40
|
exports.getter = getter;
|
|
41
41
|
function query(pre, params) {
|
|
42
42
|
let str = '';
|
|
43
|
-
for (const key
|
|
43
|
+
for (const key of Object.keys(params)) {
|
|
44
44
|
const v = params[key];
|
|
45
|
-
if (v === null || v === undefined || v === '') {
|
|
45
|
+
if (v === null || v === undefined || v === '' || typeof v === 'function') {
|
|
46
46
|
continue;
|
|
47
47
|
}
|
|
48
48
|
const encoded = encodeURIComponent(v);
|
|
@@ -66,12 +66,19 @@ function toAlias(data, aliases) {
|
|
|
66
66
|
obj[key] = toAlias();
|
|
67
67
|
}
|
|
68
68
|
else if (aliases && aliases[key]) {
|
|
69
|
-
obj[aliases[key]] =
|
|
69
|
+
obj[aliases[key]] = value;
|
|
70
70
|
}
|
|
71
71
|
else {
|
|
72
|
-
obj[key] =
|
|
72
|
+
obj[key] = value;
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
return obj;
|
|
76
76
|
}
|
|
77
77
|
exports.toAlias = toAlias;
|
|
78
|
+
function mapValues(record, mapping) {
|
|
79
|
+
return Object.entries(record).reduce((acc, [key, value]) => {
|
|
80
|
+
acc[key] = mapping(value);
|
|
81
|
+
return acc;
|
|
82
|
+
}, {});
|
|
83
|
+
}
|
|
84
|
+
exports.mapValues = mapValues;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webpb",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"description": "The webpb runtime library for javascript",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"deploy": "npm run check && npm run build && npm publish ./dist --access public",
|
|
13
13
|
"test": "jest --forceExit --coverage --verbose --detectOpenHandles"
|
|
14
14
|
},
|
|
15
|
-
"author": "
|
|
15
|
+
"author": "jinganix@gmail.com",
|
|
16
16
|
"license": "Apache-2.0",
|
|
17
17
|
"keywords": [
|
|
18
18
|
"webpb",
|
|
@@ -23,21 +23,22 @@
|
|
|
23
23
|
"url": "https://github.com/linqu-tech/webpb"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@types/jest": "~
|
|
27
|
-
"@types/node": "~
|
|
28
|
-
"@typescript-eslint/eslint-plugin": "~
|
|
29
|
-
"@typescript-eslint/parser": "~
|
|
30
|
-
"eslint": "~
|
|
31
|
-
"eslint-config-prettier": "~8.
|
|
32
|
-
"eslint-plugin-import": "~2.
|
|
26
|
+
"@types/jest": "~29.5.3",
|
|
27
|
+
"@types/node": "~20.4.2",
|
|
28
|
+
"@typescript-eslint/eslint-plugin": "~6.0.0",
|
|
29
|
+
"@typescript-eslint/parser": "~6.0.0",
|
|
30
|
+
"eslint": "~8.45.0",
|
|
31
|
+
"eslint-config-prettier": "~8.8.0",
|
|
32
|
+
"eslint-plugin-import": "~2.27.5",
|
|
33
33
|
"eslint-plugin-import-quotes": "~0.0.1",
|
|
34
34
|
"eslint-plugin-no-null": "~1.0.2",
|
|
35
|
-
"eslint-plugin-prettier": "~
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"ts-
|
|
41
|
-
"
|
|
35
|
+
"eslint-plugin-prettier": "~5.0.0",
|
|
36
|
+
"eslint-plugin-sort-keys-fix": "~1.1.2",
|
|
37
|
+
"jest": "~29.6.1",
|
|
38
|
+
"prettier": "~3.0.0",
|
|
39
|
+
"pretty-quick": "~3.1.3",
|
|
40
|
+
"ts-jest": "~29.1.1",
|
|
41
|
+
"ts-node": "~10.9.1",
|
|
42
|
+
"typescript": "~5.1.6"
|
|
42
43
|
}
|
|
43
44
|
}
|