UNPKG

1.81 kBMarkdownView Raw
1[![NPM Package](https://badge.fury.io/js/villa.svg)](https://www.npmjs.com/package/villa)
2[![Build Status](https://travis-ci.org/vilic/villa.svg)](https://travis-ci.org/vilic/villa)
3[![Coverage Status](https://coveralls.io/repos/github/vilic/villa/badge.svg?branch=master)](https://coveralls.io/github/vilic/villa?branch=master)
4
5# Villa
6
7Villa is a set of promise utilities for `async`-`await`-ready environment.
8
9Promises have been widely used in JavaScript, and there are quite a few fully
10featured promise libraries like
11[bluebird](https://github.com/petkaantonov/bluebird) and
12[Q](https://github.com/kriskowal/q). But with the growing adoption of
13`async`/`await` provided by ES-next (via transpilers like
14[TypeScript](http://www.typescriptlang.org/) and [Babel](http://babeljs.io/)),
15some cretical features provided by those libraries become less relevant.
16
17And there is another problem with third-party promise for code using
18`async`/`await`: it could be confusing having different promise instances with
19different APIs, while an `async` function always returns native promise object.
20
21While most of the promise use cases so far can be addressed using
22`async`/`await` with simple helpers, I created villa with my favorite features
23from my own promise library [ThenFail](https://github.com/vilic/thenfail).
24
25# Installation
26
27Villa is written in TypeScript and compiled with TypeScript 2.0, and works with
28both TypeScript and Babel.
29
30```sh
31npm install villa --save
32```
33
34# Example
35
36```ts
37import * as FS from 'fs';
38import { awaitable } from 'villa';
39
40async function copy(source, target) {
41 let readStream = FS.createReadStream(source);
42 let writeStream = FS.createWriteStream(target);
43 readStream.pipe(writeStream);
44 return awaitable(writeStream, 'close', [readStream]);
45}
46```
47
48# License
49
50MIT License.