@vpmedia/simplify 1.16.0 → 1.18.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @vpmedia/simplify
2
2
 
3
- [![npm version](https://badge.fury.io/js/@vpmedia%2Fsimplify.svg?v=1.16.0)](https://badge.fury.io/js/@vpmedia%2Fsimplify)
3
+ [![npm version](https://badge.fury.io/js/@vpmedia%2Fsimplify.svg?v=1.18.0)](https://badge.fury.io/js/@vpmedia%2Fsimplify)
4
4
  [![Node.js CI](https://github.com/vpmedia/simplify/actions/workflows/ci.yml/badge.svg)](https://github.com/vpmedia/simplify/actions/workflows/ci.yml)
5
5
 
6
6
  @vpmedia/simplify TBD
package/lefthook.yml CHANGED
@@ -1,7 +1,3 @@
1
- # Copyright (c) Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
2
- # author: Andras Csizmadia <andras@vpmedia.hu>
3
- # see: https://github.com/evilmartians/lefthook/blob/master/docs/configuration.md
4
-
5
1
  pre-commit:
6
2
  parallel: false
7
3
  commands:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vpmedia/simplify",
3
- "version": "1.16.0",
3
+ "version": "1.18.0",
4
4
  "description": "@vpmedia/simplify",
5
5
  "author": "Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)",
6
6
  "license": "MIT",
@@ -19,32 +19,30 @@
19
19
  "types": "./types/index.d.ts",
20
20
  "type": "module",
21
21
  "devDependencies": {
22
- "@babel/preset-env": "^7.26.0",
23
- "@eslint/js": "^9.15.0",
22
+ "@babel/preset-env": "^7.26.9",
23
+ "@eslint/js": "^9.23.0",
24
24
  "@jest/globals": "^29.7.0",
25
25
  "@types/jest": "^29.5.14",
26
- "eslint": "^9.15.0",
27
- "eslint-plugin-jsdoc": "^50.5.0",
28
- "eslint-plugin-unicorn": "^56.0.1",
29
- "globals": "^15.12.0",
26
+ "eslint": "^9.24.0",
27
+ "eslint-plugin-jsdoc": "^50.6.9",
28
+ "eslint-plugin-unicorn": "^58.0.0",
29
+ "globals": "^16.0.0",
30
30
  "jest": "^29.7.0",
31
31
  "jest-environment-jsdom": "^29.7.0",
32
- "lefthook": "^1.8.4",
33
- "prettier": "^3.3.3",
34
- "typescript": "^5.7.2"
32
+ "prettier": "^3.5.3",
33
+ "typescript": "^5.8.3"
35
34
  },
36
35
  "scripts": {
37
36
  "test": "NODE_OPTIONS=--experimental-vm-modules jest --passWithNoTests",
38
37
  "lint": "eslint \"**/*.{js,jsx}\"",
39
38
  "typecheck": "tsc",
40
- "format": "prettier --write \"./**/*.{js,jsx,mjs,cjs,ts,tsx,json,md,css}\"",
41
- "lefthook:install": "lefthook install",
42
- "lefthook:uninstall": "lefthook uninstall"
39
+ "format": "prettier --write \"./**/*.{js,jsx,mjs,cjs,ts,tsx,json,md,css}\""
43
40
  },
44
41
  "browserslist": [
45
42
  "> 0.5%",
46
43
  "not dead",
47
- "not op_mini all"
44
+ "not op_mini all",
45
+ "iOS >= 14"
48
46
  ],
49
47
  "dependencies": {
50
48
  "eventemitter3": "^5.0.1"
package/src/index.js CHANGED
@@ -7,16 +7,20 @@ export * from './pagelifecycle/typedef.js';
7
7
  export * from './pagelifecycle/util.js';
8
8
  export { addLeadingZero } from './util/addLeadingZero.js';
9
9
  export { capitalize } from './util/capitalize.js';
10
+ export { deepMerge } from './util/deepMerge.js';
10
11
  export { deg2rad } from './util/deg2rad.js';
11
12
  export { delayPromise } from './util/delayPromise.js';
12
- export { FetchError, HTTP_0_ANY, fetchRetry } from './util/fetchRetry.js';
13
+ export { FetchError, fetchRetry, HTTP_0_ANY } from './util/fetchRetry.js';
13
14
  export { fixFloatPrecision } from './util/fixFloatPrecision.js';
14
15
  export { getObjValueByPath } from './util/getObjValueByPath.js';
15
16
  export { getRandomInt } from './util/getRandomInt.js';
16
17
  export { getURLParam } from './util/getURLParam.js';
18
+ export { loadJSON } from './util/loadJSON.js';
17
19
  export { purgeObject } from './util/purgeObject.js';
18
20
  export { addFloat, fixFloat, subFloat } from './util/safeFloat.js';
19
21
  export { sanitizeURLParam } from './util/sanitizeURLParam.js';
20
22
  export { saveAsFile } from './util/saveAsFile.js';
23
+ export { serverDataToState } from './util/serverDataToState.js';
21
24
  export { setObjValueByPath } from './util/setObjValueByPath.js';
22
25
  export { underscoreToCamelCase } from './util/underscoreToCamelCase.js';
26
+
@@ -0,0 +1,23 @@
1
+ /**
2
+ * TBD.
3
+ * @param {object} target - TBD.
4
+ * @param {object} source - TBD.
5
+ * @returns {object} TBD.
6
+ */
7
+ export const deepMerge = (target, source) => {
8
+ if (typeof target !== 'object' || target === null) return source;
9
+ if (typeof source !== 'object' || source === null) return target;
10
+
11
+ for (const key of Object.keys(source)) {
12
+ if (typeof source[key] === 'object' && source[key] !== null) {
13
+ if (!target[key] || typeof target[key] !== 'object') {
14
+ target[key] = {};
15
+ }
16
+ deepMerge(target[key], source[key]);
17
+ } else {
18
+ target[key] = source[key];
19
+ }
20
+ }
21
+
22
+ return target;
23
+ };
@@ -0,0 +1,25 @@
1
+ import { deepMerge } from './deepMerge.js';
2
+
3
+ describe('deepMerge', () => {
4
+ test('should override deep properties correctly', () => {
5
+ const defaultObj = { a: { b: 1, c: 2 }, d: 3 };
6
+ const overrideObj = { a: { b: 42 } };
7
+ const expectedResult = { a: { b: 42, c: 2 }, d: 3 };
8
+
9
+ expect(deepMerge({ ...defaultObj }, overrideObj)).toEqual(expectedResult);
10
+ });
11
+
12
+ test('should not modify the original target object', () => {
13
+ const target = { x: { y: 10 } };
14
+ const source = { x: { y: 20 } };
15
+ const copy = { ...target };
16
+
17
+ deepMerge(target, source);
18
+ expect(target).toEqual(copy);
19
+ });
20
+
21
+ test('should handle non-object values correctly', () => {
22
+ expect(deepMerge(null, { a: 1 })).toEqual({ a: 1 });
23
+ expect(deepMerge({ a: 1 }, null)).toEqual({ a: 1 });
24
+ });
25
+ });
@@ -1,4 +1,9 @@
1
- import { HTTP_401_UNAUTHORIZED, HTTP_403_FORBIDDEN, HTTP_405_METHOD_NOT_ALLOWED } from '../const/http_status.js';
1
+ import {
2
+ HTTP_401_UNAUTHORIZED,
3
+ HTTP_403_FORBIDDEN,
4
+ HTTP_405_METHOD_NOT_ALLOWED,
5
+ HTTP_422_UNPROCESSABLE_ENTITY,
6
+ } from '../const/http_status.js';
2
7
  import { Logger } from '../logging/Logger.js';
3
8
  import { delayPromise } from './delayPromise.js';
4
9
 
@@ -38,6 +43,7 @@ export const fetchRetry = async (resource, fetchOptions, retryOptions) => {
38
43
  HTTP_401_UNAUTHORIZED,
39
44
  HTTP_403_FORBIDDEN,
40
45
  HTTP_405_METHOD_NOT_ALLOWED,
46
+ HTTP_422_UNPROCESSABLE_ENTITY,
41
47
  ];
42
48
  while (retryOptions.numTries > 0) {
43
49
  logger.info('request', { resource, fetchOptions, retryOptions });
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Load JSON file using a fetch GET request.
3
+ * @param {string} url - URL to load.
4
+ * @returns {Promise<string>} The parsed JSON data.
5
+ */
6
+ export async function loadJSON(url) {
7
+ const response = await fetch(url);
8
+ const json = await response.json();
9
+ return JSON.stringify(json);
10
+ }
@@ -0,0 +1,15 @@
1
+ import { underscoreToCamelCase } from './underscoreToCamelCase.js';
2
+
3
+ /**
4
+ * Maps server data to client data.
5
+ * @param {object} data - The server input data.
6
+ * @returns {object} The output data.
7
+ */
8
+ export const serverDataToState = (data) => {
9
+ const result = {};
10
+ for (const serverKey of Object.keys(data)) {
11
+ const clientKey = underscoreToCamelCase(serverKey);
12
+ result[clientKey] = data[serverKey];
13
+ }
14
+ return result;
15
+ };
@@ -0,0 +1,8 @@
1
+ import { serverDataToState } from './serverDataToState.js';
2
+
3
+ test('serverDataToState()', () => {
4
+ const state = serverDataToState({ balance: 1000, my_var: 'test', my_list: [1, 2, 3] });
5
+ expect(state.balance).toBe(1000);
6
+ expect(state.myVar).toBe('test');
7
+ expect(state.myList[0]).toBe(1);
8
+ });
package/types/index.d.ts CHANGED
@@ -6,17 +6,20 @@ export * from "./pagelifecycle/util.js";
6
6
  export { Logger } from "./logging/Logger.js";
7
7
  export { addLeadingZero } from "./util/addLeadingZero.js";
8
8
  export { capitalize } from "./util/capitalize.js";
9
+ export { deepMerge } from "./util/deepMerge.js";
9
10
  export { deg2rad } from "./util/deg2rad.js";
10
11
  export { delayPromise } from "./util/delayPromise.js";
11
12
  export { fixFloatPrecision } from "./util/fixFloatPrecision.js";
12
13
  export { getObjValueByPath } from "./util/getObjValueByPath.js";
13
14
  export { getRandomInt } from "./util/getRandomInt.js";
14
15
  export { getURLParam } from "./util/getURLParam.js";
16
+ export { loadJSON } from "./util/loadJSON.js";
15
17
  export { purgeObject } from "./util/purgeObject.js";
16
18
  export { sanitizeURLParam } from "./util/sanitizeURLParam.js";
17
19
  export { saveAsFile } from "./util/saveAsFile.js";
20
+ export { serverDataToState } from "./util/serverDataToState.js";
18
21
  export { setObjValueByPath } from "./util/setObjValueByPath.js";
19
22
  export { underscoreToCamelCase } from "./util/underscoreToCamelCase.js";
20
- export { FetchError, HTTP_0_ANY, fetchRetry } from "./util/fetchRetry.js";
23
+ export { FetchError, fetchRetry, HTTP_0_ANY } from "./util/fetchRetry.js";
21
24
  export { addFloat, fixFloat, subFloat } from "./util/safeFloat.js";
22
25
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/pagelifecycle/util.js"],"names":[],"mappings":"AAsCO,gDAHI,OAAO,cAAc,EAAE,aAAa,GAAG,OAAO,cAAc,EAAE,kBAAkB,YAChF,MAAM,IAAI,QAMpB;AAgEM,0CAsBN;AAMM,yCAFM,MAAM,CAIlB;AAMM,oCAFM,OAAO,cAAc,EAAE,aAAa,CAIhD;AAMM,gDAFM,YAAY,CAOxB;AAMM,8CAFM,OAAO,CAInB;6BA9J4B,eAAe"}
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/pagelifecycle/util.js"],"names":[],"mappings":"AAsCO,gDAHI,OAAO,cAAc,EAAE,aAAa,GAAG,OAAO,cAAc,EAAE,kBAAkB,YAChF,MAAM,IAAI,QAMpB;AAgEM,0CAyBN;AAMM,yCAFM,MAAM,CAIlB;AAMM,oCAFM,OAAO,cAAc,EAAE,aAAa,CAIhD;AAMM,gDAFM,YAAY,CAOxB;AAMM,8CAFM,OAAO,CAInB;6BAjK4B,eAAe"}
@@ -0,0 +1,2 @@
1
+ export function deepMerge(target: object, source: object): object;
2
+ //# sourceMappingURL=deepMerge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deepMerge.d.ts","sourceRoot":"","sources":["../../src/util/deepMerge.js"],"names":[],"mappings":"AAMO,kCAJI,MAAM,UACN,MAAM,GACJ,MAAM,CAkBlB"}
@@ -1 +1 @@
1
- {"version":3,"file":"fetchRetry.d.ts","sourceRoot":"","sources":["../../src/util/fetchRetry.js"],"names":[],"mappings":"AAMA,yBAA0B,CAAC,CAAC;AAE5B;IACE;;;;;;OAMG;IACH,qBALW,MAAM,YACN,MAAM,GAAG,GAAG,GAAG,OAAO,gBACtB,WAAW,YACX,QAAQ,EAQlB;IAHC,iCAAwB;IACxB,0BAAgC;IAChC,mBAAwB;CAE3B;AASM,qCALI,MAAM,GAAG,GAAG,GAAG,OAAO,iBACtB,WAAW,iBACX;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;CAAC,GAC5D,OAAO,CAAC,QAAQ,CAAC,CA0C7B"}
1
+ {"version":3,"file":"fetchRetry.d.ts","sourceRoot":"","sources":["../../src/util/fetchRetry.js"],"names":[],"mappings":"AAWA,yBAA0B,CAAC,CAAC;AAE5B;IACE;;;;;;OAMG;IACH,qBALW,MAAM,YACN,MAAM,GAAG,GAAG,GAAG,OAAO,gBACtB,WAAW,YACX,QAAQ,EAQlB;IAHC,iCAAwB;IACxB,0BAAgC;IAChC,mBAAwB;CAE3B;AASM,qCALI,MAAM,GAAG,GAAG,GAAG,OAAO,iBACtB,WAAW,iBACX;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;CAAC,GAC5D,OAAO,CAAC,QAAQ,CAAC,CA2C7B"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Load JSON file using a fetch GET request.
3
+ * @param {string} url - URL to load.
4
+ * @returns {Promise<string>} The parsed JSON data.
5
+ */
6
+ export function loadJSON(url: string): Promise<string>;
7
+ //# sourceMappingURL=loadJSON.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadJSON.d.ts","sourceRoot":"","sources":["../../src/util/loadJSON.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,8BAHW,MAAM,GACJ,OAAO,CAAC,MAAM,CAAC,CAM3B"}
@@ -0,0 +1,2 @@
1
+ export function serverDataToState(data: object): object;
2
+ //# sourceMappingURL=serverDataToState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serverDataToState.d.ts","sourceRoot":"","sources":["../../src/util/serverDataToState.js"],"names":[],"mappings":"AAOO,wCAHI,MAAM,GACJ,MAAM,CASlB"}