Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

promised-until

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promised-until

Transforms a (promised) value until it satisfies the given predicate.

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

promised-until

Transforms a (promised) value until it satisfies the given predicate. Full support for Promises.

Usage

until(predicate, transform)(value) -> Promise(newValue)

Calling until(predicate, transform) returns a function that takes one parameter. Calling that function with value returns a promise, which resolves if predicate(value) is truthy. While predicate(value) is falsey, the value is transformed with transform(value) until predicate(value) returns a truthy value.

predicate(x) -> true|false or Promise(true|false)

A function that accepts one parameter x and returns a truthy or falsey value, or Promise of such a value.

transform(x) -> y or Promise(y)

A function that accepts one parameter x and transforms it into a new value y, or Promise of such a value.

value

The value, or Promise of a value to be transformed.

Example

Non-promised

const until = require('promised-until')

until(
  (c) => c >= 5,
  (c) => c + 1
)(0)
  .then(result => console.log(result)) // logs '5' to the console

Promised

const until = require('promised-until')

until(
  (c) => Promise.resolve(c >= 5),
  (c) => Promise.resolve(c + 1)
)(Promise.resolve(0))
  .then(result => console.log(result)) // logs '5' to the console

Real-world

until(
  (pageToken) => !pageToken
  (pageToken) => {
    return fetchPage(pageToken)
      .then(page => {
        socket.send(page)
        return page.nextPageToken
      })
)(getFirstPageToken())
	.then(() => console.log('done'))

Supported versions

The module is CI-tested with Node versions 0.10, 4.5 (LTS) and the latest (currently 6.5).

Promise implementation

Uses any-promise which defaults to the native Promise implementation. If you want to use a different Promise library, make sure to register it with any-promise. For example require('any-promise/register/bluebird') for bluebird.

For Node versions <= 0.12 a 3rd-party Promise library is required. More details here.

Keywords

FAQs

Package last updated on 20 Sep 2016

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc