@valkyriestudios/utils 5.3.0 → 5.4.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 (101) hide show
  1. package/.nyc_output/{e5760d4f-f98f-4742-ab93-9fe7645e0319.json → 23b5ae65-a0d9-469f-bf26-a14b838d3a7a.json} +1 -1
  2. package/.nyc_output/2b8fcaa7-2b0c-41b7-a640-7aa74f867235.json +1 -0
  3. package/.nyc_output/processinfo/23b5ae65-a0d9-469f-bf26-a14b838d3a7a.json +1 -0
  4. package/.nyc_output/processinfo/2b8fcaa7-2b0c-41b7-a640-7aa74f867235.json +1 -0
  5. package/.nyc_output/processinfo/index.json +1 -1
  6. package/CHANGELOG.md +18 -0
  7. package/README.md +23 -4
  8. package/array/dedupe.js +0 -3
  9. package/array/join.js +1 -1
  10. package/array/mapFn.js +1 -2
  11. package/array/mapKey.js +1 -1
  12. package/array/mapPrimitive.js +1 -1
  13. package/caching/memoize.js +0 -3
  14. package/codecov +0 -0
  15. package/codecov.sh +1 -1
  16. package/coverage/lcov-report/index.html +58 -58
  17. package/coverage/lcov-report/src/array/dedupe.js.html +7 -7
  18. package/coverage/lcov-report/src/array/index.html +39 -39
  19. package/coverage/lcov-report/src/array/is.js.html +4 -4
  20. package/coverage/lcov-report/src/array/isNotEmpty.js.html +6 -6
  21. package/coverage/lcov-report/src/array/join.js.html +10 -10
  22. package/coverage/lcov-report/src/array/mapFn.js.html +10 -10
  23. package/coverage/lcov-report/src/array/mapKey.js.html +10 -10
  24. package/coverage/lcov-report/src/array/mapPrimitive.js.html +10 -10
  25. package/coverage/lcov-report/src/array/shuffle.js.html +6 -6
  26. package/coverage/lcov-report/src/boolean/index.html +5 -5
  27. package/coverage/lcov-report/src/boolean/is.js.html +4 -4
  28. package/coverage/lcov-report/src/caching/index.html +9 -9
  29. package/coverage/lcov-report/src/caching/memoize.js.html +6 -6
  30. package/coverage/lcov-report/src/date/index.html +5 -5
  31. package/coverage/lcov-report/src/date/is.js.html +4 -4
  32. package/coverage/lcov-report/src/deep/define.js.html +8 -8
  33. package/coverage/lcov-report/src/deep/freeze.js.html +11 -11
  34. package/coverage/lcov-report/src/deep/get.js.html +9 -9
  35. package/coverage/lcov-report/src/deep/index.html +31 -31
  36. package/coverage/lcov-report/src/deep/seal.js.html +11 -11
  37. package/coverage/lcov-report/src/deep/set.js.html +9 -9
  38. package/coverage/lcov-report/src/equal.js.html +7 -7
  39. package/coverage/lcov-report/src/function/index.html +22 -22
  40. package/coverage/lcov-report/src/function/is.js.html +4 -4
  41. package/coverage/lcov-report/src/function/noop.js.html +9 -9
  42. package/coverage/lcov-report/src/function/noopresolve.js.html +4 -4
  43. package/coverage/lcov-report/src/function/noopreturn.js.html +4 -4
  44. package/coverage/lcov-report/src/function/sleep.js.html +4 -4
  45. package/coverage/lcov-report/src/hash/fnv1A.js.html +14 -14
  46. package/coverage/lcov-report/src/hash/guid.js.html +9 -9
  47. package/coverage/lcov-report/src/hash/index.html +23 -23
  48. package/coverage/lcov-report/src/index.html +13 -13
  49. package/coverage/lcov-report/src/is.js.html +7 -7
  50. package/coverage/lcov-report/src/number/index.html +50 -50
  51. package/coverage/lcov-report/src/number/is.js.html +8 -8
  52. package/coverage/lcov-report/src/number/isAbove.js.html +6 -6
  53. package/coverage/lcov-report/src/number/isBelow.js.html +6 -6
  54. package/coverage/lcov-report/src/number/isBetween.js.html +6 -6
  55. package/coverage/lcov-report/src/number/isInteger.js.html +8 -8
  56. package/coverage/lcov-report/src/number/isIntegerAbove.js.html +7 -7
  57. package/coverage/lcov-report/src/number/isIntegerBelow.js.html +7 -7
  58. package/coverage/lcov-report/src/number/isIntegerBetween.js.html +7 -7
  59. package/coverage/lcov-report/src/number/isNumericalNaN.js.html +5 -5
  60. package/coverage/lcov-report/src/number/randomBetween.js.html +11 -11
  61. package/coverage/lcov-report/src/number/round.js.html +7 -7
  62. package/coverage/lcov-report/src/number/toPercentage.js.html +7 -7
  63. package/coverage/lcov-report/src/object/define.js.html +6 -6
  64. package/coverage/lcov-report/src/object/defineFrozen.js.html +6 -6
  65. package/coverage/lcov-report/src/object/defineSealed.js.html +6 -6
  66. package/coverage/lcov-report/src/object/forValues.js.html +9 -9
  67. package/coverage/lcov-report/src/object/index.html +41 -41
  68. package/coverage/lcov-report/src/object/is.js.html +4 -4
  69. package/coverage/lcov-report/src/object/isNotEmpty.js.html +6 -6
  70. package/coverage/lcov-report/src/object/merge.js.html +10 -10
  71. package/coverage/lcov-report/src/object/pick.js.html +7 -7
  72. package/coverage/lcov-report/src/object/zip.js.html +6 -6
  73. package/coverage/lcov-report/src/regexp/index.html +5 -5
  74. package/coverage/lcov-report/src/regexp/is.js.html +4 -4
  75. package/coverage/lcov-report/src/string/humanizeBytes.js.html +211 -0
  76. package/coverage/lcov-report/src/string/index.html +34 -19
  77. package/coverage/lcov-report/src/string/is.js.html +5 -5
  78. package/coverage/lcov-report/src/string/isBetween.js.html +7 -7
  79. package/coverage/lcov-report/src/string/isNotEmpty.js.html +9 -9
  80. package/coverage/lcov-report/src/string/shorten.js.html +7 -7
  81. package/coverage/lcov.info +1051 -724
  82. package/deep/freeze.js +0 -1
  83. package/deep/get.js +1 -5
  84. package/deep/seal.js +0 -1
  85. package/deep/set.js +1 -7
  86. package/equal.js +0 -7
  87. package/function/is.js +0 -1
  88. package/function/noop.js +1 -2
  89. package/function/noopresolve.js +0 -1
  90. package/function/noopreturn.js +0 -1
  91. package/function/sleep.js +0 -1
  92. package/hash/fnv1A.js +0 -6
  93. package/hash/guid.js +0 -3
  94. package/number/isNumericalNaN.js +0 -2
  95. package/number/randomBetween.js +1 -1
  96. package/number/round.js +0 -1
  97. package/package.json +6 -6
  98. package/string/humanizeBytes.js +40 -0
  99. package/.nyc_output/42fb4596-cca6-4b5f-9d84-4dfa81222f86.json +0 -1
  100. package/.nyc_output/processinfo/42fb4596-cca6-4b5f-9d84-4dfa81222f86.json +0 -1
  101. package/.nyc_output/processinfo/e5760d4f-f98f-4742-ab93-9fe7645e0319.json +0 -1
