@dotrino/geo 0.9.2 → 0.9.4
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.
- package/package.json +3 -2
- package/src/canonical.js +3 -0
- package/src/index.js +2 -16
- package/src/tags.js +20 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotrino/geo",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.4",
|
|
4
4
|
"description": "Dotrino geo index client (geo.dotrino.com): vault-signed georeferenced pins, radius queries (PostGIS)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
],
|
|
20
20
|
"scripts": {
|
|
21
21
|
"test": "node --test",
|
|
22
|
-
"type-check": "tsc --noEmit"
|
|
22
|
+
"type-check": "tsc --noEmit",
|
|
23
|
+
"vendor": "node vendor.mjs"
|
|
23
24
|
},
|
|
24
25
|
"keywords": [
|
|
25
26
|
"geolocation",
|
package/src/canonical.js
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
* Serialización JSON canónica (claves ordenadas recursivamente).
|
|
3
3
|
* Necesaria para que las firmas coincidan entre cliente y servidor.
|
|
4
4
|
* Idéntica a la del proxy-client / proxy-server del ecosistema.
|
|
5
|
+
*
|
|
6
|
+
* Fuente ÚNICA dentro de este repo: el servidor la recibe copiada en
|
|
7
|
+
* server/vendor/shared.js por `node vendor.mjs` (una prueba falla si se desincronizan).
|
|
5
8
|
*/
|
|
6
9
|
export function canonicalStringify (value) {
|
|
7
10
|
if (value === null || typeof value !== 'object') {
|
package/src/index.js
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
21
|
import { canonicalStringify } from './canonical.js'
|
|
22
|
+
import { normalizeTags } from './tags.js'
|
|
22
23
|
import { encodeGeohash } from './geohash.js'
|
|
23
24
|
|
|
24
25
|
export { encodeGeohash } from './geohash.js'
|
|
@@ -156,21 +157,6 @@ function round (n, decimals) {
|
|
|
156
157
|
return Math.round(n * f) / f
|
|
157
158
|
}
|
|
158
159
|
|
|
159
|
-
// Normaliza etiquetas: lowercase, trim, slug unicode (letras/números/_/-), ≤32
|
|
160
|
-
// chars, dedup, máx 10. Descarta las inválidas en silencio.
|
|
161
|
-
export function normalizeTags (tags) {
|
|
162
|
-
if (!Array.isArray(tags)) return []
|
|
163
|
-
const out = []
|
|
164
|
-
for (const t of tags) {
|
|
165
|
-
if (typeof t !== 'string') continue
|
|
166
|
-
const s = t.trim().toLowerCase()
|
|
167
|
-
if (!/^[\p{L}\p{N}_-]{1,32}$/u.test(s)) continue
|
|
168
|
-
if (!out.includes(s)) out.push(s)
|
|
169
|
-
if (out.length >= 10) break
|
|
170
|
-
}
|
|
171
|
-
return out
|
|
172
|
-
}
|
|
173
|
-
|
|
174
160
|
async function handle (res) {
|
|
175
161
|
let body = null
|
|
176
162
|
try { body = await res.json() } catch (_) {}
|
|
@@ -181,4 +167,4 @@ async function handle (res) {
|
|
|
181
167
|
return body
|
|
182
168
|
}
|
|
183
169
|
|
|
184
|
-
export { canonicalStringify }
|
|
170
|
+
export { canonicalStringify, normalizeTags }
|
package/src/tags.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normaliza etiquetas: lowercase, trim, slug unicode (letras/números/_/-), ≤32
|
|
3
|
+
* chars, dedup, máx 10. Descarta las inválidas en silencio.
|
|
4
|
+
*
|
|
5
|
+
* Fuente ÚNICA: el servidor (CommonJS, imagen Docker con contexto ./server) la recibe
|
|
6
|
+
* copiada en server/vendor/shared.js por `node vendor.mjs`, y una prueba falla si se
|
|
7
|
+
* desincronizan.
|
|
8
|
+
*/
|
|
9
|
+
export function normalizeTags (tags) {
|
|
10
|
+
if (!Array.isArray(tags)) return []
|
|
11
|
+
const out = []
|
|
12
|
+
for (const t of tags) {
|
|
13
|
+
if (typeof t !== 'string') continue
|
|
14
|
+
const s = t.trim().toLowerCase()
|
|
15
|
+
if (!/^[\p{L}\p{N}_-]{1,32}$/u.test(s)) continue
|
|
16
|
+
if (!out.includes(s)) out.push(s)
|
|
17
|
+
if (out.length >= 10) break
|
|
18
|
+
}
|
|
19
|
+
return out
|
|
20
|
+
}
|