Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Format template literals.
This package is distributed via npm:
npm install fmt-tag
Template literals and template tags provide a unique API to build tools around strings. What started as a fun blog post about template tags ended up being this full-fledged library that might hopefully be useful to someone!
You can use this library either as an ES module or a CommonJS package:
import fmt from "fmt-tag";
- or -
const fmt = require("fmt-tag");
Please note that this library uses extensively
Intl
, which is not supported on older browsers (https://caniuse.com/?search=Intl) or Node versions < 16.
You can tag any template literal and append formatting hints right after interpolations to apply specific formatting to that substitutive value.
const name = "Alice";
const money = 20;
console.log(fmt`${name} has ${money}:c(USD) in her pocket!`);
// "Alice has $20 in her pocket!"
The formatting uses the host's default language settings. You can also pass in a specific locale via
fmt.use(locale)
.
Sets a locale to be used when formatting template literals. By default, the formatting will use the host's default language settings.
There are a few formatters available (more to come!).
Key | Options |
---|---|
:c | Any valid currency symbol (e.g. :c(USD) , :c(EUR) , ...) |
Key | Options |
---|---|
:d | - :d(DD-MM-YYYY) => 01/01/1970 - :d(DD-mm-YYYY) => 1 Jan 1970 - :d(DD-mmm-YYYY) => 1 January 1970 - :d(ddd-mmm-YYYY) => Thursday, 1 January 1970 |
Key | Options |
---|---|
:n | Number of digits (e.g. :n(2) => 42.00 ) |
Key | Options |
---|---|
:r | RelativeTimeUnit (e.g. ${-1}:r(weeks) => last week ) |
Key | Options |
---|---|
:s (default) | - :s => No transformation - :s(U) => Uppercase - :s(l) => lowercase |
Key | Options |
---|---|
:t | - :t(HH:mm) => 06:56 - :t(HH:mm aa) => 06:56 am - :t(HH:mm:ss) => 06:56:07 - :t(HH:mm:ss aa) => 06:56:07 am - :t(HH:mm:ss TZ) => 06:56:07 UTC - :t(HH:mm:ss TZ+) => 06:56:07 Coordinated Universal Time |
Thanks to Jack Hsu and his article on implementing an internationalization library using template literals (https://jaysoo.ca/2014/03/20/i18n-with-es2015-template-literals/) for the inspiration!
MIT
FAQs
Format template literals
We found that fmt-tag demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.