moderndash 0.0.16 → 0.0.17

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 (66) hide show
  1. package/README.md +16 -75
  2. package/dist/index.cjs +66 -73
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.ts +125 -113
  5. package/dist/index.js +62 -69
  6. package/dist/index.js.map +1 -1
  7. package/package.json +6 -5
  8. package/src/array/chunk.ts +0 -31
  9. package/src/array/difference.ts +0 -21
  10. package/src/array/differenceBy.ts +0 -30
  11. package/src/array/differenceWith.ts +0 -31
  12. package/src/array/dropRightWhile.ts +0 -28
  13. package/src/array/dropWhile.ts +0 -24
  14. package/src/array/index.ts +0 -21
  15. package/src/array/intersection.ts +0 -20
  16. package/src/array/intersectionBy.ts +0 -26
  17. package/src/array/intersectionWith.ts +0 -33
  18. package/src/array/sample.ts +0 -18
  19. package/src/array/sampleSize.ts +0 -31
  20. package/src/array/shuffle.ts +0 -33
  21. package/src/array/takeRightWhile.ts +0 -33
  22. package/src/array/takeWhile.ts +0 -33
  23. package/src/array/uniq.ts +0 -18
  24. package/src/array/uniqBy.ts +0 -25
  25. package/src/array/uniqWith.ts +0 -20
  26. package/src/array/unzip.ts +0 -20
  27. package/src/array/unzipWith.ts +0 -26
  28. package/src/array/zip.ts +0 -17
  29. package/src/array/zipWith.ts +0 -28
  30. package/src/collection/countBy.ts +0 -38
  31. package/src/collection/groupBy.ts +0 -32
  32. package/src/collection/index.ts +0 -3
  33. package/src/collection/sortBy.ts +0 -15
  34. package/src/function/after.ts +0 -29
  35. package/src/function/before.ts +0 -31
  36. package/src/function/debounce.ts +0 -125
  37. package/src/function/index.ts +0 -7
  38. package/src/function/memoize.ts +0 -63
  39. package/src/function/once.ts +0 -22
  40. package/src/function/throttle.ts +0 -13
  41. package/src/function/times.ts +0 -24
  42. package/src/helpers/collections.ts +0 -5
  43. package/src/helpers/shortHands.ts +0 -17
  44. package/src/helpers/stringModifiers.ts +0 -18
  45. package/src/helpers/typeofChecks.ts +0 -3
  46. package/src/index.ts +0 -7
  47. package/src/lang/index.ts +0 -4
  48. package/src/lang/isEmpty.ts +0 -51
  49. package/src/lang/isEqual.ts +0 -80
  50. package/src/lang/isEqualWith.ts +0 -34
  51. package/src/lang/isPlainObject.ts +0 -3
  52. package/src/object/index.ts +0 -1
  53. package/src/object/pick.ts +0 -21
  54. package/src/string/camelCase.ts +0 -30
  55. package/src/string/capitalize.ts +0 -14
  56. package/src/string/deburr.ts +0 -20
  57. package/src/string/escape.ts +0 -21
  58. package/src/string/escapeRegExp.ts +0 -15
  59. package/src/string/index.ts +0 -11
  60. package/src/string/kebabCase.ts +0 -25
  61. package/src/string/pascalCase.ts +0 -26
  62. package/src/string/snakeCase.ts +0 -30
  63. package/src/string/startCase.ts +0 -25
  64. package/src/string/stripSpecialChars.ts +0 -17
  65. package/src/string/unescape.ts +0 -22
  66. package/src/types.ts +0 -15
package/README.md CHANGED
@@ -2,92 +2,33 @@
2
2
 
3
3
  <p align=center>
4
4
  A Typescript-First utility library inspired by Lodash.
5
- Optimized for modern browsers.
5
+ Optimized for modern browsers, typescript & developer experience.
6
6
  </p>
7
7
  <p align=center>
8
8
  ✅ ESM
9
9
  ✅ Tree-shakable
10
10
  ✅ Typescript Strict Mode (no any types)
11
11
  ✅ Zero dependencies
12
+ ✅ Hoverable Docs
12
13
  </p>
13
14
 
14
- -------
15
+ <h2 align=center>
16
+ <a href="https://moderndash.io" target="_blank">
17
+ 📓 Documentation
18
+ </a>
19
+ </h2>
20
+
21
+ ---
15
22
 
