hyper-types
v0.0.2
Published
Advanced utility types
Downloads
1
Maintainers
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
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
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
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
IsLargerEquals
Ƭ IsLargerEquals<a
, b
>: Or
<IsLarger
<a
, b
>, IsEqual
<a
, b
>>
Type parameters
| Name | Type |
| :------ | :------ |
| a
| extends string
|
| b
| extends string
|
Defined in
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
IsSmallerEquals
Ƭ IsSmallerEquals<a
, b
>: Or
<IsSmaller
<a
, b
>, IsEqual
<a
, b
>>
Type parameters
| Name | Type |
| :------ | :------ |
| a
| extends string
|
| b
| extends string
|
Defined in
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
Extends
Ƭ Extends<A
, B
>: A
extends B
? true
: false
short for A extends B ? true : false
Type parameters
| Name |
| :------ |
| A
|
| B
|
Defined in
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
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
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
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
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
Namespace: Strings
Table of contents
Type Aliases
- Contains
- CountCharOccurances
- EndsWith
- EqualCharOccurances
- FirstChar
- IsEmpty
- IsNotEmpty
- IsSingleChar
- StartsWith
- WithoutFirstChar
Type Aliases
Contains
Ƭ Contains<str
, substring
>: Extends
<str
, `${string}${substring}${string}`>
Type parameters
| Name | Type |
| :------ | :------ |
| str
| extends string
|
| substring
| extends string
|
Defined in
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
EndsWith
Ƭ EndsWith<str
, suffix
>: Extends
<str
, `${string}${suffix}`>
Type parameters
| Name | Type |
| :------ | :------ |
| str
| extends string
|
| suffix
| extends string
|
Defined in
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
FirstChar
Ƭ FirstChar<str
>: str
extends `${infer first}${string}` ? first
: never
Type parameters
| Name | Type |
| :------ | :------ |
| str
| extends string
|
Defined in
IsEmpty
Ƭ IsEmpty<T
>: T
extends ""
? true
: false
Type parameters
| Name | Type |
| :------ | :------ |
| T
| extends string
|
Defined in
IsNotEmpty
Ƭ IsNotEmpty<T
>: Not
<IsEmpty
<T
>>
Type parameters
| Name | Type |
| :------ | :------ |
| T
| extends string
|
Defined in
IsSingleChar
Ƭ IsSingleChar<str
>: str
extends `${string}${infer a}` ? IsEmpty
<a
> : false
Type parameters
| Name | Type |
| :------ | :------ |
| str
| extends string
|
Defined in
StartsWith
Ƭ StartsWith<str
, prefix
>: Extends
<str
, `${prefix}${string}`>
Type parameters
| Name | Type |
| :------ | :------ |
| str
| extends string
|
| prefix
| extends string
|
Defined in
WithoutFirstChar
Ƭ WithoutFirstChar<str
>: str
extends `${string}${infer rest}` ? rest
: never
Type parameters
| Name | Type |
| :------ | :------ |
| str
| extends string
|
Defined in
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
|