pure-conditions

A set of pure functions for simple conditions

91 methods available

endsWith

Checks if first string ends with the second string.

endsWith("ban qux", "qux")→ true

exists

Checks if object is defined.

exists({})→ true

hasAudioExtension

Checks if the string has an audio file extension.

hasAudioExtension("foo.mp3")→ true

hasDuplicates

Checks if the array contains duplicate values.

hasDuplicates(["foo", "foo"])→ true

hasExtension

Checks if the string has given extension.

hasExtension("foo.txt", "txt")→ true

hasKeys

Checks if the passed object has any key.

hasKeys({ foo: "bar" })→ true

hasLengthOf

Checks if the length of value is equal the number.

hasLengthOf([1, 2], 2)→ true

hasLengthOfAtLeast

Checks if the length of value is greater or equal the number.

hasLengthOfAtLeast([1, 2], 2)→ true
hasLengthOfAtLeast([1, 2, 3], 2)→ true

hasLengthOfAtMost

Checks if the length of value is smaller or equal the number.

hasLengthOfAtMost([1, 2, 3, 4, 5], 10)→ true
hasLengthOfAtMost([1, 2, 3], 2)→ false

hasNewLine

Checks if the value contains the new line char.

hasNewLine("foo bar")→ true

hasNumber

Checks if the value contains at least one number.

hasNumber([1, 2])→ true
hasNumber({ foo: 1, bar: "baz" })→ true

hasNumbers

Checks if the value contains more than one number.

hasNumbers([1, 2])→ true
hasNumbers({ foo: 1, bar: "baz", ban: 2 })→ true

hasTypeOf

Checks the type of passed value.

hasTypeOf(32, "number")→ true

hasVideoExtension

Checks if the string has a video file extension.

hasVideoExtension("foo.mkv")→ true

hasWhitespace

Checks if the string contains whitespaces.

hasWhitespace("foo bar")→ true
hasWhitespace("foo bar")→ true

hasWords

Checks if the string contains particular number of words.

hasWords("foo bar baz", 3)→ true
hasWords(myVariable)→ true

have

Checks if the length of value is equal the number.

have([1, 2, 3, 4, 5], 5)→ true

haveLessThan

Checks if the length of value is smaller than the number.

haveLessThan([1, 2, 3], 10)→ true

haveMany

Checks if the array have more than one element.

haveMany([1, 2])→ true

haveMoreThan

Checks if the length of value is greater than number.

haveMoreThan([1, 2, 3, 4, 5], 4)→ true

includes

Checks if first value includes second value.

includes("lorem ipsum", "lorem")→ true

isAlpha

Checks if the string contains only letters.

isAlpha("foo")→ true
isAlpha("foo123")→ false

isAlphaNumeric

Checks if the string contains only letters and numbers.

isAlphaNumeric("foo")→ true
isAlphaNumeric("foo123")→ true

isAlternative

Returns true when one value from passed values is truthy.

isAlternative(0, 1)→ true
isAlternative(1, 1)→ true

isArray

Checks if the value is an array.

isArray([])→ true

isBetween

Checks if first is between second and third number.

isBetween(10, 5, 20)→ true

isBitwiseAlternative

Returns boolean value of bitwise alternative.

isBitwiseAlternative(1, 0)→ true
isBitwiseAlternative(1, 1)→ true

isBitwiseAlternativeNegation

Returns boolean value of bitwise alternative negation.

isBitwiseAlternativeNegation(1, 0)→ true
isBitwiseAlternativeNegation(0, 1)→ true

isBitwiseConjunction

Returns boolean value of bitwise conjunction.

isBitwiseConjunction(1, 1)→ true

isBitwiseNegation

Returns boolean value of bitwise negation.

isBitwiseNegation(0)→ true

isBoolean

Checks if the value is an boolean.

isBoolean(true)→ true
isBoolean(1)→ false

isConjunction

Returns true when both values from passed values are truthy.

isConjunction(1, 1)→ true

isDate

Checks if the value is an date.

isDate(new Date())→ true

isDecimal

Checks if the value is an decimal.

isDecimal(2.5)→ true

isDefined

Checks if the value is defined (different than undefined).

isDefined({ foo: "bar" })→ true
isDefined(null)→ true
isDefined(undefined)→ false

isDigit

Checks if the value is an digit.

isDigit(2)→ true
isDigit("2")→ true

isDivisible

Checks if one number is divisible by second number.

isDivisible(10, 5)→ true

isEmail

Checks if the string is an email.

isEmail("foobar@gmail.com")→ true

isEmpty

Checks if the value is empty.

isEmpty([])→ true
isEmpty({})→ true

isEmptyArray

Checks if the array is empty.

isEmptyArray([])→ true

isEmptyObject

Checks if the object is empty.

isEmptyObject({})→ true

isEmptySet

Checks if the set is empty.

isEmptySet(new Set([]))→ true

isEqual

Checks if values are equal.