16
23
  > **Warning**
17
24
  > This library is still in development and is not ready for production use.
18
25
 
19
- ## Documentation
20
- The documentation is WIP.
21
- [Documentation](https://moderndash.io/)
22
-
23
- ## Removed Functions because of trivial native alternatives
24
- Look at [You-Dont-Need-Lodash](https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore) for native replacements.
25
-
26
- ### Array Functions
27
- - compact
28
- - concat
29
- - differenceBy property shorthand
30
- - drop
31
- - dropRight
32
- - fill
33
- - findIndex
34
- - findLastIndex
35
- - first/head
36
- - flatten
37
- - flattenDeep
38
- - flattenDepth
39
- - fromPairs
40
- - initial
41
- - join
42
- - last
43
- - lastIndexOf
44
- - nth
45
- - without
46
- - reverse
47
- - slice
48
- - sortedIndexOf
49
- - tail
50
- - take
51
- - takeRight
52
- - without
53
-
54
- ### Collection Functions
55
- - each/forEach
56
- - every
57
- - filter
58
- - find
59
- - flatMap
60
- - includes
61
-
62
- ### String Functions
63
- - lowerCase
64
- - trim
65
- - trimEnd
66
- - trimStart
67
- - pad
68
- - padEnd
69
- - padStart
70
-
71
- Functions are not considered trivial if they:
72
- - include reduce methods
73
- - include multiple nested function calls
74
-
75
- ## TODO
76
- - More unzip tests
77
- - Check if flatmapdeep, flatmapDepth is included in native flatmap
78
- - GroupBy Property Shorthand
26
+ ## Installation
79
27
 
80
- ## Might be added later (open for discussion)
81
- - pull functions (pull, pullAll, pullAllBy, pullAllWith, pullAt)
82
- - remove
83
- - sorted functions (sortedIndex, sortedIndexBy, sortedIndexOf, sortedLastIndex, sortedLastIndexBy, sortedLastIndexOf, sortedUniq, sortedUniqBy)
84
- - if performance is better than native alternatives (testing needed)
85
- - xor functions (xor, xorBy, xorWith)
86
- - zipObject, zipObjectDeep
87
- - forEachRight
88
- - findLast
89
- - lowerFirst
90
- - keyBy
28
+ ```bash
29
+ npm install moderndash
30
+ ```
91
31
 
92
- ## Continue at
93
- - invokeMap
32
+ ## Why is X lodash function not included?
33
+ Please check [You-Dont-Need-Lodash](https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore) for native replacements.
34
+ If you still think a function is missing please open an issue.
package/dist/index.cjs CHANGED
@@ -25,7 +25,7 @@ __export(src_exports, {
25
25
  camelCase: () => camelCase,
26
26
  capitalize: () => capitalize,
27
27
  chunk: () => chunk,
28
- countBy: () => countBy,
28
+ count: () => count,
29
29
  debounce: () => debounce,
30
30
  deburr: () => deburr,
31
31
  difference: () => difference,
@@ -35,7 +35,7 @@ __export(src_exports, {
35
35
  dropWhile: () => dropWhile,
36
36
  escape: () => escape,
37
37
  escapeRegExp: () => escapeRegExp,
38
- groupBy: () => groupBy,
38
+ group: () => group,
39
39
  intersection: () => intersection,
40
40
  intersectionBy: () => intersectionBy,
41
41
  intersectionWith: () => intersectionWith,
@@ -52,9 +52,9 @@ __export(src_exports, {
52
52
  sampleSize: () => sampleSize,
53
53
  shuffle: () => shuffle,
54
54
  snakeCase: () => snakeCase,
55
- sortBy: () => sortBy,
55
+ sort: () => sort,
56
56
  startCase: () => startCase,
57
- stripSpecialChars: () => stripSpecialChars,
57
+ stripSpecial: () => stripSpecial,
58
58
  takeRightWhile: () => takeRightWhile,
59
59
  takeWhile: () => takeWhile,
60
60
  throttle: () => throttle,
@@ -85,6 +85,20 @@ function chunk(chunkSize, array) {
85
85
  return chunkedArray;
86
86
  }
87
87
 
88
+ // src/array/count.ts
89
+ function count(array, iteratee) {
90
+ const result = {};
91
+ for (const value of array) {
92
+ const key = iteratee(value);
93
+ if (result[key] === void 0) {
94
+ result[key] = 1;
95
+ } else {
96
+ result[key] += 1;
97
+ }
98
+ }
99
+ return result;
100
+ }
101
+
88
102
  // src/array/differenceWith.ts
89
103
  function differenceWith(comparator, ...arrays) {
90
104
  const difference2 = [];
@@ -172,7 +186,7 @@ function differenceBy(iteratee, ...arrays) {
172
186
  }
173
187
 
174
188
  // src/array/dropRightWhile.ts
175
- function dropRightWhile(predicate, array) {
189
+ function dropRightWhile(array, predicate) {
176
190
  let i = array.length;
177
191
  while (i > 0 && predicate(array[i - 1])) {
178
192
  i--;
@@ -181,11 +195,22 @@ function dropRightWhile(predicate, array) {
181
195
  }
182
196
 
183
197
  // src/array/dropWhile.ts
184
- function dropWhile(predicate, array) {
198
+ function dropWhile(array, predicate) {
185
199
  const index = array.findIndex((x) => !predicate(x));
186
200
  return array.slice(index === -1 ? array.length : index);
187
201
  }
188
202
 
203
+ // src/array/group.ts
204
+ function group(array, iteratee) {
205
+ const result = {};
206
+ for (const value of array) {
207
+ const key = iteratee(value);
208
+ result[key] = result[key] ?? [];
209
+ result[key].push(value);
210
+ }
211
+ return result;
212
+ }
213
+
189
214
  // src/array/intersectionWith.ts
190
215
  function intersectionWith(comparator, ...arrays) {
191
216
  const intersection2 = [];
@@ -219,7 +244,7 @@ function sample(array) {
219
244
  }
220
245
 
221
246
  // src/array/sampleSize.ts
222
- function sampleSize(size, array) {
247
+ function sampleSize(array, size) {
223
248
  const sampleArray = [];
224
249
  if (array.length === 0 || size <= 0) {
225
250
  return sampleArray;
@@ -246,6 +271,21 @@ function shuffle(array) {
246
271
  return shuffledArray;
247
272
  }
248
273
 
274
+ // src/array/sort.ts
275
+ function sort(array, order, iteratee) {
276
+ return [...array].sort((a, b) => {
277
+ const aValue = iteratee ? iteratee(a) : a;
278
+ const bValue = iteratee ? iteratee(b) : b;
279
+ if (aValue < bValue) {
280
+ return order === "desc" ? 1 : -1;
281
+ }
282
+ if (aValue > bValue) {
283
+ return order === "desc" ? -1 : 1;
284
+ }
285
+ return 0;
286
+ });
287
+ }
288
+
249
289
  // src/array/takeRightWhile.ts
250
290
  function takeRightWhile(predicate, array) {
251
291
  const result = [];
@@ -260,7 +300,7 @@ function takeRightWhile(predicate, array) {
260
300
  }
261
301
 
262
302
  // src/array/takeWhile.ts
263
- function takeWhile(predicate, array) {
303
+ function takeWhile(array, predicate) {
264
304
  const result = [];
265
305
  for (const element of array) {
266
306
  if (predicate(element)) {
@@ -273,7 +313,7 @@ function takeWhile(predicate, array) {
273
313
  }
274
314
 
275
315
  // src/array/uniqWith.ts
276
- function uniqWith(comparator, array) {
316
+ function uniqWith(array, comparator) {
277
317
  return array.filter((value, index, self) => {
278
318
  return self.findIndex((otherValue) => comparator(value, otherValue)) === index;
279
319
  });
@@ -281,17 +321,17 @@ function uniqWith(comparator, array) {
281
321
 
282
322
  // src/array/uniq.ts
283
323
  function uniq(array) {
284
- return uniqWith(isEqual, array);
324
+ return uniqWith(array, isEqual);
285
325
  }
286
326
 
287
327
  // src/array/uniqBy.ts
288
- function uniqBy(iteratee, array) {
328
+ function uniqBy(array, iteratee) {
289
329
  const iterateeFunction = getIterateFunction(iteratee);
290
- return uniqWith((a, b) => iterateeFunction(a) === iterateeFunction(b), array);
330
+ return uniqWith(array, (a, b) => iterateeFunction(a) === iterateeFunction(b));
291
331
  }
292
332
 
293
333
  // src/array/unzipWith.ts
294
- function unzipWith(iteratee, array) {
334
+ function unzipWith(array, iteratee) {
295
335
  const result = [];
296
336
  for (const elements of array) {
297
337
  result.push(iteratee(...elements));
@@ -301,7 +341,7 @@ function unzipWith(iteratee, array) {
301
341
 
302
342
  // src/array/unzip.ts
303
343
  function unzip(array) {
304
- return unzipWith((...t) => t, array);
344
+ return unzipWith(array, (...t) => t);
305
345
  }
306
346
 
307
347
  // src/array/zipWith.ts
@@ -319,71 +359,24 @@ function zip(...arrays) {
319
359
  return zipWith((...t) => t, ...arrays);
320
360
  }
321
361
 
322
- // src/helpers/collections.ts
323
- function getValuesFromCollection(collection) {
324
- return Array.isArray(collection) ? collection : Object.values(collection);
325
- }
326
-
327
- // src/collection/countBy.ts
328
- function countBy(collection, iteratee) {
329
- const result = {};
330
- const values = getValuesFromCollection(collection);
331
- for (const value of values) {
332
- const key = iteratee(value);
333
- if (result[key] === void 0) {
334
- result[key] = 1;
335
- } else {
336
- result[key] += 1;
337
- }
338
- }
339
- return result;
340
- }
341
-
342
- // src/collection/groupBy.ts
343
- function groupBy(collection, iteratee) {
344
- const result = {};
345
- const values = getValuesFromCollection(collection);
346
- for (const value of values) {
347
- const key = iteratee(value);
348
- result[key] = result[key] ?? [];
349
- result[key].push(value);
350
- }
351
- return result;
352
- }
353
-
354
- // src/collection/sortBy.ts
355
- function sortBy(iteratee, array) {
356
- return array.sort((a, b) => {
357
- const aValue = iteratee(a);
358
- const bValue = iteratee(b);
359
- if (aValue < bValue) {
360
- return -1;
361
- }
362
- if (aValue > bValue) {
363
- return 1;
364
- }
365
- return 0;
366
- });
367
- }
368
-
369
362
  // src/function/after.ts
370
363
  function after(n, func) {
371
- let count = 1;
364
+ let count2 = 1;
372
365
  return (...args) => {
373
- if (count >= n) {
366
+ if (count2 >= n) {
374
367
  return func(...args);
375
368
  }
376
- count += 1;
369
+ count2 += 1;
377
370
  };
378
371
  }
379
372
 
380
373
  // src/function/before.ts
381
374
  function before(n, func) {
382
- let count = 0;
375
+ let count2 = 0;
383
376
  let result;
384
377
  return (...args) => {
385
- if (count < n) {
386
- count += 1;
378
+ if (count2 < n) {
379
+ count2 += 1;
387
380
  result = func(...args);
388
381
  }
389
382
  return result;
@@ -641,8 +634,8 @@ function startCase(str) {
641
634
  return startCase2.trimEnd();
642
635
  }
643
636
 
644
- // src/string/stripSpecialChars.ts
645
- function stripSpecialChars(str) {
637
+ // src/string/stripSpecial.ts
638
+ function stripSpecial(str) {
646
639
  str = deburr(str);
647
640
  return str.replace(/[^\s\w]/gi, "");
648
641
  }
@@ -665,7 +658,7 @@ function unescape(str) {
665
658
  camelCase,
666
659
  capitalize,
667
660
  chunk,
668
- countBy,
661
+ count,
669
662
  debounce,
670
663
  deburr,
671
664
  difference,
@@ -675,7 +668,7 @@ function unescape(str) {
675
668
  dropWhile,
676
669
  escape,
677
670
  escapeRegExp,
678
- groupBy,
671
+ group,
679
672
  intersection,
680
673
  intersectionBy,
681
674
  intersectionWith,
@@ -692,9 +685,9 @@ function unescape(str) {
692
685
  sampleSize,
693
686
  shuffle,
694
687
  snakeCase,
695
- sortBy,
688
+ sort,
696
689
  startCase,
697
- stripSpecialChars,
690
+ stripSpecial,
698
691
  takeRightWhile,
699
692
  takeWhile,
700
693
  throttle,