id
int32
0
58k
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
list
docstring
stringlengths
4
11.8k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
86
226
36,500
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", ";", "// 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$", "/", ",", "\"\"", ")", ";", "}" ]
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
36,501
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
36,502
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
36,503
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", ")", ";", "}", "// 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", ";", "}" ]
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
36,504
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
36,505
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
36,506
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
36,507
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
36,508
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
36,509
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
36,510
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
36,511
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
36,512
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
36,513
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
36,514
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
36,515
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
36,516
avoidwork/abaaso
lib/abaaso.js
function ( arg ) { if ( arg === true ) { observer.silent = arg; } else if ( arg === false ) { observer.silent = arg; array.each( observer.queue, function ( i ) { observer.fire( i.obj, i.event ); }); observer.queue = []; } return arg; }
javascript
function ( arg ) { if ( arg === true ) { observer.silent = arg; } else if ( arg === false ) { observer.silent = arg; array.each( observer.queue, function ( i ) { observer.fire( i.obj, i.event ); }); observer.queue = []; } return arg; }
[ "function", "(", "arg", ")", "{", "if", "(", "arg", "===", "true", ")", "{", "observer", ".", "silent", "=", "arg", ";", "}", "else", "if", "(", "arg", "===", "false", ")", "{", "observer", ".", "silent", "=", "arg", ";", "array", ".", "each", "(", "observer", ".", "queue", ",", "function", "(", "i", ")", "{", "observer", ".", "fire", "(", "i", ".", "obj", ",", "i", ".", "event", ")", ";", "}", ")", ";", "observer", ".", "queue", "=", "[", "]", ";", "}", "return", "arg", ";", "}" ]
Pauses observer events, and queues them @method pause @param {Boolean} arg Boolean indicating if events will be queued @return {Boolean} Current setting
[ "Pauses", "observer", "events", "and", "queues", "them" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L7200-L7215
36,517
avoidwork/abaaso
lib/abaaso.js
function ( obj ) { return obj ? observer.clisteners[observer.id( obj )] : array.keys( observer.clisteners ).length; }
javascript
function ( obj ) { return obj ? observer.clisteners[observer.id( obj )] : array.keys( observer.clisteners ).length; }
[ "function", "(", "obj", ")", "{", "return", "obj", "?", "observer", ".", "clisteners", "[", "observer", ".", "id", "(", "obj", ")", "]", ":", "array", ".", "keys", "(", "observer", ".", "clisteners", ")", ".", "length", ";", "}" ]
Returns the sum of active listeners for one or all Objects @method sum @param {Mixed} obj [Optional] Entity @return {Object} Object with total listeners per event
[ "Returns", "the", "sum", "of", "active", "listeners", "for", "one", "or", "all", "Objects" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L7312-L7314
36,518
avoidwork/abaaso
lib/abaaso.js
function ( obj, event, st ) { observer.alisteners[obj][event][st] = array.cast( observer.listeners[obj][event][st] ); }
javascript
function ( obj, event, st ) { observer.alisteners[obj][event][st] = array.cast( observer.listeners[obj][event][st] ); }
[ "function", "(", "obj", ",", "event", ",", "st", ")", "{", "observer", ".", "alisteners", "[", "obj", "]", "[", "event", "]", "[", "st", "]", "=", "array", ".", "cast", "(", "observer", ".", "listeners", "[", "obj", "]", "[", "event", "]", "[", "st", "]", ")", ";", "}" ]
Syncs `alisteners` with `listeners` @method sync @param {String} obj Object ID @param {String} event Event @param {String} st Application state @return {Undefined} undefined
[ "Syncs", "alisteners", "with", "listeners" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L7325-L7327
36,519
avoidwork/abaaso
lib/abaaso.js
function ( obj, all ) { all = ( all === true ); var result; if ( all ) { result = string.explode( obj, " " ).map( function ( i ) { return i.charAt( 0 ).toUpperCase() + i.slice( 1 ); }).join(" "); } else { result = obj.charAt( 0 ).toUpperCase() + obj.slice( 1 ); } return result; }
javascript
function ( obj, all ) { all = ( all === true ); var result; if ( all ) { result = string.explode( obj, " " ).map( function ( i ) { return i.charAt( 0 ).toUpperCase() + i.slice( 1 ); }).join(" "); } else { result = obj.charAt( 0 ).toUpperCase() + obj.slice( 1 ); } return result; }
[ "function", "(", "obj", ",", "all", ")", "{", "all", "=", "(", "all", "===", "true", ")", ";", "var", "result", ";", "if", "(", "all", ")", "{", "result", "=", "string", ".", "explode", "(", "obj", ",", "\" \"", ")", ".", "map", "(", "function", "(", "i", ")", "{", "return", "i", ".", "charAt", "(", "0", ")", ".", "toUpperCase", "(", ")", "+", "i", ".", "slice", "(", "1", ")", ";", "}", ")", ".", "join", "(", "\" \"", ")", ";", "}", "else", "{", "result", "=", "obj", ".", "charAt", "(", "0", ")", ".", "toUpperCase", "(", ")", "+", "obj", ".", "slice", "(", "1", ")", ";", "}", "return", "result", ";", "}" ]
Capitalizes the String @method capitalize @param {String} obj String to capitalize @param {Boolean} all [Optional] Capitalize each word @return {String} Capitalized String
[ "Capitalizes", "the", "String" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L8666-L8681
36,520
avoidwork/abaaso
lib/abaaso.js
function ( obj, camel ) { var result = string.trim( obj ).replace( /\s+/g, "-" ); if ( camel === true ) { result = result.replace( /([A-Z])/g, "-$1" ).toLowerCase(); } return result; }
javascript
function ( obj, camel ) { var result = string.trim( obj ).replace( /\s+/g, "-" ); if ( camel === true ) { result = result.replace( /([A-Z])/g, "-$1" ).toLowerCase(); } return result; }
[ "function", "(", "obj", ",", "camel", ")", "{", "var", "result", "=", "string", ".", "trim", "(", "obj", ")", ".", "replace", "(", "/", "\\s+", "/", "g", ",", "\"-\"", ")", ";", "if", "(", "camel", "===", "true", ")", "{", "result", "=", "result", ".", "replace", "(", "/", "([A-Z])", "/", "g", ",", "\"-$1\"", ")", ".", "toLowerCase", "(", ")", ";", "}", "return", "result", ";", "}" ]
Replaces all spaces in a string with dashes @method hyphenate @param {String} obj String to hyphenate @param {Boolean} camel [Optional] Hyphenate camelCase @return {String} String with dashes instead of spaces
[ "Replaces", "all", "spaces", "in", "a", "string", "with", "dashes" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L8716-L8724
36,521
avoidwork/abaaso
lib/abaaso.js
function ( obj ) { return obj.replace( /oe?s$/, "o" ).replace( /ies$/, "y" ).replace( /ses$/, "se" ).replace( /s$/, "" ); }
javascript
function ( obj ) { return obj.replace( /oe?s$/, "o" ).replace( /ies$/, "y" ).replace( /ses$/, "se" ).replace( /s$/, "" ); }
[ "function", "(", "obj", ")", "{", "return", "obj", ".", "replace", "(", "/", "oe?s$", "/", ",", "\"o\"", ")", ".", "replace", "(", "/", "ies$", "/", ",", "\"y\"", ")", ".", "replace", "(", "/", "ses$", "/", ",", "\"se\"", ")", ".", "replace", "(", "/", "s$", "/", ",", "\"\"", ")", ";", "}" ]
Returns singular form of the string @method singular @param {String} obj String to transform @return {String} Transformed string
[ "Returns", "singular", "form", "of", "the", "string" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L8854-L8856
36,522
avoidwork/abaaso
lib/abaaso.js
function ( obj ) { var s = string.trim( obj ).replace( /\.|_|-|\@|\[|\]|\(|\)|\#|\$|\%|\^|\&|\*|\s+/g, " " ).toLowerCase().split( regex.space_hyphen ), r = []; array.each( s, function ( i, idx ) { r.push( idx === 0 ? i : string.capitalize( i ) ); }); return r.join( "" ); }
javascript
function ( obj ) { var s = string.trim( obj ).replace( /\.|_|-|\@|\[|\]|\(|\)|\#|\$|\%|\^|\&|\*|\s+/g, " " ).toLowerCase().split( regex.space_hyphen ), r = []; array.each( s, function ( i, idx ) { r.push( idx === 0 ? i : string.capitalize( i ) ); }); return r.join( "" ); }
[ "function", "(", "obj", ")", "{", "var", "s", "=", "string", ".", "trim", "(", "obj", ")", ".", "replace", "(", "/", "\\.|_|-|\\@|\\[|\\]|\\(|\\)|\\#|\\$|\\%|\\^|\\&|\\*|\\s+", "/", "g", ",", "\" \"", ")", ".", "toLowerCase", "(", ")", ".", "split", "(", "regex", ".", "space_hyphen", ")", ",", "r", "=", "[", "]", ";", "array", ".", "each", "(", "s", ",", "function", "(", "i", ",", "idx", ")", "{", "r", ".", "push", "(", "idx", "===", "0", "?", "i", ":", "string", ".", "capitalize", "(", "i", ")", ")", ";", "}", ")", ";", "return", "r", ".", "join", "(", "\"\"", ")", ";", "}" ]
Transforms the case of a String into CamelCase @method toCamelCase @param {String} obj String to capitalize @return {String} Camel case String
[ "Transforms", "the", "case", "of", "a", "String", "into", "CamelCase" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L8865-L8874
36,523
avoidwork/abaaso
lib/abaaso.js
function ( obj ) { obj = string.trim( obj ); return obj.charAt( 0 ).toLowerCase() + obj.slice( 1 ); }
javascript
function ( obj ) { obj = string.trim( obj ); return obj.charAt( 0 ).toLowerCase() + obj.slice( 1 ); }
[ "function", "(", "obj", ")", "{", "obj", "=", "string", ".", "trim", "(", "obj", ")", ";", "return", "obj", ".", "charAt", "(", "0", ")", ".", "toLowerCase", "(", ")", "+", "obj", ".", "slice", "(", "1", ")", ";", "}" ]
Uncapitalizes the String @method uncapitalize @param {String} obj String to uncapitalize @return {String} Uncapitalized String
[ "Uncapitalizes", "the", "String" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L8905-L8909
36,524
avoidwork/abaaso
lib/abaaso.js
function ( obj, caps ) { if ( caps !== true ) { return string.explode( obj, "-" ).join( " " ); } else { return string.explode( obj, "-" ).map( function ( i ) { return string.capitalize( i ); }).join( " " ); } }
javascript
function ( obj, caps ) { if ( caps !== true ) { return string.explode( obj, "-" ).join( " " ); } else { return string.explode( obj, "-" ).map( function ( i ) { return string.capitalize( i ); }).join( " " ); } }
[ "function", "(", "obj", ",", "caps", ")", "{", "if", "(", "caps", "!==", "true", ")", "{", "return", "string", ".", "explode", "(", "obj", ",", "\"-\"", ")", ".", "join", "(", "\" \"", ")", ";", "}", "else", "{", "return", "string", ".", "explode", "(", "obj", ",", "\"-\"", ")", ".", "map", "(", "function", "(", "i", ")", "{", "return", "string", ".", "capitalize", "(", "i", ")", ";", "}", ")", ".", "join", "(", "\" \"", ")", ";", "}", "}" ]
Replaces all hyphens with spaces @method unhyphenate @param {String} obj String to unhypenate @param {Boolean} caps [Optional] True to capitalize each word @return {String} Unhyphenated String
[ "Replaces", "all", "hyphens", "with", "spaces" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L8919-L8928
36,525
avoidwork/abaaso
lib/abaaso.js
function ( arg ) { var result; if ( !arg ) { return; } arg = string.trim( arg ); if ( arg.indexOf( "," ) === -1 ) { result = utility.dom( arg ); } else { result = []; array.each( string.explode( arg ), function ( query ) { var obj = utility.dom( query ); if ( obj instanceof Array ) { result = result.concat( obj ); } else if ( obj ) { result.push( obj ); } }); } return result; }
javascript
function ( arg ) { var result; if ( !arg ) { return; } arg = string.trim( arg ); if ( arg.indexOf( "," ) === -1 ) { result = utility.dom( arg ); } else { result = []; array.each( string.explode( arg ), function ( query ) { var obj = utility.dom( query ); if ( obj instanceof Array ) { result = result.concat( obj ); } else if ( obj ) { result.push( obj ); } }); } return result; }
[ "function", "(", "arg", ")", "{", "var", "result", ";", "if", "(", "!", "arg", ")", "{", "return", ";", "}", "arg", "=", "string", ".", "trim", "(", "arg", ")", ";", "if", "(", "arg", ".", "indexOf", "(", "\",\"", ")", "===", "-", "1", ")", "{", "result", "=", "utility", ".", "dom", "(", "arg", ")", ";", "}", "else", "{", "result", "=", "[", "]", ";", "array", ".", "each", "(", "string", ".", "explode", "(", "arg", ")", ",", "function", "(", "query", ")", "{", "var", "obj", "=", "utility", ".", "dom", "(", "query", ")", ";", "if", "(", "obj", "instanceof", "Array", ")", "{", "result", "=", "result", ".", "concat", "(", "obj", ")", ";", "}", "else", "if", "(", "obj", ")", "{", "result", ".", "push", "(", "obj", ")", ";", "}", "}", ")", ";", "}", "return", "result", ";", "}" ]
Queries the DOM using CSS selectors and returns an Element or Array of Elements @method $ @param {String} arg Comma delimited string of CSS selectors @return {Mixed} Element or Array of Elements
[ "Queries", "the", "DOM", "using", "CSS", "selectors", "and", "returns", "an", "Element", "or", "Array", "of", "Elements" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L8946-L8974
36,526
avoidwork/abaaso
lib/abaaso.js
function ( obj, origin ) { var o = obj, s = origin; utility.iterate( s, function ( v, k ) { var getter, setter; if ( !( v instanceof RegExp ) && typeof v === "function" ) { o[k] = v.bind( o[k] ); } else if ( !(v instanceof RegExp ) && !(v instanceof Array ) && v instanceof Object ) { if ( o[k] === undefined ) { o[k] = {}; } utility.alias( o[k], s[k] ); } else { getter = function () { return s[k]; }; setter = function ( arg ) { s[k] = arg; }; utility.property( o, k, {enumerable: true, get: getter, set: setter, value: s[k]} ); } }); return obj; }
javascript
function ( obj, origin ) { var o = obj, s = origin; utility.iterate( s, function ( v, k ) { var getter, setter; if ( !( v instanceof RegExp ) && typeof v === "function" ) { o[k] = v.bind( o[k] ); } else if ( !(v instanceof RegExp ) && !(v instanceof Array ) && v instanceof Object ) { if ( o[k] === undefined ) { o[k] = {}; } utility.alias( o[k], s[k] ); } else { getter = function () { return s[k]; }; setter = function ( arg ) { s[k] = arg; }; utility.property( o, k, {enumerable: true, get: getter, set: setter, value: s[k]} ); } }); return obj; }
[ "function", "(", "obj", ",", "origin", ")", "{", "var", "o", "=", "obj", ",", "s", "=", "origin", ";", "utility", ".", "iterate", "(", "s", ",", "function", "(", "v", ",", "k", ")", "{", "var", "getter", ",", "setter", ";", "if", "(", "!", "(", "v", "instanceof", "RegExp", ")", "&&", "typeof", "v", "===", "\"function\"", ")", "{", "o", "[", "k", "]", "=", "v", ".", "bind", "(", "o", "[", "k", "]", ")", ";", "}", "else", "if", "(", "!", "(", "v", "instanceof", "RegExp", ")", "&&", "!", "(", "v", "instanceof", "Array", ")", "&&", "v", "instanceof", "Object", ")", "{", "if", "(", "o", "[", "k", "]", "===", "undefined", ")", "{", "o", "[", "k", "]", "=", "{", "}", ";", "}", "utility", ".", "alias", "(", "o", "[", "k", "]", ",", "s", "[", "k", "]", ")", ";", "}", "else", "{", "getter", "=", "function", "(", ")", "{", "return", "s", "[", "k", "]", ";", "}", ";", "setter", "=", "function", "(", "arg", ")", "{", "s", "[", "k", "]", "=", "arg", ";", "}", ";", "utility", ".", "property", "(", "o", ",", "k", ",", "{", "enumerable", ":", "true", ",", "get", ":", "getter", ",", "set", ":", "setter", ",", "value", ":", "s", "[", "k", "]", "}", ")", ";", "}", "}", ")", ";", "return", "obj", ";", "}" ]
Aliases origin onto obj @method alias @param {Object} obj Object receiving aliasing @param {Object} origin Object providing structure to obj @return {Object} Object receiving aliasing
[ "Aliases", "origin", "onto", "obj" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L8984-L9015
36,527
avoidwork/abaaso
lib/abaaso.js
function ( id ) { if ( id === undefined || string.isEmpty( id ) ) { throw new Error( label.error.invalidArguments ); } // deferred if ( utility.timer[id] !== undefined ) { clearTimeout( utility.timer[id] ); delete utility.timer[id]; } // repeating if ( utility.repeating[id] !== undefined ) { clearTimeout( utility.repeating[id] ); delete utility.repeating[id]; } }
javascript
function ( id ) { if ( id === undefined || string.isEmpty( id ) ) { throw new Error( label.error.invalidArguments ); } // deferred if ( utility.timer[id] !== undefined ) { clearTimeout( utility.timer[id] ); delete utility.timer[id]; } // repeating if ( utility.repeating[id] !== undefined ) { clearTimeout( utility.repeating[id] ); delete utility.repeating[id]; } }
[ "function", "(", "id", ")", "{", "if", "(", "id", "===", "undefined", "||", "string", ".", "isEmpty", "(", "id", ")", ")", "{", "throw", "new", "Error", "(", "label", ".", "error", ".", "invalidArguments", ")", ";", "}", "// deferred", "if", "(", "utility", ".", "timer", "[", "id", "]", "!==", "undefined", ")", "{", "clearTimeout", "(", "utility", ".", "timer", "[", "id", "]", ")", ";", "delete", "utility", ".", "timer", "[", "id", "]", ";", "}", "// repeating", "if", "(", "utility", ".", "repeating", "[", "id", "]", "!==", "undefined", ")", "{", "clearTimeout", "(", "utility", ".", "repeating", "[", "id", "]", ")", ";", "delete", "utility", ".", "repeating", "[", "id", "]", ";", "}", "}" ]
Clears deferred & repeating functions @method clearTimers @param {String} id ID of timer( s ) @return {Undefined} undefined
[ "Clears", "deferred", "&", "repeating", "functions" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L9024-L9040
36,528
avoidwork/abaaso
lib/abaaso.js
function ( obj, shallow ) { var clone; if ( shallow === true ) { return json.decode( json.encode( obj ) ); } else if ( !obj || regex.primitive.test( typeof obj ) || ( obj instanceof RegExp ) ) { return obj; } else if ( obj instanceof Array ) { return obj.slice(); } else if ( !server && !client.ie && obj instanceof Document ) { return xml.decode( xml.encode( obj ) ); } else if ( typeof obj.__proto__ !== "undefined" ) { return utility.extend( obj.__proto__, obj ); } else if ( obj instanceof Object ) { // If JSON encoding fails due to recursion, the original Object is returned because it's assumed this is for decoration clone = json.encode( obj, true ); if ( clone !== undefined ) { clone = json.decode( clone ); // Decorating Functions that would be lost with JSON encoding/decoding utility.iterate( obj, function ( v, k ) { if ( typeof v === "function" ) { clone[k] = v; } }); } else { clone = obj; } return clone; } else { return obj; } }
javascript
function ( obj, shallow ) { var clone; if ( shallow === true ) { return json.decode( json.encode( obj ) ); } else if ( !obj || regex.primitive.test( typeof obj ) || ( obj instanceof RegExp ) ) { return obj; } else if ( obj instanceof Array ) { return obj.slice(); } else if ( !server && !client.ie && obj instanceof Document ) { return xml.decode( xml.encode( obj ) ); } else if ( typeof obj.__proto__ !== "undefined" ) { return utility.extend( obj.__proto__, obj ); } else if ( obj instanceof Object ) { // If JSON encoding fails due to recursion, the original Object is returned because it's assumed this is for decoration clone = json.encode( obj, true ); if ( clone !== undefined ) { clone = json.decode( clone ); // Decorating Functions that would be lost with JSON encoding/decoding utility.iterate( obj, function ( v, k ) { if ( typeof v === "function" ) { clone[k] = v; } }); } else { clone = obj; } return clone; } else { return obj; } }
[ "function", "(", "obj", ",", "shallow", ")", "{", "var", "clone", ";", "if", "(", "shallow", "===", "true", ")", "{", "return", "json", ".", "decode", "(", "json", ".", "encode", "(", "obj", ")", ")", ";", "}", "else", "if", "(", "!", "obj", "||", "regex", ".", "primitive", ".", "test", "(", "typeof", "obj", ")", "||", "(", "obj", "instanceof", "RegExp", ")", ")", "{", "return", "obj", ";", "}", "else", "if", "(", "obj", "instanceof", "Array", ")", "{", "return", "obj", ".", "slice", "(", ")", ";", "}", "else", "if", "(", "!", "server", "&&", "!", "client", ".", "ie", "&&", "obj", "instanceof", "Document", ")", "{", "return", "xml", ".", "decode", "(", "xml", ".", "encode", "(", "obj", ")", ")", ";", "}", "else", "if", "(", "typeof", "obj", ".", "__proto__", "!==", "\"undefined\"", ")", "{", "return", "utility", ".", "extend", "(", "obj", ".", "__proto__", ",", "obj", ")", ";", "}", "else", "if", "(", "obj", "instanceof", "Object", ")", "{", "// If JSON encoding fails due to recursion, the original Object is returned because it's assumed this is for decoration", "clone", "=", "json", ".", "encode", "(", "obj", ",", "true", ")", ";", "if", "(", "clone", "!==", "undefined", ")", "{", "clone", "=", "json", ".", "decode", "(", "clone", ")", ";", "// Decorating Functions that would be lost with JSON encoding/decoding", "utility", ".", "iterate", "(", "obj", ",", "function", "(", "v", ",", "k", ")", "{", "if", "(", "typeof", "v", "===", "\"function\"", ")", "{", "clone", "[", "k", "]", "=", "v", ";", "}", "}", ")", ";", "}", "else", "{", "clone", "=", "obj", ";", "}", "return", "clone", ";", "}", "else", "{", "return", "obj", ";", "}", "}" ]
Clones an Object @method clone @param {Object} obj Object to clone @param {Boolean} shallow [Optional] Create a shallow clone, which doesn't maintain prototypes, default is `false` @return {Object} Clone of obj
[ "Clones", "an", "Object" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L9050-L9091
36,529
avoidwork/abaaso
lib/abaaso.js
function ( value ) { var tmp; if ( value === null || value === undefined ) { return undefined; } else if ( value === "true" ) { return true; } else if ( value === "false" ) { return false; } else if ( value === "null" ) { return null; } else if ( value === "undefined" ) { return undefined; } else if ( value === "" ) { return value; } else if ( !isNaN( tmp = Number( value ) ) ) { return tmp; } else if ( regex.json_wrap.test( value ) ) { return json.decode( value, true ) || value; } else { return value; } }
javascript
function ( value ) { var tmp; if ( value === null || value === undefined ) { return undefined; } else if ( value === "true" ) { return true; } else if ( value === "false" ) { return false; } else if ( value === "null" ) { return null; } else if ( value === "undefined" ) { return undefined; } else if ( value === "" ) { return value; } else if ( !isNaN( tmp = Number( value ) ) ) { return tmp; } else if ( regex.json_wrap.test( value ) ) { return json.decode( value, true ) || value; } else { return value; } }
[ "function", "(", "value", ")", "{", "var", "tmp", ";", "if", "(", "value", "===", "null", "||", "value", "===", "undefined", ")", "{", "return", "undefined", ";", "}", "else", "if", "(", "value", "===", "\"true\"", ")", "{", "return", "true", ";", "}", "else", "if", "(", "value", "===", "\"false\"", ")", "{", "return", "false", ";", "}", "else", "if", "(", "value", "===", "\"null\"", ")", "{", "return", "null", ";", "}", "else", "if", "(", "value", "===", "\"undefined\"", ")", "{", "return", "undefined", ";", "}", "else", "if", "(", "value", "===", "\"\"", ")", "{", "return", "value", ";", "}", "else", "if", "(", "!", "isNaN", "(", "tmp", "=", "Number", "(", "value", ")", ")", ")", "{", "return", "tmp", ";", "}", "else", "if", "(", "regex", ".", "json_wrap", ".", "test", "(", "value", ")", ")", "{", "return", "json", ".", "decode", "(", "value", ",", "true", ")", "||", "value", ";", "}", "else", "{", "return", "value", ";", "}", "}" ]
Coerces a String to a Type @method coerce @param {String} value String to coerce @return {Mixed} Primitive version of the String
[ "Coerces", "a", "String", "to", "a", "Type" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L9100-L9130
36,530
avoidwork/abaaso
lib/abaaso.js
function ( content, media ) { var ss, css; ss = element.create( "style", {type: "text/css", media: media || "print, screen"}, utility.$( "head" )[0] ); if ( ss.styleSheet ) { ss.styleSheet.cssText = content; } else { css = document.createTextNode( content ); ss.appendChild( css ); } return ss; }
javascript
function ( content, media ) { var ss, css; ss = element.create( "style", {type: "text/css", media: media || "print, screen"}, utility.$( "head" )[0] ); if ( ss.styleSheet ) { ss.styleSheet.cssText = content; } else { css = document.createTextNode( content ); ss.appendChild( css ); } return ss; }
[ "function", "(", "content", ",", "media", ")", "{", "var", "ss", ",", "css", ";", "ss", "=", "element", ".", "create", "(", "\"style\"", ",", "{", "type", ":", "\"text/css\"", ",", "media", ":", "media", "||", "\"print, screen\"", "}", ",", "utility", ".", "$", "(", "\"head\"", ")", "[", "0", "]", ")", ";", "if", "(", "ss", ".", "styleSheet", ")", "{", "ss", ".", "styleSheet", ".", "cssText", "=", "content", ";", "}", "else", "{", "css", "=", "document", ".", "createTextNode", "(", "content", ")", ";", "ss", ".", "appendChild", "(", "css", ")", ";", "}", "return", "ss", ";", "}" ]
Creates a CSS stylesheet in the View @method css @param {String} content CSS to put in a style tag @param {String} media [Optional] Medias the stylesheet applies to @return {Object} Element created or undefined
[ "Creates", "a", "CSS", "stylesheet", "in", "the", "View" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L9157-L9171
36,531
avoidwork/abaaso
lib/abaaso.js
function ( fn, ms, scope ) { ms = ms || 1000; scope = scope || global; return function debounced () { setTimeout( function () { fn.apply( scope, arguments ); }, ms); }; }
javascript
function ( fn, ms, scope ) { ms = ms || 1000; scope = scope || global; return function debounced () { setTimeout( function () { fn.apply( scope, arguments ); }, ms); }; }
[ "function", "(", "fn", ",", "ms", ",", "scope", ")", "{", "ms", "=", "ms", "||", "1000", ";", "scope", "=", "scope", "||", "global", ";", "return", "function", "debounced", "(", ")", "{", "setTimeout", "(", "function", "(", ")", "{", "fn", ".", "apply", "(", "scope", ",", "arguments", ")", ";", "}", ",", "ms", ")", ";", "}", ";", "}" ]
Debounces a function @method debounce @param {Function} fn Function to execute @param {Number} ms Time to wait to execute in milliseconds, default is 1000 @param {Mixed} scope `this` context during execution, default is `global` @return {Undefined} undefined
[ "Debounces", "a", "function" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L9182-L9191
36,532
avoidwork/abaaso
lib/abaaso.js
function ( args, value, obj ) { args = args.split( "." ); var p = obj, nth = args.length; if ( obj === undefined ) { obj = this; } if ( value === undefined ) { value = null; } array.each( args, function ( i, idx ) { var num = idx + 1 < nth && !isNaN( number.parse( args[idx + 1], 10 ) ), val = value; if ( !isNaN( number.parse( i, 10 ) ) ) { i = number.parse( i, 10 ); } // Creating or casting if ( p[i] === undefined ) { p[i] = num ? [] : {}; } else if ( p[i] instanceof Object && num ) { p[i] = array.cast( p[i] ); } else if ( p[i] instanceof Object ) { // Do nothing } else if ( p[i] instanceof Array && !num ) { p[i] = array.toObject( p[i] ); } else { p[i] = {}; } // Setting reference or value idx + 1 === nth ? p[i] = val : p = p[i]; }); return obj; }
javascript
function ( args, value, obj ) { args = args.split( "." ); var p = obj, nth = args.length; if ( obj === undefined ) { obj = this; } if ( value === undefined ) { value = null; } array.each( args, function ( i, idx ) { var num = idx + 1 < nth && !isNaN( number.parse( args[idx + 1], 10 ) ), val = value; if ( !isNaN( number.parse( i, 10 ) ) ) { i = number.parse( i, 10 ); } // Creating or casting if ( p[i] === undefined ) { p[i] = num ? [] : {}; } else if ( p[i] instanceof Object && num ) { p[i] = array.cast( p[i] ); } else if ( p[i] instanceof Object ) { // Do nothing } else if ( p[i] instanceof Array && !num ) { p[i] = array.toObject( p[i] ); } else { p[i] = {}; } // Setting reference or value idx + 1 === nth ? p[i] = val : p = p[i]; }); return obj; }
[ "function", "(", "args", ",", "value", ",", "obj", ")", "{", "args", "=", "args", ".", "split", "(", "\".\"", ")", ";", "var", "p", "=", "obj", ",", "nth", "=", "args", ".", "length", ";", "if", "(", "obj", "===", "undefined", ")", "{", "obj", "=", "this", ";", "}", "if", "(", "value", "===", "undefined", ")", "{", "value", "=", "null", ";", "}", "array", ".", "each", "(", "args", ",", "function", "(", "i", ",", "idx", ")", "{", "var", "num", "=", "idx", "+", "1", "<", "nth", "&&", "!", "isNaN", "(", "number", ".", "parse", "(", "args", "[", "idx", "+", "1", "]", ",", "10", ")", ")", ",", "val", "=", "value", ";", "if", "(", "!", "isNaN", "(", "number", ".", "parse", "(", "i", ",", "10", ")", ")", ")", "{", "i", "=", "number", ".", "parse", "(", "i", ",", "10", ")", ";", "}", "// Creating or casting", "if", "(", "p", "[", "i", "]", "===", "undefined", ")", "{", "p", "[", "i", "]", "=", "num", "?", "[", "]", ":", "{", "}", ";", "}", "else", "if", "(", "p", "[", "i", "]", "instanceof", "Object", "&&", "num", ")", "{", "p", "[", "i", "]", "=", "array", ".", "cast", "(", "p", "[", "i", "]", ")", ";", "}", "else", "if", "(", "p", "[", "i", "]", "instanceof", "Object", ")", "{", "// Do nothing", "}", "else", "if", "(", "p", "[", "i", "]", "instanceof", "Array", "&&", "!", "num", ")", "{", "p", "[", "i", "]", "=", "array", ".", "toObject", "(", "p", "[", "i", "]", ")", ";", "}", "else", "{", "p", "[", "i", "]", "=", "{", "}", ";", "}", "// Setting reference or value", "idx", "+", "1", "===", "nth", "?", "p", "[", "i", "]", "=", "val", ":", "p", "=", "p", "[", "i", "]", ";", "}", ")", ";", "return", "obj", ";", "}" ]
Allows deep setting of properties without knowing if the structure is valid @method define @param {String} args Dot delimited string of the structure @param {Mixed} value Value to set @param {Object} obj Object receiving value @return {Object} Object receiving value
[ "Allows", "deep", "setting", "of", "properties", "without", "knowing", "if", "the", "structure", "is", "valid" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L9203-L9246
36,533
avoidwork/abaaso
lib/abaaso.js
function ( fn, ms, id, repeat ) { var op; ms = ms || 0; repeat = ( repeat === true ); if ( id !== undefined ) { utility.clearTimers( id ); } else { id = utility.uuid( true ); } op = function () { utility.clearTimers( id ); fn(); }; utility[repeat ? "repeating" : "timer"][id] = setTimeout( op, ms ); return id; }
javascript
function ( fn, ms, id, repeat ) { var op; ms = ms || 0; repeat = ( repeat === true ); if ( id !== undefined ) { utility.clearTimers( id ); } else { id = utility.uuid( true ); } op = function () { utility.clearTimers( id ); fn(); }; utility[repeat ? "repeating" : "timer"][id] = setTimeout( op, ms ); return id; }
[ "function", "(", "fn", ",", "ms", ",", "id", ",", "repeat", ")", "{", "var", "op", ";", "ms", "=", "ms", "||", "0", ";", "repeat", "=", "(", "repeat", "===", "true", ")", ";", "if", "(", "id", "!==", "undefined", ")", "{", "utility", ".", "clearTimers", "(", "id", ")", ";", "}", "else", "{", "id", "=", "utility", ".", "uuid", "(", "true", ")", ";", "}", "op", "=", "function", "(", ")", "{", "utility", ".", "clearTimers", "(", "id", ")", ";", "fn", "(", ")", ";", "}", ";", "utility", "[", "repeat", "?", "\"repeating\"", ":", "\"timer\"", "]", "[", "id", "]", "=", "setTimeout", "(", "op", ",", "ms", ")", ";", "return", "id", ";", "}" ]
Defers the execution of Function by at least the supplied milliseconds Timing may vary under "heavy load" relative to the CPU & client JavaScript engine @method defer @param {Function} fn Function to defer execution of @param {Number} ms Milliseconds to defer execution @param {Number} id [Optional] ID of the deferred function @param {Boolean} repeat [Optional] Describes the execution, default is `false` @return {String} ID of the timer
[ "Defers", "the", "execution", "of", "Function", "by", "at", "least", "the", "supplied", "milliseconds", "Timing", "may", "vary", "under", "heavy", "load", "relative", "to", "the", "CPU", "&", "client", "JavaScript", "engine" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L9259-L9280
36,534
avoidwork/abaaso
lib/abaaso.js
function ( arg ) { var result; if ( !regex.selector_complex.test( arg ) ) { if ( regex.hash.test( arg ) ) { result = document.getElementById( arg.replace( regex.hash, "" ) ) || undefined; } else if ( regex.klass.test( arg ) ) { result = array.cast( document.getElementsByClassName( arg.replace( regex.klass, "" ) ) ); } else if ( regex.word.test( arg ) ) { result = array.cast( document.getElementsByTagName( arg ) ); } else { result = array.cast( document.querySelectorAll( arg ) ); } } else { result = array.cast( document.querySelectorAll( arg ) ); } return result; }
javascript
function ( arg ) { var result; if ( !regex.selector_complex.test( arg ) ) { if ( regex.hash.test( arg ) ) { result = document.getElementById( arg.replace( regex.hash, "" ) ) || undefined; } else if ( regex.klass.test( arg ) ) { result = array.cast( document.getElementsByClassName( arg.replace( regex.klass, "" ) ) ); } else if ( regex.word.test( arg ) ) { result = array.cast( document.getElementsByTagName( arg ) ); } else { result = array.cast( document.querySelectorAll( arg ) ); } } else { result = array.cast( document.querySelectorAll( arg ) ); } return result; }
[ "function", "(", "arg", ")", "{", "var", "result", ";", "if", "(", "!", "regex", ".", "selector_complex", ".", "test", "(", "arg", ")", ")", "{", "if", "(", "regex", ".", "hash", ".", "test", "(", "arg", ")", ")", "{", "result", "=", "document", ".", "getElementById", "(", "arg", ".", "replace", "(", "regex", ".", "hash", ",", "\"\"", ")", ")", "||", "undefined", ";", "}", "else", "if", "(", "regex", ".", "klass", ".", "test", "(", "arg", ")", ")", "{", "result", "=", "array", ".", "cast", "(", "document", ".", "getElementsByClassName", "(", "arg", ".", "replace", "(", "regex", ".", "klass", ",", "\"\"", ")", ")", ")", ";", "}", "else", "if", "(", "regex", ".", "word", ".", "test", "(", "arg", ")", ")", "{", "result", "=", "array", ".", "cast", "(", "document", ".", "getElementsByTagName", "(", "arg", ")", ")", ";", "}", "else", "{", "result", "=", "array", ".", "cast", "(", "document", ".", "querySelectorAll", "(", "arg", ")", ")", ";", "}", "}", "else", "{", "result", "=", "array", ".", "cast", "(", "document", ".", "querySelectorAll", "(", "arg", ")", ")", ";", "}", "return", "result", ";", "}" ]
Queries DOM with fastest method @method dom @param {String} arg DOM query @return {Mixed} undefined, Element, or Array of Elements
[ "Queries", "DOM", "with", "fastest", "method" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L9289-L9311
36,535
avoidwork/abaaso
lib/abaaso.js
function ( e, args, scope, warning ) { warning = ( warning === true ); var o = { "arguments" : args !== undefined ? array.cast( args ) : [], message : e.message || e, number : e.number !== undefined ? ( e.number & 0xFFFF ) : undefined, scope : scope, stack : e.stack || undefined, timestamp : new Date().toUTCString(), type : e.type || "TypeError" }; utility.log( ( o.stack || o.message || o ), !warning ? "error" : "warn" ); utility.error.log.push( o ); observer.fire( abaaso, "error", o ); return undefined; }
javascript
function ( e, args, scope, warning ) { warning = ( warning === true ); var o = { "arguments" : args !== undefined ? array.cast( args ) : [], message : e.message || e, number : e.number !== undefined ? ( e.number & 0xFFFF ) : undefined, scope : scope, stack : e.stack || undefined, timestamp : new Date().toUTCString(), type : e.type || "TypeError" }; utility.log( ( o.stack || o.message || o ), !warning ? "error" : "warn" ); utility.error.log.push( o ); observer.fire( abaaso, "error", o ); return undefined; }
[ "function", "(", "e", ",", "args", ",", "scope", ",", "warning", ")", "{", "warning", "=", "(", "warning", "===", "true", ")", ";", "var", "o", "=", "{", "\"arguments\"", ":", "args", "!==", "undefined", "?", "array", ".", "cast", "(", "args", ")", ":", "[", "]", ",", "message", ":", "e", ".", "message", "||", "e", ",", "number", ":", "e", ".", "number", "!==", "undefined", "?", "(", "e", ".", "number", "&", "0xFFFF", ")", ":", "undefined", ",", "scope", ":", "scope", ",", "stack", ":", "e", ".", "stack", "||", "undefined", ",", "timestamp", ":", "new", "Date", "(", ")", ".", "toUTCString", "(", ")", ",", "type", ":", "e", ".", "type", "||", "\"TypeError\"", "}", ";", "utility", ".", "log", "(", "(", "o", ".", "stack", "||", "o", ".", "message", "||", "o", ")", ",", "!", "warning", "?", "\"error\"", ":", "\"warn\"", ")", ";", "utility", ".", "error", ".", "log", ".", "push", "(", "o", ")", ";", "observer", ".", "fire", "(", "abaaso", ",", "\"error\"", ",", "o", ")", ";", "return", "undefined", ";", "}" ]
Error handling, with history in .log @method error @param {Mixed} e Error object or message to display @param {Array} args Array of arguments from the callstack @param {Mixed} scope Entity that was "this" @param {Boolean} warning [Optional] Will display as console warning if true @return {Undefined} undefined
[ "Error", "handling", "with", "history", "in", ".", "log" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L9334-L9351
36,536
avoidwork/abaaso
lib/abaaso.js
function ( obj, dom ) { dom = ( dom === true ); var id; if ( obj !== undefined && ( ( obj.id !== undefined && obj.id !== "" ) || ( obj instanceof Array ) || ( obj instanceof String || typeof obj === "string" ) ) ) { return obj; } if ( dom ) { do { id = utility.domId( utility.uuid( true) ); } while ( utility.$( "#" + id ) !== undefined ); } else { id = utility.domId( utility.uuid( true) ); } if ( typeof obj === "object" ) { obj.id = id; return obj; } else { return id; } }
javascript
function ( obj, dom ) { dom = ( dom === true ); var id; if ( obj !== undefined && ( ( obj.id !== undefined && obj.id !== "" ) || ( obj instanceof Array ) || ( obj instanceof String || typeof obj === "string" ) ) ) { return obj; } if ( dom ) { do { id = utility.domId( utility.uuid( true) ); } while ( utility.$( "#" + id ) !== undefined ); } else { id = utility.domId( utility.uuid( true) ); } if ( typeof obj === "object" ) { obj.id = id; return obj; } else { return id; } }
[ "function", "(", "obj", ",", "dom", ")", "{", "dom", "=", "(", "dom", "===", "true", ")", ";", "var", "id", ";", "if", "(", "obj", "!==", "undefined", "&&", "(", "(", "obj", ".", "id", "!==", "undefined", "&&", "obj", ".", "id", "!==", "\"\"", ")", "||", "(", "obj", "instanceof", "Array", ")", "||", "(", "obj", "instanceof", "String", "||", "typeof", "obj", "===", "\"string\"", ")", ")", ")", "{", "return", "obj", ";", "}", "if", "(", "dom", ")", "{", "do", "{", "id", "=", "utility", ".", "domId", "(", "utility", ".", "uuid", "(", "true", ")", ")", ";", "}", "while", "(", "utility", ".", "$", "(", "\"#\"", "+", "id", ")", "!==", "undefined", ")", ";", "}", "else", "{", "id", "=", "utility", ".", "domId", "(", "utility", ".", "uuid", "(", "true", ")", ")", ";", "}", "if", "(", "typeof", "obj", "===", "\"object\"", ")", "{", "obj", ".", "id", "=", "id", ";", "return", "obj", ";", "}", "else", "{", "return", "id", ";", "}", "}" ]
Generates an ID value @method genId @param {Mixed} obj [Optional] Object to receive id @param {Boolean} dom [Optional] Verify the ID is unique in the DOM, default is false @return {Mixed} Object or id
[ "Generates", "an", "ID", "value" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L9427-L9453
36,537
avoidwork/abaaso
lib/abaaso.js
function ( color ) { var digits, red, green, blue, result, i, nth; if ( color.charAt( 0 ) === "#" ) { result = color; } else { digits = string.explode( color.replace( /.*\(|\)/g, "" ) ); red = number.parse( digits[0] || 0 ); green = number.parse( digits[1] || 0 ); blue = number.parse( digits[2] || 0 ); result = ( blue | ( green << 8 ) | ( red << 16 ) ).toString( 16 ); if ( result.length < 6 ) { nth = number.diff( result.length, 6 ); i = -1; while ( ++i < nth ) { result = "0" + result; } } result = "#" + result; } return result; }
javascript
function ( color ) { var digits, red, green, blue, result, i, nth; if ( color.charAt( 0 ) === "#" ) { result = color; } else { digits = string.explode( color.replace( /.*\(|\)/g, "" ) ); red = number.parse( digits[0] || 0 ); green = number.parse( digits[1] || 0 ); blue = number.parse( digits[2] || 0 ); result = ( blue | ( green << 8 ) | ( red << 16 ) ).toString( 16 ); if ( result.length < 6 ) { nth = number.diff( result.length, 6 ); i = -1; while ( ++i < nth ) { result = "0" + result; } } result = "#" + result; } return result; }
[ "function", "(", "color", ")", "{", "var", "digits", ",", "red", ",", "green", ",", "blue", ",", "result", ",", "i", ",", "nth", ";", "if", "(", "color", ".", "charAt", "(", "0", ")", "===", "\"#\"", ")", "{", "result", "=", "color", ";", "}", "else", "{", "digits", "=", "string", ".", "explode", "(", "color", ".", "replace", "(", "/", ".*\\(|\\)", "/", "g", ",", "\"\"", ")", ")", ";", "red", "=", "number", ".", "parse", "(", "digits", "[", "0", "]", "||", "0", ")", ";", "green", "=", "number", ".", "parse", "(", "digits", "[", "1", "]", "||", "0", ")", ";", "blue", "=", "number", ".", "parse", "(", "digits", "[", "2", "]", "||", "0", ")", ";", "result", "=", "(", "blue", "|", "(", "green", "<<", "8", ")", "|", "(", "red", "<<", "16", ")", ")", ".", "toString", "(", "16", ")", ";", "if", "(", "result", ".", "length", "<", "6", ")", "{", "nth", "=", "number", ".", "diff", "(", "result", ".", "length", ",", "6", ")", ";", "i", "=", "-", "1", ";", "while", "(", "++", "i", "<", "nth", ")", "{", "result", "=", "\"0\"", "+", "result", ";", "}", "}", "result", "=", "\"#\"", "+", "result", ";", "}", "return", "result", ";", "}" ]
Converts RGB to HEX @method hex @param {String} color RGB as `rgb(255, 255, 255)` or `255, 255, 255` @return {String} Color as HEX
[ "Converts", "RGB", "to", "HEX" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L9477-L9503
36,538
avoidwork/abaaso
lib/abaaso.js
function ( obj ) { var l = abaaso.loading; if ( l.url === null || obj === undefined ) { throw new Error( label.error.invalidArguments ); } // Setting loading image if ( l.image === undefined ) { l.image = new Image(); l.image.src = l.url; } // Clearing target element element.clear( obj ); // Creating loading image in target element element.create( "img", {alt: label.common.loading, src: l.image.src}, element.create( "div", {"class": "loading"}, obj ) ); return obj; }
javascript
function ( obj ) { var l = abaaso.loading; if ( l.url === null || obj === undefined ) { throw new Error( label.error.invalidArguments ); } // Setting loading image if ( l.image === undefined ) { l.image = new Image(); l.image.src = l.url; } // Clearing target element element.clear( obj ); // Creating loading image in target element element.create( "img", {alt: label.common.loading, src: l.image.src}, element.create( "div", {"class": "loading"}, obj ) ); return obj; }
[ "function", "(", "obj", ")", "{", "var", "l", "=", "abaaso", ".", "loading", ";", "if", "(", "l", ".", "url", "===", "null", "||", "obj", "===", "undefined", ")", "{", "throw", "new", "Error", "(", "label", ".", "error", ".", "invalidArguments", ")", ";", "}", "// Setting loading image", "if", "(", "l", ".", "image", "===", "undefined", ")", "{", "l", ".", "image", "=", "new", "Image", "(", ")", ";", "l", ".", "image", ".", "src", "=", "l", ".", "url", ";", "}", "// Clearing target element", "element", ".", "clear", "(", "obj", ")", ";", "// Creating loading image in target element", "element", ".", "create", "(", "\"img\"", ",", "{", "alt", ":", "label", ".", "common", ".", "loading", ",", "src", ":", "l", ".", "image", ".", "src", "}", ",", "element", ".", "create", "(", "\"div\"", ",", "{", "\"class\"", ":", "\"loading\"", "}", ",", "obj", ")", ")", ";", "return", "obj", ";", "}" ]
Renders a loading icon in a target element, with a class of "loading" @method loading @param {Mixed} obj Element @return {Mixed} Element
[ "Renders", "a", "loading", "icon", "in", "a", "target", "element", "with", "a", "class", "of", "loading" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L9563-L9583
36,539
avoidwork/abaaso
lib/abaaso.js
function ( arg, target ) { var ts, msg; if ( typeof console !== "undefined" ) { ts = typeof arg !== "object"; msg = ts ? "[" + new Date().toLocaleTimeString() + "] " + arg : arg; console[target || "log"]( msg ); } }
javascript
function ( arg, target ) { var ts, msg; if ( typeof console !== "undefined" ) { ts = typeof arg !== "object"; msg = ts ? "[" + new Date().toLocaleTimeString() + "] " + arg : arg; console[target || "log"]( msg ); } }
[ "function", "(", "arg", ",", "target", ")", "{", "var", "ts", ",", "msg", ";", "if", "(", "typeof", "console", "!==", "\"undefined\"", ")", "{", "ts", "=", "typeof", "arg", "!==", "\"object\"", ";", "msg", "=", "ts", "?", "\"[\"", "+", "new", "Date", "(", ")", ".", "toLocaleTimeString", "(", ")", "+", "\"] \"", "+", "arg", ":", "arg", ";", "console", "[", "target", "||", "\"log\"", "]", "(", "msg", ")", ";", "}", "}" ]
Writes argument to the console @method log @param {String} arg String to write to the console @param {String} target [Optional] Target console, default is "log" @return {Undefined} undefined
[ "Writes", "argument", "to", "the", "console" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L9593-L9601
36,540
avoidwork/abaaso
lib/abaaso.js
function ( obj, arg ) { utility.iterate( arg, function ( v, k ) { if ( ( obj[k] instanceof Array ) && ( v instanceof Array ) ) { array.merge( obj[k], v ); } else if ( ( obj[k] instanceof Object ) && ( v instanceof Object ) ) { utility.iterate( v, function ( x, y ) { obj[k][y] = utility.clone( x ); }); } else { obj[k] = utility.clone( v ); } }); return obj; }
javascript
function ( obj, arg ) { utility.iterate( arg, function ( v, k ) { if ( ( obj[k] instanceof Array ) && ( v instanceof Array ) ) { array.merge( obj[k], v ); } else if ( ( obj[k] instanceof Object ) && ( v instanceof Object ) ) { utility.iterate( v, function ( x, y ) { obj[k][y] = utility.clone( x ); }); } else { obj[k] = utility.clone( v ); } }); return obj; }
[ "function", "(", "obj", ",", "arg", ")", "{", "utility", ".", "iterate", "(", "arg", ",", "function", "(", "v", ",", "k", ")", "{", "if", "(", "(", "obj", "[", "k", "]", "instanceof", "Array", ")", "&&", "(", "v", "instanceof", "Array", ")", ")", "{", "array", ".", "merge", "(", "obj", "[", "k", "]", ",", "v", ")", ";", "}", "else", "if", "(", "(", "obj", "[", "k", "]", "instanceof", "Object", ")", "&&", "(", "v", "instanceof", "Object", ")", ")", "{", "utility", ".", "iterate", "(", "v", ",", "function", "(", "x", ",", "y", ")", "{", "obj", "[", "k", "]", "[", "y", "]", "=", "utility", ".", "clone", "(", "x", ")", ";", "}", ")", ";", "}", "else", "{", "obj", "[", "k", "]", "=", "utility", ".", "clone", "(", "v", ")", ";", "}", "}", ")", ";", "return", "obj", ";", "}" ]
Merges obj with arg @method merge @param {Object} obj Object to decorate @param {Object} arg Decoration @return {Object} Decorated Object
[ "Merges", "obj", "with", "arg" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L9611-L9627
36,541
avoidwork/abaaso
lib/abaaso.js
function ( arg, obj ) { if ( $[arg] !== undefined || !obj instanceof Object ) { throw new Error( label.error.invalidArguments ); } $[arg] = obj; return $[arg]; }
javascript
function ( arg, obj ) { if ( $[arg] !== undefined || !obj instanceof Object ) { throw new Error( label.error.invalidArguments ); } $[arg] = obj; return $[arg]; }
[ "function", "(", "arg", ",", "obj", ")", "{", "if", "(", "$", "[", "arg", "]", "!==", "undefined", "||", "!", "obj", "instanceof", "Object", ")", "{", "throw", "new", "Error", "(", "label", ".", "error", ".", "invalidArguments", ")", ";", "}", "$", "[", "arg", "]", "=", "obj", ";", "return", "$", "[", "arg", "]", ";", "}" ]
Registers a module on abaaso @method module @param {String} arg Module name @param {Object} obj Module structure @return {Object} Module registered
[ "Registers", "a", "module", "on", "abaaso" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L9637-L9645
36,542
avoidwork/abaaso
lib/abaaso.js
function ( obj ) { return typeof obj === "object" ? obj : ( obj.charAt && obj.charAt( 0 ) === "#" ? utility.$( obj ) : obj ); }
javascript
function ( obj ) { return typeof obj === "object" ? obj : ( obj.charAt && obj.charAt( 0 ) === "#" ? utility.$( obj ) : obj ); }
[ "function", "(", "obj", ")", "{", "return", "typeof", "obj", "===", "\"object\"", "?", "obj", ":", "(", "obj", ".", "charAt", "&&", "obj", ".", "charAt", "(", "0", ")", "===", "\"#\"", "?", "utility", ".", "$", "(", "obj", ")", ":", "obj", ")", ";", "}" ]
Returns Object, or reference to Element @method object @private @param {Mixed} obj Entity or $ query @return {Mixed} Entity
[ "Returns", "Object", "or", "reference", "to", "Element" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L9655-L9657
36,543
avoidwork/abaaso
lib/abaaso.js
function ( uri ) { var obj = {}, parsed = {}; if ( uri === undefined ) { uri = !server ? location.href : ""; } if ( !server ) { obj = document.createElement( "a" ); obj.href = uri; } else { obj = url.parse( uri ); } if ( server ) { utility.iterate( obj, function ( v, k ) { if ( v === null ) { obj[k] = undefined; } }); } parsed = { auth : server ? null : regex.auth.exec( uri ), protocol : obj.protocol || "http:", hostname : obj.hostname || "localhost", port : obj.port ? number.parse( obj.port, 10 ) : "", pathname : obj.pathname, search : obj.search || "", hash : obj.hash || "", host : obj.host || "localhost" }; // 'cause IE is ... IE; required for data.batch() if ( client.ie ) { if ( parsed.protocol === ":" ) { parsed.protocol = location.protocol; } if ( string.isEmpty( parsed.hostname ) ) { parsed.hostname = location.hostname; } if ( string.isEmpty( parsed.host ) ) { parsed.host = location.host; } if ( parsed.pathname.charAt( 0 ) !== "/" ) { parsed.pathname = "/" + parsed.pathname; } } parsed.auth = obj.auth || ( parsed.auth === null ? "" : parsed.auth[1] ); parsed.href = obj.href || ( parsed.protocol + "//" + ( string.isEmpty( parsed.auth ) ? "" : parsed.auth + "@" ) + parsed.host + parsed.pathname + parsed.search + parsed.hash ); parsed.path = obj.path || parsed.pathname + parsed.search; parsed.query = utility.queryString( null, parsed.search ); return parsed; }
javascript
function ( uri ) { var obj = {}, parsed = {}; if ( uri === undefined ) { uri = !server ? location.href : ""; } if ( !server ) { obj = document.createElement( "a" ); obj.href = uri; } else { obj = url.parse( uri ); } if ( server ) { utility.iterate( obj, function ( v, k ) { if ( v === null ) { obj[k] = undefined; } }); } parsed = { auth : server ? null : regex.auth.exec( uri ), protocol : obj.protocol || "http:", hostname : obj.hostname || "localhost", port : obj.port ? number.parse( obj.port, 10 ) : "", pathname : obj.pathname, search : obj.search || "", hash : obj.hash || "", host : obj.host || "localhost" }; // 'cause IE is ... IE; required for data.batch() if ( client.ie ) { if ( parsed.protocol === ":" ) { parsed.protocol = location.protocol; } if ( string.isEmpty( parsed.hostname ) ) { parsed.hostname = location.hostname; } if ( string.isEmpty( parsed.host ) ) { parsed.host = location.host; } if ( parsed.pathname.charAt( 0 ) !== "/" ) { parsed.pathname = "/" + parsed.pathname; } } parsed.auth = obj.auth || ( parsed.auth === null ? "" : parsed.auth[1] ); parsed.href = obj.href || ( parsed.protocol + "//" + ( string.isEmpty( parsed.auth ) ? "" : parsed.auth + "@" ) + parsed.host + parsed.pathname + parsed.search + parsed.hash ); parsed.path = obj.path || parsed.pathname + parsed.search; parsed.query = utility.queryString( null, parsed.search ); return parsed; }
[ "function", "(", "uri", ")", "{", "var", "obj", "=", "{", "}", ",", "parsed", "=", "{", "}", ";", "if", "(", "uri", "===", "undefined", ")", "{", "uri", "=", "!", "server", "?", "location", ".", "href", ":", "\"\"", ";", "}", "if", "(", "!", "server", ")", "{", "obj", "=", "document", ".", "createElement", "(", "\"a\"", ")", ";", "obj", ".", "href", "=", "uri", ";", "}", "else", "{", "obj", "=", "url", ".", "parse", "(", "uri", ")", ";", "}", "if", "(", "server", ")", "{", "utility", ".", "iterate", "(", "obj", ",", "function", "(", "v", ",", "k", ")", "{", "if", "(", "v", "===", "null", ")", "{", "obj", "[", "k", "]", "=", "undefined", ";", "}", "}", ")", ";", "}", "parsed", "=", "{", "auth", ":", "server", "?", "null", ":", "regex", ".", "auth", ".", "exec", "(", "uri", ")", ",", "protocol", ":", "obj", ".", "protocol", "||", "\"http:\"", ",", "hostname", ":", "obj", ".", "hostname", "||", "\"localhost\"", ",", "port", ":", "obj", ".", "port", "?", "number", ".", "parse", "(", "obj", ".", "port", ",", "10", ")", ":", "\"\"", ",", "pathname", ":", "obj", ".", "pathname", ",", "search", ":", "obj", ".", "search", "||", "\"\"", ",", "hash", ":", "obj", ".", "hash", "||", "\"\"", ",", "host", ":", "obj", ".", "host", "||", "\"localhost\"", "}", ";", "// 'cause IE is ... IE; required for data.batch()", "if", "(", "client", ".", "ie", ")", "{", "if", "(", "parsed", ".", "protocol", "===", "\":\"", ")", "{", "parsed", ".", "protocol", "=", "location", ".", "protocol", ";", "}", "if", "(", "string", ".", "isEmpty", "(", "parsed", ".", "hostname", ")", ")", "{", "parsed", ".", "hostname", "=", "location", ".", "hostname", ";", "}", "if", "(", "string", ".", "isEmpty", "(", "parsed", ".", "host", ")", ")", "{", "parsed", ".", "host", "=", "location", ".", "host", ";", "}", "if", "(", "parsed", ".", "pathname", ".", "charAt", "(", "0", ")", "!==", "\"/\"", ")", "{", "parsed", ".", "pathname", "=", "\"/\"", "+", "parsed", ".", "pathname", ";", "}", "}", "parsed", ".", "auth", "=", "obj", ".", "auth", "||", "(", "parsed", ".", "auth", "===", "null", "?", "\"\"", ":", "parsed", ".", "auth", "[", "1", "]", ")", ";", "parsed", ".", "href", "=", "obj", ".", "href", "||", "(", "parsed", ".", "protocol", "+", "\"//\"", "+", "(", "string", ".", "isEmpty", "(", "parsed", ".", "auth", ")", "?", "\"\"", ":", "parsed", ".", "auth", "+", "\"@\"", ")", "+", "parsed", ".", "host", "+", "parsed", ".", "pathname", "+", "parsed", ".", "search", "+", "parsed", ".", "hash", ")", ";", "parsed", ".", "path", "=", "obj", ".", "path", "||", "parsed", ".", "pathname", "+", "parsed", ".", "search", ";", "parsed", ".", "query", "=", "utility", ".", "queryString", "(", "null", ",", "parsed", ".", "search", ")", ";", "return", "parsed", ";", "}" ]
Parses a URI into an Object @method parse @param {String} uri URI to parse @return {Object} Parsed URI
[ "Parses", "a", "URI", "into", "an", "Object" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L9666-L9726
36,544
avoidwork/abaaso
lib/abaaso.js
function () { if ( ( server || ( !client.ie || client.version > 8 ) ) && typeof Object.defineProperty === "function" ) { return function ( obj, prop, descriptor ) { if ( !( descriptor instanceof Object ) ) { throw new Error( label.error.invalidArguments ); } if ( descriptor.value !== undefined && descriptor.get !== undefined ) { delete descriptor.value; } Object.defineProperty( obj, prop, descriptor ); }; } else { return function ( obj, prop, descriptor ) { if ( !( descriptor instanceof Object ) ) { throw new Error( label.error.invalidArguments ); } obj[prop] = descriptor.value; return obj; }; } }
javascript
function () { if ( ( server || ( !client.ie || client.version > 8 ) ) && typeof Object.defineProperty === "function" ) { return function ( obj, prop, descriptor ) { if ( !( descriptor instanceof Object ) ) { throw new Error( label.error.invalidArguments ); } if ( descriptor.value !== undefined && descriptor.get !== undefined ) { delete descriptor.value; } Object.defineProperty( obj, prop, descriptor ); }; } else { return function ( obj, prop, descriptor ) { if ( !( descriptor instanceof Object ) ) { throw new Error( label.error.invalidArguments ); } obj[prop] = descriptor.value; return obj; }; } }
[ "function", "(", ")", "{", "if", "(", "(", "server", "||", "(", "!", "client", ".", "ie", "||", "client", ".", "version", ">", "8", ")", ")", "&&", "typeof", "Object", ".", "defineProperty", "===", "\"function\"", ")", "{", "return", "function", "(", "obj", ",", "prop", ",", "descriptor", ")", "{", "if", "(", "!", "(", "descriptor", "instanceof", "Object", ")", ")", "{", "throw", "new", "Error", "(", "label", ".", "error", ".", "invalidArguments", ")", ";", "}", "if", "(", "descriptor", ".", "value", "!==", "undefined", "&&", "descriptor", ".", "get", "!==", "undefined", ")", "{", "delete", "descriptor", ".", "value", ";", "}", "Object", ".", "defineProperty", "(", "obj", ",", "prop", ",", "descriptor", ")", ";", "}", ";", "}", "else", "{", "return", "function", "(", "obj", ",", "prop", ",", "descriptor", ")", "{", "if", "(", "!", "(", "descriptor", "instanceof", "Object", ")", ")", "{", "throw", "new", "Error", "(", "label", ".", "error", ".", "invalidArguments", ")", ";", "}", "obj", "[", "prop", "]", "=", "descriptor", ".", "value", ";", "return", "obj", ";", "}", ";", "}", "}" ]
Sets a property on an Object, if defineProperty cannot be used the value will be set classically @method property @param {Object} obj Object to decorate @param {String} prop Name of property to set @param {Object} descriptor Descriptor of the property @return {Object} Object receiving the property
[ "Sets", "a", "property", "on", "an", "Object", "if", "defineProperty", "cannot", "be", "used", "the", "value", "will", "be", "set", "classically" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L9737-L9762
36,545
avoidwork/abaaso
lib/abaaso.js
function ( obj, type ) { var target = obj.prototype || obj; utility.iterate( prototypes[type], function ( v, k ) { if ( !target[k] ) { utility.property( target, k, {value: v, configurable: true, writable: true} ); } }); return obj; }
javascript
function ( obj, type ) { var target = obj.prototype || obj; utility.iterate( prototypes[type], function ( v, k ) { if ( !target[k] ) { utility.property( target, k, {value: v, configurable: true, writable: true} ); } }); return obj; }
[ "function", "(", "obj", ",", "type", ")", "{", "var", "target", "=", "obj", ".", "prototype", "||", "obj", ";", "utility", ".", "iterate", "(", "prototypes", "[", "type", "]", ",", "function", "(", "v", ",", "k", ")", "{", "if", "(", "!", "target", "[", "k", "]", ")", "{", "utility", ".", "property", "(", "target", ",", "k", ",", "{", "value", ":", "v", ",", "configurable", ":", "true", ",", "writable", ":", "true", "}", ")", ";", "}", "}", ")", ";", "return", "obj", ";", "}" ]
Sets methods on a prototype object Allows hooks to be overwritten @method proto @param {Object} obj Object receiving prototype extension @param {String} type Identifier of obj, determines what Arrays to apply @return {Object} obj or undefined
[ "Sets", "methods", "on", "a", "prototype", "object" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L9774-L9784
36,546
avoidwork/abaaso
lib/abaaso.js
function ( arg, qstring ) { var obj = {}, result = qstring !== undefined ? ( qstring.indexOf( "?" ) > -1 ? qstring.replace( /.*\?/, "" ) : null) : ( server || string.isEmpty( location.search ) ? null : location.search.replace( "?", "" ) ); if ( result !== null && !string.isEmpty( result ) ) { result = result.split( "&" ); array.each( result, function (prop ) { var item = prop.split( "=" ); if ( string.isEmpty( item[0] ) ) { return; } if ( item[1] === undefined ) { item[1] = ""; } else { item[1] = utility.coerce( decodeURIComponent( item[1] ) ); } if ( obj[item[0]] === undefined ) { obj[item[0]] = item[1]; } else if ( !(obj[item[0]] instanceof Array) ) { obj[item[0]] = [obj[item[0]]]; obj[item[0]].push( item[1] ); } else { obj[item[0]].push( item[1] ); } }); } if ( arg !== null && arg !== undefined ) { obj = obj[arg]; } return obj; }
javascript
function ( arg, qstring ) { var obj = {}, result = qstring !== undefined ? ( qstring.indexOf( "?" ) > -1 ? qstring.replace( /.*\?/, "" ) : null) : ( server || string.isEmpty( location.search ) ? null : location.search.replace( "?", "" ) ); if ( result !== null && !string.isEmpty( result ) ) { result = result.split( "&" ); array.each( result, function (prop ) { var item = prop.split( "=" ); if ( string.isEmpty( item[0] ) ) { return; } if ( item[1] === undefined ) { item[1] = ""; } else { item[1] = utility.coerce( decodeURIComponent( item[1] ) ); } if ( obj[item[0]] === undefined ) { obj[item[0]] = item[1]; } else if ( !(obj[item[0]] instanceof Array) ) { obj[item[0]] = [obj[item[0]]]; obj[item[0]].push( item[1] ); } else { obj[item[0]].push( item[1] ); } }); } if ( arg !== null && arg !== undefined ) { obj = obj[arg]; } return obj; }
[ "function", "(", "arg", ",", "qstring", ")", "{", "var", "obj", "=", "{", "}", ",", "result", "=", "qstring", "!==", "undefined", "?", "(", "qstring", ".", "indexOf", "(", "\"?\"", ")", ">", "-", "1", "?", "qstring", ".", "replace", "(", "/", ".*\\?", "/", ",", "\"\"", ")", ":", "null", ")", ":", "(", "server", "||", "string", ".", "isEmpty", "(", "location", ".", "search", ")", "?", "null", ":", "location", ".", "search", ".", "replace", "(", "\"?\"", ",", "\"\"", ")", ")", ";", "if", "(", "result", "!==", "null", "&&", "!", "string", ".", "isEmpty", "(", "result", ")", ")", "{", "result", "=", "result", ".", "split", "(", "\"&\"", ")", ";", "array", ".", "each", "(", "result", ",", "function", "(", "prop", ")", "{", "var", "item", "=", "prop", ".", "split", "(", "\"=\"", ")", ";", "if", "(", "string", ".", "isEmpty", "(", "item", "[", "0", "]", ")", ")", "{", "return", ";", "}", "if", "(", "item", "[", "1", "]", "===", "undefined", ")", "{", "item", "[", "1", "]", "=", "\"\"", ";", "}", "else", "{", "item", "[", "1", "]", "=", "utility", ".", "coerce", "(", "decodeURIComponent", "(", "item", "[", "1", "]", ")", ")", ";", "}", "if", "(", "obj", "[", "item", "[", "0", "]", "]", "===", "undefined", ")", "{", "obj", "[", "item", "[", "0", "]", "]", "=", "item", "[", "1", "]", ";", "}", "else", "if", "(", "!", "(", "obj", "[", "item", "[", "0", "]", "]", "instanceof", "Array", ")", ")", "{", "obj", "[", "item", "[", "0", "]", "]", "=", "[", "obj", "[", "item", "[", "0", "]", "]", "]", ";", "obj", "[", "item", "[", "0", "]", "]", ".", "push", "(", "item", "[", "1", "]", ")", ";", "}", "else", "{", "obj", "[", "item", "[", "0", "]", "]", ".", "push", "(", "item", "[", "1", "]", ")", ";", "}", "}", ")", ";", "}", "if", "(", "arg", "!==", "null", "&&", "arg", "!==", "undefined", ")", "{", "obj", "=", "obj", "[", "arg", "]", ";", "}", "return", "obj", ";", "}" ]
Parses a query string & coerces values @method queryString @param {String} arg [Optional] Key to find in the querystring @param {String} qstring [Optional] Query string to parse @return {Mixed} Value or Object of key:value pairs
[ "Parses", "a", "query", "string", "&", "coerces", "values" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L9794-L9832
36,547
avoidwork/abaaso
lib/abaaso.js
function ( arg ) { if ( arg === undefined ) { arg = this || utility.$; } arg = arg.toString().match( regex.reflect )[1]; return string.explode( arg ); }
javascript
function ( arg ) { if ( arg === undefined ) { arg = this || utility.$; } arg = arg.toString().match( regex.reflect )[1]; return string.explode( arg ); }
[ "function", "(", "arg", ")", "{", "if", "(", "arg", "===", "undefined", ")", "{", "arg", "=", "this", "||", "utility", ".", "$", ";", "}", "arg", "=", "arg", ".", "toString", "(", ")", ".", "match", "(", "regex", ".", "reflect", ")", "[", "1", "]", ";", "return", "string", ".", "explode", "(", "arg", ")", ";", "}" ]
Returns an Array of parameters of a Function @method reflect @param {Function} arg Function to reflect @return {Array} Array of parameters
[ "Returns", "an", "Array", "of", "parameters", "of", "a", "Function" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L9841-L9849
36,548
avoidwork/abaaso
lib/abaaso.js
function ( fn, ms, id, now ) { ms = ms || 10; id = id || utility.uuid( true ); now = ( now !== false ); // Could be valid to return false from initial execution if ( now && fn() === false ) { return; } // Creating repeating execution utility.defer( function () { var recursive = function ( fn, ms, id ) { var recursive = this; if ( fn() !== false ) { utility.repeating[id] = setTimeout( function () { recursive.call( recursive, fn, ms, id ); }, ms ); } else { delete utility.repeating[id]; } }; recursive.call( recursive, fn, ms, id ); }, ms, id, true ); return id; }
javascript
function ( fn, ms, id, now ) { ms = ms || 10; id = id || utility.uuid( true ); now = ( now !== false ); // Could be valid to return false from initial execution if ( now && fn() === false ) { return; } // Creating repeating execution utility.defer( function () { var recursive = function ( fn, ms, id ) { var recursive = this; if ( fn() !== false ) { utility.repeating[id] = setTimeout( function () { recursive.call( recursive, fn, ms, id ); }, ms ); } else { delete utility.repeating[id]; } }; recursive.call( recursive, fn, ms, id ); }, ms, id, true ); return id; }
[ "function", "(", "fn", ",", "ms", ",", "id", ",", "now", ")", "{", "ms", "=", "ms", "||", "10", ";", "id", "=", "id", "||", "utility", ".", "uuid", "(", "true", ")", ";", "now", "=", "(", "now", "!==", "false", ")", ";", "// Could be valid to return false from initial execution", "if", "(", "now", "&&", "fn", "(", ")", "===", "false", ")", "{", "return", ";", "}", "// Creating repeating execution", "utility", ".", "defer", "(", "function", "(", ")", "{", "var", "recursive", "=", "function", "(", "fn", ",", "ms", ",", "id", ")", "{", "var", "recursive", "=", "this", ";", "if", "(", "fn", "(", ")", "!==", "false", ")", "{", "utility", ".", "repeating", "[", "id", "]", "=", "setTimeout", "(", "function", "(", ")", "{", "recursive", ".", "call", "(", "recursive", ",", "fn", ",", "ms", ",", "id", ")", ";", "}", ",", "ms", ")", ";", "}", "else", "{", "delete", "utility", ".", "repeating", "[", "id", "]", ";", "}", "}", ";", "recursive", ".", "call", "(", "recursive", ",", "fn", ",", "ms", ",", "id", ")", ";", "}", ",", "ms", ",", "id", ",", "true", ")", ";", "return", "id", ";", "}" ]
Creates a recursive function Return false from the function to halt recursion @method repeat @param {Function} fn Function to execute repeatedly @param {Number} ms Milliseconds to stagger the execution @param {String} id [Optional] Timeout ID @param {Boolean} now Executes `fn` and then setup repetition, default is `true` @return {String} Timeout ID
[ "Creates", "a", "recursive", "function" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L9863-L9892
36,549
avoidwork/abaaso
lib/abaaso.js
function ( arg, target ) { var frag; if ( typeof arg !== "object" || (!(regex.object_undefined.test( typeof target ) ) && ( target = target.charAt( 0 ) === "#" ? utility.$( target ) : utility.$( target )[0] ) === undefined ) ) { throw new Error( label.error.invalidArguments ); } if ( target === undefined ) { target = utility.$( "body" )[0]; } frag = document.createDocumentFragment(); if ( arg instanceof Array ) { array.each( arg, function ( i ) { element.html( element.create( array.cast( i, true )[0], frag ), array.cast(i)[0] ); }); } else { utility.iterate( arg, function ( v, k ) { if ( typeof v === "string" ) { element.html( element.create( k, undefined, frag ), v ); } else if ( ( v instanceof Array ) || ( v instanceof Object ) ) { utility.tpl( v, element.create( k, undefined, frag ) ); } }); } target.appendChild( frag ); return array.last( target.childNodes ); }
javascript
function ( arg, target ) { var frag; if ( typeof arg !== "object" || (!(regex.object_undefined.test( typeof target ) ) && ( target = target.charAt( 0 ) === "#" ? utility.$( target ) : utility.$( target )[0] ) === undefined ) ) { throw new Error( label.error.invalidArguments ); } if ( target === undefined ) { target = utility.$( "body" )[0]; } frag = document.createDocumentFragment(); if ( arg instanceof Array ) { array.each( arg, function ( i ) { element.html( element.create( array.cast( i, true )[0], frag ), array.cast(i)[0] ); }); } else { utility.iterate( arg, function ( v, k ) { if ( typeof v === "string" ) { element.html( element.create( k, undefined, frag ), v ); } else if ( ( v instanceof Array ) || ( v instanceof Object ) ) { utility.tpl( v, element.create( k, undefined, frag ) ); } }); } target.appendChild( frag ); return array.last( target.childNodes ); }
[ "function", "(", "arg", ",", "target", ")", "{", "var", "frag", ";", "if", "(", "typeof", "arg", "!==", "\"object\"", "||", "(", "!", "(", "regex", ".", "object_undefined", ".", "test", "(", "typeof", "target", ")", ")", "&&", "(", "target", "=", "target", ".", "charAt", "(", "0", ")", "===", "\"#\"", "?", "utility", ".", "$", "(", "target", ")", ":", "utility", ".", "$", "(", "target", ")", "[", "0", "]", ")", "===", "undefined", ")", ")", "{", "throw", "new", "Error", "(", "label", ".", "error", ".", "invalidArguments", ")", ";", "}", "if", "(", "target", "===", "undefined", ")", "{", "target", "=", "utility", ".", "$", "(", "\"body\"", ")", "[", "0", "]", ";", "}", "frag", "=", "document", ".", "createDocumentFragment", "(", ")", ";", "if", "(", "arg", "instanceof", "Array", ")", "{", "array", ".", "each", "(", "arg", ",", "function", "(", "i", ")", "{", "element", ".", "html", "(", "element", ".", "create", "(", "array", ".", "cast", "(", "i", ",", "true", ")", "[", "0", "]", ",", "frag", ")", ",", "array", ".", "cast", "(", "i", ")", "[", "0", "]", ")", ";", "}", ")", ";", "}", "else", "{", "utility", ".", "iterate", "(", "arg", ",", "function", "(", "v", ",", "k", ")", "{", "if", "(", "typeof", "v", "===", "\"string\"", ")", "{", "element", ".", "html", "(", "element", ".", "create", "(", "k", ",", "undefined", ",", "frag", ")", ",", "v", ")", ";", "}", "else", "if", "(", "(", "v", "instanceof", "Array", ")", "||", "(", "v", "instanceof", "Object", ")", ")", "{", "utility", ".", "tpl", "(", "v", ",", "element", ".", "create", "(", "k", ",", "undefined", ",", "frag", ")", ")", ";", "}", "}", ")", ";", "}", "target", ".", "appendChild", "(", "frag", ")", ";", "return", "array", ".", "last", "(", "target", ".", "childNodes", ")", ";", "}" ]
Transforms JSON to HTML and appends to Body or target Element @method tpl @param {Object} data JSON Object describing HTML @param {Mixed} target [Optional] Target Element or Element.id to receive the HTML @return {Object} New Element created from the template
[ "Transforms", "JSON", "to", "HTML", "and", "appends", "to", "Body", "or", "target", "Element" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L9939-L9971
36,550
avoidwork/abaaso
lib/abaaso.js
function ( safe ) { var s = function () { return ( ( ( 1 + Math.random() ) * 0x10000 ) | 0 ).toString( 16 ).substring( 1 ); }, r = [8, 9, "a", "b"], o; o = ( s() + s() + "-" + s() + "-4" + s().substr( 0, 3 ) + "-" + r[Math.floor( Math.random() * 4 )] + s().substr( 0, 3 ) + "-" + s() + s() + s() ); if ( safe === true ) { o = o.replace( /-/g, "" ); } return o; }
javascript
function ( safe ) { var s = function () { return ( ( ( 1 + Math.random() ) * 0x10000 ) | 0 ).toString( 16 ).substring( 1 ); }, r = [8, 9, "a", "b"], o; o = ( s() + s() + "-" + s() + "-4" + s().substr( 0, 3 ) + "-" + r[Math.floor( Math.random() * 4 )] + s().substr( 0, 3 ) + "-" + s() + s() + s() ); if ( safe === true ) { o = o.replace( /-/g, "" ); } return o; }
[ "function", "(", "safe", ")", "{", "var", "s", "=", "function", "(", ")", "{", "return", "(", "(", "(", "1", "+", "Math", ".", "random", "(", ")", ")", "*", "0x10000", ")", "|", "0", ")", ".", "toString", "(", "16", ")", ".", "substring", "(", "1", ")", ";", "}", ",", "r", "=", "[", "8", ",", "9", ",", "\"a\"", ",", "\"b\"", "]", ",", "o", ";", "o", "=", "(", "s", "(", ")", "+", "s", "(", ")", "+", "\"-\"", "+", "s", "(", ")", "+", "\"-4\"", "+", "s", "(", ")", ".", "substr", "(", "0", ",", "3", ")", "+", "\"-\"", "+", "r", "[", "Math", ".", "floor", "(", "Math", ".", "random", "(", ")", "*", "4", ")", "]", "+", "s", "(", ")", ".", "substr", "(", "0", ",", "3", ")", "+", "\"-\"", "+", "s", "(", ")", "+", "s", "(", ")", "+", "s", "(", ")", ")", ";", "if", "(", "safe", "===", "true", ")", "{", "o", "=", "o", ".", "replace", "(", "/", "-", "/", "g", ",", "\"\"", ")", ";", "}", "return", "o", ";", "}" ]
Generates a version 4 UUID @method uuid @param {Boolean} safe [Optional] Strips - from UUID @return {String} UUID
[ "Generates", "a", "version", "4", "UUID" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L9980-L9992
36,551
avoidwork/abaaso
lib/abaaso.js
function ( obj, arg ) { array.each( arg.replace( /\]$/, "" ).replace( /\]/g, "." ).replace( /\.\./g, "." ).split( /\.|\[/ ), function ( i ) { obj = obj[i]; }); return obj; }
javascript
function ( obj, arg ) { array.each( arg.replace( /\]$/, "" ).replace( /\]/g, "." ).replace( /\.\./g, "." ).split( /\.|\[/ ), function ( i ) { obj = obj[i]; }); return obj; }
[ "function", "(", "obj", ",", "arg", ")", "{", "array", ".", "each", "(", "arg", ".", "replace", "(", "/", "\\]$", "/", ",", "\"\"", ")", ".", "replace", "(", "/", "\\]", "/", "g", ",", "\".\"", ")", ".", "replace", "(", "/", "\\.\\.", "/", "g", ",", "\".\"", ")", ".", "split", "(", "/", "\\.|\\[", "/", ")", ",", "function", "(", "i", ")", "{", "obj", "=", "obj", "[", "i", "]", ";", "}", ")", ";", "return", "obj", ";", "}" ]
Walks a structure and returns arg @method walk @param {Mixed} obj Object or Array @param {String} arg String describing the property to return @return {Mixed} arg
[ "Walks", "a", "structure", "and", "returns", "arg" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L10002-L10008
36,552
avoidwork/abaaso
lib/abaaso.js
function () { var i = 0, defer = deferred(), args = array.cast( arguments ), nth; // Did we receive an Array? if so it overrides any other arguments if ( args[0] instanceof Array ) { args = args[0]; } // How many instances to observe? nth = args.length; // None, end on next tick if ( nth === 0 ) { defer.resolve( null ); } // Setup and wait else { array.each( args, function ( p ) { p.then( function () { if ( ++i === nth && !defer.isResolved()) { if ( args.length > 1 ) { defer.resolve( args.map( function ( obj ) { return obj.value || obj.promise.value; })); } else { defer.resolve( args[0].value || args[0].promise.value ); } } }, function () { if ( !defer.isResolved() ) { if ( args.length > 1 ) { defer.reject( args.map( function ( obj ) { return obj.value || obj.promise.value; })); } else { defer.reject( args[0].value || args[0].promise.value ); } } }); }); } return defer; }
javascript
function () { var i = 0, defer = deferred(), args = array.cast( arguments ), nth; // Did we receive an Array? if so it overrides any other arguments if ( args[0] instanceof Array ) { args = args[0]; } // How many instances to observe? nth = args.length; // None, end on next tick if ( nth === 0 ) { defer.resolve( null ); } // Setup and wait else { array.each( args, function ( p ) { p.then( function () { if ( ++i === nth && !defer.isResolved()) { if ( args.length > 1 ) { defer.resolve( args.map( function ( obj ) { return obj.value || obj.promise.value; })); } else { defer.resolve( args[0].value || args[0].promise.value ); } } }, function () { if ( !defer.isResolved() ) { if ( args.length > 1 ) { defer.reject( args.map( function ( obj ) { return obj.value || obj.promise.value; })); } else { defer.reject( args[0].value || args[0].promise.value ); } } }); }); } return defer; }
[ "function", "(", ")", "{", "var", "i", "=", "0", ",", "defer", "=", "deferred", "(", ")", ",", "args", "=", "array", ".", "cast", "(", "arguments", ")", ",", "nth", ";", "// Did we receive an Array? if so it overrides any other arguments", "if", "(", "args", "[", "0", "]", "instanceof", "Array", ")", "{", "args", "=", "args", "[", "0", "]", ";", "}", "// How many instances to observe?", "nth", "=", "args", ".", "length", ";", "// None, end on next tick", "if", "(", "nth", "===", "0", ")", "{", "defer", ".", "resolve", "(", "null", ")", ";", "}", "// Setup and wait", "else", "{", "array", ".", "each", "(", "args", ",", "function", "(", "p", ")", "{", "p", ".", "then", "(", "function", "(", ")", "{", "if", "(", "++", "i", "===", "nth", "&&", "!", "defer", ".", "isResolved", "(", ")", ")", "{", "if", "(", "args", ".", "length", ">", "1", ")", "{", "defer", ".", "resolve", "(", "args", ".", "map", "(", "function", "(", "obj", ")", "{", "return", "obj", ".", "value", "||", "obj", ".", "promise", ".", "value", ";", "}", ")", ")", ";", "}", "else", "{", "defer", ".", "resolve", "(", "args", "[", "0", "]", ".", "value", "||", "args", "[", "0", "]", ".", "promise", ".", "value", ")", ";", "}", "}", "}", ",", "function", "(", ")", "{", "if", "(", "!", "defer", ".", "isResolved", "(", ")", ")", "{", "if", "(", "args", ".", "length", ">", "1", ")", "{", "defer", ".", "reject", "(", "args", ".", "map", "(", "function", "(", "obj", ")", "{", "return", "obj", ".", "value", "||", "obj", ".", "promise", ".", "value", ";", "}", ")", ")", ";", "}", "else", "{", "defer", ".", "reject", "(", "args", "[", "0", "]", ".", "value", "||", "args", "[", "0", "]", ".", "promise", ".", "value", ")", ";", "}", "}", "}", ")", ";", "}", ")", ";", "}", "return", "defer", ";", "}" ]
Accepts Deferreds or Promises as arguments or an Array @method when @return {Object} Deferred
[ "Accepts", "Deferreds", "or", "Promises", "as", "arguments", "or", "an", "Array" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L10016-L10064
36,553
avoidwork/abaaso
lib/abaaso.js
function ( arg, wrap ) { try { if ( arg === undefined ) { throw new Error( label.error.invalidArguments ); } wrap = ( wrap !== false ); var x = wrap ? "<xml>" : "", top = ( arguments[2] !== false ), node; /** * Encodes a value as a node * * @method node * @private * @param {String} name Node name * @param {Value} value Node value * @return {String} Node */ node = function ( name, value ) { var output = "<n>v</n>"; output = output.replace( "v", ( regex.cdata.test( value ) ? "<![CDATA[" + value + "]]>" : value ) ); return output.replace(/<(\/)?n>/g, "<$1" + name + ">"); }; if ( arg !== null && arg.xml !== undefined ) { arg = arg.xml; } if ( arg instanceof Document ) { arg = ( new XMLSerializer() ).serializeToString( arg ); } if ( regex.boolean_number_string.test( typeof arg ) ) { x += node( "item", arg ); } else if ( typeof arg === "object" ) { utility.iterate( arg, function ( v, k ) { x += xml.encode( v, ( typeof v === "object" ), false ).replace( /item|xml/g, isNaN( k ) ? k : "item" ); }); } x += wrap ? "</xml>" : ""; if ( top ) { x = "<?xml version=\"1.0\" encoding=\"UTF8\"?>" + x; } return x; } catch ( e ) { utility.error( e, arguments, this ); return undefined; } }
javascript
function ( arg, wrap ) { try { if ( arg === undefined ) { throw new Error( label.error.invalidArguments ); } wrap = ( wrap !== false ); var x = wrap ? "<xml>" : "", top = ( arguments[2] !== false ), node; /** * Encodes a value as a node * * @method node * @private * @param {String} name Node name * @param {Value} value Node value * @return {String} Node */ node = function ( name, value ) { var output = "<n>v</n>"; output = output.replace( "v", ( regex.cdata.test( value ) ? "<![CDATA[" + value + "]]>" : value ) ); return output.replace(/<(\/)?n>/g, "<$1" + name + ">"); }; if ( arg !== null && arg.xml !== undefined ) { arg = arg.xml; } if ( arg instanceof Document ) { arg = ( new XMLSerializer() ).serializeToString( arg ); } if ( regex.boolean_number_string.test( typeof arg ) ) { x += node( "item", arg ); } else if ( typeof arg === "object" ) { utility.iterate( arg, function ( v, k ) { x += xml.encode( v, ( typeof v === "object" ), false ).replace( /item|xml/g, isNaN( k ) ? k : "item" ); }); } x += wrap ? "</xml>" : ""; if ( top ) { x = "<?xml version=\"1.0\" encoding=\"UTF8\"?>" + x; } return x; } catch ( e ) { utility.error( e, arguments, this ); return undefined; } }
[ "function", "(", "arg", ",", "wrap", ")", "{", "try", "{", "if", "(", "arg", "===", "undefined", ")", "{", "throw", "new", "Error", "(", "label", ".", "error", ".", "invalidArguments", ")", ";", "}", "wrap", "=", "(", "wrap", "!==", "false", ")", ";", "var", "x", "=", "wrap", "?", "\"<xml>\"", ":", "\"\"", ",", "top", "=", "(", "arguments", "[", "2", "]", "!==", "false", ")", ",", "node", ";", "/**\n\t\t\t * Encodes a value as a node\n\t\t\t *\n\t\t\t * @method node\n\t\t\t * @private\n\t\t\t * @param {String} name Node name\n\t\t\t * @param {Value} value Node value\n\t\t\t * @return {String} Node\n\t\t\t */", "node", "=", "function", "(", "name", ",", "value", ")", "{", "var", "output", "=", "\"<n>v</n>\"", ";", "output", "=", "output", ".", "replace", "(", "\"v\"", ",", "(", "regex", ".", "cdata", ".", "test", "(", "value", ")", "?", "\"<![CDATA[\"", "+", "value", "+", "\"]]>\"", ":", "value", ")", ")", ";", "return", "output", ".", "replace", "(", "/", "<(\\/)?n>", "/", "g", ",", "\"<$1\"", "+", "name", "+", "\">\"", ")", ";", "}", ";", "if", "(", "arg", "!==", "null", "&&", "arg", ".", "xml", "!==", "undefined", ")", "{", "arg", "=", "arg", ".", "xml", ";", "}", "if", "(", "arg", "instanceof", "Document", ")", "{", "arg", "=", "(", "new", "XMLSerializer", "(", ")", ")", ".", "serializeToString", "(", "arg", ")", ";", "}", "if", "(", "regex", ".", "boolean_number_string", ".", "test", "(", "typeof", "arg", ")", ")", "{", "x", "+=", "node", "(", "\"item\"", ",", "arg", ")", ";", "}", "else", "if", "(", "typeof", "arg", "===", "\"object\"", ")", "{", "utility", ".", "iterate", "(", "arg", ",", "function", "(", "v", ",", "k", ")", "{", "x", "+=", "xml", ".", "encode", "(", "v", ",", "(", "typeof", "v", "===", "\"object\"", ")", ",", "false", ")", ".", "replace", "(", "/", "item|xml", "/", "g", ",", "isNaN", "(", "k", ")", "?", "k", ":", "\"item\"", ")", ";", "}", ")", ";", "}", "x", "+=", "wrap", "?", "\"</xml>\"", ":", "\"\"", ";", "if", "(", "top", ")", "{", "x", "=", "\"<?xml version=\\\"1.0\\\" encoding=\\\"UTF8\\\"?>\"", "+", "x", ";", "}", "return", "x", ";", "}", "catch", "(", "e", ")", "{", "utility", ".", "error", "(", "e", ",", "arguments", ",", "this", ")", ";", "return", "undefined", ";", "}", "}" ]
Returns XML String from an Object or Array @method encode @param {Mixed} arg Object or Array to cast to XML String @return {String} XML String or undefined
[ "Returns", "XML", "String", "from", "an", "Object", "or", "Array" ]
07c147684bccd28868f377881eb80ffc285cd483
https://github.com/avoidwork/abaaso/blob/07c147684bccd28868f377881eb80ffc285cd483/lib/abaaso.js#L10614-L10671
36,554
tinwatchman/grawlix
grawlix.js
function(str, options) { // get settings var settings; if (_.isUndefined(options) && defaultSettings !== null) { settings = defaultSettings; } else if (!_.isUndefined(options)) { settings = util.parseOptions(options, defaultOptions); } else { settings = util.parseOptions(defaultOptions); defaultSettings = settings; } // return processed string return util.replaceMatches(str, settings); }
javascript
function(str, options) { // get settings var settings; if (_.isUndefined(options) && defaultSettings !== null) { settings = defaultSettings; } else if (!_.isUndefined(options)) { settings = util.parseOptions(options, defaultOptions); } else { settings = util.parseOptions(defaultOptions); defaultSettings = settings; } // return processed string return util.replaceMatches(str, settings); }
[ "function", "(", "str", ",", "options", ")", "{", "// get settings", "var", "settings", ";", "if", "(", "_", ".", "isUndefined", "(", "options", ")", "&&", "defaultSettings", "!==", "null", ")", "{", "settings", "=", "defaultSettings", ";", "}", "else", "if", "(", "!", "_", ".", "isUndefined", "(", "options", ")", ")", "{", "settings", "=", "util", ".", "parseOptions", "(", "options", ",", "defaultOptions", ")", ";", "}", "else", "{", "settings", "=", "util", ".", "parseOptions", "(", "defaultOptions", ")", ";", "defaultSettings", "=", "settings", ";", "}", "// return processed string", "return", "util", ".", "replaceMatches", "(", "str", ",", "settings", ")", ";", "}" ]
Replaces all curse words in the given content string with cartoon-like grawlixes. @param {String} str Content string @param {Object} options Options object. Optional. @param {Object} options.style Style of grawlix to use for replacements. Can be either a string, with the name of the style to use; or an object with a required `name` property. See readme for more details and available options. Defaults to the `ascii` style. @param {Boolean} options.randomize Whether or not to replace curses with randomized or fixed grawlixes. Default is true. @param {Array} options.allowed Array of strings, representing whitelisted words that would otherwise be replaced. Optional. @param {Array} options.filters Array of custom filter objects. These can either reconfigure one of the existing default filter, or represent an entirely new filter. See readme for details. Optional. @param {Array} options.plugins Array of either plugin factory functions or GrawlixPlugin objects. See docs for details. Optional. @return {String} Processed string
[ "Replaces", "all", "curse", "words", "in", "the", "given", "content", "string", "with", "cartoon", "-", "like", "grawlixes", "." ]
235cd9629992b97c62953b813d5034a9546211f1
https://github.com/tinwatchman/grawlix/blob/235cd9629992b97c62953b813d5034a9546211f1/grawlix.js#L56-L69
36,555
tlewowski/zurvan
detail/DateInterceptor.js
FakeDate
function FakeDate(a, b, c, d, e, f, g) { var argsArray = [].splice.call(arguments, 0); var date = argsArray.length === 0 ? new OriginalDate(Date.now()) : makeOriginalDateFromArgs.apply(undefined, argsArray); if (!(this instanceof FakeDate)) { return date.toString(); } this._date = date; }
javascript
function FakeDate(a, b, c, d, e, f, g) { var argsArray = [].splice.call(arguments, 0); var date = argsArray.length === 0 ? new OriginalDate(Date.now()) : makeOriginalDateFromArgs.apply(undefined, argsArray); if (!(this instanceof FakeDate)) { return date.toString(); } this._date = date; }
[ "function", "FakeDate", "(", "a", ",", "b", ",", "c", ",", "d", ",", "e", ",", "f", ",", "g", ")", "{", "var", "argsArray", "=", "[", "]", ".", "splice", ".", "call", "(", "arguments", ",", "0", ")", ";", "var", "date", "=", "argsArray", ".", "length", "===", "0", "?", "new", "OriginalDate", "(", "Date", ".", "now", "(", ")", ")", ":", "makeOriginalDateFromArgs", ".", "apply", "(", "undefined", ",", "argsArray", ")", ";", "if", "(", "!", "(", "this", "instanceof", "FakeDate", ")", ")", "{", "return", "date", ".", "toString", "(", ")", ";", "}", "this", ".", "_date", "=", "date", ";", "}" ]
needs to have 7 arguments to be compliant to length of Date constructor
[ "needs", "to", "have", "7", "arguments", "to", "be", "compliant", "to", "length", "of", "Date", "constructor" ]
22683cbbdb87684fe7f49922e2c4d96ed4a53107
https://github.com/tlewowski/zurvan/blob/22683cbbdb87684fe7f49922e2c4d96ed4a53107/detail/DateInterceptor.js#L88-L100
36,556
retextjs/retext-pos
index.js
patch
function patch(node, tag) { var data = node.data || (node.data = {}) data.partOfSpeech = tag }
javascript
function patch(node, tag) { var data = node.data || (node.data = {}) data.partOfSpeech = tag }
[ "function", "patch", "(", "node", ",", "tag", ")", "{", "var", "data", "=", "node", ".", "data", "||", "(", "node", ".", "data", "=", "{", "}", ")", "data", ".", "partOfSpeech", "=", "tag", "}" ]
Patch a `partOfSpeech` property on `node`s.
[ "Patch", "a", "partOfSpeech", "property", "on", "node", "s", "." ]
e433f6fd8b52e175c2b641c72514aea9b0d4c341
https://github.com/retextjs/retext-pos/blob/e433f6fd8b52e175c2b641c72514aea9b0d4c341/index.js#L57-L60
36,557
datanews/tables
lib/columns-to-model.js
dataToType
function dataToType(data, name, options) { options = options || {}; var knownID = /(^|\s|_)(zip|phone|id)(_|\s|$)/i; // If data is not a simple type, then just use text if (_.isArray(data[0]) || _.isObject(data[0])) { return Sequelize.TEXT; } // Otherise go through each value and see what is found data = _.map(data, function(d) { d = standardize(d); return { value: d, length: (d && d.toString) ? d.toString().length : null, kind: pickle(d, options) }; }); // Filter out any empty values data = _.filter(data, "length"); var counted = _.countBy(data, "kind"); var top = _.sortBy(_.map(counted, function(d, di) { return { kind: di, count: d }; }), "count").reverse()[0]; var maxLength = _.maxBy(data, "length"); maxLength = maxLength ? maxLength.length : maxLength; var kind; // If none, then just assume string if (_.size(data) === 0) { return Sequelize.STRING; } // If there is only one kind, stick with that else if (_.size(counted) === 1) { kind = top.kind; } // If there is an integer and a float, use float else if (counted.INTGER && counted.FLOAT) { kind = "FLOAT"; } else { kind = top.kind; } // Check for long strings if (kind === "STRING" && maxLength * 2 < 512) { return new Sequelize.STRING(Math.floor(maxLength * 2)); } // Otherwise add length else if (kind === "STRING" && maxLength * 2 >= 512) { return Sequelize.TEXT; } // Known not numbers else if ((kind === "INTEGER" || kind === "FLOAT") && knownID.test(name)) { return new Sequelize.STRING(Math.floor(maxLength * 2)); } // Check for long integers else if (kind === "INTEGER" && maxLength > 8) { return Sequelize.BIGINT; } else { return Sequelize[kind]; } }
javascript
function dataToType(data, name, options) { options = options || {}; var knownID = /(^|\s|_)(zip|phone|id)(_|\s|$)/i; // If data is not a simple type, then just use text if (_.isArray(data[0]) || _.isObject(data[0])) { return Sequelize.TEXT; } // Otherise go through each value and see what is found data = _.map(data, function(d) { d = standardize(d); return { value: d, length: (d && d.toString) ? d.toString().length : null, kind: pickle(d, options) }; }); // Filter out any empty values data = _.filter(data, "length"); var counted = _.countBy(data, "kind"); var top = _.sortBy(_.map(counted, function(d, di) { return { kind: di, count: d }; }), "count").reverse()[0]; var maxLength = _.maxBy(data, "length"); maxLength = maxLength ? maxLength.length : maxLength; var kind; // If none, then just assume string if (_.size(data) === 0) { return Sequelize.STRING; } // If there is only one kind, stick with that else if (_.size(counted) === 1) { kind = top.kind; } // If there is an integer and a float, use float else if (counted.INTGER && counted.FLOAT) { kind = "FLOAT"; } else { kind = top.kind; } // Check for long strings if (kind === "STRING" && maxLength * 2 < 512) { return new Sequelize.STRING(Math.floor(maxLength * 2)); } // Otherwise add length else if (kind === "STRING" && maxLength * 2 >= 512) { return Sequelize.TEXT; } // Known not numbers else if ((kind === "INTEGER" || kind === "FLOAT") && knownID.test(name)) { return new Sequelize.STRING(Math.floor(maxLength * 2)); } // Check for long integers else if (kind === "INTEGER" && maxLength > 8) { return Sequelize.BIGINT; } else { return Sequelize[kind]; } }
[ "function", "dataToType", "(", "data", ",", "name", ",", "options", ")", "{", "options", "=", "options", "||", "{", "}", ";", "var", "knownID", "=", "/", "(^|\\s|_)(zip|phone|id)(_|\\s|$)", "/", "i", ";", "// If data is not a simple type, then just use text", "if", "(", "_", ".", "isArray", "(", "data", "[", "0", "]", ")", "||", "_", ".", "isObject", "(", "data", "[", "0", "]", ")", ")", "{", "return", "Sequelize", ".", "TEXT", ";", "}", "// Otherise go through each value and see what is found", "data", "=", "_", ".", "map", "(", "data", ",", "function", "(", "d", ")", "{", "d", "=", "standardize", "(", "d", ")", ";", "return", "{", "value", ":", "d", ",", "length", ":", "(", "d", "&&", "d", ".", "toString", ")", "?", "d", ".", "toString", "(", ")", ".", "length", ":", "null", ",", "kind", ":", "pickle", "(", "d", ",", "options", ")", "}", ";", "}", ")", ";", "// Filter out any empty values", "data", "=", "_", ".", "filter", "(", "data", ",", "\"length\"", ")", ";", "var", "counted", "=", "_", ".", "countBy", "(", "data", ",", "\"kind\"", ")", ";", "var", "top", "=", "_", ".", "sortBy", "(", "_", ".", "map", "(", "counted", ",", "function", "(", "d", ",", "di", ")", "{", "return", "{", "kind", ":", "di", ",", "count", ":", "d", "}", ";", "}", ")", ",", "\"count\"", ")", ".", "reverse", "(", ")", "[", "0", "]", ";", "var", "maxLength", "=", "_", ".", "maxBy", "(", "data", ",", "\"length\"", ")", ";", "maxLength", "=", "maxLength", "?", "maxLength", ".", "length", ":", "maxLength", ";", "var", "kind", ";", "// If none, then just assume string", "if", "(", "_", ".", "size", "(", "data", ")", "===", "0", ")", "{", "return", "Sequelize", ".", "STRING", ";", "}", "// If there is only one kind, stick with that", "else", "if", "(", "_", ".", "size", "(", "counted", ")", "===", "1", ")", "{", "kind", "=", "top", ".", "kind", ";", "}", "// If there is an integer and a float, use float", "else", "if", "(", "counted", ".", "INTGER", "&&", "counted", ".", "FLOAT", ")", "{", "kind", "=", "\"FLOAT\"", ";", "}", "else", "{", "kind", "=", "top", ".", "kind", ";", "}", "// Check for long strings", "if", "(", "kind", "===", "\"STRING\"", "&&", "maxLength", "*", "2", "<", "512", ")", "{", "return", "new", "Sequelize", ".", "STRING", "(", "Math", ".", "floor", "(", "maxLength", "*", "2", ")", ")", ";", "}", "// Otherwise add length", "else", "if", "(", "kind", "===", "\"STRING\"", "&&", "maxLength", "*", "2", ">=", "512", ")", "{", "return", "Sequelize", ".", "TEXT", ";", "}", "// Known not numbers", "else", "if", "(", "(", "kind", "===", "\"INTEGER\"", "||", "kind", "===", "\"FLOAT\"", ")", "&&", "knownID", ".", "test", "(", "name", ")", ")", "{", "return", "new", "Sequelize", ".", "STRING", "(", "Math", ".", "floor", "(", "maxLength", "*", "2", ")", ")", ";", "}", "// Check for long integers", "else", "if", "(", "kind", "===", "\"INTEGER\"", "&&", "maxLength", ">", "8", ")", "{", "return", "Sequelize", ".", "BIGINT", ";", "}", "else", "{", "return", "Sequelize", "[", "kind", "]", ";", "}", "}" ]
Data to type
[ "Data", "to", "type" ]
4b33aa7a944a93260c49baecbb90345211cac789
https://github.com/datanews/tables/blob/4b33aa7a944a93260c49baecbb90345211cac789/lib/columns-to-model.js#L73-L138
36,558
datanews/tables
lib/columns-to-model.js
standardize
function standardize(value) { var isString = _.isString(value); value = utils.standardizeInput(value); return (isString && value === null) ? "" : value; }
javascript
function standardize(value) { var isString = _.isString(value); value = utils.standardizeInput(value); return (isString && value === null) ? "" : value; }
[ "function", "standardize", "(", "value", ")", "{", "var", "isString", "=", "_", ".", "isString", "(", "value", ")", ";", "value", "=", "utils", ".", "standardizeInput", "(", "value", ")", ";", "return", "(", "isString", "&&", "value", "===", "null", ")", "?", "\"\"", ":", "value", ";", "}" ]
Convert value a bit, but keep as string if needed
[ "Convert", "value", "a", "bit", "but", "keep", "as", "string", "if", "needed" ]
4b33aa7a944a93260c49baecbb90345211cac789
https://github.com/datanews/tables/blob/4b33aa7a944a93260c49baecbb90345211cac789/lib/columns-to-model.js#L141-L145
36,559
datanews/tables
lib/columns-to-model.js
pickle
function pickle(value, options) { options = options || {}; // Tests var floatTest = /^(-|)[\d,]+.\d+$/g; var intTest = /^\d+$/g; var booleanTest = /^(true|false)$/g; var dateTest = /^\d{1,2}\/\d{1,2}\/\d{2,4}$/g; var datetimeTest = /^\d{1,2}\/\d{1,2}\/\d{2,4}\s+\d{1,2}:\d{1,2}(:\d{1,2}|)(\s+|)(am|pm|)$/gi; // Test values if ((options.datetimeFormat && moment(value, options.datetimeFormat, true).isValid()) || datetimeTest.test(value)) { return "DATE"; } if ((options.dateFormat && moment(value, options.dateFormat, true).isValid()) || dateTest.test(value)) { return "DATEONLY"; } if (_.isInteger(value) || intTest.test(value)) { return "INTEGER"; } if ((_.isFinite(value) && !_.isInteger(value)) || floatTest.test(value)) { return "FLOAT"; } if (_.isBoolean(value) || booleanTest.test(value)) { return "BOOLEAN"; } return "STRING"; }
javascript
function pickle(value, options) { options = options || {}; // Tests var floatTest = /^(-|)[\d,]+.\d+$/g; var intTest = /^\d+$/g; var booleanTest = /^(true|false)$/g; var dateTest = /^\d{1,2}\/\d{1,2}\/\d{2,4}$/g; var datetimeTest = /^\d{1,2}\/\d{1,2}\/\d{2,4}\s+\d{1,2}:\d{1,2}(:\d{1,2}|)(\s+|)(am|pm|)$/gi; // Test values if ((options.datetimeFormat && moment(value, options.datetimeFormat, true).isValid()) || datetimeTest.test(value)) { return "DATE"; } if ((options.dateFormat && moment(value, options.dateFormat, true).isValid()) || dateTest.test(value)) { return "DATEONLY"; } if (_.isInteger(value) || intTest.test(value)) { return "INTEGER"; } if ((_.isFinite(value) && !_.isInteger(value)) || floatTest.test(value)) { return "FLOAT"; } if (_.isBoolean(value) || booleanTest.test(value)) { return "BOOLEAN"; } return "STRING"; }
[ "function", "pickle", "(", "value", ",", "options", ")", "{", "options", "=", "options", "||", "{", "}", ";", "// Tests", "var", "floatTest", "=", "/", "^(-|)[\\d,]+.\\d+$", "/", "g", ";", "var", "intTest", "=", "/", "^\\d+$", "/", "g", ";", "var", "booleanTest", "=", "/", "^(true|false)$", "/", "g", ";", "var", "dateTest", "=", "/", "^\\d{1,2}\\/\\d{1,2}\\/\\d{2,4}$", "/", "g", ";", "var", "datetimeTest", "=", "/", "^\\d{1,2}\\/\\d{1,2}\\/\\d{2,4}\\s+\\d{1,2}:\\d{1,2}(:\\d{1,2}|)(\\s+|)(am|pm|)$", "/", "gi", ";", "// Test values", "if", "(", "(", "options", ".", "datetimeFormat", "&&", "moment", "(", "value", ",", "options", ".", "datetimeFormat", ",", "true", ")", ".", "isValid", "(", ")", ")", "||", "datetimeTest", ".", "test", "(", "value", ")", ")", "{", "return", "\"DATE\"", ";", "}", "if", "(", "(", "options", ".", "dateFormat", "&&", "moment", "(", "value", ",", "options", ".", "dateFormat", ",", "true", ")", ".", "isValid", "(", ")", ")", "||", "dateTest", ".", "test", "(", "value", ")", ")", "{", "return", "\"DATEONLY\"", ";", "}", "if", "(", "_", ".", "isInteger", "(", "value", ")", "||", "intTest", ".", "test", "(", "value", ")", ")", "{", "return", "\"INTEGER\"", ";", "}", "if", "(", "(", "_", ".", "isFinite", "(", "value", ")", "&&", "!", "_", ".", "isInteger", "(", "value", ")", ")", "||", "floatTest", ".", "test", "(", "value", ")", ")", "{", "return", "\"FLOAT\"", ";", "}", "if", "(", "_", ".", "isBoolean", "(", "value", ")", "||", "booleanTest", ".", "test", "(", "value", ")", ")", "{", "return", "\"BOOLEAN\"", ";", "}", "return", "\"STRING\"", ";", "}" ]
Find type. Should return base Sequelize type
[ "Find", "type", ".", "Should", "return", "base", "Sequelize", "type" ]
4b33aa7a944a93260c49baecbb90345211cac789
https://github.com/datanews/tables/blob/4b33aa7a944a93260c49baecbb90345211cac789/lib/columns-to-model.js#L154-L181
36,560
datanews/tables
examples/ny-campaign-finance.conf.js
function(line) { line = line.toString(); var colCount = _.size(transactionFields); var possibleRow = row + line; var possibleFields = possibleRow.slice(1, possibleRow.length - 1).split("\",\""); // Unfortunately there are some fields that have new line characters in them // and there could be exta commas if (line.slice(-1) !== "\"" || possibleFields.length < colCount) { row = row + line; return false; } // Otherwise just use what we have else { line = row + line; row = ""; } // Parse and match with headers var fields = line.slice(1, line.length - 1).split("\",\""); var parsed = {}; _.each(_.keys(transactionFields), function(h, hi) { parsed[h] = fields[hi]; }); // Use auto parser to coerce the types parsed = this.autoParser(parsed, this.options.models, { dateFormat: this.options.dateFormat, datetimeFormat: this.options.datetimeFormat }); //checkFieldLength(parsed, "other_receipt_code"); return parsed; }
javascript
function(line) { line = line.toString(); var colCount = _.size(transactionFields); var possibleRow = row + line; var possibleFields = possibleRow.slice(1, possibleRow.length - 1).split("\",\""); // Unfortunately there are some fields that have new line characters in them // and there could be exta commas if (line.slice(-1) !== "\"" || possibleFields.length < colCount) { row = row + line; return false; } // Otherwise just use what we have else { line = row + line; row = ""; } // Parse and match with headers var fields = line.slice(1, line.length - 1).split("\",\""); var parsed = {}; _.each(_.keys(transactionFields), function(h, hi) { parsed[h] = fields[hi]; }); // Use auto parser to coerce the types parsed = this.autoParser(parsed, this.options.models, { dateFormat: this.options.dateFormat, datetimeFormat: this.options.datetimeFormat }); //checkFieldLength(parsed, "other_receipt_code"); return parsed; }
[ "function", "(", "line", ")", "{", "line", "=", "line", ".", "toString", "(", ")", ";", "var", "colCount", "=", "_", ".", "size", "(", "transactionFields", ")", ";", "var", "possibleRow", "=", "row", "+", "line", ";", "var", "possibleFields", "=", "possibleRow", ".", "slice", "(", "1", ",", "possibleRow", ".", "length", "-", "1", ")", ".", "split", "(", "\"\\\",\\\"\"", ")", ";", "// Unfortunately there are some fields that have new line characters in them", "// and there could be exta commas", "if", "(", "line", ".", "slice", "(", "-", "1", ")", "!==", "\"\\\"\"", "||", "possibleFields", ".", "length", "<", "colCount", ")", "{", "row", "=", "row", "+", "line", ";", "return", "false", ";", "}", "// Otherwise just use what we have", "else", "{", "line", "=", "row", "+", "line", ";", "row", "=", "\"\"", ";", "}", "// Parse and match with headers", "var", "fields", "=", "line", ".", "slice", "(", "1", ",", "line", ".", "length", "-", "1", ")", ".", "split", "(", "\"\\\",\\\"\"", ")", ";", "var", "parsed", "=", "{", "}", ";", "_", ".", "each", "(", "_", ".", "keys", "(", "transactionFields", ")", ",", "function", "(", "h", ",", "hi", ")", "{", "parsed", "[", "h", "]", "=", "fields", "[", "hi", "]", ";", "}", ")", ";", "// Use auto parser to coerce the types", "parsed", "=", "this", ".", "autoParser", "(", "parsed", ",", "this", ".", "options", ".", "models", ",", "{", "dateFormat", ":", "this", ".", "options", ".", "dateFormat", ",", "datetimeFormat", ":", "this", ".", "options", ".", "datetimeFormat", "}", ")", ";", "//checkFieldLength(parsed, \"other_receipt_code\");", "return", "parsed", ";", "}" ]
Comes in as buffer
[ "Comes", "in", "as", "buffer" ]
4b33aa7a944a93260c49baecbb90345211cac789
https://github.com/datanews/tables/blob/4b33aa7a944a93260c49baecbb90345211cac789/examples/ny-campaign-finance.conf.js#L30-L64
36,561
datanews/tables
examples/ny-campaign-finance.conf.js
checkFieldLength
function checkFieldLength(parsed, field, length) { length = length || transactionFields[field].options.length; if (parsed.transactions[field] && parsed.transactions[field].toString().length > length) { console.log(parsed.transactions); console.log(field, parsed.transactions[field]); } }
javascript
function checkFieldLength(parsed, field, length) { length = length || transactionFields[field].options.length; if (parsed.transactions[field] && parsed.transactions[field].toString().length > length) { console.log(parsed.transactions); console.log(field, parsed.transactions[field]); } }
[ "function", "checkFieldLength", "(", "parsed", ",", "field", ",", "length", ")", "{", "length", "=", "length", "||", "transactionFields", "[", "field", "]", ".", "options", ".", "length", ";", "if", "(", "parsed", ".", "transactions", "[", "field", "]", "&&", "parsed", ".", "transactions", "[", "field", "]", ".", "toString", "(", ")", ".", "length", ">", "length", ")", "{", "console", ".", "log", "(", "parsed", ".", "transactions", ")", ";", "console", ".", "log", "(", "field", ",", "parsed", ".", "transactions", "[", "field", "]", ")", ";", "}", "}" ]
Just a helpful function to help find some issues.
[ "Just", "a", "helpful", "function", "to", "help", "find", "some", "issues", "." ]
4b33aa7a944a93260c49baecbb90345211cac789
https://github.com/datanews/tables/blob/4b33aa7a944a93260c49baecbb90345211cac789/examples/ny-campaign-finance.conf.js#L144-L150
36,562
HumanBrainProject/jsdoc-sphinx
template/publish.js
improveFunc
function improveFunc(doclet) { doclet.signature = doclet.name + '('; _.each(doclet.params, function(p, i) { if (!(p && p.type && p.type.names)) { logger.debug('Bad parameter', p, doclet.longname); return; } p.signature = ':param ' + p.type && p.type.names && p.type.names.join('|'); p.signature += ' ' + p.name; if (p.optional) { doclet.signature += '['; } if (i > 0) { doclet.signature += ', '; } doclet.signature += p.name; if (p.optional) { doclet.signature += ']'; } return p.name; }); doclet.signature += ')'; _.each(doclet.returns, function(r) { if (!(r && r.type && r.type.names)) { logger.debug('Bad return', r, doclet.longname); return; } r.signature = ':return ' + r.type && r.type.names && r.type.names.join('|'); }); }
javascript
function improveFunc(doclet) { doclet.signature = doclet.name + '('; _.each(doclet.params, function(p, i) { if (!(p && p.type && p.type.names)) { logger.debug('Bad parameter', p, doclet.longname); return; } p.signature = ':param ' + p.type && p.type.names && p.type.names.join('|'); p.signature += ' ' + p.name; if (p.optional) { doclet.signature += '['; } if (i > 0) { doclet.signature += ', '; } doclet.signature += p.name; if (p.optional) { doclet.signature += ']'; } return p.name; }); doclet.signature += ')'; _.each(doclet.returns, function(r) { if (!(r && r.type && r.type.names)) { logger.debug('Bad return', r, doclet.longname); return; } r.signature = ':return ' + r.type && r.type.names && r.type.names.join('|'); }); }
[ "function", "improveFunc", "(", "doclet", ")", "{", "doclet", ".", "signature", "=", "doclet", ".", "name", "+", "'('", ";", "_", ".", "each", "(", "doclet", ".", "params", ",", "function", "(", "p", ",", "i", ")", "{", "if", "(", "!", "(", "p", "&&", "p", ".", "type", "&&", "p", ".", "type", ".", "names", ")", ")", "{", "logger", ".", "debug", "(", "'Bad parameter'", ",", "p", ",", "doclet", ".", "longname", ")", ";", "return", ";", "}", "p", ".", "signature", "=", "':param '", "+", "p", ".", "type", "&&", "p", ".", "type", ".", "names", "&&", "p", ".", "type", ".", "names", ".", "join", "(", "'|'", ")", ";", "p", ".", "signature", "+=", "' '", "+", "p", ".", "name", ";", "if", "(", "p", ".", "optional", ")", "{", "doclet", ".", "signature", "+=", "'['", ";", "}", "if", "(", "i", ">", "0", ")", "{", "doclet", ".", "signature", "+=", "', '", ";", "}", "doclet", ".", "signature", "+=", "p", ".", "name", ";", "if", "(", "p", ".", "optional", ")", "{", "doclet", ".", "signature", "+=", "']'", ";", "}", "return", "p", ".", "name", ";", "}", ")", ";", "doclet", ".", "signature", "+=", "')'", ";", "_", ".", "each", "(", "doclet", ".", "returns", ",", "function", "(", "r", ")", "{", "if", "(", "!", "(", "r", "&&", "r", ".", "type", "&&", "r", ".", "type", ".", "names", ")", ")", "{", "logger", ".", "debug", "(", "'Bad return'", ",", "r", ",", "doclet", ".", "longname", ")", ";", "return", ";", "}", "r", ".", "signature", "=", "':return '", "+", "r", ".", "type", "&&", "r", ".", "type", ".", "names", "&&", "r", ".", "type", ".", "names", ".", "join", "(", "'|'", ")", ";", "}", ")", ";", "}" ]
Write the function signature for the current function doclet. @param {object} doclet function doclet
[ "Write", "the", "function", "signature", "for", "the", "current", "function", "doclet", "." ]
9d7c1d318ce535640588e7308917729c3849bc83
https://github.com/HumanBrainProject/jsdoc-sphinx/blob/9d7c1d318ce535640588e7308917729c3849bc83/template/publish.js#L56-L89
36,563
HumanBrainProject/jsdoc-sphinx
template/publish.js
generate
function generate(target, generator) { return function(cb) { logger.debug('generate', target); generator(context, handleErrorCallback(function(err, data) { if (err) { logger.error('cannot generate ' + target); logger.debug(err); return; } write(target, data, cb); })); }; }
javascript
function generate(target, generator) { return function(cb) { logger.debug('generate', target); generator(context, handleErrorCallback(function(err, data) { if (err) { logger.error('cannot generate ' + target); logger.debug(err); return; } write(target, data, cb); })); }; }
[ "function", "generate", "(", "target", ",", "generator", ")", "{", "return", "function", "(", "cb", ")", "{", "logger", ".", "debug", "(", "'generate'", ",", "target", ")", ";", "generator", "(", "context", ",", "handleErrorCallback", "(", "function", "(", "err", ",", "data", ")", "{", "if", "(", "err", ")", "{", "logger", ".", "error", "(", "'cannot generate '", "+", "target", ")", ";", "logger", ".", "debug", "(", "err", ")", ";", "return", ";", "}", "write", "(", "target", ",", "data", ",", "cb", ")", ";", "}", ")", ")", ";", "}", ";", "}" ]
Return a function that will asynchronously generate the documentation and write the result. @param {object} target the target @param {function} generator the generator function to use @return {function} the function that will build this part of the documentation
[ "Return", "a", "function", "that", "will", "asynchronously", "generate", "the", "documentation", "and", "write", "the", "result", "." ]
9d7c1d318ce535640588e7308917729c3849bc83
https://github.com/HumanBrainProject/jsdoc-sphinx/blob/9d7c1d318ce535640588e7308917729c3849bc83/template/publish.js#L123-L135
36,564
HumanBrainProject/jsdoc-sphinx
template/publish.js
registerLink
function registerLink(doclet) { var url = helper.createLink(doclet); helper.registerLink(doclet.longname, url); doclet.rstLink = url.substr(0, url.length - helper.fileExtension.length); // Parent link if (!doclet.memberof) { return; } var parent; parent = helper.find(context.data, {longname: doclet.memberof}); if (parent && parent.length > 0) { doclet.parentRstLink = parent[0].rstLink; } // Reference code doclet.rstReference = doclet.parentRstLink + '.' + doclet.name; }
javascript
function registerLink(doclet) { var url = helper.createLink(doclet); helper.registerLink(doclet.longname, url); doclet.rstLink = url.substr(0, url.length - helper.fileExtension.length); // Parent link if (!doclet.memberof) { return; } var parent; parent = helper.find(context.data, {longname: doclet.memberof}); if (parent && parent.length > 0) { doclet.parentRstLink = parent[0].rstLink; } // Reference code doclet.rstReference = doclet.parentRstLink + '.' + doclet.name; }
[ "function", "registerLink", "(", "doclet", ")", "{", "var", "url", "=", "helper", ".", "createLink", "(", "doclet", ")", ";", "helper", ".", "registerLink", "(", "doclet", ".", "longname", ",", "url", ")", ";", "doclet", ".", "rstLink", "=", "url", ".", "substr", "(", "0", ",", "url", ".", "length", "-", "helper", ".", "fileExtension", ".", "length", ")", ";", "// Parent link", "if", "(", "!", "doclet", ".", "memberof", ")", "{", "return", ";", "}", "var", "parent", ";", "parent", "=", "helper", ".", "find", "(", "context", ".", "data", ",", "{", "longname", ":", "doclet", ".", "memberof", "}", ")", ";", "if", "(", "parent", "&&", "parent", ".", "length", ">", "0", ")", "{", "doclet", ".", "parentRstLink", "=", "parent", "[", "0", "]", ".", "rstLink", ";", "}", "// Reference code", "doclet", ".", "rstReference", "=", "doclet", ".", "parentRstLink", "+", "'.'", "+", "doclet", ".", "name", ";", "}" ]
Add a link to the link registry. @param {object} doclet the doclet to create a link for
[ "Add", "a", "link", "to", "the", "link", "registry", "." ]
9d7c1d318ce535640588e7308917729c3849bc83
https://github.com/HumanBrainProject/jsdoc-sphinx/blob/9d7c1d318ce535640588e7308917729c3849bc83/template/publish.js#L141-L157
36,565
HumanBrainProject/jsdoc-sphinx
template/publish.js
write
function write(relPath, data, cb) { var target = path.join(context.destination, relPath); mkdirp(path.dirname(target), handleErrorCallback(function() { fs.writeFileSync(target, data); handleErrorCallback(cb)(null, target); logger.debug('file written: %s', target); })); }
javascript
function write(relPath, data, cb) { var target = path.join(context.destination, relPath); mkdirp(path.dirname(target), handleErrorCallback(function() { fs.writeFileSync(target, data); handleErrorCallback(cb)(null, target); logger.debug('file written: %s', target); })); }
[ "function", "write", "(", "relPath", ",", "data", ",", "cb", ")", "{", "var", "target", "=", "path", ".", "join", "(", "context", ".", "destination", ",", "relPath", ")", ";", "mkdirp", "(", "path", ".", "dirname", "(", "target", ")", ",", "handleErrorCallback", "(", "function", "(", ")", "{", "fs", ".", "writeFileSync", "(", "target", ",", "data", ")", ";", "handleErrorCallback", "(", "cb", ")", "(", "null", ",", "target", ")", ";", "logger", ".", "debug", "(", "'file written: %s'", ",", "target", ")", ";", "}", ")", ")", ";", "}" ]
Handle all write operations. @private @param {string} relPath Relative path in the ouput directory @param {string} data File content @param {publish.writeCallback} cb node fs.write compatible callback @return {undefined}
[ "Handle", "all", "write", "operations", "." ]
9d7c1d318ce535640588e7308917729c3849bc83
https://github.com/HumanBrainProject/jsdoc-sphinx/blob/9d7c1d318ce535640588e7308917729c3849bc83/template/publish.js#L168-L176
36,566
HumanBrainProject/jsdoc-sphinx
template/publish.js
handleErrorCallback
function handleErrorCallback(cb) { return function(err) { if (err) { logger.error(err); return cb(err); } return cb.apply(this, arguments); }; }
javascript
function handleErrorCallback(cb) { return function(err) { if (err) { logger.error(err); return cb(err); } return cb.apply(this, arguments); }; }
[ "function", "handleErrorCallback", "(", "cb", ")", "{", "return", "function", "(", "err", ")", "{", "if", "(", "err", ")", "{", "logger", ".", "error", "(", "err", ")", ";", "return", "cb", "(", "err", ")", ";", "}", "return", "cb", ".", "apply", "(", "this", ",", "arguments", ")", ";", "}", ";", "}" ]
Gracefully handle errors in callback. @param {Function} cb the callback to handle error for @return {any} the result of cb
[ "Gracefully", "handle", "errors", "in", "callback", "." ]
9d7c1d318ce535640588e7308917729c3849bc83
https://github.com/HumanBrainProject/jsdoc-sphinx/blob/9d7c1d318ce535640588e7308917729c3849bc83/template/publish.js#L183-L191
36,567
datanews/tables
lib/auto-parser.js
autoParse
function autoParse(data, models, options) { options = options || {}; var parsed = {}; // Go through each data point _.each(data, function(value, field) { var d = findField(field, models); // Find field in if (d) { parsed[d.modelName] = parsed[d.modelName] || {}; parsed[d.modelName][d.field.name] = parse(value, d.field, options); } }); return parsed; }
javascript
function autoParse(data, models, options) { options = options || {}; var parsed = {}; // Go through each data point _.each(data, function(value, field) { var d = findField(field, models); // Find field in if (d) { parsed[d.modelName] = parsed[d.modelName] || {}; parsed[d.modelName][d.field.name] = parse(value, d.field, options); } }); return parsed; }
[ "function", "autoParse", "(", "data", ",", "models", ",", "options", ")", "{", "options", "=", "options", "||", "{", "}", ";", "var", "parsed", "=", "{", "}", ";", "// Go through each data point", "_", ".", "each", "(", "data", ",", "function", "(", "value", ",", "field", ")", "{", "var", "d", "=", "findField", "(", "field", ",", "models", ")", ";", "// Find field in", "if", "(", "d", ")", "{", "parsed", "[", "d", ".", "modelName", "]", "=", "parsed", "[", "d", ".", "modelName", "]", "||", "{", "}", ";", "parsed", "[", "d", ".", "modelName", "]", "[", "d", ".", "field", ".", "name", "]", "=", "parse", "(", "value", ",", "d", ".", "field", ",", "options", ")", ";", "}", "}", ")", ";", "return", "parsed", ";", "}" ]
Main function. Takes a row of incoming data and the models definition
[ "Main", "function", ".", "Takes", "a", "row", "of", "incoming", "data", "and", "the", "models", "definition" ]
4b33aa7a944a93260c49baecbb90345211cac789
https://github.com/datanews/tables/blob/4b33aa7a944a93260c49baecbb90345211cac789/lib/auto-parser.js#L12-L28
36,568
datanews/tables
lib/auto-parser.js
parse
function parse(value, field, options) { options = options || {}; var parsed = utils.standardizeInput(value); // Integer if (field.type.key === "BOOLEAN") { parsed = utils.toBoolean(parsed); } else if (field.type.key === "INTEGER") { parsed = utils.toInteger(parsed); } else if (field.type.key === "FLOAT") { parsed = utils.toFloat(parsed); } else if (field.type.key === "DATEONLY") { parsed = utils.toDate(parsed, options.dateFormat); } else if (field.type.key === "DATE") { parsed = utils.toDateTime(parsed, options.datetimeFormat); } else if (field.type.key === "STRING") { parsed = utils.toString(parsed); } return parsed; }
javascript
function parse(value, field, options) { options = options || {}; var parsed = utils.standardizeInput(value); // Integer if (field.type.key === "BOOLEAN") { parsed = utils.toBoolean(parsed); } else if (field.type.key === "INTEGER") { parsed = utils.toInteger(parsed); } else if (field.type.key === "FLOAT") { parsed = utils.toFloat(parsed); } else if (field.type.key === "DATEONLY") { parsed = utils.toDate(parsed, options.dateFormat); } else if (field.type.key === "DATE") { parsed = utils.toDateTime(parsed, options.datetimeFormat); } else if (field.type.key === "STRING") { parsed = utils.toString(parsed); } return parsed; }
[ "function", "parse", "(", "value", ",", "field", ",", "options", ")", "{", "options", "=", "options", "||", "{", "}", ";", "var", "parsed", "=", "utils", ".", "standardizeInput", "(", "value", ")", ";", "// Integer", "if", "(", "field", ".", "type", ".", "key", "===", "\"BOOLEAN\"", ")", "{", "parsed", "=", "utils", ".", "toBoolean", "(", "parsed", ")", ";", "}", "else", "if", "(", "field", ".", "type", ".", "key", "===", "\"INTEGER\"", ")", "{", "parsed", "=", "utils", ".", "toInteger", "(", "parsed", ")", ";", "}", "else", "if", "(", "field", ".", "type", ".", "key", "===", "\"FLOAT\"", ")", "{", "parsed", "=", "utils", ".", "toFloat", "(", "parsed", ")", ";", "}", "else", "if", "(", "field", ".", "type", ".", "key", "===", "\"DATEONLY\"", ")", "{", "parsed", "=", "utils", ".", "toDate", "(", "parsed", ",", "options", ".", "dateFormat", ")", ";", "}", "else", "if", "(", "field", ".", "type", ".", "key", "===", "\"DATE\"", ")", "{", "parsed", "=", "utils", ".", "toDateTime", "(", "parsed", ",", "options", ".", "datetimeFormat", ")", ";", "}", "else", "if", "(", "field", ".", "type", ".", "key", "===", "\"STRING\"", ")", "{", "parsed", "=", "utils", ".", "toString", "(", "parsed", ")", ";", "}", "return", "parsed", ";", "}" ]
Parse value based on field definition
[ "Parse", "value", "based", "on", "field", "definition" ]
4b33aa7a944a93260c49baecbb90345211cac789
https://github.com/datanews/tables/blob/4b33aa7a944a93260c49baecbb90345211cac789/lib/auto-parser.js#L31-L56
36,569
datanews/tables
lib/auto-parser.js
findField
function findField(field, models) { var found = false; _.each(models, function(model) { // Go through fields _.each(model.fields, function(f) { if (f.input === field) { found = { modelName: model.modelName, field: f }; } }); }); return found; }
javascript
function findField(field, models) { var found = false; _.each(models, function(model) { // Go through fields _.each(model.fields, function(f) { if (f.input === field) { found = { modelName: model.modelName, field: f }; } }); }); return found; }
[ "function", "findField", "(", "field", ",", "models", ")", "{", "var", "found", "=", "false", ";", "_", ".", "each", "(", "models", ",", "function", "(", "model", ")", "{", "// Go through fields", "_", ".", "each", "(", "model", ".", "fields", ",", "function", "(", "f", ")", "{", "if", "(", "f", ".", "input", "===", "field", ")", "{", "found", "=", "{", "modelName", ":", "model", ".", "modelName", ",", "field", ":", "f", "}", ";", "}", "}", ")", ";", "}", ")", ";", "return", "found", ";", "}" ]
Find definition in models
[ "Find", "definition", "in", "models" ]
4b33aa7a944a93260c49baecbb90345211cac789
https://github.com/datanews/tables/blob/4b33aa7a944a93260c49baecbb90345211cac789/lib/auto-parser.js#L59-L75
36,570
spreadshirt/rAppid.js-sprd
sprd/manager/ApiBasketManager.js
function (element, quantity, callback) { if (this.$.basket) { this.fixBasketCurrency(); var basketItem = this.$.basket.addElement(element, quantity); element = basketItem.$.element; var originId = this.$.originId; if (originId) { basketItem.set('origin', new Entity({ id: originId })); } this.extendElementWithLinks(element); } callback && callback(); }
javascript
function (element, quantity, callback) { if (this.$.basket) { this.fixBasketCurrency(); var basketItem = this.$.basket.addElement(element, quantity); element = basketItem.$.element; var originId = this.$.originId; if (originId) { basketItem.set('origin', new Entity({ id: originId })); } this.extendElementWithLinks(element); } callback && callback(); }
[ "function", "(", "element", ",", "quantity", ",", "callback", ")", "{", "if", "(", "this", ".", "$", ".", "basket", ")", "{", "this", ".", "fixBasketCurrency", "(", ")", ";", "var", "basketItem", "=", "this", ".", "$", ".", "basket", ".", "addElement", "(", "element", ",", "quantity", ")", ";", "element", "=", "basketItem", ".", "$", ".", "element", ";", "var", "originId", "=", "this", ".", "$", ".", "originId", ";", "if", "(", "originId", ")", "{", "basketItem", ".", "set", "(", "'origin'", ",", "new", "Entity", "(", "{", "id", ":", "originId", "}", ")", ")", ";", "}", "this", ".", "extendElementWithLinks", "(", "element", ")", ";", "}", "callback", "&&", "callback", "(", ")", ";", "}" ]
Adds an element to the basket without saving it @param element @param quantity @param callback
[ "Adds", "an", "element", "to", "the", "basket", "without", "saving", "it" ]
b56f9f47fe01332f5bf885eaf4db59014f099019
https://github.com/spreadshirt/rAppid.js-sprd/blob/b56f9f47fe01332f5bf885eaf4db59014f099019/sprd/manager/ApiBasketManager.js#L105-L124
36,571
spreadshirt/rAppid.js-sprd
sprd/manager/ApiBasketManager.js
function (basketItem, element, quantity, cb) { this.extendElementWithLinks(element); basketItem.set({ element: element, quantity: quantity }); basketItem.save(null, cb); }
javascript
function (basketItem, element, quantity, cb) { this.extendElementWithLinks(element); basketItem.set({ element: element, quantity: quantity }); basketItem.save(null, cb); }
[ "function", "(", "basketItem", ",", "element", ",", "quantity", ",", "cb", ")", "{", "this", ".", "extendElementWithLinks", "(", "element", ")", ";", "basketItem", ".", "set", "(", "{", "element", ":", "element", ",", "quantity", ":", "quantity", "}", ")", ";", "basketItem", ".", "save", "(", "null", ",", "cb", ")", ";", "}" ]
Updates the given basket item @param {sprd.model.BasketItem} basketItem @param {sprd.model.ConcreteElement} element @param {Number} quantity @param {Function} cb
[ "Updates", "the", "given", "basket", "item" ]
b56f9f47fe01332f5bf885eaf4db59014f099019
https://github.com/spreadshirt/rAppid.js-sprd/blob/b56f9f47fe01332f5bf885eaf4db59014f099019/sprd/manager/ApiBasketManager.js#L145-L154
36,572
HumanBrainProject/jsdoc-sphinx
template/util/template.js
docletChildren
function docletChildren(context, doclet, kinds) { if (!kinds) { kinds = mainDocletKinds; } var results = {}; _.each(kinds, function(k) { var q = { kind: k, memberof: doclet ? doclet.longname : {isUndefined: true} }; results[k] = helper.find(context.data, q); }); logger.debug((doclet ? doclet.longname : '<global>'), 'doclet children', 'kinds:', kinds, 'results:', results); return results; }
javascript
function docletChildren(context, doclet, kinds) { if (!kinds) { kinds = mainDocletKinds; } var results = {}; _.each(kinds, function(k) { var q = { kind: k, memberof: doclet ? doclet.longname : {isUndefined: true} }; results[k] = helper.find(context.data, q); }); logger.debug((doclet ? doclet.longname : '<global>'), 'doclet children', 'kinds:', kinds, 'results:', results); return results; }
[ "function", "docletChildren", "(", "context", ",", "doclet", ",", "kinds", ")", "{", "if", "(", "!", "kinds", ")", "{", "kinds", "=", "mainDocletKinds", ";", "}", "var", "results", "=", "{", "}", ";", "_", ".", "each", "(", "kinds", ",", "function", "(", "k", ")", "{", "var", "q", "=", "{", "kind", ":", "k", ",", "memberof", ":", "doclet", "?", "doclet", ".", "longname", ":", "{", "isUndefined", ":", "true", "}", "}", ";", "results", "[", "k", "]", "=", "helper", ".", "find", "(", "context", ".", "data", ",", "q", ")", ";", "}", ")", ";", "logger", ".", "debug", "(", "(", "doclet", "?", "doclet", ".", "longname", ":", "'<global>'", ")", ",", "'doclet children'", ",", "'kinds:'", ",", "kinds", ",", "'results:'", ",", "results", ")", ";", "return", "results", ";", "}" ]
Find the doclet children of a given type. @param {object} context the jsdoc context @param {object} doclet the doclet to use @param {string} kinds the kind of children to return (function, module, ...) @return {array} All the children doclet matching the parameters
[ "Find", "the", "doclet", "children", "of", "a", "given", "type", "." ]
9d7c1d318ce535640588e7308917729c3849bc83
https://github.com/HumanBrainProject/jsdoc-sphinx/blob/9d7c1d318ce535640588e7308917729c3849bc83/template/util/template.js#L25-L42
36,573
HumanBrainProject/jsdoc-sphinx
template/util/template.js
example
function example() { return function(data, render) { var output = '.. code-block:: javascript\n'; var lines = render(data).split('\n'); logger.debug('line-0', data); if (lines.length && lines[0].match(/^<caption>.*<\/caption>$/)) { output += ' :caption: ' + lines.shift().slice(9, -10) + '\n'; } output += '\n'; for (var i = 0; i < lines.length; i++) { output += ' ' + lines[i] + '\n'; } return render(output); }; }
javascript
function example() { return function(data, render) { var output = '.. code-block:: javascript\n'; var lines = render(data).split('\n'); logger.debug('line-0', data); if (lines.length && lines[0].match(/^<caption>.*<\/caption>$/)) { output += ' :caption: ' + lines.shift().slice(9, -10) + '\n'; } output += '\n'; for (var i = 0; i < lines.length; i++) { output += ' ' + lines[i] + '\n'; } return render(output); }; }
[ "function", "example", "(", ")", "{", "return", "function", "(", "data", ",", "render", ")", "{", "var", "output", "=", "'.. code-block:: javascript\\n'", ";", "var", "lines", "=", "render", "(", "data", ")", ".", "split", "(", "'\\n'", ")", ";", "logger", ".", "debug", "(", "'line-0'", ",", "data", ")", ";", "if", "(", "lines", ".", "length", "&&", "lines", "[", "0", "]", ".", "match", "(", "/", "^<caption>.*<\\/caption>$", "/", ")", ")", "{", "output", "+=", "' :caption: '", "+", "lines", ".", "shift", "(", ")", ".", "slice", "(", "9", ",", "-", "10", ")", "+", "'\\n'", ";", "}", "output", "+=", "'\\n'", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "lines", ".", "length", ";", "i", "++", ")", "{", "output", "+=", "' '", "+", "lines", "[", "i", "]", "+", "'\\n'", ";", "}", "return", "render", "(", "output", ")", ";", "}", ";", "}" ]
Format a code example. @return {string} the example output
[ "Format", "a", "code", "example", "." ]
9d7c1d318ce535640588e7308917729c3849bc83
https://github.com/HumanBrainProject/jsdoc-sphinx/blob/9d7c1d318ce535640588e7308917729c3849bc83/template/util/template.js#L48-L62
36,574
spreadshirt/rAppid.js-sprd
sprd/data/IImageUploadService.js
function(data, restrictions, callback) { var image; if (restrictions instanceof Function) { callback = restrictions; restrictions = null; } if (data instanceof BlobImage || data instanceof iFrameUpload) { image = data; } else if (_.isString(data)) { image = new RemoteImage({ src: data }); } else { image = new FileSystemImage({ file: data }); } var uploadDesign = new UploadDesign({ image: image }); this._uploadDesign(uploadDesign, restrictions, callback); return uploadDesign; }
javascript
function(data, restrictions, callback) { var image; if (restrictions instanceof Function) { callback = restrictions; restrictions = null; } if (data instanceof BlobImage || data instanceof iFrameUpload) { image = data; } else if (_.isString(data)) { image = new RemoteImage({ src: data }); } else { image = new FileSystemImage({ file: data }); } var uploadDesign = new UploadDesign({ image: image }); this._uploadDesign(uploadDesign, restrictions, callback); return uploadDesign; }
[ "function", "(", "data", ",", "restrictions", ",", "callback", ")", "{", "var", "image", ";", "if", "(", "restrictions", "instanceof", "Function", ")", "{", "callback", "=", "restrictions", ";", "restrictions", "=", "null", ";", "}", "if", "(", "data", "instanceof", "BlobImage", "||", "data", "instanceof", "iFrameUpload", ")", "{", "image", "=", "data", ";", "}", "else", "if", "(", "_", ".", "isString", "(", "data", ")", ")", "{", "image", "=", "new", "RemoteImage", "(", "{", "src", ":", "data", "}", ")", ";", "}", "else", "{", "image", "=", "new", "FileSystemImage", "(", "{", "file", ":", "data", "}", ")", ";", "}", "var", "uploadDesign", "=", "new", "UploadDesign", "(", "{", "image", ":", "image", "}", ")", ";", "this", ".", "_uploadDesign", "(", "uploadDesign", ",", "restrictions", ",", "callback", ")", ";", "return", "uploadDesign", ";", "}" ]
Upload image from local file system @param {sprd.entity.Image | sprd.data.iFrameUpload} data @param {Object} restrictions @param {Function} callback @returns {sprd.type.UploadDesign}
[ "Upload", "image", "from", "local", "file", "system" ]
b56f9f47fe01332f5bf885eaf4db59014f099019
https://github.com/spreadshirt/rAppid.js-sprd/blob/b56f9f47fe01332f5bf885eaf4db59014f099019/sprd/data/IImageUploadService.js#L18-L47
36,575
datanews/tables
lib/output.js
function(on, options) { options = options || {}; this.on = _.isUndefined(on) ? true : !!on; this.useBullet = _.isUndefined(options.useBullet) ? true : !!options.useBullet; // Use stderr since this is all just nice info to have and not data // http://www.jstorimer.com/blogs/workingwithcode/7766119-when-to-use-stderr-instead-of-stdout this.output = options.output || process.stderr; // Other properties this.bullet = bullet; this.cc = cc; this.chalk = chalk; this.progressOptionsComplete = cc.bgo + " " + cc.bgc; this.progressOptionsIncomplete = cc.bwo + " " + cc.bwc; this.progressBarFormat = (this.useBullet ? bullet : "") + "[:bar] :percent | :elapseds elapsed | ~:etas left"; this.spinnerFormat = (this.useBullet ? bullet : "") + "%s"; }
javascript
function(on, options) { options = options || {}; this.on = _.isUndefined(on) ? true : !!on; this.useBullet = _.isUndefined(options.useBullet) ? true : !!options.useBullet; // Use stderr since this is all just nice info to have and not data // http://www.jstorimer.com/blogs/workingwithcode/7766119-when-to-use-stderr-instead-of-stdout this.output = options.output || process.stderr; // Other properties this.bullet = bullet; this.cc = cc; this.chalk = chalk; this.progressOptionsComplete = cc.bgo + " " + cc.bgc; this.progressOptionsIncomplete = cc.bwo + " " + cc.bwc; this.progressBarFormat = (this.useBullet ? bullet : "") + "[:bar] :percent | :elapseds elapsed | ~:etas left"; this.spinnerFormat = (this.useBullet ? bullet : "") + "%s"; }
[ "function", "(", "on", ",", "options", ")", "{", "options", "=", "options", "||", "{", "}", ";", "this", ".", "on", "=", "_", ".", "isUndefined", "(", "on", ")", "?", "true", ":", "!", "!", "on", ";", "this", ".", "useBullet", "=", "_", ".", "isUndefined", "(", "options", ".", "useBullet", ")", "?", "true", ":", "!", "!", "options", ".", "useBullet", ";", "// Use stderr since this is all just nice info to have and not data", "// http://www.jstorimer.com/blogs/workingwithcode/7766119-when-to-use-stderr-instead-of-stdout", "this", ".", "output", "=", "options", ".", "output", "||", "process", ".", "stderr", ";", "// Other properties", "this", ".", "bullet", "=", "bullet", ";", "this", ".", "cc", "=", "cc", ";", "this", ".", "chalk", "=", "chalk", ";", "this", ".", "progressOptionsComplete", "=", "cc", ".", "bgo", "+", "\" \"", "+", "cc", ".", "bgc", ";", "this", ".", "progressOptionsIncomplete", "=", "cc", ".", "bwo", "+", "\" \"", "+", "cc", ".", "bwc", ";", "this", ".", "progressBarFormat", "=", "(", "this", ".", "useBullet", "?", "bullet", ":", "\"\"", ")", "+", "\"[:bar] :percent | :elapseds elapsed | ~:etas left\"", ";", "this", ".", "spinnerFormat", "=", "(", "this", ".", "useBullet", "?", "bullet", ":", "\"\"", ")", "+", "\"%s\"", ";", "}" ]
Create class for output, this is mostly used so that turning off and on output can be managed more easily
[ "Create", "class", "for", "output", "this", "is", "mostly", "used", "so", "that", "turning", "off", "and", "on", "output", "can", "be", "managed", "more", "easily" ]
4b33aa7a944a93260c49baecbb90345211cac789
https://github.com/datanews/tables/blob/4b33aa7a944a93260c49baecbb90345211cac789/lib/output.js#L25-L42
36,576
tinwatchman/grawlix
util.js
function(settings, pluginInfo, options) { // resolve plugin and plugin options var plugin; if (_.has(pluginInfo, 'plugin')) { plugin = pluginInfo.plugin; } else if (_.has(pluginInfo, 'module')) { // make sure we don't load the same module twice if (_.contains(settings.loadedModules, pluginInfo.module)) { return settings; } // try to load module try { plugin = require(pluginInfo.module); } catch (err) { throw new GrawlixPluginError({ msg: "cannot find module '" + pluginInfo.module + "'", plugin: pluginInfo, trace: new Error() }); } settings.loadedModules.push(pluginInfo.module); } else { plugin = pluginInfo; } var pluginOpts = _.has(pluginInfo, 'options') ? pluginInfo.options : {}; // instantiate plugin if necessary if (_.isFunction(plugin)) { plugin = plugin(pluginOpts, options); } // validate plugin if (!(plugin instanceof GrawlixPlugin)) { throw new GrawlixPluginError({ msg: 'invalid plugin', plugin: pluginInfo }); } else if (plugin.name === null || _.isEmpty(plugin.name)) { throw new GrawlixPluginError({ msg: 'invalid plugin - name property not provided', plugin: pluginInfo }); } else if (_.contains(settings.loadedPlugins, plugin.name)) { // don't load the same plugin twice return settings; } // initialize plugin plugin.init(pluginOpts); // load filters if (!_.isUndefined(plugin.filters) && _.isArray(plugin.filters)) { try { loadFilters(settings, plugin.filters, options.allowed); } catch (err) { err.plugin = pluginInfo; throw err; } } // load styles if (!_.isUndefined(plugin.styles) && _.isArray(plugin.styles)) { try { loadStyles(settings, plugin.styles); } catch (err) { err.plugin = pluginInfo; throw err; } } // add name to loaded plugins settings.loadedPlugins.push(plugin.name); // return return settings; }
javascript
function(settings, pluginInfo, options) { // resolve plugin and plugin options var plugin; if (_.has(pluginInfo, 'plugin')) { plugin = pluginInfo.plugin; } else if (_.has(pluginInfo, 'module')) { // make sure we don't load the same module twice if (_.contains(settings.loadedModules, pluginInfo.module)) { return settings; } // try to load module try { plugin = require(pluginInfo.module); } catch (err) { throw new GrawlixPluginError({ msg: "cannot find module '" + pluginInfo.module + "'", plugin: pluginInfo, trace: new Error() }); } settings.loadedModules.push(pluginInfo.module); } else { plugin = pluginInfo; } var pluginOpts = _.has(pluginInfo, 'options') ? pluginInfo.options : {}; // instantiate plugin if necessary if (_.isFunction(plugin)) { plugin = plugin(pluginOpts, options); } // validate plugin if (!(plugin instanceof GrawlixPlugin)) { throw new GrawlixPluginError({ msg: 'invalid plugin', plugin: pluginInfo }); } else if (plugin.name === null || _.isEmpty(plugin.name)) { throw new GrawlixPluginError({ msg: 'invalid plugin - name property not provided', plugin: pluginInfo }); } else if (_.contains(settings.loadedPlugins, plugin.name)) { // don't load the same plugin twice return settings; } // initialize plugin plugin.init(pluginOpts); // load filters if (!_.isUndefined(plugin.filters) && _.isArray(plugin.filters)) { try { loadFilters(settings, plugin.filters, options.allowed); } catch (err) { err.plugin = pluginInfo; throw err; } } // load styles if (!_.isUndefined(plugin.styles) && _.isArray(plugin.styles)) { try { loadStyles(settings, plugin.styles); } catch (err) { err.plugin = pluginInfo; throw err; } } // add name to loaded plugins settings.loadedPlugins.push(plugin.name); // return return settings; }
[ "function", "(", "settings", ",", "pluginInfo", ",", "options", ")", "{", "// resolve plugin and plugin options", "var", "plugin", ";", "if", "(", "_", ".", "has", "(", "pluginInfo", ",", "'plugin'", ")", ")", "{", "plugin", "=", "pluginInfo", ".", "plugin", ";", "}", "else", "if", "(", "_", ".", "has", "(", "pluginInfo", ",", "'module'", ")", ")", "{", "// make sure we don't load the same module twice", "if", "(", "_", ".", "contains", "(", "settings", ".", "loadedModules", ",", "pluginInfo", ".", "module", ")", ")", "{", "return", "settings", ";", "}", "// try to load module", "try", "{", "plugin", "=", "require", "(", "pluginInfo", ".", "module", ")", ";", "}", "catch", "(", "err", ")", "{", "throw", "new", "GrawlixPluginError", "(", "{", "msg", ":", "\"cannot find module '\"", "+", "pluginInfo", ".", "module", "+", "\"'\"", ",", "plugin", ":", "pluginInfo", ",", "trace", ":", "new", "Error", "(", ")", "}", ")", ";", "}", "settings", ".", "loadedModules", ".", "push", "(", "pluginInfo", ".", "module", ")", ";", "}", "else", "{", "plugin", "=", "pluginInfo", ";", "}", "var", "pluginOpts", "=", "_", ".", "has", "(", "pluginInfo", ",", "'options'", ")", "?", "pluginInfo", ".", "options", ":", "{", "}", ";", "// instantiate plugin if necessary", "if", "(", "_", ".", "isFunction", "(", "plugin", ")", ")", "{", "plugin", "=", "plugin", "(", "pluginOpts", ",", "options", ")", ";", "}", "// validate plugin", "if", "(", "!", "(", "plugin", "instanceof", "GrawlixPlugin", ")", ")", "{", "throw", "new", "GrawlixPluginError", "(", "{", "msg", ":", "'invalid plugin'", ",", "plugin", ":", "pluginInfo", "}", ")", ";", "}", "else", "if", "(", "plugin", ".", "name", "===", "null", "||", "_", ".", "isEmpty", "(", "plugin", ".", "name", ")", ")", "{", "throw", "new", "GrawlixPluginError", "(", "{", "msg", ":", "'invalid plugin - name property not provided'", ",", "plugin", ":", "pluginInfo", "}", ")", ";", "}", "else", "if", "(", "_", ".", "contains", "(", "settings", ".", "loadedPlugins", ",", "plugin", ".", "name", ")", ")", "{", "// don't load the same plugin twice", "return", "settings", ";", "}", "// initialize plugin", "plugin", ".", "init", "(", "pluginOpts", ")", ";", "// load filters", "if", "(", "!", "_", ".", "isUndefined", "(", "plugin", ".", "filters", ")", "&&", "_", ".", "isArray", "(", "plugin", ".", "filters", ")", ")", "{", "try", "{", "loadFilters", "(", "settings", ",", "plugin", ".", "filters", ",", "options", ".", "allowed", ")", ";", "}", "catch", "(", "err", ")", "{", "err", ".", "plugin", "=", "pluginInfo", ";", "throw", "err", ";", "}", "}", "// load styles", "if", "(", "!", "_", ".", "isUndefined", "(", "plugin", ".", "styles", ")", "&&", "_", ".", "isArray", "(", "plugin", ".", "styles", ")", ")", "{", "try", "{", "loadStyles", "(", "settings", ",", "plugin", ".", "styles", ")", ";", "}", "catch", "(", "err", ")", "{", "err", ".", "plugin", "=", "pluginInfo", ";", "throw", "err", ";", "}", "}", "// add name to loaded plugins", "settings", ".", "loadedPlugins", ".", "push", "(", "plugin", ".", "name", ")", ";", "// return", "return", "settings", ";", "}" ]
Loads the given plugin into the given GrawlixSettings object @param {GrawlixSettings} settings GrawlixSettings object @param {Object|Function} pluginInfo Either a factory function, a GrawlixPlugin object, or an object wrapping a factory function or GrawlixPlugin with additional plugin-specific config options @param {Object} options Main grawlix options object @return {GrawlixSettings} Settings object with plugin loaded
[ "Loads", "the", "given", "plugin", "into", "the", "given", "GrawlixSettings", "object" ]
235cd9629992b97c62953b813d5034a9546211f1
https://github.com/tinwatchman/grawlix/blob/235cd9629992b97c62953b813d5034a9546211f1/util.js#L126-L194
36,577
tinwatchman/grawlix
util.js
function(settings, filters, allowed) { if (filters.length > 0) { _.each(filters, function(obj) { if (!_.has(obj, 'word')) { return; } if (!_.has(obj, 'pattern')) { // configure existing filter options var filter = _.findWhere(settings.filters, { word: obj.word }); if (!_.isUndefined(filter)) { filter.configure(obj); } } else if (!_.contains(allowed, obj.word)) { // if filter word isn't whitelisted, add as new GrawlixFilter settings.filters.push( toGrawlixFilter(obj) ); } }); } return settings; }
javascript
function(settings, filters, allowed) { if (filters.length > 0) { _.each(filters, function(obj) { if (!_.has(obj, 'word')) { return; } if (!_.has(obj, 'pattern')) { // configure existing filter options var filter = _.findWhere(settings.filters, { word: obj.word }); if (!_.isUndefined(filter)) { filter.configure(obj); } } else if (!_.contains(allowed, obj.word)) { // if filter word isn't whitelisted, add as new GrawlixFilter settings.filters.push( toGrawlixFilter(obj) ); } }); } return settings; }
[ "function", "(", "settings", ",", "filters", ",", "allowed", ")", "{", "if", "(", "filters", ".", "length", ">", "0", ")", "{", "_", ".", "each", "(", "filters", ",", "function", "(", "obj", ")", "{", "if", "(", "!", "_", ".", "has", "(", "obj", ",", "'word'", ")", ")", "{", "return", ";", "}", "if", "(", "!", "_", ".", "has", "(", "obj", ",", "'pattern'", ")", ")", "{", "// configure existing filter options", "var", "filter", "=", "_", ".", "findWhere", "(", "settings", ".", "filters", ",", "{", "word", ":", "obj", ".", "word", "}", ")", ";", "if", "(", "!", "_", ".", "isUndefined", "(", "filter", ")", ")", "{", "filter", ".", "configure", "(", "obj", ")", ";", "}", "}", "else", "if", "(", "!", "_", ".", "contains", "(", "allowed", ",", "obj", ".", "word", ")", ")", "{", "// if filter word isn't whitelisted, add as new GrawlixFilter", "settings", ".", "filters", ".", "push", "(", "toGrawlixFilter", "(", "obj", ")", ")", ";", "}", "}", ")", ";", "}", "return", "settings", ";", "}" ]
Loads an array of filter objects into the GrawlixSettings object @param {GrawlixSettings} settings GrawlixSettings object @param {Array} filters Array of filter objects @param {Array} allowed Whitelist of words to ignore @return {GrawlixSettings} Settings objects with filters added
[ "Loads", "an", "array", "of", "filter", "objects", "into", "the", "GrawlixSettings", "object" ]
235cd9629992b97c62953b813d5034a9546211f1
https://github.com/tinwatchman/grawlix/blob/235cd9629992b97c62953b813d5034a9546211f1/util.js#L204-L223
36,578
tinwatchman/grawlix
util.js
function(settings, styles) { if (_.isArray(styles) && styles.length > 0) { _.each(styles, function(obj) { if (!_.has(obj, 'name')) { return; } var style = _.findWhere(settings.styles, { name: obj.name }); if (!_.isUndefined(style)) { style.configure(obj); } else { settings.styles.push( toGrawlixStyle(obj) ); } }); } return settings; }
javascript
function(settings, styles) { if (_.isArray(styles) && styles.length > 0) { _.each(styles, function(obj) { if (!_.has(obj, 'name')) { return; } var style = _.findWhere(settings.styles, { name: obj.name }); if (!_.isUndefined(style)) { style.configure(obj); } else { settings.styles.push( toGrawlixStyle(obj) ); } }); } return settings; }
[ "function", "(", "settings", ",", "styles", ")", "{", "if", "(", "_", ".", "isArray", "(", "styles", ")", "&&", "styles", ".", "length", ">", "0", ")", "{", "_", ".", "each", "(", "styles", ",", "function", "(", "obj", ")", "{", "if", "(", "!", "_", ".", "has", "(", "obj", ",", "'name'", ")", ")", "{", "return", ";", "}", "var", "style", "=", "_", ".", "findWhere", "(", "settings", ".", "styles", ",", "{", "name", ":", "obj", ".", "name", "}", ")", ";", "if", "(", "!", "_", ".", "isUndefined", "(", "style", ")", ")", "{", "style", ".", "configure", "(", "obj", ")", ";", "}", "else", "{", "settings", ".", "styles", ".", "push", "(", "toGrawlixStyle", "(", "obj", ")", ")", ";", "}", "}", ")", ";", "}", "return", "settings", ";", "}" ]
Loads an array of style objects into the given GrawlixSettings instance @param {GrawlixSettings} settings GrawlixSettings object @param {Array} styles Array of style objects @return {GrawlixSettings}
[ "Loads", "an", "array", "of", "style", "objects", "into", "the", "given", "GrawlixSettings", "instance" ]
235cd9629992b97c62953b813d5034a9546211f1
https://github.com/tinwatchman/grawlix/blob/235cd9629992b97c62953b813d5034a9546211f1/util.js#L232-L247
36,579
tinwatchman/grawlix
util.js
function(str, filter, settings) { // get filter style if provided var style; if (filter.hasStyle() && settings.style.isOverrideAllowed) { style = _.findWhere(settings.styles, { name: filter.style }); } if (_.isUndefined(style)) { // if filter style not found, or no filter style set, use main style style = settings.style; } // get replacement grawlix var repl; if (!settings.isRandom && style.hasFixed(filter.word)) { // if in fixed replacement mode and style has a defined fixed replacement // string for the filter's word repl = style.getFixed(filter.word); } else { // if single-character style repl = generateGrawlix(str, filter, style); } // apply filter template if necessary if (filter.hasTemplate()) { repl = filter.template(repl); } // replace the match return str.replace(filter.regex, repl); }
javascript
function(str, filter, settings) { // get filter style if provided var style; if (filter.hasStyle() && settings.style.isOverrideAllowed) { style = _.findWhere(settings.styles, { name: filter.style }); } if (_.isUndefined(style)) { // if filter style not found, or no filter style set, use main style style = settings.style; } // get replacement grawlix var repl; if (!settings.isRandom && style.hasFixed(filter.word)) { // if in fixed replacement mode and style has a defined fixed replacement // string for the filter's word repl = style.getFixed(filter.word); } else { // if single-character style repl = generateGrawlix(str, filter, style); } // apply filter template if necessary if (filter.hasTemplate()) { repl = filter.template(repl); } // replace the match return str.replace(filter.regex, repl); }
[ "function", "(", "str", ",", "filter", ",", "settings", ")", "{", "// get filter style if provided", "var", "style", ";", "if", "(", "filter", ".", "hasStyle", "(", ")", "&&", "settings", ".", "style", ".", "isOverrideAllowed", ")", "{", "style", "=", "_", ".", "findWhere", "(", "settings", ".", "styles", ",", "{", "name", ":", "filter", ".", "style", "}", ")", ";", "}", "if", "(", "_", ".", "isUndefined", "(", "style", ")", ")", "{", "// if filter style not found, or no filter style set, use main style", "style", "=", "settings", ".", "style", ";", "}", "// get replacement grawlix", "var", "repl", ";", "if", "(", "!", "settings", ".", "isRandom", "&&", "style", ".", "hasFixed", "(", "filter", ".", "word", ")", ")", "{", "// if in fixed replacement mode and style has a defined fixed replacement ", "// string for the filter's word ", "repl", "=", "style", ".", "getFixed", "(", "filter", ".", "word", ")", ";", "}", "else", "{", "// if single-character style", "repl", "=", "generateGrawlix", "(", "str", ",", "filter", ",", "style", ")", ";", "}", "// apply filter template if necessary", "if", "(", "filter", ".", "hasTemplate", "(", ")", ")", "{", "repl", "=", "filter", ".", "template", "(", "repl", ")", ";", "}", "// replace the match", "return", "str", ".", "replace", "(", "filter", ".", "regex", ",", "repl", ")", ";", "}" ]
Replaces a filter match in a string @param {String} str Content string @param {GrawlixFilter} filter GrawlixFilter object @param {GrawlixSettings} settings GrawlixSettings object @return {String} String with replacement applied
[ "Replaces", "a", "filter", "match", "in", "a", "string" ]
235cd9629992b97c62953b813d5034a9546211f1
https://github.com/tinwatchman/grawlix/blob/235cd9629992b97c62953b813d5034a9546211f1/util.js#L332-L358
36,580
tinwatchman/grawlix
util.js
function(str, filter, style) { // determine length var len; if (filter.isExpandable) { len = filter.getMatchLen(str); } else { len = filter.word.length; } // generate grawlix if (!style.canRandomize()) { return style.getFillGrawlix(len); } return style.getRandomGrawlix(len); }
javascript
function(str, filter, style) { // determine length var len; if (filter.isExpandable) { len = filter.getMatchLen(str); } else { len = filter.word.length; } // generate grawlix if (!style.canRandomize()) { return style.getFillGrawlix(len); } return style.getRandomGrawlix(len); }
[ "function", "(", "str", ",", "filter", ",", "style", ")", "{", "// determine length", "var", "len", ";", "if", "(", "filter", ".", "isExpandable", ")", "{", "len", "=", "filter", ".", "getMatchLen", "(", "str", ")", ";", "}", "else", "{", "len", "=", "filter", ".", "word", ".", "length", ";", "}", "// generate grawlix", "if", "(", "!", "style", ".", "canRandomize", "(", ")", ")", "{", "return", "style", ".", "getFillGrawlix", "(", "len", ")", ";", "}", "return", "style", ".", "getRandomGrawlix", "(", "len", ")", ";", "}" ]
Replaces matched content with a grawlix, taking into account filter and style settings. @param {String} str Content string @param {GrawlixFilter} filter Filter object @param {GrawlixStyle} style Style object @return {String} Grawlix replacement string
[ "Replaces", "matched", "content", "with", "a", "grawlix", "taking", "into", "account", "filter", "and", "style", "settings", "." ]
235cd9629992b97c62953b813d5034a9546211f1
https://github.com/tinwatchman/grawlix/blob/235cd9629992b97c62953b813d5034a9546211f1/util.js#L369-L382
36,581
Download/webdb
dist/webdb.umd.js
indexOf
function indexOf(list, element, comparator) { for (var i=0,item; item=list[i]; i++) { if (equals(item, element, comparator)) { return i; } } return -1; }
javascript
function indexOf(list, element, comparator) { for (var i=0,item; item=list[i]; i++) { if (equals(item, element, comparator)) { return i; } } return -1; }
[ "function", "indexOf", "(", "list", ",", "element", ",", "comparator", ")", "{", "for", "(", "var", "i", "=", "0", ",", "item", ";", "item", "=", "list", "[", "i", "]", ";", "i", "++", ")", "{", "if", "(", "equals", "(", "item", ",", "element", ",", "comparator", ")", ")", "{", "return", "i", ";", "}", "}", "return", "-", "1", ";", "}" ]
returns index of given element in given list, using given comparator
[ "returns", "index", "of", "given", "element", "in", "given", "list", "using", "given", "comparator" ]
ca93fdc67dfba04d3adfb94b4c7e877d9ed3ec3b
https://github.com/Download/webdb/blob/ca93fdc67dfba04d3adfb94b4c7e877d9ed3ec3b/dist/webdb.umd.js#L666-L673
36,582
Download/webdb
dist/webdb.umd.js
Tree
function Tree(options) { this.root = new Node(this, options); this.unique = options && options.unique || false; this.compare = options && options.compare || compare; this.equals = options && options.equals || equals; this.keyType = options && options.keyType || undefined; this.id = options && options.id || undefined; }
javascript
function Tree(options) { this.root = new Node(this, options); this.unique = options && options.unique || false; this.compare = options && options.compare || compare; this.equals = options && options.equals || equals; this.keyType = options && options.keyType || undefined; this.id = options && options.id || undefined; }
[ "function", "Tree", "(", "options", ")", "{", "this", ".", "root", "=", "new", "Node", "(", "this", ",", "options", ")", ";", "this", ".", "unique", "=", "options", "&&", "options", ".", "unique", "||", "false", ";", "this", ".", "compare", "=", "options", "&&", "options", ".", "compare", "||", "compare", ";", "this", ".", "equals", "=", "options", "&&", "options", ".", "equals", "||", "equals", ";", "this", ".", "keyType", "=", "options", "&&", "options", ".", "keyType", "||", "undefined", ";", "this", ".", "id", "=", "options", "&&", "options", ".", "id", "||", "undefined", ";", "}" ]
Creates a new Tree. @param {Object} Optional options object @param {Boolean} options.unique Whether to enforce a 'unique' constraint on the key or not @param {Function} options.compare Optional key comparison function @param {Function} options.equals Optional data equality comparison function @param {Function} options.keyType Optional constructor function for when key type is not primitive @param {Function} options.id Optional id extraction function
[ "Creates", "a", "new", "Tree", "." ]
ca93fdc67dfba04d3adfb94b4c7e877d9ed3ec3b
https://github.com/Download/webdb/blob/ca93fdc67dfba04d3adfb94b4c7e877d9ed3ec3b/dist/webdb.umd.js#L950-L957
36,583
Download/webdb
dist/webdb.umd.js
Node
function Node(tree, options) { this.tree = tree; if (options && options.parent) {this.parent = options.parent;} if (options && options.hasOwnProperty('key')) { this.key = options.key; } this.data = options && options.hasOwnProperty('value') ? [options.value] : []; }
javascript
function Node(tree, options) { this.tree = tree; if (options && options.parent) {this.parent = options.parent;} if (options && options.hasOwnProperty('key')) { this.key = options.key; } this.data = options && options.hasOwnProperty('value') ? [options.value] : []; }
[ "function", "Node", "(", "tree", ",", "options", ")", "{", "this", ".", "tree", "=", "tree", ";", "if", "(", "options", "&&", "options", ".", "parent", ")", "{", "this", ".", "parent", "=", "options", ".", "parent", ";", "}", "if", "(", "options", "&&", "options", ".", "hasOwnProperty", "(", "'key'", ")", ")", "{", "this", ".", "key", "=", "options", ".", "key", ";", "}", "this", ".", "data", "=", "options", "&&", "options", ".", "hasOwnProperty", "(", "'value'", ")", "?", "[", "options", ".", "value", "]", ":", "[", "]", ";", "}" ]
Creates a new Node. @param {Object} Optional options object. @param {Node} options.parent Initialize this Node's parent @param {Key} options.key Initialize this Node's key @param {Value} options.value Initialize this Node's value
[ "Creates", "a", "new", "Node", "." ]
ca93fdc67dfba04d3adfb94b4c7e877d9ed3ec3b
https://github.com/Download/webdb/blob/ca93fdc67dfba04d3adfb94b4c7e877d9ed3ec3b/dist/webdb.umd.js#L979-L984
36,584
Download/webdb
dist/webdb.umd.js
getLowerBoundMatcher
function getLowerBoundMatcher(compare, query) { // No lower bound if (!query.hasOwnProperty('$gt') && !query.hasOwnProperty('$gte')) { return function(){return true;}; } if (query.hasOwnProperty('$gt') && query.hasOwnProperty('$gte')) { if (compare(query.$gte, query.$gt) === 0) { return function (key) { return compare(key, query.$gt) > 0; }; } if (compare(query.$gte, query.$gt) > 0) { return function (key) { return compare(key, query.$gte) >= 0; }; } else { return function (key) { return compare(key, query.$gt) > 0; }; } } if (query.hasOwnProperty('$gt')) { return function (key) { return compare(key, query.$gt) > 0; }; } else { return function (key) { return compare(key, query.$gte) >= 0; }; } }
javascript
function getLowerBoundMatcher(compare, query) { // No lower bound if (!query.hasOwnProperty('$gt') && !query.hasOwnProperty('$gte')) { return function(){return true;}; } if (query.hasOwnProperty('$gt') && query.hasOwnProperty('$gte')) { if (compare(query.$gte, query.$gt) === 0) { return function (key) { return compare(key, query.$gt) > 0; }; } if (compare(query.$gte, query.$gt) > 0) { return function (key) { return compare(key, query.$gte) >= 0; }; } else { return function (key) { return compare(key, query.$gt) > 0; }; } } if (query.hasOwnProperty('$gt')) { return function (key) { return compare(key, query.$gt) > 0; }; } else { return function (key) { return compare(key, query.$gte) >= 0; }; } }
[ "function", "getLowerBoundMatcher", "(", "compare", ",", "query", ")", "{", "// No lower bound", "if", "(", "!", "query", ".", "hasOwnProperty", "(", "'$gt'", ")", "&&", "!", "query", ".", "hasOwnProperty", "(", "'$gte'", ")", ")", "{", "return", "function", "(", ")", "{", "return", "true", ";", "}", ";", "}", "if", "(", "query", ".", "hasOwnProperty", "(", "'$gt'", ")", "&&", "query", ".", "hasOwnProperty", "(", "'$gte'", ")", ")", "{", "if", "(", "compare", "(", "query", ".", "$gte", ",", "query", ".", "$gt", ")", "===", "0", ")", "{", "return", "function", "(", "key", ")", "{", "return", "compare", "(", "key", ",", "query", ".", "$gt", ")", ">", "0", ";", "}", ";", "}", "if", "(", "compare", "(", "query", ".", "$gte", ",", "query", ".", "$gt", ")", ">", "0", ")", "{", "return", "function", "(", "key", ")", "{", "return", "compare", "(", "key", ",", "query", ".", "$gte", ")", ">=", "0", ";", "}", ";", "}", "else", "{", "return", "function", "(", "key", ")", "{", "return", "compare", "(", "key", ",", "query", ".", "$gt", ")", ">", "0", ";", "}", ";", "}", "}", "if", "(", "query", ".", "hasOwnProperty", "(", "'$gt'", ")", ")", "{", "return", "function", "(", "key", ")", "{", "return", "compare", "(", "key", ",", "query", ".", "$gt", ")", ">", "0", ";", "}", ";", "}", "else", "{", "return", "function", "(", "key", ")", "{", "return", "compare", "(", "key", ",", "query", ".", "$gte", ")", ">=", "0", ";", "}", ";", "}", "}" ]
Return a function that tells whether a given key matches a lower bound
[ "Return", "a", "function", "that", "tells", "whether", "a", "given", "key", "matches", "a", "lower", "bound" ]
ca93fdc67dfba04d3adfb94b4c7e877d9ed3ec3b
https://github.com/Download/webdb/blob/ca93fdc67dfba04d3adfb94b4c7e877d9ed3ec3b/dist/webdb.umd.js#L1213-L1233
36,585
Download/webdb
dist/webdb.umd.js
getUpperBoundMatcher
function getUpperBoundMatcher(compare, query) { // No lower bound if (!query.hasOwnProperty('$lt') && !query.hasOwnProperty('$lte')) { return function () { return true; }; } if (query.hasOwnProperty('$lt') && query.hasOwnProperty('$lte')) { if (compare(query.$lte, query.$lt) === 0) { return function (key) { return compare(key, query.$lt) < 0; }; } if (compare(query.$lte, query.$lt) < 0) { return function (key) { return compare(key, query.$lte) <= 0; }; } else { return function (key) { return compare(key, query.$lt) < 0; }; } } if (query.hasOwnProperty('$lt')) { return function (key) { return compare(key, query.$lt) < 0; }; } else { return function (key) { return compare(key, query.$lte) <= 0; }; } }
javascript
function getUpperBoundMatcher(compare, query) { // No lower bound if (!query.hasOwnProperty('$lt') && !query.hasOwnProperty('$lte')) { return function () { return true; }; } if (query.hasOwnProperty('$lt') && query.hasOwnProperty('$lte')) { if (compare(query.$lte, query.$lt) === 0) { return function (key) { return compare(key, query.$lt) < 0; }; } if (compare(query.$lte, query.$lt) < 0) { return function (key) { return compare(key, query.$lte) <= 0; }; } else { return function (key) { return compare(key, query.$lt) < 0; }; } } if (query.hasOwnProperty('$lt')) { return function (key) { return compare(key, query.$lt) < 0; }; } else { return function (key) { return compare(key, query.$lte) <= 0; }; } }
[ "function", "getUpperBoundMatcher", "(", "compare", ",", "query", ")", "{", "// No lower bound", "if", "(", "!", "query", ".", "hasOwnProperty", "(", "'$lt'", ")", "&&", "!", "query", ".", "hasOwnProperty", "(", "'$lte'", ")", ")", "{", "return", "function", "(", ")", "{", "return", "true", ";", "}", ";", "}", "if", "(", "query", ".", "hasOwnProperty", "(", "'$lt'", ")", "&&", "query", ".", "hasOwnProperty", "(", "'$lte'", ")", ")", "{", "if", "(", "compare", "(", "query", ".", "$lte", ",", "query", ".", "$lt", ")", "===", "0", ")", "{", "return", "function", "(", "key", ")", "{", "return", "compare", "(", "key", ",", "query", ".", "$lt", ")", "<", "0", ";", "}", ";", "}", "if", "(", "compare", "(", "query", ".", "$lte", ",", "query", ".", "$lt", ")", "<", "0", ")", "{", "return", "function", "(", "key", ")", "{", "return", "compare", "(", "key", ",", "query", ".", "$lte", ")", "<=", "0", ";", "}", ";", "}", "else", "{", "return", "function", "(", "key", ")", "{", "return", "compare", "(", "key", ",", "query", ".", "$lt", ")", "<", "0", ";", "}", ";", "}", "}", "if", "(", "query", ".", "hasOwnProperty", "(", "'$lt'", ")", ")", "{", "return", "function", "(", "key", ")", "{", "return", "compare", "(", "key", ",", "query", ".", "$lt", ")", "<", "0", ";", "}", ";", "}", "else", "{", "return", "function", "(", "key", ")", "{", "return", "compare", "(", "key", ",", "query", ".", "$lte", ")", "<=", "0", ";", "}", ";", "}", "}" ]
Return a function that tells whether a given key matches an upper bound
[ "Return", "a", "function", "that", "tells", "whether", "a", "given", "key", "matches", "an", "upper", "bound" ]
ca93fdc67dfba04d3adfb94b4c7e877d9ed3ec3b
https://github.com/Download/webdb/blob/ca93fdc67dfba04d3adfb94b4c7e877d9ed3ec3b/dist/webdb.umd.js#L1238-L1258
36,586
Download/webdb
dist/webdb.umd.js
betweenBounds
function betweenBounds(node, query, lbm, ubm) { var res = []; if (!node.hasOwnProperty('key')) { return res; } // Empty tree lbm = lbm || getLowerBoundMatcher(node.tree.compare, query); ubm = ubm || getUpperBoundMatcher(node.tree.compare, query); if (lbm(node.key) && node.left) { res.push.apply(res, betweenBounds(node.left, query, lbm, ubm)); } if (lbm(node.key) && ubm(node.key)) { res.push.apply(res, node.data); } if (ubm(node.key) && node.right) { res.push.apply(res, betweenBounds(node.right, query, lbm, ubm)); } return res; }
javascript
function betweenBounds(node, query, lbm, ubm) { var res = []; if (!node.hasOwnProperty('key')) { return res; } // Empty tree lbm = lbm || getLowerBoundMatcher(node.tree.compare, query); ubm = ubm || getUpperBoundMatcher(node.tree.compare, query); if (lbm(node.key) && node.left) { res.push.apply(res, betweenBounds(node.left, query, lbm, ubm)); } if (lbm(node.key) && ubm(node.key)) { res.push.apply(res, node.data); } if (ubm(node.key) && node.right) { res.push.apply(res, betweenBounds(node.right, query, lbm, ubm)); } return res; }
[ "function", "betweenBounds", "(", "node", ",", "query", ",", "lbm", ",", "ubm", ")", "{", "var", "res", "=", "[", "]", ";", "if", "(", "!", "node", ".", "hasOwnProperty", "(", "'key'", ")", ")", "{", "return", "res", ";", "}", "// Empty tree", "lbm", "=", "lbm", "||", "getLowerBoundMatcher", "(", "node", ".", "tree", ".", "compare", ",", "query", ")", ";", "ubm", "=", "ubm", "||", "getUpperBoundMatcher", "(", "node", ".", "tree", ".", "compare", ",", "query", ")", ";", "if", "(", "lbm", "(", "node", ".", "key", ")", "&&", "node", ".", "left", ")", "{", "res", ".", "push", ".", "apply", "(", "res", ",", "betweenBounds", "(", "node", ".", "left", ",", "query", ",", "lbm", ",", "ubm", ")", ")", ";", "}", "if", "(", "lbm", "(", "node", ".", "key", ")", "&&", "ubm", "(", "node", ".", "key", ")", ")", "{", "res", ".", "push", ".", "apply", "(", "res", ",", "node", ".", "data", ")", ";", "}", "if", "(", "ubm", "(", "node", ".", "key", ")", "&&", "node", ".", "right", ")", "{", "res", ".", "push", ".", "apply", "(", "res", ",", "betweenBounds", "(", "node", ".", "right", ",", "query", ",", "lbm", ",", "ubm", ")", ")", ";", "}", "return", "res", ";", "}" ]
Get all data for a key between bounds Return it in key order @param {Node} Node to execute on @param {Object} query Mongo-style query where keys are $lt, $lte, $gt or $gte (other keys are not considered) @param {Functions} lbm/ubm matching functions calculated at the first recursive step
[ "Get", "all", "data", "for", "a", "key", "between", "bounds", "Return", "it", "in", "key", "order" ]
ca93fdc67dfba04d3adfb94b4c7e877d9ed3ec3b
https://github.com/Download/webdb/blob/ca93fdc67dfba04d3adfb94b4c7e877d9ed3ec3b/dist/webdb.umd.js#L1267-L1276
36,587
Download/webdb
dist/webdb.umd.js
balanceFactor
function balanceFactor(node) { return (node.left ? node.left.height : 0) - (node.right ? node.right.height : 0); }
javascript
function balanceFactor(node) { return (node.left ? node.left.height : 0) - (node.right ? node.right.height : 0); }
[ "function", "balanceFactor", "(", "node", ")", "{", "return", "(", "node", ".", "left", "?", "node", ".", "left", ".", "height", ":", "0", ")", "-", "(", "node", ".", "right", "?", "node", ".", "right", ".", "height", ":", "0", ")", ";", "}" ]
Return the balance factor of the given node
[ "Return", "the", "balance", "factor", "of", "the", "given", "node" ]
ca93fdc67dfba04d3adfb94b4c7e877d9ed3ec3b
https://github.com/Download/webdb/blob/ca93fdc67dfba04d3adfb94b4c7e877d9ed3ec3b/dist/webdb.umd.js#L1281-L1283
36,588
Download/webdb
dist/webdb.umd.js
rightTooSmall
function rightTooSmall(node) { if (balanceFactor(node) <= 1) { return node; } // Right is not too small, don't change if (balanceFactor(node.left) < 0) {leftRotation(node.left);} return rightRotation(node); }
javascript
function rightTooSmall(node) { if (balanceFactor(node) <= 1) { return node; } // Right is not too small, don't change if (balanceFactor(node.left) < 0) {leftRotation(node.left);} return rightRotation(node); }
[ "function", "rightTooSmall", "(", "node", ")", "{", "if", "(", "balanceFactor", "(", "node", ")", "<=", "1", ")", "{", "return", "node", ";", "}", "// Right is not too small, don't change", "if", "(", "balanceFactor", "(", "node", ".", "left", ")", "<", "0", ")", "{", "leftRotation", "(", "node", ".", "left", ")", ";", "}", "return", "rightRotation", "(", "node", ")", ";", "}" ]
Modify the tree if its right subtree is too small compared to the left Return the new root if any
[ "Modify", "the", "tree", "if", "its", "right", "subtree", "is", "too", "small", "compared", "to", "the", "left", "Return", "the", "new", "root", "if", "any" ]
ca93fdc67dfba04d3adfb94b4c7e877d9ed3ec3b
https://github.com/Download/webdb/blob/ca93fdc67dfba04d3adfb94b4c7e877d9ed3ec3b/dist/webdb.umd.js#L1351-L1355
36,589
Download/webdb
dist/webdb.umd.js
leftTooSmall
function leftTooSmall(node) { if (balanceFactor(node) >= -1) { return node; } // Left is not too small, don't change if (balanceFactor(node.right) > 0) {rightRotation(node.right);} return leftRotation(node); }
javascript
function leftTooSmall(node) { if (balanceFactor(node) >= -1) { return node; } // Left is not too small, don't change if (balanceFactor(node.right) > 0) {rightRotation(node.right);} return leftRotation(node); }
[ "function", "leftTooSmall", "(", "node", ")", "{", "if", "(", "balanceFactor", "(", "node", ")", ">=", "-", "1", ")", "{", "return", "node", ";", "}", "// Left is not too small, don't change", "if", "(", "balanceFactor", "(", "node", ".", "right", ")", ">", "0", ")", "{", "rightRotation", "(", "node", ".", "right", ")", ";", "}", "return", "leftRotation", "(", "node", ")", ";", "}" ]
Modify the tree if its left subtree is too small compared to the right Return the new root if any
[ "Modify", "the", "tree", "if", "its", "left", "subtree", "is", "too", "small", "compared", "to", "the", "right", "Return", "the", "new", "root", "if", "any" ]
ca93fdc67dfba04d3adfb94b4c7e877d9ed3ec3b
https://github.com/Download/webdb/blob/ca93fdc67dfba04d3adfb94b4c7e877d9ed3ec3b/dist/webdb.umd.js#L1361-L1365
36,590
datanews/tables
lib/tables.js
function(data) { if (thisTables.options.stdin) { thisTables.guessBuffers.push(data); } bar.tick(data.length); }
javascript
function(data) { if (thisTables.options.stdin) { thisTables.guessBuffers.push(data); } bar.tick(data.length); }
[ "function", "(", "data", ")", "{", "if", "(", "thisTables", ".", "options", ".", "stdin", ")", "{", "thisTables", ".", "guessBuffers", ".", "push", "(", "data", ")", ";", "}", "bar", ".", "tick", "(", "data", ".", "length", ")", ";", "}" ]
Create functions for streams so that we can remove them if needed
[ "Create", "functions", "for", "streams", "so", "that", "we", "can", "remove", "them", "if", "needed" ]
4b33aa7a944a93260c49baecbb90345211cac789
https://github.com/datanews/tables/blob/4b33aa7a944a93260c49baecbb90345211cac789/lib/tables.js#L363-L369
36,591
Tixit/observe
observe.js
unionizeList
function unionizeList(array, start, count, union) { var internalObservees = [] // list of observees and their property path if(union !== undefined) { var afterEnd = start+count for(var n=start; n<afterEnd; n++) { internalObservees.push({obj: array[n], index: n}) if(union === true) array[n] = array[n].subject } } return internalObservees }
javascript
function unionizeList(array, start, count, union) { var internalObservees = [] // list of observees and their property path if(union !== undefined) { var afterEnd = start+count for(var n=start; n<afterEnd; n++) { internalObservees.push({obj: array[n], index: n}) if(union === true) array[n] = array[n].subject } } return internalObservees }
[ "function", "unionizeList", "(", "array", ",", "start", ",", "count", ",", "union", ")", "{", "var", "internalObservees", "=", "[", "]", "// list of observees and their property path", "if", "(", "union", "!==", "undefined", ")", "{", "var", "afterEnd", "=", "start", "+", "count", "for", "(", "var", "n", "=", "start", ";", "n", "<", "afterEnd", ";", "n", "++", ")", "{", "internalObservees", ".", "push", "(", "{", "obj", ":", "array", "[", "n", "]", ",", "index", ":", "n", "}", ")", "if", "(", "union", "===", "true", ")", "array", "[", "n", "]", "=", "array", "[", "n", "]", ".", "subject", "}", "}", "return", "internalObservees", "}" ]
sets a slice of elements to their subjects and returns the original observee objects along with their indexes
[ "sets", "a", "slice", "of", "elements", "to", "their", "subjects", "and", "returns", "the", "original", "observee", "objects", "along", "with", "their", "indexes" ]
4a51a2d419a7a7336b97266ea2934f44c513d77b
https://github.com/Tixit/observe/blob/4a51a2d419a7a7336b97266ea2934f44c513d77b/observe.js#L384-L396
36,592
Tixit/observe
observe.js
unionizeListEvents
function unionizeListEvents(that, internalObservees, propertyList, collapse) { for(var n=0; n<internalObservees.length; n++) { unionizeEvents(that, internalObservees[n].obj, propertyList.concat(internalObservees[n].index+''), collapse) } }
javascript
function unionizeListEvents(that, internalObservees, propertyList, collapse) { for(var n=0; n<internalObservees.length; n++) { unionizeEvents(that, internalObservees[n].obj, propertyList.concat(internalObservees[n].index+''), collapse) } }
[ "function", "unionizeListEvents", "(", "that", ",", "internalObservees", ",", "propertyList", ",", "collapse", ")", "{", "for", "(", "var", "n", "=", "0", ";", "n", "<", "internalObservees", ".", "length", ";", "n", "++", ")", "{", "unionizeEvents", "(", "that", ",", "internalObservees", "[", "n", "]", ".", "obj", ",", "propertyList", ".", "concat", "(", "internalObservees", "[", "n", "]", ".", "index", "+", "''", ")", ",", "collapse", ")", "}", "}" ]
runs unionizeEvents for elements in a list internalObservees should be the result from `unionizeList`
[ "runs", "unionizeEvents", "for", "elements", "in", "a", "list", "internalObservees", "should", "be", "the", "result", "from", "unionizeList" ]
4a51a2d419a7a7336b97266ea2934f44c513d77b
https://github.com/Tixit/observe/blob/4a51a2d419a7a7336b97266ea2934f44c513d77b/observe.js#L400-L404
36,593
HBYoon/node-mysql-transaction
lib/chain.js
chainQueryRun
function chainQueryRun (safeCon, arg, currentObj) { objAdder(safeCon, currentObj); var stream; try { stream = safeCon.query.apply(safeCon, arg); } catch(e) { return currentObj.rollback(e); } autoErrorRollback(currentObj); onewayEventConnect(stream, currentObj); if (currentObj._autoCommit) { autoCommitReady(safeCon, currentObj); } stream.on('error', function(e){ safeCon._errorState = true; }); currentObj.on('end', function(){ safeCon._count -= 1; }); safeCon._count += 1; currentObj.stream = stream; currentObj.emit('nextChain', safeCon); }
javascript
function chainQueryRun (safeCon, arg, currentObj) { objAdder(safeCon, currentObj); var stream; try { stream = safeCon.query.apply(safeCon, arg); } catch(e) { return currentObj.rollback(e); } autoErrorRollback(currentObj); onewayEventConnect(stream, currentObj); if (currentObj._autoCommit) { autoCommitReady(safeCon, currentObj); } stream.on('error', function(e){ safeCon._errorState = true; }); currentObj.on('end', function(){ safeCon._count -= 1; }); safeCon._count += 1; currentObj.stream = stream; currentObj.emit('nextChain', safeCon); }
[ "function", "chainQueryRun", "(", "safeCon", ",", "arg", ",", "currentObj", ")", "{", "objAdder", "(", "safeCon", ",", "currentObj", ")", ";", "var", "stream", ";", "try", "{", "stream", "=", "safeCon", ".", "query", ".", "apply", "(", "safeCon", ",", "arg", ")", ";", "}", "catch", "(", "e", ")", "{", "return", "currentObj", ".", "rollback", "(", "e", ")", ";", "}", "autoErrorRollback", "(", "currentObj", ")", ";", "onewayEventConnect", "(", "stream", ",", "currentObj", ")", ";", "if", "(", "currentObj", ".", "_autoCommit", ")", "{", "autoCommitReady", "(", "safeCon", ",", "currentObj", ")", ";", "}", "stream", ".", "on", "(", "'error'", ",", "function", "(", "e", ")", "{", "safeCon", ".", "_errorState", "=", "true", ";", "}", ")", ";", "currentObj", ".", "on", "(", "'end'", ",", "function", "(", ")", "{", "safeCon", ".", "_count", "-=", "1", ";", "}", ")", ";", "safeCon", ".", "_count", "+=", "1", ";", "currentObj", ".", "stream", "=", "stream", ";", "currentObj", ".", "emit", "(", "'nextChain'", ",", "safeCon", ")", ";", "}" ]
main procedure function
[ "main", "procedure", "function" ]
a63ad00a93afb59dfab06218b89222248ba872a1
https://github.com/HBYoon/node-mysql-transaction/blob/a63ad00a93afb59dfab06218b89222248ba872a1/lib/chain.js#L195-L224
36,594
jtrussell/bedecked
lib/bedecked.js
function(prezContents, cb) { var slideChunksPreTpl = prezContents.toString().split(slideBreakAt); _.forEach(slideChunksPreTpl, function(chunk) { opts.slides.push({ preHtml: chunk, indented: opts.slides.length && isIndented(chunk) }); }); cb(null, opts); }
javascript
function(prezContents, cb) { var slideChunksPreTpl = prezContents.toString().split(slideBreakAt); _.forEach(slideChunksPreTpl, function(chunk) { opts.slides.push({ preHtml: chunk, indented: opts.slides.length && isIndented(chunk) }); }); cb(null, opts); }
[ "function", "(", "prezContents", ",", "cb", ")", "{", "var", "slideChunksPreTpl", "=", "prezContents", ".", "toString", "(", ")", ".", "split", "(", "slideBreakAt", ")", ";", "_", ".", "forEach", "(", "slideChunksPreTpl", ",", "function", "(", "chunk", ")", "{", "opts", ".", "slides", ".", "push", "(", "{", "preHtml", ":", "chunk", ",", "indented", ":", "opts", ".", "slides", ".", "length", "&&", "isIndented", "(", "chunk", ")", "}", ")", ";", "}", ")", ";", "cb", "(", "null", ",", "opts", ")", ";", "}" ]
Split the prez markup into slides
[ "Split", "the", "prez", "markup", "into", "slides" ]
2c7d53642327e621c027bf44395d2a62333ee1bd
https://github.com/jtrussell/bedecked/blob/2c7d53642327e621c027bf44395d2a62333ee1bd/lib/bedecked.js#L120-L129
36,595
spreadshirt/rAppid.js-sprd
sprd/view/ImageUploadClass.js
function (e) { if (this.$.enabled) { this.removeClass('drag-over'); if (e && e.$) { e = e.$; if (e.dataTransfer && e.dataTransfer.files.length) { for (var i = 0; i < e.dataTransfer.files.length; i++) { this._addAndUploadFile(e.dataTransfer.files[i]); } } } } e.preventDefault(); e.stopPropagation(); return false; }
javascript
function (e) { if (this.$.enabled) { this.removeClass('drag-over'); if (e && e.$) { e = e.$; if (e.dataTransfer && e.dataTransfer.files.length) { for (var i = 0; i < e.dataTransfer.files.length; i++) { this._addAndUploadFile(e.dataTransfer.files[i]); } } } } e.preventDefault(); e.stopPropagation(); return false; }
[ "function", "(", "e", ")", "{", "if", "(", "this", ".", "$", ".", "enabled", ")", "{", "this", ".", "removeClass", "(", "'drag-over'", ")", ";", "if", "(", "e", "&&", "e", ".", "$", ")", "{", "e", "=", "e", ".", "$", ";", "if", "(", "e", ".", "dataTransfer", "&&", "e", ".", "dataTransfer", ".", "files", ".", "length", ")", "{", "for", "(", "var", "i", "=", "0", ";", "i", "<", "e", ".", "dataTransfer", ".", "files", ".", "length", ";", "i", "++", ")", "{", "this", ".", "_addAndUploadFile", "(", "e", ".", "dataTransfer", ".", "files", "[", "i", "]", ")", ";", "}", "}", "}", "}", "e", ".", "preventDefault", "(", ")", ";", "e", ".", "stopPropagation", "(", ")", ";", "return", "false", ";", "}" ]
An image has been dropped into the design window. @param {Event} e @returns {boolean}
[ "An", "image", "has", "been", "dropped", "into", "the", "design", "window", "." ]
b56f9f47fe01332f5bf885eaf4db59014f099019
https://github.com/spreadshirt/rAppid.js-sprd/blob/b56f9f47fe01332f5bf885eaf4db59014f099019/sprd/view/ImageUploadClass.js#L71-L88
36,596
spreadshirt/rAppid.js-sprd
sprd/view/ImageUploadClass.js
function (file, callback) { var self = this, reader = new FileReader(); var uploadDesign = this.$.imageUploadService.upload(file, function (err) { if (!err) { self.trigger("uploadComplete", { uploadDesign: uploadDesign }); } else { self.trigger("uploadError", { error: err, uploadDesign: uploadDesign }); } callback && callback(err, uploadDesign); }); reader.onload = function(evt) { var img = new Image(); img.onload = function() { uploadDesign.set({ previewImage: evt.target.result, localImage: evt.target.result }); }; img.src = evt.target.result; }; reader.readAsDataURL(file); return uploadDesign; }
javascript
function (file, callback) { var self = this, reader = new FileReader(); var uploadDesign = this.$.imageUploadService.upload(file, function (err) { if (!err) { self.trigger("uploadComplete", { uploadDesign: uploadDesign }); } else { self.trigger("uploadError", { error: err, uploadDesign: uploadDesign }); } callback && callback(err, uploadDesign); }); reader.onload = function(evt) { var img = new Image(); img.onload = function() { uploadDesign.set({ previewImage: evt.target.result, localImage: evt.target.result }); }; img.src = evt.target.result; }; reader.readAsDataURL(file); return uploadDesign; }
[ "function", "(", "file", ",", "callback", ")", "{", "var", "self", "=", "this", ",", "reader", "=", "new", "FileReader", "(", ")", ";", "var", "uploadDesign", "=", "this", ".", "$", ".", "imageUploadService", ".", "upload", "(", "file", ",", "function", "(", "err", ")", "{", "if", "(", "!", "err", ")", "{", "self", ".", "trigger", "(", "\"uploadComplete\"", ",", "{", "uploadDesign", ":", "uploadDesign", "}", ")", ";", "}", "else", "{", "self", ".", "trigger", "(", "\"uploadError\"", ",", "{", "error", ":", "err", ",", "uploadDesign", ":", "uploadDesign", "}", ")", ";", "}", "callback", "&&", "callback", "(", "err", ",", "uploadDesign", ")", ";", "}", ")", ";", "reader", ".", "onload", "=", "function", "(", "evt", ")", "{", "var", "img", "=", "new", "Image", "(", ")", ";", "img", ".", "onload", "=", "function", "(", ")", "{", "uploadDesign", ".", "set", "(", "{", "previewImage", ":", "evt", ".", "target", ".", "result", ",", "localImage", ":", "evt", ".", "target", ".", "result", "}", ")", ";", "}", ";", "img", ".", "src", "=", "evt", ".", "target", ".", "result", ";", "}", ";", "reader", ".", "readAsDataURL", "(", "file", ")", ";", "return", "uploadDesign", ";", "}" ]
Upload image to Spreadshirt platform. @param {File} file @param {Function} [callback] @returns {sprd.type.UploadDesign}
[ "Upload", "image", "to", "Spreadshirt", "platform", "." ]
b56f9f47fe01332f5bf885eaf4db59014f099019
https://github.com/spreadshirt/rAppid.js-sprd/blob/b56f9f47fe01332f5bf885eaf4db59014f099019/sprd/view/ImageUploadClass.js#L143-L179
36,597
iriscouch/fastcgi
fastcgi.js
on_record
function on_record(record) { var parser = this //LOG.info('Record %s: %s', RECORD_NAMES[record.header.type], record.header.recordId) record.bodies = parser.bodies parser.bodies = [] record.body_utf8 = function() { return this.bodies .map(function(data) { return data.toString() }) .join('') } var req_id = record.header.recordId if(req_id == 0) return LOG.info('Ignoring management record: %j', record) var request = requests_in_flight[req_id] if(!request) return LOG.error('Record for unknown request: %s\n%s', req_id, util.inspect(request)) if(record.header.type == FCGI.constants.record.FCGI_STDERR) return LOG.error('Error: %s', record.body_utf8().trim()) else if(record.header.type == FCGI.constants.record.FCGI_STDOUT) { request.stdout = request.stdout.concat(record.bodies) return send_stdout(request) } else if(record.header.type == FCGI.constants.record.FCGI_END) { request.res.end() LOG.info('%s %s %d', request.req.method, request.req.url, request.status) delete requests_in_flight[req_id] if(request.keepalive == FCGI.constants.keepalive.ON) process_request() // If there are more in the queue, get to them now. else socket.end() } else { LOG.info('Unknown record: %j', record) Object.keys(FCGI.constants.record).forEach(function(type) { if(record.header.type == FCGI.constants.record[type]) LOG.info('Unknown record type: %s', type) }) } }
javascript
function on_record(record) { var parser = this //LOG.info('Record %s: %s', RECORD_NAMES[record.header.type], record.header.recordId) record.bodies = parser.bodies parser.bodies = [] record.body_utf8 = function() { return this.bodies .map(function(data) { return data.toString() }) .join('') } var req_id = record.header.recordId if(req_id == 0) return LOG.info('Ignoring management record: %j', record) var request = requests_in_flight[req_id] if(!request) return LOG.error('Record for unknown request: %s\n%s', req_id, util.inspect(request)) if(record.header.type == FCGI.constants.record.FCGI_STDERR) return LOG.error('Error: %s', record.body_utf8().trim()) else if(record.header.type == FCGI.constants.record.FCGI_STDOUT) { request.stdout = request.stdout.concat(record.bodies) return send_stdout(request) } else if(record.header.type == FCGI.constants.record.FCGI_END) { request.res.end() LOG.info('%s %s %d', request.req.method, request.req.url, request.status) delete requests_in_flight[req_id] if(request.keepalive == FCGI.constants.keepalive.ON) process_request() // If there are more in the queue, get to them now. else socket.end() } else { LOG.info('Unknown record: %j', record) Object.keys(FCGI.constants.record).forEach(function(type) { if(record.header.type == FCGI.constants.record[type]) LOG.info('Unknown record type: %s', type) }) } }
[ "function", "on_record", "(", "record", ")", "{", "var", "parser", "=", "this", "//LOG.info('Record %s: %s', RECORD_NAMES[record.header.type], record.header.recordId)", "record", ".", "bodies", "=", "parser", ".", "bodies", "parser", ".", "bodies", "=", "[", "]", "record", ".", "body_utf8", "=", "function", "(", ")", "{", "return", "this", ".", "bodies", ".", "map", "(", "function", "(", "data", ")", "{", "return", "data", ".", "toString", "(", ")", "}", ")", ".", "join", "(", "''", ")", "}", "var", "req_id", "=", "record", ".", "header", ".", "recordId", "if", "(", "req_id", "==", "0", ")", "return", "LOG", ".", "info", "(", "'Ignoring management record: %j'", ",", "record", ")", "var", "request", "=", "requests_in_flight", "[", "req_id", "]", "if", "(", "!", "request", ")", "return", "LOG", ".", "error", "(", "'Record for unknown request: %s\\n%s'", ",", "req_id", ",", "util", ".", "inspect", "(", "request", ")", ")", "if", "(", "record", ".", "header", ".", "type", "==", "FCGI", ".", "constants", ".", "record", ".", "FCGI_STDERR", ")", "return", "LOG", ".", "error", "(", "'Error: %s'", ",", "record", ".", "body_utf8", "(", ")", ".", "trim", "(", ")", ")", "else", "if", "(", "record", ".", "header", ".", "type", "==", "FCGI", ".", "constants", ".", "record", ".", "FCGI_STDOUT", ")", "{", "request", ".", "stdout", "=", "request", ".", "stdout", ".", "concat", "(", "record", ".", "bodies", ")", "return", "send_stdout", "(", "request", ")", "}", "else", "if", "(", "record", ".", "header", ".", "type", "==", "FCGI", ".", "constants", ".", "record", ".", "FCGI_END", ")", "{", "request", ".", "res", ".", "end", "(", ")", "LOG", ".", "info", "(", "'%s %s %d'", ",", "request", ".", "req", ".", "method", ",", "request", ".", "req", ".", "url", ",", "request", ".", "status", ")", "delete", "requests_in_flight", "[", "req_id", "]", "if", "(", "request", ".", "keepalive", "==", "FCGI", ".", "constants", ".", "keepalive", ".", "ON", ")", "process_request", "(", ")", "// If there are more in the queue, get to them now.", "else", "socket", ".", "end", "(", ")", "}", "else", "{", "LOG", ".", "info", "(", "'Unknown record: %j'", ",", "record", ")", "Object", ".", "keys", "(", "FCGI", ".", "constants", ".", "record", ")", ".", "forEach", "(", "function", "(", "type", ")", "{", "if", "(", "record", ".", "header", ".", "type", "==", "FCGI", ".", "constants", ".", "record", "[", "type", "]", ")", "LOG", ".", "info", "(", "'Unknown record type: %s'", ",", "type", ")", "}", ")", "}", "}" ]
Handle incoming responder records.
[ "Handle", "incoming", "responder", "records", "." ]
960d540695d702931ffa587ead48d05d0bb61826
https://github.com/iriscouch/fastcgi/blob/960d540695d702931ffa587ead48d05d0bb61826/fastcgi.js#L334-L380
36,598
spreadshirt/rAppid.js-sprd
sprd/data/LabelService.js
function (object, label, callback) { var labelObject = this.$.dataSource.createEntity(ObjectLabel); labelObject.set({ object: object, objectType: this.$.dataSource.createEntity(ObjectType, this.getObjectTypeIdForElement(object)), label: label }); labelObject.save(callback); }
javascript
function (object, label, callback) { var labelObject = this.$.dataSource.createEntity(ObjectLabel); labelObject.set({ object: object, objectType: this.$.dataSource.createEntity(ObjectType, this.getObjectTypeIdForElement(object)), label: label }); labelObject.save(callback); }
[ "function", "(", "object", ",", "label", ",", "callback", ")", "{", "var", "labelObject", "=", "this", ".", "$", ".", "dataSource", ".", "createEntity", "(", "ObjectLabel", ")", ";", "labelObject", ".", "set", "(", "{", "object", ":", "object", ",", "objectType", ":", "this", ".", "$", ".", "dataSource", ".", "createEntity", "(", "ObjectType", ",", "this", ".", "getObjectTypeIdForElement", "(", "object", ")", ")", ",", "label", ":", "label", "}", ")", ";", "labelObject", ".", "save", "(", "callback", ")", ";", "}" ]
Labels an object with the given label @param {sprd.model.Model} object @param {sprd.model.Label} label @param {Function} callback
[ "Labels", "an", "object", "with", "the", "given", "label" ]
b56f9f47fe01332f5bf885eaf4db59014f099019
https://github.com/spreadshirt/rAppid.js-sprd/blob/b56f9f47fe01332f5bf885eaf4db59014f099019/sprd/data/LabelService.js#L111-L122
36,599
Rohail1/iplocate
index.js
middlewareFunction
function middlewareFunction (req,res,next){ return ipToLocation(req.ip) .then(function (location) { req.location = location; next(); }) .catch(function (error) { req.locationError = error; next(); }) }
javascript
function middlewareFunction (req,res,next){ return ipToLocation(req.ip) .then(function (location) { req.location = location; next(); }) .catch(function (error) { req.locationError = error; next(); }) }
[ "function", "middlewareFunction", "(", "req", ",", "res", ",", "next", ")", "{", "return", "ipToLocation", "(", "req", ".", "ip", ")", ".", "then", "(", "function", "(", "location", ")", "{", "req", ".", "location", "=", "location", ";", "next", "(", ")", ";", "}", ")", ".", "catch", "(", "function", "(", "error", ")", "{", "req", ".", "locationError", "=", "error", ";", "next", "(", ")", ";", "}", ")", "}" ]
Middleware Function for the IP @param {Request} req @param {Response} res @param {function} next
[ "Middleware", "Function", "for", "the", "IP" ]
7272e3b085877288aed714119f9e50bf9d08a6d6
https://github.com/Rohail1/iplocate/blob/7272e3b085877288aed714119f9e50bf9d08a6d6/index.js#L46-L58