String.prototype.padLeft / String.prototype.padRight
alex at weej.com
Mon Nov 16 13:01:36 UTC 2015
I see about as little use case for this as `String.prototype.blink`.
Date/hours is better solved with zero padding formatting, not just padding
out the already stringified number (think negative values -000042). Same
applies to filenames for lexicographical sort. Fixed length fields in wire
protocols already need to be converted to bytes first before padding, which
makes the use of this feature impossible.
On Monday, 16 November 2015, Claude Pache <claude.pache at gmail.com> wrote:
> Here are my typical use cases (found by scanning uses of "str_pad" in my
> PHP codebase):
> * transferring data through a protocol that uses fix-length fields;
> * formatting things like date/hours, e.g. "08:00" for "8am";
> * generating filenames of fixed length, so that they sort correctly, e.g.
> * generating codes of fixed length (e.g. barcodes).
> In all those cases, the set of characters is typically limited to ASCII or
> Moreover, the filler string consists always of one ASCII character
> (usually " " or "0").
> es-discuss mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss