Comparing version 0.1.1 to 0.1.2
17
index.js
@@ -56,2 +56,14 @@ function addSymbolIterator(obj) { | ||
function isIterator(data) { | ||
try { | ||
return ( | ||
Symbol.iterator in data && | ||
typeof data.next === "function" && | ||
data.propertyIsEnumerable("next") === false | ||
); | ||
} catch { | ||
return false; | ||
} | ||
} | ||
function getIterator(data) { | ||
@@ -75,3 +87,5 @@ const iter = data["@@iterator"]; | ||
function getOrCreateIterator(data) { | ||
if (hasSymbolIterator(data)) { | ||
if (isIterator(data)) { | ||
return data; | ||
} else if (hasSymbolIterator(data)) { | ||
return data[Symbol.iterator](); | ||
@@ -93,2 +107,3 @@ } else if (hasNext(data)) { | ||
addSymbolIteratorFallback, | ||
isIterator, | ||
isArray, | ||
@@ -95,0 +110,0 @@ hasNext, |
{ | ||
"name": "iter-fun", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Fun with Iterables", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -19,2 +19,5 @@ # iter-fun | ||
import { isIterator } from "iter-fun"; | ||
isIterator([1, 2, 3][Symbol.iterator]()); // true | ||
import { hasNext } from "iter-fun"; | ||
@@ -21,0 +24,0 @@ hasNext({ next: () => {...} }); // true |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11539
104
58