isEqual("foo", "foo")→ true
isEqual([1, 3, 2], [1, 2, 3])→ true
isEqual([1, 2, 3], [1, 2, 3])→ true
isEqual([1, 3, 2], [1, 2, 3], true)→ false
isEqual([1, 2, 3], [1, 2, 3], true)→ true

isError

Checks if passed object is an error object.

isError(new Error("ValidationError"))→ true

isEven

Checks if the number is even.

isEven(2)→ true

isExclusiveAlternative

Returns true when one value from passed values is truthy and second is falsy.

isExclusiveAlternative(1, 0)→ true
isExclusiveAlternative(0, 1)→ true

isExtensible

Determines if an object can be extend by new properties.

isExtensible({})→ true

isFalsy

Checks if passed value is an falsy value.

isFalsy(false)→ true
isFalsy(null)→ true

isFinite

Checks if the number is finite.

isFinite(100)→ true

isFrozen

Checks if tje object is frozen (cannot add, remove, change object properties).

isFrozen(Object.freeze({}))→ true

isFunction

Checks if passed value is a function.

isFunction(function () {})→ true

isGreaterThan

Checks if first number is greater than second.

isGreaterThan(10, 5)→ true

isGreaterThanOrEqual

Checks if first value is greater or equal second value.

isGreaterThanOrEqual(42, 42)→ true

isImage

Checks if the string is a name of image file.

isImage("foo.jpg")→ true

isIn

Checks if the first value includes second value.

isIn(5, [5, 10, 15])→ true
isIn("5", "12345")→ true

isInfinite

Checks if the number is infinite.

isInfinite(Infinity)→ true

isInstanceOf

Checks if the prototype property of a constructor exists in the prototype chain of an object.

isInstanceOf(["foo", "bar"], Array)→ true

isLaterThan

Checks if one date is later than second date.

isLaterThan(new Date(2018, 4, 11), new Date(2018, 4, 1))→ true

isLessThan

Checks if first number is smaller than second.

isLessThan(2, 5)→ true

isLessThanOrEqual

Checks if first number is smaller or equal second.

isLessThanOrEqual(3,5)→ true

isMap

Checks if the value is a map.

isMap(new Map([ ["foo", "bar"] ]))→ true

isMissing

Checks if object is undefined.

isMissing(null)→ true

isMultiple

Checks if one number is multiple of second number.

isMultiple(200, 100)→ true

isNaN

Checks if passed value is NaN and the type of value is Number.

isNaN(NaN)→ true

isNegative

Checks if the number is negative.

isNegative(-100)→ true

isNull

Checks if the value is null.

isNull(null)→ true
isNull(0)→ false

isNumber

Checks if the value is an number.

isNumber(2)→ true

isNumeric

Checks if the value is an numeric (a number or string that could be converted to number).

isNumeric(2)→ true
isNumeric("2")→ true

isObject

Checks if the value is an object.

isObject({})→ true
isObject(function () {})→ true

isOdd

Checks if the number is odd.

isOdd(1)→ true

isPalindrome

Checks if the value is palindrome.

isPalindrome("devil lived")→ true

isPhone

Checks if the string is a valid phone number.

isPhone("+48 123 345 67")→ true

isPlainObject

Checks if passed value is an object.

isPlainObject({})→ true
isPlainObject([])→ false

isPositive

Checks if the number is positive.

isPositive(100)→ true

isPresent

Checks if the value is present (different than undefined).

isPresent({ foo: "bar" })→ true
isPresent(null)→ true

isPrime

Checks if the number is prime.

isPrime(13)→ true

isRegExp

Checks if the value is an regural expression.

isRegExp(/foo/)→ true

isSealed

Checks if the object is frozen (cannot add and remove object properties).

isSealed(Object.seal({}))→ true

isSet

Checks if the value is an set.

isSet(new Set())→ true

isSoonerThan

Checks if one date is sooner than second date.

isSoonerThan(new Date(2018, 4, 1), new Date(2018, 4, 11))→ true

isString

Checks if the value is an string.

isString("foo")→ true

isSymbol

Checks if the value is an symbol.

isSymbol(Symbol("foo"))→ true

isTruthy

Checks if passed value is an truthy value.

isTruthy({})→ true
isTruthy([])→ true

isUndefined

Checks if the value is undefined.

isUndefined(undefined)→ true

isUrl

Checks if the string is an url.

isUrl("https://buxlabs.pl/narzędzia/js")→ true

isWeakMap

Checks if the value is an weakmap.

isWeakMap(new WeakMap())→ true

isWeakSet

Checks if the value is an weakset.

isWeakSet(new WeakSet())→ true

matches

Checks if string matches passed regExp.

matches("lorem ipsum", /ipsum/)→ true

notEqual

Checks if values are different.

notEqual("foo", "bar")→ true

respondsTo

Checks if object has function with the name given in string.

respondsTo({ foo: function () {} }, "foo")→ true

startsWith

Checks if first string starts with the second string.

startsWith("ban qux", "ban")→ true