8000 GitHub - esmkit/array: A collection of Array-related methods
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

esmkit/array

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"]);<
722F
/span>
  });
  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

 
0