Last Updated | | Ratings | | Unique User Downloads | | Download Rankings |
2016-05-11 (5 months ago) | | 68% | | Total: 93 | | All time: 391 This week: 13 |
|
Description | | Author |
This object can format text string according to a pattern.
It adds a prototype to an object that can format a text string expanding certain marks in a given format.
The format marks can determine if the input parameters should be taken as text or numbers. Numbers can be formatted as decimal, hexadecimal or octal.
The formatted values can be justified with spaces and aligned to the left or right. Innovation Award
May 2016
Number 2 |
Most languages provide standard libraries that allow string manipulation operations like formatting a text string with a list of parameters values. However, JavaScript does not come with any built-in objects for that purpose.
This package can add a prototype to an object to let it format strings in a similar way to sprintf functions of other functions.
Manuel Lemos |
| |
|
|
Innovation award
Nominee: 1x |
|
Details
Syntax
Each function call requires a format string and a list of arguments. The format string can be a fixed text string or one or more inlays that specify the format. Format specifiers begin and end in braces {...}.
The general format for formatting strings or numbers is:
{argument_index[$[align]['char][width]conversion[arguments][/objet_property]]}
- argument_index: (required) is the unsigned integer indicating the index of the argument to take from the list. The index is numbered from zero to n (0, 1, 2, 3 ... n).
- align: (optional) character - (minus) indicates that the text is aligned to the left.
- char: (optional) a character with the apostrophe prefix, fill in the result when the width indicated.
- width: (optional) is the unsigned integer indicating the filling result.
- conversion: (required if) Conversion argument to be formatted. "s" used to string and default if not indicated. "n" used to format numbers.
- arguments: see below.
- object_property: if the argument is an object that allows him to read a property. The point separates sub properties.
Arguments for numbers (n)
The following table shows the supported arguments.
| Flag | Description |
|------|-------------------------------------------------------------|
| + | The result will always include a sign |
| # | The result will include a leading space for positive values |
| , | The result will include locale-specific grouping separators |
|
Applications that use this package |
|
No pages of applications that use this class were specified.
If you know an application of this package, send a message to the author to add a link here.