New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

ts-iterable

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-iterable

Iterable abstract class for TypeScript

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

Iterable abstract class for TypeScript

Build Status Coveralls npm version npm downloads npm dependencies npm devDependencies npm license

Make any object iterable with the Typescript Iterable abstract class. The iterable class uses the standard Symbol.iterator symbol for iteration.

Install

The easiest way is to install ts-iterable as dependency:

npm install ts-iterable --save

Usage

Extending the Iterable abstract class

class Cart extends Iterable {
  private articles: string[]

  public constructor(...articles) {
    super()
    this.articles = articles
  }

  public valid(key): boolean {
    return key < this.articles.length
  }

  public current(key): any {
    return this.articles[key]
  }
}

With the for...of instruction

const cart = new Cart('flour', 'eggs', 'milk')
for (const article of cart) {
  console.log(article)
}

// Displays:
// "flour"
// "eggs"
// "milk"

With the Angular's ngFor directive

cart.component.ts

@Component({
  selector: 'app-cart',
  templateUrl: './cart.component.html'
})
export class CartComponent {

  public cart: Cart

  public constructor() {
    this.cart = new Cart('flour', 'eggs', 'milk')
  }

cart.component.html

<h1>Your cart</h1>
<ul>
  <li *ngFor="let article of cart">{{article}}</li>
</ul>

License

Code licensed under MIT License.

Keywords

iterable

FAQs

Package last updated on 08 Feb 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts