Classes
Namespaces
Methods
-
<static> capitalize(str) → {String}
-
Capitalizes a string changing the first letter to title case as per Character.
Parameters:
Name Type Description str
String The string to capitalize, may be null
- Since:
-
- 2.0.0
Returns:
A capitalized String, null if null String input
- Type
- String
Example
caph.capitalize('test') // Test caph.capitalize('Test') // Test caph.capitalize('TEST') // TEST
-
<static> clone(obj) → {Object}
-
Clones an object.
Parameters:
Name Type Description obj
Object An object which will be cloned.
- Since:
-
- 2.0.0
Returns:
A new cloned object.
- Type
- Object
Example
var a = {age: 30, name: 'John'}; var b = caph.clone(a); //b has all properties of a
-
<static> equal(a, b) → {Boolean}
-
Determines whether the first argument is same as the second parameter. This code is inspired from the code in http://jsperf.com/_equal-underscore-vs-ws-util
Parameters:
Name Type Description a
Object An object with which to compare
b
Object An object with which to compare
- Since:
-
- 2.0.0
Returns:
- Type
- Boolean
Example
var test = caph.equal({ a : 1234, b : '4567', c : null, d : window.abcd }, { a : 1234, b : '4567', c : null, d : window.abcd} console.log(test); //true will be showed
-
<static> escapeHTML(str) → {String}
-
Escapes the characters in a String using HTML entities.
Parameters:
Name Type Description str
String The string to escape, may be null
- Since:
-
- 2.0.0
Returns:
A new escaped string, null if null String input
- Type
- String
Example
caph.escapeHTML('<div>You & I</div>'); // <div>You & I</div>
-
<static> extend(base, ext, clone) → {Object}
-
Merges the contents of two objects together into the first object. This code is inspired from the code in http://stackoverflow.com/questions/11197247/javascript-equivalent-of-jquerys-extend-method
http://meta.stackoverflow.com/questions/25956/what-is-up-with-the-source-code-license-on-stack-overflow
http://andrewdupont.net/2009/08/28/deep-extending-objects-in-javascript/Parameters:
Name Type Argument Description base
Object An object that will receive another object's properties.
ext
Object An object containing additional properties to merge in.
clone
boolean <optional>
true : clone "base" object false or empty : do not clone "base" object
- Since:
-
- 2.0.0
Returns:
When third argument is empty or false : return The first argument When third argument is true : return cloned first argument
- Type
- Object
Example
var option = { version: 2.0, size: [window.innerWidth, window.innerHeight], opacity: 1, backgroundColor: '#000' } var opt = { name: 'extend' }; caph.extend(opt, option);
-
<static> getRevision() → {String}
-
Returns revision of framework
- Since:
-
- 2.0.0
Returns:
- Type
- String
Example
var revision = caph.getRevision();
-
<static> getVersion() → {String}
-
Returns version of framework
- Since:
-
- 2.0.0
Returns:
- Type
- String
Example
var version = caph.getVersion();
-
<static> has(obj, key) → {Boolean}
-
This function checks a given object has a given property
Parameters:
Name Type Description obj
Object object to be checked.
key
String property to be checked.
- Since:
-
- 2.1.0
Returns:
true if it's null or undefined, false if not.
- Type
- Boolean
Example
var object = { key : "1"}; if(caph.has(object , 'key')) { alert('object has "key"'); }
-
<static> isArguments(obj) → {Boolean}
-
This function checks a given object is arguments object or not
Parameters:
Name Type Description obj
Object object to be checked.
- Since:
-
- 2.1.0
Returns:
true if it's null or undefined, false if not.
- Type
- Boolean
Example
function a(arg){ if(caph.isArguments(arg) { alert('object is argument'); } }
-
<static> isArray(value) → {Boolean}
-
This function checks the given value is array type or not. Checks "value instanceof Array".
Parameters:
Name Type Description value
object value to be checked.
- Since:
-
- 2.0.0
Returns:
true if it's array, false if not.
- Type
- Boolean
Example
var value = [1, 2, 3]; if(caph.isArray(value)) { alert('This is array.'); }
-
<static> isBlank(value) → {Boolean}
-
This function checks the given value is null or undefined or empty string. Checks "value" is "null" or "undefined" or "".
Parameters:
Name Type Description value
object value to be checked.
- Since:
-
- 2.0.0
Returns:
true if it's null or undefined or empty string, false if not.
- Type
- Boolean
Example
var value = ''; if(caph.isBlank(value)) { alert('This is blank.'); }
-
<static> isBoolean(value) → {Boolean}
-
This function checks the given value is boolean type or not. Checks "typeof value" is "boolean".
Parameters:
Name Type Description value
object value to be checked.
- Since:
-
- 2.0.0
Returns:
true if it's boolean, false if not.
- Type
- Boolean
Example
var value = true; if(caph.isBoolean(value)) { alert('This is boolean.'); }
-
<static> isEmpty(obj) → {Boolean}
-
This function checks a given object(array, string, object) is empty or not
Parameters:
Name Type Description obj
Object | String | Array object to be checked.
- Since:
-
- 2.0.0
Returns:
true if it's null or undefined, false if not.
- Type
- Boolean
Example
var object = {}; if(caph.isEmpty(object) { alert('object is empty'); }
-
<static> isFunction(value) → {Boolean}
-
This function checks the given value is function type or not. Checks "typeof value" is "function".
Parameters:
Name Type Description value
object value to be checked.
- Since:
-
- 2.0.0
Returns:
true if it's function, false if not.
- Type
- Boolean
Example
var fun = function() {}; if(caph.isFunction(fun)) { alert('This is function.'); }
-
<static> isHTMLElement(value) → {Boolean}
-
This function checks the given value is HTMLElement type or not. Checks "value instanceof HTMLElement".
Parameters:
Name Type Description value
object value to be checked.
- Since:
-
- 2.0.0
Returns:
true if it's HTMLElement, false if not.
- Type
- Boolean
Example
var value = document.getElementById('main'); if(caph.isHTMLElement(value)) { alert('This is HTML element.'); }
-
<static> isNull(value) → {Boolean}
-
This function checks the given value is null or not. Checks "value" is "null".
Parameters:
Name Type Description value
object value to be checked.
- Since:
-
- 2.0.0
Returns:
true if it's null, false if not.
- Type
- Boolean
Example
var value = null; if(caph.isNull(value)) { alert('This is null.'); }
-
<static> isNumber(value) → {Boolean}
-
This function checks the given value is number type or not. Checks "typeof value" is "number".
Parameters:
Name Type Description value
object value to be checked.
- Since:
-
- 2.0.0
Returns:
true if it's number, false if not.
- Type
- Boolean
Example
var value = 10; if(caph.isNumber(value)) { alert('This is number.'); }
-
<static> isObject(value) → {Boolean}
-
This function checks the given value is object type or not. Checks "value instanceof Object".
Parameters:
Name Type Description value
object value to be checked.
- Since:
-
- 2.0.0
Returns:
true if it's object, false if not.
- Type
- Boolean
Example
var value = {name: 'caph'}; if(caph.isObject(value)) { alert('This is object.'); }
-
<static> isObjectInArray(array, object) → {Boolean}
-
checks if the given object is in the array or not.
Parameters:
Name Type Description array
Array Array object
object
Object | Boolean | Null | Undefined | Number | String | Symbol any data type instance you want to check
- Since:
-
- 2.0.0
Returns:
- Type
- Boolean
Example
if(caph.isObjectInArray([1,2,3], 2)) { alert('There is 2 in this array.'); }
-
<static> isRegExp(value) → {Boolean}
-
This function checks the given value is regular expression type or not. Checks "value instanceof RegExp".
Parameters:
Name Type Description value
object value to be checked.
- Since:
-
- 2.0.0
Returns:
true if it's regular expression, false if not.
- Type
- Boolean
Example
var value = new RegExp("a", "z"); if(caph.isRegExp(value)) { alert('This is regular expression.'); }
-
<static> isRTL(str) → {String}
-
Determines rtl
Parameters:
Name Type Description str
String A string to check rtl The string to escape, may be null
- Since:
-
- 2.0.0
Returns:
str - true if str is RTL
- Type
- String
Example
var text = "this is test"; var _return = caph.isRTL(text);
-
<static> isString(value) → {Boolean}
-
This function checks the given value is string type or not. Checks "typeof value" is "string".
Parameters:
Name Type Description value
object value to be checked.
- Since:
-
- 2.0.0
Returns:
true if it's string, false if not.
- Type
- Boolean
Example
var value = 'hello'; if(caph.isString(value)) { alert('This is string.'); }
-
<static> isUndefined(value) → {Boolean}
-
This function checks the given value is undefined or not. Checks "value" is "undefined".
Parameters:
Name Type Description value
object value to be checked.
- Since:
-
- 2.0.0
Returns:
true if it's undefined, false if not.
- Type
- Boolean
Example
if(caph.isUndefined(value)) { alert('This is undefined.'); }
-
<static> mixin() → {Object}
-
Adds the functionality of one or more objects to a new object.
- Since:
-
- 2.0.0
Returns:
A new merged object.
- Type
- Object
Example
var opt = { name: 'original' } var temp = { version: 2.0 } var mixinObject = caph.mixin(opt, temp);
-
<static> namespace(ns_string, obj, base)
-
Creates a namespace and binds the given object with the created namespace.
Parameters:
Name Type Description ns_string
String A string to define the namespace.
obj
Object | String An object or a string to be bound with the namespace.
base
Object An object which is used for a root object.
- Since:
-
- 2.0.0
Example
caph.namespace('myobj', { test1: 1234, test2: { sub1: 4567, func2: function () { console.log('func2'); } }, func1: function () { console.log('func1'); } }); if(myobj.hasOwnProperty('test2') && myobj.test2.hasOwnProperty('sub1') && typeof myobj.test2.sub1 === 'number'){ console.log('doing namespace successfully'); }
-
<static> once(fn) → {function}
-
Returns function that is called only one time
Parameters:
Name Type Description fn
function fn is a function that is called only one time
- Since:
-
- 2.0.0
Returns:
- Type
- function
Example
var testClass = $class({ $constructor: function() { this.initialize = caph.once(this.initialize); } )};
-
<static> require(namespace, base) → {Object}
-
Provides a module or an object in the given namespace. You already have a direct access to the one in the given namespace. Getting the module using this method will ensure that it is dynamically loaded even if it doesn't exist in namespace. NOTE : the dynamic module load is not supported yet.
Parameters:
Name Type Argument Description namespace
string A namespace string.
base
string <optional>
A base namespace. If undefined, the value of require._baseNamespace, 'windows.caph', is its default.
- Since:
-
- 2.0.0
Returns:
A module or an object matched with the given namespace.
- Type
- Object
Example
var Vector3 = caph.require('math.vector3');
-
<static> toCamelCase(input) → {String}
-
Returns the input applied camel case naming convention
Parameters:
Name Type Description input
Object The input to be applied camelcase
- Since:
-
- 2.0.0
Returns:
- Type
- String
Example
caph.toCamelCase('background-position'); // backgroundPosition caph.toCamelCase('-webkit-transform'); // webkitTransform
-
<static> xhr(url, option) → {Promise|caph.xhr.Response}
-
Performs an asynchronous HTTP (Ajax) request using Promise.
Parameters:
Name Type Description url
String A string containing the URL to which the request is sent.
option
Object A set of key/value pairs that configure the Ajax request.
Option Details {String} method The type of request to make 'post' or 'get', default is 'get'. {Boolean} async By default, all requests are sent asynchronously. If you need synchronous requests, set this option to false. {String|Object} parameter Data to be sent to the server. It is converted to a query string, if not already a string. If the parameter type is an object, it must be key/value string pairs. {String} type The type of data that you're expecting back from the server. The available types are 'XML', 'HTML', TEXT, JSON and JSONP, default is 'XML'. {Object} header Additional header key/value string pair object to send along with requests using the XMLHttpRequest transport. {String} jsonpCharset Only applies when the 'JSONP' type is used. Sets the charset attribute on the script tag used in the request. {String} jsonpCallback Override the callback parameter name in a jsonp request. This value will be used instead of '_callback' in the '_callback=' part of the query string in the url. {Number} timeout Sets a timeout (in milliseconds) for the request. Default is '0', which indicates that there is no timeout. - Since:
-
- 2.0.0
Returns:
By default, returns a Promise object. If async option is false, returns a caph.xhr.Response object.
- Type
- Promise | caph.xhr.Response
Example
// asynchronous request caph.xhr('/test', { method: 'get', type: 'TEXT', parameter: 'param1=1&param2=2' }).then(function(response) { // a caph.xhr.Response object. console.log(response.value); }); // jsonp request caph.xhr('/test', { method: 'get', type: 'JSONP', parameter: 'param1=1&param2=2' }).then(function(data) { // a json object. console.log(data); }); // synchronous request var response = caph.xhr('/test', { // a caph.xhr.Response object. method: 'get', type: 'TEXT', parameter: 'param1=1&param2=2', async: false }) console.log(response.value);