Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chjj/n
pretty control for js
https://github.com/chjj/n
Last synced: 9 days ago
JSON representation
pretty control for js
- Host: GitHub
- URL: https://github.com/chjj/n
- Owner: chjj
- License: mit
- Created: 2011-04-11T13:01:14.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2011-08-05T00:40:51.000Z (over 13 years ago)
- Last Synced: 2024-10-20T01:14:51.732Z (24 days ago)
- Language: JavaScript
- Homepage:
- Size: 97.7 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# $N
$N is my attempt at making something similar to Step, but with less indentation
and slightly different syntax. $N is very light-weight and small, only a few
lines, so it is copy & pastable if need be.## Usage
``` js
var $N = require('N')
, fs = require('fs');$N(function(next) {
fs.readFile('./log.txt', 'utf-8', next);
})
.N(function(next, err, txt) {
if (err) {
console.log(err.message);
} else {
console.log('Some text: ' + txt);
}
next.N(
// you can even push
// more functions onto the stack!
function(next) {
console.log('world');
next();
},
// you can pass multiple args if
// you want to use it like Step
function() {
console.log('how are you?');
}
)('hello');
})
.N(function(next, hello) {
console.log(hello);
next();
})();
```### Outputs:
Some text: [whatever text]
hello
world
how are you?## More Features
There's also an "N-features.js" file, which is something I'm experimenting with.
It includes parallel calls and consistent arguments with error handling, e.g.
(err, data). I'm unsure whether I want to include these features, I like
keeping things simple.``` js
$N(function() {
fs.readFile('./log1.txt', 'utf-8', this);
})
.N(function(err, text) {
if (err) {
console.log(err);
} else {
console.log('Some text: ' + text);
}
this.N(
// you can even push
// more functions onto the stack!
function(err, results) {
console.log('world');
this(results);
},
// you can pass multiple args if
// you want to use it like Step
function(err, results) {
console.log('how are you?');
console.log('...even more text:', results);
}
)('hello');
})
.N(function(err, hello) {
if (err) console.log('oh no, an error:', err)
console.log(hello);
fs.readFile('./log2.txt', 'utf-8', this.para);
fs.readFile('./log3.txt', 'utf-8', this.para);
})();
```## License
See LICENSE for more info (MIT).