@konfirm/geojson 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.
Files changed (122) hide show
  1. package/.editorconfig +16 -0
  2. package/.github/workflows/release.yml +21 -0
  3. package/.github/workflows/tests.yml +56 -0
  4. package/CHANGELOG.md +21 -0
  5. package/LICENSE +21 -0
  6. package/README.md +260 -0
  7. package/dist/Domain/Constants.d.ts +5 -0
  8. package/dist/Domain/GeoJSON/Concept/Altitude.d.ts +3 -0
  9. package/dist/Domain/GeoJSON/Concept/BoundingBox.d.ts +6 -0
  10. package/dist/Domain/GeoJSON/Concept/ExteriorRing.d.ts +4 -0
  11. package/dist/Domain/GeoJSON/Concept/GeoJSONObject.d.ts +11 -0
  12. package/dist/Domain/GeoJSON/Concept/InteriorRing.d.ts +4 -0
  13. package/dist/Domain/GeoJSON/Concept/Latitude.d.ts +3 -0
  14. package/dist/Domain/GeoJSON/Concept/LinearRing.d.ts +4 -0
  15. package/dist/Domain/GeoJSON/Concept/Longitude.d.ts +3 -0
  16. package/dist/Domain/GeoJSON/Concept/Position.d.ts +7 -0
  17. package/dist/Domain/GeoJSON/Feature.d.ts +12 -0
  18. package/dist/Domain/GeoJSON/FeatureCollection.d.ts +8 -0
  19. package/dist/Domain/GeoJSON/GeoJSON.d.ts +7 -0
  20. package/dist/Domain/GeoJSON/Geometry/LineString.d.ts +11 -0
  21. package/dist/Domain/GeoJSON/Geometry/MultiLineString.d.ts +7 -0
  22. package/dist/Domain/GeoJSON/Geometry/MultiPoint.d.ts +8 -0
  23. package/dist/Domain/GeoJSON/Geometry/MultiPolygon.d.ts +7 -0
  24. package/dist/Domain/GeoJSON/Geometry/Point.d.ts +11 -0
  25. package/dist/Domain/GeoJSON/Geometry/Polygon.d.ts +11 -0
  26. package/dist/Domain/GeoJSON/Geometry.d.ts +9 -0
  27. package/dist/Domain/GeoJSON/GeometryCollection.d.ts +8 -0
  28. package/dist/Domain/GeoJSON/GeometryObject.d.ts +12 -0
  29. package/dist/Domain/Guards/Number.d.ts +3 -0
  30. package/dist/Domain/Guards/Tuple.d.ts +3 -0
  31. package/dist/Domain/Iterator/IterablePair.d.ts +32 -0
  32. package/dist/Domain/Iterator/SimpleGeometry.d.ts +90 -0
  33. package/dist/Domain/Utility/Calculate.d.ts +9 -0
  34. package/dist/Domain/Utility/Distance.d.ts +3 -0
  35. package/dist/Domain/Utility/Intersect.d.ts +2 -0
  36. package/dist/Domain/Utility/Segments.d.ts +2 -0
  37. package/dist/Domain/Utility/Winding.d.ts +3 -0
  38. package/dist/geojson.cjs.js +655 -0
  39. package/dist/geojson.cjs.min.js +1 -0
  40. package/dist/geojson.d.ts +198 -0
  41. package/dist/geojson.es.js +627 -0
  42. package/dist/geojson.es.min.js +1 -0
  43. package/dist/geojson.js +660 -0
  44. package/dist/geojson.min.js +1 -0
  45. package/dist/main.d.ts +15 -0
  46. package/package.json +63 -0
  47. package/rollup.config.mjs +43 -0
  48. package/source/Domain/Constants.ts +5 -0
  49. package/source/Domain/GeoJSON/Concept/Altitude.ts +9 -0
  50. package/source/Domain/GeoJSON/Concept/BoundingBox.ts +31 -0
  51. package/source/Domain/GeoJSON/Concept/ExteriorRing.ts +12 -0
  52. package/source/Domain/GeoJSON/Concept/GeoJSONObject.ts +23 -0
  53. package/source/Domain/GeoJSON/Concept/InteriorRing.ts +12 -0
  54. package/source/Domain/GeoJSON/Concept/Latitude.ts +7 -0
  55. package/source/Domain/GeoJSON/Concept/LinearRing.ts +14 -0
  56. package/source/Domain/GeoJSON/Concept/Longitude.ts +7 -0
  57. package/source/Domain/GeoJSON/Concept/Position.ts +18 -0
  58. package/source/Domain/GeoJSON/Feature.ts +24 -0
  59. package/source/Domain/GeoJSON/FeatureCollection.ts +16 -0
  60. package/source/Domain/GeoJSON/GeoJSON.ts +9 -0
  61. package/source/Domain/GeoJSON/Geometry/LineString.ts +12 -0
  62. package/source/Domain/GeoJSON/Geometry/MultiLineString.ts +9 -0
  63. package/source/Domain/GeoJSON/Geometry/MultiPoint.ts +10 -0
  64. package/source/Domain/GeoJSON/Geometry/MultiPolygon.ts +9 -0
  65. package/source/Domain/GeoJSON/Geometry/Point.ts +12 -0
  66. package/source/Domain/GeoJSON/Geometry/Polygon.ts +20 -0
  67. package/source/Domain/GeoJSON/Geometry.ts +11 -0
  68. package/source/Domain/GeoJSON/GeometryCollection.ts +23 -0
  69. package/source/Domain/GeoJSON/GeometryObject.ts +20 -0
  70. package/source/Domain/Guards/Number.ts +13 -0
  71. package/source/Domain/Guards/Tuple.ts +6 -0
  72. package/source/Domain/Guards/Utility.ts +1 -0
  73. package/source/Domain/Iterator/IterablePair.ts +47 -0
  74. package/source/Domain/Iterator/SimpleGeometry.ts +137 -0
  75. package/source/Domain/Utility/Calculate.ts +143 -0
  76. package/source/Domain/Utility/Distance.ts +56 -0
  77. package/source/Domain/Utility/Intersect.ts +42 -0
  78. package/source/Domain/Utility/Numeric.ts +8 -0
  79. package/source/Domain/Utility/Segments.ts +5 -0
  80. package/source/Domain/Utility/Winding.ts +19 -0
  81. package/source/main.ts +20 -0
  82. package/test/Domain/GeoJSON/Concept/Altitude.ts +58 -0
  83. package/test/Domain/GeoJSON/Concept/BoundingBox.ts +77 -0
  84. package/test/Domain/GeoJSON/Concept/ExteriorRing.ts +65 -0
  85. package/test/Domain/GeoJSON/Concept/GeoJSONObject.ts +56 -0
  86. package/test/Domain/GeoJSON/Concept/InteriorRing.ts +65 -0
  87. package/test/Domain/GeoJSON/Concept/Latitude.ts +56 -0
  88. package/test/Domain/GeoJSON/Concept/LinearRing.ts +63 -0
  89. package/test/Domain/GeoJSON/Concept/Longitude.ts +56 -0
  90. package/test/Domain/GeoJSON/Concept/Position.ts +56 -0
  91. package/test/Domain/GeoJSON/Feature.ts +9 -0
  92. package/test/Domain/GeoJSON/FeatureCollection.ts +9 -0
  93. package/test/Domain/GeoJSON/GeoJSON.ts +21 -0
  94. package/test/Domain/GeoJSON/Geometry/LineString.ts +11 -0
  95. package/test/Domain/GeoJSON/Geometry/MultiLineString.ts +11 -0
  96. package/test/Domain/GeoJSON/Geometry/MultiPoint.ts +11 -0
  97. package/test/Domain/GeoJSON/Geometry/MultiPolygon.ts +11 -0
  98. package/test/Domain/GeoJSON/Geometry/Point.ts +11 -0
  99. package/test/Domain/GeoJSON/Geometry/Polygon.ts +11 -0
  100. package/test/Domain/GeoJSON/Geometry.ts +9 -0
  101. package/test/Domain/GeoJSON/GeometryCollection.ts +9 -0
  102. package/test/Domain/GeoJSON/GeometryObject.ts +4 -0
  103. package/test/Domain/Guards/Number.ts +49 -0
  104. package/test/Domain/Guards/Tuple.ts +27 -0
  105. package/test/Domain/Iterator/IterablePair.ts +203 -0
  106. package/test/Domain/Iterator/SimpleGeometry.ts +195 -0
  107. package/test/Domain/Utility/Calculate.ts +178 -0
  108. package/test/Domain/Utility/Distance.ts +19 -0
  109. package/test/Domain/Utility/Intersect.ts +54 -0
  110. package/test/Domain/Utility/Numeric.ts +30 -0
  111. package/test/Domain/Utility/Winding.ts +52 -0
  112. package/test/README.ts +123 -0
  113. package/test/data/Distance.ts +51 -0
  114. package/test/data/HolySee.ts +74 -0
  115. package/test/data/Intersect.ts +300 -0
  116. package/test/data/Italy.ts +2883 -0
  117. package/test/data/SanMarino.ts +83 -0
  118. package/test/data/Shapes.ts +107 -0
  119. package/test/helper/geometry.ts +76 -0
  120. package/test/helper/malform.ts +82 -0
  121. package/test/main.ts +4 -0
  122. package/tsconfig.json +12 -0
@@ -0,0 +1,56 @@
1
+ import test from 'tape';
2
+ import { each } from 'template-literal-each';
3
+ import * as Export from '../../../../source/Domain/GeoJSON/Concept/GeoJSONObject';
4
+ import { exported } from '../../../helper/geometry';
5
+
6
+ exported('Domain/GeoJSON/Concept/GeoJSONObject', Export, 'isGeoJSONObject', 'isStrictGeoJSONObject');
7
+
8
+ const { isGeoJSONObject, isStrictGeoJSONObject } = Export;
9
+
10
+ test('Domain/GeoJSON/Concept/GeoJSONObject - isGeoJSONObject', (t) => {
11
+ each`
12
+ type | bbox | valid
13
+ -------------|-------------------------------|-------
14
+ Type | | yes
15
+ Type | ${[0, 0, 0, 0]} | yes
16
+ Type | ${[0, 0, 0, 0, 0, 0]} | yes
17
+ Type | ${[-181, -91, 0, 181, 91, 0]} | yes
18
+ ${undefined} | | no
19
+ ${null} | | no
20
+ ${true} | | no
21
+ ${false} | | no
22
+ ${12345} | | no
23
+ `(({ type, bbox, valid }: any) => {
24
+ const validate = isGeoJSONObject(type);
25
+ const input = Object.assign({ type }, bbox ? { bbox } : {});
26
+
27
+ t.equal(typeof validate, 'function', `creates isGeoJSONObject validator for type ${JSON.stringify(type)}`);
28
+ t.equal(validate(input), valid === 'yes', `type ${JSON.stringify(type)} validates ${JSON.stringify(input)} ${valid}`);
29
+ });
30
+
31
+ t.end();
32
+ });
33
+
34
+ test('Domain/GeoJSON/Concept/GeoJSONObject - isStrictGeoJSONObject', (t) => {
35
+ each`
36
+ type | bbox | valid
37
+ -------------|-------------------------------|-------
38
+ Type | | yes
39
+ Type | ${[0, 0, 0, 0]} | yes
40
+ Type | ${[0, 0, 0, 0, 0, 0]} | yes
41
+ Type | ${[-181, -91, 0, 181, 91, 0]} | no
42
+ ${undefined} | | no
43
+ ${null} | | no
44
+ ${true} | | no
45
+ ${false} | | no
46
+ ${12345} | | no
47
+ `(({ type, bbox, valid }: any) => {
48
+ const validate = isStrictGeoJSONObject(type);
49
+ const input = Object.assign({ type }, bbox ? { bbox } : {});
50
+
51
+ t.equal(typeof validate, 'function', `creates isStrictGeoJSONObject validator for type ${JSON.stringify(type)}`);
52
+ t.equal(validate(input), valid === 'yes', `type ${JSON.stringify(type)} validates ${JSON.stringify(input)} ${valid}`);
53
+ });
54
+
55
+ t.end();
56
+ });
@@ -0,0 +1,65 @@
1
+ import test from 'tape';
2
+ import { each } from 'template-literal-each';
3
+ import * as Export from '../../../../source/Domain/GeoJSON/Concept/InteriorRing';
4
+ import { exported } from '../../../helper/geometry';
5
+ import { coordinates as Italy } from '../../../data/Italy';
6
+ import { coordinates as SanMarino, polygon } from '../../../data/SanMarino';
7
+ import { coordinates as HolySee } from '../../../data/HolySee';
8
+
9
+ exported('Domain/GeoJSON/Concept/InteriorRing', Export, 'isInteriorRing', 'isStrictInteriorRing');
10
+
11
+ const { isInteriorRing, isStrictInteriorRing } = Export;
12
+
13
+ test('Domain/GeoJSON/Concept/InteriorRing - isInteriorRing', (t) => {
14
+ each`
15
+ input | valid
16
+ -------------------------------------------------|----
17
+ ${undefined} | no
18
+ ${null} | no
19
+ ${'[[1,0],[1,1],[0,1],[1,0]]'} | no
20
+ ${[[1, 0], [1, 1], [0, 1], [0, 0.5], [1, 0]]} | yes
21
+ ${[[1, 0], [0, 0.5], [0, 1], [1, 1], [1, 0]]} | yes
22
+ ${[[1, 0], [1, 1], [0, 1], [1, 0]]} | yes
23
+ ${[[1, 0], [1, 1], [0, 1], [0, 0]]} | no
24
+ ${[[1, 0], [1, 1], [1, 0]]} | no
25
+ ${[[1, 0], [1, 0]]} | no
26
+ ${[[1, 0]]} | no
27
+ ${[[-181, -91], [0, -91], [0, 91], [-181, -91]]} | yes
28
+ `(({ input, valid }) => {
29
+ t.equal(isInteriorRing(input), valid === 'yes', `[${input}] isInteriorRing ${valid}`);
30
+ });
31
+
32
+ t.ok(Italy.every((polygon) => polygon.every(isInteriorRing)), 'coordinates for Italy polygon all match isInteriorRing');
33
+ t.notOk(SanMarino.every(isInteriorRing), 'coordinates for SanMarino does not match isInteriorRing');
34
+ t.notOk(HolySee.every(isInteriorRing), 'coordinates for HolySee does not match isInteriorRing');
35
+
36
+ t.end();
37
+ });
38
+
39
+ test('Domain/GeoJSON/Concept/InteriorRing - isStrictInteriorRing', (t) => {
40
+ each`
41
+ input | valid
42
+ -------------------------------------------------|----
43
+ ${undefined} | no
44
+ ${null} | no
45
+ ${'[[1,0],[1,1],[0,1],[1,0]]'} | no
46
+ ${[[1, 0], [1, 1], [0, 1], [0, 0.5], [1, 0]]} | yes
47
+ ${[[1, 0], [0, 0.5], [0, 1], [1, 1], [1, 0]]} | no
48
+ ${[[1, 0], [1, 1], [0, 1], [1, 0]]} | yes
49
+ ${[[1, 0], [1, 1], [0, 1], [0, 0]]} | no
50
+ ${[[1, 0], [1, 1], [1, 0]]} | no
51
+ ${[[1, 0], [1, 0]]} | no
52
+ ${[[1, 0]]} | no
53
+ ${[[-181, -91], [0, -91], [0, 91], [-181, -91]]} | no
54
+ `(({ input, valid }) => {
55
+ t.equal(isStrictInteriorRing(input), valid === 'yes', `[${input}] isStrictInteriorRing ${valid}`);
56
+ });
57
+
58
+ t.notOk(Italy.every((polygon) => polygon.every(isStrictInteriorRing)), 'coordinates for Italy polygon do not match isStrictInteriorRing');
59
+ t.ok(Italy.every((polygon) => !isStrictInteriorRing(polygon[0])), 'first polygon coordinates for Italy none match isStrictInteriorRing');
60
+ t.ok(Italy.filter((polygon) => polygon.length > 1).every((polygon) => polygon.slice(1).every(isStrictInteriorRing)), 'second+ polygon coordinates for Italy none match isStrictInteriorRing')
61
+ t.notOk(SanMarino.every(isStrictInteriorRing), 'coordinates for SanMarino does not match isStrictInteriorRing');
62
+ t.notOk(HolySee.every(isStrictInteriorRing), 'coordinates for HolySee does not match isStrictInteriorRing');
63
+
64
+ t.end();
65
+ });
@@ -0,0 +1,56 @@
1
+ import test from 'tape';
2
+ import { each } from 'template-literal-each';
3
+ import * as Export from '../../../../source/Domain/GeoJSON/Concept/Latitude';
4
+ import { exported } from '../../../helper/geometry';
5
+
6
+ exported('Domain/GeoJSON/Concept/Latitude', Export, 'isLatitude', 'isStrictLatitude');
7
+
8
+ const { isLatitude, isStrictLatitude } = Export;
9
+
10
+ test('Domain/GeoJSON/Concept/Latitude - isLatitude', (t) => {
11
+ each`
12
+ input | valid
13
+ ----------------|-------
14
+ ${0} | yes
15
+ ${0.0000000001} | yes
16
+ ${51.9851034} | yes
17
+ ${-90} | yes
18
+ ${-90.1} | yes
19
+ ${90} | yes
20
+ ${90.1} | yes
21
+ ${-Infinity} | no
22
+ ${Infinity} | no
23
+ ${NaN} | no
24
+ ${'1234'} | no
25
+ ${false} | no
26
+ ${true} | no
27
+ `(({ input, valid }) => {
28
+ t.equal(isLatitude(input), valid === 'yes', `${input} ${valid}`);
29
+ });
30
+
31
+ t.end();
32
+ });
33
+
34
+ test('Domain/GeoJSON/Concept/Latitude - isStrictLatitude', (t) => {
35
+ each`
36
+ input | valid
37
+ ----------------|-------
38
+ ${0} | yes
39
+ ${0.0000000001} | yes
40
+ ${51.9851034} | yes
41
+ ${-90} | yes
42
+ ${-90.1} | no
43
+ ${90} | yes
44
+ ${90.1} | no
45
+ ${-Infinity} | no
46
+ ${Infinity} | no
47
+ ${NaN} | no
48
+ ${'1234'} | no
49
+ ${false} | no
50
+ ${true} | no
51
+ `(({ input, valid }) => {
52
+ t.equal(isStrictLatitude(input), valid === 'yes', `${input} ${valid}`);
53
+ });
54
+
55
+ t.end();
56
+ });
@@ -0,0 +1,63 @@
1
+ import test from 'tape';
2
+ import { each } from 'template-literal-each';
3
+ import * as Export from '../../../../source/Domain/GeoJSON/Concept/LinearRing';
4
+ import { exported } from '../../../helper/geometry';
5
+ import { coordinates as Italy } from '../../../data/Italy';
6
+ import { coordinates as SanMarino } from '../../../data/SanMarino';
7
+ import { coordinates as HolySee } from '../../../data/HolySee';
8
+
9
+ exported('Domain/GeoJSON/Concept/LinearRing', Export, 'isLinearRing', 'isStrictLinearRing');
10
+
11
+ const { isLinearRing, isStrictLinearRing } = Export;
12
+
13
+ test('Domain/GeoJSON/Concept/LinearRing - isLinearRing', (t) => {
14
+ each`
15
+ input | valid
16
+ -------------------------------------------------|----
17
+ ${undefined} | no
18
+ ${null} | no
19
+ ${'[[1,0],[1,1],[0,1],[1,0]]'} | no
20
+ ${[[1, 0], [1, 1], [0, 1], [0, 0.5], [1, 0]]} | yes
21
+ ${[[1, 0], [0, 0.5], [0, 1], [1, 1], [1, 0]]} | yes
22
+ ${[[1, 0], [1, 1], [0, 1], [1, 0]]} | yes
23
+ ${[[1, 0], [1, 1], [0, 1], [0, 0]]} | no
24
+ ${[[1, 0], [1, 1], [1, 0]]} | no
25
+ ${[[1, 0], [1, 0]]} | no
26
+ ${[[1, 0]]} | no
27
+ ${[[-181, -91], [0, -91], [0, 91], [-181, -91]]} | yes
28
+ `(({ input, valid }) => {
29
+ t.equal(isLinearRing(input), valid === 'yes', `[${input}] isLinearRing ${valid}`);
30
+ });
31
+
32
+ t.ok(Italy.every((polygon) => polygon.every(isLinearRing)), 'coordinates for Italy polygon all match isLinearRing');
33
+ t.notOk(SanMarino.every(isLinearRing), 'coordinates for SanMarino does not match isLinearRing');
34
+ t.notOk(HolySee.every(isLinearRing), 'coordinates for HolySee does not match isLinearRing');
35
+
36
+ t.end();
37
+ });
38
+
39
+ test('Domain/GeoJSON/Concept/LinearRing - isStrictLinearRing', (t) => {
40
+ each`
41
+ input | valid
42
+ -------------------------------------------------|----
43
+ ${undefined} | no
44
+ ${null} | no
45
+ ${'[[1,0],[1,1],[0,1],[1,0]]'} | no
46
+ ${[[1, 0], [1, 1], [0, 1], [0, 0.5], [1, 0]]} | yes
47
+ ${[[1, 0], [0, 0.5], [0, 1], [1, 1], [1, 0]]} | yes
48
+ ${[[1, 0], [1, 1], [0, 1], [1, 0]]} | yes
49
+ ${[[1, 0], [1, 1], [0, 1], [0, 0]]} | no
50
+ ${[[1, 0], [1, 1], [1, 0]]} | no
51
+ ${[[1, 0], [1, 0]]} | no
52
+ ${[[1, 0]]} | no
53
+ ${[[-181, -91], [0, -91], [0, 91], [-181, -91]]} | no
54
+ `(({ input, valid }) => {
55
+ t.equal(isStrictLinearRing(input), valid === 'yes', `[${input}] isStrictLinearRing ${valid}`);
56
+ });
57
+
58
+ t.ok(Italy.every((polygon) => polygon.every(isStrictLinearRing)), 'coordinates for Italy polygon all match isStrictLinearRing');
59
+ t.notOk(SanMarino.every(isStrictLinearRing), 'coordinates for SanMarino does not match isStrictLinearRing');
60
+ t.notOk(HolySee.every(isStrictLinearRing), 'coordinates for HolySee does not match isStrictLinearRing');
61
+
62
+ t.end();
63
+ });
@@ -0,0 +1,56 @@
1
+ import test from 'tape';
2
+ import { each } from 'template-literal-each';
3
+ import * as Export from '../../../../source/Domain/GeoJSON/Concept/Longitude';
4
+ import { exported } from '../../../helper/geometry';
5
+
6
+ exported('Domain/GeoJSON/Concept/Longitude', Export, 'isLongitude', 'isStrictLongitude');
7
+
8
+ const { isLongitude, isStrictLongitude } = Export;
9
+
10
+ test('Domain/GeoJSON/Concept/Longitude - isLongitude', (t) => {
11
+ each`
12
+ input | valid
13
+ ----------------|-------
14
+ ${0} | yes
15
+ ${0.0000000001} | yes
16
+ ${5.8987296} | yes
17
+ ${-180} | yes
18
+ ${-180.1} | yes
19
+ ${180} | yes
20
+ ${180.1} | yes
21
+ ${-Infinity} | no
22
+ ${Infinity} | no
23
+ ${NaN} | no
24
+ ${'1234'} | no
25
+ ${false} | no
26
+ ${true} | no
27
+ `(({ input, valid }) => {
28
+ t.equal(isLongitude(input), valid === 'yes', `${input} ${valid}`);
29
+ });
30
+
31
+ t.end();
32
+ });
33
+
34
+ test('Domain/GeoJSON/Concept/Longitude - isStrictLongitude', (t) => {
35
+ each`
36
+ input | valid
37
+ ----------------|-------
38
+ ${0} | yes
39
+ ${0.0000000001} | yes
40
+ ${5.8987296} | yes
41
+ ${-180} | yes
42
+ ${-180.1} | no
43
+ ${180} | yes
44
+ ${180.1} | no
45
+ ${-Infinity} | no
46
+ ${Infinity} | no
47
+ ${NaN} | no
48
+ ${'1234'} | no
49
+ ${false} | no
50
+ ${true} | no
51
+ `(({ input, valid }) => {
52
+ t.equal(isStrictLongitude(input), valid === 'yes', `${input} ${valid}`);
53
+ });
54
+
55
+ t.end();
56
+ });
@@ -0,0 +1,56 @@
1
+ import test from 'tape';
2
+ import * as Export from '../../../../source/Domain/GeoJSON/Concept/Position';
3
+ import { coordinates } from '../../../data/HolySee';
4
+ import { exported } from '../../../helper/geometry';
5
+
6
+ exported('Domain/GeoJSON/Concept/Position', Export, 'isPosition', 'isStrictPosition', 'isEquivalentPosition');
7
+
8
+ const { isPosition, isStrictPosition, isEquivalentPosition } = Export;
9
+ const altitude = coordinates.map(([lon, lat, alt = 1.23]) => [lon, lat, alt]);
10
+
11
+ test('Domain/GeoJSON/Concept/Position - isPosition', (t) => {
12
+ t.ok(coordinates.every(isPosition), 'all coordinates match isPosition');
13
+ t.ok(altitude.every(isPosition), 'all coordinates with altitude match isPosition');
14
+
15
+ t.notOk(isPosition([Infinity, 0, 0]), `[Infinity, 0, 0] is not a Position`);
16
+ t.notOk(isPosition([0, Infinity, 0]), `[0, Infinity, 0] is not a Position`);
17
+ t.notOk(isPosition([0, 0, Infinity]), `[0, 0, Infinity] is not a Position`);
18
+ t.ok(isPosition([0, 0, 0]), `[0, 0, 0] is Position`);
19
+ t.ok(isPosition([-181, 0, 0]), `[-181, 0, 0] is Position`);
20
+ t.ok(isPosition([0, -91, 0]), `[0, -91, 0] is Position`);
21
+ t.ok(isPosition([0, 0, -7000000]), `[0, 0, -7000000] is Position`);
22
+ t.ok(isPosition([-181, -91, 0]), `[-181, -91, 0] is Position`);
23
+ t.ok(isPosition([0, -91, -7000000]), `[0, -91, -7000000] is Position`);
24
+ t.ok(isPosition([-181, 0, -7000000]), `[-181, 0, -7000000] is Position`);
25
+ t.ok(isPosition([-181, -91, -7000000]), `[-181, -91, -7000000] is Position`);
26
+
27
+ t.end();
28
+ });
29
+
30
+ test('Domain/GeoJSON/Concept/Position - isStrictPosition', (t) => {
31
+ t.ok(coordinates.every(isStrictPosition), 'all coordinates match isStrictPosition');
32
+ t.ok(altitude.every(isStrictPosition), 'all coordinates with altitude match isStrictPosition');
33
+
34
+ t.notOk(isStrictPosition([Infinity, 0, 0]), `[Infinity, 0, 0] is not a strict Position`);
35
+ t.notOk(isStrictPosition([0, Infinity, 0]), `[0, Infinity, 0] is not a strict Position`);
36
+ t.notOk(isStrictPosition([0, 0, Infinity]), `[0, 0, Infinity] is not a strict Position`);
37
+ t.ok(isStrictPosition([0, 0, 0]), `[0, 0, 0] is strict Position`);
38
+ t.notOk(isStrictPosition([-181, 0, 0]), `[-181, 0, 0] is not a strict Position`);
39
+ t.notOk(isStrictPosition([0, -91, 0]), `[0, -91, 0] is not a strict Position`);
40
+ t.notOk(isStrictPosition([0, 0, -7000000]), `[0, 0, -7000000] is not a strict Position`);
41
+ t.notOk(isStrictPosition([-181, -91, 0]), `[-181, -91, 0] is not a strict Position`);
42
+ t.notOk(isStrictPosition([0, -91, -7000000]), `[0, -91, -7000000] is not a strict Position`);
43
+ t.notOk(isStrictPosition([-181, 0, -7000000]), `[-181, 0, -7000000] is not a strict Position`);
44
+ t.notOk(isStrictPosition([-181, -91, -7000000]), `[-181, -91, -7000000] is not a strict Position`);
45
+
46
+ t.end();
47
+ });
48
+
49
+ test('Domain/GeoJSON/Concept/Position - isEquivalentPosition', (t) => {
50
+ t.ok(isEquivalentPosition([1.23456789, 2.3456789], [1.23456789, 2.3456789]), `[1.23456789,2.3456789] and [1.23456789,2.3456789] are equivalent`);
51
+ t.ok(isEquivalentPosition([1.23456789, 2.3456789, 3.456789], [1.23456789, 2.3456789, 3.456789]), `[1.23456789,2.3456789,3.456789] and [1.23456789,2.3456789,3.456789] are equivalent`);
52
+ t.notOk(isEquivalentPosition([1.23456789, 2.3456789, 3.456789], [1.23456789, 2.3456789]), `[1.23456789,2.3456789,3.456789] and [1.23456789,2.3456789] are not equivalent`);
53
+ t.notOk(isEquivalentPosition([1.23456789, 2.3456789], [1.23456789, 2.3456789, , 3.456789]), `[1.23456789,2.3456789] and [1.23456789,2.3456789,,3.456789] are not equivalent`);
54
+
55
+ t.end();
56
+ });
@@ -0,0 +1,9 @@
1
+ import * as Export from '../../../source/Domain/GeoJSON/Feature';
2
+ import { runner } from '../../helper/geometry';
3
+
4
+ runner(
5
+ 'Domain/GeoJSON/Feature',
6
+ Export,
7
+ 'isFeature',
8
+ 'isStrictFeature',
9
+ );
@@ -0,0 +1,9 @@
1
+ import * as Export from '../../../source/Domain/GeoJSON/FeatureCollection';
2
+ import { runner } from '../../helper/geometry';
3
+
4
+ runner(
5
+ 'Domain/GeoJSON/FeatureCollection',
6
+ Export,
7
+ 'isFeatureCollection',
8
+ 'isStrictFeatureCollection',
9
+ );
@@ -0,0 +1,21 @@
1
+ import * as Export from '../../../source/Domain/GeoJSON/GeoJSON';
2
+ import { runner } from '../../helper/geometry';
3
+
4
+ const types = [
5
+ 'Point',
6
+ 'MultiPoint',
7
+ 'LineString',
8
+ 'MultiLineString',
9
+ 'Polygon',
10
+ 'MultiPolygon',
11
+ 'GeometryCollection',
12
+ 'Feature',
13
+ 'FeatureCollection',
14
+ ]
15
+
16
+ runner(
17
+ 'Domain/GeoJSON/GeoJSON',
18
+ Export,
19
+ ['isGeoJSON', types],
20
+ ['isStrictGeoJSON', types],
21
+ );
@@ -0,0 +1,11 @@
1
+ import * as Export from '../../../../source/Domain/GeoJSON/Geometry/LineString';
2
+ import { runner } from '../../../helper/geometry';
3
+
4
+ runner(
5
+ 'Domain/GeoJSON/Geometry/LineString',
6
+ Export,
7
+ ['isLineStringCoordinates', ['MultiPoint']],
8
+ 'isLineString',
9
+ ['isStrictLineStringCoordinates', ['MultiPoint']],
10
+ 'isStrictLineString',
11
+ );
@@ -0,0 +1,11 @@
1
+ import * as Export from '../../../../source/Domain/GeoJSON/Geometry/MultiLineString';
2
+ import { runner } from '../../../helper/geometry';
3
+
4
+ runner(
5
+ 'Domain/GeoJSON/Geometry/MultiLineString',
6
+ Export,
7
+ ['isMultiLineStringCoordinates', ['Polygon']],
8
+ 'isMultiLineString',
9
+ ['isStrictMultiLineStringCoordinates', ['Polygon']],
10
+ 'isStrictMultiLineString',
11
+ );
@@ -0,0 +1,11 @@
1
+ import * as Export from '../../../../source/Domain/GeoJSON/Geometry/MultiPoint';
2
+ import { runner } from '../../../helper/geometry';
3
+
4
+ runner(
5
+ 'Domain/GeoJSON/Geometry/MultiPoint',
6
+ Export,
7
+ ['isMultiPointCoordinates', ['LineString']],
8
+ 'isMultiPoint',
9
+ ['isStrictMultiPointCoordinates', ['LineString']],
10
+ 'isStrictMultiPoint',
11
+ );
@@ -0,0 +1,11 @@
1
+ import * as Export from '../../../../source/Domain/GeoJSON/Geometry/MultiPolygon';
2
+ import { runner } from '../../../helper/geometry';
3
+
4
+ runner(
5
+ 'Domain/GeoJSON/Geometry/MultiPolygon',
6
+ Export,
7
+ 'isMultiPolygonCoordinates',
8
+ 'isMultiPolygon',
9
+ 'isStrictMultiPolygonCoordinates',
10
+ 'isStrictMultiPolygon',
11
+ );
@@ -0,0 +1,11 @@
1
+ import * as Export from '../../../../source/Domain/GeoJSON/Geometry/Point';
2
+ import { runner } from '../../../helper/geometry';
3
+
4
+ runner(
5
+ 'Domain/GeoJSON/Geometry/Point',
6
+ Export,
7
+ 'isPointCoordinates',
8
+ 'isPoint',
9
+ 'isStrictPointCoordinates',
10
+ 'isStrictPoint',
11
+ );
@@ -0,0 +1,11 @@
1
+ import * as Export from '../../../../source/Domain/GeoJSON/Geometry/Polygon';
2
+ import { runner } from '../../../helper/geometry';
3
+
4
+ runner(
5
+ 'Domain/GeoJSON/Geometry/Polygon',
6
+ Export,
7
+ 'isPolygonCoordinates',
8
+ 'isPolygon',
9
+ 'isStrictPolygonCoordinates',
10
+ 'isStrictPolygon',
11
+ );
@@ -0,0 +1,9 @@
1
+ import * as Export from '../../../source/Domain/GeoJSON/Geometry';
2
+ import { runner } from '../../helper/geometry';
3
+
4
+ runner(
5
+ 'Domain/GeoJSON/Geometry',
6
+ Export,
7
+ ['isGeometry', ['Point', 'MultiPoint', 'LineString', 'MultiLineString', 'Polygon', 'MultiPolygon']],
8
+ ['isStrictGeometry', ['Point', 'MultiPoint', 'LineString', 'MultiLineString', 'Polygon', 'MultiPolygon']],
9
+ );
@@ -0,0 +1,9 @@
1
+ import * as Export from '../../../source/Domain/GeoJSON/GeometryCollection';
2
+ import { runner } from '../../helper/geometry';
3
+
4
+ runner(
5
+ 'Domain/GeoJSON/GeometryCollection',
6
+ Export,
7
+ 'isGeometryCollection',
8
+ 'isStrictGeometryCollection',
9
+ );
@@ -0,0 +1,4 @@
1
+ import * as Export from '../../../source/Domain/GeoJSON/GeometryObject';
2
+ import { exported } from '../../helper/geometry';
3
+
4
+ exported('Domain/GeoJSON/GeometryObject', Export, 'isGeometryObject');
@@ -0,0 +1,49 @@
1
+ import test from 'tape';
2
+ import { each } from 'template-literal-each';
3
+ import * as Export from '../../../source/Domain/Guards/Number';
4
+ import { exported } from '../../helper/geometry';
5
+
6
+ exported('Domain/Guards/Number - exports', Export, 'isNumberValue', 'isNumberBetween');
7
+
8
+ const { isNumberValue, isNumberBetween } = Export;
9
+
10
+ test('Domain/Guards/Number - isNumberValue', (t) => {
11
+ each`
12
+ input | valid
13
+ ---------------------------|-------
14
+ ${123} | yes
15
+ ${Number.MAX_SAFE_INTEGER} | yes
16
+ ${Number.MIN_SAFE_INTEGER} | yes
17
+ ${Number.MAX_VALUE} | yes
18
+ ${Number.MIN_VALUE} | yes
19
+ ${Math.PI} | yes
20
+ ${-Math.PI} | yes
21
+ ${Infinity} | no
22
+ ${-Infinity} | no
23
+ ${NaN} | no
24
+ ${'123'} | no
25
+ `(({ input, valid }) => {
26
+ t.equal(isNumberValue(input), valid === 'yes', `${input} isNumberValue ${valid}`);
27
+ });
28
+
29
+ t.end();
30
+ });
31
+
32
+ test('Domain/Guards/Number - isNumberBetween', (t) => {
33
+ each`
34
+ input | min | max | valid
35
+ -------------|--------|--------------|-------
36
+ ${1} | ${0} | ${2} | yes
37
+ ${0} | ${0} | ${2} | yes
38
+ ${-1} | ${0} | ${2} | no
39
+ ${Infinity} | ${0} | ${undefined} | no
40
+ ${Math.PI} | ${0} | ${undefined} | yes
41
+ ${0} | ${-10} | ${10} | yes
42
+ `(({ input, min, max, valid }: any) => {
43
+ const between = isNumberBetween(min, max);
44
+
45
+ t.equal(between(input), valid === 'yes', `${input} is ${valid === 'no' ? 'not ' : ''}between ${min} and ${max}`);
46
+ });
47
+
48
+ t.end();
49
+ });
@@ -0,0 +1,27 @@
1
+ import { isBoolean, isNumber, isString } from '@konfirm/guard';
2
+ import test from 'tape';
3
+ import * as Export from '../../../source/Domain/Guards/Tuple';
4
+ import { exported } from '../../helper/geometry';
5
+
6
+ exported('Domain/Guards/Tuple - exports', Export, 'isTuple');
7
+
8
+ const { isTuple } = Export;
9
+
10
+ test('Domain/Guards/Tuple - isTuple', (t) => {
11
+ const snn = isTuple(isString, isNumber, isNumber);
12
+ const bsn = isTuple(isBoolean, isString, isNumber);
13
+
14
+ t.notOk(snn(['abc']), `['abc'] does not match isTuple(isString, isNumber, isNumber)`);
15
+ t.notOk(snn(['abc', 123]), `['abc', 123] does not match isTuple(isString, isNumber, isNumber)`);
16
+ t.ok(snn(['abc', 123, 456]), `['abc', 123, 456] matches isTuple(isString, isNumber, isNumber)`);
17
+ t.notOk(snn(['abc', 123, true]), `['abc', 123, true] does not match isTuple(isString, isNumber, isNumber)`);
18
+ t.notOk(snn(['abc', false, 123]), `['abc', false, 123] does not match isTuple(isString, isNumber, isNumber)`);
19
+ t.notOk(snn(['abc', 123, 456, 789]), `['abc', 456, 789, 123] does not match isTuple(isString, isNumber, isNumber)`);
20
+
21
+ t.notOk(bsn(['abc', 123]), `['abc', 123] does not match isTuple(isBoolean, isString, isNumber)`);
22
+ t.notOk(bsn(['abc', false, 123]), `['abc', false, 123] does not match isTuple(isBoolean, isString, isNumber)`);
23
+ t.ok(bsn([true, 'abc', 123]), `[true, 'abc', 123] matches isTuple(isBoolean, isString, isNumber)`);
24
+ t.ok(bsn([false, 'abc', 123]), `[false, 'abc', 123] matches isTuple(isBoolean, isString, isNumber)`);
25
+
26
+ t.end();
27
+ });