mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
feat: create languageSchema
This commit is contained in:
parent
dac11a9055
commit
92aaca0d91
1 changed files with 13 additions and 0 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
import ISO6391 from 'iso-639-1';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
/** Validates individual items in an array, dropping any that aren't valid. */
|
/** Validates individual items in an array, dropping any that aren't valid. */
|
||||||
|
|
@ -40,12 +41,24 @@ const fileSchema = z.custom<File>((value) => value instanceof File);
|
||||||
|
|
||||||
const percentageSchema = z.coerce.number().int().gte(1).lte(100);
|
const percentageSchema = z.coerce.number().int().gte(1).lte(100);
|
||||||
|
|
||||||
|
const languageSchema = z.string().max(2).transform((val, ctx) => {
|
||||||
|
if (!ISO6391.validate(val)) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
message: 'Not a valid language in ISO-639-1 format',
|
||||||
|
});
|
||||||
|
return z.NEVER;
|
||||||
|
}
|
||||||
|
return val;
|
||||||
|
});
|
||||||
|
|
||||||
export {
|
export {
|
||||||
booleanParamSchema,
|
booleanParamSchema,
|
||||||
decode64Schema,
|
decode64Schema,
|
||||||
fileSchema,
|
fileSchema,
|
||||||
filteredArray,
|
filteredArray,
|
||||||
hashtagSchema,
|
hashtagSchema,
|
||||||
|
languageSchema,
|
||||||
percentageSchema,
|
percentageSchema,
|
||||||
safeUrlSchema,
|
safeUrlSchema,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue