Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/soenkekluth/prs

alias for `new Promise`
https://github.com/soenkekluth/prs

alias promise

Last synced: 9 days ago
JSON representation

alias for `new Promise`

Awesome Lists containing this project

README

        

[![Build Status](https://travis-ci.org/soenkekluth/prs.svg?branch=master)](https://travis-ci.org/soenkekluth/prs)

# prs

alias for `new Promise`

## Install

$ npm install --save prs
# or
$ yarn add prs

## API

#### Table of Contents

- [prs](#prs)
- [compose](#compose)
- [resolve](#resolve)
- [reject](#reject)
- [all](#all)

### prs

returns a new Promise

**Parameters**

- `resolver`
- `null` **[function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** (resolve, [reject]) => ..

**Examples**

```javascript
prs(resolve => {
load(url, resolve);
}).then(...)
```

### compose

creates a Promise of a none-promise function
you can also use:
`promisify() prsfy()` and `prs.fy()` or `prs.ensure()` or `prs.compose()`

**Parameters**

- `fn` **[function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)**

**Examples**

```javascript
const fn = value => value;
const promise = prs.compose(fn);
const value = await promise('check');
```

### resolve

returns Promise.resolve
you can also use:
`res()` and `prs.res() prs.resolve`

**Parameters**

- `null` **any** \*

### reject

returns Promise.reject
you can also use:
`rej()` and `prs.rej()` `prs.reject()`

**Parameters**

- `null` **any** \*

### all

returns Promise.all

**Parameters**

- `null` **any** \*

## Usage

```js
const prs = require('prs');

const resolver = (resolve, reject) => {
setTimeout(()=>{
resolve('foo');
}, 1000);
};

// Alias for new Promise
prs(resolver)
.then((val) => {
console.log(val);
// => foo
});

// await
async function(){
const value = await prs(resolver)
}

// Alias for Promise.resolve
prs.resolve()
.then()...

const value = await prs.resolve('check');

// or
prs.res()
.then()...

// Alias for Promise.all
prs.all([prs,prs...])

// compose
const func = value => value;
const promise = prs.compose(func);
const value = await promise('check');
t.is(value, 'check');
```

## License

MIT © [Sönke Kluth](https://soenkekluth.com)