@vpmedia/simplify 1.17.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.17.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vpmedia/simplify",
3
- "version": "1.17.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",
@@ -20,17 +20,17 @@
20
20
  "type": "module",
21
21
  "devDependencies": {
22
22
  "@babel/preset-env": "^7.26.9",
23
- "@eslint/js": "^9.21.0",
23
+ "@eslint/js": "^9.23.0",
24
24
  "@jest/globals": "^29.7.0",
25
25
  "@types/jest": "^29.5.14",
26
- "eslint": "^9.22.0",
27
- "eslint-plugin-jsdoc": "^50.6.3",
28
- "eslint-plugin-unicorn": "^57.0.0",
26
+ "eslint": "^9.24.0",
27
+ "eslint-plugin-jsdoc": "^50.6.9",
28
+ "eslint-plugin-unicorn": "^58.0.0",
29
29
  "globals": "^16.0.0",
30
30
  "jest": "^29.7.0",
31
31
  "jest-environment-jsdom": "^29.7.0",
32
32
  "prettier": "^3.5.3",
33
- "typescript": "^5.8.2"
33
+ "typescript": "^5.8.3"
34
34
  },
35
35
  "scripts": {
36
36
  "test": "NODE_OPTIONS=--experimental-vm-modules jest --passWithNoTests",
package/src/index.js CHANGED
@@ -7,6 +7,7 @@ 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
13
  export { FetchError, fetchRetry, HTTP_0_ANY } from './util/fetchRetry.js';
@@ -19,5 +20,7 @@ export { purgeObject } from './util/purgeObject.js';
19
20
  export { addFloat, fixFloat, subFloat } from './util/safeFloat.js';
20
21
  export { sanitizeURLParam } from './util/sanitizeURLParam.js';
21
22
  export { saveAsFile } from './util/saveAsFile.js';
23
+ export { serverDataToState } from './util/serverDataToState.js';
22
24
  export { setObjValueByPath } from './util/setObjValueByPath.js';
23
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, HTTP_422_UNPROCESSABLE_ENTITY } 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
 
@@ -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,6 +6,7 @@ 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";
@@ -16,6 +17,7 @@ export { loadJSON } from "./util/loadJSON.js";
16
17
  export { purgeObject } from "./util/purgeObject.js";
17
18
  export { sanitizeURLParam } from "./util/sanitizeURLParam.js";
18
19
  export { saveAsFile } from "./util/saveAsFile.js";
20
+ export { serverDataToState } from "./util/serverDataToState.js";
19
21
  export { setObjValueByPath } from "./util/setObjValueByPath.js";
20
22
  export { underscoreToCamelCase } from "./util/underscoreToCamelCase.js";
21
23
  export { FetchError, fetchRetry, HTTP_0_ANY } from "./util/fetchRetry.js";
@@ -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,CA2C7B"}
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,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"}