🌊
Deep Waters
  • What is Deep Waters
  • πŸ“ŒGetting started
    • Installation
  • 🍰Composition
    • compose
    • when
    • or
    • not
  • πŸ‘οΈ Validators
    • arrayOf
    • arrayOfShape
    • between
    • biggerThan
    • contains
    • equals
    • every
    • hasProp
    • hasShape
    • isCreditCard
      • isVISA
      • isMastercard
      • isAmericanExpress
      • isDinersClub
      • isDiscover
      • isJCB
    • isDateFormat [TD]
    • isDivisibleBy [TD]
    • isEmail [TD]
    • isEmpty [TD]
    • isEmptyString [TD]
    • isIP [TD]
      • isIPv6 [TD]
      • isIPv4 [TD]
    • isNumeric [TD]
    • isPhone [TD]
    • isPrimitive [TD]
    • isRequired [TD]
    • isURL [TD]
    • matchesPattern [TD]
    • maxLenght [TD]
    • minLength [TD]
    • ofLength [TD]
    • ofUniqueItems [TD]
    • ofClass
    • oneOfValues [TD]
    • smallerThan
  • βœ…Type validators
    • isBigInt
    • isBoolean
    • isBuffer
    • isDate
    • isError
    • isFunction
    • isInt8Array
    • isMap
    • isNull
    • isNumber
    • isObject
    • isRegExp
    • isSet
    • isString
    • isSymbol
    • isUint8Array
    • isUndefined
    • isWeakMap
    • isWeakSet
  • github repository
Powered by GitBook
On this page

Was this helpful?

  1. Type validators

isRegExp

isRegExp :: a β†’ Boolean

PreviousisObjectNextisSet

Last updated 5 years ago

Was this helpful?

Evaluates whether the given value is of type

import isRegExp from 'deep-waters/isRegExp';

isRegExp(/^foo$/); // β†’ true
isRegExp(new RegExp(/^foo$/)); // β†’ true

isRegExp("/^foo$/"]); // β†’ false
isRegExp(null); // β†’ false
isRegExp("foo"); // β†’ false

isRegExp, like any other type validator, is mostly used in composed validators:

import isString from 'deep-waters/isString';
import matchesPattern from 'deep-waters/matchesPattern';

const isEmail = compose(
  isString,
  matchesPattern(/^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/),
);

isRegExp is built on top of validator and rely on Object.prototype.toString to check on the received value type in order to avoid and encouraging a runtime strict type validation.

βœ…
RegExp
ofClass
typeof weird behaviours