A JavaScript implementation of VBScript's Format function, providing similar string formatting capabilities.
npm install vbscript-format
import { format } from "vbscript-format";
// Date formatting
const date = new Date("2023-03-15T14:30:45");
format(date, "dd/mm/yyyy"); // "15/03/2023"
format(date, "mmm dd, yyyy"); // "Mar 15, 2023"
format(date, "hh:nn:ss"); // "14:30:45"
// Number formatting
format(1234.56, "$"); // "$1,234.56"
format(0.1234, "%"); // "12.34%"
format(1234.5678, ".2"); // "1234.57"
format(1234567, ","); // "1,234,567"
// String formatting
format("hello", ">"); // "HELLO"
format("HELLO", "<"); // "hello"
format("hello", "{10}"); // "hello "
-
d
,dd
: Day of month (1-31) -
ddd
: Abbreviated day name (Sun-Sat) -
dddd
: Full day name (Sunday-Saturday) -
m
,mm
: Month (1-12) -
mmm
: Abbreviated month name (Jan-Dec) -
mmmm
: Full month name (January-December) -
y
,yy
,yyyy
: Year (1, 2, or 4 digits) -
h
,hh
: Hours (0-23) -
n
,nn
: Minutes (0-59) -
s
,ss
: Seconds (0-59) -
t
,tt
: AM/PM indicator
-
$
: Currency format -
%
: Percentage format -
.n
: Decimal places -
,
: Thousands separator
-
>
: Convert to uppercase -
<
: Convert to lowercase -
{n}
: Pad string to length n
MIT