Giter Club home page Giter Club logo

type-space's Introduction

Type Space

Welcome to Type Space, a suite of utility types for enhancing your TypeScript code. With @cuppachino/type-space, you can perform a wide range of type operations, including numeric calculations, string manipulation, tuple operations, and more.

Report Problem ๐ŸŒ˜๐Ÿง‘โ€๐Ÿš€ Contribute

๐Ÿ“ฆ 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!

type-space's People

Contributors

cuppachino avatar github-actions[bot] avatar renovate[bot] avatar

Stargazers

 avatar

Watchers

 avatar

type-space's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • Update dependency tsc-alias to v1.8.8
  • Update dependency @changesets/cli to v2.27.1
  • Update dependency @tsd/typescript to v5.3.3
  • Update dependency eslint to v8.56.0 (eslint, @types/eslint)
  • Update dependency jest to v29.7.0
  • Update actions/checkout action to v4
  • Update actions/setup-node action to v4
  • Update dependency eslint-config-prettier to v9
  • Update dependency eslint-plugin-jsdoc to v48
  • Update dependency eslint-plugin-prettier to v5
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/release.yml
  • actions/checkout v3
  • pnpm/action-setup v2.2.4
  • actions/setup-node v3
  • changesets/action v1
npm
package.json
  • @changesets/cli ^2.26.2
  • @tsd/typescript ^5.2.2
  • @type-challenges/utils ^0.1.1
  • @types/eslint ^8.44.2
  • @typescript-eslint/eslint-plugin ^5.62.0
  • @typescript-eslint/parser ^5.62.0
  • eslint ^8.49.0
  • eslint-config-prettier ^8.10.0
  • eslint-plugin-jsdoc ^40.3.0
  • eslint-plugin-prettier ^4.2.1
  • eslint-plugin-tsdoc ^0.2.17
  • jest ^29.6.4
  • jest-runner-tsd ^5.0.0
  • prettier 2.8.6
  • tsc-alias ^1.8.7
  • tsd-lite ^0.7.0
  • typescript 5.2.2
  • pnpm 7.30.0

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.