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

iterall

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

iterall - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

5

index.d.ts

@@ -11,4 +11,7 @@ /**

export var $$ITERATOR: symbol | string
// Note: TypeScript already has built-in definitions for
// Iterable<TValue> and Iterator<TValue> so they are not defined here.
export var $$iterator: symbol | string
export function isIterable(obj: any): boolean

@@ -15,0 +18,0 @@

68

index.js

@@ -11,17 +11,43 @@ /**

/**
* [Iterator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#iterator)
* is a *protocol* which describes a standard way to produce a sequence of
* values, typically the values of the Iterable represented by this Iterator.
*
* While described by the [ES2015 version of JavaScript](http://www.ecma-international.org/ecma-262/6.0/#sec-iterator-interface)
* it can be utilized by any version of JavaScript.
*
* @typedef {Object} Iterator
* @template T The type of each iterated value
* @property {function (): { value: T, done: boolean }} next
* A method which produces either the next value in a sequence or a result
* where the `done` property is `true` indicating the end of the Iterator.
*/
/**
* [Iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#iterable)
* is a *protocol* which when implemented allows a JavaScript object to define
* their iteration behavior, such as what values are looped over in a `for..of`
* loop or `iterall`'s `forEach` function. Many [built-in types](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#Builtin_iterables)
* implement the Iterable protocol, including `Array` and `Map`.
*
* While described by the [ES2015 version of JavaScript](http://www.ecma-international.org/ecma-262/6.0/#sec-iterable-interface)
* it can be utilized by any version of JavaScript.
*
* @typedef {Object} Iterable
* @template T The type of each iterated value
* @property {function (): Iterator<T>} Symbol.iterator
* A method which produces an Iterator for this Iterable.
*/
// In ES2015 (or a polyfilled) environment, this will be Symbol.iterator
var REAL_$$ITERATOR = typeof Symbol === 'function' && Symbol.iterator
var SYMBOL_ITERATOR = typeof Symbol === 'function' && Symbol.iterator
/**
* A property name to be used as the name of an Iterable's method responsible
* for producing an Iterator. Typically represents the value `Symbol.iterator`.
* for producing an Iterator, referred to as `@@iterator`. Typically represents
* the value `Symbol.iterator` but falls back to the string `"@@iterator"` when
* `Symbol.iterator` is not defined.
*
* `Symbol` is defined in ES2015 environments, however some transitioning
* JavaScript environments, such as older versions of Node define `Symbol`, but
* do not define `Symbol.iterator`. Older versions of Mozilla Firefox,
* which originally introduced the Iterable protocol, used the string
* value `"@@iterator"`. This string value is used when `Symbol.iterator` is
* not defined.
*
* Use `$$ITERATOR` for defining new Iterables instead of `Symbol.iterator`,
* Use `$$iterator` for defining new Iterables instead of `Symbol.iterator`,
* but do not use it for accessing existing Iterables, instead use

@@ -32,3 +58,3 @@ * `getIterator()` or `isIterable()`.

*
* var $$ITERATOR = require('iterall').$$ITERATOR
* var $$iterator = require('iterall').$$iterator
*

@@ -39,3 +65,3 @@ * function Counter (to) {

*
* Counter.prototype[$$ITERATOR] = function () {
* Counter.prototype[$$iterator] = function () {
* return {

@@ -60,4 +86,4 @@ * to: this.to,

*/
var $$ITERATOR = REAL_$$ITERATOR || '@@iterator'
exports.$$ITERATOR = $$ITERATOR
var $$iterator = SYMBOL_ITERATOR || '@@iterator'
exports.$$iterator = $$iterator

@@ -73,3 +99,3 @@ /**

* isIterable('ABC') // true
* isArrayLike({ length: 1, 0: 'Alpha' }) // false
* isIterable({ length: 1, 0: 'Alpha' }) // false
* isIterable({ key: 'value' }) // false

@@ -125,4 +151,4 @@ * isIterable(new Map()) // true

* isCollection({ length: 1, 0: 'Alpha' }) // true
* isArrayLike({ key: 'value' }) // false
* isArrayLike(new Map()) // true
* isCollection({ key: 'value' }) // false
* isCollection(new Map()) // true
*

@@ -196,3 +222,3 @@ * @example

if (iterable != null) {
var method = REAL_$$ITERATOR && iterable[REAL_$$ITERATOR] || iterable['@@iterator']
var method = SYMBOL_ITERATOR && iterable[SYMBOL_ITERATOR] || iterable['@@iterator']
if (typeof method === 'function') {

@@ -243,3 +269,3 @@ return method

* @template T the type of each iterated value
* @param {Iterable<T>|Array<T>} collection
* @param {Iterable<T>|{ length: number }} collection
* The Iterable or array to iterate over.

@@ -304,3 +330,3 @@ * @param {function(T, number, object)} callback

* @template T the type of each iterated value
* @param {Iterable<T>|Array<T>} collection
* @param {Iterable<T>|{ length: number }} collection
* An Iterable or Array-like object to produce an Iterator.

@@ -330,3 +356,3 @@ * @return {Iterator<T>} new Iterator instance.

// Note: all Iterators are themselves Iterable.
ArrayLikeIterator.prototype[$$ITERATOR] = function () {
ArrayLikeIterator.prototype[$$iterator] = function () {
return this

@@ -333,0 +359,0 @@ }

{
"name": "iterall",
"version": "1.0.1",
"version": "1.0.2",
"description": "Minimal zero-dependency utilities for using JavaScript Iterables in all environments.",

@@ -5,0 +5,0 @@ "main": "index.js",

Sorry, the diff of this file is not supported yet

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