tiniest string formatting library
Install from npm:
$ npm install fr --save
// All examples return 'Hello World!'
fr('Hello {0}!', 'World');
fr('{0} {1}!', 'Hello', 'World');
fr('{0} {2}!', 'Hello', 'zalgo', 'World');
fr('{0} {2}!', 'Hello', { hecomes: 'zalgo' }, 'World');
fr('{1} {0}{2}', 'World', 'Hello', '!');
fr('{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}', 'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!');
fr('{0}{1}{2}{2}{3}{4}{5}{6}{7}{8}{9}{10}', 'H', 'e', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!');
fr('Hello {}!', 'World');
fr('Hello {}{1}', 'World', '!');
fr('{greeting} World!', { greeting: 'Hello' });
fr('{0:greeting} World!', { greeting: 'Hello' });
fr('{0:data:greeting} World!', { data: { greeting: 'Hello' }});
fr('{data:greeting} World!', { data: { greeting: 'Hello' }});
fr('{1:data:greeting}{2}{0}!', 'World', { data: { greeting: 'Hello' }} , ' ');
fr('{1:data:greeting} {0:thing}!', { thing: 'World' }, { data: { greeting: 'Hello' }});
var intermediate = fr('{greeting} {thing}!', {greeting: 'Hello'});
fr(intermediate, {thing: 'World'});
var fn1 = fr('Hello {}!');
var fn2 = fr('Hello {}{1}')
var fn3 = fr('Hello {thing}{punctuation}');
fn1('World');
fn2('World', '!');
fn3({ thing: 'World', punctuation: '!' });
MIT © Frederik Ring