# sinless

> Adapts sync functions to expose async api and leaves async functions unchanged..

Latest version **0.1.0** (published 2013-07-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install sinless
pnpm add sinless
yarn add sinless
bun add sinless
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2013-07-08 |
| First published | 2013-07-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Thorsten Lorenz |
| Maintainers | thlorenz |
| Keywords | sync, async, callback, return, wrap, adapt, convert |

## Links

- npm: https://www.npmjs.com/package/sinless
- Repository: https://github.com/thlorenz/sinless
- Issues: https://github.com/thlorenz/sinless/issues
- npm.io page: https://npm.io/package/sinless

## Dependencies (1)

- [setimmediate](https://npm.io/package/setimmediate.md) ~1.0.1

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 0.1.0 (latest) — 2013-07-08
- 0.0.1 — 2013-07-07

## README

# sinless [![build status](https://secure.travis-ci.org/thlorenz/sinless.png)](http://travis-ci.org/thlorenz/sinless)

[![testling badge](https://ci.testling.com/thlorenz/sinless.png)](https://ci.testling.com/thlorenz/sinless)

**sinless** [ˈsɪnlɪs]
*free from sin or guilt; innocent; pure*

Adapts sync functions to expose async api and leaves async functions unchanged.

```js
var sinless = require('sinless')

function syncAdd (a, b) {
  return a + b;
}

// fn takes 3 args if it is async and has a callback 
var sinlessAdd = sinless(syncAdd, 3); 
sinlessAdd(1, 3, function (err, res) {
  if (err) return console.error('err', err);
  console.log('res', res);
})

// res: 4
```

```js
// although it makes deducing fn's asynchronousity more solid, supplying number of args is optional
// Therefore the below also works assuming that syncAdd's number of arguments is constant
var sinlessAdd = sinless(syncAdd); 
```

## Installation

    npm install sinless

## Features

- consume identical API while giving function implementers the option to return synchronously or callback asynchronously [see
  example](https://github.com/thlorenz/sinless/blob/master/examples/unified-api.js)
- **does not make sync calls async**, i.e. `fs.readFileSync` will still block

## API

### *sinlessAdd(fn, lenWithCb)*

```
/**
  * Returns an async version of a given function or the function itself if it could be determined to be async already.
  * If lenWithCb is given, the function will be wrapped if the number of its arguments are smaller than this length.
  * If lenWithCb is not given the function will be wrapped whenever it is called with more arguments than it takes. 
  *
  * @name sinless
  * @function
  * @param fn {Function} to be wrapped if it isn't async
  * @param lenWithCb {Number} [optional] number of arguments the function should have if it was async and included a callback
  * @return {Function} either the original function or a wrapped version of it
  */
```

## License

MIT

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