Socket
Socket
Sign inDemoInstall

@arktype/util

Package Overview
Dependencies
Maintainers
1
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arktype/util - npm Package Compare versions

Comparing version 0.0.34 to 0.0.35

out/primitive.d.ts

12

compilation.ts
import { DynamicFunction } from "./functions.js"
import { CastableBase } from "./records.js"
import { isDotAccessible, reference } from "./registry.js"
import { isDotAccessible, registeredReference } from "./registry.js"

@@ -40,3 +40,3 @@ export type CoercibleValue = string | number | boolean | null | undefined

prop(key: PropertyKey, optional = false): string {
return literalPropAccess(key, optional)
return compileLiteralPropAccess(key, optional)
}

@@ -92,3 +92,3 @@

block(prefix: string, contents: (self: this) => this): this {
block(prefix: string, contents: (self: this) => this, suffix = ""): this {
this.line(`${prefix} {`)

@@ -98,3 +98,3 @@ this.indent()

this.dedent()
return this.line("}")
return this.line(`}${suffix}`)
}

@@ -117,3 +117,3 @@

export const literalPropAccess = (
export const compileLiteralPropAccess = (
key: PropertyKey,

@@ -129,5 +129,5 @@ optional = false

export const serializeLiteralKey = (key: PropertyKey): string =>
typeof key === "symbol" ? reference(key) : JSON.stringify(key)
typeof key === "symbol" ? registeredReference(key) : JSON.stringify(key)
export const indexPropAccess = (key: string, optional = false) =>
`${optional ? "?." : ""}[${key}]` as const

@@ -74,2 +74,6 @@ import type { Primitive } from "./domain.js"

export type keyError<message extends string> = ErrorMessage<message> & {
[id]: "KeyError"
}
export type satisfy<base, t extends base> = t

@@ -76,0 +80,0 @@

@@ -15,2 +15,3 @@ export * from "./arrays.js"

export * from "./objectKinds.js"
export * from "./primitive.js"
export * from "./records.js"

@@ -17,0 +18,0 @@ export * from "./registry.js"

@@ -177,8 +177,8 @@ import type { array } from "./arrays.js"

while (curr !== Object.prototype && curr !== null && curr !== undefined) {
for (const k of Object.getOwnPropertyNames(curr)) {
for (const k of Object.getOwnPropertyNames(curr))
if (k !== "constructor" && !result.includes(k)) result.push(k)
}
for (const symbol of Object.getOwnPropertySymbols(curr)) {
for (const symbol of Object.getOwnPropertySymbols(curr))
if (!result.includes(symbol)) result.push(symbol)
}
curr = Object.getPrototypeOf(curr)

@@ -185,0 +185,0 @@ }

@@ -25,5 +25,3 @@ import type { isDisjoint } from "./intersections.js";

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 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>[]];

@@ -75,4 +73,3 @@ export declare const ReadonlyArray: new <T>(...args: ConstructorParameters<typeof Array<T>>) => ReadonlyArray<T>;

} & unknown;
export declare const groupBy: <element, discriminator extends groupableKeyOf<element>>(array: readonly element[], discriminator: discriminator) => { [k in element[discriminator] & PropertyKey]?: element extends unknown ? isDisjoint<element[discriminator], k> extends true ? never : element[] : never; };
export declare const groupBy: <element, discriminator extends groupableKeyOf<element>>(array: readonly element[], discriminator: discriminator) => groupBy<element, discriminator>;
export {};
//# sourceMappingURL=arrays.d.ts.map

@@ -92,2 +92,1 @@ export const getPath = (root, path) => {

}, {});
//# sourceMappingURL=arrays.js.map
export declare const shallowClone: <input extends object>(input: input) => input;
export declare const deepClone: <input>(input: input, seen?: Map<any, any>) => input;
//# sourceMappingURL=clone.d.ts.map

@@ -20,2 +20,1 @@ export const shallowClone = (input) => Object.create(Object.getPrototypeOf(input), Object.getOwnPropertyDescriptors(input));

};
//# sourceMappingURL=clone.js.map

@@ -25,3 +25,3 @@ import { CastableBase } from "./records.js";

forIn(object: string, body: (self: this) => this): this;
block(prefix: string, contents: (self: this) => this): this;
block(prefix: string, contents: (self: this) => this, suffix?: string): this;
return(expression?: CoercibleValue): this;

@@ -32,5 +32,4 @@ compile<f extends (...args: {

}
export declare const literalPropAccess: (key: PropertyKey, optional?: boolean) => string;
export declare const compileLiteralPropAccess: (key: PropertyKey, optional?: boolean) => string;
export declare const serializeLiteralKey: (key: PropertyKey) => string;
export declare const indexPropAccess: (key: string, optional?: boolean) => `[${string}]` | `?.[${string}]`;
//# sourceMappingURL=compilation.d.ts.map
import { DynamicFunction } from "./functions.js";
import { CastableBase } from "./records.js";
import { isDotAccessible, reference } from "./registry.js";
import { isDotAccessible, registeredReference } from "./registry.js";
export class CompiledFunction extends CastableBase {

@@ -28,3 +28,3 @@ argNames;

prop(key, optional = false) {
return literalPropAccess(key, optional);
return compileLiteralPropAccess(key, optional);
}

@@ -66,3 +66,3 @@ index(key, optional = false) {

}
block(prefix, contents) {
block(prefix, contents, suffix = "") {
this.line(`${prefix} {`);

@@ -72,3 +72,3 @@ this.indent();

this.dedent();
return this.line("}");
return this.line(`}${suffix}`);
}

@@ -82,3 +82,3 @@ return(expression = "") {

}
export const literalPropAccess = (key, optional = false) => {
export const compileLiteralPropAccess = (key, optional = false) => {
if (typeof key === "string" && isDotAccessible(key))

@@ -88,4 +88,3 @@ return `${optional ? "?" : ""}.${key}`;

};
export const serializeLiteralKey = (key) => typeof key === "symbol" ? reference(key) : JSON.stringify(key);
export const serializeLiteralKey = (key) => typeof key === "symbol" ? registeredReference(key) : JSON.stringify(key);
export const indexPropAccess = (key, optional = false) => `${optional ? "?." : ""}[${key}]`;
//# sourceMappingURL=compilation.js.map

@@ -7,2 +7,1 @@ import type { describeDomainOf, domainOf, inferDomain } from "./domain.js";

export type describeExpression<t> = describe<t, " | ">;
//# sourceMappingURL=describe.d.ts.map

@@ -31,15 +31,5 @@ import type { show } from "./generics.js";

/** 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 declare const domainDescriptions: typeof domainDescriptions;
export type domainDescriptions = typeof domainDescriptions;
export type describeDomainOf<t> = stringifyUnion<domainDescriptions[domainOf<t>], " or ">;
export {};
//# sourceMappingURL=domain.d.ts.map

@@ -28,2 +28,1 @@ export const hasDomain = (data, kind) => domainOf(data) === kind;

};
//# sourceMappingURL=domain.js.map

@@ -12,2 +12,1 @@ export declare class InternalArktypeError extends Error {

export type Completion<text extends string = string> = `${text}${ZeroWidthSpace}${ZeroWidthSpace}`;
//# sourceMappingURL=errors.d.ts.map

@@ -11,2 +11,1 @@ export class InternalArktypeError extends Error {

export const throwParseError = message => throwError(message, ParseError);
//# sourceMappingURL=errors.js.map

@@ -31,2 +31,1 @@ import type { array, listable } from "./arrays.js";

export {};
//# sourceMappingURL=flatMorph.d.ts.map

@@ -20,2 +20,1 @@ // eslint-disable-next-line prefer-arrow-functions/prefer-arrow-functions

}
//# sourceMappingURL=flatMorph.js.map
import { NoopBase } from "./records.js";
export declare const cached: <T>(thunk: () => T) => (() => T);
export declare const isThunk: <value>(value: value) => value is Extract<value, Thunk<unknown>> extends never ? value & Thunk<unknown> : Extract<value, Thunk<unknown>>;
export declare const isThunk: <value>(value: value) => value is Extract<value, Thunk> extends never ? value & Thunk : Extract<value, Thunk>;
export type Thunk<ret = unknown> = () => ret;
export type thunkable<t> = t | Thunk<t>;
export declare const DynamicFunction: DynamicFunction;
export declare const DynamicFunction: new <f extends (...args: never[]) => unknown>(...args: ConstructorParameters<typeof Function>) => f & {
apply(thisArg: null, args: Parameters<f>): ReturnType<f>;
call(thisArg: null, ...args: Parameters<f>): ReturnType<f>;
};
export type DynamicFunction = new <f extends (...args: never[]) => unknown>(...args: ConstructorParameters<typeof Function>) => f & {

@@ -20,2 +23,1 @@ apply(thisArg: null, args: Parameters<f>): ReturnType<f>;

export type Guardable<input = unknown, narrowed extends input = input> = ((In: input) => In is narrowed) | ((In: input) => boolean);
//# sourceMappingURL=functions.d.ts.map

@@ -38,2 +38,1 @@ import { throwInternalError } from "./errors.js";

}
//# sourceMappingURL=functions.js.map

@@ -33,3 +33,3 @@ import type { Primitive } from "./domain.js";

export type equals<t, u> = (<_>() => _ extends t ? 1 : 2) extends <_>() => _ extends u ? 1 : 2 ? true : false;
export declare const id: unique symbol;
export declare const id: typeof id;
export type id = typeof id;

@@ -39,2 +39,5 @@ export type nominal<t, id extends string> = t & {

};
export type keyError<message extends string> = ErrorMessage<message> & {
[id]: "KeyError";
};
export type satisfy<base, t extends base> = t;

@@ -51,2 +54,1 @@ export type defined<t> = t & ({} | null);

export {};
//# sourceMappingURL=generics.d.ts.map
export const id = Symbol("id");
export const narrow = (t) => t;
//# sourceMappingURL=generics.js.map

@@ -40,2 +40,1 @@ import type { conform } from "./generics.js";

}
//# sourceMappingURL=hkt.d.ts.map

@@ -16,2 +16,1 @@ /** A small set of HKT utility types based on https://github.com/poteat/hkt-toolbelt */

})(Hkt || (Hkt = {}));
//# sourceMappingURL=hkt.js.map

@@ -89,2 +89,1 @@ import type { array } from "./arrays.js";

export {};
//# sourceMappingURL=intersections.d.ts.map
export declare const lazily: <t extends object>(thunk: () => t) => t;
//# sourceMappingURL=lazily.d.ts.map

@@ -17,2 +17,1 @@ export const lazily = (thunk) => {

};
//# sourceMappingURL=lazily.js.map

@@ -15,2 +15,3 @@ export * from "./arrays.js";

export * from "./objectKinds.js";
export * from "./primitive.js";
export * from "./records.js";

@@ -22,2 +23,1 @@ export * from "./registry.js";

export * from "./unionToTuple.js";
//# sourceMappingURL=main.d.ts.map

@@ -15,2 +15,3 @@ export * from "./arrays.js";

export * from "./objectKinds.js";
export * from "./primitive.js";
export * from "./records.js";

@@ -22,2 +23,1 @@ export * from "./registry.js";

export * from "./unionToTuple.js";
//# sourceMappingURL=main.js.map

@@ -28,14 +28,6 @@ export type Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;

type NumericLiteralKind = "number" | "bigint" | "integer";
declare const numericLiteralDescriptions: {
readonly number: "a number";
readonly bigint: "a bigint";
readonly integer: "an integer";
};
declare const numericLiteralDescriptions: typeof numericLiteralDescriptions;
type numericLiteralDescriptions = typeof numericLiteralDescriptions;
export type writeMalformedNumericLiteralMessage<def extends string, kind extends NumericLiteralKind> = `'${def}' was parsed as ${numericLiteralDescriptions[kind]} but could not be narrowed to a literal value. Avoid unnecessary leading or trailing zeros and other abnormal notation`;
export declare const writeMalformedNumericLiteralMessage: <def extends string, kind extends NumericLiteralKind>(def: def, kind: kind) => `'${def}' was parsed as ${{
readonly number: "a number";
readonly bigint: "a bigint";
readonly integer: "an integer";
}[kind]} but could not be narrowed to a literal value. Avoid unnecessary leading or trailing zeros and other abnormal notation`;
export declare const writeMalformedNumericLiteralMessage: <def extends string, kind extends NumericLiteralKind>(def: def, kind: kind) => writeMalformedNumericLiteralMessage<def, kind>;
export declare const tryParseNumber: <errorOnFail extends string | boolean>(token: string, options?: NumericParseOptions<errorOnFail>) => errorOnFail extends true | string ? number : number | undefined;

@@ -54,2 +46,1 @@ export type tryParseNumber<token extends string, messageOnFail extends string> = token extends `${infer n extends number}` ? number extends n ? writeMalformedNumericLiteralMessage<token, "number"> : n : messageOnFail;

export {};
//# sourceMappingURL=numericLiterals.d.ts.map

@@ -76,2 +76,1 @@ import { throwParseError } from "./errors.js";

};
//# sourceMappingURL=numericLiterals.js.map

@@ -44,3 +44,3 @@ import type { array } from "./arrays.js";

readonly Promise: PromiseConstructor;
}>(data: data, kinds?: kinds | undefined) => objectKindOf<data, kinds> | undefined;
}>(data: data, kinds?: kinds) => objectKindOf<data, kinds> | undefined;
export declare const objectKindOrDomainOf: <data, kinds extends ObjectKindSet = {

@@ -60,3 +60,3 @@ readonly Array: ArrayConstructor;

readonly Promise: PromiseConstructor;
}>(data: data, kinds?: kinds | undefined) => (objectKindOf<data & object, kinds> & {}) | domainOf<data>;
}>(data: data, kinds?: kinds) => (objectKindOf<data & object, kinds> & {}) | domainOf<data>;
export type objectKindOrDomainOf<data, kinds extends ObjectKindSet = BuiltinObjectConstructors> = data extends object ? objectKindOf<data, kinds> extends undefined ? "object" : objectKindOf<data, kinds> : domainOf<data>;

