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

@produck/crank

v0.4.1

Published

executor framework

Downloads

6

Readme

GitHub Workflow Status (with event) Coveralls branch npm (scoped) npm lerna NPM

crank

The framework is to generate program execution engine. You should provide executors, program and extern that is customized. By providing as mentioned above, you can customize the functions of engine. And then you will get the result of execution. The execution of program support async function and common functon.

Installation

$ npm install @produck/crank

Examples

import * as Crank from '@produck/crank';

const CustomEngine = Crank.defineEngine({}, {
	a: async (process) => {
		return 'pass';
	},
});

const extern = new CustomEngine.Extern();
const vm = new CustomEngine();

const ret = vm.execute({
	*foo() {
		return yield this._a();
	},
	*main() {
		return yield this.foo();
	},
}, extern).then(value => {
	console.log(value); // 'pass'
});

Usage

Import & Require

As esModule,

import {
	defineEngine, define,
	Extern,
	isToken
} from '@produck/crank';
// Or
import * as Crank from '@produck/crank';

As CommonJS,

const {
	defineEngine, define,
	Extern,
	isToken
} = require('@produck/crank');
// Or
const Crank = require('@produck/crank');

Creating a Engine class by default options

import * as Crank from '@produck/crank';

const Engine = Crank.define();

Creating a Engine class by custom options

You can customize Engine features by custom options.

options.name: The name of Engine class.
options.call: Customized the calling of functions.
options.Extern: Customized Extern, should be subclass of Crank.Extern.
options.abort: Customize when to abort the running program.

import * as Crank from '@produck/crank';

const Engine = Crank.define({
	name: 'CustomEngine',
	call: async (process, nextFrame, next) => await next(),
	Extern,
	abort: (lastInstruction) => false;
});

Creating a Engine class by custom executors

You can customize Engine functions by custom executors.

The item of executors should be async function or common functon.

import * as Crank from '@produck/crank';

const Engine = Crank.define({}, {
	async b() {
		return Promise.resolve(1);
	},
	a() {
		return 1;
	}
});

Execute a program

You can execute program and get returned value.

The function of program should be GeneratorFunction or AsyncGeneratorFunction.
The main function is required.
The executors should be calling by this._[executorName].
The function of program should be calling by this.[functionName].

The extern should be the instance of Engine.Extern.

import * as Crank from '@produck/crank';

const Engine = Crank.define({}, {
	a() {
		return 1;
	}
});
const vm = new Engine();

const program = {
	*main() {
		return yield this._a();
	}
};
const extern = new Engine.Extern();

vm.execute(program, extern).then(val => {
	console.log(val); // 1
});