Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

reverse-iterable-array

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reverse-iterable-array - npm Package Compare versions

Comparing version 4.0.0 to 5.0.0

dist/reverse-iterable-array.js

70

package.json
{
"name": "reverse-iterable-array",
"version": "5.0.0",
"license": "MIT",
"description": "A reverse-iterable array implementation based on the built-in Array object",
"version": "4.0.0",
"repository": "kleinfreund/reverse-iterable-array",
"author": {

@@ -10,34 +10,10 @@ "name": "Philipp Rudloff",

},
"license": "MIT",
"main": "dist/cjs/reverse-iterable-array",
"module": "dist/esm/reverse-iterable-array.mjs",
"sideEffects": false,
"files": [
"src",
"dist"
],
"scripts": {
"prepublishOnly": "npm test",
"prepare": "npm run build",
"test": "nyc ava tests/*.js",
"build": "npm run build:esm && npm run build:cjs",
"build:esm": "tsc --module es2015 --outDir dist/esm && npm run rename-to-mjs",
"build:cjs": "tsc --module commonjs --outDir dist/cjs",
"rename-to-mjs": "mv dist/esm/reverse-iterable-array.js dist/esm/reverse-iterable-array.mjs",
"examples": "npm run build && http-server"
"homepage": "https://github.com/kleinfreund/reverse-iterable-array",
"repository": {
"type": "git",
"url": "https://github.com/kleinfreund/reverse-iterable-array.git"
},
"ava": {
"compileEnhancements": false,
"extensions": [
"ts"
],
"require": [
"ts-node/register"
]
"bugs": {
"url": "https://github.com/kleinfreund/reverse-iterable-array/issues"
},
"nyc": {
"extension": [
".ts"
]
},
"keywords": [

@@ -49,12 +25,28 @@ "array",

],
"bugs": {
"url": "https://github.com/kleinfreund/reverse-iterable-array/issues"
"exports": "./dist/reverse-iterable-array.js",
"main": "./dist/reverse-iterable-array.js",
"module": "./dist/reverse-iterable-array.js",
"files": [
"src",
"dist"
],
"sideEffects": false,
"scripts": {
"build": "NODE_ENV=production rollup --config",
"prebuild": "npm run test",
"test": "jest",
"start": "npm run build && http-server",
"prestart": "npm run build",
"prepack": "npm run build",
"prepublishOnly": "npm run test"
},
"devDependencies": {
"ava": "^1.2.0",
"http-server": "^0.11.1",
"nyc": "^13.1.0",
"ts-node": "^8.0.2",
"typescript": "^3.2.4"
"@rollup/plugin-typescript": "^8.2.1",
"@types/jest": "^26.0.22",
"http-server": "^0.12.3",
"jest": "^26.6.3",
"rollup-plugin-terser": "^7.0.2",
"ts-jest": "^26.5.4",
"typescript": "^4.2.3"
}
}

@@ -8,2 +8,3 @@ # reverse-iterable-array

- [**npmjs.com**/package/reverse-iterable-array](https://www.npmjs.com/package/reverse-iterable-array)
- [on BundlePhobia](https://bundlephobia.com/result?p=reverse-iterable-array)
- [**github.com**/kleinfreund/reverse-iterable-array](https://github.com/kleinfreund/reverse-iterable-array)

@@ -25,4 +26,6 @@

- [Constructor](#constructor)
- [`[Symbol.toStringTag]`](#symboltostringtag)
- [`entries()`](#entries)
- [`forEachReverse()`](#foreachreverse)
- [`iteratorFor()`](#iteratorfor)
- [`keys()`](#keys)

@@ -32,4 +35,2 @@ - [`reverseIterator()`](#reverseiterator)

- [`[Symbol.iterator]()`](#symboliterator)
- [`[Symbol.toStringTag]()`](#symboltostringtag)
- [`iteratorFor()`](#iteratorfor)

@@ -42,6 +43,6 @@

Download the ES module file …
Download the UMD bundle file …
```sh
curl -O https://raw.githubusercontent.com/kleinfreund/reverse-iterable-array/main/dist/esm/reverse-iterable-array.mjs
curl -O https://raw.githubusercontent.com/kleinfreund/reverse-iterable-array/main/dist/reverse-iterable-array.js
```

@@ -52,3 +53,3 @@

```js
import ReverseIterableArray from 'reverse-iterable-array.mjs';
const ReverseIterableArray = window.ReverseIterableArray.default

@@ -63,3 +64,3 @@ const array = new ReverseIterableArray();

```sh
npm install --save reverse-iterable-array
npm install reverse-iterable-array
```

@@ -69,28 +70,10 @@

- CommonJS module
```node
const ReverseIterableArray = require('reverse-iterable-array').default;
```node
const ReverseIterableArray = require('reverse-iterable-array').default;
const array = new ReverseIterableArray();
```
const array = new ReverseIterableArray();
```
- ES module
```js
import ReverseIterableArray from 'reverse-iterable-array/dist/esm/reverse-iterable-array';
const array = new ReverseIterableArray();
```
- TypeScript module
```ts
import ReverseIterableArray from 'reverse-iterable-array/src/reverse-iterable-array';
const array = new ReverseIterableArray();
```
## Examples

@@ -101,3 +84,4 @@

```sh
npm install && npm run examples
npm install
npm start
```

@@ -114,3 +98,4 @@

```sh
npm install && npm test
npm install
npm test
```

@@ -163,2 +148,8 @@

### `[Symbol.toStringTag]`
The `ReverseIterableArray[@@toStringTag]` property has an initial value of “ReverseIterableArray”.
### `entries()`

@@ -239,2 +230,56 @@

### `iteratorFor()`
Returns an iterator containing the `[index, element]` pairs for each element in the `ReverseIterableArray` object in insertion order **starting with the pair specified by the `index` parameter**.
This allows starting iteration at a specific element in the array.
An iterator containing the same pairs in reverse-insertion order can be obtained with `iteratorFor(index).reverseIterator()`.
#### Syntax
```
array.iteratorFor(index);
```
**Parameters**:
- **index**: Required. The index of the element to start iterating from.
**Return value**:
A new `ReverseIterableArray` iterator object.
#### Usage
```js
const array = new ReverseIterableArray('a', 'b', 'c');
// Iterator, starting at the element with key 1.
const iterator = array.iteratorFor(1);
iterator.next().value;
//> [1, 'b']
iterator.next().value;
//> [2, 'c']
iterator.next().value;
//> undefined
// Reverse-iterator, starting at the element with key 1.
const reverseIterator = array.iteratorFor(1).reverseIterator();
reverseIterator.next().value;
//> [1, 'c']
reverseIterator.next().value;
//> [0, 'a']
reverseIterator.next().value;
//> undefined
```
### `keys()`

@@ -400,55 +445,1 @@

```
### `iteratorFor()`
Returns an iterator containing the `[index, element]` pairs for each element in the `ReverseIterableArray` object in insertion order **starting with the pair specified by the `index` parameter**.
This allows starting iteration at a specific element in the array.
An iterator containing the same pairs in reverse-insertion order can be obtained with `iteratorFor(index).reverseIterator()`.
#### Syntax
```
array.iteratorFor(index);
```
**Parameters**:
- **index**: Required. The index of the element to start iterating from.
**Return value**:
A new `ReverseIterableArray` iterator object.
#### Usage
```js
const array = new ReverseIterableArray('a', 'b', 'c');
// Iterator, starting at the element with key 1.
const iterator = array.iteratorFor(1);
iterator.next().value;
//> [1, 'b']
iterator.next().value;
//> [2, 'c']
iterator.next().value;
//> undefined
// Reverse-iterator, starting at the element with key 1.
const reverseIterator = array.iteratorFor(1).reverseIterator();
reverseIterator.next().value;
//> [1, 'c']
reverseIterator.next().value;
//> [0, 'a']
reverseIterator.next().value;
//> undefined
```

@@ -16,4 +16,5 @@ /**

*/
constructor(...arrayLengthOrElements: T[]) {
super(...arrayLengthOrElements)
constructor(...arrayLengthOrElements: Array<Array<T>> | Array<T>) {
const arrayArgument = Array.isArray(arguments[0]) ? arguments[0] : arrayLengthOrElements
super(...arrayArgument)
}

@@ -38,5 +39,8 @@

* @param callbackfn
* @param [thisArg]
* @param thisArg
*/
forEachReverse(callbackfn: (value: T, index: number, map: T[]) => void, thisArg?: any) {
forEachReverse(
callbackfn: (value: T, index: number, array: ReverseIterableArray<T>) => void,
thisArg?: any
) {
for (const [index, value] of this.entries().reverseIterator()) {

@@ -97,3 +101,3 @@ callbackfn.call(thisArg, value, index, this);

*/
get [Symbol.toStringTag](): string {
get [Symbol.toStringTag]() {
return 'ReverseIterableArray';

@@ -134,7 +138,6 @@ }

* @param getIteratorValue
* @param [startIndex] Index of the element to start iterating from
* @param startIndex Index of the element to start iterating from
* @returns a reverse-iterable iterator
* @private
*/
_iterableIterator(
private _iterableIterator(
getIteratorValue: (index: number) => [number, T] | number | T,

@@ -156,2 +159,3 @@ startIndex?: number

},
[Symbol.iterator]() {

@@ -161,2 +165,3 @@ // Return the iterable itself.

},
next() {

@@ -163,0 +168,0 @@ let value;

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc