🔖 Useful template literal tags for dealing with strings in ES2015+
This release is based on the same code that v1.8.1, but it fixes a regression caused by forgetting to run the build before publishing. Thanks @alumni for the hint!
The creator of the package changed the handle from declandewet
to zspecza
, and for a while GitHub was redirecting from the old repo to the new one. This changed with the "takeover" of the original user handle by a random person, and so in this release all the links in package.json are updated to include the new handle.
This is a pre-release. Please help the development of common-tags by testing the common-tags@next version.
Version 2.0.0 is coming. Before it is released however, there are some things to be done - eg. the documentation needs to be rewritten properly for clarity. Maybe the package will be also rewritten into TypeScript? Who knows.
TemplateTag
no longer detects whether the argument is a function and subsequently calls it. This may have been a bit convenient, but at the cost of code clarity, and it was also adding extra complication to the core function that should be as lean as possible: (https://github.com/declandewet/common-tags/commit/0c1c971e59a41fb65a41971537fdbe0cf05ab7a6)createTag
is introduced as a replacement for TemplateTag
. The days of adding new
each time you want to combine some tags are over (https://github.com/declandewet/common-tags/commit/74d10765ea1693a256c1eeadeca355c4f90734e2)onString
, onSubstitution
, onEndResult
) now gets and additional argument: context
. You can initialize its value in the new getInitialContext
hook. This replaces the previously suggested practice of doing something like assigning to this
in a hook. For more insight I recommend reading the tests in the linked commit (https://github.com/declandewet/common-tags/commit/c17c2f02e016c0da79755fbf2279980ad9c8b5a2)id
. It just returns whatever it receives. Again, for more examples for now look into tests in the following commit (https://github.com/declandewet/common-tags/commit/52120bb72007d3afd7c16bdec2c6b166c561e71b)createTag
without a problem (https://github.com/declandewet/common-tags/commit/e3931951c211c475ea54b204a0b54c9c81554b6f)stripIndent
and stripIndents
(https://github.com/declandewet/common-tags/pull/165)html
(aka source aka
codeBlock`) should not cause nasty surprises anymore (https://github.com/declandewet/common-tags/pull/182)createTag
, TemplateTag
is now soft-deprecated. That means you can still use it, but it will print a helpful message that will guide you to the new API (https://github.com/declandewet/common-tags/commit/3ad194684f8e3358a6c042a066da9db745518ac0)valueOf
was called on objects in templates before toString
- now the order is in line with the spec (#144)babel-plugin-transform-runtime
was removed as a dependency and as a result babel-runtime
is not necessary to use common-tags
any more (that means common-tags
is dependency-free!) (#148)common-tags
is now rolling up into a neat bundle that you can get at unpkg. This makes it even easier to get started with this library! (#150)This was a test release to check if common-tags will register properly with unpkg.com.
No major changes in this release, we just migrated from the AVA test runner to Jest, which has mitigated some issues with our CI pipeline speeds and removed some hard to maintain configs.
onString
- transformers now accept an onString
method which runs on each part of the template literal that is not marked as a substitution (i.e. not inside "${}").
replaceStringTransformer(replaceWhat, replaceWith)
Replaces the result of all strings (what's not in ${ ... }
) with a new value. Same as for replaceResultTransformer
, replaceWhat
can be a string or regular expression and replaceWith
is the new value.