npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2019 – Ryan Hefner

is-lite

v0.6.0

Published

A tiny javascript type testing tool

Downloads

183,979

Maintainers

gilbarbaragilbarbara

Keywords

typetest

Readme

is-lite

NPM version build status is-lite Maintainability Test Coverage

Lightweight type check tool.

Typescript ready with type guards to infer the correct type inside conditionals.

Setup

npm install is-lite

Usage

import is from 'is-lite';

is('value'); // string
is.string('value'); // true

API

is(value)
Returns the type of the value.

Primitives are lowercase: bigint, boolean, null, number, string, symbol, undefined
The rest are camelcase: Array, Function, GeneratorFunction, Object, ...

is.array(value)

is.arrayOf(target: any[], predicate: (value: unknown) => boolean)
Check if all items in an array are of same type.

is.arrayOf(['a', 'b'], is.string); // true
is.arrayOf([123, 456], is.nnumber); // true

is.arrayOf(['a', 1], is.string); // false

is.asyncFunction(value)
Check if value is an async function that can be called with await

is.asyncFunction(async () => {}); // true
is.asyncFunction(() => {}); // false

is.boolean(value)

is.date(value)

is.defined(value)
Check if value is anything but undefined.

is.domElement(value)
Check if value is a DOM Element.

is.empty(value)
Returns true if:

  • the value is a string and length is 0
  • the value is an Object and Object.keys(value).length is 0
  • the value is an Array and length is 0
  • the value is a Map and size is 0
  • the value is a Set and size is 0

is.error(value)

is.function(value)

is.generator(value)
Check for an object that has its own .next() and .throw() methods and has a function definition for Symbol.iterator

is.generatorFunction(value)

is.instanceOf(value, class)
Check if value is a direct instance of class

class APIError extends Error {}

const error = new APIError('Fail');

is.instanceOf(error, APIError); // true 
is.instanceOf(error, Error); // false 

is.iterable(value)

is.map(value)

is.nan(value)

is.null(value)

is.nullOrUndefined(value)

is.number(value)
Note: is.number(NaN) returns false

is.numericString(value)
Check for a string that represents a number.

is.numericString('42'); // true
is.numericString('-5'); // true
is.numericString('Inifinity'); // true
is.numericString('NaN'); // true

is.object(value)
Remember that functions and arrays are objects too.

is.oneOf(target: any[], value: any)
Check if value exists is the target

const colors = ['red', 'green', 'blue'];

is.oneOf(colors, 'green'); // true
is.oneOf(colors, 'brown'); // false

is.plainObject(value)
Check if the object is created by either {}, new Object() or Object.create(null).

is.promise(value)

is.propertyOf(target: object, key: string, predicate?: (value: unknown) => boolean)
Check if key exists of target. if you pass a predicate function, it will check the value's type.

const map = { items: [1], isLogged: false, retries: 0 };

is.propertyOf(map, 'retries'); // true
is.propertyOf(map, 'auth'); // false

is.propertyOf(map, 'retries', is.number); // true
is.propertyOf(map, 'items', is.array); // true
is.propertyOf(map, 'isLogged', is.string); // false

is.regexp(value)

is.set(value)

is.string(value)

is.symbol(value)

is.undefined(value)

is.weakMap(value)

is.weakSet(value)

Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page.

Show your support

Give a ⭐️ if this project helped you!

License

Copyright © 2019 Gil Barbara <[email protected]>.
This project is MIT licensed.

FAQ

@sindresorhus/is is amazing but I needed something even smaller (and simpler). This package cover the basics and is less than 1k minified+gzipped.