package/deep/freeze.js CHANGED
@@ -16,7 +16,6 @@ function deep(obj) {
16
16
  });
17
17
  return next(obj);
18
18
  }
19
-
20
19
  function _default(obj) {
21
20
  if (!(0, _is["default"])(obj) && !(0, _is2["default"])(obj)) {
22
21
  throw new TypeError('Only objects can be frozen');
package/deep/get.js CHANGED
@@ -13,25 +13,21 @@ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread n
13
13
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
14
14
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
15
15
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
16
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
16
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
17
17
  function interpolatePath(path) {
18
18
  if (!(0, _isNotEmpty["default"])(path) && !(0, _is2["default"])(path)) throw new TypeError('No Path was given');
19
19
  if ((0, _is2["default"])(path)) return _toConsumableArray(path);
20
20
  return path.replace('[', '.').replace(']', '').split('.');
21
21
  }
22
-
23
22
  function _default(obj, path) {
24
23
  var get_parent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : !1;
25
24
  if (!(0, _is["default"])(obj) && !(0, _is2["default"])(obj)) throw new TypeError('Deepget is only supported for objects');
26
25
  var parts = interpolatePath(path);
27
-
28
26
  if (parts.length === 0 || parts.length === 1 && get_parent) return obj;
29
-
30
27
  if (get_parent) parts.pop();
31
28
  var cursor = obj;
32
29
  while (parts.length > 0) {
33
30
  cursor = (0, _is2["default"])(cursor) ? cursor[parseInt(parts.shift())] : cursor[parts.shift()];
34
31
  }
35
-
36
32
  return cursor || cursor === !1 || cursor === 0 || cursor === '' ? cursor : undefined;
37
33
  }
package/deep/seal.js CHANGED
@@ -16,7 +16,6 @@ function deep(obj) {
16
16
  });
17
17
  return next(obj);
18
18
  }
19
-
20
19
  function _default(obj) {
21
20
  if (!(0, _is["default"])(obj) && !(0, _is2["default"])(obj)) {
22
21
  throw new TypeError('Only objects can be sealed');
package/deep/set.js CHANGED
@@ -13,33 +13,27 @@ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread n
13
13
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
14
14
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
15
15
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
16
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
16
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
17
17
  function interpolatePath(path) {
18
18
  if (!(0, _isNotEmpty["default"])(path) && !(0, _is2["default"])(path)) throw new TypeError('No Path was given');
19
19
  if ((0, _is2["default"])(path)) return _toConsumableArray(path);
20
20
  return path.replace('[', '.').replace(']', '').split('.');
21
21
  }
22
-
23
22
  function _default(obj, path) {
24
23
  var value = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
25
24
  var define = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : !1;
26
25
  if (!(0, _is["default"])(obj) && !(0, _is2["default"])(obj)) throw new TypeError('Deepset is only supported for objects');
27
26
  var parts = interpolatePath(path);
28
-
29
27
  for (var i = 0; i < parts.length - 1; i++) {
30
28
  if (parts[i] === '') continue;
31
29
  if (!obj[parts[i]]) obj[parts[i]] = {};
32
-
33
30
  obj = obj[parts[i]];
34
-
35
31
  if (!(0, _is2["default"])(obj)) continue;
36
-
37
32
  if (i < parts.length - 2) {
38
33
  obj = obj[parts[i + 1]];
39
34
  i++;
40
35
  }
41
36
  }
42
-
43
37
  if (define) {
44
38
  Object.defineProperty(obj, parts[parts.length - 1], value);
45
39
  } else {
package/equal.js CHANGED
@@ -1,5 +1,4 @@
1
1
  'use strict';
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
3
  value: !0
5
4
  });
@@ -10,7 +9,6 @@ var _isNumericalNaN = _interopRequireDefault(require("./number/isNumericalNaN"))
10
9
  var _is3 = _interopRequireDefault(require("./regexp/is"));
11
10
  var _is4 = _interopRequireDefault(require("./date/is"));
12
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
-
14
12
  function isArrayEqual(a, b) {
15
13
  if (a.length !== b.length) return !1;
16
14
  for (var i = a.length - 1; i >= 0; i--) {
@@ -32,23 +30,18 @@ function equal(a, b) {
32
30
  if ((0, _is4["default"])(a) && (0, _is4["default"])(b)) {
33
31
  return a.valueOf() === b.valueOf();
34
32
  }
35
-
36
33
  if ((0, _is3["default"])(a) || (0, _is3["default"])(b)) {
37
34
  return String(a) === String(b);
38
35
  }
39
-
40
36
  if ((0, _is2["default"])(a) && (0, _is2["default"])(b)) {
41
37
  return isArrayEqual(a, b);
42
38
  }
43
-
44
39
  if ((0, _is["default"])(a) && (0, _is["default"])(b)) {
45
40
  return isObjectEqual(a, b);
46
41
  }
47
-
48
42
  if ((0, _isNumericalNaN["default"])(a)) {
49
43
  return (0, _isNumericalNaN["default"])(b);
50
44
  }
51
-
52
45
  return a === b;
53
46
  }
54
47
  var _default = equal;
package/function/is.js CHANGED
@@ -1,5 +1,4 @@
1
1
  'use strict';
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
3
  value: !0
5
4
  });
package/function/noop.js CHANGED
@@ -4,5 +4,4 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: !0
5
5
  });
