Giter Site home page Giter Site logo

is's Introduction

is Version Badge

Build Status dependency status dev dependency status License Downloads

npm badge

browser support

The definitive JavaScript type testing library

To be or not to be? This is the library!

Installation

As a node.js module

$ npm install is

As a component

$ component install enricomarino/is

API

general

  • is.a (value, type) or is.type (value, type)
  • is.defined (value)
  • is.empty (value)
  • is.equal (value, other)
  • is.hosted (value, host)
  • is.instance (value, constructor)
  • is.instanceof (value, constructor) - deprecated, because in ES3 browsers, "instanceof" is a reserved word
  • is.nil (value)
  • is.null (value) - deprecated, because in ES3 browsers, "null" is a reserved word
  • is.undef (value)
  • is.undefined (value) - deprecated, because in ES3 browsers, "undefined" is a reserved word

arguments

  • is.args (value)
  • is.arguments (value) - deprecated, because "arguments" is a reserved word
  • is.args.empty (value)

array

  • is.array (value)
  • is.array.empty (value)
  • is.arraylike (value)

boolean

  • is.bool (value)
  • is.boolean (value) - deprecated, because in ES3 browsers, "boolean" is a reserved word
  • is.false (value) - deprecated, because in ES3 browsers, "false" is a reserved word
  • is.true (value) - deprecated, because in ES3 browsers, "true" is a reserved word

date

  • is.date (value)

element

  • is.element (value)

error

  • is.error (value)

function

  • is.fn (value)
  • is.function (value) - deprecated, because in ES3 browsers, "function" is a reserved word

number

  • is.number (value)
  • is.infinite (value)
  • is.decimal (value)
  • is.divisibleBy (value, n)
  • is.integer (value)
  • is.int (value) - deprecated, because in ES3 browsers, "int" is a reserved word
  • is.maximum (value, others)
  • is.minimum (value, others)
  • is.nan (value)
  • is.even (value)
  • is.odd (value)
  • is.ge (value, other)
  • is.gt (value, other)
  • is.le (value, other)
  • is.lt (value, other)
  • is.within (value, start, finish)

object

  • is.object (value)

regexp

  • is.regexp (value)

string

  • is.string (value)

encoded binary

  • is.base64 (value)
  • is.hex (value)

Symbols

  • is.symbol (value)

BigInts

  • is.bigint (value)

Contributors

is's People

Contributors

enricomarino avatar euank avatar gi60s avatar ivoputzer avatar javiercejudo avatar ljharb avatar pgirard avatar roark avatar shakiba avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

is's Issues

BigInt support

Since May, Chrome has support for BigInt.

I think it would be interesting to have is.bigint, wouldn't it?

v3.0.0 corrupted on npm?

I'm not sure if it's just me or what, but I whenever I install is, it is missing index.js, so I keep getting the "can't find module 'is'" error.

Is anyone else experiencing this? I've cleared out every bit of npm cache I can think of, still getting the same result.

Bug: is.equal on 2 empty arrays causes infinite loop

Hi Enciromarino,

Love your library. Came across a bug that causes an infinite loop when comparing 2 empty arrays using is.equal().

Can easily be replicated by trying:
is.equal([], [])

Thanks for the great library!

Can you support all types of judgment?

I may need various types of judgment, but they are incomplete, such as isBuffer, isArrayBuffer ,isStream...

I can use import {isBuffer} from'lodash'

However, it does not have isArrayBuffer, isStream, isURLSearchParams, and expects is to accommodate all types of judgments, so that only the introduction of is can be used to facilitate the determination of any type

import { isBuffer, isSet } from 'lodash';

is.buffer = isBuffer;
is.set = isSet;

/**
 * Determine if a value is an ArrayBuffer
 *
 * @param {Object} val The value to test
 * @returns {boolean} True if value is an ArrayBuffer, otherwise false
 */
function isArrayBuffer(val) {
  return toStr.call(val) === '[object ArrayBuffer]';
}

/**
 * Determine if a value is a FormData
 *
 * @param {Object} val The value to test
 * @returns {boolean} True if value is an FormData, otherwise false
 */
function isFormData(val) {
  return (typeof FormData !== 'undefined') && (val instanceof FormData);
}

/**
 * Determine if a value is a view on an ArrayBuffer
 *
 * @param {Object} val The value to test
 * @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
 */
function isArrayBufferView(val) {
  var result;
  if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {
    result = ArrayBuffer.isView(val);
  } else {
    result = (val) && (val.buffer) && (val.buffer instanceof ArrayBuffer);
  }
  return result;
}

/**
 * Determine if a value is a File
 *
 * @param {Object} val The value to test
 * @returns {boolean} True if value is a File, otherwise false
 */
function isFile(val) {
  return toStr.call(val) === '[object File]';
}

/**
 * Determine if a value is a Blob
 *
 * @param {Object} val The value to test
 * @returns {boolean} True if value is a Blob, otherwise false
 */
function isBlob(val) {
  return toStr.call(val) === '[object Blob]';
}

/**
 * Determine if a value is a Stream
 *
 * @param {Object} val The value to test
 * @returns {boolean} True if value is a Stream, otherwise false
 */
function isStream(val) {
  return is.object(val) && is.function(val.pipe);
}

/**
 * Determine if a value is a URLSearchParams object
 *
 * @param {Object} val The value to test
 * @returns {boolean} True if value is a URLSearchParams object, otherwise false
 */
function isURLSearchParams(val) {
  return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams
}

/**
 * Determine if we're running in a standard browser environment
 *
 * This allows axios to run in a web worker, and react-native.
 * Both environments support XMLHttpRequest, but not fully standard globals.
 *
 * web workers:
 *  typeof window -> undefined
 *  typeof document -> undefined
 *
 * react-native:
 *  navigator.product -> 'ReactNative'
 */
function isStandardBrowserEnv() {
  if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
    return false;
  }
  return (
    typeof window !== 'undefined' &&
    typeof document !== 'undefined';
  )
}

is.number(NaN) returns true

I realize that this is intentional, but I'm not sure how you can justify calling NaN a number when it is expressly designed to represent the concept of something that is not a number. This behavior defies expectations.

is.not?

I wonder if implementing jasmine-like syntax sugar makes any sense. For example is.not.object. I can try and implement that if you would be interested in including such feature.

is.fn(async function () {}) returns false

$ node --harmony
> process.versions.node
'7.5.0'
> require('is').fn(async function () {})
false
> Object.prototype.toString.call(async function () {})
'[object AsyncFunction]'
> typeof async function () {}
'function'

The problem is toStr.call(asyncFunction) returns [object AsyncFunction] instead [object Function].

Maybe it would be better to use typeof fn === 'function' instead toStr.call(fn) === '[object Function]'?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.