Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
hkt-toolbelt
Advanced tools
A higher-kinded-type companion to ts-toolbelt.
npm install hkt-toolbelt
import { List, Conditional } from "hkt-toolbelt/list";
// Filter a tuple to only numbers
type FilterNumbers = List.Filter<Conditional.SubtypeOf<number>>;
// A :: [1, 2, 3]
type A = $<FilterNumbers, [1, null, 2, 3, "4"]>;
This library is a companion to ts-toolbelt that provides higher-kinded-type versions of its functionality. This allows for more complex types to be constructed.
The curried nature of the functions in this library is intended to be utilized to compose types using point-free style. In this respect, API types will first take in 'operations' and then the data to be operated on.
All type functions (e.g. full Kinds) take in one parameter at a time, to support currying and point-free style.
The $
operator is used to apply a higher-kinded-type function to a type. It is equivalent to the F<A>
syntax in TypeScript.
The Cast
type is used to cast a type to another type. It is equivalent to the A as B
syntax in TypeScript.
The And
type takes in a boolean and returns a function that takes in another boolean and returns the result of the two booleans being &&
'd together.
The Not
type takes in a boolean and returns the opposite boolean.
The Equals
type is used to check if a type is equal to another type. It is equivalent to the A extends B ? (B extends A ? true : false) : false
syntax in TypeScript.
Equals
returns a higher-kinded-type function that takes a type and returns a boolean.
The SubtypeOf
type is used to check if a type is a subtype of another type. It is equivalent to the A extends B ? true : false
syntax in TypeScript.
SubtypeOf
returns a higher-kinded-type function that takes a type and returns a boolean.
The Function
type is a supertype of all functions, i.e. all functions are a subtype of Function
.
The Constant
type takes in a type and returns a function that takes in any type and returns the original type.
The Identity
type takes in a type and returns the same type, on the higher-kinded-type level.
The Kind
type denotes a type function that may be applied to a type using $
.
The Kind type can optionally be provided a function type to increase the specificity of its internal parameter and return types.
The Composable
type checks whether a tuple of kinds are composable. A tuple of kinds is composable if the output of kind N is a subtype of the input of kind N-1.
The Compose
type takes in a tuple of type functions, and composes them into one type function.
Compose
checks that the tuple of kinds is composable, and returns a higher-kinded-type function that takes in a type and returns the result of the composition.
The _
type represents the 'placeholder variable' used in type functions before application.
The Map
function takes in a type function, and returns a higher kinded type that takes in a tuple type. It applies the given type function over every element in the tuple.
The Find
function takes in a type function, then a tuple, and returns the first tuple element for which the finder function returns true
. If no such element exists, Find
returns never
.
The Filter
function takes in a type function, and a tuple, and returns a tuple in-order of the input tuple, whereby only elements for which the filter function returns true
remain in the resultant tuple.
The Append
function takes in a type, and a tuple, and applies the type such that it is appended to the end of the provided tuple.
The Last
function takes in a tuple, and returns the last element of the tuple. In the case of tuples with variadic elements, the variadic element is properly handled, even if it's infix.
The Pair
function takes in a tuple, and returns a tuple of tuples, where each tuple is a pair of the original tuple's elements, in order. e.g. [1, 2, 3]
becomes [[1, 2], [2, 3]]
.
For variadic tuples, the variadic element is handled via introducing unions to represent the possible combinations of variadic pair elements.
The StartsWith
function takes in a string literal and returns whether or not it starts with the given prefix, returning true
or false
as appropriate.
All strings start with string
, so StartsWith<string>
will return true for all subsequent string types.
However, string
starts with no particular prefix, so $<StartsWith<"f">, string>
will result in false. All strings start with the empty string, as well.
The EndsWith
function takes in a string literal and returns whether or not it ends with the given suffix, returning true
or false
as appropriate.
@see String.StartsWith
The Includes
function takes in a string literal and returns whether or not it is a substring of the given string, returning true
or false
as appropriate.
@see String.StartsWith
[0.2.0]
Kind.Compose
.FAQs
Functional and composable type utilities
The npm package hkt-toolbelt receives a total of 27 weekly downloads. As such, hkt-toolbelt popularity was classified as not popular.
We found that hkt-toolbelt demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.