@valkyriestudios/utils 12.20.0 → 12.22.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.
Files changed (87) hide show
  1. package/README.md +389 -160
  2. package/array/dedupe.d.ts +0 -2
  3. package/array/groupBy.d.ts +0 -1
  4. package/array/is.d.ts +1 -3
  5. package/array/isNotEmpty.d.ts +1 -3
  6. package/array/join.d.ts +0 -2
  7. package/array/join.js +3 -2
  8. package/array/mapFn.js +1 -1
  9. package/array/mapPrimitive.d.ts +0 -2
  10. package/array/sort.d.ts +0 -2
  11. package/array/split.d.ts +0 -2
  12. package/boolean/is.d.ts +1 -3
  13. package/date/addUTC.d.ts +5 -6
  14. package/date/diff.d.ts +5 -6
  15. package/date/endOfUTC.d.ts +4 -5
  16. package/date/format.d.ts +16 -2
  17. package/date/format.js +110 -42
  18. package/date/index.d.ts +2 -1
  19. package/date/index.js +3 -1
  20. package/date/is.d.ts +1 -3
  21. package/date/isFormat.d.ts +0 -1
  22. package/date/isLeap.d.ts +7 -0
  23. package/date/isLeap.js +11 -0
  24. package/date/nowUnix.d.ts +0 -2
  25. package/date/nowUnixMs.d.ts +0 -2
  26. package/date/setTimeUTC.d.ts +1 -2
  27. package/date/startOfUTC.d.ts +4 -5
  28. package/date/toUTC.d.ts +1 -3
  29. package/date/toUnix.d.ts +1 -3
  30. package/deep/freeze.d.ts +1 -3
  31. package/deep/get.d.ts +5 -7
  32. package/deep/seal.d.ts +1 -3
  33. package/deep/set.d.ts +0 -1
  34. package/equal.d.ts +2 -4
  35. package/formdata/index.d.ts +2 -1
  36. package/formdata/index.js +3 -1
  37. package/formdata/is.d.ts +1 -3
  38. package/formdata/toObject.d.ts +23 -0
  39. package/formdata/toObject.js +58 -0
  40. package/function/is.d.ts +1 -3
  41. package/function/isAsync.d.ts +1 -3
  42. package/function/noop.d.ts +0 -2
  43. package/function/noop.js +1 -2
  44. package/function/noopresolve.d.ts +0 -2
  45. package/function/noopreturn.d.ts +0 -2
  46. package/function/sleep.d.ts +1 -3
  47. package/hash/fnv1A.d.ts +2 -4
  48. package/hash/guid.d.ts +0 -2
  49. package/index.d.ts +39 -10
  50. package/number/is.d.ts +1 -3
  51. package/number/isAbove.d.ts +2 -4
  52. package/number/isAboveOrEqual.d.ts +2 -4
  53. package/number/isBelow.d.ts +2 -4
  54. package/number/isBelowOrEqual.d.ts +2 -4
  55. package/number/isBetween.d.ts +3 -5
  56. package/number/isBetween.js +4 -6
  57. package/number/isInteger.d.ts +1 -3
  58. package/number/isIntegerAbove.d.ts +2 -4
  59. package/number/isIntegerAboveOrEqual.d.ts +2 -4
  60. package/number/isIntegerBelow.d.ts +2 -4
  61. package/number/isIntegerBelowOrEqual.d.ts +2 -4
  62. package/number/isIntegerBetween.d.ts +3 -5
  63. package/number/isIntegerBetween.js +4 -6
  64. package/number/isNumericalNaN.d.ts +1 -3
  65. package/number/randomBetween.d.ts +2 -4
  66. package/number/randomIntBetween.d.ts +2 -4
  67. package/number/round.d.ts +2 -4
  68. package/number/round.js +5 -3
  69. package/number/toPercentage.d.ts +4 -6
  70. package/object/define.d.ts +0 -2
  71. package/object/is.d.ts +1 -3
  72. package/object/isNotEmpty.d.ts +2 -6
  73. package/object/merge.d.ts +2 -4
  74. package/object/merge.js +2 -3
  75. package/object/pick.d.ts +0 -2
  76. package/package.json +1 -1
  77. package/regexp/is.d.ts +1 -3
  78. package/regexp/sanitize.d.ts +1 -3
  79. package/regexp/sanitize.js +2 -1
  80. package/string/humanizeBytes.d.ts +1 -3
  81. package/string/humanizeNumber.d.ts +2 -4
  82. package/string/humanizeNumber.js +2 -2
  83. package/string/is.d.ts +1 -3
  84. package/string/isBetween.d.ts +4 -6
  85. package/string/isNotEmpty.d.ts +2 -4
  86. package/string/shorten.d.ts +0 -2
  87. package/string/shorten.js +1 -1
@@ -1,11 +1,7 @@
1
1
  /**
2
2
  * Check whether or not a provided value is an object with content
3
3
  *
4
- * @param val - Value to verify
5
- *
6
- * @returns Whether or not the value is an object with content
4
+ * @param {unknown} val - Value to verify
7
5
  */
