array_utils 1.5.5-dev.bae473c16 → 1.5.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.
@@ -1,16 +1,21 @@
1
-
2
1
  name: release
3
2
  on:
4
- release:
5
- types: [published]
3
+ release:
4
+ types: [published]
6
5
 
7
6
  jobs:
8
- release:
9
- runs-on: ubuntu-latest
10
- steps:
11
- - uses: actions/checkout@v1
12
- - name: Make stable release to npm
13
- uses: epeli/npm-release@v1
14
- with:
15
- type: stable
16
- token: ${{ secrets.NPM_TOKEN }}
7
+ release:
8
+ permissions:
9
+ contents: read
10
+ id-token: write
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+ - uses: actions/setup-node@v6
15
+ with:
16
+ node-version: "24"
17
+ registry-url: "https://registry.npmjs.org"
18
+ - run: npm ci
19
+ - run: npm test
20
+ - run: npm version ${{ github.event.release.tag_name }} --no-git-tag-version
21
+ - run: npm publish --ignore-scripts
@@ -2,12 +2,12 @@ name: test
2
2
  on: [push]
3
3
 
4
4
  jobs:
5
- test:
6
- runs-on: ubuntu-latest
7
- steps:
8
- - uses: actions/checkout@v1
9
- - name: test coverage
10
- run: |
11
- npm ci
12
- npm test -- --coverage
13
- bash <(curl -s https://codecov.io/bash) -t ${{ secrets.CODECOV_TOKEN }}
5
+ test:
6
+ runs-on: ubuntu-latest
7
+ steps:
8
+ - uses: actions/checkout@v1
9
+ - name: test coverage
10
+ run: |
11
+ npm ci
12
+ npm test -- --coverage
13
+ bash <(curl -s https://codecov.io/bash) -t ${{ secrets.CODECOV_TOKEN }}
package/package.json CHANGED
@@ -1,30 +1,30 @@
1
1
  {
2
- "name": "array_utils",
3
- "version": "1.5.5-dev.bae473c16",
4
- "description": "Some basic array utilities",
5
- "main": "./dist/index.js",
6
- "jest": {
7
- "rootDir": "src"
8
- },
9
- "scripts": {
10
- "test": "jest",
11
- "build": "babel src -d dist",
12
- "prepublishOnly": "npm run build"
13
- },
14
- "repository": {
15
- "type": "git",
16
- "url": "git+https://github.com/danielhstahl/array-utils.git"
17
- },
18
- "author": "Daniel Stahl",
19
- "license": "ISC",
20
- "bugs": {
21
- "url": "https://github.com/danielhstahl/array-utils/issues"
22
- },
23
- "homepage": "https://github.com/danielhstahl/array-utils#readme",
24
- "devDependencies": {
25
- "@babel/cli": "^7.15",
26
- "@babel/core": "^7.15",
27
- "@babel/preset-env": "^7.15",
28
- "jest": "^27.2"
29
- }
30
- }
2
+ "name": "array_utils",
3
+ "version": "1.5.7",
4
+ "description": "Some basic array utilities",
5
+ "main": "./dist/index.js",
6
+ "jest": {
7
+ "rootDir": "src"
8
+ },
9
+ "scripts": {
10
+ "test": "jest",
11
+ "build": "babel src -d dist",
12
+ "prepublishOnly": "npm run build"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/danielhstahl/array-utils.git"
17
+ },
18
+ "author": "Daniel Stahl",
19
+ "license": "ISC",
20
+ "bugs": {
21
+ "url": "https://github.com/danielhstahl/array-utils/issues"
22
+ },
23
+ "homepage": "https://github.com/danielhstahl/array-utils#readme",
24
+ "devDependencies": {
25
+ "@babel/cli": "^7.15",
26
+ "@babel/core": "^7.15",
27
+ "@babel/preset-env": "^7.15",
28
+ "jest": "^30.2"
29
+ }
30
+ }
@@ -1,20 +0,0 @@
1
- name: prerelease
2
- on:
3
- push:
4
- branches:
5
- - master
6
-
7
- jobs:
8
- prerelease:
9
- runs-on: ubuntu-latest
10
- steps:
11
- - uses: actions/checkout@v1
12
- - name: test coverage
13
- run: |
14
- npm ci
15
- npm test
16
- - name: Make prerelease to npm
17
- uses: epeli/npm-release@v1
18
- with:
19
- type: prerelease
20
- token: ${{ secrets.NPM_TOKEN }}
package/dist/index.js DELETED
@@ -1,107 +0,0 @@
1
- "use strict";
2
-
3
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
4
- 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."); }
5
- 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); }
6
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
7
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
8
- 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; }
9
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
10
- var leftjoin = function leftjoin() {
11
- var leftArray = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
12
- var rightArray = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
13
- var condition = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (left, right) {
14
- return left === right;
15
- };
16
- var manageResult = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : function (left, right) {
17
- return right ? right : left;
18
- };
19
- return leftArray.map(function (left) {
20
- var result = rightArray.filter(function (right) {
21
- return condition(left, right);
22
- })[0];
23
- return manageResult(left, result);
24
- });
25
- };
26
- var innerjoin = function innerjoin() {
27
- var leftArray = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
28
- var rightArray = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
29
- var condition = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (left, right) {
30
- return left === right;
31
- };
32
- return leftArray.filter(function (left) {
33
- return rightArray.filter(function (right) {
34
- return condition(left, right);
35
- })[0];
36
- });
37
- };
38
- var convertArrayToObjByKey = function convertArrayToObjByKey() {
39
- var arr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
40
- var key = arguments.length > 1 ? arguments[1] : undefined;
41
- return arr.reduce(function (aggr, val) {
42
- return Object.assign({}, aggr, _defineProperty({}, val[key], val));
43
- }, {});
44
- };
45
- var unionObj = function unionObj() {
46
- var obj1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
47
- var obj2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
48
- var arr1 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
49
- var arr2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
50
- var leftKey = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : "";
51
- var rightKey = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : "";
52
- var manageResult = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : function (left, right) {
53
- return right ? right : left;
54
- };
55
- return [].concat(_toConsumableArray(arr1.map(function (val) {
56
- return manageResult(obj1[val[leftKey]], obj2[val[leftKey]]);
57
- })), _toConsumableArray(arr2.filter(function (val) {
58
- return !obj1[val[rightKey]];
59
- }).map(function (val) {
60
- return manageResult(obj1[val[rightKey]], obj2[val[rightKey]]);
61
- })));
62
- };
63
- var outerjoin = function outerjoin() {
64
- var leftArray = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
65
- var rightArray = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
66
- var leftKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "";
67
- var rightKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "";
68
- var manageResult = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : function (left, right) {
69
- return right ? right : left;
70
- };
71
- var createObjFromLeft = convertArrayToObjByKey(leftArray, leftKey);
72
- var createObjFromRight = convertArrayToObjByKey(rightArray, rightKey);
73
- return unionObj(createObjFromLeft, createObjFromRight, leftArray, rightArray, leftKey, rightKey, manageResult);
74
- };
75
- var convertArrayToObj = function convertArrayToObj() {
76
- var arr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
77
- return arr.reduce(function (aggr, val) {
78
- return Object.assign({}, aggr, _defineProperty({}, val, true));
79
- }, {});
80
- };
81
- var hasLengthGreaterThanZero = function hasLengthGreaterThanZero() {
82
- var arr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
83
- return arr.length > 0 ? true : false;
84
- };
85
- var sortNull = function sortNull(a, b) {
86
- return (a === null) - (b === null) || +(a > b) || -(a < b);
87
- };
88
- var getUniqueArray = function getUniqueArray(array, key) {
89
- if (key !== undefined) {
90
- return array.sort(function (a, b) {
91
- return sortNull(a[key], b[key]);
92
- }).filter(function (val, index, arr) {
93
- return !index || val[key] !== arr[index - 1][key];
94
- });
95
- } else {
96
- return array.sort(sortNull).filter(function (val, index, arr) {
97
- return !index || val !== arr[index - 1];
98
- });
99
- }
100
- };
101
- module.exports.leftjoin = leftjoin;
102
- module.exports.innerjoin = innerjoin;
103
- module.exports.convertArrayToObj = convertArrayToObj;
104
- module.exports.getUniqueArray = getUniqueArray;
105
- module.exports.hasLengthGreaterThanZero = hasLengthGreaterThanZero;
106
- module.exports.outerjoin = outerjoin;
107
- module.exports.convertArrayToObjByKey = convertArrayToObjByKey;
@@ -1,304 +0,0 @@
1
- "use strict";
2
-
3
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
- var arrayUtils = require('./index.js');
5
- var leftArray = [{
6
- id: 1,
7
- val: 5
8
- }, {
9
- id: 2,
10
- val: 6
11
- }, {
12
- id: 3,
13
- val: 7
14
- }];
15
- var rightArray = [{
16
- id: 2,
17
- val: 6,
18
- another: 4
19
- }];
20
- it('correctly turns array into keys', function () {
21
- var arr = ["one", "two", "three"];
22
- var expected = {
23
- one: true,
24
- two: true,
25
- three: true
26
- };
27
- expect(arrayUtils.convertArrayToObj(arr)).toEqual(expected);
28
- });
29
- it('returns empty object when provided empty array', function () {
30
- var arr = [];
31
- var expected = {};
32
- expect(arrayUtils.convertArrayToObj(arr)).toEqual(expected);
33
- });
34
- it('correctly returns true when array has length greater than zero', function () {
35
- var arr = ["one", "two", "three"];
36
- expect(arrayUtils.hasLengthGreaterThanZero(arr)).toEqual(true);
37
- });
38
- it('correctly returns false when array has length zero', function () {
39
- var arr = [];
40
- expect(arrayUtils.hasLengthGreaterThanZero(arr)).toEqual(false);
41
- });
42
- it('returns all matches', function () {
43
- var comb = arrayUtils.leftjoin(leftArray, rightArray, function (left, right) {
44
- return left.id === right.id;
45
- });
46
- expect(comb).toEqual([{
47
- id: 1,
48
- val: 5
49
- }, {
50
- id: 2,
51
- val: 6,
52
- another: 4
53
- }, {
54
- id: 3,
55
- val: 7
56
- }]);
57
- });
58
- it('returns only matches', function () {
59
- var comb = arrayUtils.innerjoin(leftArray, rightArray, function (left, right) {
60
- return left.id === right.id;
61
- });
62
- expect(comb).toEqual([{
63
- id: 2,
64
- val: 6
65
- }]);
66
- });
67
- it('returns unique array without last 1', function () {
68
- var arr = [1, 2, 3, 1];
69
- var expectedResult = [1, 2, 3];
70
- expect(arrayUtils.getUniqueArray(arr)).toEqual(expectedResult);
71
- });
72
- it('returns unique array with only 1', function () {
73
- var arr = [1, 1, 1, 1];
74
- var expectedResult = [1];
75
- expect(arrayUtils.getUniqueArray(arr)).toEqual(expectedResult);
76
- });
77
- it('returns unique array from array with keys', function () {
78
- var arr = [{
79
- hello: 4,
80
- world: 2
81
- }, {
82
- hello: 4,
83
- world: 3
84
- }, {
85
- hello: 5,
86
- world: 3
87
- }, {
88
- hello: 5,
89
- world: 4
90
- }];
91
- var expectedResult = [{
92
- hello: 4,
93
- world: 2
94
- }, {
95
- hello: 5,
96
- world: 3
97
- }];
98
- expect(arrayUtils.getUniqueArray(arr, "hello")).toEqual(expectedResult);
99
- });
100
- it('returns unique array from array of arrays', function () {
101
- var arr = [[4, 2], [4, 3], [5, 3], [5, 4]];
102
- var expectedResult = [[4, 2], [5, 3]];
103
- expect(arrayUtils.getUniqueArray(arr, 0)).toEqual(expectedResult);
104
- });
105
- it('returns unique array from array with keys and out of order and with null', function () {
106
- var arr = [{
107
- hello: 4,
108
- world: 2
109
- }, {
110
- hello: 5,
111
- world: 3
112
- }, {
113
- hello: 4,
114
- world: 3
115
- }, {
116
- hello: 5,
117
- world: 4
118
- }, {
119
- hello: null,
120
- world: 4
121
- }];
122
- var expectedResult = [{
123
- hello: 4,
124
- world: 2
125
- }, {
126
- hello: 5,
127
- world: 3
128
- }, {
129
- hello: null,
130
- world: 4
131
- }];
132
- expect(arrayUtils.getUniqueArray(arr, "hello")).toEqual(expectedResult);
133
- });
134
- it('returns unique array from array with more complicated case', function () {
135
- var arr = [{
136
- CLASSIFICATION: "High"
137
- }, {
138
- CLASSIFICATION: "Moderate"
139
- }, {
140
- CLASSIFICATION: null
141
- }, {
142
- CLASSIFICATION: "High"
143
- }, {
144
- CLASSIFICATION: "High"
145
- }, {
146
- CLASSIFICATION: null
147
- }, {
148
- CLASSIFICATION: "Low"
149
- }, {
150
- CLASSIFICATION: "Moderate"
151
- }, {
152
- CLASSIFICATION: "Low"
153
- }];
154
- var expectedResult = [{
155
- CLASSIFICATION: "High"
156
- }, {
157
- CLASSIFICATION: "Low"
158
- }, {
159
- CLASSIFICATION: "Moderate"
160
- }, {
161
- CLASSIFICATION: null
162
- }];
163
- expect(arrayUtils.getUniqueArray(arr, "CLASSIFICATION")).toEqual(expectedResult);
164
- });
165
- it("returns obj from array", function () {
166
- var expected = {
167
- 1: {
168
- id: 1,
169
- val: 5
170
- },
171
- 2: {
172
- id: 2,
173
- val: 6
174
- },
175
- 3: {
176
- id: 3,
177
- val: 7
178
- }
179
- };
180
- expect(arrayUtils.convertArrayToObjByKey(leftArray, "id")).toEqual(expected);
181
- });
182
- it("returns left join when all match in outer join", function () {
183
- var expected = [{
184
- id: 1,
185
- val: 5
186
- }, {
187
- another: 4,
188
- id: 2,
189
- val: 6
190
- }, {
191
- id: 3,
192
- val: 7
193
- }];
194
- expect(arrayUtils.outerjoin(leftArray, rightArray, "id", "id")).toEqual(expected);
195
- });
196
- it("returns all results from both array when each contains items not in the other", function () {
197
- var rightArray = [{
198
- id: 2,
199
- val: 6
200
- }, {
201
- id: 10,
202
- val: 8
203
- }];
204
- var expected = [{
205
- id: 1,
206
- val: 5
207
- }, {
208
- id: 2,
209
- val: 6
210
- }, {
211
- id: 3,
212
- val: 7
213
- }, {
214
- id: 10,
215
- val: 8
216
- }];
217
- expect(arrayUtils.outerjoin(leftArray, rightArray, "id", "id")).toEqual(expected);
218
- });
219
- it("returns all results for a more complicated case", function () {
220
- var leftKey = "issueId";
221
- var rightKey = "ISSUEID";
222
- var state = [{
223
- issueId: 1,
224
- someOtherKey: 3
225
- }, {
226
- issueId: 2,
227
- someOtherKey: 4
228
- }];
229
- var pastDue = [{
230
- ISSUEID: 1
231
- }, {
232
- ISSUEID: 3
233
- }, {
234
- ISSUEID: 4
235
- }];
236
- var expected = [{
237
- issueId: 1,
238
- someOtherKey: 3,
239
- pastDue: true
240
- }, {
241
- issueId: 2,
242
- someOtherKey: 4
243
- }, {
244
- issueId: 3,
245
- pastDue: true
246
- }, {
247
- issueId: 4,
248
- pastDue: true
249
- }];
250
- var myJoin = arrayUtils.outerjoin(state, pastDue, leftKey, rightKey, function (left, right) {
251
- if (left && right) {
252
- return Object.assign({}, left, {
253
- pastDue: true
254
- });
255
- } else if (left) {
256
- return left;
257
- } else {
258
- var _ref;
259
- return _ref = {}, _defineProperty(_ref, leftKey, right[rightKey]), _defineProperty(_ref, "pastDue", true), _ref;
260
- }
261
- });
262
- expect(myJoin).toEqual(expected);
263
- });
264
- it("returns all results when no left state", function () {
265
- var leftKey = "issueId";
266
- var rightKey = "ISSUEID";
267
- var state = [];
268
- var pastDue = [{
269
- ISSUEID: 1
270
- }, {
271
- ISSUEID: 3
272
- }, {
273
- ISSUEID: 4
274
- }];
275
- var expected = [{
276
- issueId: 1,
277
- pastDue: true
278
- }, {
279
- issueId: 3,
280
- pastDue: true
281
- }, {
282
- issueId: 4,
283
- pastDue: true
284
- }];
285
- var myJoin = arrayUtils.outerjoin(state, pastDue, leftKey, rightKey, function (left, right) {
286
- if (left && right) {
287
- return Object.assign({}, left, {
288
- pastDue: true
289
- });
290
- } else if (left) {
291
- return left;
292
- } else {
293
- var _ref2;
294
- return _ref2 = {}, _defineProperty(_ref2, leftKey, right[rightKey]), _defineProperty(_ref2, "pastDue", true), _ref2;
295
- }
296
- });
297
- expect(myJoin).toEqual(expected);
298
- });
299
- it("returns only left when blank right", function () {
300
- expect(arrayUtils.outerjoin(leftArray, [], "id", "id")).toEqual(leftArray);
301
- });
302
- it("returns only right when blank left", function () {
303
- expect(arrayUtils.outerjoin([], rightArray, "id", "id")).toEqual(rightArray);
304
- });