@leexi/shared 0.3.9 → 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.
- package/README.md +198 -43
- package/dist/eslint/base.eslint.config.d.ts +3 -1277
- package/dist/eslint/base.eslint.config.mjs +6 -3
- package/dist/eslint/vue.eslint.config.d.ts +3 -1307
- package/dist/eslint/vue.eslint.config.mjs +2 -1
- package/dist/module.json +2 -2
- package/dist/runtime/utils/array/castArray.d.ts +1 -0
- package/dist/runtime/utils/array/castArray.js +3 -0
- package/dist/runtime/utils/array/groupBy.d.ts +1 -0
- package/dist/runtime/utils/array/groupBy.js +9 -0
- package/dist/runtime/utils/array/index.d.ts +11 -0
- package/dist/runtime/utils/array/index.js +11 -0
- package/dist/runtime/utils/array/joinBy.d.ts +1 -0
- package/dist/runtime/utils/array/joinBy.js +9 -0
- package/dist/runtime/utils/array/partition.d.ts +1 -0
- package/dist/runtime/utils/array/partition.js +4 -0
- package/dist/runtime/utils/array/removeRecord.d.ts +1 -0
- package/dist/runtime/utils/array/removeRecord.js +3 -0
- package/dist/runtime/utils/array/replaceRecord.d.ts +1 -0
- package/dist/runtime/utils/array/replaceRecord.js +3 -0
- package/dist/runtime/utils/array/sortBy.d.ts +2 -0
- package/dist/runtime/utils/array/sortBy.js +40 -0
- package/dist/runtime/utils/array/sum.d.ts +1 -0
- package/dist/runtime/utils/array/sum.js +1 -0
- package/dist/runtime/utils/array/sumBy.d.ts +1 -0
- package/dist/runtime/utils/array/sumBy.js +3 -0
- package/dist/runtime/utils/array/uniq.d.ts +1 -0
- package/dist/runtime/utils/array/uniq.js +1 -0
- package/dist/runtime/utils/array/uniqBy.d.ts +1 -0
- package/dist/runtime/utils/array/uniqBy.js +8 -0
- package/dist/runtime/utils/function/debounce.d.ts +1 -0
- package/dist/runtime/utils/function/debounce.js +6 -0
- package/dist/runtime/utils/function/index.d.ts +1 -0
- package/dist/runtime/utils/function/index.js +1 -0
- package/dist/runtime/utils/index.d.ts +4 -0
- package/dist/runtime/utils/index.js +4 -0
- package/dist/runtime/utils/number/index.d.ts +1 -0
- package/dist/runtime/utils/number/index.js +1 -0
- package/dist/runtime/utils/number/toPadStart.d.ts +1 -0
- package/dist/runtime/utils/number/toPadStart.js +3 -0
- package/dist/runtime/utils/promise/index.d.ts +3 -0
- package/dist/runtime/utils/promise/index.js +3 -0
- package/dist/runtime/utils/promise/singleFlight.d.ts +1 -0
- package/dist/runtime/utils/promise/singleFlight.js +32 -0
- package/dist/runtime/utils/promise/sleep.d.ts +1 -0
- package/dist/runtime/utils/promise/sleep.js +1 -0
- package/dist/runtime/utils/promise/throttle.d.ts +1 -0
- package/dist/runtime/utils/promise/throttle.js +32 -0
- package/dist/runtime/utils/records/get.d.ts +1 -0
- package/dist/runtime/utils/records/get.js +5 -0
- package/dist/runtime/utils/records/index.d.ts +2 -0
- package/dist/runtime/utils/records/index.js +2 -0
- package/dist/runtime/utils/records/merge.d.ts +1 -0
- package/dist/runtime/utils/records/merge.js +16 -0
- package/dist/runtime/utils/records/set.js +4 -2
- package/dist/runtime/utils/strings/index.d.ts +3 -0
- package/dist/runtime/utils/strings/index.js +3 -0
- package/dist/runtime/utils/strings/strContains.d.ts +1 -0
- package/dist/runtime/utils/strings/strContains.js +18 -0
- package/dist/runtime/utils/strings/truncate.d.ts +1 -0
- package/dist/runtime/utils/strings/truncate.js +5 -0
- package/dist/runtime/utils/strings/urlify.d.ts +1 -0
- package/dist/runtime/utils/strings/urlify.js +1 -0
- 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
|
-
- [
|
|
69
|
-
- [
|
|
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
|
-
|
|
77
|
-
- [
|
|
78
|
-
- [
|
|
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
|
-
####
|
|
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
|
-
|
|
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:
|
|
114
|
-
|
|
286
|
+
const myObject = { a: 1, b: 2, c: 3, d: 4 };
|
|
287
|
+
const omittedObject = omit(myObject, ['b', 'd']);
|
|
115
288
|
|
|
116
|
-
console.log(
|
|
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
|
-
####
|
|
134
|
-
|
|
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
|
|
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:
|
|
142
|
-
|
|
315
|
+
const myObject = { a: { b: { c: 1 } } };
|
|
316
|
+
set(myObject, ['a', 'b', 'd'], 2);
|
|
143
317
|
|
|
144
|
-
console.log(
|
|
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
|
-
|
|
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
|
-
####
|
|
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
|
-
|
|
382
|
+
|
|
223
383
|
```
|
|
224
|
-
|
|
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
|
```
|