nodes2ts 3.0.0 → 4.0.1

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 (80) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +102 -15
  3. package/dist/export.cjs +5350 -0
  4. package/dist/export.cjs.map +1 -0
  5. package/dist/export.d.cts +1847 -0
  6. package/dist/export.d.ts +1837 -20
  7. package/dist/export.js +5299 -62
  8. package/dist/export.js.map +1 -1
  9. package/package.json +34 -55
  10. package/.eslintignore +0 -3
  11. package/.eslintrc.cjs +0 -11
  12. package/.github/workflows/lint.js.yml +0 -22
  13. package/.github/workflows/node.js.yml +0 -22
  14. package/.mocharc.js +0 -7
  15. package/dist/Interval.d.ts +0 -24
  16. package/dist/Interval.js +0 -23
  17. package/dist/Interval.js.map +0 -1
  18. package/dist/MutableInteger.d.ts +0 -4
  19. package/dist/MutableInteger.js +0 -10
  20. package/dist/MutableInteger.js.map +0 -1
  21. package/dist/Platform.d.ts +0 -15
  22. package/dist/Platform.js +0 -53
  23. package/dist/Platform.js.map +0 -1
  24. package/dist/R1Interval.d.ts +0 -76
  25. package/dist/R1Interval.js +0 -158
  26. package/dist/R1Interval.js.map +0 -1
  27. package/dist/R2Vector.d.ts +0 -34
  28. package/dist/R2Vector.js +0 -131
  29. package/dist/R2Vector.js.map +0 -1
  30. package/dist/S1Angle.d.ts +0 -60
  31. package/dist/S1Angle.js +0 -133
  32. package/dist/S1Angle.js.map +0 -1
  33. package/dist/S1ChordAngle.d.ts +0 -166
  34. package/dist/S1ChordAngle.js +0 -318
  35. package/dist/S1ChordAngle.js.map +0 -1
  36. package/dist/S1Interval.d.ts +0 -109
  37. package/dist/S1Interval.js +0 -398
  38. package/dist/S1Interval.js.map +0 -1
  39. package/dist/S2.d.ts +0 -96
  40. package/dist/S2.js +0 -231
  41. package/dist/S2.js.map +0 -1
  42. package/dist/S2Cap.d.ts +0 -122
  43. package/dist/S2Cap.js +0 -399
  44. package/dist/S2Cap.js.map +0 -1
  45. package/dist/S2Cell.d.ts +0 -106
  46. package/dist/S2Cell.js +0 -358
  47. package/dist/S2Cell.js.map +0 -1
  48. package/dist/S2CellId.d.ts +0 -290
  49. package/dist/S2CellId.js +0 -983
  50. package/dist/S2CellId.js.map +0 -1
  51. package/dist/S2CellUnion.d.ts +0 -179
  52. package/dist/S2CellUnion.js +0 -523
  53. package/dist/S2CellUnion.js.map +0 -1
  54. package/dist/S2EdgeUtil.d.ts +0 -17
  55. package/dist/S2EdgeUtil.js +0 -785
  56. package/dist/S2EdgeUtil.js.map +0 -1
  57. package/dist/S2LatLng.d.ts +0 -77
  58. package/dist/S2LatLng.js +0 -186
  59. package/dist/S2LatLng.js.map +0 -1
  60. package/dist/S2LatLngRect.d.ts +0 -190
  61. package/dist/S2LatLngRect.js +0 -624
  62. package/dist/S2LatLngRect.js.map +0 -1
  63. package/dist/S2Metric.d.ts +0 -38
  64. package/dist/S2Metric.js +0 -79
  65. package/dist/S2Metric.js.map +0 -1
  66. package/dist/S2Point.d.ts +0 -78
  67. package/dist/S2Point.js +0 -250
  68. package/dist/S2Point.js.map +0 -1
  69. package/dist/S2Projections.d.ts +0 -102
  70. package/dist/S2Projections.js +0 -331
  71. package/dist/S2Projections.js.map +0 -1
  72. package/dist/S2Region.d.ts +0 -31
  73. package/dist/S2Region.js +0 -18
  74. package/dist/S2Region.js.map +0 -1
  75. package/dist/S2RegionCoverer.d.ts +0 -186
  76. package/dist/S2RegionCoverer.js +0 -471
  77. package/dist/S2RegionCoverer.js.map +0 -1
  78. package/dist/utils/preconditions.d.ts +0 -2
  79. package/dist/utils/preconditions.js +0 -16
  80. package/dist/utils/preconditions.js.map +0 -1
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Andrea Baccega
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.
package/README.md CHANGED
@@ -2,18 +2,53 @@
2
2
  <img src="https://github.com/vekexasia/nodes2-ts/actions/workflows/node.js.yml/badge.svg" />
