ansuko 1.2.8 → 1.2.9

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.
@@ -13,6 +13,7 @@ export declare enum GeomType {
13
13
  auto = "auto"
14
14
  }
15
15
  export interface AnsukoGeoPluginExtension {
16
+ toLngLatArray: (coord: any, digit?: number) => [lng: number, lat: number] | null;
16
17
  toPointGeoJson: (geo: any, digit?: number) => GeoJSON.Point | null;
17
18
  toPolygonGeoJson: (geo: any, digit?: number) => GeoJSON.Polygon | null;
18
19
  toLineStringGeoJson: (geo: any, digit?: number) => GeoJSON.LineString | null;
@@ -19,7 +19,7 @@ const ansukoGeoPlugin = (ansuko) => {
19
19
  * Swaps order if lat/lng appear to be inverted. Returns null when invalid.
20
20
  * @internal
21
21
  */
22
- const toLngLatToArray = (coord, digit) => {
22
+ const toLngLatArray = (coord, digit) => {
23
23
  if (_.isNil(coord)) {
24
24
  return null;
25
25
  }
@@ -66,14 +66,14 @@ const ansukoGeoPlugin = (ansuko) => {
66
66
  }
67
67
  if (Array.isArray(geo)) {
68
68
  if (_.size(geo) === 1) {
69
- lngLat = toLngLatToArray(geo[0], digit);
69
+ lngLat = toLngLatArray(geo[0], digit);
70
70
  }
71
71
  else {
72
- lngLat = toLngLatToArray(geo, digit);
72
+ lngLat = toLngLatArray(geo, digit);
73
73
  }
74
74
  }
75
75
  else if (_.has(geo, "lat") || _.has(geo, "latitude")) {
76
- lngLat = toLngLatToArray(geo, digit);
76
+ lngLat = toLngLatArray(geo, digit);
77
77
  }
78
78
  else if (_.has(geo, "type")) {
79
79
  switch (geo.type.toLowerCase()) {
@@ -84,16 +84,16 @@ const ansukoGeoPlugin = (ansuko) => {
84
84
  if (_.size(geo.features) !== 1) {
85
85
  return null;
86
86
  }
87
- lngLat = toLngLatToArray(_.get(geo, "features[0].geometry.coordinates"), digit);
87
+ lngLat = toLngLatArray(_.get(geo, "features[0].geometry.coordinates"), digit);
88
88
  break;
89
89
  case "feature":
90
90
  if (geo.geometry?.type?.toLowerCase() !== "point") {
91
91
  return null;
92
92
  }
93
- lngLat = toLngLatToArray(geo.geometry?.coordinates, digit);
93
+ lngLat = toLngLatArray(geo.geometry?.coordinates, digit);
94
94
  break;
95
95
  case "point":
96
- lngLat = toLngLatToArray(geo.coordinates, digit);
96
+ lngLat = toLngLatArray(geo.coordinates, digit);
97
97
  break;
98
98
  default:
99
99
  return null;
@@ -125,10 +125,10 @@ const ansukoGeoPlugin = (ansuko) => {
125
125
  const toPolygonGeoJson = (geo, digit) => {
126
126
  let ll = null;
127
127
  if (_.arrayDepth(geo) === 3 && _.size(geo) === 1) { // [[外周リング]]
128
- ll = _.first(geo).map((coord) => toLngLatToArray(coord, digit));
128
+ ll = _.first(geo).map((coord) => toLngLatArray(coord, digit));
129
129
  }
130
130
  else if (_.arrayDepth(geo) === 2) { // [外周リング]
131
- ll = geo.map((coord) => toLngLatToArray(coord, digit));
131
+ ll = geo.map((coord) => toLngLatArray(coord, digit));
132
132
  }
133
133
  else if (_.has(geo, "type")) {
134
134
  switch (_.get(geo, "type")?.toLowerCase()) {
@@ -141,16 +141,16 @@ const ansukoGeoPlugin = (ansuko) => {
141
141
  }
142
142
  // 最初のリング(外周)だけ取得
143
143
  ll = _.first(_.first(geo.features)?.geometry.coordinates)
144
- ?.map((coord) => toLngLatToArray(coord, digit));
144
+ ?.map((coord) => toLngLatArray(coord, digit));
145
145
  break;
146
146
  case "feature":
147
147
  if (geo.geometry?.type?.toLowerCase() !== "polygon") {
148
148
  return null;
149
149
  }
150
- ll = _.first(geo.geometry.coordinates)?.map((coord) => toLngLatToArray(coord, digit));
150
+ ll = _.first(geo.geometry.coordinates)?.map((coord) => toLngLatArray(coord, digit));
151
151
  break;
152
152
  case "polygon":
153
- ll = _.first(geo.coordinates)?.map((coord) => toLngLatToArray(coord, digit));
153
+ ll = _.first(geo.coordinates)?.map((coord) => toLngLatArray(coord, digit));
154
154
  break;
155
155
  default:
156
156
  return null;
@@ -183,10 +183,10 @@ const ansukoGeoPlugin = (ansuko) => {
183
183
  const toLineStringGeoJson = (geo, digit) => {
184
184
  let ll = null;
185
185
  if (_.arrayDepth(geo) === 3 && _.size(geo) === 1) {
186
- ll = _.first(geo).map((l) => toLngLatToArray(l, digit));
186
+ ll = _.first(geo).map((l) => toLngLatArray(l, digit));
187
187
  }
188
188
  else if (_.arrayDepth(geo) === 2) {
189
- ll = geo.map((l) => toLngLatToArray(l, digit));
189
+ ll = geo.map((l) => toLngLatArray(l, digit));
190
190
  }
191
191
  else if (_.has(geo, "type")) {
192
192
  switch (_.get(geo, "type")?.toLowerCase()) {
@@ -197,16 +197,16 @@ const ansukoGeoPlugin = (ansuko) => {
197
197
  if (_.size(geo.features) !== 1) {
198
198
  return null;
199
199
  }
200
- ll = _.first(geo.features)?.geometry.coordinates?.map((l) => toLngLatToArray(l, digit));
200
+ ll = _.first(geo.features)?.geometry.coordinates?.map((l) => toLngLatArray(l, digit));
201
201
  break;
202
202
  case "feature":
203
203
  if (geo.geometry?.type?.toLowerCase() !== "linestring") {
204
204
  return null;
205
205
  }
206
- ll = geo.geometry?.coordinates?.map((l) => toLngLatToArray(l, digit));
206
+ ll = geo.geometry?.coordinates?.map((l) => toLngLatArray(l, digit));
207
207
  break;
208
208
  case "linestring":
209
- ll = geo.coordinates?.map((l) => toLngLatToArray(l, digit));
209
+ ll = geo.coordinates?.map((l) => toLngLatArray(l, digit));
210
210
  break;
211
211
  default:
212
212
  return null;
@@ -240,7 +240,7 @@ const ansukoGeoPlugin = (ansuko) => {
240
240
  const toMultiPointGeoJson = (geo, digit) => {
241
241
  let ll = null;
242
242
  if (_.arrayDepth(geo) === 2) { // MultiPointは2次元
243
- ll = geo.map((coord) => toLngLatToArray(coord, digit));
243
+ ll = geo.map((coord) => toLngLatArray(coord, digit));
244
244
  }
245
245
  else if (_.has(geo, "type")) {
246
246
  switch (_.get(geo, "type")?.toLowerCase()) {
@@ -252,16 +252,16 @@ const ansukoGeoPlugin = (ansuko) => {
252
252
  return null;
253
253
  }
254
254
  ll = _.first(geo.features).geometry?.coordinates
255
- ?.map((coord) => toLngLatToArray(coord, digit));
255
+ ?.map((coord) => toLngLatArray(coord, digit));
256
256
  break;
257
257
  case "feature":
258
258
  if (geo.geometry?.type?.toLowerCase() !== "multipoint") {
259
259
  return null;
260
260
  }
261
- ll = geo.geometry?.coordinates?.map((coord) => toLngLatToArray(coord, digit));
261
+ ll = geo.geometry?.coordinates?.map((coord) => toLngLatArray(coord, digit));
262
262
  break;
263
263
  case "multipoint":
264
- ll = geo.coordinates?.map((coord) => toLngLatToArray(coord, digit));
264
+ ll = geo.coordinates?.map((coord) => toLngLatArray(coord, digit));
265
265
  break;
266
266
  default:
267
267
  return null;
@@ -294,7 +294,7 @@ const ansukoGeoPlugin = (ansuko) => {
294
294
  const toMultiPolygonGeoJson = (geo, digit) => {
295
295
  let ll = null;
296
296
  if (_.arrayDepth(geo) === 4) {
297
- ll = geo.map((polygon) => _.first(polygon).map((l) => toLngLatToArray(l, digit)));
297
+ ll = geo.map((polygon) => _.first(polygon).map((l) => toLngLatArray(l, digit)));
298
298
  }
299
299
  else if (_.has(geo, "type")) {
300
300
  switch (geo.type.toLowerCase()) {
@@ -305,16 +305,16 @@ const ansukoGeoPlugin = (ansuko) => {
305
305
  if (_.size(geo.features) !== 1) {
306
306
  return null;
307
307
  }
308
- ll = _.first(geo.features).geometry?.coordinates?.map((polygon) => _.first(polygon).map((l) => toLngLatToArray(l, digit)));
308
+ ll = _.first(geo.features).geometry?.coordinates?.map((polygon) => _.first(polygon).map((l) => toLngLatArray(l, digit)));
309
309
  break;
310
310
  case "feature":
311
311
  if (geo.geometry?.type?.toLowerCase() !== "multipolygon") {
312
312
  return null;
313
313
  }
314
- ll = geo.geometry?.coordinates?.map((polygon) => _.first(polygon).map((l) => toLngLatToArray(l, digit)));
314
+ ll = geo.geometry?.coordinates?.map((polygon) => _.first(polygon).map((l) => toLngLatArray(l, digit)));
315
315
  break;
316
316
  case "multipolygon":
317
- ll = geo.coordinates?.map((polygon) => _.first(polygon).map((l) => toLngLatToArray(l, digit)));
317
+ ll = geo.coordinates?.map((polygon) => _.first(polygon).map((l) => toLngLatArray(l, digit)));
318
318
  break;
319
319
  default:
320
320
  return null;
@@ -334,20 +334,20 @@ const ansukoGeoPlugin = (ansuko) => {
334
334
  }
335
335
  };
336
336
  /**
337
- * Converts lines to MultiLineString GeoJSON, rejecting self-intersections.
338
- * @param geo - Lines
339
- * @param digit - Rounding digits
340
- * @returns MultiLineString or null
341
- * @example toMultiLineStringGeoJson([
342
- * [[139.7,35.6],[139.8,35.65]],
343
- * [[139.75,35.62],[139.85,35.68]]
344
- * ])
345
- * @category Geo Utilities
346
- */
337
+ * Converts lines to MultiLineString GeoJSON, rejecting self-intersections.
338
+ * @param geo - Lines
339
+ * @param digit - Rounding digits
340
+ * @returns MultiLineString or null
341
+ * @example toMultiLineStringGeoJson([
342
+ * [[139.7,35.6],[139.8,35.65]],
343
+ * [[139.75,35.62],[139.85,35.68]]
344
+ * ])
345
+ * @category Geo Utilities
346
+ */
347
347
  const toMultiLineStringGeoJson = (geo, digit) => {
348
348
  let ll = null;
349
349
  if (_.arrayDepth(geo) === 3) {
350
- ll = geo.map((line) => line.map((l) => toLngLatToArray(l, digit)));
350
+ ll = geo.map((line) => line.map((l) => toLngLatArray(l, digit)));
351
351
  }
352
352
  else if (_.has(geo, "type")) {
353
353
  switch (_.get(geo, "type").toLowerCase()) {
@@ -358,16 +358,16 @@ const ansukoGeoPlugin = (ansuko) => {
358
358
  if (_.size(geo.features) !== 1) {
359
359
  return null;
360
360
  }
361
- ll = _.first(geo.features).geometry?.coordinates?.map((line) => line.map((l) => toLngLatToArray(l, digit)));
361
+ ll = _.first(geo.features).geometry?.coordinates?.map((line) => line.map((l) => toLngLatArray(l, digit)));
362
362
  break;
363
363
  case "feature":
364
364
  if (geo.geometry?.type?.toLowerCase() !== "multilinestring") {
365
365
  return null;
366
366
  } // 修正
367
- ll = geo.geometry?.coordinates?.map((line) => line.map((l) => toLngLatToArray(l, digit)));
367
+ ll = geo.geometry?.coordinates?.map((line) => line.map((l) => toLngLatArray(l, digit)));
368
368
  break;
369
369
  case "multilinestring":
370
- ll = geo.coordinates?.map((line) => line.map((l) => toLngLatToArray(l, digit)));
370
+ ll = geo.coordinates?.map((line) => line.map((l) => toLngLatArray(l, digit)));
371
371
  break;
372
372
  default:
373
373
  return null;
@@ -552,6 +552,7 @@ const ansukoGeoPlugin = (ansuko) => {
552
552
  return features;
553
553
  };
554
554
  const a = ansuko;
555
+ a.toLngLatArray = toLngLatArray;
555
556
  a.toGeoJson = toGeoJson;
556
557
  a.toPointGeoJson = toPointGeoJson;
557
558
  a.toPolygonGeoJson = toPolygonGeoJson;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ansuko",
3
- "version": "1.2.8",
3
+ "version": "1.2.9",
4
4
  "description": "A modern JavaScript/TypeScript utility library that extends lodash with practical, intuitive behaviors. Fixes lodash quirks, adds Promise support, Japanese text processing, and GeoJSON utilities.",
5
5
  "keywords": [
6
6
  "lodash",
@@ -22,7 +22,7 @@
22
22
  "license": "MIT",
23
23
  "repository": {
24
24
  "type": "git",
25
- "url": "https://github.com/sera4am/ansuko.git"
25
+ "url": "git+https://github.com/sera4am/ansuko.git"
26
26
  },
27
27
  "bugs": {
28
28
  "url": "https://github.com/sera4am/ansuko/issues"
@@ -60,6 +60,7 @@
60
60
  "@eslint/js": "^9.39.2",
61
61
  "@types/geojson": "^7946.0.16",
62
62
  "@types/lodash": "^4.14.202",
63
+ "@types/node": "^25.0.5",
63
64
  "@typescript-eslint/eslint-plugin": "^8.52.0",
64
65
  "eslint": "^9.39.2",
65
66
  "typescript": "^5.3.3",