# promisify-4loc

> Promisify a callback-style function in just 4 lines of code

Latest version **1.0.0** (published 2020-11-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install promisify-4loc
pnpm add promisify-4loc
yarn add promisify-4loc
bun add promisify-4loc
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2020-11-18 |
| First published | 2020-11-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=6 |
| Dependencies | 0 |
| Unpacked size | 3.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 57 |
| Author | Andre Staltz |
| Maintainers | staltz |
| Keywords | chain, pipe, functions, functional, compose |

## Links

- npm: https://www.npmjs.com/package/promisify-4loc
- Repository: https://github.com/staltz/promisify-4loc
- Homepage: https://github.com/staltz/promisify-4loc#readme
- Issues: https://github.com/staltz/promisify-4loc/issues
- npm.io page: https://npm.io/package/promisify-4loc

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2020-11-18

## README

# promisify-4loc

Convert a Node.js-style callback API `(err, val) => void` to a Promise. Much like [pify](https://github.com/sindresorhus/pify), but implemented in just 4 lines of code, with only the core functionality provided.

```
npm install --save promisify-4loc
```

**Before:**

```js
const fs = require('fs')

function main() {
  fs.readFile('./test.js', (err, val) => {
    if (err) console.error(err)
    else console.log(val)
  })
}

main()
```

**After:**

```js
const fs = require('fs')
const pify = require('promisify-4loc')

async function main() {
  try {
    const val = await pify(fs.readFile)('./test.js')
    console.log(val)
  } catch (err) {
    console.error(err)
  }
}

main()
```

## Source code

It's called "4loc" because the implementation is only 4 lines of code:

```js
module.exports = (fn) => (...args) =>
  new Promise((resolve, reject) => {
    fn(...args, (err, val) => err ? reject(err) : resolve(val))
  })
```

That's 144 bytes.

## License

[MIT](LICENSE)

---
_Source: https://npm.io/package/promisify-4loc · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
