@saulx/utils
Advanced tools
Comparing version 2.2.1 to 2.3.0
@@ -12,2 +12,4 @@ import deepCopy from './deepCopy'; | ||
export * from './deepMerge'; | ||
export { deepCopy, queued, obscurify, readStream, isObject, wait, deepEqual, toEnvVar, retry, randomString }; | ||
export { deepCopy, queued, obscurify, readStream, isObject, wait, deepEqual, toEnvVar, retry, randomString, }; | ||
export * from './walker'; | ||
export * from './getType'; |
@@ -38,2 +38,4 @@ "use strict"; | ||
__exportStar(require("./deepMerge"), exports); | ||
__exportStar(require("./walker"), exports); | ||
__exportStar(require("./getType"), exports); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@saulx/utils", | ||
"main": "./dist/index.js", | ||
"version": "2.2.1", | ||
"version": "2.3.0", | ||
"scripts": { | ||
@@ -49,6 +49,6 @@ "build": "tsc", | ||
"ava": "2.4.0", | ||
"eslint": "^6.5.1", | ||
"eslint": "^7.18.0", | ||
"husky": "^3.0.8", | ||
"lint-staged": "^9.4.2", | ||
"prettier": "^1.18.2", | ||
"prettier": "^2.2.1", | ||
"ts-node": "^8.5.4", | ||
@@ -55,0 +55,0 @@ "typescript": "^3.7.3" |
@@ -163,1 +163,56 @@ # utils | ||
``` | ||
## getType | ||
Returns a string with the operand/type of the javascrit primitive. Adds 'null' and 'array'. | ||
```javascript | ||
getType('') // -> "string" | ||
getType('this is a string') // -> "string" | ||
getType(123) // -> "number" | ||
getType(12.3) // -> "number" | ||
getType(-12.3) // -> "number" | ||
getType(-123) // -> "number" | ||
getType(BigInt('1')) // -> "bigint" | ||
getType(true) // -> "boolean" | ||
getType(false) // -> "boolean" | ||
getType(undefined) // -> "undefined" | ||
getType({}) // -> "object" | ||
getType({ a: 'wawa' }) // -> "object" | ||
getType(() => {}) // -> "function" | ||
getType([]) // -> "array" | ||
getType([1, 2, 3]) // -> "array" | ||
getType(null) // -> "null" | ||
``` | ||
## walker | ||
Generic structure walker. By default walks objects. | ||
```javascript | ||
const result = [] | ||
await walk(objectToWalk, async (item, info) => { | ||
result.push({ | ||
value: item, | ||
name: info.name, // property name | ||
path: info.path, // slash separated path in object | ||
type: info.type // operand type | ||
}) | ||
}) // returns void | ||
``` | ||
By configuring the options you can walk any kind of structure | ||
```javascript | ||
await walk( | ||
objectToWalk, // starting target | ||
itemFn, // function to run for each matched item | ||
options: { | ||
// check types for details | ||
listFn, // function to list each path. Should return a list of items. | ||
itemMatchFn, // function to choose which items to run itemFn on | ||
recureseFn, // function to choose wchich items to recurse on | ||
targetValidationFn, // function to validate starting path | ||
previousPath, // prefix to add to paths | ||
} | ||
}) | ||
``` |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
67814
69
959
218