@ginden/blinkstick-v2
Version:
Improved Blickstick API for Node.js
34 lines • 1.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.repeat = repeat;
const tsafe_1 = require("tsafe");
const node_util_1 = require("node:util");
/**
* Repeats an animation a specified number of times.
* Note that passing a generator object to repeat will not work as expected;
* @category Animation
*/
function repeat(animation, times) {
if (times === 1) {
return typeof animation === 'function' ? animation() : animation;
}
(0, tsafe_1.assert)(times > 0, 'Times must be greater than 0');
(0, tsafe_1.assert)(!node_util_1.types.isGeneratorObject(animation), 'Passing a generator object to repeat will not work as expected - wrap the call in a function');
if (times === Infinity) {
return {
[Symbol.asyncIterator]: async function* () {
while (true) {
yield* typeof animation === 'function' ? animation() : animation;
}
},
};
}
return {
[Symbol.asyncIterator]: async function* () {
for (let i = 0; i < times; i++) {
yield* typeof animation === 'function' ? animation() : animation;
}
},
};
}
//# sourceMappingURL=repeat.js.map