-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add data url support * more complex tests * fix older node * Update lib/data-url.js Co-authored-by: Ryan Zimmerman <[email protected]> Co-authored-by: Ryan Zimmerman <[email protected]>
- Loading branch information
1 parent
2c0c3e9
commit 90e035b
Showing
7 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"use strict" | ||
|
||
const dataURLRegexp = /^data:text\/css;base64,/i | ||
|
||
function isValid(url) { | ||
return dataURLRegexp.test(url) | ||
} | ||
|
||
function contents(url) { | ||
// "data:text/css;base64,".length === 21 | ||
return Buffer.from(url.slice(21), "base64").toString() | ||
} | ||
|
||
module.exports = { | ||
isValid, | ||
contents, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
"use strict" | ||
|
||
const readCache = require("read-cache") | ||
const dataURL = require("./data-url") | ||
|
||
module.exports = filename => readCache(filename, "utf-8") | ||
module.exports = filename => { | ||
if (dataURL.isValid(filename)) { | ||
return dataURL.contents(filename) | ||
} | ||
|
||
return readCache(filename, "utf-8") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
"use strict" | ||
// external tooling | ||
const test = require("ava") | ||
|
||
// internal tooling | ||
const checkFixture = require("./helpers/check-fixture") | ||
|
||
test("should inline data urls", checkFixture, "data-url") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@import url(data:text/css;base64,QGltcG9ydCB1cmwoZGF0YTp0ZXh0L2NzcztiYXNlNjQsY0NCN0lHTnZiRzl5T2lCbmNtVmxianNnZlE9PSk7CgpwIHsgY29sb3I6IGJsdWU7IH0K); | ||
@import url("DATA:TEXT/CSS;BASE64,QGltcG9ydCB1cmwoZGF0YTp0ZXh0L2NzcztiYXNlNjQsY0NCN0lHTnZiRzl5T2lCbmNtVmxianNnZlE9PSk7CgpwIHsgY29sb3I6IGJsdWU7IH0K") layer(foo) (min-width: 320px); | ||
|
||
/* Mixed imports: */ | ||
@import url(data:text/css;base64,QGltcG9ydCB1cmwoZm9vLmNzcyk7CgpwIHsKICBjb2xvcjogYmx1ZTsKfQo=); | ||
@import url(data-url.css); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
p { color: green; } | ||
|
||
p { color: blue; } | ||
|
||
@media (min-width: 320px) { | ||
|
||
@layer foo { | ||
p { color: green; } } } | ||
|
||
@media (min-width: 320px) { | ||
|
||
@layer foo { | ||
|
||
p { color: blue; } } } | ||
|
||
/* Mixed imports: */ | ||
|
||
foo{} | ||
|
||
p { | ||
color: blue; | ||
} | ||
|
||
p { color: pink; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@import url("DATA:text/CSS;BASE64,cCB7IGNvbG9yOiBwaW5rOyB9"); |