Socket
Socket
Sign inDemoInstall

ts-toolbelt

Package Overview
Dependencies
Maintainers
1
Versions
916
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-toolbelt - npm Package Compare versions

Comparing version 0.0.0 to 0.0.1

.history/.gitignore_20190605161655

24

package.json
{
"name": "ts-toolbelt",
"version": "0.0.0",
"version": "0.0.1",
"license": "AGPL-3.0-only",
"author": "Pierre-Antoine Mills",
"description": "Higher type safety for TypeScript",
"keywords": [],
"keywords": [
"types",
"tools",
"safe",
"typescript"
],
"homepage": "https://github.com/pirix-gh/ts-tools",

@@ -13,3 +18,3 @@ "repository": {

},
"types": "out/types/src/_index.d.ts",
"types": "out/types/src/index.d.ts",
"scripts": {

@@ -21,11 +26,10 @@ "build:types": "tsc --emitDeclarationOnly",

"@types/ramda": "latest",
"@typescript-eslint/parser": "^1.5.0",
"@typescript-eslint/parser": "^1.9.0",
"eledoc": "^0.0.1",
"eslint": "^5.16.0",
"eslint-plugin-fp": "^2.3.0",
"eslint-plugin-react": "^7.12.4",
"ts-node": "^8.0.3",
"typedoc": "^0.15.0-0",
"typedoc-plugin-markdown": "^1.1.27",
"typedoc-thunder-theme": "0.0.2",
"typescript": "next"
"eslint-plugin-react": "^7.13.0",
"ts-node": "^8.2.0",
"typedoc": "^0.14.2",
"typescript": "^3.6.0-dev.20190607"
},

@@ -32,0 +36,0 @@ "peerDependencies": {},

@@ -1,143 +0,14 @@

# true-promise
A **cancelable** & **typed** Promise for TypeScript, Node.js & the browser.
## Installation
```sh
npm install @streamhive/true-promise --save
```
```sh
yarn add @streamhive/true-promise
```
## Features
### **Extended Promises**
Use **cancel**, **resolve**, **reject** & **finally** on your Promise, otherwise it's just like a regular Promise.
### **100% Compatible**
**Includes** babel **polyfill** to run your Promises without global scope pollution, **it's ready-to-use**.
### **Built-in Types**
**Types** for **TypeScript** and your **IDE** so you can write stuff like this & **avoid development errors**.
```ts
new TruePromise<string, number>((resolve, reject) => {
resolve(42000); // TS Error
reject('Oops'); // TS Error
});
```
## How to use
### ES7+ | TypeScript
```ts
const promise0 = new TruePromise<string, number>((resolve) => {
setTimeout(() => resolve('I <3 Promises'), 500);
});
const promise1 = promise0.then(() => "Won't execute");
promise0.cancel('I <3 Cancelling');
console.log(await promise0);
console.log(await promise1);
```
Remember to remove the types when using vanilla JavaScript.
### ES5+ | Browser
```html
<script type="text/javascript" src="true-promise.web.js"></script>
<script type="text/javascript">
new TruePromise.default(function () {
alert('I <3 Promises')
});
<script async type="text/javascript"> // Handle when image displayed in website
document.addEventListener("DOMContentLoaded", function(event) {
document.querySelectorAll('img').forEach(function(img) {
img.onerror = function(){
this.style.display='none'
}
})
})
</script>
```
## Documentation
Do you want to know more about `.resolved()`, `.rejected()`, ... ?
Visit [**Quick API Manual**](https://github.com/streamhive/true-promise/blob/master/lib/docs/classes/_truepromise_.truepromise.md#methods)
## Examples
Let's take a few examples through a practical. If you are not using TypeScript just remove the types.
### Create a basic Promise
```ts
// Create a Promise that resolves a string and errors a number
const promise0 = new TruePromise<string, number>((resolve) => {
setTimeout(() => resolve('promise0'), 500);
});
// Let's chain the Promise with then
const promise1 = promise0.then((v) => {
return 'promise1';
});
// Which returns a Promise
console.log(await promise0);
console.log(await promise1);
```
> **promise0**
> **promise1**
### Cancel your first Promise manually
```ts
// Create a Promise that resolves a string and errors a number
const promise0 = new TruePromise<string, number>((resolve) => {
setTimeout(() => resolve('promise0'), 500);
});
<center>
<img src=".github/logo.png" alt="logo" width="400" onerror="this.src='../.github/logo.png'"/>
</center>
// Let's chain the Promise with then
const promise1 = promise0.then((v) => {
return 'promise1';
});
// Let's chain the Promise with then
const promise2 = promise1.then((v) => {
return 'promise2';
});
promise0.cancel('canceled');
// Which returns a Promise
console.log(await promise0);
console.log(await promise1);
console.log(await promise2);
```
> **canceled**
> **undefined**
> **undefined**
Why did it display `undefined` ? We canceled the parent Promise so `promise1` could not yield a result (and any chained/nested Promise).
Only a pending promise can be canceled. Use .[status](https://github.com/streamhive/true-promise/blob/master/lib/docs/classes/_truepromise_.truepromise.md#status)() to check it's current status.
### Resolve or reject your Promise manually
```ts
// Create a Promise that resolves a string and errors a number
const promise0 = new TruePromise<string, number>((resolve) => {
setTimeout(() => resolve('promise0'), 500);
});
// Let's chain the Promise with then
const promise1 = promise0.then((v) => {
return 'promise1';
});
promise0.resolve('resolved');
promise1.reject('42');
// Which returns a Promise
console.log(await promise0);
console.log(await promise1);
```
> **resolved**
> **Error: Unhandled Rejection: 42**
Only a pending promise can be rejected or resolved. Use .[status](https://github.com/streamhive/true-promise/blob/master/lib/docs/classes/_truepromise_.truepromise.md#status)() to check it's current status.
## Todos
- Write more serious tests.
## License
AGPL 3.0
# [Documentation](index.html)

@@ -82,3 +82,3 @@ {

/* Stylize errors and messages using color and context (experimental). */
"removeComments": true,
"removeComments": false,
/* Do not emit comments to output. */

@@ -85,0 +85,0 @@ "resolveJsonModule": true,

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc