Skip to content

Commit

Permalink
fix: (typescript) generator and async generator types
Browse files Browse the repository at this point in the history
  • Loading branch information
gurgunday committed Aug 21, 2024
1 parent 25fba8e commit 8f33927
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"devDependencies": {
"@fastify/pre-commit": "^2.1.0",
"c8": "^10.1.2",
"grules": "^0.23.0",
"tinybench": "^2.8.0",
"grules": "^0.23.3",
"tinybench": "^2.9.0",
"typescript": ">=5.5.4"
},
"repository": {
Expand Down
25 changes: 14 additions & 11 deletions src/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ const escapeFunction = (string) => {
};

/**
* @param {{ raw: Readonly<string[]> }} literals Tagged template literals.
* @param {TemplateStringsArray} literals Tagged template literals.
* @param {...any} expressions Expressions to interpolate.
* @returns {string} The HTML string.
* @returns {string} The processed HTML string.
*/
const html = ({ raw: literals }, ...expressions) => {
export const html = ({ raw: literals }, ...expressions) => {
let accumulator = "";

for (let i = 0; i !== expressions.length; ++i) {
Expand Down Expand Up @@ -72,11 +72,12 @@ const html = ({ raw: literals }, ...expressions) => {
};

/**
* @param {{ raw: Readonly<string[]> }} literals Tagged template literals.
* @param {TemplateStringsArray} literals Tagged template literals.
* @param {...any} expressions Expressions to interpolate.
* @yields {string} The HTML strings.
* @yields Processed HTML strings.
* @returns {Generator<string, void, void>} The HTML generator.
*/
const htmlGenerator = function* ({ raw: literals }, ...expressions) {
export const htmlGenerator = function* ({ raw: literals }, ...expressions) {
for (let i = 0; i !== expressions.length; ++i) {
let expression = expressions[i];
let literal = literals[i];
Expand Down Expand Up @@ -166,11 +167,15 @@ const htmlGenerator = function* ({ raw: literals }, ...expressions) {
};

/**
* @param {{ raw: Readonly<string[]> }} literals Tagged template literals.
* @param {TemplateStringsArray} literals Tagged template literals.
* @param {...any} expressions Expressions to interpolate.
* @yields {string} The HTML strings.
* @yields Processed HTML strings.
* @returns {AsyncGenerator<string, void, void>} The HTML generator.
*/
const htmlAsyncGenerator = async function* ({ raw: literals }, ...expressions) {
export const htmlAsyncGenerator = async function* (
{ raw: literals },
...expressions
) {
for (let i = 0; i !== expressions.length; ++i) {
let expression = await expressions[i];
let literal = literals[i];
Expand Down Expand Up @@ -261,5 +266,3 @@ const htmlAsyncGenerator = async function* ({ raw: literals }, ...expressions) {
yield literals[expressions.length];
}
};

export { html, htmlGenerator, htmlAsyncGenerator };

0 comments on commit 8f33927

Please # to comment.