# nestless

> Async callback flattening JS rewriter

Latest version **0.1.3** (published 2012-06-05) · 0 weekly downloads

## Install

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

Provides the command `nestless`.

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2012-06-05 |
| First published | 2012-01-30 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | ~0.6.2 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Lal'C Mellk Mal |
| Maintainers | lalc |

## Links

- npm: https://www.npmjs.com/package/nestless
- Repository: git@github.com:lalcmellkmal/nestless
- Homepage: https://github.com/lalcmellkmal/nestless
- npm.io page: https://npm.io/package/nestless

## Recent versions

- 0.1.3 (latest) — 2012-06-05
- 0.1.2 — 2012-02-11
- 0.1.1 — 2012-01-31
- 0.1.0 — 2012-01-31
- 0.0.2 — 2012-01-31
- 0.0.1 — 2012-01-30
- 0.0.0 — 2012-01-30

## README

# Nestless.js

Rewrites a flat synchronous-style JS variant into proper callback-y JS **preserving line numbers**.

Sample input:

```js
function cat(encoding, cb) {
    filename <- askUser("Filename? ");
    contents <- fs.readFile(filename, encoding);

    if (contents.match(/piracy/))
        throw "TAKEN DOWN";

    return contents;
}
```

becomes:

```js
function cat(encoding, cb) {
    askUser("Filename? ", function (err, filename) { if (err) return cb(err);
    fs.readFile(filename, encoding, function (err, contents) { if (err) return cb(err);

    if (contents.match(/piracy/))
        return cb("TAKEN DOWN");

    return cb(null, contents);
}); }); }
```

The transformation is opt-in per function. Every transformed function must take a last parameter called `callback` or `cb` and contain at least one `<-` binding.

After the first arrow binding, any `return` or `throw` in the same function *(not in contained functions!)* will be transformed to a callback invocation.
See the test folder for more examples.

## BONUS

Lets you use Pythonic """multi-line string literals""".
However, it's currently hacked in with a preprocessor. Don't put """ in
comments or normal string literals.

## WARNING

* Nestless is very dumb and hacky and comes without warranty.
  It only handles a certain (common) case.
  Do not use nestless-generated code for anything important without examining the transformed output.
* Loops are right out.
  Use [async.js](https://github.com/caolan/async) or [TameJS](http://tamejs.org/).
* Once you `return` a value, nestless tries to stop all execution in the function by possibly inserting more `return`s.
  Strange control flows may break this.
  I assume no responsibility if your callback never gets called or, worse, gets called multiple times.

## Meta

Install with `npm install -g nestless`. This should put nestless in your npm bin.

Many thanks to Brendan Eich and Mozilla for [Narcissus](https://github.com/mozilla/narcissus/) which parses the JavaScript and provides token boundaries for rewriting. Relevant bits of Narcissus have been patched and bundled with Nestless, and it assumes the same license.

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