-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
100 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@vpmedia/simplify", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "@vpmedia/simplify", | ||
"author": "Andras Csizmadia <[email protected]> (www.vpmedia.hu)", | ||
"license": "MIT", | ||
|
@@ -15,7 +15,7 @@ | |
"keywords": [ | ||
"utils" | ||
], | ||
"main": "./src/index.js", | ||
"exports": "./src/index.js", | ||
"types": "./types/index.d.ts", | ||
"type": "module", | ||
"devDependencies": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,18 @@ | ||
// core | ||
import { capitalize } from './util/capitalize.js'; | ||
import { getObjValueByPath } from './util/getObjValueByPath.js'; | ||
import { getRandomInt } from './util/getRandomInt.js'; | ||
import { getURLParam } from './util/getURLParam.js'; | ||
import { sanitizeURLParam } from './util/sanitizeURLParam.js'; | ||
import { setObjValueByPath } from './util/setObjValueByPath.js'; | ||
import { underscoreToCamelCase } from './util/underscoreToCamelCase.js'; | ||
// exports | ||
export { capitalize, getRandomInt, getURLParam, sanitizeURLParam, underscoreToCamelCase }; | ||
export { | ||
capitalize, | ||
getObjValueByPath, | ||
getRandomInt, | ||
getURLParam, | ||
sanitizeURLParam, | ||
setObjValueByPath, | ||
underscoreToCamelCase, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Get object value by path. | ||
* @param {object} obj - TBD. | ||
* @param {string} path - TBD. | ||
* @returns {*} TBD. | ||
*/ | ||
export function getObjValueByPath(obj, path) { | ||
if (!obj || !path) { | ||
return; | ||
} | ||
const keyParts = path.split('.'); | ||
const nextKey = keyParts[0]; | ||
if (keyParts.length === 1) { | ||
return obj[nextKey]; | ||
} | ||
return getObjValueByPath(obj[nextKey], keyParts.slice(1).join('.')); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { getObjValueByPath } from './getObjValueByPath.js'; | ||
|
||
test('Tests getObjValueByPath', () => { | ||
const source = { a: { b: { c: 'd' } } }; | ||
expect(getObjValueByPath(source, 'a.b.c')).toBe('d'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Get object value by path. | ||
* @param {object} obj - TBD. | ||
* @param {string} path - TBD. | ||
* @param {*} value - TBD. | ||
*/ | ||
export function setObjValueByPath(obj, path, value) { | ||
if (!obj || !path) { | ||
return; | ||
} | ||
const keyParts = path.split('.'); | ||
const nextKey = keyParts[0]; | ||
if (keyParts.length === 1) { | ||
obj[nextKey] = value; | ||
} | ||
setObjValueByPath(obj[nextKey], keyParts.slice(1).join('.'), value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { getObjValueByPath } from './getObjValueByPath.js'; | ||
import { setObjValueByPath } from './setObjValueByPath.js'; | ||
|
||
test('Tests setObjValueByPath', () => { | ||
const source = { a: { b: { c: 'd' } } }; | ||
expect(getObjValueByPath(source, 'a.b.c')).toBe('d'); | ||
setObjValueByPath(source, 'a.b.c', 'newValue'); | ||
expect(getObjValueByPath(source, 'a.b.c')).toBe('newValue'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import { capitalize } from './util/capitalize.js'; | ||
import { getObjValueByPath } from './util/getObjValueByPath.js'; | ||
import { getRandomInt } from './util/getRandomInt.js'; | ||
import { getURLParam } from './util/getURLParam.js'; | ||
import { sanitizeURLParam } from './util/sanitizeURLParam.js'; | ||
import { setObjValueByPath } from './util/setObjValueByPath.js'; | ||
import { underscoreToCamelCase } from './util/underscoreToCamelCase.js'; | ||
export { capitalize, getRandomInt, getURLParam, sanitizeURLParam, underscoreToCamelCase }; | ||
export { capitalize, getObjValueByPath, getRandomInt, getURLParam, sanitizeURLParam, setObjValueByPath, underscoreToCamelCase }; | ||
//# sourceMappingURL=index.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* Returns the sum value of an array of objects field. | ||
* @param {object[]} arr - The list of input objects. | ||
* @param {string} prop - The object property key. | ||
* @returns {number} The sum value. | ||
*/ | ||
export function getObjArrayPropSum(arr: object[], prop: string): number; | ||
//# sourceMappingURL=getObjArrayPropSum.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* Get object value by path | ||
* @param {object} obj - TBD. | ||
* @param {string} path - TBD. | ||
* @returns {*} TBD. | ||
*/ | ||
export function getObjValueByPath(obj: object, path: string): any; | ||
//# sourceMappingURL=getObjValueByPath.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* Get object value by path | ||
* @param {object} obj - TBD. | ||
* @param {string} path - TBD. | ||
* @param {*} value - TBD. | ||
*/ | ||
export function setObjValueByPath(obj: object, path: string, value: any): void; | ||
//# sourceMappingURL=setObjValueByPath.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.