@valkyriestudios/utils 12.19.0 → 12.21.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 (91) hide show
  1. package/README.md +384 -161
  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 +175 -73
  18. package/date/index.d.ts +3 -1
  19. package/date/index.js +6 -1
  20. package/date/is.d.ts +1 -3
  21. package/date/isFormat.d.ts +11 -0
  22. package/date/isFormat.js +110 -0
  23. package/date/isLeap.d.ts +7 -0
  24. package/date/isLeap.js +11 -0
  25. package/date/nowUnix.d.ts +0 -2
  26. package/date/nowUnixMs.d.ts +0 -2
  27. package/date/setTimeUTC.d.ts +1 -2
  28. package/date/startOfUTC.d.ts +4 -5
  29. package/date/toUTC.d.ts +1 -3
  30. package/date/toUnix.d.ts +1 -3
  31. package/deep/freeze.d.ts +1 -3
  32. package/deep/get.d.ts +5 -7
  33. package/deep/seal.d.ts +1 -3
  34. package/deep/set.d.ts +0 -1
  35. package/equal.d.ts +2 -4
  36. package/formdata/index.d.ts +2 -1
  37. package/formdata/index.js +3 -1
  38. package/formdata/is.d.ts +1 -3
  39. package/formdata/toObject.d.ts +16 -0
  40. package/formdata/toObject.js +23 -0
  41. package/function/is.d.ts +1 -3
  42. package/function/isAsync.d.ts +1 -3
  43. package/function/noop.d.ts +0 -2
  44. package/function/noop.js +1 -2
  45. package/function/noopresolve.d.ts +0 -2
  46. package/function/noopreturn.d.ts +0 -2
  47. package/function/sleep.d.ts +1 -3
  48. package/hash/fnv1A.d.ts +2 -4
  49. package/hash/fnv1A.js +2 -2
  50. package/hash/guid.d.ts +0 -2
  51. package/index.d.ts +41 -10
  52. package/number/is.d.ts +1 -3
  53. package/number/isAbove.d.ts +2 -4
  54. package/number/isAboveOrEqual.d.ts +2 -4
  55. package/number/isBelow.d.ts +2 -4
  56. package/number/isBelowOrEqual.d.ts +2 -4
  57. package/number/isBetween.d.ts +3 -5
  58. package/number/isBetween.js +4 -6
  59. package/number/isInteger.d.ts +1 -3
  60. package/number/isIntegerAbove.d.ts +2 -4
  61. package/number/isIntegerAboveOrEqual.d.ts +2 -4
  62. package/number/isIntegerBelow.d.ts +2 -4
  63. package/number/isIntegerBelowOrEqual.d.ts +2 -4
  64. package/number/isIntegerBetween.d.ts +3 -5
  65. package/number/isIntegerBetween.js +4 -6
  66. package/number/isNumericalNaN.d.ts +1 -3
  67. package/number/randomBetween.d.ts +2 -4
  68. package/number/randomIntBetween.d.ts +2 -4
  69. package/number/round.d.ts +2 -4
  70. package/number/round.js +5 -3
  71. package/number/toPercentage.d.ts +4 -6
  72. package/object/define.d.ts +0 -2
  73. package/object/is.d.ts +1 -3
  74. package/object/isNotEmpty.d.ts +2 -6
  75. package/object/merge.d.ts +2 -4
  76. package/object/merge.js +2 -3
  77. package/object/pick.d.ts +0 -2
  78. package/object/pick.js +2 -3
  79. package/package.json +1 -1
  80. package/regexp/is.d.ts +1 -3
  81. package/regexp/sanitize.d.ts +1 -3
  82. package/regexp/sanitize.js +2 -1
  83. package/string/humanizeBytes.d.ts +1 -3
  84. package/string/humanizeBytes.js +5 -11
  85. package/string/humanizeNumber.d.ts +2 -4
  86. package/string/humanizeNumber.js +13 -15
  87. package/string/is.d.ts +1 -3
  88. package/string/isBetween.d.ts +4 -6
  89. package/string/isNotEmpty.d.ts +2 -4
  90. package/string/shorten.d.ts +0 -2
  91. package/string/shorten.js +1 -4
@@ -3,10 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isNumberBetween = isNumberBetween;
4
4
  exports.default = isNumberBetween;
5
5
  function isNumberBetween(val, min, max) {
6
- if (!Number.isFinite(val) ||
7
- !Number.isFinite(min) ||
8
- !Number.isFinite(max) ||
9
- min >= max)
10
- return false;
11
- return val >= min && val <= max;
6
+ return (Number.isFinite(val) &&
7
+ Number.isFinite(min) &&
8
+ Number.isFinite(max) &&
9
+ (val >= min && val <= max));
12
10
  }
