@valkyriestudios/utils 7.4.0 → 8.0.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 (124) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/README.md +9 -56
  3. package/array/dedupe.js +25 -12
  4. package/array/isNotEmpty.js +1 -4
  5. package/array/join.js +8 -10
  6. package/array/mapFn.js +7 -9
  7. package/array/mapKey.js +5 -6
  8. package/array/mapPrimitive.js +5 -7
  9. package/array/shuffle.js +1 -4
  10. package/array/sort.js +16 -16
  11. package/caching/memoize.js +1 -1
  12. package/date/addUTC.js +10 -6
  13. package/date/diff.js +3 -4
  14. package/date/endOfUTC.js +23 -16
  15. package/date/is.js +1 -1
  16. package/date/startOfUTC.js +23 -16
  17. package/date/toUTC.js +1 -3
  18. package/date/toUnix.js +1 -3
  19. package/deep/define.js +1 -1
  20. package/deep/freeze.js +8 -12
  21. package/deep/get.js +16 -18
  22. package/deep/seal.js +8 -12
  23. package/deep/set.js +6 -21
  24. package/equal.js +8 -19
  25. package/hash/fnv1A.js +35 -27
  26. package/is.js +33 -37
  27. package/number/is.js +1 -4
  28. package/number/isAbove.js +1 -5
  29. package/number/isAboveOrEqual.js +1 -5
  30. package/number/isBelow.js +1 -5
  31. package/number/isBelowOrEqual.js +1 -5
  32. package/number/isBetween.js +1 -4
  33. package/number/isInteger.js +0 -3
  34. package/number/isIntegerAbove.js +1 -6
  35. package/number/isIntegerAboveOrEqual.js +1 -6
  36. package/number/isIntegerBelow.js +1 -6
  37. package/number/isIntegerBelowOrEqual.js +1 -6
  38. package/number/isIntegerBetween.js +1 -5
  39. package/number/isNumericalNaN.js +2 -1
  40. package/number/randomBetween.js +1 -4
  41. package/number/randomIntBetween.js +1 -4
  42. package/number/round.js +2 -6
  43. package/number/toPercentage.js +2 -3
  44. package/object/define.js +3 -5
  45. package/object/is.js +3 -1
  46. package/object/isNotEmpty.js +2 -4
  47. package/object/merge.js +8 -12
  48. package/object/pick.js +16 -12
  49. package/package.json +15 -18
  50. package/regexp/is.js +3 -1
  51. package/regexp/sanitize.js +2 -2
  52. package/src/array/dedupe.js +24 -0
  53. package/src/array/is.js +5 -0
  54. package/src/array/isNotEmpty.js +5 -0
  55. package/src/array/join.js +31 -0
  56. package/src/array/mapFn.js +34 -0
  57. package/src/array/mapKey.js +29 -0
  58. package/src/array/mapPrimitive.js +29 -0
  59. package/src/array/shuffle.js +14 -0
  60. package/src/array/sort.js +100 -0
  61. package/src/boolean/is.js +5 -0
  62. package/src/caching/memoize.js +24 -0
  63. package/src/date/addUTC.js +67 -0
  64. package/src/date/diff.js +46 -0
  65. package/src/date/endOfUTC.js +130 -0
  66. package/src/date/is.js +5 -0
  67. package/src/date/nowUnix.js +5 -0
  68. package/src/date/nowUnixMs.js +5 -0
  69. package/src/date/startOfUTC.js +129 -0
  70. package/src/date/toUTC.js +17 -0
  71. package/src/date/toUnix.js +9 -0
  72. package/src/deep/define.js +7 -0
  73. package/src/deep/freeze.js +22 -0
  74. package/src/deep/get.js +47 -0
  75. package/src/deep/seal.js +22 -0
  76. package/src/deep/set.js +41 -0
  77. package/src/equal.js +67 -0
  78. package/src/function/is.js +6 -0
  79. package/src/function/noop.js +5 -0
  80. package/src/function/noopresolve.js +6 -0
  81. package/src/function/noopreturn.js +6 -0
  82. package/src/function/sleep.js +12 -0
  83. package/src/hash/fnv1A.js +58 -0
  84. package/src/hash/guid.js +38 -0
  85. package/src/is.js +86 -0
  86. package/src/number/is.js +5 -0
  87. package/src/number/isAbove.js +6 -0
  88. package/src/number/isAboveOrEqual.js +6 -0
  89. package/src/number/isBelow.js +6 -0
  90. package/src/number/isBelowOrEqual.js +6 -0
  91. package/src/number/isBetween.js +13 -0
  92. package/src/number/isInteger.js +5 -0
  93. package/src/number/isIntegerAbove.js +6 -0
  94. package/src/number/isIntegerAboveOrEqual.js +6 -0
  95. package/src/number/isIntegerBelow.js +6 -0
  96. package/src/number/isIntegerBelowOrEqual.js +6 -0
  97. package/src/number/isIntegerBetween.js +13 -0
  98. package/src/number/isNumericalNaN.js +5 -0
  99. package/src/number/randomBetween.js +11 -0
  100. package/src/number/randomIntBetween.js +11 -0
  101. package/src/number/round.js +10 -0
  102. package/src/number/toPercentage.js +14 -0
  103. package/src/object/define.js +12 -0
  104. package/src/object/is.js +7 -0
  105. package/src/object/isNotEmpty.js +7 -0
  106. package/src/object/merge.js +27 -0
  107. package/src/object/pick.js +33 -0
  108. package/src/regexp/is.js +7 -0
  109. package/src/regexp/sanitize.js +12 -0
  110. package/src/string/humanizeBytes.js +29 -0
  111. package/src/string/humanizeNumber.js +84 -0
  112. package/src/string/is.js +5 -0
  113. package/src/string/isBetween.js +18 -0
  114. package/src/string/isNotEmpty.js +6 -0
  115. package/src/string/shorten.js +21 -0
  116. package/string/humanizeBytes.js +9 -10
  117. package/string/humanizeNumber.js +21 -22
  118. package/string/isBetween.js +2 -3
  119. package/string/isNotEmpty.js +2 -4
  120. package/string/shorten.js +3 -4
  121. package/object/defineFrozen.js +0 -13
  122. package/object/defineSealed.js +0 -13
  123. package/object/forValues.js +0 -18
  124. package/object/zip.js +0 -19
package/CHANGELOG.md CHANGED
@@ -5,6 +5,76 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic
6
6
  Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [8.0.0] - 2023-11-29
9
+ ### Added
10
+ - Dev: Dep: c8\@8.0.1
11
+ - Dev: Internal benchmark script to produce ops/sec for close to all util functions
12
+ - date/startOfUTC: Add support for week_mon as mode (alias for week with monday as first day of the week)
13
+ - date/startOfUTC: Add support for week_tue as mode (tuesday as first day of the week)
14
+ - date/startOfUTC: Add support for week_wed as mode (wednesday as first day of the week)
15
+ - date/startOfUTC: Add support for week_thu as mode (thursday as first day of the week)
16
+ - date/startOfUTC: Add support for week_fri as mode (friday as first day of the week)
17
+ - date/startOfUTC: Add support for week_sat as mode (saturday as first day of the week)
18
+ - date/endOfUTC: Add support for week_mon as mode (alias for week with monday as first day of the week)
19
+ - date/endOfUTC: Add support for week_tue as mode (tuesday as first day of the week)
20
+ - date/endOfUTC: Add support for week_wed as mode (wednesday as first day of the week)
21
+ - date/endOfUTC: Add support for week_thu as mode (thursday as first day of the week)
22
+ - date/endOfUTC: Add support for week_fri as mode (friday as first day of the week)
23
+ - date/endOfUTC: Add support for week_sat as mode (saturday as first day of the week)
24
+
25
+ ### Improved
26
+ - Dev Dep: Upgrade @babel/cli to 7.23.4
27
+ - Switch from using chai/mocha to node native test runner
28
+ - hash/fnv1A: Improved performance thanks to predefined constants and reducing internal overhead regarding conversion
29
+ - array/dedupe: Improved performance due to replacement of filter and object map by for with native map
30
+ - deep/freeze: Improved performance due to replacement of forEach with native for
31
+ - deep/seal: Improved performance due to replacement of forEach with native for
32
+ - deep/get: Improved performance due to order change during path interpolation
33
+ - deep/set: Improved performance due to order change during path interpolation
34
+ - date/startOfUTC: Improved performance for start of week and quarter calculation due to improved internal handling
35
+ - date/endOfUTC: Improved performance for start of week and quarter calculation due to improved internal handling
36
+ - string/shorten: Will no longer return false but an empty string when passed a string that is empty after trimming
37
+ - string/isBetween: Will now validate that min and max are passed as above or equal to 0
38
+ - string/humanizeNumber Will now be magnitudes faster (50x) due to ditching usage of Intl for separator handling
39
+ - string/humanizeBytes: Will now be magnitudes faster (50x) due to ditching usage of Intl for separator handling
40
+ - object/pick: Will now throw when passed an empty array of keys
41
+ - object/pick: Will now be magnitudes faster (7x) if working with non-deep keys (eg: pick(obj, ['g.d', 'g.e']))
42
+ - object/merge: Will now throw when passed a non-object target and source (previously only non-object target)
43
+ - Performance improvements across a plethora of functions due to internal usage swaps in favor of Number.isFinite, Number.isInteger and Array.isArray leading to reduction of function calls andless Heap chatter
44
+ - Published package will now also include original src files which can be imported in @valkyriestudios/utils/src, this allows anyone wishing to use in esm format to do so
45
+
46
+ ### Breaking
47
+ - The usage of non-primitive number formats (eg: `new Number(...)`) will no longer be supported to allow for performance improvements during validity checks. This should not impact many people as the usage of numbers in that format has been discouraged for many years.
48
+
49
+ ### Fixed
50
+ - deep/set: Fix an issue where multiple runs of deepSet could throw errors when trying to assign a deeper value to a value that was previously set to a primitive
51
+ - deep/set: Fix an issue preventing building up of deep arrays using eg: deepSet({a: []}, 'a.0.name', 'Peter')
52
+ - deep/get: Fix an issue where deepGet would throw an error instead of returning undefined when diving into certain keys that don't exist on deep objects and arrays
53
+
54
+ ### Removed
55
+ - Dev Dep: babel-plugin-check-es2015-constants (as not needed)
56
+ - Dev Dep: babel-plugin-transform-member-expression-literals (as not needed)
57
+ - Dev Dep: babel-plugin-transform-property-literals (as not needed)
58
+ - Dev Dep: chai (in favor of native node test runner)
59
+ - Dev Dep: chai-as-promised (in favor of native node test runner)
60
+ - Dev Dep: chai-spies (in favor of native node test runner)
61
+ - Dev Dep: mocha (in favor of native node test runner)
62
+ - Dev Dep: nyc (in favor of native node test runner in combination with c8)
63
+ - object/defineFrozen: As these worked on a pass-by-reference and if misunderstood could have certain unwanted side-effects
64
+ - object/defineSealed: As these worked on a pass-by-reference and if misunderstood could have certain unwanted side-effects
65
+ - object/zip
66
+ - object/forValues
67
+
68
+ ## [7.5.0] - 2023-10-22
69
+ ### Improved
70
+ - Dep: Upgrade @babel/cli to 7.23.0
71
+ - Dep: Upgrade @babel/core to 7.23.2
72
+ - Dep: Upgrade @babel/preset-env to 7.23.2
73
+ - Dep: Upgrade @babel/register to 7.22.15
74
+ - Dep: Upgrade chai to 4.3.10
75
+ - Dep: Upgrade eslint to 8.52.0
76
+ - date/addUTC now supports millisecond/milliseconds as keys
77
+
8
78
  ## [7.4.0] - 2023-08-10
9
79
  ### Added
10
80
  - regexp/sanitize
package/README.md CHANGED
@@ -47,7 +47,7 @@ output:
47
47
 
48
48
  Autofilters anything not meeting the spec:
49
49
  ```js
50
- [
50
+ mapKey([
51
51
  0,
52
52
  {uid: 12, name: 'Peter'},
53
53
  false,
@@ -71,7 +71,7 @@ output:
71
71
 
72
72
  allows merging objects onto existing keys:
73
73
  ```js
74
- [
74
+ mapKey([
75
75
  0,
76
76
  {uid: 12, name: 'Peter'},
77
77
  false,
@@ -104,7 +104,7 @@ mapFn([
104
104
  {uid: 12, name: 'Peter'},
105
105
  {uid: 15, name: 'Jonas'},
106
106
  {uid: 87, name: 'Josh'},
107
- ], el => el.uid))
107
+ ], el => el.uid)
108
108
 
109
109
  output:
110
110
 
@@ -349,7 +349,7 @@ endOfUTC(new Date("2023-05-04T12:04:27.043+02:00"), 'second'); // new Date("2023
349
349
  ```
350
350
 
351
351
  - **addUTC(val:Date, amount:integer, key:String)**
352
- Take the incoming date and add a certain amount of the passed key. Possible key options(year,years,month,months,day,days,hour,hours,minute,minutes,second,seconds).
352
+ Take the incoming date and add a certain amount of the passed key. Possible key options(year,years,month,months,day,days,hour,hours,minute,minutes,second,seconds,millisecond,milliseconds).
353
353
 
354
354
  Note: Does not touch the date object passed
355
355
  ```js
@@ -412,7 +412,7 @@ Sets a property and its value deep in the structure of an object
412
412
  ```js
413
413
  const myObj = {
414
414
  a: 2,
415
- });
415
+ };
416
416
  deepSet(myObj, 'b.c.d.e', 4);
417
417
  myObj.b.c.d.e; // 4
418
418
  ```
@@ -424,7 +424,7 @@ const myObj = {
424
424
  { price : 2 },
425
425
  { price : 4 },
426
426
  ],
427
- });
427
+ };
428
428
  deepSet(myObj, 'b[0].price', 100);
429
429
  deepSet(myObj, 'b[1].price', 500);
430
430
  myObj.b[0].price; // 100
@@ -434,7 +434,7 @@ myObj.b[1].price; // 500
434
434
  ```js
435
435
  const myObj = {
436
436
  a: 2,
437
- });
437
+ };
438
438
  deepSet(myObj, 'b.c', { value: function () => {...} }, true);
439
439
  myObj.b.c; // Function
440
440
  ```
@@ -448,7 +448,7 @@ const myObj = {
448
448
  { price : 2 },
449
449
  { price : 4 },
450
450
  ],
451
- });
451
+ };
452
452
  deepGet(myObj, 'b[0].price', true); // [{price: 2}, {price: 4}]
453
453
  ```
454
454
 
@@ -459,7 +459,7 @@ const myObj = {
459
459
  { price : 2 },
460
460
  { price : 4 },
461
461
  ],
462
- });
462
+ };
463
463
  deepGet(myObj, 'b[0].price'); // 2
464
464
  ```
465
465
 
@@ -659,13 +659,6 @@ randomIntBetween(25, 100); // Will generate a random between 25 and 100 (100 not
659
659
  ```
660
660
 
661
661
  ### object
662
- - **forValues(obj:Object={}, cb:Function=noopreturn)**
663
- Iterate over the keys of the object and apply the callback function to their values
664
- ```js
665
- const obj = {a: 1, b: 2, c: 3};
666
- forValues(obj, (key, value, index) => value + 1); // {a: 2, b:3, c:4}
667
- ```
668
-
669
662
  - **isObject(val:any)**
670
663
  Check if a variable is of type Object
671
664
  ```js
@@ -694,20 +687,6 @@ Merges two objects together, with the preference over the second object.
694
687
  merge({a: 1, b: false}, {a: 900, c: 50}); // {a: 900, b: false, c: 50}
695
688
  ```
696
689
 
697
- - **zip(keys:Array[string]=[], values:Array[string]=[], default_to:any=null)**
698
- Creates an object from a keys and a values array. Mapping them together.
699
- ```js
700
- zip(['a', 'b'], [100, 200]); // {a: 100, b: 200}
701
- ```
702
-
703
- ```js
704
- zip(['a','b']); // {a: null, b: null}
705
- ```
706
-
707
- ```js
708
- zip(['a','b', false, 9999]); // {a: 9999, b: 9999}
709
- ```
710
-
711
690
  - **define(props:Object, obj:Object={})**
712
691
  Creates an object with the passed accessors set on it
713
692
  ```js
@@ -732,32 +711,6 @@ define({
732
711
  }); // { a : () => ... }
733
712
  ```
734
713
 
735
- - **defineFrozen(props:Object, obj:Object={})**
736
- Creates an object with the passed accessors set on it, and returns it as a frozen object
737
- ```js
738
- const myObject = defineFrozen({
739
- a : {
740
- enumerable: false,
741
- value : function () { ... }
742
- }
743
- );
744
- myObject; // { a : () => ... }
745
- Object.isFrozen(myObject); // TRUE
746
- ```
747
-
748
- - **defineSealed(props:Object, obj:Object={})**
749
- Creates an object with the passed accessors set on it, and returns it as a sealed object
750
- ```js
751
- const myObject = defineSealed({
752
- a : {
753
- enumerable: false,
754
- value : function () { ... }
755
- }
756
- );
757
- myObject; // { a : () => ... }
758
- Object.isSealed(myObject); // TRUE
759
- ```
760
-
761
714
  ### regexp
762
715
  - **isRegExp(val:any)**
763
716
  Check if a variable is an instance of RegExp
package/array/dedupe.js CHANGED
@@ -4,17 +4,30 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: !0
5
5
  });
6
6
  exports["default"] = dedupe;
7
- var _fnv1A = _interopRequireDefault(require("../hash/fnv1A"));
8
- var _isNotEmpty = _interopRequireDefault(require("./isNotEmpty"));
7
+ var _fnv1A = _interopRequireDefault(require("../hash/fnv1A.js"));
9
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
- function dedupe() {
11
- var val = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
12
- if (!(0, _isNotEmpty["default"])(val)) return [];
13
- var seen = {};
14
- return val.filter(function (item) {
15
- var hash = (0, _fnv1A["default"])(item);
16
- if (Object.prototype.hasOwnProperty.call(seen, hash)) return !1;
17
- seen[hash] = !0;
18
- return !0;
19
- });
9
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: !0 }; return { done: !1, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = !0, didErr = !1, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = !0; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
10
+ 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); }
11
+ 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; }
12
+ function dedupe(val) {
13
+ if (!Array.isArray(val) || val.length === 0) return [];
14
+ var map = new Map();
15
+ var acc = [];
16
+ var hash;
17
+ var _iterator = _createForOfIteratorHelper(val),
18
+ _step;
19
+ try {
20
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
21
+ var item = _step.value;
22
+ hash = (0, _fnv1A["default"])(item);
23
+ if (map.has(hash)) continue;
24
+ map.set(hash, !0);
25
+ acc.push(item);
26
+ }
27
+ } catch (err) {
28
+ _iterator.e(err);
29
+ } finally {
30
+ _iterator.f();
31
+ }
32
+ return acc;
20
33
  }
@@ -4,9 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: !0
5
5
  });
6
6
  exports["default"] = isNotEmptyArray;
7
- var _is = _interopRequireDefault(require("./is"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
7
  function isNotEmptyArray(val) {
10
- if (!(0, _is["default"])(val)) return !1;
11
- return val.length !== 0;
8
+ return Array.isArray(val) && val.length !== 0;
12
9
  }
package/array/join.js CHANGED
@@ -4,34 +4,32 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: !0
5
5
  });
6
6
  exports["default"] = join;
7
- var _isNotEmpty = _interopRequireDefault(require("./isNotEmpty"));
8
- var _isNotEmpty2 = _interopRequireDefault(require("../string/isNotEmpty"));
9
- var _is = _interopRequireDefault(require("../number/is"));
10
- var _isNotEmpty3 = _interopRequireDefault(require("../object/isNotEmpty"));
11
- var _round = _interopRequireDefault(require("../number/round"));
7
+ var _isNotEmpty = _interopRequireDefault(require("../string/isNotEmpty.js"));
8
+ var _isNotEmpty2 = _interopRequireDefault(require("../object/isNotEmpty.js"));
9
+ var _round = _interopRequireDefault(require("../number/round.js"));
12
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
11
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: !0 }; return { done: !1, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = !0, didErr = !1, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = !0; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
14
12
  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); }
15
13
  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
14
  function join(arr) {
17
15
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
18
- if (!(0, _isNotEmpty["default"])(arr)) return '';
16
+ if (!Array.isArray(arr) || arr.length === 0) return '';
19
17
  var OPTS = Object.assign({
20
18
  delim: ' ',
21
19
  trim: !0,
22
20
  valtrim: !0,
23
21
  valround: !1
24
- }, (0, _isNotEmpty3["default"])(options) ? options : {});
22
+ }, (0, _isNotEmpty2["default"])(options) ? options : {});
25
23
  var filtered = [];
26
24
  var _iterator = _createForOfIteratorHelper(arr),
27
25
  _step;
28
26
  try {
29
27
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
30
28
  var el = _step.value;
31
- if ((0, _isNotEmpty2["default"])(el)) {
29
+ if ((0, _isNotEmpty["default"])(el)) {
32
30
  filtered.push(OPTS.valtrim === !0 ? el.trim() : el);
33
- } else if ((0, _is["default"])(el)) {
34
- filtered.push((0, _is["default"])(OPTS.valround) ? (0, _round["default"])(el, OPTS.valround) : el);
31
+ } else if (Number.isFinite(el)) {
32
+ filtered.push(Number.isFinite(OPTS.valround) ? (0, _round["default"])(el, OPTS.valround) : el);
35
33
  }
36
34
  }
37
35
  } catch (err) {
package/array/mapFn.js CHANGED
@@ -4,21 +4,19 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: !0
5
5
  });
6
6
  exports["default"] = mapFn;
7
- var _is = _interopRequireDefault(require("../object/is"));
8
- var _isNotEmpty = _interopRequireDefault(require("./isNotEmpty"));
9
- var _is2 = _interopRequireDefault(require("../function/is"));
10
- var _isNotEmpty2 = _interopRequireDefault(require("../string/isNotEmpty"));
11
- var _is3 = _interopRequireDefault(require("../number/is"));
7
+ var _is = _interopRequireDefault(require("../function/is.js"));
8
+ var _isNotEmpty = _interopRequireDefault(require("../string/isNotEmpty.js"));
9
+ var _is2 = require("../object/is.js");
12
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
11
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: !0 }; return { done: !1, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = !0, didErr = !1, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = !0; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
14
12
  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); }
15
13
  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
14
  function mapFn(arr, fn) {
17
15
  var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
18
- if (!(0, _isNotEmpty["default"])(arr) || !(0, _is2["default"])(fn)) return {};
16
+ if (!Array.isArray(arr) || arr.length === 0 || !(0, _is["default"])(fn)) return {};
19
17
  var OPTS = Object.assign({
20
18
  merge: !1
21
- }, (0, _is["default"])(opts) ? opts : {});
19
+ }, Object.prototype.toString.call(opts) === _is2.PROTO_OBJ ? opts : {});
22
20
  var map = {};
23
21
  var hash = !1;
24
22
  var _iterator = _createForOfIteratorHelper(arr),
@@ -26,9 +24,9 @@ function mapFn(arr, fn) {
26
24
  try {
27
25
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
28
26
  var el = _step.value;
29
- if (!(0, _is["default"])(el)) continue;
27
+ if (Object.prototype.toString.call(el) !== _is2.PROTO_OBJ) continue;
30
28
  hash = fn(el);
31
- if (!(0, _is3["default"])(hash) && !(0, _isNotEmpty2["default"])(hash)) continue;
29
+ if (!Number.isFinite(hash) && !(0, _isNotEmpty["default"])(hash)) continue;
32
30
  if (OPTS.merge === !0 && map.hasOwnProperty(hash)) {
33
31
  map[hash] = Object.assign(map[hash], el);
34
32
  } else {
package/array/mapKey.js CHANGED
@@ -4,26 +4,25 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: !0
5
5
  });
6
6
  exports["default"] = mapKey;
7
- var _is = _interopRequireDefault(require("../object/is"));
8
- var _isNotEmpty = _interopRequireDefault(require("./isNotEmpty"));
9
- var _isNotEmpty2 = _interopRequireDefault(require("../string/isNotEmpty"));
7
+ var _isNotEmpty = _interopRequireDefault(require("../string/isNotEmpty.js"));
8
+ var _is = require("../object/is.js");
10
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
10
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: !0 }; return { done: !1, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = !0, didErr = !1, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = !0; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
12
11
  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); }
13
12
  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; }
14
13
  function mapKey(arr, key) {
15
14
  var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
16
- if (!(0, _isNotEmpty["default"])(arr) || !(0, _isNotEmpty2["default"])(key)) return {};
15
+ if (!Array.isArray(arr) || arr.length === 0 || !(0, _isNotEmpty["default"])(key)) return {};
17
16
  var OPTS = Object.assign({
18
17
  merge: !1
19
- }, (0, _is["default"])(opts) ? opts : {});
18
+ }, Object.prototype.toString.call(opts) === _is.PROTO_OBJ ? opts : {});
20
19
  var map = {};
21
20
  var _iterator = _createForOfIteratorHelper(arr),
22
21
  _step;
23
22
  try {
24
23
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
25
24
  var el = _step.value;
26
- if (!(0, _is["default"])(el) || !el.hasOwnProperty(key)) continue;
25
+ if (Object.prototype.toString.call(el) !== _is.PROTO_OBJ || !el.hasOwnProperty(key)) continue;
27
26
  if (OPTS.merge === !0 && map.hasOwnProperty(el[key])) {
28
27
  map[el[key]] = Object.assign(map[el[key]], el);
29
28
  } else {
@@ -4,29 +4,27 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: !0
5
5
  });
6
6
  exports["default"] = mapPrimitive;
7
- var _is = _interopRequireDefault(require("../number/is"));
8
- var _isNotEmpty = _interopRequireDefault(require("../string/isNotEmpty"));
9
- var _isNotEmpty2 = _interopRequireDefault(require("./isNotEmpty"));
10
- var _isNotEmpty3 = _interopRequireDefault(require("../object/isNotEmpty"));
7
+ var _isNotEmpty = _interopRequireDefault(require("../string/isNotEmpty.js"));
8
+ var _isNotEmpty2 = _interopRequireDefault(require("../object/isNotEmpty.js"));
11
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
12
10
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: !0 }; return { done: !1, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = !0, didErr = !1, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = !0; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
13
11
  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
12
  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; }
15
13
  function mapPrimitive(arr) {
16
14
  var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
17
- if (!(0, _isNotEmpty2["default"])(arr)) return {};
15
+ if (!Array.isArray(arr) || arr.length === 0) return {};
18
16
  var OPTS = Object.assign({
19
17
  valtrim: !1,
20
18
  keyround: !1,
21
19
  valround: !1
22
- }, (0, _isNotEmpty3["default"])(opts) ? opts : {});
20
+ }, (0, _isNotEmpty2["default"])(opts) ? opts : {});
23
21
  var map = {};
24
22
  var _iterator = _createForOfIteratorHelper(arr),
25
23
  _step;
26
24
  try {
27
25
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
28
26
  var el = _step.value;
29
- if ((0, _is["default"])(el)) {
27
+ if (Number.isFinite(el)) {
30
28
  if (OPTS.keyround === !0) {
31
29
  map[Math.round(el)] = OPTS.valround ? Math.round(el) : el;
32
30
  } else {
package/array/shuffle.js CHANGED
@@ -1,13 +1,10 @@
1
1
  'use strict';
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
3
  value: !0
5
4
  });
6
5
  exports["default"] = shuffle;
7
- var _isNotEmpty = _interopRequireDefault(require("./isNotEmpty"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
6
  function shuffle(arr) {
10
- if (!(0, _isNotEmpty["default"])(arr)) return;
7
+ if (!Array.isArray(arr) || arr.length === 0) return;
11
8
  for (var i = arr.length - 1; i > 0; i--) {
12
9
  var j = Math.floor(Math.random() * (i + 1));
13
10
  var _ref = [arr[j], arr[i]];
package/array/sort.js CHANGED
@@ -4,12 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: !0
5
5
  });
6
6
  exports["default"] = sort;
7
- var _is = _interopRequireDefault(require("../boolean/is"));
8
- var _isNotEmpty = _interopRequireDefault(require("./isNotEmpty"));
9
- var _is2 = _interopRequireDefault(require("../object/is"));
10
- var _isNotEmpty2 = _interopRequireDefault(require("../object/isNotEmpty"));
11
- var _isNotEmpty3 = _interopRequireDefault(require("../string/isNotEmpty"));
12
- var _is3 = _interopRequireDefault(require("../function/is"));
7
+ var _is = _interopRequireDefault(require("../boolean/is.js"));
8
+ var _isNotEmpty = _interopRequireDefault(require("../object/isNotEmpty.js"));
9
+ var _is2 = require("../object/is.js");
10
+ var _isNotEmpty2 = _interopRequireDefault(require("../string/isNotEmpty.js"));
11
+ var _is3 = _interopRequireDefault(require("../function/is.js"));
13
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
14
13
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
15
14
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -19,12 +18,12 @@ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol
19
18
  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); }
20
19
  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; }
21
20
  function partition(arr, start_ix, end_ix) {
22
- var pivotVal = arr[Math.floor((start_ix + end_ix) / 2)].t;
21
+ var pivot_val = arr[Math.floor((start_ix + end_ix) / 2)].t;
23
22
  while (start_ix <= end_ix) {
24
- while (arr[start_ix].t < pivotVal) {
23
+ while (arr[start_ix].t < pivot_val) {
25
24
  start_ix++;
26
25
  }
27
- while (arr[end_ix].t > pivotVal) {
26
+ while (arr[end_ix].t > pivot_val) {
28
27
  end_ix--;
29
28
  }
30
29
  if (start_ix <= end_ix) {
@@ -50,17 +49,18 @@ function quickSort(arr) {
50
49
  function sort(arr, by) {
51
50
  var dir = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'asc';
52
51
  var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
53
- if (!(0, _isNotEmpty["default"])(arr)) return [];
54
- if (!(0, _isNotEmpty3["default"])(by) && !(0, _is3["default"])(by)) throw new Error('Sort by should be either a string or a function');
55
- if (dir !== 'asc' && dir !== 'desc') throw new Error('dir should be either asc or desc');
52
+ if (!Array.isArray(arr) || arr.length === 0) return [];
53
+ if (!(0, _isNotEmpty2["default"])(by) && !(0, _is3["default"])(by)) throw new Error('Sort by should be either a string or a function');
54
+ if (dir !== 'asc' && dir !== 'desc') throw new Error('Direction should be either asc or desc');
55
+ var has_opts = Object.prototype.toString.call(options) === _is2.PROTO_OBJ;
56
56
  var OPTS = {
57
- filter_fn: (0, _is2["default"])(options) && (0, _is3["default"])(options.filter_fn) ? options.filter_fn : _isNotEmpty2["default"],
58
- nokey_hide: (0, _is2["default"])(options) && (0, _is["default"])(options.nokey_hide) ? options.nokey_hide : !1,
59
- nokey_atend: (0, _is2["default"])(options) && (0, _is["default"])(options.nokey_atend) ? options.nokey_atend : !0
57
+ filter_fn: has_opts && (0, _is3["default"])(options.filter_fn) ? options.filter_fn : _isNotEmpty["default"],
58
+ nokey_hide: has_opts && (0, _is["default"])(options.nokey_hide) ? options.nokey_hide : !1,
59
+ nokey_atend: has_opts && (0, _is["default"])(options.nokey_atend) ? options.nokey_atend : !0
60
60
  };
61
61
  var prepared_arr = [];
62
62
  var nokey_arr = [];
63
- if ((0, _isNotEmpty3["default"])(by)) {
63
+ if ((0, _isNotEmpty2["default"])(by)) {
64
64
  var _iterator = _createForOfIteratorHelper(arr),
65
65
  _step;
66
66
  try {
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: !0
5
5
  });
6
6
  exports["default"] = memoize;
7
- var _is = _interopRequireDefault(require("../function/is"));
7
+ var _is = _interopRequireDefault(require("../function/is.js"));
8
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
9
  function memoize(fn) {
10
10
  var resolver = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : !1;
package/date/addUTC.js CHANGED
@@ -4,14 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: !0
5
5
  });
6
6
  exports["default"] = addUTC;
7
- var _is = _interopRequireDefault(require("./is"));
8
- var _isInteger = _interopRequireDefault(require("../number/isInteger"));
9
- var _isNotEmpty = _interopRequireDefault(require("../string/isNotEmpty"));
7
+ var _isNotEmpty = _interopRequireDefault(require("../string/isNotEmpty.js"));
10
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
9
  function addUTC(val, amount, key) {
12
- if (!(0, _is["default"])(val)) throw new Error('Date To UTC requires a date object');
13
- if (!(0, _isInteger["default"])(amount)) throw new Error('Amount needs to be an integer');
14
- if (!(0, _isNotEmpty["default"])(key)) throw new Error('Key needs to be a string with content');
10
+ if (!(val instanceof Date)) throw new TypeError('addUTC requires a date object');
11
+ if (!Number.isInteger(amount)) throw new TypeError('Amount needs to be an integer');
12
+ if (!(0, _isNotEmpty["default"])(key)) throw new TypeError('Key needs to be a string with content');
15
13
  var copy = new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate(), val.getUTCHours(), val.getUTCMinutes(), val.getUTCSeconds(), val.getUTCMilliseconds()));
16
14
  switch (key) {
17
15
  case 'years':
@@ -50,6 +48,12 @@ function addUTC(val, amount, key) {
50
48
  copy.setUTCSeconds(copy.getUTCSeconds() + amount);
51
49
  return copy;
52
50
  }
51
+ case 'milliseconds':
52
+ case 'millisecond':
53
+ {
54
+ copy.setUTCMilliseconds(copy.getUTCMilliseconds() + amount);
55
+ return copy;
56
+ }
53
57
  default:
54
58
  return copy;
55
59
  }
package/date/diff.js CHANGED
@@ -4,8 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: !0
5
5
  });
6
6
  exports["default"] = diff;
7
- var _is = _interopRequireDefault(require("./is"));
8
- var _isNotEmpty = _interopRequireDefault(require("../string/isNotEmpty"));
7
+ var _isNotEmpty = _interopRequireDefault(require("../string/isNotEmpty.js"));
9
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
9
  var SECOND_IN_MILLISECONDS = 1000;
11
10
  var MINUTE_IN_MILLISECONDS = SECOND_IN_MILLISECONDS * 60;
@@ -14,8 +13,8 @@ var DAY_IN_MILLISECONDS = HOUR_IN_MILLISECONDS * 24;
14
13
  var WEEK_IN_MILLISECONDS = DAY_IN_MILLISECONDS * 7;
15
14
  function diff(val_a, val_b) {
16
15
  var key = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : !1;
17
- if (!(0, _is["default"])(val_a) || !(0, _is["default"])(val_b)) throw new Error('Diff requires date objects for both values');
18
- if (key !== !1 && !(0, _isNotEmpty["default"])(key)) throw new Error('Key needs to be a string or false');
16
+ if (!(val_a instanceof Date) || !(val_b instanceof Date)) throw new TypeError('Diff requires date objects for both values');
17
+ if (key !== !1 && !(0, _isNotEmpty["default"])(key)) throw new TypeError('Key needs to be a string or false');
19
18
  var diff_in_ms = val_a.valueOf() - val_b.valueOf();
20
19
  switch (key) {
21
20
  case 'week':
package/date/endOfUTC.js CHANGED
@@ -4,35 +4,42 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: !0
5
5
  });
6
6
  exports["default"] = endOfUTC;
7
- var _is = _interopRequireDefault(require("./is"));
8
- var _isNotEmpty = _interopRequireDefault(require("../string/isNotEmpty"));
7
+ var _isNotEmpty = _interopRequireDefault(require("../string/isNotEmpty.js"));
9
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
+ var WEEK_END = {
10
+ week: 0,
11
+ week_sun: 6,
12
+ week_mon: 0,
13
+ week_tue: 1,
14
+ week_wed: 2,
15
+ week_thu: 3,
16
+ week_fri: 4,
17
+ week_sat: 5
18
+ };
10
19
  function endOfUTC(val, key) {
11
- if (!(0, _is["default"])(val)) throw new Error('Date To UTC requires a date object');
12
- if (!(0, _isNotEmpty["default"])(key)) throw new Error('Key needs to be a string with content');
20
+ if (!(val instanceof Date)) throw new TypeError('endOfUTC requires a date object');
21
+ if (!(0, _isNotEmpty["default"])(key)) throw new TypeError('Key needs to be a string with content');
13
22
  switch (key) {
14
23
  case 'year':
15
24
  return new Date(Date.UTC(val.getUTCFullYear(), 11, 31, 23, 59, 59, 999));
16
25
  case 'quarter':
17
26
  {
18
- var new_quarter = val.getUTCMonth() - val.getUTCMonth() % 3;
19
- return new Date(Date.UTC(val.getUTCFullYear(), new_quarter >= 0 ? new_quarter + 3 : 3, 0, 23, 59, 59, 999));
27
+ return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth() - val.getUTCMonth() % 3 + 3, 0, 23, 59, 59, 999));
20
28
  }
21
29
  case 'month':
22
30
  return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth() + 1, 0, 23, 59, 59, 999));
23
31
  case 'week':
24
- {
25
- var date = new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate(), 23, 59, 59, 999));
26
- var day = date.getUTCDay();
27
- if (day !== 0) date.setUTCDate(date.getUTCDate() + (7 - day));
28
- return date;
29
- }
30
32
  case 'week_sun':
33
+ case 'week_mon':
34
+ case 'week_tue':
35
+ case 'week_wed':
36
+ case 'week_thu':
37
+ case 'week_fri':
38
+ case 'week_sat':
31
39
  {
32
- var _date = new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate(), 23, 59, 59, 999));
33
- var _day = _date.getUTCDay();
34
- if (_day !== 6) _date.setUTCDate(_date.getUTCDate() + (6 - _day));
35
- return _date;
40
+ var UTC_DAY = val.getUTCDay();
41
+ var UTC_EOD = WEEK_END[key];
42
+ return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate() + (UTC_DAY <= UTC_EOD ? UTC_EOD - UTC_DAY : 7 - UTC_DAY + UTC_EOD), 23, 59, 59, 999));
36
43
  }
37
44
  case 'day':
38
45
  return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate(), 23, 59, 59, 999));