@bhbr/betray 0.0.0-stage → 1.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.
- package/README.md +2 -2
- package/dist/betray.d.ts +12 -0
- package/dist/betray.d.ts.map +1 -0
- package/dist/betray.js +105 -0
- package/dist/betray.js.map +1 -0
- package/package.json +40 -4
package/README.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Description
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
the package betray ("better arrays") contains some convenience functions for handling arrays.
|
package/dist/betray.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare function removeOne(arr: Array<any>, value: any): boolean;
|
|
2
|
+
export declare function removeAll(arr: Array<any>, value: any): void;
|
|
3
|
+
export declare function remove(arr: Array<any>, value: any, all?: boolean): void;
|
|
4
|
+
export declare function clear(arr: Array<any>): void;
|
|
5
|
+
export declare function concat(arr1: Array<any>, arr2: Array<any>): Array<any>;
|
|
6
|
+
export declare function extend(arr1: Array<any>, arr2: Array<any>): void;
|
|
7
|
+
export declare function convertStringToArray(s: string): Array<string>;
|
|
8
|
+
export declare function convertArrayToString(array: Array<string>): string;
|
|
9
|
+
export declare function removeDuplicates(arr: Array<any>): Array<any>;
|
|
10
|
+
export declare function replaceAll(arr: Array<any>, oldValue: any, newValue: any): void;
|
|
11
|
+
export declare function arrayWithReplacements(oldArr: Array<string>, replacements: Record<string, string>): Array<string>;
|
|
12
|
+
//# sourceMappingURL=betray.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"betray.d.ts","sourceRoot":"","sources":["../src/betray.ts"],"names":[],"mappings":"AAIA,wBAAgB,SAAS,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CAS9D;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,GAAG,QAKpD;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,GAAE,OAAe,QAMvE;AAED,wBAAgB,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,QAKpC;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAKrE;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,QAExD;AAED,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAU7D;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAWjE;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAO5D;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,QAavE;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAMhH"}
|
package/dist/betray.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { equal } from '@bhbr/egalite';
|
|
2
|
+
import { copy } from '@bhbr/copycat';
|
|
3
|
+
export function removeOne(arr, value) {
|
|
4
|
+
// remove the first encountered matching entry of an object or value from an Array
|
|
5
|
+
for (let i = 0; i < arr.length; i++) {
|
|
6
|
+
if (arr[i] == value) {
|
|
7
|
+
arr.splice(i, 1);
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
export function removeAll(arr, value) {
|
|
14
|
+
var found = true;
|
|
15
|
+
while (found) {
|
|
16
|
+
found = removeOne(arr, value);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function remove(arr, value, all = false) {
|
|
20
|
+
if (all) {
|
|
21
|
+
removeAll(arr, value);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
removeOne(arr, value);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function clear(arr) {
|
|
28
|
+
let l = arr.length;
|
|
29
|
+
for (var i = 0; i < l; i++) {
|
|
30
|
+
arr.pop();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export function concat(arr1, arr2) {
|
|
34
|
+
let ret = [];
|
|
35
|
+
for (let x of arr1) {
|
|
36
|
+
ret.push(x);
|
|
37
|
+
}
|
|
38
|
+
for (let x of arr2) {
|
|
39
|
+
ret.push(x);
|
|
40
|
+
}
|
|
41
|
+
return ret;
|
|
42
|
+
}
|
|
43
|
+
export function extend(arr1, arr2) {
|
|
44
|
+
for (let x of arr2) {
|
|
45
|
+
arr1.push(x);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export function convertStringToArray(s) {
|
|
49
|
+
let brackets = ["(", ")", "[", "]"];
|
|
50
|
+
let whitespace = [" ", "\t", "\r", "\n"];
|
|
51
|
+
for (let char of brackets.concat(whitespace)) {
|
|
52
|
+
s = s.replace(char, "");
|
|
53
|
+
}
|
|
54
|
+
if (s.length == 0)
|
|
55
|
+
return [];
|
|
56
|
+
let a = s.split(",");
|
|
57
|
+
if (a.length == 0) {
|
|
58
|
+
return [s];
|
|
59
|
+
}
|
|
60
|
+
return a;
|
|
61
|
+
}
|
|
62
|
+
export function convertArrayToString(array) {
|
|
63
|
+
var arrayString = "(";
|
|
64
|
+
for (let s of array) {
|
|
65
|
+
arrayString += s;
|
|
66
|
+
arrayString += ",";
|
|
67
|
+
}
|
|
68
|
+
if (arrayString.length > 1) {
|
|
69
|
+
arrayString = arrayString.slice(0, arrayString.length - 1);
|
|
70
|
+
}
|
|
71
|
+
arrayString += ")";
|
|
72
|
+
return arrayString;
|
|
73
|
+
}
|
|
74
|
+
export function removeDuplicates(arr) {
|
|
75
|
+
let ret = [];
|
|
76
|
+
for (let x of arr) {
|
|
77
|
+
if (ret.includes(x)) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
ret.push(x);
|
|
81
|
+
}
|
|
82
|
+
return ret;
|
|
83
|
+
}
|
|
84
|
+
export function replaceAll(arr, oldValue, newValue) {
|
|
85
|
+
for (let i = 0; i < arr.length; i++) {
|
|
86
|
+
let entry = arr[i];
|
|
87
|
+
if (entry === oldValue) {
|
|
88
|
+
arr[i] = newValue;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (entry instanceof Array && oldValue instanceof Array) {
|
|
92
|
+
if (equal(entry, oldValue)) {
|
|
93
|
+
arr[i] = newValue;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
export function arrayWithReplacements(oldArr, replacements) {
|
|
99
|
+
let newArr = copy(oldArr);
|
|
100
|
+
for (let [key, value] of Object.entries(replacements)) {
|
|
101
|
+
replaceAll(newArr, key, value);
|
|
102
|
+
}
|
|
103
|
+
return newArr;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=betray.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"betray.js","sourceRoot":"","sources":["../src/betray.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AAEpC,MAAM,UAAU,SAAS,CAAC,GAAe,EAAE,KAAU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C;IACD,OAAO,MAAM,CAAA;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bhbr/betray",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Some convenience functions for handling array",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/betray.js",
|
|
7
|
+
"types": "./dist/betray.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/betray.d.ts",
|
|
11
|
+
"import": "./dist/betray.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist/betray.js",
|
|
16
|
+
"dist/betray.d.ts",
|
|
17
|
+
"dist/betray.js.map",
|
|
18
|
+
"dist/betray.d.ts.map"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "cd build && ./build.sh",
|
|
22
|
+
"test": "node dist/_tests/betray_tests.js",
|
|
23
|
+
"prepack": "npm run build"
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "https://github.com/bhbr/betray"
|
|
28
|
+
},
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/bhbr/betray/issues"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/bhbr/betray#readme",
|
|
33
|
+
"keywords": [],
|
|
34
|
+
"author": "Ben Hambrecht",
|
|
35
|
+
"license": "ISC",
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@bhbr/copycat": "^1.0.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@bhbr/tsts": "^1.1.3"
|
|
41
|
+
}
|
|
42
|
+
}
|