Socket
Socket
Sign inDemoInstall

@ark/util

Package Overview
Dependencies
Maintainers
1
Versions
21
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.17.0 to 0.18.0

23

out/arrays.d.ts

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

import type { Guardable } from "./functions.ts";
import type { GuardablePredicate } from "./functions.ts";
import type { anyOrNever } from "./generics.ts";

@@ -31,3 +31,22 @@ import type { isDisjoint } from "./intersections.ts";

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>[]];
/**
* Splits an array into two arrays based on the result of a predicate
*
* @param arr - The input array to be split.
* @param predicate - The guard function used to determine which items to include.
* @returns A tuple containing two arrays:
* - the first includes items for which `predicate` returns true
* - the second includes items for which `predicate` returns false
*
* @example
* const list = [1, "2", "3", 4, 5];
* const [numbers, strings] = spliterate(list, (x) => typeof x === "number");
* // Type: number[]
* // Output: [1, 4, 5]
* console.log(evens);
* // Type: string[]
* // Output: ["2", "3"]
* console.log(odds);
*/
export declare const spliterate: <item, included extends item>(arr: readonly item[], predicate: GuardablePredicate<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>;

@@ -34,0 +53,0 @@ export declare const includes: <a extends array>(array: a, element: unknown) => element is a[number];

@@ -19,6 +19,25 @@ export const join = (segments, delimiter) => segments.join(delimiter);

export const liftArray = (data) => (Array.isArray(data) ? data : [data]);
export const spliterate = (list, by) => {
/**
* Splits an array into two arrays based on the result of a predicate
*
* @param arr - The input array to be split.
* @param predicate - The guard function used to determine which items to include.
* @returns A tuple containing two arrays:
* - the first includes items for which `predicate` returns true
* - the second includes items for which `predicate` returns false
*
* @example
* const list = [1, "2", "3", 4, 5];
* const [numbers, strings] = spliterate(list, (x) => typeof x === "number");
* // Type: number[]
* // Output: [1, 4, 5]
* console.log(evens);
* // Type: string[]
* // Output: ["2", "3"]
* console.log(odds);
*/
export const spliterate = (arr, predicate) => {
const result = [[], []];
for (const item of list) {
if (by(item))
for (const item of arr) {
if (predicate(item))
result[0].push(item);

@@ -25,0 +44,0 @@ else

2

out/functions.d.ts

@@ -22,3 +22,3 @@ export type Fn<args extends readonly any[] = readonly any[], returns = unknown> = (...args: args) => returns;

}
export type Guardable<input = unknown, narrowed extends input = input> = ((In: input) => In is narrowed) | ((In: input) => boolean);
export type GuardablePredicate<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;

@@ -25,0 +25,0 @@ /**

@@ -19,2 +19,3 @@ import type { Primitive } from "./domain.ts";

} & u;
export type promisable<t> = t | Promise<t>;
export type leftIfEqual<l, r> = [l, r] extends [r, l] ? l : r;

@@ -21,0 +22,0 @@ export type UnknownUnion = string | number | symbol | bigint | boolean | object | null | undefined;

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

import type { array } from "./arrays.ts";
import type { DescribeOptions } from "./describe.ts";

@@ -117,3 +116,3 @@ import { type domainDescriptions, domainOf } from "./domain.ts";

export declare const hasObjectKind: <kind extends keyof builtinConstructors>(data: object, kind: kind) => data is InstanceType<builtinConstructors[kind]>;
export declare const isArray: (data: unknown) => data is array;
export declare const isArray: (data: unknown) => data is readonly unknown[];
export declare const ecmascriptDescriptions: {

@@ -120,0 +119,0 @@ readonly Array: "an array";

@@ -73,3 +73,3 @@ import { domainOf } from "./domain.js";

export const hasObjectKind = (data, kind) => objectKindOf(data) === kind;
export const isArray = (data) => Array.isArray(data);
export const isArray = Array.isArray;
export const ecmascriptDescriptions = {

@@ -76,0 +76,0 @@ Array: "an array",

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

} : o;
/**
* extracts entries mimicking Object.entries, accounting for whether the
* object is an array
**/
export type entryOf<o> = {
[k in keyof o]-?: [k, o[k] & ({} | null)];
}[o extends array ? keyof o & number : keyof o] & unknown;
}[o extends readonly unknown[] ? keyof o & number : keyof o] & unknown;
export type entriesOf<o extends object> = entryOf<o>[];
export declare const entriesOf: <o extends object>(o: o) => entriesOf<o>;
/**
* Object.entries wrapper providing narrowed types for objects with known sets
* 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
*/
export declare const entriesOf: <o extends object>(o: o) => entryOf<o>[];
export type Entry<key extends PropertyKey = PropertyKey, value = unknown> = readonly [key: key, value: value];

@@ -52,0 +63,0 @@ export type fromEntries<entries extends readonly Entry[]> = show<{

import { flatMorph } from "./flatMorph.js";
export const entriesOf = (o) => Object.entries(o);
/**
* Object.entries wrapper providing narrowed types for objects with known sets
* 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
*/
export const entriesOf = Object.entries;
export const fromEntries = (entries) => Object.fromEntries(entries);

@@ -4,0 +11,0 @@ export const keysOf = (o) => Object.keys(o);

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

export declare const arkUtilVersion = "0.17.0";
export declare const arkUtilVersion = "0.18.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.17.0";
export const arkUtilVersion = "0.18.0";
export const initialRegistryContents = {

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

{
"name": "@ark/util",
"version": "0.17.0",
"version": "0.18.0",
"author": {

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

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