mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-17 13:38:07 +01:00
chore(module): lint
This commit is contained in:
@@ -4,21 +4,21 @@ import type { ObjectSchema as YupObjectSchema, ValidationError as YupError } fro
|
||||
import type { ObjectSchemaAsync as ValibotObjectSchema } from 'valibot'
|
||||
import type { FormError } from '#ui/types/form'
|
||||
|
||||
export function isYupSchema (schema: any): schema is YupObjectSchema<any> {
|
||||
export function isYupSchema(schema: any): schema is YupObjectSchema<any> {
|
||||
return schema.validate && schema.__isYupSchema__
|
||||
}
|
||||
|
||||
export function isYupError (error: any): error is YupError {
|
||||
export function isYupError(error: any): error is YupError {
|
||||
return error.inner !== undefined
|
||||
}
|
||||
|
||||
export async function getYupErrors (state: any, schema: YupObjectSchema<any>): Promise<FormError[]> {
|
||||
export async function getYupErrors(state: any, schema: YupObjectSchema<any>): Promise<FormError[]> {
|
||||
try {
|
||||
await schema.validate(state, { abortEarly: false })
|
||||
return []
|
||||
} catch (error) {
|
||||
if (isYupError(error)) {
|
||||
return error.inner.map((issue) => ({
|
||||
return error.inner.map(issue => ({
|
||||
name: issue.path ?? '',
|
||||
message: issue.message
|
||||
}))
|
||||
@@ -28,14 +28,14 @@ export async function getYupErrors (state: any, schema: YupObjectSchema<any>): P
|
||||
}
|
||||
}
|
||||
|
||||
export function isZodSchema (schema: any): schema is ZodSchema {
|
||||
export function isZodSchema(schema: any): schema is ZodSchema {
|
||||
return schema.parse !== undefined
|
||||
}
|
||||
|
||||
export async function getZodErrors (state: any, schema: ZodSchema): Promise<FormError[]> {
|
||||
export async function getZodErrors(state: any, schema: ZodSchema): Promise<FormError[]> {
|
||||
const result = await schema.safeParseAsync(state)
|
||||
if (result.success === false) {
|
||||
return result.error.issues.map((issue) => ({
|
||||
return result.error.issues.map(issue => ({
|
||||
name: issue.path.join('.'),
|
||||
message: issue.message
|
||||
}))
|
||||
@@ -43,21 +43,21 @@ export async function getZodErrors (state: any, schema: ZodSchema): Promise<Form
|
||||
return []
|
||||
}
|
||||
|
||||
export function isJoiSchema (schema: any): schema is JoiSchema {
|
||||
export function isJoiSchema(schema: any): schema is JoiSchema {
|
||||
return schema.validateAsync !== undefined && schema.id !== undefined
|
||||
}
|
||||
|
||||
export function isJoiError (error: any): error is JoiError {
|
||||
export function isJoiError(error: any): error is JoiError {
|
||||
return error.isJoi === true
|
||||
}
|
||||
|
||||
export async function getJoiErrors (state: any, schema: JoiSchema): Promise<FormError[]> {
|
||||
export async function getJoiErrors(state: any, schema: JoiSchema): Promise<FormError[]> {
|
||||
try {
|
||||
await schema.validateAsync(state, { abortEarly: false })
|
||||
return []
|
||||
} catch (error) {
|
||||
if (isJoiError(error)) {
|
||||
return error.details.map((detail) => ({
|
||||
return error.details.map(detail => ({
|
||||
name: detail.path.join('.'),
|
||||
message: detail.message
|
||||
}))
|
||||
@@ -67,15 +67,15 @@ export async function getJoiErrors (state: any, schema: JoiSchema): Promise<Form
|
||||
}
|
||||
}
|
||||
|
||||
export function isValibotSchema (schema: any): schema is ValibotObjectSchema<any> {
|
||||
export function isValibotSchema(schema: any): schema is ValibotObjectSchema<any> {
|
||||
return schema._parse !== undefined
|
||||
}
|
||||
|
||||
export async function getValibotError (state: any, schema: ValibotObjectSchema<any>): Promise<FormError[]> {
|
||||
export async function getValibotError(state: any, schema: ValibotObjectSchema<any>): Promise<FormError[]> {
|
||||
const result = await schema._parse(state)
|
||||
if (result.issues) {
|
||||
return result.issues.map((issue) => ({
|
||||
name: issue.path?.map((p) => p.key).join('.') || '',
|
||||
return result.issues.map(issue => ({
|
||||
name: issue.path?.map(p => p.key).join('.') || '',
|
||||
message: issue.message
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export function pick<Data extends object, Keys extends keyof Data> (data: Data, keys: Keys[]): Pick<Data, Keys> {
|
||||
export function pick<Data extends object, Keys extends keyof Data>(data: Data, keys: Keys[]): Pick<Data, Keys> {
|
||||
const result = {} as Pick<Data, Keys>
|
||||
|
||||
for (const key of keys) {
|
||||
@@ -8,17 +8,18 @@ export function pick<Data extends object, Keys extends keyof Data> (data: Data,
|
||||
return result
|
||||
}
|
||||
|
||||
export function omit<Data extends object, Keys extends keyof Data> (data: Data, keys: Keys[]): Omit<Data, Keys> {
|
||||
export function omit<Data extends object, Keys extends keyof Data>(data: Data, keys: Keys[]): Omit<Data, Keys> {
|
||||
const result = { ...data }
|
||||
|
||||
for (const key of keys) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
||||
delete result[key]
|
||||
}
|
||||
|
||||
return result as Omit<Data, Keys>
|
||||
}
|
||||
|
||||
export function looseToNumber (val: any): any {
|
||||
const n = parseFloat(val)
|
||||
return isNaN(n) ? val : n
|
||||
export function looseToNumber(val: any): any {
|
||||
const n = Number.parseFloat(val)
|
||||
return Number.isNaN(n) ? val : n
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user