commit 9f1b6509734b0dde65466ab70e76a74735fd85b6
parent 466743206fa52e828131dc922578a96a0b1742f1
Author: triesap <triesap@radroots.dev>
Date: Sun, 21 Dec 2025 01:36:02 +0000
utils: standardized earth-radius usage, expanded public exports, added string capitalization utilities, introduced a media schema, and broadened file path types
Diffstat:
5 files changed, 45 insertions(+), 23 deletions(-)
diff --git a/utils/src/geo.ts b/utils/src/geo.ts
@@ -1,5 +1,7 @@
import { decodeBase32, encodeBase32 } from "geohashing";
+const EARTH_RADIUS = 6371;
+
export type GeometryPoint = {
type: string;
coordinates: number[];
@@ -209,12 +211,10 @@ export const compute_bounding_box = (lat: number, lng: number, distance_km: numb
const deg_to_rad = (deg: number) => deg * (Math.PI / 180);
const rad_to_deg = (rad: number) => rad * (180 / Math.PI);
- const R = 6371;
-
function destination_point(lat: number, lng: number, bearing: number, distance_km: number): GeolocationPoint {
const lat1 = deg_to_rad(lat);
const lon1 = deg_to_rad(lng);
- const angular_distance = distance_km / R;
+ const angular_distance = distance_km / EARTH_RADIUS;
const lat2 = Math.asin(Math.sin(lat1) * Math.cos(angular_distance) + Math.cos(lat1) * Math.sin(angular_distance) * Math.cos(deg_to_rad(bearing)));
const lon2 = lon1 + Math.atan2(Math.sin(deg_to_rad(bearing)) * Math.sin(angular_distance) * Math.cos(lat1), Math.cos(angular_distance) - Math.sin(lat1) * Math.sin(lat2));
@@ -238,12 +238,10 @@ export const geo_bounds_calc = (lat: number, lng: number, distance_km: number):
const deg_to_rad = (deg: number) => deg * (Math.PI / 180);
const rad_to_deg = (rad: number) => rad * (180 / Math.PI);
- const R = 6371;
-
function destination_point(lat: number, lng: number, bearing: number, distance_km: number): GeolocationPoint {
const lat1 = deg_to_rad(lat);
const lon1 = deg_to_rad(lng);
- const angular_distance = distance_km / R;
+ const angular_distance = distance_km / EARTH_RADIUS;
const lat2 = Math.asin(Math.sin(lat1) * Math.cos(angular_distance) + Math.cos(lat1) * Math.sin(angular_distance) * Math.cos(deg_to_rad(bearing)));
const lon2 = lon1 + Math.atan2(Math.sin(deg_to_rad(bearing)) * Math.sin(angular_distance) * Math.cos(lat1), Math.cos(angular_distance) - Math.sin(lat1) * Math.sin(lat2));
diff --git a/utils/src/index.ts b/utils/src/index.ts
@@ -1,15 +1,17 @@
-export * from "./currency.js"
-export * from "./errors/lib.js"
-export * from "./geo.js"
-export * from "./http.js"
-export * from "./id/lib.js"
-export * from "./lib.js"
-export * from "./model.js"
-export * from "./numbers/lib.js"
-export * from "./text/lib.js"
-export * from "./time/lib.js"
-export * from "./types.js"
-export * from "./types/lib.js"
-export * from "./unit.js"
-export * from "./validation/regex.js"
-export * from "./validation/schemas.js"
+export * from "./currency.js";
+export * from "./errors/lib.js";
+export * from "./geo.js";
+export * from "./http.js";
+export * from "./id/lib.js";
+export * from "./index.js";
+export * from "./lib.js";
+export * from "./model.js";
+export * from "./numbers/lib.js";
+export * from "./schema/media.js";
+export * from "./text/lib.js";
+export * from "./time/lib.js";
+export * from "./types/lib.js";
+export * from "./types.js";
+export * from "./unit.js";
+export * from "./validation/regex.js";
+export * from "./validation/schemas.js";
diff --git a/utils/src/lib.ts b/utils/src/lib.ts
@@ -42,4 +42,14 @@ export const obj_result = (obj: any): string | undefined => {
export const obj_results_str = (obj: any): string[] | undefined => {
if (Array.isArray(obj.results)) return obj.results.map(String);
return undefined;
+};
+
+export const str_cap = (val?: string): string => {
+ if (!val) return ``;
+ return `${val[0].toUpperCase()}${val.slice(1)}`;
+};
+
+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
diff --git a/utils/src/schema/media.ts b/utils/src/schema/media.ts
@@ -0,0 +1,9 @@
+import z from "zod";
+
+export const schema_media_resource = z.object({
+ base_url: z.string(),
+ hash: z.string(),
+ ext: z.string(),
+
+});
+export type MediaResource = z.infer<typeof schema_media_resource>;
diff --git a/utils/src/types.ts b/utils/src/types.ts
@@ -11,6 +11,9 @@ export type NotifyMessage = {
export type FileBytesFormat = `kb` | `mb` | `gb`;
export type FileMimeType = string;
export type FilePath = { file_path: string; file_name: string; mime_type: FileMimeType; }
+export type FilePathBlob = { blob_path: string; blob_name: string; mime_type?: FileMimeType; }
+
+export type WebFilePath = FilePath | FilePathBlob;
export type ValStr = string | undefined | null;
@@ -22,4 +25,5 @@ export type IdbClientConfig = {
export type ValidationRegex = {
value: RegExp;
charset: RegExp;
-}
-\ No newline at end of file
+}
+