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
sequence
docstring
stringlengths
4
11.8k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
86
226
51,900
novadiscovery/nway
lib/parsers/css/injector.js
injector
function injector(css, module, makeModule, options) { output_css = join(options.output, options.css_folder || 'css'); location_css = options.client + '/' + (options.css_folder || 'css'); output_links = join(options.output, options.links_folder || 'links'); location_links = options.client + '/' + (options.links_folder || 'links'); // Unify css url (and store related assets in a sub directory 'links') css = rework(css) .use(unifyurl(module.path, output_links, location_links, options)) .toString(); // Create the css file var uid = getUID(options) + getUID(css) , oFilename = uid + '.css' , oFilepath = join(output_css, oFilename) , oLocation = location_css + '/' + oFilename ; write(oFilepath, css, {encoding:'utf8'}) var js = tmpl.replace(/\{\{location\}\}/, oLocation); return jsParser(js, module, makeModule, options); }
javascript
function injector(css, module, makeModule, options) { output_css = join(options.output, options.css_folder || 'css'); location_css = options.client + '/' + (options.css_folder || 'css'); output_links = join(options.output, options.links_folder || 'links'); location_links = options.client + '/' + (options.links_folder || 'links'); // Unify css url (and store related assets in a sub directory 'links') css = rework(css) .use(unifyurl(module.path, output_links, location_links, options)) .toString(); // Create the css file var uid = getUID(options) + getUID(css) , oFilename = uid + '.css' , oFilepath = join(output_css, oFilename) , oLocation = location_css + '/' + oFilename ; write(oFilepath, css, {encoding:'utf8'}) var js = tmpl.replace(/\{\{location\}\}/, oLocation); return jsParser(js, module, makeModule, options); }
[ "function", "injector", "(", "css", ",", "module", ",", "makeModule", ",", "options", ")", "{", "output_css", "=", "join", "(", "options", ".", "output", ",", "options", ".", "css_folder", "||", "'css'", ")", ";", "location_css", "=", "options", ".", "client", "+", "'/'", "+", "(", "options", ".", "css_folder", "||", "'css'", ")", ";", "output_links", "=", "join", "(", "options", ".", "output", ",", "options", ".", "links_folder", "||", "'links'", ")", ";", "location_links", "=", "options", ".", "client", "+", "'/'", "+", "(", "options", ".", "links_folder", "||", "'links'", ")", ";", "// Unify css url (and store related assets in a sub directory 'links')", "css", "=", "rework", "(", "css", ")", ".", "use", "(", "unifyurl", "(", "module", ".", "path", ",", "output_links", ",", "location_links", ",", "options", ")", ")", ".", "toString", "(", ")", ";", "// Create the css file", "var", "uid", "=", "getUID", "(", "options", ")", "+", "getUID", "(", "css", ")", ",", "oFilename", "=", "uid", "+", "'.css'", ",", "oFilepath", "=", "join", "(", "output_css", ",", "oFilename", ")", ",", "oLocation", "=", "location_css", "+", "'/'", "+", "oFilename", ";", "write", "(", "oFilepath", ",", "css", ",", "{", "encoding", ":", "'utf8'", "}", ")", "var", "js", "=", "tmpl", ".", "replace", "(", "/", "\\{\\{location\\}\\}", "/", ",", "oLocation", ")", ";", "return", "jsParser", "(", "js", ",", "module", ",", "makeModule", ",", "options", ")", ";", "}" ]
Injector module for css source A nway parser function who create a nway javascript module that offer a css injector for the css source. The module exports: - inject([media]): Inject css in the page (with a loaded promise) may be called with a media attribute (default:all) - eject(): remove css off the page - injected *boolean*: The css is injected - location *css*: The css location
[ "Injector", "module", "for", "css", "source" ]
fa31c6fe56f2305721e581ac25e8ac9a87e15dda
https://github.com/novadiscovery/nway/blob/fa31c6fe56f2305721e581ac25e8ac9a87e15dda/lib/parsers/css/injector.js#L54-L77
51,901
xsolon/spexplorerjs
webapi/src/components/sp/widgets/treelight.js
function () { if (!enumer.moveNext()) { cb(groups); return; } var li = enumer.get_current(); var name = li.get_item("Name"); if (name.search(" ") > 0) { doNext(); } else { var id = li.get_item("ID"); var user = web.ensureUser(name); ctx.load(user); groups.push({ text: name, id: id + "_User", data: user, icon: "/_layouts/images/ribbon_userprofile_16.png" }); //count++; //if (count % 50 == 0) ctx.executeQueryAsync(function () { doNext(); }, function () { doNext(); }); } }
javascript
function () { if (!enumer.moveNext()) { cb(groups); return; } var li = enumer.get_current(); var name = li.get_item("Name"); if (name.search(" ") > 0) { doNext(); } else { var id = li.get_item("ID"); var user = web.ensureUser(name); ctx.load(user); groups.push({ text: name, id: id + "_User", data: user, icon: "/_layouts/images/ribbon_userprofile_16.png" }); //count++; //if (count % 50 == 0) ctx.executeQueryAsync(function () { doNext(); }, function () { doNext(); }); } }
[ "function", "(", ")", "{", "if", "(", "!", "enumer", ".", "moveNext", "(", ")", ")", "{", "cb", "(", "groups", ")", ";", "return", ";", "}", "var", "li", "=", "enumer", ".", "get_current", "(", ")", ";", "var", "name", "=", "li", ".", "get_item", "(", "\"Name\"", ")", ";", "if", "(", "name", ".", "search", "(", "\" \"", ")", ">", "0", ")", "{", "doNext", "(", ")", ";", "}", "else", "{", "var", "id", "=", "li", ".", "get_item", "(", "\"ID\"", ")", ";", "var", "user", "=", "web", ".", "ensureUser", "(", "name", ")", ";", "ctx", ".", "load", "(", "user", ")", ";", "groups", ".", "push", "(", "{", "text", ":", "name", ",", "id", ":", "id", "+", "\"_User\"", ",", "data", ":", "user", ",", "icon", ":", "\"/_layouts/images/ribbon_userprofile_16.png\"", "}", ")", ";", "//count++;", "//if (count % 50 == 0)", "ctx", ".", "executeQueryAsync", "(", "function", "(", ")", "{", "doNext", "(", ")", ";", "}", ",", "function", "(", ")", "{", "doNext", "(", ")", ";", "}", ")", ";", "}", "}" ]
var count = 0;
[ "var", "count", "=", "0", ";" ]
4e9b410864afb731f88e84414984fa18ac5705f1
https://github.com/xsolon/spexplorerjs/blob/4e9b410864afb731f88e84414984fa18ac5705f1/webapi/src/components/sp/widgets/treelight.js#L121-L146
51,902
BuZZ-dEE/fussball-de-matchplan-grabber
index.js
parseMatchplan
function parseMatchplan(team, callback) { /** @type {String[]} */ var matchPlanArr = [], /** @type {Matchplan} */ matchPlan, /** @type {String[]} */ matchDetails = [], /** @type {Encounter[]} */ encounters = []; jsdom.env({ url: team, scripts: ["http://code.jquery.com/jquery.js"], done: function (err, window) { var $ = window.$; $("tr.row-headline").each(function() { matchPlanArr.push(parseMatchTime($(this).text())); }); $(".club-name").each(function(index) { if ((index + 1) % 2 === 0) { encounters[encounters.length - 1].setVisitingTeam($(this).text()); } else { encounters.push(new Encounter($(this).text())); } }); $("td.column-detail a").each(function(index, element) { matchDetails.push(new URL(element.href)); }); matchPlan = createMatchplan(matchPlanArr, encounters, matchDetails); matchPlan.output(); callback(matchPlan); } }); }
javascript
function parseMatchplan(team, callback) { /** @type {String[]} */ var matchPlanArr = [], /** @type {Matchplan} */ matchPlan, /** @type {String[]} */ matchDetails = [], /** @type {Encounter[]} */ encounters = []; jsdom.env({ url: team, scripts: ["http://code.jquery.com/jquery.js"], done: function (err, window) { var $ = window.$; $("tr.row-headline").each(function() { matchPlanArr.push(parseMatchTime($(this).text())); }); $(".club-name").each(function(index) { if ((index + 1) % 2 === 0) { encounters[encounters.length - 1].setVisitingTeam($(this).text()); } else { encounters.push(new Encounter($(this).text())); } }); $("td.column-detail a").each(function(index, element) { matchDetails.push(new URL(element.href)); }); matchPlan = createMatchplan(matchPlanArr, encounters, matchDetails); matchPlan.output(); callback(matchPlan); } }); }
[ "function", "parseMatchplan", "(", "team", ",", "callback", ")", "{", "/** @type {String[]} */", "var", "matchPlanArr", "=", "[", "]", ",", "/** @type {Matchplan} */", "matchPlan", ",", "/** @type {String[]} */", "matchDetails", "=", "[", "]", ",", "/** @type {Encounter[]} */", "encounters", "=", "[", "]", ";", "jsdom", ".", "env", "(", "{", "url", ":", "team", ",", "scripts", ":", "[", "\"http://code.jquery.com/jquery.js\"", "]", ",", "done", ":", "function", "(", "err", ",", "window", ")", "{", "var", "$", "=", "window", ".", "$", ";", "$", "(", "\"tr.row-headline\"", ")", ".", "each", "(", "function", "(", ")", "{", "matchPlanArr", ".", "push", "(", "parseMatchTime", "(", "$", "(", "this", ")", ".", "text", "(", ")", ")", ")", ";", "}", ")", ";", "$", "(", "\".club-name\"", ")", ".", "each", "(", "function", "(", "index", ")", "{", "if", "(", "(", "index", "+", "1", ")", "%", "2", "===", "0", ")", "{", "encounters", "[", "encounters", ".", "length", "-", "1", "]", ".", "setVisitingTeam", "(", "$", "(", "this", ")", ".", "text", "(", ")", ")", ";", "}", "else", "{", "encounters", ".", "push", "(", "new", "Encounter", "(", "$", "(", "this", ")", ".", "text", "(", ")", ")", ")", ";", "}", "}", ")", ";", "$", "(", "\"td.column-detail a\"", ")", ".", "each", "(", "function", "(", "index", ",", "element", ")", "{", "matchDetails", ".", "push", "(", "new", "URL", "(", "element", ".", "href", ")", ")", ";", "}", ")", ";", "matchPlan", "=", "createMatchplan", "(", "matchPlanArr", ",", "encounters", ",", "matchDetails", ")", ";", "matchPlan", ".", "output", "(", ")", ";", "callback", "(", "matchPlan", ")", ";", "}", "}", ")", ";", "}" ]
Parse the match plan. @param {String} team - The next matches team URL. @param {function} callback - The function to call back with the match plan.
[ "Parse", "the", "match", "plan", "." ]
01b4766b7cc1ea42e9acb885ca132b5fc0598cd9
https://github.com/BuZZ-dEE/fussball-de-matchplan-grabber/blob/01b4766b7cc1ea42e9acb885ca132b5fc0598cd9/index.js#L12-L50
51,903
BuZZ-dEE/fussball-de-matchplan-grabber
index.js
parseMatchTime
function parseMatchTime(matchTime) { /** @type String[] */ var matchTimeArr = matchTime.split(' '); matchTimeArr = [matchTimeArr[1], matchTimeArr[3]]; var dayMonthYear = matchTimeArr[0].split('.'); var hourMinutes = matchTimeArr[1].split(':'); var date = new Date(dayMonthYear[2], parseInt(dayMonthYear[1]) - 1, dayMonthYear[0], hourMinutes[0], hourMinutes[1]); return date; }
javascript
function parseMatchTime(matchTime) { /** @type String[] */ var matchTimeArr = matchTime.split(' '); matchTimeArr = [matchTimeArr[1], matchTimeArr[3]]; var dayMonthYear = matchTimeArr[0].split('.'); var hourMinutes = matchTimeArr[1].split(':'); var date = new Date(dayMonthYear[2], parseInt(dayMonthYear[1]) - 1, dayMonthYear[0], hourMinutes[0], hourMinutes[1]); return date; }
[ "function", "parseMatchTime", "(", "matchTime", ")", "{", "/** @type String[] */", "var", "matchTimeArr", "=", "matchTime", ".", "split", "(", "' '", ")", ";", "matchTimeArr", "=", "[", "matchTimeArr", "[", "1", "]", ",", "matchTimeArr", "[", "3", "]", "]", ";", "var", "dayMonthYear", "=", "matchTimeArr", "[", "0", "]", ".", "split", "(", "'.'", ")", ";", "var", "hourMinutes", "=", "matchTimeArr", "[", "1", "]", ".", "split", "(", "':'", ")", ";", "var", "date", "=", "new", "Date", "(", "dayMonthYear", "[", "2", "]", ",", "parseInt", "(", "dayMonthYear", "[", "1", "]", ")", "-", "1", ",", "dayMonthYear", "[", "0", "]", ",", "hourMinutes", "[", "0", "]", ",", "hourMinutes", "[", "1", "]", ")", ";", "return", "date", ";", "}" ]
Parse the match time. @param {String} matchTime @returns {Date} The match date time.
[ "Parse", "the", "match", "time", "." ]
01b4766b7cc1ea42e9acb885ca132b5fc0598cd9
https://github.com/BuZZ-dEE/fussball-de-matchplan-grabber/blob/01b4766b7cc1ea42e9acb885ca132b5fc0598cd9/index.js#L58-L68
51,904
BuZZ-dEE/fussball-de-matchplan-grabber
index.js
createMatchplan
function createMatchplan(matchPlanArr, encounters, matchDetails) { var matchPlan = new Matchplan(); matchPlanArr.forEach(function(currentValue, index, array) { matchplanEntry = new MatchplanEntry(currentValue, null, encounters[index], null, matchDetails[index]); matchPlan.addEntry(matchplanEntry); }); return matchPlan; }
javascript
function createMatchplan(matchPlanArr, encounters, matchDetails) { var matchPlan = new Matchplan(); matchPlanArr.forEach(function(currentValue, index, array) { matchplanEntry = new MatchplanEntry(currentValue, null, encounters[index], null, matchDetails[index]); matchPlan.addEntry(matchplanEntry); }); return matchPlan; }
[ "function", "createMatchplan", "(", "matchPlanArr", ",", "encounters", ",", "matchDetails", ")", "{", "var", "matchPlan", "=", "new", "Matchplan", "(", ")", ";", "matchPlanArr", ".", "forEach", "(", "function", "(", "currentValue", ",", "index", ",", "array", ")", "{", "matchplanEntry", "=", "new", "MatchplanEntry", "(", "currentValue", ",", "null", ",", "encounters", "[", "index", "]", ",", "null", ",", "matchDetails", "[", "index", "]", ")", ";", "matchPlan", ".", "addEntry", "(", "matchplanEntry", ")", ";", "}", ")", ";", "return", "matchPlan", ";", "}" ]
Create the match plan. @param {String[]} matchPlanArr @param {Encounter[]} encounters @param {URL[]} matchDetails @returns {Matchplan}
[ "Create", "the", "match", "plan", "." ]
01b4766b7cc1ea42e9acb885ca132b5fc0598cd9
https://github.com/BuZZ-dEE/fussball-de-matchplan-grabber/blob/01b4766b7cc1ea42e9acb885ca132b5fc0598cd9/index.js#L78-L85
51,905
bigpipe/bigpipe-watch
index.js
refresh
function refresh(file, event, full) { views.forEach(function loopViews(path) { if (path !== full) return; tempers.forEach(function eachTemper(temper) { delete temper.file[path]; delete temper.compiled[path]; temper.prefetch(path); }); }); assets.forEach(function loopAssets(path) { if (path !== full) return; bigpipe.compiler.put(path); }); bigpipe.emit('change', file, event, full); console.log([ '[watch] detected content changes --'.blue, file.white, 'changed'.white ].join(' ')); }
javascript
function refresh(file, event, full) { views.forEach(function loopViews(path) { if (path !== full) return; tempers.forEach(function eachTemper(temper) { delete temper.file[path]; delete temper.compiled[path]; temper.prefetch(path); }); }); assets.forEach(function loopAssets(path) { if (path !== full) return; bigpipe.compiler.put(path); }); bigpipe.emit('change', file, event, full); console.log([ '[watch] detected content changes --'.blue, file.white, 'changed'.white ].join(' ')); }
[ "function", "refresh", "(", "file", ",", "event", ",", "full", ")", "{", "views", ".", "forEach", "(", "function", "loopViews", "(", "path", ")", "{", "if", "(", "path", "!==", "full", ")", "return", ";", "tempers", ".", "forEach", "(", "function", "eachTemper", "(", "temper", ")", "{", "delete", "temper", ".", "file", "[", "path", "]", ";", "delete", "temper", ".", "compiled", "[", "path", "]", ";", "temper", ".", "prefetch", "(", "path", ")", ";", "}", ")", ";", "}", ")", ";", "assets", ".", "forEach", "(", "function", "loopAssets", "(", "path", ")", "{", "if", "(", "path", "!==", "full", ")", "return", ";", "bigpipe", ".", "compiler", ".", "put", "(", "path", ")", ";", "}", ")", ";", "bigpipe", ".", "emit", "(", "'change'", ",", "file", ",", "event", ",", "full", ")", ";", "console", ".", "log", "(", "[", "'[watch] detected content changes --'", ".", "blue", ",", "file", ".", "white", ",", "'changed'", ".", "white", "]", ".", "join", "(", "' '", ")", ")", ";", "}" ]
Check cache and prefetch if the file is part of the compiler. @param {String} file name @api private
[ "Check", "cache", "and", "prefetch", "if", "the", "file", "is", "part", "of", "the", "compiler", "." ]
337ef162a4c5c4533a2120437e5fbb8a300e0bc2
https://github.com/bigpipe/bigpipe-watch/blob/337ef162a4c5c4533a2120437e5fbb8a300e0bc2/index.js#L78-L102
51,906
thirdcoder/tritwise
tritwise.js
dyadic_pref_op
function dyadic_pref_op(pref, input1, input2, input_width) { if (pref < -13 || pref > 13) throw new Error('dyadic_pref_op('+pref+'): out of range iii-111'); var bt_pref = pad(3, n2bts(pref), '0'); if (bt_pref.indexOf('i') === -1 || bt_pref.indexOf('0') === -1 || bt_pref.indexOf('1') === -1) throw new Error('dyadic_pref_op('+pref+'): preference must contain all digits i,0,1'); var input1_bt = pad(input_width, n2bts(input1), '0'); var input2_bt = pad(input_width, n2bts(input2), '0'); var output_bt = ''; for (var i = 0; i < input_width; ++i) { var a = input1_bt.charAt(i); var b = input2_bt.charAt(i); if (bt_pref.indexOf(a) < bt_pref.indexOf(b)) { // a has a higher preference than b (comes earlier in preference list), choose a output_bt += a; } else { // otherwise choose b (preference functions always choose one of the inputs) output_bt += b; } } var output = bts2n(output_bt); return output; }
javascript
function dyadic_pref_op(pref, input1, input2, input_width) { if (pref < -13 || pref > 13) throw new Error('dyadic_pref_op('+pref+'): out of range iii-111'); var bt_pref = pad(3, n2bts(pref), '0'); if (bt_pref.indexOf('i') === -1 || bt_pref.indexOf('0') === -1 || bt_pref.indexOf('1') === -1) throw new Error('dyadic_pref_op('+pref+'): preference must contain all digits i,0,1'); var input1_bt = pad(input_width, n2bts(input1), '0'); var input2_bt = pad(input_width, n2bts(input2), '0'); var output_bt = ''; for (var i = 0; i < input_width; ++i) { var a = input1_bt.charAt(i); var b = input2_bt.charAt(i); if (bt_pref.indexOf(a) < bt_pref.indexOf(b)) { // a has a higher preference than b (comes earlier in preference list), choose a output_bt += a; } else { // otherwise choose b (preference functions always choose one of the inputs) output_bt += b; } } var output = bts2n(output_bt); return output; }
[ "function", "dyadic_pref_op", "(", "pref", ",", "input1", ",", "input2", ",", "input_width", ")", "{", "if", "(", "pref", "<", "-", "13", "||", "pref", ">", "13", ")", "throw", "new", "Error", "(", "'dyadic_pref_op('", "+", "pref", "+", "'): out of range iii-111'", ")", ";", "var", "bt_pref", "=", "pad", "(", "3", ",", "n2bts", "(", "pref", ")", ",", "'0'", ")", ";", "if", "(", "bt_pref", ".", "indexOf", "(", "'i'", ")", "===", "-", "1", "||", "bt_pref", ".", "indexOf", "(", "'0'", ")", "===", "-", "1", "||", "bt_pref", ".", "indexOf", "(", "'1'", ")", "===", "-", "1", ")", "throw", "new", "Error", "(", "'dyadic_pref_op('", "+", "pref", "+", "'): preference must contain all digits i,0,1'", ")", ";", "var", "input1_bt", "=", "pad", "(", "input_width", ",", "n2bts", "(", "input1", ")", ",", "'0'", ")", ";", "var", "input2_bt", "=", "pad", "(", "input_width", ",", "n2bts", "(", "input2", ")", ",", "'0'", ")", ";", "var", "output_bt", "=", "''", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "input_width", ";", "++", "i", ")", "{", "var", "a", "=", "input1_bt", ".", "charAt", "(", "i", ")", ";", "var", "b", "=", "input2_bt", ".", "charAt", "(", "i", ")", ";", "if", "(", "bt_pref", ".", "indexOf", "(", "a", ")", "<", "bt_pref", ".", "indexOf", "(", "b", ")", ")", "{", "// a has a higher preference than b (comes earlier in preference list), choose a", "output_bt", "+=", "a", ";", "}", "else", "{", "// otherwise choose b (preference functions always choose one of the inputs)", "output_bt", "+=", "b", ";", "}", "}", "var", "output", "=", "bts2n", "(", "output_bt", ")", ";", "return", "output", ";", "}" ]
Dyadic preference functions
[ "Dyadic", "preference", "functions" ]
d947fa07e88a9e516279c6ac5e9eda6e8228ecf2
https://github.com/thirdcoder/tritwise/blob/d947fa07e88a9e516279c6ac5e9eda6e8228ecf2/tritwise.js#L46-L73
51,907
glebmachine/node-localcache
index.js
ejectionHandler
function ejectionHandler() { process.stdin.resume(); log(chalk.yellow('Ejection, swooooooooo-oooopphhhf!')); _this.fileSynceInstantly(function ejectionComplete() { log(chalk.green('Everything saved, for god sake')); log('shittung down, see you next life'); process.exit(); }); }
javascript
function ejectionHandler() { process.stdin.resume(); log(chalk.yellow('Ejection, swooooooooo-oooopphhhf!')); _this.fileSynceInstantly(function ejectionComplete() { log(chalk.green('Everything saved, for god sake')); log('shittung down, see you next life'); process.exit(); }); }
[ "function", "ejectionHandler", "(", ")", "{", "process", ".", "stdin", ".", "resume", "(", ")", ";", "log", "(", "chalk", ".", "yellow", "(", "'Ejection, swooooooooo-oooopphhhf!'", ")", ")", ";", "_this", ".", "fileSynceInstantly", "(", "function", "ejectionComplete", "(", ")", "{", "log", "(", "chalk", ".", "green", "(", "'Everything saved, for god sake'", ")", ")", ";", "log", "(", "'shittung down, see you next life'", ")", ";", "process", ".", "exit", "(", ")", ";", "}", ")", ";", "}" ]
handler for exit fo nodejs process
[ "handler", "for", "exit", "fo", "nodejs", "process" ]
a8ecf248c16e11871faa581d61453bd8f81b6d9c
https://github.com/glebmachine/node-localcache/blob/a8ecf248c16e11871faa581d61453bd8f81b6d9c/index.js#L41-L49
51,908
redisjs/jsr-server
lib/command/server/shutdown.js
execute
function execute(req, res) { var save = undefined; if(req.args[0] !== undefined) { save = req.args[0] === true; } this.shutdown({save: save, code: 0}, process.exit); }
javascript
function execute(req, res) { var save = undefined; if(req.args[0] !== undefined) { save = req.args[0] === true; } this.shutdown({save: save, code: 0}, process.exit); }
[ "function", "execute", "(", "req", ",", "res", ")", "{", "var", "save", "=", "undefined", ";", "if", "(", "req", ".", "args", "[", "0", "]", "!==", "undefined", ")", "{", "save", "=", "req", ".", "args", "[", "0", "]", "===", "true", ";", "}", "this", ".", "shutdown", "(", "{", "save", ":", "save", ",", "code", ":", "0", "}", ",", "process", ".", "exit", ")", ";", "}" ]
Respond to the SHUTDOWN command.
[ "Respond", "to", "the", "SHUTDOWN", "command", "." ]
49413052d3039524fbdd2ade0ef9bae26cb4d647
https://github.com/redisjs/jsr-server/blob/49413052d3039524fbdd2ade0ef9bae26cb4d647/lib/command/server/shutdown.js#L19-L25
51,909
redisjs/jsr-server
lib/command/server/shutdown.js
validate
function validate(cmd, args, info) { AbstractCommand.prototype.validate.apply(this, arguments); if(args[0]) { var arg = ('' + args[0]).toLowerCase(); if(arg !== Constants.SHUTDOWN.SAVE && arg !== Constants.SHUTDOWN.NOSAVE) { throw CommandSyntax; } // rewrite with boolean args[0] = (arg === Constants.SHUTDOWN.SAVE); } }
javascript
function validate(cmd, args, info) { AbstractCommand.prototype.validate.apply(this, arguments); if(args[0]) { var arg = ('' + args[0]).toLowerCase(); if(arg !== Constants.SHUTDOWN.SAVE && arg !== Constants.SHUTDOWN.NOSAVE) { throw CommandSyntax; } // rewrite with boolean args[0] = (arg === Constants.SHUTDOWN.SAVE); } }
[ "function", "validate", "(", "cmd", ",", "args", ",", "info", ")", "{", "AbstractCommand", ".", "prototype", ".", "validate", ".", "apply", "(", "this", ",", "arguments", ")", ";", "if", "(", "args", "[", "0", "]", ")", "{", "var", "arg", "=", "(", "''", "+", "args", "[", "0", "]", ")", ".", "toLowerCase", "(", ")", ";", "if", "(", "arg", "!==", "Constants", ".", "SHUTDOWN", ".", "SAVE", "&&", "arg", "!==", "Constants", ".", "SHUTDOWN", ".", "NOSAVE", ")", "{", "throw", "CommandSyntax", ";", "}", "// rewrite with boolean", "args", "[", "0", "]", "=", "(", "arg", "===", "Constants", ".", "SHUTDOWN", ".", "SAVE", ")", ";", "}", "}" ]
Validate the SHUTDOWN command.
[ "Validate", "the", "SHUTDOWN", "command", "." ]
49413052d3039524fbdd2ade0ef9bae26cb4d647
https://github.com/redisjs/jsr-server/blob/49413052d3039524fbdd2ade0ef9bae26cb4d647/lib/command/server/shutdown.js#L30-L41
51,910
Xrew/bobril-chartjs
docs/a.js
function() { var me = this; var barCount = 0; helpers.each(me.chart.data.datasets, function(dataset, datasetIndex) { var meta = me.chart.getDatasetMeta(datasetIndex); if (meta.bar && me.chart.isDatasetVisible(datasetIndex)) { ++barCount; } }, me); return barCount; }
javascript
function() { var me = this; var barCount = 0; helpers.each(me.chart.data.datasets, function(dataset, datasetIndex) { var meta = me.chart.getDatasetMeta(datasetIndex); if (meta.bar && me.chart.isDatasetVisible(datasetIndex)) { ++barCount; } }, me); return barCount; }
[ "function", "(", ")", "{", "var", "me", "=", "this", ";", "var", "barCount", "=", "0", ";", "helpers", ".", "each", "(", "me", ".", "chart", ".", "data", ".", "datasets", ",", "function", "(", "dataset", ",", "datasetIndex", ")", "{", "var", "meta", "=", "me", ".", "chart", ".", "getDatasetMeta", "(", "datasetIndex", ")", ";", "if", "(", "meta", ".", "bar", "&&", "me", ".", "chart", ".", "isDatasetVisible", "(", "datasetIndex", ")", ")", "{", "++", "barCount", ";", "}", "}", ",", "me", ")", ";", "return", "barCount", ";", "}" ]
Get the number of datasets that display bars. We use this to correctly calculate the bar width
[ "Get", "the", "number", "of", "datasets", "that", "display", "bars", ".", "We", "use", "this", "to", "correctly", "calculate", "the", "bar", "width" ]
8362f4ba54fb216343d30cc6a3ef35e98fa9cb44
https://github.com/Xrew/bobril-chartjs/blob/8362f4ba54fb216343d30cc6a3ef35e98fa9cb44/docs/a.js#L6184-L6194
51,911
Xrew/bobril-chartjs
docs/a.js
function(datasetIndex) { var barIndex = 0; var meta, j; for (j = 0; j < datasetIndex; ++j) { meta = this.chart.getDatasetMeta(j); if (meta.bar && this.chart.isDatasetVisible(j)) { ++barIndex; } } return barIndex; }
javascript
function(datasetIndex) { var barIndex = 0; var meta, j; for (j = 0; j < datasetIndex; ++j) { meta = this.chart.getDatasetMeta(j); if (meta.bar && this.chart.isDatasetVisible(j)) { ++barIndex; } } return barIndex; }
[ "function", "(", "datasetIndex", ")", "{", "var", "barIndex", "=", "0", ";", "var", "meta", ",", "j", ";", "for", "(", "j", "=", "0", ";", "j", "<", "datasetIndex", ";", "++", "j", ")", "{", "meta", "=", "this", ".", "chart", ".", "getDatasetMeta", "(", "j", ")", ";", "if", "(", "meta", ".", "bar", "&&", "this", ".", "chart", ".", "isDatasetVisible", "(", "j", ")", ")", "{", "++", "barIndex", ";", "}", "}", "return", "barIndex", ";", "}" ]
Get bar index from the given dataset index accounting for the fact that not all bars are visible
[ "Get", "bar", "index", "from", "the", "given", "dataset", "index", "accounting", "for", "the", "fact", "that", "not", "all", "bars", "are", "visible" ]
8362f4ba54fb216343d30cc6a3ef35e98fa9cb44
https://github.com/Xrew/bobril-chartjs/blob/8362f4ba54fb216343d30cc6a3ef35e98fa9cb44/docs/a.js#L6311-L6323
51,912
Xrew/bobril-chartjs
docs/a.js
function() { var me = this; var options = me.options; var scales = me.scales = {}; var items = []; if (options.scales) { items = items.concat( (options.scales.xAxes || []).map(function(xAxisOptions) { return {options: xAxisOptions, dtype: 'category'}; }), (options.scales.yAxes || []).map(function(yAxisOptions) { return {options: yAxisOptions, dtype: 'linear'}; }) ); } if (options.scale) { items.push({options: options.scale, dtype: 'radialLinear', isDefault: true}); } helpers.each(items, function(item) { var scaleOptions = item.options; var scaleType = helpers.getValueOrDefault(scaleOptions.type, item.dtype); var scaleClass = Chart.scaleService.getScaleConstructor(scaleType); if (!scaleClass) { return; } var scale = new scaleClass({ id: scaleOptions.id, options: scaleOptions, ctx: me.chart.ctx, chart: me }); scales[scale.id] = scale; // TODO(SB): I think we should be able to remove this custom case (options.scale) // and consider it as a regular scale part of the "scales"" map only! This would // make the logic easier and remove some useless? custom code. if (item.isDefault) { me.scale = scale; } }); Chart.scaleService.addScalesToLayout(this); }
javascript
function() { var me = this; var options = me.options; var scales = me.scales = {}; var items = []; if (options.scales) { items = items.concat( (options.scales.xAxes || []).map(function(xAxisOptions) { return {options: xAxisOptions, dtype: 'category'}; }), (options.scales.yAxes || []).map(function(yAxisOptions) { return {options: yAxisOptions, dtype: 'linear'}; }) ); } if (options.scale) { items.push({options: options.scale, dtype: 'radialLinear', isDefault: true}); } helpers.each(items, function(item) { var scaleOptions = item.options; var scaleType = helpers.getValueOrDefault(scaleOptions.type, item.dtype); var scaleClass = Chart.scaleService.getScaleConstructor(scaleType); if (!scaleClass) { return; } var scale = new scaleClass({ id: scaleOptions.id, options: scaleOptions, ctx: me.chart.ctx, chart: me }); scales[scale.id] = scale; // TODO(SB): I think we should be able to remove this custom case (options.scale) // and consider it as a regular scale part of the "scales"" map only! This would // make the logic easier and remove some useless? custom code. if (item.isDefault) { me.scale = scale; } }); Chart.scaleService.addScalesToLayout(this); }
[ "function", "(", ")", "{", "var", "me", "=", "this", ";", "var", "options", "=", "me", ".", "options", ";", "var", "scales", "=", "me", ".", "scales", "=", "{", "}", ";", "var", "items", "=", "[", "]", ";", "if", "(", "options", ".", "scales", ")", "{", "items", "=", "items", ".", "concat", "(", "(", "options", ".", "scales", ".", "xAxes", "||", "[", "]", ")", ".", "map", "(", "function", "(", "xAxisOptions", ")", "{", "return", "{", "options", ":", "xAxisOptions", ",", "dtype", ":", "'category'", "}", ";", "}", ")", ",", "(", "options", ".", "scales", ".", "yAxes", "||", "[", "]", ")", ".", "map", "(", "function", "(", "yAxisOptions", ")", "{", "return", "{", "options", ":", "yAxisOptions", ",", "dtype", ":", "'linear'", "}", ";", "}", ")", ")", ";", "}", "if", "(", "options", ".", "scale", ")", "{", "items", ".", "push", "(", "{", "options", ":", "options", ".", "scale", ",", "dtype", ":", "'radialLinear'", ",", "isDefault", ":", "true", "}", ")", ";", "}", "helpers", ".", "each", "(", "items", ",", "function", "(", "item", ")", "{", "var", "scaleOptions", "=", "item", ".", "options", ";", "var", "scaleType", "=", "helpers", ".", "getValueOrDefault", "(", "scaleOptions", ".", "type", ",", "item", ".", "dtype", ")", ";", "var", "scaleClass", "=", "Chart", ".", "scaleService", ".", "getScaleConstructor", "(", "scaleType", ")", ";", "if", "(", "!", "scaleClass", ")", "{", "return", ";", "}", "var", "scale", "=", "new", "scaleClass", "(", "{", "id", ":", "scaleOptions", ".", "id", ",", "options", ":", "scaleOptions", ",", "ctx", ":", "me", ".", "chart", ".", "ctx", ",", "chart", ":", "me", "}", ")", ";", "scales", "[", "scale", ".", "id", "]", "=", "scale", ";", "// TODO(SB): I think we should be able to remove this custom case (options.scale)", "// and consider it as a regular scale part of the \"scales\"\" map only! This would", "// make the logic easier and remove some useless? custom code.", "if", "(", "item", ".", "isDefault", ")", "{", "me", ".", "scale", "=", "scale", ";", "}", "}", ")", ";", "Chart", ".", "scaleService", ".", "addScalesToLayout", "(", "this", ")", ";", "}" ]
Builds a map of scale ID to scale object for future lookup.
[ "Builds", "a", "map", "of", "scale", "ID", "to", "scale", "object", "for", "future", "lookup", "." ]
8362f4ba54fb216343d30cc6a3ef35e98fa9cb44
https://github.com/Xrew/bobril-chartjs/blob/8362f4ba54fb216343d30cc6a3ef35e98fa9cb44/docs/a.js#L8439-L8486
51,913
Xrew/bobril-chartjs
docs/a.js
function() { if (!stub.ticking) { stub.ticking = true; helpers.requestAnimFrame.call(window, function() { if (stub.resizer) { stub.ticking = false; return callback(); } }); } }
javascript
function() { if (!stub.ticking) { stub.ticking = true; helpers.requestAnimFrame.call(window, function() { if (stub.resizer) { stub.ticking = false; return callback(); } }); } }
[ "function", "(", ")", "{", "if", "(", "!", "stub", ".", "ticking", ")", "{", "stub", ".", "ticking", "=", "true", ";", "helpers", ".", "requestAnimFrame", ".", "call", "(", "window", ",", "function", "(", ")", "{", "if", "(", "stub", ".", "resizer", ")", "{", "stub", ".", "ticking", "=", "false", ";", "return", "callback", "(", ")", ";", "}", "}", ")", ";", "}", "}" ]
Throttle the callback notification until the next animation frame.
[ "Throttle", "the", "callback", "notification", "until", "the", "next", "animation", "frame", "." ]
8362f4ba54fb216343d30cc6a3ef35e98fa9cb44
https://github.com/Xrew/bobril-chartjs/blob/8362f4ba54fb216343d30cc6a3ef35e98fa9cb44/docs/a.js#L10298-L10308
51,914
Xrew/bobril-chartjs
docs/a.js
function(chart, e) { var position = helpers.getRelativePosition(e, chart.chart); return getIntersectItems(chart, position); }
javascript
function(chart, e) { var position = helpers.getRelativePosition(e, chart.chart); return getIntersectItems(chart, position); }
[ "function", "(", "chart", ",", "e", ")", "{", "var", "position", "=", "helpers", ".", "getRelativePosition", "(", "e", ",", "chart", ".", "chart", ")", ";", "return", "getIntersectItems", "(", "chart", ",", "position", ")", ";", "}" ]
Point mode returns all elements that hit test based on the event position of the event @function Chart.Interaction.modes.intersect @param chart {chart} the chart we are returning items from @param e {Event} the event we are find things at @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
[ "Point", "mode", "returns", "all", "elements", "that", "hit", "test", "based", "on", "the", "event", "position", "of", "the", "event" ]
8362f4ba54fb216343d30cc6a3ef35e98fa9cb44
https://github.com/Xrew/bobril-chartjs/blob/8362f4ba54fb216343d30cc6a3ef35e98fa9cb44/docs/a.js#L10575-L10578
51,915
Xrew/bobril-chartjs
docs/a.js
function(chartInstance, box) { if (!chartInstance.boxes) { chartInstance.boxes = []; } chartInstance.boxes.push(box); }
javascript
function(chartInstance, box) { if (!chartInstance.boxes) { chartInstance.boxes = []; } chartInstance.boxes.push(box); }
[ "function", "(", "chartInstance", ",", "box", ")", "{", "if", "(", "!", "chartInstance", ".", "boxes", ")", "{", "chartInstance", ".", "boxes", "=", "[", "]", ";", "}", "chartInstance", ".", "boxes", ".", "push", "(", "box", ")", ";", "}" ]
Register a box to a chartInstance. A box is simply a reference to an object that requires layout. eg. Scales, Legend, Plugins.
[ "Register", "a", "box", "to", "a", "chartInstance", ".", "A", "box", "is", "simply", "a", "reference", "to", "an", "object", "that", "requires", "layout", ".", "eg", ".", "Scales", "Legend", "Plugins", "." ]
8362f4ba54fb216343d30cc6a3ef35e98fa9cb44
https://github.com/Xrew/bobril-chartjs/blob/8362f4ba54fb216343d30cc6a3ef35e98fa9cb44/docs/a.js#L10749-L10754
51,916
Xrew/bobril-chartjs
docs/a.js
function(extension, args) { var plugins = this._plugins; var ilen = plugins.length; var i, plugin; for (i=0; i<ilen; ++i) { plugin = plugins[i]; if (typeof plugin[extension] === 'function') { if (plugin[extension].apply(plugin, args || []) === false) { return false; } } } return true; }
javascript
function(extension, args) { var plugins = this._plugins; var ilen = plugins.length; var i, plugin; for (i=0; i<ilen; ++i) { plugin = plugins[i]; if (typeof plugin[extension] === 'function') { if (plugin[extension].apply(plugin, args || []) === false) { return false; } } } return true; }
[ "function", "(", "extension", ",", "args", ")", "{", "var", "plugins", "=", "this", ".", "_plugins", ";", "var", "ilen", "=", "plugins", ".", "length", ";", "var", "i", ",", "plugin", ";", "for", "(", "i", "=", "0", ";", "i", "<", "ilen", ";", "++", "i", ")", "{", "plugin", "=", "plugins", "[", "i", "]", ";", "if", "(", "typeof", "plugin", "[", "extension", "]", "===", "'function'", ")", "{", "if", "(", "plugin", "[", "extension", "]", ".", "apply", "(", "plugin", ",", "args", "||", "[", "]", ")", "===", "false", ")", "{", "return", "false", ";", "}", "}", "}", "return", "true", ";", "}" ]
Calls registered plugins on the specified extension, with the given args. This method immediately returns as soon as a plugin explicitly returns false. The returned value can be used, for instance, to interrupt the current action. @param {String} extension the name of the plugin method to call (e.g. 'beforeUpdate'). @param {Array} [args] extra arguments to apply to the extension call. @returns {Boolean} false if any of the plugins return false, else returns true.
[ "Calls", "registered", "plugins", "on", "the", "specified", "extension", "with", "the", "given", "args", ".", "This", "method", "immediately", "returns", "as", "soon", "as", "a", "plugin", "explicitly", "returns", "false", ".", "The", "returned", "value", "can", "be", "used", "for", "instance", "to", "interrupt", "the", "current", "action", "." ]
8362f4ba54fb216343d30cc6a3ef35e98fa9cb44
https://github.com/Xrew/bobril-chartjs/blob/8362f4ba54fb216343d30cc6a3ef35e98fa9cb44/docs/a.js#L11653-L11668
51,917
Xrew/bobril-chartjs
docs/a.js
function(rawValue) { // Null and undefined values first if (rawValue === null || typeof(rawValue) === 'undefined') { return NaN; } // isNaN(object) returns true, so make sure NaN is checking for a number; Discard Infinite values if (typeof(rawValue) === 'number' && !isFinite(rawValue)) { return NaN; } // If it is in fact an object, dive in one more level if (typeof(rawValue) === 'object') { if ((rawValue instanceof Date) || (rawValue.isValid)) { return rawValue; } return this.getRightValue(this.isHorizontal() ? rawValue.x : rawValue.y); } // Value is good, return it return rawValue; }
javascript
function(rawValue) { // Null and undefined values first if (rawValue === null || typeof(rawValue) === 'undefined') { return NaN; } // isNaN(object) returns true, so make sure NaN is checking for a number; Discard Infinite values if (typeof(rawValue) === 'number' && !isFinite(rawValue)) { return NaN; } // If it is in fact an object, dive in one more level if (typeof(rawValue) === 'object') { if ((rawValue instanceof Date) || (rawValue.isValid)) { return rawValue; } return this.getRightValue(this.isHorizontal() ? rawValue.x : rawValue.y); } // Value is good, return it return rawValue; }
[ "function", "(", "rawValue", ")", "{", "// Null and undefined values first", "if", "(", "rawValue", "===", "null", "||", "typeof", "(", "rawValue", ")", "===", "'undefined'", ")", "{", "return", "NaN", ";", "}", "// isNaN(object) returns true, so make sure NaN is checking for a number; Discard Infinite values", "if", "(", "typeof", "(", "rawValue", ")", "===", "'number'", "&&", "!", "isFinite", "(", "rawValue", ")", ")", "{", "return", "NaN", ";", "}", "// If it is in fact an object, dive in one more level", "if", "(", "typeof", "(", "rawValue", ")", "===", "'object'", ")", "{", "if", "(", "(", "rawValue", "instanceof", "Date", ")", "||", "(", "rawValue", ".", "isValid", ")", ")", "{", "return", "rawValue", ";", "}", "return", "this", ".", "getRightValue", "(", "this", ".", "isHorizontal", "(", ")", "?", "rawValue", ".", "x", ":", "rawValue", ".", "y", ")", ";", "}", "// Value is good, return it", "return", "rawValue", ";", "}" ]
Get the correct value. NaN bad inputs, If the value type is object get the x or y based on whether we are horizontal or not
[ "Get", "the", "correct", "value", ".", "NaN", "bad", "inputs", "If", "the", "value", "type", "is", "object", "get", "the", "x", "or", "y", "based", "on", "whether", "we", "are", "horizontal", "or", "not" ]
8362f4ba54fb216343d30cc6a3ef35e98fa9cb44
https://github.com/Xrew/bobril-chartjs/blob/8362f4ba54fb216343d30cc6a3ef35e98fa9cb44/docs/a.js#L12097-L12116
51,918
Xrew/bobril-chartjs
docs/a.js
function(index, includeOffset) { var me = this; if (me.isHorizontal()) { var innerWidth = me.width - (me.paddingLeft + me.paddingRight); var tickWidth = innerWidth / Math.max((me.ticks.length - ((me.options.gridLines.offsetGridLines) ? 0 : 1)), 1); var pixel = (tickWidth * index) + me.paddingLeft; if (includeOffset) { pixel += tickWidth / 2; } var finalVal = me.left + Math.round(pixel); finalVal += me.isFullWidth() ? me.margins.left : 0; return finalVal; } var innerHeight = me.height - (me.paddingTop + me.paddingBottom); return me.top + (index * (innerHeight / (me.ticks.length - 1))); }
javascript
function(index, includeOffset) { var me = this; if (me.isHorizontal()) { var innerWidth = me.width - (me.paddingLeft + me.paddingRight); var tickWidth = innerWidth / Math.max((me.ticks.length - ((me.options.gridLines.offsetGridLines) ? 0 : 1)), 1); var pixel = (tickWidth * index) + me.paddingLeft; if (includeOffset) { pixel += tickWidth / 2; } var finalVal = me.left + Math.round(pixel); finalVal += me.isFullWidth() ? me.margins.left : 0; return finalVal; } var innerHeight = me.height - (me.paddingTop + me.paddingBottom); return me.top + (index * (innerHeight / (me.ticks.length - 1))); }
[ "function", "(", "index", ",", "includeOffset", ")", "{", "var", "me", "=", "this", ";", "if", "(", "me", ".", "isHorizontal", "(", ")", ")", "{", "var", "innerWidth", "=", "me", ".", "width", "-", "(", "me", ".", "paddingLeft", "+", "me", ".", "paddingRight", ")", ";", "var", "tickWidth", "=", "innerWidth", "/", "Math", ".", "max", "(", "(", "me", ".", "ticks", ".", "length", "-", "(", "(", "me", ".", "options", ".", "gridLines", ".", "offsetGridLines", ")", "?", "0", ":", "1", ")", ")", ",", "1", ")", ";", "var", "pixel", "=", "(", "tickWidth", "*", "index", ")", "+", "me", ".", "paddingLeft", ";", "if", "(", "includeOffset", ")", "{", "pixel", "+=", "tickWidth", "/", "2", ";", "}", "var", "finalVal", "=", "me", ".", "left", "+", "Math", ".", "round", "(", "pixel", ")", ";", "finalVal", "+=", "me", ".", "isFullWidth", "(", ")", "?", "me", ".", "margins", ".", "left", ":", "0", ";", "return", "finalVal", ";", "}", "var", "innerHeight", "=", "me", ".", "height", "-", "(", "me", ".", "paddingTop", "+", "me", ".", "paddingBottom", ")", ";", "return", "me", ".", "top", "+", "(", "index", "*", "(", "innerHeight", "/", "(", "me", ".", "ticks", ".", "length", "-", "1", ")", ")", ")", ";", "}" ]
Used for tick location, should
[ "Used", "for", "tick", "location", "should" ]
8362f4ba54fb216343d30cc6a3ef35e98fa9cb44
https://github.com/Xrew/bobril-chartjs/blob/8362f4ba54fb216343d30cc6a3ef35e98fa9cb44/docs/a.js#L12129-L12146
51,919
Xrew/bobril-chartjs
docs/a.js
function(decimal /* , includeOffset*/) { var me = this; if (me.isHorizontal()) { var innerWidth = me.width - (me.paddingLeft + me.paddingRight); var valueOffset = (innerWidth * decimal) + me.paddingLeft; var finalVal = me.left + Math.round(valueOffset); finalVal += me.isFullWidth() ? me.margins.left : 0; return finalVal; } return me.top + (decimal * me.height); }
javascript
function(decimal /* , includeOffset*/) { var me = this; if (me.isHorizontal()) { var innerWidth = me.width - (me.paddingLeft + me.paddingRight); var valueOffset = (innerWidth * decimal) + me.paddingLeft; var finalVal = me.left + Math.round(valueOffset); finalVal += me.isFullWidth() ? me.margins.left : 0; return finalVal; } return me.top + (decimal * me.height); }
[ "function", "(", "decimal", "/* , includeOffset*/", ")", "{", "var", "me", "=", "this", ";", "if", "(", "me", ".", "isHorizontal", "(", ")", ")", "{", "var", "innerWidth", "=", "me", ".", "width", "-", "(", "me", ".", "paddingLeft", "+", "me", ".", "paddingRight", ")", ";", "var", "valueOffset", "=", "(", "innerWidth", "*", "decimal", ")", "+", "me", ".", "paddingLeft", ";", "var", "finalVal", "=", "me", ".", "left", "+", "Math", ".", "round", "(", "valueOffset", ")", ";", "finalVal", "+=", "me", ".", "isFullWidth", "(", ")", "?", "me", ".", "margins", ".", "left", ":", "0", ";", "return", "finalVal", ";", "}", "return", "me", ".", "top", "+", "(", "decimal", "*", "me", ".", "height", ")", ";", "}" ]
Utility for getting the pixel location of a percentage of scale
[ "Utility", "for", "getting", "the", "pixel", "location", "of", "a", "percentage", "of", "scale" ]
8362f4ba54fb216343d30cc6a3ef35e98fa9cb44
https://github.com/Xrew/bobril-chartjs/blob/8362f4ba54fb216343d30cc6a3ef35e98fa9cb44/docs/a.js#L12149-L12160
51,920
Xrew/bobril-chartjs
docs/a.js
function(generationOptions, dataRange) { var ticks = []; // To get a "nice" value for the tick spacing, we will use the appropriately named // "nice number" algorithm. See http://stackoverflow.com/questions/8506881/nice-label-algorithm-for-charts-with-minimum-ticks // for details. var spacing; if (generationOptions.stepSize && generationOptions.stepSize > 0) { spacing = generationOptions.stepSize; } else { var niceRange = helpers.niceNum(dataRange.max - dataRange.min, false); spacing = helpers.niceNum(niceRange / (generationOptions.maxTicks - 1), true); } var niceMin = Math.floor(dataRange.min / spacing) * spacing; var niceMax = Math.ceil(dataRange.max / spacing) * spacing; // If min, max and stepSize is set and they make an evenly spaced scale use it. if (generationOptions.min && generationOptions.max && generationOptions.stepSize) { var minMaxDeltaDivisibleByStepSize = ((generationOptions.max - generationOptions.min) % generationOptions.stepSize) === 0; if (minMaxDeltaDivisibleByStepSize) { niceMin = generationOptions.min; niceMax = generationOptions.max; } } var numSpaces = (niceMax - niceMin) / spacing; // If very close to our rounded value, use it. if (helpers.almostEquals(numSpaces, Math.round(numSpaces), spacing / 1000)) { numSpaces = Math.round(numSpaces); } else { numSpaces = Math.ceil(numSpaces); } // Put the values into the ticks array ticks.push(generationOptions.min !== undefined ? generationOptions.min : niceMin); for (var j = 1; j < numSpaces; ++j) { ticks.push(niceMin + (j * spacing)); } ticks.push(generationOptions.max !== undefined ? generationOptions.max : niceMax); return ticks; }
javascript
function(generationOptions, dataRange) { var ticks = []; // To get a "nice" value for the tick spacing, we will use the appropriately named // "nice number" algorithm. See http://stackoverflow.com/questions/8506881/nice-label-algorithm-for-charts-with-minimum-ticks // for details. var spacing; if (generationOptions.stepSize && generationOptions.stepSize > 0) { spacing = generationOptions.stepSize; } else { var niceRange = helpers.niceNum(dataRange.max - dataRange.min, false); spacing = helpers.niceNum(niceRange / (generationOptions.maxTicks - 1), true); } var niceMin = Math.floor(dataRange.min / spacing) * spacing; var niceMax = Math.ceil(dataRange.max / spacing) * spacing; // If min, max and stepSize is set and they make an evenly spaced scale use it. if (generationOptions.min && generationOptions.max && generationOptions.stepSize) { var minMaxDeltaDivisibleByStepSize = ((generationOptions.max - generationOptions.min) % generationOptions.stepSize) === 0; if (minMaxDeltaDivisibleByStepSize) { niceMin = generationOptions.min; niceMax = generationOptions.max; } } var numSpaces = (niceMax - niceMin) / spacing; // If very close to our rounded value, use it. if (helpers.almostEquals(numSpaces, Math.round(numSpaces), spacing / 1000)) { numSpaces = Math.round(numSpaces); } else { numSpaces = Math.ceil(numSpaces); } // Put the values into the ticks array ticks.push(generationOptions.min !== undefined ? generationOptions.min : niceMin); for (var j = 1; j < numSpaces; ++j) { ticks.push(niceMin + (j * spacing)); } ticks.push(generationOptions.max !== undefined ? generationOptions.max : niceMax); return ticks; }
[ "function", "(", "generationOptions", ",", "dataRange", ")", "{", "var", "ticks", "=", "[", "]", ";", "// To get a \"nice\" value for the tick spacing, we will use the appropriately named", "// \"nice number\" algorithm. See http://stackoverflow.com/questions/8506881/nice-label-algorithm-for-charts-with-minimum-ticks", "// for details.", "var", "spacing", ";", "if", "(", "generationOptions", ".", "stepSize", "&&", "generationOptions", ".", "stepSize", ">", "0", ")", "{", "spacing", "=", "generationOptions", ".", "stepSize", ";", "}", "else", "{", "var", "niceRange", "=", "helpers", ".", "niceNum", "(", "dataRange", ".", "max", "-", "dataRange", ".", "min", ",", "false", ")", ";", "spacing", "=", "helpers", ".", "niceNum", "(", "niceRange", "/", "(", "generationOptions", ".", "maxTicks", "-", "1", ")", ",", "true", ")", ";", "}", "var", "niceMin", "=", "Math", ".", "floor", "(", "dataRange", ".", "min", "/", "spacing", ")", "*", "spacing", ";", "var", "niceMax", "=", "Math", ".", "ceil", "(", "dataRange", ".", "max", "/", "spacing", ")", "*", "spacing", ";", "// If min, max and stepSize is set and they make an evenly spaced scale use it.", "if", "(", "generationOptions", ".", "min", "&&", "generationOptions", ".", "max", "&&", "generationOptions", ".", "stepSize", ")", "{", "var", "minMaxDeltaDivisibleByStepSize", "=", "(", "(", "generationOptions", ".", "max", "-", "generationOptions", ".", "min", ")", "%", "generationOptions", ".", "stepSize", ")", "===", "0", ";", "if", "(", "minMaxDeltaDivisibleByStepSize", ")", "{", "niceMin", "=", "generationOptions", ".", "min", ";", "niceMax", "=", "generationOptions", ".", "max", ";", "}", "}", "var", "numSpaces", "=", "(", "niceMax", "-", "niceMin", ")", "/", "spacing", ";", "// If very close to our rounded value, use it.", "if", "(", "helpers", ".", "almostEquals", "(", "numSpaces", ",", "Math", ".", "round", "(", "numSpaces", ")", ",", "spacing", "/", "1000", ")", ")", "{", "numSpaces", "=", "Math", ".", "round", "(", "numSpaces", ")", ";", "}", "else", "{", "numSpaces", "=", "Math", ".", "ceil", "(", "numSpaces", ")", ";", "}", "// Put the values into the ticks array", "ticks", ".", "push", "(", "generationOptions", ".", "min", "!==", "undefined", "?", "generationOptions", ".", "min", ":", "niceMin", ")", ";", "for", "(", "var", "j", "=", "1", ";", "j", "<", "numSpaces", ";", "++", "j", ")", "{", "ticks", ".", "push", "(", "niceMin", "+", "(", "j", "*", "spacing", ")", ")", ";", "}", "ticks", ".", "push", "(", "generationOptions", ".", "max", "!==", "undefined", "?", "generationOptions", ".", "max", ":", "niceMax", ")", ";", "return", "ticks", ";", "}" ]
Interface for the options provided to the numeric tick generator @interface INumericTickGenerationOptions The maximum number of ticks to display @name INumericTickGenerationOptions#maxTicks @type Number The distance between each tick. @name INumericTickGenerationOptions#stepSize @type Number @optional Forced minimum for the ticks. If not specified, the minimum of the data range is used to calculate the tick minimum @name INumericTickGenerationOptions#min @type Number @optional The maximum value of the ticks. If not specified, the maximum of the data range is used to calculate the tick maximum @name INumericTickGenerationOptions#max @type Number @optional Generate a set of linear ticks @method Chart.Ticks.generators.linear @param generationOptions {INumericTickGenerationOptions} the options used to generate the ticks @param dataRange {IRange} the range of the data @returns {Array<Number>} array of tick values
[ "Interface", "for", "the", "options", "provided", "to", "the", "numeric", "tick", "generator" ]
8362f4ba54fb216343d30cc6a3ef35e98fa9cb44
https://github.com/Xrew/bobril-chartjs/blob/8362f4ba54fb216343d30cc6a3ef35e98fa9cb44/docs/a.js#L12555-L12596
51,921
Xrew/bobril-chartjs
docs/a.js
function() { var chartOpts = this.chart.options; if (chartOpts && chartOpts.title) { this.options = helpers.configMerge(Chart.defaults.global.title, chartOpts.title); } }
javascript
function() { var chartOpts = this.chart.options; if (chartOpts && chartOpts.title) { this.options = helpers.configMerge(Chart.defaults.global.title, chartOpts.title); } }
[ "function", "(", ")", "{", "var", "chartOpts", "=", "this", ".", "chart", ".", "options", ";", "if", "(", "chartOpts", "&&", "chartOpts", ".", "title", ")", "{", "this", ".", "options", "=", "helpers", ".", "configMerge", "(", "Chart", ".", "defaults", ".", "global", ".", "title", ",", "chartOpts", ".", "title", ")", ";", "}", "}" ]
These methods are ordered by lifecycle. Utilities then follow.
[ "These", "methods", "are", "ordered", "by", "lifecycle", ".", "Utilities", "then", "follow", "." ]
8362f4ba54fb216343d30cc6a3ef35e98fa9cb44
https://github.com/Xrew/bobril-chartjs/blob/8362f4ba54fb216343d30cc6a3ef35e98fa9cb44/docs/a.js#L12740-L12745
51,922
Xrew/bobril-chartjs
docs/a.js
getBaseModel
function getBaseModel(tooltipOpts) { var globalDefaults = Chart.defaults.global; var getValueOrDefault = helpers.getValueOrDefault; return { // Positioning xPadding: tooltipOpts.xPadding, yPadding: tooltipOpts.yPadding, xAlign: tooltipOpts.xAlign, yAlign: tooltipOpts.yAlign, // Body bodyFontColor: tooltipOpts.bodyFontColor, _bodyFontFamily: getValueOrDefault(tooltipOpts.bodyFontFamily, globalDefaults.defaultFontFamily), _bodyFontStyle: getValueOrDefault(tooltipOpts.bodyFontStyle, globalDefaults.defaultFontStyle), _bodyAlign: tooltipOpts.bodyAlign, bodyFontSize: getValueOrDefault(tooltipOpts.bodyFontSize, globalDefaults.defaultFontSize), bodySpacing: tooltipOpts.bodySpacing, // Title titleFontColor: tooltipOpts.titleFontColor, _titleFontFamily: getValueOrDefault(tooltipOpts.titleFontFamily, globalDefaults.defaultFontFamily), _titleFontStyle: getValueOrDefault(tooltipOpts.titleFontStyle, globalDefaults.defaultFontStyle), titleFontSize: getValueOrDefault(tooltipOpts.titleFontSize, globalDefaults.defaultFontSize), _titleAlign: tooltipOpts.titleAlign, titleSpacing: tooltipOpts.titleSpacing, titleMarginBottom: tooltipOpts.titleMarginBottom, // Footer footerFontColor: tooltipOpts.footerFontColor, _footerFontFamily: getValueOrDefault(tooltipOpts.footerFontFamily, globalDefaults.defaultFontFamily), _footerFontStyle: getValueOrDefault(tooltipOpts.footerFontStyle, globalDefaults.defaultFontStyle), footerFontSize: getValueOrDefault(tooltipOpts.footerFontSize, globalDefaults.defaultFontSize), _footerAlign: tooltipOpts.footerAlign, footerSpacing: tooltipOpts.footerSpacing, footerMarginTop: tooltipOpts.footerMarginTop, // Appearance caretSize: tooltipOpts.caretSize, cornerRadius: tooltipOpts.cornerRadius, backgroundColor: tooltipOpts.backgroundColor, opacity: 0, legendColorBackground: tooltipOpts.multiKeyBackground, displayColors: tooltipOpts.displayColors }; }
javascript
function getBaseModel(tooltipOpts) { var globalDefaults = Chart.defaults.global; var getValueOrDefault = helpers.getValueOrDefault; return { // Positioning xPadding: tooltipOpts.xPadding, yPadding: tooltipOpts.yPadding, xAlign: tooltipOpts.xAlign, yAlign: tooltipOpts.yAlign, // Body bodyFontColor: tooltipOpts.bodyFontColor, _bodyFontFamily: getValueOrDefault(tooltipOpts.bodyFontFamily, globalDefaults.defaultFontFamily), _bodyFontStyle: getValueOrDefault(tooltipOpts.bodyFontStyle, globalDefaults.defaultFontStyle), _bodyAlign: tooltipOpts.bodyAlign, bodyFontSize: getValueOrDefault(tooltipOpts.bodyFontSize, globalDefaults.defaultFontSize), bodySpacing: tooltipOpts.bodySpacing, // Title titleFontColor: tooltipOpts.titleFontColor, _titleFontFamily: getValueOrDefault(tooltipOpts.titleFontFamily, globalDefaults.defaultFontFamily), _titleFontStyle: getValueOrDefault(tooltipOpts.titleFontStyle, globalDefaults.defaultFontStyle), titleFontSize: getValueOrDefault(tooltipOpts.titleFontSize, globalDefaults.defaultFontSize), _titleAlign: tooltipOpts.titleAlign, titleSpacing: tooltipOpts.titleSpacing, titleMarginBottom: tooltipOpts.titleMarginBottom, // Footer footerFontColor: tooltipOpts.footerFontColor, _footerFontFamily: getValueOrDefault(tooltipOpts.footerFontFamily, globalDefaults.defaultFontFamily), _footerFontStyle: getValueOrDefault(tooltipOpts.footerFontStyle, globalDefaults.defaultFontStyle), footerFontSize: getValueOrDefault(tooltipOpts.footerFontSize, globalDefaults.defaultFontSize), _footerAlign: tooltipOpts.footerAlign, footerSpacing: tooltipOpts.footerSpacing, footerMarginTop: tooltipOpts.footerMarginTop, // Appearance caretSize: tooltipOpts.caretSize, cornerRadius: tooltipOpts.cornerRadius, backgroundColor: tooltipOpts.backgroundColor, opacity: 0, legendColorBackground: tooltipOpts.multiKeyBackground, displayColors: tooltipOpts.displayColors }; }
[ "function", "getBaseModel", "(", "tooltipOpts", ")", "{", "var", "globalDefaults", "=", "Chart", ".", "defaults", ".", "global", ";", "var", "getValueOrDefault", "=", "helpers", ".", "getValueOrDefault", ";", "return", "{", "// Positioning", "xPadding", ":", "tooltipOpts", ".", "xPadding", ",", "yPadding", ":", "tooltipOpts", ".", "yPadding", ",", "xAlign", ":", "tooltipOpts", ".", "xAlign", ",", "yAlign", ":", "tooltipOpts", ".", "yAlign", ",", "// Body", "bodyFontColor", ":", "tooltipOpts", ".", "bodyFontColor", ",", "_bodyFontFamily", ":", "getValueOrDefault", "(", "tooltipOpts", ".", "bodyFontFamily", ",", "globalDefaults", ".", "defaultFontFamily", ")", ",", "_bodyFontStyle", ":", "getValueOrDefault", "(", "tooltipOpts", ".", "bodyFontStyle", ",", "globalDefaults", ".", "defaultFontStyle", ")", ",", "_bodyAlign", ":", "tooltipOpts", ".", "bodyAlign", ",", "bodyFontSize", ":", "getValueOrDefault", "(", "tooltipOpts", ".", "bodyFontSize", ",", "globalDefaults", ".", "defaultFontSize", ")", ",", "bodySpacing", ":", "tooltipOpts", ".", "bodySpacing", ",", "// Title", "titleFontColor", ":", "tooltipOpts", ".", "titleFontColor", ",", "_titleFontFamily", ":", "getValueOrDefault", "(", "tooltipOpts", ".", "titleFontFamily", ",", "globalDefaults", ".", "defaultFontFamily", ")", ",", "_titleFontStyle", ":", "getValueOrDefault", "(", "tooltipOpts", ".", "titleFontStyle", ",", "globalDefaults", ".", "defaultFontStyle", ")", ",", "titleFontSize", ":", "getValueOrDefault", "(", "tooltipOpts", ".", "titleFontSize", ",", "globalDefaults", ".", "defaultFontSize", ")", ",", "_titleAlign", ":", "tooltipOpts", ".", "titleAlign", ",", "titleSpacing", ":", "tooltipOpts", ".", "titleSpacing", ",", "titleMarginBottom", ":", "tooltipOpts", ".", "titleMarginBottom", ",", "// Footer", "footerFontColor", ":", "tooltipOpts", ".", "footerFontColor", ",", "_footerFontFamily", ":", "getValueOrDefault", "(", "tooltipOpts", ".", "footerFontFamily", ",", "globalDefaults", ".", "defaultFontFamily", ")", ",", "_footerFontStyle", ":", "getValueOrDefault", "(", "tooltipOpts", ".", "footerFontStyle", ",", "globalDefaults", ".", "defaultFontStyle", ")", ",", "footerFontSize", ":", "getValueOrDefault", "(", "tooltipOpts", ".", "footerFontSize", ",", "globalDefaults", ".", "defaultFontSize", ")", ",", "_footerAlign", ":", "tooltipOpts", ".", "footerAlign", ",", "footerSpacing", ":", "tooltipOpts", ".", "footerSpacing", ",", "footerMarginTop", ":", "tooltipOpts", ".", "footerMarginTop", ",", "// Appearance", "caretSize", ":", "tooltipOpts", ".", "caretSize", ",", "cornerRadius", ":", "tooltipOpts", ".", "cornerRadius", ",", "backgroundColor", ":", "tooltipOpts", ".", "backgroundColor", ",", "opacity", ":", "0", ",", "legendColorBackground", ":", "tooltipOpts", ".", "multiKeyBackground", ",", "displayColors", ":", "tooltipOpts", ".", "displayColors", "}", ";", "}" ]
Helper to get the reset model for the tooltip @param tooltipOpts {Object} the tooltip options
[ "Helper", "to", "get", "the", "reset", "model", "for", "the", "tooltip" ]
8362f4ba54fb216343d30cc6a3ef35e98fa9cb44
https://github.com/Xrew/bobril-chartjs/blob/8362f4ba54fb216343d30cc6a3ef35e98fa9cb44/docs/a.js#L13047-L13092
51,923
Xrew/bobril-chartjs
docs/a.js
function(elements) { if (!elements.length) { return false; } var i, len; var x = 0; var y = 0; var count = 0; for (i = 0, len = elements.length; i < len; ++i) { var el = elements[i]; if (el && el.hasValue()) { var pos = el.tooltipPosition(); x += pos.x; y += pos.y; ++count; } } return { x: Math.round(x / count), y: Math.round(y / count) }; }
javascript
function(elements) { if (!elements.length) { return false; } var i, len; var x = 0; var y = 0; var count = 0; for (i = 0, len = elements.length; i < len; ++i) { var el = elements[i]; if (el && el.hasValue()) { var pos = el.tooltipPosition(); x += pos.x; y += pos.y; ++count; } } return { x: Math.round(x / count), y: Math.round(y / count) }; }
[ "function", "(", "elements", ")", "{", "if", "(", "!", "elements", ".", "length", ")", "{", "return", "false", ";", "}", "var", "i", ",", "len", ";", "var", "x", "=", "0", ";", "var", "y", "=", "0", ";", "var", "count", "=", "0", ";", "for", "(", "i", "=", "0", ",", "len", "=", "elements", ".", "length", ";", "i", "<", "len", ";", "++", "i", ")", "{", "var", "el", "=", "elements", "[", "i", "]", ";", "if", "(", "el", "&&", "el", ".", "hasValue", "(", ")", ")", "{", "var", "pos", "=", "el", ".", "tooltipPosition", "(", ")", ";", "x", "+=", "pos", ".", "x", ";", "y", "+=", "pos", ".", "y", ";", "++", "count", ";", "}", "}", "return", "{", "x", ":", "Math", ".", "round", "(", "x", "/", "count", ")", ",", "y", ":", "Math", ".", "round", "(", "y", "/", "count", ")", "}", ";", "}" ]
Average mode places the tooltip at the average position of the elements shown @function Chart.Tooltip.positioners.average @param elements {ChartElement[]} the elements being displayed in the tooltip @returns {Point} tooltip position
[ "Average", "mode", "places", "the", "tooltip", "at", "the", "average", "position", "of", "the", "elements", "shown" ]
8362f4ba54fb216343d30cc6a3ef35e98fa9cb44
https://github.com/Xrew/bobril-chartjs/blob/8362f4ba54fb216343d30cc6a3ef35e98fa9cb44/docs/a.js#L13728-L13752
51,924
Xrew/bobril-chartjs
docs/a.js
lineToPoint
function lineToPoint(previousPoint, point) { var pointVM = point._view; if (point._view.steppedLine === true) { ctx.lineTo(pointVM.x, previousPoint._view.y); ctx.lineTo(pointVM.x, pointVM.y); } else if (point._view.tension === 0) { ctx.lineTo(pointVM.x, pointVM.y); } else { ctx.bezierCurveTo( previousPoint._view.controlPointNextX, previousPoint._view.controlPointNextY, pointVM.controlPointPreviousX, pointVM.controlPointPreviousY, pointVM.x, pointVM.y ); } }
javascript
function lineToPoint(previousPoint, point) { var pointVM = point._view; if (point._view.steppedLine === true) { ctx.lineTo(pointVM.x, previousPoint._view.y); ctx.lineTo(pointVM.x, pointVM.y); } else if (point._view.tension === 0) { ctx.lineTo(pointVM.x, pointVM.y); } else { ctx.bezierCurveTo( previousPoint._view.controlPointNextX, previousPoint._view.controlPointNextY, pointVM.controlPointPreviousX, pointVM.controlPointPreviousY, pointVM.x, pointVM.y ); } }
[ "function", "lineToPoint", "(", "previousPoint", ",", "point", ")", "{", "var", "pointVM", "=", "point", ".", "_view", ";", "if", "(", "point", ".", "_view", ".", "steppedLine", "===", "true", ")", "{", "ctx", ".", "lineTo", "(", "pointVM", ".", "x", ",", "previousPoint", ".", "_view", ".", "y", ")", ";", "ctx", ".", "lineTo", "(", "pointVM", ".", "x", ",", "pointVM", ".", "y", ")", ";", "}", "else", "if", "(", "point", ".", "_view", ".", "tension", "===", "0", ")", "{", "ctx", ".", "lineTo", "(", "pointVM", ".", "x", ",", "pointVM", ".", "y", ")", ";", "}", "else", "{", "ctx", ".", "bezierCurveTo", "(", "previousPoint", ".", "_view", ".", "controlPointNextX", ",", "previousPoint", ".", "_view", ".", "controlPointNextY", ",", "pointVM", ".", "controlPointPreviousX", ",", "pointVM", ".", "controlPointPreviousY", ",", "pointVM", ".", "x", ",", "pointVM", ".", "y", ")", ";", "}", "}" ]
Helper function to draw a line to a point
[ "Helper", "function", "to", "draw", "a", "line", "to", "a", "point" ]
8362f4ba54fb216343d30cc6a3ef35e98fa9cb44
https://github.com/Xrew/bobril-chartjs/blob/8362f4ba54fb216343d30cc6a3ef35e98fa9cb44/docs/a.js#L13943-L13960
51,925
Xrew/bobril-chartjs
docs/a.js
function() { var me = this; var labels = me.getLabels(); me.minIndex = 0; me.maxIndex = labels.length - 1; var findIndex; if (me.options.ticks.min !== undefined) { // user specified min value findIndex = helpers.indexOf(labels, me.options.ticks.min); me.minIndex = findIndex !== -1 ? findIndex : me.minIndex; } if (me.options.ticks.max !== undefined) { // user specified max value findIndex = helpers.indexOf(labels, me.options.ticks.max); me.maxIndex = findIndex !== -1 ? findIndex : me.maxIndex; } me.min = labels[me.minIndex]; me.max = labels[me.maxIndex]; }
javascript
function() { var me = this; var labels = me.getLabels(); me.minIndex = 0; me.maxIndex = labels.length - 1; var findIndex; if (me.options.ticks.min !== undefined) { // user specified min value findIndex = helpers.indexOf(labels, me.options.ticks.min); me.minIndex = findIndex !== -1 ? findIndex : me.minIndex; } if (me.options.ticks.max !== undefined) { // user specified max value findIndex = helpers.indexOf(labels, me.options.ticks.max); me.maxIndex = findIndex !== -1 ? findIndex : me.maxIndex; } me.min = labels[me.minIndex]; me.max = labels[me.maxIndex]; }
[ "function", "(", ")", "{", "var", "me", "=", "this", ";", "var", "labels", "=", "me", ".", "getLabels", "(", ")", ";", "me", ".", "minIndex", "=", "0", ";", "me", ".", "maxIndex", "=", "labels", ".", "length", "-", "1", ";", "var", "findIndex", ";", "if", "(", "me", ".", "options", ".", "ticks", ".", "min", "!==", "undefined", ")", "{", "// user specified min value", "findIndex", "=", "helpers", ".", "indexOf", "(", "labels", ",", "me", ".", "options", ".", "ticks", ".", "min", ")", ";", "me", ".", "minIndex", "=", "findIndex", "!==", "-", "1", "?", "findIndex", ":", "me", ".", "minIndex", ";", "}", "if", "(", "me", ".", "options", ".", "ticks", ".", "max", "!==", "undefined", ")", "{", "// user specified max value", "findIndex", "=", "helpers", ".", "indexOf", "(", "labels", ",", "me", ".", "options", ".", "ticks", ".", "max", ")", ";", "me", ".", "maxIndex", "=", "findIndex", "!==", "-", "1", "?", "findIndex", ":", "me", ".", "maxIndex", ";", "}", "me", ".", "min", "=", "labels", "[", "me", ".", "minIndex", "]", ";", "me", ".", "max", "=", "labels", "[", "me", ".", "maxIndex", "]", ";", "}" ]
Implement this so that
[ "Implement", "this", "so", "that" ]
8362f4ba54fb216343d30cc6a3ef35e98fa9cb44
https://github.com/Xrew/bobril-chartjs/blob/8362f4ba54fb216343d30cc6a3ef35e98fa9cb44/docs/a.js#L14367-L14388
51,926
Xrew/bobril-chartjs
docs/a.js
function(value, index, datasetIndex, includeOffset) { var me = this; // 1 is added because we need the length but we have the indexes var offsetAmt = Math.max((me.maxIndex + 1 - me.minIndex - ((me.options.gridLines.offsetGridLines) ? 0 : 1)), 1); if (value !== undefined && isNaN(index)) { var labels = me.getLabels(); var idx = labels.indexOf(value); index = idx !== -1 ? idx : index; } if (me.isHorizontal()) { var innerWidth = me.width - (me.paddingLeft + me.paddingRight); var valueWidth = innerWidth / offsetAmt; var widthOffset = (valueWidth * (index - me.minIndex)) + me.paddingLeft; if (me.options.gridLines.offsetGridLines && includeOffset || me.maxIndex === me.minIndex && includeOffset) { widthOffset += (valueWidth / 2); } return me.left + Math.round(widthOffset); } var innerHeight = me.height - (me.paddingTop + me.paddingBottom); var valueHeight = innerHeight / offsetAmt; var heightOffset = (valueHeight * (index - me.minIndex)) + me.paddingTop; if (me.options.gridLines.offsetGridLines && includeOffset) { heightOffset += (valueHeight / 2); } return me.top + Math.round(heightOffset); }
javascript
function(value, index, datasetIndex, includeOffset) { var me = this; // 1 is added because we need the length but we have the indexes var offsetAmt = Math.max((me.maxIndex + 1 - me.minIndex - ((me.options.gridLines.offsetGridLines) ? 0 : 1)), 1); if (value !== undefined && isNaN(index)) { var labels = me.getLabels(); var idx = labels.indexOf(value); index = idx !== -1 ? idx : index; } if (me.isHorizontal()) { var innerWidth = me.width - (me.paddingLeft + me.paddingRight); var valueWidth = innerWidth / offsetAmt; var widthOffset = (valueWidth * (index - me.minIndex)) + me.paddingLeft; if (me.options.gridLines.offsetGridLines && includeOffset || me.maxIndex === me.minIndex && includeOffset) { widthOffset += (valueWidth / 2); } return me.left + Math.round(widthOffset); } var innerHeight = me.height - (me.paddingTop + me.paddingBottom); var valueHeight = innerHeight / offsetAmt; var heightOffset = (valueHeight * (index - me.minIndex)) + me.paddingTop; if (me.options.gridLines.offsetGridLines && includeOffset) { heightOffset += (valueHeight / 2); } return me.top + Math.round(heightOffset); }
[ "function", "(", "value", ",", "index", ",", "datasetIndex", ",", "includeOffset", ")", "{", "var", "me", "=", "this", ";", "// 1 is added because we need the length but we have the indexes", "var", "offsetAmt", "=", "Math", ".", "max", "(", "(", "me", ".", "maxIndex", "+", "1", "-", "me", ".", "minIndex", "-", "(", "(", "me", ".", "options", ".", "gridLines", ".", "offsetGridLines", ")", "?", "0", ":", "1", ")", ")", ",", "1", ")", ";", "if", "(", "value", "!==", "undefined", "&&", "isNaN", "(", "index", ")", ")", "{", "var", "labels", "=", "me", ".", "getLabels", "(", ")", ";", "var", "idx", "=", "labels", ".", "indexOf", "(", "value", ")", ";", "index", "=", "idx", "!==", "-", "1", "?", "idx", ":", "index", ";", "}", "if", "(", "me", ".", "isHorizontal", "(", ")", ")", "{", "var", "innerWidth", "=", "me", ".", "width", "-", "(", "me", ".", "paddingLeft", "+", "me", ".", "paddingRight", ")", ";", "var", "valueWidth", "=", "innerWidth", "/", "offsetAmt", ";", "var", "widthOffset", "=", "(", "valueWidth", "*", "(", "index", "-", "me", ".", "minIndex", ")", ")", "+", "me", ".", "paddingLeft", ";", "if", "(", "me", ".", "options", ".", "gridLines", ".", "offsetGridLines", "&&", "includeOffset", "||", "me", ".", "maxIndex", "===", "me", ".", "minIndex", "&&", "includeOffset", ")", "{", "widthOffset", "+=", "(", "valueWidth", "/", "2", ")", ";", "}", "return", "me", ".", "left", "+", "Math", ".", "round", "(", "widthOffset", ")", ";", "}", "var", "innerHeight", "=", "me", ".", "height", "-", "(", "me", ".", "paddingTop", "+", "me", ".", "paddingBottom", ")", ";", "var", "valueHeight", "=", "innerHeight", "/", "offsetAmt", ";", "var", "heightOffset", "=", "(", "valueHeight", "*", "(", "index", "-", "me", ".", "minIndex", ")", ")", "+", "me", ".", "paddingTop", ";", "if", "(", "me", ".", "options", ".", "gridLines", ".", "offsetGridLines", "&&", "includeOffset", ")", "{", "heightOffset", "+=", "(", "valueHeight", "/", "2", ")", ";", "}", "return", "me", ".", "top", "+", "Math", ".", "round", "(", "heightOffset", ")", ";", "}" ]
Used to get data value locations. Value can either be an index or a numerical value
[ "Used", "to", "get", "data", "value", "locations", ".", "Value", "can", "either", "be", "an", "index", "or", "a", "numerical", "value" ]
8362f4ba54fb216343d30cc6a3ef35e98fa9cb44
https://github.com/Xrew/bobril-chartjs/blob/8362f4ba54fb216343d30cc6a3ef35e98fa9cb44/docs/a.js#L14409-L14440
51,927
ssmereka/cramit
libs/index.js
function(err, files, results) { if(err) { cb(err); } else { for(var i = 0; i < results.length; i++) { if(results[i] !== undefined && results[i].error === undefined && results[i].id !== undefined) { fixtures[results[i].id] = results[i]; } } cb(undefined, fixtures); } }
javascript
function(err, files, results) { if(err) { cb(err); } else { for(var i = 0; i < results.length; i++) { if(results[i] !== undefined && results[i].error === undefined && results[i].id !== undefined) { fixtures[results[i].id] = results[i]; } } cb(undefined, fixtures); } }
[ "function", "(", "err", ",", "files", ",", "results", ")", "{", "if", "(", "err", ")", "{", "cb", "(", "err", ")", ";", "}", "else", "{", "for", "(", "var", "i", "=", "0", ";", "i", "<", "results", ".", "length", ";", "i", "++", ")", "{", "if", "(", "results", "[", "i", "]", "!==", "undefined", "&&", "results", "[", "i", "]", ".", "error", "===", "undefined", "&&", "results", "[", "i", "]", ".", "id", "!==", "undefined", ")", "{", "fixtures", "[", "results", "[", "i", "]", ".", "id", "]", "=", "results", "[", "i", "]", ";", "}", "}", "cb", "(", "undefined", ",", "fixtures", ")", ";", "}", "}" ]
Format the returned data object into a fixtures object, with the fixture ID as the key and the fixture class as the value.
[ "Format", "the", "returned", "data", "object", "into", "a", "fixtures", "object", "with", "the", "fixture", "ID", "as", "the", "key", "and", "the", "fixture", "class", "as", "the", "value", "." ]
dac45479ca2b9455095624637a4796c1d2a710b9
https://github.com/ssmereka/cramit/blob/dac45479ca2b9455095624637a4796c1d2a710b9/libs/index.js#L255-L266
51,928
xsolon/spexplorerjs
webapi/src/components/sp/widgets/field.selector.js
function (listTitle) { return $.Deferred(function (dfd) { trace.debug(`loading list ${listTitle}`); spdal.getList(listTitle).done(function (list) { onListChange(list); listCtrl.data("xSPTreeLight").value(list); }).always(function () { dfd.resolve(); }); }).promise(); }
javascript
function (listTitle) { return $.Deferred(function (dfd) { trace.debug(`loading list ${listTitle}`); spdal.getList(listTitle).done(function (list) { onListChange(list); listCtrl.data("xSPTreeLight").value(list); }).always(function () { dfd.resolve(); }); }).promise(); }
[ "function", "(", "listTitle", ")", "{", "return", "$", ".", "Deferred", "(", "function", "(", "dfd", ")", "{", "trace", ".", "debug", "(", "`", "${", "listTitle", "}", "`", ")", ";", "spdal", ".", "getList", "(", "listTitle", ")", ".", "done", "(", "function", "(", "list", ")", "{", "onListChange", "(", "list", ")", ";", "listCtrl", ".", "data", "(", "\"xSPTreeLight\"", ")", ".", "value", "(", "list", ")", ";", "}", ")", ".", "always", "(", "function", "(", ")", "{", "dfd", ".", "resolve", "(", ")", ";", "}", ")", ";", "}", ")", ".", "promise", "(", ")", ";", "}" ]
hide treelight section
[ "hide", "treelight", "section" ]
4e9b410864afb731f88e84414984fa18ac5705f1
https://github.com/xsolon/spexplorerjs/blob/4e9b410864afb731f88e84414984fa18ac5705f1/webapi/src/components/sp/widgets/field.selector.js#L238-L252
51,929
labs-js/turbo-git-config
lib/utils.js
checkGitRepoExistence
function checkGitRepoExistence() { return new Promise(function(resolve, reject) { var checkRepoCommand = childProcess.exec('git branch'); checkRepoCommand.stderr.on('data', function(err) { reject(err); }); checkRepoCommand.on('close', function(code) { if (code === 0) { //0 means ok, 128 means error resolve(); } }); }); }
javascript
function checkGitRepoExistence() { return new Promise(function(resolve, reject) { var checkRepoCommand = childProcess.exec('git branch'); checkRepoCommand.stderr.on('data', function(err) { reject(err); }); checkRepoCommand.on('close', function(code) { if (code === 0) { //0 means ok, 128 means error resolve(); } }); }); }
[ "function", "checkGitRepoExistence", "(", ")", "{", "return", "new", "Promise", "(", "function", "(", "resolve", ",", "reject", ")", "{", "var", "checkRepoCommand", "=", "childProcess", ".", "exec", "(", "'git branch'", ")", ";", "checkRepoCommand", ".", "stderr", ".", "on", "(", "'data'", ",", "function", "(", "err", ")", "{", "reject", "(", "err", ")", ";", "}", ")", ";", "checkRepoCommand", ".", "on", "(", "'close'", ",", "function", "(", "code", ")", "{", "if", "(", "code", "===", "0", ")", "{", "//0 means ok, 128 means error", "resolve", "(", ")", ";", "}", "}", ")", ";", "}", ")", ";", "}" ]
Exec git branch to check if exist .git files
[ "Exec", "git", "branch", "to", "check", "if", "exist", ".", "git", "files" ]
b8e540a426cc778df36a62df9807d03a82322c8f
https://github.com/labs-js/turbo-git-config/blob/b8e540a426cc778df36a62df9807d03a82322c8f/lib/utils.js#L36-L50
51,930
bucharest-gold/unifiedpush-admin-client
lib/variants.js
create
function create (client) { return function create (options) { options = options || {}; const type = getType(options); const req = { url: `${client.baseUrl}/rest/applications/${options.pushAppId}/${type}`, method: 'POST' }; const data = { name: options.name, description: options.description }; if (options.type !== 'ios') { for (let key in options[options.type]) { data[key] = options[options.type][key]; } req.body = data; } else { data.passphrase = options.ios.passphrase; data.production = options.ios.production ? 'true' : 'false'; // If they send in a string, then lets assume that is the location of the cert file // Otherwise, we will assume it is a Stream or Buffer and can just pass it along if (typeof options.ios.certificate === 'string') { data.certificate = fs.createReadStream(options.ios.certificate); } else { data.certificate = options.ios.certificate; } // need to clean up the description field if it is undefined, doing multipart with request barfs if this is null if (!data.description) { delete data.description; } req.formData = data; } return request(client, req) .then((response) => { if (response.resp.statusCode !== 201) { return Promise.reject(response.body); } return Promise.resolve(response.body); }); }; }
javascript
function create (client) { return function create (options) { options = options || {}; const type = getType(options); const req = { url: `${client.baseUrl}/rest/applications/${options.pushAppId}/${type}`, method: 'POST' }; const data = { name: options.name, description: options.description }; if (options.type !== 'ios') { for (let key in options[options.type]) { data[key] = options[options.type][key]; } req.body = data; } else { data.passphrase = options.ios.passphrase; data.production = options.ios.production ? 'true' : 'false'; // If they send in a string, then lets assume that is the location of the cert file // Otherwise, we will assume it is a Stream or Buffer and can just pass it along if (typeof options.ios.certificate === 'string') { data.certificate = fs.createReadStream(options.ios.certificate); } else { data.certificate = options.ios.certificate; } // need to clean up the description field if it is undefined, doing multipart with request barfs if this is null if (!data.description) { delete data.description; } req.formData = data; } return request(client, req) .then((response) => { if (response.resp.statusCode !== 201) { return Promise.reject(response.body); } return Promise.resolve(response.body); }); }; }
[ "function", "create", "(", "client", ")", "{", "return", "function", "create", "(", "options", ")", "{", "options", "=", "options", "||", "{", "}", ";", "const", "type", "=", "getType", "(", "options", ")", ";", "const", "req", "=", "{", "url", ":", "`", "${", "client", ".", "baseUrl", "}", "${", "options", ".", "pushAppId", "}", "${", "type", "}", "`", ",", "method", ":", "'POST'", "}", ";", "const", "data", "=", "{", "name", ":", "options", ".", "name", ",", "description", ":", "options", ".", "description", "}", ";", "if", "(", "options", ".", "type", "!==", "'ios'", ")", "{", "for", "(", "let", "key", "in", "options", "[", "options", ".", "type", "]", ")", "{", "data", "[", "key", "]", "=", "options", "[", "options", ".", "type", "]", "[", "key", "]", ";", "}", "req", ".", "body", "=", "data", ";", "}", "else", "{", "data", ".", "passphrase", "=", "options", ".", "ios", ".", "passphrase", ";", "data", ".", "production", "=", "options", ".", "ios", ".", "production", "?", "'true'", ":", "'false'", ";", "// If they send in a string, then lets assume that is the location of the cert file", "// Otherwise, we will assume it is a Stream or Buffer and can just pass it along", "if", "(", "typeof", "options", ".", "ios", ".", "certificate", "===", "'string'", ")", "{", "data", ".", "certificate", "=", "fs", ".", "createReadStream", "(", "options", ".", "ios", ".", "certificate", ")", ";", "}", "else", "{", "data", ".", "certificate", "=", "options", ".", "ios", ".", "certificate", ";", "}", "// need to clean up the description field if it is undefined, doing multipart with request barfs if this is null", "if", "(", "!", "data", ".", "description", ")", "{", "delete", "data", ".", "description", ";", "}", "req", ".", "formData", "=", "data", ";", "}", "return", "request", "(", "client", ",", "req", ")", ".", "then", "(", "(", "response", ")", "=>", "{", "if", "(", "response", ".", "resp", ".", "statusCode", "!==", "201", ")", "{", "return", "Promise", ".", "reject", "(", "response", ".", "body", ")", ";", "}", "return", "Promise", ".", "resolve", "(", "response", ".", "body", ")", ";", "}", ")", ";", "}", ";", "}" ]
A function to create a variant of a particular type. @param {object} options - An options object @param {string} options.pushAppId - The id of the push application @param {string} options.type - The type variant. - ex: android, ios, .... All Variants will have a type, name, and an optional description @param {string} options.name - The name of the variant @param {string} [options.description] - The description of the variant * For SimplePush ** Nothing else required * For iOS ** @param {object} [options.ios] - The specific iOS options @param {string} [options.ios.passphrase] - The APNs passphrase that is needed to establish a connection to any of Apple's APNs Push Servers. @param {string|Buffer|Stream} [options.ios.certficate] - the full location of the APNs certificate that is needed to establish a connection to any of Apple's APNs Push Servers. @param {boolean} [options.ios.production] - defaults to false - flag to indicate if a connection to Apples production or sandbox APNS server * For Android ** @param {object} [options.android] - The specific Android options @param {string} [options.android.googleKey] - The Google Cloud Messaging Key. Required For Android @param {string} [options.android.projectNumber] - The Google Project Number * For ADM - Amazon Push ** @param {object} [options.adm] - The specific ADM options @param {string} [options.adm.clientId] - The client id to connect to the Amazon Device Messaging services @param {string} [options.adm.clientSecret] - The client secret (password) to connect to the Amazon Device Messaging services * For Windows ** @param {object} [options.windows] - The specific Windows options @param {string} [options.windows.protocolType] - mpns or wns @param {string} [options.windows.sid] - *for wns only* - (Package security identifier) used to connect to the windows push notification services @param {string} [options.windows.clientSecret] - *for wns only* - The client secret (password) to connect to the windows push notification services @returns {Promise} A promise that will resolve with the Array of variant objects or if a variant is specified, just the variant object @example adminClient(baseUrl, settings) .then((client) => { client.variants.create(variantOptions) .then((variant) => { console.log(variant) // {...} }) })
[ "A", "function", "to", "create", "a", "variant", "of", "a", "particular", "type", "." ]
a39c98c9a383d7f87cb5cbbc25c4371ea1ad049e
https://github.com/bucharest-gold/unifiedpush-admin-client/blob/a39c98c9a383d7f87cb5cbbc25c4371ea1ad049e/lib/variants.js#L106-L157
51,931
tolokoban/ToloFrameWork
ker/cls/tfw.CssAnim.js
function(variables) { var animation = false, animationstring = 'animation', keyframeprefix = '', domPrefixes = ["Webkit", "Moz", "O", "ms", "Khtml"], pfx = '', elm = document.querySelector("body"); if( elm.style.animationName !== undefined ) { animation = true; } if( animation === false ) { for( var i = 0; i < domPrefixes.length; i++ ) { if( elm.style[ domPrefixes[i] + 'AnimationName' ] !== undefined ) { pfx = domPrefixes[ i ]; animationstring = pfx + 'Animation'; keyframeprefix = '-' + pfx.toLowerCase() + '-'; animation = true; break; } } } variables.keyframesPrefix = keyframeprefix; variables.animationString = animationstring; variables.aliases = { transform: keyframeprefix + "transform" }; variables.count = 1; }
javascript
function(variables) { var animation = false, animationstring = 'animation', keyframeprefix = '', domPrefixes = ["Webkit", "Moz", "O", "ms", "Khtml"], pfx = '', elm = document.querySelector("body"); if( elm.style.animationName !== undefined ) { animation = true; } if( animation === false ) { for( var i = 0; i < domPrefixes.length; i++ ) { if( elm.style[ domPrefixes[i] + 'AnimationName' ] !== undefined ) { pfx = domPrefixes[ i ]; animationstring = pfx + 'Animation'; keyframeprefix = '-' + pfx.toLowerCase() + '-'; animation = true; break; } } } variables.keyframesPrefix = keyframeprefix; variables.animationString = animationstring; variables.aliases = { transform: keyframeprefix + "transform" }; variables.count = 1; }
[ "function", "(", "variables", ")", "{", "var", "animation", "=", "false", ",", "animationstring", "=", "'animation'", ",", "keyframeprefix", "=", "''", ",", "domPrefixes", "=", "[", "\"Webkit\"", ",", "\"Moz\"", ",", "\"O\"", ",", "\"ms\"", ",", "\"Khtml\"", "]", ",", "pfx", "=", "''", ",", "elm", "=", "document", ".", "querySelector", "(", "\"body\"", ")", ";", "if", "(", "elm", ".", "style", ".", "animationName", "!==", "undefined", ")", "{", "animation", "=", "true", ";", "}", "if", "(", "animation", "===", "false", ")", "{", "for", "(", "var", "i", "=", "0", ";", "i", "<", "domPrefixes", ".", "length", ";", "i", "++", ")", "{", "if", "(", "elm", ".", "style", "[", "domPrefixes", "[", "i", "]", "+", "'AnimationName'", "]", "!==", "undefined", ")", "{", "pfx", "=", "domPrefixes", "[", "i", "]", ";", "animationstring", "=", "pfx", "+", "'Animation'", ";", "keyframeprefix", "=", "'-'", "+", "pfx", ".", "toLowerCase", "(", ")", "+", "'-'", ";", "animation", "=", "true", ";", "break", ";", "}", "}", "}", "variables", ".", "keyframesPrefix", "=", "keyframeprefix", ";", "variables", ".", "animationString", "=", "animationstring", ";", "variables", ".", "aliases", "=", "{", "transform", ":", "keyframeprefix", "+", "\"transform\"", "}", ";", "variables", ".", "count", "=", "1", ";", "}" ]
Look for css prefixes.
[ "Look", "for", "css", "prefixes", "." ]
730845a833a9660ebfdb60ad027ebaab5ac871b6
https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/ker/cls/tfw.CssAnim.js#L16-L42
51,932
tuunanen/camelton
lib/cli.js
cli
function cli(program) { var source = program.args[0] ? path.resolve(program.args[0]) : null, destinations = program.args[1] ? Array.prototype.slice.call(program.args, 1) : [], options = {}, camelton; if (!source) { console.error('Source file not defined.'); program.help(); } if (!destinations.length) { console.error('Destination file not defined.'); program.help(); } if (program.prune) { options.prune = program.prune; } if (program.placeholder) { options.placeholder = program.placeholder; } if (program.sort) { options.sort = program.sort; } if (program.verbose) { options.verbose = program.verbose; } try { camelton = new Camelton(source, destinations, options); camelton.run(); camelton.report(); process.exit(0); } catch (e) { console.error(e.message); process.exit(1); } }
javascript
function cli(program) { var source = program.args[0] ? path.resolve(program.args[0]) : null, destinations = program.args[1] ? Array.prototype.slice.call(program.args, 1) : [], options = {}, camelton; if (!source) { console.error('Source file not defined.'); program.help(); } if (!destinations.length) { console.error('Destination file not defined.'); program.help(); } if (program.prune) { options.prune = program.prune; } if (program.placeholder) { options.placeholder = program.placeholder; } if (program.sort) { options.sort = program.sort; } if (program.verbose) { options.verbose = program.verbose; } try { camelton = new Camelton(source, destinations, options); camelton.run(); camelton.report(); process.exit(0); } catch (e) { console.error(e.message); process.exit(1); } }
[ "function", "cli", "(", "program", ")", "{", "var", "source", "=", "program", ".", "args", "[", "0", "]", "?", "path", ".", "resolve", "(", "program", ".", "args", "[", "0", "]", ")", ":", "null", ",", "destinations", "=", "program", ".", "args", "[", "1", "]", "?", "Array", ".", "prototype", ".", "slice", ".", "call", "(", "program", ".", "args", ",", "1", ")", ":", "[", "]", ",", "options", "=", "{", "}", ",", "camelton", ";", "if", "(", "!", "source", ")", "{", "console", ".", "error", "(", "'Source file not defined.'", ")", ";", "program", ".", "help", "(", ")", ";", "}", "if", "(", "!", "destinations", ".", "length", ")", "{", "console", ".", "error", "(", "'Destination file not defined.'", ")", ";", "program", ".", "help", "(", ")", ";", "}", "if", "(", "program", ".", "prune", ")", "{", "options", ".", "prune", "=", "program", ".", "prune", ";", "}", "if", "(", "program", ".", "placeholder", ")", "{", "options", ".", "placeholder", "=", "program", ".", "placeholder", ";", "}", "if", "(", "program", ".", "sort", ")", "{", "options", ".", "sort", "=", "program", ".", "sort", ";", "}", "if", "(", "program", ".", "verbose", ")", "{", "options", ".", "verbose", "=", "program", ".", "verbose", ";", "}", "try", "{", "camelton", "=", "new", "Camelton", "(", "source", ",", "destinations", ",", "options", ")", ";", "camelton", ".", "run", "(", ")", ";", "camelton", ".", "report", "(", ")", ";", "process", ".", "exit", "(", "0", ")", ";", "}", "catch", "(", "e", ")", "{", "console", ".", "error", "(", "e", ".", "message", ")", ";", "process", ".", "exit", "(", "1", ")", ";", "}", "}" ]
Command-line program. @param {object} program - Commander program
[ "Command", "-", "line", "program", "." ]
2beee32431e1b2867396e25f560f8dbd53535041
https://github.com/tuunanen/camelton/blob/2beee32431e1b2867396e25f560f8dbd53535041/lib/cli.js#L18-L60
51,933
jaredhanson/connect-lrdd
lib/middleware/lrdd.js
serializeToXRD
function serializeToXRD(descriptor) { var xml = '<?xml version="1.0" encoding="UTF-8"?>'; xml += '<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'; if (descriptor.expires) { xml += '<Expires>' + xsdDateTimeString(descriptor.expires) + '</Expires>'; } if (descriptor.subject) { xml += '<Subject>' + descriptor.subject + '</Subject>'; } descriptor.aliases.forEach(function(alias) { xml += '<Alias>' + alias + '</Alias>'; }); descriptor.properties.forEach(function(key, value) { if (value) { xml += '<Property type="' + key + '">' + value + '</Property>'; } else { xml += '<Property type="' + key + '" xsi:nil="true" />'; } }); descriptor.links.forEach(function(link) { xml += '<Link'; if (link.rel) { xml += ' rel="' + link.rel + '"'; } if (link.href) { xml += ' href="' + link.href + '"'; } if (link.template) { xml += ' template="' + link.template + '"'; } if (link.type) { xml += ' type="' + link.type + '"'; } xml += '>'; link.titles.forEach(function(lang, title) { if (lang === '_') { xml += '<Title>' + title + '</Title>'; } else { xml += '<Title xml:lang="' + lang + '">' + title + '</Title>'; } }); link.properties.forEach(function(key, value) { if (value) { xml += '<Property type="' + key + '">' + value + '</Property>'; } else { xml += '<Property type="' + key + '" xsi:nil="true" />'; } }); xml += '</Link>'; }); xml += '</XRD>'; return xml; }
javascript
function serializeToXRD(descriptor) { var xml = '<?xml version="1.0" encoding="UTF-8"?>'; xml += '<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'; if (descriptor.expires) { xml += '<Expires>' + xsdDateTimeString(descriptor.expires) + '</Expires>'; } if (descriptor.subject) { xml += '<Subject>' + descriptor.subject + '</Subject>'; } descriptor.aliases.forEach(function(alias) { xml += '<Alias>' + alias + '</Alias>'; }); descriptor.properties.forEach(function(key, value) { if (value) { xml += '<Property type="' + key + '">' + value + '</Property>'; } else { xml += '<Property type="' + key + '" xsi:nil="true" />'; } }); descriptor.links.forEach(function(link) { xml += '<Link'; if (link.rel) { xml += ' rel="' + link.rel + '"'; } if (link.href) { xml += ' href="' + link.href + '"'; } if (link.template) { xml += ' template="' + link.template + '"'; } if (link.type) { xml += ' type="' + link.type + '"'; } xml += '>'; link.titles.forEach(function(lang, title) { if (lang === '_') { xml += '<Title>' + title + '</Title>'; } else { xml += '<Title xml:lang="' + lang + '">' + title + '</Title>'; } }); link.properties.forEach(function(key, value) { if (value) { xml += '<Property type="' + key + '">' + value + '</Property>'; } else { xml += '<Property type="' + key + '" xsi:nil="true" />'; } }); xml += '</Link>'; }); xml += '</XRD>'; return xml; }
[ "function", "serializeToXRD", "(", "descriptor", ")", "{", "var", "xml", "=", "'<?xml version=\"1.0\" encoding=\"UTF-8\"?>'", ";", "xml", "+=", "'<XRD xmlns=\"http://docs.oasis-open.org/ns/xri/xrd-1.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">'", ";", "if", "(", "descriptor", ".", "expires", ")", "{", "xml", "+=", "'<Expires>'", "+", "xsdDateTimeString", "(", "descriptor", ".", "expires", ")", "+", "'</Expires>'", ";", "}", "if", "(", "descriptor", ".", "subject", ")", "{", "xml", "+=", "'<Subject>'", "+", "descriptor", ".", "subject", "+", "'</Subject>'", ";", "}", "descriptor", ".", "aliases", ".", "forEach", "(", "function", "(", "alias", ")", "{", "xml", "+=", "'<Alias>'", "+", "alias", "+", "'</Alias>'", ";", "}", ")", ";", "descriptor", ".", "properties", ".", "forEach", "(", "function", "(", "key", ",", "value", ")", "{", "if", "(", "value", ")", "{", "xml", "+=", "'<Property type=\"'", "+", "key", "+", "'\">'", "+", "value", "+", "'</Property>'", ";", "}", "else", "{", "xml", "+=", "'<Property type=\"'", "+", "key", "+", "'\" xsi:nil=\"true\" />'", ";", "}", "}", ")", ";", "descriptor", ".", "links", ".", "forEach", "(", "function", "(", "link", ")", "{", "xml", "+=", "'<Link'", ";", "if", "(", "link", ".", "rel", ")", "{", "xml", "+=", "' rel=\"'", "+", "link", ".", "rel", "+", "'\"'", ";", "}", "if", "(", "link", ".", "href", ")", "{", "xml", "+=", "' href=\"'", "+", "link", ".", "href", "+", "'\"'", ";", "}", "if", "(", "link", ".", "template", ")", "{", "xml", "+=", "' template=\"'", "+", "link", ".", "template", "+", "'\"'", ";", "}", "if", "(", "link", ".", "type", ")", "{", "xml", "+=", "' type=\"'", "+", "link", ".", "type", "+", "'\"'", ";", "}", "xml", "+=", "'>'", ";", "link", ".", "titles", ".", "forEach", "(", "function", "(", "lang", ",", "title", ")", "{", "if", "(", "lang", "===", "'_'", ")", "{", "xml", "+=", "'<Title>'", "+", "title", "+", "'</Title>'", ";", "}", "else", "{", "xml", "+=", "'<Title xml:lang=\"'", "+", "lang", "+", "'\">'", "+", "title", "+", "'</Title>'", ";", "}", "}", ")", ";", "link", ".", "properties", ".", "forEach", "(", "function", "(", "key", ",", "value", ")", "{", "if", "(", "value", ")", "{", "xml", "+=", "'<Property type=\"'", "+", "key", "+", "'\">'", "+", "value", "+", "'</Property>'", ";", "}", "else", "{", "xml", "+=", "'<Property type=\"'", "+", "key", "+", "'\" xsi:nil=\"true\" />'", ";", "}", "}", ")", ";", "xml", "+=", "'</Link>'", ";", "}", ")", ";", "xml", "+=", "'</XRD>'", ";", "return", "xml", ";", "}" ]
Serialize `descriptor` to XRD format. @param {Descriptor} descriptor @return {String} @api private
[ "Serialize", "descriptor", "to", "XRD", "format", "." ]
6d1f1f9b98cdd1ebc5fb3f048c4eddf5ef034ec1
https://github.com/jaredhanson/connect-lrdd/blob/6d1f1f9b98cdd1ebc5fb3f048c4eddf5ef034ec1/lib/middleware/lrdd.js#L94-L148
51,934
jaredhanson/connect-lrdd
lib/middleware/lrdd.js
serializeToJRD
function serializeToJRD(descriptor) { var obj = {}; if (descriptor.expires) { obj.expires = xsdDateTimeString(descriptor.expires); } if (descriptor.subject) { obj.subject = descriptor.subject; } if (descriptor.aliases.length > 0) { obj.aliases = []; descriptor.aliases.forEach(function(alias) { obj.aliases.push(alias); }); } if (descriptor.properties.length > 0) { obj.properties = {}; descriptor.properties.forEach(function(key, value) { obj.properties[key] = value; }, { flatten: true }); } if (descriptor.links.length > 0) { obj.links = []; descriptor.links.forEach(function(link) { var l = {}; if (link.rel) { l.rel = link.rel; } if (link.href) { l.href = link.href; } if (link.template) { l.template = link.template; } if (link.type) { l.type = link.type; } if (link.titles.length > 0) { l.titles = {}; link.titles.forEach(function(lang, title) { if (lang === '_') { l.titles['default'] = title; } else { l.titles[lang] = title; } }, { flatten: true }); } if (link.properties.length > 0) { l.properties = {}; link.properties.forEach(function(key, value) { l.properties[key] = value; }, { flatten: true }); } obj.links.push(l); }); } return JSON.stringify(obj); }
javascript
function serializeToJRD(descriptor) { var obj = {}; if (descriptor.expires) { obj.expires = xsdDateTimeString(descriptor.expires); } if (descriptor.subject) { obj.subject = descriptor.subject; } if (descriptor.aliases.length > 0) { obj.aliases = []; descriptor.aliases.forEach(function(alias) { obj.aliases.push(alias); }); } if (descriptor.properties.length > 0) { obj.properties = {}; descriptor.properties.forEach(function(key, value) { obj.properties[key] = value; }, { flatten: true }); } if (descriptor.links.length > 0) { obj.links = []; descriptor.links.forEach(function(link) { var l = {}; if (link.rel) { l.rel = link.rel; } if (link.href) { l.href = link.href; } if (link.template) { l.template = link.template; } if (link.type) { l.type = link.type; } if (link.titles.length > 0) { l.titles = {}; link.titles.forEach(function(lang, title) { if (lang === '_') { l.titles['default'] = title; } else { l.titles[lang] = title; } }, { flatten: true }); } if (link.properties.length > 0) { l.properties = {}; link.properties.forEach(function(key, value) { l.properties[key] = value; }, { flatten: true }); } obj.links.push(l); }); } return JSON.stringify(obj); }
[ "function", "serializeToJRD", "(", "descriptor", ")", "{", "var", "obj", "=", "{", "}", ";", "if", "(", "descriptor", ".", "expires", ")", "{", "obj", ".", "expires", "=", "xsdDateTimeString", "(", "descriptor", ".", "expires", ")", ";", "}", "if", "(", "descriptor", ".", "subject", ")", "{", "obj", ".", "subject", "=", "descriptor", ".", "subject", ";", "}", "if", "(", "descriptor", ".", "aliases", ".", "length", ">", "0", ")", "{", "obj", ".", "aliases", "=", "[", "]", ";", "descriptor", ".", "aliases", ".", "forEach", "(", "function", "(", "alias", ")", "{", "obj", ".", "aliases", ".", "push", "(", "alias", ")", ";", "}", ")", ";", "}", "if", "(", "descriptor", ".", "properties", ".", "length", ">", "0", ")", "{", "obj", ".", "properties", "=", "{", "}", ";", "descriptor", ".", "properties", ".", "forEach", "(", "function", "(", "key", ",", "value", ")", "{", "obj", ".", "properties", "[", "key", "]", "=", "value", ";", "}", ",", "{", "flatten", ":", "true", "}", ")", ";", "}", "if", "(", "descriptor", ".", "links", ".", "length", ">", "0", ")", "{", "obj", ".", "links", "=", "[", "]", ";", "descriptor", ".", "links", ".", "forEach", "(", "function", "(", "link", ")", "{", "var", "l", "=", "{", "}", ";", "if", "(", "link", ".", "rel", ")", "{", "l", ".", "rel", "=", "link", ".", "rel", ";", "}", "if", "(", "link", ".", "href", ")", "{", "l", ".", "href", "=", "link", ".", "href", ";", "}", "if", "(", "link", ".", "template", ")", "{", "l", ".", "template", "=", "link", ".", "template", ";", "}", "if", "(", "link", ".", "type", ")", "{", "l", ".", "type", "=", "link", ".", "type", ";", "}", "if", "(", "link", ".", "titles", ".", "length", ">", "0", ")", "{", "l", ".", "titles", "=", "{", "}", ";", "link", ".", "titles", ".", "forEach", "(", "function", "(", "lang", ",", "title", ")", "{", "if", "(", "lang", "===", "'_'", ")", "{", "l", ".", "titles", "[", "'default'", "]", "=", "title", ";", "}", "else", "{", "l", ".", "titles", "[", "lang", "]", "=", "title", ";", "}", "}", ",", "{", "flatten", ":", "true", "}", ")", ";", "}", "if", "(", "link", ".", "properties", ".", "length", ">", "0", ")", "{", "l", ".", "properties", "=", "{", "}", ";", "link", ".", "properties", ".", "forEach", "(", "function", "(", "key", ",", "value", ")", "{", "l", ".", "properties", "[", "key", "]", "=", "value", ";", "}", ",", "{", "flatten", ":", "true", "}", ")", ";", "}", "obj", ".", "links", ".", "push", "(", "l", ")", ";", "}", ")", ";", "}", "return", "JSON", ".", "stringify", "(", "obj", ")", ";", "}" ]
Serialize `descriptor` to JRD format. @param {Descriptor} descriptor @return {String} @api private
[ "Serialize", "descriptor", "to", "JRD", "format", "." ]
6d1f1f9b98cdd1ebc5fb3f048c4eddf5ef034ec1
https://github.com/jaredhanson/connect-lrdd/blob/6d1f1f9b98cdd1ebc5fb3f048c4eddf5ef034ec1/lib/middleware/lrdd.js#L157-L207
51,935
nickeljew/unjq-ajax
lib/ajax.js
textXml
function textXml(data) { var xml = undefined, tmp = undefined; if (!data || typeof data !== "string") { return null; } // Support: IE9 try { tmp = new DOMParser(); xml = tmp.parseFromString(data, "text/xml"); } catch (e) { xml = undefined; } if (!xml || xml.getElementsByTagName("parsererror").length) { throwError("Invalid XML: " + data); } return xml; }
javascript
function textXml(data) { var xml = undefined, tmp = undefined; if (!data || typeof data !== "string") { return null; } // Support: IE9 try { tmp = new DOMParser(); xml = tmp.parseFromString(data, "text/xml"); } catch (e) { xml = undefined; } if (!xml || xml.getElementsByTagName("parsererror").length) { throwError("Invalid XML: " + data); } return xml; }
[ "function", "textXml", "(", "data", ")", "{", "var", "xml", "=", "undefined", ",", "tmp", "=", "undefined", ";", "if", "(", "!", "data", "||", "typeof", "data", "!==", "\"string\"", ")", "{", "return", "null", ";", "}", "// Support: IE9", "try", "{", "tmp", "=", "new", "DOMParser", "(", ")", ";", "xml", "=", "tmp", ".", "parseFromString", "(", "data", ",", "\"text/xml\"", ")", ";", "}", "catch", "(", "e", ")", "{", "xml", "=", "undefined", ";", "}", "if", "(", "!", "xml", "||", "xml", ".", "getElementsByTagName", "(", "\"parsererror\"", ")", ".", "length", ")", "{", "throwError", "(", "\"Invalid XML: \"", "+", "data", ")", ";", "}", "return", "xml", ";", "}" ]
Parse text as xml
[ "Parse", "text", "as", "xml" ]
126626c08640e9ae386fea4e34b6b10482c5dbd6
https://github.com/nickeljew/unjq-ajax/blob/126626c08640e9ae386fea4e34b6b10482c5dbd6/lib/ajax.js#L824-L843
51,936
nickeljew/unjq-ajax
lib/ajax.js
ajaxSetup
function ajaxSetup(target, settings) { return settings ? // Building a settings object ajaxExtend(ajaxExtend(target, this.ajaxSettings), settings) : // Extending ajaxSettings ajaxExtend(this.ajaxSettings, target); }
javascript
function ajaxSetup(target, settings) { return settings ? // Building a settings object ajaxExtend(ajaxExtend(target, this.ajaxSettings), settings) : // Extending ajaxSettings ajaxExtend(this.ajaxSettings, target); }
[ "function", "ajaxSetup", "(", "target", ",", "settings", ")", "{", "return", "settings", "?", "// Building a settings object", "ajaxExtend", "(", "ajaxExtend", "(", "target", ",", "this", ".", "ajaxSettings", ")", ",", "settings", ")", ":", "// Extending ajaxSettings", "ajaxExtend", "(", "this", ".", "ajaxSettings", ",", "target", ")", ";", "}" ]
Creates a full fledged settings object into target with both ajaxSettings and settings fields. If target is omitted, writes into ajaxSettings.
[ "Creates", "a", "full", "fledged", "settings", "object", "into", "target", "with", "both", "ajaxSettings", "and", "settings", "fields", ".", "If", "target", "is", "omitted", "writes", "into", "ajaxSettings", "." ]
126626c08640e9ae386fea4e34b6b10482c5dbd6
https://github.com/nickeljew/unjq-ajax/blob/126626c08640e9ae386fea4e34b6b10482c5dbd6/lib/ajax.js#L859-L867
51,937
nickeljew/unjq-ajax
lib/ajax.js
abort
function abort(statusText) { var finalText = statusText || strAbort; if (transport) { transport.abort(finalText); } done(0, finalText); return this; }
javascript
function abort(statusText) { var finalText = statusText || strAbort; if (transport) { transport.abort(finalText); } done(0, finalText); return this; }
[ "function", "abort", "(", "statusText", ")", "{", "var", "finalText", "=", "statusText", "||", "strAbort", ";", "if", "(", "transport", ")", "{", "transport", ".", "abort", "(", "finalText", ")", ";", "}", "done", "(", "0", ",", "finalText", ")", ";", "return", "this", ";", "}" ]
Cancel the request
[ "Cancel", "the", "request" ]
126626c08640e9ae386fea4e34b6b10482c5dbd6
https://github.com/nickeljew/unjq-ajax/blob/126626c08640e9ae386fea4e34b6b10482c5dbd6/lib/ajax.js#L997-L1004
51,938
ENOW-IJI/ENOW-console
dist/src/anchors.js
function (endpoint, anchorPos) { continuousAnchorLocations[endpoint.id] = [ anchorPos[0], anchorPos[1], anchorPos[2], anchorPos[3] ]; continuousAnchorOrientations[endpoint.id] = orientation; }
javascript
function (endpoint, anchorPos) { continuousAnchorLocations[endpoint.id] = [ anchorPos[0], anchorPos[1], anchorPos[2], anchorPos[3] ]; continuousAnchorOrientations[endpoint.id] = orientation; }
[ "function", "(", "endpoint", ",", "anchorPos", ")", "{", "continuousAnchorLocations", "[", "endpoint", ".", "id", "]", "=", "[", "anchorPos", "[", "0", "]", ",", "anchorPos", "[", "1", "]", ",", "anchorPos", "[", "2", "]", ",", "anchorPos", "[", "3", "]", "]", ";", "continuousAnchorOrientations", "[", "endpoint", ".", "id", "]", "=", "orientation", ";", "}" ]
takes a computed anchor position and adjusts it for parent offset and scroll, then stores it.
[ "takes", "a", "computed", "anchor", "position", "and", "adjusts", "it", "for", "parent", "offset", "and", "scroll", "then", "stores", "it", "." ]
f241ed4e645a7da0cd1a6ca86e896a5b73be53e5
https://github.com/ENOW-IJI/ENOW-console/blob/f241ed4e645a7da0cd1a6ca86e896a5b73be53e5/dist/src/anchors.js#L172-L175
51,939
vkiding/jud-previewer
build/libs/server.js
sendSocketMessage
function sendSocketMessage(message) { clients.forEach(function (client) { if (client.readyState === WebSocket.OPEN) { client.send(message || 'refresh', function (err) { if (err) { npmlog.error(err); } }); } }); }
javascript
function sendSocketMessage(message) { clients.forEach(function (client) { if (client.readyState === WebSocket.OPEN) { client.send(message || 'refresh', function (err) { if (err) { npmlog.error(err); } }); } }); }
[ "function", "sendSocketMessage", "(", "message", ")", "{", "clients", ".", "forEach", "(", "function", "(", "client", ")", "{", "if", "(", "client", ".", "readyState", "===", "WebSocket", ".", "OPEN", ")", "{", "client", ".", "send", "(", "message", "||", "'refresh'", ",", "function", "(", "err", ")", "{", "if", "(", "err", ")", "{", "npmlog", ".", "error", "(", "err", ")", ";", "}", "}", ")", ";", "}", "}", ")", ";", "}" ]
send web socket messsage to client
[ "send", "web", "socket", "messsage", "to", "client" ]
795e2b649f840e9515858332023d5238640730da
https://github.com/vkiding/jud-previewer/blob/795e2b649f840e9515858332023d5238640730da/build/libs/server.js#L100-L110
51,940
tolokoban/ToloFrameWork
ker/mod/tfw.binding.property-manager.js
getProperties
function getProperties( property ) { var properties = property[ PROPERTY_SYMBOL ]; if ( !Array.isArray( properties ) ) return null; return properties; }
javascript
function getProperties( property ) { var properties = property[ PROPERTY_SYMBOL ]; if ( !Array.isArray( properties ) ) return null; return properties; }
[ "function", "getProperties", "(", "property", ")", "{", "var", "properties", "=", "property", "[", "PROPERTY_SYMBOL", "]", ";", "if", "(", "!", "Array", ".", "isArray", "(", "properties", ")", ")", "return", "null", ";", "return", "properties", ";", "}" ]
Return the linkable properties which holds this value, or `null`.
[ "Return", "the", "linkable", "properties", "which", "holds", "this", "value", "or", "null", "." ]
730845a833a9660ebfdb60ad027ebaab5ac871b6
https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/ker/mod/tfw.binding.property-manager.js#L219-L223
51,941
tolokoban/ToloFrameWork
ker/mod/tfw.binding.property-manager.js
applyAttributesToTarget
function applyAttributesToTarget( source, target ) { var attName, attValue; for ( attName in source ) { if ( module.exports.isLinkable( target, attName ) ) { attValue = source[ attName ]; target[ attName ] = attValue; } } }
javascript
function applyAttributesToTarget( source, target ) { var attName, attValue; for ( attName in source ) { if ( module.exports.isLinkable( target, attName ) ) { attValue = source[ attName ]; target[ attName ] = attValue; } } }
[ "function", "applyAttributesToTarget", "(", "source", ",", "target", ")", "{", "var", "attName", ",", "attValue", ";", "for", "(", "attName", "in", "source", ")", "{", "if", "(", "module", ".", "exports", ".", "isLinkable", "(", "target", ",", "attName", ")", ")", "{", "attValue", "=", "source", "[", "attName", "]", ";", "target", "[", "attName", "]", "=", "attValue", ";", "}", "}", "}" ]
Copy all the attributes of `source` into `target`.
[ "Copy", "all", "the", "attributes", "of", "source", "into", "target", "." ]
730845a833a9660ebfdb60ad027ebaab5ac871b6
https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/ker/mod/tfw.binding.property-manager.js#L249-L257
51,942
tolokoban/ToloFrameWork
ker/mod/tfw.binding.property-manager.js
addPropToValue
function addPropToValue( prop, value ) { if ( value === undefined || value === null ) return; if ( value.isContentChangeAware !== true ) return; var properties = value[ PROPERTY_SYMBOL ]; if ( !Array.isArray( properties ) ) { properties = [ prop ]; } else if ( properties.indexOf( prop ) === -1 ) { properties.push( prop ); } value[ PROPERTY_SYMBOL ] = properties; }
javascript
function addPropToValue( prop, value ) { if ( value === undefined || value === null ) return; if ( value.isContentChangeAware !== true ) return; var properties = value[ PROPERTY_SYMBOL ]; if ( !Array.isArray( properties ) ) { properties = [ prop ]; } else if ( properties.indexOf( prop ) === -1 ) { properties.push( prop ); } value[ PROPERTY_SYMBOL ] = properties; }
[ "function", "addPropToValue", "(", "prop", ",", "value", ")", "{", "if", "(", "value", "===", "undefined", "||", "value", "===", "null", ")", "return", ";", "if", "(", "value", ".", "isContentChangeAware", "!==", "true", ")", "return", ";", "var", "properties", "=", "value", "[", "PROPERTY_SYMBOL", "]", ";", "if", "(", "!", "Array", ".", "isArray", "(", "properties", ")", ")", "{", "properties", "=", "[", "prop", "]", ";", "}", "else", "if", "(", "properties", ".", "indexOf", "(", "prop", ")", "===", "-", "1", ")", "{", "properties", ".", "push", "(", "prop", ")", ";", "}", "value", "[", "PROPERTY_SYMBOL", "]", "=", "properties", ";", "}" ]
Add an `info` attribute to the property's value. This is useful to find the container and the property name from the value.
[ "Add", "an", "info", "attribute", "to", "the", "property", "s", "value", ".", "This", "is", "useful", "to", "find", "the", "container", "and", "the", "property", "name", "from", "the", "value", "." ]
730845a833a9660ebfdb60ad027ebaab5ac871b6
https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/ker/mod/tfw.binding.property-manager.js#L336-L346
51,943
tolokoban/ToloFrameWork
ker/mod/tfw.binding.property-manager.js
readonly
function readonly( target, attribs ) { const attribNames = Object.keys( attribs ); attribNames.forEach( function ( attName ) { const attValue = attribs[ attName ]; if ( typeof attValue === 'function' ) { Object.defineProperty( target, attName, { set() { throw Error( `Attribute "${attName}" is read only!` ); }, get: attValue, configurable: false, enumerable: true } ); } else { Object.defineProperty( target, attName, { value: attValue, writable: false, configurable: false, enumerable: true } ); } } ); }
javascript
function readonly( target, attribs ) { const attribNames = Object.keys( attribs ); attribNames.forEach( function ( attName ) { const attValue = attribs[ attName ]; if ( typeof attValue === 'function' ) { Object.defineProperty( target, attName, { set() { throw Error( `Attribute "${attName}" is read only!` ); }, get: attValue, configurable: false, enumerable: true } ); } else { Object.defineProperty( target, attName, { value: attValue, writable: false, configurable: false, enumerable: true } ); } } ); }
[ "function", "readonly", "(", "target", ",", "attribs", ")", "{", "const", "attribNames", "=", "Object", ".", "keys", "(", "attribs", ")", ";", "attribNames", ".", "forEach", "(", "function", "(", "attName", ")", "{", "const", "attValue", "=", "attribs", "[", "attName", "]", ";", "if", "(", "typeof", "attValue", "===", "'function'", ")", "{", "Object", ".", "defineProperty", "(", "target", ",", "attName", ",", "{", "set", "(", ")", "{", "throw", "Error", "(", "`", "${", "attName", "}", "`", ")", ";", "}", ",", "get", ":", "attValue", ",", "configurable", ":", "false", ",", "enumerable", ":", "true", "}", ")", ";", "}", "else", "{", "Object", ".", "defineProperty", "(", "target", ",", "attName", ",", "{", "value", ":", "attValue", ",", "writable", ":", "false", ",", "configurable", ":", "false", ",", "enumerable", ":", "true", "}", ")", ";", "}", "}", ")", ";", "}" ]
Create a readonly attribute. @param {object} target - Object which will bear the readonly attribute. @param {object} attribs - Attributes with their values. @returns {undefined}
[ "Create", "a", "readonly", "attribute", "." ]
730845a833a9660ebfdb60ad027ebaab5ac871b6
https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/ker/mod/tfw.binding.property-manager.js#L425-L453
51,944
vkiding/judpack-common
src/FileUpdater.js
updatePathInternal
function updatePathInternal(sourcePath, targetPath, options, log) { var rootDir = (options && options.rootDir) || ""; var targetFullPath = path.join(rootDir, targetPath); var targetStats = fs.existsSync(targetFullPath) ? fs.statSync(targetFullPath) : null; var sourceStats = null; if (sourcePath) { // A non-null source path was specified. It should exist. var sourceFullPath = path.join(rootDir, sourcePath); if (!fs.existsSync(sourceFullPath)) { throw new Error("Source path does not exist: " + sourcePath); } sourceStats = fs.statSync(sourceFullPath); // Create the target's parent directory if it doesn't exist. var parentDir = path.dirname(targetFullPath); if (!fs.existsSync(parentDir)) { shell.mkdir("-p", parentDir); } } return updatePathWithStats(sourcePath, sourceStats, targetPath, targetStats, options, log); }
javascript
function updatePathInternal(sourcePath, targetPath, options, log) { var rootDir = (options && options.rootDir) || ""; var targetFullPath = path.join(rootDir, targetPath); var targetStats = fs.existsSync(targetFullPath) ? fs.statSync(targetFullPath) : null; var sourceStats = null; if (sourcePath) { // A non-null source path was specified. It should exist. var sourceFullPath = path.join(rootDir, sourcePath); if (!fs.existsSync(sourceFullPath)) { throw new Error("Source path does not exist: " + sourcePath); } sourceStats = fs.statSync(sourceFullPath); // Create the target's parent directory if it doesn't exist. var parentDir = path.dirname(targetFullPath); if (!fs.existsSync(parentDir)) { shell.mkdir("-p", parentDir); } } return updatePathWithStats(sourcePath, sourceStats, targetPath, targetStats, options, log); }
[ "function", "updatePathInternal", "(", "sourcePath", ",", "targetPath", ",", "options", ",", "log", ")", "{", "var", "rootDir", "=", "(", "options", "&&", "options", ".", "rootDir", ")", "||", "\"\"", ";", "var", "targetFullPath", "=", "path", ".", "join", "(", "rootDir", ",", "targetPath", ")", ";", "var", "targetStats", "=", "fs", ".", "existsSync", "(", "targetFullPath", ")", "?", "fs", ".", "statSync", "(", "targetFullPath", ")", ":", "null", ";", "var", "sourceStats", "=", "null", ";", "if", "(", "sourcePath", ")", "{", "// A non-null source path was specified. It should exist.", "var", "sourceFullPath", "=", "path", ".", "join", "(", "rootDir", ",", "sourcePath", ")", ";", "if", "(", "!", "fs", ".", "existsSync", "(", "sourceFullPath", ")", ")", "{", "throw", "new", "Error", "(", "\"Source path does not exist: \"", "+", "sourcePath", ")", ";", "}", "sourceStats", "=", "fs", ".", "statSync", "(", "sourceFullPath", ")", ";", "// Create the target's parent directory if it doesn't exist.", "var", "parentDir", "=", "path", ".", "dirname", "(", "targetFullPath", ")", ";", "if", "(", "!", "fs", ".", "existsSync", "(", "parentDir", ")", ")", "{", "shell", ".", "mkdir", "(", "\"-p\"", ",", "parentDir", ")", ";", "}", "}", "return", "updatePathWithStats", "(", "sourcePath", ",", "sourceStats", ",", "targetPath", ",", "targetStats", ",", "options", ",", "log", ")", ";", "}" ]
Helper for updatePath and updatePaths functions. Queries stats for source and target and ensures target directory exists before copying a file.
[ "Helper", "for", "updatePath", "and", "updatePaths", "functions", ".", "Queries", "stats", "for", "source", "and", "target", "and", "ensures", "target", "directory", "exists", "before", "copying", "a", "file", "." ]
5b87d3f1cb10c2c867243e3a692d39b4bb189dd4
https://github.com/vkiding/judpack-common/blob/5b87d3f1cb10c2c867243e3a692d39b4bb189dd4/src/FileUpdater.js#L135-L158
51,945
vkiding/judpack-common
src/FileUpdater.js
updatePaths
function updatePaths(pathMap, options, log) { if (!pathMap || typeof pathMap !== "object" || Array.isArray(pathMap)) { throw new Error("An object mapping from target paths to source paths is required."); } log = log || function(message) { }; var updated = false; // Iterate in sorted order to ensure directories are created before files under them. Object.keys(pathMap).sort().forEach(function (targetPath) { var sourcePath = pathMap[targetPath]; updated = updatePathInternal(sourcePath, targetPath, options, log) || updated; }); return updated; }
javascript
function updatePaths(pathMap, options, log) { if (!pathMap || typeof pathMap !== "object" || Array.isArray(pathMap)) { throw new Error("An object mapping from target paths to source paths is required."); } log = log || function(message) { }; var updated = false; // Iterate in sorted order to ensure directories are created before files under them. Object.keys(pathMap).sort().forEach(function (targetPath) { var sourcePath = pathMap[targetPath]; updated = updatePathInternal(sourcePath, targetPath, options, log) || updated; }); return updated; }
[ "function", "updatePaths", "(", "pathMap", ",", "options", ",", "log", ")", "{", "if", "(", "!", "pathMap", "||", "typeof", "pathMap", "!==", "\"object\"", "||", "Array", ".", "isArray", "(", "pathMap", ")", ")", "{", "throw", "new", "Error", "(", "\"An object mapping from target paths to source paths is required.\"", ")", ";", "}", "log", "=", "log", "||", "function", "(", "message", ")", "{", "}", ";", "var", "updated", "=", "false", ";", "// Iterate in sorted order to ensure directories are created before files under them.", "Object", ".", "keys", "(", "pathMap", ")", ".", "sort", "(", ")", ".", "forEach", "(", "function", "(", "targetPath", ")", "{", "var", "sourcePath", "=", "pathMap", "[", "targetPath", "]", ";", "updated", "=", "updatePathInternal", "(", "sourcePath", ",", "targetPath", ",", "options", ",", "log", ")", "||", "updated", ";", "}", ")", ";", "return", "updated", ";", "}" ]
Updates files and directories based on a mapping from target paths to source paths. Targets with null sources in the map are deleted. @param {Object} pathMap A dictionary mapping from target paths to source paths. @param {Object} [options] Optional additional parameters for the update. @param {string} [options.rootDir] Optional root directory (such as a project) to which target and source path parameters are relative; may be omitted if the paths are absolute. The rootDir is always omitted from any logged paths, to make the logs easier to read. @param {boolean} [options.all] If true, all files are copied regardless of last-modified times. Otherwise, a file is copied if the source's last-modified time is greather than or equal to the target's last-modified time, or if the file sizes are different. @param {loggingCallback} [log] Optional logging callback that takes a string message describing any file operations that are performed. @return {boolean} true if any changes were made, or false if the force flag is not set and everything was up to date
[ "Updates", "files", "and", "directories", "based", "on", "a", "mapping", "from", "target", "paths", "to", "source", "paths", ".", "Targets", "with", "null", "sources", "in", "the", "map", "are", "deleted", "." ]
5b87d3f1cb10c2c867243e3a692d39b4bb189dd4
https://github.com/vkiding/judpack-common/blob/5b87d3f1cb10c2c867243e3a692d39b4bb189dd4/src/FileUpdater.js#L211-L227
51,946
vkiding/judpack-common
src/FileUpdater.js
mergeAndUpdateDir
function mergeAndUpdateDir(sourceDirs, targetDir, options, log) { if (sourceDirs && typeof sourceDirs === "string") { sourceDirs = [ sourceDirs ]; } else if (!Array.isArray(sourceDirs)) { throw new Error("A source directory path or array of paths is required."); } if (!targetDir || typeof targetDir !== "string") { throw new Error("A target directory path is required."); } log = log || function(message) { }; var rootDir = (options && options.rootDir) || ""; var include = (options && options.include) || [ "**" ]; if (typeof include === "string") { include = [ include ]; } else if (!Array.isArray(include)) { throw new Error("Include parameter must be a glob string or array of glob strings."); } var exclude = (options && options.exclude) || []; if (typeof exclude === "string") { exclude = [ exclude ]; } else if (!Array.isArray(exclude)) { throw new Error("Exclude parameter must be a glob string or array of glob strings."); } // Scan the files in each of the source directories. var sourceMaps = sourceDirs.map(function (sourceDir) { return path.join(rootDir, sourceDir); }).map(function (sourcePath) { if (!fs.existsSync(sourcePath)) { throw new Error("Source directory does not exist: " + sourcePath); } return mapDirectory(rootDir, path.relative(rootDir, sourcePath), include, exclude); }); // Scan the files in the target directory, if it exists. var targetMap = {}; var targetFullPath = path.join(rootDir, targetDir); if (fs.existsSync(targetFullPath)) { targetMap = mapDirectory(rootDir, targetDir, include, exclude); } var pathMap = mergePathMaps(sourceMaps, targetMap, targetDir); var updated = false; // Iterate in sorted order to ensure directories are created before files under them. Object.keys(pathMap).sort().forEach(function (subPath) { var entry = pathMap[subPath]; updated = updatePathWithStats( entry.sourcePath, entry.sourceStats, entry.targetPath, entry.targetStats, options, log) || updated; }); return updated; }
javascript
function mergeAndUpdateDir(sourceDirs, targetDir, options, log) { if (sourceDirs && typeof sourceDirs === "string") { sourceDirs = [ sourceDirs ]; } else if (!Array.isArray(sourceDirs)) { throw new Error("A source directory path or array of paths is required."); } if (!targetDir || typeof targetDir !== "string") { throw new Error("A target directory path is required."); } log = log || function(message) { }; var rootDir = (options && options.rootDir) || ""; var include = (options && options.include) || [ "**" ]; if (typeof include === "string") { include = [ include ]; } else if (!Array.isArray(include)) { throw new Error("Include parameter must be a glob string or array of glob strings."); } var exclude = (options && options.exclude) || []; if (typeof exclude === "string") { exclude = [ exclude ]; } else if (!Array.isArray(exclude)) { throw new Error("Exclude parameter must be a glob string or array of glob strings."); } // Scan the files in each of the source directories. var sourceMaps = sourceDirs.map(function (sourceDir) { return path.join(rootDir, sourceDir); }).map(function (sourcePath) { if (!fs.existsSync(sourcePath)) { throw new Error("Source directory does not exist: " + sourcePath); } return mapDirectory(rootDir, path.relative(rootDir, sourcePath), include, exclude); }); // Scan the files in the target directory, if it exists. var targetMap = {}; var targetFullPath = path.join(rootDir, targetDir); if (fs.existsSync(targetFullPath)) { targetMap = mapDirectory(rootDir, targetDir, include, exclude); } var pathMap = mergePathMaps(sourceMaps, targetMap, targetDir); var updated = false; // Iterate in sorted order to ensure directories are created before files under them. Object.keys(pathMap).sort().forEach(function (subPath) { var entry = pathMap[subPath]; updated = updatePathWithStats( entry.sourcePath, entry.sourceStats, entry.targetPath, entry.targetStats, options, log) || updated; }); return updated; }
[ "function", "mergeAndUpdateDir", "(", "sourceDirs", ",", "targetDir", ",", "options", ",", "log", ")", "{", "if", "(", "sourceDirs", "&&", "typeof", "sourceDirs", "===", "\"string\"", ")", "{", "sourceDirs", "=", "[", "sourceDirs", "]", ";", "}", "else", "if", "(", "!", "Array", ".", "isArray", "(", "sourceDirs", ")", ")", "{", "throw", "new", "Error", "(", "\"A source directory path or array of paths is required.\"", ")", ";", "}", "if", "(", "!", "targetDir", "||", "typeof", "targetDir", "!==", "\"string\"", ")", "{", "throw", "new", "Error", "(", "\"A target directory path is required.\"", ")", ";", "}", "log", "=", "log", "||", "function", "(", "message", ")", "{", "}", ";", "var", "rootDir", "=", "(", "options", "&&", "options", ".", "rootDir", ")", "||", "\"\"", ";", "var", "include", "=", "(", "options", "&&", "options", ".", "include", ")", "||", "[", "\"**\"", "]", ";", "if", "(", "typeof", "include", "===", "\"string\"", ")", "{", "include", "=", "[", "include", "]", ";", "}", "else", "if", "(", "!", "Array", ".", "isArray", "(", "include", ")", ")", "{", "throw", "new", "Error", "(", "\"Include parameter must be a glob string or array of glob strings.\"", ")", ";", "}", "var", "exclude", "=", "(", "options", "&&", "options", ".", "exclude", ")", "||", "[", "]", ";", "if", "(", "typeof", "exclude", "===", "\"string\"", ")", "{", "exclude", "=", "[", "exclude", "]", ";", "}", "else", "if", "(", "!", "Array", ".", "isArray", "(", "exclude", ")", ")", "{", "throw", "new", "Error", "(", "\"Exclude parameter must be a glob string or array of glob strings.\"", ")", ";", "}", "// Scan the files in each of the source directories.", "var", "sourceMaps", "=", "sourceDirs", ".", "map", "(", "function", "(", "sourceDir", ")", "{", "return", "path", ".", "join", "(", "rootDir", ",", "sourceDir", ")", ";", "}", ")", ".", "map", "(", "function", "(", "sourcePath", ")", "{", "if", "(", "!", "fs", ".", "existsSync", "(", "sourcePath", ")", ")", "{", "throw", "new", "Error", "(", "\"Source directory does not exist: \"", "+", "sourcePath", ")", ";", "}", "return", "mapDirectory", "(", "rootDir", ",", "path", ".", "relative", "(", "rootDir", ",", "sourcePath", ")", ",", "include", ",", "exclude", ")", ";", "}", ")", ";", "// Scan the files in the target directory, if it exists.", "var", "targetMap", "=", "{", "}", ";", "var", "targetFullPath", "=", "path", ".", "join", "(", "rootDir", ",", "targetDir", ")", ";", "if", "(", "fs", ".", "existsSync", "(", "targetFullPath", ")", ")", "{", "targetMap", "=", "mapDirectory", "(", "rootDir", ",", "targetDir", ",", "include", ",", "exclude", ")", ";", "}", "var", "pathMap", "=", "mergePathMaps", "(", "sourceMaps", ",", "targetMap", ",", "targetDir", ")", ";", "var", "updated", "=", "false", ";", "// Iterate in sorted order to ensure directories are created before files under them.", "Object", ".", "keys", "(", "pathMap", ")", ".", "sort", "(", ")", ".", "forEach", "(", "function", "(", "subPath", ")", "{", "var", "entry", "=", "pathMap", "[", "subPath", "]", ";", "updated", "=", "updatePathWithStats", "(", "entry", ".", "sourcePath", ",", "entry", ".", "sourceStats", ",", "entry", ".", "targetPath", ",", "entry", ".", "targetStats", ",", "options", ",", "log", ")", "||", "updated", ";", "}", ")", ";", "return", "updated", ";", "}" ]
Updates a target directory with merged files and subdirectories from source directories. @param {string|string[]} sourceDirs Required source directory or array of source directories to be merged into the target. The directories are listed in order of precedence; files in directories later in the array supersede files in directories earlier in the array (regardless of timestamps). @param {string} targetDir Required destination directory to be updated. If it does not exist, it will be created. If it exists, newer files from source directories will be copied over, and files missing in the source directories will be deleted. @param {Object} [options] Optional additional parameters for the update. @param {string} [options.rootDir] Optional root directory (such as a project) to which target and source path parameters are relative; may be omitted if the paths are absolute. The rootDir is always omitted from any logged paths, to make the logs easier to read. @param {boolean} [options.all] If true, all files are copied regardless of last-modified times. Otherwise, a file is copied if the source's last-modified time is greather than or equal to the target's last-modified time, or if the file sizes are different. @param {string|string[]} [options.include] Optional glob string or array of glob strings that are tested against both target and source relative paths to determine if they are included in the merge-and-update. If unspecified, all items are included. @param {string|string[]} [options.exclude] Optional glob string or array of glob strings that are tested against both target and source relative paths to determine if they are excluded from the merge-and-update. Exclusions override inclusions. If unspecified, no items are excluded. @param {loggingCallback} [log] Optional logging callback that takes a string message describing any file operations that are performed. @return {boolean} true if any changes were made, or false if the force flag is not set and everything was up to date
[ "Updates", "a", "target", "directory", "with", "merged", "files", "and", "subdirectories", "from", "source", "directories", "." ]
5b87d3f1cb10c2c867243e3a692d39b4bb189dd4
https://github.com/vkiding/judpack-common/blob/5b87d3f1cb10c2c867243e3a692d39b4bb189dd4/src/FileUpdater.js#L258-L321
51,947
vkiding/judpack-common
src/FileUpdater.js
mapDirectory
function mapDirectory(rootDir, subDir, include, exclude) { var dirMap = { "": { subDir: subDir, stats: fs.statSync(path.join(rootDir, subDir)) } }; mapSubdirectory(rootDir, subDir, "", include, exclude, dirMap); return dirMap; function mapSubdirectory(rootDir, subDir, relativeDir, include, exclude, dirMap) { var itemMapped = false; var items = fs.readdirSync(path.join(rootDir, subDir, relativeDir)); items.forEach(function(item) { var relativePath = path.join(relativeDir, item); if(!matchGlobArray(relativePath, exclude)) { // Stats obtained here (required at least to know where to recurse in directories) // are saved for later, where the modified times may also be used. This minimizes // the number of file I/O operations performed. var fullPath = path.join(rootDir, subDir, relativePath); var stats = fs.statSync(fullPath); if (stats.isDirectory()) { // Directories are included if either something under them is included or they // match an include glob. if (mapSubdirectory(rootDir, subDir, relativePath, include, exclude, dirMap) || matchGlobArray(relativePath, include)) { dirMap[relativePath] = { subDir: subDir, stats: stats }; itemMapped = true; } } else if (stats.isFile()) { // Files are included only if they match an include glob. if (matchGlobArray(relativePath, include)) { dirMap[relativePath] = { subDir: subDir, stats: stats }; itemMapped = true; } } } }); return itemMapped; } function matchGlobArray(path, globs) { return globs.some(function(elem) { return minimatch(path, elem, {dot:true}); }); } }
javascript
function mapDirectory(rootDir, subDir, include, exclude) { var dirMap = { "": { subDir: subDir, stats: fs.statSync(path.join(rootDir, subDir)) } }; mapSubdirectory(rootDir, subDir, "", include, exclude, dirMap); return dirMap; function mapSubdirectory(rootDir, subDir, relativeDir, include, exclude, dirMap) { var itemMapped = false; var items = fs.readdirSync(path.join(rootDir, subDir, relativeDir)); items.forEach(function(item) { var relativePath = path.join(relativeDir, item); if(!matchGlobArray(relativePath, exclude)) { // Stats obtained here (required at least to know where to recurse in directories) // are saved for later, where the modified times may also be used. This minimizes // the number of file I/O operations performed. var fullPath = path.join(rootDir, subDir, relativePath); var stats = fs.statSync(fullPath); if (stats.isDirectory()) { // Directories are included if either something under them is included or they // match an include glob. if (mapSubdirectory(rootDir, subDir, relativePath, include, exclude, dirMap) || matchGlobArray(relativePath, include)) { dirMap[relativePath] = { subDir: subDir, stats: stats }; itemMapped = true; } } else if (stats.isFile()) { // Files are included only if they match an include glob. if (matchGlobArray(relativePath, include)) { dirMap[relativePath] = { subDir: subDir, stats: stats }; itemMapped = true; } } } }); return itemMapped; } function matchGlobArray(path, globs) { return globs.some(function(elem) { return minimatch(path, elem, {dot:true}); }); } }
[ "function", "mapDirectory", "(", "rootDir", ",", "subDir", ",", "include", ",", "exclude", ")", "{", "var", "dirMap", "=", "{", "\"\"", ":", "{", "subDir", ":", "subDir", ",", "stats", ":", "fs", ".", "statSync", "(", "path", ".", "join", "(", "rootDir", ",", "subDir", ")", ")", "}", "}", ";", "mapSubdirectory", "(", "rootDir", ",", "subDir", ",", "\"\"", ",", "include", ",", "exclude", ",", "dirMap", ")", ";", "return", "dirMap", ";", "function", "mapSubdirectory", "(", "rootDir", ",", "subDir", ",", "relativeDir", ",", "include", ",", "exclude", ",", "dirMap", ")", "{", "var", "itemMapped", "=", "false", ";", "var", "items", "=", "fs", ".", "readdirSync", "(", "path", ".", "join", "(", "rootDir", ",", "subDir", ",", "relativeDir", ")", ")", ";", "items", ".", "forEach", "(", "function", "(", "item", ")", "{", "var", "relativePath", "=", "path", ".", "join", "(", "relativeDir", ",", "item", ")", ";", "if", "(", "!", "matchGlobArray", "(", "relativePath", ",", "exclude", ")", ")", "{", "// Stats obtained here (required at least to know where to recurse in directories)", "// are saved for later, where the modified times may also be used. This minimizes", "// the number of file I/O operations performed.", "var", "fullPath", "=", "path", ".", "join", "(", "rootDir", ",", "subDir", ",", "relativePath", ")", ";", "var", "stats", "=", "fs", ".", "statSync", "(", "fullPath", ")", ";", "if", "(", "stats", ".", "isDirectory", "(", ")", ")", "{", "// Directories are included if either something under them is included or they", "// match an include glob.", "if", "(", "mapSubdirectory", "(", "rootDir", ",", "subDir", ",", "relativePath", ",", "include", ",", "exclude", ",", "dirMap", ")", "||", "matchGlobArray", "(", "relativePath", ",", "include", ")", ")", "{", "dirMap", "[", "relativePath", "]", "=", "{", "subDir", ":", "subDir", ",", "stats", ":", "stats", "}", ";", "itemMapped", "=", "true", ";", "}", "}", "else", "if", "(", "stats", ".", "isFile", "(", ")", ")", "{", "// Files are included only if they match an include glob.", "if", "(", "matchGlobArray", "(", "relativePath", ",", "include", ")", ")", "{", "dirMap", "[", "relativePath", "]", "=", "{", "subDir", ":", "subDir", ",", "stats", ":", "stats", "}", ";", "itemMapped", "=", "true", ";", "}", "}", "}", "}", ")", ";", "return", "itemMapped", ";", "}", "function", "matchGlobArray", "(", "path", ",", "globs", ")", "{", "return", "globs", ".", "some", "(", "function", "(", "elem", ")", "{", "return", "minimatch", "(", "path", ",", "elem", ",", "{", "dot", ":", "true", "}", ")", ";", "}", ")", ";", "}", "}" ]
Creates a dictionary map of all files and directories under a path.
[ "Creates", "a", "dictionary", "map", "of", "all", "files", "and", "directories", "under", "a", "path", "." ]
5b87d3f1cb10c2c867243e3a692d39b4bb189dd4
https://github.com/vkiding/judpack-common/blob/5b87d3f1cb10c2c867243e3a692d39b4bb189dd4/src/FileUpdater.js#L326-L369
51,948
vkiding/judpack-common
src/FileUpdater.js
mergePathMaps
function mergePathMaps(sourceMaps, targetMap, targetDir) { // Merge multiple source maps together, along with target path info. // Entries in later source maps override those in earlier source maps. // Target stats will be filled in below for targets that exist. var pathMap = {}; sourceMaps.forEach(function (sourceMap) { Object.keys(sourceMap).forEach(function(sourceSubPath){ var sourceEntry = sourceMap[sourceSubPath]; pathMap[sourceSubPath] = { targetPath: path.join(targetDir, sourceSubPath), targetStats: null, sourcePath: path.join(sourceEntry.subDir, sourceSubPath), sourceStats: sourceEntry.stats }; }); }); // Fill in target stats for targets that exist, and create entries // for targets that don't have any corresponding sources. Object.keys(targetMap).forEach(function(subPath){ var entry = pathMap[subPath]; if (entry) { entry.targetStats = targetMap[subPath].stats; } else { pathMap[subPath] = { targetPath: path.join(targetDir, subPath), targetStats: targetMap[subPath].stats, sourcePath: null, sourceStats: null }; } }); return pathMap; }
javascript
function mergePathMaps(sourceMaps, targetMap, targetDir) { // Merge multiple source maps together, along with target path info. // Entries in later source maps override those in earlier source maps. // Target stats will be filled in below for targets that exist. var pathMap = {}; sourceMaps.forEach(function (sourceMap) { Object.keys(sourceMap).forEach(function(sourceSubPath){ var sourceEntry = sourceMap[sourceSubPath]; pathMap[sourceSubPath] = { targetPath: path.join(targetDir, sourceSubPath), targetStats: null, sourcePath: path.join(sourceEntry.subDir, sourceSubPath), sourceStats: sourceEntry.stats }; }); }); // Fill in target stats for targets that exist, and create entries // for targets that don't have any corresponding sources. Object.keys(targetMap).forEach(function(subPath){ var entry = pathMap[subPath]; if (entry) { entry.targetStats = targetMap[subPath].stats; } else { pathMap[subPath] = { targetPath: path.join(targetDir, subPath), targetStats: targetMap[subPath].stats, sourcePath: null, sourceStats: null }; } }); return pathMap; }
[ "function", "mergePathMaps", "(", "sourceMaps", ",", "targetMap", ",", "targetDir", ")", "{", "// Merge multiple source maps together, along with target path info.", "// Entries in later source maps override those in earlier source maps.", "// Target stats will be filled in below for targets that exist.", "var", "pathMap", "=", "{", "}", ";", "sourceMaps", ".", "forEach", "(", "function", "(", "sourceMap", ")", "{", "Object", ".", "keys", "(", "sourceMap", ")", ".", "forEach", "(", "function", "(", "sourceSubPath", ")", "{", "var", "sourceEntry", "=", "sourceMap", "[", "sourceSubPath", "]", ";", "pathMap", "[", "sourceSubPath", "]", "=", "{", "targetPath", ":", "path", ".", "join", "(", "targetDir", ",", "sourceSubPath", ")", ",", "targetStats", ":", "null", ",", "sourcePath", ":", "path", ".", "join", "(", "sourceEntry", ".", "subDir", ",", "sourceSubPath", ")", ",", "sourceStats", ":", "sourceEntry", ".", "stats", "}", ";", "}", ")", ";", "}", ")", ";", "// Fill in target stats for targets that exist, and create entries", "// for targets that don't have any corresponding sources.", "Object", ".", "keys", "(", "targetMap", ")", ".", "forEach", "(", "function", "(", "subPath", ")", "{", "var", "entry", "=", "pathMap", "[", "subPath", "]", ";", "if", "(", "entry", ")", "{", "entry", ".", "targetStats", "=", "targetMap", "[", "subPath", "]", ".", "stats", ";", "}", "else", "{", "pathMap", "[", "subPath", "]", "=", "{", "targetPath", ":", "path", ".", "join", "(", "targetDir", ",", "subPath", ")", ",", "targetStats", ":", "targetMap", "[", "subPath", "]", ".", "stats", ",", "sourcePath", ":", "null", ",", "sourceStats", ":", "null", "}", ";", "}", "}", ")", ";", "return", "pathMap", ";", "}" ]
Merges together multiple source maps and a target map into a single mapping from relative paths to objects with target and source paths and stats.
[ "Merges", "together", "multiple", "source", "maps", "and", "a", "target", "map", "into", "a", "single", "mapping", "from", "relative", "paths", "to", "objects", "with", "target", "and", "source", "paths", "and", "stats", "." ]
5b87d3f1cb10c2c867243e3a692d39b4bb189dd4
https://github.com/vkiding/judpack-common/blob/5b87d3f1cb10c2c867243e3a692d39b4bb189dd4/src/FileUpdater.js#L375-L409
51,949
nivesh2/dotenv-minimal
index.js
readFromEnvFile
function readFromEnvFile() { try { // .env file should be in root directory const data = require('fs').readFileSync(require('path').join(__dirname, '../../.env'), 'utf8') const env = {} data.split('\n').filter((v) => { return v !== '' }).filter((v) => { return v.indexOf('#') === -1 }).forEach((v) => { const splitPosition = v.indexOf('=') if (splitPosition === -1) { return } // only first '=' will be splitted const key = v.slice(0, splitPosition).trim() const value = v.slice(splitPosition + 1).trim() env[key] = value }) return env } catch (err) { throw err } }
javascript
function readFromEnvFile() { try { // .env file should be in root directory const data = require('fs').readFileSync(require('path').join(__dirname, '../../.env'), 'utf8') const env = {} data.split('\n').filter((v) => { return v !== '' }).filter((v) => { return v.indexOf('#') === -1 }).forEach((v) => { const splitPosition = v.indexOf('=') if (splitPosition === -1) { return } // only first '=' will be splitted const key = v.slice(0, splitPosition).trim() const value = v.slice(splitPosition + 1).trim() env[key] = value }) return env } catch (err) { throw err } }
[ "function", "readFromEnvFile", "(", ")", "{", "try", "{", "// .env file should be in root directory", "const", "data", "=", "require", "(", "'fs'", ")", ".", "readFileSync", "(", "require", "(", "'path'", ")", ".", "join", "(", "__dirname", ",", "'../../.env'", ")", ",", "'utf8'", ")", "const", "env", "=", "{", "}", "data", ".", "split", "(", "'\\n'", ")", ".", "filter", "(", "(", "v", ")", "=>", "{", "return", "v", "!==", "''", "}", ")", ".", "filter", "(", "(", "v", ")", "=>", "{", "return", "v", ".", "indexOf", "(", "'#'", ")", "===", "-", "1", "}", ")", ".", "forEach", "(", "(", "v", ")", "=>", "{", "const", "splitPosition", "=", "v", ".", "indexOf", "(", "'='", ")", "if", "(", "splitPosition", "===", "-", "1", ")", "{", "return", "}", "// only first '=' will be splitted", "const", "key", "=", "v", ".", "slice", "(", "0", ",", "splitPosition", ")", ".", "trim", "(", ")", "const", "value", "=", "v", ".", "slice", "(", "splitPosition", "+", "1", ")", ".", "trim", "(", ")", "env", "[", "key", "]", "=", "value", "}", ")", "return", "env", "}", "catch", "(", "err", ")", "{", "throw", "err", "}", "}" ]
Loads environment variables from .env file check for the missing environment variables at start throw exception if .env file doesnot exist @returns env
[ "Loads", "environment", "variables", "from", ".", "env", "file", "check", "for", "the", "missing", "environment", "variables", "at", "start", "throw", "exception", "if", ".", "env", "file", "doesnot", "exist" ]
d93f09a579cd890edb9c37881f6fec6de18c023f
https://github.com/nivesh2/dotenv-minimal/blob/d93f09a579cd890edb9c37881f6fec6de18c023f/index.js#L7-L31
51,950
nivesh2/dotenv-minimal
index.js
splitMultipleValues
function splitMultipleValues(envObject) { try { const data = Object.keys(envObject) return data.reduce((p, v) => { p[v] = envObject[v] if (envObject[v].indexOf(',') !== -1) { p[v] = envObject[v].split(',') } return p }, {}) } catch (err) { throw err } }
javascript
function splitMultipleValues(envObject) { try { const data = Object.keys(envObject) return data.reduce((p, v) => { p[v] = envObject[v] if (envObject[v].indexOf(',') !== -1) { p[v] = envObject[v].split(',') } return p }, {}) } catch (err) { throw err } }
[ "function", "splitMultipleValues", "(", "envObject", ")", "{", "try", "{", "const", "data", "=", "Object", ".", "keys", "(", "envObject", ")", "return", "data", ".", "reduce", "(", "(", "p", ",", "v", ")", "=>", "{", "p", "[", "v", "]", "=", "envObject", "[", "v", "]", "if", "(", "envObject", "[", "v", "]", ".", "indexOf", "(", "','", ")", "!==", "-", "1", ")", "{", "p", "[", "v", "]", "=", "envObject", "[", "v", "]", ".", "split", "(", "','", ")", "}", "return", "p", "}", ",", "{", "}", ")", "}", "catch", "(", "err", ")", "{", "throw", "err", "}", "}" ]
it only supports spilitting using comma
[ "it", "only", "supports", "spilitting", "using", "comma" ]
d93f09a579cd890edb9c37881f6fec6de18c023f
https://github.com/nivesh2/dotenv-minimal/blob/d93f09a579cd890edb9c37881f6fec6de18c023f/index.js#L34-L47
51,951
Digznav/bilberry
promise-read-file.js
promiseReadFile
function promiseReadFile(path, encoding = 'utf-8') { return new Promise((resolve, reject) => { fs.readFile(path, encoding, (err, content) => { if (err) reject(err); resolve({ path, fileName: path.split('/').pop(), content }); }); }); }
javascript
function promiseReadFile(path, encoding = 'utf-8') { return new Promise((resolve, reject) => { fs.readFile(path, encoding, (err, content) => { if (err) reject(err); resolve({ path, fileName: path.split('/').pop(), content }); }); }); }
[ "function", "promiseReadFile", "(", "path", ",", "encoding", "=", "'utf-8'", ")", "{", "return", "new", "Promise", "(", "(", "resolve", ",", "reject", ")", "=>", "{", "fs", ".", "readFile", "(", "path", ",", "encoding", ",", "(", "err", ",", "content", ")", "=>", "{", "if", "(", "err", ")", "reject", "(", "err", ")", ";", "resolve", "(", "{", "path", ",", "fileName", ":", "path", ".", "split", "(", "'/'", ")", ".", "pop", "(", ")", ",", "content", "}", ")", ";", "}", ")", ";", "}", ")", ";", "}" ]
Get the content of a single file. @param {string} path Path to file. @param {string} encoding Encoding. @return {promise} Promise to get the content.
[ "Get", "the", "content", "of", "a", "single", "file", "." ]
ef6db49de6c8b0d2f4f9d3e10e8a8153e39ffcc4
https://github.com/Digznav/bilberry/blob/ef6db49de6c8b0d2f4f9d3e10e8a8153e39ffcc4/promise-read-file.js#L9-L21
51,952
woyorus/syncsocket-client
src/connection.js
Connection
function Connection(uri) { this.channels = {}; let version = require('../package.json').version; let opts = { query: 'instanceId=' + 'js_cli_' + version, 'sync disconnect on unload': true, path: '/syncsocket' }; this.socket = io.connect(uri, opts); this.bindEvents(); }
javascript
function Connection(uri) { this.channels = {}; let version = require('../package.json').version; let opts = { query: 'instanceId=' + 'js_cli_' + version, 'sync disconnect on unload': true, path: '/syncsocket' }; this.socket = io.connect(uri, opts); this.bindEvents(); }
[ "function", "Connection", "(", "uri", ")", "{", "this", ".", "channels", "=", "{", "}", ";", "let", "version", "=", "require", "(", "'../package.json'", ")", ".", "version", ";", "let", "opts", "=", "{", "query", ":", "'instanceId='", "+", "'js_cli_'", "+", "version", ",", "'sync disconnect on unload'", ":", "true", ",", "path", ":", "'/syncsocket'", "}", ";", "this", ".", "socket", "=", "io", ".", "connect", "(", "uri", ",", "opts", ")", ";", "this", ".", "bindEvents", "(", ")", ";", "}" ]
Creates new `Connection` object @param uri URI of SyncSocket server (e.g. http://localhost:5579) @constructor @public
[ "Creates", "new", "Connection", "object" ]
3bd023ce3611afd0e19a8234ce9731413bcfc890
https://github.com/woyorus/syncsocket-client/blob/3bd023ce3611afd0e19a8234ce9731413bcfc890/src/connection.js#L17-L27
51,953
insistime/qiao.util.file
lib/qiao.util.file.js
getFoldersAndFiles
function getFoldersAndFiles(fpath, folders, files){ fs.readdirSync(fpath).forEach(function(name){ var stat = fs.statSync(fpath + name); if(stat.isDirectory()){ folders.push({ path : fpath, name : name }); getFoldersAndFiles(fpath + name + '/', folders, files); }else{ files.push({ path : fpath, name : name }); } }); }
javascript
function getFoldersAndFiles(fpath, folders, files){ fs.readdirSync(fpath).forEach(function(name){ var stat = fs.statSync(fpath + name); if(stat.isDirectory()){ folders.push({ path : fpath, name : name }); getFoldersAndFiles(fpath + name + '/', folders, files); }else{ files.push({ path : fpath, name : name }); } }); }
[ "function", "getFoldersAndFiles", "(", "fpath", ",", "folders", ",", "files", ")", "{", "fs", ".", "readdirSync", "(", "fpath", ")", ".", "forEach", "(", "function", "(", "name", ")", "{", "var", "stat", "=", "fs", ".", "statSync", "(", "fpath", "+", "name", ")", ";", "if", "(", "stat", ".", "isDirectory", "(", ")", ")", "{", "folders", ".", "push", "(", "{", "path", ":", "fpath", ",", "name", ":", "name", "}", ")", ";", "getFoldersAndFiles", "(", "fpath", "+", "name", "+", "'/'", ",", "folders", ",", "files", ")", ";", "}", "else", "{", "files", ".", "push", "(", "{", "path", ":", "fpath", ",", "name", ":", "name", "}", ")", ";", "}", "}", ")", ";", "}" ]
get folders and files
[ "get", "folders", "and", "files" ]
b359226cfcbb8db9a07153f27c5303b00d01640f
https://github.com/insistime/qiao.util.file/blob/b359226cfcbb8db9a07153f27c5303b00d01640f/lib/qiao.util.file.js#L109-L126
51,954
redisjs/jsr-resp
lib/decoder.js
Decoder
function Decoder(options) { options = options || {}; Transform.call(this, {}); this._reset(); // maximum length for bulk strings (512MB) this.maxlen = options.maxlen || 536870912; // create String instances for simple string replies this.simple = options.simple !== undefined ? options.simple : false; // return buffers for bulk strings this.buffers = options.return_buffers || options.buffers; // pass RESP messasges untouched this.raw = options.raw !== undefined ? options.raw : false; /* istanbul ignore next: optional dependency */ if(hiredis) { this.reader = new hiredis.Reader({return_buffers: this.buffers}); } }
javascript
function Decoder(options) { options = options || {}; Transform.call(this, {}); this._reset(); // maximum length for bulk strings (512MB) this.maxlen = options.maxlen || 536870912; // create String instances for simple string replies this.simple = options.simple !== undefined ? options.simple : false; // return buffers for bulk strings this.buffers = options.return_buffers || options.buffers; // pass RESP messasges untouched this.raw = options.raw !== undefined ? options.raw : false; /* istanbul ignore next: optional dependency */ if(hiredis) { this.reader = new hiredis.Reader({return_buffers: this.buffers}); } }
[ "function", "Decoder", "(", "options", ")", "{", "options", "=", "options", "||", "{", "}", ";", "Transform", ".", "call", "(", "this", ",", "{", "}", ")", ";", "this", ".", "_reset", "(", ")", ";", "// maximum length for bulk strings (512MB)", "this", ".", "maxlen", "=", "options", ".", "maxlen", "||", "536870912", ";", "// create String instances for simple string replies", "this", ".", "simple", "=", "options", ".", "simple", "!==", "undefined", "?", "options", ".", "simple", ":", "false", ";", "// return buffers for bulk strings", "this", ".", "buffers", "=", "options", ".", "return_buffers", "||", "options", ".", "buffers", ";", "// pass RESP messasges untouched", "this", ".", "raw", "=", "options", ".", "raw", "!==", "undefined", "?", "options", ".", "raw", ":", "false", ";", "/* istanbul ignore next: optional dependency */", "if", "(", "hiredis", ")", "{", "this", ".", "reader", "=", "new", "hiredis", ".", "Reader", "(", "{", "return_buffers", ":", "this", ".", "buffers", "}", ")", ";", "}", "}" ]
Class for decoding RESP messages to javascript types. Emits an error event when an exception occurs.
[ "Class", "for", "decoding", "RESP", "messages", "to", "javascript", "types", "." ]
9f998fc65a4494a358fca296adfe37fc5fb3f03c
https://github.com/redisjs/jsr-resp/blob/9f998fc65a4494a358fca296adfe37fc5fb3f03c/lib/decoder.js#L23-L46
51,955
redisjs/jsr-resp
lib/decoder.js
_type
function _type(chunk, test) { var b = chunk[0]; if(b === ERR || b === BST || b === STR || b === INT || b === ARR) { if(!test) this._offset++; return b; } }
javascript
function _type(chunk, test) { var b = chunk[0]; if(b === ERR || b === BST || b === STR || b === INT || b === ARR) { if(!test) this._offset++; return b; } }
[ "function", "_type", "(", "chunk", ",", "test", ")", "{", "var", "b", "=", "chunk", "[", "0", "]", ";", "if", "(", "b", "===", "ERR", "||", "b", "===", "BST", "||", "b", "===", "STR", "||", "b", "===", "INT", "||", "b", "===", "ARR", ")", "{", "if", "(", "!", "test", ")", "this", ".", "_offset", "++", ";", "return", "b", ";", "}", "}" ]
Swallow type identifier.
[ "Swallow", "type", "identifier", "." ]
9f998fc65a4494a358fca296adfe37fc5fb3f03c
https://github.com/redisjs/jsr-resp/blob/9f998fc65a4494a358fca296adfe37fc5fb3f03c/lib/decoder.js#L135-L141
51,956
redisjs/jsr-resp
lib/decoder.js
_arr
function _arr(chunk, type) { var len = this._int(chunk, type); // allow zero length for the empty array if(typeof len === 'number' && !isNaN(len)) { var arr = new Array(len); this._elements += len; Object.defineProperty(arr, '_index', { enumerable: false, configurable: true, writable: true, value: 0 } ); return arr; } }
javascript
function _arr(chunk, type) { var len = this._int(chunk, type); // allow zero length for the empty array if(typeof len === 'number' && !isNaN(len)) { var arr = new Array(len); this._elements += len; Object.defineProperty(arr, '_index', { enumerable: false, configurable: true, writable: true, value: 0 } ); return arr; } }
[ "function", "_arr", "(", "chunk", ",", "type", ")", "{", "var", "len", "=", "this", ".", "_int", "(", "chunk", ",", "type", ")", ";", "// allow zero length for the empty array", "if", "(", "typeof", "len", "===", "'number'", "&&", "!", "isNaN", "(", "len", ")", ")", "{", "var", "arr", "=", "new", "Array", "(", "len", ")", ";", "this", ".", "_elements", "+=", "len", ";", "Object", ".", "defineProperty", "(", "arr", ",", "'_index'", ",", "{", "enumerable", ":", "false", ",", "configurable", ":", "true", ",", "writable", ":", "true", ",", "value", ":", "0", "}", ")", ";", "return", "arr", ";", "}", "}" ]
Read an array.
[ "Read", "an", "array", "." ]
9f998fc65a4494a358fca296adfe37fc5fb3f03c
https://github.com/redisjs/jsr-resp/blob/9f998fc65a4494a358fca296adfe37fc5fb3f03c/lib/decoder.js#L286-L304
51,957
redisjs/jsr-resp
lib/decoder.js
_int
function _int(chunk, type) { var b, s = '', i; while(this._offset < chunk.length) { b = chunk[this._offset]; if(b === CR && chunk[this._offset + 1] === LF) { this._offset += 2; i = parseInt(s); if(type === BST) { if(isNaN(i)) { return this._abort(new Error('bad string length')); }else if(i > this.maxlen) { return this._abort(new Error('string length exceeded')); } } return i; } s += String.fromCharCode(b); ++this._offset; } }
javascript
function _int(chunk, type) { var b, s = '', i; while(this._offset < chunk.length) { b = chunk[this._offset]; if(b === CR && chunk[this._offset + 1] === LF) { this._offset += 2; i = parseInt(s); if(type === BST) { if(isNaN(i)) { return this._abort(new Error('bad string length')); }else if(i > this.maxlen) { return this._abort(new Error('string length exceeded')); } } return i; } s += String.fromCharCode(b); ++this._offset; } }
[ "function", "_int", "(", "chunk", ",", "type", ")", "{", "var", "b", ",", "s", "=", "''", ",", "i", ";", "while", "(", "this", ".", "_offset", "<", "chunk", ".", "length", ")", "{", "b", "=", "chunk", "[", "this", ".", "_offset", "]", ";", "if", "(", "b", "===", "CR", "&&", "chunk", "[", "this", ".", "_offset", "+", "1", "]", "===", "LF", ")", "{", "this", ".", "_offset", "+=", "2", ";", "i", "=", "parseInt", "(", "s", ")", ";", "if", "(", "type", "===", "BST", ")", "{", "if", "(", "isNaN", "(", "i", ")", ")", "{", "return", "this", ".", "_abort", "(", "new", "Error", "(", "'bad string length'", ")", ")", ";", "}", "else", "if", "(", "i", ">", "this", ".", "maxlen", ")", "{", "return", "this", ".", "_abort", "(", "new", "Error", "(", "'string length exceeded'", ")", ")", ";", "}", "}", "return", "i", ";", "}", "s", "+=", "String", ".", "fromCharCode", "(", "b", ")", ";", "++", "this", ".", "_offset", ";", "}", "}" ]
Read an integer.
[ "Read", "an", "integer", "." ]
9f998fc65a4494a358fca296adfe37fc5fb3f03c
https://github.com/redisjs/jsr-resp/blob/9f998fc65a4494a358fca296adfe37fc5fb3f03c/lib/decoder.js#L325-L344
51,958
redisjs/jsr-resp
lib/decoder.js
_bst
function _bst(chunk, type) { // we should have already read the chunk var len = this._int(chunk, type), buf; if(!isNaN(len)) { // read an integer less than zero, treat as null if(len < 0) return null; // read in the entire bulk string and swallow the crlf if((chunk.length - this._offset) >= len + 2) { buf = chunk.slice(this._offset, this._offset + len); this._offset += (len + 2); //this._buffer = this._buffer.slice(this._offset, this._buffer.length); //console.dir(buf); return this.buffers ? buf : '' + buf; }else{ this._wait(); } } }
javascript
function _bst(chunk, type) { // we should have already read the chunk var len = this._int(chunk, type), buf; if(!isNaN(len)) { // read an integer less than zero, treat as null if(len < 0) return null; // read in the entire bulk string and swallow the crlf if((chunk.length - this._offset) >= len + 2) { buf = chunk.slice(this._offset, this._offset + len); this._offset += (len + 2); //this._buffer = this._buffer.slice(this._offset, this._buffer.length); //console.dir(buf); return this.buffers ? buf : '' + buf; }else{ this._wait(); } } }
[ "function", "_bst", "(", "chunk", ",", "type", ")", "{", "// we should have already read the chunk", "var", "len", "=", "this", ".", "_int", "(", "chunk", ",", "type", ")", ",", "buf", ";", "if", "(", "!", "isNaN", "(", "len", ")", ")", "{", "// read an integer less than zero, treat as null", "if", "(", "len", "<", "0", ")", "return", "null", ";", "// read in the entire bulk string and swallow the crlf", "if", "(", "(", "chunk", ".", "length", "-", "this", ".", "_offset", ")", ">=", "len", "+", "2", ")", "{", "buf", "=", "chunk", ".", "slice", "(", "this", ".", "_offset", ",", "this", ".", "_offset", "+", "len", ")", ";", "this", ".", "_offset", "+=", "(", "len", "+", "2", ")", ";", "//this._buffer = this._buffer.slice(this._offset, this._buffer.length);", "//console.dir(buf);", "return", "this", ".", "buffers", "?", "buf", ":", "''", "+", "buf", ";", "}", "else", "{", "this", ".", "_wait", "(", ")", ";", "}", "}", "}" ]
Read a bulk string.
[ "Read", "a", "bulk", "string", "." ]
9f998fc65a4494a358fca296adfe37fc5fb3f03c
https://github.com/redisjs/jsr-resp/blob/9f998fc65a4494a358fca296adfe37fc5fb3f03c/lib/decoder.js#L350-L367
51,959
chatphrase/caress
lib/routes/uuidGet.js
noNew
function noNew() { return finish(function(err) { if (err) return next(err); // If there was a body initially, respond that there's been no change if (ourEtag) return res.send(304); // Otherwise, respond that there's no content (yet) else return res.send(204); }); }
javascript
function noNew() { return finish(function(err) { if (err) return next(err); // If there was a body initially, respond that there's been no change if (ourEtag) return res.send(304); // Otherwise, respond that there's no content (yet) else return res.send(204); }); }
[ "function", "noNew", "(", ")", "{", "return", "finish", "(", "function", "(", "err", ")", "{", "if", "(", "err", ")", "return", "next", "(", "err", ")", ";", "// If there was a body initially, respond that there's been no change", "if", "(", "ourEtag", ")", "return", "res", ".", "send", "(", "304", ")", ";", "// Otherwise, respond that there's no content (yet)", "else", "return", "res", ".", "send", "(", "204", ")", ";", "}", ")", ";", "}" ]
Callback for if there's no new body by the time we're supposed to respond.
[ "Callback", "for", "if", "there", "s", "no", "new", "body", "by", "the", "time", "we", "re", "supposed", "to", "respond", "." ]
1634c127e90c8140baf5e2803a2938ffaf0414c4
https://github.com/chatphrase/caress/blob/1634c127e90c8140baf5e2803a2938ffaf0414c4/lib/routes/uuidGet.js#L47-L57
51,960
chatphrase/caress
lib/routes/uuidGet.js
getNew
function getNew(body) { // If we haven't already cleared the callback (we got the body, then the // message on the subscriber) if (timer) { // If the new body is present (say, if it wasn't deleted) if (body) { // Calculate the new Etag ourEtag = '"' + sha1hex(body) + '"'; // If it's a new body (which it almost certainly should be) if (ourEtag != theirEtag) { sendNewEtagAndBody(body); } // If it's not a new body we do nothing and keep listening / waiting // If the new body is empty } else { // Respond that it is now Not Found respondNotFound(); } } }
javascript
function getNew(body) { // If we haven't already cleared the callback (we got the body, then the // message on the subscriber) if (timer) { // If the new body is present (say, if it wasn't deleted) if (body) { // Calculate the new Etag ourEtag = '"' + sha1hex(body) + '"'; // If it's a new body (which it almost certainly should be) if (ourEtag != theirEtag) { sendNewEtagAndBody(body); } // If it's not a new body we do nothing and keep listening / waiting // If the new body is empty } else { // Respond that it is now Not Found respondNotFound(); } } }
[ "function", "getNew", "(", "body", ")", "{", "// If we haven't already cleared the callback (we got the body, then the", "// message on the subscriber)", "if", "(", "timer", ")", "{", "// If the new body is present (say, if it wasn't deleted)", "if", "(", "body", ")", "{", "// Calculate the new Etag", "ourEtag", "=", "'\"'", "+", "sha1hex", "(", "body", ")", "+", "'\"'", ";", "// If it's a new body (which it almost certainly should be)", "if", "(", "ourEtag", "!=", "theirEtag", ")", "{", "sendNewEtagAndBody", "(", "body", ")", ";", "}", "// If it's not a new body we do nothing and keep listening / waiting", "// If the new body is empty", "}", "else", "{", "// Respond that it is now Not Found", "respondNotFound", "(", ")", ";", "}", "}", "}" ]
Callback for when we get a mesage that there's a new body.
[ "Callback", "for", "when", "we", "get", "a", "mesage", "that", "there", "s", "a", "new", "body", "." ]
1634c127e90c8140baf5e2803a2938ffaf0414c4
https://github.com/chatphrase/caress/blob/1634c127e90c8140baf5e2803a2938ffaf0414c4/lib/routes/uuidGet.js#L76-L97
51,961
hex7c0/setheaders
index.js
setOverrideHeader
function setOverrideHeader(res, name, value) { if (res._headers && res._headers[name] !== undefined) { return true; } res.setHeader(name, value); return true; }
javascript
function setOverrideHeader(res, name, value) { if (res._headers && res._headers[name] !== undefined) { return true; } res.setHeader(name, value); return true; }
[ "function", "setOverrideHeader", "(", "res", ",", "name", ",", "value", ")", "{", "if", "(", "res", ".", "_headers", "&&", "res", ".", "_headers", "[", "name", "]", "!==", "undefined", ")", "{", "return", "true", ";", "}", "res", ".", "setHeader", "(", "name", ",", "value", ")", ";", "return", "true", ";", "}" ]
set override header on response @function setOverrideHeader @param {Object} res - response to client @param {String} name - header's name @param {String} value - header's value @return {Boolean}
[ "set", "override", "header", "on", "response" ]
e2d92bc8f03ec1938036e15ffc2a01b286137f9e
https://github.com/hex7c0/setheaders/blob/e2d92bc8f03ec1938036e15ffc2a01b286137f9e/index.js#L118-L126
51,962
hex7c0/setheaders
index.js
setWritableHeader
function setWritableHeader(res, name, value) { if (res._headerSent && res.finished) { return false; } res.setHeader(name, value); return true; }
javascript
function setWritableHeader(res, name, value) { if (res._headerSent && res.finished) { return false; } res.setHeader(name, value); return true; }
[ "function", "setWritableHeader", "(", "res", ",", "name", ",", "value", ")", "{", "if", "(", "res", ".", "_headerSent", "&&", "res", ".", "finished", ")", "{", "return", "false", ";", "}", "res", ".", "setHeader", "(", "name", ",", "value", ")", ";", "return", "true", ";", "}" ]
set writable header on response @function setWritableHeader @param {Object} res - response to client @param {String} name - header's name @param {String} value - header's value @return {Boolean}
[ "set", "writable", "header", "on", "response" ]
e2d92bc8f03ec1938036e15ffc2a01b286137f9e
https://github.com/hex7c0/setheaders/blob/e2d92bc8f03ec1938036e15ffc2a01b286137f9e/index.js#L138-L146
51,963
repetere/component.collection-linotype
lib/linotype.js
function (options) { /** call event emitter */ events.EventEmitter.call(this); /** module default configuration */ var defaults = { idSelector: 'linotype', start: 0, currentSection: 0, delay: 300, easingdelay: 700, easing: false, isMoving: false, keyboardScrolling: true, touchevents: true, mousewheel: true, sections: null, numSections: 0, touchSensitivity: 5, sectionHeight: null, callback: false, normalscroll: false, continuous: false }; this.$el = null; /** extended default options */ this.options = extend(defaults, options); this.init(this.options); }
javascript
function (options) { /** call event emitter */ events.EventEmitter.call(this); /** module default configuration */ var defaults = { idSelector: 'linotype', start: 0, currentSection: 0, delay: 300, easingdelay: 700, easing: false, isMoving: false, keyboardScrolling: true, touchevents: true, mousewheel: true, sections: null, numSections: 0, touchSensitivity: 5, sectionHeight: null, callback: false, normalscroll: false, continuous: false }; this.$el = null; /** extended default options */ this.options = extend(defaults, options); this.init(this.options); }
[ "function", "(", "options", ")", "{", "/** call event emitter */", "events", ".", "EventEmitter", ".", "call", "(", "this", ")", ";", "/** module default configuration */", "var", "defaults", "=", "{", "idSelector", ":", "'linotype'", ",", "start", ":", "0", ",", "currentSection", ":", "0", ",", "delay", ":", "300", ",", "easingdelay", ":", "700", ",", "easing", ":", "false", ",", "isMoving", ":", "false", ",", "keyboardScrolling", ":", "true", ",", "touchevents", ":", "true", ",", "mousewheel", ":", "true", ",", "sections", ":", "null", ",", "numSections", ":", "0", ",", "touchSensitivity", ":", "5", ",", "sectionHeight", ":", "null", ",", "callback", ":", "false", ",", "normalscroll", ":", "false", ",", "continuous", ":", "false", "}", ";", "this", ".", "$el", "=", "null", ";", "/** extended default options */", "this", ".", "options", "=", "extend", "(", "defaults", ",", "options", ")", ";", "this", ".", "init", "(", "this", ".", "options", ")", ";", "}" ]
A module that represents a Linotype object, a Linotyper is a page composition tool. @{@link https://github.com/typesettin/linotype} @author Yaw Joseph Etse @copyright Copyright (c) 2014 Typesettin. All rights reserved. @license MIT @constructor Linotype @requires module:classie @requires module:util-extent @requires module:util @requires module:events
[ "A", "module", "that", "represents", "a", "Linotype", "object", "a", "Linotyper", "is", "a", "page", "composition", "tool", "." ]
c3ddbd4a10ee58171602ec0747bac60064c15403
https://github.com/repetere/component.collection-linotype/blob/c3ddbd4a10ee58171602ec0747bac60064c15403/lib/linotype.js#L34-L64
51,964
repetere/component.collection-linotype
lib/linotype.js
function (e) { var touchEvents = getEventsPage(e); touchStartY = touchEvents.y; touchStartX = touchEvents.x; if (e.touches) { touchMoveStartY = e.touches[0].screenY; touchMoveStartX = e.touches[0].screenX; } }
javascript
function (e) { var touchEvents = getEventsPage(e); touchStartY = touchEvents.y; touchStartX = touchEvents.x; if (e.touches) { touchMoveStartY = e.touches[0].screenY; touchMoveStartX = e.touches[0].screenX; } }
[ "function", "(", "e", ")", "{", "var", "touchEvents", "=", "getEventsPage", "(", "e", ")", ";", "touchStartY", "=", "touchEvents", ".", "y", ";", "touchStartX", "=", "touchEvents", ".", "x", ";", "if", "(", "e", ".", "touches", ")", "{", "touchMoveStartY", "=", "e", ".", "touches", "[", "0", "]", ".", "screenY", ";", "touchMoveStartX", "=", "e", ".", "touches", "[", "0", "]", ".", "screenX", ";", "}", "}" ]
handle touch start events @event touchStartHandler @param {object} e touch event object
[ "handle", "touch", "start", "events" ]
c3ddbd4a10ee58171602ec0747bac60064c15403
https://github.com/repetere/component.collection-linotype/blob/c3ddbd4a10ee58171602ec0747bac60064c15403/lib/linotype.js#L184-L192
51,965
robotlolita/specify-reporter-tap
index.js
describeFailure
function describeFailure(ex) { return ex.stack? [' ---' ,' type: ' + ex.name ,' message: >' , pad(6, ex.message) ,' stack: | ' , pad(6, ex.stack) ,' ...' ].join('\n') : /* otherwise */ [' ---' ,' message: >' , pad(6, ex.toString()) ,' ...' ].join('\n') }
javascript
function describeFailure(ex) { return ex.stack? [' ---' ,' type: ' + ex.name ,' message: >' , pad(6, ex.message) ,' stack: | ' , pad(6, ex.stack) ,' ...' ].join('\n') : /* otherwise */ [' ---' ,' message: >' , pad(6, ex.toString()) ,' ...' ].join('\n') }
[ "function", "describeFailure", "(", "ex", ")", "{", "return", "ex", ".", "stack", "?", "[", "' ---'", ",", "' type: '", "+", "ex", ".", "name", ",", "' message: >'", ",", "pad", "(", "6", ",", "ex", ".", "message", ")", ",", "' stack: | '", ",", "pad", "(", "6", ",", "ex", ".", "stack", ")", ",", "' ...'", "]", ".", "join", "(", "'\\n'", ")", ":", "/* otherwise */", "[", "' ---'", ",", "' message: >'", ",", "pad", "(", "6", ",", "ex", ".", "toString", "(", ")", ")", ",", "' ...'", "]", ".", "join", "(", "'\\n'", ")", "}" ]
Returns a YAML serialisation of an exception. @summary Error → String
[ "Returns", "a", "YAML", "serialisation", "of", "an", "exception", "." ]
809a4cf783907c58873e2a329c7e40a9ee25e5e1
https://github.com/robotlolita/specify-reporter-tap/blob/809a4cf783907c58873e2a329c7e40a9ee25e5e1/index.js#L32-L46
51,966
Nazariglez/perenquen
lib/pixi/src/filters/twist/TwistFilter.js
TwistFilter
function TwistFilter() { core.AbstractFilter.call(this, // vertex shader null, // fragment shader fs.readFileSync(__dirname + '/twist.frag', 'utf8'), // custom uniforms { radius: { type: '1f', value: 0.5 }, angle: { type: '1f', value: 5 }, offset: { type: 'v2', value: { x: 0.5, y: 0.5 } } } ); }
javascript
function TwistFilter() { core.AbstractFilter.call(this, // vertex shader null, // fragment shader fs.readFileSync(__dirname + '/twist.frag', 'utf8'), // custom uniforms { radius: { type: '1f', value: 0.5 }, angle: { type: '1f', value: 5 }, offset: { type: 'v2', value: { x: 0.5, y: 0.5 } } } ); }
[ "function", "TwistFilter", "(", ")", "{", "core", ".", "AbstractFilter", ".", "call", "(", "this", ",", "// vertex shader", "null", ",", "// fragment shader", "fs", ".", "readFileSync", "(", "__dirname", "+", "'/twist.frag'", ",", "'utf8'", ")", ",", "// custom uniforms", "{", "radius", ":", "{", "type", ":", "'1f'", ",", "value", ":", "0.5", "}", ",", "angle", ":", "{", "type", ":", "'1f'", ",", "value", ":", "5", "}", ",", "offset", ":", "{", "type", ":", "'v2'", ",", "value", ":", "{", "x", ":", "0.5", ",", "y", ":", "0.5", "}", "}", "}", ")", ";", "}" ]
This filter applies a twist effect making display objects appear twisted in the given direction. @class @extends AbstractFilter @memberof PIXI.filters
[ "This", "filter", "applies", "a", "twist", "effect", "making", "display", "objects", "appear", "twisted", "in", "the", "given", "direction", "." ]
e023964d05afeefebdcac4e2044819fdfa3899ae
https://github.com/Nazariglez/perenquen/blob/e023964d05afeefebdcac4e2044819fdfa3899ae/lib/pixi/src/filters/twist/TwistFilter.js#L12-L26
51,967
inviqa/deck-task-registry
src/scripts/lintScripts.js
lintScripts
function lintScripts(conf, undertaker) { const jsSrc = path.join(conf.themeConfig.root, conf.themeConfig.js.src, '**', '*.js'); // Lint theme scripts with ESLint. This won't touch any TypeScript files. return undertaker.src(jsSrc) .pipe(eslint()) .pipe(eslint.format()) .pipe(gulpIf(conf.productionMode, eslint.failAfterError())); }
javascript
function lintScripts(conf, undertaker) { const jsSrc = path.join(conf.themeConfig.root, conf.themeConfig.js.src, '**', '*.js'); // Lint theme scripts with ESLint. This won't touch any TypeScript files. return undertaker.src(jsSrc) .pipe(eslint()) .pipe(eslint.format()) .pipe(gulpIf(conf.productionMode, eslint.failAfterError())); }
[ "function", "lintScripts", "(", "conf", ",", "undertaker", ")", "{", "const", "jsSrc", "=", "path", ".", "join", "(", "conf", ".", "themeConfig", ".", "root", ",", "conf", ".", "themeConfig", ".", "js", ".", "src", ",", "'**'", ",", "'*.js'", ")", ";", "// Lint theme scripts with ESLint. This won't touch any TypeScript files.", "return", "undertaker", ".", "src", "(", "jsSrc", ")", ".", "pipe", "(", "eslint", "(", ")", ")", ".", "pipe", "(", "eslint", ".", "format", "(", ")", ")", ".", "pipe", "(", "gulpIf", "(", "conf", ".", "productionMode", ",", "eslint", ".", "failAfterError", "(", ")", ")", ")", ";", "}" ]
Lint project scripts. @param {ConfigParser} conf A configuration parser object. @param {Undertaker} undertaker An Undertaker instance. @returns {Stream} A stream of files.
[ "Lint", "project", "scripts", "." ]
4c31787b978e9d99a47052e090d4589a50cd3015
https://github.com/inviqa/deck-task-registry/blob/4c31787b978e9d99a47052e090d4589a50cd3015/src/scripts/lintScripts.js#L15-L25
51,968
grownseed/haibu-ishiki
lib/ishiki.js
switchState
function switchState(started, pkg) { pkg.started = started; //add available port back into port range if (!started && pkg.env && pkg.env.PORT) ports.push(pkg.env.PORT); console.log((started ? 'Started' : 'Stopped') + ' application ' + pkg.user + '/' + pkg.name); logInfo('info', 'Application ' + (started ? 'started' : 'stopped'), {name: pkg.app, user: pkg.user}); droneModel.createOrUpdate(pkg, function(){}); }
javascript
function switchState(started, pkg) { pkg.started = started; //add available port back into port range if (!started && pkg.env && pkg.env.PORT) ports.push(pkg.env.PORT); console.log((started ? 'Started' : 'Stopped') + ' application ' + pkg.user + '/' + pkg.name); logInfo('info', 'Application ' + (started ? 'started' : 'stopped'), {name: pkg.app, user: pkg.user}); droneModel.createOrUpdate(pkg, function(){}); }
[ "function", "switchState", "(", "started", ",", "pkg", ")", "{", "pkg", ".", "started", "=", "started", ";", "//add available port back into port range", "if", "(", "!", "started", "&&", "pkg", ".", "env", "&&", "pkg", ".", "env", ".", "PORT", ")", "ports", ".", "push", "(", "pkg", ".", "env", ".", "PORT", ")", ";", "console", ".", "log", "(", "(", "started", "?", "'Started'", ":", "'Stopped'", ")", "+", "' application '", "+", "pkg", ".", "user", "+", "'/'", "+", "pkg", ".", "name", ")", ";", "logInfo", "(", "'info'", ",", "'Application '", "+", "(", "started", "?", "'started'", ":", "'stopped'", ")", ",", "{", "name", ":", "pkg", ".", "app", ",", "user", ":", "pkg", ".", "user", "}", ")", ";", "droneModel", ".", "createOrUpdate", "(", "pkg", ",", "function", "(", ")", "{", "}", ")", ";", "}" ]
update drone state
[ "update", "drone", "state" ]
697e7d5fbc8405654b6cfc30bd5979f76c135421
https://github.com/grownseed/haibu-ishiki/blob/697e7d5fbc8405654b6cfc30bd5979f76c135421/lib/ishiki.js#L47-L58
51,969
grownseed/haibu-ishiki
lib/ishiki.js
switchAndClear
function switchAndClear(pkg) { switchState(false, pkg); //unload proxy routes proxy.deleteBy(app.config.get('public-port'), {user: pkg.user, appid: pkg.name}); }
javascript
function switchAndClear(pkg) { switchState(false, pkg); //unload proxy routes proxy.deleteBy(app.config.get('public-port'), {user: pkg.user, appid: pkg.name}); }
[ "function", "switchAndClear", "(", "pkg", ")", "{", "switchState", "(", "false", ",", "pkg", ")", ";", "//unload proxy routes", "proxy", ".", "deleteBy", "(", "app", ".", "config", ".", "get", "(", "'public-port'", ")", ",", "{", "user", ":", "pkg", ".", "user", ",", "appid", ":", "pkg", ".", "name", "}", ")", ";", "}" ]
update drone state and clear proxy routes
[ "update", "drone", "state", "and", "clear", "proxy", "routes" ]
697e7d5fbc8405654b6cfc30bd5979f76c135421
https://github.com/grownseed/haibu-ishiki/blob/697e7d5fbc8405654b6cfc30bd5979f76c135421/lib/ishiki.js#L61-L66
51,970
grownseed/haibu-ishiki
lib/ishiki.js
findSwitchAndClear
function findSwitchAndClear(uid) { if (uid) { droneModel.getProcessed({uid: uid}, function(err, result) { if (!err && result && result.length == 1) { switchAndClear(result[0]); } }); } }
javascript
function findSwitchAndClear(uid) { if (uid) { droneModel.getProcessed({uid: uid}, function(err, result) { if (!err && result && result.length == 1) { switchAndClear(result[0]); } }); } }
[ "function", "findSwitchAndClear", "(", "uid", ")", "{", "if", "(", "uid", ")", "{", "droneModel", ".", "getProcessed", "(", "{", "uid", ":", "uid", "}", ",", "function", "(", "err", ",", "result", ")", "{", "if", "(", "!", "err", "&&", "result", "&&", "result", ".", "length", "==", "1", ")", "{", "switchAndClear", "(", "result", "[", "0", "]", ")", ";", "}", "}", ")", ";", "}", "}" ]
find drone by uid, update drone state and clear proxy routes
[ "find", "drone", "by", "uid", "update", "drone", "state", "and", "clear", "proxy", "routes" ]
697e7d5fbc8405654b6cfc30bd5979f76c135421
https://github.com/grownseed/haibu-ishiki/blob/697e7d5fbc8405654b6cfc30bd5979f76c135421/lib/ishiki.js#L69-L77
51,971
grownseed/haibu-ishiki
lib/ishiki.js
startDrone
function startDrone(pkg, userid, appid, callback) { var drone_port = getPort(); if (drone_port) { pkg.env = pkg.env || {}; pkg.env['PORT'] = drone_port; //ensure package user and name match internally pkg.user = userid; pkg.name = appid; drone.start(pkg, function(err, result) { if (err) callback(err); pkg.host = result.host; pkg.port = result.port; pkg.uid = result.uid; //async update package in db droneModel.createOrUpdate(pkg, function(){}); //load proxy routes proxy.load(app.config.get('public-port'), pkg); callback(null, {drone: result}); }); }else{ callback({message: 'No more ports available'}); } }
javascript
function startDrone(pkg, userid, appid, callback) { var drone_port = getPort(); if (drone_port) { pkg.env = pkg.env || {}; pkg.env['PORT'] = drone_port; //ensure package user and name match internally pkg.user = userid; pkg.name = appid; drone.start(pkg, function(err, result) { if (err) callback(err); pkg.host = result.host; pkg.port = result.port; pkg.uid = result.uid; //async update package in db droneModel.createOrUpdate(pkg, function(){}); //load proxy routes proxy.load(app.config.get('public-port'), pkg); callback(null, {drone: result}); }); }else{ callback({message: 'No more ports available'}); } }
[ "function", "startDrone", "(", "pkg", ",", "userid", ",", "appid", ",", "callback", ")", "{", "var", "drone_port", "=", "getPort", "(", ")", ";", "if", "(", "drone_port", ")", "{", "pkg", ".", "env", "=", "pkg", ".", "env", "||", "{", "}", ";", "pkg", ".", "env", "[", "'PORT'", "]", "=", "drone_port", ";", "//ensure package user and name match internally", "pkg", ".", "user", "=", "userid", ";", "pkg", ".", "name", "=", "appid", ";", "drone", ".", "start", "(", "pkg", ",", "function", "(", "err", ",", "result", ")", "{", "if", "(", "err", ")", "callback", "(", "err", ")", ";", "pkg", ".", "host", "=", "result", ".", "host", ";", "pkg", ".", "port", "=", "result", ".", "port", ";", "pkg", ".", "uid", "=", "result", ".", "uid", ";", "//async update package in db", "droneModel", ".", "createOrUpdate", "(", "pkg", ",", "function", "(", ")", "{", "}", ")", ";", "//load proxy routes", "proxy", ".", "load", "(", "app", ".", "config", ".", "get", "(", "'public-port'", ")", ",", "pkg", ")", ";", "callback", "(", "null", ",", "{", "drone", ":", "result", "}", ")", ";", "}", ")", ";", "}", "else", "{", "callback", "(", "{", "message", ":", "'No more ports available'", "}", ")", ";", "}", "}" ]
starts a drone and sets up proxy routes for it
[ "starts", "a", "drone", "and", "sets", "up", "proxy", "routes", "for", "it" ]
697e7d5fbc8405654b6cfc30bd5979f76c135421
https://github.com/grownseed/haibu-ishiki/blob/697e7d5fbc8405654b6cfc30bd5979f76c135421/lib/ishiki.js#L111-L141
51,972
grownseed/haibu-ishiki
lib/ishiki.js
stopDrone
function stopDrone(userid, appid, callback) { droneModel.getProcessed({user: userid, name: appid}, function(err, result) { if (err) return callback(err); if (result.length == 1) { if (!result[0].started) { callback({message: 'Drone is already stopped'}); }else{ //need to namespace apps to allow for two users with same app name drone.stop(appid, function(err, response) { if (err) return callback(err); result[0].started = false; callback(null, result[0]); }); } }else{ callback({message: 'No drone matching ' + userid + '/' + appid}); } }); }
javascript
function stopDrone(userid, appid, callback) { droneModel.getProcessed({user: userid, name: appid}, function(err, result) { if (err) return callback(err); if (result.length == 1) { if (!result[0].started) { callback({message: 'Drone is already stopped'}); }else{ //need to namespace apps to allow for two users with same app name drone.stop(appid, function(err, response) { if (err) return callback(err); result[0].started = false; callback(null, result[0]); }); } }else{ callback({message: 'No drone matching ' + userid + '/' + appid}); } }); }
[ "function", "stopDrone", "(", "userid", ",", "appid", ",", "callback", ")", "{", "droneModel", ".", "getProcessed", "(", "{", "user", ":", "userid", ",", "name", ":", "appid", "}", ",", "function", "(", "err", ",", "result", ")", "{", "if", "(", "err", ")", "return", "callback", "(", "err", ")", ";", "if", "(", "result", ".", "length", "==", "1", ")", "{", "if", "(", "!", "result", "[", "0", "]", ".", "started", ")", "{", "callback", "(", "{", "message", ":", "'Drone is already stopped'", "}", ")", ";", "}", "else", "{", "//need to namespace apps to allow for two users with same app name", "drone", ".", "stop", "(", "appid", ",", "function", "(", "err", ",", "response", ")", "{", "if", "(", "err", ")", "return", "callback", "(", "err", ")", ";", "result", "[", "0", "]", ".", "started", "=", "false", ";", "callback", "(", "null", ",", "result", "[", "0", "]", ")", ";", "}", ")", ";", "}", "}", "else", "{", "callback", "(", "{", "message", ":", "'No drone matching '", "+", "userid", "+", "'/'", "+", "appid", "}", ")", ";", "}", "}", ")", ";", "}" ]
stops a drone
[ "stops", "a", "drone" ]
697e7d5fbc8405654b6cfc30bd5979f76c135421
https://github.com/grownseed/haibu-ishiki/blob/697e7d5fbc8405654b6cfc30bd5979f76c135421/lib/ishiki.js#L144-L166
51,973
grownseed/haibu-ishiki
lib/ishiki.js
sendDrones
function sendDrones(filter, res) { droneModel.getProcessed(filter, function(err, result) { if (err) return haibu.sendResponse(res, 500, err); haibu.sendResponse(res, 200, {drones: result}); }); }
javascript
function sendDrones(filter, res) { droneModel.getProcessed(filter, function(err, result) { if (err) return haibu.sendResponse(res, 500, err); haibu.sendResponse(res, 200, {drones: result}); }); }
[ "function", "sendDrones", "(", "filter", ",", "res", ")", "{", "droneModel", ".", "getProcessed", "(", "filter", ",", "function", "(", "err", ",", "result", ")", "{", "if", "(", "err", ")", "return", "haibu", ".", "sendResponse", "(", "res", ",", "500", ",", "err", ")", ";", "haibu", ".", "sendResponse", "(", "res", ",", "200", ",", "{", "drones", ":", "result", "}", ")", ";", "}", ")", ";", "}" ]
find drones for given filter and sends response
[ "find", "drones", "for", "given", "filter", "and", "sends", "response" ]
697e7d5fbc8405654b6cfc30bd5979f76c135421
https://github.com/grownseed/haibu-ishiki/blob/697e7d5fbc8405654b6cfc30bd5979f76c135421/lib/ishiki.js#L169-L176
51,974
cp2017/sign
index.js
function(ethereumAddress, ethereumDataDir, ethereumAccountPassword, cb = null){ if(isFunction(cb)){ try { keythereum.importFromFile(ethereumAddress, ethereumDataDir, function(keyObject){ keythereum.recover(ethereumAccountPassword, keyObject, function(privateKey){ return cb(null, privateKey) }) }) } catch (err){ return cb(err) } } else { try { var keyObject = keythereum.importFromFile(ethereumAddress, ethereumDataDir) return keythereum.recover(ethereumAccountPassword, keyObject) } catch (err){ return err } } }
javascript
function(ethereumAddress, ethereumDataDir, ethereumAccountPassword, cb = null){ if(isFunction(cb)){ try { keythereum.importFromFile(ethereumAddress, ethereumDataDir, function(keyObject){ keythereum.recover(ethereumAccountPassword, keyObject, function(privateKey){ return cb(null, privateKey) }) }) } catch (err){ return cb(err) } } else { try { var keyObject = keythereum.importFromFile(ethereumAddress, ethereumDataDir) return keythereum.recover(ethereumAccountPassword, keyObject) } catch (err){ return err } } }
[ "function", "(", "ethereumAddress", ",", "ethereumDataDir", ",", "ethereumAccountPassword", ",", "cb", "=", "null", ")", "{", "if", "(", "isFunction", "(", "cb", ")", ")", "{", "try", "{", "keythereum", ".", "importFromFile", "(", "ethereumAddress", ",", "ethereumDataDir", ",", "function", "(", "keyObject", ")", "{", "keythereum", ".", "recover", "(", "ethereumAccountPassword", ",", "keyObject", ",", "function", "(", "privateKey", ")", "{", "return", "cb", "(", "null", ",", "privateKey", ")", "}", ")", "}", ")", "}", "catch", "(", "err", ")", "{", "return", "cb", "(", "err", ")", "}", "}", "else", "{", "try", "{", "var", "keyObject", "=", "keythereum", ".", "importFromFile", "(", "ethereumAddress", ",", "ethereumDataDir", ")", "return", "keythereum", ".", "recover", "(", "ethereumAccountPassword", ",", "keyObject", ")", "}", "catch", "(", "err", ")", "{", "return", "err", "}", "}", "}" ]
get the ethereum private key for the specified ethereum account, throws exception in case of any error @param {String} ethereumAddress address of the ethereum account or empty if default account @param {String} ethereumDataDir absolute path of the ethereum data, defaults to ~/.ethereum @param {String} ethereumAccountPassword password of the specified ethereum account @return {Buffer} Private key of the specified ethereum account
[ "get", "the", "ethereum", "private", "key", "for", "the", "specified", "ethereum", "account", "throws", "exception", "in", "case", "of", "any", "error" ]
9a838d454f862e674a505a09dd31cef93f727b4f
https://github.com/cp2017/sign/blob/9a838d454f862e674a505a09dd31cef93f727b4f/index.js#L82-L101
51,975
cp2017/sign
index.js
function(privateKey, cb = null){ if(isFunction(cb)){ try { return cb(null, ethUtils.privateToPublic(privateKey)) } catch(err){ return cb(err) } } else { try { return ethUtils.privateToPublic(privateKey) } catch(err){ return err } } }
javascript
function(privateKey, cb = null){ if(isFunction(cb)){ try { return cb(null, ethUtils.privateToPublic(privateKey)) } catch(err){ return cb(err) } } else { try { return ethUtils.privateToPublic(privateKey) } catch(err){ return err } } }
[ "function", "(", "privateKey", ",", "cb", "=", "null", ")", "{", "if", "(", "isFunction", "(", "cb", ")", ")", "{", "try", "{", "return", "cb", "(", "null", ",", "ethUtils", ".", "privateToPublic", "(", "privateKey", ")", ")", "}", "catch", "(", "err", ")", "{", "return", "cb", "(", "err", ")", "}", "}", "else", "{", "try", "{", "return", "ethUtils", ".", "privateToPublic", "(", "privateKey", ")", "}", "catch", "(", "err", ")", "{", "return", "err", "}", "}", "}" ]
get public key for a given ethereum private key @param {Buffer} privateKey ethereum private key @return {Buffer} the associated public key
[ "get", "public", "key", "for", "a", "given", "ethereum", "private", "key" ]
9a838d454f862e674a505a09dd31cef93f727b4f
https://github.com/cp2017/sign/blob/9a838d454f862e674a505a09dd31cef93f727b4f/index.js#L107-L123
51,976
cp2017/sign
index.js
function(message, signatureObject, cb = null){ var result = false var ethSig = toEthUtilsSignature(signatureObject) try { var isSigValid = ethUtils.isValidSignature(ethSig.v, ethSig.r, ethSig.s) var isPubKeyValid = ethUtils.isValidPublic(signatureObject.publicKey) //convert public key to secp256k1 format signatureObject.publicKey = getSecp256k1PublicKey(signatureObject.publicKey) var isSigVerified = secp256k1.verify(ethUtils.sha3(message), signatureObject.signature, signatureObject.publicKey) if(isSigVerified){ result = true } } catch(err){ result = err } if(isFunction(cb)){ if(result instanceof Error){ return cb(result) } else { return cb(null, result) } } else { return result } }
javascript
function(message, signatureObject, cb = null){ var result = false var ethSig = toEthUtilsSignature(signatureObject) try { var isSigValid = ethUtils.isValidSignature(ethSig.v, ethSig.r, ethSig.s) var isPubKeyValid = ethUtils.isValidPublic(signatureObject.publicKey) //convert public key to secp256k1 format signatureObject.publicKey = getSecp256k1PublicKey(signatureObject.publicKey) var isSigVerified = secp256k1.verify(ethUtils.sha3(message), signatureObject.signature, signatureObject.publicKey) if(isSigVerified){ result = true } } catch(err){ result = err } if(isFunction(cb)){ if(result instanceof Error){ return cb(result) } else { return cb(null, result) } } else { return result } }
[ "function", "(", "message", ",", "signatureObject", ",", "cb", "=", "null", ")", "{", "var", "result", "=", "false", "var", "ethSig", "=", "toEthUtilsSignature", "(", "signatureObject", ")", "try", "{", "var", "isSigValid", "=", "ethUtils", ".", "isValidSignature", "(", "ethSig", ".", "v", ",", "ethSig", ".", "r", ",", "ethSig", ".", "s", ")", "var", "isPubKeyValid", "=", "ethUtils", ".", "isValidPublic", "(", "signatureObject", ".", "publicKey", ")", "//convert public key to secp256k1 format", "signatureObject", ".", "publicKey", "=", "getSecp256k1PublicKey", "(", "signatureObject", ".", "publicKey", ")", "var", "isSigVerified", "=", "secp256k1", ".", "verify", "(", "ethUtils", ".", "sha3", "(", "message", ")", ",", "signatureObject", ".", "signature", ",", "signatureObject", ".", "publicKey", ")", "if", "(", "isSigVerified", ")", "{", "result", "=", "true", "}", "}", "catch", "(", "err", ")", "{", "result", "=", "err", "}", "if", "(", "isFunction", "(", "cb", ")", ")", "{", "if", "(", "result", "instanceof", "Error", ")", "{", "return", "cb", "(", "result", ")", "}", "else", "{", "return", "cb", "(", "null", ",", "result", ")", "}", "}", "else", "{", "return", "result", "}", "}" ]
verify signature easier handing over the complete signature object containing the signature, recovery and the public key in one object @param {String} message message to verify @param {Object} signatureObject Signature object. must contain recovery (Number), signature and publicKey (both buffers) @param {Function} cb callback function (optional) @return {boolean} true, if signature and public key are valid, otherwise false
[ "verify", "signature", "easier", "handing", "over", "the", "complete", "signature", "object", "containing", "the", "signature", "recovery", "and", "the", "public", "key", "in", "one", "object" ]
9a838d454f862e674a505a09dd31cef93f727b4f
https://github.com/cp2017/sign/blob/9a838d454f862e674a505a09dd31cef93f727b4f/index.js#L157-L181
51,977
cp2017/sign
index.js
function(signatureObject, publicKey, bufferEncoding = DEFAULT_ENCODING, cb = null){ var clonedSignatureObj = { signature: signatureObject.signature, recovery: signatureObject.recovery, publicKey: publicKey } bufferEncoding = getEncodingOrDefault(bufferEncoding) if(isFunction(cb)){ convertBuffersToStrings(clonedSignatureObj, bufferEncoding, function(convertedObj){ var base64String = Buffer.from(JSON.stringify(convertedObj)).toString('base64') return cb(null, base64String) }) } else { var convertedObj = convertBuffersToStrings(clonedSignatureObj, bufferEncoding) var base64String = Buffer.from(JSON.stringify(convertedObj)).toString('base64') return base64String } }
javascript
function(signatureObject, publicKey, bufferEncoding = DEFAULT_ENCODING, cb = null){ var clonedSignatureObj = { signature: signatureObject.signature, recovery: signatureObject.recovery, publicKey: publicKey } bufferEncoding = getEncodingOrDefault(bufferEncoding) if(isFunction(cb)){ convertBuffersToStrings(clonedSignatureObj, bufferEncoding, function(convertedObj){ var base64String = Buffer.from(JSON.stringify(convertedObj)).toString('base64') return cb(null, base64String) }) } else { var convertedObj = convertBuffersToStrings(clonedSignatureObj, bufferEncoding) var base64String = Buffer.from(JSON.stringify(convertedObj)).toString('base64') return base64String } }
[ "function", "(", "signatureObject", ",", "publicKey", ",", "bufferEncoding", "=", "DEFAULT_ENCODING", ",", "cb", "=", "null", ")", "{", "var", "clonedSignatureObj", "=", "{", "signature", ":", "signatureObject", ".", "signature", ",", "recovery", ":", "signatureObject", ".", "recovery", ",", "publicKey", ":", "publicKey", "}", "bufferEncoding", "=", "getEncodingOrDefault", "(", "bufferEncoding", ")", "if", "(", "isFunction", "(", "cb", ")", ")", "{", "convertBuffersToStrings", "(", "clonedSignatureObj", ",", "bufferEncoding", ",", "function", "(", "convertedObj", ")", "{", "var", "base64String", "=", "Buffer", ".", "from", "(", "JSON", ".", "stringify", "(", "convertedObj", ")", ")", ".", "toString", "(", "'base64'", ")", "return", "cb", "(", "null", ",", "base64String", ")", "}", ")", "}", "else", "{", "var", "convertedObj", "=", "convertBuffersToStrings", "(", "clonedSignatureObj", ",", "bufferEncoding", ")", "var", "base64String", "=", "Buffer", ".", "from", "(", "JSON", ".", "stringify", "(", "convertedObj", ")", ")", ".", "toString", "(", "'base64'", ")", "return", "base64String", "}", "}" ]
creates a new object containing the values of the signature object plus the public key, encoded as a base64 string @param {Object} signatureObject the signature object containing signature and recovery @param {Buffer} publicKey the ethereum public key for later signature verification @param {String} bufferEncoding (optional) the encoding to be used for remaining buffers @param {Function} cb (optional) callback function @return {String} Base64-encoded String representation of the input
[ "creates", "a", "new", "object", "containing", "the", "values", "of", "the", "signature", "object", "plus", "the", "public", "key", "encoded", "as", "a", "base64", "string" ]
9a838d454f862e674a505a09dd31cef93f727b4f
https://github.com/cp2017/sign/blob/9a838d454f862e674a505a09dd31cef93f727b4f/index.js#L190-L207
51,978
cp2017/sign
index.js
function(base64String, bufferEncoding = DEFAULT_ENCODING, cb = null){ bufferEncoding = getEncodingOrDefault(bufferEncoding) var decodedObj = JSON.parse(Buffer.from(base64String, 'base64').toString()) var result = {} if('signature' in decodedObj && 'recovery' in decodedObj){ result = decodedObj result.signature = Buffer.from(result.signature, bufferEncoding) if('publicKey' in decodedObj){ result.publicKey = Buffer.from(result.publicKey, bufferEncoding) } } else { result = new Error("decoded object does not contain all required elements!") } if(isFunction(cb)){ if(result instanceof Error){ return cb(result) } else { return cb(null, result) } } else { return result } }
javascript
function(base64String, bufferEncoding = DEFAULT_ENCODING, cb = null){ bufferEncoding = getEncodingOrDefault(bufferEncoding) var decodedObj = JSON.parse(Buffer.from(base64String, 'base64').toString()) var result = {} if('signature' in decodedObj && 'recovery' in decodedObj){ result = decodedObj result.signature = Buffer.from(result.signature, bufferEncoding) if('publicKey' in decodedObj){ result.publicKey = Buffer.from(result.publicKey, bufferEncoding) } } else { result = new Error("decoded object does not contain all required elements!") } if(isFunction(cb)){ if(result instanceof Error){ return cb(result) } else { return cb(null, result) } } else { return result } }
[ "function", "(", "base64String", ",", "bufferEncoding", "=", "DEFAULT_ENCODING", ",", "cb", "=", "null", ")", "{", "bufferEncoding", "=", "getEncodingOrDefault", "(", "bufferEncoding", ")", "var", "decodedObj", "=", "JSON", ".", "parse", "(", "Buffer", ".", "from", "(", "base64String", ",", "'base64'", ")", ".", "toString", "(", ")", ")", "var", "result", "=", "{", "}", "if", "(", "'signature'", "in", "decodedObj", "&&", "'recovery'", "in", "decodedObj", ")", "{", "result", "=", "decodedObj", "result", ".", "signature", "=", "Buffer", ".", "from", "(", "result", ".", "signature", ",", "bufferEncoding", ")", "if", "(", "'publicKey'", "in", "decodedObj", ")", "{", "result", ".", "publicKey", "=", "Buffer", ".", "from", "(", "result", ".", "publicKey", ",", "bufferEncoding", ")", "}", "}", "else", "{", "result", "=", "new", "Error", "(", "\"decoded object does not contain all required elements!\"", ")", "}", "if", "(", "isFunction", "(", "cb", ")", ")", "{", "if", "(", "result", "instanceof", "Error", ")", "{", "return", "cb", "(", "result", ")", "}", "else", "{", "return", "cb", "(", "null", ",", "result", ")", "}", "}", "else", "{", "return", "result", "}", "}" ]
recover signature object from base64-encoded string @param {String} base64String String to decode @param {String} bufferEncoding encoding for recovering the buffers inside the object @param {Function} cb callback function @return {Object} Signature object recovered from the input string, or Error object if an error occured
[ "recover", "signature", "object", "from", "base64", "-", "encoded", "string" ]
9a838d454f862e674a505a09dd31cef93f727b4f
https://github.com/cp2017/sign/blob/9a838d454f862e674a505a09dd31cef93f727b4f/index.js#L215-L238
51,979
webcredits/wc_db
lib/db.js
getConnection
function getConnection (config) { var sequelize var defaultStorage = 'store.db' var logging = config.logging || false if (config.dialect === 'sqlite') { if (!config.storage) { config.storage = defaultStorage } sequelize = new Sequelize(config.database, config.username, config.password, { host: config.host, dialect: config.dialect, storage: config.storage, logging: logging }) } else { sequelize = new Sequelize(config.database, config.username, config.password, { host: config.host, dialect: config.dialect, logging: logging }) } return sequelize }
javascript
function getConnection (config) { var sequelize var defaultStorage = 'store.db' var logging = config.logging || false if (config.dialect === 'sqlite') { if (!config.storage) { config.storage = defaultStorage } sequelize = new Sequelize(config.database, config.username, config.password, { host: config.host, dialect: config.dialect, storage: config.storage, logging: logging }) } else { sequelize = new Sequelize(config.database, config.username, config.password, { host: config.host, dialect: config.dialect, logging: logging }) } return sequelize }
[ "function", "getConnection", "(", "config", ")", "{", "var", "sequelize", "var", "defaultStorage", "=", "'store.db'", "var", "logging", "=", "config", ".", "logging", "||", "false", "if", "(", "config", ".", "dialect", "===", "'sqlite'", ")", "{", "if", "(", "!", "config", ".", "storage", ")", "{", "config", ".", "storage", "=", "defaultStorage", "}", "sequelize", "=", "new", "Sequelize", "(", "config", ".", "database", ",", "config", ".", "username", ",", "config", ".", "password", ",", "{", "host", ":", "config", ".", "host", ",", "dialect", ":", "config", ".", "dialect", ",", "storage", ":", "config", ".", "storage", ",", "logging", ":", "logging", "}", ")", "}", "else", "{", "sequelize", "=", "new", "Sequelize", "(", "config", ".", "database", ",", "config", ".", "username", ",", "config", ".", "password", ",", "{", "host", ":", "config", ".", "host", ",", "dialect", ":", "config", ".", "dialect", ",", "logging", ":", "logging", "}", ")", "}", "return", "sequelize", "}" ]
Setup database. @param {Object} config The config object. @param {string} config.dialect The db dialect sqlite | mysql. @param {string} config.host The db host. @param {string} config.database The db database name. @param {string} config.username The db username. @param {string} config.password The db password. @return {Object} Sequelize db object.
[ "Setup", "database", "." ]
a3232a69d31f03da071f6f8a26169ce386b1c231
https://github.com/webcredits/wc_db/blob/a3232a69d31f03da071f6f8a26169ce386b1c231/lib/db.js#L19-L43
51,980
webcredits/wc_db
lib/db.js
runSQL
function runSQL (sql, config, conn, replacements) { return new Promise(function (resolve, reject) { if (!config && !conn) { reject('Must set config or connection') } if (!sql) { reject('Need some sql') } if (!conn) { conn = getConnection(config) } replacements = replacements || {} conn.query(sql, { replacements: replacements }).then(function (ret) { return resolve({'ret': ret, 'conn': conn}) }).catch(function (err) { return reject(err) }) }) }
javascript
function runSQL (sql, config, conn, replacements) { return new Promise(function (resolve, reject) { if (!config && !conn) { reject('Must set config or connection') } if (!sql) { reject('Need some sql') } if (!conn) { conn = getConnection(config) } replacements = replacements || {} conn.query(sql, { replacements: replacements }).then(function (ret) { return resolve({'ret': ret, 'conn': conn}) }).catch(function (err) { return reject(err) }) }) }
[ "function", "runSQL", "(", "sql", ",", "config", ",", "conn", ",", "replacements", ")", "{", "return", "new", "Promise", "(", "function", "(", "resolve", ",", "reject", ")", "{", "if", "(", "!", "config", "&&", "!", "conn", ")", "{", "reject", "(", "'Must set config or connection'", ")", "}", "if", "(", "!", "sql", ")", "{", "reject", "(", "'Need some sql'", ")", "}", "if", "(", "!", "conn", ")", "{", "conn", "=", "getConnection", "(", "config", ")", "}", "replacements", "=", "replacements", "||", "{", "}", "conn", ".", "query", "(", "sql", ",", "{", "replacements", ":", "replacements", "}", ")", ".", "then", "(", "function", "(", "ret", ")", "{", "return", "resolve", "(", "{", "'ret'", ":", "ret", ",", "'conn'", ":", "conn", "}", ")", "}", ")", ".", "catch", "(", "function", "(", "err", ")", "{", "return", "reject", "(", "err", ")", "}", ")", "}", ")", "}" ]
Run SQL as promise @param {string} sql The SQL to run @param {Object} config The config object. @param {string} config.dialect The db dialect sqlite | mysql. @param {string} config.host The db host. @param {string} config.database The db database name. @param {string} config.username The db username. @param {string} config.password The db password. @param {Object} conn Sequelize connection. @param {Object} replacements Possiblle replacements. @return {Object} Promise
[ "Run", "SQL", "as", "promise" ]
a3232a69d31f03da071f6f8a26169ce386b1c231
https://github.com/webcredits/wc_db/blob/a3232a69d31f03da071f6f8a26169ce386b1c231/lib/db.js#L58-L80
51,981
commenthol/mergee
index.js
_checkCircular
function _checkCircular (opts, obj) { var key if (util.isObject(obj)) { if (~opts._visited.indexOf(obj)) { return true } opts._visited.push(obj) for (key in obj) { if (obj.hasOwnProperty(key) && _checkCircular(opts, obj[key])) { return true } } } return false }
javascript
function _checkCircular (opts, obj) { var key if (util.isObject(obj)) { if (~opts._visited.indexOf(obj)) { return true } opts._visited.push(obj) for (key in obj) { if (obj.hasOwnProperty(key) && _checkCircular(opts, obj[key])) { return true } } } return false }
[ "function", "_checkCircular", "(", "opts", ",", "obj", ")", "{", "var", "key", "if", "(", "util", ".", "isObject", "(", "obj", ")", ")", "{", "if", "(", "~", "opts", ".", "_visited", ".", "indexOf", "(", "obj", ")", ")", "{", "return", "true", "}", "opts", ".", "_visited", ".", "push", "(", "obj", ")", "for", "(", "key", "in", "obj", ")", "{", "if", "(", "obj", ".", "hasOwnProperty", "(", "key", ")", "&&", "_checkCircular", "(", "opts", ",", "obj", "[", "key", "]", ")", ")", "{", "return", "true", "}", "}", "}", "return", "false", "}" ]
recursive helper function @api private
[ "recursive", "helper", "function" ]
a4c42223b59b184c8a3034c0be49f0067634ac71
https://github.com/commenthol/mergee/blob/a4c42223b59b184c8a3034c0be49f0067634ac71/index.js#L54-L68
51,982
commenthol/mergee
index.js
merge
function merge () { var args = [].slice.call(arguments) args.unshift({}) return mergeExt.apply(null, args) }
javascript
function merge () { var args = [].slice.call(arguments) args.unshift({}) return mergeExt.apply(null, args) }
[ "function", "merge", "(", ")", "{", "var", "args", "=", "[", "]", ".", "slice", ".", "call", "(", "arguments", ")", "args", ".", "unshift", "(", "{", "}", ")", "return", "mergeExt", ".", "apply", "(", "null", ",", "args", ")", "}" ]
merge multiple objects into `target` #### Example ````js var merge = require('mergee').merge, target = { t: 1, x: { y: 'z' } }, source1 = { t: { s1: /source1/ } }, source2 = { t: { s2: new Date(100), x: null } }; merge(target, source1, source2); // target === { t: { s1: /source1/, s2: Wed Dec 31 1969 17:00:00 GMT-0700 (MST) }, x: null } ```` @param {Object|Function|Array} target - target object @param {Any} source - arguments 2 ... n @return {Object} merged target
[ "merge", "multiple", "objects", "into", "target" ]
a4c42223b59b184c8a3034c0be49f0067634ac71
https://github.com/commenthol/mergee/blob/a4c42223b59b184c8a3034c0be49f0067634ac71/index.js#L124-L128
51,983
commenthol/mergee
index.js
_segment
function _segment (char) { var tmp char = char || '.' return function (k) { if (tmp) { tmp += char + k if (CLOSE.test(k)) { k = tmp tmp = '' } else { return } } else if (OPEN.test(k)) { tmp = k if (CLOSE.test(k)) { tmp = '' } else { return } } return k.trim().replace(QUOTES, '$2') } }
javascript
function _segment (char) { var tmp char = char || '.' return function (k) { if (tmp) { tmp += char + k if (CLOSE.test(k)) { k = tmp tmp = '' } else { return } } else if (OPEN.test(k)) { tmp = k if (CLOSE.test(k)) { tmp = '' } else { return } } return k.trim().replace(QUOTES, '$2') } }
[ "function", "_segment", "(", "char", ")", "{", "var", "tmp", "char", "=", "char", "||", "'.'", "return", "function", "(", "k", ")", "{", "if", "(", "tmp", ")", "{", "tmp", "+=", "char", "+", "k", "if", "(", "CLOSE", ".", "test", "(", "k", ")", ")", "{", "k", "=", "tmp", "tmp", "=", "''", "}", "else", "{", "return", "}", "}", "else", "if", "(", "OPEN", ".", "test", "(", "k", ")", ")", "{", "tmp", "=", "k", "if", "(", "CLOSE", ".", "test", "(", "k", ")", ")", "{", "tmp", "=", "''", "}", "else", "{", "return", "}", "}", "return", "k", ".", "trim", "(", ")", ".", "replace", "(", "QUOTES", ",", "'$2'", ")", "}", "}" ]
segment path or properties string @api private @param {String} char - separator char @return {Function}
[ "segment", "path", "or", "properties", "string" ]
a4c42223b59b184c8a3034c0be49f0067634ac71
https://github.com/commenthol/mergee/blob/a4c42223b59b184c8a3034c0be49f0067634ac71/index.js#L322-L344
51,984
commenthol/mergee
index.js
_splitPath
function _splitPath (keys) { var out if (util.isString(keys)) { out = [] keys .split('.') .map(_segment('.')) .forEach(function (k) { k = (k || ' ').trim() .replace(/^([^[]+)\[(["']?)(.+)\2\]$/, function (m, m1, m2, m3) { if (m1 && m3) { out.push(m1, m3) } return '' }) if (k) { out.push(k) } }) keys = out } return keys }
javascript
function _splitPath (keys) { var out if (util.isString(keys)) { out = [] keys .split('.') .map(_segment('.')) .forEach(function (k) { k = (k || ' ').trim() .replace(/^([^[]+)\[(["']?)(.+)\2\]$/, function (m, m1, m2, m3) { if (m1 && m3) { out.push(m1, m3) } return '' }) if (k) { out.push(k) } }) keys = out } return keys }
[ "function", "_splitPath", "(", "keys", ")", "{", "var", "out", "if", "(", "util", ".", "isString", "(", "keys", ")", ")", "{", "out", "=", "[", "]", "keys", ".", "split", "(", "'.'", ")", ".", "map", "(", "_segment", "(", "'.'", ")", ")", ".", "forEach", "(", "function", "(", "k", ")", "{", "k", "=", "(", "k", "||", "' '", ")", ".", "trim", "(", ")", ".", "replace", "(", "/", "^([^[]+)\\[([\"']?)(.+)\\2\\]$", "/", ",", "function", "(", "m", ",", "m1", ",", "m2", ",", "m3", ")", "{", "if", "(", "m1", "&&", "m3", ")", "{", "out", ".", "push", "(", "m1", ",", "m3", ")", "}", "return", "''", "}", ")", "if", "(", "k", ")", "{", "out", ".", "push", "(", "k", ")", "}", "}", ")", "keys", "=", "out", "}", "return", "keys", "}" ]
split dot separated String or Array into a property path @private @param {Array|String} keys @return {Object} obj for comparison
[ "split", "dot", "separated", "String", "or", "Array", "into", "a", "property", "path" ]
a4c42223b59b184c8a3034c0be49f0067634ac71
https://github.com/commenthol/mergee/blob/a4c42223b59b184c8a3034c0be49f0067634ac71/index.js#L352-L375
51,985
commenthol/mergee
index.js
_splitProps
function _splitProps (props) { var test = {} if (util.isString(props)) { props = props .split(',') .map(_segment(',')) .filter(function (k) { return k }) } if (util.isArray(props)) { props.forEach(function (key) { test[key] = 1 }) return test } return {} }
javascript
function _splitProps (props) { var test = {} if (util.isString(props)) { props = props .split(',') .map(_segment(',')) .filter(function (k) { return k }) } if (util.isArray(props)) { props.forEach(function (key) { test[key] = 1 }) return test } return {} }
[ "function", "_splitProps", "(", "props", ")", "{", "var", "test", "=", "{", "}", "if", "(", "util", ".", "isString", "(", "props", ")", ")", "{", "props", "=", "props", ".", "split", "(", "','", ")", ".", "map", "(", "_segment", "(", "','", ")", ")", ".", "filter", "(", "function", "(", "k", ")", "{", "return", "k", "}", ")", "}", "if", "(", "util", ".", "isArray", "(", "props", ")", ")", "{", "props", ".", "forEach", "(", "function", "(", "key", ")", "{", "test", "[", "key", "]", "=", "1", "}", ")", "return", "test", "}", "return", "{", "}", "}" ]
split comma separated String or Array into a test hash @private @param {Array|String} keys @return {Object} obj for comparison
[ "split", "comma", "separated", "String", "or", "Array", "into", "a", "test", "hash" ]
a4c42223b59b184c8a3034c0be49f0067634ac71
https://github.com/commenthol/mergee/blob/a4c42223b59b184c8a3034c0be49f0067634ac71/index.js#L384-L402
51,986
commenthol/mergee
index.js
pick
function pick (obj, props) { var key var val var out var test = _splitProps(props) if (util.isObject(obj)) { out = {} for (key in test) { val = get(obj, key) if (val !== undefined && val !== null) { set(out, key, val) } } } return out }
javascript
function pick (obj, props) { var key var val var out var test = _splitProps(props) if (util.isObject(obj)) { out = {} for (key in test) { val = get(obj, key) if (val !== undefined && val !== null) { set(out, key, val) } } } return out }
[ "function", "pick", "(", "obj", ",", "props", ")", "{", "var", "key", "var", "val", "var", "out", "var", "test", "=", "_splitProps", "(", "props", ")", "if", "(", "util", ".", "isObject", "(", "obj", ")", ")", "{", "out", "=", "{", "}", "for", "(", "key", "in", "test", ")", "{", "val", "=", "get", "(", "obj", ",", "key", ")", "if", "(", "val", "!==", "undefined", "&&", "val", "!==", "null", ")", "{", "set", "(", "out", ",", "key", ",", "val", ")", "}", "}", "}", "return", "out", "}" ]
pick properties from `obj` into a new object #### Example ```js var r, pick = require('mergee').pick, obj = { a: 1, b: [ 1, 2 ], c: { cc:3, 'c-d':4 }, '0d': { '0d0': 5 } }; r = pick(obj, ['a', 'b[1]', 'c["c-d"]', '0d.0d0']); //> r = { a: 1, b: { '1': 2 }, c: { 'c-d': 4 }, '0d': { '0d0': 5 } } r = pick(obj, 'a, b[1], c["c-d"], 0d.0d0'); //> r = { a: 1, b: { '1': 2 }, c: { 'c-d': 4 }, '0d': { '0d0': 5 } } ``` @param {Object} obj - object to pick properties from @param {Array|String} props - Array of properties or comma separated string of properties @return {Object} object with picked properties
[ "pick", "properties", "from", "obj", "into", "a", "new", "object" ]
a4c42223b59b184c8a3034c0be49f0067634ac71
https://github.com/commenthol/mergee/blob/a4c42223b59b184c8a3034c0be49f0067634ac71/index.js#L424-L440
51,987
commenthol/mergee
index.js
omit
function omit (obj, props) { var key var out var test = _splitProps(props) if (util.isObject(obj)) { out = clone(obj) for (key in test) { if ((get(obj, key))) { set(out, key, null) } } } return out }
javascript
function omit (obj, props) { var key var out var test = _splitProps(props) if (util.isObject(obj)) { out = clone(obj) for (key in test) { if ((get(obj, key))) { set(out, key, null) } } } return out }
[ "function", "omit", "(", "obj", ",", "props", ")", "{", "var", "key", "var", "out", "var", "test", "=", "_splitProps", "(", "props", ")", "if", "(", "util", ".", "isObject", "(", "obj", ")", ")", "{", "out", "=", "clone", "(", "obj", ")", "for", "(", "key", "in", "test", ")", "{", "if", "(", "(", "get", "(", "obj", ",", "key", ")", ")", ")", "{", "set", "(", "out", ",", "key", ",", "null", ")", "}", "}", "}", "return", "out", "}" ]
omit properties from `obj` into a new object #### Example ```js var r, omit = require('mergee').omit, obj = { a: 1, b: [ 1, 2 ], c: { cc:3, 'c-d':4 }, '0d': { '0d0': 5 } }; r = omit(obj, ['a', 'b[1]', 'c["c-d"]', '0d.0d0']); // r = { b: [ 1, ], c: { cc: 3 }, '0d': {} } r = omit(obj, 'a, b[1], c["c-d"], 0d.0d0'); // r = { b: [ 1, ], c: { cc: 3 }, '0d': {} } ``` @param {Object} obj - object @param {Array|String} props - Array of properties or comma separated string of properties @return {Object} object with omitted properties
[ "omit", "properties", "from", "obj", "into", "a", "new", "object" ]
a4c42223b59b184c8a3034c0be49f0067634ac71
https://github.com/commenthol/mergee/blob/a4c42223b59b184c8a3034c0be49f0067634ac71/index.js#L462-L476
51,988
commenthol/mergee
index.js
get
function get (obj, keys, _default) { var i var key var tmp = obj || {} keys = _splitPath(keys) if (!keys || keys.length === 0) { return _default } for (i = 0; i < keys.length; i++) { key = keys[i] if (tmp && tmp.hasOwnProperty(key)) { tmp = tmp[key] } else { return _default } } return tmp }
javascript
function get (obj, keys, _default) { var i var key var tmp = obj || {} keys = _splitPath(keys) if (!keys || keys.length === 0) { return _default } for (i = 0; i < keys.length; i++) { key = keys[i] if (tmp && tmp.hasOwnProperty(key)) { tmp = tmp[key] } else { return _default } } return tmp }
[ "function", "get", "(", "obj", ",", "keys", ",", "_default", ")", "{", "var", "i", "var", "key", "var", "tmp", "=", "obj", "||", "{", "}", "keys", "=", "_splitPath", "(", "keys", ")", "if", "(", "!", "keys", "||", "keys", ".", "length", "===", "0", ")", "{", "return", "_default", "}", "for", "(", "i", "=", "0", ";", "i", "<", "keys", ".", "length", ";", "i", "++", ")", "{", "key", "=", "keys", "[", "i", "]", "if", "(", "tmp", "&&", "tmp", ".", "hasOwnProperty", "(", "key", ")", ")", "{", "tmp", "=", "tmp", "[", "key", "]", "}", "else", "{", "return", "_default", "}", "}", "return", "tmp", "}" ]
get properties from `obj` #### Example ```js var r, get = require('mergee').get, obj = { a: { b: { c: 1 } } }; r = get(obj, ['a', 'b', 'c']); // r = 1 r = get(obj, 'a.b'); // r = { c: 1 } r = get(obj, 'there.is.no.such.property'); // this will not throw! // r = undefined ``` @param {Object} obj - object to select from @param {Array|String} keys - Array of properties or dot separated string of properties; If using a String avoid using property names containing a `.` @return {Object} selected object
[ "get", "properties", "from", "obj" ]
a4c42223b59b184c8a3034c0be49f0067634ac71
https://github.com/commenthol/mergee/blob/a4c42223b59b184c8a3034c0be49f0067634ac71/index.js#L501-L521
51,989
commenthol/mergee
index.js
set
function set (obj, keys, value) { var i var key var last var tmp = obj || {} keys = _splitPath(keys) if (!keys || keys.length === 0) { return } last = keys.pop() for (i = 0; i < keys.length; i++) { key = keys[i] if (!tmp[key]) { tmp[key] = {} } if (tmp.hasOwnProperty(key)) { tmp = tmp[key] } } if (value === null) { delete (tmp[last]) } else { tmp[last] = value } return obj }
javascript
function set (obj, keys, value) { var i var key var last var tmp = obj || {} keys = _splitPath(keys) if (!keys || keys.length === 0) { return } last = keys.pop() for (i = 0; i < keys.length; i++) { key = keys[i] if (!tmp[key]) { tmp[key] = {} } if (tmp.hasOwnProperty(key)) { tmp = tmp[key] } } if (value === null) { delete (tmp[last]) } else { tmp[last] = value } return obj }
[ "function", "set", "(", "obj", ",", "keys", ",", "value", ")", "{", "var", "i", "var", "key", "var", "last", "var", "tmp", "=", "obj", "||", "{", "}", "keys", "=", "_splitPath", "(", "keys", ")", "if", "(", "!", "keys", "||", "keys", ".", "length", "===", "0", ")", "{", "return", "}", "last", "=", "keys", ".", "pop", "(", ")", "for", "(", "i", "=", "0", ";", "i", "<", "keys", ".", "length", ";", "i", "++", ")", "{", "key", "=", "keys", "[", "i", "]", "if", "(", "!", "tmp", "[", "key", "]", ")", "{", "tmp", "[", "key", "]", "=", "{", "}", "}", "if", "(", "tmp", ".", "hasOwnProperty", "(", "key", ")", ")", "{", "tmp", "=", "tmp", "[", "key", "]", "}", "}", "if", "(", "value", "===", "null", ")", "{", "delete", "(", "tmp", "[", "last", "]", ")", "}", "else", "{", "tmp", "[", "last", "]", "=", "value", "}", "return", "obj", "}" ]
set a property in `obj` #### Example ```js var r, set = require('mergee').set, obj = {}; r = set(obj, ['a', 'b'], { c:1 }); //> r = { a: { b: { c: 1 } } } r = set(obj, 'a.b.d', 2); //> r = { a: { b: { c:1, d:2 } } } ``` @param {Object} obj - object to select from @param {Array|String} keys - Array of properties or dot separated string of properties; If using a String avoid using property names containing a `.` @param {Any} value - The value to set @return {Object} set object
[ "set", "a", "property", "in", "obj" ]
a4c42223b59b184c8a3034c0be49f0067634ac71
https://github.com/commenthol/mergee/blob/a4c42223b59b184c8a3034c0be49f0067634ac71/index.js#L550-L579
51,990
rowanmanning/chic-event
lib/chic-event.js
arrayIndexOf
function arrayIndexOf (array, val) { // Use native indexOf if (Array.prototype.indexOf) { return array.indexOf(val); } // Use loop/if for environments without native indexOf var i, len = array.length; for (i = 0; i < len; len += 1) { if (array[i] === val) { return i; } } return -1; }
javascript
function arrayIndexOf (array, val) { // Use native indexOf if (Array.prototype.indexOf) { return array.indexOf(val); } // Use loop/if for environments without native indexOf var i, len = array.length; for (i = 0; i < len; len += 1) { if (array[i] === val) { return i; } } return -1; }
[ "function", "arrayIndexOf", "(", "array", ",", "val", ")", "{", "// Use native indexOf", "if", "(", "Array", ".", "prototype", ".", "indexOf", ")", "{", "return", "array", ".", "indexOf", "(", "val", ")", ";", "}", "// Use loop/if for environments without native indexOf", "var", "i", ",", "len", "=", "array", ".", "length", ";", "for", "(", "i", "=", "0", ";", "i", "<", "len", ";", "len", "+=", "1", ")", "{", "if", "(", "array", "[", "i", "]", "===", "val", ")", "{", "return", "i", ";", "}", "}", "return", "-", "1", ";", "}" ]
Utilities Get the index of the first instance of a value in an array
[ "Utilities", "Get", "the", "index", "of", "the", "first", "instance", "of", "a", "value", "in", "an", "array" ]
0911e4211be2615ddb06a797e0fe57480cf06972
https://github.com/rowanmanning/chic-event/blob/0911e4211be2615ddb06a797e0fe57480cf06972/lib/chic-event.js#L21-L37
51,991
rowanmanning/chic-event
lib/chic-event.js
function (type, handler) { // Validate arguments if (typeof type !== 'string') { throw new Error('Type must be a string'); } if (typeof handler !== 'function') { throw new Error('Handler must be a function'); } // Check for presence of event store if (!this._events) { this._events = {}; } if (!this._events[type]) { this._events[type] = []; } // Add handler this._events[type].push(handler); }
javascript
function (type, handler) { // Validate arguments if (typeof type !== 'string') { throw new Error('Type must be a string'); } if (typeof handler !== 'function') { throw new Error('Handler must be a function'); } // Check for presence of event store if (!this._events) { this._events = {}; } if (!this._events[type]) { this._events[type] = []; } // Add handler this._events[type].push(handler); }
[ "function", "(", "type", ",", "handler", ")", "{", "// Validate arguments", "if", "(", "typeof", "type", "!==", "'string'", ")", "{", "throw", "new", "Error", "(", "'Type must be a string'", ")", ";", "}", "if", "(", "typeof", "handler", "!==", "'function'", ")", "{", "throw", "new", "Error", "(", "'Handler must be a function'", ")", ";", "}", "// Check for presence of event store", "if", "(", "!", "this", ".", "_events", ")", "{", "this", ".", "_events", "=", "{", "}", ";", "}", "if", "(", "!", "this", ".", "_events", "[", "type", "]", ")", "{", "this", ".", "_events", "[", "type", "]", "=", "[", "]", ";", "}", "// Add handler", "this", ".", "_events", "[", "type", "]", ".", "push", "(", "handler", ")", ";", "}" ]
Bind a handler to an event
[ "Bind", "a", "handler", "to", "an", "event" ]
0911e4211be2615ddb06a797e0fe57480cf06972
https://github.com/rowanmanning/chic-event/blob/0911e4211be2615ddb06a797e0fe57480cf06972/lib/chic-event.js#L70-L91
51,992
rowanmanning/chic-event
lib/chic-event.js
function (type, handler) { // Validate arguments if (typeof type !== 'undefined' && typeof type !== 'string') { throw new Error('Type must be a string or undefined'); } if (typeof handler !== 'undefined' && typeof handler !== 'function') { throw new Error('Handler must be a function or undefined'); } // If no type is given, remove all handlers if (!type) { return delete this._events; } // Check for presence of event store if (!this._events || !this._events[type]) { return; } // If no handler is given, remove all handlers for this type if (!handler) { return delete this._events[type]; } // Do we have a matching handler? var handlers = this._events[type]; var i = arrayIndexOf(handlers, handler); if (i === -1) { return; } // Remove handler handlers.splice(i, 1); }
javascript
function (type, handler) { // Validate arguments if (typeof type !== 'undefined' && typeof type !== 'string') { throw new Error('Type must be a string or undefined'); } if (typeof handler !== 'undefined' && typeof handler !== 'function') { throw new Error('Handler must be a function or undefined'); } // If no type is given, remove all handlers if (!type) { return delete this._events; } // Check for presence of event store if (!this._events || !this._events[type]) { return; } // If no handler is given, remove all handlers for this type if (!handler) { return delete this._events[type]; } // Do we have a matching handler? var handlers = this._events[type]; var i = arrayIndexOf(handlers, handler); if (i === -1) { return; } // Remove handler handlers.splice(i, 1); }
[ "function", "(", "type", ",", "handler", ")", "{", "// Validate arguments", "if", "(", "typeof", "type", "!==", "'undefined'", "&&", "typeof", "type", "!==", "'string'", ")", "{", "throw", "new", "Error", "(", "'Type must be a string or undefined'", ")", ";", "}", "if", "(", "typeof", "handler", "!==", "'undefined'", "&&", "typeof", "handler", "!==", "'function'", ")", "{", "throw", "new", "Error", "(", "'Handler must be a function or undefined'", ")", ";", "}", "// If no type is given, remove all handlers", "if", "(", "!", "type", ")", "{", "return", "delete", "this", ".", "_events", ";", "}", "// Check for presence of event store", "if", "(", "!", "this", ".", "_events", "||", "!", "this", ".", "_events", "[", "type", "]", ")", "{", "return", ";", "}", "// If no handler is given, remove all handlers for this type", "if", "(", "!", "handler", ")", "{", "return", "delete", "this", ".", "_events", "[", "type", "]", ";", "}", "// Do we have a matching handler?", "var", "handlers", "=", "this", ".", "_events", "[", "type", "]", ";", "var", "i", "=", "arrayIndexOf", "(", "handlers", ",", "handler", ")", ";", "if", "(", "i", "===", "-", "1", ")", "{", "return", ";", "}", "// Remove handler", "handlers", ".", "splice", "(", "i", ",", "1", ")", ";", "}" ]
Unbind handlers from events
[ "Unbind", "handlers", "from", "events" ]
0911e4211be2615ddb06a797e0fe57480cf06972
https://github.com/rowanmanning/chic-event/blob/0911e4211be2615ddb06a797e0fe57480cf06972/lib/chic-event.js#L94-L129
51,993
rowanmanning/chic-event
lib/chic-event.js
function (type, event) { // Validate arguments if (typeof type !== 'string') { throw new Error('Type must be a string'); } // Check for presence of event store if (!this._events || !this._events[type]) { return; } // Get handlers var handlers = this._events[type]; // Build event if (!(event instanceof Event)) { var data = event; event = new Event(data); } event.type = type; event.target = this; // Loop and call handlers var i, len = handlers.length; for (i = 0; i < len; i += 1) { handlers[i].call(this, event); // Prevent further handlers from being called if event is stopped if (event.stopped()) { break; } } }
javascript
function (type, event) { // Validate arguments if (typeof type !== 'string') { throw new Error('Type must be a string'); } // Check for presence of event store if (!this._events || !this._events[type]) { return; } // Get handlers var handlers = this._events[type]; // Build event if (!(event instanceof Event)) { var data = event; event = new Event(data); } event.type = type; event.target = this; // Loop and call handlers var i, len = handlers.length; for (i = 0; i < len; i += 1) { handlers[i].call(this, event); // Prevent further handlers from being called if event is stopped if (event.stopped()) { break; } } }
[ "function", "(", "type", ",", "event", ")", "{", "// Validate arguments", "if", "(", "typeof", "type", "!==", "'string'", ")", "{", "throw", "new", "Error", "(", "'Type must be a string'", ")", ";", "}", "// Check for presence of event store", "if", "(", "!", "this", ".", "_events", "||", "!", "this", ".", "_events", "[", "type", "]", ")", "{", "return", ";", "}", "// Get handlers", "var", "handlers", "=", "this", ".", "_events", "[", "type", "]", ";", "// Build event", "if", "(", "!", "(", "event", "instanceof", "Event", ")", ")", "{", "var", "data", "=", "event", ";", "event", "=", "new", "Event", "(", "data", ")", ";", "}", "event", ".", "type", "=", "type", ";", "event", ".", "target", "=", "this", ";", "// Loop and call handlers", "var", "i", ",", "len", "=", "handlers", ".", "length", ";", "for", "(", "i", "=", "0", ";", "i", "<", "len", ";", "i", "+=", "1", ")", "{", "handlers", "[", "i", "]", ".", "call", "(", "this", ",", "event", ")", ";", "// Prevent further handlers from being called if event is stopped", "if", "(", "event", ".", "stopped", "(", ")", ")", "{", "break", ";", "}", "}", "}" ]
Emit an event
[ "Emit", "an", "event" ]
0911e4211be2615ddb06a797e0fe57480cf06972
https://github.com/rowanmanning/chic-event/blob/0911e4211be2615ddb06a797e0fe57480cf06972/lib/chic-event.js#L132-L164
51,994
doowb/macro-store
lib/store.js
Store
function Store(options) { if (!(this instanceof Store)) { return new Store(options); } if (typeof options === 'string') { options = { name: options }; } options = options || {}; var name = options.name || 'macros'; this.store = options.store || new utils.Store(name); }
javascript
function Store(options) { if (!(this instanceof Store)) { return new Store(options); } if (typeof options === 'string') { options = { name: options }; } options = options || {}; var name = options.name || 'macros'; this.store = options.store || new utils.Store(name); }
[ "function", "Store", "(", "options", ")", "{", "if", "(", "!", "(", "this", "instanceof", "Store", ")", ")", "{", "return", "new", "Store", "(", "options", ")", ";", "}", "if", "(", "typeof", "options", "===", "'string'", ")", "{", "options", "=", "{", "name", ":", "options", "}", ";", "}", "options", "=", "options", "||", "{", "}", ";", "var", "name", "=", "options", ".", "name", "||", "'macros'", ";", "this", ".", "store", "=", "options", ".", "store", "||", "new", "utils", ".", "Store", "(", "name", ")", ";", "}" ]
Initialize a new `Store` with the given `options`. ```js var macroStore = new Store(); //=> '~/data-store/macros.json' var macroStore = new Store({name: 'abc'}); //=> '~/data-store/abc.json' ``` @param {Object} `options` @param {String} `options.name` Name of the json file to use for storing macros. Defaults to 'macros' @param {Object} `options.store` Instance of [data-store][] to use. Allows complete control over where the store is located. @api public
[ "Initialize", "a", "new", "Store", "with", "the", "given", "options", "." ]
29cb4f578e162aab5acedc72a313d97694d58a33
https://github.com/doowb/macro-store/blob/29cb4f578e162aab5acedc72a313d97694d58a33/lib/store.js#L30-L41
51,995
milojs/ml-mixin
lib/mixin.js
_createProxyMethod
function _createProxyMethod(proxyMethodName, mixinMethodName, hostObject) { hostObject = hostObject || this._hostObject; // Mixin class does not allow shadowing methods that exist on the host object if (hostObject[proxyMethodName]) throw new Error('method ' + proxyMethodName + ' already defined in host object'); var method = this[mixinMethodName]; check(method, Function); // Bind proxied Mixin's method to Mixin instance var boundMethod = method.bind(this); Object.defineProperty(hostObject, proxyMethodName, { value: boundMethod, enumerable: false, configurable: false, writable: true }); }
javascript
function _createProxyMethod(proxyMethodName, mixinMethodName, hostObject) { hostObject = hostObject || this._hostObject; // Mixin class does not allow shadowing methods that exist on the host object if (hostObject[proxyMethodName]) throw new Error('method ' + proxyMethodName + ' already defined in host object'); var method = this[mixinMethodName]; check(method, Function); // Bind proxied Mixin's method to Mixin instance var boundMethod = method.bind(this); Object.defineProperty(hostObject, proxyMethodName, { value: boundMethod, enumerable: false, configurable: false, writable: true }); }
[ "function", "_createProxyMethod", "(", "proxyMethodName", ",", "mixinMethodName", ",", "hostObject", ")", "{", "hostObject", "=", "hostObject", "||", "this", ".", "_hostObject", ";", "// Mixin class does not allow shadowing methods that exist on the host object", "if", "(", "hostObject", "[", "proxyMethodName", "]", ")", "throw", "new", "Error", "(", "'method '", "+", "proxyMethodName", "+", "' already defined in host object'", ")", ";", "var", "method", "=", "this", "[", "mixinMethodName", "]", ";", "check", "(", "method", ",", "Function", ")", ";", "// Bind proxied Mixin's method to Mixin instance", "var", "boundMethod", "=", "method", ".", "bind", "(", "this", ")", ";", "Object", ".", "defineProperty", "(", "hostObject", ",", "proxyMethodName", ",", "{", "value", ":", "boundMethod", ",", "enumerable", ":", "false", ",", "configurable", ":", "false", ",", "writable", ":", "true", "}", ")", ";", "}" ]
Creates a proxied method of Mixin subclass on host object. @param {String} mixinMethodName name of method in Mixin subclass @param {String} proxyMethodName name of created proxy method on host object @param {Object} hostObject Optional reference to the host object; if not specified the host object passed to constructor wil be used. It allows to use the same instance of Mixin on two host objects.
[ "Creates", "a", "proxied", "method", "of", "Mixin", "subclass", "on", "host", "object", "." ]
7e6d220d8c8bdd598969edcbbc8886da644b7a24
https://github.com/milojs/ml-mixin/blob/7e6d220d8c8bdd598969edcbbc8886da644b7a24/lib/mixin.js#L69-L89
51,996
milojs/ml-mixin
lib/mixin.js
_createProxyMethods
function _createProxyMethods(proxyMethods, hostObject) { check(proxyMethods, Match.Optional(Match.OneOf([String], Match.ObjectHash(String)))); // creating and binding proxy methods on the host object if (Array.isArray(proxyMethods)) proxyMethods.forEach(function(methodName) { // method called this way to allow using _createProxyMethods with objects // that are not inheriting from Mixin _createProxyMethod.call(this, methodName, methodName, hostObject); }, this); else for (var proxyMethodName in proxyMethods) { // method called this way to allow using _createProxyMethods with objects // that are not inheriting from Mixin if (proxyMethods.hasOwnProperty(proxyMethodName)) { var mixinMethodName = proxyMethods[proxyMethodName]; _createProxyMethod.call(this, proxyMethodName, mixinMethodName, hostObject); } } }
javascript
function _createProxyMethods(proxyMethods, hostObject) { check(proxyMethods, Match.Optional(Match.OneOf([String], Match.ObjectHash(String)))); // creating and binding proxy methods on the host object if (Array.isArray(proxyMethods)) proxyMethods.forEach(function(methodName) { // method called this way to allow using _createProxyMethods with objects // that are not inheriting from Mixin _createProxyMethod.call(this, methodName, methodName, hostObject); }, this); else for (var proxyMethodName in proxyMethods) { // method called this way to allow using _createProxyMethods with objects // that are not inheriting from Mixin if (proxyMethods.hasOwnProperty(proxyMethodName)) { var mixinMethodName = proxyMethods[proxyMethodName]; _createProxyMethod.call(this, proxyMethodName, mixinMethodName, hostObject); } } }
[ "function", "_createProxyMethods", "(", "proxyMethods", ",", "hostObject", ")", "{", "check", "(", "proxyMethods", ",", "Match", ".", "Optional", "(", "Match", ".", "OneOf", "(", "[", "String", "]", ",", "Match", ".", "ObjectHash", "(", "String", ")", ")", ")", ")", ";", "// creating and binding proxy methods on the host object", "if", "(", "Array", ".", "isArray", "(", "proxyMethods", ")", ")", "proxyMethods", ".", "forEach", "(", "function", "(", "methodName", ")", "{", "// method called this way to allow using _createProxyMethods with objects", "// that are not inheriting from Mixin", "_createProxyMethod", ".", "call", "(", "this", ",", "methodName", ",", "methodName", ",", "hostObject", ")", ";", "}", ",", "this", ")", ";", "else", "for", "(", "var", "proxyMethodName", "in", "proxyMethods", ")", "{", "// method called this way to allow using _createProxyMethods with objects", "// that are not inheriting from Mixin", "if", "(", "proxyMethods", ".", "hasOwnProperty", "(", "proxyMethodName", ")", ")", "{", "var", "mixinMethodName", "=", "proxyMethods", "[", "proxyMethodName", "]", ";", "_createProxyMethod", ".", "call", "(", "this", ",", "proxyMethodName", ",", "mixinMethodName", ",", "hostObject", ")", ";", "}", "}", "}" ]
Creates proxied methods of Mixin subclass on host object. @param {Hash[String]|Array[String]} proxyMethods map of names of methods, key - proxy method name, value - mixin method name. Can be array. @param {Object} hostObject an optional reference to the host object; if not specified the host object passed to constructor wil be used. It allows to use the same instance of Mixin on two host objects.
[ "Creates", "proxied", "methods", "of", "Mixin", "subclass", "on", "host", "object", "." ]
7e6d220d8c8bdd598969edcbbc8886da644b7a24
https://github.com/milojs/ml-mixin/blob/7e6d220d8c8bdd598969edcbbc8886da644b7a24/lib/mixin.js#L98-L117
51,997
milojs/ml-mixin
lib/mixin.js
Mixin_setInstanceKey
function Mixin_setInstanceKey(hostClass, method, instanceKey) { check(hostClass, Function); check(instanceKey, Match.IdentifierString); var prop = INSTANCE_PROPERTIES_MAP, instanceKeys = hostClass[prop] = hostClass[prop] || {}; if (instanceKeys[method.name]) throw new Error('Mixin: instance property for method with name ' + method.name + ' is already set'); instanceKeys[method.name] = instanceKey; }
javascript
function Mixin_setInstanceKey(hostClass, method, instanceKey) { check(hostClass, Function); check(instanceKey, Match.IdentifierString); var prop = INSTANCE_PROPERTIES_MAP, instanceKeys = hostClass[prop] = hostClass[prop] || {}; if (instanceKeys[method.name]) throw new Error('Mixin: instance property for method with name ' + method.name + ' is already set'); instanceKeys[method.name] = instanceKey; }
[ "function", "Mixin_setInstanceKey", "(", "hostClass", ",", "method", ",", "instanceKey", ")", "{", "check", "(", "hostClass", ",", "Function", ")", ";", "check", "(", "instanceKey", ",", "Match", ".", "IdentifierString", ")", ";", "var", "prop", "=", "INSTANCE_PROPERTIES_MAP", ",", "instanceKeys", "=", "hostClass", "[", "prop", "]", "=", "hostClass", "[", "prop", "]", "||", "{", "}", ";", "if", "(", "instanceKeys", "[", "method", ".", "name", "]", ")", "throw", "new", "Error", "(", "'Mixin: instance property for method with name '", "+", "method", ".", "name", "+", "' is already set'", ")", ";", "instanceKeys", "[", "method", ".", "name", "]", "=", "instanceKey", ";", "}" ]
Sets mixin instance property name on the host class Can be called only once @private @param {Function} this Mixin subclass (not instance) @param {Function} hostClass @param {String} instanceKey
[ "Sets", "mixin", "instance", "property", "name", "on", "the", "host", "class", "Can", "be", "called", "only", "once" ]
7e6d220d8c8bdd598969edcbbc8886da644b7a24
https://github.com/milojs/ml-mixin/blob/7e6d220d8c8bdd598969edcbbc8886da644b7a24/lib/mixin.js#L129-L141
51,998
milojs/ml-mixin
lib/mixin.js
Mixin_addMethod
function Mixin_addMethod(hostClass, instanceKey, mixinMethodName, hostMethodName) { var method = this.prototype[mixinMethodName]; check(method, Function); var wrappedMethod = _wrapMixinMethod.call(this, method); Object.defineProperty(hostClass.prototype, hostMethodName, { value: wrappedMethod, enumerable: false, configurable: false, writable: true }); Mixin_setInstanceKey(hostClass, method, instanceKey); }
javascript
function Mixin_addMethod(hostClass, instanceKey, mixinMethodName, hostMethodName) { var method = this.prototype[mixinMethodName]; check(method, Function); var wrappedMethod = _wrapMixinMethod.call(this, method); Object.defineProperty(hostClass.prototype, hostMethodName, { value: wrappedMethod, enumerable: false, configurable: false, writable: true }); Mixin_setInstanceKey(hostClass, method, instanceKey); }
[ "function", "Mixin_addMethod", "(", "hostClass", ",", "instanceKey", ",", "mixinMethodName", ",", "hostMethodName", ")", "{", "var", "method", "=", "this", ".", "prototype", "[", "mixinMethodName", "]", ";", "check", "(", "method", ",", "Function", ")", ";", "var", "wrappedMethod", "=", "_wrapMixinMethod", ".", "call", "(", "this", ",", "method", ")", ";", "Object", ".", "defineProperty", "(", "hostClass", ".", "prototype", ",", "hostMethodName", ",", "{", "value", ":", "wrappedMethod", ",", "enumerable", ":", "false", ",", "configurable", ":", "false", ",", "writable", ":", "true", "}", ")", ";", "Mixin_setInstanceKey", "(", "hostClass", ",", "method", ",", "instanceKey", ")", ";", "}" ]
Adds method of Mixin subclass to host class prototype. @private @param {Function} this Mixin subclass (not instance) @param {String} mixinMethodName name of method in Mixin subclass @param {String} hostMethodName (optional) name of created proxy method on host object, same if not specified @param {Object} hostObject object class, must be specified as the last parameter (2nd or 3rd)
[ "Adds", "method", "of", "Mixin", "subclass", "to", "host", "class", "prototype", "." ]
7e6d220d8c8bdd598969edcbbc8886da644b7a24
https://github.com/milojs/ml-mixin/blob/7e6d220d8c8bdd598969edcbbc8886da644b7a24/lib/mixin.js#L153-L167
51,999
milojs/ml-mixin
lib/mixin.js
_wrapMixinMethod
function _wrapMixinMethod(method) { return function() { // ,... arguments var mixinInstance = _getMixinInstance.call(this, method.name); return method.apply(mixinInstance || this, arguments); }; }
javascript
function _wrapMixinMethod(method) { return function() { // ,... arguments var mixinInstance = _getMixinInstance.call(this, method.name); return method.apply(mixinInstance || this, arguments); }; }
[ "function", "_wrapMixinMethod", "(", "method", ")", "{", "return", "function", "(", ")", "{", "// ,... arguments", "var", "mixinInstance", "=", "_getMixinInstance", ".", "call", "(", "this", ",", "method", ".", "name", ")", ";", "return", "method", ".", "apply", "(", "mixinInstance", "||", "this", ",", "arguments", ")", ";", "}", ";", "}" ]
Returns method that will be exposed on the host class prototype @private @param {Function} this Mixin subclass (not instance) @return {Function}
[ "Returns", "method", "that", "will", "be", "exposed", "on", "the", "host", "class", "prototype" ]
7e6d220d8c8bdd598969edcbbc8886da644b7a24
https://github.com/milojs/ml-mixin/blob/7e6d220d8c8bdd598969edcbbc8886da644b7a24/lib/mixin.js#L177-L182