Skip to content

Commit

Permalink
feat: add util functions for html and css
Browse files Browse the repository at this point in the history
  • Loading branch information
sounmind committed Jun 23, 2024
1 parent ac28b7f commit 16f93e3
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions html-css-utils.js
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>
`;
}

0 comments on commit 16f93e3

Please sign in to comment.