radashi 12.2.0-beta.437b4fe → 12.2.0-beta.649f0d1

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.
@@ -17,9 +17,9 @@ var __copyProps = (to, from, except, desc) => {
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
- // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
20
+ // src/mod.ts
21
+ var mod_exports = {};
22
+ __export(mod_exports, {
23
23
  AggregateError: () => AggregateError,
24
24
  all: () => all,
25
25
  alphabetical: () => alphabetical,
@@ -40,6 +40,7 @@ __export(src_exports, {
40
40
  defer: () => defer,
41
41
  diff: () => diff,
42
42
  draw: () => draw,
43
+ filterKey: () => filterKey,
43
44
  first: () => first,
44
45
  flat: () => flat,
45
46
  fork: () => fork,
@@ -118,7 +119,7 @@ __export(src_exports, {
118
119
  zip: () => zip,
119
120
  zipToObject: () => zipToObject
120
121
  });
121
- module.exports = __toCommonJS(src_exports);
122
+ module.exports = __toCommonJS(mod_exports);
122
123
 
123
124
  // src/array/alphabetical.ts
124
125
  var alphabetical = (array, getter, dir = "asc") => {
@@ -687,23 +688,23 @@ function inRange(number, start, end) {
687
688
  return number >= Math.min(start, end) && number < Math.max(start, end);
688
689
  }
689
690
 
690
- // src/number/toInt.ts
691
- var toInt = (value, defaultValue) => {
691
+ // src/number/toFloat.ts
692
+ var toFloat = (value, defaultValue) => {
692
693
  const def = defaultValue === void 0 ? 0 : defaultValue;
693
694
  if (value === null || value === void 0) {
694
695
  return def;
695
696
  }
696
- const result = parseInt(value);
697
+ const result = parseFloat(value);
697
698
  return isNaN(result) ? def : result;
698
699
  };
699
700
 
700
- // src/number/toFloat.ts
701
- var toFloat = (value, defaultValue) => {
701
+ // src/number/toInt.ts
702
+ var toInt = (value, defaultValue) => {
702
703
  const def = defaultValue === void 0 ? 0 : defaultValue;
703
704
  if (value === null || value === void 0) {
704
705
  return def;
705
706
  }
706
- const result = parseFloat(value);
707
+ const result = parseInt(value);
707
708
  return isNaN(result) ? def : result;
708
709
  };
709
710
 
@@ -754,6 +755,11 @@ var crush = (value) => {
754
755
  );
755
756
  };
756
757
 
758
+ // src/object/filterKey.ts
759
+ var filterKey = (obj, key, filter) => {
760
+ return Object.hasOwnProperty.call(obj, key) && (filter == null || (isArray(filter) ? filter.includes(key) : filter(obj[key], key, obj)));
761
+ };
762
+
757
763
  // src/object/get.ts
758
764
  var get = (value, path, defaultValue) => {
759
765
  const segments = path.split(/[\.\[\]]/g);
@@ -782,18 +788,27 @@ var invert = (obj) => {
782
788
  // src/object/keys.ts
783
789
  var keys = (value) => {
784
790
  if (!value) return [];
785
- const getKeys = (nested, paths) => {
786
- if (isPlainObject(nested)) {
787
- return Object.entries(nested).flatMap(
788
- ([k, v]) => getKeys(v, [...paths, k])
789
- );
790
- }
791
- if (isArray(nested)) {
792
- return nested.flatMap((item, i) => getKeys(item, [...paths, `${i}`]));
791
+ const keys2 = [];
792
+ const keyPath = [];
793
+ const recurse = (value2) => {
794
+ if (isPlainObject(value2)) {
795
+ for (const [prop, propValue] of Object.entries(value2)) {
796
+ keyPath.push(prop);
797
+ recurse(propValue);
798
+ keyPath.pop();
799
+ }
800
+ } else if (isArray(value2)) {
801
+ value2.forEach((item, index) => {
802
+ keyPath.push(index);
803
+ recurse(item);
804
+ keyPath.pop();
805
+ });
806
+ } else {
807
+ keys2.push(keyPath.join("."));
793
808
  }
794
- return [paths.join(".")];
795
809
  };
796
- return getKeys(value, []);
810
+ recurse(value);
811
+ return keys2;
797
812
  };
798
813
 
799
814
  // src/object/listify.ts
@@ -830,13 +845,13 @@ var mapKeys = (obj, mapFunc) => {
830
845
  };
831
846
 
832
847
  // src/object/mapValues.ts
833
- var mapValues = (obj, mapFunc) => {
848
+ function mapValues(obj, mapFunc) {
834
849
  const keys2 = Object.keys(obj);
835
850
  return keys2.reduce((acc, key) => {
836
851
  acc[key] = mapFunc(obj[key], key);
837
852
  return acc;
838
853
  }, {});
839
- };
854
+ }
840
855
 
841
856
  // src/object/omit.ts
842
857
  var omit = (obj, keys2) => {
@@ -1180,6 +1195,7 @@ var isSymbol = (value) => {
1180
1195
  defer,
1181
1196
  diff,
1182
1197
  draw,
1198
+ filterKey,
1183
1199
  first,
1184
1200
  flat,
1185
1201
  fork,
@@ -50,7 +50,7 @@ declare const fork: <T>(list: readonly T[], condition: (item: T) => boolean) =>
50
50
  * where the keys are the group ids the given getGroupId function
51
51
  * produced and the value is an array of each item in that group.
52
52
  */
53
- declare const group: <T, Key extends string | number | symbol>(array: readonly T[], getGroupId: (item: T) => Key) => Partial<Record<Key, T[]>>;
53
+ declare const group: <T, Key extends string | number | symbol>(array: readonly T[], getGroupId: (item: T) => Key) => { [K in Key]?: T[] | undefined; };
54
54
 
55
55
  /**
56
56
  * Given two arrays, returns true if any elements intersect
@@ -473,10 +473,10 @@ declare function inRange(number: number, end: number): boolean;
473
473
  */
474
474
  declare function inRange(number: number, start: number, end: number): boolean;
475
475
 
476
- declare const toInt: <T extends number | null = number>(value: any, defaultValue?: T | undefined) => number | T;
477
-
478
476
  declare const toFloat: <T extends number | null = number>(value: any, defaultValue?: T | undefined) => number | T;
479
477
 
478
+ declare const toInt: <T extends number | null = number>(value: any, defaultValue?: T | undefined) => number | T;
479
+
480
480
  /**
481
481
  * Merges two objects together recursivly into a new object applying
482
482
  * values from right to left. Recursion only applies to child object
@@ -511,6 +511,20 @@ declare const construct: <TObject extends object>(obj: TObject) => object;
511
511
  */
512
512
  declare const crush: <TValue extends object>(value: TValue) => object;
513
513
 
514
+ type KeyOf<T extends object> = object extends T ? keyof any : keyof T;
515
+ type ValueOf<T extends object> = object extends T ? unknown : T[keyof T];
516
+ type KeyFilterFunction<T extends object = object> = (value: ValueOf<T>, key: KeyOf<T>, obj: T) => boolean;
517
+ /**
518
+ * Functions can use this type to accept either an array of keys or a
519
+ * filter function.
520
+ */
521
+ type KeyFilter<T extends object = object, Key extends keyof any = keyof any> = KeyFilterFunction<T> | readonly Key[];
522
+ /**
523
+ * Returns true if the key is in the “keys array” or if the “filter
524
+ * function” returns true.
525
+ */
526
+ declare const filterKey: (obj: object, key: keyof any, filter: KeyFilter | null | undefined) => boolean;
527
+
514
528
  /**
515
529
  * Dynamically get a nested value from an array or object with a
516
530
  * string.
@@ -532,7 +546,7 @@ declare const invert: <TKey extends string | number | symbol, TValue extends str
532
546
  * keys({ name: 'ra' }) // ['name']
533
547
  * keys({ name: 'ra', children: [{ name: 'hathor' }] }) // ['name', 'children.0.name']
534
548
  */
535
- declare const keys: <TValue extends object>(value: TValue) => string[];
549
+ declare const keys: (value: object) => string[];
536
550
 
537
551
  /**
538
552
  * Convert an object to a list, mapping each entry into a list item
@@ -560,7 +574,16 @@ declare const mapKeys: <TValue, TKey extends string | number | symbol, TNewKey e
560
574
  /**
561
575
  * Map over all the keys to create a new object
562
576
  */
563
- declare const mapValues: <TValue, TKey extends string | number | symbol, TNewValue>(obj: Record<TKey, TValue>, mapFunc: (value: TValue, key: TKey) => TNewValue) => Record<TKey, TNewValue>;
577
+ declare function mapValues<TValue, TKey extends string | number | symbol, TNewValue>(obj: {
578
+ [K in TKey]: TValue;
579
+ }, mapFunc: (value: TValue, key: TKey) => TNewValue): {
580
+ [K in TKey]: TNewValue;
581
+ };
582
+ declare function mapValues<TValue, TKey extends string | number | symbol, TNewValue>(obj: {
583
+ [K in TKey]?: TValue;
584
+ }, mapFunc: (value: TValue, key: TKey) => TNewValue): {
585
+ [K in TKey]?: TNewValue;
586
+ };
564
587
 
565
588
  /**
566
589
  * Omit a list of properties from an object returning a new object
@@ -743,4 +766,4 @@ declare const isString: (value: any) => value is string;
743
766
 
744
767
  declare const isSymbol: (value: any) => value is symbol;
745
768
 
746
- export { AggregateError, type DebounceFunction, type RetryOptions, type ThrottledFunction, all, alphabetical, assign, boil, callable, camel, capitalize, chain, clone, cluster, compose, construct, counting, crush, dash, debounce, defer, diff, draw, first, flat, fork, get, group, guard, inRange, intersects, invert, isArray, isDate, isEmpty, isEqual, isFloat, isFunction, isInt, isIntString, isNumber, isObject, isPlainObject, isPrimitive, isPromise, isString, isSymbol, iterate, keys, last, list, listify, lowerize, map, mapEntries, mapKeys, mapValues, max, memo, merge, min, objectify, omit, parallel, partial, partob, pascal, pick, proxied, random, range, reduce, replace, replaceOrAppend, retry, select, series, set, shake, shift, shuffle, sift, sleep, snake, sort, sum, template, throttle, title, toFloat, toInt, toggle, trim, tryit as try, tryit, uid, unique, upperize, zip, zipToObject };
769
+ export { AggregateError, type DebounceFunction, type KeyFilter, type KeyFilterFunction, type RetryOptions, type ThrottledFunction, all, alphabetical, assign, boil, callable, camel, capitalize, chain, clone, cluster, compose, construct, counting, crush, dash, debounce, defer, diff, draw, filterKey, first, flat, fork, get, group, guard, inRange, intersects, invert, isArray, isDate, isEmpty, isEqual, isFloat, isFunction, isInt, isIntString, isNumber, isObject, isPlainObject, isPrimitive, isPromise, isString, isSymbol, iterate, keys, last, list, listify, lowerize, map, mapEntries, mapKeys, mapValues, max, memo, merge, min, objectify, omit, parallel, partial, partob, pascal, pick, proxied, random, range, reduce, replace, replaceOrAppend, retry, select, series, set, shake, shift, shuffle, sift, sleep, snake, sort, sum, template, throttle, title, toFloat, toInt, toggle, trim, tryit as try, tryit, uid, unique, upperize, zip, zipToObject };
@@ -50,7 +50,7 @@ declare const fork: <T>(list: readonly T[], condition: (item: T) => boolean) =>
50
50
  * where the keys are the group ids the given getGroupId function
51
51
  * produced and the value is an array of each item in that group.
52
52
  */
53
- declare const group: <T, Key extends string | number | symbol>(array: readonly T[], getGroupId: (item: T) => Key) => Partial<Record<Key, T[]>>;
53
+ declare const group: <T, Key extends string | number | symbol>(array: readonly T[], getGroupId: (item: T) => Key) => { [K in Key]?: T[] | undefined; };
54
54
 
55
55
  /**
56
56
  * Given two arrays, returns true if any elements intersect
@@ -473,10 +473,10 @@ declare function inRange(number: number, end: number): boolean;
473
473
  */
474
474
  declare function inRange(number: number, start: number, end: number): boolean;
475
475
 
476
- declare const toInt: <T extends number | null = number>(value: any, defaultValue?: T | undefined) => number | T;
477
-
478
476
  declare const toFloat: <T extends number | null = number>(value: any, defaultValue?: T | undefined) => number | T;
479
477
 
478
+ declare const toInt: <T extends number | null = number>(value: any, defaultValue?: T | undefined) => number | T;
479
+
480
480
  /**
481
481
  * Merges two objects together recursivly into a new object applying
482
482
  * values from right to left. Recursion only applies to child object
@@ -511,6 +511,20 @@ declare const construct: <TObject extends object>(obj: TObject) => object;
511
511
  */
512
512
  declare const crush: <TValue extends object>(value: TValue) => object;
513
513
 
514
+ type KeyOf<T extends object> = object extends T ? keyof any : keyof T;
515
+ type ValueOf<T extends object> = object extends T ? unknown : T[keyof T];
516
+ type KeyFilterFunction<T extends object = object> = (value: ValueOf<T>, key: KeyOf<T>, obj: T) => boolean;
517
+ /**
518
+ * Functions can use this type to accept either an array of keys or a
519
+ * filter function.
520
+ */
521
+ type KeyFilter<T extends object = object, Key extends keyof any = keyof any> = KeyFilterFunction<T> | readonly Key[];
522
+ /**
523
+ * Returns true if the key is in the “keys array” or if the “filter
524
+ * function” returns true.
525
+ */
526
+ declare const filterKey: (obj: object, key: keyof any, filter: KeyFilter | null | undefined) => boolean;
527
+
514
528
  /**
515
529
  * Dynamically get a nested value from an array or object with a
516
530
  * string.
@@ -532,7 +546,7 @@ declare const invert: <TKey extends string | number | symbol, TValue extends str
532
546
  * keys({ name: 'ra' }) // ['name']
533
547
  * keys({ name: 'ra', children: [{ name: 'hathor' }] }) // ['name', 'children.0.name']
534
548
  */
535
- declare const keys: <TValue extends object>(value: TValue) => string[];
549
+ declare const keys: (value: object) => string[];
536
550
 
537
551
  /**
538
552
  * Convert an object to a list, mapping each entry into a list item
@@ -560,7 +574,16 @@ declare const mapKeys: <TValue, TKey extends string | number | symbol, TNewKey e
560
574
  /**
561
575
  * Map over all the keys to create a new object
562
576
  */
563
- declare const mapValues: <TValue, TKey extends string | number | symbol, TNewValue>(obj: Record<TKey, TValue>, mapFunc: (value: TValue, key: TKey) => TNewValue) => Record<TKey, TNewValue>;
577
+ declare function mapValues<TValue, TKey extends string | number | symbol, TNewValue>(obj: {
578
+ [K in TKey]: TValue;
579
+ }, mapFunc: (value: TValue, key: TKey) => TNewValue): {
580
+ [K in TKey]: TNewValue;
581
+ };
582
+ declare function mapValues<TValue, TKey extends string | number | symbol, TNewValue>(obj: {
583
+ [K in TKey]?: TValue;
584
+ }, mapFunc: (value: TValue, key: TKey) => TNewValue): {
585
+ [K in TKey]?: TNewValue;
586
+ };
564
587
 
565
588
  /**
566
589
  * Omit a list of properties from an object returning a new object
@@ -743,4 +766,4 @@ declare const isString: (value: any) => value is string;
743
766
 
744
767
  declare const isSymbol: (value: any) => value is symbol;
745
768
 
746
- export { AggregateError, type DebounceFunction, type RetryOptions, type ThrottledFunction, all, alphabetical, assign, boil, callable, camel, capitalize, chain, clone, cluster, compose, construct, counting, crush, dash, debounce, defer, diff, draw, first, flat, fork, get, group, guard, inRange, intersects, invert, isArray, isDate, isEmpty, isEqual, isFloat, isFunction, isInt, isIntString, isNumber, isObject, isPlainObject, isPrimitive, isPromise, isString, isSymbol, iterate, keys, last, list, listify, lowerize, map, mapEntries, mapKeys, mapValues, max, memo, merge, min, objectify, omit, parallel, partial, partob, pascal, pick, proxied, random, range, reduce, replace, replaceOrAppend, retry, select, series, set, shake, shift, shuffle, sift, sleep, snake, sort, sum, template, throttle, title, toFloat, toInt, toggle, trim, tryit as try, tryit, uid, unique, upperize, zip, zipToObject };
769
+ export { AggregateError, type DebounceFunction, type KeyFilter, type KeyFilterFunction, type RetryOptions, type ThrottledFunction, all, alphabetical, assign, boil, callable, camel, capitalize, chain, clone, cluster, compose, construct, counting, crush, dash, debounce, defer, diff, draw, filterKey, first, flat, fork, get, group, guard, inRange, intersects, invert, isArray, isDate, isEmpty, isEqual, isFloat, isFunction, isInt, isIntString, isNumber, isObject, isPlainObject, isPrimitive, isPromise, isString, isSymbol, iterate, keys, last, list, listify, lowerize, map, mapEntries, mapKeys, mapValues, max, memo, merge, min, objectify, omit, parallel, partial, partob, pascal, pick, proxied, random, range, reduce, replace, replaceOrAppend, retry, select, series, set, shake, shift, shuffle, sift, sleep, snake, sort, sum, template, throttle, title, toFloat, toInt, toggle, trim, tryit as try, tryit, uid, unique, upperize, zip, zipToObject };
@@ -565,23 +565,23 @@ function inRange(number, start, end) {
565
565
  return number >= Math.min(start, end) && number < Math.max(start, end);
566
566
  }
567
567
 
568
- // src/number/toInt.ts
569
- var toInt = (value, defaultValue) => {
568
+ // src/number/toFloat.ts
569
+ var toFloat = (value, defaultValue) => {
570
570
  const def = defaultValue === void 0 ? 0 : defaultValue;
571
571
  if (value === null || value === void 0) {
572
572
  return def;
573
573
  }
574
- const result = parseInt(value);
574
+ const result = parseFloat(value);
575
575
  return isNaN(result) ? def : result;
576
576
  };
577
577
 
578
- // src/number/toFloat.ts
579
- var toFloat = (value, defaultValue) => {
578
+ // src/number/toInt.ts
579
+ var toInt = (value, defaultValue) => {
580
580
  const def = defaultValue === void 0 ? 0 : defaultValue;
581
581
  if (value === null || value === void 0) {
582
582
  return def;
583
583
  }
584
- const result = parseFloat(value);
584
+ const result = parseInt(value);
585
585
  return isNaN(result) ? def : result;
586
586
  };
587
587
 
@@ -632,6 +632,11 @@ var crush = (value) => {
632
632
  );
633
633
  };
634
634
 
635
+ // src/object/filterKey.ts
636
+ var filterKey = (obj, key, filter) => {
637
+ return Object.hasOwnProperty.call(obj, key) && (filter == null || (isArray(filter) ? filter.includes(key) : filter(obj[key], key, obj)));
638
+ };
639
+
635
640
  // src/object/get.ts
636
641
  var get = (value, path, defaultValue) => {
637
642
  const segments = path.split(/[\.\[\]]/g);
@@ -660,18 +665,27 @@ var invert = (obj) => {
660
665
  // src/object/keys.ts
661
666
  var keys = (value) => {
662
667
  if (!value) return [];
663
- const getKeys = (nested, paths) => {
664
- if (isPlainObject(nested)) {
665
- return Object.entries(nested).flatMap(
666
- ([k, v]) => getKeys(v, [...paths, k])
667
- );
668
- }
669
- if (isArray(nested)) {
670
- return nested.flatMap((item, i) => getKeys(item, [...paths, `${i}`]));
668
+ const keys2 = [];
669
+ const keyPath = [];
670
+ const recurse = (value2) => {
671
+ if (isPlainObject(value2)) {
672
+ for (const [prop, propValue] of Object.entries(value2)) {
673
+ keyPath.push(prop);
674
+ recurse(propValue);
675
+ keyPath.pop();
676
+ }
677
+ } else if (isArray(value2)) {
678
+ value2.forEach((item, index) => {
679
+ keyPath.push(index);
680
+ recurse(item);
681
+ keyPath.pop();
682
+ });
683
+ } else {
684
+ keys2.push(keyPath.join("."));
671
685
  }
672
- return [paths.join(".")];
673
686
  };
674
- return getKeys(value, []);
687
+ recurse(value);
688
+ return keys2;
675
689
  };
676
690
 
677
691
  // src/object/listify.ts
@@ -708,13 +722,13 @@ var mapKeys = (obj, mapFunc) => {
708
722
  };
709
723
 
710
724
  // src/object/mapValues.ts
711
- var mapValues = (obj, mapFunc) => {
725
+ function mapValues(obj, mapFunc) {
712
726
  const keys2 = Object.keys(obj);
713
727
  return keys2.reduce((acc, key) => {
714
728
  acc[key] = mapFunc(obj[key], key);
715
729
  return acc;
716
730
  }, {});
717
- };
731
+ }
718
732
 
719
733
  // src/object/omit.ts
720
734
  var omit = (obj, keys2) => {
@@ -1057,6 +1071,7 @@ export {
1057
1071
  defer,
1058
1072
  diff,
1059
1073
  draw,
1074
+ filterKey,
1060
1075
  first,
1061
1076
  flat,
1062
1077
  fork,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "radashi",
3
- "version": "12.2.0-beta.437b4fe",
3
+ "version": "12.2.0-beta.649f0d1",
4
4
  "description": "Functional utility library - modern, simple, typed, powerful",
5
5
  "sideEffects": false,
6
6
  "author": "Alec Larson",
@@ -38,15 +38,15 @@
38
38
  "repository": {
39
39
  "url": "https://github.com/radashi-org/radashi"
40
40
  },
41
- "main": "dist/index.cjs",
42
- "module": "dist/index.js",
43
- "types": "dist/index.d.cts",
41
+ "main": "dist/radashi.cjs",
42
+ "module": "dist/radashi.js",
43
+ "types": "dist/radashi.d.cts",
44
44
  "exports": {
45
45
  "require": {
46
- "types": "./dist/index.d.cts",
47
- "default": "./dist/index.cjs"
46
+ "types": "./dist/radashi.d.cts",
47
+ "default": "./dist/radashi.cjs"
48
48
  },
49
- "types": "./dist/index.d.ts",
50
- "default": "./dist/index.js"
49
+ "types": "./dist/radashi.d.ts",
50
+ "default": "./dist/radashi.js"
51
51
  }
52
52
  }