id
int32
0
58k
repo
stringlengths
5
67
path
stringlengths
4
116
func_name
stringlengths
0
58
original_string
stringlengths
52
373k
language
stringclasses
1 value
code
stringlengths
52
373k
code_tokens
list
docstring
stringlengths
4
11.8k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
86
226
48,500
desmondmorris/node-mta
lib/utils.js
function (obj) { var ret = {}; if( Object.prototype.toString.call(obj) === '[object Object]' ) { for (var key in obj) { ret[key] = arrayClean(obj[key]); } } else if( Object.prototype.toString.call(obj) === '[object Array]' ) { if (obj.length === 1) { ret = arrayClean(obj[0]); } else { ret = new Array; for(var i=0;i<obj.length;i++) { ret.push(arrayClean(obj[i])); } } } else { ret = obj; } return ret; }
javascript
function (obj) { var ret = {}; if( Object.prototype.toString.call(obj) === '[object Object]' ) { for (var key in obj) { ret[key] = arrayClean(obj[key]); } } else if( Object.prototype.toString.call(obj) === '[object Array]' ) { if (obj.length === 1) { ret = arrayClean(obj[0]); } else { ret = new Array; for(var i=0;i<obj.length;i++) { ret.push(arrayClean(obj[i])); } } } else { ret = obj; } return ret; }
[ "function", "(", "obj", ")", "{", "var", "ret", "=", "{", "}", ";", "if", "(", "Object", ".", "prototype", ".", "toString", ".", "call", "(", "obj", ")", "===", "'[object Object]'", ")", "{", "for", "(", "var", "key", "in", "obj", ")", "{", "ret", "[", "key", "]", "=", "arrayClean", "(", "obj", "[", "key", "]", ")", ";", "}", "}", "else", "if", "(", "Object", ".", "prototype", ".", "toString", ".", "call", "(", "obj", ")", "===", "'[object Array]'", ")", "{", "if", "(", "obj", ".", "length", "===", "1", ")", "{", "ret", "=", "arrayClean", "(", "obj", "[", "0", "]", ")", ";", "}", "else", "{", "ret", "=", "new", "Array", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "obj", ".", "length", ";", "i", "++", ")", "{", "ret", ".", "push", "(", "arrayClean", "(", "obj", "[", "i", "]", ")", ")", ";", "}", "}", "}", "else", "{", "ret", "=", "obj", ";", "}", "return", "ret", ";", "}" ]
Recursively removes extraneous nested arrays from objects @param {Object|Array|String|Integer} obj @return {Object}
[ "Recursively", "removes", "extraneous", "nested", "arrays", "from", "objects" ]
e87b57b4518b603a5f17ff4aecf0694d37c45b71
https://github.com/desmondmorris/node-mta/blob/e87b57b4518b603a5f17ff4aecf0694d37c45b71/lib/utils.js#L29-L52
48,501
areslabs/babel-plugin-import-css
src/util.js
queryImport
function queryImport(styles) { if (styles.indexOf('@import') < 0) return [] const arr = [] const ast = csstree.parse(styles); csstree.walk(ast, { enter: function (node) { if (node.type === 'Atrule' && node.name === 'import') { const pat = node.prelude.children.head.data.value arr.push(pat.substring(1, pat.length - 1)) } } }) return arr }
javascript
function queryImport(styles) { if (styles.indexOf('@import') < 0) return [] const arr = [] const ast = csstree.parse(styles); csstree.walk(ast, { enter: function (node) { if (node.type === 'Atrule' && node.name === 'import') { const pat = node.prelude.children.head.data.value arr.push(pat.substring(1, pat.length - 1)) } } }) return arr }
[ "function", "queryImport", "(", "styles", ")", "{", "if", "(", "styles", ".", "indexOf", "(", "'@import'", ")", "<", "0", ")", "return", "[", "]", "const", "arr", "=", "[", "]", "const", "ast", "=", "csstree", ".", "parse", "(", "styles", ")", ";", "csstree", ".", "walk", "(", "ast", ",", "{", "enter", ":", "function", "(", "node", ")", "{", "if", "(", "node", ".", "type", "===", "'Atrule'", "&&", "node", ".", "name", "===", "'import'", ")", "{", "const", "pat", "=", "node", ".", "prelude", ".", "children", ".", "head", ".", "data", ".", "value", "arr", ".", "push", "(", "pat", ".", "substring", "(", "1", ",", "pat", ".", "length", "-", "1", ")", ")", "}", "}", "}", ")", "return", "arr", "}" ]
get import content in css file,may import multi times @param styles css file content @returns {Array} result
[ "get", "import", "content", "in", "css", "file", "may", "import", "multi", "times" ]
b90d3a4ec3a644edcaa1c803314e2c39de1d29c9
https://github.com/areslabs/babel-plugin-import-css/blob/b90d3a4ec3a644edcaa1c803314e2c39de1d29c9/src/util.js#L11-L24
48,502
areslabs/babel-plugin-import-css
src/util.js
handleImportStyle
function handleImportStyle(styles, initPath, mayRM) { if (!!mayRM) { styles = styles.replace(mayRM, '') } if (styles.indexOf('@import') < 0) return styles const ast = csstree.parse(styles); csstree.walk(ast, { enter: function (node) { if (node.type === 'Atrule') { if (node.name === 'import') { const pat = node.prelude.children.head.data.value if (initPath && typeof pat === 'string') { const realP = pat.substring(1, pat.length - 1) const newPath = path.dirname(initPath) const resPath = path.resolve(newPath, realP) const text = fs.readFileSync(resPath).toString() const re = new RegExp("[\\s]*@import[\\s]+\"" + realP + "\";", "g"); //handle with loop import styles = styles.replace(re, handleImportStyle(text, resPath, re)) } } } } }) return styles }
javascript
function handleImportStyle(styles, initPath, mayRM) { if (!!mayRM) { styles = styles.replace(mayRM, '') } if (styles.indexOf('@import') < 0) return styles const ast = csstree.parse(styles); csstree.walk(ast, { enter: function (node) { if (node.type === 'Atrule') { if (node.name === 'import') { const pat = node.prelude.children.head.data.value if (initPath && typeof pat === 'string') { const realP = pat.substring(1, pat.length - 1) const newPath = path.dirname(initPath) const resPath = path.resolve(newPath, realP) const text = fs.readFileSync(resPath).toString() const re = new RegExp("[\\s]*@import[\\s]+\"" + realP + "\";", "g"); //handle with loop import styles = styles.replace(re, handleImportStyle(text, resPath, re)) } } } } }) return styles }
[ "function", "handleImportStyle", "(", "styles", ",", "initPath", ",", "mayRM", ")", "{", "if", "(", "!", "!", "mayRM", ")", "{", "styles", "=", "styles", ".", "replace", "(", "mayRM", ",", "''", ")", "}", "if", "(", "styles", ".", "indexOf", "(", "'@import'", ")", "<", "0", ")", "return", "styles", "const", "ast", "=", "csstree", ".", "parse", "(", "styles", ")", ";", "csstree", ".", "walk", "(", "ast", ",", "{", "enter", ":", "function", "(", "node", ")", "{", "if", "(", "node", ".", "type", "===", "'Atrule'", ")", "{", "if", "(", "node", ".", "name", "===", "'import'", ")", "{", "const", "pat", "=", "node", ".", "prelude", ".", "children", ".", "head", ".", "data", ".", "value", "if", "(", "initPath", "&&", "typeof", "pat", "===", "'string'", ")", "{", "const", "realP", "=", "pat", ".", "substring", "(", "1", ",", "pat", ".", "length", "-", "1", ")", "const", "newPath", "=", "path", ".", "dirname", "(", "initPath", ")", "const", "resPath", "=", "path", ".", "resolve", "(", "newPath", ",", "realP", ")", "const", "text", "=", "fs", ".", "readFileSync", "(", "resPath", ")", ".", "toString", "(", ")", "const", "re", "=", "new", "RegExp", "(", "\"[\\\\s]*@import[\\\\s]+\\\"\"", "+", "realP", "+", "\"\\\";\"", ",", "\"g\"", ")", ";", "//handle with loop import", "styles", "=", "styles", ".", "replace", "(", "re", ",", "handleImportStyle", "(", "text", ",", "resPath", ",", "re", ")", ")", "}", "}", "}", "}", "}", ")", "return", "styles", "}" ]
handle with import procedure,may search involved file in project @param styles styles css file content @param initPath project path, used for searching target file @param mayRM this param avoid loop importing @returns handled styles content
[ "handle", "with", "import", "procedure", "may", "search", "involved", "file", "in", "project" ]
b90d3a4ec3a644edcaa1c803314e2c39de1d29c9
https://github.com/areslabs/babel-plugin-import-css/blob/b90d3a4ec3a644edcaa1c803314e2c39de1d29c9/src/util.js#L33-L58
48,503
areslabs/babel-plugin-import-css
src/util.js
createStylefromCode
function createStylefromCode(styles, abspath) { //may import other file const arr = queryImport(styles) const baseRes = handleImportStyle(styles, abspath) const obj = {} const ast = csstree.parse(baseRes); csstree.walk(ast, { enter: function (node) { if (node.type === 'Rule' && node.prelude && node.prelude.type === 'SelectorList') { const clzName = [] node.prelude.children.forEach(e => { //we may handle each class selector here let ans = selectorBlockHandler(e) if (ans) { //to save before value obj[ans] = obj[ans] || {} //save ans to log which to give value clzName.push(ans) } }) const styleArray = [] node.block.children.forEach(e => { //handle with unit or function case const styleItem = styleBlockHandler(e) styleItem.length > 0 && styleArray.push(styleItem) }) clzName.forEach(e => { try { const styleObject = transform(styleArray) if (styleObject.fontWeight) { //fontWeight must be string styleObject.fontWeight = styleObject.fontWeight + "" } Object.assign(obj[e], styleObject) } catch (e) { console.error("convert ", abspath, " error:", e.message) } }) } }, }) return {styles: obj, imports: arr} }
javascript
function createStylefromCode(styles, abspath) { //may import other file const arr = queryImport(styles) const baseRes = handleImportStyle(styles, abspath) const obj = {} const ast = csstree.parse(baseRes); csstree.walk(ast, { enter: function (node) { if (node.type === 'Rule' && node.prelude && node.prelude.type === 'SelectorList') { const clzName = [] node.prelude.children.forEach(e => { //we may handle each class selector here let ans = selectorBlockHandler(e) if (ans) { //to save before value obj[ans] = obj[ans] || {} //save ans to log which to give value clzName.push(ans) } }) const styleArray = [] node.block.children.forEach(e => { //handle with unit or function case const styleItem = styleBlockHandler(e) styleItem.length > 0 && styleArray.push(styleItem) }) clzName.forEach(e => { try { const styleObject = transform(styleArray) if (styleObject.fontWeight) { //fontWeight must be string styleObject.fontWeight = styleObject.fontWeight + "" } Object.assign(obj[e], styleObject) } catch (e) { console.error("convert ", abspath, " error:", e.message) } }) } }, }) return {styles: obj, imports: arr} }
[ "function", "createStylefromCode", "(", "styles", ",", "abspath", ")", "{", "//may import other file", "const", "arr", "=", "queryImport", "(", "styles", ")", "const", "baseRes", "=", "handleImportStyle", "(", "styles", ",", "abspath", ")", "const", "obj", "=", "{", "}", "const", "ast", "=", "csstree", ".", "parse", "(", "baseRes", ")", ";", "csstree", ".", "walk", "(", "ast", ",", "{", "enter", ":", "function", "(", "node", ")", "{", "if", "(", "node", ".", "type", "===", "'Rule'", "&&", "node", ".", "prelude", "&&", "node", ".", "prelude", ".", "type", "===", "'SelectorList'", ")", "{", "const", "clzName", "=", "[", "]", "node", ".", "prelude", ".", "children", ".", "forEach", "(", "e", "=>", "{", "//we may handle each class selector here", "let", "ans", "=", "selectorBlockHandler", "(", "e", ")", "if", "(", "ans", ")", "{", "//to save before value", "obj", "[", "ans", "]", "=", "obj", "[", "ans", "]", "||", "{", "}", "//save ans to log which to give value", "clzName", ".", "push", "(", "ans", ")", "}", "}", ")", "const", "styleArray", "=", "[", "]", "node", ".", "block", ".", "children", ".", "forEach", "(", "e", "=>", "{", "//handle with unit or function case", "const", "styleItem", "=", "styleBlockHandler", "(", "e", ")", "styleItem", ".", "length", ">", "0", "&&", "styleArray", ".", "push", "(", "styleItem", ")", "}", ")", "clzName", ".", "forEach", "(", "e", "=>", "{", "try", "{", "const", "styleObject", "=", "transform", "(", "styleArray", ")", "if", "(", "styleObject", ".", "fontWeight", ")", "{", "//fontWeight must be string", "styleObject", ".", "fontWeight", "=", "styleObject", ".", "fontWeight", "+", "\"\"", "}", "Object", ".", "assign", "(", "obj", "[", "e", "]", ",", "styleObject", ")", "}", "catch", "(", "e", ")", "{", "console", ".", "error", "(", "\"convert \"", ",", "abspath", ",", "\" error:\"", ",", "e", ".", "message", ")", "}", "}", ")", "}", "}", ",", "}", ")", "return", "{", "styles", ":", "obj", ",", "imports", ":", "arr", "}", "}" ]
create style object from css file content,which is raw string. @param styles styles styles css file content @param abspath project file path @returns {{styles, imports: Array}}
[ "create", "style", "object", "from", "css", "file", "content", "which", "is", "raw", "string", "." ]
b90d3a4ec3a644edcaa1c803314e2c39de1d29c9
https://github.com/areslabs/babel-plugin-import-css/blob/b90d3a4ec3a644edcaa1c803314e2c39de1d29c9/src/util.js#L66-L109
48,504
areslabs/babel-plugin-import-css
src/util.js
createStyleDictionary
function createStyleDictionary(styles) { let total = {} for (let k in styles) { const val = styles[k] //sort clz name to judge arbitrary order in multi-className k = sortSeq(k) //merge style chain from last condition const lastEle = getLastEle(k) //no sharing data. create new chain if (!total.hasOwnProperty(lastEle)) { total[lastEle] = createItem(k, val)[lastEle] } else { //merge chain data merge(createItem(k, styles[k]), total) } } return total }
javascript
function createStyleDictionary(styles) { let total = {} for (let k in styles) { const val = styles[k] //sort clz name to judge arbitrary order in multi-className k = sortSeq(k) //merge style chain from last condition const lastEle = getLastEle(k) //no sharing data. create new chain if (!total.hasOwnProperty(lastEle)) { total[lastEle] = createItem(k, val)[lastEle] } else { //merge chain data merge(createItem(k, styles[k]), total) } } return total }
[ "function", "createStyleDictionary", "(", "styles", ")", "{", "let", "total", "=", "{", "}", "for", "(", "let", "k", "in", "styles", ")", "{", "const", "val", "=", "styles", "[", "k", "]", "//sort clz name to judge arbitrary order in multi-className", "k", "=", "sortSeq", "(", "k", ")", "//merge style chain from last condition", "const", "lastEle", "=", "getLastEle", "(", "k", ")", "//no sharing data. create new chain", "if", "(", "!", "total", ".", "hasOwnProperty", "(", "lastEle", ")", ")", "{", "total", "[", "lastEle", "]", "=", "createItem", "(", "k", ",", "val", ")", "[", "lastEle", "]", "}", "else", "{", "//merge chain data", "merge", "(", "createItem", "(", "k", ",", "styles", "[", "k", "]", ")", ",", "total", ")", "}", "}", "return", "total", "}" ]
create special style dict structure for high performance query @param styles style object
[ "create", "special", "style", "dict", "structure", "for", "high", "performance", "query" ]
b90d3a4ec3a644edcaa1c803314e2c39de1d29c9
https://github.com/areslabs/babel-plugin-import-css/blob/b90d3a4ec3a644edcaa1c803314e2c39de1d29c9/src/util.js#L115-L132
48,505
areslabs/babel-plugin-import-css
src/util.js
selectorBlockHandler
function selectorBlockHandler(element) { if (element.type === 'Selector') { const name = [] let discard = false element.children.forEach(e => { switch (e.type) { case "ClassSelector": name.push("." + e.name); break; //not support for now case "Combinator": name.push(e.name); discard = true return null case "TypeSelector": name.push(e.name); break; case "IdSelector": //not support for now name.push("#" + e.name); discard = true return null case "WhiteSpace": name.push(" "); break default: { // console.warn('unknown selector type:', e) discard = true return null } } }) if (!discard) return name.join("") else return null } }
javascript
function selectorBlockHandler(element) { if (element.type === 'Selector') { const name = [] let discard = false element.children.forEach(e => { switch (e.type) { case "ClassSelector": name.push("." + e.name); break; //not support for now case "Combinator": name.push(e.name); discard = true return null case "TypeSelector": name.push(e.name); break; case "IdSelector": //not support for now name.push("#" + e.name); discard = true return null case "WhiteSpace": name.push(" "); break default: { // console.warn('unknown selector type:', e) discard = true return null } } }) if (!discard) return name.join("") else return null } }
[ "function", "selectorBlockHandler", "(", "element", ")", "{", "if", "(", "element", ".", "type", "===", "'Selector'", ")", "{", "const", "name", "=", "[", "]", "let", "discard", "=", "false", "element", ".", "children", ".", "forEach", "(", "e", "=>", "{", "switch", "(", "e", ".", "type", ")", "{", "case", "\"ClassSelector\"", ":", "name", ".", "push", "(", "\".\"", "+", "e", ".", "name", ")", ";", "break", ";", "//not support for now", "case", "\"Combinator\"", ":", "name", ".", "push", "(", "e", ".", "name", ")", ";", "discard", "=", "true", "return", "null", "case", "\"TypeSelector\"", ":", "name", ".", "push", "(", "e", ".", "name", ")", ";", "break", ";", "case", "\"IdSelector\"", ":", "//not support for now", "name", ".", "push", "(", "\"#\"", "+", "e", ".", "name", ")", ";", "discard", "=", "true", "return", "null", "case", "\"WhiteSpace\"", ":", "name", ".", "push", "(", "\" \"", ")", ";", "break", "default", ":", "{", "// console.warn('unknown selector type:', e)", "discard", "=", "true", "return", "null", "}", "}", "}", ")", "if", "(", "!", "discard", ")", "return", "name", ".", "join", "(", "\"\"", ")", "else", "return", "null", "}", "}" ]
handle with selector part in node's structure @param element node to be searched @return {*}
[ "handle", "with", "selector", "part", "in", "node", "s", "structure" ]
b90d3a4ec3a644edcaa1c803314e2c39de1d29c9
https://github.com/areslabs/babel-plugin-import-css/blob/b90d3a4ec3a644edcaa1c803314e2c39de1d29c9/src/util.js#L240-L276
48,506
areslabs/babel-plugin-import-css
src/util.js
paddingElementForTransform
function paddingElementForTransform(proper, arr) { //RN not support multi font-family keywords if (proper === 'font-family') { return [proper, arr.pop()] } //not support such shorthand if (proper === 'background') { return ['background-color', arr.join(" ")] } //not support such shorthand if (proper === 'border-bottom' || proper === 'border-top' || proper === 'border-right' || proper === 'border-left') { // console.warn("not support property",proper) return [] } //content property should take just single value if (proper === 'content' && arr.length === 1) return [proper, arr[0]] return [proper, arr.join(" ")] }
javascript
function paddingElementForTransform(proper, arr) { //RN not support multi font-family keywords if (proper === 'font-family') { return [proper, arr.pop()] } //not support such shorthand if (proper === 'background') { return ['background-color', arr.join(" ")] } //not support such shorthand if (proper === 'border-bottom' || proper === 'border-top' || proper === 'border-right' || proper === 'border-left') { // console.warn("not support property",proper) return [] } //content property should take just single value if (proper === 'content' && arr.length === 1) return [proper, arr[0]] return [proper, arr.join(" ")] }
[ "function", "paddingElementForTransform", "(", "proper", ",", "arr", ")", "{", "//RN not support multi font-family keywords", "if", "(", "proper", "===", "'font-family'", ")", "{", "return", "[", "proper", ",", "arr", ".", "pop", "(", ")", "]", "}", "//not support such shorthand", "if", "(", "proper", "===", "'background'", ")", "{", "return", "[", "'background-color'", ",", "arr", ".", "join", "(", "\" \"", ")", "]", "}", "//not support such shorthand", "if", "(", "proper", "===", "'border-bottom'", "||", "proper", "===", "'border-top'", "||", "proper", "===", "'border-right'", "||", "proper", "===", "'border-left'", ")", "{", "// console.warn(\"not support property\",proper)", "return", "[", "]", "}", "//content property should take just single value", "if", "(", "proper", "===", "'content'", "&&", "arr", ".", "length", "===", "1", ")", "return", "[", "proper", ",", "arr", "[", "0", "]", "]", "return", "[", "proper", ",", "arr", ".", "join", "(", "\" \"", ")", "]", "}" ]
do some padding modification,to produce more stable run-time environment @param proper @param arr @return {*}
[ "do", "some", "padding", "modification", "to", "produce", "more", "stable", "run", "-", "time", "environment" ]
b90d3a4ec3a644edcaa1c803314e2c39de1d29c9
https://github.com/areslabs/babel-plugin-import-css/blob/b90d3a4ec3a644edcaa1c803314e2c39de1d29c9/src/util.js#L284-L302
48,507
areslabs/babel-plugin-import-css
src/util.js
styleBlockHandler
function styleBlockHandler(element) { const {property, value} = element let result = [] const styleContent = value && value.children ? value.children : [] const defaultUnit = "px" styleContent.forEach(e => { switch (e.type) { case "Identifier": result.push(e.name); break case "Dimension": result.push(e.value + defaultUnit); break case 'Function': { //function case need '()' container,such as rgb(255,0,0) let name = e.name + "(" e.children.forEach(e => name += e.value + queryUnit(e.unit)) result.push(name + ")") break } case "HexColor": { result.push("#" + e.value) break } case "String": { const str = e.value result.push(str) break } case "Number": { result.push(e.value) break } case "Percentage": { result.push(e.value + "%") break } case "WhiteSpace": { break } case "Operator": { break } case "Url": { break } default: // console.log("unknown,", property, e) break } }) //padding modification if (result.length > 0) return paddingElementForTransform(property, result) return [] }
javascript
function styleBlockHandler(element) { const {property, value} = element let result = [] const styleContent = value && value.children ? value.children : [] const defaultUnit = "px" styleContent.forEach(e => { switch (e.type) { case "Identifier": result.push(e.name); break case "Dimension": result.push(e.value + defaultUnit); break case 'Function': { //function case need '()' container,such as rgb(255,0,0) let name = e.name + "(" e.children.forEach(e => name += e.value + queryUnit(e.unit)) result.push(name + ")") break } case "HexColor": { result.push("#" + e.value) break } case "String": { const str = e.value result.push(str) break } case "Number": { result.push(e.value) break } case "Percentage": { result.push(e.value + "%") break } case "WhiteSpace": { break } case "Operator": { break } case "Url": { break } default: // console.log("unknown,", property, e) break } }) //padding modification if (result.length > 0) return paddingElementForTransform(property, result) return [] }
[ "function", "styleBlockHandler", "(", "element", ")", "{", "const", "{", "property", ",", "value", "}", "=", "element", "let", "result", "=", "[", "]", "const", "styleContent", "=", "value", "&&", "value", ".", "children", "?", "value", ".", "children", ":", "[", "]", "const", "defaultUnit", "=", "\"px\"", "styleContent", ".", "forEach", "(", "e", "=>", "{", "switch", "(", "e", ".", "type", ")", "{", "case", "\"Identifier\"", ":", "result", ".", "push", "(", "e", ".", "name", ")", ";", "break", "case", "\"Dimension\"", ":", "result", ".", "push", "(", "e", ".", "value", "+", "defaultUnit", ")", ";", "break", "case", "'Function'", ":", "{", "//function case need '()' container,such as rgb(255,0,0)", "let", "name", "=", "e", ".", "name", "+", "\"(\"", "e", ".", "children", ".", "forEach", "(", "e", "=>", "name", "+=", "e", ".", "value", "+", "queryUnit", "(", "e", ".", "unit", ")", ")", "result", ".", "push", "(", "name", "+", "\")\"", ")", "break", "}", "case", "\"HexColor\"", ":", "{", "result", ".", "push", "(", "\"#\"", "+", "e", ".", "value", ")", "break", "}", "case", "\"String\"", ":", "{", "const", "str", "=", "e", ".", "value", "result", ".", "push", "(", "str", ")", "break", "}", "case", "\"Number\"", ":", "{", "result", ".", "push", "(", "e", ".", "value", ")", "break", "}", "case", "\"Percentage\"", ":", "{", "result", ".", "push", "(", "e", ".", "value", "+", "\"%\"", ")", "break", "}", "case", "\"WhiteSpace\"", ":", "{", "break", "}", "case", "\"Operator\"", ":", "{", "break", "}", "case", "\"Url\"", ":", "{", "break", "}", "default", ":", "// console.log(\"unknown,\", property, e)", "break", "}", "}", ")", "//padding modification", "if", "(", "result", ".", "length", ">", "0", ")", "return", "paddingElementForTransform", "(", "property", ",", "result", ")", "return", "[", "]", "}" ]
handle with different node structure in ast @param element @return {*}
[ "handle", "with", "different", "node", "structure", "in", "ast" ]
b90d3a4ec3a644edcaa1c803314e2c39de1d29c9
https://github.com/areslabs/babel-plugin-import-css/blob/b90d3a4ec3a644edcaa1c803314e2c39de1d29c9/src/util.js#L318-L373
48,508
poynt/traildb-node
lib/traildb.js
function (uuid) { uuid = ref.reinterpret(uuid, 16).toString('hex'); return [ uuid.slice(0, 8), uuid.slice(8, 12), uuid.slice(12, 16), uuid.slice(16, 20), uuid.slice(20, 32) ].join('-'); }
javascript
function (uuid) { uuid = ref.reinterpret(uuid, 16).toString('hex'); return [ uuid.slice(0, 8), uuid.slice(8, 12), uuid.slice(12, 16), uuid.slice(16, 20), uuid.slice(20, 32) ].join('-'); }
[ "function", "(", "uuid", ")", "{", "uuid", "=", "ref", ".", "reinterpret", "(", "uuid", ",", "16", ")", ".", "toString", "(", "'hex'", ")", ";", "return", "[", "uuid", ".", "slice", "(", "0", ",", "8", ")", ",", "uuid", ".", "slice", "(", "8", ",", "12", ")", ",", "uuid", ".", "slice", "(", "12", ",", "16", ")", ",", "uuid", ".", "slice", "(", "16", ",", "20", ")", ",", "uuid", ".", "slice", "(", "20", ",", "32", ")", "]", ".", "join", "(", "'-'", ")", ";", "}" ]
Returns a UUID hex string. @param {Array[Byte]} uuid - UUID buffer. @return {String} uuid - UUID string.
[ "Returns", "a", "UUID", "hex", "string", "." ]
c174ae3e417877eeeae6e0e1af013a7182f6c65a
https://github.com/poynt/traildb-node/blob/c174ae3e417877eeeae6e0e1af013a7182f6c65a/lib/traildb.js#L169-L178
48,509
poynt/traildb-node
lib/traildb.js
function (trail, options) { this.trail = trail; this.options = options || {}; this.cursor = lib.tdb_cursor_new(this.trail.tdb._db); /*\ |*| Filter logic \*/ if (typeof this.options.filter != 'undefined') { const err = lib.tdb_cursor_set_event_filter(this.cursor, this.options.filter); if (err) { throw new TrailDBError('Unable to set event filter: ' + this.trail.id); } } const r = lib.tdb_get_trail(this.cursor, this.trail.id); if (r) { throw new TrailDBError('Failed to open trail cursor: ' + this.trail.id); } return this; }
javascript
function (trail, options) { this.trail = trail; this.options = options || {}; this.cursor = lib.tdb_cursor_new(this.trail.tdb._db); /*\ |*| Filter logic \*/ if (typeof this.options.filter != 'undefined') { const err = lib.tdb_cursor_set_event_filter(this.cursor, this.options.filter); if (err) { throw new TrailDBError('Unable to set event filter: ' + this.trail.id); } } const r = lib.tdb_get_trail(this.cursor, this.trail.id); if (r) { throw new TrailDBError('Failed to open trail cursor: ' + this.trail.id); } return this; }
[ "function", "(", "trail", ",", "options", ")", "{", "this", ".", "trail", "=", "trail", ";", "this", ".", "options", "=", "options", "||", "{", "}", ";", "this", ".", "cursor", "=", "lib", ".", "tdb_cursor_new", "(", "this", ".", "trail", ".", "tdb", ".", "_db", ")", ";", "/*\\\n |*| Filter logic\n \\*/", "if", "(", "typeof", "this", ".", "options", ".", "filter", "!=", "'undefined'", ")", "{", "const", "err", "=", "lib", ".", "tdb_cursor_set_event_filter", "(", "this", ".", "cursor", ",", "this", ".", "options", ".", "filter", ")", ";", "if", "(", "err", ")", "{", "throw", "new", "TrailDBError", "(", "'Unable to set event filter: '", "+", "this", ".", "trail", ".", "id", ")", ";", "}", "}", "const", "r", "=", "lib", ".", "tdb_get_trail", "(", "this", ".", "cursor", ",", "this", ".", "trail", ".", "id", ")", ";", "if", "(", "r", ")", "{", "throw", "new", "TrailDBError", "(", "'Failed to open trail cursor: '", "+", "this", ".", "trail", ".", "id", ")", ";", "}", "return", "this", ";", "}" ]
Initialize a new EventsIterator. Iterate over all events in a trail.. @param {TrailDB} tdb - TrailDB object. @param {Boolean,Object} options.toMap - Whether the iterator should return a map for each event, grabbing the appropriate key names. Defaults to a list with just values. options.filter - T_TDB_FILTER event filter struct (optional) @return {EventsIterator} iterator.
[ "Initialize", "a", "new", "EventsIterator", ".", "Iterate", "over", "all", "events", "in", "a", "trail", ".." ]
c174ae3e417877eeeae6e0e1af013a7182f6c65a
https://github.com/poynt/traildb-node/blob/c174ae3e417877eeeae6e0e1af013a7182f6c65a/lib/traildb.js#L244-L263
48,510
poynt/traildb-node
lib/traildb.js
function (options) { if (!options.path) { throw new TrailDBError('Path is required'); } if (!options.fieldNames || !options.fieldNames.length) { throw new TrailDBError('Field names are required'); } if (options.path.slice(-4) === '.tdb') { options.path = options.path.slice(0, -4); } this._cons = lib.tdb_cons_init(); this.numFields = options.fieldNames.length; const fieldNamesLength = ref.alloc(ref.types.uint64, this.numFields); const fieldNamesArray = new T_STRING_ARRAY(this.numFields); options.fieldNames.forEach(function (field, i) { fieldNamesArray[i] = ref.allocCString(field); }); const r = lib.tdb_cons_open( this._cons, ref.allocCString(options.path), fieldNamesArray, ref.deref(fieldNamesLength) ); if (r !== 0) { throw new TrailDBError('Cannot open constructor: ' + r); } this.path = options.path; this.fieldNames = options.fieldNames; return this; }
javascript
function (options) { if (!options.path) { throw new TrailDBError('Path is required'); } if (!options.fieldNames || !options.fieldNames.length) { throw new TrailDBError('Field names are required'); } if (options.path.slice(-4) === '.tdb') { options.path = options.path.slice(0, -4); } this._cons = lib.tdb_cons_init(); this.numFields = options.fieldNames.length; const fieldNamesLength = ref.alloc(ref.types.uint64, this.numFields); const fieldNamesArray = new T_STRING_ARRAY(this.numFields); options.fieldNames.forEach(function (field, i) { fieldNamesArray[i] = ref.allocCString(field); }); const r = lib.tdb_cons_open( this._cons, ref.allocCString(options.path), fieldNamesArray, ref.deref(fieldNamesLength) ); if (r !== 0) { throw new TrailDBError('Cannot open constructor: ' + r); } this.path = options.path; this.fieldNames = options.fieldNames; return this; }
[ "function", "(", "options", ")", "{", "if", "(", "!", "options", ".", "path", ")", "{", "throw", "new", "TrailDBError", "(", "'Path is required'", ")", ";", "}", "if", "(", "!", "options", ".", "fieldNames", "||", "!", "options", ".", "fieldNames", ".", "length", ")", "{", "throw", "new", "TrailDBError", "(", "'Field names are required'", ")", ";", "}", "if", "(", "options", ".", "path", ".", "slice", "(", "-", "4", ")", "===", "'.tdb'", ")", "{", "options", ".", "path", "=", "options", ".", "path", ".", "slice", "(", "0", ",", "-", "4", ")", ";", "}", "this", ".", "_cons", "=", "lib", ".", "tdb_cons_init", "(", ")", ";", "this", ".", "numFields", "=", "options", ".", "fieldNames", ".", "length", ";", "const", "fieldNamesLength", "=", "ref", ".", "alloc", "(", "ref", ".", "types", ".", "uint64", ",", "this", ".", "numFields", ")", ";", "const", "fieldNamesArray", "=", "new", "T_STRING_ARRAY", "(", "this", ".", "numFields", ")", ";", "options", ".", "fieldNames", ".", "forEach", "(", "function", "(", "field", ",", "i", ")", "{", "fieldNamesArray", "[", "i", "]", "=", "ref", ".", "allocCString", "(", "field", ")", ";", "}", ")", ";", "const", "r", "=", "lib", ".", "tdb_cons_open", "(", "this", ".", "_cons", ",", "ref", ".", "allocCString", "(", "options", ".", "path", ")", ",", "fieldNamesArray", ",", "ref", ".", "deref", "(", "fieldNamesLength", ")", ")", ";", "if", "(", "r", "!==", "0", ")", "{", "throw", "new", "TrailDBError", "(", "'Cannot open constructor: '", "+", "r", ")", ";", "}", "this", ".", "path", "=", "options", ".", "path", ";", "this", ".", "fieldNames", "=", "options", ".", "fieldNames", ";", "return", "this", ";", "}" ]
TrailDBConstructor class Construct a new TrailDB. Initialize a new TrailDBConstructor. @param {String} options.path - TrailDB output path (without .tdb). @param {Array[String]} options.fieldNames - Array of field names in this TrailDB. @return {Object} cons - TrailDB constructor object.
[ "TrailDBConstructor", "class", "Construct", "a", "new", "TrailDB", ".", "Initialize", "a", "new", "TrailDBConstructor", "." ]
c174ae3e417877eeeae6e0e1af013a7182f6c65a
https://github.com/poynt/traildb-node/blob/c174ae3e417877eeeae6e0e1af013a7182f6c65a/lib/traildb.js#L324-L359
48,511
poynt/traildb-node
lib/traildb.js
function (options) { this._db = lib.tdb_init(); const r = lib.tdb_open(this._db, ref.allocCString(options.path)); if (r !== 0) { throw new TrailDBError('Could not open TrailDB: ' + r); } this.numTrails = lib.tdb_num_trails(this._db); this.numEvents = lib.tdb_num_events(this._db); this.numFields = lib.tdb_num_fields(this._db); this.fieldNames = []; this.fieldNameToId = {}; for (let i = 0; i < this.numFields; i++) { this.fieldNames[i] = lib.tdb_get_field_name(this._db, i); this.fieldNameToId[this.fieldNames[i]] = i; } return this; }
javascript
function (options) { this._db = lib.tdb_init(); const r = lib.tdb_open(this._db, ref.allocCString(options.path)); if (r !== 0) { throw new TrailDBError('Could not open TrailDB: ' + r); } this.numTrails = lib.tdb_num_trails(this._db); this.numEvents = lib.tdb_num_events(this._db); this.numFields = lib.tdb_num_fields(this._db); this.fieldNames = []; this.fieldNameToId = {}; for (let i = 0; i < this.numFields; i++) { this.fieldNames[i] = lib.tdb_get_field_name(this._db, i); this.fieldNameToId[this.fieldNames[i]] = i; } return this; }
[ "function", "(", "options", ")", "{", "this", ".", "_db", "=", "lib", ".", "tdb_init", "(", ")", ";", "const", "r", "=", "lib", ".", "tdb_open", "(", "this", ".", "_db", ",", "ref", ".", "allocCString", "(", "options", ".", "path", ")", ")", ";", "if", "(", "r", "!==", "0", ")", "{", "throw", "new", "TrailDBError", "(", "'Could not open TrailDB: '", "+", "r", ")", ";", "}", "this", ".", "numTrails", "=", "lib", ".", "tdb_num_trails", "(", "this", ".", "_db", ")", ";", "this", ".", "numEvents", "=", "lib", ".", "tdb_num_events", "(", "this", ".", "_db", ")", ";", "this", ".", "numFields", "=", "lib", ".", "tdb_num_fields", "(", "this", ".", "_db", ")", ";", "this", ".", "fieldNames", "=", "[", "]", ";", "this", ".", "fieldNameToId", "=", "{", "}", ";", "for", "(", "let", "i", "=", "0", ";", "i", "<", "this", ".", "numFields", ";", "i", "++", ")", "{", "this", ".", "fieldNames", "[", "i", "]", "=", "lib", ".", "tdb_get_field_name", "(", "this", ".", "_db", ",", "i", ")", ";", "this", ".", "fieldNameToId", "[", "this", ".", "fieldNames", "[", "i", "]", "]", "=", "i", ";", "}", "return", "this", ";", "}" ]
TrailDB class Query a TrailDB. Opens a TrailDB at path. @param {String} options.path - TrailDB output path (without .tdb). @return {Object} tdb - TrailDB object.
[ "TrailDB", "class", "Query", "a", "TrailDB", ".", "Opens", "a", "TrailDB", "at", "path", "." ]
c174ae3e417877eeeae6e0e1af013a7182f6c65a
https://github.com/poynt/traildb-node/blob/c174ae3e417877eeeae6e0e1af013a7182f6c65a/lib/traildb.js#L470-L490
48,512
deanlandolt/bytewise-core
util.js
encodeBound
function encodeBound(data, base) { var prefix = data.prefix var buffer = prefix ? base.encode(prefix, null) : new Buffer([ data.byte ]) if (data.upper) buffer = Buffer.concat([ buffer, new Buffer([ 0xff ]) ]) return util.encodedBound(data, buffer) }
javascript
function encodeBound(data, base) { var prefix = data.prefix var buffer = prefix ? base.encode(prefix, null) : new Buffer([ data.byte ]) if (data.upper) buffer = Buffer.concat([ buffer, new Buffer([ 0xff ]) ]) return util.encodedBound(data, buffer) }
[ "function", "encodeBound", "(", "data", ",", "base", ")", "{", "var", "prefix", "=", "data", ".", "prefix", "var", "buffer", "=", "prefix", "?", "base", ".", "encode", "(", "prefix", ",", "null", ")", ":", "new", "Buffer", "(", "[", "data", ".", "byte", "]", ")", "if", "(", "data", ".", "upper", ")", "buffer", "=", "Buffer", ".", "concat", "(", "[", "buffer", ",", "new", "Buffer", "(", "[", "0xff", "]", ")", "]", ")", "return", "util", ".", "encodedBound", "(", "data", ",", "buffer", ")", "}" ]
helpers for encoding boundary types
[ "helpers", "for", "encoding", "boundary", "types" ]
293f2eb2623903baf0fc02fd81a770f06d62c8de
https://github.com/deanlandolt/bytewise-core/blob/293f2eb2623903baf0fc02fd81a770f06d62c8de/util.js#L286-L294
48,513
zackurben/event-chain
lib/index.js
function(required, cb) { var chain = new Chain(config); chain.on(required, cb); return chain; }
javascript
function(required, cb) { var chain = new Chain(config); chain.on(required, cb); return chain; }
[ "function", "(", "required", ",", "cb", ")", "{", "var", "chain", "=", "new", "Chain", "(", "config", ")", ";", "chain", ".", "on", "(", "required", ",", "cb", ")", ";", "return", "chain", ";", "}" ]
EventChain factory. @param required The list of events that are required before invoking the callback function. @param cb The callback to invoke after all required events have been fired. @returns {Chain|exports|module.exports}
[ "EventChain", "factory", "." ]
d6b12f569afb58cb6b01e85dbb7dbf320583ed7b
https://github.com/zackurben/event-chain/blob/d6b12f569afb58cb6b01e85dbb7dbf320583ed7b/lib/index.js#L23-L27
48,514
alexindigo/batcher
lib/command_factory.js
commandFactory
function commandFactory(combos, cmd) { var command; // if no combos provided // consider it as a single command run if (!cmd) { cmd = combos; combos = [{}]; } command = partial(iterate, combos, cmd); command.commandDescription = partial(commandDescription, cmd); return command; }
javascript
function commandFactory(combos, cmd) { var command; // if no combos provided // consider it as a single command run if (!cmd) { cmd = combos; combos = [{}]; } command = partial(iterate, combos, cmd); command.commandDescription = partial(commandDescription, cmd); return command; }
[ "function", "commandFactory", "(", "combos", ",", "cmd", ")", "{", "var", "command", ";", "// if no combos provided", "// consider it as a single command run", "if", "(", "!", "cmd", ")", "{", "cmd", "=", "combos", ";", "combos", "=", "[", "{", "}", "]", ";", "}", "command", "=", "partial", "(", "iterate", ",", "combos", ",", "cmd", ")", ";", "command", ".", "commandDescription", "=", "partial", "(", "commandDescription", ",", "cmd", ")", ";", "return", "command", ";", "}" ]
Creates command executor from state property @param {array|string} [combos] – list of combinations @param {string} cmd - state property to get command from @returns {function} function that executes the command
[ "Creates", "command", "executor", "from", "state", "property" ]
73d9c8c994f915688db0627ea3b4854ead771138
https://github.com/alexindigo/batcher/blob/73d9c8c994f915688db0627ea3b4854ead771138/lib/command_factory.js#L23-L38
48,515
alexindigo/batcher
lib/command_factory.js
forEachFactory
function forEachFactory(properties) { // expand object's combinations into an array of objects if (typeOf(properties) == 'object') { properties = cartesian(clone(properties)); } return {command: partial(commandFactory, properties)}; }
javascript
function forEachFactory(properties) { // expand object's combinations into an array of objects if (typeOf(properties) == 'object') { properties = cartesian(clone(properties)); } return {command: partial(commandFactory, properties)}; }
[ "function", "forEachFactory", "(", "properties", ")", "{", "// expand object's combinations into an array of objects", "if", "(", "typeOf", "(", "properties", ")", "==", "'object'", ")", "{", "properties", "=", "cartesian", "(", "clone", "(", "properties", ")", ")", ";", "}", "return", "{", "command", ":", "partial", "(", "commandFactory", ",", "properties", ")", "}", ";", "}" ]
Constructs set of commands for each property of the passed object with loops over passed arrays @param {object|array|string} properties - list of properties to run a command with @returns {object} run command factory
[ "Constructs", "set", "of", "commands", "for", "each", "property", "of", "the", "passed", "object", "with", "loops", "over", "passed", "arrays" ]
73d9c8c994f915688db0627ea3b4854ead771138
https://github.com/alexindigo/batcher/blob/73d9c8c994f915688db0627ea3b4854ead771138/lib/command_factory.js#L47-L56
48,516
alexindigo/batcher
lib/command_factory.js
valueFactory
function valueFactory(value) { function command(cb) { cb(null, value); } command.commandDescription = partial(commandDescription, 'VALUE SETTER'); return command; }
javascript
function valueFactory(value) { function command(cb) { cb(null, value); } command.commandDescription = partial(commandDescription, 'VALUE SETTER'); return command; }
[ "function", "valueFactory", "(", "value", ")", "{", "function", "command", "(", "cb", ")", "{", "cb", "(", "null", ",", "value", ")", ";", "}", "command", ".", "commandDescription", "=", "partial", "(", "commandDescription", ",", "'VALUE SETTER'", ")", ";", "return", "command", ";", "}" ]
Creates function that returns provided value @param {mixed} value - value to return during execution time @returns {function} function that executes the command
[ "Creates", "function", "that", "returns", "provided", "value" ]
73d9c8c994f915688db0627ea3b4854ead771138
https://github.com/alexindigo/batcher/blob/73d9c8c994f915688db0627ea3b4854ead771138/lib/command_factory.js#L64-L72
48,517
alexindigo/batcher
lib/command_factory.js
commandDescription
function commandDescription(desc, state) { desc = state[desc] || desc; return desc.join ? '[' + desc.join(', ') + ']' : desc.toString(); }
javascript
function commandDescription(desc, state) { desc = state[desc] || desc; return desc.join ? '[' + desc.join(', ') + ']' : desc.toString(); }
[ "function", "commandDescription", "(", "desc", ",", "state", ")", "{", "desc", "=", "state", "[", "desc", "]", "||", "desc", ";", "return", "desc", ".", "join", "?", "'['", "+", "desc", ".", "join", "(", "', '", ")", "+", "']'", ":", "desc", ".", "toString", "(", ")", ";", "}" ]
Provides command description, finds matching within state object or uses provided one as is @private @param {string} desc - command's description or property to fetch command from current state @param {object} state - current state @returns {string} - command's description
[ "Provides", "command", "description", "finds", "matching", "within", "state", "object", "or", "uses", "provided", "one", "as", "is" ]
73d9c8c994f915688db0627ea3b4854ead771138
https://github.com/alexindigo/batcher/blob/73d9c8c994f915688db0627ea3b4854ead771138/lib/command_factory.js#L84-L88
48,518
alexindigo/batcher
lib/command_factory.js
iterate
function iterate(accumulator, combos, cmd, callback) { var params; // initial call might not have accumulator if (arguments.length == 3) { callback = cmd; cmd = combos; combos = accumulator; accumulator = []; } // resolve params from combo reference if (typeof combos == 'string') { // only work with arrays and object this way params = null; // get elements one by one from the array // consider number of elements in `accumulator` // as number of processed from referenced array if (Array.isArray(this[combos]) && this[combos][accumulator.length]) { params = {}; params[combos] = this[combos][accumulator.length]; } // if object gets referenced // create list of combinations out of it // and use array logic to resolve // current iteration params else if (typeOf(this[combos]) == 'object') { params = cartesian(clone(this[combos]))[accumulator.length]; } } else { // get another combination params = combos.shift(); } // when done with the combos // invoke callback if (!params) { // if it's a single element, return it as is callback(null, (accumulator && accumulator.length == 1) ? accumulator[0] : accumulator); return; } // if command name doesn't as state property // consider it as standalone command runCommand.call(this, params, this[cmd] || cmd, function(err, output) { accumulator.push(output); if (err) { callback(err, accumulator); return; } // rinse, repeat iterate.call(this, accumulator, combos, cmd, callback); }.bind(this)); }
javascript
function iterate(accumulator, combos, cmd, callback) { var params; // initial call might not have accumulator if (arguments.length == 3) { callback = cmd; cmd = combos; combos = accumulator; accumulator = []; } // resolve params from combo reference if (typeof combos == 'string') { // only work with arrays and object this way params = null; // get elements one by one from the array // consider number of elements in `accumulator` // as number of processed from referenced array if (Array.isArray(this[combos]) && this[combos][accumulator.length]) { params = {}; params[combos] = this[combos][accumulator.length]; } // if object gets referenced // create list of combinations out of it // and use array logic to resolve // current iteration params else if (typeOf(this[combos]) == 'object') { params = cartesian(clone(this[combos]))[accumulator.length]; } } else { // get another combination params = combos.shift(); } // when done with the combos // invoke callback if (!params) { // if it's a single element, return it as is callback(null, (accumulator && accumulator.length == 1) ? accumulator[0] : accumulator); return; } // if command name doesn't as state property // consider it as standalone command runCommand.call(this, params, this[cmd] || cmd, function(err, output) { accumulator.push(output); if (err) { callback(err, accumulator); return; } // rinse, repeat iterate.call(this, accumulator, combos, cmd, callback); }.bind(this)); }
[ "function", "iterate", "(", "accumulator", ",", "combos", ",", "cmd", ",", "callback", ")", "{", "var", "params", ";", "// initial call might not have accumulator", "if", "(", "arguments", ".", "length", "==", "3", ")", "{", "callback", "=", "cmd", ";", "cmd", "=", "combos", ";", "combos", "=", "accumulator", ";", "accumulator", "=", "[", "]", ";", "}", "// resolve params from combo reference", "if", "(", "typeof", "combos", "==", "'string'", ")", "{", "// only work with arrays and object this way", "params", "=", "null", ";", "// get elements one by one from the array", "// consider number of elements in `accumulator`", "// as number of processed from referenced array", "if", "(", "Array", ".", "isArray", "(", "this", "[", "combos", "]", ")", "&&", "this", "[", "combos", "]", "[", "accumulator", ".", "length", "]", ")", "{", "params", "=", "{", "}", ";", "params", "[", "combos", "]", "=", "this", "[", "combos", "]", "[", "accumulator", ".", "length", "]", ";", "}", "// if object gets referenced", "// create list of combinations out of it", "// and use array logic to resolve", "// current iteration params", "else", "if", "(", "typeOf", "(", "this", "[", "combos", "]", ")", "==", "'object'", ")", "{", "params", "=", "cartesian", "(", "clone", "(", "this", "[", "combos", "]", ")", ")", "[", "accumulator", ".", "length", "]", ";", "}", "}", "else", "{", "// get another combination", "params", "=", "combos", ".", "shift", "(", ")", ";", "}", "// when done with the combos", "// invoke callback", "if", "(", "!", "params", ")", "{", "// if it's a single element, return it as is", "callback", "(", "null", ",", "(", "accumulator", "&&", "accumulator", ".", "length", "==", "1", ")", "?", "accumulator", "[", "0", "]", ":", "accumulator", ")", ";", "return", ";", "}", "// if command name doesn't as state property", "// consider it as standalone command", "runCommand", ".", "call", "(", "this", ",", "params", ",", "this", "[", "cmd", "]", "||", "cmd", ",", "function", "(", "err", ",", "output", ")", "{", "accumulator", ".", "push", "(", "output", ")", ";", "if", "(", "err", ")", "{", "callback", "(", "err", ",", "accumulator", ")", ";", "return", ";", "}", "// rinse, repeat", "iterate", ".", "call", "(", "this", ",", "accumulator", ",", "combos", ",", "cmd", ",", "callback", ")", ";", "}", ".", "bind", "(", "this", ")", ")", ";", "}" ]
Runs provided command with each of the combinations @private @param {array} [accumulator] – accumulates commands output @param {array|string} combos – list of combinations @param {string|array} cmd - command to run @param {function} callback - invoked after commands finished executing @returns {void}
[ "Runs", "provided", "command", "with", "each", "of", "the", "combinations" ]
73d9c8c994f915688db0627ea3b4854ead771138
https://github.com/alexindigo/batcher/blob/73d9c8c994f915688db0627ea3b4854ead771138/lib/command_factory.js#L100-L167
48,519
rtm/upward
src/Ass.js
keepAssigned
function keepAssigned(...objs) { var ka = create(keepAssignedPrototype); defineProperty(ka, 'objs', { value: [] }); // first-come first-served [...objs].forEach(o => _keepAssigned(ka, o)); return ka; }
javascript
function keepAssigned(...objs) { var ka = create(keepAssignedPrototype); defineProperty(ka, 'objs', { value: [] }); // first-come first-served [...objs].forEach(o => _keepAssigned(ka, o)); return ka; }
[ "function", "keepAssigned", "(", "...", "objs", ")", "{", "var", "ka", "=", "create", "(", "keepAssignedPrototype", ")", ";", "defineProperty", "(", "ka", ",", "'objs'", ",", "{", "value", ":", "[", "]", "}", ")", ";", "// first-come first-served", "[", "...", "objs", "]", ".", "forEach", "(", "o", "=>", "_keepAssigned", "(", "ka", ",", "o", ")", ")", ";", "return", "ka", ";", "}" ]
Create the `keepAssigned` object.
[ "Create", "the", "keepAssigned", "object", "." ]
82495c34f70c9a4336a3b34cc6781e5662324c03
https://github.com/rtm/upward/blob/82495c34f70c9a4336a3b34cc6781e5662324c03/src/Ass.js#L20-L25
48,520
rtm/upward
src/Ass.js
findFirstProp
function findFirstProp(objs, p) { for (let obj of objs) { if (obj && obj.hasOwnProperty(p)) { return valueize(obj[p]); } } }
javascript
function findFirstProp(objs, p) { for (let obj of objs) { if (obj && obj.hasOwnProperty(p)) { return valueize(obj[p]); } } }
[ "function", "findFirstProp", "(", "objs", ",", "p", ")", "{", "for", "(", "let", "obj", "of", "objs", ")", "{", "if", "(", "obj", "&&", "obj", ".", "hasOwnProperty", "(", "p", ")", ")", "{", "return", "valueize", "(", "obj", "[", "p", "]", ")", ";", "}", "}", "}" ]
Return property's value from the first object in which it appears.
[ "Return", "property", "s", "value", "from", "the", "first", "object", "in", "which", "it", "appears", "." ]
82495c34f70c9a4336a3b34cc6781e5662324c03
https://github.com/rtm/upward/blob/82495c34f70c9a4336a3b34cc6781e5662324c03/src/Ass.js#L28-L32
48,521
rtm/upward
src/Ass.js
calcProp
function calcProp(ka, p) { var val = ka[p]; if (isKeepAssigned(val)) { recalc(val); } else { val.val = findFirstProp(ka.objs, p); } }
javascript
function calcProp(ka, p) { var val = ka[p]; if (isKeepAssigned(val)) { recalc(val); } else { val.val = findFirstProp(ka.objs, p); } }
[ "function", "calcProp", "(", "ka", ",", "p", ")", "{", "var", "val", "=", "ka", "[", "p", "]", ";", "if", "(", "isKeepAssigned", "(", "val", ")", ")", "{", "recalc", "(", "val", ")", ";", "}", "else", "{", "val", ".", "val", "=", "findFirstProp", "(", "ka", ".", "objs", ",", "p", ")", ";", "}", "}" ]
Calculate value for a property, recursively.
[ "Calculate", "value", "for", "a", "property", "recursively", "." ]
82495c34f70c9a4336a3b34cc6781e5662324c03
https://github.com/rtm/upward/blob/82495c34f70c9a4336a3b34cc6781e5662324c03/src/Ass.js#L35-L42
48,522
rtm/upward
src/Ass.js
placeKey
function placeKey(ka, v, k, pusher) { if (isObject(v)) { if (k in ka) { _keepAssigned(ka[k], v, pusher); } else { ka[k] = subKeepAssigned(ka.objs, k, pusher); } } else { if (k in ka) { ka[k].val = calcProp(ka, k); } else { defineProperty(ka, k, { get() { return U(findFirstProp(ka.objs, k)); }, enumerable: true }); //upward(v, ka[k]); } } }
javascript
function placeKey(ka, v, k, pusher) { if (isObject(v)) { if (k in ka) { _keepAssigned(ka[k], v, pusher); } else { ka[k] = subKeepAssigned(ka.objs, k, pusher); } } else { if (k in ka) { ka[k].val = calcProp(ka, k); } else { defineProperty(ka, k, { get() { return U(findFirstProp(ka.objs, k)); }, enumerable: true }); //upward(v, ka[k]); } } }
[ "function", "placeKey", "(", "ka", ",", "v", ",", "k", ",", "pusher", ")", "{", "if", "(", "isObject", "(", "v", ")", ")", "{", "if", "(", "k", "in", "ka", ")", "{", "_keepAssigned", "(", "ka", "[", "k", "]", ",", "v", ",", "pusher", ")", ";", "}", "else", "{", "ka", "[", "k", "]", "=", "subKeepAssigned", "(", "ka", ".", "objs", ",", "k", ",", "pusher", ")", ";", "}", "}", "else", "{", "if", "(", "k", "in", "ka", ")", "{", "ka", "[", "k", "]", ".", "val", "=", "calcProp", "(", "ka", ",", "k", ")", ";", "}", "else", "{", "defineProperty", "(", "ka", ",", "k", ",", "{", "get", "(", ")", "{", "return", "U", "(", "findFirstProp", "(", "ka", ".", "objs", ",", "k", ")", ")", ";", "}", ",", "enumerable", ":", "true", "}", ")", ";", "//upward(v, ka[k]);", "}", "}", "}" ]
Place a key in the kept object.
[ "Place", "a", "key", "in", "the", "kept", "object", "." ]
82495c34f70c9a4336a3b34cc6781e5662324c03
https://github.com/rtm/upward/blob/82495c34f70c9a4336a3b34cc6781e5662324c03/src/Ass.js#L45-L63
48,523
rtm/upward
src/Ass.js
recalc
function recalc(ka) { for (let [key, val] of objectPairs(ka)) { if (isKeepAssigned(val)) { recalc(val); } else { val.val = getter(key); } } }
javascript
function recalc(ka) { for (let [key, val] of objectPairs(ka)) { if (isKeepAssigned(val)) { recalc(val); } else { val.val = getter(key); } } }
[ "function", "recalc", "(", "ka", ")", "{", "for", "(", "let", "[", "key", ",", "val", "]", "of", "objectPairs", "(", "ka", ")", ")", "{", "if", "(", "isKeepAssigned", "(", "val", ")", ")", "{", "recalc", "(", "val", ")", ";", "}", "else", "{", "val", ".", "val", "=", "getter", "(", "key", ")", ";", "}", "}", "}" ]
Recalculate values for all keys, as when an object changes.
[ "Recalculate", "values", "for", "all", "keys", "as", "when", "an", "object", "changes", "." ]
82495c34f70c9a4336a3b34cc6781e5662324c03
https://github.com/rtm/upward/blob/82495c34f70c9a4336a3b34cc6781e5662324c03/src/Ass.js#L66-L71
48,524
rtm/upward
src/Ass.js
subKeepAssigned
function subKeepAssigned(objs, k, pusher) { var ka = keepAssigned(); objs .map(propGetter(k)) .filter(Boolean) .forEach(o => _keepAssigned(ka, o, pusher)); return ka; }
javascript
function subKeepAssigned(objs, k, pusher) { var ka = keepAssigned(); objs .map(propGetter(k)) .filter(Boolean) .forEach(o => _keepAssigned(ka, o, pusher)); return ka; }
[ "function", "subKeepAssigned", "(", "objs", ",", "k", ",", "pusher", ")", "{", "var", "ka", "=", "keepAssigned", "(", ")", ";", "objs", ".", "map", "(", "propGetter", "(", "k", ")", ")", ".", "filter", "(", "Boolean", ")", ".", "forEach", "(", "o", "=>", "_keepAssigned", "(", "ka", ",", "o", ",", "pusher", ")", ")", ";", "return", "ka", ";", "}" ]
Make a keepAssigned object for subobjects with some key.
[ "Make", "a", "keepAssigned", "object", "for", "subobjects", "with", "some", "key", "." ]
82495c34f70c9a4336a3b34cc6781e5662324c03
https://github.com/rtm/upward/blob/82495c34f70c9a4336a3b34cc6781e5662324c03/src/Ass.js#L74-L81
48,525
rtm/upward
src/Ass.js
_keepAssigned
function _keepAssigned(ka, o, pusher = unshift) { // Handle an upwardable object changing, in case of `O(model.obj)`. function objectChanged(_o) { replace(ka.objs, o, _o); recalc(ka); } // @TODO: figure out how to handle this. // upward(o, objectChanged); function key(v, k) { placeKey(ka, v, k); } function update(k, v) { processKey(k, v); } function _delete(k) { recalc(ka); } var handlers = { add: argify(placeKey, ka), update: argify(placeKey, ka), delete: _delete }; observeObject(o, makeObserver(handlers)); pusher.call(ka.objs, o); mapObject(o, (v, k) => placeKey(ka, v, k, pusher)); return ka; }
javascript
function _keepAssigned(ka, o, pusher = unshift) { // Handle an upwardable object changing, in case of `O(model.obj)`. function objectChanged(_o) { replace(ka.objs, o, _o); recalc(ka); } // @TODO: figure out how to handle this. // upward(o, objectChanged); function key(v, k) { placeKey(ka, v, k); } function update(k, v) { processKey(k, v); } function _delete(k) { recalc(ka); } var handlers = { add: argify(placeKey, ka), update: argify(placeKey, ka), delete: _delete }; observeObject(o, makeObserver(handlers)); pusher.call(ka.objs, o); mapObject(o, (v, k) => placeKey(ka, v, k, pusher)); return ka; }
[ "function", "_keepAssigned", "(", "ka", ",", "o", ",", "pusher", "=", "unshift", ")", "{", "// Handle an upwardable object changing, in case of `O(model.obj)`.", "function", "objectChanged", "(", "_o", ")", "{", "replace", "(", "ka", ".", "objs", ",", "o", ",", "_o", ")", ";", "recalc", "(", "ka", ")", ";", "}", "// @TODO: figure out how to handle this.", "// upward(o, objectChanged);", "function", "key", "(", "v", ",", "k", ")", "{", "placeKey", "(", "ka", ",", "v", ",", "k", ")", ";", "}", "function", "update", "(", "k", ",", "v", ")", "{", "processKey", "(", "k", ",", "v", ")", ";", "}", "function", "_delete", "(", "k", ")", "{", "recalc", "(", "ka", ")", ";", "}", "var", "handlers", "=", "{", "add", ":", "argify", "(", "placeKey", ",", "ka", ")", ",", "update", ":", "argify", "(", "placeKey", ",", "ka", ")", ",", "delete", ":", "_delete", "}", ";", "observeObject", "(", "o", ",", "makeObserver", "(", "handlers", ")", ")", ";", "pusher", ".", "call", "(", "ka", ".", "objs", ",", "o", ")", ";", "mapObject", "(", "o", ",", "(", "v", ",", "k", ")", "=>", "placeKey", "(", "ka", ",", "v", ",", "k", ",", "pusher", ")", ")", ";", "return", "ka", ";", "}" ]
Push one object onto a keepAssigned object, either at the front or back.
[ "Push", "one", "object", "onto", "a", "keepAssigned", "object", "either", "at", "the", "front", "or", "back", "." ]
82495c34f70c9a4336a3b34cc6781e5662324c03
https://github.com/rtm/upward/blob/82495c34f70c9a4336a3b34cc6781e5662324c03/src/Ass.js#L84-L117
48,526
iLambda/sparse-binary-matrix
lib/sbm.js
function(source, dimension) { // create the matrix var mat = {} // if dimension is an integer, the matrix is square if (_.isFunction(source) && _.isInteger(dimension) && dimension >= 0) { dimension = { x:dimension, y:dimension } } // source can be a 2-var predicate function or a line based matrix if (_.isFunction(source) && dimension && _.isInteger(dimension.x) && dimension.x >= 0 && _.isInteger(dimension.y) && dimension.y >= 0) { // creating the matrix mat.x = dimension.x mat.y = dimension.y mat.data = [] // populate for (var i = 0; i < mat.x; i++) { mat.data.push([]) for (var j = 0; j < mat.y; j++) { if (source(i, j)) { mat.data[i].push(j) } } } } else if (_.isArray(source) && source[0] && _.isArray(source[0])) { // creating the matrix mat.x = source.length mat.y = source[0].length mat.data = [] // populate for (var i = 0; i < mat.x; i++) { mat.data.push([]) for (var j = 0; j < mat.y; j++) { if (source[i][j]) { mat.data[i].push(j) } } } } // return the matrix return mat }
javascript
function(source, dimension) { // create the matrix var mat = {} // if dimension is an integer, the matrix is square if (_.isFunction(source) && _.isInteger(dimension) && dimension >= 0) { dimension = { x:dimension, y:dimension } } // source can be a 2-var predicate function or a line based matrix if (_.isFunction(source) && dimension && _.isInteger(dimension.x) && dimension.x >= 0 && _.isInteger(dimension.y) && dimension.y >= 0) { // creating the matrix mat.x = dimension.x mat.y = dimension.y mat.data = [] // populate for (var i = 0; i < mat.x; i++) { mat.data.push([]) for (var j = 0; j < mat.y; j++) { if (source(i, j)) { mat.data[i].push(j) } } } } else if (_.isArray(source) && source[0] && _.isArray(source[0])) { // creating the matrix mat.x = source.length mat.y = source[0].length mat.data = [] // populate for (var i = 0; i < mat.x; i++) { mat.data.push([]) for (var j = 0; j < mat.y; j++) { if (source[i][j]) { mat.data[i].push(j) } } } } // return the matrix return mat }
[ "function", "(", "source", ",", "dimension", ")", "{", "// create the matrix", "var", "mat", "=", "{", "}", "// if dimension is an integer, the matrix is square", "if", "(", "_", ".", "isFunction", "(", "source", ")", "&&", "_", ".", "isInteger", "(", "dimension", ")", "&&", "dimension", ">=", "0", ")", "{", "dimension", "=", "{", "x", ":", "dimension", ",", "y", ":", "dimension", "}", "}", "// source can be a 2-var predicate function or a line based matrix", "if", "(", "_", ".", "isFunction", "(", "source", ")", "&&", "dimension", "&&", "_", ".", "isInteger", "(", "dimension", ".", "x", ")", "&&", "dimension", ".", "x", ">=", "0", "&&", "_", ".", "isInteger", "(", "dimension", ".", "y", ")", "&&", "dimension", ".", "y", ">=", "0", ")", "{", "// creating the matrix", "mat", ".", "x", "=", "dimension", ".", "x", "mat", ".", "y", "=", "dimension", ".", "y", "mat", ".", "data", "=", "[", "]", "// populate", "for", "(", "var", "i", "=", "0", ";", "i", "<", "mat", ".", "x", ";", "i", "++", ")", "{", "mat", ".", "data", ".", "push", "(", "[", "]", ")", "for", "(", "var", "j", "=", "0", ";", "j", "<", "mat", ".", "y", ";", "j", "++", ")", "{", "if", "(", "source", "(", "i", ",", "j", ")", ")", "{", "mat", ".", "data", "[", "i", "]", ".", "push", "(", "j", ")", "}", "}", "}", "}", "else", "if", "(", "_", ".", "isArray", "(", "source", ")", "&&", "source", "[", "0", "]", "&&", "_", ".", "isArray", "(", "source", "[", "0", "]", ")", ")", "{", "// creating the matrix", "mat", ".", "x", "=", "source", ".", "length", "mat", ".", "y", "=", "source", "[", "0", "]", ".", "length", "mat", ".", "data", "=", "[", "]", "// populate", "for", "(", "var", "i", "=", "0", ";", "i", "<", "mat", ".", "x", ";", "i", "++", ")", "{", "mat", ".", "data", ".", "push", "(", "[", "]", ")", "for", "(", "var", "j", "=", "0", ";", "j", "<", "mat", ".", "y", ";", "j", "++", ")", "{", "if", "(", "source", "[", "i", "]", "[", "j", "]", ")", "{", "mat", ".", "data", "[", "i", "]", ".", "push", "(", "j", ")", "}", "}", "}", "}", "// return the matrix", "return", "mat", "}" ]
creates a sparse binary matrix
[ "creates", "a", "sparse", "binary", "matrix" ]
cface7e5679f7e7c71fa37a4967413589e02eb42
https://github.com/iLambda/sparse-binary-matrix/blob/cface7e5679f7e7c71fa37a4967413589e02eb42/lib/sbm.js#L5-L49
48,527
iLambda/sparse-binary-matrix
lib/sbm.js
function(sbm) { // creating matrix var mat = [] // populate for (var i = 0; i < sbm.x; i++) { mat.push([]) for (var j = 0; j < sbm.y; j++) { mat[i][j] = _.includes(sbm.data[i], j) ? 1 : 0 } } // return the matrix return mat }
javascript
function(sbm) { // creating matrix var mat = [] // populate for (var i = 0; i < sbm.x; i++) { mat.push([]) for (var j = 0; j < sbm.y; j++) { mat[i][j] = _.includes(sbm.data[i], j) ? 1 : 0 } } // return the matrix return mat }
[ "function", "(", "sbm", ")", "{", "// creating matrix", "var", "mat", "=", "[", "]", "// populate", "for", "(", "var", "i", "=", "0", ";", "i", "<", "sbm", ".", "x", ";", "i", "++", ")", "{", "mat", ".", "push", "(", "[", "]", ")", "for", "(", "var", "j", "=", "0", ";", "j", "<", "sbm", ".", "y", ";", "j", "++", ")", "{", "mat", "[", "i", "]", "[", "j", "]", "=", "_", ".", "includes", "(", "sbm", ".", "data", "[", "i", "]", ",", "j", ")", "?", "1", ":", "0", "}", "}", "// return the matrix", "return", "mat", "}" ]
returns the sbm in line-based matrix form
[ "returns", "the", "sbm", "in", "line", "-", "based", "matrix", "form" ]
cface7e5679f7e7c71fa37a4967413589e02eb42
https://github.com/iLambda/sparse-binary-matrix/blob/cface7e5679f7e7c71fa37a4967413589e02eb42/lib/sbm.js#L51-L63
48,528
iLambda/sparse-binary-matrix
lib/sbm.js
function(n) { n = _.isInteger(n) ? n : 0 return { x: n, y: n, data: _.map(_.range(n), function (num) { return [num] }) } }
javascript
function(n) { n = _.isInteger(n) ? n : 0 return { x: n, y: n, data: _.map(_.range(n), function (num) { return [num] }) } }
[ "function", "(", "n", ")", "{", "n", "=", "_", ".", "isInteger", "(", "n", ")", "?", "n", ":", "0", "return", "{", "x", ":", "n", ",", "y", ":", "n", ",", "data", ":", "_", ".", "map", "(", "_", ".", "range", "(", "n", ")", ",", "function", "(", "num", ")", "{", "return", "[", "num", "]", "}", ")", "}", "}" ]
returns the identity matrix for a given dimension
[ "returns", "the", "identity", "matrix", "for", "a", "given", "dimension" ]
cface7e5679f7e7c71fa37a4967413589e02eb42
https://github.com/iLambda/sparse-binary-matrix/blob/cface7e5679f7e7c71fa37a4967413589e02eb42/lib/sbm.js#L71-L81
48,529
iLambda/sparse-binary-matrix
lib/sbm.js
function(matrix) { // if not square if (matrix.x != matrix.y) { return } // return trace return _.filter(matrix.data, function (line, number) { return _.includes(line, number) }).length }
javascript
function(matrix) { // if not square if (matrix.x != matrix.y) { return } // return trace return _.filter(matrix.data, function (line, number) { return _.includes(line, number) }).length }
[ "function", "(", "matrix", ")", "{", "// if not square", "if", "(", "matrix", ".", "x", "!=", "matrix", ".", "y", ")", "{", "return", "}", "// return trace", "return", "_", ".", "filter", "(", "matrix", ".", "data", ",", "function", "(", "line", ",", "number", ")", "{", "return", "_", ".", "includes", "(", "line", ",", "number", ")", "}", ")", ".", "length", "}" ]
computes the trace of the matrix
[ "computes", "the", "trace", "of", "the", "matrix" ]
cface7e5679f7e7c71fa37a4967413589e02eb42
https://github.com/iLambda/sparse-binary-matrix/blob/cface7e5679f7e7c71fa37a4967413589e02eb42/lib/sbm.js#L110-L119
48,530
iLambda/sparse-binary-matrix
lib/sbm.js
function(sbm) { // create the matrix var mat = {} mat.x = sbm.y mat.y = sbm.x mat.data = [] // populate for (var i = 0; i < mat.x; i++) { mat.data.push([]) for (var j = 0; j < mat.y; j++) { if (_.includes(sbm.data[j], i)) { mat.data[i].push(j) } } } return mat }
javascript
function(sbm) { // create the matrix var mat = {} mat.x = sbm.y mat.y = sbm.x mat.data = [] // populate for (var i = 0; i < mat.x; i++) { mat.data.push([]) for (var j = 0; j < mat.y; j++) { if (_.includes(sbm.data[j], i)) { mat.data[i].push(j) } } } return mat }
[ "function", "(", "sbm", ")", "{", "// create the matrix", "var", "mat", "=", "{", "}", "mat", ".", "x", "=", "sbm", ".", "y", "mat", ".", "y", "=", "sbm", ".", "x", "mat", ".", "data", "=", "[", "]", "// populate", "for", "(", "var", "i", "=", "0", ";", "i", "<", "mat", ".", "x", ";", "i", "++", ")", "{", "mat", ".", "data", ".", "push", "(", "[", "]", ")", "for", "(", "var", "j", "=", "0", ";", "j", "<", "mat", ".", "y", ";", "j", "++", ")", "{", "if", "(", "_", ".", "includes", "(", "sbm", ".", "data", "[", "j", "]", ",", "i", ")", ")", "{", "mat", ".", "data", "[", "i", "]", ".", "push", "(", "j", ")", "}", "}", "}", "return", "mat", "}" ]
transposes the matrix
[ "transposes", "the", "matrix" ]
cface7e5679f7e7c71fa37a4967413589e02eb42
https://github.com/iLambda/sparse-binary-matrix/blob/cface7e5679f7e7c71fa37a4967413589e02eb42/lib/sbm.js#L122-L138
48,531
iLambda/sparse-binary-matrix
lib/sbm.js
function(sbmA, sbmB) { // check size if (sbmA.x !== sbmB.x || sbmA.y !== sbmB.y) { return false } // check return _.every(sbmA.data, function (line, idx) { return _.isEqual(line.sort(), sbmB.data[idx].sort()) }) }
javascript
function(sbmA, sbmB) { // check size if (sbmA.x !== sbmB.x || sbmA.y !== sbmB.y) { return false } // check return _.every(sbmA.data, function (line, idx) { return _.isEqual(line.sort(), sbmB.data[idx].sort()) }) }
[ "function", "(", "sbmA", ",", "sbmB", ")", "{", "// check size", "if", "(", "sbmA", ".", "x", "!==", "sbmB", ".", "x", "||", "sbmA", ".", "y", "!==", "sbmB", ".", "y", ")", "{", "return", "false", "}", "// check", "return", "_", ".", "every", "(", "sbmA", ".", "data", ",", "function", "(", "line", ",", "idx", ")", "{", "return", "_", ".", "isEqual", "(", "line", ".", "sort", "(", ")", ",", "sbmB", ".", "data", "[", "idx", "]", ".", "sort", "(", ")", ")", "}", ")", "}" ]
are both matrices equal ?
[ "are", "both", "matrices", "equal", "?" ]
cface7e5679f7e7c71fa37a4967413589e02eb42
https://github.com/iLambda/sparse-binary-matrix/blob/cface7e5679f7e7c71fa37a4967413589e02eb42/lib/sbm.js#L142-L152
48,532
iLambda/sparse-binary-matrix
lib/sbm.js
function(sbm) { // create the matrix var mat = {} mat.x = sbm.x mat.y = sbm.y mat.data = [] // populate for (var i = 0; i < mat.x; i++) { mat.data[i] = _.difference(_.range(mat.y), sbm.data[i]) } // return matrix return mat }
javascript
function(sbm) { // create the matrix var mat = {} mat.x = sbm.x mat.y = sbm.y mat.data = [] // populate for (var i = 0; i < mat.x; i++) { mat.data[i] = _.difference(_.range(mat.y), sbm.data[i]) } // return matrix return mat }
[ "function", "(", "sbm", ")", "{", "// create the matrix", "var", "mat", "=", "{", "}", "mat", ".", "x", "=", "sbm", ".", "x", "mat", ".", "y", "=", "sbm", ".", "y", "mat", ".", "data", "=", "[", "]", "// populate", "for", "(", "var", "i", "=", "0", ";", "i", "<", "mat", ".", "x", ";", "i", "++", ")", "{", "mat", ".", "data", "[", "i", "]", "=", "_", ".", "difference", "(", "_", ".", "range", "(", "mat", ".", "y", ")", ",", "sbm", ".", "data", "[", "i", "]", ")", "}", "// return matrix", "return", "mat", "}" ]
NOT the matrix
[ "NOT", "the", "matrix" ]
cface7e5679f7e7c71fa37a4967413589e02eb42
https://github.com/iLambda/sparse-binary-matrix/blob/cface7e5679f7e7c71fa37a4967413589e02eb42/lib/sbm.js#L155-L167
48,533
iLambda/sparse-binary-matrix
lib/sbm.js
function(sbmA, sbmB) { // if not the same sizes if (sbmA.x != sbmB.x || sbmA.y != sbmB.y) { return } // create the matrix var mat = {} mat.x = sbmA.x mat.y = sbmA.y mat.data = [] // populate for (var i = 0; i < mat.x; i++) { mat.data[i] = _.intersection(sbmA.data[i], sbmB.data[i]) } // return matrix return mat }
javascript
function(sbmA, sbmB) { // if not the same sizes if (sbmA.x != sbmB.x || sbmA.y != sbmB.y) { return } // create the matrix var mat = {} mat.x = sbmA.x mat.y = sbmA.y mat.data = [] // populate for (var i = 0; i < mat.x; i++) { mat.data[i] = _.intersection(sbmA.data[i], sbmB.data[i]) } // return matrix return mat }
[ "function", "(", "sbmA", ",", "sbmB", ")", "{", "// if not the same sizes", "if", "(", "sbmA", ".", "x", "!=", "sbmB", ".", "x", "||", "sbmA", ".", "y", "!=", "sbmB", ".", "y", ")", "{", "return", "}", "// create the matrix", "var", "mat", "=", "{", "}", "mat", ".", "x", "=", "sbmA", ".", "x", "mat", ".", "y", "=", "sbmA", ".", "y", "mat", ".", "data", "=", "[", "]", "// populate", "for", "(", "var", "i", "=", "0", ";", "i", "<", "mat", ".", "x", ";", "i", "++", ")", "{", "mat", ".", "data", "[", "i", "]", "=", "_", ".", "intersection", "(", "sbmA", ".", "data", "[", "i", "]", ",", "sbmB", ".", "data", "[", "i", "]", ")", "}", "// return matrix", "return", "mat", "}" ]
AND the two matrices
[ "AND", "the", "two", "matrices" ]
cface7e5679f7e7c71fa37a4967413589e02eb42
https://github.com/iLambda/sparse-binary-matrix/blob/cface7e5679f7e7c71fa37a4967413589e02eb42/lib/sbm.js#L169-L185
48,534
iLambda/sparse-binary-matrix
lib/sbm.js
function(sbmA, sbmB) { // if not the same sizes if (sbmA.x != sbmB.x || sbmA.y != sbmB.y) { return } // create the matrix var mat = {} mat.x = sbmA.x mat.y = sbmA.y mat.data = [] // populate for (var i = 0; i < mat.x; i++) { mat.data[i] = _.union(sbmA.data[i], sbmB.data[i]).sort() } // return matrix return mat }
javascript
function(sbmA, sbmB) { // if not the same sizes if (sbmA.x != sbmB.x || sbmA.y != sbmB.y) { return } // create the matrix var mat = {} mat.x = sbmA.x mat.y = sbmA.y mat.data = [] // populate for (var i = 0; i < mat.x; i++) { mat.data[i] = _.union(sbmA.data[i], sbmB.data[i]).sort() } // return matrix return mat }
[ "function", "(", "sbmA", ",", "sbmB", ")", "{", "// if not the same sizes", "if", "(", "sbmA", ".", "x", "!=", "sbmB", ".", "x", "||", "sbmA", ".", "y", "!=", "sbmB", ".", "y", ")", "{", "return", "}", "// create the matrix", "var", "mat", "=", "{", "}", "mat", ".", "x", "=", "sbmA", ".", "x", "mat", ".", "y", "=", "sbmA", ".", "y", "mat", ".", "data", "=", "[", "]", "// populate", "for", "(", "var", "i", "=", "0", ";", "i", "<", "mat", ".", "x", ";", "i", "++", ")", "{", "mat", ".", "data", "[", "i", "]", "=", "_", ".", "union", "(", "sbmA", ".", "data", "[", "i", "]", ",", "sbmB", ".", "data", "[", "i", "]", ")", ".", "sort", "(", ")", "}", "// return matrix", "return", "mat", "}" ]
OR the two matrices
[ "OR", "the", "two", "matrices" ]
cface7e5679f7e7c71fa37a4967413589e02eb42
https://github.com/iLambda/sparse-binary-matrix/blob/cface7e5679f7e7c71fa37a4967413589e02eb42/lib/sbm.js#L187-L203
48,535
iLambda/sparse-binary-matrix
lib/sbm.js
function(sbmA, sbmB) { // check if size compatible if (sbmA.y !== sbmB.x) { return } // create a new matrix return this.make((function (i, j) { return _.reduce(_.map(_.range(sbmA.y), (function(id) { return this.check(sbmA, i, id) && this.check(sbmB, id, j) }).bind(this)), function (sum, a) { return sum ^ a }) == 1 }).bind(this), { x: sbmA.x, y: sbmB.y }) }
javascript
function(sbmA, sbmB) { // check if size compatible if (sbmA.y !== sbmB.x) { return } // create a new matrix return this.make((function (i, j) { return _.reduce(_.map(_.range(sbmA.y), (function(id) { return this.check(sbmA, i, id) && this.check(sbmB, id, j) }).bind(this)), function (sum, a) { return sum ^ a }) == 1 }).bind(this), { x: sbmA.x, y: sbmB.y }) }
[ "function", "(", "sbmA", ",", "sbmB", ")", "{", "// check if size compatible", "if", "(", "sbmA", ".", "y", "!==", "sbmB", ".", "x", ")", "{", "return", "}", "// create a new matrix", "return", "this", ".", "make", "(", "(", "function", "(", "i", ",", "j", ")", "{", "return", "_", ".", "reduce", "(", "_", ".", "map", "(", "_", ".", "range", "(", "sbmA", ".", "y", ")", ",", "(", "function", "(", "id", ")", "{", "return", "this", ".", "check", "(", "sbmA", ",", "i", ",", "id", ")", "&&", "this", ".", "check", "(", "sbmB", ",", "id", ",", "j", ")", "}", ")", ".", "bind", "(", "this", ")", ")", ",", "function", "(", "sum", ",", "a", ")", "{", "return", "sum", "^", "a", "}", ")", "==", "1", "}", ")", ".", "bind", "(", "this", ")", ",", "{", "x", ":", "sbmA", ".", "x", ",", "y", ":", "sbmB", ".", "y", "}", ")", "}" ]
multiply two matrices
[ "multiply", "two", "matrices" ]
cface7e5679f7e7c71fa37a4967413589e02eb42
https://github.com/iLambda/sparse-binary-matrix/blob/cface7e5679f7e7c71fa37a4967413589e02eb42/lib/sbm.js#L226-L239
48,536
iLambda/sparse-binary-matrix
lib/sbm.js
function(sbm, n) { if (n == 0) { return this.identity(n) } else if (n == 1) { return sbm } else if (n % 2 == 0) { return this.pow(this.multiply(sbm, sbm), n/2) } else { return this.multiply(sbm, this.pow(this.multiply(sbm, sbm), (n-1)/2)) } }
javascript
function(sbm, n) { if (n == 0) { return this.identity(n) } else if (n == 1) { return sbm } else if (n % 2 == 0) { return this.pow(this.multiply(sbm, sbm), n/2) } else { return this.multiply(sbm, this.pow(this.multiply(sbm, sbm), (n-1)/2)) } }
[ "function", "(", "sbm", ",", "n", ")", "{", "if", "(", "n", "==", "0", ")", "{", "return", "this", ".", "identity", "(", "n", ")", "}", "else", "if", "(", "n", "==", "1", ")", "{", "return", "sbm", "}", "else", "if", "(", "n", "%", "2", "==", "0", ")", "{", "return", "this", ".", "pow", "(", "this", ".", "multiply", "(", "sbm", ",", "sbm", ")", ",", "n", "/", "2", ")", "}", "else", "{", "return", "this", ".", "multiply", "(", "sbm", ",", "this", ".", "pow", "(", "this", ".", "multiply", "(", "sbm", ",", "sbm", ")", ",", "(", "n", "-", "1", ")", "/", "2", ")", ")", "}", "}" ]
power of the matrix
[ "power", "of", "the", "matrix" ]
cface7e5679f7e7c71fa37a4967413589e02eb42
https://github.com/iLambda/sparse-binary-matrix/blob/cface7e5679f7e7c71fa37a4967413589e02eb42/lib/sbm.js#L241-L251
48,537
iLambda/sparse-binary-matrix
lib/sbm.js
function(sbm) { // if the matrix ain't square, symmetry is off if (sbm.x !== sbm.y) { return false } // symmetry status var symmetry = true // iterate for (var i = 0; i < sbm.x; i++) { for (var j = 0; j <= i; j++) { symmetry = symmetry && ((_.includes(sbm.data[i], j) ^ _.includes(sbm.data[j], i)) === 0) } } // return return symmetry }
javascript
function(sbm) { // if the matrix ain't square, symmetry is off if (sbm.x !== sbm.y) { return false } // symmetry status var symmetry = true // iterate for (var i = 0; i < sbm.x; i++) { for (var j = 0; j <= i; j++) { symmetry = symmetry && ((_.includes(sbm.data[i], j) ^ _.includes(sbm.data[j], i)) === 0) } } // return return symmetry }
[ "function", "(", "sbm", ")", "{", "// if the matrix ain't square, symmetry is off", "if", "(", "sbm", ".", "x", "!==", "sbm", ".", "y", ")", "{", "return", "false", "}", "// symmetry status", "var", "symmetry", "=", "true", "// iterate", "for", "(", "var", "i", "=", "0", ";", "i", "<", "sbm", ".", "x", ";", "i", "++", ")", "{", "for", "(", "var", "j", "=", "0", ";", "j", "<=", "i", ";", "j", "++", ")", "{", "symmetry", "=", "symmetry", "&&", "(", "(", "_", ".", "includes", "(", "sbm", ".", "data", "[", "i", "]", ",", "j", ")", "^", "_", ".", "includes", "(", "sbm", ".", "data", "[", "j", "]", ",", "i", ")", ")", "===", "0", ")", "}", "}", "// return", "return", "symmetry", "}" ]
returns true if the matrix is symmetric
[ "returns", "true", "if", "the", "matrix", "is", "symmetric" ]
cface7e5679f7e7c71fa37a4967413589e02eb42
https://github.com/iLambda/sparse-binary-matrix/blob/cface7e5679f7e7c71fa37a4967413589e02eb42/lib/sbm.js#L254-L270
48,538
iLambda/sparse-binary-matrix
lib/sbm.js
function(sbm) { return _.sum(_.map(sbm.data, function (ar) { return ar.length })) }
javascript
function(sbm) { return _.sum(_.map(sbm.data, function (ar) { return ar.length })) }
[ "function", "(", "sbm", ")", "{", "return", "_", ".", "sum", "(", "_", ".", "map", "(", "sbm", ".", "data", ",", "function", "(", "ar", ")", "{", "return", "ar", ".", "length", "}", ")", ")", "}" ]
returns the number of 1 in the matrix
[ "returns", "the", "number", "of", "1", "in", "the", "matrix" ]
cface7e5679f7e7c71fa37a4967413589e02eb42
https://github.com/iLambda/sparse-binary-matrix/blob/cface7e5679f7e7c71fa37a4967413589e02eb42/lib/sbm.js#L272-L274
48,539
Aigeec/mandrill-webhook-event-parser
src/mandrill-webhook-event-parser.js
function() { if (!(this instanceof EventParser)) { return new EventParser(); } /** * Parses Mandrill Events request. Sets mandrillEvents property on req. Expects body to contain decoded post body mandrill_events parameter. Please see Madrills article {@link https://mandrill.zendesk.com/hc/en-us/articles/205583207-What-is-the-format-of-inbound-email-webhooks- | What is the format of inbound email webhook } * @param { Request } req - Express request * @param { object } req.body - request body * @param { string } req.body.mandrill_events - JSON String of Mandrill events * @param { Response } res - Express response */ var parser = function(req, res, next) { if (req.body && req.body.mandrill_events) { try { req.mandrillEvents = JSON.parse(req.body.mandrill_events); next(); } catch (err) { next(err); } } else { next(new Error('No body or body is missing [mandrill_events] property')); } }; return parser; }
javascript
function() { if (!(this instanceof EventParser)) { return new EventParser(); } /** * Parses Mandrill Events request. Sets mandrillEvents property on req. Expects body to contain decoded post body mandrill_events parameter. Please see Madrills article {@link https://mandrill.zendesk.com/hc/en-us/articles/205583207-What-is-the-format-of-inbound-email-webhooks- | What is the format of inbound email webhook } * @param { Request } req - Express request * @param { object } req.body - request body * @param { string } req.body.mandrill_events - JSON String of Mandrill events * @param { Response } res - Express response */ var parser = function(req, res, next) { if (req.body && req.body.mandrill_events) { try { req.mandrillEvents = JSON.parse(req.body.mandrill_events); next(); } catch (err) { next(err); } } else { next(new Error('No body or body is missing [mandrill_events] property')); } }; return parser; }
[ "function", "(", ")", "{", "if", "(", "!", "(", "this", "instanceof", "EventParser", ")", ")", "{", "return", "new", "EventParser", "(", ")", ";", "}", "/**\n * Parses Mandrill Events request. Sets mandrillEvents property on req. Expects body to contain decoded post body mandrill_events parameter. Please see Madrills article {@link https://mandrill.zendesk.com/hc/en-us/articles/205583207-What-is-the-format-of-inbound-email-webhooks- | What is the format of inbound email webhook }\n * @param { Request } req - Express request\n * @param { object } req.body - request body\n * @param { string } req.body.mandrill_events - JSON String of Mandrill events\n * @param { Response } res - Express response\n */", "var", "parser", "=", "function", "(", "req", ",", "res", ",", "next", ")", "{", "if", "(", "req", ".", "body", "&&", "req", ".", "body", ".", "mandrill_events", ")", "{", "try", "{", "req", ".", "mandrillEvents", "=", "JSON", ".", "parse", "(", "req", ".", "body", ".", "mandrill_events", ")", ";", "next", "(", ")", ";", "}", "catch", "(", "err", ")", "{", "next", "(", "err", ")", ";", "}", "}", "else", "{", "next", "(", "new", "Error", "(", "'No body or body is missing [mandrill_events] property'", ")", ")", ";", "}", "}", ";", "return", "parser", ";", "}" ]
Simple express middleware for parsing Inbound Mandrill Webhook events @Module MandrillWebhookEventParser
[ "Simple", "express", "middleware", "for", "parsing", "Inbound", "Mandrill", "Webhook", "events" ]
94cffaa6e3258950d43e67aae0a5d6d04e3b948f
https://github.com/Aigeec/mandrill-webhook-event-parser/blob/94cffaa6e3258950d43e67aae0a5d6d04e3b948f/src/mandrill-webhook-event-parser.js#L12-L38
48,540
reelyactive/chickadee
lib/routes/associations.js
retrieveAssociations
function retrieveAssociations(req, res) { switch(req.accepts(['json', 'html'])) { // TODO: support HTML in future //case 'html': // res.sendFile(path.resolve(__dirname + '/../../web/association.html')); // break; default: var rootUrl = req.protocol + '://' + req.get('host'); var queryPath = req.originalUrl; req.chickadee.getAssociations(req, rootUrl, queryPath, function(response, status) { res.status(status).json(response); }); break; } }
javascript
function retrieveAssociations(req, res) { switch(req.accepts(['json', 'html'])) { // TODO: support HTML in future //case 'html': // res.sendFile(path.resolve(__dirname + '/../../web/association.html')); // break; default: var rootUrl = req.protocol + '://' + req.get('host'); var queryPath = req.originalUrl; req.chickadee.getAssociations(req, rootUrl, queryPath, function(response, status) { res.status(status).json(response); }); break; } }
[ "function", "retrieveAssociations", "(", "req", ",", "res", ")", "{", "switch", "(", "req", ".", "accepts", "(", "[", "'json'", ",", "'html'", "]", ")", ")", "{", "// TODO: support HTML in future", "//case 'html':", "// res.sendFile(path.resolve(__dirname + '/../../web/association.html'));", "// break;", "default", ":", "var", "rootUrl", "=", "req", ".", "protocol", "+", "'://'", "+", "req", ".", "get", "(", "'host'", ")", ";", "var", "queryPath", "=", "req", ".", "originalUrl", ";", "req", ".", "chickadee", ".", "getAssociations", "(", "req", ",", "rootUrl", ",", "queryPath", ",", "function", "(", "response", ",", "status", ")", "{", "res", ".", "status", "(", "status", ")", ".", "json", "(", "response", ")", ";", "}", ")", ";", "break", ";", "}", "}" ]
Retrieve all available associations. @param {Object} req The HTTP request. @param {Object} res The HTTP result.
[ "Retrieve", "all", "available", "associations", "." ]
1f65c2d369694d93796aae63318fa76326275120
https://github.com/reelyactive/chickadee/blob/1f65c2d369694d93796aae63318fa76326275120/lib/routes/associations.js#L83-L98
48,541
reelyactive/chickadee
lib/routes/associations.js
retrieveAssociation
function retrieveAssociation(req, res) { if(redirect(req.params.id, '', '', res)) { return; } switch(req.accepts(['json', 'html'])) { // TODO: support HTML in future //case 'html': // res.sendFile(path.resolve(__dirname + '/../../web/association.html')); // break; default: var id = req.params.id; var rootUrl = req.protocol + '://' + req.get('host'); var queryPath = req.originalUrl; req.chickadee.getAssociation(req, id, null, rootUrl, queryPath, function(response, status) { res.status(status).json(response); }); break; } }
javascript
function retrieveAssociation(req, res) { if(redirect(req.params.id, '', '', res)) { return; } switch(req.accepts(['json', 'html'])) { // TODO: support HTML in future //case 'html': // res.sendFile(path.resolve(__dirname + '/../../web/association.html')); // break; default: var id = req.params.id; var rootUrl = req.protocol + '://' + req.get('host'); var queryPath = req.originalUrl; req.chickadee.getAssociation(req, id, null, rootUrl, queryPath, function(response, status) { res.status(status).json(response); }); break; } }
[ "function", "retrieveAssociation", "(", "req", ",", "res", ")", "{", "if", "(", "redirect", "(", "req", ".", "params", ".", "id", ",", "''", ",", "''", ",", "res", ")", ")", "{", "return", ";", "}", "switch", "(", "req", ".", "accepts", "(", "[", "'json'", ",", "'html'", "]", ")", ")", "{", "// TODO: support HTML in future", "//case 'html':", "// res.sendFile(path.resolve(__dirname + '/../../web/association.html'));", "// break;", "default", ":", "var", "id", "=", "req", ".", "params", ".", "id", ";", "var", "rootUrl", "=", "req", ".", "protocol", "+", "'://'", "+", "req", ".", "get", "(", "'host'", ")", ";", "var", "queryPath", "=", "req", ".", "originalUrl", ";", "req", ".", "chickadee", ".", "getAssociation", "(", "req", ",", "id", ",", "null", ",", "rootUrl", ",", "queryPath", ",", "function", "(", "response", ",", "status", ")", "{", "res", ".", "status", "(", "status", ")", ".", "json", "(", "response", ")", ";", "}", ")", ";", "break", ";", "}", "}" ]
Retrieve the given association. @param {Object} req The HTTP request. @param {Object} res The HTTP result.
[ "Retrieve", "the", "given", "association", "." ]
1f65c2d369694d93796aae63318fa76326275120
https://github.com/reelyactive/chickadee/blob/1f65c2d369694d93796aae63318fa76326275120/lib/routes/associations.js#L106-L126
48,542
reelyactive/chickadee
lib/routes/associations.js
replaceAssociation
function replaceAssociation(req, res) { if(redirect(req.params.id, '', '', res)) { return; } var id = req.params.id; var url = req.body.url; var directory = req.body.directory; var tags = req.body.tags; var position = req.body.position; var rootUrl = req.protocol + '://' + req.get('host'); var queryPath = req.originalUrl; req.chickadee.setAssociation(req, id, url, directory, tags, position, rootUrl, queryPath, function(response, status) { res.status(status).json(response); }); }
javascript
function replaceAssociation(req, res) { if(redirect(req.params.id, '', '', res)) { return; } var id = req.params.id; var url = req.body.url; var directory = req.body.directory; var tags = req.body.tags; var position = req.body.position; var rootUrl = req.protocol + '://' + req.get('host'); var queryPath = req.originalUrl; req.chickadee.setAssociation(req, id, url, directory, tags, position, rootUrl, queryPath, function(response, status) { res.status(status).json(response); }); }
[ "function", "replaceAssociation", "(", "req", ",", "res", ")", "{", "if", "(", "redirect", "(", "req", ".", "params", ".", "id", ",", "''", ",", "''", ",", "res", ")", ")", "{", "return", ";", "}", "var", "id", "=", "req", ".", "params", ".", "id", ";", "var", "url", "=", "req", ".", "body", ".", "url", ";", "var", "directory", "=", "req", ".", "body", ".", "directory", ";", "var", "tags", "=", "req", ".", "body", ".", "tags", ";", "var", "position", "=", "req", ".", "body", ".", "position", ";", "var", "rootUrl", "=", "req", ".", "protocol", "+", "'://'", "+", "req", ".", "get", "(", "'host'", ")", ";", "var", "queryPath", "=", "req", ".", "originalUrl", ";", "req", ".", "chickadee", ".", "setAssociation", "(", "req", ",", "id", ",", "url", ",", "directory", ",", "tags", ",", "position", ",", "rootUrl", ",", "queryPath", ",", "function", "(", "response", ",", "status", ")", "{", "res", ".", "status", "(", "status", ")", ".", "json", "(", "response", ")", ";", "}", ")", ";", "}" ]
Replace the specified association. @param {Object} req The HTTP request. @param {Object} res The HTTP result.
[ "Replace", "the", "specified", "association", "." ]
1f65c2d369694d93796aae63318fa76326275120
https://github.com/reelyactive/chickadee/blob/1f65c2d369694d93796aae63318fa76326275120/lib/routes/associations.js#L134-L150
48,543
reelyactive/chickadee
lib/routes/associations.js
replaceAssociationPosition
function replaceAssociationPosition(req, res) { if(redirect(req.params.id, '../', '/tags', res)) { return; } var id = req.params.id; var position = req.body.position; var rootUrl = req.protocol + '://' + req.get('host'); var queryPath = req.originalUrl; req.chickadee.setAssociation(req, id, null, null, null, position, rootUrl, queryPath, function(response, status) { res.status(status).json(response); }); }
javascript
function replaceAssociationPosition(req, res) { if(redirect(req.params.id, '../', '/tags', res)) { return; } var id = req.params.id; var position = req.body.position; var rootUrl = req.protocol + '://' + req.get('host'); var queryPath = req.originalUrl; req.chickadee.setAssociation(req, id, null, null, null, position, rootUrl, queryPath, function(response, status) { res.status(status).json(response); }); }
[ "function", "replaceAssociationPosition", "(", "req", ",", "res", ")", "{", "if", "(", "redirect", "(", "req", ".", "params", ".", "id", ",", "'../'", ",", "'/tags'", ",", "res", ")", ")", "{", "return", ";", "}", "var", "id", "=", "req", ".", "params", ".", "id", ";", "var", "position", "=", "req", ".", "body", ".", "position", ";", "var", "rootUrl", "=", "req", ".", "protocol", "+", "'://'", "+", "req", ".", "get", "(", "'host'", ")", ";", "var", "queryPath", "=", "req", ".", "originalUrl", ";", "req", ".", "chickadee", ".", "setAssociation", "(", "req", ",", "id", ",", "null", ",", "null", ",", "null", ",", "position", ",", "rootUrl", ",", "queryPath", ",", "function", "(", "response", ",", "status", ")", "{", "res", ".", "status", "(", "status", ")", ".", "json", "(", "response", ")", ";", "}", ")", ";", "}" ]
Replace the specified association position. @param {Object} req The HTTP request. @param {Object} res The HTTP result.
[ "Replace", "the", "specified", "association", "position", "." ]
1f65c2d369694d93796aae63318fa76326275120
https://github.com/reelyactive/chickadee/blob/1f65c2d369694d93796aae63318fa76326275120/lib/routes/associations.js#L413-L426
48,544
reelyactive/chickadee
lib/routes/associations.js
deleteAssociationPosition
function deleteAssociationPosition(req, res) { if(redirect(req.params.id, '../', '/tags', res)) { return; } var id = req.params.id; var rootUrl = req.protocol + '://' + req.get('host'); var queryPath = req.originalUrl; req.chickadee.removeAssociation(req, id, 'position', rootUrl, queryPath, function(response, status) { res.status(status).json(response); }); }
javascript
function deleteAssociationPosition(req, res) { if(redirect(req.params.id, '../', '/tags', res)) { return; } var id = req.params.id; var rootUrl = req.protocol + '://' + req.get('host'); var queryPath = req.originalUrl; req.chickadee.removeAssociation(req, id, 'position', rootUrl, queryPath, function(response, status) { res.status(status).json(response); }); }
[ "function", "deleteAssociationPosition", "(", "req", ",", "res", ")", "{", "if", "(", "redirect", "(", "req", ".", "params", ".", "id", ",", "'../'", ",", "'/tags'", ",", "res", ")", ")", "{", "return", ";", "}", "var", "id", "=", "req", ".", "params", ".", "id", ";", "var", "rootUrl", "=", "req", ".", "protocol", "+", "'://'", "+", "req", ".", "get", "(", "'host'", ")", ";", "var", "queryPath", "=", "req", ".", "originalUrl", ";", "req", ".", "chickadee", ".", "removeAssociation", "(", "req", ",", "id", ",", "'position'", ",", "rootUrl", ",", "queryPath", ",", "function", "(", "response", ",", "status", ")", "{", "res", ".", "status", "(", "status", ")", ".", "json", "(", "response", ")", ";", "}", ")", ";", "}" ]
Delete the specified association position. @param {Object} req The HTTP request. @param {Object} res The HTTP result.
[ "Delete", "the", "specified", "association", "position", "." ]
1f65c2d369694d93796aae63318fa76326275120
https://github.com/reelyactive/chickadee/blob/1f65c2d369694d93796aae63318fa76326275120/lib/routes/associations.js#L434-L446
48,545
rhardin/node-statistics2
lib/statistics2.js
p_nor
function p_nor(z) { var e, z2, prev = 0.0, t, p, i = 3; if (z < -12) { return 0.0; } if (z > 12) { return 1.0; } if (z === 0.0) { return 0.5; } if (z > 0) { e = true; } else { e = false; z = -z; } z2 = z * z; p = z * Math.exp(-0.5 * z2) / SQ2PI; t = p; for (i; i < 200; i = i + 2) { prev = p; t = t * (z2 / i); p = p + t; if (p <= prev) { return (e ? 0.5 + p : 0.5 - p); } } return (e ? 1.0 : 0.0); }
javascript
function p_nor(z) { var e, z2, prev = 0.0, t, p, i = 3; if (z < -12) { return 0.0; } if (z > 12) { return 1.0; } if (z === 0.0) { return 0.5; } if (z > 0) { e = true; } else { e = false; z = -z; } z2 = z * z; p = z * Math.exp(-0.5 * z2) / SQ2PI; t = p; for (i; i < 200; i = i + 2) { prev = p; t = t * (z2 / i); p = p + t; if (p <= prev) { return (e ? 0.5 + p : 0.5 - p); } } return (e ? 1.0 : 0.0); }
[ "function", "p_nor", "(", "z", ")", "{", "var", "e", ",", "z2", ",", "prev", "=", "0.0", ",", "t", ",", "p", ",", "i", "=", "3", ";", "if", "(", "z", "<", "-", "12", ")", "{", "return", "0.0", ";", "}", "if", "(", "z", ">", "12", ")", "{", "return", "1.0", ";", "}", "if", "(", "z", "===", "0.0", ")", "{", "return", "0.5", ";", "}", "if", "(", "z", ">", "0", ")", "{", "e", "=", "true", ";", "}", "else", "{", "e", "=", "false", ";", "z", "=", "-", "z", ";", "}", "z2", "=", "z", "*", "z", ";", "p", "=", "z", "*", "Math", ".", "exp", "(", "-", "0.5", "*", "z2", ")", "/", "SQ2PI", ";", "t", "=", "p", ";", "for", "(", "i", ";", "i", "<", "200", ";", "i", "=", "i", "+", "2", ")", "{", "prev", "=", "p", ";", "t", "=", "t", "*", "(", "z2", "/", "i", ")", ";", "p", "=", "p", "+", "t", ";", "if", "(", "p", "<=", "prev", ")", "{", "return", "(", "e", "?", "0.5", "+", "p", ":", "0.5", "-", "p", ")", ";", "}", "}", "return", "(", "e", "?", "1.0", ":", "0.0", ")", ";", "}" ]
normal-distribution (-\infty, z]
[ "normal", "-", "distribution", "(", "-", "\\", "infty", "z", "]" ]
b00400adc7c3a0df43dee8d94b20affbb62be1ba
https://github.com/rhardin/node-statistics2/blob/b00400adc7c3a0df43dee8d94b20affbb62be1ba/lib/statistics2.js#L292-L317
48,546
rhardin/node-statistics2
lib/statistics2.js
pf
function pf(q, n1, n2) { var eps, fw, s, qe, w1, w2, w3, w4, u, u2, a, b, c, d; if (q < 0.0 || q > 1.0 || n1 < 1 || n2 < 1) { console.error('Error : Illegal parameter in pf()!'); return 0.0; } if (n1 <= 240 || n2 <= 240) { eps = 1.0e-5; } if (n2 === 1) { eps = 1.0e-4; } fw = 0.0; s = 1000.0; while (true) { fw = fw + s; if (s <= eps) { return fw; } if ((qe = q_f(n1, n2, fw) - q) === 0.0) { return fw; } if (qe < 0.0) { fw = fw - s; s = s / 10.0; } } eps = 1.0e-6; qn = q; if (q < 0.5) { qn = 1.0 - q; } u = pnorm(qn); w1 = 2.0 / n1 / 9.0; w2 = 2.0 / n2 / 9.0; w3 = 1.0 - w1; w4 = 1.0 - w2; u2 = u * u; a = w4 * w4 - u2 * w2; b = -2.0 * w3 * w4; c = w3 * w3 - u2 * w1; d = b * b - 4 * a * c; if (d < 0.0) { fw = pfsub(a, b, 0.0); } else { if (a.abs > eps) { fw = pfsub(a, b, d); } else { if (abs(b) > eps) { return -c / b; } fw = pfsub(a, b, 0.0); } } return fw * fw * fw; }
javascript
function pf(q, n1, n2) { var eps, fw, s, qe, w1, w2, w3, w4, u, u2, a, b, c, d; if (q < 0.0 || q > 1.0 || n1 < 1 || n2 < 1) { console.error('Error : Illegal parameter in pf()!'); return 0.0; } if (n1 <= 240 || n2 <= 240) { eps = 1.0e-5; } if (n2 === 1) { eps = 1.0e-4; } fw = 0.0; s = 1000.0; while (true) { fw = fw + s; if (s <= eps) { return fw; } if ((qe = q_f(n1, n2, fw) - q) === 0.0) { return fw; } if (qe < 0.0) { fw = fw - s; s = s / 10.0; } } eps = 1.0e-6; qn = q; if (q < 0.5) { qn = 1.0 - q; } u = pnorm(qn); w1 = 2.0 / n1 / 9.0; w2 = 2.0 / n2 / 9.0; w3 = 1.0 - w1; w4 = 1.0 - w2; u2 = u * u; a = w4 * w4 - u2 * w2; b = -2.0 * w3 * w4; c = w3 * w3 - u2 * w1; d = b * b - 4 * a * c; if (d < 0.0) { fw = pfsub(a, b, 0.0); } else { if (a.abs > eps) { fw = pfsub(a, b, d); } else { if (abs(b) > eps) { return -c / b; } fw = pfsub(a, b, 0.0); } } return fw * fw * fw; }
[ "function", "pf", "(", "q", ",", "n1", ",", "n2", ")", "{", "var", "eps", ",", "fw", ",", "s", ",", "qe", ",", "w1", ",", "w2", ",", "w3", ",", "w4", ",", "u", ",", "u2", ",", "a", ",", "b", ",", "c", ",", "d", ";", "if", "(", "q", "<", "0.0", "||", "q", ">", "1.0", "||", "n1", "<", "1", "||", "n2", "<", "1", ")", "{", "console", ".", "error", "(", "'Error : Illegal parameter in pf()!'", ")", ";", "return", "0.0", ";", "}", "if", "(", "n1", "<=", "240", "||", "n2", "<=", "240", ")", "{", "eps", "=", "1.0e-5", ";", "}", "if", "(", "n2", "===", "1", ")", "{", "eps", "=", "1.0e-4", ";", "}", "fw", "=", "0.0", ";", "s", "=", "1000.0", ";", "while", "(", "true", ")", "{", "fw", "=", "fw", "+", "s", ";", "if", "(", "s", "<=", "eps", ")", "{", "return", "fw", ";", "}", "if", "(", "(", "qe", "=", "q_f", "(", "n1", ",", "n2", ",", "fw", ")", "-", "q", ")", "===", "0.0", ")", "{", "return", "fw", ";", "}", "if", "(", "qe", "<", "0.0", ")", "{", "fw", "=", "fw", "-", "s", ";", "s", "=", "s", "/", "10.0", ";", "}", "}", "eps", "=", "1.0e-6", ";", "qn", "=", "q", ";", "if", "(", "q", "<", "0.5", ")", "{", "qn", "=", "1.0", "-", "q", ";", "}", "u", "=", "pnorm", "(", "qn", ")", ";", "w1", "=", "2.0", "/", "n1", "/", "9.0", ";", "w2", "=", "2.0", "/", "n2", "/", "9.0", ";", "w3", "=", "1.0", "-", "w1", ";", "w4", "=", "1.0", "-", "w2", ";", "u2", "=", "u", "*", "u", ";", "a", "=", "w4", "*", "w4", "-", "u2", "*", "w2", ";", "b", "=", "-", "2.0", "*", "w3", "*", "w4", ";", "c", "=", "w3", "*", "w3", "-", "u2", "*", "w1", ";", "d", "=", "b", "*", "b", "-", "4", "*", "a", "*", "c", ";", "if", "(", "d", "<", "0.0", ")", "{", "fw", "=", "pfsub", "(", "a", ",", "b", ",", "0.0", ")", ";", "}", "else", "{", "if", "(", "a", ".", "abs", ">", "eps", ")", "{", "fw", "=", "pfsub", "(", "a", ",", "b", ",", "d", ")", ";", "}", "else", "{", "if", "(", "abs", "(", "b", ")", ">", "eps", ")", "{", "return", "-", "c", "/", "b", ";", "}", "fw", "=", "pfsub", "(", "a", ",", "b", ",", "0.0", ")", ";", "}", "}", "return", "fw", "*", "fw", "*", "fw", ";", "}" ]
[x, \infty)
[ "[", "x", "\\", "infty", ")" ]
b00400adc7c3a0df43dee8d94b20affbb62be1ba
https://github.com/rhardin/node-statistics2/blob/b00400adc7c3a0df43dee8d94b20affbb62be1ba/lib/statistics2.js#L551-L602
48,547
Jmlevick/node-exec
lib/main.js
puts
function puts(error, stdout, stderr) { if (error || stderr) { let err = null; if (error) { err = `${error}`; } else if (stderr) { err = `${stderr}`; } returnObj.code = 1; returnObj.error = err; } else if (stdout) { returnObj.code = 0; returnObj.result = `${stdout}`; } else { returnObj.code = null; returnObj.result = "Unknown stdout"; } }
javascript
function puts(error, stdout, stderr) { if (error || stderr) { let err = null; if (error) { err = `${error}`; } else if (stderr) { err = `${stderr}`; } returnObj.code = 1; returnObj.error = err; } else if (stdout) { returnObj.code = 0; returnObj.result = `${stdout}`; } else { returnObj.code = null; returnObj.result = "Unknown stdout"; } }
[ "function", "puts", "(", "error", ",", "stdout", ",", "stderr", ")", "{", "if", "(", "error", "||", "stderr", ")", "{", "let", "err", "=", "null", ";", "if", "(", "error", ")", "{", "err", "=", "`", "${", "error", "}", "`", ";", "}", "else", "if", "(", "stderr", ")", "{", "err", "=", "`", "${", "stderr", "}", "`", ";", "}", "returnObj", ".", "code", "=", "1", ";", "returnObj", ".", "error", "=", "err", ";", "}", "else", "if", "(", "stdout", ")", "{", "returnObj", ".", "code", "=", "0", ";", "returnObj", ".", "result", "=", "`", "${", "stdout", "}", "`", ";", "}", "else", "{", "returnObj", ".", "code", "=", "null", ";", "returnObj", ".", "result", "=", "\"Unknown stdout\"", ";", "}", "}" ]
Helpers Callback for exec @param {any} error @param {any} stdout @param {any} stderr
[ "Helpers", "Callback", "for", "exec" ]
afb2d31eda9cbb0911820dc2f78ef23f87d40187
https://github.com/Jmlevick/node-exec/blob/afb2d31eda9cbb0911820dc2f78ef23f87d40187/lib/main.js#L20-L39
48,548
jurca/namespace-proxy
es2015/createNamespaceProxy.js
createProxy
function createProxy(instance, symbols, enumerable) { return new Proxy(instance, { set: (target, propertyName, value) => { let { symbol, isNew } = getSymbol(symbols, propertyName) instance[symbol] = value if (!enumerable && isNew) { Object.defineProperty(instance, symbol, { enumerable: false }) } return true }, get: (target, propertyName) => { if (!symbols.has(propertyName)) { return undefined // the property has not been defined (set) yet } let { symbol } = getSymbol(symbols, propertyName) return instance[symbol] } }) }
javascript
function createProxy(instance, symbols, enumerable) { return new Proxy(instance, { set: (target, propertyName, value) => { let { symbol, isNew } = getSymbol(symbols, propertyName) instance[symbol] = value if (!enumerable && isNew) { Object.defineProperty(instance, symbol, { enumerable: false }) } return true }, get: (target, propertyName) => { if (!symbols.has(propertyName)) { return undefined // the property has not been defined (set) yet } let { symbol } = getSymbol(symbols, propertyName) return instance[symbol] } }) }
[ "function", "createProxy", "(", "instance", ",", "symbols", ",", "enumerable", ")", "{", "return", "new", "Proxy", "(", "instance", ",", "{", "set", ":", "(", "target", ",", "propertyName", ",", "value", ")", "=>", "{", "let", "{", "symbol", ",", "isNew", "}", "=", "getSymbol", "(", "symbols", ",", "propertyName", ")", "instance", "[", "symbol", "]", "=", "value", "if", "(", "!", "enumerable", "&&", "isNew", ")", "{", "Object", ".", "defineProperty", "(", "instance", ",", "symbol", ",", "{", "enumerable", ":", "false", "}", ")", "}", "return", "true", "}", ",", "get", ":", "(", "target", ",", "propertyName", ")", "=>", "{", "if", "(", "!", "symbols", ".", "has", "(", "propertyName", ")", ")", "{", "return", "undefined", "// the property has not been defined (set) yet", "}", "let", "{", "symbol", "}", "=", "getSymbol", "(", "symbols", ",", "propertyName", ")", "return", "instance", "[", "symbol", "]", "}", "}", ")", "}" ]
Creates a proxy for retrieving and setting the values of the private properties of the provided instance. @param {Object} instance The instance for which the proxy should be created. @param {Map<string, symbol>} symbols Cache of private property symbols. @param {boolean} enumerable The flag specifying whether or not the properties created by the returned proxy should be enumerable or not. @return {Proxy} The proxy for convenient setting and retrieving of private properties of the specified instance.
[ "Creates", "a", "proxy", "for", "retrieving", "and", "setting", "the", "values", "of", "the", "private", "properties", "of", "the", "provided", "instance", "." ]
b3526c8788930362694920d94a10848352436492
https://github.com/jurca/namespace-proxy/blob/b3526c8788930362694920d94a10848352436492/es2015/createNamespaceProxy.js#L57-L79
48,549
jurca/namespace-proxy
es2015/createNamespaceProxy.js
getSymbol
function getSymbol(symbols, propertyName) { if (symbols.has(propertyName)) { return { symbol: symbols.get(propertyName), isNew: false } } let symbol = Symbol(propertyName) symbols.set(propertyName, symbol) return { symbol, isNew: true } }
javascript
function getSymbol(symbols, propertyName) { if (symbols.has(propertyName)) { return { symbol: symbols.get(propertyName), isNew: false } } let symbol = Symbol(propertyName) symbols.set(propertyName, symbol) return { symbol, isNew: true } }
[ "function", "getSymbol", "(", "symbols", ",", "propertyName", ")", "{", "if", "(", "symbols", ".", "has", "(", "propertyName", ")", ")", "{", "return", "{", "symbol", ":", "symbols", ".", "get", "(", "propertyName", ")", ",", "isNew", ":", "false", "}", "}", "let", "symbol", "=", "Symbol", "(", "propertyName", ")", "symbols", ".", "set", "(", "propertyName", ",", "symbol", ")", "return", "{", "symbol", ",", "isNew", ":", "true", "}", "}" ]
Retrieves or generates and caches the private field symbol for the private property of the specified name. @param {Map<string, symbol>} symbols Cache of private property symbols. @param {string} propertyName The name of the private property. @return {{symbol: symbol, isNew: boolean}} An object wrapping the symbol to use for setting and retrieving the value of the specified private property. The {@code isNew} flag specifies whether the symbol has just been created.
[ "Retrieves", "or", "generates", "and", "caches", "the", "private", "field", "symbol", "for", "the", "private", "property", "of", "the", "specified", "name", "." ]
b3526c8788930362694920d94a10848352436492
https://github.com/jurca/namespace-proxy/blob/b3526c8788930362694920d94a10848352436492/es2015/createNamespaceProxy.js#L92-L106
48,550
neoziro/image-size-parser
index.js
parse
function parse(size) { var matches = size.match(regexp); if (!matches) return null; var multiplicator = matches[3] ? +matches[3].replace(/x$/, '') : 1; return { width: +matches[1] * multiplicator, height: +matches[2] * multiplicator }; }
javascript
function parse(size) { var matches = size.match(regexp); if (!matches) return null; var multiplicator = matches[3] ? +matches[3].replace(/x$/, '') : 1; return { width: +matches[1] * multiplicator, height: +matches[2] * multiplicator }; }
[ "function", "parse", "(", "size", ")", "{", "var", "matches", "=", "size", ".", "match", "(", "regexp", ")", ";", "if", "(", "!", "matches", ")", "return", "null", ";", "var", "multiplicator", "=", "matches", "[", "3", "]", "?", "+", "matches", "[", "3", "]", ".", "replace", "(", "/", "x$", "/", ",", "''", ")", ":", "1", ";", "return", "{", "width", ":", "+", "matches", "[", "1", "]", "*", "multiplicator", ",", "height", ":", "+", "matches", "[", "2", "]", "*", "multiplicator", "}", ";", "}" ]
Parse image size. @param {string} size Size string @returns {object} size Size object @returns {number} size.width Width @returns {number} size.height Height
[ "Parse", "image", "size", "." ]
4b6594ae71a01900e9ace09a7a589c8976e5715e
https://github.com/neoziro/image-size-parser/blob/4b6594ae71a01900e9ace09a7a589c8976e5715e/index.js#L15-L27
48,551
AutocratJS/autocrat
lib/law.js
function() { var streams = this.sourceStreams = toArray(arguments); if(streams.length > 1) { this.resultStream = Bacon.mergeAll(streams); } else { this.resultStream = streams[0]; } this.streamsHash = this._computeStreamsHash('any', streams); // invalidate 'all' return this; }
javascript
function() { var streams = this.sourceStreams = toArray(arguments); if(streams.length > 1) { this.resultStream = Bacon.mergeAll(streams); } else { this.resultStream = streams[0]; } this.streamsHash = this._computeStreamsHash('any', streams); // invalidate 'all' return this; }
[ "function", "(", ")", "{", "var", "streams", "=", "this", ".", "sourceStreams", "=", "toArray", "(", "arguments", ")", ";", "if", "(", "streams", ".", "length", ">", "1", ")", "{", "this", ".", "resultStream", "=", "Bacon", ".", "mergeAll", "(", "streams", ")", ";", "}", "else", "{", "this", ".", "resultStream", "=", "streams", "[", "0", "]", ";", "}", "this", ".", "streamsHash", "=", "this", ".", "_computeStreamsHash", "(", "'any'", ",", "streams", ")", ";", "// invalidate 'all'", "return", "this", ";", "}" ]
Produce a side effect when any of the Law events occur @function @name whenAny @instance @memberof Law
[ "Produce", "a", "side", "effect", "when", "any", "of", "the", "Law", "events", "occur" ]
ca1466f851c4dbc5237fbbb2ee7caa1cff964f51
https://github.com/AutocratJS/autocrat/blob/ca1466f851c4dbc5237fbbb2ee7caa1cff964f51/lib/law.js#L155-L168
48,552
AutocratJS/autocrat
lib/law.js
function() { var streams = this.sourceStreams = toArray(arguments); if(streams.length === 1) { this.any.apply(this, streams); return this; } this.resultStream = Bacon.zipAsArray(streams); this.streamsHash = this._computeStreamsHash('all', streams); // invalidate 'any' return this; }
javascript
function() { var streams = this.sourceStreams = toArray(arguments); if(streams.length === 1) { this.any.apply(this, streams); return this; } this.resultStream = Bacon.zipAsArray(streams); this.streamsHash = this._computeStreamsHash('all', streams); // invalidate 'any' return this; }
[ "function", "(", ")", "{", "var", "streams", "=", "this", ".", "sourceStreams", "=", "toArray", "(", "arguments", ")", ";", "if", "(", "streams", ".", "length", "===", "1", ")", "{", "this", ".", "any", ".", "apply", "(", "this", ",", "streams", ")", ";", "return", "this", ";", "}", "this", ".", "resultStream", "=", "Bacon", ".", "zipAsArray", "(", "streams", ")", ";", "this", ".", "streamsHash", "=", "this", ".", "_computeStreamsHash", "(", "'all'", ",", "streams", ")", ";", "// invalidate 'any'", "return", "this", ";", "}" ]
Produce a side effect only after all of the Law events occur @function whenAll @name whenAll @instance @memberof Law
[ "Produce", "a", "side", "effect", "only", "after", "all", "of", "the", "Law", "events", "occur" ]
ca1466f851c4dbc5237fbbb2ee7caa1cff964f51
https://github.com/AutocratJS/autocrat/blob/ca1466f851c4dbc5237fbbb2ee7caa1cff964f51/lib/law.js#L178-L192
48,553
AutocratJS/autocrat
lib/law.js
function(autocrat, governor, origHandler, context) { var streamsHash = this.streamsHash, handlerSequence, isFirstHandler, deferred, handler; context || (context = this.governor); if(isFunction(origHandler)) { origHandler = bind(origHandler, context); } else if(isString(origHandler)){ origHandler = bind(this.governor[origHandler], context); } if(autocrat.awaiting[this.streamsHash]) { handlerSequence = autocrat.awaiting[this.streamsHash]; } else { handlerSequence = autocrat.awaiting[this.streamsHash] = []; isFirstHandler = true; } deferred = new HandlerDeferred(handlerSequence); handler = this._buildAsyncHandler(origHandler, deferred); if(isFirstHandler) { deferred.handlerIndex = 0; handlerSequence.push(handler); this.resultStream.subscribe(handler); } else { deferred.handlerIndex = handlerSequence.length; handlerSequence.push(handler); } // terminate chain return this; }
javascript
function(autocrat, governor, origHandler, context) { var streamsHash = this.streamsHash, handlerSequence, isFirstHandler, deferred, handler; context || (context = this.governor); if(isFunction(origHandler)) { origHandler = bind(origHandler, context); } else if(isString(origHandler)){ origHandler = bind(this.governor[origHandler], context); } if(autocrat.awaiting[this.streamsHash]) { handlerSequence = autocrat.awaiting[this.streamsHash]; } else { handlerSequence = autocrat.awaiting[this.streamsHash] = []; isFirstHandler = true; } deferred = new HandlerDeferred(handlerSequence); handler = this._buildAsyncHandler(origHandler, deferred); if(isFirstHandler) { deferred.handlerIndex = 0; handlerSequence.push(handler); this.resultStream.subscribe(handler); } else { deferred.handlerIndex = handlerSequence.length; handlerSequence.push(handler); } // terminate chain return this; }
[ "function", "(", "autocrat", ",", "governor", ",", "origHandler", ",", "context", ")", "{", "var", "streamsHash", "=", "this", ".", "streamsHash", ",", "handlerSequence", ",", "isFirstHandler", ",", "deferred", ",", "handler", ";", "context", "||", "(", "context", "=", "this", ".", "governor", ")", ";", "if", "(", "isFunction", "(", "origHandler", ")", ")", "{", "origHandler", "=", "bind", "(", "origHandler", ",", "context", ")", ";", "}", "else", "if", "(", "isString", "(", "origHandler", ")", ")", "{", "origHandler", "=", "bind", "(", "this", ".", "governor", "[", "origHandler", "]", ",", "context", ")", ";", "}", "if", "(", "autocrat", ".", "awaiting", "[", "this", ".", "streamsHash", "]", ")", "{", "handlerSequence", "=", "autocrat", ".", "awaiting", "[", "this", ".", "streamsHash", "]", ";", "}", "else", "{", "handlerSequence", "=", "autocrat", ".", "awaiting", "[", "this", ".", "streamsHash", "]", "=", "[", "]", ";", "isFirstHandler", "=", "true", ";", "}", "deferred", "=", "new", "HandlerDeferred", "(", "handlerSequence", ")", ";", "handler", "=", "this", ".", "_buildAsyncHandler", "(", "origHandler", ",", "deferred", ")", ";", "if", "(", "isFirstHandler", ")", "{", "deferred", ".", "handlerIndex", "=", "0", ";", "handlerSequence", ".", "push", "(", "handler", ")", ";", "this", ".", "resultStream", ".", "subscribe", "(", "handler", ")", ";", "}", "else", "{", "deferred", ".", "handlerIndex", "=", "handlerSequence", ".", "length", ";", "handlerSequence", ".", "push", "(", "handler", ")", ";", "}", "// terminate chain", "return", "this", ";", "}" ]
Explicitly specify a side effect function @function then @name then @instance @memberof Law
[ "Explicitly", "specify", "a", "side", "effect", "function" ]
ca1466f851c4dbc5237fbbb2ee7caa1cff964f51
https://github.com/AutocratJS/autocrat/blob/ca1466f851c4dbc5237fbbb2ee7caa1cff964f51/lib/law.js#L202-L235
48,554
AutocratJS/autocrat
lib/law.js
function(propName, updater) { var updaterName, handler; if(!isFunction(updater)) { updaterName = 'update' + propName[0].toUpperCase() + propName.slice(1); updater = this.governor[updaterName]; } if(updater) { this.then(function(advisorEvent, deferred, consequenceActions, streamEvent) { var currVal = this.props[propName].value; var updaterArgs = [currVal].concat(advisorEvent, streamEvent); var retVal = updater.apply(this, updaterArgs); // Only trigger a reactive change if the value has actually changed; // if(!isEqual(retVal, currVal)) this.props[propName] = retVal; this.props[propName] = retVal deferred.resolve(retVal); }); } else { throw new Error('An updater function was not specified and governor.' + updaterName + ' is not defined'); } return this; }
javascript
function(propName, updater) { var updaterName, handler; if(!isFunction(updater)) { updaterName = 'update' + propName[0].toUpperCase() + propName.slice(1); updater = this.governor[updaterName]; } if(updater) { this.then(function(advisorEvent, deferred, consequenceActions, streamEvent) { var currVal = this.props[propName].value; var updaterArgs = [currVal].concat(advisorEvent, streamEvent); var retVal = updater.apply(this, updaterArgs); // Only trigger a reactive change if the value has actually changed; // if(!isEqual(retVal, currVal)) this.props[propName] = retVal; this.props[propName] = retVal deferred.resolve(retVal); }); } else { throw new Error('An updater function was not specified and governor.' + updaterName + ' is not defined'); } return this; }
[ "function", "(", "propName", ",", "updater", ")", "{", "var", "updaterName", ",", "handler", ";", "if", "(", "!", "isFunction", "(", "updater", ")", ")", "{", "updaterName", "=", "'update'", "+", "propName", "[", "0", "]", ".", "toUpperCase", "(", ")", "+", "propName", ".", "slice", "(", "1", ")", ";", "updater", "=", "this", ".", "governor", "[", "updaterName", "]", ";", "}", "if", "(", "updater", ")", "{", "this", ".", "then", "(", "function", "(", "advisorEvent", ",", "deferred", ",", "consequenceActions", ",", "streamEvent", ")", "{", "var", "currVal", "=", "this", ".", "props", "[", "propName", "]", ".", "value", ";", "var", "updaterArgs", "=", "[", "currVal", "]", ".", "concat", "(", "advisorEvent", ",", "streamEvent", ")", ";", "var", "retVal", "=", "updater", ".", "apply", "(", "this", ",", "updaterArgs", ")", ";", "// Only trigger a reactive change if the value has actually changed;", "// if(!isEqual(retVal, currVal)) this.props[propName] = retVal;", "this", ".", "props", "[", "propName", "]", "=", "retVal", "deferred", ".", "resolve", "(", "retVal", ")", ";", "}", ")", ";", "}", "else", "{", "throw", "new", "Error", "(", "'An updater function was not specified and governor.'", "+", "updaterName", "+", "' is not defined'", ")", ";", "}", "return", "this", ";", "}" ]
Indicate which property update function should be called in response to Advisor events. @function updateProp @name updateProp @instance @memberof Law
[ "Indicate", "which", "property", "update", "function", "should", "be", "called", "in", "response", "to", "Advisor", "events", "." ]
ca1466f851c4dbc5237fbbb2ee7caa1cff964f51
https://github.com/AutocratJS/autocrat/blob/ca1466f851c4dbc5237fbbb2ee7caa1cff964f51/lib/law.js#L246-L271
48,555
AutocratJS/autocrat
lib/law.js
function() { var props = arguments.length ? toArray(arguments) : keys(this.governor.props); forEach(props, this.updateProp, this); return this; }
javascript
function() { var props = arguments.length ? toArray(arguments) : keys(this.governor.props); forEach(props, this.updateProp, this); return this; }
[ "function", "(", ")", "{", "var", "props", "=", "arguments", ".", "length", "?", "toArray", "(", "arguments", ")", ":", "keys", "(", "this", ".", "governor", ".", "props", ")", ";", "forEach", "(", "props", ",", "this", ".", "updateProp", ",", "this", ")", ";", "return", "this", ";", "}" ]
Indicate that all prop update functions should be called in resonse to a Law's Advisor events. @function updateProps @name updateProps @instance @memberof Law
[ "Indicate", "that", "all", "prop", "update", "functions", "should", "be", "called", "in", "resonse", "to", "a", "Law", "s", "Advisor", "events", "." ]
ca1466f851c4dbc5237fbbb2ee7caa1cff964f51
https://github.com/AutocratJS/autocrat/blob/ca1466f851c4dbc5237fbbb2ee7caa1cff964f51/lib/law.js#L282-L286
48,556
hawtio/hawtio-utilities
dist/hawtio-utilities.js
removeElements
function removeElements(collection, newCollection, index) { if (index === void 0) { index = 'id'; } var oldLength = collection.length; _.remove(collection, function (item) { return !_.some(newCollection, function (c) { return c[index] === item[index]; }); }); return collection.length !== oldLength; }
javascript
function removeElements(collection, newCollection, index) { if (index === void 0) { index = 'id'; } var oldLength = collection.length; _.remove(collection, function (item) { return !_.some(newCollection, function (c) { return c[index] === item[index]; }); }); return collection.length !== oldLength; }
[ "function", "removeElements", "(", "collection", ",", "newCollection", ",", "index", ")", "{", "if", "(", "index", "===", "void", "0", ")", "{", "index", "=", "'id'", ";", "}", "var", "oldLength", "=", "collection", ".", "length", ";", "_", ".", "remove", "(", "collection", ",", "function", "(", "item", ")", "{", "return", "!", "_", ".", "some", "(", "newCollection", ",", "function", "(", "c", ")", "{", "return", "c", "[", "index", "]", "===", "item", "[", "index", "]", ";", "}", ")", ";", "}", ")", ";", "return", "collection", ".", "length", "!==", "oldLength", ";", "}" ]
Removes elements in the target array based on the new collection, returns true if any changes were made
[ "Removes", "elements", "in", "the", "target", "array", "based", "on", "the", "new", "collection", "returns", "true", "if", "any", "changes", "were", "made" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L17-L22
48,557
hawtio/hawtio-utilities
dist/hawtio-utilities.js
sync
function sync(collection, newCollection, index) { if (index === void 0) { index = 'id'; } var answer = removeElements(collection, newCollection, index); if (newCollection) { newCollection.forEach(function (item) { var oldItem = _.find(collection, function (c) { return c[index] === item[index]; }); if (!oldItem) { answer = true; collection.push(item); } else { if (item !== oldItem) { angular.copy(item, oldItem); answer = true; } } }); } return answer; }
javascript
function sync(collection, newCollection, index) { if (index === void 0) { index = 'id'; } var answer = removeElements(collection, newCollection, index); if (newCollection) { newCollection.forEach(function (item) { var oldItem = _.find(collection, function (c) { return c[index] === item[index]; }); if (!oldItem) { answer = true; collection.push(item); } else { if (item !== oldItem) { angular.copy(item, oldItem); answer = true; } } }); } return answer; }
[ "function", "sync", "(", "collection", ",", "newCollection", ",", "index", ")", "{", "if", "(", "index", "===", "void", "0", ")", "{", "index", "=", "'id'", ";", "}", "var", "answer", "=", "removeElements", "(", "collection", ",", "newCollection", ",", "index", ")", ";", "if", "(", "newCollection", ")", "{", "newCollection", ".", "forEach", "(", "function", "(", "item", ")", "{", "var", "oldItem", "=", "_", ".", "find", "(", "collection", ",", "function", "(", "c", ")", "{", "return", "c", "[", "index", "]", "===", "item", "[", "index", "]", ";", "}", ")", ";", "if", "(", "!", "oldItem", ")", "{", "answer", "=", "true", ";", "collection", ".", "push", "(", "item", ")", ";", "}", "else", "{", "if", "(", "item", "!==", "oldItem", ")", "{", "angular", ".", "copy", "(", "item", ",", "oldItem", ")", ";", "answer", "=", "true", ";", "}", "}", "}", ")", ";", "}", "return", "answer", ";", "}" ]
Changes the existing collection to match the new collection to avoid re-assigning the array pointer, returns true if the array size has changed
[ "Changes", "the", "existing", "collection", "to", "match", "the", "new", "collection", "to", "avoid", "re", "-", "assigning", "the", "array", "pointer", "returns", "true", "if", "the", "array", "size", "has", "changed" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L28-L47
48,558
hawtio/hawtio-utilities
dist/hawtio-utilities.js
escapeColons
function escapeColons(url) { var answer = url; if (_.startsWith(url, 'proxy')) { answer = url.replace(/:/g, '\\:'); } else { answer = url.replace(/:([^\/])/, '\\:$1'); } return answer; }
javascript
function escapeColons(url) { var answer = url; if (_.startsWith(url, 'proxy')) { answer = url.replace(/:/g, '\\:'); } else { answer = url.replace(/:([^\/])/, '\\:$1'); } return answer; }
[ "function", "escapeColons", "(", "url", ")", "{", "var", "answer", "=", "url", ";", "if", "(", "_", ".", "startsWith", "(", "url", ",", "'proxy'", ")", ")", "{", "answer", "=", "url", ".", "replace", "(", "/", ":", "/", "g", ",", "'\\\\:'", ")", ";", "}", "else", "{", "answer", "=", "url", ".", "replace", "(", "/", ":([^\\/])", "/", ",", "'\\\\:$1'", ")", ";", "}", "return", "answer", ";", "}" ]
Escape any colons in the URL for ng-resource, mostly useful for handling proxified URLs @param url @returns {*}
[ "Escape", "any", "colons", "in", "the", "URL", "for", "ng", "-", "resource", "mostly", "useful", "for", "handling", "proxified", "URLs" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L207-L216
48,559
hawtio/hawtio-utilities
dist/hawtio-utilities.js
url
function url(path) { if (path) { if (_.startsWith(path, "/")) { if (!_urlPrefix) { // lets discover the base url via the base html element _urlPrefix = $('base').attr('href') || ""; if (_.endsWith(_urlPrefix, '/')) { _urlPrefix = _urlPrefix.substring(0, _urlPrefix.length - 1); } } if (_urlPrefix) { return _urlPrefix + path; } } } return path; }
javascript
function url(path) { if (path) { if (_.startsWith(path, "/")) { if (!_urlPrefix) { // lets discover the base url via the base html element _urlPrefix = $('base').attr('href') || ""; if (_.endsWith(_urlPrefix, '/')) { _urlPrefix = _urlPrefix.substring(0, _urlPrefix.length - 1); } } if (_urlPrefix) { return _urlPrefix + path; } } } return path; }
[ "function", "url", "(", "path", ")", "{", "if", "(", "path", ")", "{", "if", "(", "_", ".", "startsWith", "(", "path", ",", "\"/\"", ")", ")", "{", "if", "(", "!", "_urlPrefix", ")", "{", "// lets discover the base url via the base html element", "_urlPrefix", "=", "$", "(", "'base'", ")", ".", "attr", "(", "'href'", ")", "||", "\"\"", ";", "if", "(", "_", ".", "endsWith", "(", "_urlPrefix", ",", "'/'", ")", ")", "{", "_urlPrefix", "=", "_urlPrefix", ".", "substring", "(", "0", ",", "_urlPrefix", ".", "length", "-", "1", ")", ";", "}", "}", "if", "(", "_urlPrefix", ")", "{", "return", "_urlPrefix", "+", "path", ";", "}", "}", "}", "return", "path", ";", "}" ]
Prefixes absolute URLs with current window.location.pathname @param path @returns {string}
[ "Prefixes", "absolute", "URLs", "with", "current", "window", ".", "location", ".", "pathname" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L239-L255
48,560
hawtio/hawtio-utilities
dist/hawtio-utilities.js
trimLeading
function trimLeading(text, prefix) { if (text && prefix) { if (_.startsWith(text, prefix) || text.indexOf(prefix) === 0) { return text.substring(prefix.length); } } return text; }
javascript
function trimLeading(text, prefix) { if (text && prefix) { if (_.startsWith(text, prefix) || text.indexOf(prefix) === 0) { return text.substring(prefix.length); } } return text; }
[ "function", "trimLeading", "(", "text", ",", "prefix", ")", "{", "if", "(", "text", "&&", "prefix", ")", "{", "if", "(", "_", ".", "startsWith", "(", "text", ",", "prefix", ")", "||", "text", ".", "indexOf", "(", "prefix", ")", "===", "0", ")", "{", "return", "text", ".", "substring", "(", "prefix", ".", "length", ")", ";", "}", "}", "return", "text", ";", "}" ]
Trims the leading prefix from a string if its present @method trimLeading @for Core @static @param {String} text @param {String} prefix @return {String}
[ "Trims", "the", "leading", "prefix", "from", "a", "string", "if", "its", "present" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L296-L303
48,561
hawtio/hawtio-utilities
dist/hawtio-utilities.js
trimTrailing
function trimTrailing(text, postfix) { if (text && postfix) { if (_.endsWith(text, postfix)) { return text.substring(0, text.length - postfix.length); } } return text; }
javascript
function trimTrailing(text, postfix) { if (text && postfix) { if (_.endsWith(text, postfix)) { return text.substring(0, text.length - postfix.length); } } return text; }
[ "function", "trimTrailing", "(", "text", ",", "postfix", ")", "{", "if", "(", "text", "&&", "postfix", ")", "{", "if", "(", "_", ".", "endsWith", "(", "text", ",", "postfix", ")", ")", "{", "return", "text", ".", "substring", "(", "0", ",", "text", ".", "length", "-", "postfix", ".", "length", ")", ";", "}", "}", "return", "text", ";", "}" ]
Trims the trailing postfix from a string if its present @method trimTrailing @for Core @static @param {String} trim @param {String} postfix @return {String}
[ "Trims", "the", "trailing", "postfix", "from", "a", "string", "if", "its", "present" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L314-L321
48,562
hawtio/hawtio-utilities
dist/hawtio-utilities.js
adjustHeight
function adjustHeight() { var windowHeight = $(window).height(); var headerHeight = $("#main-nav").height(); var containerHeight = windowHeight - headerHeight; $("#main").css("min-height", "" + containerHeight + "px"); }
javascript
function adjustHeight() { var windowHeight = $(window).height(); var headerHeight = $("#main-nav").height(); var containerHeight = windowHeight - headerHeight; $("#main").css("min-height", "" + containerHeight + "px"); }
[ "function", "adjustHeight", "(", ")", "{", "var", "windowHeight", "=", "$", "(", "window", ")", ".", "height", "(", ")", ";", "var", "headerHeight", "=", "$", "(", "\"#main-nav\"", ")", ".", "height", "(", ")", ";", "var", "containerHeight", "=", "windowHeight", "-", "headerHeight", ";", "$", "(", "\"#main\"", ")", ".", "css", "(", "\"min-height\"", ",", "\"\"", "+", "containerHeight", "+", "\"px\"", ")", ";", "}" ]
Ensure our main app container takes up at least the viewport height
[ "Ensure", "our", "main", "app", "container", "takes", "up", "at", "least", "the", "viewport", "height" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L327-L332
48,563
hawtio/hawtio-utilities
dist/hawtio-utilities.js
addCSS
function addCSS(path) { if ('createStyleSheet' in document) { // IE9 document.createStyleSheet(path); } else { // Everyone else var link = $("<link>"); $("head").append(link); link.attr({ rel: 'stylesheet', type: 'text/css', href: path }); } }
javascript
function addCSS(path) { if ('createStyleSheet' in document) { // IE9 document.createStyleSheet(path); } else { // Everyone else var link = $("<link>"); $("head").append(link); link.attr({ rel: 'stylesheet', type: 'text/css', href: path }); } }
[ "function", "addCSS", "(", "path", ")", "{", "if", "(", "'createStyleSheet'", "in", "document", ")", "{", "// IE9", "document", ".", "createStyleSheet", "(", "path", ")", ";", "}", "else", "{", "// Everyone else", "var", "link", "=", "$", "(", "\"<link>\"", ")", ";", "$", "(", "\"head\"", ")", ".", "append", "(", "link", ")", ";", "link", ".", "attr", "(", "{", "rel", ":", "'stylesheet'", ",", "type", ":", "'text/css'", ",", "href", ":", "path", "}", ")", ";", "}", "}" ]
Adds the specified CSS file to the document's head, handy for external plugins that might bring along their own CSS @param path
[ "Adds", "the", "specified", "CSS", "file", "to", "the", "document", "s", "head", "handy", "for", "external", "plugins", "that", "might", "bring", "along", "their", "own", "CSS" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L352-L367
48,564
hawtio/hawtio-utilities
dist/hawtio-utilities.js
parseBooleanValue
function parseBooleanValue(value, defaultValue) { if (defaultValue === void 0) { defaultValue = false; } if (!angular.isDefined(value) || !value) { return defaultValue; } if (value.constructor === Boolean) { return value; } if (angular.isString(value)) { switch (value.toLowerCase()) { case "true": case "1": case "yes": return true; default: return false; } } if (angular.isNumber(value)) { return value !== 0; } throw new Error("Can't convert value " + value + " to boolean"); }
javascript
function parseBooleanValue(value, defaultValue) { if (defaultValue === void 0) { defaultValue = false; } if (!angular.isDefined(value) || !value) { return defaultValue; } if (value.constructor === Boolean) { return value; } if (angular.isString(value)) { switch (value.toLowerCase()) { case "true": case "1": case "yes": return true; default: return false; } } if (angular.isNumber(value)) { return value !== 0; } throw new Error("Can't convert value " + value + " to boolean"); }
[ "function", "parseBooleanValue", "(", "value", ",", "defaultValue", ")", "{", "if", "(", "defaultValue", "===", "void", "0", ")", "{", "defaultValue", "=", "false", ";", "}", "if", "(", "!", "angular", ".", "isDefined", "(", "value", ")", "||", "!", "value", ")", "{", "return", "defaultValue", ";", "}", "if", "(", "value", ".", "constructor", "===", "Boolean", ")", "{", "return", "value", ";", "}", "if", "(", "angular", ".", "isString", "(", "value", ")", ")", "{", "switch", "(", "value", ".", "toLowerCase", "(", ")", ")", "{", "case", "\"true\"", ":", "case", "\"1\"", ":", "case", "\"yes\"", ":", "return", "true", ";", "default", ":", "return", "false", ";", "}", "}", "if", "(", "angular", ".", "isNumber", "(", "value", ")", ")", "{", "return", "value", "!==", "0", ";", "}", "throw", "new", "Error", "(", "\"Can't convert value \"", "+", "value", "+", "\" to boolean\"", ")", ";", "}" ]
Ensure whatever value is passed in is converted to a boolean In the branding module for now as it's needed before bootstrap @method parseBooleanValue @for Core @param {any} value @param {Boolean} defaultValue default value to use if value is not defined @return {Boolean}
[ "Ensure", "whatever", "value", "is", "passed", "in", "is", "converted", "to", "a", "boolean" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L407-L429
48,565
hawtio/hawtio-utilities
dist/hawtio-utilities.js
pathGet
function pathGet(object, paths) { var pathArray = (angular.isArray(paths)) ? paths : (paths || "").split("."); var value = object; angular.forEach(pathArray, function (name) { if (value) { try { value = value[name]; } catch (e) { // ignore errors return null; } } else { return null; } }); return value; }
javascript
function pathGet(object, paths) { var pathArray = (angular.isArray(paths)) ? paths : (paths || "").split("."); var value = object; angular.forEach(pathArray, function (name) { if (value) { try { value = value[name]; } catch (e) { // ignore errors return null; } } else { return null; } }); return value; }
[ "function", "pathGet", "(", "object", ",", "paths", ")", "{", "var", "pathArray", "=", "(", "angular", ".", "isArray", "(", "paths", ")", ")", "?", "paths", ":", "(", "paths", "||", "\"\"", ")", ".", "split", "(", "\".\"", ")", ";", "var", "value", "=", "object", ";", "angular", ".", "forEach", "(", "pathArray", ",", "function", "(", "name", ")", "{", "if", "(", "value", ")", "{", "try", "{", "value", "=", "value", "[", "name", "]", ";", "}", "catch", "(", "e", ")", "{", "// ignore errors", "return", "null", ";", "}", "}", "else", "{", "return", "null", ";", "}", "}", ")", ";", "return", "value", ";", "}" ]
Navigates the given set of paths in turn on the source object and returns the last most value of the path or null if it could not be found. @method pathGet @for Core @static @param {Object} object the start object to start navigating from @param {Array} paths an array of path names to navigate or a string of dot separated paths to navigate @return {*} the last step on the path which is updated
[ "Navigates", "the", "given", "set", "of", "paths", "in", "turn", "on", "the", "source", "object", "and", "returns", "the", "last", "most", "value", "of", "the", "path", "or", "null", "if", "it", "could", "not", "be", "found", "." ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L517-L535
48,566
hawtio/hawtio-utilities
dist/hawtio-utilities.js
pathSet
function pathSet(object, paths, newValue) { var pathArray = (angular.isArray(paths)) ? paths : (paths || "").split("."); var value = object; var lastIndex = pathArray.length - 1; angular.forEach(pathArray, function (name, idx) { var next = value[name]; if (idx >= lastIndex || !angular.isObject(next)) { next = (idx < lastIndex) ? {} : newValue; value[name] = next; } value = next; }); return value; }
javascript
function pathSet(object, paths, newValue) { var pathArray = (angular.isArray(paths)) ? paths : (paths || "").split("."); var value = object; var lastIndex = pathArray.length - 1; angular.forEach(pathArray, function (name, idx) { var next = value[name]; if (idx >= lastIndex || !angular.isObject(next)) { next = (idx < lastIndex) ? {} : newValue; value[name] = next; } value = next; }); return value; }
[ "function", "pathSet", "(", "object", ",", "paths", ",", "newValue", ")", "{", "var", "pathArray", "=", "(", "angular", ".", "isArray", "(", "paths", ")", ")", "?", "paths", ":", "(", "paths", "||", "\"\"", ")", ".", "split", "(", "\".\"", ")", ";", "var", "value", "=", "object", ";", "var", "lastIndex", "=", "pathArray", ".", "length", "-", "1", ";", "angular", ".", "forEach", "(", "pathArray", ",", "function", "(", "name", ",", "idx", ")", "{", "var", "next", "=", "value", "[", "name", "]", ";", "if", "(", "idx", ">=", "lastIndex", "||", "!", "angular", ".", "isObject", "(", "next", ")", ")", "{", "next", "=", "(", "idx", "<", "lastIndex", ")", "?", "{", "}", ":", "newValue", ";", "value", "[", "name", "]", "=", "next", ";", "}", "value", "=", "next", ";", "}", ")", ";", "return", "value", ";", "}" ]
Navigates the given set of paths in turn on the source object and updates the last path value to the given newValue @method pathSet @for Core @static @param {Object} object the start object to start navigating from @param {Array} paths an array of path names to navigate or a string of dot separated paths to navigate @param {Object} newValue the value to update @return {*} the last step on the path which is updated
[ "Navigates", "the", "given", "set", "of", "paths", "in", "turn", "on", "the", "source", "object", "and", "updates", "the", "last", "path", "value", "to", "the", "given", "newValue" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L549-L562
48,567
hawtio/hawtio-utilities
dist/hawtio-utilities.js
getOrCreateElements
function getOrCreateElements(domElement, arrayOfElementNames) { var element = domElement; angular.forEach(arrayOfElementNames, function (name) { if (element) { var children = $(element).children(name); if (!children || !children.length) { $("<" + name + "></" + name + ">").appendTo(element); children = $(element).children(name); } element = children; } }); return element; }
javascript
function getOrCreateElements(domElement, arrayOfElementNames) { var element = domElement; angular.forEach(arrayOfElementNames, function (name) { if (element) { var children = $(element).children(name); if (!children || !children.length) { $("<" + name + "></" + name + ">").appendTo(element); children = $(element).children(name); } element = children; } }); return element; }
[ "function", "getOrCreateElements", "(", "domElement", ",", "arrayOfElementNames", ")", "{", "var", "element", "=", "domElement", ";", "angular", ".", "forEach", "(", "arrayOfElementNames", ",", "function", "(", "name", ")", "{", "if", "(", "element", ")", "{", "var", "children", "=", "$", "(", "element", ")", ".", "children", "(", "name", ")", ";", "if", "(", "!", "children", "||", "!", "children", ".", "length", ")", "{", "$", "(", "\"<\"", "+", "name", "+", "\"></\"", "+", "name", "+", "\">\"", ")", ".", "appendTo", "(", "element", ")", ";", "children", "=", "$", "(", "element", ")", ".", "children", "(", "name", ")", ";", "}", "element", "=", "children", ";", "}", "}", ")", ";", "return", "element", ";", "}" ]
Look up a list of child element names or lazily create them. Useful for example to get the <tbody> <tr> element from a <table> lazily creating one if not present. Usage: var trElement = getOrCreateElements(tableElement, ["tbody", "tr"]) @method getOrCreateElements @for Core @static @param {Object} domElement @param {Array} arrayOfElementNames @return {Object}
[ "Look", "up", "a", "list", "of", "child", "element", "names", "or", "lazily", "create", "them", "." ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L654-L667
48,568
hawtio/hawtio-utilities
dist/hawtio-utilities.js
escapeHtml
function escapeHtml(str) { if (angular.isString(str)) { var newStr = ""; for (var i = 0; i < str.length; i++) { var ch = str.charAt(i); ch = _escapeHtmlChars[ch] || ch; newStr += ch; } return newStr; } else { return str; } }
javascript
function escapeHtml(str) { if (angular.isString(str)) { var newStr = ""; for (var i = 0; i < str.length; i++) { var ch = str.charAt(i); ch = _escapeHtmlChars[ch] || ch; newStr += ch; } return newStr; } else { return str; } }
[ "function", "escapeHtml", "(", "str", ")", "{", "if", "(", "angular", ".", "isString", "(", "str", ")", ")", "{", "var", "newStr", "=", "\"\"", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "str", ".", "length", ";", "i", "++", ")", "{", "var", "ch", "=", "str", ".", "charAt", "(", "i", ")", ";", "ch", "=", "_escapeHtmlChars", "[", "ch", "]", "||", "ch", ";", "newStr", "+=", "ch", ";", "}", "return", "newStr", ";", "}", "else", "{", "return", "str", ";", "}", "}" ]
static escapeHtml method @param str @returns {*}
[ "static", "escapeHtml", "method" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L697-L710
48,569
hawtio/hawtio-utilities
dist/hawtio-utilities.js
isBlank
function isBlank(str) { if (str === undefined || str === null) { return true; } if (angular.isString(str)) { return str.trim().length === 0; } else { // TODO - not undefined but also not a string... return false; } }
javascript
function isBlank(str) { if (str === undefined || str === null) { return true; } if (angular.isString(str)) { return str.trim().length === 0; } else { // TODO - not undefined but also not a string... return false; } }
[ "function", "isBlank", "(", "str", ")", "{", "if", "(", "str", "===", "undefined", "||", "str", "===", "null", ")", "{", "return", "true", ";", "}", "if", "(", "angular", ".", "isString", "(", "str", ")", ")", "{", "return", "str", ".", "trim", "(", ")", ".", "length", "===", "0", ";", "}", "else", "{", "// TODO - not undefined but also not a string...", "return", "false", ";", "}", "}" ]
Returns true if the string is either null or empty @method isBlank @for Core @static @param {String} str @return {Boolean}
[ "Returns", "true", "if", "the", "string", "is", "either", "null", "or", "empty" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L721-L732
48,570
hawtio/hawtio-utilities
dist/hawtio-utilities.js
humanizeValue
function humanizeValue(value) { if (value) { var text = value + ''; if (Core.isBlank(text)) { return text; } try { text = _.snakeCase(text); text = _.capitalize(text.split('_').join(' ')); } catch (e) { // ignore } return trimQuotes(text); } return value; }
javascript
function humanizeValue(value) { if (value) { var text = value + ''; if (Core.isBlank(text)) { return text; } try { text = _.snakeCase(text); text = _.capitalize(text.split('_').join(' ')); } catch (e) { // ignore } return trimQuotes(text); } return value; }
[ "function", "humanizeValue", "(", "value", ")", "{", "if", "(", "value", ")", "{", "var", "text", "=", "value", "+", "''", ";", "if", "(", "Core", ".", "isBlank", "(", "text", ")", ")", "{", "return", "text", ";", "}", "try", "{", "text", "=", "_", ".", "snakeCase", "(", "text", ")", ";", "text", "=", "_", ".", "capitalize", "(", "text", ".", "split", "(", "'_'", ")", ".", "join", "(", "' '", ")", ")", ";", "}", "catch", "(", "e", ")", "{", "// ignore", "}", "return", "trimQuotes", "(", "text", ")", ";", "}", "return", "value", ";", "}" ]
Converts camel-case and dash-separated strings into Human readable forms @param value @returns {*}
[ "Converts", "camel", "-", "case", "and", "dash", "-", "separated", "strings", "into", "Human", "readable", "forms" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L750-L766
48,571
hawtio/hawtio-utilities
dist/hawtio-utilities.js
lineCount
function lineCount(value) { var rows = 0; if (value) { rows = 1; value.toString().each(/\n/, function () { return rows++; }); } return rows; }
javascript
function lineCount(value) { var rows = 0; if (value) { rows = 1; value.toString().each(/\n/, function () { return rows++; }); } return rows; }
[ "function", "lineCount", "(", "value", ")", "{", "var", "rows", "=", "0", ";", "if", "(", "value", ")", "{", "rows", "=", "1", ";", "value", ".", "toString", "(", ")", ".", "each", "(", "/", "\\n", "/", ",", "function", "(", ")", "{", "return", "rows", "++", ";", "}", ")", ";", "}", "return", "rows", ";", "}" ]
Returns the number of lines in the given text @method lineCount @static @param {String} value @return {Number}
[ "Returns", "the", "number", "of", "lines", "in", "the", "given", "text" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L914-L921
48,572
hawtio/hawtio-utilities
dist/hawtio-utilities.js
toSearchArgumentArray
function toSearchArgumentArray(value) { if (value) { if (angular.isArray(value)) return value; if (angular.isString(value)) return value.split(','); } return []; }
javascript
function toSearchArgumentArray(value) { if (value) { if (angular.isArray(value)) return value; if (angular.isString(value)) return value.split(','); } return []; }
[ "function", "toSearchArgumentArray", "(", "value", ")", "{", "if", "(", "value", ")", "{", "if", "(", "angular", ".", "isArray", "(", "value", ")", ")", "return", "value", ";", "if", "(", "angular", ".", "isString", "(", "value", ")", ")", "return", "value", ".", "split", "(", "','", ")", ";", "}", "return", "[", "]", ";", "}" ]
Converts the given value to an array of query arguments. If the value is null an empty array is returned. If the value is a non empty string then the string is split by commas @method toSearchArgumentArray @static @param {*} value @return {String[]}
[ "Converts", "the", "given", "value", "to", "an", "array", "of", "query", "arguments", "." ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L998-L1006
48,573
hawtio/hawtio-utilities
dist/hawtio-utilities.js
onSuccess
function onSuccess(fn, options) { if (options === void 0) { options = {}; } options['mimeType'] = 'application/json'; if (!_.isUndefined(fn)) { options['success'] = fn; } if (!options['method']) { options['method'] = "POST"; } // the default (unsorted) order is important for Karaf runtime options['canonicalNaming'] = false; options['canonicalProperties'] = false; if (!options['error']) { options['error'] = function (response) { return defaultJolokiaErrorHandler(response, options); }; } return options; }
javascript
function onSuccess(fn, options) { if (options === void 0) { options = {}; } options['mimeType'] = 'application/json'; if (!_.isUndefined(fn)) { options['success'] = fn; } if (!options['method']) { options['method'] = "POST"; } // the default (unsorted) order is important for Karaf runtime options['canonicalNaming'] = false; options['canonicalProperties'] = false; if (!options['error']) { options['error'] = function (response) { return defaultJolokiaErrorHandler(response, options); }; } return options; }
[ "function", "onSuccess", "(", "fn", ",", "options", ")", "{", "if", "(", "options", "===", "void", "0", ")", "{", "options", "=", "{", "}", ";", "}", "options", "[", "'mimeType'", "]", "=", "'application/json'", ";", "if", "(", "!", "_", ".", "isUndefined", "(", "fn", ")", ")", "{", "options", "[", "'success'", "]", "=", "fn", ";", "}", "if", "(", "!", "options", "[", "'method'", "]", ")", "{", "options", "[", "'method'", "]", "=", "\"POST\"", ";", "}", "// the default (unsorted) order is important for Karaf runtime", "options", "[", "'canonicalNaming'", "]", "=", "false", ";", "options", "[", "'canonicalProperties'", "]", "=", "false", ";", "if", "(", "!", "options", "[", "'error'", "]", ")", "{", "options", "[", "'error'", "]", "=", "function", "(", "response", ")", "{", "return", "defaultJolokiaErrorHandler", "(", "response", ",", "options", ")", ";", "}", ";", "}", "return", "options", ";", "}" ]
Pass in null for the success function to switch to sync mode @method onSuccess @static @param {Function} Success callback function @param {Object} Options object to pass on to Jolokia request @return {Object} initialized options object
[ "Pass", "in", "null", "for", "the", "success", "function", "to", "switch", "to", "sync", "mode" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L1058-L1074
48,574
hawtio/hawtio-utilities
dist/hawtio-utilities.js
defaultJolokiaErrorHandler
function defaultJolokiaErrorHandler(response, options) { if (options === void 0) { options = {}; } var operation = Core.pathGet(response, ['request', 'operation']) || "unknown"; var silent = options['silent']; var stacktrace = response.stacktrace; if (silent || isIgnorableException(response)) { log.debug("Operation", operation, "failed due to:", response['error']); } else { log.warn("Operation", operation, "failed due to:", response['error']); } }
javascript
function defaultJolokiaErrorHandler(response, options) { if (options === void 0) { options = {}; } var operation = Core.pathGet(response, ['request', 'operation']) || "unknown"; var silent = options['silent']; var stacktrace = response.stacktrace; if (silent || isIgnorableException(response)) { log.debug("Operation", operation, "failed due to:", response['error']); } else { log.warn("Operation", operation, "failed due to:", response['error']); } }
[ "function", "defaultJolokiaErrorHandler", "(", "response", ",", "options", ")", "{", "if", "(", "options", "===", "void", "0", ")", "{", "options", "=", "{", "}", ";", "}", "var", "operation", "=", "Core", ".", "pathGet", "(", "response", ",", "[", "'request'", ",", "'operation'", "]", ")", "||", "\"unknown\"", ";", "var", "silent", "=", "options", "[", "'silent'", "]", ";", "var", "stacktrace", "=", "response", ".", "stacktrace", ";", "if", "(", "silent", "||", "isIgnorableException", "(", "response", ")", ")", "{", "log", ".", "debug", "(", "\"Operation\"", ",", "operation", ",", "\"failed due to:\"", ",", "response", "[", "'error'", "]", ")", ";", "}", "else", "{", "log", ".", "warn", "(", "\"Operation\"", ",", "operation", ",", "\"failed due to:\"", ",", "response", "[", "'error'", "]", ")", ";", "}", "}" ]
The default error handler which logs errors either using debug or log level logging based on the silent setting @param response the response from a jolokia request
[ "The", "default", "error", "handler", "which", "logs", "errors", "either", "using", "debug", "or", "log", "level", "logging", "based", "on", "the", "silent", "setting" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L1080-L1091
48,575
hawtio/hawtio-utilities
dist/hawtio-utilities.js
isIgnorableException
function isIgnorableException(response) { var isNotFound = function (target) { return target.indexOf("InstanceNotFoundException") >= 0 || target.indexOf("AttributeNotFoundException") >= 0 || target.indexOf("IllegalArgumentException: No operation") >= 0; }; return (response.stacktrace && isNotFound(response.stacktrace)) || (response.error && isNotFound(response.error)); }
javascript
function isIgnorableException(response) { var isNotFound = function (target) { return target.indexOf("InstanceNotFoundException") >= 0 || target.indexOf("AttributeNotFoundException") >= 0 || target.indexOf("IllegalArgumentException: No operation") >= 0; }; return (response.stacktrace && isNotFound(response.stacktrace)) || (response.error && isNotFound(response.error)); }
[ "function", "isIgnorableException", "(", "response", ")", "{", "var", "isNotFound", "=", "function", "(", "target", ")", "{", "return", "target", ".", "indexOf", "(", "\"InstanceNotFoundException\"", ")", ">=", "0", "||", "target", ".", "indexOf", "(", "\"AttributeNotFoundException\"", ")", ">=", "0", "||", "target", ".", "indexOf", "(", "\"IllegalArgumentException: No operation\"", ")", ">=", "0", ";", "}", ";", "return", "(", "response", ".", "stacktrace", "&&", "isNotFound", "(", "response", ".", "stacktrace", ")", ")", "||", "(", "response", ".", "error", "&&", "isNotFound", "(", "response", ".", "error", ")", ")", ";", "}" ]
Checks if it's an error that can happen on timing issues such as its been removed or if we run against older containers @param {Object} response the error response from a jolokia request
[ "Checks", "if", "it", "s", "an", "error", "that", "can", "happen", "on", "timing", "issues", "such", "as", "its", "been", "removed", "or", "if", "we", "run", "against", "older", "containers" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L1097-L1104
48,576
hawtio/hawtio-utilities
dist/hawtio-utilities.js
logJolokiaStackTrace
function logJolokiaStackTrace(response) { var stacktrace = response.stacktrace; if (stacktrace) { var operation = Core.pathGet(response, ['request', 'operation']) || "unknown"; log.info("Operation", operation, "failed due to:", response['error']); } }
javascript
function logJolokiaStackTrace(response) { var stacktrace = response.stacktrace; if (stacktrace) { var operation = Core.pathGet(response, ['request', 'operation']) || "unknown"; log.info("Operation", operation, "failed due to:", response['error']); } }
[ "function", "logJolokiaStackTrace", "(", "response", ")", "{", "var", "stacktrace", "=", "response", ".", "stacktrace", ";", "if", "(", "stacktrace", ")", "{", "var", "operation", "=", "Core", ".", "pathGet", "(", "response", ",", "[", "'request'", ",", "'operation'", "]", ")", "||", "\"unknown\"", ";", "log", ".", "info", "(", "\"Operation\"", ",", "operation", ",", "\"failed due to:\"", ",", "response", "[", "'error'", "]", ")", ";", "}", "}" ]
Logs any failed operation and stack traces
[ "Logs", "any", "failed", "operation", "and", "stack", "traces" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L1108-L1114
48,577
hawtio/hawtio-utilities
dist/hawtio-utilities.js
logLevelClass
function logLevelClass(level) { if (level) { var first = level[0]; if (first === 'w' || first === "W") { return "warning"; } else if (first === 'e' || first === "E") { return "error"; } else if (first === 'i' || first === "I") { return "info"; } else if (first === 'd' || first === "D") { // we have no debug css style return ""; } } return ""; }
javascript
function logLevelClass(level) { if (level) { var first = level[0]; if (first === 'w' || first === "W") { return "warning"; } else if (first === 'e' || first === "E") { return "error"; } else if (first === 'i' || first === "I") { return "info"; } else if (first === 'd' || first === "D") { // we have no debug css style return ""; } } return ""; }
[ "function", "logLevelClass", "(", "level", ")", "{", "if", "(", "level", ")", "{", "var", "first", "=", "level", "[", "0", "]", ";", "if", "(", "first", "===", "'w'", "||", "first", "===", "\"W\"", ")", "{", "return", "\"warning\"", ";", "}", "else", "if", "(", "first", "===", "'e'", "||", "first", "===", "\"E\"", ")", "{", "return", "\"error\"", ";", "}", "else", "if", "(", "first", "===", "'i'", "||", "first", "===", "\"I\"", ")", "{", "return", "\"info\"", ";", "}", "else", "if", "(", "first", "===", "'d'", "||", "first", "===", "\"D\"", ")", "{", "// we have no debug css style", "return", "\"\"", ";", "}", "}", "return", "\"\"", ";", "}" ]
Returns the CSS class for a log level based on if its info, warn, error etc. @method logLevelClass @static @param {String} level @return {String}
[ "Returns", "the", "CSS", "class", "for", "a", "log", "level", "based", "on", "if", "its", "info", "warn", "error", "etc", "." ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L1190-L1208
48,578
hawtio/hawtio-utilities
dist/hawtio-utilities.js
hashToString
function hashToString(hash) { var keyValuePairs = []; angular.forEach(hash, function (value, key) { keyValuePairs.push(key + "=" + value); }); var params = keyValuePairs.join("&"); return encodeURI(params); }
javascript
function hashToString(hash) { var keyValuePairs = []; angular.forEach(hash, function (value, key) { keyValuePairs.push(key + "=" + value); }); var params = keyValuePairs.join("&"); return encodeURI(params); }
[ "function", "hashToString", "(", "hash", ")", "{", "var", "keyValuePairs", "=", "[", "]", ";", "angular", ".", "forEach", "(", "hash", ",", "function", "(", "value", ",", "key", ")", "{", "keyValuePairs", ".", "push", "(", "key", "+", "\"=\"", "+", "value", ")", ";", "}", ")", ";", "var", "params", "=", "keyValuePairs", ".", "join", "(", "\"&\"", ")", ";", "return", "encodeURI", "(", "params", ")", ";", "}" ]
Turns the given search hash into a URI style query string @method hashToString @for Core @static @param {Object} hash @return {String}
[ "Turns", "the", "given", "search", "hash", "into", "a", "URI", "style", "query", "string" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L1275-L1282
48,579
hawtio/hawtio-utilities
dist/hawtio-utilities.js
stringToHash
function stringToHash(hashAsString) { var entries = {}; if (hashAsString) { var text = decodeURI(hashAsString); var items = text.split('&'); angular.forEach(items, function (item) { var kv = item.split('='); var key = kv[0]; var value = kv[1] || key; entries[key] = value; }); } return entries; }
javascript
function stringToHash(hashAsString) { var entries = {}; if (hashAsString) { var text = decodeURI(hashAsString); var items = text.split('&'); angular.forEach(items, function (item) { var kv = item.split('='); var key = kv[0]; var value = kv[1] || key; entries[key] = value; }); } return entries; }
[ "function", "stringToHash", "(", "hashAsString", ")", "{", "var", "entries", "=", "{", "}", ";", "if", "(", "hashAsString", ")", "{", "var", "text", "=", "decodeURI", "(", "hashAsString", ")", ";", "var", "items", "=", "text", ".", "split", "(", "'&'", ")", ";", "angular", ".", "forEach", "(", "items", ",", "function", "(", "item", ")", "{", "var", "kv", "=", "item", ".", "split", "(", "'='", ")", ";", "var", "key", "=", "kv", "[", "0", "]", ";", "var", "value", "=", "kv", "[", "1", "]", "||", "key", ";", "entries", "[", "key", "]", "=", "value", ";", "}", ")", ";", "}", "return", "entries", ";", "}" ]
Parses the given string of x=y&bar=foo into a hash @method stringToHash @for Core @static @param {String} hashAsString @return {Object}
[ "Parses", "the", "given", "string", "of", "x", "=", "y&bar", "=", "foo", "into", "a", "hash" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L1292-L1305
48,580
hawtio/hawtio-utilities
dist/hawtio-utilities.js
registerForChanges
function registerForChanges(jolokia, $scope, arguments, callback, options) { var decorated = { responseJson: '', success: function (response) { var json = angular.toJson(response.value); if (decorated.responseJson !== json) { decorated.responseJson = json; callback(response); } } }; angular.extend(decorated, options); return Core.register(jolokia, $scope, arguments, onSuccess(undefined, decorated)); }
javascript
function registerForChanges(jolokia, $scope, arguments, callback, options) { var decorated = { responseJson: '', success: function (response) { var json = angular.toJson(response.value); if (decorated.responseJson !== json) { decorated.responseJson = json; callback(response); } } }; angular.extend(decorated, options); return Core.register(jolokia, $scope, arguments, onSuccess(undefined, decorated)); }
[ "function", "registerForChanges", "(", "jolokia", ",", "$scope", ",", "arguments", ",", "callback", ",", "options", ")", "{", "var", "decorated", "=", "{", "responseJson", ":", "''", ",", "success", ":", "function", "(", "response", ")", "{", "var", "json", "=", "angular", ".", "toJson", "(", "response", ".", "value", ")", ";", "if", "(", "decorated", ".", "responseJson", "!==", "json", ")", "{", "decorated", ".", "responseJson", "=", "json", ";", "callback", "(", "response", ")", ";", "}", "}", "}", ";", "angular", ".", "extend", "(", "decorated", ",", "options", ")", ";", "return", "Core", ".", "register", "(", "jolokia", ",", "$scope", ",", "arguments", ",", "onSuccess", "(", "undefined", ",", "decorated", ")", ")", ";", "}" ]
Register a JMX operation to poll for changes, only calls back when a change occurs @param jolokia @param scope @param arguments @param callback @param options @returns Object
[ "Register", "a", "JMX", "operation", "to", "poll", "for", "changes", "only", "calls", "back", "when", "a", "change", "occurs" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L1318-L1331
48,581
hawtio/hawtio-utilities
dist/hawtio-utilities.js
register
function register(jolokia, scope, arguments, callback) { if (scope.$$destroyed) { // fail fast to prevent registration leaks return; } /* if (scope && !Core.isBlank(scope.name)) { Core.log.debug("Calling register from scope: ", scope.name); } else { Core.log.debug("Calling register from anonymous scope"); } */ if (!angular.isDefined(scope.$jhandle) || !angular.isArray(scope.$jhandle)) { //log.debug("No existing handle set, creating one"); scope.$jhandle = []; } else { //log.debug("Using existing handle set"); } if (angular.isDefined(scope.$on)) { scope.$on('$destroy', function (event) { unregister(jolokia, scope); }); } var handle = null; if ('success' in callback) { var cb_1 = callback.success; var args_1 = arguments; callback.success = function (response) { addResponse(args_1, response); cb_1(response); }; } if (angular.isArray(arguments)) { if (arguments.length >= 1) { // TODO can't get this to compile in typescript :) //let args = [callback].concat(arguments); var args_2 = [callback]; angular.forEach(arguments, function (value) { return args_2.push(value); }); //let args = [callback]; //args.push(arguments); var registerFn = jolokia.register; handle = registerFn.apply(jolokia, args_2); scope.$jhandle.push(handle); getResponse(jolokia, arguments, callback); } } else { handle = jolokia.register(callback, arguments); scope.$jhandle.push(handle); getResponse(jolokia, arguments, callback); } return function () { if (handle !== null) { scope.$jhandle.remove(handle); jolokia.unregister(handle); } }; }
javascript
function register(jolokia, scope, arguments, callback) { if (scope.$$destroyed) { // fail fast to prevent registration leaks return; } /* if (scope && !Core.isBlank(scope.name)) { Core.log.debug("Calling register from scope: ", scope.name); } else { Core.log.debug("Calling register from anonymous scope"); } */ if (!angular.isDefined(scope.$jhandle) || !angular.isArray(scope.$jhandle)) { //log.debug("No existing handle set, creating one"); scope.$jhandle = []; } else { //log.debug("Using existing handle set"); } if (angular.isDefined(scope.$on)) { scope.$on('$destroy', function (event) { unregister(jolokia, scope); }); } var handle = null; if ('success' in callback) { var cb_1 = callback.success; var args_1 = arguments; callback.success = function (response) { addResponse(args_1, response); cb_1(response); }; } if (angular.isArray(arguments)) { if (arguments.length >= 1) { // TODO can't get this to compile in typescript :) //let args = [callback].concat(arguments); var args_2 = [callback]; angular.forEach(arguments, function (value) { return args_2.push(value); }); //let args = [callback]; //args.push(arguments); var registerFn = jolokia.register; handle = registerFn.apply(jolokia, args_2); scope.$jhandle.push(handle); getResponse(jolokia, arguments, callback); } } else { handle = jolokia.register(callback, arguments); scope.$jhandle.push(handle); getResponse(jolokia, arguments, callback); } return function () { if (handle !== null) { scope.$jhandle.remove(handle); jolokia.unregister(handle); } }; }
[ "function", "register", "(", "jolokia", ",", "scope", ",", "arguments", ",", "callback", ")", "{", "if", "(", "scope", ".", "$$destroyed", ")", "{", "// fail fast to prevent registration leaks", "return", ";", "}", "/*\n if (scope && !Core.isBlank(scope.name)) {\n Core.log.debug(\"Calling register from scope: \", scope.name);\n } else {\n Core.log.debug(\"Calling register from anonymous scope\");\n }\n */", "if", "(", "!", "angular", ".", "isDefined", "(", "scope", ".", "$jhandle", ")", "||", "!", "angular", ".", "isArray", "(", "scope", ".", "$jhandle", ")", ")", "{", "//log.debug(\"No existing handle set, creating one\");", "scope", ".", "$jhandle", "=", "[", "]", ";", "}", "else", "{", "//log.debug(\"Using existing handle set\");", "}", "if", "(", "angular", ".", "isDefined", "(", "scope", ".", "$on", ")", ")", "{", "scope", ".", "$on", "(", "'$destroy'", ",", "function", "(", "event", ")", "{", "unregister", "(", "jolokia", ",", "scope", ")", ";", "}", ")", ";", "}", "var", "handle", "=", "null", ";", "if", "(", "'success'", "in", "callback", ")", "{", "var", "cb_1", "=", "callback", ".", "success", ";", "var", "args_1", "=", "arguments", ";", "callback", ".", "success", "=", "function", "(", "response", ")", "{", "addResponse", "(", "args_1", ",", "response", ")", ";", "cb_1", "(", "response", ")", ";", "}", ";", "}", "if", "(", "angular", ".", "isArray", "(", "arguments", ")", ")", "{", "if", "(", "arguments", ".", "length", ">=", "1", ")", "{", "// TODO can't get this to compile in typescript :)", "//let args = [callback].concat(arguments);", "var", "args_2", "=", "[", "callback", "]", ";", "angular", ".", "forEach", "(", "arguments", ",", "function", "(", "value", ")", "{", "return", "args_2", ".", "push", "(", "value", ")", ";", "}", ")", ";", "//let args = [callback];", "//args.push(arguments);", "var", "registerFn", "=", "jolokia", ".", "register", ";", "handle", "=", "registerFn", ".", "apply", "(", "jolokia", ",", "args_2", ")", ";", "scope", ".", "$jhandle", ".", "push", "(", "handle", ")", ";", "getResponse", "(", "jolokia", ",", "arguments", ",", "callback", ")", ";", "}", "}", "else", "{", "handle", "=", "jolokia", ".", "register", "(", "callback", ",", "arguments", ")", ";", "scope", ".", "$jhandle", ".", "push", "(", "handle", ")", ";", "getResponse", "(", "jolokia", ",", "arguments", ",", "callback", ")", ";", "}", "return", "function", "(", ")", "{", "if", "(", "handle", "!==", "null", ")", "{", "scope", ".", "$jhandle", ".", "remove", "(", "handle", ")", ";", "jolokia", ".", "unregister", "(", "handle", ")", ";", "}", "}", ";", "}" ]
end jolokia caching stuff Register a JMX operation to poll for changes @method register @for Core @static @return {Function} a zero argument function for unregistering this registration @param {*} jolokia @param {*} scope @param {Object} arguments @param {Function} callback
[ "end", "jolokia", "caching", "stuff", "Register", "a", "JMX", "operation", "to", "poll", "for", "changes" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L1465-L1523
48,582
hawtio/hawtio-utilities
dist/hawtio-utilities.js
unregister
function unregister(jolokia, scope) { if (angular.isDefined(scope.$jhandle)) { scope.$jhandle.forEach(function (handle) { jolokia.unregister(handle); }); delete scope.$jhandle; } }
javascript
function unregister(jolokia, scope) { if (angular.isDefined(scope.$jhandle)) { scope.$jhandle.forEach(function (handle) { jolokia.unregister(handle); }); delete scope.$jhandle; } }
[ "function", "unregister", "(", "jolokia", ",", "scope", ")", "{", "if", "(", "angular", ".", "isDefined", "(", "scope", ".", "$jhandle", ")", ")", "{", "scope", ".", "$jhandle", ".", "forEach", "(", "function", "(", "handle", ")", "{", "jolokia", ".", "unregister", "(", "handle", ")", ";", "}", ")", ";", "delete", "scope", ".", "$jhandle", ";", "}", "}" ]
Register a JMX operation to poll for changes using a jolokia search using the given mbean pattern @method registerSearch @for Core @static @paran {*} jolokia @param {*} scope @param {String} mbeanPattern @param {Function} callback /* TODO - won't compile, and where is 'arguments' coming from? export function registerSearch(jolokia:Jolokia.IJolokia, scope, mbeanPattern:string, callback) { if (!angular.isDefined(scope.$jhandle) || !angular.isArray(scope.$jhandle)) { scope.$jhandle = []; } if (angular.isDefined(scope.$on)) { scope.$on('$destroy', function (event) { unregister(jolokia, scope); }); } if (angular.isArray(arguments)) { if (arguments.length >= 1) { TODO can't get this to compile in typescript :) let args = [callback].concat(arguments); let args = [callback]; angular.forEach(arguments, (value) => args.push(value)); let args = [callback]; args.push(arguments); let registerFn = jolokia.register; let handle = registerFn.apply(jolokia, args); scope.$jhandle.push(handle); jolokia.search(mbeanPattern, callback); } } else { let handle = jolokia.register(callback, arguments); scope.$jhandle.push(handle); jolokia.search(mbeanPattern, callback); } }
[ "Register", "a", "JMX", "operation", "to", "poll", "for", "changes", "using", "a", "jolokia", "search", "using", "the", "given", "mbean", "pattern" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L1566-L1573
48,583
hawtio/hawtio-utilities
dist/hawtio-utilities.js
xmlNodeToString
function xmlNodeToString(xmlNode) { try { // Gecko- and Webkit-based browsers (Firefox, Chrome), Opera. return (new XMLSerializer()).serializeToString(xmlNode); } catch (e) { try { // Internet Explorer. return xmlNode.xml; } catch (e) { //Other browsers without XML Serializer console.log('WARNING: XMLSerializer not supported'); } } return false; }
javascript
function xmlNodeToString(xmlNode) { try { // Gecko- and Webkit-based browsers (Firefox, Chrome), Opera. return (new XMLSerializer()).serializeToString(xmlNode); } catch (e) { try { // Internet Explorer. return xmlNode.xml; } catch (e) { //Other browsers without XML Serializer console.log('WARNING: XMLSerializer not supported'); } } return false; }
[ "function", "xmlNodeToString", "(", "xmlNode", ")", "{", "try", "{", "// Gecko- and Webkit-based browsers (Firefox, Chrome), Opera.", "return", "(", "new", "XMLSerializer", "(", ")", ")", ".", "serializeToString", "(", "xmlNode", ")", ";", "}", "catch", "(", "e", ")", "{", "try", "{", "// Internet Explorer.", "return", "xmlNode", ".", "xml", ";", "}", "catch", "(", "e", ")", "{", "//Other browsers without XML Serializer", "console", ".", "log", "(", "'WARNING: XMLSerializer not supported'", ")", ";", "}", "}", "return", "false", ";", "}" ]
Converts the given XML node to a string representation of the XML @method xmlNodeToString @for Core @static @param {Object} xmlNode @return {Object}
[ "Converts", "the", "given", "XML", "node", "to", "a", "string", "representation", "of", "the", "XML" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L1583-L1599
48,584
hawtio/hawtio-utilities
dist/hawtio-utilities.js
fileExtension
function fileExtension(name, defaultValue) { if (defaultValue === void 0) { defaultValue = ""; } var extension = defaultValue; if (name) { var idx = name.lastIndexOf("."); if (idx > 0) { extension = name.substring(idx + 1, name.length).toLowerCase(); } } return extension; }
javascript
function fileExtension(name, defaultValue) { if (defaultValue === void 0) { defaultValue = ""; } var extension = defaultValue; if (name) { var idx = name.lastIndexOf("."); if (idx > 0) { extension = name.substring(idx + 1, name.length).toLowerCase(); } } return extension; }
[ "function", "fileExtension", "(", "name", ",", "defaultValue", ")", "{", "if", "(", "defaultValue", "===", "void", "0", ")", "{", "defaultValue", "=", "\"\"", ";", "}", "var", "extension", "=", "defaultValue", ";", "if", "(", "name", ")", "{", "var", "idx", "=", "name", ".", "lastIndexOf", "(", "\".\"", ")", ";", "if", "(", "idx", ">", "0", ")", "{", "extension", "=", "name", ".", "substring", "(", "idx", "+", "1", ",", "name", ".", "length", ")", ".", "toLowerCase", "(", ")", ";", "}", "}", "return", "extension", ";", "}" ]
Returns the lowercase file extension of the given file name or returns the empty string if the file does not have an extension @method fileExtension @for Core @static @param {String} name @param {String} defaultValue @return {String}
[ "Returns", "the", "lowercase", "file", "extension", "of", "the", "given", "file", "name", "or", "returns", "the", "empty", "string", "if", "the", "file", "does", "not", "have", "an", "extension" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L1623-L1633
48,585
hawtio/hawtio-utilities
dist/hawtio-utilities.js
parseVersionNumbers
function parseVersionNumbers(text) { if (text) { var m = text.match(_versionRegex); if (m && m.length > 4) { var m1 = m[1]; var m2 = m[2]; var m4 = m[4]; if (angular.isDefined(m4)) { return [parseInt(m1), parseInt(m2), parseInt(m4)]; } else if (angular.isDefined(m2)) { return [parseInt(m1), parseInt(m2)]; } else if (angular.isDefined(m1)) { return [parseInt(m1)]; } } } return null; }
javascript
function parseVersionNumbers(text) { if (text) { var m = text.match(_versionRegex); if (m && m.length > 4) { var m1 = m[1]; var m2 = m[2]; var m4 = m[4]; if (angular.isDefined(m4)) { return [parseInt(m1), parseInt(m2), parseInt(m4)]; } else if (angular.isDefined(m2)) { return [parseInt(m1), parseInt(m2)]; } else if (angular.isDefined(m1)) { return [parseInt(m1)]; } } } return null; }
[ "function", "parseVersionNumbers", "(", "text", ")", "{", "if", "(", "text", ")", "{", "var", "m", "=", "text", ".", "match", "(", "_versionRegex", ")", ";", "if", "(", "m", "&&", "m", ".", "length", ">", "4", ")", "{", "var", "m1", "=", "m", "[", "1", "]", ";", "var", "m2", "=", "m", "[", "2", "]", ";", "var", "m4", "=", "m", "[", "4", "]", ";", "if", "(", "angular", ".", "isDefined", "(", "m4", ")", ")", "{", "return", "[", "parseInt", "(", "m1", ")", ",", "parseInt", "(", "m2", ")", ",", "parseInt", "(", "m4", ")", "]", ";", "}", "else", "if", "(", "angular", ".", "isDefined", "(", "m2", ")", ")", "{", "return", "[", "parseInt", "(", "m1", ")", ",", "parseInt", "(", "m2", ")", "]", ";", "}", "else", "if", "(", "angular", ".", "isDefined", "(", "m1", ")", ")", "{", "return", "[", "parseInt", "(", "m1", ")", "]", ";", "}", "}", "}", "return", "null", ";", "}" ]
Parses some text of the form "xxxx2.3.4xxxx" to extract the version numbers as an array of numbers then returns an array of 2 or 3 numbers. Characters before the first digit are ignored as are characters after the last digit. @method parseVersionNumbers @for Core @static @param {String} text a maven like string containing a dash then numbers separated by dots @return {Array}
[ "Parses", "some", "text", "of", "the", "form", "xxxx2", ".", "3", ".", "4xxxx", "to", "extract", "the", "version", "numbers", "as", "an", "array", "of", "numbers", "then", "returns", "an", "array", "of", "2", "or", "3", "numbers", "." ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L1654-L1673
48,586
hawtio/hawtio-utilities
dist/hawtio-utilities.js
versionToSortableString
function versionToSortableString(version, maxDigitsBetweenDots) { if (maxDigitsBetweenDots === void 0) { maxDigitsBetweenDots = 4; } return (version || "").split(".").map(function (x) { var length = x.length; return (length >= maxDigitsBetweenDots) ? x : _.padStart(x, maxDigitsBetweenDots - length, ' '); }).join("."); }
javascript
function versionToSortableString(version, maxDigitsBetweenDots) { if (maxDigitsBetweenDots === void 0) { maxDigitsBetweenDots = 4; } return (version || "").split(".").map(function (x) { var length = x.length; return (length >= maxDigitsBetweenDots) ? x : _.padStart(x, maxDigitsBetweenDots - length, ' '); }).join("."); }
[ "function", "versionToSortableString", "(", "version", ",", "maxDigitsBetweenDots", ")", "{", "if", "(", "maxDigitsBetweenDots", "===", "void", "0", ")", "{", "maxDigitsBetweenDots", "=", "4", ";", "}", "return", "(", "version", "||", "\"\"", ")", ".", "split", "(", "\".\"", ")", ".", "map", "(", "function", "(", "x", ")", "{", "var", "length", "=", "x", ".", "length", ";", "return", "(", "length", ">=", "maxDigitsBetweenDots", ")", "?", "x", ":", "_", ".", "padStart", "(", "x", ",", "maxDigitsBetweenDots", "-", "length", ",", "' '", ")", ";", "}", ")", ".", "join", "(", "\".\"", ")", ";", "}" ]
Converts a version string with numbers and dots of the form "123.456.790" into a string which is sortable as a string, by left padding each string between the dots to at least 4 characters so things just sort as a string. @param text @return {string} the sortable version string
[ "Converts", "a", "version", "string", "with", "numbers", "and", "dots", "of", "the", "form", "123", ".", "456", ".", "790", "into", "a", "string", "which", "is", "sortable", "as", "a", "string", "by", "left", "padding", "each", "string", "between", "the", "dots", "to", "at", "least", "4", "characters", "so", "things", "just", "sort", "as", "a", "string", "." ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L1683-L1690
48,587
hawtio/hawtio-utilities
dist/hawtio-utilities.js
compareVersionNumberArrays
function compareVersionNumberArrays(v1, v2) { if (v1 && !v2) { return 1; } if (!v1 && v2) { return -1; } if (v1 === v2) { return 0; } for (var i = 0; i < v1.length; i++) { var n1 = v1[i]; if (i >= v2.length) { return 1; } var n2 = v2[i]; if (!angular.isDefined(n1)) { return -1; } if (!angular.isDefined(n2)) { return 1; } if (n1 > n2) { return 1; } else if (n1 < n2) { return -1; } } return 0; }
javascript
function compareVersionNumberArrays(v1, v2) { if (v1 && !v2) { return 1; } if (!v1 && v2) { return -1; } if (v1 === v2) { return 0; } for (var i = 0; i < v1.length; i++) { var n1 = v1[i]; if (i >= v2.length) { return 1; } var n2 = v2[i]; if (!angular.isDefined(n1)) { return -1; } if (!angular.isDefined(n2)) { return 1; } if (n1 > n2) { return 1; } else if (n1 < n2) { return -1; } } return 0; }
[ "function", "compareVersionNumberArrays", "(", "v1", ",", "v2", ")", "{", "if", "(", "v1", "&&", "!", "v2", ")", "{", "return", "1", ";", "}", "if", "(", "!", "v1", "&&", "v2", ")", "{", "return", "-", "1", ";", "}", "if", "(", "v1", "===", "v2", ")", "{", "return", "0", ";", "}", "for", "(", "var", "i", "=", "0", ";", "i", "<", "v1", ".", "length", ";", "i", "++", ")", "{", "var", "n1", "=", "v1", "[", "i", "]", ";", "if", "(", "i", ">=", "v2", ".", "length", ")", "{", "return", "1", ";", "}", "var", "n2", "=", "v2", "[", "i", "]", ";", "if", "(", "!", "angular", ".", "isDefined", "(", "n1", ")", ")", "{", "return", "-", "1", ";", "}", "if", "(", "!", "angular", ".", "isDefined", "(", "n2", ")", ")", "{", "return", "1", ";", "}", "if", "(", "n1", ">", "n2", ")", "{", "return", "1", ";", "}", "else", "if", "(", "n1", "<", "n2", ")", "{", "return", "-", "1", ";", "}", "}", "return", "0", ";", "}" ]
Compares the 2 version arrays and returns -1 if v1 is less than v2 or 0 if they are equal or 1 if v1 is greater than v2 @method compareVersionNumberArrays @for Core @static @param {Array} v1 an array of version numbers with the most significant version first (major, minor, patch). @param {Array} v2 @return {Number}
[ "Compares", "the", "2", "version", "arrays", "and", "returns", "-", "1", "if", "v1", "is", "less", "than", "v2", "or", "0", "if", "they", "are", "equal", "or", "1", "if", "v1", "is", "greater", "than", "v2" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L1709-L1739
48,588
hawtio/hawtio-utilities
dist/hawtio-utilities.js
forEachLeafFolder
function forEachLeafFolder(folders, fn) { angular.forEach(folders, function (folder) { var children = folder["children"]; if (angular.isArray(children) && children.length > 0) { forEachLeafFolder(children, fn); } else { fn(folder); } }); }
javascript
function forEachLeafFolder(folders, fn) { angular.forEach(folders, function (folder) { var children = folder["children"]; if (angular.isArray(children) && children.length > 0) { forEachLeafFolder(children, fn); } else { fn(folder); } }); }
[ "function", "forEachLeafFolder", "(", "folders", ",", "fn", ")", "{", "angular", ".", "forEach", "(", "folders", ",", "function", "(", "folder", ")", "{", "var", "children", "=", "folder", "[", "\"children\"", "]", ";", "if", "(", "angular", ".", "isArray", "(", "children", ")", "&&", "children", ".", "length", ">", "0", ")", "{", "forEachLeafFolder", "(", "children", ",", "fn", ")", ";", "}", "else", "{", "fn", "(", "folder", ")", ";", "}", "}", ")", ";", "}" ]
Invokes the given function on each leaf node in the array of folders @method forEachLeafFolder @for Core @static @param {Array[Folder]} folders @param {Function} fn
[ "Invokes", "the", "given", "function", "on", "each", "leaf", "node", "in", "the", "array", "of", "folders" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L1888-L1898
48,589
hawtio/hawtio-utilities
dist/hawtio-utilities.js
parseUrl
function parseUrl(url) { if (Core.isBlank(url)) { return null; } var matches = url.match(httpRegex); if (matches === null) { return null; } //log.debug("matches: ", matches); var scheme = matches[1]; var host = matches[3]; var port = matches[4]; var parts = null; if (!Core.isBlank(port)) { parts = url.split(port); } else { parts = url.split(host); } // make sure we use port as a number var portNum = Core.parseIntValue(port); var path = parts[1]; if (path && _.startsWith(path, '/')) { path = path.slice(1, path.length); } //log.debug("parts: ", parts); return { scheme: scheme, host: host, port: portNum, path: path }; }
javascript
function parseUrl(url) { if (Core.isBlank(url)) { return null; } var matches = url.match(httpRegex); if (matches === null) { return null; } //log.debug("matches: ", matches); var scheme = matches[1]; var host = matches[3]; var port = matches[4]; var parts = null; if (!Core.isBlank(port)) { parts = url.split(port); } else { parts = url.split(host); } // make sure we use port as a number var portNum = Core.parseIntValue(port); var path = parts[1]; if (path && _.startsWith(path, '/')) { path = path.slice(1, path.length); } //log.debug("parts: ", parts); return { scheme: scheme, host: host, port: portNum, path: path }; }
[ "function", "parseUrl", "(", "url", ")", "{", "if", "(", "Core", ".", "isBlank", "(", "url", ")", ")", "{", "return", "null", ";", "}", "var", "matches", "=", "url", ".", "match", "(", "httpRegex", ")", ";", "if", "(", "matches", "===", "null", ")", "{", "return", "null", ";", "}", "//log.debug(\"matches: \", matches);", "var", "scheme", "=", "matches", "[", "1", "]", ";", "var", "host", "=", "matches", "[", "3", "]", ";", "var", "port", "=", "matches", "[", "4", "]", ";", "var", "parts", "=", "null", ";", "if", "(", "!", "Core", ".", "isBlank", "(", "port", ")", ")", "{", "parts", "=", "url", ".", "split", "(", "port", ")", ";", "}", "else", "{", "parts", "=", "url", ".", "split", "(", "host", ")", ";", "}", "// make sure we use port as a number", "var", "portNum", "=", "Core", ".", "parseIntValue", "(", "port", ")", ";", "var", "path", "=", "parts", "[", "1", "]", ";", "if", "(", "path", "&&", "_", ".", "startsWith", "(", "path", ",", "'/'", ")", ")", "{", "path", "=", "path", ".", "slice", "(", "1", ",", "path", ".", "length", ")", ";", "}", "//log.debug(\"parts: \", parts);", "return", "{", "scheme", ":", "scheme", ",", "host", ":", "host", ",", "port", ":", "portNum", ",", "path", ":", "path", "}", ";", "}" ]
Breaks a URL up into a nice object @method parseUrl @for Core @static @param url @returns object
[ "Breaks", "a", "URL", "up", "into", "a", "nice", "object" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L1924-L1956
48,590
hawtio/hawtio-utilities
dist/hawtio-utilities.js
useProxyIfExternal
function useProxyIfExternal(connectUrl) { if (Core.isChromeApp()) { return connectUrl; } var host = window.location.host; if (!_.startsWith(connectUrl, "http://" + host + "/") && !_.startsWith(connectUrl, "https://" + host + "/")) { // lets remove the http stuff var idx = connectUrl.indexOf("://"); if (idx > 0) { connectUrl = connectUrl.substring(idx + 3); } // lets replace the : with a / connectUrl = connectUrl.replace(":", "/"); connectUrl = Core.trimLeading(connectUrl, "/"); connectUrl = Core.trimTrailing(connectUrl, "/"); connectUrl = Core.url("/proxy/" + connectUrl); } return connectUrl; }
javascript
function useProxyIfExternal(connectUrl) { if (Core.isChromeApp()) { return connectUrl; } var host = window.location.host; if (!_.startsWith(connectUrl, "http://" + host + "/") && !_.startsWith(connectUrl, "https://" + host + "/")) { // lets remove the http stuff var idx = connectUrl.indexOf("://"); if (idx > 0) { connectUrl = connectUrl.substring(idx + 3); } // lets replace the : with a / connectUrl = connectUrl.replace(":", "/"); connectUrl = Core.trimLeading(connectUrl, "/"); connectUrl = Core.trimTrailing(connectUrl, "/"); connectUrl = Core.url("/proxy/" + connectUrl); } return connectUrl; }
[ "function", "useProxyIfExternal", "(", "connectUrl", ")", "{", "if", "(", "Core", ".", "isChromeApp", "(", ")", ")", "{", "return", "connectUrl", ";", "}", "var", "host", "=", "window", ".", "location", ".", "host", ";", "if", "(", "!", "_", ".", "startsWith", "(", "connectUrl", ",", "\"http://\"", "+", "host", "+", "\"/\"", ")", "&&", "!", "_", ".", "startsWith", "(", "connectUrl", ",", "\"https://\"", "+", "host", "+", "\"/\"", ")", ")", "{", "// lets remove the http stuff", "var", "idx", "=", "connectUrl", ".", "indexOf", "(", "\"://\"", ")", ";", "if", "(", "idx", ">", "0", ")", "{", "connectUrl", "=", "connectUrl", ".", "substring", "(", "idx", "+", "3", ")", ";", "}", "// lets replace the : with a /", "connectUrl", "=", "connectUrl", ".", "replace", "(", "\":\"", ",", "\"/\"", ")", ";", "connectUrl", "=", "Core", ".", "trimLeading", "(", "connectUrl", ",", "\"/\"", ")", ";", "connectUrl", "=", "Core", ".", "trimTrailing", "(", "connectUrl", ",", "\"/\"", ")", ";", "connectUrl", "=", "Core", ".", "url", "(", "\"/proxy/\"", "+", "connectUrl", ")", ";", "}", "return", "connectUrl", ";", "}" ]
If a URL is external to the current web application, then replace the URL with the proxy servlet URL @method useProxyIfExternal @for Core @static @param {String} connectUrl @return {String}
[ "If", "a", "URL", "is", "external", "to", "the", "current", "web", "application", "then", "replace", "the", "URL", "with", "the", "proxy", "servlet", "URL" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L1972-L1990
48,591
hawtio/hawtio-utilities
dist/hawtio-utilities.js
throttled
function throttled(fn, millis) { var nextInvokeTime = 0; var lastAnswer = null; return function () { var now = Date.now(); if (nextInvokeTime < now) { nextInvokeTime = now + millis; lastAnswer = fn(); } else { //log.debug("Not invoking function as we did call " + (now - (nextInvokeTime - millis)) + " ms ago"); } return lastAnswer; }; }
javascript
function throttled(fn, millis) { var nextInvokeTime = 0; var lastAnswer = null; return function () { var now = Date.now(); if (nextInvokeTime < now) { nextInvokeTime = now + millis; lastAnswer = fn(); } else { //log.debug("Not invoking function as we did call " + (now - (nextInvokeTime - millis)) + " ms ago"); } return lastAnswer; }; }
[ "function", "throttled", "(", "fn", ",", "millis", ")", "{", "var", "nextInvokeTime", "=", "0", ";", "var", "lastAnswer", "=", "null", ";", "return", "function", "(", ")", "{", "var", "now", "=", "Date", ".", "now", "(", ")", ";", "if", "(", "nextInvokeTime", "<", "now", ")", "{", "nextInvokeTime", "=", "now", "+", "millis", ";", "lastAnswer", "=", "fn", "(", ")", ";", "}", "else", "{", "//log.debug(\"Not invoking function as we did call \" + (now - (nextInvokeTime - millis)) + \" ms ago\");", "}", "return", "lastAnswer", ";", "}", ";", "}" ]
Returns a new function which ensures that the delegate function is only invoked at most once within the given number of millseconds @method throttled @for Core @static @param {Function} fn the function to be invoked at most once within the given number of millis @param {Number} millis the time window during which this function should only be called at most once @return {Object}
[ "Returns", "a", "new", "function", "which", "ensures", "that", "the", "delegate", "function", "is", "only", "invoked", "at", "most", "once", "within", "the", "given", "number", "of", "millseconds" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L2081-L2095
48,592
hawtio/hawtio-utilities
dist/hawtio-utilities.js
parseJsonText
function parseJsonText(text, message) { if (message === void 0) { message = "JSON"; } var answer = null; try { answer = angular.fromJson(text); } catch (e) { log.info("Failed to parse " + message + " from: " + text + ". " + e); } return answer; }
javascript
function parseJsonText(text, message) { if (message === void 0) { message = "JSON"; } var answer = null; try { answer = angular.fromJson(text); } catch (e) { log.info("Failed to parse " + message + " from: " + text + ". " + e); } return answer; }
[ "function", "parseJsonText", "(", "text", ",", "message", ")", "{", "if", "(", "message", "===", "void", "0", ")", "{", "message", "=", "\"JSON\"", ";", "}", "var", "answer", "=", "null", ";", "try", "{", "answer", "=", "angular", ".", "fromJson", "(", "text", ")", ";", "}", "catch", "(", "e", ")", "{", "log", ".", "info", "(", "\"Failed to parse \"", "+", "message", "+", "\" from: \"", "+", "text", "+", "\". \"", "+", "e", ")", ";", "}", "return", "answer", ";", "}" ]
Attempts to parse the given JSON text and returns the JSON object structure or null. Bad JSON is logged at info level. @param text a JSON formatted string @param message description of the thing being parsed logged if its invalid
[ "Attempts", "to", "parse", "the", "given", "JSON", "text", "and", "returns", "the", "JSON", "object", "structure", "or", "null", ".", "Bad", "JSON", "is", "logged", "at", "info", "level", "." ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L2104-L2114
48,593
hawtio/hawtio-utilities
dist/hawtio-utilities.js
humanizeValueHtml
function humanizeValueHtml(value) { var formattedValue = ""; if (value === true) { formattedValue = '<i class="icon-check"></i>'; } else if (value === false) { formattedValue = '<i class="icon-check-empty"></i>'; } else { formattedValue = Core.humanizeValue(value); } return formattedValue; }
javascript
function humanizeValueHtml(value) { var formattedValue = ""; if (value === true) { formattedValue = '<i class="icon-check"></i>'; } else if (value === false) { formattedValue = '<i class="icon-check-empty"></i>'; } else { formattedValue = Core.humanizeValue(value); } return formattedValue; }
[ "function", "humanizeValueHtml", "(", "value", ")", "{", "var", "formattedValue", "=", "\"\"", ";", "if", "(", "value", "===", "true", ")", "{", "formattedValue", "=", "'<i class=\"icon-check\"></i>'", ";", "}", "else", "if", "(", "value", "===", "false", ")", "{", "formattedValue", "=", "'<i class=\"icon-check-empty\"></i>'", ";", "}", "else", "{", "formattedValue", "=", "Core", ".", "humanizeValue", "(", "value", ")", ";", "}", "return", "formattedValue", ";", "}" ]
Returns the humanized markup of the given value
[ "Returns", "the", "humanized", "markup", "of", "the", "given", "value" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L2119-L2131
48,594
hawtio/hawtio-utilities
dist/hawtio-utilities.js
getQueryParameterValue
function getQueryParameterValue(url, parameterName) { var parts; var query = (url || '').split('?'); if (query && query.length > 0) { parts = query[1]; } else { parts = ''; } var vars = parts.split('&'); for (var i = 0; i < vars.length; i++) { var pair = vars[i].split('='); if (decodeURIComponent(pair[0]) == parameterName) { return decodeURIComponent(pair[1]); } } // not found return null; }
javascript
function getQueryParameterValue(url, parameterName) { var parts; var query = (url || '').split('?'); if (query && query.length > 0) { parts = query[1]; } else { parts = ''; } var vars = parts.split('&'); for (var i = 0; i < vars.length; i++) { var pair = vars[i].split('='); if (decodeURIComponent(pair[0]) == parameterName) { return decodeURIComponent(pair[1]); } } // not found return null; }
[ "function", "getQueryParameterValue", "(", "url", ",", "parameterName", ")", "{", "var", "parts", ";", "var", "query", "=", "(", "url", "||", "''", ")", ".", "split", "(", "'?'", ")", ";", "if", "(", "query", "&&", "query", ".", "length", ">", "0", ")", "{", "parts", "=", "query", "[", "1", "]", ";", "}", "else", "{", "parts", "=", "''", ";", "}", "var", "vars", "=", "parts", ".", "split", "(", "'&'", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "vars", ".", "length", ";", "i", "++", ")", "{", "var", "pair", "=", "vars", "[", "i", "]", ".", "split", "(", "'='", ")", ";", "if", "(", "decodeURIComponent", "(", "pair", "[", "0", "]", ")", "==", "parameterName", ")", "{", "return", "decodeURIComponent", "(", "pair", "[", "1", "]", ")", ";", "}", "}", "// not found", "return", "null", ";", "}" ]
Gets a query value from the given url @param url url @param parameterName the uri parameter value to get @returns {*}
[ "Gets", "a", "query", "value", "from", "the", "given", "url" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L2140-L2158
48,595
hawtio/hawtio-utilities
dist/hawtio-utilities.js
humanizeMilliseconds
function humanizeMilliseconds(value) { if (!angular.isNumber(value)) { return "XXX"; } var seconds = value / 1000; var years = Math.floor(seconds / 31536000); if (years) { return maybePlural(years, "year"); } var days = Math.floor((seconds %= 31536000) / 86400); if (days) { return maybePlural(days, "day"); } var hours = Math.floor((seconds %= 86400) / 3600); if (hours) { return maybePlural(hours, 'hour'); } var minutes = Math.floor((seconds %= 3600) / 60); if (minutes) { return maybePlural(minutes, 'minute'); } seconds = Math.floor(seconds % 60); if (seconds) { return maybePlural(seconds, 'second'); } return value + " ms"; }
javascript
function humanizeMilliseconds(value) { if (!angular.isNumber(value)) { return "XXX"; } var seconds = value / 1000; var years = Math.floor(seconds / 31536000); if (years) { return maybePlural(years, "year"); } var days = Math.floor((seconds %= 31536000) / 86400); if (days) { return maybePlural(days, "day"); } var hours = Math.floor((seconds %= 86400) / 3600); if (hours) { return maybePlural(hours, 'hour'); } var minutes = Math.floor((seconds %= 3600) / 60); if (minutes) { return maybePlural(minutes, 'minute'); } seconds = Math.floor(seconds % 60); if (seconds) { return maybePlural(seconds, 'second'); } return value + " ms"; }
[ "function", "humanizeMilliseconds", "(", "value", ")", "{", "if", "(", "!", "angular", ".", "isNumber", "(", "value", ")", ")", "{", "return", "\"XXX\"", ";", "}", "var", "seconds", "=", "value", "/", "1000", ";", "var", "years", "=", "Math", ".", "floor", "(", "seconds", "/", "31536000", ")", ";", "if", "(", "years", ")", "{", "return", "maybePlural", "(", "years", ",", "\"year\"", ")", ";", "}", "var", "days", "=", "Math", ".", "floor", "(", "(", "seconds", "%=", "31536000", ")", "/", "86400", ")", ";", "if", "(", "days", ")", "{", "return", "maybePlural", "(", "days", ",", "\"day\"", ")", ";", "}", "var", "hours", "=", "Math", ".", "floor", "(", "(", "seconds", "%=", "86400", ")", "/", "3600", ")", ";", "if", "(", "hours", ")", "{", "return", "maybePlural", "(", "hours", ",", "'hour'", ")", ";", "}", "var", "minutes", "=", "Math", ".", "floor", "(", "(", "seconds", "%=", "3600", ")", "/", "60", ")", ";", "if", "(", "minutes", ")", "{", "return", "maybePlural", "(", "minutes", ",", "'minute'", ")", ";", "}", "seconds", "=", "Math", ".", "floor", "(", "seconds", "%", "60", ")", ";", "if", "(", "seconds", ")", "{", "return", "maybePlural", "(", "seconds", ",", "'second'", ")", ";", "}", "return", "value", "+", "\" ms\"", ";", "}" ]
Takes a value in ms and returns a human readable duration @param value
[ "Takes", "a", "value", "in", "ms", "and", "returns", "a", "human", "readable", "duration" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L2165-L2191
48,596
hawtio/hawtio-utilities
dist/hawtio-utilities.js
createControllerFunction
function createControllerFunction(_module, pluginName) { return function (name, inlineAnnotatedConstructor) { return _module.controller(pluginName + '.' + name, inlineAnnotatedConstructor); }; }
javascript
function createControllerFunction(_module, pluginName) { return function (name, inlineAnnotatedConstructor) { return _module.controller(pluginName + '.' + name, inlineAnnotatedConstructor); }; }
[ "function", "createControllerFunction", "(", "_module", ",", "pluginName", ")", "{", "return", "function", "(", "name", ",", "inlineAnnotatedConstructor", ")", "{", "return", "_module", ".", "controller", "(", "pluginName", "+", "'.'", "+", "name", ",", "inlineAnnotatedConstructor", ")", ";", "}", ";", "}" ]
creates a nice little shortcut function that plugins can use to easily prefix controllers with the plugin name, helps avoid redundancy and typos
[ "creates", "a", "nice", "little", "shortcut", "function", "that", "plugins", "can", "use", "to", "easily", "prefix", "controllers", "with", "the", "plugin", "name", "helps", "avoid", "redundancy", "and", "typos" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L2744-L2748
48,597
hawtio/hawtio-utilities
dist/hawtio-utilities.js
parsePreferencesJson
function parsePreferencesJson(value, key) { var answer = null; if (angular.isDefined(value)) { answer = Core.parseJsonText(value, "localStorage for " + key); } return answer; }
javascript
function parsePreferencesJson(value, key) { var answer = null; if (angular.isDefined(value)) { answer = Core.parseJsonText(value, "localStorage for " + key); } return answer; }
[ "function", "parsePreferencesJson", "(", "value", ",", "key", ")", "{", "var", "answer", "=", "null", ";", "if", "(", "angular", ".", "isDefined", "(", "value", ")", ")", "{", "answer", "=", "Core", ".", "parseJsonText", "(", "value", ",", "\"localStorage for \"", "+", "key", ")", ";", "}", "return", "answer", ";", "}" ]
Parsers the given value as JSON if it is define
[ "Parsers", "the", "given", "value", "as", "JSON", "if", "it", "is", "define" ]
c938a8936a0e547d61b0dfdfdc94145c280d2eeb
https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L2826-L2832
48,598
emreavsar/unjar-from-url
index.js
function () { // looking for keys passed as cli arguments with urls and download-dirs const urlsKey = "urls"; const downloadDirsKey = "download-dirs"; const destinationDir = "destination-dirs"; // keys used in the array (same as in configuration via package.json) for each item (so urls => url) const confUrlsKey = "url"; const confDownloadDirsKey = "directory"; const confDestinationDir = "nodeModulesDir"; // getting cli arguments var argv = require('minimist')(process.argv.slice(2)); var unjarConfigFromArguments = []; if (argv[urlsKey] != null) { // only 1 object passed if (typeof argv[urlsKey] === 'string') { // put into an array, so as it can be used the same way as multiple args argv[urlsKey] = [argv[urlsKey]]; argv[downloadDirsKey] = [argv[downloadDirsKey]]; argv[destinationDir] = [argv[destinationDir]]; } // put them together so that the array has a object with the attributes: nodeModulesDir, directory, url for (var i = 0; i < argv[urlsKey].length; i++) { var configItem = {}; configItem[confUrlsKey] = argv[urlsKey][i]; configItem[confDownloadDirsKey] = argv[downloadDirsKey][i]; configItem[confDestinationDir] = argv[destinationDir][i]; unjarConfigFromArguments.push(configItem); } } return unjarConfigFromArguments; }
javascript
function () { // looking for keys passed as cli arguments with urls and download-dirs const urlsKey = "urls"; const downloadDirsKey = "download-dirs"; const destinationDir = "destination-dirs"; // keys used in the array (same as in configuration via package.json) for each item (so urls => url) const confUrlsKey = "url"; const confDownloadDirsKey = "directory"; const confDestinationDir = "nodeModulesDir"; // getting cli arguments var argv = require('minimist')(process.argv.slice(2)); var unjarConfigFromArguments = []; if (argv[urlsKey] != null) { // only 1 object passed if (typeof argv[urlsKey] === 'string') { // put into an array, so as it can be used the same way as multiple args argv[urlsKey] = [argv[urlsKey]]; argv[downloadDirsKey] = [argv[downloadDirsKey]]; argv[destinationDir] = [argv[destinationDir]]; } // put them together so that the array has a object with the attributes: nodeModulesDir, directory, url for (var i = 0; i < argv[urlsKey].length; i++) { var configItem = {}; configItem[confUrlsKey] = argv[urlsKey][i]; configItem[confDownloadDirsKey] = argv[downloadDirsKey][i]; configItem[confDestinationDir] = argv[destinationDir][i]; unjarConfigFromArguments.push(configItem); } } return unjarConfigFromArguments; }
[ "function", "(", ")", "{", "// looking for keys passed as cli arguments with urls and download-dirs", "const", "urlsKey", "=", "\"urls\"", ";", "const", "downloadDirsKey", "=", "\"download-dirs\"", ";", "const", "destinationDir", "=", "\"destination-dirs\"", ";", "// keys used in the array (same as in configuration via package.json) for each item (so urls => url)", "const", "confUrlsKey", "=", "\"url\"", ";", "const", "confDownloadDirsKey", "=", "\"directory\"", ";", "const", "confDestinationDir", "=", "\"nodeModulesDir\"", ";", "// getting cli arguments", "var", "argv", "=", "require", "(", "'minimist'", ")", "(", "process", ".", "argv", ".", "slice", "(", "2", ")", ")", ";", "var", "unjarConfigFromArguments", "=", "[", "]", ";", "if", "(", "argv", "[", "urlsKey", "]", "!=", "null", ")", "{", "// only 1 object passed", "if", "(", "typeof", "argv", "[", "urlsKey", "]", "===", "'string'", ")", "{", "// put into an array, so as it can be used the same way as multiple args", "argv", "[", "urlsKey", "]", "=", "[", "argv", "[", "urlsKey", "]", "]", ";", "argv", "[", "downloadDirsKey", "]", "=", "[", "argv", "[", "downloadDirsKey", "]", "]", ";", "argv", "[", "destinationDir", "]", "=", "[", "argv", "[", "destinationDir", "]", "]", ";", "}", "// put them together so that the array has a object with the attributes: nodeModulesDir, directory, url", "for", "(", "var", "i", "=", "0", ";", "i", "<", "argv", "[", "urlsKey", "]", ".", "length", ";", "i", "++", ")", "{", "var", "configItem", "=", "{", "}", ";", "configItem", "[", "confUrlsKey", "]", "=", "argv", "[", "urlsKey", "]", "[", "i", "]", ";", "configItem", "[", "confDownloadDirsKey", "]", "=", "argv", "[", "downloadDirsKey", "]", "[", "i", "]", ";", "configItem", "[", "confDestinationDir", "]", "=", "argv", "[", "destinationDir", "]", "[", "i", "]", ";", "unjarConfigFromArguments", ".", "push", "(", "configItem", ")", ";", "}", "}", "return", "unjarConfigFromArguments", ";", "}" ]
Finds the configuration passed by command line arguments. CLI args are limited, thus one have to pass the following CLI arguments: --urls = list of urls to download the jars from --download-dirs = names of the directories to put the jars into (uncompress jar into this directory) --destination-dirs = names of the directories where the directory (download-dirs) will be Example for usage with command line args: <pre><code> --urls http://selenium-release.storage.googleapis.com/2.43/selenium-server-standalone-2.43.1.jar --download-dirs selenium-server-standalone --destination-dirs=/data --urls http://otherurl.com/file.jar --download-dirs otherurl-directory --destination-dirs=/tmp </pre></code> This would download the selenium server standalone 2.4.32.1 jar into /data/selenium-server-standalone/ and uncompress the jar there and file.jar downloaded from http://otherurl.com/file.jar into /tmp/otherurl-directory/ and uncompress the jar there Important: the order does matter (first urls argument matches to first download-dirs and destination-dirs etc.)
[ "Finds", "the", "configuration", "passed", "by", "command", "line", "arguments", "." ]
998b45d0c67a6f21a552ac6780900549d6fb0026
https://github.com/emreavsar/unjar-from-url/blob/998b45d0c67a6f21a552ac6780900549d6fb0026/index.js#L48-L84
48,599
emreavsar/unjar-from-url
index.js
function (module) { const configKey = 'unjar-from-url-config'; if (module == null) { return []; } var highestParent; if (module.parent != null) { highestParent = module.parent; } else { highestParent = module; } var parentFound = false; // iterate up to all parents, until parent is undefined => root of all while (!parentFound) { parentFound = highestParent.parent == undefined || highestParent.parent == null; // go to upper parent if (!parentFound) { highestParent = highestParent.parent; } } // get the path to project itself (where the package.json is) var pathToNodeModules = highestParent.paths[0].split("node_modules")[0]; // read the package json var packageJson = require(pathToNodeModules + "package.json"); var unjarFromUrlConfig; if (packageJson != null && packageJson[configKey] != null) { unjarFromUrlConfig = packageJson[configKey]; } if (unjarFromUrlConfig != null) { // add the highest parent path (used as nodeModulesDir later) to each item var nodeModulesDir = highestParent.paths != null ? highestParent.paths[0] : ''; unjarFromUrlConfig.forEach(function (item) { item.nodeModulesDir = nodeModulesDir }); } else { console.warn("No config found in package.json: ", pathToNodeModules + "package.json"); unjarFromUrlConfig = []; } return unjarFromUrlConfig; }
javascript
function (module) { const configKey = 'unjar-from-url-config'; if (module == null) { return []; } var highestParent; if (module.parent != null) { highestParent = module.parent; } else { highestParent = module; } var parentFound = false; // iterate up to all parents, until parent is undefined => root of all while (!parentFound) { parentFound = highestParent.parent == undefined || highestParent.parent == null; // go to upper parent if (!parentFound) { highestParent = highestParent.parent; } } // get the path to project itself (where the package.json is) var pathToNodeModules = highestParent.paths[0].split("node_modules")[0]; // read the package json var packageJson = require(pathToNodeModules + "package.json"); var unjarFromUrlConfig; if (packageJson != null && packageJson[configKey] != null) { unjarFromUrlConfig = packageJson[configKey]; } if (unjarFromUrlConfig != null) { // add the highest parent path (used as nodeModulesDir later) to each item var nodeModulesDir = highestParent.paths != null ? highestParent.paths[0] : ''; unjarFromUrlConfig.forEach(function (item) { item.nodeModulesDir = nodeModulesDir }); } else { console.warn("No config found in package.json: ", pathToNodeModules + "package.json"); unjarFromUrlConfig = []; } return unjarFromUrlConfig; }
[ "function", "(", "module", ")", "{", "const", "configKey", "=", "'unjar-from-url-config'", ";", "if", "(", "module", "==", "null", ")", "{", "return", "[", "]", ";", "}", "var", "highestParent", ";", "if", "(", "module", ".", "parent", "!=", "null", ")", "{", "highestParent", "=", "module", ".", "parent", ";", "}", "else", "{", "highestParent", "=", "module", ";", "}", "var", "parentFound", "=", "false", ";", "// iterate up to all parents, until parent is undefined => root of all", "while", "(", "!", "parentFound", ")", "{", "parentFound", "=", "highestParent", ".", "parent", "==", "undefined", "||", "highestParent", ".", "parent", "==", "null", ";", "// go to upper parent", "if", "(", "!", "parentFound", ")", "{", "highestParent", "=", "highestParent", ".", "parent", ";", "}", "}", "// get the path to project itself (where the package.json is)", "var", "pathToNodeModules", "=", "highestParent", ".", "paths", "[", "0", "]", ".", "split", "(", "\"node_modules\"", ")", "[", "0", "]", ";", "// read the package json", "var", "packageJson", "=", "require", "(", "pathToNodeModules", "+", "\"package.json\"", ")", ";", "var", "unjarFromUrlConfig", ";", "if", "(", "packageJson", "!=", "null", "&&", "packageJson", "[", "configKey", "]", "!=", "null", ")", "{", "unjarFromUrlConfig", "=", "packageJson", "[", "configKey", "]", ";", "}", "if", "(", "unjarFromUrlConfig", "!=", "null", ")", "{", "// add the highest parent path (used as nodeModulesDir later) to each item", "var", "nodeModulesDir", "=", "highestParent", ".", "paths", "!=", "null", "?", "highestParent", ".", "paths", "[", "0", "]", ":", "''", ";", "unjarFromUrlConfig", ".", "forEach", "(", "function", "(", "item", ")", "{", "item", ".", "nodeModulesDir", "=", "nodeModulesDir", "}", ")", ";", "}", "else", "{", "console", ".", "warn", "(", "\"No config found in package.json: \"", ",", "pathToNodeModules", "+", "\"package.json\"", ")", ";", "unjarFromUrlConfig", "=", "[", "]", ";", "}", "return", "unjarFromUrlConfig", ";", "}" ]
Searches the unjar configuration inside the highest parent's package.json. This is typically used when this module is used inside another project which has the configuration inside the package.json of the project itself. Returns unjar configuration as a js object. Example for configuration: <pre><code> // package.json of your project ... unjar-config: [ { "directory": "selenium-server-standalone", "url": "http://selenium-release.storage.googleapis.com/2.43/selenium-server-standalone-2.43.1.jar" }, { // other jars } ] </pre></code> @param {module} module to start searching the configuration file
[ "Searches", "the", "unjar", "configuration", "inside", "the", "highest", "parent", "s", "package", ".", "json", ".", "This", "is", "typically", "used", "when", "this", "module", "is", "used", "inside", "another", "project", "which", "has", "the", "configuration", "inside", "the", "package", ".", "json", "of", "the", "project", "itself", "." ]
998b45d0c67a6f21a552ac6780900549d6fb0026
https://github.com/emreavsar/unjar-from-url/blob/998b45d0c67a6f21a552ac6780900549d6fb0026/index.js#L109-L158