@util.js/arrays 0.41.5 → 0.41.7

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/package.json CHANGED
@@ -9,6 +9,10 @@
9
9
  "work in https://npm.runkit.com."
10
10
  ],
11
11
  "description": "JavaScript utility methods for arrays",
12
+ "files": [
13
+ "dist",
14
+ "index.js"
15
+ ],
12
16
  "keywords": [
13
17
  "array",
14
18
  "arrays",
@@ -30,5 +34,5 @@
30
34
  "type": "git",
31
35
  "url": "https://github.com/creemama/utiljs/tree/master/packages/utiljs-arrays"
32
36
  },
33
- "version": "0.41.5"
37
+ "version": "0.41.7"
34
38
  }
package/lib/Arrays.js DELETED
@@ -1,99 +0,0 @@
1
- "use strict";
2
-
3
- /**
4
- * JavaScript utility methods for [arrays]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array}
5
- * @public
6
- * @class
7
- */
8
- class Arrays {
9
- /**
10
- * Creates a new, shallow-copied Array instance from an array-like or iterable object.
11
- *
12
- * See MDN's documentation about [from]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from}.
13
- *
14
- * @param arrayLike An array-like or iterable object to convert to an array
15
- * @param {Function} [mapFn] Map function to call on every element of the array
16
- * @param {Object} [thisArg] Value to use as this when executing mapFn
17
- * @return {Array} A new Array instance
18
- * @public
19
- * @instance
20
- * @function
21
- */
22
- from() {
23
- return Array.from(...arguments);
24
- }
25
-
26
- /**
27
- * Determines whether the passed value is an Array.
28
- *
29
- * See MDN's documentation about [isArray]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray}.
30
- *
31
- * @param {*} obj The object to be checked
32
- * @return {boolean} true if the object is an Array or false otherwise
33
- * @public
34
- * @instance
35
- * @function
36
- */
37
- isArray() {
38
- return Array.isArray(...arguments);
39
- }
40
-
41
- /**
42
- * Creates a new Array instance with a variable number of arguments, regardless of number or type of the arguments
43
- *
44
- * See MDN's documentation about [of]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of}.
45
- *
46
- * @param {...*} elementN Elements of which to create the array
47
- * @return {Array} A new Array instance
48
- * @public
49
- * @instance
50
- * @function
51
- */
52
- of() {
53
- return Array.of(...arguments);
54
- }
55
-
56
- /**
57
- * Shuffles the elements of the specified array.
58
- *
59
- * See [knuth-shuffle]{@link https://www.npmjs.com/package/knuth-shuffle}.
60
- *
61
- * @param {Array} array The array to shuffle
62
- * @return {Array} A new Array instance
63
- * @public
64
- * @instance
65
- * @function
66
- */
67
- shuffle(array) {
68
- return knuthshuffle().knuthShuffle(this.from(array));
69
- }
70
-
71
- /**
72
- * 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.
73
- *
74
- * See [knuth-shuffle]{@link https://www.npmjs.com/package/knuth-shuffle}.
75
- *
76
- * @param {Array} array The array to shuffle
77
- * @return {Array} A new Array instance
78
- * @public
79
- * @instance
80
- * @function
81
- */
82
- sort(array, compareFunction) {
83
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
84
- // https://stackoverflow.com/questions/9592740/how-can-you-sort-an-array-without-mutating-the-original-array
85
- // https://stackoverflow.com/a/9592755
86
- return Array.prototype.slice.call(array).sort(compareFunction);
87
- }
88
- }
89
-
90
- module.exports = Arrays;
91
-
92
- const dependencies = {};
93
-
94
- function knuthshuffle() {
95
- return (
96
- dependencies["knuth-shuffle"] ||
97
- (dependencies["knuth-shuffle"] = require("knuth-shuffle"))
98
- );
99
- }
@@ -1,45 +0,0 @@
1
- "use strict";
2
-
3
- const arrays = require("..");
4
- const { expect } = require("chai");
5
-
6
- describe("Arrays", () => {
7
- describe("#from", () => {
8
- it("should create a shallow copy", () => {
9
- const a = [1, 2, 3];
10
- const b = arrays.from(a);
11
- expect(b === a).to.be.false;
12
- expect(b[0]).to.eql(1);
13
- expect(b[1]).to.eql(2);
14
- expect(b[2]).to.eql(3);
15
- expect(b.length).to.eql(3);
16
- });
17
- it("should throw an error an undefined or null input", () => {
18
- expect(() => arrays.from()).to.throw(Error);
19
- expect(() => arrays.from(null)).to.throw(Error);
20
- });
21
- });
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
-
32
- describe("#shuffle", () => {
33
- it("should shuffle array contents", () => {
34
- const a = [1, 2, 3];
35
- const b = arrays.shuffle(a);
36
- expect(b === a).to.be.false;
37
- expect(b.length).to.eql(3);
38
- // console.log(b)
39
- });
40
- it("should throw an error an undefined or null input", () => {
41
- expect(() => arrays.shuffle()).to.throw(Error);
42
- expect(() => arrays.shuffle(null)).to.throw(Error);
43
- });
44
- });
45
- });