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
|
---|---|---|---|---|---|---|---|---|---|---|---|
57,200 | medic/couchdb-audit | couchdb-audit/log.js | function(doc, callback) {
audit([doc], function(err) {
if (err) {
return callback(err);
}
docsDb.saveDoc(doc, callback);
});
} | javascript | function(doc, callback) {
audit([doc], function(err) {
if (err) {
return callback(err);
}
docsDb.saveDoc(doc, callback);
});
} | [
"function",
"(",
"doc",
",",
"callback",
")",
"{",
"audit",
"(",
"[",
"doc",
"]",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"docsDb",
".",
"saveDoc",
"(",
"doc",
",",
"callback",
")",
";",
"}",
")",
";",
"}"
] | Saves the given doc with an audit record
@name saveDoc(doc, callback)
@param {Object} doc
@param {Function} callback(err,response)
@api public | [
"Saves",
"the",
"given",
"doc",
"with",
"an",
"audit",
"record"
] | 88a2fde06830e91966fc82c7356ec46da043fc01 | https://github.com/medic/couchdb-audit/blob/88a2fde06830e91966fc82c7356ec46da043fc01/couchdb-audit/log.js#L200-L207 |
|
57,201 | medic/couchdb-audit | couchdb-audit/log.js | function(docs, options, callback) {
if (!callback) {
callback = options;
options = {};
}
audit(docs, function(err) {
if (err) {
return callback(err);
}
options.docs = docs;
docsDb.bulkDocs(options, callback);
});
} | javascript | function(docs, options, callback) {
if (!callback) {
callback = options;
options = {};
}
audit(docs, function(err) {
if (err) {
return callback(err);
}
options.docs = docs;
docsDb.bulkDocs(options, callback);
});
} | [
"function",
"(",
"docs",
",",
"options",
",",
"callback",
")",
"{",
"if",
"(",
"!",
"callback",
")",
"{",
"callback",
"=",
"options",
";",
"options",
"=",
"{",
"}",
";",
"}",
"audit",
"(",
"docs",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"options",
".",
"docs",
"=",
"docs",
";",
"docsDb",
".",
"bulkDocs",
"(",
"options",
",",
"callback",
")",
";",
"}",
")",
";",
"}"
] | Saves the given docs with individual audit records
@name bulkSave(docs, options, callback)
@param {Array} docs An array of documents to be saved
@param {Object} options Optional options to pass through to bulk save
@param {Function} callback(err,response)
@api public | [
"Saves",
"the",
"given",
"docs",
"with",
"individual",
"audit",
"records"
] | 88a2fde06830e91966fc82c7356ec46da043fc01 | https://github.com/medic/couchdb-audit/blob/88a2fde06830e91966fc82c7356ec46da043fc01/couchdb-audit/log.js#L218-L230 |
|
57,202 | medic/couchdb-audit | couchdb-audit/log.js | function(doc, callback) {
audit([doc], 'delete', function(err) {
if (err) {
return callback(err);
}
docsDb.removeDoc(doc._id, doc._rev, callback);
});
} | javascript | function(doc, callback) {
audit([doc], 'delete', function(err) {
if (err) {
return callback(err);
}
docsDb.removeDoc(doc._id, doc._rev, callback);
});
} | [
"function",
"(",
"doc",
",",
"callback",
")",
"{",
"audit",
"(",
"[",
"doc",
"]",
",",
"'delete'",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"docsDb",
".",
"removeDoc",
"(",
"doc",
".",
"_id",
",",
"doc",
".",
"_rev",
",",
"callback",
")",
";",
"}",
")",
";",
"}"
] | Deletes the given doc with auditing
@name removeDoc(doc, callback)
@param {Object} doc
@param {Function} callback(err,response)
@api public | [
"Deletes",
"the",
"given",
"doc",
"with",
"auditing"
] | 88a2fde06830e91966fc82c7356ec46da043fc01 | https://github.com/medic/couchdb-audit/blob/88a2fde06830e91966fc82c7356ec46da043fc01/couchdb-audit/log.js#L240-L247 |
|
57,203 | zship/grunt-amd-check | tasks/amd-check.js | function(arr, i) {
var ret = arr.slice(0);
for (var j = 0; j < i; j++) {
ret = [ret[ret.length - 1]].concat(ret.slice(0, ret.length - 1));
}
return ret;
} | javascript | function(arr, i) {
var ret = arr.slice(0);
for (var j = 0; j < i; j++) {
ret = [ret[ret.length - 1]].concat(ret.slice(0, ret.length - 1));
}
return ret;
} | [
"function",
"(",
"arr",
",",
"i",
")",
"{",
"var",
"ret",
"=",
"arr",
".",
"slice",
"(",
"0",
")",
";",
"for",
"(",
"var",
"j",
"=",
"0",
";",
"j",
"<",
"i",
";",
"j",
"++",
")",
"{",
"ret",
"=",
"[",
"ret",
"[",
"ret",
".",
"length",
"-",
"1",
"]",
"]",
".",
"concat",
"(",
"ret",
".",
"slice",
"(",
"0",
",",
"ret",
".",
"length",
"-",
"1",
")",
")",
";",
"}",
"return",
"ret",
";",
"}"
] | eliminate duplicate circular dependency loops | [
"eliminate",
"duplicate",
"circular",
"dependency",
"loops"
] | cabd51c2e33c2dae620420b568cc7853ff5e330c | https://github.com/zship/grunt-amd-check/blob/cabd51c2e33c2dae620420b568cc7853ff5e330c/tasks/amd-check.js#L163-L169 |
|
57,204 | zship/grunt-amd-check | tasks/amd-check.js | function(first, second) {
if (_equal(first, second)) {
return true;
}
for (var i = 1; i <= first.length; i++) {
if (_equal(first, _rotated(second, i))) {
return true;
}
}
return false;
} | javascript | function(first, second) {
if (_equal(first, second)) {
return true;
}
for (var i = 1; i <= first.length; i++) {
if (_equal(first, _rotated(second, i))) {
return true;
}
}
return false;
} | [
"function",
"(",
"first",
",",
"second",
")",
"{",
"if",
"(",
"_equal",
"(",
"first",
",",
"second",
")",
")",
"{",
"return",
"true",
";",
"}",
"for",
"(",
"var",
"i",
"=",
"1",
";",
"i",
"<=",
"first",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"_equal",
"(",
"first",
",",
"_rotated",
"(",
"second",
",",
"i",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | loops are "equal" if their elements are equal when "shifted" to the right by some amount | [
"loops",
"are",
"equal",
"if",
"their",
"elements",
"are",
"equal",
"when",
"shifted",
"to",
"the",
"right",
"by",
"some",
"amount"
] | cabd51c2e33c2dae620420b568cc7853ff5e330c | https://github.com/zship/grunt-amd-check/blob/cabd51c2e33c2dae620420b568cc7853ff5e330c/tasks/amd-check.js#L176-L186 |
|
57,205 | bvalosek/sql-params | index.js | sqlParams | function sqlParams(sql, params)
{
var args = [];
var keys = sql.match(/@\w+/g);
var aKeys = sql.match(/\$\d+/g);
if (keys && aKeys)
throw new Error(
'Cannot use both array-style and object-style parametric values');
// Array-style (native)
if (aKeys) {
return { text: sql, values: params };
}
// No params
if (!keys) {
return { text: sql, values: [] };
}
var n = 1;
keys.forEach(function(key) {
key = key.substr(1);
var val = params[key];
if (val === undefined)
throw new Error('No value for @' + key + ' provided');
args.push(val);
sql = sql.replace('@' + key, '$' + n++);
});
return { text: sql, values: args };
} | javascript | function sqlParams(sql, params)
{
var args = [];
var keys = sql.match(/@\w+/g);
var aKeys = sql.match(/\$\d+/g);
if (keys && aKeys)
throw new Error(
'Cannot use both array-style and object-style parametric values');
// Array-style (native)
if (aKeys) {
return { text: sql, values: params };
}
// No params
if (!keys) {
return { text: sql, values: [] };
}
var n = 1;
keys.forEach(function(key) {
key = key.substr(1);
var val = params[key];
if (val === undefined)
throw new Error('No value for @' + key + ' provided');
args.push(val);
sql = sql.replace('@' + key, '$' + n++);
});
return { text: sql, values: args };
} | [
"function",
"sqlParams",
"(",
"sql",
",",
"params",
")",
"{",
"var",
"args",
"=",
"[",
"]",
";",
"var",
"keys",
"=",
"sql",
".",
"match",
"(",
"/",
"@\\w+",
"/",
"g",
")",
";",
"var",
"aKeys",
"=",
"sql",
".",
"match",
"(",
"/",
"\\$\\d+",
"/",
"g",
")",
";",
"if",
"(",
"keys",
"&&",
"aKeys",
")",
"throw",
"new",
"Error",
"(",
"'Cannot use both array-style and object-style parametric values'",
")",
";",
"// Array-style (native)",
"if",
"(",
"aKeys",
")",
"{",
"return",
"{",
"text",
":",
"sql",
",",
"values",
":",
"params",
"}",
";",
"}",
"// No params",
"if",
"(",
"!",
"keys",
")",
"{",
"return",
"{",
"text",
":",
"sql",
",",
"values",
":",
"[",
"]",
"}",
";",
"}",
"var",
"n",
"=",
"1",
";",
"keys",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"key",
"=",
"key",
".",
"substr",
"(",
"1",
")",
";",
"var",
"val",
"=",
"params",
"[",
"key",
"]",
";",
"if",
"(",
"val",
"===",
"undefined",
")",
"throw",
"new",
"Error",
"(",
"'No value for @'",
"+",
"key",
"+",
"' provided'",
")",
";",
"args",
".",
"push",
"(",
"val",
")",
";",
"sql",
"=",
"sql",
".",
"replace",
"(",
"'@'",
"+",
"key",
",",
"'$'",
"+",
"n",
"++",
")",
";",
"}",
")",
";",
"return",
"{",
"text",
":",
"sql",
",",
"values",
":",
"args",
"}",
";",
"}"
] | Given a hash and parametric sql string, swap all of the @vars into $N args
and create an array
@param {string} sql Parametric sql string
@param {object} hash All of the named arguments
@return {{sql:string, args:array.<any>}} | [
"Given",
"a",
"hash",
"and",
"parametric",
"sql",
"string",
"swap",
"all",
"of",
"the"
] | abaa04f95debb23353f214eb5dec27894851d259 | https://github.com/bvalosek/sql-params/blob/abaa04f95debb23353f214eb5dec27894851d259/index.js#L10-L42 |
57,206 | radiovisual/tokenize-whitespace | index.js | getWordToken | function getWordToken(str) {
var word = str.split(/\s/g)[0];
return {text: word, type: 'WORD', length: word.length};
} | javascript | function getWordToken(str) {
var word = str.split(/\s/g)[0];
return {text: word, type: 'WORD', length: word.length};
} | [
"function",
"getWordToken",
"(",
"str",
")",
"{",
"var",
"word",
"=",
"str",
".",
"split",
"(",
"/",
"\\s",
"/",
"g",
")",
"[",
"0",
"]",
";",
"return",
"{",
"text",
":",
"word",
",",
"type",
":",
"'WORD'",
",",
"length",
":",
"word",
".",
"length",
"}",
";",
"}"
] | Extract whole word values | [
"Extract",
"whole",
"word",
"values"
] | de6991b9ca6e979202df9708770bd785672f8345 | https://github.com/radiovisual/tokenize-whitespace/blob/de6991b9ca6e979202df9708770bd785672f8345/index.js#L41-L44 |
57,207 | bredele/uri-params-match | index.js | contains | function contains (obj1, obj2) {
const keys = Object.keys(obj1)
let result = keys.length > 0
let l = keys.length
while (l--) {
const key = keys[l]
result = result && match(obj1[key], obj2[key])
}
return result
} | javascript | function contains (obj1, obj2) {
const keys = Object.keys(obj1)
let result = keys.length > 0
let l = keys.length
while (l--) {
const key = keys[l]
result = result && match(obj1[key], obj2[key])
}
return result
} | [
"function",
"contains",
"(",
"obj1",
",",
"obj2",
")",
"{",
"const",
"keys",
"=",
"Object",
".",
"keys",
"(",
"obj1",
")",
"let",
"result",
"=",
"keys",
".",
"length",
">",
"0",
"let",
"l",
"=",
"keys",
".",
"length",
"while",
"(",
"l",
"--",
")",
"{",
"const",
"key",
"=",
"keys",
"[",
"l",
"]",
"result",
"=",
"result",
"&&",
"match",
"(",
"obj1",
"[",
"key",
"]",
",",
"obj2",
"[",
"key",
"]",
")",
"}",
"return",
"result",
"}"
] | Return true if second object contains all keys and values
from the first object.
@param {Object} obj1
@param {Object} obj2
@return {Boolean}
@api private | [
"Return",
"true",
"if",
"second",
"object",
"contains",
"all",
"keys",
"and",
"values",
"from",
"the",
"first",
"object",
"."
] | 093666babe2b270a99230358892db8e8651264bc | https://github.com/bredele/uri-params-match/blob/093666babe2b270a99230358892db8e8651264bc/index.js#L37-L46 |
57,208 | Ravenwall/node-ravenwall | index.js | ravenwall | function ravenwall(options) {
if (options instanceof statware) return options
options = options || {}
// set defaults
options.sysstats = !(options.sysstats === false)
options.procstats = !(options.procstats === false)
options.memstats = !(options.memstats === false)
options.push = !(options.push === false)
options.pushApi = options.pushApi || "https://push.ravenwall.com"
options.pushSeconds = options.pushSeconds || 10
options.logHandle = options.logHandle || console.log
options.logSeconds = options.logSeconds || 60
options.initial = options.initial || {}
options.initial.ravenwall_agent = "nodejs_" + VERSION
if (options.id) id = options.id
function startPusher(id) {
if (!options.apiToken) throw new Error("Push API Requires an API token.")
var pusherSettings = {
url: options.pushApi + "/" + id,
headers: {
"Ravenwall-API-Token": options.apiToken,
},
timeout: (options.pushSeconds * 900) | 0
}
stats.pusher(pusherSettings, options.pushSeconds)
stats.push()
}
// Create series/api client
if (!options.noUpsert) {
var client = api(options.apiToken, options.apiUrl)
.upsertSeries({id: options.id, tags: options.tags}, function (err, res, body) {
if (err) {
console.log("Unable to upsert series to Ravenwall!", err)
return
}
if (res.statusCode != 201) {
console.log("Unable to upsert series to Ravenwall: server replied %s", res.statusCode)
return
}
var results = JSON.parse(body)
if (!options.id && options.push && !options.push) {
// This is a new series, so the pusher wasn't set up yet. Set it up now.
id = results.id
startPusher(results.id)
}
})
}
var stats = statware(options.initial)
if (options.sysstats) stats.registerHelper(statware.sysstats)
if (options.procstats) stats.registerHelper(statware.procstats)
if (options.memstats) stats.registerHelper(statware.memstats)
// Don't immediately start a pusher if no id specified (instead it will start after upsert)
if (options.push && options.id) {
startPusher(options.id)
}
if (options.page) {
stats.page(options.pagePort)
}
if (options.log) {
stats.logger(options.logHandle, options.logSeconds)
stats.log()
}
return stats
} | javascript | function ravenwall(options) {
if (options instanceof statware) return options
options = options || {}
// set defaults
options.sysstats = !(options.sysstats === false)
options.procstats = !(options.procstats === false)
options.memstats = !(options.memstats === false)
options.push = !(options.push === false)
options.pushApi = options.pushApi || "https://push.ravenwall.com"
options.pushSeconds = options.pushSeconds || 10
options.logHandle = options.logHandle || console.log
options.logSeconds = options.logSeconds || 60
options.initial = options.initial || {}
options.initial.ravenwall_agent = "nodejs_" + VERSION
if (options.id) id = options.id
function startPusher(id) {
if (!options.apiToken) throw new Error("Push API Requires an API token.")
var pusherSettings = {
url: options.pushApi + "/" + id,
headers: {
"Ravenwall-API-Token": options.apiToken,
},
timeout: (options.pushSeconds * 900) | 0
}
stats.pusher(pusherSettings, options.pushSeconds)
stats.push()
}
// Create series/api client
if (!options.noUpsert) {
var client = api(options.apiToken, options.apiUrl)
.upsertSeries({id: options.id, tags: options.tags}, function (err, res, body) {
if (err) {
console.log("Unable to upsert series to Ravenwall!", err)
return
}
if (res.statusCode != 201) {
console.log("Unable to upsert series to Ravenwall: server replied %s", res.statusCode)
return
}
var results = JSON.parse(body)
if (!options.id && options.push && !options.push) {
// This is a new series, so the pusher wasn't set up yet. Set it up now.
id = results.id
startPusher(results.id)
}
})
}
var stats = statware(options.initial)
if (options.sysstats) stats.registerHelper(statware.sysstats)
if (options.procstats) stats.registerHelper(statware.procstats)
if (options.memstats) stats.registerHelper(statware.memstats)
// Don't immediately start a pusher if no id specified (instead it will start after upsert)
if (options.push && options.id) {
startPusher(options.id)
}
if (options.page) {
stats.page(options.pagePort)
}
if (options.log) {
stats.logger(options.logHandle, options.logSeconds)
stats.log()
}
return stats
} | [
"function",
"ravenwall",
"(",
"options",
")",
"{",
"if",
"(",
"options",
"instanceof",
"statware",
")",
"return",
"options",
"options",
"=",
"options",
"||",
"{",
"}",
"// set defaults",
"options",
".",
"sysstats",
"=",
"!",
"(",
"options",
".",
"sysstats",
"===",
"false",
")",
"options",
".",
"procstats",
"=",
"!",
"(",
"options",
".",
"procstats",
"===",
"false",
")",
"options",
".",
"memstats",
"=",
"!",
"(",
"options",
".",
"memstats",
"===",
"false",
")",
"options",
".",
"push",
"=",
"!",
"(",
"options",
".",
"push",
"===",
"false",
")",
"options",
".",
"pushApi",
"=",
"options",
".",
"pushApi",
"||",
"\"https://push.ravenwall.com\"",
"options",
".",
"pushSeconds",
"=",
"options",
".",
"pushSeconds",
"||",
"10",
"options",
".",
"logHandle",
"=",
"options",
".",
"logHandle",
"||",
"console",
".",
"log",
"options",
".",
"logSeconds",
"=",
"options",
".",
"logSeconds",
"||",
"60",
"options",
".",
"initial",
"=",
"options",
".",
"initial",
"||",
"{",
"}",
"options",
".",
"initial",
".",
"ravenwall_agent",
"=",
"\"nodejs_\"",
"+",
"VERSION",
"if",
"(",
"options",
".",
"id",
")",
"id",
"=",
"options",
".",
"id",
"function",
"startPusher",
"(",
"id",
")",
"{",
"if",
"(",
"!",
"options",
".",
"apiToken",
")",
"throw",
"new",
"Error",
"(",
"\"Push API Requires an API token.\"",
")",
"var",
"pusherSettings",
"=",
"{",
"url",
":",
"options",
".",
"pushApi",
"+",
"\"/\"",
"+",
"id",
",",
"headers",
":",
"{",
"\"Ravenwall-API-Token\"",
":",
"options",
".",
"apiToken",
",",
"}",
",",
"timeout",
":",
"(",
"options",
".",
"pushSeconds",
"*",
"900",
")",
"|",
"0",
"}",
"stats",
".",
"pusher",
"(",
"pusherSettings",
",",
"options",
".",
"pushSeconds",
")",
"stats",
".",
"push",
"(",
")",
"}",
"// Create series/api client",
"if",
"(",
"!",
"options",
".",
"noUpsert",
")",
"{",
"var",
"client",
"=",
"api",
"(",
"options",
".",
"apiToken",
",",
"options",
".",
"apiUrl",
")",
".",
"upsertSeries",
"(",
"{",
"id",
":",
"options",
".",
"id",
",",
"tags",
":",
"options",
".",
"tags",
"}",
",",
"function",
"(",
"err",
",",
"res",
",",
"body",
")",
"{",
"if",
"(",
"err",
")",
"{",
"console",
".",
"log",
"(",
"\"Unable to upsert series to Ravenwall!\"",
",",
"err",
")",
"return",
"}",
"if",
"(",
"res",
".",
"statusCode",
"!=",
"201",
")",
"{",
"console",
".",
"log",
"(",
"\"Unable to upsert series to Ravenwall: server replied %s\"",
",",
"res",
".",
"statusCode",
")",
"return",
"}",
"var",
"results",
"=",
"JSON",
".",
"parse",
"(",
"body",
")",
"if",
"(",
"!",
"options",
".",
"id",
"&&",
"options",
".",
"push",
"&&",
"!",
"options",
".",
"push",
")",
"{",
"// This is a new series, so the pusher wasn't set up yet. Set it up now.",
"id",
"=",
"results",
".",
"id",
"startPusher",
"(",
"results",
".",
"id",
")",
"}",
"}",
")",
"}",
"var",
"stats",
"=",
"statware",
"(",
"options",
".",
"initial",
")",
"if",
"(",
"options",
".",
"sysstats",
")",
"stats",
".",
"registerHelper",
"(",
"statware",
".",
"sysstats",
")",
"if",
"(",
"options",
".",
"procstats",
")",
"stats",
".",
"registerHelper",
"(",
"statware",
".",
"procstats",
")",
"if",
"(",
"options",
".",
"memstats",
")",
"stats",
".",
"registerHelper",
"(",
"statware",
".",
"memstats",
")",
"// Don't immediately start a pusher if no id specified (instead it will start after upsert)",
"if",
"(",
"options",
".",
"push",
"&&",
"options",
".",
"id",
")",
"{",
"startPusher",
"(",
"options",
".",
"id",
")",
"}",
"if",
"(",
"options",
".",
"page",
")",
"{",
"stats",
".",
"page",
"(",
"options",
".",
"pagePort",
")",
"}",
"if",
"(",
"options",
".",
"log",
")",
"{",
"stats",
".",
"logger",
"(",
"options",
".",
"logHandle",
",",
"options",
".",
"logSeconds",
")",
"stats",
".",
"log",
"(",
")",
"}",
"return",
"stats",
"}"
] | The Ravenwall Agent.
@param {Object} options The options to create the agent with.
options.apiToken {string} set your Ravenwall API key. Can also use the RAVENWALL_API_TOKEN environment variable.
options.id {string} set a series id. This defines where your data will be stored. If not specified, a uuid will be generated.
options.tags {Array} tags to add/apply to the series. Add-only. Must match: /[a-zA-Z0-9:_-]+/
options.initial {Object} [{}] a default stats object. Useful for initializing values that may be set later for data continuity.
options.sysstats {Bool} [true] whether to apply a default set of system-related stats.
options.procstats {Bool} [true] whether to apply a default set of process-related stats.
options.memstats {Bool} [true] whether to apply a default set of memory-related stats.
options.push {Bool} [true] whether to create as a stats-pushing agent that will send data to Ravenwall.
options.pushApi {string} [https://push.ravenwall.com] The ravenwall push api endpoint.
options.pushSeconds {Int} [10] the frequency it will automatically push data. Setting this too low can get you throttled. Suggested minimum is ~10 seconds. Set to <= 0 to disable recurring push.
options.page {Bool} [false] whether to create a status page that will report the stats that can be scraped.
options.pagePort {Int} [7667] port to run the status page on (if enabled)
options.log {Bool} [false] whether to create a recurring stat logger
options.logHandle {Function} [console.log] a handle to log to
options.logSeconds {Int} [60] the frequency to log the stats to the log handle.
@return {Statware} | [
"The",
"Ravenwall",
"Agent",
"."
] | 23e6491f0dec26f7879103e3be1c88abad17a58f | https://github.com/Ravenwall/node-ravenwall/blob/23e6491f0dec26f7879103e3be1c88abad17a58f/index.js#L46-L119 |
57,209 | mgesmundo/port-manager | lib/port-manager.js | normalize | function normalize(from, to) {
if (from && (isNaN(from) || from <= 0) || (to && (isNaN(to) || to <= 0))) {
throw new Error('invalid port range: required > 0');
}
if ((from && from > MAX) || (to && to > MAX)) {
throw new Error(f('invalid port range: required < %d', MAX));
}
if (to && to < from) {
throw new Error('invalid port range: required max >= min');
}
if (!from) {
from = min;
to = to || max;
} else {
to = to || from;
}
return {
from: from,
to: to
};
} | javascript | function normalize(from, to) {
if (from && (isNaN(from) || from <= 0) || (to && (isNaN(to) || to <= 0))) {
throw new Error('invalid port range: required > 0');
}
if ((from && from > MAX) || (to && to > MAX)) {
throw new Error(f('invalid port range: required < %d', MAX));
}
if (to && to < from) {
throw new Error('invalid port range: required max >= min');
}
if (!from) {
from = min;
to = to || max;
} else {
to = to || from;
}
return {
from: from,
to: to
};
} | [
"function",
"normalize",
"(",
"from",
",",
"to",
")",
"{",
"if",
"(",
"from",
"&&",
"(",
"isNaN",
"(",
"from",
")",
"||",
"from",
"<=",
"0",
")",
"||",
"(",
"to",
"&&",
"(",
"isNaN",
"(",
"to",
")",
"||",
"to",
"<=",
"0",
")",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'invalid port range: required > 0'",
")",
";",
"}",
"if",
"(",
"(",
"from",
"&&",
"from",
">",
"MAX",
")",
"||",
"(",
"to",
"&&",
"to",
">",
"MAX",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"f",
"(",
"'invalid port range: required < %d'",
",",
"MAX",
")",
")",
";",
"}",
"if",
"(",
"to",
"&&",
"to",
"<",
"from",
")",
"{",
"throw",
"new",
"Error",
"(",
"'invalid port range: required max >= min'",
")",
";",
"}",
"if",
"(",
"!",
"from",
")",
"{",
"from",
"=",
"min",
";",
"to",
"=",
"to",
"||",
"max",
";",
"}",
"else",
"{",
"to",
"=",
"to",
"||",
"from",
";",
"}",
"return",
"{",
"from",
":",
"from",
",",
"to",
":",
"to",
"}",
";",
"}"
] | Normalize a TCP ports range
@param {Number} [from] Start port (included)
@param {Number} [to] End port (included)
@return {{from: {Number}, to: {Number}}}
@private
@ignore | [
"Normalize",
"a",
"TCP",
"ports",
"range"
] | a09356b9063c228616d0ffc56217b93c479f2604 | https://github.com/mgesmundo/port-manager/blob/a09356b9063c228616d0ffc56217b93c479f2604/lib/port-manager.js#L24-L44 |
57,210 | relief-melone/limitpromises | src/services/service.cleanObject.js | cleanObject | function cleanObject(Object){
delete Object.resolve;
delete Object.reject;
delete Object.resolveResult;
delete Object.rejectResult;
delete Object.launchPromise;
delete Object.promiseFunc;
} | javascript | function cleanObject(Object){
delete Object.resolve;
delete Object.reject;
delete Object.resolveResult;
delete Object.rejectResult;
delete Object.launchPromise;
delete Object.promiseFunc;
} | [
"function",
"cleanObject",
"(",
"Object",
")",
"{",
"delete",
"Object",
".",
"resolve",
";",
"delete",
"Object",
".",
"reject",
";",
"delete",
"Object",
".",
"resolveResult",
";",
"delete",
"Object",
".",
"rejectResult",
";",
"delete",
"Object",
".",
"launchPromise",
";",
"delete",
"Object",
".",
"promiseFunc",
";",
"}"
] | Will be called if a resultPromise is either rejected or resolved to clean the Object of Attributes you don't want to
send back to the user
@param {Object} Object The Object you want to clean | [
"Will",
"be",
"called",
"if",
"a",
"resultPromise",
"is",
"either",
"rejected",
"or",
"resolved",
"to",
"clean",
"the",
"Object",
"of",
"Attributes",
"you",
"don",
"t",
"want",
"to",
"send",
"back",
"to",
"the",
"user"
] | 1735b92749740204b597c1c6026257d54ade8200 | https://github.com/relief-melone/limitpromises/blob/1735b92749740204b597c1c6026257d54ade8200/src/services/service.cleanObject.js#L8-L15 |
57,211 | update/updater-example | updatefile.js | updateExample | function updateExample(app, str) {
var cwd = app.options.dest || app.cwd;
return app.src('example.txt', {cwd: cwd})
.pipe(append(str))
.pipe(app.dest(cwd));
} | javascript | function updateExample(app, str) {
var cwd = app.options.dest || app.cwd;
return app.src('example.txt', {cwd: cwd})
.pipe(append(str))
.pipe(app.dest(cwd));
} | [
"function",
"updateExample",
"(",
"app",
",",
"str",
")",
"{",
"var",
"cwd",
"=",
"app",
".",
"options",
".",
"dest",
"||",
"app",
".",
"cwd",
";",
"return",
"app",
".",
"src",
"(",
"'example.txt'",
",",
"{",
"cwd",
":",
"cwd",
"}",
")",
".",
"pipe",
"(",
"append",
"(",
"str",
")",
")",
".",
"pipe",
"(",
"app",
".",
"dest",
"(",
"cwd",
")",
")",
";",
"}"
] | Append the given string to `example.txt` and re-write the file to the current
working directory.
The `.src` and `.dest` methods work exactly like gulp's (we use the same libs from the
gulp team under the hood)
@param {Object} `app` Instance of update, to get the cwd. Pass `--dest` on the command line to set `app.options.dest`
@return {Stream} vinyl stream
@api public | [
"Append",
"the",
"given",
"string",
"to",
"example",
".",
"txt",
"and",
"re",
"-",
"write",
"the",
"file",
"to",
"the",
"current",
"working",
"directory",
"."
] | 5e89b9acc78f7789d344d4c2c7d2b94dd348734b | https://github.com/update/updater-example/blob/5e89b9acc78f7789d344d4c2c7d2b94dd348734b/updatefile.js#L58-L63 |
57,212 | update/updater-example | updatefile.js | erase | function erase(num) {
var n = typeof num === 'number' ? num : 1;
return through.obj(function(file, enc, next) {
var lines = file.contents.toString().trim().split('\n');
file.contents = new Buffer(lines.slice(0, -n).join('\n') + '\n');
next(null, file);
});
} | javascript | function erase(num) {
var n = typeof num === 'number' ? num : 1;
return through.obj(function(file, enc, next) {
var lines = file.contents.toString().trim().split('\n');
file.contents = new Buffer(lines.slice(0, -n).join('\n') + '\n');
next(null, file);
});
} | [
"function",
"erase",
"(",
"num",
")",
"{",
"var",
"n",
"=",
"typeof",
"num",
"===",
"'number'",
"?",
"num",
":",
"1",
";",
"return",
"through",
".",
"obj",
"(",
"function",
"(",
"file",
",",
"enc",
",",
"next",
")",
"{",
"var",
"lines",
"=",
"file",
".",
"contents",
".",
"toString",
"(",
")",
".",
"trim",
"(",
")",
".",
"split",
"(",
"'\\n'",
")",
";",
"file",
".",
"contents",
"=",
"new",
"Buffer",
"(",
"lines",
".",
"slice",
"(",
"0",
",",
"-",
"n",
")",
".",
"join",
"(",
"'\\n'",
")",
"+",
"'\\n'",
")",
";",
"next",
"(",
"null",
",",
"file",
")",
";",
"}",
")",
";",
"}"
] | Erase the given number of lines from the end of a string
@param {String} `str`
@return {Stream} vinyl stream
@api public | [
"Erase",
"the",
"given",
"number",
"of",
"lines",
"from",
"the",
"end",
"of",
"a",
"string"
] | 5e89b9acc78f7789d344d4c2c7d2b94dd348734b | https://github.com/update/updater-example/blob/5e89b9acc78f7789d344d4c2c7d2b94dd348734b/updatefile.js#L88-L95 |
57,213 | yoshuawuyts/virtual-raf | index.js | update | function update (state) {
assert.ifError(inRenderingTransaction, 'infinite loop detected')
// request a redraw for next frame
if (currentState === null && !redrawScheduled) {
redrawScheduled = true
raf(function redraw () {
redrawScheduled = false
if (!currentState) return
inRenderingTransaction = true
var newTree = view(currentState)
const patches = vdom.diff(tree, newTree)
inRenderingTransaction = false
target = vdom.patch(target, patches)
tree = newTree
currentState = null
})
}
// update data for redraw
currentState = state
} | javascript | function update (state) {
assert.ifError(inRenderingTransaction, 'infinite loop detected')
// request a redraw for next frame
if (currentState === null && !redrawScheduled) {
redrawScheduled = true
raf(function redraw () {
redrawScheduled = false
if (!currentState) return
inRenderingTransaction = true
var newTree = view(currentState)
const patches = vdom.diff(tree, newTree)
inRenderingTransaction = false
target = vdom.patch(target, patches)
tree = newTree
currentState = null
})
}
// update data for redraw
currentState = state
} | [
"function",
"update",
"(",
"state",
")",
"{",
"assert",
".",
"ifError",
"(",
"inRenderingTransaction",
",",
"'infinite loop detected'",
")",
"// request a redraw for next frame",
"if",
"(",
"currentState",
"===",
"null",
"&&",
"!",
"redrawScheduled",
")",
"{",
"redrawScheduled",
"=",
"true",
"raf",
"(",
"function",
"redraw",
"(",
")",
"{",
"redrawScheduled",
"=",
"false",
"if",
"(",
"!",
"currentState",
")",
"return",
"inRenderingTransaction",
"=",
"true",
"var",
"newTree",
"=",
"view",
"(",
"currentState",
")",
"const",
"patches",
"=",
"vdom",
".",
"diff",
"(",
"tree",
",",
"newTree",
")",
"inRenderingTransaction",
"=",
"false",
"target",
"=",
"vdom",
".",
"patch",
"(",
"target",
",",
"patches",
")",
"tree",
"=",
"newTree",
"currentState",
"=",
"null",
"}",
")",
"}",
"// update data for redraw",
"currentState",
"=",
"state",
"}"
] | update the state and render function obj -> null | [
"update",
"the",
"state",
"and",
"render",
"function",
"obj",
"-",
">",
"null"
] | d2a8fcd49a6e55ca135d4a9c002bf6d7ffe0f76b | https://github.com/yoshuawuyts/virtual-raf/blob/d2a8fcd49a6e55ca135d4a9c002bf6d7ffe0f76b/index.js#L33-L57 |
57,214 | commenthol/streamss | lib/split.js | Split | function Split (options) {
if (!(this instanceof Split)) {
return new Split(options)
}
if (options instanceof RegExp || typeof options === 'string') {
options = { matcher: options }
}
this.options = Object.assign({
matcher: /(\r?\n)/, // emits also newlines
encoding: 'utf8'
}, options)
this.buffer = ''
Transform.call(this, _omit(this.options, ['matcher']))
return this
} | javascript | function Split (options) {
if (!(this instanceof Split)) {
return new Split(options)
}
if (options instanceof RegExp || typeof options === 'string') {
options = { matcher: options }
}
this.options = Object.assign({
matcher: /(\r?\n)/, // emits also newlines
encoding: 'utf8'
}, options)
this.buffer = ''
Transform.call(this, _omit(this.options, ['matcher']))
return this
} | [
"function",
"Split",
"(",
"options",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Split",
")",
")",
"{",
"return",
"new",
"Split",
"(",
"options",
")",
"}",
"if",
"(",
"options",
"instanceof",
"RegExp",
"||",
"typeof",
"options",
"===",
"'string'",
")",
"{",
"options",
"=",
"{",
"matcher",
":",
"options",
"}",
"}",
"this",
".",
"options",
"=",
"Object",
".",
"assign",
"(",
"{",
"matcher",
":",
"/",
"(\\r?\\n)",
"/",
",",
"// emits also newlines",
"encoding",
":",
"'utf8'",
"}",
",",
"options",
")",
"this",
".",
"buffer",
"=",
"''",
"Transform",
".",
"call",
"(",
"this",
",",
"_omit",
"(",
"this",
".",
"options",
",",
"[",
"'matcher'",
"]",
")",
")",
"return",
"this",
"}"
] | Split a stream using a regexp or string based matcher
@constructor
@param {Object} [options] - Stream Options `{encoding, highWaterMark, decodeStrings, ...}`
@param {RegExp|String} options.matcher - RegExp or String use for splitting up the stream. Default=/(\r?\n)/
@return {Transform} A transform stream | [
"Split",
"a",
"stream",
"using",
"a",
"regexp",
"or",
"string",
"based",
"matcher"
] | cfef5d0ed30c7efe002018886e2e843c91d3558f | https://github.com/commenthol/streamss/blob/cfef5d0ed30c7efe002018886e2e843c91d3558f/lib/split.js#L20-L37 |
57,215 | AndreasMadsen/piccolo | lib/modules/url.js | copyObject | function copyObject(obj) {
var ret = {}, name;
for (name in obj) {
if (obj.hasOwnProperty(name)) {
ret[name] = obj[name];
}
}
return ret;
} | javascript | function copyObject(obj) {
var ret = {}, name;
for (name in obj) {
if (obj.hasOwnProperty(name)) {
ret[name] = obj[name];
}
}
return ret;
} | [
"function",
"copyObject",
"(",
"obj",
")",
"{",
"var",
"ret",
"=",
"{",
"}",
",",
"name",
";",
"for",
"(",
"name",
"in",
"obj",
")",
"{",
"if",
"(",
"obj",
".",
"hasOwnProperty",
"(",
"name",
")",
")",
"{",
"ret",
"[",
"name",
"]",
"=",
"obj",
"[",
"name",
"]",
";",
"}",
"}",
"return",
"ret",
";",
"}"
] | copy an object without depth | [
"copy",
"an",
"object",
"without",
"depth"
] | ef43f5634c564eef0d21a4a6aa103b2f1e3baa3d | https://github.com/AndreasMadsen/piccolo/blob/ef43f5634c564eef0d21a4a6aa103b2f1e3baa3d/lib/modules/url.js#L7-L15 |
57,216 | AndreasMadsen/piccolo | lib/modules/url.js | setHost | function setHost(uri) {
if (uri.auth || uri.hostname || uri.port) {
uri.host = '';
if (uri.auth) uri.host += uri.auth + '@';
if (uri.hostname) uri.host += uri.hostname;
if (uri.port) uri.host += ':' + uri.port;
}
} | javascript | function setHost(uri) {
if (uri.auth || uri.hostname || uri.port) {
uri.host = '';
if (uri.auth) uri.host += uri.auth + '@';
if (uri.hostname) uri.host += uri.hostname;
if (uri.port) uri.host += ':' + uri.port;
}
} | [
"function",
"setHost",
"(",
"uri",
")",
"{",
"if",
"(",
"uri",
".",
"auth",
"||",
"uri",
".",
"hostname",
"||",
"uri",
".",
"port",
")",
"{",
"uri",
".",
"host",
"=",
"''",
";",
"if",
"(",
"uri",
".",
"auth",
")",
"uri",
".",
"host",
"+=",
"uri",
".",
"auth",
"+",
"'@'",
";",
"if",
"(",
"uri",
".",
"hostname",
")",
"uri",
".",
"host",
"+=",
"uri",
".",
"hostname",
";",
"if",
"(",
"uri",
".",
"port",
")",
"uri",
".",
"host",
"+=",
"':'",
"+",
"uri",
".",
"port",
";",
"}",
"}"
] | construct host property | [
"construct",
"host",
"property"
] | ef43f5634c564eef0d21a4a6aa103b2f1e3baa3d | https://github.com/AndreasMadsen/piccolo/blob/ef43f5634c564eef0d21a4a6aa103b2f1e3baa3d/lib/modules/url.js#L18-L25 |
57,217 | AndreasMadsen/piccolo | lib/modules/url.js | setHref | function setHref(uri) {
uri.href = '';
if (uri.protocol) uri.href += uri.protocol + '//';
if (uri.host) uri.href += uri.host;
if (uri.path) uri.href += uri.path;
if (uri.hash) uri.href += uri.hash;
} | javascript | function setHref(uri) {
uri.href = '';
if (uri.protocol) uri.href += uri.protocol + '//';
if (uri.host) uri.href += uri.host;
if (uri.path) uri.href += uri.path;
if (uri.hash) uri.href += uri.hash;
} | [
"function",
"setHref",
"(",
"uri",
")",
"{",
"uri",
".",
"href",
"=",
"''",
";",
"if",
"(",
"uri",
".",
"protocol",
")",
"uri",
".",
"href",
"+=",
"uri",
".",
"protocol",
"+",
"'//'",
";",
"if",
"(",
"uri",
".",
"host",
")",
"uri",
".",
"href",
"+=",
"uri",
".",
"host",
";",
"if",
"(",
"uri",
".",
"path",
")",
"uri",
".",
"href",
"+=",
"uri",
".",
"path",
";",
"if",
"(",
"uri",
".",
"hash",
")",
"uri",
".",
"href",
"+=",
"uri",
".",
"hash",
";",
"}"
] | construct href property | [
"construct",
"href",
"property"
] | ef43f5634c564eef0d21a4a6aa103b2f1e3baa3d | https://github.com/AndreasMadsen/piccolo/blob/ef43f5634c564eef0d21a4a6aa103b2f1e3baa3d/lib/modules/url.js#L28-L34 |
57,218 | AndreasMadsen/piccolo | lib/modules/url.js | setPath | function setPath(uri) {
if (uri.path || (uri.pathname === undefined && uri.search === undefined)) return;
uri.path = '';
if (uri.pathname) uri.path += uri.pathname;
if (uri.search) uri.path += uri.search;
} | javascript | function setPath(uri) {
if (uri.path || (uri.pathname === undefined && uri.search === undefined)) return;
uri.path = '';
if (uri.pathname) uri.path += uri.pathname;
if (uri.search) uri.path += uri.search;
} | [
"function",
"setPath",
"(",
"uri",
")",
"{",
"if",
"(",
"uri",
".",
"path",
"||",
"(",
"uri",
".",
"pathname",
"===",
"undefined",
"&&",
"uri",
".",
"search",
"===",
"undefined",
")",
")",
"return",
";",
"uri",
".",
"path",
"=",
"''",
";",
"if",
"(",
"uri",
".",
"pathname",
")",
"uri",
".",
"path",
"+=",
"uri",
".",
"pathname",
";",
"if",
"(",
"uri",
".",
"search",
")",
"uri",
".",
"path",
"+=",
"uri",
".",
"search",
";",
"}"
] | construct path property | [
"construct",
"path",
"property"
] | ef43f5634c564eef0d21a4a6aa103b2f1e3baa3d | https://github.com/AndreasMadsen/piccolo/blob/ef43f5634c564eef0d21a4a6aa103b2f1e3baa3d/lib/modules/url.js#L37-L43 |
57,219 | AndreasMadsen/piccolo | lib/modules/url.js | setSearch | function setSearch(uri) {
if (typeof uri.search === 'string' || uri.query === undefined) return;
if (typeof uri.query === 'string') {
uri.search = '?' + uri.query;
return;
}
var name, filled = false;
uri.search = '?';
for (name in uri.query) {
filled = true;
uri.search += name + '=' + uri.query[name] + '&';
}
uri.search = uri.search.substr(0, uri.search.length - 1);
} | javascript | function setSearch(uri) {
if (typeof uri.search === 'string' || uri.query === undefined) return;
if (typeof uri.query === 'string') {
uri.search = '?' + uri.query;
return;
}
var name, filled = false;
uri.search = '?';
for (name in uri.query) {
filled = true;
uri.search += name + '=' + uri.query[name] + '&';
}
uri.search = uri.search.substr(0, uri.search.length - 1);
} | [
"function",
"setSearch",
"(",
"uri",
")",
"{",
"if",
"(",
"typeof",
"uri",
".",
"search",
"===",
"'string'",
"||",
"uri",
".",
"query",
"===",
"undefined",
")",
"return",
";",
"if",
"(",
"typeof",
"uri",
".",
"query",
"===",
"'string'",
")",
"{",
"uri",
".",
"search",
"=",
"'?'",
"+",
"uri",
".",
"query",
";",
"return",
";",
"}",
"var",
"name",
",",
"filled",
"=",
"false",
";",
"uri",
".",
"search",
"=",
"'?'",
";",
"for",
"(",
"name",
"in",
"uri",
".",
"query",
")",
"{",
"filled",
"=",
"true",
";",
"uri",
".",
"search",
"+=",
"name",
"+",
"'='",
"+",
"uri",
".",
"query",
"[",
"name",
"]",
"+",
"'&'",
";",
"}",
"uri",
".",
"search",
"=",
"uri",
".",
"search",
".",
"substr",
"(",
"0",
",",
"uri",
".",
"search",
".",
"length",
"-",
"1",
")",
";",
"}"
] | construct search property | [
"construct",
"search",
"property"
] | ef43f5634c564eef0d21a4a6aa103b2f1e3baa3d | https://github.com/AndreasMadsen/piccolo/blob/ef43f5634c564eef0d21a4a6aa103b2f1e3baa3d/lib/modules/url.js#L46-L63 |
57,220 | AndreasMadsen/piccolo | lib/modules/url.js | parseFilepath | function parseFilepath(path) {
if (path === undefined) {
return {filename: null, list: []};
}
var list = path.split('/'),
isDir = (path[path.length - 1] === '/') || (list[list.length - 1].indexOf('.') === -1);
return {
filename: isDir ? null : list.pop(),
list: list
};
} | javascript | function parseFilepath(path) {
if (path === undefined) {
return {filename: null, list: []};
}
var list = path.split('/'),
isDir = (path[path.length - 1] === '/') || (list[list.length - 1].indexOf('.') === -1);
return {
filename: isDir ? null : list.pop(),
list: list
};
} | [
"function",
"parseFilepath",
"(",
"path",
")",
"{",
"if",
"(",
"path",
"===",
"undefined",
")",
"{",
"return",
"{",
"filename",
":",
"null",
",",
"list",
":",
"[",
"]",
"}",
";",
"}",
"var",
"list",
"=",
"path",
".",
"split",
"(",
"'/'",
")",
",",
"isDir",
"=",
"(",
"path",
"[",
"path",
".",
"length",
"-",
"1",
"]",
"===",
"'/'",
")",
"||",
"(",
"list",
"[",
"list",
".",
"length",
"-",
"1",
"]",
".",
"indexOf",
"(",
"'.'",
")",
"===",
"-",
"1",
")",
";",
"return",
"{",
"filename",
":",
"isDir",
"?",
"null",
":",
"list",
".",
"pop",
"(",
")",
",",
"list",
":",
"list",
"}",
";",
"}"
] | split filepath from filename | [
"split",
"filepath",
"from",
"filename"
] | ef43f5634c564eef0d21a4a6aa103b2f1e3baa3d | https://github.com/AndreasMadsen/piccolo/blob/ef43f5634c564eef0d21a4a6aa103b2f1e3baa3d/lib/modules/url.js#L66-L78 |
57,221 | melvincarvalho/rdf-shell | lib/rm.js | bin | function bin(argv) {
rm(argv, function(err, res, uri) {
console.log('rm of : ' + uri);
});
} | javascript | function bin(argv) {
rm(argv, function(err, res, uri) {
console.log('rm of : ' + uri);
});
} | [
"function",
"bin",
"(",
"argv",
")",
"{",
"rm",
"(",
"argv",
",",
"function",
"(",
"err",
",",
"res",
",",
"uri",
")",
"{",
"console",
".",
"log",
"(",
"'rm of : '",
"+",
"uri",
")",
";",
"}",
")",
";",
"}"
] | rm as a command
@param {String} argv[2] login
@callback {bin~cb} callback | [
"rm",
"as",
"a",
"command"
] | bf2015f6f333855e69a18ce3ec9e917bbddfb425 | https://github.com/melvincarvalho/rdf-shell/blob/bf2015f6f333855e69a18ce3ec9e917bbddfb425/lib/rm.js#L29-L33 |
57,222 | iwillwen/co-e | index.js | buildError | function buildError(err, hackErr) {
var stack1 = err.stack;
var stack2 = hackErr.stack;
var label = hackErr.label;
var stack = [];
stack1.split('\n').forEach(function(line, index, arr) {
if (line.match(/^ at GeneratorFunctionPrototype.next/)) {
stack = stack.concat(arr.slice(0, index));
return;
}
});
stack = stack.concat(stack2.split('\n').slice(2));
if (!stack[0].match(/^Error:/)) {
stack.unshift(err.message);
}
if (!!label) {
stack.unshift('[DEBUG: ' + label + ']');
}
stack = stack.join('\n');
var newError = new Error();
newError.message = err.message;
newError.stack = stack;
return newError;
} | javascript | function buildError(err, hackErr) {
var stack1 = err.stack;
var stack2 = hackErr.stack;
var label = hackErr.label;
var stack = [];
stack1.split('\n').forEach(function(line, index, arr) {
if (line.match(/^ at GeneratorFunctionPrototype.next/)) {
stack = stack.concat(arr.slice(0, index));
return;
}
});
stack = stack.concat(stack2.split('\n').slice(2));
if (!stack[0].match(/^Error:/)) {
stack.unshift(err.message);
}
if (!!label) {
stack.unshift('[DEBUG: ' + label + ']');
}
stack = stack.join('\n');
var newError = new Error();
newError.message = err.message;
newError.stack = stack;
return newError;
} | [
"function",
"buildError",
"(",
"err",
",",
"hackErr",
")",
"{",
"var",
"stack1",
"=",
"err",
".",
"stack",
";",
"var",
"stack2",
"=",
"hackErr",
".",
"stack",
";",
"var",
"label",
"=",
"hackErr",
".",
"label",
";",
"var",
"stack",
"=",
"[",
"]",
";",
"stack1",
".",
"split",
"(",
"'\\n'",
")",
".",
"forEach",
"(",
"function",
"(",
"line",
",",
"index",
",",
"arr",
")",
"{",
"if",
"(",
"line",
".",
"match",
"(",
"/",
"^ at GeneratorFunctionPrototype.next",
"/",
")",
")",
"{",
"stack",
"=",
"stack",
".",
"concat",
"(",
"arr",
".",
"slice",
"(",
"0",
",",
"index",
")",
")",
";",
"return",
";",
"}",
"}",
")",
";",
"stack",
"=",
"stack",
".",
"concat",
"(",
"stack2",
".",
"split",
"(",
"'\\n'",
")",
".",
"slice",
"(",
"2",
")",
")",
";",
"if",
"(",
"!",
"stack",
"[",
"0",
"]",
".",
"match",
"(",
"/",
"^Error:",
"/",
")",
")",
"{",
"stack",
".",
"unshift",
"(",
"err",
".",
"message",
")",
";",
"}",
"if",
"(",
"!",
"!",
"label",
")",
"{",
"stack",
".",
"unshift",
"(",
"'[DEBUG: '",
"+",
"label",
"+",
"']'",
")",
";",
"}",
"stack",
"=",
"stack",
".",
"join",
"(",
"'\\n'",
")",
";",
"var",
"newError",
"=",
"new",
"Error",
"(",
")",
";",
"newError",
".",
"message",
"=",
"err",
".",
"message",
";",
"newError",
".",
"stack",
"=",
"stack",
";",
"return",
"newError",
";",
"}"
] | Build the full error stack | [
"Build",
"the",
"full",
"error",
"stack"
] | f8ac569e63028111c1942b6caadb651fc0e2e2a8 | https://github.com/iwillwen/co-e/blob/f8ac569e63028111c1942b6caadb651fc0e2e2a8/index.js#L78-L106 |
57,223 | deepjs/deep-promise | index.js | function(argument) {
//console.log("deep.Deferred.resolve : ", argument);
if (this.rejected || this.resolved)
throw new Error("deferred has already been ended !");
if (argument instanceof Error)
return this.reject(argument);
this._success = argument;
this.resolved = true;
var self = this;
this._promises.forEach(function(promise) {
promise.resolve(argument);
});
} | javascript | function(argument) {
//console.log("deep.Deferred.resolve : ", argument);
if (this.rejected || this.resolved)
throw new Error("deferred has already been ended !");
if (argument instanceof Error)
return this.reject(argument);
this._success = argument;
this.resolved = true;
var self = this;
this._promises.forEach(function(promise) {
promise.resolve(argument);
});
} | [
"function",
"(",
"argument",
")",
"{",
"//console.log(\"deep.Deferred.resolve : \", argument);",
"if",
"(",
"this",
".",
"rejected",
"||",
"this",
".",
"resolved",
")",
"throw",
"new",
"Error",
"(",
"\"deferred has already been ended !\"",
")",
";",
"if",
"(",
"argument",
"instanceof",
"Error",
")",
"return",
"this",
".",
"reject",
"(",
"argument",
")",
";",
"this",
".",
"_success",
"=",
"argument",
";",
"this",
".",
"resolved",
"=",
"true",
";",
"var",
"self",
"=",
"this",
";",
"this",
".",
"_promises",
".",
"forEach",
"(",
"function",
"(",
"promise",
")",
"{",
"promise",
".",
"resolve",
"(",
"argument",
")",
";",
"}",
")",
";",
"}"
] | resolve the Deferred and so the associated promise
@method resolve
@param {Object} argument the resolved object injected in promise
@return {deep.Deferred} this | [
"resolve",
"the",
"Deferred",
"and",
"so",
"the",
"associated",
"promise"
] | 022fb9d99def95d0017d965efb88cc4c4393bd30 | https://github.com/deepjs/deep-promise/blob/022fb9d99def95d0017d965efb88cc4c4393bd30/index.js#L263-L275 |
|
57,224 | deepjs/deep-promise | index.js | function(argument) {
// console.log("DeepDeferred.reject");
if (this.rejected || this.resolved)
throw new Error("deferred has already been ended !");
this._error = argument;
this.rejected = true;
var self = this;
this._promises.forEach(function(promise) {
promise.reject(argument);
});
} | javascript | function(argument) {
// console.log("DeepDeferred.reject");
if (this.rejected || this.resolved)
throw new Error("deferred has already been ended !");
this._error = argument;
this.rejected = true;
var self = this;
this._promises.forEach(function(promise) {
promise.reject(argument);
});
} | [
"function",
"(",
"argument",
")",
"{",
"// console.log(\"DeepDeferred.reject\");",
"if",
"(",
"this",
".",
"rejected",
"||",
"this",
".",
"resolved",
")",
"throw",
"new",
"Error",
"(",
"\"deferred has already been ended !\"",
")",
";",
"this",
".",
"_error",
"=",
"argument",
";",
"this",
".",
"rejected",
"=",
"true",
";",
"var",
"self",
"=",
"this",
";",
"this",
".",
"_promises",
".",
"forEach",
"(",
"function",
"(",
"promise",
")",
"{",
"promise",
".",
"reject",
"(",
"argument",
")",
";",
"}",
")",
";",
"}"
] | reject the Deferred and so the associated promise
@method reject
@param {Object} argument the rejected object injected in promise
@return {deep.Deferred} this | [
"reject",
"the",
"Deferred",
"and",
"so",
"the",
"associated",
"promise"
] | 022fb9d99def95d0017d965efb88cc4c4393bd30 | https://github.com/deepjs/deep-promise/blob/022fb9d99def95d0017d965efb88cc4c4393bd30/index.js#L282-L292 |
|
57,225 | deepjs/deep-promise | index.js | function() {
var prom = new promise.Promise();
//console.log("deep2.Deffered.promise : ", prom, " r,r,c : ", this.rejected, this.resolved, this.canceled)
if (this.resolved)
return prom.resolve(this._success);
if (this.rejected)
return prom.reject(this._error);
this._promises.push(prom);
return prom;
} | javascript | function() {
var prom = new promise.Promise();
//console.log("deep2.Deffered.promise : ", prom, " r,r,c : ", this.rejected, this.resolved, this.canceled)
if (this.resolved)
return prom.resolve(this._success);
if (this.rejected)
return prom.reject(this._error);
this._promises.push(prom);
return prom;
} | [
"function",
"(",
")",
"{",
"var",
"prom",
"=",
"new",
"promise",
".",
"Promise",
"(",
")",
";",
"//console.log(\"deep2.Deffered.promise : \", prom, \" r,r,c : \", this.rejected, this.resolved, this.canceled)",
"if",
"(",
"this",
".",
"resolved",
")",
"return",
"prom",
".",
"resolve",
"(",
"this",
".",
"_success",
")",
";",
"if",
"(",
"this",
".",
"rejected",
")",
"return",
"prom",
".",
"reject",
"(",
"this",
".",
"_error",
")",
";",
"this",
".",
"_promises",
".",
"push",
"(",
"prom",
")",
";",
"return",
"prom",
";",
"}"
] | return a promise for this deferred
@method promise
@return {deep.Promise} | [
"return",
"a",
"promise",
"for",
"this",
"deferred"
] | 022fb9d99def95d0017d965efb88cc4c4393bd30 | https://github.com/deepjs/deep-promise/blob/022fb9d99def95d0017d965efb88cc4c4393bd30/index.js#L298-L307 |
|
57,226 | AlphaReplica/Connecta | lib/client/source/connecta.js | init | function init()
{
scope._servConn = new ConnectaSocket(scope._url,scope._reconnect,scope._encode);
scope._servConn.onConnected = function(e)
{
scope.id = e;
scope.dispatchEvent("connected");
}
scope._servConn.onError = function(e)
{
scope.dispatchEvent("error",e);
}
scope._servConn.onClose = function(e)
{
scope.dispatchEvent("close");
scope.closePeers();
}
scope._servConn.onJoinedRoom = onJoinedRoom;
scope._servConn.onClientJoinedRoom = onClientJoinedRoom;
scope._servConn.onLeftRoom = onLeftRoom;
scope._servConn.onClientLeftRoom = onClientLeftRoom;
scope._servConn.onSDPDescription = onSDPDescription;
scope._servConn.onIceCandidate = onIceCandidate;
scope._servConn.onRTCFallback = onRTCFallback;
scope._servConn.onMessage = onServerMessage;
scope._servConn.onBytesMessage = onServerByteArray;
window.addEventListener("beforeunload", function (event)
{
scope.dispose();
});
} | javascript | function init()
{
scope._servConn = new ConnectaSocket(scope._url,scope._reconnect,scope._encode);
scope._servConn.onConnected = function(e)
{
scope.id = e;
scope.dispatchEvent("connected");
}
scope._servConn.onError = function(e)
{
scope.dispatchEvent("error",e);
}
scope._servConn.onClose = function(e)
{
scope.dispatchEvent("close");
scope.closePeers();
}
scope._servConn.onJoinedRoom = onJoinedRoom;
scope._servConn.onClientJoinedRoom = onClientJoinedRoom;
scope._servConn.onLeftRoom = onLeftRoom;
scope._servConn.onClientLeftRoom = onClientLeftRoom;
scope._servConn.onSDPDescription = onSDPDescription;
scope._servConn.onIceCandidate = onIceCandidate;
scope._servConn.onRTCFallback = onRTCFallback;
scope._servConn.onMessage = onServerMessage;
scope._servConn.onBytesMessage = onServerByteArray;
window.addEventListener("beforeunload", function (event)
{
scope.dispose();
});
} | [
"function",
"init",
"(",
")",
"{",
"scope",
".",
"_servConn",
"=",
"new",
"ConnectaSocket",
"(",
"scope",
".",
"_url",
",",
"scope",
".",
"_reconnect",
",",
"scope",
".",
"_encode",
")",
";",
"scope",
".",
"_servConn",
".",
"onConnected",
"=",
"function",
"(",
"e",
")",
"{",
"scope",
".",
"id",
"=",
"e",
";",
"scope",
".",
"dispatchEvent",
"(",
"\"connected\"",
")",
";",
"}",
"scope",
".",
"_servConn",
".",
"onError",
"=",
"function",
"(",
"e",
")",
"{",
"scope",
".",
"dispatchEvent",
"(",
"\"error\"",
",",
"e",
")",
";",
"}",
"scope",
".",
"_servConn",
".",
"onClose",
"=",
"function",
"(",
"e",
")",
"{",
"scope",
".",
"dispatchEvent",
"(",
"\"close\"",
")",
";",
"scope",
".",
"closePeers",
"(",
")",
";",
"}",
"scope",
".",
"_servConn",
".",
"onJoinedRoom",
"=",
"onJoinedRoom",
";",
"scope",
".",
"_servConn",
".",
"onClientJoinedRoom",
"=",
"onClientJoinedRoom",
";",
"scope",
".",
"_servConn",
".",
"onLeftRoom",
"=",
"onLeftRoom",
";",
"scope",
".",
"_servConn",
".",
"onClientLeftRoom",
"=",
"onClientLeftRoom",
";",
"scope",
".",
"_servConn",
".",
"onSDPDescription",
"=",
"onSDPDescription",
";",
"scope",
".",
"_servConn",
".",
"onIceCandidate",
"=",
"onIceCandidate",
";",
"scope",
".",
"_servConn",
".",
"onRTCFallback",
"=",
"onRTCFallback",
";",
"scope",
".",
"_servConn",
".",
"onMessage",
"=",
"onServerMessage",
";",
"scope",
".",
"_servConn",
".",
"onBytesMessage",
"=",
"onServerByteArray",
";",
"window",
".",
"addEventListener",
"(",
"\"beforeunload\"",
",",
"function",
"(",
"event",
")",
"{",
"scope",
".",
"dispose",
"(",
")",
";",
"}",
")",
";",
"}"
] | init acts as constructor | [
"init",
"acts",
"as",
"constructor"
] | bc0ce3fa1ef5ef07526633da5668dcaff5ef29e0 | https://github.com/AlphaReplica/Connecta/blob/bc0ce3fa1ef5ef07526633da5668dcaff5ef29e0/lib/client/source/connecta.js#L28-L60 |
57,227 | AlphaReplica/Connecta | lib/client/source/connecta.js | createPeerInstance | function createPeerInstance(id)
{
var peer = new ConnectaPeer(id,stunUrls);
peer.onIceCandidate = gotIceCandidate;
peer.onDescription = createdDescription;
peer.onRemoteStream = gotRemoteStream;
peer.onConnected = onPeerConnected;
peer.onMessage = onPeerMessage;
peer.onBytesMessage = onBytesMessage;
peer.onConnectionFail = onPeerFailed;
peer.onClosed = onPeerClose;
peer.onError = onPeerError;
peer.onChannelState = onPeerState;
scope.peers[id] = peer;
peer.init();
return peer;
} | javascript | function createPeerInstance(id)
{
var peer = new ConnectaPeer(id,stunUrls);
peer.onIceCandidate = gotIceCandidate;
peer.onDescription = createdDescription;
peer.onRemoteStream = gotRemoteStream;
peer.onConnected = onPeerConnected;
peer.onMessage = onPeerMessage;
peer.onBytesMessage = onBytesMessage;
peer.onConnectionFail = onPeerFailed;
peer.onClosed = onPeerClose;
peer.onError = onPeerError;
peer.onChannelState = onPeerState;
scope.peers[id] = peer;
peer.init();
return peer;
} | [
"function",
"createPeerInstance",
"(",
"id",
")",
"{",
"var",
"peer",
"=",
"new",
"ConnectaPeer",
"(",
"id",
",",
"stunUrls",
")",
";",
"peer",
".",
"onIceCandidate",
"=",
"gotIceCandidate",
";",
"peer",
".",
"onDescription",
"=",
"createdDescription",
";",
"peer",
".",
"onRemoteStream",
"=",
"gotRemoteStream",
";",
"peer",
".",
"onConnected",
"=",
"onPeerConnected",
";",
"peer",
".",
"onMessage",
"=",
"onPeerMessage",
";",
"peer",
".",
"onBytesMessage",
"=",
"onBytesMessage",
";",
"peer",
".",
"onConnectionFail",
"=",
"onPeerFailed",
";",
"peer",
".",
"onClosed",
"=",
"onPeerClose",
";",
"peer",
".",
"onError",
"=",
"onPeerError",
";",
"peer",
".",
"onChannelState",
"=",
"onPeerState",
";",
"scope",
".",
"peers",
"[",
"id",
"]",
"=",
"peer",
";",
"peer",
".",
"init",
"(",
")",
";",
"return",
"peer",
";",
"}"
] | creates ConnectaPeer Instance and returns | [
"creates",
"ConnectaPeer",
"Instance",
"and",
"returns"
] | bc0ce3fa1ef5ef07526633da5668dcaff5ef29e0 | https://github.com/AlphaReplica/Connecta/blob/bc0ce3fa1ef5ef07526633da5668dcaff5ef29e0/lib/client/source/connecta.js#L63-L81 |
57,228 | AlphaReplica/Connecta | lib/client/source/connecta.js | getPeerByRTCId | function getPeerByRTCId(id)
{
for(var num = 0; num < scope._servConn.roomUsers.length; num++)
{
if(scope._servConn.roomUsers[num].rtcId == id)
{
return scope._servConn.roomUsers[num];
}
}
return null;
} | javascript | function getPeerByRTCId(id)
{
for(var num = 0; num < scope._servConn.roomUsers.length; num++)
{
if(scope._servConn.roomUsers[num].rtcId == id)
{
return scope._servConn.roomUsers[num];
}
}
return null;
} | [
"function",
"getPeerByRTCId",
"(",
"id",
")",
"{",
"for",
"(",
"var",
"num",
"=",
"0",
";",
"num",
"<",
"scope",
".",
"_servConn",
".",
"roomUsers",
".",
"length",
";",
"num",
"++",
")",
"{",
"if",
"(",
"scope",
".",
"_servConn",
".",
"roomUsers",
"[",
"num",
"]",
".",
"rtcId",
"==",
"id",
")",
"{",
"return",
"scope",
".",
"_servConn",
".",
"roomUsers",
"[",
"num",
"]",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | gets ConnectaPeer instance by rtcId | [
"gets",
"ConnectaPeer",
"instance",
"by",
"rtcId"
] | bc0ce3fa1ef5ef07526633da5668dcaff5ef29e0 | https://github.com/AlphaReplica/Connecta/blob/bc0ce3fa1ef5ef07526633da5668dcaff5ef29e0/lib/client/source/connecta.js#L94-L104 |
57,229 | AlphaReplica/Connecta | lib/client/source/connecta.js | getOrCreatePeer | function getOrCreatePeer(id)
{
if(scope.peers[id])
{
return scope.peers[id];
}
return createPeerInstance(id);
} | javascript | function getOrCreatePeer(id)
{
if(scope.peers[id])
{
return scope.peers[id];
}
return createPeerInstance(id);
} | [
"function",
"getOrCreatePeer",
"(",
"id",
")",
"{",
"if",
"(",
"scope",
".",
"peers",
"[",
"id",
"]",
")",
"{",
"return",
"scope",
".",
"peers",
"[",
"id",
"]",
";",
"}",
"return",
"createPeerInstance",
"(",
"id",
")",
";",
"}"
] | gets ConnectaPeer instance by id, if not exists, creates new and returns | [
"gets",
"ConnectaPeer",
"instance",
"by",
"id",
"if",
"not",
"exists",
"creates",
"new",
"and",
"returns"
] | bc0ce3fa1ef5ef07526633da5668dcaff5ef29e0 | https://github.com/AlphaReplica/Connecta/blob/bc0ce3fa1ef5ef07526633da5668dcaff5ef29e0/lib/client/source/connecta.js#L107-L114 |
57,230 | AlphaReplica/Connecta | lib/client/source/connecta.js | onClientJoinedRoom | function onClientJoinedRoom(id)
{
if(scope._servConn.useRTC)
{
if(scope.hasWebRTCSupport())
{
var peer = getOrCreatePeer(id);
peer.createOffer();
}
else
{
scope._servConn.sendRTCState(false,id);
}
}
scope.dispatchEvent("clientJoinedRoom",id);
} | javascript | function onClientJoinedRoom(id)
{
if(scope._servConn.useRTC)
{
if(scope.hasWebRTCSupport())
{
var peer = getOrCreatePeer(id);
peer.createOffer();
}
else
{
scope._servConn.sendRTCState(false,id);
}
}
scope.dispatchEvent("clientJoinedRoom",id);
} | [
"function",
"onClientJoinedRoom",
"(",
"id",
")",
"{",
"if",
"(",
"scope",
".",
"_servConn",
".",
"useRTC",
")",
"{",
"if",
"(",
"scope",
".",
"hasWebRTCSupport",
"(",
")",
")",
"{",
"var",
"peer",
"=",
"getOrCreatePeer",
"(",
"id",
")",
";",
"peer",
".",
"createOffer",
"(",
")",
";",
"}",
"else",
"{",
"scope",
".",
"_servConn",
".",
"sendRTCState",
"(",
"false",
",",
"id",
")",
";",
"}",
"}",
"scope",
".",
"dispatchEvent",
"(",
"\"clientJoinedRoom\"",
",",
"id",
")",
";",
"}"
] | called when client joined in room, if rtc enabled and browser has support of rtc, creates offer and sends to peer by sending sdp string to server, else notifies server to add connection in fallback list | [
"called",
"when",
"client",
"joined",
"in",
"room",
"if",
"rtc",
"enabled",
"and",
"browser",
"has",
"support",
"of",
"rtc",
"creates",
"offer",
"and",
"sends",
"to",
"peer",
"by",
"sending",
"sdp",
"string",
"to",
"server",
"else",
"notifies",
"server",
"to",
"add",
"connection",
"in",
"fallback",
"list"
] | bc0ce3fa1ef5ef07526633da5668dcaff5ef29e0 | https://github.com/AlphaReplica/Connecta/blob/bc0ce3fa1ef5ef07526633da5668dcaff5ef29e0/lib/client/source/connecta.js#L123-L138 |
57,231 | AlphaReplica/Connecta | lib/client/source/connecta.js | onRTCFallback | function onRTCFallback(from,data,isArray)
{
var peer = getPeerByRTCId(from);
if(peer)
{
if(isArray == true)
{
data = sliceArray(data,0,data.length-2);// data.slice(0,data.length-2);
}
scope.dispatchEvent("peerMessage",{message:data,id:peer.id,rtc:peer.rtcId,array:isArray,fallback:true});
}
} | javascript | function onRTCFallback(from,data,isArray)
{
var peer = getPeerByRTCId(from);
if(peer)
{
if(isArray == true)
{
data = sliceArray(data,0,data.length-2);// data.slice(0,data.length-2);
}
scope.dispatchEvent("peerMessage",{message:data,id:peer.id,rtc:peer.rtcId,array:isArray,fallback:true});
}
} | [
"function",
"onRTCFallback",
"(",
"from",
",",
"data",
",",
"isArray",
")",
"{",
"var",
"peer",
"=",
"getPeerByRTCId",
"(",
"from",
")",
";",
"if",
"(",
"peer",
")",
"{",
"if",
"(",
"isArray",
"==",
"true",
")",
"{",
"data",
"=",
"sliceArray",
"(",
"data",
",",
"0",
",",
"data",
".",
"length",
"-",
"2",
")",
";",
"// data.slice(0,data.length-2);",
"}",
"scope",
".",
"dispatchEvent",
"(",
"\"peerMessage\"",
",",
"{",
"message",
":",
"data",
",",
"id",
":",
"peer",
".",
"id",
",",
"rtc",
":",
"peer",
".",
"rtcId",
",",
"array",
":",
"isArray",
",",
"fallback",
":",
"true",
"}",
")",
";",
"}",
"}"
] | invoked when fallback message is received | [
"invoked",
"when",
"fallback",
"message",
"is",
"received"
] | bc0ce3fa1ef5ef07526633da5668dcaff5ef29e0 | https://github.com/AlphaReplica/Connecta/blob/bc0ce3fa1ef5ef07526633da5668dcaff5ef29e0/lib/client/source/connecta.js#L155-L167 |
57,232 | AlphaReplica/Connecta | lib/client/source/connecta.js | onServerMessage | function onServerMessage(data)
{
if(data.ev)
{
scope.dispatchEvent("onServerMessage",data);
scope.dispatchEvent(data.ev,data);
}
} | javascript | function onServerMessage(data)
{
if(data.ev)
{
scope.dispatchEvent("onServerMessage",data);
scope.dispatchEvent(data.ev,data);
}
} | [
"function",
"onServerMessage",
"(",
"data",
")",
"{",
"if",
"(",
"data",
".",
"ev",
")",
"{",
"scope",
".",
"dispatchEvent",
"(",
"\"onServerMessage\"",
",",
"data",
")",
";",
"scope",
".",
"dispatchEvent",
"(",
"data",
".",
"ev",
",",
"data",
")",
";",
"}",
"}"
] | invoked when server message received | [
"invoked",
"when",
"server",
"message",
"received"
] | bc0ce3fa1ef5ef07526633da5668dcaff5ef29e0 | https://github.com/AlphaReplica/Connecta/blob/bc0ce3fa1ef5ef07526633da5668dcaff5ef29e0/lib/client/source/connecta.js#L176-L183 |
57,233 | AlphaReplica/Connecta | lib/client/source/connecta.js | onPeerConnected | function onPeerConnected(peer)
{
if(scope.localStream)
{
peer.updateStream(scope.localStream,false);
}
scope._servConn.sendRTCState(true,peer.id);
scope.dispatchEvent("peerConnected",peer.id);
} | javascript | function onPeerConnected(peer)
{
if(scope.localStream)
{
peer.updateStream(scope.localStream,false);
}
scope._servConn.sendRTCState(true,peer.id);
scope.dispatchEvent("peerConnected",peer.id);
} | [
"function",
"onPeerConnected",
"(",
"peer",
")",
"{",
"if",
"(",
"scope",
".",
"localStream",
")",
"{",
"peer",
".",
"updateStream",
"(",
"scope",
".",
"localStream",
",",
"false",
")",
";",
"}",
"scope",
".",
"_servConn",
".",
"sendRTCState",
"(",
"true",
",",
"peer",
".",
"id",
")",
";",
"scope",
".",
"dispatchEvent",
"(",
"\"peerConnected\"",
",",
"peer",
".",
"id",
")",
";",
"}"
] | invoked when peer connection, notifies server and resends offser if stream is enabled | [
"invoked",
"when",
"peer",
"connection",
"notifies",
"server",
"and",
"resends",
"offser",
"if",
"stream",
"is",
"enabled"
] | bc0ce3fa1ef5ef07526633da5668dcaff5ef29e0 | https://github.com/AlphaReplica/Connecta/blob/bc0ce3fa1ef5ef07526633da5668dcaff5ef29e0/lib/client/source/connecta.js#L201-L210 |
57,234 | AlphaReplica/Connecta | lib/client/source/connecta.js | onPeerFailed | function onPeerFailed(peer)
{
scope._servConn.sendRTCState(false,peer.id);
scope.dispatchEvent("peerFailed",peer.id);
} | javascript | function onPeerFailed(peer)
{
scope._servConn.sendRTCState(false,peer.id);
scope.dispatchEvent("peerFailed",peer.id);
} | [
"function",
"onPeerFailed",
"(",
"peer",
")",
"{",
"scope",
".",
"_servConn",
".",
"sendRTCState",
"(",
"false",
",",
"peer",
".",
"id",
")",
";",
"scope",
".",
"dispatchEvent",
"(",
"\"peerFailed\"",
",",
"peer",
".",
"id",
")",
";",
"}"
] | invoked when peer fails to connect | [
"invoked",
"when",
"peer",
"fails",
"to",
"connect"
] | bc0ce3fa1ef5ef07526633da5668dcaff5ef29e0 | https://github.com/AlphaReplica/Connecta/blob/bc0ce3fa1ef5ef07526633da5668dcaff5ef29e0/lib/client/source/connecta.js#L213-L217 |
57,235 | AlphaReplica/Connecta | lib/client/source/connecta.js | onPeerClose | function onPeerClose(peer)
{
var id = peer.id;
scope.removePeer(peer);
sendPeerClose(id);
scope.dispatchEvent("peerDisconnected",id);
} | javascript | function onPeerClose(peer)
{
var id = peer.id;
scope.removePeer(peer);
sendPeerClose(id);
scope.dispatchEvent("peerDisconnected",id);
} | [
"function",
"onPeerClose",
"(",
"peer",
")",
"{",
"var",
"id",
"=",
"peer",
".",
"id",
";",
"scope",
".",
"removePeer",
"(",
"peer",
")",
";",
"sendPeerClose",
"(",
"id",
")",
";",
"scope",
".",
"dispatchEvent",
"(",
"\"peerDisconnected\"",
",",
"id",
")",
";",
"}"
] | invoked when peer closes, this will remove peer from dictionary | [
"invoked",
"when",
"peer",
"closes",
"this",
"will",
"remove",
"peer",
"from",
"dictionary"
] | bc0ce3fa1ef5ef07526633da5668dcaff5ef29e0 | https://github.com/AlphaReplica/Connecta/blob/bc0ce3fa1ef5ef07526633da5668dcaff5ef29e0/lib/client/source/connecta.js#L220-L227 |
57,236 | AlphaReplica/Connecta | lib/client/source/connecta.js | onIceCandidate | function onIceCandidate(id,data)
{
if(scope.hasWebRTCSupport())
{
getOrCreatePeer(id).onServerMessage(JSON.parse(data));
}
} | javascript | function onIceCandidate(id,data)
{
if(scope.hasWebRTCSupport())
{
getOrCreatePeer(id).onServerMessage(JSON.parse(data));
}
} | [
"function",
"onIceCandidate",
"(",
"id",
",",
"data",
")",
"{",
"if",
"(",
"scope",
".",
"hasWebRTCSupport",
"(",
")",
")",
"{",
"getOrCreatePeer",
"(",
"id",
")",
".",
"onServerMessage",
"(",
"JSON",
".",
"parse",
"(",
"data",
")",
")",
";",
"}",
"}"
] | invoked when peer creates ice candidate and it's ready to send | [
"invoked",
"when",
"peer",
"creates",
"ice",
"candidate",
"and",
"it",
"s",
"ready",
"to",
"send"
] | bc0ce3fa1ef5ef07526633da5668dcaff5ef29e0 | https://github.com/AlphaReplica/Connecta/blob/bc0ce3fa1ef5ef07526633da5668dcaff5ef29e0/lib/client/source/connecta.js#L266-L272 |
57,237 | AlphaReplica/Connecta | lib/client/source/connecta.js | onPeerMessage | function onPeerMessage(peer,msg)
{
scope.dispatchEvent("peerMessage",{message:msg,id:peer.id,rtc:peer.rtcId,array:false,fallback:false});
} | javascript | function onPeerMessage(peer,msg)
{
scope.dispatchEvent("peerMessage",{message:msg,id:peer.id,rtc:peer.rtcId,array:false,fallback:false});
} | [
"function",
"onPeerMessage",
"(",
"peer",
",",
"msg",
")",
"{",
"scope",
".",
"dispatchEvent",
"(",
"\"peerMessage\"",
",",
"{",
"message",
":",
"msg",
",",
"id",
":",
"peer",
".",
"id",
",",
"rtc",
":",
"peer",
".",
"rtcId",
",",
"array",
":",
"false",
",",
"fallback",
":",
"false",
"}",
")",
";",
"}"
] | invoked when string message received from peer | [
"invoked",
"when",
"string",
"message",
"received",
"from",
"peer"
] | bc0ce3fa1ef5ef07526633da5668dcaff5ef29e0 | https://github.com/AlphaReplica/Connecta/blob/bc0ce3fa1ef5ef07526633da5668dcaff5ef29e0/lib/client/source/connecta.js#L275-L278 |
57,238 | AlphaReplica/Connecta | lib/client/source/connecta.js | onBytesMessage | function onBytesMessage(peer,data)
{
var arr = bufferToArray(scope._servConn.byteType,data);
if(arr)
{
if(scope._servConn.rtcFallback == true)
{
arr = arr.slice(0,arr.length-2);
}
scope.dispatchEvent("peerMessage",{message:arr,id:peer.id,rtc:peer.rtcId,array:true,fallback:false});
}
} | javascript | function onBytesMessage(peer,data)
{
var arr = bufferToArray(scope._servConn.byteType,data);
if(arr)
{
if(scope._servConn.rtcFallback == true)
{
arr = arr.slice(0,arr.length-2);
}
scope.dispatchEvent("peerMessage",{message:arr,id:peer.id,rtc:peer.rtcId,array:true,fallback:false});
}
} | [
"function",
"onBytesMessage",
"(",
"peer",
",",
"data",
")",
"{",
"var",
"arr",
"=",
"bufferToArray",
"(",
"scope",
".",
"_servConn",
".",
"byteType",
",",
"data",
")",
";",
"if",
"(",
"arr",
")",
"{",
"if",
"(",
"scope",
".",
"_servConn",
".",
"rtcFallback",
"==",
"true",
")",
"{",
"arr",
"=",
"arr",
".",
"slice",
"(",
"0",
",",
"arr",
".",
"length",
"-",
"2",
")",
";",
"}",
"scope",
".",
"dispatchEvent",
"(",
"\"peerMessage\"",
",",
"{",
"message",
":",
"arr",
",",
"id",
":",
"peer",
".",
"id",
",",
"rtc",
":",
"peer",
".",
"rtcId",
",",
"array",
":",
"true",
",",
"fallback",
":",
"false",
"}",
")",
";",
"}",
"}"
] | invoked when byte message received from peer | [
"invoked",
"when",
"byte",
"message",
"received",
"from",
"peer"
] | bc0ce3fa1ef5ef07526633da5668dcaff5ef29e0 | https://github.com/AlphaReplica/Connecta/blob/bc0ce3fa1ef5ef07526633da5668dcaff5ef29e0/lib/client/source/connecta.js#L281-L293 |
57,239 | compose-ui/dialog | index.js | addText | function addText() {
// Add title
dialogEl.querySelector( '#dialog-title' ).innerHTML = options.title
// Add optional description
var descriptionEl = dialogEl.querySelector( '#dialog-description' )
if ( options.description ) {
descriptionEl.innerHTML = options.description
} else {
descriptionEl.parentElement.removeChild( descriptionEl )
dialogEl.removeAttribute( 'aria-labelledby' )
}
} | javascript | function addText() {
// Add title
dialogEl.querySelector( '#dialog-title' ).innerHTML = options.title
// Add optional description
var descriptionEl = dialogEl.querySelector( '#dialog-description' )
if ( options.description ) {
descriptionEl.innerHTML = options.description
} else {
descriptionEl.parentElement.removeChild( descriptionEl )
dialogEl.removeAttribute( 'aria-labelledby' )
}
} | [
"function",
"addText",
"(",
")",
"{",
"// Add title",
"dialogEl",
".",
"querySelector",
"(",
"'#dialog-title'",
")",
".",
"innerHTML",
"=",
"options",
".",
"title",
"// Add optional description",
"var",
"descriptionEl",
"=",
"dialogEl",
".",
"querySelector",
"(",
"'#dialog-description'",
")",
"if",
"(",
"options",
".",
"description",
")",
"{",
"descriptionEl",
".",
"innerHTML",
"=",
"options",
".",
"description",
"}",
"else",
"{",
"descriptionEl",
".",
"parentElement",
".",
"removeChild",
"(",
"descriptionEl",
")",
"dialogEl",
".",
"removeAttribute",
"(",
"'aria-labelledby'",
")",
"}",
"}"
] | Add title and description from options | [
"Add",
"title",
"and",
"description",
"from",
"options"
] | 5d085394c4414d12ade5b7c864cbef80e2837f44 | https://github.com/compose-ui/dialog/blob/5d085394c4414d12ade5b7c864cbef80e2837f44/index.js#L56-L71 |
57,240 | compose-ui/dialog | index.js | tab | function tab( event ) {
// Find all focusable elements in the dialog card
var focusable = dialogEl.querySelectorAll('input:not([type=hidden]), textarea, select, button'),
last = focusable[focusable.length - 1],
focused = document.activeElement
// If focused on the last focusable element, tab to the first element.
if ( focused == last ) {
if ( event ){ event.preventDefault() }
focusable[0].focus()
}
// Focus on the last element if the focused element is not a child of the dialog
if ( !focused || !toolbox.childOf( focused, dialogEl ) ) {
last.focus()
}
} | javascript | function tab( event ) {
// Find all focusable elements in the dialog card
var focusable = dialogEl.querySelectorAll('input:not([type=hidden]), textarea, select, button'),
last = focusable[focusable.length - 1],
focused = document.activeElement
// If focused on the last focusable element, tab to the first element.
if ( focused == last ) {
if ( event ){ event.preventDefault() }
focusable[0].focus()
}
// Focus on the last element if the focused element is not a child of the dialog
if ( !focused || !toolbox.childOf( focused, dialogEl ) ) {
last.focus()
}
} | [
"function",
"tab",
"(",
"event",
")",
"{",
"// Find all focusable elements in the dialog card",
"var",
"focusable",
"=",
"dialogEl",
".",
"querySelectorAll",
"(",
"'input:not([type=hidden]), textarea, select, button'",
")",
",",
"last",
"=",
"focusable",
"[",
"focusable",
".",
"length",
"-",
"1",
"]",
",",
"focused",
"=",
"document",
".",
"activeElement",
"// If focused on the last focusable element, tab to the first element.",
"if",
"(",
"focused",
"==",
"last",
")",
"{",
"if",
"(",
"event",
")",
"{",
"event",
".",
"preventDefault",
"(",
")",
"}",
"focusable",
"[",
"0",
"]",
".",
"focus",
"(",
")",
"}",
"// Focus on the last element if the focused element is not a child of the dialog",
"if",
"(",
"!",
"focused",
"||",
"!",
"toolbox",
".",
"childOf",
"(",
"focused",
",",
"dialogEl",
")",
")",
"{",
"last",
".",
"focus",
"(",
")",
"}",
"}"
] | In a modal window, `tab` must cycle between elements in the modal. | [
"In",
"a",
"modal",
"window",
"tab",
"must",
"cycle",
"between",
"elements",
"in",
"the",
"modal",
"."
] | 5d085394c4414d12ade5b7c864cbef80e2837f44 | https://github.com/compose-ui/dialog/blob/5d085394c4414d12ade5b7c864cbef80e2837f44/index.js#L98-L115 |
57,241 | muigui/useful-date | index.js | function( d ) { // ISO-8601 year number. This has the same value as Y, except that if the ISO
var m = d.getMonth(), w = DATE_PROTO.getISOWeek.call( d ); // week number (W) belongs to the previous or next year, that year is used instead.
return ( d.getFullYear() + ( w == 1 && m > 0 ? 1 : ( w >= 52 && m < 11 ? -1 : 0 ) ) );
} | javascript | function( d ) { // ISO-8601 year number. This has the same value as Y, except that if the ISO
var m = d.getMonth(), w = DATE_PROTO.getISOWeek.call( d ); // week number (W) belongs to the previous or next year, that year is used instead.
return ( d.getFullYear() + ( w == 1 && m > 0 ? 1 : ( w >= 52 && m < 11 ? -1 : 0 ) ) );
} | [
"function",
"(",
"d",
")",
"{",
"// ISO-8601 year number. This has the same value as Y, except that if the ISO",
"var",
"m",
"=",
"d",
".",
"getMonth",
"(",
")",
",",
"w",
"=",
"DATE_PROTO",
".",
"getISOWeek",
".",
"call",
"(",
"d",
")",
";",
"// week number (W) belongs to the previous or next year, that year is used instead.",
"return",
"(",
"d",
".",
"getFullYear",
"(",
")",
"+",
"(",
"w",
"==",
"1",
"&&",
"m",
">",
"0",
"?",
"1",
":",
"(",
"w",
">=",
"52",
"&&",
"m",
"<",
"11",
"?",
"-",
"1",
":",
"0",
")",
")",
")",
";",
"}"
] | Whether it's a leap year | [
"Whether",
"it",
"s",
"a",
"leap",
"year"
] | 1dd1e82767336f5394bfc38570480340348ba966 | https://github.com/muigui/useful-date/blob/1dd1e82767336f5394bfc38570480340348ba966/index.js#L761-L764 |
|
57,242 | ItsAsbreuk/itsa-mojitonthefly-addon | examples/webapp using pjax/mojits/Navigation/controller.server.js | function(ac) {
var data = {},
selectedmojit = ac.params.getFromRoute('mojit') || 'none';
data[selectedmojit] = true;
ac.assets.addCss('./index.css');
ac.done(data);
} | javascript | function(ac) {
var data = {},
selectedmojit = ac.params.getFromRoute('mojit') || 'none';
data[selectedmojit] = true;
ac.assets.addCss('./index.css');
ac.done(data);
} | [
"function",
"(",
"ac",
")",
"{",
"var",
"data",
"=",
"{",
"}",
",",
"selectedmojit",
"=",
"ac",
".",
"params",
".",
"getFromRoute",
"(",
"'mojit'",
")",
"||",
"'none'",
";",
"data",
"[",
"selectedmojit",
"]",
"=",
"true",
";",
"ac",
".",
"assets",
".",
"addCss",
"(",
"'./index.css'",
")",
";",
"ac",
".",
"done",
"(",
"data",
")",
";",
"}"
] | Method corresponding to the 'index' action.
@param ac {Object} The ActionContext that provides access
to the Mojito API. | [
"Method",
"corresponding",
"to",
"the",
"index",
"action",
"."
] | 500de397fef8f80f719360d4ac023bb860934ec0 | https://github.com/ItsAsbreuk/itsa-mojitonthefly-addon/blob/500de397fef8f80f719360d4ac023bb860934ec0/examples/webapp using pjax/mojits/Navigation/controller.server.js#L24-L30 |
|
57,243 | Industryswarm/isnode-mod-data | lib/mongodb/mongodb/lib/bulk/ordered.js | executeCommands | function executeCommands(bulkOperation, options, callback) {
if (bulkOperation.s.batches.length === 0) {
return handleCallback(callback, null, new BulkWriteResult(bulkOperation.s.bulkResult));
}
// Ordered execution of the command
const batch = bulkOperation.s.batches.shift();
function resultHandler(err, result) {
// Error is a driver related error not a bulk op error, terminate
if (((err && err.driver) || (err && err.message)) && !(err instanceof MongoWriteConcernError)) {
return handleCallback(callback, err);
}
// If we have and error
if (err) err.ok = 0;
if (err instanceof MongoWriteConcernError) {
return handleMongoWriteConcernError(batch, bulkOperation.s.bulkResult, true, err, callback);
}
// Merge the results together
const writeResult = new BulkWriteResult(bulkOperation.s.bulkResult);
const mergeResult = mergeBatchResults(true, batch, bulkOperation.s.bulkResult, err, result);
if (mergeResult != null) {
return handleCallback(callback, null, writeResult);
}
if (bulkOperation.handleWriteError(callback, writeResult)) return;
// Execute the next command in line
executeCommands(bulkOperation, options, callback);
}
bulkOperation.finalOptionsHandler({ options, batch, resultHandler }, callback);
} | javascript | function executeCommands(bulkOperation, options, callback) {
if (bulkOperation.s.batches.length === 0) {
return handleCallback(callback, null, new BulkWriteResult(bulkOperation.s.bulkResult));
}
// Ordered execution of the command
const batch = bulkOperation.s.batches.shift();
function resultHandler(err, result) {
// Error is a driver related error not a bulk op error, terminate
if (((err && err.driver) || (err && err.message)) && !(err instanceof MongoWriteConcernError)) {
return handleCallback(callback, err);
}
// If we have and error
if (err) err.ok = 0;
if (err instanceof MongoWriteConcernError) {
return handleMongoWriteConcernError(batch, bulkOperation.s.bulkResult, true, err, callback);
}
// Merge the results together
const writeResult = new BulkWriteResult(bulkOperation.s.bulkResult);
const mergeResult = mergeBatchResults(true, batch, bulkOperation.s.bulkResult, err, result);
if (mergeResult != null) {
return handleCallback(callback, null, writeResult);
}
if (bulkOperation.handleWriteError(callback, writeResult)) return;
// Execute the next command in line
executeCommands(bulkOperation, options, callback);
}
bulkOperation.finalOptionsHandler({ options, batch, resultHandler }, callback);
} | [
"function",
"executeCommands",
"(",
"bulkOperation",
",",
"options",
",",
"callback",
")",
"{",
"if",
"(",
"bulkOperation",
".",
"s",
".",
"batches",
".",
"length",
"===",
"0",
")",
"{",
"return",
"handleCallback",
"(",
"callback",
",",
"null",
",",
"new",
"BulkWriteResult",
"(",
"bulkOperation",
".",
"s",
".",
"bulkResult",
")",
")",
";",
"}",
"// Ordered execution of the command",
"const",
"batch",
"=",
"bulkOperation",
".",
"s",
".",
"batches",
".",
"shift",
"(",
")",
";",
"function",
"resultHandler",
"(",
"err",
",",
"result",
")",
"{",
"// Error is a driver related error not a bulk op error, terminate",
"if",
"(",
"(",
"(",
"err",
"&&",
"err",
".",
"driver",
")",
"||",
"(",
"err",
"&&",
"err",
".",
"message",
")",
")",
"&&",
"!",
"(",
"err",
"instanceof",
"MongoWriteConcernError",
")",
")",
"{",
"return",
"handleCallback",
"(",
"callback",
",",
"err",
")",
";",
"}",
"// If we have and error",
"if",
"(",
"err",
")",
"err",
".",
"ok",
"=",
"0",
";",
"if",
"(",
"err",
"instanceof",
"MongoWriteConcernError",
")",
"{",
"return",
"handleMongoWriteConcernError",
"(",
"batch",
",",
"bulkOperation",
".",
"s",
".",
"bulkResult",
",",
"true",
",",
"err",
",",
"callback",
")",
";",
"}",
"// Merge the results together",
"const",
"writeResult",
"=",
"new",
"BulkWriteResult",
"(",
"bulkOperation",
".",
"s",
".",
"bulkResult",
")",
";",
"const",
"mergeResult",
"=",
"mergeBatchResults",
"(",
"true",
",",
"batch",
",",
"bulkOperation",
".",
"s",
".",
"bulkResult",
",",
"err",
",",
"result",
")",
";",
"if",
"(",
"mergeResult",
"!=",
"null",
")",
"{",
"return",
"handleCallback",
"(",
"callback",
",",
"null",
",",
"writeResult",
")",
";",
"}",
"if",
"(",
"bulkOperation",
".",
"handleWriteError",
"(",
"callback",
",",
"writeResult",
")",
")",
"return",
";",
"// Execute the next command in line",
"executeCommands",
"(",
"bulkOperation",
",",
"options",
",",
"callback",
")",
";",
"}",
"bulkOperation",
".",
"finalOptionsHandler",
"(",
"{",
"options",
",",
"batch",
",",
"resultHandler",
"}",
",",
"callback",
")",
";",
"}"
] | Execute next write command in a chain
@param {OrderedBulkOperation} bulkOperation
@param {object} options
@param {function} callback | [
"Execute",
"next",
"write",
"command",
"in",
"a",
"chain"
] | 5adc639b88a0d72cbeef23a6b5df7f4540745089 | https://github.com/Industryswarm/isnode-mod-data/blob/5adc639b88a0d72cbeef23a6b5df7f4540745089/lib/mongodb/mongodb/lib/bulk/ordered.js#L132-L166 |
57,244 | mthadley/magnet-plugin-sass | src/index.js | serveSassFiles | function serveSassFiles(magnet, outputDir) {
if (!isServingSassFiles) {
magnet.getServer()
.getEngine()
.use('/css', express.static(outputDir));
}
isServingSassFiles = true;
} | javascript | function serveSassFiles(magnet, outputDir) {
if (!isServingSassFiles) {
magnet.getServer()
.getEngine()
.use('/css', express.static(outputDir));
}
isServingSassFiles = true;
} | [
"function",
"serveSassFiles",
"(",
"magnet",
",",
"outputDir",
")",
"{",
"if",
"(",
"!",
"isServingSassFiles",
")",
"{",
"magnet",
".",
"getServer",
"(",
")",
".",
"getEngine",
"(",
")",
".",
"use",
"(",
"'/css'",
",",
"express",
".",
"static",
"(",
"outputDir",
")",
")",
";",
"}",
"isServingSassFiles",
"=",
"true",
";",
"}"
] | Serves built sass files using magnet server instance
@param {!Magnet} magnet
@param {!string} outputDir | [
"Serves",
"built",
"sass",
"files",
"using",
"magnet",
"server",
"instance"
] | 60323a1e590534954d813a13a08046eb3c12265f | https://github.com/mthadley/magnet-plugin-sass/blob/60323a1e590534954d813a13a08046eb3c12265f/src/index.js#L22-L29 |
57,245 | mthadley/magnet-plugin-sass | src/index.js | getOutputFile | function getOutputFile(file, outputDir) {
const fileName = path.basename(file).replace('.scss', '.css');
return path.join(outputDir, fileName);
} | javascript | function getOutputFile(file, outputDir) {
const fileName = path.basename(file).replace('.scss', '.css');
return path.join(outputDir, fileName);
} | [
"function",
"getOutputFile",
"(",
"file",
",",
"outputDir",
")",
"{",
"const",
"fileName",
"=",
"path",
".",
"basename",
"(",
"file",
")",
".",
"replace",
"(",
"'.scss'",
",",
"'.css'",
")",
";",
"return",
"path",
".",
"join",
"(",
"outputDir",
",",
"fileName",
")",
";",
"}"
] | Gets the output file path for a file and a given
output directory.
@param {!string} file
@param {!string} outputDir
@return {!string} | [
"Gets",
"the",
"output",
"file",
"path",
"for",
"a",
"file",
"and",
"a",
"given",
"output",
"directory",
"."
] | 60323a1e590534954d813a13a08046eb3c12265f | https://github.com/mthadley/magnet-plugin-sass/blob/60323a1e590534954d813a13a08046eb3c12265f/src/index.js#L38-L41 |
57,246 | mthadley/magnet-plugin-sass | src/index.js | writeFile | function writeFile(file, css) {
return new Promise((resolve, reject) => {
fs.writeFile(file, css, err => {
if (err) {
return reject(err);
}
resolve();
})
});
} | javascript | function writeFile(file, css) {
return new Promise((resolve, reject) => {
fs.writeFile(file, css, err => {
if (err) {
return reject(err);
}
resolve();
})
});
} | [
"function",
"writeFile",
"(",
"file",
",",
"css",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"fs",
".",
"writeFile",
"(",
"file",
",",
"css",
",",
"err",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"reject",
"(",
"err",
")",
";",
"}",
"resolve",
"(",
")",
";",
"}",
")",
"}",
")",
";",
"}"
] | Writes css to file
@param {!string} file
@param {!string} css
@return {!Promise} | [
"Writes",
"css",
"to",
"file"
] | 60323a1e590534954d813a13a08046eb3c12265f | https://github.com/mthadley/magnet-plugin-sass/blob/60323a1e590534954d813a13a08046eb3c12265f/src/index.js#L49-L58 |
57,247 | mthadley/magnet-plugin-sass | src/index.js | renderFile | function renderFile(file, config) {
const options = Object.assign({file}, config);
return new Promise((resolve, reject) => {
sass.render(options, (err, result) => {
if (err) {
return reject(err);
}
resolve(result.css);
});
});
} | javascript | function renderFile(file, config) {
const options = Object.assign({file}, config);
return new Promise((resolve, reject) => {
sass.render(options, (err, result) => {
if (err) {
return reject(err);
}
resolve(result.css);
});
});
} | [
"function",
"renderFile",
"(",
"file",
",",
"config",
")",
"{",
"const",
"options",
"=",
"Object",
".",
"assign",
"(",
"{",
"file",
"}",
",",
"config",
")",
";",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"sass",
".",
"render",
"(",
"options",
",",
"(",
"err",
",",
"result",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"reject",
"(",
"err",
")",
";",
"}",
"resolve",
"(",
"result",
".",
"css",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Renders a single sass file
@param {!string} file
@param {!object} config
@return {!Promise.<string>} The resulting css | [
"Renders",
"a",
"single",
"sass",
"file"
] | 60323a1e590534954d813a13a08046eb3c12265f | https://github.com/mthadley/magnet-plugin-sass/blob/60323a1e590534954d813a13a08046eb3c12265f/src/index.js#L66-L77 |
57,248 | mthadley/magnet-plugin-sass | src/index.js | buildSassFiles | async function buildSassFiles(files, outputDir, config) {
const renderedFiles = await Promise.all(files.map(async file => {
const css = await renderFile(file, config);
return {file, css};
}));
await fs.ensureDir(outputDir);
return Promise.all(renderedFiles.map(({file, css}) => {
const outputFile = getOutputFile(file, outputDir);
return writeFile(outputFile, css);
}));
} | javascript | async function buildSassFiles(files, outputDir, config) {
const renderedFiles = await Promise.all(files.map(async file => {
const css = await renderFile(file, config);
return {file, css};
}));
await fs.ensureDir(outputDir);
return Promise.all(renderedFiles.map(({file, css}) => {
const outputFile = getOutputFile(file, outputDir);
return writeFile(outputFile, css);
}));
} | [
"async",
"function",
"buildSassFiles",
"(",
"files",
",",
"outputDir",
",",
"config",
")",
"{",
"const",
"renderedFiles",
"=",
"await",
"Promise",
".",
"all",
"(",
"files",
".",
"map",
"(",
"async",
"file",
"=>",
"{",
"const",
"css",
"=",
"await",
"renderFile",
"(",
"file",
",",
"config",
")",
";",
"return",
"{",
"file",
",",
"css",
"}",
";",
"}",
")",
")",
";",
"await",
"fs",
".",
"ensureDir",
"(",
"outputDir",
")",
";",
"return",
"Promise",
".",
"all",
"(",
"renderedFiles",
".",
"map",
"(",
"(",
"{",
"file",
",",
"css",
"}",
")",
"=>",
"{",
"const",
"outputFile",
"=",
"getOutputFile",
"(",
"file",
",",
"outputDir",
")",
";",
"return",
"writeFile",
"(",
"outputFile",
",",
"css",
")",
";",
"}",
")",
")",
";",
"}"
] | Builds sass files to output dir
@param {!Array.<string>} files
@param {!string} outputDir
@param {!Object} config
@return {!Promise} | [
"Builds",
"sass",
"files",
"to",
"output",
"dir"
] | 60323a1e590534954d813a13a08046eb3c12265f | https://github.com/mthadley/magnet-plugin-sass/blob/60323a1e590534954d813a13a08046eb3c12265f/src/index.js#L86-L98 |
57,249 | Julien-Cousineau/util | src/index.js | range | function range(n,type) {
n = (typeof n !== 'undefined') ? n : 0;
if (!(Number.isInteger(n))) throw Error("Error in range: Value must be an integer");
let array;
if(type=='Uint8') array = new Uint8Array(n);
if(type=='Uint16') array = new Uint16Array(n);
if(type=='Uint32') array = new Uint32Array(n);
if(type=='Int8') array = new Int8Array(n);
if(type=='Int16') array = new Int16Array(n);
if(type=='Int32') array = new Int32Array(n);
if(type=='Float32') array = new Float32Array(n);
if((typeof type === 'undefined') || !array)array = new Array(n);
for(let i=0;i<n;i++)array[i]=i;
return array;
} | javascript | function range(n,type) {
n = (typeof n !== 'undefined') ? n : 0;
if (!(Number.isInteger(n))) throw Error("Error in range: Value must be an integer");
let array;
if(type=='Uint8') array = new Uint8Array(n);
if(type=='Uint16') array = new Uint16Array(n);
if(type=='Uint32') array = new Uint32Array(n);
if(type=='Int8') array = new Int8Array(n);
if(type=='Int16') array = new Int16Array(n);
if(type=='Int32') array = new Int32Array(n);
if(type=='Float32') array = new Float32Array(n);
if((typeof type === 'undefined') || !array)array = new Array(n);
for(let i=0;i<n;i++)array[i]=i;
return array;
} | [
"function",
"range",
"(",
"n",
",",
"type",
")",
"{",
"n",
"=",
"(",
"typeof",
"n",
"!==",
"'undefined'",
")",
"?",
"n",
":",
"0",
";",
"if",
"(",
"!",
"(",
"Number",
".",
"isInteger",
"(",
"n",
")",
")",
")",
"throw",
"Error",
"(",
"\"Error in range: Value must be an integer\"",
")",
";",
"let",
"array",
";",
"if",
"(",
"type",
"==",
"'Uint8'",
")",
"array",
"=",
"new",
"Uint8Array",
"(",
"n",
")",
";",
"if",
"(",
"type",
"==",
"'Uint16'",
")",
"array",
"=",
"new",
"Uint16Array",
"(",
"n",
")",
";",
"if",
"(",
"type",
"==",
"'Uint32'",
")",
"array",
"=",
"new",
"Uint32Array",
"(",
"n",
")",
";",
"if",
"(",
"type",
"==",
"'Int8'",
")",
"array",
"=",
"new",
"Int8Array",
"(",
"n",
")",
";",
"if",
"(",
"type",
"==",
"'Int16'",
")",
"array",
"=",
"new",
"Int16Array",
"(",
"n",
")",
";",
"if",
"(",
"type",
"==",
"'Int32'",
")",
"array",
"=",
"new",
"Int32Array",
"(",
"n",
")",
";",
"if",
"(",
"type",
"==",
"'Float32'",
")",
"array",
"=",
"new",
"Float32Array",
"(",
"n",
")",
";",
"if",
"(",
"(",
"typeof",
"type",
"===",
"'undefined'",
")",
"||",
"!",
"array",
")",
"array",
"=",
"new",
"Array",
"(",
"n",
")",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"array",
"[",
"i",
"]",
"=",
"i",
";",
"return",
"array",
";",
"}"
] | module.exports.quickSort = quickSort; module.exports.quickSortIndices = quickSortIndices; | [
"module",
".",
"exports",
".",
"quickSort",
"=",
"quickSort",
";",
"module",
".",
"exports",
".",
"quickSortIndices",
"=",
"quickSortIndices",
";"
] | b52b841288a1d5eb5fd185a42664a75fba42e2da | https://github.com/Julien-Cousineau/util/blob/b52b841288a1d5eb5fd185a42664a75fba42e2da/src/index.js#L291-L307 |
57,250 | Psychopoulet/simplessl | lib/wrapperStdToString.js | _execution | function _execution (spawn, data, options) {
const match = data.match(WATING_STDIN);
if (match) {
if (-1 < match[1].indexOf("Country Name")) {
if (!options.country) {
options.country = match[2] ? match[2] : ".";
}
spawn.stdin.write(options.country + "\n");
}
else if (-1 < match[1].indexOf("Locality Name")) {
if (!options.locality) {
options.locality = match[2] ? match[2] : ".";
}
spawn.stdin.write(options.locality + "\n");
}
else if (-1 < match[1].indexOf("State or Province Name")) {
if (!options.state) {
options.state = match[2] ? match[2] : ".";
}
spawn.stdin.write(options.state + "\n");
}
else if (-1 < match[1].indexOf("Organization Name")) {
if (!options.organization) {
options.organization = match[2] ? match[2] : ".";
}
spawn.stdin.write(options.organization + "\n");
}
else if (-1 < match[1].indexOf("Common Name")) {
if (!options.common) {
options.common = match[2] ? match[2] : ".";
}
spawn.stdin.write(options.common + "\n");
}
else if (-1 < match[1].indexOf("Email Address")) {
if (!options.email) {
options.email = match[2] ? match[2] : ".";
}
spawn.stdin.write(options.email + "\n");
}
else {
spawn.stdin.write(".\n");
}
return "";
}
else {
return data;
}
} | javascript | function _execution (spawn, data, options) {
const match = data.match(WATING_STDIN);
if (match) {
if (-1 < match[1].indexOf("Country Name")) {
if (!options.country) {
options.country = match[2] ? match[2] : ".";
}
spawn.stdin.write(options.country + "\n");
}
else if (-1 < match[1].indexOf("Locality Name")) {
if (!options.locality) {
options.locality = match[2] ? match[2] : ".";
}
spawn.stdin.write(options.locality + "\n");
}
else if (-1 < match[1].indexOf("State or Province Name")) {
if (!options.state) {
options.state = match[2] ? match[2] : ".";
}
spawn.stdin.write(options.state + "\n");
}
else if (-1 < match[1].indexOf("Organization Name")) {
if (!options.organization) {
options.organization = match[2] ? match[2] : ".";
}
spawn.stdin.write(options.organization + "\n");
}
else if (-1 < match[1].indexOf("Common Name")) {
if (!options.common) {
options.common = match[2] ? match[2] : ".";
}
spawn.stdin.write(options.common + "\n");
}
else if (-1 < match[1].indexOf("Email Address")) {
if (!options.email) {
options.email = match[2] ? match[2] : ".";
}
spawn.stdin.write(options.email + "\n");
}
else {
spawn.stdin.write(".\n");
}
return "";
}
else {
return data;
}
} | [
"function",
"_execution",
"(",
"spawn",
",",
"data",
",",
"options",
")",
"{",
"const",
"match",
"=",
"data",
".",
"match",
"(",
"WATING_STDIN",
")",
";",
"if",
"(",
"match",
")",
"{",
"if",
"(",
"-",
"1",
"<",
"match",
"[",
"1",
"]",
".",
"indexOf",
"(",
"\"Country Name\"",
")",
")",
"{",
"if",
"(",
"!",
"options",
".",
"country",
")",
"{",
"options",
".",
"country",
"=",
"match",
"[",
"2",
"]",
"?",
"match",
"[",
"2",
"]",
":",
"\".\"",
";",
"}",
"spawn",
".",
"stdin",
".",
"write",
"(",
"options",
".",
"country",
"+",
"\"\\n\"",
")",
";",
"}",
"else",
"if",
"(",
"-",
"1",
"<",
"match",
"[",
"1",
"]",
".",
"indexOf",
"(",
"\"Locality Name\"",
")",
")",
"{",
"if",
"(",
"!",
"options",
".",
"locality",
")",
"{",
"options",
".",
"locality",
"=",
"match",
"[",
"2",
"]",
"?",
"match",
"[",
"2",
"]",
":",
"\".\"",
";",
"}",
"spawn",
".",
"stdin",
".",
"write",
"(",
"options",
".",
"locality",
"+",
"\"\\n\"",
")",
";",
"}",
"else",
"if",
"(",
"-",
"1",
"<",
"match",
"[",
"1",
"]",
".",
"indexOf",
"(",
"\"State or Province Name\"",
")",
")",
"{",
"if",
"(",
"!",
"options",
".",
"state",
")",
"{",
"options",
".",
"state",
"=",
"match",
"[",
"2",
"]",
"?",
"match",
"[",
"2",
"]",
":",
"\".\"",
";",
"}",
"spawn",
".",
"stdin",
".",
"write",
"(",
"options",
".",
"state",
"+",
"\"\\n\"",
")",
";",
"}",
"else",
"if",
"(",
"-",
"1",
"<",
"match",
"[",
"1",
"]",
".",
"indexOf",
"(",
"\"Organization Name\"",
")",
")",
"{",
"if",
"(",
"!",
"options",
".",
"organization",
")",
"{",
"options",
".",
"organization",
"=",
"match",
"[",
"2",
"]",
"?",
"match",
"[",
"2",
"]",
":",
"\".\"",
";",
"}",
"spawn",
".",
"stdin",
".",
"write",
"(",
"options",
".",
"organization",
"+",
"\"\\n\"",
")",
";",
"}",
"else",
"if",
"(",
"-",
"1",
"<",
"match",
"[",
"1",
"]",
".",
"indexOf",
"(",
"\"Common Name\"",
")",
")",
"{",
"if",
"(",
"!",
"options",
".",
"common",
")",
"{",
"options",
".",
"common",
"=",
"match",
"[",
"2",
"]",
"?",
"match",
"[",
"2",
"]",
":",
"\".\"",
";",
"}",
"spawn",
".",
"stdin",
".",
"write",
"(",
"options",
".",
"common",
"+",
"\"\\n\"",
")",
";",
"}",
"else",
"if",
"(",
"-",
"1",
"<",
"match",
"[",
"1",
"]",
".",
"indexOf",
"(",
"\"Email Address\"",
")",
")",
"{",
"if",
"(",
"!",
"options",
".",
"email",
")",
"{",
"options",
".",
"email",
"=",
"match",
"[",
"2",
"]",
"?",
"match",
"[",
"2",
"]",
":",
"\".\"",
";",
"}",
"spawn",
".",
"stdin",
".",
"write",
"(",
"options",
".",
"email",
"+",
"\"\\n\"",
")",
";",
"}",
"else",
"{",
"spawn",
".",
"stdin",
".",
"write",
"(",
"\".\\n\"",
")",
";",
"}",
"return",
"\"\"",
";",
"}",
"else",
"{",
"return",
"data",
";",
"}",
"}"
] | methods
Execute method
@param {child_process} spawn : std process
@param {string} data : data to check
@param {object} options : options for execution
@returns {any} Cloned data | [
"methods",
"Execute",
"method"
] | 22872f3429510a45260ba73158dfdcc44df80700 | https://github.com/Psychopoulet/simplessl/blob/22872f3429510a45260ba73158dfdcc44df80700/lib/wrapperStdToString.js#L27-L98 |
57,251 | panarch/famous-mig | surfaces/CanvasSurface.js | CanvasSurface | function CanvasSurface(options) {
if (options)
options.useTarget = true;
else
options = { useTarget: true };
if (options.canvasSize) this._canvasSize = options.canvasSize;
Surface.apply(this, arguments);
if (!this._canvasSize) this._canvasSize = this.getSize();
this._backBuffer = document.createElement('canvas');
if (this._canvasSize) {
this._backBuffer.width = this._canvasSize[0];
this._backBuffer.height = this._canvasSize[1];
}
this._contextId = undefined;
} | javascript | function CanvasSurface(options) {
if (options)
options.useTarget = true;
else
options = { useTarget: true };
if (options.canvasSize) this._canvasSize = options.canvasSize;
Surface.apply(this, arguments);
if (!this._canvasSize) this._canvasSize = this.getSize();
this._backBuffer = document.createElement('canvas');
if (this._canvasSize) {
this._backBuffer.width = this._canvasSize[0];
this._backBuffer.height = this._canvasSize[1];
}
this._contextId = undefined;
} | [
"function",
"CanvasSurface",
"(",
"options",
")",
"{",
"if",
"(",
"options",
")",
"options",
".",
"useTarget",
"=",
"true",
";",
"else",
"options",
"=",
"{",
"useTarget",
":",
"true",
"}",
";",
"if",
"(",
"options",
".",
"canvasSize",
")",
"this",
".",
"_canvasSize",
"=",
"options",
".",
"canvasSize",
";",
"Surface",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"if",
"(",
"!",
"this",
".",
"_canvasSize",
")",
"this",
".",
"_canvasSize",
"=",
"this",
".",
"getSize",
"(",
")",
";",
"this",
".",
"_backBuffer",
"=",
"document",
".",
"createElement",
"(",
"'canvas'",
")",
";",
"if",
"(",
"this",
".",
"_canvasSize",
")",
"{",
"this",
".",
"_backBuffer",
".",
"width",
"=",
"this",
".",
"_canvasSize",
"[",
"0",
"]",
";",
"this",
".",
"_backBuffer",
".",
"height",
"=",
"this",
".",
"_canvasSize",
"[",
"1",
"]",
";",
"}",
"this",
".",
"_contextId",
"=",
"undefined",
";",
"}"
] | A surface containing an HTML5 Canvas element.
This extends the Surface class.
@class CanvasSurface
@extends Surface
@constructor
@param {Object} [options] overrides of default options
@param {Array.Number} [options.canvasSize] [width, height] for document element | [
"A",
"surface",
"containing",
"an",
"HTML5",
"Canvas",
"element",
".",
"This",
"extends",
"the",
"Surface",
"class",
"."
] | a241d9955d20ceb0fe3ce0a1fb13e9961e1c6878 | https://github.com/panarch/famous-mig/blob/a241d9955d20ceb0fe3ce0a1fb13e9961e1c6878/surfaces/CanvasSurface.js#L17-L32 |
57,252 | melvincarvalho/rdf-shell | lib/cat.js | cat | function cat(uri, callback) {
if (!uri) {
callback(new Error('URI is required'))
}
util.get(uri, function(err, val, uri) {
callback(null, val, uri)
})
} | javascript | function cat(uri, callback) {
if (!uri) {
callback(new Error('URI is required'))
}
util.get(uri, function(err, val, uri) {
callback(null, val, uri)
})
} | [
"function",
"cat",
"(",
"uri",
",",
"callback",
")",
"{",
"if",
"(",
"!",
"uri",
")",
"{",
"callback",
"(",
"new",
"Error",
"(",
"'URI is required'",
")",
")",
"}",
"util",
".",
"get",
"(",
"uri",
",",
"function",
"(",
"err",
",",
"val",
",",
"uri",
")",
"{",
"callback",
"(",
"null",
",",
"val",
",",
"uri",
")",
"}",
")",
"}"
] | cat gets the turtle for a uri
@param {string} uri The URI to get
@param {Function} callback Callback with text and uri | [
"cat",
"gets",
"the",
"turtle",
"for",
"a",
"uri"
] | bf2015f6f333855e69a18ce3ec9e917bbddfb425 | https://github.com/melvincarvalho/rdf-shell/blob/bf2015f6f333855e69a18ce3ec9e917bbddfb425/lib/cat.js#L10-L17 |
57,253 | nightshiftjs/nightshift-core | src/utils/functions.js | getParamNames | function getParamNames(fn) {
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
var fnString = fn.toString().replace(STRIP_COMMENTS, '');
var result = fnString.slice(fnString.indexOf('(') + 1, fnString.indexOf(')')).match(/([^\s,]+)/g);
return result || [];
} | javascript | function getParamNames(fn) {
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
var fnString = fn.toString().replace(STRIP_COMMENTS, '');
var result = fnString.slice(fnString.indexOf('(') + 1, fnString.indexOf(')')).match(/([^\s,]+)/g);
return result || [];
} | [
"function",
"getParamNames",
"(",
"fn",
")",
"{",
"var",
"STRIP_COMMENTS",
"=",
"/",
"((\\/\\/.*$)|(\\/\\*[\\s\\S]*?\\*\\/))",
"/",
"mg",
";",
"var",
"fnString",
"=",
"fn",
".",
"toString",
"(",
")",
".",
"replace",
"(",
"STRIP_COMMENTS",
",",
"''",
")",
";",
"var",
"result",
"=",
"fnString",
".",
"slice",
"(",
"fnString",
".",
"indexOf",
"(",
"'('",
")",
"+",
"1",
",",
"fnString",
".",
"indexOf",
"(",
"')'",
")",
")",
".",
"match",
"(",
"/",
"([^\\s,]+)",
"/",
"g",
")",
";",
"return",
"result",
"||",
"[",
"]",
";",
"}"
] | This method returns an array listing the names of the parameters of the given function. The array is empty if the
function does not expect any parameter.
@param {function} fn the function to retrieve the parameters names for
@returns {Array|{index: number, input: string}} an array listing the names of the parameters of the given
function, or an empty array if the function does not expect any parameter | [
"This",
"method",
"returns",
"an",
"array",
"listing",
"the",
"names",
"of",
"the",
"parameters",
"of",
"the",
"given",
"function",
".",
"The",
"array",
"is",
"empty",
"if",
"the",
"function",
"does",
"not",
"expect",
"any",
"parameter",
"."
] | e1dc28b4d551c71dfb09d5b1e939a44d922a89d7 | https://github.com/nightshiftjs/nightshift-core/blob/e1dc28b4d551c71dfb09d5b1e939a44d922a89d7/src/utils/functions.js#L33-L38 |
57,254 | aashay/node-bart | lib/bart.js | merge_objects | function merge_objects(obj1,obj2){
var obj3 = {};
for (var attrname1 in obj1) { obj3[attrname1] = obj1[attrname1]; }
for (var attrname2 in obj2) { obj3[attrname2] = obj2[attrname2]; }
return obj3;
} | javascript | function merge_objects(obj1,obj2){
var obj3 = {};
for (var attrname1 in obj1) { obj3[attrname1] = obj1[attrname1]; }
for (var attrname2 in obj2) { obj3[attrname2] = obj2[attrname2]; }
return obj3;
} | [
"function",
"merge_objects",
"(",
"obj1",
",",
"obj2",
")",
"{",
"var",
"obj3",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"attrname1",
"in",
"obj1",
")",
"{",
"obj3",
"[",
"attrname1",
"]",
"=",
"obj1",
"[",
"attrname1",
"]",
";",
"}",
"for",
"(",
"var",
"attrname2",
"in",
"obj2",
")",
"{",
"obj3",
"[",
"attrname2",
"]",
"=",
"obj2",
"[",
"attrname2",
"]",
";",
"}",
"return",
"obj3",
";",
"}"
] | Convenience function to smash two objects together.
@param obj1
@param obj2
@returns obj3, a merged object | [
"Convenience",
"function",
"to",
"smash",
"two",
"objects",
"together",
"."
] | a9fea7e7adb59d44628c05b54547c347c1accd6e | https://github.com/aashay/node-bart/blob/a9fea7e7adb59d44628c05b54547c347c1accd6e/lib/bart.js#L20-L25 |
57,255 | assemble/assemble-fs | index.js | toFiles | function toFiles(app, options) {
let opts = Object.assign({ collection: null }, options);
let name = opts.collection;
let collection = app.collections ? name && app[name] : app;
let view;
if (!collection && name) {
collection = app.create(name, opts);
}
return utils.through.obj(async (file, enc, next) => {
if (!app.File.isFile(file)) {
file = app.file(file.path, file);
}
if (file.isNull()) {
next(null, file);
return;
}
if (collection && isCollection(collection)) {
try {
view = await collection.set(file.path, file);
} catch (err) {
next(err);
return;
}
next(null, view);
return;
}
view = !app.File.isFile(file) ? app.file(file.path, file) : file;
app.handle('onLoad', view)
.then(() => next(null, view))
.catch(next);
});
} | javascript | function toFiles(app, options) {
let opts = Object.assign({ collection: null }, options);
let name = opts.collection;
let collection = app.collections ? name && app[name] : app;
let view;
if (!collection && name) {
collection = app.create(name, opts);
}
return utils.through.obj(async (file, enc, next) => {
if (!app.File.isFile(file)) {
file = app.file(file.path, file);
}
if (file.isNull()) {
next(null, file);
return;
}
if (collection && isCollection(collection)) {
try {
view = await collection.set(file.path, file);
} catch (err) {
next(err);
return;
}
next(null, view);
return;
}
view = !app.File.isFile(file) ? app.file(file.path, file) : file;
app.handle('onLoad', view)
.then(() => next(null, view))
.catch(next);
});
} | [
"function",
"toFiles",
"(",
"app",
",",
"options",
")",
"{",
"let",
"opts",
"=",
"Object",
".",
"assign",
"(",
"{",
"collection",
":",
"null",
"}",
",",
"options",
")",
";",
"let",
"name",
"=",
"opts",
".",
"collection",
";",
"let",
"collection",
"=",
"app",
".",
"collections",
"?",
"name",
"&&",
"app",
"[",
"name",
"]",
":",
"app",
";",
"let",
"view",
";",
"if",
"(",
"!",
"collection",
"&&",
"name",
")",
"{",
"collection",
"=",
"app",
".",
"create",
"(",
"name",
",",
"opts",
")",
";",
"}",
"return",
"utils",
".",
"through",
".",
"obj",
"(",
"async",
"(",
"file",
",",
"enc",
",",
"next",
")",
"=>",
"{",
"if",
"(",
"!",
"app",
".",
"File",
".",
"isFile",
"(",
"file",
")",
")",
"{",
"file",
"=",
"app",
".",
"file",
"(",
"file",
".",
"path",
",",
"file",
")",
";",
"}",
"if",
"(",
"file",
".",
"isNull",
"(",
")",
")",
"{",
"next",
"(",
"null",
",",
"file",
")",
";",
"return",
";",
"}",
"if",
"(",
"collection",
"&&",
"isCollection",
"(",
"collection",
")",
")",
"{",
"try",
"{",
"view",
"=",
"await",
"collection",
".",
"set",
"(",
"file",
".",
"path",
",",
"file",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"next",
"(",
"err",
")",
";",
"return",
";",
"}",
"next",
"(",
"null",
",",
"view",
")",
";",
"return",
";",
"}",
"view",
"=",
"!",
"app",
".",
"File",
".",
"isFile",
"(",
"file",
")",
"?",
"app",
".",
"file",
"(",
"file",
".",
"path",
",",
"file",
")",
":",
"file",
";",
"app",
".",
"handle",
"(",
"'onLoad'",
",",
"view",
")",
".",
"then",
"(",
"(",
")",
"=>",
"next",
"(",
"null",
",",
"view",
")",
")",
".",
"catch",
"(",
"next",
")",
";",
"}",
")",
";",
"}"
] | Make sure vinyl files are assemble files, and add
them to a collection, if specified. | [
"Make",
"sure",
"vinyl",
"files",
"are",
"assemble",
"files",
"and",
"add",
"them",
"to",
"a",
"collection",
"if",
"specified",
"."
] | 708e393935d52bf75659905ca1d658f92c362d7c | https://github.com/assemble/assemble-fs/blob/708e393935d52bf75659905ca1d658f92c362d7c/index.js#L129-L166 |
57,256 | EpiphanySoft/assertly | inspect.js | inspect | function inspect(obj, opts) {
// default options
var ctx = {
seen: [],
stylize: stylizeNoColor
};
// legacy...
if (arguments[2] !== undefined) ctx.depth = arguments[2];
if (arguments[3] !== undefined) ctx.colors = arguments[3];
if (typeof opts === 'boolean') {
// legacy...
ctx.showHidden = opts;
}
// Set default and user-specified options
ctx = Object.assign({}, inspect.defaultOptions, ctx, opts);
if (ctx.colors) ctx.stylize = stylizeWithColor;
if (ctx.maxArrayLength === null) ctx.maxArrayLength = Infinity;
return formatValue(ctx, obj, ctx.depth);
} | javascript | function inspect(obj, opts) {
// default options
var ctx = {
seen: [],
stylize: stylizeNoColor
};
// legacy...
if (arguments[2] !== undefined) ctx.depth = arguments[2];
if (arguments[3] !== undefined) ctx.colors = arguments[3];
if (typeof opts === 'boolean') {
// legacy...
ctx.showHidden = opts;
}
// Set default and user-specified options
ctx = Object.assign({}, inspect.defaultOptions, ctx, opts);
if (ctx.colors) ctx.stylize = stylizeWithColor;
if (ctx.maxArrayLength === null) ctx.maxArrayLength = Infinity;
return formatValue(ctx, obj, ctx.depth);
} | [
"function",
"inspect",
"(",
"obj",
",",
"opts",
")",
"{",
"// default options",
"var",
"ctx",
"=",
"{",
"seen",
":",
"[",
"]",
",",
"stylize",
":",
"stylizeNoColor",
"}",
";",
"// legacy...",
"if",
"(",
"arguments",
"[",
"2",
"]",
"!==",
"undefined",
")",
"ctx",
".",
"depth",
"=",
"arguments",
"[",
"2",
"]",
";",
"if",
"(",
"arguments",
"[",
"3",
"]",
"!==",
"undefined",
")",
"ctx",
".",
"colors",
"=",
"arguments",
"[",
"3",
"]",
";",
"if",
"(",
"typeof",
"opts",
"===",
"'boolean'",
")",
"{",
"// legacy...",
"ctx",
".",
"showHidden",
"=",
"opts",
";",
"}",
"// Set default and user-specified options",
"ctx",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"inspect",
".",
"defaultOptions",
",",
"ctx",
",",
"opts",
")",
";",
"if",
"(",
"ctx",
".",
"colors",
")",
"ctx",
".",
"stylize",
"=",
"stylizeWithColor",
";",
"if",
"(",
"ctx",
".",
"maxArrayLength",
"===",
"null",
")",
"ctx",
".",
"maxArrayLength",
"=",
"Infinity",
";",
"return",
"formatValue",
"(",
"ctx",
",",
"obj",
",",
"ctx",
".",
"depth",
")",
";",
"}"
] | Echos the value of a value. Tries to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Object} opts Optional options object that alters the output.
/* legacy: obj, showHidden, depth, colors | [
"Echos",
"the",
"value",
"of",
"a",
"value",
".",
"Tries",
"to",
"print",
"the",
"value",
"out",
"in",
"the",
"best",
"way",
"possible",
"given",
"the",
"different",
"types",
"."
] | 04a62335eb0ebba5308a9b5d2059ee38bcaf1444 | https://github.com/EpiphanySoft/assertly/blob/04a62335eb0ebba5308a9b5d2059ee38bcaf1444/inspect.js#L176-L194 |
57,257 | jtheriault/code-copter-analyzer-jscs | src/index.js | getJscsrc | function getJscsrc () {
var jscsrcPath = process.cwd() + '/.jscsrc';
try {
return JSON.parse(fs.readFileSync(jscsrcPath, 'utf8'));
}
catch (error) {
throw new Error(`Expected to find JSCS configuration ${jscsrcPath}; saw error "${error.message}". Cannot run JSCS analysis.`, error);
}
} | javascript | function getJscsrc () {
var jscsrcPath = process.cwd() + '/.jscsrc';
try {
return JSON.parse(fs.readFileSync(jscsrcPath, 'utf8'));
}
catch (error) {
throw new Error(`Expected to find JSCS configuration ${jscsrcPath}; saw error "${error.message}". Cannot run JSCS analysis.`, error);
}
} | [
"function",
"getJscsrc",
"(",
")",
"{",
"var",
"jscsrcPath",
"=",
"process",
".",
"cwd",
"(",
")",
"+",
"'/.jscsrc'",
";",
"try",
"{",
"return",
"JSON",
".",
"parse",
"(",
"fs",
".",
"readFileSync",
"(",
"jscsrcPath",
",",
"'utf8'",
")",
")",
";",
"}",
"catch",
"(",
"error",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"jscsrcPath",
"}",
"${",
"error",
".",
"message",
"}",
"`",
",",
"error",
")",
";",
"}",
"}"
] | Get the object representation of the configuration in .jscsrc in the project
root. | [
"Get",
"the",
"object",
"representation",
"of",
"the",
"configuration",
"in",
".",
"jscsrc",
"in",
"the",
"project",
"root",
"."
] | 81ee8300c1e6017e7e2f3b4ac880bca6f124d601 | https://github.com/jtheriault/code-copter-analyzer-jscs/blob/81ee8300c1e6017e7e2f3b4ac880bca6f124d601/src/index.js#L50-L59 |
57,258 | allanmboyd/formaterrors | lib/formatErrors.js | filterMatch | function filterMatch(s, regExps) {
if (!regExps) {
return false;
}
var match = false;
for (var i = 0; i < regExps.length && !match; i++) {
match = s.match(regExps[i]) !== null;
}
return match;
} | javascript | function filterMatch(s, regExps) {
if (!regExps) {
return false;
}
var match = false;
for (var i = 0; i < regExps.length && !match; i++) {
match = s.match(regExps[i]) !== null;
}
return match;
} | [
"function",
"filterMatch",
"(",
"s",
",",
"regExps",
")",
"{",
"if",
"(",
"!",
"regExps",
")",
"{",
"return",
"false",
";",
"}",
"var",
"match",
"=",
"false",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"regExps",
".",
"length",
"&&",
"!",
"match",
";",
"i",
"++",
")",
"{",
"match",
"=",
"s",
".",
"match",
"(",
"regExps",
"[",
"i",
"]",
")",
"!==",
"null",
";",
"}",
"return",
"match",
";",
"}"
] | Determine if a provided array of regular expressions includes a match for a provided String.
@method filterMatch
@private
@param {String} s the String
@param {String[]} regExps an array of reg. exp. Strings
@return {Boolean} true if a match is found; false otherwise | [
"Determine",
"if",
"a",
"provided",
"array",
"of",
"regular",
"expressions",
"includes",
"a",
"match",
"for",
"a",
"provided",
"String",
"."
] | 83c6f0c9d6334e706549db848174fc901e6ce5c3 | https://github.com/allanmboyd/formaterrors/blob/83c6f0c9d6334e706549db848174fc901e6ce5c3/lib/formatErrors.js#L323-L333 |
57,259 | allanmboyd/formaterrors | lib/formatErrors.js | isError | function isError(error) {
return error && (Object.prototype.toString.call(error).slice(8, -1) === "Error" ||
(typeof error.stack !== "undefined" && typeof error.name !== "undefined"));
} | javascript | function isError(error) {
return error && (Object.prototype.toString.call(error).slice(8, -1) === "Error" ||
(typeof error.stack !== "undefined" && typeof error.name !== "undefined"));
} | [
"function",
"isError",
"(",
"error",
")",
"{",
"return",
"error",
"&&",
"(",
"Object",
".",
"prototype",
".",
"toString",
".",
"call",
"(",
"error",
")",
".",
"slice",
"(",
"8",
",",
"-",
"1",
")",
"===",
"\"Error\"",
"||",
"(",
"typeof",
"error",
".",
"stack",
"!==",
"\"undefined\"",
"&&",
"typeof",
"error",
".",
"name",
"!==",
"\"undefined\"",
")",
")",
";",
"}"
] | Determine if a given parameter is an Error.
@method isError
@private
@param {Error} error the prospective Error
@return {Boolean} true is 'error' is an Error; false otherwise | [
"Determine",
"if",
"a",
"given",
"parameter",
"is",
"an",
"Error",
"."
] | 83c6f0c9d6334e706549db848174fc901e6ce5c3 | https://github.com/allanmboyd/formaterrors/blob/83c6f0c9d6334e706549db848174fc901e6ce5c3/lib/formatErrors.js#L402-L405 |
57,260 | allanmboyd/formaterrors | lib/formatErrors.js | diffToMessage | function diffToMessage(diffedAssertionError) {
var diff = diffedAssertionError.diff;
var actual = "";
var expected = "";
for (var i = 0; i < diff.length; i++) {
var diffType = diff[i][0];
if (diffType === 1) {
if (actual.length > 0) {
actual += ", ";
}
actual += "\"" + diff[i][1] + "\"";
} else if (diffType === -1) {
if (expected.length > 0) {
expected += ", ";
}
expected += "\"" + diff[i][1] + "\"";
}
}
var message = "Differences: ";
if (expected.length > 0) {
message += "'expected': " + expected;
}
if (actual.length > 0) {
if (expected.length > 0) {
message += ", ";
}
message += "'actual': " + actual;
}
message += "\n";
return getMessages(diffedAssertionError).join(" ") + "\n" + message;
} | javascript | function diffToMessage(diffedAssertionError) {
var diff = diffedAssertionError.diff;
var actual = "";
var expected = "";
for (var i = 0; i < diff.length; i++) {
var diffType = diff[i][0];
if (diffType === 1) {
if (actual.length > 0) {
actual += ", ";
}
actual += "\"" + diff[i][1] + "\"";
} else if (diffType === -1) {
if (expected.length > 0) {
expected += ", ";
}
expected += "\"" + diff[i][1] + "\"";
}
}
var message = "Differences: ";
if (expected.length > 0) {
message += "'expected': " + expected;
}
if (actual.length > 0) {
if (expected.length > 0) {
message += ", ";
}
message += "'actual': " + actual;
}
message += "\n";
return getMessages(diffedAssertionError).join(" ") + "\n" + message;
} | [
"function",
"diffToMessage",
"(",
"diffedAssertionError",
")",
"{",
"var",
"diff",
"=",
"diffedAssertionError",
".",
"diff",
";",
"var",
"actual",
"=",
"\"\"",
";",
"var",
"expected",
"=",
"\"\"",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"diff",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"diffType",
"=",
"diff",
"[",
"i",
"]",
"[",
"0",
"]",
";",
"if",
"(",
"diffType",
"===",
"1",
")",
"{",
"if",
"(",
"actual",
".",
"length",
">",
"0",
")",
"{",
"actual",
"+=",
"\", \"",
";",
"}",
"actual",
"+=",
"\"\\\"\"",
"+",
"diff",
"[",
"i",
"]",
"[",
"1",
"]",
"+",
"\"\\\"\"",
";",
"}",
"else",
"if",
"(",
"diffType",
"===",
"-",
"1",
")",
"{",
"if",
"(",
"expected",
".",
"length",
">",
"0",
")",
"{",
"expected",
"+=",
"\", \"",
";",
"}",
"expected",
"+=",
"\"\\\"\"",
"+",
"diff",
"[",
"i",
"]",
"[",
"1",
"]",
"+",
"\"\\\"\"",
";",
"}",
"}",
"var",
"message",
"=",
"\"Differences: \"",
";",
"if",
"(",
"expected",
".",
"length",
">",
"0",
")",
"{",
"message",
"+=",
"\"'expected': \"",
"+",
"expected",
";",
"}",
"if",
"(",
"actual",
".",
"length",
">",
"0",
")",
"{",
"if",
"(",
"expected",
".",
"length",
">",
"0",
")",
"{",
"message",
"+=",
"\", \"",
";",
"}",
"message",
"+=",
"\"'actual': \"",
"+",
"actual",
";",
"}",
"message",
"+=",
"\"\\n\"",
";",
"return",
"getMessages",
"(",
"diffedAssertionError",
")",
".",
"join",
"(",
"\" \"",
")",
"+",
"\"\\n\"",
"+",
"message",
";",
"}"
] | Given an AssertionError that has had diffs applied - and that means it has a diff property - provide the message
for the AssertionError including details of the diffs.
@method diffToMessage
@private
@param {AssertionError} diffedAssertionError an AssertionError that has a diff property containing diffs between the expected and
actual values
@return {String} the message that includes diff details | [
"Given",
"an",
"AssertionError",
"that",
"has",
"had",
"diffs",
"applied",
"-",
"and",
"that",
"means",
"it",
"has",
"a",
"diff",
"property",
"-",
"provide",
"the",
"message",
"for",
"the",
"AssertionError",
"including",
"details",
"of",
"the",
"diffs",
"."
] | 83c6f0c9d6334e706549db848174fc901e6ce5c3 | https://github.com/allanmboyd/formaterrors/blob/83c6f0c9d6334e706549db848174fc901e6ce5c3/lib/formatErrors.js#L547-L578 |
57,261 | greggman/hft-sample-ui | src/hft/scripts/commonui.js | function() {
if (!fullScreen.isFullScreen()) {
touchStartElement.removeEventListener('touchstart', requestFullScreen, false);
touchStartElement.style.display = "none";
fullScreen.requestFullScreen(document.body);
}
} | javascript | function() {
if (!fullScreen.isFullScreen()) {
touchStartElement.removeEventListener('touchstart', requestFullScreen, false);
touchStartElement.style.display = "none";
fullScreen.requestFullScreen(document.body);
}
} | [
"function",
"(",
")",
"{",
"if",
"(",
"!",
"fullScreen",
".",
"isFullScreen",
"(",
")",
")",
"{",
"touchStartElement",
".",
"removeEventListener",
"(",
"'touchstart'",
",",
"requestFullScreen",
",",
"false",
")",
";",
"touchStartElement",
".",
"style",
".",
"display",
"=",
"\"none\"",
";",
"fullScreen",
".",
"requestFullScreen",
"(",
"document",
".",
"body",
")",
";",
"}",
"}"
] | setup full screen support | [
"setup",
"full",
"screen",
"support"
] | b9e20afd5183db73522bcfae48225c87e01f68c0 | https://github.com/greggman/hft-sample-ui/blob/b9e20afd5183db73522bcfae48225c87e01f68c0/src/hft/scripts/commonui.js#L220-L226 |
|
57,262 | huafu/ember-dev-fixtures | private/utils/dev-fixtures/adapter.js | function (name) {
if (!this.instances[name]) {
this.instances[name] = DevFixturesAdapter.create({name: name});
}
return this.instances[name];
} | javascript | function (name) {
if (!this.instances[name]) {
this.instances[name] = DevFixturesAdapter.create({name: name});
}
return this.instances[name];
} | [
"function",
"(",
"name",
")",
"{",
"if",
"(",
"!",
"this",
".",
"instances",
"[",
"name",
"]",
")",
"{",
"this",
".",
"instances",
"[",
"name",
"]",
"=",
"DevFixturesAdapter",
".",
"create",
"(",
"{",
"name",
":",
"name",
"}",
")",
";",
"}",
"return",
"this",
".",
"instances",
"[",
"name",
"]",
";",
"}"
] | Get or create the singleton instance for given adapter name
@method for
@param {string} name
@return {DevFixturesAdapter} | [
"Get",
"or",
"create",
"the",
"singleton",
"instance",
"for",
"given",
"adapter",
"name"
] | 811ed4d339c2dc840d5b297b5b244726cf1339ca | https://github.com/huafu/ember-dev-fixtures/blob/811ed4d339c2dc840d5b297b5b244726cf1339ca/private/utils/dev-fixtures/adapter.js#L131-L136 |
|
57,263 | altshift/altshift | lib/altshift/core/base.js | format | function format(string, args) {
if (
string.length === 0 ||
!args ||
Object.keys(args).length === 0
) {
return string;
}
var matchVar = '[0-9a-zA-Z_$\\.]+',
matchBrackets = '\\[[^\\]]*\\]',
matchParsing = new RegExp(
//"^" +
"((" + matchVar + "|" + matchBrackets + ")*)" + //Match arg path
"(!([rsa]))?" + //Conversion
"(:([^\\?\\!]+))?" //spec
//"$"
),
matchCount = 0;
return string.replace(FORMAT_EXPRESSION, function (_, match) {
var parts = match.match(matchParsing),
argName = parts[1] || matchCount,
conversion = parts[4] || 's', //Default is string conversion
formatSpec = parts[6],
value = formatArgGet(args, argName);
matchCount += 1;
if (value === undefined) {
return FORMAT_EXPRESSION_START + match + FORMAT_EXPRESSION_STOP;//Replace unchanged
}
if (formatSpec && formatSpec.length > 0) {
value = formatValueSpec(value, formatSpec);
}
//Conversion s, r or a
switch (conversion) {
case 's':
return '' + value;
case 'r':
return inspect(value);
case 'a':
throw new Error('Not yet implemented conversion "' + conversion + '"');
default:
throw new Error('Invalid conversion "' + conversion + '"');
}
});
} | javascript | function format(string, args) {
if (
string.length === 0 ||
!args ||
Object.keys(args).length === 0
) {
return string;
}
var matchVar = '[0-9a-zA-Z_$\\.]+',
matchBrackets = '\\[[^\\]]*\\]',
matchParsing = new RegExp(
//"^" +
"((" + matchVar + "|" + matchBrackets + ")*)" + //Match arg path
"(!([rsa]))?" + //Conversion
"(:([^\\?\\!]+))?" //spec
//"$"
),
matchCount = 0;
return string.replace(FORMAT_EXPRESSION, function (_, match) {
var parts = match.match(matchParsing),
argName = parts[1] || matchCount,
conversion = parts[4] || 's', //Default is string conversion
formatSpec = parts[6],
value = formatArgGet(args, argName);
matchCount += 1;
if (value === undefined) {
return FORMAT_EXPRESSION_START + match + FORMAT_EXPRESSION_STOP;//Replace unchanged
}
if (formatSpec && formatSpec.length > 0) {
value = formatValueSpec(value, formatSpec);
}
//Conversion s, r or a
switch (conversion) {
case 's':
return '' + value;
case 'r':
return inspect(value);
case 'a':
throw new Error('Not yet implemented conversion "' + conversion + '"');
default:
throw new Error('Invalid conversion "' + conversion + '"');
}
});
} | [
"function",
"format",
"(",
"string",
",",
"args",
")",
"{",
"if",
"(",
"string",
".",
"length",
"===",
"0",
"||",
"!",
"args",
"||",
"Object",
".",
"keys",
"(",
"args",
")",
".",
"length",
"===",
"0",
")",
"{",
"return",
"string",
";",
"}",
"var",
"matchVar",
"=",
"'[0-9a-zA-Z_$\\\\.]+'",
",",
"matchBrackets",
"=",
"'\\\\[[^\\\\]]*\\\\]'",
",",
"matchParsing",
"=",
"new",
"RegExp",
"(",
"//\"^\" +",
"\"((\"",
"+",
"matchVar",
"+",
"\"|\"",
"+",
"matchBrackets",
"+",
"\")*)\"",
"+",
"//Match arg path",
"\"(!([rsa]))?\"",
"+",
"//Conversion",
"\"(:([^\\\\?\\\\!]+))?\"",
"//spec",
"//\"$\"",
")",
",",
"matchCount",
"=",
"0",
";",
"return",
"string",
".",
"replace",
"(",
"FORMAT_EXPRESSION",
",",
"function",
"(",
"_",
",",
"match",
")",
"{",
"var",
"parts",
"=",
"match",
".",
"match",
"(",
"matchParsing",
")",
",",
"argName",
"=",
"parts",
"[",
"1",
"]",
"||",
"matchCount",
",",
"conversion",
"=",
"parts",
"[",
"4",
"]",
"||",
"'s'",
",",
"//Default is string conversion",
"formatSpec",
"=",
"parts",
"[",
"6",
"]",
",",
"value",
"=",
"formatArgGet",
"(",
"args",
",",
"argName",
")",
";",
"matchCount",
"+=",
"1",
";",
"if",
"(",
"value",
"===",
"undefined",
")",
"{",
"return",
"FORMAT_EXPRESSION_START",
"+",
"match",
"+",
"FORMAT_EXPRESSION_STOP",
";",
"//Replace unchanged",
"}",
"if",
"(",
"formatSpec",
"&&",
"formatSpec",
".",
"length",
">",
"0",
")",
"{",
"value",
"=",
"formatValueSpec",
"(",
"value",
",",
"formatSpec",
")",
";",
"}",
"//Conversion s, r or a",
"switch",
"(",
"conversion",
")",
"{",
"case",
"'s'",
":",
"return",
"''",
"+",
"value",
";",
"case",
"'r'",
":",
"return",
"inspect",
"(",
"value",
")",
";",
"case",
"'a'",
":",
"throw",
"new",
"Error",
"(",
"'Not yet implemented conversion \"'",
"+",
"conversion",
"+",
"'\"'",
")",
";",
"default",
":",
"throw",
"new",
"Error",
"(",
"'Invalid conversion \"'",
"+",
"conversion",
"+",
"'\"'",
")",
";",
"}",
"}",
")",
";",
"}"
] | Format string with `args`
@see http://docs.python.org/release/3.1.3/library/string.html#format-string-syntax
@param {string} string
@param {Array|Object} args
@return {string} | [
"Format",
"string",
"with",
"args"
] | 5c051157e6f558636c8e12081b6707caa66249de | https://github.com/altshift/altshift/blob/5c051157e6f558636c8e12081b6707caa66249de/lib/altshift/core/base.js#L133-L182 |
57,264 | altshift/altshift | lib/altshift/core/base.js | mixin | function mixin(obj, props) {
var argi = 1,
argc = arguments.length,
source, property, value;
if (!obj) {
obj = {};
}
while (argi < argc) {
source = arguments[argi];
for (property in source) {
if (source.hasOwnProperty(property)) {
value = source[property];
if (obj[property] !== value) {
obj[property] = value;
}
}
}
argi += 1;
}
return obj; // Object
} | javascript | function mixin(obj, props) {
var argi = 1,
argc = arguments.length,
source, property, value;
if (!obj) {
obj = {};
}
while (argi < argc) {
source = arguments[argi];
for (property in source) {
if (source.hasOwnProperty(property)) {
value = source[property];
if (obj[property] !== value) {
obj[property] = value;
}
}
}
argi += 1;
}
return obj; // Object
} | [
"function",
"mixin",
"(",
"obj",
",",
"props",
")",
"{",
"var",
"argi",
"=",
"1",
",",
"argc",
"=",
"arguments",
".",
"length",
",",
"source",
",",
"property",
",",
"value",
";",
"if",
"(",
"!",
"obj",
")",
"{",
"obj",
"=",
"{",
"}",
";",
"}",
"while",
"(",
"argi",
"<",
"argc",
")",
"{",
"source",
"=",
"arguments",
"[",
"argi",
"]",
";",
"for",
"(",
"property",
"in",
"source",
")",
"{",
"if",
"(",
"source",
".",
"hasOwnProperty",
"(",
"property",
")",
")",
"{",
"value",
"=",
"source",
"[",
"property",
"]",
";",
"if",
"(",
"obj",
"[",
"property",
"]",
"!==",
"value",
")",
"{",
"obj",
"[",
"property",
"]",
"=",
"value",
";",
"}",
"}",
"}",
"argi",
"+=",
"1",
";",
"}",
"return",
"obj",
";",
"// Object",
"}"
] | Mix all props, ... into `obj`
@param {Object} obj
@param {Object} props
@return {Object} | [
"Mix",
"all",
"props",
"...",
"into",
"obj"
] | 5c051157e6f558636c8e12081b6707caa66249de | https://github.com/altshift/altshift/blob/5c051157e6f558636c8e12081b6707caa66249de/lib/altshift/core/base.js#L191-L213 |
57,265 | altshift/altshift | lib/altshift/core/base.js | isObject | function isObject(obj) {
return obj !== undefined &&
(obj === null || typeof obj === "object" ||
typeof obj === "array" || obj instanceof Array ||
Object.prototype.toString.call(obj) === "[object Function]"
);
} | javascript | function isObject(obj) {
return obj !== undefined &&
(obj === null || typeof obj === "object" ||
typeof obj === "array" || obj instanceof Array ||
Object.prototype.toString.call(obj) === "[object Function]"
);
} | [
"function",
"isObject",
"(",
"obj",
")",
"{",
"return",
"obj",
"!==",
"undefined",
"&&",
"(",
"obj",
"===",
"null",
"||",
"typeof",
"obj",
"===",
"\"object\"",
"||",
"typeof",
"obj",
"===",
"\"array\"",
"||",
"obj",
"instanceof",
"Array",
"||",
"Object",
".",
"prototype",
".",
"toString",
".",
"call",
"(",
"obj",
")",
"===",
"\"[object Function]\"",
")",
";",
"}"
] | Return true if `obj` is an Object
@param {*} obj
@return {boolean} | [
"Return",
"true",
"if",
"obj",
"is",
"an",
"Object"
] | 5c051157e6f558636c8e12081b6707caa66249de | https://github.com/altshift/altshift/blob/5c051157e6f558636c8e12081b6707caa66249de/lib/altshift/core/base.js#L251-L257 |
57,266 | altshift/altshift | lib/altshift/core/base.js | isScalar | function isScalar(obj) {
var type = typeof obj;
return (type !== 'undefined' && (
obj === null ||
type === 'string' ||
type === 'number' ||
type === 'boolean'
));
} | javascript | function isScalar(obj) {
var type = typeof obj;
return (type !== 'undefined' && (
obj === null ||
type === 'string' ||
type === 'number' ||
type === 'boolean'
));
} | [
"function",
"isScalar",
"(",
"obj",
")",
"{",
"var",
"type",
"=",
"typeof",
"obj",
";",
"return",
"(",
"type",
"!==",
"'undefined'",
"&&",
"(",
"obj",
"===",
"null",
"||",
"type",
"===",
"'string'",
"||",
"type",
"===",
"'number'",
"||",
"type",
"===",
"'boolean'",
")",
")",
";",
"}"
] | Return true if `obj` is a scalar
@param {*} obj
@return {boolean} | [
"Return",
"true",
"if",
"obj",
"is",
"a",
"scalar"
] | 5c051157e6f558636c8e12081b6707caa66249de | https://github.com/altshift/altshift/blob/5c051157e6f558636c8e12081b6707caa66249de/lib/altshift/core/base.js#L265-L273 |
57,267 | altshift/altshift | lib/altshift/core/base.js | destroy | function destroy(object) {
if (isObject(object)) {
if (isFunction(object.finalize)) {
object.finalize();
}
for (var property in object) {
if (true) {//For lint
delete object[property];
}
}
}
} | javascript | function destroy(object) {
if (isObject(object)) {
if (isFunction(object.finalize)) {
object.finalize();
}
for (var property in object) {
if (true) {//For lint
delete object[property];
}
}
}
} | [
"function",
"destroy",
"(",
"object",
")",
"{",
"if",
"(",
"isObject",
"(",
"object",
")",
")",
"{",
"if",
"(",
"isFunction",
"(",
"object",
".",
"finalize",
")",
")",
"{",
"object",
".",
"finalize",
"(",
")",
";",
"}",
"for",
"(",
"var",
"property",
"in",
"object",
")",
"{",
"if",
"(",
"true",
")",
"{",
"//For lint",
"delete",
"object",
"[",
"property",
"]",
";",
"}",
"}",
"}",
"}"
] | Will destroy object
@param {Object} object
@return undefined | [
"Will",
"destroy",
"object"
] | 5c051157e6f558636c8e12081b6707caa66249de | https://github.com/altshift/altshift/blob/5c051157e6f558636c8e12081b6707caa66249de/lib/altshift/core/base.js#L281-L292 |
57,268 | altshift/altshift | lib/altshift/core/base.js | clone | function clone(obj, deep) {
if (!obj || typeof obj !== "object" || isFunction(obj)) {
// null, undefined, any non-object, or function
return obj; // anything
}
if (obj instanceof Date) {
// Date
return new Date(obj.getTime()); // Date
}
var result, index, length, value;
if (isArray(obj)) {
// array
result = [];
if (deep) {
for (index = 0, length = obj.length; index < length; index += 1) {
if (index in obj) {
value = obj[index];
value = value.clone ? value.clone(true) : clone(value);
result.push(clone(value));
}
}
} else {
for (index = 0, length = obj.length; index < length; index += 1) {
if (index in obj) {
result.push(value);
}
}
}
return result;
}
//Default implementation
if (obj.clone) {
return obj.clone(obj, deep);
}
// generic objects
result = obj.constructor ? new obj.constructor() : {};
for (index in obj) {
if (true) {//jslint validation
value = obj[index];
if (
!(index in result) ||
(result[index] !== value && (!(index in EMPTY) || EMPTY[index] !== value))
) {
result[index] = clone(value);
}
}
}
return result; // Object
} | javascript | function clone(obj, deep) {
if (!obj || typeof obj !== "object" || isFunction(obj)) {
// null, undefined, any non-object, or function
return obj; // anything
}
if (obj instanceof Date) {
// Date
return new Date(obj.getTime()); // Date
}
var result, index, length, value;
if (isArray(obj)) {
// array
result = [];
if (deep) {
for (index = 0, length = obj.length; index < length; index += 1) {
if (index in obj) {
value = obj[index];
value = value.clone ? value.clone(true) : clone(value);
result.push(clone(value));
}
}
} else {
for (index = 0, length = obj.length; index < length; index += 1) {
if (index in obj) {
result.push(value);
}
}
}
return result;
}
//Default implementation
if (obj.clone) {
return obj.clone(obj, deep);
}
// generic objects
result = obj.constructor ? new obj.constructor() : {};
for (index in obj) {
if (true) {//jslint validation
value = obj[index];
if (
!(index in result) ||
(result[index] !== value && (!(index in EMPTY) || EMPTY[index] !== value))
) {
result[index] = clone(value);
}
}
}
return result; // Object
} | [
"function",
"clone",
"(",
"obj",
",",
"deep",
")",
"{",
"if",
"(",
"!",
"obj",
"||",
"typeof",
"obj",
"!==",
"\"object\"",
"||",
"isFunction",
"(",
"obj",
")",
")",
"{",
"// null, undefined, any non-object, or function",
"return",
"obj",
";",
"// anything",
"}",
"if",
"(",
"obj",
"instanceof",
"Date",
")",
"{",
"// Date",
"return",
"new",
"Date",
"(",
"obj",
".",
"getTime",
"(",
")",
")",
";",
"// Date",
"}",
"var",
"result",
",",
"index",
",",
"length",
",",
"value",
";",
"if",
"(",
"isArray",
"(",
"obj",
")",
")",
"{",
"// array",
"result",
"=",
"[",
"]",
";",
"if",
"(",
"deep",
")",
"{",
"for",
"(",
"index",
"=",
"0",
",",
"length",
"=",
"obj",
".",
"length",
";",
"index",
"<",
"length",
";",
"index",
"+=",
"1",
")",
"{",
"if",
"(",
"index",
"in",
"obj",
")",
"{",
"value",
"=",
"obj",
"[",
"index",
"]",
";",
"value",
"=",
"value",
".",
"clone",
"?",
"value",
".",
"clone",
"(",
"true",
")",
":",
"clone",
"(",
"value",
")",
";",
"result",
".",
"push",
"(",
"clone",
"(",
"value",
")",
")",
";",
"}",
"}",
"}",
"else",
"{",
"for",
"(",
"index",
"=",
"0",
",",
"length",
"=",
"obj",
".",
"length",
";",
"index",
"<",
"length",
";",
"index",
"+=",
"1",
")",
"{",
"if",
"(",
"index",
"in",
"obj",
")",
"{",
"result",
".",
"push",
"(",
"value",
")",
";",
"}",
"}",
"}",
"return",
"result",
";",
"}",
"//Default implementation",
"if",
"(",
"obj",
".",
"clone",
")",
"{",
"return",
"obj",
".",
"clone",
"(",
"obj",
",",
"deep",
")",
";",
"}",
"// generic objects",
"result",
"=",
"obj",
".",
"constructor",
"?",
"new",
"obj",
".",
"constructor",
"(",
")",
":",
"{",
"}",
";",
"for",
"(",
"index",
"in",
"obj",
")",
"{",
"if",
"(",
"true",
")",
"{",
"//jslint validation",
"value",
"=",
"obj",
"[",
"index",
"]",
";",
"if",
"(",
"!",
"(",
"index",
"in",
"result",
")",
"||",
"(",
"result",
"[",
"index",
"]",
"!==",
"value",
"&&",
"(",
"!",
"(",
"index",
"in",
"EMPTY",
")",
"||",
"EMPTY",
"[",
"index",
"]",
"!==",
"value",
")",
")",
")",
"{",
"result",
"[",
"index",
"]",
"=",
"clone",
"(",
"value",
")",
";",
"}",
"}",
"}",
"return",
"result",
";",
"// Object",
"}"
] | Clone an object
@param {*} obj
@return {*} | [
"Clone",
"an",
"object"
] | 5c051157e6f558636c8e12081b6707caa66249de | https://github.com/altshift/altshift/blob/5c051157e6f558636c8e12081b6707caa66249de/lib/altshift/core/base.js#L301-L354 |
57,269 | altshift/altshift | lib/altshift/core/base.js | forEach | function forEach(object, iterator, thisp) {
if (object) {
if (object.forEach) {
object.forEach(iterator, thisp);
return;
}
//Default implementation
if (! (iterator instanceof Function)) {
throw new TypeError('iterator should be a Function');
}
var key, length;
if (isString(object)) {
length = object.length;
for (key = 0; key < length; key += 1) {
iterator.call(thisp, object[key], key, object);
}
return;
}
for (key in object) {
if (object.hasOwnProperty(key)) {
iterator.call(thisp, object[key], key, object);
}
}
}
} | javascript | function forEach(object, iterator, thisp) {
if (object) {
if (object.forEach) {
object.forEach(iterator, thisp);
return;
}
//Default implementation
if (! (iterator instanceof Function)) {
throw new TypeError('iterator should be a Function');
}
var key, length;
if (isString(object)) {
length = object.length;
for (key = 0; key < length; key += 1) {
iterator.call(thisp, object[key], key, object);
}
return;
}
for (key in object) {
if (object.hasOwnProperty(key)) {
iterator.call(thisp, object[key], key, object);
}
}
}
} | [
"function",
"forEach",
"(",
"object",
",",
"iterator",
",",
"thisp",
")",
"{",
"if",
"(",
"object",
")",
"{",
"if",
"(",
"object",
".",
"forEach",
")",
"{",
"object",
".",
"forEach",
"(",
"iterator",
",",
"thisp",
")",
";",
"return",
";",
"}",
"//Default implementation",
"if",
"(",
"!",
"(",
"iterator",
"instanceof",
"Function",
")",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'iterator should be a Function'",
")",
";",
"}",
"var",
"key",
",",
"length",
";",
"if",
"(",
"isString",
"(",
"object",
")",
")",
"{",
"length",
"=",
"object",
".",
"length",
";",
"for",
"(",
"key",
"=",
"0",
";",
"key",
"<",
"length",
";",
"key",
"+=",
"1",
")",
"{",
"iterator",
".",
"call",
"(",
"thisp",
",",
"object",
"[",
"key",
"]",
",",
"key",
",",
"object",
")",
";",
"}",
"return",
";",
"}",
"for",
"(",
"key",
"in",
"object",
")",
"{",
"if",
"(",
"object",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"iterator",
".",
"call",
"(",
"thisp",
",",
"object",
"[",
"key",
"]",
",",
"key",
",",
"object",
")",
";",
"}",
"}",
"}",
"}"
] | Iterate on object
@param {*} object
@param {Function} iterator
@param {*} thisp
@return undefined | [
"Iterate",
"on",
"object"
] | 5c051157e6f558636c8e12081b6707caa66249de | https://github.com/altshift/altshift/blob/5c051157e6f558636c8e12081b6707caa66249de/lib/altshift/core/base.js#L364-L391 |
57,270 | altshift/altshift | lib/altshift/core/base.js | hash | function hash(object) {
if (object === undefined || isScalar(object)) {
return '' + object;
}
if (object.hash) {
return object.hash();
}
//Default implementation
var hashes = [],
value, key, hashKey, hashValue;
for (key in object) {
if (object.hasOwnProperty(key)) {
value = object[key];
hashKey = String(key);
hashValue = hash(value);
hashValue = (hashKey > hashValue) ? hashValue + hashKey : hashKey + hashValue;
hashes.push(hashValue);
}
}
return hashes.sort().join('');
} | javascript | function hash(object) {
if (object === undefined || isScalar(object)) {
return '' + object;
}
if (object.hash) {
return object.hash();
}
//Default implementation
var hashes = [],
value, key, hashKey, hashValue;
for (key in object) {
if (object.hasOwnProperty(key)) {
value = object[key];
hashKey = String(key);
hashValue = hash(value);
hashValue = (hashKey > hashValue) ? hashValue + hashKey : hashKey + hashValue;
hashes.push(hashValue);
}
}
return hashes.sort().join('');
} | [
"function",
"hash",
"(",
"object",
")",
"{",
"if",
"(",
"object",
"===",
"undefined",
"||",
"isScalar",
"(",
"object",
")",
")",
"{",
"return",
"''",
"+",
"object",
";",
"}",
"if",
"(",
"object",
".",
"hash",
")",
"{",
"return",
"object",
".",
"hash",
"(",
")",
";",
"}",
"//Default implementation",
"var",
"hashes",
"=",
"[",
"]",
",",
"value",
",",
"key",
",",
"hashKey",
",",
"hashValue",
";",
"for",
"(",
"key",
"in",
"object",
")",
"{",
"if",
"(",
"object",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"value",
"=",
"object",
"[",
"key",
"]",
";",
"hashKey",
"=",
"String",
"(",
"key",
")",
";",
"hashValue",
"=",
"hash",
"(",
"value",
")",
";",
"hashValue",
"=",
"(",
"hashKey",
">",
"hashValue",
")",
"?",
"hashValue",
"+",
"hashKey",
":",
"hashKey",
"+",
"hashValue",
";",
"hashes",
".",
"push",
"(",
"hashValue",
")",
";",
"}",
"}",
"return",
"hashes",
".",
"sort",
"(",
")",
".",
"join",
"(",
"''",
")",
";",
"}"
] | Return a hash string for the object
@param {*} object
@return {String} | [
"Return",
"a",
"hash",
"string",
"for",
"the",
"object"
] | 5c051157e6f558636c8e12081b6707caa66249de | https://github.com/altshift/altshift/blob/5c051157e6f558636c8e12081b6707caa66249de/lib/altshift/core/base.js#L399-L423 |
57,271 | dazeus/dazeus-nodejs | dazeus.js | function (options, onConnect) {
var self = this;
EventEmitter.call(this);
this.options = options;
// debugging
this.debug_enabled = options.debug;
this.handshook = false;
// received data which could not be parsed into messages yet
this.data = '';
// determine correct call of net.connect
var cb = function () {
connected.call(self);
onConnect.call(self);
};
if (options.path) {
this.debug("Trying to establish connection to unix socket %s", options.path);
this.client = net.connect(options.path, cb);
} else {
this.debug("Trying to establish connection to %s on port %s", options.host, options.port);
this.client = net.connect(options.port, options.host, cb);
}
// when data is received
this.client.on('data', function (data) {
var obj = dezeusify.call(self, data.toString('utf8'));
obj.forEach(function (item) {
received.call(self, item);
});
});
// when the connection is closed
this.client.on('end', function () {
disconnected.call(self);
});
this.client.on('error', function (err) {
self.debug("Whoops, an error occurred: %s", err.message);
throw new Error(util.format("A connection error occurred: %s", err.message));
});
// when a new listener is added to this object, we'll want to check if we should notify the server
this.on('newListener', function (evt) {
this.debug("A new event listener was added");
if (evt.toUpperCase() === evt && !this.subscribedEvents.indexOf(evt) !== -1) {
subscribeServerEvent.call(self, evt);
}
});
this.subscribedEvents = [];
this.waitingCallbacks = [];
} | javascript | function (options, onConnect) {
var self = this;
EventEmitter.call(this);
this.options = options;
// debugging
this.debug_enabled = options.debug;
this.handshook = false;
// received data which could not be parsed into messages yet
this.data = '';
// determine correct call of net.connect
var cb = function () {
connected.call(self);
onConnect.call(self);
};
if (options.path) {
this.debug("Trying to establish connection to unix socket %s", options.path);
this.client = net.connect(options.path, cb);
} else {
this.debug("Trying to establish connection to %s on port %s", options.host, options.port);
this.client = net.connect(options.port, options.host, cb);
}
// when data is received
this.client.on('data', function (data) {
var obj = dezeusify.call(self, data.toString('utf8'));
obj.forEach(function (item) {
received.call(self, item);
});
});
// when the connection is closed
this.client.on('end', function () {
disconnected.call(self);
});
this.client.on('error', function (err) {
self.debug("Whoops, an error occurred: %s", err.message);
throw new Error(util.format("A connection error occurred: %s", err.message));
});
// when a new listener is added to this object, we'll want to check if we should notify the server
this.on('newListener', function (evt) {
this.debug("A new event listener was added");
if (evt.toUpperCase() === evt && !this.subscribedEvents.indexOf(evt) !== -1) {
subscribeServerEvent.call(self, evt);
}
});
this.subscribedEvents = [];
this.waitingCallbacks = [];
} | [
"function",
"(",
"options",
",",
"onConnect",
")",
"{",
"var",
"self",
"=",
"this",
";",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"options",
"=",
"options",
";",
"// debugging",
"this",
".",
"debug_enabled",
"=",
"options",
".",
"debug",
";",
"this",
".",
"handshook",
"=",
"false",
";",
"// received data which could not be parsed into messages yet",
"this",
".",
"data",
"=",
"''",
";",
"// determine correct call of net.connect",
"var",
"cb",
"=",
"function",
"(",
")",
"{",
"connected",
".",
"call",
"(",
"self",
")",
";",
"onConnect",
".",
"call",
"(",
"self",
")",
";",
"}",
";",
"if",
"(",
"options",
".",
"path",
")",
"{",
"this",
".",
"debug",
"(",
"\"Trying to establish connection to unix socket %s\"",
",",
"options",
".",
"path",
")",
";",
"this",
".",
"client",
"=",
"net",
".",
"connect",
"(",
"options",
".",
"path",
",",
"cb",
")",
";",
"}",
"else",
"{",
"this",
".",
"debug",
"(",
"\"Trying to establish connection to %s on port %s\"",
",",
"options",
".",
"host",
",",
"options",
".",
"port",
")",
";",
"this",
".",
"client",
"=",
"net",
".",
"connect",
"(",
"options",
".",
"port",
",",
"options",
".",
"host",
",",
"cb",
")",
";",
"}",
"// when data is received",
"this",
".",
"client",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"data",
")",
"{",
"var",
"obj",
"=",
"dezeusify",
".",
"call",
"(",
"self",
",",
"data",
".",
"toString",
"(",
"'utf8'",
")",
")",
";",
"obj",
".",
"forEach",
"(",
"function",
"(",
"item",
")",
"{",
"received",
".",
"call",
"(",
"self",
",",
"item",
")",
";",
"}",
")",
";",
"}",
")",
";",
"// when the connection is closed",
"this",
".",
"client",
".",
"on",
"(",
"'end'",
",",
"function",
"(",
")",
"{",
"disconnected",
".",
"call",
"(",
"self",
")",
";",
"}",
")",
";",
"this",
".",
"client",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"err",
")",
"{",
"self",
".",
"debug",
"(",
"\"Whoops, an error occurred: %s\"",
",",
"err",
".",
"message",
")",
";",
"throw",
"new",
"Error",
"(",
"util",
".",
"format",
"(",
"\"A connection error occurred: %s\"",
",",
"err",
".",
"message",
")",
")",
";",
"}",
")",
";",
"// when a new listener is added to this object, we'll want to check if we should notify the server",
"this",
".",
"on",
"(",
"'newListener'",
",",
"function",
"(",
"evt",
")",
"{",
"this",
".",
"debug",
"(",
"\"A new event listener was added\"",
")",
";",
"if",
"(",
"evt",
".",
"toUpperCase",
"(",
")",
"===",
"evt",
"&&",
"!",
"this",
".",
"subscribedEvents",
".",
"indexOf",
"(",
"evt",
")",
"!==",
"-",
"1",
")",
"{",
"subscribeServerEvent",
".",
"call",
"(",
"self",
",",
"evt",
")",
";",
"}",
"}",
")",
";",
"this",
".",
"subscribedEvents",
"=",
"[",
"]",
";",
"this",
".",
"waitingCallbacks",
"=",
"[",
"]",
";",
"}"
] | DaZeus client connection object
@param {Object} options
@param {Function} onConnect Function to be executed when the connection is established | [
"DaZeus",
"client",
"connection",
"object"
] | d62347378bb4cd5939fdabec7e0922548178222c | https://github.com/dazeus/dazeus-nodejs/blob/d62347378bb4cd5939fdabec7e0922548178222c/dazeus.js#L23-L78 |
|
57,272 | dazeus/dazeus-nodejs | dazeus.js | function (data, callback) {
this.debug("Sending: %s", JSON.stringify(data));
var message = dazeusify.call(this, data);
this.client.write(message, callback);
} | javascript | function (data, callback) {
this.debug("Sending: %s", JSON.stringify(data));
var message = dazeusify.call(this, data);
this.client.write(message, callback);
} | [
"function",
"(",
"data",
",",
"callback",
")",
"{",
"this",
".",
"debug",
"(",
"\"Sending: %s\"",
",",
"JSON",
".",
"stringify",
"(",
"data",
")",
")",
";",
"var",
"message",
"=",
"dazeusify",
".",
"call",
"(",
"this",
",",
"data",
")",
";",
"this",
".",
"client",
".",
"write",
"(",
"message",
",",
"callback",
")",
";",
"}"
] | Sends some data to the server and calls a callback as soon as that is done.
@param {Object} data Message to be sent
@param {Function} callback Callback to be executed when sending is finished | [
"Sends",
"some",
"data",
"to",
"the",
"server",
"and",
"calls",
"a",
"callback",
"as",
"soon",
"as",
"that",
"is",
"done",
"."
] | d62347378bb4cd5939fdabec7e0922548178222c | https://github.com/dazeus/dazeus-nodejs/blob/d62347378bb4cd5939fdabec7e0922548178222c/dazeus.js#L592-L596 |
|
57,273 | dazeus/dazeus-nodejs | dazeus.js | function (data, callback) {
if (typeof callback !== 'function') {
this.debug("Registering dummy callback, because a response message is expected");
} else {
this.debug("Registering callback");
}
this.waitingCallbacks.push(callback);
send.call(this, data);
} | javascript | function (data, callback) {
if (typeof callback !== 'function') {
this.debug("Registering dummy callback, because a response message is expected");
} else {
this.debug("Registering callback");
}
this.waitingCallbacks.push(callback);
send.call(this, data);
} | [
"function",
"(",
"data",
",",
"callback",
")",
"{",
"if",
"(",
"typeof",
"callback",
"!==",
"'function'",
")",
"{",
"this",
".",
"debug",
"(",
"\"Registering dummy callback, because a response message is expected\"",
")",
";",
"}",
"else",
"{",
"this",
".",
"debug",
"(",
"\"Registering callback\"",
")",
";",
"}",
"this",
".",
"waitingCallbacks",
".",
"push",
"(",
"callback",
")",
";",
"send",
".",
"call",
"(",
"this",
",",
"data",
")",
";",
"}"
] | Send a message and register a callback
@param {Object} data Message to be sent
@param {Function} callback Callback function to be registered | [
"Send",
"a",
"message",
"and",
"register",
"a",
"callback"
] | d62347378bb4cd5939fdabec7e0922548178222c | https://github.com/dazeus/dazeus-nodejs/blob/d62347378bb4cd5939fdabec7e0922548178222c/dazeus.js#L603-L611 |
|
57,274 | dazeus/dazeus-nodejs | dazeus.js | function (event) {
this.debug("Requesting subscription for " + event);
sendReceive.call(this, {'do': 'subscribe', params: [event]}, function (result) {
if (result.success) {
this.debug("Succesfully subscribed to %s", event);
} else {
this.debug("Subscription request for %s failed", event);
}
});
this.subscribedEvents.push(event);
} | javascript | function (event) {
this.debug("Requesting subscription for " + event);
sendReceive.call(this, {'do': 'subscribe', params: [event]}, function (result) {
if (result.success) {
this.debug("Succesfully subscribed to %s", event);
} else {
this.debug("Subscription request for %s failed", event);
}
});
this.subscribedEvents.push(event);
} | [
"function",
"(",
"event",
")",
"{",
"this",
".",
"debug",
"(",
"\"Requesting subscription for \"",
"+",
"event",
")",
";",
"sendReceive",
".",
"call",
"(",
"this",
",",
"{",
"'do'",
":",
"'subscribe'",
",",
"params",
":",
"[",
"event",
"]",
"}",
",",
"function",
"(",
"result",
")",
"{",
"if",
"(",
"result",
".",
"success",
")",
"{",
"this",
".",
"debug",
"(",
"\"Succesfully subscribed to %s\"",
",",
"event",
")",
";",
"}",
"else",
"{",
"this",
".",
"debug",
"(",
"\"Subscription request for %s failed\"",
",",
"event",
")",
";",
"}",
"}",
")",
";",
"this",
".",
"subscribedEvents",
".",
"push",
"(",
"event",
")",
";",
"}"
] | Request DaZeus to be notified of a certain type of event
@param {String} event Type of event to subscribe to | [
"Request",
"DaZeus",
"to",
"be",
"notified",
"of",
"a",
"certain",
"type",
"of",
"event"
] | d62347378bb4cd5939fdabec7e0922548178222c | https://github.com/dazeus/dazeus-nodejs/blob/d62347378bb4cd5939fdabec7e0922548178222c/dazeus.js#L617-L627 |
|
57,275 | dazeus/dazeus-nodejs | dazeus.js | function (obj) {
this.debug("Received: %s", JSON.stringify(obj));
if (typeof obj.event !== 'undefined') {
this.debug("Received an event-based message, sending off to listeners");
handleEvent.call(this, obj.event, obj.params);
} else {
if (this.waitingCallbacks.length > 0) {
var callback = this.waitingCallbacks.shift();
if (typeof callback === 'function') {
this.debug("Calling previously registered callback with message");
callback.call(this, obj);
} else {
this.debug("Callback was a dummy, not calling");
}
} else {
this.debug("No callbacks remaining, still received a response");
}
}
} | javascript | function (obj) {
this.debug("Received: %s", JSON.stringify(obj));
if (typeof obj.event !== 'undefined') {
this.debug("Received an event-based message, sending off to listeners");
handleEvent.call(this, obj.event, obj.params);
} else {
if (this.waitingCallbacks.length > 0) {
var callback = this.waitingCallbacks.shift();
if (typeof callback === 'function') {
this.debug("Calling previously registered callback with message");
callback.call(this, obj);
} else {
this.debug("Callback was a dummy, not calling");
}
} else {
this.debug("No callbacks remaining, still received a response");
}
}
} | [
"function",
"(",
"obj",
")",
"{",
"this",
".",
"debug",
"(",
"\"Received: %s\"",
",",
"JSON",
".",
"stringify",
"(",
"obj",
")",
")",
";",
"if",
"(",
"typeof",
"obj",
".",
"event",
"!==",
"'undefined'",
")",
"{",
"this",
".",
"debug",
"(",
"\"Received an event-based message, sending off to listeners\"",
")",
";",
"handleEvent",
".",
"call",
"(",
"this",
",",
"obj",
".",
"event",
",",
"obj",
".",
"params",
")",
";",
"}",
"else",
"{",
"if",
"(",
"this",
".",
"waitingCallbacks",
".",
"length",
">",
"0",
")",
"{",
"var",
"callback",
"=",
"this",
".",
"waitingCallbacks",
".",
"shift",
"(",
")",
";",
"if",
"(",
"typeof",
"callback",
"===",
"'function'",
")",
"{",
"this",
".",
"debug",
"(",
"\"Calling previously registered callback with message\"",
")",
";",
"callback",
".",
"call",
"(",
"this",
",",
"obj",
")",
";",
"}",
"else",
"{",
"this",
".",
"debug",
"(",
"\"Callback was a dummy, not calling\"",
")",
";",
"}",
"}",
"else",
"{",
"this",
".",
"debug",
"(",
"\"No callbacks remaining, still received a response\"",
")",
";",
"}",
"}",
"}"
] | Receive a new message object from the server.
Either we pass it off to the event-handler if it is an event-based object, or
we look for a corresponding callback that is waiting for a response.
@param {Object} obj The received message as a javascript object | [
"Receive",
"a",
"new",
"message",
"object",
"from",
"the",
"server",
".",
"Either",
"we",
"pass",
"it",
"off",
"to",
"the",
"event",
"-",
"handler",
"if",
"it",
"is",
"an",
"event",
"-",
"based",
"object",
"or",
"we",
"look",
"for",
"a",
"corresponding",
"callback",
"that",
"is",
"waiting",
"for",
"a",
"response",
"."
] | d62347378bb4cd5939fdabec7e0922548178222c | https://github.com/dazeus/dazeus-nodejs/blob/d62347378bb4cd5939fdabec7e0922548178222c/dazeus.js#L635-L653 |
|
57,276 | dazeus/dazeus-nodejs | dazeus.js | function (event, parameters) {
if (event === 'COMMAND') {
event = 'command_' + parameters[3];
}
parameters.unshift(event);
this.emit.apply(this, parameters);
} | javascript | function (event, parameters) {
if (event === 'COMMAND') {
event = 'command_' + parameters[3];
}
parameters.unshift(event);
this.emit.apply(this, parameters);
} | [
"function",
"(",
"event",
",",
"parameters",
")",
"{",
"if",
"(",
"event",
"===",
"'COMMAND'",
")",
"{",
"event",
"=",
"'command_'",
"+",
"parameters",
"[",
"3",
"]",
";",
"}",
"parameters",
".",
"unshift",
"(",
"event",
")",
";",
"this",
".",
"emit",
".",
"apply",
"(",
"this",
",",
"parameters",
")",
";",
"}"
] | For event-type messages, this calls the correct event handlers.
@param {String} event Event type name
@param {Array} parameters Parameters for the event | [
"For",
"event",
"-",
"type",
"messages",
"this",
"calls",
"the",
"correct",
"event",
"handlers",
"."
] | d62347378bb4cd5939fdabec7e0922548178222c | https://github.com/dazeus/dazeus-nodejs/blob/d62347378bb4cd5939fdabec7e0922548178222c/dazeus.js#L660-L666 |
|
57,277 | dazeus/dazeus-nodejs | dazeus.js | function (message) {
var objs = [], collector = '', chr, msglen, data;
this.data += message;
data = new Buffer(this.data, 'utf8');
for (var i = 0; i < data.length; i += 1) {
chr = data[i];
if (chr > 47 && chr < 58) {
collector += String.fromCharCode(chr);
} else if (chr !== 10 && chr !== 13) {
msglen = parseInt(collector, 10);
if (msglen + i <= data.length) {
objs.push(JSON.parse(data.toString('utf8', i, msglen + i)));
data = data.slice(i + msglen);
collector = '';
i = 0;
} else {
break;
}
}
}
this.data = data.toString('utf8');
return objs;
} | javascript | function (message) {
var objs = [], collector = '', chr, msglen, data;
this.data += message;
data = new Buffer(this.data, 'utf8');
for (var i = 0; i < data.length; i += 1) {
chr = data[i];
if (chr > 47 && chr < 58) {
collector += String.fromCharCode(chr);
} else if (chr !== 10 && chr !== 13) {
msglen = parseInt(collector, 10);
if (msglen + i <= data.length) {
objs.push(JSON.parse(data.toString('utf8', i, msglen + i)));
data = data.slice(i + msglen);
collector = '';
i = 0;
} else {
break;
}
}
}
this.data = data.toString('utf8');
return objs;
} | [
"function",
"(",
"message",
")",
"{",
"var",
"objs",
"=",
"[",
"]",
",",
"collector",
"=",
"''",
",",
"chr",
",",
"msglen",
",",
"data",
";",
"this",
".",
"data",
"+=",
"message",
";",
"data",
"=",
"new",
"Buffer",
"(",
"this",
".",
"data",
",",
"'utf8'",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"data",
".",
"length",
";",
"i",
"+=",
"1",
")",
"{",
"chr",
"=",
"data",
"[",
"i",
"]",
";",
"if",
"(",
"chr",
">",
"47",
"&&",
"chr",
"<",
"58",
")",
"{",
"collector",
"+=",
"String",
".",
"fromCharCode",
"(",
"chr",
")",
";",
"}",
"else",
"if",
"(",
"chr",
"!==",
"10",
"&&",
"chr",
"!==",
"13",
")",
"{",
"msglen",
"=",
"parseInt",
"(",
"collector",
",",
"10",
")",
";",
"if",
"(",
"msglen",
"+",
"i",
"<=",
"data",
".",
"length",
")",
"{",
"objs",
".",
"push",
"(",
"JSON",
".",
"parse",
"(",
"data",
".",
"toString",
"(",
"'utf8'",
",",
"i",
",",
"msglen",
"+",
"i",
")",
")",
")",
";",
"data",
"=",
"data",
".",
"slice",
"(",
"i",
"+",
"msglen",
")",
";",
"collector",
"=",
"''",
";",
"i",
"=",
"0",
";",
"}",
"else",
"{",
"break",
";",
"}",
"}",
"}",
"this",
".",
"data",
"=",
"data",
".",
"toString",
"(",
"'utf8'",
")",
";",
"return",
"objs",
";",
"}"
] | Transform a string retrieved from DaZeus to it's javascript-object-equivalents.
@param {String} message
@return {Array} Array of parsed messages | [
"Transform",
"a",
"string",
"retrieved",
"from",
"DaZeus",
"to",
"it",
"s",
"javascript",
"-",
"object",
"-",
"equivalents",
"."
] | d62347378bb4cd5939fdabec7e0922548178222c | https://github.com/dazeus/dazeus-nodejs/blob/d62347378bb4cd5939fdabec7e0922548178222c/dazeus.js#L698-L723 |
|
57,278 | sebpiq/node-validation-pod | index.js | function(err) {
var validationErrMsg = self.handleError(err)
if (!validationErrMsg) return false
else {
self._merge(validationErrors, validationErrMsg, prefix)
isValid = false
return true
}
} | javascript | function(err) {
var validationErrMsg = self.handleError(err)
if (!validationErrMsg) return false
else {
self._merge(validationErrors, validationErrMsg, prefix)
isValid = false
return true
}
} | [
"function",
"(",
"err",
")",
"{",
"var",
"validationErrMsg",
"=",
"self",
".",
"handleError",
"(",
"err",
")",
"if",
"(",
"!",
"validationErrMsg",
")",
"return",
"false",
"else",
"{",
"self",
".",
"_merge",
"(",
"validationErrors",
",",
"validationErrMsg",
",",
"prefix",
")",
"isValid",
"=",
"false",
"return",
"true",
"}",
"}"
] | Returns true if `err` was handled as a validation error, false otherwise | [
"Returns",
"true",
"if",
"err",
"was",
"handled",
"as",
"a",
"validation",
"error",
"false",
"otherwise"
] | c9a75c94c219a41fa877157a2df102c8fa24efbf | https://github.com/sebpiq/node-validation-pod/blob/c9a75c94c219a41fa877157a2df102c8fa24efbf/index.js#L34-L42 |
|
57,279 | ugate/releasebot | tasks/release.js | genTemplateData | function genTemplateData() {
var templateData = {
data : {
process : process,
commit : commit,
env : commitTask.commitOpts,
options : options
}
};
var rtn = {};
var arr = Array.prototype.slice.call(arguments, 0);
arr.forEach(function genIntMsgs(s) {
rtn[s] = options[s] ? rbot.processTemplate(options[s], templateData) : '';
if (rtn[s]) {
rbot.log.verbose(s + ' = ' + rtn[s]);
}
});
return rtn;
} | javascript | function genTemplateData() {
var templateData = {
data : {
process : process,
commit : commit,
env : commitTask.commitOpts,
options : options
}
};
var rtn = {};
var arr = Array.prototype.slice.call(arguments, 0);
arr.forEach(function genIntMsgs(s) {
rtn[s] = options[s] ? rbot.processTemplate(options[s], templateData) : '';
if (rtn[s]) {
rbot.log.verbose(s + ' = ' + rtn[s]);
}
});
return rtn;
} | [
"function",
"genTemplateData",
"(",
")",
"{",
"var",
"templateData",
"=",
"{",
"data",
":",
"{",
"process",
":",
"process",
",",
"commit",
":",
"commit",
",",
"env",
":",
"commitTask",
".",
"commitOpts",
",",
"options",
":",
"options",
"}",
"}",
";",
"var",
"rtn",
"=",
"{",
"}",
";",
"var",
"arr",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"0",
")",
";",
"arr",
".",
"forEach",
"(",
"function",
"genIntMsgs",
"(",
"s",
")",
"{",
"rtn",
"[",
"s",
"]",
"=",
"options",
"[",
"s",
"]",
"?",
"rbot",
".",
"processTemplate",
"(",
"options",
"[",
"s",
"]",
",",
"templateData",
")",
":",
"''",
";",
"if",
"(",
"rtn",
"[",
"s",
"]",
")",
"{",
"rbot",
".",
"log",
".",
"verbose",
"(",
"s",
"+",
"' = '",
"+",
"rtn",
"[",
"s",
"]",
")",
";",
"}",
"}",
")",
";",
"return",
"rtn",
";",
"}"
] | Generates an object that contains each of the passed arguments as a
property with a value of an option with the same name. Each property
will have a value for that option that is parsed using the template
processor.
@returns the parsed template data | [
"Generates",
"an",
"object",
"that",
"contains",
"each",
"of",
"the",
"passed",
"arguments",
"as",
"a",
"property",
"with",
"a",
"value",
"of",
"an",
"option",
"with",
"the",
"same",
"name",
".",
"Each",
"property",
"will",
"have",
"a",
"value",
"for",
"that",
"option",
"that",
"is",
"parsed",
"using",
"the",
"template",
"processor",
"."
] | 1a2ff42796e77f47f9590992c014fee461aad80b | https://github.com/ugate/releasebot/blob/1a2ff42796e77f47f9590992c014fee461aad80b/tasks/release.js#L123-L141 |
57,280 | ugate/releasebot | tasks/release.js | remoteSetup | function remoteSetup() {
var link = '${GH_TOKEN}@' + options.gitHostname + '/' + commit.slug + '.git';
cmd('git config --global user.email "' + options.repoEmail + '"');
cmd('git config --global user.name "' + options.repoUser + '"');
cmd('git remote rm ' + options.repoName);
cmd('git remote add ' + options.repoName + ' https://' + commit.username + ':' + link);
} | javascript | function remoteSetup() {
var link = '${GH_TOKEN}@' + options.gitHostname + '/' + commit.slug + '.git';
cmd('git config --global user.email "' + options.repoEmail + '"');
cmd('git config --global user.name "' + options.repoUser + '"');
cmd('git remote rm ' + options.repoName);
cmd('git remote add ' + options.repoName + ' https://' + commit.username + ':' + link);
} | [
"function",
"remoteSetup",
"(",
")",
"{",
"var",
"link",
"=",
"'${GH_TOKEN}@'",
"+",
"options",
".",
"gitHostname",
"+",
"'/'",
"+",
"commit",
".",
"slug",
"+",
"'.git'",
";",
"cmd",
"(",
"'git config --global user.email \"'",
"+",
"options",
".",
"repoEmail",
"+",
"'\"'",
")",
";",
"cmd",
"(",
"'git config --global user.name \"'",
"+",
"options",
".",
"repoUser",
"+",
"'\"'",
")",
";",
"cmd",
"(",
"'git remote rm '",
"+",
"options",
".",
"repoName",
")",
";",
"cmd",
"(",
"'git remote add '",
"+",
"options",
".",
"repoName",
"+",
"' https://'",
"+",
"commit",
".",
"username",
"+",
"':'",
"+",
"link",
")",
";",
"}"
] | Remote Git setup to permit pushes | [
"Remote",
"Git",
"setup",
"to",
"permit",
"pushes"
] | 1a2ff42796e77f47f9590992c014fee461aad80b | https://github.com/ugate/releasebot/blob/1a2ff42796e77f47f9590992c014fee461aad80b/tasks/release.js#L146-L152 |
57,281 | ugate/releasebot | tasks/release.js | gitRelease | function gitRelease() {
// Tag release
rbot.log.info('Tagging release ' + commit.versionTag + ' via ' + options.gitHostname);
cmd('git tag -f -a ' + commit.versionTag + ' -m "'
+ (chgLogRtn ? chgLogRtn.replace(coopt.regexLines, '$1 \\') : commit.message) + '"');
cmd('git push -f ' + options.repoName + ' ' + commit.versionTag);
commit.releaseId = commit.versionTag;
// TODO : upload asset?
rollCall.addRollback(rollbackTag);
rollCall.then(publish);
} | javascript | function gitRelease() {
// Tag release
rbot.log.info('Tagging release ' + commit.versionTag + ' via ' + options.gitHostname);
cmd('git tag -f -a ' + commit.versionTag + ' -m "'
+ (chgLogRtn ? chgLogRtn.replace(coopt.regexLines, '$1 \\') : commit.message) + '"');
cmd('git push -f ' + options.repoName + ' ' + commit.versionTag);
commit.releaseId = commit.versionTag;
// TODO : upload asset?
rollCall.addRollback(rollbackTag);
rollCall.then(publish);
} | [
"function",
"gitRelease",
"(",
")",
"{",
"// Tag release",
"rbot",
".",
"log",
".",
"info",
"(",
"'Tagging release '",
"+",
"commit",
".",
"versionTag",
"+",
"' via '",
"+",
"options",
".",
"gitHostname",
")",
";",
"cmd",
"(",
"'git tag -f -a '",
"+",
"commit",
".",
"versionTag",
"+",
"' -m \"'",
"+",
"(",
"chgLogRtn",
"?",
"chgLogRtn",
".",
"replace",
"(",
"coopt",
".",
"regexLines",
",",
"'$1 \\\\'",
")",
":",
"commit",
".",
"message",
")",
"+",
"'\"'",
")",
";",
"cmd",
"(",
"'git push -f '",
"+",
"options",
".",
"repoName",
"+",
"' '",
"+",
"commit",
".",
"versionTag",
")",
";",
"commit",
".",
"releaseId",
"=",
"commit",
".",
"versionTag",
";",
"// TODO : upload asset?",
"rollCall",
".",
"addRollback",
"(",
"rollbackTag",
")",
";",
"rollCall",
".",
"then",
"(",
"publish",
")",
";",
"}"
] | Tags release via standard Git CLI | [
"Tags",
"release",
"via",
"standard",
"Git",
"CLI"
] | 1a2ff42796e77f47f9590992c014fee461aad80b | https://github.com/ugate/releasebot/blob/1a2ff42796e77f47f9590992c014fee461aad80b/tasks/release.js#L335-L345 |
57,282 | ugate/releasebot | tasks/release.js | gitHubRelease | function gitHubRelease() {
rbot.log.info('Releasing ' + commit.versionTag + ' via ' + options.gitHostname);
// GitHub Release API will not remove the tag when removing a
// release
github.releaseAndUploadAsset(distAssets, coopt.regexLines, commit, tmpltData.name, chgLogRtn
|| commit.message, options, rollCall, rollbackTag, function() {
rollCall.then(publish);
});
} | javascript | function gitHubRelease() {
rbot.log.info('Releasing ' + commit.versionTag + ' via ' + options.gitHostname);
// GitHub Release API will not remove the tag when removing a
// release
github.releaseAndUploadAsset(distAssets, coopt.regexLines, commit, tmpltData.name, chgLogRtn
|| commit.message, options, rollCall, rollbackTag, function() {
rollCall.then(publish);
});
} | [
"function",
"gitHubRelease",
"(",
")",
"{",
"rbot",
".",
"log",
".",
"info",
"(",
"'Releasing '",
"+",
"commit",
".",
"versionTag",
"+",
"' via '",
"+",
"options",
".",
"gitHostname",
")",
";",
"// GitHub Release API will not remove the tag when removing a",
"// release",
"github",
".",
"releaseAndUploadAsset",
"(",
"distAssets",
",",
"coopt",
".",
"regexLines",
",",
"commit",
",",
"tmpltData",
".",
"name",
",",
"chgLogRtn",
"||",
"commit",
".",
"message",
",",
"options",
",",
"rollCall",
",",
"rollbackTag",
",",
"function",
"(",
")",
"{",
"rollCall",
".",
"then",
"(",
"publish",
")",
";",
"}",
")",
";",
"}"
] | Calls the GitHub Release API to tag release and upload optional
distribution asset | [
"Calls",
"the",
"GitHub",
"Release",
"API",
"to",
"tag",
"release",
"and",
"upload",
"optional",
"distribution",
"asset"
] | 1a2ff42796e77f47f9590992c014fee461aad80b | https://github.com/ugate/releasebot/blob/1a2ff42796e77f47f9590992c014fee461aad80b/tasks/release.js#L351-L359 |
57,283 | ugate/releasebot | tasks/release.js | rollbackPublish | function rollbackPublish() {
try {
chkoutRun(options.distBranch, function() {
var cph = cmd('git rev-parse HEAD');
if (pubHash && pubHash !== cph) {
cmd('git checkout -qf ' + pubHash);
cmd('git commit -q -m "Rollback: ' + tmpltData.distBranchPubMsg + '"');
cmd('git push -f ' + options.repoName + ' ' + options.distBranch);
} else if (!pubHash) {
cmd('git push ' + options.repoName + ' --delete ' + options.distBranch);
} else {
rbot.log.verbose('Skipping rollback for ' + options.distBranch + ' for hash "' + pubHash
+ '" (current hash: "' + cph + '")');
}
});
} catch (e) {
var msg = 'Failed to rollback publish branch changes!';
rollCall.error(msg, e);
}
} | javascript | function rollbackPublish() {
try {
chkoutRun(options.distBranch, function() {
var cph = cmd('git rev-parse HEAD');
if (pubHash && pubHash !== cph) {
cmd('git checkout -qf ' + pubHash);
cmd('git commit -q -m "Rollback: ' + tmpltData.distBranchPubMsg + '"');
cmd('git push -f ' + options.repoName + ' ' + options.distBranch);
} else if (!pubHash) {
cmd('git push ' + options.repoName + ' --delete ' + options.distBranch);
} else {
rbot.log.verbose('Skipping rollback for ' + options.distBranch + ' for hash "' + pubHash
+ '" (current hash: "' + cph + '")');
}
});
} catch (e) {
var msg = 'Failed to rollback publish branch changes!';
rollCall.error(msg, e);
}
} | [
"function",
"rollbackPublish",
"(",
")",
"{",
"try",
"{",
"chkoutRun",
"(",
"options",
".",
"distBranch",
",",
"function",
"(",
")",
"{",
"var",
"cph",
"=",
"cmd",
"(",
"'git rev-parse HEAD'",
")",
";",
"if",
"(",
"pubHash",
"&&",
"pubHash",
"!==",
"cph",
")",
"{",
"cmd",
"(",
"'git checkout -qf '",
"+",
"pubHash",
")",
";",
"cmd",
"(",
"'git commit -q -m \"Rollback: '",
"+",
"tmpltData",
".",
"distBranchPubMsg",
"+",
"'\"'",
")",
";",
"cmd",
"(",
"'git push -f '",
"+",
"options",
".",
"repoName",
"+",
"' '",
"+",
"options",
".",
"distBranch",
")",
";",
"}",
"else",
"if",
"(",
"!",
"pubHash",
")",
"{",
"cmd",
"(",
"'git push '",
"+",
"options",
".",
"repoName",
"+",
"' --delete '",
"+",
"options",
".",
"distBranch",
")",
";",
"}",
"else",
"{",
"rbot",
".",
"log",
".",
"verbose",
"(",
"'Skipping rollback for '",
"+",
"options",
".",
"distBranch",
"+",
"' for hash \"'",
"+",
"pubHash",
"+",
"'\" (current hash: \"'",
"+",
"cph",
"+",
"'\")'",
")",
";",
"}",
"}",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"var",
"msg",
"=",
"'Failed to rollback publish branch changes!'",
";",
"rollCall",
".",
"error",
"(",
"msg",
",",
"e",
")",
";",
"}",
"}"
] | Reverts published branch | [
"Reverts",
"published",
"branch"
] | 1a2ff42796e77f47f9590992c014fee461aad80b | https://github.com/ugate/releasebot/blob/1a2ff42796e77f47f9590992c014fee461aad80b/tasks/release.js#L428-L447 |
57,284 | d-mon-/typeof-- | index.js | getObjectToStringValue | function getObjectToStringValue(value) {
var result = objectToString.call(value);
switch (result) {
case '[object Undefined]':
return '#Undefined';
case '[object Null]':
return '#Null';
case '[object Object]':
return 'Object';
case '[object Function]':
return 'Function';
case '[object String]':
return 'String';
case '[object Number]':
return (value != +value) ? '#NaN' : 'Number';
case '[object Array]':
return 'Array';
case '[object Boolean]':
return 'Boolean';
case '[object RegExp]':
return 'RegExp';
case '[object Symbol]':
return 'Symbol';
case '[object Map]':
return 'Map';
case '[object WeakMap]':
return 'WeakMap';
case '[object Set]':
return 'Set';
case '[object WeakSet]':
return 'WeakSet';
case '[object Int8Array]':
return 'Int8Array';
case '[object Uint8Array]':
return 'Uint8Array';
case '[object Uint8ClampedArray]':
return 'Uint8ClampedArray';
case '[object Int16Array]':
return 'Int16Array';
case '[object Uint16Array]':
return 'Uint16Array';
case '[object Int32Array]':
return 'Int32Array';
case '[object Uint32Array]':
return 'Uint32Array';
case '[object Float32Array]':
return 'Float32Array';
case '[object Float64Array]':
return 'Float64Array';
case '[object ArrayBuffer]':
return 'ArrayBuffer';
case '[object DataView]':
return 'DataView';
case '[object Error]':
return 'Error';
case '[object Arguments]':
return 'Arguments';
case '[object JSON]':
return 'JSON';
case '[object Math]':
return 'Math';
case '[object Date]':
return 'Date';
default: //handle the rest (HTML element, future global objects,...)
return result.slice(8, -1);
}
} | javascript | function getObjectToStringValue(value) {
var result = objectToString.call(value);
switch (result) {
case '[object Undefined]':
return '#Undefined';
case '[object Null]':
return '#Null';
case '[object Object]':
return 'Object';
case '[object Function]':
return 'Function';
case '[object String]':
return 'String';
case '[object Number]':
return (value != +value) ? '#NaN' : 'Number';
case '[object Array]':
return 'Array';
case '[object Boolean]':
return 'Boolean';
case '[object RegExp]':
return 'RegExp';
case '[object Symbol]':
return 'Symbol';
case '[object Map]':
return 'Map';
case '[object WeakMap]':
return 'WeakMap';
case '[object Set]':
return 'Set';
case '[object WeakSet]':
return 'WeakSet';
case '[object Int8Array]':
return 'Int8Array';
case '[object Uint8Array]':
return 'Uint8Array';
case '[object Uint8ClampedArray]':
return 'Uint8ClampedArray';
case '[object Int16Array]':
return 'Int16Array';
case '[object Uint16Array]':
return 'Uint16Array';
case '[object Int32Array]':
return 'Int32Array';
case '[object Uint32Array]':
return 'Uint32Array';
case '[object Float32Array]':
return 'Float32Array';
case '[object Float64Array]':
return 'Float64Array';
case '[object ArrayBuffer]':
return 'ArrayBuffer';
case '[object DataView]':
return 'DataView';
case '[object Error]':
return 'Error';
case '[object Arguments]':
return 'Arguments';
case '[object JSON]':
return 'JSON';
case '[object Math]':
return 'Math';
case '[object Date]':
return 'Date';
default: //handle the rest (HTML element, future global objects,...)
return result.slice(8, -1);
}
} | [
"function",
"getObjectToStringValue",
"(",
"value",
")",
"{",
"var",
"result",
"=",
"objectToString",
".",
"call",
"(",
"value",
")",
";",
"switch",
"(",
"result",
")",
"{",
"case",
"'[object Undefined]'",
":",
"return",
"'#Undefined'",
";",
"case",
"'[object Null]'",
":",
"return",
"'#Null'",
";",
"case",
"'[object Object]'",
":",
"return",
"'Object'",
";",
"case",
"'[object Function]'",
":",
"return",
"'Function'",
";",
"case",
"'[object String]'",
":",
"return",
"'String'",
";",
"case",
"'[object Number]'",
":",
"return",
"(",
"value",
"!=",
"+",
"value",
")",
"?",
"'#NaN'",
":",
"'Number'",
";",
"case",
"'[object Array]'",
":",
"return",
"'Array'",
";",
"case",
"'[object Boolean]'",
":",
"return",
"'Boolean'",
";",
"case",
"'[object RegExp]'",
":",
"return",
"'RegExp'",
";",
"case",
"'[object Symbol]'",
":",
"return",
"'Symbol'",
";",
"case",
"'[object Map]'",
":",
"return",
"'Map'",
";",
"case",
"'[object WeakMap]'",
":",
"return",
"'WeakMap'",
";",
"case",
"'[object Set]'",
":",
"return",
"'Set'",
";",
"case",
"'[object WeakSet]'",
":",
"return",
"'WeakSet'",
";",
"case",
"'[object Int8Array]'",
":",
"return",
"'Int8Array'",
";",
"case",
"'[object Uint8Array]'",
":",
"return",
"'Uint8Array'",
";",
"case",
"'[object Uint8ClampedArray]'",
":",
"return",
"'Uint8ClampedArray'",
";",
"case",
"'[object Int16Array]'",
":",
"return",
"'Int16Array'",
";",
"case",
"'[object Uint16Array]'",
":",
"return",
"'Uint16Array'",
";",
"case",
"'[object Int32Array]'",
":",
"return",
"'Int32Array'",
";",
"case",
"'[object Uint32Array]'",
":",
"return",
"'Uint32Array'",
";",
"case",
"'[object Float32Array]'",
":",
"return",
"'Float32Array'",
";",
"case",
"'[object Float64Array]'",
":",
"return",
"'Float64Array'",
";",
"case",
"'[object ArrayBuffer]'",
":",
"return",
"'ArrayBuffer'",
";",
"case",
"'[object DataView]'",
":",
"return",
"'DataView'",
";",
"case",
"'[object Error]'",
":",
"return",
"'Error'",
";",
"case",
"'[object Arguments]'",
":",
"return",
"'Arguments'",
";",
"case",
"'[object JSON]'",
":",
"return",
"'JSON'",
";",
"case",
"'[object Math]'",
":",
"return",
"'Math'",
";",
"case",
"'[object Date]'",
":",
"return",
"'Date'",
";",
"default",
":",
"//handle the rest (HTML element, future global objects,...)",
"return",
"result",
".",
"slice",
"(",
"8",
",",
"-",
"1",
")",
";",
"}",
"}"
] | retrieve type of value after calling Object.prototype.toString
@param value
@returns {String} | [
"retrieve",
"type",
"of",
"value",
"after",
"calling",
"Object",
".",
"prototype",
".",
"toString"
] | 9749072fec62b42a0b35dc00f87c6169f5d93855 | https://github.com/d-mon-/typeof--/blob/9749072fec62b42a0b35dc00f87c6169f5d93855/index.js#L27-L93 |
57,285 | d-mon-/typeof-- | index.js | typeOf | function typeOf(value, options) {
if (value === undefined) return '#Undefined';
if (value === null) return '#Null';
if (options !== 'forceObjectToString') {
var constructor = getConstructor(value);
if (constructor !== null) {
var type = getFunctionName(constructor);
if (type === 'Object') {
return getObjectToStringValue(value);
}
return (type === 'Number' && value != +value) ? '#NaN' : type;
}
}
return getObjectToStringValue(value);
} | javascript | function typeOf(value, options) {
if (value === undefined) return '#Undefined';
if (value === null) return '#Null';
if (options !== 'forceObjectToString') {
var constructor = getConstructor(value);
if (constructor !== null) {
var type = getFunctionName(constructor);
if (type === 'Object') {
return getObjectToStringValue(value);
}
return (type === 'Number' && value != +value) ? '#NaN' : type;
}
}
return getObjectToStringValue(value);
} | [
"function",
"typeOf",
"(",
"value",
",",
"options",
")",
"{",
"if",
"(",
"value",
"===",
"undefined",
")",
"return",
"'#Undefined'",
";",
"if",
"(",
"value",
"===",
"null",
")",
"return",
"'#Null'",
";",
"if",
"(",
"options",
"!==",
"'forceObjectToString'",
")",
"{",
"var",
"constructor",
"=",
"getConstructor",
"(",
"value",
")",
";",
"if",
"(",
"constructor",
"!==",
"null",
")",
"{",
"var",
"type",
"=",
"getFunctionName",
"(",
"constructor",
")",
";",
"if",
"(",
"type",
"===",
"'Object'",
")",
"{",
"return",
"getObjectToStringValue",
"(",
"value",
")",
";",
"}",
"return",
"(",
"type",
"===",
"'Number'",
"&&",
"value",
"!=",
"+",
"value",
")",
"?",
"'#NaN'",
":",
"type",
";",
"}",
"}",
"return",
"getObjectToStringValue",
"(",
"value",
")",
";",
"}"
] | return the constructor name if "defined" and "valid" of the value, otherwise return Object.prototype.toString
@param {*} value
@returns {String} | [
"return",
"the",
"constructor",
"name",
"if",
"defined",
"and",
"valid",
"of",
"the",
"value",
"otherwise",
"return",
"Object",
".",
"prototype",
".",
"toString"
] | 9749072fec62b42a0b35dc00f87c6169f5d93855 | https://github.com/d-mon-/typeof--/blob/9749072fec62b42a0b35dc00f87c6169f5d93855/index.js#L100-L114 |
57,286 | gahlotnikhil/bower-component-files | lib/main.js | fetchComponents | function fetchComponents(filter, options) {
console.log('Fetching dependencies...');
var componentList = [];
if (_.isObject(filter) || _.isArray(filter)) {
var dependencies = fetchBowerComponents();
_.each(dependencies, function(dep) {
var bowerObj = getBower(dep);
if (bowerObj) {
var mainFiles = fetchMainFiles(bowerObj);
var componentFiles = [];
_.each(filter, function(destDir, expression) {
var expressionObj = {};
expressionObj[expression] = destDir;
var filteredValues = filterByExpression(mainFiles, expressionObj, options);
Array.prototype.push.apply(componentFiles,
filteredValues);
});
// create Component class and encapsulate Component
// related info in that.
componentList.push(new Component(bowerObj, componentFiles));
console.log(componentFiles.length + ' file(s) found for ' + dep);
}
});
console.log('##### Total dependencie(s) found ' + componentList.length);
}
return componentList;
} | javascript | function fetchComponents(filter, options) {
console.log('Fetching dependencies...');
var componentList = [];
if (_.isObject(filter) || _.isArray(filter)) {
var dependencies = fetchBowerComponents();
_.each(dependencies, function(dep) {
var bowerObj = getBower(dep);
if (bowerObj) {
var mainFiles = fetchMainFiles(bowerObj);
var componentFiles = [];
_.each(filter, function(destDir, expression) {
var expressionObj = {};
expressionObj[expression] = destDir;
var filteredValues = filterByExpression(mainFiles, expressionObj, options);
Array.prototype.push.apply(componentFiles,
filteredValues);
});
// create Component class and encapsulate Component
// related info in that.
componentList.push(new Component(bowerObj, componentFiles));
console.log(componentFiles.length + ' file(s) found for ' + dep);
}
});
console.log('##### Total dependencie(s) found ' + componentList.length);
}
return componentList;
} | [
"function",
"fetchComponents",
"(",
"filter",
",",
"options",
")",
"{",
"console",
".",
"log",
"(",
"'Fetching dependencies...'",
")",
";",
"var",
"componentList",
"=",
"[",
"]",
";",
"if",
"(",
"_",
".",
"isObject",
"(",
"filter",
")",
"||",
"_",
".",
"isArray",
"(",
"filter",
")",
")",
"{",
"var",
"dependencies",
"=",
"fetchBowerComponents",
"(",
")",
";",
"_",
".",
"each",
"(",
"dependencies",
",",
"function",
"(",
"dep",
")",
"{",
"var",
"bowerObj",
"=",
"getBower",
"(",
"dep",
")",
";",
"if",
"(",
"bowerObj",
")",
"{",
"var",
"mainFiles",
"=",
"fetchMainFiles",
"(",
"bowerObj",
")",
";",
"var",
"componentFiles",
"=",
"[",
"]",
";",
"_",
".",
"each",
"(",
"filter",
",",
"function",
"(",
"destDir",
",",
"expression",
")",
"{",
"var",
"expressionObj",
"=",
"{",
"}",
";",
"expressionObj",
"[",
"expression",
"]",
"=",
"destDir",
";",
"var",
"filteredValues",
"=",
"filterByExpression",
"(",
"mainFiles",
",",
"expressionObj",
",",
"options",
")",
";",
"Array",
".",
"prototype",
".",
"push",
".",
"apply",
"(",
"componentFiles",
",",
"filteredValues",
")",
";",
"}",
")",
";",
"// create Component class and encapsulate Component",
"// related info in that.",
"componentList",
".",
"push",
"(",
"new",
"Component",
"(",
"bowerObj",
",",
"componentFiles",
")",
")",
";",
"console",
".",
"log",
"(",
"componentFiles",
".",
"length",
"+",
"' file(s) found for '",
"+",
"dep",
")",
";",
"}",
"}",
")",
";",
"console",
".",
"log",
"(",
"'##### Total dependencie(s) found '",
"+",
"componentList",
".",
"length",
")",
";",
"}",
"return",
"componentList",
";",
"}"
] | Get components from bower.json
@param {Object}/{Array} filter
@param {Object} options
@return {Array<Component>} List of components | [
"Get",
"components",
"from",
"bower",
".",
"json"
] | f57111e2718517d2c86995975be0d862dc83c7bd | https://github.com/gahlotnikhil/bower-component-files/blob/f57111e2718517d2c86995975be0d862dc83c7bd/lib/main.js#L188-L223 |
57,287 | gahlotnikhil/bower-component-files | lib/main.js | fetchComponent | function fetchComponent(compName, filter, options) {
var componentFiles = [];
_.each(filter, function(destDir, expression) {
var fileInfo = path.parse(path.resolve(BOWER_DIRECTORY, compName, expression));
var sourceDir = fileInfo.dir;
var dirContent = fs.readdirSync(sourceDir);
var expressionObj = {};
expressionObj[expression] = destDir;
dirContent = dirContent.map(function(file) {
return path.resolve(BOWER_DIRECTORY, compName, file);
});
Array.prototype.push.apply(componentFiles,
filterByExpression(dirContent, expressionObj, options));
});
console.log(componentFiles.length + ' file(s) found for ' + compName);
var bowerObj = getBower(compName);
return new Component(bowerObj, componentFiles);
} | javascript | function fetchComponent(compName, filter, options) {
var componentFiles = [];
_.each(filter, function(destDir, expression) {
var fileInfo = path.parse(path.resolve(BOWER_DIRECTORY, compName, expression));
var sourceDir = fileInfo.dir;
var dirContent = fs.readdirSync(sourceDir);
var expressionObj = {};
expressionObj[expression] = destDir;
dirContent = dirContent.map(function(file) {
return path.resolve(BOWER_DIRECTORY, compName, file);
});
Array.prototype.push.apply(componentFiles,
filterByExpression(dirContent, expressionObj, options));
});
console.log(componentFiles.length + ' file(s) found for ' + compName);
var bowerObj = getBower(compName);
return new Component(bowerObj, componentFiles);
} | [
"function",
"fetchComponent",
"(",
"compName",
",",
"filter",
",",
"options",
")",
"{",
"var",
"componentFiles",
"=",
"[",
"]",
";",
"_",
".",
"each",
"(",
"filter",
",",
"function",
"(",
"destDir",
",",
"expression",
")",
"{",
"var",
"fileInfo",
"=",
"path",
".",
"parse",
"(",
"path",
".",
"resolve",
"(",
"BOWER_DIRECTORY",
",",
"compName",
",",
"expression",
")",
")",
";",
"var",
"sourceDir",
"=",
"fileInfo",
".",
"dir",
";",
"var",
"dirContent",
"=",
"fs",
".",
"readdirSync",
"(",
"sourceDir",
")",
";",
"var",
"expressionObj",
"=",
"{",
"}",
";",
"expressionObj",
"[",
"expression",
"]",
"=",
"destDir",
";",
"dirContent",
"=",
"dirContent",
".",
"map",
"(",
"function",
"(",
"file",
")",
"{",
"return",
"path",
".",
"resolve",
"(",
"BOWER_DIRECTORY",
",",
"compName",
",",
"file",
")",
";",
"}",
")",
";",
"Array",
".",
"prototype",
".",
"push",
".",
"apply",
"(",
"componentFiles",
",",
"filterByExpression",
"(",
"dirContent",
",",
"expressionObj",
",",
"options",
")",
")",
";",
"}",
")",
";",
"console",
".",
"log",
"(",
"componentFiles",
".",
"length",
"+",
"' file(s) found for '",
"+",
"compName",
")",
";",
"var",
"bowerObj",
"=",
"getBower",
"(",
"compName",
")",
";",
"return",
"new",
"Component",
"(",
"bowerObj",
",",
"componentFiles",
")",
";",
"}"
] | Constructs a Component object
@param {String} compName
@param {Object} filter
@param {Object} options
@return {Component} | [
"Constructs",
"a",
"Component",
"object"
] | f57111e2718517d2c86995975be0d862dc83c7bd | https://github.com/gahlotnikhil/bower-component-files/blob/f57111e2718517d2c86995975be0d862dc83c7bd/lib/main.js#L232-L253 |
57,288 | MiguelCastillo/dis-isa | src/index.js | typeName | function typeName(item) {
if (isNull(item)) {
return "null";
}
else if (isUndefined(item)) {
return "undefined";
}
return /\[.+ ([^\]]+)/.exec(toString(item))[1].toLowerCase();
} | javascript | function typeName(item) {
if (isNull(item)) {
return "null";
}
else if (isUndefined(item)) {
return "undefined";
}
return /\[.+ ([^\]]+)/.exec(toString(item))[1].toLowerCase();
} | [
"function",
"typeName",
"(",
"item",
")",
"{",
"if",
"(",
"isNull",
"(",
"item",
")",
")",
"{",
"return",
"\"null\"",
";",
"}",
"else",
"if",
"(",
"isUndefined",
"(",
"item",
")",
")",
"{",
"return",
"\"undefined\"",
";",
"}",
"return",
"/",
"\\[.+ ([^\\]]+)",
"/",
".",
"exec",
"(",
"toString",
"(",
"item",
")",
")",
"[",
"1",
"]",
".",
"toLowerCase",
"(",
")",
";",
"}"
] | Extract the type name. This uses Object.prototype.toString
to get the type name.
@param {*} item - Item to get the type for
@returns {string} type of the object | [
"Extract",
"the",
"type",
"name",
".",
"This",
"uses",
"Object",
".",
"prototype",
".",
"toString",
"to",
"get",
"the",
"type",
"name",
"."
] | 11ed2ba864ad8c50b11ce025d345242dd62e4f65 | https://github.com/MiguelCastillo/dis-isa/blob/11ed2ba864ad8c50b11ce025d345242dd62e4f65/src/index.js#L148-L157 |
57,289 | edinella/ploud | public/audiojs/audio.js | function(wrapper, audio) {
if (!audio.settings.createPlayer) return;
var player = audio.settings.createPlayer,
playPause = getByClass(player.playPauseClass, wrapper),
scrubber = getByClass(player.scrubberClass, wrapper),
leftPos = function(elem) {
var curleft = 0;
if (elem.offsetParent) {
do { curleft += elem.offsetLeft; } while (elem = elem.offsetParent);
}
return curleft;
};
container[audiojs].events.addListener(playPause, 'click', function(e) {
audio.playPause.apply(audio);
});
container[audiojs].events.addListener(scrubber, 'click', function(e) {
var relativeLeft = e.clientX - leftPos(this);
audio.skipTo(relativeLeft / scrubber.offsetWidth);
});
// _If flash is being used, then the following handlers don't need to be registered._
if (audio.settings.useFlash) return;
// Start tracking the load progress of the track.
container[audiojs].events.trackLoadProgress(audio);
container[audiojs].events.addListener(audio.element, 'timeupdate', function(e) {
audio.updatePlayhead.apply(audio);
});
container[audiojs].events.addListener(audio.element, 'ended', function(e) {
audio.trackEnded.apply(audio);
});
container[audiojs].events.addListener(audio.source, 'error', function(e) {
// on error, cancel any load timers that are running.
clearInterval(audio.readyTimer);
clearInterval(audio.loadTimer);
audio.settings.loadError.apply(audio);
});
} | javascript | function(wrapper, audio) {
if (!audio.settings.createPlayer) return;
var player = audio.settings.createPlayer,
playPause = getByClass(player.playPauseClass, wrapper),
scrubber = getByClass(player.scrubberClass, wrapper),
leftPos = function(elem) {
var curleft = 0;
if (elem.offsetParent) {
do { curleft += elem.offsetLeft; } while (elem = elem.offsetParent);
}
return curleft;
};
container[audiojs].events.addListener(playPause, 'click', function(e) {
audio.playPause.apply(audio);
});
container[audiojs].events.addListener(scrubber, 'click', function(e) {
var relativeLeft = e.clientX - leftPos(this);
audio.skipTo(relativeLeft / scrubber.offsetWidth);
});
// _If flash is being used, then the following handlers don't need to be registered._
if (audio.settings.useFlash) return;
// Start tracking the load progress of the track.
container[audiojs].events.trackLoadProgress(audio);
container[audiojs].events.addListener(audio.element, 'timeupdate', function(e) {
audio.updatePlayhead.apply(audio);
});
container[audiojs].events.addListener(audio.element, 'ended', function(e) {
audio.trackEnded.apply(audio);
});
container[audiojs].events.addListener(audio.source, 'error', function(e) {
// on error, cancel any load timers that are running.
clearInterval(audio.readyTimer);
clearInterval(audio.loadTimer);
audio.settings.loadError.apply(audio);
});
} | [
"function",
"(",
"wrapper",
",",
"audio",
")",
"{",
"if",
"(",
"!",
"audio",
".",
"settings",
".",
"createPlayer",
")",
"return",
";",
"var",
"player",
"=",
"audio",
".",
"settings",
".",
"createPlayer",
",",
"playPause",
"=",
"getByClass",
"(",
"player",
".",
"playPauseClass",
",",
"wrapper",
")",
",",
"scrubber",
"=",
"getByClass",
"(",
"player",
".",
"scrubberClass",
",",
"wrapper",
")",
",",
"leftPos",
"=",
"function",
"(",
"elem",
")",
"{",
"var",
"curleft",
"=",
"0",
";",
"if",
"(",
"elem",
".",
"offsetParent",
")",
"{",
"do",
"{",
"curleft",
"+=",
"elem",
".",
"offsetLeft",
";",
"}",
"while",
"(",
"elem",
"=",
"elem",
".",
"offsetParent",
")",
";",
"}",
"return",
"curleft",
";",
"}",
";",
"container",
"[",
"audiojs",
"]",
".",
"events",
".",
"addListener",
"(",
"playPause",
",",
"'click'",
",",
"function",
"(",
"e",
")",
"{",
"audio",
".",
"playPause",
".",
"apply",
"(",
"audio",
")",
";",
"}",
")",
";",
"container",
"[",
"audiojs",
"]",
".",
"events",
".",
"addListener",
"(",
"scrubber",
",",
"'click'",
",",
"function",
"(",
"e",
")",
"{",
"var",
"relativeLeft",
"=",
"e",
".",
"clientX",
"-",
"leftPos",
"(",
"this",
")",
";",
"audio",
".",
"skipTo",
"(",
"relativeLeft",
"/",
"scrubber",
".",
"offsetWidth",
")",
";",
"}",
")",
";",
"// _If flash is being used, then the following handlers don't need to be registered._",
"if",
"(",
"audio",
".",
"settings",
".",
"useFlash",
")",
"return",
";",
"// Start tracking the load progress of the track.",
"container",
"[",
"audiojs",
"]",
".",
"events",
".",
"trackLoadProgress",
"(",
"audio",
")",
";",
"container",
"[",
"audiojs",
"]",
".",
"events",
".",
"addListener",
"(",
"audio",
".",
"element",
",",
"'timeupdate'",
",",
"function",
"(",
"e",
")",
"{",
"audio",
".",
"updatePlayhead",
".",
"apply",
"(",
"audio",
")",
";",
"}",
")",
";",
"container",
"[",
"audiojs",
"]",
".",
"events",
".",
"addListener",
"(",
"audio",
".",
"element",
",",
"'ended'",
",",
"function",
"(",
"e",
")",
"{",
"audio",
".",
"trackEnded",
".",
"apply",
"(",
"audio",
")",
";",
"}",
")",
";",
"container",
"[",
"audiojs",
"]",
".",
"events",
".",
"addListener",
"(",
"audio",
".",
"source",
",",
"'error'",
",",
"function",
"(",
"e",
")",
"{",
"// on error, cancel any load timers that are running.",
"clearInterval",
"(",
"audio",
".",
"readyTimer",
")",
";",
"clearInterval",
"(",
"audio",
".",
"loadTimer",
")",
";",
"audio",
".",
"settings",
".",
"loadError",
".",
"apply",
"(",
"audio",
")",
";",
"}",
")",
";",
"}"
] | Attaches useful event callbacks to an `audiojs` instance. | [
"Attaches",
"useful",
"event",
"callbacks",
"to",
"an",
"audiojs",
"instance",
"."
] | ccf01fd213482b320a0a804f100eaae007103b6d | https://github.com/edinella/ploud/blob/ccf01fd213482b320a0a804f100eaae007103b6d/public/audiojs/audio.js#L240-L283 |
|
57,290 | cli-kit/cli-property | lib/exec.js | exec | function exec(ptn, source, opts) {
opts = opts || {};
var list = []
, flat = opts.flat = opts.flat !== undefined ? opts.flat : false
, keys = opts.keys = opts.keys !== undefined ? opts.keys : true
, values = opts.values = opts.values !== undefined ? opts.values : false
if(flat) {
source = flatten(source);
}
//console.dir(source);
function match(k, v, p) {
var re = recopy(ptn)
, res = {key: k, value: v, parent: p, match: {key: false, value: false}};
res.match.key = keys && re.test(k);
res.match.value = values && re.test('' + v);
//console.log('matches %s %s %s', matches, re, k);
if(res.match.key || res.match.value) {
res.pattern = ptn;
list.push(res);
}
}
function lookup(source) {
var k, v;
for(k in source) {
v = source[k];
match(k, v, source);
if(!flat && v && typeof v === 'object' && Object.keys(v).length) {
lookup(v);
}
}
}
lookup(source);
return list;
} | javascript | function exec(ptn, source, opts) {
opts = opts || {};
var list = []
, flat = opts.flat = opts.flat !== undefined ? opts.flat : false
, keys = opts.keys = opts.keys !== undefined ? opts.keys : true
, values = opts.values = opts.values !== undefined ? opts.values : false
if(flat) {
source = flatten(source);
}
//console.dir(source);
function match(k, v, p) {
var re = recopy(ptn)
, res = {key: k, value: v, parent: p, match: {key: false, value: false}};
res.match.key = keys && re.test(k);
res.match.value = values && re.test('' + v);
//console.log('matches %s %s %s', matches, re, k);
if(res.match.key || res.match.value) {
res.pattern = ptn;
list.push(res);
}
}
function lookup(source) {
var k, v;
for(k in source) {
v = source[k];
match(k, v, source);
if(!flat && v && typeof v === 'object' && Object.keys(v).length) {
lookup(v);
}
}
}
lookup(source);
return list;
} | [
"function",
"exec",
"(",
"ptn",
",",
"source",
",",
"opts",
")",
"{",
"opts",
"=",
"opts",
"||",
"{",
"}",
";",
"var",
"list",
"=",
"[",
"]",
",",
"flat",
"=",
"opts",
".",
"flat",
"=",
"opts",
".",
"flat",
"!==",
"undefined",
"?",
"opts",
".",
"flat",
":",
"false",
",",
"keys",
"=",
"opts",
".",
"keys",
"=",
"opts",
".",
"keys",
"!==",
"undefined",
"?",
"opts",
".",
"keys",
":",
"true",
",",
"values",
"=",
"opts",
".",
"values",
"=",
"opts",
".",
"values",
"!==",
"undefined",
"?",
"opts",
".",
"values",
":",
"false",
"if",
"(",
"flat",
")",
"{",
"source",
"=",
"flatten",
"(",
"source",
")",
";",
"}",
"//console.dir(source);",
"function",
"match",
"(",
"k",
",",
"v",
",",
"p",
")",
"{",
"var",
"re",
"=",
"recopy",
"(",
"ptn",
")",
",",
"res",
"=",
"{",
"key",
":",
"k",
",",
"value",
":",
"v",
",",
"parent",
":",
"p",
",",
"match",
":",
"{",
"key",
":",
"false",
",",
"value",
":",
"false",
"}",
"}",
";",
"res",
".",
"match",
".",
"key",
"=",
"keys",
"&&",
"re",
".",
"test",
"(",
"k",
")",
";",
"res",
".",
"match",
".",
"value",
"=",
"values",
"&&",
"re",
".",
"test",
"(",
"''",
"+",
"v",
")",
";",
"//console.log('matches %s %s %s', matches, re, k);",
"if",
"(",
"res",
".",
"match",
".",
"key",
"||",
"res",
".",
"match",
".",
"value",
")",
"{",
"res",
".",
"pattern",
"=",
"ptn",
";",
"list",
".",
"push",
"(",
"res",
")",
";",
"}",
"}",
"function",
"lookup",
"(",
"source",
")",
"{",
"var",
"k",
",",
"v",
";",
"for",
"(",
"k",
"in",
"source",
")",
"{",
"v",
"=",
"source",
"[",
"k",
"]",
";",
"match",
"(",
"k",
",",
"v",
",",
"source",
")",
";",
"if",
"(",
"!",
"flat",
"&&",
"v",
"&&",
"typeof",
"v",
"===",
"'object'",
"&&",
"Object",
".",
"keys",
"(",
"v",
")",
".",
"length",
")",
"{",
"lookup",
"(",
"v",
")",
";",
"}",
"}",
"}",
"lookup",
"(",
"source",
")",
";",
"return",
"list",
";",
"}"
] | Execute a regular expression pattern against
an object finding all values that match the pattern.
Returns an array of result object.
@param ptn The regular expression to execute.
@param source The source object to search.
@param opts Processing options.
@param opts.flat Compare against flattened object keys.
@param opts.keys Match against keys.
@param opts.values Match against values. | [
"Execute",
"a",
"regular",
"expression",
"pattern",
"against",
"an",
"object",
"finding",
"all",
"values",
"that",
"match",
"the",
"pattern",
"."
] | de6f727af1f8fc1f613fe42200c5e070aa6b0b21 | https://github.com/cli-kit/cli-property/blob/de6f727af1f8fc1f613fe42200c5e070aa6b0b21/lib/exec.js#L18-L55 |
57,291 | mrjoelkemp/ya | helpers/GruntHelper.js | generateGruntfile | function generateGruntfile (generatedConfig) {
return function(grunt) {
var path = require('path'),
fs = require('fs');
require('load-grunt-tasks')(grunt);
grunt.initConfig(generatedConfig);
grunt.registerTask('default', ['watch']);
// Handle new files with that have a new, supported preprocessor
grunt.event.on('watch', function(action, filepath) {
var ext = path.extname(filepath);
// Ignore directories
if (fs.lstatSync(filepath).isDirectory()) return;
if (action === 'added') {
// This is a special message that's parsed by YA
// to determine if support for an additional preprocessor is necessary
// Note: this allows us to avoid controlling grunt manually within YA
console.log('EXTADDED:' + ext);
// Note: we don't do anything for newly added .js files
// A new js file can't be the root unless it's changed to require
// the current root and saved/changed
} else if (action === 'changed' || action === 'deleted') {
if (ext === '.js') {
// Ignore bundles
if (/.+bundle.js/g.test(filepath)) return;
// Notify YA to recompute the roots and
// generate a configuration
console.log('JSCHANGED:' + filepath);
}
}
});
// For watching entire directories but allowing
// the grunt.event binding to take care of it
grunt.registerTask('noop', function () {});
};
} | javascript | function generateGruntfile (generatedConfig) {
return function(grunt) {
var path = require('path'),
fs = require('fs');
require('load-grunt-tasks')(grunt);
grunt.initConfig(generatedConfig);
grunt.registerTask('default', ['watch']);
// Handle new files with that have a new, supported preprocessor
grunt.event.on('watch', function(action, filepath) {
var ext = path.extname(filepath);
// Ignore directories
if (fs.lstatSync(filepath).isDirectory()) return;
if (action === 'added') {
// This is a special message that's parsed by YA
// to determine if support for an additional preprocessor is necessary
// Note: this allows us to avoid controlling grunt manually within YA
console.log('EXTADDED:' + ext);
// Note: we don't do anything for newly added .js files
// A new js file can't be the root unless it's changed to require
// the current root and saved/changed
} else if (action === 'changed' || action === 'deleted') {
if (ext === '.js') {
// Ignore bundles
if (/.+bundle.js/g.test(filepath)) return;
// Notify YA to recompute the roots and
// generate a configuration
console.log('JSCHANGED:' + filepath);
}
}
});
// For watching entire directories but allowing
// the grunt.event binding to take care of it
grunt.registerTask('noop', function () {});
};
} | [
"function",
"generateGruntfile",
"(",
"generatedConfig",
")",
"{",
"return",
"function",
"(",
"grunt",
")",
"{",
"var",
"path",
"=",
"require",
"(",
"'path'",
")",
",",
"fs",
"=",
"require",
"(",
"'fs'",
")",
";",
"require",
"(",
"'load-grunt-tasks'",
")",
"(",
"grunt",
")",
";",
"grunt",
".",
"initConfig",
"(",
"generatedConfig",
")",
";",
"grunt",
".",
"registerTask",
"(",
"'default'",
",",
"[",
"'watch'",
"]",
")",
";",
"// Handle new files with that have a new, supported preprocessor",
"grunt",
".",
"event",
".",
"on",
"(",
"'watch'",
",",
"function",
"(",
"action",
",",
"filepath",
")",
"{",
"var",
"ext",
"=",
"path",
".",
"extname",
"(",
"filepath",
")",
";",
"// Ignore directories",
"if",
"(",
"fs",
".",
"lstatSync",
"(",
"filepath",
")",
".",
"isDirectory",
"(",
")",
")",
"return",
";",
"if",
"(",
"action",
"===",
"'added'",
")",
"{",
"// This is a special message that's parsed by YA",
"// to determine if support for an additional preprocessor is necessary",
"// Note: this allows us to avoid controlling grunt manually within YA",
"console",
".",
"log",
"(",
"'EXTADDED:'",
"+",
"ext",
")",
";",
"// Note: we don't do anything for newly added .js files",
"// A new js file can't be the root unless it's changed to require",
"// the current root and saved/changed",
"}",
"else",
"if",
"(",
"action",
"===",
"'changed'",
"||",
"action",
"===",
"'deleted'",
")",
"{",
"if",
"(",
"ext",
"===",
"'.js'",
")",
"{",
"// Ignore bundles",
"if",
"(",
"/",
".+bundle.js",
"/",
"g",
".",
"test",
"(",
"filepath",
")",
")",
"return",
";",
"// Notify YA to recompute the roots and",
"// generate a configuration",
"console",
".",
"log",
"(",
"'JSCHANGED:'",
"+",
"filepath",
")",
";",
"}",
"}",
"}",
")",
";",
"// For watching entire directories but allowing",
"// the grunt.event binding to take care of it",
"grunt",
".",
"registerTask",
"(",
"'noop'",
",",
"function",
"(",
")",
"{",
"}",
")",
";",
"}",
";",
"}"
] | Helper that returns a function whose body represents a gruntfile definition | [
"Helper",
"that",
"returns",
"a",
"function",
"whose",
"body",
"represents",
"a",
"gruntfile",
"definition"
] | 6cb44f31902daaed32b2d72168b15eebfb7fbfbb | https://github.com/mrjoelkemp/ya/blob/6cb44f31902daaed32b2d72168b15eebfb7fbfbb/helpers/GruntHelper.js#L167-L210 |
57,292 | mrjoelkemp/ya | helpers/GruntHelper.js | getMatches | function getMatches(source, pattern) {
var matches = [],
match;
// Grab all added extensions
while (match = pattern.exec(source)) {
matches.push(match[2]);
}
return matches;
} | javascript | function getMatches(source, pattern) {
var matches = [],
match;
// Grab all added extensions
while (match = pattern.exec(source)) {
matches.push(match[2]);
}
return matches;
} | [
"function",
"getMatches",
"(",
"source",
",",
"pattern",
")",
"{",
"var",
"matches",
"=",
"[",
"]",
",",
"match",
";",
"// Grab all added extensions",
"while",
"(",
"match",
"=",
"pattern",
".",
"exec",
"(",
"source",
")",
")",
"{",
"matches",
".",
"push",
"(",
"match",
"[",
"2",
"]",
")",
";",
"}",
"return",
"matches",
";",
"}"
] | Returns a list of pattern matches against the source string | [
"Returns",
"a",
"list",
"of",
"pattern",
"matches",
"against",
"the",
"source",
"string"
] | 6cb44f31902daaed32b2d72168b15eebfb7fbfbb | https://github.com/mrjoelkemp/ya/blob/6cb44f31902daaed32b2d72168b15eebfb7fbfbb/helpers/GruntHelper.js#L308-L318 |
57,293 | t9md/atom-outlet | lib/index.js | link | function link (outlet, editor) {
if (getLocationForItem(editor) === 'center') {
outlet.element.setAttribute('outlet-linked-editor-id', editor.id)
} else {
outlet.element.removeAttribute('outlet-linked-editor-id')
}
} | javascript | function link (outlet, editor) {
if (getLocationForItem(editor) === 'center') {
outlet.element.setAttribute('outlet-linked-editor-id', editor.id)
} else {
outlet.element.removeAttribute('outlet-linked-editor-id')
}
} | [
"function",
"link",
"(",
"outlet",
",",
"editor",
")",
"{",
"if",
"(",
"getLocationForItem",
"(",
"editor",
")",
"===",
"'center'",
")",
"{",
"outlet",
".",
"element",
".",
"setAttribute",
"(",
"'outlet-linked-editor-id'",
",",
"editor",
".",
"id",
")",
"}",
"else",
"{",
"outlet",
".",
"element",
".",
"removeAttribute",
"(",
"'outlet-linked-editor-id'",
")",
"}",
"}"
] | When outlet was created from an editor. Call this function to link outlet to that editor. Linked editor will not be hidden while outlet relocation. Only editor in center container can be linked. | [
"When",
"outlet",
"was",
"created",
"from",
"an",
"editor",
".",
"Call",
"this",
"function",
"to",
"link",
"outlet",
"to",
"that",
"editor",
".",
"Linked",
"editor",
"will",
"not",
"be",
"hidden",
"while",
"outlet",
"relocation",
".",
"Only",
"editor",
"in",
"center",
"container",
"can",
"be",
"linked",
"."
] | 6098828c54dbb0b64b14e89c449a04ea1ed069b1 | https://github.com/t9md/atom-outlet/blob/6098828c54dbb0b64b14e89c449a04ea1ed069b1/lib/index.js#L198-L204 |
57,294 | zappan/connect-spa-request-filter | lib/requestFilter.js | _isVoidFilterRoute | function _isVoidFilterRoute(req) {
var reqPathRegex = new RegExp(['^', req.path.replace(/\/$/, ''), '$'].join(''), 'i')
, voidRoute
, i;
for (i=0; i<voidFilterRoutes.length; i++) {
if (reqPathRegex.test(voidFilterRoutes[i])) { return true; }
}
return false;
} | javascript | function _isVoidFilterRoute(req) {
var reqPathRegex = new RegExp(['^', req.path.replace(/\/$/, ''), '$'].join(''), 'i')
, voidRoute
, i;
for (i=0; i<voidFilterRoutes.length; i++) {
if (reqPathRegex.test(voidFilterRoutes[i])) { return true; }
}
return false;
} | [
"function",
"_isVoidFilterRoute",
"(",
"req",
")",
"{",
"var",
"reqPathRegex",
"=",
"new",
"RegExp",
"(",
"[",
"'^'",
",",
"req",
".",
"path",
".",
"replace",
"(",
"/",
"\\/$",
"/",
",",
"''",
")",
",",
"'$'",
"]",
".",
"join",
"(",
"''",
")",
",",
"'i'",
")",
",",
"voidRoute",
",",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"voidFilterRoutes",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"reqPathRegex",
".",
"test",
"(",
"voidFilterRoutes",
"[",
"i",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Checks whether the route is in the list of routes to void filtering on
@param {http.ServerRequest} req Node.js HTTP Server request
@return true if request headers match 'application/json', false otherwise
@return {Boolean} true if route (path) in the list of routes to void filtering on, false otherwise
@author Tomislav Capan | [
"Checks",
"whether",
"the",
"route",
"is",
"in",
"the",
"list",
"of",
"routes",
"to",
"void",
"filtering",
"on"
] | 52a497dd8c4b315410322d698089a43ccdb938bc | https://github.com/zappan/connect-spa-request-filter/blob/52a497dd8c4b315410322d698089a43ccdb938bc/lib/requestFilter.js#L28-L37 |
57,295 | zappan/connect-spa-request-filter | lib/requestFilter.js | _renderAppShell | function _renderAppShell(res) {
res.render(appShell.view, {
layout : appShell.layout
, appTitle : appConfig.appTitle
, appConfig : JSON.stringify(appConfig)
, appData : JSON.stringify(appData)
});
} | javascript | function _renderAppShell(res) {
res.render(appShell.view, {
layout : appShell.layout
, appTitle : appConfig.appTitle
, appConfig : JSON.stringify(appConfig)
, appData : JSON.stringify(appData)
});
} | [
"function",
"_renderAppShell",
"(",
"res",
")",
"{",
"res",
".",
"render",
"(",
"appShell",
".",
"view",
",",
"{",
"layout",
":",
"appShell",
".",
"layout",
",",
"appTitle",
":",
"appConfig",
".",
"appTitle",
",",
"appConfig",
":",
"JSON",
".",
"stringify",
"(",
"appConfig",
")",
",",
"appData",
":",
"JSON",
".",
"stringify",
"(",
"appData",
")",
"}",
")",
";",
"}"
] | Default method to render app shell, could be overriden through init options
@return _void_
@author Tomislav Capan | [
"Default",
"method",
"to",
"render",
"app",
"shell",
"could",
"be",
"overriden",
"through",
"init",
"options"
] | 52a497dd8c4b315410322d698089a43ccdb938bc | https://github.com/zappan/connect-spa-request-filter/blob/52a497dd8c4b315410322d698089a43ccdb938bc/lib/requestFilter.js#L45-L52 |
57,296 | zappan/connect-spa-request-filter | lib/requestFilter.js | configure | function configure(options) {
options = options || {};
var assertErrTemplate = '[connect-spa-request-filter middleware :: configure()] Fatal error! Missing parameter:';
assert(options.appConfig, util.format(assertErrTemplate, 'options.appConfig'));
assert(options.appConfig.appTitle, util.format(assertErrTemplate, 'options.appConfig.appTitle'));
appConfig = options.appConfig;
appData = options.appData || {};
appShell = options.appShell || {};
voidFilterRoutes = options.voidFilterRoutes || [];
appShell.view = appShell.view || 'index';
appShell.layout = appShell.layout || false;
// Publicly expose the module interface after initialized
return requestFilter;
} | javascript | function configure(options) {
options = options || {};
var assertErrTemplate = '[connect-spa-request-filter middleware :: configure()] Fatal error! Missing parameter:';
assert(options.appConfig, util.format(assertErrTemplate, 'options.appConfig'));
assert(options.appConfig.appTitle, util.format(assertErrTemplate, 'options.appConfig.appTitle'));
appConfig = options.appConfig;
appData = options.appData || {};
appShell = options.appShell || {};
voidFilterRoutes = options.voidFilterRoutes || [];
appShell.view = appShell.view || 'index';
appShell.layout = appShell.layout || false;
// Publicly expose the module interface after initialized
return requestFilter;
} | [
"function",
"configure",
"(",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"var",
"assertErrTemplate",
"=",
"'[connect-spa-request-filter middleware :: configure()] Fatal error! Missing parameter:'",
";",
"assert",
"(",
"options",
".",
"appConfig",
",",
"util",
".",
"format",
"(",
"assertErrTemplate",
",",
"'options.appConfig'",
")",
")",
";",
"assert",
"(",
"options",
".",
"appConfig",
".",
"appTitle",
",",
"util",
".",
"format",
"(",
"assertErrTemplate",
",",
"'options.appConfig.appTitle'",
")",
")",
";",
"appConfig",
"=",
"options",
".",
"appConfig",
";",
"appData",
"=",
"options",
".",
"appData",
"||",
"{",
"}",
";",
"appShell",
"=",
"options",
".",
"appShell",
"||",
"{",
"}",
";",
"voidFilterRoutes",
"=",
"options",
".",
"voidFilterRoutes",
"||",
"[",
"]",
";",
"appShell",
".",
"view",
"=",
"appShell",
".",
"view",
"||",
"'index'",
";",
"appShell",
".",
"layout",
"=",
"appShell",
".",
"layout",
"||",
"false",
";",
"// Publicly expose the module interface after initialized",
"return",
"requestFilter",
";",
"}"
] | Initializes the middleware by setting the required options for it to run
and exposing the filtering interface
@param {object} options Options object containing the following:
* app: A reference to the Express app object
* voidFilterRoutes: an array of routes (paths) to void filtering on
@return {function} The requestFilter function doing the filtering
@author Tomislav Capan | [
"Initializes",
"the",
"middleware",
"by",
"setting",
"the",
"required",
"options",
"for",
"it",
"to",
"run",
"and",
"exposing",
"the",
"filtering",
"interface"
] | 52a497dd8c4b315410322d698089a43ccdb938bc | https://github.com/zappan/connect-spa-request-filter/blob/52a497dd8c4b315410322d698089a43ccdb938bc/lib/requestFilter.js#L80-L98 |
57,297 | crysalead-js/expand-flatten | expand.js | expand | function expand(object, options) {
var expanded = {};
var options = options || {};
var separator = options.separator || '.';
var affix = options.affix ? separator + options.affix + separator : separator;
for (var path in object) {
var value = object[path];
var pointer = expanded;
if (path.indexOf('[') >= 0) {
path = path.replace(/\[/g, '[.').replace(/]/g, '');
}
var parts = path.split(separator).join(affix).split('.');
while (parts.length - 1) {
var key = parts.shift();
if (key.slice(-1) === '[') {
key = key.slice(0, - 1);
pointer[key] = Array.isArray(pointer[key]) ? pointer[key] : [];
} else {
pointer[key] = (pointer[key] !== null && typeof pointer[key] === 'object' && pointer[key].constructor === Object) ? pointer[key] : {};
}
pointer = pointer[key];
}
pointer[parts.shift()] = value;
}
return expanded;
} | javascript | function expand(object, options) {
var expanded = {};
var options = options || {};
var separator = options.separator || '.';
var affix = options.affix ? separator + options.affix + separator : separator;
for (var path in object) {
var value = object[path];
var pointer = expanded;
if (path.indexOf('[') >= 0) {
path = path.replace(/\[/g, '[.').replace(/]/g, '');
}
var parts = path.split(separator).join(affix).split('.');
while (parts.length - 1) {
var key = parts.shift();
if (key.slice(-1) === '[') {
key = key.slice(0, - 1);
pointer[key] = Array.isArray(pointer[key]) ? pointer[key] : [];
} else {
pointer[key] = (pointer[key] !== null && typeof pointer[key] === 'object' && pointer[key].constructor === Object) ? pointer[key] : {};
}
pointer = pointer[key];
}
pointer[parts.shift()] = value;
}
return expanded;
} | [
"function",
"expand",
"(",
"object",
",",
"options",
")",
"{",
"var",
"expanded",
"=",
"{",
"}",
";",
"var",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"var",
"separator",
"=",
"options",
".",
"separator",
"||",
"'.'",
";",
"var",
"affix",
"=",
"options",
".",
"affix",
"?",
"separator",
"+",
"options",
".",
"affix",
"+",
"separator",
":",
"separator",
";",
"for",
"(",
"var",
"path",
"in",
"object",
")",
"{",
"var",
"value",
"=",
"object",
"[",
"path",
"]",
";",
"var",
"pointer",
"=",
"expanded",
";",
"if",
"(",
"path",
".",
"indexOf",
"(",
"'['",
")",
">=",
"0",
")",
"{",
"path",
"=",
"path",
".",
"replace",
"(",
"/",
"\\[",
"/",
"g",
",",
"'[.'",
")",
".",
"replace",
"(",
"/",
"]",
"/",
"g",
",",
"''",
")",
";",
"}",
"var",
"parts",
"=",
"path",
".",
"split",
"(",
"separator",
")",
".",
"join",
"(",
"affix",
")",
".",
"split",
"(",
"'.'",
")",
";",
"while",
"(",
"parts",
".",
"length",
"-",
"1",
")",
"{",
"var",
"key",
"=",
"parts",
".",
"shift",
"(",
")",
";",
"if",
"(",
"key",
".",
"slice",
"(",
"-",
"1",
")",
"===",
"'['",
")",
"{",
"key",
"=",
"key",
".",
"slice",
"(",
"0",
",",
"-",
"1",
")",
";",
"pointer",
"[",
"key",
"]",
"=",
"Array",
".",
"isArray",
"(",
"pointer",
"[",
"key",
"]",
")",
"?",
"pointer",
"[",
"key",
"]",
":",
"[",
"]",
";",
"}",
"else",
"{",
"pointer",
"[",
"key",
"]",
"=",
"(",
"pointer",
"[",
"key",
"]",
"!==",
"null",
"&&",
"typeof",
"pointer",
"[",
"key",
"]",
"===",
"'object'",
"&&",
"pointer",
"[",
"key",
"]",
".",
"constructor",
"===",
"Object",
")",
"?",
"pointer",
"[",
"key",
"]",
":",
"{",
"}",
";",
"}",
"pointer",
"=",
"pointer",
"[",
"key",
"]",
";",
"}",
"pointer",
"[",
"parts",
".",
"shift",
"(",
")",
"]",
"=",
"value",
";",
"}",
"return",
"expanded",
";",
"}"
] | Expands a "hash" object an object.
@param Object object The object to expand.
@param Object options The options.
@return Object The expanded object. | [
"Expands",
"a",
"hash",
"object",
"an",
"object",
"."
] | dd298e70509a11219603f7eccecd2b0d963da904 | https://github.com/crysalead-js/expand-flatten/blob/dd298e70509a11219603f7eccecd2b0d963da904/expand.js#L8-L36 |
57,298 | melvincarvalho/rdf-shell | lib/touch.js | touch | function touch(argv, callback) {
util.patch(argv[2], 'DELETE {} .', function(err, val) {
if (!err) {
console.log('touch to : ' + argv[2]);
}
});
} | javascript | function touch(argv, callback) {
util.patch(argv[2], 'DELETE {} .', function(err, val) {
if (!err) {
console.log('touch to : ' + argv[2]);
}
});
} | [
"function",
"touch",
"(",
"argv",
",",
"callback",
")",
"{",
"util",
".",
"patch",
"(",
"argv",
"[",
"2",
"]",
",",
"'DELETE {} .'",
",",
"function",
"(",
"err",
",",
"val",
")",
"{",
"if",
"(",
"!",
"err",
")",
"{",
"console",
".",
"log",
"(",
"'touch to : '",
"+",
"argv",
"[",
"2",
"]",
")",
";",
"}",
"}",
")",
";",
"}"
] | touch gets list of files for a given container
@param {String} argv[2] url
@param {String} argv[3] data
@callback {bin~cb} callback | [
"touch",
"gets",
"list",
"of",
"files",
"for",
"a",
"given",
"container"
] | bf2015f6f333855e69a18ce3ec9e917bbddfb425 | https://github.com/melvincarvalho/rdf-shell/blob/bf2015f6f333855e69a18ce3ec9e917bbddfb425/lib/touch.js#L13-L19 |
57,299 | tomek-f/auto-elems-from-dom | autoElemsFromDOM.js | getDocumentFragmentFromString | function getDocumentFragmentFromString(html) {
// return document.createRange().createContextualFragment(html); // FU safari
var range = document.createRange();
range.selectNode(document.body);// safari
return range.createContextualFragment(html);
} | javascript | function getDocumentFragmentFromString(html) {
// return document.createRange().createContextualFragment(html); // FU safari
var range = document.createRange();
range.selectNode(document.body);// safari
return range.createContextualFragment(html);
} | [
"function",
"getDocumentFragmentFromString",
"(",
"html",
")",
"{",
"// return document.createRange().createContextualFragment(html); // FU safari",
"var",
"range",
"=",
"document",
".",
"createRange",
"(",
")",
";",
"range",
".",
"selectNode",
"(",
"document",
".",
"body",
")",
";",
"// safari",
"return",
"range",
".",
"createContextualFragment",
"(",
"html",
")",
";",
"}"
] | Array.from without additional div | [
"Array",
".",
"from",
"without",
"additional",
"div"
] | 1852d0a3d2d3b5ecb5d0f66c8fbf753e71e699af | https://github.com/tomek-f/auto-elems-from-dom/blob/1852d0a3d2d3b5ecb5d0f66c8fbf753e71e699af/autoElemsFromDOM.js#L4-L9 |
Subsets and Splits