-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
WIP: Optimize templating #56
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "tickplate", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto |
||
"author": "Timur Shemsedinov <[email protected]>", | ||
"description": "Back-tick templates for JavaScript", | ||
"license": "MIT", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
declare function tickplate(strings: Array<string>, ...keys: Array<string>): (values: object) => string; | ||
declare function tickplate( | ||
strings: TemplateStringsArray, | ||
...keys: string[] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We prefer |
||
): (values: object) => string; | ||
|
||
export = tickplate; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,7 @@ | |
|
||
const tickplate = | ||
(strings, ...keys) => | ||
(values) => { | ||
const result = [strings[0]]; | ||
for (let i = 0; i < keys.length; i++) { | ||
const key = keys[i]; | ||
result.push(values[key], strings[i + 1]); | ||
} | ||
return result.join(''); | ||
}; | ||
(values) => | ||
String.raw(strings, ...keys.map((key) => values[key] ?? '')); | ||
Comment on lines
+5
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
module.exports = tickplate; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.