Skip to content

Commit

Permalink
Remove template display name
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed Sep 2, 2024
1 parent 530ccd8 commit b8d9aa9
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type Template<T extends object> = (data: T) => string;
/**
* Stringify a template into a function.
*/
export function compile(value: string, displayName = "template") {
export function compile(value: string) {
let result = QUOTE_CHAR;
for (let i = 0; i < value.length; i++) {
const char = value[i];
Expand Down Expand Up @@ -50,16 +50,13 @@ export function compile(value: string, displayName = "template") {
}
result += QUOTE_CHAR;

return `function ${displayName}(${INPUT_VAR_NAME}) { return ${result}; }`;
return `function (${INPUT_VAR_NAME}) { return ${result}; }`;
}

/**
* Fast and simple string templates.
*/
export function template<T extends object = object>(
value: string,
displayName?: string
) {
const body = compile(value, displayName);
export function template<T extends object = object>(value: string) {
const body = compile(value);
return new Function(`return (${body});`)() as Template<T>;
}

0 comments on commit b8d9aa9

Please sign in to comment.