6
6
  exports["default"] = _default;
7
- function _default() {
8
- }
7
+ function _default() {}
@@ -1,5 +1,4 @@
1
1
  'use strict';
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
3
  value: !0
5
4
  });
@@ -1,5 +1,4 @@
1
1
  'use strict';
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
3
  value: !0
5
4
  });
package/function/sleep.js CHANGED
@@ -1,5 +1,4 @@
1
1
  'use strict';
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
3
  value: !0
5
4
  });
package/hash/fnv1A.js CHANGED
@@ -1,5 +1,4 @@
1
1
  'use strict';
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
3
  value: !0
5
4
  });
@@ -12,14 +11,12 @@ var _is5 = _interopRequireDefault(require("../number/is"));
12
11
  var _isNumericalNaN = _interopRequireDefault(require("../number/isNumericalNaN"));
13
12
  var _is6 = _interopRequireDefault(require("../regexp/is"));
14
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
-
16
14
  var FNV_OFFSET_BASIS_32 = 2166136261;
17
15
  function _default() {
18
16
  var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
19
17
  var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : FNV_OFFSET_BASIS_32;
20
18
  var hash = offset;
21
19
  var sanitized_data = JSON.stringify(data);
22
-
23
20
  if ((0, _is["default"])(data)) {
24
21
  sanitized_data = data;
25
22
  } else if ((0, _is4["default"])(data) || (0, _is3["default"])(data)) {
@@ -33,14 +30,11 @@ function _default() {
33
30
  } else if ((0, _isNumericalNaN["default"])(data)) {
34
31
  sanitized_data = 'NaN';
35
32
  }
36
-
37
33
  if (sanitized_data === !1) {
38
34
  throw new TypeError('An FNVA1 Hash could not be calculated for this datatype');
39
35
  }
40
-
41
36
  for (var i = 0; i < sanitized_data.length; i++) {
42
37
  hash ^= sanitized_data.charCodeAt(i);
43
-
44
38
  hash += (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24);
45
39
  }
46
40
  return hash >>> 0;
package/hash/guid.js CHANGED
@@ -1,10 +1,8 @@
1
1
  'use strict';
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
3
  value: !0
5
4
  });
6
5
  exports["default"] = _default;
7
-
8
6
  var performance = !1;
9
7
  if (typeof window !== 'undefined' && (window.performance || {}).now) {
10
8
  performance = function performance() {
@@ -21,7 +19,6 @@ if (typeof window !== 'undefined' && (window.performance || {}).now) {
21
19
  }
22
20
  function _default() {
23
21
  var d = new Date().getTime();
24
-
25
22
  d += performance();
26
23
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
27
24
  var r = (d + Math.random() * 16) % 16 | 0;
@@ -1,10 +1,8 @@
1
1
  'use strict';
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
3
  value: !0
5
4
  });
6
5
  exports["default"] = _default;
7
-
8
6
  function _default(val) {
9
7
  return Number.isNaN(val) || val === Infinity || val === NaN;
10
8
  }
@@ -11,5 +11,5 @@ function _default() {
11
11
  var max = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
12
12
  if (!(0, _is["default"])(min)) throw new TypeError('Min should be numeric');
13
13
  if (!(0, _is["default"])(max)) throw new TypeError('Max should be numeric');
14
- return Math.random() * max + min;
14
+ return Math.random() * (max - min) + min;
15
15
  }
package/number/round.js CHANGED
@@ -10,7 +10,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
10
10
  function _default(val) {
11
11
  var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
12
12
  if (!(0, _is["default"])(val)) throw new TypeError('Value should be numeric');
13
-
14
13
  if (!(0, _isAbove["default"])(precision, 0)) return Math.round(val);
15
14
  var exp = Math.pow(10, Math.ceil(precision));
16
15
  return Math.round(val * exp) / exp;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valkyriestudios/utils",
3
- "version": "5.3.0",
3
+ "version": "5.4.0",
4
4
  "description": "A collection of single-function utilities for common tasks",
5
5
  "main": "index.js",
6
6
  "author": {
@@ -32,9 +32,9 @@
32
32
  },
33
33
  "homepage": "https://github.com/ValkyrieStudios/utils#readme",
34
34
  "devDependencies": {
35
- "@babel/core": "^7.20.2",
36
- "@babel/preset-env": "^7.20.2",
37
- "@babel/register": "^7.18.9",
35
+ "@babel/core": "^7.21.4",
36
+ "@babel/preset-env": "^7.21.4",
37
+ "@babel/register": "^7.21.0",
38
38
  "babel-plugin-check-es2015-constants": "^6.22.0",
39
39
  "babel-plugin-transform-member-expression-literals": "^6.9.4",
40
40
  "babel-plugin-transform-minify-booleans": "^6.9.4",
@@ -43,10 +43,10 @@
43
43
  "chai": "^4.3.7",
44
44
  "chai-as-promised": "^7.1.1",
45
45
  "chai-spies": "^1.0.0",
46
- "eslint": "^8.28.0",
46
+ "eslint": "^8.38.0",
47
47
  "gulp": "^4.0.2",
48
48
  "gulp-babel": "^8.0.0",
49
- "mocha": "^10.1.0",
49
+ "mocha": "^10.2.0",
50
50
  "nyc": "^15.1.0"
51
51
  }
52
52
  }
@@ -0,0 +1,40 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: !0
5
+ });
6
+ exports["default"] = humanizeBytes;
7
+ var _is = _interopRequireDefault(require("../number/is"));
8
+ var _isInteger = _interopRequireDefault(require("../number/isInteger"));
9
+ var _is2 = _interopRequireDefault(require("../string/is"));
10
+ var _isNotEmpty = _interopRequireDefault(require("../string/isNotEmpty"));
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
12
+ var units = [{
13
+ abbreviation: 'bytes'
14
+ }, {
15
+ abbreviation: 'KB'
16
+ }, {
17
+ abbreviation: 'MB'
18
+ }, {
19
+ abbreviation: 'GB'
20
+ }, {
21
+ abbreviation: 'TB'
22
+ }, {
23
+ abbreviation: 'PB'
24
+ }, {
25
+ abbreviation: 'EB'
26
+ }, {
27
+ abbreviation: 'ZB'
28
+ }, {
29
+ abbreviation: 'YB'
30
+ }];
31
+ function humanizeBytes(val) {
32
+ if (!((0, _is["default"])(val) || (0, _isNotEmpty["default"])(val))) return '0 bytes';
33
+ var n = parseInt((0, _is2["default"])(val) ? val.trim() : val) || 0;
34
+ if (!(0, _isInteger["default"])(n) || n === 0) return '0 bytes';
35
+ var sign = n < 0 ? '-' : '';
36
+ n = Math.abs(n);
37
+ var l = 0;
38
+ while (n >= 1024 && ++l && l < units.length) n = n / 1024;
39
+ return "".concat(sign).concat(n.toFixed(l > 0 ? 1 : 0), " ").concat(units[l].abbreviation);
40
+ }