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

innerator

v0.0.1-0

Published

JavaScript built-in functions rewritten to understand generators

Downloads

17

Readme

innerator

npm version Build Status Dependency Status devDependency Status

JavaScript built-in functions rewritten to understand generators.

The innerator functions closely follow the Standard ECMA-262 6th Edition, a.k.a. ECMAScript 2015, a.k.a. ES6 specification. The inneratored versions of the built-in functions support generator functions where only regular functions were supported, properly executing the generator and iterating over it.

Install

npm install --save innerator

API

innerator has two modes: library and global.

The library mode is 100% self-contained and does not conflict with existing code.

The global mode overrides built-ins and may break existing code under rare circumstances.

Library mode

// Import the library with module syntax:
import { lib } from 'innerator';
// Or CommonJS:
var lib = require('innerator').lib;

// Then call or apply the functions you want:
lib['Array.prototype.forEach'].default.call([1, 2, 3], function *(item) {
	console.log(1, 2, 3);
	yield;
});

You can also use the Function Bind syntax (compiled with Babel) to write more readable code:

[1, 2, 3]::lib['Array.prototype.forEach'].default(function *(item) {
	console.log(1, 2, 3);
	yield;
});

The examples above are very contrived, for a real use case you may want to yield promises from inside the generator, and delegate the iteration logic to an outer iterator by yield*ing the return value of the innerator library function. See the unit tests for more elaborated examples.

Global mode

import { installGlobals } from 'innerator';
installGlobals();
// Or CommonJS:
// require('innerator').installGlobals();

[1, 2, 3].forEach(function *(item) {
	console.log(1, 2, 3);
	yield;
});

// Still supports regular functions:
[1, 2, 3].forEach(function (item) {
	console.log(1, 2, 3);
});

The global mode overrides built-ins in such a way that they work with generator functions while keeping compatibility with regular functions.

This means that once the global mode has been installed, passing a generator function to a built-in will behave differently from the native behavior. Most of the time, it does not make sense to pass a generator function to built-in functions, but in rare occasions (e.g. mapping an array to iterator objects) the behavior will be significantly different and thus introduce breaking changes.

The global mode is not recommended unless you are just making a quick experiment or running in an environment where you have full control over where generator functions can be used.

Options

You can pass an options object as the first argument to the installGlobals function in order to customize its behavior. The options object may contain the following properties:

  • supportAether (boolean, default: false) - whether to support code running inside an Aether sandbox.

Developing

You may find these commands useful if you want to hack this package's source:

  • npm run dev: makes a complete build (clean up, lint, compile and test) then starts watching the src directory to make incremental builds.
  • npm test: makes a complete build.

Changelog

No stable release yet.