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.20 to 0.0.21

__tests__/remap.test.ts

8

compilation.ts

@@ -118,9 +118,9 @@ import { DynamicFunction } from "./functions.js"

}
return indexPropAccess(
typeof key === "symbol" ? reference(key) : JSON.stringify(key),
optional
)
return indexPropAccess(serializeLiteralKey(key), optional)
}
export const serializeLiteralKey = (key: PropertyKey) =>
typeof key === "symbol" ? reference(key) : JSON.stringify(key)
export const indexPropAccess = (key: string, optional = false) =>
`${optional ? "?." : ""}[${key}]`
export class InternalArktypeError extends Error {}
export const throwInternalError: (message: string) => never = (message) => {
throw new InternalArktypeError(message)
export const throwInternalError: (message: string) => never = (message) =>
throwError(message, InternalArktypeError)
export const throwError: (
message: string,
constructor?: new (message: string) => Error
) => never = (message, constructor = Error) => {
throw new constructor(message)
}

@@ -9,5 +15,4 @@

export const throwParseError: (message: string) => never = (message) => {
throw new ParseError(message)
}
export const throwParseError: (message: string) => never = (message) =>
throwError(message, ParseError)

@@ -14,0 +19,0 @@ // Using "Hair Space" as a non-rendered sentinel for an error message string:

@@ -65,1 +65,5 @@ import { throwInternalError } from "./errors.js"

) => f
export type Guardable<input = unknown, narrowed extends input = input> =
| ((In: input) => In is narrowed)
| ((In: input) => boolean)
import type { NumberLiteral } from "./numericLiterals.js"
import { isArray } from "./objectKinds.js"
import type { mutable } from "./records.js"

@@ -153,3 +155,3 @@ export type pathToString<

to extends element[] | undefined,
element extends {},
element extends {} | null,
value extends element | undefined

