typetify 2.1.0 → 2.4.0
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/CHANGELOG.md +131 -0
- package/README.md +108 -0
- package/dist/async/index.js +1 -49
- package/dist/async/index.mjs +1 -4
- package/dist/chunk-272Z3AXV.js +1 -0
- package/dist/chunk-2YRFWQ6M.mjs +1 -0
- package/dist/chunk-35CB7HNN.js +1 -0
- package/dist/chunk-4JG7CFRK.js +1 -0
- package/dist/chunk-5FBZYPQM.mjs +1 -0
- package/dist/chunk-5XQRYI2Q.mjs +1 -0
- package/dist/chunk-6HA2SN23.js +1 -0
- package/dist/chunk-6NWIIOHH.js +1 -0
- package/dist/chunk-6WGRWYAD.js +1 -0
- package/dist/chunk-7LBL6CYT.js +1 -0
- package/dist/chunk-7UMXGQE4.mjs +1 -0
- package/dist/chunk-7XHBEA63.js +1 -0
- package/dist/chunk-B3R73UK5.mjs +1 -0
- package/dist/chunk-BLUG7TSP.js +1 -0
- package/dist/chunk-EAHFED6V.mjs +1 -0
- package/dist/chunk-EKSHS4DL.mjs +1 -0
- package/dist/chunk-F76ECQKE.js +1 -0
- package/dist/chunk-FHCBXSNA.js +1 -0
- package/dist/chunk-GKOA3XGQ.js +1 -0
- package/dist/chunk-GQIJLGEZ.mjs +1 -0
- package/dist/chunk-I4YSQ4HB.js +1 -0
- package/dist/chunk-JZXLCA2E.mjs +1 -0
- package/dist/chunk-M5OMYDI7.mjs +1 -0
- package/dist/chunk-MB77QAOC.mjs +1 -0
- package/dist/chunk-MPY3WRLG.mjs +1 -0
- package/dist/chunk-NENRAPOL.mjs +1 -0
- package/dist/chunk-NOW4Q26G.mjs +1 -0
- package/dist/chunk-P4UNM7SF.js +1 -0
- package/dist/chunk-P5E2JDCX.mjs +1 -0
- package/dist/chunk-Q7SUL7MD.js +1 -0
- package/dist/chunk-QKNZICUO.mjs +1 -0
- package/dist/chunk-RHMANSTA.mjs +1 -0
- package/dist/chunk-SF64HETW.js +1 -0
- package/dist/chunk-T66YO63J.js +1 -0
- package/dist/chunk-TNK6EVQK.mjs +1 -0
- package/dist/chunk-TSJFKV3R.js +1 -0
- package/dist/chunk-TVCWWECJ.mjs +1 -0
- package/dist/chunk-U7MK5AR5.mjs +1 -0
- package/dist/chunk-W5I352FJ.js +1 -0
- package/dist/chunk-WAT4QJB2.js +1 -0
- package/dist/chunk-WCG5ODRX.mjs +1 -0
- package/dist/chunk-WDFIRO2J.js +1 -0
- package/dist/chunk-WOT6VMZA.js +1 -0
- package/dist/chunk-WS743BFA.js +1 -0
- package/dist/chunk-WWU7P2L2.mjs +1 -0
- package/dist/chunk-XPY5CWKZ.mjs +1 -0
- package/dist/collection/index.d.mts +125 -1
- package/dist/collection/index.d.ts +125 -1
- package/dist/collection/index.js +1 -125
- package/dist/collection/index.mjs +1 -4
- package/dist/color/index.d.mts +274 -0
- package/dist/color/index.d.ts +274 -0
- package/dist/color/index.js +1 -0
- package/dist/color/index.mjs +1 -0
- package/dist/core/index.js +1 -41
- package/dist/core/index.mjs +1 -4
- package/dist/decorator/index.js +1 -57
- package/dist/decorator/index.mjs +1 -4
- package/dist/dom/index.d.mts +353 -0
- package/dist/dom/index.d.ts +353 -0
- package/dist/dom/index.js +1 -0
- package/dist/dom/index.mjs +1 -0
- package/dist/dx/index.js +1 -53
- package/dist/dx/index.mjs +1 -4
- package/dist/flow/index.js +1 -50
- package/dist/flow/index.mjs +1 -5
- package/dist/fn/index.js +1 -37
- package/dist/fn/index.mjs +1 -4
- package/dist/guards/index.js +1 -233
- package/dist/guards/index.mjs +1 -4
- package/dist/index.d.mts +482 -410
- package/dist/index.d.ts +482 -410
- package/dist/index.js +3 -2507
- package/dist/index.mjs +3 -1546
- package/dist/input/index.js +1 -74
- package/dist/input/index.mjs +1 -5
- package/dist/iterator/index.js +1 -85
- package/dist/iterator/index.mjs +1 -4
- package/dist/logic/index.js +1 -201
- package/dist/logic/index.mjs +1 -4
- package/dist/math/index.js +1 -45
- package/dist/math/index.mjs +1 -4
- package/dist/narrowing/index.js +1 -141
- package/dist/narrowing/index.mjs +1 -4
- package/dist/object/index.d.mts +137 -1
- package/dist/object/index.d.ts +137 -1
- package/dist/object/index.js +1 -113
- package/dist/object/index.mjs +1 -4
- package/dist/result/index.js +1 -86
- package/dist/result/index.mjs +1 -5
- package/dist/schema/index.js +1 -110
- package/dist/schema/index.mjs +1 -5
- package/dist/storage/index.d.mts +197 -0
- package/dist/storage/index.d.ts +197 -0
- package/dist/storage/index.js +1 -0
- package/dist/storage/index.mjs +1 -0
- package/dist/string/index.d.mts +201 -1
- package/dist/string/index.d.ts +201 -1
- package/dist/string/index.js +1 -49
- package/dist/string/index.mjs +1 -4
- package/dist/typed/index.js +1 -193
- package/dist/typed/index.mjs +1 -4
- package/package.json +23 -3
- package/dist/async/index.js.map +0 -1
- package/dist/async/index.mjs.map +0 -1
- package/dist/chunk-2LJ6NZ6K.js +0 -108
- package/dist/chunk-2LJ6NZ6K.js.map +0 -1
- package/dist/chunk-4NXETABV.mjs +0 -116
- package/dist/chunk-4NXETABV.mjs.map +0 -1
- package/dist/chunk-6ZBTL74K.js +0 -129
- package/dist/chunk-6ZBTL74K.js.map +0 -1
- package/dist/chunk-7G4ZSMQX.js +0 -470
- package/dist/chunk-7G4ZSMQX.js.map +0 -1
- package/dist/chunk-CN3GYRJN.mjs +0 -137
- package/dist/chunk-CN3GYRJN.mjs.map +0 -1
- package/dist/chunk-CNTE6ZVH.js +0 -359
- package/dist/chunk-CNTE6ZVH.js.map +0 -1
- package/dist/chunk-CWHYQWNU.mjs +0 -224
- package/dist/chunk-CWHYQWNU.mjs.map +0 -1
- package/dist/chunk-DBENOSTA.js +0 -156
- package/dist/chunk-DBENOSTA.js.map +0 -1
- package/dist/chunk-DWIG5GF2.js +0 -135
- package/dist/chunk-DWIG5GF2.js.map +0 -1
- package/dist/chunk-EAUTTWTQ.mjs +0 -231
- package/dist/chunk-EAUTTWTQ.mjs.map +0 -1
- package/dist/chunk-FEX5C4OH.mjs +0 -1007
- package/dist/chunk-FEX5C4OH.mjs.map +0 -1
- package/dist/chunk-FN553YPU.js +0 -441
- package/dist/chunk-FN553YPU.js.map +0 -1
- package/dist/chunk-FT2EK4AM.mjs +0 -420
- package/dist/chunk-FT2EK4AM.mjs.map +0 -1
- package/dist/chunk-FXWYPHA3.mjs +0 -13
- package/dist/chunk-FXWYPHA3.mjs.map +0 -1
- package/dist/chunk-GS3PP67B.js +0 -200
- package/dist/chunk-GS3PP67B.js.map +0 -1
- package/dist/chunk-IGA3VEZM.mjs +0 -503
- package/dist/chunk-IGA3VEZM.mjs.map +0 -1
- package/dist/chunk-J5LGTIGS.mjs +0 -9
- package/dist/chunk-J5LGTIGS.mjs.map +0 -1
- package/dist/chunk-JB6UXRKD.mjs +0 -97
- package/dist/chunk-JB6UXRKD.mjs.map +0 -1
- package/dist/chunk-JQAQV75V.js +0 -561
- package/dist/chunk-JQAQV75V.js.map +0 -1
- package/dist/chunk-JQHUBZ4M.js +0 -88
- package/dist/chunk-JQHUBZ4M.js.map +0 -1
- package/dist/chunk-LT7JK7RJ.js +0 -87
- package/dist/chunk-LT7JK7RJ.js.map +0 -1
- package/dist/chunk-N6IUADIP.mjs +0 -414
- package/dist/chunk-N6IUADIP.mjs.map +0 -1
- package/dist/chunk-OEJK37LO.mjs +0 -328
- package/dist/chunk-OEJK37LO.mjs.map +0 -1
- package/dist/chunk-OKB3MS5F.js +0 -547
- package/dist/chunk-OKB3MS5F.js.map +0 -1
- package/dist/chunk-OPVES6W2.js +0 -16
- package/dist/chunk-OPVES6W2.js.map +0 -1
- package/dist/chunk-OWNUKWXV.js +0 -291
- package/dist/chunk-OWNUKWXV.js.map +0 -1
- package/dist/chunk-POD52NJ3.mjs +0 -526
- package/dist/chunk-POD52NJ3.mjs.map +0 -1
- package/dist/chunk-PQTXSQ4P.js +0 -369
- package/dist/chunk-PQTXSQ4P.js.map +0 -1
- package/dist/chunk-PZ5AY32C.js +0 -11
- package/dist/chunk-PZ5AY32C.js.map +0 -1
- package/dist/chunk-QFR7DVAJ.mjs +0 -63
- package/dist/chunk-QFR7DVAJ.mjs.map +0 -1
- package/dist/chunk-S535LAXW.js +0 -1054
- package/dist/chunk-S535LAXW.js.map +0 -1
- package/dist/chunk-SGQNLTRK.js +0 -73
- package/dist/chunk-SGQNLTRK.js.map +0 -1
- package/dist/chunk-SRDWUHDY.mjs +0 -188
- package/dist/chunk-SRDWUHDY.mjs.map +0 -1
- package/dist/chunk-TXU7NTT4.js +0 -249
- package/dist/chunk-TXU7NTT4.js.map +0 -1
- package/dist/chunk-TZEWREAC.mjs +0 -277
- package/dist/chunk-TZEWREAC.mjs.map +0 -1
- package/dist/chunk-V6CWFDIJ.mjs +0 -123
- package/dist/chunk-V6CWFDIJ.mjs.map +0 -1
- package/dist/chunk-X55EORNF.js +0 -259
- package/dist/chunk-X55EORNF.js.map +0 -1
- package/dist/chunk-YBJC5WMX.mjs +0 -341
- package/dist/chunk-YBJC5WMX.mjs.map +0 -1
- package/dist/chunk-YOPAXITF.mjs +0 -75
- package/dist/chunk-YOPAXITF.mjs.map +0 -1
- package/dist/chunk-ZE4FDBRI.mjs +0 -79
- package/dist/chunk-ZE4FDBRI.mjs.map +0 -1
- package/dist/collection/index.js.map +0 -1
- package/dist/collection/index.mjs.map +0 -1
- package/dist/core/index.js.map +0 -1
- package/dist/core/index.mjs.map +0 -1
- package/dist/decorator/index.js.map +0 -1
- package/dist/decorator/index.mjs.map +0 -1
- package/dist/dx/index.js.map +0 -1
- package/dist/dx/index.mjs.map +0 -1
- package/dist/flow/index.js.map +0 -1
- package/dist/flow/index.mjs.map +0 -1
- package/dist/fn/index.js.map +0 -1
- package/dist/fn/index.mjs.map +0 -1
- package/dist/guards/index.js.map +0 -1
- package/dist/guards/index.mjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/input/index.js.map +0 -1
- package/dist/input/index.mjs.map +0 -1
- package/dist/iterator/index.js.map +0 -1
- package/dist/iterator/index.mjs.map +0 -1
- package/dist/logic/index.js.map +0 -1
- package/dist/logic/index.mjs.map +0 -1
- package/dist/math/index.js.map +0 -1
- package/dist/math/index.mjs.map +0 -1
- package/dist/narrowing/index.js.map +0 -1
- package/dist/narrowing/index.mjs.map +0 -1
- package/dist/object/index.js.map +0 -1
- package/dist/object/index.mjs.map +0 -1
- package/dist/result/index.js.map +0 -1
- package/dist/result/index.mjs.map +0 -1
- package/dist/schema/index.js.map +0 -1
- package/dist/schema/index.mjs.map +0 -1
- package/dist/string/index.js.map +0 -1
- package/dist/string/index.mjs.map +0 -1
- package/dist/typed/index.js.map +0 -1
- package/dist/typed/index.mjs.map +0 -1
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-safe storage wrapper with serialization.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* // Create typed storage
|
|
6
|
+
* interface UserPrefs {
|
|
7
|
+
* theme: 'light' | 'dark';
|
|
8
|
+
* language: string;
|
|
9
|
+
* notifications: boolean;
|
|
10
|
+
* }
|
|
11
|
+
*
|
|
12
|
+
* const prefs = createStorage<UserPrefs>('user-prefs', {
|
|
13
|
+
* storage: localStorage
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* prefs.set({ theme: 'dark', language: 'en', notifications: true });
|
|
17
|
+
* const theme = prefs.get()?.theme; // 'dark' | undefined
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* // With default value
|
|
21
|
+
* const settings = createStorage('settings', {
|
|
22
|
+
* storage: localStorage,
|
|
23
|
+
* defaultValue: { volume: 50 }
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* // Session storage
|
|
28
|
+
* const tempData = createStorage('temp', {
|
|
29
|
+
* storage: sessionStorage
|
|
30
|
+
* });
|
|
31
|
+
*/
|
|
32
|
+
interface StorageOptions<T> {
|
|
33
|
+
storage: Storage;
|
|
34
|
+
defaultValue?: T;
|
|
35
|
+
serializer?: {
|
|
36
|
+
stringify: (value: T) => string;
|
|
37
|
+
parse: (value: string) => T;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
interface TypedStorage<T> {
|
|
41
|
+
get(): T | null;
|
|
42
|
+
set(value: T): void;
|
|
43
|
+
remove(): void;
|
|
44
|
+
clear(): void;
|
|
45
|
+
has(): boolean;
|
|
46
|
+
}
|
|
47
|
+
declare function createStorage<T>(key: string, options: StorageOptions<T>): TypedStorage<T>;
|
|
48
|
+
/**
|
|
49
|
+
* Creates a storage instance with localStorage.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* const userPrefs = localStorageTyped<UserPrefs>('prefs');
|
|
53
|
+
* userPrefs.set({ theme: 'dark' });
|
|
54
|
+
*/
|
|
55
|
+
declare function localStorageTyped<T>(key: string, defaultValue?: T): TypedStorage<T>;
|
|
56
|
+
/**
|
|
57
|
+
* Creates a storage instance with sessionStorage.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* const tempData = sessionStorageTyped<TempData>('temp');
|
|
61
|
+
* tempData.set({ token: 'abc123' });
|
|
62
|
+
*/
|
|
63
|
+
declare function sessionStorageTyped<T>(key: string, defaultValue?: T): TypedStorage<T>;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Storage wrapper that adds expiration to stored values.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* // Store with 1 hour expiry
|
|
70
|
+
* const cache = withExpiry<User>('user-cache', {
|
|
71
|
+
* storage: localStorage,
|
|
72
|
+
* ttl: 60 * 60 * 1000 // 1 hour in ms
|
|
73
|
+
* });
|
|
74
|
+
*
|
|
75
|
+
* cache.set(user);
|
|
76
|
+
* const cached = cache.get(); // null after 1 hour
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* // Check if expired
|
|
80
|
+
* if (cache.isExpired()) {
|
|
81
|
+
* cache.remove();
|
|
82
|
+
* fetchFreshData();
|
|
83
|
+
* }
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* // API response caching
|
|
87
|
+
* const apiCache = withExpiry<ApiResponse>('api-cache', {
|
|
88
|
+
* storage: sessionStorage,
|
|
89
|
+
* ttl: 5 * 60 * 1000 // 5 minutes
|
|
90
|
+
* });
|
|
91
|
+
*/
|
|
92
|
+
interface ExpiryStorageOptions {
|
|
93
|
+
storage: Storage;
|
|
94
|
+
ttl: number;
|
|
95
|
+
}
|
|
96
|
+
interface ExpiryStorage<T> {
|
|
97
|
+
get(): T | null;
|
|
98
|
+
set(value: T): void;
|
|
99
|
+
remove(): void;
|
|
100
|
+
isExpired(): boolean;
|
|
101
|
+
getExpiry(): number | null;
|
|
102
|
+
}
|
|
103
|
+
declare function withExpiry<T>(key: string, options: ExpiryStorageOptions): ExpiryStorage<T>;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* In-memory storage implementation (useful for SSR/testing).
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* // Use in Node.js or SSR
|
|
110
|
+
* const storage = createMemoryStorage();
|
|
111
|
+
* storage.setItem('key', 'value');
|
|
112
|
+
* storage.getItem('key'); // => 'value'
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* // Fallback when localStorage is not available
|
|
116
|
+
* const storage = typeof window !== 'undefined'
|
|
117
|
+
* ? localStorage
|
|
118
|
+
* : createMemoryStorage();
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* // Testing
|
|
122
|
+
* const mockStorage = createMemoryStorage();
|
|
123
|
+
* const store = createStorage('test', { storage: mockStorage });
|
|
124
|
+
*/
|
|
125
|
+
declare function createMemoryStorage(): Storage;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Cookie options for setting cookies.
|
|
129
|
+
*/
|
|
130
|
+
interface CookieOptions {
|
|
131
|
+
expires?: Date | number;
|
|
132
|
+
path?: string;
|
|
133
|
+
domain?: string;
|
|
134
|
+
secure?: boolean;
|
|
135
|
+
sameSite?: 'Strict' | 'Lax' | 'None';
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Gets a cookie value by name.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* const token = getCookie('auth_token');
|
|
142
|
+
* if (token) {
|
|
143
|
+
* authenticate(token);
|
|
144
|
+
* }
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* // Returns null if not found
|
|
148
|
+
* const missing = getCookie('nonexistent'); // => null
|
|
149
|
+
*/
|
|
150
|
+
declare function getCookie(name: string): string | null;
|
|
151
|
+
/**
|
|
152
|
+
* Sets a cookie with options.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* // Simple cookie
|
|
156
|
+
* setCookie('user_id', '123');
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* // With expiration (7 days)
|
|
160
|
+
* setCookie('session', 'abc', { expires: 7 });
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* // Secure cookie
|
|
164
|
+
* setCookie('auth_token', token, {
|
|
165
|
+
* expires: 30,
|
|
166
|
+
* secure: true,
|
|
167
|
+
* sameSite: 'Strict',
|
|
168
|
+
* path: '/'
|
|
169
|
+
* });
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* // Session cookie (expires when browser closes)
|
|
173
|
+
* setCookie('temp', 'value');
|
|
174
|
+
*/
|
|
175
|
+
declare function setCookie(name: string, value: string, options?: CookieOptions): void;
|
|
176
|
+
/**
|
|
177
|
+
* Removes a cookie by name.
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* removeCookie('session');
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* // Remove with specific path
|
|
184
|
+
* removeCookie('token', { path: '/admin' });
|
|
185
|
+
*/
|
|
186
|
+
declare function removeCookie(name: string, options?: Pick<CookieOptions, 'path' | 'domain'>): void;
|
|
187
|
+
/**
|
|
188
|
+
* Checks if a cookie exists.
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* if (hasCookie('auth_token')) {
|
|
192
|
+
* console.log('User is authenticated');
|
|
193
|
+
* }
|
|
194
|
+
*/
|
|
195
|
+
declare function hasCookie(name: string): boolean;
|
|
196
|
+
|
|
197
|
+
export { type CookieOptions, type ExpiryStorage, type ExpiryStorageOptions, type StorageOptions, type TypedStorage, createMemoryStorage, createStorage, getCookie, hasCookie, localStorageTyped, removeCookie, sessionStorageTyped, setCookie, withExpiry };
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-safe storage wrapper with serialization.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* // Create typed storage
|
|
6
|
+
* interface UserPrefs {
|
|
7
|
+
* theme: 'light' | 'dark';
|
|
8
|
+
* language: string;
|
|
9
|
+
* notifications: boolean;
|
|
10
|
+
* }
|
|
11
|
+
*
|
|
12
|
+
* const prefs = createStorage<UserPrefs>('user-prefs', {
|
|
13
|
+
* storage: localStorage
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* prefs.set({ theme: 'dark', language: 'en', notifications: true });
|
|
17
|
+
* const theme = prefs.get()?.theme; // 'dark' | undefined
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* // With default value
|
|
21
|
+
* const settings = createStorage('settings', {
|
|
22
|
+
* storage: localStorage,
|
|
23
|
+
* defaultValue: { volume: 50 }
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* // Session storage
|
|
28
|
+
* const tempData = createStorage('temp', {
|
|
29
|
+
* storage: sessionStorage
|
|
30
|
+
* });
|
|
31
|
+
*/
|
|
32
|
+
interface StorageOptions<T> {
|
|
33
|
+
storage: Storage;
|
|
34
|
+
defaultValue?: T;
|
|
35
|
+
serializer?: {
|
|
36
|
+
stringify: (value: T) => string;
|
|
37
|
+
parse: (value: string) => T;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
interface TypedStorage<T> {
|
|
41
|
+
get(): T | null;
|
|
42
|
+
set(value: T): void;
|
|
43
|
+
remove(): void;
|
|
44
|
+
clear(): void;
|
|
45
|
+
has(): boolean;
|
|
46
|
+
}
|
|
47
|
+
declare function createStorage<T>(key: string, options: StorageOptions<T>): TypedStorage<T>;
|
|
48
|
+
/**
|
|
49
|
+
* Creates a storage instance with localStorage.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* const userPrefs = localStorageTyped<UserPrefs>('prefs');
|
|
53
|
+
* userPrefs.set({ theme: 'dark' });
|
|
54
|
+
*/
|
|
55
|
+
declare function localStorageTyped<T>(key: string, defaultValue?: T): TypedStorage<T>;
|
|
56
|
+
/**
|
|
57
|
+
* Creates a storage instance with sessionStorage.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* const tempData = sessionStorageTyped<TempData>('temp');
|
|
61
|
+
* tempData.set({ token: 'abc123' });
|
|
62
|
+
*/
|
|
63
|
+
declare function sessionStorageTyped<T>(key: string, defaultValue?: T): TypedStorage<T>;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Storage wrapper that adds expiration to stored values.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* // Store with 1 hour expiry
|
|
70
|
+
* const cache = withExpiry<User>('user-cache', {
|
|
71
|
+
* storage: localStorage,
|
|
72
|
+
* ttl: 60 * 60 * 1000 // 1 hour in ms
|
|
73
|
+
* });
|
|
74
|
+
*
|
|
75
|
+
* cache.set(user);
|
|
76
|
+
* const cached = cache.get(); // null after 1 hour
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* // Check if expired
|
|
80
|
+
* if (cache.isExpired()) {
|
|
81
|
+
* cache.remove();
|
|
82
|
+
* fetchFreshData();
|
|
83
|
+
* }
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* // API response caching
|
|
87
|
+
* const apiCache = withExpiry<ApiResponse>('api-cache', {
|
|
88
|
+
* storage: sessionStorage,
|
|
89
|
+
* ttl: 5 * 60 * 1000 // 5 minutes
|
|
90
|
+
* });
|
|
91
|
+
*/
|
|
92
|
+
interface ExpiryStorageOptions {
|
|
93
|
+
storage: Storage;
|
|
94
|
+
ttl: number;
|
|
95
|
+
}
|
|
96
|
+
interface ExpiryStorage<T> {
|
|
97
|
+
get(): T | null;
|
|
98
|
+
set(value: T): void;
|
|
99
|
+
remove(): void;
|
|
100
|
+
isExpired(): boolean;
|
|
101
|
+
getExpiry(): number | null;
|
|
102
|
+
}
|
|
103
|
+
declare function withExpiry<T>(key: string, options: ExpiryStorageOptions): ExpiryStorage<T>;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* In-memory storage implementation (useful for SSR/testing).
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* // Use in Node.js or SSR
|
|
110
|
+
* const storage = createMemoryStorage();
|
|
111
|
+
* storage.setItem('key', 'value');
|
|
112
|
+
* storage.getItem('key'); // => 'value'
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* // Fallback when localStorage is not available
|
|
116
|
+
* const storage = typeof window !== 'undefined'
|
|
117
|
+
* ? localStorage
|
|
118
|
+
* : createMemoryStorage();
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* // Testing
|
|
122
|
+
* const mockStorage = createMemoryStorage();
|
|
123
|
+
* const store = createStorage('test', { storage: mockStorage });
|
|
124
|
+
*/
|
|
125
|
+
declare function createMemoryStorage(): Storage;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Cookie options for setting cookies.
|
|
129
|
+
*/
|
|
130
|
+
interface CookieOptions {
|
|
131
|
+
expires?: Date | number;
|
|
132
|
+
path?: string;
|
|
133
|
+
domain?: string;
|
|
134
|
+
secure?: boolean;
|
|
135
|
+
sameSite?: 'Strict' | 'Lax' | 'None';
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Gets a cookie value by name.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* const token = getCookie('auth_token');
|
|
142
|
+
* if (token) {
|
|
143
|
+
* authenticate(token);
|
|
144
|
+
* }
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* // Returns null if not found
|
|
148
|
+
* const missing = getCookie('nonexistent'); // => null
|
|
149
|
+
*/
|
|
150
|
+
declare function getCookie(name: string): string | null;
|
|
151
|
+
/**
|
|
152
|
+
* Sets a cookie with options.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* // Simple cookie
|
|
156
|
+
* setCookie('user_id', '123');
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* // With expiration (7 days)
|
|
160
|
+
* setCookie('session', 'abc', { expires: 7 });
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* // Secure cookie
|
|
164
|
+
* setCookie('auth_token', token, {
|
|
165
|
+
* expires: 30,
|
|
166
|
+
* secure: true,
|
|
167
|
+
* sameSite: 'Strict',
|
|
168
|
+
* path: '/'
|
|
169
|
+
* });
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* // Session cookie (expires when browser closes)
|
|
173
|
+
* setCookie('temp', 'value');
|
|
174
|
+
*/
|
|
175
|
+
declare function setCookie(name: string, value: string, options?: CookieOptions): void;
|
|
176
|
+
/**
|
|
177
|
+
* Removes a cookie by name.
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* removeCookie('session');
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* // Remove with specific path
|
|
184
|
+
* removeCookie('token', { path: '/admin' });
|
|
185
|
+
*/
|
|
186
|
+
declare function removeCookie(name: string, options?: Pick<CookieOptions, 'path' | 'domain'>): void;
|
|
187
|
+
/**
|
|
188
|
+
* Checks if a cookie exists.
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* if (hasCookie('auth_token')) {
|
|
192
|
+
* console.log('User is authenticated');
|
|
193
|
+
* }
|
|
194
|
+
*/
|
|
195
|
+
declare function hasCookie(name: string): boolean;
|
|
196
|
+
|
|
197
|
+
export { type CookieOptions, type ExpiryStorage, type ExpiryStorageOptions, type StorageOptions, type TypedStorage, createMemoryStorage, createStorage, getCookie, hasCookie, localStorageTyped, removeCookie, sessionStorageTyped, setCookie, withExpiry };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var chunkF76ECQKE_js=require('../chunk-F76ECQKE.js');require('../chunk-WOT6VMZA.js');Object.defineProperty(exports,"createMemoryStorage",{enumerable:true,get:function(){return chunkF76ECQKE_js.e}});Object.defineProperty(exports,"createStorage",{enumerable:true,get:function(){return chunkF76ECQKE_js.a}});Object.defineProperty(exports,"getCookie",{enumerable:true,get:function(){return chunkF76ECQKE_js.f}});Object.defineProperty(exports,"hasCookie",{enumerable:true,get:function(){return chunkF76ECQKE_js.i}});Object.defineProperty(exports,"localStorageTyped",{enumerable:true,get:function(){return chunkF76ECQKE_js.b}});Object.defineProperty(exports,"removeCookie",{enumerable:true,get:function(){return chunkF76ECQKE_js.h}});Object.defineProperty(exports,"sessionStorageTyped",{enumerable:true,get:function(){return chunkF76ECQKE_js.c}});Object.defineProperty(exports,"setCookie",{enumerable:true,get:function(){return chunkF76ECQKE_js.g}});Object.defineProperty(exports,"withExpiry",{enumerable:true,get:function(){return chunkF76ECQKE_js.d}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{e as createMemoryStorage,a as createStorage,f as getCookie,i as hasCookie,b as localStorageTyped,h as removeCookie,c as sessionStorageTyped,g as setCookie,d as withExpiry}from'../chunk-MB77QAOC.mjs';import'../chunk-JZXLCA2E.mjs';
|
package/dist/string/index.d.mts
CHANGED
|
@@ -99,4 +99,204 @@ declare function template(str: string, vars: Record<string, unknown>): string;
|
|
|
99
99
|
*/
|
|
100
100
|
declare function words(str: string): string[];
|
|
101
101
|
|
|
102
|
-
|
|
102
|
+
/**
|
|
103
|
+
* Removes diacritical marks (accents) from a string.
|
|
104
|
+
* Converts Latin-1 Supplement and Latin Extended-A letters to basic Latin letters.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* // Remove French accents
|
|
108
|
+
* deburr('déjà vu')
|
|
109
|
+
* // => 'deja vu'
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* // Remove German umlauts
|
|
113
|
+
* deburr('Müller')
|
|
114
|
+
* // => 'Muller'
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* // Remove Spanish accents
|
|
118
|
+
* deburr('señor')
|
|
119
|
+
* // => 'senor'
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* // Useful for search/filtering
|
|
123
|
+
* const users = ['José', 'François', 'Müller']
|
|
124
|
+
* const search = 'jose'
|
|
125
|
+
* users.filter(name => deburr(name).toLowerCase().includes(search))
|
|
126
|
+
* // => ['José']
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* // Create URL-safe slugs
|
|
130
|
+
* deburr('Crème brûlée').toLowerCase().replace(/\s+/g, '-')
|
|
131
|
+
* // => 'creme-brulee'
|
|
132
|
+
*/
|
|
133
|
+
declare function deburr(str: string): string;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Escapes HTML special characters to prevent XSS attacks.
|
|
137
|
+
* Converts &, <, >, ", and ' to their HTML entity equivalents.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* // Escape user input before rendering
|
|
141
|
+
* escape('<script>alert("xss")</script>')
|
|
142
|
+
* // => '<script>alert("xss")</script>'
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* // Escape ampersands
|
|
146
|
+
* escape('Tom & Jerry')
|
|
147
|
+
* // => 'Tom & Jerry'
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* // Escape quotes in attributes
|
|
151
|
+
* escape('He said "Hello"')
|
|
152
|
+
* // => 'He said "Hello"'
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* // Safe to use in innerHTML
|
|
156
|
+
* const userInput = '<img src=x onerror=alert(1)>'
|
|
157
|
+
* element.innerHTML = escape(userInput)
|
|
158
|
+
* // Renders as text, not as HTML
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* // Escape single quotes
|
|
162
|
+
* escape("It's a test")
|
|
163
|
+
* // => 'It's a test'
|
|
164
|
+
*/
|
|
165
|
+
declare function escape(str: string): string;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Converts HTML entities back to their corresponding characters.
|
|
169
|
+
* Inverse of escape().
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* // Unescape HTML entities
|
|
173
|
+
* unescape('<script>')
|
|
174
|
+
* // => '<script>'
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* // Unescape ampersands
|
|
178
|
+
* unescape('Tom & Jerry')
|
|
179
|
+
* // => 'Tom & Jerry'
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* // Unescape quotes
|
|
183
|
+
* unescape('He said "Hello"')
|
|
184
|
+
* // => 'He said "Hello"'
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* // Parse escaped content from API
|
|
188
|
+
* const apiResponse = { title: 'Rock & Roll' }
|
|
189
|
+
* unescape(apiResponse.title)
|
|
190
|
+
* // => 'Rock & Roll'
|
|
191
|
+
*/
|
|
192
|
+
declare function unescape(str: string): string;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Escapes special RegExp characters in a string.
|
|
196
|
+
* Useful when building dynamic regular expressions from user input.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* // Escape special characters
|
|
200
|
+
* escapeRegExp('[lodash](https://lodash.com/)')
|
|
201
|
+
* // => '\\[lodash\\]\\(https://lodash\\.com/\\)'
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* // Safe dynamic regex from user input
|
|
205
|
+
* const userSearch = 'price: $100'
|
|
206
|
+
* const regex = new RegExp(escapeRegExp(userSearch), 'i')
|
|
207
|
+
* regex.test('The price: $100 is final') // => true
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* // Highlight search terms safely
|
|
211
|
+
* function highlightText(text: string, search: string) {
|
|
212
|
+
* const escaped = escapeRegExp(search)
|
|
213
|
+
* return text.replace(new RegExp(escaped, 'gi'), '<mark>$&</mark>')
|
|
214
|
+
* }
|
|
215
|
+
* highlightText('Hello (world)', '(world)')
|
|
216
|
+
* // => 'Hello <mark>(world)</mark>'
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* // Build complex patterns safely
|
|
220
|
+
* const terms = ['C++', 'C#', '.NET']
|
|
221
|
+
* const pattern = terms.map(escapeRegExp).join('|')
|
|
222
|
+
* const regex = new RegExp(pattern, 'g')
|
|
223
|
+
* 'I know C++ and .NET'.match(regex)
|
|
224
|
+
* // => ['C++', '.NET']
|
|
225
|
+
*/
|
|
226
|
+
declare function escapeRegExp(str: string): string;
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Pads a string on both sides to reach the target length.
|
|
230
|
+
* If the padding length is odd, the extra character goes to the right.
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* // Center text
|
|
234
|
+
* pad('hello', 11)
|
|
235
|
+
* // => ' hello '
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* // Custom padding character
|
|
239
|
+
* pad('5', 3, '0')
|
|
240
|
+
* // => '050'
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* // Center with dashes
|
|
244
|
+
* pad('TITLE', 15, '-')
|
|
245
|
+
* // => '-----TITLE-----'
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* // No padding if already long enough
|
|
249
|
+
* pad('hello', 3)
|
|
250
|
+
* // => 'hello'
|
|
251
|
+
*/
|
|
252
|
+
declare function pad(str: string, length: number, chars?: string): string;
|
|
253
|
+
/**
|
|
254
|
+
* Pads a string on the left (start) to reach the target length.
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* // Pad numbers with zeros
|
|
258
|
+
* padStart('5', 3, '0')
|
|
259
|
+
* // => '005'
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* // Format time components
|
|
263
|
+
* padStart('9', 2, '0')
|
|
264
|
+
* // => '09'
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* // Align text to the right
|
|
268
|
+
* padStart('42', 5)
|
|
269
|
+
* // => ' 42'
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
272
|
+
* // Format IDs
|
|
273
|
+
* padStart('123', 8, '0')
|
|
274
|
+
* // => '00000123'
|
|
275
|
+
*/
|
|
276
|
+
declare function padStart(str: string, length: number, chars?: string): string;
|
|
277
|
+
/**
|
|
278
|
+
* Pads a string on the right (end) to reach the target length.
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* // Align text to the left
|
|
282
|
+
* padEnd('hello', 10)
|
|
283
|
+
* // => 'hello '
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* // Create fixed-width columns
|
|
287
|
+
* padEnd('Name', 20) + padEnd('Age', 5)
|
|
288
|
+
* // => 'Name Age '
|
|
289
|
+
*
|
|
290
|
+
* @example
|
|
291
|
+
* // Pad with custom character
|
|
292
|
+
* padEnd('1', 4, '0')
|
|
293
|
+
* // => '1000'
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* // Format file sizes
|
|
297
|
+
* padEnd('1.5', 6, '0') + ' MB'
|
|
298
|
+
* // => '1.5000 MB'
|
|
299
|
+
*/
|
|
300
|
+
declare function padEnd(str: string, length: number, chars?: string): string;
|
|
301
|
+
|
|
302
|
+
export { camelCase, capitalize, deburr, escape, escapeRegExp, kebabCase, pad, padEnd, padStart, pascalCase, slugify, snakeCase, template, truncate, uncapitalize, unescape, words };
|