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 🙏

© 2026 – Pkg Stats / Ryan Hefner

element-strategy

v1.1.0

Published

This library helps creating general purposes element strategy

Downloads

11

Readme

Element Strategy

This package helps to build strategies which your program should follow. It is not an finite state machine library.

Strategies are a part of machine state, and should be treated like step by step alghoritm.

For example if program faild due to exception it may change it's state to "failure" with specific strategy. It could've been some repair steps or cleanups before shutting down.

Generic Strategy

Main part of this package contain basic logic which is needed to manage strategy. Any implementation with unified API fits this construct. It may be Linear, Graph or any other Strategy.

It is highly recomended not to use generic constructs directly. You should always extends from it and make your own specific strategy.

Strategy Controller

Controller([ Element[] ]): controller

  • @param {Element} Optional array of strategy elements
  • @return {controller} new Controller object

Example:

/* create empty controller wihout any elements */
new Controller();

/*
 * create controller with two empty elements
 */
new Controller([new Element({}), new Element({})]);

Controller API

index: number

  • @property
  • @public

Points to current active element in strategy.

push(element: Element[]): number

  • @method
  • @public
  • @param {Element} strategy Element
  • @return {number} Index of new added element

Adds new Element at the end of strategy, and returns its index.

currentElement(): Element

  • @method
  • @public
  • @return {Element} Current active element

move(step: number): boolean

  • @method
  • @public
  • @return {bool} is move action successful

Move method contains logic which prevents to go out of range. Returns bool which indicates if strategy successfully move to next Element.

step param must be zero or positive and negative Integer.

Move calls hooks which may cause wanted side effects. These hooks are:

  • onNext()
  • onPrev()
  • onAgain()
  • onFinsih()

Hooks are part of Strategy Element API and it's required by implementing IElement Interface.

prev(): boolean

  • @method
  • @public
  • @return {bool} is prev action successful

Move strategy by one step backward, and return true if ends with success.

next(): boolean

  • @method
  • @public
  • @return {bool} is next action successful

Move strategy by one step forward, and return true if ends with success.

again(): boolean

  • @method
  • @public
  • @return {bool} is next action successful

Repeats the same step, and return true if ends with success.

Strategy Element

Element(obj: Object): element

  • @param {Object} Object which represents your strategy step
  • @return {element} new Element object

Example:

/* create simple element which some method */
new Element({ init: function () {},
              run: function () {},
              report: function () {} });

Element API

Element implements IElement interface which define hooks unified API. Every hook takes one argument which is index of element.

It shouldn't return anything because all returned values will not be utilise. Purpose of these hooks is to create space for side effects like logging, event emmitting and so on.

onPush(index: number): void

  • @method
  • @public

onPush is invoke every time when new element is added to strategy and returns it's index.

onPrev(index: number): void

  • @method
  • @public

onPrev is invoke every time when strategy successfully goes backward.

onNext(index: number): void

  • @method
  • @public

onNext is invoke every time when strategy successfully goes forward.

onAgain(index: number): void

  • @method
  • @public

onAgain is invoke every time when strategy successfully repeat the step.

onFinish(index: number): void

  • @method
  • @public

onFinish is invoke every time when strategy passes last element.

Linear Strategy

Lienar strategy leverage Generic Strategy to make linear strategy, which should be processed one by one without jumping through all strategy Elements.

Linear strategy additionally implements rewind to first and fast forward to last element.

Controller API

first(): void

  • @method
  • @public

Rewind to first element in strategy.

last(): void

  • @method
  • @public

Fast forward to last element in strategy.