webpb 0.0.16 → 0.0.18
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/README.md +5 -2
- package/index.d.ts +6 -6
- package/index.js +33 -32
- package/package.json +23 -23
package/README.md
CHANGED
package/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export type Constructor<T> = {
|
|
|
5
5
|
type AnyObject = Record<string | number, unknown>;
|
|
6
6
|
export interface WebpbMessage {
|
|
7
7
|
webpbMeta(): WebpbMeta;
|
|
8
|
-
toWebpbAlias():
|
|
8
|
+
toWebpbAlias(): unknown;
|
|
9
9
|
}
|
|
10
10
|
export interface WebpbMeta {
|
|
11
11
|
class: string;
|
|
@@ -13,13 +13,13 @@ export interface WebpbMeta {
|
|
|
13
13
|
context: string;
|
|
14
14
|
path: string;
|
|
15
15
|
}
|
|
16
|
-
export declare function assign(src:
|
|
17
|
-
export declare function getter(data:
|
|
16
|
+
export declare function assign(src: unknown, dest: unknown, excludes?: string[]): void;
|
|
17
|
+
export declare function getter(data: unknown, path: string): unknown;
|
|
18
18
|
export declare function query(pre: string, params: {
|
|
19
|
-
[key: string]:
|
|
19
|
+
[key: string]: unknown;
|
|
20
20
|
}): string;
|
|
21
|
-
export declare function toAlias(data:
|
|
21
|
+
export declare function toAlias(data: unknown, aliases: {
|
|
22
22
|
[key: string]: string;
|
|
23
|
-
}):
|
|
23
|
+
}): unknown;
|
|
24
24
|
export declare function mapValues(record: AnyObject, mapping: (v: unknown) => unknown): AnyObject;
|
|
25
25
|
export {};
|
package/index.js
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.mapValues = exports.toAlias = exports.query = exports.getter = exports.assign = void 0;
|
|
4
|
-
function assign(src, dest,
|
|
5
|
-
if (src
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
function assign(src, dest, excludes) {
|
|
5
|
+
if (!src || !dest || typeof src !== "object" || typeof dest !== "object") {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
for (var _i = 0, _a = Object.entries(src); _i < _a.length; _i++) {
|
|
9
|
+
var _b = _a[_i], key = _b[0], value = _b[1];
|
|
10
|
+
if (value !== undefined && !isExcluded(key, excludes)) {
|
|
11
|
+
dest[key] = value;
|
|
10
12
|
}
|
|
11
13
|
}
|
|
12
14
|
}
|
|
13
15
|
exports.assign = assign;
|
|
14
|
-
function
|
|
15
|
-
if (!
|
|
16
|
+
function isExcluded(k, excludes) {
|
|
17
|
+
if (!excludes) {
|
|
16
18
|
return false;
|
|
17
19
|
}
|
|
18
|
-
for (
|
|
20
|
+
for (var _i = 0, excludes_1 = excludes; _i < excludes_1.length; _i++) {
|
|
21
|
+
var o = excludes_1[_i];
|
|
19
22
|
if (o === k) {
|
|
20
23
|
return true;
|
|
21
24
|
}
|
|
@@ -23,47 +26,44 @@ function isOmitted(k, omitted) {
|
|
|
23
26
|
return false;
|
|
24
27
|
}
|
|
25
28
|
function getter(data, path) {
|
|
26
|
-
if (data === null || data === undefined) {
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
if (typeof data !== 'object') {
|
|
29
|
+
if (data === null || data === undefined || typeof data !== "object") {
|
|
30
30
|
return null;
|
|
31
31
|
}
|
|
32
|
-
for (
|
|
33
|
-
|
|
32
|
+
for (var _i = 0, _a = path.split("."); _i < _a.length; _i++) {
|
|
33
|
+
var key = _a[_i];
|
|
34
|
+
data = data[key];
|
|
34
35
|
if (data === null || data === undefined) {
|
|
35
|
-
return
|
|
36
|
+
return data;
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
return data;
|
|
39
40
|
}
|
|
40
41
|
exports.getter = getter;
|
|
41
42
|
function query(pre, params) {
|
|
42
|
-
|
|
43
|
-
for (
|
|
44
|
-
|
|
45
|
-
if (
|
|
43
|
+
var queries = [];
|
|
44
|
+
for (var _i = 0, _a = Object.entries(params); _i < _a.length; _i++) {
|
|
45
|
+
var _b = _a[_i], key = _b[0], value = _b[1];
|
|
46
|
+
if (value === null || value === undefined || typeof value === "function") {
|
|
46
47
|
continue;
|
|
47
48
|
}
|
|
48
|
-
|
|
49
|
+
var encoded = encodeURIComponent(String(value));
|
|
49
50
|
if (encoded) {
|
|
50
|
-
|
|
51
|
-
pre = '&';
|
|
51
|
+
queries.push("".concat(key, "=").concat(encoded));
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
return
|
|
54
|
+
return queries.length ? "".concat(pre).concat(queries.join("&")) : "";
|
|
55
55
|
}
|
|
56
56
|
exports.query = query;
|
|
57
57
|
function toAlias(data, aliases) {
|
|
58
|
-
if (!data || typeof data !==
|
|
58
|
+
if (!data || typeof data !== "object" || Array.isArray(data)) {
|
|
59
59
|
return data;
|
|
60
60
|
}
|
|
61
|
-
|
|
62
|
-
for (
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (typeof
|
|
66
|
-
obj[key] =
|
|
61
|
+
var obj = {};
|
|
62
|
+
for (var _i = 0, _a = Object.entries(data); _i < _a.length; _i++) {
|
|
63
|
+
var _b = _a[_i], key = _b[0], value = _b[1];
|
|
64
|
+
var toAlias_1 = value["toAlias"];
|
|
65
|
+
if (typeof toAlias_1 === "function") {
|
|
66
|
+
obj[key] = toAlias_1();
|
|
67
67
|
}
|
|
68
68
|
else if (aliases && aliases[key]) {
|
|
69
69
|
obj[aliases[key]] = value;
|
|
@@ -76,7 +76,8 @@ function toAlias(data, aliases) {
|
|
|
76
76
|
}
|
|
77
77
|
exports.toAlias = toAlias;
|
|
78
78
|
function mapValues(record, mapping) {
|
|
79
|
-
return Object.entries(record).reduce((acc,
|
|
79
|
+
return Object.entries(record).reduce(function (acc, _a) {
|
|
80
|
+
var key = _a[0], value = _a[1];
|
|
80
81
|
acc[key] = mapping(value);
|
|
81
82
|
return acc;
|
|
82
83
|
}, {});
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webpb",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "The webpb runtime library
|
|
5
|
-
"main": "
|
|
6
|
-
"types": "
|
|
3
|
+
"version": "0.0.18",
|
|
4
|
+
"description": "The webpb runtime library",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"build": "tsc && cp README.md ./dist && cp package.json ./dist",
|
|
8
|
+
"build": "rimraf dist && tsc && cp README.md ./dist && cp package.json ./dist",
|
|
9
9
|
"check": "npm run lint && npm run test",
|
|
10
10
|
"lint": "eslint --quiet src/**/*.ts",
|
|
11
11
|
"lint-fix": "eslint --fix src/**/*.ts",
|
|
@@ -20,25 +20,25 @@
|
|
|
20
20
|
],
|
|
21
21
|
"repository": {
|
|
22
22
|
"type": "git",
|
|
23
|
-
"url": "https://github.com/
|
|
23
|
+
"url": "https://github.com/jinganix/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": "
|
|
32
|
-
"eslint-plugin-import": "
|
|
33
|
-
"eslint-plugin-import-quotes": "
|
|
34
|
-
"eslint-plugin-no-null": "
|
|
35
|
-
"eslint-plugin-prettier": "
|
|
36
|
-
"eslint-plugin-sort-keys-fix": "
|
|
37
|
-
"jest": "
|
|
38
|
-
"prettier": "
|
|
39
|
-
"pretty-quick": "
|
|
40
|
-
"ts-jest": "
|
|
41
|
-
"ts-node": "
|
|
42
|
-
"typescript": "
|
|
26
|
+
"@types/jest": "^29.5.12",
|
|
27
|
+
"@types/node": "^20.12.7",
|
|
28
|
+
"@typescript-eslint/eslint-plugin": "^7.7.1",
|
|
29
|
+
"@typescript-eslint/parser": "^7.7.1",
|
|
30
|
+
"eslint": "^8.57.0",
|
|
31
|
+
"eslint-config-prettier": "^9.1.0",
|
|
32
|
+
"eslint-plugin-import": "^2.29.1",
|
|
33
|
+
"eslint-plugin-import-quotes": "^0.0.1",
|
|
34
|
+
"eslint-plugin-no-null": "^1.0.2",
|
|
35
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
36
|
+
"eslint-plugin-sort-keys-fix": "^1.1.2",
|
|
37
|
+
"jest": "^29.7.0",
|
|
38
|
+
"prettier": "^3.2.5",
|
|
39
|
+
"pretty-quick": "^4.0.0",
|
|
40
|
+
"ts-jest": "^29.1.2",
|
|
41
|
+
"ts-node": "^10.9.2",
|
|
42
|
+
"typescript": "^5.4.5"
|
|
43
43
|
}
|
|
44
44
|
}
|