Skip to content

arshadkazmi42/strmat

Repository files navigation

strmat

Build NPM Version NPM Downloads Github Repo Size LICENSE Contributors Commit

Node plugin for string formatting with dynamic values like python

Install

npm install strmat

or

yarn add strmat

Usage

const Strmat = require('strmat');

const string = 'This will {0} using dynamic {1}';
const values = ['format', 'queries'];
const formattedString = Strmat.format(string, values);

// Output:
// This will format using dyamic queries


const string = 'This will {firstKey} using dynamic {secondKey}';
const values = {
  'firstKey': 'format',
  'secondKey': 'queries'
};
const formattedString = Strmat.format(string, values);

// Output:
// This will format using dyamic queries


const string = 'This will not use dynamic values';
const values = {};
const formattedString = Strmat.format(string, values);

// Output
// This will not use dynamic values


const string = 'This will not use dynamic values';
const values = [];
const formattedString = Strmat.format(string, values);

// Output
// This will not use dynamic values


const string = undefined;
const values = ['format'];
const formattedString = Strmat.format(string, values);

// Output
// undefined

Contributing

Interested in contributing to this project? You can log any issues or suggestion related to this library here.

Read our contributing guide to get started with contributing to the codebase.