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 1.1.4 to 4.0.0

dist/cjs/reverse-iterable-array.js

42

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

@@ -11,15 +11,33 @@ "author": {

"license": "MIT",
"main": "./src/reverse-iterable-array.mjs",
"module": "./src/reverse-iterable-array.mjs",
"main": "dist/cjs/reverse-iterable-array",
"module": "dist/esm/reverse-iterable-array.mjs",
"sideEffects": false,
"files": [
"src/"
"src",
"dist"
],
"engines": {
"node": ">=8.5"
},
"scripts": {
"test": "node --experimental-modules tests/tests.mjs",
"examples": "node ./node_modules/.bin/http-server"
"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"
},
"ava": {
"compileEnhancements": false,
"extensions": [
"ts"
],
"require": [
"ts-node/register"
]
},
"nyc": {
"extension": [
".ts"
]
},
"keywords": [

@@ -35,4 +53,8 @@ "array",

"devDependencies": {
"http-server": "^0.11.1"
"ava": "^1.2.0",
"http-server": "^0.11.1",
"nyc": "^13.1.0",
"ts-node": "^8.0.2",
"typescript": "^3.2.4"
}
}

@@ -19,57 +19,81 @@ # reverse-iterable-array

* [Install](#install)
* [ES Module](#es-module)
* [Node.js package](#nodejs-package)
* [Usage](#usage)
* [Tests](#tests)
* [Documentation](#documentation)
* [Constructor](#constructor)
* [`entries()`](#entries)
* [`forEachReverse()`](#foreachreverse)
* [`keys()`](#keys)
* [`reverseIterator()`](#reverseiterator)
* [`values()`](#values)
* [`[Symbol.iterator]()`](#symboliterator)
* [`[Symbol.toStringTag]()`](#symboltostringtag)
* [`iteratorFor()`](#iteratorfor)
- [Installation & usage](#installation--usage)
- [Examples](#examples)
- [Tests](#tests)
- [Documentation](#documentation)
- [Constructor](#constructor)
- [`entries()`](#entries)
- [`forEachReverse()`](#foreachreverse)
- [`keys()`](#keys)
- [`reverseIterator()`](#reverseiterator)
- [`values()`](#values)
- [`[Symbol.iterator]()`](#symboliterator)
- [`[Symbol.toStringTag]()`](#symboltostringtag)
- [`iteratorFor()`](#iteratorfor)
## Install
## Installation & usage
### ES Module
### Browser
Download only the ES module file:
Download the ES module file …
```shell
curl -O https://raw.githubusercontent.com/kleinfreund/reverse-iterable-array/main/src/reverse-iterable-array.mjs
```sh
curl -O https://raw.githubusercontent.com/kleinfreund/reverse-iterable-array/main/dist/esm/reverse-iterable-array.mjs
```
### Node.js package
… and import it like this:
*(Requires Node version 8.5 or higher for ES module support)*
```js
import ReverseIterableArray from 'reverse-iterable-array.mjs';
Installs the node package as a dependency. It doesn’t have any dependencies itself.
const array = new ReverseIterableArray();
```
```shell
### Node
Install the node package as a dependency …
```sh
npm install --save reverse-iterable-array
```
Note, that Node.js version 8.5 or higher is required, as it comes with experimental support for ES modules. If you don’t want to use it as an ES module, you will need to transpile the package yourself.
… and import it like this:
## Usage
- CommonJS module
```js
import { ReverseIterableArray } from './src/reverse-iterable-array.mjs';
```node
const ReverseIterableArray = require('reverse-iterable-array').default;
const array = new ReverseIterableArray();
```
const array = new ReverseIterableArray();
```
For more usage examples, clone the repository and run:
- ES module
```shell
```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
For some live usage examples, clone the repository and run the following:
```sh
npm install && npm run examples
```
Then, open `http://127.0.0.1:8080/examples` in your browser.
Then, open [localhost:8080/examples](http://127.0.0.1:8080/examples) in a browser.

@@ -80,6 +104,6 @@

**… with Node’s experimental ES module feature**:
In order to run the tests, clone the repository and run the following:
```shell
npm test
```sh
npm install && npm test
```

@@ -105,24 +129,29 @@

* `iterable`: An [iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol) object.
- `iterable`: An [iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol) object.
#### Usage
```js
const array = new ReverseIterableArray();
```
- Without arguments
##### `Array`
```js
const array = new ReverseIterableArray();
//> Array []
```
```js
const array = new ReverseIterableArray([1, 2, 3]);
```
- With multiple elements
##### `NodeList`
```js
const array = new ReverseIterableArray(1, 2, 3);
//> Array(3) [ 1, 2, 3 ]
```
```js
const array = new ReverseIterableArray(...document.querySelectorAll('div'));
```
- With a single length argument
```js
const array = new ReverseIterableArray(7);
//> Array(7) [ <7 empty slots> ]
```
### `entries()`

@@ -144,4 +173,24 @@

#### Usage
```js
const array = new ReverseIterableArray(1, 2, 4);
const iterator = array.entries();
iterator.next().value;
//> [0, 1]
iterator.next().value;
//> [1, 2]
iterator.next().value;
//> [2, 4]
iterator.next().value;
//> undefined
```
### `forEachReverse()`

@@ -159,7 +208,27 @@

* **callback**: Function to execute for each element.
* **thisArg**: Value to use as `this` when executing `callback`.
- **callback**: Function to execute for each element.
- **thisArg**: Value to use as `this` when executing `callback`.
#### Usage
```js
const array = new ReverseIterableArray('a', 'b', 'c');
array.forEachReverse(value => {
console.log(value);
});
//> c
//> b
//> a
array.forEachReverse(function (value, key, arrayReference) {
console.log(key, value, arrayReference.size);
});
//> 2 c 3
//> 1 b 3
//> 0 a 3
```
### `keys()`

@@ -181,4 +250,24 @@

#### Usage
```js
const array = new ReverseIterableArray(1, 2, 4);
const iterator = array.keys();
iterator.next().value;
//> 0
iterator.next().value;
//> 1
iterator.next().value;
//> 2
iterator.next().value;
//> undefined
```
### `reverseIterator()`

@@ -198,4 +287,24 @@

#### Usage
```js
const array = new ReverseIterableArray(1, 2, 4);
const iterator = array.reverseIterator();
iterator.next().value;
//> [2, 4]
iterator.next().value;
//> [1, 2]
iterator.next().value;
//> [0, 1]
iterator.next().value;
//> undefined
```
### `values()`

@@ -217,4 +326,24 @@

#### Usage
```js
const array = new ReverseIterableArray(1, 2, 4);
const iterator = array.values();
iterator.next().value;
//> 1
iterator.next().value;
//> 2
iterator.next().value;
//> 4
iterator.next().value;
//> undefined
```
### `[Symbol.iterator]()`

@@ -260,4 +389,13 @@

#### Usage
```js
const array = new ReverseIterableArray();
Object.prototype.toString.call(array)
//> [object ReverseIterableArray]
```
### `iteratorFor()`

@@ -279,3 +417,3 @@

* **index**: Required. The index of the element to start iterating from.
- **index**: Required. The index of the element to start iterating from.

@@ -285,1 +423,31 @@ **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
```
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