Skip to content

Commit

Permalink
Release v1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
vpmedia committed Nov 5, 2023
1 parent adffaaa commit afb9c42
Show file tree
Hide file tree
Showing 17 changed files with 100 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## 1.0.3

- Added deep object value getter / setter helpers

## 1.0.2

- Added missing typescript typedefs
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# @vpmedia/simplify

[![npm version](https://badge.fury.io/js/@vpmedia%2Fsimplify.svg?v=1.0.2)](https://badge.fury.io/js/@vpmedia%2Fsimplify)
[![npm version](https://badge.fury.io/js/@vpmedia%2Fsimplify.svg?v=1.0.3)](https://badge.fury.io/js/@vpmedia%2Fsimplify)
[![Node.js CI](https://github.com/vpmedia/simplify/actions/workflows/node.js.yml/badge.svg)](https://github.com/vpmedia/simplify/actions/workflows/node.js.yml)

@vpmedia/simplify TBD
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
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",
Expand All @@ -15,7 +15,7 @@
"keywords": [
"utils"
],
"main": "./src/index.js",
"exports": "./src/index.js",
"types": "./types/index.d.ts",
"type": "module",
"devDependencies": {
Expand Down
12 changes: 11 additions & 1 deletion src/index.js
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,
};
17 changes: 17 additions & 0 deletions src/util/getObjValueByPath.js
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('.'));
}
6 changes: 6 additions & 0 deletions src/util/getObjValueByPath.test.js
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');
});
17 changes: 17 additions & 0 deletions src/util/setObjValueByPath.js
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);
}
9 changes: 9 additions & 0 deletions src/util/setObjValueByPath.test.js
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');
});
4 changes: 3 additions & 1 deletion types/index.d.ts
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
2 changes: 1 addition & 1 deletion types/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions types/util/getObjArrayPropSum.d.ts
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
1 change: 1 addition & 0 deletions types/util/getObjArrayPropSum.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions types/util/getObjValueByPath.d.ts
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
1 change: 1 addition & 0 deletions types/util/getObjValueByPath.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions types/util/setObjValueByPath.d.ts
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
1 change: 1 addition & 0 deletions types/util/setObjValueByPath.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit afb9c42

Please sign in to comment.