# values-iterator

> Returns an iterator of the values of an Array, Iterator, Object, Map, Set, or Typed Array.

Latest version **1.2.0** (published 2018-05-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install values-iterator
pnpm add values-iterator
yarn add values-iterator
bun add values-iterator
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2018-05-14 |
| First published | 2018-02-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=7.0.0 |
| Dependencies | 7 |
| Unpacked size | 6.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | John Lamansky |
| Maintainers | lamansky |
| Keywords | array, iterator, map, object, set, string, typed array, values |

## Links

- npm: https://www.npmjs.com/package/values-iterator
- Repository: https://github.com/lamansky/values-iterator
- Issues: https://github.com/lamansky/values-iterator/issues
- npm.io page: https://npm.io/package/values-iterator

## Dependencies (7)

- [sbo](https://npm.io/package/sbo.md) ^1.0.0
- [is-object](https://npm.io/package/is-object.md) ^1.0.1
- [is-iterator](https://npm.io/package/is-iterator.md) ^1.0.1
- [prop-values](https://npm.io/package/prop-values.md) ^1.0.0
- [typed-arrays](https://npm.io/package/typed-arrays.md) ^1.0.0
- [empty-iterator](https://npm.io/package/empty-iterator.md) ^1.0.0
- [is-instance-of](https://npm.io/package/is-instance-of.md) ^1.0.0

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 1.2.0 (latest) — 2018-05-14
- 1.1.0 — 2018-04-18
- 1.0.0 — 2018-02-19

## README

# values-iterator

Returns an iterator of the values of an Array, Iterator, Object, Map, Set, or Typed Array. Useful for when you need the values of a collection object but aren’t sure what type of collection you’ll be given.

## Installation

Requires [Node.js](https://nodejs.org/) 7.0.0 or above.

```bash
npm i values-iterator
```

## API

The module exports a single function.

### Parameters

1. Bindable: `c` (Array, iterator, Object, Map, Set, string, or Typed Array)
2. Object argument:
    * Optional: `arrays` / `maps` / `sets` (array, class, or string): A class that should be treated as equivalent to `Array`/`Map`/`Set` (respectively), the string name of such a class, or an array of such classes/strings.
    * Optional: `inObj` (boolean): Whether or not to act like the “in” operator by including inherited Object property values. Only takes effect if `c` is an Object (i.e. not another recognized type). Defaults to `false`.
    * Optional: `reflectObj` (boolean): Whether or not to use reflection to include non-enumerable Object property values. Only takes effect if `c` is an Object (i.e. not another recognized type). Defaults to `false`.

### Return Value

An iterator which yields values from the collection.

## Examples

### Arrays

```javascript
const values = require('values-iterator')

const i = values(['a', 'b'])
i.next().value // 'a'
i.next().value // 'b'
i.next().done // true

// Supports the bind operator
['a', 'b']::values()
```

### Iterators

```javascript
const values = require('values-iterator')

function * gen () {
  yield 'a'
  yield 'b'
}

const i = values(gen())
i.next().value // 'a'
i.next().value // 'b'
i.next().done // true
```

### Maps

```javascript
const values = require('values-iterator')

const map = new Map()
map.set('key', 'value')

const i = values(map)
i.next().value // 'value'
i.next().done // true
```

### Objects

```javascript
const values = require('values-iterator')

const i = values({key: 'value'})
i.next().value // 'value'
i.next().done // true

// Supports the bind operator
const obj = {key: 'value'}
obj::values()
```

#### Inherited Object Properties

Include Object property values from the prototype chain by setting `inObj` to `true`:

```javascript
const values = require('values-iterator')

function Cls () {}
Cls.prototype.key = 'value'

const i = values(new Cls(), {inObj: true})
i.next().value // 'value'
i.next().done // true
```

#### Non-Enumerable Object Properties

Include non-enumerable Object property values by setting `reflectObj` to `true`:

```javascript
const values = require('values-iterator')

const obj = {}
Object.defineProperty(obj, 'key', {value: 'value', enumerable: false})

const i = values(obj, {reflectObj: true})
i.next().value // 'value'
i.next().done // true
```

### Sets

```javascript
const values = require('values-iterator')

const set = new Set()
set.add('first')
set.add('second')

const i = values(set)
i.next().value // 'first'
i.next().value // 'second'
i.next().done // true
```

### Strings

`values-iterator` will treat a string like a character array.

```javascript
const values = require('values-iterator')

const i = keys('hi')
i.next().value // 'h'
i.next().value // 'i'
i.next().done // true
```

### Typed Arrays

```javascript
const values = require('values-iterator')

const typedArray = new Int32Array(new ArrayBuffer(4))

const i = values(typedArray)
i.next().value // 0
i.next().done // true
```

## Related

* [entries-iterator](https://github.com/lamansky/entries-iterator)
* [entries-array](https://github.com/lamansky/entries-array)
* [keys-iterator](https://github.com/lamansky/keys-iterator)
* [keys-array](https://github.com/lamansky/keys-array)
* [prop-values](https://github.com/lamansky/prop-values)
* [values-array](https://github.com/lamansky/values-array)

---
_Source: https://npm.io/package/values-iterator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
