@leexi/shared 0.3.9 → 0.5.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.
Files changed (64) hide show
  1. package/README.md +198 -43
  2. package/dist/eslint/base.eslint.config.d.ts +3 -1277
  3. package/dist/eslint/base.eslint.config.mjs +6 -3
  4. package/dist/eslint/vue.eslint.config.d.ts +3 -1307
  5. package/dist/eslint/vue.eslint.config.mjs +2 -1
  6. package/dist/module.json +2 -2
  7. package/dist/runtime/utils/array/castArray.d.ts +1 -0
  8. package/dist/runtime/utils/array/castArray.js +3 -0
  9. package/dist/runtime/utils/array/groupBy.d.ts +1 -0
  10. package/dist/runtime/utils/array/groupBy.js +9 -0
  11. package/dist/runtime/utils/array/index.d.ts +11 -0
  12. package/dist/runtime/utils/array/index.js +11 -0
  13. package/dist/runtime/utils/array/joinBy.d.ts +1 -0
  14. package/dist/runtime/utils/array/joinBy.js +9 -0
  15. package/dist/runtime/utils/array/partition.d.ts +1 -0
  16. package/dist/runtime/utils/array/partition.js +4 -0
  17. package/dist/runtime/utils/array/removeRecord.d.ts +1 -0
  18. package/dist/runtime/utils/array/removeRecord.js +5 -0
  19. package/dist/runtime/utils/array/replaceRecord.d.ts +1 -0
  20. package/dist/runtime/utils/array/replaceRecord.js +5 -0
  21. package/dist/runtime/utils/array/sortBy.d.ts +2 -0
  22. package/dist/runtime/utils/array/sortBy.js +40 -0
  23. package/dist/runtime/utils/array/sum.d.ts +1 -0
  24. package/dist/runtime/utils/array/sum.js +1 -0
  25. package/dist/runtime/utils/array/sumBy.d.ts +1 -0
  26. package/dist/runtime/utils/array/sumBy.js +3 -0
  27. package/dist/runtime/utils/array/uniq.d.ts +1 -0
  28. package/dist/runtime/utils/array/uniq.js +1 -0
  29. package/dist/runtime/utils/array/uniqBy.d.ts +1 -0
  30. package/dist/runtime/utils/array/uniqBy.js +8 -0
  31. package/dist/runtime/utils/function/debounce.d.ts +1 -0
  32. package/dist/runtime/utils/function/debounce.js +6 -0
  33. package/dist/runtime/utils/function/index.d.ts +1 -0
  34. package/dist/runtime/utils/function/index.js +1 -0
  35. package/dist/runtime/utils/index.d.ts +4 -0
  36. package/dist/runtime/utils/index.js +4 -0
  37. package/dist/runtime/utils/number/index.d.ts +1 -0
  38. package/dist/runtime/utils/number/index.js +1 -0
  39. package/dist/runtime/utils/number/toPadStart.d.ts +1 -0
  40. package/dist/runtime/utils/number/toPadStart.js +3 -0
  41. package/dist/runtime/utils/promise/index.d.ts +3 -0
  42. package/dist/runtime/utils/promise/index.js +3 -0
  43. package/dist/runtime/utils/promise/singleFlight.d.ts +1 -0
  44. package/dist/runtime/utils/promise/singleFlight.js +32 -0
  45. package/dist/runtime/utils/promise/sleep.d.ts +1 -0
  46. package/dist/runtime/utils/promise/sleep.js +1 -0
  47. package/dist/runtime/utils/promise/throttle.d.ts +1 -0
  48. package/dist/runtime/utils/promise/throttle.js +32 -0
  49. package/dist/runtime/utils/records/get.d.ts +1 -0
  50. package/dist/runtime/utils/records/get.js +5 -0
  51. package/dist/runtime/utils/records/index.d.ts +2 -0
  52. package/dist/runtime/utils/records/index.js +2 -0
  53. package/dist/runtime/utils/records/merge.d.ts +1 -0
  54. package/dist/runtime/utils/records/merge.js +16 -0
  55. package/dist/runtime/utils/records/set.js +4 -2
  56. package/dist/runtime/utils/strings/index.d.ts +3 -0
  57. package/dist/runtime/utils/strings/index.js +3 -0
  58. package/dist/runtime/utils/strings/strContains.d.ts +1 -0
  59. package/dist/runtime/utils/strings/strContains.js +18 -0
  60. package/dist/runtime/utils/strings/truncate.d.ts +1 -0
  61. package/dist/runtime/utils/strings/truncate.js +5 -0
  62. package/dist/runtime/utils/strings/urlify.d.ts +1 -0
  63. package/dist/runtime/utils/strings/urlify.js +1 -0
  64. package/package.json +10 -9
package/README.md CHANGED
@@ -64,18 +64,43 @@ export default defineNuxtConfig({
64
64
  - [Composables](#composables)
65
65
  - [useLocalStorage](#uselocalstorage)
66
66
  - [Utils](#utils)
67
+ - [Array](#array)
68
+ - [castArray](#castarray)
69
+ - [groupBy](#groupby)
70
+ - [joinBy](#joinby)
71
+ - [partition](#partition)
72
+ - [removeRecord](#removerecord)
73
+ - [replaceRecord](#replacerecord)
74
+ - [sortBy](#sortby)
75
+ - [sum](#sum)
76
+ - [sumBy](#sumby)
77
+ - [uniq](#uniq)
78
+ - [uniqBy](#uniqby)
79
+ - [Function](#function)
80
+ - [debounce](#debounce)
81
+ - [Number](#number)
82
+ - [toPadStart](#topadstart)
83
+ - [Objects](#objects)
84
+ - [deepDup](#deepdup)
85
+ - [isSame](#issame)
86
+ - [Promise](#promise)
87
+ - [singleFlight](#singleflight)
88
+ - [sleep](#sleep)
89
+ - [throttle](#throttle)
67
90
  - [Records](#records)
68
- - [set](#set)
69
- - [pick](#pick)
91
+ - [get](#get)
92
+ - [merge](#merge)
70
93
  - [omit](#omit)
94
+ - [pick](#pick)
95
+ - [set](#set)
71
96
  - [Strings](#strings)
72
97
  - [camelcase](#camelcase)
73
98
  - [capitalize](#capitalize)
74
99
  - [kebabcase](#kebabcase)
75
100
  - [snakecase](#snakecase)
76
- - [Objects](#objects)
77
- - [isSame](#issame)
78
- - [deepDup](#deepdup)
101
+ - [strContains](#strcontains)
102
+ - [truncate](#truncate)
103
+ - [urlify](#urlify)
79
104
 
80
105
  ## Composables
81
106
  ### useLocalStorage
@@ -100,20 +125,168 @@ console.log(localStorage.userSetting); // Output: '{"theme":"dark","notification
100
125
  ```
101
126
 
102
127
  ## Utils
128
+ ### Array
129
+ #### castArray
130
+ - Type
131
+ ```ts
132
+
133
+ ```
134
+
135
+ #### groupBy
136
+ - Type
137
+ ```ts
138
+
139
+ ```
140
+
141
+ #### joinBy
142
+ - Type
143
+ ```ts
144
+
145
+ ```
146
+
147
+ #### partition
148
+ - Type
149
+ ```ts
150
+
151
+ ```
152
+
153
+ #### removeRecord
154
+ - Type
155
+ ```ts
156
+
157
+ ```
158
+
159
+ #### replaceRecord
160
+ - Type
161
+ ```ts
162
+
163
+ ```
164
+
165
+ #### sortBy
166
+ - Type
167
+ ```ts
168
+ const sortBy: <T, C extends (_: T) => Primitive, K extends Extract<FilteredAttrs<T, Primitive>, string>>(items: T[], attrsOrCallbacks: C | K | `-${K}` | (C | K | `-${K}`)[]) => T[];
169
+ ```
170
+
171
+ #### sum
172
+ - Type
173
+ ```ts
174
+
175
+ ```
176
+
177
+ #### sumBy
178
+ - Type
179
+ ```ts
180
+
181
+ ```
182
+
183
+ #### uniq
184
+ - Type
185
+ ```ts
186
+
187
+ ```
188
+
189
+ #### uniqBy
190
+ - Type
191
+ ```ts
192
+
193
+ ```
194
+
195
+ ### Function
196
+ #### debounce
197
+ - Type
198
+ ```ts
199
+
200
+ ```
201
+
202
+ ### Number
203
+ #### toPadStart
204
+ - Type
205
+ ```ts
206
+
207
+ ```
208
+
209
+ ### Objects
210
+ #### deepDup
211
+ Creates a deep duplicate of an object, array, or Set.
212
+ It handles nested objects, arrays, and Sets but does not handle functions, Dates, or circular references.
213
+ - Type
214
+ ```ts
215
+ const deepDup: <T extends object>(object: T) => T;
216
+ ```
217
+ - Example
218
+ ```ts
219
+ const originalObject = { a: 1, b: { c: 2, d: [3, 4] }, e: new Set([5, 6]) };
220
+ const duplicatedObject = deepDup(originalObject);
221
+
222
+ console.log(duplicatedObject); // Output: { a: 1, b: { c: 2, d: [3, 4] }, e: Set { 5, 6 } }
223
+ console.log(originalObject === duplicatedObject); // Output: false
224
+ console.log(originalObject.b === duplicatedObject.b); // Output: false
225
+ console.log(originalObject.b.d === duplicatedObject.b.d); // Output: false
226
+ console.log(originalObject.e === duplicatedObject.e); // Output: false
227
+ ```
228
+
229
+ #### isSame
230
+ Checks if two objects are the same by comparing their JSON stringified representations.
231
+ Note: This method has limitations and may not accurately compare objects with different key orders, non-primitive values like functions or Dates, or circular references.
232
+ - Type
233
+ ```ts
234
+ const isSame: (a: object, b: object) => boolean;
235
+ ```
236
+ - Example
237
+ ```ts
238
+ const obj1 = { a: 1, b: 2 };
239
+ const obj2 = { a: 1, b: 2 };
240
+ const obj3 = { b: 2, a: 1 };
241
+
242
+ console.log(isSame(obj1, obj2)); // Output: true
243
+ console.log(isSame(obj1, obj3)); // Output: false (due to key order difference in JSON stringification)
244
+ ```
245
+
246
+ ### Promise
247
+ #### singleFlight
248
+ - Type
249
+ ```ts
250
+
251
+ ```
252
+
253
+ #### sleep
254
+ - Type
255
+ ```ts
256
+
257
+ ```
258
+
259
+ #### throttle
260
+ - Type
261
+ ```ts
262
+
263
+ ```
264
+
103
265
  ### Records
104
- #### set
105
- Sets a value within a nested object structure based on a provided path.
106
- It mutates the original object and creates nested objects if they don't exist along the path.
266
+ #### get
107
267
  - Type
108
268
  ```ts
109
- const set: <T extends Record<string, unknown>, const P extends string[], V>(record: T, path: P, value: V) => SetRecord<T, P, V>;
269
+
270
+ ```
271
+
272
+ #### merge
273
+ - Type
274
+ ```ts
275
+
276
+ ```
277
+
278
+ #### omit
279
+ Creates a new object by omitting the specified keys from the input record.
280
+ - Type
281
+ ```ts
282
+ const omit: <T extends Record<string, unknown>, K extends (keyof T)[]>(record: T, keys: K) => Omit<T, K[number]>;
110
283
  ```
111
284
  - Example
112
285
  ```ts
113
- const myObject = { a: { b: { c: 1 } } };
114
- set(myObject, ['a', 'b', 'd'], 2);
286
+ const myObject = { a: 1, b: 2, c: 3, d: 4 };
287
+ const omittedObject = omit(myObject, ['b', 'd']);
115
288
 
116
- console.log(myObject); // Output: { a: { b: { c: 1, d: 2 } } }
289
+ console.log(omittedObject); // Output: { a: 1, c: 3 }
117
290
  ```
118
291
 
119
292
  #### pick
@@ -130,18 +303,19 @@ const pickedObject = pick(myObject, ['a', 'c']);
130
303
  console.log(pickedObject); // Output: { a: 1, c: 3 }
131
304
  ```
132
305
 
133
- #### omit
134
- Creates a new object by omitting the specified keys from the input record.
306
+ #### set
307
+ Sets a value within a nested object structure based on a provided path.
308
+ It mutates the original object and creates nested objects if they don't exist along the path.
135
309
  - Type
136
310
  ```ts
137
- const omit: <T extends Record<string, unknown>, K extends (keyof T)[]>(record: T, keys: K) => Omit<T, K[number]>;
311
+ const set: <T extends Record<string, unknown>, const P extends string[], V>(record: T, path: P, value: V) => SetRecord<T, P, V>;
138
312
  ```
139
313
  - Example
140
314
  ```ts
141
- const myObject = { a: 1, b: 2, c: 3, d: 4 };
142
- const omittedObject = omit(myObject, ['b', 'd']);
315
+ const myObject = { a: { b: { c: 1 } } };
316
+ set(myObject, ['a', 'b', 'd'], 2);
143
317
 
144
- console.log(omittedObject); // Output: { a: 1, c: 3 }
318
+ console.log(myObject); // Output: { a: { b: { c: 1, d: 2 } } }
145
319
  ```
146
320
 
147
321
  ### Strings
@@ -196,39 +370,20 @@ console.log(snakecase('my-variable-name')); // Output: my_variable_name
196
370
  console.log(snakecase('my_variable_name')); // Output: my_variable_name
197
371
  ```
198
372
 
199
- ### Objects
200
- #### isSame
201
- Checks if two objects are the same by comparing their JSON stringified representations.
202
- Note: This method has limitations and may not accurately compare objects with different key orders, non-primitive values like functions or Dates, or circular references.
373
+ #### strContains
203
374
  - Type
204
375
  ```ts
205
- const isSame: (a: object, b: object) => boolean;
206
- ```
207
- - Example
208
- ```ts
209
- const obj1 = { a: 1, b: 2 };
210
- const obj2 = { a: 1, b: 2 };
211
- const obj3 = { b: 2, a: 1 };
212
376
 
213
- console.log(isSame(obj1, obj2)); // Output: true
214
- console.log(isSame(obj1, obj3)); // Output: false (due to key order difference in JSON stringification)
215
377
  ```
216
378
 
217
- #### deepDup
218
- Creates a deep duplicate of an object, array, or Set.
219
- It handles nested objects, arrays, and Sets but does not handle functions, Dates, or circular references.
379
+ #### truncate
220
380
  - Type
221
381
  ```ts
222
- const deepDup: <T extends object>(object: T) => T;
382
+
223
383
  ```
224
- - Example
384
+
385
+ #### urlify
386
+ - Type
225
387
  ```ts
226
- const originalObject = { a: 1, b: { c: 2, d: [3, 4] }, e: new Set([5, 6]) };
227
- const duplicatedObject = deepDup(originalObject);
228
388
 
229
- console.log(duplicatedObject); // Output: { a: 1, b: { c: 2, d: [3, 4] }, e: Set { 5, 6 } }
230
- console.log(originalObject === duplicatedObject); // Output: false
231
- console.log(originalObject.b === duplicatedObject.b); // Output: false
232
- console.log(originalObject.b.d === duplicatedObject.b.d); // Output: false
233
- console.log(originalObject.e === duplicatedObject.e); // Output: false
234
389
  ```