@@ -77,20 +77,6 @@ export declare const hasObjectKind: <kind extends keyof kinds, kinds extends ObjectKindSet = {

readonly Promise: PromiseConstructor;
}>(data: object, kind: kind, kinds?: kinds | undefined) => data is InstanceType<kinds[kind]>;
}>(data: object, kind: kind, kinds?: kinds) => data is InstanceType<kinds[kind]>;
export declare const isArray: (data: unknown) => data is array;
/** Each defaultObjectKind's completion for the phrase "must be _____" */
export declare const objectKindDescriptions: {
readonly Array: "an array";
readonly Function: "a function";
readonly Date: "a Date";
readonly RegExp: "a RegExp";
readonly Error: "an Error";
readonly Map: "a Map";
readonly Set: "a Set";
readonly String: "a String object";
readonly Number: "a Number object";
readonly Boolean: "a Boolean object";
readonly Promise: "a Promise";
readonly WeakMap: "a WeakMap";
readonly WeakSet: "a WeakSet";
};
export declare const objectKindDescriptions: typeof objectKindDescriptions;
export type objectKindDescriptions = typeof objectKindDescriptions;

@@ -113,2 +99,1 @@ export declare const getExactBuiltinConstructorName: (ctor: unknown) => BuiltinObjectKind | null;

export {};
//# sourceMappingURL=objectKinds.d.ts.map

@@ -83,10 +83,8 @@ import { domainOf } from "./domain.js";

while (curr !== Object.prototype && curr !== null && curr !== undefined) {
for (const k of Object.getOwnPropertyNames(curr)) {
for (const k of Object.getOwnPropertyNames(curr))
if (k !== "constructor" && !result.includes(k))
result.push(k);
}
for (const symbol of Object.getOwnPropertySymbols(curr)) {
for (const symbol of Object.getOwnPropertySymbols(curr))
if (!result.includes(symbol))
result.push(symbol);
}
curr = Object.getPrototypeOf(curr);

@@ -117,2 +115,1 @@ }

};
//# sourceMappingURL=objectKinds.js.map

@@ -43,3 +43,3 @@ import type { array } from "./arrays.js";

}>;
export declare const fromEntries: <const entries extends readonly Entry<PropertyKey, unknown>[]>(entries: entries) => { [entry in entries[number] as entry[0]]: entry[1]; } extends infer T ? { [k in keyof T]: { [entry in entries[number] as entry[0]]: entry[1]; }[k]; } : never;
export declare const fromEntries: <const entries extends readonly Entry<PropertyKey, unknown>[]>(entries: entries) => fromEntries<entries>;
/** Mimics the result of Object.keys(...) */

@@ -56,3 +56,3 @@ export type keysOf<o> = o extends array ? number extends o["length"] ? `${number}` : keyof o & `${number}` : {

}>;
export declare const hasKey: <o extends object, k extends unionKeyOf<o>>(o: o, k: k) => o is Extract<o, { [_ in k]?: unknown; }>;
export declare const hasKey: <o extends object, k extends unionKeyOf<o>>(o: o, k: k) => o is extractKeyed<o, k>;
export type extractDefinedKey<o extends object, k extends unionKeyOf<o>> = show<extractKeyed<o, k> & {

@@ -88,8 +88,8 @@ [_ in k]: {} | null;

}
export declare const splitByKeys: <o extends object, leftKeys extends keySetOf<o>>(o: o, leftKeys: leftKeys) => [Pick<o, keyof leftKeys & keyof o> extends infer T ? { [k in keyof T]: Pick<o, keyof leftKeys & keyof o>[k]; } : never, Omit<o, keyof leftKeys & keyof o> extends infer T_1 ? { [k_1 in keyof T_1]: Omit<o, keyof leftKeys & keyof o>[k_1]; } : never];
export declare const pick: <o extends object, keys extends keySetOf<o>>(o: o, keys: keys) => Pick<o, keyof keys & keyof o> extends infer T ? { [k in keyof T]: Pick<o, keyof keys & keyof o>[k]; } : never;
export declare const omit: <o extends object, keys extends keySetOf<o>>(o: o, keys: keys) => Omit<o, keyof keys> extends infer T ? { [k in keyof T]: Omit<o, keyof keys>[k]; } : never;
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>>;
export type EmptyObject = Record<PropertyKey, never>;
export declare const isEmptyObject: (o: object) => o is EmptyObject;
export declare const stringAndSymbolicEntriesOf: (o: Record<Key, unknown>) => Entry<Key>[];
export declare const stringAndSymbolicEntriesOf: (o: object) => Entry<Key>[];
/** Like Object.assign, but it will preserve getters instead of evaluating them. */

@@ -103,4 +103,3 @@ export declare const defineProperties: <base extends object, merged extends object>(base: base, merged: merged) => merge<base, merged>;

} & unknown;
export declare const invert: <t extends Record<PropertyKey, PropertyKey>>(t: t) => { [k in t[keyof t]]: { [k2 in keyof t]: t[k2] extends k ? k2 : never; }[keyof t]; };
export declare const invert: <t extends Record<PropertyKey, PropertyKey>>(t: t) => invert<t>;
export {};
//# sourceMappingURL=records.d.ts.map

@@ -46,2 +46,1 @@ import { flatMorph } from "./flatMorph.js";

export const invert = (t) => flatMorph(t, (k, v) => [v, k]);
//# sourceMappingURL=records.js.map

@@ -7,5 +7,6 @@ declare global {

export declare const registry: Record<string, unknown>;
export declare const reference: (value: object | symbol) => `$ark.${string}`;
export declare const register: (value: object | symbol) => string;
export declare const reference: (name: string) => `$ark.${string}`;
export declare const registeredReference: (value: object | symbol) => `$ark.${string}`;
export declare const isDotAccessible: (keyName: string) => boolean;
export declare const compileSerializedValue: (value: unknown) => string;
//# sourceMappingURL=registry.d.ts.map
import { domainOf, hasDomain } from "./domain.js";
import { throwInternalError } from "./errors.js";
import { objectKindOf } from "./objectKinds.js";
import { serializePrimitive } from "./serialize.js";
import { serializePrimitive } from "./primitive.js";
export const registry = {};

@@ -9,17 +9,21 @@ globalThis.$ark = registry;

const nameCounts = {};
export const reference = (value) => {
export const register = (value) => {
const existingName = namesByResolution.get(value);
if (existingName)
return `$ark.${existingName}`;
const baseName = baseNameFor(value);
nameCounts[baseName] ??= 1;
const uniqueName = `${baseName}${nameCounts[baseName]++}`;
registry[uniqueName] = value;
namesByResolution.set(value, uniqueName);
return `$ark.${uniqueName}`;
return existingName;
let name = baseNameFor(value);
if (nameCounts[name])
name = `${name}${nameCounts[name]++}`;
else
nameCounts[name] = 1;
registry[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) => {
return hasDomain(value, "object") || typeof value === "symbol" ?
reference(value)
registeredReference(value)
: serializePrimitive(value);

@@ -37,10 +41,9 @@ };

case "function":
return isDotAccessible(value.name) ? value.name : "anonymousFunction";
return isDotAccessible(value.name) ? value.name : "fn";
case "symbol":
return value.description && isDotAccessible(value.description) ?
value.description
: "anonymousSymbol";
: "symbol";
}
return throwInternalError(`Unexpected attempt to register serializable value of type ${domainOf(value)}`);
};
//# sourceMappingURL=registry.js.map
import type { array } from "./arrays.js";
import { type Primitive, type inferDomain } from "./domain.js";
import type { BigintLiteral } from "./numericLiterals.js";
import { type Primitive } from "./domain.js";
export type SerializationOptions = {

@@ -22,16 +21,2 @@ onCycle?: (value: object) => string;

export declare const printable: (data: unknown, indent?: number) => string;
type SerializedString<value extends string = string> = `"${value}"`;
export type SerializedPrimitives = {
string: SerializedString;
number: `${number}`;
bigint: BigintLiteral;
boolean: "true" | "false";
null: "null";
undefined: "undefined";
};
export type SerializedPrimitive = SerializedPrimitives[keyof SerializedPrimitives];
export type SerializablePrimitive = inferDomain<keyof SerializedPrimitives>;
export declare const serializePrimitive: <value extends string | number | bigint | boolean | null | undefined>(value: value) => serializePrimitive<value>;
export type serializePrimitive<value extends SerializablePrimitive> = value extends string ? `"${value}"` : value extends bigint ? `${value}n` : `${value}`;
export {};
//# sourceMappingURL=serialize.d.ts.map
import { domainOf } from "./domain.js";
import { serializePrimitive } from "./primitive.js";
import { register } from "./registry.js";
export const snapshot = (data, opts = { onUndefined: "(undefined)" }) => _serialize(data, opts, []);

@@ -18,4 +20,4 @@ export const print = (data, indent) => console.log(printable(data, indent));

onCycle: () => "(cycle)",
onSymbol: v => `(symbol ${v.description ?? "anonymous"})`,
onFunction: v => `(function ${v.name ?? "anonymous"})`
onSymbol: v => `Symbol(${register(v)})`,
onFunction: v => `Function(${register(v)})`
};

@@ -49,5 +51,1 @@ const _serialize = (data, opts, seen) => {

};
export const serializePrimitive = (value) => (typeof value === "string" ? JSON.stringify(value)
: typeof value === "bigint" ? `${value}n`
: `${value}`);
//# sourceMappingURL=serialize.js.map

@@ -6,2 +6,1 @@ export declare const capitalize: <s extends string>(s: s) => Capitalize<s>;

export type charsBeforeLast<s extends string> = s extends `${infer head}${infer tail}` ? tail extends "" ? "" : `${head}${charsBeforeLast<tail>}` : "";
//# sourceMappingURL=strings.d.ts.map
export const capitalize = (s) => (s[0].toUpperCase() + s.slice(1));
//# sourceMappingURL=strings.js.map

@@ -90,2 +90,1 @@ import type { array } from "./arrays.js";

export {};
//# sourceMappingURL=traits.d.ts.map

@@ -75,2 +75,1 @@ import { hasDomain } from "./domain.js";

};
//# sourceMappingURL=traits.js.map

@@ -13,2 +13,1 @@ import type { array, join } from "./arrays.js";

