Exciting release!Introducing "safe npm". Learn more
Socket
Log inDemoInstall

iteration-typeguards

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Issues
File Explorer

Advanced tools

iteration-typeguards

typeguard functions to determine whether or not a value is iterable or an iterator in the ES6 sense

    0.1.1latest
    GitHub

Version published
Maintainers
1
Weekly downloads
514
decreased by-21.29%

Weekly downloads

Readme

Source

iteration-typeguards

NPM

Build Status npm version

Installation

Install with npm

npm install iteration-typeguards

Requirements

This module assumes a javascript environment implementing ES6, as it defines iterators and iterability based on the ES6 iteration protocols.

Module Contents

This module consists of two typeguard functions, isIterable and isIterator that accept any javascript value as a single argument and return a boolean for whether or not that value is a Iterable or an Iterator in the ES6 sense, respectively.

Usage with Typescript

A typescript compiler --target argument of es6 should be used. Both of the functions isIterable and isIterator are defined as typescript typeguards for the built-in iterfaces: Iterable<T> and Iterator<T>, respectively.

isIterable

import {isIterable} from "iteration-typeguards"; isIterable(5); // false isIterable<string>("oh hai"); // true isIterable(null); // false isIterable([1,2,3]); // true isIterable(new Map<any,any>([ ["hi", 3], [{water: true}, "summer"]] )); // true isIterable({ [Symbol.iterator]: function() { return { next: function() { return 47; }, done: false } } }); // true

isIterator

import {isIterator} from "iteration-typeguards"; isIterator(5); // false isIterator<string>("oh hai"); // false isIterator<string>("oh hai"[Symbol.iterator]());// true isIterator(null); // false isIterator([1,2,3]); // false isIterator([1,2,3][Symbol.iterator]); // true isIterator({ next: function() { return 47; }, done: false }); // true

Usage without Typescript

Usage without typescript in nodejs is very similar to the typescript examples above without the type annotations. Since an ES6 environment is assumed, the import statements above should work. The more traditional nodejs require statements shown below also work.

var itGuards = require("iteration-typeguards"); itGuards.isIterable([1,2,3]) // true itGuards.isIterator([1,2,3][Symbol.iterator]) // true

Contributions

If you come across a case in which these typeguards do not perform as expected, please submit an issue (outlining the case) or a pull request (again, outlining the case and a possible solution).

License

MIT --- open source

Keywords

FAQs

Last updated on 13 Aug 2016

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket
support@socket.devSocket SOC 2 Logo

Product

  • Package Issues
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc