🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

unless-async

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unless-async

Async unless conditional flow.

0.0.1
latest
Source
npm
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

UnlessAsync

Async unless conditional flow inspired by Ruby.

Node 6+

Why?

Because programming is fun, and implementing what you think you know shows you what you've yet to learn.

Installation

npm i -S unless-async

Usage

const unless = require('unless-async');

const foo = false;
unless(foo, () => console.log('Foo is false so I am called!'));

const bar = true;
unless(bar, () => console.log('Bar is true so I am NOT called!'));

unless(user.isAuthenticated(), () => authenticate(user))
.then(() => {
  return mail.send(user.email);
});

const isAdmin = User.find(params.userId).then(u => u.isAdmin);

return unless(isAdmin, () => {
  throw new Error('Forbidden');
})
.then(() => Message.find(params));

API

unless(
  Promise<any>|boolean condition,
  function action
) -> Promise

Creates a promise that is resolved with the given action function when false, otherwise resolves undefined.

Test

npm test

License

MIT

Keywords

conditionals

FAQs

Package last updated on 20 Jan 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts