Socket
Socket
Sign inDemoInstall

@immutable-array/splice

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @immutable-array/splice

Immutable Array.prototype.splice


Version published
Weekly downloads
118
increased by78.79%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

@immutable-array/splice

Immutable Array.prototype.splice().

Install

Install with npm:

npm install @immutable-array/splice

Usage

Same API with Array.prototype.splice().

/**
 * Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
 * @param array Base array.
 * @param start The zero-based location in the array from which to start removing elements.
 * @param deleteCount The number of elements to remove.
 * @param items Elements to insert into the array in place of the deleted elements.
 */
export declare function splice<T>(array: Array<T>, start?: number, deleteCount?: number, ...items: T[]): Array<T>;

Example

Delete all:

import { splice } from "@immutable-array/splice"
const originalArray = ["a", "b", "c", "d", "e"];
const resultArray = splice(originalArray, 0);
assert.deepStrictEqual(resultArray, []);

Delete range: 1-3

import { splice } from "@immutable-array/splice"
const originalArray = ["a", "b", "c", "d", "e"];
const resultArray = splice(originalArray, 1, 3);
assert.deepStrictEqual(resultArray, ["a", "e"]);

Delete and Insert = replace index 0 with "x"

import { splice } from "@immutable-array/splice"
const originalArray = ["a", "b", "c", "d", "e"];
const resultArray = splice(originalArray, 0, 1, "x");
assert.deepStrictEqual(resultArray, ["x", "b", "c", "d", "e"]);

Changelog

See Releases page.

Running tests

Install devDependencies and Run npm test:

npm i -d && npm test

Contributing

Pull requests and stars are always welcome.

For bugs and feature requests, please create an issue.

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

License

MIT © azu

Keywords

FAQs

Last updated on 09 Jan 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc