npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lazyiterators

v1.0.12

Published

lazyIterators will allow you to iterate over Arrays of Objects or any end-point using the same simple iteration API, taking care of all the hard work for you.

Downloads

9

Readme

LazyIterators

lazyIterators will allow you to iterate over Arrays of Objects or any end-point using the same simple iteration API, taking care of all the hard work for you.

In the current LazyIterators module you can find an Array of Objects lazyIterator and a generic end-points lazyIterator which will handle for you responses out of order, connections errors and timeouts.

Please note that lazyIterators are framework independant and compatible with AngularJS, meaning that if you use them from within AngularJS they will detect it is present and require transparently its required services, if Angular is not present it will use XMLHTTPRequest native methods :)

Installation

 $ npm install lazyiterators

LazyArrayIterators

LazyArrayIterators implement the lazyIterators API and allows you to iterate over an Array of Objects.

LazyArrayIterators Usage:


  /* 
   * require LazyArrayIterator from lazyIterators module.
   *
   **/

  var LazyArrayIterator = require('lazyiterators').ArrayIterator;

  /* lazyIterator elements loading success/error callbacks */

  function error(error) {
  	console.log('error loading elements:', error);
  }

  function success(elements) {
  	console.log(' - retrieved elements:', elements);
  }

  /* create list of elements to iterate */

  var i, myElements = [];

  for (i = 0; i < 100; i++) {
  	myElements.push({ id: i, name: 'element ' + i });
  }

  /* Apply iterator over list */

  var myLazyIterator = new LazyArrayIterator(myElements, { iter: 5 });

  /* 
   * Get a badge of elements, current index 0,
   * first five elements will be returned.
   *
   **/

  myLazyIterator.next(success, error);

  /* 
   * Get a badge of 10 elements, current index 5,
   * elements from index 5 till 15 will be returned.
   *
   **/

  myLazyIterator.next(success, error, 10);

  /* Get back a badge of 15 elements from current
   * collection index, from 15 to 0.
   *
   **/

  myLazyIterator.prev(success, error, 15);

  /*
   * Use get() method to retrieve elements from collection,
   * by using this method the specified elements will be
   * returned without affecting the current iterator index.
   *
   **/

  myLazyIterator.get({
  	index: 50,
  	limit: 10,
  	error: error,
  	success: success,
  });

  /* Get a badge of elements, iterator index was left at
   * zero before using the previous get() method so the
   * first badge of elements will be returned.
   *
   **/

  myLazyIterator.next(success, error);

  /*
   * Index element 95 and request one badge of elements, 
   * getting to the end of the collection. LazyIterators
   * should return true in its done() method when this
   * condition is true.
   *
   **/

  myLazyIterator.index(95).next(success, error);

  /* */

  setTimeout(function() {
  	console.log('end of collection?', 
  		(myLazyIterator.done()) ? 'YES' : 'NO');

  }, 0);

LazyEndPointIterators

lazyEndPointIterators will allow you to iterate over almost any HTTP end-point transparently using the lazyIterators API. The iterator will transparently handle for you responses out of order, connection errors or timeouts. For more detailed information about their config options kindly check the "lazyIterators" section in the "lazyContainers" documentation located at: http://www.slidonjqueryslider.com/lazycontainer/

LazyEndPointIterators Usage:


  /* Require LazyEndPointIterator from lazyIterators module */

  var LazyEndPointIterator = require('lazyiterators').EndPointIterator;

  /*
   * This example assumes we are using an end-point located at
   * "/api/items.php" which has an "index" parameter to specify
   * the starting index in the end-point's collection we want to
   * request and a "limit" parameter stating the number of 
   * elements we need from within the specified "index".
   *
   * For example, to request the first 10 elements we would need
   * the following query: "/api/items.php?index=0&limit=10"
   *
   * Don't worry about AngularJS services, lazyEndPointIterator
   * will detect if Angular is present, request app injector and
   * request the necesary services. If using them from another
   * framework or whatsoever, they will detect Angular is not
   * present and use native XMLHTTPRequest :)
   *
   **/

  /* Build end-point iterator */

  var endPointUrl = "/api/items.php?index=:index&limit=:limit";
  var myLazyIterator = new LazyEndPointIterator(endPointUrl, config);

  /*
   * From here on you use the end-point just as the LazyArrayIterator,
   * the beauty of the lazyIterators (thus the lazyContainers) is that
   * at any given point you can switch the elements stream transparently.
   *
   **/

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the Apache License