@cometjs/core
Advanced tools
Comparing version
# @cometjs/core | ||
## 2.1.1 | ||
### Patch Changes | ||
- cef0284: Fix tuple helpers stability | ||
## 2.1.0 | ||
@@ -4,0 +10,0 @@ |
@@ -15,3 +15,3 @@ /** | ||
*/ | ||
export declare type Primitive = (null | undefined | boolean | string | number | bigint | symbol); | ||
export type Primitive = (null | undefined | boolean | string | number | bigint | symbol); | ||
/** | ||
@@ -22,3 +22,3 @@ * Alternative to `any` | ||
*/ | ||
export declare type InferrableAny = Primitive | object; | ||
export type InferrableAny = Primitive | object; | ||
/** | ||
@@ -28,28 +28,28 @@ * Simulate Flow's `$NonMaybeType<mixed>`. | ||
*/ | ||
export declare type NonMaybeType = {}; | ||
export type NonMaybeType = {}; | ||
/** | ||
* Strict presentation of empty object | ||
*/ | ||
export declare type EmptyObject = Record<string, never>; | ||
export type EmptyObject = Record<string, never>; | ||
/** | ||
* Strict presentation of any object | ||
*/ | ||
export declare type AnyObject = Record<string, unknown>; | ||
export type AnyObject = Record<string, unknown>; | ||
/** | ||
* Safely intersect prop types | ||
*/ | ||
export declare type OverrideProps<TBaseProps, TNewProps> = Omit<TBaseProps, keyof TNewProps> & TNewProps; | ||
export type OverrideProps<TBaseProps, TNewProps> = Omit<TBaseProps, keyof TNewProps> & TNewProps; | ||
/** | ||
* Well-known `U<T>`-like nominal types | ||
*/ | ||
export declare type BoxType<T = any> = (Promise<T> | Array<T> | Set<T>); | ||
export type BoxType<T = any> = (Promise<T> | Array<T> | Set<T>); | ||
/** | ||
* Unwrap BoxType<T>. | ||
*/ | ||
export declare type Unwrap<T> = (T extends Promise<infer U> ? U : T extends Array<infer U> ? U : T extends Set<infer U> ? U : never); | ||
export type Unwrap<T> = (T extends Promise<infer U> ? U : T extends Array<infer U> ? U : T extends Set<infer U> ? U : never); | ||
/** | ||
* Wrap T by BoxType. | ||
*/ | ||
export declare type Wrap<T, Box extends BoxType> = (Box extends Promise<any> ? Promise<T> : Box extends Array<any> ? Array<T> : Box extends Set<any> ? Set<T> : never); | ||
export declare type OneOrMany<T> = T | T[]; | ||
export type Wrap<T, Box extends BoxType> = (Box extends Promise<any> ? Promise<T> : Box extends Array<any> ? Array<T> : Box extends Set<any> ? Set<T> : never); | ||
export type OneOrMany<T> = T | T[]; | ||
/** | ||
@@ -61,7 +61,7 @@ * Check type-level equally of given two types. | ||
*/ | ||
export declare type IfEquals<X, Y, A = X, B = never> = ((<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? A : B); | ||
export type IfEquals<X, Y, A = X, B = never> = ((<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? A : B); | ||
/** | ||
* @see https://stackoverflow.com/a/49725198/5734400 | ||
*/ | ||
export declare type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = (Pick<T, Exclude<keyof T, Keys>> & { | ||
export type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = (Pick<T, Exclude<keyof T, Keys>> & { | ||
[K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>; | ||
@@ -72,3 +72,3 @@ }[Keys]); | ||
*/ | ||
export declare type RequireOnlyOne<T, Keys extends keyof T = keyof T> = (Pick<T, Exclude<keyof T, Keys>> & { | ||
export type RequireOnlyOne<T, Keys extends keyof T = keyof T> = (Pick<T, Exclude<keyof T, Keys>> & { | ||
[K in Keys]-?: (Required<Pick<T, K>> & Partial<Record<Exclude<Keys, K>, undefined>>); | ||
@@ -75,0 +75,0 @@ }[Keys]); |
import type { InferrableAny } from './common'; | ||
import * as Fn from './function'; | ||
export declare type Falsy = (false | null | undefined | 0 | -0 | 0n | ''); | ||
export declare type Truthy<X = InferrableAny> = Exclude<X, Falsy>; | ||
export declare type T<X> = (Truthy<X> | Falsy); | ||
export type Falsy = (false | null | undefined | 0 | -0 | 0n | ''); | ||
export type Truthy<X = InferrableAny> = Exclude<X, Falsy>; | ||
export type T<X> = (Truthy<X> | Falsy); | ||
export declare function isTruthy<X>(condition: T<X>): condition is Truthy<X>; | ||
@@ -7,0 +7,0 @@ export declare function isFalsy<X>(condition: T<X>): condition is Falsy; |
@@ -1,4 +0,4 @@ | ||
export declare type T<Y, X = any> = (Y | ((domain: X) => Y)); | ||
export declare type Domain<TFn> = TFn extends ((x: infer X) => any) ? X : void; | ||
export declare type Range<TFn> = TFn extends T<infer R> ? R : never; | ||
export type T<Y, X = any> = (Y | ((domain: X) => Y)); | ||
export type Domain<TFn> = TFn extends ((x: infer X) => any) ? X : void; | ||
export type Range<TFn> = TFn extends T<infer R> ? R : never; | ||
/** | ||
@@ -12,2 +12,2 @@ * Returns result of function, or value as-is. | ||
export declare function range<R, X = any>(fn: T<R, X>, ...arg: [X?] | []): R; | ||
export declare type MergeRange<TFunction> = TFunction extends Record<string, T<unknown>> ? Range<TFunction[keyof TFunction]> : TFunction extends Array<T<unknown>> ? Range<TFunction[number]> : never; | ||
export type MergeRange<TFunction> = TFunction extends Record<string, T<unknown>> ? Range<TFunction[keyof TFunction]> : TFunction extends Array<T<unknown>> ? Range<TFunction[number]> : never; |
@@ -1,4 +0,4 @@ | ||
export declare type SerializableValue = (null | number | string | boolean | SerializableValue[] | SerializableObject); | ||
export declare type SerializableObject = { | ||
export type SerializableValue = (null | number | string | boolean | SerializableValue[] | SerializableObject); | ||
export type SerializableObject = { | ||
[x: string]: SerializableValue; | ||
}; |
import * as Fn from './function'; | ||
export declare type None = null | undefined; | ||
export declare type Some<X> = Exclude<X, None>; | ||
export declare type T<X> = Some<X> | None; | ||
export type None = null | undefined; | ||
export type Some<X> = Exclude<X, None>; | ||
export type T<X> = Some<X> | None; | ||
export declare function of<X>(x: Fn.T<X>): T<X>; | ||
@@ -6,0 +6,0 @@ /** |
@@ -5,5 +5,5 @@ import type { Callable, Unwrap } from './common'; | ||
declare const s_err: unique symbol; | ||
export declare type Ok<T> = [typeof s_ok, T]; | ||
export declare type Err<T = unknown> = [typeof s_err, T]; | ||
export declare type T<TOk, TError = unknown> = Ok<TOk> | Err<TError>; | ||
export type Ok<T> = [typeof s_ok, T]; | ||
export type Err<T = unknown> = [typeof s_err, T]; | ||
export type T<TOk, TError = unknown> = Ok<TOk> | Err<TError>; | ||
export declare function ok<TOk = void>(t: TOk | void): Ok<TOk>; | ||
@@ -10,0 +10,0 @@ export declare function err<TError = void>(t: TError | void): Err<TError>; |
import type { Wrap, Unwrap, BoxType } from './common'; | ||
export declare type Head<Tuple extends readonly any[]> = (Tuple['length'] extends 0 ? never : Tuple[0]); | ||
export declare type Tail<Tuple extends readonly any[]> = (((...tail: Tuple) => any) extends ((head: any, ...tail: infer Tail) => any) ? Tail : never); | ||
declare namespace $Variadic { | ||
type Head<Tuple extends readonly unknown[]> = (Tuple extends [infer Head, ...any] ? Head : never); | ||
type Tail<Tuple extends readonly unknown[]> = (Tuple extends [any?, ...infer Tail] ? Tail : never); | ||
} | ||
export declare type Append<Tuple extends readonly any[], Item> = [...Tuple, Item]; | ||
export declare type Prepend<Tuple extends readonly any[], Item> = [Item, ...Tuple]; | ||
export declare type MapPromise<Tuple extends readonly any[], Result extends readonly any[] = []> = { | ||
export type Head<Tuple extends readonly any[]> = (Tuple['length'] extends 0 ? never : Tuple[0]); | ||
export type Tail<Tuple extends readonly any[]> = (((...tail: Tuple) => any) extends ((head: any, ...tail: infer Tail) => any) ? Tail : never); | ||
export type Append<Tuple extends readonly any[], Item> = [...Tuple, Item]; | ||
export type Prepend<Tuple extends readonly any[], Item> = [Item, ...Tuple]; | ||
export type MapPromise<Tuple extends readonly any[], Result extends readonly any[] = []> = { | ||
0: Result; | ||
1: MapPromise<$Variadic.Tail<Tuple>, Append<Result, Promise<$Variadic.Head<Tuple>>>>; | ||
1: MapPromise<Tail<Tuple>, Append<Result, Promise<Head<Tuple>>>>; | ||
}[Tuple['length'] extends 0 ? 0 : 1]; | ||
export declare type MapReturnType<Tuple extends readonly any[], Result extends readonly any[] = []> = { | ||
export type MapReturnType<Tuple extends readonly any[], Result extends readonly any[] = []> = { | ||
0: Result; | ||
1: MapReturnType<$Variadic.Tail<Tuple>, Append<Result, ReturnType<Head<Tuple>>>>; | ||
1: MapReturnType<Tail<Tuple>, Append<Result, ReturnType<Head<Tuple>>>>; | ||
}[Tuple['length'] extends 0 ? 0 : 1]; | ||
export declare type MapPick<Tuple extends readonly any[], Key extends string, Result extends readonly any[] = []> = { | ||
export type MapPick<Tuple extends readonly any[], Key extends string, Result extends readonly any[] = []> = { | ||
0: Result; | ||
1: MapPick<$Variadic.Tail<Tuple>, Key, Append<Result, Pick<Head<Tuple>, Key>>>; | ||
1: MapPick<Tail<Tuple>, Key, Append<Result, Pick<Head<Tuple>, Key>>>; | ||
}[Tuple['length'] extends 0 ? 0 : 1]; | ||
export declare type MapUnwrap<Tuple extends readonly any[], Result extends readonly any[] = []> = { | ||
export type MapUnwrap<Tuple extends readonly any[], Result extends readonly any[] = []> = { | ||
0: Result; | ||
1: MapUnwrap<$Variadic.Tail<Tuple>, Append<Result, Unwrap<$Variadic.Head<Tuple>>>>; | ||
1: MapUnwrap<Tail<Tuple>, Append<Result, Unwrap<Head<Tuple>>>>; | ||
}[Tuple['length'] extends 0 ? 0 : 1]; | ||
export declare type MapWrap<Tuple extends readonly any[], Box extends BoxType<any>, Result extends readonly any[] = []> = { | ||
export type MapWrap<Tuple extends readonly any[], Box extends BoxType<any>, Result extends readonly any[] = []> = { | ||
0: Result; | ||
1: MapWrap<$Variadic.Tail<Tuple>, Box, Append<Result, Wrap<$Variadic.Head<Tuple>, Box>>>; | ||
1: MapWrap<Tail<Tuple>, Box, Append<Result, Wrap<Head<Tuple>, Box>>>; | ||
}[Tuple['length'] extends 0 ? 0 : 1]; | ||
@@ -35,4 +31,4 @@ /** | ||
*/ | ||
export declare type T<X, N extends number> = N extends N ? number extends N ? X[] : _T<X, N> : never; | ||
declare type _T<X, N extends number> = MakeTuple<X, N>; | ||
export type T<X, N extends number> = N extends N ? number extends N ? X[] : _T<X, N> : never; | ||
type _T<X, N extends number> = MakeTuple<X, N>; | ||
/** | ||
@@ -42,10 +38,10 @@ * Credits to [Gal Schlezinger](https://github.com/schniz) | ||
*/ | ||
declare type MakeTuple<X, N extends number, Result extends readonly X[] = []> = { | ||
type MakeTuple<X, N extends number, Result extends readonly X[] = []> = { | ||
0: Result; | ||
1: MakeTuple<X, N, [X, ...Result]>; | ||
}[Result['length'] extends N ? 0 : 1]; | ||
export declare type Replace<Tuple extends readonly any[], X, Result extends readonly X[] = []> = { | ||
export type Replace<Tuple extends readonly any[], X, Result extends readonly X[] = []> = { | ||
0: Result; | ||
1: Replace<$Variadic.Tail<Tuple>, X, [X, ...Result]>; | ||
1: Replace<Tail<Tuple>, X, [X, ...Result]>; | ||
}[Tuple['length'] extends 0 ? 0 : 1]; | ||
export {}; |
{ | ||
"name": "@cometjs/core", | ||
"description": "cometjs core utilities", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"license": "MIT", | ||
@@ -17,3 +17,2 @@ "homepage": "https://github.com/cometkim/cometjs/tree/main/packages/core", | ||
"sideEffects": false, | ||
"source": "./src/index.ts", | ||
"main": "./lib/index.mjs", | ||
@@ -23,11 +22,12 @@ "types": "./lib/index.d.ts", | ||
"access": "public", | ||
"main": "./lib/index.mjs", | ||
"exports": { | ||
".": { | ||
"import": "./lib/index.mjs", | ||
"require": "./lib/index.cjs" | ||
}, | ||
"./package.json": "./package.json" | ||
} | ||
"main": "./lib/index.mjs" | ||
}, | ||
"exports": { | ||
".": { | ||
"types": "./lib/index.d.ts", | ||
"import": "./lib/index.mjs", | ||
"require": "./lib/index.cjs" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"browserslist": [ | ||
@@ -45,3 +45,3 @@ "defaults", | ||
"test": "vitest run", | ||
"build": "tsc --emitDeclarationOnly && nanobundle build --dts=false", | ||
"build": "nanobundle build", | ||
"prepack": "rm -rf lib && yarn build" | ||
@@ -59,14 +59,10 @@ }, | ||
"c8": "^7.11.0", | ||
"nanobundle": "^0.0.27", | ||
"typescript": "^4.6.2", | ||
"nanobundle": "^1.0.0-rc.8", | ||
"typescript": "^4.9.3", | ||
"vite": "^2.8.6", | ||
"vitest": "^0.6.0" | ||
}, | ||
"exports": { | ||
".": { | ||
"import": "./lib/index.mjs", | ||
"require": "./lib/index.cjs" | ||
}, | ||
"./package.json": "./package.json" | ||
"dependencies": { | ||
"tsconfck": "^2.0.1" | ||
} | ||
} |
@@ -30,18 +30,2 @@ import type { | ||
declare namespace $Variadic { | ||
// `Head<T>` and `Tail<T>` implementation using variadic tuple. | ||
// It's much simpler but type inference is uncertain compared to the old version. | ||
export type Head<Tuple extends readonly unknown[]> = ( | ||
Tuple extends [infer Head, ...any] | ||
? Head | ||
: never | ||
); | ||
export type Tail<Tuple extends readonly unknown[]> = ( | ||
Tuple extends [any?, ...infer Tail] | ||
? Tail | ||
: never | ||
); | ||
} | ||
export type Append< | ||
@@ -66,4 +50,4 @@ Tuple extends readonly any[], | ||
1: MapPromise< | ||
$Variadic.Tail<Tuple>, | ||
Append<Result, Promise<$Variadic.Head<Tuple>>> | ||
Tail<Tuple>, | ||
Append<Result, Promise<Head<Tuple>>> | ||
>, | ||
@@ -78,3 +62,3 @@ }[Tuple['length'] extends 0 ? 0 : 1]; | ||
1: MapReturnType< | ||
$Variadic.Tail<Tuple>, | ||
Tail<Tuple>, | ||
Append<Result, ReturnType<Head<Tuple>>> | ||
@@ -89,4 +73,5 @@ >, | ||
> = { | ||
0: Result, 1: MapPick< | ||
$Variadic.Tail<Tuple>, | ||
0: Result, | ||
1: MapPick< | ||
Tail<Tuple>, | ||
Key, | ||
@@ -103,4 +88,4 @@ Append<Result, Pick<Head<Tuple>, Key>> | ||
1: MapUnwrap< | ||
$Variadic.Tail<Tuple>, | ||
Append<Result, Unwrap<$Variadic.Head<Tuple>>> | ||
Tail<Tuple>, | ||
Append<Result, Unwrap<Head<Tuple>>> | ||
>, | ||
@@ -116,5 +101,5 @@ }[Tuple['length'] extends 0 ? 0 : 1]; | ||
1: MapWrap< | ||
$Variadic.Tail<Tuple>, | ||
Tail<Tuple>, | ||
Box, | ||
Append<Result, Wrap<$Variadic.Head<Tuple>, Box>> | ||
Append<Result, Wrap<Head<Tuple>, Box>> | ||
>, | ||
@@ -142,3 +127,3 @@ }[Tuple['length'] extends 0 ? 0 : 1]; | ||
0: Result, | ||
1: Replace<$Variadic.Tail<Tuple>, X, [X, ...Result]>, | ||
1: Replace<Tail<Tuple>, X, [X, ...Result]>, | ||
}[Tuple['length'] extends 0 ? 0 : 1]; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
75271
6.27%1260
52.17%2
100%+ Added
+ Added