Latest Socket ResearchMalicious Chrome Extension Performs Hidden Affiliate Hijacking.Details
Socket
Book a DemoInstallSign in
Socket

string-object-formatter

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string-object-formatter

Python inspired named template formatter for Javascript strings

Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

string-object-formatter

Inspired by python named formatter function, replace text inside a string based on object properties names and values.

Example usage

Default delimiters

const Formatter = require('string-object-formatter');
const formatter = new Formatter();
const toFormat = 'My name is {firstName} {lastName}';
const formatted = formatter.format(toFormat, {firstName: 'John', lastName: 'Doe'});

// formatted is 'My name is John Doe'

Custom delimiters

const Formatter = require('string-object-formatter');
const formatter = new Formatter('{{', '}}');
const toFormat = 'My name is {{firstName}} {{lastName}}';
const formatted = formatter.format(toFormat, {firstName: 'John', lastName: 'Doe'});

// formatted is 'My name is John Doe'

Formatter

Kind: global class

new Formatter()

Formatter Class

formatter.format(stringToFormat, formatItems) ⇒ string

Formats string according to object

Kind: instance method of Formatter

ParamTypeDescription
stringToFormatstring
formatItemsobjectEx.: {'toReplace': 'replaced'} turns 'example_{toReplace}' to 'example_replaced'

Formatter.Formatter

Kind: static class of Formatter

new Formatter([startDelimiter], [endDelimiter])

Creates an instance of Formatter.

ParamTypeDefault
[startDelimiter]string"'{'"
[endDelimiter]string"'}'"

Keywords

strings

FAQs

Package last updated on 14 Oct 2020

Did you know?

Socket

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.

Install

Related posts