moderndash 0.0.21 → 0.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/dist/index.d.ts CHANGED
@@ -102,11 +102,6 @@ declare function differenceWith<T>(comparator: (a: T, b: T) => boolean, ...array
102
102
  * Elements are dropped until `predicate` returns falsey. The predicate is
103
103
  * invoked with three arguments: (value, index, array).
104
104
  *
105
- * @category Array
106
- * @param predicate - The function invoked per iteration.
107
- * @param array - The array to query.
108
- * @returns Returns the slice of `array`.
109
- * @example
110
105
  * const users = [
111
106
  * { 'user': 'barney', 'active': false },
112
107
  * { 'user': 'fred', 'active': true },
@@ -115,6 +110,11 @@ declare function differenceWith<T>(comparator: (a: T, b: T) => boolean, ...array
115
110
  *
116
111
  * dropRightWhile(users, { active }) => active)
117
112
  * // => objects for ['barney']
113
+ * @category Array
114
+ * @param predicate - The function invoked per iteration.
115
+ * @param array - The array to query.
116
+ * @returns Returns the slice of `array`.
117
+ * @example
118
118
  */
119
119
  declare function dropRightWhile<T>(array: T[], predicate: (value: T) => boolean): T[];
120
120
 
@@ -123,10 +123,6 @@ declare function dropRightWhile<T>(array: T[], predicate: (value: T) => boolean)
123
123
  * Elements are dropped until `predicate` returns falsey. The predicate is
124
124
  * invoked with three arguments: (value, index, array).
125
125
  *
126
- * @category Array
127
- * @param predicate - The function invoked per iteration.
128
- * @param array - The array to query.
129
- * @returns Returns the slice of `array`.
130
126
  * @example
131
127
  * const users = [
132
128
  * { 'user': 'barney', 'active': true },
@@ -134,8 +130,12 @@ declare function dropRightWhile<T>(array: T[], predicate: (value: T) => boolean)
134
130
  * { 'user': 'pebbles', 'active': false }
135
131
  * ]
136
132
  *
137
- * dropWhile(({ active }) => active, users)
133
+ * dropWhile(users, ({ active }) => active)
138
134
  * // => objects for ['pebbles']
135
+ * @category Array
136
+ * @param predicate - The function invoked per iteration.
137
+ * @param array - The array to query.
138
+ * @returns Returns the slice of `array`.
139
139
  */
140
140
  declare function dropWhile<T>(array: T[], predicate: (value: T) => boolean): T[];
141
141
 
@@ -547,95 +547,19 @@ declare function throttle<TFunc extends GenericFunction<TFunc>>(func: TFunc, wai
547
547
  declare function times<TInput>(n: number, func: (index: number) => TInput): TInput[];
548
548
 
549
549
  /**
550
- * Checks if `value` is an empty object, collection, map, or set.
551
- *
552
- * Objects are considered empty if they have no own enumerable string keyed
553
- * properties.
554
- *
555
- * Array-like values such as `arguments` objects, arrays, buffers, strings, or
556
- * Similarly, maps and sets are considered empty if they have a `size` of `0`.
557
- *
558
- * @example
559
- * isEmpty(null)
560
- * // => true
561
- *
562
- * isEmpty({})
563
- * // => true
564
- *
565
- * isEmpty("")
566
- * // => true
567
- *
568
- * isEmpty([1, 2, 3])
569
- * // => false
570
- *
571
- * isEmpty('abc')
572
- * // => false
573
- *
574
- * isEmpty({ 'a': 1 })
575
- * // => false
576
- * @category Lang
577
- * @param value - The value to check.
578
- * @returns Returns `true` if given vlaue is empty, else `false`.
579
- */
580
- declare function isEmpty(value: string | object | null | undefined): boolean;
581
-
582
- /**
583
- * Performs a deep comparison between two values to determine if they are
584
- * equivalent.
585
- *
586
- * **Note:** This method supports comparing arrays, array buffers, booleans,
587
- * date objects, error objects, maps, numbers, `Object` objects, regexes,
588
- * sets, strings, symbols, and typed arrays. `Object` objects are compared
589
- * by their own, not inherited, enumerable properties. Functions and DOM
590
- * nodes are compared by strict equality, i.e. `===`.
550
+ * Omit specified keys from an object
591
551
  *
592
- * @category Lang
593
- * @param value1 - The value to compare.
594
- * @param value2 - The other value to compare.
595
- * @returns Returns `true` if the values are equivalent, else `false`.
596
552
  * @example
597
- * var object = { 'a': 1 };
598
- * var other = { 'a': 1 };
553
+ * const obj = {a: 1, b: 2, c: 3};
554
+ * omit(obj, ['a', 'b']);
555
+ * // => {c: 3}
599
556
  *
600
- * isEqual(object, other);
601
- * // => true
557
+ * @param object - The object to filter
558
+ * @param keysToOmit - The keys to exclude from the returned object
559
+ * @returns - An object without the specified keys
602
560
  *
603
- * object === other;
604
- * // => false
605
561
  */
606
- declare function isEqual(value1: unknown, value2: unknown): boolean;
607
-
608
- /**
609
- * This method is like `_.isEqual` except that it accepts `customizer` which
610
- * is invoked to compare values. If `customizer` returns `undefined`, comparisons
611
- * are handled by the method instead. The `customizer` is invoked with up to
612
- * six arguments: (objValue, othValue [, index|key, object, other, stack]).
613
- *
614
- * @category Lang
615
- * @example
616
- * function isGreeting(value) {
617
- * return /^h(?:i|ello)$/.test(value);
618
- * }
619
- *
620
- * function customizer(objValue, othValue) {
621
- * if (isGreeting(objValue) && isGreeting(othValue)) {
622
- * return true;
623
- * }
624
- * }
625
- *
626
- * var array = ['hello', 'goodbye'];
627
- * var other = ['hi', 'goodbye'];
628
- *
629
- * isEqualWith(array, other, customizer);
630
- * // => true
631
- * @param a - The value to compare.
632
- * @param b - The other value to compare.
633
- * @param customizer - The function to customize comparisons.
634
- * @returns Returns `true` if the values are equivalent, else `false`.
635
- */
636
- declare function isEqualWith<T>(a: T, b: T, customizer: (value: T) => unknown): boolean;
637
-
638
- declare function isPlainObject(value: unknown): value is object;
562
+ declare function omit<TObj extends object, Key extends keyof TObj>(object: TObj, keysToOmit: Key[]): Omit<TObj, Key>;
639
563
 
640
564
  /**
641
565
  * Creates an object composed of the picked `object` properties.
@@ -647,10 +571,21 @@ declare function isPlainObject(value: unknown): value is object;
647
571
  * // => { 'a': 1, 'c': 3 }
648
572
  * @category Object
649
573
  * @param object - The source object.
650
- * @param keys - The property paths to pick.
574
+ * @param keysToPick - The property paths to pick.
651
575
  * @returns Returns the new object.
652
576
  */
653
- declare function pick<TInput, Key extends keyof TInput>(object: TInput, keys: Key[]): Pick<TInput, Key>;
577
+ declare function pick<TInput, Key extends keyof TInput>(object: TInput, keysToPick: Key[]): Pick<TInput, Key>;
578
+
579
+ /**
580
+ * Sleeps for the given amount of time.
581
+ *
582
+ * @example
583
+ * await sleep(1000);
584
+ * // => Waits for 1 second.
585
+ * @param ms - Amount of time to sleep in milliseconds.
586
+ * @returns A promise that resolves after the given amount of time.
587
+ */
588
+ declare function sleep(ms: number): Promise<unknown>;
654
589
 
655
590
  /**
656
591
  * Converts `string` to camelCase.
@@ -706,7 +641,7 @@ declare function deburr(str: string): string;
706
641
  * @param str - The string to escape.
707
642
  * @returns Returns the escaped string.
708
643
  */
709
- declare function escape(str: string): string;
644
+ declare function escapeHtml(str: string): string;
710
645
 
711
646
  /**
712
647
  * Escapes the `RegExp` special characters `^`, `$`, `\`, `.`, `*`, `+`,
@@ -810,6 +745,80 @@ declare function stripSpecial(str: string): string;
810
745
  * @param str - The string to unescape.
811
746
  * @returns Returns the unescaped string.
812
747
  */
813
- declare function unescape(str: string): string;
748
+ declare function unescapeHtml(str: string): string;
749
+
750
+ /**
751
+ * Checks if `value` is an empty object, collection, map, or set.
752
+ *
753
+ * Objects are considered empty if they have no own enumerable string keyed
754
+ * properties.
755
+ *
756
+ * Array-like values such as `arguments` objects, arrays, buffers, strings, or
757
+ * Similarly, maps and sets are considered empty if they have a `size` of `0`.
758
+ *
759
+ * @example
760
+ * isEmpty(null)
761
+ * // => true
762
+ *
763
+ * isEmpty({})
764
+ * // => true
765
+ *
766
+ * isEmpty("")
767
+ * // => true
768
+ *
769
+ * isEmpty([1, 2, 3])
770
+ * // => false
771
+ *
772
+ * isEmpty('abc')
773
+ * // => false
774
+ *
775
+ * isEmpty({ 'a': 1 })
776
+ * // => false
777
+ * @category Validate
778
+ * @param value - The value to check.
779
+ * @returns Returns `true` if given vlaue is empty, else `false`.
780
+ */
781
+ declare function isEmpty(value: string | object | null | undefined): boolean;
782
+
783
+ /**
784
+ * Performs a deep comparison between two values to determine if they are
785
+ * equivalent.
786
+ *
787
+ * **Note:** This method supports comparing arrays, array buffers, booleans,
788
+ * date objects, error objects, maps, numbers, `Object` objects, regexes,
789
+ * sets, strings, symbols, and typed arrays. `Object` objects are compared
790
+ * by their own, not inherited, enumerable properties. Functions and DOM
791
+ * nodes are compared by strict equality, i.e. `===`.
792
+ *
793
+ * @example
794
+ * var object = { 'a': 1 };
795
+ * var other = { 'a': 1 };
796
+ *
797
+ * isEqual(object, other);
798
+ * // => true
799
+ *
800
+ * object === other;
801
+ * // => false
802
+ * @category Validate
803
+ * @param value1 - The value to compare.
804
+ * @param value2 - The other value to compare.
805
+ * @returns Returns `true` if the values are equivalent, else `false`.
806
+ */
807
+ declare function isEqual(value1: unknown, value2: unknown): boolean;
808
+
809
+ declare function isPlainObject(value: unknown): value is object;
810
+
811
+ /**
812
+ * Checks if given string is a valid URL
813
+ *
814
+ * @example
815
+ * isUrl('https://google.com')
816
+ * // => true
817
+ * isUrl('google.com')
818
+ * // => false
819
+ * @param str - The string to check.
820
+ * @returns Returns `true` if given string is a valid URL, else `false`.
821
+ */
822
+ declare function isUrl(str: string): boolean;
814
823
 
815
- export { GenericFunction, IterateeFunction, MinimumTwoArrays, NoUnion, PropertyShorthand, RecordKey, after, before, camelCase, capitalize, chunk, count, debounce, deburr, difference, differenceBy, differenceWith, dropRightWhile, dropWhile, escape, escapeRegExp, group, intersection, intersectionBy, intersectionWith, isEmpty, isEqual, isEqualWith, isPlainObject, kebabCase, memoize, once, pascalCase, pick, sample, sampleSize, shuffle, snakeCase, sort, startCase, stripSpecial, takeRightWhile, takeWhile, throttle, times, unescape, uniq, uniqBy, uniqWith, unzip, unzipWith, zip, zipWith };
824
+ export { GenericFunction, IterateeFunction, MinimumTwoArrays, NoUnion, PropertyShorthand, RecordKey, after, before, camelCase, capitalize, chunk, count, debounce, deburr, difference, differenceBy, differenceWith, dropRightWhile, dropWhile, escapeHtml, escapeRegExp, group, intersection, intersectionBy, intersectionWith, isEmpty, isEqual, isPlainObject, isUrl, kebabCase, memoize, omit, once, pascalCase, pick, sample, sampleSize, shuffle, sleep, snakeCase, sort, startCase, stripSpecial, takeRightWhile, takeWhile, throttle, times, unescapeHtml, uniq, uniqBy, uniqWith, unzip, unzipWith, zip, zipWith };
package/dist/index.js CHANGED
@@ -39,7 +39,7 @@ function differenceWith(comparator, ...arrays) {
39
39
  return difference2;
40
40
  }
41
41
 
42
- // src/lang/isEqual.ts
42
+ // src/validate/isEqual.ts
43
43
  function isEqual(value1, value2) {
44
44
  if (value1 === value2)
45
45
  return true;
@@ -102,15 +102,10 @@ function getIterateFunction(iteratee) {
102
102
  }
103
103
  }
104
104
 
105
- // src/lang/isEqualWith.ts
106
- function isEqualWith(a, b, customizer) {
107
- return isEqual(customizer(a), customizer(b));
108
- }
109
-
110
105
  // src/array/differenceBy.ts
111
106
  function differenceBy(iteratee, ...arrays) {
112
- const iterateeFunction = getIterateFunction(iteratee);
113
- return differenceWith((a, b) => isEqualWith(a, b, iterateeFunction), ...arrays);
107
+ const iterateeFn = getIterateFunction(iteratee);
108
+ return differenceWith((a, b) => isEqual(iterateeFn(a), iterateeFn(b)), ...arrays);
114
109
  }
115
110
 
116
111
  // src/array/dropRightWhile.ts
@@ -158,8 +153,8 @@ function intersection(...arrays) {
158
153
 
159
154
  // src/array/intersectionBy.ts
160
155
  function intersectionBy(iteratee, ...arrays) {
161
- const iterateeFunction = getIterateFunction(iteratee);
162
- return intersectionWith((a, b) => isEqualWith(a, b, iterateeFunction), ...arrays);
156
+ const iterateeFn = getIterateFunction(iteratee);
157
+ return intersectionWith((a, b) => isEqual(iterateeFn(a), iterateeFn(b)), ...arrays);
163
158
  }
164
159
 
165
160
  // src/array/sample.ts
@@ -440,37 +435,27 @@ function times(n, func) {
440
435
  return result;
441
436
  }
442
437
 
443
- // src/lang/isEmpty.ts
444
- function isEmpty(value) {
445
- if (value === null || value === void 0) {
446
- return true;
447
- }
448
- if (typeof value === "string" || Array.isArray(value)) {
449
- return value.length === 0;
450
- }
451
- if (value instanceof Map || value instanceof Set) {
452
- return value.size === 0;
453
- }
454
- if (typeof value === "object") {
455
- return Object.keys(value).length === 0;
456
- }
457
- return false;
458
- }
459
-
460
- // src/lang/isPlainObject.ts
461
- function isPlainObject(value) {
462
- return value !== null && typeof value === "object" && value.constructor === Object;
463
- }
464
-
465
438
  // src/object/pick.ts
466
- function pick(object, keys) {
439
+ function pick(object, keysToPick) {
467
440
  const result = {};
468
- for (const key of keys) {
441
+ for (const key of keysToPick) {
469
442
  result[key] = object[key];
470
443
  }
471
444
  return result;
472
445
  }
473
446
 
447
+ // src/object/omit.ts
448
+ function omit(object, keysToOmit) {
449
+ const keys = Object.keys(object);
450
+ const filteredKeys = keys.filter((key) => !keysToOmit.includes(key));
451
+ return pick(object, filteredKeys);
452
+ }
453
+
454
+ // src/promise/sleep.ts
455
+ function sleep(ms) {
456
+ return new Promise((resolve) => setTimeout(resolve, ms));
457
+ }
458
+
474
459
  // src/string/deburr.ts
475
460
  function deburr(str) {
476
461
  return str.replace(/[^\u0000-\u007E]/g, (chr) => chr.normalize("NFD").replace(/[\u0300-\u036F]/g, ""));
@@ -502,8 +487,8 @@ function capitalize(str) {
502
487
  return str.charAt(0).toUpperCase() + str.slice(1);
503
488
  }
504
489
 
505
- // src/string/escape.ts
506
- function escape(str) {
490
+ // src/string/escapeHtml.ts
491
+ function escapeHtml(str) {
507
492
  const escapeChars = {
508
493
  "&": "&amp;",
509
494
  "<": "&lt;",
@@ -568,8 +553,8 @@ function stripSpecial(str) {
568
553
  return str.replace(/[^\s\w]/gi, "");
569
554
  }
570
555
 
571
- // src/string/unescape.ts
572
- function unescape(str) {
556
+ // src/string/unescapeHtml.ts
557
+ function unescapeHtml(str) {
573
558
  const entityMap = {
574
559
  "&amp;": "&",
575
560
  "&lt;": "<",
@@ -579,6 +564,38 @@ function unescape(str) {
579
564
  };
580
565
  return str.replace(/&(?:amp|lt|gt|quot|#(0+)?39);/g, (entity) => entityMap[entity] || entity);
581
566
  }
567
+
568
+ // src/validate/isEmpty.ts
569
+ function isEmpty(value) {
570
+ if (value === null || value === void 0) {
571
+ return true;
572
+ }
573
+ if (typeof value === "string" || Array.isArray(value)) {
574
+ return value.length === 0;
575
+ }
576
+ if (value instanceof Map || value instanceof Set) {
577
+ return value.size === 0;
578
+ }
579
+ if (typeof value === "object") {
580
+ return Object.keys(value).length === 0;
581
+ }
582
+ return false;
583
+ }
584
+
585
+ // src/validate/isPlainObject.ts
586
+ function isPlainObject(value) {
587
+ return value !== null && typeof value === "object" && value.constructor === Object;
588
+ }
589
+
590
+ // src/validate/isUrl.ts
591
+ function isUrl(str) {
592
+ try {
593
+ new URL(str);
594
+ return true;
595
+ } catch {
596
+ return false;
597
+ }
598
+ }
582
599
  export {
583
600
  after,
584
601
  before,
@@ -593,7 +610,7 @@ export {
593
610
  differenceWith,
594
611
  dropRightWhile,
595
612
  dropWhile,
596
- escape,
613
+ escapeHtml,
597
614
  escapeRegExp,
598
615
  group,
599
616
  intersection,
@@ -601,16 +618,18 @@ export {
601
618
  intersectionWith,
602
619
  isEmpty,
603
620
  isEqual,
604
- isEqualWith,
605
621
  isPlainObject,
622
+ isUrl,
606
623
  kebabCase,
607
624
  memoize,
625
+ omit,
608
626
  once,
609
627
  pascalCase,
610
628
  pick,
611
629
  sample,
612
630
  sampleSize,
613
631
  shuffle,
632
+ sleep,
614
633
  snakeCase,
615
634
  sort,
616
635
  startCase,
@@ -619,7 +638,7 @@ export {
619
638
  takeWhile,
620
639
  throttle,
621
640
  times,
622
- unescape,
641
+ unescapeHtml,
623
642
  uniq,
624
643
  uniqBy,
625
644
  uniqWith,