@web-ts-toolkit/utils 0.30.0 → 0.31.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
@@ -11,7 +11,7 @@ pnpm add @web-ts-toolkit/utils
11
11
  ## Highlights
12
12
 
13
13
  - object-path helpers such as `get(...)`, `set(...)`, and `hasOwn(...)`
14
- - collection helpers such as `map(...)`, `filter(...)`, `uniq(...)`, `uniqBy(...)`, and `orderBy(...)`
14
+ - collection helpers such as `map(...)`, `filter(...)`, `eachRight(...)`, `join(...)`, `uniq(...)`, `uniqBy(...)`, and `orderBy(...)`
15
15
  - small type guards
16
16
  - URL helpers such as `normalizeUrlPath(...)`
17
17
  - async helpers such as `mapValuesAsync(...)`
@@ -65,7 +65,7 @@ parseBooleanString('true', false);
65
65
  ## Main Exports
66
66
 
67
67
  - object helpers: `get`, `set`, `hasOwn`, `pick`, `pickBy`, `omit`, `omitBy`, `assign`, `cloneDeep`, `mapKeys`
68
- - collection helpers: `map`, `filter`, `reduce`, `find`, `flatten`, `uniq`, `uniqBy`, `orderBy`, `groupBy`, `sum`, `sumBy`
68
+ - collection helpers: `map`, `filter`, `eachRight`, `join`, `reduce`, `find`, `flatten`, `uniq`, `uniqBy`, `orderBy`, `groupBy`, `sum`, `sumBy`
69
69
  - string helpers: `startCase`, `upperCase`
70
70
  - guards: `isArray`, `isPlainObject`, `isString`, `isPromise`
71
71
  - URL helpers: `addLeadingSlash`, `removeConsecutiveSlashesFromUrl`, `normalizeUrlPath`
package/index.d.mts CHANGED
@@ -12,6 +12,9 @@ declare function compact<T>(array: T[] | null | undefined): T[];
12
12
 
13
13
  declare function difference<T>(array: T[] | null | undefined, ...values: Array<T[] | null | undefined>): T[];
14
14
 
15
+ declare function eachRight<T>(collection: T[] | null | undefined, iteratee: (value: T, key: number, collection: T[]) => unknown): T[] | null | undefined;
16
+ declare function eachRight<T extends object>(collection: T | null | undefined, iteratee: (value: T[keyof T], key: string, collection: T) => unknown): T | null | undefined;
17
+
15
18
  declare function filter<T>(collection: T[] | Record<string, T> | null | undefined, predicate: (value: T, key: number | string) => boolean): T[];
16
19
 
17
20
  declare function find<T>(collection: T[] | Record<string, T> | null | undefined, predicate: (value: T, key: number | string) => boolean): T | undefined;
@@ -63,6 +66,8 @@ declare function isString(value: unknown): value is string;
63
66
 
64
67
  declare function isUndefined(value: unknown): value is undefined;
65
68
 
69
+ declare function join(array: unknown[] | null | undefined, separator?: string): string;
70
+
66
71
  declare function keys(value: unknown): string[];
67
72
 
68
73
  declare function map<T, TResult>(collection: T[] | Record<string, T> | null | undefined, iteratee: string | number | ((value: T, key: number | string, collection: T[] | Record<string, T>) => TResult)): TResult[];
@@ -114,4 +119,4 @@ declare function uniqBy<T>(array: T[] | null | undefined, iteratee?: string | nu
114
119
 
115
120
  declare function upperCase(value: unknown): string;
116
121
 
117
- export { addLeadingSlash, arrayToRecord, assign, castArray, cloneDeep, compact, difference, filter, find, flatten, flattenDeep, forEach, get, groupBy, hasOwn, intersection, intersectionBy, isArray, isBoolean, isEmpty, isEqual, isFunction, isMatch, isNaNValue as isNaN, isNil, isNumber, isObject, isPlainObject, isPromise, isString, isUndefined, keys, map, mapKeys, mapValues, mapValuesAsync, noop, normalizeUrlPath, omit, omitBy, orderBy, padEnd, parseBooleanString, pick, pickBy, reduce, removeConsecutiveSlashesFromUrl, set, startCase, sum, sumBy, toAsyncFn, toStringRecord, uniq, uniqBy, upperCase };
122
+ export { addLeadingSlash, arrayToRecord, assign, castArray, cloneDeep, compact, difference, eachRight, filter, find, flatten, flattenDeep, forEach, get, groupBy, hasOwn, intersection, intersectionBy, isArray, isBoolean, isEmpty, isEqual, isFunction, isMatch, isNaNValue as isNaN, isNil, isNumber, isObject, isPlainObject, isPromise, isString, isUndefined, join, keys, map, mapKeys, mapValues, mapValuesAsync, noop, normalizeUrlPath, omit, omitBy, orderBy, padEnd, parseBooleanString, pick, pickBy, reduce, removeConsecutiveSlashesFromUrl, set, startCase, sum, sumBy, toAsyncFn, toStringRecord, uniq, uniqBy, upperCase };
package/index.d.ts CHANGED
@@ -12,6 +12,9 @@ declare function compact<T>(array: T[] | null | undefined): T[];
12
12
 
13
13
  declare function difference<T>(array: T[] | null | undefined, ...values: Array<T[] | null | undefined>): T[];
14
14
 
15
+ declare function eachRight<T>(collection: T[] | null | undefined, iteratee: (value: T, key: number, collection: T[]) => unknown): T[] | null | undefined;
16
+ declare function eachRight<T extends object>(collection: T | null | undefined, iteratee: (value: T[keyof T], key: string, collection: T) => unknown): T | null | undefined;
17
+
15
18
  declare function filter<T>(collection: T[] | Record<string, T> | null | undefined, predicate: (value: T, key: number | string) => boolean): T[];
16
19
 
17
20
  declare function find<T>(collection: T[] | Record<string, T> | null | undefined, predicate: (value: T, key: number | string) => boolean): T | undefined;
@@ -63,6 +66,8 @@ declare function isString(value: unknown): value is string;
63
66
 
64
67
  declare function isUndefined(value: unknown): value is undefined;
65
68
 
69
+ declare function join(array: unknown[] | null | undefined, separator?: string): string;
70
+
66
71
  declare function keys(value: unknown): string[];
67
72
 
68
73
  declare function map<T, TResult>(collection: T[] | Record<string, T> | null | undefined, iteratee: string | number | ((value: T, key: number | string, collection: T[] | Record<string, T>) => TResult)): TResult[];
@@ -114,4 +119,4 @@ declare function uniqBy<T>(array: T[] | null | undefined, iteratee?: string | nu
114
119
 
115
120
  declare function upperCase(value: unknown): string;
116
121
 
117
- export { addLeadingSlash, arrayToRecord, assign, castArray, cloneDeep, compact, difference, filter, find, flatten, flattenDeep, forEach, get, groupBy, hasOwn, intersection, intersectionBy, isArray, isBoolean, isEmpty, isEqual, isFunction, isMatch, isNaNValue as isNaN, isNil, isNumber, isObject, isPlainObject, isPromise, isString, isUndefined, keys, map, mapKeys, mapValues, mapValuesAsync, noop, normalizeUrlPath, omit, omitBy, orderBy, padEnd, parseBooleanString, pick, pickBy, reduce, removeConsecutiveSlashesFromUrl, set, startCase, sum, sumBy, toAsyncFn, toStringRecord, uniq, uniqBy, upperCase };
122
+ export { addLeadingSlash, arrayToRecord, assign, castArray, cloneDeep, compact, difference, eachRight, filter, find, flatten, flattenDeep, forEach, get, groupBy, hasOwn, intersection, intersectionBy, isArray, isBoolean, isEmpty, isEqual, isFunction, isMatch, isNaNValue as isNaN, isNil, isNumber, isObject, isPlainObject, isPromise, isString, isUndefined, join, keys, map, mapKeys, mapValues, mapValuesAsync, noop, normalizeUrlPath, omit, omitBy, orderBy, padEnd, parseBooleanString, pick, pickBy, reduce, removeConsecutiveSlashesFromUrl, set, startCase, sum, sumBy, toAsyncFn, toStringRecord, uniq, uniqBy, upperCase };
package/index.js CHANGED
@@ -26,6 +26,7 @@ __export(index_exports, {
26
26
  cloneDeep: () => cloneDeep,
27
27
  compact: () => compact,
28
28
  difference: () => difference,
29
+ eachRight: () => eachRight,
29
30
  filter: () => filter,
30
31
  find: () => find,
31
32
  flatten: () => flatten,
@@ -50,6 +51,7 @@ __export(index_exports, {
50
51
  isPromise: () => isPromise,
51
52
  isString: () => isString,
52
53
  isUndefined: () => isUndefined,
54
+ join: () => join,
53
55
  keys: () => keys,
54
56
  map: () => map,
55
57
  mapKeys: () => mapKeys,
@@ -401,6 +403,30 @@ function difference(array, ...values) {
401
403
  return array.filter((item) => !arrayIncludes(excluded, item));
402
404
  }
403
405
 
406
+ // src/eachRight.ts
407
+ function eachRight(collection, iteratee) {
408
+ if (!collection) {
409
+ return collection;
410
+ }
411
+ const callback = iteratee;
412
+ if (Array.isArray(collection)) {
413
+ for (let index = collection.length - 1; index >= 0; index--) {
414
+ if (callback(collection[index], index, collection) === false) {
415
+ break;
416
+ }
417
+ }
418
+ return collection;
419
+ }
420
+ const keys2 = Object.keys(collection);
421
+ for (let index = keys2.length - 1; index >= 0; index--) {
422
+ const key = keys2[index];
423
+ if (callback(collection[key], key, collection) === false) {
424
+ break;
425
+ }
426
+ }
427
+ return collection;
428
+ }
429
+
404
430
  // src/filter.ts
405
431
  function filter(collection, predicate) {
406
432
  if (!collection) {
@@ -672,6 +698,14 @@ function isUndefined(value) {
672
698
  return value === void 0;
673
699
  }
674
700
 
701
+ // src/join.ts
702
+ function join(array, separator) {
703
+ if (!Array.isArray(array)) {
704
+ return "";
705
+ }
706
+ return array.join(separator);
707
+ }
708
+
675
709
  // src/keys.ts
676
710
  function keys(value) {
677
711
  if (value == null) {
@@ -980,6 +1014,7 @@ function upperCase(value) {
980
1014
  cloneDeep,
981
1015
  compact,
982
1016
  difference,
1017
+ eachRight,
983
1018
  filter,
984
1019
  find,
985
1020
  flatten,
@@ -1004,6 +1039,7 @@ function upperCase(value) {
1004
1039
  isPromise,
1005
1040
  isString,
1006
1041
  isUndefined,
1042
+ join,
1007
1043
  keys,
1008
1044
  map,
1009
1045
  mapKeys,
package/index.mjs CHANGED
@@ -321,6 +321,30 @@ function difference(array, ...values) {
321
321
  return array.filter((item) => !arrayIncludes(excluded, item));
322
322
  }
323
323
 
324
+ // src/eachRight.ts
325
+ function eachRight(collection, iteratee) {
326
+ if (!collection) {
327
+ return collection;
328
+ }
329
+ const callback = iteratee;
330
+ if (Array.isArray(collection)) {
331
+ for (let index = collection.length - 1; index >= 0; index--) {
332
+ if (callback(collection[index], index, collection) === false) {
333
+ break;
334
+ }
335
+ }
336
+ return collection;
337
+ }
338
+ const keys2 = Object.keys(collection);
339
+ for (let index = keys2.length - 1; index >= 0; index--) {
340
+ const key = keys2[index];
341
+ if (callback(collection[key], key, collection) === false) {
342
+ break;
343
+ }
344
+ }
345
+ return collection;
346
+ }
347
+
324
348
  // src/filter.ts
325
349
  function filter(collection, predicate) {
326
350
  if (!collection) {
@@ -592,6 +616,14 @@ function isUndefined(value) {
592
616
  return value === void 0;
593
617
  }
594
618
 
619
+ // src/join.ts
620
+ function join(array, separator) {
621
+ if (!Array.isArray(array)) {
622
+ return "";
623
+ }
624
+ return array.join(separator);
625
+ }
626
+
595
627
  // src/keys.ts
596
628
  function keys(value) {
597
629
  if (value == null) {
@@ -899,6 +931,7 @@ export {
899
931
  cloneDeep,
900
932
  compact,
901
933
  difference,
934
+ eachRight,
902
935
  filter,
903
936
  find,
904
937
  flatten,
@@ -923,6 +956,7 @@ export {
923
956
  isPromise,
924
957
  isString,
925
958
  isUndefined,
959
+ join,
926
960
  keys,
927
961
  map,
928
962
  mapKeys,
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@web-ts-toolkit/utils",
3
3
  "description": "Shared collection, object, async, and URL helpers used across workspace packages",
4
4
  "homepage": "https://web-ts-toolkit.pages.dev/docs/packages/utils",
5
- "version": "0.30.0",
5
+ "version": "0.31.1",
6
6
  "sideEffects": false,
7
7
  "keywords": [
8
8
  "utilities",