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

typelevel-ts

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

typelevel-ts - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

9

CHANGELOG.md

@@ -15,2 +15,11 @@ # Changelog

# 0.1.3
- **New Feature**
- `NumberToNat`
- `NatToNumber`
- hlists
- tuples
- convert tuples to / from hlists (`TupleToTHList`, `THListToTuple`)
# 0.1.2

@@ -17,0 +26,0 @@

117

lib/index.d.ts

@@ -49,4 +49,17 @@ export declare type Bool = 'true' | 'false';

}
export declare type _0 = {
isZero: 'true';
};
export declare type _1 = Succ<_0>;
export declare type _2 = Succ<_1>;
export declare type _3 = Succ<_2>;
export declare type _4 = Succ<_3>;
export declare type _5 = Succ<_4>;
export declare type _6 = Succ<_5>;
export declare type _7 = Succ<_6>;
export declare type _8 = Succ<_7>;
export declare type _9 = Succ<_8>;
export declare type _10 = Succ<_9>;
export declare type IsZero<N extends Nat> = N['isZero'];
export declare type Succ<N extends Positive | _0> = {
export declare type Succ<N extends Nat> = {
prev: N;

@@ -92,26 +105,18 @@ isZero: 'false';

export declare type Gt<N1 extends Nat, N2 extends Nat> = Not<Lte<N1, N2>>;
/** private */
export declare type __Mod<N1 extends Nat, N2 extends Nat, O extends TOption<Nat>> = {
true: N1;
false: Mod<TOptionUnsafeGet<O>, N2>;
}[IsNone<O>];
export declare type Mod<N1 extends Nat, N2 extends Nat> = {
true: _0;
false: __Mod<N1, N2, Sub<N1, N2>>;
export declare type Mod<N1 extends Nat, N2 extends Nat, R = _0> = {
true: R;
false: Mod<N1, N2, UnsafeSub<N1, N2>>;
}[IsZero<N1>];
export declare type Min<N1 extends Nat, N2 extends Nat> = If<Lte<N1, N2>, N1, N2>;
export declare type Max<N1 extends Nat, N2 extends Nat> = If<Lte<N1, N2>, N2, N1>;
export declare type _0 = {
isZero: 'true';
};
export declare type _1 = Succ<_0>;
export declare type _2 = Succ<_1>;
export declare type _3 = Succ<_2>;
export declare type _4 = Succ<_3>;
export declare type _5 = Succ<_4>;
export declare type _6 = Succ<_5>;
export declare type _7 = Succ<_6>;
export declare type _8 = Succ<_7>;
export declare type _9 = Succ<_8>;
export declare type _10 = Succ<_9>;
/**
* max number = 10
* examples:
* t.NumberToNat[0] == _0
* t.NumberToNat[1] == _1
* t.NumberToNat[10] == _10
*/
export declare type NumberToNat = TupleToObject<[_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10]>;
/** max Nat = _10 */
export declare type NatToNumber<N extends Nat> = If<NatEq<N, _0>, 0, If<NatEq<N, _1>, 1, If<NatEq<N, _2>, 2, If<NatEq<N, _3>, 3, If<NatEq<N, _4>, 4, If<NatEq<N, _5>, 5, If<NatEq<N, _6>, 6, If<NatEq<N, _7>, 7, If<NatEq<N, _8>, 8, If<NatEq<N, _9>, 9, 10>>>>>>>>>>;
export declare type StringOmit<L1 extends string, L2 extends string> = ({

@@ -139,1 +144,69 @@ [P in L1]: P;

};
export declare type THNil = {
IsHNil: 'true';
};
export declare type THCons<H, T extends THList> = {
IsHNil: 'false';
head: H;
tail: T;
};
export declare type THList = THNil | THCons<any, any>;
export declare type THListIsTHNil<L extends THList> = L['IsHNil'];
export declare type THListHead<L extends THCons<any, any>> = L['head'];
export declare type THListTail<L extends THCons<any, any>> = L['tail'];
export declare type THListLength<L extends THList> = {
true: _0;
false: Succ<THListLength<THListTail<L>>>;
}[THListIsTHNil<L>];
export declare type THListTypeAt<L extends THList, I extends Nat> = {
true: THListHead<L>;
false: THListTypeAt<THListTail<L>, Prev<I>>;
}[IsZero<I>];
export declare type THListGet<L extends THList, I extends Nat> = {
true: TNone;
false: {
true: TSome<THListHead<L>>;
false: THListGet<THListTail<L>, Prev<I>>;
}[IsZero<I>];
}[THListIsTHNil<L>];
export declare type UnsafeTHListGet<L extends THList, I extends Nat> = {
true: THListHead<L>;
false: UnsafeTHListGet<THListTail<L>, Prev<I>>;
}[IsZero<I>];
export declare type THListReverse<L extends THList, Acc = THNil> = {
true: Acc;
false: THListReverse<THListTail<L>, THCons<THListHead<L>, Acc>>;
}[THListIsTHNil<L>];
/** max length = 6 */
export declare type THListToTuple<L extends THList> = {
true: [];
false: {
true: [THListHead<L>];
false: {
true: [THListHead<L>, THListHead<THListTail<L>>];
false: {
true: [THListHead<L>, THListHead<THListTail<L>>, THListHead<THListTail<THListTail<L>>>];
false: {
true: [THListHead<L>, THListHead<THListTail<L>>, THListHead<THListTail<THListTail<L>>>, THListHead<THListTail<THListTail<THListTail<L>>>>];
false: {
true: [THListHead<L>, THListHead<THListTail<L>>, THListHead<THListTail<THListTail<L>>>, THListHead<THListTail<THListTail<THListTail<L>>>>, THListHead<THListTail<THListTail<THListTail<THListTail<L>>>>>];
false: {
true: [THListHead<L>, THListHead<THListTail<L>>, THListHead<THListTail<THListTail<L>>>, THListHead<THListTail<THListTail<THListTail<L>>>>, THListHead<THListTail<THListTail<THListTail<THListTail<L>>>>>, THListHead<THListTail<THListTail<THListTail<THListTail<THListTail<L>>>>>>];
false: 'Error';
}[IsZero<THListLength<THListTail<THListTail<THListTail<THListTail<THListTail<THListTail<L>>>>>>>>];
}[IsZero<THListLength<THListTail<THListTail<THListTail<THListTail<THListTail<L>>>>>>>];
}[IsZero<THListLength<THListTail<THListTail<THListTail<THListTail<L>>>>>>];
}[IsZero<THListLength<THListTail<THListTail<THListTail<L>>>>>];
}[IsZero<THListLength<THListTail<THListTail<L>>>>];
}[IsZero<THListLength<THListTail<L>>>];
}[IsZero<THListLength<L>>];
export declare type TupleToObject<T> = ObjectOmit<T, keyof Array<any>>;
export declare type Increment = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
export declare type TupleLength<T, I = 0> = {
true: TupleLength<T, Increment[I]>;
false: I;
}[ObjectHasKey<T, I>];
export declare type TupleToTHList<T, I = 0, L = THNil> = {
true: TupleToTHList<T, Increment[I], THCons<T[I], L>>;
false: L;
}[ObjectHasKey<T, I>];

2

package.json
{
"name": "typelevel-ts",
"version": "0.1.2",
"version": "0.1.3",
"description": "Type level programming in TypeScript",

@@ -5,0 +5,0 @@ "files": ["lib"],

@@ -55,3 +55,3 @@ **Requires TypeScript v2.4.1+**

# The `ObjectOmit` operator
# The `ObjectDiff` operator

@@ -64,7 +64,7 @@ **Example**. A `withDefaults` function (React)

export default function withDefaults<A, D extends keyof A>(
export default function withDefaults<D, A extends D>(
C: React.ComponentType<A>,
defaults: Pick<A, D>
): React.SFC<ObjectOmit<A, D> & Partial<Pick<A, D>>> {
return (props: any) => <C {...Object.assign({}, defaults, props)} />
defaults: D
): React.SFC<ObjectDiff<A, D>> {
return (props: any) => <C {...defaults} {...props} />
}

@@ -77,2 +77,4 @@

# The `ObjectOmit` operator
**Example**. A `withProps` function (React)

@@ -85,3 +87,3 @@

function withProps<D, P extends D>(C: React.ComponentType<P>, values: D): React.SFC<ObjectOmit<P, keyof D>> {
return (props: any) => <C {...Object.assign({}, props, values)} />
return (props: any) => <C {...props} {...values} />
}

@@ -93,14 +95,17 @@

```
# THlist
# The `ObjectDiff` operator
How to return the intersection of the items
```ts
import { Diff } from 'typelevel-ts'
export type __THListIntersection<L extends THList, Acc> = {
true: Acc
false: __THListIntersection<THListTail<L>, THListHead<L> & Acc>
}[THListIsTHNil<L>]
type Foo = { a: string; b: number }
type Bar = { b: number }
// Baz :: { a: string, b?: number }
type Baz = Diff<Foo, Bar>
/** returns the intersection of the contained types */
export type THListIntersection<L extends THList, WhenTHNil = never> = {
true: WhenTHNil
false: __THListIntersection<THListTail<L>, THListHead<L>>
}[THListIsTHNil<L>]
```
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