Comparing version 0.1.0 to 0.1.1
@@ -0,1 +1,3 @@ | ||
import type { Guardable } from "./functions.js"; | ||
import type { anyOrNever } from "./generics.js"; | ||
import type { isDisjoint } from "./intersections.js"; | ||
@@ -24,5 +26,8 @@ import type { parseNonNegativeInteger } from "./numericLiterals.js"; | ||
export type numericStringKeyOf<t extends array> = Extract<keyof t, `${number}`>; | ||
export type indexOf<a extends array> = keyof a extends infer k ? parseNonNegativeInteger<k & string> : never; | ||
export declare const arrayFrom: <t>(data: t) => t extends array ? [t] extends [null] ? t[] : t : t[]; | ||
export declare const spliterate: <item, included extends item>(list: readonly item[], by: (item: item) => item is included) => [included: included[], excluded: Exclude<item, included>[]]; | ||
export type arrayIndexOf<a extends array> = keyof a extends infer k ? parseNonNegativeInteger<k & string> : never; | ||
export type liftArray<t> = t extends array ? [ | ||
t | ||
] extends [anyOrNever] ? t[] : t : t[]; | ||
export declare const liftArray: <t>(data: t) => liftArray<t>; | ||
export declare const spliterate: <item, included extends item>(list: readonly item[], by: Guardable<item, included>) => [included: included[], excluded: item extends included ? item[] : Exclude<item, included>[]]; | ||
export declare const ReadonlyArray: new <T>(...args: ConstructorParameters<typeof Array<T>>) => ReadonlyArray<T>; | ||
@@ -29,0 +34,0 @@ export declare const includes: <a extends array>(array: a, element: unknown) => element is a[number]; |
@@ -18,3 +18,3 @@ export const join = (segments, delimiter) => segments.join(delimiter); | ||
}; | ||
export const arrayFrom = (data) => (Array.isArray(data) ? data : [data]); | ||
export const liftArray = (data) => (Array.isArray(data) ? data : [data]); | ||
export const spliterate = (list, by) => { | ||
@@ -64,3 +64,3 @@ const result = [[], []]; | ||
if (to === undefined || to === null) | ||
return arrayFrom(elementOrList); | ||
return liftArray(elementOrList); | ||
return to.concat(elementOrList); | ||
@@ -86,3 +86,3 @@ }; | ||
const isEqual = opts?.isEqual ?? ((l, r) => l === r); | ||
arrayFrom(value).forEach(v => { | ||
liftArray(value).forEach(v => { | ||
if (!to.some(existing => isEqual(existing, v))) | ||
@@ -89,0 +89,0 @@ to.push(v); |
@@ -20,3 +20,3 @@ import { NoopBase } from "./records.js"; | ||
export declare class Callable<f extends (...args: never[]) => unknown, attachments extends object = {}> extends NoopBase<f & attachments> { | ||
constructor(f: f, opts?: CallableOptions<attachments>); | ||
constructor(f: f, ...[opts]: {} extends attachments ? [opts?: CallableOptions<attachments>] : [opts: CallableOptions<attachments>]); | ||
} | ||
@@ -23,0 +23,0 @@ export type Guardable<input = unknown, narrowed extends input = input> = ((In: input) => In is narrowed) | ((In: input) => boolean); |
@@ -49,3 +49,3 @@ import { throwInternalError } from "./errors.js"; | ||
export class Callable extends NoopBase { | ||
constructor(f, opts) { | ||
constructor(f, ...[opts]) { | ||
super(); | ||
@@ -52,0 +52,0 @@ return Object.assign(Object.setPrototypeOf(f.bind(opts?.bind ?? this), this.constructor.prototype), opts?.attach); |
export * from "./arrays.js"; | ||
export * from "./clone.js"; | ||
export * from "./compilation.js"; | ||
export * from "./describe.js"; | ||
@@ -5,0 +4,0 @@ export * from "./domain.js"; |
export * from "./arrays.js"; | ||
export * from "./clone.js"; | ||
export * from "./compilation.js"; | ||
export * from "./describe.js"; | ||
@@ -5,0 +4,0 @@ export * from "./domain.js"; |
import type { PartialRecord } from "./records.js"; | ||
export declare const arkUtilVersion = "0.1.1"; | ||
export declare const initialRegistryContents: { | ||
version: string; | ||
filename: string; | ||
}; | ||
export type InitialRegistryContents = typeof initialRegistryContents; | ||
export declare const $ark: ArkEnv.registry; | ||
declare global { | ||
export const $ark: ArkEnv.registry; | ||
export interface ArkEnv { | ||
@@ -8,11 +14,6 @@ registry(): {}; | ||
export namespace ArkEnv { | ||
type registry = PartialRecord<string, object | symbol> & ReturnType<ArkEnv["registry"]>; | ||
type registry = PartialRecord<string, object | symbol> & InitialRegistryContents & ReturnType<ArkEnv["registry"]>; | ||
} | ||
} | ||
export declare const registry: Record<string, unknown>; | ||
export declare const register: (value: object | symbol) => string; | ||
export declare const reference: (name: string) => RegisteredReference; | ||
export declare const registeredReference: (value: object | symbol) => RegisteredReference; | ||
export type RegisteredReference<to extends string = string> = `$ark.${to}`; | ||
export declare const isDotAccessible: (keyName: string) => boolean; | ||
export declare const compileSerializedValue: (value: unknown) => string; |
@@ -1,13 +0,14 @@ | ||
import { domainOf, hasDomain } from "./domain.js"; | ||
import { throwError, throwInternalError } from "./errors.js"; | ||
import { domainOf } from "./domain.js"; | ||
import { throwInternalError } from "./errors.js"; | ||
import { objectKindOf } from "./objectKinds.js"; | ||
import { serializePrimitive } from "./primitive.js"; | ||
if ("$ark" in globalThis) { | ||
throwError(`Tried to initialize an $ark registry but one already existed. | ||
This probably means you are either depending on multiple versions of an arktype package, | ||
or importing the same package from both ESM and CJS. | ||
Review package.json versions across your repo to ensure consistency.`); | ||
} | ||
export const registry = {}; | ||
globalThis.$ark = registry; | ||
// Eventually we can just import from package.json in the source itself | ||
// but for now, import assertions are too unstable and it wouldn't support | ||
// recent node versions (https://nodejs.org/api/esm.html#json-modules). | ||
// For now, we assert this matches the package.json version via a unit test. | ||
export const arkUtilVersion = "0.1.1"; | ||
export const initialRegistryContents = { | ||
version: arkUtilVersion, | ||
filename: import.meta.filename | ||
}; | ||
export const $ark = initialRegistryContents; | ||
const namesByResolution = new WeakMap(); | ||
@@ -24,12 +25,7 @@ const nameCounts = {}; | ||
nameCounts[name] = 1; | ||
registry[name] = value; | ||
$ark[name] = value; | ||
namesByResolution.set(value, name); | ||
return name; | ||
}; | ||
export const reference = (name) => `$ark.${name}`; | ||
export const registeredReference = (value) => reference(register(value)); | ||
export const isDotAccessible = (keyName) => /^[a-zA-Z_$][a-zA-Z_$0-9]*$/.test(keyName); | ||
export const compileSerializedValue = (value) => hasDomain(value, "object") || typeof value === "symbol" ? | ||
registeredReference(value) | ||
: serializePrimitive(value); | ||
const baseNameFor = (value) => { | ||
@@ -36,0 +32,0 @@ switch (typeof value) { |
{ | ||
"name": "@ark/util", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"author": { | ||
@@ -5,0 +5,0 @@ "name": "David Blass", |
Sorry, the diff of this file is not supported yet
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
77102
45
1556