commit 75f2ee62b43a61c9ba9700d306366a07fcd2d494
parent d6497e698168b47e9a6b43fe323369740b23b4e9
Author: triesap <triesap@radroots.dev>
Date: Thu, 20 Nov 2025 16:44:57 +0000
utils: update geolocation types, add object helper utilities, extend validation primitives with shared regex structure and email patterns
Diffstat:
5 files changed, 36 insertions(+), 16 deletions(-)
diff --git a/utils/src/geo.ts b/utils/src/geo.ts
@@ -23,8 +23,8 @@ export type GeolocationPoint = {
lng: number;
};
-export type LocationPoint = GeolocationCoordinatesPoint & {
- error: GeolocationCoordinatesPoint;
+export type LocationPoint = GeolocationPoint & {
+ error: GeolocationPoint;
}
export type GeocoderReverseResult = {
@@ -38,19 +38,12 @@ export type GeocoderReverseResult = {
longitude: number;
};
-export type IClientGeolocationPosition = {
- lat: number;
- lng: number;
+export type IClientGeolocationPosition = GeolocationPoint & {
accuracy?: number;
altitude?: number;
altitude_accuracy?: number;
};
-export type GeolocationCoordinatesPoint = {
- lat: number;
- lng: number;
-}
-
export type GeolocationLatitudeFmtOption = 'dms' | 'd' | 'dm';
export type LocationBasis = {
@@ -81,13 +74,13 @@ export const geohash_decode = (geohash: string): LocationPoint => {
};
};
-export const location_geohash = (point: GeolocationCoordinatesPoint): string => {
+export const location_geohash = (point: GeolocationPoint): string => {
const { lat, lng } = point;
const res = geohash_encode({ lat, lng });
return res;
};
-export const parse_geop_point = (point: GeolocationCoordinatesPoint): GeolocationPoint => {
+export const parse_geop_point = (point: GeolocationPoint): GeolocationPoint => {
const { lat, lng } = point;
return { lat, lng };
};
diff --git a/utils/src/lib.ts b/utils/src/lib.ts
@@ -25,3 +25,21 @@ export type MediaImageUploadResult = {
};
export const fmt_media_image_upload_result_url = (res: MediaImageUploadResult): string => `${res.base_url}/${res.file_hash}.${res.file_ext}`;
+
+export const obj_en = <KeyType extends string, ValType>(object: Record<string, ValType>, parse_function: (key: string) => KeyType = (i) => i as KeyType): [KeyType, ValType][] => {
+ return Object.entries(object).map<[KeyType, ValType]>(([k, v]) => [parse_function(k), v])
+};
+
+export const obj_truthy_fields = (obj: Record<string, string>): boolean => {
+ return Object.values(obj).every(Boolean);
+};
+
+export const obj_result = (obj: any): string | undefined => {
+ if (`result` in obj && typeof obj.result === `string`) return obj.result;
+ return undefined;
+};
+
+export const obj_results_str = (obj: any): string[] | undefined => {
+ if (Array.isArray(obj.results)) return obj.results.map(String);
+ return undefined;
+};
+\ No newline at end of file
diff --git a/utils/src/model.ts b/utils/src/model.ts
@@ -1,3 +1,5 @@
+import { ValidationRegex } from "./types.js";
+
export type IModelsQueryValue = string | number | boolean | null;
export type IModelsQueryBindValue = string | number | boolean | null;;
export type IModelsQueryBindValueTuple = [string, IModelsQueryValue];
@@ -16,11 +18,10 @@ export type IModelsForm = {
placeholder?: string;
validateKeypress?: boolean;
preventFocusRest?: boolean;
- validation: RegExp;
- charset: RegExp;
hidden?: boolean;
optional?: boolean;
default?: string | number;
+ rxpv: ValidationRegex;
};
export type IModelQueryFilterMapValuesTuplesOption = [IModelsQueryValue, IModelsQueryFilterOption];
diff --git a/utils/src/types.ts b/utils/src/types.ts
@@ -17,4 +17,9 @@ export type ValStr = string | undefined | null;
export type IdbClientConfig = {
database: string;
store: string;
-};
-\ No newline at end of file
+};
+
+export type ValidationRegex = {
+ value: RegExp;
+ charset: RegExp;
+}
+\ No newline at end of file
diff --git a/utils/src/validation/regex.ts b/utils/src/validation/regex.ts
@@ -1,4 +1,6 @@
export const util_rxp = {
+ email: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,
+ email_ch: /^[a-zA-Z0-9._%+-@-]*$/,
product_key: /^[A-Za-z_]+$/,
product_key_ch: /^[A-Za-z_]$/,
product_title: /[A-Za-z0-9 ]+$/,