diff options
Diffstat (limited to 'u/process/validate_identifier.ts')
-rw-r--r-- | u/process/validate_identifier.ts | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/u/process/validate_identifier.ts b/u/process/validate_identifier.ts index ec8b77b..32952a6 100644 --- a/u/process/validate_identifier.ts +++ b/u/process/validate_identifier.ts @@ -1,4 +1,4 @@ -import { Either } from "./mod.ts"; +import { Either, type IEither } from "@emprespresso/pengueno"; export const validateIdentifier = (token: string) => { return (/^[a-zA-Z0-9_\-:. \/]+$/).test(token) && !token.includes(".."); @@ -6,11 +6,18 @@ export const validateIdentifier = (token: string) => { // ensure {@param obj} is a Record<string, string> with stuff that won't // have the potential for shell injection, just to be super safe. -export const validateExecutionEntries = ( - obj: Record<string, unknown>, -): Either<Array<[string, unknown]>, Record<string, string>> => { - const invalidEntries = Object.entries(obj).filter((e) => - !e.every((x) => typeof x === "string" && validateIdentifier(x)) +type InvalidEntry<K, T> = [K, T]; +export const validateExecutionEntries = < + T, + K extends symbol | number | string = symbol | number | string, +>( + obj: Record<K, T>, +): IEither< + Array<InvalidEntry<K, T>>, + Record<string, string> +> => { + const invalidEntries = <Array<InvalidEntry<K, T>>> Object.entries(obj).filter( + (e) => !e.every((x) => typeof x === "string" && validateIdentifier(x)), ); if (invalidEntries.length > 0) return Either.left(invalidEntries); return Either.right(<Record<string, string>> obj); |