-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
84 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,38 @@ | ||
/* node:coverage disable */ | ||
|
||
import test, { describe } from 'node:test'; | ||
import assert from 'node:assert'; | ||
|
||
import { css } from './css.js'; | ||
|
||
describe('css string template utility', async () => { | ||
test('simple css string', () => { | ||
assert.equal( | ||
css` | ||
body { | ||
color: red; | ||
} | ||
`, | ||
` | ||
body { | ||
color: red; | ||
} | ||
` | ||
); | ||
}); | ||
test('simple css string with variable', () => { | ||
const color = 'red'; | ||
assert.equal( | ||
css` | ||
body { | ||
color: ${color}; | ||
} | ||
`, | ||
` | ||
body { | ||
color: red; | ||
} | ||
` | ||
); | ||
}); | ||
}); |
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 @@ | ||
/** | ||
* String template utility that adds syntax highlighting and formatting in text editors. | ||
* | ||
* @param {TemplateStringsArray} strings | ||
* @param {any[]} values | ||
*/ | ||
|
||
export const css = (strings: TemplateStringsArray, ...values: any[]) => { | ||
const processedValues = values.map(value => | ||
Array.isArray(value) ? value.join('') : value | ||
); | ||
|
||
return strings.reduce( | ||
(prev, curr, i) => `${prev}${curr}${processedValues[i] || ''}`, | ||
'' | ||
); | ||
}; |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export { css } from './css.js'; | ||
export { html } from './html.js'; |