commit 857f59c7c299c6151f67cfc19d091a9b1bf515da
parent 9f1b6509734b0dde65466ab70e76a74735fd85b6
Author: triesap <triesap@radroots.dev>
Date: Sun, 21 Dec 2025 04:19:35 +0000
utils: integrated schema bindings and added utilities for geocode-to-location mapping and consistent uint8array-to-arraybuffer conversion
Diffstat:
3 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/utils/package.json b/utils/package.json
@@ -35,6 +35,7 @@
"access": "public"
},
"dependencies": {
+ "@radroots/tangle-schema-bindings": "*",
"@radroots/types-bindings": "*",
"@noble/curves": "^1.6.0",
"@noble/hashes": "^1.4.0",
diff --git a/utils/src/geo.ts b/utils/src/geo.ts
@@ -1,3 +1,4 @@
+import { LocationGcs } from "@radroots/tangle-schema-bindings";
import { decodeBase32, encodeBase32 } from "geohashing";
const EARTH_RADIUS = 6371;
@@ -256,3 +257,24 @@ export const geo_bounds_calc = (lat: number, lng: number, distance_km: number):
west: destination_point(lat, lng, 270, distance_km)
};
};
+
+
+export const gcs_to_location_basis = ({
+ id,
+ lat,
+ lng,
+ gc_name: primary,
+ gc_admin1_name: admin,
+ gc_country_id: country,
+}: LocationGcs): LocationBasis => ({
+ id,
+ point: {
+ lat,
+ lng,
+ },
+ address: primary && admin && country ? {
+ primary,
+ admin,
+ country,
+ } : undefined
+});
+\ No newline at end of file
diff --git a/utils/src/lib.ts b/utils/src/lib.ts
@@ -52,4 +52,11 @@ export const str_cap = (val?: string): string => {
export const str_cap_words = (val?: string): string => {
if (!val) return ``;
return val.split(` `).map(i => i ? str_cap(i) : ``).filter(i => !!i).join(` `);
-};
-\ No newline at end of file
+};
+
+export function as_array_buffer(u8: Uint8Array): ArrayBuffer {
+ if (u8.byteOffset === 0 && u8.buffer instanceof ArrayBuffer && u8.byteLength === u8.buffer.byteLength) {
+ return u8.buffer;
+ }
+ return u8.slice().buffer;
+}
+\ No newline at end of file