Check whether all values are equal
Compare every item with the first using Object.is.
function allEqual(values) { return values.every(value => Object.is(value, values[0])); }validatorCollection · 47 utilities
Checks that answer yes or no: emptiness, parity, equality and the Gregorian leap-year rules. Each states exactly what it compares.
Compare every item with the first using Object.is.
function allEqual(values) { return values.every(value => Object.is(value, values[0])); }validatorCheck for own enumerable string keys on a JSON object.
function isEmpty(value) { return Object.keys(value).length === 0; }validatorTest parity for safe integers, including zero and negative values.
function isEven(value) { return value % 2 === 0; }validatorApply the Gregorian divisible-by-4, century and 400-year rules.
function isLeapYear(year) { return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0); }validatorTest that a string is exactly one ASCII digit from 0 to 9.
function isDigit(char) { return /^[0-9]$/.test(char); }validatorReturn true when a YYYY-MM-DD date falls on a Saturday or Sunday.
function isWeekend(date) { return new Date(date).getUTCDay() % 6 === 0; }validatorCompare the size of a Set with the array length.
function hasDuplicates(values) { return new Set(values).size !== values.length; }validatorTest whether a YYYY-MM-DD date falls inside an inclusive range.
function isBetween({ date, min, max }) { const time = Date.parse(date); return time >= Date.par…validatorCompare the UTC calendar day of a date-time with the current one.
function isToday({ dateTime, now }) { return new Date(dateTime).toISOString().slice(0, 10) === …validatorCompare the UTC year of a date-time with the current one.
function isCurrentYear({ dateTime, now }) { return new Date(dateTime).getUTCFullYear() === new …validatorTrial division up to the square root, without allocating an array.
function isPrime(n) { if (n < 2) return false; for (let i = 2; i * i <= n; i++) if (n % i === 0…validatorReturn true for numbers greater than zero.
function isPositive(n) { return Math.sign(n) === 1; }validatorCompare a string with its lowercase form.
function containsUpperCase(text) { return text !== text.toLowerCase(); }validatorReturn true for a YYYY-MM-DD date from Monday to Friday.
function isWeekday(date) { return new Date(date).getUTCDay() % 6 !== 0; }validatorUse the bit trick n & (n − 1) on a positive integer.
function isPowerOfTwo(n) { return n > 0 && (n & (n - 1)) === 0; }validatorReturn true for numbers below zero.
function isNegative(n) { return n < 0; }validatorTest for one or more ASCII letters or digits.
function isAlphanumeric(text) { return /^[0-9A-Z]+$/i.test(text); }validatorTest for exactly 24 hexadecimal characters.
function isMongoId(text) { return /^[0-9a-f]{24}$/i.test(text); }validatorCompare a string with its uppercase form.
function isUpperCase(text) { return text === text.toUpperCase(); }validatorCompare every item with a value using ===.
function isEqual({ values, value }) { return values.every(item => item === value); }validatorTest an inclusive range whose ends may be given in any order, with an optional tolerance.
function inRange({ value, a, b, threshold = 0 }) { return Math.min(a, b) - threshold <= value &…validatorTest that an integer leaves a remainder when divided by 2.
function isOdd(n) { return n % 2 !== 0; }validatorCompare a string with its uppercase form.
function containsLowerCase(text) { return text !== text.toUpperCase(); }validatorTest that every character is in the 0–127 range.
function isAscii(text) { return /^[\x00-\x7F]+$/.test(text); }validatorTest for one or more ASCII digits.
function isNumeric(text) { return /^[0-9]+$/.test(text); }validatorTest for one or more ASCII letters.
function isAlpha(text) { return /^[A-Z]+$/i.test(text); }validatorAccept #rgb, #rgba, #rrggbb and #rrggbbaa.
function isHexColor(color) { return /^#([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i.tes…validatorTest for one or more hexadecimal digits.
function isHexadecimal(text) { return /^[0-9a-f]+$/i.test(text); }validatorTest for octal digits with an optional 0o prefix.
function isOctal(text) { return /^(0o)?[0-7]+$/i.test(text); }validatorCompare a string with its lowercase form.
function isLowerCase(text) { return text === text.toLowerCase(); }validatorTest the shape of an 8- or 11-character BIC (SWIFT) code.
function isBic(value) { return /^[a-zA-Z]{6}[a-zA-Z0-9]{2}([a-zA-Z0-9]{3})?$/.test(value); }validatorReturn true for objects whose prototype is Object.prototype or null.
function isPlainObject(value) { return value !== null && typeof value === 'object' && [null, Ob…validatorUse Object.prototype.toString so String objects count too.
function isString(value) { return Object.prototype.toString.call(value) === '[object String]'; …validatorTest the RFC 4648 base32 alphabet and a length that is a multiple of 8.
function isBase32(value) { return value.length % 8 === 0 && /^[A-Z2-7]+=*$/.test(value); }validatorTest the Bitcoin base58 alphabet, which leaves out 0, O, I and l.
function isBase58(value) { return /^[A-HJ-NP-Za-km-z1-9]*$/.test(value); }validatorReturn true for null and undefined.
function isNil(value) { return value == null; }validatorReturn true for an array with at least one item.
function isNotEmpty(value) { return Array.isArray(value) && value.length > 0; }validatorReturn true when every value of subset appears in of.
function isSubset({ subset, of }) { const all = new Set(of); return subset.every(value => all.h…validatorCheck that a year, a 1-based month and a day form a real calendar date.
function isValidDate({ year, month, day }) { const leap = year % 4 === 0 && (year % 100 !== 0 |…validatorTest for any whitespace character.
function containsWhitespace(text) { return /\s/.test(text); }validatorAccept finite numbers and numeric strings.
function isNumber(value) { return !isNaN(parseFloat(value)) && isFinite(value); }validatorReturn true for any non-null object, including arrays.
function isObject(value) { return value !== null && typeof value === 'object'; }validatorTest standard, padded base64.
function isBase64(value) { return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}…validatorUse Array.isArray, which works across realms.
function isArray(value) { return Array.isArray(value); }validatorRead the internal tag, which also works for values from another realm.
function isRegExp(value) { return Object.prototype.toString.call(value) === '[object RegExp]'; …validatorTrue when at least one item satisfies the predicate.
function contains(values, predicate) { return values.some(predicate); }validatorDetect a thenable: an object or function with a then method.
function isPromise(value) { return value !== null && (typeof value === 'object' || typeof value…validatorTry a function in the local code lab, then read its limits before using it in an application.