mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 09:46:28 +08:00
core: validator: support 'convert' as default action
fix #505, close #506
This commit is contained in:
1 parent
02c0d7aaa8
commit
1124ed9506
7 files changed
+11
-9
No files matched your search
@@ -8,7 +8,7 @@ import saslprep from 'saslprep';
|
||||
type InputType = string | number | Record<string, any> | any[];
|
||||
export type Converter<T> = (value: any) => T;
|
||||
export type Validator<Loose extends boolean = true> = (value: Loose extends true ? any : InputType) => boolean;
|
||||
export type Type<T> = readonly [Converter<T>, Validator<false>?, boolean?];
|
||||
export type Type<T> = readonly [Converter<T>, Validator<false>?, (boolean | 'convert')?];
|
||||
|
||||
export interface Types {
|
||||
// String outputs
|
||||
@@ -95,7 +95,7 @@ export const Types: Types = {
|
||||
Float: [(v) => +v, (v) => Number.isFinite(+v)],
|
||||
|
||||
ObjectID: [(v) => new ObjectID(v), ObjectID.isValid],
|
||||
Boolean: [(v) => v && !['false', 'off'].includes(v), null, true],
|
||||
Boolean: [(v) => !!(v && !['false', 'off'].includes(v)), null, 'convert'],
|
||||
Date: [
|
||||
(v) => {
|
||||
const d = v.split('-');
|
||||
|
||||
Reference in new issue
Block a user