8
- declare function isNotEmptyObject(val: unknown): val is {
9
- [key: string]: any;
10
- };
6
+ declare function isNotEmptyObject(val: unknown): val is Record<string, any>;
11
7
  export { isNotEmptyObject, isNotEmptyObject as default };
package/object/merge.d.ts CHANGED
@@ -10,10 +10,8 @@ type MergeOptions = {
10
10
  * take note: this does not merge onto passed objects by reference but instead
11
11
  * returns a new object
12
12
  *
13
- * @param target - Base Object
14
- * @param source - (default={}) Object to merge onto base object
15
- *
16
- * @returns Combined target and source objects
13
+ * @param {Record<string,any>} target - Base Object
14
+ * @param {Record<string,any>|Record<string,any>[]} source - (default={}) Object to merge onto base object
17
15
  */
18
16
  declare function merge(target: Record<string, any>, source?: Record<string, any> | Record<string, any>[], opts?: MergeOptions): Record<string, any>;
19
17
  export { merge, merge as default };
package/object/merge.js CHANGED
@@ -26,9 +26,8 @@ function merge(target, source = {}, opts = {}) {
26
26
  let acc = { ...target };
27
27
  for (let i = 0; i < sources.length; i++) {
28
28
  const el = sources[i];
29
- if (Object.prototype.toString.call(el) !== PROTO_OBJ) {
30
- throw new Error('object/merge: Please ensure valid target/source is passed');
31
- }
29
+ if (Object.prototype.toString.call(el) !== PROTO_OBJ)
30
+ continue;
32
31
  acc = innerMerge(acc, el, union);
33
32
  }
34
33
  return acc;
package/object/pick.d.ts CHANGED
@@ -9,8 +9,6 @@ type DottedKeys<T> = (T extends ObjectType ? {
9
9
  *
10
10
  * @param obj - Object to pick from
11
11
  * @param keys - Array of keys to pick from object
12
- *
13
- * @returns Object containing the picked keys from source object
14
12
  */
15
13
  declare function pick<T extends Record<string, any>, K extends DottedKeys<T>>(obj: T, keys: K[]): {
16
14
  [key: string]: any;
package/package.json CHANGED
@@ -1 +1 @@
1
- { "name": "@valkyriestudios/utils", "version": "12.20.0", "description": "A collection of single-function utilities for common tasks", "author": { "name": "Peter Vermeulen", "url": "https://www.linkedin.com/in/petervermeulen1/" }, "keywords": [ "utility", "library", "javascript", "js", "node", "bun" ], "license": "MIT", "repository": { "type": "git", "url": "git+https://github.com/ValkyrieStudios/utils.git" }, "bugs": { "url": "https://github.com/ValkyrieStudios/utils/issues" }, "homepage": "https://github.com/ValkyrieStudios/utils#readme", "types": "index.d.ts" }
1
+ { "name": "@valkyriestudios/utils", "version": "12.22.0", "description": "A collection of single-function utilities for common tasks", "author": { "name": "Peter Vermeulen", "url": "https://www.linkedin.com/in/petervermeulen1/" }, "keywords": [ "utility", "library", "javascript", "js", "node", "bun" ], "license": "MIT", "repository": { "type": "git", "url": "git+https://github.com/ValkyrieStudios/utils.git" }, "bugs": { "url": "https://github.com/ValkyrieStudios/utils/issues" }, "homepage": "https://github.com/ValkyrieStudios/utils#readme", "types": "index.d.ts" }
package/regexp/is.d.ts CHANGED
@@ -1,9 +1,7 @@
1
1
  /**
2
2
  * Check whether or not a provided value is a RegExp instance
3
3
  *
4
- * @param val - Value to verify
5
- *
6
- * @returns Whether or not the value is a RegExp
4
+ * @param {unknown} val - Value to verify
7
5
  */
8
6
  declare function isRegExp(val: unknown): val is RegExp;
9
7
  export { isRegExp, isRegExp as default };
@@ -4,9 +4,7 @@
4
4
  *
5
5
  * For more info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping
6
6
  *
7
- * @param val - Value to sanitize
8
- *
9
- * @returns Sanitized value
7
+ * @param {string} val - Value to sanitize
10
8
  */
11
9
  declare function sanitizeRegExp(val: string): string | false;
12
10
  export { sanitizeRegExp, sanitizeRegExp as default };
@@ -2,8 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.sanitizeRegExp = sanitizeRegExp;
4
4
  exports.default = sanitizeRegExp;
5
+ const RGX = /[.*+\-?^${}()|[\]\\]/g;
5
6
  function sanitizeRegExp(val) {
6
7
  if (typeof val !== 'string')
7
8
  return false;
8
- return val.trim().replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&');
9
+ return val.trim().replace(RGX, '\\$&');
9
10
  }
@@ -32,9 +32,7 @@ interface humanizeBytesOptions {
32
32
  * humanizeBytes(-374237489237); // '-348.5 GB'
33
33
  *
34
34
  * @param {number|string} val - Number or string byte value to humanize (string should be convertible to a number)
35
- * @param {humanizeBytesOptions?} opts - Humanization options
36
- *
37
- * @returns Humanized byte value as string
35
+ * @param {humanizeBytesOptions} opts - Humanization options
38
36
  */
39
37
  declare function humanizeBytes(val: number | string, options?: humanizeBytesOptions): string;
40
38
  export { humanizeBytes, humanizeBytes as default };
@@ -43,10 +43,8 @@ interface humanizeNumberOptions {
43
43
  * humanizeNumber('-1500'); // '-1.5k'
44
44
  * humanizeNumber(47328748923747923479); // '47,328.75q'
45
45
  *
46
- * @param val - Number or string value to humanize (string should be convertible to a number)
47
- * @param opts - (default={}) Pass to override options.
48
- *
49
- * @returns Humanized number as string
46
+ * @param {number|string} val - Number or string value to humanize (string should be convertible to a number)
47
+ * @param {humanizeNumberOptions} opts - (default={}) Pass to override options.
50
48
  */
51
49
  declare function humanizeNumber(val: number | string, options?: humanizeNumberOptions): string;
52
50
  export { humanizeNumber, humanizeNumber as default };
@@ -18,7 +18,7 @@ function humanizeNumber(val, options = {}) {
18
18
  : DEFAULT_UNITS;
19
19
  let normalized = typeof val === 'string' ? parseFloat(val.trim()) : val;
20
20
  if (!Number.isFinite(normalized) || normalized === 0)
21
- return UNITS ? `0${UNITS[0]}` : '0';
21
+ return UNITS ? '0' + UNITS[0] : '0';
22
22
  if (REAL)
23
23
  normalized = Math.round(normalized);
24
24
  const sign = normalized < 0 ? '-' : '';
@@ -30,7 +30,7 @@ function humanizeNumber(val, options = {}) {
30
30
  unit_ix++;
31
31
  }
32
32
  }
33
- const humanized = `${(0, round_1.round)(normalized, PRECISION)}`.split('.', 2);
33
+ const humanized = ('' + (0, round_1.round)(normalized, PRECISION)).split('.', 2);
34
34
  const integer_part = humanized[0];
35
35
  const integer_part_len = integer_part.length;
36
36
  let formattedIntegerPart = '';
package/string/is.d.ts CHANGED
@@ -1,9 +1,7 @@
1
1
  /**
2
2
  * Check whether or not a provided value is a string
3
3
  *
4
- * @param val - Value to verify
5
- *
6
- * @returns Whether or not the value is a string
4
+ * @param {unknown} val - Value to verify
7
5
  */
8
6
  declare function isString(val: unknown): val is string;
9
7
  export { isString, isString as default };
@@ -3,12 +3,10 @@
3
3
  * inclusive of min and max
4
4
  * equal to another value
5
5
  *
6
- * @param val - Value to verify
7
- * @param min - Lower boundary
8
- * @param max - Upper boundary
9
- * @param trimmed - (default=true) Trim the string or not
10
- *
11
- * @returns Whether or not the value is a string of length between min and max inclusive
6
+ * @param {unknown} val - Value to verify
7
+ * @param {number} min - Lower boundary
8
+ * @param {number} max - Upper boundary
9
+ * @param {boolean} trimmed - (default=true) Trim the string or not
12
10
  */
13
11
  declare function isStringBetween(val: unknown, min: number, max: number, trimmed?: boolean): val is string;
14
12
  export { isStringBetween, isStringBetween as default };
@@ -1,10 +1,8 @@
1
1
  /**
2
2
  * Check whether or not a provided value is a string with content
3
3
  *
4
- * @param val - Value to verify
5
- * @param trimmed - (default=true) Trim the string or not
6
- *
7
- * @returns Whether or not the value is a string with content
4
+ * @param {unknown} val - Value to verify
5
+ * @param {boolean} trimmed - (default=true) Trim the string or not
8
6
  */
9
7
  declare function isNotEmptyString(val: unknown, trimmed?: boolean): val is string;
10
8
  export { isNotEmptyString, isNotEmptyString as default };
@@ -5,8 +5,6 @@
5
5
  * @param {number} length - Length to shorten it to
6
6
  * @param {string} postfix - (default:'...') Postfix to use in case the string got shortened
7
7
  * @param {boolean?} truncate_words - (default:true) Truncate words or not
8
- *
9
- * @returns Shortened string
10
8
  */
11
9
  declare function shorten(val: string, length: number, postfix?: string, truncate_words?: boolean): string;
12
10
  export { shorten, shorten as default };
package/string/shorten.js CHANGED
@@ -14,7 +14,7 @@ function shorten(val, length, postfix = '...', truncate_words = true) {
14
14
  if (truncate_words)
15
15
  return truncated + postfix;
16
16
  let end = length;
17
- while (end > 0 && sanitized[end] !== ' ' && sanitized[end - 1] !== ' ') {
17
+ while (end && sanitized[end] !== ' ' && sanitized[end - 1] !== ' ') {
18
18
  end--;
19
19
  }
20
20
  return sanitized.substring(0, end).trim() + postfix;