3
3
 
4
4
  <img src="https://img.shields.io/badge/TypeScript-007ACC?style=for-the-badge&logo=typescript&logoColor=white"/> <img
5
- src="https://img.shields.io/badge/mocha.js-323330?style=for-the-badge&logo=mocha&logoColor=Brown"/> <img
6
- src="https://img.shields.io/badge/eslint-3A33D1?style=for-the-badge&logo=eslint&logoColor=white"/>
5
+ src="https://img.shields.io/badge/vitest-6E9F18?style=for-the-badge&logo=vitest&logoColor=white"/> <img
6
+ src="https://img.shields.io/badge/eslint-3A33D1?style=for-the-badge&logo=eslint&logoColor=white"/> <img
7
+ src="https://img.shields.io/badge/runtime_deps-0-brightgreen?style=for-the-badge"/>
7
8
 
8
9
 
9
10
  An extensive port of google's s2 geometry library written in TypeScript.
10
11
 
11
- The only direct dependencies are some math related npm packages (long and math-float64-exponent).
12
+ The library has **no runtime dependencies**. Cell IDs use native JavaScript `bigint` (v4+).
12
13
 
13
14
  Npm package is `nodes2ts`.
14
15
 
16
+ > Requires **Node.js 20+**.
17
+
18
+ ## Breaking Changes in v4
19
+
20
+ **`S2CellId.id` is now `bigint` (was `Long`).**
21
+
22
+ ```typescript
23
+ // v3
24
+ import Long from 'long';
25
+ const id = new S2CellId(Long.fromString('-6533045114107854848'));
26
+ id.id.toString(); // "-6533045114107854848" (signed)
27
+
28
+ // v4 — Long import removed, signed strings still work in constructor
29
+ const id = new S2CellId('-6533045114107854848');
30
+ id.id.toString(); // "11913698959601696768" (unsigned)
31
+ id.toSignedDecimalString(); // "-6533045114107854848" (compat helper)
32
+ ```
33
+
34
+ **Other changed APIs:**
35
+
36
+ | Symbol | v3 type | v4 type |
37
+ |---|---|---|
38
+ | `S2CellId.id` | `Long` | `bigint` |
39
+ | `S2CellId` constructor | `Long \| string` | `bigint \| string` |
40
+ | `S2CellId.fromFacePosLevel` `pos` | `Long` | `bigint` |
41
+ | `S2CellId.pos()` | `Long` | `bigint` |
42
+ | `S2CellId.lowestOnBit()` | `Long` | `bigint` |
43
+ | `S2CellId.lowestOnBitForLevel()` | `Long` | `bigint` |
44
+ | `S2CellId.toIJOrientation()` | `Long` | `bigint` |
45
+ | `S2CellUnion.initFromIds()` | `Long[] \| string[]` | `bigint[] \| string[]` |
46
+ | `S2CellUnion.leafCellsCovered()` | `Long` | `bigint` |
47
+
48
+ See [MIGRATION.md](./MIGRATION.md) for a full migration guide and operator cheat-sheet.
49
+
15
50
  #### Tests
16
- This project is backed by 60+ 1-by-1 comparison tests between this implementation and the original one.
51
+ This project is backed by 80+ 1-by-1 comparison tests between this implementation and the original one.
17
52
 
18
53
  When implementing a not-yet-ported feature, please generate the needed tests by modifiying the java code within `java-test-creator` folder
