nodes2ts 2.0.0 → 4.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 (67) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +116 -13
  3. package/dist/export.cjs +5331 -0
  4. package/dist/export.cjs.map +1 -0
  5. package/dist/export.d.cts +1838 -0
  6. package/dist/export.d.ts +1828 -20
  7. package/dist/export.js +5279 -51
  8. package/dist/export.js.map +1 -1
  9. package/package.json +34 -49
  10. package/dist/Interval.d.ts +0 -24
  11. package/dist/Interval.js +0 -22
  12. package/dist/Interval.js.map +0 -1
  13. package/dist/MutableInteger.d.ts +0 -4
  14. package/dist/MutableInteger.js +0 -9
  15. package/dist/MutableInteger.js.map +0 -1
  16. package/dist/R1Interval.d.ts +0 -76
  17. package/dist/R1Interval.js +0 -167
  18. package/dist/R1Interval.js.map +0 -1
  19. package/dist/R2Vector.d.ts +0 -34
  20. package/dist/R2Vector.js +0 -138
  21. package/dist/R2Vector.js.map +0 -1
  22. package/dist/S1Angle.d.ts +0 -26
  23. package/dist/S1Angle.js +0 -78
  24. package/dist/S1Angle.js.map +0 -1
  25. package/dist/S1Interval.d.ts +0 -109
  26. package/dist/S1Interval.js +0 -403
  27. package/dist/S1Interval.js.map +0 -1
  28. package/dist/S2.d.ts +0 -91
  29. package/dist/S2.js +0 -236
  30. package/dist/S2.js.map +0 -1
  31. package/dist/S2Cap.d.ts +0 -113
  32. package/dist/S2Cap.js +0 -392
  33. package/dist/S2Cap.js.map +0 -1
  34. package/dist/S2Cell.d.ts +0 -103
  35. package/dist/S2Cell.js +0 -361
  36. package/dist/S2Cell.js.map +0 -1
  37. package/dist/S2CellId.d.ts +0 -267
  38. package/dist/S2CellId.js +0 -933
  39. package/dist/S2CellId.js.map +0 -1
  40. package/dist/S2CellUnion.d.ts +0 -180
  41. package/dist/S2CellUnion.js +0 -518
  42. package/dist/S2CellUnion.js.map +0 -1
  43. package/dist/S2EdgeUtil.d.ts +0 -17
  44. package/dist/S2EdgeUtil.js +0 -787
  45. package/dist/S2EdgeUtil.js.map +0 -1
  46. package/dist/S2LatLng.d.ts +0 -72
  47. package/dist/S2LatLng.js +0 -182
  48. package/dist/S2LatLng.js.map +0 -1
  49. package/dist/S2LatLngRect.d.ts +0 -185
  50. package/dist/S2LatLngRect.js +0 -605
  51. package/dist/S2LatLngRect.js.map +0 -1
  52. package/dist/S2Metric.d.ts +0 -38
  53. package/dist/S2Metric.js +0 -75
  54. package/dist/S2Metric.js.map +0 -1
  55. package/dist/S2Point.d.ts +0 -43
  56. package/dist/S2Point.js +0 -200
  57. package/dist/S2Point.js.map +0 -1
  58. package/dist/S2Projections.d.ts +0 -67
  59. package/dist/S2Projections.js +0 -152
  60. package/dist/S2Projections.js.map +0 -1
  61. package/dist/S2Region.d.ts +0 -31
  62. package/dist/S2Region.js +0 -17
  63. package/dist/S2Region.js.map +0 -1
  64. package/dist/S2RegionCoverer.d.ts +0 -171
  65. package/dist/S2RegionCoverer.js +0 -435
  66. package/dist/S2RegionCoverer.js.map +0 -1
  67. package/yarn.lock +0 -4381
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
@@ -1,13 +1,54 @@
1
- ### Node S2Geometry Typescript
1
+ ### Node S2 Geometry Typescript
2
+ <img src="https://github.com/vekexasia/nodes2-ts/actions/workflows/node.js.yml/badge.svg" />
2
3
 
3
- An extensive port of google's s2 geometry library written in Typescript.
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/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"/>
4
8
 
5
- The library uses `decimal.js` and `long` as external libraries to perform the needed math.
9
+
10
+ An extensive port of google's s2 geometry library written in TypeScript.
11
+
12
+ The library has **no runtime dependencies**. Cell IDs use native JavaScript `bigint` (v4+).
6
13
 
7
14
  Npm package is `nodes2ts`.
8
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
+
9
50
  #### Tests
10
- 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.
11
52
 
12
53
  When implementing a not-yet-ported feature, please generate the needed tests by modifiying the java code within `java-test-creator` folder
13
54
 
@@ -47,37 +88,99 @@ Also, for some classes, an extra `toGEOJSON` method is provided to let developer
47
88
 
48
89
 
49
90
 
50
- ### Samples
91
+ ### Samples
92
+
93
+ #### Basic usage
51
94
 
52
- - Convert Lat/Lng to S2CellId
53
95
  ```typescript
96
+ import { S2Cell, S2CellId, S2LatLng } from 'nodes2ts';
97
+
54
98
  const cellId = S2CellId.fromPoint(
55
- S2LatLng.fromDegrees(10 /*latitude*/, 11 /*longitude*/)
99
+ S2LatLng.fromDegrees(10 /* latitude */, 11 /* longitude */).toPoint(),
56
100
  );
101
+
102
+ console.log(cellId.id); // 11532778376507094629n
103
+ console.log(typeof cellId.id); // 'bigint'
104
+ console.log(cellId.toToken()); // stable hex token
57
105
  ```
58
106
 
59
- - Get previous or next s2cell
107
+ #### Previous / next cell
108
+
60
109
  ```typescript
61
- // const cellId;
62
110
  const nextCell = cellId.next();
63
111
  const prevCell = cellId.prev();
64
112
  ```
65
113
 
114
+ #### Get all neighbors at the current level
66
115
 
67
- - Get All neighbor cell ids of cur level
68
116
  ```typescript
69
- // const cellId;
70
117
  const neighbors = cellId.getAllNeighbors(cellId.level());
71
118
  ```
72
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
73
169
 
74
- - See S2cell on google maps
75
170
  ```typescript
76
171
  const cell = new S2Cell(cellId);
77
172
  console.log(cell.toGEOJSON());
78
- // copy the output and paste it on http://geojson.io/
173
+ // copy the output and paste it into https://geojson.io/
79
174
  ```
80
175
 
176
+ ## Contributing
177
+
178
+ The library was initially conceived to be used in both server and client env leveraging TypeScript peculiarities.
81
179
 
180
+ If you wish to contribute please make sure, wherever applicable, to create a tiny merge request to ease the code
181
+ review of the proposed changes.
82
182
 
183
+ ## Want to connect with the author?
83
184
 
185
+ If you wish to contact the library author for business (or any other) proposal you can write an email to `vekexasia`
186
+ `at` gmail `dot` com.