Socket
Socket
Sign inDemoInstall

fr

Package Overview
Dependencies
0
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    fr

tiniest string formatting library


Version published
Weekly downloads
211
increased by18.54%
Maintainers
2
Install size
7.73 kB
Created
Weekly downloads
 

Readme

Source

fr

tiniest string formatting library

Build Status

Installation:

Install from npm:

$ npm install fr --save

Usage:

Index based token replacement:
// 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', '!');

Empty index uses 0:
fr('Hello {}!', 'World');
fr('Hello {}{1}', 'World', '!');
String tokens and access of nested object properties:
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' }});
Unknown tokens will not be replaced:
var intermediate =  fr('{greeting} {thing}!', {greeting: 'Hello'});
fr(intermediate, {thing: 'World'});
Precompiling:
var fn1 = fr('Hello {}!');
var fn2 = fr('Hello {}{1}')
var fn3 = fr('Hello {thing}{punctuation}');
fn1('World');
fn2('World', '!');
fn3({ thing: 'World', punctuation: '!' });

License

MIT © Frederik Ring

Keywords

FAQs

Last updated on 26 Oct 2016

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc