validateWsc.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.isStyle = isStyle;
  6. exports.isWidth = isWidth;
  7. exports.isColor = isColor;
  8. exports.isValidWsc = isValidWsc;
  9. var _cssColorNames = require("css-color-names");
  10. var _cssColorNames2 = _interopRequireDefault(_cssColorNames);
  11. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12. const widths = ["thin", "medium", "thick"];
  13. const styles = ["none", "hidden", "dotted", "dashed", "solid", "double", "groove", "ridge", "inset", "outset"];
  14. const colors = Object.keys(_cssColorNames2.default);
  15. function isStyle(value) {
  16. return value && !!~styles.indexOf(value.toLowerCase());
  17. }
  18. function isWidth(value) {
  19. return value && !!~widths.indexOf(value.toLowerCase()) || /^(\d+(\.\d+)?|\.\d+)(\w+)?$/.test(value);
  20. }
  21. function isColor(value) {
  22. if (!value) {
  23. return false;
  24. }
  25. value = value.toLowerCase();
  26. if (/rgba?\(/.test(value)) {
  27. return true;
  28. }
  29. if (/hsla?\(/.test(value)) {
  30. return true;
  31. }
  32. if (/#([0-9a-z]{6}|[0-9a-z]{3})/.test(value)) {
  33. return true;
  34. }
  35. if (value === "transparent") {
  36. return true;
  37. }
  38. if (value === "currentcolor") {
  39. return true;
  40. }
  41. return !!~colors.indexOf(value);
  42. }
  43. function isValidWsc(wscs) {
  44. const validWidth = isWidth(wscs[0]);
  45. const validStyle = isStyle(wscs[1]);
  46. const validColor = isColor(wscs[2]);
  47. return validWidth && validStyle || validWidth && validColor || validStyle && validColor;
  48. }