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

hotscript

v1.0.13

Published

A library of composable functions for the type-level! Transform your TypeScript types in any way you want using functions you already know.

Downloads

889,273

Readme

Higher-Order TypeScript (HOTScript)

A library of composable functions for the type level!

Transform your TypeScript types in any way you want using functions you already know.

image

Features

  • Type-level higher-order functions (Tuples.Map, Tuples.Filter, Objects.MapValues, etc).
  • Type-level pattern matching with Match.
  • Performant math operations (Numbers.Add, Numbers.Sub, Numbers.Mul, Numbers.Div, etc).
  • Custom "lambda" functions.

🚧 work in progress 🚧

Installation

You can find HotScript on npm:

npm install -D hotscript

HotScript is a work-in-progress library, so expect breaking changes in its API.

Examples

Transforming a list

Run this as a TypeScript Playground

import { Pipe, Tuples, Strings, Numbers } from "hotscript";

type res1 = Pipe<
  //  ^? 62
  [1, 2, 3, 4],
  [
    Tuples.Map<Numbers.Add<3>>,       // [4, 5, 6, 7]
    Tuples.Join<".">,                 // "4.5.6.7"
    Strings.Split<".">,               // ["4", "5", "6", "7"]
    Tuples.Map<Strings.Prepend<"1">>, // ["14", "15", "16", "17"]
    Tuples.Map<Strings.ToNumber>,     // [14, 15, 16, 17]
    Tuples.Sum                        // 62
  ]
>;

Defining a first-class function

Run this as a TypeScript Playground

import { Call, Fn, Tuples } from "hotscript";

// This is a type-level "lambda"!
interface Duplicate extends Fn {
  return: [this["arg0"], this["arg0"]];
}

type result1 = Call<Tuples.Map<Duplicate>, [1, 2, 3, 4]>;
//     ^? [[1, 1], [2, 2], [3, 3], [4, 4]]

type result2 = Call<Tuples.FlatMap<Duplicate>, [1, 2, 3, 4]>;
//     ^? [1, 1, 2, 2, 3, 3, 4, 4]

Transforming an object type

Run this as a TypeScript Playground

import { Pipe, Objects, Booleans } from "hotscript";

// Let's compose some functions to transform an object type:
type ToAPIPayload<T> = Pipe<
  T,
  [
    Objects.OmitBy<Booleans.Equals<symbol>>,
    Objects.Assign<{ metadata: { newUser: true } }>,
    Objects.SnakeCaseDeep,
    Objects.Assign<{ id: string }>
  ]
>;
type T = ToAPIPayload<{
  id: symbol;
  firstName: string;
  lastName: string;
}>;
// Returns:
type T = {
  id: string;
  metadata: { new_user: true };
  first_name: string;
  last_name: string;
};

Parsing a route path

Run this as a TypeScript Playground

https://user-images.githubusercontent.com/2315749/222081717-96217cd2-ac89-4e06-a942-17fbda717cd2.mp4

import { Pipe, Objects, Strings, ComposeLeft, Tuples, Match } from "hotscript";

type res5 = Pipe<
  //    ^? { id: string, index: number }
  "/users/<id:string>/posts/<index:number>",
  [
    Strings.Split<"/">,
    Tuples.Filter<Strings.StartsWith<"<">>,
    Tuples.Map<ComposeLeft<[Strings.Trim<"<" | ">">, Strings.Split<":">]>>,
    Tuples.ToUnion,
    Objects.FromEntries,
    Objects.MapValues<
      Match<[Match.With<"string", string>, Match.With<"number", number>]>
    >
  ]
>;

API

  • [x] Core
    • [x] Pipe<Input, Fn[]>
    • [x] PipeRight<Fn[], Input>
    • [x] Call<Fn, ...Arg>
    • [x] Apply<Fn, Arg[]>
    • [x] PartialApply<Fn, Arg[]>
    • [x] Compose<Fn[]>
    • [x] ComposeLeft<Fn[]>
  • [x] Function
    • [x] ReturnType<Fn>
    • [x] Parameters<Fn>
    • [x] Parameter<N, Fn>
    • [x] MapReturnType<Fn, FunctionType>
    • [x] MapParameters<Fn, FunctionType>
  • [ ] Tuples
    • [x] Create<X> -> [X]
    • [x] Partition<Tuple>
    • [x] IsEmpty<Tuple>
    • [x] Zip<...Tuple[]>
    • [x] ZipWith<Fn, ...Tuple[]>
    • [x] Sort<Tuple>
    • [x] Head<Tuple>
    • [x] Tail<Tuple>
    • [x] At<N, Tuple>
    • [x] Last<Tuple>
    • [x] FlatMap<Fn, Tuple>
    • [x] Find<Fn, Tuple>
    • [x] Drop<N, Tuple>
    • [x] Take<N, Tuple>
    • [x] TakeWhile<Fn, Tuple>
    • [x] GroupBy<Fn, Tuple>
    • [x] Join<Str, Tuple>
    • [x] Map<Fn, Tuple>
    • [x] Filter<Fn, Tuple>
    • [x] Reduce<Fn, Init, Tuple>
    • [x] ReduceRight<Fn, Init, Tuple>
    • [x] Reverse<Tuple>
    • [x] Every<Fn, Tuple>
    • [x] Some<Fn, Tuple>
    • [x] SplitAt<N, Tuple>
    • [x] ToUnion<Tuple>
    • [x] ToIntersection<Tuple>
    • [x] Prepend<X, Tuple>
    • [x] Append<X, Tuple>
    • [x] Concat<T1, T2>
    • [x] Min<Tuple>
    • [x] Max<Tuple>
    • [x] Sum<Tuple>
  • [ ] Object
    • [x] Readonly<Obj>
    • [x] Mutable<Obj>
    • [x] Required<Obj>
    • [x] Partial<Obj>
    • [x] ReadonlyDeep<Obj>
    • [x] MutableDeep<Obj>
    • [x] RequiredDeep<Obj>
    • [x] PartialDeep<Obj>
    • [x] Update<Path, Fn | V, Obj>
    • [x] Record<Key, Value>
    • [x] Keys<Obj>
    • [x] Values<Obj>
    • [x] AllPaths<Obj>
    • [x] Create<Pattern, X>
    • [x] Get<Path, Obj>
    • [x] FromEntries<[Key, Value]>
    • [x] Entries<Obj>
    • [x] MapValues<Fn, Obj>
    • [x] MapKeys<Fn, Obj>
    • [x] Assign<...Obj>
    • [x] Pick<Key, Obj>
    • [x] PickBy<Fn, Obj>
    • [x] Omit<Key, Obj>
    • [x] OmitBy<Fn, Obj>
    • [x] CamelCase<Obj>
    • [x] CamelCaseDeep<Obj>
    • [x] SnakeCase<Obj>
    • [x] SnakeCaseDeep<Obj>
    • [x] KebabCase<Obj>
    • [x] KebabCaseDeep<Obj>
  • [ ] Union
    • [x] Map<Fn, U>
    • [x] Extract<T, U>
    • [x] ExtractBy<Fn, U>
    • [x] Exclude<T, U>
    • [x] ExcludeBy<Fn, U>
    • [x] NonNullable<U>
    • [x] ToTuple<U>
    • [x] ToIntersection<U>
  • [ ] String
    • [x] Length<Str>
    • [x] TrimLeft<Str>
    • [x] TrimRight<Str>
    • [x] Trim<Str>
    • [x] Join<Sep, Str>
    • [x] Replace<From, To, Str>
    • [x] Slice<Start, End, Str>
    • [x] Split<Sep, Str>
    • [x] Repeat<N, Str>
    • [x] StartsWith<S, Str>
    • [x] EndsWith<E, Str>
    • [x] ToTuple<Str>
    • [x] ToNumber<Str>
    • [x] ToString<Str>
    • [x] Prepend<Start, Str>
    • [x] Append<End, Str>
    • [x] Uppercase<Str>
    • [x] Lowercase<Str>
    • [x] Capitalize<Str>
    • [x] Uncapitalize<Str>
    • [x] SnakeCase<Str>
    • [x] CamelCase<Str>
    • [x] KebabCase<Str>
    • [x] Compare<Str, Str>
    • [x] Equal<Str, Str>
    • [x] NotEqual<Str, Str>
    • [x] LessThan<Str, Str>
    • [x] LessThanOrEqual<Str, Str>
    • [x] GreaterThan<Str, Str>
    • [x] GreaterThanOrEqual<Str, Str>
  • [ ] Number
    • [x] Add<N, M>
    • [x] Multiply<N, M>
    • [x] Subtract<N, M>
    • [x] Negate<N>
    • [x] Power<N, M>
    • [x] Div<N, M>
    • [x] Mod<N, M>
    • [x] Abs<N>
    • [x] Compare<N, M>
    • [x] GreaterThan<N, M>
    • [x] GreaterThanOrEqual<N, M>
    • [x] LessThan<N, M>
    • [x] LessThanOrEqual<N, M>
  • [ ] Boolean
    • [x] And<Bool, Bool>
    • [x] Or<Bool, Bool>
    • [x] XOr<Bool, Bool>
    • [x] Not<Bool>
    • [x] Extends<A, B>
    • [x] Equals<A, B>
    • [x] DoesNotExtend<A, B>