@leexi/shared 0.3.8 → 0.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.
Files changed (64) hide show
  1. package/README.md +192 -37
  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 +3 -3
  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 +3 -0
  19. package/dist/runtime/utils/array/replaceRecord.d.ts +1 -0
  20. package/dist/runtime/utils/array/replaceRecord.js +3 -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 +13 -12
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)
91
+ - [get](#get)
92
+ - [merge](#merge)
69
93
  - [omit](#omit)
70
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
- - [deepDup](#deepdup)
78
- - [isSame](#issame)
101
+ - [strContains](#strcontains)
102
+ - [truncate](#truncate)
103
+ - [urlify](#urlify)
79
104
 
80
105
  ## Composables
81
106
  ### useLocalStorage
@@ -100,20 +125,154 @@ console.log(localStorage.userSetting); // Output: '{"theme":"dark","notification
100
125
  ```
101
126
 
102
127
  ## Utils
103
- ### 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.
128
+ ### Array
129
+ #### castArray
107
130
  - Type
108
131
  ```ts
109
- const set: <T extends Record<string, unknown>, const P extends string[], V>(record: T, path: P, value: V) => SetRecord<T, P, V>;
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;
110
216
  ```
111
217
  - Example
112
218
  ```ts
113
- const myObject = { a: { b: { c: 1 } } };
114
- set(myObject, ['a', 'b', 'd'], 2);
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
+
265
+ ### Records
266
+ #### get
267
+ - Type
268
+ ```ts
269
+
270
+ ```
271
+
272
+ #### merge
273
+ - Type
274
+ ```ts
115
275
 
116
- console.log(myObject); // Output: { a: { b: { c: 1, d: 2 } } }
117
276
  ```
118
277
 
119
278
  #### omit
@@ -144,6 +303,21 @@ const pickedObject = pick(myObject, ['a', 'c']);
144
303
  console.log(pickedObject); // Output: { a: 1, c: 3 }
145
304
  ```
146
305
 
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.
309
+ - Type
310
+ ```ts
311
+ const set: <T extends Record<string, unknown>, const P extends string[], V>(record: T, path: P, value: V) => SetRecord<T, P, V>;
312
+ ```
313
+ - Example
314
+ ```ts
315
+ const myObject = { a: { b: { c: 1 } } };
316
+ set(myObject, ['a', 'b', 'd'], 2);
317
+
318
+ console.log(myObject); // Output: { a: { b: { c: 1, d: 2 } } }
319
+ ```
320
+
147
321
  ### Strings
148
322
  #### camelcase
149
323
  Converts a string from snake_case or kebab-case to camelCase.
@@ -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
- #### deepDup
201
- Creates a deep duplicate of an object, array, or Set.
202
- It handles nested objects, arrays, and Sets but does not handle functions, Dates, or circular references.
373
+ #### strContains
203
374
  - Type
204
375
  ```ts
205
- const deepDup: <T extends object>(object: T) => T;
206
- ```
207
- - Example
208
- ```ts
209
- const originalObject = { a: 1, b: { c: 2, d: [3, 4] }, e: new Set([5, 6]) };
210
- const duplicatedObject = deepDup(originalObject);
211
376
 
212
- console.log(duplicatedObject); // Output: { a: 1, b: { c: 2, d: [3, 4] }, e: Set { 5, 6 } }
213
- console.log(originalObject === duplicatedObject); // Output: false
214
- console.log(originalObject.b === duplicatedObject.b); // Output: false
215
- console.log(originalObject.b.d === duplicatedObject.b.d); // Output: false
216
- console.log(originalObject.e === duplicatedObject.e); // Output: false
217
377
  ```
218
378
 
219
- #### isSame
220
- Checks if two objects are the same by comparing their JSON stringified representations.
221
- 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.
379
+ #### truncate
222
380
  - Type
223
381
  ```ts
224
- const isSame: (a: object, b: object) => boolean;
382
+
225
383
  ```
226
- - Example
384
+
385
+ #### urlify
386
+ - Type
227
387
  ```ts
228
- const obj1 = { a: 1, b: 2 };
229
- const obj2 = { a: 1, b: 2 };
230
- const obj3 = { b: 2, a: 1 };
231
388
 
232
- console.log(isSame(obj1, obj2)); // Output: true
233
- console.log(isSame(obj1, obj3)); // Output: false (due to key order difference in JSON stringification)
234
389
  ```