Skip to content

Instantly share code, notes, and snippets.

@robwelan
Last active October 14, 2019 07:48
Show Gist options
  • Save robwelan/14354bd8394cea0a9162a401ba3683be to your computer and use it in GitHub Desktop.
Save robwelan/14354bd8394cea0a9162a401ba3683be to your computer and use it in GitHub Desktop.
the utility referenced by cot-blog-react-component-parallax.jsx (gist:robwelan/14354bd8394cea0a9162a401ba3683be#cot-blog-utilities-validation-parallax.js)
const validation = {
default: {
color: 255,
alpha: 0.4,
},
color(color) {
let validColor = this.default.color;
if (!Number.isNaN(color)) {
if (color < 0) {
validColor = 0;
} else if (color > 255) {
validColor = 255;
} else {
validColor = color;
}
}
return validColor;
},
alpha(alpha) {
let validAlpha = this.default.alpha;
if (!Number.isNaN(alpha)) {
if (alpha < 0) {
validAlpha = 0;
} else if (alpha > 1) {
validAlpha = 1;
} else {
validAlpha = alpha;
}
}
return validAlpha;
},
};
export default validation;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment