id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
list | docstring
stringlengths 4
11.8k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
36,600 |
HumanBrainProject/jsdoc-sphinx
|
template/view-models/home.js
|
home
|
function home(context, cb) {
var viewModel = _.extend(
{
package: helper.find(context.data, {kind: 'package'})[0]
}, util.docletChildren(context, null, util.mainDocletKinds),
util.docletChildren(context, null, util.subDocletKinds),
util.rstMixin,
_.pick(context, ['readme'])
);
logger.debug('home namespaces', viewModel.namespaces);
util.view('home.rst', viewModel, cb);
}
|
javascript
|
function home(context, cb) {
var viewModel = _.extend(
{
package: helper.find(context.data, {kind: 'package'})[0]
}, util.docletChildren(context, null, util.mainDocletKinds),
util.docletChildren(context, null, util.subDocletKinds),
util.rstMixin,
_.pick(context, ['readme'])
);
logger.debug('home namespaces', viewModel.namespaces);
util.view('home.rst', viewModel, cb);
}
|
[
"function",
"home",
"(",
"context",
",",
"cb",
")",
"{",
"var",
"viewModel",
"=",
"_",
".",
"extend",
"(",
"{",
"package",
":",
"helper",
".",
"find",
"(",
"context",
".",
"data",
",",
"{",
"kind",
":",
"'package'",
"}",
")",
"[",
"0",
"]",
"}",
",",
"util",
".",
"docletChildren",
"(",
"context",
",",
"null",
",",
"util",
".",
"mainDocletKinds",
")",
",",
"util",
".",
"docletChildren",
"(",
"context",
",",
"null",
",",
"util",
".",
"subDocletKinds",
")",
",",
"util",
".",
"rstMixin",
",",
"_",
".",
"pick",
"(",
"context",
",",
"[",
"'readme'",
"]",
")",
")",
";",
"logger",
".",
"debug",
"(",
"'home namespaces'",
",",
"viewModel",
".",
"namespaces",
")",
";",
"util",
".",
"view",
"(",
"'home.rst'",
",",
"viewModel",
",",
"cb",
")",
";",
"}"
] |
The Mustache template to render the first page.
@param {object} context the current context
@param {Function} cb called after the generation has been done
|
[
"The",
"Mustache",
"template",
"to",
"render",
"the",
"first",
"page",
"."
] |
9d7c1d318ce535640588e7308917729c3849bc83
|
https://github.com/HumanBrainProject/jsdoc-sphinx/blob/9d7c1d318ce535640588e7308917729c3849bc83/template/view-models/home.js#L13-L26
|
36,601 |
vanwagonet/modules
|
lib/modules.js
|
resolve
|
function resolve(parent, id) {
if (/^\.\.?\//.test(id) && parent) { // is a relative id
id = parent.replace(/[^\/]+$/, id); // prepend parent's dirname
}
var terms = [];
id.split('/').forEach(function(term) {
if ('..' === term) { terms.pop(); } // remove previous, don't add ..
else if ('.' !== term) { terms.push(term); } // add term
// else if ('.' === term) // ignore .
});
return terms.join('/');
}
|
javascript
|
function resolve(parent, id) {
if (/^\.\.?\//.test(id) && parent) { // is a relative id
id = parent.replace(/[^\/]+$/, id); // prepend parent's dirname
}
var terms = [];
id.split('/').forEach(function(term) {
if ('..' === term) { terms.pop(); } // remove previous, don't add ..
else if ('.' !== term) { terms.push(term); } // add term
// else if ('.' === term) // ignore .
});
return terms.join('/');
}
|
[
"function",
"resolve",
"(",
"parent",
",",
"id",
")",
"{",
"if",
"(",
"/",
"^\\.\\.?\\/",
"/",
".",
"test",
"(",
"id",
")",
"&&",
"parent",
")",
"{",
"// is a relative id",
"id",
"=",
"parent",
".",
"replace",
"(",
"/",
"[^\\/]+$",
"/",
",",
"id",
")",
";",
"// prepend parent's dirname",
"}",
"var",
"terms",
"=",
"[",
"]",
";",
"id",
".",
"split",
"(",
"'/'",
")",
".",
"forEach",
"(",
"function",
"(",
"term",
")",
"{",
"if",
"(",
"'..'",
"===",
"term",
")",
"{",
"terms",
".",
"pop",
"(",
")",
";",
"}",
"// remove previous, don't add ..",
"else",
"if",
"(",
"'.'",
"!==",
"term",
")",
"{",
"terms",
".",
"push",
"(",
"term",
")",
";",
"}",
"// add term",
"// else if ('.' === term) // ignore .",
"}",
")",
";",
"return",
"terms",
".",
"join",
"(",
"'/'",
")",
";",
"}"
] |
Turn a relative id to absolute given a parent id
|
[
"Turn",
"a",
"relative",
"id",
"to",
"absolute",
"given",
"a",
"parent",
"id"
] |
eb2a0c9c54040937f7e361783cbaa0121713498c
|
https://github.com/vanwagonet/modules/blob/eb2a0c9c54040937f7e361783cbaa0121713498c/lib/modules.js#L22-L33
|
36,602 |
vanwagonet/modules
|
lib/modules.js
|
translate
|
function translate(id, filename, buffer, options, next) {
var ext = (filename.match(extexp) || [])[1] || '',
encoding = options.encoding || exports.defaults.encoding,
trans = options.translate, js, nowrap;
// make a list of what not to wrap
nowrap = options.nowrap || exports.defaults.nowrap;
nowrap = [ 'define', 'define.min', 'define.shim' ].concat(nowrap);
// should this code get wrapped with a define?
nowrap = nowrap.some(function(no) {
return no.test ? no.test(id) : (no === id);
});
// convert commonjs to amd
function wrap(err, js) {
if (err) { return next(err); }
var deps = exports.dependencies(id, js), params = [], undef = '';
// make sure require, exports, and module are properly passed into the factory
if (/\brequire\b/.test(js)) { params.push('require'); }
if (/\bexports\b/.test(js)) { params.push('exports'); }
if (/\bmodule\b/.test(js)) { params.push('module'); }
// make sure code follows the `exports` path instead of `define` path once wrapped
if (/\bdefine\.amd\b/.test(js)) { undef = 'var define;'; }
if (deps.length) {
deps = ',' + JSON.stringify(params.concat(deps));
} else if (params.length) {
params = [ 'require', 'exports', 'module' ];
}
js = 'define(' + JSON.stringify(id) + deps + ',function(' + params + ')' +
'{' + js + '\n' + undef + '}' + // rely on hoisting for define
');\n';
next(null, js);
}
// find the translate function
trans = trans && (trans[filename] || trans[id] || trans[ext]);
if (trans) { // user configured translation
return trans(
{ id:id, filename:filename, buffer:buffer },
options, (nowrap ? next : wrap)
);
}
js = buffer.toString(encoding);
// handle javascript files
if ('js' === ext) {
return (nowrap ? next : wrap)(null, js);
}
// handle non-javascript files
if ('json' !== ext) { js = JSON.stringify(js); } // export file as json string
if (nowrap) { return next(null, 'return ' + js); }
return next(null, 'define(' + JSON.stringify(id) + ',' + js + ');\n');
}
|
javascript
|
function translate(id, filename, buffer, options, next) {
var ext = (filename.match(extexp) || [])[1] || '',
encoding = options.encoding || exports.defaults.encoding,
trans = options.translate, js, nowrap;
// make a list of what not to wrap
nowrap = options.nowrap || exports.defaults.nowrap;
nowrap = [ 'define', 'define.min', 'define.shim' ].concat(nowrap);
// should this code get wrapped with a define?
nowrap = nowrap.some(function(no) {
return no.test ? no.test(id) : (no === id);
});
// convert commonjs to amd
function wrap(err, js) {
if (err) { return next(err); }
var deps = exports.dependencies(id, js), params = [], undef = '';
// make sure require, exports, and module are properly passed into the factory
if (/\brequire\b/.test(js)) { params.push('require'); }
if (/\bexports\b/.test(js)) { params.push('exports'); }
if (/\bmodule\b/.test(js)) { params.push('module'); }
// make sure code follows the `exports` path instead of `define` path once wrapped
if (/\bdefine\.amd\b/.test(js)) { undef = 'var define;'; }
if (deps.length) {
deps = ',' + JSON.stringify(params.concat(deps));
} else if (params.length) {
params = [ 'require', 'exports', 'module' ];
}
js = 'define(' + JSON.stringify(id) + deps + ',function(' + params + ')' +
'{' + js + '\n' + undef + '}' + // rely on hoisting for define
');\n';
next(null, js);
}
// find the translate function
trans = trans && (trans[filename] || trans[id] || trans[ext]);
if (trans) { // user configured translation
return trans(
{ id:id, filename:filename, buffer:buffer },
options, (nowrap ? next : wrap)
);
}
js = buffer.toString(encoding);
// handle javascript files
if ('js' === ext) {
return (nowrap ? next : wrap)(null, js);
}
// handle non-javascript files
if ('json' !== ext) { js = JSON.stringify(js); } // export file as json string
if (nowrap) { return next(null, 'return ' + js); }
return next(null, 'define(' + JSON.stringify(id) + ',' + js + ');\n');
}
|
[
"function",
"translate",
"(",
"id",
",",
"filename",
",",
"buffer",
",",
"options",
",",
"next",
")",
"{",
"var",
"ext",
"=",
"(",
"filename",
".",
"match",
"(",
"extexp",
")",
"||",
"[",
"]",
")",
"[",
"1",
"]",
"||",
"''",
",",
"encoding",
"=",
"options",
".",
"encoding",
"||",
"exports",
".",
"defaults",
".",
"encoding",
",",
"trans",
"=",
"options",
".",
"translate",
",",
"js",
",",
"nowrap",
";",
"// make a list of what not to wrap",
"nowrap",
"=",
"options",
".",
"nowrap",
"||",
"exports",
".",
"defaults",
".",
"nowrap",
";",
"nowrap",
"=",
"[",
"'define'",
",",
"'define.min'",
",",
"'define.shim'",
"]",
".",
"concat",
"(",
"nowrap",
")",
";",
"// should this code get wrapped with a define?",
"nowrap",
"=",
"nowrap",
".",
"some",
"(",
"function",
"(",
"no",
")",
"{",
"return",
"no",
".",
"test",
"?",
"no",
".",
"test",
"(",
"id",
")",
":",
"(",
"no",
"===",
"id",
")",
";",
"}",
")",
";",
"// convert commonjs to amd",
"function",
"wrap",
"(",
"err",
",",
"js",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"next",
"(",
"err",
")",
";",
"}",
"var",
"deps",
"=",
"exports",
".",
"dependencies",
"(",
"id",
",",
"js",
")",
",",
"params",
"=",
"[",
"]",
",",
"undef",
"=",
"''",
";",
"// make sure require, exports, and module are properly passed into the factory",
"if",
"(",
"/",
"\\brequire\\b",
"/",
".",
"test",
"(",
"js",
")",
")",
"{",
"params",
".",
"push",
"(",
"'require'",
")",
";",
"}",
"if",
"(",
"/",
"\\bexports\\b",
"/",
".",
"test",
"(",
"js",
")",
")",
"{",
"params",
".",
"push",
"(",
"'exports'",
")",
";",
"}",
"if",
"(",
"/",
"\\bmodule\\b",
"/",
".",
"test",
"(",
"js",
")",
")",
"{",
"params",
".",
"push",
"(",
"'module'",
")",
";",
"}",
"// make sure code follows the `exports` path instead of `define` path once wrapped",
"if",
"(",
"/",
"\\bdefine\\.amd\\b",
"/",
".",
"test",
"(",
"js",
")",
")",
"{",
"undef",
"=",
"'var define;'",
";",
"}",
"if",
"(",
"deps",
".",
"length",
")",
"{",
"deps",
"=",
"','",
"+",
"JSON",
".",
"stringify",
"(",
"params",
".",
"concat",
"(",
"deps",
")",
")",
";",
"}",
"else",
"if",
"(",
"params",
".",
"length",
")",
"{",
"params",
"=",
"[",
"'require'",
",",
"'exports'",
",",
"'module'",
"]",
";",
"}",
"js",
"=",
"'define('",
"+",
"JSON",
".",
"stringify",
"(",
"id",
")",
"+",
"deps",
"+",
"',function('",
"+",
"params",
"+",
"')'",
"+",
"'{'",
"+",
"js",
"+",
"'\\n'",
"+",
"undef",
"+",
"'}'",
"+",
"// rely on hoisting for define",
"');\\n'",
";",
"next",
"(",
"null",
",",
"js",
")",
";",
"}",
"// find the translate function",
"trans",
"=",
"trans",
"&&",
"(",
"trans",
"[",
"filename",
"]",
"||",
"trans",
"[",
"id",
"]",
"||",
"trans",
"[",
"ext",
"]",
")",
";",
"if",
"(",
"trans",
")",
"{",
"// user configured translation",
"return",
"trans",
"(",
"{",
"id",
":",
"id",
",",
"filename",
":",
"filename",
",",
"buffer",
":",
"buffer",
"}",
",",
"options",
",",
"(",
"nowrap",
"?",
"next",
":",
"wrap",
")",
")",
";",
"}",
"js",
"=",
"buffer",
".",
"toString",
"(",
"encoding",
")",
";",
"// handle javascript files",
"if",
"(",
"'js'",
"===",
"ext",
")",
"{",
"return",
"(",
"nowrap",
"?",
"next",
":",
"wrap",
")",
"(",
"null",
",",
"js",
")",
";",
"}",
"// handle non-javascript files",
"if",
"(",
"'json'",
"!==",
"ext",
")",
"{",
"js",
"=",
"JSON",
".",
"stringify",
"(",
"js",
")",
";",
"}",
"// export file as json string",
"if",
"(",
"nowrap",
")",
"{",
"return",
"next",
"(",
"null",
",",
"'return '",
"+",
"js",
")",
";",
"}",
"return",
"next",
"(",
"null",
",",
"'define('",
"+",
"JSON",
".",
"stringify",
"(",
"id",
")",
"+",
"','",
"+",
"js",
"+",
"');\\n'",
")",
";",
"}"
] |
Convert arbitrary file to commonjs+return exports
|
[
"Convert",
"arbitrary",
"file",
"to",
"commonjs",
"+",
"return",
"exports"
] |
eb2a0c9c54040937f7e361783cbaa0121713498c
|
https://github.com/vanwagonet/modules/blob/eb2a0c9c54040937f7e361783cbaa0121713498c/lib/modules.js#L39-L98
|
36,603 |
vanwagonet/modules
|
lib/modules.js
|
wrap
|
function wrap(err, js) {
if (err) { return next(err); }
var deps = exports.dependencies(id, js), params = [], undef = '';
// make sure require, exports, and module are properly passed into the factory
if (/\brequire\b/.test(js)) { params.push('require'); }
if (/\bexports\b/.test(js)) { params.push('exports'); }
if (/\bmodule\b/.test(js)) { params.push('module'); }
// make sure code follows the `exports` path instead of `define` path once wrapped
if (/\bdefine\.amd\b/.test(js)) { undef = 'var define;'; }
if (deps.length) {
deps = ',' + JSON.stringify(params.concat(deps));
} else if (params.length) {
params = [ 'require', 'exports', 'module' ];
}
js = 'define(' + JSON.stringify(id) + deps + ',function(' + params + ')' +
'{' + js + '\n' + undef + '}' + // rely on hoisting for define
');\n';
next(null, js);
}
|
javascript
|
function wrap(err, js) {
if (err) { return next(err); }
var deps = exports.dependencies(id, js), params = [], undef = '';
// make sure require, exports, and module are properly passed into the factory
if (/\brequire\b/.test(js)) { params.push('require'); }
if (/\bexports\b/.test(js)) { params.push('exports'); }
if (/\bmodule\b/.test(js)) { params.push('module'); }
// make sure code follows the `exports` path instead of `define` path once wrapped
if (/\bdefine\.amd\b/.test(js)) { undef = 'var define;'; }
if (deps.length) {
deps = ',' + JSON.stringify(params.concat(deps));
} else if (params.length) {
params = [ 'require', 'exports', 'module' ];
}
js = 'define(' + JSON.stringify(id) + deps + ',function(' + params + ')' +
'{' + js + '\n' + undef + '}' + // rely on hoisting for define
');\n';
next(null, js);
}
|
[
"function",
"wrap",
"(",
"err",
",",
"js",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"next",
"(",
"err",
")",
";",
"}",
"var",
"deps",
"=",
"exports",
".",
"dependencies",
"(",
"id",
",",
"js",
")",
",",
"params",
"=",
"[",
"]",
",",
"undef",
"=",
"''",
";",
"// make sure require, exports, and module are properly passed into the factory",
"if",
"(",
"/",
"\\brequire\\b",
"/",
".",
"test",
"(",
"js",
")",
")",
"{",
"params",
".",
"push",
"(",
"'require'",
")",
";",
"}",
"if",
"(",
"/",
"\\bexports\\b",
"/",
".",
"test",
"(",
"js",
")",
")",
"{",
"params",
".",
"push",
"(",
"'exports'",
")",
";",
"}",
"if",
"(",
"/",
"\\bmodule\\b",
"/",
".",
"test",
"(",
"js",
")",
")",
"{",
"params",
".",
"push",
"(",
"'module'",
")",
";",
"}",
"// make sure code follows the `exports` path instead of `define` path once wrapped",
"if",
"(",
"/",
"\\bdefine\\.amd\\b",
"/",
".",
"test",
"(",
"js",
")",
")",
"{",
"undef",
"=",
"'var define;'",
";",
"}",
"if",
"(",
"deps",
".",
"length",
")",
"{",
"deps",
"=",
"','",
"+",
"JSON",
".",
"stringify",
"(",
"params",
".",
"concat",
"(",
"deps",
")",
")",
";",
"}",
"else",
"if",
"(",
"params",
".",
"length",
")",
"{",
"params",
"=",
"[",
"'require'",
",",
"'exports'",
",",
"'module'",
"]",
";",
"}",
"js",
"=",
"'define('",
"+",
"JSON",
".",
"stringify",
"(",
"id",
")",
"+",
"deps",
"+",
"',function('",
"+",
"params",
"+",
"')'",
"+",
"'{'",
"+",
"js",
"+",
"'\\n'",
"+",
"undef",
"+",
"'}'",
"+",
"// rely on hoisting for define",
"');\\n'",
";",
"next",
"(",
"null",
",",
"js",
")",
";",
"}"
] |
convert commonjs to amd
|
[
"convert",
"commonjs",
"to",
"amd"
] |
eb2a0c9c54040937f7e361783cbaa0121713498c
|
https://github.com/vanwagonet/modules/blob/eb2a0c9c54040937f7e361783cbaa0121713498c/lib/modules.js#L53-L76
|
36,604 |
vanwagonet/modules
|
lib/modules.js
|
getFilename
|
function getFilename(id, options, next) {
var Path = require('path'),
root = options.root || exports.defaults.root,
map = options.map || {},
forbid = (options.forbid || []).map(function(forbid) {
return forbid.test ? forbid : Path.resolve(root, forbid);
}),
filename;
function test(forbid) {
return forbid.test ? forbid.test(filename) :
(filename.slice(0, forbid.length) === forbid); // filename starts with forbid
}
// mapped modules can be in forbidden places. (define and define.shim should be mapped)
map.define = map.define || Path.resolve(__dirname, 'define');
map['define.min'] = map['define.min'] || Path.resolve(__dirname, 'define.min');
map['define.shim'] = map['define.shim'] || Path.resolve(__dirname, 'define.shim');
// get a filename from the id
filename = map[id] || id; // look for the file in the id map
if ('function' === typeof filename) { filename = filename(id, options); } // if function use result
filename = Path.resolve(root, filename); // relative to root
if (!map[id]) {
// anything below options.root is forbidden
if ('..' === Path.relative(root, filename).slice(0, 2) || forbid.some(test)) {
return next(new Error('Forbidden'), '');
}
}
fs.stat(filename, function(err, stats) {
if (err) { // not found without .js, try with
return fs.exists(filename + '.js', function(exists) {
return next(null, filename + (exists ? '.js' : ''));
});
}
if (stats.isDirectory()) { // directories look for /index.js
return fs.exists(filename + '/index.js', function(exists) {
return next(null, filename + (exists ? '/index.js' : ''));
});
}
return next(null, filename);
});
}
|
javascript
|
function getFilename(id, options, next) {
var Path = require('path'),
root = options.root || exports.defaults.root,
map = options.map || {},
forbid = (options.forbid || []).map(function(forbid) {
return forbid.test ? forbid : Path.resolve(root, forbid);
}),
filename;
function test(forbid) {
return forbid.test ? forbid.test(filename) :
(filename.slice(0, forbid.length) === forbid); // filename starts with forbid
}
// mapped modules can be in forbidden places. (define and define.shim should be mapped)
map.define = map.define || Path.resolve(__dirname, 'define');
map['define.min'] = map['define.min'] || Path.resolve(__dirname, 'define.min');
map['define.shim'] = map['define.shim'] || Path.resolve(__dirname, 'define.shim');
// get a filename from the id
filename = map[id] || id; // look for the file in the id map
if ('function' === typeof filename) { filename = filename(id, options); } // if function use result
filename = Path.resolve(root, filename); // relative to root
if (!map[id]) {
// anything below options.root is forbidden
if ('..' === Path.relative(root, filename).slice(0, 2) || forbid.some(test)) {
return next(new Error('Forbidden'), '');
}
}
fs.stat(filename, function(err, stats) {
if (err) { // not found without .js, try with
return fs.exists(filename + '.js', function(exists) {
return next(null, filename + (exists ? '.js' : ''));
});
}
if (stats.isDirectory()) { // directories look for /index.js
return fs.exists(filename + '/index.js', function(exists) {
return next(null, filename + (exists ? '/index.js' : ''));
});
}
return next(null, filename);
});
}
|
[
"function",
"getFilename",
"(",
"id",
",",
"options",
",",
"next",
")",
"{",
"var",
"Path",
"=",
"require",
"(",
"'path'",
")",
",",
"root",
"=",
"options",
".",
"root",
"||",
"exports",
".",
"defaults",
".",
"root",
",",
"map",
"=",
"options",
".",
"map",
"||",
"{",
"}",
",",
"forbid",
"=",
"(",
"options",
".",
"forbid",
"||",
"[",
"]",
")",
".",
"map",
"(",
"function",
"(",
"forbid",
")",
"{",
"return",
"forbid",
".",
"test",
"?",
"forbid",
":",
"Path",
".",
"resolve",
"(",
"root",
",",
"forbid",
")",
";",
"}",
")",
",",
"filename",
";",
"function",
"test",
"(",
"forbid",
")",
"{",
"return",
"forbid",
".",
"test",
"?",
"forbid",
".",
"test",
"(",
"filename",
")",
":",
"(",
"filename",
".",
"slice",
"(",
"0",
",",
"forbid",
".",
"length",
")",
"===",
"forbid",
")",
";",
"// filename starts with forbid",
"}",
"// mapped modules can be in forbidden places. (define and define.shim should be mapped)",
"map",
".",
"define",
"=",
"map",
".",
"define",
"||",
"Path",
".",
"resolve",
"(",
"__dirname",
",",
"'define'",
")",
";",
"map",
"[",
"'define.min'",
"]",
"=",
"map",
"[",
"'define.min'",
"]",
"||",
"Path",
".",
"resolve",
"(",
"__dirname",
",",
"'define.min'",
")",
";",
"map",
"[",
"'define.shim'",
"]",
"=",
"map",
"[",
"'define.shim'",
"]",
"||",
"Path",
".",
"resolve",
"(",
"__dirname",
",",
"'define.shim'",
")",
";",
"// get a filename from the id",
"filename",
"=",
"map",
"[",
"id",
"]",
"||",
"id",
";",
"// look for the file in the id map",
"if",
"(",
"'function'",
"===",
"typeof",
"filename",
")",
"{",
"filename",
"=",
"filename",
"(",
"id",
",",
"options",
")",
";",
"}",
"// if function use result",
"filename",
"=",
"Path",
".",
"resolve",
"(",
"root",
",",
"filename",
")",
";",
"// relative to root",
"if",
"(",
"!",
"map",
"[",
"id",
"]",
")",
"{",
"// anything below options.root is forbidden",
"if",
"(",
"'..'",
"===",
"Path",
".",
"relative",
"(",
"root",
",",
"filename",
")",
".",
"slice",
"(",
"0",
",",
"2",
")",
"||",
"forbid",
".",
"some",
"(",
"test",
")",
")",
"{",
"return",
"next",
"(",
"new",
"Error",
"(",
"'Forbidden'",
")",
",",
"''",
")",
";",
"}",
"}",
"fs",
".",
"stat",
"(",
"filename",
",",
"function",
"(",
"err",
",",
"stats",
")",
"{",
"if",
"(",
"err",
")",
"{",
"// not found without .js, try with",
"return",
"fs",
".",
"exists",
"(",
"filename",
"+",
"'.js'",
",",
"function",
"(",
"exists",
")",
"{",
"return",
"next",
"(",
"null",
",",
"filename",
"+",
"(",
"exists",
"?",
"'.js'",
":",
"''",
")",
")",
";",
"}",
")",
";",
"}",
"if",
"(",
"stats",
".",
"isDirectory",
"(",
")",
")",
"{",
"// directories look for /index.js",
"return",
"fs",
".",
"exists",
"(",
"filename",
"+",
"'/index.js'",
",",
"function",
"(",
"exists",
")",
"{",
"return",
"next",
"(",
"null",
",",
"filename",
"+",
"(",
"exists",
"?",
"'/index.js'",
":",
"''",
")",
")",
";",
"}",
")",
";",
"}",
"return",
"next",
"(",
"null",
",",
"filename",
")",
";",
"}",
")",
";",
"}"
] |
convert module id to filename
|
[
"convert",
"module",
"id",
"to",
"filename"
] |
eb2a0c9c54040937f7e361783cbaa0121713498c
|
https://github.com/vanwagonet/modules/blob/eb2a0c9c54040937f7e361783cbaa0121713498c/lib/modules.js#L104-L150
|
36,605 |
vanwagonet/modules
|
lib/modules.js
|
moduleToCode
|
function moduleToCode(id, r) {
exports.module(id, options, done);
function done(err, result) {
if (err) {
next(err);
next = function(){}; // make sure you only call next(err) once
return;
}
if (result && (!modified || result.modified > modified)) {
modified = result.modified; // update latest last modified date
}
results[r] = result && result.code || '';
if (++doneCount >= ids.length) { alldone(); } // done with all of them
}
}
|
javascript
|
function moduleToCode(id, r) {
exports.module(id, options, done);
function done(err, result) {
if (err) {
next(err);
next = function(){}; // make sure you only call next(err) once
return;
}
if (result && (!modified || result.modified > modified)) {
modified = result.modified; // update latest last modified date
}
results[r] = result && result.code || '';
if (++doneCount >= ids.length) { alldone(); } // done with all of them
}
}
|
[
"function",
"moduleToCode",
"(",
"id",
",",
"r",
")",
"{",
"exports",
".",
"module",
"(",
"id",
",",
"options",
",",
"done",
")",
";",
"function",
"done",
"(",
"err",
",",
"result",
")",
"{",
"if",
"(",
"err",
")",
"{",
"next",
"(",
"err",
")",
";",
"next",
"=",
"function",
"(",
")",
"{",
"}",
";",
"// make sure you only call next(err) once",
"return",
";",
"}",
"if",
"(",
"result",
"&&",
"(",
"!",
"modified",
"||",
"result",
".",
"modified",
">",
"modified",
")",
")",
"{",
"modified",
"=",
"result",
".",
"modified",
";",
"// update latest last modified date",
"}",
"results",
"[",
"r",
"]",
"=",
"result",
"&&",
"result",
".",
"code",
"||",
"''",
";",
"if",
"(",
"++",
"doneCount",
">=",
"ids",
".",
"length",
")",
"{",
"alldone",
"(",
")",
";",
"}",
"// done with all of them",
"}",
"}"
] |
convert a module
|
[
"convert",
"a",
"module"
] |
eb2a0c9c54040937f7e361783cbaa0121713498c
|
https://github.com/vanwagonet/modules/blob/eb2a0c9c54040937f7e361783cbaa0121713498c/lib/modules.js#L264-L281
|
36,606 |
vanwagonet/modules
|
lib/modules.js
|
alldone
|
function alldone() {
// combine and compress modules
var module = {
code: results.join(''),
modified: modified
};
// no compressing? done.
if (!compress) { return next(null, module); }
compress(module, function(err, js) {
module.code = js.code || js;
next(err, err ? null : module);
});
}
|
javascript
|
function alldone() {
// combine and compress modules
var module = {
code: results.join(''),
modified: modified
};
// no compressing? done.
if (!compress) { return next(null, module); }
compress(module, function(err, js) {
module.code = js.code || js;
next(err, err ? null : module);
});
}
|
[
"function",
"alldone",
"(",
")",
"{",
"// combine and compress modules",
"var",
"module",
"=",
"{",
"code",
":",
"results",
".",
"join",
"(",
"''",
")",
",",
"modified",
":",
"modified",
"}",
";",
"// no compressing? done.",
"if",
"(",
"!",
"compress",
")",
"{",
"return",
"next",
"(",
"null",
",",
"module",
")",
";",
"}",
"compress",
"(",
"module",
",",
"function",
"(",
"err",
",",
"js",
")",
"{",
"module",
".",
"code",
"=",
"js",
".",
"code",
"||",
"js",
";",
"next",
"(",
"err",
",",
"err",
"?",
"null",
":",
"module",
")",
";",
"}",
")",
";",
"}"
] |
put it all together
|
[
"put",
"it",
"all",
"together"
] |
eb2a0c9c54040937f7e361783cbaa0121713498c
|
https://github.com/vanwagonet/modules/blob/eb2a0c9c54040937f7e361783cbaa0121713498c/lib/modules.js#L284-L298
|
36,607 |
AdminJuwel191/node-mvc
|
framework/core/logger.js
|
exec_console
|
function exec_console(func, log, format) {
if (format === 'json') {
func(JSON.stringify(log));
} else {
func(
' ' + log.type + '\n',
'CREATED: ' + log.created + '\t ' + '\n',
'MESSAGE: ' + log.message + '\t ' + log.trace + '\n',
!!log.data ? 'DATA:' + log.data + '\n' : '',
'\n'
);
}
}
|
javascript
|
function exec_console(func, log, format) {
if (format === 'json') {
func(JSON.stringify(log));
} else {
func(
' ' + log.type + '\n',
'CREATED: ' + log.created + '\t ' + '\n',
'MESSAGE: ' + log.message + '\t ' + log.trace + '\n',
!!log.data ? 'DATA:' + log.data + '\n' : '',
'\n'
);
}
}
|
[
"function",
"exec_console",
"(",
"func",
",",
"log",
",",
"format",
")",
"{",
"if",
"(",
"format",
"===",
"'json'",
")",
"{",
"func",
"(",
"JSON",
".",
"stringify",
"(",
"log",
")",
")",
";",
"}",
"else",
"{",
"func",
"(",
"' '",
"+",
"log",
".",
"type",
"+",
"'\\n'",
",",
"'CREATED: '",
"+",
"log",
".",
"created",
"+",
"'\\t '",
"+",
"'\\n'",
",",
"'MESSAGE: '",
"+",
"log",
".",
"message",
"+",
"'\\t '",
"+",
"log",
".",
"trace",
"+",
"'\\n'",
",",
"!",
"!",
"log",
".",
"data",
"?",
"'DATA:'",
"+",
"log",
".",
"data",
"+",
"'\\n'",
":",
"''",
",",
"'\\n'",
")",
";",
"}",
"}"
] |
Exec console output
@param func
@param log
|
[
"Exec",
"console",
"output"
] |
07c40ca18962cbd17c6df1d4e4b6de494aceff8d
|
https://github.com/AdminJuwel191/node-mvc/blob/07c40ca18962cbd17c6df1d4e4b6de494aceff8d/framework/core/logger.js#L209-L221
|
36,608 |
thenables/thenify-all
|
index.js
|
withCallback
|
function withCallback(source, destination, methods) {
return promisifyAll(source, destination, methods, thenify.withCallback)
}
|
javascript
|
function withCallback(source, destination, methods) {
return promisifyAll(source, destination, methods, thenify.withCallback)
}
|
[
"function",
"withCallback",
"(",
"source",
",",
"destination",
",",
"methods",
")",
"{",
"return",
"promisifyAll",
"(",
"source",
",",
"destination",
",",
"methods",
",",
"thenify",
".",
"withCallback",
")",
"}"
] |
Promisifies all the selected functions in an object and backward compatible with callback.
@param {Object} source the source object for the async functions
@param {Object} [destination] the destination to set all the promisified methods
@param {Array} [methods] an array of method names of `source`
@return {Object}
@api public
|
[
"Promisifies",
"all",
"the",
"selected",
"functions",
"in",
"an",
"object",
"and",
"backward",
"compatible",
"with",
"callback",
"."
] |
f436113d8076adb9138c222a61689acdef6f6bd9
|
https://github.com/thenables/thenify-all/blob/f436113d8076adb9138c222a61689acdef6f6bd9/index.js#L32-L34
|
36,609 |
vanwagonet/modules
|
lib/define.js
|
map
|
function map(arr, fn) {
for (var arr2 = [], a = 0, aa = arr.length; a < aa; ++a) { arr2[a] = fn(arr[a]); }
return arr2;
}
|
javascript
|
function map(arr, fn) {
for (var arr2 = [], a = 0, aa = arr.length; a < aa; ++a) { arr2[a] = fn(arr[a]); }
return arr2;
}
|
[
"function",
"map",
"(",
"arr",
",",
"fn",
")",
"{",
"for",
"(",
"var",
"arr2",
"=",
"[",
"]",
",",
"a",
"=",
"0",
",",
"aa",
"=",
"arr",
".",
"length",
";",
"a",
"<",
"aa",
";",
"++",
"a",
")",
"{",
"arr2",
"[",
"a",
"]",
"=",
"fn",
"(",
"arr",
"[",
"a",
"]",
")",
";",
"}",
"return",
"arr2",
";",
"}"
] |
a poor-man's Array.prototype.map
|
[
"a",
"poor",
"-",
"man",
"s",
"Array",
".",
"prototype",
".",
"map"
] |
eb2a0c9c54040937f7e361783cbaa0121713498c
|
https://github.com/vanwagonet/modules/blob/eb2a0c9c54040937f7e361783cbaa0121713498c/lib/define.js#L9-L12
|
36,610 |
vanwagonet/modules
|
lib/define.js
|
fireWaits
|
function fireWaits(module) {
map(waits[module.id], function(fn) { fn(module); });
waits[module.id] = [];
}
|
javascript
|
function fireWaits(module) {
map(waits[module.id], function(fn) { fn(module); });
waits[module.id] = [];
}
|
[
"function",
"fireWaits",
"(",
"module",
")",
"{",
"map",
"(",
"waits",
"[",
"module",
".",
"id",
"]",
",",
"function",
"(",
"fn",
")",
"{",
"fn",
"(",
"module",
")",
";",
"}",
")",
";",
"waits",
"[",
"module",
".",
"id",
"]",
"=",
"[",
"]",
";",
"}"
] |
run all functions waiting for the module
|
[
"run",
"all",
"functions",
"waiting",
"for",
"the",
"module"
] |
eb2a0c9c54040937f7e361783cbaa0121713498c
|
https://github.com/vanwagonet/modules/blob/eb2a0c9c54040937f7e361783cbaa0121713498c/lib/define.js#L15-L18
|
36,611 |
vanwagonet/modules
|
lib/define.js
|
define
|
function define(id, deps, exp) {
if (!exp) { exp = deps; deps = [ 'require', 'exports', 'module' ]; }
var module = getModule(undefined, id);
module.children = map(deps, function(dep) { return getModule(module, dep); });
module.loaded = true;
factories[id] = exp;
fireWaits(module);
}
|
javascript
|
function define(id, deps, exp) {
if (!exp) { exp = deps; deps = [ 'require', 'exports', 'module' ]; }
var module = getModule(undefined, id);
module.children = map(deps, function(dep) { return getModule(module, dep); });
module.loaded = true;
factories[id] = exp;
fireWaits(module);
}
|
[
"function",
"define",
"(",
"id",
",",
"deps",
",",
"exp",
")",
"{",
"if",
"(",
"!",
"exp",
")",
"{",
"exp",
"=",
"deps",
";",
"deps",
"=",
"[",
"'require'",
",",
"'exports'",
",",
"'module'",
"]",
";",
"}",
"var",
"module",
"=",
"getModule",
"(",
"undefined",
",",
"id",
")",
";",
"module",
".",
"children",
"=",
"map",
"(",
"deps",
",",
"function",
"(",
"dep",
")",
"{",
"return",
"getModule",
"(",
"module",
",",
"dep",
")",
";",
"}",
")",
";",
"module",
".",
"loaded",
"=",
"true",
";",
"factories",
"[",
"id",
"]",
"=",
"exp",
";",
"fireWaits",
"(",
"module",
")",
";",
"}"
] |
define a new module
|
[
"define",
"a",
"new",
"module"
] |
eb2a0c9c54040937f7e361783cbaa0121713498c
|
https://github.com/vanwagonet/modules/blob/eb2a0c9c54040937f7e361783cbaa0121713498c/lib/define.js#L32-L39
|
36,612 |
vanwagonet/modules
|
lib/define.js
|
makeRequire
|
function makeRequire(module) {
var mrequire = function(id, fn) { return require(module, id, fn); };
mrequire.resolve = function(id) { return getModule(module, id).uri; };
mrequire.toUrl = function(id) {
return getModule(module, id.replace(/\.[^.\\\/]+$/, ''))
.uri.replace(/\.js$/i, id.match(/\.[^.\\\/]+$/));
};
mrequire.cache = modules;
mrequire.main = main;
mrequire.map = mapUrlToIds; // allow mapping multiple module ids to a url
return mrequire;
}
|
javascript
|
function makeRequire(module) {
var mrequire = function(id, fn) { return require(module, id, fn); };
mrequire.resolve = function(id) { return getModule(module, id).uri; };
mrequire.toUrl = function(id) {
return getModule(module, id.replace(/\.[^.\\\/]+$/, ''))
.uri.replace(/\.js$/i, id.match(/\.[^.\\\/]+$/));
};
mrequire.cache = modules;
mrequire.main = main;
mrequire.map = mapUrlToIds; // allow mapping multiple module ids to a url
return mrequire;
}
|
[
"function",
"makeRequire",
"(",
"module",
")",
"{",
"var",
"mrequire",
"=",
"function",
"(",
"id",
",",
"fn",
")",
"{",
"return",
"require",
"(",
"module",
",",
"id",
",",
"fn",
")",
";",
"}",
";",
"mrequire",
".",
"resolve",
"=",
"function",
"(",
"id",
")",
"{",
"return",
"getModule",
"(",
"module",
",",
"id",
")",
".",
"uri",
";",
"}",
";",
"mrequire",
".",
"toUrl",
"=",
"function",
"(",
"id",
")",
"{",
"return",
"getModule",
"(",
"module",
",",
"id",
".",
"replace",
"(",
"/",
"\\.[^.\\\\\\/]+$",
"/",
",",
"''",
")",
")",
".",
"uri",
".",
"replace",
"(",
"/",
"\\.js$",
"/",
"i",
",",
"id",
".",
"match",
"(",
"/",
"\\.[^.\\\\\\/]+$",
"/",
")",
")",
";",
"}",
";",
"mrequire",
".",
"cache",
"=",
"modules",
";",
"mrequire",
".",
"main",
"=",
"main",
";",
"mrequire",
".",
"map",
"=",
"mapUrlToIds",
";",
"// allow mapping multiple module ids to a url",
"return",
"mrequire",
";",
"}"
] |
build out the require function specific to the module scope
|
[
"build",
"out",
"the",
"require",
"function",
"specific",
"to",
"the",
"module",
"scope"
] |
eb2a0c9c54040937f7e361783cbaa0121713498c
|
https://github.com/vanwagonet/modules/blob/eb2a0c9c54040937f7e361783cbaa0121713498c/lib/define.js#L42-L53
|
36,613 |
vanwagonet/modules
|
lib/define.js
|
getModule
|
function getModule(parent, id) {
if ('require' === id || 'exports' === id || 'module' === id) {
return { id:id, loaded:true, exports:parent[id] || parent, children:[] };
}
id = resolve(parent, id).replace(/\.js$/i, '');
if (modules[id]) { return modules[id]; }
var uri = canonicalize(urls[id] ? urls[id] : path.replace(/[^\/]*$/, id + '.js')),
module = (modules[id] = { id:id, filename:uri, uri:uri, loaded:false, children:[] });
module.require = makeRequire(module);
waits[id] = [];
return module;
}
|
javascript
|
function getModule(parent, id) {
if ('require' === id || 'exports' === id || 'module' === id) {
return { id:id, loaded:true, exports:parent[id] || parent, children:[] };
}
id = resolve(parent, id).replace(/\.js$/i, '');
if (modules[id]) { return modules[id]; }
var uri = canonicalize(urls[id] ? urls[id] : path.replace(/[^\/]*$/, id + '.js')),
module = (modules[id] = { id:id, filename:uri, uri:uri, loaded:false, children:[] });
module.require = makeRequire(module);
waits[id] = [];
return module;
}
|
[
"function",
"getModule",
"(",
"parent",
",",
"id",
")",
"{",
"if",
"(",
"'require'",
"===",
"id",
"||",
"'exports'",
"===",
"id",
"||",
"'module'",
"===",
"id",
")",
"{",
"return",
"{",
"id",
":",
"id",
",",
"loaded",
":",
"true",
",",
"exports",
":",
"parent",
"[",
"id",
"]",
"||",
"parent",
",",
"children",
":",
"[",
"]",
"}",
";",
"}",
"id",
"=",
"resolve",
"(",
"parent",
",",
"id",
")",
".",
"replace",
"(",
"/",
"\\.js$",
"/",
"i",
",",
"''",
")",
";",
"if",
"(",
"modules",
"[",
"id",
"]",
")",
"{",
"return",
"modules",
"[",
"id",
"]",
";",
"}",
"var",
"uri",
"=",
"canonicalize",
"(",
"urls",
"[",
"id",
"]",
"?",
"urls",
"[",
"id",
"]",
":",
"path",
".",
"replace",
"(",
"/",
"[^\\/]*$",
"/",
",",
"id",
"+",
"'.js'",
")",
")",
",",
"module",
"=",
"(",
"modules",
"[",
"id",
"]",
"=",
"{",
"id",
":",
"id",
",",
"filename",
":",
"uri",
",",
"uri",
":",
"uri",
",",
"loaded",
":",
"false",
",",
"children",
":",
"[",
"]",
"}",
")",
";",
"module",
".",
"require",
"=",
"makeRequire",
"(",
"module",
")",
";",
"waits",
"[",
"id",
"]",
"=",
"[",
"]",
";",
"return",
"module",
";",
"}"
] |
build or retrieve a specific module object
|
[
"build",
"or",
"retrieve",
"a",
"specific",
"module",
"object"
] |
eb2a0c9c54040937f7e361783cbaa0121713498c
|
https://github.com/vanwagonet/modules/blob/eb2a0c9c54040937f7e361783cbaa0121713498c/lib/define.js#L56-L68
|
36,614 |
vanwagonet/modules
|
lib/define.js
|
require
|
function require(parent, id, fn) {
if (fn) { return ensure(parent, id, fn); }
var module = getModule(parent, id);
if (!module.loaded) { throw new Error(id + ' not found'); }
if (!('exports' in module)) {
module.parent = parent; // first module to actually require this one is parent
// if define was passed a non-function, just assign it to exports
if ('function' !== typeof factories[id = module.id]) { module.exports = factories[id]; }
else {
module.exports = {};
fn = map(module.children.slice(0, factories[id].length), // don't require prematurely on wrapped commonjs
function(child) { return require(module, child.id); });
if ((fn = factories[id].apply(global, fn))) { module.exports = fn; } // if something was returned, export it instead
}
}
return module.exports;
}
|
javascript
|
function require(parent, id, fn) {
if (fn) { return ensure(parent, id, fn); }
var module = getModule(parent, id);
if (!module.loaded) { throw new Error(id + ' not found'); }
if (!('exports' in module)) {
module.parent = parent; // first module to actually require this one is parent
// if define was passed a non-function, just assign it to exports
if ('function' !== typeof factories[id = module.id]) { module.exports = factories[id]; }
else {
module.exports = {};
fn = map(module.children.slice(0, factories[id].length), // don't require prematurely on wrapped commonjs
function(child) { return require(module, child.id); });
if ((fn = factories[id].apply(global, fn))) { module.exports = fn; } // if something was returned, export it instead
}
}
return module.exports;
}
|
[
"function",
"require",
"(",
"parent",
",",
"id",
",",
"fn",
")",
"{",
"if",
"(",
"fn",
")",
"{",
"return",
"ensure",
"(",
"parent",
",",
"id",
",",
"fn",
")",
";",
"}",
"var",
"module",
"=",
"getModule",
"(",
"parent",
",",
"id",
")",
";",
"if",
"(",
"!",
"module",
".",
"loaded",
")",
"{",
"throw",
"new",
"Error",
"(",
"id",
"+",
"' not found'",
")",
";",
"}",
"if",
"(",
"!",
"(",
"'exports'",
"in",
"module",
")",
")",
"{",
"module",
".",
"parent",
"=",
"parent",
";",
"// first module to actually require this one is parent",
"// if define was passed a non-function, just assign it to exports",
"if",
"(",
"'function'",
"!==",
"typeof",
"factories",
"[",
"id",
"=",
"module",
".",
"id",
"]",
")",
"{",
"module",
".",
"exports",
"=",
"factories",
"[",
"id",
"]",
";",
"}",
"else",
"{",
"module",
".",
"exports",
"=",
"{",
"}",
";",
"fn",
"=",
"map",
"(",
"module",
".",
"children",
".",
"slice",
"(",
"0",
",",
"factories",
"[",
"id",
"]",
".",
"length",
")",
",",
"// don't require prematurely on wrapped commonjs",
"function",
"(",
"child",
")",
"{",
"return",
"require",
"(",
"module",
",",
"child",
".",
"id",
")",
";",
"}",
")",
";",
"if",
"(",
"(",
"fn",
"=",
"factories",
"[",
"id",
"]",
".",
"apply",
"(",
"global",
",",
"fn",
")",
")",
")",
"{",
"module",
".",
"exports",
"=",
"fn",
";",
"}",
"// if something was returned, export it instead",
"}",
"}",
"return",
"module",
".",
"exports",
";",
"}"
] |
execute a module's code, and return its exports
|
[
"execute",
"a",
"module",
"s",
"code",
"and",
"return",
"its",
"exports"
] |
eb2a0c9c54040937f7e361783cbaa0121713498c
|
https://github.com/vanwagonet/modules/blob/eb2a0c9c54040937f7e361783cbaa0121713498c/lib/define.js#L71-L88
|
36,615 |
vanwagonet/modules
|
lib/define.js
|
ensure
|
function ensure(parent, ids, fn) {
ids = [].concat(ids);
var visited = {}, wait = 0;
function done() {
if (fn) { fn.apply(global, map(ids, function(id) { return require(parent, id); })); }
fn = undefined;
}
function visit(module) {
if (module.id in visited) { return; }
if ((visited[module.id] = module.loaded)) { return map(module.children, visit); }
++wait;
waits[module.id].push(function() {
map(module.children, visit);
if (--wait <= 0) { setTimeout(done, 0); }
});
var script;
map(doc.querySelectorAll('script'), function(node) {
if (canonicalize(node.src) === module.uri) { script = node; }
});
if (!script) {
script = doc.createElement('script');
script.onload = script.onerror = script.onreadystatechange = function() {
if ('loading' === script.readyState) { return; }
script.onload = script.onerror = script.onreadystatechange = null;
fireWaits(module);
};
script.defer = true;
script.src = module.uri;
doc.querySelector('head').appendChild(script);
}
}
map(ids, function(id) { visit(getModule(parent, id)); });
if (wait <= 0) { setTimeout(done, 0); } // always async
}
|
javascript
|
function ensure(parent, ids, fn) {
ids = [].concat(ids);
var visited = {}, wait = 0;
function done() {
if (fn) { fn.apply(global, map(ids, function(id) { return require(parent, id); })); }
fn = undefined;
}
function visit(module) {
if (module.id in visited) { return; }
if ((visited[module.id] = module.loaded)) { return map(module.children, visit); }
++wait;
waits[module.id].push(function() {
map(module.children, visit);
if (--wait <= 0) { setTimeout(done, 0); }
});
var script;
map(doc.querySelectorAll('script'), function(node) {
if (canonicalize(node.src) === module.uri) { script = node; }
});
if (!script) {
script = doc.createElement('script');
script.onload = script.onerror = script.onreadystatechange = function() {
if ('loading' === script.readyState) { return; }
script.onload = script.onerror = script.onreadystatechange = null;
fireWaits(module);
};
script.defer = true;
script.src = module.uri;
doc.querySelector('head').appendChild(script);
}
}
map(ids, function(id) { visit(getModule(parent, id)); });
if (wait <= 0) { setTimeout(done, 0); } // always async
}
|
[
"function",
"ensure",
"(",
"parent",
",",
"ids",
",",
"fn",
")",
"{",
"ids",
"=",
"[",
"]",
".",
"concat",
"(",
"ids",
")",
";",
"var",
"visited",
"=",
"{",
"}",
",",
"wait",
"=",
"0",
";",
"function",
"done",
"(",
")",
"{",
"if",
"(",
"fn",
")",
"{",
"fn",
".",
"apply",
"(",
"global",
",",
"map",
"(",
"ids",
",",
"function",
"(",
"id",
")",
"{",
"return",
"require",
"(",
"parent",
",",
"id",
")",
";",
"}",
")",
")",
";",
"}",
"fn",
"=",
"undefined",
";",
"}",
"function",
"visit",
"(",
"module",
")",
"{",
"if",
"(",
"module",
".",
"id",
"in",
"visited",
")",
"{",
"return",
";",
"}",
"if",
"(",
"(",
"visited",
"[",
"module",
".",
"id",
"]",
"=",
"module",
".",
"loaded",
")",
")",
"{",
"return",
"map",
"(",
"module",
".",
"children",
",",
"visit",
")",
";",
"}",
"++",
"wait",
";",
"waits",
"[",
"module",
".",
"id",
"]",
".",
"push",
"(",
"function",
"(",
")",
"{",
"map",
"(",
"module",
".",
"children",
",",
"visit",
")",
";",
"if",
"(",
"--",
"wait",
"<=",
"0",
")",
"{",
"setTimeout",
"(",
"done",
",",
"0",
")",
";",
"}",
"}",
")",
";",
"var",
"script",
";",
"map",
"(",
"doc",
".",
"querySelectorAll",
"(",
"'script'",
")",
",",
"function",
"(",
"node",
")",
"{",
"if",
"(",
"canonicalize",
"(",
"node",
".",
"src",
")",
"===",
"module",
".",
"uri",
")",
"{",
"script",
"=",
"node",
";",
"}",
"}",
")",
";",
"if",
"(",
"!",
"script",
")",
"{",
"script",
"=",
"doc",
".",
"createElement",
"(",
"'script'",
")",
";",
"script",
".",
"onload",
"=",
"script",
".",
"onerror",
"=",
"script",
".",
"onreadystatechange",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"'loading'",
"===",
"script",
".",
"readyState",
")",
"{",
"return",
";",
"}",
"script",
".",
"onload",
"=",
"script",
".",
"onerror",
"=",
"script",
".",
"onreadystatechange",
"=",
"null",
";",
"fireWaits",
"(",
"module",
")",
";",
"}",
";",
"script",
".",
"defer",
"=",
"true",
";",
"script",
".",
"src",
"=",
"module",
".",
"uri",
";",
"doc",
".",
"querySelector",
"(",
"'head'",
")",
".",
"appendChild",
"(",
"script",
")",
";",
"}",
"}",
"map",
"(",
"ids",
",",
"function",
"(",
"id",
")",
"{",
"visit",
"(",
"getModule",
"(",
"parent",
",",
"id",
")",
")",
";",
"}",
")",
";",
"if",
"(",
"wait",
"<=",
"0",
")",
"{",
"setTimeout",
"(",
"done",
",",
"0",
")",
";",
"}",
"// always async",
"}"
] |
make sure the modules are loaded
|
[
"make",
"sure",
"the",
"modules",
"are",
"loaded"
] |
eb2a0c9c54040937f7e361783cbaa0121713498c
|
https://github.com/vanwagonet/modules/blob/eb2a0c9c54040937f7e361783cbaa0121713498c/lib/define.js#L105-L143
|
36,616 |
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",
")",
"{",
"// 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",
";",
"}",
"}"
] |
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
|
36,617 |
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
|
36,618 |
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.external = fixExternal(options.external);",
"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
|
36,619 |
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",
")",
",",
"// (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",
")",
";",
"}",
";",
"}"
] |
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
|
36,620 |
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'",
")",
";",
"}",
"/*\n * Need to escape backslashes (\\) first because escaping ' and \" will also \n * add a \\, which interferes with \\ escaping.\n */",
"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",
";",
"}"
] |
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
|
36,621 |
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",
")",
"// 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",
"}"
] |
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
|
36,622 |
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",
"(",
"/",
"^[+\\-! ]",
"/",
",",
"''",
")",
"}",
"// 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",
")",
"}"
] |
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
|
36,623 |
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",
"}",
"// 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",
"}"
] |
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
|
36,624 |
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
|
36,625 |
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
|
36,626 |
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
|
36,627 |
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
|
36,628 |
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
|
|
36,629 |
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
|
36,630 |
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
|
36,631 |
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
|
36,632 |
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
|
36,633 |
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
|
36,634 |
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
|
36,635 |
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
|
36,636 |
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
|
36,637 |
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
|
36,638 |
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
|
36,639 |
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",
"// 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",
"}"
] |
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
|
36,640 |
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
|
36,641 |
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
|
36,642 |
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
|
36,643 |
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
|
|
36,644 |
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
|
|
36,645 |
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
|
36,646 |
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
|
|
36,647 |
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
|
|
36,648 |
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
|
36,649 |
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
|
36,650 |
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
|
36,651 |
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
|
36,652 |
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
|
36,653 |
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
|
36,654 |
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",
"]",
";",
"}",
"}",
"// 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",
")",
";",
"}"
] |
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
|
36,655 |
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
|
|
36,656 |
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
|
|
36,657 |
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
|
|
36,658 |
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'",
",",
"}",
"// 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",
")",
"}",
")",
"}"
] |
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
|
|
36,659 |
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
|
36,660 |
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
|
36,661 |
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
|
36,662 |
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
|
36,663 |
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
|
36,664 |
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
|
36,665 |
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",
"=",
"{",
"}",
"// 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",
")",
"}",
"}"
] |
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
|
36,666 |
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
|
36,667 |
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
|
36,668 |
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
|
36,669 |
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
|
36,670 |
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
|
36,671 |
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
|
36,672 |
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
|
36,673 |
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",
";",
"// 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",
";",
"}",
";",
"}",
"}",
"}"
] |
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
|
36,674 |
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
|
36,675 |
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",
")",
"{",
"// 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",
"}"
] |
Find type at
|
[
"Find",
"type",
"at"
] |
b362729530727cfde0ec96289775d4363c40a17c
|
https://github.com/angelozerr/tern-browser-extension/blob/b362729530727cfde0ec96289775d4363c40a17c/browser-extension.js#L370-L403
|
36,676 |
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",
"]",
";",
"// 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",
"(",
"`",
"`",
")",
")",
";",
"}",
"// 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",
"=",
"`",
"${",
"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
|
36,677 |
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
|
36,678 |
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
|
36,679 |
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",
")",
"// bootstrap to itself to make the transformer accessible to children",
"}"
] |
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
|
36,680 |
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
|
36,681 |
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
|
36,682 |
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
|
36,683 |
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
|
36,684 |
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
|
36,685 |
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",
"(",
")",
"{",
"// 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",
")",
";",
"}",
"}",
"}",
";",
"}"
] |
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
|
36,686 |
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
|
36,687 |
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",
")",
"{",
"// 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",
";",
"}"
] |
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
|
36,688 |
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
|
36,689 |
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
|
36,690 |
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
|
36,691 |
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'",
")",
"{",
"/* 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",
"]",
";",
"}"
] |
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
|
36,692 |
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
|
36,693 |
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
|
36,694 |
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
|
36,695 |
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",
"(",
")",
"{",
"// 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",
";",
"}"
] |
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
|
36,696 |
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",
"=",
"{",
"}",
";",
"// 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",
";",
"}"
] |
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
|
36,697 |
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'",
";",
"// 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.'",
")",
";",
"}",
"}",
")",
")",
";",
"}",
",",
"{",
"}",
")",
";",
"}"
] |
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
|
36,698 |
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",
")",
"{",
"// 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",
";",
"}",
")",
")",
";",
"}",
",",
"{",
"}",
")",
";",
"}"
] |
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
|
36,699 |
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
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.