repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
sequence | docstring
stringlengths 4
11.8k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 86
226
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
JakubMrozek/eet | lib/eet.js | getHeaderItems | function getHeaderItems (uid, currentDate, prvniZaslani, overeni) {
return {
attributes: {
uuid_zpravy: uid,
dat_odesl: formatDate(currentDate),
prvni_zaslani: formatBool(prvniZaslani, true),
overeni: formatBool(overeni, false)
}
}
} | javascript | function getHeaderItems (uid, currentDate, prvniZaslani, overeni) {
return {
attributes: {
uuid_zpravy: uid,
dat_odesl: formatDate(currentDate),
prvni_zaslani: formatBool(prvniZaslani, true),
overeni: formatBool(overeni, false)
}
}
} | [
"function",
"getHeaderItems",
"(",
"uid",
",",
"currentDate",
",",
"prvniZaslani",
",",
"overeni",
")",
"{",
"return",
"{",
"attributes",
":",
"{",
"uuid_zpravy",
":",
"uid",
",",
"dat_odesl",
":",
"formatDate",
"(",
"currentDate",
")",
",",
"prvni_zaslani",
":",
"formatBool",
"(",
"prvniZaslani",
",",
"true",
")",
",",
"overeni",
":",
"formatBool",
"(",
"overeni",
",",
"false",
")",
"}",
"}",
"}"
] | Vygeneruje polozky pro element Hlavicka. | [
"Vygeneruje",
"polozky",
"pro",
"element",
"Hlavicka",
"."
] | 28a8f0b6743308c705eb0c17e985e0ed065b692e | https://github.com/JakubMrozek/eet/blob/28a8f0b6743308c705eb0c17e985e0ed065b692e/lib/eet.js#L114-L123 | train |
JakubMrozek/eet | lib/eet.js | getFooterItems | function getFooterItems (privateKey, items) {
const pkp = generatePKP(
privateKey,
items.dicPopl,
items.idProvoz,
items.idPokl,
items.poradCis,
formatDate(items.datTrzby),
formatNumber(items.celkTrzba)
)
const bkp = generateBKP(pkp)
return {
pkp: {
attributes: {
digest: 'SHA256',
cipher: 'RSA2048',
encoding: 'base64'
},
$value: pkp
},
bkp: {
attributes: {
digest: 'SHA1',
encoding: 'base16'
},
$value: bkp
}
}
} | javascript | function getFooterItems (privateKey, items) {
const pkp = generatePKP(
privateKey,
items.dicPopl,
items.idProvoz,
items.idPokl,
items.poradCis,
formatDate(items.datTrzby),
formatNumber(items.celkTrzba)
)
const bkp = generateBKP(pkp)
return {
pkp: {
attributes: {
digest: 'SHA256',
cipher: 'RSA2048',
encoding: 'base64'
},
$value: pkp
},
bkp: {
attributes: {
digest: 'SHA1',
encoding: 'base16'
},
$value: bkp
}
}
} | [
"function",
"getFooterItems",
"(",
"privateKey",
",",
"items",
")",
"{",
"const",
"pkp",
"=",
"generatePKP",
"(",
"privateKey",
",",
"items",
".",
"dicPopl",
",",
"items",
".",
"idProvoz",
",",
"items",
".",
"idPokl",
",",
"items",
".",
"poradCis",
",",
"formatDate",
"(",
"items",
".",
"datTrzby",
")",
",",
"formatNumber",
"(",
"items",
".",
"celkTrzba",
")",
")",
"const",
"bkp",
"=",
"generateBKP",
"(",
"pkp",
")",
"return",
"{",
"pkp",
":",
"{",
"attributes",
":",
"{",
"digest",
":",
"'SHA256'",
",",
"cipher",
":",
"'RSA2048'",
",",
"encoding",
":",
"'base64'",
"}",
",",
"$value",
":",
"pkp",
"}",
",",
"bkp",
":",
"{",
"attributes",
":",
"{",
"digest",
":",
"'SHA1'",
",",
"encoding",
":",
"'base16'",
"}",
",",
"$value",
":",
"bkp",
"}",
"}",
"}"
] | Vygeneruje polozky pro element KontrolniKody. | [
"Vygeneruje",
"polozky",
"pro",
"element",
"KontrolniKody",
"."
] | 28a8f0b6743308c705eb0c17e985e0ed065b692e | https://github.com/JakubMrozek/eet/blob/28a8f0b6743308c705eb0c17e985e0ed065b692e/lib/eet.js#L194-L223 | train |
JakubMrozek/eet | lib/eet.js | getResponseItems | function getResponseItems (response) {
const header = response.Hlavicka.attributes
const body = response.Potvrzeni.attributes
return {
uuid: header.uuid_zpravy,
bkp: header.bkp,
date: new Date(header.dat_prij),
test: body.test === 'true',
fik: body.fik,
warnings: getWarnings(response.Varovani)
}
} | javascript | function getResponseItems (response) {
const header = response.Hlavicka.attributes
const body = response.Potvrzeni.attributes
return {
uuid: header.uuid_zpravy,
bkp: header.bkp,
date: new Date(header.dat_prij),
test: body.test === 'true',
fik: body.fik,
warnings: getWarnings(response.Varovani)
}
} | [
"function",
"getResponseItems",
"(",
"response",
")",
"{",
"const",
"header",
"=",
"response",
".",
"Hlavicka",
".",
"attributes",
"const",
"body",
"=",
"response",
".",
"Potvrzeni",
".",
"attributes",
"return",
"{",
"uuid",
":",
"header",
".",
"uuid_zpravy",
",",
"bkp",
":",
"header",
".",
"bkp",
",",
"date",
":",
"new",
"Date",
"(",
"header",
".",
"dat_prij",
")",
",",
"test",
":",
"body",
".",
"test",
"===",
"'true'",
",",
"fik",
":",
"body",
".",
"fik",
",",
"warnings",
":",
"getWarnings",
"(",
"response",
".",
"Varovani",
")",
"}",
"}"
] | Zpracuje OK odpoved ze serveru EET. | [
"Zpracuje",
"OK",
"odpoved",
"ze",
"serveru",
"EET",
"."
] | 28a8f0b6743308c705eb0c17e985e0ed065b692e | https://github.com/JakubMrozek/eet/blob/28a8f0b6743308c705eb0c17e985e0ed065b692e/lib/eet.js#L229-L240 | train |
grasshopper-cms/grasshopper-api-js | lib/routes/social/twitter.js | _loadUserFromToken | function _loadUserFromToken(){
return BB
.bind(this)
.then(function() {
return grasshopper.request(this.token).users.current();
})
.then(function(user){
this.user = user;
});
} | javascript | function _loadUserFromToken(){
return BB
.bind(this)
.then(function() {
return grasshopper.request(this.token).users.current();
})
.then(function(user){
this.user = user;
});
} | [
"function",
"_loadUserFromToken",
"(",
")",
"{",
"return",
"BB",
".",
"bind",
"(",
"this",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"return",
"grasshopper",
".",
"request",
"(",
"this",
".",
"token",
")",
".",
"users",
".",
"current",
"(",
")",
";",
"}",
")",
".",
"then",
"(",
"function",
"(",
"user",
")",
"{",
"this",
".",
"user",
"=",
"user",
";",
"}",
")",
";",
"}"
] | Utility function to return the current logged in user. | [
"Utility",
"function",
"to",
"return",
"the",
"current",
"logged",
"in",
"user",
"."
] | 05a952b8b65e3a66c8a27f5d84699ee5cf02844d | https://github.com/grasshopper-cms/grasshopper-api-js/blob/05a952b8b65e3a66c8a27f5d84699ee5cf02844d/lib/routes/social/twitter.js#L62-L71 | train |
grasshopper-cms/grasshopper-api-js | lib/routes/social/twitter.js | _linkIdentity | function _linkIdentity() {
var identityOptions = {
id: this.params.raw.user_id,
accessToken: this.params.access_token,
accessSecret: this.params.access_secret,
screen_name: this.params.raw.screen_name
};
return BB.resolve(grasshopper.request(this.token).users.linkIdentity(this.user._id.toString(), 'twitter', identityOptions));
} | javascript | function _linkIdentity() {
var identityOptions = {
id: this.params.raw.user_id,
accessToken: this.params.access_token,
accessSecret: this.params.access_secret,
screen_name: this.params.raw.screen_name
};
return BB.resolve(grasshopper.request(this.token).users.linkIdentity(this.user._id.toString(), 'twitter', identityOptions));
} | [
"function",
"_linkIdentity",
"(",
")",
"{",
"var",
"identityOptions",
"=",
"{",
"id",
":",
"this",
".",
"params",
".",
"raw",
".",
"user_id",
",",
"accessToken",
":",
"this",
".",
"params",
".",
"access_token",
",",
"accessSecret",
":",
"this",
".",
"params",
".",
"access_secret",
",",
"screen_name",
":",
"this",
".",
"params",
".",
"raw",
".",
"screen_name",
"}",
";",
"return",
"BB",
".",
"resolve",
"(",
"grasshopper",
".",
"request",
"(",
"this",
".",
"token",
")",
".",
"users",
".",
"linkIdentity",
"(",
"this",
".",
"user",
".",
"_id",
".",
"toString",
"(",
")",
",",
"'twitter'",
",",
"identityOptions",
")",
")",
";",
"}"
] | Utility function to link a user's twitter info to the current user. | [
"Utility",
"function",
"to",
"link",
"a",
"user",
"s",
"twitter",
"info",
"to",
"the",
"current",
"user",
"."
] | 05a952b8b65e3a66c8a27f5d84699ee5cf02844d | https://github.com/grasshopper-cms/grasshopper-api-js/blob/05a952b8b65e3a66c8a27f5d84699ee5cf02844d/lib/routes/social/twitter.js#L74-L83 | train |
aaronj1335/webpack-postcss-tools | index.js | makeVarMap | function makeVarMap(filename) {
var map = {vars: {}, media: {}, selector: {}};
function resolveImport(path, basedir) {
if (path[0] === '/')
return path;
if (path[0] === '.')
return pathResolve(join(basedir, path));
// webpack treats anything starting w/ ~ as a module name, which we're
// about to do below, so just remove leading tildes
path = path.replace(/^~/, '');
return resolve.sync(path, {
basedir: basedir,
packageFilter: function (package) {
var newPackage = extend({}, package);
if (newPackage.style != null)
newPackage.main = newPackage.style;
return newPackage;
}
});
}
function processRules(rule) {
// only variables declared for `:root` are supported for now
if (rule.type !== 'rule' ||
rule.selectors.length !== 1 ||
rule.selectors[0] !== ':root' ||
rule.parent.type !== 'root')
return;
rule.each(function (decl) {
var prop = decl.prop;
var value = decl.value;
if (prop && prop.indexOf('--') === 0)
map.vars[prop] = value;
});
}
function processAtRuleCustom(atRule) {
if (atRule.name && ['custom-media', 'custom-selector'].indexOf(atRule.name) !== -1) {
var type = atRule.name.split('-')[1];
var name = atRule.params.split(/\s+/, 1)[0];
var nameRe = new RegExp('^' + name + '\\s+');
map[type][name] = atRule.params.replace(nameRe, '');
}
}
function isUrl(string) {
return /(https?:)?\/\//.test(string);
}
function process(fn) {
var style = postcss().process(fs.readFileSync(fn, 'utf8'));
// recurse into each import. because we make the recursive call before
// extracting values (depth-first, post-order traversal), files that import
// libraries can re-define variable declarations, which more-closely
// matches the browser's behavior
style.root.eachAtRule(function (atRule) {
if (atRule.name !== 'import')
return;
var stripped = stripQuotes(unwrapUrl(atRule.params));
if(isUrl(stripped)) {
return;
}
process(resolveImport(stripped, dirname(fn)));
});
// extract variable definitions
style.root.eachRule(processRules);
// extract custom definitions
style.root.eachAtRule(processAtRuleCustom);
}
process(pathResolve(filename));
return map;
} | javascript | function makeVarMap(filename) {
var map = {vars: {}, media: {}, selector: {}};
function resolveImport(path, basedir) {
if (path[0] === '/')
return path;
if (path[0] === '.')
return pathResolve(join(basedir, path));
// webpack treats anything starting w/ ~ as a module name, which we're
// about to do below, so just remove leading tildes
path = path.replace(/^~/, '');
return resolve.sync(path, {
basedir: basedir,
packageFilter: function (package) {
var newPackage = extend({}, package);
if (newPackage.style != null)
newPackage.main = newPackage.style;
return newPackage;
}
});
}
function processRules(rule) {
// only variables declared for `:root` are supported for now
if (rule.type !== 'rule' ||
rule.selectors.length !== 1 ||
rule.selectors[0] !== ':root' ||
rule.parent.type !== 'root')
return;
rule.each(function (decl) {
var prop = decl.prop;
var value = decl.value;
if (prop && prop.indexOf('--') === 0)
map.vars[prop] = value;
});
}
function processAtRuleCustom(atRule) {
if (atRule.name && ['custom-media', 'custom-selector'].indexOf(atRule.name) !== -1) {
var type = atRule.name.split('-')[1];
var name = atRule.params.split(/\s+/, 1)[0];
var nameRe = new RegExp('^' + name + '\\s+');
map[type][name] = atRule.params.replace(nameRe, '');
}
}
function isUrl(string) {
return /(https?:)?\/\//.test(string);
}
function process(fn) {
var style = postcss().process(fs.readFileSync(fn, 'utf8'));
// recurse into each import. because we make the recursive call before
// extracting values (depth-first, post-order traversal), files that import
// libraries can re-define variable declarations, which more-closely
// matches the browser's behavior
style.root.eachAtRule(function (atRule) {
if (atRule.name !== 'import')
return;
var stripped = stripQuotes(unwrapUrl(atRule.params));
if(isUrl(stripped)) {
return;
}
process(resolveImport(stripped, dirname(fn)));
});
// extract variable definitions
style.root.eachRule(processRules);
// extract custom definitions
style.root.eachAtRule(processAtRuleCustom);
}
process(pathResolve(filename));
return map;
} | [
"function",
"makeVarMap",
"(",
"filename",
")",
"{",
"var",
"map",
"=",
"{",
"vars",
":",
"{",
"}",
",",
"media",
":",
"{",
"}",
",",
"selector",
":",
"{",
"}",
"}",
";",
"function",
"resolveImport",
"(",
"path",
",",
"basedir",
")",
"{",
"if",
"(",
"path",
"[",
"0",
"]",
"===",
"'/'",
")",
"return",
"path",
";",
"if",
"(",
"path",
"[",
"0",
"]",
"===",
"'.'",
")",
"return",
"pathResolve",
"(",
"join",
"(",
"basedir",
",",
"path",
")",
")",
";",
"path",
"=",
"path",
".",
"replace",
"(",
"/",
"^~",
"/",
",",
"''",
")",
";",
"return",
"resolve",
".",
"sync",
"(",
"path",
",",
"{",
"basedir",
":",
"basedir",
",",
"packageFilter",
":",
"function",
"(",
"package",
")",
"{",
"var",
"newPackage",
"=",
"extend",
"(",
"{",
"}",
",",
"package",
")",
";",
"if",
"(",
"newPackage",
".",
"style",
"!=",
"null",
")",
"newPackage",
".",
"main",
"=",
"newPackage",
".",
"style",
";",
"return",
"newPackage",
";",
"}",
"}",
")",
";",
"}",
"function",
"processRules",
"(",
"rule",
")",
"{",
"if",
"(",
"rule",
".",
"type",
"!==",
"'rule'",
"||",
"rule",
".",
"selectors",
".",
"length",
"!==",
"1",
"||",
"rule",
".",
"selectors",
"[",
"0",
"]",
"!==",
"':root'",
"||",
"rule",
".",
"parent",
".",
"type",
"!==",
"'root'",
")",
"return",
";",
"rule",
".",
"each",
"(",
"function",
"(",
"decl",
")",
"{",
"var",
"prop",
"=",
"decl",
".",
"prop",
";",
"var",
"value",
"=",
"decl",
".",
"value",
";",
"if",
"(",
"prop",
"&&",
"prop",
".",
"indexOf",
"(",
"'--'",
")",
"===",
"0",
")",
"map",
".",
"vars",
"[",
"prop",
"]",
"=",
"value",
";",
"}",
")",
";",
"}",
"function",
"processAtRuleCustom",
"(",
"atRule",
")",
"{",
"if",
"(",
"atRule",
".",
"name",
"&&",
"[",
"'custom-media'",
",",
"'custom-selector'",
"]",
".",
"indexOf",
"(",
"atRule",
".",
"name",
")",
"!==",
"-",
"1",
")",
"{",
"var",
"type",
"=",
"atRule",
".",
"name",
".",
"split",
"(",
"'-'",
")",
"[",
"1",
"]",
";",
"var",
"name",
"=",
"atRule",
".",
"params",
".",
"split",
"(",
"/",
"\\s+",
"/",
",",
"1",
")",
"[",
"0",
"]",
";",
"var",
"nameRe",
"=",
"new",
"RegExp",
"(",
"'^'",
"+",
"name",
"+",
"'\\\\s+'",
")",
";",
"\\\\",
"}",
"}",
"map",
"[",
"type",
"]",
"[",
"name",
"]",
"=",
"atRule",
".",
"params",
".",
"replace",
"(",
"nameRe",
",",
"''",
")",
";",
"function",
"isUrl",
"(",
"string",
")",
"{",
"return",
"/",
"(https?:)?\\/\\/",
"/",
".",
"test",
"(",
"string",
")",
";",
"}",
"function",
"process",
"(",
"fn",
")",
"{",
"var",
"style",
"=",
"postcss",
"(",
")",
".",
"process",
"(",
"fs",
".",
"readFileSync",
"(",
"fn",
",",
"'utf8'",
")",
")",
";",
"style",
".",
"root",
".",
"eachAtRule",
"(",
"function",
"(",
"atRule",
")",
"{",
"if",
"(",
"atRule",
".",
"name",
"!==",
"'import'",
")",
"return",
";",
"var",
"stripped",
"=",
"stripQuotes",
"(",
"unwrapUrl",
"(",
"atRule",
".",
"params",
")",
")",
";",
"if",
"(",
"isUrl",
"(",
"stripped",
")",
")",
"{",
"return",
";",
"}",
"process",
"(",
"resolveImport",
"(",
"stripped",
",",
"dirname",
"(",
"fn",
")",
")",
")",
";",
"}",
")",
";",
"style",
".",
"root",
".",
"eachRule",
"(",
"processRules",
")",
";",
"style",
".",
"root",
".",
"eachAtRule",
"(",
"processAtRuleCustom",
")",
";",
"}",
"process",
"(",
"pathResolve",
"(",
"filename",
")",
")",
";",
"}"
] | create maps of variables and custom media queries
because we want to:
- treat every css file as a separate webpack module
- statically resolve css variables during the build
we run into an issue where we're compiling a css library with variables that
might be overridden by a later stylesheet. we solve this by resolving all
variables up front (making a "variable map"), and then using this while
actually compiling the css during the webpack build.
the downside of this approach is that changing a variable value usually
requires you to restart the webpack dev build.
this takes a single css filename as an entry point and makes a map of all
variables, including those defined in `import`'ed css files. it does the
same for custom media queries. | [
"create",
"maps",
"of",
"variables",
"and",
"custom",
"media",
"queries"
] | 9baa0e43cc9929ca94e9cab336089bfb96ffed98 | https://github.com/aaronj1335/webpack-postcss-tools/blob/9baa0e43cc9929ca94e9cab336089bfb96ffed98/index.js#L33-L121 | train |
aaronj1335/webpack-postcss-tools | index.js | prependTildesToImports | function prependTildesToImports(styles) {
styles.eachAtRule(function (atRule) {
if (atRule.name !== 'import')
return;
var stripped = stripQuotes(unwrapUrl(atRule.params));
if (stripped[0] !== '.' && stripped[0] !== '~' && stripped[0] !== '/') {
atRule.params = '"~' + stripped + '"';
}
});
} | javascript | function prependTildesToImports(styles) {
styles.eachAtRule(function (atRule) {
if (atRule.name !== 'import')
return;
var stripped = stripQuotes(unwrapUrl(atRule.params));
if (stripped[0] !== '.' && stripped[0] !== '~' && stripped[0] !== '/') {
atRule.params = '"~' + stripped + '"';
}
});
} | [
"function",
"prependTildesToImports",
"(",
"styles",
")",
"{",
"styles",
".",
"eachAtRule",
"(",
"function",
"(",
"atRule",
")",
"{",
"if",
"(",
"atRule",
".",
"name",
"!==",
"'import'",
")",
"return",
";",
"var",
"stripped",
"=",
"stripQuotes",
"(",
"unwrapUrl",
"(",
"atRule",
".",
"params",
")",
")",
";",
"if",
"(",
"stripped",
"[",
"0",
"]",
"!==",
"'.'",
"&&",
"stripped",
"[",
"0",
"]",
"!==",
"'~'",
"&&",
"stripped",
"[",
"0",
"]",
"!==",
"'/'",
")",
"{",
"atRule",
".",
"params",
"=",
"'\"~'",
"+",
"stripped",
"+",
"'\"'",
";",
"}",
"}",
")",
";",
"}"
] | prepend a tilde to css module imports
webpack's css-loader [treats css imports as relative paths][url-to-req], not
modules. the easiest way i've found to correct this prepending a `~` to each
import to force webpack to use it's full module lookup machinery.
[url-to-req]: https://github.com/webpack/css-loader/blob/7b50d4f569adcaf5bf185180c15435bde03f4de7/index.js#L37 | [
"prepend",
"a",
"tilde",
"to",
"css",
"module",
"imports"
] | 9baa0e43cc9929ca94e9cab336089bfb96ffed98 | https://github.com/aaronj1335/webpack-postcss-tools/blob/9baa0e43cc9929ca94e9cab336089bfb96ffed98/index.js#L136-L147 | train |
grasshopper-cms/grasshopper-api-js | lib/routes/social/facebook.js | facebookReq | function facebookReq(req, res){
var redirectUrl = _.has(grasshopper.config.identities, 'facebook') ? grasshopper.config.identities.facebook.redirectUrl : 'defaultRoute';
BB.bind({token: req.session.token, params: req.query, res: res, req: req, user: null })
.then(function(){
if(!_.isUndefined(this.token)){
this.token = new Buffer(this.token, 'base64'); //A token exists, let's decode it
return _linkSocialAccount.call(this);
}
else {
return _createSocialAccount.call(this);
}
})
.then(function(){
res.redirect(redirectUrl);
})
.catch(function(err){
console.log(err.stack);
res.redirect(redirectUrl + '?error='+ err.message);
});
} | javascript | function facebookReq(req, res){
var redirectUrl = _.has(grasshopper.config.identities, 'facebook') ? grasshopper.config.identities.facebook.redirectUrl : 'defaultRoute';
BB.bind({token: req.session.token, params: req.query, res: res, req: req, user: null })
.then(function(){
if(!_.isUndefined(this.token)){
this.token = new Buffer(this.token, 'base64'); //A token exists, let's decode it
return _linkSocialAccount.call(this);
}
else {
return _createSocialAccount.call(this);
}
})
.then(function(){
res.redirect(redirectUrl);
})
.catch(function(err){
console.log(err.stack);
res.redirect(redirectUrl + '?error='+ err.message);
});
} | [
"function",
"facebookReq",
"(",
"req",
",",
"res",
")",
"{",
"var",
"redirectUrl",
"=",
"_",
".",
"has",
"(",
"grasshopper",
".",
"config",
".",
"identities",
",",
"'facebook'",
")",
"?",
"grasshopper",
".",
"config",
".",
"identities",
".",
"facebook",
".",
"redirectUrl",
":",
"'defaultRoute'",
";",
"BB",
".",
"bind",
"(",
"{",
"token",
":",
"req",
".",
"session",
".",
"token",
",",
"params",
":",
"req",
".",
"query",
",",
"res",
":",
"res",
",",
"req",
":",
"req",
",",
"user",
":",
"null",
"}",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"!",
"_",
".",
"isUndefined",
"(",
"this",
".",
"token",
")",
")",
"{",
"this",
".",
"token",
"=",
"new",
"Buffer",
"(",
"this",
".",
"token",
",",
"'base64'",
")",
";",
"return",
"_linkSocialAccount",
".",
"call",
"(",
"this",
")",
";",
"}",
"else",
"{",
"return",
"_createSocialAccount",
".",
"call",
"(",
"this",
")",
";",
"}",
"}",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"res",
".",
"redirect",
"(",
"redirectUrl",
")",
";",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"err",
")",
"{",
"console",
".",
"log",
"(",
"err",
".",
"stack",
")",
";",
"res",
".",
"redirect",
"(",
"redirectUrl",
"+",
"'?error='",
"+",
"err",
".",
"message",
")",
";",
"}",
")",
";",
"}"
] | Middleware that handles all of the logic for creating and linking social accounts. | [
"Middleware",
"that",
"handles",
"all",
"of",
"the",
"logic",
"for",
"creating",
"and",
"linking",
"social",
"accounts",
"."
] | 05a952b8b65e3a66c8a27f5d84699ee5cf02844d | https://github.com/grasshopper-cms/grasshopper-api-js/blob/05a952b8b65e3a66c8a27f5d84699ee5cf02844d/lib/routes/social/facebook.js#L15-L36 | train |
Aldaviva/mongoose-moment | lib/schema.js | SchemaMoment | function SchemaMoment(key, options) {
SchemaType.call(this, key, options);
this.get(function(val, self){
if(!val){
return val;
} else {
return new Moment(val);
}
});
} | javascript | function SchemaMoment(key, options) {
SchemaType.call(this, key, options);
this.get(function(val, self){
if(!val){
return val;
} else {
return new Moment(val);
}
});
} | [
"function",
"SchemaMoment",
"(",
"key",
",",
"options",
")",
"{",
"SchemaType",
".",
"call",
"(",
"this",
",",
"key",
",",
"options",
")",
";",
"this",
".",
"get",
"(",
"function",
"(",
"val",
",",
"self",
")",
"{",
"if",
"(",
"!",
"val",
")",
"{",
"return",
"val",
";",
"}",
"else",
"{",
"return",
"new",
"Moment",
"(",
"val",
")",
";",
"}",
"}",
")",
";",
"}"
] | Moment SchemaType constructor.
@param {String} key
@param {Object} options
@inherits SchemaType
@api private | [
"Moment",
"SchemaType",
"constructor",
"."
] | ba36ec59e9a630b21d61d9ad63d9865ff3cb0872 | https://github.com/Aldaviva/mongoose-moment/blob/ba36ec59e9a630b21d61d9ad63d9865ff3cb0872/lib/schema.js#L46-L56 | train |
Battochon/passwordless-postgrestore | lib/postgrestore.js | PostgreStore | function PostgreStore(conString, options) {
if(!conString){
throw new Error('Connection String is missing.');
}
this._options = options || {};
this._options.pgstore = this._options.pgstore || {};
this._difficulty = this._options.pgstore.difficulty || 10;
this._table = this._options.pgstore.table || 'passwordless';
this._client = new pg.Pool({
connectionString: conString,
max: this._options.pgstore.pgPoolSize || 10
});
if(!isNumber(this._difficulty) || this._cost < 1) {
throw new Error('bcrypt difficulty must be an integer >= 1');
}
delete this._options.pgstore;
var self = this;
this._client.connect(function(err, client) {
if(err) {
throw new Error('Could not connect to Postgres database, with error : ' + err);
}
});
} | javascript | function PostgreStore(conString, options) {
if(!conString){
throw new Error('Connection String is missing.');
}
this._options = options || {};
this._options.pgstore = this._options.pgstore || {};
this._difficulty = this._options.pgstore.difficulty || 10;
this._table = this._options.pgstore.table || 'passwordless';
this._client = new pg.Pool({
connectionString: conString,
max: this._options.pgstore.pgPoolSize || 10
});
if(!isNumber(this._difficulty) || this._cost < 1) {
throw new Error('bcrypt difficulty must be an integer >= 1');
}
delete this._options.pgstore;
var self = this;
this._client.connect(function(err, client) {
if(err) {
throw new Error('Could not connect to Postgres database, with error : ' + err);
}
});
} | [
"function",
"PostgreStore",
"(",
"conString",
",",
"options",
")",
"{",
"if",
"(",
"!",
"conString",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Connection String is missing.'",
")",
";",
"}",
"this",
".",
"_options",
"=",
"options",
"||",
"{",
"}",
";",
"this",
".",
"_options",
".",
"pgstore",
"=",
"this",
".",
"_options",
".",
"pgstore",
"||",
"{",
"}",
";",
"this",
".",
"_difficulty",
"=",
"this",
".",
"_options",
".",
"pgstore",
".",
"difficulty",
"||",
"10",
";",
"this",
".",
"_table",
"=",
"this",
".",
"_options",
".",
"pgstore",
".",
"table",
"||",
"'passwordless'",
";",
"this",
".",
"_client",
"=",
"new",
"pg",
".",
"Pool",
"(",
"{",
"connectionString",
":",
"conString",
",",
"max",
":",
"this",
".",
"_options",
".",
"pgstore",
".",
"pgPoolSize",
"||",
"10",
"}",
")",
";",
"if",
"(",
"!",
"isNumber",
"(",
"this",
".",
"_difficulty",
")",
"||",
"this",
".",
"_cost",
"<",
"1",
")",
"{",
"throw",
"new",
"Error",
"(",
"'bcrypt difficulty must be an integer >= 1'",
")",
";",
"}",
"delete",
"this",
".",
"_options",
".",
"pgstore",
";",
"var",
"self",
"=",
"this",
";",
"this",
".",
"_client",
".",
"connect",
"(",
"function",
"(",
"err",
",",
"client",
")",
"{",
"if",
"(",
"err",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Could not connect to Postgres database, with error : '",
"+",
"err",
")",
";",
"}",
"}",
")",
";",
"}"
] | Constructor of PostgreStore
@param {String} conString URI as defined by the PostgreSQL specification. Please
check the documentation for details:
https://github.com/brianc/node-postgres
@param {Object} [options] Combines both the options for the PostgreClient as well
as the options for PostgreStore. For the PostgreClient options please refer back to
the documentation. PostgreStore understands the following options:
(1) { pgstore: { difficulty: integer }} to change the bcrypt difficulty. Defaults to: 10
(1) { pgstore: { table: string }} to change the name of the table used. Defaults to: 'passwordless'
(2) { pgstore: { pgPoolSize: integer }} to change the pool size of PostgreSQL client. Defaults to: 10
@constructor | [
"Constructor",
"of",
"PostgreStore"
] | feb17613cf4dad8ebfabba54e146d0bc14b390d0 | https://github.com/Battochon/passwordless-postgrestore/blob/feb17613cf4dad8ebfabba54e146d0bc14b390d0/lib/postgrestore.js#L21-L48 | train |
grasshopper-cms/grasshopper-api-js | lib/routes/google.js | oauth | function oauth(httpRequest, httpResponse){
var code = httpRequest.query.code,
redirectUrl = _.has(grasshopper.config.identities, 'google') ? grasshopper.config.identities.google.redirectUrl : 'defaultRoute';
grasshopper.auth('Google', { code: code })
.then(function(token) {
httpRequest.session.token = new Buffer(token).toString('base64');
httpRequest.session.save(function() {
httpResponse.redirect(redirectUrl+'/'+ httpRequest.session.token);
});
})
.fail(function(err){
httpResponse.redirect(redirectUrl+'/error='+ err.message);
});
} | javascript | function oauth(httpRequest, httpResponse){
var code = httpRequest.query.code,
redirectUrl = _.has(grasshopper.config.identities, 'google') ? grasshopper.config.identities.google.redirectUrl : 'defaultRoute';
grasshopper.auth('Google', { code: code })
.then(function(token) {
httpRequest.session.token = new Buffer(token).toString('base64');
httpRequest.session.save(function() {
httpResponse.redirect(redirectUrl+'/'+ httpRequest.session.token);
});
})
.fail(function(err){
httpResponse.redirect(redirectUrl+'/error='+ err.message);
});
} | [
"function",
"oauth",
"(",
"httpRequest",
",",
"httpResponse",
")",
"{",
"var",
"code",
"=",
"httpRequest",
".",
"query",
".",
"code",
",",
"redirectUrl",
"=",
"_",
".",
"has",
"(",
"grasshopper",
".",
"config",
".",
"identities",
",",
"'google'",
")",
"?",
"grasshopper",
".",
"config",
".",
"identities",
".",
"google",
".",
"redirectUrl",
":",
"'defaultRoute'",
";",
"grasshopper",
".",
"auth",
"(",
"'Google'",
",",
"{",
"code",
":",
"code",
"}",
")",
".",
"then",
"(",
"function",
"(",
"token",
")",
"{",
"httpRequest",
".",
"session",
".",
"token",
"=",
"new",
"Buffer",
"(",
"token",
")",
".",
"toString",
"(",
"'base64'",
")",
";",
"httpRequest",
".",
"session",
".",
"save",
"(",
"function",
"(",
")",
"{",
"httpResponse",
".",
"redirect",
"(",
"redirectUrl",
"+",
"'/'",
"+",
"httpRequest",
".",
"session",
".",
"token",
")",
";",
"}",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
"err",
")",
"{",
"httpResponse",
".",
"redirect",
"(",
"redirectUrl",
"+",
"'/error='",
"+",
"err",
".",
"message",
")",
";",
"}",
")",
";",
"}"
] | Method will accept the oauth callback from google, run authentication, then redirect the user to the page that accepts the token. | [
"Method",
"will",
"accept",
"the",
"oauth",
"callback",
"from",
"google",
"run",
"authentication",
"then",
"redirect",
"the",
"user",
"to",
"the",
"page",
"that",
"accepts",
"the",
"token",
"."
] | 05a952b8b65e3a66c8a27f5d84699ee5cf02844d | https://github.com/grasshopper-cms/grasshopper-api-js/blob/05a952b8b65e3a66c8a27f5d84699ee5cf02844d/lib/routes/google.js#L24-L42 | train |
grasshopper-cms/grasshopper-api-js | lib/routes/google.js | url | function url(httpRequest, httpResponse) {
var response = new Response(httpResponse);
grasshopper.googleAuthUrl()
.then(function(url) {
response.writeSuccess(url);
})
.fail(function(message) {
var err = {
code : 400,
message : message
};
response.writeError(err);
})
.done();
} | javascript | function url(httpRequest, httpResponse) {
var response = new Response(httpResponse);
grasshopper.googleAuthUrl()
.then(function(url) {
response.writeSuccess(url);
})
.fail(function(message) {
var err = {
code : 400,
message : message
};
response.writeError(err);
})
.done();
} | [
"function",
"url",
"(",
"httpRequest",
",",
"httpResponse",
")",
"{",
"var",
"response",
"=",
"new",
"Response",
"(",
"httpResponse",
")",
";",
"grasshopper",
".",
"googleAuthUrl",
"(",
")",
".",
"then",
"(",
"function",
"(",
"url",
")",
"{",
"response",
".",
"writeSuccess",
"(",
"url",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
"message",
")",
"{",
"var",
"err",
"=",
"{",
"code",
":",
"400",
",",
"message",
":",
"message",
"}",
";",
"response",
".",
"writeError",
"(",
"err",
")",
";",
"}",
")",
".",
"done",
"(",
")",
";",
"}"
] | Method will return a google auth url. | [
"Method",
"will",
"return",
"a",
"google",
"auth",
"url",
"."
] | 05a952b8b65e3a66c8a27f5d84699ee5cf02844d | https://github.com/grasshopper-cms/grasshopper-api-js/blob/05a952b8b65e3a66c8a27f5d84699ee5cf02844d/lib/routes/google.js#L47-L63 | train |
grasshopper-cms/grasshopper-api-js | lib/routes/token.js | parseHeader | function parseHeader(authHeader, callback){
try {
var parts=authHeader.split(/:/),
username=parts[0],
password=parts[1];
callback(null, {username: username, password: password});
}
catch(ex){
callback(ex);
}
} | javascript | function parseHeader(authHeader, callback){
try {
var parts=authHeader.split(/:/),
username=parts[0],
password=parts[1];
callback(null, {username: username, password: password});
}
catch(ex){
callback(ex);
}
} | [
"function",
"parseHeader",
"(",
"authHeader",
",",
"callback",
")",
"{",
"try",
"{",
"var",
"parts",
"=",
"authHeader",
".",
"split",
"(",
"/",
":",
"/",
")",
",",
"username",
"=",
"parts",
"[",
"0",
"]",
",",
"password",
"=",
"parts",
"[",
"1",
"]",
";",
"callback",
"(",
"null",
",",
"{",
"username",
":",
"username",
",",
"password",
":",
"password",
"}",
")",
";",
"}",
"catch",
"(",
"ex",
")",
"{",
"callback",
"(",
"ex",
")",
";",
"}",
"}"
] | Method will pull out the username and password out of the auth header.
@param authHeader String found in the HTTP authentication header.
@param callback | [
"Method",
"will",
"pull",
"out",
"the",
"username",
"and",
"password",
"out",
"of",
"the",
"auth",
"header",
"."
] | 05a952b8b65e3a66c8a27f5d84699ee5cf02844d | https://github.com/grasshopper-cms/grasshopper-api-js/blob/05a952b8b65e3a66c8a27f5d84699ee5cf02844d/lib/routes/token.js#L19-L30 | train |
newrelic/yakaa | https.js | createConnection | function createConnection(port, host, options) {
if (isObject(port)) {
options = port;
}
else if (isObject(host)) {
options = host;
}
else if (isObject(options)) {
options = options;
}
else {
options = {};
}
if (isNumber(port)) {
options.port = port;
}
if (isString(host)) {
options.host = host;
}
debug('createConnection', options);
return tls.connect(options);
} | javascript | function createConnection(port, host, options) {
if (isObject(port)) {
options = port;
}
else if (isObject(host)) {
options = host;
}
else if (isObject(options)) {
options = options;
}
else {
options = {};
}
if (isNumber(port)) {
options.port = port;
}
if (isString(host)) {
options.host = host;
}
debug('createConnection', options);
return tls.connect(options);
} | [
"function",
"createConnection",
"(",
"port",
",",
"host",
",",
"options",
")",
"{",
"if",
"(",
"isObject",
"(",
"port",
")",
")",
"{",
"options",
"=",
"port",
";",
"}",
"else",
"if",
"(",
"isObject",
"(",
"host",
")",
")",
"{",
"options",
"=",
"host",
";",
"}",
"else",
"if",
"(",
"isObject",
"(",
"options",
")",
")",
"{",
"options",
"=",
"options",
";",
"}",
"else",
"{",
"options",
"=",
"{",
"}",
";",
"}",
"if",
"(",
"isNumber",
"(",
"port",
")",
")",
"{",
"options",
".",
"port",
"=",
"port",
";",
"}",
"if",
"(",
"isString",
"(",
"host",
")",
")",
"{",
"options",
".",
"host",
"=",
"host",
";",
"}",
"debug",
"(",
"'createConnection'",
",",
"options",
")",
";",
"return",
"tls",
".",
"connect",
"(",
"options",
")",
";",
"}"
] | HTTPS agents. | [
"HTTPS",
"agents",
"."
] | 8574311a6e35da5122eecef145df386eaa4a6d5e | https://github.com/newrelic/yakaa/blob/8574311a6e35da5122eecef145df386eaa4a6d5e/https.js#L43-L67 | train |
BKWLD/vue-balance-text | index.js | bind | function bind(el, _ref) {
var modifiers = _ref.modifiers;
var target;
// Support children's modifier
target = modifiers.children ? Array.from(el.children) : el;
// Add balance text to the element
Vue.nextTick(function () {
return balanceText(target, {
watch: true
});
});
// Manually fire again later, like after styles are injected by Webpack
return setTimeout(function () {
return balanceText(target);
}, 300);
} | javascript | function bind(el, _ref) {
var modifiers = _ref.modifiers;
var target;
// Support children's modifier
target = modifiers.children ? Array.from(el.children) : el;
// Add balance text to the element
Vue.nextTick(function () {
return balanceText(target, {
watch: true
});
});
// Manually fire again later, like after styles are injected by Webpack
return setTimeout(function () {
return balanceText(target);
}, 300);
} | [
"function",
"bind",
"(",
"el",
",",
"_ref",
")",
"{",
"var",
"modifiers",
"=",
"_ref",
".",
"modifiers",
";",
"var",
"target",
";",
"target",
"=",
"modifiers",
".",
"children",
"?",
"Array",
".",
"from",
"(",
"el",
".",
"children",
")",
":",
"el",
";",
"Vue",
".",
"nextTick",
"(",
"function",
"(",
")",
"{",
"return",
"balanceText",
"(",
"target",
",",
"{",
"watch",
":",
"true",
"}",
")",
";",
"}",
")",
";",
"return",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"return",
"balanceText",
"(",
"target",
")",
";",
"}",
",",
"300",
")",
";",
"}"
] | Add balance text to the element | [
"Add",
"balance",
"text",
"to",
"the",
"element"
] | 86e00b5fbef3d38b7d180cd89b98b66757975010 | https://github.com/BKWLD/vue-balance-text/blob/86e00b5fbef3d38b7d180cd89b98b66757975010/index.js#L17-L35 | train |
BKWLD/vue-balance-text | index.js | componentUpdated | function componentUpdated(el, _ref2) {
var modifiers = _ref2.modifiers;
var target;
target = modifiers.children ? Array.from(el.children) : el;
return balanceText(target);
} | javascript | function componentUpdated(el, _ref2) {
var modifiers = _ref2.modifiers;
var target;
target = modifiers.children ? Array.from(el.children) : el;
return balanceText(target);
} | [
"function",
"componentUpdated",
"(",
"el",
",",
"_ref2",
")",
"{",
"var",
"modifiers",
"=",
"_ref2",
".",
"modifiers",
";",
"var",
"target",
";",
"target",
"=",
"modifiers",
".",
"children",
"?",
"Array",
".",
"from",
"(",
"el",
".",
"children",
")",
":",
"el",
";",
"return",
"balanceText",
"(",
"target",
")",
";",
"}"
] | Update when contents change | [
"Update",
"when",
"contents",
"change"
] | 86e00b5fbef3d38b7d180cd89b98b66757975010 | https://github.com/BKWLD/vue-balance-text/blob/86e00b5fbef3d38b7d180cd89b98b66757975010/index.js#L37-L43 | train |
JakubMrozek/eet | lib/validate.js | date | function date (value) {
if (Object.prototype.toString.call(value) !== '[object Date]' || isNaN(value)) {
throw new Error(`Value '${value}' is not a date object.`)
}
} | javascript | function date (value) {
if (Object.prototype.toString.call(value) !== '[object Date]' || isNaN(value)) {
throw new Error(`Value '${value}' is not a date object.`)
}
} | [
"function",
"date",
"(",
"value",
")",
"{",
"if",
"(",
"Object",
".",
"prototype",
".",
"toString",
".",
"call",
"(",
"value",
")",
"!==",
"'[object Date]'",
"||",
"isNaN",
"(",
"value",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"value",
"}",
"`",
")",
"}",
"}"
] | Validace data. | [
"Validace",
"data",
"."
] | 28a8f0b6743308c705eb0c17e985e0ed065b692e | https://github.com/JakubMrozek/eet/blob/28a8f0b6743308c705eb0c17e985e0ed065b692e/lib/validate.js#L67-L71 | train |
JakubMrozek/eet | lib/validate.js | httpResponse | function httpResponse (response) {
if (!response) {
throw new Error('Unable to parse response.')
}
const errorAttrs = response.Chyba && response.Chyba.attributes
if (errorAttrs) {
throw new Error(`${response.Chyba.$value} (${errorAttrs.kod})`)
}
const body = response.Potvrzeni && response.Potvrzeni.attributes
const header = response.Hlavicka && response.Hlavicka.attributes
if (!body || !header) {
throw new Error('Unable to read response.')
}
} | javascript | function httpResponse (response) {
if (!response) {
throw new Error('Unable to parse response.')
}
const errorAttrs = response.Chyba && response.Chyba.attributes
if (errorAttrs) {
throw new Error(`${response.Chyba.$value} (${errorAttrs.kod})`)
}
const body = response.Potvrzeni && response.Potvrzeni.attributes
const header = response.Hlavicka && response.Hlavicka.attributes
if (!body || !header) {
throw new Error('Unable to read response.')
}
} | [
"function",
"httpResponse",
"(",
"response",
")",
"{",
"if",
"(",
"!",
"response",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Unable to parse response.'",
")",
"}",
"const",
"errorAttrs",
"=",
"response",
".",
"Chyba",
"&&",
"response",
".",
"Chyba",
".",
"attributes",
"if",
"(",
"errorAttrs",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"response",
".",
"Chyba",
".",
"$value",
"}",
"${",
"errorAttrs",
".",
"kod",
"}",
"`",
")",
"}",
"const",
"body",
"=",
"response",
".",
"Potvrzeni",
"&&",
"response",
".",
"Potvrzeni",
".",
"attributes",
"const",
"header",
"=",
"response",
".",
"Hlavicka",
"&&",
"response",
".",
"Hlavicka",
".",
"attributes",
"if",
"(",
"!",
"body",
"||",
"!",
"header",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Unable to read response.'",
")",
"}",
"}"
] | Zpracuje chybnou odpoved. | [
"Zpracuje",
"chybnou",
"odpoved",
"."
] | 28a8f0b6743308c705eb0c17e985e0ed065b692e | https://github.com/JakubMrozek/eet/blob/28a8f0b6743308c705eb0c17e985e0ed065b692e/lib/validate.js#L98-L111 | train |
grasshopper-cms/grasshopper-api-js | lib/routes/social/pinterest.js | _createSocialAccount | function _createSocialAccount(){
return BB
.bind(this)
.then(function() {
return grasshopper.auth('Pinterest', this.params);
})
.then(function(token) {
this.req.session.token = new Buffer(token).toString('base64');
this.req.session.save();
});
} | javascript | function _createSocialAccount(){
return BB
.bind(this)
.then(function() {
return grasshopper.auth('Pinterest', this.params);
})
.then(function(token) {
this.req.session.token = new Buffer(token).toString('base64');
this.req.session.save();
});
} | [
"function",
"_createSocialAccount",
"(",
")",
"{",
"return",
"BB",
".",
"bind",
"(",
"this",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"return",
"grasshopper",
".",
"auth",
"(",
"'Pinterest'",
",",
"this",
".",
"params",
")",
";",
"}",
")",
".",
"then",
"(",
"function",
"(",
"token",
")",
"{",
"this",
".",
"req",
".",
"session",
".",
"token",
"=",
"new",
"Buffer",
"(",
"token",
")",
".",
"toString",
"(",
"'base64'",
")",
";",
"this",
".",
"req",
".",
"session",
".",
"save",
"(",
")",
";",
"}",
")",
";",
"}"
] | Function that will create a user in our system. the `auth` function will auto-create a user if there is not already one in the system. | [
"Function",
"that",
"will",
"create",
"a",
"user",
"in",
"our",
"system",
".",
"the",
"auth",
"function",
"will",
"auto",
"-",
"create",
"a",
"user",
"if",
"there",
"is",
"not",
"already",
"one",
"in",
"the",
"system",
"."
] | 05a952b8b65e3a66c8a27f5d84699ee5cf02844d | https://github.com/grasshopper-cms/grasshopper-api-js/blob/05a952b8b65e3a66c8a27f5d84699ee5cf02844d/lib/routes/social/pinterest.js#L66-L76 | train |
grasshopper-cms/grasshopper-api-js | lib/routes/social/pinterest.js | _linkSocialAccount | function _linkSocialAccount(){
return BB.bind(this)
.then(_loadUserFromToken)
.then(_getUserSocialDetails)
.then(_linkIdentity)
.catch(function(){
return _createSocialAccount.call(this); // Could not link account. Create one instead.
});
} | javascript | function _linkSocialAccount(){
return BB.bind(this)
.then(_loadUserFromToken)
.then(_getUserSocialDetails)
.then(_linkIdentity)
.catch(function(){
return _createSocialAccount.call(this); // Could not link account. Create one instead.
});
} | [
"function",
"_linkSocialAccount",
"(",
")",
"{",
"return",
"BB",
".",
"bind",
"(",
"this",
")",
".",
"then",
"(",
"_loadUserFromToken",
")",
".",
"then",
"(",
"_getUserSocialDetails",
")",
".",
"then",
"(",
"_linkIdentity",
")",
".",
"catch",
"(",
"function",
"(",
")",
"{",
"return",
"_createSocialAccount",
".",
"call",
"(",
"this",
")",
";",
"}",
")",
";",
"}"
] | Function will link an existing account loading the current user from their token. We first load the user from token, then link identities. If there is an issue, we try to create the user. | [
"Function",
"will",
"link",
"an",
"existing",
"account",
"loading",
"the",
"current",
"user",
"from",
"their",
"token",
".",
"We",
"first",
"load",
"the",
"user",
"from",
"token",
"then",
"link",
"identities",
".",
"If",
"there",
"is",
"an",
"issue",
"we",
"try",
"to",
"create",
"the",
"user",
"."
] | 05a952b8b65e3a66c8a27f5d84699ee5cf02844d | https://github.com/grasshopper-cms/grasshopper-api-js/blob/05a952b8b65e3a66c8a27f5d84699ee5cf02844d/lib/routes/social/pinterest.js#L81-L90 | train |
grasshopper-cms/grasshopper-api-js | lib/routes/social/pinterest.js | _getUserSocialDetails | function _getUserSocialDetails(){
return BB
.bind(this)
.then(function() {
return pinterest
.query()
.get('me/?fields=id,first_name,last_name,url,username,image&access_token=' + this.params.access_token)
.request();
})
.then(function(res){
this.socialUserInfo = res[1].data;
});
} | javascript | function _getUserSocialDetails(){
return BB
.bind(this)
.then(function() {
return pinterest
.query()
.get('me/?fields=id,first_name,last_name,url,username,image&access_token=' + this.params.access_token)
.request();
})
.then(function(res){
this.socialUserInfo = res[1].data;
});
} | [
"function",
"_getUserSocialDetails",
"(",
")",
"{",
"return",
"BB",
".",
"bind",
"(",
"this",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"return",
"pinterest",
".",
"query",
"(",
")",
".",
"get",
"(",
"'me/?fields=id,first_name,last_name,url,username,image&access_token='",
"+",
"this",
".",
"params",
".",
"access_token",
")",
".",
"request",
"(",
")",
";",
"}",
")",
".",
"then",
"(",
"function",
"(",
"res",
")",
"{",
"this",
".",
"socialUserInfo",
"=",
"res",
"[",
"1",
"]",
".",
"data",
";",
"}",
")",
";",
"}"
] | Pinterest doesn't return any user info back with login. So go get some basic info so we can link the account. | [
"Pinterest",
"doesn",
"t",
"return",
"any",
"user",
"info",
"back",
"with",
"login",
".",
"So",
"go",
"get",
"some",
"basic",
"info",
"so",
"we",
"can",
"link",
"the",
"account",
"."
] | 05a952b8b65e3a66c8a27f5d84699ee5cf02844d | https://github.com/grasshopper-cms/grasshopper-api-js/blob/05a952b8b65e3a66c8a27f5d84699ee5cf02844d/lib/routes/social/pinterest.js#L105-L117 | train |
grasshopper-cms/grasshopper-api-js | lib/routes/social/pinterest.js | _linkIdentity | function _linkIdentity() {
var identityOptions = {
id: this.socialUserInfo.id,
accessToken: this.params.access_token,
screen_name: this.socialUserInfo.username
};
return BB.resolve(grasshopper.request(this.token).users.linkIdentity(this.user._id.toString(), 'pinterest', identityOptions));
} | javascript | function _linkIdentity() {
var identityOptions = {
id: this.socialUserInfo.id,
accessToken: this.params.access_token,
screen_name: this.socialUserInfo.username
};
return BB.resolve(grasshopper.request(this.token).users.linkIdentity(this.user._id.toString(), 'pinterest', identityOptions));
} | [
"function",
"_linkIdentity",
"(",
")",
"{",
"var",
"identityOptions",
"=",
"{",
"id",
":",
"this",
".",
"socialUserInfo",
".",
"id",
",",
"accessToken",
":",
"this",
".",
"params",
".",
"access_token",
",",
"screen_name",
":",
"this",
".",
"socialUserInfo",
".",
"username",
"}",
";",
"return",
"BB",
".",
"resolve",
"(",
"grasshopper",
".",
"request",
"(",
"this",
".",
"token",
")",
".",
"users",
".",
"linkIdentity",
"(",
"this",
".",
"user",
".",
"_id",
".",
"toString",
"(",
")",
",",
"'pinterest'",
",",
"identityOptions",
")",
")",
";",
"}"
] | Utility function to link a user's pinterest info to the current user. | [
"Utility",
"function",
"to",
"link",
"a",
"user",
"s",
"pinterest",
"info",
"to",
"the",
"current",
"user",
"."
] | 05a952b8b65e3a66c8a27f5d84699ee5cf02844d | https://github.com/grasshopper-cms/grasshopper-api-js/blob/05a952b8b65e3a66c8a27f5d84699ee5cf02844d/lib/routes/social/pinterest.js#L120-L128 | train |
wmfs/tymly-core | lib/boot/refs/first-pass/index.js | firstPass | function firstPass (loadedComponents, messages) {
messages.heading('Reference resolution - first pass')
const components = loadedComponents.blueprintComponents
const tymlyRefs = loadedComponents.blueprintRefs
const resolutions = findFirstPassResolutions(tymlyRefs, components)
if (!resolutions) {
messages.subHeading('Nothing to resolve')
return
}
resolveResolutions(resolutions, components, messages)
} | javascript | function firstPass (loadedComponents, messages) {
messages.heading('Reference resolution - first pass')
const components = loadedComponents.blueprintComponents
const tymlyRefs = loadedComponents.blueprintRefs
const resolutions = findFirstPassResolutions(tymlyRefs, components)
if (!resolutions) {
messages.subHeading('Nothing to resolve')
return
}
resolveResolutions(resolutions, components, messages)
} | [
"function",
"firstPass",
"(",
"loadedComponents",
",",
"messages",
")",
"{",
"messages",
".",
"heading",
"(",
"'Reference resolution - first pass'",
")",
"const",
"components",
"=",
"loadedComponents",
".",
"blueprintComponents",
"const",
"tymlyRefs",
"=",
"loadedComponents",
".",
"blueprintRefs",
"const",
"resolutions",
"=",
"findFirstPassResolutions",
"(",
"tymlyRefs",
",",
"components",
")",
"if",
"(",
"!",
"resolutions",
")",
"{",
"messages",
".",
"subHeading",
"(",
"'Nothing to resolve'",
")",
"return",
"}",
"resolveResolutions",
"(",
"resolutions",
",",
"components",
",",
"messages",
")",
"}"
] | First pass through the references. None of the services have yet been booted, but we can resolve static references | [
"First",
"pass",
"through",
"the",
"references",
".",
"None",
"of",
"the",
"services",
"have",
"yet",
"been",
"booted",
"but",
"we",
"can",
"resolve",
"static",
"references"
] | 7f05f7b8c2a1c09b03bb4a6ac34013ff4c9edfee | https://github.com/wmfs/tymly-core/blob/7f05f7b8c2a1c09b03bb4a6ac34013ff4c9edfee/lib/boot/refs/first-pass/index.js#L6-L20 | train |
benjamn/arson | index.js | getArrayOfHoles | function getArrayOfHoles(length) {
var holyLen = HOLY_ARRAY.length;
if (length > holyLen) {
HOLY_ARRAY.length = length;
for (var i = holyLen; i < length; ++i) {
HOLY_ARRAY[i] = ARRAY_HOLE_INDEX;
}
}
return HOLY_ARRAY.slice(0, length);
} | javascript | function getArrayOfHoles(length) {
var holyLen = HOLY_ARRAY.length;
if (length > holyLen) {
HOLY_ARRAY.length = length;
for (var i = holyLen; i < length; ++i) {
HOLY_ARRAY[i] = ARRAY_HOLE_INDEX;
}
}
return HOLY_ARRAY.slice(0, length);
} | [
"function",
"getArrayOfHoles",
"(",
"length",
")",
"{",
"var",
"holyLen",
"=",
"HOLY_ARRAY",
".",
"length",
";",
"if",
"(",
"length",
">",
"holyLen",
")",
"{",
"HOLY_ARRAY",
".",
"length",
"=",
"length",
";",
"for",
"(",
"var",
"i",
"=",
"holyLen",
";",
"i",
"<",
"length",
";",
"++",
"i",
")",
"{",
"HOLY_ARRAY",
"[",
"i",
"]",
"=",
"ARRAY_HOLE_INDEX",
";",
"}",
"}",
"return",
"HOLY_ARRAY",
".",
"slice",
"(",
"0",
",",
"length",
")",
";",
"}"
] | Returns an array of the given length filled with ARRAY_HOLE_INDEX. | [
"Returns",
"an",
"array",
"of",
"the",
"given",
"length",
"filled",
"with",
"ARRAY_HOLE_INDEX",
"."
] | aeee18764c9901759762d2f011589caea9e768e1 | https://github.com/benjamn/arson/blob/aeee18764c9901759762d2f011589caea9e768e1/index.js#L39-L49 | train |
canjs/can-construct | can-construct.js | function (what, oldProps, propName, val) {
Object.defineProperty(what, propName, {value: val, configurable: true, enumerable: true, writable: true});
} | javascript | function (what, oldProps, propName, val) {
Object.defineProperty(what, propName, {value: val, configurable: true, enumerable: true, writable: true});
} | [
"function",
"(",
"what",
",",
"oldProps",
",",
"propName",
",",
"val",
")",
"{",
"Object",
".",
"defineProperty",
"(",
"what",
",",
"propName",
",",
"{",
"value",
":",
"val",
",",
"configurable",
":",
"true",
",",
"enumerable",
":",
"true",
",",
"writable",
":",
"true",
"}",
")",
";",
"}"
] | used for overwriting a single property. this should be used for patching other objects the super plugin overwrites this | [
"used",
"for",
"overwriting",
"a",
"single",
"property",
".",
"this",
"should",
"be",
"used",
"for",
"patching",
"other",
"objects",
"the",
"super",
"plugin",
"overwrites",
"this"
] | 0c64cc2ccf917d705070d51416ac8cd1bda35259 | https://github.com/canjs/can-construct/blob/0c64cc2ccf917d705070d51416ac8cd1bda35259/can-construct.js#L334-L336 | train |
|
canjs/can-construct | can-construct.js | init | function init() {
/* jshint validthis: true */
// All construction is actually done in the init method.
if (!initializing) {
//!steal-remove-start
if(process.env.NODE_ENV !== 'production') {
if(!this || (this.constructor !== Constructor) &&
// We are being called without `new` or we are extending.
arguments.length && Constructor.constructorExtends) {
dev.warn('can/construct/construct.js: extending a Construct without calling extend');
}
}
//!steal-remove-end
return (!this || this.constructor !== Constructor) &&
// We are being called without `new` or we are extending.
arguments.length && Constructor.constructorExtends ? Constructor.extend.apply(Constructor, arguments) :
// We are being called with `new`.
Constructor.newInstance.apply(Constructor, arguments);
}
} | javascript | function init() {
/* jshint validthis: true */
// All construction is actually done in the init method.
if (!initializing) {
//!steal-remove-start
if(process.env.NODE_ENV !== 'production') {
if(!this || (this.constructor !== Constructor) &&
// We are being called without `new` or we are extending.
arguments.length && Constructor.constructorExtends) {
dev.warn('can/construct/construct.js: extending a Construct without calling extend');
}
}
//!steal-remove-end
return (!this || this.constructor !== Constructor) &&
// We are being called without `new` or we are extending.
arguments.length && Constructor.constructorExtends ? Constructor.extend.apply(Constructor, arguments) :
// We are being called with `new`.
Constructor.newInstance.apply(Constructor, arguments);
}
} | [
"function",
"init",
"(",
")",
"{",
"if",
"(",
"!",
"initializing",
")",
"{",
"if",
"(",
"process",
".",
"env",
".",
"NODE_ENV",
"!==",
"'production'",
")",
"{",
"if",
"(",
"!",
"this",
"||",
"(",
"this",
".",
"constructor",
"!==",
"Constructor",
")",
"&&",
"arguments",
".",
"length",
"&&",
"Constructor",
".",
"constructorExtends",
")",
"{",
"dev",
".",
"warn",
"(",
"'can/construct/construct.js: extending a Construct without calling extend'",
")",
";",
"}",
"}",
"return",
"(",
"!",
"this",
"||",
"this",
".",
"constructor",
"!==",
"Constructor",
")",
"&&",
"arguments",
".",
"length",
"&&",
"Constructor",
".",
"constructorExtends",
"?",
"Constructor",
".",
"extend",
".",
"apply",
"(",
"Constructor",
",",
"arguments",
")",
":",
"Constructor",
".",
"newInstance",
".",
"apply",
"(",
"Constructor",
",",
"arguments",
")",
";",
"}",
"}"
] | !steal-remove-end The dummy class constructor. | [
"!steal",
"-",
"remove",
"-",
"end",
"The",
"dummy",
"class",
"constructor",
"."
] | 0c64cc2ccf917d705070d51416ac8cd1bda35259 | https://github.com/canjs/can-construct/blob/0c64cc2ccf917d705070d51416ac8cd1bda35259/can-construct.js#L642-L662 | train |
grasshopper-cms/grasshopper-core-nodejs | lib/event/filter.js | findMatch | function findMatch(filters, listener){
var handlers = [],
isMatch = true;
if( !_.isUndefined(listener.filters.nodes) && listener.filters.nodes.length > 0 ) {
isMatch = !_.isUndefined( _.find( listener.filters.nodes , function(node) {
return (node === filters.node || node === '*');
} ) );
}
if ( isMatch && !_.isUndefined(listener.filters.types) && listener.filters.types.length > 0 ) {
isMatch = !_.isUndefined( _.find( listener.filters.types , function(type) {
return (type === filters.type || type === '*');
} ) );
}
if( isMatch && !_.isUndefined(listener.filters.contentids) && listener.filters.contentids.length > 0 ) {
isMatch = !_.isUndefined( _.find( listener.filters.contentids , function(contentid) {
return (contentid === filters.contentid || contentid === '*');
} ) );
}
if( isMatch && !_.isUndefined(listener.filters.system) && listener.filters.system.length > 0 ) {
isMatch = !_.isUndefined( _.find( listener.filters.system , function(val) {
return (val === filters.system || val === '*');
} ) );
}
// If we still have a match return handlers attached to the listener
if( isMatch ) {
handlers = listener.handlers;
}
return handlers;
} | javascript | function findMatch(filters, listener){
var handlers = [],
isMatch = true;
if( !_.isUndefined(listener.filters.nodes) && listener.filters.nodes.length > 0 ) {
isMatch = !_.isUndefined( _.find( listener.filters.nodes , function(node) {
return (node === filters.node || node === '*');
} ) );
}
if ( isMatch && !_.isUndefined(listener.filters.types) && listener.filters.types.length > 0 ) {
isMatch = !_.isUndefined( _.find( listener.filters.types , function(type) {
return (type === filters.type || type === '*');
} ) );
}
if( isMatch && !_.isUndefined(listener.filters.contentids) && listener.filters.contentids.length > 0 ) {
isMatch = !_.isUndefined( _.find( listener.filters.contentids , function(contentid) {
return (contentid === filters.contentid || contentid === '*');
} ) );
}
if( isMatch && !_.isUndefined(listener.filters.system) && listener.filters.system.length > 0 ) {
isMatch = !_.isUndefined( _.find( listener.filters.system , function(val) {
return (val === filters.system || val === '*');
} ) );
}
// If we still have a match return handlers attached to the listener
if( isMatch ) {
handlers = listener.handlers;
}
return handlers;
} | [
"function",
"findMatch",
"(",
"filters",
",",
"listener",
")",
"{",
"var",
"handlers",
"=",
"[",
"]",
",",
"isMatch",
"=",
"true",
";",
"if",
"(",
"!",
"_",
".",
"isUndefined",
"(",
"listener",
".",
"filters",
".",
"nodes",
")",
"&&",
"listener",
".",
"filters",
".",
"nodes",
".",
"length",
">",
"0",
")",
"{",
"isMatch",
"=",
"!",
"_",
".",
"isUndefined",
"(",
"_",
".",
"find",
"(",
"listener",
".",
"filters",
".",
"nodes",
",",
"function",
"(",
"node",
")",
"{",
"return",
"(",
"node",
"===",
"filters",
".",
"node",
"||",
"node",
"===",
"'*'",
")",
";",
"}",
")",
")",
";",
"}",
"if",
"(",
"isMatch",
"&&",
"!",
"_",
".",
"isUndefined",
"(",
"listener",
".",
"filters",
".",
"types",
")",
"&&",
"listener",
".",
"filters",
".",
"types",
".",
"length",
">",
"0",
")",
"{",
"isMatch",
"=",
"!",
"_",
".",
"isUndefined",
"(",
"_",
".",
"find",
"(",
"listener",
".",
"filters",
".",
"types",
",",
"function",
"(",
"type",
")",
"{",
"return",
"(",
"type",
"===",
"filters",
".",
"type",
"||",
"type",
"===",
"'*'",
")",
";",
"}",
")",
")",
";",
"}",
"if",
"(",
"isMatch",
"&&",
"!",
"_",
".",
"isUndefined",
"(",
"listener",
".",
"filters",
".",
"contentids",
")",
"&&",
"listener",
".",
"filters",
".",
"contentids",
".",
"length",
">",
"0",
")",
"{",
"isMatch",
"=",
"!",
"_",
".",
"isUndefined",
"(",
"_",
".",
"find",
"(",
"listener",
".",
"filters",
".",
"contentids",
",",
"function",
"(",
"contentid",
")",
"{",
"return",
"(",
"contentid",
"===",
"filters",
".",
"contentid",
"||",
"contentid",
"===",
"'*'",
")",
";",
"}",
")",
")",
";",
"}",
"if",
"(",
"isMatch",
"&&",
"!",
"_",
".",
"isUndefined",
"(",
"listener",
".",
"filters",
".",
"system",
")",
"&&",
"listener",
".",
"filters",
".",
"system",
".",
"length",
">",
"0",
")",
"{",
"isMatch",
"=",
"!",
"_",
".",
"isUndefined",
"(",
"_",
".",
"find",
"(",
"listener",
".",
"filters",
".",
"system",
",",
"function",
"(",
"val",
")",
"{",
"return",
"(",
"val",
"===",
"filters",
".",
"system",
"||",
"val",
"===",
"'*'",
")",
";",
"}",
")",
")",
";",
"}",
"if",
"(",
"isMatch",
")",
"{",
"handlers",
"=",
"listener",
".",
"handlers",
";",
"}",
"return",
"handlers",
";",
"}"
] | Function will look at the filters that have been passed in to the module through an
emit call and compair them to the filters that are attached to all of the listeners.
If there are matches the function will return an array of event handlers that
match the criteria.
@param filters - Event filters that are passed in through emit
@param listener - Listener that has been registered in the application
@returns {Array} - Array of event handlers that match the filter criteria | [
"Function",
"will",
"look",
"at",
"the",
"filters",
"that",
"have",
"been",
"passed",
"in",
"to",
"the",
"module",
"through",
"an",
"emit",
"call",
"and",
"compair",
"them",
"to",
"the",
"filters",
"that",
"are",
"attached",
"to",
"all",
"of",
"the",
"listeners",
".",
"If",
"there",
"are",
"matches",
"the",
"function",
"will",
"return",
"an",
"array",
"of",
"event",
"handlers",
"that",
"match",
"the",
"criteria",
"."
] | 8fabc3bfc5b18855ead443db0644608a277d0ea0 | https://github.com/grasshopper-cms/grasshopper-core-nodejs/blob/8fabc3bfc5b18855ead443db0644608a277d0ea0/lib/event/filter.js#L17-L51 | train |
grasshopper-cms/grasshopper-core-nodejs | lib/event/filter.js | filterListeners | function filterListeners (listenerCollection) {
return function(filters) {
var handlers = [];
_.each(listenerCollection, function(listener){
handlers = handlers.concat( findMatch(filters, listener) );
});
return handlers;
};
} | javascript | function filterListeners (listenerCollection) {
return function(filters) {
var handlers = [];
_.each(listenerCollection, function(listener){
handlers = handlers.concat( findMatch(filters, listener) );
});
return handlers;
};
} | [
"function",
"filterListeners",
"(",
"listenerCollection",
")",
"{",
"return",
"function",
"(",
"filters",
")",
"{",
"var",
"handlers",
"=",
"[",
"]",
";",
"_",
".",
"each",
"(",
"listenerCollection",
",",
"function",
"(",
"listener",
")",
"{",
"handlers",
"=",
"handlers",
".",
"concat",
"(",
"findMatch",
"(",
"filters",
",",
"listener",
")",
")",
";",
"}",
")",
";",
"return",
"handlers",
";",
"}",
";",
"}"
] | Function that accepts a collection of listeners and inspects each one to determine
if their handler should be called.
@param listenerCollection
@returns {Function} | [
"Function",
"that",
"accepts",
"a",
"collection",
"of",
"listeners",
"and",
"inspects",
"each",
"one",
"to",
"determine",
"if",
"their",
"handler",
"should",
"be",
"called",
"."
] | 8fabc3bfc5b18855ead443db0644608a277d0ea0 | https://github.com/grasshopper-cms/grasshopper-core-nodejs/blob/8fabc3bfc5b18855ead443db0644608a277d0ea0/lib/event/filter.js#L60-L70 | train |
casetext/fireproof | lib/demux.js | Demux | function Demux(refs, limit) {
if (!(this instanceof Fireproof.Demux)) {
return new Fireproof.Demux(refs);
} else if (arguments.length > 1 && !Array.isArray(refs)) {
refs = Array.prototype.slice.call(arguments, 0);
}
this._limit = (limit !== undefined ? limit : true);
this._refs = refs;
this._positions = refs.reduce(function(positions, ref) {
positions[ref.ref().toString()] = {
name: undefined,
priority: undefined
};
return positions;
}, {});
// we always want there to be a "previous" promise to hang operations from
this._previousPromise = Fireproof.Promise.resolve([]);
this._buffer = [];
} | javascript | function Demux(refs, limit) {
if (!(this instanceof Fireproof.Demux)) {
return new Fireproof.Demux(refs);
} else if (arguments.length > 1 && !Array.isArray(refs)) {
refs = Array.prototype.slice.call(arguments, 0);
}
this._limit = (limit !== undefined ? limit : true);
this._refs = refs;
this._positions = refs.reduce(function(positions, ref) {
positions[ref.ref().toString()] = {
name: undefined,
priority: undefined
};
return positions;
}, {});
// we always want there to be a "previous" promise to hang operations from
this._previousPromise = Fireproof.Promise.resolve([]);
this._buffer = [];
} | [
"function",
"Demux",
"(",
"refs",
",",
"limit",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Fireproof",
".",
"Demux",
")",
")",
"{",
"return",
"new",
"Fireproof",
".",
"Demux",
"(",
"refs",
")",
";",
"}",
"else",
"if",
"(",
"arguments",
".",
"length",
">",
"1",
"&&",
"!",
"Array",
".",
"isArray",
"(",
"refs",
")",
")",
"{",
"refs",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"0",
")",
";",
"}",
"this",
".",
"_limit",
"=",
"(",
"limit",
"!==",
"undefined",
"?",
"limit",
":",
"true",
")",
";",
"this",
".",
"_refs",
"=",
"refs",
";",
"this",
".",
"_positions",
"=",
"refs",
".",
"reduce",
"(",
"function",
"(",
"positions",
",",
"ref",
")",
"{",
"positions",
"[",
"ref",
".",
"ref",
"(",
")",
".",
"toString",
"(",
")",
"]",
"=",
"{",
"name",
":",
"undefined",
",",
"priority",
":",
"undefined",
"}",
";",
"return",
"positions",
";",
"}",
",",
"{",
"}",
")",
";",
"this",
".",
"_previousPromise",
"=",
"Fireproof",
".",
"Promise",
".",
"resolve",
"(",
"[",
"]",
")",
";",
"this",
".",
"_buffer",
"=",
"[",
"]",
";",
"}"
] | A helper object for retrieving sorted Firebase objects from multiple
locations.
@constructor Fireproof.Demux
@static
@param {Array} refs a list of Fireproof object references to draw from.
@param {boolean} [limitToFirst] Whether to use "limitToFirst" to restrict the length
of queries to Firebase. True by default. Set this to false if you want to
control the query more directly by setting it on the objects you pass to refs. | [
"A",
"helper",
"object",
"for",
"retrieving",
"sorted",
"Firebase",
"objects",
"from",
"multiple",
"locations",
"."
] | a568157310d965d2c115e5a3c9e8287fc8fe021b | https://github.com/casetext/fireproof/blob/a568157310d965d2c115e5a3c9e8287fc8fe021b/lib/demux.js#L12-L38 | train |
reddit/node-build | lib/uploadToSentry.js | createRelease | function createRelease(endpoint, version) {
return new Promise(function(resolve, reject) {
superagent
.post(endpoint)
.set(HEADERS)
.send({ version: version })
.end(function(err, res) {
if (!err) {
console.log('Sentry - Pushed release. Version: ' + version);
resolve(res);
} else {
reject(err);
}
});
});
} | javascript | function createRelease(endpoint, version) {
return new Promise(function(resolve, reject) {
superagent
.post(endpoint)
.set(HEADERS)
.send({ version: version })
.end(function(err, res) {
if (!err) {
console.log('Sentry - Pushed release. Version: ' + version);
resolve(res);
} else {
reject(err);
}
});
});
} | [
"function",
"createRelease",
"(",
"endpoint",
",",
"version",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"superagent",
".",
"post",
"(",
"endpoint",
")",
".",
"set",
"(",
"HEADERS",
")",
".",
"send",
"(",
"{",
"version",
":",
"version",
"}",
")",
".",
"end",
"(",
"function",
"(",
"err",
",",
"res",
")",
"{",
"if",
"(",
"!",
"err",
")",
"{",
"console",
".",
"log",
"(",
"'Sentry - Pushed release. Version: '",
"+",
"version",
")",
";",
"resolve",
"(",
"res",
")",
";",
"}",
"else",
"{",
"reject",
"(",
"err",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}"
] | Creates a Sentry release, a versioned collection of compiled js and their
sourcemaps.
@param {String} endpoint
The endpoint this release is being pushed to
@param {String} version
The version for this release | [
"Creates",
"a",
"Sentry",
"release",
"a",
"versioned",
"collection",
"of",
"compiled",
"js",
"and",
"their",
"sourcemaps",
"."
] | af30dc8c637631b177ae33a1984a44ffa839914b | https://github.com/reddit/node-build/blob/af30dc8c637631b177ae33a1984a44ffa839914b/lib/uploadToSentry.js#L20-L35 | train |
reddit/node-build | lib/uploadToSentry.js | uploadFile | function uploadFile(endpoint, releaseVersion, filePath) {
// sentry lets you use the tilde to indicate it just looks at relative locations
// instead of relying on the host/domain.
var IGNORE_DOMAIN = '~';
var staticBase = process.env.STATIC_BASE;
var IGNORE_PATH = staticBase ? url.parse(staticBase).path + '/' : '';
var CONFLICT_CODE = 409;
var fileData = path.parse(filePath);
var fileName = fileData.name + fileData.ext;
var sentryFilePath = IGNORE_DOMAIN + IGNORE_PATH + fileName;
return new Promise(function(resolve, reject) {
superagent
.post(endpoint)
.set(HEADERS)
.attach('file', filePath)
.field('name', sentryFilePath)
.end(function(err, res) {
if (!err) {
console.log('Sentry (release: ' + releaseVersion +
') - Successfully uploaded ' + fileName);
resolve();
} if (err && err.response && err.response.statusCode === CONFLICT_CODE) {
console.log('Sentry (' + releaseVersion + ') - ' + fileName +
' already exists.');
resolve();
} else {
reject(err);
}
});
});
} | javascript | function uploadFile(endpoint, releaseVersion, filePath) {
// sentry lets you use the tilde to indicate it just looks at relative locations
// instead of relying on the host/domain.
var IGNORE_DOMAIN = '~';
var staticBase = process.env.STATIC_BASE;
var IGNORE_PATH = staticBase ? url.parse(staticBase).path + '/' : '';
var CONFLICT_CODE = 409;
var fileData = path.parse(filePath);
var fileName = fileData.name + fileData.ext;
var sentryFilePath = IGNORE_DOMAIN + IGNORE_PATH + fileName;
return new Promise(function(resolve, reject) {
superagent
.post(endpoint)
.set(HEADERS)
.attach('file', filePath)
.field('name', sentryFilePath)
.end(function(err, res) {
if (!err) {
console.log('Sentry (release: ' + releaseVersion +
') - Successfully uploaded ' + fileName);
resolve();
} if (err && err.response && err.response.statusCode === CONFLICT_CODE) {
console.log('Sentry (' + releaseVersion + ') - ' + fileName +
' already exists.');
resolve();
} else {
reject(err);
}
});
});
} | [
"function",
"uploadFile",
"(",
"endpoint",
",",
"releaseVersion",
",",
"filePath",
")",
"{",
"var",
"IGNORE_DOMAIN",
"=",
"'~'",
";",
"var",
"staticBase",
"=",
"process",
".",
"env",
".",
"STATIC_BASE",
";",
"var",
"IGNORE_PATH",
"=",
"staticBase",
"?",
"url",
".",
"parse",
"(",
"staticBase",
")",
".",
"path",
"+",
"'/'",
":",
"''",
";",
"var",
"CONFLICT_CODE",
"=",
"409",
";",
"var",
"fileData",
"=",
"path",
".",
"parse",
"(",
"filePath",
")",
";",
"var",
"fileName",
"=",
"fileData",
".",
"name",
"+",
"fileData",
".",
"ext",
";",
"var",
"sentryFilePath",
"=",
"IGNORE_DOMAIN",
"+",
"IGNORE_PATH",
"+",
"fileName",
";",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"superagent",
".",
"post",
"(",
"endpoint",
")",
".",
"set",
"(",
"HEADERS",
")",
".",
"attach",
"(",
"'file'",
",",
"filePath",
")",
".",
"field",
"(",
"'name'",
",",
"sentryFilePath",
")",
".",
"end",
"(",
"function",
"(",
"err",
",",
"res",
")",
"{",
"if",
"(",
"!",
"err",
")",
"{",
"console",
".",
"log",
"(",
"'Sentry (release: '",
"+",
"releaseVersion",
"+",
"') - Successfully uploaded '",
"+",
"fileName",
")",
";",
"resolve",
"(",
")",
";",
"}",
"if",
"(",
"err",
"&&",
"err",
".",
"response",
"&&",
"err",
".",
"response",
".",
"statusCode",
"===",
"CONFLICT_CODE",
")",
"{",
"console",
".",
"log",
"(",
"'Sentry ('",
"+",
"releaseVersion",
"+",
"') - '",
"+",
"fileName",
"+",
"' already exists.'",
")",
";",
"resolve",
"(",
")",
";",
"}",
"else",
"{",
"reject",
"(",
"err",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}"
] | Uploads a single file to a selected release.
@param {String} endpoint
The endpoint to push these files to
@param {String} releaseVersion
The release version for this file
@param {String} filePath
The absolute file path for the file we want to upload to the release | [
"Uploads",
"a",
"single",
"file",
"to",
"a",
"selected",
"release",
"."
] | af30dc8c637631b177ae33a1984a44ffa839914b | https://github.com/reddit/node-build/blob/af30dc8c637631b177ae33a1984a44ffa839914b/lib/uploadToSentry.js#L46-L78 | train |
reddit/node-build | lib/uploadToSentry.js | uploadToSentry | function uploadToSentry(projectSlug, orgSlug, releaseVersion, assets) {
var releaseEndpoint = makeUrl(projectSlug, orgSlug);
var uploadEndpoint = releaseEndpoint + releaseVersion + '/files/';
createRelease(releaseEndpoint, releaseVersion)
.then(function() {
return Promise.all(assets.map(uploadFile.bind(null,
uploadEndpoint,
releaseVersion
)));
})
.catch(function(e) {
console.log('Release failed with error: ', e);
});
} | javascript | function uploadToSentry(projectSlug, orgSlug, releaseVersion, assets) {
var releaseEndpoint = makeUrl(projectSlug, orgSlug);
var uploadEndpoint = releaseEndpoint + releaseVersion + '/files/';
createRelease(releaseEndpoint, releaseVersion)
.then(function() {
return Promise.all(assets.map(uploadFile.bind(null,
uploadEndpoint,
releaseVersion
)));
})
.catch(function(e) {
console.log('Release failed with error: ', e);
});
} | [
"function",
"uploadToSentry",
"(",
"projectSlug",
",",
"orgSlug",
",",
"releaseVersion",
",",
"assets",
")",
"{",
"var",
"releaseEndpoint",
"=",
"makeUrl",
"(",
"projectSlug",
",",
"orgSlug",
")",
";",
"var",
"uploadEndpoint",
"=",
"releaseEndpoint",
"+",
"releaseVersion",
"+",
"'/files/'",
";",
"createRelease",
"(",
"releaseEndpoint",
",",
"releaseVersion",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"return",
"Promise",
".",
"all",
"(",
"assets",
".",
"map",
"(",
"uploadFile",
".",
"bind",
"(",
"null",
",",
"uploadEndpoint",
",",
"releaseVersion",
")",
")",
")",
";",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"e",
")",
"{",
"console",
".",
"log",
"(",
"'Release failed with error: '",
",",
"e",
")",
";",
"}",
")",
";",
"}"
] | Creates a Sentry release and pushes the relevant assets to that release.
@param {String} projectName
The Sentry project this release belongs to
@param {String} releaseVersion
The release version for the js assets
@param {Array} assets
An array of filepaths to the assets that will be uploaded | [
"Creates",
"a",
"Sentry",
"release",
"and",
"pushes",
"the",
"relevant",
"assets",
"to",
"that",
"release",
"."
] | af30dc8c637631b177ae33a1984a44ffa839914b | https://github.com/reddit/node-build/blob/af30dc8c637631b177ae33a1984a44ffa839914b/lib/uploadToSentry.js#L89-L103 | train |
gilt/swig | packages/swig-cli/index.js | tell | function tell(name, taskInfo) {
if (swig.tasks[name]) {
console.log(`Task '${name}' has been overridden by a local installation`.yellow);
}
swig.tasks[name] = _.extend({
description: '<unknown>',
flags: {},
}, taskInfo);
} | javascript | function tell(name, taskInfo) {
if (swig.tasks[name]) {
console.log(`Task '${name}' has been overridden by a local installation`.yellow);
}
swig.tasks[name] = _.extend({
description: '<unknown>',
flags: {},
}, taskInfo);
} | [
"function",
"tell",
"(",
"name",
",",
"taskInfo",
")",
"{",
"if",
"(",
"swig",
".",
"tasks",
"[",
"name",
"]",
")",
"{",
"console",
".",
"log",
"(",
"`",
"${",
"name",
"}",
"`",
".",
"yellow",
")",
";",
"}",
"swig",
".",
"tasks",
"[",
"name",
"]",
"=",
"_",
".",
"extend",
"(",
"{",
"description",
":",
"'<unknown>'",
",",
"flags",
":",
"{",
"}",
",",
"}",
",",
"taskInfo",
")",
";",
"}"
] | allows a task to tell swig about itself | [
"allows",
"a",
"task",
"to",
"tell",
"swig",
"about",
"itself"
] | 499e83d60dea7208640549056d99988b29177980 | https://github.com/gilt/swig/blob/499e83d60dea7208640549056d99988b29177980/packages/swig-cli/index.js#L170-L179 | train |
acss-io/gulp-atomizer | index.js | function (file, unused, cb) {
if (file.isNull()) {
// nothing to do
return cb(null, file)
} else if (file.isStream()) {
// file.contents is a Stream. We don't support streams
this.emit('error', new PluginError(PLUGIN_NAME, 'Streams not supported!'))
} else if (file.isBuffer()) {
// lazy init the acss class
if (!acss) {
acss = new Atomizer()
if (addRules) {
acss.addRules(addRules)
}
}
// generate the class names and push them into the global collector array
var html = String(file.contents)
var classes = acss.findClassNames(html)
foundClasses = Array.prototype.concat(foundClasses, classes)
// make a note of this file if it's the newer than we've seen before
if (!latestMod || file.stat && file.stat.mtime > latestMod) {
latestFile = file
latestMod = file.stat && file.stat.mtime
}
// tell the engine we're done
cb()
}
} | javascript | function (file, unused, cb) {
if (file.isNull()) {
// nothing to do
return cb(null, file)
} else if (file.isStream()) {
// file.contents is a Stream. We don't support streams
this.emit('error', new PluginError(PLUGIN_NAME, 'Streams not supported!'))
} else if (file.isBuffer()) {
// lazy init the acss class
if (!acss) {
acss = new Atomizer()
if (addRules) {
acss.addRules(addRules)
}
}
// generate the class names and push them into the global collector array
var html = String(file.contents)
var classes = acss.findClassNames(html)
foundClasses = Array.prototype.concat(foundClasses, classes)
// make a note of this file if it's the newer than we've seen before
if (!latestMod || file.stat && file.stat.mtime > latestMod) {
latestFile = file
latestMod = file.stat && file.stat.mtime
}
// tell the engine we're done
cb()
}
} | [
"function",
"(",
"file",
",",
"unused",
",",
"cb",
")",
"{",
"if",
"(",
"file",
".",
"isNull",
"(",
")",
")",
"{",
"return",
"cb",
"(",
"null",
",",
"file",
")",
"}",
"else",
"if",
"(",
"file",
".",
"isStream",
"(",
")",
")",
"{",
"this",
".",
"emit",
"(",
"'error'",
",",
"new",
"PluginError",
"(",
"PLUGIN_NAME",
",",
"'Streams not supported!'",
")",
")",
"}",
"else",
"if",
"(",
"file",
".",
"isBuffer",
"(",
")",
")",
"{",
"if",
"(",
"!",
"acss",
")",
"{",
"acss",
"=",
"new",
"Atomizer",
"(",
")",
"if",
"(",
"addRules",
")",
"{",
"acss",
".",
"addRules",
"(",
"addRules",
")",
"}",
"}",
"var",
"html",
"=",
"String",
"(",
"file",
".",
"contents",
")",
"var",
"classes",
"=",
"acss",
".",
"findClassNames",
"(",
"html",
")",
"foundClasses",
"=",
"Array",
".",
"prototype",
".",
"concat",
"(",
"foundClasses",
",",
"classes",
")",
"if",
"(",
"!",
"latestMod",
"||",
"file",
".",
"stat",
"&&",
"file",
".",
"stat",
".",
"mtime",
">",
"latestMod",
")",
"{",
"latestFile",
"=",
"file",
"latestMod",
"=",
"file",
".",
"stat",
"&&",
"file",
".",
"stat",
".",
"mtime",
"}",
"cb",
"(",
")",
"}",
"}"
] | create the file handler | [
"create",
"the",
"file",
"handler"
] | 8a0e4aca88ea4d8cb701b7323fa6164887f97503 | https://github.com/acss-io/gulp-atomizer/blob/8a0e4aca88ea4d8cb701b7323fa6164887f97503/index.js#L36-L67 | train |
|
senecajs/seneca-mem-store | mem-store.js | do_save | function do_save(id, isnew) {
var mement = ent.data$(true, 'string')
if (undefined !== id) {
mement.id = id
}
mement.entity$ = ent.entity$
entmap[base] = entmap[base] || {}
entmap[base][name] = entmap[base][name] || {}
var prev = entmap[base][name][mement.id]
if (isnew && prev) {
return reply(error('entity-id-exists', { type: ent.entity$, id: id }))
}
var shouldMerge = true
if (options.merge !== false && ent.merge$ === false) {
shouldMerge = false
}
if (options.merge === false && ent.merge$ !== true) {
shouldMerge = false
}
mement = _.cloneDeep(mement)
if (shouldMerge) {
mement = _.assign(prev || {}, mement)
}
prev = entmap[base][name][mement.id] = mement
seneca.log.debug(function() {
return [
'save/' + (create ? 'insert' : 'update'),
ent.canon$({ string: 1 }),
mement,
desc
]
})
reply(null, ent.make$(prev))
} | javascript | function do_save(id, isnew) {
var mement = ent.data$(true, 'string')
if (undefined !== id) {
mement.id = id
}
mement.entity$ = ent.entity$
entmap[base] = entmap[base] || {}
entmap[base][name] = entmap[base][name] || {}
var prev = entmap[base][name][mement.id]
if (isnew && prev) {
return reply(error('entity-id-exists', { type: ent.entity$, id: id }))
}
var shouldMerge = true
if (options.merge !== false && ent.merge$ === false) {
shouldMerge = false
}
if (options.merge === false && ent.merge$ !== true) {
shouldMerge = false
}
mement = _.cloneDeep(mement)
if (shouldMerge) {
mement = _.assign(prev || {}, mement)
}
prev = entmap[base][name][mement.id] = mement
seneca.log.debug(function() {
return [
'save/' + (create ? 'insert' : 'update'),
ent.canon$({ string: 1 }),
mement,
desc
]
})
reply(null, ent.make$(prev))
} | [
"function",
"do_save",
"(",
"id",
",",
"isnew",
")",
"{",
"var",
"mement",
"=",
"ent",
".",
"data$",
"(",
"true",
",",
"'string'",
")",
"if",
"(",
"undefined",
"!==",
"id",
")",
"{",
"mement",
".",
"id",
"=",
"id",
"}",
"mement",
".",
"entity$",
"=",
"ent",
".",
"entity$",
"entmap",
"[",
"base",
"]",
"=",
"entmap",
"[",
"base",
"]",
"||",
"{",
"}",
"entmap",
"[",
"base",
"]",
"[",
"name",
"]",
"=",
"entmap",
"[",
"base",
"]",
"[",
"name",
"]",
"||",
"{",
"}",
"var",
"prev",
"=",
"entmap",
"[",
"base",
"]",
"[",
"name",
"]",
"[",
"mement",
".",
"id",
"]",
"if",
"(",
"isnew",
"&&",
"prev",
")",
"{",
"return",
"reply",
"(",
"error",
"(",
"'entity-id-exists'",
",",
"{",
"type",
":",
"ent",
".",
"entity$",
",",
"id",
":",
"id",
"}",
")",
")",
"}",
"var",
"shouldMerge",
"=",
"true",
"if",
"(",
"options",
".",
"merge",
"!==",
"false",
"&&",
"ent",
".",
"merge$",
"===",
"false",
")",
"{",
"shouldMerge",
"=",
"false",
"}",
"if",
"(",
"options",
".",
"merge",
"===",
"false",
"&&",
"ent",
".",
"merge$",
"!==",
"true",
")",
"{",
"shouldMerge",
"=",
"false",
"}",
"mement",
"=",
"_",
".",
"cloneDeep",
"(",
"mement",
")",
"if",
"(",
"shouldMerge",
")",
"{",
"mement",
"=",
"_",
".",
"assign",
"(",
"prev",
"||",
"{",
"}",
",",
"mement",
")",
"}",
"prev",
"=",
"entmap",
"[",
"base",
"]",
"[",
"name",
"]",
"[",
"mement",
".",
"id",
"]",
"=",
"mement",
"seneca",
".",
"log",
".",
"debug",
"(",
"function",
"(",
")",
"{",
"return",
"[",
"'save/'",
"+",
"(",
"create",
"?",
"'insert'",
":",
"'update'",
")",
",",
"ent",
".",
"canon$",
"(",
"{",
"string",
":",
"1",
"}",
")",
",",
"mement",
",",
"desc",
"]",
"}",
")",
"reply",
"(",
"null",
",",
"ent",
".",
"make$",
"(",
"prev",
")",
")",
"}"
] | The actual save logic for saving or creating and then saving the entity. | [
"The",
"actual",
"save",
"logic",
"for",
"saving",
"or",
"creating",
"and",
"then",
"saving",
"the",
"entity",
"."
] | 46a25e9fe75f85a31dc6c052f4807eaf4745fdbb | https://github.com/senecajs/seneca-mem-store/blob/46a25e9fe75f85a31dc6c052f4807eaf4745fdbb/mem-store.js#L82-L123 | train |
senecajs/seneca-mem-store | mem-store.js | create_new | function create_new() {
var id
// Check if we already have an id or if
// we need to generate a new one.
if (undefined !== ent.id$) {
// Take a copy of the existing id and
// delete it from the ent object. Do
// save will handle the id for us.
id = ent.id$
delete ent.id$
// Save with the existing id
return do_save(id, true)
}
// Generate a new id
id = options.generate_id ? options.generate_id(ent) : void 0
if (undefined !== id) {
return do_save(id, true)
} else {
var gen_id = {
role: 'basic',
cmd: 'generate_id',
name: name,
base: base,
zone: zone
}
// When we get a respones we will use the id param
// as our entity id, if this fails we just fail and
// call reply() as we have no way to save without an id
seneca.act(gen_id, function(err, id) {
if (err) return reply(err)
do_save(id, true)
})
}
} | javascript | function create_new() {
var id
// Check if we already have an id or if
// we need to generate a new one.
if (undefined !== ent.id$) {
// Take a copy of the existing id and
// delete it from the ent object. Do
// save will handle the id for us.
id = ent.id$
delete ent.id$
// Save with the existing id
return do_save(id, true)
}
// Generate a new id
id = options.generate_id ? options.generate_id(ent) : void 0
if (undefined !== id) {
return do_save(id, true)
} else {
var gen_id = {
role: 'basic',
cmd: 'generate_id',
name: name,
base: base,
zone: zone
}
// When we get a respones we will use the id param
// as our entity id, if this fails we just fail and
// call reply() as we have no way to save without an id
seneca.act(gen_id, function(err, id) {
if (err) return reply(err)
do_save(id, true)
})
}
} | [
"function",
"create_new",
"(",
")",
"{",
"var",
"id",
"if",
"(",
"undefined",
"!==",
"ent",
".",
"id$",
")",
"{",
"id",
"=",
"ent",
".",
"id$",
"delete",
"ent",
".",
"id$",
"return",
"do_save",
"(",
"id",
",",
"true",
")",
"}",
"id",
"=",
"options",
".",
"generate_id",
"?",
"options",
".",
"generate_id",
"(",
"ent",
")",
":",
"void",
"0",
"if",
"(",
"undefined",
"!==",
"id",
")",
"{",
"return",
"do_save",
"(",
"id",
",",
"true",
")",
"}",
"else",
"{",
"var",
"gen_id",
"=",
"{",
"role",
":",
"'basic'",
",",
"cmd",
":",
"'generate_id'",
",",
"name",
":",
"name",
",",
"base",
":",
"base",
",",
"zone",
":",
"zone",
"}",
"seneca",
".",
"act",
"(",
"gen_id",
",",
"function",
"(",
"err",
",",
"id",
")",
"{",
"if",
"(",
"err",
")",
"return",
"reply",
"(",
"err",
")",
"do_save",
"(",
"id",
",",
"true",
")",
"}",
")",
"}",
"}"
] | We will still use do_save to save the entity but we need a place to handle new entites and id concerns. | [
"We",
"will",
"still",
"use",
"do_save",
"to",
"save",
"the",
"entity",
"but",
"we",
"need",
"a",
"place",
"to",
"handle",
"new",
"entites",
"and",
"id",
"concerns",
"."
] | 46a25e9fe75f85a31dc6c052f4807eaf4745fdbb | https://github.com/senecajs/seneca-mem-store/blob/46a25e9fe75f85a31dc6c052f4807eaf4745fdbb/mem-store.js#L127-L165 | train |
senecajs/seneca-mem-store | mem-store.js | listents | function listents(seneca, entmap, qent, q, done) {
var list = []
var canon = qent.canon$({ object: true })
var base = canon.base
var name = canon.name
var entset = entmap[base] ? entmap[base][name] : null
if (entset) {
if (_.isString(q)) {
var ent = entset[q]
if (ent) {
list.push(ent)
}
}
if (_.isArray(q)) {
_.each(q, function(id) {
var ent = entset[id]
if (ent) {
ent = qent.make$(ent)
list.push(ent)
}
})
}
if (_.isObject(q)) {
_.keys(entset).forEach(function(id) {
var ent = entset[id]
for (var p in q) {
if (!~p.indexOf('$') && q[p] !== ent[p]) {
return
}
}
ent = qent.make$(ent)
list.push(ent)
})
}
}
// Always sort first, this is the 'expected' behaviour.
if (q.sort$) {
for (var sf in q.sort$) {
break
}
var sd = q.sort$[sf] < 0 ? -1 : 1
list = list.sort(function(a, b) {
return sd * (a[sf] < b[sf] ? -1 : a[sf] === b[sf] ? 0 : 1)
})
}
// Skip before limiting.
if (q.skip$ && q.skip$ > 0) {
list = list.slice(q.skip$)
}
// Limited the possibly sorted and skipped list.
if (q.limit$ && q.limit$ >= 0) {
list = list.slice(0, q.limit$)
}
// Prune fields
if (q.fields$) {
for (var i = 0; i < list.length; i++) {
var entfields = list[i].fields$()
for (var j = 0; j < entfields.length; j++) {
if ('id' !== entfields[j] && -1 == q.fields$.indexOf(entfields[j])) {
delete list[i][entfields[j]]
}
}
}
}
// Return the resulting list to the caller.
done.call(seneca, null, list)
} | javascript | function listents(seneca, entmap, qent, q, done) {
var list = []
var canon = qent.canon$({ object: true })
var base = canon.base
var name = canon.name
var entset = entmap[base] ? entmap[base][name] : null
if (entset) {
if (_.isString(q)) {
var ent = entset[q]
if (ent) {
list.push(ent)
}
}
if (_.isArray(q)) {
_.each(q, function(id) {
var ent = entset[id]
if (ent) {
ent = qent.make$(ent)
list.push(ent)
}
})
}
if (_.isObject(q)) {
_.keys(entset).forEach(function(id) {
var ent = entset[id]
for (var p in q) {
if (!~p.indexOf('$') && q[p] !== ent[p]) {
return
}
}
ent = qent.make$(ent)
list.push(ent)
})
}
}
// Always sort first, this is the 'expected' behaviour.
if (q.sort$) {
for (var sf in q.sort$) {
break
}
var sd = q.sort$[sf] < 0 ? -1 : 1
list = list.sort(function(a, b) {
return sd * (a[sf] < b[sf] ? -1 : a[sf] === b[sf] ? 0 : 1)
})
}
// Skip before limiting.
if (q.skip$ && q.skip$ > 0) {
list = list.slice(q.skip$)
}
// Limited the possibly sorted and skipped list.
if (q.limit$ && q.limit$ >= 0) {
list = list.slice(0, q.limit$)
}
// Prune fields
if (q.fields$) {
for (var i = 0; i < list.length; i++) {
var entfields = list[i].fields$()
for (var j = 0; j < entfields.length; j++) {
if ('id' !== entfields[j] && -1 == q.fields$.indexOf(entfields[j])) {
delete list[i][entfields[j]]
}
}
}
}
// Return the resulting list to the caller.
done.call(seneca, null, list)
} | [
"function",
"listents",
"(",
"seneca",
",",
"entmap",
",",
"qent",
",",
"q",
",",
"done",
")",
"{",
"var",
"list",
"=",
"[",
"]",
"var",
"canon",
"=",
"qent",
".",
"canon$",
"(",
"{",
"object",
":",
"true",
"}",
")",
"var",
"base",
"=",
"canon",
".",
"base",
"var",
"name",
"=",
"canon",
".",
"name",
"var",
"entset",
"=",
"entmap",
"[",
"base",
"]",
"?",
"entmap",
"[",
"base",
"]",
"[",
"name",
"]",
":",
"null",
"if",
"(",
"entset",
")",
"{",
"if",
"(",
"_",
".",
"isString",
"(",
"q",
")",
")",
"{",
"var",
"ent",
"=",
"entset",
"[",
"q",
"]",
"if",
"(",
"ent",
")",
"{",
"list",
".",
"push",
"(",
"ent",
")",
"}",
"}",
"if",
"(",
"_",
".",
"isArray",
"(",
"q",
")",
")",
"{",
"_",
".",
"each",
"(",
"q",
",",
"function",
"(",
"id",
")",
"{",
"var",
"ent",
"=",
"entset",
"[",
"id",
"]",
"if",
"(",
"ent",
")",
"{",
"ent",
"=",
"qent",
".",
"make$",
"(",
"ent",
")",
"list",
".",
"push",
"(",
"ent",
")",
"}",
"}",
")",
"}",
"if",
"(",
"_",
".",
"isObject",
"(",
"q",
")",
")",
"{",
"_",
".",
"keys",
"(",
"entset",
")",
".",
"forEach",
"(",
"function",
"(",
"id",
")",
"{",
"var",
"ent",
"=",
"entset",
"[",
"id",
"]",
"for",
"(",
"var",
"p",
"in",
"q",
")",
"{",
"if",
"(",
"!",
"~",
"p",
".",
"indexOf",
"(",
"'$'",
")",
"&&",
"q",
"[",
"p",
"]",
"!==",
"ent",
"[",
"p",
"]",
")",
"{",
"return",
"}",
"}",
"ent",
"=",
"qent",
".",
"make$",
"(",
"ent",
")",
"list",
".",
"push",
"(",
"ent",
")",
"}",
")",
"}",
"}",
"if",
"(",
"q",
".",
"sort$",
")",
"{",
"for",
"(",
"var",
"sf",
"in",
"q",
".",
"sort$",
")",
"{",
"break",
"}",
"var",
"sd",
"=",
"q",
".",
"sort$",
"[",
"sf",
"]",
"<",
"0",
"?",
"-",
"1",
":",
"1",
"list",
"=",
"list",
".",
"sort",
"(",
"function",
"(",
"a",
",",
"b",
")",
"{",
"return",
"sd",
"*",
"(",
"a",
"[",
"sf",
"]",
"<",
"b",
"[",
"sf",
"]",
"?",
"-",
"1",
":",
"a",
"[",
"sf",
"]",
"===",
"b",
"[",
"sf",
"]",
"?",
"0",
":",
"1",
")",
"}",
")",
"}",
"if",
"(",
"q",
".",
"skip$",
"&&",
"q",
".",
"skip$",
">",
"0",
")",
"{",
"list",
"=",
"list",
".",
"slice",
"(",
"q",
".",
"skip$",
")",
"}",
"if",
"(",
"q",
".",
"limit$",
"&&",
"q",
".",
"limit$",
">=",
"0",
")",
"{",
"list",
"=",
"list",
".",
"slice",
"(",
"0",
",",
"q",
".",
"limit$",
")",
"}",
"if",
"(",
"q",
".",
"fields$",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"list",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"entfields",
"=",
"list",
"[",
"i",
"]",
".",
"fields$",
"(",
")",
"for",
"(",
"var",
"j",
"=",
"0",
";",
"j",
"<",
"entfields",
".",
"length",
";",
"j",
"++",
")",
"{",
"if",
"(",
"'id'",
"!==",
"entfields",
"[",
"j",
"]",
"&&",
"-",
"1",
"==",
"q",
".",
"fields$",
".",
"indexOf",
"(",
"entfields",
"[",
"j",
"]",
")",
")",
"{",
"delete",
"list",
"[",
"i",
"]",
"[",
"entfields",
"[",
"j",
"]",
"]",
"}",
"}",
"}",
"}",
"done",
".",
"call",
"(",
"seneca",
",",
"null",
",",
"list",
")",
"}"
] | Seneca supports a reasonable set of features in terms of listing. This function can handle sorting, skiping, limiting and general retrieval. | [
"Seneca",
"supports",
"a",
"reasonable",
"set",
"of",
"features",
"in",
"terms",
"of",
"listing",
".",
"This",
"function",
"can",
"handle",
"sorting",
"skiping",
"limiting",
"and",
"general",
"retrieval",
"."
] | 46a25e9fe75f85a31dc6c052f4807eaf4745fdbb | https://github.com/senecajs/seneca-mem-store/blob/46a25e9fe75f85a31dc6c052f4807eaf4745fdbb/mem-store.js#L329-L404 | train |
grasshopper-cms/grasshopper-core-nodejs | lib/middleware/content/validate.js | validateContentType | function validateContentType(cb) {
if (!_.isUndefined(kontx.args.meta) && !_.isUndefined(kontx.args.meta.type)) {
db.contentTypes.getById(kontx.args.meta.type.toString()).then(
function(contentType) {
cb(null, contentType);
},
function() {
cb(createError(400, messages.invalid_content_type));
});
} else {
cb(createError(400, messages.invalid_content_type));
}
} | javascript | function validateContentType(cb) {
if (!_.isUndefined(kontx.args.meta) && !_.isUndefined(kontx.args.meta.type)) {
db.contentTypes.getById(kontx.args.meta.type.toString()).then(
function(contentType) {
cb(null, contentType);
},
function() {
cb(createError(400, messages.invalid_content_type));
});
} else {
cb(createError(400, messages.invalid_content_type));
}
} | [
"function",
"validateContentType",
"(",
"cb",
")",
"{",
"if",
"(",
"!",
"_",
".",
"isUndefined",
"(",
"kontx",
".",
"args",
".",
"meta",
")",
"&&",
"!",
"_",
".",
"isUndefined",
"(",
"kontx",
".",
"args",
".",
"meta",
".",
"type",
")",
")",
"{",
"db",
".",
"contentTypes",
".",
"getById",
"(",
"kontx",
".",
"args",
".",
"meta",
".",
"type",
".",
"toString",
"(",
")",
")",
".",
"then",
"(",
"function",
"(",
"contentType",
")",
"{",
"cb",
"(",
"null",
",",
"contentType",
")",
";",
"}",
",",
"function",
"(",
")",
"{",
"cb",
"(",
"createError",
"(",
"400",
",",
"messages",
".",
"invalid_content_type",
")",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"cb",
"(",
"createError",
"(",
"400",
",",
"messages",
".",
"invalid_content_type",
")",
")",
";",
"}",
"}"
] | Function will test to see if the content type is in the system. | [
"Function",
"will",
"test",
"to",
"see",
"if",
"the",
"content",
"type",
"is",
"in",
"the",
"system",
"."
] | 8fabc3bfc5b18855ead443db0644608a277d0ea0 | https://github.com/grasshopper-cms/grasshopper-core-nodejs/blob/8fabc3bfc5b18855ead443db0644608a277d0ea0/lib/middleware/content/validate.js#L27-L40 | train |
grasshopper-cms/grasshopper-core-nodejs | lib/middleware/content/validate.js | validateFields | function validateFields(contentType, cb) {
if (_.isArray(contentType.fields)) {
async.each(contentType.fields, validateField, function(err) {
cb(err);
});
} else {
cb();
}
} | javascript | function validateFields(contentType, cb) {
if (_.isArray(contentType.fields)) {
async.each(contentType.fields, validateField, function(err) {
cb(err);
});
} else {
cb();
}
} | [
"function",
"validateFields",
"(",
"contentType",
",",
"cb",
")",
"{",
"if",
"(",
"_",
".",
"isArray",
"(",
"contentType",
".",
"fields",
")",
")",
"{",
"async",
".",
"each",
"(",
"contentType",
".",
"fields",
",",
"validateField",
",",
"function",
"(",
"err",
")",
"{",
"cb",
"(",
"err",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"cb",
"(",
")",
";",
"}",
"}"
] | Function will iterate all the fields in the content type and check the validation rules for each one. | [
"Function",
"will",
"iterate",
"all",
"the",
"fields",
"in",
"the",
"content",
"type",
"and",
"check",
"the",
"validation",
"rules",
"for",
"each",
"one",
"."
] | 8fabc3bfc5b18855ead443db0644608a277d0ea0 | https://github.com/grasshopper-cms/grasshopper-core-nodejs/blob/8fabc3bfc5b18855ead443db0644608a277d0ea0/lib/middleware/content/validate.js#L43-L51 | train |
grasshopper-cms/grasshopper-core-nodejs | lib/middleware/content/validate.js | validateField | function validateField(field, cb) {
if (_.isArray(field.validation)) {
async.each(field.validation, performValidation(field), function(err) {
cb(err);
});
} else {
cb();
}
} | javascript | function validateField(field, cb) {
if (_.isArray(field.validation)) {
async.each(field.validation, performValidation(field), function(err) {
cb(err);
});
} else {
cb();
}
} | [
"function",
"validateField",
"(",
"field",
",",
"cb",
")",
"{",
"if",
"(",
"_",
".",
"isArray",
"(",
"field",
".",
"validation",
")",
")",
"{",
"async",
".",
"each",
"(",
"field",
".",
"validation",
",",
"performValidation",
"(",
"field",
")",
",",
"function",
"(",
"err",
")",
"{",
"cb",
"(",
"err",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"cb",
"(",
")",
";",
"}",
"}"
] | Function will iterate all of the validation rules for a specific field and perform the validation rule. | [
"Function",
"will",
"iterate",
"all",
"of",
"the",
"validation",
"rules",
"for",
"a",
"specific",
"field",
"and",
"perform",
"the",
"validation",
"rule",
"."
] | 8fabc3bfc5b18855ead443db0644608a277d0ea0 | https://github.com/grasshopper-cms/grasshopper-core-nodejs/blob/8fabc3bfc5b18855ead443db0644608a277d0ea0/lib/middleware/content/validate.js#L54-L62 | train |
grasshopper-cms/grasshopper-core-nodejs | lib/middleware/content/validate.js | performValidation | function performValidation(field) {
return function(rule, cb) {
var valueToBeValidated = kontx.args.fields[field._id],
validate = validator.get(rule);
//Undefined values do not need to be validated unless the field is required
if (rule.type === 'required' || !_.isUndefined(valueToBeValidated)) {
if (_.isArray(valueToBeValidated)) {
q.all(
_.map(valueToBeValidated, function(value) {
return validate(value, rule.options);
})
)
.then(
function() {
cb();
},
function() {
cb(createError(400, validationTemplate({
label: field.label
})));
}
);
} else {
validate(valueToBeValidated, rule.options)
.then(
function() {
cb();
},
function() {
cb(createError(400, validationTemplate({
label: field.label
})));
}
);
}
} else {
cb();
}
};
} | javascript | function performValidation(field) {
return function(rule, cb) {
var valueToBeValidated = kontx.args.fields[field._id],
validate = validator.get(rule);
//Undefined values do not need to be validated unless the field is required
if (rule.type === 'required' || !_.isUndefined(valueToBeValidated)) {
if (_.isArray(valueToBeValidated)) {
q.all(
_.map(valueToBeValidated, function(value) {
return validate(value, rule.options);
})
)
.then(
function() {
cb();
},
function() {
cb(createError(400, validationTemplate({
label: field.label
})));
}
);
} else {
validate(valueToBeValidated, rule.options)
.then(
function() {
cb();
},
function() {
cb(createError(400, validationTemplate({
label: field.label
})));
}
);
}
} else {
cb();
}
};
} | [
"function",
"performValidation",
"(",
"field",
")",
"{",
"return",
"function",
"(",
"rule",
",",
"cb",
")",
"{",
"var",
"valueToBeValidated",
"=",
"kontx",
".",
"args",
".",
"fields",
"[",
"field",
".",
"_id",
"]",
",",
"validate",
"=",
"validator",
".",
"get",
"(",
"rule",
")",
";",
"if",
"(",
"rule",
".",
"type",
"===",
"'required'",
"||",
"!",
"_",
".",
"isUndefined",
"(",
"valueToBeValidated",
")",
")",
"{",
"if",
"(",
"_",
".",
"isArray",
"(",
"valueToBeValidated",
")",
")",
"{",
"q",
".",
"all",
"(",
"_",
".",
"map",
"(",
"valueToBeValidated",
",",
"function",
"(",
"value",
")",
"{",
"return",
"validate",
"(",
"value",
",",
"rule",
".",
"options",
")",
";",
"}",
")",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"cb",
"(",
")",
";",
"}",
",",
"function",
"(",
")",
"{",
"cb",
"(",
"createError",
"(",
"400",
",",
"validationTemplate",
"(",
"{",
"label",
":",
"field",
".",
"label",
"}",
")",
")",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"validate",
"(",
"valueToBeValidated",
",",
"rule",
".",
"options",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"cb",
"(",
")",
";",
"}",
",",
"function",
"(",
")",
"{",
"cb",
"(",
"createError",
"(",
"400",
",",
"validationTemplate",
"(",
"{",
"label",
":",
"field",
".",
"label",
"}",
")",
")",
")",
";",
"}",
")",
";",
"}",
"}",
"else",
"{",
"cb",
"(",
")",
";",
"}",
"}",
";",
"}"
] | Function actually tests the field for a specific validation rule. | [
"Function",
"actually",
"tests",
"the",
"field",
"for",
"a",
"specific",
"validation",
"rule",
"."
] | 8fabc3bfc5b18855ead443db0644608a277d0ea0 | https://github.com/grasshopper-cms/grasshopper-core-nodejs/blob/8fabc3bfc5b18855ead443db0644608a277d0ea0/lib/middleware/content/validate.js#L65-L105 | train |
grasshopper-cms/grasshopper-core-nodejs | lib/security/providers/facebook.js | _getPersistantFacebookToken | function _getPersistantFacebookToken(){
return facebook.query()
.get('/oauth/access_token?' +
'grant_type=fb_exchange_token&' +
'client_id=' + appId + '&' +
'client_secret=' + secret + '&' +
'fb_exchange_token=' + this.options.code)
.request()
.then(function (res) {
// Bad tokens result in a 200 with an error object
if (res[1].error) {
throw new Error(res[1].error.message);
}
this.creds = querystring.parse(res[1]);
}.bind(this));
} | javascript | function _getPersistantFacebookToken(){
return facebook.query()
.get('/oauth/access_token?' +
'grant_type=fb_exchange_token&' +
'client_id=' + appId + '&' +
'client_secret=' + secret + '&' +
'fb_exchange_token=' + this.options.code)
.request()
.then(function (res) {
// Bad tokens result in a 200 with an error object
if (res[1].error) {
throw new Error(res[1].error.message);
}
this.creds = querystring.parse(res[1]);
}.bind(this));
} | [
"function",
"_getPersistantFacebookToken",
"(",
")",
"{",
"return",
"facebook",
".",
"query",
"(",
")",
".",
"get",
"(",
"'/oauth/access_token?'",
"+",
"'grant_type=fb_exchange_token&'",
"+",
"'client_id='",
"+",
"appId",
"+",
"'&'",
"+",
"'client_secret='",
"+",
"secret",
"+",
"'&'",
"+",
"'fb_exchange_token='",
"+",
"this",
".",
"options",
".",
"code",
")",
".",
"request",
"(",
")",
".",
"then",
"(",
"function",
"(",
"res",
")",
"{",
"if",
"(",
"res",
"[",
"1",
"]",
".",
"error",
")",
"{",
"throw",
"new",
"Error",
"(",
"res",
"[",
"1",
"]",
".",
"error",
".",
"message",
")",
";",
"}",
"this",
".",
"creds",
"=",
"querystring",
".",
"parse",
"(",
"res",
"[",
"1",
"]",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
")",
";",
"}"
] | Function will accept the passed in authentication token from FB and exchange it for a permenant token. This token will be saved to the user's identities profile. | [
"Function",
"will",
"accept",
"the",
"passed",
"in",
"authentication",
"token",
"from",
"FB",
"and",
"exchange",
"it",
"for",
"a",
"permenant",
"token",
".",
"This",
"token",
"will",
"be",
"saved",
"to",
"the",
"user",
"s",
"identities",
"profile",
"."
] | 8fabc3bfc5b18855ead443db0644608a277d0ea0 | https://github.com/grasshopper-cms/grasshopper-core-nodejs/blob/8fabc3bfc5b18855ead443db0644608a277d0ea0/lib/security/providers/facebook.js#L39-L55 | train |
grasshopper-cms/grasshopper-core-nodejs | lib/security/providers/facebook.js | _createNewFacebookUser | function _createNewFacebookUser() {
var avatar = '',
excludedFields = ['link', 'email', 'first_name', 'last_name','picture'],
newUser;
//Set Image
if(this.socialUserInfo.picture && this.socialUserInfo.picture.data && this.socialUserInfo.picture.data.url !== ''){
avatar = this.socialUserInfo.picture.data.url;
}
newUser = {
role: 'external',
identities: {
facebook: {
id: this.socialUserInfo.id,
accessToken: this.creds.access_token,
expiresIn: this.creds.expires
}
},
linkedidentities: ['facebook'],
profile: {
picture: avatar
},
enabled: true,
email: this.socialUserInfo.email,
firstname: this.socialUserInfo.first_name,
lastname: this.socialUserInfo.last_name
};
_.each(profileFieldsArr, function(field){
if(excludedFields.indexOf(field) === -1){
newUser.profile[field] = this.socialUserInfo[field];
}
}.bind(this));
return db.users.insert(newUser);
} | javascript | function _createNewFacebookUser() {
var avatar = '',
excludedFields = ['link', 'email', 'first_name', 'last_name','picture'],
newUser;
//Set Image
if(this.socialUserInfo.picture && this.socialUserInfo.picture.data && this.socialUserInfo.picture.data.url !== ''){
avatar = this.socialUserInfo.picture.data.url;
}
newUser = {
role: 'external',
identities: {
facebook: {
id: this.socialUserInfo.id,
accessToken: this.creds.access_token,
expiresIn: this.creds.expires
}
},
linkedidentities: ['facebook'],
profile: {
picture: avatar
},
enabled: true,
email: this.socialUserInfo.email,
firstname: this.socialUserInfo.first_name,
lastname: this.socialUserInfo.last_name
};
_.each(profileFieldsArr, function(field){
if(excludedFields.indexOf(field) === -1){
newUser.profile[field] = this.socialUserInfo[field];
}
}.bind(this));
return db.users.insert(newUser);
} | [
"function",
"_createNewFacebookUser",
"(",
")",
"{",
"var",
"avatar",
"=",
"''",
",",
"excludedFields",
"=",
"[",
"'link'",
",",
"'email'",
",",
"'first_name'",
",",
"'last_name'",
",",
"'picture'",
"]",
",",
"newUser",
";",
"if",
"(",
"this",
".",
"socialUserInfo",
".",
"picture",
"&&",
"this",
".",
"socialUserInfo",
".",
"picture",
".",
"data",
"&&",
"this",
".",
"socialUserInfo",
".",
"picture",
".",
"data",
".",
"url",
"!==",
"''",
")",
"{",
"avatar",
"=",
"this",
".",
"socialUserInfo",
".",
"picture",
".",
"data",
".",
"url",
";",
"}",
"newUser",
"=",
"{",
"role",
":",
"'external'",
",",
"identities",
":",
"{",
"facebook",
":",
"{",
"id",
":",
"this",
".",
"socialUserInfo",
".",
"id",
",",
"accessToken",
":",
"this",
".",
"creds",
".",
"access_token",
",",
"expiresIn",
":",
"this",
".",
"creds",
".",
"expires",
"}",
"}",
",",
"linkedidentities",
":",
"[",
"'facebook'",
"]",
",",
"profile",
":",
"{",
"picture",
":",
"avatar",
"}",
",",
"enabled",
":",
"true",
",",
"email",
":",
"this",
".",
"socialUserInfo",
".",
"email",
",",
"firstname",
":",
"this",
".",
"socialUserInfo",
".",
"first_name",
",",
"lastname",
":",
"this",
".",
"socialUserInfo",
".",
"last_name",
"}",
";",
"_",
".",
"each",
"(",
"profileFieldsArr",
",",
"function",
"(",
"field",
")",
"{",
"if",
"(",
"excludedFields",
".",
"indexOf",
"(",
"field",
")",
"===",
"-",
"1",
")",
"{",
"newUser",
".",
"profile",
"[",
"field",
"]",
"=",
"this",
".",
"socialUserInfo",
"[",
"field",
"]",
";",
"}",
"}",
".",
"bind",
"(",
"this",
")",
")",
";",
"return",
"db",
".",
"users",
".",
"insert",
"(",
"newUser",
")",
";",
"}"
] | Function that takes the facebook social data and attaches it to a user in grasshopper | [
"Function",
"that",
"takes",
"the",
"facebook",
"social",
"data",
"and",
"attaches",
"it",
"to",
"a",
"user",
"in",
"grasshopper"
] | 8fabc3bfc5b18855ead443db0644608a277d0ea0 | https://github.com/grasshopper-cms/grasshopper-core-nodejs/blob/8fabc3bfc5b18855ead443db0644608a277d0ea0/lib/security/providers/facebook.js#L97-L133 | train |
grasshopper-cms/grasshopper-core-nodejs | lib/security/providers/facebook.js | _createNewToken | function _createNewToken() {
var token = uuid.v4(),
newTokenObj = {
_id: crypto.createHash(token, config.crypto.secret_passphrase),
uid: this.userInfo._id.toString(),
created: new Date().toISOString(),
type: 'facebook'
};
return db.tokens.insert(newTokenObj).then(function() { return token; });
} | javascript | function _createNewToken() {
var token = uuid.v4(),
newTokenObj = {
_id: crypto.createHash(token, config.crypto.secret_passphrase),
uid: this.userInfo._id.toString(),
created: new Date().toISOString(),
type: 'facebook'
};
return db.tokens.insert(newTokenObj).then(function() { return token; });
} | [
"function",
"_createNewToken",
"(",
")",
"{",
"var",
"token",
"=",
"uuid",
".",
"v4",
"(",
")",
",",
"newTokenObj",
"=",
"{",
"_id",
":",
"crypto",
".",
"createHash",
"(",
"token",
",",
"config",
".",
"crypto",
".",
"secret_passphrase",
")",
",",
"uid",
":",
"this",
".",
"userInfo",
".",
"_id",
".",
"toString",
"(",
")",
",",
"created",
":",
"new",
"Date",
"(",
")",
".",
"toISOString",
"(",
")",
",",
"type",
":",
"'facebook'",
"}",
";",
"return",
"db",
".",
"tokens",
".",
"insert",
"(",
"newTokenObj",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"return",
"token",
";",
"}",
")",
";",
"}"
] | Function will create a new access token in grasshopper and return it to the app | [
"Function",
"will",
"create",
"a",
"new",
"access",
"token",
"in",
"grasshopper",
"and",
"return",
"it",
"to",
"the",
"app"
] | 8fabc3bfc5b18855ead443db0644608a277d0ea0 | https://github.com/grasshopper-cms/grasshopper-core-nodejs/blob/8fabc3bfc5b18855ead443db0644608a277d0ea0/lib/security/providers/facebook.js#L149-L159 | train |
aureooms/js-itertools | lib/reduce/some.js | some | function some(iterable, n) {
if (n <= 0) return true;
for (let item of iterable) {
if (item && --n === 0) return true;
}
return false;
} | javascript | function some(iterable, n) {
if (n <= 0) return true;
for (let item of iterable) {
if (item && --n === 0) return true;
}
return false;
} | [
"function",
"some",
"(",
"iterable",
",",
"n",
")",
"{",
"if",
"(",
"n",
"<=",
"0",
")",
"return",
"true",
";",
"for",
"(",
"let",
"item",
"of",
"iterable",
")",
"{",
"if",
"(",
"item",
"&&",
"--",
"n",
"===",
"0",
")",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Returns true if at least some of the elements of the input iterable are
truthy.
@example
some( repeat( true ) , 100 ) ; // returns true
@example
some( repeat( false ) , 0 ) ; // returns true
@example
some( repeat( false ) , 10 ) ; // loops forever
@example
some( nrepeat( true , 10 ) , 11 ) ; // returns false
@param {Iterable} iterable - The input iterable.
@param {Number} n - The number of elements that should be truthy.
@returns {Boolean} Returns <code>true</code> if at least <code>n</code>
elements of <code>iterable</code> are truthy, <code>false</code> otherwise. | [
"Returns",
"true",
"if",
"at",
"least",
"some",
"of",
"the",
"elements",
"of",
"the",
"input",
"iterable",
"are",
"truthy",
"."
] | 72bafa5f3f957ceb37bdfa87a222364fe4974be3 | https://github.com/aureooms/js-itertools/blob/72bafa5f3f957ceb37bdfa87a222364fe4974be3/lib/reduce/some.js#L30-L40 | train |
grasshopper-cms/grasshopper-core-nodejs | lib/runners/users.js | roleOrSelf | function roleOrSelf (role) {
if (!_.isNumber(role)) {
role = roles[role.toUpperCase()];
}
return function validateRoleOrSelf (kontx, next) {
var userPrivLevel = roles[kontx.user.role.toUpperCase()],
passedInUserId = kontx.args[0],
err = createError(strings.group('codes').forbidden, strings.group('errors').user_privileges_exceeded);
//If user object passed in instead of a string then parse.
if (!_.isUndefined(kontx.args[0]._id)) {
passedInUserId = kontx.args[0]._id;
}
//If user has enough priviliges then keep going
if (userPrivLevel <= parseInt(role, 10) || kontx.user._id.toString() === passedInUserId.toString()) {
next();
return;
}
next(err);
};
} | javascript | function roleOrSelf (role) {
if (!_.isNumber(role)) {
role = roles[role.toUpperCase()];
}
return function validateRoleOrSelf (kontx, next) {
var userPrivLevel = roles[kontx.user.role.toUpperCase()],
passedInUserId = kontx.args[0],
err = createError(strings.group('codes').forbidden, strings.group('errors').user_privileges_exceeded);
//If user object passed in instead of a string then parse.
if (!_.isUndefined(kontx.args[0]._id)) {
passedInUserId = kontx.args[0]._id;
}
//If user has enough priviliges then keep going
if (userPrivLevel <= parseInt(role, 10) || kontx.user._id.toString() === passedInUserId.toString()) {
next();
return;
}
next(err);
};
} | [
"function",
"roleOrSelf",
"(",
"role",
")",
"{",
"if",
"(",
"!",
"_",
".",
"isNumber",
"(",
"role",
")",
")",
"{",
"role",
"=",
"roles",
"[",
"role",
".",
"toUpperCase",
"(",
")",
"]",
";",
"}",
"return",
"function",
"validateRoleOrSelf",
"(",
"kontx",
",",
"next",
")",
"{",
"var",
"userPrivLevel",
"=",
"roles",
"[",
"kontx",
".",
"user",
".",
"role",
".",
"toUpperCase",
"(",
")",
"]",
",",
"passedInUserId",
"=",
"kontx",
".",
"args",
"[",
"0",
"]",
",",
"err",
"=",
"createError",
"(",
"strings",
".",
"group",
"(",
"'codes'",
")",
".",
"forbidden",
",",
"strings",
".",
"group",
"(",
"'errors'",
")",
".",
"user_privileges_exceeded",
")",
";",
"if",
"(",
"!",
"_",
".",
"isUndefined",
"(",
"kontx",
".",
"args",
"[",
"0",
"]",
".",
"_id",
")",
")",
"{",
"passedInUserId",
"=",
"kontx",
".",
"args",
"[",
"0",
"]",
".",
"_id",
";",
"}",
"if",
"(",
"userPrivLevel",
"<=",
"parseInt",
"(",
"role",
",",
"10",
")",
"||",
"kontx",
".",
"user",
".",
"_id",
".",
"toString",
"(",
")",
"===",
"passedInUserId",
".",
"toString",
"(",
")",
")",
"{",
"next",
"(",
")",
";",
"return",
";",
"}",
"next",
"(",
"err",
")",
";",
"}",
";",
"}"
] | Middleware the ensures that the user either has a good enough role or is trying to get information
about themselves.
@param role
@returns {Function} | [
"Middleware",
"the",
"ensures",
"that",
"the",
"user",
"either",
"has",
"a",
"good",
"enough",
"role",
"or",
"is",
"trying",
"to",
"get",
"information",
"about",
"themselves",
"."
] | 8fabc3bfc5b18855ead443db0644608a277d0ea0 | https://github.com/grasshopper-cms/grasshopper-core-nodejs/blob/8fabc3bfc5b18855ead443db0644608a277d0ea0/lib/runners/users.js#L18-L41 | train |
grasshopper-cms/grasshopper-core-nodejs | lib/runners/users.js | setDefaultUser | function setDefaultUser (kontx, next) {
var a = _.clone(kontx.args);
if (a.length === 0) { //No args are sent in, set first to be user id
a[0] = kontx.user._id;
}
else if (_.has(a[0], 'include') || _.has(a[0], 'exclude')) { // If first arg is options then reassign
a[0] = kontx.user._id;
a[1] = kontx.args[0];
}
kontx.args = a;
next();
} | javascript | function setDefaultUser (kontx, next) {
var a = _.clone(kontx.args);
if (a.length === 0) { //No args are sent in, set first to be user id
a[0] = kontx.user._id;
}
else if (_.has(a[0], 'include') || _.has(a[0], 'exclude')) { // If first arg is options then reassign
a[0] = kontx.user._id;
a[1] = kontx.args[0];
}
kontx.args = a;
next();
} | [
"function",
"setDefaultUser",
"(",
"kontx",
",",
"next",
")",
"{",
"var",
"a",
"=",
"_",
".",
"clone",
"(",
"kontx",
".",
"args",
")",
";",
"if",
"(",
"a",
".",
"length",
"===",
"0",
")",
"{",
"a",
"[",
"0",
"]",
"=",
"kontx",
".",
"user",
".",
"_id",
";",
"}",
"else",
"if",
"(",
"_",
".",
"has",
"(",
"a",
"[",
"0",
"]",
",",
"'include'",
")",
"||",
"_",
".",
"has",
"(",
"a",
"[",
"0",
"]",
",",
"'exclude'",
")",
")",
"{",
"a",
"[",
"0",
"]",
"=",
"kontx",
".",
"user",
".",
"_id",
";",
"a",
"[",
"1",
"]",
"=",
"kontx",
".",
"args",
"[",
"0",
"]",
";",
"}",
"kontx",
".",
"args",
"=",
"a",
";",
"next",
"(",
")",
";",
"}"
] | Middleware that will set the function argument equal to the currently logged in user id if it is left
empty. This can be used for returning back the currently logged in user's information.
@param kontx
@param next | [
"Middleware",
"that",
"will",
"set",
"the",
"function",
"argument",
"equal",
"to",
"the",
"currently",
"logged",
"in",
"user",
"id",
"if",
"it",
"is",
"left",
"empty",
".",
"This",
"can",
"be",
"used",
"for",
"returning",
"back",
"the",
"currently",
"logged",
"in",
"user",
"s",
"information",
"."
] | 8fabc3bfc5b18855ead443db0644608a277d0ea0 | https://github.com/grasshopper-cms/grasshopper-core-nodejs/blob/8fabc3bfc5b18855ead443db0644608a277d0ea0/lib/runners/users.js#L49-L62 | train |
grasshopper-cms/grasshopper-core-nodejs | lib/db/mongodb/mixins/fields.js | function(options){
var cleanOptions = this.parseOptions(options),
excludes = _.clone(this.privateFields),
includeExludes = [];
// If any includes are passed in through the options clean up the
// default excluded fields. A type can have some excluded fields by
// default and if the user overrides this then we need to clean up the query.
if(options && options.include){
_.each(options.include, function(include){
//If the include matches an existing exclude then remove it from the
//excludes and also from the includes (you can't mix them)
excludes = _.remove(excludes, function(o){
if(o === include){
cleanOptions.include = _.remove(cleanOptions.include, function(i){
return i !== include;
});
}
return o !== include;
});
});
}
includeExludes = _.union(cleanOptions.include,
this.parseExclusion(cleanOptions.exclude),
this.parseExclusion(excludes)
);
return includeExludes.join(' ');
} | javascript | function(options){
var cleanOptions = this.parseOptions(options),
excludes = _.clone(this.privateFields),
includeExludes = [];
// If any includes are passed in through the options clean up the
// default excluded fields. A type can have some excluded fields by
// default and if the user overrides this then we need to clean up the query.
if(options && options.include){
_.each(options.include, function(include){
//If the include matches an existing exclude then remove it from the
//excludes and also from the includes (you can't mix them)
excludes = _.remove(excludes, function(o){
if(o === include){
cleanOptions.include = _.remove(cleanOptions.include, function(i){
return i !== include;
});
}
return o !== include;
});
});
}
includeExludes = _.union(cleanOptions.include,
this.parseExclusion(cleanOptions.exclude),
this.parseExclusion(excludes)
);
return includeExludes.join(' ');
} | [
"function",
"(",
"options",
")",
"{",
"var",
"cleanOptions",
"=",
"this",
".",
"parseOptions",
"(",
"options",
")",
",",
"excludes",
"=",
"_",
".",
"clone",
"(",
"this",
".",
"privateFields",
")",
",",
"includeExludes",
"=",
"[",
"]",
";",
"if",
"(",
"options",
"&&",
"options",
".",
"include",
")",
"{",
"_",
".",
"each",
"(",
"options",
".",
"include",
",",
"function",
"(",
"include",
")",
"{",
"excludes",
"=",
"_",
".",
"remove",
"(",
"excludes",
",",
"function",
"(",
"o",
")",
"{",
"if",
"(",
"o",
"===",
"include",
")",
"{",
"cleanOptions",
".",
"include",
"=",
"_",
".",
"remove",
"(",
"cleanOptions",
".",
"include",
",",
"function",
"(",
"i",
")",
"{",
"return",
"i",
"!==",
"include",
";",
"}",
")",
";",
"}",
"return",
"o",
"!==",
"include",
";",
"}",
")",
";",
"}",
")",
";",
"}",
"includeExludes",
"=",
"_",
".",
"union",
"(",
"cleanOptions",
".",
"include",
",",
"this",
".",
"parseExclusion",
"(",
"cleanOptions",
".",
"exclude",
")",
",",
"this",
".",
"parseExclusion",
"(",
"excludes",
")",
")",
";",
"return",
"includeExludes",
".",
"join",
"(",
"' '",
")",
";",
"}"
] | Build string variable that can be sent to mongo query to include or exclude fields in the response. Your
implementation module should set 'privateFields' so that we can use the parameter here.
@param options Query options object
@returns {string} | [
"Build",
"string",
"variable",
"that",
"can",
"be",
"sent",
"to",
"mongo",
"query",
"to",
"include",
"or",
"exclude",
"fields",
"in",
"the",
"response",
".",
"Your",
"implementation",
"module",
"should",
"set",
"privateFields",
"so",
"that",
"we",
"can",
"use",
"the",
"parameter",
"here",
"."
] | 8fabc3bfc5b18855ead443db0644608a277d0ea0 | https://github.com/grasshopper-cms/grasshopper-core-nodejs/blob/8fabc3bfc5b18855ead443db0644608a277d0ea0/lib/db/mongodb/mixins/fields.js#L38-L69 | train |
|
gilt/swig | packages/swig-minify/lib/regex-replacer.js | Position | function Position(file, line, column) {
this.file = file;
this.line = line || 1;
this.column = column || 0;
} | javascript | function Position(file, line, column) {
this.file = file;
this.line = line || 1;
this.column = column || 0;
} | [
"function",
"Position",
"(",
"file",
",",
"line",
",",
"column",
")",
"{",
"this",
".",
"file",
"=",
"file",
";",
"this",
".",
"line",
"=",
"line",
"||",
"1",
";",
"this",
".",
"column",
"=",
"column",
"||",
"0",
";",
"}"
] | Handle a position in a file | [
"Handle",
"a",
"position",
"in",
"a",
"file"
] | 499e83d60dea7208640549056d99988b29177980 | https://github.com/gilt/swig/blob/499e83d60dea7208640549056d99988b29177980/packages/swig-minify/lib/regex-replacer.js#L13-L17 | train |
gilt/swig | packages/swig-spec/lib/jasmine-nyan-reporter.js | function () {
function draw(color, n) {
n = Math.max(parseInt(n), 0);
write(' ');
write('\u001b[' + color + 'm' + n + '\u001b[0m');
write('\n');
}
draw(colors.green, this.passed);
draw(colors.fail, this.failed);
draw(colors.pending, this.pending + ' ');
write('\n');
cursor.up(this.numberOfLines);
} | javascript | function () {
function draw(color, n) {
n = Math.max(parseInt(n), 0);
write(' ');
write('\u001b[' + color + 'm' + n + '\u001b[0m');
write('\n');
}
draw(colors.green, this.passed);
draw(colors.fail, this.failed);
draw(colors.pending, this.pending + ' ');
write('\n');
cursor.up(this.numberOfLines);
} | [
"function",
"(",
")",
"{",
"function",
"draw",
"(",
"color",
",",
"n",
")",
"{",
"n",
"=",
"Math",
".",
"max",
"(",
"parseInt",
"(",
"n",
")",
",",
"0",
")",
";",
"write",
"(",
"' '",
")",
";",
"write",
"(",
"'\\u001b['",
"+",
"\\u001b",
"+",
"color",
"+",
"'m'",
"+",
"n",
")",
";",
"'\\u001b[0m'",
"}",
"\\u001b",
"write",
"(",
"'\\n'",
")",
";",
"\\n",
"draw",
"(",
"colors",
".",
"green",
",",
"this",
".",
"passed",
")",
";",
"draw",
"(",
"colors",
".",
"fail",
",",
"this",
".",
"failed",
")",
";",
"}"
] | Draw the "scoreboard" showing the number
of passes, failures and pending tests.
@api private | [
"Draw",
"the",
"scoreboard",
"showing",
"the",
"number",
"of",
"passes",
"failures",
"and",
"pending",
"tests",
"."
] | 499e83d60dea7208640549056d99988b29177980 | https://github.com/gilt/swig/blob/499e83d60dea7208640549056d99988b29177980/packages/swig-spec/lib/jasmine-nyan-reporter.js#L261-L277 | train |
|
gilt/swig | packages/swig-spec/lib/jasmine-nyan-reporter.js | function () {
var self = this;
this.trajectories.forEach(function(line, index) {
write('\u001b[' + self.scoreboardWidth + 'C');
write(line.join(''));
write('\n');
});
cursor.up(this.numberOfLines);
} | javascript | function () {
var self = this;
this.trajectories.forEach(function(line, index) {
write('\u001b[' + self.scoreboardWidth + 'C');
write(line.join(''));
write('\n');
});
cursor.up(this.numberOfLines);
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"this",
".",
"trajectories",
".",
"forEach",
"(",
"function",
"(",
"line",
",",
"index",
")",
"{",
"write",
"(",
"'\\u001b['",
"+",
"\\u001b",
"+",
"self",
".",
"scoreboardWidth",
")",
";",
"'C'",
"write",
"(",
"line",
".",
"join",
"(",
"''",
")",
")",
";",
"}",
")",
";",
"write",
"(",
"'\\n'",
")",
";",
"}"
] | Draw the rainbow.
@api private | [
"Draw",
"the",
"rainbow",
"."
] | 499e83d60dea7208640549056d99988b29177980 | https://github.com/gilt/swig/blob/499e83d60dea7208640549056d99988b29177980/packages/swig-spec/lib/jasmine-nyan-reporter.js#L300-L310 | train |
|
gilt/swig | packages/swig-spec/lib/jasmine-nyan-reporter.js | function () {
var self = this;
var startWidth = this.scoreboardWidth + this.trajectories[0].length;
var color = '\u001b[' + startWidth + 'C';
var padding = '';
write(color);
write('_,------,');
write('\n');
write(color);
padding = self.tick ? ' ' : ' ';
write('_|' + padding + '/\\_/\\ ');
write('\n');
write(color);
padding = self.tick ? '_' : '__';
var tail = self.tick ? '~' : '^';
var face;
write(tail + '|' + padding + this.drawFace() + ' ');
write('\n');
write(color);
padding = self.tick ? ' ' : ' ';
write(padding + '"" "" ');
write('\n');
cursor.up(this.numberOfLines);
} | javascript | function () {
var self = this;
var startWidth = this.scoreboardWidth + this.trajectories[0].length;
var color = '\u001b[' + startWidth + 'C';
var padding = '';
write(color);
write('_,------,');
write('\n');
write(color);
padding = self.tick ? ' ' : ' ';
write('_|' + padding + '/\\_/\\ ');
write('\n');
write(color);
padding = self.tick ? '_' : '__';
var tail = self.tick ? '~' : '^';
var face;
write(tail + '|' + padding + this.drawFace() + ' ');
write('\n');
write(color);
padding = self.tick ? ' ' : ' ';
write(padding + '"" "" ');
write('\n');
cursor.up(this.numberOfLines);
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"startWidth",
"=",
"this",
".",
"scoreboardWidth",
"+",
"this",
".",
"trajectories",
"[",
"0",
"]",
".",
"length",
";",
"var",
"color",
"=",
"'\\u001b['",
"+",
"\\u001b",
"+",
"startWidth",
";",
"'C'",
"var",
"padding",
"=",
"''",
";",
"write",
"(",
"color",
")",
";",
"write",
"(",
"'_,------,'",
")",
";",
"write",
"(",
"'\\n'",
")",
";",
"\\n",
"write",
"(",
"color",
")",
";",
"padding",
"=",
"self",
".",
"tick",
"?",
"' '",
":",
"' '",
";",
"write",
"(",
"'_|'",
"+",
"padding",
"+",
"'/\\\\_/\\\\ '",
")",
";",
"\\\\",
"\\\\",
"write",
"(",
"'\\n'",
")",
";",
"\\n",
"write",
"(",
"color",
")",
";",
"padding",
"=",
"self",
".",
"tick",
"?",
"'_'",
":",
"'__'",
";",
"var",
"tail",
"=",
"self",
".",
"tick",
"?",
"'~'",
":",
"'^'",
";",
"var",
"face",
";",
"write",
"(",
"tail",
"+",
"'|'",
"+",
"padding",
"+",
"this",
".",
"drawFace",
"(",
")",
"+",
"' '",
")",
";",
"write",
"(",
"'\\n'",
")",
";",
"}"
] | Draw the nyan cat
@api private | [
"Draw",
"the",
"nyan",
"cat"
] | 499e83d60dea7208640549056d99988b29177980 | https://github.com/gilt/swig/blob/499e83d60dea7208640549056d99988b29177980/packages/swig-spec/lib/jasmine-nyan-reporter.js#L317-L345 | train |
|
aureooms/js-itertools | lib/reduce/_reduce.js | _reduce | function _reduce(accumulator, iterable, initializer) {
for (let item of iterable) {
initializer = accumulator(initializer, item);
}
return initializer;
} | javascript | function _reduce(accumulator, iterable, initializer) {
for (let item of iterable) {
initializer = accumulator(initializer, item);
}
return initializer;
} | [
"function",
"_reduce",
"(",
"accumulator",
",",
"iterable",
",",
"initializer",
")",
"{",
"for",
"(",
"let",
"item",
"of",
"iterable",
")",
"{",
"initializer",
"=",
"accumulator",
"(",
"initializer",
",",
"item",
")",
";",
"}",
"return",
"initializer",
";",
"}"
] | Applies the accumulator function iteratively on the last return value of the
accumulator and the next value in the input iterable. The initial value is
the initializer parameter.
@example
_reduce( ( x , y ) => x + y , range( 10 ) , 0 ) ; // returns 45
@example
_reduce( ( x , y ) => x + y , range( 10 ) , 100 ) ; // returns 145
@param {Function} accumulator - The accumulator, a 2-ary function.
@param {Iterable} iterable - The input iterable.
@param {Object} initializer - The initial value of the reduction.
@returns {Object} - The reduction of the elements of <code>iterable</code>. | [
"Applies",
"the",
"accumulator",
"function",
"iteratively",
"on",
"the",
"last",
"return",
"value",
"of",
"the",
"accumulator",
"and",
"the",
"next",
"value",
"in",
"the",
"input",
"iterable",
".",
"The",
"initial",
"value",
"is",
"the",
"initializer",
"parameter",
"."
] | 72bafa5f3f957ceb37bdfa87a222364fe4974be3 | https://github.com/aureooms/js-itertools/blob/72bafa5f3f957ceb37bdfa87a222364fe4974be3/lib/reduce/_reduce.js#L23-L30 | train |
gilt/swig | packages/swig-install/lib/public-directory.js | compile | function compile() {
swig.log.info('', 'Compiling module list...');
const modulesPath = path.join(swig.temp, '/**/node_modules/@gilt-tech');
const modPaths = glob.sync(modulesPath);
let dirs;
swig.log.verbose(`[compile] searching: ${modulesPath}`);
swig.log.verbose(`[compile] found module directories: ${modPaths.length}`);
modPaths.forEach((modPath) => {
swig.log.verbose(`[compile] compiling: ${modPath}`);
dirs = fs.readdirSync(modPath);
_.each(dirs, (dir) => {
const dirPath = path.join(modPath, dir);
if (fs.existsSync(dirPath) && fs.lstatSync(dirPath).isDirectory()) {
azModules.push({ name: dir, path: dirPath });
}
});
});
// group by basename, and take the 'topmost' module in the hierarchy
azModules = _.groupBy(azModules, module => path.basename(module.path));
// pull out the 'winning' module path, for each module
azModules = _.map(azModules, (modulesList) => {
// the modules arg will be [{ name:, path: }, ...]
if (modulesList.length === 1) {
return modulesList[0];
}
// glob will almost always return the right order,
// but let's assert this to be safe. we can spare the cycles.
return _.sortBy(modulesList, module => module.path.length)[0];
});
// and now we pretty sort a-z for various output
// we dont reset azModules to the sorted array because we need it dirty for deps.less
_.sortBy(azModules, mod => mod.name).forEach((mod) => {
modules[mod.name] = mod.path;
});
swig.log.verbose('[compile] sorted modules: ');
swig.log.verbose(modules);
} | javascript | function compile() {
swig.log.info('', 'Compiling module list...');
const modulesPath = path.join(swig.temp, '/**/node_modules/@gilt-tech');
const modPaths = glob.sync(modulesPath);
let dirs;
swig.log.verbose(`[compile] searching: ${modulesPath}`);
swig.log.verbose(`[compile] found module directories: ${modPaths.length}`);
modPaths.forEach((modPath) => {
swig.log.verbose(`[compile] compiling: ${modPath}`);
dirs = fs.readdirSync(modPath);
_.each(dirs, (dir) => {
const dirPath = path.join(modPath, dir);
if (fs.existsSync(dirPath) && fs.lstatSync(dirPath).isDirectory()) {
azModules.push({ name: dir, path: dirPath });
}
});
});
// group by basename, and take the 'topmost' module in the hierarchy
azModules = _.groupBy(azModules, module => path.basename(module.path));
// pull out the 'winning' module path, for each module
azModules = _.map(azModules, (modulesList) => {
// the modules arg will be [{ name:, path: }, ...]
if (modulesList.length === 1) {
return modulesList[0];
}
// glob will almost always return the right order,
// but let's assert this to be safe. we can spare the cycles.
return _.sortBy(modulesList, module => module.path.length)[0];
});
// and now we pretty sort a-z for various output
// we dont reset azModules to the sorted array because we need it dirty for deps.less
_.sortBy(azModules, mod => mod.name).forEach((mod) => {
modules[mod.name] = mod.path;
});
swig.log.verbose('[compile] sorted modules: ');
swig.log.verbose(modules);
} | [
"function",
"compile",
"(",
")",
"{",
"swig",
".",
"log",
".",
"info",
"(",
"''",
",",
"'Compiling module list...'",
")",
";",
"const",
"modulesPath",
"=",
"path",
".",
"join",
"(",
"swig",
".",
"temp",
",",
"'/**/node_modules/@gilt-tech'",
")",
";",
"const",
"modPaths",
"=",
"glob",
".",
"sync",
"(",
"modulesPath",
")",
";",
"let",
"dirs",
";",
"swig",
".",
"log",
".",
"verbose",
"(",
"`",
"${",
"modulesPath",
"}",
"`",
")",
";",
"swig",
".",
"log",
".",
"verbose",
"(",
"`",
"${",
"modPaths",
".",
"length",
"}",
"`",
")",
";",
"modPaths",
".",
"forEach",
"(",
"(",
"modPath",
")",
"=>",
"{",
"swig",
".",
"log",
".",
"verbose",
"(",
"`",
"${",
"modPath",
"}",
"`",
")",
";",
"dirs",
"=",
"fs",
".",
"readdirSync",
"(",
"modPath",
")",
";",
"_",
".",
"each",
"(",
"dirs",
",",
"(",
"dir",
")",
"=>",
"{",
"const",
"dirPath",
"=",
"path",
".",
"join",
"(",
"modPath",
",",
"dir",
")",
";",
"if",
"(",
"fs",
".",
"existsSync",
"(",
"dirPath",
")",
"&&",
"fs",
".",
"lstatSync",
"(",
"dirPath",
")",
".",
"isDirectory",
"(",
")",
")",
"{",
"azModules",
".",
"push",
"(",
"{",
"name",
":",
"dir",
",",
"path",
":",
"dirPath",
"}",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"azModules",
"=",
"_",
".",
"groupBy",
"(",
"azModules",
",",
"module",
"=>",
"path",
".",
"basename",
"(",
"module",
".",
"path",
")",
")",
";",
"azModules",
"=",
"_",
".",
"map",
"(",
"azModules",
",",
"(",
"modulesList",
")",
"=>",
"{",
"if",
"(",
"modulesList",
".",
"length",
"===",
"1",
")",
"{",
"return",
"modulesList",
"[",
"0",
"]",
";",
"}",
"return",
"_",
".",
"sortBy",
"(",
"modulesList",
",",
"module",
"=>",
"module",
".",
"path",
".",
"length",
")",
"[",
"0",
"]",
";",
"}",
")",
";",
"_",
".",
"sortBy",
"(",
"azModules",
",",
"mod",
"=>",
"mod",
".",
"name",
")",
".",
"forEach",
"(",
"(",
"mod",
")",
"=>",
"{",
"modules",
"[",
"mod",
".",
"name",
"]",
"=",
"mod",
".",
"path",
";",
"}",
")",
";",
"swig",
".",
"log",
".",
"verbose",
"(",
"'[compile] sorted modules: '",
")",
";",
"swig",
".",
"log",
".",
"verbose",
"(",
"modules",
")",
";",
"}"
] | find and compile a list of all unique modules, and their paths | [
"find",
"and",
"compile",
"a",
"list",
"of",
"all",
"unique",
"modules",
"and",
"their",
"paths"
] | 499e83d60dea7208640549056d99988b29177980 | https://github.com/gilt/swig/blob/499e83d60dea7208640549056d99988b29177980/packages/swig-install/lib/public-directory.js#L54-L101 | train |
casetext/fireproof | lib/pager.js | Pager | function Pager(ref, initialCount) {
if (arguments.length < 1) {
throw new Error('Not enough arguments to Pager');
}
this._mainRef = ref.ref();
this._resetCurrentOperation();
this.hasNext = true;
this.hasPrevious = false;
var promise;
if (initialCount) {
promise = this.next(initialCount);
} else {
promise = Fireproof.Promise.resolve([]);
}
this.then = promise.then.bind(promise);
} | javascript | function Pager(ref, initialCount) {
if (arguments.length < 1) {
throw new Error('Not enough arguments to Pager');
}
this._mainRef = ref.ref();
this._resetCurrentOperation();
this.hasNext = true;
this.hasPrevious = false;
var promise;
if (initialCount) {
promise = this.next(initialCount);
} else {
promise = Fireproof.Promise.resolve([]);
}
this.then = promise.then.bind(promise);
} | [
"function",
"Pager",
"(",
"ref",
",",
"initialCount",
")",
"{",
"if",
"(",
"arguments",
".",
"length",
"<",
"1",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Not enough arguments to Pager'",
")",
";",
"}",
"this",
".",
"_mainRef",
"=",
"ref",
".",
"ref",
"(",
")",
";",
"this",
".",
"_resetCurrentOperation",
"(",
")",
";",
"this",
".",
"hasNext",
"=",
"true",
";",
"this",
".",
"hasPrevious",
"=",
"false",
";",
"var",
"promise",
";",
"if",
"(",
"initialCount",
")",
"{",
"promise",
"=",
"this",
".",
"next",
"(",
"initialCount",
")",
";",
"}",
"else",
"{",
"promise",
"=",
"Fireproof",
".",
"Promise",
".",
"resolve",
"(",
"[",
"]",
")",
";",
"}",
"this",
".",
"then",
"=",
"promise",
".",
"then",
".",
"bind",
"(",
"promise",
")",
";",
"}"
] | A helper object for paging over Firebase objects.
@constructor Fireproof.Pager
@static
@param {Fireproof} ref a Firebase ref whose children you wish to page over.
@param {Number} [initialCount] The number of objects in the first page.
@property {Boolean} hasPrevious True if there are more objects before the current page.
@property {Boolean} hasNext True if there are more objects after the current page. | [
"A",
"helper",
"object",
"for",
"paging",
"over",
"Firebase",
"objects",
"."
] | a568157310d965d2c115e5a3c9e8287fc8fe021b | https://github.com/casetext/fireproof/blob/a568157310d965d2c115e5a3c9e8287fc8fe021b/lib/pager.js#L11-L32 | train |
pex-gl/pex-gl | patch-gl.js | flipImageData | function flipImageData (data, width, height) {
const numComponents = data.length / (width * height)
for (let y = 0; y < height / 2; y++) {
for (let x = 0; x < width; x++) {
for (let c = 0; c < numComponents; c++) {
const i = (y * width + x) * numComponents + c
const flippedI = ((height - y - 1) * width + x) * numComponents + c
const tmp = data[i]
data[i] = data[flippedI]
data[flippedI] = tmp
}
}
}
} | javascript | function flipImageData (data, width, height) {
const numComponents = data.length / (width * height)
for (let y = 0; y < height / 2; y++) {
for (let x = 0; x < width; x++) {
for (let c = 0; c < numComponents; c++) {
const i = (y * width + x) * numComponents + c
const flippedI = ((height - y - 1) * width + x) * numComponents + c
const tmp = data[i]
data[i] = data[flippedI]
data[flippedI] = tmp
}
}
}
} | [
"function",
"flipImageData",
"(",
"data",
",",
"width",
",",
"height",
")",
"{",
"const",
"numComponents",
"=",
"data",
".",
"length",
"/",
"(",
"width",
"*",
"height",
")",
"for",
"(",
"let",
"y",
"=",
"0",
";",
"y",
"<",
"height",
"/",
"2",
";",
"y",
"++",
")",
"{",
"for",
"(",
"let",
"x",
"=",
"0",
";",
"x",
"<",
"width",
";",
"x",
"++",
")",
"{",
"for",
"(",
"let",
"c",
"=",
"0",
";",
"c",
"<",
"numComponents",
";",
"c",
"++",
")",
"{",
"const",
"i",
"=",
"(",
"y",
"*",
"width",
"+",
"x",
")",
"*",
"numComponents",
"+",
"c",
"const",
"flippedI",
"=",
"(",
"(",
"height",
"-",
"y",
"-",
"1",
")",
"*",
"width",
"+",
"x",
")",
"*",
"numComponents",
"+",
"c",
"const",
"tmp",
"=",
"data",
"[",
"i",
"]",
"data",
"[",
"i",
"]",
"=",
"data",
"[",
"flippedI",
"]",
"data",
"[",
"flippedI",
"]",
"=",
"tmp",
"}",
"}",
"}",
"}"
] | Flipping array buffer in place | [
"Flipping",
"array",
"buffer",
"in",
"place"
] | d611c6defd45676da98edb9242da9c30faeef18e | https://github.com/pex-gl/pex-gl/blob/d611c6defd45676da98edb9242da9c30faeef18e/patch-gl.js#L2-L15 | train |
stealjs/steal-npm | npm-load.js | deeplyExtendPkg | function deeplyExtendPkg(a, b) {
if(!a.resolutions) {
a.resolutions = {};
}
utils.extend(a.resolutions, b.resolutions || {});
if(!a.steal) {
a.steal = {};
}
if(!b.steal) {
b.steal = {};
}
utils.extend(a.steal, b.steal, true);
} | javascript | function deeplyExtendPkg(a, b) {
if(!a.resolutions) {
a.resolutions = {};
}
utils.extend(a.resolutions, b.resolutions || {});
if(!a.steal) {
a.steal = {};
}
if(!b.steal) {
b.steal = {};
}
utils.extend(a.steal, b.steal, true);
} | [
"function",
"deeplyExtendPkg",
"(",
"a",
",",
"b",
")",
"{",
"if",
"(",
"!",
"a",
".",
"resolutions",
")",
"{",
"a",
".",
"resolutions",
"=",
"{",
"}",
";",
"}",
"utils",
".",
"extend",
"(",
"a",
".",
"resolutions",
",",
"b",
".",
"resolutions",
"||",
"{",
"}",
")",
";",
"if",
"(",
"!",
"a",
".",
"steal",
")",
"{",
"a",
".",
"steal",
"=",
"{",
"}",
";",
"}",
"if",
"(",
"!",
"b",
".",
"steal",
")",
"{",
"b",
".",
"steal",
"=",
"{",
"}",
";",
"}",
"utils",
".",
"extend",
"(",
"a",
".",
"steal",
",",
"b",
".",
"steal",
",",
"true",
")",
";",
"}"
] | Deeply extend the configuration that needs to be kept from a previous bundle that runs through the build process. This makes sure that if we load different configuration for different bundles, all of it is retained for use in production. | [
"Deeply",
"extend",
"the",
"configuration",
"that",
"needs",
"to",
"be",
"kept",
"from",
"a",
"previous",
"bundle",
"that",
"runs",
"through",
"the",
"build",
"process",
".",
"This",
"makes",
"sure",
"that",
"if",
"we",
"load",
"different",
"configuration",
"for",
"different",
"bundles",
"all",
"of",
"it",
"is",
"retained",
"for",
"use",
"in",
"production",
"."
] | 216463c552cabe7d9dad86d754da784b5dea3d78 | https://github.com/stealjs/steal-npm/blob/216463c552cabe7d9dad86d754da784b5dea3d78/npm-load.js#L255-L269 | train |
grasshopper-cms/grasshopper-core-nodejs | lib/middleware/nodes/getChildren.js | loadChild | function loadChild(node, cb){
db.nodes.getByParent(node._id.toString()).then(
function(data){
payload = payload.concat(data);
async.each(data, loadChild, cb);
}).done();
} | javascript | function loadChild(node, cb){
db.nodes.getByParent(node._id.toString()).then(
function(data){
payload = payload.concat(data);
async.each(data, loadChild, cb);
}).done();
} | [
"function",
"loadChild",
"(",
"node",
",",
"cb",
")",
"{",
"db",
".",
"nodes",
".",
"getByParent",
"(",
"node",
".",
"_id",
".",
"toString",
"(",
")",
")",
".",
"then",
"(",
"function",
"(",
"data",
")",
"{",
"payload",
"=",
"payload",
".",
"concat",
"(",
"data",
")",
";",
"async",
".",
"each",
"(",
"data",
",",
"loadChild",
",",
"cb",
")",
";",
"}",
")",
".",
"done",
"(",
")",
";",
"}"
] | Recursive function to load children and save them into the payload | [
"Recursive",
"function",
"to",
"load",
"children",
"and",
"save",
"them",
"into",
"the",
"payload"
] | 8fabc3bfc5b18855ead443db0644608a277d0ea0 | https://github.com/grasshopper-cms/grasshopper-core-nodejs/blob/8fabc3bfc5b18855ead443db0644608a277d0ea0/lib/middleware/nodes/getChildren.js#L21-L27 | train |
grasshopper-cms/grasshopper-core-nodejs | lib/middleware/nodes/getChildren.js | setNodes | function setNodes(data){
payload = data;
if(kontx.args.deep === true){
async.eachSeries(data, loadChild, sendNext);
}
else {
sendNext();
}
} | javascript | function setNodes(data){
payload = data;
if(kontx.args.deep === true){
async.eachSeries(data, loadChild, sendNext);
}
else {
sendNext();
}
} | [
"function",
"setNodes",
"(",
"data",
")",
"{",
"payload",
"=",
"data",
";",
"if",
"(",
"kontx",
".",
"args",
".",
"deep",
"===",
"true",
")",
"{",
"async",
".",
"eachSeries",
"(",
"data",
",",
"loadChild",
",",
"sendNext",
")",
";",
"}",
"else",
"{",
"sendNext",
"(",
")",
";",
"}",
"}"
] | Initial callback that sets the payload and kicks off the recursive method if "deep" is set to true | [
"Initial",
"callback",
"that",
"sets",
"the",
"payload",
"and",
"kicks",
"off",
"the",
"recursive",
"method",
"if",
"deep",
"is",
"set",
"to",
"true"
] | 8fabc3bfc5b18855ead443db0644608a277d0ea0 | https://github.com/grasshopper-cms/grasshopper-core-nodejs/blob/8fabc3bfc5b18855ead443db0644608a277d0ea0/lib/middleware/nodes/getChildren.js#L30-L39 | train |
reddit/node-build | lib/build.js | function() {
if (!builds.length) { return; } // this shouldn't happen
var build = builds.shift();
var buildCallback = function(stats) {
cb(build.buildName, stats);
if (builds.length) {
runNextBuild();
}
};
console.log(colors.cyan('[Starting build]'), build.buildName);
executeBuild(build, buildCallback);
} | javascript | function() {
if (!builds.length) { return; } // this shouldn't happen
var build = builds.shift();
var buildCallback = function(stats) {
cb(build.buildName, stats);
if (builds.length) {
runNextBuild();
}
};
console.log(colors.cyan('[Starting build]'), build.buildName);
executeBuild(build, buildCallback);
} | [
"function",
"(",
")",
"{",
"if",
"(",
"!",
"builds",
".",
"length",
")",
"{",
"return",
";",
"}",
"var",
"build",
"=",
"builds",
".",
"shift",
"(",
")",
";",
"var",
"buildCallback",
"=",
"function",
"(",
"stats",
")",
"{",
"cb",
"(",
"build",
".",
"buildName",
",",
"stats",
")",
";",
"if",
"(",
"builds",
".",
"length",
")",
"{",
"runNextBuild",
"(",
")",
";",
"}",
"}",
";",
"console",
".",
"log",
"(",
"colors",
".",
"cyan",
"(",
"'[Starting build]'",
")",
",",
"build",
".",
"buildName",
")",
";",
"executeBuild",
"(",
"build",
",",
"buildCallback",
")",
";",
"}"
] | Run each build serially so the server can do things like read an app manifest file that's genrated during the client build step. | [
"Run",
"each",
"build",
"serially",
"so",
"the",
"server",
"can",
"do",
"things",
"like",
"read",
"an",
"app",
"manifest",
"file",
"that",
"s",
"genrated",
"during",
"the",
"client",
"build",
"step",
"."
] | af30dc8c637631b177ae33a1984a44ffa839914b | https://github.com/reddit/node-build/blob/af30dc8c637631b177ae33a1984a44ffa839914b/lib/build.js#L20-L32 | train |
|
grasshopper-cms/grasshopper-core-nodejs | dev/server/public/admin/vendor/svg-edit-2.7/extensions/ext-overview_window.js | function(){
var portHeight=parseFloat($("#workarea").css("height"));
var portWidth=parseFloat($("#workarea").css("width"));
var portX=$("#workarea").scrollLeft();
var portY=$("#workarea").scrollTop();
var windowWidth=parseFloat($("#svgcanvas").css("width"));
var windowHeight=parseFloat($("#svgcanvas").css("height"));
var overviewWidth=$("#overviewMiniView").attr("width");
var overviewHeight=$("#overviewMiniView").attr("height");
var viewBoxX=portX/windowWidth*overviewWidth;
var viewBoxY=portY/windowHeight*overviewHeight;
var viewBoxWidth=portWidth/windowWidth*overviewWidth;
var viewBoxHeight=portHeight/windowHeight*overviewHeight;
$("#overview_window_view_box").css("min-width",viewBoxWidth+"px");
$("#overview_window_view_box").css("min-height",viewBoxHeight+"px");
$("#overview_window_view_box").css("top",viewBoxY+"px");
$("#overview_window_view_box").css("left",viewBoxX+"px");
} | javascript | function(){
var portHeight=parseFloat($("#workarea").css("height"));
var portWidth=parseFloat($("#workarea").css("width"));
var portX=$("#workarea").scrollLeft();
var portY=$("#workarea").scrollTop();
var windowWidth=parseFloat($("#svgcanvas").css("width"));
var windowHeight=parseFloat($("#svgcanvas").css("height"));
var overviewWidth=$("#overviewMiniView").attr("width");
var overviewHeight=$("#overviewMiniView").attr("height");
var viewBoxX=portX/windowWidth*overviewWidth;
var viewBoxY=portY/windowHeight*overviewHeight;
var viewBoxWidth=portWidth/windowWidth*overviewWidth;
var viewBoxHeight=portHeight/windowHeight*overviewHeight;
$("#overview_window_view_box").css("min-width",viewBoxWidth+"px");
$("#overview_window_view_box").css("min-height",viewBoxHeight+"px");
$("#overview_window_view_box").css("top",viewBoxY+"px");
$("#overview_window_view_box").css("left",viewBoxX+"px");
} | [
"function",
"(",
")",
"{",
"var",
"portHeight",
"=",
"parseFloat",
"(",
"$",
"(",
"\"#workarea\"",
")",
".",
"css",
"(",
"\"height\"",
")",
")",
";",
"var",
"portWidth",
"=",
"parseFloat",
"(",
"$",
"(",
"\"#workarea\"",
")",
".",
"css",
"(",
"\"width\"",
")",
")",
";",
"var",
"portX",
"=",
"$",
"(",
"\"#workarea\"",
")",
".",
"scrollLeft",
"(",
")",
";",
"var",
"portY",
"=",
"$",
"(",
"\"#workarea\"",
")",
".",
"scrollTop",
"(",
")",
";",
"var",
"windowWidth",
"=",
"parseFloat",
"(",
"$",
"(",
"\"#svgcanvas\"",
")",
".",
"css",
"(",
"\"width\"",
")",
")",
";",
"var",
"windowHeight",
"=",
"parseFloat",
"(",
"$",
"(",
"\"#svgcanvas\"",
")",
".",
"css",
"(",
"\"height\"",
")",
")",
";",
"var",
"overviewWidth",
"=",
"$",
"(",
"\"#overviewMiniView\"",
")",
".",
"attr",
"(",
"\"width\"",
")",
";",
"var",
"overviewHeight",
"=",
"$",
"(",
"\"#overviewMiniView\"",
")",
".",
"attr",
"(",
"\"height\"",
")",
";",
"var",
"viewBoxX",
"=",
"portX",
"/",
"windowWidth",
"*",
"overviewWidth",
";",
"var",
"viewBoxY",
"=",
"portY",
"/",
"windowHeight",
"*",
"overviewHeight",
";",
"var",
"viewBoxWidth",
"=",
"portWidth",
"/",
"windowWidth",
"*",
"overviewWidth",
";",
"var",
"viewBoxHeight",
"=",
"portHeight",
"/",
"windowHeight",
"*",
"overviewHeight",
";",
"$",
"(",
"\"#overview_window_view_box\"",
")",
".",
"css",
"(",
"\"min-width\"",
",",
"viewBoxWidth",
"+",
"\"px\"",
")",
";",
"$",
"(",
"\"#overview_window_view_box\"",
")",
".",
"css",
"(",
"\"min-height\"",
",",
"viewBoxHeight",
"+",
"\"px\"",
")",
";",
"$",
"(",
"\"#overview_window_view_box\"",
")",
".",
"css",
"(",
"\"top\"",
",",
"viewBoxY",
"+",
"\"px\"",
")",
";",
"$",
"(",
"\"#overview_window_view_box\"",
")",
".",
"css",
"(",
"\"left\"",
",",
"viewBoxX",
"+",
"\"px\"",
")",
";",
"}"
] | define dynamic animation of the view box. | [
"define",
"dynamic",
"animation",
"of",
"the",
"view",
"box",
"."
] | 8fabc3bfc5b18855ead443db0644608a277d0ea0 | https://github.com/grasshopper-cms/grasshopper-core-nodejs/blob/8fabc3bfc5b18855ead443db0644608a277d0ea0/dev/server/public/admin/vendor/svg-edit-2.7/extensions/ext-overview_window.js#L30-L49 | train |
|
grasshopper-cms/grasshopper-core-nodejs | dev/server/public/admin/vendor/svg-edit-2.7/extensions/ext-overview_window.js | function(){
var viewWidth=$("#svgroot").attr("width");
var viewHeight=$("#svgroot").attr("height");
var viewX=640;
var viewY=480;
if(svgedit.browser.isIE())
{
//This has only been tested with Firefox 10 and IE 9 (without chrome frame).
//I am not sure if if is Firefox or IE that is being non compliant here.
//Either way the one that is noncompliant may become more compliant later.
//TAG:HACK
//TAG:VERSION_DEPENDENT
//TAG:BROWSER_SNIFFING
viewX=0;
viewY=0;
}
var svgWidth_old=$("#overviewMiniView").attr("width");
var svgHeight_new=viewHeight/viewWidth*svgWidth_old;
$("#overviewMiniView").attr("viewBox",viewX+" "+viewY+" "+viewWidth+" "+viewHeight);
$("#overviewMiniView").attr("height",svgHeight_new);
updateViewBox();
} | javascript | function(){
var viewWidth=$("#svgroot").attr("width");
var viewHeight=$("#svgroot").attr("height");
var viewX=640;
var viewY=480;
if(svgedit.browser.isIE())
{
//This has only been tested with Firefox 10 and IE 9 (without chrome frame).
//I am not sure if if is Firefox or IE that is being non compliant here.
//Either way the one that is noncompliant may become more compliant later.
//TAG:HACK
//TAG:VERSION_DEPENDENT
//TAG:BROWSER_SNIFFING
viewX=0;
viewY=0;
}
var svgWidth_old=$("#overviewMiniView").attr("width");
var svgHeight_new=viewHeight/viewWidth*svgWidth_old;
$("#overviewMiniView").attr("viewBox",viewX+" "+viewY+" "+viewWidth+" "+viewHeight);
$("#overviewMiniView").attr("height",svgHeight_new);
updateViewBox();
} | [
"function",
"(",
")",
"{",
"var",
"viewWidth",
"=",
"$",
"(",
"\"#svgroot\"",
")",
".",
"attr",
"(",
"\"width\"",
")",
";",
"var",
"viewHeight",
"=",
"$",
"(",
"\"#svgroot\"",
")",
".",
"attr",
"(",
"\"height\"",
")",
";",
"var",
"viewX",
"=",
"640",
";",
"var",
"viewY",
"=",
"480",
";",
"if",
"(",
"svgedit",
".",
"browser",
".",
"isIE",
"(",
")",
")",
"{",
"viewX",
"=",
"0",
";",
"viewY",
"=",
"0",
";",
"}",
"var",
"svgWidth_old",
"=",
"$",
"(",
"\"#overviewMiniView\"",
")",
".",
"attr",
"(",
"\"width\"",
")",
";",
"var",
"svgHeight_new",
"=",
"viewHeight",
"/",
"viewWidth",
"*",
"svgWidth_old",
";",
"$",
"(",
"\"#overviewMiniView\"",
")",
".",
"attr",
"(",
"\"viewBox\"",
",",
"viewX",
"+",
"\" \"",
"+",
"viewY",
"+",
"\" \"",
"+",
"viewWidth",
"+",
"\" \"",
"+",
"viewHeight",
")",
";",
"$",
"(",
"\"#overviewMiniView\"",
")",
".",
"attr",
"(",
"\"height\"",
",",
"svgHeight_new",
")",
";",
"updateViewBox",
"(",
")",
";",
"}"
] | comphensate for changes in zoom and canvas size | [
"comphensate",
"for",
"changes",
"in",
"zoom",
"and",
"canvas",
"size"
] | 8fabc3bfc5b18855ead443db0644608a277d0ea0 | https://github.com/grasshopper-cms/grasshopper-core-nodejs/blob/8fabc3bfc5b18855ead443db0644608a277d0ea0/dev/server/public/admin/vendor/svg-edit-2.7/extensions/ext-overview_window.js#L59-L82 | train |
|
grasshopper-cms/grasshopper-core-nodejs | dev/server/public/admin/vendor/svg-edit-2.7/extensions/ext-markers.js | getLinked | function getLinked(elem, attr) {
var str = elem.getAttribute(attr);
if(!str) {return null;}
var m = str.match(/\(\#(.*)\)/);
if(!m || m.length !== 2) {
return null;
}
return S.getElem(m[1]);
} | javascript | function getLinked(elem, attr) {
var str = elem.getAttribute(attr);
if(!str) {return null;}
var m = str.match(/\(\#(.*)\)/);
if(!m || m.length !== 2) {
return null;
}
return S.getElem(m[1]);
} | [
"function",
"getLinked",
"(",
"elem",
",",
"attr",
")",
"{",
"var",
"str",
"=",
"elem",
".",
"getAttribute",
"(",
"attr",
")",
";",
"if",
"(",
"!",
"str",
")",
"{",
"return",
"null",
";",
"}",
"var",
"m",
"=",
"str",
".",
"match",
"(",
"/",
"\\(\\#(.*)\\)",
"/",
")",
";",
"if",
"(",
"!",
"m",
"||",
"m",
".",
"length",
"!==",
"2",
")",
"{",
"return",
"null",
";",
"}",
"return",
"S",
".",
"getElem",
"(",
"m",
"[",
"1",
"]",
")",
";",
"}"
] | elem = a graphic element will have an attribute like marker-start attr - marker-start, marker-mid, or marker-end returns the marker element that is linked to the graphic element | [
"elem",
"=",
"a",
"graphic",
"element",
"will",
"have",
"an",
"attribute",
"like",
"marker",
"-",
"start",
"attr",
"-",
"marker",
"-",
"start",
"marker",
"-",
"mid",
"or",
"marker",
"-",
"end",
"returns",
"the",
"marker",
"element",
"that",
"is",
"linked",
"to",
"the",
"graphic",
"element"
] | 8fabc3bfc5b18855ead443db0644608a277d0ea0 | https://github.com/grasshopper-cms/grasshopper-core-nodejs/blob/8fabc3bfc5b18855ead443db0644608a277d0ea0/dev/server/public/admin/vendor/svg-edit-2.7/extensions/ext-markers.js#L113-L121 | train |
grasshopper-cms/grasshopper-core-nodejs | dev/server/public/admin/vendor/svg-edit-2.7/extensions/ext-markers.js | colorChanged | function colorChanged(elem) {
var color = elem.getAttribute('stroke');
$.each(mtypes, function(i, pos) {
var marker = getLinked(elem, 'marker-'+pos);
if (!marker) {return;}
if (!marker.attributes.se_type) {return;} // not created by this extension
var ch = marker.lastElementChild;
if (!ch) {return;}
var curfill = ch.getAttribute('fill');
var curstroke = ch.getAttribute('stroke');
if (curfill && curfill != 'none') {ch.setAttribute('fill', color);}
if (curstroke && curstroke != 'none') {ch.setAttribute('stroke', color);}
});
} | javascript | function colorChanged(elem) {
var color = elem.getAttribute('stroke');
$.each(mtypes, function(i, pos) {
var marker = getLinked(elem, 'marker-'+pos);
if (!marker) {return;}
if (!marker.attributes.se_type) {return;} // not created by this extension
var ch = marker.lastElementChild;
if (!ch) {return;}
var curfill = ch.getAttribute('fill');
var curstroke = ch.getAttribute('stroke');
if (curfill && curfill != 'none') {ch.setAttribute('fill', color);}
if (curstroke && curstroke != 'none') {ch.setAttribute('stroke', color);}
});
} | [
"function",
"colorChanged",
"(",
"elem",
")",
"{",
"var",
"color",
"=",
"elem",
".",
"getAttribute",
"(",
"'stroke'",
")",
";",
"$",
".",
"each",
"(",
"mtypes",
",",
"function",
"(",
"i",
",",
"pos",
")",
"{",
"var",
"marker",
"=",
"getLinked",
"(",
"elem",
",",
"'marker-'",
"+",
"pos",
")",
";",
"if",
"(",
"!",
"marker",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"marker",
".",
"attributes",
".",
"se_type",
")",
"{",
"return",
";",
"}",
"var",
"ch",
"=",
"marker",
".",
"lastElementChild",
";",
"if",
"(",
"!",
"ch",
")",
"{",
"return",
";",
"}",
"var",
"curfill",
"=",
"ch",
".",
"getAttribute",
"(",
"'fill'",
")",
";",
"var",
"curstroke",
"=",
"ch",
".",
"getAttribute",
"(",
"'stroke'",
")",
";",
"if",
"(",
"curfill",
"&&",
"curfill",
"!=",
"'none'",
")",
"{",
"ch",
".",
"setAttribute",
"(",
"'fill'",
",",
"color",
")",
";",
"}",
"if",
"(",
"curstroke",
"&&",
"curstroke",
"!=",
"'none'",
")",
"{",
"ch",
".",
"setAttribute",
"(",
"'stroke'",
",",
"color",
")",
";",
"}",
"}",
")",
";",
"}"
] | called when the main system modifies an object this routine changes the associated markers to be the same color | [
"called",
"when",
"the",
"main",
"system",
"modifies",
"an",
"object",
"this",
"routine",
"changes",
"the",
"associated",
"markers",
"to",
"be",
"the",
"same",
"color"
] | 8fabc3bfc5b18855ead443db0644608a277d0ea0 | https://github.com/grasshopper-cms/grasshopper-core-nodejs/blob/8fabc3bfc5b18855ead443db0644608a277d0ea0/dev/server/public/admin/vendor/svg-edit-2.7/extensions/ext-markers.js#L329-L343 | train |
grasshopper-cms/grasshopper-core-nodejs | dev/server/public/admin/vendor/svg-edit-2.7/extensions/ext-markers.js | updateReferences | function updateReferences(el) {
$.each(mtypes, function (i, pos) {
var id = marker_prefix + pos + '_' + el.id;
var marker_name = 'marker-'+pos;
var marker = getLinked(el, marker_name);
if (!marker || !marker.attributes.se_type) {return;} // not created by this extension
var url = el.getAttribute(marker_name);
if (url) {
var len = el.id.length;
var linkid = url.substr(-len-1, len);
if (el.id != linkid) {
var val = $('#'+pos + '_marker').attr('value');
addMarker(id, val);
svgCanvas.changeSelectedAttribute(marker_name, "url(#" + id + ")");
if (el.tagName === 'line' && pos == 'mid') {el = convertline(el);}
S.call("changed", selElems);
}
}
});
} | javascript | function updateReferences(el) {
$.each(mtypes, function (i, pos) {
var id = marker_prefix + pos + '_' + el.id;
var marker_name = 'marker-'+pos;
var marker = getLinked(el, marker_name);
if (!marker || !marker.attributes.se_type) {return;} // not created by this extension
var url = el.getAttribute(marker_name);
if (url) {
var len = el.id.length;
var linkid = url.substr(-len-1, len);
if (el.id != linkid) {
var val = $('#'+pos + '_marker').attr('value');
addMarker(id, val);
svgCanvas.changeSelectedAttribute(marker_name, "url(#" + id + ")");
if (el.tagName === 'line' && pos == 'mid') {el = convertline(el);}
S.call("changed", selElems);
}
}
});
} | [
"function",
"updateReferences",
"(",
"el",
")",
"{",
"$",
".",
"each",
"(",
"mtypes",
",",
"function",
"(",
"i",
",",
"pos",
")",
"{",
"var",
"id",
"=",
"marker_prefix",
"+",
"pos",
"+",
"'_'",
"+",
"el",
".",
"id",
";",
"var",
"marker_name",
"=",
"'marker-'",
"+",
"pos",
";",
"var",
"marker",
"=",
"getLinked",
"(",
"el",
",",
"marker_name",
")",
";",
"if",
"(",
"!",
"marker",
"||",
"!",
"marker",
".",
"attributes",
".",
"se_type",
")",
"{",
"return",
";",
"}",
"var",
"url",
"=",
"el",
".",
"getAttribute",
"(",
"marker_name",
")",
";",
"if",
"(",
"url",
")",
"{",
"var",
"len",
"=",
"el",
".",
"id",
".",
"length",
";",
"var",
"linkid",
"=",
"url",
".",
"substr",
"(",
"-",
"len",
"-",
"1",
",",
"len",
")",
";",
"if",
"(",
"el",
".",
"id",
"!=",
"linkid",
")",
"{",
"var",
"val",
"=",
"$",
"(",
"'#'",
"+",
"pos",
"+",
"'_marker'",
")",
".",
"attr",
"(",
"'value'",
")",
";",
"addMarker",
"(",
"id",
",",
"val",
")",
";",
"svgCanvas",
".",
"changeSelectedAttribute",
"(",
"marker_name",
",",
"\"url(#\"",
"+",
"id",
"+",
"\")\"",
")",
";",
"if",
"(",
"el",
".",
"tagName",
"===",
"'line'",
"&&",
"pos",
"==",
"'mid'",
")",
"{",
"el",
"=",
"convertline",
"(",
"el",
")",
";",
"}",
"S",
".",
"call",
"(",
"\"changed\"",
",",
"selElems",
")",
";",
"}",
"}",
"}",
")",
";",
"}"
] | called when the main system creates or modifies an object primary purpose is create new markers for cloned objects | [
"called",
"when",
"the",
"main",
"system",
"creates",
"or",
"modifies",
"an",
"object",
"primary",
"purpose",
"is",
"create",
"new",
"markers",
"for",
"cloned",
"objects"
] | 8fabc3bfc5b18855ead443db0644608a277d0ea0 | https://github.com/grasshopper-cms/grasshopper-core-nodejs/blob/8fabc3bfc5b18855ead443db0644608a277d0ea0/dev/server/public/admin/vendor/svg-edit-2.7/extensions/ext-markers.js#L347-L366 | train |
grasshopper-cms/grasshopper-core-nodejs | dev/server/public/admin/vendor/svg-edit-2.7/svgcanvas.js | function(elem) {
try {
// TODO: Fix issue with rotated groups. Currently they work
// fine in FF, but not in other browsers (same problem mentioned
// in Issue 339 comment #2).
var bb = svgedit.utilities.getBBox(elem);
var angle = svgedit.utilities.getRotationAngle(elem);
if ((angle && angle % 90) ||
svgedit.math.hasMatrixTransform(svgedit.transformlist.getTransformList(elem))) {
// Accurate way to get BBox of rotated element in Firefox:
// Put element in group and get its BBox
var good_bb = false;
// Get the BBox from the raw path for these elements
var elemNames = ['ellipse', 'path', 'line', 'polyline', 'polygon'];
if (elemNames.indexOf(elem.tagName) >= 0) {
bb = good_bb = canvas.convertToPath(elem, true);
} else if (elem.tagName == 'rect') {
// Look for radius
var rx = elem.getAttribute('rx');
var ry = elem.getAttribute('ry');
if (rx || ry) {
bb = good_bb = canvas.convertToPath(elem, true);
}
}
if (!good_bb) {
// Must use clone else FF freaks out
var clone = elem.cloneNode(true);
var g = document.createElementNS(NS.SVG, "g");
var parent = elem.parentNode;
parent.appendChild(g);
g.appendChild(clone);
bb = svgedit.utilities.bboxToObj(g.getBBox());
parent.removeChild(g);
}
// Old method: Works by giving the rotated BBox,
// this is (unfortunately) what Opera and Safari do
// natively when getting the BBox of the parent group
// var angle = angle * Math.PI / 180.0;
// var rminx = Number.MAX_VALUE, rminy = Number.MAX_VALUE,
// rmaxx = Number.MIN_VALUE, rmaxy = Number.MIN_VALUE;
// var cx = round(bb.x + bb.width/2),
// cy = round(bb.y + bb.height/2);
// var pts = [ [bb.x - cx, bb.y - cy],
// [bb.x + bb.width - cx, bb.y - cy],
// [bb.x + bb.width - cx, bb.y + bb.height - cy],
// [bb.x - cx, bb.y + bb.height - cy] ];
// var j = 4;
// while (j--) {
// var x = pts[j][0],
// y = pts[j][1],
// r = Math.sqrt( x*x + y*y );
// var theta = Math.atan2(y,x) + angle;
// x = round(r * Math.cos(theta) + cx);
// y = round(r * Math.sin(theta) + cy);
//
// // now set the bbox for the shape after it's been rotated
// if (x < rminx) rminx = x;
// if (y < rminy) rminy = y;
// if (x > rmaxx) rmaxx = x;
// if (y > rmaxy) rmaxy = y;
// }
//
// bb.x = rminx;
// bb.y = rminy;
// bb.width = rmaxx - rminx;
// bb.height = rmaxy - rminy;
}
return bb;
} catch(e) {
console.log(elem, e);
return null;
}
} | javascript | function(elem) {
try {
// TODO: Fix issue with rotated groups. Currently they work
// fine in FF, but not in other browsers (same problem mentioned
// in Issue 339 comment #2).
var bb = svgedit.utilities.getBBox(elem);
var angle = svgedit.utilities.getRotationAngle(elem);
if ((angle && angle % 90) ||
svgedit.math.hasMatrixTransform(svgedit.transformlist.getTransformList(elem))) {
// Accurate way to get BBox of rotated element in Firefox:
// Put element in group and get its BBox
var good_bb = false;
// Get the BBox from the raw path for these elements
var elemNames = ['ellipse', 'path', 'line', 'polyline', 'polygon'];
if (elemNames.indexOf(elem.tagName) >= 0) {
bb = good_bb = canvas.convertToPath(elem, true);
} else if (elem.tagName == 'rect') {
// Look for radius
var rx = elem.getAttribute('rx');
var ry = elem.getAttribute('ry');
if (rx || ry) {
bb = good_bb = canvas.convertToPath(elem, true);
}
}
if (!good_bb) {
// Must use clone else FF freaks out
var clone = elem.cloneNode(true);
var g = document.createElementNS(NS.SVG, "g");
var parent = elem.parentNode;
parent.appendChild(g);
g.appendChild(clone);
bb = svgedit.utilities.bboxToObj(g.getBBox());
parent.removeChild(g);
}
// Old method: Works by giving the rotated BBox,
// this is (unfortunately) what Opera and Safari do
// natively when getting the BBox of the parent group
// var angle = angle * Math.PI / 180.0;
// var rminx = Number.MAX_VALUE, rminy = Number.MAX_VALUE,
// rmaxx = Number.MIN_VALUE, rmaxy = Number.MIN_VALUE;
// var cx = round(bb.x + bb.width/2),
// cy = round(bb.y + bb.height/2);
// var pts = [ [bb.x - cx, bb.y - cy],
// [bb.x + bb.width - cx, bb.y - cy],
// [bb.x + bb.width - cx, bb.y + bb.height - cy],
// [bb.x - cx, bb.y + bb.height - cy] ];
// var j = 4;
// while (j--) {
// var x = pts[j][0],
// y = pts[j][1],
// r = Math.sqrt( x*x + y*y );
// var theta = Math.atan2(y,x) + angle;
// x = round(r * Math.cos(theta) + cx);
// y = round(r * Math.sin(theta) + cy);
//
// // now set the bbox for the shape after it's been rotated
// if (x < rminx) rminx = x;
// if (y < rminy) rminy = y;
// if (x > rmaxx) rmaxx = x;
// if (y > rmaxy) rmaxy = y;
// }
//
// bb.x = rminx;
// bb.y = rminy;
// bb.width = rmaxx - rminx;
// bb.height = rmaxy - rminy;
}
return bb;
} catch(e) {
console.log(elem, e);
return null;
}
} | [
"function",
"(",
"elem",
")",
"{",
"try",
"{",
"var",
"bb",
"=",
"svgedit",
".",
"utilities",
".",
"getBBox",
"(",
"elem",
")",
";",
"var",
"angle",
"=",
"svgedit",
".",
"utilities",
".",
"getRotationAngle",
"(",
"elem",
")",
";",
"if",
"(",
"(",
"angle",
"&&",
"angle",
"%",
"90",
")",
"||",
"svgedit",
".",
"math",
".",
"hasMatrixTransform",
"(",
"svgedit",
".",
"transformlist",
".",
"getTransformList",
"(",
"elem",
")",
")",
")",
"{",
"var",
"good_bb",
"=",
"false",
";",
"var",
"elemNames",
"=",
"[",
"'ellipse'",
",",
"'path'",
",",
"'line'",
",",
"'polyline'",
",",
"'polygon'",
"]",
";",
"if",
"(",
"elemNames",
".",
"indexOf",
"(",
"elem",
".",
"tagName",
")",
">=",
"0",
")",
"{",
"bb",
"=",
"good_bb",
"=",
"canvas",
".",
"convertToPath",
"(",
"elem",
",",
"true",
")",
";",
"}",
"else",
"if",
"(",
"elem",
".",
"tagName",
"==",
"'rect'",
")",
"{",
"var",
"rx",
"=",
"elem",
".",
"getAttribute",
"(",
"'rx'",
")",
";",
"var",
"ry",
"=",
"elem",
".",
"getAttribute",
"(",
"'ry'",
")",
";",
"if",
"(",
"rx",
"||",
"ry",
")",
"{",
"bb",
"=",
"good_bb",
"=",
"canvas",
".",
"convertToPath",
"(",
"elem",
",",
"true",
")",
";",
"}",
"}",
"if",
"(",
"!",
"good_bb",
")",
"{",
"var",
"clone",
"=",
"elem",
".",
"cloneNode",
"(",
"true",
")",
";",
"var",
"g",
"=",
"document",
".",
"createElementNS",
"(",
"NS",
".",
"SVG",
",",
"\"g\"",
")",
";",
"var",
"parent",
"=",
"elem",
".",
"parentNode",
";",
"parent",
".",
"appendChild",
"(",
"g",
")",
";",
"g",
".",
"appendChild",
"(",
"clone",
")",
";",
"bb",
"=",
"svgedit",
".",
"utilities",
".",
"bboxToObj",
"(",
"g",
".",
"getBBox",
"(",
")",
")",
";",
"parent",
".",
"removeChild",
"(",
"g",
")",
";",
"}",
"}",
"return",
"bb",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"console",
".",
"log",
"(",
"elem",
",",
"e",
")",
";",
"return",
"null",
";",
"}",
"}"
] | Make sure the expected BBox is returned if the element is a group | [
"Make",
"sure",
"the",
"expected",
"BBox",
"is",
"returned",
"if",
"the",
"element",
"is",
"a",
"group"
] | 8fabc3bfc5b18855ead443db0644608a277d0ea0 | https://github.com/grasshopper-cms/grasshopper-core-nodejs/blob/8fabc3bfc5b18855ead443db0644608a277d0ea0/dev/server/public/admin/vendor/svg-edit-2.7/svgcanvas.js#L602-L679 | train |
|
grasshopper-cms/grasshopper-core-nodejs | dev/server/public/admin/vendor/svg-edit-2.7/svgcanvas.js | function(m) {
console.log([m.a, m.b, m.c, m.d, m.e, m.f]);
} | javascript | function(m) {
console.log([m.a, m.b, m.c, m.d, m.e, m.f]);
} | [
"function",
"(",
"m",
")",
"{",
"console",
".",
"log",
"(",
"[",
"m",
".",
"a",
",",
"m",
".",
"b",
",",
"m",
".",
"c",
",",
"m",
".",
"d",
",",
"m",
".",
"e",
",",
"m",
".",
"f",
"]",
")",
";",
"}"
] | Debug tool to easily see the current matrix in the browser's console | [
"Debug",
"tool",
"to",
"easily",
"see",
"the",
"current",
"matrix",
"in",
"the",
"browser",
"s",
"console"
] | 8fabc3bfc5b18855ead443db0644608a277d0ea0 | https://github.com/grasshopper-cms/grasshopper-core-nodejs/blob/8fabc3bfc5b18855ead443db0644608a277d0ea0/dev/server/public/admin/vendor/svg-edit-2.7/svgcanvas.js#L1022-L1024 | train |
|
apostrophecms-legacy/apostrophe-pages | index.js | sanitizeSpontaneousAreas | function sanitizeSpontaneousAreas(req, data, page, callback) {
var toSanitize = [];
_.each(data, function(val, key) {
if (typeof(val) === 'object') {
if (val.type === 'area') {
if (_.has(page, key) && ((typeof(page[key]) !== 'object') || (page[key].type !== 'area'))) {
// Spontaneous areas may not replace properties that are not areas
return;
}
toSanitize.push({ key: key, items: val.items });
}
}
});
return async.eachSeries(toSanitize, function(entry, callback) {
return apos.sanitizeItems(req, entry.items || [], function(err, _items) {
if (err) {
return callback(err);
}
entry.items = _items;
return callback(null);
});
}, function(err) {
if (err) {
return callback(err);
}
_.each(toSanitize, function(entry) {
page[entry.key] = { type: 'area', items: entry.items };
});
return callback(null);
});
} | javascript | function sanitizeSpontaneousAreas(req, data, page, callback) {
var toSanitize = [];
_.each(data, function(val, key) {
if (typeof(val) === 'object') {
if (val.type === 'area') {
if (_.has(page, key) && ((typeof(page[key]) !== 'object') || (page[key].type !== 'area'))) {
// Spontaneous areas may not replace properties that are not areas
return;
}
toSanitize.push({ key: key, items: val.items });
}
}
});
return async.eachSeries(toSanitize, function(entry, callback) {
return apos.sanitizeItems(req, entry.items || [], function(err, _items) {
if (err) {
return callback(err);
}
entry.items = _items;
return callback(null);
});
}, function(err) {
if (err) {
return callback(err);
}
_.each(toSanitize, function(entry) {
page[entry.key] = { type: 'area', items: entry.items };
});
return callback(null);
});
} | [
"function",
"sanitizeSpontaneousAreas",
"(",
"req",
",",
"data",
",",
"page",
",",
"callback",
")",
"{",
"var",
"toSanitize",
"=",
"[",
"]",
";",
"_",
".",
"each",
"(",
"data",
",",
"function",
"(",
"val",
",",
"key",
")",
"{",
"if",
"(",
"typeof",
"(",
"val",
")",
"===",
"'object'",
")",
"{",
"if",
"(",
"val",
".",
"type",
"===",
"'area'",
")",
"{",
"if",
"(",
"_",
".",
"has",
"(",
"page",
",",
"key",
")",
"&&",
"(",
"(",
"typeof",
"(",
"page",
"[",
"key",
"]",
")",
"!==",
"'object'",
")",
"||",
"(",
"page",
"[",
"key",
"]",
".",
"type",
"!==",
"'area'",
")",
")",
")",
"{",
"return",
";",
"}",
"toSanitize",
".",
"push",
"(",
"{",
"key",
":",
"key",
",",
"items",
":",
"val",
".",
"items",
"}",
")",
";",
"}",
"}",
"}",
")",
";",
"return",
"async",
".",
"eachSeries",
"(",
"toSanitize",
",",
"function",
"(",
"entry",
",",
"callback",
")",
"{",
"return",
"apos",
".",
"sanitizeItems",
"(",
"req",
",",
"entry",
".",
"items",
"||",
"[",
"]",
",",
"function",
"(",
"err",
",",
"_items",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"entry",
".",
"items",
"=",
"_items",
";",
"return",
"callback",
"(",
"null",
")",
";",
"}",
")",
";",
"}",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"_",
".",
"each",
"(",
"toSanitize",
",",
"function",
"(",
"entry",
")",
"{",
"page",
"[",
"entry",
".",
"key",
"]",
"=",
"{",
"type",
":",
"'area'",
",",
"items",
":",
"entry",
".",
"items",
"}",
";",
"}",
")",
";",
"return",
"callback",
"(",
"null",
")",
";",
"}",
")",
";",
"}"
] | Both the new and edit page operations utilize this to deal with areas that arise spontaneously via page templates rather than being hardcoded in the schema. The rule is that if an otherwise unknown property is an object with a "type" sub-property set to "area", that is accepted and sanitized as an area. | [
"Both",
"the",
"new",
"and",
"edit",
"page",
"operations",
"utilize",
"this",
"to",
"deal",
"with",
"areas",
"that",
"arise",
"spontaneously",
"via",
"page",
"templates",
"rather",
"than",
"being",
"hardcoded",
"in",
"the",
"schema",
".",
"The",
"rule",
"is",
"that",
"if",
"an",
"otherwise",
"unknown",
"property",
"is",
"an",
"object",
"with",
"a",
"type",
"sub",
"-",
"property",
"set",
"to",
"area",
"that",
"is",
"accepted",
"and",
"sanitized",
"as",
"an",
"area",
"."
] | 72eb4b1df351b1c253e9b1c2bd2fe3fff6eb71b3 | https://github.com/apostrophecms-legacy/apostrophe-pages/blob/72eb4b1df351b1c253e9b1c2bd2fe3fff6eb71b3/index.js#L1760-L1790 | train |
apostrophecms-legacy/apostrophe-pages | index.js | diffVersions | function diffVersions(callback) {
var prior = null;
_.each(versions, function(version) {
if (!prior) {
version.diff = [ { value: '[NEW]', added: true } ];
} else {
version.diff = apos.diffPages(prior, version);
}
prior = version;
});
versions.reverse();
return callback(null);
} | javascript | function diffVersions(callback) {
var prior = null;
_.each(versions, function(version) {
if (!prior) {
version.diff = [ { value: '[NEW]', added: true } ];
} else {
version.diff = apos.diffPages(prior, version);
}
prior = version;
});
versions.reverse();
return callback(null);
} | [
"function",
"diffVersions",
"(",
"callback",
")",
"{",
"var",
"prior",
"=",
"null",
";",
"_",
".",
"each",
"(",
"versions",
",",
"function",
"(",
"version",
")",
"{",
"if",
"(",
"!",
"prior",
")",
"{",
"version",
".",
"diff",
"=",
"[",
"{",
"value",
":",
"'[NEW]'",
",",
"added",
":",
"true",
"}",
"]",
";",
"}",
"else",
"{",
"version",
".",
"diff",
"=",
"apos",
".",
"diffPages",
"(",
"prior",
",",
"version",
")",
";",
"}",
"prior",
"=",
"version",
";",
"}",
")",
";",
"versions",
".",
"reverse",
"(",
")",
";",
"return",
"callback",
"(",
"null",
")",
";",
"}"
] | We must diff on the fly because versions get pruned over time | [
"We",
"must",
"diff",
"on",
"the",
"fly",
"because",
"versions",
"get",
"pruned",
"over",
"time"
] | 72eb4b1df351b1c253e9b1c2bd2fe3fff6eb71b3 | https://github.com/apostrophecms-legacy/apostrophe-pages/blob/72eb4b1df351b1c253e9b1c2bd2fe3fff6eb71b3/index.js#L2226-L2238 | train |
grasshopper-cms/grasshopper-core-nodejs | lib/db/mongodb/nodes.js | getId | function getId(id){
if(_.isObject(id) && !_.isUndefined(id.id)){
if (objectIdRegex.test(id.id)) {
id = id.id;
}
else {
id = null;
}
}
return id;
} | javascript | function getId(id){
if(_.isObject(id) && !_.isUndefined(id.id)){
if (objectIdRegex.test(id.id)) {
id = id.id;
}
else {
id = null;
}
}
return id;
} | [
"function",
"getId",
"(",
"id",
")",
"{",
"if",
"(",
"_",
".",
"isObject",
"(",
"id",
")",
"&&",
"!",
"_",
".",
"isUndefined",
"(",
"id",
".",
"id",
")",
")",
"{",
"if",
"(",
"objectIdRegex",
".",
"test",
"(",
"id",
".",
"id",
")",
")",
"{",
"id",
"=",
"id",
".",
"id",
";",
"}",
"else",
"{",
"id",
"=",
"null",
";",
"}",
"}",
"return",
"id",
";",
"}"
] | Function will look at the id that has been passed to the module and
if it is a string send it back, if it is an object with an `id` property
then it will check to see if it is a valid mongo objectid format and then
send it back.
@param id
@returns {*} | [
"Function",
"will",
"look",
"at",
"the",
"id",
"that",
"has",
"been",
"passed",
"to",
"the",
"module",
"and",
"if",
"it",
"is",
"a",
"string",
"send",
"it",
"back",
"if",
"it",
"is",
"an",
"object",
"with",
"an",
"id",
"property",
"then",
"it",
"will",
"check",
"to",
"see",
"if",
"it",
"is",
"a",
"valid",
"mongo",
"objectid",
"format",
"and",
"then",
"send",
"it",
"back",
"."
] | 8fabc3bfc5b18855ead443db0644608a277d0ea0 | https://github.com/grasshopper-cms/grasshopper-core-nodejs/blob/8fabc3bfc5b18855ead443db0644608a277d0ea0/lib/db/mongodb/nodes.js#L30-L40 | train |
grasshopper-cms/grasshopper-core-nodejs | dev/server/public/admin/vendor/svg-edit-2.7/extensions/ext-connector.js | init | function init() {
// Make sure all connectors have data set
$(svgcontent).find('*').each(function() {
var conn = this.getAttributeNS(se_ns, "connector");
if(conn) {
this.setAttribute('class', conn_sel.substr(1));
var conn_data = conn.split(' ');
var sbb = svgCanvas.getStrokedBBox([getElem(conn_data[0])]);
var ebb = svgCanvas.getStrokedBBox([getElem(conn_data[1])]);
$(this).data('c_start',conn_data[0])
.data('c_end',conn_data[1])
.data('start_bb', sbb)
.data('end_bb', ebb);
svgCanvas.getEditorNS(true);
}
});
// updateConnectors();
} | javascript | function init() {
// Make sure all connectors have data set
$(svgcontent).find('*').each(function() {
var conn = this.getAttributeNS(se_ns, "connector");
if(conn) {
this.setAttribute('class', conn_sel.substr(1));
var conn_data = conn.split(' ');
var sbb = svgCanvas.getStrokedBBox([getElem(conn_data[0])]);
var ebb = svgCanvas.getStrokedBBox([getElem(conn_data[1])]);
$(this).data('c_start',conn_data[0])
.data('c_end',conn_data[1])
.data('start_bb', sbb)
.data('end_bb', ebb);
svgCanvas.getEditorNS(true);
}
});
// updateConnectors();
} | [
"function",
"init",
"(",
")",
"{",
"$",
"(",
"svgcontent",
")",
".",
"find",
"(",
"'*'",
")",
".",
"each",
"(",
"function",
"(",
")",
"{",
"var",
"conn",
"=",
"this",
".",
"getAttributeNS",
"(",
"se_ns",
",",
"\"connector\"",
")",
";",
"if",
"(",
"conn",
")",
"{",
"this",
".",
"setAttribute",
"(",
"'class'",
",",
"conn_sel",
".",
"substr",
"(",
"1",
")",
")",
";",
"var",
"conn_data",
"=",
"conn",
".",
"split",
"(",
"' '",
")",
";",
"var",
"sbb",
"=",
"svgCanvas",
".",
"getStrokedBBox",
"(",
"[",
"getElem",
"(",
"conn_data",
"[",
"0",
"]",
")",
"]",
")",
";",
"var",
"ebb",
"=",
"svgCanvas",
".",
"getStrokedBBox",
"(",
"[",
"getElem",
"(",
"conn_data",
"[",
"1",
"]",
")",
"]",
")",
";",
"$",
"(",
"this",
")",
".",
"data",
"(",
"'c_start'",
",",
"conn_data",
"[",
"0",
"]",
")",
".",
"data",
"(",
"'c_end'",
",",
"conn_data",
"[",
"1",
"]",
")",
".",
"data",
"(",
"'start_bb'",
",",
"sbb",
")",
".",
"data",
"(",
"'end_bb'",
",",
"ebb",
")",
";",
"svgCanvas",
".",
"getEditorNS",
"(",
"true",
")",
";",
"}",
"}",
")",
";",
"}"
] | Do on reset | [
"Do",
"on",
"reset"
] | 8fabc3bfc5b18855ead443db0644608a277d0ea0 | https://github.com/grasshopper-cms/grasshopper-core-nodejs/blob/8fabc3bfc5b18855ead443db0644608a277d0ea0/dev/server/public/admin/vendor/svg-edit-2.7/extensions/ext-connector.js#L274-L291 | train |
matmanjs/matman | packages/matman-crawler/asserts/nightmare-preload.js | error | function error(err) {
if (!(err instanceof Error)) return err
return {
code: err.code,
message: err.message,
details: err.detail,
stack: err.stack || ''
}
} | javascript | function error(err) {
if (!(err instanceof Error)) return err
return {
code: err.code,
message: err.message,
details: err.detail,
stack: err.stack || ''
}
} | [
"function",
"error",
"(",
"err",
")",
"{",
"if",
"(",
"!",
"(",
"err",
"instanceof",
"Error",
")",
")",
"return",
"err",
"return",
"{",
"code",
":",
"err",
".",
"code",
",",
"message",
":",
"err",
".",
"message",
",",
"details",
":",
"err",
".",
"detail",
",",
"stack",
":",
"err",
".",
"stack",
"||",
"''",
"}",
"}"
] | Make errors serializeable | [
"Make",
"errors",
"serializeable"
] | 2ffe0760aba4d8ccb45f056bb1aa1b8429e2c89a | https://github.com/matmanjs/matman/blob/2ffe0760aba4d8ccb45f056bb1aa1b8429e2c89a/packages/matman-crawler/asserts/nightmare-preload.js#L106-L114 | train |
stratumn/js-chainscript | src/proto/chainscript_pb.js | Segment | function Segment(properties) {
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 Segment(properties) {
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",
"Segment",
"(",
"properties",
")",
"{",
"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 Segment.
@memberof stratumn.chainscript
@interface ISegment
@property {stratumn.chainscript.ILink|null} [link] Segment link
@property {stratumn.chainscript.ISegmentMeta|null} [meta] Segment meta
Constructs a new Segment.
@memberof stratumn.chainscript
@classdesc Represents a Segment.
@implements ISegment
@constructor
@param {stratumn.chainscript.ISegment=} [properties] Properties to set | [
"Properties",
"of",
"a",
"Segment",
"."
] | 1aba9933f18107d6d66c0b559cb07255e6398cdb | https://github.com/stratumn/js-chainscript/blob/1aba9933f18107d6d66c0b559cb07255e6398cdb/src/proto/chainscript_pb.js#L48-L53 | train |
stratumn/js-chainscript | src/proto/chainscript_pb.js | SegmentMeta | function SegmentMeta(properties) {
this.evidences = [];
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 SegmentMeta(properties) {
this.evidences = [];
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",
"SegmentMeta",
"(",
"properties",
")",
"{",
"this",
".",
"evidences",
"=",
"[",
"]",
";",
"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 SegmentMeta.
@memberof stratumn.chainscript
@interface ISegmentMeta
@property {Uint8Array|null} [linkHash] SegmentMeta linkHash
@property {Array.<stratumn.chainscript.IEvidence>|null} [evidences] SegmentMeta evidences
Constructs a new SegmentMeta.
@memberof stratumn.chainscript
@classdesc Represents a SegmentMeta.
@implements ISegmentMeta
@constructor
@param {stratumn.chainscript.ISegmentMeta=} [properties] Properties to set | [
"Properties",
"of",
"a",
"SegmentMeta",
"."
] | 1aba9933f18107d6d66c0b559cb07255e6398cdb | https://github.com/stratumn/js-chainscript/blob/1aba9933f18107d6d66c0b559cb07255e6398cdb/src/proto/chainscript_pb.js#L268-L274 | train |
stratumn/js-chainscript | src/proto/chainscript_pb.js | Evidence | function Evidence(properties) {
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 Evidence(properties) {
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",
"Evidence",
"(",
"properties",
")",
"{",
"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 an Evidence.
@memberof stratumn.chainscript
@interface IEvidence
@property {string|null} [version] Evidence version
@property {string|null} [backend] Evidence backend
@property {string|null} [provider] Evidence provider
@property {Uint8Array|null} [proof] Evidence proof
Constructs a new Evidence.
@memberof stratumn.chainscript
@classdesc Represents an Evidence.
@implements IEvidence
@constructor
@param {stratumn.chainscript.IEvidence=} [properties] Properties to set | [
"Properties",
"of",
"an",
"Evidence",
"."
] | 1aba9933f18107d6d66c0b559cb07255e6398cdb | https://github.com/stratumn/js-chainscript/blob/1aba9933f18107d6d66c0b559cb07255e6398cdb/src/proto/chainscript_pb.js#L510-L515 | train |
stratumn/js-chainscript | src/proto/chainscript_pb.js | Link | function Link(properties) {
this.signatures = [];
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 Link(properties) {
this.signatures = [];
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",
"Link",
"(",
"properties",
")",
"{",
"this",
".",
"signatures",
"=",
"[",
"]",
";",
"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 Link.
@memberof stratumn.chainscript
@interface ILink
@property {string|null} [version] Link version
@property {Uint8Array|null} [data] Link data
@property {stratumn.chainscript.ILinkMeta|null} [meta] Link meta
@property {Array.<stratumn.chainscript.ISignature>|null} [signatures] Link signatures
Constructs a new Link.
@memberof stratumn.chainscript
@classdesc Represents a Link.
@implements ILink
@constructor
@param {stratumn.chainscript.ILink=} [properties] Properties to set | [
"Properties",
"of",
"a",
"Link",
"."
] | 1aba9933f18107d6d66c0b559cb07255e6398cdb | https://github.com/stratumn/js-chainscript/blob/1aba9933f18107d6d66c0b559cb07255e6398cdb/src/proto/chainscript_pb.js#L773-L779 | train |
stratumn/js-chainscript | src/proto/chainscript_pb.js | Process | function Process(properties) {
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 Process(properties) {
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",
"Process",
"(",
"properties",
")",
"{",
"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 Process.
@memberof stratumn.chainscript
@interface IProcess
@property {string|null} [name] Process name
@property {string|null} [state] Process state
Constructs a new Process.
@memberof stratumn.chainscript
@classdesc Represents a Process.
@implements IProcess
@constructor
@param {stratumn.chainscript.IProcess=} [properties] Properties to set | [
"Properties",
"of",
"a",
"Process",
"."
] | 1aba9933f18107d6d66c0b559cb07255e6398cdb | https://github.com/stratumn/js-chainscript/blob/1aba9933f18107d6d66c0b559cb07255e6398cdb/src/proto/chainscript_pb.js#L1061-L1066 | train |
stratumn/js-chainscript | src/proto/chainscript_pb.js | LinkMeta | function LinkMeta(properties) {
this.refs = [];
this.tags = [];
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 LinkMeta(properties) {
this.refs = [];
this.tags = [];
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",
"LinkMeta",
"(",
"properties",
")",
"{",
"this",
".",
"refs",
"=",
"[",
"]",
";",
"this",
".",
"tags",
"=",
"[",
"]",
";",
"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 LinkMeta.
@memberof stratumn.chainscript
@interface ILinkMeta
@property {string|null} [clientId] LinkMeta clientId
@property {Uint8Array|null} [prevLinkHash] LinkMeta prevLinkHash
@property {number|null} [priority] LinkMeta priority
@property {Array.<stratumn.chainscript.ILinkReference>|null} [refs] LinkMeta refs
@property {number|null} [outDegree] LinkMeta outDegree
@property {stratumn.chainscript.IProcess|null} [process] LinkMeta process
@property {string|null} [mapId] LinkMeta mapId
@property {string|null} [action] LinkMeta action
@property {string|null} [step] LinkMeta step
@property {Array.<string>|null} [tags] LinkMeta tags
@property {Uint8Array|null} [data] LinkMeta data
Constructs a new LinkMeta.
@memberof stratumn.chainscript
@classdesc Represents a LinkMeta.
@implements ILinkMeta
@constructor
@param {stratumn.chainscript.ILinkMeta=} [properties] Properties to set | [
"Properties",
"of",
"a",
"LinkMeta",
"."
] | 1aba9933f18107d6d66c0b559cb07255e6398cdb | https://github.com/stratumn/js-chainscript/blob/1aba9933f18107d6d66c0b559cb07255e6398cdb/src/proto/chainscript_pb.js#L1280-L1287 | train |
stratumn/js-chainscript | src/proto/chainscript_pb.js | LinkReference | function LinkReference(properties) {
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 LinkReference(properties) {
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",
"LinkReference",
"(",
"properties",
")",
"{",
"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 LinkReference.
@memberof stratumn.chainscript
@interface ILinkReference
@property {Uint8Array|null} [linkHash] LinkReference linkHash
@property {string|null} [process] LinkReference process
Constructs a new LinkReference.
@memberof stratumn.chainscript
@classdesc Represents a LinkReference.
@implements ILinkReference
@constructor
@param {stratumn.chainscript.ILinkReference=} [properties] Properties to set | [
"Properties",
"of",
"a",
"LinkReference",
"."
] | 1aba9933f18107d6d66c0b559cb07255e6398cdb | https://github.com/stratumn/js-chainscript/blob/1aba9933f18107d6d66c0b559cb07255e6398cdb/src/proto/chainscript_pb.js#L1741-L1746 | train |
stratumn/js-chainscript | src/proto/chainscript_pb.js | Signature | function Signature(properties) {
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 Signature(properties) {
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",
"Signature",
"(",
"properties",
")",
"{",
"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 Signature.
@memberof stratumn.chainscript
@interface ISignature
@property {string|null} [version] Signature version
@property {string|null} [type] Signature type
@property {string|null} [payloadPath] Signature payloadPath
@property {Uint8Array|null} [publicKey] Signature publicKey
@property {Uint8Array|null} [signature] Signature signature
Constructs a new Signature.
@memberof stratumn.chainscript
@classdesc Represents a Signature.
@implements ISignature
@constructor
@param {stratumn.chainscript.ISignature=} [properties] Properties to set | [
"Properties",
"of",
"a",
"Signature",
"."
] | 1aba9933f18107d6d66c0b559cb07255e6398cdb | https://github.com/stratumn/js-chainscript/blob/1aba9933f18107d6d66c0b559cb07255e6398cdb/src/proto/chainscript_pb.js#L1963-L1968 | train |
grasshopper-cms/grasshopper-core-nodejs | lib/middleware/assets/index.js | proxy | function proxy(func){
'use strict';
// Returns a middleware
return function (kontx, next){
func(kontx.args).then(
function(payload){
kontx.payload = payload;
next();
},
function(err){
next(err);
}
);
};
} | javascript | function proxy(func){
'use strict';
// Returns a middleware
return function (kontx, next){
func(kontx.args).then(
function(payload){
kontx.payload = payload;
next();
},
function(err){
next(err);
}
);
};
} | [
"function",
"proxy",
"(",
"func",
")",
"{",
"'use strict'",
";",
"return",
"function",
"(",
"kontx",
",",
"next",
")",
"{",
"func",
"(",
"kontx",
".",
"args",
")",
".",
"then",
"(",
"function",
"(",
"payload",
")",
"{",
"kontx",
".",
"payload",
"=",
"payload",
";",
"next",
"(",
")",
";",
"}",
",",
"function",
"(",
"err",
")",
"{",
"next",
"(",
"err",
")",
";",
"}",
")",
";",
"}",
";",
"}"
] | Proxy function will take a assets function and wrap it with a middleware.
@param func
@returns {Function} | [
"Proxy",
"function",
"will",
"take",
"a",
"assets",
"function",
"and",
"wrap",
"it",
"with",
"a",
"middleware",
"."
] | 8fabc3bfc5b18855ead443db0644608a277d0ea0 | https://github.com/grasshopper-cms/grasshopper-core-nodejs/blob/8fabc3bfc5b18855ead443db0644608a277d0ea0/lib/middleware/assets/index.js#L9-L24 | train |
grasshopper-cms/grasshopper-core-nodejs | docs/js/vendor/flipclock/flipclock.js | function(index, obj) {
var lang = this.lang;
var lindex = index.toLowerCase();
if(typeof obj == "object") {
lang = obj;
}
if(lang && lang[lindex]) {
return lang[lindex];
}
return index;
} | javascript | function(index, obj) {
var lang = this.lang;
var lindex = index.toLowerCase();
if(typeof obj == "object") {
lang = obj;
}
if(lang && lang[lindex]) {
return lang[lindex];
}
return index;
} | [
"function",
"(",
"index",
",",
"obj",
")",
"{",
"var",
"lang",
"=",
"this",
".",
"lang",
";",
"var",
"lindex",
"=",
"index",
".",
"toLowerCase",
"(",
")",
";",
"if",
"(",
"typeof",
"obj",
"==",
"\"object\"",
")",
"{",
"lang",
"=",
"obj",
";",
"}",
"if",
"(",
"lang",
"&&",
"lang",
"[",
"lindex",
"]",
")",
"{",
"return",
"lang",
"[",
"lindex",
"]",
";",
"}",
"return",
"index",
";",
"}"
] | Localize strings into various languages
@param string The index of the localized string
@param object Optionally pass a lang object | [
"Localize",
"strings",
"into",
"various",
"languages"
] | 8fabc3bfc5b18855ead443db0644608a277d0ea0 | https://github.com/grasshopper-cms/grasshopper-core-nodejs/blob/8fabc3bfc5b18855ead443db0644608a277d0ea0/docs/js/vendor/flipclock/flipclock.js#L354-L367 | train |
|
grasshopper-cms/grasshopper-core-nodejs | docs/js/vendor/flipclock/flipclock.js | function(callback) {
this.face.stop();
this.timer.stop(callback);
for(var x in this.lists) {
this.lists[x].stop();
}
} | javascript | function(callback) {
this.face.stop();
this.timer.stop(callback);
for(var x in this.lists) {
this.lists[x].stop();
}
} | [
"function",
"(",
"callback",
")",
"{",
"this",
".",
"face",
".",
"stop",
"(",
")",
";",
"this",
".",
"timer",
".",
"stop",
"(",
"callback",
")",
";",
"for",
"(",
"var",
"x",
"in",
"this",
".",
"lists",
")",
"{",
"this",
".",
"lists",
"[",
"x",
"]",
".",
"stop",
"(",
")",
";",
"}",
"}"
] | Stops the clock | [
"Stops",
"the",
"clock"
] | 8fabc3bfc5b18855ead443db0644608a277d0ea0 | https://github.com/grasshopper-cms/grasshopper-core-nodejs/blob/8fabc3bfc5b18855ead443db0644608a277d0ea0/docs/js/vendor/flipclock/flipclock.js#L396-L403 | train |
|
grasshopper-cms/grasshopper-core-nodejs | docs/js/vendor/flipclock/flipclock.js | function(label, css, excludeDots) {
if(typeof css == "boolean" || !css) {
excludeDots = css;
css = label;
}
var dots = [
'<span class="'+this.factory.classes.dot+' top"></span>',
'<span class="'+this.factory.classes.dot+' bottom"></span>'
].join('');
if(excludeDots) {
dots = '';
}
label = this.factory.localize(label);
var html = [
'<span class="'+this.factory.classes.divider+' '+(css ? css : '').toLowerCase()+'">',
'<span class="'+this.factory.classes.label+'">'+(label ? label : '')+'</span>',
dots,
'</span>'
];
return $(html.join(''));
} | javascript | function(label, css, excludeDots) {
if(typeof css == "boolean" || !css) {
excludeDots = css;
css = label;
}
var dots = [
'<span class="'+this.factory.classes.dot+' top"></span>',
'<span class="'+this.factory.classes.dot+' bottom"></span>'
].join('');
if(excludeDots) {
dots = '';
}
label = this.factory.localize(label);
var html = [
'<span class="'+this.factory.classes.divider+' '+(css ? css : '').toLowerCase()+'">',
'<span class="'+this.factory.classes.label+'">'+(label ? label : '')+'</span>',
dots,
'</span>'
];
return $(html.join(''));
} | [
"function",
"(",
"label",
",",
"css",
",",
"excludeDots",
")",
"{",
"if",
"(",
"typeof",
"css",
"==",
"\"boolean\"",
"||",
"!",
"css",
")",
"{",
"excludeDots",
"=",
"css",
";",
"css",
"=",
"label",
";",
"}",
"var",
"dots",
"=",
"[",
"'<span class=\"'",
"+",
"this",
".",
"factory",
".",
"classes",
".",
"dot",
"+",
"' top\"></span>'",
",",
"'<span class=\"'",
"+",
"this",
".",
"factory",
".",
"classes",
".",
"dot",
"+",
"' bottom\"></span>'",
"]",
".",
"join",
"(",
"''",
")",
";",
"if",
"(",
"excludeDots",
")",
"{",
"dots",
"=",
"''",
";",
"}",
"label",
"=",
"this",
".",
"factory",
".",
"localize",
"(",
"label",
")",
";",
"var",
"html",
"=",
"[",
"'<span class=\"'",
"+",
"this",
".",
"factory",
".",
"classes",
".",
"divider",
"+",
"' '",
"+",
"(",
"css",
"?",
"css",
":",
"''",
")",
".",
"toLowerCase",
"(",
")",
"+",
"'\">'",
",",
"'<span class=\"'",
"+",
"this",
".",
"factory",
".",
"classes",
".",
"label",
"+",
"'\">'",
"+",
"(",
"label",
"?",
"label",
":",
"''",
")",
"+",
"'</span>'",
",",
"dots",
",",
"'</span>'",
"]",
";",
"return",
"$",
"(",
"html",
".",
"join",
"(",
"''",
")",
")",
";",
"}"
] | Creates a jQuery object used for the digit divider
@param mixed The divider label text
@param mixed Set true to exclude the dots in the divider.
If not set, is false. | [
"Creates",
"a",
"jQuery",
"object",
"used",
"for",
"the",
"digit",
"divider"
] | 8fabc3bfc5b18855ead443db0644608a277d0ea0 | https://github.com/grasshopper-cms/grasshopper-core-nodejs/blob/8fabc3bfc5b18855ead443db0644608a277d0ea0/docs/js/vendor/flipclock/flipclock.js#L514-L540 | train |
|
grasshopper-cms/grasshopper-core-nodejs | docs/js/vendor/flipclock/flipclock.js | function(digit) {
var obj = this.createList(digit, {
classes: {
active: this.factory.classes.active,
before: this.factory.classes.before,
flip: this.factory.classes.flip
}
});
obj.$obj.insertBefore(this.factory.lists[0].$obj);
this.factory.lists.unshift(obj);
} | javascript | function(digit) {
var obj = this.createList(digit, {
classes: {
active: this.factory.classes.active,
before: this.factory.classes.before,
flip: this.factory.classes.flip
}
});
obj.$obj.insertBefore(this.factory.lists[0].$obj);
this.factory.lists.unshift(obj);
} | [
"function",
"(",
"digit",
")",
"{",
"var",
"obj",
"=",
"this",
".",
"createList",
"(",
"digit",
",",
"{",
"classes",
":",
"{",
"active",
":",
"this",
".",
"factory",
".",
"classes",
".",
"active",
",",
"before",
":",
"this",
".",
"factory",
".",
"classes",
".",
"before",
",",
"flip",
":",
"this",
".",
"factory",
".",
"classes",
".",
"flip",
"}",
"}",
")",
";",
"obj",
".",
"$obj",
".",
"insertBefore",
"(",
"this",
".",
"factory",
".",
"lists",
"[",
"0",
"]",
".",
"$obj",
")",
";",
"this",
".",
"factory",
".",
"lists",
".",
"unshift",
"(",
"obj",
")",
";",
"}"
] | Sets the clock time | [
"Sets",
"the",
"clock",
"time"
] | 8fabc3bfc5b18855ead443db0644608a277d0ea0 | https://github.com/grasshopper-cms/grasshopper-core-nodejs/blob/8fabc3bfc5b18855ead443db0644608a277d0ea0/docs/js/vendor/flipclock/flipclock.js#L580-L592 | train |
|
grasshopper-cms/grasshopper-core-nodejs | docs/js/vendor/flipclock/flipclock.js | function() {
var t = this;
setTimeout(function() {
t.$obj.removeClass(t.factory.classes.play);
}, this.factory.timer.interval);
} | javascript | function() {
var t = this;
setTimeout(function() {
t.$obj.removeClass(t.factory.classes.play);
}, this.factory.timer.interval);
} | [
"function",
"(",
")",
"{",
"var",
"t",
"=",
"this",
";",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"t",
".",
"$obj",
".",
"removeClass",
"(",
"t",
".",
"factory",
".",
"classes",
".",
"play",
")",
";",
"}",
",",
"this",
".",
"factory",
".",
"timer",
".",
"interval",
")",
";",
"}"
] | Removes the play class to the DOM object | [
"Removes",
"the",
"play",
"class",
"to",
"the",
"DOM",
"object"
] | 8fabc3bfc5b18855ead443db0644608a277d0ea0 | https://github.com/grasshopper-cms/grasshopper-core-nodejs/blob/8fabc3bfc5b18855ead443db0644608a277d0ea0/docs/js/vendor/flipclock/flipclock.js#L781-L787 | train |
|
grasshopper-cms/grasshopper-core-nodejs | lib/db/mongodb/schemas/contentType.js | validateFieldType | function validateFieldType(fieldsCollection){
var err;
// ensure fieldsCollection is an array.
if(!_.isArray(fieldsCollection)) {
err = new Error('content type fields collection must be an array of field objects.');
}
if(!err) {
_.each(fieldsCollection, function(field){
err = isValidField(field);
});
}
return _.isUndefined(err);
} | javascript | function validateFieldType(fieldsCollection){
var err;
// ensure fieldsCollection is an array.
if(!_.isArray(fieldsCollection)) {
err = new Error('content type fields collection must be an array of field objects.');
}
if(!err) {
_.each(fieldsCollection, function(field){
err = isValidField(field);
});
}
return _.isUndefined(err);
} | [
"function",
"validateFieldType",
"(",
"fieldsCollection",
")",
"{",
"var",
"err",
";",
"if",
"(",
"!",
"_",
".",
"isArray",
"(",
"fieldsCollection",
")",
")",
"{",
"err",
"=",
"new",
"Error",
"(",
"'content type fields collection must be an array of field objects.'",
")",
";",
"}",
"if",
"(",
"!",
"err",
")",
"{",
"_",
".",
"each",
"(",
"fieldsCollection",
",",
"function",
"(",
"field",
")",
"{",
"err",
"=",
"isValidField",
"(",
"field",
")",
";",
"}",
")",
";",
"}",
"return",
"_",
".",
"isUndefined",
"(",
"err",
")",
";",
"}"
] | In order to be valid we are checking the following rules
1) Collection must be an instance of an array
2) Does the element in the Collection array have all of the necessary properties
3) Are there any duplicate ids
@param value
@returns {null} | [
"In",
"order",
"to",
"be",
"valid",
"we",
"are",
"checking",
"the",
"following",
"rules",
"1",
")",
"Collection",
"must",
"be",
"an",
"instance",
"of",
"an",
"array",
"2",
")",
"Does",
"the",
"element",
"in",
"the",
"Collection",
"array",
"have",
"all",
"of",
"the",
"necessary",
"properties",
"3",
")",
"Are",
"there",
"any",
"duplicate",
"ids"
] | 8fabc3bfc5b18855ead443db0644608a277d0ea0 | https://github.com/grasshopper-cms/grasshopper-core-nodejs/blob/8fabc3bfc5b18855ead443db0644608a277d0ea0/lib/db/mongodb/schemas/contentType.js#L70-L85 | train |
grasshopper-cms/grasshopper-core-nodejs | lib/security/providers/twitter.js | _setUserInfoFromSocialAccount | function _setUserInfoFromSocialAccount(){
return db.users.socialAuthentication('twitter', this.socialUserInfo.id_str)
.then(function(user){
this.userInfo = user;
}.bind(this))
.catch(function(err){ // If user isn't found surpress error. If found and still error then throw.
if(err.code !== 404){
throw(err);
}
});
} | javascript | function _setUserInfoFromSocialAccount(){
return db.users.socialAuthentication('twitter', this.socialUserInfo.id_str)
.then(function(user){
this.userInfo = user;
}.bind(this))
.catch(function(err){ // If user isn't found surpress error. If found and still error then throw.
if(err.code !== 404){
throw(err);
}
});
} | [
"function",
"_setUserInfoFromSocialAccount",
"(",
")",
"{",
"return",
"db",
".",
"users",
".",
"socialAuthentication",
"(",
"'twitter'",
",",
"this",
".",
"socialUserInfo",
".",
"id_str",
")",
".",
"then",
"(",
"function",
"(",
"user",
")",
"{",
"this",
".",
"userInfo",
"=",
"user",
";",
"}",
".",
"bind",
"(",
"this",
")",
")",
".",
"catch",
"(",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
".",
"code",
"!==",
"404",
")",
"{",
"throw",
"(",
"err",
")",
";",
"}",
"}",
")",
";",
"}"
] | Function will look up a user by their social id and then assign it to the userInfo object | [
"Function",
"will",
"look",
"up",
"a",
"user",
"by",
"their",
"social",
"id",
"and",
"then",
"assign",
"it",
"to",
"the",
"userInfo",
"object"
] | 8fabc3bfc5b18855ead443db0644608a277d0ea0 | https://github.com/grasshopper-cms/grasshopper-core-nodejs/blob/8fabc3bfc5b18855ead443db0644608a277d0ea0/lib/security/providers/twitter.js#L48-L58 | train |
grasshopper-cms/grasshopper-core-nodejs | lib/grasshopper.js | function(token){
return {
users: require('./runners/users')(token),
tokens: require('./runners/tokens')(token),
content: require('./runners/content')(token),
contentTypes: require('./runners/contentTypes')(token),
nodes: require('./runners/nodes')(token),
assets: require('./runners/assets')(token),
system: require('./runners/system')(token)
};
} | javascript | function(token){
return {
users: require('./runners/users')(token),
tokens: require('./runners/tokens')(token),
content: require('./runners/content')(token),
contentTypes: require('./runners/contentTypes')(token),
nodes: require('./runners/nodes')(token),
assets: require('./runners/assets')(token),
system: require('./runners/system')(token)
};
} | [
"function",
"(",
"token",
")",
"{",
"return",
"{",
"users",
":",
"require",
"(",
"'./runners/users'",
")",
"(",
"token",
")",
",",
"tokens",
":",
"require",
"(",
"'./runners/tokens'",
")",
"(",
"token",
")",
",",
"content",
":",
"require",
"(",
"'./runners/content'",
")",
"(",
"token",
")",
",",
"contentTypes",
":",
"require",
"(",
"'./runners/contentTypes'",
")",
"(",
"token",
")",
",",
"nodes",
":",
"require",
"(",
"'./runners/nodes'",
")",
"(",
"token",
")",
",",
"assets",
":",
"require",
"(",
"'./runners/assets'",
")",
"(",
"token",
")",
",",
"system",
":",
"require",
"(",
"'./runners/system'",
")",
"(",
"token",
")",
"}",
";",
"}"
] | The grasshopper request function will return back an object that can execute calls to the system.
If you are making an authenticated call then you should send in your token. If you are making a
public call then don't pass in an argument.
@param token
@returns {{users: *, tokens: *, content: *, contentTypes: *, nodes: *}} | [
"The",
"grasshopper",
"request",
"function",
"will",
"return",
"back",
"an",
"object",
"that",
"can",
"execute",
"calls",
"to",
"the",
"system",
".",
"If",
"you",
"are",
"making",
"an",
"authenticated",
"call",
"then",
"you",
"should",
"send",
"in",
"your",
"token",
".",
"If",
"you",
"are",
"making",
"a",
"public",
"call",
"then",
"don",
"t",
"pass",
"in",
"an",
"argument",
"."
] | 8fabc3bfc5b18855ead443db0644608a277d0ea0 | https://github.com/grasshopper-cms/grasshopper-core-nodejs/blob/8fabc3bfc5b18855ead443db0644608a277d0ea0/lib/grasshopper.js#L57-L67 | train |
|
EasyGraphQL/easygraphql-parser | lib/schemaParser.js | findType | function findType (node, typeInfo, nestedCall) {
typeInfo = typeInfo || { noNull: false, isArray: false, noNullArrayValues: false }
if (!node) {
return typeInfo
}
// Validate nested call, the parser will check first if the array can be null
// then it will check if the values inside can be null
if (!nestedCall && node.kind === 'NonNullType') {
typeInfo.noNull = true
}
// If it is an array, validate if the values inside can be null
if (nestedCall && typeInfo.isArray && node.kind === 'NonNullType') {
typeInfo.noNullArrayValues = true
}
if (node.kind === 'ListType') {
typeInfo.isArray = true
}
if (node.name) {
typeInfo.type = node.name.value
}
return findType(node.type, typeInfo, true)
} | javascript | function findType (node, typeInfo, nestedCall) {
typeInfo = typeInfo || { noNull: false, isArray: false, noNullArrayValues: false }
if (!node) {
return typeInfo
}
// Validate nested call, the parser will check first if the array can be null
// then it will check if the values inside can be null
if (!nestedCall && node.kind === 'NonNullType') {
typeInfo.noNull = true
}
// If it is an array, validate if the values inside can be null
if (nestedCall && typeInfo.isArray && node.kind === 'NonNullType') {
typeInfo.noNullArrayValues = true
}
if (node.kind === 'ListType') {
typeInfo.isArray = true
}
if (node.name) {
typeInfo.type = node.name.value
}
return findType(node.type, typeInfo, true)
} | [
"function",
"findType",
"(",
"node",
",",
"typeInfo",
",",
"nestedCall",
")",
"{",
"typeInfo",
"=",
"typeInfo",
"||",
"{",
"noNull",
":",
"false",
",",
"isArray",
":",
"false",
",",
"noNullArrayValues",
":",
"false",
"}",
"if",
"(",
"!",
"node",
")",
"{",
"return",
"typeInfo",
"}",
"if",
"(",
"!",
"nestedCall",
"&&",
"node",
".",
"kind",
"===",
"'NonNullType'",
")",
"{",
"typeInfo",
".",
"noNull",
"=",
"true",
"}",
"if",
"(",
"nestedCall",
"&&",
"typeInfo",
".",
"isArray",
"&&",
"node",
".",
"kind",
"===",
"'NonNullType'",
")",
"{",
"typeInfo",
".",
"noNullArrayValues",
"=",
"true",
"}",
"if",
"(",
"node",
".",
"kind",
"===",
"'ListType'",
")",
"{",
"typeInfo",
".",
"isArray",
"=",
"true",
"}",
"if",
"(",
"node",
".",
"name",
")",
"{",
"typeInfo",
".",
"type",
"=",
"node",
".",
"name",
".",
"value",
"}",
"return",
"findType",
"(",
"node",
".",
"type",
",",
"typeInfo",
",",
"true",
")",
"}"
] | Find the type of a field on the Schema
@param node - The graph schema
@param typeInfo - The object with the recursive values
@returns {{type: String, noNull: Boolean, isArray: Boolean}} | [
"Find",
"the",
"type",
"of",
"a",
"field",
"on",
"the",
"Schema"
] | 6425e9a68647a90602e0eda7728ae0929c4f8539 | https://github.com/EasyGraphQL/easygraphql-parser/blob/6425e9a68647a90602e0eda7728ae0929c4f8539/lib/schemaParser.js#L79-L105 | train |
EasyGraphQL/easygraphql-parser | lib/schemaParser.js | findArguments | function findArguments (node) {
if (!node) {
return []
}
return node.map(arg => {
const name = arg.name.value
const fieldType = findType(arg.type)
const isDeprecated = validateIfDeprecated(arg.directives)
return Object.assign({ name, isDeprecated }, fieldType)
})
} | javascript | function findArguments (node) {
if (!node) {
return []
}
return node.map(arg => {
const name = arg.name.value
const fieldType = findType(arg.type)
const isDeprecated = validateIfDeprecated(arg.directives)
return Object.assign({ name, isDeprecated }, fieldType)
})
} | [
"function",
"findArguments",
"(",
"node",
")",
"{",
"if",
"(",
"!",
"node",
")",
"{",
"return",
"[",
"]",
"}",
"return",
"node",
".",
"map",
"(",
"arg",
"=>",
"{",
"const",
"name",
"=",
"arg",
".",
"name",
".",
"value",
"const",
"fieldType",
"=",
"findType",
"(",
"arg",
".",
"type",
")",
"const",
"isDeprecated",
"=",
"validateIfDeprecated",
"(",
"arg",
".",
"directives",
")",
"return",
"Object",
".",
"assign",
"(",
"{",
"name",
",",
"isDeprecated",
"}",
",",
"fieldType",
")",
"}",
")",
"}"
] | Find the arguments that are used on the Schema
@param node - The graph schema
@returns {[{name: String, noNull: Boolean, isArray: Boolean, type: String}]} | [
"Find",
"the",
"arguments",
"that",
"are",
"used",
"on",
"the",
"Schema"
] | 6425e9a68647a90602e0eda7728ae0929c4f8539 | https://github.com/EasyGraphQL/easygraphql-parser/blob/6425e9a68647a90602e0eda7728ae0929c4f8539/lib/schemaParser.js#L112-L124 | train |
EasyGraphQL/easygraphql-parser | lib/schemaParser.js | validateIfDeprecated | function validateIfDeprecated (directives) {
if (!directives.length) {
return false
}
return directives.some(directive => directive.name.value === 'deprecated')
} | javascript | function validateIfDeprecated (directives) {
if (!directives.length) {
return false
}
return directives.some(directive => directive.name.value === 'deprecated')
} | [
"function",
"validateIfDeprecated",
"(",
"directives",
")",
"{",
"if",
"(",
"!",
"directives",
".",
"length",
")",
"{",
"return",
"false",
"}",
"return",
"directives",
".",
"some",
"(",
"directive",
"=>",
"directive",
".",
"name",
".",
"value",
"===",
"'deprecated'",
")",
"}"
] | Check if a field is deprecated
@param directives - Receive the directives array
@returns {boolean} | [
"Check",
"if",
"a",
"field",
"is",
"deprecated"
] | 6425e9a68647a90602e0eda7728ae0929c4f8539 | https://github.com/EasyGraphQL/easygraphql-parser/blob/6425e9a68647a90602e0eda7728ae0929c4f8539/lib/schemaParser.js#L131-L137 | train |
aureooms/js-itertools | lib/reduce/min.js | min | function min(compare, iterable, dflt = undefined) {
let iterator = (0, _iter.iter)(iterable);
let first = iterator.next();
if (first.done) return dflt;
let smallest = first.value;
for (let candidate of iterator) {
if (compare(candidate, smallest) < 0) {
smallest = candidate;
}
}
return smallest;
} | javascript | function min(compare, iterable, dflt = undefined) {
let iterator = (0, _iter.iter)(iterable);
let first = iterator.next();
if (first.done) return dflt;
let smallest = first.value;
for (let candidate of iterator) {
if (compare(candidate, smallest) < 0) {
smallest = candidate;
}
}
return smallest;
} | [
"function",
"min",
"(",
"compare",
",",
"iterable",
",",
"dflt",
"=",
"undefined",
")",
"{",
"let",
"iterator",
"=",
"(",
"0",
",",
"_iter",
".",
"iter",
")",
"(",
"iterable",
")",
";",
"let",
"first",
"=",
"iterator",
".",
"next",
"(",
")",
";",
"if",
"(",
"first",
".",
"done",
")",
"return",
"dflt",
";",
"let",
"smallest",
"=",
"first",
".",
"value",
";",
"for",
"(",
"let",
"candidate",
"of",
"iterator",
")",
"{",
"if",
"(",
"compare",
"(",
"candidate",
",",
"smallest",
")",
"<",
"0",
")",
"{",
"smallest",
"=",
"candidate",
";",
"}",
"}",
"return",
"smallest",
";",
"}"
] | Returns the smallest element of the input iterable according
to some comparison function.
@example
min( ( a , b ) => a - b , range( 10 ) ) ; // returns 0
@example
min( ( a , b ) => a - b , range( 0 ) ) ; // returns undefined
@param {Function} compare - The comparison function to use. This function
must be 2-ary. It must return -1, 0, or 1 depending whether the first
parameter is, respectively, less than, equal to, or greater than the second
parameter.
@param {Iterable} iterable - The input iterable.
@param {Object} [dflt=undefined] - The default value to return in the case
that the input iterable is empty.
@returns {Object} The smallest element of <code>iterable</code> according to
<code>compare</code>. | [
"Returns",
"the",
"smallest",
"element",
"of",
"the",
"input",
"iterable",
"according",
"to",
"some",
"comparison",
"function",
"."
] | 72bafa5f3f957ceb37bdfa87a222364fe4974be3 | https://github.com/aureooms/js-itertools/blob/72bafa5f3f957ceb37bdfa87a222364fe4974be3/lib/reduce/min.js#L30-L49 | train |
syntax-tree/mdast-util-to-nlcst | index.js | toNLCST | function toNLCST(tree, file, Parser, options) {
var settings = options || {}
var parser
// Warn for invalid parameters.
if (!tree || !tree.type) {
throw new Error('mdast-util-to-nlcst expected node')
}
if (!file || !file.messages) {
throw new Error('mdast-util-to-nlcst expected file')
}
// Construct parser.
if (!Parser) {
throw new Error('mdast-util-to-nlcst expected parser')
}
if (
!tree.position ||
!tree.position.start ||
!tree.position.start.column ||
!tree.position.start.line
) {
throw new Error('mdast-util-to-nlcst expected position on nodes')
}
parser = 'parse' in Parser ? Parser : new Parser()
// Transform mdast into NLCST tokens, and pass these into `parser.parse` to
// insert sentences, paragraphs where needed.
return parser.parse(
one(
{
doc: String(file),
location: vfileLocation(file),
parser: parser,
ignore: ignore.concat(settings.ignore || []),
source: source.concat(settings.source || [])
},
tree
)
)
} | javascript | function toNLCST(tree, file, Parser, options) {
var settings = options || {}
var parser
// Warn for invalid parameters.
if (!tree || !tree.type) {
throw new Error('mdast-util-to-nlcst expected node')
}
if (!file || !file.messages) {
throw new Error('mdast-util-to-nlcst expected file')
}
// Construct parser.
if (!Parser) {
throw new Error('mdast-util-to-nlcst expected parser')
}
if (
!tree.position ||
!tree.position.start ||
!tree.position.start.column ||
!tree.position.start.line
) {
throw new Error('mdast-util-to-nlcst expected position on nodes')
}
parser = 'parse' in Parser ? Parser : new Parser()
// Transform mdast into NLCST tokens, and pass these into `parser.parse` to
// insert sentences, paragraphs where needed.
return parser.parse(
one(
{
doc: String(file),
location: vfileLocation(file),
parser: parser,
ignore: ignore.concat(settings.ignore || []),
source: source.concat(settings.source || [])
},
tree
)
)
} | [
"function",
"toNLCST",
"(",
"tree",
",",
"file",
",",
"Parser",
",",
"options",
")",
"{",
"var",
"settings",
"=",
"options",
"||",
"{",
"}",
"var",
"parser",
"if",
"(",
"!",
"tree",
"||",
"!",
"tree",
".",
"type",
")",
"{",
"throw",
"new",
"Error",
"(",
"'mdast-util-to-nlcst expected node'",
")",
"}",
"if",
"(",
"!",
"file",
"||",
"!",
"file",
".",
"messages",
")",
"{",
"throw",
"new",
"Error",
"(",
"'mdast-util-to-nlcst expected file'",
")",
"}",
"if",
"(",
"!",
"Parser",
")",
"{",
"throw",
"new",
"Error",
"(",
"'mdast-util-to-nlcst expected parser'",
")",
"}",
"if",
"(",
"!",
"tree",
".",
"position",
"||",
"!",
"tree",
".",
"position",
".",
"start",
"||",
"!",
"tree",
".",
"position",
".",
"start",
".",
"column",
"||",
"!",
"tree",
".",
"position",
".",
"start",
".",
"line",
")",
"{",
"throw",
"new",
"Error",
"(",
"'mdast-util-to-nlcst expected position on nodes'",
")",
"}",
"parser",
"=",
"'parse'",
"in",
"Parser",
"?",
"Parser",
":",
"new",
"Parser",
"(",
")",
"return",
"parser",
".",
"parse",
"(",
"one",
"(",
"{",
"doc",
":",
"String",
"(",
"file",
")",
",",
"location",
":",
"vfileLocation",
"(",
"file",
")",
",",
"parser",
":",
"parser",
",",
"ignore",
":",
"ignore",
".",
"concat",
"(",
"settings",
".",
"ignore",
"||",
"[",
"]",
")",
",",
"source",
":",
"source",
".",
"concat",
"(",
"settings",
".",
"source",
"||",
"[",
"]",
")",
"}",
",",
"tree",
")",
")",
"}"
] | Transform `tree` into `nlcst`. | [
"Transform",
"tree",
"into",
"nlcst",
"."
] | a827720d2e5d4f53aa44cc3a3231e4431b4ad4e0 | https://github.com/syntax-tree/mdast-util-to-nlcst/blob/a827720d2e5d4f53aa44cc3a3231e4431b4ad4e0/index.js#L17-L60 | train |
syntax-tree/mdast-util-to-nlcst | index.js | one | function one(config, node) {
var offset = config.location.toOffset
var parser = config.parser
var doc = config.doc
var type = node.type
var start = offset(position.start(node))
var end = offset(position.end(node))
if (config.ignore.indexOf(type) === -1) {
if (config.source.indexOf(type) !== -1) {
return patch(
config,
[parser.tokenizeSource(doc.slice(start, end))],
start
)
}
if (node.children) {
return all(config, node)
}
if (type === 'image' || type === 'imageReference') {
return patch(config, parser.tokenize(node.alt), start + 2)
}
if (type === 'text' || type === 'escape') {
return patch(config, parser.tokenize(node.value), start)
}
if (node.type === 'break') {
return patch(config, [parser.tokenizeWhiteSpace('\n')], start)
}
}
return null
} | javascript | function one(config, node) {
var offset = config.location.toOffset
var parser = config.parser
var doc = config.doc
var type = node.type
var start = offset(position.start(node))
var end = offset(position.end(node))
if (config.ignore.indexOf(type) === -1) {
if (config.source.indexOf(type) !== -1) {
return patch(
config,
[parser.tokenizeSource(doc.slice(start, end))],
start
)
}
if (node.children) {
return all(config, node)
}
if (type === 'image' || type === 'imageReference') {
return patch(config, parser.tokenize(node.alt), start + 2)
}
if (type === 'text' || type === 'escape') {
return patch(config, parser.tokenize(node.value), start)
}
if (node.type === 'break') {
return patch(config, [parser.tokenizeWhiteSpace('\n')], start)
}
}
return null
} | [
"function",
"one",
"(",
"config",
",",
"node",
")",
"{",
"var",
"offset",
"=",
"config",
".",
"location",
".",
"toOffset",
"var",
"parser",
"=",
"config",
".",
"parser",
"var",
"doc",
"=",
"config",
".",
"doc",
"var",
"type",
"=",
"node",
".",
"type",
"var",
"start",
"=",
"offset",
"(",
"position",
".",
"start",
"(",
"node",
")",
")",
"var",
"end",
"=",
"offset",
"(",
"position",
".",
"end",
"(",
"node",
")",
")",
"if",
"(",
"config",
".",
"ignore",
".",
"indexOf",
"(",
"type",
")",
"===",
"-",
"1",
")",
"{",
"if",
"(",
"config",
".",
"source",
".",
"indexOf",
"(",
"type",
")",
"!==",
"-",
"1",
")",
"{",
"return",
"patch",
"(",
"config",
",",
"[",
"parser",
".",
"tokenizeSource",
"(",
"doc",
".",
"slice",
"(",
"start",
",",
"end",
")",
")",
"]",
",",
"start",
")",
"}",
"if",
"(",
"node",
".",
"children",
")",
"{",
"return",
"all",
"(",
"config",
",",
"node",
")",
"}",
"if",
"(",
"type",
"===",
"'image'",
"||",
"type",
"===",
"'imageReference'",
")",
"{",
"return",
"patch",
"(",
"config",
",",
"parser",
".",
"tokenize",
"(",
"node",
".",
"alt",
")",
",",
"start",
"+",
"2",
")",
"}",
"if",
"(",
"type",
"===",
"'text'",
"||",
"type",
"===",
"'escape'",
")",
"{",
"return",
"patch",
"(",
"config",
",",
"parser",
".",
"tokenize",
"(",
"node",
".",
"value",
")",
",",
"start",
")",
"}",
"if",
"(",
"node",
".",
"type",
"===",
"'break'",
")",
"{",
"return",
"patch",
"(",
"config",
",",
"[",
"parser",
".",
"tokenizeWhiteSpace",
"(",
"'\\n'",
")",
"]",
",",
"\\n",
")",
"}",
"}",
"start",
"}"
] | Convert `node` into NLCST. | [
"Convert",
"node",
"into",
"NLCST",
"."
] | a827720d2e5d4f53aa44cc3a3231e4431b4ad4e0 | https://github.com/syntax-tree/mdast-util-to-nlcst/blob/a827720d2e5d4f53aa44cc3a3231e4431b4ad4e0/index.js#L63-L98 | train |
syntax-tree/mdast-util-to-nlcst | index.js | patch | function patch(config, nodes, offset) {
var position = config.location.toPosition
var length = nodes.length
var index = -1
var start = offset
var children
var node
var end
while (++index < length) {
node = nodes[index]
children = node.children
if (children) {
patch(config, children, start)
}
end = start + toString(node).length
node.position = {start: position(start), end: position(end)}
start = end
}
return nodes
} | javascript | function patch(config, nodes, offset) {
var position = config.location.toPosition
var length = nodes.length
var index = -1
var start = offset
var children
var node
var end
while (++index < length) {
node = nodes[index]
children = node.children
if (children) {
patch(config, children, start)
}
end = start + toString(node).length
node.position = {start: position(start), end: position(end)}
start = end
}
return nodes
} | [
"function",
"patch",
"(",
"config",
",",
"nodes",
",",
"offset",
")",
"{",
"var",
"position",
"=",
"config",
".",
"location",
".",
"toPosition",
"var",
"length",
"=",
"nodes",
".",
"length",
"var",
"index",
"=",
"-",
"1",
"var",
"start",
"=",
"offset",
"var",
"children",
"var",
"node",
"var",
"end",
"while",
"(",
"++",
"index",
"<",
"length",
")",
"{",
"node",
"=",
"nodes",
"[",
"index",
"]",
"children",
"=",
"node",
".",
"children",
"if",
"(",
"children",
")",
"{",
"patch",
"(",
"config",
",",
"children",
",",
"start",
")",
"}",
"end",
"=",
"start",
"+",
"toString",
"(",
"node",
")",
".",
"length",
"node",
".",
"position",
"=",
"{",
"start",
":",
"position",
"(",
"start",
")",
",",
"end",
":",
"position",
"(",
"end",
")",
"}",
"start",
"=",
"end",
"}",
"return",
"nodes",
"}"
] | Patch a position on each node in `nodes`. `offset` is the offset in `file` this run of content starts at. | [
"Patch",
"a",
"position",
"on",
"each",
"node",
"in",
"nodes",
".",
"offset",
"is",
"the",
"offset",
"in",
"file",
"this",
"run",
"of",
"content",
"starts",
"at",
"."
] | a827720d2e5d4f53aa44cc3a3231e4431b4ad4e0 | https://github.com/syntax-tree/mdast-util-to-nlcst/blob/a827720d2e5d4f53aa44cc3a3231e4431b4ad4e0/index.js#L147-L172 | train |
aureooms/js-itertools | lib/reduce/reduce.js | reduce | function reduce(accumulator, iterable, initializer = undefined) {
if (initializer === undefined) {
const iterator = (0, _iter.iter)(iterable);
const first = iterator.next();
if (first.done) {
return undefined;
}
return (0, _reduce2._reduce)(accumulator, iterator, first.value);
}
return (0, _reduce2._reduce)(accumulator, iterable, initializer);
} | javascript | function reduce(accumulator, iterable, initializer = undefined) {
if (initializer === undefined) {
const iterator = (0, _iter.iter)(iterable);
const first = iterator.next();
if (first.done) {
return undefined;
}
return (0, _reduce2._reduce)(accumulator, iterator, first.value);
}
return (0, _reduce2._reduce)(accumulator, iterable, initializer);
} | [
"function",
"reduce",
"(",
"accumulator",
",",
"iterable",
",",
"initializer",
"=",
"undefined",
")",
"{",
"if",
"(",
"initializer",
"===",
"undefined",
")",
"{",
"const",
"iterator",
"=",
"(",
"0",
",",
"_iter",
".",
"iter",
")",
"(",
"iterable",
")",
";",
"const",
"first",
"=",
"iterator",
".",
"next",
"(",
")",
";",
"if",
"(",
"first",
".",
"done",
")",
"{",
"return",
"undefined",
";",
"}",
"return",
"(",
"0",
",",
"_reduce2",
".",
"_reduce",
")",
"(",
"accumulator",
",",
"iterator",
",",
"first",
".",
"value",
")",
";",
"}",
"return",
"(",
"0",
",",
"_reduce2",
".",
"_reduce",
")",
"(",
"accumulator",
",",
"iterable",
",",
"initializer",
")",
";",
"}"
] | Applies the accumulator function iteratively on the last return value of the
accumulator and the next value in the input iterable. The initial value is
the initializer parameter. If no initial value is given, the first element
of the input iterable is used.
@example
_reduce( ( x , y ) => x + y , range( 10 ) , 0 ) ; // returns 45
@example
_reduce( ( x , y ) => x + y , range( 10 ) , 100 ) ; // returns 145
@param {Function} accumulator - The accumulator, a 2-ary function.
@param {Iterable} iterable - The input iterable.
@param {Object} [initializer=undefined] - The initial value of the reduction.
@returns {Object} - The reduction of the elements of <code>iterable</code>. | [
"Applies",
"the",
"accumulator",
"function",
"iteratively",
"on",
"the",
"last",
"return",
"value",
"of",
"the",
"accumulator",
"and",
"the",
"next",
"value",
"in",
"the",
"input",
"iterable",
".",
"The",
"initial",
"value",
"is",
"the",
"initializer",
"parameter",
".",
"If",
"no",
"initial",
"value",
"is",
"given",
"the",
"first",
"element",
"of",
"the",
"input",
"iterable",
"is",
"used",
"."
] | 72bafa5f3f957ceb37bdfa87a222364fe4974be3 | https://github.com/aureooms/js-itertools/blob/72bafa5f3f957ceb37bdfa87a222364fe4974be3/lib/reduce/reduce.js#L29-L43 | train |
stealjs/steal-npm | npm-extension.js | function(loader, name){
var pkg = utils.pkg.findByName(loader, name.split("/")[0]);
if(pkg) {
var parsed = utils.moduleName.parse(name, pkg.name);
parsed.version = pkg.version;
if(!parsed.modulePath) {
parsed.modulePath = utils.pkg.main(pkg);
}
return utils.moduleName.create(parsed);
}
return name;
} | javascript | function(loader, name){
var pkg = utils.pkg.findByName(loader, name.split("/")[0]);
if(pkg) {
var parsed = utils.moduleName.parse(name, pkg.name);
parsed.version = pkg.version;
if(!parsed.modulePath) {
parsed.modulePath = utils.pkg.main(pkg);
}
return utils.moduleName.create(parsed);
}
return name;
} | [
"function",
"(",
"loader",
",",
"name",
")",
"{",
"var",
"pkg",
"=",
"utils",
".",
"pkg",
".",
"findByName",
"(",
"loader",
",",
"name",
".",
"split",
"(",
"\"/\"",
")",
"[",
"0",
"]",
")",
";",
"if",
"(",
"pkg",
")",
"{",
"var",
"parsed",
"=",
"utils",
".",
"moduleName",
".",
"parse",
"(",
"name",
",",
"pkg",
".",
"name",
")",
";",
"parsed",
".",
"version",
"=",
"pkg",
".",
"version",
";",
"if",
"(",
"!",
"parsed",
".",
"modulePath",
")",
"{",
"parsed",
".",
"modulePath",
"=",
"utils",
".",
"pkg",
".",
"main",
"(",
"pkg",
")",
";",
"}",
"return",
"utils",
".",
"moduleName",
".",
"create",
"(",
"parsed",
")",
";",
"}",
"return",
"name",
";",
"}"
] | Given a moduleName convert it into a npm-style moduleName if it belongs to a package. | [
"Given",
"a",
"moduleName",
"convert",
"it",
"into",
"a",
"npm",
"-",
"style",
"moduleName",
"if",
"it",
"belongs",
"to",
"a",
"package",
"."
] | 216463c552cabe7d9dad86d754da784b5dea3d78 | https://github.com/stealjs/steal-npm/blob/216463c552cabe7d9dad86d754da784b5dea3d78/npm-extension.js#L329-L340 | train |
|
apostrophecms-legacy/apostrophe-pages | public/js/editor.js | function(callback) {
var page = apos.data.aposPages.page;
var _id = page._id;
$.get('/apos-pages/info', { _id: _id }, function(data) {
var newPathname = data.slug.replace(/^\/\//, '/');
apos.redirect(newPathname);
}).error(function() {
// If the page no longer exists, navigate away to home page
apos.redirect('/');
});
} | javascript | function(callback) {
var page = apos.data.aposPages.page;
var _id = page._id;
$.get('/apos-pages/info', { _id: _id }, function(data) {
var newPathname = data.slug.replace(/^\/\//, '/');
apos.redirect(newPathname);
}).error(function() {
// If the page no longer exists, navigate away to home page
apos.redirect('/');
});
} | [
"function",
"(",
"callback",
")",
"{",
"var",
"page",
"=",
"apos",
".",
"data",
".",
"aposPages",
".",
"page",
";",
"var",
"_id",
"=",
"page",
".",
"_id",
";",
"$",
".",
"get",
"(",
"'/apos-pages/info'",
",",
"{",
"_id",
":",
"_id",
"}",
",",
"function",
"(",
"data",
")",
"{",
"var",
"newPathname",
"=",
"data",
".",
"slug",
".",
"replace",
"(",
"/",
"^\\/\\/",
"/",
",",
"'/'",
")",
";",
"apos",
".",
"redirect",
"(",
"newPathname",
")",
";",
"}",
")",
".",
"error",
"(",
"function",
"(",
")",
"{",
"apos",
".",
"redirect",
"(",
"'/'",
")",
";",
"}",
")",
";",
"}"
] | After a reorg the page URL may have changed, be prepared to navigate there or to the home page or just refresh to reflect possible new tabs | [
"After",
"a",
"reorg",
"the",
"page",
"URL",
"may",
"have",
"changed",
"be",
"prepared",
"to",
"navigate",
"there",
"or",
"to",
"the",
"home",
"page",
"or",
"just",
"refresh",
"to",
"reflect",
"possible",
"new",
"tabs"
] | 72eb4b1df351b1c253e9b1c2bd2fe3fff6eb71b3 | https://github.com/apostrophecms-legacy/apostrophe-pages/blob/72eb4b1df351b1c253e9b1c2bd2fe3fff6eb71b3/public/js/editor.js#L546-L556 | train |
|
thinkjs/think-loader | loader/bootstrap.js | loadBootstrap | function loadBootstrap(appPath, modules, type = 'worker') {
let bootstrapPath = '';
if (modules.length) {
bootstrapPath = path.join(appPath, 'common/bootstrap');
} else {
bootstrapPath = path.join(appPath, 'bootstrap');
}
const filepath = path.join(bootstrapPath, `${type}.js`);
if (helper.isFile(filepath)) {
debug(`load file: ${filepath}`);
return require(filepath);
}
} | javascript | function loadBootstrap(appPath, modules, type = 'worker') {
let bootstrapPath = '';
if (modules.length) {
bootstrapPath = path.join(appPath, 'common/bootstrap');
} else {
bootstrapPath = path.join(appPath, 'bootstrap');
}
const filepath = path.join(bootstrapPath, `${type}.js`);
if (helper.isFile(filepath)) {
debug(`load file: ${filepath}`);
return require(filepath);
}
} | [
"function",
"loadBootstrap",
"(",
"appPath",
",",
"modules",
",",
"type",
"=",
"'worker'",
")",
"{",
"let",
"bootstrapPath",
"=",
"''",
";",
"if",
"(",
"modules",
".",
"length",
")",
"{",
"bootstrapPath",
"=",
"path",
".",
"join",
"(",
"appPath",
",",
"'common/bootstrap'",
")",
";",
"}",
"else",
"{",
"bootstrapPath",
"=",
"path",
".",
"join",
"(",
"appPath",
",",
"'bootstrap'",
")",
";",
"}",
"const",
"filepath",
"=",
"path",
".",
"join",
"(",
"bootstrapPath",
",",
"`",
"${",
"type",
"}",
"`",
")",
";",
"if",
"(",
"helper",
".",
"isFile",
"(",
"filepath",
")",
")",
"{",
"debug",
"(",
"`",
"${",
"filepath",
"}",
"`",
")",
";",
"return",
"require",
"(",
"filepath",
")",
";",
"}",
"}"
] | load bootstrap files | [
"load",
"bootstrap",
"files"
] | 680ab3dfd38c3a926b6bd5a026b78a0095cd39f6 | https://github.com/thinkjs/think-loader/blob/680ab3dfd38c3a926b6bd5a026b78a0095cd39f6/loader/bootstrap.js#L8-L20 | train |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.