moderndash 2.0.1 → 2.1.1

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 CHANGED
@@ -19,7 +19,7 @@
19
19
  <p></p>
20
20
 
21
21
  <div align=center class="center">
22
- <a href="https://bundlephobia.com/package/moderndash@0.11.1">
22
+ <a href="https://bundlephobia.com/package/moderndash@latest">
23
23
  <img alt="npm bundle size" src="https://img.shields.io/bundlephobia/minzip/moderndash@latest?color=Green">
24
24
  </a>
25
25
  <a href="https://www.npmjs.com/package/moderndash">
package/dist/index.cjs CHANGED
@@ -89,10 +89,8 @@ function chunk(array, chunkSize) {
89
89
  return [];
90
90
  }
91
91
  const chunkedArray = [];
92
- let i = 0;
93
- while (i < array.length) {
92
+ for (let i = 0; i < array.length; i += sizeInteger) {
94
93
  chunkedArray.push(array.slice(i, i + sizeInteger));
95
- i += sizeInteger;
96
94
  }
97
95
  return chunkedArray;
98
96
  }
@@ -101,65 +99,16 @@ function chunk(array, chunkSize) {
101
99
  function count(array, criteria) {
102
100
  const result = {};
103
101
  for (const value of array) {
104
- let key = criteria(value);
105
- if (typeof key === "boolean")
106
- key = key.toString();
107
- if (result[key] === void 0)
108
- result[key] = 1;
109
- else
110
- result[key] += 1;
102
+ const key = criteria(value);
103
+ result[key] = (result[key] ?? 0) + 1;
111
104
  }
112
105
  return result;
113
106
  }
114
107
 
115
- // src/validate/isPlainObject.ts
116
- function isPlainObject(value) {
117
- return value?.constructor === Object;
118
- }
119
-
120
- // src/validate/isEqual.ts
121
- function isEqual(a, b) {
122
- if (Object.is(a, b))
123
- return true;
124
- if (Array.isArray(a) && Array.isArray(b)) {
125
- return isSameArray(a, b);
126
- }
127
- if (a instanceof Date && b instanceof Date) {
128
- return a.getTime() === b.getTime();
129
- }
130
- if (a instanceof RegExp && b instanceof RegExp) {
131
- return a.toString() === b.toString();
132
- }
133
- if (isPlainObject(a) && isPlainObject(b)) {
134
- return isSameObject(a, b);
135
- }
136
- return false;
137
- }
138
- function isSameObject(a, b) {
139
- const keys1 = Object.keys(a);
140
- const keys2 = Object.keys(b);
141
- if (!isEqual(keys1, keys2))
142
- return false;
143
- for (const key of keys1) {
144
- if (!isEqual(a[key], b[key]))
145
- return false;
146
- }
147
- return true;
148
- }
149
- function isSameArray(a, b) {
150
- if (a.length !== b.length)
151
- return false;
152
- for (const [i, element] of a.entries()) {
153
- if (!isEqual(element, b[i]))
154
- return false;
155
- }
156
- return true;
157
- }
158
-
159
108
  // src/array/difference.ts
160
109
  function difference(arrayOrCompFn, ...arrays) {
161
110
  const withCompareFn = typeof arrayOrCompFn === "function";
162
- const compareFN = withCompareFn ? arrayOrCompFn : isEqual;
111
+ const compareFN = withCompareFn ? arrayOrCompFn : (a, b) => a === b;
163
112
  const [firstArray, ...restArrays] = withCompareFn ? arrays : [arrayOrCompFn, ...arrays];
164
113
  const difference2 = [];
165
114
  firstArray.forEach((element) => {
@@ -198,14 +147,37 @@ function group(array, criteria) {
198
147
  return result;
199
148
  }
200
149
 
150
+ // src/array/unique.ts
151
+ function unique(array, compareFn) {
152
+ if (!compareFn)
153
+ return [...new Set(array)];
154
+ const uniqueArray = [];
155
+ for (const value of array) {
156
+ let isUnique = true;
157
+ for (const uniqueValue of uniqueArray) {
158
+ if (compareFn(value, uniqueValue)) {
159
+ isUnique = false;
160
+ break;
161
+ }
162
+ }
163
+ if (isUnique)
164
+ uniqueArray.push(value);
165
+ }
166
+ return uniqueArray;
167
+ }
168
+
201
169
  // src/array/intersection.ts
202
170
  function intersection(arrayOrCompFn, ...arrays) {
203
171
  const withCompareFn = typeof arrayOrCompFn === "function";
204
- const compareFN = withCompareFn ? arrayOrCompFn : isEqual;
205
- const [firstArray, ...restArrays] = withCompareFn ? arrays : [arrayOrCompFn, ...arrays];
172
+ const firstArray = unique(withCompareFn ? arrays.shift() : arrayOrCompFn);
173
+ if (!withCompareFn) {
174
+ const restSets = arrays.map((array) => new Set(array));
175
+ return firstArray.filter((element) => restSets.every((set2) => set2.has(element)));
176
+ }
177
+ const compareFN = arrayOrCompFn;
206
178
  const intersection2 = [];
207
179
  firstArray.forEach((element) => {
208
- if (restArrays.every((array) => array.some((item) => compareFN(item, element)))) {
180
+ if (arrays.every((array) => array.some((item) => compareFN(item, element)))) {
209
181
  intersection2.push(element);
210
182
  }
211
183
  });
@@ -259,7 +231,7 @@ function sort(array, ...orders) {
259
231
  }
260
232
 
261
233
  // src/array/takeRightWhile.ts
262
- function takeRightWhile(predicate, array) {
234
+ function takeRightWhile(array, predicate) {
263
235
  const result = [];
264
236
  for (let i = array.length - 1; i >= 0; i--) {
265
237
  if (predicate(array[i])) {
@@ -284,13 +256,6 @@ function takeWhile(array, predicate) {
284
256
  return result;
285
257
  }
286
258
 
287
- // src/array/unique.ts
288
- function unique(array, compareFn = (a, b) => isEqual(a, b)) {
289
- return array.filter((value, index, self) => {
290
- return self.findIndex((otherValue) => compareFn(value, otherValue)) === index;
291
- });
292
- }
293
-
294
259
  // src/crypto/hash.ts
295
260
  async function hash(data, algorithm = "SHA-256") {
296
261
  const encoder = new TextEncoder();
@@ -345,6 +310,8 @@ function randomFloat(min, max) {
345
310
  // src/crypto/randomString.ts
346
311
  var DEFAULT_CHARSET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
347
312
  function randomString(length, charSet = DEFAULT_CHARSET) {
313
+ if (charSet.length <= 0)
314
+ return "";
348
315
  const randomValues = new Uint32Array(length);
349
316
  crypto.getRandomValues(randomValues);
350
317
  let result = "";
@@ -508,6 +475,11 @@ function round(number, precision = 2) {
508
475
  return Math.round((number + Number.EPSILON) * factor) / factor;
509
476
  }
510
477
 
478
+ // src/validate/isPlainObject.ts
479
+ function isPlainObject(value) {
480
+ return value?.constructor === Object;
481
+ }
482
+
511
483
  // src/object/merge.ts
512
484
  function merge(target, ...sources) {
513
485
  const targetCopy = { ...target };
@@ -714,7 +686,7 @@ function splitWords(str) {
714
686
 
715
687
  // src/string/deburr.ts
716
688
  function deburr(str) {
717
- return str.replace(/[^\u0000-\u007E]/g, (chr) => chr.normalize("NFD").replace(/[\u0300-\u036F]/g, ""));
689
+ return str.normalize("NFD").replace(/[\u0300-\u036F]/g, "");
718
690
  }
719
691
 
720
692
  // src/string/camelCase.ts
@@ -828,6 +800,47 @@ function isEmpty(value) {
828
800
  return false;
829
801
  }
830
802
 
803
+ // src/validate/isEqual.ts
804
+ function isEqual(a, b) {
805
+ if (Object.is(a, b))
806
+ return true;
807
+ if (typeof a !== typeof b)
808
+ return false;
809
+ if (Array.isArray(a) && Array.isArray(b)) {
810
+ return isSameArray(a, b);
811
+ }
812
+ if (a instanceof Date && b instanceof Date) {
813
+ return a.getTime() === b.getTime();
814
+ }
815
+ if (a instanceof RegExp && b instanceof RegExp) {
816
+ return a.toString() === b.toString();
817
+ }
818
+ if (isPlainObject(a) && isPlainObject(b)) {
819
+ return isSameObject(a, b);
820
+ }
821
+ return false;
822
+ }
823
+ function isSameObject(a, b) {
824
+ const keys1 = Object.keys(a);
825
+ const keys2 = Object.keys(b);
826
+ if (!isEqual(keys1, keys2))
827
+ return false;
828
+ for (const key of keys1) {
829
+ if (!isEqual(a[key], b[key]))
830
+ return false;
831
+ }
832
+ return true;
833
+ }
834
+ function isSameArray(a, b) {
835
+ if (a.length !== b.length)
836
+ return false;
837
+ for (const [i, element] of a.entries()) {
838
+ if (!isEqual(element, b[i]))
839
+ return false;
840
+ }
841
+ return true;
842
+ }
843
+
831
844
  // src/validate/isUrl.ts
832
845
  function isUrl(str) {
833
846
  try {