update tsconfig

This commit is contained in:
Philipp Kunz 2024-04-14 18:10:00 +02:00
parent 3a5ea9aa13
commit 85706e8a4e
4 changed files with 168 additions and 87 deletions

View File

@ -9,12 +9,22 @@
"githost": "code.foss.global",
"gitscope": "push.rocks",
"gitrepo": "smartpromise",
"description": "simple promises and Deferred constructs",
"description": "A library for simple promises and Deferred constructs with TypeScript support.",
"npmPackagename": "@push.rocks/smartpromise",
"license": "MIT"
"license": "MIT",
"keywords": [
"promise",
"deferred",
"async",
"promisify",
"cumulative deferred",
"map",
"timeout",
"typescript"
]
}
},
"tsdocs": {
"tsdoc": {
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
}
}

View File

@ -2,7 +2,7 @@
"name": "@push.rocks/smartpromise",
"private": false,
"version": "4.0.3",
"description": "simple promises and Deferred constructs",
"description": "A library for simple promises and Deferred constructs with TypeScript support.",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"scripts": {
@ -42,5 +42,15 @@
"browserslist": [
"last 1 chrome versions"
],
"type": "module"
}
"type": "module",
"keywords": [
"promise",
"deferred",
"async",
"promisify",
"cumulative deferred",
"map",
"timeout",
"typescript"
]
}

1
readme.hints.md Normal file
View File

@ -0,0 +1 @@

222
readme.md
View File

@ -1,96 +1,156 @@
# @pushrocks/smartpromise
# @push.rocks/smartpromise
simple promises and Deferred constructs
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartpromise)
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartpromise)
* [github.com (source mirror)](https://github.com/pushrocks/smartpromise)
* [docs (typedoc)](https://pushrocks.gitlab.io/smartpromise/)
## Install
## Status for master
```bash
npm install @push.rocks/smartpromise --save
```
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartpromise/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartpromise/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartpromise)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartpromise)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartpromise)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartpromise)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartpromise)](https://lossless.cloud)
This module is designed to be used with TypeScript for the best developer experience, providing type safety and IntelliSense in your IDE.
## Usage
Use TypeScript for best in class instellisense.
`@push.rocks/smartpromise` simplifies the use of promises and deferred constructs in TypeScript, offering a set of utility functions that extend native Promise capabilities in specific scenarios. This guide walks you through its functionalities, showcasing how to leverage this library in a TypeScript project.
> Note: smartq uses native ES6 promises
> smartq does not repeat any native functions, so for things like .all() simply use Promise.all()
### Setting Up Your Project
```typescript
import * as q from '@pushrocks/smartpromise';
Ensure your TypeScript project is configured to support ES Module syntax. In your `tsconfig.json`, you should have:
// Deferred
// -----------------------------------------------
let myAsyncFunction = (): Promise<string> => {
let done = q.defer<string>(); // returns your typical Deferred object
setTimeout(() => {
done.resolve('hi'); // will throw type error for other types than string as argument ;)
}, 6000);
console.log(done.status); // logs "pending";
done.promise.then(() => {
console.log(done.status); // logs "fullfilled"
console.log(done.duration); // logs the milliseconds between instantiation and fullfillment
});
return done.promise;
};
let myAsyncFunction2 = async () => {
let aString = await myAsyncFunction();
console.log(aString); // will log 'hi' to console
};
myAsyncFunction2();
// Resolved and Rejected promises
// ------------------------------------------------
q.resolvedPromise(`I'll get logged to console soon`).then((x) => {
console.log(x);
});
q.rejectedPromise(`what a lovely error message`)
.then(
() => {
console.log('This never makes it to console');
} /*, alternatively put a reject function here */
)
.catch((err) => {
console.log(err);
});
// Promisify (typed)
// ------------------------------------------------
let myCallbackedFunction = (someString: string, someNumber: number, cb) => {
cb(null, someString);
};
let myPromisedFunction = q.promisify(myCallbackFunction);
myPromisedFunction('helloThere', 2).then((x) => {
console.log(x); // will log 'helloThere' to console
});
```json
{
"compilerOptions": {
"module": "ESNext",
"target": "ESNext",
"moduleResolution": "node"
}
}
```
## Contribution
### Basic Usage
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
#### Creating a Deferred
For further information read the linked docs at the top of this readme.
Deferred objects in `@push.rocks/smartpromise` give you more control over your promises, allowing for manual resolution or rejection beyond the initial executor function.
## Legal
> MIT licensed | **&copy;** [Task Venture Capital GmbH](https://task.vc)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
```typescript
import { defer } from '@push.rocks/smartpromise';
async function exampleDeferred(): Promise<string> {
const myDeferred = defer<string>();
// Simulate an async task
setTimeout(() => {
myDeferred.resolve('Hello, Deferred!');
}, 1000);
return myDeferred.promise;
}
exampleDeferred().then((result) => console.log(result));
```
#### Cumulative Deferred
For scenarios where multiple asynchronous tasks need to be tracked collectively before proceeding, use `CumulativeDeferred`. It waits for all added promises to resolve.
```typescript
import { cumulativeDefer } from '@push.rocks/smartpromise';
async function exampleCumulativeDeferred() {
const myCumulativeDeferred = cumulativeDefer();
for (let i = 0; i < 5; i++) {
myCumulativeDeferred.addPromise(new Promise((resolve) => setTimeout(resolve, 1000 * i)));
}
await myCumulativeDeferred.promise;
console.log('All tasks completed!');
}
exampleCumulativeDeferred();
```
#### Utilizing Resolved and Rejected Promises
Quickly create already resolved or rejected promises for testing or initialization purposes.
```typescript
import { resolvedPromise, rejectedPromise } from '@push.rocks/smartpromise';
resolvedPromise('immediately resolved').then(console.log);
rejectedPromise('immediately rejected').catch(console.error);
```
### Advanced Use Cases
#### Promisify Callback Functions
`@push.rocks/smartpromise` does not directly provide a `promisify` function like Node.js util module, but you can easily integrate existing functions or use third-party libraries to convert callback-based functions into promises.
#### Handling Timeouts and Continuations
Managing timeouts or long-running promises gets easier with helper functions.
```typescript
import { timeoutWrap, timeoutAndContinue } from '@push.rocks/smartpromise';
async function exampleTimeout() {
const myPromise = new Promise((resolve) => setTimeout(() => resolve('Done!'), 2000));
// Will reject if the promise does not resolve within 1 second
try {
const result = await timeoutWrap(myPromise, 1000);
console.log(result);
} catch (error) {
console.error('Promise timed out');
}
// Continues after 1 second, regardless of whether the promise has resolved
const result = await timeoutAndContinue(myPromise, 1000);
console.log(result); // May log `null` if the original promise did not resolve in time
}
exampleTimeout();
```
#### Map and Reduce Asynchronous Functions
Suppose you have a collection of items that you need to process asynchronously. You can use the `map` function to apply an asynchronous function to each item in the array and wait for all the promises to resolve.
```typescript
import { map } from '@push.rocks/smartpromise';
async function processData(items: string[]): Promise<string[]> {
return map(items, async (item) => {
// Simulate an async operation
await new Promise((resolve) => setTimeout(resolve, 100));
return item.toUpperCase();
});
}
processData(['hello', 'world']).then(console.log);
```
### Conclusion
`@push.rocks/smartpromise` offers a refined and accessible approach to handling promises and asynchronous operations in TypeScript. Whether you're dealing with individual promises, a group of asynchronous tasks, or integrating callback-based APIs into your promise flows, this library provides the necessary tools to make your code more readable and easier to manage. With straightforward utility functions and TypeScript support, it enhances the native Promise API, making it an essential tool for modern TypeScript development.
## License and Legal Information
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
### Trademarks
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
### Company Information
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.