@math.gl/types 4.0.1 → 4.1.0-alpha.2

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.
@@ -8,7 +8,55 @@ export type TypedArrayConstructor = Int8ArrayConstructor | Uint8ArrayConstructor
8
8
  */
9
9
  export type NumericArray = TypedArray | number[];
10
10
  /**
11
- * TypeScript type covering all typed arrays and classic arrays consisting of numbers
12
- * @note alias for NumericArray
11
+ * TypeScript type for classic arrays consisting of numbers
12
+ * @note Included for completeness / orthogonality, prefer `number[]` in actual use
13
13
  */
14
- export type NumberArray = NumericArray;
14
+ export type NumberArray = number[];
15
+ /** Array with exactly 1 number */
16
+ export type NumberArray1 = [number];
17
+ /** Array with exactly 2 numbers */
18
+ export type NumberArray2 = [number, number];
19
+ /** Array with exactly 3 numbers */
20
+ export type NumberArray3 = [number, number, number];
21
+ /** Array with exactly 4 numbers */
22
+ export type NumberArray4 = [number, number, number, number];
23
+ /** Array with exactly 6 numbers */
24
+ export type NumberArray6 = [number, number, number, number, number, number];
25
+ /** Array with exactly 8 numbers */
26
+ export type NumberArray8 = [number, number, number, number, number, number, number, number];
27
+ /** Array with exactly 9 numbers */
28
+ export type NumberArray9 = [number, number, number, number, number, number, number, number, number];
29
+ /** Array with exactly 12 numbers */
30
+ export type NumberArray12 = [
31
+ number,
32
+ number,
33
+ number,
34
+ number,
35
+ number,
36
+ number,
37
+ number,
38
+ number,
39
+ number,
40
+ number,
41
+ number,
42
+ number
43
+ ];
44
+ /** Array with exactly 16 numbers */
45
+ export type NumberArray16 = [
46
+ number,
47
+ number,
48
+ number,
49
+ number,
50
+ number,
51
+ number,
52
+ number,
53
+ number,
54
+ number,
55
+ number,
56
+ number,
57
+ number,
58
+ number,
59
+ number,
60
+ number,
61
+ number
62
+ ];
@@ -1 +1,4 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
1
4
  export {};
package/dist/bigint.js CHANGED
@@ -1,3 +1,6 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
1
4
  // BigInt compatibility layer
2
5
  // Inspired by ArrowJS (under Apache2 license)
3
6
  // https://github.com/apache/arrow/blob/master/js/src/util/compat.ts
@@ -0,0 +1,10 @@
1
+ /** 2 dimensional bounds [[minX, minY], [maxX, maxY]] */
2
+ export type Bounds2D = [[number, number], [number, number]];
3
+ /** 3 dimensional bounds [[minX, minY, minZ], [maxX, maxY, maxZ]] */
4
+ export type Bounds3D = [[number, number, number], [number, number, number]];
5
+ /** 2 or 3 dimensional bounds [[minX, minY], [maxX, maxY]] or [[minX, minY, minZ], [maxX, maxY, maxZ]] */
6
+ export type Bounds = [[number, number], [number, number]] | [[number, number, number], [number, number, number]];
7
+ /** Checks if a `Bounds` is a `Bounds2D` */
8
+ export declare function isBounds2D(bounds: Bounds): bounds is Bounds2D;
9
+ /** Accepts 2D and 3D bounds and returns a 2D bound, truncating 3D dimension if necessary */
10
+ export declare function getBounds2D(bounds: Bounds): Bounds2D;
@@ -0,0 +1,16 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ /** Checks if a `Bounds` is a `Bounds2D` */
5
+ export function isBounds2D(bounds) {
6
+ return bounds.length === 2;
7
+ }
8
+ /** Accepts 2D and 3D bounds and returns a 2D bound, truncating 3D dimension if necessary */
9
+ export function getBounds2D(bounds) {
10
+ return isBounds2D(bounds)
11
+ ? bounds
12
+ : [
13
+ [bounds[0][0], bounds[0][1]],
14
+ [bounds[1][0], bounds[1][1]]
15
+ ];
16
+ }
package/dist/index.cjs CHANGED
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  // dist/index.js
20
20
  var dist_exports = {};
21
21
  __export(dist_exports, {
22
+ isNumberArray: () => isNumberArray,
22
23
  isNumericArray: () => isNumericArray,
23
24
  isTypedArray: () => isTypedArray
24
25
  });
@@ -26,12 +27,15 @@ module.exports = __toCommonJS(dist_exports);
26
27
 
27
28
  // dist/is-array.js
28
29
  function isTypedArray(value) {
29
- return ArrayBuffer.isView(value) && !(value instanceof DataView) ? value : null;
30
+ return ArrayBuffer.isView(value) && !(value instanceof DataView);
30
31
  }
31
- function isNumericArray(value) {
32
+ function isNumberArray(value) {
32
33
  if (Array.isArray(value)) {
33
- return value.length === 0 || typeof value[0] === "number" ? value : null;
34
+ return value.length === 0 || typeof value[0] === "number";
34
35
  }
35
- return isTypedArray(value);
36
+ return false;
37
+ }
38
+ function isNumericArray(value) {
39
+ return isTypedArray(value) || isNumberArray(value);
36
40
  }
37
41
  //# sourceMappingURL=index.cjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["index.js", "is-array.js"],
4
- "sourcesContent": ["export { isTypedArray, isNumericArray } from \"./is-array.js\";\n", "/**\n * Check is an array is a typed array\n * @param value value to be tested\n * @returns input as TypedArray, or null\n */\nexport function isTypedArray(value) {\n return ArrayBuffer.isView(value) && !(value instanceof DataView) ? value : null;\n}\n/**\n * Check is an array is a numeric array (typed array or array of numbers)\n * @param value value to be tested\n * @returns input as NumericArray, or null\n */\nexport function isNumericArray(value) {\n if (Array.isArray(value)) {\n return value.length === 0 || typeof value[0] === 'number' ? value : null;\n }\n return isTypedArray(value);\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACKO,SAAS,aAAa,OAAO;AAChC,SAAO,YAAY,OAAO,KAAK,KAAK,EAAE,iBAAiB,YAAY,QAAQ;AAC/E;AAMO,SAAS,eAAe,OAAO;AAClC,MAAI,MAAM,QAAQ,KAAK,GAAG;AACtB,WAAO,MAAM,WAAW,KAAK,OAAO,MAAM,OAAO,WAAW,QAAQ;AAAA,EACxE;AACA,SAAO,aAAa,KAAK;AAC7B;",
4
+ "sourcesContent": ["// math.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\nexport { isTypedArray, isNumberArray, isNumericArray } from \"./is-array.js\";\n", "// math.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n/**\n * Check is an array is a typed array\n * @param value value to be tested\n * @returns input with type narrowed to TypedArray, or null\n */\nexport function isTypedArray(value) {\n return ArrayBuffer.isView(value) && !(value instanceof DataView);\n}\n/**\n * Check is an array is an array of numbers)\n * @param value value to be tested\n * @returns input with type narrowed to NumberArray, or null\n */\nexport function isNumberArray(value) {\n if (Array.isArray(value)) {\n return value.length === 0 || typeof value[0] === 'number';\n }\n return false;\n}\n/**\n * Check is an array is a numeric array (typed array or array of numbers)\n * @param value value to be tested\n * @returns input with type narrowed to NumericArray, or null\n */\nexport function isNumericArray(value) {\n return isTypedArray(value) || isNumberArray(value);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACQO,SAAS,aAAa,OAAO;AAChC,SAAO,YAAY,OAAO,KAAK,KAAK,EAAE,iBAAiB;AAC3D;AAMO,SAAS,cAAc,OAAO;AACjC,MAAI,MAAM,QAAQ,KAAK,GAAG;AACtB,WAAO,MAAM,WAAW,KAAK,OAAO,MAAM,OAAO;AAAA,EACrD;AACA,SAAO;AACX;AAMO,SAAS,eAAe,OAAO;AAClC,SAAO,aAAa,KAAK,KAAK,cAAc,KAAK;AACrD;",
6
6
  "names": []
7
7
  }
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- export type { TypedArray, TypedArrayConstructor, NumericArray, NumberArray } from "./array-types.js";
2
- export { isTypedArray, isNumericArray } from "./is-array.js";
1
+ export type { TypedArray, TypedArrayConstructor, NumericArray, NumberArray, NumberArray1, NumberArray2, NumberArray3, NumberArray4, NumberArray6, NumberArray8, NumberArray9, NumberArray12, NumberArray16 } from "./array-types.js";
2
+ export { isTypedArray, isNumberArray, isNumericArray } from "./is-array.js";
3
+ export type { Bounds, Bounds2D, Bounds3D } from "./bounds-types.js";
package/dist/index.js CHANGED
@@ -1 +1,4 @@
1
- export { isTypedArray, isNumericArray } from "./is-array.js";
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ export { isTypedArray, isNumberArray, isNumericArray } from "./is-array.js";
@@ -1,13 +1,19 @@
1
- import { TypedArray, NumericArray } from "./array-types.js";
1
+ import { TypedArray, NumericArray, NumberArray } from "./array-types.js";
2
2
  /**
3
3
  * Check is an array is a typed array
4
4
  * @param value value to be tested
5
- * @returns input as TypedArray, or null
5
+ * @returns input with type narrowed to TypedArray, or null
6
6
  */
7
- export declare function isTypedArray(value: unknown): TypedArray | null;
7
+ export declare function isTypedArray(value: unknown): value is TypedArray;
8
+ /**
9
+ * Check is an array is an array of numbers)
10
+ * @param value value to be tested
11
+ * @returns input with type narrowed to NumberArray, or null
12
+ */
13
+ export declare function isNumberArray(value: unknown): value is NumberArray;
8
14
  /**
9
15
  * Check is an array is a numeric array (typed array or array of numbers)
10
16
  * @param value value to be tested
11
- * @returns input as NumericArray, or null
17
+ * @returns input with type narrowed to NumericArray, or null
12
18
  */
13
- export declare function isNumericArray(value: unknown): NumericArray | null;
19
+ export declare function isNumericArray(value: unknown): value is NumericArray;
package/dist/is-array.js CHANGED
@@ -1,19 +1,30 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
1
4
  /**
2
5
  * Check is an array is a typed array
3
6
  * @param value value to be tested
4
- * @returns input as TypedArray, or null
7
+ * @returns input with type narrowed to TypedArray, or null
5
8
  */
6
9
  export function isTypedArray(value) {
7
- return ArrayBuffer.isView(value) && !(value instanceof DataView) ? value : null;
10
+ return ArrayBuffer.isView(value) && !(value instanceof DataView);
8
11
  }
9
12
  /**
10
- * Check is an array is a numeric array (typed array or array of numbers)
13
+ * Check is an array is an array of numbers)
11
14
  * @param value value to be tested
12
- * @returns input as NumericArray, or null
15
+ * @returns input with type narrowed to NumberArray, or null
13
16
  */
14
- export function isNumericArray(value) {
17
+ export function isNumberArray(value) {
15
18
  if (Array.isArray(value)) {
16
- return value.length === 0 || typeof value[0] === 'number' ? value : null;
19
+ return value.length === 0 || typeof value[0] === 'number';
17
20
  }
18
- return isTypedArray(value);
21
+ return false;
22
+ }
23
+ /**
24
+ * Check is an array is a numeric array (typed array or array of numbers)
25
+ * @param value value to be tested
26
+ * @returns input with type narrowed to NumericArray, or null
27
+ */
28
+ export function isNumericArray(value) {
29
+ return isTypedArray(value) || isNumberArray(value);
19
30
  }
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
9
- "version": "4.0.1",
9
+ "version": "4.1.0-alpha.2",
10
10
  "keywords": [
11
11
  "typescript",
12
12
  "javascript",
@@ -35,5 +35,5 @@
35
35
  "sideEffects": [
36
36
  "./src/bigint.js"
37
37
  ],
38
- "gitHead": "33f369ba3a259f79acc3fa8181190c9da8841648"
38
+ "gitHead": "59eb434870991d06aecff5b1dee38078af0ca447"
39
39
  }
@@ -1,3 +1,7 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
1
5
  /**
2
6
  * TypeScript type covering all typed arrays
3
7
  */
@@ -33,7 +37,64 @@ export type TypedArrayConstructor =
33
37
  export type NumericArray = TypedArray | number[];
34
38
 
35
39
  /**
36
- * TypeScript type covering all typed arrays and classic arrays consisting of numbers
37
- * @note alias for NumericArray
40
+ * TypeScript type for classic arrays consisting of numbers
41
+ * @note Included for completeness / orthogonality, prefer `number[]` in actual use
38
42
  */
39
- export type NumberArray = NumericArray;
43
+ export type NumberArray = number[];
44
+
45
+ /** Array with exactly 1 number */
46
+ export type NumberArray1 = [number];
47
+
48
+ /** Array with exactly 2 numbers */
49
+ export type NumberArray2 = [number, number];
50
+
51
+ /** Array with exactly 3 numbers */
52
+ export type NumberArray3 = [number, number, number];
53
+
54
+ /** Array with exactly 4 numbers */
55
+ export type NumberArray4 = [number, number, number, number];
56
+
57
+ /** Array with exactly 6 numbers */
58
+ export type NumberArray6 = [number, number, number, number, number, number];
59
+
60
+ /** Array with exactly 8 numbers */
61
+ export type NumberArray8 = [number, number, number, number, number, number, number, number];
62
+
63
+ /** Array with exactly 9 numbers */
64
+ export type NumberArray9 = [number, number, number, number, number, number, number, number, number];
65
+
66
+ /** Array with exactly 12 numbers */
67
+ export type NumberArray12 = [
68
+ number,
69
+ number,
70
+ number,
71
+ number,
72
+ number,
73
+ number,
74
+ number,
75
+ number,
76
+ number,
77
+ number,
78
+ number,
79
+ number
80
+ ];
81
+
82
+ /** Array with exactly 16 numbers */
83
+ export type NumberArray16 = [
84
+ number,
85
+ number,
86
+ number,
87
+ number,
88
+ number,
89
+ number,
90
+ number,
91
+ number,
92
+ number,
93
+ number,
94
+ number,
95
+ number,
96
+ number,
97
+ number,
98
+ number,
99
+ number
100
+ ];
package/src/bigint.ts CHANGED
@@ -1,3 +1,7 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
1
5
  // BigInt compatibility layer
2
6
  // Inspired by ArrowJS (under Apache2 license)
3
7
  // https://github.com/apache/arrow/blob/master/js/src/util/compat.ts
@@ -0,0 +1,29 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ /** 2 dimensional bounds [[minX, minY], [maxX, maxY]] */
6
+ export type Bounds2D = [[number, number], [number, number]];
7
+
8
+ /** 3 dimensional bounds [[minX, minY, minZ], [maxX, maxY, maxZ]] */
9
+ export type Bounds3D = [[number, number, number], [number, number, number]];
10
+
11
+ /** 2 or 3 dimensional bounds [[minX, minY], [maxX, maxY]] or [[minX, minY, minZ], [maxX, maxY, maxZ]] */
12
+ export type Bounds =
13
+ | [[number, number], [number, number]]
14
+ | [[number, number, number], [number, number, number]];
15
+
16
+ /** Checks if a `Bounds` is a `Bounds2D` */
17
+ export function isBounds2D(bounds: Bounds): bounds is Bounds2D {
18
+ return bounds.length === 2;
19
+ }
20
+
21
+ /** Accepts 2D and 3D bounds and returns a 2D bound, truncating 3D dimension if necessary */
22
+ export function getBounds2D(bounds: Bounds): Bounds2D {
23
+ return isBounds2D(bounds)
24
+ ? bounds
25
+ : [
26
+ [bounds[0][0], bounds[0][1]],
27
+ [bounds[1][0], bounds[1][1]]
28
+ ];
29
+ }
package/src/index.ts CHANGED
@@ -1,2 +1,23 @@
1
- export type {TypedArray, TypedArrayConstructor, NumericArray, NumberArray} from './array-types';
2
- export {isTypedArray, isNumericArray} from './is-array';
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ export type {
6
+ TypedArray,
7
+ TypedArrayConstructor,
8
+ NumericArray,
9
+ NumberArray,
10
+ NumberArray1,
11
+ NumberArray2,
12
+ NumberArray3,
13
+ NumberArray4,
14
+ NumberArray6,
15
+ NumberArray8,
16
+ NumberArray9,
17
+ NumberArray12,
18
+ NumberArray16
19
+ } from './array-types';
20
+
21
+ export {isTypedArray, isNumberArray, isNumericArray} from './is-array';
22
+
23
+ export type {Bounds, Bounds2D, Bounds3D} from './bounds-types';
package/src/is-array.ts CHANGED
@@ -1,22 +1,35 @@
1
- import {TypedArray, NumericArray} from './array-types';
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import {TypedArray, NumericArray, NumberArray} from './array-types';
2
6
 
3
7
  /**
4
8
  * Check is an array is a typed array
5
9
  * @param value value to be tested
6
- * @returns input as TypedArray, or null
10
+ * @returns input with type narrowed to TypedArray, or null
7
11
  */
8
- export function isTypedArray(value: unknown): TypedArray | null {
9
- return ArrayBuffer.isView(value) && !(value instanceof DataView) ? (value as TypedArray) : null;
12
+ export function isTypedArray(value: unknown): value is TypedArray {
13
+ return ArrayBuffer.isView(value) && !(value instanceof DataView);
10
14
  }
11
15
 
12
16
  /**
13
- * Check is an array is a numeric array (typed array or array of numbers)
17
+ * Check is an array is an array of numbers)
14
18
  * @param value value to be tested
15
- * @returns input as NumericArray, or null
19
+ * @returns input with type narrowed to NumberArray, or null
16
20
  */
17
- export function isNumericArray(value: unknown): NumericArray | null {
21
+ export function isNumberArray(value: unknown): value is NumberArray {
18
22
  if (Array.isArray(value)) {
19
- return value.length === 0 || typeof value[0] === 'number' ? (value as number[]) : null;
23
+ return value.length === 0 || typeof value[0] === 'number';
20
24
  }
21
- return isTypedArray(value);
25
+ return false;
26
+ }
27
+
28
+ /**
29
+ * Check is an array is a numeric array (typed array or array of numbers)
30
+ * @param value value to be tested
31
+ * @returns input with type narrowed to NumericArray, or null
32
+ */
33
+ export function isNumericArray(value: unknown): value is NumericArray {
34
+ return isTypedArray(value) || isNumberArray(value);
22
35
  }