@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.
Files changed (2) hide show
  1. package/README.md +35 -47
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,56 +1,44 @@
1
- ## Mutex
2
- [![npm version](https://img.shields.io/npm/v/@minsize/mutex)](https://www.npmjs.com/package/@minsize/mutex)
1
+ ## Utils
2
+ [![npm version](https://img.shields.io/npm/v/@minsize/utils)](https://www.npmjs.com/package/@minsize/utils)
3
3
 
4
4
  ```
5
- npm i @minsize/mutex
5
+ npm i @minsize/utils
6
6
 
7
- yarn add @minsize/mutex
7
+ yarn add @minsize/utils
8
8
  ```
9
9
 
10
- ### Usage
10
+ ### Functions
11
11
  ```js
12
- import { Mutex } from '@minsize/mutex'
13
-
14
- const mutex = Mutex({
15
- globalLimit: 1 // Global limit on how many functions a mutex can process at once
16
- })
17
-
18
- const fn = async () => {
19
- const release = await mutex.wait();
20
-
21
- try {
22
- // ...
23
- } finally {
24
- release();
25
- // or
26
- mutex.release();
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
- ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minsize/utils",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Frequently used utilities",
5
5
  "license": "MIT",
6
6
  "types": "index.ts",