repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
sequence | docstring
stringlengths 4
11.8k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 86
226
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
Dashron/roads | src/middleware/parseBody.js | parseBody | function parseBody (body, content_type) {
if (typeof(body) === "object" || Array.isArray(body) || !body) {
// no need to parse if it's already an object
return body;
}
let parsed_content_type = content_type_module.parse(content_type);
if (parsed_content_type.type === 'application/json') {
// parse json
return JSON.parse(body);
} else if (parsed_content_type.type === 'application/x-www-form-urlencoded') {
// parse form encoded
return qs_module.parse(body);
} else {
// maybe it's supposed to be literal
return body;
}
} | javascript | function parseBody (body, content_type) {
if (typeof(body) === "object" || Array.isArray(body) || !body) {
// no need to parse if it's already an object
return body;
}
let parsed_content_type = content_type_module.parse(content_type);
if (parsed_content_type.type === 'application/json') {
// parse json
return JSON.parse(body);
} else if (parsed_content_type.type === 'application/x-www-form-urlencoded') {
// parse form encoded
return qs_module.parse(body);
} else {
// maybe it's supposed to be literal
return body;
}
} | [
"function",
"parseBody",
"(",
"body",
",",
"content_type",
")",
"{",
"if",
"(",
"typeof",
"(",
"body",
")",
"===",
"\"object\"",
"||",
"Array",
".",
"isArray",
"(",
"body",
")",
"||",
"!",
"body",
")",
"{",
"return",
"body",
";",
"}",
"let",
"parsed_content_type",
"=",
"content_type_module",
".",
"parse",
"(",
"content_type",
")",
";",
"if",
"(",
"parsed_content_type",
".",
"type",
"===",
"'application/json'",
")",
"{",
"return",
"JSON",
".",
"parse",
"(",
"body",
")",
";",
"}",
"else",
"if",
"(",
"parsed_content_type",
".",
"type",
"===",
"'application/x-www-form-urlencoded'",
")",
"{",
"return",
"qs_module",
".",
"parse",
"(",
"body",
")",
";",
"}",
"else",
"{",
"return",
"body",
";",
"}",
"}"
] | Translate the request body into a usable value.
If the content type is application/json this will attempt to parse that json
If application/x-www-form-urlencoded this will attempt to parse it as a query format
Otherwise this will return a string
@param {mixed} body - request body
@param {string} content_type - media type of the body
@returns {(object|string)} parsed body
@todo Actually do something with the parameters, such as charset | [
"Translate",
"the",
"request",
"body",
"into",
"a",
"usable",
"value",
"."
] | c089d79d8181063c7fae00432a79b7a79a7809d3 | https://github.com/Dashron/roads/blob/c089d79d8181063c7fae00432a79b7a79a7809d3/src/middleware/parseBody.js#L25-L43 | train |
Dashron/roads | src/client/build.js | fixExclude | function fixExclude(exclude_list) {
if (!exclude_list) {
exclude_list = [];
}
exclude_list.push(__filename);
exclude_list.push(__dirname + '/../../tests');
exclude_list.push(__dirname + '/../integrations/koa.js');
exclude_list.push(__dirname + '/../integrations/express.js');
exclude_list.push(__dirname + '/../middleware/cors.js');
return exclude_list;
} | javascript | function fixExclude(exclude_list) {
if (!exclude_list) {
exclude_list = [];
}
exclude_list.push(__filename);
exclude_list.push(__dirname + '/../../tests');
exclude_list.push(__dirname + '/../integrations/koa.js');
exclude_list.push(__dirname + '/../integrations/express.js');
exclude_list.push(__dirname + '/../middleware/cors.js');
return exclude_list;
} | [
"function",
"fixExclude",
"(",
"exclude_list",
")",
"{",
"if",
"(",
"!",
"exclude_list",
")",
"{",
"exclude_list",
"=",
"[",
"]",
";",
"}",
"exclude_list",
".",
"push",
"(",
"__filename",
")",
";",
"exclude_list",
".",
"push",
"(",
"__dirname",
"+",
"'/../../tests'",
")",
";",
"exclude_list",
".",
"push",
"(",
"__dirname",
"+",
"'/../integrations/koa.js'",
")",
";",
"exclude_list",
".",
"push",
"(",
"__dirname",
"+",
"'/../integrations/express.js'",
")",
";",
"exclude_list",
".",
"push",
"(",
"__dirname",
"+",
"'/../middleware/cors.js'",
")",
";",
"return",
"exclude_list",
";",
"}"
] | An array of files or node modules to exclude in browserify. Excluded modules will throw an exception
if they are required
@param {Array} exclude_list - Array of file paths or node module names to exclude
@returns {Array} exclude_list with defaults applied | [
"An",
"array",
"of",
"files",
"or",
"node",
"modules",
"to",
"exclude",
"in",
"browserify",
".",
"Excluded",
"modules",
"will",
"throw",
"an",
"exception",
"if",
"they",
"are",
"required"
] | c089d79d8181063c7fae00432a79b7a79a7809d3 | https://github.com/Dashron/roads/blob/c089d79d8181063c7fae00432a79b7a79a7809d3/src/client/build.js#L63-L74 | train |
Dashron/roads | src/client/build.js | fixOptions | function fixOptions (options) {
if (!options) {
options = {};
}
options.use_sourcemaps = options.use_sourcemaps ? true : false;
options.babelify = fixBabelify(options.babelify);
// options.external = fixExternal(options.external);
options.ignore = fixIgnore(options.ignore);
options.exclude = fixExclude(options.exclude);
return options;
} | javascript | function fixOptions (options) {
if (!options) {
options = {};
}
options.use_sourcemaps = options.use_sourcemaps ? true : false;
options.babelify = fixBabelify(options.babelify);
// options.external = fixExternal(options.external);
options.ignore = fixIgnore(options.ignore);
options.exclude = fixExclude(options.exclude);
return options;
} | [
"function",
"fixOptions",
"(",
"options",
")",
"{",
"if",
"(",
"!",
"options",
")",
"{",
"options",
"=",
"{",
"}",
";",
"}",
"options",
".",
"use_sourcemaps",
"=",
"options",
".",
"use_sourcemaps",
"?",
"true",
":",
"false",
";",
"options",
".",
"babelify",
"=",
"fixBabelify",
"(",
"options",
".",
"babelify",
")",
";",
"options",
".",
"ignore",
"=",
"fixIgnore",
"(",
"options",
".",
"ignore",
")",
";",
"options",
".",
"exclude",
"=",
"fixExclude",
"(",
"options",
".",
"exclude",
")",
";",
"return",
"options",
";",
"}"
] | Applies defaults and cleanup to the options sent to the method exposed by this file
@param {object} options - The options passed into the function exposed by this file
@returns {object} options with defaults applied | [
"Applies",
"defaults",
"and",
"cleanup",
"to",
"the",
"options",
"sent",
"to",
"the",
"method",
"exposed",
"by",
"this",
"file"
] | c089d79d8181063c7fae00432a79b7a79a7809d3 | https://github.com/Dashron/roads/blob/c089d79d8181063c7fae00432a79b7a79a7809d3/src/client/build.js#L82-L94 | train |
HumanBrainProject/jsdoc-sphinx | template/view-models/doclet.js | docletModel | function docletModel(doclet) {
return function(context, cb) {
logger.debug('doclet', doclet);
var viewModel = _.extend({},
util.rstMixin,
util.docletChildren(context, doclet, util.mainDocletKinds),
// (doclet.kind === 'module' ? {} :
// util.docletChildren(context, doclet, util.subDocletKinds)
// ), {
util.docletChildren(context, doclet, util.subDocletKinds), {
doclet: doclet,
example: util.example
}
);
util.view('doclet.rst', viewModel, cb);
};
} | javascript | function docletModel(doclet) {
return function(context, cb) {
logger.debug('doclet', doclet);
var viewModel = _.extend({},
util.rstMixin,
util.docletChildren(context, doclet, util.mainDocletKinds),
// (doclet.kind === 'module' ? {} :
// util.docletChildren(context, doclet, util.subDocletKinds)
// ), {
util.docletChildren(context, doclet, util.subDocletKinds), {
doclet: doclet,
example: util.example
}
);
util.view('doclet.rst', viewModel, cb);
};
} | [
"function",
"docletModel",
"(",
"doclet",
")",
"{",
"return",
"function",
"(",
"context",
",",
"cb",
")",
"{",
"logger",
".",
"debug",
"(",
"'doclet'",
",",
"doclet",
")",
";",
"var",
"viewModel",
"=",
"_",
".",
"extend",
"(",
"{",
"}",
",",
"util",
".",
"rstMixin",
",",
"util",
".",
"docletChildren",
"(",
"context",
",",
"doclet",
",",
"util",
".",
"mainDocletKinds",
")",
",",
"util",
".",
"docletChildren",
"(",
"context",
",",
"doclet",
",",
"util",
".",
"subDocletKinds",
")",
",",
"{",
"doclet",
":",
"doclet",
",",
"example",
":",
"util",
".",
"example",
"}",
")",
";",
"util",
".",
"view",
"(",
"'doclet.rst'",
",",
"viewModel",
",",
"cb",
")",
";",
"}",
";",
"}"
] | The Mustache ViewModel to render a doclet.
@param {object} doclet the doclet to render
@return {function} the template helper func | [
"The",
"Mustache",
"ViewModel",
"to",
"render",
"a",
"doclet",
"."
] | 9d7c1d318ce535640588e7308917729c3849bc83 | https://github.com/HumanBrainProject/jsdoc-sphinx/blob/9d7c1d318ce535640588e7308917729c3849bc83/template/view-models/doclet.js#L11-L27 | train |
FINRAOS/MSL | msl-client-browser/appcontainer-driver.js | escapeString | function escapeString(str) {
if(str === undefined) {
throw new Error('\'str\' is required');
}
if(str === null) {
throw new Error('\'str\' must not be null');
}
if(typeof str !== 'string') {
throw new Error('\'str\' must be a string');
}
/*
* Need to escape backslashes (\) first because escaping ' and " will also
* add a \, which interferes with \ escaping.
*/
var escaped_str = str;
// regex replace all \ to \\
escaped_str = escaped_str.replace(/\\/g, '\\\\');
// regex replace all ' to \'
escaped_str = escaped_str.replace(/'/g, '\\\'');
// regex replace all " to \"
escaped_str = escaped_str.replace(/"/g, '\\"');
return escaped_str;
} | javascript | function escapeString(str) {
if(str === undefined) {
throw new Error('\'str\' is required');
}
if(str === null) {
throw new Error('\'str\' must not be null');
}
if(typeof str !== 'string') {
throw new Error('\'str\' must be a string');
}
/*
* Need to escape backslashes (\) first because escaping ' and " will also
* add a \, which interferes with \ escaping.
*/
var escaped_str = str;
// regex replace all \ to \\
escaped_str = escaped_str.replace(/\\/g, '\\\\');
// regex replace all ' to \'
escaped_str = escaped_str.replace(/'/g, '\\\'');
// regex replace all " to \"
escaped_str = escaped_str.replace(/"/g, '\\"');
return escaped_str;
} | [
"function",
"escapeString",
"(",
"str",
")",
"{",
"if",
"(",
"str",
"===",
"undefined",
")",
"{",
"throw",
"new",
"Error",
"(",
"'\\'str\\' is required'",
")",
";",
"}",
"\\'",
"\\'",
"if",
"(",
"str",
"===",
"null",
")",
"{",
"throw",
"new",
"Error",
"(",
"'\\'str\\' must not be null'",
")",
";",
"}",
"\\'",
"\\'",
"if",
"(",
"typeof",
"str",
"!==",
"'string'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'\\'str\\' must be a string'",
")",
";",
"}",
"\\'",
"}"
] | Escapes single, double quotes, and backslashes of the given string.
@name escapeString
@param {string} str - string to escape
@returns {string} the escaped string | [
"Escapes",
"single",
"double",
"quotes",
"and",
"backslashes",
"of",
"the",
"given",
"string",
"."
] | c8e2d79749551c551fc42b8ed80d3321141df845 | https://github.com/FINRAOS/MSL/blob/c8e2d79749551c551fc42b8ed80d3321141df845/msl-client-browser/appcontainer-driver.js#L189-L217 | train |
blakeembrey/highlighter | highlighter.js | highlight | function highlight (code, lang) {
if (!lang) {
return code
}
var isDiff = DIFF_REGEXP.test(lang)
// Remove the diff suffix. E.g. "javascript.diff".
lang = lang.replace(DIFF_REGEXP, '')
// Ignore unknown languages.
if (!isDiff && !supported(lang)) {
return code
}
return isDiff ? diff(code, lang) : hljs.highlight(lang, code).value
} | javascript | function highlight (code, lang) {
if (!lang) {
return code
}
var isDiff = DIFF_REGEXP.test(lang)
// Remove the diff suffix. E.g. "javascript.diff".
lang = lang.replace(DIFF_REGEXP, '')
// Ignore unknown languages.
if (!isDiff && !supported(lang)) {
return code
}
return isDiff ? diff(code, lang) : hljs.highlight(lang, code).value
} | [
"function",
"highlight",
"(",
"code",
",",
"lang",
")",
"{",
"if",
"(",
"!",
"lang",
")",
"{",
"return",
"code",
"}",
"var",
"isDiff",
"=",
"DIFF_REGEXP",
".",
"test",
"(",
"lang",
")",
"lang",
"=",
"lang",
".",
"replace",
"(",
"DIFF_REGEXP",
",",
"''",
")",
"if",
"(",
"!",
"isDiff",
"&&",
"!",
"supported",
"(",
"lang",
")",
")",
"{",
"return",
"code",
"}",
"return",
"isDiff",
"?",
"diff",
"(",
"code",
",",
"lang",
")",
":",
"hljs",
".",
"highlight",
"(",
"lang",
",",
"code",
")",
".",
"value",
"}"
] | Syntax highlighting in the format Marked supports.
@param {String} code
@param {String} lang
@return {String} | [
"Syntax",
"highlighting",
"in",
"the",
"format",
"Marked",
"supports",
"."
] | 65d9a2d65ece87f2f245536e94d5eb1dc4707106 | https://github.com/blakeembrey/highlighter/blob/65d9a2d65ece87f2f245536e94d5eb1dc4707106/highlighter.js#L49-L65 | train |
blakeembrey/highlighter | highlighter.js | diff | function diff (code, lang) {
var sections = []
code.split(/\r?\n/g).forEach(function (line) {
var type
if (CHUNK_REGEXP.test(line)) {
type = 'chunk'
} else if (HEADER_REGEXP.test(line)) {
type = 'header'
} else {
type = PATCH_TYPES[line[0]] || 'null'
line = line.replace(/^[+\-! ]/, '')
}
// Merge data with the previous section where possible.
var previous = sections[sections.length - 1]
if (!previous || previous.type !== type) {
sections.push({
type: type,
lines: [line]
})
return
}
previous.lines.push(line)
})
return highlightSections(sections, lang)
.map(function (section) {
var type = section.type
var value = section.lines.join(SEPARATOR)
return '<span class="diff-' + type + '">' + value + '</span>'
})
.join(SEPARATOR)
} | javascript | function diff (code, lang) {
var sections = []
code.split(/\r?\n/g).forEach(function (line) {
var type
if (CHUNK_REGEXP.test(line)) {
type = 'chunk'
} else if (HEADER_REGEXP.test(line)) {
type = 'header'
} else {
type = PATCH_TYPES[line[0]] || 'null'
line = line.replace(/^[+\-! ]/, '')
}
// Merge data with the previous section where possible.
var previous = sections[sections.length - 1]
if (!previous || previous.type !== type) {
sections.push({
type: type,
lines: [line]
})
return
}
previous.lines.push(line)
})
return highlightSections(sections, lang)
.map(function (section) {
var type = section.type
var value = section.lines.join(SEPARATOR)
return '<span class="diff-' + type + '">' + value + '</span>'
})
.join(SEPARATOR)
} | [
"function",
"diff",
"(",
"code",
",",
"lang",
")",
"{",
"var",
"sections",
"=",
"[",
"]",
"code",
".",
"split",
"(",
"/",
"\\r?\\n",
"/",
"g",
")",
".",
"forEach",
"(",
"function",
"(",
"line",
")",
"{",
"var",
"type",
"if",
"(",
"CHUNK_REGEXP",
".",
"test",
"(",
"line",
")",
")",
"{",
"type",
"=",
"'chunk'",
"}",
"else",
"if",
"(",
"HEADER_REGEXP",
".",
"test",
"(",
"line",
")",
")",
"{",
"type",
"=",
"'header'",
"}",
"else",
"{",
"type",
"=",
"PATCH_TYPES",
"[",
"line",
"[",
"0",
"]",
"]",
"||",
"'null'",
"line",
"=",
"line",
".",
"replace",
"(",
"/",
"^[+\\-! ]",
"/",
",",
"''",
")",
"}",
"var",
"previous",
"=",
"sections",
"[",
"sections",
".",
"length",
"-",
"1",
"]",
"if",
"(",
"!",
"previous",
"||",
"previous",
".",
"type",
"!==",
"type",
")",
"{",
"sections",
".",
"push",
"(",
"{",
"type",
":",
"type",
",",
"lines",
":",
"[",
"line",
"]",
"}",
")",
"return",
"}",
"previous",
".",
"lines",
".",
"push",
"(",
"line",
")",
"}",
")",
"return",
"highlightSections",
"(",
"sections",
",",
"lang",
")",
".",
"map",
"(",
"function",
"(",
"section",
")",
"{",
"var",
"type",
"=",
"section",
".",
"type",
"var",
"value",
"=",
"section",
".",
"lines",
".",
"join",
"(",
"SEPARATOR",
")",
"return",
"'<span class=\"diff-'",
"+",
"type",
"+",
"'\">'",
"+",
"value",
"+",
"'</span>'",
"}",
")",
".",
"join",
"(",
"SEPARATOR",
")",
"}"
] | Add diff syntax highlighting to code.
@param {String} code
@param {String} lang
@return {String} | [
"Add",
"diff",
"syntax",
"highlighting",
"to",
"code",
"."
] | 65d9a2d65ece87f2f245536e94d5eb1dc4707106 | https://github.com/blakeembrey/highlighter/blob/65d9a2d65ece87f2f245536e94d5eb1dc4707106/highlighter.js#L74-L112 | train |
blakeembrey/highlighter | highlighter.js | highlightSections | function highlightSections (sections, lang) {
if (!supported(lang)) {
return sections
}
// Keep track of the most recent stacks.
var additionStack
var deletionStack
sections
.forEach(function (section) {
var type = section.type
// Reset the stacks for metadata types.
if (type === 'header' || type === 'chunk') {
additionStack = deletionStack = null
return
}
var value = section.lines.join(SEPARATOR)
var stack = type === 'deletion' ? deletionStack : additionStack
var highlight = hljs.highlight(lang, value, false, stack)
// Set the top of each stack, depending on context.
if (type === 'addition') {
additionStack = highlight.top
} else if (type === 'deletion') {
deletionStack = highlight.top
} else {
additionStack = deletionStack = highlight.top
}
section.lines = highlight.value.split(SEPARATOR)
})
return sections
} | javascript | function highlightSections (sections, lang) {
if (!supported(lang)) {
return sections
}
// Keep track of the most recent stacks.
var additionStack
var deletionStack
sections
.forEach(function (section) {
var type = section.type
// Reset the stacks for metadata types.
if (type === 'header' || type === 'chunk') {
additionStack = deletionStack = null
return
}
var value = section.lines.join(SEPARATOR)
var stack = type === 'deletion' ? deletionStack : additionStack
var highlight = hljs.highlight(lang, value, false, stack)
// Set the top of each stack, depending on context.
if (type === 'addition') {
additionStack = highlight.top
} else if (type === 'deletion') {
deletionStack = highlight.top
} else {
additionStack = deletionStack = highlight.top
}
section.lines = highlight.value.split(SEPARATOR)
})
return sections
} | [
"function",
"highlightSections",
"(",
"sections",
",",
"lang",
")",
"{",
"if",
"(",
"!",
"supported",
"(",
"lang",
")",
")",
"{",
"return",
"sections",
"}",
"var",
"additionStack",
"var",
"deletionStack",
"sections",
".",
"forEach",
"(",
"function",
"(",
"section",
")",
"{",
"var",
"type",
"=",
"section",
".",
"type",
"if",
"(",
"type",
"===",
"'header'",
"||",
"type",
"===",
"'chunk'",
")",
"{",
"additionStack",
"=",
"deletionStack",
"=",
"null",
"return",
"}",
"var",
"value",
"=",
"section",
".",
"lines",
".",
"join",
"(",
"SEPARATOR",
")",
"var",
"stack",
"=",
"type",
"===",
"'deletion'",
"?",
"deletionStack",
":",
"additionStack",
"var",
"highlight",
"=",
"hljs",
".",
"highlight",
"(",
"lang",
",",
"value",
",",
"false",
",",
"stack",
")",
"if",
"(",
"type",
"===",
"'addition'",
")",
"{",
"additionStack",
"=",
"highlight",
".",
"top",
"}",
"else",
"if",
"(",
"type",
"===",
"'deletion'",
")",
"{",
"deletionStack",
"=",
"highlight",
".",
"top",
"}",
"else",
"{",
"additionStack",
"=",
"deletionStack",
"=",
"highlight",
".",
"top",
"}",
"section",
".",
"lines",
"=",
"highlight",
".",
"value",
".",
"split",
"(",
"SEPARATOR",
")",
"}",
")",
"return",
"sections",
"}"
] | Add syntax highlighting to all sections.
@param {Array} sections
@param {String} lang
@return {Array} | [
"Add",
"syntax",
"highlighting",
"to",
"all",
"sections",
"."
] | 65d9a2d65ece87f2f245536e94d5eb1dc4707106 | https://github.com/blakeembrey/highlighter/blob/65d9a2d65ece87f2f245536e94d5eb1dc4707106/highlighter.js#L121-L158 | train |
danigb/smplr | packages/audio-pack/index.js | encode | function encode (filename) {
var ext = path.extname(filename)
var data = fs.readFileSync(filename)
var prefix = 'data:audio/' + ext.substring(1) + ';base64,'
var encoded = new Buffer(data).toString('base64')
return prefix + encoded
} | javascript | function encode (filename) {
var ext = path.extname(filename)
var data = fs.readFileSync(filename)
var prefix = 'data:audio/' + ext.substring(1) + ';base64,'
var encoded = new Buffer(data).toString('base64')
return prefix + encoded
} | [
"function",
"encode",
"(",
"filename",
")",
"{",
"var",
"ext",
"=",
"path",
".",
"extname",
"(",
"filename",
")",
"var",
"data",
"=",
"fs",
".",
"readFileSync",
"(",
"filename",
")",
"var",
"prefix",
"=",
"'data:audio/'",
"+",
"ext",
".",
"substring",
"(",
"1",
")",
"+",
"';base64,'",
"var",
"encoded",
"=",
"new",
"Buffer",
"(",
"data",
")",
".",
"toString",
"(",
"'base64'",
")",
"return",
"prefix",
"+",
"encoded",
"}"
] | Encode an audio file using base64 | [
"Encode",
"an",
"audio",
"file",
"using",
"base64"
] | d2ef6b41dfea486cb5eeaa320f5a75efe9ae9bb1 | https://github.com/danigb/smplr/blob/d2ef6b41dfea486cb5eeaa320f5a75efe9ae9bb1/packages/audio-pack/index.js#L7-L13 | train |
danigb/smplr | packages/audio-pack/index.js | audioExt | function audioExt (name) {
var ext = path.extname(name)
return ['.wav', '.ogg', '.mp3'].indexOf(ext) > -1 ? ext : null
} | javascript | function audioExt (name) {
var ext = path.extname(name)
return ['.wav', '.ogg', '.mp3'].indexOf(ext) > -1 ? ext : null
} | [
"function",
"audioExt",
"(",
"name",
")",
"{",
"var",
"ext",
"=",
"path",
".",
"extname",
"(",
"name",
")",
"return",
"[",
"'.wav'",
",",
"'.ogg'",
",",
"'.mp3'",
"]",
".",
"indexOf",
"(",
"ext",
")",
">",
"-",
"1",
"?",
"ext",
":",
"null",
"}"
] | Return the extension of a filename if its a valid web audio format extension | [
"Return",
"the",
"extension",
"of",
"a",
"filename",
"if",
"its",
"a",
"valid",
"web",
"audio",
"format",
"extension"
] | d2ef6b41dfea486cb5eeaa320f5a75efe9ae9bb1 | https://github.com/danigb/smplr/blob/d2ef6b41dfea486cb5eeaa320f5a75efe9ae9bb1/packages/audio-pack/index.js#L18-L21 | train |
danigb/smplr | packages/audio-pack/index.js | build | function build (instFile) {
var dir = path.dirname(instFile)
var inst = JSON.parse(fs.readFileSync(instFile))
inst.samples = samples(path.join(dir, 'samples'), true)
return JSON.stringify(inst, null, 2)
} | javascript | function build (instFile) {
var dir = path.dirname(instFile)
var inst = JSON.parse(fs.readFileSync(instFile))
inst.samples = samples(path.join(dir, 'samples'), true)
return JSON.stringify(inst, null, 2)
} | [
"function",
"build",
"(",
"instFile",
")",
"{",
"var",
"dir",
"=",
"path",
".",
"dirname",
"(",
"instFile",
")",
"var",
"inst",
"=",
"JSON",
".",
"parse",
"(",
"fs",
".",
"readFileSync",
"(",
"instFile",
")",
")",
"inst",
".",
"samples",
"=",
"samples",
"(",
"path",
".",
"join",
"(",
"dir",
",",
"'samples'",
")",
",",
"true",
")",
"return",
"JSON",
".",
"stringify",
"(",
"inst",
",",
"null",
",",
"2",
")",
"}"
] | Build a JSON packed file from the instrument.json file | [
"Build",
"a",
"JSON",
"packed",
"file",
"from",
"the",
"instrument",
".",
"json",
"file"
] | d2ef6b41dfea486cb5eeaa320f5a75efe9ae9bb1 | https://github.com/danigb/smplr/blob/d2ef6b41dfea486cb5eeaa320f5a75efe9ae9bb1/packages/audio-pack/index.js#L26-L31 | train |
danigb/smplr | packages/audio-pack/index.js | samples | function samples (samplesPath, obj) {
var files = fs.readdirSync(samplesPath).reduce(function (d, name) {
var ext = audioExt(name)
if (ext) d[name.substring(0, name.length - ext.length)] = name
return d
}, {})
var names = Object.keys(files)
var prefix = sharedStart(names)
var len = prefix.length
var samples = names.reduce(function (s, name) {
s[name.substring(len)] = encode(path.join(samplesPath, files[name]))
return s
}, {})
return obj ? samples : JSON.stringify(samples, null, 2)
} | javascript | function samples (samplesPath, obj) {
var files = fs.readdirSync(samplesPath).reduce(function (d, name) {
var ext = audioExt(name)
if (ext) d[name.substring(0, name.length - ext.length)] = name
return d
}, {})
var names = Object.keys(files)
var prefix = sharedStart(names)
var len = prefix.length
var samples = names.reduce(function (s, name) {
s[name.substring(len)] = encode(path.join(samplesPath, files[name]))
return s
}, {})
return obj ? samples : JSON.stringify(samples, null, 2)
} | [
"function",
"samples",
"(",
"samplesPath",
",",
"obj",
")",
"{",
"var",
"files",
"=",
"fs",
".",
"readdirSync",
"(",
"samplesPath",
")",
".",
"reduce",
"(",
"function",
"(",
"d",
",",
"name",
")",
"{",
"var",
"ext",
"=",
"audioExt",
"(",
"name",
")",
"if",
"(",
"ext",
")",
"d",
"[",
"name",
".",
"substring",
"(",
"0",
",",
"name",
".",
"length",
"-",
"ext",
".",
"length",
")",
"]",
"=",
"name",
"return",
"d",
"}",
",",
"{",
"}",
")",
"var",
"names",
"=",
"Object",
".",
"keys",
"(",
"files",
")",
"var",
"prefix",
"=",
"sharedStart",
"(",
"names",
")",
"var",
"len",
"=",
"prefix",
".",
"length",
"var",
"samples",
"=",
"names",
".",
"reduce",
"(",
"function",
"(",
"s",
",",
"name",
")",
"{",
"s",
"[",
"name",
".",
"substring",
"(",
"len",
")",
"]",
"=",
"encode",
"(",
"path",
".",
"join",
"(",
"samplesPath",
",",
"files",
"[",
"name",
"]",
")",
")",
"return",
"s",
"}",
",",
"{",
"}",
")",
"return",
"obj",
"?",
"samples",
":",
"JSON",
".",
"stringify",
"(",
"samples",
",",
"null",
",",
"2",
")",
"}"
] | Return a JSON with the audio files from a path encoded in base64 | [
"Return",
"a",
"JSON",
"with",
"the",
"audio",
"files",
"from",
"a",
"path",
"encoded",
"in",
"base64"
] | d2ef6b41dfea486cb5eeaa320f5a75efe9ae9bb1 | https://github.com/danigb/smplr/blob/d2ef6b41dfea486cb5eeaa320f5a75efe9ae9bb1/packages/audio-pack/index.js#L36-L50 | train |
joshbuddy/tcplock | examples/oo-mutex.js | function(activateNextConnection) {
if ( (count % 20) == 0 || timeoutOccurred) {
timeoutOccurred = false;
exec('killall -9 soffice.bin libreoffice soffice', function(error, stdout, stderr) {
waitForOOState('closed', function() {
exec('libreoffice -headless -nofirststartwizard -accept="socket,host=0.0.0.0,port=8100;urp;StarOffice.Service"');
waitForOOState('open', function() {
activateNextConnection();
});
});
});
} else {
activateNextConnection();
}
count += 1;
} | javascript | function(activateNextConnection) {
if ( (count % 20) == 0 || timeoutOccurred) {
timeoutOccurred = false;
exec('killall -9 soffice.bin libreoffice soffice', function(error, stdout, stderr) {
waitForOOState('closed', function() {
exec('libreoffice -headless -nofirststartwizard -accept="socket,host=0.0.0.0,port=8100;urp;StarOffice.Service"');
waitForOOState('open', function() {
activateNextConnection();
});
});
});
} else {
activateNextConnection();
}
count += 1;
} | [
"function",
"(",
"activateNextConnection",
")",
"{",
"if",
"(",
"(",
"count",
"%",
"20",
")",
"==",
"0",
"||",
"timeoutOccurred",
")",
"{",
"timeoutOccurred",
"=",
"false",
";",
"exec",
"(",
"'killall -9 soffice.bin libreoffice soffice'",
",",
"function",
"(",
"error",
",",
"stdout",
",",
"stderr",
")",
"{",
"waitForOOState",
"(",
"'closed'",
",",
"function",
"(",
")",
"{",
"exec",
"(",
"'libreoffice -headless -nofirststartwizard -accept=\"socket,host=0.0.0.0,port=8100;urp;StarOffice.Service\"'",
")",
";",
"waitForOOState",
"(",
"'open'",
",",
"function",
"(",
")",
"{",
"activateNextConnection",
"(",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"activateNextConnection",
"(",
")",
";",
"}",
"count",
"+=",
"1",
";",
"}"
] | Only alow OOP to run for 20 seconds. | [
"Only",
"alow",
"OOP",
"to",
"run",
"for",
"20",
"seconds",
"."
] | 1c50a86fb8da94ea6f7984caadf9682f8875b1e8 | https://github.com/joshbuddy/tcplock/blob/1c50a86fb8da94ea6f7984caadf9682f8875b1e8/examples/oo-mutex.js#L25-L42 | train |
|
phphe/helper-js | dist/helper-js.es.js | arraySibling | function arraySibling(arr, item, offset) {
var index = arr.indexOf(item);
if (index === -1) {
throw 'item is not in array';
}
if (isArray(offset)) {
return offset.map(function (v) {
return arr[index + v];
});
}
return arr[index + offset];
} | javascript | function arraySibling(arr, item, offset) {
var index = arr.indexOf(item);
if (index === -1) {
throw 'item is not in array';
}
if (isArray(offset)) {
return offset.map(function (v) {
return arr[index + v];
});
}
return arr[index + offset];
} | [
"function",
"arraySibling",
"(",
"arr",
",",
"item",
",",
"offset",
")",
"{",
"var",
"index",
"=",
"arr",
".",
"indexOf",
"(",
"item",
")",
";",
"if",
"(",
"index",
"===",
"-",
"1",
")",
"{",
"throw",
"'item is not in array'",
";",
"}",
"if",
"(",
"isArray",
"(",
"offset",
")",
")",
"{",
"return",
"offset",
".",
"map",
"(",
"function",
"(",
"v",
")",
"{",
"return",
"arr",
"[",
"index",
"+",
"v",
"]",
";",
"}",
")",
";",
"}",
"return",
"arr",
"[",
"index",
"+",
"offset",
"]",
";",
"}"
] | offset can be many | [
"offset",
"can",
"be",
"many"
] | ba605006bb9c9434f2402c57e4cc50f145628558 | https://github.com/phphe/helper-js/blob/ba605006bb9c9434f2402c57e4cc50f145628558/dist/helper-js.es.js#L361-L375 | train |
phphe/helper-js | dist/helper-js.es.js | forAll | function forAll(val, handler, reverse) {
if (!reverse) {
if (isArray(val) || isString(val)) {
for (var i = 0; i < val.length; i++) {
if (handler(val[i], i) === false) {
break;
}
}
} else if (isObject(val)) {
for (var _i2 = 0, _Object$keys = Object.keys(val); _i2 < _Object$keys.length; _i2++) {
var key = _Object$keys[_i2];
if (handler(val[key], key) === false) {
break;
}
}
} else if (Number.isInteger(val)) {
for (var _i3 = 0; _i3 < val; _i3++) {
if (handler(_i3, _i3) === false) {
break;
}
}
}
} else {
if (isArray(val) || isString(val)) {
for (var _i4 = val.length - 1; _i4 >= 0; _i4--) {
if (handler(val[_i4], _i4) === false) {
break;
}
}
} else if (isObject(val)) {
var keys = Object.keys(val);
keys.reverse();
for (var _i5 = 0, _keys = keys; _i5 < _keys.length; _i5++) {
var _key = _keys[_i5];
if (handler(val[_key], _key) === false) {
break;
}
}
} else if (Number.isInteger(val)) {
for (var _i6 = val - 1; _i6 >= 0; _i6--) {
if (handler(_i6, _i6) === false) {
break;
}
}
}
}
} | javascript | function forAll(val, handler, reverse) {
if (!reverse) {
if (isArray(val) || isString(val)) {
for (var i = 0; i < val.length; i++) {
if (handler(val[i], i) === false) {
break;
}
}
} else if (isObject(val)) {
for (var _i2 = 0, _Object$keys = Object.keys(val); _i2 < _Object$keys.length; _i2++) {
var key = _Object$keys[_i2];
if (handler(val[key], key) === false) {
break;
}
}
} else if (Number.isInteger(val)) {
for (var _i3 = 0; _i3 < val; _i3++) {
if (handler(_i3, _i3) === false) {
break;
}
}
}
} else {
if (isArray(val) || isString(val)) {
for (var _i4 = val.length - 1; _i4 >= 0; _i4--) {
if (handler(val[_i4], _i4) === false) {
break;
}
}
} else if (isObject(val)) {
var keys = Object.keys(val);
keys.reverse();
for (var _i5 = 0, _keys = keys; _i5 < _keys.length; _i5++) {
var _key = _keys[_i5];
if (handler(val[_key], _key) === false) {
break;
}
}
} else if (Number.isInteger(val)) {
for (var _i6 = val - 1; _i6 >= 0; _i6--) {
if (handler(_i6, _i6) === false) {
break;
}
}
}
}
} | [
"function",
"forAll",
"(",
"val",
",",
"handler",
",",
"reverse",
")",
"{",
"if",
"(",
"!",
"reverse",
")",
"{",
"if",
"(",
"isArray",
"(",
"val",
")",
"||",
"isString",
"(",
"val",
")",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"val",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"handler",
"(",
"val",
"[",
"i",
"]",
",",
"i",
")",
"===",
"false",
")",
"{",
"break",
";",
"}",
"}",
"}",
"else",
"if",
"(",
"isObject",
"(",
"val",
")",
")",
"{",
"for",
"(",
"var",
"_i2",
"=",
"0",
",",
"_Object$keys",
"=",
"Object",
".",
"keys",
"(",
"val",
")",
";",
"_i2",
"<",
"_Object$keys",
".",
"length",
";",
"_i2",
"++",
")",
"{",
"var",
"key",
"=",
"_Object$keys",
"[",
"_i2",
"]",
";",
"if",
"(",
"handler",
"(",
"val",
"[",
"key",
"]",
",",
"key",
")",
"===",
"false",
")",
"{",
"break",
";",
"}",
"}",
"}",
"else",
"if",
"(",
"Number",
".",
"isInteger",
"(",
"val",
")",
")",
"{",
"for",
"(",
"var",
"_i3",
"=",
"0",
";",
"_i3",
"<",
"val",
";",
"_i3",
"++",
")",
"{",
"if",
"(",
"handler",
"(",
"_i3",
",",
"_i3",
")",
"===",
"false",
")",
"{",
"break",
";",
"}",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"isArray",
"(",
"val",
")",
"||",
"isString",
"(",
"val",
")",
")",
"{",
"for",
"(",
"var",
"_i4",
"=",
"val",
".",
"length",
"-",
"1",
";",
"_i4",
">=",
"0",
";",
"_i4",
"--",
")",
"{",
"if",
"(",
"handler",
"(",
"val",
"[",
"_i4",
"]",
",",
"_i4",
")",
"===",
"false",
")",
"{",
"break",
";",
"}",
"}",
"}",
"else",
"if",
"(",
"isObject",
"(",
"val",
")",
")",
"{",
"var",
"keys",
"=",
"Object",
".",
"keys",
"(",
"val",
")",
";",
"keys",
".",
"reverse",
"(",
")",
";",
"for",
"(",
"var",
"_i5",
"=",
"0",
",",
"_keys",
"=",
"keys",
";",
"_i5",
"<",
"_keys",
".",
"length",
";",
"_i5",
"++",
")",
"{",
"var",
"_key",
"=",
"_keys",
"[",
"_i5",
"]",
";",
"if",
"(",
"handler",
"(",
"val",
"[",
"_key",
"]",
",",
"_key",
")",
"===",
"false",
")",
"{",
"break",
";",
"}",
"}",
"}",
"else",
"if",
"(",
"Number",
".",
"isInteger",
"(",
"val",
")",
")",
"{",
"for",
"(",
"var",
"_i6",
"=",
"val",
"-",
"1",
";",
"_i6",
">=",
"0",
";",
"_i6",
"--",
")",
"{",
"if",
"(",
"handler",
"(",
"_i6",
",",
"_i6",
")",
"===",
"false",
")",
"{",
"break",
";",
"}",
"}",
"}",
"}",
"}"
] | loop for all type | [
"loop",
"for",
"all",
"type"
] | ba605006bb9c9434f2402c57e4cc50f145628558 | https://github.com/phphe/helper-js/blob/ba605006bb9c9434f2402c57e4cc50f145628558/dist/helper-js.es.js#L487-L536 | train |
phphe/helper-js | dist/helper-js.es.js | executeWithCount | function executeWithCount(func) {
var count = 0;
return function () {
for (var _len = arguments.length, args = new Array(_len), _key2 = 0; _key2 < _len; _key2++) {
args[_key2] = arguments[_key2];
}
return func.call.apply(func, [this, count++].concat(args));
};
} | javascript | function executeWithCount(func) {
var count = 0;
return function () {
for (var _len = arguments.length, args = new Array(_len), _key2 = 0; _key2 < _len; _key2++) {
args[_key2] = arguments[_key2];
}
return func.call.apply(func, [this, count++].concat(args));
};
} | [
"function",
"executeWithCount",
"(",
"func",
")",
"{",
"var",
"count",
"=",
"0",
";",
"return",
"function",
"(",
")",
"{",
"for",
"(",
"var",
"_len",
"=",
"arguments",
".",
"length",
",",
"args",
"=",
"new",
"Array",
"(",
"_len",
")",
",",
"_key2",
"=",
"0",
";",
"_key2",
"<",
"_len",
";",
"_key2",
"++",
")",
"{",
"args",
"[",
"_key2",
"]",
"=",
"arguments",
"[",
"_key2",
"]",
";",
"}",
"return",
"func",
".",
"call",
".",
"apply",
"(",
"func",
",",
"[",
"this",
",",
"count",
"++",
"]",
".",
"concat",
"(",
"args",
")",
")",
";",
"}",
";",
"}"
] | function helper | method helper | [
"function",
"helper",
"|",
"method",
"helper"
] | ba605006bb9c9434f2402c57e4cc50f145628558 | https://github.com/phphe/helper-js/blob/ba605006bb9c9434f2402c57e4cc50f145628558/dist/helper-js.es.js#L824-L833 | train |
phphe/helper-js | dist/helper-js.es.js | executePromiseGetters | function executePromiseGetters(getters) {
var concurrent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
var stopped;
var promise = new Promise(function (resolve, reject) {
var r = [];
var chunks = splitArray(getters, concurrent);
var promise = Promise.resolve();
chunks.forEach(function (chunk) {
promise = promise.then(function (result) {
if (result) {
r.push.apply(r, _toConsumableArray(result));
}
if (stopped) {
reject('stopped');
} else {
return Promise.all(chunk.map(function (v) {
return v();
}));
}
});
});
promise.then(function (result) {
r.push.apply(r, _toConsumableArray(result));
resolve(r);
});
});
return {
promise: promise,
destroy: function destroy() {
stopped = true;
}
};
} | javascript | function executePromiseGetters(getters) {
var concurrent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
var stopped;
var promise = new Promise(function (resolve, reject) {
var r = [];
var chunks = splitArray(getters, concurrent);
var promise = Promise.resolve();
chunks.forEach(function (chunk) {
promise = promise.then(function (result) {
if (result) {
r.push.apply(r, _toConsumableArray(result));
}
if (stopped) {
reject('stopped');
} else {
return Promise.all(chunk.map(function (v) {
return v();
}));
}
});
});
promise.then(function (result) {
r.push.apply(r, _toConsumableArray(result));
resolve(r);
});
});
return {
promise: promise,
destroy: function destroy() {
stopped = true;
}
};
} | [
"function",
"executePromiseGetters",
"(",
"getters",
")",
"{",
"var",
"concurrent",
"=",
"arguments",
".",
"length",
">",
"1",
"&&",
"arguments",
"[",
"1",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"1",
"]",
":",
"1",
";",
"var",
"stopped",
";",
"var",
"promise",
"=",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"var",
"r",
"=",
"[",
"]",
";",
"var",
"chunks",
"=",
"splitArray",
"(",
"getters",
",",
"concurrent",
")",
";",
"var",
"promise",
"=",
"Promise",
".",
"resolve",
"(",
")",
";",
"chunks",
".",
"forEach",
"(",
"function",
"(",
"chunk",
")",
"{",
"promise",
"=",
"promise",
".",
"then",
"(",
"function",
"(",
"result",
")",
"{",
"if",
"(",
"result",
")",
"{",
"r",
".",
"push",
".",
"apply",
"(",
"r",
",",
"_toConsumableArray",
"(",
"result",
")",
")",
";",
"}",
"if",
"(",
"stopped",
")",
"{",
"reject",
"(",
"'stopped'",
")",
";",
"}",
"else",
"{",
"return",
"Promise",
".",
"all",
"(",
"chunk",
".",
"map",
"(",
"function",
"(",
"v",
")",
"{",
"return",
"v",
"(",
")",
";",
"}",
")",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"promise",
".",
"then",
"(",
"function",
"(",
"result",
")",
"{",
"r",
".",
"push",
".",
"apply",
"(",
"r",
",",
"_toConsumableArray",
"(",
"result",
")",
")",
";",
"resolve",
"(",
"r",
")",
";",
"}",
")",
";",
"}",
")",
";",
"return",
"{",
"promise",
":",
"promise",
",",
"destroy",
":",
"function",
"destroy",
"(",
")",
"{",
"stopped",
"=",
"true",
";",
"}",
"}",
";",
"}"
] | promise execute promise in sequence | [
"promise",
"execute",
"promise",
"in",
"sequence"
] | ba605006bb9c9434f2402c57e4cc50f145628558 | https://github.com/phphe/helper-js/blob/ba605006bb9c9434f2402c57e4cc50f145628558/dist/helper-js.es.js#L1031-L1064 | train |
phphe/helper-js | dist/helper-js.es.js | getOffsetParent | function getOffsetParent(el) {
var offsetParent = el.offsetParent;
if (!offsetParent || offsetParent === document.body && getComputedStyle(document.body).position === 'static') {
offsetParent = document.body.parentElement;
}
return offsetParent;
} | javascript | function getOffsetParent(el) {
var offsetParent = el.offsetParent;
if (!offsetParent || offsetParent === document.body && getComputedStyle(document.body).position === 'static') {
offsetParent = document.body.parentElement;
}
return offsetParent;
} | [
"function",
"getOffsetParent",
"(",
"el",
")",
"{",
"var",
"offsetParent",
"=",
"el",
".",
"offsetParent",
";",
"if",
"(",
"!",
"offsetParent",
"||",
"offsetParent",
"===",
"document",
".",
"body",
"&&",
"getComputedStyle",
"(",
"document",
".",
"body",
")",
".",
"position",
"===",
"'static'",
")",
"{",
"offsetParent",
"=",
"document",
".",
"body",
".",
"parentElement",
";",
"}",
"return",
"offsetParent",
";",
"}"
] | there is some trap in el.offsetParent, so use this func to fix | [
"there",
"is",
"some",
"trap",
"in",
"el",
".",
"offsetParent",
"so",
"use",
"this",
"func",
"to",
"fix"
] | ba605006bb9c9434f2402c57e4cc50f145628558 | https://github.com/phphe/helper-js/blob/ba605006bb9c9434f2402c57e4cc50f145628558/dist/helper-js.es.js#L1171-L1179 | train |
phphe/helper-js | dist/helper-js.es.js | URLHelper | function URLHelper(baseUrl) {
var _this3 = this;
_classCallCheck(this, URLHelper);
_defineProperty(this, "baseUrl", '');
_defineProperty(this, "search", {});
var t = decodeURI(baseUrl).split('?');
this.baseUrl = t[0];
if (t[1]) {
t[1].split('&').forEach(function (v) {
var t2 = v.split('=');
_this3.search[t2[0]] = t2[1] == null ? '' : decodeURIComponent(t2[1]);
});
}
} | javascript | function URLHelper(baseUrl) {
var _this3 = this;
_classCallCheck(this, URLHelper);
_defineProperty(this, "baseUrl", '');
_defineProperty(this, "search", {});
var t = decodeURI(baseUrl).split('?');
this.baseUrl = t[0];
if (t[1]) {
t[1].split('&').forEach(function (v) {
var t2 = v.split('=');
_this3.search[t2[0]] = t2[1] == null ? '' : decodeURIComponent(t2[1]);
});
}
} | [
"function",
"URLHelper",
"(",
"baseUrl",
")",
"{",
"var",
"_this3",
"=",
"this",
";",
"_classCallCheck",
"(",
"this",
",",
"URLHelper",
")",
";",
"_defineProperty",
"(",
"this",
",",
"\"baseUrl\"",
",",
"''",
")",
";",
"_defineProperty",
"(",
"this",
",",
"\"search\"",
",",
"{",
"}",
")",
";",
"var",
"t",
"=",
"decodeURI",
"(",
"baseUrl",
")",
".",
"split",
"(",
"'?'",
")",
";",
"this",
".",
"baseUrl",
"=",
"t",
"[",
"0",
"]",
";",
"if",
"(",
"t",
"[",
"1",
"]",
")",
"{",
"t",
"[",
"1",
"]",
".",
"split",
"(",
"'&'",
")",
".",
"forEach",
"(",
"function",
"(",
"v",
")",
"{",
"var",
"t2",
"=",
"v",
".",
"split",
"(",
"'='",
")",
";",
"_this3",
".",
"search",
"[",
"t2",
"[",
"0",
"]",
"]",
"=",
"t2",
"[",
"1",
"]",
"==",
"null",
"?",
"''",
":",
"decodeURIComponent",
"(",
"t2",
"[",
"1",
"]",
")",
";",
"}",
")",
";",
"}",
"}"
] | protocol, hostname, port, pastname | [
"protocol",
"hostname",
"port",
"pastname"
] | ba605006bb9c9434f2402c57e4cc50f145628558 | https://github.com/phphe/helper-js/blob/ba605006bb9c9434f2402c57e4cc50f145628558/dist/helper-js.es.js#L1821-L1839 | train |
phphe/helper-js | dist/helper-js.es.js | makeStorageHelper | function makeStorageHelper(storage) {
return {
storage: storage,
set: function set(name, value, minutes) {
if (value == null) {
this.storage.removeItem(name);
} else {
this.storage.setItem(name, JSON.stringify({
value: value,
expired_at: minutes ? new Date().getTime() + minutes * 60 * 1000 : null
}));
}
},
get: function get$$1(name) {
var t = this.storage.getItem(name);
if (t) {
t = JSON.parse(t);
if (!t.expired_at || t.expired_at > new Date().getTime()) {
return t.value;
} else {
this.storage.removeItem(name);
}
}
return null;
},
clear: function clear() {
this.storage.clear();
}
};
} | javascript | function makeStorageHelper(storage) {
return {
storage: storage,
set: function set(name, value, minutes) {
if (value == null) {
this.storage.removeItem(name);
} else {
this.storage.setItem(name, JSON.stringify({
value: value,
expired_at: minutes ? new Date().getTime() + minutes * 60 * 1000 : null
}));
}
},
get: function get$$1(name) {
var t = this.storage.getItem(name);
if (t) {
t = JSON.parse(t);
if (!t.expired_at || t.expired_at > new Date().getTime()) {
return t.value;
} else {
this.storage.removeItem(name);
}
}
return null;
},
clear: function clear() {
this.storage.clear();
}
};
} | [
"function",
"makeStorageHelper",
"(",
"storage",
")",
"{",
"return",
"{",
"storage",
":",
"storage",
",",
"set",
":",
"function",
"set",
"(",
"name",
",",
"value",
",",
"minutes",
")",
"{",
"if",
"(",
"value",
"==",
"null",
")",
"{",
"this",
".",
"storage",
".",
"removeItem",
"(",
"name",
")",
";",
"}",
"else",
"{",
"this",
".",
"storage",
".",
"setItem",
"(",
"name",
",",
"JSON",
".",
"stringify",
"(",
"{",
"value",
":",
"value",
",",
"expired_at",
":",
"minutes",
"?",
"new",
"Date",
"(",
")",
".",
"getTime",
"(",
")",
"+",
"minutes",
"*",
"60",
"*",
"1000",
":",
"null",
"}",
")",
")",
";",
"}",
"}",
",",
"get",
":",
"function",
"get$$1",
"(",
"name",
")",
"{",
"var",
"t",
"=",
"this",
".",
"storage",
".",
"getItem",
"(",
"name",
")",
";",
"if",
"(",
"t",
")",
"{",
"t",
"=",
"JSON",
".",
"parse",
"(",
"t",
")",
";",
"if",
"(",
"!",
"t",
".",
"expired_at",
"||",
"t",
".",
"expired_at",
">",
"new",
"Date",
"(",
")",
".",
"getTime",
"(",
")",
")",
"{",
"return",
"t",
".",
"value",
";",
"}",
"else",
"{",
"this",
".",
"storage",
".",
"removeItem",
"(",
"name",
")",
";",
"}",
"}",
"return",
"null",
";",
"}",
",",
"clear",
":",
"function",
"clear",
"(",
")",
"{",
"this",
".",
"storage",
".",
"clear",
"(",
")",
";",
"}",
"}",
";",
"}"
] | set null can remove a item | [
"set",
"null",
"can",
"remove",
"a",
"item"
] | ba605006bb9c9434f2402c57e4cc50f145628558 | https://github.com/phphe/helper-js/blob/ba605006bb9c9434f2402c57e4cc50f145628558/dist/helper-js.es.js#L1903-L1935 | train |
nodef/extra-ffmpeg | index.js | command | function command(os) {
var z = 'ffmpeg';
var os = os||[];
for(var o of os) {
var o = o||{};
for(var k in o) {
if(o[k]==null) continue;
if(k==='stdio') continue;
if(k==='o' || k==='outfile') z += ` "${o[k]}"`;
else if(typeof o[k]==='boolean') z += o[k]? ` -${k}`:'';
else z += ` -${k} ${JSON.stringify(o[k])}`;
}
}
return z;
} | javascript | function command(os) {
var z = 'ffmpeg';
var os = os||[];
for(var o of os) {
var o = o||{};
for(var k in o) {
if(o[k]==null) continue;
if(k==='stdio') continue;
if(k==='o' || k==='outfile') z += ` "${o[k]}"`;
else if(typeof o[k]==='boolean') z += o[k]? ` -${k}`:'';
else z += ` -${k} ${JSON.stringify(o[k])}`;
}
}
return z;
} | [
"function",
"command",
"(",
"os",
")",
"{",
"var",
"z",
"=",
"'ffmpeg'",
";",
"var",
"os",
"=",
"os",
"||",
"[",
"]",
";",
"for",
"(",
"var",
"o",
"of",
"os",
")",
"{",
"var",
"o",
"=",
"o",
"||",
"{",
"}",
";",
"for",
"(",
"var",
"k",
"in",
"o",
")",
"{",
"if",
"(",
"o",
"[",
"k",
"]",
"==",
"null",
")",
"continue",
";",
"if",
"(",
"k",
"===",
"'stdio'",
")",
"continue",
";",
"if",
"(",
"k",
"===",
"'o'",
"||",
"k",
"===",
"'outfile'",
")",
"z",
"+=",
"`",
"${",
"o",
"[",
"k",
"]",
"}",
"`",
";",
"else",
"if",
"(",
"typeof",
"o",
"[",
"k",
"]",
"===",
"'boolean'",
")",
"z",
"+=",
"o",
"[",
"k",
"]",
"?",
"`",
"${",
"k",
"}",
"`",
":",
"''",
";",
"else",
"z",
"+=",
"`",
"${",
"k",
"}",
"${",
"JSON",
".",
"stringify",
"(",
"o",
"[",
"k",
"]",
")",
"}",
"`",
";",
"}",
"}",
"return",
"z",
";",
"}"
] | Generate command for ffmpeg. | [
"Generate",
"command",
"for",
"ffmpeg",
"."
] | 5f0ad08e8be923c417dcd550d896e8c50c38b871 | https://github.com/nodef/extra-ffmpeg/blob/5f0ad08e8be923c417dcd550d896e8c50c38b871/index.js#L9-L23 | train |
nodef/extra-ffmpeg | index.js | sync | function sync(os) {
var stdio = os.stdio===undefined? STDIO:os.stdio;
return cp.execSync(command(os), {stdio});
} | javascript | function sync(os) {
var stdio = os.stdio===undefined? STDIO:os.stdio;
return cp.execSync(command(os), {stdio});
} | [
"function",
"sync",
"(",
"os",
")",
"{",
"var",
"stdio",
"=",
"os",
".",
"stdio",
"===",
"undefined",
"?",
"STDIO",
":",
"os",
".",
"stdio",
";",
"return",
"cp",
".",
"execSync",
"(",
"command",
"(",
"os",
")",
",",
"{",
"stdio",
"}",
")",
";",
"}"
] | Invoke "ffmpeg" synchronously.
@param {object} os ffmpeg options. | [
"Invoke",
"ffmpeg",
"synchronously",
"."
] | 5f0ad08e8be923c417dcd550d896e8c50c38b871 | https://github.com/nodef/extra-ffmpeg/blob/5f0ad08e8be923c417dcd550d896e8c50c38b871/index.js#L29-L32 | train |
nodef/extra-ffmpeg | index.js | ffmpeg | function ffmpeg(os) {
var stdio = os.stdio===undefined? STDIO:os.stdio;
return new Promise((fres, frej) => cp.exec(command(os), {stdio}, (err, stdout, stderr) => {
if(err) frej(err);
else fres({stdout, stderr});
}));
} | javascript | function ffmpeg(os) {
var stdio = os.stdio===undefined? STDIO:os.stdio;
return new Promise((fres, frej) => cp.exec(command(os), {stdio}, (err, stdout, stderr) => {
if(err) frej(err);
else fres({stdout, stderr});
}));
} | [
"function",
"ffmpeg",
"(",
"os",
")",
"{",
"var",
"stdio",
"=",
"os",
".",
"stdio",
"===",
"undefined",
"?",
"STDIO",
":",
"os",
".",
"stdio",
";",
"return",
"new",
"Promise",
"(",
"(",
"fres",
",",
"frej",
")",
"=>",
"cp",
".",
"exec",
"(",
"command",
"(",
"os",
")",
",",
"{",
"stdio",
"}",
",",
"(",
"err",
",",
"stdout",
",",
"stderr",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"frej",
"(",
"err",
")",
";",
"else",
"fres",
"(",
"{",
"stdout",
",",
"stderr",
"}",
")",
";",
"}",
")",
")",
";",
"}"
] | Invoke "ffmpeg" asynchronously.
@param {object} os ffmpeg options. | [
"Invoke",
"ffmpeg",
"asynchronously",
"."
] | 5f0ad08e8be923c417dcd550d896e8c50c38b871 | https://github.com/nodef/extra-ffmpeg/blob/5f0ad08e8be923c417dcd550d896e8c50c38b871/index.js#L38-L44 | train |
ocadotechnology/quantumjs | quantum-core/lib/parse.js | tokenize | function tokenize (str) {
let pos = 0
let row = 1
let col = 1
let newline = true
let state = CONTENT
let start = 0
let consumingSameLineContent = false
let escapedInlineCounter = 0
let escapedParamCounter = 0
let consumingEscapedParams = false
let consumingUnparsed = false // true when in an @@ block
let lastInlineContentEndPos = void (0)
let unparsedIndentStart = void (0)
const indent = [0]
const tokens = []
function emit (type, value) {
if (arguments.length > 1) {
tokens.push({type: type, value: value})
} else {
tokens.push({type: type})
}
}
function consume (type, next) {
emit(type, str.substring(start, pos))
state = next
start = pos + 1
}
function consumeIfNonEmpty (type, next, escaped) {
let v = str.substring(start, pos)
if (v.length > 0) {
if (escaped) {
const l = escaped.length
for (let i = 0; i < l; i++) {
const es = escaped[i]
v = v.replace(es, es[1])
}
}
emit(type, v)
}
state = next
start = pos + 1
}
function shuffleIfNext (character) {
if (str[pos + 1] === character) {
pos++
start++
return true
} else {
return false
}
}
function err (msg) {
let start = str.lastIndexOf('\n', pos - 1)
start = str.lastIndexOf('\n', start - 1)
start = str.lastIndexOf('\n', start - 1)
const nextNewline = str.indexOf('\n', pos)
const errorLineEnd = nextNewline === -1 ? pos : nextNewline
let end = str.indexOf('\n', errorLineEnd + 1)
if (end === -1) {
end = str.length - 1
} else {
end = str.indexOf('\n', end + 1)
if (end === -1) {
end = str.length - 1
} else {
end = str.indexOf('\n', end + 1)
if (end === -1) {
end = str.length - 1
}
}
}
const indentSpaces = (new Array(col)).join(' ')
const message = 'Syntax error at line ' + row + ', col ' + col + ': ' + msg
const context = str.substring(start, errorLineEnd) + '\n' + indentSpaces + '^^^^^^^^\n' + str.substring(errorLineEnd + 1, end)
throw new ParseError(message + '\n' + context, context, str, row, col, msg, pos)
}
while (pos < str.length) {
// indentation and comment handling.
if (newline) {
while (newline && pos < str.length) {
let ind = 0
while (str[pos + ind] === ' ' && pos + ind < str.length) {
ind++
}
// if it was an empty content line, then add it to the list of empty
// content to emit on the next non empty line
if (str[pos + ind] === '\n') {
pos += ind + 1
row++
emit('EMPTY_CONTENT', str.substring(start, pos - 1))
} else if (str[pos + ind] !== '#' || consumingUnparsed) {
if (ind > indent[indent.length - 1]) {
emit('INDENT', ind - indent[indent.length - 1])
indent.push(ind)
} else if (ind < indent[indent.length - 1]) {
while (indent[indent.length - 1] > ind) {
const prev = indent.pop()
emit('DEDENT', prev - indent[indent.length - 1])
if (consumingUnparsed && unparsedIndentStart >= indent[indent.length - 1]) {
consumingUnparsed = false
}
}
if (indent.length > 0 && (indent[indent.length - 1] !== ind)) {
err('indentation mismatch: this line dedents with an indentation of ' + ind + ' spaces, but an indentation of ' + indent[indent.length - 1] + ' spaces was expected')
}
}
pos += ind
if (str[pos] === '\\' && str[pos + 1] === '#') {
pos++
}
newline = false
} else {
while (str[pos] !== '\n' && pos < str.length) {
pos++
}
emit('COMMENT', str.substring(start + ind + 1, pos))
pos++
row++
}
start = pos
}
}
if (pos >= str.length) {
return tokens
}
const s = str[pos]
if (state === TYPE) {
if (s === ' ') {
consume('TYPE', PARAMS)
while (shuffleIfNext(' ') && pos < str.length) {}
} else if (s === ':') {
consume('TYPE', CONTENT)
shuffleIfNext(' ')
consumingSameLineContent = true
emit('START_SAME_LINE_CONTENT')
} else if (s === '[') {
consume('TYPE', INLINE_CONTENT)
emit('START_INLINE_CONTENT')
} else if (s === '(') {
consume('TYPE', INLINE_PARAMS)
} else if (s === '\n') {
consume('TYPE', CONTENT)
if (consumingSameLineContent) {
emit('END_SAME_LINE_CONTENT')
consumingSameLineContent = false
}
}
} else if (state === PARAMS) {
if (s === '[') {
escapedParamCounter++
consumingEscapedParams = true
} else if (consumingEscapedParams && (s === ']')) {
escapedParamCounter--
if (escapedParamCounter === 0) {
consumingEscapedParams = false
}
} else if (s === ':' && !consumingEscapedParams) {
consume('PARAMS', CONTENT)
shuffleIfNext(' ')
shuffleIfNext(']')
consumingSameLineContent = true
emit('START_SAME_LINE_CONTENT')
} else if (s === '\n') {
escapedParamCounter = 0
consumingEscapedParams = false
consume('PARAMS', CONTENT)
if (consumingSameLineContent) {
emit('END_SAME_LINE_CONTENT')
consumingSameLineContent = false
}
}
} else if (state === CONTENT) {
if (s === '@' && !consumingUnparsed) {
consumeIfNonEmpty('CONTENT', TYPE)
if (str[pos + 1] === '@') {
consumingUnparsed = true
unparsedIndentStart = indent[indent.length - 1]
pos++
start++
}
} else if (s === '\n') {
if (consumingSameLineContent) {
if (lastInlineContentEndPos !== pos - 1) {
consumeIfNonEmpty('CONTENT', CONTENT)
}
emit('END_SAME_LINE_CONTENT')
consumingSameLineContent = false
consumingUnparsed = false
} else {
if (lastInlineContentEndPos !== pos - 1) {
consumeIfNonEmpty('CONTENT', CONTENT)
}
}
}
} else if (state === INLINE_PARAMS) {
if (s === ')') {
if (str[pos + 1] === '[') {
consume('PARAMS', INLINE_CONTENT)
emit('START_INLINE_CONTENT')
start++
pos++
} else {
consume('PARAMS', CONTENT)
}
}
} else { // if (state === INLINE_CONTENT) {
if (s === '\\' && (str[pos + 1] === '[' || str[pos + 1] === ']')) {
pos++
} else if (s === '[') {
escapedInlineCounter++
} else if (s === ']') {
if (escapedInlineCounter === 0) {
consumeIfNonEmpty('CONTENT', CONTENT, ['\\]', '\\['])
emit('END_INLINE_CONTENT')
lastInlineContentEndPos = pos + 1
} else {
escapedInlineCounter--
}
} else if (s === '\n') {
consume('CONTENT', INLINE_CONTENT)
}
}
if (s === '\n') {
col = 0
row++
newline = true
} else {
col++
}
pos++
}
if (state === TYPE) {
emit('TYPE', str.substring(start, pos))
} else if (state === PARAMS) {
emit('PARAMS', str.substring(start, pos))
} else if (state === INLINE_PARAMS) {
err('missing closing ) bracket?')
} else if (state === INLINE_CONTENT) {
err('missing closing ] bracket?')
} else { // if (state === CONTENT) {
if (start < pos) {
emit('CONTENT', str.substring(start, pos))
}
}
return tokens
} | javascript | function tokenize (str) {
let pos = 0
let row = 1
let col = 1
let newline = true
let state = CONTENT
let start = 0
let consumingSameLineContent = false
let escapedInlineCounter = 0
let escapedParamCounter = 0
let consumingEscapedParams = false
let consumingUnparsed = false // true when in an @@ block
let lastInlineContentEndPos = void (0)
let unparsedIndentStart = void (0)
const indent = [0]
const tokens = []
function emit (type, value) {
if (arguments.length > 1) {
tokens.push({type: type, value: value})
} else {
tokens.push({type: type})
}
}
function consume (type, next) {
emit(type, str.substring(start, pos))
state = next
start = pos + 1
}
function consumeIfNonEmpty (type, next, escaped) {
let v = str.substring(start, pos)
if (v.length > 0) {
if (escaped) {
const l = escaped.length
for (let i = 0; i < l; i++) {
const es = escaped[i]
v = v.replace(es, es[1])
}
}
emit(type, v)
}
state = next
start = pos + 1
}
function shuffleIfNext (character) {
if (str[pos + 1] === character) {
pos++
start++
return true
} else {
return false
}
}
function err (msg) {
let start = str.lastIndexOf('\n', pos - 1)
start = str.lastIndexOf('\n', start - 1)
start = str.lastIndexOf('\n', start - 1)
const nextNewline = str.indexOf('\n', pos)
const errorLineEnd = nextNewline === -1 ? pos : nextNewline
let end = str.indexOf('\n', errorLineEnd + 1)
if (end === -1) {
end = str.length - 1
} else {
end = str.indexOf('\n', end + 1)
if (end === -1) {
end = str.length - 1
} else {
end = str.indexOf('\n', end + 1)
if (end === -1) {
end = str.length - 1
}
}
}
const indentSpaces = (new Array(col)).join(' ')
const message = 'Syntax error at line ' + row + ', col ' + col + ': ' + msg
const context = str.substring(start, errorLineEnd) + '\n' + indentSpaces + '^^^^^^^^\n' + str.substring(errorLineEnd + 1, end)
throw new ParseError(message + '\n' + context, context, str, row, col, msg, pos)
}
while (pos < str.length) {
// indentation and comment handling.
if (newline) {
while (newline && pos < str.length) {
let ind = 0
while (str[pos + ind] === ' ' && pos + ind < str.length) {
ind++
}
// if it was an empty content line, then add it to the list of empty
// content to emit on the next non empty line
if (str[pos + ind] === '\n') {
pos += ind + 1
row++
emit('EMPTY_CONTENT', str.substring(start, pos - 1))
} else if (str[pos + ind] !== '#' || consumingUnparsed) {
if (ind > indent[indent.length - 1]) {
emit('INDENT', ind - indent[indent.length - 1])
indent.push(ind)
} else if (ind < indent[indent.length - 1]) {
while (indent[indent.length - 1] > ind) {
const prev = indent.pop()
emit('DEDENT', prev - indent[indent.length - 1])
if (consumingUnparsed && unparsedIndentStart >= indent[indent.length - 1]) {
consumingUnparsed = false
}
}
if (indent.length > 0 && (indent[indent.length - 1] !== ind)) {
err('indentation mismatch: this line dedents with an indentation of ' + ind + ' spaces, but an indentation of ' + indent[indent.length - 1] + ' spaces was expected')
}
}
pos += ind
if (str[pos] === '\\' && str[pos + 1] === '#') {
pos++
}
newline = false
} else {
while (str[pos] !== '\n' && pos < str.length) {
pos++
}
emit('COMMENT', str.substring(start + ind + 1, pos))
pos++
row++
}
start = pos
}
}
if (pos >= str.length) {
return tokens
}
const s = str[pos]
if (state === TYPE) {
if (s === ' ') {
consume('TYPE', PARAMS)
while (shuffleIfNext(' ') && pos < str.length) {}
} else if (s === ':') {
consume('TYPE', CONTENT)
shuffleIfNext(' ')
consumingSameLineContent = true
emit('START_SAME_LINE_CONTENT')
} else if (s === '[') {
consume('TYPE', INLINE_CONTENT)
emit('START_INLINE_CONTENT')
} else if (s === '(') {
consume('TYPE', INLINE_PARAMS)
} else if (s === '\n') {
consume('TYPE', CONTENT)
if (consumingSameLineContent) {
emit('END_SAME_LINE_CONTENT')
consumingSameLineContent = false
}
}
} else if (state === PARAMS) {
if (s === '[') {
escapedParamCounter++
consumingEscapedParams = true
} else if (consumingEscapedParams && (s === ']')) {
escapedParamCounter--
if (escapedParamCounter === 0) {
consumingEscapedParams = false
}
} else if (s === ':' && !consumingEscapedParams) {
consume('PARAMS', CONTENT)
shuffleIfNext(' ')
shuffleIfNext(']')
consumingSameLineContent = true
emit('START_SAME_LINE_CONTENT')
} else if (s === '\n') {
escapedParamCounter = 0
consumingEscapedParams = false
consume('PARAMS', CONTENT)
if (consumingSameLineContent) {
emit('END_SAME_LINE_CONTENT')
consumingSameLineContent = false
}
}
} else if (state === CONTENT) {
if (s === '@' && !consumingUnparsed) {
consumeIfNonEmpty('CONTENT', TYPE)
if (str[pos + 1] === '@') {
consumingUnparsed = true
unparsedIndentStart = indent[indent.length - 1]
pos++
start++
}
} else if (s === '\n') {
if (consumingSameLineContent) {
if (lastInlineContentEndPos !== pos - 1) {
consumeIfNonEmpty('CONTENT', CONTENT)
}
emit('END_SAME_LINE_CONTENT')
consumingSameLineContent = false
consumingUnparsed = false
} else {
if (lastInlineContentEndPos !== pos - 1) {
consumeIfNonEmpty('CONTENT', CONTENT)
}
}
}
} else if (state === INLINE_PARAMS) {
if (s === ')') {
if (str[pos + 1] === '[') {
consume('PARAMS', INLINE_CONTENT)
emit('START_INLINE_CONTENT')
start++
pos++
} else {
consume('PARAMS', CONTENT)
}
}
} else { // if (state === INLINE_CONTENT) {
if (s === '\\' && (str[pos + 1] === '[' || str[pos + 1] === ']')) {
pos++
} else if (s === '[') {
escapedInlineCounter++
} else if (s === ']') {
if (escapedInlineCounter === 0) {
consumeIfNonEmpty('CONTENT', CONTENT, ['\\]', '\\['])
emit('END_INLINE_CONTENT')
lastInlineContentEndPos = pos + 1
} else {
escapedInlineCounter--
}
} else if (s === '\n') {
consume('CONTENT', INLINE_CONTENT)
}
}
if (s === '\n') {
col = 0
row++
newline = true
} else {
col++
}
pos++
}
if (state === TYPE) {
emit('TYPE', str.substring(start, pos))
} else if (state === PARAMS) {
emit('PARAMS', str.substring(start, pos))
} else if (state === INLINE_PARAMS) {
err('missing closing ) bracket?')
} else if (state === INLINE_CONTENT) {
err('missing closing ] bracket?')
} else { // if (state === CONTENT) {
if (start < pos) {
emit('CONTENT', str.substring(start, pos))
}
}
return tokens
} | [
"function",
"tokenize",
"(",
"str",
")",
"{",
"let",
"pos",
"=",
"0",
"let",
"row",
"=",
"1",
"let",
"col",
"=",
"1",
"let",
"newline",
"=",
"true",
"let",
"state",
"=",
"CONTENT",
"let",
"start",
"=",
"0",
"let",
"consumingSameLineContent",
"=",
"false",
"let",
"escapedInlineCounter",
"=",
"0",
"let",
"escapedParamCounter",
"=",
"0",
"let",
"consumingEscapedParams",
"=",
"false",
"let",
"consumingUnparsed",
"=",
"false",
"let",
"lastInlineContentEndPos",
"=",
"void",
"(",
"0",
")",
"let",
"unparsedIndentStart",
"=",
"void",
"(",
"0",
")",
"const",
"indent",
"=",
"[",
"0",
"]",
"const",
"tokens",
"=",
"[",
"]",
"function",
"emit",
"(",
"type",
",",
"value",
")",
"{",
"if",
"(",
"arguments",
".",
"length",
">",
"1",
")",
"{",
"tokens",
".",
"push",
"(",
"{",
"type",
":",
"type",
",",
"value",
":",
"value",
"}",
")",
"}",
"else",
"{",
"tokens",
".",
"push",
"(",
"{",
"type",
":",
"type",
"}",
")",
"}",
"}",
"function",
"consume",
"(",
"type",
",",
"next",
")",
"{",
"emit",
"(",
"type",
",",
"str",
".",
"substring",
"(",
"start",
",",
"pos",
")",
")",
"state",
"=",
"next",
"start",
"=",
"pos",
"+",
"1",
"}",
"function",
"consumeIfNonEmpty",
"(",
"type",
",",
"next",
",",
"escaped",
")",
"{",
"let",
"v",
"=",
"str",
".",
"substring",
"(",
"start",
",",
"pos",
")",
"if",
"(",
"v",
".",
"length",
">",
"0",
")",
"{",
"if",
"(",
"escaped",
")",
"{",
"const",
"l",
"=",
"escaped",
".",
"length",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"const",
"es",
"=",
"escaped",
"[",
"i",
"]",
"v",
"=",
"v",
".",
"replace",
"(",
"es",
",",
"es",
"[",
"1",
"]",
")",
"}",
"}",
"emit",
"(",
"type",
",",
"v",
")",
"}",
"state",
"=",
"next",
"start",
"=",
"pos",
"+",
"1",
"}",
"function",
"shuffleIfNext",
"(",
"character",
")",
"{",
"if",
"(",
"str",
"[",
"pos",
"+",
"1",
"]",
"===",
"character",
")",
"{",
"pos",
"++",
"start",
"++",
"return",
"true",
"}",
"else",
"{",
"return",
"false",
"}",
"}",
"function",
"err",
"(",
"msg",
")",
"{",
"let",
"start",
"=",
"str",
".",
"lastIndexOf",
"(",
"'\\n'",
",",
"\\n",
")",
"pos",
"-",
"1",
"start",
"=",
"str",
".",
"lastIndexOf",
"(",
"'\\n'",
",",
"\\n",
")",
"start",
"-",
"1",
"start",
"=",
"str",
".",
"lastIndexOf",
"(",
"'\\n'",
",",
"\\n",
")",
"start",
"-",
"1",
"const",
"nextNewline",
"=",
"str",
".",
"indexOf",
"(",
"'\\n'",
",",
"\\n",
")",
"pos",
"const",
"errorLineEnd",
"=",
"nextNewline",
"===",
"-",
"1",
"?",
"pos",
":",
"nextNewline",
"let",
"end",
"=",
"str",
".",
"indexOf",
"(",
"'\\n'",
",",
"\\n",
")",
"errorLineEnd",
"+",
"1",
"}",
"if",
"(",
"end",
"===",
"-",
"1",
")",
"{",
"end",
"=",
"str",
".",
"length",
"-",
"1",
"}",
"else",
"{",
"end",
"=",
"str",
".",
"indexOf",
"(",
"'\\n'",
",",
"\\n",
")",
"end",
"+",
"1",
"}",
"if",
"(",
"end",
"===",
"-",
"1",
")",
"{",
"end",
"=",
"str",
".",
"length",
"-",
"1",
"}",
"else",
"{",
"end",
"=",
"str",
".",
"indexOf",
"(",
"'\\n'",
",",
"\\n",
")",
"end",
"+",
"1",
"}",
"if",
"(",
"end",
"===",
"-",
"1",
")",
"{",
"end",
"=",
"str",
".",
"length",
"-",
"1",
"}",
"}"
] | turns the input into an array of tokens | [
"turns",
"the",
"input",
"into",
"an",
"array",
"of",
"tokens"
] | 5bc684b750472296f186a816529272c36218db04 | https://github.com/ocadotechnology/quantumjs/blob/5bc684b750472296f186a816529272c36218db04/quantum-core/lib/parse.js#L45-L315 | train |
gulp-cookery/gulp-chef | lib/task/factory.js | simple | function simple() {
var recipe, configs;
recipe = recipes.inline(taskInfo) || recipes.plugin(taskInfo) || recipes.task(taskInfo);
if (recipe) {
configs = Configuration.sort(taskInfo, rawConfig, parentConfig, recipe.schema);
if (!configs.taskInfo.name) {
configs.taskInfo.visibility = CONSTANT.VISIBILITY.HIDDEN;
}
return self.create(prefix, configs.taskInfo, configs.taskConfig, recipe);
}
} | javascript | function simple() {
var recipe, configs;
recipe = recipes.inline(taskInfo) || recipes.plugin(taskInfo) || recipes.task(taskInfo);
if (recipe) {
configs = Configuration.sort(taskInfo, rawConfig, parentConfig, recipe.schema);
if (!configs.taskInfo.name) {
configs.taskInfo.visibility = CONSTANT.VISIBILITY.HIDDEN;
}
return self.create(prefix, configs.taskInfo, configs.taskConfig, recipe);
}
} | [
"function",
"simple",
"(",
")",
"{",
"var",
"recipe",
",",
"configs",
";",
"recipe",
"=",
"recipes",
".",
"inline",
"(",
"taskInfo",
")",
"||",
"recipes",
".",
"plugin",
"(",
"taskInfo",
")",
"||",
"recipes",
".",
"task",
"(",
"taskInfo",
")",
";",
"if",
"(",
"recipe",
")",
"{",
"configs",
"=",
"Configuration",
".",
"sort",
"(",
"taskInfo",
",",
"rawConfig",
",",
"parentConfig",
",",
"recipe",
".",
"schema",
")",
";",
"if",
"(",
"!",
"configs",
".",
"taskInfo",
".",
"name",
")",
"{",
"configs",
".",
"taskInfo",
".",
"visibility",
"=",
"CONSTANT",
".",
"VISIBILITY",
".",
"HIDDEN",
";",
"}",
"return",
"self",
".",
"create",
"(",
"prefix",
",",
"configs",
".",
"taskInfo",
",",
"configs",
".",
"taskConfig",
",",
"recipe",
")",
";",
"}",
"}"
] | Simple task should show up in task tree and cli, unless anonymous. | [
"Simple",
"task",
"should",
"show",
"up",
"in",
"task",
"tree",
"and",
"cli",
"unless",
"anonymous",
"."
] | 6a8b6b4d20a9f8a36bc74f2beb74524c7338788f | https://github.com/gulp-cookery/gulp-chef/blob/6a8b6b4d20a9f8a36bc74f2beb74524c7338788f/lib/task/factory.js#L93-L104 | train |
gulp-cookery/gulp-chef | lib/task/factory.js | auxiliary | function auxiliary() {
var recipe, configs, tasks;
recipe = recipes.stream(taskInfo) || recipes.flow(taskInfo);
if (recipe) {
configs = Configuration.sort(taskInfo, rawConfig, parentConfig, recipe.schema);
if (configs.taskInfo.name !== 'watch' && (!configs.taskInfo.name || !('visibility' in configs.taskInfo))) {
configs.taskInfo.visibility = CONSTANT.VISIBILITY.HIDDEN;
configs.taskInfo.name = '<' + configs.taskInfo.name + '>';
}
tasks = createTasks(configs);
return self.create(prefix, configs.taskInfo, configs.taskConfig, recipe, tasks);
}
} | javascript | function auxiliary() {
var recipe, configs, tasks;
recipe = recipes.stream(taskInfo) || recipes.flow(taskInfo);
if (recipe) {
configs = Configuration.sort(taskInfo, rawConfig, parentConfig, recipe.schema);
if (configs.taskInfo.name !== 'watch' && (!configs.taskInfo.name || !('visibility' in configs.taskInfo))) {
configs.taskInfo.visibility = CONSTANT.VISIBILITY.HIDDEN;
configs.taskInfo.name = '<' + configs.taskInfo.name + '>';
}
tasks = createTasks(configs);
return self.create(prefix, configs.taskInfo, configs.taskConfig, recipe, tasks);
}
} | [
"function",
"auxiliary",
"(",
")",
"{",
"var",
"recipe",
",",
"configs",
",",
"tasks",
";",
"recipe",
"=",
"recipes",
".",
"stream",
"(",
"taskInfo",
")",
"||",
"recipes",
".",
"flow",
"(",
"taskInfo",
")",
";",
"if",
"(",
"recipe",
")",
"{",
"configs",
"=",
"Configuration",
".",
"sort",
"(",
"taskInfo",
",",
"rawConfig",
",",
"parentConfig",
",",
"recipe",
".",
"schema",
")",
";",
"if",
"(",
"configs",
".",
"taskInfo",
".",
"name",
"!==",
"'watch'",
"&&",
"(",
"!",
"configs",
".",
"taskInfo",
".",
"name",
"||",
"!",
"(",
"'visibility'",
"in",
"configs",
".",
"taskInfo",
")",
")",
")",
"{",
"configs",
".",
"taskInfo",
".",
"visibility",
"=",
"CONSTANT",
".",
"VISIBILITY",
".",
"HIDDEN",
";",
"configs",
".",
"taskInfo",
".",
"name",
"=",
"'<'",
"+",
"configs",
".",
"taskInfo",
".",
"name",
"+",
"'>'",
";",
"}",
"tasks",
"=",
"createTasks",
"(",
"configs",
")",
";",
"return",
"self",
".",
"create",
"(",
"prefix",
",",
"configs",
".",
"taskInfo",
",",
"configs",
".",
"taskConfig",
",",
"recipe",
",",
"tasks",
")",
";",
"}",
"}"
] | Auxiliary task should show up in task tree, but not in cli by default for simplicity. | [
"Auxiliary",
"task",
"should",
"show",
"up",
"in",
"task",
"tree",
"but",
"not",
"in",
"cli",
"by",
"default",
"for",
"simplicity",
"."
] | 6a8b6b4d20a9f8a36bc74f2beb74524c7338788f | https://github.com/gulp-cookery/gulp-chef/blob/6a8b6b4d20a9f8a36bc74f2beb74524c7338788f/lib/task/factory.js#L196-L209 | train |
gulp-cookery/gulp-chef | lib/task/factory.js | composite | function composite() {
var configs, type, recipe, tasks, wrapper;
configs = Configuration.sort(taskInfo, rawConfig, parentConfig);
tasks = configs.taskInfo.parallel || configs.taskInfo.series || configs.taskInfo.task || configs.subTaskConfigs;
type = _type();
if (type) {
tasks = createTasks(configs);
recipe = recipes.flow({ recipe: type });
wrapper = self.create(prefix, {
name: '<' + type + '>',
visibility: CONSTANT.VISIBILITY.HIDDEN
}, configs.taskConfig, recipe, tasks);
if (configs.taskInfo.name) {
return self.create(prefix, configs.taskInfo, configs.taskConfig, wrapper, [wrapper]);
}
configs.taskInfo.visibility = CONSTANT.VISIBILITY.HIDDEN;
return wrapper;
}
if (_forward()) {
tasks = createTasks(configs);
recipe = function (done) {
return tasks[0].call(this, done);
};
return self.create(prefix, configs.taskInfo, configs.taskConfig, recipe, tasks);
}
function _type() {
if (configs.taskInfo.series) {
return 'series';
} else if (configs.taskInfo.parallel) {
return 'parallel';
} else if (_.size(tasks) > 1) {
if (Array.isArray(tasks)) {
return 'series';
} else if (_.isPlainObject(tasks)) {
return 'parallel';
}
}
}
function _forward() {
return _.size(tasks) === 1;
}
} | javascript | function composite() {
var configs, type, recipe, tasks, wrapper;
configs = Configuration.sort(taskInfo, rawConfig, parentConfig);
tasks = configs.taskInfo.parallel || configs.taskInfo.series || configs.taskInfo.task || configs.subTaskConfigs;
type = _type();
if (type) {
tasks = createTasks(configs);
recipe = recipes.flow({ recipe: type });
wrapper = self.create(prefix, {
name: '<' + type + '>',
visibility: CONSTANT.VISIBILITY.HIDDEN
}, configs.taskConfig, recipe, tasks);
if (configs.taskInfo.name) {
return self.create(prefix, configs.taskInfo, configs.taskConfig, wrapper, [wrapper]);
}
configs.taskInfo.visibility = CONSTANT.VISIBILITY.HIDDEN;
return wrapper;
}
if (_forward()) {
tasks = createTasks(configs);
recipe = function (done) {
return tasks[0].call(this, done);
};
return self.create(prefix, configs.taskInfo, configs.taskConfig, recipe, tasks);
}
function _type() {
if (configs.taskInfo.series) {
return 'series';
} else if (configs.taskInfo.parallel) {
return 'parallel';
} else if (_.size(tasks) > 1) {
if (Array.isArray(tasks)) {
return 'series';
} else if (_.isPlainObject(tasks)) {
return 'parallel';
}
}
}
function _forward() {
return _.size(tasks) === 1;
}
} | [
"function",
"composite",
"(",
")",
"{",
"var",
"configs",
",",
"type",
",",
"recipe",
",",
"tasks",
",",
"wrapper",
";",
"configs",
"=",
"Configuration",
".",
"sort",
"(",
"taskInfo",
",",
"rawConfig",
",",
"parentConfig",
")",
";",
"tasks",
"=",
"configs",
".",
"taskInfo",
".",
"parallel",
"||",
"configs",
".",
"taskInfo",
".",
"series",
"||",
"configs",
".",
"taskInfo",
".",
"task",
"||",
"configs",
".",
"subTaskConfigs",
";",
"type",
"=",
"_type",
"(",
")",
";",
"if",
"(",
"type",
")",
"{",
"tasks",
"=",
"createTasks",
"(",
"configs",
")",
";",
"recipe",
"=",
"recipes",
".",
"flow",
"(",
"{",
"recipe",
":",
"type",
"}",
")",
";",
"wrapper",
"=",
"self",
".",
"create",
"(",
"prefix",
",",
"{",
"name",
":",
"'<'",
"+",
"type",
"+",
"'>'",
",",
"visibility",
":",
"CONSTANT",
".",
"VISIBILITY",
".",
"HIDDEN",
"}",
",",
"configs",
".",
"taskConfig",
",",
"recipe",
",",
"tasks",
")",
";",
"if",
"(",
"configs",
".",
"taskInfo",
".",
"name",
")",
"{",
"return",
"self",
".",
"create",
"(",
"prefix",
",",
"configs",
".",
"taskInfo",
",",
"configs",
".",
"taskConfig",
",",
"wrapper",
",",
"[",
"wrapper",
"]",
")",
";",
"}",
"configs",
".",
"taskInfo",
".",
"visibility",
"=",
"CONSTANT",
".",
"VISIBILITY",
".",
"HIDDEN",
";",
"return",
"wrapper",
";",
"}",
"if",
"(",
"_forward",
"(",
")",
")",
"{",
"tasks",
"=",
"createTasks",
"(",
"configs",
")",
";",
"recipe",
"=",
"function",
"(",
"done",
")",
"{",
"return",
"tasks",
"[",
"0",
"]",
".",
"call",
"(",
"this",
",",
"done",
")",
";",
"}",
";",
"return",
"self",
".",
"create",
"(",
"prefix",
",",
"configs",
".",
"taskInfo",
",",
"configs",
".",
"taskConfig",
",",
"recipe",
",",
"tasks",
")",
";",
"}",
"function",
"_type",
"(",
")",
"{",
"if",
"(",
"configs",
".",
"taskInfo",
".",
"series",
")",
"{",
"return",
"'series'",
";",
"}",
"else",
"if",
"(",
"configs",
".",
"taskInfo",
".",
"parallel",
")",
"{",
"return",
"'parallel'",
";",
"}",
"else",
"if",
"(",
"_",
".",
"size",
"(",
"tasks",
")",
">",
"1",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"tasks",
")",
")",
"{",
"return",
"'series'",
";",
"}",
"else",
"if",
"(",
"_",
".",
"isPlainObject",
"(",
"tasks",
")",
")",
"{",
"return",
"'parallel'",
";",
"}",
"}",
"}",
"function",
"_forward",
"(",
")",
"{",
"return",
"_",
".",
"size",
"(",
"tasks",
")",
"===",
"1",
";",
"}",
"}"
] | Composite task should show up in task treem, and show up in cli if holding task is a named task. | [
"Composite",
"task",
"should",
"show",
"up",
"in",
"task",
"treem",
"and",
"show",
"up",
"in",
"cli",
"if",
"holding",
"task",
"is",
"a",
"named",
"task",
"."
] | 6a8b6b4d20a9f8a36bc74f2beb74524c7338788f | https://github.com/gulp-cookery/gulp-chef/blob/6a8b6b4d20a9f8a36bc74f2beb74524c7338788f/lib/task/factory.js#L212-L257 | train |
mmattozzi/webrepl | webrepl.js | function(port, options) {
var stream = new SimpleStream();
var prompt = 'node> ';
var rs = repl.start({ prompt: prompt, input: stream, output: stream});
var replHttpServer = new ReplHttpServer(prompt, stream, rs, options);
replHttpServer.start(port);
return rs;
} | javascript | function(port, options) {
var stream = new SimpleStream();
var prompt = 'node> ';
var rs = repl.start({ prompt: prompt, input: stream, output: stream});
var replHttpServer = new ReplHttpServer(prompt, stream, rs, options);
replHttpServer.start(port);
return rs;
} | [
"function",
"(",
"port",
",",
"options",
")",
"{",
"var",
"stream",
"=",
"new",
"SimpleStream",
"(",
")",
";",
"var",
"prompt",
"=",
"'node> '",
";",
"var",
"rs",
"=",
"repl",
".",
"start",
"(",
"{",
"prompt",
":",
"prompt",
",",
"input",
":",
"stream",
",",
"output",
":",
"stream",
"}",
")",
";",
"var",
"replHttpServer",
"=",
"new",
"ReplHttpServer",
"(",
"prompt",
",",
"stream",
",",
"rs",
",",
"options",
")",
";",
"replHttpServer",
".",
"start",
"(",
"port",
")",
";",
"return",
"rs",
";",
"}"
] | Starts a repl served via a web console.
@param {Integer} port Port to serve web console
@param {Object} options Set username, password, and hostname options
@return Return the REPLServer. Context can be set on this variable. | [
"Starts",
"a",
"repl",
"served",
"via",
"a",
"web",
"console",
"."
] | af10029031502bce3bb46b660e65d8a768a5eb80 | https://github.com/mmattozzi/webrepl/blob/af10029031502bce3bb46b660e65d8a768a5eb80/webrepl.js#L228-L235 | train |
|
misoproject/storyboard | dist/node/miso.storyboard.deps.0.0.1.js | function(context) {
this._context = context;
if (this.scenes) {
_.each(this.scenes, function(scene) {
scene.setContext(context);
});
}
} | javascript | function(context) {
this._context = context;
if (this.scenes) {
_.each(this.scenes, function(scene) {
scene.setContext(context);
});
}
} | [
"function",
"(",
"context",
")",
"{",
"this",
".",
"_context",
"=",
"context",
";",
"if",
"(",
"this",
".",
"scenes",
")",
"{",
"_",
".",
"each",
"(",
"this",
".",
"scenes",
",",
"function",
"(",
"scene",
")",
"{",
"scene",
".",
"setContext",
"(",
"context",
")",
";",
"}",
")",
";",
"}",
"}"
] | Allows the changing of context. This will alter what 'this'
will be set to inside the transition methods. | [
"Allows",
"the",
"changing",
"of",
"context",
".",
"This",
"will",
"alter",
"what",
"this",
"will",
"be",
"set",
"to",
"inside",
"the",
"transition",
"methods",
"."
] | 96d6cdfe756e0e4f2df7c9a55c414fe93a4c38ec | https://github.com/misoproject/storyboard/blob/96d6cdfe756e0e4f2df7c9a55c414fe93a4c38ec/dist/node/miso.storyboard.deps.0.0.1.js#L314-L321 | train |
|
misoproject/storyboard | dist/node/miso.storyboard.deps.0.0.1.js | leaf_to | function leaf_to( sceneName, argsArr, deferred ) {
this._transitioning = true;
var complete = this._complete = deferred || _.Deferred(),
args = argsArr ? argsArr : [],
handlerComplete = _.Deferred()
.done(_.bind(function() {
this._transitioning = false;
this._current = sceneName;
complete.resolve();
}, this))
.fail(_.bind(function() {
this._transitioning = false;
complete.reject();
}, this));
this.handlers[sceneName].call(this._context, args, handlerComplete);
return complete.promise();
} | javascript | function leaf_to( sceneName, argsArr, deferred ) {
this._transitioning = true;
var complete = this._complete = deferred || _.Deferred(),
args = argsArr ? argsArr : [],
handlerComplete = _.Deferred()
.done(_.bind(function() {
this._transitioning = false;
this._current = sceneName;
complete.resolve();
}, this))
.fail(_.bind(function() {
this._transitioning = false;
complete.reject();
}, this));
this.handlers[sceneName].call(this._context, args, handlerComplete);
return complete.promise();
} | [
"function",
"leaf_to",
"(",
"sceneName",
",",
"argsArr",
",",
"deferred",
")",
"{",
"this",
".",
"_transitioning",
"=",
"true",
";",
"var",
"complete",
"=",
"this",
".",
"_complete",
"=",
"deferred",
"||",
"_",
".",
"Deferred",
"(",
")",
",",
"args",
"=",
"argsArr",
"?",
"argsArr",
":",
"[",
"]",
",",
"handlerComplete",
"=",
"_",
".",
"Deferred",
"(",
")",
".",
"done",
"(",
"_",
".",
"bind",
"(",
"function",
"(",
")",
"{",
"this",
".",
"_transitioning",
"=",
"false",
";",
"this",
".",
"_current",
"=",
"sceneName",
";",
"complete",
".",
"resolve",
"(",
")",
";",
"}",
",",
"this",
")",
")",
".",
"fail",
"(",
"_",
".",
"bind",
"(",
"function",
"(",
")",
"{",
"this",
".",
"_transitioning",
"=",
"false",
";",
"complete",
".",
"reject",
"(",
")",
";",
"}",
",",
"this",
")",
")",
";",
"this",
".",
"handlers",
"[",
"sceneName",
"]",
".",
"call",
"(",
"this",
".",
"_context",
",",
"args",
",",
"handlerComplete",
")",
";",
"return",
"complete",
".",
"promise",
"(",
")",
";",
"}"
] | Used as the to function to scenes which do not have children These scenes only have their own enter and exit. | [
"Used",
"as",
"the",
"to",
"function",
"to",
"scenes",
"which",
"do",
"not",
"have",
"children",
"These",
"scenes",
"only",
"have",
"their",
"own",
"enter",
"and",
"exit",
"."
] | 96d6cdfe756e0e4f2df7c9a55c414fe93a4c38ec | https://github.com/misoproject/storyboard/blob/96d6cdfe756e0e4f2df7c9a55c414fe93a4c38ec/dist/node/miso.storyboard.deps.0.0.1.js#L334-L353 | train |
coderigo/node-highcharts-exporter | lib/node-highcharts-exporter/main.js | function(hcExportRequest,asyncCallback){
var makeThisExportDir = function(mkExportDirErr){
var thisExportDir = [config.processingDir, crypto.createHash('md5').update(Date().toString()+hcExportRequest.svg).digest('hex'),''].join('/');
fs.mkdir(thisExportDir, function(error){
asyncCallback(mkExportDirErr, thisExportDir, hcExportRequest);
});
};
if(fs.existsSync(config.processingDir)){
makeThisExportDir(null);
}
else{
fs.mkdir(config.processingDir, function(error){
makeThisExportDir(error);
});
}
} | javascript | function(hcExportRequest,asyncCallback){
var makeThisExportDir = function(mkExportDirErr){
var thisExportDir = [config.processingDir, crypto.createHash('md5').update(Date().toString()+hcExportRequest.svg).digest('hex'),''].join('/');
fs.mkdir(thisExportDir, function(error){
asyncCallback(mkExportDirErr, thisExportDir, hcExportRequest);
});
};
if(fs.existsSync(config.processingDir)){
makeThisExportDir(null);
}
else{
fs.mkdir(config.processingDir, function(error){
makeThisExportDir(error);
});
}
} | [
"function",
"(",
"hcExportRequest",
",",
"asyncCallback",
")",
"{",
"var",
"makeThisExportDir",
"=",
"function",
"(",
"mkExportDirErr",
")",
"{",
"var",
"thisExportDir",
"=",
"[",
"config",
".",
"processingDir",
",",
"crypto",
".",
"createHash",
"(",
"'md5'",
")",
".",
"update",
"(",
"Date",
"(",
")",
".",
"toString",
"(",
")",
"+",
"hcExportRequest",
".",
"svg",
")",
".",
"digest",
"(",
"'hex'",
")",
",",
"''",
"]",
".",
"join",
"(",
"'/'",
")",
";",
"fs",
".",
"mkdir",
"(",
"thisExportDir",
",",
"function",
"(",
"error",
")",
"{",
"asyncCallback",
"(",
"mkExportDirErr",
",",
"thisExportDir",
",",
"hcExportRequest",
")",
";",
"}",
")",
";",
"}",
";",
"if",
"(",
"fs",
".",
"existsSync",
"(",
"config",
".",
"processingDir",
")",
")",
"{",
"makeThisExportDir",
"(",
"null",
")",
";",
"}",
"else",
"{",
"fs",
".",
"mkdir",
"(",
"config",
".",
"processingDir",
",",
"function",
"(",
"error",
")",
"{",
"makeThisExportDir",
"(",
"error",
")",
";",
"}",
")",
";",
"}",
"}"
] | Makes the directory to process and store the requested chart
@param {object} hcExportRequest The Highcharts POSTed export request object
@param {function} asyncCallback A reference to the async callback
@return {void} Nothing | [
"Makes",
"the",
"directory",
"to",
"process",
"and",
"store",
"the",
"requested",
"chart"
] | 25da7a92af3f1e70802271080854a1d423588a08 | https://github.com/coderigo/node-highcharts-exporter/blob/25da7a92af3f1e70802271080854a1d423588a08/lib/node-highcharts-exporter/main.js#L47-L64 | train |
|
coderigo/node-highcharts-exporter | lib/node-highcharts-exporter/main.js | function(processingDir, hcExportRequest, callback){
var outputChartName = hcExportRequest.filename,
outputFormat = hcExportRequest.type.split('/')[1],
outputExtension = outputFormat == 'svg+xml' ? '.svg' : '.' + outputFormat,
outputFile = outputChartName + outputExtension,
outputFilePath = processingDir + outputFile,
basePNGFile = processingDir + outputChartName + '.png',
baseSVGFile = processingDir + outputChartName + '.svg',
exportInfo = {
fileName : outputChartName,
file : outputFile,
type : outputExtension.replace('.',''),
parentDir : processingDir,
filePath : outputFilePath
};
fs.writeFile(baseSVGFile, hcExportRequest.svg, function(svgErr){
if(outputFormat == 'svg+xml'){
callback(null, exportInfo);
}
else{
svg2png(baseSVGFile, basePNGFile, hcExportRequest.scale, function(err){
switch(outputFormat){
case 'png':
callback(null, exportInfo);
break;
case 'pdf':
var pdf = new pdfkit({size:'A4',layout:'landscape'});
pdf.image(basePNGFile,{width : 700})
.write(outputFilePath, function(){
callback(null, exportInfo);
});
break;
case 'jpeg':
case 'jpg':
jpegConvert(basePNGFile, outputFilePath , {width : 1200}, function(jpegError){
if(jpegError) throw jpegError;
callback(null,exportInfo);
});
break;
default:
var errorMessage = ['Invalid export format requested:',outputFormat+'.','Currently supported outputFormats: svg+xml, pdf, jpeg, jpg, and png.'].join(' ');
callback({message: errorMessage}, null);
}
});
}
});
} | javascript | function(processingDir, hcExportRequest, callback){
var outputChartName = hcExportRequest.filename,
outputFormat = hcExportRequest.type.split('/')[1],
outputExtension = outputFormat == 'svg+xml' ? '.svg' : '.' + outputFormat,
outputFile = outputChartName + outputExtension,
outputFilePath = processingDir + outputFile,
basePNGFile = processingDir + outputChartName + '.png',
baseSVGFile = processingDir + outputChartName + '.svg',
exportInfo = {
fileName : outputChartName,
file : outputFile,
type : outputExtension.replace('.',''),
parentDir : processingDir,
filePath : outputFilePath
};
fs.writeFile(baseSVGFile, hcExportRequest.svg, function(svgErr){
if(outputFormat == 'svg+xml'){
callback(null, exportInfo);
}
else{
svg2png(baseSVGFile, basePNGFile, hcExportRequest.scale, function(err){
switch(outputFormat){
case 'png':
callback(null, exportInfo);
break;
case 'pdf':
var pdf = new pdfkit({size:'A4',layout:'landscape'});
pdf.image(basePNGFile,{width : 700})
.write(outputFilePath, function(){
callback(null, exportInfo);
});
break;
case 'jpeg':
case 'jpg':
jpegConvert(basePNGFile, outputFilePath , {width : 1200}, function(jpegError){
if(jpegError) throw jpegError;
callback(null,exportInfo);
});
break;
default:
var errorMessage = ['Invalid export format requested:',outputFormat+'.','Currently supported outputFormats: svg+xml, pdf, jpeg, jpg, and png.'].join(' ');
callback({message: errorMessage}, null);
}
});
}
});
} | [
"function",
"(",
"processingDir",
",",
"hcExportRequest",
",",
"callback",
")",
"{",
"var",
"outputChartName",
"=",
"hcExportRequest",
".",
"filename",
",",
"outputFormat",
"=",
"hcExportRequest",
".",
"type",
".",
"split",
"(",
"'/'",
")",
"[",
"1",
"]",
",",
"outputExtension",
"=",
"outputFormat",
"==",
"'svg+xml'",
"?",
"'.svg'",
":",
"'.'",
"+",
"outputFormat",
",",
"outputFile",
"=",
"outputChartName",
"+",
"outputExtension",
",",
"outputFilePath",
"=",
"processingDir",
"+",
"outputFile",
",",
"basePNGFile",
"=",
"processingDir",
"+",
"outputChartName",
"+",
"'.png'",
",",
"baseSVGFile",
"=",
"processingDir",
"+",
"outputChartName",
"+",
"'.svg'",
",",
"exportInfo",
"=",
"{",
"fileName",
":",
"outputChartName",
",",
"file",
":",
"outputFile",
",",
"type",
":",
"outputExtension",
".",
"replace",
"(",
"'.'",
",",
"''",
")",
",",
"parentDir",
":",
"processingDir",
",",
"filePath",
":",
"outputFilePath",
"}",
";",
"fs",
".",
"writeFile",
"(",
"baseSVGFile",
",",
"hcExportRequest",
".",
"svg",
",",
"function",
"(",
"svgErr",
")",
"{",
"if",
"(",
"outputFormat",
"==",
"'svg+xml'",
")",
"{",
"callback",
"(",
"null",
",",
"exportInfo",
")",
";",
"}",
"else",
"{",
"svg2png",
"(",
"baseSVGFile",
",",
"basePNGFile",
",",
"hcExportRequest",
".",
"scale",
",",
"function",
"(",
"err",
")",
"{",
"switch",
"(",
"outputFormat",
")",
"{",
"case",
"'png'",
":",
"callback",
"(",
"null",
",",
"exportInfo",
")",
";",
"break",
";",
"case",
"'pdf'",
":",
"var",
"pdf",
"=",
"new",
"pdfkit",
"(",
"{",
"size",
":",
"'A4'",
",",
"layout",
":",
"'landscape'",
"}",
")",
";",
"pdf",
".",
"image",
"(",
"basePNGFile",
",",
"{",
"width",
":",
"700",
"}",
")",
".",
"write",
"(",
"outputFilePath",
",",
"function",
"(",
")",
"{",
"callback",
"(",
"null",
",",
"exportInfo",
")",
";",
"}",
")",
";",
"break",
";",
"case",
"'jpeg'",
":",
"case",
"'jpg'",
":",
"jpegConvert",
"(",
"basePNGFile",
",",
"outputFilePath",
",",
"{",
"width",
":",
"1200",
"}",
",",
"function",
"(",
"jpegError",
")",
"{",
"if",
"(",
"jpegError",
")",
"throw",
"jpegError",
";",
"callback",
"(",
"null",
",",
"exportInfo",
")",
";",
"}",
")",
";",
"break",
";",
"default",
":",
"var",
"errorMessage",
"=",
"[",
"'Invalid export format requested:'",
",",
"outputFormat",
"+",
"'.'",
",",
"'Currently supported outputFormats: svg+xml, pdf, jpeg, jpg, and png.'",
"]",
".",
"join",
"(",
"' '",
")",
";",
"callback",
"(",
"{",
"message",
":",
"errorMessage",
"}",
",",
"null",
")",
";",
"}",
"}",
")",
";",
"}",
"}",
")",
";",
"}"
] | Exports chart into desired format
@param {string} processingDir The processing directory to export the chart to (returned by _makeDirs() function)
@param {object} hcExportRequest The Highcharts POSTed export request object
@param {Function} asyncCallback A reference to the async callback
@return {void} Nothing
Notes: At this juncture, if you request anything other than svg, a PNG will be
created first and if requested, a PDF or JPEG will be then created from
that PNG. | [
"Exports",
"chart",
"into",
"desired",
"format"
] | 25da7a92af3f1e70802271080854a1d423588a08 | https://github.com/coderigo/node-highcharts-exporter/blob/25da7a92af3f1e70802271080854a1d423588a08/lib/node-highcharts-exporter/main.js#L76-L123 | train |
|
platformsh/platformsh-nodejs-helper | src/platformsh.js | num_of_cpus | function num_of_cpus() {
try {
if(process.env['OMP_NUM_THREADS']) {
return process.env['OMP_NUM_THREADS'];
}
return Math.ceil(jsonConfig.info.limits.cpu);
} catch (err) {
throw new Error('Could not get number of cpus');
}
} | javascript | function num_of_cpus() {
try {
if(process.env['OMP_NUM_THREADS']) {
return process.env['OMP_NUM_THREADS'];
}
return Math.ceil(jsonConfig.info.limits.cpu);
} catch (err) {
throw new Error('Could not get number of cpus');
}
} | [
"function",
"num_of_cpus",
"(",
")",
"{",
"try",
"{",
"if",
"(",
"process",
".",
"env",
"[",
"'OMP_NUM_THREADS'",
"]",
")",
"{",
"return",
"process",
".",
"env",
"[",
"'OMP_NUM_THREADS'",
"]",
";",
"}",
"return",
"Math",
".",
"ceil",
"(",
"jsonConfig",
".",
"info",
".",
"limits",
".",
"cpu",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Could not get number of cpus'",
")",
";",
"}",
"}"
] | Read number of CPUs from environment or fallback to the _private_ configuration property
Useful for determining the number of processes to fork. | [
"Read",
"number",
"of",
"CPUs",
"from",
"environment",
"or",
"fallback",
"to",
"the",
"_private_",
"configuration",
"property",
"Useful",
"for",
"determining",
"the",
"number",
"of",
"processes",
"to",
"fork",
"."
] | c614422f4534f67b9c72f13cc1a4498f9a3a7108 | https://github.com/platformsh/platformsh-nodejs-helper/blob/c614422f4534f67b9c72f13cc1a4498f9a3a7108/src/platformsh.js#L19-L29 | train |
platformsh/platformsh-nodejs-helper | src/platformsh.js | config | function config() {
if(!process.env.PLATFORM_PROJECT) {
throw Error('This is not running on platform.sh');
}
return {
application: read_base64_json('PLATFORM_APPLICATION'),
relationships: read_base64_json('PLATFORM_RELATIONSHIPS'),
variables: read_base64_json('PLATFORM_VARIABLES'),
application_name: process.env.PLATFORM_APPLICATION_NAME,
app_dir: process.env.PLATFORM_APP_DIR,
environment: process.env.PLATFORM_ENVIRONMENT,
project: process.env.PLATFORM_PROJECT,
routes: read_base64_json('PLATFORM_ROUTES'),
tree_id: process.env.PLATFORM_TREE_ID,
project_entropy: process.env.PLATFORM_PROJECT_ENTROPY,
branch: process.env.PLATFORM_BRANCH,
document_root: process.env.PLATFORM_DOCUMENT_ROOT,
port: process.env.PORT,
omp_num_threads: num_of_cpus()
};
} | javascript | function config() {
if(!process.env.PLATFORM_PROJECT) {
throw Error('This is not running on platform.sh');
}
return {
application: read_base64_json('PLATFORM_APPLICATION'),
relationships: read_base64_json('PLATFORM_RELATIONSHIPS'),
variables: read_base64_json('PLATFORM_VARIABLES'),
application_name: process.env.PLATFORM_APPLICATION_NAME,
app_dir: process.env.PLATFORM_APP_DIR,
environment: process.env.PLATFORM_ENVIRONMENT,
project: process.env.PLATFORM_PROJECT,
routes: read_base64_json('PLATFORM_ROUTES'),
tree_id: process.env.PLATFORM_TREE_ID,
project_entropy: process.env.PLATFORM_PROJECT_ENTROPY,
branch: process.env.PLATFORM_BRANCH,
document_root: process.env.PLATFORM_DOCUMENT_ROOT,
port: process.env.PORT,
omp_num_threads: num_of_cpus()
};
} | [
"function",
"config",
"(",
")",
"{",
"if",
"(",
"!",
"process",
".",
"env",
".",
"PLATFORM_PROJECT",
")",
"{",
"throw",
"Error",
"(",
"'This is not running on platform.sh'",
")",
";",
"}",
"return",
"{",
"application",
":",
"read_base64_json",
"(",
"'PLATFORM_APPLICATION'",
")",
",",
"relationships",
":",
"read_base64_json",
"(",
"'PLATFORM_RELATIONSHIPS'",
")",
",",
"variables",
":",
"read_base64_json",
"(",
"'PLATFORM_VARIABLES'",
")",
",",
"application_name",
":",
"process",
".",
"env",
".",
"PLATFORM_APPLICATION_NAME",
",",
"app_dir",
":",
"process",
".",
"env",
".",
"PLATFORM_APP_DIR",
",",
"environment",
":",
"process",
".",
"env",
".",
"PLATFORM_ENVIRONMENT",
",",
"project",
":",
"process",
".",
"env",
".",
"PLATFORM_PROJECT",
",",
"routes",
":",
"read_base64_json",
"(",
"'PLATFORM_ROUTES'",
")",
",",
"tree_id",
":",
"process",
".",
"env",
".",
"PLATFORM_TREE_ID",
",",
"project_entropy",
":",
"process",
".",
"env",
".",
"PLATFORM_PROJECT_ENTROPY",
",",
"branch",
":",
"process",
".",
"env",
".",
"PLATFORM_BRANCH",
",",
"document_root",
":",
"process",
".",
"env",
".",
"PLATFORM_DOCUMENT_ROOT",
",",
"port",
":",
"process",
".",
"env",
".",
"PORT",
",",
"omp_num_threads",
":",
"num_of_cpus",
"(",
")",
"}",
";",
"}"
] | Reads Platform.sh configuration from environment and returns a single object | [
"Reads",
"Platform",
".",
"sh",
"configuration",
"from",
"environment",
"and",
"returns",
"a",
"single",
"object"
] | c614422f4534f67b9c72f13cc1a4498f9a3a7108 | https://github.com/platformsh/platformsh-nodejs-helper/blob/c614422f4534f67b9c72f13cc1a4498f9a3a7108/src/platformsh.js#L42-L63 | train |
huffpostdata/in-memory-website | lib/protobuf.js | StaticEndpoint | function StaticEndpoint(properties) {
this.headers = {};
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
} | javascript | function StaticEndpoint(properties) {
this.headers = {};
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
} | [
"function",
"StaticEndpoint",
"(",
"properties",
")",
"{",
"this",
".",
"headers",
"=",
"{",
"}",
";",
"if",
"(",
"properties",
")",
"for",
"(",
"var",
"keys",
"=",
"Object",
".",
"keys",
"(",
"properties",
")",
",",
"i",
"=",
"0",
";",
"i",
"<",
"keys",
".",
"length",
";",
"++",
"i",
")",
"if",
"(",
"properties",
"[",
"keys",
"[",
"i",
"]",
"]",
"!=",
"null",
")",
"this",
"[",
"keys",
"[",
"i",
"]",
"]",
"=",
"properties",
"[",
"keys",
"[",
"i",
"]",
"]",
";",
"}"
] | Properties of a StaticEndpoint.
@memberof staticwebsite
@interface IStaticEndpoint
@property {string} [path] StaticEndpoint path
@property {Object.<string,string>} [headers] StaticEndpoint headers
@property {Uint8Array} [body] StaticEndpoint body
Constructs a new StaticEndpoint.
@memberof staticwebsite
@classdesc Represents a StaticEndpoint.
@constructor
@param {staticwebsite.IStaticEndpoint=} [properties] Properties to set | [
"Properties",
"of",
"a",
"StaticEndpoint",
"."
] | d12048a81ef389ccb522425378f3db99ac071598 | https://github.com/huffpostdata/in-memory-website/blob/d12048a81ef389ccb522425378f3db99ac071598/lib/protobuf.js#L39-L45 | train |
huffpostdata/in-memory-website | lib/protobuf.js | StaticWebsite | function StaticWebsite(properties) {
this.endpoints = [];
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
} | javascript | function StaticWebsite(properties) {
this.endpoints = [];
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
} | [
"function",
"StaticWebsite",
"(",
"properties",
")",
"{",
"this",
".",
"endpoints",
"=",
"[",
"]",
";",
"if",
"(",
"properties",
")",
"for",
"(",
"var",
"keys",
"=",
"Object",
".",
"keys",
"(",
"properties",
")",
",",
"i",
"=",
"0",
";",
"i",
"<",
"keys",
".",
"length",
";",
"++",
"i",
")",
"if",
"(",
"properties",
"[",
"keys",
"[",
"i",
"]",
"]",
"!=",
"null",
")",
"this",
"[",
"keys",
"[",
"i",
"]",
"]",
"=",
"properties",
"[",
"keys",
"[",
"i",
"]",
"]",
";",
"}"
] | Properties of a StaticWebsite.
@memberof staticwebsite
@interface IStaticWebsite
@property {Array.<staticwebsite.IStaticEndpoint>} [endpoints] StaticWebsite endpoints
Constructs a new StaticWebsite.
@memberof staticwebsite
@classdesc Represents a StaticWebsite.
@constructor
@param {staticwebsite.IStaticWebsite=} [properties] Properties to set | [
"Properties",
"of",
"a",
"StaticWebsite",
"."
] | d12048a81ef389ccb522425378f3db99ac071598 | https://github.com/huffpostdata/in-memory-website/blob/d12048a81ef389ccb522425378f3db99ac071598/lib/protobuf.js#L293-L299 | train |
Banno/polymer-lint | src/gulp-task/index.js | transform | function transform(transform, flush) {
const stream = new Transform({ objectMode: true });
stream._transform = transform;
if (typeof flush === 'function') {
stream._flush = flush;
}
return stream;
} | javascript | function transform(transform, flush) {
const stream = new Transform({ objectMode: true });
stream._transform = transform;
if (typeof flush === 'function') {
stream._flush = flush;
}
return stream;
} | [
"function",
"transform",
"(",
"transform",
",",
"flush",
")",
"{",
"const",
"stream",
"=",
"new",
"Transform",
"(",
"{",
"objectMode",
":",
"true",
"}",
")",
";",
"stream",
".",
"_transform",
"=",
"transform",
";",
"if",
"(",
"typeof",
"flush",
"===",
"'function'",
")",
"{",
"stream",
".",
"_flush",
"=",
"flush",
";",
"}",
"return",
"stream",
";",
"}"
] | Convenience function for creating a Transform stream
@param {Function} transform - A function to be called for each File received
@param {Function} [flush] - A function to be called when the stream ends
@returns {external:stream.Transform} | [
"Convenience",
"function",
"for",
"creating",
"a",
"Transform",
"stream"
] | cf4ffdc63837280080b67f496d038d33a3975b6f | https://github.com/Banno/polymer-lint/blob/cf4ffdc63837280080b67f496d038d33a3975b6f/src/gulp-task/index.js#L36-L43 | train |
spyfu/spyfu-vuex-helpers | lib/helpers/simple_instance_setters.js | findInstance | function findInstance(state, stateKey, instanceKey, payload) {
return state[stateKey].find(obj => obj[instanceKey] === payload[instanceKey]);
} | javascript | function findInstance(state, stateKey, instanceKey, payload) {
return state[stateKey].find(obj => obj[instanceKey] === payload[instanceKey]);
} | [
"function",
"findInstance",
"(",
"state",
",",
"stateKey",
",",
"instanceKey",
",",
"payload",
")",
"{",
"return",
"state",
"[",
"stateKey",
"]",
".",
"find",
"(",
"obj",
"=>",
"obj",
"[",
"instanceKey",
"]",
"===",
"payload",
"[",
"instanceKey",
"]",
")",
";",
"}"
] | helper function to find the correct instance | [
"helper",
"function",
"to",
"find",
"the",
"correct",
"instance"
] | 64742e0cbadb3e6ee62d722b26dbc27b87e1a378 | https://github.com/spyfu/spyfu-vuex-helpers/blob/64742e0cbadb3e6ee62d722b26dbc27b87e1a378/lib/helpers/simple_instance_setters.js#L49-L51 | train |
spyfu/spyfu-vuex-helpers | lib/helpers/simple_instance_setters.js | findValue | function findValue(payload, instanceKey) {
for (let key in payload) {
if (key !== instanceKey) {
return payload[key];
}
}
// if we don't have a value, throw an error because the payload is invalid.
/* istanbul ignore next */
throw new Error('Failed to mutate instance, no value found in payload.', payload);
} | javascript | function findValue(payload, instanceKey) {
for (let key in payload) {
if (key !== instanceKey) {
return payload[key];
}
}
// if we don't have a value, throw an error because the payload is invalid.
/* istanbul ignore next */
throw new Error('Failed to mutate instance, no value found in payload.', payload);
} | [
"function",
"findValue",
"(",
"payload",
",",
"instanceKey",
")",
"{",
"for",
"(",
"let",
"key",
"in",
"payload",
")",
"{",
"if",
"(",
"key",
"!==",
"instanceKey",
")",
"{",
"return",
"payload",
"[",
"key",
"]",
";",
"}",
"}",
"throw",
"new",
"Error",
"(",
"'Failed to mutate instance, no value found in payload.'",
",",
"payload",
")",
";",
"}"
] | helper function to find the payload value | [
"helper",
"function",
"to",
"find",
"the",
"payload",
"value"
] | 64742e0cbadb3e6ee62d722b26dbc27b87e1a378 | https://github.com/spyfu/spyfu-vuex-helpers/blob/64742e0cbadb3e6ee62d722b26dbc27b87e1a378/lib/helpers/simple_instance_setters.js#L54-L64 | train |
jhermsmeier/node-flightstats | lib/alerts/index.js | function( maxId, callback ) {
if( typeof maxId === 'function' ) {
callback = maxId
maxId = null
}
var self = this
var id = maxId ? '/' + maxId : ''
return this.client._clientRequest({
url: '/alerts/rest/v1/json/list' + id,
}, function( error, data ) {
callback.call( self.client, error, data )
})
} | javascript | function( maxId, callback ) {
if( typeof maxId === 'function' ) {
callback = maxId
maxId = null
}
var self = this
var id = maxId ? '/' + maxId : ''
return this.client._clientRequest({
url: '/alerts/rest/v1/json/list' + id,
}, function( error, data ) {
callback.call( self.client, error, data )
})
} | [
"function",
"(",
"maxId",
",",
"callback",
")",
"{",
"if",
"(",
"typeof",
"maxId",
"===",
"'function'",
")",
"{",
"callback",
"=",
"maxId",
"maxId",
"=",
"null",
"}",
"var",
"self",
"=",
"this",
"var",
"id",
"=",
"maxId",
"?",
"'/'",
"+",
"maxId",
":",
"''",
"return",
"this",
".",
"client",
".",
"_clientRequest",
"(",
"{",
"url",
":",
"'/alerts/rest/v1/json/list'",
"+",
"id",
",",
"}",
",",
"function",
"(",
"error",
",",
"data",
")",
"{",
"callback",
".",
"call",
"(",
"self",
".",
"client",
",",
"error",
",",
"data",
")",
"}",
")",
"}"
] | List all registered rule IDs,
optionally only up to a given `maxId`
@param {String} maxId - optional, list only rules that are less than the specified max Rule ID
@param {Function} callback( error, rules )
@return {Request} | [
"List",
"all",
"registered",
"rule",
"IDs",
"optionally",
"only",
"up",
"to",
"a",
"given",
"maxId"
] | 023d46e11db4f4ba45ed414b1dc23084b1c9749d | https://github.com/jhermsmeier/node-flightstats/blob/023d46e11db4f4ba45ed414b1dc23084b1c9749d/lib/alerts/index.js#L33-L49 | train |
|
jhermsmeier/node-flightstats | lib/alerts/index.js | function( id, callback ) {
var self = this
return this.client._clientRequest({
url: '/alerts/rest/v1/json/get/' + id,
}, function( error, data ) {
callback.call( self.client, error, data )
})
} | javascript | function( id, callback ) {
var self = this
return this.client._clientRequest({
url: '/alerts/rest/v1/json/get/' + id,
}, function( error, data ) {
callback.call( self.client, error, data )
})
} | [
"function",
"(",
"id",
",",
"callback",
")",
"{",
"var",
"self",
"=",
"this",
"return",
"this",
".",
"client",
".",
"_clientRequest",
"(",
"{",
"url",
":",
"'/alerts/rest/v1/json/get/'",
"+",
"id",
",",
"}",
",",
"function",
"(",
"error",
",",
"data",
")",
"{",
"callback",
".",
"call",
"(",
"self",
".",
"client",
",",
"error",
",",
"data",
")",
"}",
")",
"}"
] | Retrieve a registered rule by it's ID
@param {String} id
@param {Function} callback( error, result )
@return {Request} | [
"Retrieve",
"a",
"registered",
"rule",
"by",
"it",
"s",
"ID"
] | 023d46e11db4f4ba45ed414b1dc23084b1c9749d | https://github.com/jhermsmeier/node-flightstats/blob/023d46e11db4f4ba45ed414b1dc23084b1c9749d/lib/alerts/index.js#L57-L64 | train |
|
jhermsmeier/node-flightstats | lib/alerts/index.js | function( options, callback ) {
var self = this
var path = '/alerts/rest/v1/json/testdelivery/' +
options.airlineCode + '/' + options.flightNumber +
'/from/' + options.departureAirport +
'/to/' + options.arrivalAirport
var extensions = [
'includeNewFields',
'useInlinedReferences'
]
if( Array.isArray( options.extendedOptions ) ) {
extensions = extensions.concat( options.extendedOptions )
}
return this.client._clientRequest({
url: path,
extendedOptions: extensions,
qs: {
deliverTo: options.deliverTo,
type: options.type || 'JSON',
},
}, function( error, data ) {
callback.call( self.client, error, data )
})
} | javascript | function( options, callback ) {
var self = this
var path = '/alerts/rest/v1/json/testdelivery/' +
options.airlineCode + '/' + options.flightNumber +
'/from/' + options.departureAirport +
'/to/' + options.arrivalAirport
var extensions = [
'includeNewFields',
'useInlinedReferences'
]
if( Array.isArray( options.extendedOptions ) ) {
extensions = extensions.concat( options.extendedOptions )
}
return this.client._clientRequest({
url: path,
extendedOptions: extensions,
qs: {
deliverTo: options.deliverTo,
type: options.type || 'JSON',
},
}, function( error, data ) {
callback.call( self.client, error, data )
})
} | [
"function",
"(",
"options",
",",
"callback",
")",
"{",
"var",
"self",
"=",
"this",
"var",
"path",
"=",
"'/alerts/rest/v1/json/testdelivery/'",
"+",
"options",
".",
"airlineCode",
"+",
"'/'",
"+",
"options",
".",
"flightNumber",
"+",
"'/from/'",
"+",
"options",
".",
"departureAirport",
"+",
"'/to/'",
"+",
"options",
".",
"arrivalAirport",
"var",
"extensions",
"=",
"[",
"'includeNewFields'",
",",
"'useInlinedReferences'",
"]",
"if",
"(",
"Array",
".",
"isArray",
"(",
"options",
".",
"extendedOptions",
")",
")",
"{",
"extensions",
"=",
"extensions",
".",
"concat",
"(",
"options",
".",
"extendedOptions",
")",
"}",
"return",
"this",
".",
"client",
".",
"_clientRequest",
"(",
"{",
"url",
":",
"path",
",",
"extendedOptions",
":",
"extensions",
",",
"qs",
":",
"{",
"deliverTo",
":",
"options",
".",
"deliverTo",
",",
"type",
":",
"options",
".",
"type",
"||",
"'JSON'",
",",
"}",
",",
"}",
",",
"function",
"(",
"error",
",",
"data",
")",
"{",
"callback",
".",
"call",
"(",
"self",
".",
"client",
",",
"error",
",",
"data",
")",
"}",
")",
"}"
] | Simulate a fake event for a fake flight
@param {Object} options
@param {String} options.airlineCode
@param {String} options.arrivalAirport
@param {String} options.deliverTo (can be smtp://[email protected] for testing)
@param {String} options.departureAirport
@param {String} options.flightNumber
@param {?Array<String>} [options.extendedOptions] optional
@param {String} options.type - optional (JSON|XML), defaults to JSON
@param {Function} callback( error, result )
@return {Request} | [
"Simulate",
"a",
"fake",
"event",
"for",
"a",
"fake",
"flight"
] | 023d46e11db4f4ba45ed414b1dc23084b1c9749d | https://github.com/jhermsmeier/node-flightstats/blob/023d46e11db4f4ba45ed414b1dc23084b1c9749d/lib/alerts/index.js#L94-L123 | train |
|
jhermsmeier/node-flightstats | lib/alerts/index.js | function( options, callback ) {
var self = this
var events = options.events || [ 'all' ]
var year = options.date.getFullYear()
var month = options.date.getMonth() + 1
var day = options.date.getDate()
var direction = /^dep/i.test( options.direction ) ?
'departing' : 'arriving'
var path = '/alerts/rest/v1/json/create/' +
options.airlineCode + '/' + options.flightNumber +
'/from/' + options.departureAirport +
'/to/' + options.arrivalAirport +
'/' + direction + '/' + year + '/' + month + '/' + day
var extensions = [
'includeNewFields',
'useInlinedReferences'
]
if( Array.isArray( options.extendedOptions ) ) {
extensions = extensions.concat( options.extendedOptions )
}
var query = {
name: options.name,
desc: options.desc,
codeType: options.codeType,
events: events.join(),
deliverTo: options.deliverTo,
type: options.type || 'JSON',
}
// Add underscore-prefixed custom data
// key-value pairs to query parameters
if( options.data != null ) {
Object.keys( options.data ).forEach( function( k ) {
query[ '_' + k ] = options.data[k]
})
}
return this.client._clientRequest({
url: path,
extendedOptions: extensions,
qs: query,
}, function( error, data ) {
callback.call( self.client, error, data )
})
} | javascript | function( options, callback ) {
var self = this
var events = options.events || [ 'all' ]
var year = options.date.getFullYear()
var month = options.date.getMonth() + 1
var day = options.date.getDate()
var direction = /^dep/i.test( options.direction ) ?
'departing' : 'arriving'
var path = '/alerts/rest/v1/json/create/' +
options.airlineCode + '/' + options.flightNumber +
'/from/' + options.departureAirport +
'/to/' + options.arrivalAirport +
'/' + direction + '/' + year + '/' + month + '/' + day
var extensions = [
'includeNewFields',
'useInlinedReferences'
]
if( Array.isArray( options.extendedOptions ) ) {
extensions = extensions.concat( options.extendedOptions )
}
var query = {
name: options.name,
desc: options.desc,
codeType: options.codeType,
events: events.join(),
deliverTo: options.deliverTo,
type: options.type || 'JSON',
}
// Add underscore-prefixed custom data
// key-value pairs to query parameters
if( options.data != null ) {
Object.keys( options.data ).forEach( function( k ) {
query[ '_' + k ] = options.data[k]
})
}
return this.client._clientRequest({
url: path,
extendedOptions: extensions,
qs: query,
}, function( error, data ) {
callback.call( self.client, error, data )
})
} | [
"function",
"(",
"options",
",",
"callback",
")",
"{",
"var",
"self",
"=",
"this",
"var",
"events",
"=",
"options",
".",
"events",
"||",
"[",
"'all'",
"]",
"var",
"year",
"=",
"options",
".",
"date",
".",
"getFullYear",
"(",
")",
"var",
"month",
"=",
"options",
".",
"date",
".",
"getMonth",
"(",
")",
"+",
"1",
"var",
"day",
"=",
"options",
".",
"date",
".",
"getDate",
"(",
")",
"var",
"direction",
"=",
"/",
"^dep",
"/",
"i",
".",
"test",
"(",
"options",
".",
"direction",
")",
"?",
"'departing'",
":",
"'arriving'",
"var",
"path",
"=",
"'/alerts/rest/v1/json/create/'",
"+",
"options",
".",
"airlineCode",
"+",
"'/'",
"+",
"options",
".",
"flightNumber",
"+",
"'/from/'",
"+",
"options",
".",
"departureAirport",
"+",
"'/to/'",
"+",
"options",
".",
"arrivalAirport",
"+",
"'/'",
"+",
"direction",
"+",
"'/'",
"+",
"year",
"+",
"'/'",
"+",
"month",
"+",
"'/'",
"+",
"day",
"var",
"extensions",
"=",
"[",
"'includeNewFields'",
",",
"'useInlinedReferences'",
"]",
"if",
"(",
"Array",
".",
"isArray",
"(",
"options",
".",
"extendedOptions",
")",
")",
"{",
"extensions",
"=",
"extensions",
".",
"concat",
"(",
"options",
".",
"extendedOptions",
")",
"}",
"var",
"query",
"=",
"{",
"name",
":",
"options",
".",
"name",
",",
"desc",
":",
"options",
".",
"desc",
",",
"codeType",
":",
"options",
".",
"codeType",
",",
"events",
":",
"events",
".",
"join",
"(",
")",
",",
"deliverTo",
":",
"options",
".",
"deliverTo",
",",
"type",
":",
"options",
".",
"type",
"||",
"'JSON'",
",",
"}",
"if",
"(",
"options",
".",
"data",
"!=",
"null",
")",
"{",
"Object",
".",
"keys",
"(",
"options",
".",
"data",
")",
".",
"forEach",
"(",
"function",
"(",
"k",
")",
"{",
"query",
"[",
"'_'",
"+",
"k",
"]",
"=",
"options",
".",
"data",
"[",
"k",
"]",
"}",
")",
"}",
"return",
"this",
".",
"client",
".",
"_clientRequest",
"(",
"{",
"url",
":",
"path",
",",
"extendedOptions",
":",
"extensions",
",",
"qs",
":",
"query",
",",
"}",
",",
"function",
"(",
"error",
",",
"data",
")",
"{",
"callback",
".",
"call",
"(",
"self",
".",
"client",
",",
"error",
",",
"data",
")",
"}",
")",
"}"
] | Create an flight alert rule
@param {Object} options
@param {String} options.airlineCode
@param {String} options.arrivalAirport
@param {String} options.codeType
@param {String} options.data - optional, custom key/value pairs to be included in delivered alerts
@param {String} options.date
@param {String} options.deliverTo - where alert will be delivered to, must accept POST data
@param {String} options.departureAirport
@param {String} options.desc - optional, description of the rule
@param {String} options.direction - optional (arr|dep), defaults to arriving
@param {String} options.events - comma separated list of events that should be emitted for the flight, defaults to [all]
@param {String} options.flightNumber
@param {String} options.name - optional, defaults to "Default"
@param {String} options.type - optional (JSON|XML), defaults to JSON
@param {?Array<String>} [options.extendedOptions] optional
@param {Function} callback( error, result )
@return {Request} | [
"Create",
"an",
"flight",
"alert",
"rule"
] | 023d46e11db4f4ba45ed414b1dc23084b1c9749d | https://github.com/jhermsmeier/node-flightstats/blob/023d46e11db4f4ba45ed414b1dc23084b1c9749d/lib/alerts/index.js#L145-L195 | train |
|
GeoXForm/esri-to-geojson | src/index.js | csvFieldNames | function csvFieldNames (inFields) {
const fieldNames = _.map(inFields, (field) => {
return convertFieldName(field)
})
return fieldNames
} | javascript | function csvFieldNames (inFields) {
const fieldNames = _.map(inFields, (field) => {
return convertFieldName(field)
})
return fieldNames
} | [
"function",
"csvFieldNames",
"(",
"inFields",
")",
"{",
"const",
"fieldNames",
"=",
"_",
".",
"map",
"(",
"inFields",
",",
"(",
"field",
")",
"=>",
"{",
"return",
"convertFieldName",
"(",
"field",
")",
"}",
")",
"return",
"fieldNames",
"}"
] | Parse array of field names and sanitize them
@param {array} inFields - array of field names
@returns {array} fieldNames - array of sanitized field Names | [
"Parse",
"array",
"of",
"field",
"names",
"and",
"sanitize",
"them"
] | 55d32955d8ef0acb26de70025539e7c7a37d838e | https://github.com/GeoXForm/esri-to-geojson/blob/55d32955d8ef0acb26de70025539e7c7a37d838e/src/index.js#L35-L40 | train |
GeoXForm/esri-to-geojson | src/index.js | convertCSVGeom | function convertCSVGeom (columns, row) {
const geometry = _.reduce(columns, (tempGeom, colName, i) => {
if (isLongitudeField(colName)) tempGeom.coordinates[0] = parseFloat(row[i])
else if (isLatitudeField(colName)) tempGeom.coordinates[1] = parseFloat(row[i])
return tempGeom
}, { type: 'Point', coordinates: [null, null] })
return validGeometry(geometry) ? geometry : null
} | javascript | function convertCSVGeom (columns, row) {
const geometry = _.reduce(columns, (tempGeom, colName, i) => {
if (isLongitudeField(colName)) tempGeom.coordinates[0] = parseFloat(row[i])
else if (isLatitudeField(colName)) tempGeom.coordinates[1] = parseFloat(row[i])
return tempGeom
}, { type: 'Point', coordinates: [null, null] })
return validGeometry(geometry) ? geometry : null
} | [
"function",
"convertCSVGeom",
"(",
"columns",
",",
"row",
")",
"{",
"const",
"geometry",
"=",
"_",
".",
"reduce",
"(",
"columns",
",",
"(",
"tempGeom",
",",
"colName",
",",
"i",
")",
"=>",
"{",
"if",
"(",
"isLongitudeField",
"(",
"colName",
")",
")",
"tempGeom",
".",
"coordinates",
"[",
"0",
"]",
"=",
"parseFloat",
"(",
"row",
"[",
"i",
"]",
")",
"else",
"if",
"(",
"isLatitudeField",
"(",
"colName",
")",
")",
"tempGeom",
".",
"coordinates",
"[",
"1",
"]",
"=",
"parseFloat",
"(",
"row",
"[",
"i",
"]",
")",
"return",
"tempGeom",
"}",
",",
"{",
"type",
":",
"'Point'",
",",
"coordinates",
":",
"[",
"null",
",",
"null",
"]",
"}",
")",
"return",
"validGeometry",
"(",
"geometry",
")",
"?",
"geometry",
":",
"null",
"}"
] | Convert CSV geom to geojson
@param {array} fieldNames - array of field names
@param {array} feature - individual feature
@returns {object} geometry - geometry object | [
"Convert",
"CSV",
"geom",
"to",
"geojson"
] | 55d32955d8ef0acb26de70025539e7c7a37d838e | https://github.com/GeoXForm/esri-to-geojson/blob/55d32955d8ef0acb26de70025539e7c7a37d838e/src/index.js#L50-L57 | train |
GeoXForm/esri-to-geojson | src/index.js | validGeometry | function validGeometry (geometry) {
return geometry.coordinates.length === 2 && (geometry.coordinates[0] && geometry.coordinates[1]) ? true : false
} | javascript | function validGeometry (geometry) {
return geometry.coordinates.length === 2 && (geometry.coordinates[0] && geometry.coordinates[1]) ? true : false
} | [
"function",
"validGeometry",
"(",
"geometry",
")",
"{",
"return",
"geometry",
".",
"coordinates",
".",
"length",
"===",
"2",
"&&",
"(",
"geometry",
".",
"coordinates",
"[",
"0",
"]",
"&&",
"geometry",
".",
"coordinates",
"[",
"1",
"]",
")",
"?",
"true",
":",
"false",
"}"
] | Check to see if geometry object is valid
@param {object} geometry - built geometry object
@return {boolean} validGeom - whether or not geom is valid | [
"Check",
"to",
"see",
"if",
"geometry",
"object",
"is",
"valid"
] | 55d32955d8ef0acb26de70025539e7c7a37d838e | https://github.com/GeoXForm/esri-to-geojson/blob/55d32955d8ef0acb26de70025539e7c7a37d838e/src/index.js#L88-L90 | train |
GeoXForm/esri-to-geojson | src/index.js | constructProps | function constructProps (fieldNames, feature) {
const properties = _.reduce(fieldNames, (tempProps, fieldName, key) => {
tempProps[fieldName] = (!isNaN(feature[key])) ? parseFloat(feature[key]) : feature[key]
return tempProps
}, {})
return properties
} | javascript | function constructProps (fieldNames, feature) {
const properties = _.reduce(fieldNames, (tempProps, fieldName, key) => {
tempProps[fieldName] = (!isNaN(feature[key])) ? parseFloat(feature[key]) : feature[key]
return tempProps
}, {})
return properties
} | [
"function",
"constructProps",
"(",
"fieldNames",
",",
"feature",
")",
"{",
"const",
"properties",
"=",
"_",
".",
"reduce",
"(",
"fieldNames",
",",
"(",
"tempProps",
",",
"fieldName",
",",
"key",
")",
"=>",
"{",
"tempProps",
"[",
"fieldName",
"]",
"=",
"(",
"!",
"isNaN",
"(",
"feature",
"[",
"key",
"]",
")",
")",
"?",
"parseFloat",
"(",
"feature",
"[",
"key",
"]",
")",
":",
"feature",
"[",
"key",
"]",
"return",
"tempProps",
"}",
",",
"{",
"}",
")",
"return",
"properties",
"}"
] | Covert fields into properties object
@param {array} fieldNames - array of field names
@param {array} feature - individual feature
@returns {object} properties - property object | [
"Covert",
"fields",
"into",
"properties",
"object"
] | 55d32955d8ef0acb26de70025539e7c7a37d838e | https://github.com/GeoXForm/esri-to-geojson/blob/55d32955d8ef0acb26de70025539e7c7a37d838e/src/index.js#L99-L105 | train |
GeoXForm/esri-to-geojson | src/index.js | convertFields | function convertFields (infields) {
const fields = {}
_.each(infields, (field) => {
field.outName = convertFieldName(field.name)
fields[field.name] = field
})
return fields
} | javascript | function convertFields (infields) {
const fields = {}
_.each(infields, (field) => {
field.outName = convertFieldName(field.name)
fields[field.name] = field
})
return fields
} | [
"function",
"convertFields",
"(",
"infields",
")",
"{",
"const",
"fields",
"=",
"{",
"}",
"_",
".",
"each",
"(",
"infields",
",",
"(",
"field",
")",
"=>",
"{",
"field",
".",
"outName",
"=",
"convertFieldName",
"(",
"field",
".",
"name",
")",
"fields",
"[",
"field",
".",
"name",
"]",
"=",
"field",
"}",
")",
"return",
"fields",
"}"
] | Converts a set of fields to have names that work well in JS
@params {object} inFields - the original fields object from the esri json
@returns {object} fields - converted fields
@private | [
"Converts",
"a",
"set",
"of",
"fields",
"to",
"have",
"names",
"that",
"work",
"well",
"in",
"JS"
] | 55d32955d8ef0acb26de70025539e7c7a37d838e | https://github.com/GeoXForm/esri-to-geojson/blob/55d32955d8ef0acb26de70025539e7c7a37d838e/src/index.js#L138-L146 | train |
GeoXForm/esri-to-geojson | src/index.js | convertFieldName | function convertFieldName (name) {
const regex = new RegExp(/\.|\(|\)/g)
return name.replace(regex, '').replace(/\s/g, '_')
} | javascript | function convertFieldName (name) {
const regex = new RegExp(/\.|\(|\)/g)
return name.replace(regex, '').replace(/\s/g, '_')
} | [
"function",
"convertFieldName",
"(",
"name",
")",
"{",
"const",
"regex",
"=",
"new",
"RegExp",
"(",
"/",
"\\.|\\(|\\)",
"/",
"g",
")",
"return",
"name",
".",
"replace",
"(",
"regex",
",",
"''",
")",
".",
"replace",
"(",
"/",
"\\s",
"/",
"g",
",",
"'_'",
")",
"}"
] | Converts a single field name to a legal javascript object key
@params {string} name - the original field name
@returns {string} outName - a cleansed field name
@private | [
"Converts",
"a",
"single",
"field",
"name",
"to",
"a",
"legal",
"javascript",
"object",
"key"
] | 55d32955d8ef0acb26de70025539e7c7a37d838e | https://github.com/GeoXForm/esri-to-geojson/blob/55d32955d8ef0acb26de70025539e7c7a37d838e/src/index.js#L156-L159 | train |
GeoXForm/esri-to-geojson | src/index.js | transformFeature | function transformFeature (feature, fields) {
const attributes = {}
// first transform each of the features to the converted field name and transformed value
if (feature.attributes && Object.keys(feature.attributes)) {
_.each(Object.keys(feature.attributes), (name) => {
let attr = {}
attr[name] = feature.attributes[name]
try {
attributes[fields[name].outName] = convertAttribute(attr, fields[name])
} catch (e) {
console.error('Field was missing from attribute')
}
})
}
return {
type: 'Feature',
properties: attributes,
geometry: parseGeometry(feature.geometry)
}
} | javascript | function transformFeature (feature, fields) {
const attributes = {}
// first transform each of the features to the converted field name and transformed value
if (feature.attributes && Object.keys(feature.attributes)) {
_.each(Object.keys(feature.attributes), (name) => {
let attr = {}
attr[name] = feature.attributes[name]
try {
attributes[fields[name].outName] = convertAttribute(attr, fields[name])
} catch (e) {
console.error('Field was missing from attribute')
}
})
}
return {
type: 'Feature',
properties: attributes,
geometry: parseGeometry(feature.geometry)
}
} | [
"function",
"transformFeature",
"(",
"feature",
",",
"fields",
")",
"{",
"const",
"attributes",
"=",
"{",
"}",
"if",
"(",
"feature",
".",
"attributes",
"&&",
"Object",
".",
"keys",
"(",
"feature",
".",
"attributes",
")",
")",
"{",
"_",
".",
"each",
"(",
"Object",
".",
"keys",
"(",
"feature",
".",
"attributes",
")",
",",
"(",
"name",
")",
"=>",
"{",
"let",
"attr",
"=",
"{",
"}",
"attr",
"[",
"name",
"]",
"=",
"feature",
".",
"attributes",
"[",
"name",
"]",
"try",
"{",
"attributes",
"[",
"fields",
"[",
"name",
"]",
".",
"outName",
"]",
"=",
"convertAttribute",
"(",
"attr",
",",
"fields",
"[",
"name",
"]",
")",
"}",
"catch",
"(",
"e",
")",
"{",
"console",
".",
"error",
"(",
"'Field was missing from attribute'",
")",
"}",
"}",
")",
"}",
"return",
"{",
"type",
":",
"'Feature'",
",",
"properties",
":",
"attributes",
",",
"geometry",
":",
"parseGeometry",
"(",
"feature",
".",
"geometry",
")",
"}",
"}"
] | Converts a single feature from esri json to geojson
@param {object} feature - a single esri feature
@param {object} fields - the fields object from the service
@returns {object} feature - a geojson feature
@private | [
"Converts",
"a",
"single",
"feature",
"from",
"esri",
"json",
"to",
"geojson"
] | 55d32955d8ef0acb26de70025539e7c7a37d838e | https://github.com/GeoXForm/esri-to-geojson/blob/55d32955d8ef0acb26de70025539e7c7a37d838e/src/index.js#L170-L191 | train |
GeoXForm/esri-to-geojson | src/index.js | convertAttribute | function convertAttribute (attribute, field) {
const inValue = attribute[field.name]
let value
if (inValue === null) return inValue
if (field.domain && field.domain.type === 'codedValue') {
value = cvd(inValue, field)
} else if (field.type === 'esriFieldTypeDate') {
try {
value = new Date(inValue).toISOString()
} catch (e) {
value = inValue
}
} else {
value = inValue
}
return value
} | javascript | function convertAttribute (attribute, field) {
const inValue = attribute[field.name]
let value
if (inValue === null) return inValue
if (field.domain && field.domain.type === 'codedValue') {
value = cvd(inValue, field)
} else if (field.type === 'esriFieldTypeDate') {
try {
value = new Date(inValue).toISOString()
} catch (e) {
value = inValue
}
} else {
value = inValue
}
return value
} | [
"function",
"convertAttribute",
"(",
"attribute",
",",
"field",
")",
"{",
"const",
"inValue",
"=",
"attribute",
"[",
"field",
".",
"name",
"]",
"let",
"value",
"if",
"(",
"inValue",
"===",
"null",
")",
"return",
"inValue",
"if",
"(",
"field",
".",
"domain",
"&&",
"field",
".",
"domain",
".",
"type",
"===",
"'codedValue'",
")",
"{",
"value",
"=",
"cvd",
"(",
"inValue",
",",
"field",
")",
"}",
"else",
"if",
"(",
"field",
".",
"type",
"===",
"'esriFieldTypeDate'",
")",
"{",
"try",
"{",
"value",
"=",
"new",
"Date",
"(",
"inValue",
")",
".",
"toISOString",
"(",
")",
"}",
"catch",
"(",
"e",
")",
"{",
"value",
"=",
"inValue",
"}",
"}",
"else",
"{",
"value",
"=",
"inValue",
"}",
"return",
"value",
"}"
] | Decodes an attributes CVD and standardizes any date fields
@params {object} attribute - a single esri feature attribute
@params {object} field - the field metadata describing that attribute
@returns {object} outAttribute - the converted attribute
@private | [
"Decodes",
"an",
"attributes",
"CVD",
"and",
"standardizes",
"any",
"date",
"fields"
] | 55d32955d8ef0acb26de70025539e7c7a37d838e | https://github.com/GeoXForm/esri-to-geojson/blob/55d32955d8ef0acb26de70025539e7c7a37d838e/src/index.js#L202-L220 | train |
GeoXForm/esri-to-geojson | src/index.js | cvd | function cvd (value, field) {
const domain = _.find(field.domain.codedValues, (d) => {
return value === d.code
})
return domain ? domain.name : value
} | javascript | function cvd (value, field) {
const domain = _.find(field.domain.codedValues, (d) => {
return value === d.code
})
return domain ? domain.name : value
} | [
"function",
"cvd",
"(",
"value",
",",
"field",
")",
"{",
"const",
"domain",
"=",
"_",
".",
"find",
"(",
"field",
".",
"domain",
".",
"codedValues",
",",
"(",
"d",
")",
"=>",
"{",
"return",
"value",
"===",
"d",
".",
"code",
"}",
")",
"return",
"domain",
"?",
"domain",
".",
"name",
":",
"value",
"}"
] | Looks up a value from a coded domain
@params {integer} value - The original field value
@params {object} field - metadata describing the attribute field
@returns {string/integerfloat} - The decoded field value | [
"Looks",
"up",
"a",
"value",
"from",
"a",
"coded",
"domain"
] | 55d32955d8ef0acb26de70025539e7c7a37d838e | https://github.com/GeoXForm/esri-to-geojson/blob/55d32955d8ef0acb26de70025539e7c7a37d838e/src/index.js#L230-L235 | train |
GeoXForm/esri-to-geojson | src/index.js | parseGeometry | function parseGeometry (geometry) {
try {
const parsed = geometry ? arcgisToGeoJSON(geometry) : null
if (parsed && parsed.type && parsed.coordinates) return parsed
else {
return null
}
} catch (e) {
console.error(e)
return null
}
} | javascript | function parseGeometry (geometry) {
try {
const parsed = geometry ? arcgisToGeoJSON(geometry) : null
if (parsed && parsed.type && parsed.coordinates) return parsed
else {
return null
}
} catch (e) {
console.error(e)
return null
}
} | [
"function",
"parseGeometry",
"(",
"geometry",
")",
"{",
"try",
"{",
"const",
"parsed",
"=",
"geometry",
"?",
"arcgisToGeoJSON",
"(",
"geometry",
")",
":",
"null",
"if",
"(",
"parsed",
"&&",
"parsed",
".",
"type",
"&&",
"parsed",
".",
"coordinates",
")",
"return",
"parsed",
"else",
"{",
"return",
"null",
"}",
"}",
"catch",
"(",
"e",
")",
"{",
"console",
".",
"error",
"(",
"e",
")",
"return",
"null",
"}",
"}"
] | Convert an esri geometry to a geojson geometry
@param {object} geometry - an esri geometry object
@return {object} geojson geometry
@private | [
"Convert",
"an",
"esri",
"geometry",
"to",
"a",
"geojson",
"geometry"
] | 55d32955d8ef0acb26de70025539e7c7a37d838e | https://github.com/GeoXForm/esri-to-geojson/blob/55d32955d8ef0acb26de70025539e7c7a37d838e/src/index.js#L245-L256 | train |
spyfu/spyfu-vuex-helpers | lib/helpers/map_two_way_state.js | createSetter | function createSetter(namespace, mappings) {
let mutation = mappings.mutation;
if (namespace) {
mutation = namespace + '/' + mutation;
}
return function (value) {
this.$store.commit(mutation, value)
};
} | javascript | function createSetter(namespace, mappings) {
let mutation = mappings.mutation;
if (namespace) {
mutation = namespace + '/' + mutation;
}
return function (value) {
this.$store.commit(mutation, value)
};
} | [
"function",
"createSetter",
"(",
"namespace",
",",
"mappings",
")",
"{",
"let",
"mutation",
"=",
"mappings",
".",
"mutation",
";",
"if",
"(",
"namespace",
")",
"{",
"mutation",
"=",
"namespace",
"+",
"'/'",
"+",
"mutation",
";",
"}",
"return",
"function",
"(",
"value",
")",
"{",
"this",
".",
"$store",
".",
"commit",
"(",
"mutation",
",",
"value",
")",
"}",
";",
"}"
] | create a setter for computed properties | [
"create",
"a",
"setter",
"for",
"computed",
"properties"
] | 64742e0cbadb3e6ee62d722b26dbc27b87e1a378 | https://github.com/spyfu/spyfu-vuex-helpers/blob/64742e0cbadb3e6ee62d722b26dbc27b87e1a378/lib/helpers/map_two_way_state.js#L82-L92 | train |
Banno/polymer-lint | lib/util/filterErrors.js | disabledRules | function disabledRules(directives) {
return directives.reduce((disabled, _ref) => {
let name = _ref.name;
let args = _ref.args;
if (name === 'bplint-disable') {
for (const ruleName of args) {
disabled[ruleName] = true;
}
} else if (name === 'bplint-enable') {
for (const ruleName of args) {
if (disabled[ruleName]) {
disabled[ruleName] = false;
}
}
}
return disabled;
}, {});
} | javascript | function disabledRules(directives) {
return directives.reduce((disabled, _ref) => {
let name = _ref.name;
let args = _ref.args;
if (name === 'bplint-disable') {
for (const ruleName of args) {
disabled[ruleName] = true;
}
} else if (name === 'bplint-enable') {
for (const ruleName of args) {
if (disabled[ruleName]) {
disabled[ruleName] = false;
}
}
}
return disabled;
}, {});
} | [
"function",
"disabledRules",
"(",
"directives",
")",
"{",
"return",
"directives",
".",
"reduce",
"(",
"(",
"disabled",
",",
"_ref",
")",
"=>",
"{",
"let",
"name",
"=",
"_ref",
".",
"name",
";",
"let",
"args",
"=",
"_ref",
".",
"args",
";",
"if",
"(",
"name",
"===",
"'bplint-disable'",
")",
"{",
"for",
"(",
"const",
"ruleName",
"of",
"args",
")",
"{",
"disabled",
"[",
"ruleName",
"]",
"=",
"true",
";",
"}",
"}",
"else",
"if",
"(",
"name",
"===",
"'bplint-enable'",
")",
"{",
"for",
"(",
"const",
"ruleName",
"of",
"args",
")",
"{",
"if",
"(",
"disabled",
"[",
"ruleName",
"]",
")",
"{",
"disabled",
"[",
"ruleName",
"]",
"=",
"false",
";",
"}",
"}",
"}",
"return",
"disabled",
";",
"}",
",",
"{",
"}",
")",
";",
"}"
] | Given an array of directives, returns the names of rules disabled by bplint-disable directives and not subsequently re-enabled by bplint-enable. | [
"Given",
"an",
"array",
"of",
"directives",
"returns",
"the",
"names",
"of",
"rules",
"disabled",
"by",
"bplint",
"-",
"disable",
"directives",
"and",
"not",
"subsequently",
"re",
"-",
"enabled",
"by",
"bplint",
"-",
"enable",
"."
] | cf4ffdc63837280080b67f496d038d33a3975b6f | https://github.com/Banno/polymer-lint/blob/cf4ffdc63837280080b67f496d038d33a3975b6f/lib/util/filterErrors.js#L7-L26 | train |
simonepri/phc-bcrypt | bcrypt-b64.js | decode | function decode(str) {
let off = 0;
let olen = 0;
const slen = str.length;
const stra = [];
const len = str.length;
while (off < slen - 1 && olen < len) {
let code = str.charCodeAt(off++);
const c1 = code < BASE64_INDEX.length ? BASE64_INDEX[code] : -1;
code = str.charCodeAt(off++);
const c2 = code < BASE64_INDEX.length ? BASE64_INDEX[code] : -1;
if (c1 === -1 || c2 === -1) break;
let o = (c1 << 2) >>> 0;
o |= (c2 & 0x30) >> 4;
stra.push(String.fromCharCode(o));
if (++olen >= len || off >= slen) break;
code = str.charCodeAt(off++);
const c3 = code < BASE64_INDEX.length ? BASE64_INDEX[code] : -1;
if (c3 === -1) break;
o = ((c2 & 0x0f) << 4) >>> 0;
o |= (c3 & 0x3c) >> 2;
stra.push(String.fromCharCode(o));
if (++olen >= len || off >= slen) break;
code = str.charCodeAt(off++);
const c4 = code < BASE64_INDEX.length ? BASE64_INDEX[code] : -1;
o = ((c3 & 0x03) << 6) >>> 0;
o |= c4;
stra.push(String.fromCharCode(o));
++olen;
}
const buffa = [];
for (off = 0; off < olen; off++) buffa.push(stra[off].charCodeAt(0));
return Buffer.from(buffa);
} | javascript | function decode(str) {
let off = 0;
let olen = 0;
const slen = str.length;
const stra = [];
const len = str.length;
while (off < slen - 1 && olen < len) {
let code = str.charCodeAt(off++);
const c1 = code < BASE64_INDEX.length ? BASE64_INDEX[code] : -1;
code = str.charCodeAt(off++);
const c2 = code < BASE64_INDEX.length ? BASE64_INDEX[code] : -1;
if (c1 === -1 || c2 === -1) break;
let o = (c1 << 2) >>> 0;
o |= (c2 & 0x30) >> 4;
stra.push(String.fromCharCode(o));
if (++olen >= len || off >= slen) break;
code = str.charCodeAt(off++);
const c3 = code < BASE64_INDEX.length ? BASE64_INDEX[code] : -1;
if (c3 === -1) break;
o = ((c2 & 0x0f) << 4) >>> 0;
o |= (c3 & 0x3c) >> 2;
stra.push(String.fromCharCode(o));
if (++olen >= len || off >= slen) break;
code = str.charCodeAt(off++);
const c4 = code < BASE64_INDEX.length ? BASE64_INDEX[code] : -1;
o = ((c3 & 0x03) << 6) >>> 0;
o |= c4;
stra.push(String.fromCharCode(o));
++olen;
}
const buffa = [];
for (off = 0; off < olen; off++) buffa.push(stra[off].charCodeAt(0));
return Buffer.from(buffa);
} | [
"function",
"decode",
"(",
"str",
")",
"{",
"let",
"off",
"=",
"0",
";",
"let",
"olen",
"=",
"0",
";",
"const",
"slen",
"=",
"str",
".",
"length",
";",
"const",
"stra",
"=",
"[",
"]",
";",
"const",
"len",
"=",
"str",
".",
"length",
";",
"while",
"(",
"off",
"<",
"slen",
"-",
"1",
"&&",
"olen",
"<",
"len",
")",
"{",
"let",
"code",
"=",
"str",
".",
"charCodeAt",
"(",
"off",
"++",
")",
";",
"const",
"c1",
"=",
"code",
"<",
"BASE64_INDEX",
".",
"length",
"?",
"BASE64_INDEX",
"[",
"code",
"]",
":",
"-",
"1",
";",
"code",
"=",
"str",
".",
"charCodeAt",
"(",
"off",
"++",
")",
";",
"const",
"c2",
"=",
"code",
"<",
"BASE64_INDEX",
".",
"length",
"?",
"BASE64_INDEX",
"[",
"code",
"]",
":",
"-",
"1",
";",
"if",
"(",
"c1",
"===",
"-",
"1",
"||",
"c2",
"===",
"-",
"1",
")",
"break",
";",
"let",
"o",
"=",
"(",
"c1",
"<<",
"2",
")",
">>>",
"0",
";",
"o",
"|=",
"(",
"c2",
"&",
"0x30",
")",
">>",
"4",
";",
"stra",
".",
"push",
"(",
"String",
".",
"fromCharCode",
"(",
"o",
")",
")",
";",
"if",
"(",
"++",
"olen",
">=",
"len",
"||",
"off",
">=",
"slen",
")",
"break",
";",
"code",
"=",
"str",
".",
"charCodeAt",
"(",
"off",
"++",
")",
";",
"const",
"c3",
"=",
"code",
"<",
"BASE64_INDEX",
".",
"length",
"?",
"BASE64_INDEX",
"[",
"code",
"]",
":",
"-",
"1",
";",
"if",
"(",
"c3",
"===",
"-",
"1",
")",
"break",
";",
"o",
"=",
"(",
"(",
"c2",
"&",
"0x0f",
")",
"<<",
"4",
")",
">>>",
"0",
";",
"o",
"|=",
"(",
"c3",
"&",
"0x3c",
")",
">>",
"2",
";",
"stra",
".",
"push",
"(",
"String",
".",
"fromCharCode",
"(",
"o",
")",
")",
";",
"if",
"(",
"++",
"olen",
">=",
"len",
"||",
"off",
">=",
"slen",
")",
"break",
";",
"code",
"=",
"str",
".",
"charCodeAt",
"(",
"off",
"++",
")",
";",
"const",
"c4",
"=",
"code",
"<",
"BASE64_INDEX",
".",
"length",
"?",
"BASE64_INDEX",
"[",
"code",
"]",
":",
"-",
"1",
";",
"o",
"=",
"(",
"(",
"c3",
"&",
"0x03",
")",
"<<",
"6",
")",
">>>",
"0",
";",
"o",
"|=",
"c4",
";",
"stra",
".",
"push",
"(",
"String",
".",
"fromCharCode",
"(",
"o",
")",
")",
";",
"++",
"olen",
";",
"}",
"const",
"buffa",
"=",
"[",
"]",
";",
"for",
"(",
"off",
"=",
"0",
";",
"off",
"<",
"olen",
";",
"off",
"++",
")",
"buffa",
".",
"push",
"(",
"stra",
"[",
"off",
"]",
".",
"charCodeAt",
"(",
"0",
")",
")",
";",
"return",
"Buffer",
".",
"from",
"(",
"buffa",
")",
";",
"}"
] | Decodes a base64 encoded string using the bcrypt's base64 dictionary.
@param {string} str String to decode.
@returns {Buffer} The string decoded as a Buffer.
@inner | [
"Decodes",
"a",
"base64",
"encoded",
"string",
"using",
"the",
"bcrypt",
"s",
"base64",
"dictionary",
"."
] | 225fe73d3458a8f35f664f21e1cedd5545c256b4 | https://github.com/simonepri/phc-bcrypt/blob/225fe73d3458a8f35f664f21e1cedd5545c256b4/bcrypt-b64.js#L63-L97 | train |
danigb/smplr | packages/sampler-instrument/lib/midi.js | midi | function midi (instrument, options) {
options = options || {}
var midi = {}
var unused = []
instrument.names().forEach(function (name) {
var m = toMidi(name)
if (m) midi[m] = instrument.get(name)
else unused.push(name)
})
if (options.map) addMap(midi, instrument, options.map)
return {
unused: function () { return unused.slice() },
names: function () { return Object.keys(midi) },
get: function (name) { return midi[toMidi(name) || name] }
}
} | javascript | function midi (instrument, options) {
options = options || {}
var midi = {}
var unused = []
instrument.names().forEach(function (name) {
var m = toMidi(name)
if (m) midi[m] = instrument.get(name)
else unused.push(name)
})
if (options.map) addMap(midi, instrument, options.map)
return {
unused: function () { return unused.slice() },
names: function () { return Object.keys(midi) },
get: function (name) { return midi[toMidi(name) || name] }
}
} | [
"function",
"midi",
"(",
"instrument",
",",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
"var",
"midi",
"=",
"{",
"}",
"var",
"unused",
"=",
"[",
"]",
"instrument",
".",
"names",
"(",
")",
".",
"forEach",
"(",
"function",
"(",
"name",
")",
"{",
"var",
"m",
"=",
"toMidi",
"(",
"name",
")",
"if",
"(",
"m",
")",
"midi",
"[",
"m",
"]",
"=",
"instrument",
".",
"get",
"(",
"name",
")",
"else",
"unused",
".",
"push",
"(",
"name",
")",
"}",
")",
"if",
"(",
"options",
".",
"map",
")",
"addMap",
"(",
"midi",
",",
"instrument",
",",
"options",
".",
"map",
")",
"return",
"{",
"unused",
":",
"function",
"(",
")",
"{",
"return",
"unused",
".",
"slice",
"(",
")",
"}",
",",
"names",
":",
"function",
"(",
")",
"{",
"return",
"Object",
".",
"keys",
"(",
"midi",
")",
"}",
",",
"get",
":",
"function",
"(",
"name",
")",
"{",
"return",
"midi",
"[",
"toMidi",
"(",
"name",
")",
"||",
"name",
"]",
"}",
"}",
"}"
] | Create midi mappings for an instrument
@param {Instrument} instrument - the instrument. An instrument is an object
with names() and get() methods
@param {HashMap} options - (Optional) the midi mapping options. A hash may
with:
- map: a hash map of notes or a range of notes mapped to a sample name and
sample playing options. For example:
`map: {'C2': { sample: 'c2 sound' }, 'C3-C4': { sample: 'c3 sound'}}` | [
"Create",
"midi",
"mappings",
"for",
"an",
"instrument"
] | d2ef6b41dfea486cb5eeaa320f5a75efe9ae9bb1 | https://github.com/danigb/smplr/blob/d2ef6b41dfea486cb5eeaa320f5a75efe9ae9bb1/packages/sampler-instrument/lib/midi.js#L17-L34 | train |
gulp-cookery/gulp-chef | lib/configuration/sort.js | sort | function sort(taskInfo, rawConfig, parentConfig, optionalSchema) {
var schema, subTaskConfigs, taskConfig, value;
schema = optionalSchema || {};
from(schema).to(taskInfo).imply(TASK_SCHEMA_MAPPINGS);
schema = defaults({}, schema, SCHEMA_DEFAULTS);
taskConfig = rawConfig;
// NOTE: If schema provided, try to normalize properties inside 'config' property.
if (optionalSchema) {
taskConfig = regulate(taskConfig, ['config']);
}
taskConfig = normalize(schema, taskConfig, {
before: before,
after: after
});
taskConfig = renamePatternProperties(taskConfig);
// NOTE: A thought about that `config` should be "normalized".
// But remember that the `config` and `$` property prefix are designed for tasks that have no schemas.
// It just won't do anything try to normalize it without schema.
taskConfig = regulate(taskConfig, ['config']);
// NOTE: When there is `plugin`, `task`, `series` or `parallel` property,
// then all other properties will be treated as properties, not sub-task configs.
// So user don't have to use `config` keyword or `$` prefix.
value = _.omit(rawConfig, Object.keys(taskConfig).concat('config'));
if (!optionalSchema && (taskInfo.plugin || taskInfo.task || taskInfo.series || taskInfo.parallel)) {
taskConfig = defaults(taskConfig, value);
} else {
subTaskConfigs = value;
}
// inherit parent's config
taskConfig = defaults(taskConfig, parentConfig);
return {
taskInfo: taskInfo,
taskConfig: taskConfig,
subTaskConfigs: subTaskConfigs
};
function before(propSchema, values) {
if (propSchema.type === 'glob') {
_.defaults(propSchema, glob.SCHEMA);
} else if (propSchema.type === 'path') {
_.defaults(propSchema, path.SCHEMA);
}
}
function after(propSchema, resolved) {
var value, join;
if (resolved) {
value = resolved();
if (propSchema.type === 'glob') {
join = propSchema.properties.options.properties.join.default || 'src';
return resolve(resolveSrc(parentConfig, value, join));
} else if (propSchema.type === 'path') {
join = propSchema.properties.options.properties.join.default || 'dest';
return resolve(resolveDest(parentConfig, value, join));
}
}
return resolved;
function resolve(value) {
return function () {
return value;
};
}
}
} | javascript | function sort(taskInfo, rawConfig, parentConfig, optionalSchema) {
var schema, subTaskConfigs, taskConfig, value;
schema = optionalSchema || {};
from(schema).to(taskInfo).imply(TASK_SCHEMA_MAPPINGS);
schema = defaults({}, schema, SCHEMA_DEFAULTS);
taskConfig = rawConfig;
// NOTE: If schema provided, try to normalize properties inside 'config' property.
if (optionalSchema) {
taskConfig = regulate(taskConfig, ['config']);
}
taskConfig = normalize(schema, taskConfig, {
before: before,
after: after
});
taskConfig = renamePatternProperties(taskConfig);
// NOTE: A thought about that `config` should be "normalized".
// But remember that the `config` and `$` property prefix are designed for tasks that have no schemas.
// It just won't do anything try to normalize it without schema.
taskConfig = regulate(taskConfig, ['config']);
// NOTE: When there is `plugin`, `task`, `series` or `parallel` property,
// then all other properties will be treated as properties, not sub-task configs.
// So user don't have to use `config` keyword or `$` prefix.
value = _.omit(rawConfig, Object.keys(taskConfig).concat('config'));
if (!optionalSchema && (taskInfo.plugin || taskInfo.task || taskInfo.series || taskInfo.parallel)) {
taskConfig = defaults(taskConfig, value);
} else {
subTaskConfigs = value;
}
// inherit parent's config
taskConfig = defaults(taskConfig, parentConfig);
return {
taskInfo: taskInfo,
taskConfig: taskConfig,
subTaskConfigs: subTaskConfigs
};
function before(propSchema, values) {
if (propSchema.type === 'glob') {
_.defaults(propSchema, glob.SCHEMA);
} else if (propSchema.type === 'path') {
_.defaults(propSchema, path.SCHEMA);
}
}
function after(propSchema, resolved) {
var value, join;
if (resolved) {
value = resolved();
if (propSchema.type === 'glob') {
join = propSchema.properties.options.properties.join.default || 'src';
return resolve(resolveSrc(parentConfig, value, join));
} else if (propSchema.type === 'path') {
join = propSchema.properties.options.properties.join.default || 'dest';
return resolve(resolveDest(parentConfig, value, join));
}
}
return resolved;
function resolve(value) {
return function () {
return value;
};
}
}
} | [
"function",
"sort",
"(",
"taskInfo",
",",
"rawConfig",
",",
"parentConfig",
",",
"optionalSchema",
")",
"{",
"var",
"schema",
",",
"subTaskConfigs",
",",
"taskConfig",
",",
"value",
";",
"schema",
"=",
"optionalSchema",
"||",
"{",
"}",
";",
"from",
"(",
"schema",
")",
".",
"to",
"(",
"taskInfo",
")",
".",
"imply",
"(",
"TASK_SCHEMA_MAPPINGS",
")",
";",
"schema",
"=",
"defaults",
"(",
"{",
"}",
",",
"schema",
",",
"SCHEMA_DEFAULTS",
")",
";",
"taskConfig",
"=",
"rawConfig",
";",
"if",
"(",
"optionalSchema",
")",
"{",
"taskConfig",
"=",
"regulate",
"(",
"taskConfig",
",",
"[",
"'config'",
"]",
")",
";",
"}",
"taskConfig",
"=",
"normalize",
"(",
"schema",
",",
"taskConfig",
",",
"{",
"before",
":",
"before",
",",
"after",
":",
"after",
"}",
")",
";",
"taskConfig",
"=",
"renamePatternProperties",
"(",
"taskConfig",
")",
";",
"taskConfig",
"=",
"regulate",
"(",
"taskConfig",
",",
"[",
"'config'",
"]",
")",
";",
"value",
"=",
"_",
".",
"omit",
"(",
"rawConfig",
",",
"Object",
".",
"keys",
"(",
"taskConfig",
")",
".",
"concat",
"(",
"'config'",
")",
")",
";",
"if",
"(",
"!",
"optionalSchema",
"&&",
"(",
"taskInfo",
".",
"plugin",
"||",
"taskInfo",
".",
"task",
"||",
"taskInfo",
".",
"series",
"||",
"taskInfo",
".",
"parallel",
")",
")",
"{",
"taskConfig",
"=",
"defaults",
"(",
"taskConfig",
",",
"value",
")",
";",
"}",
"else",
"{",
"subTaskConfigs",
"=",
"value",
";",
"}",
"taskConfig",
"=",
"defaults",
"(",
"taskConfig",
",",
"parentConfig",
")",
";",
"return",
"{",
"taskInfo",
":",
"taskInfo",
",",
"taskConfig",
":",
"taskConfig",
",",
"subTaskConfigs",
":",
"subTaskConfigs",
"}",
";",
"function",
"before",
"(",
"propSchema",
",",
"values",
")",
"{",
"if",
"(",
"propSchema",
".",
"type",
"===",
"'glob'",
")",
"{",
"_",
".",
"defaults",
"(",
"propSchema",
",",
"glob",
".",
"SCHEMA",
")",
";",
"}",
"else",
"if",
"(",
"propSchema",
".",
"type",
"===",
"'path'",
")",
"{",
"_",
".",
"defaults",
"(",
"propSchema",
",",
"path",
".",
"SCHEMA",
")",
";",
"}",
"}",
"function",
"after",
"(",
"propSchema",
",",
"resolved",
")",
"{",
"var",
"value",
",",
"join",
";",
"if",
"(",
"resolved",
")",
"{",
"value",
"=",
"resolved",
"(",
")",
";",
"if",
"(",
"propSchema",
".",
"type",
"===",
"'glob'",
")",
"{",
"join",
"=",
"propSchema",
".",
"properties",
".",
"options",
".",
"properties",
".",
"join",
".",
"default",
"||",
"'src'",
";",
"return",
"resolve",
"(",
"resolveSrc",
"(",
"parentConfig",
",",
"value",
",",
"join",
")",
")",
";",
"}",
"else",
"if",
"(",
"propSchema",
".",
"type",
"===",
"'path'",
")",
"{",
"join",
"=",
"propSchema",
".",
"properties",
".",
"options",
".",
"properties",
".",
"join",
".",
"default",
"||",
"'dest'",
";",
"return",
"resolve",
"(",
"resolveDest",
"(",
"parentConfig",
",",
"value",
",",
"join",
")",
")",
";",
"}",
"}",
"return",
"resolved",
";",
"function",
"resolve",
"(",
"value",
")",
"{",
"return",
"function",
"(",
")",
"{",
"return",
"value",
";",
"}",
";",
"}",
"}",
"}"
] | If both parentConfig and taskConfig specified src property
then try to join paths. | [
"If",
"both",
"parentConfig",
"and",
"taskConfig",
"specified",
"src",
"property",
"then",
"try",
"to",
"join",
"paths",
"."
] | 6a8b6b4d20a9f8a36bc74f2beb74524c7338788f | https://github.com/gulp-cookery/gulp-chef/blob/6a8b6b4d20a9f8a36bc74f2beb74524c7338788f/lib/configuration/sort.js#L109-L181 | train |
angelozerr/tern-browser-extension | browser-extension.js | createElement | function createElement (tagName) {
if (!tagName || tagName.length < 1) return new infer.Obj(infer.def.parsePath('HTMLElement.prototype'))
var cx = infer.cx(), server = cx.parent, name = getHTMLElementName(tagName),
locals = infer.def.parsePath(name + '.prototype')
if (locals && locals != infer.ANull) return new infer.Obj(locals)
return createElement()
} | javascript | function createElement (tagName) {
if (!tagName || tagName.length < 1) return new infer.Obj(infer.def.parsePath('HTMLElement.prototype'))
var cx = infer.cx(), server = cx.parent, name = getHTMLElementName(tagName),
locals = infer.def.parsePath(name + '.prototype')
if (locals && locals != infer.ANull) return new infer.Obj(locals)
return createElement()
} | [
"function",
"createElement",
"(",
"tagName",
")",
"{",
"if",
"(",
"!",
"tagName",
"||",
"tagName",
".",
"length",
"<",
"1",
")",
"return",
"new",
"infer",
".",
"Obj",
"(",
"infer",
".",
"def",
".",
"parsePath",
"(",
"'HTMLElement.prototype'",
")",
")",
"var",
"cx",
"=",
"infer",
".",
"cx",
"(",
")",
",",
"server",
"=",
"cx",
".",
"parent",
",",
"name",
"=",
"getHTMLElementName",
"(",
"tagName",
")",
",",
"locals",
"=",
"infer",
".",
"def",
".",
"parsePath",
"(",
"name",
"+",
"'.prototype'",
")",
"if",
"(",
"locals",
"&&",
"locals",
"!=",
"infer",
".",
"ANull",
")",
"return",
"new",
"infer",
".",
"Obj",
"(",
"locals",
")",
"return",
"createElement",
"(",
")",
"}"
] | Custom tern function | [
"Custom",
"tern",
"function"
] | b362729530727cfde0ec96289775d4363c40a17c | https://github.com/angelozerr/tern-browser-extension/blob/b362729530727cfde0ec96289775d4363c40a17c/browser-extension.js#L148-L154 | train |
angelozerr/tern-browser-extension | browser-extension.js | findTypeAt | function findTypeAt (_file, _pos, expr, type) {
if (!expr) return type
var isStringLiteral = expr.node.type === 'Literal' &&
typeof expr.node.value === 'string'
if (isStringLiteral) {
var attr = null
if (!!expr.node.dom) {
attr = expr.node.dom
} else if (!!expr.node.eventType) {
var eventType = expr.node.eventType
type = Object.create(type)
type.doc = eventType['!doc']
type.url = eventType['!url']
type.origin = "browser-extension"
} else if (expr.node.cssselectors == true) {
var text = _file.text, wordStart = _pos, wordEnd = _pos
while (wordStart && acorn.isIdentifierChar(text.charCodeAt(wordStart - 1))) --wordStart
while (wordEnd < text.length && acorn.isIdentifierChar(text.charCodeAt(wordEnd))) ++wordEnd
var id = text.slice(wordStart, wordEnd)
attr = getAttr(expr.node, id)
}
if (attr) {
// The `type` is a value shared for all string literals.
// We must create a copy before modifying `origin` and `originNode`.
// Otherwise all string literals would point to the last jump location
type = Object.create(type)
type.origin = attr.sourceFile.name
type.originNode = attr
}
}
return type
} | javascript | function findTypeAt (_file, _pos, expr, type) {
if (!expr) return type
var isStringLiteral = expr.node.type === 'Literal' &&
typeof expr.node.value === 'string'
if (isStringLiteral) {
var attr = null
if (!!expr.node.dom) {
attr = expr.node.dom
} else if (!!expr.node.eventType) {
var eventType = expr.node.eventType
type = Object.create(type)
type.doc = eventType['!doc']
type.url = eventType['!url']
type.origin = "browser-extension"
} else if (expr.node.cssselectors == true) {
var text = _file.text, wordStart = _pos, wordEnd = _pos
while (wordStart && acorn.isIdentifierChar(text.charCodeAt(wordStart - 1))) --wordStart
while (wordEnd < text.length && acorn.isIdentifierChar(text.charCodeAt(wordEnd))) ++wordEnd
var id = text.slice(wordStart, wordEnd)
attr = getAttr(expr.node, id)
}
if (attr) {
// The `type` is a value shared for all string literals.
// We must create a copy before modifying `origin` and `originNode`.
// Otherwise all string literals would point to the last jump location
type = Object.create(type)
type.origin = attr.sourceFile.name
type.originNode = attr
}
}
return type
} | [
"function",
"findTypeAt",
"(",
"_file",
",",
"_pos",
",",
"expr",
",",
"type",
")",
"{",
"if",
"(",
"!",
"expr",
")",
"return",
"type",
"var",
"isStringLiteral",
"=",
"expr",
".",
"node",
".",
"type",
"===",
"'Literal'",
"&&",
"typeof",
"expr",
".",
"node",
".",
"value",
"===",
"'string'",
"if",
"(",
"isStringLiteral",
")",
"{",
"var",
"attr",
"=",
"null",
"if",
"(",
"!",
"!",
"expr",
".",
"node",
".",
"dom",
")",
"{",
"attr",
"=",
"expr",
".",
"node",
".",
"dom",
"}",
"else",
"if",
"(",
"!",
"!",
"expr",
".",
"node",
".",
"eventType",
")",
"{",
"var",
"eventType",
"=",
"expr",
".",
"node",
".",
"eventType",
"type",
"=",
"Object",
".",
"create",
"(",
"type",
")",
"type",
".",
"doc",
"=",
"eventType",
"[",
"'!doc'",
"]",
"type",
".",
"url",
"=",
"eventType",
"[",
"'!url'",
"]",
"type",
".",
"origin",
"=",
"\"browser-extension\"",
"}",
"else",
"if",
"(",
"expr",
".",
"node",
".",
"cssselectors",
"==",
"true",
")",
"{",
"var",
"text",
"=",
"_file",
".",
"text",
",",
"wordStart",
"=",
"_pos",
",",
"wordEnd",
"=",
"_pos",
"while",
"(",
"wordStart",
"&&",
"acorn",
".",
"isIdentifierChar",
"(",
"text",
".",
"charCodeAt",
"(",
"wordStart",
"-",
"1",
")",
")",
")",
"--",
"wordStart",
"while",
"(",
"wordEnd",
"<",
"text",
".",
"length",
"&&",
"acorn",
".",
"isIdentifierChar",
"(",
"text",
".",
"charCodeAt",
"(",
"wordEnd",
")",
")",
")",
"++",
"wordEnd",
"var",
"id",
"=",
"text",
".",
"slice",
"(",
"wordStart",
",",
"wordEnd",
")",
"attr",
"=",
"getAttr",
"(",
"expr",
".",
"node",
",",
"id",
")",
"}",
"if",
"(",
"attr",
")",
"{",
"type",
"=",
"Object",
".",
"create",
"(",
"type",
")",
"type",
".",
"origin",
"=",
"attr",
".",
"sourceFile",
".",
"name",
"type",
".",
"originNode",
"=",
"attr",
"}",
"}",
"return",
"type",
"}"
] | Find type at | [
"Find",
"type",
"at"
] | b362729530727cfde0ec96289775d4363c40a17c | https://github.com/angelozerr/tern-browser-extension/blob/b362729530727cfde0ec96289775d4363c40a17c/browser-extension.js#L370-L403 | train |
simonepri/phc-bcrypt | index.js | hash | function hash(password, options) {
options = options || {};
const rounds = options.rounds || defaults.rounds;
const saltSize = options.saltSize || defaults.saltSize;
const version = versions[versions.length - 1];
// Rounds Validation
if (typeof rounds !== 'number' || !Number.isInteger(rounds)) {
return Promise.reject(
new TypeError("The 'rounds' option must be an integer")
);
}
if (rounds < 4 || rounds > 31) {
return Promise.reject(
new TypeError(
`The 'rounds' option must be in the range (4 <= rounds <= 31)`
)
);
}
// Salt Size Validation
if (saltSize < 8 || saltSize > 1024) {
return Promise.reject(
new TypeError(
"The 'saltSize' option must be in the range (8 <= saltSize <= 1023)"
)
);
}
return gensalt(saltSize).then(salt => {
const bb64salt = bb64.encode(salt);
const padrounds = rounds > 9 ? Number(rounds) : '0' + rounds;
const decver = String.fromCharCode(version);
const parstr = `$2${decver}$${padrounds}$${bb64salt}`;
return bcrypt.hash(password, parstr).then(enchash => {
const hash = bb64.decode(enchash.split(parstr)[1]);
const phcstr = phc.serialize({
id: 'bcrypt',
version,
params: {
r: rounds
},
salt,
hash
});
return phcstr;
});
});
} | javascript | function hash(password, options) {
options = options || {};
const rounds = options.rounds || defaults.rounds;
const saltSize = options.saltSize || defaults.saltSize;
const version = versions[versions.length - 1];
// Rounds Validation
if (typeof rounds !== 'number' || !Number.isInteger(rounds)) {
return Promise.reject(
new TypeError("The 'rounds' option must be an integer")
);
}
if (rounds < 4 || rounds > 31) {
return Promise.reject(
new TypeError(
`The 'rounds' option must be in the range (4 <= rounds <= 31)`
)
);
}
// Salt Size Validation
if (saltSize < 8 || saltSize > 1024) {
return Promise.reject(
new TypeError(
"The 'saltSize' option must be in the range (8 <= saltSize <= 1023)"
)
);
}
return gensalt(saltSize).then(salt => {
const bb64salt = bb64.encode(salt);
const padrounds = rounds > 9 ? Number(rounds) : '0' + rounds;
const decver = String.fromCharCode(version);
const parstr = `$2${decver}$${padrounds}$${bb64salt}`;
return bcrypt.hash(password, parstr).then(enchash => {
const hash = bb64.decode(enchash.split(parstr)[1]);
const phcstr = phc.serialize({
id: 'bcrypt',
version,
params: {
r: rounds
},
salt,
hash
});
return phcstr;
});
});
} | [
"function",
"hash",
"(",
"password",
",",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"const",
"rounds",
"=",
"options",
".",
"rounds",
"||",
"defaults",
".",
"rounds",
";",
"const",
"saltSize",
"=",
"options",
".",
"saltSize",
"||",
"defaults",
".",
"saltSize",
";",
"const",
"version",
"=",
"versions",
"[",
"versions",
".",
"length",
"-",
"1",
"]",
";",
"if",
"(",
"typeof",
"rounds",
"!==",
"'number'",
"||",
"!",
"Number",
".",
"isInteger",
"(",
"rounds",
")",
")",
"{",
"return",
"Promise",
".",
"reject",
"(",
"new",
"TypeError",
"(",
"\"The 'rounds' option must be an integer\"",
")",
")",
";",
"}",
"if",
"(",
"rounds",
"<",
"4",
"||",
"rounds",
">",
"31",
")",
"{",
"return",
"Promise",
".",
"reject",
"(",
"new",
"TypeError",
"(",
"`",
"`",
")",
")",
";",
"}",
"if",
"(",
"saltSize",
"<",
"8",
"||",
"saltSize",
">",
"1024",
")",
"{",
"return",
"Promise",
".",
"reject",
"(",
"new",
"TypeError",
"(",
"\"The 'saltSize' option must be in the range (8 <= saltSize <= 1023)\"",
")",
")",
";",
"}",
"return",
"gensalt",
"(",
"saltSize",
")",
".",
"then",
"(",
"salt",
"=>",
"{",
"const",
"bb64salt",
"=",
"bb64",
".",
"encode",
"(",
"salt",
")",
";",
"const",
"padrounds",
"=",
"rounds",
">",
"9",
"?",
"Number",
"(",
"rounds",
")",
":",
"'0'",
"+",
"rounds",
";",
"const",
"decver",
"=",
"String",
".",
"fromCharCode",
"(",
"version",
")",
";",
"const",
"parstr",
"=",
"`",
"${",
"decver",
"}",
"${",
"padrounds",
"}",
"${",
"bb64salt",
"}",
"`",
";",
"return",
"bcrypt",
".",
"hash",
"(",
"password",
",",
"parstr",
")",
".",
"then",
"(",
"enchash",
"=>",
"{",
"const",
"hash",
"=",
"bb64",
".",
"decode",
"(",
"enchash",
".",
"split",
"(",
"parstr",
")",
"[",
"1",
"]",
")",
";",
"const",
"phcstr",
"=",
"phc",
".",
"serialize",
"(",
"{",
"id",
":",
"'bcrypt'",
",",
"version",
",",
"params",
":",
"{",
"r",
":",
"rounds",
"}",
",",
"salt",
",",
"hash",
"}",
")",
";",
"return",
"phcstr",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Computes the hash string of the given password in the PHC format using bcrypt
package.
@public
@param {string} password The password to hash.
@param {Object} [options] Optional configurations related to the hashing
function.
@param {number} [options.rounds=10] Optional
Must be an integer within the range (`4` <= `rounds` <= `31`).
@return {Promise.<string>} The generated secure hash string in the PHC
format. | [
"Computes",
"the",
"hash",
"string",
"of",
"the",
"given",
"password",
"in",
"the",
"PHC",
"format",
"using",
"bcrypt",
"package",
"."
] | 225fe73d3458a8f35f664f21e1cedd5545c256b4 | https://github.com/simonepri/phc-bcrypt/blob/225fe73d3458a8f35f664f21e1cedd5545c256b4/index.js#L45-L93 | train |
Banno/polymer-lint | src/reporters/ConsoleReporter.js | formatLine | function formatLine({ rule, message, location }, metrics) {
const { line, col } = location;
const { line: lineW, col: colW, message: msgW } = metrics;
const loc = sprintf(`%${lineW}d:%-${colW}d`, line, col);
const msg = sprintf(`%-${msgW}s`, message);
return ` ${loc} ${msg} ${rule}`;
} | javascript | function formatLine({ rule, message, location }, metrics) {
const { line, col } = location;
const { line: lineW, col: colW, message: msgW } = metrics;
const loc = sprintf(`%${lineW}d:%-${colW}d`, line, col);
const msg = sprintf(`%-${msgW}s`, message);
return ` ${loc} ${msg} ${rule}`;
} | [
"function",
"formatLine",
"(",
"{",
"rule",
",",
"message",
",",
"location",
"}",
",",
"metrics",
")",
"{",
"const",
"{",
"line",
",",
"col",
"}",
"=",
"location",
";",
"const",
"{",
"line",
":",
"lineW",
",",
"col",
":",
"colW",
",",
"message",
":",
"msgW",
"}",
"=",
"metrics",
";",
"const",
"loc",
"=",
"sprintf",
"(",
"`",
"${",
"lineW",
"}",
"${",
"colW",
"}",
"`",
",",
"line",
",",
"col",
")",
";",
"const",
"msg",
"=",
"sprintf",
"(",
"`",
"${",
"msgW",
"}",
"`",
",",
"message",
")",
";",
"return",
"`",
"${",
"loc",
"}",
"${",
"msg",
"}",
"${",
"rule",
"}",
"`",
";",
"}"
] | Formats the output line with the widths given in `metrics`
@private
@param {{
rule: string,
message: string,
location: parse5.LocationInfo
}} error
@param {{line: number, col: number, message: number}} metrics
@return {string} | [
"Formats",
"the",
"output",
"line",
"with",
"the",
"widths",
"given",
"in",
"metrics"
] | cf4ffdc63837280080b67f496d038d33a3975b6f | https://github.com/Banno/polymer-lint/blob/cf4ffdc63837280080b67f496d038d33a3975b6f/src/reporters/ConsoleReporter.js#L50-L56 | train |
ocadotechnology/quantumjs | quantum-html/lib/index.js | prepareTransforms | function prepareTransforms (entityTransforms, namespace, target) {
const resolvedNamespace = namespace || ''
const resolvedTarget = target || {}
for (const d in entityTransforms) {
if (typeof (entityTransforms[d]) === 'function') {
resolvedTarget[resolvedNamespace + d] = entityTransforms[d]
resolvedTarget[d] = entityTransforms[d]
} else {
prepareTransforms(entityTransforms[d], resolvedNamespace + d + '.', resolvedTarget)
}
}
return resolvedTarget
} | javascript | function prepareTransforms (entityTransforms, namespace, target) {
const resolvedNamespace = namespace || ''
const resolvedTarget = target || {}
for (const d in entityTransforms) {
if (typeof (entityTransforms[d]) === 'function') {
resolvedTarget[resolvedNamespace + d] = entityTransforms[d]
resolvedTarget[d] = entityTransforms[d]
} else {
prepareTransforms(entityTransforms[d], resolvedNamespace + d + '.', resolvedTarget)
}
}
return resolvedTarget
} | [
"function",
"prepareTransforms",
"(",
"entityTransforms",
",",
"namespace",
",",
"target",
")",
"{",
"const",
"resolvedNamespace",
"=",
"namespace",
"||",
"''",
"const",
"resolvedTarget",
"=",
"target",
"||",
"{",
"}",
"for",
"(",
"const",
"d",
"in",
"entityTransforms",
")",
"{",
"if",
"(",
"typeof",
"(",
"entityTransforms",
"[",
"d",
"]",
")",
"===",
"'function'",
")",
"{",
"resolvedTarget",
"[",
"resolvedNamespace",
"+",
"d",
"]",
"=",
"entityTransforms",
"[",
"d",
"]",
"resolvedTarget",
"[",
"d",
"]",
"=",
"entityTransforms",
"[",
"d",
"]",
"}",
"else",
"{",
"prepareTransforms",
"(",
"entityTransforms",
"[",
"d",
"]",
",",
"resolvedNamespace",
"+",
"d",
"+",
"'.'",
",",
"resolvedTarget",
")",
"}",
"}",
"return",
"resolvedTarget",
"}"
] | flattens out namespaced renderers into a single object | [
"flattens",
"out",
"namespaced",
"renderers",
"into",
"a",
"single",
"object"
] | 5bc684b750472296f186a816529272c36218db04 | https://github.com/ocadotechnology/quantumjs/blob/5bc684b750472296f186a816529272c36218db04/quantum-html/lib/index.js#L147-L160 | train |
ocadotechnology/quantumjs | quantum-html/lib/index.js | transformer | function transformer (selection) {
const type = quantum.isSelection(selection) ? selection.type() : undefined
const entityTransform = transformMap[type] || defaultTransform
return entityTransform(selection, transformer, meta) // bootstrap to itself to make the transformer accessible to children
} | javascript | function transformer (selection) {
const type = quantum.isSelection(selection) ? selection.type() : undefined
const entityTransform = transformMap[type] || defaultTransform
return entityTransform(selection, transformer, meta) // bootstrap to itself to make the transformer accessible to children
} | [
"function",
"transformer",
"(",
"selection",
")",
"{",
"const",
"type",
"=",
"quantum",
".",
"isSelection",
"(",
"selection",
")",
"?",
"selection",
".",
"type",
"(",
")",
":",
"undefined",
"const",
"entityTransform",
"=",
"transformMap",
"[",
"type",
"]",
"||",
"defaultTransform",
"return",
"entityTransform",
"(",
"selection",
",",
"transformer",
",",
"meta",
")",
"}"
] | renders an selection by looking at its type and selecting the transform from the list | [
"renders",
"an",
"selection",
"by",
"looking",
"at",
"its",
"type",
"and",
"selecting",
"the",
"transform",
"from",
"the",
"list"
] | 5bc684b750472296f186a816529272c36218db04 | https://github.com/ocadotechnology/quantumjs/blob/5bc684b750472296f186a816529272c36218db04/quantum-html/lib/index.js#L188-L192 | train |
bigpipe/illuminati | bootstrap.js | Error | function Error() {
Illuminati.apply(this, arguments);
var backtrace = new Backtrace({ error: this })
, sourcemap = stackmap(Error.sourcemap).map(backtrace.traces);
this.stringify(backtrace.traces, sourcemap);
} | javascript | function Error() {
Illuminati.apply(this, arguments);
var backtrace = new Backtrace({ error: this })
, sourcemap = stackmap(Error.sourcemap).map(backtrace.traces);
this.stringify(backtrace.traces, sourcemap);
} | [
"function",
"Error",
"(",
")",
"{",
"Illuminati",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"var",
"backtrace",
"=",
"new",
"Backtrace",
"(",
"{",
"error",
":",
"this",
"}",
")",
",",
"sourcemap",
"=",
"stackmap",
"(",
"Error",
".",
"sourcemap",
")",
".",
"map",
"(",
"backtrace",
".",
"traces",
")",
";",
"this",
".",
"stringify",
"(",
"backtrace",
".",
"traces",
",",
"sourcemap",
")",
";",
"}"
] | Create a custom error instance that will automatically map a given source map
to the received or internal `stack` property.
@constructor
@api public | [
"Create",
"a",
"custom",
"error",
"instance",
"that",
"will",
"automatically",
"map",
"a",
"given",
"source",
"map",
"to",
"the",
"received",
"or",
"internal",
"stack",
"property",
"."
] | f32ee3d0980bdb5fe23945dd9f8da63f2f737303 | https://github.com/bigpipe/illuminati/blob/f32ee3d0980bdb5fe23945dd9f8da63f2f737303/bootstrap.js#L20-L27 | train |
ibolmo/grunt-mootools-packager | tasks/packager.js | getKeys | function getKeys(definition){
return definition.provides.map(function(component){
return definition.package + '/' + component;
}).concat(getPrimaryKey(definition));
} | javascript | function getKeys(definition){
return definition.provides.map(function(component){
return definition.package + '/' + component;
}).concat(getPrimaryKey(definition));
} | [
"function",
"getKeys",
"(",
"definition",
")",
"{",
"return",
"definition",
".",
"provides",
".",
"map",
"(",
"function",
"(",
"component",
")",
"{",
"return",
"definition",
".",
"package",
"+",
"'/'",
"+",
"component",
";",
"}",
")",
".",
"concat",
"(",
"getPrimaryKey",
"(",
"definition",
")",
")",
";",
"}"
] | provides keys to the source file based on the name and the components provided | [
"provides",
"keys",
"to",
"the",
"source",
"file",
"based",
"on",
"the",
"name",
"and",
"the",
"components",
"provided"
] | fde35544d09c9ca4efc83bf386310ce8f022fd16 | https://github.com/ibolmo/grunt-mootools-packager/blob/fde35544d09c9ca4efc83bf386310ce8f022fd16/tasks/packager.js#L31-L35 | train |
ibolmo/grunt-mootools-packager | tasks/packager.js | getProjectName | function getProjectName(componentPath, optionsName){
if (typeof optionsName == 'string') return optionsName;
var projectName;
for (var prj in optionsName){
if(~componentPath.indexOf(optionsName[prj])) projectName = prj;
}
if (!projectName) grunt.fail.warn('Missing name in options for component with path: ' + componentPath);
return projectName;
} | javascript | function getProjectName(componentPath, optionsName){
if (typeof optionsName == 'string') return optionsName;
var projectName;
for (var prj in optionsName){
if(~componentPath.indexOf(optionsName[prj])) projectName = prj;
}
if (!projectName) grunt.fail.warn('Missing name in options for component with path: ' + componentPath);
return projectName;
} | [
"function",
"getProjectName",
"(",
"componentPath",
",",
"optionsName",
")",
"{",
"if",
"(",
"typeof",
"optionsName",
"==",
"'string'",
")",
"return",
"optionsName",
";",
"var",
"projectName",
";",
"for",
"(",
"var",
"prj",
"in",
"optionsName",
")",
"{",
"if",
"(",
"~",
"componentPath",
".",
"indexOf",
"(",
"optionsName",
"[",
"prj",
"]",
")",
")",
"projectName",
"=",
"prj",
";",
"}",
"if",
"(",
"!",
"projectName",
")",
"grunt",
".",
"fail",
".",
"warn",
"(",
"'Missing name in options for component with path: '",
"+",
"componentPath",
")",
";",
"return",
"projectName",
";",
"}"
] | matches project name with component's path | [
"matches",
"project",
"name",
"with",
"component",
"s",
"path"
] | fde35544d09c9ca4efc83bf386310ce8f022fd16 | https://github.com/ibolmo/grunt-mootools-packager/blob/fde35544d09c9ca4efc83bf386310ce8f022fd16/tasks/packager.js#L38-L46 | train |
ibolmo/grunt-mootools-packager | tasks/packager.js | toArray | function toArray(object){
if (!object) return [];
if (object.charAt) return [object];
return grunt.util.toArray(object);
} | javascript | function toArray(object){
if (!object) return [];
if (object.charAt) return [object];
return grunt.util.toArray(object);
} | [
"function",
"toArray",
"(",
"object",
")",
"{",
"if",
"(",
"!",
"object",
")",
"return",
"[",
"]",
";",
"if",
"(",
"object",
".",
"charAt",
")",
"return",
"[",
"object",
"]",
";",
"return",
"grunt",
".",
"util",
".",
"toArray",
"(",
"object",
")",
";",
"}"
] | wraps item in an array if it isn't one | [
"wraps",
"item",
"in",
"an",
"array",
"if",
"it",
"isn",
"t",
"one"
] | fde35544d09c9ca4efc83bf386310ce8f022fd16 | https://github.com/ibolmo/grunt-mootools-packager/blob/fde35544d09c9ca4efc83bf386310ce8f022fd16/tasks/packager.js#L49-L53 | train |
ibolmo/grunt-mootools-packager | tasks/packager.js | checkRegistry | function checkRegistry(registry, key, path){
if (registry[key] == undefined){
throw new Error('Dependency not found: ' + key + ' in ' + path);
}
} | javascript | function checkRegistry(registry, key, path){
if (registry[key] == undefined){
throw new Error('Dependency not found: ' + key + ' in ' + path);
}
} | [
"function",
"checkRegistry",
"(",
"registry",
",",
"key",
",",
"path",
")",
"{",
"if",
"(",
"registry",
"[",
"key",
"]",
"==",
"undefined",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Dependency not found: '",
"+",
"key",
"+",
"' in '",
"+",
"path",
")",
";",
"}",
"}"
] | verifies that an item is in the registry of components | [
"verifies",
"that",
"an",
"item",
"is",
"in",
"the",
"registry",
"of",
"components"
] | fde35544d09c9ca4efc83bf386310ce8f022fd16 | https://github.com/ibolmo/grunt-mootools-packager/blob/fde35544d09c9ca4efc83bf386310ce8f022fd16/tasks/packager.js#L56-L60 | train |
spyfu/spyfu-vuex-helpers | dist/spyfu-vuex-helpers.js | findInstanceThen | function findInstanceThen() {
// this function supports two argument signatures. if the
// first argument is an object, we will use that as the
// config, and the second arg as the mutation handler
var _parseArguments = parseArguments(arguments),
config = _parseArguments.config,
callback = _parseArguments.callback;
return function (state, payload) {
if (stateAndPayloadAreValid(config, state, payload)) {
// find our instance based on the current configuration
var instance = state[config.stateKey].find(function (obj) {
return obj[config.instanceKey] === payload[config.instanceKey];
});
// if the instance was found, execute our mutation callback
if (instance) {
callback(instance, payload, state);
}
}
};
} | javascript | function findInstanceThen() {
// this function supports two argument signatures. if the
// first argument is an object, we will use that as the
// config, and the second arg as the mutation handler
var _parseArguments = parseArguments(arguments),
config = _parseArguments.config,
callback = _parseArguments.callback;
return function (state, payload) {
if (stateAndPayloadAreValid(config, state, payload)) {
// find our instance based on the current configuration
var instance = state[config.stateKey].find(function (obj) {
return obj[config.instanceKey] === payload[config.instanceKey];
});
// if the instance was found, execute our mutation callback
if (instance) {
callback(instance, payload, state);
}
}
};
} | [
"function",
"findInstanceThen",
"(",
")",
"{",
"var",
"_parseArguments",
"=",
"parseArguments",
"(",
"arguments",
")",
",",
"config",
"=",
"_parseArguments",
".",
"config",
",",
"callback",
"=",
"_parseArguments",
".",
"callback",
";",
"return",
"function",
"(",
"state",
",",
"payload",
")",
"{",
"if",
"(",
"stateAndPayloadAreValid",
"(",
"config",
",",
"state",
",",
"payload",
")",
")",
"{",
"var",
"instance",
"=",
"state",
"[",
"config",
".",
"stateKey",
"]",
".",
"find",
"(",
"function",
"(",
"obj",
")",
"{",
"return",
"obj",
"[",
"config",
".",
"instanceKey",
"]",
"===",
"payload",
"[",
"config",
".",
"instanceKey",
"]",
";",
"}",
")",
";",
"if",
"(",
"instance",
")",
"{",
"callback",
"(",
"instance",
",",
"payload",
",",
"state",
")",
";",
"}",
"}",
"}",
";",
"}"
] | Find a state instance, and execute a callback if found.
@param {Object|Function} required the config object, or mutation callback
@param {Function} optional mutation callback
@return {Function} | [
"Find",
"a",
"state",
"instance",
"and",
"execute",
"a",
"callback",
"if",
"found",
"."
] | 64742e0cbadb3e6ee62d722b26dbc27b87e1a378 | https://github.com/spyfu/spyfu-vuex-helpers/blob/64742e0cbadb3e6ee62d722b26dbc27b87e1a378/dist/spyfu-vuex-helpers.js#L99-L121 | train |
spyfu/spyfu-vuex-helpers | dist/spyfu-vuex-helpers.js | parseArguments | function parseArguments(args) {
var defaultConfig = {
stateKey: 'instances',
instanceKey: 'id'
};
if (typeof args[0] === 'function') {
return {
callback: args[0],
config: defaultConfig
};
} else {
return {
callback: args[1],
config: Object.assign({}, defaultConfig, args[0])
};
}
} | javascript | function parseArguments(args) {
var defaultConfig = {
stateKey: 'instances',
instanceKey: 'id'
};
if (typeof args[0] === 'function') {
return {
callback: args[0],
config: defaultConfig
};
} else {
return {
callback: args[1],
config: Object.assign({}, defaultConfig, args[0])
};
}
} | [
"function",
"parseArguments",
"(",
"args",
")",
"{",
"var",
"defaultConfig",
"=",
"{",
"stateKey",
":",
"'instances'",
",",
"instanceKey",
":",
"'id'",
"}",
";",
"if",
"(",
"typeof",
"args",
"[",
"0",
"]",
"===",
"'function'",
")",
"{",
"return",
"{",
"callback",
":",
"args",
"[",
"0",
"]",
",",
"config",
":",
"defaultConfig",
"}",
";",
"}",
"else",
"{",
"return",
"{",
"callback",
":",
"args",
"[",
"1",
"]",
",",
"config",
":",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"defaultConfig",
",",
"args",
"[",
"0",
"]",
")",
"}",
";",
"}",
"}"
] | helper to get config and callback from the arguments | [
"helper",
"to",
"get",
"config",
"and",
"callback",
"from",
"the",
"arguments"
] | 64742e0cbadb3e6ee62d722b26dbc27b87e1a378 | https://github.com/spyfu/spyfu-vuex-helpers/blob/64742e0cbadb3e6ee62d722b26dbc27b87e1a378/dist/spyfu-vuex-helpers.js#L129-L146 | train |
spyfu/spyfu-vuex-helpers | dist/spyfu-vuex-helpers.js | stateAndPayloadAreValid | function stateAndPayloadAreValid(config, state, payload) {
// ensure that the instances array exists
if (!Array.isArray(state[config.stateKey])) {
console.error('State does not contain an "' + config.stateKey + '" array.');
return false;
}
// ensure that the payload contains an id
if ((typeof payload === 'undefined' ? 'undefined' : _typeof(payload)) !== 'object' || typeof payload[config.instanceKey] === 'undefined') {
console.error('Mutation payloads must be an object with an "' + config.instanceKey + '" property.');
return false;
}
return true;
} | javascript | function stateAndPayloadAreValid(config, state, payload) {
// ensure that the instances array exists
if (!Array.isArray(state[config.stateKey])) {
console.error('State does not contain an "' + config.stateKey + '" array.');
return false;
}
// ensure that the payload contains an id
if ((typeof payload === 'undefined' ? 'undefined' : _typeof(payload)) !== 'object' || typeof payload[config.instanceKey] === 'undefined') {
console.error('Mutation payloads must be an object with an "' + config.instanceKey + '" property.');
return false;
}
return true;
} | [
"function",
"stateAndPayloadAreValid",
"(",
"config",
",",
"state",
",",
"payload",
")",
"{",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"state",
"[",
"config",
".",
"stateKey",
"]",
")",
")",
"{",
"console",
".",
"error",
"(",
"'State does not contain an \"'",
"+",
"config",
".",
"stateKey",
"+",
"'\" array.'",
")",
";",
"return",
"false",
";",
"}",
"if",
"(",
"(",
"typeof",
"payload",
"===",
"'undefined'",
"?",
"'undefined'",
":",
"_typeof",
"(",
"payload",
")",
")",
"!==",
"'object'",
"||",
"typeof",
"payload",
"[",
"config",
".",
"instanceKey",
"]",
"===",
"'undefined'",
")",
"{",
"console",
".",
"error",
"(",
"'Mutation payloads must be an object with an \"'",
"+",
"config",
".",
"instanceKey",
"+",
"'\" property.'",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | check if the state or payload is malformed | [
"check",
"if",
"the",
"state",
"or",
"payload",
"is",
"malformed"
] | 64742e0cbadb3e6ee62d722b26dbc27b87e1a378 | https://github.com/spyfu/spyfu-vuex-helpers/blob/64742e0cbadb3e6ee62d722b26dbc27b87e1a378/dist/spyfu-vuex-helpers.js#L149-L164 | train |
spyfu/spyfu-vuex-helpers | dist/spyfu-vuex-helpers.js | instance_getters | function instance_getters () {
var _parseArguments = parseArguments$1(arguments),
getters = _parseArguments.getters,
options = _parseArguments.options;
return Object.keys(getters).reduce(function (instanceGetters, name) {
instanceGetters[name] = function (state, otherGetters) {
return function (instanceKey) {
var instance = state[options.stateKey || 'instances'].find(function (obj) {
return obj[options.instanceKey || 'id'] === instanceKey;
});
if (instance) {
return getters[name](instance, otherGetters, state, instanceKey);
}
};
};
return instanceGetters;
}, {});
} | javascript | function instance_getters () {
var _parseArguments = parseArguments$1(arguments),
getters = _parseArguments.getters,
options = _parseArguments.options;
return Object.keys(getters).reduce(function (instanceGetters, name) {
instanceGetters[name] = function (state, otherGetters) {
return function (instanceKey) {
var instance = state[options.stateKey || 'instances'].find(function (obj) {
return obj[options.instanceKey || 'id'] === instanceKey;
});
if (instance) {
return getters[name](instance, otherGetters, state, instanceKey);
}
};
};
return instanceGetters;
}, {});
} | [
"function",
"instance_getters",
"(",
")",
"{",
"var",
"_parseArguments",
"=",
"parseArguments$1",
"(",
"arguments",
")",
",",
"getters",
"=",
"_parseArguments",
".",
"getters",
",",
"options",
"=",
"_parseArguments",
".",
"options",
";",
"return",
"Object",
".",
"keys",
"(",
"getters",
")",
".",
"reduce",
"(",
"function",
"(",
"instanceGetters",
",",
"name",
")",
"{",
"instanceGetters",
"[",
"name",
"]",
"=",
"function",
"(",
"state",
",",
"otherGetters",
")",
"{",
"return",
"function",
"(",
"instanceKey",
")",
"{",
"var",
"instance",
"=",
"state",
"[",
"options",
".",
"stateKey",
"||",
"'instances'",
"]",
".",
"find",
"(",
"function",
"(",
"obj",
")",
"{",
"return",
"obj",
"[",
"options",
".",
"instanceKey",
"||",
"'id'",
"]",
"===",
"instanceKey",
";",
"}",
")",
";",
"if",
"(",
"instance",
")",
"{",
"return",
"getters",
"[",
"name",
"]",
"(",
"instance",
",",
"otherGetters",
",",
"state",
",",
"instanceKey",
")",
";",
"}",
"}",
";",
"}",
";",
"return",
"instanceGetters",
";",
"}",
",",
"{",
"}",
")",
";",
"}"
] | Instance getters.
@return {Object} | [
"Instance",
"getters",
"."
] | 64742e0cbadb3e6ee62d722b26dbc27b87e1a378 | https://github.com/spyfu/spyfu-vuex-helpers/blob/64742e0cbadb3e6ee62d722b26dbc27b87e1a378/dist/spyfu-vuex-helpers.js#L171-L191 | train |
spyfu/spyfu-vuex-helpers | dist/spyfu-vuex-helpers.js | instance_mutations | function instance_mutations () {
var _parseArguments = parseArguments$2(arguments),
options = _parseArguments.options,
mutations = _parseArguments.mutations;
return Object.keys(mutations).reduce(function (instanceMutations, name) {
instanceMutations[name] = findInstanceThen(options, mutations[name]);
return instanceMutations;
}, {});
} | javascript | function instance_mutations () {
var _parseArguments = parseArguments$2(arguments),
options = _parseArguments.options,
mutations = _parseArguments.mutations;
return Object.keys(mutations).reduce(function (instanceMutations, name) {
instanceMutations[name] = findInstanceThen(options, mutations[name]);
return instanceMutations;
}, {});
} | [
"function",
"instance_mutations",
"(",
")",
"{",
"var",
"_parseArguments",
"=",
"parseArguments$2",
"(",
"arguments",
")",
",",
"options",
"=",
"_parseArguments",
".",
"options",
",",
"mutations",
"=",
"_parseArguments",
".",
"mutations",
";",
"return",
"Object",
".",
"keys",
"(",
"mutations",
")",
".",
"reduce",
"(",
"function",
"(",
"instanceMutations",
",",
"name",
")",
"{",
"instanceMutations",
"[",
"name",
"]",
"=",
"findInstanceThen",
"(",
"options",
",",
"mutations",
"[",
"name",
"]",
")",
";",
"return",
"instanceMutations",
";",
"}",
",",
"{",
"}",
")",
";",
"}"
] | Instance mutations.
@return {Object} | [
"Instance",
"mutations",
"."
] | 64742e0cbadb3e6ee62d722b26dbc27b87e1a378 | https://github.com/spyfu/spyfu-vuex-helpers/blob/64742e0cbadb3e6ee62d722b26dbc27b87e1a378/dist/spyfu-vuex-helpers.js#L208-L218 | train |
spyfu/spyfu-vuex-helpers | dist/spyfu-vuex-helpers.js | getEntries | function getEntries (obj) {
return Object.keys(obj).map(function (key) {
return [key, obj[key]];
});
} | javascript | function getEntries (obj) {
return Object.keys(obj).map(function (key) {
return [key, obj[key]];
});
} | [
"function",
"getEntries",
"(",
"obj",
")",
"{",
"return",
"Object",
".",
"keys",
"(",
"obj",
")",
".",
"map",
"(",
"function",
"(",
"key",
")",
"{",
"return",
"[",
"key",
",",
"obj",
"[",
"key",
"]",
"]",
";",
"}",
")",
";",
"}"
] | Similar to Object.entries but without using polyfill | [
"Similar",
"to",
"Object",
".",
"entries",
"but",
"without",
"using",
"polyfill"
] | 64742e0cbadb3e6ee62d722b26dbc27b87e1a378 | https://github.com/spyfu/spyfu-vuex-helpers/blob/64742e0cbadb3e6ee62d722b26dbc27b87e1a378/dist/spyfu-vuex-helpers.js#L236-L240 | train |
spyfu/spyfu-vuex-helpers | dist/spyfu-vuex-helpers.js | wrapGetterFn | function wrapGetterFn(_ref) {
var _ref2 = slicedToArray(_ref, 2),
key = _ref2[0],
originalFn = _ref2[1];
var newFn = function newFn() {
var innerFn = originalFn.apply(this, arguments);
if (typeof innerFn !== 'function') {
/* istanbul ignore next */
throw 'The getter ' + key + ' does not return a function. Try using the \'mapGetter\' helper instead';
}
return innerFn(this.id);
};
return [key, newFn];
} | javascript | function wrapGetterFn(_ref) {
var _ref2 = slicedToArray(_ref, 2),
key = _ref2[0],
originalFn = _ref2[1];
var newFn = function newFn() {
var innerFn = originalFn.apply(this, arguments);
if (typeof innerFn !== 'function') {
/* istanbul ignore next */
throw 'The getter ' + key + ' does not return a function. Try using the \'mapGetter\' helper instead';
}
return innerFn(this.id);
};
return [key, newFn];
} | [
"function",
"wrapGetterFn",
"(",
"_ref",
")",
"{",
"var",
"_ref2",
"=",
"slicedToArray",
"(",
"_ref",
",",
"2",
")",
",",
"key",
"=",
"_ref2",
"[",
"0",
"]",
",",
"originalFn",
"=",
"_ref2",
"[",
"1",
"]",
";",
"var",
"newFn",
"=",
"function",
"newFn",
"(",
")",
"{",
"var",
"innerFn",
"=",
"originalFn",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"if",
"(",
"typeof",
"innerFn",
"!==",
"'function'",
")",
"{",
"throw",
"'The getter '",
"+",
"key",
"+",
"' does not return a function. Try using the \\'mapGetter\\' helper instead'",
";",
"}",
"\\'",
"}",
";",
"\\'",
"}"
] | Create a wrapper function which invokes the original function passing in `this.id` | [
"Create",
"a",
"wrapper",
"function",
"which",
"invokes",
"the",
"original",
"function",
"passing",
"in",
"this",
".",
"id"
] | 64742e0cbadb3e6ee62d722b26dbc27b87e1a378 | https://github.com/spyfu/spyfu-vuex-helpers/blob/64742e0cbadb3e6ee62d722b26dbc27b87e1a378/dist/spyfu-vuex-helpers.js#L274-L291 | train |
spyfu/spyfu-vuex-helpers | dist/spyfu-vuex-helpers.js | resolveObjectPath | function resolveObjectPath (obj, path) {
var delimeter = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '.';
var pathArray = Array.isArray(path) ? path : path.split(delimeter);
return pathArray.reduce(function (p, item) {
return p && p[item];
}, obj);
} | javascript | function resolveObjectPath (obj, path) {
var delimeter = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '.';
var pathArray = Array.isArray(path) ? path : path.split(delimeter);
return pathArray.reduce(function (p, item) {
return p && p[item];
}, obj);
} | [
"function",
"resolveObjectPath",
"(",
"obj",
",",
"path",
")",
"{",
"var",
"delimeter",
"=",
"arguments",
".",
"length",
">",
"2",
"&&",
"arguments",
"[",
"2",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"2",
"]",
":",
"'.'",
";",
"var",
"pathArray",
"=",
"Array",
".",
"isArray",
"(",
"path",
")",
"?",
"path",
":",
"path",
".",
"split",
"(",
"delimeter",
")",
";",
"return",
"pathArray",
".",
"reduce",
"(",
"function",
"(",
"p",
",",
"item",
")",
"{",
"return",
"p",
"&&",
"p",
"[",
"item",
"]",
";",
"}",
",",
"obj",
")",
";",
"}"
] | Helper function for resolving nested object values.
@param {Object} obj source object
@param {Array|String} path path to nested value
@param {String|RegExp} delimeter characters / pattern to split path on
@return {mixed} | [
"Helper",
"function",
"for",
"resolving",
"nested",
"object",
"values",
"."
] | 64742e0cbadb3e6ee62d722b26dbc27b87e1a378 | https://github.com/spyfu/spyfu-vuex-helpers/blob/64742e0cbadb3e6ee62d722b26dbc27b87e1a378/dist/spyfu-vuex-helpers.js#L332-L340 | train |
spyfu/spyfu-vuex-helpers | dist/spyfu-vuex-helpers.js | normalizeMappings | function normalizeMappings(mappings) {
if (Array.isArray(mappings)) {
return mappings.reduce(function (normalizedMappings, key) {
normalizedMappings[key] = key;
return normalizedMappings;
}, {});
}
return mappings;
} | javascript | function normalizeMappings(mappings) {
if (Array.isArray(mappings)) {
return mappings.reduce(function (normalizedMappings, key) {
normalizedMappings[key] = key;
return normalizedMappings;
}, {});
}
return mappings;
} | [
"function",
"normalizeMappings",
"(",
"mappings",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"mappings",
")",
")",
"{",
"return",
"mappings",
".",
"reduce",
"(",
"function",
"(",
"normalizedMappings",
",",
"key",
")",
"{",
"normalizedMappings",
"[",
"key",
"]",
"=",
"key",
";",
"return",
"normalizedMappings",
";",
"}",
",",
"{",
"}",
")",
";",
"}",
"return",
"mappings",
";",
"}"
] | normalize the mappings into a consistent object format | [
"normalize",
"the",
"mappings",
"into",
"a",
"consistent",
"object",
"format"
] | 64742e0cbadb3e6ee62d722b26dbc27b87e1a378 | https://github.com/spyfu/spyfu-vuex-helpers/blob/64742e0cbadb3e6ee62d722b26dbc27b87e1a378/dist/spyfu-vuex-helpers.js#L376-L386 | train |
spyfu/spyfu-vuex-helpers | dist/spyfu-vuex-helpers.js | error | function error (message) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
throw new (Function.prototype.bind.apply(Error, [null].concat(['[spyfu-vuex-helpers]: ' + message], args)))();
} | javascript | function error (message) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
throw new (Function.prototype.bind.apply(Error, [null].concat(['[spyfu-vuex-helpers]: ' + message], args)))();
} | [
"function",
"error",
"(",
"message",
")",
"{",
"for",
"(",
"var",
"_len",
"=",
"arguments",
".",
"length",
",",
"args",
"=",
"Array",
"(",
"_len",
">",
"1",
"?",
"_len",
"-",
"1",
":",
"0",
")",
",",
"_key",
"=",
"1",
";",
"_key",
"<",
"_len",
";",
"_key",
"++",
")",
"{",
"args",
"[",
"_key",
"-",
"1",
"]",
"=",
"arguments",
"[",
"_key",
"]",
";",
"}",
"throw",
"new",
"(",
"Function",
".",
"prototype",
".",
"bind",
".",
"apply",
"(",
"Error",
",",
"[",
"null",
"]",
".",
"concat",
"(",
"[",
"'[spyfu-vuex-helpers]: '",
"+",
"message",
"]",
",",
"args",
")",
")",
")",
"(",
")",
";",
"}"
] | helper to throw consistent errors this is useful in testing to make sure caught errors are ours | [
"helper",
"to",
"throw",
"consistent",
"errors",
"this",
"is",
"useful",
"in",
"testing",
"to",
"make",
"sure",
"caught",
"errors",
"are",
"ours"
] | 64742e0cbadb3e6ee62d722b26dbc27b87e1a378 | https://github.com/spyfu/spyfu-vuex-helpers/blob/64742e0cbadb3e6ee62d722b26dbc27b87e1a378/dist/spyfu-vuex-helpers.js#L420-L426 | train |
spyfu/spyfu-vuex-helpers | dist/spyfu-vuex-helpers.js | map_two_way_state | function map_two_way_state () {
// this function supports two argument signatures. if the
// first argument is a string, we will use that as the
// namespace, and the next arg as the state mapping
var _parseArguments = parseArguments$3(arguments),
namespace = _parseArguments.namespace,
mappings = _parseArguments.mappings;
// then get the key and mutation names from our mappings
var parsedMappings = parseMappings(mappings);
// and last, turn them into getters and setters
var computedProperties = {};
Object.keys(parsedMappings).forEach(function (key) {
computedProperties[key] = {
get: createGetter$1(namespace, parsedMappings[key]),
set: createSetter(namespace, parsedMappings[key])
};
});
return computedProperties;
} | javascript | function map_two_way_state () {
// this function supports two argument signatures. if the
// first argument is a string, we will use that as the
// namespace, and the next arg as the state mapping
var _parseArguments = parseArguments$3(arguments),
namespace = _parseArguments.namespace,
mappings = _parseArguments.mappings;
// then get the key and mutation names from our mappings
var parsedMappings = parseMappings(mappings);
// and last, turn them into getters and setters
var computedProperties = {};
Object.keys(parsedMappings).forEach(function (key) {
computedProperties[key] = {
get: createGetter$1(namespace, parsedMappings[key]),
set: createSetter(namespace, parsedMappings[key])
};
});
return computedProperties;
} | [
"function",
"map_two_way_state",
"(",
")",
"{",
"var",
"_parseArguments",
"=",
"parseArguments$3",
"(",
"arguments",
")",
",",
"namespace",
"=",
"_parseArguments",
".",
"namespace",
",",
"mappings",
"=",
"_parseArguments",
".",
"mappings",
";",
"var",
"parsedMappings",
"=",
"parseMappings",
"(",
"mappings",
")",
";",
"var",
"computedProperties",
"=",
"{",
"}",
";",
"Object",
".",
"keys",
"(",
"parsedMappings",
")",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"computedProperties",
"[",
"key",
"]",
"=",
"{",
"get",
":",
"createGetter$1",
"(",
"namespace",
",",
"parsedMappings",
"[",
"key",
"]",
")",
",",
"set",
":",
"createSetter",
"(",
"namespace",
",",
"parsedMappings",
"[",
"key",
"]",
")",
"}",
";",
"}",
")",
";",
"return",
"computedProperties",
";",
"}"
] | Map vuex state with two way computed properties
@param {string|Object} required the module namespace, or state mappings
@param {Object} optional state mappings
@return {Object} | [
"Map",
"vuex",
"state",
"with",
"two",
"way",
"computed",
"properties"
] | 64742e0cbadb3e6ee62d722b26dbc27b87e1a378 | https://github.com/spyfu/spyfu-vuex-helpers/blob/64742e0cbadb3e6ee62d722b26dbc27b87e1a378/dist/spyfu-vuex-helpers.js#L435-L459 | train |
spyfu/spyfu-vuex-helpers | dist/spyfu-vuex-helpers.js | parseMappings | function parseMappings(obj) {
var mapping = {};
// throw a helpful error when mapTwoWayState is mixed up with mapState
if (Array.isArray(obj)) {
error('Invalid arguments for mapTwoWayState. State mapping must be an object in { \'path.to.state\': \'mutationName\' } format.');
}
Object.keys(obj).forEach(function (key) {
var value = obj[key];
var vmKey = key.slice(key.lastIndexOf('.') + 1);
if (typeof value === 'string') {
mapping[vmKey] = { key: key, mutation: value };
} else {
mapping[vmKey] = { key: value.key, mutation: value.mutation };
}
});
return mapping;
} | javascript | function parseMappings(obj) {
var mapping = {};
// throw a helpful error when mapTwoWayState is mixed up with mapState
if (Array.isArray(obj)) {
error('Invalid arguments for mapTwoWayState. State mapping must be an object in { \'path.to.state\': \'mutationName\' } format.');
}
Object.keys(obj).forEach(function (key) {
var value = obj[key];
var vmKey = key.slice(key.lastIndexOf('.') + 1);
if (typeof value === 'string') {
mapping[vmKey] = { key: key, mutation: value };
} else {
mapping[vmKey] = { key: value.key, mutation: value.mutation };
}
});
return mapping;
} | [
"function",
"parseMappings",
"(",
"obj",
")",
"{",
"var",
"mapping",
"=",
"{",
"}",
";",
"if",
"(",
"Array",
".",
"isArray",
"(",
"obj",
")",
")",
"{",
"error",
"(",
"'Invalid arguments for mapTwoWayState. State mapping must be an object in { \\'path.to.state\\': \\'mutationName\\' } format.'",
")",
";",
"}",
"\\'",
"\\'",
"}"
] | determine our key and mutation values | [
"determine",
"our",
"key",
"and",
"mutation",
"values"
] | 64742e0cbadb3e6ee62d722b26dbc27b87e1a378 | https://github.com/spyfu/spyfu-vuex-helpers/blob/64742e0cbadb3e6ee62d722b26dbc27b87e1a378/dist/spyfu-vuex-helpers.js#L470-L490 | train |
spyfu/spyfu-vuex-helpers | dist/spyfu-vuex-helpers.js | simple_instance_setters | function simple_instance_setters (setters) {
var stateKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'instances';
var instanceKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'id';
// loop over the setter keys and make a mutation for each
return Object.keys(setters).reduce(function (mutations, name) {
// attach our new mutation to result
return Object.assign({}, mutations, defineProperty({}, name, function (state, payload) {
// find the instance that we're mutating
var instance = findInstance(state, stateKey, instanceKey, payload);
if (instance) {
var value = findValue(payload, instanceKey);
// if the setter name has a dot, then resolve the
// state path before feeding our value into it.
if (setters[name].indexOf('.') > -1) {
var obj = setters[name].split('.');
var key = obj.pop();
resolveObjectPath(instance, obj)[key] = value;
} else {
// otherwise, just set the instance state to our value
instance[setters[name]] = value;
}
} else {
// if the instance wasn't found, let the dev know with a warning
console.warn('An instance with an identifier of ' + instanceKey + ' was not found.');
}
}));
}, {});
} | javascript | function simple_instance_setters (setters) {
var stateKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'instances';
var instanceKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'id';
// loop over the setter keys and make a mutation for each
return Object.keys(setters).reduce(function (mutations, name) {
// attach our new mutation to result
return Object.assign({}, mutations, defineProperty({}, name, function (state, payload) {
// find the instance that we're mutating
var instance = findInstance(state, stateKey, instanceKey, payload);
if (instance) {
var value = findValue(payload, instanceKey);
// if the setter name has a dot, then resolve the
// state path before feeding our value into it.
if (setters[name].indexOf('.') > -1) {
var obj = setters[name].split('.');
var key = obj.pop();
resolveObjectPath(instance, obj)[key] = value;
} else {
// otherwise, just set the instance state to our value
instance[setters[name]] = value;
}
} else {
// if the instance wasn't found, let the dev know with a warning
console.warn('An instance with an identifier of ' + instanceKey + ' was not found.');
}
}));
}, {});
} | [
"function",
"simple_instance_setters",
"(",
"setters",
")",
"{",
"var",
"stateKey",
"=",
"arguments",
".",
"length",
">",
"1",
"&&",
"arguments",
"[",
"1",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"1",
"]",
":",
"'instances'",
";",
"var",
"instanceKey",
"=",
"arguments",
".",
"length",
">",
"2",
"&&",
"arguments",
"[",
"2",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"2",
"]",
":",
"'id'",
";",
"return",
"Object",
".",
"keys",
"(",
"setters",
")",
".",
"reduce",
"(",
"function",
"(",
"mutations",
",",
"name",
")",
"{",
"return",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"mutations",
",",
"defineProperty",
"(",
"{",
"}",
",",
"name",
",",
"function",
"(",
"state",
",",
"payload",
")",
"{",
"var",
"instance",
"=",
"findInstance",
"(",
"state",
",",
"stateKey",
",",
"instanceKey",
",",
"payload",
")",
";",
"if",
"(",
"instance",
")",
"{",
"var",
"value",
"=",
"findValue",
"(",
"payload",
",",
"instanceKey",
")",
";",
"if",
"(",
"setters",
"[",
"name",
"]",
".",
"indexOf",
"(",
"'.'",
")",
">",
"-",
"1",
")",
"{",
"var",
"obj",
"=",
"setters",
"[",
"name",
"]",
".",
"split",
"(",
"'.'",
")",
";",
"var",
"key",
"=",
"obj",
".",
"pop",
"(",
")",
";",
"resolveObjectPath",
"(",
"instance",
",",
"obj",
")",
"[",
"key",
"]",
"=",
"value",
";",
"}",
"else",
"{",
"instance",
"[",
"setters",
"[",
"name",
"]",
"]",
"=",
"value",
";",
"}",
"}",
"else",
"{",
"console",
".",
"warn",
"(",
"'An instance with an identifier of '",
"+",
"instanceKey",
"+",
"' was not found.'",
")",
";",
"}",
"}",
")",
")",
";",
"}",
",",
"{",
"}",
")",
";",
"}"
] | Simple mutations that set an instance's state equal to a value.
@param {Object}
@param {String}
@param {String}
@return {Object} | [
"Simple",
"mutations",
"that",
"set",
"an",
"instance",
"s",
"state",
"equal",
"to",
"a",
"value",
"."
] | 64742e0cbadb3e6ee62d722b26dbc27b87e1a378 | https://github.com/spyfu/spyfu-vuex-helpers/blob/64742e0cbadb3e6ee62d722b26dbc27b87e1a378/dist/spyfu-vuex-helpers.js#L528-L560 | train |
spyfu/spyfu-vuex-helpers | dist/spyfu-vuex-helpers.js | simple_setters | function simple_setters (setters) {
// loop over the setter keys and make a mutation for each
return Object.keys(setters).reduce(function (mutations, name) {
// attach our new mutation to result
return Object.assign({}, mutations, defineProperty({}, name, function (state, value) {
// if the setter name has a dot, then resolve the
// state path before feeding our value into it.
if (setters[name].indexOf('.') > -1) {
var obj = setters[name].split('.');
var key = obj.pop();
resolveObjectPath(state, obj)[key] = value;
}
// otherwise, just set the state to our value
else state[setters[name]] = value;
}));
}, {});
} | javascript | function simple_setters (setters) {
// loop over the setter keys and make a mutation for each
return Object.keys(setters).reduce(function (mutations, name) {
// attach our new mutation to result
return Object.assign({}, mutations, defineProperty({}, name, function (state, value) {
// if the setter name has a dot, then resolve the
// state path before feeding our value into it.
if (setters[name].indexOf('.') > -1) {
var obj = setters[name].split('.');
var key = obj.pop();
resolveObjectPath(state, obj)[key] = value;
}
// otherwise, just set the state to our value
else state[setters[name]] = value;
}));
}, {});
} | [
"function",
"simple_setters",
"(",
"setters",
")",
"{",
"return",
"Object",
".",
"keys",
"(",
"setters",
")",
".",
"reduce",
"(",
"function",
"(",
"mutations",
",",
"name",
")",
"{",
"return",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"mutations",
",",
"defineProperty",
"(",
"{",
"}",
",",
"name",
",",
"function",
"(",
"state",
",",
"value",
")",
"{",
"if",
"(",
"setters",
"[",
"name",
"]",
".",
"indexOf",
"(",
"'.'",
")",
">",
"-",
"1",
")",
"{",
"var",
"obj",
"=",
"setters",
"[",
"name",
"]",
".",
"split",
"(",
"'.'",
")",
";",
"var",
"key",
"=",
"obj",
".",
"pop",
"(",
")",
";",
"resolveObjectPath",
"(",
"state",
",",
"obj",
")",
"[",
"key",
"]",
"=",
"value",
";",
"}",
"else",
"state",
"[",
"setters",
"[",
"name",
"]",
"]",
"=",
"value",
";",
"}",
")",
")",
";",
"}",
",",
"{",
"}",
")",
";",
"}"
] | Simple mutations that set a piece of state equal to a value.
@param {Object} setters Object mapping mutations to state
@return {Object} | [
"Simple",
"mutations",
"that",
"set",
"a",
"piece",
"of",
"state",
"equal",
"to",
"a",
"value",
"."
] | 64742e0cbadb3e6ee62d722b26dbc27b87e1a378 | https://github.com/spyfu/spyfu-vuex-helpers/blob/64742e0cbadb3e6ee62d722b26dbc27b87e1a378/dist/spyfu-vuex-helpers.js#L695-L715 | train |
SuneBear/midi.js | examples/inc/event.js | function(event) {
event = event || window.event;
self.state = count++ ? "change" : "start";
self.wheelDelta = event.detail ? event.detail * -20 : event.wheelDelta;
conf.listener(event, self);
clearTimeout(interval);
interval = setTimeout(function() {
count = 0;
self.state = "end";
self.wheelDelta = 0;
conf.listener(event, self);
}, timeout);
} | javascript | function(event) {
event = event || window.event;
self.state = count++ ? "change" : "start";
self.wheelDelta = event.detail ? event.detail * -20 : event.wheelDelta;
conf.listener(event, self);
clearTimeout(interval);
interval = setTimeout(function() {
count = 0;
self.state = "end";
self.wheelDelta = 0;
conf.listener(event, self);
}, timeout);
} | [
"function",
"(",
"event",
")",
"{",
"event",
"=",
"event",
"||",
"window",
".",
"event",
";",
"self",
".",
"state",
"=",
"count",
"++",
"?",
"\"change\"",
":",
"\"start\"",
";",
"self",
".",
"wheelDelta",
"=",
"event",
".",
"detail",
"?",
"event",
".",
"detail",
"*",
"-",
"20",
":",
"event",
".",
"wheelDelta",
";",
"conf",
".",
"listener",
"(",
"event",
",",
"self",
")",
";",
"clearTimeout",
"(",
"interval",
")",
";",
"interval",
"=",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"count",
"=",
"0",
";",
"self",
".",
"state",
"=",
"\"end\"",
";",
"self",
".",
"wheelDelta",
"=",
"0",
";",
"conf",
".",
"listener",
"(",
"event",
",",
"self",
")",
";",
"}",
",",
"timeout",
")",
";",
"}"
] | Tracking the events. | [
"Tracking",
"the",
"events",
"."
] | 46856c7c18b13938ef4167a5f49114cd487802c0 | https://github.com/SuneBear/midi.js/blob/46856c7c18b13938ef4167a5f49114cd487802c0/examples/inc/event.js#L1860-L1872 | train |
|
ocadotechnology/quantumjs | quantum-api/lib/entity-transforms/components/type.js | getType | function getType (str, typeLinks) {
if (str in typeLinks) {
return dom.create('a').class('qm-api-type-link').attr('href', typeLinks[str]).text(str)
} else {
return str
}
} | javascript | function getType (str, typeLinks) {
if (str in typeLinks) {
return dom.create('a').class('qm-api-type-link').attr('href', typeLinks[str]).text(str)
} else {
return str
}
} | [
"function",
"getType",
"(",
"str",
",",
"typeLinks",
")",
"{",
"if",
"(",
"str",
"in",
"typeLinks",
")",
"{",
"return",
"dom",
".",
"create",
"(",
"'a'",
")",
".",
"class",
"(",
"'qm-api-type-link'",
")",
".",
"attr",
"(",
"'href'",
",",
"typeLinks",
"[",
"str",
"]",
")",
".",
"text",
"(",
"str",
")",
"}",
"else",
"{",
"return",
"str",
"}",
"}"
] | Lookup the type url from the availble type links | [
"Lookup",
"the",
"type",
"url",
"from",
"the",
"availble",
"type",
"links"
] | 5bc684b750472296f186a816529272c36218db04 | https://github.com/ocadotechnology/quantumjs/blob/5bc684b750472296f186a816529272c36218db04/quantum-api/lib/entity-transforms/components/type.js#L6-L12 | train |
misoproject/storyboard | dist/miso.storyboard.r.0.1.0.js | children_to | function children_to( sceneName, argsArr, deferred ) {
var toScene = this.scenes[sceneName],
fromScene = this._current,
args = argsArr ? argsArr : [],
complete = this._complete = deferred || _.Deferred(),
exitComplete = _.Deferred(),
enterComplete = _.Deferred(),
publish = _.bind(function(name, isExit) {
var sceneName = isExit ? fromScene : toScene;
sceneName = sceneName ? sceneName.name : "";
this.publish(name, fromScene, toScene);
if (name !== "start" || name !== "end") {
this.publish(sceneName + ":" + name);
}
}, this),
bailout = _.bind(function() {
this._transitioning = false;
this._current = fromScene;
publish("fail");
complete.reject();
}, this),
success = _.bind(function() {
publish("enter");
this._transitioning = false;
this._current = toScene;
publish("end");
complete.resolve();
}, this);
if (!toScene) {
throw "Scene \"" + sceneName + "\" not found!";
}
// we in the middle of a transition?
if (this._transitioning) {
return complete.reject();
}
publish("start");
this._transitioning = true;
if (fromScene) {
// we are coming from a scene, so transition out of it.
fromScene.to("exit", args, exitComplete);
exitComplete.done(function() {
publish("exit", true);
});
} else {
exitComplete.resolve();
}
// when we're done exiting, enter the next set
_.when(exitComplete).then(function() {
toScene.to(toScene._initial || "enter", args, enterComplete);
}).fail(bailout);
enterComplete
.then(success)
.fail(bailout);
return complete.promise();
} | javascript | function children_to( sceneName, argsArr, deferred ) {
var toScene = this.scenes[sceneName],
fromScene = this._current,
args = argsArr ? argsArr : [],
complete = this._complete = deferred || _.Deferred(),
exitComplete = _.Deferred(),
enterComplete = _.Deferred(),
publish = _.bind(function(name, isExit) {
var sceneName = isExit ? fromScene : toScene;
sceneName = sceneName ? sceneName.name : "";
this.publish(name, fromScene, toScene);
if (name !== "start" || name !== "end") {
this.publish(sceneName + ":" + name);
}
}, this),
bailout = _.bind(function() {
this._transitioning = false;
this._current = fromScene;
publish("fail");
complete.reject();
}, this),
success = _.bind(function() {
publish("enter");
this._transitioning = false;
this._current = toScene;
publish("end");
complete.resolve();
}, this);
if (!toScene) {
throw "Scene \"" + sceneName + "\" not found!";
}
// we in the middle of a transition?
if (this._transitioning) {
return complete.reject();
}
publish("start");
this._transitioning = true;
if (fromScene) {
// we are coming from a scene, so transition out of it.
fromScene.to("exit", args, exitComplete);
exitComplete.done(function() {
publish("exit", true);
});
} else {
exitComplete.resolve();
}
// when we're done exiting, enter the next set
_.when(exitComplete).then(function() {
toScene.to(toScene._initial || "enter", args, enterComplete);
}).fail(bailout);
enterComplete
.then(success)
.fail(bailout);
return complete.promise();
} | [
"function",
"children_to",
"(",
"sceneName",
",",
"argsArr",
",",
"deferred",
")",
"{",
"var",
"toScene",
"=",
"this",
".",
"scenes",
"[",
"sceneName",
"]",
",",
"fromScene",
"=",
"this",
".",
"_current",
",",
"args",
"=",
"argsArr",
"?",
"argsArr",
":",
"[",
"]",
",",
"complete",
"=",
"this",
".",
"_complete",
"=",
"deferred",
"||",
"_",
".",
"Deferred",
"(",
")",
",",
"exitComplete",
"=",
"_",
".",
"Deferred",
"(",
")",
",",
"enterComplete",
"=",
"_",
".",
"Deferred",
"(",
")",
",",
"publish",
"=",
"_",
".",
"bind",
"(",
"function",
"(",
"name",
",",
"isExit",
")",
"{",
"var",
"sceneName",
"=",
"isExit",
"?",
"fromScene",
":",
"toScene",
";",
"sceneName",
"=",
"sceneName",
"?",
"sceneName",
".",
"name",
":",
"\"\"",
";",
"this",
".",
"publish",
"(",
"name",
",",
"fromScene",
",",
"toScene",
")",
";",
"if",
"(",
"name",
"!==",
"\"start\"",
"||",
"name",
"!==",
"\"end\"",
")",
"{",
"this",
".",
"publish",
"(",
"sceneName",
"+",
"\":\"",
"+",
"name",
")",
";",
"}",
"}",
",",
"this",
")",
",",
"bailout",
"=",
"_",
".",
"bind",
"(",
"function",
"(",
")",
"{",
"this",
".",
"_transitioning",
"=",
"false",
";",
"this",
".",
"_current",
"=",
"fromScene",
";",
"publish",
"(",
"\"fail\"",
")",
";",
"complete",
".",
"reject",
"(",
")",
";",
"}",
",",
"this",
")",
",",
"success",
"=",
"_",
".",
"bind",
"(",
"function",
"(",
")",
"{",
"publish",
"(",
"\"enter\"",
")",
";",
"this",
".",
"_transitioning",
"=",
"false",
";",
"this",
".",
"_current",
"=",
"toScene",
";",
"publish",
"(",
"\"end\"",
")",
";",
"complete",
".",
"resolve",
"(",
")",
";",
"}",
",",
"this",
")",
";",
"if",
"(",
"!",
"toScene",
")",
"{",
"throw",
"\"Scene \\\"\"",
"+",
"\\\"",
"+",
"sceneName",
";",
"}",
"\"\\\" not found!\"",
"\\\"",
"if",
"(",
"this",
".",
"_transitioning",
")",
"{",
"return",
"complete",
".",
"reject",
"(",
")",
";",
"}",
"publish",
"(",
"\"start\"",
")",
";",
"this",
".",
"_transitioning",
"=",
"true",
";",
"if",
"(",
"fromScene",
")",
"{",
"fromScene",
".",
"to",
"(",
"\"exit\"",
",",
"args",
",",
"exitComplete",
")",
";",
"exitComplete",
".",
"done",
"(",
"function",
"(",
")",
"{",
"publish",
"(",
"\"exit\"",
",",
"true",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"exitComplete",
".",
"resolve",
"(",
")",
";",
"}",
"_",
".",
"when",
"(",
"exitComplete",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"toScene",
".",
"to",
"(",
"toScene",
".",
"_initial",
"||",
"\"enter\"",
",",
"args",
",",
"enterComplete",
")",
";",
"}",
")",
".",
"fail",
"(",
"bailout",
")",
";",
"}"
] | Used as the function to scenes that do have children. | [
"Used",
"as",
"the",
"function",
"to",
"scenes",
"that",
"do",
"have",
"children",
"."
] | 96d6cdfe756e0e4f2df7c9a55c414fe93a4c38ec | https://github.com/misoproject/storyboard/blob/96d6cdfe756e0e4f2df7c9a55c414fe93a4c38ec/dist/miso.storyboard.r.0.1.0.js#L377-L446 | train |
ocadotechnology/quantumjs | quantum-markdown/lib/index.js | sluggifyText | function sluggifyText (text) {
const slug = unEscapeHtmlTags(text).toLowerCase()
// Replace 'unsafe' chars with dashes (!!!! is changed to -)
.replace(unsafeCharsRegex, '-')
// Replace multiple concurrent dashes with a single dash
.replace(multiDashRegex, '-')
// Remove trailing -
.replace(lastCharDashRegex, '')
// Encode the resulting string to make it url-safe
return encodeURIComponent(slug)
} | javascript | function sluggifyText (text) {
const slug = unEscapeHtmlTags(text).toLowerCase()
// Replace 'unsafe' chars with dashes (!!!! is changed to -)
.replace(unsafeCharsRegex, '-')
// Replace multiple concurrent dashes with a single dash
.replace(multiDashRegex, '-')
// Remove trailing -
.replace(lastCharDashRegex, '')
// Encode the resulting string to make it url-safe
return encodeURIComponent(slug)
} | [
"function",
"sluggifyText",
"(",
"text",
")",
"{",
"const",
"slug",
"=",
"unEscapeHtmlTags",
"(",
"text",
")",
".",
"toLowerCase",
"(",
")",
".",
"replace",
"(",
"unsafeCharsRegex",
",",
"'-'",
")",
".",
"replace",
"(",
"multiDashRegex",
",",
"'-'",
")",
".",
"replace",
"(",
"lastCharDashRegex",
",",
"''",
")",
"return",
"encodeURIComponent",
"(",
"slug",
")",
"}"
] | Takes a text string and returns a url-safe string for use when de-duplicating | [
"Takes",
"a",
"text",
"string",
"and",
"returns",
"a",
"url",
"-",
"safe",
"string",
"for",
"use",
"when",
"de",
"-",
"duplicating"
] | 5bc684b750472296f186a816529272c36218db04 | https://github.com/ocadotechnology/quantumjs/blob/5bc684b750472296f186a816529272c36218db04/quantum-markdown/lib/index.js#L56-L66 | train |
ocadotechnology/quantumjs | quantum-markdown/lib/index.js | dedupeAndSluggify | function dedupeAndSluggify (sluggify) {
const existingHeadings = {}
return (heading) => {
const sluggifiedText = sluggify(heading)
const existingCount = existingHeadings[sluggifiedText] || 0
existingHeadings[sluggifiedText] = existingCount + 1
return existingCount > 0 ? `${sluggifiedText}-${existingCount}` : sluggifiedText
}
} | javascript | function dedupeAndSluggify (sluggify) {
const existingHeadings = {}
return (heading) => {
const sluggifiedText = sluggify(heading)
const existingCount = existingHeadings[sluggifiedText] || 0
existingHeadings[sluggifiedText] = existingCount + 1
return existingCount > 0 ? `${sluggifiedText}-${existingCount}` : sluggifiedText
}
} | [
"function",
"dedupeAndSluggify",
"(",
"sluggify",
")",
"{",
"const",
"existingHeadings",
"=",
"{",
"}",
"return",
"(",
"heading",
")",
"=>",
"{",
"const",
"sluggifiedText",
"=",
"sluggify",
"(",
"heading",
")",
"const",
"existingCount",
"=",
"existingHeadings",
"[",
"sluggifiedText",
"]",
"||",
"0",
"existingHeadings",
"[",
"sluggifiedText",
"]",
"=",
"existingCount",
"+",
"1",
"return",
"existingCount",
">",
"0",
"?",
"`",
"${",
"sluggifiedText",
"}",
"${",
"existingCount",
"}",
"`",
":",
"sluggifiedText",
"}",
"}"
] | Takes an array and an sluggify function and returns a function that de-duplicates headings | [
"Takes",
"an",
"array",
"and",
"an",
"sluggify",
"function",
"and",
"returns",
"a",
"function",
"that",
"de",
"-",
"duplicates",
"headings"
] | 5bc684b750472296f186a816529272c36218db04 | https://github.com/ocadotechnology/quantumjs/blob/5bc684b750472296f186a816529272c36218db04/quantum-markdown/lib/index.js#L69-L77 | train |
retsr/rets.js | lib/client.js | Client | function Client(name, password) {
if (!(this instanceof Client)) {
return new Client(name, password);
}
this.name = name || 'RETS-Connector1/2';
this.password = password || '';
} | javascript | function Client(name, password) {
if (!(this instanceof Client)) {
return new Client(name, password);
}
this.name = name || 'RETS-Connector1/2';
this.password = password || '';
} | [
"function",
"Client",
"(",
"name",
",",
"password",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Client",
")",
")",
"{",
"return",
"new",
"Client",
"(",
"name",
",",
"password",
")",
";",
"}",
"this",
".",
"name",
"=",
"name",
"||",
"'RETS-Connector1/2'",
";",
"this",
".",
"password",
"=",
"password",
"||",
"''",
";",
"}"
] | Client class encapsulates User Agent instance data.
@param {Object} config
@param {string} config.name - The user agent's name
@param {string} config.password - The user agent's password | [
"Client",
"class",
"encapsulates",
"User",
"Agent",
"instance",
"data",
"."
] | 52f0287390a1d0cb93bbbd7edf630d7ebcb6de26 | https://github.com/retsr/rets.js/blob/52f0287390a1d0cb93bbbd7edf630d7ebcb6de26/lib/client.js#L24-L33 | train |
mariusc23/express-query-int | lib/parse.js | parseNums | function parseNums(obj, options) {
var result = Array.isArray(obj) ? [] : {},
key,
value,
parsedValue;
for (key in obj) {
if (obj.hasOwnProperty(key)) {
value = obj[key];
parsedValue = options.parser.call(null, value, 10, key);
if (typeof value === 'string' && !isNaN(parsedValue)) {
result[key] = parsedValue;
}
else if (value.constructor === Object || Array.isArray(value)) {
result[key] = parseNums(value, options);
}
else {
result[key] = value;
}
}
}
return result;
} | javascript | function parseNums(obj, options) {
var result = Array.isArray(obj) ? [] : {},
key,
value,
parsedValue;
for (key in obj) {
if (obj.hasOwnProperty(key)) {
value = obj[key];
parsedValue = options.parser.call(null, value, 10, key);
if (typeof value === 'string' && !isNaN(parsedValue)) {
result[key] = parsedValue;
}
else if (value.constructor === Object || Array.isArray(value)) {
result[key] = parseNums(value, options);
}
else {
result[key] = value;
}
}
}
return result;
} | [
"function",
"parseNums",
"(",
"obj",
",",
"options",
")",
"{",
"var",
"result",
"=",
"Array",
".",
"isArray",
"(",
"obj",
")",
"?",
"[",
"]",
":",
"{",
"}",
",",
"key",
",",
"value",
",",
"parsedValue",
";",
"for",
"(",
"key",
"in",
"obj",
")",
"{",
"if",
"(",
"obj",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"value",
"=",
"obj",
"[",
"key",
"]",
";",
"parsedValue",
"=",
"options",
".",
"parser",
".",
"call",
"(",
"null",
",",
"value",
",",
"10",
",",
"key",
")",
";",
"if",
"(",
"typeof",
"value",
"===",
"'string'",
"&&",
"!",
"isNaN",
"(",
"parsedValue",
")",
")",
"{",
"result",
"[",
"key",
"]",
"=",
"parsedValue",
";",
"}",
"else",
"if",
"(",
"value",
".",
"constructor",
"===",
"Object",
"||",
"Array",
".",
"isArray",
"(",
"value",
")",
")",
"{",
"result",
"[",
"key",
"]",
"=",
"parseNums",
"(",
"value",
",",
"options",
")",
";",
"}",
"else",
"{",
"result",
"[",
"key",
"]",
"=",
"value",
";",
"}",
"}",
"}",
"return",
"result",
";",
"}"
] | Attempts to convert object properties recursively to numbers.
@param {Object} obj - Object to iterate over.
@param {Object} options - Options.
@param {Function} options.parser - Parser to process string with. Should return NaN if not a valid number. Defaults to parseInt.
@return {Object} Returns new object with same properties (shallow copy). | [
"Attempts",
"to",
"convert",
"object",
"properties",
"recursively",
"to",
"numbers",
"."
] | 01aad8c910c006aae7bc87306a742d35c510a0a5 | https://github.com/mariusc23/express-query-int/blob/01aad8c910c006aae7bc87306a742d35c510a0a5/lib/parse.js#L10-L34 | train |
ocadotechnology/quantumjs | quantum-template/lib/index.js | wrapper | function wrapper (fileContent, wrapperOptions) {
const selection = quantum.select({
type: '',
params: [],
content: fileContent.content
})
if (selection.has('template')) {
const template = selection.select('template')
// find out the name of the entity to replace with the page content
const contentEntityType = template.has('contentEntityName') ?
template.select('contentEntityName').ps() : 'content'
// find the place to mount the rest of the page's content
const contentEntity = template.select('content').select(contentEntityType, {recursive: true})
const parentContent = contentEntity.parent().content()
// find out where the mount point is
const position = parentContent.indexOf(contentEntity.entity())
// get the content to place at the mount point (ie remove all @templates from the page)
const nonTemplateContent = selection.filter(x => x.type !== 'template')
// make the replacement
parentContent.splice.apply(parentContent, [position, 1].concat(nonTemplateContent.content()))
return {
content: template.select('content').content()
}
} else {
return fileContent
}
} | javascript | function wrapper (fileContent, wrapperOptions) {
const selection = quantum.select({
type: '',
params: [],
content: fileContent.content
})
if (selection.has('template')) {
const template = selection.select('template')
// find out the name of the entity to replace with the page content
const contentEntityType = template.has('contentEntityName') ?
template.select('contentEntityName').ps() : 'content'
// find the place to mount the rest of the page's content
const contentEntity = template.select('content').select(contentEntityType, {recursive: true})
const parentContent = contentEntity.parent().content()
// find out where the mount point is
const position = parentContent.indexOf(contentEntity.entity())
// get the content to place at the mount point (ie remove all @templates from the page)
const nonTemplateContent = selection.filter(x => x.type !== 'template')
// make the replacement
parentContent.splice.apply(parentContent, [position, 1].concat(nonTemplateContent.content()))
return {
content: template.select('content').content()
}
} else {
return fileContent
}
} | [
"function",
"wrapper",
"(",
"fileContent",
",",
"wrapperOptions",
")",
"{",
"const",
"selection",
"=",
"quantum",
".",
"select",
"(",
"{",
"type",
":",
"''",
",",
"params",
":",
"[",
"]",
",",
"content",
":",
"fileContent",
".",
"content",
"}",
")",
"if",
"(",
"selection",
".",
"has",
"(",
"'template'",
")",
")",
"{",
"const",
"template",
"=",
"selection",
".",
"select",
"(",
"'template'",
")",
"const",
"contentEntityType",
"=",
"template",
".",
"has",
"(",
"'contentEntityName'",
")",
"?",
"template",
".",
"select",
"(",
"'contentEntityName'",
")",
".",
"ps",
"(",
")",
":",
"'content'",
"const",
"contentEntity",
"=",
"template",
".",
"select",
"(",
"'content'",
")",
".",
"select",
"(",
"contentEntityType",
",",
"{",
"recursive",
":",
"true",
"}",
")",
"const",
"parentContent",
"=",
"contentEntity",
".",
"parent",
"(",
")",
".",
"content",
"(",
")",
"const",
"position",
"=",
"parentContent",
".",
"indexOf",
"(",
"contentEntity",
".",
"entity",
"(",
")",
")",
"const",
"nonTemplateContent",
"=",
"selection",
".",
"filter",
"(",
"x",
"=>",
"x",
".",
"type",
"!==",
"'template'",
")",
"parentContent",
".",
"splice",
".",
"apply",
"(",
"parentContent",
",",
"[",
"position",
",",
"1",
"]",
".",
"concat",
"(",
"nonTemplateContent",
".",
"content",
"(",
")",
")",
")",
"return",
"{",
"content",
":",
"template",
".",
"select",
"(",
"'content'",
")",
".",
"content",
"(",
")",
"}",
"}",
"else",
"{",
"return",
"fileContent",
"}",
"}"
] | Processes the page for wrapping templates. | [
"Processes",
"the",
"page",
"for",
"wrapping",
"templates",
"."
] | 5bc684b750472296f186a816529272c36218db04 | https://github.com/ocadotechnology/quantumjs/blob/5bc684b750472296f186a816529272c36218db04/quantum-template/lib/index.js#L233-L267 | train |
gauravchl/ansi-art | webapp/src/index.js | readFile | function readFile(e) {
const file = e.currentTarget.files && e.currentTarget.files[0];
const reader = new FileReader();
reader.onload = event => ArtBoard.loadANSI(event.target.result);
if (file) reader.readAsText(file);
} | javascript | function readFile(e) {
const file = e.currentTarget.files && e.currentTarget.files[0];
const reader = new FileReader();
reader.onload = event => ArtBoard.loadANSI(event.target.result);
if (file) reader.readAsText(file);
} | [
"function",
"readFile",
"(",
"e",
")",
"{",
"const",
"file",
"=",
"e",
".",
"currentTarget",
".",
"files",
"&&",
"e",
".",
"currentTarget",
".",
"files",
"[",
"0",
"]",
";",
"const",
"reader",
"=",
"new",
"FileReader",
"(",
")",
";",
"reader",
".",
"onload",
"=",
"event",
"=>",
"ArtBoard",
".",
"loadANSI",
"(",
"event",
".",
"target",
".",
"result",
")",
";",
"if",
"(",
"file",
")",
"reader",
".",
"readAsText",
"(",
"file",
")",
";",
"}"
] | Init file uploader | [
"Init",
"file",
"uploader"
] | ed23b07320999728d2eeee07872c9e7881a700f9 | https://github.com/gauravchl/ansi-art/blob/ed23b07320999728d2eeee07872c9e7881a700f9/webapp/src/index.js#L14-L20 | train |
Banno/polymer-lint | spec/support/helpers/streamFromString.js | streamFromString | function streamFromString(string) {
const s = new stream.Readable();
s.push(string);
s.push(null);
return s;
} | javascript | function streamFromString(string) {
const s = new stream.Readable();
s.push(string);
s.push(null);
return s;
} | [
"function",
"streamFromString",
"(",
"string",
")",
"{",
"const",
"s",
"=",
"new",
"stream",
".",
"Readable",
"(",
")",
";",
"s",
".",
"push",
"(",
"string",
")",
";",
"s",
".",
"push",
"(",
"null",
")",
";",
"return",
"s",
";",
"}"
] | helpers.streamFromString
@param {string} string
@return {stream.Readable} A Readable stream that will emit the given string | [
"helpers",
".",
"streamFromString"
] | cf4ffdc63837280080b67f496d038d33a3975b6f | https://github.com/Banno/polymer-lint/blob/cf4ffdc63837280080b67f496d038d33a3975b6f/spec/support/helpers/streamFromString.js#L8-L13 | train |
fullstackers/bus.io | demo/chat/public/js/chat.js | share | function share() {
var status = $.trim($('#status').val()),
target = $('#target').val();
// Nothing to share
if(status === '') {
return;
}
// When messaging an individual user, update the target to be the user
// that is being messaged.
if(target === 'user') {
target = $('#target_user').val();
}
// Dispatch the message to the server.
socket.emit('post', status, target);
// Clear the status input for the next message.
$('#status').val('');
} | javascript | function share() {
var status = $.trim($('#status').val()),
target = $('#target').val();
// Nothing to share
if(status === '') {
return;
}
// When messaging an individual user, update the target to be the user
// that is being messaged.
if(target === 'user') {
target = $('#target_user').val();
}
// Dispatch the message to the server.
socket.emit('post', status, target);
// Clear the status input for the next message.
$('#status').val('');
} | [
"function",
"share",
"(",
")",
"{",
"var",
"status",
"=",
"$",
".",
"trim",
"(",
"$",
"(",
"'#status'",
")",
".",
"val",
"(",
")",
")",
",",
"target",
"=",
"$",
"(",
"'#target'",
")",
".",
"val",
"(",
")",
";",
"if",
"(",
"status",
"===",
"''",
")",
"{",
"return",
";",
"}",
"if",
"(",
"target",
"===",
"'user'",
")",
"{",
"target",
"=",
"$",
"(",
"'#target_user'",
")",
".",
"val",
"(",
")",
";",
"}",
"socket",
".",
"emit",
"(",
"'post'",
",",
"status",
",",
"target",
")",
";",
"$",
"(",
"'#status'",
")",
".",
"val",
"(",
"''",
")",
";",
"}"
] | Call this method when you are ready to send a message to the server. | [
"Call",
"this",
"method",
"when",
"you",
"are",
"ready",
"to",
"send",
"a",
"message",
"to",
"the",
"server",
"."
] | 8bc8f38938925a31f67a9b03cf24f8fdb12f3353 | https://github.com/fullstackers/bus.io/blob/8bc8f38938925a31f67a9b03cf24f8fdb12f3353/demo/chat/public/js/chat.js#L6-L26 | train |
jhermsmeier/node-flightstats | lib/flightstats.js | function( options, callback ) {
if( typeof options === 'function' ) {
callback = options
options = null
}
options = options != null ? options : {}
var self = this
var baseUrl = 'airlines/rest/v1/json'
var isCode = options.fs || options.iata || options.icao
var supportsDate = !options.all || isCode
if( !options.all && !isCode ) {
baseUrl += '/active'
} else if( !isCode ) {
baseUrl += '/all'
}
if( options.fs ) {
baseUrl += '/fs/' + options.fs
} else if( options.iata ) {
baseUrl += '/iata/' + options.iata
} else if( options.icao ) {
baseUrl += '/icao/' + options.icao
}
if( options.date && supportsDate ) {
var year = options.date.getFullYear()
var month = options.date.getMonth() + 1
var day = options.date.getDate()
baseUrl += '/' + year + '/' + month + '/' + day
}
return this._clientRequest({
url: baseUrl,
extendedOptions: [
'includeNewFields'
],
}, function( error, data ) {
if( error != null )
return callback.call( self, error )
var airlines = [].concat( data.airlines || data.airline || [] )
// Trim excessive whitespace in airline names
airlines.forEach( function( airline ) {
airline.name = airline.name.replace( /^\s|\s$/g, '' )
})
// Expand the airline category to a detailed object
if( options.expandCategory ) {
airlines.forEach( function( airline ) {
var info = FlightStats.AirlineCategory[ airline.category ]
airline.category = {
code: ( info && info.code ) || airline.category,
scheduled: info && info.scheduled,
passenger: info && info.passenger,
cargo: info && info.cargo,
}
})
}
callback.call( self, error, airlines )
})
} | javascript | function( options, callback ) {
if( typeof options === 'function' ) {
callback = options
options = null
}
options = options != null ? options : {}
var self = this
var baseUrl = 'airlines/rest/v1/json'
var isCode = options.fs || options.iata || options.icao
var supportsDate = !options.all || isCode
if( !options.all && !isCode ) {
baseUrl += '/active'
} else if( !isCode ) {
baseUrl += '/all'
}
if( options.fs ) {
baseUrl += '/fs/' + options.fs
} else if( options.iata ) {
baseUrl += '/iata/' + options.iata
} else if( options.icao ) {
baseUrl += '/icao/' + options.icao
}
if( options.date && supportsDate ) {
var year = options.date.getFullYear()
var month = options.date.getMonth() + 1
var day = options.date.getDate()
baseUrl += '/' + year + '/' + month + '/' + day
}
return this._clientRequest({
url: baseUrl,
extendedOptions: [
'includeNewFields'
],
}, function( error, data ) {
if( error != null )
return callback.call( self, error )
var airlines = [].concat( data.airlines || data.airline || [] )
// Trim excessive whitespace in airline names
airlines.forEach( function( airline ) {
airline.name = airline.name.replace( /^\s|\s$/g, '' )
})
// Expand the airline category to a detailed object
if( options.expandCategory ) {
airlines.forEach( function( airline ) {
var info = FlightStats.AirlineCategory[ airline.category ]
airline.category = {
code: ( info && info.code ) || airline.category,
scheduled: info && info.scheduled,
passenger: info && info.passenger,
cargo: info && info.cargo,
}
})
}
callback.call( self, error, airlines )
})
} | [
"function",
"(",
"options",
",",
"callback",
")",
"{",
"if",
"(",
"typeof",
"options",
"===",
"'function'",
")",
"{",
"callback",
"=",
"options",
"options",
"=",
"null",
"}",
"options",
"=",
"options",
"!=",
"null",
"?",
"options",
":",
"{",
"}",
"var",
"self",
"=",
"this",
"var",
"baseUrl",
"=",
"'airlines/rest/v1/json'",
"var",
"isCode",
"=",
"options",
".",
"fs",
"||",
"options",
".",
"iata",
"||",
"options",
".",
"icao",
"var",
"supportsDate",
"=",
"!",
"options",
".",
"all",
"||",
"isCode",
"if",
"(",
"!",
"options",
".",
"all",
"&&",
"!",
"isCode",
")",
"{",
"baseUrl",
"+=",
"'/active'",
"}",
"else",
"if",
"(",
"!",
"isCode",
")",
"{",
"baseUrl",
"+=",
"'/all'",
"}",
"if",
"(",
"options",
".",
"fs",
")",
"{",
"baseUrl",
"+=",
"'/fs/'",
"+",
"options",
".",
"fs",
"}",
"else",
"if",
"(",
"options",
".",
"iata",
")",
"{",
"baseUrl",
"+=",
"'/iata/'",
"+",
"options",
".",
"iata",
"}",
"else",
"if",
"(",
"options",
".",
"icao",
")",
"{",
"baseUrl",
"+=",
"'/icao/'",
"+",
"options",
".",
"icao",
"}",
"if",
"(",
"options",
".",
"date",
"&&",
"supportsDate",
")",
"{",
"var",
"year",
"=",
"options",
".",
"date",
".",
"getFullYear",
"(",
")",
"var",
"month",
"=",
"options",
".",
"date",
".",
"getMonth",
"(",
")",
"+",
"1",
"var",
"day",
"=",
"options",
".",
"date",
".",
"getDate",
"(",
")",
"baseUrl",
"+=",
"'/'",
"+",
"year",
"+",
"'/'",
"+",
"month",
"+",
"'/'",
"+",
"day",
"}",
"return",
"this",
".",
"_clientRequest",
"(",
"{",
"url",
":",
"baseUrl",
",",
"extendedOptions",
":",
"[",
"'includeNewFields'",
"]",
",",
"}",
",",
"function",
"(",
"error",
",",
"data",
")",
"{",
"if",
"(",
"error",
"!=",
"null",
")",
"return",
"callback",
".",
"call",
"(",
"self",
",",
"error",
")",
"var",
"airlines",
"=",
"[",
"]",
".",
"concat",
"(",
"data",
".",
"airlines",
"||",
"data",
".",
"airline",
"||",
"[",
"]",
")",
"airlines",
".",
"forEach",
"(",
"function",
"(",
"airline",
")",
"{",
"airline",
".",
"name",
"=",
"airline",
".",
"name",
".",
"replace",
"(",
"/",
"^\\s|\\s$",
"/",
"g",
",",
"''",
")",
"}",
")",
"if",
"(",
"options",
".",
"expandCategory",
")",
"{",
"airlines",
".",
"forEach",
"(",
"function",
"(",
"airline",
")",
"{",
"var",
"info",
"=",
"FlightStats",
".",
"AirlineCategory",
"[",
"airline",
".",
"category",
"]",
"airline",
".",
"category",
"=",
"{",
"code",
":",
"(",
"info",
"&&",
"info",
".",
"code",
")",
"||",
"airline",
".",
"category",
",",
"scheduled",
":",
"info",
"&&",
"info",
".",
"scheduled",
",",
"passenger",
":",
"info",
"&&",
"info",
".",
"passenger",
",",
"cargo",
":",
"info",
"&&",
"info",
".",
"cargo",
",",
"}",
"}",
")",
"}",
"callback",
".",
"call",
"(",
"self",
",",
"error",
",",
"airlines",
")",
"}",
")",
"}"
] | Retrieve a list of airlines
@param {Object} options
@param {Boolean} [options.all=false] optional
@param {?Date} [options.date] optional
@param {?String} [options.iata] optional
@param {?String} [options.icao] optional
@param {?String} [options.fs] optional
@param {Function} callback
@return {Request} | [
"Retrieve",
"a",
"list",
"of",
"airlines"
] | 023d46e11db4f4ba45ed414b1dc23084b1c9749d | https://github.com/jhermsmeier/node-flightstats/blob/023d46e11db4f4ba45ed414b1dc23084b1c9749d/lib/flightstats.js#L170-L245 | train |
|
jhermsmeier/node-flightstats | lib/flightstats.js | function( options, callback ) {
if( typeof options === 'function' ) {
callback = options
options = null
}
options = options != null ? options : {}
var self = this
var baseUrl = 'airports/rest/v1/json'
var isCode = options.fs || options.iata || options.icao
var isLocationCode = options.city || options.country
var isLocation = options.latitude && options.longitude && options.radius
var supportsDate = !options.all && isCode
if( !options.all && !isCode ) {
baseUrl += '/active'
} else if( !isCode && !isLocationCode && !isLocation ) {
baseUrl += '/all'
}
if( isCode || isLocationCode ) {
if( options.fs ) {
baseUrl += '/fs/' + options.fs
} else if( options.iata ) {
baseUrl += '/iata/' + options.iata
} else if( options.icao ) {
baseUrl += '/icao/' + options.icao
} else if( options.city ) {
baseUrl += '/cityCode/' + options.city
} else if( options.country ) {
baseUrl += '/countryCode/' + options.country
}
}
if( options.date && supportsDate ) {
var year = options.date.getFullYear()
var month = options.date.getMonth() + 1
var day = options.date.getDate()
baseUrl += '/' + year + '/' + month + '/' + day
}
if( isLocation ) {
baseUrl += '/' + options.longitude + '/' + options.latitude + '/' + options.radius
}
return this._clientRequest({
url: baseUrl,
extendedOptions: [
'includeNewFields'
],
}, function( error, data ) {
if( error != null )
return callback.call( self, error )
var airports = [].concat( data.airports || data.airport || [] )
.map( function( airport ) {
airport.tzOffset = airport.utcOffsetHours
airport.tzRegion = airport.timeZoneRegionName
airport.elevation = airport.elevationFeet * 0.305
airport.utcOffsetHours = undefined
delete airport.utcOffsetHours
airport.timeZoneRegionName = undefined
delete airport.timeZoneRegionName
return airport
})
callback.call( self, error, airports )
})
} | javascript | function( options, callback ) {
if( typeof options === 'function' ) {
callback = options
options = null
}
options = options != null ? options : {}
var self = this
var baseUrl = 'airports/rest/v1/json'
var isCode = options.fs || options.iata || options.icao
var isLocationCode = options.city || options.country
var isLocation = options.latitude && options.longitude && options.radius
var supportsDate = !options.all && isCode
if( !options.all && !isCode ) {
baseUrl += '/active'
} else if( !isCode && !isLocationCode && !isLocation ) {
baseUrl += '/all'
}
if( isCode || isLocationCode ) {
if( options.fs ) {
baseUrl += '/fs/' + options.fs
} else if( options.iata ) {
baseUrl += '/iata/' + options.iata
} else if( options.icao ) {
baseUrl += '/icao/' + options.icao
} else if( options.city ) {
baseUrl += '/cityCode/' + options.city
} else if( options.country ) {
baseUrl += '/countryCode/' + options.country
}
}
if( options.date && supportsDate ) {
var year = options.date.getFullYear()
var month = options.date.getMonth() + 1
var day = options.date.getDate()
baseUrl += '/' + year + '/' + month + '/' + day
}
if( isLocation ) {
baseUrl += '/' + options.longitude + '/' + options.latitude + '/' + options.radius
}
return this._clientRequest({
url: baseUrl,
extendedOptions: [
'includeNewFields'
],
}, function( error, data ) {
if( error != null )
return callback.call( self, error )
var airports = [].concat( data.airports || data.airport || [] )
.map( function( airport ) {
airport.tzOffset = airport.utcOffsetHours
airport.tzRegion = airport.timeZoneRegionName
airport.elevation = airport.elevationFeet * 0.305
airport.utcOffsetHours = undefined
delete airport.utcOffsetHours
airport.timeZoneRegionName = undefined
delete airport.timeZoneRegionName
return airport
})
callback.call( self, error, airports )
})
} | [
"function",
"(",
"options",
",",
"callback",
")",
"{",
"if",
"(",
"typeof",
"options",
"===",
"'function'",
")",
"{",
"callback",
"=",
"options",
"options",
"=",
"null",
"}",
"options",
"=",
"options",
"!=",
"null",
"?",
"options",
":",
"{",
"}",
"var",
"self",
"=",
"this",
"var",
"baseUrl",
"=",
"'airports/rest/v1/json'",
"var",
"isCode",
"=",
"options",
".",
"fs",
"||",
"options",
".",
"iata",
"||",
"options",
".",
"icao",
"var",
"isLocationCode",
"=",
"options",
".",
"city",
"||",
"options",
".",
"country",
"var",
"isLocation",
"=",
"options",
".",
"latitude",
"&&",
"options",
".",
"longitude",
"&&",
"options",
".",
"radius",
"var",
"supportsDate",
"=",
"!",
"options",
".",
"all",
"&&",
"isCode",
"if",
"(",
"!",
"options",
".",
"all",
"&&",
"!",
"isCode",
")",
"{",
"baseUrl",
"+=",
"'/active'",
"}",
"else",
"if",
"(",
"!",
"isCode",
"&&",
"!",
"isLocationCode",
"&&",
"!",
"isLocation",
")",
"{",
"baseUrl",
"+=",
"'/all'",
"}",
"if",
"(",
"isCode",
"||",
"isLocationCode",
")",
"{",
"if",
"(",
"options",
".",
"fs",
")",
"{",
"baseUrl",
"+=",
"'/fs/'",
"+",
"options",
".",
"fs",
"}",
"else",
"if",
"(",
"options",
".",
"iata",
")",
"{",
"baseUrl",
"+=",
"'/iata/'",
"+",
"options",
".",
"iata",
"}",
"else",
"if",
"(",
"options",
".",
"icao",
")",
"{",
"baseUrl",
"+=",
"'/icao/'",
"+",
"options",
".",
"icao",
"}",
"else",
"if",
"(",
"options",
".",
"city",
")",
"{",
"baseUrl",
"+=",
"'/cityCode/'",
"+",
"options",
".",
"city",
"}",
"else",
"if",
"(",
"options",
".",
"country",
")",
"{",
"baseUrl",
"+=",
"'/countryCode/'",
"+",
"options",
".",
"country",
"}",
"}",
"if",
"(",
"options",
".",
"date",
"&&",
"supportsDate",
")",
"{",
"var",
"year",
"=",
"options",
".",
"date",
".",
"getFullYear",
"(",
")",
"var",
"month",
"=",
"options",
".",
"date",
".",
"getMonth",
"(",
")",
"+",
"1",
"var",
"day",
"=",
"options",
".",
"date",
".",
"getDate",
"(",
")",
"baseUrl",
"+=",
"'/'",
"+",
"year",
"+",
"'/'",
"+",
"month",
"+",
"'/'",
"+",
"day",
"}",
"if",
"(",
"isLocation",
")",
"{",
"baseUrl",
"+=",
"'/'",
"+",
"options",
".",
"longitude",
"+",
"'/'",
"+",
"options",
".",
"latitude",
"+",
"'/'",
"+",
"options",
".",
"radius",
"}",
"return",
"this",
".",
"_clientRequest",
"(",
"{",
"url",
":",
"baseUrl",
",",
"extendedOptions",
":",
"[",
"'includeNewFields'",
"]",
",",
"}",
",",
"function",
"(",
"error",
",",
"data",
")",
"{",
"if",
"(",
"error",
"!=",
"null",
")",
"return",
"callback",
".",
"call",
"(",
"self",
",",
"error",
")",
"var",
"airports",
"=",
"[",
"]",
".",
"concat",
"(",
"data",
".",
"airports",
"||",
"data",
".",
"airport",
"||",
"[",
"]",
")",
".",
"map",
"(",
"function",
"(",
"airport",
")",
"{",
"airport",
".",
"tzOffset",
"=",
"airport",
".",
"utcOffsetHours",
"airport",
".",
"tzRegion",
"=",
"airport",
".",
"timeZoneRegionName",
"airport",
".",
"elevation",
"=",
"airport",
".",
"elevationFeet",
"*",
"0.305",
"airport",
".",
"utcOffsetHours",
"=",
"undefined",
"delete",
"airport",
".",
"utcOffsetHours",
"airport",
".",
"timeZoneRegionName",
"=",
"undefined",
"delete",
"airport",
".",
"timeZoneRegionName",
"return",
"airport",
"}",
")",
"callback",
".",
"call",
"(",
"self",
",",
"error",
",",
"airports",
")",
"}",
")",
"}"
] | Retrieve a list of airports
@param {Object} options
@param {?Boolean} [options.all=false] optional
@param {?Date} [options.date] optional
@param {?String} [options.iata] optional
@param {?String} [options.icao] optional
@param {?String} [options.fs] optional
@param {?String} [options.city] optional
@param {?String} [options.country] optional
@param {?Number} [options.latitude] optional
@param {?Number} [options.longitude] optional
@param {?Number} [options.radius] optional
@param {Function} callback
@return {Request} | [
"Retrieve",
"a",
"list",
"of",
"airports"
] | 023d46e11db4f4ba45ed414b1dc23084b1c9749d | https://github.com/jhermsmeier/node-flightstats/blob/023d46e11db4f4ba45ed414b1dc23084b1c9749d/lib/flightstats.js#L263-L344 | train |
|
jhermsmeier/node-flightstats | lib/flightstats.js | function( options, callback ) {
debug( 'lookup' )
var now = Date.now()
var target = options.date.getTime()
// NOTE: `.status()` is only available within a window of -7 to +3 days
var timeMin = now - ( 8 * 24 ) * 60 * 60 * 1000
var timeMax = now + ( 3 * 24 ) * 60 * 60 * 1000
var method = target < timeMin || target > timeMax ?
'schedule' : 'status'
debug( 'lookup:time:target ', target )
debug( 'lookup:time:window', timeMin, timeMax )
debug( 'lookup:type', method )
return this[ method ]( options, callback )
} | javascript | function( options, callback ) {
debug( 'lookup' )
var now = Date.now()
var target = options.date.getTime()
// NOTE: `.status()` is only available within a window of -7 to +3 days
var timeMin = now - ( 8 * 24 ) * 60 * 60 * 1000
var timeMax = now + ( 3 * 24 ) * 60 * 60 * 1000
var method = target < timeMin || target > timeMax ?
'schedule' : 'status'
debug( 'lookup:time:target ', target )
debug( 'lookup:time:window', timeMin, timeMax )
debug( 'lookup:type', method )
return this[ method ]( options, callback )
} | [
"function",
"(",
"options",
",",
"callback",
")",
"{",
"debug",
"(",
"'lookup'",
")",
"var",
"now",
"=",
"Date",
".",
"now",
"(",
")",
"var",
"target",
"=",
"options",
".",
"date",
".",
"getTime",
"(",
")",
"var",
"timeMin",
"=",
"now",
"-",
"(",
"8",
"*",
"24",
")",
"*",
"60",
"*",
"60",
"*",
"1000",
"var",
"timeMax",
"=",
"now",
"+",
"(",
"3",
"*",
"24",
")",
"*",
"60",
"*",
"60",
"*",
"1000",
"var",
"method",
"=",
"target",
"<",
"timeMin",
"||",
"target",
">",
"timeMax",
"?",
"'schedule'",
":",
"'status'",
"debug",
"(",
"'lookup:time:target '",
",",
"target",
")",
"debug",
"(",
"'lookup:time:window'",
",",
"timeMin",
",",
"timeMax",
")",
"debug",
"(",
"'lookup:type'",
",",
"method",
")",
"return",
"this",
"[",
"method",
"]",
"(",
"options",
",",
"callback",
")",
"}"
] | Look up a flight
@param {Object} options
@param {Date} options.date
@param {String} options.airlineCode
@param {String} options.flightNumber
@param {?String} [options.airport] optional
@param {?String} [options.direction='arr'] optional
@param {?Array<String>} [options.extendedOptions] optional
@param {Function} callback
@return {Request} | [
"Look",
"up",
"a",
"flight"
] | 023d46e11db4f4ba45ed414b1dc23084b1c9749d | https://github.com/jhermsmeier/node-flightstats/blob/023d46e11db4f4ba45ed414b1dc23084b1c9749d/lib/flightstats.js#L358-L378 | train |
|
jhermsmeier/node-flightstats | lib/flightstats.js | function( options, callback ) {
debug( 'schedule', options )
var self = this
var protocol = options.protocol || 'rest'
var format = options.format || 'json'
var baseUrl = 'schedules/' + protocol + '/v1/' + format + '/flight'
var carrier = options.airlineCode
var flightNumber = options.flightNumber
var year = options.date.getFullYear()
var month = options.date.getMonth() + 1
var day = options.date.getDate()
var direction = /^dep/i.test( options.direction ) ?
'departing' : 'arriving'
var extensions = [
'includeDirects',
'includeCargo',
'useInlinedReferences'
]
if( Array.isArray( options.extendedOptions ) ) {
extensions = extensions.concat( options.extendedOptions )
}
return this._clientRequest({
url: baseUrl + '/' + carrier + '/' + flightNumber + '/' + direction + '/' + year + '/' + month + '/' + day,
extendedOptions: extensions,
}, function( error, data ) {
if( data != null ) {
data = FlightStats.formatSchedule( data )
if( options.airport && data.flights ) {
data.flights = FlightStats.filterByAirport( data.flights, options.airport, options.direction )
}
}
callback.call( self, error, data )
})
} | javascript | function( options, callback ) {
debug( 'schedule', options )
var self = this
var protocol = options.protocol || 'rest'
var format = options.format || 'json'
var baseUrl = 'schedules/' + protocol + '/v1/' + format + '/flight'
var carrier = options.airlineCode
var flightNumber = options.flightNumber
var year = options.date.getFullYear()
var month = options.date.getMonth() + 1
var day = options.date.getDate()
var direction = /^dep/i.test( options.direction ) ?
'departing' : 'arriving'
var extensions = [
'includeDirects',
'includeCargo',
'useInlinedReferences'
]
if( Array.isArray( options.extendedOptions ) ) {
extensions = extensions.concat( options.extendedOptions )
}
return this._clientRequest({
url: baseUrl + '/' + carrier + '/' + flightNumber + '/' + direction + '/' + year + '/' + month + '/' + day,
extendedOptions: extensions,
}, function( error, data ) {
if( data != null ) {
data = FlightStats.formatSchedule( data )
if( options.airport && data.flights ) {
data.flights = FlightStats.filterByAirport( data.flights, options.airport, options.direction )
}
}
callback.call( self, error, data )
})
} | [
"function",
"(",
"options",
",",
"callback",
")",
"{",
"debug",
"(",
"'schedule'",
",",
"options",
")",
"var",
"self",
"=",
"this",
"var",
"protocol",
"=",
"options",
".",
"protocol",
"||",
"'rest'",
"var",
"format",
"=",
"options",
".",
"format",
"||",
"'json'",
"var",
"baseUrl",
"=",
"'schedules/'",
"+",
"protocol",
"+",
"'/v1/'",
"+",
"format",
"+",
"'/flight'",
"var",
"carrier",
"=",
"options",
".",
"airlineCode",
"var",
"flightNumber",
"=",
"options",
".",
"flightNumber",
"var",
"year",
"=",
"options",
".",
"date",
".",
"getFullYear",
"(",
")",
"var",
"month",
"=",
"options",
".",
"date",
".",
"getMonth",
"(",
")",
"+",
"1",
"var",
"day",
"=",
"options",
".",
"date",
".",
"getDate",
"(",
")",
"var",
"direction",
"=",
"/",
"^dep",
"/",
"i",
".",
"test",
"(",
"options",
".",
"direction",
")",
"?",
"'departing'",
":",
"'arriving'",
"var",
"extensions",
"=",
"[",
"'includeDirects'",
",",
"'includeCargo'",
",",
"'useInlinedReferences'",
"]",
"if",
"(",
"Array",
".",
"isArray",
"(",
"options",
".",
"extendedOptions",
")",
")",
"{",
"extensions",
"=",
"extensions",
".",
"concat",
"(",
"options",
".",
"extendedOptions",
")",
"}",
"return",
"this",
".",
"_clientRequest",
"(",
"{",
"url",
":",
"baseUrl",
"+",
"'/'",
"+",
"carrier",
"+",
"'/'",
"+",
"flightNumber",
"+",
"'/'",
"+",
"direction",
"+",
"'/'",
"+",
"year",
"+",
"'/'",
"+",
"month",
"+",
"'/'",
"+",
"day",
",",
"extendedOptions",
":",
"extensions",
",",
"}",
",",
"function",
"(",
"error",
",",
"data",
")",
"{",
"if",
"(",
"data",
"!=",
"null",
")",
"{",
"data",
"=",
"FlightStats",
".",
"formatSchedule",
"(",
"data",
")",
"if",
"(",
"options",
".",
"airport",
"&&",
"data",
".",
"flights",
")",
"{",
"data",
".",
"flights",
"=",
"FlightStats",
".",
"filterByAirport",
"(",
"data",
".",
"flights",
",",
"options",
".",
"airport",
",",
"options",
".",
"direction",
")",
"}",
"}",
"callback",
".",
"call",
"(",
"self",
",",
"error",
",",
"data",
")",
"}",
")",
"}"
] | Get a flight's schedule status information
@param {Object} options - see [.lookup()]{@link FlightStats#lookup}
@param {Function} callback
@return {Request} | [
"Get",
"a",
"flight",
"s",
"schedule",
"status",
"information"
] | 023d46e11db4f4ba45ed414b1dc23084b1c9749d | https://github.com/jhermsmeier/node-flightstats/blob/023d46e11db4f4ba45ed414b1dc23084b1c9749d/lib/flightstats.js#L440-L484 | train |
|
jhermsmeier/node-flightstats | lib/flightstats.js | function( options, callback ) {
options = Object.assign({ type: 'firstflightin', verb: '/arriving_before/' }, options )
return this.connections( options, callback )
} | javascript | function( options, callback ) {
options = Object.assign({ type: 'firstflightin', verb: '/arriving_before/' }, options )
return this.connections( options, callback )
} | [
"function",
"(",
"options",
",",
"callback",
")",
"{",
"options",
"=",
"Object",
".",
"assign",
"(",
"{",
"type",
":",
"'firstflightin'",
",",
"verb",
":",
"'/arriving_before/'",
"}",
",",
"options",
")",
"return",
"this",
".",
"connections",
"(",
"options",
",",
"callback",
")",
"}"
] | Get the first inbound flight between two airports
@param {Object} options - see [.connections()]{@link FlightStats#connections}
@param {Function} callback
@return {Request} | [
"Get",
"the",
"first",
"inbound",
"flight",
"between",
"two",
"airports"
] | 023d46e11db4f4ba45ed414b1dc23084b1c9749d | https://github.com/jhermsmeier/node-flightstats/blob/023d46e11db4f4ba45ed414b1dc23084b1c9749d/lib/flightstats.js#L492-L495 | train |
|
jhermsmeier/node-flightstats | lib/flightstats.js | function( options, callback ) {
var self = this
var year = options.date.getFullYear()
var month = options.date.getMonth() + 1
var day = options.date.getDate()
var hour = options.date.getHours()
var minute = options.date.getMinutes()
var url = '/connections/rest/v2/json/' + options.type + '/' + options.departureAirport + '/to/' + options.arrivalAirport +
options.verb + year + '/' + month + '/' + day + '/' + hour + '/' + minute
var extensions = []
if( Array.isArray( options.extendedOptions ) ) {
extensions = extensions.concat( options.extendedOptions )
}
var query = {
numHours: options.numHours,
maxResults: options.maxResults,
maxConnections: options.maxConnections,
minimumConnectTime: options.minimumConnectTime,
payloadType: options.payloadType,
includeAirlines: options.includeAirlines,
excludeAirlines: options.excludeAirlines,
includeAirports: options.includeAirports,
excludeAirports: options.excludeAirports,
includeSurface: options.includeSurface,
includeCodeshares: options.includeCodeshares,
includeMultipleCarriers: options.includeMultipleCarriers,
}
Object.keys( query ).forEach( function( key ) {
query[key] = query[key] != null ?
query[key] : undefined
})
return this._clientRequest({
url: url,
qs: query,
extendedOptions: extensions,
}, function( error, data ) {
callback.call( self, error, data )
})
} | javascript | function( options, callback ) {
var self = this
var year = options.date.getFullYear()
var month = options.date.getMonth() + 1
var day = options.date.getDate()
var hour = options.date.getHours()
var minute = options.date.getMinutes()
var url = '/connections/rest/v2/json/' + options.type + '/' + options.departureAirport + '/to/' + options.arrivalAirport +
options.verb + year + '/' + month + '/' + day + '/' + hour + '/' + minute
var extensions = []
if( Array.isArray( options.extendedOptions ) ) {
extensions = extensions.concat( options.extendedOptions )
}
var query = {
numHours: options.numHours,
maxResults: options.maxResults,
maxConnections: options.maxConnections,
minimumConnectTime: options.minimumConnectTime,
payloadType: options.payloadType,
includeAirlines: options.includeAirlines,
excludeAirlines: options.excludeAirlines,
includeAirports: options.includeAirports,
excludeAirports: options.excludeAirports,
includeSurface: options.includeSurface,
includeCodeshares: options.includeCodeshares,
includeMultipleCarriers: options.includeMultipleCarriers,
}
Object.keys( query ).forEach( function( key ) {
query[key] = query[key] != null ?
query[key] : undefined
})
return this._clientRequest({
url: url,
qs: query,
extendedOptions: extensions,
}, function( error, data ) {
callback.call( self, error, data )
})
} | [
"function",
"(",
"options",
",",
"callback",
")",
"{",
"var",
"self",
"=",
"this",
"var",
"year",
"=",
"options",
".",
"date",
".",
"getFullYear",
"(",
")",
"var",
"month",
"=",
"options",
".",
"date",
".",
"getMonth",
"(",
")",
"+",
"1",
"var",
"day",
"=",
"options",
".",
"date",
".",
"getDate",
"(",
")",
"var",
"hour",
"=",
"options",
".",
"date",
".",
"getHours",
"(",
")",
"var",
"minute",
"=",
"options",
".",
"date",
".",
"getMinutes",
"(",
")",
"var",
"url",
"=",
"'/connections/rest/v2/json/'",
"+",
"options",
".",
"type",
"+",
"'/'",
"+",
"options",
".",
"departureAirport",
"+",
"'/to/'",
"+",
"options",
".",
"arrivalAirport",
"+",
"options",
".",
"verb",
"+",
"year",
"+",
"'/'",
"+",
"month",
"+",
"'/'",
"+",
"day",
"+",
"'/'",
"+",
"hour",
"+",
"'/'",
"+",
"minute",
"var",
"extensions",
"=",
"[",
"]",
"if",
"(",
"Array",
".",
"isArray",
"(",
"options",
".",
"extendedOptions",
")",
")",
"{",
"extensions",
"=",
"extensions",
".",
"concat",
"(",
"options",
".",
"extendedOptions",
")",
"}",
"var",
"query",
"=",
"{",
"numHours",
":",
"options",
".",
"numHours",
",",
"maxResults",
":",
"options",
".",
"maxResults",
",",
"maxConnections",
":",
"options",
".",
"maxConnections",
",",
"minimumConnectTime",
":",
"options",
".",
"minimumConnectTime",
",",
"payloadType",
":",
"options",
".",
"payloadType",
",",
"includeAirlines",
":",
"options",
".",
"includeAirlines",
",",
"excludeAirlines",
":",
"options",
".",
"excludeAirlines",
",",
"includeAirports",
":",
"options",
".",
"includeAirports",
",",
"excludeAirports",
":",
"options",
".",
"excludeAirports",
",",
"includeSurface",
":",
"options",
".",
"includeSurface",
",",
"includeCodeshares",
":",
"options",
".",
"includeCodeshares",
",",
"includeMultipleCarriers",
":",
"options",
".",
"includeMultipleCarriers",
",",
"}",
"Object",
".",
"keys",
"(",
"query",
")",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"query",
"[",
"key",
"]",
"=",
"query",
"[",
"key",
"]",
"!=",
"null",
"?",
"query",
"[",
"key",
"]",
":",
"undefined",
"}",
")",
"return",
"this",
".",
"_clientRequest",
"(",
"{",
"url",
":",
"url",
",",
"qs",
":",
"query",
",",
"extendedOptions",
":",
"extensions",
",",
"}",
",",
"function",
"(",
"error",
",",
"data",
")",
"{",
"callback",
".",
"call",
"(",
"self",
",",
"error",
",",
"data",
")",
"}",
")",
"}"
] | Get connecting flights between two airports
@internal used by {first,last}Flight{In,Out} methods
@param {Object} options
@param {?String} [options.type] optional, only used by `.connections()`
@param {String} options.departureAirport
@param {String} options.arrivalAirport
@param {Date} options.date
@param {?Number} [options.numHours=6] optional
@param {?Number} [options.maxResults=25] optional
@param {?Number} [options.maxConnections=2] optional
@param {?Number} [options.minimumConnectTime] optional
@param {?String} [options.payloadType='passenger'] optional
@param {?Array<String>} [options.includeAirlines] optional
@param {?Array<String>} [options.excludeAirlines] optional
@param {?Array<String>} [options.includeAirports] optional
@param {?Array<String>} [options.excludeAirports] optional
@param {?Boolean} [options.includeSurface=false] optional
@param {?Boolean} [options.includeCodeshares=true] optional
@param {?Boolean} [options.includeMultipleCarriers=true] optional
@param {Array<String>} [options.extendedOptions]
@param {Function} callback
@return {Request} | [
"Get",
"connecting",
"flights",
"between",
"two",
"airports"
] | 023d46e11db4f4ba45ed414b1dc23084b1c9749d | https://github.com/jhermsmeier/node-flightstats/blob/023d46e11db4f4ba45ed414b1dc23084b1c9749d/lib/flightstats.js#L554-L601 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.