mirror of
https://github.com/swc-project/swc.git
synced 2024-12-27 15:42:51 +03:00
18 lines
489 B
TypeScript
18 lines
489 B
TypeScript
// Loaded from https://deno.land/x/validasaur/src/rules/max_length.ts
|
|
|
|
|
|
import type { Validity, Rule } from "../types.ts";
|
|
import { invalid } from "../utils.ts";
|
|
|
|
export function maxLength(maxValue: number): Rule {
|
|
return function maxLengthRule(value: any): Validity {
|
|
if (typeof value !== "string") {
|
|
return invalid("maxLength", { value, maxValue }, false);
|
|
}
|
|
|
|
if (value.length > maxValue) {
|
|
return invalid("maxLength", { value, maxValue }, false);
|
|
}
|
|
};
|
|
}
|