UNPKG

locutus

Version:

Locutus other languages' standard libraries to JavaScript for fun and educational purposes

17 lines (16 loc) 555 B
import { echo } from "../strings/echo.js"; import { sprintf } from "../strings/sprintf.js"; export function printf(format, ...args) { // discuss at: https://locutus.io/php/printf/ // original by: Ash Searle (https://hexmen.com/blog/) // improved by: Michael White (https://getsprink.com) // improved by: Brett Zamir (https://brett-zamir.me) // example 1: printf("%01.2f", 123.1) // returns 1: 6 const ret = sprintf(format, ...args); if (ret === false) { return 0; } echo(ret); return ret.length; }