Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sf

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sf

String formatting library for node.js

  • 0.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.8K
decreased by-15.76%
Maintainers
1
Weekly downloads
 
Created
Source

sf

String formatting library for node.js.

Installation

$ npm install sf

Quick Examples

var sf = require("sf");

sf("{who} has a {what}", { who: 'dog', what: 'tail' });
// returns: dog has a tail

sf("{0} has a {1}", 'dog', 'tail');
// returns: dog has a tail

sf("{0:#,##0.00}", 2123.1);
// returns: 2,123.10

sf("{0,15:#,##0.00}", 2123.1);
// returns:        2,123.10

sf("{a.b}", { a: { b: 'test' }});
// returns: test

sf("{a.z.c}", { a: { b: 'test' }});
// throws an error

sf("{a.?z.?c}", { a: { b: 'test' }});
// returns:

sf("{a[0]}", { a: [ 'foo', 'bar' ]});
// returns: foo

sf("{a[-1]}", { a: [ 'foo', 'bar' ]});
// returns: bar

sf.log("{who} has a {what}", { who: 'dog', what: 'tail' });
// outputs to standard out: dog has a tail

Format Specifiers

The format is similar to C#'s string.format. The text inside the curly braces is {indexOrName[,alignment][:formatString]}. If alignment is positive the text is right aligned. If alignment is negative it will be left aligned.

Object

SpecifierName
jsonJSON.stringify
inspectutil.inspect

Numbers

SpecifierNameExampleOutput
0Zero placeholder{0:00.0000}02.1200
#Digit placeholder{0:#,###}1,234
xLowercase hex{0:x4}01fc
XUppercase hex{0:X4}01FC

Dates

SpecifierNameExample
sdShort date10/12/2002
DLong dateDecember 10, 2002
tShort time10:11 PM
TLong time10:11:29 PM
fdtFull date & timeDecember 10, 2002 10:11 PM
FFull date & time (long)December 10, 2002 10:11:29 PM
gDefault date & time10/12/2002 10:11 PM
GDefault date & time (long)10/12/2002 10:11:29 PM
mdMonth day patternDecember 10
rRFC1123 date stringTue, 10 Dec 2002 22:11:29 +0500
sSortable date string2002-12-10T22:11:29
dDate single digit1
ddDate leading zero01
dddShort day nameMon
ddddLong day nameMonday
fFraction of second (1 digit)1
ffFraction of second (2 digit)24
fffFraction of second (3 digit)345
hHour 12-hour format 1 digit5
hhHour 12-hour format 2 digits05
HHour 24-hour format 1 digit5
HHHour 24-hour format 2 digits05
mmMinutes 2 digits23
MMonth single digit2
MMMonth leading zero02
MMMMonth short nameFeb
MMMMMonth long nameFebruary
ssSeconds 2 digits54
ttAM/PMAM
yyYear 2 digits12
yyyyYear 4 digits2012
zzTime zone offset05
+zzTime zone offset leading ++05
zzzTime zone offset full05:00
zzzzTime zone offset full0500
+zzzzTime zone offset full leading ++0500

Helper Functions

  • sf.log(formatString [, args...]);
  • sf.info(formatString [, args...]);
  • sf.warn(formatString [, args...]);
  • sf.error(formatString [, args...]);

Keywords

FAQs

Package last updated on 08 Mar 2012

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc