UNPKG

@yobta/validator

Version:
10 lines (9 loc) 424 B
import { pluralizeEn } from '../_internal/pluralizeEn/index.js'; import { rule } from '../rule/rule.js'; export const maxCharactersMessage = (limit) => `It should be within ${pluralizeEn(limit, 'character')}`; export const maxCharacters = (limit, message = maxCharactersMessage) => rule((input) => { if (input !== undefined && input.length > limit) { throw new Error(message(limit)); } return input; });