Members
GLOBAL
Retrieves the global scope
- Source:
L
Convenient alias for console.log
- Source:
NUMBERS
Character constants
- Source:
shortcut
http://www.openjs.com/scripts/events/keyboard_shortcuts/
Version : 2.01.B
By Binny V A
License : BSD
- Source:
TIMEZONES
For use in the timezone functions
- Source:
Methods
Basename(path)
Simple regex to get the filename portion of a full path.
Thanks to http://planetozh.com/blog/2008/04/javascript-basename-and-dirname/
Parameters:
Name | Type | Description |
---|---|---|
path |
string | The full path of the file. |
- Source:
Bound(value, min, max, defaultvalue)
Limits the number to the range provided.
If value is not a number, then return defaultvalue
Parameters:
Name | Type | Default | Description |
---|---|---|---|
value |
number | The value to limit. | |
min |
number | The minimum allowed value. | |
max |
number | The maximum allowed value. | |
defaultvalue |
number | 0 | The value returned if the original value was not a valid number. |
- Source:
Clone(o)
Deep clones any object. Handy when you want to use a mutable data type
without changing the original
Thanks to https://github.com/davidmarkclements/rfdc
Parameters:
Name | Type | Description |
---|---|---|
o |
object | The object to deep clone. |
- Source:
ColorCode(value, thresholds)
For simple highlighting of values, returns the background color
for a value based upon given thresholds.
The colors run from purple, blue, green, orange, to red, so
thresholds needs to be an array of four values from highest to lowest.
Parameters:
Name | Type | Description |
---|---|---|
value |
number | The value to test |
thresholds |
array | A list of four values from highest to lowest. |
- Source:
CopyValues(objfrom, objto)
Copies all keys and values from newvalues to obj.
Useful for storing multiple CSS styles in a DOM element.
Parameters:
Name | Type | Description |
---|---|---|
objfrom |
object | |
objto |
object |
- Source:
DebugObject(obj, searchterm)
Search for any keys containing searchterm inside obj, printing
the key and value to the console log.
Parameters:
Name | Type | Description |
---|---|---|
obj |
object | The object to search within. |
searchterm |
string | A string that the keyname must contain. |
- Source:
Dirname(path)
Simple regex to get the directory name portion of a full path.
Thanks to http://planetozh.com/blog/2008/04/javascript-basename-and-dirname/
Parameters:
Name | Type | Description |
---|---|---|
path |
string | The full path of the file. |
- Source:
E(selector)
Returns the first element containing this selector.
Parameters:
Name | Type | Description |
---|---|---|
selector |
string | CSS selector |
- Source:
EncodeEntities(str)
Shamelessly stolen from AngularJS to encode HTML entities.
Parameters:
Name | Type | Description |
---|---|---|
str |
string | The string to encode into HTML entities. |
- Source:
EscapeSQL()
Taken from mysql-connector for the web dbapi where we know that
only administrators will use this function.
- Source:
First(obj)
Returns the first property inside an object.
Parameters:
Name | Type | Description |
---|---|---|
obj |
object | The object to look in |
- Source:
FromShortCode(code, chars)
The reverse of ToShortCode(), turning a six character alphanumeric
code into a 32-bit integer
Parameters:
Name | Type | Default | Description |
---|---|---|---|
code |
string | The code to convert | |
chars |
string | 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_ | The character set to use. Make sure that every application that you write uses the same character set, or short codes will not be portable. |
- Source:
GetFileExtension(str)
Returns the extension of a given filename, which is everything
after the last period.
Parameters:
Name | Type | Description |
---|---|---|
str |
string | The string to encode into HTML entities. |
- Source:
GetParentObject(obj)
Returns the prototype of obj, essentially the JavaScript base class.
Parameters:
Name | Type | Description |
---|---|---|
obj |
object | An object to get the prototype of. |
- Source:
HasKey(obj, keyname)
Returns true if the object has a key with the given name.
Parameters:
Name | Type | Description |
---|---|---|
obj |
object | The object to search within |
keyname |
string | The key to search for |
- Source:
I(id)
Returns an element by ID.
Parameters:
Name | Type | Description |
---|---|---|
id |
string | CSS ID selector |
- Source:
InRect(x, y, rect)
Generic function to see if the point (x, y) is inside the rect
(top, right, bottom, left)
Parameters:
Name | Type | Description |
---|---|---|
x |
number | |
y |
number | |
rect |
rect |
- Source:
IsAlpha(stringtotest)
Returns true if the string contains only ASCII alphabetical characters.
Parameters:
Name | Type | Description |
---|---|---|
stringtotest |
string |
- Source:
IsAlphaNum(stringtotest)
Returns true if the string contains only ASCII alphanumeric characters.
Parameters:
Name | Type | Description |
---|---|---|
stringtotest |
string |
- Source:
IsArray(v)
Returns true if v is an array.
Parameters:
Name | Type | Description |
---|---|---|
v |
value |
- Source:
IsAsyncFunc(value)
Returns true if value is an async function.
Parameters:
Name | Type | Description |
---|---|---|
value |
value | The value to examine. |
- Source:
IsEmail(stringtotest)
Returns true if the string appears to be a valid email address.
Thanks to https://codeforgeek.com/how-to-validate-email-address-javascript
Parameters:
Name | Type | Description |
---|---|---|
stringtotest |
string |
- Source:
IsEmpty(value)
Returns true if the value is boolean false, undefined, or is an
empty array or object.
Parameters:
Name | Type | Description |
---|---|---|
value |
value | The value to examine. |
- Source:
IsEqual(a, b)
Returns true if a and b are equal, comparing even lists and objects
Parameters:
Name | Type | Description |
---|---|---|
a |
value | |
b |
value |
- Source:
IsFunc(value)
Returns true if value is a function.
Parameters:
Name | Type | Description |
---|---|---|
value |
value | The value to examine. |
- Source:
IsLower(stringtotest)
Returns true if the string contains only lower case ASCII letters.
Parameters:
Name | Type | Description |
---|---|---|
stringtotest |
string |
- Source:
IsNum(v)
Returns true if v is a number.
Parameters:
Name | Type | Description |
---|---|---|
v |
value |
- Source:
IsNumber(stringtotest)
Returns true if the string contains only numbers.
Parameters:
Name | Type | Description |
---|---|---|
stringtotest |
string |
- Source:
IsObject(v)
Returns true if v is an object.
Parameters:
Name | Type | Description |
---|---|---|
v |
value |
- Source:
IsString(v)
Returns true if v is a string.
Parameters:
Name | Type | Description |
---|---|---|
v |
value |
- Source:
IsUndef(value)
Returns true if value is undefined.
Parameters:
Name | Type | Description |
---|---|---|
value |
value | The value to examine. |
- Source:
IsUpper(stringtotest)
Returns true if the string contains only upper case ASCII letters.
Parameters:
Name | Type | Description |
---|---|---|
stringtotest |
string |
- Source:
Keys(obj)
Returns a list of the key names for an object
Parameters:
Name | Type | Description |
---|---|---|
obj |
object | The object to list keys for. |
- Source:
Last(a)
Returns the last element of an array or 0 otherwise.
Parameters:
Name | Type | Description |
---|---|---|
a |
list | The array to examine. |
- Source:
LocalToUTC(isostring)
Converts a local date string to UTC time.
Parameters:
Name | Type | Description |
---|---|---|
isostring |
string | The local datetime string to convert as a Date object or ISO string. If blank, then returns the current UTC time. |
- Source:
MakeDateReadable(timestring)
Makes a ISO timestring more readable by getting rid of the
characters after seconds and the T between the date and time.
Parameters:
Name | Type | Description |
---|---|---|
timestring |
string | An ISO string, Date object, or integer timestamp. If blank, returns the current local time. |
- Source:
Merge(A)
Merge a number of objects together, with the latter object
properties overwriting the earlier object properties akin to
cascading style sheets.
Parameters:
Name | Type | Description |
---|---|---|
A |
object | variable number of objects to merge from left to right. |
- Source:
PrintTimestamp(timestamp, dateonly)
Returns a datetime string from a timestamp.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
timestamp |
int | The timestamp in seconds instead of milliseconds, so if you use JavaScript's Date.now(), divided by 1000 first. | |
dateonly |
bool | 0 | Returns only the date string and not a whole datetime string. |
- Source:
Q(selector)
Returns all elements containing this selector.
Parameters:
Name | Type | Description |
---|---|---|
selector |
string | CSS selector |
- Source:
RandElement(a)
Returns a random element of an array.
Parameters:
Name | Type | Description |
---|---|---|
a |
array |
- Source:
RandInt(min, max)
Returns a random integer from min to max.
Parameters:
Name | Type | Description |
---|---|---|
min |
int | The minimum value |
max |
int | The maximum value |
- Source:
Range(min, max, step)
A copy of the python range() function, this returns an array of
integers from min to max differing by step.
Parameters:
Name | Type | Description |
---|---|---|
min |
int | |
max |
int | |
step |
int |
- Source:
SaveNestedObject(baseobj, dottedname)
Converts a dot notation such as animals.felines.cats into
animals['felines'] = 'cats'
Parameters:
Name | Type | Description |
---|---|---|
baseobj |
object | The object to store the values in |
dottedname |
string | The |
- Source:
SecondsToTime(numseconds, nohours, precision)
Turns a number of seconds into a hours, minutes, seconds string.
Handy for countdowns and timers.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
numseconds |
number | The total number of seconds | |
nohours |
bool | 0 | Set to true to print only minutes and seconds |
precision |
bool | 0 | The number of digits for fractional seconds. |
- Source:
SetCookie(name, value, numdays, path, domain, secure)
Convenience function to set a cookie in JavaScript. Pafera itself
uses this to set a user's time offset for converting between
GMT and local time on the server side. Only name and value are
required.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The identifier for the cookie |
value |
value | The cookie's contents |
numdays |
int | How many days the cookie is valid for |
path |
string | The valid path for the cookie |
domain |
string | The valid domain for the cookie |
secure |
string | The security for the cookie |
- Source:
Shuffle(a)
Randomly shuffles an array's elements. Be sure to clone a copy if
you still want to use the original array.
Parameters:
Name | Type | Description |
---|---|---|
a |
array | The array to shuffle. |
- Source:
Sleep(ms)
An implementation of other languages' sleep functions through
JavaScript promises.
Parameters:
Name | Type | Description |
---|---|---|
ms |
int | The number of milliseconds to delay execution. |
- Source:
SortArray(obj, ignorecase, level1, level2)
Sorts a JavaScript object based upon its keys and returns a sorted
array of [value, key, obj] pairs. level1 and level2 allow sorting based
upon a key such as obj['animals']['birds']['parrots']
Parameters:
Name | Type | Default | Description |
---|---|---|---|
obj |
object | The object to sort | |
ignorecase |
bool | Set to true to enable case insensitive sorting | |
level1 |
string | 0 | The first key to sort, or blank to do top-level sorting. |
level2 |
string | 0 | The first key to sort, or blank to do level 1 sorting. |
- Source:
StrCmp(a, b, ignorecase)
A copy of the C strcmp() function.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
a |
string | ||
b |
string | ||
ignorecase |
bool | 0 |
- Source:
StrCmpI(a, b)
A copy of the C strcmpi() function.
Parameters:
Name | Type | Description |
---|---|---|
a |
string | |
b |
string |
- Source:
StripTags(str)
Quick and easy regexp to strip HTML tags inside a string.
Parameters:
Name | Type | Description |
---|---|---|
str |
string | The string to encode into HTML entities. |
- Source:
SVGInject()
Defines a SVGInject() function that replaces an img tag with inline
SVG, allowing CSS and JavaScript to be used on the SVG
Use like
<img src="image.svg" onload="SVGInject(this)">
Thanks to https://github.com/iconfu/svg-inject/
- Source:
time()
Copy of the python time.time() function, returns the number of
seconds since the Unix epoch.
- Source:
ToInt(v)
Converts v into a valid int.
Parameters:
Name | Type | Description |
---|---|---|
v |
value | Any value to convert to an int. |
- Source:
ToParams(data)
Converts a dict into query string params. Useful if you need to
construct a query string.
Parameters:
Name | Type | Description |
---|---|---|
data |
object | The dict to convert |
- Source:
ToShortCode(val, chars)
Convert a 32-bit integer into a six character alphanumeric code.
This is used extensively in Pafera to both save space in URLs and to
make IDs more human readable.
Since JavaScript represents all numbers internally as 64-bit doubles,
if you need a 64-bit integer, use two short codes together.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
val |
int | The integer to convert | |
chars |
string | 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_ | The character set to use. Make sure that every application that you write uses the same character set, or short codes will not be portable. |
- Source:
UTCToLocal(isostring)
Converts an UTC ISO date string to local time.
Parameters:
Name | Type | Description |
---|---|---|
isostring |
string | The date to convert in ISO 8601 format as an date object or ISO string. If blank, then returns the current local time. If it's an integer, then interprets it as a timestamp. |
- Source:
uuid()
Defines a uuid() function that can be used to return unique IDs.
Thanks to https://github.com/jchook/uuid-random/blob/master/uuid-random.min.js
- Source:
ValidString(stringtotest, allowedcharacters)
Returns true if the string contains only the allowed characters.
Parameters:
Name | Type | Description |
---|---|---|
stringtotest |
string | |
allowedcharacters |
string |
- Source:
Values(obj)
Returns a list of the values for an object excluding functions.
Parameters:
Name | Type | Description |
---|---|---|
obj |
object | The object to list values for. |
- Source: