Comparing version 1.0.4 to 1.0.5
@@ -1,2 +0,2 @@ | ||
import { Apply, Call, Call2, Eval, Fn, Pipe, PipeRight, _ } from "./internals/core/Core"; | ||
import { Apply, Call, Call2, Eval, Fn, Pipe, PipeRight, _, arg, arg0, arg1, arg2, arg3 } from "./internals/core/Core"; | ||
import { Functions } from "./internals/functions/Functions"; | ||
@@ -9,2 +9,3 @@ import { Numbers } from "./internals/numbers/Numbers"; | ||
import { Booleans } from "./internals/booleans/Booleans"; | ||
export { _, Fn, Pipe, PipeRight, Call, Call2, Apply, Eval, Booleans, Objects, Unions, Strings, Numbers, Tuples, Functions, Booleans as B, Objects as O, Unions as U, Strings as S, Numbers as N, Tuples as T, Functions as F, }; | ||
import { Match } from "./internals/match/Match"; | ||
export { _, arg, arg0, arg1, arg2, arg3, Fn, Pipe, PipeRight, Call, Call2, Apply, Eval, Booleans, Objects, Unions, Strings, Numbers, Tuples, Functions, Match, Booleans as B, Objects as O, Unions as U, Strings as S, Numbers as N, Tuples as T, Functions as F, }; |
@@ -46,3 +46,11 @@ import { Equal, Every, Some } from "../helpers"; | ||
export type Or<a = unset, b = unset> = Functions.PartialApply<OrFn, [a, b]>; | ||
interface XOrFn extends Fn { | ||
return: this["args"] extends [ | ||
infer first extends boolean, | ||
infer second extends boolean, | ||
...any | ||
] ? first extends second ? false : true : never; | ||
} | ||
export type XOr<a = unset, b = unset> = Functions.PartialApply<XOrFn, [a, b]>; | ||
export {}; | ||
} |
@@ -33,2 +33,11 @@ declare const rawArgs: unique symbol; | ||
export type _ = "@hotscript/placeholder"; | ||
export type arg<Index extends number, Constraint = unknown> = { | ||
tag: "@hotscript/arg"; | ||
index: Index; | ||
constraint: Constraint; | ||
}; | ||
export type arg0<Constraint = unknown> = arg<0, Constraint>; | ||
export type arg1<Constraint = unknown> = arg<1, Constraint>; | ||
export type arg2<Constraint = unknown> = arg<2, Constraint>; | ||
export type arg3<Constraint = unknown> = arg<3, Constraint>; | ||
/** | ||
@@ -35,0 +44,0 @@ * Call a HOTScript function with the given arguments. |
@@ -81,2 +81,3 @@ export type Equal<a, b> = (<T>() => T extends a ? 1 : 2) extends <T>() => T extends b ? 1 : 2 ? true : false; | ||
export type Stringifiable = string | number | boolean | bigint | null | undefined; | ||
export type Primitive = string | number | boolean | bigint | null | undefined | symbol; | ||
export {}; |
@@ -97,3 +97,3 @@ import { Fn, unset, _ } from "../core/Core"; | ||
*/ | ||
export type Mod<n1 extends number | bigint | _ | unset = unset, n2 extends number | bigint | _ | unset = unset> = Functions.PartialApply<ModFn, [n1, n2]>; | ||
export type Mod<n1 extends number | bigint | _ | unset = unset, n2 extends number | bigint | _ | unset = unset> = Functions.PartialApply<ModFn, n2 extends unset ? [unset, n1] : [n1, n2]>; | ||
interface ModFn extends Fn { | ||
@@ -100,0 +100,0 @@ return: this["args"] extends [ |
@@ -1,3 +0,3 @@ | ||
import { GetFromPath, IsArrayStrict, Prettify, UnionToIntersection } from "../helpers"; | ||
import { Call, Call2, Fn, unset, _ } from "../core/Core"; | ||
import { GetFromPath, IsArrayStrict, Prettify, Primitive, UnionToIntersection } from "../helpers"; | ||
import { arg, Call, Call2, Fn, unset, _ } from "../core/Core"; | ||
import { Std } from "../std/Std"; | ||
@@ -111,3 +111,40 @@ import { Strings } from "../strings/Strings"; | ||
} | ||
/** | ||
* Create an object from parameters | ||
* @description This function is used to make an object from parameters | ||
* And allows to place the parameters in any object property | ||
* @param args - The parameters to make the object from | ||
* @returns The object made from the parameters | ||
* | ||
* @example | ||
* ```ts | ||
* type T0 = Apply<O.Create<{ a: arg0, b: arg1 }>, [1, 2]>; // { a: 1, b: 2 } | ||
* ``` | ||
*/ | ||
interface CreateFn extends Fn { | ||
return: this["args"] extends [infer pattern, ...infer args] ? CreateImpl<pattern, args> : never; | ||
} | ||
type CreateImpl<pattern, args extends unknown[]> = pattern extends arg<infer N extends number> ? args[N] : pattern extends Primitive ? pattern : pattern extends [any, ...any] ? { | ||
[key in keyof pattern]: CreateImpl<pattern[key], args>; | ||
} : pattern extends (infer V)[] ? CreateImpl<V, args>[] : pattern extends object ? { | ||
[key in keyof pattern]: CreateImpl<pattern[key], args>; | ||
} : pattern; | ||
export type Create<pattern = unset, arg0 = unset, arg1 = unset, arg2 = unset, arg3 = unset> = Functions.PartialApply<CreateFn, [pattern, arg0, arg1, arg2, arg3]>; | ||
interface RecordFn extends Fn { | ||
return: this["args"] extends [infer union extends string, infer value] ? Std._Record<union, value> : never; | ||
} | ||
/** | ||
* Create a record from a union of strings and a value type | ||
* @description This function is used to create a record from a union of strings | ||
* @param union - The union of strings to create the record from | ||
* @param value - The value to assign to each property | ||
* @returns The record created from the union of strings | ||
* | ||
* @example | ||
* ```ts | ||
* type T0 = Call<O.Record<'a' | 'b' | 'c'>, 1>; // { a: 1, b: 1, c: 1 } | ||
* ``` | ||
*/ | ||
export type Record<union extends string | _ | unset = unset, value = unset> = Functions.PartialApply<RecordFn, [union, value]>; | ||
export {}; | ||
} |
@@ -10,2 +10,3 @@ export declare namespace Std { | ||
type _Uncapitalize<a extends string> = Uncapitalize<a>; | ||
type _Record<k extends PropertyKey, v> = Record<k, v>; | ||
} |
import { Functions as F, Functions } from "../functions/Functions"; | ||
import { Numbers as N } from "../numbers/Numbers"; | ||
import * as NumbersImpl from "../numbers/impl/numbers"; | ||
import { Call, Call2, Eval, Fn, unset, _ } from "../core/Core"; | ||
import { Numbers as N, Numbers } from "../numbers/Numbers"; | ||
import { Call, Call2, Eval, Fn, Pipe, unset, _ } from "../core/Core"; | ||
import { Iterator, Stringifiable } from "../helpers"; | ||
@@ -59,3 +58,17 @@ export declare namespace Tuples { | ||
]>; | ||
interface ToUnionFn extends Fn { | ||
return: this["arg0"][number]; | ||
} | ||
/** | ||
* Convert a tuple to a union of its elements. | ||
* @param tuple - The tuple to convert. | ||
* @returns A union of the tuple's elements. | ||
* @example | ||
* ```ts | ||
* type T0 = Call<Tuples.ToUnion, [1, 2, 3]>; // 1 | 2 | 3 | ||
* type T1 = Eval<Tuples.ToUnion<[1, 2, 3]>>; // 1 | 2 | 3 | ||
* ``` | ||
*/ | ||
export type ToUnion<tuple extends readonly any[] | _ | unset = unset> = Functions.PartialApply<ToUnionFn, [tuple]>; | ||
/** | ||
* Returns the first element of a tuple. | ||
@@ -494,9 +507,13 @@ * @params args[0] - A tuple. | ||
infer end extends number | ||
] ? NumbersImpl.LessThanOrEqual<start, end> extends true ? NumbersImpl.Abs<NumbersImpl.Add<1, NumbersImpl.Sub<end, start>>> extends infer length extends number ? RangeImpl<start, length> : never : never : never; | ||
] ? Call2<Numbers.LessThanOrEqual, start, end> extends true ? Pipe<start, [ | ||
Numbers.Sub<end, _>, | ||
Numbers.Add<1>, | ||
Numbers.Abs | ||
]> extends infer length extends number ? RangeImpl<start, length> : never : never : never; | ||
} | ||
type RangeImpl<start extends number, length extends number, output extends any[] = []> = output["length"] extends length ? output : RangeImpl<start, length, [ | ||
...output, | ||
NumbersImpl.Add<start, output["length"]> | ||
Eval<Numbers.Add<start, output["length"]>> | ||
]>; | ||
export {}; | ||
} |
{ | ||
"name": "hotscript", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Type-level madness", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -91,3 +91,14 @@ # Higher-Order TypeScript (HOTScript) | ||
- [x] Some | ||
- [x] ToUnion | ||
- [ ] Object | ||
- [ ] Readonly | ||
- [ ] Mutable | ||
- [ ] Required | ||
- [ ] Partial | ||
- [ ] ReadonlyDeep | ||
- [ ] MutableDeep | ||
- [ ] RequiredDeep | ||
- [ ] PartialDeep | ||
- [x] Record | ||
- [x] Create | ||
- [x] Get | ||
@@ -164,2 +175,3 @@ - [x] FromEntries | ||
- [x] Or | ||
- [x] XOr | ||
- [x] Not | ||
@@ -166,0 +178,0 @@ - [x] Extends |
153389
83
4128
179