@bscotch/utility
Advanced tools
Comparing version 0.7.1 to 0.8.0
@@ -5,2 +5,3 @@ export * from "./lib/strings"; | ||
export * from "./lib/wait"; | ||
export * from "./lib/objects"; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -17,2 +17,3 @@ "use strict"; | ||
__exportStar(require("./lib/wait"), exports); | ||
__exportStar(require("./lib/objects"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -0,1 +1,10 @@ | ||
# [0.8.0](https://github.com/bscotch/node-util/compare/v0.7.1...v0.8.0) (2020-11-17) | ||
### Features | ||
* Object path and related functions added. ([6ebcd72](https://github.com/bscotch/node-util/commit/6ebcd727bb86be26373caf4834e6247975590b40)) | ||
## [0.7.1](https://github.com/bscotch/node-util/compare/v0.7.0...v0.7.1) (2020-11-12) | ||
@@ -2,0 +11,0 @@ |
{ | ||
"name": "@bscotch/utility", | ||
"version": "0.7.1", | ||
"version": "0.8.0", | ||
"description": "Bscotch Utilities: Methods for common Node.js needs.", | ||
@@ -41,17 +41,17 @@ "engines": { | ||
"devDependencies": { | ||
"@types/chai": "^4.2.12", | ||
"@types/fs-extra": "^9.0.2", | ||
"@types/mocha": "^8.0.3", | ||
"@types/node": "^14.6.4", | ||
"@typescript-eslint/eslint-plugin": "^4.3.0", | ||
"@typescript-eslint/parser": "^4.3.0", | ||
"@types/chai": "^4.2.14", | ||
"@types/fs-extra": "^9.0.4", | ||
"@types/mocha": "^8.0.4", | ||
"@types/node": "^14.14.7", | ||
"@typescript-eslint/eslint-plugin": "^4.8.1", | ||
"@typescript-eslint/parser": "^4.8.1", | ||
"chai": "^4.2.0", | ||
"conventional-changelog-cli": "^2.1.0", | ||
"eslint": "^7.8.1", | ||
"conventional-changelog-cli": "^2.1.1", | ||
"eslint": "^7.13.0", | ||
"fs-extra": "^9.0.1", | ||
"mocha": "^8.1.3", | ||
"mocha": "^8.2.1", | ||
"source-map-support": "^0.5.19", | ||
"ts-node": "^9.0.0", | ||
"typescript": "^4.0.2" | ||
"typescript": "^4.0.5" | ||
} | ||
} |
@@ -145,1 +145,49 @@ # Bscotch Utilities | ||
``` | ||
## Objects | ||
```ts | ||
import { | ||
isPlainObject, | ||
isPlainObjectOrArray, | ||
asObjectIfArray, | ||
flattenObjectPaths, | ||
objectPaths, | ||
getValueAtPath, | ||
setValueAtPath, | ||
objectPathsFromWildcardPath, | ||
transformValueByPath, | ||
} from '@bscotch/utility'; | ||
asObjectIfArray(['hello']); // return {'0':'hello'} | ||
const testObject = { | ||
hello: 'world', | ||
nested: { | ||
layer: 1, | ||
array: [ | ||
4, | ||
6, | ||
7 | ||
] | ||
} | ||
} | ||
flattenObjectPaths(testObject); // returns: | ||
/** | ||
* { | ||
* 'hello':'world', | ||
* 'nested.layer': 1, | ||
* 'nested.array.0': 4, | ||
* 'nested.array.1': 6, | ||
* 'nested.array.2': 7, | ||
* } | ||
*/ | ||
objectPaths(testObject); // returns keys from flattenObjectPaths(testObject) | ||
getValueAtPath(testObject,'nested.array.2'); // returns 7 | ||
setValueAtPath(testObject,'new.0.field',10); // adds 'new' field to set to [{field:10}] | ||
objectPathsFromWildcardPath('nested.*',testObject); // returns: | ||
// ['nested.layer','nested.array'] | ||
objectPathsFromWildcardPath('nested.array.*',testObject); // returns: | ||
// ['nested.array.0','nested.array.1','nested.array.2] | ||
transformValueByPath(testObject,'nested.array.*',n=>++n); // Increments all array values by 1 | ||
``` | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
43407
32
510
193