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

iter-fun

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

iter-fun - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

40

index.js

@@ -0,1 +1,24 @@

function addSymbolIterator(obj) {
try {
obj[Symbol.iterator] = function () {
return this;
};
} catch (error) {
// pass
}
}
function addSymbolIteratorFallback(obj) {
obj["@@iterator"] = function () {
return this;
};
}
function wrapNextFunction(next) {
const iter = { next };
addSymbolIterator(iter);
addSymbolIteratorFallback(iter);
return iter;
}
function isArray(data) {

@@ -45,12 +68,12 @@ try {

let len = data.length;
return {
next: () => (i++ < len ? { value: data[i], done: false } : { done: true })
};
const next = () =>
i++ < len ? { value: data[i], done: false } : { done: true };
return wrapNextFunction(next);
}
function getOrCreateIterator(data) {
if (hasNext(data)) {
return data;
} else if (hasSymbolIterator(data)) {
if (hasSymbolIterator(data)) {
return data[Symbol.iterator]();
} else if (hasNext(data)) {
return wrapNextFunction(data.next);
} else if (hasIterator(data)) {

@@ -67,2 +90,4 @@ return getIterator(data);

module.exports = {
addSymbolIterator,
addSymbolIteratorFallback,
isArray,

@@ -74,4 +99,5 @@ hasNext,

createIterator,
getOrCreateIterator
getOrCreateIterator,
wrapNextFunction
};
}

2

package.json
{
"name": "iter-fun",
"version": "0.1.0",
"version": "0.1.1",
"description": "Fun with Iterables",

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

@@ -38,2 +38,18 @@ # iter-fun

const iter = createIterator(obj);
import { addSymbolIterator } from "iter-fun";
const obj = { next: () => {...} };
addSymbolIterator(obj);
// modifies the object in-place adding a [Symbol.iterator] key
import { addSymbolIteratorFallback } from "iter-fun";
const obj = { next: () => {...} };
addSymbolIteratorFallback(obj);
// modifies the object in-place adding a "@@iterator" string key
// helpful if you are running in an old browser
import { wrapNextFunction } from "iter-fun";
const next = () => { ... };
const iter = wrapNextFunction(next);
// converts a next function into a fully functioning iterable
```
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