Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hotscript

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hotscript

Type-level madness

  • 1.0.10
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
221K
increased by6.84%
Maintainers
1
Weekly downloads
 
Created
Source

Higher-Order TypeScript (HOTScript)

A lodash-like library for types, with support for type-level 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";

// prettier-ignore
type res1 = Pipe<
  //  ^? 95
  [1, 2, 3, 4, 3, 4],
  [
    Tuples.Map<Numbers.Add<3>>,
    Tuples.Join<".">,
    Strings.Split<".">,
    Tuples.Map<Strings.ToNumber>,
    Tuples.Map<Numbers.Add<10>>,
    Tuples.Sum
  ]
>;
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>]>
    >
  ]
>;

TODO

  • Core
    • Pipe
    • PipeRight
    • Call
    • Apply
    • PartialApply
    • Compose
    • ComposeLeft
  • Function
    • ReturnType
    • Parameters
    • Parameter n
  • Tuples
    • Create
    • Partition
    • IsEmpty
    • Zip
    • ZipWith
    • Sort
    • Head
    • At
    • Tail
    • Last
    • FlatMap
    • Find
    • Sum
    • Drop n
    • Take n
    • TakeWhile
    • Join separator
    • Map
    • Filter
    • Reduce
    • ReduceRight
    • Every
    • Some
    • ToUnion
    • ToIntersection
    • Prepend
    • Append
    • Concat
  • Object
    • Readonly
    • Mutable
    • Required
    • Partial
    • ReadonlyDeep
    • MutableDeep
    • RequiredDeep
    • PartialDeep
    • Update
    • Record
    • Keys
    • Values
    • AllPaths
    • Create
    • Get
    • FromEntries
    • Entries
    • MapValues
    • MapKeys
    • GroupBy
    • Assign
    • Pick
    • PickBy
    • Omit
    • OmitBy
    • CamelCase
    • CamelCaseDeep
    • SnakeCase
    • SnakeCaseDeep
    • KebabCase
    • KebabCaseDeep
    • Min
    • Max
  • Union
    • Map
    • Extract
    • ExtractBy
    • Exclude
    • ExcludeBy
    • NonNullable
    • ToTuple
    • ToIntersection
  • String
    • Length
    • TrimLeft
    • TrimRight
    • Trim
    • Join
    • Replace
    • Slice
    • Split
    • Repeat
    • StartsWith
    • EndsWith
    • ToTuple
    • ToNumber
    • ToString
    • Prepend
    • Append
    • Uppercase
    • Lowercase
    • Capitalize
    • Uncapitalize
    • SnakeCase
    • CamelCase
    • KebabCase
    • Compare
    • Equal
    • NotEqual
    • LessThan
    • LessThanOrEqual
    • GreaterThan
    • GreaterThanOrEqual
  • Number
    • Add
    • Multiply
    • Subtract
    • Negate
    • Power
    • Div
    • Mod
    • Abs
    • Compare
    • GreaterThan
    • GreaterThanOrEqual
    • LessThan
    • LessThanOrEqual
  • Boolean
    • And
    • Or
    • XOr
    • Not
    • Extends
    • Equals
    • DoesNotExtend

FAQs

Package last updated on 04 Mar 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc