quixot-js
the missing javascript library
quixot.js mission is to provide a set of stable cross-platform and cross-engine features
what's new in version 1.0.2
- safer Logger configuration via URL access key
- Util.aton method
- Cache instances lifetime support
- Event namespace
- Mingui namespace (full support for browsers, beta-testing java options)
- Time namespace
object
quixot : Kind: global namespace
- quixot :
object
- .require
- .Fingerprint :
object
- .data() ⇒
Object
- .identifier() ⇒
String
- .text() ⇒
String
- .numbers() ⇒
String
- .data() ⇒
- .Event :
object
- .APPOINTMENT_DONE
- .dispatch(name) ⇒
Number
- .hasListener(eventName, uidName) ⇒
Boolean
- .addListener(eventName, callback, uidName) ⇒
Object
- .removeListener(eventName, uidName) ⇒
boolean
- .getAll() ⇒
Object
- .appoint(callback, delay) ⇒
Object
- .dropAppoint(id) ⇒
Boolean
- .URL :
object
- .getParams(url) ⇒
Object
- .getDomainFromUrl(url) ⇒
String
- .currentDomain() ⇒
String
- .querify(object) ⇒
String
- .decode(url) ⇒
Object
- .currentPath() ⇒
String
- .currentSearch() ⇒
String
- .currentParams() ⇒
Object
- .getParams(url) ⇒
- .Logger :
object
- .Cookie :
object
- .getc(name) ⇒
String
- .setc(name, value, expires, path, domain, secure) ⇒
String
- .drop(name, path, domain) ⇒
String
- .getc(name) ⇒
- .Util :
object
- .incr ⇒
Number
- .randNr ⇒
Number
- .randInt ⇒
Number
- .atos(data, mapping, zval) ⇒
String
- .aton(input, separator) ⇒
String
- .makeDomId(prefix) ⇒
String
- .randStr(mapping) ⇒
String
- .incr ⇒
- .Cache :
object
- .getInstance(instanceName, lifetime) ⇒
Object
- .put(key, value) ⇒
Boolean
- .getInstance(instanceName, lifetime) ⇒
- .Env :
object
- .System :
object
- .os :
object
- .os :
- .Browser :
object
- .Sancho :
object
- .equals() ⇒
Boolean
- .noDuplicates(list) ⇒
Boolean
- .equals() ⇒
- .Mingui :
object
- .notify(title, text, picture, lifetime, success, failure, onclick, onclose) ⇒
Boolean
|Object
- .notify(title, text, picture, lifetime, success, failure, onclick, onclose) ⇒
- .Time :
object
- .interval(count, type) ⇒
Number
- .interval(count, type) ⇒
- .Dulcineea :
object
- .compiler :
object
- .execute(caller, jsonData) ⇒
Object
- .extract(input) ⇒
Array
- .execute(caller, jsonData) ⇒
- .compiler :
quixot.require
require safe support: cached node js requirements
TODO support for http://requirejs.org/
Kind: static property of quixot
object
quixot.Fingerprint : Kind: static namespace of quixot
- .Fingerprint :
object
- .data() ⇒
Object
- .identifier() ⇒
String
- .text() ⇒
String
- .numbers() ⇒
String
- .data() ⇒
Object
Fingerprint.data() ⇒ Kind: static method of Fingerprint
Returns: Object
- the full scanned properties
String
Fingerprint.identifier() ⇒ Kind: static method of Fingerprint
Returns: String
- The unique fingerprint identifier
String
Fingerprint.text() ⇒ Kind: static method of Fingerprint
Returns: String
- the text to compose the identifier
String
Fingerprint.numbers() ⇒ Kind: static method of Fingerprint
Returns: String
- the numbers from text()
object
quixot.Event : Kind: static namespace of quixot
- .Event :
object
- .APPOINTMENT_DONE
- .dispatch(name) ⇒
Number
- .hasListener(eventName, uidName) ⇒
Boolean
- .addListener(eventName, callback, uidName) ⇒
Object
- .removeListener(eventName, uidName) ⇒
boolean
- .getAll() ⇒
Object
- .appoint(callback, delay) ⇒
Object
- .dropAppoint(id) ⇒
Boolean
Event.APPOINTMENT_DONE
the name of the event witch is triggered any time an "Event.appoint" is registered
Kind: static property of Event
Properties
Type |
---|
String |
Number
Event.dispatch(name) ⇒ Kind: static method of Event
Returns: Number
- -1 if error occurs, 0 if no event is registered, > 0 as length of
registered events for specified name
Param | Type | Description |
---|---|---|
name | String |
required |
Boolean
Event.hasListener(eventName, uidName) ⇒ check if a provided listener exist using declared or autogenerated "uidName" from "addListener"
Kind: static method of Event
Returns: Boolean
- true if the listener exist
Param | Type | Description |
---|---|---|
eventName | String |
required |
uidName | String |
optional, if provided when listener was added |
Object
Event.addListener(eventName, callback, uidName) ⇒ register an event listener
Kind: static method of Event
Returns: Object
- The current registered event listeners
Param | Type | Description |
---|---|---|
eventName | String |
required |
callback | function |
required |
uidName | String |
an optional unique identifier for the method, to be used when removing the event handler |
Example
quixot;
boolean
Event.removeListener(eventName, uidName) ⇒ remove a registered event listener
Kind: static method of Event
Returns: boolean
- true if the listener is removed, false if listener does not exist anymore
Param | Type | Description |
---|---|---|
eventName | String |
name of the event to be removed |
uidName | String |
optional. If not provided default function to string will be used |
Object
Event.getAll() ⇒ retrieve all registered events and dispacthers
Kind: static method of Event
Returns: Object
- containing 2 properties: events and dispatchers
Object
Event.appoint(callback, delay) ⇒ appoint a method. If the environment is browser the appointment will be done via "_raf".
For NodeJS, method "setImmediate" will be used, so the "id" property of the result will be an object.
Kind: static method of Event
Returns: Object
- containing 2 properties: "type" => a string describing the used method for appointment (mozRequestAnimationFrame|setImmediate|setTimeout|nothing_found)
and an "id" => the data return by the method.
This can be used as parameter for "dropAppoint".
Param | Type | Description |
---|---|---|
callback | function |
required |
delay | Number |
optional, used only if browser has no support for "animationFrame" and a setTimeout will be used. If not provided, a default value of 30 will be used. |
Boolean
Event.dropAppoint(id) ⇒ cancel an appoint. Usage of this method should be avoided, since further changes on "appoint" method might return undroppable callbacks.
Kind: static method of Event
Returns: Boolean
- false if "id" is not provided or is invalid
Param | Type | Description |
---|---|---|
id | Object | Number |
required |
Example
var result = quixotEvent;quixotEvent; //and nothing will happen
object
quixot.URL : Kind: static namespace of quixot
- .URL :
object
- .getParams(url) ⇒
Object
- .getDomainFromUrl(url) ⇒
String
- .currentDomain() ⇒
String
- .querify(object) ⇒
String
- .decode(url) ⇒
Object
- .currentPath() ⇒
String
- .currentSearch() ⇒
String
- .currentParams() ⇒
Object
- .getParams(url) ⇒
Object
URL.getParams(url) ⇒ retrieve the parameters from a given url
Kind: static method of URL
Param | Type |
---|---|
url | String |
Example
quixotURL//returns Object {one: 1, two: 2}// same as:quixotURLparams
String
URL.getDomainFromUrl(url) ⇒ Extract the domain from an url.
Kind: static method of URL
Returns: String
- For any invalid input, default return value is "localhost"
Param | Type |
---|---|
url | String |
Example
quixotURL;
String
URL.currentDomain() ⇒ returns the current domain
Kind: static method of URL
Returns: String
- for NodeJS environment default value will be "localhost"
Example
quixotURL; //produces the same result as: quixotURL
String
URL.querify(object) ⇒ converts an object to a url query model. Inherited objects are converted into json string.
Lists are converted into csv format
Kind: static method of URL
Param | Type | Description |
---|---|---|
object | Object |
object in json format |
Example
quixotURL;//output: 'a=1&b=[1,2,3]&g=text&c={"d":2,"f":"some string"}'
Object
URL.decode(url) ⇒ Kind: static method of URL
Param | Type |
---|---|
url | String |
Example
quixotURL;//protocol => 'http'//lastPage => 'finalPage'//parts[2] =>mydomain//params.arg0[0] => '1'//params.arg1[0] => '[1'
String
URL.currentPath() ⇒ cross browser support for window.location.pathname. For non browsers environment, empty string is returned
Kind: static method of URL
Returns: String
- current path name, as defined by window.location.pathname.
String
URL.currentSearch() ⇒ Kind: static method of URL
Returns: String
- current search name, as defined by window.location.search
Object
URL.currentParams() ⇒ Kind: static method of URL
Returns: Object
- current url params
Example
quixotURL; retrieve the same data as:quixotURLparams;
object
quixot.Logger : Kind: static namespace of quixot
Example
var myLogger = quixotLogger; myLogger; myLogger; //produces the same as myLogger; myLogger; //produces the same as myLogger; quixotLogger; //produces the same as quixotLogger; quixotLogger; ///produces the same as quixotLogger;
- .Logger :
object
Logger.CONSOLE_APPENDER
default console appender function
Kind: static property of Logger
Properties
Type |
---|
function |
Logger.DOM_APPENDER
default html appender function
Kind: static property of Logger
Properties
Type |
---|
function |
Logger.info(message)
info logging using default instance
Kind: static method of Logger
Param | Type | Description |
---|---|---|
message | Object |
required |
Logger.setDefaultConfig(config)
define default configuration for all newly created logging instances
Kind: static method of Logger
Param | Type | Description |
---|---|---|
config | Object |
optional keys |
Example
//built in definition:quixotLogger
Object
Logger.getDefaultConfig() ⇒ Kind: static method of Logger
Returns: Object
- logger default configuration
Logger.trace(message)
trace logging using default instance
Kind: static method of Logger
Param | Type |
---|---|
message | Object |
Logger.error(message)
error logging using default instance
Kind: static method of Logger
Param | Type |
---|---|
message | Object |
Logger.warn(message)
warn logging using default instance
Kind: static method of Logger
Param | Type |
---|---|
message | Object |
Object
Logger.getLogs() ⇒ Kind: static method of Logger
Returns: Object
- default instance logs
Object
Logger.getAll() ⇒ Kind: static method of Logger
Returns: Object
- the logger_container with all logging instances
Object
Logger.getInstance(instancename, config) ⇒ returns a new logger instance
Kind: static method of Logger
Returns: Object
- the logger_container with all the logger instances
Param | Type | Description |
---|---|---|
instancename | String |
required |
config | Object |
optional logger configuration |
Example
var myLogger = quixotLogger;myLogger
Logger.setURLAccessKey(name)
set the value for accessing logger configuration from URL. This feature is avaiable only for
browser environments.
If is set to false
, no configuration can
be changed by using URL parameters. The url query opbject can contain only 2 properties:
"consoleAppender", to use quixot default console appender as defined by quixot.Logger.CONSOLE_APPENDER
and "fileAppender", to use quixot default dom appender as defined by quixot.Logger.DOM_APPENDER.
Kind: static method of Logger
Param | Type | Description |
---|---|---|
name | String |
required |
Example
//this will allow you to put the following query param into url://http://localhost/mypage?customKey={"ALL":{"consoleAppender":true}}quixotLogger;
object
quixot.Cookie : The following namespace has no effect in non-browser environments, although is unit testable
Kind: static namespace of quixot
- .Cookie :
object
- .getc(name) ⇒
String
- .setc(name, value, expires, path, domain, secure) ⇒
String
- .drop(name, path, domain) ⇒
String
- .getc(name) ⇒
String
Cookie.getc(name) ⇒ retrieve a cookie with provided name.
Kind: static method of Cookie
Returns: String
- if the cookie does not exist, result is null
Param | Type |
---|---|
name | String |
String
Cookie.setc(name, value, expires, path, domain, secure) ⇒ create a new cookie
Kind: static method of Cookie
Returns: String
- the composed cookie string
Param | Type | Description |
---|---|---|
name | String |
required name of the cookie |
value | String |
required value of the cookie |
expires | Date | Number |
expire date. This parameter can also be provided via "Time" namespace |
path | String |
optional |
domain | String |
optional |
secure | Boolean |
optional |
Example
quixotCookie; //based on client timestamp, might return //"test-cookie=test-cookie-value; expires=Tue, 03 Jan 2017 10:41:31 GMT; path=path; domain=domain; secure"
String
Cookie.drop(name, path, domain) ⇒ delete a cookie
Kind: static method of Cookie
Returns: String
- empty string
Param | Type | Description |
---|---|---|
name | String |
required |
path | String |
optional |
domain | String |
optional |
object
quixot.Util : Kind: static namespace of quixot
- .Util :
object
- .incr ⇒
Number
- .randNr ⇒
Number
- .randInt ⇒
Number
- .atos(data, mapping, zval) ⇒
String
- .aton(input, separator) ⇒
String
- .makeDomId(prefix) ⇒
String
- .randStr(mapping) ⇒
String
- .incr ⇒
Number
Util.incr ⇒ increments an unique number (old value is cached)
Kind: static property of Util
Returns: Number
- positive integer
Param | Type | Description |
---|---|---|
asfloat | Boolean |
optional |
Example
quixotUtil; // 30.07000000000001quixotUtil; // 31
Number
Util.randNr ⇒ if no parameters are provided a currentTimestamp value will be returned. id method is called twice in less than a milisecond, a quixot.Util.incr() value will be returned to make sure return values are avoided
Kind: static property of Util
Returns: Number
- float
Param | Description |
---|---|
min | limit range if "max" is not provided |
max | limit range |
Example
quixotUtil; // will generate numbers betwen 0 and 3, like 0.6573690931544247quixotUtil; // will generate numbers betwen 2 and 4, like 2.3124963172024833quixotUtil; // will generate numbers betwen -5 and 0, like -4.3664502906423195
Number
Util.randInt ⇒ same usage as "randNr", only it returns an integer
Kind: static property of Util
Returns: Number
- float
Param |
---|
min |
max |
String
Util.atos(data, mapping, zval) ⇒ encode any type of javascript data type (specially numbers) to string
Kind: static method of Util
Param | Type | Description |
---|---|---|
data | Number | String | Date | Object | Array | function |
required |
mapping | String |
optional a string whose characters will be used for encoding |
zval | Number |
the value for 0, used for encoding duplicated numeric characters |
Example
quixot; // "mdefghij" quixot; // "a" quixot; // "abcdef" quixot; // "!@#$%^"
String
Util.aton(input, separator) ⇒ converts any type of data into a string containing only numeric characters
Kind: static method of Util
Returns: String
- a string containing only numeric characters
Param | Type | Description |
---|---|---|
input | String | Number | Array | Object | Date |
|
separator | String |
a separator for numbers |
Example
quixotUtil; // "54__54" quixotUtil; //"1234234"
String
Util.makeDomId(prefix) ⇒ generates an unique id that begins with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9])
Kind: static method of Util
Param | Type | Description |
---|---|---|
prefix | String |
optional, a prefix to be appended at the begging of the string |
String
Util.randStr(mapping) ⇒ generates a random string
Kind: static method of Util
Returns: String
- a random string
Param | Type | Description |
---|---|---|
mapping | String |
a string whose characters will be used for encoding. Same usage as for "atos" method |
object
quixot.Cache : supports browser && nodejs
Kind: static namespace of quixot
- .Cache :
object
- .getInstance(instanceName, lifetime) ⇒
Object
- .put(key, value) ⇒
Boolean
- .getInstance(instanceName, lifetime) ⇒
Object
Cache.getInstance(instanceName, lifetime) ⇒ caching instances factory
Kind: static method of Cache
Returns: Object
- a new or an existing caching instance
Param | Type |
---|---|
instanceName | String |
lifetime | Number |
Boolean
Cache.put(key, value) ⇒ put item inside default cache instance
Kind: static method of Cache
Returns: Boolean
- true if cache is populated
Param | Type |
---|---|
key | String |
value | String | Number | Array | Object |
object
quixot.Env : contains data related to enviroment:
Kind: static namespace of quixot
Example
quixotEnvjsEngineisBrowser; //true if script is running in browserquixotEnvjsEngineisNodeJs; //true if script is running in node jsquixotEnvjavaEnabled; //true if java is enabled in browser, // or if a path to JAVA_HOME exist is operating system enviromentquixotEnvtempDir //path to operating system temporary directoryquixotEnvhomeDir //path to operating system user home directoryquixotEnvjavaPath //path to java binary (java.exe || java)
object
quixot.System : system information (browser|nodejs)
Kind: static namespace of quixot
object
System.os : operating system info
Kind: static namespace of System
Example
quixotSystemosname; // returns the operating system generic name // nodejs support is provided via os.type if exists otherwise via // os.platform. Result may be "Windows|Mac|Linux" quixotSystemversion // returns operatinng system version // result may vary based on scanned features // browsers will return data based on user agent, nodejs // or other engines may provide content via 'os.release'
object
quixot.Browser : browser information< br/>
Kind: static namespace of quixot
Example
quixotBrowsername; Chrome|Firefox|Explorer|Opera|iCab|rekonq|Midori|Arora|Stainless|Epiphany|K-Meleon|Camino|Maxthon|SeaMonkey|Edge|OmniWeb|Apple|KDE|Netscape|MSIE|Gecko|Mozilla|Tizen quixotBrowserversion;
object
quixot.Sancho : the unit testing namespace.
Kind: static namespace of quixot
- .Sancho :
object
- .equals() ⇒
Boolean
- .noDuplicates(list) ⇒
Boolean
- .equals() ⇒
Boolean
Sancho.equals() ⇒ For NodeJS environment, built-in 'assert' library will be used.
Kind: static method of Sancho
Returns: Boolean
- true if test is passed
Example
quixotSancho;
Boolean
Sancho.noDuplicates(list) ⇒ verify if a list contains no duplicates
Kind: static method of Sancho
Param | Type |
---|---|
list | Array |
Example
quixotSancho
object
quixot.Mingui : minimal graphic user interface components designed to run inside any type of enviroment and provide if possible native behaviour on visual components
Kind: static namespace of quixot
Boolean
| Object
Mingui.notify(title, text, picture, lifetime, success, failure, onclick, onclose) ⇒ for browsers the notify action will first try create a native html5 notification
if domain protocol is "http" or "https".
Second second approach will
be to create a pop-up window. Please remember that second tryout will also
apply if user native notifications are blocked from settings.
Finally, if the pop-up window is blocked, a simple html notification will
be added to current document, styled by default with operating system colors.
For nodejs enviroments if java path is detected a spawned process wil start. (required java 1.8, this feature is still under developpement)
Kind: static method of Mingui
Returns: Boolean
| Object
- false if notification fails to be displayed due to known reasons, an object with "remove()" method.
Param | Type | Description |
---|---|---|
title | String |
|
text | String |
|
picture | String |
|
lifetime | Number |
|
success | function |
|
failure | function |
although the method returns false due to known reasons, this callback is safe to use. For example, native html5 notification require user approval. In this case method will return false, but if user press "Allow" the "failure" callback will never be called |
onclick | function |
Attention!!! This callback may run without context in some implementations. |
onclose | function |
Attention!!! This callback may run without context in some implementations. |
object
quixot.Time : Time utils
Kind: static namespace of quixot
Number
Time.interval(count, type) ⇒ Kind: static method of Time
Returns: Number
- the value in milliseconds of required parameters
Param | Type | Description |
---|---|---|
count | Number |
required |
type | String |
required, one of (nano |
Example
quixotTime; // returns 126144000000
object
quixot.Dulcineea : Kind: static namespace of quixot
- .Dulcineea :
object
- .compiler :
object
- .execute(caller, jsonData) ⇒
Object
- .extract(input) ⇒
Array
- .execute(caller, jsonData) ⇒
- .compiler :
object
Dulcineea.compiler : Kind: static namespace of Dulcineea
- .compiler :
object
- .execute(caller, jsonData) ⇒
Object
- .extract(input) ⇒
Array
- .execute(caller, jsonData) ⇒
Object
compiler.execute(caller, jsonData) ⇒ executes a call for a JSON formatted object
Kind: static method of compiler
Param | Type |
---|---|
caller | String |
jsonData | Object | JSON |
Example
quixotDulcineeacompiler;//returns "1"
Array
compiler.extract(input) ⇒ converts a string into a list of valid JSON callers
Kind: static method of compiler
Param | Type |
---|---|
input | String |
Example
quixotDulcineeacompiler; //returns ['a', 'b', 'c']quixotDulcineeacompiler; //returns ["a", "b", "0", "c", "'data'"]
realtime browser customer support (use case sample)
- Create a urlAccessKey:
quixot.Logger.setURLAccessKey('mySecretKey');
- Create a logger instance with no appenders and use it in your webpage:
var log4CustomerSupport = quixot.Logger.getInstance('log4CustomerSupport', {consoleAppender: false, fileAppender: false});
log4CustomerSupport.trace('this log happens client side');
log4CustomerSupport.trace('and client could see stored data');
log4CustomerSupport.trace('by calling in console');
log4CustomerSupport.trace('quixot.Logger.getInstance(\'log4CustomerSupport\').getLogs().trace');
- ask your customer to access the webpage using the following query param:
http://domain/custompage?mySecretKey={"log4CustomerSupport":{"fileAppender":true, "consoleAppender":true}}
to view all logs of that specific logger or usemySecretKey={"log4CustomerSupport":{"fileAppender":true} }
to display on screen only info messages forlog4CustomerSupport
. You can also usemySecretKey={"ALL":{"fileAppender":true}}
to view all logs
browser scanned features in fingerprint detection
- abreviated time zone
Math
functions and static values- computer name (for older IE versions retrieved via ActiveX)
- installed plugins and supported mime types based on the recursive depth scan
- webgl support, version , vendor, renderer
- empty canvas dataUrl, both .png and .jpeg format
- chrome, netscape specific properties
- screen info (width, height, colorDepth, pixelRation)
- browser supported css properties
- unique property names of supported javascript features (check the .evilUtors) property
- the
evilUtors
are a set of evaluable strings meant to return sensitive information about browser and javascript engine