@yobta/validator
Version:
Tree-shakable es6 validator
10 lines (9 loc) • 424 B
JavaScript
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;
});