@superutils/core 1.1.6 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -7
- package/dist/index.d.ts +1177 -936
- package/dist/index.js +27 -22
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -77,14 +77,14 @@ import {
|
|
|
77
77
|
} from '@superutils/core'
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
-
<div id="
|
|
80
|
+
<div id="debounce"></div>
|
|
81
81
|
|
|
82
|
-
### `
|
|
82
|
+
### `debounce(fn, delay, options)`: debounce callbacks
|
|
83
83
|
|
|
84
84
|
```javascript
|
|
85
|
-
import {
|
|
85
|
+
import { debounce } from '@superutils/core'
|
|
86
86
|
|
|
87
|
-
const handleChange =
|
|
87
|
+
const handleChange = debounce(
|
|
88
88
|
event => console.log(event.target.value),
|
|
89
89
|
300, // debounce delay in milliseconds
|
|
90
90
|
{
|
|
@@ -196,6 +196,10 @@ const source = {
|
|
|
196
196
|
a: 1,
|
|
197
197
|
b: 2,
|
|
198
198
|
c: 3,
|
|
199
|
+
x: {
|
|
200
|
+
a: 1,
|
|
201
|
+
b: 2,
|
|
202
|
+
},
|
|
199
203
|
}
|
|
200
204
|
const dest = {
|
|
201
205
|
d: 4,
|
|
@@ -204,9 +208,11 @@ const dest = {
|
|
|
204
208
|
const copied = objCopy(
|
|
205
209
|
source,
|
|
206
210
|
dest,
|
|
207
|
-
['a'], // exclude source property
|
|
211
|
+
['a', 'x.b'], // exclude source property
|
|
208
212
|
'empty', // only override if dest doesn't have the property or value is "empty" (check `is.emtpy()`)
|
|
213
|
+
true, // recursively copies child objects. If false, child objects are copied by reference.
|
|
209
214
|
)
|
|
215
|
+
console.log({ copied })
|
|
210
216
|
// Result:
|
|
211
217
|
// {
|
|
212
218
|
// b: 2,
|
|
@@ -281,7 +287,7 @@ const data = new Map([
|
|
|
281
287
|
[4, { age: 28, name: 'Dave' }],
|
|
282
288
|
[5, { age: 22, name: 'Eve' }],
|
|
283
289
|
])
|
|
284
|
-
search(data, {
|
|
290
|
+
const result = search(data, {
|
|
285
291
|
asMap: false, // Result type: true => Map (default, keys preserved), false => Array
|
|
286
292
|
ignoreCase: false, // For text case-sensitivity
|
|
287
293
|
limit: 10, // Number of items returned. Default: no limit
|
|
@@ -300,6 +306,7 @@ search(data, {
|
|
|
300
306
|
return `${value}`
|
|
301
307
|
},
|
|
302
308
|
})
|
|
309
|
+
console.log({ result })
|
|
303
310
|
// Result:
|
|
304
311
|
// [
|
|
305
312
|
// { age: 30, name: 'Alice' },
|
|
@@ -379,7 +386,9 @@ setTimeout(() => searchDeferred({ target: { value: 'lic' } }), 510)
|
|
|
379
386
|
|
|
380
387
|
### `curry(fn, arity)`: Convert any function into a curried function
|
|
381
388
|
|
|
382
|
-
```
|
|
389
|
+
```javascript
|
|
390
|
+
import { curry } from '@superutils/core'
|
|
391
|
+
|
|
383
392
|
const func = (
|
|
384
393
|
first: string,
|
|
385
394
|
second: number,
|
|
@@ -399,4 +408,6 @@ const fnWith2 = fnWith1(2)
|
|
|
399
408
|
const fnWith3 = fnWith2(false)
|
|
400
409
|
// All args are now provided, the original function is called and result is returned.
|
|
401
410
|
const result = fnWith3('last')
|
|
411
|
+
console.log({ result })
|
|
412
|
+
// Result: 'first-2-false-last'
|
|
402
413
|
```
|