npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@bcg-ts/ts-toolkit

v7.0.0

Published

Helper Code For Typescript Projects (not fully documented, see code for a better understanding of available features).

Downloads

159

Readme

ts-toolkit

Helper Code For Typescript Projects (not fully documented, see code for a better understanding of available features).

Function type aliases

type Fn0<R> = () => R;
type Fn<P1, R> = (p1: P1) => R
// Fn2
// Fn3
// Fn4
// Fn5
// Fn6
// Fn7
// Fn8

type Consumer<T> = Fn<T, void>;
type Supplier<T> = Fn0<T>;
type Predicate<T> = Fn<T, boolean>;
type Reducer<T> = Fn2<T, T, T>;
type Comparator<T> = Fn2<T, T, -1|0|1>;
type Callback = Fn0<void>;

compose

Can compose up to 10 functions

import {Fn, compose} from "@bcg-ts/ts-toolkit";

const fn1: Fn<number, string> = (val: number) => val.toString();
const fn2: Fn<string, number> = (val: string) => val.length;
const fn3: Fn<number, number> = compose(fn1, fn2);

TypeUtils

import {TypeUtils} from "@bcg-ts/ts-toolkit";

TypeUtils.boolean(false); // true
TypeUtils.boolean(1); // false
// TypeUtils.function( ... )
// TypeUtils.nonNull( ... )
// TypeUtils.nonEmptyString( ... )
// TypeUtils.null( ... )
// TypeUtils.undefined( ... )
// TypeUtils.number( ... )
// TypeUtils.object( ... )
// TypeUtils.string( ... )
// TypeUtils.symbol( ... )
// TypeUtils.unknown ( ... )

TypeUtils.field({ value: 1 }, "value", TypeUtils.number) // true

Pipeline

uses "compose" internally to avoid intermediate values

import {Fn, Pipeline} from "@bcg-ts/ts-toolkit";

const numDigits: Fn<number, number> = Pipeline
  .identity<number>()
  .map((val) => val.toString())
  .map((str) => str.length)
  .callable;

const numDigitsStr: Fn<number, string> = Pipeline
  .fromCallable(numDigits)
  .map((val) => val.toString())
  .callable;

Optional

import {Optional} from "@bcg-ts/ts-toolkit";

const result: number = Optional.some(1) // number
  .map((val) => val + 1)                // number
  .filter((val) => val > 0)             // number | undefined
  .orElse(0)                            // number
  .value;                               // number