Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

exframe-string-formatters

exzeo-usa237ISC1.5.2

exframe-string-formatters

readme

exframe-string-formatters

A collection of various functions that create formatted strings (e.g. currency, date, etc). This module was created as a compliment to JSON Transpose to provide common formatting functions compatible with the customObjects parameter, but can be used independently if desired.

Date formatters are using moment-timezone, see the docs for details about supported format string.

Currency formatters are using Intl.NumberFormat and support the same options.

Usage

const { formatPhoneNumber } = require('exframe-string-formatters');

console.log(formatPhoneNumber(5558675309));
$ node example.js
(555) 867-5309

Using with JSON Transpose

This module exports an object that can be passed directly to the customObjects parameter of JSON Transpose.

const stringFormatters = require('exframe-string-formatters');
const { compile } = require('json-transpose');

const transform = compile({
  totalCost: '${formatPhoneNumber(it.primaryPhone)}'
}, {
  customObjects: stringFormatters
});

const transformed = transform({
  primaryPhone: 5558675309
});

console.log(transformed);
$ node example.js
{ primaryPhone: '(555) 867-5309' }