Last active
October 14, 2019 07:48
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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