Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | 70x 70x 1x 1x 4x 3x 1x 1x 1x 1x 4x 4x 4x 4x 4x 4x 4x 4x 4x 25x 34x 17x | import { Nullable } from '../types' import { isInteger, isNumeric, toNumber } from '../utils' import { VaeLocale, VaeLocaleMessage } from './VaeLocale' import { VaeSchema } from './VaeSchema' export class VaeNumberSchema< T0 extends Nullable<number> = number, > extends VaeSchema<T0> { constructor(message: VaeLocaleMessage = VaeLocale.number.type) { super({ type: 'number', }) this.check({ fn: isNumeric, message: message, }).transform(toNumber as any) } /** * 最小值 */ min(value: number, message: VaeLocaleMessage = VaeLocale.number.min) { return this.check({ fn: v => v >= value, message: message, messageParams: { min: value, }, tag: 'min', }) } /** * 最大值 */ max(value: number, message: VaeLocaleMessage = VaeLocale.number.max) { return this.check({ fn: v => v <= value, message: message, messageParams: { max: value, }, tag: 'max', }) } /** * 小于 */ lessThan( value: number, message: VaeLocaleMessage = VaeLocale.number.lessThan, ) { return this.check({ fn: v => v < value, message: message, messageParams: { lessThan: value, }, tag: 'lessThan', }) } /** * 大于 */ moreThan( value: number, message: VaeLocaleMessage = VaeLocale.number.moreThan, ) { return this.check({ fn: v => v > value, message: message, messageParams: { moreThan: value, }, tag: 'moreThan', }) } /** * 整数,即 -100, -1, 0, 1, 2, 100, ... */ integer(message: VaeLocaleMessage = VaeLocale.number.integer) { return this.check({ fn: isInteger, message: message, tag: 'integer', }) } /** * 正数,即 0.01, 0.1, 1, 2, 3, ... */ positive(message: VaeLocaleMessage = VaeLocale.number.positive) { return this.check({ fn: v => v > 0, message: message, tag: 'positive', }) } /** * 非正数,即 0, -0.01, -1, -100, ... */ nonpositive(message: VaeLocaleMessage = VaeLocale.number.nonpositive) { return this.check({ fn: v => v <= 0, message: message, tag: 'nonpositive', }) } /** * 负数,即 -0.01, -1, -100, ... */ negative(message: VaeLocaleMessage = VaeLocale.number.negative) { return this.check({ fn: v => v < 0, message: message, tag: 'negative', }) } /** * 非负数,即 0, 0.01, 0.1, 1, 2.1, 100, ... */ nonnegative(message: VaeLocaleMessage = VaeLocale.number.nonnegative) { return this.check({ fn: v => v >= 0, message: message, tag: 'nonnegative', }) } /** * 正整数,即 1, 2, 3, 4, 5, ... */ positiveInteger( message: VaeLocaleMessage = VaeLocale.number.positiveInteger, ) { return this.check({ fn: v => v > 0 && isInteger(v), message: message, tag: 'positiveInteger', }) } /** * ID,即正整数,即 1, 2, 3, 4, 5, ... */ id(message: VaeLocaleMessage = VaeLocale.number.positiveInteger) { return this.positiveInteger(message) } } |