@arktype/util
Advanced tools
Comparing version 0.1.2 to 0.2.1
@@ -0,2 +1,9 @@ | ||
/** Shallowly copy the properties and prototype of the object. | ||
* | ||
* NOTE: this still cannot guarantee arrow functions attached to the object | ||
* are rebound in case they reference `this`. | ||
* | ||
* See: https://x.com/colinhacks/status/1818422039210049985 | ||
*/ | ||
export declare const shallowClone: <input extends object>(input: input) => input; | ||
export declare const deepClone: <input>(input: input) => input; |
@@ -1,2 +0,12 @@ | ||
export const shallowClone = (input) => Object.create(Object.getPrototypeOf(input), Object.getOwnPropertyDescriptors(input)); | ||
/** Shallowly copy the properties and prototype of the object. | ||
* | ||
* NOTE: this still cannot guarantee arrow functions attached to the object | ||
* are rebound in case they reference `this`. | ||
* | ||
* See: https://x.com/colinhacks/status/1818422039210049985 | ||
*/ | ||
export const shallowClone = (input) => { | ||
const cloned = Object.create(Object.getPrototypeOf(input), Object.getOwnPropertyDescriptors(input)); | ||
return cloned; | ||
}; | ||
export const deepClone = (input) => _deepClone(input, new Map()); | ||
@@ -3,0 +13,0 @@ const _deepClone = (input, seen) => { |
import type { array } from "./arrays.js"; | ||
import type { describeDomainOf, domainOf, inferDomain } from "./domain.js"; | ||
import type { isAny, isNever, satisfy, Stringifiable } from "./generics.js"; | ||
import type { anyOrNever, satisfy, Stringifiable } from "./generics.js"; | ||
import type { describeObject } from "./objectKinds.js"; | ||
@@ -10,3 +10,6 @@ import type { stringifyUnion } from "./unionToTuple.js"; | ||
}; | ||
export type typeToString<t, opts extends DescribeOptions = {}> = stringifyUnion<isAny<t> extends true ? "any" : isNever<t> extends true ? "never" : unknown extends t ? "unknown" : boolean extends t ? "boolean" | ([t] extends [boolean] ? never : typeToString<Exclude<t, boolean>, opts>) : t extends array ? arrayTypeToString<t, opts> : t extends object ? describeObject<t, opts> : t extends Stringifiable ? inferDomain<domainOf<t>> extends t ? describeDomainOf<t, opts> : `${t}` : describeDomainOf<t, opts>, opts["branchDelimiter"] extends string ? opts["branchDelimiter"] : describeDefaults["branchDelimiter"]>; | ||
export type typeToString<t, opts extends DescribeOptions = {}> = stringifyUnion<[ | ||
t | ||
] extends [anyOrNever] ? unknown extends t ? "any" : "never" : unknown extends t ? "unknown" : boolean extends t ? "boolean" | ([t] extends [boolean] ? never : typeToString<Exclude<t, boolean>, opts>) : t extends array ? arrayTypeToString<t, opts> : t extends object ? describeObject<t, opts> : t extends Stringifiable ? stringifiableToString<t, opts> : describeDomainOf<t, opts>, opts["branchDelimiter"] extends string ? opts["branchDelimiter"] : describeDefaults["branchDelimiter"]>; | ||
type stringifiableToString<t extends Stringifiable, opts extends DescribeOptions> = inferDomain<domainOf<t>> extends t ? describeDomainOf<t, opts> : `${t}`; | ||
export type describe<t> = typeToString<t, { | ||
@@ -13,0 +16,0 @@ includeArticles: true; |
@@ -23,3 +23,7 @@ import type { describeDefaults, DescribeOptions } from "./describe.js"; | ||
export declare const domainOf: <data>(data: data) => domainOf<data>; | ||
declare const nonEnumerableDomainDescriptions: { | ||
/** Each domain's completion for the phrase "must be _____" */ | ||
export declare const domainDescriptions: { | ||
readonly boolean: "boolean"; | ||
readonly null: "null"; | ||
readonly undefined: "undefined"; | ||
readonly bigint: "a bigint"; | ||
@@ -31,16 +35,4 @@ readonly number: "a number"; | ||
}; | ||
export type NonEnumerableDomain = keyof typeof nonEnumerableDomainDescriptions; | ||
/** Each domain's completion for the phrase "must be _____" */ | ||
export declare const domainDescriptions: { | ||
boolean: "boolean"; | ||
null: "null"; | ||
undefined: "undefined"; | ||
bigint: "a bigint"; | ||
number: "a number"; | ||
object: "an object"; | ||
string: "a string"; | ||
symbol: "a symbol"; | ||
}; | ||
export type domainDescriptions = typeof domainDescriptions; | ||
export type describeDomainOf<t, opts extends DescribeOptions = {}> = stringifyUnion<opts["includeArticles"] extends true ? domainDescriptions[domainOf<t>] : domainOf<t>, opts["branchDelimiter"] extends string ? opts["branchDelimiter"] : describeDefaults["branchDelimiter"]>; | ||
export {}; |
@@ -11,8 +11,7 @@ export const hasDomain = (data, kind) => domainOf(data) === kind; | ||
}; | ||
const enumerableDomainDescriptions = { | ||
/** Each domain's completion for the phrase "must be _____" */ | ||
export const domainDescriptions = { | ||
boolean: "boolean", | ||
null: "null", | ||
undefined: "undefined" | ||
}; | ||
const nonEnumerableDomainDescriptions = { | ||
undefined: "undefined", | ||
bigint: "a bigint", | ||
@@ -24,6 +23,1 @@ number: "a number", | ||
}; | ||
/** Each domain's completion for the phrase "must be _____" */ | ||
export const domainDescriptions = { | ||
...nonEnumerableDomainDescriptions, | ||
...enumerableDomainDescriptions | ||
}; |
@@ -1,2 +0,2 @@ | ||
import type { id } from "./generics.js"; | ||
import type { keyNonimal } from "./generics.js"; | ||
export declare class InternalArktypeError extends Error { | ||
@@ -10,6 +10,23 @@ } | ||
export declare const throwParseError: (message: string) => never; | ||
export type ZeroWidthSpace = " "; | ||
/** | ||
* TypeScript won't suggest strings beginning with a space as properties. | ||
* Useful for symbol-like string properties. | ||
*/ | ||
export declare const noSuggest: <s extends string>(s: s) => noSuggest<s>; | ||
/** | ||
* TypeScript won't suggest strings beginning with a space as properties. | ||
* Useful for symbol-like string properties. | ||
*/ | ||
export type noSuggest<s extends string = string> = ` ${s}`; | ||
/** "Hair Space" character, used as a non-rendered sentinel for an error message string: | ||
* https://www.compart.com/en/unicode/U+200A | ||
*/ | ||
export declare const zeroWidthSpace = "\u200A"; | ||
/** "Hair Space" character, used as a non-rendered sentinel for an error message string: | ||
* https://www.compart.com/en/unicode/U+200A | ||
*/ | ||
export type ZeroWidthSpace = typeof zeroWidthSpace; | ||
export type ErrorMessage<message extends string = string> = `${message}${ZeroWidthSpace}`; | ||
export interface ErrorType<message extends string = string, ctx extends {} = {}> { | ||
[id]: "ErrorObject"; | ||
[keyNonimal]: "ErrorObject"; | ||
message: message; | ||
@@ -16,0 +33,0 @@ ctx: ctx; |
@@ -11,1 +11,10 @@ export class InternalArktypeError extends Error { | ||
export const throwParseError = message => throwError(message, ParseError); | ||
/** | ||
* TypeScript won't suggest strings beginning with a space as properties. | ||
* Useful for symbol-like string properties. | ||
*/ | ||
export const noSuggest = (s) => ` ${s}`; | ||
/** "Hair Space" character, used as a non-rendered sentinel for an error message string: | ||
* https://www.compart.com/en/unicode/U+200A | ||
*/ | ||
export const zeroWidthSpace = " "; |
@@ -18,3 +18,3 @@ import { NoopBase } from "./records.js"; | ||
}; | ||
/** @ts-expect-error required to cast function type */ | ||
/** @ts-ignore required to cast function type */ | ||
export declare class Callable<f extends (...args: never[]) => unknown, attachments extends object = {}> extends NoopBase<f & attachments> { | ||
@@ -24,2 +24,3 @@ constructor(f: f, ...[opts]: {} extends attachments ? [opts?: CallableOptions<attachments>] : [opts: CallableOptions<attachments>]); | ||
export type Guardable<input = unknown, narrowed extends input = input> = ((In: input) => In is narrowed) | ((In: input) => boolean); | ||
export type TypeGuard<input = unknown, narrowed extends input = input> = (In: input) => In is narrowed; | ||
/** | ||
@@ -26,0 +27,0 @@ * Checks if the environment has Content Security Policy (CSP) enabled, |
@@ -47,3 +47,3 @@ import { throwInternalError } from "./errors.js"; | ||
}; | ||
/** @ts-expect-error required to cast function type */ | ||
/** @ts-ignore required to cast function type */ | ||
export class Callable extends NoopBase { | ||
@@ -50,0 +50,0 @@ constructor(f, ...[opts]) { |
@@ -5,7 +5,3 @@ import type { Primitive } from "./domain.js"; | ||
export type Stringifiable = string | boolean | number | bigint | null | undefined; | ||
/** | ||
* Force an operation like `{ a: 0 } & { b: 1 }` to be computed so that it displays `{ a: 0; b: 1 }`. | ||
* | ||
* Also works for some non-intersections, e.g. `keyof SomeObj` => `"a" | "b" | ...` | ||
*/ | ||
/** Force an operation like `{ a: 0 } & { b: 1 }` to be computed so that it displays `{ a: 0; b: 1 }`. */ | ||
export type show<t> = { | ||
@@ -31,15 +27,21 @@ [k in keyof t]: t[k]; | ||
export type andPreserveUnknown<l, r> = unknown extends l & r ? unknown : show<l & r>; | ||
declare const anyOrNever: unique symbol; | ||
export type anyOrNever = typeof anyOrNever; | ||
export type isAny<t> = 0 extends 1 & t ? true : false; | ||
export type isNever<t> = [t] extends [never] ? true : false; | ||
export type isUnknown<t> = unknown extends t ? [ | ||
t | ||
] extends [{}] ? false : true : false; | ||
/** Can be used to test for the universal subtypes, `any` and `never`, e.g.: | ||
* | ||
* ```ts | ||
* type isAnyOrNever<t> = [t] extends [anyOrNever] ? true : false | ||
* ``` | ||
* | ||
* The actual value is a string literal, but the only realistic subtypes | ||
* of that literal are `any` and `never`. | ||
*/ | ||
export type anyOrNever = " anyOrNever"; | ||
export type conform<t, base> = t extends base ? t : base; | ||
export type equals<l, r> = [l, r] extends [r, l] ? true : false; | ||
export type exactEquals<l, r> = (<_>() => _ extends l ? 1 : 2) extends <_>() => _ extends r ? 1 : 2 ? true : false; | ||
export declare const id: unique symbol; | ||
/** You can avoid suggesting completions by prefixing a string key with whitespace. | ||
* Isn't that keyNominal? | ||
*/ | ||
export declare const keyNonimal = " keyNonimal"; | ||
export type nominal<t, id extends string> = t & { | ||
readonly [id]: id; | ||
readonly [keyNonimal]: id; | ||
}; | ||
@@ -46,0 +48,0 @@ export type satisfy<base, t extends base> = t; |
@@ -1,2 +0,5 @@ | ||
export const id = Symbol("id"); | ||
/** You can avoid suggesting completions by prefixing a string key with whitespace. | ||
* Isn't that keyNominal? | ||
*/ | ||
export const keyNonimal = " keyNonimal"; | ||
export const narrow = (t) => t; |
@@ -1,39 +0,25 @@ | ||
import type { conform } from "./generics.js"; | ||
export type instantiate<hkt extends Hkt.Instantiable, args extends Parameters<hkt[Hkt.instantiate]>[0]> = ReturnType<(hkt & { | ||
readonly [Hkt.args]: args; | ||
})[Hkt.instantiate]>; | ||
/** A small set of HKT utility types based on https://github.com/poteat/hkt-toolbelt */ | ||
declare const args = "~args"; | ||
type args = typeof args; | ||
export declare abstract class Hkt<constraints extends unknown[] = any> { | ||
[args]: unknown[]; | ||
constraints: constraints; | ||
args: this[args] extends infer args extends unknown[] ? args : never; | ||
0: this[args] extends [infer arg, ...any] ? arg : never; | ||
1: this[args] extends [any, infer arg, ...any] ? arg : never; | ||
2: this[args] extends [any, any, infer arg, ...any] ? arg : never; | ||
3: this[args] extends [any, any, any, infer arg, ...any] ? arg : never; | ||
abstract body: unknown; | ||
} | ||
/** A small set of HKT utility types based on https://github.com/gvergnaud/hotscript | ||
* See https://github.com/gvergnaud/hotscript/blob/main/src/internals/core/Core.ts | ||
*/ | ||
export declare namespace Hkt { | ||
export const args: unique symbol; | ||
export type args = typeof args; | ||
export const instantiate: unique symbol; | ||
export type instantiate = typeof instantiate; | ||
export abstract class Kind<hkt extends (...args: any[]) => unknown = (...args: any[]) => unknown> { | ||
readonly [args]: unknown; | ||
abstract readonly hkt: hkt; | ||
} | ||
export abstract class Instantiable { | ||
readonly [args]: unknown; | ||
abstract readonly [instantiate]: (...args: never[]) => Instantiable; | ||
} | ||
export type apply<hkt extends Kind, args extends Parameters<hkt["hkt"]>[0]> = ReturnType<(hkt & { | ||
readonly [args]: args; | ||
})["hkt"]>; | ||
export interface Reify extends Kind { | ||
hkt(In: conform<this[args], Kind>): reify<typeof In>; | ||
} | ||
export const reify: <def extends Kind>(def: def) => reify<def>; | ||
export type reify<hkt extends Kind> = <const In extends Parameters<hkt["hkt"]>[0]>(In: In) => Hkt.apply<hkt, In>; | ||
export abstract class UnaryKind<hkt extends (In: never) => unknown = (In: any) => unknown> { | ||
readonly [args]: unknown; | ||
abstract readonly hkt: hkt; | ||
} | ||
type validatePipedKinds<kinds extends UnaryKind[], Out = Parameters<kinds[0]["hkt"]>[0]> = kinds extends (readonly [infer head extends UnaryKind, ...infer tail extends UnaryKind[]]) ? Out extends Parameters<head["hkt"]>[0] ? [ | ||
kinds[0], | ||
...validatePipedKinds<tail, Hkt.apply<head, Out>> | ||
] : [Kind<(In: Out) => unknown>, ...tail] : []; | ||
type inferPipedReturn<kinds extends UnaryKind[], Out> = kinds extends (readonly [infer head extends UnaryKind, ...infer tail extends UnaryKind[]]) ? inferPipedReturn<tail, Hkt.apply<head, Out>> : Out; | ||
export type pipe<kinds extends UnaryKind[]> = <In extends Parameters<kinds[0]["hkt"]>[0]>(In: In) => inferPipedReturn<kinds, In>; | ||
export const pipe: <kinds extends UnaryKind[], validatedKinds extends UnaryKind[] = validatePipedKinds<kinds, Parameters<kinds[0]["hkt"]>[0]>>(...kinds: { [i in keyof kinds]: conform<kinds[i], validatedKinds[i & keyof validatedKinds]>; }) => pipe<kinds>; | ||
export {}; | ||
type constructor<constraints extends unknown[] = any> = new () => Hkt<constraints>; | ||
type args = typeof args; | ||
type apply<hkt extends Hkt, args extends { | ||
[i in keyof args]: hkt["constraints"][i]; | ||
}> = (hkt & { | ||
[args]: args; | ||
})["body"]; | ||
} | ||
export {}; |
@@ -1,15 +0,3 @@ | ||
/** A small set of HKT utility types based on https://github.com/poteat/hkt-toolbelt */ | ||
export var Hkt; | ||
(function (Hkt) { | ||
class Kind { | ||
} | ||
Hkt.Kind = Kind; | ||
class Instantiable { | ||
} | ||
Hkt.Instantiable = Instantiable; | ||
Hkt.reify = (def) => def.hkt; | ||
class UnaryKind { | ||
} | ||
Hkt.UnaryKind = UnaryKind; | ||
Hkt.pipe = (...kinds) => In => kinds.reduce((out, kind) => kind.hkt(out), In); | ||
})(Hkt || (Hkt = {})); | ||
const args = "~args"; | ||
export class Hkt { | ||
} |
import type { array } from "./arrays.js"; | ||
import type { domainOf } from "./domain.js"; | ||
import type { andPreserveUnknown, conform } from "./generics.js"; | ||
import type { andPreserveUnknown } from "./generics.js"; | ||
import type { Hkt } from "./hkt.js"; | ||
import type { propValueOf, requiredKeyOf } from "./records.js"; | ||
export interface AndPreserveUnknown extends Hkt.Kind { | ||
hkt: (args: conform<this[Hkt.args], [unknown, unknown]>) => andPreserveUnknown<(typeof args)[0], (typeof args)[1]>; | ||
export interface AndPreserveUnknown extends Hkt<[unknown, unknown]> { | ||
body: andPreserveUnknown<this[0], this[1]>; | ||
} | ||
type SequenceIntersectionKind = "array" | "parameters"; | ||
export type intersectArrays<l extends array, r extends array, operator extends Hkt.Kind = AndPreserveUnknown> = intersectSequences<l, r, [], [], operator, "array">; | ||
export type intersectParameters<l extends array, r extends array, operator extends Hkt.Kind = AndPreserveUnknown> = intersectSequences<l, r, [], [], operator, "parameters">; | ||
type intersectSequences<l extends array, r extends array, acc extends array, postfix extends array, operation extends Hkt.Kind, kind extends SequenceIntersectionKind> = l extends readonly [] ? kind extends "array" ? [ | ||
export type intersectArrays<l extends array, r extends array, operator extends Hkt = AndPreserveUnknown> = intersectSequences<l, r, [], [], operator, "array">; | ||
export type intersectParameters<l extends array, r extends array, operator extends Hkt = AndPreserveUnknown> = intersectSequences<l, r, [], [], operator, "parameters">; | ||
type intersectSequences<l extends array, r extends array, acc extends array, postfix extends array, operation extends Hkt, kind extends SequenceIntersectionKind> = l extends readonly [] ? kind extends "array" ? [ | ||
] extends r ? [ | ||
@@ -14,0 +14,0 @@ ...acc, |
export type Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9; | ||
export type NumberLiteral<value extends number = number> = `${value}`; | ||
export type BigintLiteral<value extends bigint = bigint> = `${value}n`; | ||
export type NumberLiteral<n extends number = number> = `${n}`; | ||
export type BigintLiteral<n extends bigint = bigint> = `${n}n`; | ||
export type IntegerLiteral<n extends bigint = bigint> = `${n}`; | ||
export type NonNegativeIntegerLiteral<n extends bigint = bigint> = `${Digit}` | (`${Exclude<Digit, 0>}${string}` & `${n}`); | ||
/** | ||
@@ -5,0 +7,0 @@ * The goal of the number literal and bigint literal regular expressions is to: |
@@ -32,3 +32,3 @@ import { domainOf } from "./domain.js"; | ||
export const objectKindOrDomainOf = (data) => (typeof data === "object" && data !== null ? | ||
objectKindOf(data) ?? "object" | ||
(objectKindOf(data) ?? "object") | ||
: domainOf(data)); | ||
@@ -35,0 +35,0 @@ export const hasObjectKind = (data, kind) => objectKindOf(data) === kind; |
@@ -69,3 +69,11 @@ import type { array } from "./arrays.js"; | ||
export type optionalKeyOf<o> = Exclude<keyof o, requiredKeyOf<o>>; | ||
export type merge<base, merged> = show<Omit<base, keyof merged> & merged>; | ||
export type merge<base, props> = base extends unknown ? props extends unknown ? show<omit<base, keyof props & keyof base> & props> : never : never; | ||
export type mergeExact<base, props> = base extends unknown ? props extends unknown ? show<omitMerged<base, props> & props> : never : never; | ||
type omitMerged<base, props> = { | ||
[k in keyof base as excludeExactKeyOf<k, props>]: base[k]; | ||
}; | ||
type excludeExactKeyOf<key extends PropertyKey, o> = Exclude<key, extractExactKeyOf<key, o>>; | ||
type extractExactKeyOf<key extends PropertyKey, base> = keyof { | ||
[k in keyof base as [key, k] extends [k, key] ? key : never]: 1; | ||
}; | ||
export type override<base, merged extends { | ||
@@ -76,12 +84,42 @@ [k in keyof base]?: unknown; | ||
export declare const InnerDynamicBase: new <t extends object>(base: t) => t; | ||
/** @ts-expect-error (needed to extend `t`, but safe given ShallowClone's implementation) **/ | ||
/** @ts-ignore (needed to extend `t`, but safe given ShallowClone's implementation) **/ | ||
export declare class DynamicBase<t extends object> extends InnerDynamicBase<t> { | ||
} | ||
export declare const NoopBase: new <t extends object>() => t; | ||
/** @ts-expect-error (see DynamicBase) **/ | ||
/** @ts-ignore (see DynamicBase) **/ | ||
export declare class CastableBase<t extends object> extends NoopBase<t> { | ||
} | ||
export declare const splitByKeys: <o extends object, leftKeys extends keySetOf<o>>(o: o, leftKeys: leftKeys) => [show<Pick<o, keyof leftKeys & keyof o>>, show<Omit<o, keyof leftKeys & keyof o>>]; | ||
export declare const pick: <o extends object, keys extends keySetOf<o>>(o: o, keys: keys) => show<Pick<o, keyof keys & keyof o>>; | ||
export declare const omit: <o extends object, keys extends keySetOf<o>>(o: o, keys: keys) => show<Omit<o, keyof keys>>; | ||
/** Homomorphic implementation of the builtin Pick. | ||
* | ||
* Gives different results for certain union expressions like the following: | ||
* | ||
* @example | ||
* // flattens result to { a?: 1 | 2; b?: 1 | 2 } | ||
* type PickResult = Pick<{ a: 1; b?: 1 } | { a?: 2; b: 2 }, "a" | "b"> | ||
* | ||
* @example | ||
* // preserves original type w/ modifier groupings | ||
* type pickResult = pick<{ a: 1; b?: 1 } | { a?: 2; b: 2 }, "a" | "b"> | ||
*/ | ||
export type pick<o, key extends keyof o> = o extends unknown ? { | ||
[k in keyof o as k extends key ? k : never]: o[k]; | ||
} : never; | ||
export declare const pick: <o extends object, keys extends keySetOf<o>>(o: o, keys: keys) => pick<o, keyof keys & keyof o>; | ||
/** Homomorphic implementation of the builtin Omit. | ||
* | ||
* Gives different results for many union expressions like the following: | ||
* | ||
* @example | ||
* // {} | ||
* type OmitResult = Omit<{ a: 1 } | { b: 2 }, never> | ||
* | ||
* @example | ||
* // preserves original type w/ modifier groupings | ||
* type omitResult = omit<{ a: 1 } | { b: 2 }, never> | ||
*/ | ||
export type omit<o, key extends keyof o> = { | ||
[k in keyof o as k extends key ? never : k]: o[k]; | ||
}; | ||
export declare const omit: <o extends object, keys extends keySetOf<o>>(o: o, keys: keys) => omit<o, keyof keys & keyof o>; | ||
export type EmptyObject = Record<PropertyKey, never>; | ||
@@ -88,0 +126,0 @@ export declare const isEmptyObject: (o: object) => o is EmptyObject; |
@@ -14,3 +14,3 @@ import { flatMorph } from "./flatMorph.js"; | ||
}; | ||
/** @ts-expect-error (needed to extend `t`, but safe given ShallowClone's implementation) **/ | ||
/** @ts-ignore (needed to extend `t`, but safe given ShallowClone's implementation) **/ | ||
export class DynamicBase extends InnerDynamicBase { | ||
@@ -20,3 +20,3 @@ } | ||
}; | ||
/** @ts-expect-error (see DynamicBase) **/ | ||
/** @ts-ignore (see DynamicBase) **/ | ||
export class CastableBase extends NoopBase { | ||
@@ -23,0 +23,0 @@ } |
@@ -1,3 +0,2 @@ | ||
import type { PartialRecord } from "./records.js"; | ||
export declare const arkUtilVersion = "0.1.2"; | ||
export declare const arkUtilVersion = "0.2.1"; | ||
export declare const initialRegistryContents: { | ||
@@ -8,9 +7,12 @@ version: string; | ||
export type InitialRegistryContents = typeof initialRegistryContents; | ||
export declare const $ark: ArkEnv.registry; | ||
export interface ArkRegistry extends InitialRegistryContents { | ||
[k: string]: unknown; | ||
} | ||
export declare const registry: ArkRegistry; | ||
declare global { | ||
export interface ArkEnv { | ||
registry(): {}; | ||
prototypes(): never; | ||
} | ||
export namespace ArkEnv { | ||
type registry = PartialRecord<string, object | symbol> & InitialRegistryContents & ReturnType<ArkEnv["registry"]>; | ||
type prototypes = ReturnType<ArkEnv["prototypes"]>; | ||
} | ||
@@ -17,0 +19,0 @@ } |
@@ -8,3 +8,3 @@ import { domainOf } from "./domain.js"; | ||
// For now, we assert this matches the package.json version via a unit test. | ||
export const arkUtilVersion = "0.1.2"; | ||
export const arkUtilVersion = "0.2.1"; | ||
export const initialRegistryContents = { | ||
@@ -14,3 +14,3 @@ version: arkUtilVersion, | ||
}; | ||
export const $ark = initialRegistryContents; | ||
export const registry = initialRegistryContents; | ||
const namesByResolution = new WeakMap(); | ||
@@ -27,3 +27,3 @@ const nameCounts = {}; | ||
nameCounts[name] = 1; | ||
$ark[name] = value; | ||
registry[name] = value; | ||
namesByResolution.set(value, name); | ||
@@ -30,0 +30,0 @@ return name; |
@@ -18,3 +18,3 @@ import type { array } from "./arrays.js"; | ||
}; | ||
/** @ts-expect-error required to extend NoopBase */ | ||
/** @ts-ignore required to extend NoopBase */ | ||
export declare abstract class Trait<d extends TraitDeclaration = {}, abstractMethods extends object = d["abstractMethods"] & {}, abstractProps extends object = d["abstractProps"] & {}, abstractStatics extends object = d["abstractStatics"] & {}, dynamicBase extends object = d["dynamicBase"] & {}> extends NoopBase<abstractMethods & abstractProps & dynamicBase> { | ||
@@ -21,0 +21,0 @@ abstractMethods: abstractMethods; |
@@ -16,3 +16,3 @@ import { hasDomain } from "./domain.js"; | ||
}; | ||
/** @ts-expect-error required to extend NoopBase */ | ||
/** @ts-ignore required to extend NoopBase */ | ||
export class Trait extends NoopBase { | ||
@@ -19,0 +19,0 @@ static get [Symbol.hasInstance]() { |
@@ -10,4 +10,5 @@ import type { array, join } from "./arrays.js"; | ||
export type intersectUnion<t> = (t extends unknown ? (_: t) => void : never) extends ((_: infer intersection) => void) ? intersection : never; | ||
export type intersectOverloadReturns<f extends (...args: never[]) => unknown> = intersectUnion<ReturnType<overloadOf<f>>>; | ||
export type overloadOf<f extends (...args: never[]) => unknown, givenArgs extends array = array> = Exclude<collectSignatures<(() => never) & f, givenArgs, unknown>, f extends () => never ? never : () => never>; | ||
type collectSignatures<f, givenArgs extends array, result> = result & f extends (...args: infer args) => infer returns ? result extends f ? never : collectSignatures<f, givenArgs, Pick<f, keyof f> & result & ((...args: args) => returns)> | (args extends givenArgs ? (...args: args) => returns : never) : never; | ||
export {}; |
{ | ||
"name": "@arktype/util", | ||
"version": "0.1.2", | ||
"version": "0.2.1", | ||
"author": { | ||
@@ -5,0 +5,0 @@ "name": "David Blass", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
79796
47
1629