Generic javascript utilities.
Methods
checkExtension(name, extopt) → {string}
Checks a filename to see if it has the right extension and adds the extension if it doesn't. The default extension is 'js'.
Parameters
-
name
string
The filename to check.
-
ext
string
<optional>
'js'The extension to add if missing.
Returns
-
string
- The filename with the correct extension.
Source
commonInitialSlice(…arrays) → {Array}
Find the longest common initial slice of a set of arrays.
Parameters
-
arrays
Array
<repeatable>
The arrays to compare.
Returns
-
Array
- The longest common initial slice of the arrays.
Source
indent(s, n) → {string}
Indent string $s$ with a tab of $n$ spaces. If $s$ contains multiple lines, indent each line.
Parameters
-
s
string
the string to indent
-
n
number
the number of spaces to indent
Returns
-
string
the resulting string
Source
lineNum(n, widthopt, suffixopt) → {string}
Returns a right justified line number consisting of a minimum width padded on the right with a given suffix.
Parameters
-
n
number
The line number.
-
width
number
<optional>
4The minimum width of the line number.
-
suffix
string
<optional>
': 'The suffix to be added to the line number.
Returns
-
string
The right justified line number.
Source
rgb2hex()
Convert RGB to HEX
Source
subscript(n)
Convert the integer $n$ to a string consisting of the corresponding unicode subscript.
Parameters
-
n
number
The integer to be converted.
Source
tab(n, charopt) → {string}
Return a string of $n$ spaces (or other character).
Parameters
-
n
number
the length of the string
-
char
string
<optional>
' 'the character to use
Returns
-
string
the resulting string
Source
timer()
Report the time it took to execute function f
, passed as an argument.