Skip to content

Latest commit

 

History

History
218 lines (155 loc) · 4.08 KB

README.md

File metadata and controls

218 lines (155 loc) · 4.08 KB

lil'-type Build Status Stories in Ready Code Climate Gitter chat

Modern, reliable, full featured, type checking helpers (based on hu)

Nametype
Version0.1.2
Size2 KB / >1 KB (gzipped)
EnvironmentNode, Browser

Features

  • Full type-checking support
  • Support upcoming ES6 data types (Generators, Promise, Map, WeakMap...)
  • Support for binary data types (Blob, File, FileReader...)
  • Support for buffer data types (ArrayBuffer, DataView...)
  • Support for typed arrays (Int8Array, Float32Array...)
  • Smart type inference

Installation

Node.js

npm install lil-type

Browser

Via Bower

bower install lil-type

Via Component

component install lil-js/type

Or loading the script remotely

<script src="//cdn.rawgit.com/lil-js/type/0.1.2/type.js"></script>

Environments

  • Node.js
  • Chrome >= 6
  • Firefox >= 4
  • Safari >= 5.1
  • Opera >= 12
  • IE >= 9

Usage

You could fetch de module via require() if it's available. Otherwise, global fallback will be used, exposed via lil.type

var lil = require('lil-type')
Type checking
lil.isObject({}) // -> true
lil.isArray([1,2,3]) // -> true
lil.isNumber(1.2) // -> true
lil.isBool(1.2) // -> true
lil.isRegExp(/[a-z]/) // -> true
Content checking
lil.isEmpty(void 0) // -> true
lil.isEmpty('') // -> true
lil.isEmpty([]) // -> true
lil.isEmpty({}) // -> true
lil.isEmpty(1.5) // -> false
lil.isEmpty(new Date) // -> false
Getting data type
lil.is('name') // -> 'string'
lil.is({}) // -> 'object'
lil.is([1]) // -> 'array'
lil.is(/[a-z]/) // -> 'regexp'
lil.is(function () {}) // -> 'function'
lil.is(void 0) // -> 'undefined'
Type handle helpers
lil.isIterable([1,2,3]) // -> true
lil.isIterable({ name: 'Chuck' }) // -> true
lil.isIterable(function () {}) // -> false
lil.isIterable(true) // -> false
lil.isMutable({}) // -> true
lil.isMutable([]) // -> true
lil.isMutable('') // -> false
lil.isMutable(/[a-z]/) // -> false

API

lil.isBool(o)

Alias: isBoolean

lil.isNumber(o)

lil.isNaN(o)

lil.isFinite(o)

lil.isString(o)

lil.isDate(o)

lil.isRegExp(o)

lil.isError(o)

lil.isFn(o)

Alias: isFunction

lil.isArguments(o)

lil.isSymbol(o)

lil.isArray(o)

lil.isTypedArray(o)

lil.isObject(o)

lil.isPlainObject(o)

lil.isElement(o)

lil.isNull(o)

lil.isUndefined(o)

lil.isPromise(o)

lil.isGenerator(o)

lil.isMap(o)

lil.isWeakMap(o)

lil.isWeakSet(o)

lil.isBinary(o)

lil.isBlob(o)

lil.isFile(o)

lil.isBuffer(o)

lil.isEmpty(o)

lil.notEmpty(o)

lil.isIterable(o)

lil.isPrimitive(o)

lil.isMutable(o)

lil.is(o)

Alias: isType

lil.type.VERSION

Contributing

Wanna help? Cool! It will be appreciated :)

You must add new test cases for any new feature or refactor you do, always following the same design/code patterns that already exist

Development

Only node.js is required for development

Clone the repository

$ git clone https://github.com/lil-js/type.git && cd type

Install dependencies

$ npm install

Generate browser bundle source

$ make browser

Run tests

$ make test

License

MIT © Tomas Aparicio