boxwood 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +53 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -493,9 +493,62 @@ function css(inputs) {
|
|
|
493
493
|
}
|
|
494
494
|
}
|
|
495
495
|
|
|
496
|
+
function occurences(input, string) {
|
|
497
|
+
if (string.length <= 0) {
|
|
498
|
+
return input.length + 1
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
let count = 0
|
|
502
|
+
let position = 0
|
|
503
|
+
const step = string.length
|
|
504
|
+
while (true) {
|
|
505
|
+
position = input.indexOf(string, position)
|
|
506
|
+
if (position >= 0) {
|
|
507
|
+
count += 1
|
|
508
|
+
position += step
|
|
509
|
+
} else {
|
|
510
|
+
break
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
return count
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
const validateCSS = (content, character1, character2) => {
|
|
517
|
+
const count1 = occurences(content, character1)
|
|
518
|
+
const count2 = occurences(content, character2)
|
|
519
|
+
if (count1 !== count2) {
|
|
520
|
+
return {
|
|
521
|
+
valid: false,
|
|
522
|
+
message: `Mismatched count of ${character1} and ${character2}`,
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
return { valid: true }
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
const CSS_PAIRS = [
|
|
529
|
+
["{", "}"],
|
|
530
|
+
["(", ")"],
|
|
531
|
+
["[", "]"],
|
|
532
|
+
]
|
|
533
|
+
|
|
534
|
+
function isCSSValid(content) {
|
|
535
|
+
for (const [left, right] of CSS_PAIRS) {
|
|
536
|
+
const { valid, message } = validateCSS(content, left, right)
|
|
537
|
+
if (!valid) {
|
|
538
|
+
return { valid, message: message }
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
return { valid: true }
|
|
543
|
+
}
|
|
544
|
+
|
|
496
545
|
css.load = function (path) {
|
|
497
546
|
const file = path.endsWith(".css") ? path : join(path, "index.css")
|
|
498
547
|
const content = readFile(file, "utf8")
|
|
548
|
+
const { valid, message } = isCSSValid(content)
|
|
549
|
+
if (!valid) {
|
|
550
|
+
throw new Error(`CSSError: invalid CSS for path "${file}": ${message}`)
|
|
551
|
+
}
|
|
499
552
|
return css`
|
|
500
553
|
${content}
|
|
501
554
|
`
|