Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ark/util

Package Overview
Dependencies
Maintainers
0
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ark/util - npm Package Compare versions

Comparing version 0.32.0 to 0.33.0

17

out/arrays.d.ts

@@ -34,3 +34,2 @@ import type { GuardablePredicate } from "./functions.ts";

*
* @param arr - The input array to be split.
* @param predicate - The guard function used to determine which items to include.

@@ -56,2 +55,3 @@ * @returns A tuple containing two arrays:

export type AppendOptions = {
/** If true, adds the element to the beginning of the array instead of the end */
prepend?: boolean;

@@ -61,8 +61,2 @@ };

* Adds a value or array to an array, returning the concatenated result
*
* @param to The array to which `value` is to be added. If `to` is `undefined`, a new array
* is created as `[value]` if value was not undefined, otherwise `[]`.
* @param value The value to add to the array.
* @param opts
* prepend: If true, adds the element to the beginning of the array instead of the end
*/

@@ -73,5 +67,2 @@ export declare const append: <to extends unknown[] | undefined, value extends appendableValue<to>>(to: to, value: value, opts?: AppendOptions) => to & {};

* Concatenates an element or list with a readonly list
*
* @param {to} to - The base list.
* @param {elementOrList} elementOrList - The element or list to concatenate.
*/

@@ -81,4 +72,2 @@ export declare const conflatenate: <element>(to: readonly element[] | undefined | null, elementOrList: appendableValue<readonly element[]> | undefined | null) => readonly element[];

* Concatenates a variadic list of elements or lists with a readonly list
*
* @param {elementsOrLists} elementsOrLists - The elements or lists to concatenate.
*/

@@ -91,6 +80,2 @@ export declare const conflatenateAll: <element>(...elementsOrLists: (listable<element> | undefined | null)[]) => readonly element[];

* Appends a value or concatenates an array to an array if it is not already included, returning the array
*
* @param to The array to which `value` is to be appended. If `to` is `undefined`, a new array
* is created including only `value`.
* @param value An array or value to append to the array. If `to` includes `value`, nothing is appended.
*/

@@ -97,0 +82,0 @@ export declare const appendUnique: <to extends unknown[]>(to: to | undefined, value: NoInfer<Readonly<to> | to[number]>, opts?: ComparisonOptions<to[number]>) => to;

@@ -22,3 +22,2 @@ export const join = (segments, delimiter) => segments.join(delimiter);

*
* @param arr - The input array to be split.
* @param predicate - The guard function used to determine which items to include.

@@ -54,8 +53,2 @@ * @returns A tuple containing two arrays:

* Adds a value or array to an array, returning the concatenated result
*
* @param to The array to which `value` is to be added. If `to` is `undefined`, a new array
* is created as `[value]` if value was not undefined, otherwise `[]`.
* @param value The value to add to the array.
* @param opts
* prepend: If true, adds the element to the beginning of the array instead of the end
*/

@@ -84,5 +77,2 @@ export const append = (to, value, opts) => {

* Concatenates an element or list with a readonly list
*
* @param {to} to - The base list.
* @param {elementOrList} elementOrList - The element or list to concatenate.
*/

@@ -98,4 +88,2 @@ export const conflatenate = (to, elementOrList) => {

* Concatenates a variadic list of elements or lists with a readonly list
*
* @param {elementsOrLists} elementsOrLists - The elements or lists to concatenate.
*/

@@ -105,6 +93,2 @@ export const conflatenateAll = (...elementsOrLists) => elementsOrLists.reduce(conflatenate, []);

* Appends a value or concatenates an array to an array if it is not already included, returning the array
*
* @param to The array to which `value` is to be appended. If `to` is `undefined`, a new array
* is created including only `value`.
* @param value An array or value to append to the array. If `to` includes `value`, nothing is appended.
*/

@@ -111,0 +95,0 @@ export const appendUnique = (to, value, opts) => {

/** Shallowly copy the properties of the object. */
export declare const shallowClone: <input extends object>(input: input) => input;
/** Deeply copy the properties of the a non-subclassed Object, Array or Date.
*
* @param input The object to clone
*
* @returns A new deeply cloned version of the object, or the original object
* if it has a prototype other than Object, Array Date, or null.
*/
/** Deeply copy the properties of the a non-subclassed Object, Array or Date.*/
export declare const deepClone: <input extends object>(input: input) => input;
import { getBuiltinNameOfConstructor } from "./objectKinds.js";
/** Shallowly copy the properties of the object. */
export const shallowClone = input => _clone(input, null);
/** Deeply copy the properties of the a non-subclassed Object, Array or Date.
*
* @param input The object to clone
*
* @returns A new deeply cloned version of the object, or the original object
* if it has a prototype other than Object, Array Date, or null.
*/
/** Deeply copy the properties of the a non-subclassed Object, Array or Date.*/
export const deepClone = (input) => _clone(input, new Map());

@@ -12,0 +6,0 @@ const _clone = (input, seen) => {

27

out/flatMorph.d.ts

@@ -1,7 +0,10 @@

import type { array, listable } from "./arrays.ts";
import type { show } from "./generics.ts";
import { type array, type listable } from "./arrays.ts";
import type { conform, show } from "./generics.ts";
import type { Key } from "./keys.ts";
import type { Entry, entryOf, fromEntries } from "./records.ts";
import type { Entry, entryOf } from "./records.ts";
import type { intersectUnion } from "./unionToTuple.ts";
type objectFromListableEntries<transformed extends readonly Entry[]> = show<intersectUnion<fromEntries<transformed>>>;
type objectFromListableEntries<transformed extends readonly GroupableEntry[]> = show<intersectUnion<fromGroupableEntries<transformed>>>;
type fromGroupableEntries<entries extends readonly GroupableEntry[]> = {
[entry in entries[number] as entry extends GroupedEntry ? entry[0]["group"] : conform<entry[0], PropertyKey>]: entry extends GroupedEntry ? entry[1][] : entry[1];
};
type arrayFromListableEntries<transformed extends Entry> = Entry<number, never> extends transformed ? transformed[1][] : _arrayFromListableEntries<transformed, []>;

@@ -16,3 +19,3 @@ type _arrayFromListableEntries<transformed extends Entry, result extends unknown[]> = [

] : _arrayFromListableEntries<remaining, [...result, next[1]]> : never : [...result, ...transformed[1][]];
type extractEntrySets<e extends listable<Entry>> = e extends readonly Entry[] ? e : [e];
type extractEntrySets<e extends listable<GroupableEntry>> = e extends readonly GroupableEntry[] ? e : [e];
type extractEntries<e extends listable<Entry>> = e extends readonly Entry[] ? e[number] : e;

@@ -25,12 +28,16 @@ type entryArgsWithIndex<o> = {

}[number];
export type MappedEntry = listable<Entry<Key> | Entry<number>>;
export type fromMappedEntries<transformed extends MappedEntry> = [
export type GroupedEntry = readonly [key: {
group: Key;
}, value: unknown];
export type GroupableEntry = Entry<Key> | Entry<number> | GroupedEntry;
export type ListableEntry = listable<GroupableEntry>;
export type fromMappedEntries<transformed extends ListableEntry> = [
transformed
] extends [listable<Entry<number>>] ? arrayFromListableEntries<extractEntries<transformed>> : objectFromListableEntries<extractEntrySets<transformed>>;
export type FlatMorph = {
<const o extends array, transformed extends MappedEntry>(o: o, flatMapEntry: (...args: numericArrayEntry<o>) => transformed): fromMappedEntries<transformed>;
<const o extends object, transformed extends MappedEntry>(o: o, flatMapEntry: (...args: entryOf<o>) => transformed): fromMappedEntries<transformed>;
<const o extends object, transformed extends MappedEntry>(o: o, flatMapEntry: (...args: entryArgsWithIndex<o>) => transformed): fromMappedEntries<transformed>;
<const o extends array, transformed extends ListableEntry>(o: o, flatMapEntry: (...args: numericArrayEntry<o>) => transformed): fromMappedEntries<transformed>;
<const o extends object, transformed extends ListableEntry>(o: o, flatMapEntry: (...args: entryOf<o>) => transformed): fromMappedEntries<transformed>;
<const o extends object, transformed extends ListableEntry>(o: o, flatMapEntry: (...args: entryArgsWithIndex<o>) => transformed): fromMappedEntries<transformed>;
};
export declare const flatMorph: FlatMorph;
export {};

@@ -0,18 +1,24 @@

import { append } from "./arrays.js";
export const flatMorph = (o, flatMapEntry) => {
const result = {};
const inputIsArray = Array.isArray(o);
const entries = Object.entries(o).flatMap((entry, i) => {
const result = inputIsArray ? flatMapEntry(i, entry[1]) : flatMapEntry(...entry, i);
const entrySet = Array.isArray(result[0]) || result.length === 0 ?
let outputShouldBeArray = false;
Object.entries(o).forEach((entry, i) => {
const mapped = inputIsArray ? flatMapEntry(i, entry[1]) : flatMapEntry(...entry, i);
outputShouldBeArray ||= typeof mapped[0] === "number";
const flattenedEntries = Array.isArray(mapped[0]) || mapped.length === 0 ?
// if we have an empty array (for filtering) or an array with
// another array as its first element, treat it as a list of
result
// another array as its first element, treat it as a list
mapped
// otherwise, it should be a single entry, so nest it in a tuple
// so it doesn't get spread when the result is flattened
: [result];
return entrySet;
: [mapped];
flattenedEntries.forEach(([k, v]) => {
if (typeof k === "object")
result[k.group] = append(result[k.group], v);
else
result[k] = v;
});
});
const objectResult = Object.fromEntries(entries);
return typeof entries[0]?.[0] === "number" ?
Object.values(objectResult)
: objectResult;
return outputShouldBeArray ? Object.values(result) : result;
};

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

*
* @param {number} n - The input number.
* @param {"+" | "-"} [direction="+"] - The direction to find the nearest float. "+" for the next float, "-" for the previous float.
* @returns {number} The nearest representable floating-point number after or before the input.
* @throws {Error} If the input is not a finite number.

@@ -61,0 +59,0 @@ *

@@ -107,5 +107,3 @@ import { throwParseError } from "./errors.js";

*
* @param {number} n - The input number.
* @param {"+" | "-"} [direction="+"] - The direction to find the nearest float. "+" for the next float, "-" for the previous float.
* @returns {number} The nearest representable floating-point number after or before the input.
* @throws {Error} If the input is not a finite number.

@@ -112,0 +110,0 @@ *

@@ -201,5 +201,2 @@ import type { DescribeOptions } from "./describe.ts";

* Returns an array of constructors for all ancestors (i.e., prototypes) of a given object.
*
* @param {object} o - The object to find the ancestors of.
* @returns {Function[]} An array of constructors for all ancestors of the object.
*/

@@ -206,0 +203,0 @@ export declare const ancestorsOf: (o: object) => Function[];

@@ -132,5 +132,2 @@ import { domainOf } from "./domain.js";

* Returns an array of constructors for all ancestors (i.e., prototypes) of a given object.
*
* @param {object} o - The object to find the ancestors of.
* @returns {Function[]} An array of constructors for all ancestors of the object.
*/

@@ -137,0 +134,0 @@ export const ancestorsOf = (o) => {

@@ -60,5 +60,2 @@ import type { array } from "./arrays.ts";

* of keys, e.g. those defined internally as configs
*
* @param o the object to get narrowed entries from
* @returns a narrowed array of entries based on that object's type
*/

@@ -65,0 +62,0 @@ export declare const entriesOf: <o extends object>(o: o) => entryOf<o>[];

@@ -6,5 +6,2 @@ import { noSuggest } from "./errors.js";

* of keys, e.g. those defined internally as configs
*
* @param o the object to get narrowed entries from
* @returns a narrowed array of entries based on that object's type
*/

@@ -11,0 +8,0 @@ export const entriesOf = Object.entries;

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

export declare const arkUtilVersion = "0.32.0";
export declare const arkUtilVersion = "0.33.0";
export declare const initialRegistryContents: {

@@ -3,0 +3,0 @@ version: string;

@@ -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.32.0";
export const arkUtilVersion = "0.33.0";
export const initialRegistryContents = {

@@ -11,0 +11,0 @@ version: arkUtilVersion,

@@ -28,7 +28,4 @@ import type { array } from "./arrays.ts";

* Converts a Date instance to a human-readable description relative to its precision
*
* @param {Date} date
* @returns {string} - The generated description
*/
export declare const describeCollapsibleDate: (date: Date) => string;
export {};

@@ -60,2 +60,4 @@ import { domainOf } from "./domain.js";

return opts.onUndefined ?? "undefined";
case "string":
return data.replaceAll("\\", "\\\\");
default:

@@ -67,5 +69,2 @@ return data;

* Converts a Date instance to a human-readable description relative to its precision
*
* @param {Date} date
* @returns {string} - The generated description
*/

@@ -72,0 +71,0 @@ export const describeCollapsibleDate = (date) => {

{
"name": "@ark/util",
"version": "0.32.0",
"version": "0.33.0",
"license": "MIT",

@@ -5,0 +5,0 @@ "author": {

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