@cornerstonejs/utils 5.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/LICENSE +21 -0
- package/dist/esm/index.d.ts +6 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/utilities/index.d.ts +6 -0
- package/dist/esm/utilities/index.js +5 -0
- package/dist/esm/utilities/logging/index.d.ts +22 -0
- package/dist/esm/utilities/logging/index.js +20 -0
- package/dist/esm/utilities/math/index.d.ts +4 -0
- package/dist/esm/utilities/math/index.js +4 -0
- package/dist/esm/utilities/math/isEqual.d.ts +7 -0
- package/dist/esm/utilities/math/isEqual.js +49 -0
- package/dist/esm/utilities/math/toNumber.d.ts +6 -0
- package/dist/esm/utilities/math/toNumber.js +35 -0
- package/dist/esm/utilities/object/asArray.d.ts +2 -0
- package/dist/esm/utilities/object/asArray.js +7 -0
- package/dist/esm/utilities/object/index.d.ts +2 -0
- package/dist/esm/utilities/object/index.js +2 -0
- package/dist/esm/version.d.ts +1 -0
- package/dist/esm/version.js +1 -0
- package/package.json +90 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Open Health Imaging Foundation
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { version } from './version';
|
|
2
|
+
export * as utilities from './utilities';
|
|
3
|
+
export * as logging from './utilities/logging';
|
|
4
|
+
export { asArray } from './utilities/object';
|
|
5
|
+
export { toNumber, toFiniteNumber, isEqual, isEqualNegative, isEqualAbs, isNumber, DEFAULT_EPSILON, areNumbersEqualWithTolerance, } from './utilities/math';
|
|
6
|
+
export type { Logger } from './utilities/logging';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { version } from './version';
|
|
2
|
+
export * as utilities from './utilities';
|
|
3
|
+
export * as logging from './utilities/logging';
|
|
4
|
+
export { asArray } from './utilities/object';
|
|
5
|
+
export { toNumber, toFiniteNumber, isEqual, isEqualNegative, isEqualAbs, isNumber, DEFAULT_EPSILON, areNumbersEqualWithTolerance, } from './utilities/math';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * as object from './object';
|
|
2
|
+
export * as math from './math';
|
|
3
|
+
export * as logging from './logging';
|
|
4
|
+
export { asArray } from './object';
|
|
5
|
+
export { toNumber, toFiniteNumber, isEqual, isEqualNegative, isEqualAbs, isNumber, DEFAULT_EPSILON, areNumbersEqualWithTolerance, } from './math';
|
|
6
|
+
export type { Logger } from './logging';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export * as object from './object';
|
|
2
|
+
export * as math from './math';
|
|
3
|
+
export * as logging from './logging';
|
|
4
|
+
export { asArray } from './object';
|
|
5
|
+
export { toNumber, toFiniteNumber, isEqual, isEqualNegative, isEqualAbs, isNumber, DEFAULT_EPSILON, areNumbersEqualWithTolerance, } from './math';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { log } from 'dcmjs';
|
|
2
|
+
export type Logger = {
|
|
3
|
+
getLogger: (...categories: string[]) => Logger;
|
|
4
|
+
debug: (...args: unknown[]) => void;
|
|
5
|
+
info: (...args: unknown[]) => void;
|
|
6
|
+
warn: (...args: unknown[]) => void;
|
|
7
|
+
error: (...args: unknown[]) => void;
|
|
8
|
+
setLevel: (level: string | number) => void;
|
|
9
|
+
};
|
|
10
|
+
export declare const cs3dLog: Logger;
|
|
11
|
+
export declare const metadataLog: Logger;
|
|
12
|
+
export declare const coreLog: Logger;
|
|
13
|
+
export declare const toolsLog: Logger;
|
|
14
|
+
export declare const loaderLog: Logger;
|
|
15
|
+
export declare const aiLog: Logger;
|
|
16
|
+
export declare const examplesLog: Logger;
|
|
17
|
+
export declare const workerLog: Logger;
|
|
18
|
+
export declare const dicomConsistencyLog: Logger;
|
|
19
|
+
export declare const imageConsistencyLog: Logger;
|
|
20
|
+
export declare function getRootLogger(name: string): Logger;
|
|
21
|
+
export declare function getLogger(...name: string[]): Logger;
|
|
22
|
+
export { log };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { log } from 'dcmjs';
|
|
2
|
+
export const cs3dLog = getRootLogger('cs3d');
|
|
3
|
+
export const metadataLog = cs3dLog.getLogger('metadata');
|
|
4
|
+
export const coreLog = cs3dLog.getLogger('core');
|
|
5
|
+
export const toolsLog = cs3dLog.getLogger('tools');
|
|
6
|
+
export const loaderLog = cs3dLog.getLogger('dicomImageLoader');
|
|
7
|
+
export const aiLog = cs3dLog.getLogger('ai');
|
|
8
|
+
export const examplesLog = cs3dLog.getLogger('examples');
|
|
9
|
+
export const workerLog = cs3dLog.getLogger('worker');
|
|
10
|
+
export const dicomConsistencyLog = log.getLogger('consistency.dicom');
|
|
11
|
+
export const imageConsistencyLog = log.getLogger('consistency.image');
|
|
12
|
+
export function getRootLogger(name) {
|
|
13
|
+
const logger = log.getLogger(name);
|
|
14
|
+
logger.getLogger = (...names) => getRootLogger(`${name}.${names.join('.')}`);
|
|
15
|
+
return logger;
|
|
16
|
+
}
|
|
17
|
+
export function getLogger(...name) {
|
|
18
|
+
return getRootLogger(name.join('.'));
|
|
19
|
+
}
|
|
20
|
+
export { log };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { toNumber, toFiniteNumber } from './toNumber';
|
|
2
|
+
export { default as toNumberDefault } from './toNumber';
|
|
3
|
+
export { DEFAULT_EPSILON, areNumbersEqualWithTolerance, isEqual, isEqualNegative, isEqualAbs, isNumber, } from './isEqual';
|
|
4
|
+
export { default as isEqualDefault } from './isEqual';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { toNumber, toFiniteNumber } from './toNumber';
|
|
2
|
+
export { default as toNumberDefault } from './toNumber';
|
|
3
|
+
export { DEFAULT_EPSILON, areNumbersEqualWithTolerance, isEqual, isEqualNegative, isEqualAbs, isNumber, } from './isEqual';
|
|
4
|
+
export { default as isEqualDefault } from './isEqual';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const DEFAULT_EPSILON = 0.00001;
|
|
2
|
+
export declare function areNumbersEqualWithTolerance(num1: number, num2: number, tolerance: number): boolean;
|
|
3
|
+
export declare function isEqual<ValueType>(v1: ValueType, v2: ValueType, tolerance?: number): boolean;
|
|
4
|
+
export declare const isEqualNegative: <ValueType>(v1: ValueType, v2: ValueType, tolerance?: any) => boolean;
|
|
5
|
+
export declare const isEqualAbs: <ValueType>(v1: ValueType, v2: ValueType, tolerance?: any) => boolean;
|
|
6
|
+
export declare function isNumber(n: number[] | number): boolean;
|
|
7
|
+
export default isEqual;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export const DEFAULT_EPSILON = 1e-5;
|
|
2
|
+
export function areNumbersEqualWithTolerance(num1, num2, tolerance) {
|
|
3
|
+
return Math.abs(num1 - num2) <= tolerance;
|
|
4
|
+
}
|
|
5
|
+
function areArraysEqual(arr1, arr2, tolerance = DEFAULT_EPSILON) {
|
|
6
|
+
if (arr1.length !== arr2.length) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
for (let i = 0; i < arr1.length; i++) {
|
|
10
|
+
if (!areNumbersEqualWithTolerance(arr1[i], arr2[i], tolerance)) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
function isNumberType(value) {
|
|
17
|
+
return typeof value === 'number';
|
|
18
|
+
}
|
|
19
|
+
function isNumberArrayLike(value) {
|
|
20
|
+
return (value &&
|
|
21
|
+
typeof value === 'object' &&
|
|
22
|
+
'length' in value &&
|
|
23
|
+
typeof value.length === 'number' &&
|
|
24
|
+
value.length > 0 &&
|
|
25
|
+
typeof value[0] === 'number');
|
|
26
|
+
}
|
|
27
|
+
export function isEqual(v1, v2, tolerance = DEFAULT_EPSILON) {
|
|
28
|
+
if (typeof v1 !== typeof v2 || v1 === null || v2 === null) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
if (isNumberType(v1) && isNumberType(v2)) {
|
|
32
|
+
return areNumbersEqualWithTolerance(v1, v2, tolerance);
|
|
33
|
+
}
|
|
34
|
+
if (isNumberArrayLike(v1) && isNumberArrayLike(v2)) {
|
|
35
|
+
return areArraysEqual(v1, v2, tolerance);
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
const negative = (v) => typeof v === 'number' ? -v : v?.map ? v.map(negative) : !v;
|
|
40
|
+
const abs = (v) => typeof v === 'number' ? Math.abs(v) : v?.map ? v.map(abs) : v;
|
|
41
|
+
export const isEqualNegative = (v1, v2, tolerance = undefined) => isEqual(v1, negative(v2), tolerance);
|
|
42
|
+
export const isEqualAbs = (v1, v2, tolerance = undefined) => isEqual(abs(v1), abs(v2), tolerance);
|
|
43
|
+
export function isNumber(n) {
|
|
44
|
+
if (Array.isArray(n)) {
|
|
45
|
+
return isNumber(n[0]);
|
|
46
|
+
}
|
|
47
|
+
return isFinite(n) && !isNaN(n);
|
|
48
|
+
}
|
|
49
|
+
export default isEqual;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
type NumberLike = string | String | number | Number;
|
|
2
|
+
export declare function toFiniteNumber(value: NumberLike | undefined): number | undefined;
|
|
3
|
+
export declare function toFiniteNumber<T extends NumberLike>(value: ArrayLike<T> | undefined): number[] | undefined;
|
|
4
|
+
export declare function toNumber(val: NumberLike | null | undefined): number | undefined;
|
|
5
|
+
export declare function toNumber<T extends NumberLike>(val: ArrayLike<T> | Iterable<T>): number[];
|
|
6
|
+
export default toNumber;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
function isNumberLike(value) {
|
|
2
|
+
return (typeof value === 'string' ||
|
|
3
|
+
typeof value === 'number' ||
|
|
4
|
+
value instanceof String ||
|
|
5
|
+
value instanceof Number);
|
|
6
|
+
}
|
|
7
|
+
export function toFiniteNumber(value) {
|
|
8
|
+
if (value === undefined) {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
if (isNumberLike(value)) {
|
|
12
|
+
const converted = Number(value);
|
|
13
|
+
return Number.isFinite(converted) ? converted : undefined;
|
|
14
|
+
}
|
|
15
|
+
return Array.from(value, (entry) => {
|
|
16
|
+
const converted = Number(entry);
|
|
17
|
+
return Number.isFinite(converted) ? converted : undefined;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
export function toNumber(val) {
|
|
21
|
+
if (val === undefined || val === null) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
if (isNumberLike(val)) {
|
|
25
|
+
return Number(val);
|
|
26
|
+
}
|
|
27
|
+
if (Array.isArray(val)) {
|
|
28
|
+
return val.map((entry) => Number(entry));
|
|
29
|
+
}
|
|
30
|
+
if (typeof val === 'object' && Symbol.iterator in val) {
|
|
31
|
+
return Array.from(val, (entry) => Number(entry));
|
|
32
|
+
}
|
|
33
|
+
return Number(val);
|
|
34
|
+
}
|
|
35
|
+
export default toNumber;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const version = "5.0.0";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const version = '5.0.0';
|
package/package.json
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cornerstonejs/utils",
|
|
3
|
+
"version": "5.0.0",
|
|
4
|
+
"description": "Cornerstone3D shared utility helpers",
|
|
5
|
+
"module": "./dist/esm/index.js",
|
|
6
|
+
"types": "./dist/esm/index.d.ts",
|
|
7
|
+
"repository": "https://github.com/cornerstonejs/cornerstone3D",
|
|
8
|
+
"files": [
|
|
9
|
+
"./dist/"
|
|
10
|
+
],
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/esm/index.js",
|
|
15
|
+
"node": "./dist/esm/index.js",
|
|
16
|
+
"types": "./dist/esm/index.d.ts"
|
|
17
|
+
},
|
|
18
|
+
"./utilities": {
|
|
19
|
+
"import": "./dist/esm/utilities/index.js",
|
|
20
|
+
"node": "./dist/esm/utilities/index.js",
|
|
21
|
+
"types": "./dist/esm/utilities/index.d.ts"
|
|
22
|
+
},
|
|
23
|
+
"./utilities/object": {
|
|
24
|
+
"import": "./dist/esm/utilities/object/index.js",
|
|
25
|
+
"node": "./dist/esm/utilities/object/index.js",
|
|
26
|
+
"types": "./dist/esm/utilities/object/index.d.ts"
|
|
27
|
+
},
|
|
28
|
+
"./utilities/object/*": {
|
|
29
|
+
"import": "./dist/esm/utilities/object/*.js",
|
|
30
|
+
"node": "./dist/esm/utilities/object/*.js",
|
|
31
|
+
"types": "./dist/esm/utilities/object/*.d.ts"
|
|
32
|
+
},
|
|
33
|
+
"./utilities/math": {
|
|
34
|
+
"import": "./dist/esm/utilities/math/index.js",
|
|
35
|
+
"node": "./dist/esm/utilities/math/index.js",
|
|
36
|
+
"types": "./dist/esm/utilities/math/index.d.ts"
|
|
37
|
+
},
|
|
38
|
+
"./utilities/math/*": {
|
|
39
|
+
"import": "./dist/esm/utilities/math/*.js",
|
|
40
|
+
"node": "./dist/esm/utilities/math/*.js",
|
|
41
|
+
"types": "./dist/esm/utilities/math/*.d.ts"
|
|
42
|
+
},
|
|
43
|
+
"./utilities/logging": {
|
|
44
|
+
"import": "./dist/esm/utilities/logging/index.js",
|
|
45
|
+
"node": "./dist/esm/utilities/logging/index.js",
|
|
46
|
+
"types": "./dist/esm/utilities/logging/index.d.ts"
|
|
47
|
+
},
|
|
48
|
+
"./utilities/logging/*": {
|
|
49
|
+
"import": "./dist/esm/utilities/logging/*.js",
|
|
50
|
+
"node": "./dist/esm/utilities/logging/*.js",
|
|
51
|
+
"types": "./dist/esm/utilities/logging/*.d.ts"
|
|
52
|
+
},
|
|
53
|
+
"./version": {
|
|
54
|
+
"import": "./dist/esm/version.js",
|
|
55
|
+
"node": "./dist/esm/version.js",
|
|
56
|
+
"types": "./dist/esm/version.d.ts"
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"publishConfig": {
|
|
60
|
+
"access": "public"
|
|
61
|
+
},
|
|
62
|
+
"scripts": {
|
|
63
|
+
"prebuild": "node ../../scripts/generate-version.js ./",
|
|
64
|
+
"build:esm": "pnpm run prebuild && tsc --project ./tsconfig.json",
|
|
65
|
+
"build:esm:watch": "tsc --project ./tsconfig.json --watch",
|
|
66
|
+
"clean": "rm -rf node_modules/.cache/storybook && shx rm -rf dist",
|
|
67
|
+
"clean:deep": "pnpm run clean && shx rm -rf node_modules",
|
|
68
|
+
"build": "pnpm run build:esm",
|
|
69
|
+
"build:all": "pnpm run build:esm",
|
|
70
|
+
"dev": "tsc --project ./tsconfig.json --watch",
|
|
71
|
+
"api-check": "api-extractor --debug run",
|
|
72
|
+
"lint": "oxlint .",
|
|
73
|
+
"prepublishOnly": "pnpm run build"
|
|
74
|
+
},
|
|
75
|
+
"dependencies": {
|
|
76
|
+
"dcmjs": "0.50.1"
|
|
77
|
+
},
|
|
78
|
+
"contributors": [
|
|
79
|
+
{
|
|
80
|
+
"name": "Cornerstone.js Contributors",
|
|
81
|
+
"url": "https://github.com/orgs/cornerstonejs/people"
|
|
82
|
+
}
|
|
83
|
+
],
|
|
84
|
+
"license": "MIT",
|
|
85
|
+
"funding": {
|
|
86
|
+
"type": "individual",
|
|
87
|
+
"url": "https://ohif.org/donate"
|
|
88
|
+
},
|
|
89
|
+
"gitHead": "d6f3fba43abcbaaf7468ff534588f6a88720b875"
|
|
90
|
+
}
|