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

denote

v1.2.0

Published

Minimalistic Promises/A+ compliant JavaScript promise implementation

Downloads

8

Readme

Denote

npm version devDependency Status

API Documentation

A JavaScript promise library - because we don't have enough of those already.

Installation

npm install denote

Example Usage

var denote = require('denote');

Using deferred promise creation

function verifyEven(n) {
  var promise = denote();
  setTimeout(function() {
    if(n % 2 === 0) {
      promise.resolve('The number ' + n + ' is even.');
    } else {
      promise.reject(new Error('The number ' + n + ' is odd.'));
    }
  }, 1000);
  return promise;
}

verifyEven(14).then(function(value) {
  console.log('fulfilled', value);  // logs 'fulfilled The number 14 is even.' after 1s
  return verifyEven(27);
}, function(reason) {
  console.log('rejected', reason);  // does not run
}).catch(function(reason) {
  console.log('rejected', reason);  // logs 'rejected [Error: The number 27 is odd.]' after 2s
});

Using an executor function

denote(function(resolve, reject) {
  setTimeout(resolve, 1000, 'llamas');
}).then(function(value) {
  console.log('The value is', value); // logs 'The value is llamas' after 1s
  return denote(function(resolve, reject) {
    setTimeout(reject, 1000, new Error('There are no llamas'))
  });
}).catch(function(reason) {
  console.log('The reason is', reason); // logs 'The reaons is [Error: There are no llamas]' after 2s
});

Creating immediately fulfilled or rejected promises

denote.resolve('Such a good promise').then(function(value) {
  console.log('Here it is:', value);  // logs 'Here it is: Such a good promise' with no delay
  return denote.reject(new Error('Such a bad promise'));
}).catch(function(reason) {
  console.log('Here it is not:', reason); // logs: 'Here it is not: [Error: Such a bad promise]' with no delay
});

Using denote.all to handle many promises

var promises = [denote.resolve('hello'), verifyEven(22), 'howdy!'];

denote.all(promises).then(function(values) {
  console.log('The results are:', values); // logs ['hello', 'The number 22 is even.', 'howdy!'] once all promises are resolved
}, function(reason) {
  console.log('One of the promises rejected:', reason); // called as soon as one of the promises is rejected
});

Using denote.race to handle the first promise to complete

var morePromises = [denote.resolve('hey'), verifyEven(17), 'tra la la'];

denote.race(morePromises).then(function(winner) {
  console.log('I do declare:', winner); // logs 'I do declare: tra la la' since it fulfills before the other two complete
}, function(reason) {
  console.log('The winner rejected!', reason); // called if the first completed promise is rejected
});

API

View the online documentation for details.

denote = require('denote')

  • denote([executor]) - returns a new Denote promise instance
  • denote.resolve(value)
  • denote.reject(reason)
  • denote.all(list)
  • denote.race(list)

Denote.prototype

  • Denote.prototype.then(onFulfilled, onRejected)
  • Denote.prototype.catch(onRejected)
  • Denote.prototype.resolve(value)
  • Denote.prototype.reject(reason)

Contributing

git clone https://github.com/msrose/denote.git
cd denote
npm install

To run the project's own test suite: npm test

To run the Promises/A+ compliance tests: npm run test:aplus

Before submitting a pull request, make sure that:

  • you've written tests for any new features,
  • the code conforms to the eslint configuration for this project,
  • and that all the tests pass
npm run lint && npm run test:all

Making a Release

npm run lint
npm run test:all
git checkout develop
npm version major|minor|patch
git push origin develop
git checkout gh-pages
git merge develop
jsdoc -c jsdoc.conf.json -R README.md -P package.json
git add docs
git commit -m "Update docs"
git push origin gh-pages
git checkout master
git merge develop
git push origin --tags master
npm publish

License

MIT