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

relike-value

v1.0.0

Published

Create promise from sync, async, string, number, array and so on. Handle completion (results) and errors gracefully! Built on top of `relike`, used by `redolent` to build robust (hybrid) APIs.

Downloads

23

Readme

relike-value npmjs.com The MIT License

Create promise from sync, async, string, number, array and so on. Handle completion (results) and errors gracefully! Built on top of relike, used by redolent to build robust (hybrid) APIs.

code climate standard code style travis build status coverage status dependency status

What's the difference?

What's the difference between me and you?!
–– Dr Dre feat. Eminem & X-Zibit - Whats the Difference, https://youtu.be/8y5MjguI-pM

What's the difference between this module, relike and redolent?
–– Simply, almost nothing.

  1. This one accepts everything and returns Promise. But it is little bit tricky:
  • if you pass only one non-function argument to it, it will pass it to promise
  • if you pass more that one arguments to it, it will create array from them and pass it to promise
  • if you pass function as first argument, next arguments will be passed to this function
  1. relike one just accept sync or async function which is executed immediately with next arguments, after that it returns Promise.
  2. redolent accepts everything and returns function, which when is executed it returns Promise. Above things applies here, because it is on top of relike-value.

Notice: Both relike and relike-value direcly executes first argument (if function) and returns Promise.

Install

npm i relike-value --save

Usage

For more use-cases see the tests

const relikeValue = require('relike-value')

relikeValue

Will try to promisify fn with native Promise, otherwise will use Bluebird or you can give different promise module to relikeValue.promise, for example pinkie.

  • [args...] {Anything} any number of any type from string to function (number, array, boolean, etc)
  • return {Promise} promise

Example

const fs = require('fs')
const request = require('request')
const relikeValue = require('relike-value')

relikeValue(fs.readFile, 'package.json', 'utf-8').then(data => {
  console.log(JSON.parse(data).name)
})

// promisify sync function
relikeValue(fs.readFileSync, 'package.json', 'utf-8')
.then(JSON.parse)
.then(res => {
  console.log(res.name)
})

// handles multiple arguments by default (comes from `request`)
relikeValue(request, 'http://www.tunnckocore.tk/').then(result => {
  const [httpResponse, body] = result
})

relikeValue.promise

Static property on which you can pass custom Promise module to use, e.g. Q constructor.

Example

const fs = require('fs')
const relikeValue = require('relike-value')

// `q` promise will be used if not native promise available
// but only in node <= 0.11.12
relikeValue.promise = require('q')
relikeValue(fs.readFile, 'package.json', 'utf-8').then(data => {
  console.log(JSON.parse(data).name)
})

Access Promise constructor

You can access the used Promise constructor for promisify-ing from promise.Prome

Example

const fs = require('fs')
const relikeValue = require('relike-value')

// use `pinkie` promise if not native promise available
// but only in node <= 0.11.12
relikeValue.promise = require('pinkie')

const promise = relikeValue(fs.readFile, 'package.json', 'utf8')

console.log(promise.Prome)
//=> will be `pinkie` promise constructor (only in node <= 0.11.12)
console.log(promise.Prome.___customPromise) //=> true (only on node <= 0.11.12)
console.log(promise.___customPromise) //=> true (only on node <= 0.11.12)

promise
  .then(JSON.parse)
  .then(data => {
    console.log(data.name) //=> `relike-value`
  })

Promise from any type

Any number of any type of arguments can be given - String, Stream, Null, Boolean, Number and etc.

Example

const relikeValue = require('relike-value')

var promise = relikeValue('foo bar baz').then(function (str) {
  console.log(str) // => 'foo bar baz'
}, console.error)

relikeValue(false).then(function (bool) {
  console.log(bool) // => false

  return relikeValue(null).then(function (empty) {
  console.log(empty) // => null
  })
}, console.error)

relikeValue('foo', 123, [1, 2], {a: 'b'}).then(function (arr) {
  console.log(arr) // => ['foo', 123, [1, 2], {a: 'b'}]
}, console.error)

Related

  • always-done: Handles completion and errors of anything!
  • always-promise: Promisify, basically, everything. Generator function, callback-style or synchronous function; sync function that returns child process, stream or observable; directly passed promise, stream or child process.
  • always-thunk: Thunkify, basically, everything. Generator function, callback-style or synchronous function; sync function that returns child process, stream or observable; directly passed promise, stream or child process.
  • always-generator: Generatorify, basically, everything. Async, callback-style or synchronous function; sync function that returns child process, stream or observable; directly passed promise, stream or child process.
  • native-or-another: Always will expose native Promise if available, otherwise Bluebird but only if you don't give another promise module like q or promise or what you want.
  • native-promise: Get native Promise or falsey value if not available.
  • relike: Simple promisify a callback-style function with sane defaults. Support promisify-ing sync functions.
  • relike-all: Promisify all functions in an object, using relike.

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.

Charlike Make Reagent new message to charlike freenode #charlike

tunnckocore.tk keybase tunnckocore tunnckoCore npm tunnckoCore twitter tunnckoCore github