npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@xylabs/array

v5.0.87

Published

Base functionality used throughout XY Labs TypeScript/JavaScript libraries

Readme

@xylabs/array

logo

main-build npm-badge npm-downloads-badge jsdelivr-badge npm-license-badge codacy-badge codeclimate-badge snyk-badge socket-badge

Base functionality used throughout XY Labs TypeScript/JavaScript libraries

Reference

@xylabs/array


Functions

| Function | Description | | ------ | ------ | | containsAll | Checks whether the source array contains every element in the target array. | | distinct | Array filter callback that removes duplicate values, with correct NaN handling. Use with array.filter(distinct). | | filterAs | Maps each element using the predicate and filters out nullish results. | | filterAsync | Returns the elements of an array that meet the condition specified in a callback function. | | findAs | Maps each element using the predicate and returns the first non-nullish result. | | findLastAs | Maps each element using the predicate and returns the last non-nullish result. | | flatten | Concatenates two values or arrays into a single flat array, filtering out nullish entries. | | uniq | Returns a new array with duplicate values removed. | | uniqBy | Returns a new array with duplicates removed, using a key function for comparison. |

functions

containsAll

@xylabs/array


function containsAll<T>(source: T[], target: T[]): boolean;

Checks whether the source array contains every element in the target array.

Type Parameters

| Type Parameter | | ------ | | T |

Parameters

| Parameter | Type | Description | | ------ | ------ | ------ | | source | T[] | The array to search within | | target | T[] | The elements that must all be present |

Returns

boolean

True if every target element exists in source

distinct

@xylabs/array


function distinct<T>(
   value: T, 
   index: number, 
   array: T[]): boolean;

Array filter callback that removes duplicate values, with correct NaN handling. Use with array.filter(distinct).

Type Parameters

| Type Parameter | | ------ | | T |

Parameters

| Parameter | Type | | ------ | ------ | | value | T | | index | number | | array | T[] |

Returns

boolean

filterAs

@xylabs/array


function filterAs<In, Out>(x: In[], predicate: (a: In) => Out): NonNullable<Out>[];

Maps each element using the predicate and filters out nullish results.

Type Parameters

| Type Parameter | | ------ | | In | | Out |

Parameters

| Parameter | Type | Description | | ------ | ------ | ------ | | x | In[] | The input array | | predicate | (a: In) => Out | Transform function applied to each element |

Returns

NonNullable<Out>[]

Array of non-nullish transformed values

filterAsync

@xylabs/array


function filterAsync<T>(array: T[], predicate: (value: T, index: number, array: T[]) => Promise<boolean>): Promise<T[]>;

Returns the elements of an array that meet the condition specified in a callback function.

Type Parameters

| Type Parameter | | ------ | | T |

Parameters

| Parameter | Type | Description | | ------ | ------ | ------ | | array | T[] | The array to filter. | | predicate | (value: T, index: number, array: T[]) => Promise<boolean> | A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array. |

Returns

Promise<T[]>

The elements of an array that meet the condition specified in a callback function.

findAs

@xylabs/array


function findAs<In, Out>(x: In[], predicate: (a: In) => Out): NonNullable<Out> | undefined;

Maps each element using the predicate and returns the first non-nullish result.

Type Parameters

| Type Parameter | | ------ | | In | | Out |

Parameters

| Parameter | Type | Description | | ------ | ------ | ------ | | x | In[] | The input array | | predicate | (a: In) => Out | Transform function applied to each element |

Returns

NonNullable<Out> | undefined

The first non-nullish transformed value, or undefined

findLastAs

@xylabs/array


function findLastAs<In, Out>(x: In[], predicate: (a: In) => Out): NonNullable<Out> | undefined;

Maps each element using the predicate and returns the last non-nullish result.

Type Parameters

| Type Parameter | | ------ | | In | | Out |

Parameters

| Parameter | Type | Description | | ------ | ------ | ------ | | x | In[] | The input array | | predicate | (a: In) => Out | Transform function applied to each element |

Returns

NonNullable<Out> | undefined

The last non-nullish transformed value, or undefined

flatten

@xylabs/array


function flatten<T>(a?: T | ConcatArray<T>, b?: T | ConcatArray<T>): T[];

Concatenates two values or arrays into a single flat array, filtering out nullish entries.

Type Parameters

| Type Parameter | | ------ | | T |

Parameters

| Parameter | Type | Description | | ------ | ------ | ------ | | a? | T | ConcatArray<T> | First value or array | | b? | T | ConcatArray<T> | Second value or array |

Returns

T[]

A flat array of non-nullish elements

uniq

@xylabs/array


function uniq<T>(arr: T[]): T[];

Returns a new array with duplicate values removed.

Type Parameters

| Type Parameter | | ------ | | T |

Parameters

| Parameter | Type | Description | | ------ | ------ | ------ | | arr | T[] | The input array |

Returns

T[]

A deduplicated array

uniqBy

@xylabs/array


function uniqBy<T, I>(arr: T[], iteratee: (item: T) => I): T[];

Returns a new array with duplicates removed, using a key function for comparison.

Type Parameters

| Type Parameter | | ------ | | T | | I |

Parameters

| Parameter | Type | Description | | ------ | ------ | ------ | | arr | T[] | The input array | | iteratee | (item: T) => I | Function that returns the key to compare by |

Returns

T[]

A deduplicated array keeping the first occurrence of each key

Part of sdk-js

Maintainers

License

See the LICENSE file for license details

Credits

Made with 🔥 and ❄️ by XYLabs