19
54
 
@@ -53,35 +88,89 @@ Also, for some classes, an extra `toGEOJSON` method is provided to let developer
53
88
 
54
89
 
55
90
 
56
- ### Samples
91
+ ### Samples
92
+
93
+ #### Basic usage
57
94
 
58
- - Convert Lat/Lng to S2CellId
59
95
  ```typescript
96
+ import { S2Cell, S2CellId, S2LatLng } from 'nodes2ts';
97
+
60
98
  const cellId = S2CellId.fromPoint(
61
- S2LatLng.fromDegrees(10 /*latitude*/, 11 /*longitude*/).toPoint()
99
+ S2LatLng.fromDegrees(10 /* latitude */, 11 /* longitude */).toPoint(),
62
100
  );
101
+
102
+ console.log(cellId.id); // 11532778376507094629n
103
+ console.log(typeof cellId.id); // 'bigint'
104
+ console.log(cellId.toToken()); // stable hex token
63
105
  ```
64
106
 
65
- - Get previous or next s2cell
107
+ #### Previous / next cell
108
+
66
109
  ```typescript
67
- // const cellId;
68
110
  const nextCell = cellId.next();
69
111
  const prevCell = cellId.prev();
70
112
  ```
71
113
 
114
+ #### Get all neighbors at the current level
72
115
 
73
- - Get All neighbor cell ids of cur level
74
116
  ```typescript
75
- // const cellId;
76
117
  const neighbors = cellId.getAllNeighbors(cellId.level());
77
118
  ```
78
119
 
120
+ #### Signed / unsigned decimal migration helpers
121
+
122
+ ```typescript
123
+ import {
124
+ S2CellId,
125
+ signedDecimalToUnsigned,
126
+ unsignedToSignedDecimal,
127
+ } from 'nodes2ts';
128
+
129
+ const legacySigned = '-6533045114107854848';
130
+
131
+ const cell = new S2CellId(legacySigned);
132
+ console.log(cell.id); // 11913698959601696768n
133
+ console.log(cell.toSignedDecimalString()); // '-6533045114107854848'
134
+ console.log(cell.toUnsignedDecimalString()); // '11913698959601696768'
135
+
136
+ console.log(signedDecimalToUnsigned(legacySigned)); // 11913698959601696768n
137
+ console.log(unsignedToSignedDecimal(cell.id)); // '-6533045114107854848'
138
+ ```
139
+
140
+ #### Construct from a legacy signed decimal explicitly
141
+
142
+ ```typescript
143
+ const legacyCell = S2CellId.fromSignedDecimalString('-6533045114107854848');
144
+ console.log(legacyCell.id); // 11913698959601696768n
145
+ console.log(legacyCell.toToken()); // same canonical token as before
146
+ ```
147
+
148
+ #### Rebuild from a token
149
+
150
+ ```typescript
151
+ const fromToken = S2CellId.fromToken('89c25c');
152
+ console.log(fromToken.id); // bigint
153
+ console.log(fromToken.toToken()); // '89c25c'
154
+ ```
155
+
156
+ #### Initialize a union from bigint ids
157
+
158
+ ```typescript
159
+ import { S2CellUnion } from 'nodes2ts';
160
+
161
+ const union = new S2CellUnion();
162
+ union.initFromIds([
163
+ 0x89c25c0000000000n,
164
+ 0x89c25c4000000000n,
165
+ ]);
166
+ ```
167
+
168
+ #### Visualize an S2 cell as GeoJSON
79
169
 
80
- - See S2cell on google maps
81
170
  ```typescript
82
171
  const cell = new S2Cell(cellId);
83
172
  console.log(cell.toGEOJSON());
84
- // copy the output and paste it on http://geojson.io/
173
+ // copy the output and paste it into https://geojson.io/
85
174
  ```
86
175
 
87
176
  ## Contributing
@@ -95,5 +184,3 @@ review of the proposed changes.
95
184
 
96
185
  If you wish to contact the library author for business (or any other) proposal you can write an email to `vekexasia`
97
186
  `at` gmail `dot` com.
98
-
99
-