@topl/tack
TypeScript icon, indicating that this package has built-in type declarations

1.0.8 • Public • Published

📌 tack

tack is just a place to stick things that are needed cross-project. It is not meant to be a big/professional library like lodash. Instead, it contains useful utilities and algorithms we commonly need with boilerplate so we don't need to waste a bunch of time configuring rollup for each little module. Instead, the modules all house together in this package, and thanks to treeshaking, we can still load only what we need.

api

assert

declare function assert(condition: any, message?: string): void;

Throw an assertion error with the given message if the condition is not true.

findLast

declare function findLast<T>(predicate: (it: T, index: number) => boolean, array: any[]): T;

Find the last item of an array that matches the predicate.

head

declare function head<T>(it: Iterable<T>): T;

Return the first item of an iterable.

partition

declare function partition<T>(predicate: (item: T, index: number) => boolean, array: T[]): [T[], T[]];

Split an array into two arrays, ones that respectively contain all the items matching and not matching the predicate.

TopologicalSort

declare class TopologicalSort<T> {
    nodes: Set<T>;
    private edges;
    addEdge(source: T, target: T): void;
    sort(): T[];
    visit(node: T, list: T[], permanent: Set<T>, temporary: Set<T>): void;
}

getAt

Get the object at the path

export declare function getAt<T, F = T>(path: string[], target: T): F;

license

See LICENSE

Readme

Keywords

none

Package Sidebar

Install

npm i @topl/tack

Weekly Downloads

2

Version

1.0.8

License

MIT

Unpacked Size

23.6 kB

Total Files

9

Last publish

Collaborators

  • stablebot