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

WIP: Optimize templating #56

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## [Unreleased][unreleased]

## [1.0.4][] - 2021-07-18

- Refactoerd tickplate function
- Updated typings
Comment on lines +7 to +8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Refactoerd tickplate function
- Updated typings
- Refactored tickplate function


## [1.0.3][] - 2021-07-17

- Fix d.ts typings and include typings to package publishing files
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tickplate",
"version": "1.0.3",
"version": "1.0.4",
Copy link
Member

Choose a reason for hiding this comment

The 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",
Expand Down
5 changes: 4 additions & 1 deletion tickplate.d.ts
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[]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We prefer Array<string>

): (values: object) => string;

export = tickplate;
10 changes: 2 additions & 8 deletions tickplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


module.exports = tickplate;