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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@prelude/array

v3.0.0

Published

Array module.

Downloads

37,458

Readme

Array module

  • at: <T>(values: T[], index: number) => T

    Returns value at index.

    Throws {TypeError} if index is out of bounds.

  • bounded: <T>(values: T[], index: number) => T

    Like at but bounds less than zero index to 0 and out of bound to last.

  • bsearch: <T>(values: T[], cmp: Cmp1<T>) => number

  • clone: <T>(values: T[]) => T[]

  • Cmp: typeof import("/Users/mirek/prelude/packages/array/node_modules/@prelude/cmp/cjs/index")

  • deleteSwapRandom: <T>(values: T[]) => T

    Deletes and returns random element. Removed element is replaced by last element.

    Throws {TypeError} if values array is empty.

    Returns deleted element.

  • first: <T>(values: T[]) => T

    Returns first element of an array.

    Throws if array length is 0.

  • groups: <T, R extends string | number | boolean | symbol>(values: T[], keyOfValue: (value: T) => R) => T[][]

    Returns values grouped by key (result of keyOfValue).

  • indices: (n: number) => number[]

    Returns array with 0 to n-1 indices.

  • last: <T>(values: T[]) => T

    Returns last element of an array.

    Throws {TypeError}

  • maybeAt: <T>(values: T[], index: number) => T

    Returns value at index or undefined.

  • maybeFirst: <T>(values: T[]) => T

    Returns first element of an array or undefined.

  • maybeLast: <T>(values: T[]) => T

    Returns last element of an array or undefined.

  • maybeSample: <T>(values: T[]) => T

    Returns random element or undefined if array is empty.

  • modulo: <T>(values: T[], index: number) => T

    Like at but wraps using modulo on length.

    Throws {TypeError} if array is empty or index is not a safe integer.

  • nulls: (n: number) => null[]

    Returns an array of n nulls.

  • of: <T>(n: number, valueOrFunction: T | ((index: number) => T)) => T[]

  • ones: (n: number) => number[]

  • permutations: <T>(values: T[]) => Generator<T[], any, unknown>

    Based on Permutation Generation Methods, Robert Sedgewick.

    Returns permutations of an array.

  • randomIndex: (length: number) => number

  • sample: <T>(values: T[]) => T

    Returns random element.

    Throws if array is empty.

  • shuffle: <T>(values: T[]) => T[]

    In-place shuffle.

  • shuffled: <T>(values: T[]) => T[]

    Returns shuffled array.

  • sort: <T>(values: T[], cmp: t<T>) => T[]

  • sorted: <T>(values: T[], cmp: t<T>) => T[]

  • swap: <T>(values: T[], i: number, j: number) => T[]

    In-place swap elements at index i and j.

  • swapDeleteAt: <T>(values: T[], index: number) => T

  • swapDeleteFirst: <T>(values: T[], predicate: (value: T, index: number, values: T[]) => boolean) => T

  • unique: <T, R extends string | number | boolean | symbol>(values: T[], keyOfValue: (value: T) => R) => T[]

    Returns unique array.

  • zeroes: (n: number) => number[]

    Returns an array of n zeroes.

Usage

npm i -E @prelude/array
import * as A from '@prelude/array'

License

MIT License

Copyright 2021 Mirek Rusin

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.