Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

esmkit/array

Open more actions menu

Repository files navigation

@esmkit/array

Immutable Array prototype methods.

Features

  • 🚀 High Performance: optimized for performance.
  • 📦 Small Bundle Size: small bundle size.
  • 🎯 Strong Type Annotations: written in TypeScript with full types support.

Installation

npm install @esmkit/array
bun add @esmkit/array

Usage

Basically, the usage of these method is same with mutable version.

import { sort, unshift, push, fill, splice, pop, reverse, copyWithin, shift } from "@esmkit/array";

describe("prototype", () => {
  it("shift", () => {
    assert.deepStrictEqual(shift(["a", "b", "c", "d", "e"]), ["b", "c", "d", "e"]);
  });
  it("unshift", () => {
    assert.deepStrictEqual(unshift(["a", "b", "c", "d", "e"], "x"), ["x", "a", "b", "c", "d", "e"]);
  });
  it("pop", () => {
    assert.deepStrictEqual(pop(["a", "b", "c", "d", "e"]), ["a", "b", "c", "d"]);
  });
  it("push", () => {
    assert.deepStrictEqual(push(["a", "b", "c", "d", "e"], "x"), ["a", "b", "c", "d", "e", "x"]);
  });
  it("splice", () => {
    assert.deepStrictEqual(splice(["a", "b", "c", "d", "e"], 0, 1, "x"), ["x", "b", "c", "d", "e"]);
  });
  it("sort", () => {
    assert.deepStrictEqual(sort(["e", "a", "c", "b", "d"]), ["a", "b", "c", "d", "e"]);
  });
  it("reverse", () => {
    assert.deepStrictEqual(reverse(["a", "b", "c", "d", "e"]), ["e", "d", "c", "b", "a"]);
  });
  it("fill", () => {
    assert.deepStrictEqual(fill(new Array(5), "x"), ["x", "x", "x", "x", "x"]);
  });
  it("copyWithin", () => {
    assert.deepStrictEqual(copyWithin(["a", "b", "c", "d", "e"], 0, 3, 4), ["d", "b", "c", "d", "e"]);
  });
});

License

MIT © BILLGO.ME & Viva Republica, Inc & azu

About

A collection of Array-related methods

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Contributors

Morty Proxy This is a proxified and sanitized view of the page, visit original site.