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

hyper-types

v0.0.2

Published

Advanced utility types

Downloads

8

Readme

hyper-types

Advanced utility types for Typescript

Installation

$ npm i hyper-types --save-dev
  or
$ yarn add hyper-types --dev

API

Table of contents

Namespaces

Namespace: Arithmetic

Table of contents

Type Aliases

Type Aliases

Decrease

Ƭ Decrease<T>: T extends `0${infer A}` ? Decrease<A> : T extends "" ? "" : T extends keyof DecreaseDigitMap ? DecreaseDigitMap[T] : T extends `${infer A}0` ? Decrease<A> extends 0 ? "9" : `${Decrease}9` : T extends `${infer A}${infer B}` ? `${A}${Decrease}` : "0"

Type parameters

| Name | Type | | :------ | :------ | | T | extends string |

Defined in

src/arithmetic.ts:16


Increase

Ƭ Increase<T>: T extends "" ? "" : T extends keyof IncreaseDigitMap ? IncreaseDigitMap[T] : T extends `${infer A}9` ? Increase<A> extends "" ? "10" : `${Increase}0` : T extends `${infer A}${infer B}` ? `${A}${Increase}` : "0"

Type parameters

| Name | Type | | :------ | :------ | | T | extends string |

Defined in

src/arithmetic.ts:42


IsDigitLarger

Ƭ IsDigitLarger<a, b, counter>: counter extends "10" ? false : a extends b ? false : a extends counter ? false : b extends counter ? true : IsDigitLarger<a, b, Increase<counter>>

Type parameters

| Name | Type | | :------ | :------ | | a | extends string | | b | extends string | | counter | extends string = "0" |

Defined in

src/arithmetic.ts:54


IsLarger

Ƭ IsLarger<a, b>: IsEqual<a, b> extends true ? false : IsLonger<a, b> extends true ? true : IsLonger<b, a> extends true ? false : a extends `${infer a1}${infer a2}` ? b extends `${infer b1}${infer b2}` ? IsEqual<a1, b1> extends true ? IsLarger<a2, b2> : IsDigitLarger<a1, b1> : never : never

Type parameters

| Name | Type | | :------ | :------ | | a | extends string | | b | extends string |

Defined in

src/arithmetic.ts:68


IsLargerEquals

Ƭ IsLargerEquals<a, b>: Or<IsLarger<a, b>, IsEqual<a, b>>

Type parameters

| Name | Type | | :------ | :------ | | a | extends string | | b | extends string |

Defined in

src/arithmetic.ts:90


IsSmaller

Ƭ IsSmaller<a, b>: And<Not<IsLarger<a, b>>, Not<IsEqual<a, b>>>

Type parameters

| Name | Type | | :------ | :------ | | a | extends string | | b | extends string |

Defined in

src/arithmetic.ts:85


IsSmallerEquals

Ƭ IsSmallerEquals<a, b>: Or<IsSmaller<a, b>, IsEqual<a, b>>

Type parameters

| Name | Type | | :------ | :------ | | a | extends string | | b | extends string |

Defined in

src/arithmetic.ts:95

Namespace: Logic

Table of contents

Type Aliases

Type Aliases

And

Ƭ And<A, B, C, D, E, F>: A extends true ? B extends true ? C extends true ? D extends true ? E extends true ? F extends true ? true : false : false : false : false : false : false

Evaluates to true if all provided types are true.

Example

type A = And<true, true>; // true
type B = And<true, false>; // false
Type parameters

| Name | Type | | :------ | :------ | | A | extends boolean | | B | extends boolean | | C | extends boolean = true | | D | extends boolean = true | | E | extends boolean = true | | F | extends boolean = true |

Defined in

src/logic.ts:10


Extends

Ƭ Extends<A, B>: A extends B ? true : false

short for A extends B ? true : false

Type parameters

| Name | | :------ | | A | | B |

Defined in

src/logic.ts:99


IfElse

Ƭ IfElse<cond, then, otherwise>: cond extends true ? then : otherwise

short for cond extends true ? then : otherwise

Example

type A = IfElse<true, 42, 1337>; // 42
Type parameters

| Name | Type | | :------ | :------ | | cond | extends boolean | | then | then | | otherwise | otherwise |

Defined in

src/logic.ts:109


IsEqual

Ƭ IsEqual<A, B>: And<A extends B ? true : false, B extends A ? true : false>

Evaluates to true if both types are equal, i.e. extend each other.

Example

