repo
stringlengths
5
67
path
stringlengths
4
116
func_name
stringlengths
0
58
original_string
stringlengths
52
373k
language
stringclasses
1 value
code
stringlengths
52
373k
code_tokens
sequence
docstring
stringlengths
4
11.8k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
86
226
partition
stringclasses
1 value
athombv/node-linux-device
lib/Compat.js
utilCallbackAfterPromise
function utilCallbackAfterPromise(self, func, args, cb) { args = Array.prototype.slice.apply(args); let lastarg = args.pop(); if(!cb) cb = lastarg; func.apply(self, args).then(res => { try { cb(null, res); } catch(e) { process.nextTick(() => { throw e }); } }).catch((err) => { try { cb(err); } catch(e) { process.nextTick(() => { throw e }); } }); }
javascript
function utilCallbackAfterPromise(self, func, args, cb) { args = Array.prototype.slice.apply(args); let lastarg = args.pop(); if(!cb) cb = lastarg; func.apply(self, args).then(res => { try { cb(null, res); } catch(e) { process.nextTick(() => { throw e }); } }).catch((err) => { try { cb(err); } catch(e) { process.nextTick(() => { throw e }); } }); }
[ "function", "utilCallbackAfterPromise", "(", "self", ",", "func", ",", "args", ",", "cb", ")", "{", "args", "=", "Array", ".", "prototype", ".", "slice", ".", "apply", "(", "args", ")", ";", "let", "lastarg", "=", "args", ".", "pop", "(", ")", ";", "if", "(", "!", "cb", ")", "cb", "=", "lastarg", ";", "func", ".", "apply", "(", "self", ",", "args", ")", ".", "then", "(", "res", "=>", "{", "try", "{", "cb", "(", "null", ",", "res", ")", ";", "}", "catch", "(", "e", ")", "{", "process", ".", "nextTick", "(", "(", ")", "=>", "{", "throw", "e", "}", ")", ";", "}", "}", ")", ".", "catch", "(", "(", "err", ")", "=>", "{", "try", "{", "cb", "(", "err", ")", ";", "}", "catch", "(", "e", ")", "{", "process", ".", "nextTick", "(", "(", ")", "=>", "{", "throw", "e", "}", ")", ";", "}", "}", ")", ";", "}" ]
Strips the callback argument, and calls the function without, then invokes the callback when the promise returns
[ "Strips", "the", "callback", "argument", "and", "calls", "the", "function", "without", "then", "invokes", "the", "callback", "when", "the", "promise", "returns" ]
43ce13c5718d5ee0d0f0424f5541c28fd4882b3c
https://github.com/athombv/node-linux-device/blob/43ce13c5718d5ee0d0f0424f5541c28fd4882b3c/lib/Compat.js#L7-L24
train
ILLGrenoble/guacamole-common-js
src/OnScreenKeyboard.js
removeClass
function removeClass(element, classname) { // If classList supported, use that if (element.classList) element.classList.remove(classname); // Otherwise, manually filter out classes with given name else { element.className = element.className.replace(/([^ ]+)[ ]*/g, function removeMatchingClasses(match, testClassname) { // If same class, remove if (testClassname === classname) return ""; // Otherwise, allow return match; } ); } }
javascript
function removeClass(element, classname) { // If classList supported, use that if (element.classList) element.classList.remove(classname); // Otherwise, manually filter out classes with given name else { element.className = element.className.replace(/([^ ]+)[ ]*/g, function removeMatchingClasses(match, testClassname) { // If same class, remove if (testClassname === classname) return ""; // Otherwise, allow return match; } ); } }
[ "function", "removeClass", "(", "element", ",", "classname", ")", "{", "if", "(", "element", ".", "classList", ")", "element", ".", "classList", ".", "remove", "(", "classname", ")", ";", "else", "{", "element", ".", "className", "=", "element", ".", "className", ".", "replace", "(", "/", "([^ ]+)[ ]*", "/", "g", ",", "function", "removeMatchingClasses", "(", "match", ",", "testClassname", ")", "{", "if", "(", "testClassname", "===", "classname", ")", "return", "\"\"", ";", "return", "match", ";", "}", ")", ";", "}", "}" ]
Removes a CSS class from an element. @private @function @param {Element} element The element to remove a class from. @param {String} classname The name of the class to remove.
[ "Removes", "a", "CSS", "class", "from", "an", "element", "." ]
71925794155ea3fc37d2a125adbca6f8be532887
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/OnScreenKeyboard.js#L106-L128
train
ILLGrenoble/guacamole-common-js
src/OnScreenKeyboard.js
modifiersPressed
function modifiersPressed(names) { // If any required modifiers are not pressed, return false for (var i=0; i < names.length; i++) { // Test whether current modifier is pressed var name = names[i]; if (!(name in modifierKeysyms)) return false; } // Otherwise, all required modifiers are pressed return true; }
javascript
function modifiersPressed(names) { // If any required modifiers are not pressed, return false for (var i=0; i < names.length; i++) { // Test whether current modifier is pressed var name = names[i]; if (!(name in modifierKeysyms)) return false; } // Otherwise, all required modifiers are pressed return true; }
[ "function", "modifiersPressed", "(", "names", ")", "{", "for", "(", "var", "i", "=", "0", ";", "i", "<", "names", ".", "length", ";", "i", "++", ")", "{", "var", "name", "=", "names", "[", "i", "]", ";", "if", "(", "!", "(", "name", "in", "modifierKeysyms", ")", ")", "return", "false", ";", "}", "return", "true", ";", "}" ]
Returns whether all modifiers having the given names are currently active. @private @param {String[]} names The names of all modifiers to test. @returns {Boolean} true if all specified modifiers are pressed, false otherwise.
[ "Returns", "whether", "all", "modifiers", "having", "the", "given", "names", "are", "currently", "active", "." ]
71925794155ea3fc37d2a125adbca6f8be532887
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/OnScreenKeyboard.js#L223-L238
train
ILLGrenoble/guacamole-common-js
src/OnScreenKeyboard.js
press
function press(keyName, keyElement) { // Press key if not yet pressed if (!pressed[keyName]) { addClass(keyElement, "guac-keyboard-pressed"); // Get current key based on modifier state var key = getActiveKey(keyName); // Update modifier state if (key.modifier) { // Construct classname for modifier var modifierClass = "guac-keyboard-modifier-" + getCSSName(key.modifier); // Retrieve originally-pressed keysym, if modifier was already pressed var originalKeysym = modifierKeysyms[key.modifier]; // Activate modifier if not pressed if (!originalKeysym) { addClass(keyboard, modifierClass); modifierKeysyms[key.modifier] = key.keysym; // Send key event if (osk.onkeydown) osk.onkeydown(key.keysym); } // Deactivate if not pressed else { removeClass(keyboard, modifierClass); delete modifierKeysyms[key.modifier]; // Send key event if (osk.onkeyup) osk.onkeyup(originalKeysym); } } // If not modifier, send key event now else if (osk.onkeydown) osk.onkeydown(key.keysym); // Mark key as pressed pressed[keyName] = true; } }
javascript
function press(keyName, keyElement) { // Press key if not yet pressed if (!pressed[keyName]) { addClass(keyElement, "guac-keyboard-pressed"); // Get current key based on modifier state var key = getActiveKey(keyName); // Update modifier state if (key.modifier) { // Construct classname for modifier var modifierClass = "guac-keyboard-modifier-" + getCSSName(key.modifier); // Retrieve originally-pressed keysym, if modifier was already pressed var originalKeysym = modifierKeysyms[key.modifier]; // Activate modifier if not pressed if (!originalKeysym) { addClass(keyboard, modifierClass); modifierKeysyms[key.modifier] = key.keysym; // Send key event if (osk.onkeydown) osk.onkeydown(key.keysym); } // Deactivate if not pressed else { removeClass(keyboard, modifierClass); delete modifierKeysyms[key.modifier]; // Send key event if (osk.onkeyup) osk.onkeyup(originalKeysym); } } // If not modifier, send key event now else if (osk.onkeydown) osk.onkeydown(key.keysym); // Mark key as pressed pressed[keyName] = true; } }
[ "function", "press", "(", "keyName", ",", "keyElement", ")", "{", "if", "(", "!", "pressed", "[", "keyName", "]", ")", "{", "addClass", "(", "keyElement", ",", "\"guac-keyboard-pressed\"", ")", ";", "var", "key", "=", "getActiveKey", "(", "keyName", ")", ";", "if", "(", "key", ".", "modifier", ")", "{", "var", "modifierClass", "=", "\"guac-keyboard-modifier-\"", "+", "getCSSName", "(", "key", ".", "modifier", ")", ";", "var", "originalKeysym", "=", "modifierKeysyms", "[", "key", ".", "modifier", "]", ";", "if", "(", "!", "originalKeysym", ")", "{", "addClass", "(", "keyboard", ",", "modifierClass", ")", ";", "modifierKeysyms", "[", "key", ".", "modifier", "]", "=", "key", ".", "keysym", ";", "if", "(", "osk", ".", "onkeydown", ")", "osk", ".", "onkeydown", "(", "key", ".", "keysym", ")", ";", "}", "else", "{", "removeClass", "(", "keyboard", ",", "modifierClass", ")", ";", "delete", "modifierKeysyms", "[", "key", ".", "modifier", "]", ";", "if", "(", "osk", ".", "onkeyup", ")", "osk", ".", "onkeyup", "(", "originalKeysym", ")", ";", "}", "}", "else", "if", "(", "osk", ".", "onkeydown", ")", "osk", ".", "onkeydown", "(", "key", ".", "keysym", ")", ";", "pressed", "[", "keyName", "]", "=", "true", ";", "}", "}" ]
Presses the key having the given name, updating the associated key element with the "guac-keyboard-pressed" CSS class. If the key is already pressed, this function has no effect. @private @param {String} keyName The name of the key to press. @param {String} keyElement The element associated with the given key.
[ "Presses", "the", "key", "having", "the", "given", "name", "updating", "the", "associated", "key", "element", "with", "the", "guac", "-", "keyboard", "-", "pressed", "CSS", "class", ".", "If", "the", "key", "is", "already", "pressed", "this", "function", "has", "no", "effect", "." ]
71925794155ea3fc37d2a125adbca6f8be532887
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/OnScreenKeyboard.js#L290-L344
train
ILLGrenoble/guacamole-common-js
src/OnScreenKeyboard.js
release
function release(keyName, keyElement) { // Release key if currently pressed if (pressed[keyName]) { removeClass(keyElement, "guac-keyboard-pressed"); // Get current key based on modifier state var key = getActiveKey(keyName); // Send key event if not a modifier key if (!key.modifier && osk.onkeyup) osk.onkeyup(key.keysym); // Mark key as released pressed[keyName] = false; } }
javascript
function release(keyName, keyElement) { // Release key if currently pressed if (pressed[keyName]) { removeClass(keyElement, "guac-keyboard-pressed"); // Get current key based on modifier state var key = getActiveKey(keyName); // Send key event if not a modifier key if (!key.modifier && osk.onkeyup) osk.onkeyup(key.keysym); // Mark key as released pressed[keyName] = false; } }
[ "function", "release", "(", "keyName", ",", "keyElement", ")", "{", "if", "(", "pressed", "[", "keyName", "]", ")", "{", "removeClass", "(", "keyElement", ",", "\"guac-keyboard-pressed\"", ")", ";", "var", "key", "=", "getActiveKey", "(", "keyName", ")", ";", "if", "(", "!", "key", ".", "modifier", "&&", "osk", ".", "onkeyup", ")", "osk", ".", "onkeyup", "(", "key", ".", "keysym", ")", ";", "pressed", "[", "keyName", "]", "=", "false", ";", "}", "}" ]
Releases the key having the given name, removing the "guac-keyboard-pressed" CSS class from the associated element. If the key is already released, this function has no effect. @private @param {String} keyName The name of the key to release. @param {String} keyElement The element associated with the given key.
[ "Releases", "the", "key", "having", "the", "given", "name", "removing", "the", "guac", "-", "keyboard", "-", "pressed", "CSS", "class", "from", "the", "associated", "element", ".", "If", "the", "key", "is", "already", "released", "this", "function", "has", "no", "effect", "." ]
71925794155ea3fc37d2a125adbca6f8be532887
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/OnScreenKeyboard.js#L358-L377
train
ILLGrenoble/guacamole-common-js
src/OnScreenKeyboard.js
getKeys
function getKeys(keys) { var keyArrays = {}; // Coerce all keys into individual key arrays for (var name in layout.keys) { keyArrays[name] = asKeyArray(name, keys[name]); } return keyArrays; }
javascript
function getKeys(keys) { var keyArrays = {}; // Coerce all keys into individual key arrays for (var name in layout.keys) { keyArrays[name] = asKeyArray(name, keys[name]); } return keyArrays; }
[ "function", "getKeys", "(", "keys", ")", "{", "var", "keyArrays", "=", "{", "}", ";", "for", "(", "var", "name", "in", "layout", ".", "keys", ")", "{", "keyArrays", "[", "name", "]", "=", "asKeyArray", "(", "name", ",", "keys", "[", "name", "]", ")", ";", "}", "return", "keyArrays", ";", "}" ]
Converts the rather forgiving key mapping allowed by Guacamole.OnScreenKeyboard.Layout into a rigorous mapping of key name to key definition, where the key definition is always an array of Key objects. @private @param {Object.<String, Number|String|Guacamole.OnScreenKeyboard.Key|Guacamole.OnScreenKeyboard.Key[]>} keys A mapping of key name to key definition, where the key definition is the title of the key (a string), the keysym (a number), a single Key object, or an array of Key objects. @returns {Object.<String, Guacamole.OnScreenKeyboard.Key[]>} A more-predictable mapping of key name to key definition, where the key definition is always simply an array of Key objects.
[ "Converts", "the", "rather", "forgiving", "key", "mapping", "allowed", "by", "Guacamole", ".", "OnScreenKeyboard", ".", "Layout", "into", "a", "rigorous", "mapping", "of", "key", "name", "to", "key", "definition", "where", "the", "key", "definition", "is", "always", "an", "array", "of", "Key", "objects", "." ]
71925794155ea3fc37d2a125adbca6f8be532887
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/OnScreenKeyboard.js#L535-L546
train
ILLGrenoble/guacamole-common-js
src/OnScreenKeyboard.js
getCSSName
function getCSSName(name) { // Convert name from possibly-CamelCase to hyphenated lowercase var cssName = name .replace(/([a-z])([A-Z])/g, '$1-$2') .replace(/[^A-Za-z0-9]+/g, '-') .toLowerCase(); return cssName; }
javascript
function getCSSName(name) { // Convert name from possibly-CamelCase to hyphenated lowercase var cssName = name .replace(/([a-z])([A-Z])/g, '$1-$2') .replace(/[^A-Za-z0-9]+/g, '-') .toLowerCase(); return cssName; }
[ "function", "getCSSName", "(", "name", ")", "{", "var", "cssName", "=", "name", ".", "replace", "(", "/", "([a-z])([A-Z])", "/", "g", ",", "'$1-$2'", ")", ".", "replace", "(", "/", "[^A-Za-z0-9]+", "/", "g", ",", "'-'", ")", ".", "toLowerCase", "(", ")", ";", "return", "cssName", ";", "}" ]
Given an arbitrary string representing the name of some component of the on-screen keyboard, returns a string formatted for use as a CSS class name. The result will be lowercase. Word boundaries previously denoted by CamelCase will be replaced by individual hyphens, as will all contiguous non-alphanumeric characters. @private @param {String} name An arbitrary string representing the name of some component of the on-screen keyboard. @returns {String} A string formatted for use as a CSS class name.
[ "Given", "an", "arbitrary", "string", "representing", "the", "name", "of", "some", "component", "of", "the", "on", "-", "screen", "keyboard", "returns", "a", "string", "formatted", "for", "use", "as", "a", "CSS", "class", "name", ".", "The", "result", "will", "be", "lowercase", ".", "Word", "boundaries", "previously", "denoted", "by", "CamelCase", "will", "be", "replaced", "by", "individual", "hyphens", "as", "will", "all", "contiguous", "non", "-", "alphanumeric", "characters", "." ]
71925794155ea3fc37d2a125adbca6f8be532887
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/OnScreenKeyboard.js#L571-L581
train
ILLGrenoble/guacamole-common-js
src/OnScreenKeyboard.js
touchPress
function touchPress(e) { e.preventDefault(); ignoreMouse = osk.touchMouseThreshold; press(object, keyElement); }
javascript
function touchPress(e) { e.preventDefault(); ignoreMouse = osk.touchMouseThreshold; press(object, keyElement); }
[ "function", "touchPress", "(", "e", ")", "{", "e", ".", "preventDefault", "(", ")", ";", "ignoreMouse", "=", "osk", ".", "touchMouseThreshold", ";", "press", "(", "object", ",", "keyElement", ")", ";", "}" ]
Handles a touch event which results in the pressing of an OSK key. Touch events will result in mouse events being ignored for touchMouseThreshold events. @private @param {TouchEvent} e The touch event being handled.
[ "Handles", "a", "touch", "event", "which", "results", "in", "the", "pressing", "of", "an", "OSK", "key", ".", "Touch", "events", "will", "result", "in", "mouse", "events", "being", "ignored", "for", "touchMouseThreshold", "events", "." ]
71925794155ea3fc37d2a125adbca6f8be532887
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/OnScreenKeyboard.js#L726-L730
train
ILLGrenoble/guacamole-common-js
src/OnScreenKeyboard.js
touchRelease
function touchRelease(e) { e.preventDefault(); ignoreMouse = osk.touchMouseThreshold; release(object, keyElement); }
javascript
function touchRelease(e) { e.preventDefault(); ignoreMouse = osk.touchMouseThreshold; release(object, keyElement); }
[ "function", "touchRelease", "(", "e", ")", "{", "e", ".", "preventDefault", "(", ")", ";", "ignoreMouse", "=", "osk", ".", "touchMouseThreshold", ";", "release", "(", "object", ",", "keyElement", ")", ";", "}" ]
Handles a touch event which results in the release of an OSK key. Touch events will result in mouse events being ignored for touchMouseThreshold events. @private @param {TouchEvent} e The touch event being handled.
[ "Handles", "a", "touch", "event", "which", "results", "in", "the", "release", "of", "an", "OSK", "key", ".", "Touch", "events", "will", "result", "in", "mouse", "events", "being", "ignored", "for", "touchMouseThreshold", "events", "." ]
71925794155ea3fc37d2a125adbca6f8be532887
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/OnScreenKeyboard.js#L741-L745
train
Twipped/QueryizeJS
lib/mutators.js
_makeJoiner
function _makeJoiner (type) { return function (clause, options) { if (isQueryizeObject(clause)) { if (typeof options !== 'object') throw new Error('You must define join options when joining against a queryize subquery.'); options = Object.create(options); options.table = clause; clause = options; } else if (typeof clause === 'object') { if (isArray(clause)) throw new TypeError('Join clauses can only be strings or object definitions'); if (!clause.table) throw new Error('You must define a table to join against'); } else if (typeof options === 'object') { options = Object.create(options); options.table = clause; clause = options; } if (typeof clause === 'object') { clause.type = type; } else { clause = clause.search(joinTest) > -1 ? clause.replace(joinTest, type + ' JOIN ') : type + ' JOIN ' + clause; } this.join(clause); return this; }; }
javascript
function _makeJoiner (type) { return function (clause, options) { if (isQueryizeObject(clause)) { if (typeof options !== 'object') throw new Error('You must define join options when joining against a queryize subquery.'); options = Object.create(options); options.table = clause; clause = options; } else if (typeof clause === 'object') { if (isArray(clause)) throw new TypeError('Join clauses can only be strings or object definitions'); if (!clause.table) throw new Error('You must define a table to join against'); } else if (typeof options === 'object') { options = Object.create(options); options.table = clause; clause = options; } if (typeof clause === 'object') { clause.type = type; } else { clause = clause.search(joinTest) > -1 ? clause.replace(joinTest, type + ' JOIN ') : type + ' JOIN ' + clause; } this.join(clause); return this; }; }
[ "function", "_makeJoiner", "(", "type", ")", "{", "return", "function", "(", "clause", ",", "options", ")", "{", "if", "(", "isQueryizeObject", "(", "clause", ")", ")", "{", "if", "(", "typeof", "options", "!==", "'object'", ")", "throw", "new", "Error", "(", "'You must define join options when joining against a queryize subquery.'", ")", ";", "options", "=", "Object", ".", "create", "(", "options", ")", ";", "options", ".", "table", "=", "clause", ";", "clause", "=", "options", ";", "}", "else", "if", "(", "typeof", "clause", "===", "'object'", ")", "{", "if", "(", "isArray", "(", "clause", ")", ")", "throw", "new", "TypeError", "(", "'Join clauses can only be strings or object definitions'", ")", ";", "if", "(", "!", "clause", ".", "table", ")", "throw", "new", "Error", "(", "'You must define a table to join against'", ")", ";", "}", "else", "if", "(", "typeof", "options", "===", "'object'", ")", "{", "options", "=", "Object", ".", "create", "(", "options", ")", ";", "options", ".", "table", "=", "clause", ";", "clause", "=", "options", ";", "}", "if", "(", "typeof", "clause", "===", "'object'", ")", "{", "clause", ".", "type", "=", "type", ";", "}", "else", "{", "clause", "=", "clause", ".", "search", "(", "joinTest", ")", ">", "-", "1", "?", "clause", ".", "replace", "(", "joinTest", ",", "type", "+", "' JOIN '", ")", ":", "type", "+", "' JOIN '", "+", "clause", ";", "}", "this", ".", "join", "(", "clause", ")", ";", "return", "this", ";", "}", ";", "}" ]
Generates the closures for innerJoin, leftJoin and rightJoin @private @param {string} type Join type @return {function}
[ "Generates", "the", "closures", "for", "innerJoin", "leftJoin", "and", "rightJoin" ]
fdee3e8900f6a95419b88056916577f9b0067c93
https://github.com/Twipped/QueryizeJS/blob/fdee3e8900f6a95419b88056916577f9b0067c93/lib/mutators.js#L1189-L1216
train
Twipped/QueryizeJS
lib/mutators.js
flatten
function flatten (input, includingObjects) { var result = []; function descend (level) { if (isArray(level)) { level.forEach(descend); } else if (typeof level === 'object' && includingObjects) { Object.keys(level).forEach(function (key) { descend(level[key]); }); } else { result.push(level); } } descend(input); return result; }
javascript
function flatten (input, includingObjects) { var result = []; function descend (level) { if (isArray(level)) { level.forEach(descend); } else if (typeof level === 'object' && includingObjects) { Object.keys(level).forEach(function (key) { descend(level[key]); }); } else { result.push(level); } } descend(input); return result; }
[ "function", "flatten", "(", "input", ",", "includingObjects", ")", "{", "var", "result", "=", "[", "]", ";", "function", "descend", "(", "level", ")", "{", "if", "(", "isArray", "(", "level", ")", ")", "{", "level", ".", "forEach", "(", "descend", ")", ";", "}", "else", "if", "(", "typeof", "level", "===", "'object'", "&&", "includingObjects", ")", "{", "Object", ".", "keys", "(", "level", ")", ".", "forEach", "(", "function", "(", "key", ")", "{", "descend", "(", "level", "[", "key", "]", ")", ";", "}", ")", ";", "}", "else", "{", "result", ".", "push", "(", "level", ")", ";", "}", "}", "descend", "(", "input", ")", ";", "return", "result", ";", "}" ]
Flattens a nested array into a single level array @private @param {Array} input The top level array to flatten @param {boolean} [includingObjects=false] If an object is encountered and this argument is truthy, the object will also be flattened by its property values. @return {Array}
[ "Flattens", "a", "nested", "array", "into", "a", "single", "level", "array" ]
fdee3e8900f6a95419b88056916577f9b0067c93
https://github.com/Twipped/QueryizeJS/blob/fdee3e8900f6a95419b88056916577f9b0067c93/lib/mutators.js#L1922-L1940
train
Twipped/QueryizeJS
lib/mutators.js
mysqlDate
function mysqlDate (input) { var date = new Date(input.getTime()); date.setMinutes(date.getMinutes() + date.getTimezoneOffset()); var y = date.getFullYear(); var m = ('0' + (date.getMonth() + 1)).substr(-2); var d = ('0' + date.getDate()).substr(-2); var h = ('0' + date.getHours()).substr(-2); var i = ('0' + date.getMinutes()).substr(-2); var s = ('0' + date.getSeconds()).substr(-2); return y + '-' + m + '-' + d + ' ' + h + ':' + i + ':' + s; }
javascript
function mysqlDate (input) { var date = new Date(input.getTime()); date.setMinutes(date.getMinutes() + date.getTimezoneOffset()); var y = date.getFullYear(); var m = ('0' + (date.getMonth() + 1)).substr(-2); var d = ('0' + date.getDate()).substr(-2); var h = ('0' + date.getHours()).substr(-2); var i = ('0' + date.getMinutes()).substr(-2); var s = ('0' + date.getSeconds()).substr(-2); return y + '-' + m + '-' + d + ' ' + h + ':' + i + ':' + s; }
[ "function", "mysqlDate", "(", "input", ")", "{", "var", "date", "=", "new", "Date", "(", "input", ".", "getTime", "(", ")", ")", ";", "date", ".", "setMinutes", "(", "date", ".", "getMinutes", "(", ")", "+", "date", ".", "getTimezoneOffset", "(", ")", ")", ";", "var", "y", "=", "date", ".", "getFullYear", "(", ")", ";", "var", "m", "=", "(", "'0'", "+", "(", "date", ".", "getMonth", "(", ")", "+", "1", ")", ")", ".", "substr", "(", "-", "2", ")", ";", "var", "d", "=", "(", "'0'", "+", "date", ".", "getDate", "(", ")", ")", ".", "substr", "(", "-", "2", ")", ";", "var", "h", "=", "(", "'0'", "+", "date", ".", "getHours", "(", ")", ")", ".", "substr", "(", "-", "2", ")", ";", "var", "i", "=", "(", "'0'", "+", "date", ".", "getMinutes", "(", ")", ")", ".", "substr", "(", "-", "2", ")", ";", "var", "s", "=", "(", "'0'", "+", "date", ".", "getSeconds", "(", ")", ")", ".", "substr", "(", "-", "2", ")", ";", "return", "y", "+", "'-'", "+", "m", "+", "'-'", "+", "d", "+", "' '", "+", "h", "+", "':'", "+", "i", "+", "':'", "+", "s", ";", "}" ]
Formats a Date object into a MySQL DATETIME @param {Date} date [description] @private @return {string} [description]
[ "Formats", "a", "Date", "object", "into", "a", "MySQL", "DATETIME" ]
fdee3e8900f6a95419b88056916577f9b0067c93
https://github.com/Twipped/QueryizeJS/blob/fdee3e8900f6a95419b88056916577f9b0067c93/lib/mutators.js#L1948-L1960
train
Twipped/QueryizeJS
lib/mutators.js
arrayFromArguments
function arrayFromArguments () { var len = arguments.length; var args = new Array(len); for (var i = 0; i < len; ++i) { args[i] = arguments[i]; } return args; }
javascript
function arrayFromArguments () { var len = arguments.length; var args = new Array(len); for (var i = 0; i < len; ++i) { args[i] = arguments[i]; } return args; }
[ "function", "arrayFromArguments", "(", ")", "{", "var", "len", "=", "arguments", ".", "length", ";", "var", "args", "=", "new", "Array", "(", "len", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "len", ";", "++", "i", ")", "{", "args", "[", "i", "]", "=", "arguments", "[", "i", "]", ";", "}", "return", "args", ";", "}" ]
Helper function to convert arguments to an array without triggering de-optimization in V8 MUST be called via .apply @private @return {Array<mixed>}
[ "Helper", "function", "to", "convert", "arguments", "to", "an", "array", "without", "triggering", "de", "-", "optimization", "in", "V8", "MUST", "be", "called", "via", ".", "apply" ]
fdee3e8900f6a95419b88056916577f9b0067c93
https://github.com/Twipped/QueryizeJS/blob/fdee3e8900f6a95419b88056916577f9b0067c93/lib/mutators.js#L1968-L1975
train
latentflip/base32-crockford-browser
dist/base32.js
function() { var table = {} // Invert 'alphabet' for (var i = 0; i < alphabet.length; i++) { table[alphabet[i]] = i } // Splice in 'alias' for (var key in alias) { if (!alias.hasOwnProperty(key)) continue table[key] = table['' + alias[key]] } lookup = function() { return table } return table }
javascript
function() { var table = {} // Invert 'alphabet' for (var i = 0; i < alphabet.length; i++) { table[alphabet[i]] = i } // Splice in 'alias' for (var key in alias) { if (!alias.hasOwnProperty(key)) continue table[key] = table['' + alias[key]] } lookup = function() { return table } return table }
[ "function", "(", ")", "{", "var", "table", "=", "{", "}", "for", "(", "var", "i", "=", "0", ";", "i", "<", "alphabet", ".", "length", ";", "i", "++", ")", "{", "table", "[", "alphabet", "[", "i", "]", "]", "=", "i", "}", "for", "(", "var", "key", "in", "alias", ")", "{", "if", "(", "!", "alias", ".", "hasOwnProperty", "(", "key", ")", ")", "continue", "table", "[", "key", "]", "=", "table", "[", "''", "+", "alias", "[", "key", "]", "]", "}", "lookup", "=", "function", "(", ")", "{", "return", "table", "}", "return", "table", "}" ]
Build a lookup table and memoize it Return an object that maps a character to its byte value.
[ "Build", "a", "lookup", "table", "and", "memoize", "it" ]
6ae0826cc89838fc935160e8547edf77f6690858
https://github.com/latentflip/base32-crockford-browser/blob/6ae0826cc89838fc935160e8547edf77f6690858/dist/base32.js#L16-L29
train
latentflip/base32-crockford-browser
dist/base32.js
Encoder
function Encoder() { var skip = 0 // how many bits we will skip from the first byte var bits = 0 // 5 high bits, carry from one byte to the next this.output = '' // Read one byte of input // Should not really be used except by "update" this.readByte = function(byte) { // coerce the byte to an int if (typeof byte == 'string') byte = byte.charCodeAt(0) if (skip < 0) { // we have a carry from the previous byte bits |= (byte >> (-skip)) } else { // no carry bits = (byte << skip) & 248 } if (skip > 3) { // not enough data to produce a character, get us another one skip -= 8 return 1 } if (skip < 4) { // produce a character this.output += alphabet[bits >> 3] skip += 5 } return 0 } // Flush any remaining bits left in the stream this.finish = function(check) { var output = this.output + (skip < 0 ? alphabet[bits >> 3] : '') + (check ? '$' : '') this.output = '' return output } }
javascript
function Encoder() { var skip = 0 // how many bits we will skip from the first byte var bits = 0 // 5 high bits, carry from one byte to the next this.output = '' // Read one byte of input // Should not really be used except by "update" this.readByte = function(byte) { // coerce the byte to an int if (typeof byte == 'string') byte = byte.charCodeAt(0) if (skip < 0) { // we have a carry from the previous byte bits |= (byte >> (-skip)) } else { // no carry bits = (byte << skip) & 248 } if (skip > 3) { // not enough data to produce a character, get us another one skip -= 8 return 1 } if (skip < 4) { // produce a character this.output += alphabet[bits >> 3] skip += 5 } return 0 } // Flush any remaining bits left in the stream this.finish = function(check) { var output = this.output + (skip < 0 ? alphabet[bits >> 3] : '') + (check ? '$' : '') this.output = '' return output } }
[ "function", "Encoder", "(", ")", "{", "var", "skip", "=", "0", "var", "bits", "=", "0", "this", ".", "output", "=", "''", "this", ".", "readByte", "=", "function", "(", "byte", ")", "{", "if", "(", "typeof", "byte", "==", "'string'", ")", "byte", "=", "byte", ".", "charCodeAt", "(", "0", ")", "if", "(", "skip", "<", "0", ")", "{", "bits", "|=", "(", "byte", ">>", "(", "-", "skip", ")", ")", "}", "else", "{", "bits", "=", "(", "byte", "<<", "skip", ")", "&", "248", "}", "if", "(", "skip", ">", "3", ")", "{", "skip", "-=", "8", "return", "1", "}", "if", "(", "skip", "<", "4", ")", "{", "this", ".", "output", "+=", "alphabet", "[", "bits", ">>", "3", "]", "skip", "+=", "5", "}", "return", "0", "}", "this", ".", "finish", "=", "function", "(", "check", ")", "{", "var", "output", "=", "this", ".", "output", "+", "(", "skip", "<", "0", "?", "alphabet", "[", "bits", ">>", "3", "]", ":", "''", ")", "+", "(", "check", "?", "'$'", ":", "''", ")", "this", ".", "output", "=", "''", "return", "output", "}", "}" ]
A streaming encoder var encoder = new base32.Encoder() var output1 = encoder.update(input1) var output2 = encoder.update(input2) var lastoutput = encode.update(lastinput, true)
[ "A", "streaming", "encoder" ]
6ae0826cc89838fc935160e8547edf77f6690858
https://github.com/latentflip/base32-crockford-browser/blob/6ae0826cc89838fc935160e8547edf77f6690858/dist/base32.js#L40-L79
train
latentflip/base32-crockford-browser
dist/base32.js
Decoder
function Decoder() { var skip = 0 // how many bits we have from the previous character var byte = 0 // current byte we're producing this.output = '' // Consume a character from the stream, store // the output in this.output. As before, better // to use update(). this.readChar = function(char) { if (typeof char != 'string'){ if (typeof char == 'number') { char = String.fromCharCode(char) } } char = char.toLowerCase() var val = lookup()[char] if (typeof val == 'undefined') { // character does not exist in our lookup table return // skip silently. An alternative would be: // throw Error('Could not find character "' + char + '" in lookup table.') } val <<= 3 // move to the high bits byte |= val >>> skip skip += 5 if (skip >= 8) { // we have enough to preduce output this.output += String.fromCharCode(byte) skip -= 8 if (skip > 0) byte = (val << (5 - skip)) & 255 else byte = 0 } } this.finish = function(check) { var output = this.output + (skip < 0 ? alphabet[bits >> 3] : '') + (check ? '$' : '') this.output = '' return output } }
javascript
function Decoder() { var skip = 0 // how many bits we have from the previous character var byte = 0 // current byte we're producing this.output = '' // Consume a character from the stream, store // the output in this.output. As before, better // to use update(). this.readChar = function(char) { if (typeof char != 'string'){ if (typeof char == 'number') { char = String.fromCharCode(char) } } char = char.toLowerCase() var val = lookup()[char] if (typeof val == 'undefined') { // character does not exist in our lookup table return // skip silently. An alternative would be: // throw Error('Could not find character "' + char + '" in lookup table.') } val <<= 3 // move to the high bits byte |= val >>> skip skip += 5 if (skip >= 8) { // we have enough to preduce output this.output += String.fromCharCode(byte) skip -= 8 if (skip > 0) byte = (val << (5 - skip)) & 255 else byte = 0 } } this.finish = function(check) { var output = this.output + (skip < 0 ? alphabet[bits >> 3] : '') + (check ? '$' : '') this.output = '' return output } }
[ "function", "Decoder", "(", ")", "{", "var", "skip", "=", "0", "var", "byte", "=", "0", "this", ".", "output", "=", "''", "this", ".", "readChar", "=", "function", "(", "char", ")", "{", "if", "(", "typeof", "char", "!=", "'string'", ")", "{", "if", "(", "typeof", "char", "==", "'number'", ")", "{", "char", "=", "String", ".", "fromCharCode", "(", "char", ")", "}", "}", "char", "=", "char", ".", "toLowerCase", "(", ")", "var", "val", "=", "lookup", "(", ")", "[", "char", "]", "if", "(", "typeof", "val", "==", "'undefined'", ")", "{", "return", "}", "val", "<<=", "3", "byte", "|=", "val", ">>>", "skip", "skip", "+=", "5", "if", "(", "skip", ">=", "8", ")", "{", "this", ".", "output", "+=", "String", ".", "fromCharCode", "(", "byte", ")", "skip", "-=", "8", "if", "(", "skip", ">", "0", ")", "byte", "=", "(", "val", "<<", "(", "5", "-", "skip", ")", ")", "&", "255", "else", "byte", "=", "0", "}", "}", "this", ".", "finish", "=", "function", "(", "check", ")", "{", "var", "output", "=", "this", ".", "output", "+", "(", "skip", "<", "0", "?", "alphabet", "[", "bits", ">>", "3", "]", ":", "''", ")", "+", "(", "check", "?", "'$'", ":", "''", ")", "this", ".", "output", "=", "''", "return", "output", "}", "}" ]
Functions analogously to Encoder
[ "Functions", "analogously", "to", "Encoder" ]
6ae0826cc89838fc935160e8547edf77f6690858
https://github.com/latentflip/base32-crockford-browser/blob/6ae0826cc89838fc935160e8547edf77f6690858/dist/base32.js#L105-L145
train
latentflip/base32-crockford-browser
dist/base32.js
decode
function decode(input) { var decoder = new Decoder() var output = decoder.update(input, true) return output }
javascript
function decode(input) { var decoder = new Decoder() var output = decoder.update(input, true) return output }
[ "function", "decode", "(", "input", ")", "{", "var", "decoder", "=", "new", "Decoder", "(", ")", "var", "output", "=", "decoder", ".", "update", "(", "input", ",", "true", ")", "return", "output", "}" ]
Base32-encoded string goes in, decoded data comes out.
[ "Base32", "-", "encoded", "string", "goes", "in", "decoded", "data", "comes", "out", "." ]
6ae0826cc89838fc935160e8547edf77f6690858
https://github.com/latentflip/base32-crockford-browser/blob/6ae0826cc89838fc935160e8547edf77f6690858/dist/base32.js#L173-L177
train
delian/node-amfutils
amfUtils.js
amf3decUI29
function amf3decUI29(buf) { var val = 0; var len = 1; var b; do { b = buf.readUInt8(len++); val = (val << 7) + (b & 0x7F); } while (len < 5 || b > 0x7F); if (len == 5) val = val | b; // Preserve the major bit of the last byte return { len: len, value: val } }
javascript
function amf3decUI29(buf) { var val = 0; var len = 1; var b; do { b = buf.readUInt8(len++); val = (val << 7) + (b & 0x7F); } while (len < 5 || b > 0x7F); if (len == 5) val = val | b; // Preserve the major bit of the last byte return { len: len, value: val } }
[ "function", "amf3decUI29", "(", "buf", ")", "{", "var", "val", "=", "0", ";", "var", "len", "=", "1", ";", "var", "b", ";", "do", "{", "b", "=", "buf", ".", "readUInt8", "(", "len", "++", ")", ";", "val", "=", "(", "val", "<<", "7", ")", "+", "(", "b", "&", "0x7F", ")", ";", "}", "while", "(", "len", "<", "5", "||", "b", ">", "0x7F", ")", ";", "if", "(", "len", "==", "5", ")", "val", "=", "val", "|", "b", ";", "return", "{", "len", ":", "len", ",", "value", ":", "val", "}", "}" ]
Generic decode of AMF3 UInt29 values @param buf @returns {{len: number, value: number}}
[ "Generic", "decode", "of", "AMF3", "UInt29", "values" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L178-L191
train
delian/node-amfutils
amfUtils.js
amf3encUI29
function amf3encUI29(num) { var len = 0; if (num < 0x80) len = 1; if (num < 0x4000) len = 2; if (num < 0x200000) len = 3; if (num >= 0x200000) len = 4; var buf = new Buffer(len); switch (len) { case 1: buf.writeUInt8(num, 0); break; case 2: buf.writeUInt8(num & 0x7F, 0); buf.writeUInt8((num >> 7) | 0x80, 1); break; case 3: buf.writeUInt8(num & 0x7F, 0); buf.writeUInt8((num >> 7) & 0x7F, 1); buf.writeUInt8((num >> 14) | 0x80, 2); break; case 4: buf.writeUInt8(num & 0xFF, 0); buf.writeUInt8((num >> 8) & 0x7F, 1); buf.writeUInt8((num >> 15) | 0x7F, 2); buf.writeUInt8((num >> 22) | 0x7F, 3); break; } return buf; }
javascript
function amf3encUI29(num) { var len = 0; if (num < 0x80) len = 1; if (num < 0x4000) len = 2; if (num < 0x200000) len = 3; if (num >= 0x200000) len = 4; var buf = new Buffer(len); switch (len) { case 1: buf.writeUInt8(num, 0); break; case 2: buf.writeUInt8(num & 0x7F, 0); buf.writeUInt8((num >> 7) | 0x80, 1); break; case 3: buf.writeUInt8(num & 0x7F, 0); buf.writeUInt8((num >> 7) & 0x7F, 1); buf.writeUInt8((num >> 14) | 0x80, 2); break; case 4: buf.writeUInt8(num & 0xFF, 0); buf.writeUInt8((num >> 8) & 0x7F, 1); buf.writeUInt8((num >> 15) | 0x7F, 2); buf.writeUInt8((num >> 22) | 0x7F, 3); break; } return buf; }
[ "function", "amf3encUI29", "(", "num", ")", "{", "var", "len", "=", "0", ";", "if", "(", "num", "<", "0x80", ")", "len", "=", "1", ";", "if", "(", "num", "<", "0x4000", ")", "len", "=", "2", ";", "if", "(", "num", "<", "0x200000", ")", "len", "=", "3", ";", "if", "(", "num", ">=", "0x200000", ")", "len", "=", "4", ";", "var", "buf", "=", "new", "Buffer", "(", "len", ")", ";", "switch", "(", "len", ")", "{", "case", "1", ":", "buf", ".", "writeUInt8", "(", "num", ",", "0", ")", ";", "break", ";", "case", "2", ":", "buf", ".", "writeUInt8", "(", "num", "&", "0x7F", ",", "0", ")", ";", "buf", ".", "writeUInt8", "(", "(", "num", ">>", "7", ")", "|", "0x80", ",", "1", ")", ";", "break", ";", "case", "3", ":", "buf", ".", "writeUInt8", "(", "num", "&", "0x7F", ",", "0", ")", ";", "buf", ".", "writeUInt8", "(", "(", "num", ">>", "7", ")", "&", "0x7F", ",", "1", ")", ";", "buf", ".", "writeUInt8", "(", "(", "num", ">>", "14", ")", "|", "0x80", ",", "2", ")", ";", "break", ";", "case", "4", ":", "buf", ".", "writeUInt8", "(", "num", "&", "0xFF", ",", "0", ")", ";", "buf", ".", "writeUInt8", "(", "(", "num", ">>", "8", ")", "&", "0x7F", ",", "1", ")", ";", "buf", ".", "writeUInt8", "(", "(", "num", ">>", "15", ")", "|", "0x7F", ",", "2", ")", ";", "buf", ".", "writeUInt8", "(", "(", "num", ">>", "22", ")", "|", "0x7F", ",", "3", ")", ";", "break", ";", "}", "return", "buf", ";", "}" ]
Generic encode of AMF3 UInt29 value @param num @returns {Buffer}
[ "Generic", "encode", "of", "AMF3", "UInt29", "value" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L198-L226
train
delian/node-amfutils
amfUtils.js
amf3decInteger
function amf3decInteger(buf) { // Invert the integer var resp = amf3decUI29(buf); if (resp.value > 0x0FFFFFFF) resp.value = (resp.value & 0x0FFFFFFF) - 0x10000000; return resp; }
javascript
function amf3decInteger(buf) { // Invert the integer var resp = amf3decUI29(buf); if (resp.value > 0x0FFFFFFF) resp.value = (resp.value & 0x0FFFFFFF) - 0x10000000; return resp; }
[ "function", "amf3decInteger", "(", "buf", ")", "{", "var", "resp", "=", "amf3decUI29", "(", "buf", ")", ";", "if", "(", "resp", ".", "value", ">", "0x0FFFFFFF", ")", "resp", ".", "value", "=", "(", "resp", ".", "value", "&", "0x0FFFFFFF", ")", "-", "0x10000000", ";", "return", "resp", ";", "}" ]
AMF3 Decode an integer @param buf @returns {{len: number, value: number}}
[ "AMF3", "Decode", "an", "integer" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L233-L237
train
delian/node-amfutils
amfUtils.js
amf3encInteger
function amf3encInteger(num) { var buf = new Buffer(1); buf.writeUInt8(0x4, 0); return Buffer.concat([buf, amf3encUI29(num & 0x3FFFFFFF)]); // This AND will auto convert the sign bit! }
javascript
function amf3encInteger(num) { var buf = new Buffer(1); buf.writeUInt8(0x4, 0); return Buffer.concat([buf, amf3encUI29(num & 0x3FFFFFFF)]); // This AND will auto convert the sign bit! }
[ "function", "amf3encInteger", "(", "num", ")", "{", "var", "buf", "=", "new", "Buffer", "(", "1", ")", ";", "buf", ".", "writeUInt8", "(", "0x4", ",", "0", ")", ";", "return", "Buffer", ".", "concat", "(", "[", "buf", ",", "amf3encUI29", "(", "num", "&", "0x3FFFFFFF", ")", "]", ")", ";", "}" ]
AMF3 Encode an integer @param num @returns {Buffer}
[ "AMF3", "Encode", "an", "integer" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L244-L248
train
delian/node-amfutils
amfUtils.js
amf3decXmlDoc
function amf3decXmlDoc(buf) { var sLen = amf3decUI29(buf); var s = sLen & 1; sLen = sLen >> 1; // The real length without the lowest bit if (s) return { len: sLen.value + 5, value: buf.slice(5, sLen.value + 5).toString('utf8') }; throw new Error("Error, we have a need to decode a String that is a Reference"); // TODO: Implement references! }
javascript
function amf3decXmlDoc(buf) { var sLen = amf3decUI29(buf); var s = sLen & 1; sLen = sLen >> 1; // The real length without the lowest bit if (s) return { len: sLen.value + 5, value: buf.slice(5, sLen.value + 5).toString('utf8') }; throw new Error("Error, we have a need to decode a String that is a Reference"); // TODO: Implement references! }
[ "function", "amf3decXmlDoc", "(", "buf", ")", "{", "var", "sLen", "=", "amf3decUI29", "(", "buf", ")", ";", "var", "s", "=", "sLen", "&", "1", ";", "sLen", "=", "sLen", ">>", "1", ";", "if", "(", "s", ")", "return", "{", "len", ":", "sLen", ".", "value", "+", "5", ",", "value", ":", "buf", ".", "slice", "(", "5", ",", "sLen", ".", "value", "+", "5", ")", ".", "toString", "(", "'utf8'", ")", "}", ";", "throw", "new", "Error", "(", "\"Error, we have a need to decode a String that is a Reference\"", ")", ";", "}" ]
AMF3 Decode XMLDoc @param buf @returns {{len: *, value: (*|String)}}
[ "AMF3", "Decode", "XMLDoc" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L280-L286
train
delian/node-amfutils
amfUtils.js
amf3encXmlDoc
function amf3encXmlDoc(str) { var sLen = amf3encUI29(str.length << 1); var buf = new Buffer(1); buf.writeUInt8(0x7, 0); return Buffer.concat([buf, sLen, new Buffer(str, 'utf8')]); }
javascript
function amf3encXmlDoc(str) { var sLen = amf3encUI29(str.length << 1); var buf = new Buffer(1); buf.writeUInt8(0x7, 0); return Buffer.concat([buf, sLen, new Buffer(str, 'utf8')]); }
[ "function", "amf3encXmlDoc", "(", "str", ")", "{", "var", "sLen", "=", "amf3encUI29", "(", "str", ".", "length", "<<", "1", ")", ";", "var", "buf", "=", "new", "Buffer", "(", "1", ")", ";", "buf", ".", "writeUInt8", "(", "0x7", ",", "0", ")", ";", "return", "Buffer", ".", "concat", "(", "[", "buf", ",", "sLen", ",", "new", "Buffer", "(", "str", ",", "'utf8'", ")", "]", ")", ";", "}" ]
AMF3 Encode XMLDoc @param str @returns {Buffer}
[ "AMF3", "Encode", "XMLDoc" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L293-L298
train
delian/node-amfutils
amfUtils.js
amf3decByteArray
function amf3decByteArray(buf) { var sLen = amf3decUI29(buf); var s = sLen & 1; // TODO: Check if we follow the same rule! sLen = sLen >> 1; // The real length without the lowest bit if (s) return { len: sLen.value + 5, value: buf.slice(5, sLen.value + 5) }; throw new Error("Error, we have a need to decode a String that is a Reference"); // TODO: Implement references! }
javascript
function amf3decByteArray(buf) { var sLen = amf3decUI29(buf); var s = sLen & 1; // TODO: Check if we follow the same rule! sLen = sLen >> 1; // The real length without the lowest bit if (s) return { len: sLen.value + 5, value: buf.slice(5, sLen.value + 5) }; throw new Error("Error, we have a need to decode a String that is a Reference"); // TODO: Implement references! }
[ "function", "amf3decByteArray", "(", "buf", ")", "{", "var", "sLen", "=", "amf3decUI29", "(", "buf", ")", ";", "var", "s", "=", "sLen", "&", "1", ";", "sLen", "=", "sLen", ">>", "1", ";", "if", "(", "s", ")", "return", "{", "len", ":", "sLen", ".", "value", "+", "5", ",", "value", ":", "buf", ".", "slice", "(", "5", ",", "sLen", ".", "value", "+", "5", ")", "}", ";", "throw", "new", "Error", "(", "\"Error, we have a need to decode a String that is a Reference\"", ")", ";", "}" ]
AMF3 Decide Byte Array @param buf @returns {{len: *, value: (Array|string|*|Buffer|Blob)}}
[ "AMF3", "Decide", "Byte", "Array" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L330-L336
train
delian/node-amfutils
amfUtils.js
amf3encDouble
function amf3encDouble(num) { var buf = new Buffer(9); buf.writeUInt8(0x05, 0); buf.writeDoubleBE(num, 1); return buf; }
javascript
function amf3encDouble(num) { var buf = new Buffer(9); buf.writeUInt8(0x05, 0); buf.writeDoubleBE(num, 1); return buf; }
[ "function", "amf3encDouble", "(", "num", ")", "{", "var", "buf", "=", "new", "Buffer", "(", "9", ")", ";", "buf", ".", "writeUInt8", "(", "0x05", ",", "0", ")", ";", "buf", ".", "writeDoubleBE", "(", "num", ",", "1", ")", ";", "return", "buf", ";", "}" ]
AMF3 Encode Double @param num @returns {Buffer}
[ "AMF3", "Encode", "Double" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L364-L369
train
delian/node-amfutils
amfUtils.js
amf3decDate
function amf3decDate(buf) { // The UI29 should be 1 var uTz = amf3decUI29(buf); var ts = buf.readDoubleBE(uTz.len); return { len: uTz.len + 8, value: ts } }
javascript
function amf3decDate(buf) { // The UI29 should be 1 var uTz = amf3decUI29(buf); var ts = buf.readDoubleBE(uTz.len); return { len: uTz.len + 8, value: ts } }
[ "function", "amf3decDate", "(", "buf", ")", "{", "var", "uTz", "=", "amf3decUI29", "(", "buf", ")", ";", "var", "ts", "=", "buf", ".", "readDoubleBE", "(", "uTz", ".", "len", ")", ";", "return", "{", "len", ":", "uTz", ".", "len", "+", "8", ",", "value", ":", "ts", "}", "}" ]
AMF3 Decode Date @param buf @returns {{len: *, value: (*|Number)}}
[ "AMF3", "Decode", "Date" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L376-L380
train
delian/node-amfutils
amfUtils.js
amf3encDate
function amf3encDate(ts) { var buf = new Buffer(1); buf.writeUInt8(0x8, 0); var tsBuf = new Buffer(8); tsBuf.writeDoubleBE(ts, 0); return Buffer.concat([buf, amf3encUI29(1), tsBuf]); // We always do 1 }
javascript
function amf3encDate(ts) { var buf = new Buffer(1); buf.writeUInt8(0x8, 0); var tsBuf = new Buffer(8); tsBuf.writeDoubleBE(ts, 0); return Buffer.concat([buf, amf3encUI29(1), tsBuf]); // We always do 1 }
[ "function", "amf3encDate", "(", "ts", ")", "{", "var", "buf", "=", "new", "Buffer", "(", "1", ")", ";", "buf", ".", "writeUInt8", "(", "0x8", ",", "0", ")", ";", "var", "tsBuf", "=", "new", "Buffer", "(", "8", ")", ";", "tsBuf", ".", "writeDoubleBE", "(", "ts", ",", "0", ")", ";", "return", "Buffer", ".", "concat", "(", "[", "buf", ",", "amf3encUI29", "(", "1", ")", ",", "tsBuf", "]", ")", ";", "}" ]
AMF3 Encode Date @param ts @returns {Buffer}
[ "AMF3", "Encode", "Date" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L387-L393
train
delian/node-amfutils
amfUtils.js
amf3decArray
function amf3decArray(buf) { var count = amf3decUI29(buf.slice(1)); var obj = amf3decObject(buf.slice(count.len)); if (count.value % 2 == 1) throw new Error("This is a reference to another array, which currently we don't support!"); return { len: count.len + obj.len, value: obj.value } }
javascript
function amf3decArray(buf) { var count = amf3decUI29(buf.slice(1)); var obj = amf3decObject(buf.slice(count.len)); if (count.value % 2 == 1) throw new Error("This is a reference to another array, which currently we don't support!"); return { len: count.len + obj.len, value: obj.value } }
[ "function", "amf3decArray", "(", "buf", ")", "{", "var", "count", "=", "amf3decUI29", "(", "buf", ".", "slice", "(", "1", ")", ")", ";", "var", "obj", "=", "amf3decObject", "(", "buf", ".", "slice", "(", "count", ".", "len", ")", ")", ";", "if", "(", "count", ".", "value", "%", "2", "==", "1", ")", "throw", "new", "Error", "(", "\"This is a reference to another array, which currently we don't support!\"", ")", ";", "return", "{", "len", ":", "count", ".", "len", "+", "obj", ".", "len", ",", "value", ":", "obj", ".", "value", "}", "}" ]
AMF3 Decode Array @param buf @returns {{len: *, value: *}}
[ "AMF3", "Decode", "Array" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L400-L405
train
delian/node-amfutils
amfUtils.js
amf0encNumber
function amf0encNumber(num) { var buf = new Buffer(9); buf.writeUInt8(0x00, 0); buf.writeDoubleBE(num, 1); return buf; }
javascript
function amf0encNumber(num) { var buf = new Buffer(9); buf.writeUInt8(0x00, 0); buf.writeDoubleBE(num, 1); return buf; }
[ "function", "amf0encNumber", "(", "num", ")", "{", "var", "buf", "=", "new", "Buffer", "(", "9", ")", ";", "buf", ".", "writeUInt8", "(", "0x00", ",", "0", ")", ";", "buf", ".", "writeDoubleBE", "(", "num", ",", "1", ")", ";", "return", "buf", ";", "}" ]
AMF0 Encode Number @param num @returns {Buffer}
[ "AMF0", "Encode", "Number" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L446-L451
train
delian/node-amfutils
amfUtils.js
amf0encBool
function amf0encBool(num) { var buf = new Buffer(2); buf.writeUInt8(0x01, 0); buf.writeUInt8((num ? 1 : 0), 1); return buf; }
javascript
function amf0encBool(num) { var buf = new Buffer(2); buf.writeUInt8(0x01, 0); buf.writeUInt8((num ? 1 : 0), 1); return buf; }
[ "function", "amf0encBool", "(", "num", ")", "{", "var", "buf", "=", "new", "Buffer", "(", "2", ")", ";", "buf", ".", "writeUInt8", "(", "0x01", ",", "0", ")", ";", "buf", ".", "writeUInt8", "(", "(", "num", "?", "1", ":", "0", ")", ",", "1", ")", ";", "return", "buf", ";", "}" ]
AMF0 Encode Boolean @param num @returns {Buffer}
[ "AMF0", "Encode", "Boolean" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L467-L472
train
delian/node-amfutils
amfUtils.js
amf0encDate
function amf0encDate(ts) { var buf = new Buffer(11); buf.writeUInt8(0x0B, 0); buf.writeInt16BE(0, 1); buf.writeDoubleBE(ts, 3); return buf; }
javascript
function amf0encDate(ts) { var buf = new Buffer(11); buf.writeUInt8(0x0B, 0); buf.writeInt16BE(0, 1); buf.writeDoubleBE(ts, 3); return buf; }
[ "function", "amf0encDate", "(", "ts", ")", "{", "var", "buf", "=", "new", "Buffer", "(", "11", ")", ";", "buf", ".", "writeUInt8", "(", "0x0B", ",", "0", ")", ";", "buf", ".", "writeInt16BE", "(", "0", ",", "1", ")", ";", "buf", ".", "writeDoubleBE", "(", "ts", ",", "3", ")", ";", "return", "buf", ";", "}" ]
AMF0 Encode Date @param ts @returns {Buffer}
[ "AMF0", "Encode", "Date" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L526-L532
train
delian/node-amfutils
amfUtils.js
amf0decObject
function amf0decObject(buf) { // TODO: Implement references! var obj = {}; var iBuf = buf.slice(1); var len = 1; // console.log('ODec',iBuf.readUInt8(0)); while (iBuf.readUInt8(0) != 0x09) { // console.log('Field', iBuf.readUInt8(0), iBuf); var prop = amf0decUString(iBuf); // console.log('Got field for property', prop); len += prop.len; if (iBuf.slice(prop.len).readUInt8(0) == 0x09) { len++; // console.log('Found the end property'); break; } // END Object as value, we shall leave if (prop.value == '') break; var val = amf0DecodeOne(iBuf.slice(prop.len)); // console.log('Got field for value', val); obj[prop.value] = val.value; len += val.len; iBuf = iBuf.slice(prop.len + val.len); } return { len: len, value: obj } }
javascript
function amf0decObject(buf) { // TODO: Implement references! var obj = {}; var iBuf = buf.slice(1); var len = 1; // console.log('ODec',iBuf.readUInt8(0)); while (iBuf.readUInt8(0) != 0x09) { // console.log('Field', iBuf.readUInt8(0), iBuf); var prop = amf0decUString(iBuf); // console.log('Got field for property', prop); len += prop.len; if (iBuf.slice(prop.len).readUInt8(0) == 0x09) { len++; // console.log('Found the end property'); break; } // END Object as value, we shall leave if (prop.value == '') break; var val = amf0DecodeOne(iBuf.slice(prop.len)); // console.log('Got field for value', val); obj[prop.value] = val.value; len += val.len; iBuf = iBuf.slice(prop.len + val.len); } return { len: len, value: obj } }
[ "function", "amf0decObject", "(", "buf", ")", "{", "var", "obj", "=", "{", "}", ";", "var", "iBuf", "=", "buf", ".", "slice", "(", "1", ")", ";", "var", "len", "=", "1", ";", "while", "(", "iBuf", ".", "readUInt8", "(", "0", ")", "!=", "0x09", ")", "{", "var", "prop", "=", "amf0decUString", "(", "iBuf", ")", ";", "len", "+=", "prop", ".", "len", ";", "if", "(", "iBuf", ".", "slice", "(", "prop", ".", "len", ")", ".", "readUInt8", "(", "0", ")", "==", "0x09", ")", "{", "len", "++", ";", "break", ";", "}", "if", "(", "prop", ".", "value", "==", "''", ")", "break", ";", "var", "val", "=", "amf0DecodeOne", "(", "iBuf", ".", "slice", "(", "prop", ".", "len", ")", ")", ";", "obj", "[", "prop", ".", "value", "]", "=", "val", ".", "value", ";", "len", "+=", "val", ".", "len", ";", "iBuf", "=", "iBuf", ".", "slice", "(", "prop", ".", "len", "+", "val", ".", "len", ")", ";", "}", "return", "{", "len", ":", "len", ",", "value", ":", "obj", "}", "}" ]
AMF0 Decode Object @param buf @returns {{len: number, value: {}}}
[ "AMF0", "Decode", "Object" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L539-L562
train
delian/node-amfutils
amfUtils.js
amf0encObject
function amf0encObject(o) { if (typeof o !== 'object') return; var data = new Buffer(1); data.writeUInt8(0x03,0); // Type object var k; for (k in o) { data = Buffer.concat([data,amf0encUString(k),amf0EncodeOne(o[k])]); } var termCode = new Buffer(1); termCode.writeUInt8(0x09,0); return Buffer.concat([data,amf0encUString(''),termCode]); }
javascript
function amf0encObject(o) { if (typeof o !== 'object') return; var data = new Buffer(1); data.writeUInt8(0x03,0); // Type object var k; for (k in o) { data = Buffer.concat([data,amf0encUString(k),amf0EncodeOne(o[k])]); } var termCode = new Buffer(1); termCode.writeUInt8(0x09,0); return Buffer.concat([data,amf0encUString(''),termCode]); }
[ "function", "amf0encObject", "(", "o", ")", "{", "if", "(", "typeof", "o", "!==", "'object'", ")", "return", ";", "var", "data", "=", "new", "Buffer", "(", "1", ")", ";", "data", ".", "writeUInt8", "(", "0x03", ",", "0", ")", ";", "var", "k", ";", "for", "(", "k", "in", "o", ")", "{", "data", "=", "Buffer", ".", "concat", "(", "[", "data", ",", "amf0encUString", "(", "k", ")", ",", "amf0EncodeOne", "(", "o", "[", "k", "]", ")", "]", ")", ";", "}", "var", "termCode", "=", "new", "Buffer", "(", "1", ")", ";", "termCode", ".", "writeUInt8", "(", "0x09", ",", "0", ")", ";", "return", "Buffer", ".", "concat", "(", "[", "data", ",", "amf0encUString", "(", "''", ")", ",", "termCode", "]", ")", ";", "}" ]
AMF0 Encode Object
[ "AMF0", "Encode", "Object" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L567-L579
train
delian/node-amfutils
amfUtils.js
amf0encRef
function amf0encRef(index) { var buf = new Buffer(3); buf.writeUInt8(0x07, 0); buf.writeUInt16BE(index, 1); return buf; }
javascript
function amf0encRef(index) { var buf = new Buffer(3); buf.writeUInt8(0x07, 0); buf.writeUInt16BE(index, 1); return buf; }
[ "function", "amf0encRef", "(", "index", ")", "{", "var", "buf", "=", "new", "Buffer", "(", "3", ")", ";", "buf", ".", "writeUInt8", "(", "0x07", ",", "0", ")", ";", "buf", ".", "writeUInt16BE", "(", "index", ",", "1", ")", ";", "return", "buf", ";", "}" ]
AMF0 Encode Reference @param index @returns {Buffer}
[ "AMF0", "Encode", "Reference" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L596-L601
train
delian/node-amfutils
amfUtils.js
amf0decString
function amf0decString(buf) { var sLen = buf.readUInt16BE(1); return { len: 3 + sLen, value: buf.toString('utf8', 3, 3 + sLen) } }
javascript
function amf0decString(buf) { var sLen = buf.readUInt16BE(1); return { len: 3 + sLen, value: buf.toString('utf8', 3, 3 + sLen) } }
[ "function", "amf0decString", "(", "buf", ")", "{", "var", "sLen", "=", "buf", ".", "readUInt16BE", "(", "1", ")", ";", "return", "{", "len", ":", "3", "+", "sLen", ",", "value", ":", "buf", ".", "toString", "(", "'utf8'", ",", "3", ",", "3", "+", "sLen", ")", "}", "}" ]
AMF0 Decode String @param buf @returns {{len: *, value: (*|string|String)}}
[ "AMF0", "Decode", "String" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L608-L611
train
delian/node-amfutils
amfUtils.js
amf0encUString
function amf0encUString(s) { var data = new Buffer(s,'utf8'); var sLen = new Buffer(2); sLen.writeUInt16BE(data.length,0); return Buffer.concat([sLen,data]); }
javascript
function amf0encUString(s) { var data = new Buffer(s,'utf8'); var sLen = new Buffer(2); sLen.writeUInt16BE(data.length,0); return Buffer.concat([sLen,data]); }
[ "function", "amf0encUString", "(", "s", ")", "{", "var", "data", "=", "new", "Buffer", "(", "s", ",", "'utf8'", ")", ";", "var", "sLen", "=", "new", "Buffer", "(", "2", ")", ";", "sLen", ".", "writeUInt16BE", "(", "data", ".", "length", ",", "0", ")", ";", "return", "Buffer", ".", "concat", "(", "[", "sLen", ",", "data", "]", ")", ";", "}" ]
Do AMD0 Encode of Untyped String @param s @returns {Buffer}
[ "Do", "AMD0", "Encode", "of", "Untyped", "String" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L628-L633
train
delian/node-amfutils
amfUtils.js
amf0encString
function amf0encString(str) { var buf = new Buffer(3); buf.writeUInt8(0x02, 0); buf.writeUInt16BE(str.length, 1); return Buffer.concat([buf, new Buffer(str, 'utf8')]); }
javascript
function amf0encString(str) { var buf = new Buffer(3); buf.writeUInt8(0x02, 0); buf.writeUInt16BE(str.length, 1); return Buffer.concat([buf, new Buffer(str, 'utf8')]); }
[ "function", "amf0encString", "(", "str", ")", "{", "var", "buf", "=", "new", "Buffer", "(", "3", ")", ";", "buf", ".", "writeUInt8", "(", "0x02", ",", "0", ")", ";", "buf", ".", "writeUInt16BE", "(", "str", ".", "length", ",", "1", ")", ";", "return", "Buffer", ".", "concat", "(", "[", "buf", ",", "new", "Buffer", "(", "str", ",", "'utf8'", ")", "]", ")", ";", "}" ]
AMF0 Encode String @param str @returns {Buffer}
[ "AMF0", "Encode", "String" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L640-L645
train
delian/node-amfutils
amfUtils.js
amf0decLongString
function amf0decLongString(buf) { var sLen = buf.readUInt32BE(1); return { len: 5 + sLen, value: buf.toString('utf8', 5, 5 + sLen) } }
javascript
function amf0decLongString(buf) { var sLen = buf.readUInt32BE(1); return { len: 5 + sLen, value: buf.toString('utf8', 5, 5 + sLen) } }
[ "function", "amf0decLongString", "(", "buf", ")", "{", "var", "sLen", "=", "buf", ".", "readUInt32BE", "(", "1", ")", ";", "return", "{", "len", ":", "5", "+", "sLen", ",", "value", ":", "buf", ".", "toString", "(", "'utf8'", ",", "5", ",", "5", "+", "sLen", ")", "}", "}" ]
AMF0 Decode Long String @param buf @returns {{len: *, value: (*|string|String)}}
[ "AMF0", "Decode", "Long", "String" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L652-L655
train
delian/node-amfutils
amfUtils.js
amf0encLongString
function amf0encLongString(str) { var buf = new Buffer(5); buf.writeUInt8(0x0C, 0); buf.writeUInt32BE(str.length, 1); return Buffer.concat([buf, new Buffer(str, 'utf8')]); }
javascript
function amf0encLongString(str) { var buf = new Buffer(5); buf.writeUInt8(0x0C, 0); buf.writeUInt32BE(str.length, 1); return Buffer.concat([buf, new Buffer(str, 'utf8')]); }
[ "function", "amf0encLongString", "(", "str", ")", "{", "var", "buf", "=", "new", "Buffer", "(", "5", ")", ";", "buf", ".", "writeUInt8", "(", "0x0C", ",", "0", ")", ";", "buf", ".", "writeUInt32BE", "(", "str", ".", "length", ",", "1", ")", ";", "return", "Buffer", ".", "concat", "(", "[", "buf", ",", "new", "Buffer", "(", "str", ",", "'utf8'", ")", "]", ")", ";", "}" ]
AMF0 Encode Long String @param str @returns {Buffer}
[ "AMF0", "Encode", "Long", "String" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L662-L667
train
delian/node-amfutils
amfUtils.js
amf0decArray
function amf0decArray(buf) { // var count = buf.readUInt32BE(1); var obj = amf0decObject(buf.slice(4)); return { len: 5 + obj.len, value: obj.value } }
javascript
function amf0decArray(buf) { // var count = buf.readUInt32BE(1); var obj = amf0decObject(buf.slice(4)); return { len: 5 + obj.len, value: obj.value } }
[ "function", "amf0decArray", "(", "buf", ")", "{", "var", "obj", "=", "amf0decObject", "(", "buf", ".", "slice", "(", "4", ")", ")", ";", "return", "{", "len", ":", "5", "+", "obj", ".", "len", ",", "value", ":", "obj", ".", "value", "}", "}" ]
AMF0 Decode Array @param buf @returns {{len: *, value: ({}|*)}}
[ "AMF0", "Decode", "Array" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L674-L678
train
delian/node-amfutils
amfUtils.js
amf0encArray
function amf0encArray(a) { var l = 0; if (a instanceof Array) l = a.length; else l = Object.keys(a).length; console.log('Array encode', l, a); var buf = new Buffer(5); buf.writeUInt8(8,0); buf.writeUInt32BE(l,1); var data = amf0encObject(a); return Buffer.concat([buf,data.slice(1)]); }
javascript
function amf0encArray(a) { var l = 0; if (a instanceof Array) l = a.length; else l = Object.keys(a).length; console.log('Array encode', l, a); var buf = new Buffer(5); buf.writeUInt8(8,0); buf.writeUInt32BE(l,1); var data = amf0encObject(a); return Buffer.concat([buf,data.slice(1)]); }
[ "function", "amf0encArray", "(", "a", ")", "{", "var", "l", "=", "0", ";", "if", "(", "a", "instanceof", "Array", ")", "l", "=", "a", ".", "length", ";", "else", "l", "=", "Object", ".", "keys", "(", "a", ")", ".", "length", ";", "console", ".", "log", "(", "'Array encode'", ",", "l", ",", "a", ")", ";", "var", "buf", "=", "new", "Buffer", "(", "5", ")", ";", "buf", ".", "writeUInt8", "(", "8", ",", "0", ")", ";", "buf", ".", "writeUInt32BE", "(", "l", ",", "1", ")", ";", "var", "data", "=", "amf0encObject", "(", "a", ")", ";", "return", "Buffer", ".", "concat", "(", "[", "buf", ",", "data", ".", "slice", "(", "1", ")", "]", ")", ";", "}" ]
AMF0 Encode Array
[ "AMF0", "Encode", "Array" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L683-L692
train
delian/node-amfutils
amfUtils.js
amf0cnvArray2Object
function amf0cnvArray2Object(aData) { var buf = new Buffer(1); buf.writeUInt8(0x3,0); // Object id return Buffer.concat([buf,aData.slice(5)]); }
javascript
function amf0cnvArray2Object(aData) { var buf = new Buffer(1); buf.writeUInt8(0x3,0); // Object id return Buffer.concat([buf,aData.slice(5)]); }
[ "function", "amf0cnvArray2Object", "(", "aData", ")", "{", "var", "buf", "=", "new", "Buffer", "(", "1", ")", ";", "buf", ".", "writeUInt8", "(", "0x3", ",", "0", ")", ";", "return", "Buffer", ".", "concat", "(", "[", "buf", ",", "aData", ".", "slice", "(", "5", ")", "]", ")", ";", "}" ]
AMF0 Encode Binary Array into binary Object @param aData @returns {Buffer}
[ "AMF0", "Encode", "Binary", "Array", "into", "binary", "Object" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L699-L703
train
delian/node-amfutils
amfUtils.js
amf0cnvObject2Array
function amf0cnvObject2Array(oData) { var buf = new Buffer(5); var o = amf0decObject(oData); var l = Object.keys(o).length; buf.writeUInt32BE(l,1); return Buffer.concat([buf,oData.slice(1)]); }
javascript
function amf0cnvObject2Array(oData) { var buf = new Buffer(5); var o = amf0decObject(oData); var l = Object.keys(o).length; buf.writeUInt32BE(l,1); return Buffer.concat([buf,oData.slice(1)]); }
[ "function", "amf0cnvObject2Array", "(", "oData", ")", "{", "var", "buf", "=", "new", "Buffer", "(", "5", ")", ";", "var", "o", "=", "amf0decObject", "(", "oData", ")", ";", "var", "l", "=", "Object", ".", "keys", "(", "o", ")", ".", "length", ";", "buf", ".", "writeUInt32BE", "(", "l", ",", "1", ")", ";", "return", "Buffer", ".", "concat", "(", "[", "buf", ",", "oData", ".", "slice", "(", "1", ")", "]", ")", ";", "}" ]
AMF0 Encode Binary Object into binary Array @param oData @returns {Buffer}
[ "AMF0", "Encode", "Binary", "Object", "into", "binary", "Array" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L710-L716
train
delian/node-amfutils
amfUtils.js
amf0decXmlDoc
function amf0decXmlDoc(buf) { var sLen = buf.readUInt16BE(1); return { len: 3 + sLen, value: buf.toString('utf8', 3, 3 + sLen) } }
javascript
function amf0decXmlDoc(buf) { var sLen = buf.readUInt16BE(1); return { len: 3 + sLen, value: buf.toString('utf8', 3, 3 + sLen) } }
[ "function", "amf0decXmlDoc", "(", "buf", ")", "{", "var", "sLen", "=", "buf", ".", "readUInt16BE", "(", "1", ")", ";", "return", "{", "len", ":", "3", "+", "sLen", ",", "value", ":", "buf", ".", "toString", "(", "'utf8'", ",", "3", ",", "3", "+", "sLen", ")", "}", "}" ]
AMF0 Decode XMLDoc @param buf @returns {{len: *, value: (*|string|String)}}
[ "AMF0", "Decode", "XMLDoc" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L723-L726
train
delian/node-amfutils
amfUtils.js
amf0encXmlDoc
function amf0encXmlDoc(str) { // Essentially it is the same as string var buf = new Buffer(3); buf.writeUInt8(0x0F, 0); buf.writeUInt16BE(str.length, 1); return Buffer.concat([buf, new Buffer(str, 'utf8')]); }
javascript
function amf0encXmlDoc(str) { // Essentially it is the same as string var buf = new Buffer(3); buf.writeUInt8(0x0F, 0); buf.writeUInt16BE(str.length, 1); return Buffer.concat([buf, new Buffer(str, 'utf8')]); }
[ "function", "amf0encXmlDoc", "(", "str", ")", "{", "var", "buf", "=", "new", "Buffer", "(", "3", ")", ";", "buf", ".", "writeUInt8", "(", "0x0F", ",", "0", ")", ";", "buf", ".", "writeUInt16BE", "(", "str", ".", "length", ",", "1", ")", ";", "return", "Buffer", ".", "concat", "(", "[", "buf", ",", "new", "Buffer", "(", "str", ",", "'utf8'", ")", "]", ")", ";", "}" ]
AMF0 Encode XMLDoc @param str @returns {Buffer}
[ "AMF0", "Encode", "XMLDoc" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L733-L738
train
delian/node-amfutils
amfUtils.js
amf0decSArray
function amf0decSArray(buf) { var a = []; var len = 5; var ret; for (var count = buf.readUInt32BE(1); count; count--) { ret = amf0DecodeOne(buf.slice(len)); a.push(ret.value); len += ret.len; } return { len: len, value: amf0markSArray(a) } }
javascript
function amf0decSArray(buf) { var a = []; var len = 5; var ret; for (var count = buf.readUInt32BE(1); count; count--) { ret = amf0DecodeOne(buf.slice(len)); a.push(ret.value); len += ret.len; } return { len: len, value: amf0markSArray(a) } }
[ "function", "amf0decSArray", "(", "buf", ")", "{", "var", "a", "=", "[", "]", ";", "var", "len", "=", "5", ";", "var", "ret", ";", "for", "(", "var", "count", "=", "buf", ".", "readUInt32BE", "(", "1", ")", ";", "count", ";", "count", "--", ")", "{", "ret", "=", "amf0DecodeOne", "(", "buf", ".", "slice", "(", "len", ")", ")", ";", "a", ".", "push", "(", "ret", ".", "value", ")", ";", "len", "+=", "ret", ".", "len", ";", "}", "return", "{", "len", ":", "len", ",", "value", ":", "amf0markSArray", "(", "a", ")", "}", "}" ]
AMF0 Decode Strict Array @param buf @returns {{len: number, value: Array}}
[ "AMF0", "Decode", "Strict", "Array" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L745-L755
train
delian/node-amfutils
amfUtils.js
amf0encSArray
function amf0encSArray(a) { console.log('Do strict array!'); var buf = new Buffer(5); buf.writeUInt8(0x0A,0); buf.writeUInt32BE(a.length,1); var i; for (i=0;i< a.length;i++) { buf = Buffer.concat([buf,amf0EncodeOne(a[i])]); } return buf; }
javascript
function amf0encSArray(a) { console.log('Do strict array!'); var buf = new Buffer(5); buf.writeUInt8(0x0A,0); buf.writeUInt32BE(a.length,1); var i; for (i=0;i< a.length;i++) { buf = Buffer.concat([buf,amf0EncodeOne(a[i])]); } return buf; }
[ "function", "amf0encSArray", "(", "a", ")", "{", "console", ".", "log", "(", "'Do strict array!'", ")", ";", "var", "buf", "=", "new", "Buffer", "(", "5", ")", ";", "buf", ".", "writeUInt8", "(", "0x0A", ",", "0", ")", ";", "buf", ".", "writeUInt32BE", "(", "a", ".", "length", ",", "1", ")", ";", "var", "i", ";", "for", "(", "i", "=", "0", ";", "i", "<", "a", ".", "length", ";", "i", "++", ")", "{", "buf", "=", "Buffer", ".", "concat", "(", "[", "buf", ",", "amf0EncodeOne", "(", "a", "[", "i", "]", ")", "]", ")", ";", "}", "return", "buf", ";", "}" ]
AMF0 Encode Strict Array @param a Array
[ "AMF0", "Encode", "Strict", "Array" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L761-L771
train
delian/node-amfutils
amfUtils.js
amf0decTypedObj
function amf0decTypedObj(buf) { var className = amf0decString(buf); var obj = amf0decObject(buf.slice(className.len - 1)); obj.value.__className__ = className.value; return { len: className.len + obj.len - 1, value: obj.value } }
javascript
function amf0decTypedObj(buf) { var className = amf0decString(buf); var obj = amf0decObject(buf.slice(className.len - 1)); obj.value.__className__ = className.value; return { len: className.len + obj.len - 1, value: obj.value } }
[ "function", "amf0decTypedObj", "(", "buf", ")", "{", "var", "className", "=", "amf0decString", "(", "buf", ")", ";", "var", "obj", "=", "amf0decObject", "(", "buf", ".", "slice", "(", "className", ".", "len", "-", "1", ")", ")", ";", "obj", ".", "value", ".", "__className__", "=", "className", ".", "value", ";", "return", "{", "len", ":", "className", ".", "len", "+", "obj", ".", "len", "-", "1", ",", "value", ":", "obj", ".", "value", "}", "}" ]
AMF0 Decode Typed Object @param buf @returns {{len: number, value: ({}|*)}}
[ "AMF0", "Decode", "Typed", "Object" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L783-L788
train
delian/node-amfutils
amfUtils.js
amfXDecodeOne
function amfXDecodeOne(rules, buffer) { if (!rules[buffer.readUInt8(0)]) { console.log('Unknown field', buffer.readUInt8(0)); throw new Error("Error: Unknown field"); } return rules[buffer.readUInt8(0)](buffer); }
javascript
function amfXDecodeOne(rules, buffer) { if (!rules[buffer.readUInt8(0)]) { console.log('Unknown field', buffer.readUInt8(0)); throw new Error("Error: Unknown field"); } return rules[buffer.readUInt8(0)](buffer); }
[ "function", "amfXDecodeOne", "(", "rules", ",", "buffer", ")", "{", "if", "(", "!", "rules", "[", "buffer", ".", "readUInt8", "(", "0", ")", "]", ")", "{", "console", ".", "log", "(", "'Unknown field'", ",", "buffer", ".", "readUInt8", "(", "0", ")", ")", ";", "throw", "new", "Error", "(", "\"Error: Unknown field\"", ")", ";", "}", "return", "rules", "[", "buffer", ".", "readUInt8", "(", "0", ")", "]", "(", "buffer", ")", ";", "}" ]
Decode one value from the Buffer according to the applied rules @param rules @param buffer @returns {*}
[ "Decode", "one", "value", "from", "the", "Buffer", "according", "to", "the", "applied", "rules" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L803-L809
train
delian/node-amfutils
amfUtils.js
amfXDecode
function amfXDecode(rules, buffer) { // We shall receive clean buffer and will respond with an array of values var resp = []; var res; for (var i = 0; i < buffer.length;) { res = amfXDecodeOne(rules, buffer.slice(i)); i += res.len; resp.push(res.value); // Add the response } return resp; }
javascript
function amfXDecode(rules, buffer) { // We shall receive clean buffer and will respond with an array of values var resp = []; var res; for (var i = 0; i < buffer.length;) { res = amfXDecodeOne(rules, buffer.slice(i)); i += res.len; resp.push(res.value); // Add the response } return resp; }
[ "function", "amfXDecode", "(", "rules", ",", "buffer", ")", "{", "var", "resp", "=", "[", "]", ";", "var", "res", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "buffer", ".", "length", ";", ")", "{", "res", "=", "amfXDecodeOne", "(", "rules", ",", "buffer", ".", "slice", "(", "i", ")", ")", ";", "i", "+=", "res", ".", "len", ";", "resp", ".", "push", "(", "res", ".", "value", ")", ";", "}", "return", "resp", ";", "}" ]
Decode a whole buffer of AMF values according to rules and return in array @param rules @param buffer @returns {Array}
[ "Decode", "a", "whole", "buffer", "of", "AMF", "values", "according", "to", "rules", "and", "return", "in", "array" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L835-L845
train
delian/node-amfutils
amfUtils.js
amfXEncodeOne
function amfXEncodeOne(rules, o) { // console.log('amfXEncodeOne type',o,amfType(o),rules[amfType(o)]); var f = rules[amfType(o)]; if (f) return f(o); throw new Error('Unsupported type for encoding!'); }
javascript
function amfXEncodeOne(rules, o) { // console.log('amfXEncodeOne type',o,amfType(o),rules[amfType(o)]); var f = rules[amfType(o)]; if (f) return f(o); throw new Error('Unsupported type for encoding!'); }
[ "function", "amfXEncodeOne", "(", "rules", ",", "o", ")", "{", "var", "f", "=", "rules", "[", "amfType", "(", "o", ")", "]", ";", "if", "(", "f", ")", "return", "f", "(", "o", ")", ";", "throw", "new", "Error", "(", "'Unsupported type for encoding!'", ")", ";", "}" ]
Encode one AMF value according to rules @param rules @param o @returns {*}
[ "Encode", "one", "AMF", "value", "according", "to", "rules" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L871-L876
train
delian/node-amfutils
amfUtils.js
decodeAMF0Cmd
function decodeAMF0Cmd(dbuf) { var buffer = dbuf; var resp = {}; var cmd = amf0DecodeOne(buffer); resp.cmd = cmd.value; buffer = buffer.slice(cmd.len); if (rtmpCmdDecode[cmd.value]) { rtmpCmdDecode[cmd.value].forEach(function (n) { if (buffer.length > 0) { var r = amf0DecodeOne(buffer); buffer = buffer.slice(r.len); resp[n] = r.value; } }); } else { console.log('Unknown command', resp); } return resp }
javascript
function decodeAMF0Cmd(dbuf) { var buffer = dbuf; var resp = {}; var cmd = amf0DecodeOne(buffer); resp.cmd = cmd.value; buffer = buffer.slice(cmd.len); if (rtmpCmdDecode[cmd.value]) { rtmpCmdDecode[cmd.value].forEach(function (n) { if (buffer.length > 0) { var r = amf0DecodeOne(buffer); buffer = buffer.slice(r.len); resp[n] = r.value; } }); } else { console.log('Unknown command', resp); } return resp }
[ "function", "decodeAMF0Cmd", "(", "dbuf", ")", "{", "var", "buffer", "=", "dbuf", ";", "var", "resp", "=", "{", "}", ";", "var", "cmd", "=", "amf0DecodeOne", "(", "buffer", ")", ";", "resp", ".", "cmd", "=", "cmd", ".", "value", ";", "buffer", "=", "buffer", ".", "slice", "(", "cmd", ".", "len", ")", ";", "if", "(", "rtmpCmdDecode", "[", "cmd", ".", "value", "]", ")", "{", "rtmpCmdDecode", "[", "cmd", ".", "value", "]", ".", "forEach", "(", "function", "(", "n", ")", "{", "if", "(", "buffer", ".", "length", ">", "0", ")", "{", "var", "r", "=", "amf0DecodeOne", "(", "buffer", ")", ";", "buffer", "=", "buffer", ".", "slice", "(", "r", ".", "len", ")", ";", "resp", "[", "n", "]", "=", "r", ".", "value", ";", "}", "}", ")", ";", "}", "else", "{", "console", ".", "log", "(", "'Unknown command'", ",", "resp", ")", ";", "}", "return", "resp", "}" ]
Decode a command! @param dbuf @returns {{cmd: (*|string|String|*), value: *}}
[ "Decode", "a", "command!" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L951-L971
train
delian/node-amfutils
amfUtils.js
encodeAMF3Cmd
function encodeAMF3Cmd(opt) { var data = amf0EncodeOne(opt.cmd); if (rtmpCmdDecode[opt.cmd]) { rtmpCmdDecode[opt.cmd].forEach(function (n) { if (opt.hasOwnProperty(n)) data = Buffer.concat([data, amf3EncodeOne(opt[n])]); }); } else { console.log('Unknown command', opt); } return data }
javascript
function encodeAMF3Cmd(opt) { var data = amf0EncodeOne(opt.cmd); if (rtmpCmdDecode[opt.cmd]) { rtmpCmdDecode[opt.cmd].forEach(function (n) { if (opt.hasOwnProperty(n)) data = Buffer.concat([data, amf3EncodeOne(opt[n])]); }); } else { console.log('Unknown command', opt); } return data }
[ "function", "encodeAMF3Cmd", "(", "opt", ")", "{", "var", "data", "=", "amf0EncodeOne", "(", "opt", ".", "cmd", ")", ";", "if", "(", "rtmpCmdDecode", "[", "opt", ".", "cmd", "]", ")", "{", "rtmpCmdDecode", "[", "opt", ".", "cmd", "]", ".", "forEach", "(", "function", "(", "n", ")", "{", "if", "(", "opt", ".", "hasOwnProperty", "(", "n", ")", ")", "data", "=", "Buffer", ".", "concat", "(", "[", "data", ",", "amf3EncodeOne", "(", "opt", "[", "n", "]", ")", "]", ")", ";", "}", ")", ";", "}", "else", "{", "console", ".", "log", "(", "'Unknown command'", ",", "opt", ")", ";", "}", "return", "data", "}" ]
Encode AMF3 Command @param opt @returns {*}
[ "Encode", "AMF3", "Command" ]
f9ef2d0df385f371c2f83a52200933f59eaebcce
https://github.com/delian/node-amfutils/blob/f9ef2d0df385f371c2f83a52200933f59eaebcce/amfUtils.js#L1025-L1037
train
ascartabelli/lamb
src/privates/_isArrayIndex.js
_isArrayIndex
function _isArrayIndex (target, key) { var n = +key; return Array.isArray(target) && n % 1 === 0 && !(n < 0 && _isEnumerable(target, key)); }
javascript
function _isArrayIndex (target, key) { var n = +key; return Array.isArray(target) && n % 1 === 0 && !(n < 0 && _isEnumerable(target, key)); }
[ "function", "_isArrayIndex", "(", "target", ",", "key", ")", "{", "var", "n", "=", "+", "key", ";", "return", "Array", ".", "isArray", "(", "target", ")", "&&", "n", "%", "1", "===", "0", "&&", "!", "(", "n", "<", "0", "&&", "_isEnumerable", "(", "target", ",", "key", ")", ")", ";", "}" ]
Accepts a target object and a key name and verifies that the target is an array and that the key is an existing index. @private @param {Object} target @param {String|Number} key @returns {Boolean}
[ "Accepts", "a", "target", "object", "and", "a", "key", "name", "and", "verifies", "that", "the", "target", "is", "an", "array", "and", "that", "the", "key", "is", "an", "existing", "index", "." ]
d36e45945c4789e4f1a2d8805936514b53f32362
https://github.com/ascartabelli/lamb/blob/d36e45945c4789e4f1a2d8805936514b53f32362/src/privates/_isArrayIndex.js#L11-L15
train
marionebl/eslint-plugin-flow-check
source/flow.js
flow
function flow(options) { const result = spawnSync(bin, [ 'check-contents', '--json', `--root=${options.root}`, options.fileName ], { input: options.source, encoding: 'utf-8' }); if (result.status !== 0) { return [{ message: result.stderr, loc: { start: { line: 1 }, end: { line: 1 } } }]; } const {errors} = JSON.parse(result.stdout); return errors.map(error => { const [leading, ...rest] = error.message; const payload = rest.map(m => format(m, { root: options.root })); return { message: [leading.descr, ...payload].join(': '), path: leading.path, start: leading.loc.start.line, end: leading.loc.end.line, loc: leading.loc }; }); }
javascript
function flow(options) { const result = spawnSync(bin, [ 'check-contents', '--json', `--root=${options.root}`, options.fileName ], { input: options.source, encoding: 'utf-8' }); if (result.status !== 0) { return [{ message: result.stderr, loc: { start: { line: 1 }, end: { line: 1 } } }]; } const {errors} = JSON.parse(result.stdout); return errors.map(error => { const [leading, ...rest] = error.message; const payload = rest.map(m => format(m, { root: options.root })); return { message: [leading.descr, ...payload].join(': '), path: leading.path, start: leading.loc.start.line, end: leading.loc.end.line, loc: leading.loc }; }); }
[ "function", "flow", "(", "options", ")", "{", "const", "result", "=", "spawnSync", "(", "bin", ",", "[", "'check-contents'", ",", "'--json'", ",", "`", "${", "options", ".", "root", "}", "`", ",", "options", ".", "fileName", "]", ",", "{", "input", ":", "options", ".", "source", ",", "encoding", ":", "'utf-8'", "}", ")", ";", "if", "(", "result", ".", "status", "!==", "0", ")", "{", "return", "[", "{", "message", ":", "result", ".", "stderr", ",", "loc", ":", "{", "start", ":", "{", "line", ":", "1", "}", ",", "end", ":", "{", "line", ":", "1", "}", "}", "}", "]", ";", "}", "const", "{", "errors", "}", "=", "JSON", ".", "parse", "(", "result", ".", "stdout", ")", ";", "return", "errors", ".", "map", "(", "error", "=>", "{", "const", "[", "leading", ",", "...", "rest", "]", "=", "error", ".", "message", ";", "const", "payload", "=", "rest", ".", "map", "(", "m", "=>", "format", "(", "m", ",", "{", "root", ":", "options", ".", "root", "}", ")", ")", ";", "return", "{", "message", ":", "[", "leading", ".", "descr", ",", "...", "payload", "]", ".", "join", "(", "': '", ")", ",", "path", ":", "leading", ".", "path", ",", "start", ":", "leading", ".", "loc", ".", "start", ".", "line", ",", "end", ":", "leading", ".", "loc", ".", "end", ".", "line", ",", "loc", ":", "leading", ".", "loc", "}", ";", "}", ")", ";", "}" ]
start a flow server
[ "start", "a", "flow", "server" ]
bd2332d114afe8a3fff03adbc4253cbd43bd926f
https://github.com/marionebl/eslint-plugin-flow-check/blob/bd2332d114afe8a3fff03adbc4253cbd43bd926f/source/flow.js#L9-L50
train
ascartabelli/lamb
src/privates/_getPathInfo.js
_getPathInfo
function _getPathInfo (obj, parts, walkNonEnumerables) { if (isNil(obj)) { throw _makeTypeErrorFor(obj, "object"); } var target = obj; var i = -1; var len = parts.length; var key; while (++i < len) { key = _getPathKey(target, parts[i], walkNonEnumerables); if (isUndefined(key)) { break; } target = target[key]; } return i === len ? { isValid: true, target: target } : { isValid: false, target: void 0 }; }
javascript
function _getPathInfo (obj, parts, walkNonEnumerables) { if (isNil(obj)) { throw _makeTypeErrorFor(obj, "object"); } var target = obj; var i = -1; var len = parts.length; var key; while (++i < len) { key = _getPathKey(target, parts[i], walkNonEnumerables); if (isUndefined(key)) { break; } target = target[key]; } return i === len ? { isValid: true, target: target } : { isValid: false, target: void 0 }; }
[ "function", "_getPathInfo", "(", "obj", ",", "parts", ",", "walkNonEnumerables", ")", "{", "if", "(", "isNil", "(", "obj", ")", ")", "{", "throw", "_makeTypeErrorFor", "(", "obj", ",", "\"object\"", ")", ";", "}", "var", "target", "=", "obj", ";", "var", "i", "=", "-", "1", ";", "var", "len", "=", "parts", ".", "length", ";", "var", "key", ";", "while", "(", "++", "i", "<", "len", ")", "{", "key", "=", "_getPathKey", "(", "target", ",", "parts", "[", "i", "]", ",", "walkNonEnumerables", ")", ";", "if", "(", "isUndefined", "(", "key", ")", ")", "{", "break", ";", "}", "target", "=", "target", "[", "key", "]", ";", "}", "return", "i", "===", "len", "?", "{", "isValid", ":", "true", ",", "target", ":", "target", "}", ":", "{", "isValid", ":", "false", ",", "target", ":", "void", "0", "}", ";", "}" ]
Checks if a path is valid in the given object and retrieves the path target. @private @param {Object} obj @param {String[]} parts @param {Boolean} walkNonEnumerables @returns {Object}
[ "Checks", "if", "a", "path", "is", "valid", "in", "the", "given", "object", "and", "retrieves", "the", "path", "target", "." ]
d36e45945c4789e4f1a2d8805936514b53f32362
https://github.com/ascartabelli/lamb/blob/d36e45945c4789e4f1a2d8805936514b53f32362/src/privates/_getPathInfo.js#L14-L35
train
ascartabelli/lamb
src/privates/_flatten.js
_flatten
function _flatten (array, isDeep, output, idx) { for (var i = 0, len = array.length, value, j, vLen; i < len; i++) { value = array[i]; if (!Array.isArray(value)) { output[idx++] = value; } else if (isDeep) { _flatten(value, true, output, idx); idx = output.length; } else { vLen = value.length; output.length += vLen; for (j = 0; j < vLen; j++) { output[idx++] = value[j]; } } } return output; }
javascript
function _flatten (array, isDeep, output, idx) { for (var i = 0, len = array.length, value, j, vLen; i < len; i++) { value = array[i]; if (!Array.isArray(value)) { output[idx++] = value; } else if (isDeep) { _flatten(value, true, output, idx); idx = output.length; } else { vLen = value.length; output.length += vLen; for (j = 0; j < vLen; j++) { output[idx++] = value[j]; } } } return output; }
[ "function", "_flatten", "(", "array", ",", "isDeep", ",", "output", ",", "idx", ")", "{", "for", "(", "var", "i", "=", "0", ",", "len", "=", "array", ".", "length", ",", "value", ",", "j", ",", "vLen", ";", "i", "<", "len", ";", "i", "++", ")", "{", "value", "=", "array", "[", "i", "]", ";", "if", "(", "!", "Array", ".", "isArray", "(", "value", ")", ")", "{", "output", "[", "idx", "++", "]", "=", "value", ";", "}", "else", "if", "(", "isDeep", ")", "{", "_flatten", "(", "value", ",", "true", ",", "output", ",", "idx", ")", ";", "idx", "=", "output", ".", "length", ";", "}", "else", "{", "vLen", "=", "value", ".", "length", ";", "output", ".", "length", "+=", "vLen", ";", "for", "(", "j", "=", "0", ";", "j", "<", "vLen", ";", "j", "++", ")", "{", "output", "[", "idx", "++", "]", "=", "value", "[", "j", "]", ";", "}", "}", "}", "return", "output", ";", "}" ]
Flattens an array. @private @param {Array} array - The source array @param {Boolean} isDeep - Whether to perform a deep flattening or not @param {Array} output - An array to collect the result @param {Number} idx - The next index to be filled in the output @returns {Array} The output array filled with the results
[ "Flattens", "an", "array", "." ]
d36e45945c4789e4f1a2d8805936514b53f32362
https://github.com/ascartabelli/lamb/blob/d36e45945c4789e4f1a2d8805936514b53f32362/src/privates/_flatten.js#L10-L30
train
fortunejs/fortune-mongodb
lib/helpers.js
mapValues
function mapValues (object, map) { return Object.keys(object).reduce((clone, key) => Object.assign(clone, { [key]: map(object[key], key) }), {}) }
javascript
function mapValues (object, map) { return Object.keys(object).reduce((clone, key) => Object.assign(clone, { [key]: map(object[key], key) }), {}) }
[ "function", "mapValues", "(", "object", ",", "map", ")", "{", "return", "Object", ".", "keys", "(", "object", ")", ".", "reduce", "(", "(", "clone", ",", "key", ")", "=>", "Object", ".", "assign", "(", "clone", ",", "{", "[", "key", "]", ":", "map", "(", "object", "[", "key", "]", ",", "key", ")", "}", ")", ",", "{", "}", ")", "}" ]
Create a new object with different key values. @param {Object} object @param {Function} map should return the first argument, which is the value @return {Object}
[ "Create", "a", "new", "object", "with", "different", "key", "values", "." ]
e1e5e4d830e37fdee92388ab194ba35a71dae27f
https://github.com/fortunejs/fortune-mongodb/blob/e1e5e4d830e37fdee92388ab194ba35a71dae27f/lib/helpers.js#L106-L109
train
fortunejs/fortune-mongodb
lib/helpers.js
toBuffer
function toBuffer (object) { if (Buffer.isBuffer(object)) return object if (object.buffer) return object.buffer throw new TypeError('Could not output buffer type.') }
javascript
function toBuffer (object) { if (Buffer.isBuffer(object)) return object if (object.buffer) return object.buffer throw new TypeError('Could not output buffer type.') }
[ "function", "toBuffer", "(", "object", ")", "{", "if", "(", "Buffer", ".", "isBuffer", "(", "object", ")", ")", "return", "object", "if", "(", "object", ".", "buffer", ")", "return", "object", ".", "buffer", "throw", "new", "TypeError", "(", "'Could not output buffer type.'", ")", "}" ]
There is an inconsistency when accessing a record depending on the method, it may be either a native `Buffer` or BSON object wrapper. We only want native buffers.
[ "There", "is", "an", "inconsistency", "when", "accessing", "a", "record", "depending", "on", "the", "method", "it", "may", "be", "either", "a", "native", "Buffer", "or", "BSON", "object", "wrapper", ".", "We", "only", "want", "native", "buffers", "." ]
e1e5e4d830e37fdee92388ab194ba35a71dae27f
https://github.com/fortunejs/fortune-mongodb/blob/e1e5e4d830e37fdee92388ab194ba35a71dae27f/lib/helpers.js#L115-L119
train
fortunejs/fortune-mongodb
lib/helpers.js
generateQuery
function generateQuery (fields, options, not) { let $and = [] const $or = [] const result = {} for (const key in options) switch (key) { case 'and': case 'or': const query = {} query[`$${key}`] = mapValues(options[key], value => { return generateQuery(fields, value) }) return query case 'not': return generateQuery(fields, options[key], true) case 'range': $and.push(generateRangeQuery(fields, options.range)) break case 'match': if ('or' in options.match) for (const key in options.match.or) { const q = {} q[key] = options.match.or[key] $or.push(q) } else $and.push(mapValues(options.match, value => Array.isArray(value) ? { $in: value } : value)) break case 'exists': $and.push(mapValues(options.exists, (value, key) => { if (!(key in fields)) return void 0 if (fields[key].isArray) return value ? { $ne: [] } : [] return value ? { $ne: null } : null })) break default: } if (not) $and = $and.map(applyNotOperator) if ($and.length) result.$and = $and if ($or.length) result.$or = $or return result }
javascript
function generateQuery (fields, options, not) { let $and = [] const $or = [] const result = {} for (const key in options) switch (key) { case 'and': case 'or': const query = {} query[`$${key}`] = mapValues(options[key], value => { return generateQuery(fields, value) }) return query case 'not': return generateQuery(fields, options[key], true) case 'range': $and.push(generateRangeQuery(fields, options.range)) break case 'match': if ('or' in options.match) for (const key in options.match.or) { const q = {} q[key] = options.match.or[key] $or.push(q) } else $and.push(mapValues(options.match, value => Array.isArray(value) ? { $in: value } : value)) break case 'exists': $and.push(mapValues(options.exists, (value, key) => { if (!(key in fields)) return void 0 if (fields[key].isArray) return value ? { $ne: [] } : [] return value ? { $ne: null } : null })) break default: } if (not) $and = $and.map(applyNotOperator) if ($and.length) result.$and = $and if ($or.length) result.$or = $or return result }
[ "function", "generateQuery", "(", "fields", ",", "options", ",", "not", ")", "{", "let", "$and", "=", "[", "]", "const", "$or", "=", "[", "]", "const", "result", "=", "{", "}", "for", "(", "const", "key", "in", "options", ")", "switch", "(", "key", ")", "{", "case", "'and'", ":", "case", "'or'", ":", "const", "query", "=", "{", "}", "query", "[", "`", "${", "key", "}", "`", "]", "=", "mapValues", "(", "options", "[", "key", "]", ",", "value", "=>", "{", "return", "generateQuery", "(", "fields", ",", "value", ")", "}", ")", "return", "query", "case", "'not'", ":", "return", "generateQuery", "(", "fields", ",", "options", "[", "key", "]", ",", "true", ")", "case", "'range'", ":", "$and", ".", "push", "(", "generateRangeQuery", "(", "fields", ",", "options", ".", "range", ")", ")", "break", "case", "'match'", ":", "if", "(", "'or'", "in", "options", ".", "match", ")", "for", "(", "const", "key", "in", "options", ".", "match", ".", "or", ")", "{", "const", "q", "=", "{", "}", "q", "[", "key", "]", "=", "options", ".", "match", ".", "or", "[", "key", "]", "$or", ".", "push", "(", "q", ")", "}", "else", "$and", ".", "push", "(", "mapValues", "(", "options", ".", "match", ",", "value", "=>", "Array", ".", "isArray", "(", "value", ")", "?", "{", "$in", ":", "value", "}", ":", "value", ")", ")", "break", "case", "'exists'", ":", "$and", ".", "push", "(", "mapValues", "(", "options", ".", "exists", ",", "(", "value", ",", "key", ")", "=>", "{", "if", "(", "!", "(", "key", "in", "fields", ")", ")", "return", "void", "0", "if", "(", "fields", "[", "key", "]", ".", "isArray", ")", "return", "value", "?", "{", "$ne", ":", "[", "]", "}", ":", "[", "]", "return", "value", "?", "{", "$ne", ":", "null", "}", ":", "null", "}", ")", ")", "break", "default", ":", "}", "if", "(", "not", ")", "$and", "=", "$and", ".", "map", "(", "applyNotOperator", ")", "if", "(", "$and", ".", "length", ")", "result", ".", "$and", "=", "$and", "if", "(", "$or", ".", "length", ")", "result", ".", "$or", "=", "$or", "return", "result", "}" ]
Generate a mongoDB query from a fortune query object
[ "Generate", "a", "mongoDB", "query", "from", "a", "fortune", "query", "object" ]
e1e5e4d830e37fdee92388ab194ba35a71dae27f
https://github.com/fortunejs/fortune-mongodb/blob/e1e5e4d830e37fdee92388ab194ba35a71dae27f/lib/helpers.js#L152-L201
train
takashiki/cos-webpack
index.js
function(fileName) { let file = assets[fileName] || {}; fileName = basePath + "/" + fileName.replace(/\\/g, '/'); let key = path.posix.join(uploadPath, fileName); return new Promise((resolve, reject) => { let begin = Date.now(); cos.putObject( { Bucket: bucket, Region: region, Key: key, Body: fs.createReadStream(file.existsAt), ContentLength: fs.statSync(file.existsAt).size }, function(err, body) { uploadedFiles++; spinner.text = tip(uploadedFiles, totalFiles); if (err) return reject(err); body.duration = Date.now() - begin; resolve(body); } ); }); }
javascript
function(fileName) { let file = assets[fileName] || {}; fileName = basePath + "/" + fileName.replace(/\\/g, '/'); let key = path.posix.join(uploadPath, fileName); return new Promise((resolve, reject) => { let begin = Date.now(); cos.putObject( { Bucket: bucket, Region: region, Key: key, Body: fs.createReadStream(file.existsAt), ContentLength: fs.statSync(file.existsAt).size }, function(err, body) { uploadedFiles++; spinner.text = tip(uploadedFiles, totalFiles); if (err) return reject(err); body.duration = Date.now() - begin; resolve(body); } ); }); }
[ "function", "(", "fileName", ")", "{", "let", "file", "=", "assets", "[", "fileName", "]", "||", "{", "}", ";", "fileName", "=", "basePath", "+", "\"/\"", "+", "fileName", ".", "replace", "(", "/", "\\\\", "/", "g", ",", "'/'", ")", ";", "let", "key", "=", "path", ".", "posix", ".", "join", "(", "uploadPath", ",", "fileName", ")", ";", "return", "new", "Promise", "(", "(", "resolve", ",", "reject", ")", "=>", "{", "let", "begin", "=", "Date", ".", "now", "(", ")", ";", "cos", ".", "putObject", "(", "{", "Bucket", ":", "bucket", ",", "Region", ":", "region", ",", "Key", ":", "key", ",", "Body", ":", "fs", ".", "createReadStream", "(", "file", ".", "existsAt", ")", ",", "ContentLength", ":", "fs", ".", "statSync", "(", "file", ".", "existsAt", ")", ".", "size", "}", ",", "function", "(", "err", ",", "body", ")", "{", "uploadedFiles", "++", ";", "spinner", ".", "text", "=", "tip", "(", "uploadedFiles", ",", "totalFiles", ")", ";", "if", "(", "err", ")", "return", "reject", "(", "err", ")", ";", "body", ".", "duration", "=", "Date", ".", "now", "(", ")", "-", "begin", ";", "resolve", "(", "body", ")", ";", "}", ")", ";", "}", ")", ";", "}" ]
Perform upload to cos
[ "Perform", "upload", "to", "cos" ]
2a8d09a14b977930c00c87a8c63e11897e929ed6
https://github.com/takashiki/cos-webpack/blob/2a8d09a14b977930c00c87a8c63e11897e929ed6/index.js#L104-L129
train
takashiki/cos-webpack
index.js
function(err) { if (err) { // eslint-disable-next-line no-console console.log("\n"); return Promise.reject(err); } // Get 20 files let _files = filesNames.splice(0, batch); if (_files.length) { return Promise.all(_files.map(performUpload)).then(() => execStack(), execStack); } else { return Promise.resolve(); } }
javascript
function(err) { if (err) { // eslint-disable-next-line no-console console.log("\n"); return Promise.reject(err); } // Get 20 files let _files = filesNames.splice(0, batch); if (_files.length) { return Promise.all(_files.map(performUpload)).then(() => execStack(), execStack); } else { return Promise.resolve(); } }
[ "function", "(", "err", ")", "{", "if", "(", "err", ")", "{", "console", ".", "log", "(", "\"\\n\"", ")", ";", "\\n", "}", "return", "Promise", ".", "reject", "(", "err", ")", ";", "let", "_files", "=", "filesNames", ".", "splice", "(", "0", ",", "batch", ")", ";", "}" ]
Execute stack according to `batch` option
[ "Execute", "stack", "according", "to", "batch", "option" ]
2a8d09a14b977930c00c87a8c63e11897e929ed6
https://github.com/takashiki/cos-webpack/blob/2a8d09a14b977930c00c87a8c63e11897e929ed6/index.js#L132-L147
train
aMarCruz/jspreproc
lib/compactor.js
indent
function indent(level) { var val = options.indent _indent = '' if (_lastch === null) _lastch = _to // as-is, this is the first file else if (_lastch !== _to) { _lastch = _to // istanbul ignore else if (output) output.emit('data', _to) // force eol after insert file } if (level > 0 && val && !/^0+\D?/.test(val)) { // format is 2, 2t, 2s, etc. default is spaces var match = /^(\d+)\s*(t?)/.exec(val), count = level * (match[1] | 0) _indent = Array(count + 1).join(match[2] ? '\t' : ' ') } }
javascript
function indent(level) { var val = options.indent _indent = '' if (_lastch === null) _lastch = _to // as-is, this is the first file else if (_lastch !== _to) { _lastch = _to // istanbul ignore else if (output) output.emit('data', _to) // force eol after insert file } if (level > 0 && val && !/^0+\D?/.test(val)) { // format is 2, 2t, 2s, etc. default is spaces var match = /^(\d+)\s*(t?)/.exec(val), count = level * (match[1] | 0) _indent = Array(count + 1).join(match[2] ? '\t' : ' ') } }
[ "function", "indent", "(", "level", ")", "{", "var", "val", "=", "options", ".", "indent", "_indent", "=", "''", "if", "(", "_lastch", "===", "null", ")", "_lastch", "=", "_to", "else", "if", "(", "_lastch", "!==", "_to", ")", "{", "_lastch", "=", "_to", "if", "(", "output", ")", "output", ".", "emit", "(", "'data'", ",", "_to", ")", "}", "if", "(", "level", ">", "0", "&&", "val", "&&", "!", "/", "^0+\\D?", "/", ".", "test", "(", "val", ")", ")", "{", "var", "match", "=", "/", "^(\\d+)\\s*(t?)", "/", ".", "exec", "(", "val", ")", ",", "count", "=", "level", "*", "(", "match", "[", "1", "]", "|", "0", ")", "_indent", "=", "Array", "(", "count", "+", "1", ")", ".", "join", "(", "match", "[", "2", "]", "?", "'\\t'", ":", "\\t", ")", "}", "}" ]
On file change, reset indentation
[ "On", "file", "change", "reset", "indentation" ]
5f31820d702a329e8aa25f0f3983f13097610250
https://github.com/aMarCruz/jspreproc/blob/5f31820d702a329e8aa25f0f3983f13097610250/lib/compactor.js#L32-L51
train
aMarCruz/jspreproc
lib/compactor.js
write
function write(buffer) { // first, trim trailing whitespace for fast searching buffer = buffer.replace(/[ \t]+$/gm, '') // compact lines if emptyLines != -1 if (_elines >= 0) buffer = trimBuffer(buffer) if (!buffer) return // finished the surrounding lines, now the inners if (!_elines) { // remove empty lines and change eols in one unique operation buffer = buffer.replace(/\n{2,}/g, _to) } else { // keep max n empty lines (n+1 sucesive eols), -1 keep all if (_elines > 0) buffer = buffer.replace(_re, '$1') // change line terminator if not unix if (_to !== '\n') buffer = buffer.replace(/\n/g, _to) } // apply indentation, regex `^.` with `/m` matches non-empty lines if (_indent) buffer = buffer.replace(/^./mg, _indent + '$&') _lastch = buffer.slice(-1) // istanbul ignore else if (output) output.emit('data', buffer) }
javascript
function write(buffer) { // first, trim trailing whitespace for fast searching buffer = buffer.replace(/[ \t]+$/gm, '') // compact lines if emptyLines != -1 if (_elines >= 0) buffer = trimBuffer(buffer) if (!buffer) return // finished the surrounding lines, now the inners if (!_elines) { // remove empty lines and change eols in one unique operation buffer = buffer.replace(/\n{2,}/g, _to) } else { // keep max n empty lines (n+1 sucesive eols), -1 keep all if (_elines > 0) buffer = buffer.replace(_re, '$1') // change line terminator if not unix if (_to !== '\n') buffer = buffer.replace(/\n/g, _to) } // apply indentation, regex `^.` with `/m` matches non-empty lines if (_indent) buffer = buffer.replace(/^./mg, _indent + '$&') _lastch = buffer.slice(-1) // istanbul ignore else if (output) output.emit('data', buffer) }
[ "function", "write", "(", "buffer", ")", "{", "buffer", "=", "buffer", ".", "replace", "(", "/", "[ \\t]+$", "/", "gm", ",", "''", ")", "if", "(", "_elines", ">=", "0", ")", "buffer", "=", "trimBuffer", "(", "buffer", ")", "if", "(", "!", "buffer", ")", "return", "if", "(", "!", "_elines", ")", "{", "buffer", "=", "buffer", ".", "replace", "(", "/", "\\n{2,}", "/", "g", ",", "_to", ")", "}", "else", "{", "if", "(", "_elines", ">", "0", ")", "buffer", "=", "buffer", ".", "replace", "(", "_re", ",", "'$1'", ")", "if", "(", "_to", "!==", "'\\n'", ")", "\\n", "}", "buffer", "=", "buffer", ".", "replace", "(", "/", "\\n", "/", "g", ",", "_to", ")", "if", "(", "_indent", ")", "buffer", "=", "buffer", ".", "replace", "(", "/", "^.", "/", "mg", ",", "_indent", "+", "'$&'", ")", "_lastch", "=", "buffer", ".", "slice", "(", "-", "1", ")", "}" ]
On new data, trim trailing whitespace and normalize eols
[ "On", "new", "data", "trim", "trailing", "whitespace", "and", "normalize", "eols" ]
5f31820d702a329e8aa25f0f3983f13097610250
https://github.com/aMarCruz/jspreproc/blob/5f31820d702a329e8aa25f0f3983f13097610250/lib/compactor.js#L55-L88
train
jgkim/mocha-gherkin
src/spec.js
GherkinSpec
function GherkinSpec(runner) { Base.call(this, runner); let indents = 0; let n = 0; if (!Base.useColors) { colors.enabled = false; } function indent() { return Array(indents).join(' '); } runner.on('start', () => { console.log(); }); runner.on('suite', (suite) => { indents += 1; let text = suite.title; switch (suite.name) { case 'Feature': text = colors.underline.bold(suite.title); suite.stories.forEach((story) => { text += `\n${indent()} ${story}`; }); break; case 'Scenario': text = colors.green(suite.title); break; default: text = Base.color('suite', text); } console.log(indent() + text); }); runner.on('suite end', () => { indents -= 1; if (indents === 1) { console.log(); } }); runner.on('pending', (test) => { console.log(`${indent()} ${colors.cyan(`- ${test.title}`)}`); }); runner.on('pass', (test) => { let fmt = indent() + colors.green(` ${Base.symbols.ok} %s`); if (test.speed === 'fast') { cursor.CR(); console.log(fmt, test.title); } else { fmt += Base.color(test.speed, ' (%dms)'); cursor.CR(); console.log(fmt, test.title, test.duration); } }); runner.on('fail', (test) => { cursor.CR(); n += 1; console.log(`${indent()} ${colors.red('%d) %s')}`, n, test.title); }); runner.on('end', this.epilogue.bind(this)); }
javascript
function GherkinSpec(runner) { Base.call(this, runner); let indents = 0; let n = 0; if (!Base.useColors) { colors.enabled = false; } function indent() { return Array(indents).join(' '); } runner.on('start', () => { console.log(); }); runner.on('suite', (suite) => { indents += 1; let text = suite.title; switch (suite.name) { case 'Feature': text = colors.underline.bold(suite.title); suite.stories.forEach((story) => { text += `\n${indent()} ${story}`; }); break; case 'Scenario': text = colors.green(suite.title); break; default: text = Base.color('suite', text); } console.log(indent() + text); }); runner.on('suite end', () => { indents -= 1; if (indents === 1) { console.log(); } }); runner.on('pending', (test) => { console.log(`${indent()} ${colors.cyan(`- ${test.title}`)}`); }); runner.on('pass', (test) => { let fmt = indent() + colors.green(` ${Base.symbols.ok} %s`); if (test.speed === 'fast') { cursor.CR(); console.log(fmt, test.title); } else { fmt += Base.color(test.speed, ' (%dms)'); cursor.CR(); console.log(fmt, test.title, test.duration); } }); runner.on('fail', (test) => { cursor.CR(); n += 1; console.log(`${indent()} ${colors.red('%d) %s')}`, n, test.title); }); runner.on('end', this.epilogue.bind(this)); }
[ "function", "GherkinSpec", "(", "runner", ")", "{", "Base", ".", "call", "(", "this", ",", "runner", ")", ";", "let", "indents", "=", "0", ";", "let", "n", "=", "0", ";", "if", "(", "!", "Base", ".", "useColors", ")", "{", "colors", ".", "enabled", "=", "false", ";", "}", "function", "indent", "(", ")", "{", "return", "Array", "(", "indents", ")", ".", "join", "(", "' '", ")", ";", "}", "runner", ".", "on", "(", "'start'", ",", "(", ")", "=>", "{", "console", ".", "log", "(", ")", ";", "}", ")", ";", "runner", ".", "on", "(", "'suite'", ",", "(", "suite", ")", "=>", "{", "indents", "+=", "1", ";", "let", "text", "=", "suite", ".", "title", ";", "switch", "(", "suite", ".", "name", ")", "{", "case", "'Feature'", ":", "text", "=", "colors", ".", "underline", ".", "bold", "(", "suite", ".", "title", ")", ";", "suite", ".", "stories", ".", "forEach", "(", "(", "story", ")", "=>", "{", "text", "+=", "`", "\\n", "${", "indent", "(", ")", "}", "${", "story", "}", "`", ";", "}", ")", ";", "break", ";", "case", "'Scenario'", ":", "text", "=", "colors", ".", "green", "(", "suite", ".", "title", ")", ";", "break", ";", "default", ":", "text", "=", "Base", ".", "color", "(", "'suite'", ",", "text", ")", ";", "}", "console", ".", "log", "(", "indent", "(", ")", "+", "text", ")", ";", "}", ")", ";", "runner", ".", "on", "(", "'suite end'", ",", "(", ")", "=>", "{", "indents", "-=", "1", ";", "if", "(", "indents", "===", "1", ")", "{", "console", ".", "log", "(", ")", ";", "}", "}", ")", ";", "runner", ".", "on", "(", "'pending'", ",", "(", "test", ")", "=>", "{", "console", ".", "log", "(", "`", "${", "indent", "(", ")", "}", "${", "colors", ".", "cyan", "(", "`", "${", "test", ".", "title", "}", "`", ")", "}", "`", ")", ";", "}", ")", ";", "runner", ".", "on", "(", "'pass'", ",", "(", "test", ")", "=>", "{", "let", "fmt", "=", "indent", "(", ")", "+", "colors", ".", "green", "(", "`", "${", "Base", ".", "symbols", ".", "ok", "}", "`", ")", ";", "if", "(", "test", ".", "speed", "===", "'fast'", ")", "{", "cursor", ".", "CR", "(", ")", ";", "console", ".", "log", "(", "fmt", ",", "test", ".", "title", ")", ";", "}", "else", "{", "fmt", "+=", "Base", ".", "color", "(", "test", ".", "speed", ",", "' (%dms)'", ")", ";", "cursor", ".", "CR", "(", ")", ";", "console", ".", "log", "(", "fmt", ",", "test", ".", "title", ",", "test", ".", "duration", ")", ";", "}", "}", ")", ";", "runner", ".", "on", "(", "'fail'", ",", "(", "test", ")", "=>", "{", "cursor", ".", "CR", "(", ")", ";", "n", "+=", "1", ";", "console", ".", "log", "(", "`", "${", "indent", "(", ")", "}", "${", "colors", ".", "red", "(", "'%d) %s'", ")", "}", "`", ",", "n", ",", "test", ".", "title", ")", ";", "}", ")", ";", "runner", ".", "on", "(", "'end'", ",", "this", ".", "epilogue", ".", "bind", "(", "this", ")", ")", ";", "}" ]
Initialize a new `GherkinSpec` test reporter. @api public @param {Runner} runner
[ "Initialize", "a", "new", "GherkinSpec", "test", "reporter", "." ]
9542725a3c5b557b153bc51ce6d61d1b11dfd3a5
https://github.com/jgkim/mocha-gherkin/blob/9542725a3c5b557b153bc51ce6d61d1b11dfd3a5/src/spec.js#L14-L82
train
LaxarJS/webpack-jasmine-html-runner-plugin
index.js
entry
function entry() { const patterns = Array.from( arguments ); const entry = {}; patterns.forEach( globPattern => { // backwards compatibility: const pattern = globPattern.replace( '[name]', '**' ); return glob.sync( pattern ).forEach( path => { const baseName = path.replace( /\.[^.]+$/, '' ); entry[ baseName ] = path; } ); } ); return entry; }
javascript
function entry() { const patterns = Array.from( arguments ); const entry = {}; patterns.forEach( globPattern => { // backwards compatibility: const pattern = globPattern.replace( '[name]', '**' ); return glob.sync( pattern ).forEach( path => { const baseName = path.replace( /\.[^.]+$/, '' ); entry[ baseName ] = path; } ); } ); return entry; }
[ "function", "entry", "(", ")", "{", "const", "patterns", "=", "Array", ".", "from", "(", "arguments", ")", ";", "const", "entry", "=", "{", "}", ";", "patterns", ".", "forEach", "(", "globPattern", "=>", "{", "const", "pattern", "=", "globPattern", ".", "replace", "(", "'[name]'", ",", "'**'", ")", ";", "return", "glob", ".", "sync", "(", "pattern", ")", ".", "forEach", "(", "path", "=>", "{", "const", "baseName", "=", "path", ".", "replace", "(", "/", "\\.[^.]+$", "/", ",", "''", ")", ";", "entry", "[", "baseName", "]", "=", "path", ";", "}", ")", ";", "}", ")", ";", "return", "entry", ";", "}" ]
Generates webpack entry points suitable for use with the WebpackJasmineHtmlRunnerPlugin plugin. Basically, each file matching one of the provided glob-patterns becomes an entry point which is named like that file, but without the extension. @param {...String} patterns File patterns in glob-syntax (may contain * and **). @return {Object} entry points for use as webpack `entry` configuration, as an object.
[ "Generates", "webpack", "entry", "points", "suitable", "for", "use", "with", "the", "WebpackJasmineHtmlRunnerPlugin", "plugin", ".", "Basically", "each", "file", "matching", "one", "of", "the", "provided", "glob", "-", "patterns", "becomes", "an", "entry", "point", "which", "is", "named", "like", "that", "file", "but", "without", "the", "extension", "." ]
6a6671385dc54db67f44446fb52308d7513e66f7
https://github.com/LaxarJS/webpack-jasmine-html-runner-plugin/blob/6a6671385dc54db67f44446fb52308d7513e66f7/index.js#L34-L46
train
Inspired-by-Boredom/generator-vintage-frontend
generators/app/templates/gulp/tasks/templates.js
compileHtml
function compileHtml(src, dest) { return gulp.src([src]) .pipe(plumber(config.plumberOptions)) .pipe(pug(pugOptions)) .pipe(prettify()) .pipe(gulp.dest(dest)); }
javascript
function compileHtml(src, dest) { return gulp.src([src]) .pipe(plumber(config.plumberOptions)) .pipe(pug(pugOptions)) .pipe(prettify()) .pipe(gulp.dest(dest)); }
[ "function", "compileHtml", "(", "src", ",", "dest", ")", "{", "return", "gulp", ".", "src", "(", "[", "src", "]", ")", ".", "pipe", "(", "plumber", "(", "config", ".", "plumberOptions", ")", ")", ".", "pipe", "(", "pug", "(", "pugOptions", ")", ")", ".", "pipe", "(", "prettify", "(", ")", ")", ".", "pipe", "(", "gulp", ".", "dest", "(", "dest", ")", ")", ";", "}" ]
Default HTML compilation function. @param {String} src @param {String} dest
[ "Default", "HTML", "compilation", "function", "." ]
316ebc981961a39d3c47ba830f377350d529452b
https://github.com/Inspired-by-Boredom/generator-vintage-frontend/blob/316ebc981961a39d3c47ba830f377350d529452b/generators/app/templates/gulp/tasks/templates.js#L46-L52
train
ILLGrenoble/guacamole-common-js
src/Tunnel.js
addExtraHeaders
function addExtraHeaders(request, headers) { for (var name in headers) { request.setRequestHeader(name, headers[name]); } }
javascript
function addExtraHeaders(request, headers) { for (var name in headers) { request.setRequestHeader(name, headers[name]); } }
[ "function", "addExtraHeaders", "(", "request", ",", "headers", ")", "{", "for", "(", "var", "name", "in", "headers", ")", "{", "request", ".", "setRequestHeader", "(", "name", ",", "headers", "[", "name", "]", ")", ";", "}", "}" ]
Adds the configured additional headers to the given request. @param {XMLHttpRequest} request The request where the configured extra headers will be added. @param {Object} headers The headers to be added to the request. @private
[ "Adds", "the", "configured", "additional", "headers", "to", "the", "given", "request", "." ]
71925794155ea3fc37d2a125adbca6f8be532887
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/Tunnel.js#L242-L246
train
ILLGrenoble/guacamole-common-js
src/Tunnel.js
reset_timeout
function reset_timeout() { // Get rid of old timeout (if any) window.clearTimeout(receive_timeout); // Set new timeout receive_timeout = window.setTimeout(function () { close_tunnel(new Guacamole.Status(Guacamole.Status.Code.UPSTREAM_TIMEOUT, "Server timeout.")); }, tunnel.receiveTimeout); }
javascript
function reset_timeout() { // Get rid of old timeout (if any) window.clearTimeout(receive_timeout); // Set new timeout receive_timeout = window.setTimeout(function () { close_tunnel(new Guacamole.Status(Guacamole.Status.Code.UPSTREAM_TIMEOUT, "Server timeout.")); }, tunnel.receiveTimeout); }
[ "function", "reset_timeout", "(", ")", "{", "window", ".", "clearTimeout", "(", "receive_timeout", ")", ";", "receive_timeout", "=", "window", ".", "setTimeout", "(", "function", "(", ")", "{", "close_tunnel", "(", "new", "Guacamole", ".", "Status", "(", "Guacamole", ".", "Status", ".", "Code", ".", "UPSTREAM_TIMEOUT", ",", "\"Server timeout.\"", ")", ")", ";", "}", ",", "tunnel", ".", "receiveTimeout", ")", ";", "}" ]
Initiates a timeout which, if data is not received, causes the tunnel to close with an error. @private
[ "Initiates", "a", "timeout", "which", "if", "data", "is", "not", "received", "causes", "the", "tunnel", "to", "close", "with", "an", "error", "." ]
71925794155ea3fc37d2a125adbca6f8be532887
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/Tunnel.js#L254-L264
train
ILLGrenoble/guacamole-common-js
src/Tunnel.js
attach
function attach(tunnel) { // Set own functions to tunnel's functions chained_tunnel.disconnect = tunnel.disconnect; chained_tunnel.sendMessage = tunnel.sendMessage; /** * Fails the currently-attached tunnel, attaching a new tunnel if * possible. * * @private * @param {Guacamole.Status} [status] * An object representing the failure that occured in the * currently-attached tunnel, if known. * * @return {Guacamole.Tunnel} * The next tunnel, or null if there are no more tunnels to try or * if no more tunnels should be tried. */ var failTunnel = function failTunnel(status) { // Do not attempt to continue using next tunnel on server timeout if (status && status.code === Guacamole.Status.Code.UPSTREAM_TIMEOUT) { tunnels = []; return null; } // Get next tunnel var next_tunnel = tunnels.shift(); // If there IS a next tunnel, try using it. if (next_tunnel) { tunnel.onerror = null; tunnel.oninstruction = null; tunnel.onstatechange = null; attach(next_tunnel); } return next_tunnel; }; /** * Use the current tunnel from this point forward. Do not try any more * tunnels, even if the current tunnel fails. * * @private */ function commit_tunnel() { tunnel.onstatechange = chained_tunnel.onstatechange; tunnel.oninstruction = chained_tunnel.oninstruction; tunnel.onerror = chained_tunnel.onerror; chained_tunnel.uuid = tunnel.uuid; committedTunnel = tunnel; } // Wrap own onstatechange within current tunnel tunnel.onstatechange = function(state) { switch (state) { // If open, use this tunnel from this point forward. case Guacamole.Tunnel.State.OPEN: commit_tunnel(); if (chained_tunnel.onstatechange) chained_tunnel.onstatechange(state); break; // If closed, mark failure, attempt next tunnel case Guacamole.Tunnel.State.CLOSED: if (!failTunnel() && chained_tunnel.onstatechange) chained_tunnel.onstatechange(state); break; } }; // Wrap own oninstruction within current tunnel tunnel.oninstruction = function(opcode, elements) { // Accept current tunnel commit_tunnel(); // Invoke handler if (chained_tunnel.oninstruction) chained_tunnel.oninstruction(opcode, elements); }; // Attach next tunnel on error tunnel.onerror = function(status) { // Mark failure, attempt next tunnel if (!failTunnel(status) && chained_tunnel.onerror) chained_tunnel.onerror(status); }; // Attempt connection tunnel.connect(connect_data); }
javascript
function attach(tunnel) { // Set own functions to tunnel's functions chained_tunnel.disconnect = tunnel.disconnect; chained_tunnel.sendMessage = tunnel.sendMessage; /** * Fails the currently-attached tunnel, attaching a new tunnel if * possible. * * @private * @param {Guacamole.Status} [status] * An object representing the failure that occured in the * currently-attached tunnel, if known. * * @return {Guacamole.Tunnel} * The next tunnel, or null if there are no more tunnels to try or * if no more tunnels should be tried. */ var failTunnel = function failTunnel(status) { // Do not attempt to continue using next tunnel on server timeout if (status && status.code === Guacamole.Status.Code.UPSTREAM_TIMEOUT) { tunnels = []; return null; } // Get next tunnel var next_tunnel = tunnels.shift(); // If there IS a next tunnel, try using it. if (next_tunnel) { tunnel.onerror = null; tunnel.oninstruction = null; tunnel.onstatechange = null; attach(next_tunnel); } return next_tunnel; }; /** * Use the current tunnel from this point forward. Do not try any more * tunnels, even if the current tunnel fails. * * @private */ function commit_tunnel() { tunnel.onstatechange = chained_tunnel.onstatechange; tunnel.oninstruction = chained_tunnel.oninstruction; tunnel.onerror = chained_tunnel.onerror; chained_tunnel.uuid = tunnel.uuid; committedTunnel = tunnel; } // Wrap own onstatechange within current tunnel tunnel.onstatechange = function(state) { switch (state) { // If open, use this tunnel from this point forward. case Guacamole.Tunnel.State.OPEN: commit_tunnel(); if (chained_tunnel.onstatechange) chained_tunnel.onstatechange(state); break; // If closed, mark failure, attempt next tunnel case Guacamole.Tunnel.State.CLOSED: if (!failTunnel() && chained_tunnel.onstatechange) chained_tunnel.onstatechange(state); break; } }; // Wrap own oninstruction within current tunnel tunnel.oninstruction = function(opcode, elements) { // Accept current tunnel commit_tunnel(); // Invoke handler if (chained_tunnel.oninstruction) chained_tunnel.oninstruction(opcode, elements); }; // Attach next tunnel on error tunnel.onerror = function(status) { // Mark failure, attempt next tunnel if (!failTunnel(status) && chained_tunnel.onerror) chained_tunnel.onerror(status); }; // Attempt connection tunnel.connect(connect_data); }
[ "function", "attach", "(", "tunnel", ")", "{", "chained_tunnel", ".", "disconnect", "=", "tunnel", ".", "disconnect", ";", "chained_tunnel", ".", "sendMessage", "=", "tunnel", ".", "sendMessage", ";", "var", "failTunnel", "=", "function", "failTunnel", "(", "status", ")", "{", "if", "(", "status", "&&", "status", ".", "code", "===", "Guacamole", ".", "Status", ".", "Code", ".", "UPSTREAM_TIMEOUT", ")", "{", "tunnels", "=", "[", "]", ";", "return", "null", ";", "}", "var", "next_tunnel", "=", "tunnels", ".", "shift", "(", ")", ";", "if", "(", "next_tunnel", ")", "{", "tunnel", ".", "onerror", "=", "null", ";", "tunnel", ".", "oninstruction", "=", "null", ";", "tunnel", ".", "onstatechange", "=", "null", ";", "attach", "(", "next_tunnel", ")", ";", "}", "return", "next_tunnel", ";", "}", ";", "function", "commit_tunnel", "(", ")", "{", "tunnel", ".", "onstatechange", "=", "chained_tunnel", ".", "onstatechange", ";", "tunnel", ".", "oninstruction", "=", "chained_tunnel", ".", "oninstruction", ";", "tunnel", ".", "onerror", "=", "chained_tunnel", ".", "onerror", ";", "chained_tunnel", ".", "uuid", "=", "tunnel", ".", "uuid", ";", "committedTunnel", "=", "tunnel", ";", "}", "tunnel", ".", "onstatechange", "=", "function", "(", "state", ")", "{", "switch", "(", "state", ")", "{", "case", "Guacamole", ".", "Tunnel", ".", "State", ".", "OPEN", ":", "commit_tunnel", "(", ")", ";", "if", "(", "chained_tunnel", ".", "onstatechange", ")", "chained_tunnel", ".", "onstatechange", "(", "state", ")", ";", "break", ";", "case", "Guacamole", ".", "Tunnel", ".", "State", ".", "CLOSED", ":", "if", "(", "!", "failTunnel", "(", ")", "&&", "chained_tunnel", ".", "onstatechange", ")", "chained_tunnel", ".", "onstatechange", "(", "state", ")", ";", "break", ";", "}", "}", ";", "tunnel", ".", "oninstruction", "=", "function", "(", "opcode", ",", "elements", ")", "{", "commit_tunnel", "(", ")", ";", "if", "(", "chained_tunnel", ".", "oninstruction", ")", "chained_tunnel", ".", "oninstruction", "(", "opcode", ",", "elements", ")", ";", "}", ";", "tunnel", ".", "onerror", "=", "function", "(", "status", ")", "{", "if", "(", "!", "failTunnel", "(", "status", ")", "&&", "chained_tunnel", ".", "onerror", ")", "chained_tunnel", ".", "onerror", "(", "status", ")", ";", "}", ";", "tunnel", ".", "connect", "(", "connect_data", ")", ";", "}" ]
Sets the current tunnel. @private @param {Guacamole.Tunnel} tunnel The tunnel to set as the current tunnel.
[ "Sets", "the", "current", "tunnel", "." ]
71925794155ea3fc37d2a125adbca6f8be532887
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/Tunnel.js#L954-L1056
train
ILLGrenoble/guacamole-common-js
src/Tunnel.js
failTunnel
function failTunnel(status) { // Do not attempt to continue using next tunnel on server timeout if (status && status.code === Guacamole.Status.Code.UPSTREAM_TIMEOUT) { tunnels = []; return null; } // Get next tunnel var next_tunnel = tunnels.shift(); // If there IS a next tunnel, try using it. if (next_tunnel) { tunnel.onerror = null; tunnel.oninstruction = null; tunnel.onstatechange = null; attach(next_tunnel); } return next_tunnel; }
javascript
function failTunnel(status) { // Do not attempt to continue using next tunnel on server timeout if (status && status.code === Guacamole.Status.Code.UPSTREAM_TIMEOUT) { tunnels = []; return null; } // Get next tunnel var next_tunnel = tunnels.shift(); // If there IS a next tunnel, try using it. if (next_tunnel) { tunnel.onerror = null; tunnel.oninstruction = null; tunnel.onstatechange = null; attach(next_tunnel); } return next_tunnel; }
[ "function", "failTunnel", "(", "status", ")", "{", "if", "(", "status", "&&", "status", ".", "code", "===", "Guacamole", ".", "Status", ".", "Code", ".", "UPSTREAM_TIMEOUT", ")", "{", "tunnels", "=", "[", "]", ";", "return", "null", ";", "}", "var", "next_tunnel", "=", "tunnels", ".", "shift", "(", ")", ";", "if", "(", "next_tunnel", ")", "{", "tunnel", ".", "onerror", "=", "null", ";", "tunnel", ".", "oninstruction", "=", "null", ";", "tunnel", ".", "onstatechange", "=", "null", ";", "attach", "(", "next_tunnel", ")", ";", "}", "return", "next_tunnel", ";", "}" ]
Fails the currently-attached tunnel, attaching a new tunnel if possible. @private @param {Guacamole.Status} [status] An object representing the failure that occured in the currently-attached tunnel, if known. @return {Guacamole.Tunnel} The next tunnel, or null if there are no more tunnels to try or if no more tunnels should be tried.
[ "Fails", "the", "currently", "-", "attached", "tunnel", "attaching", "a", "new", "tunnel", "if", "possible", "." ]
71925794155ea3fc37d2a125adbca6f8be532887
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/Tunnel.js#L973-L994
train
ILLGrenoble/guacamole-common-js
src/Tunnel.js
commit_tunnel
function commit_tunnel() { tunnel.onstatechange = chained_tunnel.onstatechange; tunnel.oninstruction = chained_tunnel.oninstruction; tunnel.onerror = chained_tunnel.onerror; chained_tunnel.uuid = tunnel.uuid; committedTunnel = tunnel; }
javascript
function commit_tunnel() { tunnel.onstatechange = chained_tunnel.onstatechange; tunnel.oninstruction = chained_tunnel.oninstruction; tunnel.onerror = chained_tunnel.onerror; chained_tunnel.uuid = tunnel.uuid; committedTunnel = tunnel; }
[ "function", "commit_tunnel", "(", ")", "{", "tunnel", ".", "onstatechange", "=", "chained_tunnel", ".", "onstatechange", ";", "tunnel", ".", "oninstruction", "=", "chained_tunnel", ".", "oninstruction", ";", "tunnel", ".", "onerror", "=", "chained_tunnel", ".", "onerror", ";", "chained_tunnel", ".", "uuid", "=", "tunnel", ".", "uuid", ";", "committedTunnel", "=", "tunnel", ";", "}" ]
Use the current tunnel from this point forward. Do not try any more tunnels, even if the current tunnel fails. @private
[ "Use", "the", "current", "tunnel", "from", "this", "point", "forward", ".", "Do", "not", "try", "any", "more", "tunnels", "even", "if", "the", "current", "tunnel", "fails", "." ]
71925794155ea3fc37d2a125adbca6f8be532887
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/Tunnel.js#L1002-L1008
train
ILLGrenoble/guacamole-common-js
src/Tunnel.js
getGuacamoleStatusCode
function getGuacamoleStatusCode(httpStatus) { // Translate status codes with known equivalents switch (httpStatus) { // HTTP 400 - Bad request case 400: return Guacamole.Status.Code.CLIENT_BAD_REQUEST; // HTTP 403 - Forbidden case 403: return Guacamole.Status.Code.CLIENT_FORBIDDEN; // HTTP 404 - Resource not found case 404: return Guacamole.Status.Code.RESOURCE_NOT_FOUND; // HTTP 429 - Too many requests case 429: return Guacamole.Status.Code.CLIENT_TOO_MANY; // HTTP 503 - Server unavailable case 503: return Guacamole.Status.Code.SERVER_BUSY; } // Default all other codes to generic internal error return Guacamole.Status.Code.SERVER_ERROR; }
javascript
function getGuacamoleStatusCode(httpStatus) { // Translate status codes with known equivalents switch (httpStatus) { // HTTP 400 - Bad request case 400: return Guacamole.Status.Code.CLIENT_BAD_REQUEST; // HTTP 403 - Forbidden case 403: return Guacamole.Status.Code.CLIENT_FORBIDDEN; // HTTP 404 - Resource not found case 404: return Guacamole.Status.Code.RESOURCE_NOT_FOUND; // HTTP 429 - Too many requests case 429: return Guacamole.Status.Code.CLIENT_TOO_MANY; // HTTP 503 - Server unavailable case 503: return Guacamole.Status.Code.SERVER_BUSY; } // Default all other codes to generic internal error return Guacamole.Status.Code.SERVER_ERROR; }
[ "function", "getGuacamoleStatusCode", "(", "httpStatus", ")", "{", "switch", "(", "httpStatus", ")", "{", "case", "400", ":", "return", "Guacamole", ".", "Status", ".", "Code", ".", "CLIENT_BAD_REQUEST", ";", "case", "403", ":", "return", "Guacamole", ".", "Status", ".", "Code", ".", "CLIENT_FORBIDDEN", ";", "case", "404", ":", "return", "Guacamole", ".", "Status", ".", "Code", ".", "RESOURCE_NOT_FOUND", ";", "case", "429", ":", "return", "Guacamole", ".", "Status", ".", "Code", ".", "CLIENT_TOO_MANY", ";", "case", "503", ":", "return", "Guacamole", ".", "Status", ".", "Code", ".", "SERVER_BUSY", ";", "}", "return", "Guacamole", ".", "Status", ".", "Code", ".", "SERVER_ERROR", ";", "}" ]
Returns the Guacamole protocol status code which most closely represents the given HTTP status code. @private @param {Number} httpStatus The HTTP status code to translate into a Guacamole protocol status code. @returns {Number} The Guacamole protocol status code which most closely represents the given HTTP status code.
[ "Returns", "the", "Guacamole", "protocol", "status", "code", "which", "most", "closely", "represents", "the", "given", "HTTP", "status", "code", "." ]
71925794155ea3fc37d2a125adbca6f8be532887
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/Tunnel.js#L1157-L1187
train
smshuja/parse-server-accountkit-auth
index.js
validateAuthData
function validateAuthData(authData, config) { var appSecretProof = crypto.createHmac('sha256', config.appSecret).update(authData.access_token).digest('hex'); return graphRequest('me/?access_token=' + authData.access_token + '&appsecret_proof=' + appSecretProof) .then((data) => { if (data && data.id == authData.id) { return; } throw new Parse.Error( Parse.Error.OBJECT_NOT_FOUND, 'AccountKit auth is invalid for this user.'); }); }
javascript
function validateAuthData(authData, config) { var appSecretProof = crypto.createHmac('sha256', config.appSecret).update(authData.access_token).digest('hex'); return graphRequest('me/?access_token=' + authData.access_token + '&appsecret_proof=' + appSecretProof) .then((data) => { if (data && data.id == authData.id) { return; } throw new Parse.Error( Parse.Error.OBJECT_NOT_FOUND, 'AccountKit auth is invalid for this user.'); }); }
[ "function", "validateAuthData", "(", "authData", ",", "config", ")", "{", "var", "appSecretProof", "=", "crypto", ".", "createHmac", "(", "'sha256'", ",", "config", ".", "appSecret", ")", ".", "update", "(", "authData", ".", "access_token", ")", ".", "digest", "(", "'hex'", ")", ";", "return", "graphRequest", "(", "'me/?access_token='", "+", "authData", ".", "access_token", "+", "'&appsecret_proof='", "+", "appSecretProof", ")", ".", "then", "(", "(", "data", ")", "=>", "{", "if", "(", "data", "&&", "data", ".", "id", "==", "authData", ".", "id", ")", "{", "return", ";", "}", "throw", "new", "Parse", ".", "Error", "(", "Parse", ".", "Error", ".", "OBJECT_NOT_FOUND", ",", "'AccountKit auth is invalid for this user.'", ")", ";", "}", ")", ";", "}" ]
Returns a promise that fulfills iff this user id is valid.
[ "Returns", "a", "promise", "that", "fulfills", "iff", "this", "user", "id", "is", "valid", "." ]
6a47523ce08f0bc8f39c372e1a99d15d4d9e4aca
https://github.com/smshuja/parse-server-accountkit-auth/blob/6a47523ce08f0bc8f39c372e1a99d15d4d9e4aca/index.js#L7-L18
train
GiladShoham/seven-boom
lib/wrappedBoomFunction.js
getWrappedFunc
function getWrappedFunc(funcName, func, ...args) { const funcDefaultArgs = defaultArgs[funcName] || defaultArgs['default']; const allArgs = funcDefaultArgs.concat(args); return function(...allArgs) { const boomArgs = _.take(allArgs, funcDefaultArgs.length); let result = func.call(null, ...boomArgs); for (var i = 0; i < args.length; i++) { let currArgVal = allArgs[i + funcDefaultArgs.length]; const argDef = args[i]; // Check if we need to use the defaults if (currArgVal === undefined){ // Run the function from the args def if (_.isFunction(argDef.default)) { result.output.payload[argDef.name] = argDef.default(); // Add the default value to result } else if (argDef.default) { result.output.payload[argDef.name] = argDef.default; } // Add the passed value to result } else { result.output.payload[argDef.name] = currArgVal; } } return result; }; }
javascript
function getWrappedFunc(funcName, func, ...args) { const funcDefaultArgs = defaultArgs[funcName] || defaultArgs['default']; const allArgs = funcDefaultArgs.concat(args); return function(...allArgs) { const boomArgs = _.take(allArgs, funcDefaultArgs.length); let result = func.call(null, ...boomArgs); for (var i = 0; i < args.length; i++) { let currArgVal = allArgs[i + funcDefaultArgs.length]; const argDef = args[i]; // Check if we need to use the defaults if (currArgVal === undefined){ // Run the function from the args def if (_.isFunction(argDef.default)) { result.output.payload[argDef.name] = argDef.default(); // Add the default value to result } else if (argDef.default) { result.output.payload[argDef.name] = argDef.default; } // Add the passed value to result } else { result.output.payload[argDef.name] = currArgVal; } } return result; }; }
[ "function", "getWrappedFunc", "(", "funcName", ",", "func", ",", "...", "args", ")", "{", "const", "funcDefaultArgs", "=", "defaultArgs", "[", "funcName", "]", "||", "defaultArgs", "[", "'default'", "]", ";", "const", "allArgs", "=", "funcDefaultArgs", ".", "concat", "(", "args", ")", ";", "return", "function", "(", "...", "allArgs", ")", "{", "const", "boomArgs", "=", "_", ".", "take", "(", "allArgs", ",", "funcDefaultArgs", ".", "length", ")", ";", "let", "result", "=", "func", ".", "call", "(", "null", ",", "...", "boomArgs", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "args", ".", "length", ";", "i", "++", ")", "{", "let", "currArgVal", "=", "allArgs", "[", "i", "+", "funcDefaultArgs", ".", "length", "]", ";", "const", "argDef", "=", "args", "[", "i", "]", ";", "if", "(", "currArgVal", "===", "undefined", ")", "{", "if", "(", "_", ".", "isFunction", "(", "argDef", ".", "default", ")", ")", "{", "result", ".", "output", ".", "payload", "[", "argDef", ".", "name", "]", "=", "argDef", ".", "default", "(", ")", ";", "}", "else", "if", "(", "argDef", ".", "default", ")", "{", "result", ".", "output", ".", "payload", "[", "argDef", ".", "name", "]", "=", "argDef", ".", "default", ";", "}", "}", "else", "{", "result", ".", "output", ".", "payload", "[", "argDef", ".", "name", "]", "=", "currArgVal", ";", "}", "}", "return", "result", ";", "}", ";", "}" ]
This function gets a boom function and arguments in new format and return a wrapped boom function
[ "This", "function", "gets", "a", "boom", "function", "and", "arguments", "in", "new", "format", "and", "return", "a", "wrapped", "boom", "function" ]
38b1469260743b5b083f8ca185786ef74a693844
https://github.com/GiladShoham/seven-boom/blob/38b1469260743b5b083f8ca185786ef74a693844/lib/wrappedBoomFunction.js#L15-L41
train
ILLGrenoble/guacamole-common-js
src/Display.js
__flush_frames
function __flush_frames() { var rendered_frames = 0; // Draw all pending frames, if ready while (rendered_frames < frames.length) { var frame = frames[rendered_frames]; if (!frame.isReady()) break; frame.flush(); rendered_frames++; } // Remove rendered frames from array frames.splice(0, rendered_frames); }
javascript
function __flush_frames() { var rendered_frames = 0; // Draw all pending frames, if ready while (rendered_frames < frames.length) { var frame = frames[rendered_frames]; if (!frame.isReady()) break; frame.flush(); rendered_frames++; } // Remove rendered frames from array frames.splice(0, rendered_frames); }
[ "function", "__flush_frames", "(", ")", "{", "var", "rendered_frames", "=", "0", ";", "while", "(", "rendered_frames", "<", "frames", ".", "length", ")", "{", "var", "frame", "=", "frames", "[", "rendered_frames", "]", ";", "if", "(", "!", "frame", ".", "isReady", "(", ")", ")", "break", ";", "frame", ".", "flush", "(", ")", ";", "rendered_frames", "++", ";", "}", "frames", ".", "splice", "(", "0", ",", "rendered_frames", ")", ";", "}" ]
Flushes all pending frames. @private
[ "Flushes", "all", "pending", "frames", "." ]
71925794155ea3fc37d2a125adbca6f8be532887
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/Display.js#L159-L178
train
ILLGrenoble/guacamole-common-js
src/Display.js
Task
function Task(taskHandler, blocked) { var task = this; /** * Whether this Task is blocked. * * @type {boolean} */ this.blocked = blocked; /** * Unblocks this Task, allowing it to run. */ this.unblock = function() { if (task.blocked) { task.blocked = false; __flush_frames(); } }; /** * Calls the handler associated with this task IMMEDIATELY. This * function does not track whether this task is marked as blocked. * Enforcing the blocked status of tasks is up to the caller. */ this.execute = function() { if (taskHandler) taskHandler(); }; }
javascript
function Task(taskHandler, blocked) { var task = this; /** * Whether this Task is blocked. * * @type {boolean} */ this.blocked = blocked; /** * Unblocks this Task, allowing it to run. */ this.unblock = function() { if (task.blocked) { task.blocked = false; __flush_frames(); } }; /** * Calls the handler associated with this task IMMEDIATELY. This * function does not track whether this task is marked as blocked. * Enforcing the blocked status of tasks is up to the caller. */ this.execute = function() { if (taskHandler) taskHandler(); }; }
[ "function", "Task", "(", "taskHandler", ",", "blocked", ")", "{", "var", "task", "=", "this", ";", "this", ".", "blocked", "=", "blocked", ";", "this", ".", "unblock", "=", "function", "(", ")", "{", "if", "(", "task", ".", "blocked", ")", "{", "task", ".", "blocked", "=", "false", ";", "__flush_frames", "(", ")", ";", "}", "}", ";", "this", ".", "execute", "=", "function", "(", ")", "{", "if", "(", "taskHandler", ")", "taskHandler", "(", ")", ";", "}", ";", "}" ]
A container for an task handler. Each operation which must be ordered is associated with a Task that goes into a task queue. Tasks in this queue are executed in order once their handlers are set, while Tasks without handlers block themselves and any following Tasks from running. @constructor @private @param {function} taskHandler The function to call when this task runs, if any. @param {boolean} blocked Whether this task should start blocked.
[ "A", "container", "for", "an", "task", "handler", ".", "Each", "operation", "which", "must", "be", "ordered", "is", "associated", "with", "a", "Task", "that", "goes", "into", "a", "task", "queue", ".", "Tasks", "in", "this", "queue", "are", "executed", "in", "order", "once", "their", "handlers", "are", "set", "while", "Tasks", "without", "handlers", "block", "themselves", "and", "any", "following", "Tasks", "from", "running", "." ]
71925794155ea3fc37d2a125adbca6f8be532887
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/Display.js#L244-L274
train
ILLGrenoble/guacamole-common-js
src/Display.js
get_children
function get_children(layer) { // Build array of children var children = []; for (var index in layer.children) children.push(layer.children[index]); // Sort children.sort(function children_comparator(a, b) { // Compare based on Z order var diff = a.z - b.z; if (diff !== 0) return diff; // If Z order identical, use document order var a_element = a.getElement(); var b_element = b.getElement(); var position = b_element.compareDocumentPosition(a_element); if (position & Node.DOCUMENT_POSITION_PRECEDING) return -1; if (position & Node.DOCUMENT_POSITION_FOLLOWING) return 1; // Otherwise, assume same return 0; }); // Done return children; }
javascript
function get_children(layer) { // Build array of children var children = []; for (var index in layer.children) children.push(layer.children[index]); // Sort children.sort(function children_comparator(a, b) { // Compare based on Z order var diff = a.z - b.z; if (diff !== 0) return diff; // If Z order identical, use document order var a_element = a.getElement(); var b_element = b.getElement(); var position = b_element.compareDocumentPosition(a_element); if (position & Node.DOCUMENT_POSITION_PRECEDING) return -1; if (position & Node.DOCUMENT_POSITION_FOLLOWING) return 1; // Otherwise, assume same return 0; }); // Done return children; }
[ "function", "get_children", "(", "layer", ")", "{", "var", "children", "=", "[", "]", ";", "for", "(", "var", "index", "in", "layer", ".", "children", ")", "children", ".", "push", "(", "layer", ".", "children", "[", "index", "]", ")", ";", "children", ".", "sort", "(", "function", "children_comparator", "(", "a", ",", "b", ")", "{", "var", "diff", "=", "a", ".", "z", "-", "b", ".", "z", ";", "if", "(", "diff", "!==", "0", ")", "return", "diff", ";", "var", "a_element", "=", "a", ".", "getElement", "(", ")", ";", "var", "b_element", "=", "b", ".", "getElement", "(", ")", ";", "var", "position", "=", "b_element", ".", "compareDocumentPosition", "(", "a_element", ")", ";", "if", "(", "position", "&", "Node", ".", "DOCUMENT_POSITION_PRECEDING", ")", "return", "-", "1", ";", "if", "(", "position", "&", "Node", ".", "DOCUMENT_POSITION_FOLLOWING", ")", "return", "1", ";", "return", "0", ";", "}", ")", ";", "return", "children", ";", "}" ]
Returns sorted array of children
[ "Returns", "sorted", "array", "of", "children" ]
71925794155ea3fc37d2a125adbca6f8be532887
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/Display.js#L1141-L1172
train
ILLGrenoble/guacamole-common-js
src/Display.js
draw_layer
function draw_layer(layer, x, y) { // Draw layer if (layer.width > 0 && layer.height > 0) { // Save and update alpha var initial_alpha = context.globalAlpha; context.globalAlpha *= layer.alpha / 255.0; // Copy data context.drawImage(layer.getCanvas(), x, y); // Draw all children var children = get_children(layer); for (var i=0; i<children.length; i++) { var child = children[i]; draw_layer(child, x + child.x, y + child.y); } // Restore alpha context.globalAlpha = initial_alpha; } }
javascript
function draw_layer(layer, x, y) { // Draw layer if (layer.width > 0 && layer.height > 0) { // Save and update alpha var initial_alpha = context.globalAlpha; context.globalAlpha *= layer.alpha / 255.0; // Copy data context.drawImage(layer.getCanvas(), x, y); // Draw all children var children = get_children(layer); for (var i=0; i<children.length; i++) { var child = children[i]; draw_layer(child, x + child.x, y + child.y); } // Restore alpha context.globalAlpha = initial_alpha; } }
[ "function", "draw_layer", "(", "layer", ",", "x", ",", "y", ")", "{", "if", "(", "layer", ".", "width", ">", "0", "&&", "layer", ".", "height", ">", "0", ")", "{", "var", "initial_alpha", "=", "context", ".", "globalAlpha", ";", "context", ".", "globalAlpha", "*=", "layer", ".", "alpha", "/", "255.0", ";", "context", ".", "drawImage", "(", "layer", ".", "getCanvas", "(", ")", ",", "x", ",", "y", ")", ";", "var", "children", "=", "get_children", "(", "layer", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "children", ".", "length", ";", "i", "++", ")", "{", "var", "child", "=", "children", "[", "i", "]", ";", "draw_layer", "(", "child", ",", "x", "+", "child", ".", "x", ",", "y", "+", "child", ".", "y", ")", ";", "}", "context", ".", "globalAlpha", "=", "initial_alpha", ";", "}", "}" ]
Draws the contents of the given layer at the given coordinates
[ "Draws", "the", "contents", "of", "the", "given", "layer", "at", "the", "given", "coordinates" ]
71925794155ea3fc37d2a125adbca6f8be532887
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/Display.js#L1175-L1199
train
ILLGrenoble/guacamole-common-js
src/AudioPlayer.js
joinAudioPackets
function joinAudioPackets(packets) { // Do not bother joining if one or fewer packets are in the queue if (packets.length <= 1) return packets[0]; // Determine total sample length of the entire queue var totalLength = 0; packets.forEach(function addPacketLengths(packet) { totalLength += packet.length; }); // Append each packet within queue var offset = 0; var joined = new SampleArray(totalLength); packets.forEach(function appendPacket(packet) { joined.set(packet, offset); offset += packet.length; }); return joined; }
javascript
function joinAudioPackets(packets) { // Do not bother joining if one or fewer packets are in the queue if (packets.length <= 1) return packets[0]; // Determine total sample length of the entire queue var totalLength = 0; packets.forEach(function addPacketLengths(packet) { totalLength += packet.length; }); // Append each packet within queue var offset = 0; var joined = new SampleArray(totalLength); packets.forEach(function appendPacket(packet) { joined.set(packet, offset); offset += packet.length; }); return joined; }
[ "function", "joinAudioPackets", "(", "packets", ")", "{", "if", "(", "packets", ".", "length", "<=", "1", ")", "return", "packets", "[", "0", "]", ";", "var", "totalLength", "=", "0", ";", "packets", ".", "forEach", "(", "function", "addPacketLengths", "(", "packet", ")", "{", "totalLength", "+=", "packet", ".", "length", ";", "}", ")", ";", "var", "offset", "=", "0", ";", "var", "joined", "=", "new", "SampleArray", "(", "totalLength", ")", ";", "packets", ".", "forEach", "(", "function", "appendPacket", "(", "packet", ")", "{", "joined", ".", "set", "(", "packet", ",", "offset", ")", ";", "offset", "+=", "packet", ".", "length", ";", "}", ")", ";", "return", "joined", ";", "}" ]
Given an array of audio packets, returns a single audio packet containing the concatenation of those packets. @private @param {SampleArray[]} packets The array of audio packets to concatenate. @returns {SampleArray} A single audio packet containing the concatenation of all given audio packets. If no packets are provided, this will be undefined.
[ "Given", "an", "array", "of", "audio", "packets", "returns", "a", "single", "audio", "packet", "containing", "the", "concatenation", "of", "those", "packets", "." ]
71925794155ea3fc37d2a125adbca6f8be532887
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/AudioPlayer.js#L228-L250
train
ILLGrenoble/guacamole-common-js
src/AudioPlayer.js
splitAudioPacket
function splitAudioPacket(data) { var minValue = Number.MAX_VALUE; var optimalSplitLength = data.length; // Calculate number of whole samples in the provided audio packet AND // in the minimum possible split packet var samples = Math.floor(data.length / format.channels); var minSplitSamples = Math.floor(format.rate * MIN_SPLIT_SIZE); // Calculate the beginning of the "end" of the audio packet var start = Math.max( format.channels * minSplitSamples, format.channels * (samples - minSplitSamples) ); // For all samples at the end of the given packet, find a point where // the perceptible volume across all channels is lowest (and thus is // the optimal point to split) for (var offset = start; offset < data.length; offset += format.channels) { // Calculate the sum of all values across all channels (the result // will be proportional to the average volume of a sample) var totalValue = 0; for (var channel = 0; channel < format.channels; channel++) { totalValue += Math.abs(data[offset + channel]); } // If this is the smallest average value thus far, set the split // length such that the first packet ends with the current sample if (totalValue <= minValue) { optimalSplitLength = offset + format.channels; minValue = totalValue; } } // If packet is not split, return the supplied packet untouched if (optimalSplitLength === data.length) return [data]; // Otherwise, split the packet into two new packets according to the // calculated optimal split length return [ new SampleArray(data.buffer.slice(0, optimalSplitLength * format.bytesPerSample)), new SampleArray(data.buffer.slice(optimalSplitLength * format.bytesPerSample)) ]; }
javascript
function splitAudioPacket(data) { var minValue = Number.MAX_VALUE; var optimalSplitLength = data.length; // Calculate number of whole samples in the provided audio packet AND // in the minimum possible split packet var samples = Math.floor(data.length / format.channels); var minSplitSamples = Math.floor(format.rate * MIN_SPLIT_SIZE); // Calculate the beginning of the "end" of the audio packet var start = Math.max( format.channels * minSplitSamples, format.channels * (samples - minSplitSamples) ); // For all samples at the end of the given packet, find a point where // the perceptible volume across all channels is lowest (and thus is // the optimal point to split) for (var offset = start; offset < data.length; offset += format.channels) { // Calculate the sum of all values across all channels (the result // will be proportional to the average volume of a sample) var totalValue = 0; for (var channel = 0; channel < format.channels; channel++) { totalValue += Math.abs(data[offset + channel]); } // If this is the smallest average value thus far, set the split // length such that the first packet ends with the current sample if (totalValue <= minValue) { optimalSplitLength = offset + format.channels; minValue = totalValue; } } // If packet is not split, return the supplied packet untouched if (optimalSplitLength === data.length) return [data]; // Otherwise, split the packet into two new packets according to the // calculated optimal split length return [ new SampleArray(data.buffer.slice(0, optimalSplitLength * format.bytesPerSample)), new SampleArray(data.buffer.slice(optimalSplitLength * format.bytesPerSample)) ]; }
[ "function", "splitAudioPacket", "(", "data", ")", "{", "var", "minValue", "=", "Number", ".", "MAX_VALUE", ";", "var", "optimalSplitLength", "=", "data", ".", "length", ";", "var", "samples", "=", "Math", ".", "floor", "(", "data", ".", "length", "/", "format", ".", "channels", ")", ";", "var", "minSplitSamples", "=", "Math", ".", "floor", "(", "format", ".", "rate", "*", "MIN_SPLIT_SIZE", ")", ";", "var", "start", "=", "Math", ".", "max", "(", "format", ".", "channels", "*", "minSplitSamples", ",", "format", ".", "channels", "*", "(", "samples", "-", "minSplitSamples", ")", ")", ";", "for", "(", "var", "offset", "=", "start", ";", "offset", "<", "data", ".", "length", ";", "offset", "+=", "format", ".", "channels", ")", "{", "var", "totalValue", "=", "0", ";", "for", "(", "var", "channel", "=", "0", ";", "channel", "<", "format", ".", "channels", ";", "channel", "++", ")", "{", "totalValue", "+=", "Math", ".", "abs", "(", "data", "[", "offset", "+", "channel", "]", ")", ";", "}", "if", "(", "totalValue", "<=", "minValue", ")", "{", "optimalSplitLength", "=", "offset", "+", "format", ".", "channels", ";", "minValue", "=", "totalValue", ";", "}", "}", "if", "(", "optimalSplitLength", "===", "data", ".", "length", ")", "return", "[", "data", "]", ";", "return", "[", "new", "SampleArray", "(", "data", ".", "buffer", ".", "slice", "(", "0", ",", "optimalSplitLength", "*", "format", ".", "bytesPerSample", ")", ")", ",", "new", "SampleArray", "(", "data", ".", "buffer", ".", "slice", "(", "optimalSplitLength", "*", "format", ".", "bytesPerSample", ")", ")", "]", ";", "}" ]
Given a single packet of audio data, splits off an arbitrary length of audio data from the beginning of that packet, returning the split result as an array of two packets. The split location is determined through an algorithm intended to minimize the liklihood of audible clicking between packets. If no such split location is possible, an array containing only the originally-provided audio packet is returned. @private @param {SampleArray} data The audio packet to split. @returns {SampleArray[]} An array of audio packets containing the result of splitting the provided audio packet. If splitting is possible, this array will contain two packets. If splitting is not possible, this array will contain only the originally-provided packet.
[ "Given", "a", "single", "packet", "of", "audio", "data", "splits", "off", "an", "arbitrary", "length", "of", "audio", "data", "from", "the", "beginning", "of", "that", "packet", "returning", "the", "split", "result", "as", "an", "array", "of", "two", "packets", ".", "The", "split", "location", "is", "determined", "through", "an", "algorithm", "intended", "to", "minimize", "the", "liklihood", "of", "audible", "clicking", "between", "packets", ".", "If", "no", "such", "split", "location", "is", "possible", "an", "array", "containing", "only", "the", "originally", "-", "provided", "audio", "packet", "is", "returned", "." ]
71925794155ea3fc37d2a125adbca6f8be532887
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/AudioPlayer.js#L270-L318
train
ILLGrenoble/guacamole-common-js
src/AudioPlayer.js
toAudioBuffer
function toAudioBuffer(data) { // Calculate total number of samples var samples = data.length / format.channels; // Determine exactly when packet CAN play var packetTime = context.currentTime; if (nextPacketTime < packetTime) nextPacketTime = packetTime; // Get audio buffer for specified format var audioBuffer = context.createBuffer(format.channels, samples, format.rate); // Convert each channel for (var channel = 0; channel < format.channels; channel++) { var audioData = audioBuffer.getChannelData(channel); // Fill audio buffer with data for channel var offset = channel; for (var i = 0; i < samples; i++) { audioData[i] = data[offset] / maxSampleValue; offset += format.channels; } } return audioBuffer; }
javascript
function toAudioBuffer(data) { // Calculate total number of samples var samples = data.length / format.channels; // Determine exactly when packet CAN play var packetTime = context.currentTime; if (nextPacketTime < packetTime) nextPacketTime = packetTime; // Get audio buffer for specified format var audioBuffer = context.createBuffer(format.channels, samples, format.rate); // Convert each channel for (var channel = 0; channel < format.channels; channel++) { var audioData = audioBuffer.getChannelData(channel); // Fill audio buffer with data for channel var offset = channel; for (var i = 0; i < samples; i++) { audioData[i] = data[offset] / maxSampleValue; offset += format.channels; } } return audioBuffer; }
[ "function", "toAudioBuffer", "(", "data", ")", "{", "var", "samples", "=", "data", ".", "length", "/", "format", ".", "channels", ";", "var", "packetTime", "=", "context", ".", "currentTime", ";", "if", "(", "nextPacketTime", "<", "packetTime", ")", "nextPacketTime", "=", "packetTime", ";", "var", "audioBuffer", "=", "context", ".", "createBuffer", "(", "format", ".", "channels", ",", "samples", ",", "format", ".", "rate", ")", ";", "for", "(", "var", "channel", "=", "0", ";", "channel", "<", "format", ".", "channels", ";", "channel", "++", ")", "{", "var", "audioData", "=", "audioBuffer", ".", "getChannelData", "(", "channel", ")", ";", "var", "offset", "=", "channel", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "samples", ";", "i", "++", ")", "{", "audioData", "[", "i", "]", "=", "data", "[", "offset", "]", "/", "maxSampleValue", ";", "offset", "+=", "format", ".", "channels", ";", "}", "}", "return", "audioBuffer", ";", "}" ]
Converts the given audio packet into an AudioBuffer, ready for playback by the Web Audio API. Unlike the raw audio packets received by this audio player, AudioBuffers require floating point samples and are split into isolated planes of channel-specific data. @private @param {SampleArray} data The raw audio packet that should be converted into a Web Audio API AudioBuffer. @returns {AudioBuffer} A new Web Audio API AudioBuffer containing the provided audio data, converted to the format used by the Web Audio API.
[ "Converts", "the", "given", "audio", "packet", "into", "an", "AudioBuffer", "ready", "for", "playback", "by", "the", "Web", "Audio", "API", ".", "Unlike", "the", "raw", "audio", "packets", "received", "by", "this", "audio", "player", "AudioBuffers", "require", "floating", "point", "samples", "and", "are", "split", "into", "isolated", "planes", "of", "channel", "-", "specific", "data", "." ]
71925794155ea3fc37d2a125adbca6f8be532887
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/AudioPlayer.js#L378-L407
train
kibertoad/objection-swagger
lib/enrichers/schema.relationships.enricher.js
enrichSchemaWithRelationships
function enrichSchemaWithRelationships( schema, relationships, isIncludeParentRelationships, fromModelClass ) { const processedSchema = _.cloneDeep(schema); _.forOwn(relationships, (value, key) => { let relationshipValue; if (value.relation.name === constants.HasOneRelation) { //protect from endless recursion const modelProperties = value.modelClass !== fromModelClass ? _resolveModelProperties( value.modelClass, true, isIncludeParentRelationships ) : { type: "object" }; relationshipValue = { ...modelProperties }; } else if ( isIncludeParentRelationships && value.relation.name === constants.BelongsToOneRelation ) { //protect from endless recursion const modelProperties = value.modelClass !== fromModelClass ? _resolveModelProperties( value.modelClass, false, isIncludeParentRelationships ) : { type: "object" }; relationshipValue = { ...modelProperties }; } else if (value.relation.name === constants.HasManyRelation) { //protect from endless recursion const modelProperties = value.modelClass !== fromModelClass ? _resolveModelProperties( value.modelClass, true, isIncludeParentRelationships ) : { type: "object" }; relationshipValue = { type: "array", items: { ...modelProperties } }; } else if ( isIncludeParentRelationships && value.relation.name === constants.ManyToManyRelation ) { //protect from endless recursion const modelProperties = value.modelClass !== fromModelClass ? _resolveModelProperties( value.modelClass, false, isIncludeParentRelationships ) : { type: "object" }; relationshipValue = { type: "array", items: { ...modelProperties } }; } if (relationshipValue) { processedSchema.properties[key] = relationshipValue; } }); return processedSchema; }
javascript
function enrichSchemaWithRelationships( schema, relationships, isIncludeParentRelationships, fromModelClass ) { const processedSchema = _.cloneDeep(schema); _.forOwn(relationships, (value, key) => { let relationshipValue; if (value.relation.name === constants.HasOneRelation) { //protect from endless recursion const modelProperties = value.modelClass !== fromModelClass ? _resolveModelProperties( value.modelClass, true, isIncludeParentRelationships ) : { type: "object" }; relationshipValue = { ...modelProperties }; } else if ( isIncludeParentRelationships && value.relation.name === constants.BelongsToOneRelation ) { //protect from endless recursion const modelProperties = value.modelClass !== fromModelClass ? _resolveModelProperties( value.modelClass, false, isIncludeParentRelationships ) : { type: "object" }; relationshipValue = { ...modelProperties }; } else if (value.relation.name === constants.HasManyRelation) { //protect from endless recursion const modelProperties = value.modelClass !== fromModelClass ? _resolveModelProperties( value.modelClass, true, isIncludeParentRelationships ) : { type: "object" }; relationshipValue = { type: "array", items: { ...modelProperties } }; } else if ( isIncludeParentRelationships && value.relation.name === constants.ManyToManyRelation ) { //protect from endless recursion const modelProperties = value.modelClass !== fromModelClass ? _resolveModelProperties( value.modelClass, false, isIncludeParentRelationships ) : { type: "object" }; relationshipValue = { type: "array", items: { ...modelProperties } }; } if (relationshipValue) { processedSchema.properties[key] = relationshipValue; } }); return processedSchema; }
[ "function", "enrichSchemaWithRelationships", "(", "schema", ",", "relationships", ",", "isIncludeParentRelationships", ",", "fromModelClass", ")", "{", "const", "processedSchema", "=", "_", ".", "cloneDeep", "(", "schema", ")", ";", "_", ".", "forOwn", "(", "relationships", ",", "(", "value", ",", "key", ")", "=>", "{", "let", "relationshipValue", ";", "if", "(", "value", ".", "relation", ".", "name", "===", "constants", ".", "HasOneRelation", ")", "{", "const", "modelProperties", "=", "value", ".", "modelClass", "!==", "fromModelClass", "?", "_resolveModelProperties", "(", "value", ".", "modelClass", ",", "true", ",", "isIncludeParentRelationships", ")", ":", "{", "type", ":", "\"object\"", "}", ";", "relationshipValue", "=", "{", "...", "modelProperties", "}", ";", "}", "else", "if", "(", "isIncludeParentRelationships", "&&", "value", ".", "relation", ".", "name", "===", "constants", ".", "BelongsToOneRelation", ")", "{", "const", "modelProperties", "=", "value", ".", "modelClass", "!==", "fromModelClass", "?", "_resolveModelProperties", "(", "value", ".", "modelClass", ",", "false", ",", "isIncludeParentRelationships", ")", ":", "{", "type", ":", "\"object\"", "}", ";", "relationshipValue", "=", "{", "...", "modelProperties", "}", ";", "}", "else", "if", "(", "value", ".", "relation", ".", "name", "===", "constants", ".", "HasManyRelation", ")", "{", "const", "modelProperties", "=", "value", ".", "modelClass", "!==", "fromModelClass", "?", "_resolveModelProperties", "(", "value", ".", "modelClass", ",", "true", ",", "isIncludeParentRelationships", ")", ":", "{", "type", ":", "\"object\"", "}", ";", "relationshipValue", "=", "{", "type", ":", "\"array\"", ",", "items", ":", "{", "...", "modelProperties", "}", "}", ";", "}", "else", "if", "(", "isIncludeParentRelationships", "&&", "value", ".", "relation", ".", "name", "===", "constants", ".", "ManyToManyRelation", ")", "{", "const", "modelProperties", "=", "value", ".", "modelClass", "!==", "fromModelClass", "?", "_resolveModelProperties", "(", "value", ".", "modelClass", ",", "false", ",", "isIncludeParentRelationships", ")", ":", "{", "type", ":", "\"object\"", "}", ";", "relationshipValue", "=", "{", "type", ":", "\"array\"", ",", "items", ":", "{", "...", "modelProperties", "}", "}", ";", "}", "if", "(", "relationshipValue", ")", "{", "processedSchema", ".", "properties", "[", "key", "]", "=", "relationshipValue", ";", "}", "}", ")", ";", "return", "processedSchema", ";", "}" ]
Creates copy of provided schema and enriches it with attributes that are derived from relationships @param {Object} schema - JSON Schema @param {Object} relationships - Objection.js relationMappings @param {boolean} isIncludeParentRelationships - whether ManyToManyRelation and BelongsToOneRelation relationships should be included @param {Object} [fromModelClass] - model class from which enrichment was initiated @returns {Object} JSON Schema object
[ "Creates", "copy", "of", "provided", "schema", "and", "enriches", "it", "with", "attributes", "that", "are", "derived", "from", "relationships" ]
2109b58ce323e78252729a46bcc94e617035b541
https://github.com/kibertoad/objection-swagger/blob/2109b58ce323e78252729a46bcc94e617035b541/lib/enrichers/schema.relationships.enricher.js#L12-L93
train
aMarCruz/jspreproc
spec/uglify/core.js
mktag
function mktag(name, html, css, attrs, js, pcex) { var c = ', ', s = '}' + (pcex.length ? ', ' + q(pcex._bp[8]) : '') + ');' // give more consistency to the output if (js && js.slice(-1) !== '\n') s = '\n' + s return 'riot.tag2(\'' + name + "'" + c + q(html) + c + q(css) + c + q(attrs) + ', function(opts) {\n' + js + s }
javascript
function mktag(name, html, css, attrs, js, pcex) { var c = ', ', s = '}' + (pcex.length ? ', ' + q(pcex._bp[8]) : '') + ');' // give more consistency to the output if (js && js.slice(-1) !== '\n') s = '\n' + s return 'riot.tag2(\'' + name + "'" + c + q(html) + c + q(css) + c + q(attrs) + ', function(opts) {\n' + js + s }
[ "function", "mktag", "(", "name", ",", "html", ",", "css", ",", "attrs", ",", "js", ",", "pcex", ")", "{", "var", "c", "=", "', '", ",", "s", "=", "'}'", "+", "(", "pcex", ".", "length", "?", "', '", "+", "q", "(", "pcex", ".", "_bp", "[", "8", "]", ")", ":", "''", ")", "+", "');'", "if", "(", "js", "&&", "js", ".", "slice", "(", "-", "1", ")", "!==", "'\\n'", ")", "\\n", "s", "=", "'\\n'", "+", "\\n", "}" ]
Generates the `riot.tag2` call with the processed parts.
[ "Generates", "the", "riot", ".", "tag2", "call", "with", "the", "processed", "parts", "." ]
5f31820d702a329e8aa25f0f3983f13097610250
https://github.com/aMarCruz/jspreproc/blob/5f31820d702a329e8aa25f0f3983f13097610250/spec/uglify/core.js#L57-L67
train
aMarCruz/jspreproc
spec/uglify/core.js
parseAttrs
function parseAttrs(str, pcex) { var list = [], match, k, v, t, e, DQ = '"' HTML_ATTR.lastIndex = 0 str = str.replace(/\s+/g, ' ') while (match = HTML_ATTR.exec(str)) { // all attribute names are converted to lower case k = match[1].toLowerCase() v = match[2] if (!v) { list.push(k) // boolean attribute without explicit value } else { // attribute values must be enclosed in double quotes if (v[0] !== DQ) v = DQ + (v[0] === "'" ? v.slice(1, -1) : v) + DQ if (k === 'type' && SPEC_TYPES.test(v)) { t = v } else { if (/\u0001\d/.test(v)) { // renames special attributes with expressiones in their value. if (k === 'value') e = 1 else if (BOOL_ATTRS.test(k)) k = '__' + k else if (~RIOT_ATTRS.indexOf(k)) k = 'riot-' + k } // join the key-value pair, with no spaces between the parts list.push(k + '=' + v) } } } // update() will evaluate `type` after the value, avoiding warnings if (t) { if (e) t = DQ + pcex._bp[0] + "'" + v.slice(1, -1) + "'" + pcex._bp[1] + DQ list.push('type=' + t) } return list.join(' ') // returns the attribute list }
javascript
function parseAttrs(str, pcex) { var list = [], match, k, v, t, e, DQ = '"' HTML_ATTR.lastIndex = 0 str = str.replace(/\s+/g, ' ') while (match = HTML_ATTR.exec(str)) { // all attribute names are converted to lower case k = match[1].toLowerCase() v = match[2] if (!v) { list.push(k) // boolean attribute without explicit value } else { // attribute values must be enclosed in double quotes if (v[0] !== DQ) v = DQ + (v[0] === "'" ? v.slice(1, -1) : v) + DQ if (k === 'type' && SPEC_TYPES.test(v)) { t = v } else { if (/\u0001\d/.test(v)) { // renames special attributes with expressiones in their value. if (k === 'value') e = 1 else if (BOOL_ATTRS.test(k)) k = '__' + k else if (~RIOT_ATTRS.indexOf(k)) k = 'riot-' + k } // join the key-value pair, with no spaces between the parts list.push(k + '=' + v) } } } // update() will evaluate `type` after the value, avoiding warnings if (t) { if (e) t = DQ + pcex._bp[0] + "'" + v.slice(1, -1) + "'" + pcex._bp[1] + DQ list.push('type=' + t) } return list.join(' ') // returns the attribute list }
[ "function", "parseAttrs", "(", "str", ",", "pcex", ")", "{", "var", "list", "=", "[", "]", ",", "match", ",", "k", ",", "v", ",", "t", ",", "e", ",", "DQ", "=", "'\"'", "HTML_ATTR", ".", "lastIndex", "=", "0", "str", "=", "str", ".", "replace", "(", "/", "\\s+", "/", "g", ",", "' '", ")", "while", "(", "match", "=", "HTML_ATTR", ".", "exec", "(", "str", ")", ")", "{", "k", "=", "match", "[", "1", "]", ".", "toLowerCase", "(", ")", "v", "=", "match", "[", "2", "]", "if", "(", "!", "v", ")", "{", "list", ".", "push", "(", "k", ")", "}", "else", "{", "if", "(", "v", "[", "0", "]", "!==", "DQ", ")", "v", "=", "DQ", "+", "(", "v", "[", "0", "]", "===", "\"'\"", "?", "v", ".", "slice", "(", "1", ",", "-", "1", ")", ":", "v", ")", "+", "DQ", "if", "(", "k", "===", "'type'", "&&", "SPEC_TYPES", ".", "test", "(", "v", ")", ")", "{", "t", "=", "v", "}", "else", "{", "if", "(", "/", "\\u0001\\d", "/", ".", "test", "(", "v", ")", ")", "{", "if", "(", "k", "===", "'value'", ")", "e", "=", "1", "else", "if", "(", "BOOL_ATTRS", ".", "test", "(", "k", ")", ")", "k", "=", "'__'", "+", "k", "else", "if", "(", "~", "RIOT_ATTRS", ".", "indexOf", "(", "k", ")", ")", "k", "=", "'riot-'", "+", "k", "}", "list", ".", "push", "(", "k", "+", "'='", "+", "v", ")", "}", "}", "}", "if", "(", "t", ")", "{", "if", "(", "e", ")", "t", "=", "DQ", "+", "pcex", ".", "_bp", "[", "0", "]", "+", "\"'\"", "+", "v", ".", "slice", "(", "1", ",", "-", "1", ")", "+", "\"'\"", "+", "pcex", ".", "_bp", "[", "1", "]", "+", "DQ", "list", ".", "push", "(", "'type='", "+", "t", ")", "}", "return", "list", ".", "join", "(", "' '", ")", "}" ]
Parses and format attributes. @param {string} str - Attributes, with expressions replaced by their hash @param {Array} pcex - Has a _bp property with info about brackets @returns {string} Formated attributes
[ "Parses", "and", "format", "attributes", "." ]
5f31820d702a329e8aa25f0f3983f13097610250
https://github.com/aMarCruz/jspreproc/blob/5f31820d702a329e8aa25f0f3983f13097610250/spec/uglify/core.js#L96-L142
train
aMarCruz/jspreproc
spec/uglify/core.js
splitHtml
function splitHtml(html, opts, pcex) { var _bp = pcex._bp // `brackets.split` is a heavy function, so don't call it if not necessary if (html && _bp[4].test(html)) { var jsfn = opts.expr && (opts.parser || opts.type) ? _compileJS : 0, list = brackets.split(html, 0, _bp), expr for (var i = 1; i < list.length; i += 2) { expr = list[i] if (expr[0] === '^') expr = expr.slice(1) else if (jsfn) { var israw = expr[0] === '=' expr = jsfn(israw ? expr.slice(1) : expr, opts).trim() if (expr.slice(-1) === ';') expr = expr.slice(0, -1) if (israw) expr = '=' + expr } list[i] = '\u0001' + (pcex.push(expr.replace(/[\r\n]+/g, ' ').trim()) - 1) + _bp[1] } html = list.join('') } return html }
javascript
function splitHtml(html, opts, pcex) { var _bp = pcex._bp // `brackets.split` is a heavy function, so don't call it if not necessary if (html && _bp[4].test(html)) { var jsfn = opts.expr && (opts.parser || opts.type) ? _compileJS : 0, list = brackets.split(html, 0, _bp), expr for (var i = 1; i < list.length; i += 2) { expr = list[i] if (expr[0] === '^') expr = expr.slice(1) else if (jsfn) { var israw = expr[0] === '=' expr = jsfn(israw ? expr.slice(1) : expr, opts).trim() if (expr.slice(-1) === ';') expr = expr.slice(0, -1) if (israw) expr = '=' + expr } list[i] = '\u0001' + (pcex.push(expr.replace(/[\r\n]+/g, ' ').trim()) - 1) + _bp[1] } html = list.join('') } return html }
[ "function", "splitHtml", "(", "html", ",", "opts", ",", "pcex", ")", "{", "var", "_bp", "=", "pcex", ".", "_bp", "if", "(", "html", "&&", "_bp", "[", "4", "]", ".", "test", "(", "html", ")", ")", "{", "var", "jsfn", "=", "opts", ".", "expr", "&&", "(", "opts", ".", "parser", "||", "opts", ".", "type", ")", "?", "_compileJS", ":", "0", ",", "list", "=", "brackets", ".", "split", "(", "html", ",", "0", ",", "_bp", ")", ",", "expr", "for", "(", "var", "i", "=", "1", ";", "i", "<", "list", ".", "length", ";", "i", "+=", "2", ")", "{", "expr", "=", "list", "[", "i", "]", "if", "(", "expr", "[", "0", "]", "===", "'^'", ")", "expr", "=", "expr", ".", "slice", "(", "1", ")", "else", "if", "(", "jsfn", ")", "{", "var", "israw", "=", "expr", "[", "0", "]", "===", "'='", "expr", "=", "jsfn", "(", "israw", "?", "expr", ".", "slice", "(", "1", ")", ":", "expr", ",", "opts", ")", ".", "trim", "(", ")", "if", "(", "expr", ".", "slice", "(", "-", "1", ")", "===", "';'", ")", "expr", "=", "expr", ".", "slice", "(", "0", ",", "-", "1", ")", "if", "(", "israw", ")", "expr", "=", "'='", "+", "expr", "}", "list", "[", "i", "]", "=", "'\\u0001'", "+", "\\u0001", "+", "(", "pcex", ".", "push", "(", "expr", ".", "replace", "(", "/", "[\\r\\n]+", "/", "g", ",", "' '", ")", ".", "trim", "(", ")", ")", "-", "1", ")", "}", "_bp", "[", "1", "]", "}", "html", "=", "list", ".", "join", "(", "''", ")", "}" ]
Replaces expressions in the HTML with a marker, and runs expressions through the parser, except those beginning with `{^`.
[ "Replaces", "expressions", "in", "the", "HTML", "with", "a", "marker", "and", "runs", "expressions", "through", "the", "parser", "except", "those", "beginning", "with", "{", "^", "." ]
5f31820d702a329e8aa25f0f3983f13097610250
https://github.com/aMarCruz/jspreproc/blob/5f31820d702a329e8aa25f0f3983f13097610250/spec/uglify/core.js#L146-L171
train
aMarCruz/jspreproc
spec/uglify/core.js
restoreExpr
function restoreExpr(html, pcex) { if (pcex.length) { html = html .replace(/\u0001(\d+)/g, function (_, d) { var expr = pcex[d] if (expr[0] === '=') { expr = expr.replace(brackets.R_STRINGS, function (qs) { return qs //.replace(/&/g, '&amp;') // I don't know if this make sense .replace(/</g, '&lt;') .replace(/>/g, '&gt;') }) } return pcex._bp[0] + expr.replace(/"/g, '\u2057') }) } return html }
javascript
function restoreExpr(html, pcex) { if (pcex.length) { html = html .replace(/\u0001(\d+)/g, function (_, d) { var expr = pcex[d] if (expr[0] === '=') { expr = expr.replace(brackets.R_STRINGS, function (qs) { return qs //.replace(/&/g, '&amp;') // I don't know if this make sense .replace(/</g, '&lt;') .replace(/>/g, '&gt;') }) } return pcex._bp[0] + expr.replace(/"/g, '\u2057') }) } return html }
[ "function", "restoreExpr", "(", "html", ",", "pcex", ")", "{", "if", "(", "pcex", ".", "length", ")", "{", "html", "=", "html", ".", "replace", "(", "/", "\\u0001(\\d+)", "/", "g", ",", "function", "(", "_", ",", "d", ")", "{", "var", "expr", "=", "pcex", "[", "d", "]", "if", "(", "expr", "[", "0", "]", "===", "'='", ")", "{", "expr", "=", "expr", ".", "replace", "(", "brackets", ".", "R_STRINGS", ",", "function", "(", "qs", ")", "{", "return", "qs", ".", "replace", "(", "/", "<", "/", "g", ",", "'&lt;'", ")", ".", "replace", "(", "/", ">", "/", "g", ",", "'&gt;'", ")", "}", ")", "}", "return", "pcex", ".", "_bp", "[", "0", "]", "+", "expr", ".", "replace", "(", "/", "\"", "/", "g", ",", "'\\u2057'", ")", "}", ")", "}", "\\u2057", "}" ]
Restores expressions hidden by splitHtml and escape literal internal brackets
[ "Restores", "expressions", "hidden", "by", "splitHtml", "and", "escape", "literal", "internal", "brackets" ]
5f31820d702a329e8aa25f0f3983f13097610250
https://github.com/aMarCruz/jspreproc/blob/5f31820d702a329e8aa25f0f3983f13097610250/spec/uglify/core.js#L174-L190
train
aMarCruz/jspreproc
spec/uglify/core.js
compileHTML
function compileHTML(html, opts, pcex) { if (Array.isArray(opts)) { pcex = opts opts = {} } else { if (!pcex) pcex = [] if (!opts) opts = {} } html = html.replace(/\r\n?/g, '\n').replace(HTML_COMMENT, function (s) { return s[0] === '<' ? '' : s }).replace(TRIM_TRAIL, '') // `_bp` is undefined when `compileHTML` is not called by compile if (!pcex._bp) pcex._bp = brackets.array(opts.brackets) return _compileHTML(html, opts, pcex) }
javascript
function compileHTML(html, opts, pcex) { if (Array.isArray(opts)) { pcex = opts opts = {} } else { if (!pcex) pcex = [] if (!opts) opts = {} } html = html.replace(/\r\n?/g, '\n').replace(HTML_COMMENT, function (s) { return s[0] === '<' ? '' : s }).replace(TRIM_TRAIL, '') // `_bp` is undefined when `compileHTML` is not called by compile if (!pcex._bp) pcex._bp = brackets.array(opts.brackets) return _compileHTML(html, opts, pcex) }
[ "function", "compileHTML", "(", "html", ",", "opts", ",", "pcex", ")", "{", "if", "(", "Array", ".", "isArray", "(", "opts", ")", ")", "{", "pcex", "=", "opts", "opts", "=", "{", "}", "}", "else", "{", "if", "(", "!", "pcex", ")", "pcex", "=", "[", "]", "if", "(", "!", "opts", ")", "opts", "=", "{", "}", "}", "html", "=", "html", ".", "replace", "(", "/", "\\r\\n?", "/", "g", ",", "'\\n'", ")", ".", "\\n", "replace", ".", "(", "HTML_COMMENT", ",", "function", "(", "s", ")", "{", "return", "s", "[", "0", "]", "===", "'<'", "?", "''", ":", "s", "}", ")", "replace", "(", "TRIM_TRAIL", ",", "''", ")", "if", "(", "!", "pcex", ".", "_bp", ")", "pcex", ".", "_bp", "=", "brackets", ".", "array", "(", "opts", ".", "brackets", ")", "}" ]
Parses and formats the HTML text. @param {string} html - Can contain embedded HTML comments and literal whitespace @param {Object} opts - Collected user options. Includes the brackets array in `_bp` @param {Array} [pcex] - Keeps precompiled expressions @returns {string} The parsed HTML text @see http://www.w3.org/TR/html5/syntax.html istanbul ignore next
[ "Parses", "and", "formats", "the", "HTML", "text", "." ]
5f31820d702a329e8aa25f0f3983f13097610250
https://github.com/aMarCruz/jspreproc/blob/5f31820d702a329e8aa25f0f3983f13097610250/spec/uglify/core.js#L248-L265
train
aMarCruz/jspreproc
spec/uglify/core.js
riotjs
function riotjs(js) { var match, toes5, parts = [], // parsed code pos // remove comments js = js.replace(JS_RMCOMMS, function (m, q) { return q ? m : ' ' }) // $1: indentation, // $2: method name, // $3: parameters while (match = js.match(JS_ES6SIGN)) { // save remaining part now -- IE9 changes `rightContext` in `RegExp.test` parts.push(RegExp.leftContext) js = RegExp.rightContext pos = skipBlock(js) // find the closing bracket // convert ES6 method signature to ES5 function toes5 = !/^(?:if|while|for|switch|catch|function)$/.test(match[2]) if (toes5) match[0] = match[1] + 'this.' + match[2] + ' = function' + match[3] parts.push(match[0], js.slice(0, pos)) js = js.slice(pos) if (toes5 && !/^\s*.\s*bind\b/.test(js)) parts.push('.bind(this)') } return parts.length ? parts.join('') + js : js // Inner helper - find the position following the closing bracket for the current block function skipBlock(str) { var re = _regEx('([{}])|' + brackets.S_QBLOCKS, 'g'), level = 1, match while (level && (match = re.exec(str))) { if (match[1]) match[1] === '{' ? ++level : --level } return level ? str.length : re.lastIndex } }
javascript
function riotjs(js) { var match, toes5, parts = [], // parsed code pos // remove comments js = js.replace(JS_RMCOMMS, function (m, q) { return q ? m : ' ' }) // $1: indentation, // $2: method name, // $3: parameters while (match = js.match(JS_ES6SIGN)) { // save remaining part now -- IE9 changes `rightContext` in `RegExp.test` parts.push(RegExp.leftContext) js = RegExp.rightContext pos = skipBlock(js) // find the closing bracket // convert ES6 method signature to ES5 function toes5 = !/^(?:if|while|for|switch|catch|function)$/.test(match[2]) if (toes5) match[0] = match[1] + 'this.' + match[2] + ' = function' + match[3] parts.push(match[0], js.slice(0, pos)) js = js.slice(pos) if (toes5 && !/^\s*.\s*bind\b/.test(js)) parts.push('.bind(this)') } return parts.length ? parts.join('') + js : js // Inner helper - find the position following the closing bracket for the current block function skipBlock(str) { var re = _regEx('([{}])|' + brackets.S_QBLOCKS, 'g'), level = 1, match while (level && (match = re.exec(str))) { if (match[1]) match[1] === '{' ? ++level : --level } return level ? str.length : re.lastIndex } }
[ "function", "riotjs", "(", "js", ")", "{", "var", "match", ",", "toes5", ",", "parts", "=", "[", "]", ",", "pos", "js", "=", "js", ".", "replace", "(", "JS_RMCOMMS", ",", "function", "(", "m", ",", "q", ")", "{", "return", "q", "?", "m", ":", "' '", "}", ")", "while", "(", "match", "=", "js", ".", "match", "(", "JS_ES6SIGN", ")", ")", "{", "parts", ".", "push", "(", "RegExp", ".", "leftContext", ")", "js", "=", "RegExp", ".", "rightContext", "pos", "=", "skipBlock", "(", "js", ")", "toes5", "=", "!", "/", "^(?:if|while|for|switch|catch|function)$", "/", ".", "test", "(", "match", "[", "2", "]", ")", "if", "(", "toes5", ")", "match", "[", "0", "]", "=", "match", "[", "1", "]", "+", "'this.'", "+", "match", "[", "2", "]", "+", "' = function'", "+", "match", "[", "3", "]", "parts", ".", "push", "(", "match", "[", "0", "]", ",", "js", ".", "slice", "(", "0", ",", "pos", ")", ")", "js", "=", "js", ".", "slice", "(", "pos", ")", "if", "(", "toes5", "&&", "!", "/", "^\\s*.\\s*bind\\b", "/", ".", "test", "(", "js", ")", ")", "parts", ".", "push", "(", "'.bind(this)'", ")", "}", "return", "parts", ".", "length", "?", "parts", ".", "join", "(", "''", ")", "+", "js", ":", "js", "function", "skipBlock", "(", "str", ")", "{", "var", "re", "=", "_regEx", "(", "'([{}])|'", "+", "brackets", ".", "S_QBLOCKS", ",", "'g'", ")", ",", "level", "=", "1", ",", "match", "while", "(", "level", "&&", "(", "match", "=", "re", ".", "exec", "(", "str", ")", ")", ")", "{", "if", "(", "match", "[", "1", "]", ")", "match", "[", "1", "]", "===", "'{'", "?", "++", "level", ":", "--", "level", "}", "return", "level", "?", "str", ".", "length", ":", "re", ".", "lastIndex", "}", "}" ]
Default parser for JavaScript code
[ "Default", "parser", "for", "JavaScript", "code" ]
5f31820d702a329e8aa25f0f3983f13097610250
https://github.com/aMarCruz/jspreproc/blob/5f31820d702a329e8aa25f0f3983f13097610250/spec/uglify/core.js#L278-L323
train
ascartabelli/lamb
src/privates/_groupWith.js
_groupWith
function _groupWith (makeValue) { return function (arrayLike, iteratee) { var result = {}; var len = arrayLike.length; for (var i = 0, element, key; i < len; i++) { element = arrayLike[i]; key = iteratee(element, i, arrayLike); result[key] = makeValue(result[key], element); } return result; }; }
javascript
function _groupWith (makeValue) { return function (arrayLike, iteratee) { var result = {}; var len = arrayLike.length; for (var i = 0, element, key; i < len; i++) { element = arrayLike[i]; key = iteratee(element, i, arrayLike); result[key] = makeValue(result[key], element); } return result; }; }
[ "function", "_groupWith", "(", "makeValue", ")", "{", "return", "function", "(", "arrayLike", ",", "iteratee", ")", "{", "var", "result", "=", "{", "}", ";", "var", "len", "=", "arrayLike", ".", "length", ";", "for", "(", "var", "i", "=", "0", ",", "element", ",", "key", ";", "i", "<", "len", ";", "i", "++", ")", "{", "element", "=", "arrayLike", "[", "i", "]", ";", "key", "=", "iteratee", "(", "element", ",", "i", ",", "arrayLike", ")", ";", "result", "[", "key", "]", "=", "makeValue", "(", "result", "[", "key", "]", ",", "element", ")", ";", "}", "return", "result", ";", "}", ";", "}" ]
Builds a "grouping function" for an array-like object. @private @param {Function} makeValue @returns {Function}
[ "Builds", "a", "grouping", "function", "for", "an", "array", "-", "like", "object", "." ]
d36e45945c4789e4f1a2d8805936514b53f32362
https://github.com/ascartabelli/lamb/blob/d36e45945c4789e4f1a2d8805936514b53f32362/src/privates/_groupWith.js#L7-L20
train
ascartabelli/lamb
src/privates/_curry3.js
_curry3
function _curry3 (fn, isRightCurry) { return function (a) { return function (b) { return function (c) { return isRightCurry ? fn.call(this, c, b, a) : fn.call(this, a, b, c); }; }; }; }
javascript
function _curry3 (fn, isRightCurry) { return function (a) { return function (b) { return function (c) { return isRightCurry ? fn.call(this, c, b, a) : fn.call(this, a, b, c); }; }; }; }
[ "function", "_curry3", "(", "fn", ",", "isRightCurry", ")", "{", "return", "function", "(", "a", ")", "{", "return", "function", "(", "b", ")", "{", "return", "function", "(", "c", ")", "{", "return", "isRightCurry", "?", "fn", ".", "call", "(", "this", ",", "c", ",", "b", ",", "a", ")", ":", "fn", ".", "call", "(", "this", ",", "a", ",", "b", ",", "c", ")", ";", "}", ";", "}", ";", "}", ";", "}" ]
Curries a function of arity 3. @private @param {Function} fn @param {Boolean} [isRightCurry=false] @returns {Function}
[ "Curries", "a", "function", "of", "arity", "3", "." ]
d36e45945c4789e4f1a2d8805936514b53f32362
https://github.com/ascartabelli/lamb/blob/d36e45945c4789e4f1a2d8805936514b53f32362/src/privates/_curry3.js#L8-L16
train
ILLGrenoble/guacamole-common-js
src/AudioContextFactory.js
getAudioContext
function getAudioContext() { // Fallback to Webkit-specific AudioContext implementation var AudioContext = window.AudioContext || window.webkitAudioContext; // Get new AudioContext instance if Web Audio API is supported if (AudioContext) { try { // Create new instance if none yet exists if (!Guacamole.AudioContextFactory.singleton) Guacamole.AudioContextFactory.singleton = new AudioContext(); // Return singleton instance return Guacamole.AudioContextFactory.singleton; } catch (e) { // Do not use Web Audio API if not allowed by browser } } // Web Audio API not supported return null; }
javascript
function getAudioContext() { // Fallback to Webkit-specific AudioContext implementation var AudioContext = window.AudioContext || window.webkitAudioContext; // Get new AudioContext instance if Web Audio API is supported if (AudioContext) { try { // Create new instance if none yet exists if (!Guacamole.AudioContextFactory.singleton) Guacamole.AudioContextFactory.singleton = new AudioContext(); // Return singleton instance return Guacamole.AudioContextFactory.singleton; } catch (e) { // Do not use Web Audio API if not allowed by browser } } // Web Audio API not supported return null; }
[ "function", "getAudioContext", "(", ")", "{", "var", "AudioContext", "=", "window", ".", "AudioContext", "||", "window", ".", "webkitAudioContext", ";", "if", "(", "AudioContext", ")", "{", "try", "{", "if", "(", "!", "Guacamole", ".", "AudioContextFactory", ".", "singleton", ")", "Guacamole", ".", "AudioContextFactory", ".", "singleton", "=", "new", "AudioContext", "(", ")", ";", "return", "Guacamole", ".", "AudioContextFactory", ".", "singleton", ";", "}", "catch", "(", "e", ")", "{", "}", "}", "return", "null", ";", "}" ]
Returns a singleton instance of a Web Audio API AudioContext object. @return {AudioContext} A singleton instance of a Web Audio API AudioContext object, or null if the Web Audio API is not supported.
[ "Returns", "a", "singleton", "instance", "of", "a", "Web", "Audio", "API", "AudioContext", "object", "." ]
71925794155ea3fc37d2a125adbca6f8be532887
https://github.com/ILLGrenoble/guacamole-common-js/blob/71925794155ea3fc37d2a125adbca6f8be532887/src/AudioContextFactory.js#L52-L77
train
jorisvervuurt/JVSDisplayOTron
lib/dot3k/dot3k.js
DOT3k
function DOT3k() { if (!(this instanceof DOT3k)) { return new DOT3k(); } this.displayOTron = new DisplayOTron('3k'); this.lcd = new LCD(this.displayOTron); this.backlight = new Backlight(this.displayOTron); this.barGraph = new BarGraph(this.displayOTron); this.joystick = new Joystick(this.displayOTron); }
javascript
function DOT3k() { if (!(this instanceof DOT3k)) { return new DOT3k(); } this.displayOTron = new DisplayOTron('3k'); this.lcd = new LCD(this.displayOTron); this.backlight = new Backlight(this.displayOTron); this.barGraph = new BarGraph(this.displayOTron); this.joystick = new Joystick(this.displayOTron); }
[ "function", "DOT3k", "(", ")", "{", "if", "(", "!", "(", "this", "instanceof", "DOT3k", ")", ")", "{", "return", "new", "DOT3k", "(", ")", ";", "}", "this", ".", "displayOTron", "=", "new", "DisplayOTron", "(", "'3k'", ")", ";", "this", ".", "lcd", "=", "new", "LCD", "(", "this", ".", "displayOTron", ")", ";", "this", ".", "backlight", "=", "new", "Backlight", "(", "this", ".", "displayOTron", ")", ";", "this", ".", "barGraph", "=", "new", "BarGraph", "(", "this", ".", "displayOTron", ")", ";", "this", ".", "joystick", "=", "new", "Joystick", "(", "this", ".", "displayOTron", ")", ";", "}" ]
Creates a new `DOT3k` object. @constructor
[ "Creates", "a", "new", "DOT3k", "object", "." ]
c8f9bfdbf4e2658bb12fc83bbf49853c938e7dcc
https://github.com/jorisvervuurt/JVSDisplayOTron/blob/c8f9bfdbf4e2658bb12fc83bbf49853c938e7dcc/lib/dot3k/dot3k.js#L44-L54
train
ascartabelli/lamb
src/privates/_isEnumerable.js
_isEnumerable
function _isEnumerable (obj, key) { return key in Object(obj) && (_isOwnEnumerable(obj, key) || ~_safeEnumerables(obj).indexOf(key)); }
javascript
function _isEnumerable (obj, key) { return key in Object(obj) && (_isOwnEnumerable(obj, key) || ~_safeEnumerables(obj).indexOf(key)); }
[ "function", "_isEnumerable", "(", "obj", ",", "key", ")", "{", "return", "key", "in", "Object", "(", "obj", ")", "&&", "(", "_isOwnEnumerable", "(", "obj", ",", "key", ")", "||", "~", "_safeEnumerables", "(", "obj", ")", ".", "indexOf", "(", "key", ")", ")", ";", "}" ]
Checks whether the specified key is an enumerable property of the given object or not. @private @param {Object} obj @param {String} key @returns {Boolean}
[ "Checks", "whether", "the", "specified", "key", "is", "an", "enumerable", "property", "of", "the", "given", "object", "or", "not", "." ]
d36e45945c4789e4f1a2d8805936514b53f32362
https://github.com/ascartabelli/lamb/blob/d36e45945c4789e4f1a2d8805936514b53f32362/src/privates/_isEnumerable.js#L11-L13
train
ascartabelli/lamb
src/privates/_compareWith.js
_compareWith
function _compareWith (criteria) { return function (a, b) { var len = criteria.length; var criterion = criteria[0]; var result = criterion.compare(a.value, b.value); for (var i = 1; result === 0 && i < len; i++) { criterion = criteria[i]; result = criterion.compare(a.value, b.value); } if (result === 0) { result = a.index - b.index; } return criterion.isDescending ? -result : result; }; }
javascript
function _compareWith (criteria) { return function (a, b) { var len = criteria.length; var criterion = criteria[0]; var result = criterion.compare(a.value, b.value); for (var i = 1; result === 0 && i < len; i++) { criterion = criteria[i]; result = criterion.compare(a.value, b.value); } if (result === 0) { result = a.index - b.index; } return criterion.isDescending ? -result : result; }; }
[ "function", "_compareWith", "(", "criteria", ")", "{", "return", "function", "(", "a", ",", "b", ")", "{", "var", "len", "=", "criteria", ".", "length", ";", "var", "criterion", "=", "criteria", "[", "0", "]", ";", "var", "result", "=", "criterion", ".", "compare", "(", "a", ".", "value", ",", "b", ".", "value", ")", ";", "for", "(", "var", "i", "=", "1", ";", "result", "===", "0", "&&", "i", "<", "len", ";", "i", "++", ")", "{", "criterion", "=", "criteria", "[", "i", "]", ";", "result", "=", "criterion", ".", "compare", "(", "a", ".", "value", ",", "b", ".", "value", ")", ";", "}", "if", "(", "result", "===", "0", ")", "{", "result", "=", "a", ".", "index", "-", "b", ".", "index", ";", "}", "return", "criterion", ".", "isDescending", "?", "-", "result", ":", "result", ";", "}", ";", "}" ]
Accepts a list of sorting criteria with at least one element and builds a function that compares two values with such criteria. @private @param {Sorter[]} criteria @returns {Function}
[ "Accepts", "a", "list", "of", "sorting", "criteria", "with", "at", "least", "one", "element", "and", "builds", "a", "function", "that", "compares", "two", "values", "with", "such", "criteria", "." ]
d36e45945c4789e4f1a2d8805936514b53f32362
https://github.com/ascartabelli/lamb/blob/d36e45945c4789e4f1a2d8805936514b53f32362/src/privates/_compareWith.js#L8-L25
train
ascartabelli/lamb
src/privates/_currier.js
_currier
function _currier (fn, arity, isRightCurry, isAutoCurry, argsHolder) { return function () { var holderLen = argsHolder.length; var argsLen = arguments.length; var newArgsLen = holderLen + (argsLen > 1 && isAutoCurry ? argsLen : 1); var newArgs = Array(newArgsLen); for (var i = 0; i < holderLen; i++) { newArgs[i] = argsHolder[i]; } for (; i < newArgsLen; i++) { newArgs[i] = arguments[i - holderLen]; } if (newArgsLen >= arity) { return fn.apply(this, isRightCurry ? newArgs.reverse() : newArgs); } else { return _currier(fn, arity, isRightCurry, isAutoCurry, newArgs); } }; }
javascript
function _currier (fn, arity, isRightCurry, isAutoCurry, argsHolder) { return function () { var holderLen = argsHolder.length; var argsLen = arguments.length; var newArgsLen = holderLen + (argsLen > 1 && isAutoCurry ? argsLen : 1); var newArgs = Array(newArgsLen); for (var i = 0; i < holderLen; i++) { newArgs[i] = argsHolder[i]; } for (; i < newArgsLen; i++) { newArgs[i] = arguments[i - holderLen]; } if (newArgsLen >= arity) { return fn.apply(this, isRightCurry ? newArgs.reverse() : newArgs); } else { return _currier(fn, arity, isRightCurry, isAutoCurry, newArgs); } }; }
[ "function", "_currier", "(", "fn", ",", "arity", ",", "isRightCurry", ",", "isAutoCurry", ",", "argsHolder", ")", "{", "return", "function", "(", ")", "{", "var", "holderLen", "=", "argsHolder", ".", "length", ";", "var", "argsLen", "=", "arguments", ".", "length", ";", "var", "newArgsLen", "=", "holderLen", "+", "(", "argsLen", ">", "1", "&&", "isAutoCurry", "?", "argsLen", ":", "1", ")", ";", "var", "newArgs", "=", "Array", "(", "newArgsLen", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "holderLen", ";", "i", "++", ")", "{", "newArgs", "[", "i", "]", "=", "argsHolder", "[", "i", "]", ";", "}", "for", "(", ";", "i", "<", "newArgsLen", ";", "i", "++", ")", "{", "newArgs", "[", "i", "]", "=", "arguments", "[", "i", "-", "holderLen", "]", ";", "}", "if", "(", "newArgsLen", ">=", "arity", ")", "{", "return", "fn", ".", "apply", "(", "this", ",", "isRightCurry", "?", "newArgs", ".", "reverse", "(", ")", ":", "newArgs", ")", ";", "}", "else", "{", "return", "_currier", "(", "fn", ",", "arity", ",", "isRightCurry", ",", "isAutoCurry", ",", "newArgs", ")", ";", "}", "}", ";", "}" ]
Used by curry functions to collect arguments until the arity is consumed, then applies the original function. @private @param {Function} fn @param {Number} arity @param {Boolean} isRightCurry @param {Boolean} isAutoCurry @param {Array} argsHolder @returns {Function}
[ "Used", "by", "curry", "functions", "to", "collect", "arguments", "until", "the", "arity", "is", "consumed", "then", "applies", "the", "original", "function", "." ]
d36e45945c4789e4f1a2d8805936514b53f32362
https://github.com/ascartabelli/lamb/blob/d36e45945c4789e4f1a2d8805936514b53f32362/src/privates/_currier.js#L12-L33
train
mrsteele/ng-alerts
dist/ng-alerts.js
reset
function reset() { $scope.count = ngAlertsMngr.get().length; $scope.badge = ($attrs.badge); if ($scope.count === 0 && $attrs.hideEmpty) { $scope.count = ''; } }
javascript
function reset() { $scope.count = ngAlertsMngr.get().length; $scope.badge = ($attrs.badge); if ($scope.count === 0 && $attrs.hideEmpty) { $scope.count = ''; } }
[ "function", "reset", "(", ")", "{", "$scope", ".", "count", "=", "ngAlertsMngr", ".", "get", "(", ")", ".", "length", ";", "$scope", ".", "badge", "=", "(", "$attrs", ".", "badge", ")", ";", "if", "(", "$scope", ".", "count", "===", "0", "&&", "$attrs", ".", "hideEmpty", ")", "{", "$scope", ".", "count", "=", "''", ";", "}", "}" ]
Resets the alert count view.
[ "Resets", "the", "alert", "count", "view", "." ]
8f4a811a62d331d6286ce01aaf88479f3cdf181c
https://github.com/mrsteele/ng-alerts/blob/8f4a811a62d331d6286ce01aaf88479f3cdf181c/dist/ng-alerts.js#L55-L62
train
mrsteele/ng-alerts
dist/ng-alerts.js
remove
function remove(id) { var i; for (i = 0; i < $scope.alerts.length; i += 1) { if ($scope.alerts[i].id === id) { $scope.alerts.splice(i, 1); return; } } }
javascript
function remove(id) { var i; for (i = 0; i < $scope.alerts.length; i += 1) { if ($scope.alerts[i].id === id) { $scope.alerts.splice(i, 1); return; } } }
[ "function", "remove", "(", "id", ")", "{", "var", "i", ";", "for", "(", "i", "=", "0", ";", "i", "<", "$scope", ".", "alerts", ".", "length", ";", "i", "+=", "1", ")", "{", "if", "(", "$scope", ".", "alerts", "[", "i", "]", ".", "id", "===", "id", ")", "{", "$scope", ".", "alerts", ".", "splice", "(", "i", ",", "1", ")", ";", "return", ";", "}", "}", "}" ]
Removes a specific alert by id.
[ "Removes", "a", "specific", "alert", "by", "id", "." ]
8f4a811a62d331d6286ce01aaf88479f3cdf181c
https://github.com/mrsteele/ng-alerts/blob/8f4a811a62d331d6286ce01aaf88479f3cdf181c/dist/ng-alerts.js#L225-L233
train
mrsteele/ng-alerts
dist/ng-alerts.js
function (args) { var params = angular.extend({ id: ngAlertsId.create(), msg: '', type: 'default', time: Date.now() }, args); this.id = params.id; this.msg = params.msg; this.type = params.type; this.time = params.time; }
javascript
function (args) { var params = angular.extend({ id: ngAlertsId.create(), msg: '', type: 'default', time: Date.now() }, args); this.id = params.id; this.msg = params.msg; this.type = params.type; this.time = params.time; }
[ "function", "(", "args", ")", "{", "var", "params", "=", "angular", ".", "extend", "(", "{", "id", ":", "ngAlertsId", ".", "create", "(", ")", ",", "msg", ":", "''", ",", "type", ":", "'default'", ",", "time", ":", "Date", ".", "now", "(", ")", "}", ",", "args", ")", ";", "this", ".", "id", "=", "params", ".", "id", ";", "this", ".", "msg", "=", "params", ".", "msg", ";", "this", ".", "type", "=", "params", ".", "type", ";", "this", ".", "time", "=", "params", ".", "time", ";", "}" ]
The alert object. @param {Object} args - The argument object. @param {Number} args.id - The unique id. @param {String} args.msg - The message. @param {String} [args.type=default] - The type of alert. @param {Number} [args.time=Date.now()] - The time of the notification (Miliseconds since Jan 1 1970).
[ "The", "alert", "object", "." ]
8f4a811a62d331d6286ce01aaf88479f3cdf181c
https://github.com/mrsteele/ng-alerts/blob/8f4a811a62d331d6286ce01aaf88479f3cdf181c/dist/ng-alerts.js#L281-L293
train
mrsteele/ng-alerts
dist/ng-alerts.js
fire
function fire(name, args) { ngAlertsEvent.fire(name, args); ngAlertsEvent.fire('change', args); }
javascript
function fire(name, args) { ngAlertsEvent.fire(name, args); ngAlertsEvent.fire('change', args); }
[ "function", "fire", "(", "name", ",", "args", ")", "{", "ngAlertsEvent", ".", "fire", "(", "name", ",", "args", ")", ";", "ngAlertsEvent", ".", "fire", "(", "'change'", ",", "args", ")", ";", "}" ]
Fires an alert event. @param {String} name - The name of the event. @param {Object=} args - Any optional arguments.
[ "Fires", "an", "alert", "event", "." ]
8f4a811a62d331d6286ce01aaf88479f3cdf181c
https://github.com/mrsteele/ng-alerts/blob/8f4a811a62d331d6286ce01aaf88479f3cdf181c/dist/ng-alerts.js#L355-L358
train