MCPcopy Index your code
hub / github.com/validatorjs/validator.js / isPostalCode

Function isPostalCode

src/lib/isPostalCode.js:85–103  ·  view source on GitHub ↗
(str, locale)

Source from the content-addressed store, hash-verified

83export const locales = Object.keys(patterns);
84
85export default function isPostalCode(str, locale) {
86 assertString(str);
87 if (locale in patterns) {
88 return patterns[locale].test(str);
89 } else if (locale === 'any') {
90 for (const key in patterns) {
91 // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
92 // istanbul ignore else
93 if (patterns.hasOwnProperty(key)) {
94 const pattern = patterns[key];
95 if (pattern.test(str)) {
96 return true;
97 }
98 }
99 }
100 return false;
101 }
102 throw new Error(`Invalid locale '${locale}'`);
103}

Callers

nothing calls this directly

Calls 1

assertStringFunction · 0.85

Tested by

no test coverage detected