@vpmedia/simplify 1.0.1 → 1.0.3
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/CHANGES.md +8 -0
- package/README.md +1 -1
- package/lefthook.yml +13 -0
- package/package.json +9 -10
- package/src/index.js +11 -1
- package/src/util/getObjArrayPropSum.js +11 -0
- package/src/util/getObjValueByPath.js +17 -0
- package/src/util/getObjValueByPath.test.js +6 -0
- package/src/util/setObjValueByPath.js +17 -0
- package/src/util/setObjValueByPath.test.js +9 -0
- package/types/index.d.ts +7 -1
- package/types/index.d.ts.map +1 -1
- package/types/util/getObjArrayPropSum.d.ts +8 -0
- package/types/util/getObjArrayPropSum.d.ts.map +1 -0
- package/types/util/getObjValueByPath.d.ts +8 -0
- package/types/util/getObjValueByPath.d.ts.map +1 -0
- package/types/util/setObjValueByPath.d.ts +8 -0
- package/types/util/setObjValueByPath.d.ts.map +1 -0
- package/types/util/underscoreToCamelCase.d.ts +1 -1
package/CHANGES.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
|
5
5
|
|
|
6
|
+
## 1.0.3
|
|
7
|
+
|
|
8
|
+
- Added deep object value getter / setter helpers
|
|
9
|
+
|
|
10
|
+
## 1.0.2
|
|
11
|
+
|
|
12
|
+
- Added missing typescript typedefs
|
|
13
|
+
|
|
6
14
|
## 1.0.1
|
|
7
15
|
|
|
8
16
|
- Changed export name, fixed input check
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @vpmedia/simplify
|
|
2
2
|
|
|
3
|
-
[](https://badge.fury.io/js/@vpmedia%2Fsimplify)
|
|
4
4
|
[](https://github.com/vpmedia/simplify/actions/workflows/node.js.yml)
|
|
5
5
|
|
|
6
6
|
@vpmedia/simplify TBD
|
package/lefthook.yml
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
pre-commit:
|
|
6
|
+
parallel: false
|
|
7
|
+
commands:
|
|
8
|
+
lint:
|
|
9
|
+
glob: "*.{js,ts,jsx,tsx}"
|
|
10
|
+
run: |
|
|
11
|
+
set -e
|
|
12
|
+
./node_modules/.bin/eslint --fix {staged_files}
|
|
13
|
+
git add {staged_files} &> /dev/null || true
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vpmedia/simplify",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "@vpmedia/simplify",
|
|
5
5
|
"author": "Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,23 +15,22 @@
|
|
|
15
15
|
"keywords": [
|
|
16
16
|
"utils"
|
|
17
17
|
],
|
|
18
|
-
"
|
|
18
|
+
"exports": "./src/index.js",
|
|
19
19
|
"types": "./types/index.d.ts",
|
|
20
20
|
"type": "module",
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@babel/preset-env": "^7.23.2",
|
|
23
23
|
"@jest/globals": "^29.7.0",
|
|
24
|
-
"@types/jest": "^29.5.
|
|
25
|
-
"eslint": "^8.
|
|
24
|
+
"@types/jest": "^29.5.7",
|
|
25
|
+
"eslint": "^8.52.0",
|
|
26
26
|
"eslint-config-prettier": "^9.0.0",
|
|
27
|
-
"eslint-plugin-import": "^2.
|
|
28
|
-
"eslint-plugin-jest": "^27.
|
|
27
|
+
"eslint-plugin-import": "^2.29.0",
|
|
28
|
+
"eslint-plugin-jest": "^27.6.0",
|
|
29
29
|
"eslint-plugin-jsdoc": "^46.8.2",
|
|
30
30
|
"eslint-plugin-prettier": "^5.0.1",
|
|
31
|
-
"husky": "^8.0.3",
|
|
32
31
|
"jest": "^29.7.0",
|
|
33
32
|
"jest-environment-jsdom": "^29.7.0",
|
|
34
|
-
"
|
|
33
|
+
"lefthook": "^1.5.2",
|
|
35
34
|
"prettier": "^3.0.3",
|
|
36
35
|
"typescript": "^5.2.2"
|
|
37
36
|
},
|
|
@@ -40,8 +39,8 @@
|
|
|
40
39
|
"lint": "eslint --fix \"**/*.{js,jsx}\"",
|
|
41
40
|
"typecheck": "tsc",
|
|
42
41
|
"format": "prettier --write \"**/*.{css,js,jsx,json,md}\"",
|
|
43
|
-
"
|
|
44
|
-
"
|
|
42
|
+
"lefthook:install": "lefthook install",
|
|
43
|
+
"lefthook:uninstall": "lefthook uninstall"
|
|
45
44
|
},
|
|
46
45
|
"browserslist": [
|
|
47
46
|
"> 1%",
|
package/src/index.js
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
// core
|
|
2
2
|
import { capitalize } from './util/capitalize.js';
|
|
3
|
+
import { getObjValueByPath } from './util/getObjValueByPath.js';
|
|
3
4
|
import { getRandomInt } from './util/getRandomInt.js';
|
|
4
5
|
import { getURLParam } from './util/getURLParam.js';
|
|
5
6
|
import { sanitizeURLParam } from './util/sanitizeURLParam.js';
|
|
7
|
+
import { setObjValueByPath } from './util/setObjValueByPath.js';
|
|
6
8
|
import { underscoreToCamelCase } from './util/underscoreToCamelCase.js';
|
|
7
9
|
// exports
|
|
8
|
-
export {
|
|
10
|
+
export {
|
|
11
|
+
capitalize,
|
|
12
|
+
getObjValueByPath,
|
|
13
|
+
getRandomInt,
|
|
14
|
+
getURLParam,
|
|
15
|
+
sanitizeURLParam,
|
|
16
|
+
setObjValueByPath,
|
|
17
|
+
underscoreToCamelCase,
|
|
18
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the sum value of an array of objects field.
|
|
3
|
+
* @param {object[]} arr - The list of input objects.
|
|
4
|
+
* @param {string} prop - The object property key.
|
|
5
|
+
* @returns {number} The sum value.
|
|
6
|
+
*/
|
|
7
|
+
export function getObjArrayPropSum(arr, prop) {
|
|
8
|
+
return arr.reduce((accumulator, object) => {
|
|
9
|
+
return accumulator + object[prop];
|
|
10
|
+
}, 0);
|
|
11
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get object value by path.
|
|
3
|
+
* @param {object} obj - TBD.
|
|
4
|
+
* @param {string} path - TBD.
|
|
5
|
+
* @returns {*} TBD.
|
|
6
|
+
*/
|
|
7
|
+
export function getObjValueByPath(obj, path) {
|
|
8
|
+
if (!obj || !path) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const keyParts = path.split('.');
|
|
12
|
+
const nextKey = keyParts[0];
|
|
13
|
+
if (keyParts.length === 1) {
|
|
14
|
+
return obj[nextKey];
|
|
15
|
+
}
|
|
16
|
+
return getObjValueByPath(obj[nextKey], keyParts.slice(1).join('.'));
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get object value by path.
|
|
3
|
+
* @param {object} obj - TBD.
|
|
4
|
+
* @param {string} path - TBD.
|
|
5
|
+
* @param {*} value - TBD.
|
|
6
|
+
*/
|
|
7
|
+
export function setObjValueByPath(obj, path, value) {
|
|
8
|
+
if (!obj || !path) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const keyParts = path.split('.');
|
|
12
|
+
const nextKey = keyParts[0];
|
|
13
|
+
if (keyParts.length === 1) {
|
|
14
|
+
obj[nextKey] = value;
|
|
15
|
+
}
|
|
16
|
+
setObjValueByPath(obj[nextKey], keyParts.slice(1).join('.'), value);
|
|
17
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { getObjValueByPath } from './getObjValueByPath.js';
|
|
2
|
+
import { setObjValueByPath } from './setObjValueByPath.js';
|
|
3
|
+
|
|
4
|
+
test('Tests setObjValueByPath', () => {
|
|
5
|
+
const source = { a: { b: { c: 'd' } } };
|
|
6
|
+
expect(getObjValueByPath(source, 'a.b.c')).toBe('d');
|
|
7
|
+
setObjValueByPath(source, 'a.b.c', 'newValue');
|
|
8
|
+
expect(getObjValueByPath(source, 'a.b.c')).toBe('newValue');
|
|
9
|
+
});
|
package/types/index.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
export { capitalize };
|
|
2
1
|
import { capitalize } from './util/capitalize.js';
|
|
2
|
+
import { getObjValueByPath } from './util/getObjValueByPath.js';
|
|
3
|
+
import { getRandomInt } from './util/getRandomInt.js';
|
|
4
|
+
import { getURLParam } from './util/getURLParam.js';
|
|
5
|
+
import { sanitizeURLParam } from './util/sanitizeURLParam.js';
|
|
6
|
+
import { setObjValueByPath } from './util/setObjValueByPath.js';
|
|
7
|
+
import { underscoreToCamelCase } from './util/underscoreToCamelCase.js';
|
|
8
|
+
export { capitalize, getObjValueByPath, getRandomInt, getURLParam, sanitizeURLParam, setObjValueByPath, underscoreToCamelCase };
|
|
3
9
|
//# sourceMappingURL=index.d.ts.map
|
package/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"2BAC2B,sBAAsB;kCACf,6BAA6B;6BAClC,wBAAwB;4BACzB,uBAAuB;iCAClB,4BAA4B;kCAC3B,6BAA6B;sCACzB,iCAAiC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the sum value of an array of objects field.
|
|
3
|
+
* @param {object[]} arr - The list of input objects.
|
|
4
|
+
* @param {string} prop - The object property key.
|
|
5
|
+
* @returns {number} The sum value.
|
|
6
|
+
*/
|
|
7
|
+
export function getObjArrayPropSum(arr: object[], prop: string): number;
|
|
8
|
+
//# sourceMappingURL=getObjArrayPropSum.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getObjArrayPropSum.d.ts","sourceRoot":"","sources":["../../src/util/getObjArrayPropSum.js"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wCAJW,MAAM,EAAE,QACR,MAAM,GACJ,MAAM,CAMlB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getObjValueByPath.d.ts","sourceRoot":"","sources":["../../src/util/getObjValueByPath.js"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,uCAJW,MAAM,QACN,MAAM,OAahB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setObjValueByPath.d.ts","sourceRoot":"","sources":["../../src/util/setObjValueByPath.js"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,uCAJW,MAAM,QACN,MAAM,oBAahB"}
|
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
* @param {string} value - The input string in underscore case.
|
|
4
4
|
* @returns {string} The output string in camel case.
|
|
5
5
|
*/
|
|
6
|
-
export function
|
|
6
|
+
export function underscoreToCamelCase(value: string): string;
|
|
7
7
|
//# sourceMappingURL=underscoreToCamelCase.d.ts.map
|