@entrolytics/utilities 2.2.0 → 2.3.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 +25 -21
- package/dist/index.cjs +360 -264
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +121 -112
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +121 -112
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +359 -263
- package/dist/index.js.map +1 -1
- package/package.json +30 -27
package/README.md
CHANGED
|
@@ -6,9 +6,13 @@ Common utilities and helper functions for Entrolytics projects.
|
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install @entrolytics/utilities
|
|
9
|
+
|
|
9
10
|
# or
|
|
11
|
+
|
|
10
12
|
pnpm add @entrolytics/utilities
|
|
13
|
+
|
|
11
14
|
# or
|
|
15
|
+
|
|
12
16
|
yarn add @entrolytics/utilities
|
|
13
17
|
```
|
|
14
18
|
|
|
@@ -29,17 +33,17 @@ yarn add @entrolytics/utilities
|
|
|
29
33
|
### String Utilities
|
|
30
34
|
|
|
31
35
|
```typescript
|
|
32
|
-
import { truncate, slugify, toKebabCase } from
|
|
36
|
+
import { truncate, slugify, toKebabCase } from "@entrolytics/utilities";
|
|
33
37
|
|
|
34
|
-
truncate(
|
|
35
|
-
slugify(
|
|
36
|
-
toKebabCase(
|
|
38
|
+
truncate("Long text here", 10); // 'Long te...'
|
|
39
|
+
slugify("Hello World!"); // 'hello-world'
|
|
40
|
+
toKebabCase("camelCaseString"); // 'camel-case-string'
|
|
37
41
|
```
|
|
38
42
|
|
|
39
43
|
### Date Utilities
|
|
40
44
|
|
|
41
45
|
```typescript
|
|
42
|
-
import { getLastNDays, toDateString, addDays } from
|
|
46
|
+
import { getLastNDays, toDateString, addDays } from "@entrolytics/utilities";
|
|
43
47
|
|
|
44
48
|
const { startDate, endDate } = getLastNDays(7);
|
|
45
49
|
toDateString(new Date()); // '2025-12-26'
|
|
@@ -49,21 +53,21 @@ addDays(new Date(), 5); // Date 5 days from now
|
|
|
49
53
|
### URL Utilities
|
|
50
54
|
|
|
51
55
|
```typescript
|
|
52
|
-
import { parseQueryParams, getDomain, combineUrl } from
|
|
56
|
+
import { parseQueryParams, getDomain, combineUrl } from "@entrolytics/utilities";
|
|
53
57
|
|
|
54
|
-
parseQueryParams(
|
|
55
|
-
getDomain(
|
|
56
|
-
combineUrl(
|
|
58
|
+
parseQueryParams("https://example.com?foo=bar"); // { foo: 'bar' }
|
|
59
|
+
getDomain("https://example.com/path"); // 'example.com'
|
|
60
|
+
combineUrl("https://api.com", "v1", "users"); // 'https://api.com/v1/users'
|
|
57
61
|
```
|
|
58
62
|
|
|
59
63
|
### Retry with Backoff
|
|
60
64
|
|
|
61
65
|
```typescript
|
|
62
|
-
import { retry } from
|
|
66
|
+
import { retry } from "@entrolytics/utilities";
|
|
63
67
|
|
|
64
68
|
await retry(
|
|
65
69
|
async () => {
|
|
66
|
-
const response = await fetch(
|
|
70
|
+
const response = await fetch("https://api.example.com/data");
|
|
67
71
|
return response.json();
|
|
68
72
|
},
|
|
69
73
|
{
|
|
@@ -73,37 +77,37 @@ await retry(
|
|
|
73
77
|
onRetry: (error, attempt) => {
|
|
74
78
|
console.log(`Retry attempt ${attempt}:`, error.message);
|
|
75
79
|
},
|
|
76
|
-
}
|
|
80
|
+
},
|
|
77
81
|
);
|
|
78
82
|
```
|
|
79
83
|
|
|
80
84
|
### Debounce & Throttle
|
|
81
85
|
|
|
82
86
|
```typescript
|
|
83
|
-
import { debounce, throttle } from
|
|
87
|
+
import { debounce, throttle } from "@entrolytics/utilities";
|
|
84
88
|
|
|
85
89
|
const debouncedSearch = debounce((query: string) => {
|
|
86
|
-
console.log(
|
|
90
|
+
console.log("Searching for:", query);
|
|
87
91
|
}, 300);
|
|
88
92
|
|
|
89
93
|
const throttledScroll = throttle(() => {
|
|
90
|
-
console.log(
|
|
94
|
+
console.log("Scrolling...");
|
|
91
95
|
}, 100);
|
|
92
96
|
```
|
|
93
97
|
|
|
94
98
|
### Storage Utilities
|
|
95
99
|
|
|
96
100
|
```typescript
|
|
97
|
-
import { storage, sessionStorage } from
|
|
101
|
+
import { storage, sessionStorage } from "@entrolytics/utilities";
|
|
98
102
|
|
|
99
103
|
// localStorage
|
|
100
|
-
storage.set(
|
|
101
|
-
const user = storage.get(
|
|
102
|
-
storage.remove(
|
|
104
|
+
storage.set("user", { name: "John", id: 123 });
|
|
105
|
+
const user = storage.get("user"); // { name: 'John', id: 123 }
|
|
106
|
+
storage.remove("user");
|
|
103
107
|
|
|
104
108
|
// sessionStorage
|
|
105
|
-
sessionStorage.set(
|
|
106
|
-
const data = sessionStorage.get(
|
|
109
|
+
sessionStorage.set("tempData", { value: 42 });
|
|
110
|
+
const data = sessionStorage.get("tempData");
|
|
107
111
|
```
|
|
108
112
|
|
|
109
113
|
## API Reference
|