Class: Format

Format()

Format is a singleton that provides various formatting functions.

Constructor

new Format()

Source:

Members

(static) alphaToPhoneNumeric

Takes a string input and converts A-Z to their respective phone number character `1800CALLME` -> `1800225563`
Source:

(static) bytesText

Properties:
Name Type Description
Text String used in file size formatter
Source:

(static) canvasDraw

Takes a 2D array of `[[x,y],[x,y]]` number coordinates and draws them onto the provided canvas The first point marks where the "pen" starts, each sequential point is then "drawn to" as if holding a pen on paper and moving the pen to the new point.
Source:

(static) decode

Takes a String and decodes `&`, `<`, `>`, `"` from HTML entities back to the character
Source:

(static) encode

Takes a String and encodes `&`, `<`, `>`, `"`, `'`, and `/` to HTML entities
Source:

(static) falseText

Properties:
Name Type Description
Text String used in bool formatter for false values
Source:

(static) fixed

Takes a number and decimal place and floors the number to that place: `fixed(5.555, 0)` => `5` `fixed(5.555, 2)` => `5.55` `fixed(5.555, 5)` => `5.555`
Source:

(static) hoursText

Properties:
Name Type Description
Text String used in timespan formatter for more than one hour
Source:

(static) hourText

Properties:
Name Type Description
Text String used in timespan formatter for exactly one hour
Source:

(static) imageFromVector

Returns the image data (or img element) for a series of vectors
Source:

(static) isEmpty

Determines if the given item is an empty string or empty arry
Source:

(static) mail

Takes an email string and wraps it with an `` element with `href="mailto:"` pointing to the email.
Source:

(static) minutesText

Properties:
Name Type Description
Text String used in timespan formatter for more than one minute
Source:

(static) minuteText

Properties:
Name Type Description
Text String used in timespan formatter for exactly one minute
Source:

(static) nl2br

Takes a string and converts all new lines `\n` to HTML `
` elements.
Source:

(static) noText

Properties:
Name Type Description
Text String used in yesNo formatter for false values
Source:

(static) percentFormatText

Properties:
Name Type Description
format String string for percent * `${0}` - percent value * `${1}` - percent synmbol "%"
Source:

(static) phone

Takes a string phone input and attempts to match it against the predefined phone formats - if a match is found it is returned formatted if not it is returned as is.
Source:

(static) phoneFormat

Properties:
Name Type Description
Array Array.<Object> of objects that have the keys `test` and `format` where `test` is a RegExp that matches the phone grouping and `format` is the string format to be replaced. The RegExp may have capture groups but when you are defining the format strings use: * `${0}` - original value * `${1}` - cleaned value * `${2}` - entire match (against clean value) * `${3..n}` - match groups (against clean value) The `clean value` is taking the inputted numbers/text and removing any non-number and non-"x" and it replaces A-Z to their respective phone number character. The three default formatters are: * `nnn-nnnn` * `(nnn)-nnn-nnnn` * `(nnn)-nnn-nnnxnnnn` If you plan to override this value make sure you include the default ones provided.
Source:

(static) trim

Removes whitespace from from and end of string
Source:

(static) trueText

Properties:
Name Type Description
Text String used in bool formatter for true values
Source:

(static) yesText

Properties:
Name Type Description
Text String used in yesNo formatter for true values
Source:

Methods

(static) bool(val) → {String}

Takes a boolean value and returns the string T or F for true or false
Parameters:
Name Type Description
val Boolean/String If string it tests if the string is `true` for true, else assumes false
Source:
Returns:
T for true, F for false.
Type
String

(static) date(val, fmt, utc) → {String}

Takes a date and format string and returns the formatted date as a string.
Parameters:
Name Type Description
val Date/String Date to be converted. If string is passed it is converted to a date using Converts toDateFromString.
fmt String Format string following [datejs formatting](http://code.google.com/p/datejs/wiki/FormatSpecifiers).
utc Boolean If a date should be in UTC time set this flag to true to counter-act javascripts built-in timezone applier.
Source:
Returns:
Date formatted as a string.
Type
String
Takes a url string and wraps it with an `` element with `href=` pointing to the url.
Parameters:
Name Type Description
val String Url string to be wrapped
Source:
Returns:
Type
String

(static) percent(val, places) → {String}

Takes a decimal number, multiplies by 100 and adds the % sign with the number of palces to the right. `perecent(0.35)` => `'35.00%'` `perecent(0.35, 0)` => `'35%'` `percent(2.9950)` => `'299.50%'` `percent(2.9950,0)` => `'300%'`
Parameters:
Name Type Description
val Number/String The value will be `parseFloat` before operating.
places Number/String If no value is given the default value will be set to 2.
Source:
Returns:
Number as a percentage with % sign.
Type
String

(static) timespan(val) → {String}

Takes a number of minutes and turns it into the string: `'n hours m minutes'`
Parameters:
Name Type Description
val Number/String Number of minutes, will be `parseFloat` before operations and fixed to 2 decimal places
Source:
Returns:
A string representation of the minutes as `'n hours m minutes'`
Type
String

(static) yesNo(val) → {String}

Takes a boolean value and returns the string Yes or No for true or false
Parameters:
Name Type Description
val Boolean/String If string it tests if the string is `true` for true, else assumes false
Source:
Returns:
Yes for true, No for false.
Type
String