moderndash 0.0.21 → 0.1.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/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`.
550
+ * Omit specified keys from an object
557
551
  *
558
552
  * @example
559
- * isEmpty(null)
560
- * // => true
553
+ * const obj = {a: 1, b: 2, c: 3};
554
+ * omit(obj, ['a', 'b']);
555
+ * // => {c: 3}
561
556
  *
562
- * isEmpty({})
563
- * // => 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
564
560
  *
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
561
  */
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. `===`.
591
- *
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
- * @example
597
- * var object = { 'a': 1 };
598
- * var other = { 'a': 1 };
599
- *
600
- * isEqual(object, other);
601
- * // => true
602
- *
603
- * object === other;
604
- * // => false
605
- */
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,110 @@ 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 Lang
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
+ * @category Lang
794
+ * @param value1 - The value to compare.
795
+ * @param value2 - The other value to compare.
796
+ * @returns Returns `true` if the values are equivalent, else `false`.
797
+ * @example
798
+ * var object = { 'a': 1 };
799
+ * var other = { 'a': 1 };
800
+ *
801
+ * isEqual(object, other);
802
+ * // => true
803
+ *
804
+ * object === other;
805
+ * // => false
806
+ */
807
+ declare function isEqual(value1: unknown, value2: unknown): boolean;
808
+
809
+ /**
810
+ * This method is like `_.isEqual` except that it accepts `customizer` which
811
+ * is invoked to compare values. If `customizer` returns `undefined`, comparisons
812
+ * are handled by the method instead. The `customizer` is invoked with up to
813
+ * six arguments: (objValue, othValue [, index|key, object, other, stack]).
814
+ *
815
+ * @category Lang
816
+ * @example
817
+ * function isGreeting(value) {
818
+ * return /^h(?:i|ello)$/.test(value);
819
+ * }
820
+ *
821
+ * function customizer(objValue, othValue) {
822
+ * if (isGreeting(objValue) && isGreeting(othValue)) {
823
+ * return true;
824
+ * }
825
+ * }
826
+ *
827
+ * var array = ['hello', 'goodbye'];
828
+ * var other = ['hi', 'goodbye'];
829
+ *
830
+ * isEqualWith(array, other, customizer);
831
+ * // => true
832
+ * @param a - The value to compare.
833
+ * @param b - The other value to compare.
834
+ * @param customizer - The function to customize comparisons.
835
+ * @returns Returns `true` if the values are equivalent, else `false`.
836
+ */
837
+ declare function isEqualWith<T>(a: T, b: T, customizer: (value: T) => unknown): boolean;
838
+
839
+ declare function isPlainObject(value: unknown): value is object;
840
+
841
+ /**
842
+ * Checks if given string is a valid URL
843
+ *
844
+ * @example
845
+ * isUrl('https://google.com')
846
+ * // => true
847
+ * isUrl('google.com')
848
+ * // => false
849
+ * @param str - The string to check.
850
+ * @returns Returns `true` if given string is a valid URL, else `false`.
851
+ */
852
+ declare function isUrl(str: string): boolean;
814
853
 
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 };
854
+ 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, isEqualWith, 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,7 +102,7 @@ function getIterateFunction(iteratee) {
102
102
  }
103
103
  }
104
104
 
105
- // src/lang/isEqualWith.ts
105
+ // src/validate/isEqualWith.ts
106
106
  function isEqualWith(a, b, customizer) {
107
107
  return isEqual(customizer(a), customizer(b));
108
108
  }
@@ -440,37 +440,27 @@ function times(n, func) {
440
440
  return result;
441
441
  }
442
442
 
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
443
  // src/object/pick.ts
466
- function pick(object, keys) {
444
+ function pick(object, keysToPick) {
467
445
  const result = {};
468
- for (const key of keys) {
446
+ for (const key of keysToPick) {
469
447
  result[key] = object[key];
470
448
  }
471
449
  return result;
472
450
  }
473
451
 
452
+ // src/object/omit.ts
453
+ function omit(object, keysToOmit) {
454
+ const keys = Object.keys(object);
455
+ const filteredKeys = keys.filter((key) => !keysToOmit.includes(key));
456
+ return pick(object, filteredKeys);
457
+ }
458
+
459
+ // src/promise/sleep.ts
460
+ function sleep(ms) {
461
+ return new Promise((resolve) => setTimeout(resolve, ms));
462
+ }
463
+
474
464
  // src/string/deburr.ts
475
465
  function deburr(str) {
476
466
  return str.replace(/[^\u0000-\u007E]/g, (chr) => chr.normalize("NFD").replace(/[\u0300-\u036F]/g, ""));
@@ -502,8 +492,8 @@ function capitalize(str) {
502
492
  return str.charAt(0).toUpperCase() + str.slice(1);
503
493
  }
504
494
 
505
- // src/string/escape.ts
506
- function escape(str) {
495
+ // src/string/escapeHtml.ts
496
+ function escapeHtml(str) {
507
497
  const escapeChars = {
508
498
  "&": "&amp;",
509
499
  "<": "&lt;",
@@ -568,8 +558,8 @@ function stripSpecial(str) {
568
558
  return str.replace(/[^\s\w]/gi, "");
569
559
  }
570
560
 
571
- // src/string/unescape.ts
572
- function unescape(str) {
561
+ // src/string/unescapeHtml.ts
562
+ function unescapeHtml(str) {
573
563
  const entityMap = {
574
564
  "&amp;": "&",
575
565
  "&lt;": "<",
@@ -579,6 +569,38 @@ function unescape(str) {
579
569
  };
580
570
  return str.replace(/&(?:amp|lt|gt|quot|#(0+)?39);/g, (entity) => entityMap[entity] || entity);
581
571
  }
572
+
573
+ // src/validate/isEmpty.ts
574
+ function isEmpty(value) {
575
+ if (value === null || value === void 0) {
576
+ return true;
577
+ }
578
+ if (typeof value === "string" || Array.isArray(value)) {
579
+ return value.length === 0;
580
+ }
581
+ if (value instanceof Map || value instanceof Set) {
582
+ return value.size === 0;
583
+ }
584
+ if (typeof value === "object") {
585
+ return Object.keys(value).length === 0;
586
+ }
587
+ return false;
588
+ }
589
+
590
+ // src/validate/isPlainObject.ts
591
+ function isPlainObject(value) {
592
+ return value !== null && typeof value === "object" && value.constructor === Object;
593
+ }
594
+
595
+ // src/validate/isUrl.ts
596
+ function isUrl(str) {
597
+ try {
598
+ new URL(str);
599
+ return true;
600
+ } catch {
601
+ return false;
602
+ }
603
+ }
582
604
  export {
583
605
  after,
584
606
  before,
@@ -593,7 +615,7 @@ export {
593
615
  differenceWith,
594
616
  dropRightWhile,
595
617
  dropWhile,
596
- escape,
618
+ escapeHtml,
597
619
  escapeRegExp,
598
620
  group,
599
621
  intersection,
@@ -603,14 +625,17 @@ export {
603
625
  isEqual,
604
626
  isEqualWith,
605
627
  isPlainObject,
628
+ isUrl,
606
629
  kebabCase,
607
630
  memoize,
631
+ omit,
608
632
  once,
609
633
  pascalCase,
610
634
  pick,
611
635
  sample,
612
636
  sampleSize,
613
637
  shuffle,
638
+ sleep,
614
639
  snakeCase,
615
640
  sort,
616
641
  startCase,
@@ -619,7 +644,7 @@ export {
619
644
  takeWhile,
620
645
  throttle,
621
646
  times,
622
- unescape,
647
+ unescapeHtml,
623
648
  uniq,
624
649
  uniqBy,
625
650
  uniqWith,