source: trip-planner-front/node_modules/postcss-merge-longhand/dist/lib/validateWsc.js@ 59329aa

Last change on this file since 59329aa was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.4 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.isStyle = isStyle;
7exports.isWidth = isWidth;
8exports.isColor = isColor;
9exports.isValidWsc = isValidWsc;
10
11var _cssColorNames = _interopRequireDefault(require("css-color-names"));
12
13function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
15const widths = ['thin', 'medium', 'thick'];
16const styles = ['none', 'hidden', 'dotted', 'dashed', 'solid', 'double', 'groove', 'ridge', 'inset', 'outset'];
17const colors = Object.keys(_cssColorNames.default);
18
19function isStyle(value) {
20 return value && !!~styles.indexOf(value.toLowerCase());
21}
22
23function isWidth(value) {
24 return value && !!~widths.indexOf(value.toLowerCase()) || /^(\d+(\.\d+)?|\.\d+)(\w+)?$/.test(value);
25}
26
27function isColor(value) {
28 if (!value) {
29 return false;
30 }
31
32 value = value.toLowerCase();
33
34 if (/rgba?\(/.test(value)) {
35 return true;
36 }
37
38 if (/hsla?\(/.test(value)) {
39 return true;
40 }
41
42 if (/#([0-9a-z]{6}|[0-9a-z]{3})/.test(value)) {
43 return true;
44 }
45
46 if (value === 'transparent') {
47 return true;
48 }
49
50 if (value === 'currentcolor') {
51 return true;
52 }
53
54 return !!~colors.indexOf(value);
55}
56
57function isValidWsc(wscs) {
58 const validWidth = isWidth(wscs[0]);
59 const validStyle = isStyle(wscs[1]);
60 const validColor = isColor(wscs[2]);
61 return validWidth && validStyle || validWidth && validColor || validStyle && validColor;
62}
Note: See TracBrowser for help on using the repository browser.