replace functions with arrow functions

This commit is contained in:
Daniel Sommer 2022-02-21 12:20:37 +01:00
parent 91f6c0a57a
commit 5b22396e0d

View file

@ -41,7 +41,7 @@ function powerOff() {
// parse a color object from given request arguments
function parseColor(value) {
if (!value || value == RANDOM) {
if (!value || value === RANDOM) {
return RANDOM;
}
let parsedColor = parseRGBColor(value);
@ -95,16 +95,16 @@ function parseHexColor(value) {
if (value.length === 4) {
value = (value[0] + value[1] + value[1] + value[2] + value[2] + value[3] + value[3]);
}
if (hexcolor({ strict: true }).test(value)) {
if (hexcolor({strict: true}).test(value)) {
return value;
}
}
// pass the options to the blinkstick accordingly
function illuminate(blinkstickConfig) {
return new Promise(function (resolve, reject) {
return new Promise((resolve, reject) => {
findBlinkstick()
.then(function () {
.then(() => {
switch (blinkstickConfig.mode) {
case 'morph':
morph(blinkstickConfig, resolve, reject);
@ -124,10 +124,10 @@ function illuminate(blinkstickConfig) {
// set a static color
function setColor(blinkstickConfig, resolve, reject) {
stopAnimation()
.then(function () {
.then(() => {
setAnimationProperties(blinkstickConfig);
logger.debug('setting color to \'' + blinkstickConfig.color + '\'...');
led.setColor(blinkstickConfig.color, blinkstickConfig.options, function (err) {
led.setColor(blinkstickConfig.color, blinkstickConfig.options, (err) => {
clearAnimationProperties();
if (err) {
return reject('error setting color \'' + blinkstickConfig.color + '\' (' + err + ')');
@ -140,10 +140,10 @@ function setColor(blinkstickConfig, resolve, reject) {
// morph to a color
function morph(blinkstickConfig, resolve, reject) {
stopAnimation()
.then(function () {
.then(() => {
setAnimationProperties(blinkstickConfig);
logger.debug('morphing color to \'' + blinkstickConfig.color + '\'...');
led.morph(blinkstickConfig.color, blinkstickConfig.options, function (err) {
led.morph(blinkstickConfig.color, blinkstickConfig.options, (err) => {
clearAnimationProperties();
if (err) {
return reject('error morphing color to \'' + blinkstickConfig.color + '\' (' + err + ')');
@ -169,7 +169,7 @@ function startPulsing(blinkstickConfig, resolve, reject) {
return;
}
setAnimationProperties(blinkstickConfig);
led.pulse(blinkstickConfig.color, blinkstickConfig.options, function (err) {
led.pulse(blinkstickConfig.color, blinkstickConfig.options, (err) => {
if (err) {
clearAnimationProperties();
return reject('error pulsing color \'' + blinkstickConfig.color + '\' (' + err + ')');
@ -198,7 +198,7 @@ function clearAnimationProperties() {
// stop the current animation
function stopAnimation() {
return new Promise(function (resolve, reject) {
return new Promise((resolve, reject) => {
if (!isAnimationInProgress()) {
return resolve();
}
@ -212,7 +212,7 @@ function waitForAnimation(timestamp, resolve, reject) {
if (!isAnimationInProgress()) {
return resolve();
}
setTimeout(function () {
setTimeout(() => {
waitForAnimation(timestamp, resolve, reject);
}, 100);
}