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

@cuppachino/type-space

v2.1.1

Published

A collection of type utilities for TypeScript.

Downloads

553

Readme

📦 Installation

Use your favorite package manager to install @cuppachino/type-space as a developer dependency.

@cuppachino/type-space

pnpm add -D @cuppachino/type-space
npm install --save-dev @cuppachino/type-space

🔎 Quick Reference

The source code is fully tsdoc'd, so you can use your IDE's intellisense to reference examples and descriptions at any time. Click any type for more documentation.

🍎 Base Types

  • NumberLiteral: A stringified number literal.
  • Stringifiable: An alias for string | number | bigint | boolean | null | undefined.
  • UnknownArray: An alias for unknown[] | readonly unknown[], safer than any.
  • UnknownRecord: An alias for Record<PropertyKey, unknown>, safer than any or {}.

🧮 Arithmetic Types

  • Absolute: Coerces a number literal to a positive number of the same magnitude.
  • Add: Return the sum of two number literals.
  • Subtract: Return the difference between two number literals.

🔢 Numeric Types

  • IntoNumber: Coerce a NumberLike type to a number
  • IntoNumberLiteral: Coerce a NumberLike type to a NumberLiteral
  • IsInteger: A boolean type that is true if a number literal is an integer.
  • IsPositive: A boolean type that is true if a number literal is positive.
  • IsNegative: A boolean type that is true if a number literal is negative.
  • IsWhole: A boolean type that is true if a number literal is a whole number.
  • NumberLike: Coerce either a number or a NumberLiteral into a union between the two.
  • ParseNumberLiteral: Coerce a NumberLiteral type to a number

💭 String Types

  • Chars: Splits a string literal into a tuple of characters. Reads more clearly than Split in some cases.
  • ReverseString: Reverse a string literal.
  • Split: Splits a string literal into a tuple of characters, separated by the given delimiter.
  • SplitAt: Split a string literal into a tuple of two strings, separated by the given index, non-inclusive.
  • Stringify: Converts a type to a string literal type, if possible.
  • StringIncludes: A boolean type that is true if a string literal includes a given substring (⊆).
  • StringIncludesProper: A boolean type that is true if a string literal includes a given substring, and the substring is not the entire string (⊂).

📜 Tuple Types

  • CreateTuple: Generate a fixed-length tuple.
  • Flat: Recursively flatten a tuple up to a given depth.
  • IndexOf: Return a union of a tuple's indices.
  • Indices: Generate a tuple of a tuple's indices.
  • Join: Joins a tuple of strings into a single string, separated by a delimiter.
  • Length: Extract the length property from an array or tuple.
  • MergeAll: Merge all type members of a tuple into a single type.
  • PartitionKeys: Extract a union of keys for each member in a tuple into a new tuple; order is preserved.
  • PartitionValues: Create a tuple of value(s) for the given key(s) in each member of a tuple; order is preserved.
  • PartitionPick: Maps picked properties from each member of a tuple into a new tuple; order is preserved.
  • Reverse: Reverse the order of elements in a tuple type.

A la Array.prototype

sig

Action :: <Tuple> -> NewTuple
  • Pop: Remove the last element from a tuple. Does not return the removed element.
  • PopBy: Remove the last N elements from a tuple.
  • Push: Adds one element type to the end of a tuple. Does not return the new length of the tuple.
  • Shift: Remove the first element from a tuple type. Does not return the removed element.
  • ShiftBy: Remove the first N elements from a tuple.
  • Unshift: Adds one element type to the beginning of a tuple. Does not return the new length of the tuple.

🧰 Utility Types

  • Assert: Assert that a type is assignable to another type; shorthand for T extends U ? T : never.
  • Combine: Simplify a type by mapping over its properties.
  • KeyOf: Extract all keys from every member of a union type, unlike keyof which only preserves shared members' keys.
  • Mutable: Recursively removes the readonly modifier from all properties of a type.
  • PartialSome: Return a new type that allows the specified keys to be undefined.
  • PickAll: Extract properties from all members in a union, missing properties default to | undefined.
  • RequireSome: Return a new type requiring the selected keys.
  • Simplify: Simplify a type by mapping over its inferred properties - use when Combine cannot infer a deep type.
  • Subset: TypeScript equivalent of .
  • UnionLiteral: Create a union from a literal and primitive type without losing the literal type.
  • UnionToIntersection: Create an intersection from all members of a union type.
  • UnionToTuple: Convert a union to a tuple type. The order is not guaranteed.
  • Zip: From a tuple of keys and a tuple of values, create a new record.

Extract

Extends

| sig

Extends :: <T, R = T> -> boolean
  • T is the type to check.
  • R is the type returned when T extends the name of the generic.
  • ExtendsFunction: Return a type if the given type extends a function or method.

I hope you have fun with these utilities. Thank you for using type-space!