@saulx/utils
Advanced tools
Comparing version 2.3.0 to 2.3.1
@@ -5,3 +5,3 @@ "use strict"; | ||
const _1 = require("./"); | ||
const defaultItemMatchFn = async (item) => _1.getType(item) !== 'object'; | ||
const defaultItemMatchFn = async (item) => _1.getType(item.ref) !== 'object'; | ||
const defaultListFn = async (target, previousPath) => { | ||
@@ -29,3 +29,3 @@ return Object.keys(target).map((key) => ({ | ||
const { name, path, type } = item; | ||
if (await options.itemMatchFn(item.ref)) { | ||
if (await options.itemMatchFn(item)) { | ||
itemFn(item.ref, { name, path, type }); | ||
@@ -32,0 +32,0 @@ } |
{ | ||
"name": "@saulx/utils", | ||
"main": "./dist/index.js", | ||
"version": "2.3.0", | ||
"version": "2.3.1", | ||
"scripts": { | ||
@@ -6,0 +6,0 @@ "build": "tsc", |
@@ -41,4 +41,4 @@ # utils | ||
{ | ||
x: { a: { b: true, c: true, x: ['bla']}}, | ||
y: true | ||
x: { a: { b: true, c: true, x: ['bla']}}, | ||
y: true | ||
} | ||
@@ -65,4 +65,4 @@ */ | ||
{ | ||
x: { a: { b: true, c: true, x: ['bla', 2, 3]}}, | ||
y: true | ||
x: { a: { b: true, c: true, x: ['bla', 2, 3]}}, | ||
y: true | ||
} | ||
@@ -90,6 +90,6 @@ */ | ||
const somethingAsync = async () => { | ||
await wait() // 100ms | ||
console.log('after 100ms') | ||
await wait(1000) | ||
console.log('after 1100ms') | ||
await wait() // 100ms | ||
console.log('after 100ms') | ||
await wait(1000) | ||
console.log('after 1100ms') | ||
} | ||
@@ -132,4 +132,4 @@ | ||
const myFn = queued(async (a: string) => { | ||
await wait(1000) | ||
return a + '!' | ||
await wait(1000) | ||
return a + '!' | ||
}) | ||
@@ -139,5 +139,5 @@ | ||
await Promise.all([ | ||
myFn('bla'), | ||
myFn('x') | ||
myFn('bla') // bla will be shared | ||
myFn('bla'), | ||
myFn('x') | ||
myFn('bla') // bla will be shared | ||
]) | ||
@@ -150,10 +150,10 @@ ``` | ||
const myFn = queued(async (a: string) => { | ||
await wait(1000) | ||
return a + '!' | ||
await wait(1000) | ||
return a + '!' | ||
}, { | ||
dedup: (a) => { | ||
// choose the value to use for dedup (to share results) | ||
return a | ||
}, | ||
concurrency: 10 // max concurrency of 10 | ||
dedup: (a) => { | ||
// choose the value to use for dedup (to share results) | ||
return a | ||
}, | ||
concurrency: 10 // max concurrency of 10 | ||
}) | ||
@@ -164,5 +164,5 @@ | ||
await Promise.all([ | ||
myFn('bla'), | ||
myFn('x') | ||
myFn('bla') // bla will be shared | ||
myFn('bla'), | ||
myFn('x') | ||
myFn('bla') // bla will be shared | ||
]) | ||
@@ -175,18 +175,18 @@ ``` | ||
```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" | ||
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" | ||
``` | ||
@@ -199,5 +199,5 @@ | ||
```javascript | ||
const result = [] | ||
await walk(objectToWalk, async (item, info) => { | ||
result.push({ | ||
const result = [] | ||
await walk(objectToWalk, async (item, info) => { | ||
result.push({ | ||
value: item, | ||
@@ -208,3 +208,3 @@ name: info.name, // property name | ||
}) | ||
}) // returns void | ||
}) // returns void | ||
``` | ||
@@ -215,5 +215,5 @@ | ||
```javascript | ||
await walk( | ||
await walk( | ||
objectToWalk, // starting target | ||
itemFn, // function to run for each matched item | ||
itemFn, // function to run for each matched item | ||
options: { | ||
@@ -227,3 +227,3 @@ // check types for details | ||
} | ||
}) | ||
}) | ||
``` |
Sorry, the diff of this file is not supported yet
67700