1.1.0 • Published 7 years ago

@fdaciuk/is v1.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

is

Typechecker in Vanilla JS

Build Status Coveralls Coverage Status Code Climate Coverage Code Climate License CONTRIBUTING

Why?

Because type checking in JS is hard. See some examples:

console.log(typeof 1) // 'number'
console.log(typeof 'javascript') // 'string'
console.log(typeof {}) // 'object'
console.log(typeof []) // 'object' wat?
console.log(typeof null) // 'object' wat? wat?
console.log(typeof new String('js')) // 'object' :|

That's why @fdaciuk/is is useful. See some examples using this library in ES2015:

import is from '@fdaciuk/is'

console.log(is('number', 10)) // true
console.log(is('object', {})) // true
console.log(is('array', [])) // true
console.log(is('object', [])) // false
console.log(is('string', new String('js'))) // true (yes, 'string', not 'object')

Installation

Yarn

yarn add @fdaciuk/is

NPM

npm i --save @fdaciuk/is

Usage

AMD

define(['is'], function (is) {
  console.log(is('arguments', arguments)) // true
})

CommonJS

var is = require('@fdaciuk/is').default
console.log(is('array', [])) // true

ES6 / ES2015 Module

import is from '@fdaciuk/is'

const isString = is('string')
console.log(isString('daciuk')) // true

Method of window object

console.log(window.is('number', 10)) // true

Signature

is(typeToTest, value)
// or
is(typeToTest)(value)

Documentation

is

A function that checks if a value is of a type:

import is from '@fdaciuk/is'
// or using commonjs:
// var is = require('@fdaciuk/is').default

const value = []

if (is('array', value)) {
  // do something
}

typeOf

A function that returns a real type of a value:

import { typeOf } from '@fdaciuk/is'
// or using commonjs:
// var typeOf = require('@fdaciuk/is').typeOf

console.log(typeOf([])) // 'array'
console.log(typeOf(123)) // 'number'
console.log(typeOf(new String('hey'))) // 'string', not 'object'

Contributing

Check CONTRIBUTING.md

License

MIT © Fernando Daciuk

1.1.0

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.0.26

7 years ago

0.0.25

7 years ago

0.0.24

7 years ago

0.0.23

7 years ago

0.0.22

7 years ago

0.0.21

7 years ago

0.0.20

7 years ago

0.0.19

7 years ago

0.0.18

7 years ago

0.0.17

7 years ago

0.0.16

7 years ago

0.0.15

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.1

7 years ago