Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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`
- Host: GitHub
- URL: https://github.com/soenkekluth/prs
- Owner: soenkekluth
- License: mit
- Created: 2017-04-15T22:29:58.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T08:44:24.000Z (11 months ago)
- Last Synced: 2024-10-11T19:37:01.115Z (about 1 month ago)
- Topics: alias, promise
- Language: HTML
- Homepage: https://www.npmjs.com/package/prs
- Size: 119 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: license
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)