export {};
//# sourceMappingURL=unionToTuple.d.ts.map
{
"name": "@arktype/util",
"version": "0.0.34",
"version": "0.0.35",
"author": {

@@ -5,0 +5,0 @@ "name": "David Blass",

@@ -192,7 +192,5 @@ import type { array } from "./arrays.js"

export const stringAndSymbolicEntriesOf = (
o: Record<Key, unknown>
): Entry<Key>[] => [
export const stringAndSymbolicEntriesOf = (o: object): Entry<Key>[] => [
...Object.entries(o),
...Object.getOwnPropertySymbols(o).map(k => [k, o[k]] as const)
...Object.getOwnPropertySymbols(o).map(k => [k, (o as any)[k]] as const)
]

@@ -199,0 +197,0 @@

import { domainOf, hasDomain } from "./domain.js"
import { throwInternalError } from "./errors.js"
import { objectKindOf } from "./objectKinds.js"
import { type SerializablePrimitive, serializePrimitive } from "./serialize.js"
import { serializePrimitive, type SerializablePrimitive } from "./primitive.js"

@@ -18,14 +18,20 @@ declare global {

export const reference = (value: object | symbol): `$ark.${string}` => {
export const register = (value: object | symbol): string => {
const existingName = namesByResolution.get(value)
if (existingName) return `$ark.${existingName}`
if (existingName) return existingName
const baseName = baseNameFor(value)
nameCounts[baseName] ??= 1
const uniqueName = `${baseName}${nameCounts[baseName]!++}`
registry[uniqueName] = value
namesByResolution.set(value, uniqueName)
return `$ark.${uniqueName}`
let name = baseNameFor(value)
if (nameCounts[name]) name = `${name}${nameCounts[name]!++}`
else nameCounts[name] = 1
registry[name] = value
namesByResolution.set(value, name)
return name
}
export const reference = (name: string): `$ark.${string}` => `$ark.${name}`
export const registeredReference = (value: object | symbol): `$ark.${string}` =>
reference(register(value))
export const isDotAccessible = (keyName: string): boolean =>

@@ -36,3 +42,3 @@ /^[a-zA-Z_$][a-zA-Z_$0-9]*$/.test(keyName)

return hasDomain(value, "object") || typeof value === "symbol" ?
reference(value)
registeredReference(value)
: serializePrimitive(value as SerializablePrimitive)

@@ -51,7 +57,7 @@ }

case "function":
return isDotAccessible(value.name) ? value.name : "anonymousFunction"
return isDotAccessible(value.name) ? value.name : "fn"
case "symbol":
return value.description && isDotAccessible(value.description) ?
value.description
: "anonymousSymbol"
: "symbol"
}

@@ -58,0 +64,0 @@ return throwInternalError(

import type { array } from "./arrays.js"
import { type Primitive, domainOf, type inferDomain } from "./domain.js"
import type { BigintLiteral } from "./numericLiterals.js"
import { domainOf, type Primitive } from "./domain.js"
import { serializePrimitive, type SerializablePrimitive } from "./primitive.js"
import type { Dict } from "./records.js"
import { register } from "./registry.js"

@@ -63,4 +64,4 @@ export type SerializationOptions = {

onCycle: () => "(cycle)",
onSymbol: v => `(symbol ${v.description ?? "anonymous"})`,
onFunction: v => `(function ${v.name ?? "anonymous"})`
onSymbol: v => `Symbol(${register(v)})`,
onFunction: v => `Function(${register(v)})`
} satisfies SerializationOptions

@@ -101,29 +102,1 @@

}
type SerializedString<value extends string = string> = `"${value}"`
export type SerializedPrimitives = {
string: SerializedString
number: `${number}`
bigint: BigintLiteral
boolean: "true" | "false"
null: "null"
undefined: "undefined"
}
export type SerializedPrimitive =
SerializedPrimitives[keyof SerializedPrimitives]
export type SerializablePrimitive = inferDomain<keyof SerializedPrimitives>
export const serializePrimitive = <value extends SerializablePrimitive>(
value: value
): serializePrimitive<value> =>
(typeof value === "string" ? JSON.stringify(value)
: typeof value === "bigint" ? `${value}n`
: `${value}`) as never
export type serializePrimitive<value extends SerializablePrimitive> =
value extends string ? `"${value}"`
: value extends bigint ? `${value}n`
: `${value}`

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

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

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