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

hotscript

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

hotscript - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

dist/internals/strings/impl/length.d.ts

124

dist/internals/core/Core.d.ts
declare const rawArgs: unique symbol;
type rawArgs = typeof rawArgs;
/**
* Base type for all functions
* @description You need to extend this type to create a new function that can be used in the HOTScript library.
* usually you will just convert some typescript utility time you already have to a hotscript function.
* This way you can use the HOTScript library to create more complex functions.
*
* @example
* ```ts
* export interface CustomOmitFn extends Fn {
* return: this[args] extends [infer obj, infer keys] ? Omit<obj, keys> : never;
* }
* ```
*/
export interface Fn {

@@ -12,25 +25,123 @@ [rawArgs]: unknown;

}
/**
* A placeholder type that can be used to indicate that a parameter is not set.
*/
export type unset = "@hotscript/unset";
/**
* A placeholder type that can be used to indicate that a parameter is to partially applied.
*/
export type _ = "@hotscript/placeholder";
/**
* Call a HOTScript function with the given arguments.
*
* @param fn - The function to call.
* @param args - The arguments to pass to the function.
* @returns The result of the function.
*
* @example
* ```ts
* type T0 = Apply<Numbers.Add, [1, 2]>; // 3
* ```
*/
export type Apply<fn extends Fn, args extends unknown[]> = (fn & {
[rawArgs]: args;
})["return"];
/**
* Call a HOTScript function with the only one argument.
*
* @param fn - The function to call.
* @param arg1 - The argument to pass to the function.
* @returns The result of the function.
*
* @example
* ```ts
* type T0 = Call<Numbers.Negate, 1>; // -1
* ```
*/
export type Call<fn extends Fn, arg1> = (fn & {
[rawArgs]: [arg1];
})["return"];
/**
* Call a HOTScript function like a normal Utility type.
*
* @param fn - The function to call.
*
* @example
* ```ts
* type T0 = Eval<Numbers.Add<1, 2>>; // 3
* type T1 = Eval<Numbers.Negate<1>>; // -1
* ```
*/
export type Eval<fn extends Fn> = (fn & {
[rawArgs]: [];
})["return"];
/**
* Call a HOTScript function with the two arguments.
*
* @param fn - The function to call.
* @param arg1 - The first argument to pass to the function.
* @param arg2 - The second argument to pass to the function.
* @returns The result of the function.
*
* @example
* ```ts
* type T0 = Call2<Numbers.Add, 1, 2>; // 3
* ```
*/
export type Call2<fn extends Fn, arg1, arg2> = (fn & {
[rawArgs]: [arg1, arg2];
})["return"];
/**
* Call a HOTScript function with the three arguments.
*
* @param fn - The function to call.
* @param arg1 - The first argument to pass to the function.
* @param arg2 - The second argument to pass to the function.
* @param arg3 - The third argument to pass to the function.
* @returns The result of the function.
*/
export type Call3<fn extends Fn, arg1, arg2, arg3> = (fn & {
[rawArgs]: [arg1, arg2, arg3];
})["return"];
/**
* Call a HOTScript function with the four arguments.
*
* @param fn - The function to call.
* @param arg1 - The first argument to pass to the function.
* @param arg2 - The second argument to pass to the function.
* @param arg3 - The third argument to pass to the function.
* @param arg4 - The fourth argument to pass to the function.
* @returns The result of the function.
*/
export type Call4<fn extends Fn, arg1, arg2, arg3, arg4> = (fn & {
[rawArgs]: [arg1, arg2, arg3, arg4];
})["return"];
/**
* Call a HOTScript function with the five arguments.
*
* @param fn - The function to call.
* @param arg1 - The first argument to pass to the function.
* @param arg2 - The second argument to pass to the function.
* @param arg3 - The third argument to pass to the function.
* @param arg4 - The fourth argument to pass to the function.
* @param arg5 - The fifth argument to pass to the function.
* @returns The result of the function.
*/
export type Call5<fn extends Fn, arg1, arg2, arg3, arg4, arg5> = (fn & {
args: [arg1, arg2, arg3, arg4, arg5];
})["return"];
/**
* Pipe a value through a list of functions.
* @description This is the same as the pipe operator in other languages.
* Evaluates the first function with the initial value, then passes the result to the second function, and so on.
*
* @param acc - The initial value to pass to the first function.
* @param xs - The list of functions to pipe the value through.
* @returns The result of the last function.
*
* @example
* ```ts
* type T0 = Pipe<1, [Numbers.Add<1>, Numbers.Negate]>; // -2
* ```
*/
export type Pipe<acc, xs extends Fn[]> = xs extends [

@@ -40,2 +151,15 @@ infer first extends Fn,

] ? Pipe<Call<first, acc>, rest> : acc;
/**
* Pipe a value through a list of functions.
* @description This is the same as the pipe operator in other languages.
* Evaluates the last function with the initial value, then passes the result to the second to last function, and so on.
*
* @param xs - The list of functions to pipe the value through.
* @param acc - The initial value to pass to the last function.
* @returns The result of the first function.
*
* @example
* ```ts
* type T0 = PipeRight<[Numbers.Add<1>, Numbers.Negate], 1>; // 0
*/
export type PipeRight<xs extends Fn[], acc> = xs extends [

@@ -42,0 +166,0 @@ ...infer rest extends Fn[],

94

dist/internals/functions/Functions.d.ts

@@ -1,7 +0,19 @@

import { Apply, Fn } from "../core/Core";
import { Apply, Fn, unset, _ } from "../core/Core";
import { MergeArgs } from "./impl/MergeArgs";
export declare namespace Functions {
/**
* Returns the the function's first argument.
*
* @param arg0 - The function to extract the first argument from.
* @returns The first argument of the function.
*/
export interface Identity extends Fn {
return: this["arg0"];
}
/**
* A function that returns it's generic parameter.
*
* @param T - The type to return.
* @returns The type `T`.
*/
export interface Constant<T> extends Fn {

@@ -11,9 +23,47 @@ return: T;

type ParametersImpl<fn> = fn extends (...args: infer args) => any ? args : never;
export interface Parameters extends Fn {
export interface ParametersFn extends Fn {
return: ParametersImpl<this["arg0"]>;
}
export interface Parameter<N extends number> extends Fn {
return: ParametersImpl<this["arg0"]>[N];
/**
* Returns the parameters of a function.
*
* @param fn - The function to extract the parameters from.
* @returns The parameters of the function.
*
* @example
* ```ts
* type T0 = Call<Parameters, (a: number, b: string) => void>; // [a: number,b: string]
* ```
*/
export type Parameters<fn extends ((...args: any[]) => any) | _ | unset = unset> = PartialApply<ParametersFn, [fn]>;
export interface ParameterFn extends Fn {
return: ParametersImpl<this["arg0"]>[this["arg1"]];
}
/**
* Returns the Nth parameter of a function.
*
* @param fn - The function to extract the parameter from.
* @param N - The index of the parameter to return.
* @returns The Nth parameter of the function.
*
* @example
* ```ts
* type T0 = Call<Parameter<1>, (a: number, b: string) => void>; // number
* type T1 = Call2<Parameter, (a: number, b: string) => void, 1>; // string
* type T2 = Eval<Parameter<(a: number, b: string) => void, 0>>; // number
*/
export type Parameter<N extends number | _ | unset = unset, fn extends ((...args: any[]) => any) | _ | unset = unset> = PartialApply<ParameterFn, [fn, N]>;
type ReturnImpl<fn> = fn extends (...args: any[]) => infer ret ? ret : never;
/**
* Returns the return type of a function.
*
* @param fn - The function to extract the return type from.
* @returns The return type of the function.
*
* @example
* ```ts
* type T0 = Call<Return, (a: number, b: string) => number>; // number
* type T1 = Eval<Return<(a: number, b: string) => number>>; // number
* ```
*/
export interface Return extends Fn {

@@ -27,2 +77,14 @@ return: ReturnImpl<this["arg0"]>;

] ? ComposeImpl<rest, [Apply<last, args>]> : Head<args>;
/**
* Composes a list of functions into a single function that passes the result of each function to the next.
* Executes the functions from right to left.
*
* @param fns - The list of functions to compose.
* @returns The composed function.
*
* @example
* ```ts
* type T0 = Call<Compose< [T.Join<'-'>,S.Split<'.'> ]>, 'a.b.c'>; // 'a-b-c'
* ```
*/
export interface Compose<fns extends Fn[]> extends Fn {

@@ -35,5 +97,29 @@ return: ComposeImpl<fns, this["args"]>;

] ? ComposeLeftImpl<rest, [Apply<first, args>]> : Head<args>;
/**
* Composes a list of functions into a single function that passes the result of each function to the next.
* Executes the functions from left to right.
*
* @param fns - The list of functions to compose.
* @returns The composed function.
*
* @example
* ```ts
* type T0 = Call<ComposeLeft< [S.Split<'.'>,T.Join<'-'> ]>, 'a.b.c'>; // 'a-b-c'
* ```
*/
export interface ComposeLeft<fns extends Fn[]> extends Fn {
return: ComposeLeftImpl<fns, this["args"]>;
}
/**
* Partially applies the passed arguments to the function and returns a new function.
* The new function will have the applied arguments passed to the original function
*
* @param fn - The function to partially apply.
* @param partialArgs - The arguments to partially apply.
* @returns The partially applied function.
*
* @example
* ```ts
* type T0 = Call<PartialApply<Parameter, [_, (a: number, b: string) => void]>, 1> ; // [b: string]
*/
export interface PartialApply<fn extends Fn, partialArgs extends unknown[]> extends Fn {

@@ -40,0 +126,0 @@ return: MergeArgs<this["args"], partialArgs> extends infer args extends unknown[] ? Apply<fn, args> : never;

2

dist/internals/functions/impl/MergeArgs.d.ts

@@ -7,3 +7,3 @@ import { unset, _ } from "../../core/Core";

] ? first extends _ ? ExcludePlaceholders<rest, output> : ExcludePlaceholders<rest, [...output, first]> : output;
type MergeArgsRec<pipedArgs extends any[], partialArgs extends any[], output extends any[] = []> = partialArgs extends [infer partialFirst, ...infer partialRest] ? [partialFirst] extends [never] ? MergeArgsRec<pipedArgs, partialRest, [...output, partialFirst]> : [partialFirst] extends [_] ? pipedArgs extends [infer pipedFirst, ...infer pipedRest] ? MergeArgsRec<pipedRest, partialRest, [...output, pipedFirst]> : [...output, ...ExcludePlaceholders<partialRest>] : MergeArgsRec<pipedArgs, partialRest, [...output, partialFirst]> : [...output, ...pipedArgs];
type MergeArgsRec<pipedArgs extends any[], partialArgs extends any[], output extends any[] = []> = partialArgs extends [infer partialFirst, ...infer partialRest] ? IsNever<partialFirst> extends true ? MergeArgsRec<pipedArgs, partialRest, [...output, partialFirst]> : [partialFirst] extends [_] ? pipedArgs extends [infer pipedFirst, ...infer pipedRest] ? MergeArgsRec<pipedRest, partialRest, [...output, pipedFirst]> : [...output, ...ExcludePlaceholders<partialRest>] : MergeArgsRec<pipedArgs, partialRest, [...output, partialFirst]> : [...output, ...pipedArgs];
type EmptyIntoPlaceholder<x> = IsNever<x> extends true ? never : [x] extends [unset] ? _ : x;

@@ -10,0 +10,0 @@ type MapEmptyIntoPlaceholder<xs, output extends any[] = []> = xs extends [

@@ -28,11 +28,12 @@ import { Digit, Digits, TrimZeros } from "../utils";

*/
export type DivModDigits<A extends Digit[], D extends Digit[], M extends Digit[], Q extends Digit[] = []> = DivModByDigit<D, M> extends {
export type _DivModDigits<A extends Digit[], D extends Digit[], M extends Digit[], Q extends Digit[] = []> = DivModByDigit<D, M> extends {
Quotient: infer B extends Digit;
Remainder: infer R extends Digit[];
} ? A extends [infer A1 extends Digit, ...infer AR extends Digit[]] ? DivModDigits<AR, TrimZeros<[...R, A1]>, M, [...Q, B]> : {
} ? A extends [infer A1 extends Digit, ...infer AR extends Digit[]] ? _DivModDigits<AR, TrimZeros<[...R, A1]>, M, [...Q, B]> : {
Quotient: [...Q, B];
Remainder: R;
} : never;
export type DivDigits<N extends Digit[], M extends Digit[]> = TruncateWith<N, M> extends [infer A extends Digit[], infer D extends Digit[]] ? DivModDigits<A, D, M>["Quotient"] : never;
export type ModDigits<N extends Digit[], M extends Digit[]> = TruncateWith<N, M> extends [infer A extends Digit[], infer D extends Digit[]] ? DivModDigits<A, D, M>["Remainder"] : never;
export type DivDigits<N extends Digit[], M extends Digit[]> = TruncateWith<N, M> extends [infer A extends Digit[], infer D extends Digit[]] ? _DivModDigits<A, D, M>["Quotient"] : never;
export type ModDigits<N extends Digit[], M extends Digit[]> = TruncateWith<N, M> extends [infer A extends Digit[], infer D extends Digit[]] ? _DivModDigits<A, D, M>["Remainder"] : never;
export type DivModDigits<N extends Digit[], M extends Digit[]> = TruncateWith<N, M> extends [infer A extends Digit[], infer D extends Digit[]] ? _DivModDigits<A, D, M> : never;
export {};
import { Digit, TrimZeros } from "../utils";
import { DivModDigits } from "./division";
import { _DivModDigits } from "./division";
import { MulDigits } from "./multiply";
export type PowerDigits<T extends Digit[], U extends Digit[], Acc extends Digit[] = [1]> = U extends [0] ? [1] : U extends [1] ? MulDigits<T, Acc> : U extends [infer UN extends Digit, ...infer UR extends Digit[]] ? DivModDigits<UR, [UN], [2]> extends {
export type PowerDigits<T extends Digit[], U extends Digit[], Acc extends Digit[] = [1]> = U extends [0] ? [1] : U extends [1] ? MulDigits<T, Acc> : U extends [infer UN extends Digit, ...infer UR extends Digit[]] ? _DivModDigits<UR, [UN], [2]> extends {
Quotient: infer Q extends Digit[];
Remainder: infer R extends Digit[];
} ? TrimZeros<R> extends [0] ? PowerDigits<MulDigits<T, T>, TrimZeros<Q>, Acc> : PowerDigits<MulDigits<T, T>, TrimZeros<Q>, MulDigits<T, Acc>> : never : Acc;

@@ -1,3 +0,3 @@

import { ToNumber, MakeDigitNumber, FromDigitNumber, Normalize, DigitNumber, Sign, Num, ToDigitNumber, ToString, MulSign } from "./utils";
import { DivDigits, ModDigits } from "./digits/division";
import { ToNumber, MakeDigitNumber, FromDigitNumber, Normalize, DigitNumber, Sign, Num, ToDigitNumber, ToString, MulSign, Digit } from "./utils";
import { DivDigits, ModDigits, DivModDigits } from "./digits/division";
export type DivDigitNumbers<T extends DigitNumber, U extends DigitNumber> = MakeDigitNumber<MulSign<Sign<T>, Sign<U>>, DivDigits<Num<T>, Num<U>>>;

@@ -7,1 +7,15 @@ export type Div<T extends number | bigint, U extends number | bigint> = ToNumber<FromDigitNumber<Normalize<DivDigitNumbers<ToDigitNumber<ToString<T>>, ToDigitNumber<ToString<U>>>>>>;

export type Mod<T extends number | bigint, U extends number | bigint> = ToNumber<FromDigitNumber<Normalize<ModDigitNumbers<ToDigitNumber<ToString<T>>, ToDigitNumber<ToString<U>>>>>>;
export type DivModDigitNumbers<T extends DigitNumber, U extends DigitNumber, DivMod extends {
Quotient: Digit[];
Remainder: Digit[];
} = DivModDigits<Num<T>, Num<U>>> = {
Quotient: MakeDigitNumber<MulSign<Sign<T>, Sign<U>>, DivMod["Quotient"]>;
Remainder: MakeDigitNumber<Sign<T>, DivMod["Remainder"]>;
};
export type DivMod<T extends number | bigint, U extends number | bigint, DivModNumbers extends {
Quotient: DigitNumber;
Remainder: DigitNumber;
} = DivModDigitNumbers<ToDigitNumber<ToString<T>>, ToDigitNumber<ToString<U>>>> = {
Quotient: ToNumber<FromDigitNumber<Normalize<DivModNumbers["Quotient"]>>>;
Remainder: ToNumber<FromDigitNumber<Normalize<DivModNumbers["Remainder"]>>>;
};

@@ -1,2 +0,8 @@

import * as H from "../../helpers";
export type Repeat<str, n extends any[], acc extends string = ""> = H.Iterator.Get<n> extends 0 ? acc : str extends string ? Repeat<str, H.Iterator.Prev<n>, `${str}${acc}`> : never;
import { DivMod } from "../../numbers/impl/division";
import { Sub } from "../../numbers/impl/substraction";
type RepeatX2<T extends string> = `${T}${T}`;
export type Repeat<T extends string, N extends number, Acc extends string = "", Calc extends {
Quotient: number;
Remainder: number;
} = DivMod<N, 2>> = N extends 0 ? Acc : N extends 1 ? `${Acc}${T}` : Calc["Remainder"] extends 0 ? Repeat<RepeatX2<T>, Calc["Quotient"], Acc> : Repeat<T, Sub<N, 1>, `${Acc}${T}`>;
export {};

@@ -6,1 +6,2 @@ export * from "./split";

export * from "./compare";
export * from "./length";

@@ -20,4 +20,14 @@ import { Fn, unset, _ } from "../core/Core";

export type Length<Str = unset> = Functions.PartialApply<LengthFn, [Str]>;
/**
* Get the length of a string.
* @warning - 🔥🔥🔥does not work with emojis since they are multiple characters🔥🔥🔥
* @param args[0] - The string to get the length of.
* @returns The length of the string.
* @example
* ```ts
* type T0 = Call<Strings.Length,"abc">; // 3
* ```
*/
export interface LengthFn extends Fn {
return: Impl.StringToTuple<this["arg0"]>["length"];
return: this["arg0"] extends string ? Impl.Length<this["arg0"]> : never;
}

@@ -138,3 +148,3 @@ /**

*/
export type Repeat<Times extends number | _ | unset = unset, Str extends number | _ | unset = unset> = Functions.PartialApply<RepeatFn, [Times, Str]>;
export type Repeat<Times extends number | _ | unset = unset, Str extends string | _ | unset = unset> = Functions.PartialApply<RepeatFn, [Times, Str]>;
interface RepeatFn extends Fn {

@@ -144,3 +154,3 @@ return: this["args"] extends [

infer Str extends string
] ? Impl.Repeat<Str, H.Iterator.Iterator<Times>> : never;
] ? Impl.Repeat<Str, Times> : never;
}

@@ -147,0 +157,0 @@ /**

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";

@@ -105,5 +106,2 @@ import { Iterator, Stringifiable } from "../helpers";

}
interface MapReducer<fn extends Fn> extends Fn {
return: this["args"] extends [infer acc extends any[], infer item] ? [...acc, Call<fn, item>] : never;
}
/**

@@ -122,3 +120,8 @@ * Apply a function to each element of a tuple and return a new tuple with the results.

interface MapFn extends Fn {
return: ReduceImpl<this["arg1"], [], MapReducer<Extract<this["arg0"], Fn>>>;
return: this["args"] extends [
infer fn extends Fn,
infer tuple extends unknown[]
] ? {
[key in keyof tuple]: Call<fn, tuple[key]>;
} : never;
}

@@ -473,3 +476,28 @@ interface FlatMapReducer<fn extends Fn> extends Fn {

export type ZipWith<fn extends Fn, arr1 extends unknown[] | _ | unset = unset, arr2 extends unknown[] | _ | unset = unset> = Functions.PartialApply<ZipWithFn<fn>, [arr1, arr2]>;
/**
* Range takes a `start` and an `end` integer and produces
* a tuple containing integer ranging from `start` to `end`
* @param start - the start of the range (included)
* @param end - the end of the range (included)
* @returns a tuple of integers
* @example
* ```ts
* type T0 = Call<Tuples.Range<3>, 7>; // [3, 4, 5, 6, 7]
* type T1 = Eval<Tuples.Range<_, 10>, 5>; // [5, 6, 7, 8, 9, 10]
* type T3 = Eval<Tuples.Range< -2, 2>, 5>; // [-2, 1, 0, 1, 2]
* type T4 = Eval<Tuples.Range< -5, -2>, 5>; // [-5, -4, -3, -2]
* ```
*/
export type Range<start extends number | _ | unset = unset, end extends number | _ | unset = unset> = Functions.PartialApply<RangeFn, [start, end]>;
interface RangeFn extends Fn {
return: this["args"] extends [
infer start extends number,
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;
}
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"]>
]>;
export {};
}

@@ -1,4 +0,5 @@

import { Call, Fn, unset } from "../core/Core";
import { Call, Eval, Fn, unset, _ } from "../core/Core";
import { Functions } from "../functions/Functions";
import { Std } from "../std/Std";
import { Tuples } from "../tuples/Tuples";
export declare namespace Unions {

@@ -29,3 +30,24 @@ export type Extract<unionOrExtracted = unset, extracted = unset> = Functions.PartialApply<ExtractFn, extracted extends unset ? [unset, unionOrExtracted] : [unionOrExtracted, extracted]>;

}
/**
* `Unions.Range` takes a `start` and an `end` integer and produces
* a union containing integer ranging from `start` to `end`
* @param start - the start of the range (included)
* @param end - the end of the range (included)
* @returns a union of integers
* @example
* ```ts
* type T0 = Call<Unions.Range<3>, 7>; // 3 | 4 | 5 | 6 | 7
* type T1 = Eval<Unions.Range<_, 10>, 5>; // 5 | 6 | 7 | 8 | 9 | 10
* type T3 = Eval<Unions.Range< -2, 2>, 5>; // -2 | 1 | 0 | 1 | 2
* type T4 = Eval<Unions.Range< -5, -2>, 5>; // -5 | -4 | -3 | -2
* ```
*/
export type Range<start extends number | _ | unset = unset, end extends number | _ | unset = unset> = Functions.PartialApply<RangeFn, [start, end]>;
interface RangeFn extends Fn {
return: this["args"] extends [
infer start extends number,
infer end extends number
] ? Eval<Tuples.Range<start, end>>[number] : never;
}
export {};
}
{
"name": "hotscript",
"version": "1.0.3",
"version": "1.0.4",
"description": "Type-level madness",

@@ -5,0 +5,0 @@ "type": "module",

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