@fluentfixture/format
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

Fluent Fixture Logo

A flexible string format library that is a part of the @fluentfixture project.

NPM Version Package License CircleCI Coverage Known Vulnerabilities CodeFactor Open in CodeSandbox Open in CodeSandbox

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.

Package Sidebar

Install

npm i @fluentfixture/format

Weekly Downloads

4

Version

1.0.5

License

MIT

Unpacked Size

89 kB

Total Files

103

Last publish

Collaborators

  • scokmen