type A = IsEqual<42, 42>; // true
type B = IsEqual<1337, 69>; // false
Type parameters

| Name | Type | | :------ | :------ | | A | extends string | | B | extends string |

Defined in

src/logic.ts:80


IsInequal

Ƭ IsInequal<A, B>: Not<IsEqual<A, B>>

Evaluates to true if both types are not equal, i.e. not extend each other.

Example

type A = IsInequal<42, 42>; // false
type B = IsInequal<1337, 69>; // true
Type parameters

| Name | Type | | :------ | :------ | | A | extends string | | B | extends string |

Defined in

src/logic.ts:94


Not

Ƭ Not<T>: T extends true ? false : true

Evaluates to the opposite of the passed type.

Example

type A = Not<false>; // true
Type parameters

| Name | Type | | :------ | :------ | | T | extends boolean |

Defined in

src/logic.ts:69


Or

Ƭ Or<A, B, C, D, E, F>: A extends true ? true : B extends true ? true : C extends true ? true : D extends true ? true : E extends true ? true : F extends true ? true : false

Evaluates to true if at least one of the provided types is true.

Example

type A = Or<true, false>; // true
type B = Or<false, false>; // false
Type parameters

| Name | Type | | :------ | :------ | | A | extends boolean | | B | extends boolean | | C | extends boolean = false | | D | extends boolean = false | | E | extends boolean = false | | F | extends boolean = false |

Defined in

src/logic.ts:40

Namespace: Strings

Table of contents

Type Aliases

Type Aliases

Contains

Ƭ Contains<str, substring>: Extends<str, `${string}${substring}${string}`>

Type parameters

| Name | Type | | :------ | :------ | | str | extends string | | substring | extends string |

Defined in

src/string.ts:8


CountCharOccurances

Ƭ CountCharOccurances<str, char, count>: IsEmpty<str> extends true ? count : CountCharOccurances<WithoutFirstChar<str>, char, FirstChar<str> extends char ? Increase<count> : count>

Type parameters

| Name | Type | | :------ | :------ | | str | extends string | | char | extends string | | count | extends string = "0" |

Defined in

src/string.ts:33


EndsWith

Ƭ EndsWith<str, suffix>: Extends<str, `${string}${suffix}`>

Type parameters

| Name | Type | | :------ | :------ | | str | extends string | | suffix | extends string |

Defined in

src/string.ts:24


EqualCharOccurances

Ƭ EqualCharOccurances<str, charA, charB>: IsEqual<CountCharOccurances<str, charA>, CountCharOccurances<str, charB>>

Type parameters

| Name | Type | | :------ | :------ | | str | extends string | | charA | extends string | | charB | extends string |

Defined in

src/string.ts:45


FirstChar

Ƭ FirstChar<str>: str extends `${infer first}${string}` ? first : never

Type parameters

| Name | Type | | :------ | :------ | | str | extends string |

Defined in

src/string.ts:13


IsEmpty

Ƭ IsEmpty<T>: T extends "" ? true : false

Type parameters

| Name | Type | | :------ | :------ | | T | extends string |

Defined in

src/string.ts:4


IsNotEmpty

Ƭ IsNotEmpty<T>: Not<IsEmpty<T>>

Type parameters

| Name | Type | | :------ | :------ | | T | extends string |

Defined in

src/string.ts:6


IsSingleChar

Ƭ IsSingleChar<str>: str extends `${string}${infer a}` ? IsEmpty<a> : false

Type parameters

| Name | Type | | :------ | :------ | | str | extends string |

Defined in

src/string.ts:29


StartsWith

Ƭ StartsWith<str, prefix>: Extends<str, `${prefix}${string}`>

Type parameters

| Name | Type | | :------ | :------ | | str | extends string | | prefix | extends string |

Defined in

src/string.ts:19


WithoutFirstChar

Ƭ WithoutFirstChar<str>: str extends `${string}${infer rest}` ? rest : never

Type parameters

| Name | Type | | :------ | :------ | | str | extends string |

Defined in

src/string.ts:16

Namespace: Utilities

Table of contents

Type Aliases

Type Aliases

IsLonger

Ƭ IsLonger<a, b>: a extends `${string}${infer a2}` ? b extends `${string}${infer b2}` ? And<IsNotEmpty<a2>, IsNotEmpty<b2>> extends true ? IsLonger<a2, b2> : IsNotEmpty<a2> : never : never

Type parameters

| Name | Type | | :------ | :------ | | a | extends string | | b | extends string |

Defined in

src/utils.ts:4