@@ -1,9 +1,7 @@
1
1
  /**
2
2
  * Check whether or not a provided value is an integer
3
3
  *
4
- * @param val - Value to verify
5
- *
6
- * @returns Whether or not the value is an integer
4
+ * @param {unknown} val - Value to verify
7
5
  */
8
6
  declare function isInteger(val: unknown): val is number;
9
7
  export { isInteger, isInteger as default };
@@ -1,10 +1,8 @@
1
1
  /**
2
2
  * Check whether or not the provided value is an integer above another value
3
3
  *
4
- * @param val - Value to verify
5
- * @param ref - Reference the provided value needs to be above
6
- *
7
- * @returns Whether or not the value is above the reference
4
+ * @param {unknown} val - Value to verify
5
+ * @param {number} ref - Reference the provided value needs to be above
8
6
  */
9
7
  declare function isIntegerAbove(val: unknown, ref: number): val is number;
10
8
  export { isIntegerAbove, isIntegerAbove as default };
@@ -2,10 +2,8 @@
2
2
  * Check whether or not the provided value is an integer above or equal
3
3
  * to another value
4
4
  *
5
- * @param val - Value to verify
6
- * @param ref - Reference the provided value needs to be above or equal to
7
- *
8
- * @returns Whether or not the value is above or equal to the reference
5
+ * @param {unknown} val - Value to verify
6
+ * @param {number} ref - Reference the provided value needs to be above or equal to
9
7
  */
10
8
  declare function isIntegerAboveOrEqual(val: unknown, ref: number): val is number;
11
9
  export { isIntegerAboveOrEqual, isIntegerAboveOrEqual as default };
@@ -1,10 +1,8 @@
1
1
  /**
2
2
  * Check whether or not the provided value is an integer below another value
3
3
  *
4
- * @param val - Value to verify
5
- * @param ref - Reference the provided value needs to be below
6
- *
7
- * @returns Whether or not the value is below the reference
4
+ * @param {unknown} val - Value to verify
5
+ * @param {number} ref - Reference the provided value needs to be below
8
6
  */
9
7
  declare function isIntegerBelow(val: unknown, ref: number): val is number;
10
8
  export { isIntegerBelow, isIntegerBelow as default };
@@ -2,10 +2,8 @@
2
2
  * Check whether or not the provided value is an integer below or
3
3
  * equal to another value
4
4
  *
5
- * @param val - Value to verify
6
- * @param ref - Reference the provided value needs to be below or equal to
7
- *
8
- * @returns Whether or not the value is below or equal to the reference
5
+ * @param {unknown} val - Value to verify
6
+ * @param {number} ref - Reference the provided value needs to be below or equal to
9
7
  */
10
8
  declare function isIntegerBelowOrEqual(val: unknown, ref: number): val is number;
11
9
  export { isIntegerBelowOrEqual, isIntegerBelowOrEqual as default };
@@ -3,11 +3,9 @@
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
- *
10
- * @returns Whether or not the value is an integer between min and max inclusive
6
+ * @param {unknown} val - Value to verify
7
+ * @param {number} min - Lower boundary
8
+ * @param {number} max - Upper boundary
11
9
  */
12
10
  declare function isIntegerBetween(val: unknown, min: number, max: number): val is number;
13
11
  export { isIntegerBetween, isIntegerBetween as default };
@@ -3,10 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isIntegerBetween = isIntegerBetween;
4
4
  exports.default = isIntegerBetween;
5
5
  function isIntegerBetween(val, min, max) {
6
- if (!Number.isInteger(val) ||
7
- !Number.isFinite(min) ||
8
- !Number.isFinite(max) ||
9
- min >= max)
10
- return false;
11
- return val >= min && val <= max;
6
+ return (Number.isInteger(val) &&
7
+ Number.isFinite(min) &&
8
+ Number.isFinite(max) &&
9
+ (val >= min && val <= max));
12
10
  }
@@ -1,9 +1,7 @@
1
1
  /**
2
2
  * Check whether or not the provided value is a numerical NaN
3
3
  *
4
- * @param val - Value to verify
5
- *
6
- * @returns Whether or not the value is a numerical NaN
4
+ * @param {unknown} val - Value to verify
7
5
  */
8
6
  declare function isNumericalNaN(val: unknown): boolean;
9
7
  export { isNumericalNaN, isNumericalNaN as default };
@@ -1,10 +1,8 @@
1
1
  /**
2
2
  * Generates a random number between the provided lower and upper bound
3
3
  *
4
- * @param min - (default=0) Lower bound
5
- * @param max - (default=10) Upper bound
6
- *
7
- * @returns Random number between min and max
4
+ * @param {number} min - (default=0) Lower bound
5
+ * @param {number} max - (default=10) Upper bound
8
6
  */
9
7
  declare function randomBetween(min?: number, max?: number): number;
10
8
  export { randomBetween, randomBetween as default };
@@ -2,10 +2,8 @@
2
2
  * Generates a random integer between the provided lower and upper bound,
3
3
  * not inclusive of the upper bound
4
4
  *
5
- * @param min - (default=0) Lower bound
6
- * @param max - (default=10) Upper bound
7
- *
8
- * @returns Random integer between min and max
5
+ * @param {number} min - (default=0) Lower bound
6
+ * @param {number} max - (default=10) Upper bound
9
7
  */
10
8
  declare function randomIntBetween(min?: number, max?: number): number;
11
9
  export { randomIntBetween, randomIntBetween as default };
package/number/round.d.ts CHANGED
@@ -1,10 +1,8 @@
1
1
  /**
2
2
  * Rounds the provided value to a certain precision
3
3
  *
4
- * @param val - Value to round
5
- * @param precision - (default=0) Amount of decimals precision to round to
6
- *
7
- * @returns Rounded value according to decimal precision provided
4
+ * @param {number} val - Value to round
5
+ * @param {number} precision - (default=0) Amount of decimals precision to round to
8
6
  */
9
7
  declare function round(val: number, precision?: number): number;
10
8
  export { round, round as default };
package/number/round.js CHANGED
@@ -2,10 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.round = round;
4
4
  exports.default = round;
5
+ const ROUND_EPSILON = 1 + Number.EPSILON;
5
6
  function round(val, precision = 0) {
6
7
  if (!Number.isFinite(val))
7
8
  throw new TypeError('Value should be numeric');
8
- const exp = Math.pow(10, Number.isInteger(precision) && precision > 0 ? precision : 0);
9
- const num = (val * exp) * (1 + Number.EPSILON);
10
- return Math.round(num) / exp;
9
+ if (!Number.isInteger(precision) || precision <= 0)
10
+ return Math.round(val * ROUND_EPSILON);
11
+ const exp = Math.pow(10, precision);
12
+ return Math.round((val * exp) * ROUND_EPSILON) / exp;
11
13
  }
@@ -1,12 +1,10 @@
1
1
  /**
2
2
  * Converts a number into a percentage respective to a provided range
3
3
  *
4
- * @param val - Value to convert into a percentage for the provided range
5
- * @param precision - (default=0) Amount of decimals precision to use
6
- * @param min - (default=0) Lower bound of the range the value is to be converted to percentage for
7
- * @param max - (default=1) Upper bound of the range the value is to be converted to percentage for
8
- *
9
- * @returns Percentage value respective to the provided range
4
+ * @param {number} val - Value to convert into a percentage for the provided range
5
+ * @param {number} precision - (default=0) Amount of decimals precision to use
6
+ * @param {number} min - (default=0) Lower bound of the range the value is to be converted to percentage for
7
+ * @param {number} max - (default=1) Upper bound of the range the value is to be converted to percentage for
10
8
  */
11
9
  declare function toPercentage(val: number, precision?: number, min?: number, max?: number): number;
12
10
  export { toPercentage, toPercentage as default };
@@ -3,8 +3,6 @@
3
3
  *
4
4
  * @param props - Object with properties to define
5
5
  * @param obj - (default={}) Object to define on top of
6
- *
7
- * @returns Object with the defined properties
8
6
  */
