UNPKG

@yobta/validator

Version:
10 lines (9 loc) 428 B
import { pluralizeEn } from '../_internal/pluralizeEn/index.js'; import { rule } from '../rule/rule.js'; export const minCharactersMessage = (limit) => `It should have at least ${pluralizeEn(limit, 'character')}`; export const minCharacters = (limit, message = minCharactersMessage) => rule((input) => { if (input !== undefined && input.length < limit) { throw new Error(message(limit)); } return input; });