@util.js/arrays 0.41.0 → 0.41.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Arrays.js CHANGED
@@ -1,31 +1,22 @@
1
1
  "use strict";
2
+
2
3
  /**
3
4
  * JavaScript utility methods for [arrays]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array}
4
5
  * @public
5
6
  * @class
6
7
  */
7
-
8
8
  var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
9
-
10
9
  var _from = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/from"));
11
-
12
10
  var _isArray = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array"));
13
-
14
11
  var _of = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/of"));
15
-
16
12
  var _sort = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/sort"));
17
-
18
13
  var _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice"));
19
-
20
14
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/classCallCheck"));
21
-
22
15
  var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/createClass"));
23
-
24
16
  var Arrays = /*#__PURE__*/function () {
25
17
  function Arrays() {
26
18
  (0, _classCallCheck2["default"])(this, Arrays);
27
19
  }
28
-
29
20
  (0, _createClass2["default"])(Arrays, [{
30
21
  key: "from",
31
22
  value:
@@ -45,6 +36,7 @@ var Arrays = /*#__PURE__*/function () {
45
36
  function from() {
46
37
  return _from["default"].apply(Array, arguments);
47
38
  }
39
+
48
40
  /**
49
41
  * Determines whether the passed value is an Array.
50
42
  *
@@ -56,12 +48,12 @@ var Arrays = /*#__PURE__*/function () {
56
48
  * @instance
57
49
  * @function
58
50
  */
59
-
60
51
  }, {
61
52
  key: "isArray",
62
53
  value: function isArray() {
63
54
  return _isArray["default"].apply(Array, arguments);
64
55
  }
56
+
65
57
  /**
66
58
  * Creates a new Array instance with a variable number of arguments, regardless of number or type of the arguments
67
59
  *
@@ -73,12 +65,12 @@ var Arrays = /*#__PURE__*/function () {
73
65
  * @instance
74
66
  * @function
75
67
  */
76
-
77
68
  }, {
78
69
  key: "of",
79
70
  value: function of() {
80
71
  return _of["default"].apply(Array, arguments);
81
72
  }
73
+
82
74
  /**
83
75
  * Shuffles the elements of the specified array.
84
76
  *
@@ -90,12 +82,12 @@ var Arrays = /*#__PURE__*/function () {
90
82
  * @instance
91
83
  * @function
92
84
  */
93
-
94
85
  }, {
95
86
  key: "shuffle",
96
87
  value: function shuffle(array) {
97
88
  return knuthshuffle().knuthShuffle(this.from(array));
98
89
  }
90
+
99
91
  /**
100
92
  * Sorts the elements of an array and (unlike returns a **new array** with the sorted elements. The default sort order is ascending, built upon converting the elements into strings, then comparing their sequences of UTF-16 code units values.
101
93
  *
@@ -107,24 +99,20 @@ var Arrays = /*#__PURE__*/function () {
107
99
  * @instance
108
100
  * @function
109
101
  */
110
-
111
102
  }, {
112
103
  key: "sort",
113
104
  value: function sort(array, compareFunction) {
114
105
  var _context;
115
-
116
106
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
117
107
  // https://stackoverflow.com/questions/9592740/how-can-you-sort-an-array-without-mutating-the-original-array
118
108
  // https://stackoverflow.com/a/9592755
119
- return (0, _sort["default"])(_context = (0, _slice["default"])(Array.prototype).call(arr)).call(_context, compareFunction);
109
+ return (0, _sort["default"])(_context = (0, _slice["default"])(Array.prototype).call(array)).call(_context, compareFunction);
120
110
  }
121
111
  }]);
122
112
  return Arrays;
123
113
  }();
124
-
125
114
  module.exports = Arrays;
126
115
  var dependencies = {};
127
-
128
116
  function knuthshuffle() {
129
117
  return dependencies["knuth-shuffle"] || (dependencies["knuth-shuffle"] = require("knuth-shuffle"));
130
118
  }
package/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
2
 
3
+ // eslint-disable-next-line no-var
3
4
  var Arrays = require("./dist/Arrays");
4
5
  module.exports = new Arrays();
package/lib/Arrays.js CHANGED
@@ -83,7 +83,7 @@ class Arrays {
83
83
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
84
84
  // https://stackoverflow.com/questions/9592740/how-can-you-sort-an-array-without-mutating-the-original-array
85
85
  // https://stackoverflow.com/a/9592755
86
- return Array.prototype.slice.call(arr).sort(compareFunction);
86
+ return Array.prototype.slice.call(array).sort(compareFunction);
87
87
  }
88
88
  }
89
89
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Chris Topher <c@creemama.com>",
3
3
  "dependencies": {
4
- "@babel/runtime-corejs3": "7.14.0",
4
+ "@babel/runtime-corejs3": "7.20.1",
5
5
  "knuth-shuffle": "1.0.8"
6
6
  },
7
7
  "dependencies-comments": [
@@ -30,6 +30,6 @@
30
30
  "type": "git",
31
31
  "url": "https://github.com/creemama/utiljs/tree/master/packages/utiljs-arrays"
32
32
  },
33
- "version": "0.41.0",
34
- "gitHead": "1ae0fda34e06ffbc546c5ba0025b0b59a0c7727d"
33
+ "version": "0.41.2",
34
+ "gitHead": "174b81ec0ead0221b9bb6617bc254b025bd20a5a"
35
35
  }
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
 
3
- const arrays = require(".."),
4
- { expect } = require("chai");
3
+ const arrays = require("..");
4
+ const { expect } = require("chai");
5
5
 
6
6
  describe("Arrays", () => {
7
7
  describe("#from", () => {
8
8
  it("should create a shallow copy", () => {
9
9
  const a = [1, 2, 3];
10
10
  const b = arrays.from(a);
11
- expect(b == a).to.be.false;
11
+ expect(b === a).to.be.false;
12
12
  expect(b[0]).to.eql(1);
13
13
  expect(b[1]).to.eql(2);
14
14
  expect(b[2]).to.eql(3);
@@ -20,11 +20,20 @@ describe("Arrays", () => {
20
20
  });
21
21
  });
22
22
 
23
+ describe("#sort", () => {
24
+ it("should sort an array", () => {
25
+ const a = [2, 1, 3];
26
+ const b = arrays.sort(a);
27
+ expect(b).to.not.eql(a);
28
+ expect(b).to.eql([1, 2, 3]);
29
+ });
30
+ });
31
+
23
32
  describe("#shuffle", () => {
24
33
  it("should shuffle array contents", () => {
25
34
  const a = [1, 2, 3];
26
35
  const b = arrays.shuffle(a);
27
- expect(b == a).to.be.false;
36
+ expect(b === a).to.be.false;
28
37
  expect(b.length).to.eql(3);
29
38
  // console.log(b)
30
39
  });