JSPM

@immutable-array/copy-within

1.0.6
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 11
  • Score
    100M100P100Q67270F
  • License MIT

Immutable Array.prototype.copyWithin().

Package Exports

  • @immutable-array/copy-within
  • @immutable-array/copy-within/lib/copy-within.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@immutable-array/copy-within) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@immutable-array/copy-within

Immutable Array.prototype.copyWithin().

Install

Install with npm:

npm install @immutable-array/copy-within

Usage

Same API with Array.prototype.copyWithin()

/**
 * Returns the this object after copying a section of the array identified by start and end
 * to the same array starting at position target
 * @param array Base array
 * @param target If target is negative, it is treated as length+target where length is the
 * length of the array.
 * @param start If start is negative, it is treated as length+start. If end is negative, it
 * is treated as length+end.
 * @param end If not specified, length of the this object is used as its default value.
 */
export declare function copyWithin<T>(array: Array<T>, target: number, start: number, end?: number): Array<T>;

Example

import { copyWithin } from "@immutable-array/copyWithin";
const originalArray = [1, 2, 3, 4, 5];
assert.deepStrictEqual(copyWithin(originalArray, -2), [1, 2, 3, 1, 2]);
assert.deepStrictEqual(copyWithin(originalArray, 0, 3), [4, 5, 3, 4, 5]);
assert.deepStrictEqual(copyWithin(originalArray, 0, 3, 4), [4, 2, 3, 4, 5]);
assert.deepStrictEqual(copyWithin(originalArray, 0, -2, -1), [4, 2, 3, 4, 5]);

TODO: Array-like.

This is not specified behavior.

If you interesting in this, Please comment to copyWithIn() with Array-like · Issue #20 · azu/immutable-array-prototype.

import { copyWithin } from "@immutable-array/copyWithin";
const arrayLike = { length: 5, 3: 1 };
let actual = copyWithin(arrayLike, 0, 3);
assert.deepStrictEqual(actual, [1, , , 1,]);

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