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

Export template function #8

Merged
merged 3 commits into from
Mar 4, 2022
Merged

Export template function #8

merged 3 commits into from
Mar 4, 2022

Conversation

GeorgeTaveras1231
Copy link
Contributor

This facilitates wrapping template behavior in other functions, and not needing to reference the tag function in many places.

In my case, I've created custom Console class that can be configured to have different prefixes, I'd like to be able to instantiate the class with a color template without needing to import chalk or chalk-template in multiple places

const scopedConsole = new Console(/*Prefix*/'{blue SomePrefix}')

This facilitates wrapping template behavior in other functions, and not needing to reference the tag function in many places.
@sindresorhus
Copy link
Member

I'm indifferent to exposing this. Deferring to @Qix-. However, this will need tests, docs, and TS types for it to be mergable.

@Qix-
Copy link
Member

Qix- commented Feb 26, 2022

Exposing it is fine, but agreed, needs tests, types and docs.

Docs need to mention that all input needs to be properly escaped - a lot of the "safety" comes from using tagged literals.

Additionally add typescript as a dev dependency
@GeorgeTaveras1231
Copy link
Contributor Author

@Qix- @sindresorhus I've updated the branch to include tests, types, and docs. I was a little unsure about what to do but welcome any feedback. I also added typescript as a dev dependency because it seemed that npm test requires typescript.

@Qix- Qix- merged commit e5a2993 into chalk:main Mar 4, 2022
@Qix-
Copy link
Member

Qix- commented Mar 4, 2022

Thank you :) Published as 0.4.0

sindresorhus added a commit that referenced this pull request Mar 5, 2022
```
import { template } from 'chalk-template';

log(template('Today is {red hot}')
Copy link
Member

Choose a reason for hiding this comment

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

Multiple typos


@example
```
import { template } from 'chalk-template';
Copy link
Member

Choose a reason for hiding this comment

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

Does not follow the existing code style.

@@ -49,6 +49,7 @@
"ava": "^3.15.0",
"cross-env": "^7.0.3",
"tsd": "^0.18.0",
"typescript": "^4.6.2",
Copy link
Member

Choose a reason for hiding this comment

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

Don't make unrelated changes.

@@ -58,6 +58,16 @@ Note that function styles (`rgb()`, etc.) may not contain spaces between paramet

All interpolated values (`` chalkTemplate`${foo}` ``) are converted to strings via the `.toString()` method. All curly braces (`{` and `}`) in interpolated value strings are escaped.

## Template function

Copy link
Member

Choose a reason for hiding this comment

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

Readme is not in sync with index.d.ts

@sindresorhus
Copy link
Member

Docs need to mention that all input needs to be properly escaped - a lot of the "safety" comes from using tagged literals.

This was not done.

@sindresorhus
Copy link
Member

I cleaned this up in bf830d7.

@Qix-
Copy link
Member

Qix- commented Mar 6, 2022

Whoops sorry @sindresorhus, missed the mark on this one. Thanks for cleaning it up.

midzelis pushed a commit to midzelis/chalk-template that referenced this pull request Jun 13, 2023
* Export template function

This facilitates wrapping template behavior in other functions, and not needing to reference the tag function in many places.

* Add tests and types

Additionally add typescript as a dev dependency

* Update README
midzelis pushed a commit to midzelis/chalk-template that referenced this pull request Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants