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

frappuccino

v1.0.0

Published

Promise library with coffee, ice and sugar!

Downloads

8

Readme

frappuccino

Promise library with coffee, ice and sugar!

You know when you order a Frappuccino on Starbucks, and sometimes it comes with more ice than you want, and other times it comes very tasty?

Yeah, I know what you're thinking, they are just like JavaScript Promises!

They can either go right, or go wrong.

# right
new Promise (resolve, reject) ->
  resolve 'tasty frappuccino'

# wrong
new Promise (resolve, reject) ->
  reject 'basically ice but more expensive'

So I wanted to understand how JavaScript Promises work, and also I wanted to drink something refreshing. That's how frappuccino came to live!

How to install and use it

To use the library, just use:

npm install --save frappuccino

And import it on your code:

Promise = require 'frappuccino'

You can do it on JavaScript too :wink:

const Promise = require('frappuccino')

API

new Promise(resolver)

Creates a new Promise object that expects a callback which receives two arguments, the resolve and reject functions.

A Promise has three possible states, they are: PENDING, FULFILLED and REJECTED.

The moment a new Promise is created, it will be on the PENDING state, waiting for one of the two callbacks to be called.

Once one of them is called, the Promise transitions to one of the other two states.

Example:

promise = new Promise (resolve, reject) ->
  resolve 'chocolate frappuccino'

To actually observe the value passed to one of the callbacks resolve or reject, you will need to call the .then method.

.then(onFulfill, onReject)

This method makes it possible to observe the value passed to one of the callbacks of the Promise constructor (resolve or reject).

promise = new Promise (resolve, reject) ->
  resolve 'chocolate frappuccino'

promise.then (value) -> 'wow, I\'ve got a ' + value

The onFulfilled callback will be called if the Promise has transitioned to the FULFILLED state.

The onRejected callback will be called if the Promise has transitioned to the REJECTED state.

A cool thing about the .then method, is that you can chain it.

promise = new Promise (resolve, reject) ->
  resolve 'chocolate frappuccino'

promise.then (value) -> 'wow, I\'ve got a ' + value
  .then (frappuccinoMessage) -> console.log 'nice message: ' + frappuccinoMessage

This is possible because the .then method always returns a new Promise with the input of the last one.

Errors

If it happens that one of your callbacks throws an error, the new Promise generated by .then will be in the REJECTED state.

promise = new Promise (resolve, reject) ->
  resolve 'chocolate frappuccino'

promise.then (value) -> throw new Error 'oopsy'
  .then null, (reason) -> console.error 'here is the reason:' + reason

It can happen on the constructor too, either with reject or with the throw itself.

promise = new Promise (resolve, reject) ->
  reject 'bad things happen'

# or

promise = new Promise (resolve, reject) ->
  throw new Error 'bad things happen'

How to build the code

Since the code is in CoffeeScript, and there is no interpreter for it, as far as I know, I compile it to JavaScript so that it can be used.

To build you will need to clone the repository, install the dependencies:

npm install

And finally just run:

npm run build

The code will be on the lib folder.

How to run the tests

Clone the repository, and run:

npm install

Then you will be able to run the tests by:

npm test

How to run the linter

Clone the repository, and run:

npm install

Then you will be able to run the linter by:

npm run lint

Notes

This project is heavly inspired by this.

License

You can check out the full license here

This project is licensed under the terms of the WTFPL license. You just DO WHAT THE FUCK YOU WANT TO.