Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
ts-toolbelt
Advanced tools
The ts-toolbelt package provides a comprehensive set of type utilities to improve TypeScript typing and enable type transformations, checks, and more complex operations. It enhances TypeScript's static typing capabilities and helps in building more robust type-safe applications.
Object Manipulation
Merge two types into one. This is useful for combining properties from multiple objects into a single type.
{ type Merged = Merge<{name: string}, {age: number}>; // Result: {name: string, age: number} }
Type Checking
Check if two types are equivalent. This utility helps in validating type structures for consistency.
{ type check = Equals<{a: string}, {a: string, b: number}>; // Result: false }
Conditional Types
Apply conditional logic to types. This feature allows for conditional type assignments based on certain conditions.
{ type Conditional = If<true, 'Yes', 'No'>; // Result: 'Yes' }
Provides a collection of utility types for TypeScript, similar to ts-toolbelt. While utility-types focuses more on transformations and mappings, ts-toolbelt offers a broader range of type operations including type checks and advanced manipulations.
A package that includes a variety of utility types for TypeScript. Type-fest is similar to ts-toolbelt but tends to be simpler and more focused on everyday use cases, whereas ts-toolbelt provides more comprehensive and complex utilities for advanced type manipulation.
A cancelable & typed Promise for TypeScript, Node.js & the browser.
npm install @streamhive/true-promise --save
yarn add @streamhive/true-promise
Use cancel, resolve, reject & finally on your Promise, otherwise it's just like a regular Promise.
Includes babel polyfill to run your Promises without global scope pollution, it's ready-to-use.
Types for TypeScript and your IDE so you can write stuff like this & avoid development errors.
new TruePromise<string, number>((resolve, reject) => {
resolve(42000); // TS Error
reject('Oops'); // TS Error
});
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.
<script type="text/javascript" src="true-promise.web.js"></script>
<script type="text/javascript">
new TruePromise.default(function () {
alert('I <3 Promises')
});
</script>
Do you want to know more about .resolved()
, .rejected()
, ... ?
Visit Quick API Manual
Let's take a few examples through a practical. If you are not using TypeScript just remove the types.
// 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
// 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';
});
// 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() to check it's current status.
// 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() to check it's current status.
AGPL 3.0
FAQs
TypeScript's largest utility library
The npm package ts-toolbelt receives a total of 2,022,480 weekly downloads. As such, ts-toolbelt popularity was classified as popular.
We found that ts-toolbelt demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.