mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 18:25:24 +00:00
Added isValidRGB function
This commit is contained in:
18
index.js
18
index.js
@@ -503,6 +503,24 @@ class Pass {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an rgb value is compliant with CSS-like syntax
|
||||
*
|
||||
* @function isValidRGB
|
||||
* @params {String} value - string to analyze
|
||||
* @returns {Boolean} True if valid rgb, false otherwise
|
||||
*/
|
||||
|
||||
function isValidRGB(value) {
|
||||
let rgb = value.match(/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/);
|
||||
|
||||
if (!rgb) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return rgb.slice(1,4).every(v => Math.abs(Number(v)) <= 255);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a date to W3C Standard format
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user