@minsize/utils 0.0.1 → 0.0.2
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 +35 -47
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,56 +1,44 @@
|
|
|
1
|
-
##
|
|
2
|
-
[](https://www.npmjs.com/package/@minsize/utils)
|
|
3
3
|
|
|
4
4
|
```
|
|
5
|
-
npm i @minsize/
|
|
5
|
+
npm i @minsize/utils
|
|
6
6
|
|
|
7
|
-
yarn add @minsize/
|
|
7
|
+
yarn add @minsize/utils
|
|
8
8
|
```
|
|
9
9
|
|
|
10
|
-
###
|
|
10
|
+
### Functions
|
|
11
11
|
```js
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
12
|
+
import {
|
|
13
|
+
chunks,
|
|
14
|
+
clamp,
|
|
15
|
+
decWord,
|
|
16
|
+
alignTo,
|
|
17
|
+
toShort,
|
|
18
|
+
timeAgo,
|
|
19
|
+
formatNumber,
|
|
20
|
+
shuffle,
|
|
21
|
+
random,
|
|
22
|
+
isType,
|
|
23
|
+
omit,
|
|
24
|
+
pick,
|
|
25
|
+
sleep
|
|
26
|
+
} from '@minsize/utils'
|
|
30
27
|
```
|
|
31
28
|
|
|
29
|
+
| Function | Description |
|
|
30
|
+
| -------------- | -------------------------------------------------------------------------------------------------- |
|
|
31
|
+
| `chunks` | Splits an array into pieces of the given size. |
|
|
32
|
+
| `clamp` | Limits the number to the specified minimum and maximum value. |
|
|
33
|
+
| `decWord` | The function returns a string representing the correct ending of the word depending on the number. |
|
|
34
|
+
| `alignTo` | The function returns an aligned number. |
|
|
35
|
+
| `toShort` | The function returns a string representing the number in short form. |
|
|
36
|
+
| `timeAgo` | The function returns a string describing the time elapsed since timestamp. |
|
|
37
|
+
| `formatNumber` | Formats a number into a delimited string. |
|
|
38
|
+
| `shuffle` | Shuffles the elements of an array in random order. |
|
|
39
|
+
| `random` | Generates a random number within the specified range. |
|
|
40
|
+
| `isType` | Checks if the value is of the specified type. |
|
|
41
|
+
| `omit` | Returns a new object with no specified keys. |
|
|
42
|
+
| `pick` | Returns a new object with the selected keys. |
|
|
43
|
+
| `sleep` | Waits for the specified number of milliseconds. |
|
|
32
44
|
|
|
33
|
-
### Use with key
|
|
34
|
-
```js
|
|
35
|
-
import { Mutex } from '@minsize/mutex'
|
|
36
|
-
|
|
37
|
-
const mutex = Mutex({
|
|
38
|
-
globalLimit: 1 // Global limit on how many functions a mutex can process at once
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
const fn = async (userId) => {
|
|
42
|
-
const release = await mutex.wait({
|
|
43
|
-
key: userId, // Whom Mutex will be used
|
|
44
|
-
limit: 1 // Works the same as the global limit, but only for 1 key
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
try {
|
|
48
|
-
// ...
|
|
49
|
-
} finally {
|
|
50
|
-
release();
|
|
51
|
-
// or
|
|
52
|
-
mutex.release({ key: userId });
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
```
|