id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
list | docstring
stringlengths 4
11.8k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
47,000 | mkay581/build-tools | src/copy.js | copyFileIntoDirectory | function copyFileIntoDirectory(srcPath, destPath) {
return ensureDestinationDirectory(destPath).then(function () {
return new Promise(function (resolve, reject) {
fs.readFile(srcPath, 'utf8', function (err, contents) {
if (!err) {
resolve();
} else {
reject(err);
}
fs.outputFile(destPath + '/' + path.basename(srcPath), contents, function (err) {
if (!err) {
resolve();
} else {
reject(err);
}
});
});
});
});
} | javascript | function copyFileIntoDirectory(srcPath, destPath) {
return ensureDestinationDirectory(destPath).then(function () {
return new Promise(function (resolve, reject) {
fs.readFile(srcPath, 'utf8', function (err, contents) {
if (!err) {
resolve();
} else {
reject(err);
}
fs.outputFile(destPath + '/' + path.basename(srcPath), contents, function (err) {
if (!err) {
resolve();
} else {
reject(err);
}
});
});
});
});
} | [
"function",
"copyFileIntoDirectory",
"(",
"srcPath",
",",
"destPath",
")",
"{",
"return",
"ensureDestinationDirectory",
"(",
"destPath",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"fs",
".",
"readFile",
"(",
"srcPath",
",",
"'utf8'",
",",
"function",
"(",
"err",
",",
"contents",
")",
"{",
"if",
"(",
"!",
"err",
")",
"{",
"resolve",
"(",
")",
";",
"}",
"else",
"{",
"reject",
"(",
"err",
")",
";",
"}",
"fs",
".",
"outputFile",
"(",
"destPath",
"+",
"'/'",
"+",
"path",
".",
"basename",
"(",
"srcPath",
")",
",",
"contents",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"!",
"err",
")",
"{",
"resolve",
"(",
")",
";",
"}",
"else",
"{",
"reject",
"(",
"err",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| Copies a file into a directory.
@param {String} srcPath - source path
@param {String} destPath - destination path
@returns {Promise} Returns a promise when completed | [
"Copies",
"a",
"file",
"into",
"a",
"directory",
"."
]
| 005cb840b5db017a33597a8d44d941d156a7a000 | https://github.com/mkay581/build-tools/blob/005cb840b5db017a33597a8d44d941d156a7a000/src/copy.js#L46-L65 |
47,001 | mkay581/build-tools | src/copy.js | copyFile | function copyFile(srcPath, destPath) {
let srcFileInfo = path.parse(srcPath) || {};
if (!path.extname(destPath) && srcFileInfo.ext) {
// destination is a directory!
return copyFileIntoDirectory(srcPath, destPath);
} else {
return new Promise(function (resolve, reject) {
fs.copy(srcPath, destPath, function (err) {
if (!err) {
resolve();
} else {
reject(err);
}
});
});
}
} | javascript | function copyFile(srcPath, destPath) {
let srcFileInfo = path.parse(srcPath) || {};
if (!path.extname(destPath) && srcFileInfo.ext) {
// destination is a directory!
return copyFileIntoDirectory(srcPath, destPath);
} else {
return new Promise(function (resolve, reject) {
fs.copy(srcPath, destPath, function (err) {
if (!err) {
resolve();
} else {
reject(err);
}
});
});
}
} | [
"function",
"copyFile",
"(",
"srcPath",
",",
"destPath",
")",
"{",
"let",
"srcFileInfo",
"=",
"path",
".",
"parse",
"(",
"srcPath",
")",
"||",
"{",
"}",
";",
"if",
"(",
"!",
"path",
".",
"extname",
"(",
"destPath",
")",
"&&",
"srcFileInfo",
".",
"ext",
")",
"{",
"// destination is a directory!",
"return",
"copyFileIntoDirectory",
"(",
"srcPath",
",",
"destPath",
")",
";",
"}",
"else",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"fs",
".",
"copy",
"(",
"srcPath",
",",
"destPath",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"!",
"err",
")",
"{",
"resolve",
"(",
")",
";",
"}",
"else",
"{",
"reject",
"(",
"err",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}",
"}"
]
| Copies one path to another one.
@param {String} srcPath - source path
@param {String} destPath - destination path
@returns {Promise} Returns a promise when done | [
"Copies",
"one",
"path",
"to",
"another",
"one",
"."
]
| 005cb840b5db017a33597a8d44d941d156a7a000 | https://github.com/mkay581/build-tools/blob/005cb840b5db017a33597a8d44d941d156a7a000/src/copy.js#L73-L89 |
47,002 | mkay581/build-tools | src/copy.js | getSourceDestinationPath | function getSourceDestinationPath (srcPath) {
let dests = _.keys(options.files);
return _.find(dests, function (destPath) {
let paths = options.files[destPath];
return _.find(paths, function (p) {
return p === srcPath || srcPath.indexOf(p) !== -1;
});
});
} | javascript | function getSourceDestinationPath (srcPath) {
let dests = _.keys(options.files);
return _.find(dests, function (destPath) {
let paths = options.files[destPath];
return _.find(paths, function (p) {
return p === srcPath || srcPath.indexOf(p) !== -1;
});
});
} | [
"function",
"getSourceDestinationPath",
"(",
"srcPath",
")",
"{",
"let",
"dests",
"=",
"_",
".",
"keys",
"(",
"options",
".",
"files",
")",
";",
"return",
"_",
".",
"find",
"(",
"dests",
",",
"function",
"(",
"destPath",
")",
"{",
"let",
"paths",
"=",
"options",
".",
"files",
"[",
"destPath",
"]",
";",
"return",
"_",
".",
"find",
"(",
"paths",
",",
"function",
"(",
"p",
")",
"{",
"return",
"p",
"===",
"srcPath",
"||",
"srcPath",
".",
"indexOf",
"(",
"p",
")",
"!==",
"-",
"1",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| Gets the destination path for a source file.
@param srcPath
@returns {string} Returns the matching destination path | [
"Gets",
"the",
"destination",
"path",
"for",
"a",
"source",
"file",
"."
]
| 005cb840b5db017a33597a8d44d941d156a7a000 | https://github.com/mkay581/build-tools/blob/005cb840b5db017a33597a8d44d941d156a7a000/src/copy.js#L96-L104 |
47,003 | andrewfhart/openassets | lib/protocol/ColoringEngine.js | function (tx) {
var outs = [];
tx.outputs.forEach(function (o) {
outs.push(new TransactionOutput(o.satoshis,o.script.toBuffer()));
});
return outs;
} | javascript | function (tx) {
var outs = [];
tx.outputs.forEach(function (o) {
outs.push(new TransactionOutput(o.satoshis,o.script.toBuffer()));
});
return outs;
} | [
"function",
"(",
"tx",
")",
"{",
"var",
"outs",
"=",
"[",
"]",
";",
"tx",
".",
"outputs",
".",
"forEach",
"(",
"function",
"(",
"o",
")",
"{",
"outs",
".",
"push",
"(",
"new",
"TransactionOutput",
"(",
"o",
".",
"satoshis",
",",
"o",
".",
"script",
".",
"toBuffer",
"(",
")",
")",
")",
";",
"}",
")",
";",
"return",
"outs",
";",
"}"
]
| Helper function to make the appropriate response in the case where no valid asset ids were found in a transaction. In this case all of the transaction outputs are considered uncolored. | [
"Helper",
"function",
"to",
"make",
"the",
"appropriate",
"response",
"in",
"the",
"case",
"where",
"no",
"valid",
"asset",
"ids",
"were",
"found",
"in",
"a",
"transaction",
".",
"In",
"this",
"case",
"all",
"of",
"the",
"transaction",
"outputs",
"are",
"considered",
"uncolored",
"."
]
| e61f238e159ae5584d28bb2e911f2995c14d45e0 | https://github.com/andrewfhart/openassets/blob/e61f238e159ae5584d28bb2e911f2995c14d45e0/lib/protocol/ColoringEngine.js#L116-L122 |
|
47,004 | greg-js/hexo-easy-edit | lib/edit.js | filterTitle | function filterTitle(posts) {
var reTitle = title.map(function makeRE(word) {
return new RegExp(word, 'i');
});
return posts.filter(function filterPosts(post) {
return reTitle.every(function checkRE(regex) {
return regex.test(post.title) || regex.test(post.slug);
});
});
} | javascript | function filterTitle(posts) {
var reTitle = title.map(function makeRE(word) {
return new RegExp(word, 'i');
});
return posts.filter(function filterPosts(post) {
return reTitle.every(function checkRE(regex) {
return regex.test(post.title) || regex.test(post.slug);
});
});
} | [
"function",
"filterTitle",
"(",
"posts",
")",
"{",
"var",
"reTitle",
"=",
"title",
".",
"map",
"(",
"function",
"makeRE",
"(",
"word",
")",
"{",
"return",
"new",
"RegExp",
"(",
"word",
",",
"'i'",
")",
";",
"}",
")",
";",
"return",
"posts",
".",
"filter",
"(",
"function",
"filterPosts",
"(",
"post",
")",
"{",
"return",
"reTitle",
".",
"every",
"(",
"function",
"checkRE",
"(",
"regex",
")",
"{",
"return",
"regex",
".",
"test",
"(",
"post",
".",
"title",
")",
"||",
"regex",
".",
"test",
"(",
"post",
".",
"slug",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| filter the posts with the supplied regular expression | [
"filter",
"the",
"posts",
"with",
"the",
"supplied",
"regular",
"expression"
]
| a2686184de47bc0c8024f40816e637bb671b280f | https://github.com/greg-js/hexo-easy-edit/blob/a2686184de47bc0c8024f40816e637bb671b280f/lib/edit.js#L93-L103 |
47,005 | greg-js/hexo-easy-edit | lib/edit.js | filterFolder | function filterFolder(posts) {
var reFolder = new RegExp(folder);
return posts.filter(function filterPosts(post) {
return reFolder.test(post.source.substr(0, post.source.lastIndexOf(path.sep)));
});
} | javascript | function filterFolder(posts) {
var reFolder = new RegExp(folder);
return posts.filter(function filterPosts(post) {
return reFolder.test(post.source.substr(0, post.source.lastIndexOf(path.sep)));
});
} | [
"function",
"filterFolder",
"(",
"posts",
")",
"{",
"var",
"reFolder",
"=",
"new",
"RegExp",
"(",
"folder",
")",
";",
"return",
"posts",
".",
"filter",
"(",
"function",
"filterPosts",
"(",
"post",
")",
"{",
"return",
"reFolder",
".",
"test",
"(",
"post",
".",
"source",
".",
"substr",
"(",
"0",
",",
"post",
".",
"source",
".",
"lastIndexOf",
"(",
"path",
".",
"sep",
")",
")",
")",
";",
"}",
")",
";",
"}"
]
| filter the posts using a subfolder if supplied | [
"filter",
"the",
"posts",
"using",
"a",
"subfolder",
"if",
"supplied"
]
| a2686184de47bc0c8024f40816e637bb671b280f | https://github.com/greg-js/hexo-easy-edit/blob/a2686184de47bc0c8024f40816e637bb671b280f/lib/edit.js#L106-L111 |
47,006 | greg-js/hexo-easy-edit | lib/edit.js | filterTag | function filterTag(posts) {
var reTag = new RegExp(tag);
return posts.filter(function filterPosts(post) {
return post.tags.data.some(function checkRe(postTag) {
return reTag.test(postTag.name);
});
});
} | javascript | function filterTag(posts) {
var reTag = new RegExp(tag);
return posts.filter(function filterPosts(post) {
return post.tags.data.some(function checkRe(postTag) {
return reTag.test(postTag.name);
});
});
} | [
"function",
"filterTag",
"(",
"posts",
")",
"{",
"var",
"reTag",
"=",
"new",
"RegExp",
"(",
"tag",
")",
";",
"return",
"posts",
".",
"filter",
"(",
"function",
"filterPosts",
"(",
"post",
")",
"{",
"return",
"post",
".",
"tags",
".",
"data",
".",
"some",
"(",
"function",
"checkRe",
"(",
"postTag",
")",
"{",
"return",
"reTag",
".",
"test",
"(",
"postTag",
".",
"name",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| filter the posts using a tag if supplied | [
"filter",
"the",
"posts",
"using",
"a",
"tag",
"if",
"supplied"
]
| a2686184de47bc0c8024f40816e637bb671b280f | https://github.com/greg-js/hexo-easy-edit/blob/a2686184de47bc0c8024f40816e637bb671b280f/lib/edit.js#L114-L121 |
47,007 | greg-js/hexo-easy-edit | lib/edit.js | filterCategory | function filterCategory(posts) {
var reCat = new RegExp(cat);
return posts.filter(function filterPosts(post) {
return post.categories.data.some(function checkRe(postCat) {
return reCat.test(postCat.name);
});
});
} | javascript | function filterCategory(posts) {
var reCat = new RegExp(cat);
return posts.filter(function filterPosts(post) {
return post.categories.data.some(function checkRe(postCat) {
return reCat.test(postCat.name);
});
});
} | [
"function",
"filterCategory",
"(",
"posts",
")",
"{",
"var",
"reCat",
"=",
"new",
"RegExp",
"(",
"cat",
")",
";",
"return",
"posts",
".",
"filter",
"(",
"function",
"filterPosts",
"(",
"post",
")",
"{",
"return",
"post",
".",
"categories",
".",
"data",
".",
"some",
"(",
"function",
"checkRe",
"(",
"postCat",
")",
"{",
"return",
"reCat",
".",
"test",
"(",
"postCat",
".",
"name",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| filter the posts using a category if supplied | [
"filter",
"the",
"posts",
"using",
"a",
"category",
"if",
"supplied"
]
| a2686184de47bc0c8024f40816e637bb671b280f | https://github.com/greg-js/hexo-easy-edit/blob/a2686184de47bc0c8024f40816e637bb671b280f/lib/edit.js#L124-L131 |
47,008 | greg-js/hexo-easy-edit | lib/edit.js | filterLayout | function filterLayout(posts) {
var reLayout = new RegExp(layout, 'i');
return posts.filter(function filterPosts(post) {
return reLayout.test(post.layout);
});
} | javascript | function filterLayout(posts) {
var reLayout = new RegExp(layout, 'i');
return posts.filter(function filterPosts(post) {
return reLayout.test(post.layout);
});
} | [
"function",
"filterLayout",
"(",
"posts",
")",
"{",
"var",
"reLayout",
"=",
"new",
"RegExp",
"(",
"layout",
",",
"'i'",
")",
";",
"return",
"posts",
".",
"filter",
"(",
"function",
"filterPosts",
"(",
"post",
")",
"{",
"return",
"reLayout",
".",
"test",
"(",
"post",
".",
"layout",
")",
";",
"}",
")",
";",
"}"
]
| filter the posts using a layout if supplied | [
"filter",
"the",
"posts",
"using",
"a",
"layout",
"if",
"supplied"
]
| a2686184de47bc0c8024f40816e637bb671b280f | https://github.com/greg-js/hexo-easy-edit/blob/a2686184de47bc0c8024f40816e637bb671b280f/lib/edit.js#L134-L140 |
47,009 | greg-js/hexo-easy-edit | lib/edit.js | filterBefore | function filterBefore(posts) {
before = moment(before.replace(/\//g, '-'), 'MM-DD-YYYY', true);
if (!before.isValid()) {
console.log(chalk.red('Before date is not valid (expecting `MM-DD-YYYY`), ignoring argument.'));
return posts;
}
return posts.filter(function filterPosts(post) {
return moment(post.date).isBefore(before);
});
} | javascript | function filterBefore(posts) {
before = moment(before.replace(/\//g, '-'), 'MM-DD-YYYY', true);
if (!before.isValid()) {
console.log(chalk.red('Before date is not valid (expecting `MM-DD-YYYY`), ignoring argument.'));
return posts;
}
return posts.filter(function filterPosts(post) {
return moment(post.date).isBefore(before);
});
} | [
"function",
"filterBefore",
"(",
"posts",
")",
"{",
"before",
"=",
"moment",
"(",
"before",
".",
"replace",
"(",
"/",
"\\/",
"/",
"g",
",",
"'-'",
")",
",",
"'MM-DD-YYYY'",
",",
"true",
")",
";",
"if",
"(",
"!",
"before",
".",
"isValid",
"(",
")",
")",
"{",
"console",
".",
"log",
"(",
"chalk",
".",
"red",
"(",
"'Before date is not valid (expecting `MM-DD-YYYY`), ignoring argument.'",
")",
")",
";",
"return",
"posts",
";",
"}",
"return",
"posts",
".",
"filter",
"(",
"function",
"filterPosts",
"(",
"post",
")",
"{",
"return",
"moment",
"(",
"post",
".",
"date",
")",
".",
"isBefore",
"(",
"before",
")",
";",
"}",
")",
";",
"}"
]
| filter the posts using a before date if supplied | [
"filter",
"the",
"posts",
"using",
"a",
"before",
"date",
"if",
"supplied"
]
| a2686184de47bc0c8024f40816e637bb671b280f | https://github.com/greg-js/hexo-easy-edit/blob/a2686184de47bc0c8024f40816e637bb671b280f/lib/edit.js#L150-L160 |
47,010 | greg-js/hexo-easy-edit | lib/edit.js | filterAfter | function filterAfter(posts) {
after = moment(after.replace(/\//g, '-'), 'MM-DD-YYYY', true);
if (!after.isValid()) {
console.log(chalk.red('After date is not valid (expecting `MM-DD-YYYY`), ignoring argument.'));
return posts;
}
return posts.filter(function filterPosts(post) {
return moment(post.date).isAfter(after);
});
} | javascript | function filterAfter(posts) {
after = moment(after.replace(/\//g, '-'), 'MM-DD-YYYY', true);
if (!after.isValid()) {
console.log(chalk.red('After date is not valid (expecting `MM-DD-YYYY`), ignoring argument.'));
return posts;
}
return posts.filter(function filterPosts(post) {
return moment(post.date).isAfter(after);
});
} | [
"function",
"filterAfter",
"(",
"posts",
")",
"{",
"after",
"=",
"moment",
"(",
"after",
".",
"replace",
"(",
"/",
"\\/",
"/",
"g",
",",
"'-'",
")",
",",
"'MM-DD-YYYY'",
",",
"true",
")",
";",
"if",
"(",
"!",
"after",
".",
"isValid",
"(",
")",
")",
"{",
"console",
".",
"log",
"(",
"chalk",
".",
"red",
"(",
"'After date is not valid (expecting `MM-DD-YYYY`), ignoring argument.'",
")",
")",
";",
"return",
"posts",
";",
"}",
"return",
"posts",
".",
"filter",
"(",
"function",
"filterPosts",
"(",
"post",
")",
"{",
"return",
"moment",
"(",
"post",
".",
"date",
")",
".",
"isAfter",
"(",
"after",
")",
";",
"}",
")",
";",
"}"
]
| filter the posts using an after date if supplied | [
"filter",
"the",
"posts",
"using",
"an",
"after",
"date",
"if",
"supplied"
]
| a2686184de47bc0c8024f40816e637bb671b280f | https://github.com/greg-js/hexo-easy-edit/blob/a2686184de47bc0c8024f40816e637bb671b280f/lib/edit.js#L163-L173 |
47,011 | greg-js/hexo-easy-edit | lib/edit.js | openFile | function openFile(file) {
var edit;
if (!editor || gui) {
open(file);
} else {
edit = spawn(editor, [file], {stdio: 'inherit'});
edit.on('exit', process.exit);
}
} | javascript | function openFile(file) {
var edit;
if (!editor || gui) {
open(file);
} else {
edit = spawn(editor, [file], {stdio: 'inherit'});
edit.on('exit', process.exit);
}
} | [
"function",
"openFile",
"(",
"file",
")",
"{",
"var",
"edit",
";",
"if",
"(",
"!",
"editor",
"||",
"gui",
")",
"{",
"open",
"(",
"file",
")",
";",
"}",
"else",
"{",
"edit",
"=",
"spawn",
"(",
"editor",
",",
"[",
"file",
"]",
",",
"{",
"stdio",
":",
"'inherit'",
"}",
")",
";",
"edit",
".",
"on",
"(",
"'exit'",
",",
"process",
".",
"exit",
")",
";",
"}",
"}"
]
| spawn process and open with associated gui or terminal editor | [
"spawn",
"process",
"and",
"open",
"with",
"associated",
"gui",
"or",
"terminal",
"editor"
]
| a2686184de47bc0c8024f40816e637bb671b280f | https://github.com/greg-js/hexo-easy-edit/blob/a2686184de47bc0c8024f40816e637bb671b280f/lib/edit.js#L176-L184 |
47,012 | porkchop/bitid-js | lib/bitid.js | Bitid | function Bitid(params) {
params = params || {};
var self = this;
this._nonce = params.nonce;
this.callback = url.parse(params.callback, true);
this.signature = params.signature;
this.address = params.address;
this.unsecure = params.unsecure;
this._uri = !params.uri ? buildURI() : url.parse(params.uri, true);
function buildURI() {
var uri = self.callback;
uri.protocol = SCHEME;
var params = {};
params[PARAM_NONCE] = self._nonce;
if(self.unsecure) params[PARAM_UNSECURE] = 1;
uri.query = params;
uri.href = url.format(uri);
return uri;
}
} | javascript | function Bitid(params) {
params = params || {};
var self = this;
this._nonce = params.nonce;
this.callback = url.parse(params.callback, true);
this.signature = params.signature;
this.address = params.address;
this.unsecure = params.unsecure;
this._uri = !params.uri ? buildURI() : url.parse(params.uri, true);
function buildURI() {
var uri = self.callback;
uri.protocol = SCHEME;
var params = {};
params[PARAM_NONCE] = self._nonce;
if(self.unsecure) params[PARAM_UNSECURE] = 1;
uri.query = params;
uri.href = url.format(uri);
return uri;
}
} | [
"function",
"Bitid",
"(",
"params",
")",
"{",
"params",
"=",
"params",
"||",
"{",
"}",
";",
"var",
"self",
"=",
"this",
";",
"this",
".",
"_nonce",
"=",
"params",
".",
"nonce",
";",
"this",
".",
"callback",
"=",
"url",
".",
"parse",
"(",
"params",
".",
"callback",
",",
"true",
")",
";",
"this",
".",
"signature",
"=",
"params",
".",
"signature",
";",
"this",
".",
"address",
"=",
"params",
".",
"address",
";",
"this",
".",
"unsecure",
"=",
"params",
".",
"unsecure",
";",
"this",
".",
"_uri",
"=",
"!",
"params",
".",
"uri",
"?",
"buildURI",
"(",
")",
":",
"url",
".",
"parse",
"(",
"params",
".",
"uri",
",",
"true",
")",
";",
"function",
"buildURI",
"(",
")",
"{",
"var",
"uri",
"=",
"self",
".",
"callback",
";",
"uri",
".",
"protocol",
"=",
"SCHEME",
";",
"var",
"params",
"=",
"{",
"}",
";",
"params",
"[",
"PARAM_NONCE",
"]",
"=",
"self",
".",
"_nonce",
";",
"if",
"(",
"self",
".",
"unsecure",
")",
"params",
"[",
"PARAM_UNSECURE",
"]",
"=",
"1",
";",
"uri",
".",
"query",
"=",
"params",
";",
"uri",
".",
"href",
"=",
"url",
".",
"format",
"(",
"uri",
")",
";",
"return",
"uri",
";",
"}",
"}"
]
| Initialize a new `Bitid` with the given `params`
@param {JSON} params
@api public | [
"Initialize",
"a",
"new",
"Bitid",
"with",
"the",
"given",
"params"
]
| 994d468c624e6bc816a73cce108daa303eb09c4e | https://github.com/porkchop/bitid-js/blob/994d468c624e6bc816a73cce108daa303eb09c4e/lib/bitid.js#L32-L54 |
47,013 | mini-eggs/cra-babel-extend | src/index.js | getPresetsString | function getPresetsString(presetArray) {
if (!presetArray.includes("react-app")) {
presetArray.push("react-app");
}
return presetArray.map(attachRequestResolve("preset")).join(",");
} | javascript | function getPresetsString(presetArray) {
if (!presetArray.includes("react-app")) {
presetArray.push("react-app");
}
return presetArray.map(attachRequestResolve("preset")).join(",");
} | [
"function",
"getPresetsString",
"(",
"presetArray",
")",
"{",
"if",
"(",
"!",
"presetArray",
".",
"includes",
"(",
"\"react-app\"",
")",
")",
"{",
"presetArray",
".",
"push",
"(",
"\"react-app\"",
")",
";",
"}",
"return",
"presetArray",
".",
"map",
"(",
"attachRequestResolve",
"(",
"\"preset\"",
")",
")",
".",
"join",
"(",
"\",\"",
")",
";",
"}"
]
| Build string to insert from presets array. | [
"Build",
"string",
"to",
"insert",
"from",
"presets",
"array",
"."
]
| 39bce9a446f1fd380b661d787cab5928fa6ecc86 | https://github.com/mini-eggs/cra-babel-extend/blob/39bce9a446f1fd380b661d787cab5928fa6ecc86/src/index.js#L22-L27 |
47,014 | soajs/connect-mongo-soajs | lib/mongo.js | connect | function connect(obj, cb) {
if (obj.db) {
return cb();
}
if (obj.pending) {
return setImmediate(function () {
connect(obj, cb);
});
}
obj.pending = true;
var url = constructMongoLink(obj.config.name, obj.config.prefix, obj.config.servers, obj.config.URLParam, obj.config.credentials);
if (!url) {
return cb(generateError(190));
}
mongoSkin.connect(url, obj.config.extraParam, function (err, db) {
if (err) {
obj.pending = false;
return cb(err);
} else {
db.on('timeout', function () {
console.log("Connection To Mongo has timed out!");
obj.flushDb();
});
db.on('close', function () {
console.log("Connection To Mongo has been closed!");
obj.flushDb();
});
if (obj.db)
obj.db.close();
obj.db = db;
obj.pending = false;
return cb();
}
});
/**
*constructMongoLink: is a function that takes the below param and return the URL need to by mongoskin.connect
*
* @param dbName
* @param prefix
* @param servers
* @param params
* @param credentials
* @returns {*}
*/
function constructMongoLink(dbName, prefix, servers, params, credentials) {
if (dbName && Array.isArray(servers)) {
var url = "mongodb://";
if (credentials && Object.hasOwnProperty.call(credentials, 'username') && credentials.hasOwnProperty.call(credentials, 'password')) {
url = url.concat(credentials.username, ':', credentials.password, '@');
}
servers.forEach(function (element, index, array) {
url = url.concat(element.host, ':', element.port, (index === array.length - 1 ? '' : ','));
});
url = url.concat('/');
if (prefix) url = url.concat(prefix);
url = url.concat(dbName);
if (params && 'object' === typeof params && Object.keys(params).length) {
url = url.concat('?');
for (var i = 0; i < Object.keys(params).length; i++) {
url = url.concat(Object.keys(params)[i], '=', params[Object.keys(params)[i]], i === Object.keys(params).length - 1 ? '' : "&");
}
}
return url;
}
return null;
}
} | javascript | function connect(obj, cb) {
if (obj.db) {
return cb();
}
if (obj.pending) {
return setImmediate(function () {
connect(obj, cb);
});
}
obj.pending = true;
var url = constructMongoLink(obj.config.name, obj.config.prefix, obj.config.servers, obj.config.URLParam, obj.config.credentials);
if (!url) {
return cb(generateError(190));
}
mongoSkin.connect(url, obj.config.extraParam, function (err, db) {
if (err) {
obj.pending = false;
return cb(err);
} else {
db.on('timeout', function () {
console.log("Connection To Mongo has timed out!");
obj.flushDb();
});
db.on('close', function () {
console.log("Connection To Mongo has been closed!");
obj.flushDb();
});
if (obj.db)
obj.db.close();
obj.db = db;
obj.pending = false;
return cb();
}
});
/**
*constructMongoLink: is a function that takes the below param and return the URL need to by mongoskin.connect
*
* @param dbName
* @param prefix
* @param servers
* @param params
* @param credentials
* @returns {*}
*/
function constructMongoLink(dbName, prefix, servers, params, credentials) {
if (dbName && Array.isArray(servers)) {
var url = "mongodb://";
if (credentials && Object.hasOwnProperty.call(credentials, 'username') && credentials.hasOwnProperty.call(credentials, 'password')) {
url = url.concat(credentials.username, ':', credentials.password, '@');
}
servers.forEach(function (element, index, array) {
url = url.concat(element.host, ':', element.port, (index === array.length - 1 ? '' : ','));
});
url = url.concat('/');
if (prefix) url = url.concat(prefix);
url = url.concat(dbName);
if (params && 'object' === typeof params && Object.keys(params).length) {
url = url.concat('?');
for (var i = 0; i < Object.keys(params).length; i++) {
url = url.concat(Object.keys(params)[i], '=', params[Object.keys(params)[i]], i === Object.keys(params).length - 1 ? '' : "&");
}
}
return url;
}
return null;
}
} | [
"function",
"connect",
"(",
"obj",
",",
"cb",
")",
"{",
"if",
"(",
"obj",
".",
"db",
")",
"{",
"return",
"cb",
"(",
")",
";",
"}",
"if",
"(",
"obj",
".",
"pending",
")",
"{",
"return",
"setImmediate",
"(",
"function",
"(",
")",
"{",
"connect",
"(",
"obj",
",",
"cb",
")",
";",
"}",
")",
";",
"}",
"obj",
".",
"pending",
"=",
"true",
";",
"var",
"url",
"=",
"constructMongoLink",
"(",
"obj",
".",
"config",
".",
"name",
",",
"obj",
".",
"config",
".",
"prefix",
",",
"obj",
".",
"config",
".",
"servers",
",",
"obj",
".",
"config",
".",
"URLParam",
",",
"obj",
".",
"config",
".",
"credentials",
")",
";",
"if",
"(",
"!",
"url",
")",
"{",
"return",
"cb",
"(",
"generateError",
"(",
"190",
")",
")",
";",
"}",
"mongoSkin",
".",
"connect",
"(",
"url",
",",
"obj",
".",
"config",
".",
"extraParam",
",",
"function",
"(",
"err",
",",
"db",
")",
"{",
"if",
"(",
"err",
")",
"{",
"obj",
".",
"pending",
"=",
"false",
";",
"return",
"cb",
"(",
"err",
")",
";",
"}",
"else",
"{",
"db",
".",
"on",
"(",
"'timeout'",
",",
"function",
"(",
")",
"{",
"console",
".",
"log",
"(",
"\"Connection To Mongo has timed out!\"",
")",
";",
"obj",
".",
"flushDb",
"(",
")",
";",
"}",
")",
";",
"db",
".",
"on",
"(",
"'close'",
",",
"function",
"(",
")",
"{",
"console",
".",
"log",
"(",
"\"Connection To Mongo has been closed!\"",
")",
";",
"obj",
".",
"flushDb",
"(",
")",
";",
"}",
")",
";",
"if",
"(",
"obj",
".",
"db",
")",
"obj",
".",
"db",
".",
"close",
"(",
")",
";",
"obj",
".",
"db",
"=",
"db",
";",
"obj",
".",
"pending",
"=",
"false",
";",
"return",
"cb",
"(",
")",
";",
"}",
"}",
")",
";",
"/**\n *constructMongoLink: is a function that takes the below param and return the URL need to by mongoskin.connect\n *\n * @param dbName\n * @param prefix\n * @param servers\n * @param params\n * @param credentials\n * @returns {*}\n */",
"function",
"constructMongoLink",
"(",
"dbName",
",",
"prefix",
",",
"servers",
",",
"params",
",",
"credentials",
")",
"{",
"if",
"(",
"dbName",
"&&",
"Array",
".",
"isArray",
"(",
"servers",
")",
")",
"{",
"var",
"url",
"=",
"\"mongodb://\"",
";",
"if",
"(",
"credentials",
"&&",
"Object",
".",
"hasOwnProperty",
".",
"call",
"(",
"credentials",
",",
"'username'",
")",
"&&",
"credentials",
".",
"hasOwnProperty",
".",
"call",
"(",
"credentials",
",",
"'password'",
")",
")",
"{",
"url",
"=",
"url",
".",
"concat",
"(",
"credentials",
".",
"username",
",",
"':'",
",",
"credentials",
".",
"password",
",",
"'@'",
")",
";",
"}",
"servers",
".",
"forEach",
"(",
"function",
"(",
"element",
",",
"index",
",",
"array",
")",
"{",
"url",
"=",
"url",
".",
"concat",
"(",
"element",
".",
"host",
",",
"':'",
",",
"element",
".",
"port",
",",
"(",
"index",
"===",
"array",
".",
"length",
"-",
"1",
"?",
"''",
":",
"','",
")",
")",
";",
"}",
")",
";",
"url",
"=",
"url",
".",
"concat",
"(",
"'/'",
")",
";",
"if",
"(",
"prefix",
")",
"url",
"=",
"url",
".",
"concat",
"(",
"prefix",
")",
";",
"url",
"=",
"url",
".",
"concat",
"(",
"dbName",
")",
";",
"if",
"(",
"params",
"&&",
"'object'",
"===",
"typeof",
"params",
"&&",
"Object",
".",
"keys",
"(",
"params",
")",
".",
"length",
")",
"{",
"url",
"=",
"url",
".",
"concat",
"(",
"'?'",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"Object",
".",
"keys",
"(",
"params",
")",
".",
"length",
";",
"i",
"++",
")",
"{",
"url",
"=",
"url",
".",
"concat",
"(",
"Object",
".",
"keys",
"(",
"params",
")",
"[",
"i",
"]",
",",
"'='",
",",
"params",
"[",
"Object",
".",
"keys",
"(",
"params",
")",
"[",
"i",
"]",
"]",
",",
"i",
"===",
"Object",
".",
"keys",
"(",
"params",
")",
".",
"length",
"-",
"1",
"?",
"''",
":",
"\"&\"",
")",
";",
"}",
"}",
"return",
"url",
";",
"}",
"return",
"null",
";",
"}",
"}"
]
| Ensure a connection to mongo without any race condition problem
@param {Object} obj
@param {Function} cb
@returns {*} | [
"Ensure",
"a",
"connection",
"to",
"mongo",
"without",
"any",
"race",
"condition",
"problem"
]
| 27b7b0b0f25e75168857fd9d2be83cc07a0da868 | https://github.com/soajs/connect-mongo-soajs/blob/27b7b0b0f25e75168857fd9d2be83cc07a0da868/lib/mongo.js#L212-L285 |
47,015 | dtudury/discontinuous-range | index.js | _SubRange | function _SubRange(low, high) {
this.low = low;
this.high = high;
this.length = 1 + high - low;
} | javascript | function _SubRange(low, high) {
this.low = low;
this.high = high;
this.length = 1 + high - low;
} | [
"function",
"_SubRange",
"(",
"low",
",",
"high",
")",
"{",
"this",
".",
"low",
"=",
"low",
";",
"this",
".",
"high",
"=",
"high",
";",
"this",
".",
"length",
"=",
"1",
"+",
"high",
"-",
"low",
";",
"}"
]
| protected helper class | [
"protected",
"helper",
"class"
]
| 8c9a05039f09ad795fa7aea1da5e75fa3a6a949a | https://github.com/dtudury/discontinuous-range/blob/8c9a05039f09ad795fa7aea1da5e75fa3a6a949a/index.js#L2-L6 |
47,016 | makenova/nodeginx | nodeginx.js | manageNginx | function manageNginx (action, callback) {
// TODO: research if sending signals is better
// i.e. sudo nginx -s stop|quit|reload
exec(`sudo service nginx ${action}`, (err, stdout, stderr) => {
if (err) return callback(err)
return callback()
})
} | javascript | function manageNginx (action, callback) {
// TODO: research if sending signals is better
// i.e. sudo nginx -s stop|quit|reload
exec(`sudo service nginx ${action}`, (err, stdout, stderr) => {
if (err) return callback(err)
return callback()
})
} | [
"function",
"manageNginx",
"(",
"action",
",",
"callback",
")",
"{",
"// TODO: research if sending signals is better",
"// i.e. sudo nginx -s stop|quit|reload",
"exec",
"(",
"`",
"${",
"action",
"}",
"`",
",",
"(",
"err",
",",
"stdout",
",",
"stderr",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"return",
"callback",
"(",
"err",
")",
"return",
"callback",
"(",
")",
"}",
")",
"}"
]
| Nginx process functions | [
"Nginx",
"process",
"functions"
]
| 8c5d0c53780fbd4c94e4a15782f14cb0ab92498d | https://github.com/makenova/nodeginx/blob/8c5d0c53780fbd4c94e4a15782f14cb0ab92498d/nodeginx.js#L62-L69 |
47,017 | hkjels/ntask | lib/project.js | Project | function Project(path) {
path = path || PWD;
this.root = '';
this.storage = '';
this.ignore = [];
this.resolvePaths(path);
} | javascript | function Project(path) {
path = path || PWD;
this.root = '';
this.storage = '';
this.ignore = [];
this.resolvePaths(path);
} | [
"function",
"Project",
"(",
"path",
")",
"{",
"path",
"=",
"path",
"||",
"PWD",
";",
"this",
".",
"root",
"=",
"''",
";",
"this",
".",
"storage",
"=",
"''",
";",
"this",
".",
"ignore",
"=",
"[",
"]",
";",
"this",
".",
"resolvePaths",
"(",
"path",
")",
";",
"}"
]
| Locates & sets up project
Path is only needed for testing, usual case `pwd` by default
@param {String}
@api private | [
"Locates",
"&",
"sets",
"up",
"project",
"Path",
"is",
"only",
"needed",
"for",
"testing",
"usual",
"case",
"pwd",
"by",
"default"
]
| e0552042e743ef9584bc0f911245635df7acd634 | https://github.com/hkjels/ntask/blob/e0552042e743ef9584bc0f911245635df7acd634/lib/project.js#L47-L53 |
47,018 | dpjanes/iotdb-homestar | bin/commands/install.js | function (module_name, module_folder) {
var module_path = path.resolve(module_folder);
// load current keystore
let keystored = {};
const filename = ".iotdb/keystore.json";
_.cfg.load.json([ filename ], docd => keystored = _.d.compose.deep(keystored, docd.doc));
// change it
_.d.set(keystored, "/modules/" + module_name, module_path)
// save it
fs.writeFile(filename, JSON.stringify(keystored, null, 2));
console.log("- installed homestar module!");
console.log(" name:", module_name);
console.log(" path:", module_path);
} | javascript | function (module_name, module_folder) {
var module_path = path.resolve(module_folder);
// load current keystore
let keystored = {};
const filename = ".iotdb/keystore.json";
_.cfg.load.json([ filename ], docd => keystored = _.d.compose.deep(keystored, docd.doc));
// change it
_.d.set(keystored, "/modules/" + module_name, module_path)
// save it
fs.writeFile(filename, JSON.stringify(keystored, null, 2));
console.log("- installed homestar module!");
console.log(" name:", module_name);
console.log(" path:", module_path);
} | [
"function",
"(",
"module_name",
",",
"module_folder",
")",
"{",
"var",
"module_path",
"=",
"path",
".",
"resolve",
"(",
"module_folder",
")",
";",
"// load current keystore",
"let",
"keystored",
"=",
"{",
"}",
";",
"const",
"filename",
"=",
"\".iotdb/keystore.json\"",
";",
"_",
".",
"cfg",
".",
"load",
".",
"json",
"(",
"[",
"filename",
"]",
",",
"docd",
"=>",
"keystored",
"=",
"_",
".",
"d",
".",
"compose",
".",
"deep",
"(",
"keystored",
",",
"docd",
".",
"doc",
")",
")",
";",
"// change it",
"_",
".",
"d",
".",
"set",
"(",
"keystored",
",",
"\"/modules/\"",
"+",
"module_name",
",",
"module_path",
")",
"// save it",
"fs",
".",
"writeFile",
"(",
"filename",
",",
"JSON",
".",
"stringify",
"(",
"keystored",
",",
"null",
",",
"2",
")",
")",
";",
"console",
".",
"log",
"(",
"\"- installed homestar module!\"",
")",
";",
"console",
".",
"log",
"(",
"\" name:\"",
",",
"module_name",
")",
";",
"console",
".",
"log",
"(",
"\" path:\"",
",",
"module_path",
")",
";",
"}"
]
| Add module info to the keystore | [
"Add",
"module",
"info",
"to",
"the",
"keystore"
]
| ed6535aa17c8b0538f43a876c9a6025e26a389e3 | https://github.com/dpjanes/iotdb-homestar/blob/ed6535aa17c8b0538f43a876c9a6025e26a389e3/bin/commands/install.js#L217-L234 |
|
47,019 | dpjanes/iotdb-homestar | bin/commands/install.js | function (module_name, module_folder) {
var iotdb_dir = path.join(process.cwd(), module_folder, "node_modules", "iotdb");
console.log("- cleanup");
console.log(" path:", iotdb_dir);
try {
_rmdirSync(iotdb_dir);
} catch (x) {
}
} | javascript | function (module_name, module_folder) {
var iotdb_dir = path.join(process.cwd(), module_folder, "node_modules", "iotdb");
console.log("- cleanup");
console.log(" path:", iotdb_dir);
try {
_rmdirSync(iotdb_dir);
} catch (x) {
}
} | [
"function",
"(",
"module_name",
",",
"module_folder",
")",
"{",
"var",
"iotdb_dir",
"=",
"path",
".",
"join",
"(",
"process",
".",
"cwd",
"(",
")",
",",
"module_folder",
",",
"\"node_modules\"",
",",
"\"iotdb\"",
")",
";",
"console",
".",
"log",
"(",
"\"- cleanup\"",
")",
";",
"console",
".",
"log",
"(",
"\" path:\"",
",",
"iotdb_dir",
")",
";",
"try",
"{",
"_rmdirSync",
"(",
"iotdb_dir",
")",
";",
"}",
"catch",
"(",
"x",
")",
"{",
"}",
"}"
]
| We don't need to have many copies of IOTDB laying about | [
"We",
"don",
"t",
"need",
"to",
"have",
"many",
"copies",
"of",
"IOTDB",
"laying",
"about"
]
| ed6535aa17c8b0538f43a876c9a6025e26a389e3 | https://github.com/dpjanes/iotdb-homestar/blob/ed6535aa17c8b0538f43a876c9a6025e26a389e3/bin/commands/install.js#L239-L248 |
|
47,020 | dpjanes/iotdb-homestar | bin/commands/install.js | function (module_name, module_folder, callback) {
var module_folder = path.resolve(module_folder)
var module_packaged = _load_package(module_folder);
var module_dependencies = _.d.get(module_packaged, "/dependencies");
if (!module_dependencies) {
return callback();
}
module_dependencies = _.keys(module_dependencies);
var _install_next = function() {
if (module_dependencies.length === 0) {
return callback();
}
var dname = module_dependencies.pop();
var dependency_folder = path.join(module_folder, "node_modules", dname);
var dependency_homestard = _load_homestar(dependency_folder);
var is_module = _.d.get(dependency_homestard, "/module", false);
if (!is_module) {
return _install_next();
}
console.log("- found dependency:", dname);
_install(dname, function() {
try {
console.log("- cleanup");
console.log(" path:", dependency_folder);
_rmdirSync(dependency_folder);
} catch (x) {
}
_install_next();
});
}
_install_next();
} | javascript | function (module_name, module_folder, callback) {
var module_folder = path.resolve(module_folder)
var module_packaged = _load_package(module_folder);
var module_dependencies = _.d.get(module_packaged, "/dependencies");
if (!module_dependencies) {
return callback();
}
module_dependencies = _.keys(module_dependencies);
var _install_next = function() {
if (module_dependencies.length === 0) {
return callback();
}
var dname = module_dependencies.pop();
var dependency_folder = path.join(module_folder, "node_modules", dname);
var dependency_homestard = _load_homestar(dependency_folder);
var is_module = _.d.get(dependency_homestard, "/module", false);
if (!is_module) {
return _install_next();
}
console.log("- found dependency:", dname);
_install(dname, function() {
try {
console.log("- cleanup");
console.log(" path:", dependency_folder);
_rmdirSync(dependency_folder);
} catch (x) {
}
_install_next();
});
}
_install_next();
} | [
"function",
"(",
"module_name",
",",
"module_folder",
",",
"callback",
")",
"{",
"var",
"module_folder",
"=",
"path",
".",
"resolve",
"(",
"module_folder",
")",
"var",
"module_packaged",
"=",
"_load_package",
"(",
"module_folder",
")",
";",
"var",
"module_dependencies",
"=",
"_",
".",
"d",
".",
"get",
"(",
"module_packaged",
",",
"\"/dependencies\"",
")",
";",
"if",
"(",
"!",
"module_dependencies",
")",
"{",
"return",
"callback",
"(",
")",
";",
"}",
"module_dependencies",
"=",
"_",
".",
"keys",
"(",
"module_dependencies",
")",
";",
"var",
"_install_next",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"module_dependencies",
".",
"length",
"===",
"0",
")",
"{",
"return",
"callback",
"(",
")",
";",
"}",
"var",
"dname",
"=",
"module_dependencies",
".",
"pop",
"(",
")",
";",
"var",
"dependency_folder",
"=",
"path",
".",
"join",
"(",
"module_folder",
",",
"\"node_modules\"",
",",
"dname",
")",
";",
"var",
"dependency_homestard",
"=",
"_load_homestar",
"(",
"dependency_folder",
")",
";",
"var",
"is_module",
"=",
"_",
".",
"d",
".",
"get",
"(",
"dependency_homestard",
",",
"\"/module\"",
",",
"false",
")",
";",
"if",
"(",
"!",
"is_module",
")",
"{",
"return",
"_install_next",
"(",
")",
";",
"}",
"console",
".",
"log",
"(",
"\"- found dependency:\"",
",",
"dname",
")",
";",
"_install",
"(",
"dname",
",",
"function",
"(",
")",
"{",
"try",
"{",
"console",
".",
"log",
"(",
"\"- cleanup\"",
")",
";",
"console",
".",
"log",
"(",
"\" path:\"",
",",
"dependency_folder",
")",
";",
"_rmdirSync",
"(",
"dependency_folder",
")",
";",
"}",
"catch",
"(",
"x",
")",
"{",
"}",
"_install_next",
"(",
")",
";",
"}",
")",
";",
"}",
"_install_next",
"(",
")",
";",
"}"
]
| homestar.dependencies can allow more things to be installed into homestar,
essentially recursively | [
"homestar",
".",
"dependencies",
"can",
"allow",
"more",
"things",
"to",
"be",
"installed",
"into",
"homestar",
"essentially",
"recursively"
]
| ed6535aa17c8b0538f43a876c9a6025e26a389e3 | https://github.com/dpjanes/iotdb-homestar/blob/ed6535aa17c8b0538f43a876c9a6025e26a389e3/bin/commands/install.js#L254-L293 |
|
47,021 | dpjanes/iotdb-homestar | bin/commands/install.js | function() {
try {
var statbuf = fs.statSync(folder);
if (statbuf.isDirectory()) {
return;
}
}
catch (x) {
}
try {
fs.mkdirSync("node_modules");
} catch (x) {
}
statbuf = fs.statSync(folder);
if (statbuf.isDirectory()) {
return;
}
} | javascript | function() {
try {
var statbuf = fs.statSync(folder);
if (statbuf.isDirectory()) {
return;
}
}
catch (x) {
}
try {
fs.mkdirSync("node_modules");
} catch (x) {
}
statbuf = fs.statSync(folder);
if (statbuf.isDirectory()) {
return;
}
} | [
"function",
"(",
")",
"{",
"try",
"{",
"var",
"statbuf",
"=",
"fs",
".",
"statSync",
"(",
"folder",
")",
";",
"if",
"(",
"statbuf",
".",
"isDirectory",
"(",
")",
")",
"{",
"return",
";",
"}",
"}",
"catch",
"(",
"x",
")",
"{",
"}",
"try",
"{",
"fs",
".",
"mkdirSync",
"(",
"\"node_modules\"",
")",
";",
"}",
"catch",
"(",
"x",
")",
"{",
"}",
"statbuf",
"=",
"fs",
".",
"statSync",
"(",
"folder",
")",
";",
"if",
"(",
"statbuf",
".",
"isDirectory",
"(",
")",
")",
"{",
"return",
";",
"}",
"}"
]
| The node_modules directory always goes in the current directory
so that NPM doesn't start placing things in parent directories | [
"The",
"node_modules",
"directory",
"always",
"goes",
"in",
"the",
"current",
"directory",
"so",
"that",
"NPM",
"doesn",
"t",
"start",
"placing",
"things",
"in",
"parent",
"directories"
]
| ed6535aa17c8b0538f43a876c9a6025e26a389e3 | https://github.com/dpjanes/iotdb-homestar/blob/ed6535aa17c8b0538f43a876c9a6025e26a389e3/bin/commands/install.js#L299-L318 |
|
47,022 | creationix/git-node-fs | lib/node-fs.js | readFile | function readFile(path, callback) {
nodeFs.readFile(path, function (err, binary) {
if (err) {
if (err.code === "ENOENT") return callback();
return callback(err);
}
return callback(null, binary);
});
} | javascript | function readFile(path, callback) {
nodeFs.readFile(path, function (err, binary) {
if (err) {
if (err.code === "ENOENT") return callback();
return callback(err);
}
return callback(null, binary);
});
} | [
"function",
"readFile",
"(",
"path",
",",
"callback",
")",
"{",
"nodeFs",
".",
"readFile",
"(",
"path",
",",
"function",
"(",
"err",
",",
"binary",
")",
"{",
"if",
"(",
"err",
")",
"{",
"if",
"(",
"err",
".",
"code",
"===",
"\"ENOENT\"",
")",
"return",
"callback",
"(",
")",
";",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"return",
"callback",
"(",
"null",
",",
"binary",
")",
";",
"}",
")",
";",
"}"
]
| Reads all bytes for given path. => binary => undefined if file does not exist | [
"Reads",
"all",
"bytes",
"for",
"given",
"path",
".",
"=",
">",
"binary",
"=",
">",
"undefined",
"if",
"file",
"does",
"not",
"exist"
]
| 7c691d7281b49b1be77426701c2bf0535e1abcc9 | https://github.com/creationix/git-node-fs/blob/7c691d7281b49b1be77426701c2bf0535e1abcc9/lib/node-fs.js#L17-L25 |
47,023 | creationix/git-node-fs | lib/node-fs.js | readChunk | function readChunk(path, start, end, callback) {
if (end < 0) {
return readLastChunk(path, start, end, callback);
}
var stream = nodeFs.createReadStream(path, {
start: start,
end: end - 1
});
var chunks = [];
stream.on("readable", function () {
var chunk = stream.read();
if (chunk === null) return callback(null, Buffer.concat(chunks));
return chunks.push(chunk);
});
stream.on("error", function (err) {
if (err.code === "ENOENT") return callback();
return callback(err);
});
} | javascript | function readChunk(path, start, end, callback) {
if (end < 0) {
return readLastChunk(path, start, end, callback);
}
var stream = nodeFs.createReadStream(path, {
start: start,
end: end - 1
});
var chunks = [];
stream.on("readable", function () {
var chunk = stream.read();
if (chunk === null) return callback(null, Buffer.concat(chunks));
return chunks.push(chunk);
});
stream.on("error", function (err) {
if (err.code === "ENOENT") return callback();
return callback(err);
});
} | [
"function",
"readChunk",
"(",
"path",
",",
"start",
",",
"end",
",",
"callback",
")",
"{",
"if",
"(",
"end",
"<",
"0",
")",
"{",
"return",
"readLastChunk",
"(",
"path",
",",
"start",
",",
"end",
",",
"callback",
")",
";",
"}",
"var",
"stream",
"=",
"nodeFs",
".",
"createReadStream",
"(",
"path",
",",
"{",
"start",
":",
"start",
",",
"end",
":",
"end",
"-",
"1",
"}",
")",
";",
"var",
"chunks",
"=",
"[",
"]",
";",
"stream",
".",
"on",
"(",
"\"readable\"",
",",
"function",
"(",
")",
"{",
"var",
"chunk",
"=",
"stream",
".",
"read",
"(",
")",
";",
"if",
"(",
"chunk",
"===",
"null",
")",
"return",
"callback",
"(",
"null",
",",
"Buffer",
".",
"concat",
"(",
"chunks",
")",
")",
";",
"return",
"chunks",
".",
"push",
"(",
"chunk",
")",
";",
"}",
")",
";",
"stream",
".",
"on",
"(",
"\"error\"",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
".",
"code",
"===",
"\"ENOENT\"",
")",
"return",
"callback",
"(",
")",
";",
"return",
"callback",
"(",
"err",
")",
";",
"}",
")",
";",
"}"
]
| Reads bytes from inclusive [start, end) exclusive for given path. => binary => undefined if file does not exist | [
"Reads",
"bytes",
"from",
"inclusive",
"[",
"start",
"end",
")",
"exclusive",
"for",
"given",
"path",
".",
"=",
">",
"binary",
"=",
">",
"undefined",
"if",
"file",
"does",
"not",
"exist"
]
| 7c691d7281b49b1be77426701c2bf0535e1abcc9 | https://github.com/creationix/git-node-fs/blob/7c691d7281b49b1be77426701c2bf0535e1abcc9/lib/node-fs.js#L30-L48 |
47,024 | creationix/git-node-fs | lib/node-fs.js | readLastChunk | function readLastChunk(path, start, end, callback) {
nodeFs.open(path, "r", function (err, fd) {
if (err) {
if (err.code === "EACCES") return callback();
return callback(err);
}
var buffer = new Buffer(4096);
var length = 0;
read();
// Only the first read needs to seek.
// All subsequent reads will continue from the end of the previous.
start = null;
function read() {
if (buffer.length - length === 0) {
grow();
}
nodeFs.read(fd, buffer, length, buffer.length - length, start, onread);
}
function onread(err, bytesRead) {
if (err) return callback(err);
length += bytesRead;
if (bytesRead === 0) {
return callback(null, buffer.slice(0, buffer.length + end));
}
read();
}
function grow() {
var newBuffer = new Buffer(buffer.length * 2);
buffer.copy(newBuffer);
buffer = newBuffer;
}
});
} | javascript | function readLastChunk(path, start, end, callback) {
nodeFs.open(path, "r", function (err, fd) {
if (err) {
if (err.code === "EACCES") return callback();
return callback(err);
}
var buffer = new Buffer(4096);
var length = 0;
read();
// Only the first read needs to seek.
// All subsequent reads will continue from the end of the previous.
start = null;
function read() {
if (buffer.length - length === 0) {
grow();
}
nodeFs.read(fd, buffer, length, buffer.length - length, start, onread);
}
function onread(err, bytesRead) {
if (err) return callback(err);
length += bytesRead;
if (bytesRead === 0) {
return callback(null, buffer.slice(0, buffer.length + end));
}
read();
}
function grow() {
var newBuffer = new Buffer(buffer.length * 2);
buffer.copy(newBuffer);
buffer = newBuffer;
}
});
} | [
"function",
"readLastChunk",
"(",
"path",
",",
"start",
",",
"end",
",",
"callback",
")",
"{",
"nodeFs",
".",
"open",
"(",
"path",
",",
"\"r\"",
",",
"function",
"(",
"err",
",",
"fd",
")",
"{",
"if",
"(",
"err",
")",
"{",
"if",
"(",
"err",
".",
"code",
"===",
"\"EACCES\"",
")",
"return",
"callback",
"(",
")",
";",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"var",
"buffer",
"=",
"new",
"Buffer",
"(",
"4096",
")",
";",
"var",
"length",
"=",
"0",
";",
"read",
"(",
")",
";",
"// Only the first read needs to seek.",
"// All subsequent reads will continue from the end of the previous.",
"start",
"=",
"null",
";",
"function",
"read",
"(",
")",
"{",
"if",
"(",
"buffer",
".",
"length",
"-",
"length",
"===",
"0",
")",
"{",
"grow",
"(",
")",
";",
"}",
"nodeFs",
".",
"read",
"(",
"fd",
",",
"buffer",
",",
"length",
",",
"buffer",
".",
"length",
"-",
"length",
",",
"start",
",",
"onread",
")",
";",
"}",
"function",
"onread",
"(",
"err",
",",
"bytesRead",
")",
"{",
"if",
"(",
"err",
")",
"return",
"callback",
"(",
"err",
")",
";",
"length",
"+=",
"bytesRead",
";",
"if",
"(",
"bytesRead",
"===",
"0",
")",
"{",
"return",
"callback",
"(",
"null",
",",
"buffer",
".",
"slice",
"(",
"0",
",",
"buffer",
".",
"length",
"+",
"end",
")",
")",
";",
"}",
"read",
"(",
")",
";",
"}",
"function",
"grow",
"(",
")",
"{",
"var",
"newBuffer",
"=",
"new",
"Buffer",
"(",
"buffer",
".",
"length",
"*",
"2",
")",
";",
"buffer",
".",
"copy",
"(",
"newBuffer",
")",
";",
"buffer",
"=",
"newBuffer",
";",
"}",
"}",
")",
";",
"}"
]
| Node.js readable streams do not support reading from a position to the end of the file, but we can roll our own using the lower-level fs.open and fs.read on a file descriptor, which allows read to seek. | [
"Node",
".",
"js",
"readable",
"streams",
"do",
"not",
"support",
"reading",
"from",
"a",
"position",
"to",
"the",
"end",
"of",
"the",
"file",
"but",
"we",
"can",
"roll",
"our",
"own",
"using",
"the",
"lower",
"-",
"level",
"fs",
".",
"open",
"and",
"fs",
".",
"read",
"on",
"a",
"file",
"descriptor",
"which",
"allows",
"read",
"to",
"seek",
"."
]
| 7c691d7281b49b1be77426701c2bf0535e1abcc9 | https://github.com/creationix/git-node-fs/blob/7c691d7281b49b1be77426701c2bf0535e1abcc9/lib/node-fs.js#L53-L88 |
47,025 | creationix/git-node-fs | lib/node-fs.js | writeFile | function writeFile(path, binary, callback) {
mkdirp(nodePath.dirname(path), function (err) {
if (err) return callback(err);
nodeFs.writeFile(path, binary, callback);
});
} | javascript | function writeFile(path, binary, callback) {
mkdirp(nodePath.dirname(path), function (err) {
if (err) return callback(err);
nodeFs.writeFile(path, binary, callback);
});
} | [
"function",
"writeFile",
"(",
"path",
",",
"binary",
",",
"callback",
")",
"{",
"mkdirp",
"(",
"nodePath",
".",
"dirname",
"(",
"path",
")",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"return",
"callback",
"(",
"err",
")",
";",
"nodeFs",
".",
"writeFile",
"(",
"path",
",",
"binary",
",",
"callback",
")",
";",
"}",
")",
";",
"}"
]
| Writes all bytes over file at given path. Creates all necessary parent directories. => undefined | [
"Writes",
"all",
"bytes",
"over",
"file",
"at",
"given",
"path",
".",
"Creates",
"all",
"necessary",
"parent",
"directories",
".",
"=",
">",
"undefined"
]
| 7c691d7281b49b1be77426701c2bf0535e1abcc9 | https://github.com/creationix/git-node-fs/blob/7c691d7281b49b1be77426701c2bf0535e1abcc9/lib/node-fs.js#L93-L98 |
47,026 | creationix/git-node-fs | lib/node-fs.js | rename | function rename(oldPath, newPath, callback) {
var oldBase = nodePath.dirname(oldPath);
var newBase = nodePath.dirname(newPath);
if (oldBase === newBase) {
return nodeFs.rename(oldPath, newPath, callback);
}
mkdirp(nodePath.dirname(path), function (err) {
if (err) return callback(err);
nodeFs.rename(oldPath, newPath, callback);
});
} | javascript | function rename(oldPath, newPath, callback) {
var oldBase = nodePath.dirname(oldPath);
var newBase = nodePath.dirname(newPath);
if (oldBase === newBase) {
return nodeFs.rename(oldPath, newPath, callback);
}
mkdirp(nodePath.dirname(path), function (err) {
if (err) return callback(err);
nodeFs.rename(oldPath, newPath, callback);
});
} | [
"function",
"rename",
"(",
"oldPath",
",",
"newPath",
",",
"callback",
")",
"{",
"var",
"oldBase",
"=",
"nodePath",
".",
"dirname",
"(",
"oldPath",
")",
";",
"var",
"newBase",
"=",
"nodePath",
".",
"dirname",
"(",
"newPath",
")",
";",
"if",
"(",
"oldBase",
"===",
"newBase",
")",
"{",
"return",
"nodeFs",
".",
"rename",
"(",
"oldPath",
",",
"newPath",
",",
"callback",
")",
";",
"}",
"mkdirp",
"(",
"nodePath",
".",
"dirname",
"(",
"path",
")",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"return",
"callback",
"(",
"err",
")",
";",
"nodeFs",
".",
"rename",
"(",
"oldPath",
",",
"newPath",
",",
"callback",
")",
";",
"}",
")",
";",
"}"
]
| Renames the given file. Creates all necessary parent directories. => undefined | [
"Renames",
"the",
"given",
"file",
".",
"Creates",
"all",
"necessary",
"parent",
"directories",
".",
"=",
">",
"undefined"
]
| 7c691d7281b49b1be77426701c2bf0535e1abcc9 | https://github.com/creationix/git-node-fs/blob/7c691d7281b49b1be77426701c2bf0535e1abcc9/lib/node-fs.js#L103-L113 |
47,027 | IonicaBizau/emoji-logger | lib/index.js | emojiLogger | function emojiLogger(msg, type, override) {
// Get the type
var _type = emojiLogger.types[type || "info"];
if (!_type) {
throw new Err(`There is no such logger type: ${type}`, "NO_SUCH_LOGGER_TYPE");
}
emojiLogger.log(msg, _type, override);
} | javascript | function emojiLogger(msg, type, override) {
// Get the type
var _type = emojiLogger.types[type || "info"];
if (!_type) {
throw new Err(`There is no such logger type: ${type}`, "NO_SUCH_LOGGER_TYPE");
}
emojiLogger.log(msg, _type, override);
} | [
"function",
"emojiLogger",
"(",
"msg",
",",
"type",
",",
"override",
")",
"{",
"// Get the type",
"var",
"_type",
"=",
"emojiLogger",
".",
"types",
"[",
"type",
"||",
"\"info\"",
"]",
";",
"if",
"(",
"!",
"_type",
")",
"{",
"throw",
"new",
"Err",
"(",
"`",
"${",
"type",
"}",
"`",
",",
"\"NO_SUCH_LOGGER_TYPE\"",
")",
";",
"}",
"emojiLogger",
".",
"log",
"(",
"msg",
",",
"_type",
",",
"override",
")",
";",
"}"
]
| emojiLogger
Logs the specified message.
@name emojiLogger
@function
@param {String} msg The message to log.
@param {String} type The message type (default: `"info"`).
@param {Object} override An object to override the type object fields. | [
"emojiLogger",
"Logs",
"the",
"specified",
"message",
"."
]
| 50f33240f31059642a805badd018e1bf0ec90bff | https://github.com/IonicaBizau/emoji-logger/blob/50f33240f31059642a805badd018e1bf0ec90bff/lib/index.js#L22-L31 |
47,028 | ghosert/grunt-applymin | tasks/applymin.js | function (targetFilePath, abspaths) {
// Change 'assets/mdeditor.min.js' to 'assets/' and 'mdeditor.min.js'
var pathFilename = _splitPathAndFilename(targetFilePath);
var targetPath = pathFilename[0];
var targetFilename = pathFilename[1];
// bug fix: assets/xxxxxxxx.mdeditor.min.js, xxxxxxxx can't contain '/' or white character
// otherwise 'assets/mdeditor/1111.mmm.min.js' matched target filename: 'assets/mmm.min.js', which is incorrect.
var filenamePattern = new RegExp(targetPath + '[^\\/\\s]+?\\.' + targetFilename);
// Find the revision file based on targetFilePath defined in html template, if there are multiple files matched, pick up the latest one.
var revTargetFilePath = null;
var revTargetFileModifyTime = null;
for (var index in abspaths) {
if (abspaths[index].match(filenamePattern)) { // there could be more than one revision files matched filenamePattern
// match the first revision file.
if (revTargetFilePath === null) {
revTargetFilePath = abspaths[index];
// match the one more revision files, pick up the latest files.
} else {
if (revTargetFileModifyTime === null) {
revTargetFileModifyTime = fs.lstatSync(revTargetFilePath).mtime;
}
var currentFileModifyTime = fs.lstatSync(abspaths[index]).mtime;
if (currentFileModifyTime > revTargetFileModifyTime) {
revTargetFilePath = abspaths[index];
revTargetFileModifyTime = currentFileModifyTime;
}
}
}
}
if (revTargetFilePath === null) {
grunt.warn('In the file: ' + templateFilename + ', the target filename: ' + targetFilePath + ' has not been handled to produce a corresponding revision file.');
}
return revTargetFilePath;
} | javascript | function (targetFilePath, abspaths) {
// Change 'assets/mdeditor.min.js' to 'assets/' and 'mdeditor.min.js'
var pathFilename = _splitPathAndFilename(targetFilePath);
var targetPath = pathFilename[0];
var targetFilename = pathFilename[1];
// bug fix: assets/xxxxxxxx.mdeditor.min.js, xxxxxxxx can't contain '/' or white character
// otherwise 'assets/mdeditor/1111.mmm.min.js' matched target filename: 'assets/mmm.min.js', which is incorrect.
var filenamePattern = new RegExp(targetPath + '[^\\/\\s]+?\\.' + targetFilename);
// Find the revision file based on targetFilePath defined in html template, if there are multiple files matched, pick up the latest one.
var revTargetFilePath = null;
var revTargetFileModifyTime = null;
for (var index in abspaths) {
if (abspaths[index].match(filenamePattern)) { // there could be more than one revision files matched filenamePattern
// match the first revision file.
if (revTargetFilePath === null) {
revTargetFilePath = abspaths[index];
// match the one more revision files, pick up the latest files.
} else {
if (revTargetFileModifyTime === null) {
revTargetFileModifyTime = fs.lstatSync(revTargetFilePath).mtime;
}
var currentFileModifyTime = fs.lstatSync(abspaths[index]).mtime;
if (currentFileModifyTime > revTargetFileModifyTime) {
revTargetFilePath = abspaths[index];
revTargetFileModifyTime = currentFileModifyTime;
}
}
}
}
if (revTargetFilePath === null) {
grunt.warn('In the file: ' + templateFilename + ', the target filename: ' + targetFilePath + ' has not been handled to produce a corresponding revision file.');
}
return revTargetFilePath;
} | [
"function",
"(",
"targetFilePath",
",",
"abspaths",
")",
"{",
"// Change 'assets/mdeditor.min.js' to 'assets/' and 'mdeditor.min.js'",
"var",
"pathFilename",
"=",
"_splitPathAndFilename",
"(",
"targetFilePath",
")",
";",
"var",
"targetPath",
"=",
"pathFilename",
"[",
"0",
"]",
";",
"var",
"targetFilename",
"=",
"pathFilename",
"[",
"1",
"]",
";",
"// bug fix: assets/xxxxxxxx.mdeditor.min.js, xxxxxxxx can't contain '/' or white character",
"// otherwise 'assets/mdeditor/1111.mmm.min.js' matched target filename: 'assets/mmm.min.js', which is incorrect.",
"var",
"filenamePattern",
"=",
"new",
"RegExp",
"(",
"targetPath",
"+",
"'[^\\\\/\\\\s]+?\\\\.'",
"+",
"targetFilename",
")",
";",
"// Find the revision file based on targetFilePath defined in html template, if there are multiple files matched, pick up the latest one.",
"var",
"revTargetFilePath",
"=",
"null",
";",
"var",
"revTargetFileModifyTime",
"=",
"null",
";",
"for",
"(",
"var",
"index",
"in",
"abspaths",
")",
"{",
"if",
"(",
"abspaths",
"[",
"index",
"]",
".",
"match",
"(",
"filenamePattern",
")",
")",
"{",
"// there could be more than one revision files matched filenamePattern",
"// match the first revision file.",
"if",
"(",
"revTargetFilePath",
"===",
"null",
")",
"{",
"revTargetFilePath",
"=",
"abspaths",
"[",
"index",
"]",
";",
"// match the one more revision files, pick up the latest files.",
"}",
"else",
"{",
"if",
"(",
"revTargetFileModifyTime",
"===",
"null",
")",
"{",
"revTargetFileModifyTime",
"=",
"fs",
".",
"lstatSync",
"(",
"revTargetFilePath",
")",
".",
"mtime",
";",
"}",
"var",
"currentFileModifyTime",
"=",
"fs",
".",
"lstatSync",
"(",
"abspaths",
"[",
"index",
"]",
")",
".",
"mtime",
";",
"if",
"(",
"currentFileModifyTime",
">",
"revTargetFileModifyTime",
")",
"{",
"revTargetFilePath",
"=",
"abspaths",
"[",
"index",
"]",
";",
"revTargetFileModifyTime",
"=",
"currentFileModifyTime",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"revTargetFilePath",
"===",
"null",
")",
"{",
"grunt",
".",
"warn",
"(",
"'In the file: '",
"+",
"templateFilename",
"+",
"', the target filename: '",
"+",
"targetFilePath",
"+",
"' has not been handled to produce a corresponding revision file.'",
")",
";",
"}",
"return",
"revTargetFilePath",
";",
"}"
]
| Get the revTargetFilePath based on targetFilePath. | [
"Get",
"the",
"revTargetFilePath",
"based",
"on",
"targetFilePath",
"."
]
| 2e8e0a7cb0c92ae12f1440dea1675dea5c7f1490 | https://github.com/ghosert/grunt-applymin/blob/2e8e0a7cb0c92ae12f1440dea1675dea5c7f1490/tasks/applymin.js#L132-L167 |
|
47,029 | zuren/catdown | lib/codemirror/keymap/sublime.js | findPosSubword | function findPosSubword(doc, start, dir) {
if (dir < 0 && start.ch == 0) return doc.clipPos(Pos(start.line - 1));
var line = doc.getLine(start.line);
if (dir > 0 && start.ch >= line.length) return doc.clipPos(Pos(start.line + 1, 0));
var state = "start", type;
for (var pos = start.ch, e = dir < 0 ? 0 : line.length, i = 0; pos != e; pos += dir, i++) {
var next = line.charAt(dir < 0 ? pos - 1 : pos);
var cat = next != "_" && CodeMirror.isWordChar(next) ? "w" : "o";
if (cat == "w" && next.toUpperCase() == next) cat = "W";
if (state == "start") {
if (cat != "o") { state = "in"; type = cat; }
} else if (state == "in") {
if (type != cat) {
if (type == "w" && cat == "W" && dir < 0) pos--;
if (type == "W" && cat == "w" && dir > 0) { type = "w"; continue; }
break;
}
}
}
return Pos(start.line, pos);
} | javascript | function findPosSubword(doc, start, dir) {
if (dir < 0 && start.ch == 0) return doc.clipPos(Pos(start.line - 1));
var line = doc.getLine(start.line);
if (dir > 0 && start.ch >= line.length) return doc.clipPos(Pos(start.line + 1, 0));
var state = "start", type;
for (var pos = start.ch, e = dir < 0 ? 0 : line.length, i = 0; pos != e; pos += dir, i++) {
var next = line.charAt(dir < 0 ? pos - 1 : pos);
var cat = next != "_" && CodeMirror.isWordChar(next) ? "w" : "o";
if (cat == "w" && next.toUpperCase() == next) cat = "W";
if (state == "start") {
if (cat != "o") { state = "in"; type = cat; }
} else if (state == "in") {
if (type != cat) {
if (type == "w" && cat == "W" && dir < 0) pos--;
if (type == "W" && cat == "w" && dir > 0) { type = "w"; continue; }
break;
}
}
}
return Pos(start.line, pos);
} | [
"function",
"findPosSubword",
"(",
"doc",
",",
"start",
",",
"dir",
")",
"{",
"if",
"(",
"dir",
"<",
"0",
"&&",
"start",
".",
"ch",
"==",
"0",
")",
"return",
"doc",
".",
"clipPos",
"(",
"Pos",
"(",
"start",
".",
"line",
"-",
"1",
")",
")",
";",
"var",
"line",
"=",
"doc",
".",
"getLine",
"(",
"start",
".",
"line",
")",
";",
"if",
"(",
"dir",
">",
"0",
"&&",
"start",
".",
"ch",
">=",
"line",
".",
"length",
")",
"return",
"doc",
".",
"clipPos",
"(",
"Pos",
"(",
"start",
".",
"line",
"+",
"1",
",",
"0",
")",
")",
";",
"var",
"state",
"=",
"\"start\"",
",",
"type",
";",
"for",
"(",
"var",
"pos",
"=",
"start",
".",
"ch",
",",
"e",
"=",
"dir",
"<",
"0",
"?",
"0",
":",
"line",
".",
"length",
",",
"i",
"=",
"0",
";",
"pos",
"!=",
"e",
";",
"pos",
"+=",
"dir",
",",
"i",
"++",
")",
"{",
"var",
"next",
"=",
"line",
".",
"charAt",
"(",
"dir",
"<",
"0",
"?",
"pos",
"-",
"1",
":",
"pos",
")",
";",
"var",
"cat",
"=",
"next",
"!=",
"\"_\"",
"&&",
"CodeMirror",
".",
"isWordChar",
"(",
"next",
")",
"?",
"\"w\"",
":",
"\"o\"",
";",
"if",
"(",
"cat",
"==",
"\"w\"",
"&&",
"next",
".",
"toUpperCase",
"(",
")",
"==",
"next",
")",
"cat",
"=",
"\"W\"",
";",
"if",
"(",
"state",
"==",
"\"start\"",
")",
"{",
"if",
"(",
"cat",
"!=",
"\"o\"",
")",
"{",
"state",
"=",
"\"in\"",
";",
"type",
"=",
"cat",
";",
"}",
"}",
"else",
"if",
"(",
"state",
"==",
"\"in\"",
")",
"{",
"if",
"(",
"type",
"!=",
"cat",
")",
"{",
"if",
"(",
"type",
"==",
"\"w\"",
"&&",
"cat",
"==",
"\"W\"",
"&&",
"dir",
"<",
"0",
")",
"pos",
"--",
";",
"if",
"(",
"type",
"==",
"\"W\"",
"&&",
"cat",
"==",
"\"w\"",
"&&",
"dir",
">",
"0",
")",
"{",
"type",
"=",
"\"w\"",
";",
"continue",
";",
"}",
"break",
";",
"}",
"}",
"}",
"return",
"Pos",
"(",
"start",
".",
"line",
",",
"pos",
")",
";",
"}"
]
| This is not exactly Sublime's algorithm. I couldn't make heads or tails of that. | [
"This",
"is",
"not",
"exactly",
"Sublime",
"s",
"algorithm",
".",
"I",
"couldn",
"t",
"make",
"heads",
"or",
"tails",
"of",
"that",
"."
]
| c45d6e3ca365c5f73cd9903a4ed6ef1369475327 | https://github.com/zuren/catdown/blob/c45d6e3ca365c5f73cd9903a4ed6ef1369475327/lib/codemirror/keymap/sublime.js#L17-L37 |
47,030 | hkjels/ntask | lib/task.js | Task | function Task(task) {
_.extend(this, task);
if (task != undefined) this.createId();
// Short id
this.__defineGetter__('id', function () {
return this.__uuid__.substr(0, 8).toString();
});
// Keyword
this.__defineGetter__('keyword', function () {
return this.labels[0].replace('#', '').toUpperCase();
});
// Stemmed
this.__defineGetter__('stemmed', function () {
return (this.title+' '+this.body).toLowerCase()
.split(' ').map(stem).join(' ');
});
// All
this.__defineGetter__('all', function () {
return '*';
});
} | javascript | function Task(task) {
_.extend(this, task);
if (task != undefined) this.createId();
// Short id
this.__defineGetter__('id', function () {
return this.__uuid__.substr(0, 8).toString();
});
// Keyword
this.__defineGetter__('keyword', function () {
return this.labels[0].replace('#', '').toUpperCase();
});
// Stemmed
this.__defineGetter__('stemmed', function () {
return (this.title+' '+this.body).toLowerCase()
.split(' ').map(stem).join(' ');
});
// All
this.__defineGetter__('all', function () {
return '*';
});
} | [
"function",
"Task",
"(",
"task",
")",
"{",
"_",
".",
"extend",
"(",
"this",
",",
"task",
")",
";",
"if",
"(",
"task",
"!=",
"undefined",
")",
"this",
".",
"createId",
"(",
")",
";",
"// Short id",
"this",
".",
"__defineGetter__",
"(",
"'id'",
",",
"function",
"(",
")",
"{",
"return",
"this",
".",
"__uuid__",
".",
"substr",
"(",
"0",
",",
"8",
")",
".",
"toString",
"(",
")",
";",
"}",
")",
";",
"// Keyword",
"this",
".",
"__defineGetter__",
"(",
"'keyword'",
",",
"function",
"(",
")",
"{",
"return",
"this",
".",
"labels",
"[",
"0",
"]",
".",
"replace",
"(",
"'#'",
",",
"''",
")",
".",
"toUpperCase",
"(",
")",
";",
"}",
")",
";",
"// Stemmed",
"this",
".",
"__defineGetter__",
"(",
"'stemmed'",
",",
"function",
"(",
")",
"{",
"return",
"(",
"this",
".",
"title",
"+",
"' '",
"+",
"this",
".",
"body",
")",
".",
"toLowerCase",
"(",
")",
".",
"split",
"(",
"' '",
")",
".",
"map",
"(",
"stem",
")",
".",
"join",
"(",
"' '",
")",
";",
"}",
")",
";",
"// All",
"this",
".",
"__defineGetter__",
"(",
"'all'",
",",
"function",
"(",
")",
"{",
"return",
"'*'",
";",
"}",
")",
";",
"}"
]
| Task
Model used by Barricane | [
"Task",
"Model",
"used",
"by",
"Barricane"
]
| e0552042e743ef9584bc0f911245635df7acd634 | https://github.com/hkjels/ntask/blob/e0552042e743ef9584bc0f911245635df7acd634/lib/task.js#L27-L51 |
47,031 | dpjanes/iotdb-homestar | bin/commands/old/model-to-jsonld.js | function (v, paramd) {
var nd = {};
var _add = function(v) {
if (!_.is.String(v)) {
return false;
}
var vmatch = v.match(/^([-a-z0-9]*):.+/);
if (!vmatch) {
return false;
}
var nshort = vmatch[1];
var nurl = _namespace[nshort];
if (!nurl) {
return false;
}
nd[nshort] = nurl;
return true;
};
var _walk = function(o) {
if (_.is.Object(o)) {
for (var key in o) {
if (!_add(key)) {
continue;
} else if (!key.match(/^iot/)) {
continue;
} else if (key === "iot:help") {
continue;
}
var sv = o[key];
if (_walk(sv)) {
nd[key] = {
"@id": _ld_expand(key),
"@type": "@id"
};
}
}
} else if (_.is.Array(o)) {
var any = false;
o.map(function(sv) {
_add(sv);
any |= _walk(sv);
});
return any;
} else if (_.is.String(o)) {
if (_add(o)) {
return true;
}
}
};
_walk(v);
if (!v["@context"]) {
v["@context"] = {};
}
_.extend(v["@context"], nd);
return v;
} | javascript | function (v, paramd) {
var nd = {};
var _add = function(v) {
if (!_.is.String(v)) {
return false;
}
var vmatch = v.match(/^([-a-z0-9]*):.+/);
if (!vmatch) {
return false;
}
var nshort = vmatch[1];
var nurl = _namespace[nshort];
if (!nurl) {
return false;
}
nd[nshort] = nurl;
return true;
};
var _walk = function(o) {
if (_.is.Object(o)) {
for (var key in o) {
if (!_add(key)) {
continue;
} else if (!key.match(/^iot/)) {
continue;
} else if (key === "iot:help") {
continue;
}
var sv = o[key];
if (_walk(sv)) {
nd[key] = {
"@id": _ld_expand(key),
"@type": "@id"
};
}
}
} else if (_.is.Array(o)) {
var any = false;
o.map(function(sv) {
_add(sv);
any |= _walk(sv);
});
return any;
} else if (_.is.String(o)) {
if (_add(o)) {
return true;
}
}
};
_walk(v);
if (!v["@context"]) {
v["@context"] = {};
}
_.extend(v["@context"], nd);
return v;
} | [
"function",
"(",
"v",
",",
"paramd",
")",
"{",
"var",
"nd",
"=",
"{",
"}",
";",
"var",
"_add",
"=",
"function",
"(",
"v",
")",
"{",
"if",
"(",
"!",
"_",
".",
"is",
".",
"String",
"(",
"v",
")",
")",
"{",
"return",
"false",
";",
"}",
"var",
"vmatch",
"=",
"v",
".",
"match",
"(",
"/",
"^([-a-z0-9]*):.+",
"/",
")",
";",
"if",
"(",
"!",
"vmatch",
")",
"{",
"return",
"false",
";",
"}",
"var",
"nshort",
"=",
"vmatch",
"[",
"1",
"]",
";",
"var",
"nurl",
"=",
"_namespace",
"[",
"nshort",
"]",
";",
"if",
"(",
"!",
"nurl",
")",
"{",
"return",
"false",
";",
"}",
"nd",
"[",
"nshort",
"]",
"=",
"nurl",
";",
"return",
"true",
";",
"}",
";",
"var",
"_walk",
"=",
"function",
"(",
"o",
")",
"{",
"if",
"(",
"_",
".",
"is",
".",
"Object",
"(",
"o",
")",
")",
"{",
"for",
"(",
"var",
"key",
"in",
"o",
")",
"{",
"if",
"(",
"!",
"_add",
"(",
"key",
")",
")",
"{",
"continue",
";",
"}",
"else",
"if",
"(",
"!",
"key",
".",
"match",
"(",
"/",
"^iot",
"/",
")",
")",
"{",
"continue",
";",
"}",
"else",
"if",
"(",
"key",
"===",
"\"iot:help\"",
")",
"{",
"continue",
";",
"}",
"var",
"sv",
"=",
"o",
"[",
"key",
"]",
";",
"if",
"(",
"_walk",
"(",
"sv",
")",
")",
"{",
"nd",
"[",
"key",
"]",
"=",
"{",
"\"@id\"",
":",
"_ld_expand",
"(",
"key",
")",
",",
"\"@type\"",
":",
"\"@id\"",
"}",
";",
"}",
"}",
"}",
"else",
"if",
"(",
"_",
".",
"is",
".",
"Array",
"(",
"o",
")",
")",
"{",
"var",
"any",
"=",
"false",
";",
"o",
".",
"map",
"(",
"function",
"(",
"sv",
")",
"{",
"_add",
"(",
"sv",
")",
";",
"any",
"|=",
"_walk",
"(",
"sv",
")",
";",
"}",
")",
";",
"return",
"any",
";",
"}",
"else",
"if",
"(",
"_",
".",
"is",
".",
"String",
"(",
"o",
")",
")",
"{",
"if",
"(",
"_add",
"(",
"o",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
";",
"_walk",
"(",
"v",
")",
";",
"if",
"(",
"!",
"v",
"[",
"\"@context\"",
"]",
")",
"{",
"v",
"[",
"\"@context\"",
"]",
"=",
"{",
"}",
";",
"}",
"_",
".",
"extend",
"(",
"v",
"[",
"\"@context\"",
"]",
",",
"nd",
")",
";",
"return",
"v",
";",
"}"
]
| This make sure all name spaces and @id types
we are aware of are properly represented
in the @context | [
"This",
"make",
"sure",
"all",
"name",
"spaces",
"and"
]
| ed6535aa17c8b0538f43a876c9a6025e26a389e3 | https://github.com/dpjanes/iotdb-homestar/blob/ed6535aa17c8b0538f43a876c9a6025e26a389e3/bin/commands/old/model-to-jsonld.js#L169-L234 |
|
47,032 | urosjarc/gitbook-plugin-build | src/index.js | function () { // eslint-disable-line object-shorthand
// Inits helper
helper.init(this);
// Check cli args for output format, and override on existance of string.
if (typeof pluginBuildFlag === 'string' || pluginBuildFlag instanceof String) {
helper.config.format = pluginBuildFlag;
}
// Fill summary array
this.book.summary.walk((article) => {
helper.summary.push(article);
});
} | javascript | function () { // eslint-disable-line object-shorthand
// Inits helper
helper.init(this);
// Check cli args for output format, and override on existance of string.
if (typeof pluginBuildFlag === 'string' || pluginBuildFlag instanceof String) {
helper.config.format = pluginBuildFlag;
}
// Fill summary array
this.book.summary.walk((article) => {
helper.summary.push(article);
});
} | [
"function",
"(",
")",
"{",
"// eslint-disable-line object-shorthand",
"// Inits helper",
"helper",
".",
"init",
"(",
"this",
")",
";",
"// Check cli args for output format, and override on existance of string.",
"if",
"(",
"typeof",
"pluginBuildFlag",
"===",
"'string'",
"||",
"pluginBuildFlag",
"instanceof",
"String",
")",
"{",
"helper",
".",
"config",
".",
"format",
"=",
"pluginBuildFlag",
";",
"}",
"// Fill summary array",
"this",
".",
"book",
".",
"summary",
".",
"walk",
"(",
"(",
"article",
")",
"=>",
"{",
"helper",
".",
"summary",
".",
"push",
"(",
"article",
")",
";",
"}",
")",
";",
"}"
]
| Gitbook hook on initilization.
@memberOf module:index~hooks | [
"Gitbook",
"hook",
"on",
"initilization",
"."
]
| 0a77829ab81a65c70bea57f72a7256e60a1004b1 | https://github.com/urosjarc/gitbook-plugin-build/blob/0a77829ab81a65c70bea57f72a7256e60a1004b1/src/index.js#L28-L41 |
|
47,033 | urosjarc/gitbook-plugin-build | src/index.js | function () { // eslint-disable-line object-shorthand
const self = this;
const outputPath = helper.getOutput();
// Render template.
const rawContent = helper.renderTemp({summary: helper.summary});
// Create output dir.
mkdirp.sync(path.parse(outputPath).dir);
// Compile rendered main file
return helper.pandocCompile(rawContent)
.then((compiledContent) => {
// Write file to output dir.
fs.writeFileSync(outputPath, compiledContent);
// Log action.
self.log.info.ln('plugin-build(output):', helper.config.output);
});
} | javascript | function () { // eslint-disable-line object-shorthand
const self = this;
const outputPath = helper.getOutput();
// Render template.
const rawContent = helper.renderTemp({summary: helper.summary});
// Create output dir.
mkdirp.sync(path.parse(outputPath).dir);
// Compile rendered main file
return helper.pandocCompile(rawContent)
.then((compiledContent) => {
// Write file to output dir.
fs.writeFileSync(outputPath, compiledContent);
// Log action.
self.log.info.ln('plugin-build(output):', helper.config.output);
});
} | [
"function",
"(",
")",
"{",
"// eslint-disable-line object-shorthand",
"const",
"self",
"=",
"this",
";",
"const",
"outputPath",
"=",
"helper",
".",
"getOutput",
"(",
")",
";",
"// Render template.",
"const",
"rawContent",
"=",
"helper",
".",
"renderTemp",
"(",
"{",
"summary",
":",
"helper",
".",
"summary",
"}",
")",
";",
"// Create output dir.",
"mkdirp",
".",
"sync",
"(",
"path",
".",
"parse",
"(",
"outputPath",
")",
".",
"dir",
")",
";",
"// Compile rendered main file",
"return",
"helper",
".",
"pandocCompile",
"(",
"rawContent",
")",
".",
"then",
"(",
"(",
"compiledContent",
")",
"=>",
"{",
"// Write file to output dir.",
"fs",
".",
"writeFileSync",
"(",
"outputPath",
",",
"compiledContent",
")",
";",
"// Log action.",
"self",
".",
"log",
".",
"info",
".",
"ln",
"(",
"'plugin-build(output):'",
",",
"helper",
".",
"config",
".",
"output",
")",
";",
"}",
")",
";",
"}"
]
| Gitbook hook on finishing.
@memberOf module:index~hooks
@returns {Promise} | [
"Gitbook",
"hook",
"on",
"finishing",
"."
]
| 0a77829ab81a65c70bea57f72a7256e60a1004b1 | https://github.com/urosjarc/gitbook-plugin-build/blob/0a77829ab81a65c70bea57f72a7256e60a1004b1/src/index.js#L48-L67 |
|
47,034 | urosjarc/gitbook-plugin-build | src/index.js | function (page) { // eslint-disable-line object-shorthand
// Fill summary with compiled page content
helper.summary.forEach((article, i, array) => {
if (article.path === page.path) {
array[i].content = page.content;
}
});
// Returns unchanged page.
return page;
} | javascript | function (page) { // eslint-disable-line object-shorthand
// Fill summary with compiled page content
helper.summary.forEach((article, i, array) => {
if (article.path === page.path) {
array[i].content = page.content;
}
});
// Returns unchanged page.
return page;
} | [
"function",
"(",
"page",
")",
"{",
"// eslint-disable-line object-shorthand",
"// Fill summary with compiled page content",
"helper",
".",
"summary",
".",
"forEach",
"(",
"(",
"article",
",",
"i",
",",
"array",
")",
"=>",
"{",
"if",
"(",
"article",
".",
"path",
"===",
"page",
".",
"path",
")",
"{",
"array",
"[",
"i",
"]",
".",
"content",
"=",
"page",
".",
"content",
";",
"}",
"}",
")",
";",
"// Returns unchanged page.",
"return",
"page",
";",
"}"
]
| Gitbook hook for page. Function will be executed
after markdown is processed with other plugins.
@memberOf module:index~hooks
@param page
@returns {page} The same as page parameter. | [
"Gitbook",
"hook",
"for",
"page",
".",
"Function",
"will",
"be",
"executed",
"after",
"markdown",
"is",
"processed",
"with",
"other",
"plugins",
"."
]
| 0a77829ab81a65c70bea57f72a7256e60a1004b1 | https://github.com/urosjarc/gitbook-plugin-build/blob/0a77829ab81a65c70bea57f72a7256e60a1004b1/src/index.js#L76-L86 |
|
47,035 | itajaja/websocket-monkeypatch | lib/index.js | sendJson | function sendJson(data, options, callback) {
var jsonData = JSON.stringify(data);
return this.send(jsonData, options, callback);
} | javascript | function sendJson(data, options, callback) {
var jsonData = JSON.stringify(data);
return this.send(jsonData, options, callback);
} | [
"function",
"sendJson",
"(",
"data",
",",
"options",
",",
"callback",
")",
"{",
"var",
"jsonData",
"=",
"JSON",
".",
"stringify",
"(",
"data",
")",
";",
"return",
"this",
".",
"send",
"(",
"jsonData",
",",
"options",
",",
"callback",
")",
";",
"}"
]
| send a json message serialized to string | [
"send",
"a",
"json",
"message",
"serialized",
"to",
"string"
]
| 7dc97366f6b863b73241a2a2f092938a8236a64e | https://github.com/itajaja/websocket-monkeypatch/blob/7dc97366f6b863b73241a2a2f092938a8236a64e/lib/index.js#L10-L13 |
47,036 | weisjohn/mongoose-csv | index.js | find_props | function find_props(schema) {
var props = _(schema.paths).keys().without('_id', 'id')
// transform the schema tree into an array for filtering
.map(function(key) { return { name : key, value : _.get(schema.tree, key) }; })
// remove paths that are annotated with csv: false
.filter(function(node) {
return typeof node.value.csv === 'undefined' || node.value.csv;
})
// remove virtuals that are annotated with csv: false
.filter(function(node) {
var opts = node.value.options;
if (!opts) return true;
return typeof opts.csv === 'undefined' || opts.csv;
})
// remove complex object types
.filter(function(node) {
var path = schema.paths[node.name];
if (!path) return true;
// filter out any of these types of properties
return [ 'Array', 'Object', 'Mixed' ].indexOf(path.instance) === -1;
})
// materialize , end chain
.pluck('name').value();
// _id at the beginning
props.unshift('_id');
return props;
} | javascript | function find_props(schema) {
var props = _(schema.paths).keys().without('_id', 'id')
// transform the schema tree into an array for filtering
.map(function(key) { return { name : key, value : _.get(schema.tree, key) }; })
// remove paths that are annotated with csv: false
.filter(function(node) {
return typeof node.value.csv === 'undefined' || node.value.csv;
})
// remove virtuals that are annotated with csv: false
.filter(function(node) {
var opts = node.value.options;
if (!opts) return true;
return typeof opts.csv === 'undefined' || opts.csv;
})
// remove complex object types
.filter(function(node) {
var path = schema.paths[node.name];
if (!path) return true;
// filter out any of these types of properties
return [ 'Array', 'Object', 'Mixed' ].indexOf(path.instance) === -1;
})
// materialize , end chain
.pluck('name').value();
// _id at the beginning
props.unshift('_id');
return props;
} | [
"function",
"find_props",
"(",
"schema",
")",
"{",
"var",
"props",
"=",
"_",
"(",
"schema",
".",
"paths",
")",
".",
"keys",
"(",
")",
".",
"without",
"(",
"'_id'",
",",
"'id'",
")",
"// transform the schema tree into an array for filtering",
".",
"map",
"(",
"function",
"(",
"key",
")",
"{",
"return",
"{",
"name",
":",
"key",
",",
"value",
":",
"_",
".",
"get",
"(",
"schema",
".",
"tree",
",",
"key",
")",
"}",
";",
"}",
")",
"// remove paths that are annotated with csv: false",
".",
"filter",
"(",
"function",
"(",
"node",
")",
"{",
"return",
"typeof",
"node",
".",
"value",
".",
"csv",
"===",
"'undefined'",
"||",
"node",
".",
"value",
".",
"csv",
";",
"}",
")",
"// remove virtuals that are annotated with csv: false",
".",
"filter",
"(",
"function",
"(",
"node",
")",
"{",
"var",
"opts",
"=",
"node",
".",
"value",
".",
"options",
";",
"if",
"(",
"!",
"opts",
")",
"return",
"true",
";",
"return",
"typeof",
"opts",
".",
"csv",
"===",
"'undefined'",
"||",
"opts",
".",
"csv",
";",
"}",
")",
"// remove complex object types",
".",
"filter",
"(",
"function",
"(",
"node",
")",
"{",
"var",
"path",
"=",
"schema",
".",
"paths",
"[",
"node",
".",
"name",
"]",
";",
"if",
"(",
"!",
"path",
")",
"return",
"true",
";",
"// filter out any of these types of properties",
"return",
"[",
"'Array'",
",",
"'Object'",
",",
"'Mixed'",
"]",
".",
"indexOf",
"(",
"path",
".",
"instance",
")",
"===",
"-",
"1",
";",
"}",
")",
"// materialize , end chain",
".",
"pluck",
"(",
"'name'",
")",
".",
"value",
"(",
")",
";",
"// _id at the beginning",
"props",
".",
"unshift",
"(",
"'_id'",
")",
";",
"return",
"props",
";",
"}"
]
| walk the paths, rejecting those that opt-out | [
"walk",
"the",
"paths",
"rejecting",
"those",
"that",
"opt",
"-",
"out"
]
| b87f1dc906ef0521a68942bfcd8b304ae274fa3b | https://github.com/weisjohn/mongoose-csv/blob/b87f1dc906ef0521a68942bfcd8b304ae274fa3b/index.js#L59-L93 |
47,037 | weisjohn/mongoose-csv | index.js | prop_to_csv | function prop_to_csv(prop) {
var val = String(prop);
if (val === 'undefined') val = '';
return '"' + val.toString().replace(/"/g, '""') + '"';
} | javascript | function prop_to_csv(prop) {
var val = String(prop);
if (val === 'undefined') val = '';
return '"' + val.toString().replace(/"/g, '""') + '"';
} | [
"function",
"prop_to_csv",
"(",
"prop",
")",
"{",
"var",
"val",
"=",
"String",
"(",
"prop",
")",
";",
"if",
"(",
"val",
"===",
"'undefined'",
")",
"val",
"=",
"''",
";",
"return",
"'\"'",
"+",
"val",
".",
"toString",
"(",
")",
".",
"replace",
"(",
"/",
"\"",
"/",
"g",
",",
"'\"\"'",
")",
"+",
"'\"'",
";",
"}"
]
| return empty string if not truthy, escape quotes | [
"return",
"empty",
"string",
"if",
"not",
"truthy",
"escape",
"quotes"
]
| b87f1dc906ef0521a68942bfcd8b304ae274fa3b | https://github.com/weisjohn/mongoose-csv/blob/b87f1dc906ef0521a68942bfcd8b304ae274fa3b/index.js#L102-L108 |
47,038 | kogarashisan/LiquidLava | lib/packages/parsers.js | function(view_config, raw_hash) {
for (var name in raw_hash) {
if (Lava.schema.DEBUG && this._allowed_hash_options.indexOf(name) == -1) Lava.t("Hash option is not supported: " + name);
if (name in this._view_config_property_setters) {
this[this._view_config_property_setters[name]](view_config, raw_hash[name]);
} else {
view_config[name] = raw_hash[name];
}
}
} | javascript | function(view_config, raw_hash) {
for (var name in raw_hash) {
if (Lava.schema.DEBUG && this._allowed_hash_options.indexOf(name) == -1) Lava.t("Hash option is not supported: " + name);
if (name in this._view_config_property_setters) {
this[this._view_config_property_setters[name]](view_config, raw_hash[name]);
} else {
view_config[name] = raw_hash[name];
}
}
} | [
"function",
"(",
"view_config",
",",
"raw_hash",
")",
"{",
"for",
"(",
"var",
"name",
"in",
"raw_hash",
")",
"{",
"if",
"(",
"Lava",
".",
"schema",
".",
"DEBUG",
"&&",
"this",
".",
"_allowed_hash_options",
".",
"indexOf",
"(",
"name",
")",
"==",
"-",
"1",
")",
"Lava",
".",
"t",
"(",
"\"Hash option is not supported: \"",
"+",
"name",
")",
";",
"if",
"(",
"name",
"in",
"this",
".",
"_view_config_property_setters",
")",
"{",
"this",
"[",
"this",
".",
"_view_config_property_setters",
"[",
"name",
"]",
"]",
"(",
"view_config",
",",
"raw_hash",
"[",
"name",
"]",
")",
";",
"}",
"else",
"{",
"view_config",
"[",
"name",
"]",
"=",
"raw_hash",
"[",
"name",
"]",
";",
"}",
"}",
"}"
]
| Store values from view's hash as config properties
@param {_cView} view_config
@param {Object} raw_hash | [
"Store",
"values",
"from",
"view",
"s",
"hash",
"as",
"config",
"properties"
]
| fb8618821a51fad373106b5cc9247464b0a23cf6 | https://github.com/kogarashisan/LiquidLava/blob/fb8618821a51fad373106b5cc9247464b0a23cf6/lib/packages/parsers.js#L102-L115 |
|
47,039 | kogarashisan/LiquidLava | lib/packages/parsers.js | function(result, raw_expression) {
if (raw_expression.arguments.length != 1) Lava.t("Expression block requires exactly one argument");
var config = {
type: 'view',
"class": 'Expression',
argument: raw_expression.arguments[0]
};
if (raw_expression.prefix == '$') {
config.container = {type: 'Morph'};
}
result.push(config);
} | javascript | function(result, raw_expression) {
if (raw_expression.arguments.length != 1) Lava.t("Expression block requires exactly one argument");
var config = {
type: 'view',
"class": 'Expression',
argument: raw_expression.arguments[0]
};
if (raw_expression.prefix == '$') {
config.container = {type: 'Morph'};
}
result.push(config);
} | [
"function",
"(",
"result",
",",
"raw_expression",
")",
"{",
"if",
"(",
"raw_expression",
".",
"arguments",
".",
"length",
"!=",
"1",
")",
"Lava",
".",
"t",
"(",
"\"Expression block requires exactly one argument\"",
")",
";",
"var",
"config",
"=",
"{",
"type",
":",
"'view'",
",",
"\"class\"",
":",
"'Expression'",
",",
"argument",
":",
"raw_expression",
".",
"arguments",
"[",
"0",
"]",
"}",
";",
"if",
"(",
"raw_expression",
".",
"prefix",
"==",
"'$'",
")",
"{",
"config",
".",
"container",
"=",
"{",
"type",
":",
"'Morph'",
"}",
";",
"}",
"result",
".",
"push",
"(",
"config",
")",
";",
"}"
]
| Compile raw expression view. Will produce a view config with class="Expression"
@param {_tTemplate} result
@param {_cRawExpression} raw_expression | [
"Compile",
"raw",
"expression",
"view",
".",
"Will",
"produce",
"a",
"view",
"config",
"with",
"class",
"=",
"Expression"
]
| fb8618821a51fad373106b5cc9247464b0a23cf6 | https://github.com/kogarashisan/LiquidLava/blob/fb8618821a51fad373106b5cc9247464b0a23cf6/lib/packages/parsers.js#L335-L353 |
|
47,040 | kogarashisan/LiquidLava | lib/packages/parsers.js | function(result, tag) {
var is_void = Lava.isVoidTag(tag.name),
tag_start_text = "<" + tag.name
+ this.renderTagAttributes(tag.attributes)
+ (is_void ? '/>' : '>'),
inner_template,
count;
this. _compileString(result, tag_start_text);
if (Lava.schema.DEBUG && is_void && tag.content) Lava.t("Void tag with content");
if (!is_void) {
if (tag.content) {
inner_template = this.compileTemplate(tag.content);
count = inner_template.length;
if (count && typeof (inner_template[0]) == 'string') {
this._compileString(result, inner_template.shift());
count--;
}
if (count) {
result.splice.apply(result, [result.length, 0].concat(inner_template));
}
}
this. _compileString(result, "</" + tag.name + ">");
}
} | javascript | function(result, tag) {
var is_void = Lava.isVoidTag(tag.name),
tag_start_text = "<" + tag.name
+ this.renderTagAttributes(tag.attributes)
+ (is_void ? '/>' : '>'),
inner_template,
count;
this. _compileString(result, tag_start_text);
if (Lava.schema.DEBUG && is_void && tag.content) Lava.t("Void tag with content");
if (!is_void) {
if (tag.content) {
inner_template = this.compileTemplate(tag.content);
count = inner_template.length;
if (count && typeof (inner_template[0]) == 'string') {
this._compileString(result, inner_template.shift());
count--;
}
if (count) {
result.splice.apply(result, [result.length, 0].concat(inner_template));
}
}
this. _compileString(result, "</" + tag.name + ">");
}
} | [
"function",
"(",
"result",
",",
"tag",
")",
"{",
"var",
"is_void",
"=",
"Lava",
".",
"isVoidTag",
"(",
"tag",
".",
"name",
")",
",",
"tag_start_text",
"=",
"\"<\"",
"+",
"tag",
".",
"name",
"+",
"this",
".",
"renderTagAttributes",
"(",
"tag",
".",
"attributes",
")",
"+",
"(",
"is_void",
"?",
"'/>'",
":",
"'>'",
")",
",",
"inner_template",
",",
"count",
";",
"this",
".",
"_compileString",
"(",
"result",
",",
"tag_start_text",
")",
";",
"if",
"(",
"Lava",
".",
"schema",
".",
"DEBUG",
"&&",
"is_void",
"&&",
"tag",
".",
"content",
")",
"Lava",
".",
"t",
"(",
"\"Void tag with content\"",
")",
";",
"if",
"(",
"!",
"is_void",
")",
"{",
"if",
"(",
"tag",
".",
"content",
")",
"{",
"inner_template",
"=",
"this",
".",
"compileTemplate",
"(",
"tag",
".",
"content",
")",
";",
"count",
"=",
"inner_template",
".",
"length",
";",
"if",
"(",
"count",
"&&",
"typeof",
"(",
"inner_template",
"[",
"0",
"]",
")",
"==",
"'string'",
")",
"{",
"this",
".",
"_compileString",
"(",
"result",
",",
"inner_template",
".",
"shift",
"(",
")",
")",
";",
"count",
"--",
";",
"}",
"if",
"(",
"count",
")",
"{",
"result",
".",
"splice",
".",
"apply",
"(",
"result",
",",
"[",
"result",
".",
"length",
",",
"0",
"]",
".",
"concat",
"(",
"inner_template",
")",
")",
";",
"}",
"}",
"this",
".",
"_compileString",
"(",
"result",
",",
"\"</\"",
"+",
"tag",
".",
"name",
"+",
"\">\"",
")",
";",
"}",
"}"
]
| Serialize the tag back into text
@param {_tTemplate} result
@param {_cRawTag} tag | [
"Serialize",
"the",
"tag",
"back",
"into",
"text"
]
| fb8618821a51fad373106b5cc9247464b0a23cf6 | https://github.com/kogarashisan/LiquidLava/blob/fb8618821a51fad373106b5cc9247464b0a23cf6/lib/packages/parsers.js#L360-L399 |
|
47,041 | kogarashisan/LiquidLava | lib/packages/parsers.js | function(raw_tag) {
var container_config = {
type: 'Element',
tag_name: raw_tag.name
};
if ('attributes' in raw_tag) this._parseContainerStaticAttributes(container_config, raw_tag.attributes);
if ('x' in raw_tag) this._parseContainerControlAttributes(container_config, raw_tag.x);
return /** @type {_cElementContainer} */ container_config;
} | javascript | function(raw_tag) {
var container_config = {
type: 'Element',
tag_name: raw_tag.name
};
if ('attributes' in raw_tag) this._parseContainerStaticAttributes(container_config, raw_tag.attributes);
if ('x' in raw_tag) this._parseContainerControlAttributes(container_config, raw_tag.x);
return /** @type {_cElementContainer} */ container_config;
} | [
"function",
"(",
"raw_tag",
")",
"{",
"var",
"container_config",
"=",
"{",
"type",
":",
"'Element'",
",",
"tag_name",
":",
"raw_tag",
".",
"name",
"}",
";",
"if",
"(",
"'attributes'",
"in",
"raw_tag",
")",
"this",
".",
"_parseContainerStaticAttributes",
"(",
"container_config",
",",
"raw_tag",
".",
"attributes",
")",
";",
"if",
"(",
"'x'",
"in",
"raw_tag",
")",
"this",
".",
"_parseContainerControlAttributes",
"(",
"container_config",
",",
"raw_tag",
".",
"x",
")",
";",
"return",
"/** @type {_cElementContainer} */",
"container_config",
";",
"}"
]
| Convert raw tag to an Element container config
@param {_cRawTag} raw_tag
@returns {_cElementContainer} | [
"Convert",
"raw",
"tag",
"to",
"an",
"Element",
"container",
"config"
]
| fb8618821a51fad373106b5cc9247464b0a23cf6 | https://github.com/kogarashisan/LiquidLava/blob/fb8618821a51fad373106b5cc9247464b0a23cf6/lib/packages/parsers.js#L656-L668 |
|
47,042 | kogarashisan/LiquidLava | lib/packages/parsers.js | function(container_config, x) {
var i,
count,
name;
if ('event' in x) {
if (typeof(x.event) != 'object') Lava.t("Malformed x:event attribute");
container_config.events = {};
for (name in x.event) {
container_config.events[name] = Lava.parsers.Common.parseTargets(x.event[name]);
}
}
// Attribute binding. Example: x:bind:src="<any_valid_expression>"
if ('bind' in x) {
if (typeof(x.bind) != 'object') Lava.t("Malformed x:bind attribute");
container_config.property_bindings = this._parseBindingsHash(x.bind);
}
if ('style' in x) {
if (typeof(x.style) != 'object') Lava.t("Malformed x:style attribute");
container_config.style_bindings = this._parseBindingsHash(x.style);
}
if ('classes' in x) {
var arguments = Lava.ExpressionParser.parse(x.classes, Lava.ExpressionParser.SEPARATORS.SEMICOLON),
class_bindings = {};
for (i = 0, count = arguments.length; i < count; i++) {
class_bindings[i] = arguments[i];
}
container_config.class_bindings = class_bindings;
}
if ('container_class' in x) {
container_config['class'] = x.container_class;
}
} | javascript | function(container_config, x) {
var i,
count,
name;
if ('event' in x) {
if (typeof(x.event) != 'object') Lava.t("Malformed x:event attribute");
container_config.events = {};
for (name in x.event) {
container_config.events[name] = Lava.parsers.Common.parseTargets(x.event[name]);
}
}
// Attribute binding. Example: x:bind:src="<any_valid_expression>"
if ('bind' in x) {
if (typeof(x.bind) != 'object') Lava.t("Malformed x:bind attribute");
container_config.property_bindings = this._parseBindingsHash(x.bind);
}
if ('style' in x) {
if (typeof(x.style) != 'object') Lava.t("Malformed x:style attribute");
container_config.style_bindings = this._parseBindingsHash(x.style);
}
if ('classes' in x) {
var arguments = Lava.ExpressionParser.parse(x.classes, Lava.ExpressionParser.SEPARATORS.SEMICOLON),
class_bindings = {};
for (i = 0, count = arguments.length; i < count; i++) {
class_bindings[i] = arguments[i];
}
container_config.class_bindings = class_bindings;
}
if ('container_class' in x) {
container_config['class'] = x.container_class;
}
} | [
"function",
"(",
"container_config",
",",
"x",
")",
"{",
"var",
"i",
",",
"count",
",",
"name",
";",
"if",
"(",
"'event'",
"in",
"x",
")",
"{",
"if",
"(",
"typeof",
"(",
"x",
".",
"event",
")",
"!=",
"'object'",
")",
"Lava",
".",
"t",
"(",
"\"Malformed x:event attribute\"",
")",
";",
"container_config",
".",
"events",
"=",
"{",
"}",
";",
"for",
"(",
"name",
"in",
"x",
".",
"event",
")",
"{",
"container_config",
".",
"events",
"[",
"name",
"]",
"=",
"Lava",
".",
"parsers",
".",
"Common",
".",
"parseTargets",
"(",
"x",
".",
"event",
"[",
"name",
"]",
")",
";",
"}",
"}",
"// Attribute binding. Example: x:bind:src=\"<any_valid_expression>\"",
"if",
"(",
"'bind'",
"in",
"x",
")",
"{",
"if",
"(",
"typeof",
"(",
"x",
".",
"bind",
")",
"!=",
"'object'",
")",
"Lava",
".",
"t",
"(",
"\"Malformed x:bind attribute\"",
")",
";",
"container_config",
".",
"property_bindings",
"=",
"this",
".",
"_parseBindingsHash",
"(",
"x",
".",
"bind",
")",
";",
"}",
"if",
"(",
"'style'",
"in",
"x",
")",
"{",
"if",
"(",
"typeof",
"(",
"x",
".",
"style",
")",
"!=",
"'object'",
")",
"Lava",
".",
"t",
"(",
"\"Malformed x:style attribute\"",
")",
";",
"container_config",
".",
"style_bindings",
"=",
"this",
".",
"_parseBindingsHash",
"(",
"x",
".",
"style",
")",
";",
"}",
"if",
"(",
"'classes'",
"in",
"x",
")",
"{",
"var",
"arguments",
"=",
"Lava",
".",
"ExpressionParser",
".",
"parse",
"(",
"x",
".",
"classes",
",",
"Lava",
".",
"ExpressionParser",
".",
"SEPARATORS",
".",
"SEMICOLON",
")",
",",
"class_bindings",
"=",
"{",
"}",
";",
"for",
"(",
"i",
"=",
"0",
",",
"count",
"=",
"arguments",
".",
"length",
";",
"i",
"<",
"count",
";",
"i",
"++",
")",
"{",
"class_bindings",
"[",
"i",
"]",
"=",
"arguments",
"[",
"i",
"]",
";",
"}",
"container_config",
".",
"class_bindings",
"=",
"class_bindings",
";",
"}",
"if",
"(",
"'container_class'",
"in",
"x",
")",
"{",
"container_config",
"[",
"'class'",
"]",
"=",
"x",
".",
"container_class",
";",
"}",
"}"
]
| Take raw control attributes, parse them, and store in `container_config`
@param {_cElementContainer} container_config
@param {_cRawX} x | [
"Take",
"raw",
"control",
"attributes",
"parse",
"them",
"and",
"store",
"in",
"container_config"
]
| fb8618821a51fad373106b5cc9247464b0a23cf6 | https://github.com/kogarashisan/LiquidLava/blob/fb8618821a51fad373106b5cc9247464b0a23cf6/lib/packages/parsers.js#L675-L733 |
|
47,043 | kogarashisan/LiquidLava | lib/packages/parsers.js | function(blocks, view_config) {
var current_block,
result = [],
type,
i = 0,
count = blocks.length,
x;
for (; i < count; i++) {
current_block = blocks[i];
type = (typeof(current_block) == 'string') ? 'string' : current_block.type;
if (type == 'tag') {
x = current_block.x;
if (x) {
if ('type' in x) {
if ('widget' in x) Lava.t("Malformed tag: both x:type and x:widget present");
type = x.type;
if (['view', 'container', 'static'].indexOf(type) == -1) Lava.t("Unknown x:type attribute: " + type);
} else if ('widget' in x) {
type = 'widget';
} else if (Lava.sugar_map[current_block.name]) {
type = 'sugar';
} else {
Lava.t("Tag with control attributes and no sugar or type on it: " + current_block.name);
}
} else if (Lava.sugar_map[current_block.name]) {
type = 'sugar';
} // else type = 'tag' - default
}
this[this._compile_handlers[type]](result, current_block, view_config);
}
return result;
} | javascript | function(blocks, view_config) {
var current_block,
result = [],
type,
i = 0,
count = blocks.length,
x;
for (; i < count; i++) {
current_block = blocks[i];
type = (typeof(current_block) == 'string') ? 'string' : current_block.type;
if (type == 'tag') {
x = current_block.x;
if (x) {
if ('type' in x) {
if ('widget' in x) Lava.t("Malformed tag: both x:type and x:widget present");
type = x.type;
if (['view', 'container', 'static'].indexOf(type) == -1) Lava.t("Unknown x:type attribute: " + type);
} else if ('widget' in x) {
type = 'widget';
} else if (Lava.sugar_map[current_block.name]) {
type = 'sugar';
} else {
Lava.t("Tag with control attributes and no sugar or type on it: " + current_block.name);
}
} else if (Lava.sugar_map[current_block.name]) {
type = 'sugar';
} // else type = 'tag' - default
}
this[this._compile_handlers[type]](result, current_block, view_config);
}
return result;
} | [
"function",
"(",
"blocks",
",",
"view_config",
")",
"{",
"var",
"current_block",
",",
"result",
"=",
"[",
"]",
",",
"type",
",",
"i",
"=",
"0",
",",
"count",
"=",
"blocks",
".",
"length",
",",
"x",
";",
"for",
"(",
";",
"i",
"<",
"count",
";",
"i",
"++",
")",
"{",
"current_block",
"=",
"blocks",
"[",
"i",
"]",
";",
"type",
"=",
"(",
"typeof",
"(",
"current_block",
")",
"==",
"'string'",
")",
"?",
"'string'",
":",
"current_block",
".",
"type",
";",
"if",
"(",
"type",
"==",
"'tag'",
")",
"{",
"x",
"=",
"current_block",
".",
"x",
";",
"if",
"(",
"x",
")",
"{",
"if",
"(",
"'type'",
"in",
"x",
")",
"{",
"if",
"(",
"'widget'",
"in",
"x",
")",
"Lava",
".",
"t",
"(",
"\"Malformed tag: both x:type and x:widget present\"",
")",
";",
"type",
"=",
"x",
".",
"type",
";",
"if",
"(",
"[",
"'view'",
",",
"'container'",
",",
"'static'",
"]",
".",
"indexOf",
"(",
"type",
")",
"==",
"-",
"1",
")",
"Lava",
".",
"t",
"(",
"\"Unknown x:type attribute: \"",
"+",
"type",
")",
";",
"}",
"else",
"if",
"(",
"'widget'",
"in",
"x",
")",
"{",
"type",
"=",
"'widget'",
";",
"}",
"else",
"if",
"(",
"Lava",
".",
"sugar_map",
"[",
"current_block",
".",
"name",
"]",
")",
"{",
"type",
"=",
"'sugar'",
";",
"}",
"else",
"{",
"Lava",
".",
"t",
"(",
"\"Tag with control attributes and no sugar or type on it: \"",
"+",
"current_block",
".",
"name",
")",
";",
"}",
"}",
"else",
"if",
"(",
"Lava",
".",
"sugar_map",
"[",
"current_block",
".",
"name",
"]",
")",
"{",
"type",
"=",
"'sugar'",
";",
"}",
"// else type = 'tag' - default",
"}",
"this",
"[",
"this",
".",
"_compile_handlers",
"[",
"type",
"]",
"]",
"(",
"result",
",",
"current_block",
",",
"view_config",
")",
";",
"}",
"return",
"result",
";",
"}"
]
| Compile raw template config
@param {_tRawTemplate} blocks
@param {_cView} [view_config]
@returns {_tTemplate} | [
"Compile",
"raw",
"template",
"config"
]
| fb8618821a51fad373106b5cc9247464b0a23cf6 | https://github.com/kogarashisan/LiquidLava/blob/fb8618821a51fad373106b5cc9247464b0a23cf6/lib/packages/parsers.js#L863-L917 |
|
47,044 | kogarashisan/LiquidLava | lib/packages/parsers.js | function(raw_blocks) {
var result = this.asBlocks(this.compileTemplate(raw_blocks));
if (result.length != 1) Lava.t("Expected: exactly one view, got either several or none.");
if (result[0].type != 'view' && result[0].type != 'widget') Lava.t("Expected: view, got: " + result[0].type);
return result[0];
} | javascript | function(raw_blocks) {
var result = this.asBlocks(this.compileTemplate(raw_blocks));
if (result.length != 1) Lava.t("Expected: exactly one view, got either several or none.");
if (result[0].type != 'view' && result[0].type != 'widget') Lava.t("Expected: view, got: " + result[0].type);
return result[0];
} | [
"function",
"(",
"raw_blocks",
")",
"{",
"var",
"result",
"=",
"this",
".",
"asBlocks",
"(",
"this",
".",
"compileTemplate",
"(",
"raw_blocks",
")",
")",
";",
"if",
"(",
"result",
".",
"length",
"!=",
"1",
")",
"Lava",
".",
"t",
"(",
"\"Expected: exactly one view, got either several or none.\"",
")",
";",
"if",
"(",
"result",
"[",
"0",
"]",
".",
"type",
"!=",
"'view'",
"&&",
"result",
"[",
"0",
"]",
".",
"type",
"!=",
"'widget'",
")",
"Lava",
".",
"t",
"(",
"\"Expected: view, got: \"",
"+",
"result",
"[",
"0",
"]",
".",
"type",
")",
";",
"return",
"result",
"[",
"0",
"]",
";",
"}"
]
| Compile template as usual and assert that it contains single view inside. Return that view
@param {_tRawTemplate} raw_blocks
@returns {_cView} | [
"Compile",
"template",
"as",
"usual",
"and",
"assert",
"that",
"it",
"contains",
"single",
"view",
"inside",
".",
"Return",
"that",
"view"
]
| fb8618821a51fad373106b5cc9247464b0a23cf6 | https://github.com/kogarashisan/LiquidLava/blob/fb8618821a51fad373106b5cc9247464b0a23cf6/lib/packages/parsers.js#L925-L932 |
|
47,045 | kogarashisan/LiquidLava | lib/packages/parsers.js | function(template) {
var i = 0,
count = template.length,
result = [];
for (; i < count; i++) {
if (typeof(template[i]) == 'string') {
if (!Lava.EMPTY_REGEX.test(template[i])) Lava.t("Text between tags is not allowed in this context. You may want to use a lava-style comment ({* ... *})");
} else {
result.push(template[i]);
}
}
return result;
} | javascript | function(template) {
var i = 0,
count = template.length,
result = [];
for (; i < count; i++) {
if (typeof(template[i]) == 'string') {
if (!Lava.EMPTY_REGEX.test(template[i])) Lava.t("Text between tags is not allowed in this context. You may want to use a lava-style comment ({* ... *})");
} else {
result.push(template[i]);
}
}
return result;
} | [
"function",
"(",
"template",
")",
"{",
"var",
"i",
"=",
"0",
",",
"count",
"=",
"template",
".",
"length",
",",
"result",
"=",
"[",
"]",
";",
"for",
"(",
";",
"i",
"<",
"count",
";",
"i",
"++",
")",
"{",
"if",
"(",
"typeof",
"(",
"template",
"[",
"i",
"]",
")",
"==",
"'string'",
")",
"{",
"if",
"(",
"!",
"Lava",
".",
"EMPTY_REGEX",
".",
"test",
"(",
"template",
"[",
"i",
"]",
")",
")",
"Lava",
".",
"t",
"(",
"\"Text between tags is not allowed in this context. You may want to use a lava-style comment ({* ... *})\"",
")",
";",
"}",
"else",
"{",
"result",
".",
"push",
"(",
"template",
"[",
"i",
"]",
")",
";",
"}",
"}",
"return",
"result",
";",
"}"
]
| Remove strings from template and assert they are empty
@param {(_tRawTemplate|_tTemplate)} template
@returns {Array} | [
"Remove",
"strings",
"from",
"template",
"and",
"assert",
"they",
"are",
"empty"
]
| fb8618821a51fad373106b5cc9247464b0a23cf6 | https://github.com/kogarashisan/LiquidLava/blob/fb8618821a51fad373106b5cc9247464b0a23cf6/lib/packages/parsers.js#L939-L961 |
|
47,046 | kogarashisan/LiquidLava | lib/packages/parsers.js | function() {
return {
type: 'widget',
"class": Lava.schema.widget.DEFAULT_EXTENSION_GATEWAY,
extender_type: Lava.schema.widget.DEFAULT_EXTENDER
}
} | javascript | function() {
return {
type: 'widget',
"class": Lava.schema.widget.DEFAULT_EXTENSION_GATEWAY,
extender_type: Lava.schema.widget.DEFAULT_EXTENDER
}
} | [
"function",
"(",
")",
"{",
"return",
"{",
"type",
":",
"'widget'",
",",
"\"class\"",
":",
"Lava",
".",
"schema",
".",
"widget",
".",
"DEFAULT_EXTENSION_GATEWAY",
",",
"extender_type",
":",
"Lava",
".",
"schema",
".",
"widget",
".",
"DEFAULT_EXTENDER",
"}",
"}"
]
| Create an empty widget config with default class and extender from schema
@returns {_cWidget} | [
"Create",
"an",
"empty",
"widget",
"config",
"with",
"default",
"class",
"and",
"extender",
"from",
"schema"
]
| fb8618821a51fad373106b5cc9247464b0a23cf6 | https://github.com/kogarashisan/LiquidLava/blob/fb8618821a51fad373106b5cc9247464b0a23cf6/lib/packages/parsers.js#L1150-L1158 |
|
47,047 | kogarashisan/LiquidLava | lib/packages/parsers.js | function(raw_string) {
var map = Firestorm.String.quote_escape_map,
result;
try {
result = eval("(" + raw_string.replace(this.UNQUOTE_ESCAPE_REGEX, function (a) {
var c = map[a];
return typeof c == 'string' ? c : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
}) + ")");
} catch (e) {
Lava.t("Malformed string: " + raw_string);
}
return result;
} | javascript | function(raw_string) {
var map = Firestorm.String.quote_escape_map,
result;
try {
result = eval("(" + raw_string.replace(this.UNQUOTE_ESCAPE_REGEX, function (a) {
var c = map[a];
return typeof c == 'string' ? c : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
}) + ")");
} catch (e) {
Lava.t("Malformed string: " + raw_string);
}
return result;
} | [
"function",
"(",
"raw_string",
")",
"{",
"var",
"map",
"=",
"Firestorm",
".",
"String",
".",
"quote_escape_map",
",",
"result",
";",
"try",
"{",
"result",
"=",
"eval",
"(",
"\"(\"",
"+",
"raw_string",
".",
"replace",
"(",
"this",
".",
"UNQUOTE_ESCAPE_REGEX",
",",
"function",
"(",
"a",
")",
"{",
"var",
"c",
"=",
"map",
"[",
"a",
"]",
";",
"return",
"typeof",
"c",
"==",
"'string'",
"?",
"c",
":",
"'\\\\u'",
"+",
"(",
"'0000'",
"+",
"a",
".",
"charCodeAt",
"(",
"0",
")",
".",
"toString",
"(",
"16",
")",
")",
".",
"slice",
"(",
"-",
"4",
")",
";",
"}",
")",
"+",
"\")\"",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"Lava",
".",
"t",
"(",
"\"Malformed string: \"",
"+",
"raw_string",
")",
";",
"}",
"return",
"result",
";",
"}"
]
| Turn a serialized and quoted string back into it's JavaScript representation.
Assume that everything that follows a backslash is a valid escape sequence
(all backslashes are prefixed with another backslash).
Quotes inside string: lexer's regex will match all escaped quotes
@param {string} raw_string
@returns {string} | [
"Turn",
"a",
"serialized",
"and",
"quoted",
"string",
"back",
"into",
"it",
"s",
"JavaScript",
"representation",
"."
]
| fb8618821a51fad373106b5cc9247464b0a23cf6 | https://github.com/kogarashisan/LiquidLava/blob/fb8618821a51fad373106b5cc9247464b0a23cf6/lib/packages/parsers.js#L1171-L1187 |
|
47,048 | kogarashisan/LiquidLava | lib/packages/parsers.js | function(raw_directive, view_config, is_top_directive) {
var directive_name = raw_directive.name,
config = this._directives_schema[directive_name];
if (!config) Lava.t("Unknown directive: " + directive_name);
if (config.view_config_presence) {
if (view_config && !config.view_config_presence) Lava.t('Directive must not be inside view definition: ' + directive_name);
if (!view_config && config.view_config_presence) Lava.t('Directive must be inside view definition: ' + directive_name);
}
if (config.is_top_directive && !is_top_directive) Lava.t("Directive must be at the top of the block content: " + directive_name);
return this['_x' + directive_name](raw_directive, view_config);
} | javascript | function(raw_directive, view_config, is_top_directive) {
var directive_name = raw_directive.name,
config = this._directives_schema[directive_name];
if (!config) Lava.t("Unknown directive: " + directive_name);
if (config.view_config_presence) {
if (view_config && !config.view_config_presence) Lava.t('Directive must not be inside view definition: ' + directive_name);
if (!view_config && config.view_config_presence) Lava.t('Directive must be inside view definition: ' + directive_name);
}
if (config.is_top_directive && !is_top_directive) Lava.t("Directive must be at the top of the block content: " + directive_name);
return this['_x' + directive_name](raw_directive, view_config);
} | [
"function",
"(",
"raw_directive",
",",
"view_config",
",",
"is_top_directive",
")",
"{",
"var",
"directive_name",
"=",
"raw_directive",
".",
"name",
",",
"config",
"=",
"this",
".",
"_directives_schema",
"[",
"directive_name",
"]",
";",
"if",
"(",
"!",
"config",
")",
"Lava",
".",
"t",
"(",
"\"Unknown directive: \"",
"+",
"directive_name",
")",
";",
"if",
"(",
"config",
".",
"view_config_presence",
")",
"{",
"if",
"(",
"view_config",
"&&",
"!",
"config",
".",
"view_config_presence",
")",
"Lava",
".",
"t",
"(",
"'Directive must not be inside view definition: '",
"+",
"directive_name",
")",
";",
"if",
"(",
"!",
"view_config",
"&&",
"config",
".",
"view_config_presence",
")",
"Lava",
".",
"t",
"(",
"'Directive must be inside view definition: '",
"+",
"directive_name",
")",
";",
"}",
"if",
"(",
"config",
".",
"is_top_directive",
"&&",
"!",
"is_top_directive",
")",
"Lava",
".",
"t",
"(",
"\"Directive must be at the top of the block content: \"",
"+",
"directive_name",
")",
";",
"return",
"this",
"[",
"'_x'",
"+",
"directive_name",
"]",
"(",
"raw_directive",
",",
"view_config",
")",
";",
"}"
]
| Handle directive tag
@param {_cRawDirective} raw_directive Raw directive tag
@param {(_cView|_cWidget)} view_config Config of the directive's parent view
@param {boolean} is_top_directive Code style validation switch. Some directives must be at the top of templates
@returns {*} Compiled template item or nothing | [
"Handle",
"directive",
"tag"
]
| fb8618821a51fad373106b5cc9247464b0a23cf6 | https://github.com/kogarashisan/LiquidLava/blob/fb8618821a51fad373106b5cc9247464b0a23cf6/lib/packages/parsers.js#L1295-L1311 |
|
47,049 | kogarashisan/LiquidLava | lib/packages/parsers.js | function(destination, source, name_list) {
for (var i = 0, count = name_list.length; i < count; i++) {
var name = name_list[i];
if (name in source) destination[name] = source[name];
}
} | javascript | function(destination, source, name_list) {
for (var i = 0, count = name_list.length; i < count; i++) {
var name = name_list[i];
if (name in source) destination[name] = source[name];
}
} | [
"function",
"(",
"destination",
",",
"source",
",",
"name_list",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"count",
"=",
"name_list",
".",
"length",
";",
"i",
"<",
"count",
";",
"i",
"++",
")",
"{",
"var",
"name",
"=",
"name_list",
"[",
"i",
"]",
";",
"if",
"(",
"name",
"in",
"source",
")",
"destination",
"[",
"name",
"]",
"=",
"source",
"[",
"name",
"]",
";",
"}",
"}"
]
| Helper method to copy properties from `source` to `destination`, if they exist
@param {Object} destination
@param {Object} source
@param {Array.<string>} name_list List of properties to copy from `source` to `destination` | [
"Helper",
"method",
"to",
"copy",
"properties",
"from",
"source",
"to",
"destination",
"if",
"they",
"exist"
]
| fb8618821a51fad373106b5cc9247464b0a23cf6 | https://github.com/kogarashisan/LiquidLava/blob/fb8618821a51fad373106b5cc9247464b0a23cf6/lib/packages/parsers.js#L1319-L1324 |
|
47,050 | kogarashisan/LiquidLava | lib/packages/parsers.js | function(raw_tag) {
if (Lava.schema.DEBUG && (!raw_tag.content || raw_tag.content.length != 1 || raw_tag.content[0] == '')) Lava.t("Malformed resources options tag");
return {
type: 'options',
value: Lava.parseOptions(raw_tag.content[0])
};
} | javascript | function(raw_tag) {
if (Lava.schema.DEBUG && (!raw_tag.content || raw_tag.content.length != 1 || raw_tag.content[0] == '')) Lava.t("Malformed resources options tag");
return {
type: 'options',
value: Lava.parseOptions(raw_tag.content[0])
};
} | [
"function",
"(",
"raw_tag",
")",
"{",
"if",
"(",
"Lava",
".",
"schema",
".",
"DEBUG",
"&&",
"(",
"!",
"raw_tag",
".",
"content",
"||",
"raw_tag",
".",
"content",
".",
"length",
"!=",
"1",
"||",
"raw_tag",
".",
"content",
"[",
"0",
"]",
"==",
"''",
")",
")",
"Lava",
".",
"t",
"(",
"\"Malformed resources options tag\"",
")",
";",
"return",
"{",
"type",
":",
"'options'",
",",
"value",
":",
"Lava",
".",
"parseOptions",
"(",
"raw_tag",
".",
"content",
"[",
"0",
"]",
")",
"}",
";",
"}"
]
| Parse resource value as any JavaScript type, including arrays, objects and literals
@param {_cRawTag} raw_tag | [
"Parse",
"resource",
"value",
"as",
"any",
"JavaScript",
"type",
"including",
"arrays",
"objects",
"and",
"literals"
]
| fb8618821a51fad373106b5cc9247464b0a23cf6 | https://github.com/kogarashisan/LiquidLava/blob/fb8618821a51fad373106b5cc9247464b0a23cf6/lib/packages/parsers.js#L1519-L1528 |
|
47,051 | kogarashisan/LiquidLava | lib/packages/parsers.js | function(raw_tag) {
if (Lava.schema.DEBUG && raw_tag.content && raw_tag.content.length != 1) Lava.t("Malformed resources string tag");
var result = {
type: 'string',
value: raw_tag.content ? raw_tag.content[0].trim() : ''
};
if (raw_tag.attributes.description) result.description = raw_tag.attributes.description;
return result;
} | javascript | function(raw_tag) {
if (Lava.schema.DEBUG && raw_tag.content && raw_tag.content.length != 1) Lava.t("Malformed resources string tag");
var result = {
type: 'string',
value: raw_tag.content ? raw_tag.content[0].trim() : ''
};
if (raw_tag.attributes.description) result.description = raw_tag.attributes.description;
return result;
} | [
"function",
"(",
"raw_tag",
")",
"{",
"if",
"(",
"Lava",
".",
"schema",
".",
"DEBUG",
"&&",
"raw_tag",
".",
"content",
"&&",
"raw_tag",
".",
"content",
".",
"length",
"!=",
"1",
")",
"Lava",
".",
"t",
"(",
"\"Malformed resources string tag\"",
")",
";",
"var",
"result",
"=",
"{",
"type",
":",
"'string'",
",",
"value",
":",
"raw_tag",
".",
"content",
"?",
"raw_tag",
".",
"content",
"[",
"0",
"]",
".",
"trim",
"(",
")",
":",
"''",
"}",
";",
"if",
"(",
"raw_tag",
".",
"attributes",
".",
"description",
")",
"result",
".",
"description",
"=",
"raw_tag",
".",
"attributes",
".",
"description",
";",
"return",
"result",
";",
"}"
]
| Parse a translatable string
@param {_cRawTag} raw_tag | [
"Parse",
"a",
"translatable",
"string"
]
| fb8618821a51fad373106b5cc9247464b0a23cf6 | https://github.com/kogarashisan/LiquidLava/blob/fb8618821a51fad373106b5cc9247464b0a23cf6/lib/packages/parsers.js#L1534-L1547 |
|
47,052 | kogarashisan/LiquidLava | lib/packages/parsers.js | function(raw_tag) {
if (Lava.schema.DEBUG && (!raw_tag.content)) Lava.t("Malformed resources plural string tag");
var plural_tags = Lava.parsers.Common.asBlockType(raw_tag.content, 'tag'),
i = 0,
count = plural_tags.length,
plurals = [],
result;
if (Lava.schema.DEBUG && count == 0) Lava.t("Malformed resources plural string definition");
for (; i < count; i++) {
if (Lava.schema.DEBUG && (plural_tags[i].name != 'string' || !plural_tags[i].content || !plural_tags[i].content[0])) Lava.t("Resources, malformed plural string");
plurals.push(plural_tags[i].content[0].trim());
}
result = {
type: 'plural_string',
value: plurals
};
if (raw_tag.attributes.description) result.description = raw_tag.attributes.description;
return result;
} | javascript | function(raw_tag) {
if (Lava.schema.DEBUG && (!raw_tag.content)) Lava.t("Malformed resources plural string tag");
var plural_tags = Lava.parsers.Common.asBlockType(raw_tag.content, 'tag'),
i = 0,
count = plural_tags.length,
plurals = [],
result;
if (Lava.schema.DEBUG && count == 0) Lava.t("Malformed resources plural string definition");
for (; i < count; i++) {
if (Lava.schema.DEBUG && (plural_tags[i].name != 'string' || !plural_tags[i].content || !plural_tags[i].content[0])) Lava.t("Resources, malformed plural string");
plurals.push(plural_tags[i].content[0].trim());
}
result = {
type: 'plural_string',
value: plurals
};
if (raw_tag.attributes.description) result.description = raw_tag.attributes.description;
return result;
} | [
"function",
"(",
"raw_tag",
")",
"{",
"if",
"(",
"Lava",
".",
"schema",
".",
"DEBUG",
"&&",
"(",
"!",
"raw_tag",
".",
"content",
")",
")",
"Lava",
".",
"t",
"(",
"\"Malformed resources plural string tag\"",
")",
";",
"var",
"plural_tags",
"=",
"Lava",
".",
"parsers",
".",
"Common",
".",
"asBlockType",
"(",
"raw_tag",
".",
"content",
",",
"'tag'",
")",
",",
"i",
"=",
"0",
",",
"count",
"=",
"plural_tags",
".",
"length",
",",
"plurals",
"=",
"[",
"]",
",",
"result",
";",
"if",
"(",
"Lava",
".",
"schema",
".",
"DEBUG",
"&&",
"count",
"==",
"0",
")",
"Lava",
".",
"t",
"(",
"\"Malformed resources plural string definition\"",
")",
";",
"for",
"(",
";",
"i",
"<",
"count",
";",
"i",
"++",
")",
"{",
"if",
"(",
"Lava",
".",
"schema",
".",
"DEBUG",
"&&",
"(",
"plural_tags",
"[",
"i",
"]",
".",
"name",
"!=",
"'string'",
"||",
"!",
"plural_tags",
"[",
"i",
"]",
".",
"content",
"||",
"!",
"plural_tags",
"[",
"i",
"]",
".",
"content",
"[",
"0",
"]",
")",
")",
"Lava",
".",
"t",
"(",
"\"Resources, malformed plural string\"",
")",
";",
"plurals",
".",
"push",
"(",
"plural_tags",
"[",
"i",
"]",
".",
"content",
"[",
"0",
"]",
".",
"trim",
"(",
")",
")",
";",
"}",
"result",
"=",
"{",
"type",
":",
"'plural_string'",
",",
"value",
":",
"plurals",
"}",
";",
"if",
"(",
"raw_tag",
".",
"attributes",
".",
"description",
")",
"result",
".",
"description",
"=",
"raw_tag",
".",
"attributes",
".",
"description",
";",
"return",
"result",
";",
"}"
]
| Parse translatable plural string
@param {_cRawTag} raw_tag | [
"Parse",
"translatable",
"plural",
"string"
]
| fb8618821a51fad373106b5cc9247464b0a23cf6 | https://github.com/kogarashisan/LiquidLava/blob/fb8618821a51fad373106b5cc9247464b0a23cf6/lib/packages/parsers.js#L1553-L1581 |
|
47,053 | kogarashisan/LiquidLava | lib/packages/parsers.js | function(raw_directive) {
if (Lava.schema.DEBUG) {
if (!raw_directive.attributes || !raw_directive.attributes.title) Lava.t("define: missing 'title' attribute");
if (raw_directive.attributes.title.indexOf(' ') != -1) Lava.t("Widget title must not contain spaces");
if ('resource_id' in raw_directive.attributes) Lava.t("resource_id is not allowed on define");
if (this._current_widget_title) Lava.t("Nested defines are not allowed: " + raw_directive.attributes.title);
}
this._current_widget_title = raw_directive.attributes.title;
var widget_config = this._parseWidgetDefinition(raw_directive);
this._current_widget_title = null;
widget_config.is_extended = false; // reserve it for serialization
if (Lava.schema.DEBUG && ('class_locator' in widget_config)) Lava.t("Dynamic class names are allowed only in inline widgets, not in x:define");
Lava.storeWidgetSchema(raw_directive.attributes.title, widget_config);
} | javascript | function(raw_directive) {
if (Lava.schema.DEBUG) {
if (!raw_directive.attributes || !raw_directive.attributes.title) Lava.t("define: missing 'title' attribute");
if (raw_directive.attributes.title.indexOf(' ') != -1) Lava.t("Widget title must not contain spaces");
if ('resource_id' in raw_directive.attributes) Lava.t("resource_id is not allowed on define");
if (this._current_widget_title) Lava.t("Nested defines are not allowed: " + raw_directive.attributes.title);
}
this._current_widget_title = raw_directive.attributes.title;
var widget_config = this._parseWidgetDefinition(raw_directive);
this._current_widget_title = null;
widget_config.is_extended = false; // reserve it for serialization
if (Lava.schema.DEBUG && ('class_locator' in widget_config)) Lava.t("Dynamic class names are allowed only in inline widgets, not in x:define");
Lava.storeWidgetSchema(raw_directive.attributes.title, widget_config);
} | [
"function",
"(",
"raw_directive",
")",
"{",
"if",
"(",
"Lava",
".",
"schema",
".",
"DEBUG",
")",
"{",
"if",
"(",
"!",
"raw_directive",
".",
"attributes",
"||",
"!",
"raw_directive",
".",
"attributes",
".",
"title",
")",
"Lava",
".",
"t",
"(",
"\"define: missing 'title' attribute\"",
")",
";",
"if",
"(",
"raw_directive",
".",
"attributes",
".",
"title",
".",
"indexOf",
"(",
"' '",
")",
"!=",
"-",
"1",
")",
"Lava",
".",
"t",
"(",
"\"Widget title must not contain spaces\"",
")",
";",
"if",
"(",
"'resource_id'",
"in",
"raw_directive",
".",
"attributes",
")",
"Lava",
".",
"t",
"(",
"\"resource_id is not allowed on define\"",
")",
";",
"if",
"(",
"this",
".",
"_current_widget_title",
")",
"Lava",
".",
"t",
"(",
"\"Nested defines are not allowed: \"",
"+",
"raw_directive",
".",
"attributes",
".",
"title",
")",
";",
"}",
"this",
".",
"_current_widget_title",
"=",
"raw_directive",
".",
"attributes",
".",
"title",
";",
"var",
"widget_config",
"=",
"this",
".",
"_parseWidgetDefinition",
"(",
"raw_directive",
")",
";",
"this",
".",
"_current_widget_title",
"=",
"null",
";",
"widget_config",
".",
"is_extended",
"=",
"false",
";",
"// reserve it for serialization",
"if",
"(",
"Lava",
".",
"schema",
".",
"DEBUG",
"&&",
"(",
"'class_locator'",
"in",
"widget_config",
")",
")",
"Lava",
".",
"t",
"(",
"\"Dynamic class names are allowed only in inline widgets, not in x:define\"",
")",
";",
"Lava",
".",
"storeWidgetSchema",
"(",
"raw_directive",
".",
"attributes",
".",
"title",
",",
"widget_config",
")",
";",
"}"
]
| Define a widget
@param {_cRawDirective} raw_directive | [
"Define",
"a",
"widget"
]
| fb8618821a51fad373106b5cc9247464b0a23cf6 | https://github.com/kogarashisan/LiquidLava/blob/fb8618821a51fad373106b5cc9247464b0a23cf6/lib/packages/parsers.js#L1788-L1806 |
|
47,054 | kogarashisan/LiquidLava | lib/packages/parsers.js | function(raw_directive) {
var widget_config = this._parseWidgetDefinition(raw_directive);
if (Lava.schema.DEBUG && ('sugar' in widget_config)) Lava.t("Inline widgets must not have sugar");
if (Lava.schema.DEBUG && !widget_config['class'] && !widget_config['extends']) Lava.t("x:define: widget definition is missing either 'controller' or 'extends' attribute");
if (raw_directive.attributes.resource_id) widget_config.resource_id = Lava.parsers.Common.parseResourceId(raw_directive.attributes.resource_id);
widget_config.type = 'widget';
return widget_config;
} | javascript | function(raw_directive) {
var widget_config = this._parseWidgetDefinition(raw_directive);
if (Lava.schema.DEBUG && ('sugar' in widget_config)) Lava.t("Inline widgets must not have sugar");
if (Lava.schema.DEBUG && !widget_config['class'] && !widget_config['extends']) Lava.t("x:define: widget definition is missing either 'controller' or 'extends' attribute");
if (raw_directive.attributes.resource_id) widget_config.resource_id = Lava.parsers.Common.parseResourceId(raw_directive.attributes.resource_id);
widget_config.type = 'widget';
return widget_config;
} | [
"function",
"(",
"raw_directive",
")",
"{",
"var",
"widget_config",
"=",
"this",
".",
"_parseWidgetDefinition",
"(",
"raw_directive",
")",
";",
"if",
"(",
"Lava",
".",
"schema",
".",
"DEBUG",
"&&",
"(",
"'sugar'",
"in",
"widget_config",
")",
")",
"Lava",
".",
"t",
"(",
"\"Inline widgets must not have sugar\"",
")",
";",
"if",
"(",
"Lava",
".",
"schema",
".",
"DEBUG",
"&&",
"!",
"widget_config",
"[",
"'class'",
"]",
"&&",
"!",
"widget_config",
"[",
"'extends'",
"]",
")",
"Lava",
".",
"t",
"(",
"\"x:define: widget definition is missing either 'controller' or 'extends' attribute\"",
")",
";",
"if",
"(",
"raw_directive",
".",
"attributes",
".",
"resource_id",
")",
"widget_config",
".",
"resource_id",
"=",
"Lava",
".",
"parsers",
".",
"Common",
".",
"parseResourceId",
"(",
"raw_directive",
".",
"attributes",
".",
"resource_id",
")",
";",
"widget_config",
".",
"type",
"=",
"'widget'",
";",
"return",
"widget_config",
";",
"}"
]
| Inline widget definition
@param {_cRawDirective} raw_directive | [
"Inline",
"widget",
"definition"
]
| fb8618821a51fad373106b5cc9247464b0a23cf6 | https://github.com/kogarashisan/LiquidLava/blob/fb8618821a51fad373106b5cc9247464b0a23cf6/lib/packages/parsers.js#L1812-L1823 |
|
47,055 | kogarashisan/LiquidLava | lib/packages/parsers.js | function(config, raw_tag, config_property_name) {
if (Lava.schema.DEBUG && !('attributes' in raw_tag)) Lava.t("option: missing attributes");
if (Lava.schema.DEBUG && (!raw_tag.content || raw_tag.content.length != 1)) Lava.t("Malformed option: " + raw_tag.attributes.name);
var option_type = raw_tag.attributes.type,
result;
if (option_type) {
if (option_type == 'targets') {
result = Lava.parsers.Common.parseTargets(raw_tag.content[0]);
} else if (option_type == 'expressions') {
result = Lava.ExpressionParser.parse(raw_tag.content[0], Lava.ExpressionParser.SEPARATORS.SEMICOLON);
} else {
Lava.t("Unknown option type: " + option_type);
}
} else {
result = Lava.parseOptions(raw_tag.content[0]);
}
Lava.store(config, config_property_name, raw_tag.attributes.name, result);
} | javascript | function(config, raw_tag, config_property_name) {
if (Lava.schema.DEBUG && !('attributes' in raw_tag)) Lava.t("option: missing attributes");
if (Lava.schema.DEBUG && (!raw_tag.content || raw_tag.content.length != 1)) Lava.t("Malformed option: " + raw_tag.attributes.name);
var option_type = raw_tag.attributes.type,
result;
if (option_type) {
if (option_type == 'targets') {
result = Lava.parsers.Common.parseTargets(raw_tag.content[0]);
} else if (option_type == 'expressions') {
result = Lava.ExpressionParser.parse(raw_tag.content[0], Lava.ExpressionParser.SEPARATORS.SEMICOLON);
} else {
Lava.t("Unknown option type: " + option_type);
}
} else {
result = Lava.parseOptions(raw_tag.content[0]);
}
Lava.store(config, config_property_name, raw_tag.attributes.name, result);
} | [
"function",
"(",
"config",
",",
"raw_tag",
",",
"config_property_name",
")",
"{",
"if",
"(",
"Lava",
".",
"schema",
".",
"DEBUG",
"&&",
"!",
"(",
"'attributes'",
"in",
"raw_tag",
")",
")",
"Lava",
".",
"t",
"(",
"\"option: missing attributes\"",
")",
";",
"if",
"(",
"Lava",
".",
"schema",
".",
"DEBUG",
"&&",
"(",
"!",
"raw_tag",
".",
"content",
"||",
"raw_tag",
".",
"content",
".",
"length",
"!=",
"1",
")",
")",
"Lava",
".",
"t",
"(",
"\"Malformed option: \"",
"+",
"raw_tag",
".",
"attributes",
".",
"name",
")",
";",
"var",
"option_type",
"=",
"raw_tag",
".",
"attributes",
".",
"type",
",",
"result",
";",
"if",
"(",
"option_type",
")",
"{",
"if",
"(",
"option_type",
"==",
"'targets'",
")",
"{",
"result",
"=",
"Lava",
".",
"parsers",
".",
"Common",
".",
"parseTargets",
"(",
"raw_tag",
".",
"content",
"[",
"0",
"]",
")",
";",
"}",
"else",
"if",
"(",
"option_type",
"==",
"'expressions'",
")",
"{",
"result",
"=",
"Lava",
".",
"ExpressionParser",
".",
"parse",
"(",
"raw_tag",
".",
"content",
"[",
"0",
"]",
",",
"Lava",
".",
"ExpressionParser",
".",
"SEPARATORS",
".",
"SEMICOLON",
")",
";",
"}",
"else",
"{",
"Lava",
".",
"t",
"(",
"\"Unknown option type: \"",
"+",
"option_type",
")",
";",
"}",
"}",
"else",
"{",
"result",
"=",
"Lava",
".",
"parseOptions",
"(",
"raw_tag",
".",
"content",
"[",
"0",
"]",
")",
";",
"}",
"Lava",
".",
"store",
"(",
"config",
",",
"config_property_name",
",",
"raw_tag",
".",
"attributes",
".",
"name",
",",
"result",
")",
";",
"}"
]
| Perform parsing of a tag with serialized JavaScript object inside it
@param {(_cView|_cWidget)} config
@param {(_cRawDirective|_cRawTag)} raw_tag
@param {string} config_property_name Name of the config member, which holds target JavaScript object | [
"Perform",
"parsing",
"of",
"a",
"tag",
"with",
"serialized",
"JavaScript",
"object",
"inside",
"it"
]
| fb8618821a51fad373106b5cc9247464b0a23cf6 | https://github.com/kogarashisan/LiquidLava/blob/fb8618821a51fad373106b5cc9247464b0a23cf6/lib/packages/parsers.js#L1879-L1911 |
|
47,056 | kogarashisan/LiquidLava | lib/packages/parsers.js | function(config, name, raw_tag) {
if (Lava.schema.DEBUG && (name in config)) Lava.t("Object already exists: " + name + ". Ensure, that x:options and x:properties directives appear before x:option and x:property.");
if (Lava.schema.DEBUG && (!raw_tag.content || raw_tag.content.length != 1)) Lava.t("Malformed directive or tag for config property: " + name);
config[name] = Lava.parseOptions(raw_tag.content[0]);
} | javascript | function(config, name, raw_tag) {
if (Lava.schema.DEBUG && (name in config)) Lava.t("Object already exists: " + name + ". Ensure, that x:options and x:properties directives appear before x:option and x:property.");
if (Lava.schema.DEBUG && (!raw_tag.content || raw_tag.content.length != 1)) Lava.t("Malformed directive or tag for config property: " + name);
config[name] = Lava.parseOptions(raw_tag.content[0]);
} | [
"function",
"(",
"config",
",",
"name",
",",
"raw_tag",
")",
"{",
"if",
"(",
"Lava",
".",
"schema",
".",
"DEBUG",
"&&",
"(",
"name",
"in",
"config",
")",
")",
"Lava",
".",
"t",
"(",
"\"Object already exists: \"",
"+",
"name",
"+",
"\". Ensure, that x:options and x:properties directives appear before x:option and x:property.\"",
")",
";",
"if",
"(",
"Lava",
".",
"schema",
".",
"DEBUG",
"&&",
"(",
"!",
"raw_tag",
".",
"content",
"||",
"raw_tag",
".",
"content",
".",
"length",
"!=",
"1",
")",
")",
"Lava",
".",
"t",
"(",
"\"Malformed directive or tag for config property: \"",
"+",
"name",
")",
";",
"config",
"[",
"name",
"]",
"=",
"Lava",
".",
"parseOptions",
"(",
"raw_tag",
".",
"content",
"[",
"0",
"]",
")",
";",
"}"
]
| Parse a tag with JavaScript object inside
@param {(_cView|_cWidget)} config
@param {string} name
@param {(_cRawDirective|_cRawTag)} raw_tag | [
"Parse",
"a",
"tag",
"with",
"JavaScript",
"object",
"inside"
]
| fb8618821a51fad373106b5cc9247464b0a23cf6 | https://github.com/kogarashisan/LiquidLava/blob/fb8618821a51fad373106b5cc9247464b0a23cf6/lib/packages/parsers.js#L2032-L2038 |
|
47,057 | kogarashisan/LiquidLava | lib/packages/parsers.js | function(widget_config, raw_directive, config_property_name) {
if (Lava.schema.DEBUG && !('attributes' in raw_directive)) Lava.t("option: missing attributes");
if (Lava.schema.DEBUG && (!raw_directive.content || raw_directive.content.length != 1)) Lava.t("Malformed property: " + raw_directive.attributes.name);
Lava.store(widget_config, config_property_name, raw_directive.attributes.name, raw_directive.content[0]);
} | javascript | function(widget_config, raw_directive, config_property_name) {
if (Lava.schema.DEBUG && !('attributes' in raw_directive)) Lava.t("option: missing attributes");
if (Lava.schema.DEBUG && (!raw_directive.content || raw_directive.content.length != 1)) Lava.t("Malformed property: " + raw_directive.attributes.name);
Lava.store(widget_config, config_property_name, raw_directive.attributes.name, raw_directive.content[0]);
} | [
"function",
"(",
"widget_config",
",",
"raw_directive",
",",
"config_property_name",
")",
"{",
"if",
"(",
"Lava",
".",
"schema",
".",
"DEBUG",
"&&",
"!",
"(",
"'attributes'",
"in",
"raw_directive",
")",
")",
"Lava",
".",
"t",
"(",
"\"option: missing attributes\"",
")",
";",
"if",
"(",
"Lava",
".",
"schema",
".",
"DEBUG",
"&&",
"(",
"!",
"raw_directive",
".",
"content",
"||",
"raw_directive",
".",
"content",
".",
"length",
"!=",
"1",
")",
")",
"Lava",
".",
"t",
"(",
"\"Malformed property: \"",
"+",
"raw_directive",
".",
"attributes",
".",
"name",
")",
";",
"Lava",
".",
"store",
"(",
"widget_config",
",",
"config_property_name",
",",
"raw_directive",
".",
"attributes",
".",
"name",
",",
"raw_directive",
".",
"content",
"[",
"0",
"]",
")",
";",
"}"
]
| Helper method for widget directives
@param {_cWidget} widget_config
@param {_cRawDirective} raw_directive
@param {string} config_property_name | [
"Helper",
"method",
"for",
"widget",
"directives"
]
| fb8618821a51fad373106b5cc9247464b0a23cf6 | https://github.com/kogarashisan/LiquidLava/blob/fb8618821a51fad373106b5cc9247464b0a23cf6/lib/packages/parsers.js#L2083-L2089 |
|
47,058 | kogarashisan/LiquidLava | lib/packages/parsers.js | function(raw_directive) {
if (Lava.schema.DEBUG && (!raw_directive.attributes || !raw_directive.attributes['locale'] || !raw_directive.attributes['for']))
Lava.t("Malformed x:resources definition. 'locale' and 'for' are required");
Lava.resources.addWidgetResource(
raw_directive.attributes['for'],
raw_directive.attributes['locale'],
this._parseResources(raw_directive, raw_directive.attributes['for'])
);
} | javascript | function(raw_directive) {
if (Lava.schema.DEBUG && (!raw_directive.attributes || !raw_directive.attributes['locale'] || !raw_directive.attributes['for']))
Lava.t("Malformed x:resources definition. 'locale' and 'for' are required");
Lava.resources.addWidgetResource(
raw_directive.attributes['for'],
raw_directive.attributes['locale'],
this._parseResources(raw_directive, raw_directive.attributes['for'])
);
} | [
"function",
"(",
"raw_directive",
")",
"{",
"if",
"(",
"Lava",
".",
"schema",
".",
"DEBUG",
"&&",
"(",
"!",
"raw_directive",
".",
"attributes",
"||",
"!",
"raw_directive",
".",
"attributes",
"[",
"'locale'",
"]",
"||",
"!",
"raw_directive",
".",
"attributes",
"[",
"'for'",
"]",
")",
")",
"Lava",
".",
"t",
"(",
"\"Malformed x:resources definition. 'locale' and 'for' are required\"",
")",
";",
"Lava",
".",
"resources",
".",
"addWidgetResource",
"(",
"raw_directive",
".",
"attributes",
"[",
"'for'",
"]",
",",
"raw_directive",
".",
"attributes",
"[",
"'locale'",
"]",
",",
"this",
".",
"_parseResources",
"(",
"raw_directive",
",",
"raw_directive",
".",
"attributes",
"[",
"'for'",
"]",
")",
")",
";",
"}"
]
| Standalone resources definition for global widget
@param {_cRawDirective} raw_directive | [
"Standalone",
"resources",
"definition",
"for",
"global",
"widget"
]
| fb8618821a51fad373106b5cc9247464b0a23cf6 | https://github.com/kogarashisan/LiquidLava/blob/fb8618821a51fad373106b5cc9247464b0a23cf6/lib/packages/parsers.js#L2119-L2130 |
|
47,059 | kogarashisan/LiquidLava | lib/packages/parsers.js | function(raw_directive) {
if (Lava.schema.DEBUG && !raw_directive.content) Lava.t("empty attach_directives");
var blocks = Lava.parsers.Common.asBlocks(raw_directive.content),
sugar = blocks[0],
directives = blocks.slice(1),
i,
count;
if (Lava.schema.DEBUG) {
if (sugar.type != 'tag' || sugar.content || directives.length == 0) Lava.t("Malformed attach_directives");
for (i = 0, count = directives.length; i < count; i++) {
if (directives[i].type != 'directive') Lava.t("Malformed attach_directives");
}
}
sugar.content = directives;
return Lava.parsers.Common.compileAsView([sugar]);
} | javascript | function(raw_directive) {
if (Lava.schema.DEBUG && !raw_directive.content) Lava.t("empty attach_directives");
var blocks = Lava.parsers.Common.asBlocks(raw_directive.content),
sugar = blocks[0],
directives = blocks.slice(1),
i,
count;
if (Lava.schema.DEBUG) {
if (sugar.type != 'tag' || sugar.content || directives.length == 0) Lava.t("Malformed attach_directives");
for (i = 0, count = directives.length; i < count; i++) {
if (directives[i].type != 'directive') Lava.t("Malformed attach_directives");
}
}
sugar.content = directives;
return Lava.parsers.Common.compileAsView([sugar]);
} | [
"function",
"(",
"raw_directive",
")",
"{",
"if",
"(",
"Lava",
".",
"schema",
".",
"DEBUG",
"&&",
"!",
"raw_directive",
".",
"content",
")",
"Lava",
".",
"t",
"(",
"\"empty attach_directives\"",
")",
";",
"var",
"blocks",
"=",
"Lava",
".",
"parsers",
".",
"Common",
".",
"asBlocks",
"(",
"raw_directive",
".",
"content",
")",
",",
"sugar",
"=",
"blocks",
"[",
"0",
"]",
",",
"directives",
"=",
"blocks",
".",
"slice",
"(",
"1",
")",
",",
"i",
",",
"count",
";",
"if",
"(",
"Lava",
".",
"schema",
".",
"DEBUG",
")",
"{",
"if",
"(",
"sugar",
".",
"type",
"!=",
"'tag'",
"||",
"sugar",
".",
"content",
"||",
"directives",
".",
"length",
"==",
"0",
")",
"Lava",
".",
"t",
"(",
"\"Malformed attach_directives\"",
")",
";",
"for",
"(",
"i",
"=",
"0",
",",
"count",
"=",
"directives",
".",
"length",
";",
"i",
"<",
"count",
";",
"i",
"++",
")",
"{",
"if",
"(",
"directives",
"[",
"i",
"]",
".",
"type",
"!=",
"'directive'",
")",
"Lava",
".",
"t",
"(",
"\"Malformed attach_directives\"",
")",
";",
"}",
"}",
"sugar",
".",
"content",
"=",
"directives",
";",
"return",
"Lava",
".",
"parsers",
".",
"Common",
".",
"compileAsView",
"(",
"[",
"sugar",
"]",
")",
";",
"}"
]
| Wrapper, used to apply directives to a void tag
@param {_cRawDirective} raw_directive | [
"Wrapper",
"used",
"to",
"apply",
"directives",
"to",
"a",
"void",
"tag"
]
| fb8618821a51fad373106b5cc9247464b0a23cf6 | https://github.com/kogarashisan/LiquidLava/blob/fb8618821a51fad373106b5cc9247464b0a23cf6/lib/packages/parsers.js#L2195-L2215 |
|
47,060 | kogarashisan/LiquidLava | lib/packages/parsers.js | function(widget_config, raw_template) {
var storage_schema = this.getMergedStorageSchema(widget_config),
tags = Lava.parsers.Common.asBlockType(raw_template, 'tag'),
i = 0,
count = tags.length,
item_schema;
for (; i < count; i++) {
item_schema = storage_schema[tags[i].name];
if (Lava.schema.DEBUG && !item_schema) Lava.t('parsing storage; no schema for ' + tags[i].name);
Lava.store(widget_config, 'storage', tags[i].name, this[this._root_handlers[item_schema.type]](item_schema, tags[i]));
}
} | javascript | function(widget_config, raw_template) {
var storage_schema = this.getMergedStorageSchema(widget_config),
tags = Lava.parsers.Common.asBlockType(raw_template, 'tag'),
i = 0,
count = tags.length,
item_schema;
for (; i < count; i++) {
item_schema = storage_schema[tags[i].name];
if (Lava.schema.DEBUG && !item_schema) Lava.t('parsing storage; no schema for ' + tags[i].name);
Lava.store(widget_config, 'storage', tags[i].name, this[this._root_handlers[item_schema.type]](item_schema, tags[i]));
}
} | [
"function",
"(",
"widget_config",
",",
"raw_template",
")",
"{",
"var",
"storage_schema",
"=",
"this",
".",
"getMergedStorageSchema",
"(",
"widget_config",
")",
",",
"tags",
"=",
"Lava",
".",
"parsers",
".",
"Common",
".",
"asBlockType",
"(",
"raw_template",
",",
"'tag'",
")",
",",
"i",
"=",
"0",
",",
"count",
"=",
"tags",
".",
"length",
",",
"item_schema",
";",
"for",
"(",
";",
"i",
"<",
"count",
";",
"i",
"++",
")",
"{",
"item_schema",
"=",
"storage_schema",
"[",
"tags",
"[",
"i",
"]",
".",
"name",
"]",
";",
"if",
"(",
"Lava",
".",
"schema",
".",
"DEBUG",
"&&",
"!",
"item_schema",
")",
"Lava",
".",
"t",
"(",
"'parsing storage; no schema for '",
"+",
"tags",
"[",
"i",
"]",
".",
"name",
")",
";",
"Lava",
".",
"store",
"(",
"widget_config",
",",
"'storage'",
",",
"tags",
"[",
"i",
"]",
".",
"name",
",",
"this",
"[",
"this",
".",
"_root_handlers",
"[",
"item_schema",
".",
"type",
"]",
"]",
"(",
"item_schema",
",",
"tags",
"[",
"i",
"]",
")",
")",
";",
"}",
"}"
]
| Parse raw tags as widget's storage
@param {_cWidget} widget_config
@param {_tRawTemplate} raw_template | [
"Parse",
"raw",
"tags",
"as",
"widget",
"s",
"storage"
]
| fb8618821a51fad373106b5cc9247464b0a23cf6 | https://github.com/kogarashisan/LiquidLava/blob/fb8618821a51fad373106b5cc9247464b0a23cf6/lib/packages/parsers.js#L2293-L2309 |
|
47,061 | kogarashisan/LiquidLava | lib/packages/parsers.js | function(schema, raw_tag, exclude_name) {
var tags = Lava.parsers.Common.asBlockType(raw_tag.content, 'tag'),
i = 0,
count = tags.length,
result = {},
descriptor,
name;
for (; i < count; i++) {
descriptor = schema.properties[tags[i].name];
if (Lava.schema.DEBUG && !descriptor) Lava.t("Unknown tag in object: " + tags[i].name);
if (Lava.schema.DEBUG && (tags[i].name in result)) Lava.t('[Storage] duplicate item in object: ' + tags[i].name);
result[tags[i].name] = this[this._object_property_handlers[descriptor.type]](descriptor, tags[i]);
}
for (name in raw_tag.attributes) {
if (exclude_name && name == 'name') continue;
descriptor = schema.properties[name];
if (Lava.schema.DEBUG && (!descriptor || !descriptor.is_attribute)) Lava.t("Unknown attribute in object: " + name);
if (Lava.schema.DEBUG && (name in result)) Lava.t('[Storage] duplicate item (attribute) in object: ' + name);
result[name] = this[this._object_attributes_handlers[descriptor.type]](descriptor, raw_tag.attributes[name]);
}
return result;
} | javascript | function(schema, raw_tag, exclude_name) {
var tags = Lava.parsers.Common.asBlockType(raw_tag.content, 'tag'),
i = 0,
count = tags.length,
result = {},
descriptor,
name;
for (; i < count; i++) {
descriptor = schema.properties[tags[i].name];
if (Lava.schema.DEBUG && !descriptor) Lava.t("Unknown tag in object: " + tags[i].name);
if (Lava.schema.DEBUG && (tags[i].name in result)) Lava.t('[Storage] duplicate item in object: ' + tags[i].name);
result[tags[i].name] = this[this._object_property_handlers[descriptor.type]](descriptor, tags[i]);
}
for (name in raw_tag.attributes) {
if (exclude_name && name == 'name') continue;
descriptor = schema.properties[name];
if (Lava.schema.DEBUG && (!descriptor || !descriptor.is_attribute)) Lava.t("Unknown attribute in object: " + name);
if (Lava.schema.DEBUG && (name in result)) Lava.t('[Storage] duplicate item (attribute) in object: ' + name);
result[name] = this[this._object_attributes_handlers[descriptor.type]](descriptor, raw_tag.attributes[name]);
}
return result;
} | [
"function",
"(",
"schema",
",",
"raw_tag",
",",
"exclude_name",
")",
"{",
"var",
"tags",
"=",
"Lava",
".",
"parsers",
".",
"Common",
".",
"asBlockType",
"(",
"raw_tag",
".",
"content",
",",
"'tag'",
")",
",",
"i",
"=",
"0",
",",
"count",
"=",
"tags",
".",
"length",
",",
"result",
"=",
"{",
"}",
",",
"descriptor",
",",
"name",
";",
"for",
"(",
";",
"i",
"<",
"count",
";",
"i",
"++",
")",
"{",
"descriptor",
"=",
"schema",
".",
"properties",
"[",
"tags",
"[",
"i",
"]",
".",
"name",
"]",
";",
"if",
"(",
"Lava",
".",
"schema",
".",
"DEBUG",
"&&",
"!",
"descriptor",
")",
"Lava",
".",
"t",
"(",
"\"Unknown tag in object: \"",
"+",
"tags",
"[",
"i",
"]",
".",
"name",
")",
";",
"if",
"(",
"Lava",
".",
"schema",
".",
"DEBUG",
"&&",
"(",
"tags",
"[",
"i",
"]",
".",
"name",
"in",
"result",
")",
")",
"Lava",
".",
"t",
"(",
"'[Storage] duplicate item in object: '",
"+",
"tags",
"[",
"i",
"]",
".",
"name",
")",
";",
"result",
"[",
"tags",
"[",
"i",
"]",
".",
"name",
"]",
"=",
"this",
"[",
"this",
".",
"_object_property_handlers",
"[",
"descriptor",
".",
"type",
"]",
"]",
"(",
"descriptor",
",",
"tags",
"[",
"i",
"]",
")",
";",
"}",
"for",
"(",
"name",
"in",
"raw_tag",
".",
"attributes",
")",
"{",
"if",
"(",
"exclude_name",
"&&",
"name",
"==",
"'name'",
")",
"continue",
";",
"descriptor",
"=",
"schema",
".",
"properties",
"[",
"name",
"]",
";",
"if",
"(",
"Lava",
".",
"schema",
".",
"DEBUG",
"&&",
"(",
"!",
"descriptor",
"||",
"!",
"descriptor",
".",
"is_attribute",
")",
")",
"Lava",
".",
"t",
"(",
"\"Unknown attribute in object: \"",
"+",
"name",
")",
";",
"if",
"(",
"Lava",
".",
"schema",
".",
"DEBUG",
"&&",
"(",
"name",
"in",
"result",
")",
")",
"Lava",
".",
"t",
"(",
"'[Storage] duplicate item (attribute) in object: '",
"+",
"name",
")",
";",
"result",
"[",
"name",
"]",
"=",
"this",
"[",
"this",
".",
"_object_attributes_handlers",
"[",
"descriptor",
".",
"type",
"]",
"]",
"(",
"descriptor",
",",
"raw_tag",
".",
"attributes",
"[",
"name",
"]",
")",
";",
"}",
"return",
"result",
";",
"}"
]
| Convert `raw_rag` into object with given `schema`
@param {_cStorageItemSchema} schema
@param {_cRawTag} raw_tag
@param {boolean} exclude_name
@returns {Object} | [
"Convert",
"raw_rag",
"into",
"object",
"with",
"given",
"schema"
]
| fb8618821a51fad373106b5cc9247464b0a23cf6 | https://github.com/kogarashisan/LiquidLava/blob/fb8618821a51fad373106b5cc9247464b0a23cf6/lib/packages/parsers.js#L2387-L2417 |
|
47,062 | jonwoodring/octal-number-loader | index.js | function(s) {
var r = '';
for (var i = s.length - 1; i >= 0; i--) {
r += s[i];
}
return r;
} | javascript | function(s) {
var r = '';
for (var i = s.length - 1; i >= 0; i--) {
r += s[i];
}
return r;
} | [
"function",
"(",
"s",
")",
"{",
"var",
"r",
"=",
"''",
";",
"for",
"(",
"var",
"i",
"=",
"s",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"r",
"+=",
"s",
"[",
"i",
"]",
";",
"}",
"return",
"r",
";",
"}"
]
| javascript doesn't have negative lookbehind so we have to reverse the string | [
"javascript",
"doesn",
"t",
"have",
"negative",
"lookbehind",
"so",
"we",
"have",
"to",
"reverse",
"the",
"string"
]
| 5b49b9ab8b116bbf9c1f0e36dd85c28ef8318c21 | https://github.com/jonwoodring/octal-number-loader/blob/5b49b9ab8b116bbf9c1f0e36dd85c28ef8318c21/index.js#L9-L15 |
|
47,063 | shama/grunt-required | tasks/required.js | npmInstall | function npmInstall(requires, done) {
var npmBin = path.join(path.dirname(process.argv[0]), 'npm');
if (process.platform === 'win32') { npmBin += '.cmd'; }
async.forEachSeries(requires, function(module, next) {
// skip existing modules
if (grunt.file.exists(path.join('./node_modules/' + module))) {
grunt.log.writeln(String('Module "' + module + '" already installed, skipping.').cyan);
return next();
}
grunt.log.writeln('npm install ' + module + ' --save');
// spawn npm install
var s = grunt.util.spawn({
cmd: npmBin,
args: ['install', module, '--save']
}, next);
// write output
s.stdout.on('data', function(buf) { grunt.log.write(String(buf)); });
s.stderr.on('data', function(buf) { grunt.log.write(String(buf)); });
}, done);
} | javascript | function npmInstall(requires, done) {
var npmBin = path.join(path.dirname(process.argv[0]), 'npm');
if (process.platform === 'win32') { npmBin += '.cmd'; }
async.forEachSeries(requires, function(module, next) {
// skip existing modules
if (grunt.file.exists(path.join('./node_modules/' + module))) {
grunt.log.writeln(String('Module "' + module + '" already installed, skipping.').cyan);
return next();
}
grunt.log.writeln('npm install ' + module + ' --save');
// spawn npm install
var s = grunt.util.spawn({
cmd: npmBin,
args: ['install', module, '--save']
}, next);
// write output
s.stdout.on('data', function(buf) { grunt.log.write(String(buf)); });
s.stderr.on('data', function(buf) { grunt.log.write(String(buf)); });
}, done);
} | [
"function",
"npmInstall",
"(",
"requires",
",",
"done",
")",
"{",
"var",
"npmBin",
"=",
"path",
".",
"join",
"(",
"path",
".",
"dirname",
"(",
"process",
".",
"argv",
"[",
"0",
"]",
")",
",",
"'npm'",
")",
";",
"if",
"(",
"process",
".",
"platform",
"===",
"'win32'",
")",
"{",
"npmBin",
"+=",
"'.cmd'",
";",
"}",
"async",
".",
"forEachSeries",
"(",
"requires",
",",
"function",
"(",
"module",
",",
"next",
")",
"{",
"// skip existing modules",
"if",
"(",
"grunt",
".",
"file",
".",
"exists",
"(",
"path",
".",
"join",
"(",
"'./node_modules/'",
"+",
"module",
")",
")",
")",
"{",
"grunt",
".",
"log",
".",
"writeln",
"(",
"String",
"(",
"'Module \"'",
"+",
"module",
"+",
"'\" already installed, skipping.'",
")",
".",
"cyan",
")",
";",
"return",
"next",
"(",
")",
";",
"}",
"grunt",
".",
"log",
".",
"writeln",
"(",
"'npm install '",
"+",
"module",
"+",
"' --save'",
")",
";",
"// spawn npm install",
"var",
"s",
"=",
"grunt",
".",
"util",
".",
"spawn",
"(",
"{",
"cmd",
":",
"npmBin",
",",
"args",
":",
"[",
"'install'",
",",
"module",
",",
"'--save'",
"]",
"}",
",",
"next",
")",
";",
"// write output",
"s",
".",
"stdout",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"buf",
")",
"{",
"grunt",
".",
"log",
".",
"write",
"(",
"String",
"(",
"buf",
")",
")",
";",
"}",
")",
";",
"s",
".",
"stderr",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"buf",
")",
"{",
"grunt",
".",
"log",
".",
"write",
"(",
"String",
"(",
"buf",
")",
")",
";",
"}",
")",
";",
"}",
",",
"done",
")",
";",
"}"
]
| use npm to install given modules | [
"use",
"npm",
"to",
"install",
"given",
"modules"
]
| 367f1e7517592fedf1a0612f44e41c05437bfcbe | https://github.com/shama/grunt-required/blob/367f1e7517592fedf1a0612f44e41c05437bfcbe/tasks/required.js#L17-L36 |
47,064 | bvalosek/sticky | util/camelize.js | camelize | function camelize()
{
return function(input, output)
{
var target = output || input;
var f = output ? remove : add;
for (var key in target) {
var value = target[key];
var key_ = f(key);
if (key_ === key) continue;
delete target[key];
target[key_] = value;
}
};
} | javascript | function camelize()
{
return function(input, output)
{
var target = output || input;
var f = output ? remove : add;
for (var key in target) {
var value = target[key];
var key_ = f(key);
if (key_ === key) continue;
delete target[key];
target[key_] = value;
}
};
} | [
"function",
"camelize",
"(",
")",
"{",
"return",
"function",
"(",
"input",
",",
"output",
")",
"{",
"var",
"target",
"=",
"output",
"||",
"input",
";",
"var",
"f",
"=",
"output",
"?",
"remove",
":",
"add",
";",
"for",
"(",
"var",
"key",
"in",
"target",
")",
"{",
"var",
"value",
"=",
"target",
"[",
"key",
"]",
";",
"var",
"key_",
"=",
"f",
"(",
"key",
")",
";",
"if",
"(",
"key_",
"===",
"key",
")",
"continue",
";",
"delete",
"target",
"[",
"key",
"]",
";",
"target",
"[",
"key_",
"]",
"=",
"value",
";",
"}",
"}",
";",
"}"
]
| A sticky transform that will change vars_like_this into varsLikeThis. | [
"A",
"sticky",
"transform",
"that",
"will",
"change",
"vars_like_this",
"into",
"varsLikeThis",
"."
]
| 8cb5fdba05be161e5936f7208558bc4702aae59a | https://github.com/bvalosek/sticky/blob/8cb5fdba05be161e5936f7208558bc4702aae59a/util/camelize.js#L6-L22 |
47,065 | timkuijsten/node-object-key-filter | index.js | filter | function filter(obj, keys, recurse) {
if (typeof obj !== 'object') { throw new TypeError('obj must be an object'); }
if (!Array.isArray(keys)) { throw new TypeError('keys must be an array'); }
if (recurse == null) {
recurse = false;
}
if (typeof recurse !== 'boolean') { throw new TypeError('recurse must be a boolean'); }
var result;
if (Array.isArray(obj)) {
result = [];
} else {
result = {};
}
Object.keys(obj).forEach(function(key) {
if (~keys.indexOf(key)) { return; }
// recurse if requested and possible
if (recurse && obj[key] != null && typeof obj[key] === 'object' && Object.keys(obj[key]).length) {
result[key] = filter(obj[key], keys, recurse);
} else {
result[key] = obj[key];
}
});
return result;
} | javascript | function filter(obj, keys, recurse) {
if (typeof obj !== 'object') { throw new TypeError('obj must be an object'); }
if (!Array.isArray(keys)) { throw new TypeError('keys must be an array'); }
if (recurse == null) {
recurse = false;
}
if (typeof recurse !== 'boolean') { throw new TypeError('recurse must be a boolean'); }
var result;
if (Array.isArray(obj)) {
result = [];
} else {
result = {};
}
Object.keys(obj).forEach(function(key) {
if (~keys.indexOf(key)) { return; }
// recurse if requested and possible
if (recurse && obj[key] != null && typeof obj[key] === 'object' && Object.keys(obj[key]).length) {
result[key] = filter(obj[key], keys, recurse);
} else {
result[key] = obj[key];
}
});
return result;
} | [
"function",
"filter",
"(",
"obj",
",",
"keys",
",",
"recurse",
")",
"{",
"if",
"(",
"typeof",
"obj",
"!==",
"'object'",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'obj must be an object'",
")",
";",
"}",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"keys",
")",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'keys must be an array'",
")",
";",
"}",
"if",
"(",
"recurse",
"==",
"null",
")",
"{",
"recurse",
"=",
"false",
";",
"}",
"if",
"(",
"typeof",
"recurse",
"!==",
"'boolean'",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'recurse must be a boolean'",
")",
";",
"}",
"var",
"result",
";",
"if",
"(",
"Array",
".",
"isArray",
"(",
"obj",
")",
")",
"{",
"result",
"=",
"[",
"]",
";",
"}",
"else",
"{",
"result",
"=",
"{",
"}",
";",
"}",
"Object",
".",
"keys",
"(",
"obj",
")",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"if",
"(",
"~",
"keys",
".",
"indexOf",
"(",
"key",
")",
")",
"{",
"return",
";",
"}",
"// recurse if requested and possible",
"if",
"(",
"recurse",
"&&",
"obj",
"[",
"key",
"]",
"!=",
"null",
"&&",
"typeof",
"obj",
"[",
"key",
"]",
"===",
"'object'",
"&&",
"Object",
".",
"keys",
"(",
"obj",
"[",
"key",
"]",
")",
".",
"length",
")",
"{",
"result",
"[",
"key",
"]",
"=",
"filter",
"(",
"obj",
"[",
"key",
"]",
",",
"keys",
",",
"recurse",
")",
";",
"}",
"else",
"{",
"result",
"[",
"key",
"]",
"=",
"obj",
"[",
"key",
"]",
";",
"}",
"}",
")",
";",
"return",
"result",
";",
"}"
]
| Filter certain keys from an object without side-effects, optionally recurse.
@param {Object|Array} obj object to filter keys from
@param {Array} keys array of key names to filter
@param {Boolean, default: false} recurse whether or not to recurse
@return {Object} object same as input but without the specified keys | [
"Filter",
"certain",
"keys",
"from",
"an",
"object",
"without",
"side",
"-",
"effects",
"optionally",
"recurse",
"."
]
| 5452a6db0f85b55351742307cbce063654ebbb15 | https://github.com/timkuijsten/node-object-key-filter/blob/5452a6db0f85b55351742307cbce063654ebbb15/index.js#L27-L55 |
47,066 | alexindigo/deeply | extra/arrays_append.js | arraysAppendAdapter | function arraysAppendAdapter(to, from, merge)
{
// transfer actual values
from.reduce(function(target, value)
{
target.push(merge(undefined, value));
return target;
}, to);
return to;
} | javascript | function arraysAppendAdapter(to, from, merge)
{
// transfer actual values
from.reduce(function(target, value)
{
target.push(merge(undefined, value));
return target;
}, to);
return to;
} | [
"function",
"arraysAppendAdapter",
"(",
"to",
",",
"from",
",",
"merge",
")",
"{",
"// transfer actual values",
"from",
".",
"reduce",
"(",
"function",
"(",
"target",
",",
"value",
")",
"{",
"target",
".",
"push",
"(",
"merge",
"(",
"undefined",
",",
"value",
")",
")",
";",
"return",
"target",
";",
"}",
",",
"to",
")",
";",
"return",
"to",
";",
"}"
]
| Adapter to merge arrays
by appending cloned elements
of the second array to the first
@param {array} to - target array to update
@param {array} from - array to clone
@param {function} merge - iterator to merge sub elements
@returns {array} - modified target object | [
"Adapter",
"to",
"merge",
"arrays",
"by",
"appending",
"cloned",
"elements",
"of",
"the",
"second",
"array",
"to",
"the",
"first"
]
| d9f59eec37b75ce52038b3fcfb0fd86d4989c0c1 | https://github.com/alexindigo/deeply/blob/d9f59eec37b75ce52038b3fcfb0fd86d4989c0c1/extra/arrays_append.js#L14-L25 |
47,067 | SilentCicero/ethdeploy | src/lib/index.js | loadEnvironment | function loadEnvironment(environment, callback) {
const errorMsgBase = 'while transforming environment, ';
var transformedEnvironment = cloneDeep(environment); // eslint-disable-line
const query = new Eth(transformedEnvironment.provider);
query.net_version((versionError, result) => { // eslint-disable-line
if (versionError) { return callback(error(`${errorMsgBase}error attempting to connect to node environment '${transformedEnvironment.name}': ${versionError}`), null); }
query.accounts((accountsError, accounts) => { // eslint-disable-line
if (accountsError !== null) { return callback(error(`${errorMsgBase}error while getting accounts for deployment: ${accountsError}`), null); }
callback(accountsError, Object.assign({}, cloneDeep(transformedEnvironment), {
accounts,
defaultTxObject: transformTxObject(environment.defaultTxObject, accounts),
}));
});
});
} | javascript | function loadEnvironment(environment, callback) {
const errorMsgBase = 'while transforming environment, ';
var transformedEnvironment = cloneDeep(environment); // eslint-disable-line
const query = new Eth(transformedEnvironment.provider);
query.net_version((versionError, result) => { // eslint-disable-line
if (versionError) { return callback(error(`${errorMsgBase}error attempting to connect to node environment '${transformedEnvironment.name}': ${versionError}`), null); }
query.accounts((accountsError, accounts) => { // eslint-disable-line
if (accountsError !== null) { return callback(error(`${errorMsgBase}error while getting accounts for deployment: ${accountsError}`), null); }
callback(accountsError, Object.assign({}, cloneDeep(transformedEnvironment), {
accounts,
defaultTxObject: transformTxObject(environment.defaultTxObject, accounts),
}));
});
});
} | [
"function",
"loadEnvironment",
"(",
"environment",
",",
"callback",
")",
"{",
"const",
"errorMsgBase",
"=",
"'while transforming environment, '",
";",
"var",
"transformedEnvironment",
"=",
"cloneDeep",
"(",
"environment",
")",
";",
"// eslint-disable-line",
"const",
"query",
"=",
"new",
"Eth",
"(",
"transformedEnvironment",
".",
"provider",
")",
";",
"query",
".",
"net_version",
"(",
"(",
"versionError",
",",
"result",
")",
"=>",
"{",
"// eslint-disable-line",
"if",
"(",
"versionError",
")",
"{",
"return",
"callback",
"(",
"error",
"(",
"`",
"${",
"errorMsgBase",
"}",
"${",
"transformedEnvironment",
".",
"name",
"}",
"${",
"versionError",
"}",
"`",
")",
",",
"null",
")",
";",
"}",
"query",
".",
"accounts",
"(",
"(",
"accountsError",
",",
"accounts",
")",
"=>",
"{",
"// eslint-disable-line",
"if",
"(",
"accountsError",
"!==",
"null",
")",
"{",
"return",
"callback",
"(",
"error",
"(",
"`",
"${",
"errorMsgBase",
"}",
"${",
"accountsError",
"}",
"`",
")",
",",
"null",
")",
";",
"}",
"callback",
"(",
"accountsError",
",",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"cloneDeep",
"(",
"transformedEnvironment",
")",
",",
"{",
"accounts",
",",
"defaultTxObject",
":",
"transformTxObject",
"(",
"environment",
".",
"defaultTxObject",
",",
"accounts",
")",
",",
"}",
")",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| Load the environment, get accounts, gas limits, balances etc.
@method loadEnvironment
@param {Object} environment the environment object specified in the config.js
@param {Function} callback the callback to return the environment
@callback {Object} output the transformed environment object | [
"Load",
"the",
"environment",
"get",
"accounts",
"gas",
"limits",
"balances",
"etc",
"."
]
| acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6 | https://github.com/SilentCicero/ethdeploy/blob/acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6/src/lib/index.js#L40-L58 |
47,068 | SilentCicero/ethdeploy | src/lib/index.js | transformContracts | function transformContracts(contracts, environmentName) {
const scopedContracts = Object.assign({}, cloneDeep(contracts[environmentName] || {}));
// add name property to all contracts for deployment identification
Object.keys(scopedContracts).forEach((contractName) => {
scopedContracts[contractName].name = contractName;
});
// return new scroped contracts
return scopedContracts;
} | javascript | function transformContracts(contracts, environmentName) {
const scopedContracts = Object.assign({}, cloneDeep(contracts[environmentName] || {}));
// add name property to all contracts for deployment identification
Object.keys(scopedContracts).forEach((contractName) => {
scopedContracts[contractName].name = contractName;
});
// return new scroped contracts
return scopedContracts;
} | [
"function",
"transformContracts",
"(",
"contracts",
",",
"environmentName",
")",
"{",
"const",
"scopedContracts",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"cloneDeep",
"(",
"contracts",
"[",
"environmentName",
"]",
"||",
"{",
"}",
")",
")",
";",
"// add name property to all contracts for deployment identification",
"Object",
".",
"keys",
"(",
"scopedContracts",
")",
".",
"forEach",
"(",
"(",
"contractName",
")",
"=>",
"{",
"scopedContracts",
"[",
"contractName",
"]",
".",
"name",
"=",
"contractName",
";",
"}",
")",
";",
"// return new scroped contracts",
"return",
"scopedContracts",
";",
"}"
]
| Prepair the contracts for deployment, scope contracts array, add name
@method transformContracts
@param {Object} contracts the environment object specified in the config.js
@param {String} environmentName the callback to return the environment
@return {Object} output the scoped contracts object, ready for deployment method | [
"Prepair",
"the",
"contracts",
"for",
"deployment",
"scope",
"contracts",
"array",
"add",
"name"
]
| acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6 | https://github.com/SilentCicero/ethdeploy/blob/acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6/src/lib/index.js#L68-L78 |
47,069 | SilentCicero/ethdeploy | src/lib/index.js | configError | function configError(config) {
if (typeof config !== 'object') { return `the config method must return a config object, got type ${typeof config}`; }
if (typeof config.entry === 'undefined') { return `No defined entry! 'config.entry' must be defined, got type ${typeof config.entry}.`; }
if (typeof config.module !== 'object') { return `No defined deployment module! 'config.module' must be an object, got type ${typeof config.module}`; }
if (typeof config.module.deployment !== 'function') { return `No defined deployment function! 'config.module.deployment' must be type Function (i.e. 'module.deployment = (deploy, contracts, done){}' ), got ${typeof config.module.deployment}`; }
if (typeof config.module.environment !== 'object') { return `No defined module environment object! 'config.module.environment' must be type Object, got ${typeof config.module.environment}`; }
const environment = config.module.environment;
if (typeof environment.provider !== 'object') { return `No defined provider object! 'config.module.environment' must have a defined 'provider' object, got ${typeof environment.provider}`; }
if (typeof environment.name !== 'string') { return `No defined environment name! 'config.module.environment.name' must be type String, got ${typeof environment.name}`; }
return null;
} | javascript | function configError(config) {
if (typeof config !== 'object') { return `the config method must return a config object, got type ${typeof config}`; }
if (typeof config.entry === 'undefined') { return `No defined entry! 'config.entry' must be defined, got type ${typeof config.entry}.`; }
if (typeof config.module !== 'object') { return `No defined deployment module! 'config.module' must be an object, got type ${typeof config.module}`; }
if (typeof config.module.deployment !== 'function') { return `No defined deployment function! 'config.module.deployment' must be type Function (i.e. 'module.deployment = (deploy, contracts, done){}' ), got ${typeof config.module.deployment}`; }
if (typeof config.module.environment !== 'object') { return `No defined module environment object! 'config.module.environment' must be type Object, got ${typeof config.module.environment}`; }
const environment = config.module.environment;
if (typeof environment.provider !== 'object') { return `No defined provider object! 'config.module.environment' must have a defined 'provider' object, got ${typeof environment.provider}`; }
if (typeof environment.name !== 'string') { return `No defined environment name! 'config.module.environment.name' must be type String, got ${typeof environment.name}`; }
return null;
} | [
"function",
"configError",
"(",
"config",
")",
"{",
"if",
"(",
"typeof",
"config",
"!==",
"'object'",
")",
"{",
"return",
"`",
"${",
"typeof",
"config",
"}",
"`",
";",
"}",
"if",
"(",
"typeof",
"config",
".",
"entry",
"===",
"'undefined'",
")",
"{",
"return",
"`",
"${",
"typeof",
"config",
".",
"entry",
"}",
"`",
";",
"}",
"if",
"(",
"typeof",
"config",
".",
"module",
"!==",
"'object'",
")",
"{",
"return",
"`",
"${",
"typeof",
"config",
".",
"module",
"}",
"`",
";",
"}",
"if",
"(",
"typeof",
"config",
".",
"module",
".",
"deployment",
"!==",
"'function'",
")",
"{",
"return",
"`",
"${",
"typeof",
"config",
".",
"module",
".",
"deployment",
"}",
"`",
";",
"}",
"if",
"(",
"typeof",
"config",
".",
"module",
".",
"environment",
"!==",
"'object'",
")",
"{",
"return",
"`",
"${",
"typeof",
"config",
".",
"module",
".",
"environment",
"}",
"`",
";",
"}",
"const",
"environment",
"=",
"config",
".",
"module",
".",
"environment",
";",
"if",
"(",
"typeof",
"environment",
".",
"provider",
"!==",
"'object'",
")",
"{",
"return",
"`",
"${",
"typeof",
"environment",
".",
"provider",
"}",
"`",
";",
"}",
"if",
"(",
"typeof",
"environment",
".",
"name",
"!==",
"'string'",
")",
"{",
"return",
"`",
"${",
"typeof",
"environment",
".",
"name",
"}",
"`",
";",
"}",
"return",
"null",
";",
"}"
]
| Validate the config, after the method has been called
@method configError
@param {Object} config the environment object specified in the config.js
@return {Object|Null} output the config error, if any | [
"Validate",
"the",
"config",
"after",
"the",
"method",
"has",
"been",
"called"
]
| acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6 | https://github.com/SilentCicero/ethdeploy/blob/acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6/src/lib/index.js#L87-L99 |
47,070 | SilentCicero/ethdeploy | src/lib/index.js | requireLoader | function requireLoader(loaderConfig) {
const errMsgBase = `while requiring loader ${JSON.stringify(loaderConfig)} config,`;
if (typeof loaderConfig !== 'object') { throw error(`${errMsgBase}, config must be object, got ${typeof loaderConfig}`); }
if (typeof loaderConfig.loader !== 'string') { throw error(`${errMsgBase}, config.loader must be String, got ${JSON.stringify(loaderConfig.loader)}`); }
return require(loaderConfig.loader); // eslint-disable-line
} | javascript | function requireLoader(loaderConfig) {
const errMsgBase = `while requiring loader ${JSON.stringify(loaderConfig)} config,`;
if (typeof loaderConfig !== 'object') { throw error(`${errMsgBase}, config must be object, got ${typeof loaderConfig}`); }
if (typeof loaderConfig.loader !== 'string') { throw error(`${errMsgBase}, config.loader must be String, got ${JSON.stringify(loaderConfig.loader)}`); }
return require(loaderConfig.loader); // eslint-disable-line
} | [
"function",
"requireLoader",
"(",
"loaderConfig",
")",
"{",
"const",
"errMsgBase",
"=",
"`",
"${",
"JSON",
".",
"stringify",
"(",
"loaderConfig",
")",
"}",
"`",
";",
"if",
"(",
"typeof",
"loaderConfig",
"!==",
"'object'",
")",
"{",
"throw",
"error",
"(",
"`",
"${",
"errMsgBase",
"}",
"${",
"typeof",
"loaderConfig",
"}",
"`",
")",
";",
"}",
"if",
"(",
"typeof",
"loaderConfig",
".",
"loader",
"!==",
"'string'",
")",
"{",
"throw",
"error",
"(",
"`",
"${",
"errMsgBase",
"}",
"${",
"JSON",
".",
"stringify",
"(",
"loaderConfig",
".",
"loader",
")",
"}",
"`",
")",
";",
"}",
"return",
"require",
"(",
"loaderConfig",
".",
"loader",
")",
";",
"// eslint-disable-line",
"}"
]
| Require the loader
@method requireLoader
@param {Object} loaderConfig the loader config
@return {Object} loader the required loader | [
"Require",
"the",
"loader"
]
| acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6 | https://github.com/SilentCicero/ethdeploy/blob/acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6/src/lib/index.js#L108-L114 |
47,071 | SilentCicero/ethdeploy | src/lib/index.js | loadContracts | function loadContracts(loaders, base, sourceMap, environment, callback) { // eslint-disable-line
var outputContracts = cloneDeep(base); // eslint-disable-line
const errMsgBase = 'while processing entry data, ';
if (!Array.isArray(loaders)) { return callback(error(`${errMsgBase}loaders must be type Array, got ${typeof loaders}`)); }
// process loaders
try {
loaders.forEach((loaderConfig) => {
// require the loader for use
const loader = requireLoader(loaderConfig);
// filtered sourcemap based on regex/include
const filteredSourceMap = filterSourceMap(loaderConfig.test,
loaderConfig.include,
sourceMap,
loaderConfig.exclude);
// get loaded contracts
const loadedEnvironment = loader(cloneDeep(filteredSourceMap), loaderConfig, environment);
// output the new contracts
outputContracts = Object.assign({}, cloneDeep(outputContracts), cloneDeep(loadedEnvironment));
});
// transform final contracts output
callback(null, outputContracts);
} catch (loaderError) {
callback(error(`${errMsgBase}loader error: ${loaderError}`));
}
} | javascript | function loadContracts(loaders, base, sourceMap, environment, callback) { // eslint-disable-line
var outputContracts = cloneDeep(base); // eslint-disable-line
const errMsgBase = 'while processing entry data, ';
if (!Array.isArray(loaders)) { return callback(error(`${errMsgBase}loaders must be type Array, got ${typeof loaders}`)); }
// process loaders
try {
loaders.forEach((loaderConfig) => {
// require the loader for use
const loader = requireLoader(loaderConfig);
// filtered sourcemap based on regex/include
const filteredSourceMap = filterSourceMap(loaderConfig.test,
loaderConfig.include,
sourceMap,
loaderConfig.exclude);
// get loaded contracts
const loadedEnvironment = loader(cloneDeep(filteredSourceMap), loaderConfig, environment);
// output the new contracts
outputContracts = Object.assign({}, cloneDeep(outputContracts), cloneDeep(loadedEnvironment));
});
// transform final contracts output
callback(null, outputContracts);
} catch (loaderError) {
callback(error(`${errMsgBase}loader error: ${loaderError}`));
}
} | [
"function",
"loadContracts",
"(",
"loaders",
",",
"base",
",",
"sourceMap",
",",
"environment",
",",
"callback",
")",
"{",
"// eslint-disable-line",
"var",
"outputContracts",
"=",
"cloneDeep",
"(",
"base",
")",
";",
"// eslint-disable-line",
"const",
"errMsgBase",
"=",
"'while processing entry data, '",
";",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"loaders",
")",
")",
"{",
"return",
"callback",
"(",
"error",
"(",
"`",
"${",
"errMsgBase",
"}",
"${",
"typeof",
"loaders",
"}",
"`",
")",
")",
";",
"}",
"// process loaders",
"try",
"{",
"loaders",
".",
"forEach",
"(",
"(",
"loaderConfig",
")",
"=>",
"{",
"// require the loader for use",
"const",
"loader",
"=",
"requireLoader",
"(",
"loaderConfig",
")",
";",
"// filtered sourcemap based on regex/include",
"const",
"filteredSourceMap",
"=",
"filterSourceMap",
"(",
"loaderConfig",
".",
"test",
",",
"loaderConfig",
".",
"include",
",",
"sourceMap",
",",
"loaderConfig",
".",
"exclude",
")",
";",
"// get loaded contracts",
"const",
"loadedEnvironment",
"=",
"loader",
"(",
"cloneDeep",
"(",
"filteredSourceMap",
")",
",",
"loaderConfig",
",",
"environment",
")",
";",
"// output the new contracts",
"outputContracts",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"cloneDeep",
"(",
"outputContracts",
")",
",",
"cloneDeep",
"(",
"loadedEnvironment",
")",
")",
";",
"}",
")",
";",
"// transform final contracts output",
"callback",
"(",
"null",
",",
"outputContracts",
")",
";",
"}",
"catch",
"(",
"loaderError",
")",
"{",
"callback",
"(",
"error",
"(",
"`",
"${",
"errMsgBase",
"}",
"${",
"loaderError",
"}",
"`",
")",
")",
";",
"}",
"}"
]
| Load contracts from the sourcemap, start from base
@method loadContracts
@param {Array} loaders the array of loaders
@param {Object} base the base contracts object from which to assign to
@param {Object} sourceMap the sourcemap from load time
@param {Object} environment the environments object
@param {Function} callback the method callback that returns the contracts
@callback {Object} contracts the loaded contracts | [
"Load",
"contracts",
"from",
"the",
"sourcemap",
"start",
"from",
"base"
]
| acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6 | https://github.com/SilentCicero/ethdeploy/blob/acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6/src/lib/index.js#L127-L156 |
47,072 | SilentCicero/ethdeploy | src/lib/index.js | processOutput | function processOutput(plugins, outputObject, configObject, baseContracts, contracts, environment, callback) { // eslint-disable-line
// the final string to be outputed
let outputString = JSON.stringify(outputObject, null, 2); // eslint-disable-line
// the err msg base
const errMsgBase = 'while processing output with plugins, ';
if (!Array.isArray(plugins)) { return callback(error(`${errMsgBase}plugins must be type Array, got ${typeof plugins}`)); }
// process deployers
try {
plugins.forEach((plugin) => {
// process deployer method
outputString = plugin.process({ output: outputString, config: configObject, baseContracts, contracts, environment });
});
// return final output string
callback(null, outputString);
} catch (deployerError) {
callback(error(`${errMsgBase}plugins error: ${deployerError}`));
}
} | javascript | function processOutput(plugins, outputObject, configObject, baseContracts, contracts, environment, callback) { // eslint-disable-line
// the final string to be outputed
let outputString = JSON.stringify(outputObject, null, 2); // eslint-disable-line
// the err msg base
const errMsgBase = 'while processing output with plugins, ';
if (!Array.isArray(plugins)) { return callback(error(`${errMsgBase}plugins must be type Array, got ${typeof plugins}`)); }
// process deployers
try {
plugins.forEach((plugin) => {
// process deployer method
outputString = plugin.process({ output: outputString, config: configObject, baseContracts, contracts, environment });
});
// return final output string
callback(null, outputString);
} catch (deployerError) {
callback(error(`${errMsgBase}plugins error: ${deployerError}`));
}
} | [
"function",
"processOutput",
"(",
"plugins",
",",
"outputObject",
",",
"configObject",
",",
"baseContracts",
",",
"contracts",
",",
"environment",
",",
"callback",
")",
"{",
"// eslint-disable-line",
"// the final string to be outputed",
"let",
"outputString",
"=",
"JSON",
".",
"stringify",
"(",
"outputObject",
",",
"null",
",",
"2",
")",
";",
"// eslint-disable-line",
"// the err msg base",
"const",
"errMsgBase",
"=",
"'while processing output with plugins, '",
";",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"plugins",
")",
")",
"{",
"return",
"callback",
"(",
"error",
"(",
"`",
"${",
"errMsgBase",
"}",
"${",
"typeof",
"plugins",
"}",
"`",
")",
")",
";",
"}",
"// process deployers",
"try",
"{",
"plugins",
".",
"forEach",
"(",
"(",
"plugin",
")",
"=>",
"{",
"// process deployer method",
"outputString",
"=",
"plugin",
".",
"process",
"(",
"{",
"output",
":",
"outputString",
",",
"config",
":",
"configObject",
",",
"baseContracts",
",",
"contracts",
",",
"environment",
"}",
")",
";",
"}",
")",
";",
"// return final output string",
"callback",
"(",
"null",
",",
"outputString",
")",
";",
"}",
"catch",
"(",
"deployerError",
")",
"{",
"callback",
"(",
"error",
"(",
"`",
"${",
"errMsgBase",
"}",
"${",
"deployerError",
"}",
"`",
")",
")",
";",
"}",
"}"
]
| Process the final load output into string output for file creation.
@method processOutput
@param {Array} plugins the array of plugins, if any
@param {Object} outputObject the deplyed contracts
@param {Object} configObject the config js object
@param {Function} callback the method callback that returns the final string output
@callback {String} outputString the loaded contracts | [
"Process",
"the",
"final",
"load",
"output",
"into",
"string",
"output",
"for",
"file",
"creation",
"."
]
| acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6 | https://github.com/SilentCicero/ethdeploy/blob/acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6/src/lib/index.js#L168-L188 |
47,073 | SilentCicero/ethdeploy | src/lib/index.js | contractIsDeployed | function contractIsDeployed(baseContract, stagedContract) {
// if bytecode and inputs match, then skip with instance
if (deepEqual(typeof baseContract.address, 'string')
&& deepEqual(baseContract.transactionObject, stagedContract.transactionObject)
&& deepEqual(`0x${stripHexPrefix(baseContract.bytecode)}`, `0x${stripHexPrefix(stagedContract.bytecode)}`)
&& deepEqual(baseContract.inputs, stagedContract.inputs)) {
return true;
}
return false;
} | javascript | function contractIsDeployed(baseContract, stagedContract) {
// if bytecode and inputs match, then skip with instance
if (deepEqual(typeof baseContract.address, 'string')
&& deepEqual(baseContract.transactionObject, stagedContract.transactionObject)
&& deepEqual(`0x${stripHexPrefix(baseContract.bytecode)}`, `0x${stripHexPrefix(stagedContract.bytecode)}`)
&& deepEqual(baseContract.inputs, stagedContract.inputs)) {
return true;
}
return false;
} | [
"function",
"contractIsDeployed",
"(",
"baseContract",
",",
"stagedContract",
")",
"{",
"// if bytecode and inputs match, then skip with instance",
"if",
"(",
"deepEqual",
"(",
"typeof",
"baseContract",
".",
"address",
",",
"'string'",
")",
"&&",
"deepEqual",
"(",
"baseContract",
".",
"transactionObject",
",",
"stagedContract",
".",
"transactionObject",
")",
"&&",
"deepEqual",
"(",
"`",
"${",
"stripHexPrefix",
"(",
"baseContract",
".",
"bytecode",
")",
"}",
"`",
",",
"`",
"${",
"stripHexPrefix",
"(",
"stagedContract",
".",
"bytecode",
")",
"}",
"`",
")",
"&&",
"deepEqual",
"(",
"baseContract",
".",
"inputs",
",",
"stagedContract",
".",
"inputs",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
]
| Determine if the contract has already been deployed.
@method contractIsDeployed
@param {Object} baseContract the base contracts on which to deploy new ones
@param {Object} stagedContract the transformed environment
@return {Boolean} isDeployed has the contract already been deployed | [
"Determine",
"if",
"the",
"contract",
"has",
"already",
"been",
"deployed",
"."
]
| acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6 | https://github.com/SilentCicero/ethdeploy/blob/acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6/src/lib/index.js#L198-L208 |
47,074 | SilentCicero/ethdeploy | src/lib/index.js | isTransactionObject | function isTransactionObject(value) {
if (typeof value !== 'object') { return false; }
const keys = Object.keys(value);
if (keys.length > 5) { return false; }
if (keys.length === 0) { return true; }
if (keys.length > 0 && isDefined(value.from) || isDefined(value.to) || isDefined(value.data) || isDefined(value.gas) || isDefined(value.gasPrice)) {
return true;
}
return false;
} | javascript | function isTransactionObject(value) {
if (typeof value !== 'object') { return false; }
const keys = Object.keys(value);
if (keys.length > 5) { return false; }
if (keys.length === 0) { return true; }
if (keys.length > 0 && isDefined(value.from) || isDefined(value.to) || isDefined(value.data) || isDefined(value.gas) || isDefined(value.gasPrice)) {
return true;
}
return false;
} | [
"function",
"isTransactionObject",
"(",
"value",
")",
"{",
"if",
"(",
"typeof",
"value",
"!==",
"'object'",
")",
"{",
"return",
"false",
";",
"}",
"const",
"keys",
"=",
"Object",
".",
"keys",
"(",
"value",
")",
";",
"if",
"(",
"keys",
".",
"length",
">",
"5",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"keys",
".",
"length",
"===",
"0",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"keys",
".",
"length",
">",
"0",
"&&",
"isDefined",
"(",
"value",
".",
"from",
")",
"||",
"isDefined",
"(",
"value",
".",
"to",
")",
"||",
"isDefined",
"(",
"value",
".",
"data",
")",
"||",
"isDefined",
"(",
"value",
".",
"gas",
")",
"||",
"isDefined",
"(",
"value",
".",
"gasPrice",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
]
| Is the value a transaction object.
@method isTransactionObject
@param {Optional} value the potential tx object
@return {Boolean} isTransactionObject is the object a tx object | [
"Is",
"the",
"value",
"a",
"transaction",
"object",
"."
]
| acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6 | https://github.com/SilentCicero/ethdeploy/blob/acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6/src/lib/index.js#L221-L233 |
47,075 | SilentCicero/ethdeploy | src/lib/index.js | buildDeployMethod | function buildDeployMethod(baseContracts, transformedEnvironment, report) {
return (...args) => {
let transactionObject = {};
const defaultTxObject = transformedEnvironment.defaultTxObject || {};
const contractData = args[0];
if (typeof contractData !== 'object') {
const noContractError = 'A contract you are trying to deploy does not exist in your contracts object. Please check your entry, loaders and contracts object.';
return Promise.reject(error(noContractError));
}
const baseContract = baseContracts[contractData.name] || {};
const contractNewArguments = args.slice(1);
const contractInputs = bnToString(Array.prototype.slice.call(contractNewArguments));
const contractBytecode = `0x${stripHexPrefix(contractData.bytecode)}`;
const contractABI = JSON.parse(contractData.interface);
const eth = new Eth(transformedEnvironment.provider);
const contract = new EthContract(eth);
const contractFactory = contract(contractABI, contractBytecode, defaultTxObject);
// trim callback from inputs, not args
// custom tx object not handled yet.....
if (typeof contractInputs[contractInputs.length - 1] === 'function') {
contractInputs.pop();
}
// if there is a tx object provided for just this contractInputs
// then get tx object, assign over default and use as the latest tx object
if (isTransactionObject(contractInputs[contractInputs.length - 1])) {
const transformedTransactionObject = transformTxObject(contractInputs[contractInputs.length - 1], transformedEnvironment.accounts);
contractInputs[contractInputs.length - 1] = transformedTransactionObject;
transactionObject = Object.assign({}, cloneDeep(defaultTxObject), cloneDeep(transformedTransactionObject));
} else {
transactionObject = Object.assign({}, cloneDeep(defaultTxObject));
}
// check contract has transaction object, either default or specified
if (!EthUtils.isHexString(transactionObject.from, 20)) {
const invalidFromAccount = `Attempting to deploy contract '${contractData.name}' with an invalid 'from' account specified. The 'from' account must be a valid 20 byte hex prefixed Ethereum address, got value '${transactionObject.from}'. Please specify a defaultTxObject in the module.environment.defaultTxObject (i.e. 'defaultTxObject: { from: 0 }') object or in the in the deploy method.`;
return Promise.reject(error(invalidFromAccount));
}
// check if contract is already deployed, if so, return instance
return new Promise((resolve, reject) => {
const resolveAndReport = (contractInstance) => {
// report the contract
report(contractData.name,
contractData,
contractInstance.address,
contractInputs,
transactionObject,
(contractInstance.receipt || baseContract.receipt));
// resolve deployment
resolve(contractInstance);
};
// if the contract is deployed, resolve with base base contract, else deploy
if (contractIsDeployed(baseContract, {
transactionObject,
bytecode: contractBytecode,
inputs: contractInputs,
})) {
resolveAndReport(contractFactory.at(baseContract.address));
} else {
deployContract(eth, contractFactory, contractInputs, (deployError, instance) => {
if (deployError) {
console.log(error(`while deploying contract '${contractData.name}': `, JSON.stringify(deployError.value, null, 2))); // eslint-disable-line
reject(deployError);
} else {
resolveAndReport(instance);
}
});
}
});
};
} | javascript | function buildDeployMethod(baseContracts, transformedEnvironment, report) {
return (...args) => {
let transactionObject = {};
const defaultTxObject = transformedEnvironment.defaultTxObject || {};
const contractData = args[0];
if (typeof contractData !== 'object') {
const noContractError = 'A contract you are trying to deploy does not exist in your contracts object. Please check your entry, loaders and contracts object.';
return Promise.reject(error(noContractError));
}
const baseContract = baseContracts[contractData.name] || {};
const contractNewArguments = args.slice(1);
const contractInputs = bnToString(Array.prototype.slice.call(contractNewArguments));
const contractBytecode = `0x${stripHexPrefix(contractData.bytecode)}`;
const contractABI = JSON.parse(contractData.interface);
const eth = new Eth(transformedEnvironment.provider);
const contract = new EthContract(eth);
const contractFactory = contract(contractABI, contractBytecode, defaultTxObject);
// trim callback from inputs, not args
// custom tx object not handled yet.....
if (typeof contractInputs[contractInputs.length - 1] === 'function') {
contractInputs.pop();
}
// if there is a tx object provided for just this contractInputs
// then get tx object, assign over default and use as the latest tx object
if (isTransactionObject(contractInputs[contractInputs.length - 1])) {
const transformedTransactionObject = transformTxObject(contractInputs[contractInputs.length - 1], transformedEnvironment.accounts);
contractInputs[contractInputs.length - 1] = transformedTransactionObject;
transactionObject = Object.assign({}, cloneDeep(defaultTxObject), cloneDeep(transformedTransactionObject));
} else {
transactionObject = Object.assign({}, cloneDeep(defaultTxObject));
}
// check contract has transaction object, either default or specified
if (!EthUtils.isHexString(transactionObject.from, 20)) {
const invalidFromAccount = `Attempting to deploy contract '${contractData.name}' with an invalid 'from' account specified. The 'from' account must be a valid 20 byte hex prefixed Ethereum address, got value '${transactionObject.from}'. Please specify a defaultTxObject in the module.environment.defaultTxObject (i.e. 'defaultTxObject: { from: 0 }') object or in the in the deploy method.`;
return Promise.reject(error(invalidFromAccount));
}
// check if contract is already deployed, if so, return instance
return new Promise((resolve, reject) => {
const resolveAndReport = (contractInstance) => {
// report the contract
report(contractData.name,
contractData,
contractInstance.address,
contractInputs,
transactionObject,
(contractInstance.receipt || baseContract.receipt));
// resolve deployment
resolve(contractInstance);
};
// if the contract is deployed, resolve with base base contract, else deploy
if (contractIsDeployed(baseContract, {
transactionObject,
bytecode: contractBytecode,
inputs: contractInputs,
})) {
resolveAndReport(contractFactory.at(baseContract.address));
} else {
deployContract(eth, contractFactory, contractInputs, (deployError, instance) => {
if (deployError) {
console.log(error(`while deploying contract '${contractData.name}': `, JSON.stringify(deployError.value, null, 2))); // eslint-disable-line
reject(deployError);
} else {
resolveAndReport(instance);
}
});
}
});
};
} | [
"function",
"buildDeployMethod",
"(",
"baseContracts",
",",
"transformedEnvironment",
",",
"report",
")",
"{",
"return",
"(",
"...",
"args",
")",
"=>",
"{",
"let",
"transactionObject",
"=",
"{",
"}",
";",
"const",
"defaultTxObject",
"=",
"transformedEnvironment",
".",
"defaultTxObject",
"||",
"{",
"}",
";",
"const",
"contractData",
"=",
"args",
"[",
"0",
"]",
";",
"if",
"(",
"typeof",
"contractData",
"!==",
"'object'",
")",
"{",
"const",
"noContractError",
"=",
"'A contract you are trying to deploy does not exist in your contracts object. Please check your entry, loaders and contracts object.'",
";",
"return",
"Promise",
".",
"reject",
"(",
"error",
"(",
"noContractError",
")",
")",
";",
"}",
"const",
"baseContract",
"=",
"baseContracts",
"[",
"contractData",
".",
"name",
"]",
"||",
"{",
"}",
";",
"const",
"contractNewArguments",
"=",
"args",
".",
"slice",
"(",
"1",
")",
";",
"const",
"contractInputs",
"=",
"bnToString",
"(",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"contractNewArguments",
")",
")",
";",
"const",
"contractBytecode",
"=",
"`",
"${",
"stripHexPrefix",
"(",
"contractData",
".",
"bytecode",
")",
"}",
"`",
";",
"const",
"contractABI",
"=",
"JSON",
".",
"parse",
"(",
"contractData",
".",
"interface",
")",
";",
"const",
"eth",
"=",
"new",
"Eth",
"(",
"transformedEnvironment",
".",
"provider",
")",
";",
"const",
"contract",
"=",
"new",
"EthContract",
"(",
"eth",
")",
";",
"const",
"contractFactory",
"=",
"contract",
"(",
"contractABI",
",",
"contractBytecode",
",",
"defaultTxObject",
")",
";",
"// trim callback from inputs, not args",
"// custom tx object not handled yet.....",
"if",
"(",
"typeof",
"contractInputs",
"[",
"contractInputs",
".",
"length",
"-",
"1",
"]",
"===",
"'function'",
")",
"{",
"contractInputs",
".",
"pop",
"(",
")",
";",
"}",
"// if there is a tx object provided for just this contractInputs",
"// then get tx object, assign over default and use as the latest tx object",
"if",
"(",
"isTransactionObject",
"(",
"contractInputs",
"[",
"contractInputs",
".",
"length",
"-",
"1",
"]",
")",
")",
"{",
"const",
"transformedTransactionObject",
"=",
"transformTxObject",
"(",
"contractInputs",
"[",
"contractInputs",
".",
"length",
"-",
"1",
"]",
",",
"transformedEnvironment",
".",
"accounts",
")",
";",
"contractInputs",
"[",
"contractInputs",
".",
"length",
"-",
"1",
"]",
"=",
"transformedTransactionObject",
";",
"transactionObject",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"cloneDeep",
"(",
"defaultTxObject",
")",
",",
"cloneDeep",
"(",
"transformedTransactionObject",
")",
")",
";",
"}",
"else",
"{",
"transactionObject",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"cloneDeep",
"(",
"defaultTxObject",
")",
")",
";",
"}",
"// check contract has transaction object, either default or specified",
"if",
"(",
"!",
"EthUtils",
".",
"isHexString",
"(",
"transactionObject",
".",
"from",
",",
"20",
")",
")",
"{",
"const",
"invalidFromAccount",
"=",
"`",
"${",
"contractData",
".",
"name",
"}",
"${",
"transactionObject",
".",
"from",
"}",
"`",
";",
"return",
"Promise",
".",
"reject",
"(",
"error",
"(",
"invalidFromAccount",
")",
")",
";",
"}",
"// check if contract is already deployed, if so, return instance",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"const",
"resolveAndReport",
"=",
"(",
"contractInstance",
")",
"=>",
"{",
"// report the contract",
"report",
"(",
"contractData",
".",
"name",
",",
"contractData",
",",
"contractInstance",
".",
"address",
",",
"contractInputs",
",",
"transactionObject",
",",
"(",
"contractInstance",
".",
"receipt",
"||",
"baseContract",
".",
"receipt",
")",
")",
";",
"// resolve deployment",
"resolve",
"(",
"contractInstance",
")",
";",
"}",
";",
"// if the contract is deployed, resolve with base base contract, else deploy",
"if",
"(",
"contractIsDeployed",
"(",
"baseContract",
",",
"{",
"transactionObject",
",",
"bytecode",
":",
"contractBytecode",
",",
"inputs",
":",
"contractInputs",
",",
"}",
")",
")",
"{",
"resolveAndReport",
"(",
"contractFactory",
".",
"at",
"(",
"baseContract",
".",
"address",
")",
")",
";",
"}",
"else",
"{",
"deployContract",
"(",
"eth",
",",
"contractFactory",
",",
"contractInputs",
",",
"(",
"deployError",
",",
"instance",
")",
"=>",
"{",
"if",
"(",
"deployError",
")",
"{",
"console",
".",
"log",
"(",
"error",
"(",
"`",
"${",
"contractData",
".",
"name",
"}",
"`",
",",
"JSON",
".",
"stringify",
"(",
"deployError",
".",
"value",
",",
"null",
",",
"2",
")",
")",
")",
";",
"// eslint-disable-line",
"reject",
"(",
"deployError",
")",
";",
"}",
"else",
"{",
"resolveAndReport",
"(",
"instance",
")",
";",
"}",
"}",
")",
";",
"}",
"}",
")",
";",
"}",
";",
"}"
]
| Basic deployer, if not deployed, deploy, else, skip and return instance
@method buildDeployMethod
@param {Array} baseContracts the base contracts on which to compare to see if already deployed
@param {Object} transformedEnvironment the transformed environment
@param {Object} report the reporter method to report newly deployed contracts
@callback {Function} deploy the deply method used in module.deployment | [
"Basic",
"deployer",
"if",
"not",
"deployed",
"deploy",
"else",
"skip",
"and",
"return",
"instance"
]
| acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6 | https://github.com/SilentCicero/ethdeploy/blob/acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6/src/lib/index.js#L244-L323 |
47,076 | SilentCicero/ethdeploy | src/lib/index.js | singleEntrySourceMap | function singleEntrySourceMap(entryItem, entryData, sourceMap, callback) { // eslint-disable-line
if (typeof entryItem !== 'string') { return callback(null, sourceMap); }
// get input sources for this entry
getInputSources(entryItem, (inputSourceError, inputSourceMap) => { // eslint-disable-line
if (inputSourceError) { return callback(inputSourceError, null); }
// get source data
const sourceData = deepAssign({}, sourceMap, inputSourceMap);
// get next entry item
const nextEntryItem = entryData[entryData.indexOf(entryItem) + 1];
// recursively go through tree
singleEntrySourceMap(nextEntryItem, entryData, sourceData, callback);
});
} | javascript | function singleEntrySourceMap(entryItem, entryData, sourceMap, callback) { // eslint-disable-line
if (typeof entryItem !== 'string') { return callback(null, sourceMap); }
// get input sources for this entry
getInputSources(entryItem, (inputSourceError, inputSourceMap) => { // eslint-disable-line
if (inputSourceError) { return callback(inputSourceError, null); }
// get source data
const sourceData = deepAssign({}, sourceMap, inputSourceMap);
// get next entry item
const nextEntryItem = entryData[entryData.indexOf(entryItem) + 1];
// recursively go through tree
singleEntrySourceMap(nextEntryItem, entryData, sourceData, callback);
});
} | [
"function",
"singleEntrySourceMap",
"(",
"entryItem",
",",
"entryData",
",",
"sourceMap",
",",
"callback",
")",
"{",
"// eslint-disable-line",
"if",
"(",
"typeof",
"entryItem",
"!==",
"'string'",
")",
"{",
"return",
"callback",
"(",
"null",
",",
"sourceMap",
")",
";",
"}",
"// get input sources for this entry",
"getInputSources",
"(",
"entryItem",
",",
"(",
"inputSourceError",
",",
"inputSourceMap",
")",
"=>",
"{",
"// eslint-disable-line",
"if",
"(",
"inputSourceError",
")",
"{",
"return",
"callback",
"(",
"inputSourceError",
",",
"null",
")",
";",
"}",
"// get source data",
"const",
"sourceData",
"=",
"deepAssign",
"(",
"{",
"}",
",",
"sourceMap",
",",
"inputSourceMap",
")",
";",
"// get next entry item",
"const",
"nextEntryItem",
"=",
"entryData",
"[",
"entryData",
".",
"indexOf",
"(",
"entryItem",
")",
"+",
"1",
"]",
";",
"// recursively go through tree",
"singleEntrySourceMap",
"(",
"nextEntryItem",
",",
"entryData",
",",
"sourceData",
",",
"callback",
")",
";",
"}",
")",
";",
"}"
]
| Get source map for a single config object entry path.
@method singleEntrySourceMap
@param {String} entryItem the entry item string, generally a file or dir path
@param {Array} entryData the entry data
@param {Object} sourceMap the source map
@callback {Function} callback the callback | [
"Get",
"source",
"map",
"for",
"a",
"single",
"config",
"object",
"entry",
"path",
"."
]
| acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6 | https://github.com/SilentCicero/ethdeploy/blob/acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6/src/lib/index.js#L334-L350 |
47,077 | SilentCicero/ethdeploy | src/lib/index.js | entrySourceMap | function entrySourceMap(entry, callback) {
const entryData = typeof entry === 'string' ? [entry] : entry;
// get source map
singleEntrySourceMap(entryData[0], entryData, {}, callback);
} | javascript | function entrySourceMap(entry, callback) {
const entryData = typeof entry === 'string' ? [entry] : entry;
// get source map
singleEntrySourceMap(entryData[0], entryData, {}, callback);
} | [
"function",
"entrySourceMap",
"(",
"entry",
",",
"callback",
")",
"{",
"const",
"entryData",
"=",
"typeof",
"entry",
"===",
"'string'",
"?",
"[",
"entry",
"]",
":",
"entry",
";",
"// get source map",
"singleEntrySourceMap",
"(",
"entryData",
"[",
"0",
"]",
",",
"entryData",
",",
"{",
"}",
",",
"callback",
")",
";",
"}"
]
| Build complete file source map of all entry items from the config.entry.
@method entrySourceMap
@param {Array|String} entry the entry object
@param {Function} callback the callback that will return the source map
@callback {Object} sourceMap the source map object with all files/dirs in entry | [
"Build",
"complete",
"file",
"source",
"map",
"of",
"all",
"entry",
"items",
"from",
"the",
"config",
".",
"entry",
"."
]
| acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6 | https://github.com/SilentCicero/ethdeploy/blob/acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6/src/lib/index.js#L360-L365 |
47,078 | jsonmaur/node-crypto-extra | src/encryption.js | constantTimeCompare | function constantTimeCompare (val1, val2) {
let sentinel
if (val1.length !== val2.length) return false
for (let i = 0, len = val1.length; i < len; i++) {
sentinel |= val1.charCodeAt(i) ^ val2.charCodeAt(i)
}
return sentinel === 0
} | javascript | function constantTimeCompare (val1, val2) {
let sentinel
if (val1.length !== val2.length) return false
for (let i = 0, len = val1.length; i < len; i++) {
sentinel |= val1.charCodeAt(i) ^ val2.charCodeAt(i)
}
return sentinel === 0
} | [
"function",
"constantTimeCompare",
"(",
"val1",
",",
"val2",
")",
"{",
"let",
"sentinel",
"if",
"(",
"val1",
".",
"length",
"!==",
"val2",
".",
"length",
")",
"return",
"false",
"for",
"(",
"let",
"i",
"=",
"0",
",",
"len",
"=",
"val1",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"sentinel",
"|=",
"val1",
".",
"charCodeAt",
"(",
"i",
")",
"^",
"val2",
".",
"charCodeAt",
"(",
"i",
")",
"}",
"return",
"sentinel",
"===",
"0",
"}"
]
| Ensures the encrypted payload has not been tampered with.
@param {string} val1 - Hash to compare
@param {string} val2 - Hash to compare to
@return {boolean} Whether it is valid | [
"Ensures",
"the",
"encrypted",
"payload",
"has",
"not",
"been",
"tampered",
"with",
"."
]
| 43f73dd892e1ffcb38e0be4fe387a8da2695c986 | https://github.com/jsonmaur/node-crypto-extra/blob/43f73dd892e1ffcb38e0be4fe387a8da2695c986/src/encryption.js#L83-L93 |
47,079 | mrzmmr/remark-extract-frontmatter | index.js | settings | function settings (options) {
var parsers
var throws
var name
if (options && typeof options === 'function') {
options = { yaml: options }
}
if (options && typeof options === 'object' && !Array.isArray(options)) {
throws = options.throws || false
name = options.name || null
delete options.throws
delete options.name
}
parsers = options
options = {
parsers: parsers,
throws: throws,
name: name
}
return options
} | javascript | function settings (options) {
var parsers
var throws
var name
if (options && typeof options === 'function') {
options = { yaml: options }
}
if (options && typeof options === 'object' && !Array.isArray(options)) {
throws = options.throws || false
name = options.name || null
delete options.throws
delete options.name
}
parsers = options
options = {
parsers: parsers,
throws: throws,
name: name
}
return options
} | [
"function",
"settings",
"(",
"options",
")",
"{",
"var",
"parsers",
"var",
"throws",
"var",
"name",
"if",
"(",
"options",
"&&",
"typeof",
"options",
"===",
"'function'",
")",
"{",
"options",
"=",
"{",
"yaml",
":",
"options",
"}",
"}",
"if",
"(",
"options",
"&&",
"typeof",
"options",
"===",
"'object'",
"&&",
"!",
"Array",
".",
"isArray",
"(",
"options",
")",
")",
"{",
"throws",
"=",
"options",
".",
"throws",
"||",
"false",
"name",
"=",
"options",
".",
"name",
"||",
"null",
"delete",
"options",
".",
"throws",
"delete",
"options",
".",
"name",
"}",
"parsers",
"=",
"options",
"options",
"=",
"{",
"parsers",
":",
"parsers",
",",
"throws",
":",
"throws",
",",
"name",
":",
"name",
"}",
"return",
"options",
"}"
]
| Formats options passed. If options is a function then assume its a yaml
parser. Any keys other than the known options, `name`, `throws` are
assumed to be a parser type and put in `parsers`
options - Object of options, or a function to parse frontmatter
options.throws - Boolean whether to throw when there's an error or not
options.name - The name to store parsed frontmatter as in | [
"Formats",
"options",
"passed",
".",
"If",
"options",
"is",
"a",
"function",
"then",
"assume",
"its",
"a",
"yaml",
"parser",
".",
"Any",
"keys",
"other",
"than",
"the",
"known",
"options",
"name",
"throws",
"are",
"assumed",
"to",
"be",
"a",
"parser",
"type",
"and",
"put",
"in",
"parsers"
]
| be3dcba3b371940bacfba2fe1c8f0b47c3397262 | https://github.com/mrzmmr/remark-extract-frontmatter/blob/be3dcba3b371940bacfba2fe1c8f0b47c3397262/index.js#L156-L180 |
47,080 | IonicaBizau/match.js | lib/index.js | Match | function Match(elm, options, data) {
this.ev = new EventEmitter();
this.data = options.data || data;
this.found = {};
this.timestamps = [];
this.flippedPairs = 0;
// [elm, elm]
this.active = [];
this.options = Ul.deepMerge(options, {
autoremove: true
, size: {
x: 4
, y: 4
}
, classes: {
active: "active"
}
, step: {
x: 43
, y: 43
}
});
this.blocks_count = this.options.size.x * this.options.size.y;
this.count = this.blocks_count / 2;
if (this.blocks_count % 2) {
throw new Error("The number of blocks should be even.");
}
this.ui = {
container: ElmSelect(elm)[0]
, items: []
, template: options.templateElm
? ElmSelect(options.templateElm)[0].outerHTML
: options.template
};
if (!Array.isArray(this.data)) {
throw new Error("Data should be an array.");
}
} | javascript | function Match(elm, options, data) {
this.ev = new EventEmitter();
this.data = options.data || data;
this.found = {};
this.timestamps = [];
this.flippedPairs = 0;
// [elm, elm]
this.active = [];
this.options = Ul.deepMerge(options, {
autoremove: true
, size: {
x: 4
, y: 4
}
, classes: {
active: "active"
}
, step: {
x: 43
, y: 43
}
});
this.blocks_count = this.options.size.x * this.options.size.y;
this.count = this.blocks_count / 2;
if (this.blocks_count % 2) {
throw new Error("The number of blocks should be even.");
}
this.ui = {
container: ElmSelect(elm)[0]
, items: []
, template: options.templateElm
? ElmSelect(options.templateElm)[0].outerHTML
: options.template
};
if (!Array.isArray(this.data)) {
throw new Error("Data should be an array.");
}
} | [
"function",
"Match",
"(",
"elm",
",",
"options",
",",
"data",
")",
"{",
"this",
".",
"ev",
"=",
"new",
"EventEmitter",
"(",
")",
";",
"this",
".",
"data",
"=",
"options",
".",
"data",
"||",
"data",
";",
"this",
".",
"found",
"=",
"{",
"}",
";",
"this",
".",
"timestamps",
"=",
"[",
"]",
";",
"this",
".",
"flippedPairs",
"=",
"0",
";",
"// [elm, elm]",
"this",
".",
"active",
"=",
"[",
"]",
";",
"this",
".",
"options",
"=",
"Ul",
".",
"deepMerge",
"(",
"options",
",",
"{",
"autoremove",
":",
"true",
",",
"size",
":",
"{",
"x",
":",
"4",
",",
"y",
":",
"4",
"}",
",",
"classes",
":",
"{",
"active",
":",
"\"active\"",
"}",
",",
"step",
":",
"{",
"x",
":",
"43",
",",
"y",
":",
"43",
"}",
"}",
")",
";",
"this",
".",
"blocks_count",
"=",
"this",
".",
"options",
".",
"size",
".",
"x",
"*",
"this",
".",
"options",
".",
"size",
".",
"y",
";",
"this",
".",
"count",
"=",
"this",
".",
"blocks_count",
"/",
"2",
";",
"if",
"(",
"this",
".",
"blocks_count",
"%",
"2",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"The number of blocks should be even.\"",
")",
";",
"}",
"this",
".",
"ui",
"=",
"{",
"container",
":",
"ElmSelect",
"(",
"elm",
")",
"[",
"0",
"]",
",",
"items",
":",
"[",
"]",
",",
"template",
":",
"options",
".",
"templateElm",
"?",
"ElmSelect",
"(",
"options",
".",
"templateElm",
")",
"[",
"0",
"]",
".",
"outerHTML",
":",
"options",
".",
"template",
"}",
";",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"this",
".",
"data",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Data should be an array.\"",
")",
";",
"}",
"}"
]
| Match
Creates a new `Match` instance.
Events you can listen to:
- `deactivate` (HTMLElement): Triggered when the block is deactivated.
- `activate` (HTMLElement): Triggered when the block is activated.
- `pair-flip` (HTMLElement, HTMLElement): After a pair flip.
- `success` (HTMLElement, HTMLElement): When a match is found.
- `win` (Number): Emitted when the game is over (the first argument is a
number representing the number of miliseconds from the moment the game
was started to now).
- `render` (currentElement, data, isDuplicate): Emitted on render–the HTML
element can be modified which will end in the editing the HTML. The data
object is the current data object reference. The `isDuplicate` parameter
takes a value of `0` or `1` (when the match is rendered).
- `time` (Number): Like `win`, but emitted every second, during the game.
@name Match
@function
@param {Element|String} elm The HTML element or the query selector.
@param {Object} options An object containing the following fields:
- `autoremove` (Boolean): If `true`, the blocks will be removed when they are matching (default: `true`).
- `size` (Object):
- `x` (Number): How many blocks per row (default: `4`).
- `y` (Number): How many blocks per column (default: `4`).
- `classes` (Object):
- `active` (String): The active class added the active block elements (default: `"active"`).
- `step` (Object):
- `x` (Number): How much should be increased the `x` coordinate for each block.
- `y` (Number): How much should be increased the `y` coordinate for each block.
@param {Array} data Array of objects used in the templating.
@return {Match} The `Match` instance. | [
"Match",
"Creates",
"a",
"new",
"Match",
"instance",
"."
]
| 0910530725dc7bc62fac55df6c371e75f9528112 | https://github.com/IonicaBizau/match.js/blob/0910530725dc7bc62fac55df6c371e75f9528112/lib/index.js#L47-L90 |
47,081 | bevacqua/ponyedit | src/ponyedit.js | fix | function fix (html) {
if (self.options.htmlWrap === false) { return html; }
if (html.substr(0,5) !== '<div>') {
html = '<div>' + html + '</div>';
}
return html;
} | javascript | function fix (html) {
if (self.options.htmlWrap === false) { return html; }
if (html.substr(0,5) !== '<div>') {
html = '<div>' + html + '</div>';
}
return html;
} | [
"function",
"fix",
"(",
"html",
")",
"{",
"if",
"(",
"self",
".",
"options",
".",
"htmlWrap",
"===",
"false",
")",
"{",
"return",
"html",
";",
"}",
"if",
"(",
"html",
".",
"substr",
"(",
"0",
",",
"5",
")",
"!==",
"'<div>'",
")",
"{",
"html",
"=",
"'<div>'",
"+",
"html",
"+",
"'</div>'",
";",
"}",
"return",
"html",
";",
"}"
]
| wrap the HTML in a div. | [
"wrap",
"the",
"HTML",
"in",
"a",
"div",
"."
]
| f142f70c6933686a088d2ed0e361182f56f77dbb | https://github.com/bevacqua/ponyedit/blob/f142f70c6933686a088d2ed0e361182f56f77dbb/src/ponyedit.js#L216-L223 |
47,082 | bevacqua/ponyedit | src/ponyedit.js | report | function report (property, name, parse) {
var rquotes = /^['"]|['"]$/g;
var inspect = queries[property] || query;
return function () {
var self = this;
var value = inspect.call(self, property);
var ev = 'report.' + name;
if (parse === 'bool') {
value = value === 'true' || value === true;
} else if (parse === 'int') {
value = parseInt(value, 10);
} else if (property === 'fontName') {
value = value.replace(rquotes, '');
}
self.emit(ev, value, name);
return value;
};
} | javascript | function report (property, name, parse) {
var rquotes = /^['"]|['"]$/g;
var inspect = queries[property] || query;
return function () {
var self = this;
var value = inspect.call(self, property);
var ev = 'report.' + name;
if (parse === 'bool') {
value = value === 'true' || value === true;
} else if (parse === 'int') {
value = parseInt(value, 10);
} else if (property === 'fontName') {
value = value.replace(rquotes, '');
}
self.emit(ev, value, name);
return value;
};
} | [
"function",
"report",
"(",
"property",
",",
"name",
",",
"parse",
")",
"{",
"var",
"rquotes",
"=",
"/",
"^['\"]|['\"]$",
"/",
"g",
";",
"var",
"inspect",
"=",
"queries",
"[",
"property",
"]",
"||",
"query",
";",
"return",
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"value",
"=",
"inspect",
".",
"call",
"(",
"self",
",",
"property",
")",
";",
"var",
"ev",
"=",
"'report.'",
"+",
"name",
";",
"if",
"(",
"parse",
"===",
"'bool'",
")",
"{",
"value",
"=",
"value",
"===",
"'true'",
"||",
"value",
"===",
"true",
";",
"}",
"else",
"if",
"(",
"parse",
"===",
"'int'",
")",
"{",
"value",
"=",
"parseInt",
"(",
"value",
",",
"10",
")",
";",
"}",
"else",
"if",
"(",
"property",
"===",
"'fontName'",
")",
"{",
"value",
"=",
"value",
".",
"replace",
"(",
"rquotes",
",",
"''",
")",
";",
"}",
"self",
".",
"emit",
"(",
"ev",
",",
"value",
",",
"name",
")",
";",
"return",
"value",
";",
"}",
";",
"}"
]
| property state emission | [
"property",
"state",
"emission"
]
| f142f70c6933686a088d2ed0e361182f56f77dbb | https://github.com/bevacqua/ponyedit/blob/f142f70c6933686a088d2ed0e361182f56f77dbb/src/ponyedit.js#L526-L546 |
47,083 | Saunalol/cssbeautify-cli | lib/cssbeautify-cli.js | isValid | function isValid(name, value) {
var tests = {
indent: function (value) {
return (/^(\s*|\d*)$/).test(value);
},
openbrace: function (value) {
return (['end-of-line', 'separate-line']).indexOf(value) !== -1;
},
autosemicolon: function (value) {
return typeof value === 'boolean';
}
};
return Boolean(tests[name] && tests[name](value));
} | javascript | function isValid(name, value) {
var tests = {
indent: function (value) {
return (/^(\s*|\d*)$/).test(value);
},
openbrace: function (value) {
return (['end-of-line', 'separate-line']).indexOf(value) !== -1;
},
autosemicolon: function (value) {
return typeof value === 'boolean';
}
};
return Boolean(tests[name] && tests[name](value));
} | [
"function",
"isValid",
"(",
"name",
",",
"value",
")",
"{",
"var",
"tests",
"=",
"{",
"indent",
":",
"function",
"(",
"value",
")",
"{",
"return",
"(",
"/",
"^(\\s*|\\d*)$",
"/",
")",
".",
"test",
"(",
"value",
")",
";",
"}",
",",
"openbrace",
":",
"function",
"(",
"value",
")",
"{",
"return",
"(",
"[",
"'end-of-line'",
",",
"'separate-line'",
"]",
")",
".",
"indexOf",
"(",
"value",
")",
"!==",
"-",
"1",
";",
"}",
",",
"autosemicolon",
":",
"function",
"(",
"value",
")",
"{",
"return",
"typeof",
"value",
"===",
"'boolean'",
";",
"}",
"}",
";",
"return",
"Boolean",
"(",
"tests",
"[",
"name",
"]",
"&&",
"tests",
"[",
"name",
"]",
"(",
"value",
")",
")",
";",
"}"
]
| Checks parameter validity
@param {string} name
@param {string} value
@return {Boolean} | [
"Checks",
"parameter",
"validity"
]
| 6ecc56073659e82386ed855b02be9ceb2c44340e | https://github.com/Saunalol/cssbeautify-cli/blob/6ecc56073659e82386ed855b02be9ceb2c44340e/lib/cssbeautify-cli.js#L115-L129 |
47,084 | SilentCicero/ethdeploy | src/plugins/index.js | JSONMinifier | function JSONMinifier() {
const self = this;
self.process = ({ output }) => JSON.stringify(JSON.parse(output));
} | javascript | function JSONMinifier() {
const self = this;
self.process = ({ output }) => JSON.stringify(JSON.parse(output));
} | [
"function",
"JSONMinifier",
"(",
")",
"{",
"const",
"self",
"=",
"this",
";",
"self",
".",
"process",
"=",
"(",
"{",
"output",
"}",
")",
"=>",
"JSON",
".",
"stringify",
"(",
"JSON",
".",
"parse",
"(",
"output",
")",
")",
";",
"}"
]
| Minifies JSON output
@method JSONMinifier
@param {String} output the final build file produced by ethdeploy
@return {String} parsedOutput parsed output | [
"Minifies",
"JSON",
"output"
]
| acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6 | https://github.com/SilentCicero/ethdeploy/blob/acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6/src/plugins/index.js#L8-L11 |
47,085 | SilentCicero/ethdeploy | src/plugins/index.js | JSONExpander | function JSONExpander() {
const self = this;
self.process = ({ output }) => JSON.stringify(JSON.parse(output), null, 2);
} | javascript | function JSONExpander() {
const self = this;
self.process = ({ output }) => JSON.stringify(JSON.parse(output), null, 2);
} | [
"function",
"JSONExpander",
"(",
")",
"{",
"const",
"self",
"=",
"this",
";",
"self",
".",
"process",
"=",
"(",
"{",
"output",
"}",
")",
"=>",
"JSON",
".",
"stringify",
"(",
"JSON",
".",
"parse",
"(",
"output",
")",
",",
"null",
",",
"2",
")",
";",
"}"
]
| Expands JSON output
@method JSONMinifier
@param {String} output the final build file produced by ethdeploy with indents
@return {String} parsedOutput parsed output | [
"Expands",
"JSON",
"output"
]
| acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6 | https://github.com/SilentCicero/ethdeploy/blob/acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6/src/plugins/index.js#L20-L23 |
47,086 | SilentCicero/ethdeploy | src/plugins/index.js | keyFilter | function keyFilter(obj, predicate) {
var result = {}, key; // eslint-disable-line
for (key in obj) { // eslint-disable-line
if (obj[key] && predicate(key)) {
result[key] = obj[key];
}
}
return result;
} | javascript | function keyFilter(obj, predicate) {
var result = {}, key; // eslint-disable-line
for (key in obj) { // eslint-disable-line
if (obj[key] && predicate(key)) {
result[key] = obj[key];
}
}
return result;
} | [
"function",
"keyFilter",
"(",
"obj",
",",
"predicate",
")",
"{",
"var",
"result",
"=",
"{",
"}",
",",
"key",
";",
"// eslint-disable-line",
"for",
"(",
"key",
"in",
"obj",
")",
"{",
"// eslint-disable-line",
"if",
"(",
"obj",
"[",
"key",
"]",
"&&",
"predicate",
"(",
"key",
")",
")",
"{",
"result",
"[",
"key",
"]",
"=",
"obj",
"[",
"key",
"]",
";",
"}",
"}",
"return",
"result",
";",
"}"
]
| a basic util filter function | [
"a",
"basic",
"util",
"filter",
"function"
]
| acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6 | https://github.com/SilentCicero/ethdeploy/blob/acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6/src/plugins/index.js#L26-L36 |
47,087 | SilentCicero/ethdeploy | src/plugins/index.js | IncludeContracts | function IncludeContracts(
contractsSelector,
propertyFilter = ['interface', 'bytecode'],
environmentName = 'contracts') {
const self = this;
self.process = ({ output, contracts }) => {
// parse output
const parsedOutput = JSON.parse(output);
// add contracts environment
parsedOutput[environmentName] = Object.assign({});
// go through selected contracts
contractsSelector.forEach((contractName) => {
// if the contracts object has the selectedcontract
// include it
if ((contracts || {})[contractName]) {
const contractObject = Object.assign({}, contracts[contractName]);
// include contract data in environments output with property filter
parsedOutput[environmentName][contractName] = propertyFilter ? keyFilter(contractObject, (key => propertyFilter.indexOf(key) !== -1)) : contractObject;
}
});
return JSON.stringify(parsedOutput);
};
} | javascript | function IncludeContracts(
contractsSelector,
propertyFilter = ['interface', 'bytecode'],
environmentName = 'contracts') {
const self = this;
self.process = ({ output, contracts }) => {
// parse output
const parsedOutput = JSON.parse(output);
// add contracts environment
parsedOutput[environmentName] = Object.assign({});
// go through selected contracts
contractsSelector.forEach((contractName) => {
// if the contracts object has the selectedcontract
// include it
if ((contracts || {})[contractName]) {
const contractObject = Object.assign({}, contracts[contractName]);
// include contract data in environments output with property filter
parsedOutput[environmentName][contractName] = propertyFilter ? keyFilter(contractObject, (key => propertyFilter.indexOf(key) !== -1)) : contractObject;
}
});
return JSON.stringify(parsedOutput);
};
} | [
"function",
"IncludeContracts",
"(",
"contractsSelector",
",",
"propertyFilter",
"=",
"[",
"'interface'",
",",
"'bytecode'",
"]",
",",
"environmentName",
"=",
"'contracts'",
")",
"{",
"const",
"self",
"=",
"this",
";",
"self",
".",
"process",
"=",
"(",
"{",
"output",
",",
"contracts",
"}",
")",
"=>",
"{",
"// parse output",
"const",
"parsedOutput",
"=",
"JSON",
".",
"parse",
"(",
"output",
")",
";",
"// add contracts environment",
"parsedOutput",
"[",
"environmentName",
"]",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
")",
";",
"// go through selected contracts",
"contractsSelector",
".",
"forEach",
"(",
"(",
"contractName",
")",
"=>",
"{",
"// if the contracts object has the selectedcontract",
"// include it",
"if",
"(",
"(",
"contracts",
"||",
"{",
"}",
")",
"[",
"contractName",
"]",
")",
"{",
"const",
"contractObject",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"contracts",
"[",
"contractName",
"]",
")",
";",
"// include contract data in environments output with property filter",
"parsedOutput",
"[",
"environmentName",
"]",
"[",
"contractName",
"]",
"=",
"propertyFilter",
"?",
"keyFilter",
"(",
"contractObject",
",",
"(",
"key",
"=>",
"propertyFilter",
".",
"indexOf",
"(",
"key",
")",
"!==",
"-",
"1",
")",
")",
":",
"contractObject",
";",
"}",
"}",
")",
";",
"return",
"JSON",
".",
"stringify",
"(",
"parsedOutput",
")",
";",
"}",
";",
"}"
]
| This wil include contracts data in the environments output
@method IncludeContracts
@param {Array} contractsSelector contracts to include in a contracts property
@param {Array} propertyFilter if fiter is not truthy, then ignore filtering
@param {String} environmentName environment name is usually contracts
@return {String} parsedOutput parsed output | [
"This",
"wil",
"include",
"contracts",
"data",
"in",
"the",
"environments",
"output"
]
| acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6 | https://github.com/SilentCicero/ethdeploy/blob/acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6/src/plugins/index.js#L47-L73 |
47,088 | magne4000/node-libquassel | src/request.js | sync | function sync(className, functionName, ...datatypes) {
const qsync = qtypes.QInt.from(Types.SYNC);
const qclassName = qtypes.QByteArray.from(className);
const qfunctionName = qtypes.QByteArray.from(functionName);
return function(target, _key, descriptor) {
return {
enumerable: false,
configurable: false,
writable: false,
value: function(...args) {
const [ id, ...data ] = descriptor.value.apply(this, args);
this.qtsocket.write([
qsync,
qclassName,
qtypes.QByteArray.from(id),
qfunctionName,
...data.map((value, index) => datatypes[index].from(value))
]);
}
};
};
} | javascript | function sync(className, functionName, ...datatypes) {
const qsync = qtypes.QInt.from(Types.SYNC);
const qclassName = qtypes.QByteArray.from(className);
const qfunctionName = qtypes.QByteArray.from(functionName);
return function(target, _key, descriptor) {
return {
enumerable: false,
configurable: false,
writable: false,
value: function(...args) {
const [ id, ...data ] = descriptor.value.apply(this, args);
this.qtsocket.write([
qsync,
qclassName,
qtypes.QByteArray.from(id),
qfunctionName,
...data.map((value, index) => datatypes[index].from(value))
]);
}
};
};
} | [
"function",
"sync",
"(",
"className",
",",
"functionName",
",",
"...",
"datatypes",
")",
"{",
"const",
"qsync",
"=",
"qtypes",
".",
"QInt",
".",
"from",
"(",
"Types",
".",
"SYNC",
")",
";",
"const",
"qclassName",
"=",
"qtypes",
".",
"QByteArray",
".",
"from",
"(",
"className",
")",
";",
"const",
"qfunctionName",
"=",
"qtypes",
".",
"QByteArray",
".",
"from",
"(",
"functionName",
")",
";",
"return",
"function",
"(",
"target",
",",
"_key",
",",
"descriptor",
")",
"{",
"return",
"{",
"enumerable",
":",
"false",
",",
"configurable",
":",
"false",
",",
"writable",
":",
"false",
",",
"value",
":",
"function",
"(",
"...",
"args",
")",
"{",
"const",
"[",
"id",
",",
"...",
"data",
"]",
"=",
"descriptor",
".",
"value",
".",
"apply",
"(",
"this",
",",
"args",
")",
";",
"this",
".",
"qtsocket",
".",
"write",
"(",
"[",
"qsync",
",",
"qclassName",
",",
"qtypes",
".",
"QByteArray",
".",
"from",
"(",
"id",
")",
",",
"qfunctionName",
",",
"...",
"data",
".",
"map",
"(",
"(",
"value",
",",
"index",
")",
"=>",
"datatypes",
"[",
"index",
"]",
".",
"from",
"(",
"value",
")",
")",
"]",
")",
";",
"}",
"}",
";",
"}",
";",
"}"
]
| Decorator for SYNC methods
@protected | [
"Decorator",
"for",
"SYNC",
"methods"
]
| 0cf97378ebe170b0abf4bdcc112933009a84156f | https://github.com/magne4000/node-libquassel/blob/0cf97378ebe170b0abf4bdcc112933009a84156f/src/request.js#L40-L61 |
47,089 | magne4000/node-libquassel | src/request.js | rpc | function rpc(functionName, ...datatypes) {
const qrpc = qtypes.QInt.from(Types.RPCCALL);
const qfunctionName = qtypes.QByteArray.from(`2${functionName}`);
return function(target, _key, descriptor) {
return {
enumerable: false,
configurable: false,
writable: false,
value: function(...args) {
const data = descriptor.value.apply(this, args);
this.qtsocket.write([
qrpc,
qfunctionName,
...data.map((value, index) => datatypes[index].from(value))
]);
}
};
};
} | javascript | function rpc(functionName, ...datatypes) {
const qrpc = qtypes.QInt.from(Types.RPCCALL);
const qfunctionName = qtypes.QByteArray.from(`2${functionName}`);
return function(target, _key, descriptor) {
return {
enumerable: false,
configurable: false,
writable: false,
value: function(...args) {
const data = descriptor.value.apply(this, args);
this.qtsocket.write([
qrpc,
qfunctionName,
...data.map((value, index) => datatypes[index].from(value))
]);
}
};
};
} | [
"function",
"rpc",
"(",
"functionName",
",",
"...",
"datatypes",
")",
"{",
"const",
"qrpc",
"=",
"qtypes",
".",
"QInt",
".",
"from",
"(",
"Types",
".",
"RPCCALL",
")",
";",
"const",
"qfunctionName",
"=",
"qtypes",
".",
"QByteArray",
".",
"from",
"(",
"`",
"${",
"functionName",
"}",
"`",
")",
";",
"return",
"function",
"(",
"target",
",",
"_key",
",",
"descriptor",
")",
"{",
"return",
"{",
"enumerable",
":",
"false",
",",
"configurable",
":",
"false",
",",
"writable",
":",
"false",
",",
"value",
":",
"function",
"(",
"...",
"args",
")",
"{",
"const",
"data",
"=",
"descriptor",
".",
"value",
".",
"apply",
"(",
"this",
",",
"args",
")",
";",
"this",
".",
"qtsocket",
".",
"write",
"(",
"[",
"qrpc",
",",
"qfunctionName",
",",
"...",
"data",
".",
"map",
"(",
"(",
"value",
",",
"index",
")",
"=>",
"datatypes",
"[",
"index",
"]",
".",
"from",
"(",
"value",
")",
")",
"]",
")",
";",
"}",
"}",
";",
"}",
";",
"}"
]
| Decorator for RPC methods
@protected | [
"Decorator",
"for",
"RPC",
"methods"
]
| 0cf97378ebe170b0abf4bdcc112933009a84156f | https://github.com/magne4000/node-libquassel/blob/0cf97378ebe170b0abf4bdcc112933009a84156f/src/request.js#L67-L85 |
47,090 | dpjanes/iotdb-homestar | static/flat-ui/js/flat-ui.js | simulateMouseEvent | function simulateMouseEvent (event, simulatedType) {
// Ignore multi-touch events
if (event.originalEvent.touches.length > 1) {
return;
}
event.preventDefault();
var touch = event.originalEvent.changedTouches[0],
simulatedEvent = document.createEvent('MouseEvents');
// Initialize the simulated mouse event using the touch event's coordinates
simulatedEvent.initMouseEvent(
simulatedType, // type
true, // bubbles
true, // cancelable
window, // view
1, // detail
touch.screenX, // screenX
touch.screenY, // screenY
touch.clientX, // clientX
touch.clientY, // clientY
false, // ctrlKey
false, // altKey
false, // shiftKey
false, // metaKey
0, // button
null // relatedTarget
);
// Dispatch the simulated event to the target element
event.target.dispatchEvent(simulatedEvent);
} | javascript | function simulateMouseEvent (event, simulatedType) {
// Ignore multi-touch events
if (event.originalEvent.touches.length > 1) {
return;
}
event.preventDefault();
var touch = event.originalEvent.changedTouches[0],
simulatedEvent = document.createEvent('MouseEvents');
// Initialize the simulated mouse event using the touch event's coordinates
simulatedEvent.initMouseEvent(
simulatedType, // type
true, // bubbles
true, // cancelable
window, // view
1, // detail
touch.screenX, // screenX
touch.screenY, // screenY
touch.clientX, // clientX
touch.clientY, // clientY
false, // ctrlKey
false, // altKey
false, // shiftKey
false, // metaKey
0, // button
null // relatedTarget
);
// Dispatch the simulated event to the target element
event.target.dispatchEvent(simulatedEvent);
} | [
"function",
"simulateMouseEvent",
"(",
"event",
",",
"simulatedType",
")",
"{",
"// Ignore multi-touch events\r",
"if",
"(",
"event",
".",
"originalEvent",
".",
"touches",
".",
"length",
">",
"1",
")",
"{",
"return",
";",
"}",
"event",
".",
"preventDefault",
"(",
")",
";",
"var",
"touch",
"=",
"event",
".",
"originalEvent",
".",
"changedTouches",
"[",
"0",
"]",
",",
"simulatedEvent",
"=",
"document",
".",
"createEvent",
"(",
"'MouseEvents'",
")",
";",
"// Initialize the simulated mouse event using the touch event's coordinates\r",
"simulatedEvent",
".",
"initMouseEvent",
"(",
"simulatedType",
",",
"// type\r",
"true",
",",
"// bubbles \r",
"true",
",",
"// cancelable \r",
"window",
",",
"// view \r",
"1",
",",
"// detail \r",
"touch",
".",
"screenX",
",",
"// screenX \r",
"touch",
".",
"screenY",
",",
"// screenY \r",
"touch",
".",
"clientX",
",",
"// clientX \r",
"touch",
".",
"clientY",
",",
"// clientY \r",
"false",
",",
"// ctrlKey \r",
"false",
",",
"// altKey \r",
"false",
",",
"// shiftKey \r",
"false",
",",
"// metaKey \r",
"0",
",",
"// button \r",
"null",
"// relatedTarget \r",
")",
";",
"// Dispatch the simulated event to the target element\r",
"event",
".",
"target",
".",
"dispatchEvent",
"(",
"simulatedEvent",
")",
";",
"}"
]
| Simulate a mouse event based on a corresponding touch event
@param {Object} event A touch event
@param {String} simulatedType The corresponding mouse event | [
"Simulate",
"a",
"mouse",
"event",
"based",
"on",
"a",
"corresponding",
"touch",
"event"
]
| ed6535aa17c8b0538f43a876c9a6025e26a389e3 | https://github.com/dpjanes/iotdb-homestar/blob/ed6535aa17c8b0538f43a876c9a6025e26a389e3/static/flat-ui/js/flat-ui.js#L3912-L3945 |
47,091 | dpjanes/iotdb-homestar | static/flat-ui/js/flat-ui.js | evaluate | function evaluate(val, context) {
if ($.isFunction(val)) {
var args = Array.prototype.slice.call(arguments, 2);
return val.apply(context, args);
}
return val;
} | javascript | function evaluate(val, context) {
if ($.isFunction(val)) {
var args = Array.prototype.slice.call(arguments, 2);
return val.apply(context, args);
}
return val;
} | [
"function",
"evaluate",
"(",
"val",
",",
"context",
")",
"{",
"if",
"(",
"$",
".",
"isFunction",
"(",
"val",
")",
")",
"{",
"var",
"args",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"2",
")",
";",
"return",
"val",
".",
"apply",
"(",
"context",
",",
"args",
")",
";",
"}",
"return",
"val",
";",
"}"
]
| Returns a given value
If given a function, returns its output
@param val string|function
@param context value of "this" to be passed to function
@returns {*} | [
"Returns",
"a",
"given",
"value",
"If",
"given",
"a",
"function",
"returns",
"its",
"output"
]
| ed6535aa17c8b0538f43a876c9a6025e26a389e3 | https://github.com/dpjanes/iotdb-homestar/blob/ed6535aa17c8b0538f43a876c9a6025e26a389e3/static/flat-ui/js/flat-ui.js#L9680-L9686 |
47,092 | dpjanes/iotdb-homestar | static/flat-ui/js/flat-ui.js | function (details) {
details = details || {};
details= $.extend({}, details, { type: "change", val: this.val() });
// prevents recursive triggering
this.opts.element.data("select2-change-triggered", true);
this.opts.element.trigger(details);
this.opts.element.data("select2-change-triggered", false);
// some validation frameworks ignore the change event and listen instead to keyup, click for selects
// so here we trigger the click event manually
this.opts.element.click();
// ValidationEngine ignores the change event and listens instead to blur
// so here we trigger the blur event manually if so desired
if (this.opts.blurOnChange)
this.opts.element.blur();
} | javascript | function (details) {
details = details || {};
details= $.extend({}, details, { type: "change", val: this.val() });
// prevents recursive triggering
this.opts.element.data("select2-change-triggered", true);
this.opts.element.trigger(details);
this.opts.element.data("select2-change-triggered", false);
// some validation frameworks ignore the change event and listen instead to keyup, click for selects
// so here we trigger the click event manually
this.opts.element.click();
// ValidationEngine ignores the change event and listens instead to blur
// so here we trigger the blur event manually if so desired
if (this.opts.blurOnChange)
this.opts.element.blur();
} | [
"function",
"(",
"details",
")",
"{",
"details",
"=",
"details",
"||",
"{",
"}",
";",
"details",
"=",
"$",
".",
"extend",
"(",
"{",
"}",
",",
"details",
",",
"{",
"type",
":",
"\"change\"",
",",
"val",
":",
"this",
".",
"val",
"(",
")",
"}",
")",
";",
"// prevents recursive triggering",
"this",
".",
"opts",
".",
"element",
".",
"data",
"(",
"\"select2-change-triggered\"",
",",
"true",
")",
";",
"this",
".",
"opts",
".",
"element",
".",
"trigger",
"(",
"details",
")",
";",
"this",
".",
"opts",
".",
"element",
".",
"data",
"(",
"\"select2-change-triggered\"",
",",
"false",
")",
";",
"// some validation frameworks ignore the change event and listen instead to keyup, click for selects",
"// so here we trigger the click event manually",
"this",
".",
"opts",
".",
"element",
".",
"click",
"(",
")",
";",
"// ValidationEngine ignores the change event and listens instead to blur",
"// so here we trigger the blur event manually if so desired",
"if",
"(",
"this",
".",
"opts",
".",
"blurOnChange",
")",
"this",
".",
"opts",
".",
"element",
".",
"blur",
"(",
")",
";",
"}"
]
| Triggers the change event on the source element
abstract | [
"Triggers",
"the",
"change",
"event",
"on",
"the",
"source",
"element",
"abstract"
]
| ed6535aa17c8b0538f43a876c9a6025e26a389e3 | https://github.com/dpjanes/iotdb-homestar/blob/ed6535aa17c8b0538f43a876c9a6025e26a389e3/static/flat-ui/js/flat-ui.js#L10255-L10272 |
|
47,093 | dpjanes/iotdb-homestar | static/flat-ui/js/flat-ui.js | function () {
if (!this.shouldOpen()) return false;
this.opening();
// Only bind the document mousemove when the dropdown is visible
$document.on("mousemove.select2Event", function (e) {
lastMousePosition.x = e.pageX;
lastMousePosition.y = e.pageY;
});
return true;
} | javascript | function () {
if (!this.shouldOpen()) return false;
this.opening();
// Only bind the document mousemove when the dropdown is visible
$document.on("mousemove.select2Event", function (e) {
lastMousePosition.x = e.pageX;
lastMousePosition.y = e.pageY;
});
return true;
} | [
"function",
"(",
")",
"{",
"if",
"(",
"!",
"this",
".",
"shouldOpen",
"(",
")",
")",
"return",
"false",
";",
"this",
".",
"opening",
"(",
")",
";",
"// Only bind the document mousemove when the dropdown is visible",
"$document",
".",
"on",
"(",
"\"mousemove.select2Event\"",
",",
"function",
"(",
"e",
")",
"{",
"lastMousePosition",
".",
"x",
"=",
"e",
".",
"pageX",
";",
"lastMousePosition",
".",
"y",
"=",
"e",
".",
"pageY",
";",
"}",
")",
";",
"return",
"true",
";",
"}"
]
| Opens the dropdown
@return {Boolean} whether or not dropdown was opened. This method will return false if, for example,
the dropdown is already open, or if the 'open' event listener on the element called preventDefault().
abstract | [
"Opens",
"the",
"dropdown"
]
| ed6535aa17c8b0538f43a876c9a6025e26a389e3 | https://github.com/dpjanes/iotdb-homestar/blob/ed6535aa17c8b0538f43a876c9a6025e26a389e3/static/flat-ui/js/flat-ui.js#L10460-L10473 |
|
47,094 | dpjanes/iotdb-homestar | static/flat-ui/js/flat-ui.js | function () {
var selected;
if (this.isPlaceholderOptionSelected()) {
this.updateSelection(null);
this.close();
this.setPlaceholder();
} else {
var self = this;
this.opts.initSelection.call(null, this.opts.element, function(selected){
if (selected !== undefined && selected !== null) {
self.updateSelection(selected);
self.close();
self.setPlaceholder();
self.nextSearchTerm = self.opts.nextSearchTerm(selected, self.search.val());
}
});
}
} | javascript | function () {
var selected;
if (this.isPlaceholderOptionSelected()) {
this.updateSelection(null);
this.close();
this.setPlaceholder();
} else {
var self = this;
this.opts.initSelection.call(null, this.opts.element, function(selected){
if (selected !== undefined && selected !== null) {
self.updateSelection(selected);
self.close();
self.setPlaceholder();
self.nextSearchTerm = self.opts.nextSearchTerm(selected, self.search.val());
}
});
}
} | [
"function",
"(",
")",
"{",
"var",
"selected",
";",
"if",
"(",
"this",
".",
"isPlaceholderOptionSelected",
"(",
")",
")",
"{",
"this",
".",
"updateSelection",
"(",
"null",
")",
";",
"this",
".",
"close",
"(",
")",
";",
"this",
".",
"setPlaceholder",
"(",
")",
";",
"}",
"else",
"{",
"var",
"self",
"=",
"this",
";",
"this",
".",
"opts",
".",
"initSelection",
".",
"call",
"(",
"null",
",",
"this",
".",
"opts",
".",
"element",
",",
"function",
"(",
"selected",
")",
"{",
"if",
"(",
"selected",
"!==",
"undefined",
"&&",
"selected",
"!==",
"null",
")",
"{",
"self",
".",
"updateSelection",
"(",
"selected",
")",
";",
"self",
".",
"close",
"(",
")",
";",
"self",
".",
"setPlaceholder",
"(",
")",
";",
"self",
".",
"nextSearchTerm",
"=",
"self",
".",
"opts",
".",
"nextSearchTerm",
"(",
"selected",
",",
"self",
".",
"search",
".",
"val",
"(",
")",
")",
";",
"}",
"}",
")",
";",
"}",
"}"
]
| Sets selection based on source element's value
single | [
"Sets",
"selection",
"based",
"on",
"source",
"element",
"s",
"value",
"single"
]
| ed6535aa17c8b0538f43a876c9a6025e26a389e3 | https://github.com/dpjanes/iotdb-homestar/blob/ed6535aa17c8b0538f43a876c9a6025e26a389e3/static/flat-ui/js/flat-ui.js#L11389-L11406 |
|
47,095 | SilentCicero/ethdeploy | src/utils/index.js | bnToString | function bnToString(objInput, baseInput, hexPrefixed) {
var obj = objInput; // eslint-disable-line
const base = baseInput || 10;
// obj is an array
if (typeof obj === 'object' && obj !== null) {
if (Array.isArray(obj)) {
// convert items in array
obj = obj.map((item) => bnToString(item, base, hexPrefixed));
} else {
if (obj.toString && (obj.lessThan || obj.dividedToIntegerBy || obj.isBN || obj.toTwos)) {
return hexPrefixed ? `0x${ethUtil.padToEven(obj.toString(16))}` : obj.toString(base);
} else { // eslint-disable-line
// recurively converty item
Object.keys(obj).forEach((key) => {
obj[key] = bnToString(obj[key], base, hexPrefixed);
});
}
}
}
return obj;
} | javascript | function bnToString(objInput, baseInput, hexPrefixed) {
var obj = objInput; // eslint-disable-line
const base = baseInput || 10;
// obj is an array
if (typeof obj === 'object' && obj !== null) {
if (Array.isArray(obj)) {
// convert items in array
obj = obj.map((item) => bnToString(item, base, hexPrefixed));
} else {
if (obj.toString && (obj.lessThan || obj.dividedToIntegerBy || obj.isBN || obj.toTwos)) {
return hexPrefixed ? `0x${ethUtil.padToEven(obj.toString(16))}` : obj.toString(base);
} else { // eslint-disable-line
// recurively converty item
Object.keys(obj).forEach((key) => {
obj[key] = bnToString(obj[key], base, hexPrefixed);
});
}
}
}
return obj;
} | [
"function",
"bnToString",
"(",
"objInput",
",",
"baseInput",
",",
"hexPrefixed",
")",
"{",
"var",
"obj",
"=",
"objInput",
";",
"// eslint-disable-line",
"const",
"base",
"=",
"baseInput",
"||",
"10",
";",
"// obj is an array",
"if",
"(",
"typeof",
"obj",
"===",
"'object'",
"&&",
"obj",
"!==",
"null",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"obj",
")",
")",
"{",
"// convert items in array",
"obj",
"=",
"obj",
".",
"map",
"(",
"(",
"item",
")",
"=>",
"bnToString",
"(",
"item",
",",
"base",
",",
"hexPrefixed",
")",
")",
";",
"}",
"else",
"{",
"if",
"(",
"obj",
".",
"toString",
"&&",
"(",
"obj",
".",
"lessThan",
"||",
"obj",
".",
"dividedToIntegerBy",
"||",
"obj",
".",
"isBN",
"||",
"obj",
".",
"toTwos",
")",
")",
"{",
"return",
"hexPrefixed",
"?",
"`",
"${",
"ethUtil",
".",
"padToEven",
"(",
"obj",
".",
"toString",
"(",
"16",
")",
")",
"}",
"`",
":",
"obj",
".",
"toString",
"(",
"base",
")",
";",
"}",
"else",
"{",
"// eslint-disable-line",
"// recurively converty item",
"Object",
".",
"keys",
"(",
"obj",
")",
".",
"forEach",
"(",
"(",
"key",
")",
"=>",
"{",
"obj",
"[",
"key",
"]",
"=",
"bnToString",
"(",
"obj",
"[",
"key",
"]",
",",
"base",
",",
"hexPrefixed",
")",
";",
"}",
")",
";",
"}",
"}",
"}",
"return",
"obj",
";",
"}"
]
| recursively converts all BN or BigNumber instances into string
Converts all BigNumber and BN instances to string, even nested deep in Arrays or Objects.
@method bnToString
@param {Optional} objInput optional input type, bypasses most
@param {Number} baseInput the base number (usually either 10 or 16).
@param {Boolean} hexPrefixed hex prefix the output
@return {Optional} output returns optional type output with converted bn's. | [
"recursively",
"converts",
"all",
"BN",
"or",
"BigNumber",
"instances",
"into",
"string",
"Converts",
"all",
"BigNumber",
"and",
"BN",
"instances",
"to",
"string",
"even",
"nested",
"deep",
"in",
"Arrays",
"or",
"Objects",
"."
]
| acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6 | https://github.com/SilentCicero/ethdeploy/blob/acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6/src/utils/index.js#L49-L71 |
47,096 | SilentCicero/ethdeploy | src/utils/index.js | filterSourceMap | function filterSourceMap(testRegex, includeRegex, sourceMap, excludeRegex) {
const outputData = Object.assign({});
const testTestRegex = testRegex || /./g;
const testIncludeRegex = includeRegex || null;
const testExcludeRegex = excludeRegex || null;
if (typeof testTestRegex !== 'object') { throw error(`while filtering source map, ${JSON.stringify(sourceMap)}, test regex must be type object, got ${typeof testRegex}.`); }
if (typeof testIncludeRegex !== 'object') { throw error(`while filtering source map, ${JSON.stringify(sourceMap)}, include regex must be type object, got ${typeof testIncludeRegex}.`); }
if (typeof testExcludeRegex !== 'object') { throw error(`while filtering source map, ${JSON.stringify(sourceMap)}, exclude regex must be type object, got ${typeof testExcludeRegex}.`); }
Object.keys(sourceMap).forEach((key) => {
if (testTestRegex.test(key)
&& (testIncludeRegex === null || testIncludeRegex.test(key))
&& (testExcludeRegex === null || !testExcludeRegex.test(key))) {
Object.assign(outputData, { [key]: sourceMap[key] });
}
});
return outputData;
} | javascript | function filterSourceMap(testRegex, includeRegex, sourceMap, excludeRegex) {
const outputData = Object.assign({});
const testTestRegex = testRegex || /./g;
const testIncludeRegex = includeRegex || null;
const testExcludeRegex = excludeRegex || null;
if (typeof testTestRegex !== 'object') { throw error(`while filtering source map, ${JSON.stringify(sourceMap)}, test regex must be type object, got ${typeof testRegex}.`); }
if (typeof testIncludeRegex !== 'object') { throw error(`while filtering source map, ${JSON.stringify(sourceMap)}, include regex must be type object, got ${typeof testIncludeRegex}.`); }
if (typeof testExcludeRegex !== 'object') { throw error(`while filtering source map, ${JSON.stringify(sourceMap)}, exclude regex must be type object, got ${typeof testExcludeRegex}.`); }
Object.keys(sourceMap).forEach((key) => {
if (testTestRegex.test(key)
&& (testIncludeRegex === null || testIncludeRegex.test(key))
&& (testExcludeRegex === null || !testExcludeRegex.test(key))) {
Object.assign(outputData, { [key]: sourceMap[key] });
}
});
return outputData;
} | [
"function",
"filterSourceMap",
"(",
"testRegex",
",",
"includeRegex",
",",
"sourceMap",
",",
"excludeRegex",
")",
"{",
"const",
"outputData",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
")",
";",
"const",
"testTestRegex",
"=",
"testRegex",
"||",
"/",
".",
"/",
"g",
";",
"const",
"testIncludeRegex",
"=",
"includeRegex",
"||",
"null",
";",
"const",
"testExcludeRegex",
"=",
"excludeRegex",
"||",
"null",
";",
"if",
"(",
"typeof",
"testTestRegex",
"!==",
"'object'",
")",
"{",
"throw",
"error",
"(",
"`",
"${",
"JSON",
".",
"stringify",
"(",
"sourceMap",
")",
"}",
"${",
"typeof",
"testRegex",
"}",
"`",
")",
";",
"}",
"if",
"(",
"typeof",
"testIncludeRegex",
"!==",
"'object'",
")",
"{",
"throw",
"error",
"(",
"`",
"${",
"JSON",
".",
"stringify",
"(",
"sourceMap",
")",
"}",
"${",
"typeof",
"testIncludeRegex",
"}",
"`",
")",
";",
"}",
"if",
"(",
"typeof",
"testExcludeRegex",
"!==",
"'object'",
")",
"{",
"throw",
"error",
"(",
"`",
"${",
"JSON",
".",
"stringify",
"(",
"sourceMap",
")",
"}",
"${",
"typeof",
"testExcludeRegex",
"}",
"`",
")",
";",
"}",
"Object",
".",
"keys",
"(",
"sourceMap",
")",
".",
"forEach",
"(",
"(",
"key",
")",
"=>",
"{",
"if",
"(",
"testTestRegex",
".",
"test",
"(",
"key",
")",
"&&",
"(",
"testIncludeRegex",
"===",
"null",
"||",
"testIncludeRegex",
".",
"test",
"(",
"key",
")",
")",
"&&",
"(",
"testExcludeRegex",
"===",
"null",
"||",
"!",
"testExcludeRegex",
".",
"test",
"(",
"key",
")",
")",
")",
"{",
"Object",
".",
"assign",
"(",
"outputData",
",",
"{",
"[",
"key",
"]",
":",
"sourceMap",
"[",
"key",
"]",
"}",
")",
";",
"}",
"}",
")",
";",
"return",
"outputData",
";",
"}"
]
| Filters a given sourcemap by specific test regex's.
@method filterSourceMap
@param {Regex} testRegex the test regex (only include these files)
@param {Regex} includeRegex the include test regex (only include these files)
@param {Object} sourceMap the complete file sourcemap
@return {Object} filteredSourceMap the filtered sourcemap
/*
function filterSourceMap(testRegex, includeRegex, sourceMap, excludeRegex) {
const outputData = Object.assign({});
const testTestRegex = testRegex || /./g;
const testIncludeRegex = includeRegex || /./g;
const testExcludeRegex = excludeRegex || null;
if (typeof testTestRegex !== 'object') { throw error(`while filtering source map, ${JSON.stringify(sourceMap)}, test regex must be type object, got ${typeof testRegex}.`); }
if (typeof testIncludeRegex !== 'object') { throw error(`while filtering source map, ${JSON.stringify(sourceMap)}, include regex must be type object, got ${typeof testIncludeRegex}.`); }
if (typeof testExcludeRegex !== 'object') { throw error(`while filtering source map, ${JSON.stringify(sourceMap)}, exclude regex must be type object, got ${typeof testExcludeRegex}.`); }
Object.keys(sourceMap).forEach((key) => {
if (testTestRegex.test(key) && testIncludeRegex.test(key) && (testExcludeRegex === null || !testExcludeRegex.test(key))) {
if (sourceMap[key]) {
outputData[key] = sourceMap[key];
}
}
});
return outputData;
} | [
"Filters",
"a",
"given",
"sourcemap",
"by",
"specific",
"test",
"regex",
"s",
"."
]
| acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6 | https://github.com/SilentCicero/ethdeploy/blob/acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6/src/utils/index.js#L103-L122 |
47,097 | SilentCicero/ethdeploy | src/utils/index.js | getTransactionSuccess | function getTransactionSuccess(eth, txHash, timeout = 800000, callback) {
const cb = callback || function cb() {};
let count = 0;
return new Promise((resolve, reject) => {
const txInterval = setInterval(() => {
eth.getTransactionReceipt(txHash, (err, result) => {
if (err) {
clearInterval(txInterval);
cb(err, null);
reject(err);
}
if (!err && result) {
clearInterval(txInterval);
cb(null, result);
resolve(result);
}
});
if (count >= timeout) {
clearInterval(txInterval);
const errMessage = `Receipt timeout waiting for tx hash: ${txHash}`;
cb(errMessage, null);
reject(errMessage);
}
count += 7000;
}, 7000);
});
} | javascript | function getTransactionSuccess(eth, txHash, timeout = 800000, callback) {
const cb = callback || function cb() {};
let count = 0;
return new Promise((resolve, reject) => {
const txInterval = setInterval(() => {
eth.getTransactionReceipt(txHash, (err, result) => {
if (err) {
clearInterval(txInterval);
cb(err, null);
reject(err);
}
if (!err && result) {
clearInterval(txInterval);
cb(null, result);
resolve(result);
}
});
if (count >= timeout) {
clearInterval(txInterval);
const errMessage = `Receipt timeout waiting for tx hash: ${txHash}`;
cb(errMessage, null);
reject(errMessage);
}
count += 7000;
}, 7000);
});
} | [
"function",
"getTransactionSuccess",
"(",
"eth",
",",
"txHash",
",",
"timeout",
"=",
"800000",
",",
"callback",
")",
"{",
"const",
"cb",
"=",
"callback",
"||",
"function",
"cb",
"(",
")",
"{",
"}",
";",
"let",
"count",
"=",
"0",
";",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"const",
"txInterval",
"=",
"setInterval",
"(",
"(",
")",
"=>",
"{",
"eth",
".",
"getTransactionReceipt",
"(",
"txHash",
",",
"(",
"err",
",",
"result",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"clearInterval",
"(",
"txInterval",
")",
";",
"cb",
"(",
"err",
",",
"null",
")",
";",
"reject",
"(",
"err",
")",
";",
"}",
"if",
"(",
"!",
"err",
"&&",
"result",
")",
"{",
"clearInterval",
"(",
"txInterval",
")",
";",
"cb",
"(",
"null",
",",
"result",
")",
";",
"resolve",
"(",
"result",
")",
";",
"}",
"}",
")",
";",
"if",
"(",
"count",
">=",
"timeout",
")",
"{",
"clearInterval",
"(",
"txInterval",
")",
";",
"const",
"errMessage",
"=",
"`",
"${",
"txHash",
"}",
"`",
";",
"cb",
"(",
"errMessage",
",",
"null",
")",
";",
"reject",
"(",
"errMessage",
")",
";",
"}",
"count",
"+=",
"7000",
";",
"}",
",",
"7000",
")",
";",
"}",
")",
";",
"}"
]
| This will wait for a transaction to present a receipt
@method getTransactionSuccess
@param {Object} eth the eth query instance
@param {Object} txHash the transaction hash
@param {Object} timeout settings
@param {Function} callback the final callback
@callback {Object} contractInstance the deployed contract instance with receipt prop | [
"This",
"will",
"wait",
"for",
"a",
"transaction",
"to",
"present",
"a",
"receipt"
]
| acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6 | https://github.com/SilentCicero/ethdeploy/blob/acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6/src/utils/index.js#L135-L163 |
47,098 | SilentCicero/ethdeploy | src/utils/index.js | deployContract | function deployContract(eth, factory, args, callback) {
factory.new.apply(factory, args).then((txHash) => {
getTransactionSuccess(eth, txHash, 8000000, (receiptError, receipt) => {
if (receiptError) {
callback(receiptError, null);
}
if (receipt) {
const contractInstance = factory.at(receipt.contractAddress);
contractInstance.receipt = receipt;
callback(null, contractInstance);
}
});
}).catch(callback);
} | javascript | function deployContract(eth, factory, args, callback) {
factory.new.apply(factory, args).then((txHash) => {
getTransactionSuccess(eth, txHash, 8000000, (receiptError, receipt) => {
if (receiptError) {
callback(receiptError, null);
}
if (receipt) {
const contractInstance = factory.at(receipt.contractAddress);
contractInstance.receipt = receipt;
callback(null, contractInstance);
}
});
}).catch(callback);
} | [
"function",
"deployContract",
"(",
"eth",
",",
"factory",
",",
"args",
",",
"callback",
")",
"{",
"factory",
".",
"new",
".",
"apply",
"(",
"factory",
",",
"args",
")",
".",
"then",
"(",
"(",
"txHash",
")",
"=>",
"{",
"getTransactionSuccess",
"(",
"eth",
",",
"txHash",
",",
"8000000",
",",
"(",
"receiptError",
",",
"receipt",
")",
"=>",
"{",
"if",
"(",
"receiptError",
")",
"{",
"callback",
"(",
"receiptError",
",",
"null",
")",
";",
"}",
"if",
"(",
"receipt",
")",
"{",
"const",
"contractInstance",
"=",
"factory",
".",
"at",
"(",
"receipt",
".",
"contractAddress",
")",
";",
"contractInstance",
".",
"receipt",
"=",
"receipt",
";",
"callback",
"(",
"null",
",",
"contractInstance",
")",
";",
"}",
"}",
")",
";",
"}",
")",
".",
"catch",
"(",
"callback",
")",
";",
"}"
]
| Deploy the contract with eth, factory, and args
@method deployContract
@param {Object} eth the eth query instance
@param {Object} factory the contract factory
@param {Array} args the contract constructor arguments
@param {Function} callback the final callback
@callback {Object} contractInstance the deployed contract instance with receipt prop | [
"Deploy",
"the",
"contract",
"with",
"eth",
"factory",
"and",
"args"
]
| acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6 | https://github.com/SilentCicero/ethdeploy/blob/acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6/src/utils/index.js#L175-L189 |
47,099 | SilentCicero/ethdeploy | src/utils/index.js | getInputSources | function getInputSources(pathname, callback) {
let filesRead = 0;
let sources = {};
// test file is a file, the last section contains a extention period
if (String(pathname).split('/').pop().indexOf('.') !== -1) {
const searchPathname = pathname.substr(0, 2) === './' ? pathname.slice(2) : pathname;
fs.readFile(searchPathname, 'utf8', (readFileError, fileData) => { // eslint-disable-line
if (readFileError) {
return callback(error(`while while getting input sources ${readFileError}`));
}
callback(null, { [searchPathname]: fileData });
});
} else {
// get all file names
dir.files(pathname, (filesError, files) => { // eslint-disable-line
if (filesError) {
return callback(error(`while while getting input sources ${filesError}`));
}
// if no files in directory, then fire callback with empty sources
if (files.length === 0) {
callback(null, sources);
} else {
// read all files
dir.readFiles(pathname, (readFilesError, content, filename, next) => { // eslint-disable-line
if (readFilesError) {
return callback(error(`while getting input sources ${readFilesError}`));
}
// add input sources to output
sources = Object.assign({}, sources, {
[path.join('./', filename)]: content,
});
// increase files readFiles
filesRead += 1;
// process next file
if (filesRead === files.length) {
callback(null, sources);
} else {
next();
}
});
}
});
}
} | javascript | function getInputSources(pathname, callback) {
let filesRead = 0;
let sources = {};
// test file is a file, the last section contains a extention period
if (String(pathname).split('/').pop().indexOf('.') !== -1) {
const searchPathname = pathname.substr(0, 2) === './' ? pathname.slice(2) : pathname;
fs.readFile(searchPathname, 'utf8', (readFileError, fileData) => { // eslint-disable-line
if (readFileError) {
return callback(error(`while while getting input sources ${readFileError}`));
}
callback(null, { [searchPathname]: fileData });
});
} else {
// get all file names
dir.files(pathname, (filesError, files) => { // eslint-disable-line
if (filesError) {
return callback(error(`while while getting input sources ${filesError}`));
}
// if no files in directory, then fire callback with empty sources
if (files.length === 0) {
callback(null, sources);
} else {
// read all files
dir.readFiles(pathname, (readFilesError, content, filename, next) => { // eslint-disable-line
if (readFilesError) {
return callback(error(`while getting input sources ${readFilesError}`));
}
// add input sources to output
sources = Object.assign({}, sources, {
[path.join('./', filename)]: content,
});
// increase files readFiles
filesRead += 1;
// process next file
if (filesRead === files.length) {
callback(null, sources);
} else {
next();
}
});
}
});
}
} | [
"function",
"getInputSources",
"(",
"pathname",
",",
"callback",
")",
"{",
"let",
"filesRead",
"=",
"0",
";",
"let",
"sources",
"=",
"{",
"}",
";",
"// test file is a file, the last section contains a extention period",
"if",
"(",
"String",
"(",
"pathname",
")",
".",
"split",
"(",
"'/'",
")",
".",
"pop",
"(",
")",
".",
"indexOf",
"(",
"'.'",
")",
"!==",
"-",
"1",
")",
"{",
"const",
"searchPathname",
"=",
"pathname",
".",
"substr",
"(",
"0",
",",
"2",
")",
"===",
"'./'",
"?",
"pathname",
".",
"slice",
"(",
"2",
")",
":",
"pathname",
";",
"fs",
".",
"readFile",
"(",
"searchPathname",
",",
"'utf8'",
",",
"(",
"readFileError",
",",
"fileData",
")",
"=>",
"{",
"// eslint-disable-line",
"if",
"(",
"readFileError",
")",
"{",
"return",
"callback",
"(",
"error",
"(",
"`",
"${",
"readFileError",
"}",
"`",
")",
")",
";",
"}",
"callback",
"(",
"null",
",",
"{",
"[",
"searchPathname",
"]",
":",
"fileData",
"}",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"// get all file names",
"dir",
".",
"files",
"(",
"pathname",
",",
"(",
"filesError",
",",
"files",
")",
"=>",
"{",
"// eslint-disable-line",
"if",
"(",
"filesError",
")",
"{",
"return",
"callback",
"(",
"error",
"(",
"`",
"${",
"filesError",
"}",
"`",
")",
")",
";",
"}",
"// if no files in directory, then fire callback with empty sources",
"if",
"(",
"files",
".",
"length",
"===",
"0",
")",
"{",
"callback",
"(",
"null",
",",
"sources",
")",
";",
"}",
"else",
"{",
"// read all files",
"dir",
".",
"readFiles",
"(",
"pathname",
",",
"(",
"readFilesError",
",",
"content",
",",
"filename",
",",
"next",
")",
"=>",
"{",
"// eslint-disable-line",
"if",
"(",
"readFilesError",
")",
"{",
"return",
"callback",
"(",
"error",
"(",
"`",
"${",
"readFilesError",
"}",
"`",
")",
")",
";",
"}",
"// add input sources to output",
"sources",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"sources",
",",
"{",
"[",
"path",
".",
"join",
"(",
"'./'",
",",
"filename",
")",
"]",
":",
"content",
",",
"}",
")",
";",
"// increase files readFiles",
"filesRead",
"+=",
"1",
";",
"// process next file",
"if",
"(",
"filesRead",
"===",
"files",
".",
"length",
")",
"{",
"callback",
"(",
"null",
",",
"sources",
")",
";",
"}",
"else",
"{",
"next",
"(",
")",
";",
"}",
"}",
")",
";",
"}",
"}",
")",
";",
"}",
"}"
]
| Get all input source for a specific pathname, used for mapping config entry
@method getInputSources
@param {String} pathname a path string to a file or directory
@param {Function} callback the final callback that returns the sources
@callback {Object} sourceMap returns a source map for this pathname | [
"Get",
"all",
"input",
"source",
"for",
"a",
"specific",
"pathname",
"used",
"for",
"mapping",
"config",
"entry"
]
| acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6 | https://github.com/SilentCicero/ethdeploy/blob/acb1212e1942ce604eb82e34ce2f8c9d6b20a0a6/src/utils/index.js#L199-L249 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.