repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
sequence | docstring
stringlengths 4
11.8k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 86
226
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
HumanBrainProject/jsdoc-sphinx | template/util/rst-mixin.js | titlecase | function titlecase() {
return function(data, render) {
var text = render(data);
if (text.length === 0) {
return text;
}
return text[0].toUpperCase() + text.substring(1);
};
} | javascript | function titlecase() {
return function(data, render) {
var text = render(data);
if (text.length === 0) {
return text;
}
return text[0].toUpperCase() + text.substring(1);
};
} | [
"function",
"titlecase",
"(",
")",
"{",
"return",
"function",
"(",
"data",
",",
"render",
")",
"{",
"var",
"text",
"=",
"render",
"(",
"data",
")",
";",
"if",
"(",
"text",
".",
"length",
"===",
"0",
")",
"{",
"return",
"text",
";",
"}",
"return",
"text",
"[",
"0",
"]",
".",
"toUpperCase",
"(",
")",
"+",
"text",
".",
"substring",
"(",
"1",
")",
";",
"}",
";",
"}"
] | Mustache lambda that upercase the first letter
of each word in the given data.
@return {function} the titlecase helper function | [
"Mustache",
"lambda",
"that",
"upercase",
"the",
"first",
"letter",
"of",
"each",
"word",
"in",
"the",
"given",
"data",
"."
] | 9d7c1d318ce535640588e7308917729c3849bc83 | https://github.com/HumanBrainProject/jsdoc-sphinx/blob/9d7c1d318ce535640588e7308917729c3849bc83/template/util/rst-mixin.js#L19-L28 | train |
HumanBrainProject/jsdoc-sphinx | template/util/rst-mixin.js | generateHeading | function generateHeading() {
var mixin = {};
// If two char are provided, first one is used as upperline of the text.
_.each(['==', '=', '-', '~', '\''], function(char, idx) {
// Mustach lambda function takes no parameters and return a function
// whose signature is data, render.
// see https://mustache.github.io/mustache.5.html
mixin['h' + (idx + 1)] = function() {
return function(data, render) {
var text = render(data);
var length = _.last(text.split('\n')).length;
if (char.length === 2) {
text = repeatChar(char[1], length) + '\n' + text;
}
return text + '\n' + repeatChar(char[0], length);
};
};
});
return mixin;
} | javascript | function generateHeading() {
var mixin = {};
// If two char are provided, first one is used as upperline of the text.
_.each(['==', '=', '-', '~', '\''], function(char, idx) {
// Mustach lambda function takes no parameters and return a function
// whose signature is data, render.
// see https://mustache.github.io/mustache.5.html
mixin['h' + (idx + 1)] = function() {
return function(data, render) {
var text = render(data);
var length = _.last(text.split('\n')).length;
if (char.length === 2) {
text = repeatChar(char[1], length) + '\n' + text;
}
return text + '\n' + repeatChar(char[0], length);
};
};
});
return mixin;
} | [
"function",
"generateHeading",
"(",
")",
"{",
"var",
"mixin",
"=",
"{",
"}",
";",
"_",
".",
"each",
"(",
"[",
"'=='",
",",
"'='",
",",
"'-'",
",",
"'~'",
",",
"'\\''",
"]",
",",
"\\'",
")",
";",
"function",
"(",
"char",
",",
"idx",
")",
"{",
"mixin",
"[",
"'h'",
"+",
"(",
"idx",
"+",
"1",
")",
"]",
"=",
"function",
"(",
")",
"{",
"return",
"function",
"(",
"data",
",",
"render",
")",
"{",
"var",
"text",
"=",
"render",
"(",
"data",
")",
";",
"var",
"length",
"=",
"_",
".",
"last",
"(",
"text",
".",
"split",
"(",
"'\\n'",
")",
")",
".",
"\\n",
";",
"length",
"if",
"(",
"char",
".",
"length",
"===",
"2",
")",
"{",
"text",
"=",
"repeatChar",
"(",
"char",
"[",
"1",
"]",
",",
"length",
")",
"+",
"'\\n'",
"+",
"\\n",
";",
"}",
"}",
";",
"}",
";",
"}",
"}"
] | Create a mixin object containing mustache lambda function for heading.
The function are named h1 to h[n].
@return {function} Mustache lambda | [
"Create",
"a",
"mixin",
"object",
"containing",
"mustache",
"lambda",
"function",
"for",
"heading",
"."
] | 9d7c1d318ce535640588e7308917729c3849bc83 | https://github.com/HumanBrainProject/jsdoc-sphinx/blob/9d7c1d318ce535640588e7308917729c3849bc83/template/util/rst-mixin.js#L37-L56 | train |
HumanBrainProject/jsdoc-sphinx | template/util/rst-mixin.js | pre | function pre() {
return function(data, render) {
// remove first line if empty ; it happens because of
// the {{pre}} tag on one line.
logger.debug('empty line:', Boolean(data.match(/^\s+\n/, '')));
data = data.replace(/^\s+\n/, '');
// Find the first non-empty lines tabulation
var m = data.match(/^([ \r\t]+)[^\s]/m);
if (!m) {
return render(data);
}
var prefix = m[1];
// remove the prefix from the beginning of all lines before rendering
data = data.replace(new RegExp('^' + prefix, 'mg'), '');
var output = render(data);
output = output.replace(/\n/mg, '\n' + prefix);
// Depending what kind of content is on the first line, it might
// or might not keep the spacing...
// if the first does not contains the pattern, add it
if (data.substring(0, prefix.length) !== prefix) {
output = prefix + output;
}
return output;
};
} | javascript | function pre() {
return function(data, render) {
// remove first line if empty ; it happens because of
// the {{pre}} tag on one line.
logger.debug('empty line:', Boolean(data.match(/^\s+\n/, '')));
data = data.replace(/^\s+\n/, '');
// Find the first non-empty lines tabulation
var m = data.match(/^([ \r\t]+)[^\s]/m);
if (!m) {
return render(data);
}
var prefix = m[1];
// remove the prefix from the beginning of all lines before rendering
data = data.replace(new RegExp('^' + prefix, 'mg'), '');
var output = render(data);
output = output.replace(/\n/mg, '\n' + prefix);
// Depending what kind of content is on the first line, it might
// or might not keep the spacing...
// if the first does not contains the pattern, add it
if (data.substring(0, prefix.length) !== prefix) {
output = prefix + output;
}
return output;
};
} | [
"function",
"pre",
"(",
")",
"{",
"return",
"function",
"(",
"data",
",",
"render",
")",
"{",
"logger",
".",
"debug",
"(",
"'empty line:'",
",",
"Boolean",
"(",
"data",
".",
"match",
"(",
"/",
"^\\s+\\n",
"/",
",",
"''",
")",
")",
")",
";",
"data",
"=",
"data",
".",
"replace",
"(",
"/",
"^\\s+\\n",
"/",
",",
"''",
")",
";",
"var",
"m",
"=",
"data",
".",
"match",
"(",
"/",
"^([ \\r\\t]+)[^\\s]",
"/",
"m",
")",
";",
"if",
"(",
"!",
"m",
")",
"{",
"return",
"render",
"(",
"data",
")",
";",
"}",
"var",
"prefix",
"=",
"m",
"[",
"1",
"]",
";",
"data",
"=",
"data",
".",
"replace",
"(",
"new",
"RegExp",
"(",
"'^'",
"+",
"prefix",
",",
"'mg'",
")",
",",
"''",
")",
";",
"var",
"output",
"=",
"render",
"(",
"data",
")",
";",
"output",
"=",
"output",
".",
"replace",
"(",
"/",
"\\n",
"/",
"mg",
",",
"'\\n'",
"+",
"\\n",
")",
";",
"prefix",
"if",
"(",
"data",
".",
"substring",
"(",
"0",
",",
"prefix",
".",
"length",
")",
"!==",
"prefix",
")",
"{",
"output",
"=",
"prefix",
"+",
"output",
";",
"}",
"}",
";",
"}"
] | Mustache lambda to preserve whitespace of the given string.
@return {function} Mustache lambda | [
"Mustache",
"lambda",
"to",
"preserve",
"whitespace",
"of",
"the",
"given",
"string",
"."
] | 9d7c1d318ce535640588e7308917729c3849bc83 | https://github.com/HumanBrainProject/jsdoc-sphinx/blob/9d7c1d318ce535640588e7308917729c3849bc83/template/util/rst-mixin.js#L63-L87 | train |
syntax-tree/unist-builder-blueprint | index.js | propsNode | function propsNode (node) {
var props = flatmap(Object.keys(node), function (key) {
if (key == 'type' || key == 'value' || key == 'children') {
return;
}
var value = node[key];
if (key == 'data') {
value = JSON.parse(JSON.stringify(value));
}
return {
type: 'Property',
key: {
type: 'Identifier',
name: key
},
value: literalNode(value)
};
});
return props.length && {
type: 'ObjectExpression',
properties: props
};
} | javascript | function propsNode (node) {
var props = flatmap(Object.keys(node), function (key) {
if (key == 'type' || key == 'value' || key == 'children') {
return;
}
var value = node[key];
if (key == 'data') {
value = JSON.parse(JSON.stringify(value));
}
return {
type: 'Property',
key: {
type: 'Identifier',
name: key
},
value: literalNode(value)
};
});
return props.length && {
type: 'ObjectExpression',
properties: props
};
} | [
"function",
"propsNode",
"(",
"node",
")",
"{",
"var",
"props",
"=",
"flatmap",
"(",
"Object",
".",
"keys",
"(",
"node",
")",
",",
"function",
"(",
"key",
")",
"{",
"if",
"(",
"key",
"==",
"'type'",
"||",
"key",
"==",
"'value'",
"||",
"key",
"==",
"'children'",
")",
"{",
"return",
";",
"}",
"var",
"value",
"=",
"node",
"[",
"key",
"]",
";",
"if",
"(",
"key",
"==",
"'data'",
")",
"{",
"value",
"=",
"JSON",
".",
"parse",
"(",
"JSON",
".",
"stringify",
"(",
"value",
")",
")",
";",
"}",
"return",
"{",
"type",
":",
"'Property'",
",",
"key",
":",
"{",
"type",
":",
"'Identifier'",
",",
"name",
":",
"key",
"}",
",",
"value",
":",
"literalNode",
"(",
"value",
")",
"}",
";",
"}",
")",
";",
"return",
"props",
".",
"length",
"&&",
"{",
"type",
":",
"'ObjectExpression'",
",",
"properties",
":",
"props",
"}",
";",
"}"
] | Create ESTree object literal node representing Unist node properties. | [
"Create",
"ESTree",
"object",
"literal",
"node",
"representing",
"Unist",
"node",
"properties",
"."
] | f63bf8f1474ea84cf1c127a3cc47814e7611783e | https://github.com/syntax-tree/unist-builder-blueprint/blob/f63bf8f1474ea84cf1c127a3cc47814e7611783e/index.js#L38-L64 | train |
syntax-tree/unist-builder-blueprint | index.js | literalNode | function literalNode (value) {
if (value === undefined) {
return {
type: 'Identifier',
name: 'undefined'
};
}
else if (typeof value == 'function') {
throw Error('Unist property contains a function');
}
else if (value === null || typeof value != 'object') {
return {
type: 'Literal',
value: value
};
}
else if (Array.isArray(value)) {
return {
type: 'ArrayExpression',
elements: value.map(literalNode)
};
}
else {
return {
type: 'ObjectExpression',
properties: Object.keys(value).map(function (key) {
return {
type: 'Property',
key: {
type: 'Identifier',
name: key
},
value: literalNode(value[key])
};
})
};
}
} | javascript | function literalNode (value) {
if (value === undefined) {
return {
type: 'Identifier',
name: 'undefined'
};
}
else if (typeof value == 'function') {
throw Error('Unist property contains a function');
}
else if (value === null || typeof value != 'object') {
return {
type: 'Literal',
value: value
};
}
else if (Array.isArray(value)) {
return {
type: 'ArrayExpression',
elements: value.map(literalNode)
};
}
else {
return {
type: 'ObjectExpression',
properties: Object.keys(value).map(function (key) {
return {
type: 'Property',
key: {
type: 'Identifier',
name: key
},
value: literalNode(value[key])
};
})
};
}
} | [
"function",
"literalNode",
"(",
"value",
")",
"{",
"if",
"(",
"value",
"===",
"undefined",
")",
"{",
"return",
"{",
"type",
":",
"'Identifier'",
",",
"name",
":",
"'undefined'",
"}",
";",
"}",
"else",
"if",
"(",
"typeof",
"value",
"==",
"'function'",
")",
"{",
"throw",
"Error",
"(",
"'Unist property contains a function'",
")",
";",
"}",
"else",
"if",
"(",
"value",
"===",
"null",
"||",
"typeof",
"value",
"!=",
"'object'",
")",
"{",
"return",
"{",
"type",
":",
"'Literal'",
",",
"value",
":",
"value",
"}",
";",
"}",
"else",
"if",
"(",
"Array",
".",
"isArray",
"(",
"value",
")",
")",
"{",
"return",
"{",
"type",
":",
"'ArrayExpression'",
",",
"elements",
":",
"value",
".",
"map",
"(",
"literalNode",
")",
"}",
";",
"}",
"else",
"{",
"return",
"{",
"type",
":",
"'ObjectExpression'",
",",
"properties",
":",
"Object",
".",
"keys",
"(",
"value",
")",
".",
"map",
"(",
"function",
"(",
"key",
")",
"{",
"return",
"{",
"type",
":",
"'Property'",
",",
"key",
":",
"{",
"type",
":",
"'Identifier'",
",",
"name",
":",
"key",
"}",
",",
"value",
":",
"literalNode",
"(",
"value",
"[",
"key",
"]",
")",
"}",
";",
"}",
")",
"}",
";",
"}",
"}"
] | Create ESTree node representing particular JavaScript literal. | [
"Create",
"ESTree",
"node",
"representing",
"particular",
"JavaScript",
"literal",
"."
] | f63bf8f1474ea84cf1c127a3cc47814e7611783e | https://github.com/syntax-tree/unist-builder-blueprint/blob/f63bf8f1474ea84cf1c127a3cc47814e7611783e/index.js#L68-L105 | train |
avoidwork/abaaso | src/promise.js | function ( parent, child ) {
parent.then( function ( arg ) {
child.resolve( arg );
}, function ( e ) {
child.reject( e );
});
} | javascript | function ( parent, child ) {
parent.then( function ( arg ) {
child.resolve( arg );
}, function ( e ) {
child.reject( e );
});
} | [
"function",
"(",
"parent",
",",
"child",
")",
"{",
"parent",
".",
"then",
"(",
"function",
"(",
"arg",
")",
"{",
"child",
".",
"resolve",
"(",
"arg",
")",
";",
"}",
",",
"function",
"(",
"e",
")",
"{",
"child",
".",
"reject",
"(",
"e",
")",
";",
"}",
")",
";",
"}"
] | Pipes a reconciliation from `parent` to `child`
@method pipe
@param {Object} parent Promise
@param {Object} child Promise
@return {Undefined} undefined | [
"Pipes",
"a",
"reconciliation",
"from",
"parent",
"to",
"child"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/src/promise.js#L43-L49 | train |
|
avoidwork/abaaso | src/promise.js | function ( obj, arg, state ) {
if ( obj.state > promise.state.PENDING ) {
return;
}
obj.value = arg;
obj.state = state;
if ( !obj.deferred ) {
promise.delay( function () {
obj.process();
});
obj.deferred = true;
}
return obj;
} | javascript | function ( obj, arg, state ) {
if ( obj.state > promise.state.PENDING ) {
return;
}
obj.value = arg;
obj.state = state;
if ( !obj.deferred ) {
promise.delay( function () {
obj.process();
});
obj.deferred = true;
}
return obj;
} | [
"function",
"(",
"obj",
",",
"arg",
",",
"state",
")",
"{",
"if",
"(",
"obj",
".",
"state",
">",
"promise",
".",
"state",
".",
"PENDING",
")",
"{",
"return",
";",
"}",
"obj",
".",
"value",
"=",
"arg",
";",
"obj",
".",
"state",
"=",
"state",
";",
"if",
"(",
"!",
"obj",
".",
"deferred",
")",
"{",
"promise",
".",
"delay",
"(",
"function",
"(",
")",
"{",
"obj",
".",
"process",
"(",
")",
";",
"}",
")",
";",
"obj",
".",
"deferred",
"=",
"true",
";",
"}",
"return",
"obj",
";",
"}"
] | Initiates processing a Promise
@memberOf process
@param {Object} obj Promise instance
@param {Mixed} arg Promise value
@param {Number} state State, e.g. "1"
@return {Object} Promise instance | [
"Initiates",
"processing",
"a",
"Promise"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/src/promise.js#L60-L77 | train |
|
HumanBrainProject/jsdoc-sphinx | template/util/index.js | view | function view(name, model, cb) {
var basePath = path.join(path.dirname(__filename), '../views');
var render = function(err, files) {
if (err) {
cb(err);
}
cb(null, mustache.render(files[0], model, {
toctreeChildren: files[1],
func: files[2],
member: files[3],
constant: files[3],
typedef: files[5]
}));
};
async.parallel(_.map([
name,
'_toctree-children',
'_function',
'_member',
'_member',
'_typedef'
], function(p) {
return function(cb) {
fs.readFile(path.join(basePath, p + '.mustache'), 'utf-8', cb);
};
}), render);
} | javascript | function view(name, model, cb) {
var basePath = path.join(path.dirname(__filename), '../views');
var render = function(err, files) {
if (err) {
cb(err);
}
cb(null, mustache.render(files[0], model, {
toctreeChildren: files[1],
func: files[2],
member: files[3],
constant: files[3],
typedef: files[5]
}));
};
async.parallel(_.map([
name,
'_toctree-children',
'_function',
'_member',
'_member',
'_typedef'
], function(p) {
return function(cb) {
fs.readFile(path.join(basePath, p + '.mustache'), 'utf-8', cb);
};
}), render);
} | [
"function",
"view",
"(",
"name",
",",
"model",
",",
"cb",
")",
"{",
"var",
"basePath",
"=",
"path",
".",
"join",
"(",
"path",
".",
"dirname",
"(",
"__filename",
")",
",",
"'../views'",
")",
";",
"var",
"render",
"=",
"function",
"(",
"err",
",",
"files",
")",
"{",
"if",
"(",
"err",
")",
"{",
"cb",
"(",
"err",
")",
";",
"}",
"cb",
"(",
"null",
",",
"mustache",
".",
"render",
"(",
"files",
"[",
"0",
"]",
",",
"model",
",",
"{",
"toctreeChildren",
":",
"files",
"[",
"1",
"]",
",",
"func",
":",
"files",
"[",
"2",
"]",
",",
"member",
":",
"files",
"[",
"3",
"]",
",",
"constant",
":",
"files",
"[",
"3",
"]",
",",
"typedef",
":",
"files",
"[",
"5",
"]",
"}",
")",
")",
";",
"}",
";",
"async",
".",
"parallel",
"(",
"_",
".",
"map",
"(",
"[",
"name",
",",
"'_toctree-children'",
",",
"'_function'",
",",
"'_member'",
",",
"'_member'",
",",
"'_typedef'",
"]",
",",
"function",
"(",
"p",
")",
"{",
"return",
"function",
"(",
"cb",
")",
"{",
"fs",
".",
"readFile",
"(",
"path",
".",
"join",
"(",
"basePath",
",",
"p",
"+",
"'.mustache'",
")",
",",
"'utf-8'",
",",
"cb",
")",
";",
"}",
";",
"}",
")",
",",
"render",
")",
";",
"}"
] | Generate the output string given a template name and the model.
@param {string} name the template name without the extension.
@param {object} model the ViewModel to use with the template
@param {viewCallback} cb callback | [
"Generate",
"the",
"output",
"string",
"given",
"a",
"template",
"name",
"and",
"the",
"model",
"."
] | 9d7c1d318ce535640588e7308917729c3849bc83 | https://github.com/HumanBrainProject/jsdoc-sphinx/blob/9d7c1d318ce535640588e7308917729c3849bc83/template/util/index.js#L24-L50 | train |
avoidwork/abaaso | lib/abaaso.js | function ( obj, arg ) {
if ( !array.contains( obj, arg ) ) {
obj.push( arg );
}
return obj;
} | javascript | function ( obj, arg ) {
if ( !array.contains( obj, arg ) ) {
obj.push( arg );
}
return obj;
} | [
"function",
"(",
"obj",
",",
"arg",
")",
"{",
"if",
"(",
"!",
"array",
".",
"contains",
"(",
"obj",
",",
"arg",
")",
")",
"{",
"obj",
".",
"push",
"(",
"arg",
")",
";",
"}",
"return",
"obj",
";",
"}"
] | Adds 'arg' to 'obj' if it is not found
@method add
@param {Array} obj Array to receive 'arg'
@param {Mixed} arg Argument to set in 'obj'
@return {Array} Array that was queried | [
"Adds",
"arg",
"to",
"obj",
"if",
"it",
"is",
"not",
"found"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L167-L173 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj, arg ) {
var min = 0,
max = obj.length - 1,
idx, val;
while ( min <= max ) {
idx = Math.floor( ( min + max ) / 2 );
val = obj[idx];
if ( val < arg ) {
min = idx + 1;
}
else if ( val > arg ) {
max = idx - 1;
}
else {
return idx;
}
}
return -1;
} | javascript | function ( obj, arg ) {
var min = 0,
max = obj.length - 1,
idx, val;
while ( min <= max ) {
idx = Math.floor( ( min + max ) / 2 );
val = obj[idx];
if ( val < arg ) {
min = idx + 1;
}
else if ( val > arg ) {
max = idx - 1;
}
else {
return idx;
}
}
return -1;
} | [
"function",
"(",
"obj",
",",
"arg",
")",
"{",
"var",
"min",
"=",
"0",
",",
"max",
"=",
"obj",
".",
"length",
"-",
"1",
",",
"idx",
",",
"val",
";",
"while",
"(",
"min",
"<=",
"max",
")",
"{",
"idx",
"=",
"Math",
".",
"floor",
"(",
"(",
"min",
"+",
"max",
")",
"/",
"2",
")",
";",
"val",
"=",
"obj",
"[",
"idx",
"]",
";",
"if",
"(",
"val",
"<",
"arg",
")",
"{",
"min",
"=",
"idx",
"+",
"1",
";",
"}",
"else",
"if",
"(",
"val",
">",
"arg",
")",
"{",
"max",
"=",
"idx",
"-",
"1",
";",
"}",
"else",
"{",
"return",
"idx",
";",
"}",
"}",
"return",
"-",
"1",
";",
"}"
] | Preforms a binary search on a sorted Array
@method binIndex
@param {Array} obj Array to search
@param {Mixed} arg Value to find index of
@return {Number} Index of `arg` within `obj` | [
"Preforms",
"a",
"binary",
"search",
"on",
"a",
"sorted",
"Array"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L183-L204 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj, size ) {
var result = [],
nth = number.round( ( obj.length / size ), "up" ),
start = 0,
i = -1;
while ( ++i < nth ) {
start = i * size;
result.push( array.limit( obj, start, size ) );
}
return result;
} | javascript | function ( obj, size ) {
var result = [],
nth = number.round( ( obj.length / size ), "up" ),
start = 0,
i = -1;
while ( ++i < nth ) {
start = i * size;
result.push( array.limit( obj, start, size ) );
}
return result;
} | [
"function",
"(",
"obj",
",",
"size",
")",
"{",
"var",
"result",
"=",
"[",
"]",
",",
"nth",
"=",
"number",
".",
"round",
"(",
"(",
"obj",
".",
"length",
"/",
"size",
")",
",",
"\"up\"",
")",
",",
"start",
"=",
"0",
",",
"i",
"=",
"-",
"1",
";",
"while",
"(",
"++",
"i",
"<",
"nth",
")",
"{",
"start",
"=",
"i",
"*",
"size",
";",
"result",
".",
"push",
"(",
"array",
".",
"limit",
"(",
"obj",
",",
"start",
",",
"size",
")",
")",
";",
"}",
"return",
"result",
";",
"}"
] | Transforms an Array to a 2D Array of chunks
@method chunk
@param {Array} obj Array to parse
@param {Number} size Chunk size ( integer )
@return {Array} Chunked Array | [
"Transforms",
"an",
"Array",
"to",
"a",
"2D",
"Array",
"of",
"chunks"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L274-L286 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj, fn ) {
var result = [];
array.each( obj, function ( i ) {
result.push( fn( i ) );
});
return result;
} | javascript | function ( obj, fn ) {
var result = [];
array.each( obj, function ( i ) {
result.push( fn( i ) );
});
return result;
} | [
"function",
"(",
"obj",
",",
"fn",
")",
"{",
"var",
"result",
"=",
"[",
"]",
";",
"array",
".",
"each",
"(",
"obj",
",",
"function",
"(",
"i",
")",
"{",
"result",
".",
"push",
"(",
"fn",
"(",
"i",
")",
")",
";",
"}",
")",
";",
"return",
"result",
";",
"}"
] | Creates a new Array of the result of `fn` executed against every index of `obj`
@method collect
@param {Array} obj Array to iterate
@param {Function} fn Function to execute against indices
@return {Array} New Array | [
"Creates",
"a",
"new",
"Array",
"of",
"the",
"result",
"of",
"fn",
"executed",
"against",
"every",
"index",
"of",
"obj"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L330-L338 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj, diff ) {
var result = [];
result = obj.filter( function ( i ) {
return !regex.null_undefined.test( i );
});
return !diff ? result : ( result.length < obj.length ? result : null );
} | javascript | function ( obj, diff ) {
var result = [];
result = obj.filter( function ( i ) {
return !regex.null_undefined.test( i );
});
return !diff ? result : ( result.length < obj.length ? result : null );
} | [
"function",
"(",
"obj",
",",
"diff",
")",
"{",
"var",
"result",
"=",
"[",
"]",
";",
"result",
"=",
"obj",
".",
"filter",
"(",
"function",
"(",
"i",
")",
"{",
"return",
"!",
"regex",
".",
"null_undefined",
".",
"test",
"(",
"i",
")",
";",
"}",
")",
";",
"return",
"!",
"diff",
"?",
"result",
":",
"(",
"result",
".",
"length",
"<",
"obj",
".",
"length",
"?",
"result",
":",
"null",
")",
";",
"}"
] | Compacts a Array by removing `null` or `undefined` indices
@method compact
@param {Array} obj Array to compact
@param {Boolean} diff Indicates to return resulting Array only if there's a difference
@return {Array} Compacted copy of `obj`, or null ( if `diff` is passed & no diff is found ) | [
"Compacts",
"a",
"Array",
"by",
"removing",
"null",
"or",
"undefined",
"indices"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L348-L356 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( array1, array2 ) {
var result = [];
array.each( array1, function ( i ) {
if ( !array.contains( array2, i ) ) {
array.add( result, i );
}
});
array.each( array2, function ( i ) {
if ( !array.contains( array1, i ) ) {
array.add( result, i );
}
});
return result;
} | javascript | function ( array1, array2 ) {
var result = [];
array.each( array1, function ( i ) {
if ( !array.contains( array2, i ) ) {
array.add( result, i );
}
});
array.each( array2, function ( i ) {
if ( !array.contains( array1, i ) ) {
array.add( result, i );
}
});
return result;
} | [
"function",
"(",
"array1",
",",
"array2",
")",
"{",
"var",
"result",
"=",
"[",
"]",
";",
"array",
".",
"each",
"(",
"array1",
",",
"function",
"(",
"i",
")",
"{",
"if",
"(",
"!",
"array",
".",
"contains",
"(",
"array2",
",",
"i",
")",
")",
"{",
"array",
".",
"add",
"(",
"result",
",",
"i",
")",
";",
"}",
"}",
")",
";",
"array",
".",
"each",
"(",
"array2",
",",
"function",
"(",
"i",
")",
"{",
"if",
"(",
"!",
"array",
".",
"contains",
"(",
"array1",
",",
"i",
")",
")",
"{",
"array",
".",
"add",
"(",
"result",
",",
"i",
")",
";",
"}",
"}",
")",
";",
"return",
"result",
";",
"}"
] | Finds the difference between array1 and array2
@method diff
@param {Array} array1 Source Array
@param {Array} array2 Comparison Array
@return {Array} Array of the differences | [
"Finds",
"the",
"difference",
"between",
"array1",
"and",
"array2"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L380-L396 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj, arg, start, offset ) {
var fn = typeof arg === "function",
l = obj.length,
i = !isNaN( start ) ? start : 0,
nth = !isNaN( offset ) ? i + offset : l - 1;
if ( nth > ( l - 1) ) {
nth = l - 1;
}
while ( i <= nth ) {
obj[i] = fn ? arg( obj[i] ) : arg;
i++;
}
return obj;
} | javascript | function ( obj, arg, start, offset ) {
var fn = typeof arg === "function",
l = obj.length,
i = !isNaN( start ) ? start : 0,
nth = !isNaN( offset ) ? i + offset : l - 1;
if ( nth > ( l - 1) ) {
nth = l - 1;
}
while ( i <= nth ) {
obj[i] = fn ? arg( obj[i] ) : arg;
i++;
}
return obj;
} | [
"function",
"(",
"obj",
",",
"arg",
",",
"start",
",",
"offset",
")",
"{",
"var",
"fn",
"=",
"typeof",
"arg",
"===",
"\"function\"",
",",
"l",
"=",
"obj",
".",
"length",
",",
"i",
"=",
"!",
"isNaN",
"(",
"start",
")",
"?",
"start",
":",
"0",
",",
"nth",
"=",
"!",
"isNaN",
"(",
"offset",
")",
"?",
"i",
"+",
"offset",
":",
"l",
"-",
"1",
";",
"if",
"(",
"nth",
">",
"(",
"l",
"-",
"1",
")",
")",
"{",
"nth",
"=",
"l",
"-",
"1",
";",
"}",
"while",
"(",
"i",
"<=",
"nth",
")",
"{",
"obj",
"[",
"i",
"]",
"=",
"fn",
"?",
"arg",
"(",
"obj",
"[",
"i",
"]",
")",
":",
"arg",
";",
"i",
"++",
";",
"}",
"return",
"obj",
";",
"}"
] | Fills `obj` with the evalution of `arg`, optionally from `start` to `offset`
@method fill
@param {Array} obj Array to fill
@param {Mixed} arg String, Number of Function to fill with
@param {Number} start [Optional] Index to begin filling at
@param {Number} end [Optional] Offset from start to stop filling at
@return {Array} Filled Array | [
"Fills",
"obj",
"with",
"the",
"evalution",
"of",
"arg",
"optionally",
"from",
"start",
"to",
"offset"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L515-L531 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj ) {
var result = [];
result = obj.reduce( function ( a, b ) {
return a.concat( b );
}, result );
return result;
} | javascript | function ( obj ) {
var result = [];
result = obj.reduce( function ( a, b ) {
return a.concat( b );
}, result );
return result;
} | [
"function",
"(",
"obj",
")",
"{",
"var",
"result",
"=",
"[",
"]",
";",
"result",
"=",
"obj",
".",
"reduce",
"(",
"function",
"(",
"a",
",",
"b",
")",
"{",
"return",
"a",
".",
"concat",
"(",
"b",
")",
";",
"}",
",",
"result",
")",
";",
"return",
"result",
";",
"}"
] | Flattens a 2D Array
@method flat
@param {Array} obj 2D Array to flatten
@return {Array} Flatten Array | [
"Flattens",
"a",
"2D",
"Array"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L551-L559 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj ) {
var indexed = [];
utility.iterate( obj, function ( v ) {
indexed.push( v );
});
return indexed;
} | javascript | function ( obj ) {
var indexed = [];
utility.iterate( obj, function ( v ) {
indexed.push( v );
});
return indexed;
} | [
"function",
"(",
"obj",
")",
"{",
"var",
"indexed",
"=",
"[",
"]",
";",
"utility",
".",
"iterate",
"(",
"obj",
",",
"function",
"(",
"v",
")",
"{",
"indexed",
".",
"push",
"(",
"v",
")",
";",
"}",
")",
";",
"return",
"indexed",
";",
"}"
] | Returns an Associative Array as an Indexed Array
@method indexed
@param {Array} obj Array to index
@return {Array} Indexed Array | [
"Returns",
"an",
"Associative",
"Array",
"as",
"an",
"Indexed",
"Array"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L591-L599 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( array1, array2 ) {
var a = array1.length > array2.length ? array1 : array2,
b = ( a === array1 ? array2 : array1 );
return a.filter( function ( key ) {
return array.contains( b, key );
});
} | javascript | function ( array1, array2 ) {
var a = array1.length > array2.length ? array1 : array2,
b = ( a === array1 ? array2 : array1 );
return a.filter( function ( key ) {
return array.contains( b, key );
});
} | [
"function",
"(",
"array1",
",",
"array2",
")",
"{",
"var",
"a",
"=",
"array1",
".",
"length",
">",
"array2",
".",
"length",
"?",
"array1",
":",
"array2",
",",
"b",
"=",
"(",
"a",
"===",
"array1",
"?",
"array2",
":",
"array1",
")",
";",
"return",
"a",
".",
"filter",
"(",
"function",
"(",
"key",
")",
"{",
"return",
"array",
".",
"contains",
"(",
"b",
",",
"key",
")",
";",
"}",
")",
";",
"}"
] | Finds the intersections between array1 and array2
@method intersect
@param {Array} array1 Source Array
@param {Array} array2 Comparison Array
@return {Array} Array of the intersections | [
"Finds",
"the",
"intersections",
"between",
"array1",
"and",
"array2"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L609-L616 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj, arg ) {
var n = obj.length - 1;
if ( arg >= ( n + 1 ) ) {
return obj;
}
else if ( isNaN( arg ) || arg === 1 ) {
return obj[n];
}
else {
return array.limit( obj, ( n - ( --arg ) ), n );
}
} | javascript | function ( obj, arg ) {
var n = obj.length - 1;
if ( arg >= ( n + 1 ) ) {
return obj;
}
else if ( isNaN( arg ) || arg === 1 ) {
return obj[n];
}
else {
return array.limit( obj, ( n - ( --arg ) ), n );
}
} | [
"function",
"(",
"obj",
",",
"arg",
")",
"{",
"var",
"n",
"=",
"obj",
".",
"length",
"-",
"1",
";",
"if",
"(",
"arg",
">=",
"(",
"n",
"+",
"1",
")",
")",
"{",
"return",
"obj",
";",
"}",
"else",
"if",
"(",
"isNaN",
"(",
"arg",
")",
"||",
"arg",
"===",
"1",
")",
"{",
"return",
"obj",
"[",
"n",
"]",
";",
"}",
"else",
"{",
"return",
"array",
".",
"limit",
"(",
"obj",
",",
"(",
"n",
"-",
"(",
"--",
"arg",
")",
")",
",",
"n",
")",
";",
"}",
"}"
] | Returns the last index of the Array
@method last
@param {Array} obj Array
@param {Number} arg [Optional] Negative offset from last index to return
@return {Mixed} Last index( s ) of Array | [
"Returns",
"the",
"last",
"index",
"of",
"the",
"Array"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L717-L729 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj, start, offset ) {
var result = [],
i = start - 1,
nth = start + offset,
max = obj.length;
if ( max > 0 ) {
while ( ++i < nth && i < max ) {
result.push( obj[i] );
}
}
return result;
} | javascript | function ( obj, start, offset ) {
var result = [],
i = start - 1,
nth = start + offset,
max = obj.length;
if ( max > 0 ) {
while ( ++i < nth && i < max ) {
result.push( obj[i] );
}
}
return result;
} | [
"function",
"(",
"obj",
",",
"start",
",",
"offset",
")",
"{",
"var",
"result",
"=",
"[",
"]",
",",
"i",
"=",
"start",
"-",
"1",
",",
"nth",
"=",
"start",
"+",
"offset",
",",
"max",
"=",
"obj",
".",
"length",
";",
"if",
"(",
"max",
">",
"0",
")",
"{",
"while",
"(",
"++",
"i",
"<",
"nth",
"&&",
"i",
"<",
"max",
")",
"{",
"result",
".",
"push",
"(",
"obj",
"[",
"i",
"]",
")",
";",
"}",
"}",
"return",
"result",
";",
"}"
] | Returns a limited range of indices from the Array
@method limit
@param {Array} obj Array to iterate
@param {Number} start Starting index
@param {Number} offset Number of indices to return
@return {Array} Array of indices | [
"Returns",
"a",
"limited",
"range",
"of",
"indices",
"from",
"the",
"Array"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L740-L753 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj, arg ) {
array.each( arg, function ( i ) {
array.add( obj, i );
});
return obj;
} | javascript | function ( obj, arg ) {
array.each( arg, function ( i ) {
array.add( obj, i );
});
return obj;
} | [
"function",
"(",
"obj",
",",
"arg",
")",
"{",
"array",
".",
"each",
"(",
"arg",
",",
"function",
"(",
"i",
")",
"{",
"array",
".",
"add",
"(",
"obj",
",",
"i",
")",
";",
"}",
")",
";",
"return",
"obj",
";",
"}"
] | Merges `arg` into `obj`, excluding duplicate indices
@method merge
@param {Array} obj Array to receive indices
@param {Array} arg Array to merge
@return {Array} obj | [
"Merges",
"arg",
"into",
"obj",
"excluding",
"duplicate",
"indices"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L800-L806 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj1, obj2 ) {
var result;
result = obj1.map( function ( i, idx ) {
return [i, obj2[idx]];
});
return result;
} | javascript | function ( obj1, obj2 ) {
var result;
result = obj1.map( function ( i, idx ) {
return [i, obj2[idx]];
});
return result;
} | [
"function",
"(",
"obj1",
",",
"obj2",
")",
"{",
"var",
"result",
";",
"result",
"=",
"obj1",
".",
"map",
"(",
"function",
"(",
"i",
",",
"idx",
")",
"{",
"return",
"[",
"i",
",",
"obj2",
"[",
"idx",
"]",
"]",
";",
"}",
")",
";",
"return",
"result",
";",
"}"
] | Mingles Arrays and returns a 2D Array
@method mingle
@param {Array} obj1 Array to mingle
@param {Array} obj2 Array to mingle
@return {Array} 2D Array | [
"Mingles",
"Arrays",
"and",
"returns",
"a",
"2D",
"Array"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L827-L835 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj ) {
var values = {},
count = 0,
nth = 0,
mode = [],
result;
// Counting values
array.each( obj, function ( i ) {
if ( !isNaN( values[i] ) ) {
values[i]++;
}
else {
values[i] = 1;
}
});
// Finding the highest occurring count
count = array.max( array.cast( values ) );
// Finding values that match the count
utility.iterate( values, function ( v, k ) {
if ( v === count ) {
mode.push( number.parse( k ) );
}
});
// Determining the result
nth = mode.length;
if ( nth > 0 ) {
result = nth === 1 ? mode[0] : mode;
}
return result;
} | javascript | function ( obj ) {
var values = {},
count = 0,
nth = 0,
mode = [],
result;
// Counting values
array.each( obj, function ( i ) {
if ( !isNaN( values[i] ) ) {
values[i]++;
}
else {
values[i] = 1;
}
});
// Finding the highest occurring count
count = array.max( array.cast( values ) );
// Finding values that match the count
utility.iterate( values, function ( v, k ) {
if ( v === count ) {
mode.push( number.parse( k ) );
}
});
// Determining the result
nth = mode.length;
if ( nth > 0 ) {
result = nth === 1 ? mode[0] : mode;
}
return result;
} | [
"function",
"(",
"obj",
")",
"{",
"var",
"values",
"=",
"{",
"}",
",",
"count",
"=",
"0",
",",
"nth",
"=",
"0",
",",
"mode",
"=",
"[",
"]",
",",
"result",
";",
"array",
".",
"each",
"(",
"obj",
",",
"function",
"(",
"i",
")",
"{",
"if",
"(",
"!",
"isNaN",
"(",
"values",
"[",
"i",
"]",
")",
")",
"{",
"values",
"[",
"i",
"]",
"++",
";",
"}",
"else",
"{",
"values",
"[",
"i",
"]",
"=",
"1",
";",
"}",
"}",
")",
";",
"count",
"=",
"array",
".",
"max",
"(",
"array",
".",
"cast",
"(",
"values",
")",
")",
";",
"utility",
".",
"iterate",
"(",
"values",
",",
"function",
"(",
"v",
",",
"k",
")",
"{",
"if",
"(",
"v",
"===",
"count",
")",
"{",
"mode",
".",
"push",
"(",
"number",
".",
"parse",
"(",
"k",
")",
")",
";",
"}",
"}",
")",
";",
"nth",
"=",
"mode",
".",
"length",
";",
"if",
"(",
"nth",
">",
"0",
")",
"{",
"result",
"=",
"nth",
"===",
"1",
"?",
"mode",
"[",
"0",
"]",
":",
"mode",
";",
"}",
"return",
"result",
";",
"}"
] | Finds the mode value of an Array
@method mode
@param {Array} obj Array to parse
@return {Mixed} Mode value of the Array | [
"Finds",
"the",
"mode",
"value",
"of",
"an",
"Array"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L844-L879 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj, arg ) {
array.remove( obj, 0, obj.length );
array.each( arg, function ( i ) {
obj.push( i );
});
return obj;
} | javascript | function ( obj, arg ) {
array.remove( obj, 0, obj.length );
array.each( arg, function ( i ) {
obj.push( i );
});
return obj;
} | [
"function",
"(",
"obj",
",",
"arg",
")",
"{",
"array",
".",
"remove",
"(",
"obj",
",",
"0",
",",
"obj",
".",
"length",
")",
";",
"array",
".",
"each",
"(",
"arg",
",",
"function",
"(",
"i",
")",
"{",
"obj",
".",
"push",
"(",
"i",
")",
";",
"}",
")",
";",
"return",
"obj",
";",
"}"
] | Replaces the contents of `obj` with `arg`
@method replace
@param {Array} obj Array to modify
@param {Array} arg Array to become `obj`
@return {Array} New version of `obj` | [
"Replaces",
"the",
"contents",
"of",
"obj",
"with",
"arg"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L980-L987 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj, start, end ) {
if ( isNaN( start ) ) {
start = obj.index( start );
if ( start === -1 ) {
return obj;
}
}
else {
start = start || 0;
}
var length = obj.length,
remaining = obj.slice( ( end || start ) + 1 || length );
obj.length = start < 0 ? ( length + start ) : start;
obj.push.apply( obj, remaining );
return obj;
} | javascript | function ( obj, start, end ) {
if ( isNaN( start ) ) {
start = obj.index( start );
if ( start === -1 ) {
return obj;
}
}
else {
start = start || 0;
}
var length = obj.length,
remaining = obj.slice( ( end || start ) + 1 || length );
obj.length = start < 0 ? ( length + start ) : start;
obj.push.apply( obj, remaining );
return obj;
} | [
"function",
"(",
"obj",
",",
"start",
",",
"end",
")",
"{",
"if",
"(",
"isNaN",
"(",
"start",
")",
")",
"{",
"start",
"=",
"obj",
".",
"index",
"(",
"start",
")",
";",
"if",
"(",
"start",
"===",
"-",
"1",
")",
"{",
"return",
"obj",
";",
"}",
"}",
"else",
"{",
"start",
"=",
"start",
"||",
"0",
";",
"}",
"var",
"length",
"=",
"obj",
".",
"length",
",",
"remaining",
"=",
"obj",
".",
"slice",
"(",
"(",
"end",
"||",
"start",
")",
"+",
"1",
"||",
"length",
")",
";",
"obj",
".",
"length",
"=",
"start",
"<",
"0",
"?",
"(",
"length",
"+",
"start",
")",
":",
"start",
";",
"obj",
".",
"push",
".",
"apply",
"(",
"obj",
",",
"remaining",
")",
";",
"return",
"obj",
";",
"}"
] | Removes indices from an Array without recreating it
@method remove
@param {Array} obj Array to remove from
@param {Mixed} start Starting index, or value to find within obj
@param {Number} end [Optional] Ending index
@return {Array} Modified Array | [
"Removes",
"indices",
"from",
"an",
"Array",
"without",
"recreating",
"it"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L998-L1017 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj, fn ) {
var remove;
if ( typeof fn !== "function" ) {
throw new Error( label.error.invalidArguments );
}
remove = obj.filter( fn );
array.each( remove, function ( i ) {
array.remove( obj, array.index ( obj, i ) );
});
return obj;
} | javascript | function ( obj, fn ) {
var remove;
if ( typeof fn !== "function" ) {
throw new Error( label.error.invalidArguments );
}
remove = obj.filter( fn );
array.each( remove, function ( i ) {
array.remove( obj, array.index ( obj, i ) );
});
return obj;
} | [
"function",
"(",
"obj",
",",
"fn",
")",
"{",
"var",
"remove",
";",
"if",
"(",
"typeof",
"fn",
"!==",
"\"function\"",
")",
"{",
"throw",
"new",
"Error",
"(",
"label",
".",
"error",
".",
"invalidArguments",
")",
";",
"}",
"remove",
"=",
"obj",
".",
"filter",
"(",
"fn",
")",
";",
"array",
".",
"each",
"(",
"remove",
",",
"function",
"(",
"i",
")",
"{",
"array",
".",
"remove",
"(",
"obj",
",",
"array",
".",
"index",
"(",
"obj",
",",
"i",
")",
")",
";",
"}",
")",
";",
"return",
"obj",
";",
"}"
] | Deletes every element of `obj` for which `fn` evaluates to true
@method removeIf
@param {Array} obj Array to iterate
@param {Function} fn Function to test indices against
@return {Array} Array | [
"Deletes",
"every",
"element",
"of",
"obj",
"for",
"which",
"fn",
"evaluates",
"to",
"true"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L1027-L1041 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj, fn ) {
if ( typeof fn !== "function" ) {
throw new Error( label.error.invalidArguments );
}
var remove = [];
array.each( obj, function ( i ) {
if ( fn( i ) !== false ) {
remove.push( i );
}
else {
return false;
}
});
array.each( remove, function ( i ) {
array.remove( obj, array.index( obj, i) );
});
return obj;
} | javascript | function ( obj, fn ) {
if ( typeof fn !== "function" ) {
throw new Error( label.error.invalidArguments );
}
var remove = [];
array.each( obj, function ( i ) {
if ( fn( i ) !== false ) {
remove.push( i );
}
else {
return false;
}
});
array.each( remove, function ( i ) {
array.remove( obj, array.index( obj, i) );
});
return obj;
} | [
"function",
"(",
"obj",
",",
"fn",
")",
"{",
"if",
"(",
"typeof",
"fn",
"!==",
"\"function\"",
")",
"{",
"throw",
"new",
"Error",
"(",
"label",
".",
"error",
".",
"invalidArguments",
")",
";",
"}",
"var",
"remove",
"=",
"[",
"]",
";",
"array",
".",
"each",
"(",
"obj",
",",
"function",
"(",
"i",
")",
"{",
"if",
"(",
"fn",
"(",
"i",
")",
"!==",
"false",
")",
"{",
"remove",
".",
"push",
"(",
"i",
")",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
")",
";",
"array",
".",
"each",
"(",
"remove",
",",
"function",
"(",
"i",
")",
"{",
"array",
".",
"remove",
"(",
"obj",
",",
"array",
".",
"index",
"(",
"obj",
",",
"i",
")",
")",
";",
"}",
")",
";",
"return",
"obj",
";",
"}"
] | Deletes elements of `obj` until `fn` evaluates to false
@method removeWhile
@param {Array} obj Array to iterate
@param {Function} fn Function to test indices against
@return {Array} Array | [
"Deletes",
"elements",
"of",
"obj",
"until",
"fn",
"evaluates",
"to",
"false"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L1051-L1072 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj, arg ) {
arg = arg || 1;
if ( arg < 1 ) {
arg = 1;
}
return array.limit( obj, arg, obj.length );
} | javascript | function ( obj, arg ) {
arg = arg || 1;
if ( arg < 1 ) {
arg = 1;
}
return array.limit( obj, arg, obj.length );
} | [
"function",
"(",
"obj",
",",
"arg",
")",
"{",
"arg",
"=",
"arg",
"||",
"1",
";",
"if",
"(",
"arg",
"<",
"1",
")",
"{",
"arg",
"=",
"1",
";",
"}",
"return",
"array",
".",
"limit",
"(",
"obj",
",",
"arg",
",",
"obj",
".",
"length",
")",
";",
"}"
] | Returns the "rest" of `obj` from `arg`
@method rest
@param {Array} obj Array to parse
@param {Number} arg [Optional] Start position of subset of `obj` ( positive number only )
@return {Array} Array of a subset of `obj` | [
"Returns",
"the",
"rest",
"of",
"obj",
"from",
"arg"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L1082-L1090 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj, arg ) {
var result = -1;
array.each( obj, function ( i, idx ) {
if ( i === arg ) {
result = idx;
}
});
return result;
} | javascript | function ( obj, arg ) {
var result = -1;
array.each( obj, function ( i, idx ) {
if ( i === arg ) {
result = idx;
}
});
return result;
} | [
"function",
"(",
"obj",
",",
"arg",
")",
"{",
"var",
"result",
"=",
"-",
"1",
";",
"array",
".",
"each",
"(",
"obj",
",",
"function",
"(",
"i",
",",
"idx",
")",
"{",
"if",
"(",
"i",
"===",
"arg",
")",
"{",
"result",
"=",
"idx",
";",
"}",
"}",
")",
";",
"return",
"result",
";",
"}"
] | Finds the last index of `arg` in `obj`
@method rindex
@param {Array} obj Array to search
@param {Mixed} arg Primitive to find
@return {Mixed} Index or undefined | [
"Finds",
"the",
"last",
"index",
"of",
"arg",
"in",
"obj"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L1100-L1110 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj, arg ) {
var nth = obj.length,
result;
if ( arg === 0 ) {
result = obj;
}
else {
if ( arg < 0 ) {
arg += nth;
}
else {
arg--;
}
result = array.limit( obj, arg, nth );
result = result.concat( array.limit( obj, 0, arg ) );
}
return result;
} | javascript | function ( obj, arg ) {
var nth = obj.length,
result;
if ( arg === 0 ) {
result = obj;
}
else {
if ( arg < 0 ) {
arg += nth;
}
else {
arg--;
}
result = array.limit( obj, arg, nth );
result = result.concat( array.limit( obj, 0, arg ) );
}
return result;
} | [
"function",
"(",
"obj",
",",
"arg",
")",
"{",
"var",
"nth",
"=",
"obj",
".",
"length",
",",
"result",
";",
"if",
"(",
"arg",
"===",
"0",
")",
"{",
"result",
"=",
"obj",
";",
"}",
"else",
"{",
"if",
"(",
"arg",
"<",
"0",
")",
"{",
"arg",
"+=",
"nth",
";",
"}",
"else",
"{",
"arg",
"--",
";",
"}",
"result",
"=",
"array",
".",
"limit",
"(",
"obj",
",",
"arg",
",",
"nth",
")",
";",
"result",
"=",
"result",
".",
"concat",
"(",
"array",
".",
"limit",
"(",
"obj",
",",
"0",
",",
"arg",
")",
")",
";",
"}",
"return",
"result",
";",
"}"
] | Returns new Array with `arg` moved to the first index
@method rotate
@param {Array} obj Array to rotate
@param {Number} arg Index to become the first index, if negative the rotation is in the opposite direction
@return {Array} Newly rotated Array | [
"Returns",
"new",
"Array",
"with",
"arg",
"moved",
"to",
"the",
"first",
"index"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L1120-L1140 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( start, end, offset ) {
start = start || 0;
end = end || start;
offset = offset || 1;
var result = [],
n = -1,
nth = Math.max( 0, Math.ceil( ( end - start ) / offset ) );
while ( ++n < nth ) {
result[n] = start;
start += offset;
}
return result;
} | javascript | function ( start, end, offset ) {
start = start || 0;
end = end || start;
offset = offset || 1;
var result = [],
n = -1,
nth = Math.max( 0, Math.ceil( ( end - start ) / offset ) );
while ( ++n < nth ) {
result[n] = start;
start += offset;
}
return result;
} | [
"function",
"(",
"start",
",",
"end",
",",
"offset",
")",
"{",
"start",
"=",
"start",
"||",
"0",
";",
"end",
"=",
"end",
"||",
"start",
";",
"offset",
"=",
"offset",
"||",
"1",
";",
"var",
"result",
"=",
"[",
"]",
",",
"n",
"=",
"-",
"1",
",",
"nth",
"=",
"Math",
".",
"max",
"(",
"0",
",",
"Math",
".",
"ceil",
"(",
"(",
"end",
"-",
"start",
")",
"/",
"offset",
")",
")",
";",
"while",
"(",
"++",
"n",
"<",
"nth",
")",
"{",
"result",
"[",
"n",
"]",
"=",
"start",
";",
"start",
"+=",
"offset",
";",
"}",
"return",
"result",
";",
"}"
] | Generates a series Array
@method series
@param {Number} start Start value the series
@param {Number} end [Optional] The end of the series
@param {Number} offset [Optional] Offset for indices, default is 1
@return {Array} Array of new series | [
"Generates",
"a",
"series",
"Array"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L1151-L1165 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj, divisor ) {
var result = [],
total = obj.length,
nth = Math.ceil( total / divisor ),
low = Math.floor( total / divisor ),
lower = Math.ceil( total / nth ),
lowered = false,
start = 0,
i = -1;
// Finding the fold
if ( number.diff( total, ( divisor * nth ) ) > nth ) {
lower = total - ( low * divisor ) + low - 1;
}
else if ( total % divisor > 0 && lower * nth >= total ) {
lower--;
}
while ( ++i < divisor ) {
if ( i > 0 ) {
start = start + nth;
}
if ( !lowered && lower < divisor && i === lower ) {
--nth;
lowered = true;
}
result.push( array.limit( obj, start, nth ) );
}
return result;
} | javascript | function ( obj, divisor ) {
var result = [],
total = obj.length,
nth = Math.ceil( total / divisor ),
low = Math.floor( total / divisor ),
lower = Math.ceil( total / nth ),
lowered = false,
start = 0,
i = -1;
// Finding the fold
if ( number.diff( total, ( divisor * nth ) ) > nth ) {
lower = total - ( low * divisor ) + low - 1;
}
else if ( total % divisor > 0 && lower * nth >= total ) {
lower--;
}
while ( ++i < divisor ) {
if ( i > 0 ) {
start = start + nth;
}
if ( !lowered && lower < divisor && i === lower ) {
--nth;
lowered = true;
}
result.push( array.limit( obj, start, nth ) );
}
return result;
} | [
"function",
"(",
"obj",
",",
"divisor",
")",
"{",
"var",
"result",
"=",
"[",
"]",
",",
"total",
"=",
"obj",
".",
"length",
",",
"nth",
"=",
"Math",
".",
"ceil",
"(",
"total",
"/",
"divisor",
")",
",",
"low",
"=",
"Math",
".",
"floor",
"(",
"total",
"/",
"divisor",
")",
",",
"lower",
"=",
"Math",
".",
"ceil",
"(",
"total",
"/",
"nth",
")",
",",
"lowered",
"=",
"false",
",",
"start",
"=",
"0",
",",
"i",
"=",
"-",
"1",
";",
"if",
"(",
"number",
".",
"diff",
"(",
"total",
",",
"(",
"divisor",
"*",
"nth",
")",
")",
">",
"nth",
")",
"{",
"lower",
"=",
"total",
"-",
"(",
"low",
"*",
"divisor",
")",
"+",
"low",
"-",
"1",
";",
"}",
"else",
"if",
"(",
"total",
"%",
"divisor",
">",
"0",
"&&",
"lower",
"*",
"nth",
">=",
"total",
")",
"{",
"lower",
"--",
";",
"}",
"while",
"(",
"++",
"i",
"<",
"divisor",
")",
"{",
"if",
"(",
"i",
">",
"0",
")",
"{",
"start",
"=",
"start",
"+",
"nth",
";",
"}",
"if",
"(",
"!",
"lowered",
"&&",
"lower",
"<",
"divisor",
"&&",
"i",
"===",
"lower",
")",
"{",
"--",
"nth",
";",
"lowered",
"=",
"true",
";",
"}",
"result",
".",
"push",
"(",
"array",
".",
"limit",
"(",
"obj",
",",
"start",
",",
"nth",
")",
")",
";",
"}",
"return",
"result",
";",
"}"
] | Splits an Array by divisor
@method split
@param {Array} obj Array to parse
@param {Number} divisor Integer to divide the Array by
@return {Array} Split Array | [
"Splits",
"an",
"Array",
"by",
"divisor"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L1175-L1207 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( a, b ) {
var types = {a: typeof a, b: typeof b},
c, d, result;
if ( types.a === "number" && types.b === "number" ) {
result = a - b;
}
else {
c = a.toString();
d = b.toString();
if ( c < d ) {
result = -1;
}
else if ( c > d ) {
result = 1;
}
else if ( types.a === types.b ) {
result = 0;
}
else if ( types.a === "boolean" ) {
result = -1;
}
else {
result = 1;
}
}
return result;
} | javascript | function ( a, b ) {
var types = {a: typeof a, b: typeof b},
c, d, result;
if ( types.a === "number" && types.b === "number" ) {
result = a - b;
}
else {
c = a.toString();
d = b.toString();
if ( c < d ) {
result = -1;
}
else if ( c > d ) {
result = 1;
}
else if ( types.a === types.b ) {
result = 0;
}
else if ( types.a === "boolean" ) {
result = -1;
}
else {
result = 1;
}
}
return result;
} | [
"function",
"(",
"a",
",",
"b",
")",
"{",
"var",
"types",
"=",
"{",
"a",
":",
"typeof",
"a",
",",
"b",
":",
"typeof",
"b",
"}",
",",
"c",
",",
"d",
",",
"result",
";",
"if",
"(",
"types",
".",
"a",
"===",
"\"number\"",
"&&",
"types",
".",
"b",
"===",
"\"number\"",
")",
"{",
"result",
"=",
"a",
"-",
"b",
";",
"}",
"else",
"{",
"c",
"=",
"a",
".",
"toString",
"(",
")",
";",
"d",
"=",
"b",
".",
"toString",
"(",
")",
";",
"if",
"(",
"c",
"<",
"d",
")",
"{",
"result",
"=",
"-",
"1",
";",
"}",
"else",
"if",
"(",
"c",
">",
"d",
")",
"{",
"result",
"=",
"1",
";",
"}",
"else",
"if",
"(",
"types",
".",
"a",
"===",
"types",
".",
"b",
")",
"{",
"result",
"=",
"0",
";",
"}",
"else",
"if",
"(",
"types",
".",
"a",
"===",
"\"boolean\"",
")",
"{",
"result",
"=",
"-",
"1",
";",
"}",
"else",
"{",
"result",
"=",
"1",
";",
"}",
"}",
"return",
"result",
";",
"}"
] | Sorts the Array by parsing values
@method sort
@param {Mixed} a Argument to compare
@param {Mixed} b Argument to compare
@return {Number} Number indicating sort order | [
"Sorts",
"the",
"Array",
"by",
"parsing",
"values"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L1217-L1246 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj ) {
var result = 0;
if ( obj.length > 0 ) {
result = obj.reduce( function ( prev, cur ) {
return prev + cur;
});
}
return result;
} | javascript | function ( obj ) {
var result = 0;
if ( obj.length > 0 ) {
result = obj.reduce( function ( prev, cur ) {
return prev + cur;
});
}
return result;
} | [
"function",
"(",
"obj",
")",
"{",
"var",
"result",
"=",
"0",
";",
"if",
"(",
"obj",
".",
"length",
">",
"0",
")",
"{",
"result",
"=",
"obj",
".",
"reduce",
"(",
"function",
"(",
"prev",
",",
"cur",
")",
"{",
"return",
"prev",
"+",
"cur",
";",
"}",
")",
";",
"}",
"return",
"result",
";",
"}"
] | Gets the summation of an Array of numbers
@method sum
@param {Array} obj Array to sum
@return {Number} Summation of Array | [
"Gets",
"the",
"summation",
"of",
"an",
"Array",
"of",
"numbers"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L1277-L1287 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( ar ) {
var obj = {},
i = ar.length;
while ( i-- ) {
obj[i.toString()] = ar[i];
}
return obj;
} | javascript | function ( ar ) {
var obj = {},
i = ar.length;
while ( i-- ) {
obj[i.toString()] = ar[i];
}
return obj;
} | [
"function",
"(",
"ar",
")",
"{",
"var",
"obj",
"=",
"{",
"}",
",",
"i",
"=",
"ar",
".",
"length",
";",
"while",
"(",
"i",
"--",
")",
"{",
"obj",
"[",
"i",
".",
"toString",
"(",
")",
"]",
"=",
"ar",
"[",
"i",
"]",
";",
"}",
"return",
"obj",
";",
"}"
] | Casts an Array to Object
@method toObject
@param {Array} ar Array to transform
@return {Object} New object | [
"Casts",
"an",
"Array",
"to",
"Object"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L1319-L1328 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj ) {
var result = [];
array.each( obj, function ( i ) {
array.add( result, i );
});
return result;
} | javascript | function ( obj ) {
var result = [];
array.each( obj, function ( i ) {
array.add( result, i );
});
return result;
} | [
"function",
"(",
"obj",
")",
"{",
"var",
"result",
"=",
"[",
"]",
";",
"array",
".",
"each",
"(",
"obj",
",",
"function",
"(",
"i",
")",
"{",
"array",
".",
"add",
"(",
"result",
",",
"i",
")",
";",
"}",
")",
";",
"return",
"result",
";",
"}"
] | Returns an Array of unique indices of `obj`
@method unique
@param {Array} obj Array to parse
@return {Array} Array of unique indices | [
"Returns",
"an",
"Array",
"of",
"unique",
"indices",
"of",
"obj"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L1337-L1345 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj, args ) {
var result = [];
// Preparing args
if ( !(args instanceof Array) ) {
args = typeof args === "object" ? array.cast( args ) : [args];
}
array.each( args, function ( i, idx ) {
if ( !( i instanceof Array ) ) {
this[idx] = [i];
}
});
// Building result Array
array.each( obj, function ( i, idx ) {
result[idx] = [i];
array.each( args, function ( x ) {
result[idx].push( x[idx] || null );
});
});
return result;
} | javascript | function ( obj, args ) {
var result = [];
// Preparing args
if ( !(args instanceof Array) ) {
args = typeof args === "object" ? array.cast( args ) : [args];
}
array.each( args, function ( i, idx ) {
if ( !( i instanceof Array ) ) {
this[idx] = [i];
}
});
// Building result Array
array.each( obj, function ( i, idx ) {
result[idx] = [i];
array.each( args, function ( x ) {
result[idx].push( x[idx] || null );
});
});
return result;
} | [
"function",
"(",
"obj",
",",
"args",
")",
"{",
"var",
"result",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"(",
"args",
"instanceof",
"Array",
")",
")",
"{",
"args",
"=",
"typeof",
"args",
"===",
"\"object\"",
"?",
"array",
".",
"cast",
"(",
"args",
")",
":",
"[",
"args",
"]",
";",
"}",
"array",
".",
"each",
"(",
"args",
",",
"function",
"(",
"i",
",",
"idx",
")",
"{",
"if",
"(",
"!",
"(",
"i",
"instanceof",
"Array",
")",
")",
"{",
"this",
"[",
"idx",
"]",
"=",
"[",
"i",
"]",
";",
"}",
"}",
")",
";",
"array",
".",
"each",
"(",
"obj",
",",
"function",
"(",
"i",
",",
"idx",
")",
"{",
"result",
"[",
"idx",
"]",
"=",
"[",
"i",
"]",
";",
"array",
".",
"each",
"(",
"args",
",",
"function",
"(",
"x",
")",
"{",
"result",
"[",
"idx",
"]",
".",
"push",
"(",
"x",
"[",
"idx",
"]",
"||",
"null",
")",
";",
"}",
")",
";",
"}",
")",
";",
"return",
"result",
";",
"}"
] | Converts any arguments to Arrays, then merges elements of `obj` with corresponding elements from each argument
@method zip
@param {Array} obj Array to transform
@param {Mixed} args Argument instance or Array to merge
@return {Array} Array | [
"Converts",
"any",
"arguments",
"to",
"Arrays",
"then",
"merges",
"elements",
"of",
"obj",
"with",
"corresponding",
"elements",
"from",
"each",
"argument"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L1381-L1404 | train |
|
avoidwork/abaaso | lib/abaaso.js | function () {
return utility.iterate( cache.items, function ( v, k ) {
if ( cache.expired( k ) ) {
cache.expire( k, true );
}
});
} | javascript | function () {
return utility.iterate( cache.items, function ( v, k ) {
if ( cache.expired( k ) ) {
cache.expire( k, true );
}
});
} | [
"function",
"(",
")",
"{",
"return",
"utility",
".",
"iterate",
"(",
"cache",
".",
"items",
",",
"function",
"(",
"v",
",",
"k",
")",
"{",
"if",
"(",
"cache",
".",
"expired",
"(",
"k",
")",
")",
"{",
"cache",
".",
"expire",
"(",
"k",
",",
"true",
")",
";",
"}",
"}",
")",
";",
"}"
] | Garbage collector for the cached items
@method clean
@private
@return {Undefined} undefined | [
"Garbage",
"collector",
"for",
"the",
"cached",
"items"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L1419-L1425 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( uri, silent ) {
silent = ( silent === true );
if ( cache.items[uri] !== undefined ) {
delete cache.items[uri];
if ( !silent ) {
observer.fire( uri, "beforeExpire, expire, afterExpire" );
}
return true;
}
else {
return false;
}
} | javascript | function ( uri, silent ) {
silent = ( silent === true );
if ( cache.items[uri] !== undefined ) {
delete cache.items[uri];
if ( !silent ) {
observer.fire( uri, "beforeExpire, expire, afterExpire" );
}
return true;
}
else {
return false;
}
} | [
"function",
"(",
"uri",
",",
"silent",
")",
"{",
"silent",
"=",
"(",
"silent",
"===",
"true",
")",
";",
"if",
"(",
"cache",
".",
"items",
"[",
"uri",
"]",
"!==",
"undefined",
")",
"{",
"delete",
"cache",
".",
"items",
"[",
"uri",
"]",
";",
"if",
"(",
"!",
"silent",
")",
"{",
"observer",
".",
"fire",
"(",
"uri",
",",
"\"beforeExpire, expire, afterExpire\"",
")",
";",
"}",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Expires a URI from the local cache
Events: expire Fires when the URI expires
@method expire
@private
@param {String} uri URI of the local representation
@param {Boolean} silent [Optional] If 'true', the event will not fire
@return {Undefined} undefined | [
"Expires",
"a",
"URI",
"from",
"the",
"local",
"cache"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L1438-L1452 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( uri ) {
var item = cache.items[uri];
return item !== undefined && item.expires !== undefined && item.expires < new Date();
} | javascript | function ( uri ) {
var item = cache.items[uri];
return item !== undefined && item.expires !== undefined && item.expires < new Date();
} | [
"function",
"(",
"uri",
")",
"{",
"var",
"item",
"=",
"cache",
".",
"items",
"[",
"uri",
"]",
";",
"return",
"item",
"!==",
"undefined",
"&&",
"item",
".",
"expires",
"!==",
"undefined",
"&&",
"item",
".",
"expires",
"<",
"new",
"Date",
"(",
")",
";",
"}"
] | Determines if a URI has expired
@method expired
@private
@param {Object} uri Cached URI object
@return {Boolean} True if the URI has expired | [
"Determines",
"if",
"a",
"URI",
"has",
"expired"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L1462-L1466 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( uri, property, value ) {
uri = utility.parse( uri ).href;
if ( cache.items[uri] === undefined ) {
cache.items[uri] = {};
cache.items[uri].permission = 0;
}
if ( property === "permission" ) {
cache.items[uri].permission |= value;
}
else if ( property === "!permission" ) {
cache.items[uri].permission &= ~value;
}
else {
cache.items[uri][property] = value;
}
return cache.items[uri];
} | javascript | function ( uri, property, value ) {
uri = utility.parse( uri ).href;
if ( cache.items[uri] === undefined ) {
cache.items[uri] = {};
cache.items[uri].permission = 0;
}
if ( property === "permission" ) {
cache.items[uri].permission |= value;
}
else if ( property === "!permission" ) {
cache.items[uri].permission &= ~value;
}
else {
cache.items[uri][property] = value;
}
return cache.items[uri];
} | [
"function",
"(",
"uri",
",",
"property",
",",
"value",
")",
"{",
"uri",
"=",
"utility",
".",
"parse",
"(",
"uri",
")",
".",
"href",
";",
"if",
"(",
"cache",
".",
"items",
"[",
"uri",
"]",
"===",
"undefined",
")",
"{",
"cache",
".",
"items",
"[",
"uri",
"]",
"=",
"{",
"}",
";",
"cache",
".",
"items",
"[",
"uri",
"]",
".",
"permission",
"=",
"0",
";",
"}",
"if",
"(",
"property",
"===",
"\"permission\"",
")",
"{",
"cache",
".",
"items",
"[",
"uri",
"]",
".",
"permission",
"|=",
"value",
";",
"}",
"else",
"if",
"(",
"property",
"===",
"\"!permission\"",
")",
"{",
"cache",
".",
"items",
"[",
"uri",
"]",
".",
"permission",
"&=",
"~",
"value",
";",
"}",
"else",
"{",
"cache",
".",
"items",
"[",
"uri",
"]",
"[",
"property",
"]",
"=",
"value",
";",
"}",
"return",
"cache",
".",
"items",
"[",
"uri",
"]",
";",
"}"
] | Sets, or updates an item in cache.items
@method set
@private
@param {String} uri URI to set or update
@param {String} property Property of the cached URI to set
@param {Mixed} value Value to set
@return {Mixed} URI Object {headers, response} or undefined | [
"Sets",
"or",
"updates",
"an",
"item",
"in",
"cache",
".",
"items"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L1505-L1524 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( uri, verb ) {
if ( string.isEmpty( uri ) || string.isEmpty( verb ) ) {
throw new Error( label.error.invalidArguments );
}
uri = utility.parse( uri ).href;
verb = verb.toLowerCase();
var result = false,
bit = 0;
if ( !cache.get( uri, false ) ) {
result = undefined;
}
else {
if ( regex.del.test( verb ) ) {
bit = 1;
}
else if ( regex.get_headers.test( verb ) ) {
bit = 4;
}
else if ( regex.put_post.test( verb ) ) {
bit = 2;
}
else if ( regex.patch.test( verb ) ) {
bit = 8;
}
result = Boolean( client.permissions( uri, verb ).bit & bit );
}
return result;
} | javascript | function ( uri, verb ) {
if ( string.isEmpty( uri ) || string.isEmpty( verb ) ) {
throw new Error( label.error.invalidArguments );
}
uri = utility.parse( uri ).href;
verb = verb.toLowerCase();
var result = false,
bit = 0;
if ( !cache.get( uri, false ) ) {
result = undefined;
}
else {
if ( regex.del.test( verb ) ) {
bit = 1;
}
else if ( regex.get_headers.test( verb ) ) {
bit = 4;
}
else if ( regex.put_post.test( verb ) ) {
bit = 2;
}
else if ( regex.patch.test( verb ) ) {
bit = 8;
}
result = Boolean( client.permissions( uri, verb ).bit & bit );
}
return result;
} | [
"function",
"(",
"uri",
",",
"verb",
")",
"{",
"if",
"(",
"string",
".",
"isEmpty",
"(",
"uri",
")",
"||",
"string",
".",
"isEmpty",
"(",
"verb",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"label",
".",
"error",
".",
"invalidArguments",
")",
";",
"}",
"uri",
"=",
"utility",
".",
"parse",
"(",
"uri",
")",
".",
"href",
";",
"verb",
"=",
"verb",
".",
"toLowerCase",
"(",
")",
";",
"var",
"result",
"=",
"false",
",",
"bit",
"=",
"0",
";",
"if",
"(",
"!",
"cache",
".",
"get",
"(",
"uri",
",",
"false",
")",
")",
"{",
"result",
"=",
"undefined",
";",
"}",
"else",
"{",
"if",
"(",
"regex",
".",
"del",
".",
"test",
"(",
"verb",
")",
")",
"{",
"bit",
"=",
"1",
";",
"}",
"else",
"if",
"(",
"regex",
".",
"get_headers",
".",
"test",
"(",
"verb",
")",
")",
"{",
"bit",
"=",
"4",
";",
"}",
"else",
"if",
"(",
"regex",
".",
"put_post",
".",
"test",
"(",
"verb",
")",
")",
"{",
"bit",
"=",
"2",
";",
"}",
"else",
"if",
"(",
"regex",
".",
"patch",
".",
"test",
"(",
"verb",
")",
")",
"{",
"bit",
"=",
"8",
";",
"}",
"result",
"=",
"Boolean",
"(",
"client",
".",
"permissions",
"(",
"uri",
",",
"verb",
")",
".",
"bit",
"&",
"bit",
")",
";",
"}",
"return",
"result",
";",
"}"
] | Quick way to see if a URI allows a specific verb
@method allows
@param {String} uri URI to query
@param {String} verb HTTP verb
@return {Boolean} `true` if the verb is allowed, undefined if unknown | [
"Quick",
"way",
"to",
"see",
"if",
"a",
"URI",
"allows",
"a",
"specific",
"verb"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L1816-L1847 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( args ) {
var result = 0;
array.each( args, function ( verb ) {
verb = verb.toLowerCase();
if ( regex.get_headers.test( verb ) ) {
result |= 4;
}
else if ( regex.put_post.test( verb ) ) {
result |= 2;
}
else if ( regex.patch.test( verb ) ) {
result |= 8;
}
else if ( regex.del.test( verb ) ) {
result |= 1;
}
});
return result;
} | javascript | function ( args ) {
var result = 0;
array.each( args, function ( verb ) {
verb = verb.toLowerCase();
if ( regex.get_headers.test( verb ) ) {
result |= 4;
}
else if ( regex.put_post.test( verb ) ) {
result |= 2;
}
else if ( regex.patch.test( verb ) ) {
result |= 8;
}
else if ( regex.del.test( verb ) ) {
result |= 1;
}
});
return result;
} | [
"function",
"(",
"args",
")",
"{",
"var",
"result",
"=",
"0",
";",
"array",
".",
"each",
"(",
"args",
",",
"function",
"(",
"verb",
")",
"{",
"verb",
"=",
"verb",
".",
"toLowerCase",
"(",
")",
";",
"if",
"(",
"regex",
".",
"get_headers",
".",
"test",
"(",
"verb",
")",
")",
"{",
"result",
"|=",
"4",
";",
"}",
"else",
"if",
"(",
"regex",
".",
"put_post",
".",
"test",
"(",
"verb",
")",
")",
"{",
"result",
"|=",
"2",
";",
"}",
"else",
"if",
"(",
"regex",
".",
"patch",
".",
"test",
"(",
"verb",
")",
")",
"{",
"result",
"|=",
"8",
";",
"}",
"else",
"if",
"(",
"regex",
".",
"del",
".",
"test",
"(",
"verb",
")",
")",
"{",
"result",
"|=",
"1",
";",
"}",
"}",
")",
";",
"return",
"result",
";",
"}"
] | Gets bit value based on args
@method bit
@param {Array} args Array of commands the URI accepts
@return {Number} To be set as a bit | [
"Gets",
"bit",
"value",
"based",
"on",
"args"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L1856-L1877 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( xhr, uri, type ) {
var headers = string.trim( xhr.getAllResponseHeaders() ).split( "\n" ),
items = {},
o = {},
allow = null,
expires = new Date(),
cors = client.cors( uri );
array.each( headers, function ( i ) {
var header, value;
value = i.replace( regex.header_value_replace, "" );
header = i.replace( regex.header_replace, "" );
header = string.unhyphenate( header, true ).replace( /\s+/g, "-" );
items[header] = value;
if ( allow === null ) {
if ( ( !cors && regex.allow.test( header) ) || ( cors && regex.allow_cors.test( header) ) ) {
allow = value;
}
}
});
if ( regex.no.test( items["Cache-Control"] ) ) {
// Do nothing
}
else if ( items["Cache-Control"] !== undefined && regex.number_present.test( items["Cache-Control"] ) ) {
expires = expires.setSeconds( expires.getSeconds() + number.parse( regex.number_present.exec( items["Cache-Control"] )[0], 10 ) );
}
else if ( items.Expires !== undefined ) {
expires = new Date( items.Expires );
}
else {
expires = expires.setSeconds( expires.getSeconds() + $.expires );
}
o.expires = expires;
o.headers = items;
o.permission = client.bit( allow !== null ? string.explode( allow ) : [type] );
if ( type === "get" ) {
cache.set( uri, "expires", o.expires );
cache.set( uri, "headers", o.headers );
cache.set( uri, "permission", o.permission );
}
return o;
} | javascript | function ( xhr, uri, type ) {
var headers = string.trim( xhr.getAllResponseHeaders() ).split( "\n" ),
items = {},
o = {},
allow = null,
expires = new Date(),
cors = client.cors( uri );
array.each( headers, function ( i ) {
var header, value;
value = i.replace( regex.header_value_replace, "" );
header = i.replace( regex.header_replace, "" );
header = string.unhyphenate( header, true ).replace( /\s+/g, "-" );
items[header] = value;
if ( allow === null ) {
if ( ( !cors && regex.allow.test( header) ) || ( cors && regex.allow_cors.test( header) ) ) {
allow = value;
}
}
});
if ( regex.no.test( items["Cache-Control"] ) ) {
// Do nothing
}
else if ( items["Cache-Control"] !== undefined && regex.number_present.test( items["Cache-Control"] ) ) {
expires = expires.setSeconds( expires.getSeconds() + number.parse( regex.number_present.exec( items["Cache-Control"] )[0], 10 ) );
}
else if ( items.Expires !== undefined ) {
expires = new Date( items.Expires );
}
else {
expires = expires.setSeconds( expires.getSeconds() + $.expires );
}
o.expires = expires;
o.headers = items;
o.permission = client.bit( allow !== null ? string.explode( allow ) : [type] );
if ( type === "get" ) {
cache.set( uri, "expires", o.expires );
cache.set( uri, "headers", o.headers );
cache.set( uri, "permission", o.permission );
}
return o;
} | [
"function",
"(",
"xhr",
",",
"uri",
",",
"type",
")",
"{",
"var",
"headers",
"=",
"string",
".",
"trim",
"(",
"xhr",
".",
"getAllResponseHeaders",
"(",
")",
")",
".",
"split",
"(",
"\"\\n\"",
")",
",",
"\\n",
",",
"items",
"=",
"{",
"}",
",",
"o",
"=",
"{",
"}",
",",
"allow",
"=",
"null",
",",
"expires",
"=",
"new",
"Date",
"(",
")",
";",
"cors",
"=",
"client",
".",
"cors",
"(",
"uri",
")",
"array",
".",
"each",
"(",
"headers",
",",
"function",
"(",
"i",
")",
"{",
"var",
"header",
",",
"value",
";",
"value",
"=",
"i",
".",
"replace",
"(",
"regex",
".",
"header_value_replace",
",",
"\"\"",
")",
";",
"header",
"=",
"i",
".",
"replace",
"(",
"regex",
".",
"header_replace",
",",
"\"\"",
")",
";",
"header",
"=",
"string",
".",
"unhyphenate",
"(",
"header",
",",
"true",
")",
".",
"replace",
"(",
"/",
"\\s+",
"/",
"g",
",",
"\"-\"",
")",
";",
"items",
"[",
"header",
"]",
"=",
"value",
";",
"if",
"(",
"allow",
"===",
"null",
")",
"{",
"if",
"(",
"(",
"!",
"cors",
"&&",
"regex",
".",
"allow",
".",
"test",
"(",
"header",
")",
")",
"||",
"(",
"cors",
"&&",
"regex",
".",
"allow_cors",
".",
"test",
"(",
"header",
")",
")",
")",
"{",
"allow",
"=",
"value",
";",
"}",
"}",
"}",
")",
";",
"if",
"(",
"regex",
".",
"no",
".",
"test",
"(",
"items",
"[",
"\"Cache-Control\"",
"]",
")",
")",
"{",
"}",
"else",
"if",
"(",
"items",
"[",
"\"Cache-Control\"",
"]",
"!==",
"undefined",
"&&",
"regex",
".",
"number_present",
".",
"test",
"(",
"items",
"[",
"\"Cache-Control\"",
"]",
")",
")",
"{",
"expires",
"=",
"expires",
".",
"setSeconds",
"(",
"expires",
".",
"getSeconds",
"(",
")",
"+",
"number",
".",
"parse",
"(",
"regex",
".",
"number_present",
".",
"exec",
"(",
"items",
"[",
"\"Cache-Control\"",
"]",
")",
"[",
"0",
"]",
",",
"10",
")",
")",
";",
"}",
"else",
"if",
"(",
"items",
".",
"Expires",
"!==",
"undefined",
")",
"{",
"expires",
"=",
"new",
"Date",
"(",
"items",
".",
"Expires",
")",
";",
"}",
"else",
"{",
"expires",
"=",
"expires",
".",
"setSeconds",
"(",
"expires",
".",
"getSeconds",
"(",
")",
"+",
"$",
".",
"expires",
")",
";",
"}",
"o",
".",
"expires",
"=",
"expires",
";",
"o",
".",
"headers",
"=",
"items",
";",
"o",
".",
"permission",
"=",
"client",
".",
"bit",
"(",
"allow",
"!==",
"null",
"?",
"string",
".",
"explode",
"(",
"allow",
")",
":",
"[",
"type",
"]",
")",
";",
"if",
"(",
"type",
"===",
"\"get\"",
")",
"{",
"cache",
".",
"set",
"(",
"uri",
",",
"\"expires\"",
",",
"o",
".",
"expires",
")",
";",
"cache",
".",
"set",
"(",
"uri",
",",
"\"headers\"",
",",
"o",
".",
"headers",
")",
";",
"cache",
".",
"set",
"(",
"uri",
",",
"\"permission\"",
",",
"o",
".",
"permission",
")",
";",
"}",
"}"
] | Caches the headers from the XHR response
@method headers
@param {Object} xhr XMLHttpRequest Object
@param {String} uri URI to request
@param {String} type Type of request
@return {Object} Cached URI representation | [
"Caches",
"the",
"headers",
"from",
"the",
"XHR",
"response"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L1899-L1946 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( xhr, type ) {
type = type || "";
var result, obj;
if ( ( regex.json_maybe.test( type ) || string.isEmpty( type ) ) && ( regex.json_wrap.test( xhr.responseText ) && Boolean( obj = json.decode( xhr.responseText, true ) ) ) ) {
result = obj;
}
else if ( regex.xml.test( type ) ) {
if ( type !== "text/xml" ) {
xhr.overrideMimeType( "text/xml" );
}
result = xhr.responseXML;
}
else if ( type === "text/plain" && regex.is_xml.test( xhr.responseText) && xml.valid( xhr.responseText ) ) {
result = xml.decode( xhr.responseText );
}
else {
result = xhr.responseText;
}
return result;
} | javascript | function ( xhr, type ) {
type = type || "";
var result, obj;
if ( ( regex.json_maybe.test( type ) || string.isEmpty( type ) ) && ( regex.json_wrap.test( xhr.responseText ) && Boolean( obj = json.decode( xhr.responseText, true ) ) ) ) {
result = obj;
}
else if ( regex.xml.test( type ) ) {
if ( type !== "text/xml" ) {
xhr.overrideMimeType( "text/xml" );
}
result = xhr.responseXML;
}
else if ( type === "text/plain" && regex.is_xml.test( xhr.responseText) && xml.valid( xhr.responseText ) ) {
result = xml.decode( xhr.responseText );
}
else {
result = xhr.responseText;
}
return result;
} | [
"function",
"(",
"xhr",
",",
"type",
")",
"{",
"type",
"=",
"type",
"||",
"\"\"",
";",
"var",
"result",
",",
"obj",
";",
"if",
"(",
"(",
"regex",
".",
"json_maybe",
".",
"test",
"(",
"type",
")",
"||",
"string",
".",
"isEmpty",
"(",
"type",
")",
")",
"&&",
"(",
"regex",
".",
"json_wrap",
".",
"test",
"(",
"xhr",
".",
"responseText",
")",
"&&",
"Boolean",
"(",
"obj",
"=",
"json",
".",
"decode",
"(",
"xhr",
".",
"responseText",
",",
"true",
")",
")",
")",
")",
"{",
"result",
"=",
"obj",
";",
"}",
"else",
"if",
"(",
"regex",
".",
"xml",
".",
"test",
"(",
"type",
")",
")",
"{",
"if",
"(",
"type",
"!==",
"\"text/xml\"",
")",
"{",
"xhr",
".",
"overrideMimeType",
"(",
"\"text/xml\"",
")",
";",
"}",
"result",
"=",
"xhr",
".",
"responseXML",
";",
"}",
"else",
"if",
"(",
"type",
"===",
"\"text/plain\"",
"&&",
"regex",
".",
"is_xml",
".",
"test",
"(",
"xhr",
".",
"responseText",
")",
"&&",
"xml",
".",
"valid",
"(",
"xhr",
".",
"responseText",
")",
")",
"{",
"result",
"=",
"xml",
".",
"decode",
"(",
"xhr",
".",
"responseText",
")",
";",
"}",
"else",
"{",
"result",
"=",
"xhr",
".",
"responseText",
";",
"}",
"return",
"result",
";",
"}"
] | Parses an XHR response
@method parse
@param {Object} xhr XHR Object
@param {String} type [Optional] Content-Type header value
@return {Mixed} Array, Boolean, Document, Number, Object or String | [
"Parses",
"an",
"XHR",
"response"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L1956-L1978 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( uri ) {
var cached = cache.get( uri, false ),
bit = !cached ? 0 : cached.permission,
result = {allows: [], bit: bit, map: {partial: 8, read: 4, write: 2, "delete": 1, unknown: 0}};
if ( bit & 1) {
result.allows.push( "DELETE" );
}
if ( bit & 2) {
result.allows.push( "POST" );
result.allows.push( "PUT" );
}
if ( bit & 4) {
result.allows.push( "GET" );
}
if ( bit & 8) {
result.allows.push( "PATCH" );
}
return result;
} | javascript | function ( uri ) {
var cached = cache.get( uri, false ),
bit = !cached ? 0 : cached.permission,
result = {allows: [], bit: bit, map: {partial: 8, read: 4, write: 2, "delete": 1, unknown: 0}};
if ( bit & 1) {
result.allows.push( "DELETE" );
}
if ( bit & 2) {
result.allows.push( "POST" );
result.allows.push( "PUT" );
}
if ( bit & 4) {
result.allows.push( "GET" );
}
if ( bit & 8) {
result.allows.push( "PATCH" );
}
return result;
} | [
"function",
"(",
"uri",
")",
"{",
"var",
"cached",
"=",
"cache",
".",
"get",
"(",
"uri",
",",
"false",
")",
",",
"bit",
"=",
"!",
"cached",
"?",
"0",
":",
"cached",
".",
"permission",
",",
"result",
"=",
"{",
"allows",
":",
"[",
"]",
",",
"bit",
":",
"bit",
",",
"map",
":",
"{",
"partial",
":",
"8",
",",
"read",
":",
"4",
",",
"write",
":",
"2",
",",
"\"delete\"",
":",
"1",
",",
"unknown",
":",
"0",
"}",
"}",
";",
"if",
"(",
"bit",
"&",
"1",
")",
"{",
"result",
".",
"allows",
".",
"push",
"(",
"\"DELETE\"",
")",
";",
"}",
"if",
"(",
"bit",
"&",
"2",
")",
"{",
"result",
".",
"allows",
".",
"push",
"(",
"\"POST\"",
")",
";",
"result",
".",
"allows",
".",
"push",
"(",
"\"PUT\"",
")",
";",
"}",
"if",
"(",
"bit",
"&",
"4",
")",
"{",
"result",
".",
"allows",
".",
"push",
"(",
"\"GET\"",
")",
";",
"}",
"if",
"(",
"bit",
"&",
"8",
")",
"{",
"result",
".",
"allows",
".",
"push",
"(",
"\"PATCH\"",
")",
";",
"}",
"return",
"result",
";",
"}"
] | Returns the permission of the cached URI
@method permissions
@param {String} uri URI to query
@return {Object} Contains an Array of available commands, the permission bit and a map | [
"Returns",
"the",
"permission",
"of",
"the",
"cached",
"URI"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L1987-L2010 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( uri, success, failure, args ) {
var defer = deferred(),
callback = "callback", cbid, s;
if ( external === undefined ) {
if ( global.abaaso === undefined ) {
utility.define( "abaaso.callback", {}, global );
}
external = "abaaso";
}
if ( args instanceof Object && args.callback !== undefined ) {
callback = args.callback;
}
defer.then( function (arg ) {
if ( typeof success === "function") {
success( arg );
}
}, function ( e ) {
if ( typeof failure === "function") {
failure( e );
}
throw e;
});
do {
cbid = utility.genId().slice( 0, 10 );
}
while ( global.abaaso.callback[cbid] !== undefined );
uri = uri.replace( callback + "=?", callback + "=" + external + ".callback." + cbid );
global.abaaso.callback[cbid] = function ( arg ) {
clearTimeout( utility.timer[cbid] );
delete utility.timer[cbid];
delete global.abaaso.callback[cbid];
defer.resolve( arg );
element.destroy( s );
};
s = element.create( "script", {src: uri, type: "text/javascript"}, utility.$( "head" )[0] );
utility.defer( function () {
defer.reject( undefined );
}, 30000, cbid );
return defer;
} | javascript | function ( uri, success, failure, args ) {
var defer = deferred(),
callback = "callback", cbid, s;
if ( external === undefined ) {
if ( global.abaaso === undefined ) {
utility.define( "abaaso.callback", {}, global );
}
external = "abaaso";
}
if ( args instanceof Object && args.callback !== undefined ) {
callback = args.callback;
}
defer.then( function (arg ) {
if ( typeof success === "function") {
success( arg );
}
}, function ( e ) {
if ( typeof failure === "function") {
failure( e );
}
throw e;
});
do {
cbid = utility.genId().slice( 0, 10 );
}
while ( global.abaaso.callback[cbid] !== undefined );
uri = uri.replace( callback + "=?", callback + "=" + external + ".callback." + cbid );
global.abaaso.callback[cbid] = function ( arg ) {
clearTimeout( utility.timer[cbid] );
delete utility.timer[cbid];
delete global.abaaso.callback[cbid];
defer.resolve( arg );
element.destroy( s );
};
s = element.create( "script", {src: uri, type: "text/javascript"}, utility.$( "head" )[0] );
utility.defer( function () {
defer.reject( undefined );
}, 30000, cbid );
return defer;
} | [
"function",
"(",
"uri",
",",
"success",
",",
"failure",
",",
"args",
")",
"{",
"var",
"defer",
"=",
"deferred",
"(",
")",
",",
"callback",
"=",
"\"callback\"",
",",
"cbid",
",",
"s",
";",
"if",
"(",
"external",
"===",
"undefined",
")",
"{",
"if",
"(",
"global",
".",
"abaaso",
"===",
"undefined",
")",
"{",
"utility",
".",
"define",
"(",
"\"abaaso.callback\"",
",",
"{",
"}",
",",
"global",
")",
";",
"}",
"external",
"=",
"\"abaaso\"",
";",
"}",
"if",
"(",
"args",
"instanceof",
"Object",
"&&",
"args",
".",
"callback",
"!==",
"undefined",
")",
"{",
"callback",
"=",
"args",
".",
"callback",
";",
"}",
"defer",
".",
"then",
"(",
"function",
"(",
"arg",
")",
"{",
"if",
"(",
"typeof",
"success",
"===",
"\"function\"",
")",
"{",
"success",
"(",
"arg",
")",
";",
"}",
"}",
",",
"function",
"(",
"e",
")",
"{",
"if",
"(",
"typeof",
"failure",
"===",
"\"function\"",
")",
"{",
"failure",
"(",
"e",
")",
";",
"}",
"throw",
"e",
";",
"}",
")",
";",
"do",
"{",
"cbid",
"=",
"utility",
".",
"genId",
"(",
")",
".",
"slice",
"(",
"0",
",",
"10",
")",
";",
"}",
"while",
"(",
"global",
".",
"abaaso",
".",
"callback",
"[",
"cbid",
"]",
"!==",
"undefined",
")",
";",
"uri",
"=",
"uri",
".",
"replace",
"(",
"callback",
"+",
"\"=?\"",
",",
"callback",
"+",
"\"=\"",
"+",
"external",
"+",
"\".callback.\"",
"+",
"cbid",
")",
";",
"global",
".",
"abaaso",
".",
"callback",
"[",
"cbid",
"]",
"=",
"function",
"(",
"arg",
")",
"{",
"clearTimeout",
"(",
"utility",
".",
"timer",
"[",
"cbid",
"]",
")",
";",
"delete",
"utility",
".",
"timer",
"[",
"cbid",
"]",
";",
"delete",
"global",
".",
"abaaso",
".",
"callback",
"[",
"cbid",
"]",
";",
"defer",
".",
"resolve",
"(",
"arg",
")",
";",
"element",
".",
"destroy",
"(",
"s",
")",
";",
"}",
";",
"s",
"=",
"element",
".",
"create",
"(",
"\"script\"",
",",
"{",
"src",
":",
"uri",
",",
"type",
":",
"\"text/javascript\"",
"}",
",",
"utility",
".",
"$",
"(",
"\"head\"",
")",
"[",
"0",
"]",
")",
";",
"utility",
".",
"defer",
"(",
"function",
"(",
")",
"{",
"defer",
".",
"reject",
"(",
"undefined",
")",
";",
"}",
",",
"30000",
",",
"cbid",
")",
";",
"return",
"defer",
";",
"}"
] | Creates a JSONP request
@method jsonp
@param {String} uri URI to request
@param {Function} success A handler function to execute when an appropriate response been received
@param {Function} failure [Optional] A handler function to execute on error
@param {Mixed} args Custom JSONP handler parameter name, default is "callback"; or custom headers for GET request ( CORS )
@return {Object} Deferred | [
"Creates",
"a",
"JSONP",
"request"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L2022-L2072 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( arg, target, pos ) {
return element.create( "script", {type: "application/javascript", src: arg}, target || utility.$( "head" )[0], pos );
} | javascript | function ( arg, target, pos ) {
return element.create( "script", {type: "application/javascript", src: arg}, target || utility.$( "head" )[0], pos );
} | [
"function",
"(",
"arg",
",",
"target",
",",
"pos",
")",
"{",
"return",
"element",
".",
"create",
"(",
"\"script\"",
",",
"{",
"type",
":",
"\"application/javascript\"",
",",
"src",
":",
"arg",
"}",
",",
"target",
"||",
"utility",
".",
"$",
"(",
"\"head\"",
")",
"[",
"0",
"]",
",",
"pos",
")",
";",
"}"
] | Creates a script Element to load an external script
@method script
@param {String} arg URL to script
@param {Object} target [Optional] Element to receive the script
@param {String} pos [Optional] Position to create the script at within the target
@return {Object} Script | [
"Creates",
"a",
"script",
"Element",
"to",
"load",
"an",
"external",
"script"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L2431-L2433 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( dest, ms ) {
var defer = deferred(),
start = client.scrollPos(),
t = 0;
ms = ( !isNaN( ms ) ? ms : 250 ) / 100;
utility.repeat( function () {
var pos = math.bezier( start[0], start[1], dest[0], dest[1], ++t / 100 );
window.scrollTo( pos[0], pos[1] );
if ( t === 100 ) {
defer.resolve( true );
return false;
}
}, ms, "scrolling" );
return defer;
} | javascript | function ( dest, ms ) {
var defer = deferred(),
start = client.scrollPos(),
t = 0;
ms = ( !isNaN( ms ) ? ms : 250 ) / 100;
utility.repeat( function () {
var pos = math.bezier( start[0], start[1], dest[0], dest[1], ++t / 100 );
window.scrollTo( pos[0], pos[1] );
if ( t === 100 ) {
defer.resolve( true );
return false;
}
}, ms, "scrolling" );
return defer;
} | [
"function",
"(",
"dest",
",",
"ms",
")",
"{",
"var",
"defer",
"=",
"deferred",
"(",
")",
",",
"start",
"=",
"client",
".",
"scrollPos",
"(",
")",
",",
"t",
"=",
"0",
";",
"ms",
"=",
"(",
"!",
"isNaN",
"(",
"ms",
")",
"?",
"ms",
":",
"250",
")",
"/",
"100",
";",
"utility",
".",
"repeat",
"(",
"function",
"(",
")",
"{",
"var",
"pos",
"=",
"math",
".",
"bezier",
"(",
"start",
"[",
"0",
"]",
",",
"start",
"[",
"1",
"]",
",",
"dest",
"[",
"0",
"]",
",",
"dest",
"[",
"1",
"]",
",",
"++",
"t",
"/",
"100",
")",
";",
"window",
".",
"scrollTo",
"(",
"pos",
"[",
"0",
"]",
",",
"pos",
"[",
"1",
"]",
")",
";",
"if",
"(",
"t",
"===",
"100",
")",
"{",
"defer",
".",
"resolve",
"(",
"true",
")",
";",
"return",
"false",
";",
"}",
"}",
",",
"ms",
",",
"\"scrolling\"",
")",
";",
"return",
"defer",
";",
"}"
] | Scrolls to a position in the view using a two point bezier curve
@method scroll
@param {Array} dest Coordinates
@param {Number} ms [Optional] Milliseconds to scroll, default is 250, min is 100
@return {Object} Deferred | [
"Scrolls",
"to",
"a",
"position",
"in",
"the",
"view",
"using",
"a",
"two",
"point",
"bezier",
"curve"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L2443-L2462 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( arg, media ) {
return element.create( "link", {rel: "stylesheet", type: "text/css", href: arg, media: media || "print, screen"}, utility.$( "head" )[0] );
} | javascript | function ( arg, media ) {
return element.create( "link", {rel: "stylesheet", type: "text/css", href: arg, media: media || "print, screen"}, utility.$( "head" )[0] );
} | [
"function",
"(",
"arg",
",",
"media",
")",
"{",
"return",
"element",
".",
"create",
"(",
"\"link\"",
",",
"{",
"rel",
":",
"\"stylesheet\"",
",",
"type",
":",
"\"text/css\"",
",",
"href",
":",
"arg",
",",
"media",
":",
"media",
"||",
"\"print, screen\"",
"}",
",",
"utility",
".",
"$",
"(",
"\"head\"",
")",
"[",
"0",
"]",
")",
";",
"}"
] | Creates a link Element to load an external stylesheet
@method stylesheet
@param {String} arg URL to stylesheet
@param {String} media [Optional] Medias the stylesheet applies to
@return {Objecct} Stylesheet | [
"Creates",
"a",
"link",
"Element",
"to",
"load",
"an",
"external",
"stylesheet"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L2498-L2500 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( name, domain, secure, path, jar ) {
cookie.set( name, "", "-1s", domain, secure, path, jar );
return name;
} | javascript | function ( name, domain, secure, path, jar ) {
cookie.set( name, "", "-1s", domain, secure, path, jar );
return name;
} | [
"function",
"(",
"name",
",",
"domain",
",",
"secure",
",",
"path",
",",
"jar",
")",
"{",
"cookie",
".",
"set",
"(",
"name",
",",
"\"\"",
",",
"\"-1s\"",
",",
"domain",
",",
"secure",
",",
"path",
",",
"jar",
")",
";",
"return",
"name",
";",
"}"
] | Expires a cookie if it exists
@method expire
@param {String} name Name of the cookie to expire
@param {String} domain [Optional] Domain to set the cookie for
@param {Boolean} secure [Optional] Make the cookie only accessible via SSL
@param {String} path [Optional] Path the cookie is for
@param {String} jar [Optional] Cookie jar, defaults to document.cookie
@return {String} Name of the expired cookie | [
"Expires",
"a",
"cookie",
"if",
"it",
"exists"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L2516-L2520 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( jar ) {
var result = {};
if ( jar === undefined ) {
jar = server ? "" : document.cookie;
}
if ( !string.isEmpty( jar ) ) {
array.each( string.explode( jar, ";" ), function ( i ) {
var item = string.explode( i, "=" );
result[item[0]] = utility.coerce( item[1] );
} );
}
return result;
} | javascript | function ( jar ) {
var result = {};
if ( jar === undefined ) {
jar = server ? "" : document.cookie;
}
if ( !string.isEmpty( jar ) ) {
array.each( string.explode( jar, ";" ), function ( i ) {
var item = string.explode( i, "=" );
result[item[0]] = utility.coerce( item[1] );
} );
}
return result;
} | [
"function",
"(",
"jar",
")",
"{",
"var",
"result",
"=",
"{",
"}",
";",
"if",
"(",
"jar",
"===",
"undefined",
")",
"{",
"jar",
"=",
"server",
"?",
"\"\"",
":",
"document",
".",
"cookie",
";",
"}",
"if",
"(",
"!",
"string",
".",
"isEmpty",
"(",
"jar",
")",
")",
"{",
"array",
".",
"each",
"(",
"string",
".",
"explode",
"(",
"jar",
",",
"\";\"",
")",
",",
"function",
"(",
"i",
")",
"{",
"var",
"item",
"=",
"string",
".",
"explode",
"(",
"i",
",",
"\"=\"",
")",
";",
"result",
"[",
"item",
"[",
"0",
"]",
"]",
"=",
"utility",
".",
"coerce",
"(",
"item",
"[",
"1",
"]",
")",
";",
"}",
")",
";",
"}",
"return",
"result",
";",
"}"
] | Gets the cookies for the domain
@method list
@param {String} jar [Optional] Cookie jar, defaults to document.cookie
@return {Object} Collection of cookies | [
"Gets",
"the",
"cookies",
"for",
"the",
"domain"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L2541-L2557 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( name, value, offset, domain, secure, path, jar ) {
value = ( value || "" ) + ";";
offset = offset || "";
domain = typeof domain === "string" ? ( " Domain=" + domain + ";" ) : "";
secure = ( secure === true ) ? " secure" : "";
path = typeof path === "string" ? ( " Path=" + path + ";" ) : "";
var expire = "",
span = null,
type = null,
types = ["d", "h", "m", "s"],
regex = new RegExp(),
i = types.length,
cookies;
if ( !string.isEmpty( offset ) ) {
while ( i-- ) {
utility.compile( regex, types[i] );
if ( regex.test( offset ) ) {
type = types[i];
span = number.parse( offset, 10 );
break;
}
}
if ( isNaN( span ) ) {
throw new Error( label.error.invalidArguments );
}
expire = new Date();
if ( type === "d" ) {
expire.setDate( expire.getDate() + span );
}
else if ( type === "h" ) {
expire.setHours( expire.getHours() + span );
}
else if ( type === "m" ) {
expire.setMinutes( expire.getMinutes() + span );
}
else if ( type === "s" ) {
expire.setSeconds( expire.getSeconds() + span );
}
}
if ( expire instanceof Date) {
expire = " Expires=" + expire.toUTCString() + ";";
}
if ( !server ) {
document.cookie = ( string.trim( name.toString() ) + "=" + value + expire + domain + path + secure );
}
else {
cookies = jar.getHeader( "Set-Cookie" ) || [];
cookies.push( ( string.trim( name.toString() ) + "=" + value + expire + domain + path + secure ).replace( /;$/, "" ) );
jar.setHeader( "Set-Cookie", cookies );
}
} | javascript | function ( name, value, offset, domain, secure, path, jar ) {
value = ( value || "" ) + ";";
offset = offset || "";
domain = typeof domain === "string" ? ( " Domain=" + domain + ";" ) : "";
secure = ( secure === true ) ? " secure" : "";
path = typeof path === "string" ? ( " Path=" + path + ";" ) : "";
var expire = "",
span = null,
type = null,
types = ["d", "h", "m", "s"],
regex = new RegExp(),
i = types.length,
cookies;
if ( !string.isEmpty( offset ) ) {
while ( i-- ) {
utility.compile( regex, types[i] );
if ( regex.test( offset ) ) {
type = types[i];
span = number.parse( offset, 10 );
break;
}
}
if ( isNaN( span ) ) {
throw new Error( label.error.invalidArguments );
}
expire = new Date();
if ( type === "d" ) {
expire.setDate( expire.getDate() + span );
}
else if ( type === "h" ) {
expire.setHours( expire.getHours() + span );
}
else if ( type === "m" ) {
expire.setMinutes( expire.getMinutes() + span );
}
else if ( type === "s" ) {
expire.setSeconds( expire.getSeconds() + span );
}
}
if ( expire instanceof Date) {
expire = " Expires=" + expire.toUTCString() + ";";
}
if ( !server ) {
document.cookie = ( string.trim( name.toString() ) + "=" + value + expire + domain + path + secure );
}
else {
cookies = jar.getHeader( "Set-Cookie" ) || [];
cookies.push( ( string.trim( name.toString() ) + "=" + value + expire + domain + path + secure ).replace( /;$/, "" ) );
jar.setHeader( "Set-Cookie", cookies );
}
} | [
"function",
"(",
"name",
",",
"value",
",",
"offset",
",",
"domain",
",",
"secure",
",",
"path",
",",
"jar",
")",
"{",
"value",
"=",
"(",
"value",
"||",
"\"\"",
")",
"+",
"\";\"",
";",
"offset",
"=",
"offset",
"||",
"\"\"",
";",
"domain",
"=",
"typeof",
"domain",
"===",
"\"string\"",
"?",
"(",
"\" Domain=\"",
"+",
"domain",
"+",
"\";\"",
")",
":",
"\"\"",
";",
"secure",
"=",
"(",
"secure",
"===",
"true",
")",
"?",
"\" secure\"",
":",
"\"\"",
";",
"path",
"=",
"typeof",
"path",
"===",
"\"string\"",
"?",
"(",
"\" Path=\"",
"+",
"path",
"+",
"\";\"",
")",
":",
"\"\"",
";",
"var",
"expire",
"=",
"\"\"",
",",
"span",
"=",
"null",
",",
"type",
"=",
"null",
",",
"types",
"=",
"[",
"\"d\"",
",",
"\"h\"",
",",
"\"m\"",
",",
"\"s\"",
"]",
",",
"regex",
"=",
"new",
"RegExp",
"(",
")",
",",
"i",
"=",
"types",
".",
"length",
",",
"cookies",
";",
"if",
"(",
"!",
"string",
".",
"isEmpty",
"(",
"offset",
")",
")",
"{",
"while",
"(",
"i",
"--",
")",
"{",
"utility",
".",
"compile",
"(",
"regex",
",",
"types",
"[",
"i",
"]",
")",
";",
"if",
"(",
"regex",
".",
"test",
"(",
"offset",
")",
")",
"{",
"type",
"=",
"types",
"[",
"i",
"]",
";",
"span",
"=",
"number",
".",
"parse",
"(",
"offset",
",",
"10",
")",
";",
"break",
";",
"}",
"}",
"if",
"(",
"isNaN",
"(",
"span",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"label",
".",
"error",
".",
"invalidArguments",
")",
";",
"}",
"expire",
"=",
"new",
"Date",
"(",
")",
";",
"if",
"(",
"type",
"===",
"\"d\"",
")",
"{",
"expire",
".",
"setDate",
"(",
"expire",
".",
"getDate",
"(",
")",
"+",
"span",
")",
";",
"}",
"else",
"if",
"(",
"type",
"===",
"\"h\"",
")",
"{",
"expire",
".",
"setHours",
"(",
"expire",
".",
"getHours",
"(",
")",
"+",
"span",
")",
";",
"}",
"else",
"if",
"(",
"type",
"===",
"\"m\"",
")",
"{",
"expire",
".",
"setMinutes",
"(",
"expire",
".",
"getMinutes",
"(",
")",
"+",
"span",
")",
";",
"}",
"else",
"if",
"(",
"type",
"===",
"\"s\"",
")",
"{",
"expire",
".",
"setSeconds",
"(",
"expire",
".",
"getSeconds",
"(",
")",
"+",
"span",
")",
";",
"}",
"}",
"if",
"(",
"expire",
"instanceof",
"Date",
")",
"{",
"expire",
"=",
"\" Expires=\"",
"+",
"expire",
".",
"toUTCString",
"(",
")",
"+",
"\";\"",
";",
"}",
"if",
"(",
"!",
"server",
")",
"{",
"document",
".",
"cookie",
"=",
"(",
"string",
".",
"trim",
"(",
"name",
".",
"toString",
"(",
")",
")",
"+",
"\"=\"",
"+",
"value",
"+",
"expire",
"+",
"domain",
"+",
"path",
"+",
"secure",
")",
";",
"}",
"else",
"{",
"cookies",
"=",
"jar",
".",
"getHeader",
"(",
"\"Set-Cookie\"",
")",
"||",
"[",
"]",
";",
"cookies",
".",
"push",
"(",
"(",
"string",
".",
"trim",
"(",
"name",
".",
"toString",
"(",
")",
")",
"+",
"\"=\"",
"+",
"value",
"+",
"expire",
"+",
"domain",
"+",
"path",
"+",
"secure",
")",
".",
"replace",
"(",
"/",
";$",
"/",
",",
"\"\"",
")",
")",
";",
"jar",
".",
"setHeader",
"(",
"\"Set-Cookie\"",
",",
"cookies",
")",
";",
"}",
"}"
] | Creates a cookie
The offset specifies a positive or negative span of time as day, hour, minute or second
@method set
@param {String} name Name of the cookie to create
@param {String} value Value to set
@param {String} offset A positive or negative integer followed by "d", "h", "m" or "s"
@param {String} domain [Optional] Domain to set the cookie for
@param {Boolean} secure [Optional] Make the cookie only accessible via SSL
@param {String} path [Optional] Path the cookie is for
@param {String} jar [Optional] Cookie jar, defaults to document.cookie
@return {Undefined} undefined | [
"Creates",
"a",
"cookie"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L2574-L2631 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj, recs, args ) {
utility.genId( obj );
// Decorating observer if not present in prototype chain
if ( typeof obj.fire !== "function" ) {
observer.decorate( obj );
}
// Creating store
obj.data = new DataStore( obj );
if ( args instanceof Object ) {
utility.merge( obj.data, args );
}
if ( recs !== null && typeof recs === "object" ) {
obj.data.batch( "set", recs );
}
return obj;
} | javascript | function ( obj, recs, args ) {
utility.genId( obj );
// Decorating observer if not present in prototype chain
if ( typeof obj.fire !== "function" ) {
observer.decorate( obj );
}
// Creating store
obj.data = new DataStore( obj );
if ( args instanceof Object ) {
utility.merge( obj.data, args );
}
if ( recs !== null && typeof recs === "object" ) {
obj.data.batch( "set", recs );
}
return obj;
} | [
"function",
"(",
"obj",
",",
"recs",
",",
"args",
")",
"{",
"utility",
".",
"genId",
"(",
"obj",
")",
";",
"if",
"(",
"typeof",
"obj",
".",
"fire",
"!==",
"\"function\"",
")",
"{",
"observer",
".",
"decorate",
"(",
"obj",
")",
";",
"}",
"obj",
".",
"data",
"=",
"new",
"DataStore",
"(",
"obj",
")",
";",
"if",
"(",
"args",
"instanceof",
"Object",
")",
"{",
"utility",
".",
"merge",
"(",
"obj",
".",
"data",
",",
"args",
")",
";",
"}",
"if",
"(",
"recs",
"!==",
"null",
"&&",
"typeof",
"recs",
"===",
"\"object\"",
")",
"{",
"obj",
".",
"data",
".",
"batch",
"(",
"\"set\"",
",",
"recs",
")",
";",
"}",
"return",
"obj",
";",
"}"
] | Decorates a DataStore on an Object
@method decorator
@param {Object} obj Object
@param {Mixed} recs [Optional] Data to set with this.batch
@param {Object} args [Optional] Arguments to set on the store
@return {Object} Decorated Object | [
"Decorates",
"a",
"DataStore",
"on",
"an",
"Object"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L2643-L2663 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj, key, value ) {
var target, result;
if ( regex.svg.test( obj.namespaceURI ) ) {
if ( value === undefined ) {
result = obj.getAttributeNS( obj.namespaceURI, key );
if ( result === null || string.isEmpty( result ) ) {
result = undefined;
}
else {
result = utility.coerce( result );
}
}
else {
obj.setAttributeNS( obj.namespaceURI, key, value );
}
}
else {
if ( typeof value === "string" ) {
value = string.trim( value );
}
if ( regex.checked_disabled.test( key ) && value === undefined ) {
return utility.coerce( obj[key] );
}
else if ( regex.checked_disabled.test( key ) && value !== undefined ) {
obj[key] = value;
}
else if ( obj.nodeName === "SELECT" && key === "selected" && value === undefined) {
return utility.$( "#" + obj.id + " option[selected=\"selected\"]" )[0] || utility.$( "#" + obj.id + " option" )[0];
}
else if ( obj.nodeName === "SELECT" && key === "selected" && value !== undefined ) {
target = utility.$( "#" + obj.id + " option[selected=\"selected\"]" )[0];
if ( target !== undefined ) {
target.selected = false;
target.removeAttribute( "selected" );
}
target = utility.$( "#" + obj.id + " option[value=\"" + value + "\"]" )[0];
target.selected = true;
target.setAttribute( "selected", "selected" );
}
else if ( value === undefined ) {
result = obj.getAttribute( key );
if ( result === null || string.isEmpty( result ) ) {
result = undefined;
}
else {
result = utility.coerce( result );
}
return result;
}
else {
obj.setAttribute( key, value );
}
}
return obj;
} | javascript | function ( obj, key, value ) {
var target, result;
if ( regex.svg.test( obj.namespaceURI ) ) {
if ( value === undefined ) {
result = obj.getAttributeNS( obj.namespaceURI, key );
if ( result === null || string.isEmpty( result ) ) {
result = undefined;
}
else {
result = utility.coerce( result );
}
}
else {
obj.setAttributeNS( obj.namespaceURI, key, value );
}
}
else {
if ( typeof value === "string" ) {
value = string.trim( value );
}
if ( regex.checked_disabled.test( key ) && value === undefined ) {
return utility.coerce( obj[key] );
}
else if ( regex.checked_disabled.test( key ) && value !== undefined ) {
obj[key] = value;
}
else if ( obj.nodeName === "SELECT" && key === "selected" && value === undefined) {
return utility.$( "#" + obj.id + " option[selected=\"selected\"]" )[0] || utility.$( "#" + obj.id + " option" )[0];
}
else if ( obj.nodeName === "SELECT" && key === "selected" && value !== undefined ) {
target = utility.$( "#" + obj.id + " option[selected=\"selected\"]" )[0];
if ( target !== undefined ) {
target.selected = false;
target.removeAttribute( "selected" );
}
target = utility.$( "#" + obj.id + " option[value=\"" + value + "\"]" )[0];
target.selected = true;
target.setAttribute( "selected", "selected" );
}
else if ( value === undefined ) {
result = obj.getAttribute( key );
if ( result === null || string.isEmpty( result ) ) {
result = undefined;
}
else {
result = utility.coerce( result );
}
return result;
}
else {
obj.setAttribute( key, value );
}
}
return obj;
} | [
"function",
"(",
"obj",
",",
"key",
",",
"value",
")",
"{",
"var",
"target",
",",
"result",
";",
"if",
"(",
"regex",
".",
"svg",
".",
"test",
"(",
"obj",
".",
"namespaceURI",
")",
")",
"{",
"if",
"(",
"value",
"===",
"undefined",
")",
"{",
"result",
"=",
"obj",
".",
"getAttributeNS",
"(",
"obj",
".",
"namespaceURI",
",",
"key",
")",
";",
"if",
"(",
"result",
"===",
"null",
"||",
"string",
".",
"isEmpty",
"(",
"result",
")",
")",
"{",
"result",
"=",
"undefined",
";",
"}",
"else",
"{",
"result",
"=",
"utility",
".",
"coerce",
"(",
"result",
")",
";",
"}",
"}",
"else",
"{",
"obj",
".",
"setAttributeNS",
"(",
"obj",
".",
"namespaceURI",
",",
"key",
",",
"value",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"typeof",
"value",
"===",
"\"string\"",
")",
"{",
"value",
"=",
"string",
".",
"trim",
"(",
"value",
")",
";",
"}",
"if",
"(",
"regex",
".",
"checked_disabled",
".",
"test",
"(",
"key",
")",
"&&",
"value",
"===",
"undefined",
")",
"{",
"return",
"utility",
".",
"coerce",
"(",
"obj",
"[",
"key",
"]",
")",
";",
"}",
"else",
"if",
"(",
"regex",
".",
"checked_disabled",
".",
"test",
"(",
"key",
")",
"&&",
"value",
"!==",
"undefined",
")",
"{",
"obj",
"[",
"key",
"]",
"=",
"value",
";",
"}",
"else",
"if",
"(",
"obj",
".",
"nodeName",
"===",
"\"SELECT\"",
"&&",
"key",
"===",
"\"selected\"",
"&&",
"value",
"===",
"undefined",
")",
"{",
"return",
"utility",
".",
"$",
"(",
"\"#\"",
"+",
"obj",
".",
"id",
"+",
"\" option[selected=\\\"selected\\\"]\"",
")",
"[",
"\\\"",
"]",
"||",
"\\\"",
";",
"}",
"else",
"0",
"}",
"utility",
".",
"$",
"(",
"\"#\"",
"+",
"obj",
".",
"id",
"+",
"\" option\"",
")",
"[",
"0",
"]",
"}"
] | Gets or sets an Element attribute
@method attr
@param {Mixed} obj Element
@param {String} name Attribute name
@param {Mixed} value Attribute value
@return {Object} Element | [
"Gets",
"or",
"sets",
"an",
"Element",
"attribute"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L4926-L4988 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj ) {
if ( typeof obj.reset === "function" ) {
obj.reset();
}
else if ( obj.value !== undefined ) {
element.update( obj, {innerHTML: "", value: ""} );
}
else {
element.update( obj, {innerHTML: ""} );
}
return obj;
} | javascript | function ( obj ) {
if ( typeof obj.reset === "function" ) {
obj.reset();
}
else if ( obj.value !== undefined ) {
element.update( obj, {innerHTML: "", value: ""} );
}
else {
element.update( obj, {innerHTML: ""} );
}
return obj;
} | [
"function",
"(",
"obj",
")",
"{",
"if",
"(",
"typeof",
"obj",
".",
"reset",
"===",
"\"function\"",
")",
"{",
"obj",
".",
"reset",
"(",
")",
";",
"}",
"else",
"if",
"(",
"obj",
".",
"value",
"!==",
"undefined",
")",
"{",
"element",
".",
"update",
"(",
"obj",
",",
"{",
"innerHTML",
":",
"\"\"",
",",
"value",
":",
"\"\"",
"}",
")",
";",
"}",
"else",
"{",
"element",
".",
"update",
"(",
"obj",
",",
"{",
"innerHTML",
":",
"\"\"",
"}",
")",
";",
"}",
"return",
"obj",
";",
"}"
] | Clears an object's innerHTML, or resets it's state
@method clear
@param {Mixed} obj Element
@return {Object} Element | [
"Clears",
"an",
"object",
"s",
"innerHTML",
"or",
"resets",
"it",
"s",
"state"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L4997-L5009 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( type, args, target, pos ) {
var svg = false,
frag = false,
obj, uid, result;
// Removing potential HTML template formatting
type = type.replace( /\t|\n|\r/g, "" );
if ( target !== undefined ) {
svg = ( target.namespaceURI !== undefined && regex.svg.test( target.namespaceURI ) );
}
else {
target = document.body;
}
if ( args instanceof Object && args.id !== undefined && utility.$( "#" + args.id ) === undefined ) {
uid = args.id;
delete args.id;
}
else if ( !svg ) {
uid = utility.genId( undefined, true );
}
// String injection, create a frag and apply it
if ( regex.html.test( type ) ) {
frag = true;
obj = element.frag( type );
result = obj.childNodes.length === 1 ? obj.childNodes[0] : array.cast( obj.childNodes );
}
// Original syntax
else {
if ( !svg && !regex.svg.test( type ) ) {
obj = document.createElement( type );
}
else {
obj = document.createElementNS( "http://www.w3.org/2000/svg", type );
}
if ( uid !== undefined ) {
obj.id = uid;
}
if ( args instanceof Object ) {
element.update( obj, args );
}
}
if ( pos === undefined || pos === "last" ) {
target.appendChild( obj );
}
else if ( pos === "first" ) {
element.prependChild( target, obj );
}
else if ( pos === "after" ) {
pos = {};
pos.after = target;
target = target.parentNode;
target.insertBefore( obj, pos.after.nextSibling );
}
else if ( pos.after !== undefined ) {
target.insertBefore( obj, pos.after.nextSibling );
}
else if ( pos === "before" ) {
pos = {};
pos.before = target;
target = target.parentNode;
target.insertBefore( obj, pos.before );
}
else if ( pos.before !== undefined ) {
target.insertBefore( obj, pos.before );
}
else {
target.appendChild( obj );
}
return !frag ? obj : result;
} | javascript | function ( type, args, target, pos ) {
var svg = false,
frag = false,
obj, uid, result;
// Removing potential HTML template formatting
type = type.replace( /\t|\n|\r/g, "" );
if ( target !== undefined ) {
svg = ( target.namespaceURI !== undefined && regex.svg.test( target.namespaceURI ) );
}
else {
target = document.body;
}
if ( args instanceof Object && args.id !== undefined && utility.$( "#" + args.id ) === undefined ) {
uid = args.id;
delete args.id;
}
else if ( !svg ) {
uid = utility.genId( undefined, true );
}
// String injection, create a frag and apply it
if ( regex.html.test( type ) ) {
frag = true;
obj = element.frag( type );
result = obj.childNodes.length === 1 ? obj.childNodes[0] : array.cast( obj.childNodes );
}
// Original syntax
else {
if ( !svg && !regex.svg.test( type ) ) {
obj = document.createElement( type );
}
else {
obj = document.createElementNS( "http://www.w3.org/2000/svg", type );
}
if ( uid !== undefined ) {
obj.id = uid;
}
if ( args instanceof Object ) {
element.update( obj, args );
}
}
if ( pos === undefined || pos === "last" ) {
target.appendChild( obj );
}
else if ( pos === "first" ) {
element.prependChild( target, obj );
}
else if ( pos === "after" ) {
pos = {};
pos.after = target;
target = target.parentNode;
target.insertBefore( obj, pos.after.nextSibling );
}
else if ( pos.after !== undefined ) {
target.insertBefore( obj, pos.after.nextSibling );
}
else if ( pos === "before" ) {
pos = {};
pos.before = target;
target = target.parentNode;
target.insertBefore( obj, pos.before );
}
else if ( pos.before !== undefined ) {
target.insertBefore( obj, pos.before );
}
else {
target.appendChild( obj );
}
return !frag ? obj : result;
} | [
"function",
"(",
"type",
",",
"args",
",",
"target",
",",
"pos",
")",
"{",
"var",
"svg",
"=",
"false",
",",
"frag",
"=",
"false",
",",
"obj",
",",
"uid",
",",
"result",
";",
"type",
"=",
"type",
".",
"replace",
"(",
"/",
"\\t|\\n|\\r",
"/",
"g",
",",
"\"\"",
")",
";",
"if",
"(",
"target",
"!==",
"undefined",
")",
"{",
"svg",
"=",
"(",
"target",
".",
"namespaceURI",
"!==",
"undefined",
"&&",
"regex",
".",
"svg",
".",
"test",
"(",
"target",
".",
"namespaceURI",
")",
")",
";",
"}",
"else",
"{",
"target",
"=",
"document",
".",
"body",
";",
"}",
"if",
"(",
"args",
"instanceof",
"Object",
"&&",
"args",
".",
"id",
"!==",
"undefined",
"&&",
"utility",
".",
"$",
"(",
"\"#\"",
"+",
"args",
".",
"id",
")",
"===",
"undefined",
")",
"{",
"uid",
"=",
"args",
".",
"id",
";",
"delete",
"args",
".",
"id",
";",
"}",
"else",
"if",
"(",
"!",
"svg",
")",
"{",
"uid",
"=",
"utility",
".",
"genId",
"(",
"undefined",
",",
"true",
")",
";",
"}",
"if",
"(",
"regex",
".",
"html",
".",
"test",
"(",
"type",
")",
")",
"{",
"frag",
"=",
"true",
";",
"obj",
"=",
"element",
".",
"frag",
"(",
"type",
")",
";",
"result",
"=",
"obj",
".",
"childNodes",
".",
"length",
"===",
"1",
"?",
"obj",
".",
"childNodes",
"[",
"0",
"]",
":",
"array",
".",
"cast",
"(",
"obj",
".",
"childNodes",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"svg",
"&&",
"!",
"regex",
".",
"svg",
".",
"test",
"(",
"type",
")",
")",
"{",
"obj",
"=",
"document",
".",
"createElement",
"(",
"type",
")",
";",
"}",
"else",
"{",
"obj",
"=",
"document",
".",
"createElementNS",
"(",
"\"http://www.w3.org/2000/svg\"",
",",
"type",
")",
";",
"}",
"if",
"(",
"uid",
"!==",
"undefined",
")",
"{",
"obj",
".",
"id",
"=",
"uid",
";",
"}",
"if",
"(",
"args",
"instanceof",
"Object",
")",
"{",
"element",
".",
"update",
"(",
"obj",
",",
"args",
")",
";",
"}",
"}",
"if",
"(",
"pos",
"===",
"undefined",
"||",
"pos",
"===",
"\"last\"",
")",
"{",
"target",
".",
"appendChild",
"(",
"obj",
")",
";",
"}",
"else",
"if",
"(",
"pos",
"===",
"\"first\"",
")",
"{",
"element",
".",
"prependChild",
"(",
"target",
",",
"obj",
")",
";",
"}",
"else",
"if",
"(",
"pos",
"===",
"\"after\"",
")",
"{",
"pos",
"=",
"{",
"}",
";",
"pos",
".",
"after",
"=",
"target",
";",
"target",
"=",
"target",
".",
"parentNode",
";",
"target",
".",
"insertBefore",
"(",
"obj",
",",
"pos",
".",
"after",
".",
"nextSibling",
")",
";",
"}",
"else",
"if",
"(",
"pos",
".",
"after",
"!==",
"undefined",
")",
"{",
"target",
".",
"insertBefore",
"(",
"obj",
",",
"pos",
".",
"after",
".",
"nextSibling",
")",
";",
"}",
"else",
"if",
"(",
"pos",
"===",
"\"before\"",
")",
"{",
"pos",
"=",
"{",
"}",
";",
"pos",
".",
"before",
"=",
"target",
";",
"target",
"=",
"target",
".",
"parentNode",
";",
"target",
".",
"insertBefore",
"(",
"obj",
",",
"pos",
".",
"before",
")",
";",
"}",
"else",
"if",
"(",
"pos",
".",
"before",
"!==",
"undefined",
")",
"{",
"target",
".",
"insertBefore",
"(",
"obj",
",",
"pos",
".",
"before",
")",
";",
"}",
"else",
"{",
"target",
".",
"appendChild",
"(",
"obj",
")",
";",
"}",
"return",
"!",
"frag",
"?",
"obj",
":",
"result",
";",
"}"
] | Creates an Element in document.body or a target Element
An id is generated if not specified with args
@method create
@param {String} type Type of Element to create
@param {Object} args [Optional] Collection of properties to apply to the new element
@param {Mixed} target [Optional] Target Element
@param {Mixed} pos [Optional] "first", "last" or Object describing how to add the new Element, e.g. {before: referenceElement}
@return {Mixed} Element that was created, or an Array if `type` is a String of multiple Elements (frag) | [
"Creates",
"an",
"Element",
"in",
"document",
".",
"body",
"or",
"a",
"target",
"Element"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L5023-L5099 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj, key, value ) {
key = string.toCamelCase( key );
if ( value !== undefined ) {
obj.style[key] = value;
return obj;
}
else {
return obj.style[key];
}
} | javascript | function ( obj, key, value ) {
key = string.toCamelCase( key );
if ( value !== undefined ) {
obj.style[key] = value;
return obj;
}
else {
return obj.style[key];
}
} | [
"function",
"(",
"obj",
",",
"key",
",",
"value",
")",
"{",
"key",
"=",
"string",
".",
"toCamelCase",
"(",
"key",
")",
";",
"if",
"(",
"value",
"!==",
"undefined",
")",
"{",
"obj",
".",
"style",
"[",
"key",
"]",
"=",
"value",
";",
"return",
"obj",
";",
"}",
"else",
"{",
"return",
"obj",
".",
"style",
"[",
"key",
"]",
";",
"}",
"}"
] | Gets or sets a CSS style attribute on an Element
@method css
@param {Mixed} obj Element
@param {String} key CSS to put in a style tag
@param {String} value [Optional] Value to set
@return {Object} Element | [
"Gets",
"or",
"sets",
"a",
"CSS",
"style",
"attribute",
"on",
"an",
"Element"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L5110-L5120 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj ) {
observer.remove( obj );
if ( obj.parentNode !== null ) {
obj.parentNode.removeChild( obj );
}
return undefined;
} | javascript | function ( obj ) {
observer.remove( obj );
if ( obj.parentNode !== null ) {
obj.parentNode.removeChild( obj );
}
return undefined;
} | [
"function",
"(",
"obj",
")",
"{",
"observer",
".",
"remove",
"(",
"obj",
")",
";",
"if",
"(",
"obj",
".",
"parentNode",
"!==",
"null",
")",
"{",
"obj",
".",
"parentNode",
".",
"removeChild",
"(",
"obj",
")",
";",
"}",
"return",
"undefined",
";",
"}"
] | Destroys an Element
@method destroy
@param {Mixed} obj Element
@return {Undefined} undefined | [
"Destroys",
"an",
"Element"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L5148-L5156 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj, arg ) {
var result = [];
utility.genId( obj, true );
array.each( string.explode( arg ), function ( i ) {
result = result.concat( utility.$( "#" + obj.id + " " + i ) );
});
return result;
} | javascript | function ( obj, arg ) {
var result = [];
utility.genId( obj, true );
array.each( string.explode( arg ), function ( i ) {
result = result.concat( utility.$( "#" + obj.id + " " + i ) );
});
return result;
} | [
"function",
"(",
"obj",
",",
"arg",
")",
"{",
"var",
"result",
"=",
"[",
"]",
";",
"utility",
".",
"genId",
"(",
"obj",
",",
"true",
")",
";",
"array",
".",
"each",
"(",
"string",
".",
"explode",
"(",
"arg",
")",
",",
"function",
"(",
"i",
")",
"{",
"result",
"=",
"result",
".",
"concat",
"(",
"utility",
".",
"$",
"(",
"\"#\"",
"+",
"obj",
".",
"id",
"+",
"\" \"",
"+",
"i",
")",
")",
";",
"}",
")",
";",
"return",
"result",
";",
"}"
] | Finds descendant childNodes of Element matched by arg
@method find
@param {Mixed} obj Element to search
@param {String} arg Comma delimited string of descendant selectors
@return {Mixed} Array of Elements or undefined | [
"Finds",
"descendant",
"childNodes",
"of",
"Element",
"matched",
"by",
"arg"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L5257-L5267 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( arg ) {
var obj = document.createDocumentFragment();
if ( arg ) {
array.each( array.cast( element.create( "div", {innerHTML: arg}, obj ).childNodes ), function ( i ) {
obj.appendChild( i );
});
obj.removeChild( obj.childNodes[0] );
}
return obj;
} | javascript | function ( arg ) {
var obj = document.createDocumentFragment();
if ( arg ) {
array.each( array.cast( element.create( "div", {innerHTML: arg}, obj ).childNodes ), function ( i ) {
obj.appendChild( i );
});
obj.removeChild( obj.childNodes[0] );
}
return obj;
} | [
"function",
"(",
"arg",
")",
"{",
"var",
"obj",
"=",
"document",
".",
"createDocumentFragment",
"(",
")",
";",
"if",
"(",
"arg",
")",
"{",
"array",
".",
"each",
"(",
"array",
".",
"cast",
"(",
"element",
".",
"create",
"(",
"\"div\"",
",",
"{",
"innerHTML",
":",
"arg",
"}",
",",
"obj",
")",
".",
"childNodes",
")",
",",
"function",
"(",
"i",
")",
"{",
"obj",
".",
"appendChild",
"(",
"i",
")",
";",
"}",
")",
";",
"obj",
".",
"removeChild",
"(",
"obj",
".",
"childNodes",
"[",
"0",
"]",
")",
";",
"}",
"return",
"obj",
";",
"}"
] | Creates a document fragment
@method frag
@param {String} arg [Optional] innerHTML
@return {Object} Document fragment | [
"Creates",
"a",
"document",
"fragment"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L5276-L5288 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj, arg ) {
var result = element.find( obj, arg );
return ( !isNaN( result.length ) && result.length > 0 );
} | javascript | function ( obj, arg ) {
var result = element.find( obj, arg );
return ( !isNaN( result.length ) && result.length > 0 );
} | [
"function",
"(",
"obj",
",",
"arg",
")",
"{",
"var",
"result",
"=",
"element",
".",
"find",
"(",
"obj",
",",
"arg",
")",
";",
"return",
"(",
"!",
"isNaN",
"(",
"result",
".",
"length",
")",
"&&",
"result",
".",
"length",
">",
"0",
")",
";",
"}"
] | Determines if Element has descendants matching arg
@method has
@param {Mixed} obj Element or Array of Elements or $ queries
@param {String} arg Type of Element to find
@return {Boolean} True if 1 or more Elements are found | [
"Determines",
"if",
"Element",
"has",
"descendants",
"matching",
"arg"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L5298-L5302 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj, arg ) {
if ( arg === undefined ) {
return obj.innerHTML;
}
else {
obj.innerHTML = arg;
return obj;
}
} | javascript | function ( obj, arg ) {
if ( arg === undefined ) {
return obj.innerHTML;
}
else {
obj.innerHTML = arg;
return obj;
}
} | [
"function",
"(",
"obj",
",",
"arg",
")",
"{",
"if",
"(",
"arg",
"===",
"undefined",
")",
"{",
"return",
"obj",
".",
"innerHTML",
";",
"}",
"else",
"{",
"obj",
".",
"innerHTML",
"=",
"arg",
";",
"return",
"obj",
";",
"}",
"}"
] | Gets or sets an Elements innerHTML
@method html
@param {Object} obj Element
@param {String} arg [Optional] innerHTML value
@return {Object} Element | [
"Gets",
"or",
"sets",
"an",
"Elements",
"innerHTML"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L5334-L5342 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj, arg ) {
if ( regex.selector_is.test( arg ) ) {
utility.id( obj );
return ( element.find( obj.parentNode, obj.nodeName.toLowerCase() + arg ).filter( function ( i ) {
return ( i.id === obj.id );
}).length === 1 );
}
else {
return new RegExp( arg, "i" ).test( obj.nodeName );
}
} | javascript | function ( obj, arg ) {
if ( regex.selector_is.test( arg ) ) {
utility.id( obj );
return ( element.find( obj.parentNode, obj.nodeName.toLowerCase() + arg ).filter( function ( i ) {
return ( i.id === obj.id );
}).length === 1 );
}
else {
return new RegExp( arg, "i" ).test( obj.nodeName );
}
} | [
"function",
"(",
"obj",
",",
"arg",
")",
"{",
"if",
"(",
"regex",
".",
"selector_is",
".",
"test",
"(",
"arg",
")",
")",
"{",
"utility",
".",
"id",
"(",
"obj",
")",
";",
"return",
"(",
"element",
".",
"find",
"(",
"obj",
".",
"parentNode",
",",
"obj",
".",
"nodeName",
".",
"toLowerCase",
"(",
")",
"+",
"arg",
")",
".",
"filter",
"(",
"function",
"(",
"i",
")",
"{",
"return",
"(",
"i",
".",
"id",
"===",
"obj",
".",
"id",
")",
";",
"}",
")",
".",
"length",
"===",
"1",
")",
";",
"}",
"else",
"{",
"return",
"new",
"RegExp",
"(",
"arg",
",",
"\"i\"",
")",
".",
"test",
"(",
"obj",
".",
"nodeName",
")",
";",
"}",
"}"
] | Determines if Element is equal to arg, supports nodeNames & CSS2+ selectors
@method is
@param {Mixed} obj Element
@param {String} arg Property to query
@return {Boolean} True if a match | [
"Determines",
"if",
"Element",
"is",
"equal",
"to",
"arg",
"supports",
"nodeNames",
"&",
"CSS2",
"+",
"selectors"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L5352-L5362 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj ) {
return obj.nodeName === "FORM" ? false : validate.test( {alphanum : obj.value || element.text( obj )} ).pass;
} | javascript | function ( obj ) {
return obj.nodeName === "FORM" ? false : validate.test( {alphanum : obj.value || element.text( obj )} ).pass;
} | [
"function",
"(",
"obj",
")",
"{",
"return",
"obj",
".",
"nodeName",
"===",
"\"FORM\"",
"?",
"false",
":",
"validate",
".",
"test",
"(",
"{",
"alphanum",
":",
"obj",
".",
"value",
"||",
"element",
".",
"text",
"(",
"obj",
")",
"}",
")",
".",
"pass",
";",
"}"
] | Tests if Element value or text is alpha-numeric
@method isAlphaNum
@param {Object} obj Element to test
@return {Boolean} Result of test | [
"Tests",
"if",
"Element",
"value",
"or",
"text",
"is",
"alpha",
"-",
"numeric"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L5371-L5373 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj ) {
return obj.nodeName === "FORM" ? false : string.isDate( obj.value || element.text( obj ) );
} | javascript | function ( obj ) {
return obj.nodeName === "FORM" ? false : string.isDate( obj.value || element.text( obj ) );
} | [
"function",
"(",
"obj",
")",
"{",
"return",
"obj",
".",
"nodeName",
"===",
"\"FORM\"",
"?",
"false",
":",
"string",
".",
"isDate",
"(",
"obj",
".",
"value",
"||",
"element",
".",
"text",
"(",
"obj",
")",
")",
";",
"}"
] | Tests if Element value or text is a date
@method isDate
@param {Object} obj Element to test
@return {Boolean} Result of test | [
"Tests",
"if",
"Element",
"value",
"or",
"text",
"is",
"a",
"date"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L5404-L5406 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj ) {
return obj.nodeName === "FORM" ? false : string.isDomain( obj.value || element.text( obj ) );
} | javascript | function ( obj ) {
return obj.nodeName === "FORM" ? false : string.isDomain( obj.value || element.text( obj ) );
} | [
"function",
"(",
"obj",
")",
"{",
"return",
"obj",
".",
"nodeName",
"===",
"\"FORM\"",
"?",
"false",
":",
"string",
".",
"isDomain",
"(",
"obj",
".",
"value",
"||",
"element",
".",
"text",
"(",
"obj",
")",
")",
";",
"}"
] | Tests if Element value or text is a domain
@method isDomain
@param {Object} obj Element to test
@return {Boolean} Result of test | [
"Tests",
"if",
"Element",
"value",
"or",
"text",
"is",
"a",
"domain"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L5426-L5428 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj ) {
return obj.nodeName === "FORM" ? false : string.isEmail( obj.value || element.text( obj ) );
} | javascript | function ( obj ) {
return obj.nodeName === "FORM" ? false : string.isEmail( obj.value || element.text( obj ) );
} | [
"function",
"(",
"obj",
")",
"{",
"return",
"obj",
".",
"nodeName",
"===",
"\"FORM\"",
"?",
"false",
":",
"string",
".",
"isEmail",
"(",
"obj",
".",
"value",
"||",
"element",
".",
"text",
"(",
"obj",
")",
")",
";",
"}"
] | Tests if Element value or text is an email address
@method isEmail
@param {Object} obj Element to test
@return {Boolean} Result of test | [
"Tests",
"if",
"Element",
"value",
"or",
"text",
"is",
"an",
"email",
"address"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L5437-L5439 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj ) {
return obj.nodeName === "FORM" ? false : string.isEmpty( obj.value || element.text( obj ) );
} | javascript | function ( obj ) {
return obj.nodeName === "FORM" ? false : string.isEmpty( obj.value || element.text( obj ) );
} | [
"function",
"(",
"obj",
")",
"{",
"return",
"obj",
".",
"nodeName",
"===",
"\"FORM\"",
"?",
"false",
":",
"string",
".",
"isEmpty",
"(",
"obj",
".",
"value",
"||",
"element",
".",
"text",
"(",
"obj",
")",
")",
";",
"}"
] | Tests if Element value or text is empty
@method isEmpty
@param {Object} obj Element to test
@return {Boolean} Result of test | [
"Tests",
"if",
"Element",
"value",
"or",
"text",
"is",
"empty"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L5448-L5450 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj ) {
return obj.nodeName === "FORM" ? false : string.isIP( obj.value || element.text( obj ) );
} | javascript | function ( obj ) {
return obj.nodeName === "FORM" ? false : string.isIP( obj.value || element.text( obj ) );
} | [
"function",
"(",
"obj",
")",
"{",
"return",
"obj",
".",
"nodeName",
"===",
"\"FORM\"",
"?",
"false",
":",
"string",
".",
"isIP",
"(",
"obj",
".",
"value",
"||",
"element",
".",
"text",
"(",
"obj",
")",
")",
";",
"}"
] | Tests if Element value or text is an IP address
@method isIP
@param {Object} obj Element to test
@return {Boolean} Result of test | [
"Tests",
"if",
"Element",
"value",
"or",
"text",
"is",
"an",
"IP",
"address"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L5459-L5461 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj ) {
return obj.nodeName === "FORM" ? false : string.isInt( obj.value || element.text( obj ) );
} | javascript | function ( obj ) {
return obj.nodeName === "FORM" ? false : string.isInt( obj.value || element.text( obj ) );
} | [
"function",
"(",
"obj",
")",
"{",
"return",
"obj",
".",
"nodeName",
"===",
"\"FORM\"",
"?",
"false",
":",
"string",
".",
"isInt",
"(",
"obj",
".",
"value",
"||",
"element",
".",
"text",
"(",
"obj",
")",
")",
";",
"}"
] | Tests if Element value or text is an integer
@method isInt
@param {Object} obj Element to test
@return {Boolean} Result of test | [
"Tests",
"if",
"Element",
"value",
"or",
"text",
"is",
"an",
"integer"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L5470-L5472 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj ) {
return obj.nodeName === "FORM" ? false : string.isNumber( obj.value || element.text( obj ) );
} | javascript | function ( obj ) {
return obj.nodeName === "FORM" ? false : string.isNumber( obj.value || element.text( obj ) );
} | [
"function",
"(",
"obj",
")",
"{",
"return",
"obj",
".",
"nodeName",
"===",
"\"FORM\"",
"?",
"false",
":",
"string",
".",
"isNumber",
"(",
"obj",
".",
"value",
"||",
"element",
".",
"text",
"(",
"obj",
")",
")",
";",
"}"
] | Tests if Element value or text is numeric
@method isNumber
@param {Object} obj Element to test
@return {Boolean} Result of test | [
"Tests",
"if",
"Element",
"value",
"or",
"text",
"is",
"numeric"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L5481-L5483 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj ) {
return obj.nodeName === "FORM" ? false : string.isPhone( obj.value || element.text( obj ) );
} | javascript | function ( obj ) {
return obj.nodeName === "FORM" ? false : string.isPhone( obj.value || element.text( obj ) );
} | [
"function",
"(",
"obj",
")",
"{",
"return",
"obj",
".",
"nodeName",
"===",
"\"FORM\"",
"?",
"false",
":",
"string",
".",
"isPhone",
"(",
"obj",
".",
"value",
"||",
"element",
".",
"text",
"(",
"obj",
")",
")",
";",
"}"
] | Tests if Element value or text is a phone number
@method isPhone
@param {Object} obj Element to test
@return {Boolean} Result of test | [
"Tests",
"if",
"Element",
"value",
"or",
"text",
"is",
"a",
"phone",
"number"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L5492-L5494 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj ) {
return obj.nodeName === "FORM" ? false : string.isUrl( obj.value || element.text( obj ) );
} | javascript | function ( obj ) {
return obj.nodeName === "FORM" ? false : string.isUrl( obj.value || element.text( obj ) );
} | [
"function",
"(",
"obj",
")",
"{",
"return",
"obj",
".",
"nodeName",
"===",
"\"FORM\"",
"?",
"false",
":",
"string",
".",
"isUrl",
"(",
"obj",
".",
"value",
"||",
"element",
".",
"text",
"(",
"obj",
")",
")",
";",
"}"
] | Tests if Element value or text is a URL
@method isUrl
@param {Object} obj Element to test
@return {Boolean} Result of test | [
"Tests",
"if",
"Element",
"value",
"or",
"text",
"is",
"a",
"URL"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L5503-L5505 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj, arg, add ) {
add = ( add !== false );
arg = string.explode( arg, " " );
if ( add ) {
array.each( arg, function ( i ) {
obj.classList.add( i );
});
}
else {
array.each( arg, function ( i ) {
if ( i !== "*" ) {
obj.classList.remove( i );
}
else {
array.each( obj.classList, function ( x ) {
this.remove( x );
});
return false;
}
});
}
return obj;
} | javascript | function ( obj, arg, add ) {
add = ( add !== false );
arg = string.explode( arg, " " );
if ( add ) {
array.each( arg, function ( i ) {
obj.classList.add( i );
});
}
else {
array.each( arg, function ( i ) {
if ( i !== "*" ) {
obj.classList.remove( i );
}
else {
array.each( obj.classList, function ( x ) {
this.remove( x );
});
return false;
}
});
}
return obj;
} | [
"function",
"(",
"obj",
",",
"arg",
",",
"add",
")",
"{",
"add",
"=",
"(",
"add",
"!==",
"false",
")",
";",
"arg",
"=",
"string",
".",
"explode",
"(",
"arg",
",",
"\" \"",
")",
";",
"if",
"(",
"add",
")",
"{",
"array",
".",
"each",
"(",
"arg",
",",
"function",
"(",
"i",
")",
"{",
"obj",
".",
"classList",
".",
"add",
"(",
"i",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"array",
".",
"each",
"(",
"arg",
",",
"function",
"(",
"i",
")",
"{",
"if",
"(",
"i",
"!==",
"\"*\"",
")",
"{",
"obj",
".",
"classList",
".",
"remove",
"(",
"i",
")",
";",
"}",
"else",
"{",
"array",
".",
"each",
"(",
"obj",
".",
"classList",
",",
"function",
"(",
"x",
")",
"{",
"this",
".",
"remove",
"(",
"x",
")",
";",
"}",
")",
";",
"return",
"false",
";",
"}",
"}",
")",
";",
"}",
"return",
"obj",
";",
"}"
] | Adds or removes a CSS class
@method klass
@param {Mixed} obj Element
@param {String} arg Class to add or remove ( can be a wildcard )
@param {Boolean} add Boolean to add or remove, defaults to true
@return {Object} Element | [
"Adds",
"or",
"removes",
"a",
"CSS",
"class"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L5516-L5541 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj ) {
obj = obj || document.body;
var left, top, right, bottom, height, width;
left = top = 0;
width = obj.offsetWidth;
height = obj.offsetHeight;
if ( obj.offsetParent ) {
top = obj.offsetTop;
left = obj.offsetLeft;
while ( obj = obj.offsetParent ) {
left += obj.offsetLeft;
top += obj.offsetTop;
}
right = document.body.offsetWidth - ( left + width );
bottom = document.body.offsetHeight - ( top + height );
}
else {
right = width;
bottom = height;
}
return [left, top, right, bottom];
} | javascript | function ( obj ) {
obj = obj || document.body;
var left, top, right, bottom, height, width;
left = top = 0;
width = obj.offsetWidth;
height = obj.offsetHeight;
if ( obj.offsetParent ) {
top = obj.offsetTop;
left = obj.offsetLeft;
while ( obj = obj.offsetParent ) {
left += obj.offsetLeft;
top += obj.offsetTop;
}
right = document.body.offsetWidth - ( left + width );
bottom = document.body.offsetHeight - ( top + height );
}
else {
right = width;
bottom = height;
}
return [left, top, right, bottom];
} | [
"function",
"(",
"obj",
")",
"{",
"obj",
"=",
"obj",
"||",
"document",
".",
"body",
";",
"var",
"left",
",",
"top",
",",
"right",
",",
"bottom",
",",
"height",
",",
"width",
";",
"left",
"=",
"top",
"=",
"0",
";",
"width",
"=",
"obj",
".",
"offsetWidth",
";",
"height",
"=",
"obj",
".",
"offsetHeight",
";",
"if",
"(",
"obj",
".",
"offsetParent",
")",
"{",
"top",
"=",
"obj",
".",
"offsetTop",
";",
"left",
"=",
"obj",
".",
"offsetLeft",
";",
"while",
"(",
"obj",
"=",
"obj",
".",
"offsetParent",
")",
"{",
"left",
"+=",
"obj",
".",
"offsetLeft",
";",
"top",
"+=",
"obj",
".",
"offsetTop",
";",
"}",
"right",
"=",
"document",
".",
"body",
".",
"offsetWidth",
"-",
"(",
"left",
"+",
"width",
")",
";",
"bottom",
"=",
"document",
".",
"body",
".",
"offsetHeight",
"-",
"(",
"top",
"+",
"height",
")",
";",
"}",
"else",
"{",
"right",
"=",
"width",
";",
"bottom",
"=",
"height",
";",
"}",
"return",
"[",
"left",
",",
"top",
",",
"right",
",",
"bottom",
"]",
";",
"}"
] | Finds the position of an element
@method position
@param {Mixed} obj Element
@return {Array} Coordinates [left, top, right, bottom] | [
"Finds",
"the",
"position",
"of",
"an",
"element"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L5550-L5576 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj, child ) {
return obj.childNodes.length === 0 ? obj.appendChild( child ) : obj.insertBefore( child, obj.childNodes[0] );
} | javascript | function ( obj, child ) {
return obj.childNodes.length === 0 ? obj.appendChild( child ) : obj.insertBefore( child, obj.childNodes[0] );
} | [
"function",
"(",
"obj",
",",
"child",
")",
"{",
"return",
"obj",
".",
"childNodes",
".",
"length",
"===",
"0",
"?",
"obj",
".",
"appendChild",
"(",
"child",
")",
":",
"obj",
".",
"insertBefore",
"(",
"child",
",",
"obj",
".",
"childNodes",
"[",
"0",
"]",
")",
";",
"}"
] | Prepends an Element to an Element
@method prependChild
@param {Object} obj Element
@param {Object} child Child Element
@return {Object} Element | [
"Prepends",
"an",
"Element",
"to",
"an",
"Element"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L5586-L5588 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj, key ) {
var target;
if ( regex.svg.test( obj.namespaceURI ) ) {
obj.removeAttributeNS( obj.namespaceURI, key );
}
else {
if ( obj.nodeName === "SELECT" && key === "selected") {
target = utility.$( "#" + obj.id + " option[selected=\"selected\"]" )[0];
if ( target !== undefined ) {
target.selected = false;
target.removeAttribute( "selected" );
}
}
else {
obj.removeAttribute( key );
}
}
return obj;
} | javascript | function ( obj, key ) {
var target;
if ( regex.svg.test( obj.namespaceURI ) ) {
obj.removeAttributeNS( obj.namespaceURI, key );
}
else {
if ( obj.nodeName === "SELECT" && key === "selected") {
target = utility.$( "#" + obj.id + " option[selected=\"selected\"]" )[0];
if ( target !== undefined ) {
target.selected = false;
target.removeAttribute( "selected" );
}
}
else {
obj.removeAttribute( key );
}
}
return obj;
} | [
"function",
"(",
"obj",
",",
"key",
")",
"{",
"var",
"target",
";",
"if",
"(",
"regex",
".",
"svg",
".",
"test",
"(",
"obj",
".",
"namespaceURI",
")",
")",
"{",
"obj",
".",
"removeAttributeNS",
"(",
"obj",
".",
"namespaceURI",
",",
"key",
")",
";",
"}",
"else",
"{",
"if",
"(",
"obj",
".",
"nodeName",
"===",
"\"SELECT\"",
"&&",
"key",
"===",
"\"selected\"",
")",
"{",
"target",
"=",
"utility",
".",
"$",
"(",
"\"#\"",
"+",
"obj",
".",
"id",
"+",
"\" option[selected=\\\"selected\\\"]\"",
")",
"[",
"\\\"",
"]",
";",
"\\\"",
"}",
"else",
"0",
"}",
"if",
"(",
"target",
"!==",
"undefined",
")",
"{",
"target",
".",
"selected",
"=",
"false",
";",
"target",
".",
"removeAttribute",
"(",
"\"selected\"",
")",
";",
"}",
"}"
] | Removes an Element attribute
@method removeAttr
@param {Mixed} obj Element
@param {String} key Attribute name
@return {Object} Element | [
"Removes",
"an",
"Element",
"attribute"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L5598-L5619 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj, ms ) {
return client.scroll( array.remove( element.position( obj ), 2, 3 ), ms );
} | javascript | function ( obj, ms ) {
return client.scroll( array.remove( element.position( obj ), 2, 3 ), ms );
} | [
"function",
"(",
"obj",
",",
"ms",
")",
"{",
"return",
"client",
".",
"scroll",
"(",
"array",
".",
"remove",
"(",
"element",
".",
"position",
"(",
"obj",
")",
",",
"2",
",",
"3",
")",
",",
"ms",
")",
";",
"}"
] | Scrolls to the position of an Element
@method scrollTo
@param {Object} obj Element to scroll to
@param {Number} ms [Optional] Milliseconds to scroll, default is 250, min is 100
@return {Object} Deferred | [
"Scrolls",
"to",
"the",
"position",
"of",
"an",
"Element"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L5629-L5631 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj, string, encode ) {
string = ( string === true );
encode = ( encode !== false );
var children = [],
registry = {},
result;
children = obj.nodeName === "FORM" ? ( obj.elements !== undefined ? array.cast( obj.elements ) : obj.find( "button, input, select, textarea" ) ) : [obj];
array.each( children, function ( i ) {
if ( i.nodeName === "FORM" ) {
utility.merge( registry, json.decode( element.serialize( i ) ) );
}
else if ( registry[i.name] === undefined ) {
registry[i.name] = element.val( i );
}
});
if ( !string ) {
result = json.encode( registry );
}
else {
result = "";
utility.iterate( registry, function ( v, k ) {
encode ? result += "&" + encodeURIComponent( k ) + "=" + encodeURIComponent( v ) : result += "&" + k + "=" + v;
});
result = result.replace( regex.and, "?" );
}
return result;
} | javascript | function ( obj, string, encode ) {
string = ( string === true );
encode = ( encode !== false );
var children = [],
registry = {},
result;
children = obj.nodeName === "FORM" ? ( obj.elements !== undefined ? array.cast( obj.elements ) : obj.find( "button, input, select, textarea" ) ) : [obj];
array.each( children, function ( i ) {
if ( i.nodeName === "FORM" ) {
utility.merge( registry, json.decode( element.serialize( i ) ) );
}
else if ( registry[i.name] === undefined ) {
registry[i.name] = element.val( i );
}
});
if ( !string ) {
result = json.encode( registry );
}
else {
result = "";
utility.iterate( registry, function ( v, k ) {
encode ? result += "&" + encodeURIComponent( k ) + "=" + encodeURIComponent( v ) : result += "&" + k + "=" + v;
});
result = result.replace( regex.and, "?" );
}
return result;
} | [
"function",
"(",
"obj",
",",
"string",
",",
"encode",
")",
"{",
"string",
"=",
"(",
"string",
"===",
"true",
")",
";",
"encode",
"=",
"(",
"encode",
"!==",
"false",
")",
";",
"var",
"children",
"=",
"[",
"]",
",",
"registry",
"=",
"{",
"}",
",",
"result",
";",
"children",
"=",
"obj",
".",
"nodeName",
"===",
"\"FORM\"",
"?",
"(",
"obj",
".",
"elements",
"!==",
"undefined",
"?",
"array",
".",
"cast",
"(",
"obj",
".",
"elements",
")",
":",
"obj",
".",
"find",
"(",
"\"button, input, select, textarea\"",
")",
")",
":",
"[",
"obj",
"]",
";",
"array",
".",
"each",
"(",
"children",
",",
"function",
"(",
"i",
")",
"{",
"if",
"(",
"i",
".",
"nodeName",
"===",
"\"FORM\"",
")",
"{",
"utility",
".",
"merge",
"(",
"registry",
",",
"json",
".",
"decode",
"(",
"element",
".",
"serialize",
"(",
"i",
")",
")",
")",
";",
"}",
"else",
"if",
"(",
"registry",
"[",
"i",
".",
"name",
"]",
"===",
"undefined",
")",
"{",
"registry",
"[",
"i",
".",
"name",
"]",
"=",
"element",
".",
"val",
"(",
"i",
")",
";",
"}",
"}",
")",
";",
"if",
"(",
"!",
"string",
")",
"{",
"result",
"=",
"json",
".",
"encode",
"(",
"registry",
")",
";",
"}",
"else",
"{",
"result",
"=",
"\"\"",
";",
"utility",
".",
"iterate",
"(",
"registry",
",",
"function",
"(",
"v",
",",
"k",
")",
"{",
"encode",
"?",
"result",
"+=",
"\"&\"",
"+",
"encodeURIComponent",
"(",
"k",
")",
"+",
"\"=\"",
"+",
"encodeURIComponent",
"(",
"v",
")",
":",
"result",
"+=",
"\"&\"",
"+",
"k",
"+",
"\"=\"",
"+",
"v",
";",
"}",
")",
";",
"result",
"=",
"result",
".",
"replace",
"(",
"regex",
".",
"and",
",",
"\"?\"",
")",
";",
"}",
"return",
"result",
";",
"}"
] | Serializes the elements of an Element
@method serialize
@param {Object} obj Element
@param {Boolean} string [Optional] true if you want a query string, default is false ( JSON )
@param {Boolean} encode [Optional] true if you want to URI encode the value, default is true
@return {Mixed} String or Object | [
"Serializes",
"the",
"elements",
"of",
"an",
"Element"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L5642-L5674 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj ) {
var parse = function ( arg ) {
return number.parse(arg, 10);
};
return {
height : obj.offsetHeight + parse( obj.style.paddingTop || 0 ) + parse( obj.style.paddingBottom || 0 ) + parse( obj.style.borderTop || 0 ) + parse( obj.style.borderBottom || 0 ),
width : obj.offsetWidth + parse( obj.style.paddingLeft || 0 ) + parse( obj.style.paddingRight || 0 ) + parse( obj.style.borderLeft || 0 ) + parse( obj.style.borderRight || 0 )
};
} | javascript | function ( obj ) {
var parse = function ( arg ) {
return number.parse(arg, 10);
};
return {
height : obj.offsetHeight + parse( obj.style.paddingTop || 0 ) + parse( obj.style.paddingBottom || 0 ) + parse( obj.style.borderTop || 0 ) + parse( obj.style.borderBottom || 0 ),
width : obj.offsetWidth + parse( obj.style.paddingLeft || 0 ) + parse( obj.style.paddingRight || 0 ) + parse( obj.style.borderLeft || 0 ) + parse( obj.style.borderRight || 0 )
};
} | [
"function",
"(",
"obj",
")",
"{",
"var",
"parse",
"=",
"function",
"(",
"arg",
")",
"{",
"return",
"number",
".",
"parse",
"(",
"arg",
",",
"10",
")",
";",
"}",
";",
"return",
"{",
"height",
":",
"obj",
".",
"offsetHeight",
"+",
"parse",
"(",
"obj",
".",
"style",
".",
"paddingTop",
"||",
"0",
")",
"+",
"parse",
"(",
"obj",
".",
"style",
".",
"paddingBottom",
"||",
"0",
")",
"+",
"parse",
"(",
"obj",
".",
"style",
".",
"borderTop",
"||",
"0",
")",
"+",
"parse",
"(",
"obj",
".",
"style",
".",
"borderBottom",
"||",
"0",
")",
",",
"width",
":",
"obj",
".",
"offsetWidth",
"+",
"parse",
"(",
"obj",
".",
"style",
".",
"paddingLeft",
"||",
"0",
")",
"+",
"parse",
"(",
"obj",
".",
"style",
".",
"paddingRight",
"||",
"0",
")",
"+",
"parse",
"(",
"obj",
".",
"style",
".",
"borderLeft",
"||",
"0",
")",
"+",
"parse",
"(",
"obj",
".",
"style",
".",
"borderRight",
"||",
"0",
")",
"}",
";",
"}"
] | Returns the size of the Object
@method size
@param {Mixed} obj Element
@return {Object} Size {height: n, width:n} | [
"Returns",
"the",
"size",
"of",
"the",
"Object"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L5683-L5692 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj, args ) {
args = args || {};
utility.iterate( args, function ( v, k ) {
if ( regex.element_update.test( k ) ) {
obj[k] = v;
}
else if ( k === "class" ) {
!string.isEmpty( v ) ? element.klass( obj, v ) : element.klass( obj, "*", false );
}
else if ( k.indexOf( "data-" ) === 0 ) {
element.data( obj, k.replace( "data-", "" ), v );
}
else if ( k === "id" ) {
var o = observer.listeners;
if ( o[obj.id] !== undefined ) {
o[k] = o[obj.id];
delete o[obj.id];
}
}
else {
element.attr ( obj, k, v );
}
});
return obj;
} | javascript | function ( obj, args ) {
args = args || {};
utility.iterate( args, function ( v, k ) {
if ( regex.element_update.test( k ) ) {
obj[k] = v;
}
else if ( k === "class" ) {
!string.isEmpty( v ) ? element.klass( obj, v ) : element.klass( obj, "*", false );
}
else if ( k.indexOf( "data-" ) === 0 ) {
element.data( obj, k.replace( "data-", "" ), v );
}
else if ( k === "id" ) {
var o = observer.listeners;
if ( o[obj.id] !== undefined ) {
o[k] = o[obj.id];
delete o[obj.id];
}
}
else {
element.attr ( obj, k, v );
}
});
return obj;
} | [
"function",
"(",
"obj",
",",
"args",
")",
"{",
"args",
"=",
"args",
"||",
"{",
"}",
";",
"utility",
".",
"iterate",
"(",
"args",
",",
"function",
"(",
"v",
",",
"k",
")",
"{",
"if",
"(",
"regex",
".",
"element_update",
".",
"test",
"(",
"k",
")",
")",
"{",
"obj",
"[",
"k",
"]",
"=",
"v",
";",
"}",
"else",
"if",
"(",
"k",
"===",
"\"class\"",
")",
"{",
"!",
"string",
".",
"isEmpty",
"(",
"v",
")",
"?",
"element",
".",
"klass",
"(",
"obj",
",",
"v",
")",
":",
"element",
".",
"klass",
"(",
"obj",
",",
"\"*\"",
",",
"false",
")",
";",
"}",
"else",
"if",
"(",
"k",
".",
"indexOf",
"(",
"\"data-\"",
")",
"===",
"0",
")",
"{",
"element",
".",
"data",
"(",
"obj",
",",
"k",
".",
"replace",
"(",
"\"data-\"",
",",
"\"\"",
")",
",",
"v",
")",
";",
"}",
"else",
"if",
"(",
"k",
"===",
"\"id\"",
")",
"{",
"var",
"o",
"=",
"observer",
".",
"listeners",
";",
"if",
"(",
"o",
"[",
"obj",
".",
"id",
"]",
"!==",
"undefined",
")",
"{",
"o",
"[",
"k",
"]",
"=",
"o",
"[",
"obj",
".",
"id",
"]",
";",
"delete",
"o",
"[",
"obj",
".",
"id",
"]",
";",
"}",
"}",
"else",
"{",
"element",
".",
"attr",
"(",
"obj",
",",
"k",
",",
"v",
")",
";",
"}",
"}",
")",
";",
"return",
"obj",
";",
"}"
] | Updates an Element
@method update
@param {Mixed} obj Element
@param {Object} args Collection of properties
@return {Object} Element | [
"Updates",
"an",
"Element"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L5737-L5764 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj, value ) {
var event = "input",
output;
if ( value === undefined ) {
if ( regex.radio_checkbox.test( obj.type ) ) {
if ( string.isEmpty( obj.name ) ) {
throw new Error( label.error.expectedProperty );
}
array.each( utility.$( "input[name='" + obj.name + "']" ), function ( i ) {
if ( i.checked ) {
output = i.value;
return false;
}
});
}
else if ( regex.select.test( obj.type ) ) {
output = obj.options[obj.selectedIndex].value;
}
else if ( "value" in obj ) {
output = obj.value;
}
else {
output = element.text( obj );
}
if ( output !== undefined ) {
output = utility.coerce( output );
}
if ( typeof output === "string" ) {
output = string.trim( output );
}
}
else {
value = value.toString();
if ( regex.radio_checkbox.test( obj.type ) ) {
event = "click";
array.each( utility.$( "input[name='" + obj.name + "']" ), function ( i ) {
if ( i.value === value ) {
i.checked = true;
output = i;
return false;
}
});
}
else if ( regex.select.test( obj.type ) ) {
event = "change";
array.each( element.find( obj, "> *" ), function ( i ) {
if ( i.value === value ) {
i.selected = true;
output = i;
return false;
}
});
}
else {
obj.value !== undefined ? obj.value = value : element.text( obj, value );
}
element.dispatch( obj, event );
output = obj;
}
return output;
} | javascript | function ( obj, value ) {
var event = "input",
output;
if ( value === undefined ) {
if ( regex.radio_checkbox.test( obj.type ) ) {
if ( string.isEmpty( obj.name ) ) {
throw new Error( label.error.expectedProperty );
}
array.each( utility.$( "input[name='" + obj.name + "']" ), function ( i ) {
if ( i.checked ) {
output = i.value;
return false;
}
});
}
else if ( regex.select.test( obj.type ) ) {
output = obj.options[obj.selectedIndex].value;
}
else if ( "value" in obj ) {
output = obj.value;
}
else {
output = element.text( obj );
}
if ( output !== undefined ) {
output = utility.coerce( output );
}
if ( typeof output === "string" ) {
output = string.trim( output );
}
}
else {
value = value.toString();
if ( regex.radio_checkbox.test( obj.type ) ) {
event = "click";
array.each( utility.$( "input[name='" + obj.name + "']" ), function ( i ) {
if ( i.value === value ) {
i.checked = true;
output = i;
return false;
}
});
}
else if ( regex.select.test( obj.type ) ) {
event = "change";
array.each( element.find( obj, "> *" ), function ( i ) {
if ( i.value === value ) {
i.selected = true;
output = i;
return false;
}
});
}
else {
obj.value !== undefined ? obj.value = value : element.text( obj, value );
}
element.dispatch( obj, event );
output = obj;
}
return output;
} | [
"function",
"(",
"obj",
",",
"value",
")",
"{",
"var",
"event",
"=",
"\"input\"",
",",
"output",
";",
"if",
"(",
"value",
"===",
"undefined",
")",
"{",
"if",
"(",
"regex",
".",
"radio_checkbox",
".",
"test",
"(",
"obj",
".",
"type",
")",
")",
"{",
"if",
"(",
"string",
".",
"isEmpty",
"(",
"obj",
".",
"name",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"label",
".",
"error",
".",
"expectedProperty",
")",
";",
"}",
"array",
".",
"each",
"(",
"utility",
".",
"$",
"(",
"\"input[name='\"",
"+",
"obj",
".",
"name",
"+",
"\"']\"",
")",
",",
"function",
"(",
"i",
")",
"{",
"if",
"(",
"i",
".",
"checked",
")",
"{",
"output",
"=",
"i",
".",
"value",
";",
"return",
"false",
";",
"}",
"}",
")",
";",
"}",
"else",
"if",
"(",
"regex",
".",
"select",
".",
"test",
"(",
"obj",
".",
"type",
")",
")",
"{",
"output",
"=",
"obj",
".",
"options",
"[",
"obj",
".",
"selectedIndex",
"]",
".",
"value",
";",
"}",
"else",
"if",
"(",
"\"value\"",
"in",
"obj",
")",
"{",
"output",
"=",
"obj",
".",
"value",
";",
"}",
"else",
"{",
"output",
"=",
"element",
".",
"text",
"(",
"obj",
")",
";",
"}",
"if",
"(",
"output",
"!==",
"undefined",
")",
"{",
"output",
"=",
"utility",
".",
"coerce",
"(",
"output",
")",
";",
"}",
"if",
"(",
"typeof",
"output",
"===",
"\"string\"",
")",
"{",
"output",
"=",
"string",
".",
"trim",
"(",
"output",
")",
";",
"}",
"}",
"else",
"{",
"value",
"=",
"value",
".",
"toString",
"(",
")",
";",
"if",
"(",
"regex",
".",
"radio_checkbox",
".",
"test",
"(",
"obj",
".",
"type",
")",
")",
"{",
"event",
"=",
"\"click\"",
";",
"array",
".",
"each",
"(",
"utility",
".",
"$",
"(",
"\"input[name='\"",
"+",
"obj",
".",
"name",
"+",
"\"']\"",
")",
",",
"function",
"(",
"i",
")",
"{",
"if",
"(",
"i",
".",
"value",
"===",
"value",
")",
"{",
"i",
".",
"checked",
"=",
"true",
";",
"output",
"=",
"i",
";",
"return",
"false",
";",
"}",
"}",
")",
";",
"}",
"else",
"if",
"(",
"regex",
".",
"select",
".",
"test",
"(",
"obj",
".",
"type",
")",
")",
"{",
"event",
"=",
"\"change\"",
";",
"array",
".",
"each",
"(",
"element",
".",
"find",
"(",
"obj",
",",
"\"> *\"",
")",
",",
"function",
"(",
"i",
")",
"{",
"if",
"(",
"i",
".",
"value",
"===",
"value",
")",
"{",
"i",
".",
"selected",
"=",
"true",
";",
"output",
"=",
"i",
";",
"return",
"false",
";",
"}",
"}",
")",
";",
"}",
"else",
"{",
"obj",
".",
"value",
"!==",
"undefined",
"?",
"obj",
".",
"value",
"=",
"value",
":",
"element",
".",
"text",
"(",
"obj",
",",
"value",
")",
";",
"}",
"element",
".",
"dispatch",
"(",
"obj",
",",
"event",
")",
";",
"output",
"=",
"obj",
";",
"}",
"return",
"output",
";",
"}"
] | Gets or sets the value of Element
@method val
@param {Mixed} obj Element
@param {Mixed} value [Optional] Value to set
@return {Object} Element | [
"Gets",
"or",
"sets",
"the",
"value",
"of",
"Element"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L5774-L5844 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj ) {
return obj.nodeName === "FORM" ? validate.test( obj ) : !string.isEmpty( obj.value || element.text( obj ) );
} | javascript | function ( obj ) {
return obj.nodeName === "FORM" ? validate.test( obj ) : !string.isEmpty( obj.value || element.text( obj ) );
} | [
"function",
"(",
"obj",
")",
"{",
"return",
"obj",
".",
"nodeName",
"===",
"\"FORM\"",
"?",
"validate",
".",
"test",
"(",
"obj",
")",
":",
"!",
"string",
".",
"isEmpty",
"(",
"obj",
".",
"value",
"||",
"element",
".",
"text",
"(",
"obj",
")",
")",
";",
"}"
] | Validates the contents of Element
@method validate
@param {Object} obj Element to test
@return {Object} Result of test | [
"Validates",
"the",
"contents",
"of",
"Element"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L5853-L5855 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( arg, delimiter, header ) {
delimiter = delimiter || ",";
header = ( header !== false );
var obj = json.decode( arg, true ) || arg,
result = "",
prepare;
// Prepares input based on CSV rules
prepare = function ( input ) {
var output;
if ( input instanceof Array ) {
output = "\"" + input.toString() + "\"";
if ( regex.object_type.test( output ) ) {
output = "\"" + json.csv( input, delimiter ) + "\"";
}
}
else if ( input instanceof Object ) {
output = "\"" + json.csv( input, delimiter ) + "\"";
}
else if ( regex.csv_quote.test( input ) ) {
output = "\"" + input.replace( /"/g, "\"\"" ) + "\"";
}
else {
output = input;
}
return output;
};
if ( obj instanceof Array ) {
if ( obj[0] instanceof Object ) {
if ( header ) {
result = ( array.keys( obj[0] ).join( delimiter ) + "\n" );
}
result += obj.map( function ( i ) {
return json.csv( i, delimiter, false );
}).join( "\n" );
}
else {
result += ( prepare( obj, delimiter ) + "\n" );
}
}
else {
if ( header ) {
result = ( array.keys( obj ).join( delimiter ) + "\n" );
}
result += ( array.cast( obj ).map( prepare ).join( delimiter ) + "\n" );
}
return result.replace(/\n$/, "");
} | javascript | function ( arg, delimiter, header ) {
delimiter = delimiter || ",";
header = ( header !== false );
var obj = json.decode( arg, true ) || arg,
result = "",
prepare;
// Prepares input based on CSV rules
prepare = function ( input ) {
var output;
if ( input instanceof Array ) {
output = "\"" + input.toString() + "\"";
if ( regex.object_type.test( output ) ) {
output = "\"" + json.csv( input, delimiter ) + "\"";
}
}
else if ( input instanceof Object ) {
output = "\"" + json.csv( input, delimiter ) + "\"";
}
else if ( regex.csv_quote.test( input ) ) {
output = "\"" + input.replace( /"/g, "\"\"" ) + "\"";
}
else {
output = input;
}
return output;
};
if ( obj instanceof Array ) {
if ( obj[0] instanceof Object ) {
if ( header ) {
result = ( array.keys( obj[0] ).join( delimiter ) + "\n" );
}
result += obj.map( function ( i ) {
return json.csv( i, delimiter, false );
}).join( "\n" );
}
else {
result += ( prepare( obj, delimiter ) + "\n" );
}
}
else {
if ( header ) {
result = ( array.keys( obj ).join( delimiter ) + "\n" );
}
result += ( array.cast( obj ).map( prepare ).join( delimiter ) + "\n" );
}
return result.replace(/\n$/, "");
} | [
"function",
"(",
"arg",
",",
"delimiter",
",",
"header",
")",
"{",
"delimiter",
"=",
"delimiter",
"||",
"\",\"",
";",
"header",
"=",
"(",
"header",
"!==",
"false",
")",
";",
"var",
"obj",
"=",
"json",
".",
"decode",
"(",
"arg",
",",
"true",
")",
"||",
"arg",
",",
"result",
"=",
"\"\"",
",",
"prepare",
";",
"prepare",
"=",
"function",
"(",
"input",
")",
"{",
"var",
"output",
";",
"if",
"(",
"input",
"instanceof",
"Array",
")",
"{",
"output",
"=",
"\"\\\"\"",
"+",
"\\\"",
"+",
"input",
".",
"toString",
"(",
")",
";",
"\"\\\"\"",
"}",
"else",
"\\\"",
"if",
"(",
"regex",
".",
"object_type",
".",
"test",
"(",
"output",
")",
")",
"{",
"output",
"=",
"\"\\\"\"",
"+",
"\\\"",
"+",
"json",
".",
"csv",
"(",
"input",
",",
"delimiter",
")",
";",
"}",
"}",
";",
"\"\\\"\"",
"\\\"",
"}"
] | Transforms JSON to CSV
@method csv
@param {String} arg JSON string to transform
@param {String} delimiter [Optional] Character to separate fields
@param {Boolean} header [Optional] False to not include field names as first row
@return {String} CSV string | [
"Transforms",
"JSON",
"to",
"CSV"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L6200-L6255 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( arg, silent ) {
try {
return JSON.parse( arg );
}
catch ( e ) {
if ( silent !== true ) {
utility.error( e, arguments, this );
}
return undefined;
}
} | javascript | function ( arg, silent ) {
try {
return JSON.parse( arg );
}
catch ( e ) {
if ( silent !== true ) {
utility.error( e, arguments, this );
}
return undefined;
}
} | [
"function",
"(",
"arg",
",",
"silent",
")",
"{",
"try",
"{",
"return",
"JSON",
".",
"parse",
"(",
"arg",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"if",
"(",
"silent",
"!==",
"true",
")",
"{",
"utility",
".",
"error",
"(",
"e",
",",
"arguments",
",",
"this",
")",
";",
"}",
"return",
"undefined",
";",
"}",
"}"
] | Decodes the argument
@method decode
@param {String} arg String to parse
@param {Boolean} silent [Optional] Silently fail
@return {Mixed} Entity resulting from parsing JSON, or undefined | [
"Decodes",
"the",
"argument"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L6265-L6276 | train |
|
avoidwork/abaaso | lib/abaaso.js | LRU | function LRU ( max ) {
this.cache = {};
this.max = max || 1000;
this.first = null;
this.last = null;
this.length = 0;
} | javascript | function LRU ( max ) {
this.cache = {};
this.max = max || 1000;
this.first = null;
this.last = null;
this.length = 0;
} | [
"function",
"LRU",
"(",
"max",
")",
"{",
"this",
".",
"cache",
"=",
"{",
"}",
";",
"this",
".",
"max",
"=",
"max",
"||",
"1000",
";",
"this",
".",
"first",
"=",
"null",
";",
"this",
".",
"last",
"=",
"null",
";",
"this",
".",
"length",
"=",
"0",
";",
"}"
] | Least Recently Used cache
@constructor
@param {Number} max [Optional] Max size of cache, default is 1000 | [
"Least",
"Recently",
"Used",
"cache"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L6412-L6418 | train |
avoidwork/abaaso | lib/abaaso.js | function () {
var a = array.cast( arguments ),
t = a.pop(),
P = array.chunk( a, 2 ),
n = P.length,
c, S0, Q0, Q1, Q2, C0, C1, C2, C3;
if ( n < 2 || n > 4 ) {
throw new Error( label.error.invalidArguments );
}
// Setting variables
c = [];
S0 = 1 - t;
Q0 = math.sqr( S0 );
Q1 = 2 * S0 * t;
Q2 = math.sqr( t );
C0 = Math.pow( S0, 3 );
C1 = 3 * Q0 * t;
C2 = 3 * S0 * Q2;
C3 = Math.pow( t, 3 );
// Straight
if ( n === 2 ) {
c.push( ( S0 * P[0][0] ) + ( t * P[1][0] ) );
c.push( ( S0 * P[0][1] ) + ( t * P[1][1] ) );
}
// Quadratic
else if ( n === 3 ) {
c.push( ( Q0 * P[0][0] ) + ( Q1 * P[1][0] ) + ( Q2 + P[2][0] ) );
c.push( ( Q0 * P[0][1] ) + ( Q1 * P[1][1] ) + ( Q2 + P[2][1] ) );
}
// Cubic
else if ( n === 4 ) {
c.push( ( C0 * P[0][0] ) + ( C1 * P[1][0] ) + ( C2 * P[2][0] ) + ( C3 * P[3][0] ) );
c.push( ( C0 * P[0][1] ) + ( C1 * P[1][1] ) + ( C2 * P[2][1] ) + ( C3 * P[3][1] ) );
}
return c;
} | javascript | function () {
var a = array.cast( arguments ),
t = a.pop(),
P = array.chunk( a, 2 ),
n = P.length,
c, S0, Q0, Q1, Q2, C0, C1, C2, C3;
if ( n < 2 || n > 4 ) {
throw new Error( label.error.invalidArguments );
}
// Setting variables
c = [];
S0 = 1 - t;
Q0 = math.sqr( S0 );
Q1 = 2 * S0 * t;
Q2 = math.sqr( t );
C0 = Math.pow( S0, 3 );
C1 = 3 * Q0 * t;
C2 = 3 * S0 * Q2;
C3 = Math.pow( t, 3 );
// Straight
if ( n === 2 ) {
c.push( ( S0 * P[0][0] ) + ( t * P[1][0] ) );
c.push( ( S0 * P[0][1] ) + ( t * P[1][1] ) );
}
// Quadratic
else if ( n === 3 ) {
c.push( ( Q0 * P[0][0] ) + ( Q1 * P[1][0] ) + ( Q2 + P[2][0] ) );
c.push( ( Q0 * P[0][1] ) + ( Q1 * P[1][1] ) + ( Q2 + P[2][1] ) );
}
// Cubic
else if ( n === 4 ) {
c.push( ( C0 * P[0][0] ) + ( C1 * P[1][0] ) + ( C2 * P[2][0] ) + ( C3 * P[3][0] ) );
c.push( ( C0 * P[0][1] ) + ( C1 * P[1][1] ) + ( C2 * P[2][1] ) + ( C3 * P[3][1] ) );
}
return c;
} | [
"function",
"(",
")",
"{",
"var",
"a",
"=",
"array",
".",
"cast",
"(",
"arguments",
")",
",",
"t",
"=",
"a",
".",
"pop",
"(",
")",
",",
"P",
"=",
"array",
".",
"chunk",
"(",
"a",
",",
"2",
")",
",",
"n",
"=",
"P",
".",
"length",
",",
"c",
",",
"S0",
",",
"Q0",
",",
"Q1",
",",
"Q2",
",",
"C0",
",",
"C1",
",",
"C2",
",",
"C3",
";",
"if",
"(",
"n",
"<",
"2",
"||",
"n",
">",
"4",
")",
"{",
"throw",
"new",
"Error",
"(",
"label",
".",
"error",
".",
"invalidArguments",
")",
";",
"}",
"c",
"=",
"[",
"]",
";",
"S0",
"=",
"1",
"-",
"t",
";",
"Q0",
"=",
"math",
".",
"sqr",
"(",
"S0",
")",
";",
"Q1",
"=",
"2",
"*",
"S0",
"*",
"t",
";",
"Q2",
"=",
"math",
".",
"sqr",
"(",
"t",
")",
";",
"C0",
"=",
"Math",
".",
"pow",
"(",
"S0",
",",
"3",
")",
";",
"C1",
"=",
"3",
"*",
"Q0",
"*",
"t",
";",
"C2",
"=",
"3",
"*",
"S0",
"*",
"Q2",
";",
"C3",
"=",
"Math",
".",
"pow",
"(",
"t",
",",
"3",
")",
";",
"if",
"(",
"n",
"===",
"2",
")",
"{",
"c",
".",
"push",
"(",
"(",
"S0",
"*",
"P",
"[",
"0",
"]",
"[",
"0",
"]",
")",
"+",
"(",
"t",
"*",
"P",
"[",
"1",
"]",
"[",
"0",
"]",
")",
")",
";",
"c",
".",
"push",
"(",
"(",
"S0",
"*",
"P",
"[",
"0",
"]",
"[",
"1",
"]",
")",
"+",
"(",
"t",
"*",
"P",
"[",
"1",
"]",
"[",
"1",
"]",
")",
")",
";",
"}",
"else",
"if",
"(",
"n",
"===",
"3",
")",
"{",
"c",
".",
"push",
"(",
"(",
"Q0",
"*",
"P",
"[",
"0",
"]",
"[",
"0",
"]",
")",
"+",
"(",
"Q1",
"*",
"P",
"[",
"1",
"]",
"[",
"0",
"]",
")",
"+",
"(",
"Q2",
"+",
"P",
"[",
"2",
"]",
"[",
"0",
"]",
")",
")",
";",
"c",
".",
"push",
"(",
"(",
"Q0",
"*",
"P",
"[",
"0",
"]",
"[",
"1",
"]",
")",
"+",
"(",
"Q1",
"*",
"P",
"[",
"1",
"]",
"[",
"1",
"]",
")",
"+",
"(",
"Q2",
"+",
"P",
"[",
"2",
"]",
"[",
"1",
"]",
")",
")",
";",
"}",
"else",
"if",
"(",
"n",
"===",
"4",
")",
"{",
"c",
".",
"push",
"(",
"(",
"C0",
"*",
"P",
"[",
"0",
"]",
"[",
"0",
"]",
")",
"+",
"(",
"C1",
"*",
"P",
"[",
"1",
"]",
"[",
"0",
"]",
")",
"+",
"(",
"C2",
"*",
"P",
"[",
"2",
"]",
"[",
"0",
"]",
")",
"+",
"(",
"C3",
"*",
"P",
"[",
"3",
"]",
"[",
"0",
"]",
")",
")",
";",
"c",
".",
"push",
"(",
"(",
"C0",
"*",
"P",
"[",
"0",
"]",
"[",
"1",
"]",
")",
"+",
"(",
"C1",
"*",
"P",
"[",
"1",
"]",
"[",
"1",
"]",
")",
"+",
"(",
"C2",
"*",
"P",
"[",
"2",
"]",
"[",
"1",
"]",
")",
"+",
"(",
"C3",
"*",
"P",
"[",
"3",
"]",
"[",
"1",
"]",
")",
")",
";",
"}",
"return",
"c",
";",
"}"
] | Generates bezier curve coordinates for up to 4 points, last parameter is `t`
Two point example: (0, 10, 0, 0, 1) means move straight up
@method bezier
@return {Array} Coordinates | [
"Generates",
"bezier",
"curve",
"coordinates",
"for",
"up",
"to",
"4",
"points",
"last",
"parameter",
"is",
"t"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L6555-L6594 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( a, b ) {
return Math.sqrt( math.sqr( b[0] - a[0] ) + math.sqr( b[1] - a[1] ) );
} | javascript | function ( a, b ) {
return Math.sqrt( math.sqr( b[0] - a[0] ) + math.sqr( b[1] - a[1] ) );
} | [
"function",
"(",
"a",
",",
"b",
")",
"{",
"return",
"Math",
".",
"sqrt",
"(",
"math",
".",
"sqr",
"(",
"b",
"[",
"0",
"]",
"-",
"a",
"[",
"0",
"]",
")",
"+",
"math",
".",
"sqr",
"(",
"b",
"[",
"1",
"]",
"-",
"a",
"[",
"1",
"]",
")",
")",
";",
"}"
] | Finds the distance between 2 Arrays of coordinates
@method dist
@param {Array} a Coordinates [x, y]
@param {Array} b Coordinates [x, y]
@return {Number} Distance between `a` & `b` | [
"Finds",
"the",
"distance",
"between",
"2",
"Arrays",
"of",
"coordinates"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L6604-L6606 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( target, arg ) {
try {
target.postMessage( arg, "*" );
}
catch ( e ) {
utility.error( e, arguments, this );
}
return target;
} | javascript | function ( target, arg ) {
try {
target.postMessage( arg, "*" );
}
catch ( e ) {
utility.error( e, arguments, this );
}
return target;
} | [
"function",
"(",
"target",
",",
"arg",
")",
"{",
"try",
"{",
"target",
".",
"postMessage",
"(",
"arg",
",",
"\"*\"",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"utility",
".",
"error",
"(",
"e",
",",
"arguments",
",",
"this",
")",
";",
"}",
"return",
"target",
";",
"}"
] | Posts a message to the target
@method send
@param {Object} target Object to receive message
@param {Mixed} arg Entity to send as message
@return {Object} target | [
"Posts",
"a",
"message",
"to",
"the",
"target"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L6642-L6651 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( fn, state ) {
state = state || "all";
return observer.add( global, "message", fn, "message", global, state );
} | javascript | function ( fn, state ) {
state = state || "all";
return observer.add( global, "message", fn, "message", global, state );
} | [
"function",
"(",
"fn",
",",
"state",
")",
"{",
"state",
"=",
"state",
"||",
"\"all\"",
";",
"return",
"observer",
".",
"add",
"(",
"global",
",",
"\"message\"",
",",
"fn",
",",
"\"message\"",
",",
"global",
",",
"state",
")",
";",
"}"
] | Sets a handler for recieving a message
@method recv
@param {Function} fn Callback function
@return {Object} abaaso | [
"Sets",
"a",
"handler",
"for",
"recieving",
"a",
"message"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L6660-L6664 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( arg ) {
var type = typeof arg;
if ( type === "object" ) {
var v = document[mouse.view],
x = arg.pageX ? arg.pageX : ( v.scrollLeft + arg.clientX ),
y = arg.pageY ? arg.pageY : ( v.scrollTop + arg.clientY ),
c = false;
if ( mouse.pos.x !== x ) {
c = true;
}
$.mouse.prev.x = mouse.prev.x = number.parse( mouse.pos.x, 10 );
$.mouse.pos.x = mouse.pos.x = x;
$.mouse.diff.x = mouse.diff.x = mouse.pos.x - mouse.prev.x;
if ( mouse.pos.y !== y ) {
c = true;
}
$.mouse.prev.y = mouse.prev.y = number.parse( mouse.pos.y, 10 );
$.mouse.pos.y = mouse.pos.y = y;
$.mouse.diff.y = mouse.diff.y = mouse.pos.y - mouse.prev.y;
if ( c && $.mouse.log ) {
utility.log( [mouse.pos.x, mouse.pos.y, mouse.diff.x, mouse.diff.y] );
}
}
else if ( type === "boolean" ) {
arg ? observer.add( document, "mousemove", mouse.track, "tracking" ) : observer.remove( document, "mousemove", "tracking" );
$.mouse.enabled = mouse.enabled = arg;
}
return $.mouse;
} | javascript | function ( arg ) {
var type = typeof arg;
if ( type === "object" ) {
var v = document[mouse.view],
x = arg.pageX ? arg.pageX : ( v.scrollLeft + arg.clientX ),
y = arg.pageY ? arg.pageY : ( v.scrollTop + arg.clientY ),
c = false;
if ( mouse.pos.x !== x ) {
c = true;
}
$.mouse.prev.x = mouse.prev.x = number.parse( mouse.pos.x, 10 );
$.mouse.pos.x = mouse.pos.x = x;
$.mouse.diff.x = mouse.diff.x = mouse.pos.x - mouse.prev.x;
if ( mouse.pos.y !== y ) {
c = true;
}
$.mouse.prev.y = mouse.prev.y = number.parse( mouse.pos.y, 10 );
$.mouse.pos.y = mouse.pos.y = y;
$.mouse.diff.y = mouse.diff.y = mouse.pos.y - mouse.prev.y;
if ( c && $.mouse.log ) {
utility.log( [mouse.pos.x, mouse.pos.y, mouse.diff.x, mouse.diff.y] );
}
}
else if ( type === "boolean" ) {
arg ? observer.add( document, "mousemove", mouse.track, "tracking" ) : observer.remove( document, "mousemove", "tracking" );
$.mouse.enabled = mouse.enabled = arg;
}
return $.mouse;
} | [
"function",
"(",
"arg",
")",
"{",
"var",
"type",
"=",
"typeof",
"arg",
";",
"if",
"(",
"type",
"===",
"\"object\"",
")",
"{",
"var",
"v",
"=",
"document",
"[",
"mouse",
".",
"view",
"]",
",",
"x",
"=",
"arg",
".",
"pageX",
"?",
"arg",
".",
"pageX",
":",
"(",
"v",
".",
"scrollLeft",
"+",
"arg",
".",
"clientX",
")",
",",
"y",
"=",
"arg",
".",
"pageY",
"?",
"arg",
".",
"pageY",
":",
"(",
"v",
".",
"scrollTop",
"+",
"arg",
".",
"clientY",
")",
",",
"c",
"=",
"false",
";",
"if",
"(",
"mouse",
".",
"pos",
".",
"x",
"!==",
"x",
")",
"{",
"c",
"=",
"true",
";",
"}",
"$",
".",
"mouse",
".",
"prev",
".",
"x",
"=",
"mouse",
".",
"prev",
".",
"x",
"=",
"number",
".",
"parse",
"(",
"mouse",
".",
"pos",
".",
"x",
",",
"10",
")",
";",
"$",
".",
"mouse",
".",
"pos",
".",
"x",
"=",
"mouse",
".",
"pos",
".",
"x",
"=",
"x",
";",
"$",
".",
"mouse",
".",
"diff",
".",
"x",
"=",
"mouse",
".",
"diff",
".",
"x",
"=",
"mouse",
".",
"pos",
".",
"x",
"-",
"mouse",
".",
"prev",
".",
"x",
";",
"if",
"(",
"mouse",
".",
"pos",
".",
"y",
"!==",
"y",
")",
"{",
"c",
"=",
"true",
";",
"}",
"$",
".",
"mouse",
".",
"prev",
".",
"y",
"=",
"mouse",
".",
"prev",
".",
"y",
"=",
"number",
".",
"parse",
"(",
"mouse",
".",
"pos",
".",
"y",
",",
"10",
")",
";",
"$",
".",
"mouse",
".",
"pos",
".",
"y",
"=",
"mouse",
".",
"pos",
".",
"y",
"=",
"y",
";",
"$",
".",
"mouse",
".",
"diff",
".",
"y",
"=",
"mouse",
".",
"diff",
".",
"y",
"=",
"mouse",
".",
"pos",
".",
"y",
"-",
"mouse",
".",
"prev",
".",
"y",
";",
"if",
"(",
"c",
"&&",
"$",
".",
"mouse",
".",
"log",
")",
"{",
"utility",
".",
"log",
"(",
"[",
"mouse",
".",
"pos",
".",
"x",
",",
"mouse",
".",
"pos",
".",
"y",
",",
"mouse",
".",
"diff",
".",
"x",
",",
"mouse",
".",
"diff",
".",
"y",
"]",
")",
";",
"}",
"}",
"else",
"if",
"(",
"type",
"===",
"\"boolean\"",
")",
"{",
"arg",
"?",
"observer",
".",
"add",
"(",
"document",
",",
"\"mousemove\"",
",",
"mouse",
".",
"track",
",",
"\"tracking\"",
")",
":",
"observer",
".",
"remove",
"(",
"document",
",",
"\"mousemove\"",
",",
"\"tracking\"",
")",
";",
"$",
".",
"mouse",
".",
"enabled",
"=",
"mouse",
".",
"enabled",
"=",
"arg",
";",
"}",
"return",
"$",
".",
"mouse",
";",
"}"
] | Enables or disables mouse co-ordinate tracking
@method track
@param {Mixed} arg Boolean to enable/disable tracking, or Mouse Event
@return {Object} $.mouse | [
"Enables",
"or",
"disables",
"mouse",
"co",
"-",
"ordinate",
"tracking"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L6692-L6727 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( num1, num2 ) {
if ( isNaN( num1 ) || isNaN( num2 ) ) {
throw new Error( label.error.expectedNumber );
}
return Math.abs( num1 - num2 );
} | javascript | function ( num1, num2 ) {
if ( isNaN( num1 ) || isNaN( num2 ) ) {
throw new Error( label.error.expectedNumber );
}
return Math.abs( num1 - num2 );
} | [
"function",
"(",
"num1",
",",
"num2",
")",
"{",
"if",
"(",
"isNaN",
"(",
"num1",
")",
"||",
"isNaN",
"(",
"num2",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"label",
".",
"error",
".",
"expectedNumber",
")",
";",
"}",
"return",
"Math",
".",
"abs",
"(",
"num1",
"-",
"num2",
")",
";",
"}"
] | Returns the difference of arg
@method odd
@param {Number} arg Number to compare
@return {Number} The absolute difference | [
"Returns",
"the",
"difference",
"of",
"arg"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L6739-L6745 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( arg, delimiter, every ) {
if ( isNaN( arg ) ) {
throw new Error( label.error.expectedNumber );
}
arg = arg.toString();
delimiter = delimiter || ",";
every = every || 3;
var d = arg.indexOf( "." ) > -1 ? "." + arg.replace( regex.number_format_1, "" ) : "",
a = arg.replace( regex.number_format_2, "" ).split( "" ).reverse(),
p = Math.floor( a.length / every ),
i = 1, n, b;
for ( b = 0; b < p; b++ ) {
n = i === 1 ? every : ( every * i ) + ( i === 2 ? 1 : ( i - 1 ) );
a.splice( n, 0, delimiter );
i++;
}
a = a.reverse().join( "" );
if ( a.charAt( 0 ) === delimiter ) {
a = a.substring( 1 );
}
return a + d;
} | javascript | function ( arg, delimiter, every ) {
if ( isNaN( arg ) ) {
throw new Error( label.error.expectedNumber );
}
arg = arg.toString();
delimiter = delimiter || ",";
every = every || 3;
var d = arg.indexOf( "." ) > -1 ? "." + arg.replace( regex.number_format_1, "" ) : "",
a = arg.replace( regex.number_format_2, "" ).split( "" ).reverse(),
p = Math.floor( a.length / every ),
i = 1, n, b;
for ( b = 0; b < p; b++ ) {
n = i === 1 ? every : ( every * i ) + ( i === 2 ? 1 : ( i - 1 ) );
a.splice( n, 0, delimiter );
i++;
}
a = a.reverse().join( "" );
if ( a.charAt( 0 ) === delimiter ) {
a = a.substring( 1 );
}
return a + d;
} | [
"function",
"(",
"arg",
",",
"delimiter",
",",
"every",
")",
"{",
"if",
"(",
"isNaN",
"(",
"arg",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"label",
".",
"error",
".",
"expectedNumber",
")",
";",
"}",
"arg",
"=",
"arg",
".",
"toString",
"(",
")",
";",
"delimiter",
"=",
"delimiter",
"||",
"\",\"",
";",
"every",
"=",
"every",
"||",
"3",
";",
"var",
"d",
"=",
"arg",
".",
"indexOf",
"(",
"\".\"",
")",
">",
"-",
"1",
"?",
"\".\"",
"+",
"arg",
".",
"replace",
"(",
"regex",
".",
"number_format_1",
",",
"\"\"",
")",
":",
"\"\"",
",",
"a",
"=",
"arg",
".",
"replace",
"(",
"regex",
".",
"number_format_2",
",",
"\"\"",
")",
".",
"split",
"(",
"\"\"",
")",
".",
"reverse",
"(",
")",
",",
"p",
"=",
"Math",
".",
"floor",
"(",
"a",
".",
"length",
"/",
"every",
")",
",",
"i",
"=",
"1",
",",
"n",
",",
"b",
";",
"for",
"(",
"b",
"=",
"0",
";",
"b",
"<",
"p",
";",
"b",
"++",
")",
"{",
"n",
"=",
"i",
"===",
"1",
"?",
"every",
":",
"(",
"every",
"*",
"i",
")",
"+",
"(",
"i",
"===",
"2",
"?",
"1",
":",
"(",
"i",
"-",
"1",
")",
")",
";",
"a",
".",
"splice",
"(",
"n",
",",
"0",
",",
"delimiter",
")",
";",
"i",
"++",
";",
"}",
"a",
"=",
"a",
".",
"reverse",
"(",
")",
".",
"join",
"(",
"\"\"",
")",
";",
"if",
"(",
"a",
".",
"charAt",
"(",
"0",
")",
"===",
"delimiter",
")",
"{",
"a",
"=",
"a",
".",
"substring",
"(",
"1",
")",
";",
"}",
"return",
"a",
"+",
"d",
";",
"}"
] | Formats a Number to a delimited String
@method format
@param {Number} arg Number to format
@param {String} delimiter [Optional] String to delimit the Number with
@param {String} every [Optional] Position to insert the delimiter, default is 3
@return {String} Number represented as a comma delimited String | [
"Formats",
"a",
"Number",
"to",
"a",
"delimited",
"String"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L6767-L6794 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( arg, direction ) {
arg = number.parse( arg );
if ( direction === undefined || string.isEmpty( direction ) ) {
return number.parse( arg.toFixed( 0 ) );
}
else if ( regex.down.test( direction ) ) {
return ~~( arg );
}
else {
return Math.ceil( arg );
}
} | javascript | function ( arg, direction ) {
arg = number.parse( arg );
if ( direction === undefined || string.isEmpty( direction ) ) {
return number.parse( arg.toFixed( 0 ) );
}
else if ( regex.down.test( direction ) ) {
return ~~( arg );
}
else {
return Math.ceil( arg );
}
} | [
"function",
"(",
"arg",
",",
"direction",
")",
"{",
"arg",
"=",
"number",
".",
"parse",
"(",
"arg",
")",
";",
"if",
"(",
"direction",
"===",
"undefined",
"||",
"string",
".",
"isEmpty",
"(",
"direction",
")",
")",
"{",
"return",
"number",
".",
"parse",
"(",
"arg",
".",
"toFixed",
"(",
"0",
")",
")",
";",
"}",
"else",
"if",
"(",
"regex",
".",
"down",
".",
"test",
"(",
"direction",
")",
")",
"{",
"return",
"~",
"~",
"(",
"arg",
")",
";",
"}",
"else",
"{",
"return",
"Math",
".",
"ceil",
"(",
"arg",
")",
";",
"}",
"}"
] | Rounds a number up or down
@method round
@param {Number} arg Number to round
@param {String} direction [Optional] "up" or "down"
@return {Number} Rounded interger | [
"Rounds",
"a",
"number",
"up",
"or",
"down"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L6853-L6865 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj ) {
var methods = [
["fire", function () { return observer.fire.apply( observer, [this].concat( array.cast( arguments ) ) ); }],
["listeners", function ( event ) { return observer.list(this, event ); }],
["on", function ( event, listener, id, scope, standby ) { return observer.add( this, event, listener, id, scope, standby ); }],
["once", function ( event, listener, id, scope, standby ) { return observer.once( this, event, listener, id, scope, standby ); }],
["un", function ( event, id ) { return observer.remove( this, event, id ); }]
];
array.each( methods, function ( i ) {
utility.property( obj, i[0], {value: i[1], configurable: true, enumerable: true, writable: true} );
});
return obj;
} | javascript | function ( obj ) {
var methods = [
["fire", function () { return observer.fire.apply( observer, [this].concat( array.cast( arguments ) ) ); }],
["listeners", function ( event ) { return observer.list(this, event ); }],
["on", function ( event, listener, id, scope, standby ) { return observer.add( this, event, listener, id, scope, standby ); }],
["once", function ( event, listener, id, scope, standby ) { return observer.once( this, event, listener, id, scope, standby ); }],
["un", function ( event, id ) { return observer.remove( this, event, id ); }]
];
array.each( methods, function ( i ) {
utility.property( obj, i[0], {value: i[1], configurable: true, enumerable: true, writable: true} );
});
return obj;
} | [
"function",
"(",
"obj",
")",
"{",
"var",
"methods",
"=",
"[",
"[",
"\"fire\"",
",",
"function",
"(",
")",
"{",
"return",
"observer",
".",
"fire",
".",
"apply",
"(",
"observer",
",",
"[",
"this",
"]",
".",
"concat",
"(",
"array",
".",
"cast",
"(",
"arguments",
")",
")",
")",
";",
"}",
"]",
",",
"[",
"\"listeners\"",
",",
"function",
"(",
"event",
")",
"{",
"return",
"observer",
".",
"list",
"(",
"this",
",",
"event",
")",
";",
"}",
"]",
",",
"[",
"\"on\"",
",",
"function",
"(",
"event",
",",
"listener",
",",
"id",
",",
"scope",
",",
"standby",
")",
"{",
"return",
"observer",
".",
"add",
"(",
"this",
",",
"event",
",",
"listener",
",",
"id",
",",
"scope",
",",
"standby",
")",
";",
"}",
"]",
",",
"[",
"\"once\"",
",",
"function",
"(",
"event",
",",
"listener",
",",
"id",
",",
"scope",
",",
"standby",
")",
"{",
"return",
"observer",
".",
"once",
"(",
"this",
",",
"event",
",",
"listener",
",",
"id",
",",
"scope",
",",
"standby",
")",
";",
"}",
"]",
",",
"[",
"\"un\"",
",",
"function",
"(",
"event",
",",
"id",
")",
"{",
"return",
"observer",
".",
"remove",
"(",
"this",
",",
"event",
",",
"id",
")",
";",
"}",
"]",
"]",
";",
"array",
".",
"each",
"(",
"methods",
",",
"function",
"(",
"i",
")",
"{",
"utility",
".",
"property",
"(",
"obj",
",",
"i",
"[",
"0",
"]",
",",
"{",
"value",
":",
"i",
"[",
"1",
"]",
",",
"configurable",
":",
"true",
",",
"enumerable",
":",
"true",
",",
"writable",
":",
"true",
"}",
")",
";",
"}",
")",
";",
"return",
"obj",
";",
"}"
] | Decorates `obj` with `observer` methods
@method decorate
@param {Object} obj Object to decorate
@return {Object} Object to decorate | [
"Decorates",
"obj",
"with",
"observer",
"methods"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L7019-L7033 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj, event ) {
var quit = false,
a = array.remove( array.cast( arguments ), 0, 1 ),
o, s, log, list;
if ( observer.ignore ) {
return obj;
}
o = observer.id( obj );
if ( o === undefined || event === undefined ) {
throw new Error( label.error.invalidArguments );
}
if ( observer.silent ) {
observer.queue.push( {obj: obj, event: event} );
}
else {
s = state.getCurrent();
log = $.logging;
array.each( string.explode( event ), function ( e ) {
if ( log ) {
utility.log(o + " firing " + e );
}
list = observer.list( obj, e, observer.alisteners );
if ( list.all !== undefined ) {
array.each( list.all, function ( i ) {
var result = i.fn.apply( i.scope, a );
if ( result === false ) {
quit = true;
return result;
}
});
}
if ( !quit && s !== "all" && list[s] !== undefined ) {
array.each( list[s], function ( i ) {
return i.fn.apply( i.scope, a );
});
}
});
}
return obj;
} | javascript | function ( obj, event ) {
var quit = false,
a = array.remove( array.cast( arguments ), 0, 1 ),
o, s, log, list;
if ( observer.ignore ) {
return obj;
}
o = observer.id( obj );
if ( o === undefined || event === undefined ) {
throw new Error( label.error.invalidArguments );
}
if ( observer.silent ) {
observer.queue.push( {obj: obj, event: event} );
}
else {
s = state.getCurrent();
log = $.logging;
array.each( string.explode( event ), function ( e ) {
if ( log ) {
utility.log(o + " firing " + e );
}
list = observer.list( obj, e, observer.alisteners );
if ( list.all !== undefined ) {
array.each( list.all, function ( i ) {
var result = i.fn.apply( i.scope, a );
if ( result === false ) {
quit = true;
return result;
}
});
}
if ( !quit && s !== "all" && list[s] !== undefined ) {
array.each( list[s], function ( i ) {
return i.fn.apply( i.scope, a );
});
}
});
}
return obj;
} | [
"function",
"(",
"obj",
",",
"event",
")",
"{",
"var",
"quit",
"=",
"false",
",",
"a",
"=",
"array",
".",
"remove",
"(",
"array",
".",
"cast",
"(",
"arguments",
")",
",",
"0",
",",
"1",
")",
",",
"o",
",",
"s",
",",
"log",
",",
"list",
";",
"if",
"(",
"observer",
".",
"ignore",
")",
"{",
"return",
"obj",
";",
"}",
"o",
"=",
"observer",
".",
"id",
"(",
"obj",
")",
";",
"if",
"(",
"o",
"===",
"undefined",
"||",
"event",
"===",
"undefined",
")",
"{",
"throw",
"new",
"Error",
"(",
"label",
".",
"error",
".",
"invalidArguments",
")",
";",
"}",
"if",
"(",
"observer",
".",
"silent",
")",
"{",
"observer",
".",
"queue",
".",
"push",
"(",
"{",
"obj",
":",
"obj",
",",
"event",
":",
"event",
"}",
")",
";",
"}",
"else",
"{",
"s",
"=",
"state",
".",
"getCurrent",
"(",
")",
";",
"log",
"=",
"$",
".",
"logging",
";",
"array",
".",
"each",
"(",
"string",
".",
"explode",
"(",
"event",
")",
",",
"function",
"(",
"e",
")",
"{",
"if",
"(",
"log",
")",
"{",
"utility",
".",
"log",
"(",
"o",
"+",
"\" firing \"",
"+",
"e",
")",
";",
"}",
"list",
"=",
"observer",
".",
"list",
"(",
"obj",
",",
"e",
",",
"observer",
".",
"alisteners",
")",
";",
"if",
"(",
"list",
".",
"all",
"!==",
"undefined",
")",
"{",
"array",
".",
"each",
"(",
"list",
".",
"all",
",",
"function",
"(",
"i",
")",
"{",
"var",
"result",
"=",
"i",
".",
"fn",
".",
"apply",
"(",
"i",
".",
"scope",
",",
"a",
")",
";",
"if",
"(",
"result",
"===",
"false",
")",
"{",
"quit",
"=",
"true",
";",
"return",
"result",
";",
"}",
"}",
")",
";",
"}",
"if",
"(",
"!",
"quit",
"&&",
"s",
"!==",
"\"all\"",
"&&",
"list",
"[",
"s",
"]",
"!==",
"undefined",
")",
"{",
"array",
".",
"each",
"(",
"list",
"[",
"s",
"]",
",",
"function",
"(",
"i",
")",
"{",
"return",
"i",
".",
"fn",
".",
"apply",
"(",
"i",
".",
"scope",
",",
"a",
")",
";",
"}",
")",
";",
"}",
"}",
")",
";",
"}",
"return",
"obj",
";",
"}"
] | Fires an event
@method fire
@param {Mixed} obj Primitive
@param {String} event Event, or Events being fired ( comma delimited supported )
@return {Mixed} Primitive | [
"Fires",
"an",
"event"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L7054-L7104 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( arg ) {
var id;
if ( arg === global ) {
id = "window";
}
else if ( !server && arg === document ) {
id = "document";
}
else if ( !server && arg === document.body ) {
id = "body";
}
else {
utility.genId( arg );
id = arg.id || ( typeof arg.toString === "function" ? arg.toString() : arg );
}
return id;
} | javascript | function ( arg ) {
var id;
if ( arg === global ) {
id = "window";
}
else if ( !server && arg === document ) {
id = "document";
}
else if ( !server && arg === document.body ) {
id = "body";
}
else {
utility.genId( arg );
id = arg.id || ( typeof arg.toString === "function" ? arg.toString() : arg );
}
return id;
} | [
"function",
"(",
"arg",
")",
"{",
"var",
"id",
";",
"if",
"(",
"arg",
"===",
"global",
")",
"{",
"id",
"=",
"\"window\"",
";",
"}",
"else",
"if",
"(",
"!",
"server",
"&&",
"arg",
"===",
"document",
")",
"{",
"id",
"=",
"\"document\"",
";",
"}",
"else",
"if",
"(",
"!",
"server",
"&&",
"arg",
"===",
"document",
".",
"body",
")",
"{",
"id",
"=",
"\"body\"",
";",
"}",
"else",
"{",
"utility",
".",
"genId",
"(",
"arg",
")",
";",
"id",
"=",
"arg",
".",
"id",
"||",
"(",
"typeof",
"arg",
".",
"toString",
"===",
"\"function\"",
"?",
"arg",
".",
"toString",
"(",
")",
":",
"arg",
")",
";",
"}",
"return",
"id",
";",
"}"
] | Gets the Observer id of arg
@method id
@param {Mixed} Object or String
@return {String} Observer id | [
"Gets",
"the",
"Observer",
"id",
"of",
"arg"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L7113-L7131 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj, event, target ) {
var l = target || observer.listeners,
o = observer.id( obj ),
r;
if ( l[o] === undefined && event === undefined ) {
r = {};
}
else if ( l[o] !== undefined && ( event === undefined || string.isEmpty( event ) ) ) {
r = l[o];
}
else if ( l[o] !== undefined && l[o][event] !== undefined ) {
r = l[o][event];
}
else {
r = {};
}
return r;
} | javascript | function ( obj, event, target ) {
var l = target || observer.listeners,
o = observer.id( obj ),
r;
if ( l[o] === undefined && event === undefined ) {
r = {};
}
else if ( l[o] !== undefined && ( event === undefined || string.isEmpty( event ) ) ) {
r = l[o];
}
else if ( l[o] !== undefined && l[o][event] !== undefined ) {
r = l[o][event];
}
else {
r = {};
}
return r;
} | [
"function",
"(",
"obj",
",",
"event",
",",
"target",
")",
"{",
"var",
"l",
"=",
"target",
"||",
"observer",
".",
"listeners",
",",
"o",
"=",
"observer",
".",
"id",
"(",
"obj",
")",
",",
"r",
";",
"if",
"(",
"l",
"[",
"o",
"]",
"===",
"undefined",
"&&",
"event",
"===",
"undefined",
")",
"{",
"r",
"=",
"{",
"}",
";",
"}",
"else",
"if",
"(",
"l",
"[",
"o",
"]",
"!==",
"undefined",
"&&",
"(",
"event",
"===",
"undefined",
"||",
"string",
".",
"isEmpty",
"(",
"event",
")",
")",
")",
"{",
"r",
"=",
"l",
"[",
"o",
"]",
";",
"}",
"else",
"if",
"(",
"l",
"[",
"o",
"]",
"!==",
"undefined",
"&&",
"l",
"[",
"o",
"]",
"[",
"event",
"]",
"!==",
"undefined",
")",
"{",
"r",
"=",
"l",
"[",
"o",
"]",
"[",
"event",
"]",
";",
"}",
"else",
"{",
"r",
"=",
"{",
"}",
";",
"}",
"return",
"r",
";",
"}"
] | Gets the listeners for an event
@method list
@param {Mixed} obj Primitive
@param {String} event Event being queried
@param {Object} target [Optional] Listeners collection to access, default is `observer.listeners`
@return {Mixed} Primitive | [
"Gets",
"the",
"listeners",
"for",
"an",
"event"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L7142-L7161 | train |
|
avoidwork/abaaso | lib/abaaso.js | function ( obj, event, fn, id, scope, st ) {
var uuid = id || utility.genId();
scope = scope || obj;
st = st || state.getCurrent();
if ( obj === undefined || event === null || event === undefined || typeof fn !== "function" ) {
throw new Error( label.error.invalidArguments );
}
observer.add( obj, event, function () {
fn.apply( scope, arguments );
observer.remove( obj, event, uuid, st );
}, uuid, scope, st);
return obj;
} | javascript | function ( obj, event, fn, id, scope, st ) {
var uuid = id || utility.genId();
scope = scope || obj;
st = st || state.getCurrent();
if ( obj === undefined || event === null || event === undefined || typeof fn !== "function" ) {
throw new Error( label.error.invalidArguments );
}
observer.add( obj, event, function () {
fn.apply( scope, arguments );
observer.remove( obj, event, uuid, st );
}, uuid, scope, st);
return obj;
} | [
"function",
"(",
"obj",
",",
"event",
",",
"fn",
",",
"id",
",",
"scope",
",",
"st",
")",
"{",
"var",
"uuid",
"=",
"id",
"||",
"utility",
".",
"genId",
"(",
")",
";",
"scope",
"=",
"scope",
"||",
"obj",
";",
"st",
"=",
"st",
"||",
"state",
".",
"getCurrent",
"(",
")",
";",
"if",
"(",
"obj",
"===",
"undefined",
"||",
"event",
"===",
"null",
"||",
"event",
"===",
"undefined",
"||",
"typeof",
"fn",
"!==",
"\"function\"",
")",
"{",
"throw",
"new",
"Error",
"(",
"label",
".",
"error",
".",
"invalidArguments",
")",
";",
"}",
"observer",
".",
"add",
"(",
"obj",
",",
"event",
",",
"function",
"(",
")",
"{",
"fn",
".",
"apply",
"(",
"scope",
",",
"arguments",
")",
";",
"observer",
".",
"remove",
"(",
"obj",
",",
"event",
",",
"uuid",
",",
"st",
")",
";",
"}",
",",
"uuid",
",",
"scope",
",",
"st",
")",
";",
"return",
"obj",
";",
"}"
] | Adds a listener for a single execution
@method once
@param {Mixed} obj Primitive
@param {String} event Event being fired
@param {Function} fn Event handler
@param {String} id [Optional / Recommended] The id for the listener
@param {String} scope [Optional / Recommended] The id of the object or element to be set as 'this'
@param {String} st [Optional] Application state, default is current
@return {Mixed} Primitive | [
"Adds",
"a",
"listener",
"for",
"a",
"single",
"execution"
] | 07c147684bccd28868f377881eb80ffc285cd483 | https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L7175-L7191 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.