9
7
  declare function define(props: {
10
8
  [key: string]: any;
package/object/is.d.ts CHANGED
@@ -1,9 +1,7 @@
1
1
  /**
2
2
  * Check whether or not a provided value is an object
3
3
  *
4
- * @param val - Value to verify
5
- *
6
- * @returns Whether or not the value is an object
4
+ * @param {unknown} val - Value to verify
7
5
  */
8
6
  declare function isObject(val: unknown): val is {
9
7
  [key: string]: any;
@@ -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/object/pick.js CHANGED
@@ -18,7 +18,7 @@ function pick(obj, keys) {
18
18
  sanitized = key.trim();
19
19
  if (!sanitized.length)
20
20
  continue;
21
- if (sanitized.includes('.')) {
21
+ if (sanitized.indexOf('.') >= 0) {
22
22
  val = (0, get_1.deepGet)(obj, sanitized);
23
23
  if (val === undefined)
24
24
  continue;
@@ -27,9 +27,8 @@ function pick(obj, keys) {
27
27
  let cursor = map;
28
28
  for (let y = 0; y < parts_len - 1; y++) {
29
29
  const part = parts[y].trim();
30
- if (!cursor[part]) {
30
+ if (!cursor[part])
31
31
  cursor[part] = {};
32
- }
33
32
  cursor = cursor[part];
34
33
  }
35
34
  cursor[parts[parts_len - 1].trim()] = val;
package/package.json CHANGED
@@ -1 +1 @@
1
- { "name": "@valkyriestudios/utils", "version": "12.19.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.21.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 };
@@ -3,21 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.humanizeBytes = humanizeBytes;
4
4
  exports.default = humanizeBytes;
5
5
  const humanizeNumber_1 = require("./humanizeNumber");
6
- const isIntegerAboveOrEqual_1 = require("../number/isIntegerAboveOrEqual");
6
+ const DEFAULT_UNITS = [' bytes', ' KB', ' MB', ' GB', ' TB', ' PB', ' EB', ' ZB', ' YB'];
7
7
  function humanizeBytes(val, options = {}) {
8
8
  return (0, humanizeNumber_1.humanizeNumber)(val, {
9
- delim: typeof options?.delim === 'string'
10
- ? options.delim
11
- : ',',
12
- separator: typeof options?.separator === 'string' && options.separator.trim().length
13
- ? options.separator
14
- : '.',
15
- precision: (0, isIntegerAboveOrEqual_1.isIntegerAboveOrEqual)(options?.precision, 0)
16
- ? options.precision
17
- : 2,
9
+ delim: 'delim' in options ? options.delim : ',',
10
+ separator: 'separator' in options ? options.separator : '.',
11
+ precision: 'precision' in options ? options.precision : 2,
18
12
  units: Array.isArray(options?.units) && options.units.length
19
13
  ? options.units
20
- : [' bytes', ' KB', ' MB', ' GB', ' TB', ' PB', ' EB', ' ZB', ' YB'],
14
+ : DEFAULT_UNITS,
21
15
  divider: 1024,
22
16
  real: true,
23
17
  });
@@ -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 };
@@ -16,31 +16,29 @@ function humanizeNumber(val, options = {}) {
16
16
  : options?.units === false
17
17
  ? false
18
18
  : DEFAULT_UNITS;
19
- let normalized = 0;
20
- if (typeof val === 'string') {
21
- normalized = REAL ? parseInt(val.trim(), 10) : parseFloat(val);
22
- }
23
- else if (Number.isFinite(val)) {
24
- normalized = REAL ? Math.round(val) : val;
25
- }
19
+ let normalized = typeof val === 'string' ? parseFloat(val.trim()) : val;
26
20
  if (!Number.isFinite(normalized) || normalized === 0)
27
- return UNITS ? `0${UNITS[0]}` : '0';
21
+ return UNITS ? '0' + UNITS[0] : '0';
22
+ if (REAL)
23
+ normalized = Math.round(normalized);
28
24
  const sign = normalized < 0 ? '-' : '';
29
25
  normalized = Math.abs(normalized);
30
26
  let unit_ix = 0;
31
27
  if (UNITS) {
32
- for (unit_ix; normalized >= DIVIDER && unit_ix < UNITS.length - 1; unit_ix++) {
28
+ while (normalized >= DIVIDER && unit_ix < UNITS.length - 1) {
33
29
  normalized /= DIVIDER;
30
+ unit_ix++;
34
31
  }
35
32
  }
36
- const humanized = `${(0, round_1.round)(normalized, PRECISION)}`.split('.', 2);
37
- const integerPart = humanized[0];
33
+ const humanized = ('' + (0, round_1.round)(normalized, PRECISION)).split('.', 2);
34
+ const integer_part = humanized[0];
35
+ const integer_part_len = integer_part.length;
38
36
  let formattedIntegerPart = '';
39
- for (let i = 0; i < integerPart.length; i++) {
40
- if (i > 0 && (integerPart.length - i) % 3 === 0) {
37
+ for (let i = 0; i < integer_part_len; i++) {
38
+ if (i > 0 && (integer_part_len - i) % 3 === 0) {
41
39
  formattedIntegerPart += DELIM;
42
40
  }
43
- formattedIntegerPart += integerPart[i];
41
+ formattedIntegerPart += integer_part[i];
44
42
  }
45
- return `${sign}${formattedIntegerPart}${humanized[1] ? SEPARATOR + humanized[1] : ''}${UNITS ? UNITS[unit_ix] : ''}`;
43
+ return sign + formattedIntegerPart + (humanized[1] ? SEPARATOR + humanized[1] : '') + (UNITS ? UNITS[unit_ix] : '');
46
44
  }
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,11 +14,8 @@ 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
- if (end === 0) {
21
- return sanitized.substring(0, length) + postfix;
22
- }
23
20
  return sanitized.substring(0, end).trim() + postfix;
24
21
  }