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 🙏

© 2024 – Pkg Stats / Ryan Hefner

make-sure

v1.1.2

Published

Fluently validate that your function arguments are what you expect.

Downloads

15

Readme

Make Sure Build Status

Fluently validate that your function arguments are what you expect.

Install

npm install make-sure

Example

import makeSure from 'make-sure';

const myFunc = (a, b) => {
  makeSure(a).is.a.String.eq('foo');
  if (makeSure.isBoolean(b) === false)
    console.log('uhoh, b is NOT a Boolean');

  // a strictly equals 'foo' and you've been warned if b isn't a Boolean

  console.log('Yay!');
};

myFunc('foo', false);

Type Validation

If you use the chained approach, make-sure will throw when a validation fails. Alternatively, you can call the assertion directly and it will return true or false.

Array / isArray()

makeSure([ 1, 2, 3 ]).is.an.Array; // doesn't throw
makeSure('foo').is.an.Array; // throws
makeSure.isArray([ 1, 2, 3 ]); // returns true
makeSure.isArray('foo'); // returns false

Boolean / isBoolean()

makeSure(true).is.a.Boolean; // doesn't throw
makeSure('true').is.a.Boolean; // throws
makeSure.isBoolean(true); // returns true
makeSure.isBoolean('true'); // returns false

Date / isDate()

makeSure(new Date()).is.a.Date; // doesn't throw
makeSure(1).is.a.Date; // throws
makeSure.isDate(new Date()); // returns true
makeSure.isDate(1); // returns false

Error / isError()

makeSure(new Error('uhoh!')).is.an.Error; // doesn't throw
makeSure('uhoh').is.an.Error; // throws
makeSure.isError(new Error('uhoh!')); // returns true
makeSure.isError('uhoh'); // returns false

Falsy / isFalsy()

makeSure(0).is.Falsy; // doesn't throw
makeSure('').is.Falsy; // doesn't throw
makeSure(false).is.Falsy; // doesn't throw
makeSure(null).is.Falsy; // doesn't throw
makeSure(undefined).is.Falsy; // doesn't throw
makeSure(true).is.Falsy; // throws
makeSure.isFalsy(''); // returns true
makeSure.isFalsy('foo'); // returns false

Function / isFunction()

makeSure(() => {}).is.a.Function; // doesn't throw
makeSure(function () {}).is.a.Function; // doesn't throw
makeSure('foo').is.a.Function; // throws
makeSure.isFunction(() => {}); // returns true
makeSure.isFunction('foo'); // returns false

Generator / isGenerator()

makeSure(function* () {}).is.a.Generator; // doesn't throw
makeSure(() => {}).is.a.Generator; // throws
makeSure.isGenerator(function* () {}); // returns true
makeSure.isGenerator(() => {}); // returns false

Map / isMap()

makeSure(new Map()).is.a.Map; // doesn't throw
makeSure(new Set()).is.a.Map; // throws
makeSure.isMap(new Map()); // returns true
makeSure.isMap(new Set()); // returns false

Null / isNull()

makeSure(null).is.Null; // doesn't throw
makeSure(undefined).is.Null; // throws
makeSure.isNull(null); // returns true
makeSure.isNull(0); // returns false

Number / isNumber()

makeSure(1).is.a.Number; // doesn't throw
makeSure('1').is.a.Number; // throws;
makeSure.isNumber(1); // returns true
makeSure.isNumber('1'); // returns false

Object / isObject()

makeSure({ a: true }).is.an.Object; // doesn't throw
makeSure('{"a":true}').is.an.Object; // throws
makeSure.isObject({ a: true }); // returns true
makeSure.isObject('{"a":true}'); // returns false

Promise / isPromise()

makeSure(new Promise().resolve()).is.a.Promise; // doesn't throw
makeSure(() => {}).is.a.Promise; // throws
makeSure.isPromise(new Promise().resolve()); // returns true
makeSure.isPromise(() => {}); // returns false

RegExp / isRegExp()

makeSure(/a/).is.a.RegExp; // doesn't throw
makeSure('/a/').is.a.RegExp; // throws
makeSure.isRegExp(/a/); // returns true
makeSure.isRegExp('/a/'); // returns false

Set / isSet()

makeSure(new Set()).is.a.Set; // doesn't throw
makeSure(new Map()).is.a.Set; // throws
makeSure.isSet(new Set()); // returns true
makeSure.isSet(new Map()); // returns false

String / isString()

makeSure('a').is.a.String; // doesn't throw
makeSure('1').is.a.String; // doesn't throw
makeSure(0).is.a.String; // throws
makeSure.isString('1'); // returns true
makeSure.isString(1); // returns false

Symbol / isSymbol()

makeSure(Symbol()).is.a.Symbol; // doesn't throw
makeSure('foo').is.a.Symbol; // throws
makeSure.isSymbol(Symbol()); // returns true
makeSure.isSymbol('foo'); // returns false

Truthy / isTruthy();

makeSure(1).is.Truthy; // doesn't throw
makeSure('1').is.Truthy; // doesn't throw
makeSure(true).is.Truthy; // doesn't throw
makeSure({a:1}).is.Truthy; // doesn't throw
makeSure([1]).is.Truthy; // doesn't throw
makeSure(false).is.Truthy; // throws
makeSure.isTruthy(1); // returns true
makeSure.isTruthy(''); // returns false

Undefined / isUndefined()

makeSure(undefined).is.Undefined; // doesn't throw
makeSure(null).is.Undefined; // throws
makeSure.isUndefined(undefined); // returns true
makeSure.isUndefined(null); // returns false

WeakMap / isWeakMap()

makeSure(new WeakMap()).is.a.WeakMap; // doesn't throw
makeSure(new Set()).is.a.WeakMap; // throws
makeSure.isWeakMap(new WeakMap()); // returns true
makeSure.isWeakMap(new Set()); // returns false

WeakSet / isWeakSet()

makeSure(new WeakSet()).is.a.WeakSet; // doesn't throw
makeSure(new Map()).is.a.WeakSet; // throws
makeSure.isWeakSet(new WeakSet()); // returns true
makeSure.isWeakSet(new Map()); // returns false

Stream / isStream()

const stream = new Transform({ transform() => {} });

makeSure(stream).is.a.Stream; // doesn't throw
makeSure('').is.a.Stream; // throws
makeSure.isStream(stream); // returns true
makeSure.isStream(''); // returns false

Tests!

Currently, there are over 700 tests!

npm test

Inspiration

should lodash is

Versions

  • 1.1.2 - Correctly fixing is/Object.js
  • 1.1.1 - Fix is/Object.js
  • 1.1.0 - Added isStream() and makeSure().Stream
  • 1.0.0 - Initial release