Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add util functions for html and css #71

Merged
merged 1 commit into from
Jun 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
`;
}