Socket
Socket
Sign inDemoInstall

sb-promisify

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    sb-promisify

Node module for simple promisification


Version published
Weekly downloads
6.8K
decreased by-5.4%
Maintainers
1
Install size
6.71 kB
Created
Weekly downloads
 

Changelog

Source

2.0.2

  • Remove Flow Declarations, Babel, Flow and ESLint config files from npm package

Readme

Source

Promisify

A node module to help you convert callback-style functions to promises

Installation

npm install --save sb-promisify

API

function promisifyAll(object, throwError = true): Object
function promisify(callback, throwError = true): Function

export default promisify
export { promisify, promisifyAll }

Example Usage

import fs from 'fs'
import promisify from 'sb-promisify'

const readFile = promisify(fs.readFile)

readFile('/etc/passwd', 'utf8').then(function(contents) {
  console.log(contents)
}, function() {
  console.error('Unable to read file')
})
import fs from 'fs'
import { promisifyAll } from 'sb-promisify'

const promisedFS = promisifyAll(fs)

promisedFS.readFileAsync('/etc/passwd', 'utf8').then(function(contents) {
  console.log(contents)
})
promisedFS.readFile('/etc/passwd', 'utf8', function(contents) {
  console.log(contents)
})

If you set throwError to false, here's how it would react

'use babel'

import fs from 'fs'
import promisify from 'sb-promisify'

const access = promisify(fs.access, false)
const readFile = promisify(fs.readFile, false)

readFile('/etc/passwd').then(function(contents) {
  if (contents === false) {
    console.error('Unable to read file')
  } else {
    console.log(contents.toString('utf8'))
  }
})

access('/etc/passwd').then(function(access) {
  console.log('access', access) // true or false
})

License

This module is licensed under the terms of MIT License. Check the LICENSE file for more info.

Keywords

FAQs

Last updated on 01 May 2017

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc