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.
Files changed (4) hide show
  1. package/README.md +5 -2
  2. package/index.d.ts +6 -6
  3. package/index.js +33 -32
  4. package/package.json +23 -23
package/README.md CHANGED
@@ -1,2 +1,5 @@
1
- # webpb-runtime
2
- Webpb runtime library for npm
1
+ # webpb
2
+
3
+ The webpb runtime library
4
+
5
+ To view more, please visit: https://github.com/jinganix/webpb
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(): any;
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: any, dest: any, omitted?: string[]): void;
17
- export declare function getter(data: any, path: string): any;
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]: any;
19
+ [key: string]: unknown;
20
20
  }): string;
21
- export declare function toAlias(data: any, aliases: {
21
+ export declare function toAlias(data: unknown, aliases: {
22
22
  [key: string]: string;
23
- }): any;
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, omitted) {
5
- if (src && typeof src === 'object' && typeof dest === 'object') {
6
- for (let ks = Object.keys(src), i = 0; i < ks.length; ++i) {
7
- if (src[ks[i]] != undefined && !isOmitted(ks[i], omitted)) {
8
- dest[ks[i]] = src[ks[i]];
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 isOmitted(k, omitted) {
15
- if (!omitted) {
16
+ function isExcluded(k, excludes) {
17
+ if (!excludes) {
16
18
  return false;
17
19
  }
18
- for (const o of omitted) {
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 (const k of path.split('.')) {
33
- data = data[k];
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 null;
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
- let str = '';
43
- for (const key of Object.keys(params)) {
44
- const v = params[key];
45
- if (v === null || v === undefined || v === '' || typeof v === 'function') {
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
- const encoded = encodeURIComponent(v);
49
+ var encoded = encodeURIComponent(String(value));
49
50
  if (encoded) {
50
- str += `${pre}${key}=${encodeURIComponent(v)}`;
51
- pre = '&';
51
+ queries.push("".concat(key, "=").concat(encoded));
52
52
  }
53
53
  }
54
- return str;
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 !== 'object' || Array.isArray(data)) {
58
+ if (!data || typeof data !== "object" || Array.isArray(data)) {
59
59
  return data;
60
60
  }
61
- const obj = {};
62
- for (const key of Object.keys(data)) {
63
- const value = data[key];
64
- const toAlias = value['toAlias'];
65
- if (typeof toAlias === 'function') {
66
- obj[key] = toAlias();
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, [key, value]) => {
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.16",
4
- "description": "The webpb runtime library for javascript",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
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/linqu-tech/webpb"
23
+ "url": "https://github.com/jinganix/webpb"
24
24
  },
25
25
  "devDependencies": {
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
- "eslint-plugin-import-quotes": "~0.0.1",
34
- "eslint-plugin-no-null": "~1.0.2",
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"
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
  }