@@ -159,5 +161,5 @@ >(

value: value
): to | Extract<value, undefined> => {
): Exclude<to, undefined> | Extract<value & to, undefined> => {
if (value === undefined) {
return to
return to as never
}

@@ -168,6 +170,35 @@ if (to === undefined) {

to.push(value)
return to
return to as never
}
/**
* Concatenates an element or list with a readonly list
*
* @param {to} to - The base list.
* @param {elementOrList} elementOrList - The element or list to concatenate.
*/
export const conflatenate = <element>(
to: readonly element[] | undefined,
elementOrList: listable<element> | undefined
): readonly element[] => {
if (elementOrList === undefined) {
return to ?? ([] as never)
}
if (to === undefined) {
return listFrom(elementOrList) as never
}
return to.concat(elementOrList) as never
}
/**
* Concatenates a variadic list of elements or lists with a readonly list
*
* @param {to} to - The base list.
* @param {elementsOrLists} elementsOrLists - The elements or lists to concatenate.
*/
export const conflatenateAll = <element>(
...elementsOrLists: (listable<element> | undefined)[]
) => elementsOrLists.reduce<readonly element[]>(conflatenate, [])
/**
* Appends a value to an array if it is not already included, returning the array

@@ -174,0 +205,0 @@ *

@@ -10,3 +10,2 @@ export * from "./compilation.js"

export * from "./lists.js"
export * from "./map.js"
export * from "./numericLiterals.js"

@@ -17,2 +16,3 @@ export * from "./objectKinds.js"

export * from "./registry.js"
export * from "./remap.js"
export * from "./serialize.js"

@@ -19,0 +19,0 @@ export * from "./strings.js"

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

export declare const literalPropAccess: (key: PropertyKey, optional?: boolean) => string;
export declare const serializeLiteralKey: (key: PropertyKey) => string;
export declare const indexPropAccess: (key: string, optional?: boolean) => string;
//# sourceMappingURL=compilation.d.ts.map

@@ -83,5 +83,6 @@ import { DynamicFunction } from "./functions.js";

}
return indexPropAccess(typeof key === "symbol" ? reference(key) : JSON.stringify(key), optional);
return indexPropAccess(serializeLiteralKey(key), optional);
};
export const serializeLiteralKey = (key) => typeof key === "symbol" ? reference(key) : JSON.stringify(key);
export const indexPropAccess = (key, optional = false) => `${optional ? "?." : ""}[${key}]`;
//# sourceMappingURL=compilation.js.map
export declare class InternalArktypeError extends Error {
}
export declare const throwInternalError: (message: string) => never;
export declare const throwError: (message: string, constructor?: new (message: string) => Error) => never;
export declare class ParseError extends Error {

@@ -5,0 +6,0 @@ }

export class InternalArktypeError extends Error {
}
export const throwInternalError = (message) => {
throw new InternalArktypeError(message);
export const throwInternalError = (message) => throwError(message, InternalArktypeError);
export const throwError = (message, constructor = Error) => {
throw new constructor(message);
};
export class ParseError extends Error {
}
export const throwParseError = (message) => {
throw new ParseError(message);
};
export const throwParseError = (message) => throwError(message, ParseError);
//# sourceMappingURL=errors.js.map

@@ -12,2 +12,3 @@ export declare const cached: <T>(thunk: () => T) => () => T;

export type Callable = new <f extends (...args: never[]) => unknown>(f: f, thisArg?: object) => f;
export type Guardable<input = unknown, narrowed extends input = input> = ((In: input) => In is narrowed) | ((In: input) => boolean);
//# sourceMappingURL=functions.d.ts.map

@@ -39,4 +39,18 @@ import type { NumberLiteral } from "./numericLiterals.js";

*/
export declare const append: <to extends element[] | undefined, element extends {}, value extends element | undefined>(to: to, value: value) => to | Extract<value, undefined>;
export declare const append: <to extends element[] | undefined, element extends {} | null, value extends element | undefined>(to: to, value: value) => Exclude<to, undefined> | Extract<value & to, undefined>;
/**
* Concatenates an element or list with a readonly list
*
* @param {to} to - The base list.
* @param {elementOrList} elementOrList - The element or list to concatenate.
*/
export declare const conflatenate: <element>(to: readonly element[] | undefined, elementOrList: listable<element> | undefined) => readonly element[];
/**
* Concatenates a variadic list of elements or lists with a readonly list
*
* @param {to} to - The base list.
* @param {elementsOrLists} elementsOrLists - The elements or lists to concatenate.
*/
export declare const conflatenateAll: <element>(...elementsOrLists: (listable<element> | undefined)[]) => readonly element[];
/**
* Appends a value to an array if it is not already included, returning the array

@@ -43,0 +57,0 @@ *

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

import { isArray } from "./objectKinds.js";
export const getPath = (root, path) => {

@@ -59,2 +60,24 @@ let result = root;

/**
* Concatenates an element or list with a readonly list
*
* @param {to} to - The base list.
* @param {elementOrList} elementOrList - The element or list to concatenate.
*/
export const conflatenate = (to, elementOrList) => {
if (elementOrList === undefined) {
return to ?? [];
}
if (to === undefined) {
return listFrom(elementOrList);
}
return to.concat(elementOrList);
};
/**
* Concatenates a variadic list of elements or lists with a readonly list
*
* @param {to} to - The base list.
* @param {elementsOrLists} elementsOrLists - The elements or lists to concatenate.
*/
export const conflatenateAll = (...elementsOrLists) => elementsOrLists.reduce(conflatenate, []);
/**
* Appends a value to an array if it is not already included, returning the array

@@ -61,0 +84,0 @@ *

@@ -10,3 +10,2 @@ export * from "./compilation.js";

export * from "./lists.js";
export * from "./map.js";
export * from "./numericLiterals.js";

@@ -17,2 +16,3 @@ export * from "./objectKinds.js";

export * from "./registry.js";
export * from "./remap.js";
export * from "./serialize.js";

@@ -19,0 +19,0 @@ export * from "./strings.js";

@@ -10,3 +10,2 @@ export * from "./compilation.js";

export * from "./lists.js";
export * from "./map.js";
export * from "./numericLiterals.js";

@@ -17,2 +16,3 @@ export * from "./objectKinds.js";

export * from "./registry.js";
export * from "./remap.js";
export * from "./serialize.js";

@@ -19,0 +19,0 @@ export * from "./strings.js";

@@ -86,2 +86,4 @@ import type { defined, evaluate } from "./generics.js";

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 & keyof o> extends infer T ? { [k in keyof T]: Omit<o, keyof keys & keyof o>[k]; } : never;
export type EmptyObject = Record<PropertyKey, never>;

@@ -88,0 +90,0 @@ export declare const isEmptyObject: (o: object) => o is EmptyObject;

@@ -35,3 +35,5 @@ export const entriesOf = (o) => Object.entries(o);

};
export const pick = (o, keys) => splitByKeys(o, keys)[0];
export const omit = (o, keys) => splitByKeys(o, keys)[1];
export const isEmptyObject = (o) => Object.keys(o).length === 0;
//# sourceMappingURL=records.js.map
{
"name": "@arktype/util",
"version": "0.0.20",
"version": "0.0.21",
"author": {

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

@@ -188,2 +188,12 @@ import type { defined, evaluate } from "./generics.js"

export const pick = <o extends object, keys extends keySetOf<o>>(
o: o,
keys: keys
) => splitByKeys(o, keys)[0]
export const omit = <o extends object, keys extends keySetOf<o>>(
o: o,
keys: keys
) => splitByKeys(o, keys)[1]
export type EmptyObject = Record<PropertyKey, never>

@@ -190,0 +200,0 @@

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

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