source: frontend/node_modules/postcss-merge-longhand/src/lib/validateWsc.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.4 KB
Line 
1'use strict';
2const colors = require('./colornames.js');
3
4const widths = new Set(['thin', 'medium', 'thick']);
5const styles = new Set([
6 'none',
7 'hidden',
8 'dotted',
9 'dashed',
10 'solid',
11 'double',
12 'groove',
13 'ridge',
14 'inset',
15 'outset',
16]);
17
18/**
19 * @param {string} value
20 * @return {boolean}
21 */
22function isStyle(value) {
23 return value !== undefined && styles.has(value.toLowerCase());
24}
25
26/**
27 * @param {string} value
28 * @return {boolean}
29 */
30function isWidth(value) {
31 return (
32 (value && widths.has(value.toLowerCase())) ||
33 /^(\d+(\.\d+)?|\.\d+)(\w+)?$/.test(value)
34 );
35}
36
37/**
38 * @param {string} value
39 * @return {boolean}
40 */
41function isColor(value) {
42 if (!value) {
43 return false;
44 }
45
46 value = value.toLowerCase();
47
48 if (/rgba?\(/.test(value)) {
49 return true;
50 }
51
52 if (/hsla?\(/.test(value)) {
53 return true;
54 }
55
56 if (/#([0-9a-z]{6}|[0-9a-z]{3})/.test(value)) {
57 return true;
58 }
59
60 if (value === 'transparent') {
61 return true;
62 }
63
64 if (value === 'currentcolor') {
65 return true;
66 }
67
68 return colors.has(value);
69}
70
71/**
72 * @param {[string, string, string]} wscs
73 * @return {boolean}
74 */
75function isValidWsc(wscs) {
76 const validWidth = isWidth(wscs[0]);
77 const validStyle = isStyle(wscs[1]);
78 const validColor = isColor(wscs[2]);
79
80 return (
81 (validWidth && validStyle) ||
82 (validWidth && validColor) ||
83 (validStyle && validColor)
84 );
85}
86
87module.exports = { isStyle, isWidth, isColor, isValidWsc };
Note: See TracBrowser for help on using the repository browser.