New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

golangify

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

golangify

Golang like error handling for async/await

latest
Source
npmnpm
Version
0.3.1
Version published
Weekly downloads
614
-11.91%
Maintainers
1
Weekly downloads
 
Created
Source

golangify

Build Status tested with jest styled with prettier All Contributors

Golang like error handling for async/await

Install

$ yarn add golangify

Usage

const go = require('golangify')

const main = async () => {
  // Async
  {
    const success = x => Promise.resolve(x + x)
    const failure = () => Promise.reject(new Error('err'))

    console.log(await go(success)(1))
    // => [ 2, null ]

    const [result, err] = await go(failure)()
    if (err !== null) {
      console.log(err.message)
      // => err
    }
    console.log(result)
    // => null
  }

  // Sync
  {
    const successSync = x => x + x
    const failureSync = () => new Error('err')

    console.log(go(successSync)(1))
    // => [ 2, null ]
    const [result, err] = go(failureSync)()
    if (err !== null) {
      console.log(err.message)
      // => err
    }
    console.log(result)
    // => null
  }
}

main()

API

golangify(func)

func

Type: function

Success

return [result, null]

Failure

return [null, err]

Contributors

Thanks goes to these wonderful people (emoji key):


akameco

💻 📖 ⚠️ 🚇

This project follows the all-contributors specification. Contributions of any kind welcome!

License

MIT © akameco

Keywords

proxy

FAQs

Package last updated on 12 Jul 2019

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