-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add util functions for html and css
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Processes a template literal to combine strings and interpolated values into a single HTML string. | ||
* | ||
* @param {TemplateStringsArray} strings - An array of string literals. | ||
* @param {...string} values - Interpolated values within the template literal. | ||
* @returns {string} The combined HTML string. | ||
*/ | ||
export function html(strings, ...values) { | ||
let htmlString = strings[0]; | ||
|
||
for (let i = 0; i < values.length; i++) { | ||
htmlString += values[i] + strings[i + 1]; | ||
} | ||
|
||
return htmlString; | ||
} | ||
|
||
/** | ||
* Processes a template literal to combine strings and interpolated values into a single CSS string. | ||
* | ||
* @param {TemplateStringsArray} strings - An array of string literals. | ||
* @param {...string} values - Interpolated values within the template literal. | ||
* @returns {string} The combined CSS string. | ||
*/ | ||
export function css(strings, ...values) { | ||
const GlobalCSS = `<link rel="stylesheet" href="./global-styles.css" />`; | ||
|
||
return html` | ||
${GlobalCSS} | ||
<style> | ||
${html(strings, ...values)} | ||
</style> | ||
`; | ||
} |