@configura/web-utilities 2.1.0-alpha.2 → 2.1.0-alpha.3
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/.eslintrc.json +5 -5
- package/.gitattributes +3 -3
- package/LICENSE +201 -201
- package/README.md +1 -1
- package/__tests__/cmMips.test.ts +129 -129
- package/__tests__/convertLength.test.ts +37 -37
- package/__tests__/price.test.ts +21 -21
- package/dist/GenericCache.d.ts +14 -14
- package/dist/GenericCache.js +38 -38
- package/dist/Observable/AccumulatingObservable.d.ts +10 -10
- package/dist/Observable/AccumulatingObservable.js +25 -25
- package/dist/Observable/AggregatedLoadingObservable.d.ts +10 -10
- package/dist/Observable/AggregatedLoadingObservable.js +28 -28
- package/dist/Observable/LogObservable.d.ts +42 -42
- package/dist/Observable/LogObservable.js +104 -104
- package/dist/Observable/LogProducer.d.ts +5 -5
- package/dist/Observable/LogProducer.js +9 -9
- package/dist/Observable/Observable.d.ts +12 -12
- package/dist/Observable/Observable.js +33 -33
- package/dist/PromiseCache.d.ts +4 -4
- package/dist/PromiseCache.js +28 -28
- package/dist/assert.d.ts +12 -12
- package/dist/assert.js +20 -20
- package/dist/cmMips.d.ts +26 -26
- package/dist/cmMips.js +159 -159
- package/dist/compare.d.ts +6 -6
- package/dist/compare.js +29 -29
- package/dist/error.d.ts +7 -7
- package/dist/error.js +24 -24
- package/dist/event.d.ts +2 -2
- package/dist/event.js +1 -1
- package/dist/filter.d.ts +22 -22
- package/dist/filter.js +19 -19
- package/dist/index.d.ts +21 -21
- package/dist/index.js +21 -21
- package/dist/utilitiesArray.d.ts +4 -4
- package/dist/utilitiesArray.js +49 -49
- package/dist/utilitiesFile.d.ts +6 -6
- package/dist/utilitiesFile.js +33 -33
- package/dist/utilitiesImage.d.ts +1 -1
- package/dist/utilitiesImage.js +19 -19
- package/dist/utilitiesMath.d.ts +3 -3
- package/dist/utilitiesMath.js +9 -9
- package/dist/utilitiesPrice.d.ts +1 -1
- package/dist/utilitiesPrice.js +16 -16
- package/dist/utilitiesPromise.d.ts +1 -1
- package/dist/utilitiesPromise.js +12 -12
- package/dist/utilitiesString.d.ts +1 -1
- package/dist/utilitiesString.js +12 -12
- package/dist/utilitiesUnits.d.ts +16 -16
- package/dist/utilitiesUnits.js +72 -72
- package/dist/utilitiesWeb.d.ts +3 -3
- package/dist/utilitiesWeb.js +20 -20
- package/package.json +2 -2
package/dist/utilitiesArray.js
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
export function shuffle(items) {
|
|
2
|
-
return items
|
|
3
|
-
.map((value) => ({
|
|
4
|
-
sort: Math.random(),
|
|
5
|
-
value,
|
|
6
|
-
}))
|
|
7
|
-
.sort((a, b) => a.sort - b.sort)
|
|
8
|
-
.map((item) => item.value);
|
|
9
|
-
}
|
|
10
|
-
export function count(items, predicate) {
|
|
11
|
-
return items.reduce((c, item) => c + (predicate(item) ? 1 : 0), 0);
|
|
12
|
-
}
|
|
13
|
-
export function someMatch(items, predicate) {
|
|
14
|
-
const len = items.length;
|
|
15
|
-
if (len < 2) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
for (let i = 0; i < len - 1; i++) {
|
|
19
|
-
for (let j = i + 1; j < len; j++) {
|
|
20
|
-
if (predicate(items[i], items[j])) {
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
export function compareArrays(left, right, predicate = (l, r) => l === r, strictOrder = true) {
|
|
28
|
-
const len = left.length;
|
|
29
|
-
if (len !== right.length) {
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
if (strictOrder) {
|
|
33
|
-
for (let i = 0; i < len; i++) {
|
|
34
|
-
if (!predicate(left[i], right[i])) {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
const rightCandidates = right.slice();
|
|
41
|
-
for (const l of left) {
|
|
42
|
-
const i = rightCandidates.findIndex((r) => predicate(l, r));
|
|
43
|
-
if (i === -1) {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
rightCandidates.splice(i, 1);
|
|
47
|
-
}
|
|
48
|
-
return true;
|
|
49
|
-
}
|
|
1
|
+
export function shuffle(items) {
|
|
2
|
+
return items
|
|
3
|
+
.map((value) => ({
|
|
4
|
+
sort: Math.random(),
|
|
5
|
+
value,
|
|
6
|
+
}))
|
|
7
|
+
.sort((a, b) => a.sort - b.sort)
|
|
8
|
+
.map((item) => item.value);
|
|
9
|
+
}
|
|
10
|
+
export function count(items, predicate) {
|
|
11
|
+
return items.reduce((c, item) => c + (predicate(item) ? 1 : 0), 0);
|
|
12
|
+
}
|
|
13
|
+
export function someMatch(items, predicate) {
|
|
14
|
+
const len = items.length;
|
|
15
|
+
if (len < 2) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
for (let i = 0; i < len - 1; i++) {
|
|
19
|
+
for (let j = i + 1; j < len; j++) {
|
|
20
|
+
if (predicate(items[i], items[j])) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
export function compareArrays(left, right, predicate = (l, r) => l === r, strictOrder = true) {
|
|
28
|
+
const len = left.length;
|
|
29
|
+
if (len !== right.length) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
if (strictOrder) {
|
|
33
|
+
for (let i = 0; i < len; i++) {
|
|
34
|
+
if (!predicate(left[i], right[i])) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
const rightCandidates = right.slice();
|
|
41
|
+
for (const l of left) {
|
|
42
|
+
const i = rightCandidates.findIndex((r) => predicate(l, r));
|
|
43
|
+
if (i === -1) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
rightCandidates.splice(i, 1);
|
|
47
|
+
}
|
|
48
|
+
return true;
|
|
49
|
+
}
|
package/dist/utilitiesFile.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export declare type BufferWithFileName = {
|
|
2
|
-
buffer: ArrayBuffer;
|
|
3
|
-
fileName: string;
|
|
4
|
-
};
|
|
5
|
-
export declare function readFileToArrayBuffer(fileReference: File): Promise<BufferWithFileName>;
|
|
6
|
-
export declare function getFileExtension(filename: string): string;
|
|
1
|
+
export declare type BufferWithFileName = {
|
|
2
|
+
buffer: ArrayBuffer;
|
|
3
|
+
fileName: string;
|
|
4
|
+
};
|
|
5
|
+
export declare function readFileToArrayBuffer(fileReference: File): Promise<BufferWithFileName>;
|
|
6
|
+
export declare function getFileExtension(filename: string): string;
|
|
7
7
|
//# sourceMappingURL=utilitiesFile.d.ts.map
|
package/dist/utilitiesFile.js
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
export function readFileToArrayBuffer(fileReference) {
|
|
11
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
12
|
-
return new Promise((resolve, reject) => {
|
|
13
|
-
const reader = new FileReader();
|
|
14
|
-
reader.addEventListener("load", (e) => {
|
|
15
|
-
const target = e.target;
|
|
16
|
-
if (target === null) {
|
|
17
|
-
reject(new Error("No target"));
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
const result = target.result;
|
|
21
|
-
if (!(result instanceof ArrayBuffer)) {
|
|
22
|
-
reject(new Error("No ArrayBuffer"));
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
resolve({ buffer: result, fileName: fileReference.name });
|
|
26
|
-
});
|
|
27
|
-
reader.readAsArrayBuffer(fileReference);
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
export function getFileExtension(filename) {
|
|
32
|
-
return filename.slice(filename.lastIndexOf(".") + 1);
|
|
33
|
-
}
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export function readFileToArrayBuffer(fileReference) {
|
|
11
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
const reader = new FileReader();
|
|
14
|
+
reader.addEventListener("load", (e) => {
|
|
15
|
+
const target = e.target;
|
|
16
|
+
if (target === null) {
|
|
17
|
+
reject(new Error("No target"));
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const result = target.result;
|
|
21
|
+
if (!(result instanceof ArrayBuffer)) {
|
|
22
|
+
reject(new Error("No ArrayBuffer"));
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
resolve({ buffer: result, fileName: fileReference.name });
|
|
26
|
+
});
|
|
27
|
+
reader.readAsArrayBuffer(fileReference);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
export function getFileExtension(filename) {
|
|
32
|
+
return filename.slice(filename.lastIndexOf(".") + 1);
|
|
33
|
+
}
|
package/dist/utilitiesImage.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function loadImage(url: string): Promise<HTMLImageElement | undefined>;
|
|
1
|
+
export declare function loadImage(url: string): Promise<HTMLImageElement | undefined>;
|
|
2
2
|
//# sourceMappingURL=utilitiesImage.d.ts.map
|
package/dist/utilitiesImage.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
export function loadImage(url) {
|
|
11
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
12
|
-
return new Promise((resolve, reject) => {
|
|
13
|
-
const image = new Image();
|
|
14
|
-
image.onload = () => resolve(image);
|
|
15
|
-
image.onerror = () => reject(Error(`Failed to load image ${url}`));
|
|
16
|
-
image.src = url;
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
}
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export function loadImage(url) {
|
|
11
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
const image = new Image();
|
|
14
|
+
image.onload = () => resolve(image);
|
|
15
|
+
image.onerror = () => reject(Error(`Failed to load image ${url}`));
|
|
16
|
+
image.src = url;
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
}
|
package/dist/utilitiesMath.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare function degToRad(deg: number): number;
|
|
2
|
-
export declare function radToDeg(rad: number): number;
|
|
3
|
-
export declare function normalizeAngle(angle: number): number;
|
|
1
|
+
export declare function degToRad(deg: number): number;
|
|
2
|
+
export declare function radToDeg(rad: number): number;
|
|
3
|
+
export declare function normalizeAngle(angle: number): number;
|
|
4
4
|
//# sourceMappingURL=utilitiesMath.d.ts.map
|
package/dist/utilitiesMath.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export function degToRad(deg) {
|
|
2
|
-
return (deg * Math.PI) / 180;
|
|
3
|
-
}
|
|
4
|
-
export function radToDeg(rad) {
|
|
5
|
-
return (rad * 180) / Math.PI;
|
|
6
|
-
}
|
|
7
|
-
export function normalizeAngle(angle) {
|
|
8
|
-
return Math.atan2(Math.sin(angle), Math.cos(angle));
|
|
9
|
-
}
|
|
1
|
+
export function degToRad(deg) {
|
|
2
|
+
return (deg * Math.PI) / 180;
|
|
3
|
+
}
|
|
4
|
+
export function radToDeg(rad) {
|
|
5
|
+
return (rad * 180) / Math.PI;
|
|
6
|
+
}
|
|
7
|
+
export function normalizeAngle(angle) {
|
|
8
|
+
return Math.atan2(Math.sin(angle), Math.cos(angle));
|
|
9
|
+
}
|
package/dist/utilitiesPrice.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function formatPrice(price: number, fractionDigits: number, lang: string, currency: string): string;
|
|
1
|
+
export declare function formatPrice(price: number, fractionDigits: number, lang: string, currency: string): string;
|
|
2
2
|
//# sourceMappingURL=utilitiesPrice.d.ts.map
|
package/dist/utilitiesPrice.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export function formatPrice(price, fractionDigits, lang, currency) {
|
|
2
|
-
if (!Number.isInteger(fractionDigits)) {
|
|
3
|
-
throw new Error("Fraction digits must be integer");
|
|
4
|
-
}
|
|
5
|
-
if (fractionDigits < 0) {
|
|
6
|
-
const pow = Math.pow(10, -fractionDigits);
|
|
7
|
-
price = Math.round(price / pow) * pow;
|
|
8
|
-
fractionDigits = 0;
|
|
9
|
-
}
|
|
10
|
-
return new Intl.NumberFormat(lang, {
|
|
11
|
-
style: "currency",
|
|
12
|
-
currency,
|
|
13
|
-
minimumFractionDigits: fractionDigits,
|
|
14
|
-
maximumFractionDigits: fractionDigits,
|
|
15
|
-
}).format(price);
|
|
16
|
-
}
|
|
1
|
+
export function formatPrice(price, fractionDigits, lang, currency) {
|
|
2
|
+
if (!Number.isInteger(fractionDigits)) {
|
|
3
|
+
throw new Error("Fraction digits must be integer");
|
|
4
|
+
}
|
|
5
|
+
if (fractionDigits < 0) {
|
|
6
|
+
const pow = Math.pow(10, -fractionDigits);
|
|
7
|
+
price = Math.round(price / pow) * pow;
|
|
8
|
+
fractionDigits = 0;
|
|
9
|
+
}
|
|
10
|
+
return new Intl.NumberFormat(lang, {
|
|
11
|
+
style: "currency",
|
|
12
|
+
currency,
|
|
13
|
+
minimumFractionDigits: fractionDigits,
|
|
14
|
+
maximumFractionDigits: fractionDigits,
|
|
15
|
+
}).format(price);
|
|
16
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function getWaitFramesPromise(frameCount: number): Promise<void>;
|
|
1
|
+
export declare function getWaitFramesPromise(frameCount: number): Promise<void>;
|
|
2
2
|
//# sourceMappingURL=utilitiesPromise.d.ts.map
|
package/dist/utilitiesPromise.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export function getWaitFramesPromise(frameCount) {
|
|
2
|
-
return new Promise((resolve) => {
|
|
3
|
-
const frame = () => {
|
|
4
|
-
if (frameCount === 0) {
|
|
5
|
-
resolve();
|
|
6
|
-
}
|
|
7
|
-
frameCount--;
|
|
8
|
-
requestAnimationFrame(frame);
|
|
9
|
-
};
|
|
10
|
-
frame();
|
|
11
|
-
});
|
|
12
|
-
}
|
|
1
|
+
export function getWaitFramesPromise(frameCount) {
|
|
2
|
+
return new Promise((resolve) => {
|
|
3
|
+
const frame = () => {
|
|
4
|
+
if (frameCount === 0) {
|
|
5
|
+
resolve();
|
|
6
|
+
}
|
|
7
|
+
frameCount--;
|
|
8
|
+
requestAnimationFrame(frame);
|
|
9
|
+
};
|
|
10
|
+
frame();
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function hashCode(str: string): number;
|
|
1
|
+
export declare function hashCode(str: string): number;
|
|
2
2
|
//# sourceMappingURL=utilitiesString.d.ts.map
|
package/dist/utilitiesString.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export function hashCode(str) {
|
|
2
|
-
const len = str.length;
|
|
3
|
-
let hash = 0, i, chr;
|
|
4
|
-
if (len === 0)
|
|
5
|
-
return hash;
|
|
6
|
-
for (i = 0; i < len; i++) {
|
|
7
|
-
chr = str.charCodeAt(i);
|
|
8
|
-
hash = (hash << 5) - hash + chr;
|
|
9
|
-
hash |= 0; // Convert to 32bit integer
|
|
10
|
-
}
|
|
11
|
-
return hash;
|
|
12
|
-
}
|
|
1
|
+
export function hashCode(str) {
|
|
2
|
+
const len = str.length;
|
|
3
|
+
let hash = 0, i, chr;
|
|
4
|
+
if (len === 0)
|
|
5
|
+
return hash;
|
|
6
|
+
for (i = 0; i < len; i++) {
|
|
7
|
+
chr = str.charCodeAt(i);
|
|
8
|
+
hash = (hash << 5) - hash + chr;
|
|
9
|
+
hash |= 0; // Convert to 32bit integer
|
|
10
|
+
}
|
|
11
|
+
return hash;
|
|
12
|
+
}
|
package/dist/utilitiesUnits.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
export declare type LengthUnit = "mm" | "cm" | "dm" | "m" | "in" | "ft";
|
|
2
|
-
export declare type LengthValue = {
|
|
3
|
-
length: number;
|
|
4
|
-
unit: LengthUnit;
|
|
5
|
-
};
|
|
6
|
-
export declare const isEqualLength: (l: LengthValue, r: LengthValue) => boolean;
|
|
7
|
-
/**
|
|
8
|
-
* Converts string to LengthUnit.
|
|
9
|
-
* @throws an error if the supplied string isn't a known length unit
|
|
10
|
-
*/
|
|
11
|
-
export declare function toLengthUnit(unit: string): LengthUnit;
|
|
12
|
-
/**
|
|
13
|
-
* As we accept inch as an alias for in we can't make this a typeguard
|
|
14
|
-
*/
|
|
15
|
-
export declare function isLengthUnit(unit: string): boolean;
|
|
16
|
-
export declare function convertLength(l: number, from: LengthUnit, to: LengthUnit): number;
|
|
1
|
+
export declare type LengthUnit = "mm" | "cm" | "dm" | "m" | "in" | "ft";
|
|
2
|
+
export declare type LengthValue = {
|
|
3
|
+
length: number;
|
|
4
|
+
unit: LengthUnit;
|
|
5
|
+
};
|
|
6
|
+
export declare const isEqualLength: (l: LengthValue, r: LengthValue) => boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Converts string to LengthUnit.
|
|
9
|
+
* @throws an error if the supplied string isn't a known length unit
|
|
10
|
+
*/
|
|
11
|
+
export declare function toLengthUnit(unit: string): LengthUnit;
|
|
12
|
+
/**
|
|
13
|
+
* As we accept inch as an alias for in we can't make this a typeguard
|
|
14
|
+
*/
|
|
15
|
+
export declare function isLengthUnit(unit: string): boolean;
|
|
16
|
+
export declare function convertLength(l: number, from: LengthUnit, to: LengthUnit): number;
|
|
17
17
|
//# sourceMappingURL=utilitiesUnits.d.ts.map
|
package/dist/utilitiesUnits.js
CHANGED
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
// Each entry in this array must be exactly 10x larger than the one before it
|
|
2
|
-
const metricUnits = ["mm", "cm", "dm", "m"];
|
|
3
|
-
const meterPerInch = 0.0254;
|
|
4
|
-
const inchPerFeet = 12;
|
|
5
|
-
const meterPerFeet = meterPerInch * inchPerFeet;
|
|
6
|
-
export const isEqualLength = (l, r) => l.length === convertLength(r.length, r.unit, l.unit);
|
|
7
|
-
/**
|
|
8
|
-
* Converts string to LengthUnit.
|
|
9
|
-
* @throws an error if the supplied string isn't a known length unit
|
|
10
|
-
*/
|
|
11
|
-
export function toLengthUnit(unit) {
|
|
12
|
-
// The list below must EXACTLY match isLengthUnit(string)
|
|
13
|
-
unit = unit === null || unit === void 0 ? void 0 : unit.toLowerCase();
|
|
14
|
-
if (unit === "inch") {
|
|
15
|
-
unit = "in";
|
|
16
|
-
}
|
|
17
|
-
if (unit === "in" ||
|
|
18
|
-
unit === "ft" ||
|
|
19
|
-
unit === "mm" ||
|
|
20
|
-
unit === "cm" ||
|
|
21
|
-
unit === "dm" ||
|
|
22
|
-
unit === "m") {
|
|
23
|
-
return unit;
|
|
24
|
-
}
|
|
25
|
-
throw new Error(`Unknown length unit ${unit}`);
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* As we accept inch as an alias for in we can't make this a typeguard
|
|
29
|
-
*/
|
|
30
|
-
export function isLengthUnit(unit) {
|
|
31
|
-
// The list below must EXACTLY match toLengthUnit(string)
|
|
32
|
-
unit = unit === null || unit === void 0 ? void 0 : unit.toLowerCase();
|
|
33
|
-
return (unit === "inch" ||
|
|
34
|
-
unit === "in" ||
|
|
35
|
-
unit === "ft" ||
|
|
36
|
-
unit === "mm" ||
|
|
37
|
-
unit === "cm" ||
|
|
38
|
-
unit === "dm" ||
|
|
39
|
-
unit === "m");
|
|
40
|
-
}
|
|
41
|
-
export function convertLength(l, from, to) {
|
|
42
|
-
if (from === to) {
|
|
43
|
-
return l;
|
|
44
|
-
}
|
|
45
|
-
if (from === "ft" && to === "in") {
|
|
46
|
-
return l * inchPerFeet;
|
|
47
|
-
}
|
|
48
|
-
if (from === "in" && to === "ft") {
|
|
49
|
-
return l / inchPerFeet;
|
|
50
|
-
}
|
|
51
|
-
if (from === "ft") {
|
|
52
|
-
l *= meterPerFeet;
|
|
53
|
-
from = "m";
|
|
54
|
-
}
|
|
55
|
-
else if (from === "in") {
|
|
56
|
-
l *= meterPerInch;
|
|
57
|
-
from = "m";
|
|
58
|
-
}
|
|
59
|
-
if (to === "ft") {
|
|
60
|
-
l /= meterPerFeet;
|
|
61
|
-
to = "m";
|
|
62
|
-
}
|
|
63
|
-
else if (to === "in") {
|
|
64
|
-
l /= meterPerInch;
|
|
65
|
-
to = "m";
|
|
66
|
-
}
|
|
67
|
-
if (from === to) {
|
|
68
|
-
return l;
|
|
69
|
-
}
|
|
70
|
-
l *= Math.pow(10, metricUnits.indexOf(from) - metricUnits.indexOf(to));
|
|
71
|
-
return l;
|
|
72
|
-
}
|
|
1
|
+
// Each entry in this array must be exactly 10x larger than the one before it
|
|
2
|
+
const metricUnits = ["mm", "cm", "dm", "m"];
|
|
3
|
+
const meterPerInch = 0.0254;
|
|
4
|
+
const inchPerFeet = 12;
|
|
5
|
+
const meterPerFeet = meterPerInch * inchPerFeet;
|
|
6
|
+
export const isEqualLength = (l, r) => l.length === convertLength(r.length, r.unit, l.unit);
|
|
7
|
+
/**
|
|
8
|
+
* Converts string to LengthUnit.
|
|
9
|
+
* @throws an error if the supplied string isn't a known length unit
|
|
10
|
+
*/
|
|
11
|
+
export function toLengthUnit(unit) {
|
|
12
|
+
// The list below must EXACTLY match isLengthUnit(string)
|
|
13
|
+
unit = unit === null || unit === void 0 ? void 0 : unit.toLowerCase();
|
|
14
|
+
if (unit === "inch") {
|
|
15
|
+
unit = "in";
|
|
16
|
+
}
|
|
17
|
+
if (unit === "in" ||
|
|
18
|
+
unit === "ft" ||
|
|
19
|
+
unit === "mm" ||
|
|
20
|
+
unit === "cm" ||
|
|
21
|
+
unit === "dm" ||
|
|
22
|
+
unit === "m") {
|
|
23
|
+
return unit;
|
|
24
|
+
}
|
|
25
|
+
throw new Error(`Unknown length unit ${unit}`);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* As we accept inch as an alias for in we can't make this a typeguard
|
|
29
|
+
*/
|
|
30
|
+
export function isLengthUnit(unit) {
|
|
31
|
+
// The list below must EXACTLY match toLengthUnit(string)
|
|
32
|
+
unit = unit === null || unit === void 0 ? void 0 : unit.toLowerCase();
|
|
33
|
+
return (unit === "inch" ||
|
|
34
|
+
unit === "in" ||
|
|
35
|
+
unit === "ft" ||
|
|
36
|
+
unit === "mm" ||
|
|
37
|
+
unit === "cm" ||
|
|
38
|
+
unit === "dm" ||
|
|
39
|
+
unit === "m");
|
|
40
|
+
}
|
|
41
|
+
export function convertLength(l, from, to) {
|
|
42
|
+
if (from === to) {
|
|
43
|
+
return l;
|
|
44
|
+
}
|
|
45
|
+
if (from === "ft" && to === "in") {
|
|
46
|
+
return l * inchPerFeet;
|
|
47
|
+
}
|
|
48
|
+
if (from === "in" && to === "ft") {
|
|
49
|
+
return l / inchPerFeet;
|
|
50
|
+
}
|
|
51
|
+
if (from === "ft") {
|
|
52
|
+
l *= meterPerFeet;
|
|
53
|
+
from = "m";
|
|
54
|
+
}
|
|
55
|
+
else if (from === "in") {
|
|
56
|
+
l *= meterPerInch;
|
|
57
|
+
from = "m";
|
|
58
|
+
}
|
|
59
|
+
if (to === "ft") {
|
|
60
|
+
l /= meterPerFeet;
|
|
61
|
+
to = "m";
|
|
62
|
+
}
|
|
63
|
+
else if (to === "in") {
|
|
64
|
+
l /= meterPerInch;
|
|
65
|
+
to = "m";
|
|
66
|
+
}
|
|
67
|
+
if (from === to) {
|
|
68
|
+
return l;
|
|
69
|
+
}
|
|
70
|
+
l *= Math.pow(10, metricUnits.indexOf(from) - metricUnits.indexOf(to));
|
|
71
|
+
return l;
|
|
72
|
+
}
|
package/dist/utilitiesWeb.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare function encodeURIComponents(...components: (string | number | boolean)[]): string;
|
|
2
|
-
export declare function mapQueryString(query: string): Map<string, string>;
|
|
3
|
-
export declare function unmapQueryString(query: Map<string, string>): string;
|
|
1
|
+
export declare function encodeURIComponents(...components: (string | number | boolean)[]): string;
|
|
2
|
+
export declare function mapQueryString(query: string): Map<string, string>;
|
|
3
|
+
export declare function unmapQueryString(query: Map<string, string>): string;
|
|
4
4
|
//# sourceMappingURL=utilitiesWeb.d.ts.map
|
package/dist/utilitiesWeb.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
export function encodeURIComponents(...components) {
|
|
2
|
-
return components.map(encodeURIComponent).join("/");
|
|
3
|
-
}
|
|
4
|
-
export function mapQueryString(query) {
|
|
5
|
-
if (query[0] === "?") {
|
|
6
|
-
query = query.substr(1);
|
|
7
|
-
}
|
|
8
|
-
return query.split("&").reduce((result, keyValueString) => {
|
|
9
|
-
const split = keyValueString.split("=");
|
|
10
|
-
if (split.length === 2) {
|
|
11
|
-
result.set(split[0], decodeURIComponent(split[1]));
|
|
12
|
-
}
|
|
13
|
-
return result;
|
|
14
|
-
}, new Map());
|
|
15
|
-
}
|
|
16
|
-
export function unmapQueryString(query) {
|
|
17
|
-
return Array.from(query)
|
|
18
|
-
.map((kv) => `${kv[0]}=${encodeURIComponent(kv[1])}`)
|
|
19
|
-
.join("&");
|
|
20
|
-
}
|
|
1
|
+
export function encodeURIComponents(...components) {
|
|
2
|
+
return components.map(encodeURIComponent).join("/");
|
|
3
|
+
}
|
|
4
|
+
export function mapQueryString(query) {
|
|
5
|
+
if (query[0] === "?") {
|
|
6
|
+
query = query.substr(1);
|
|
7
|
+
}
|
|
8
|
+
return query.split("&").reduce((result, keyValueString) => {
|
|
9
|
+
const split = keyValueString.split("=");
|
|
10
|
+
if (split.length === 2) {
|
|
11
|
+
result.set(split[0], decodeURIComponent(split[1]));
|
|
12
|
+
}
|
|
13
|
+
return result;
|
|
14
|
+
}, new Map());
|
|
15
|
+
}
|
|
16
|
+
export function unmapQueryString(query) {
|
|
17
|
+
return Array.from(query)
|
|
18
|
+
.map((kv) => `${kv[0]}=${encodeURIComponent(kv[1])}`)
|
|
19
|
+
.join("&");
|
|
20
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@configura/web-utilities",
|
|
3
|
-
"version": "2.1.0-alpha.
|
|
3
|
+
"version": "2.1.0-alpha.3",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
"publishConfig": {
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "2ef8219ac17b71f67995071c25078424cfeb2f68"
|
|
26
26
|
}
|