UNPKG

ayvajs

Version:

A lightweight, behavior-based JavaScript API for controlling Open Source Multi Axis Stroker Robots.

30 lines (22 loc) 552 B
export default class StrokeParameterProvider { #index = 0; #value; constructor (valueFunction) { this.#value = valueFunction; } next () { return this.#value(this.#index++); } get index () { return this.#index; } static createFrom (value) { if (value instanceof Array) { return new StrokeParameterProvider((index) => value[index % value.length]); } if (typeof value !== 'function') { return new StrokeParameterProvider(() => value); } return new StrokeParameterProvider(value); } }