A flexible string format library that is a part of the @fluentfixture project.
Introduction
A flexible string format library that is a part of the @fluentfixture project. Provides formatting and compiling functionalities with extensible transformation capabilities.
Installation
$ npm install @fluentfixture/format
Usage
The @fluentfixture/format utilities can be used with global format
and compile
methods or a new Formatter
instance. The following code snippet shows an example usage of global compile
method.
The more example can be found on How To Use section.
import { format } from '@fluentfixture/format';
const source = {
name: 'john',
surname: 'doe',
birthdate: new Date(1_617_258_460_000), // GMT: Thursday, 1 April 2021 06:27:40
};
// format() returns a formatted string immediately.
console.log(
format('${surname:upperCase()}, ${name:capitalCase()} BIRTH_DATE=${birthdate:date("MM-DD-YYYY")}', source),
);
// compile() returns a pre-compiled template for reusing.
const template = compile('${name:capitalCase()}, ${age:default("N/A")} >> ${colors:join("+")}');
console.log(
template.format({
name: 'john',
age: 32,
colors: ['red', 'black']
})
);
Documentation
To check out the guide, visit https://docs.fluentfixture.com/
License
@fluentfixture is MIT licensed.