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
|
---|---|---|---|---|---|---|---|---|---|---|---|
49,200 | tnantoka/LooseLeaf | skeleton/public/javascripts/lib/cleditor/jquery.cleditor.js | disable | function disable(editor, disabled) {
// Update the textarea and save the state
if (disabled) {
editor.$area.attr(DISABLED, DISABLED);
editor.disabled = true;
}
else {
editor.$area.removeAttr(DISABLED);
delete editor.disabled;
}
// Switch the iframe into design mode.
// ie6 does not support designMode.
// ie7 & ie8 do not properly support designMode="off".
try {
if (ie) editor.doc.body.contentEditable = !disabled;
else editor.doc.designMode = !disabled ? "on" : "off";
}
// Firefox 1.5 throws an exception that can be ignored
// when toggling designMode from off to on.
catch (err) {}
// Enable or disable the toolbar buttons
refreshButtons(editor);
} | javascript | function disable(editor, disabled) {
// Update the textarea and save the state
if (disabled) {
editor.$area.attr(DISABLED, DISABLED);
editor.disabled = true;
}
else {
editor.$area.removeAttr(DISABLED);
delete editor.disabled;
}
// Switch the iframe into design mode.
// ie6 does not support designMode.
// ie7 & ie8 do not properly support designMode="off".
try {
if (ie) editor.doc.body.contentEditable = !disabled;
else editor.doc.designMode = !disabled ? "on" : "off";
}
// Firefox 1.5 throws an exception that can be ignored
// when toggling designMode from off to on.
catch (err) {}
// Enable or disable the toolbar buttons
refreshButtons(editor);
} | [
"function",
"disable",
"(",
"editor",
",",
"disabled",
")",
"{",
"// Update the textarea and save the state\r",
"if",
"(",
"disabled",
")",
"{",
"editor",
".",
"$area",
".",
"attr",
"(",
"DISABLED",
",",
"DISABLED",
")",
";",
"editor",
".",
"disabled",
"=",
"true",
";",
"}",
"else",
"{",
"editor",
".",
"$area",
".",
"removeAttr",
"(",
"DISABLED",
")",
";",
"delete",
"editor",
".",
"disabled",
";",
"}",
"// Switch the iframe into design mode.\r",
"// ie6 does not support designMode.\r",
"// ie7 & ie8 do not properly support designMode=\"off\".\r",
"try",
"{",
"if",
"(",
"ie",
")",
"editor",
".",
"doc",
".",
"body",
".",
"contentEditable",
"=",
"!",
"disabled",
";",
"else",
"editor",
".",
"doc",
".",
"designMode",
"=",
"!",
"disabled",
"?",
"\"on\"",
":",
"\"off\"",
";",
"}",
"// Firefox 1.5 throws an exception that can be ignored\r",
"// when toggling designMode from off to on.\r",
"catch",
"(",
"err",
")",
"{",
"}",
"// Enable or disable the toolbar buttons\r",
"refreshButtons",
"(",
"editor",
")",
";",
"}"
] | disable - enables or disables the editor | [
"disable",
"-",
"enables",
"or",
"disables",
"the",
"editor"
] | 0c6333977224d8f4ef7ad40415aa69e0ff76f7b5 | https://github.com/tnantoka/LooseLeaf/blob/0c6333977224d8f4ef7ad40415aa69e0ff76f7b5/skeleton/public/javascripts/lib/cleditor/jquery.cleditor.js#L671-L697 |
49,201 | tnantoka/LooseLeaf | skeleton/public/javascripts/lib/cleditor/jquery.cleditor.js | execCommand | function execCommand(editor, command, value, useCSS, button) {
// Restore the current ie selection
restoreRange(editor);
// Set the styling method
if (!ie) {
if (useCSS === undefined || useCSS === null)
useCSS = editor.options.useCSS;
editor.doc.execCommand("styleWithCSS", 0, useCSS.toString());
}
// Execute the command and check for error
var success = true, description;
if (ie && command.toLowerCase() == "inserthtml")
getRange(editor).pasteHTML(value);
else {
try { success = editor.doc.execCommand(command, 0, value || null); }
catch (err) { description = err.description; success = false; }
if (!success) {
if ("cutcopypaste".indexOf(command) > -1)
showMessage(editor, "For security reasons, your browser does not support the " +
command + " command. Try using the keyboard shortcut or context menu instead.",
button);
else
showMessage(editor,
(description ? description : "Error executing the " + command + " command."),
button);
}
}
// Enable the buttons
refreshButtons(editor);
return success;
} | javascript | function execCommand(editor, command, value, useCSS, button) {
// Restore the current ie selection
restoreRange(editor);
// Set the styling method
if (!ie) {
if (useCSS === undefined || useCSS === null)
useCSS = editor.options.useCSS;
editor.doc.execCommand("styleWithCSS", 0, useCSS.toString());
}
// Execute the command and check for error
var success = true, description;
if (ie && command.toLowerCase() == "inserthtml")
getRange(editor).pasteHTML(value);
else {
try { success = editor.doc.execCommand(command, 0, value || null); }
catch (err) { description = err.description; success = false; }
if (!success) {
if ("cutcopypaste".indexOf(command) > -1)
showMessage(editor, "For security reasons, your browser does not support the " +
command + " command. Try using the keyboard shortcut or context menu instead.",
button);
else
showMessage(editor,
(description ? description : "Error executing the " + command + " command."),
button);
}
}
// Enable the buttons
refreshButtons(editor);
return success;
} | [
"function",
"execCommand",
"(",
"editor",
",",
"command",
",",
"value",
",",
"useCSS",
",",
"button",
")",
"{",
"// Restore the current ie selection\r",
"restoreRange",
"(",
"editor",
")",
";",
"// Set the styling method\r",
"if",
"(",
"!",
"ie",
")",
"{",
"if",
"(",
"useCSS",
"===",
"undefined",
"||",
"useCSS",
"===",
"null",
")",
"useCSS",
"=",
"editor",
".",
"options",
".",
"useCSS",
";",
"editor",
".",
"doc",
".",
"execCommand",
"(",
"\"styleWithCSS\"",
",",
"0",
",",
"useCSS",
".",
"toString",
"(",
")",
")",
";",
"}",
"// Execute the command and check for error\r",
"var",
"success",
"=",
"true",
",",
"description",
";",
"if",
"(",
"ie",
"&&",
"command",
".",
"toLowerCase",
"(",
")",
"==",
"\"inserthtml\"",
")",
"getRange",
"(",
"editor",
")",
".",
"pasteHTML",
"(",
"value",
")",
";",
"else",
"{",
"try",
"{",
"success",
"=",
"editor",
".",
"doc",
".",
"execCommand",
"(",
"command",
",",
"0",
",",
"value",
"||",
"null",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"description",
"=",
"err",
".",
"description",
";",
"success",
"=",
"false",
";",
"}",
"if",
"(",
"!",
"success",
")",
"{",
"if",
"(",
"\"cutcopypaste\"",
".",
"indexOf",
"(",
"command",
")",
">",
"-",
"1",
")",
"showMessage",
"(",
"editor",
",",
"\"For security reasons, your browser does not support the \"",
"+",
"command",
"+",
"\" command. Try using the keyboard shortcut or context menu instead.\"",
",",
"button",
")",
";",
"else",
"showMessage",
"(",
"editor",
",",
"(",
"description",
"?",
"description",
":",
"\"Error executing the \"",
"+",
"command",
"+",
"\" command.\"",
")",
",",
"button",
")",
";",
"}",
"}",
"// Enable the buttons\r",
"refreshButtons",
"(",
"editor",
")",
";",
"return",
"success",
";",
"}"
] | execCommand - executes a designMode command | [
"execCommand",
"-",
"executes",
"a",
"designMode",
"command"
] | 0c6333977224d8f4ef7ad40415aa69e0ff76f7b5 | https://github.com/tnantoka/LooseLeaf/blob/0c6333977224d8f4ef7ad40415aa69e0ff76f7b5/skeleton/public/javascripts/lib/cleditor/jquery.cleditor.js#L700-L735 |
49,202 | tnantoka/LooseLeaf | skeleton/public/javascripts/lib/cleditor/jquery.cleditor.js | focus | function focus(editor) {
setTimeout(function() {
if (sourceMode(editor)) editor.$area.focus();
else editor.$frame[0].contentWindow.focus();
refreshButtons(editor);
}, 0);
} | javascript | function focus(editor) {
setTimeout(function() {
if (sourceMode(editor)) editor.$area.focus();
else editor.$frame[0].contentWindow.focus();
refreshButtons(editor);
}, 0);
} | [
"function",
"focus",
"(",
"editor",
")",
"{",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"sourceMode",
"(",
"editor",
")",
")",
"editor",
".",
"$area",
".",
"focus",
"(",
")",
";",
"else",
"editor",
".",
"$frame",
"[",
"0",
"]",
".",
"contentWindow",
".",
"focus",
"(",
")",
";",
"refreshButtons",
"(",
"editor",
")",
";",
"}",
",",
"0",
")",
";",
"}"
] | focus - sets focus to either the textarea or iframe | [
"focus",
"-",
"sets",
"focus",
"to",
"either",
"the",
"textarea",
"or",
"iframe"
] | 0c6333977224d8f4ef7ad40415aa69e0ff76f7b5 | https://github.com/tnantoka/LooseLeaf/blob/0c6333977224d8f4ef7ad40415aa69e0ff76f7b5/skeleton/public/javascripts/lib/cleditor/jquery.cleditor.js#L738-L744 |
49,203 | tnantoka/LooseLeaf | skeleton/public/javascripts/lib/cleditor/jquery.cleditor.js | hidePopups | function hidePopups() {
$.each(popups, function(idx, popup) {
$(popup)
.hide()
.unbind(CLICK)
.removeData(BUTTON);
});
} | javascript | function hidePopups() {
$.each(popups, function(idx, popup) {
$(popup)
.hide()
.unbind(CLICK)
.removeData(BUTTON);
});
} | [
"function",
"hidePopups",
"(",
")",
"{",
"$",
".",
"each",
"(",
"popups",
",",
"function",
"(",
"idx",
",",
"popup",
")",
"{",
"$",
"(",
"popup",
")",
".",
"hide",
"(",
")",
".",
"unbind",
"(",
"CLICK",
")",
".",
"removeData",
"(",
"BUTTON",
")",
";",
"}",
")",
";",
"}"
] | hidePopups - hides all popups | [
"hidePopups",
"-",
"hides",
"all",
"popups"
] | 0c6333977224d8f4ef7ad40415aa69e0ff76f7b5 | https://github.com/tnantoka/LooseLeaf/blob/0c6333977224d8f4ef7ad40415aa69e0ff76f7b5/skeleton/public/javascripts/lib/cleditor/jquery.cleditor.js#L774-L781 |
49,204 | tnantoka/LooseLeaf | skeleton/public/javascripts/lib/cleditor/jquery.cleditor.js | imagesPath | function imagesPath() {
var cssFile = "jquery.cleditor.css",
href = $("link[href$='" + cssFile +"']").attr("href");
return href.substr(0, href.length - cssFile.length) + "images/";
} | javascript | function imagesPath() {
var cssFile = "jquery.cleditor.css",
href = $("link[href$='" + cssFile +"']").attr("href");
return href.substr(0, href.length - cssFile.length) + "images/";
} | [
"function",
"imagesPath",
"(",
")",
"{",
"var",
"cssFile",
"=",
"\"jquery.cleditor.css\"",
",",
"href",
"=",
"$",
"(",
"\"link[href$='\"",
"+",
"cssFile",
"+",
"\"']\"",
")",
".",
"attr",
"(",
"\"href\"",
")",
";",
"return",
"href",
".",
"substr",
"(",
"0",
",",
"href",
".",
"length",
"-",
"cssFile",
".",
"length",
")",
"+",
"\"images/\"",
";",
"}"
] | imagesPath - returns the path to the images folder | [
"imagesPath",
"-",
"returns",
"the",
"path",
"to",
"the",
"images",
"folder"
] | 0c6333977224d8f4ef7ad40415aa69e0ff76f7b5 | https://github.com/tnantoka/LooseLeaf/blob/0c6333977224d8f4ef7ad40415aa69e0ff76f7b5/skeleton/public/javascripts/lib/cleditor/jquery.cleditor.js#L784-L788 |
49,205 | tnantoka/LooseLeaf | skeleton/public/javascripts/lib/cleditor/jquery.cleditor.js | refreshButtons | function refreshButtons(editor) {
// Webkit requires focus before queryCommandEnabled will return anything but false
if (!iOS && $.browser.webkit && !editor.focused) {
editor.$frame[0].contentWindow.focus();
window.focus();
editor.focused = true;
}
// Get the object used for checking queryCommandEnabled
var queryObj = editor.doc;
if (ie) queryObj = getRange(editor);
// Loop through each button
var inSourceMode = sourceMode(editor);
$.each(editor.$toolbar.find("." + BUTTON_CLASS), function(idx, elem) {
var $elem = $(elem),
button = $.cleditor.buttons[$.data(elem, BUTTON_NAME)],
command = button.command,
enabled = true;
// Determine the state
if (editor.disabled)
enabled = false;
else if (button.getEnabled) {
var data = {
editor: editor,
button: elem,
buttonName: button.name,
popup: popups[button.popupName],
popupName: button.popupName,
command: button.command,
useCSS: editor.options.useCSS
};
enabled = button.getEnabled(data);
if (enabled === undefined)
enabled = true;
}
else if (((inSourceMode || iOS) && button.name != "source") ||
(ie && (command == "undo" || command == "redo")))
enabled = false;
else if (command && command != "print") {
if (ie && command == "hilitecolor")
command = "backcolor";
// IE does not support inserthtml, so it's always enabled
if (!ie || command != "inserthtml") {
try {enabled = queryObj.queryCommandEnabled(command);}
catch (err) {enabled = false;}
}
}
// Enable or disable the button
if (enabled) {
$elem.removeClass(DISABLED_CLASS);
$elem.removeAttr(DISABLED);
}
else {
$elem.addClass(DISABLED_CLASS);
$elem.attr(DISABLED, DISABLED);
}
});
} | javascript | function refreshButtons(editor) {
// Webkit requires focus before queryCommandEnabled will return anything but false
if (!iOS && $.browser.webkit && !editor.focused) {
editor.$frame[0].contentWindow.focus();
window.focus();
editor.focused = true;
}
// Get the object used for checking queryCommandEnabled
var queryObj = editor.doc;
if (ie) queryObj = getRange(editor);
// Loop through each button
var inSourceMode = sourceMode(editor);
$.each(editor.$toolbar.find("." + BUTTON_CLASS), function(idx, elem) {
var $elem = $(elem),
button = $.cleditor.buttons[$.data(elem, BUTTON_NAME)],
command = button.command,
enabled = true;
// Determine the state
if (editor.disabled)
enabled = false;
else if (button.getEnabled) {
var data = {
editor: editor,
button: elem,
buttonName: button.name,
popup: popups[button.popupName],
popupName: button.popupName,
command: button.command,
useCSS: editor.options.useCSS
};
enabled = button.getEnabled(data);
if (enabled === undefined)
enabled = true;
}
else if (((inSourceMode || iOS) && button.name != "source") ||
(ie && (command == "undo" || command == "redo")))
enabled = false;
else if (command && command != "print") {
if (ie && command == "hilitecolor")
command = "backcolor";
// IE does not support inserthtml, so it's always enabled
if (!ie || command != "inserthtml") {
try {enabled = queryObj.queryCommandEnabled(command);}
catch (err) {enabled = false;}
}
}
// Enable or disable the button
if (enabled) {
$elem.removeClass(DISABLED_CLASS);
$elem.removeAttr(DISABLED);
}
else {
$elem.addClass(DISABLED_CLASS);
$elem.attr(DISABLED, DISABLED);
}
});
} | [
"function",
"refreshButtons",
"(",
"editor",
")",
"{",
"// Webkit requires focus before queryCommandEnabled will return anything but false\r",
"if",
"(",
"!",
"iOS",
"&&",
"$",
".",
"browser",
".",
"webkit",
"&&",
"!",
"editor",
".",
"focused",
")",
"{",
"editor",
".",
"$frame",
"[",
"0",
"]",
".",
"contentWindow",
".",
"focus",
"(",
")",
";",
"window",
".",
"focus",
"(",
")",
";",
"editor",
".",
"focused",
"=",
"true",
";",
"}",
"// Get the object used for checking queryCommandEnabled\r",
"var",
"queryObj",
"=",
"editor",
".",
"doc",
";",
"if",
"(",
"ie",
")",
"queryObj",
"=",
"getRange",
"(",
"editor",
")",
";",
"// Loop through each button\r",
"var",
"inSourceMode",
"=",
"sourceMode",
"(",
"editor",
")",
";",
"$",
".",
"each",
"(",
"editor",
".",
"$toolbar",
".",
"find",
"(",
"\".\"",
"+",
"BUTTON_CLASS",
")",
",",
"function",
"(",
"idx",
",",
"elem",
")",
"{",
"var",
"$elem",
"=",
"$",
"(",
"elem",
")",
",",
"button",
"=",
"$",
".",
"cleditor",
".",
"buttons",
"[",
"$",
".",
"data",
"(",
"elem",
",",
"BUTTON_NAME",
")",
"]",
",",
"command",
"=",
"button",
".",
"command",
",",
"enabled",
"=",
"true",
";",
"// Determine the state\r",
"if",
"(",
"editor",
".",
"disabled",
")",
"enabled",
"=",
"false",
";",
"else",
"if",
"(",
"button",
".",
"getEnabled",
")",
"{",
"var",
"data",
"=",
"{",
"editor",
":",
"editor",
",",
"button",
":",
"elem",
",",
"buttonName",
":",
"button",
".",
"name",
",",
"popup",
":",
"popups",
"[",
"button",
".",
"popupName",
"]",
",",
"popupName",
":",
"button",
".",
"popupName",
",",
"command",
":",
"button",
".",
"command",
",",
"useCSS",
":",
"editor",
".",
"options",
".",
"useCSS",
"}",
";",
"enabled",
"=",
"button",
".",
"getEnabled",
"(",
"data",
")",
";",
"if",
"(",
"enabled",
"===",
"undefined",
")",
"enabled",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"(",
"(",
"inSourceMode",
"||",
"iOS",
")",
"&&",
"button",
".",
"name",
"!=",
"\"source\"",
")",
"||",
"(",
"ie",
"&&",
"(",
"command",
"==",
"\"undo\"",
"||",
"command",
"==",
"\"redo\"",
")",
")",
")",
"enabled",
"=",
"false",
";",
"else",
"if",
"(",
"command",
"&&",
"command",
"!=",
"\"print\"",
")",
"{",
"if",
"(",
"ie",
"&&",
"command",
"==",
"\"hilitecolor\"",
")",
"command",
"=",
"\"backcolor\"",
";",
"// IE does not support inserthtml, so it's always enabled\r",
"if",
"(",
"!",
"ie",
"||",
"command",
"!=",
"\"inserthtml\"",
")",
"{",
"try",
"{",
"enabled",
"=",
"queryObj",
".",
"queryCommandEnabled",
"(",
"command",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"enabled",
"=",
"false",
";",
"}",
"}",
"}",
"// Enable or disable the button\r",
"if",
"(",
"enabled",
")",
"{",
"$elem",
".",
"removeClass",
"(",
"DISABLED_CLASS",
")",
";",
"$elem",
".",
"removeAttr",
"(",
"DISABLED",
")",
";",
"}",
"else",
"{",
"$elem",
".",
"addClass",
"(",
"DISABLED_CLASS",
")",
";",
"$elem",
".",
"attr",
"(",
"DISABLED",
",",
"DISABLED",
")",
";",
"}",
"}",
")",
";",
"}"
] | refreshButtons - enables or disables buttons based on availability | [
"refreshButtons",
"-",
"enables",
"or",
"disables",
"buttons",
"based",
"on",
"availability"
] | 0c6333977224d8f4ef7ad40415aa69e0ff76f7b5 | https://github.com/tnantoka/LooseLeaf/blob/0c6333977224d8f4ef7ad40415aa69e0ff76f7b5/skeleton/public/javascripts/lib/cleditor/jquery.cleditor.js#L917-L980 |
49,206 | tnantoka/LooseLeaf | skeleton/public/javascripts/lib/cleditor/jquery.cleditor.js | selectedHTML | function selectedHTML(editor) {
restoreRange(editor);
var range = getRange(editor);
if (ie)
return range.htmlText;
var layer = $("<layer>")[0];
layer.appendChild(range.cloneContents());
var html = layer.innerHTML;
layer = null;
return html;
} | javascript | function selectedHTML(editor) {
restoreRange(editor);
var range = getRange(editor);
if (ie)
return range.htmlText;
var layer = $("<layer>")[0];
layer.appendChild(range.cloneContents());
var html = layer.innerHTML;
layer = null;
return html;
} | [
"function",
"selectedHTML",
"(",
"editor",
")",
"{",
"restoreRange",
"(",
"editor",
")",
";",
"var",
"range",
"=",
"getRange",
"(",
"editor",
")",
";",
"if",
"(",
"ie",
")",
"return",
"range",
".",
"htmlText",
";",
"var",
"layer",
"=",
"$",
"(",
"\"<layer>\"",
")",
"[",
"0",
"]",
";",
"layer",
".",
"appendChild",
"(",
"range",
".",
"cloneContents",
"(",
")",
")",
";",
"var",
"html",
"=",
"layer",
".",
"innerHTML",
";",
"layer",
"=",
"null",
";",
"return",
"html",
";",
"}"
] | selectedHTML - returns the current HTML selection or and empty string | [
"selectedHTML",
"-",
"returns",
"the",
"current",
"HTML",
"selection",
"or",
"and",
"empty",
"string"
] | 0c6333977224d8f4ef7ad40415aa69e0ff76f7b5 | https://github.com/tnantoka/LooseLeaf/blob/0c6333977224d8f4ef7ad40415aa69e0ff76f7b5/skeleton/public/javascripts/lib/cleditor/jquery.cleditor.js#L997-L1007 |
49,207 | tnantoka/LooseLeaf | skeleton/public/javascripts/lib/cleditor/jquery.cleditor.js | selectedText | function selectedText(editor) {
restoreRange(editor);
if (ie) return getRange(editor).text;
return getSelection(editor).toString();
} | javascript | function selectedText(editor) {
restoreRange(editor);
if (ie) return getRange(editor).text;
return getSelection(editor).toString();
} | [
"function",
"selectedText",
"(",
"editor",
")",
"{",
"restoreRange",
"(",
"editor",
")",
";",
"if",
"(",
"ie",
")",
"return",
"getRange",
"(",
"editor",
")",
".",
"text",
";",
"return",
"getSelection",
"(",
"editor",
")",
".",
"toString",
"(",
")",
";",
"}"
] | selectedText - returns the current text selection or and empty string | [
"selectedText",
"-",
"returns",
"the",
"current",
"text",
"selection",
"or",
"and",
"empty",
"string"
] | 0c6333977224d8f4ef7ad40415aa69e0ff76f7b5 | https://github.com/tnantoka/LooseLeaf/blob/0c6333977224d8f4ef7ad40415aa69e0ff76f7b5/skeleton/public/javascripts/lib/cleditor/jquery.cleditor.js#L1010-L1014 |
49,208 | tnantoka/LooseLeaf | skeleton/public/javascripts/lib/cleditor/jquery.cleditor.js | showMessage | function showMessage(editor, message, button) {
var popup = createPopup("msg", editor.options, MSG_CLASS);
popup.innerHTML = message;
showPopup(editor, popup, button);
} | javascript | function showMessage(editor, message, button) {
var popup = createPopup("msg", editor.options, MSG_CLASS);
popup.innerHTML = message;
showPopup(editor, popup, button);
} | [
"function",
"showMessage",
"(",
"editor",
",",
"message",
",",
"button",
")",
"{",
"var",
"popup",
"=",
"createPopup",
"(",
"\"msg\"",
",",
"editor",
".",
"options",
",",
"MSG_CLASS",
")",
";",
"popup",
".",
"innerHTML",
"=",
"message",
";",
"showPopup",
"(",
"editor",
",",
"popup",
",",
"button",
")",
";",
"}"
] | showMessage - alert replacement | [
"showMessage",
"-",
"alert",
"replacement"
] | 0c6333977224d8f4ef7ad40415aa69e0ff76f7b5 | https://github.com/tnantoka/LooseLeaf/blob/0c6333977224d8f4ef7ad40415aa69e0ff76f7b5/skeleton/public/javascripts/lib/cleditor/jquery.cleditor.js#L1017-L1021 |
49,209 | tnantoka/LooseLeaf | skeleton/public/javascripts/lib/cleditor/jquery.cleditor.js | showPopup | function showPopup(editor, popup, button) {
var offset, left, top, $popup = $(popup);
// Determine the popup location
if (button) {
var $button = $(button);
offset = $button.offset();
left = --offset.left;
top = offset.top + $button.height();
}
else {
var $toolbar = editor.$toolbar;
offset = $toolbar.offset();
left = Math.floor(($toolbar.width() - $popup.width()) / 2) + offset.left;
top = offset.top + $toolbar.height() - 2;
}
// Position and show the popup
hidePopups();
$popup.css({left: left, top: top})
.show();
// Assign the popup button and click event handler
if (button) {
$.data(popup, BUTTON, button);
$popup.bind(CLICK, {popup: popup}, $.proxy(popupClick, editor));
}
// Focus the first input element if any
setTimeout(function() {
$popup.find(":text,textarea").eq(0).focus().select();
}, 100);
} | javascript | function showPopup(editor, popup, button) {
var offset, left, top, $popup = $(popup);
// Determine the popup location
if (button) {
var $button = $(button);
offset = $button.offset();
left = --offset.left;
top = offset.top + $button.height();
}
else {
var $toolbar = editor.$toolbar;
offset = $toolbar.offset();
left = Math.floor(($toolbar.width() - $popup.width()) / 2) + offset.left;
top = offset.top + $toolbar.height() - 2;
}
// Position and show the popup
hidePopups();
$popup.css({left: left, top: top})
.show();
// Assign the popup button and click event handler
if (button) {
$.data(popup, BUTTON, button);
$popup.bind(CLICK, {popup: popup}, $.proxy(popupClick, editor));
}
// Focus the first input element if any
setTimeout(function() {
$popup.find(":text,textarea").eq(0).focus().select();
}, 100);
} | [
"function",
"showPopup",
"(",
"editor",
",",
"popup",
",",
"button",
")",
"{",
"var",
"offset",
",",
"left",
",",
"top",
",",
"$popup",
"=",
"$",
"(",
"popup",
")",
";",
"// Determine the popup location\r",
"if",
"(",
"button",
")",
"{",
"var",
"$button",
"=",
"$",
"(",
"button",
")",
";",
"offset",
"=",
"$button",
".",
"offset",
"(",
")",
";",
"left",
"=",
"--",
"offset",
".",
"left",
";",
"top",
"=",
"offset",
".",
"top",
"+",
"$button",
".",
"height",
"(",
")",
";",
"}",
"else",
"{",
"var",
"$toolbar",
"=",
"editor",
".",
"$toolbar",
";",
"offset",
"=",
"$toolbar",
".",
"offset",
"(",
")",
";",
"left",
"=",
"Math",
".",
"floor",
"(",
"(",
"$toolbar",
".",
"width",
"(",
")",
"-",
"$popup",
".",
"width",
"(",
")",
")",
"/",
"2",
")",
"+",
"offset",
".",
"left",
";",
"top",
"=",
"offset",
".",
"top",
"+",
"$toolbar",
".",
"height",
"(",
")",
"-",
"2",
";",
"}",
"// Position and show the popup\r",
"hidePopups",
"(",
")",
";",
"$popup",
".",
"css",
"(",
"{",
"left",
":",
"left",
",",
"top",
":",
"top",
"}",
")",
".",
"show",
"(",
")",
";",
"// Assign the popup button and click event handler\r",
"if",
"(",
"button",
")",
"{",
"$",
".",
"data",
"(",
"popup",
",",
"BUTTON",
",",
"button",
")",
";",
"$popup",
".",
"bind",
"(",
"CLICK",
",",
"{",
"popup",
":",
"popup",
"}",
",",
"$",
".",
"proxy",
"(",
"popupClick",
",",
"editor",
")",
")",
";",
"}",
"// Focus the first input element if any\r",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"$popup",
".",
"find",
"(",
"\":text,textarea\"",
")",
".",
"eq",
"(",
"0",
")",
".",
"focus",
"(",
")",
".",
"select",
"(",
")",
";",
"}",
",",
"100",
")",
";",
"}"
] | showPopup - shows a popup | [
"showPopup",
"-",
"shows",
"a",
"popup"
] | 0c6333977224d8f4ef7ad40415aa69e0ff76f7b5 | https://github.com/tnantoka/LooseLeaf/blob/0c6333977224d8f4ef7ad40415aa69e0ff76f7b5/skeleton/public/javascripts/lib/cleditor/jquery.cleditor.js#L1024-L1058 |
49,210 | tnantoka/LooseLeaf | skeleton/public/javascripts/lib/cleditor/jquery.cleditor.js | updateFrame | function updateFrame(editor, checkForChange) {
var code = editor.$area.val(),
options = editor.options,
updateFrameCallback = options.updateFrame,
$body = $(editor.doc.body);
// Check for textarea change to avoid unnecessary firing
// of potentially heavy updateFrame callbacks.
if (updateFrameCallback) {
var sum = checksum(code);
if (checkForChange && editor.areaChecksum == sum)
return;
editor.areaChecksum = sum;
}
// Convert the textarea source code into iframe html
var html = updateFrameCallback ? updateFrameCallback(code) : code;
// Prevent script injection attacks by html encoding script tags
html = html.replace(/<(?=\/?script)/ig, "<");
// Update the iframe checksum
if (options.updateTextArea)
editor.frameChecksum = checksum(html);
// Update the iframe and trigger the change event
if (html != $body.html()) {
$body.html(html);
$(editor).triggerHandler(CHANGE);
}
} | javascript | function updateFrame(editor, checkForChange) {
var code = editor.$area.val(),
options = editor.options,
updateFrameCallback = options.updateFrame,
$body = $(editor.doc.body);
// Check for textarea change to avoid unnecessary firing
// of potentially heavy updateFrame callbacks.
if (updateFrameCallback) {
var sum = checksum(code);
if (checkForChange && editor.areaChecksum == sum)
return;
editor.areaChecksum = sum;
}
// Convert the textarea source code into iframe html
var html = updateFrameCallback ? updateFrameCallback(code) : code;
// Prevent script injection attacks by html encoding script tags
html = html.replace(/<(?=\/?script)/ig, "<");
// Update the iframe checksum
if (options.updateTextArea)
editor.frameChecksum = checksum(html);
// Update the iframe and trigger the change event
if (html != $body.html()) {
$body.html(html);
$(editor).triggerHandler(CHANGE);
}
} | [
"function",
"updateFrame",
"(",
"editor",
",",
"checkForChange",
")",
"{",
"var",
"code",
"=",
"editor",
".",
"$area",
".",
"val",
"(",
")",
",",
"options",
"=",
"editor",
".",
"options",
",",
"updateFrameCallback",
"=",
"options",
".",
"updateFrame",
",",
"$body",
"=",
"$",
"(",
"editor",
".",
"doc",
".",
"body",
")",
";",
"// Check for textarea change to avoid unnecessary firing\r",
"// of potentially heavy updateFrame callbacks.\r",
"if",
"(",
"updateFrameCallback",
")",
"{",
"var",
"sum",
"=",
"checksum",
"(",
"code",
")",
";",
"if",
"(",
"checkForChange",
"&&",
"editor",
".",
"areaChecksum",
"==",
"sum",
")",
"return",
";",
"editor",
".",
"areaChecksum",
"=",
"sum",
";",
"}",
"// Convert the textarea source code into iframe html\r",
"var",
"html",
"=",
"updateFrameCallback",
"?",
"updateFrameCallback",
"(",
"code",
")",
":",
"code",
";",
"// Prevent script injection attacks by html encoding script tags\r",
"html",
"=",
"html",
".",
"replace",
"(",
"/",
"<(?=\\/?script)",
"/",
"ig",
",",
"\"<\"",
")",
";",
"// Update the iframe checksum\r",
"if",
"(",
"options",
".",
"updateTextArea",
")",
"editor",
".",
"frameChecksum",
"=",
"checksum",
"(",
"html",
")",
";",
"// Update the iframe and trigger the change event\r",
"if",
"(",
"html",
"!=",
"$body",
".",
"html",
"(",
")",
")",
"{",
"$body",
".",
"html",
"(",
"html",
")",
";",
"$",
"(",
"editor",
")",
".",
"triggerHandler",
"(",
"CHANGE",
")",
";",
"}",
"}"
] | updateFrame - updates the iframe with the textarea contents | [
"updateFrame",
"-",
"updates",
"the",
"iframe",
"with",
"the",
"textarea",
"contents"
] | 0c6333977224d8f4ef7ad40415aa69e0ff76f7b5 | https://github.com/tnantoka/LooseLeaf/blob/0c6333977224d8f4ef7ad40415aa69e0ff76f7b5/skeleton/public/javascripts/lib/cleditor/jquery.cleditor.js#L1066-L1098 |
49,211 | tnantoka/LooseLeaf | skeleton/public/javascripts/lib/cleditor/jquery.cleditor.js | updateTextArea | function updateTextArea(editor, checkForChange) {
var html = $(editor.doc.body).html(),
options = editor.options,
updateTextAreaCallback = options.updateTextArea,
$area = editor.$area;
// Check for iframe change to avoid unnecessary firing
// of potentially heavy updateTextArea callbacks.
if (updateTextAreaCallback) {
var sum = checksum(html);
if (checkForChange && editor.frameChecksum == sum)
return;
editor.frameChecksum = sum;
}
// Convert the iframe html into textarea source code
var code = updateTextAreaCallback ? updateTextAreaCallback(html) : html;
// Update the textarea checksum
if (options.updateFrame)
editor.areaChecksum = checksum(code);
// Update the textarea and trigger the change event
if (code != $area.val()) {
$area.val(code);
$(editor).triggerHandler(CHANGE);
}
} | javascript | function updateTextArea(editor, checkForChange) {
var html = $(editor.doc.body).html(),
options = editor.options,
updateTextAreaCallback = options.updateTextArea,
$area = editor.$area;
// Check for iframe change to avoid unnecessary firing
// of potentially heavy updateTextArea callbacks.
if (updateTextAreaCallback) {
var sum = checksum(html);
if (checkForChange && editor.frameChecksum == sum)
return;
editor.frameChecksum = sum;
}
// Convert the iframe html into textarea source code
var code = updateTextAreaCallback ? updateTextAreaCallback(html) : html;
// Update the textarea checksum
if (options.updateFrame)
editor.areaChecksum = checksum(code);
// Update the textarea and trigger the change event
if (code != $area.val()) {
$area.val(code);
$(editor).triggerHandler(CHANGE);
}
} | [
"function",
"updateTextArea",
"(",
"editor",
",",
"checkForChange",
")",
"{",
"var",
"html",
"=",
"$",
"(",
"editor",
".",
"doc",
".",
"body",
")",
".",
"html",
"(",
")",
",",
"options",
"=",
"editor",
".",
"options",
",",
"updateTextAreaCallback",
"=",
"options",
".",
"updateTextArea",
",",
"$area",
"=",
"editor",
".",
"$area",
";",
"// Check for iframe change to avoid unnecessary firing\r",
"// of potentially heavy updateTextArea callbacks.\r",
"if",
"(",
"updateTextAreaCallback",
")",
"{",
"var",
"sum",
"=",
"checksum",
"(",
"html",
")",
";",
"if",
"(",
"checkForChange",
"&&",
"editor",
".",
"frameChecksum",
"==",
"sum",
")",
"return",
";",
"editor",
".",
"frameChecksum",
"=",
"sum",
";",
"}",
"// Convert the iframe html into textarea source code\r",
"var",
"code",
"=",
"updateTextAreaCallback",
"?",
"updateTextAreaCallback",
"(",
"html",
")",
":",
"html",
";",
"// Update the textarea checksum\r",
"if",
"(",
"options",
".",
"updateFrame",
")",
"editor",
".",
"areaChecksum",
"=",
"checksum",
"(",
"code",
")",
";",
"// Update the textarea and trigger the change event\r",
"if",
"(",
"code",
"!=",
"$area",
".",
"val",
"(",
")",
")",
"{",
"$area",
".",
"val",
"(",
"code",
")",
";",
"$",
"(",
"editor",
")",
".",
"triggerHandler",
"(",
"CHANGE",
")",
";",
"}",
"}"
] | updateTextArea - updates the textarea with the iframe contents | [
"updateTextArea",
"-",
"updates",
"the",
"textarea",
"with",
"the",
"iframe",
"contents"
] | 0c6333977224d8f4ef7ad40415aa69e0ff76f7b5 | https://github.com/tnantoka/LooseLeaf/blob/0c6333977224d8f4ef7ad40415aa69e0ff76f7b5/skeleton/public/javascripts/lib/cleditor/jquery.cleditor.js#L1101-L1130 |
49,212 | redisjs/jsr-server | lib/response.js | send | function send(err, reply, cb) {
// invoke before function, used to end a slowlog
// timer before sending output
if(this.before) this.before();
if(this.cb) {
return this.cb(err, reply);
}
this.conn.write(err || reply, cb);
} | javascript | function send(err, reply, cb) {
// invoke before function, used to end a slowlog
// timer before sending output
if(this.before) this.before();
if(this.cb) {
return this.cb(err, reply);
}
this.conn.write(err || reply, cb);
} | [
"function",
"send",
"(",
"err",
",",
"reply",
",",
"cb",
")",
"{",
"// invoke before function, used to end a slowlog",
"// timer before sending output",
"if",
"(",
"this",
".",
"before",
")",
"this",
".",
"before",
"(",
")",
";",
"if",
"(",
"this",
".",
"cb",
")",
"{",
"return",
"this",
".",
"cb",
"(",
"err",
",",
"reply",
")",
";",
"}",
"this",
".",
"conn",
".",
"write",
"(",
"err",
"||",
"reply",
",",
"cb",
")",
";",
"}"
] | Send a response to the client that made the request.
@param err An error instance.
@param reply A reply array, string, integer or null.
@param cb A write callback. | [
"Send",
"a",
"response",
"to",
"the",
"client",
"that",
"made",
"the",
"request",
"."
] | 49413052d3039524fbdd2ade0ef9bae26cb4d647 | https://github.com/redisjs/jsr-server/blob/49413052d3039524fbdd2ade0ef9bae26cb4d647/lib/response.js#L29-L39 |
49,213 | millionsjs/millions | src/webgl/vertgen.js | genCap | function genCap(point, ux, uy, v1i, v2i, pushVert, pushIndices) {
if (!point.cap) {
genRoundedCap(point, ux, uy, v1i, v2i, pushVert, pushIndices);
} else {
switch (point.cap.type) {
case LineCaps.LINECAP_TYPE_ARROW:
genArrowCap(point, ux, uy, v1i, v2i, pushVert, pushIndices);
break;
case LineCaps.LINECAP_TYPE_ROUNDED:
genRoundedCap(point, ux, uy, v1i, v2i, pushVert, pushIndices);
break;
case LineCaps.LINECAP_TYPE_HALF_ARROW_A:
genHalfArrowACap(point, ux, uy, v1i, v2i, pushVert, pushIndices);
break;
default:
// default to no cap
break;
}
}
} | javascript | function genCap(point, ux, uy, v1i, v2i, pushVert, pushIndices) {
if (!point.cap) {
genRoundedCap(point, ux, uy, v1i, v2i, pushVert, pushIndices);
} else {
switch (point.cap.type) {
case LineCaps.LINECAP_TYPE_ARROW:
genArrowCap(point, ux, uy, v1i, v2i, pushVert, pushIndices);
break;
case LineCaps.LINECAP_TYPE_ROUNDED:
genRoundedCap(point, ux, uy, v1i, v2i, pushVert, pushIndices);
break;
case LineCaps.LINECAP_TYPE_HALF_ARROW_A:
genHalfArrowACap(point, ux, uy, v1i, v2i, pushVert, pushIndices);
break;
default:
// default to no cap
break;
}
}
} | [
"function",
"genCap",
"(",
"point",
",",
"ux",
",",
"uy",
",",
"v1i",
",",
"v2i",
",",
"pushVert",
",",
"pushIndices",
")",
"{",
"if",
"(",
"!",
"point",
".",
"cap",
")",
"{",
"genRoundedCap",
"(",
"point",
",",
"ux",
",",
"uy",
",",
"v1i",
",",
"v2i",
",",
"pushVert",
",",
"pushIndices",
")",
";",
"}",
"else",
"{",
"switch",
"(",
"point",
".",
"cap",
".",
"type",
")",
"{",
"case",
"LineCaps",
".",
"LINECAP_TYPE_ARROW",
":",
"genArrowCap",
"(",
"point",
",",
"ux",
",",
"uy",
",",
"v1i",
",",
"v2i",
",",
"pushVert",
",",
"pushIndices",
")",
";",
"break",
";",
"case",
"LineCaps",
".",
"LINECAP_TYPE_ROUNDED",
":",
"genRoundedCap",
"(",
"point",
",",
"ux",
",",
"uy",
",",
"v1i",
",",
"v2i",
",",
"pushVert",
",",
"pushIndices",
")",
";",
"break",
";",
"case",
"LineCaps",
".",
"LINECAP_TYPE_HALF_ARROW_A",
":",
"genHalfArrowACap",
"(",
"point",
",",
"ux",
",",
"uy",
",",
"v1i",
",",
"v2i",
",",
"pushVert",
",",
"pushIndices",
")",
";",
"break",
";",
"default",
":",
"// default to no cap",
"break",
";",
"}",
"}",
"}"
] | capgen shouldn't push more than two verts and 6 indices | [
"capgen",
"shouldn",
"t",
"push",
"more",
"than",
"two",
"verts",
"and",
"6",
"indices"
] | d56741bb5e88daf4cdebcec24c4ba542534d5d1a | https://github.com/millionsjs/millions/blob/d56741bb5e88daf4cdebcec24c4ba542534d5d1a/src/webgl/vertgen.js#L65-L87 |
49,214 | sendanor/nor-nopg | src/schema/v0033.js | function(db) {
var views_uuid = uuid();
debug.assert(views_uuid).is('uuid');
return db.query('CREATE SEQUENCE views_seq')
.query(['CREATE TABLE IF NOT EXISTS views (',
" id uuid PRIMARY KEY NOT NULL default uuid_generate_v5('"+views_uuid+"', nextval('views_seq'::regclass)::text),",
' types_id uuid REFERENCES types,',
' type text NOT NULL,',
' name text NOT NULL,',
' meta json NOT NULL,',
' active BOOLEAN NOT NULL DEFAULT TRUE,',
' created timestamptz NOT NULL default now(),',
' modified timestamptz NOT NULL default now()',
')'
].join('\n'))
.query('ALTER SEQUENCE views_seq OWNED BY views.id')
.query('CREATE INDEX views_types_id ON views (types_id)')
.query('CREATE INDEX views_types_id_name ON views (types_id,name)')
.query('CREATE INDEX views_type ON views (type)')
.query('CREATE INDEX views_type_name ON views (type,name)')
.query('CREATE UNIQUE INDEX ON views USING btree(types_id, name);')
.query('CREATE TRIGGER views_modified BEFORE UPDATE ON views FOR EACH ROW EXECUTE PROCEDURE moddatetime (modified)')
;
} | javascript | function(db) {
var views_uuid = uuid();
debug.assert(views_uuid).is('uuid');
return db.query('CREATE SEQUENCE views_seq')
.query(['CREATE TABLE IF NOT EXISTS views (',
" id uuid PRIMARY KEY NOT NULL default uuid_generate_v5('"+views_uuid+"', nextval('views_seq'::regclass)::text),",
' types_id uuid REFERENCES types,',
' type text NOT NULL,',
' name text NOT NULL,',
' meta json NOT NULL,',
' active BOOLEAN NOT NULL DEFAULT TRUE,',
' created timestamptz NOT NULL default now(),',
' modified timestamptz NOT NULL default now()',
')'
].join('\n'))
.query('ALTER SEQUENCE views_seq OWNED BY views.id')
.query('CREATE INDEX views_types_id ON views (types_id)')
.query('CREATE INDEX views_types_id_name ON views (types_id,name)')
.query('CREATE INDEX views_type ON views (type)')
.query('CREATE INDEX views_type_name ON views (type,name)')
.query('CREATE UNIQUE INDEX ON views USING btree(types_id, name);')
.query('CREATE TRIGGER views_modified BEFORE UPDATE ON views FOR EACH ROW EXECUTE PROCEDURE moddatetime (modified)')
;
} | [
"function",
"(",
"db",
")",
"{",
"var",
"views_uuid",
"=",
"uuid",
"(",
")",
";",
"debug",
".",
"assert",
"(",
"views_uuid",
")",
".",
"is",
"(",
"'uuid'",
")",
";",
"return",
"db",
".",
"query",
"(",
"'CREATE SEQUENCE views_seq'",
")",
".",
"query",
"(",
"[",
"'CREATE TABLE IF NOT EXISTS views ('",
",",
"\"\tid uuid PRIMARY KEY NOT NULL default uuid_generate_v5('\"",
"+",
"views_uuid",
"+",
"\"', nextval('views_seq'::regclass)::text),\"",
",",
"'\ttypes_id uuid REFERENCES types,'",
",",
"'\ttype text NOT NULL,'",
",",
"'\tname text NOT NULL,'",
",",
"'\tmeta json NOT NULL,'",
",",
"'\tactive BOOLEAN NOT NULL DEFAULT TRUE,'",
",",
"'\tcreated timestamptz NOT NULL default now(),'",
",",
"'\tmodified timestamptz NOT NULL default now()'",
",",
"')'",
"]",
".",
"join",
"(",
"'\\n'",
")",
")",
".",
"query",
"(",
"'ALTER SEQUENCE views_seq OWNED BY views.id'",
")",
".",
"query",
"(",
"'CREATE INDEX views_types_id ON views (types_id)'",
")",
".",
"query",
"(",
"'CREATE INDEX views_types_id_name ON views (types_id,name)'",
")",
".",
"query",
"(",
"'CREATE INDEX views_type ON views (type)'",
")",
".",
"query",
"(",
"'CREATE INDEX views_type_name ON views (type,name)'",
")",
".",
"query",
"(",
"'CREATE UNIQUE INDEX ON views USING btree(types_id, name);'",
")",
".",
"query",
"(",
"'CREATE TRIGGER views_modified BEFORE UPDATE ON views FOR EACH ROW EXECUTE PROCEDURE moddatetime (modified)'",
")",
";",
"}"
] | The views table | [
"The",
"views",
"table"
] | 0d99b86c1a1996b5828b56de8de23700df8bbc0c | https://github.com/sendanor/nor-nopg/blob/0d99b86c1a1996b5828b56de8de23700df8bbc0c/src/schema/v0033.js#L11-L35 |
|
49,215 | yadirhb/vitruvio | source/src/System/EventManager.js | function (target, eventName, listener, useCapture) {
var ver = System.utils.UserAgent.IE.getVersion();
if (is(target, System.EventEmitter)) {
target.on(eventName, listener, useCapture);
} else if ((ver != -1 && ver <= 8) || is(target, Element)) {
if (ver != -1 && ver < 11) {
target.attachEvent("on" + eventName, listener, useCapture);
} else target.addEventListener(eventName, listener, useCapture);
}
return target;
} | javascript | function (target, eventName, listener, useCapture) {
var ver = System.utils.UserAgent.IE.getVersion();
if (is(target, System.EventEmitter)) {
target.on(eventName, listener, useCapture);
} else if ((ver != -1 && ver <= 8) || is(target, Element)) {
if (ver != -1 && ver < 11) {
target.attachEvent("on" + eventName, listener, useCapture);
} else target.addEventListener(eventName, listener, useCapture);
}
return target;
} | [
"function",
"(",
"target",
",",
"eventName",
",",
"listener",
",",
"useCapture",
")",
"{",
"var",
"ver",
"=",
"System",
".",
"utils",
".",
"UserAgent",
".",
"IE",
".",
"getVersion",
"(",
")",
";",
"if",
"(",
"is",
"(",
"target",
",",
"System",
".",
"EventEmitter",
")",
")",
"{",
"target",
".",
"on",
"(",
"eventName",
",",
"listener",
",",
"useCapture",
")",
";",
"}",
"else",
"if",
"(",
"(",
"ver",
"!=",
"-",
"1",
"&&",
"ver",
"<=",
"8",
")",
"||",
"is",
"(",
"target",
",",
"Element",
")",
")",
"{",
"if",
"(",
"ver",
"!=",
"-",
"1",
"&&",
"ver",
"<",
"11",
")",
"{",
"target",
".",
"attachEvent",
"(",
"\"on\"",
"+",
"eventName",
",",
"listener",
",",
"useCapture",
")",
";",
"}",
"else",
"target",
".",
"addEventListener",
"(",
"eventName",
",",
"listener",
",",
"useCapture",
")",
";",
"}",
"return",
"target",
";",
"}"
] | Adds a listener to the specified target.
@param target {Object} The target which will be observed.
@param eventName {String} The event name.
@param listener {Function} The listener instance.
@param useCapture {Boolean} True to use capture or False otherwise.
@returns Target object for chaining. | [
"Adds",
"a",
"listener",
"to",
"the",
"specified",
"target",
"."
] | 2cb640e31bedfb554e6766e1e5c61fbb14226b3b | https://github.com/yadirhb/vitruvio/blob/2cb640e31bedfb554e6766e1e5c61fbb14226b3b/source/src/System/EventManager.js#L14-L24 |
|
49,216 | philipbordallo/eslint-config | src/utilities/combineRules.js | combineRules | async function combineRules(rulesList) {
return Object.keys(rulesList)
.reduce(async (collection, definitions) => {
const isEnabled = rulesList[definitions];
let { default: rules } = await import(`../rules/${definitions}`);
if (!isEnabled) rules = await disableRules(rules);
const previousRules = await collection;
return {
...previousRules,
...rules,
};
}, Promise.resolve({}));
} | javascript | async function combineRules(rulesList) {
return Object.keys(rulesList)
.reduce(async (collection, definitions) => {
const isEnabled = rulesList[definitions];
let { default: rules } = await import(`../rules/${definitions}`);
if (!isEnabled) rules = await disableRules(rules);
const previousRules = await collection;
return {
...previousRules,
...rules,
};
}, Promise.resolve({}));
} | [
"async",
"function",
"combineRules",
"(",
"rulesList",
")",
"{",
"return",
"Object",
".",
"keys",
"(",
"rulesList",
")",
".",
"reduce",
"(",
"async",
"(",
"collection",
",",
"definitions",
")",
"=>",
"{",
"const",
"isEnabled",
"=",
"rulesList",
"[",
"definitions",
"]",
";",
"let",
"{",
"default",
":",
"rules",
"}",
"=",
"await",
"import",
"(",
"`",
"${",
"definitions",
"}",
"`",
")",
";",
"if",
"(",
"!",
"isEnabled",
")",
"rules",
"=",
"await",
"disableRules",
"(",
"rules",
")",
";",
"const",
"previousRules",
"=",
"await",
"collection",
";",
"return",
"{",
"...",
"previousRules",
",",
"...",
"rules",
",",
"}",
";",
"}",
",",
"Promise",
".",
"resolve",
"(",
"{",
"}",
")",
")",
";",
"}"
] | Combine all the rules of the rules list given
@param {Object} rulesList – A list of rules to use
@returns {Promise} A promise to return a combined list of all rules | [
"Combine",
"all",
"the",
"rules",
"of",
"the",
"rules",
"list",
"given"
] | a2f1bff442fdb8ee622f842f075fa10d555302a4 | https://github.com/philipbordallo/eslint-config/blob/a2f1bff442fdb8ee622f842f075fa10d555302a4/src/utilities/combineRules.js#L9-L24 |
49,217 | tjmehta/request-to-json | index.js | reqToJSON | function reqToJSON (req, additional) {
additional = additional || []
if (additional === true) {
additional = [
'rawHeaders',
'rawTrailers',
// express/koa
'fresh',
'cookies',
'ip',
'ips',
'stale',
'subdomains'
]
}
var keys = [
'body',
'headers',
'httpVersion',
'method',
'trailers',
'url',
'socket.remoteAddress',
// express/koa
'originalUrl',
'params',
'query'
].concat(additional).sort()
var json = pick(req, keys)
defaults(json, getParsedUrl(req))
return json
} | javascript | function reqToJSON (req, additional) {
additional = additional || []
if (additional === true) {
additional = [
'rawHeaders',
'rawTrailers',
// express/koa
'fresh',
'cookies',
'ip',
'ips',
'stale',
'subdomains'
]
}
var keys = [
'body',
'headers',
'httpVersion',
'method',
'trailers',
'url',
'socket.remoteAddress',
// express/koa
'originalUrl',
'params',
'query'
].concat(additional).sort()
var json = pick(req, keys)
defaults(json, getParsedUrl(req))
return json
} | [
"function",
"reqToJSON",
"(",
"req",
",",
"additional",
")",
"{",
"additional",
"=",
"additional",
"||",
"[",
"]",
"if",
"(",
"additional",
"===",
"true",
")",
"{",
"additional",
"=",
"[",
"'rawHeaders'",
",",
"'rawTrailers'",
",",
"// express/koa",
"'fresh'",
",",
"'cookies'",
",",
"'ip'",
",",
"'ips'",
",",
"'stale'",
",",
"'subdomains'",
"]",
"}",
"var",
"keys",
"=",
"[",
"'body'",
",",
"'headers'",
",",
"'httpVersion'",
",",
"'method'",
",",
"'trailers'",
",",
"'url'",
",",
"'socket.remoteAddress'",
",",
"// express/koa",
"'originalUrl'",
",",
"'params'",
",",
"'query'",
"]",
".",
"concat",
"(",
"additional",
")",
".",
"sort",
"(",
")",
"var",
"json",
"=",
"pick",
"(",
"req",
",",
"keys",
")",
"defaults",
"(",
"json",
",",
"getParsedUrl",
"(",
"req",
")",
")",
"return",
"json",
"}"
] | return a json representation of a request
@param {IncomingMessage} req request (client incoming-message or client-request)
@param {Array} additional additional properties to pick from request
@return {Object} resJSON | [
"return",
"a",
"json",
"representation",
"of",
"a",
"request"
] | c923b13c84e718e509132d27e741666c77bb7cbf | https://github.com/tjmehta/request-to-json/blob/c923b13c84e718e509132d27e741666c77bb7cbf/index.js#L14-L46 |
49,218 | on-point/thin-orm | join.js | Join | function Join(name) {
this.name = name;
this.criteria = null;
this.table = null;
this.map = null;
this.type = this.ONE_TO_ONE;
this.default = false;
} | javascript | function Join(name) {
this.name = name;
this.criteria = null;
this.table = null;
this.map = null;
this.type = this.ONE_TO_ONE;
this.default = false;
} | [
"function",
"Join",
"(",
"name",
")",
"{",
"this",
".",
"name",
"=",
"name",
";",
"this",
".",
"criteria",
"=",
"null",
";",
"this",
".",
"table",
"=",
"null",
";",
"this",
".",
"map",
"=",
"null",
";",
"this",
".",
"type",
"=",
"this",
".",
"ONE_TO_ONE",
";",
"this",
".",
"default",
"=",
"false",
";",
"}"
] | a join model | [
"a",
"join",
"model"
] | 761783a133ef6983f46060af68febc07e1f880e8 | https://github.com/on-point/thin-orm/blob/761783a133ef6983f46060af68febc07e1f880e8/join.js#L2-L9 |
49,219 | tolokoban/ToloFrameWork | lib/compiler-js.js | compileDEP | function compileDEP( project, src, watch ) {
const
moduleName = src.name(),
depFilename = Util.replaceExtension( moduleName, '.dep' );
if ( !project.srcOrLibPath( depFilename ) ) return '';
const depFile = new Source( project, depFilename );
let code = '';
try {
const depJSON = ToloframeworkPermissiveJson.parse( depFile.read() );
code = processAttributeVar( project, depJSON, watch, depFile.getAbsoluteFilePath() );
} catch ( ex ) {
Fatal.fire( `Unable to parse JSON dependency file!\n${ex}`, depFile.getAbsoluteFilePath() );
}
/*
* List of files to watch. If one of those files is newer
* that the JS file, we have to recompile.
*/
src.tag( 'watch', watch );
return code;
} | javascript | function compileDEP( project, src, watch ) {
const
moduleName = src.name(),
depFilename = Util.replaceExtension( moduleName, '.dep' );
if ( !project.srcOrLibPath( depFilename ) ) return '';
const depFile = new Source( project, depFilename );
let code = '';
try {
const depJSON = ToloframeworkPermissiveJson.parse( depFile.read() );
code = processAttributeVar( project, depJSON, watch, depFile.getAbsoluteFilePath() );
} catch ( ex ) {
Fatal.fire( `Unable to parse JSON dependency file!\n${ex}`, depFile.getAbsoluteFilePath() );
}
/*
* List of files to watch. If one of those files is newer
* that the JS file, we have to recompile.
*/
src.tag( 'watch', watch );
return code;
} | [
"function",
"compileDEP",
"(",
"project",
",",
"src",
",",
"watch",
")",
"{",
"const",
"moduleName",
"=",
"src",
".",
"name",
"(",
")",
",",
"depFilename",
"=",
"Util",
".",
"replaceExtension",
"(",
"moduleName",
",",
"'.dep'",
")",
";",
"if",
"(",
"!",
"project",
".",
"srcOrLibPath",
"(",
"depFilename",
")",
")",
"return",
"''",
";",
"const",
"depFile",
"=",
"new",
"Source",
"(",
"project",
",",
"depFilename",
")",
";",
"let",
"code",
"=",
"''",
";",
"try",
"{",
"const",
"depJSON",
"=",
"ToloframeworkPermissiveJson",
".",
"parse",
"(",
"depFile",
".",
"read",
"(",
")",
")",
";",
"code",
"=",
"processAttributeVar",
"(",
"project",
",",
"depJSON",
",",
"watch",
",",
"depFile",
".",
"getAbsoluteFilePath",
"(",
")",
")",
";",
"}",
"catch",
"(",
"ex",
")",
"{",
"Fatal",
".",
"fire",
"(",
"`",
"\\n",
"${",
"ex",
"}",
"`",
",",
"depFile",
".",
"getAbsoluteFilePath",
"(",
")",
")",
";",
"}",
"/*\n * List of files to watch. If one of those files is newer\n * that the JS file, we have to recompile.\n */",
"src",
".",
"tag",
"(",
"'watch'",
",",
"watch",
")",
";",
"return",
"code",
";",
"}"
] | DEP file is here to load GLOBAL variable into the module.
@param {Project} project - Current project.
@param {Source} src - Module source file.
@param {array} watch - Array of files to watch for rebuild.
@returns {string} Javascript defining the const variable GLOBAL. | [
"DEP",
"file",
"is",
"here",
"to",
"load",
"GLOBAL",
"variable",
"into",
"the",
"module",
"."
] | 730845a833a9660ebfdb60ad027ebaab5ac871b6 | https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/lib/compiler-js.js#L120-L142 |
49,220 | tolokoban/ToloFrameWork | lib/compiler-js.js | processAttributeVar | function processAttributeVar( project, depJSON, watch, depAbsPath ) {
if ( typeof depJSON.var === 'undefined' ) return '';
let
head = 'const GLOBAL = {',
firstItem = true;
Object.keys( depJSON.var ).forEach( function forEachVarName( varName ) {
const
varFilename = depJSON.var[ varName ],
folder = Path.dirname( depAbsPath ),
srcVar = project.srcOrLibPath( Path.join( folder, varFilename ) ) ||
project.srcOrLibPath( `mod/${varFilename}` ) ||
project.srcOrLibPath( varFilename );
if ( !srcVar ) {
Fatal.fire(
`Unable to find dendency file "${varFilename}" nor "mod/${varFilename}"!`,
depAbsPath
);
}
Util.pushUnique( watch, srcVar );
if ( firstItem ) {
firstItem = false;
} else {
head += ',';
}
const source = new Source( project, srcVar );
head += `\n ${JSON.stringify(varName)}: ${JSON.stringify(source.read())}`;
} );
head += "};\n";
return head;
} | javascript | function processAttributeVar( project, depJSON, watch, depAbsPath ) {
if ( typeof depJSON.var === 'undefined' ) return '';
let
head = 'const GLOBAL = {',
firstItem = true;
Object.keys( depJSON.var ).forEach( function forEachVarName( varName ) {
const
varFilename = depJSON.var[ varName ],
folder = Path.dirname( depAbsPath ),
srcVar = project.srcOrLibPath( Path.join( folder, varFilename ) ) ||
project.srcOrLibPath( `mod/${varFilename}` ) ||
project.srcOrLibPath( varFilename );
if ( !srcVar ) {
Fatal.fire(
`Unable to find dendency file "${varFilename}" nor "mod/${varFilename}"!`,
depAbsPath
);
}
Util.pushUnique( watch, srcVar );
if ( firstItem ) {
firstItem = false;
} else {
head += ',';
}
const source = new Source( project, srcVar );
head += `\n ${JSON.stringify(varName)}: ${JSON.stringify(source.read())}`;
} );
head += "};\n";
return head;
} | [
"function",
"processAttributeVar",
"(",
"project",
",",
"depJSON",
",",
"watch",
",",
"depAbsPath",
")",
"{",
"if",
"(",
"typeof",
"depJSON",
".",
"var",
"===",
"'undefined'",
")",
"return",
"''",
";",
"let",
"head",
"=",
"'const GLOBAL = {'",
",",
"firstItem",
"=",
"true",
";",
"Object",
".",
"keys",
"(",
"depJSON",
".",
"var",
")",
".",
"forEach",
"(",
"function",
"forEachVarName",
"(",
"varName",
")",
"{",
"const",
"varFilename",
"=",
"depJSON",
".",
"var",
"[",
"varName",
"]",
",",
"folder",
"=",
"Path",
".",
"dirname",
"(",
"depAbsPath",
")",
",",
"srcVar",
"=",
"project",
".",
"srcOrLibPath",
"(",
"Path",
".",
"join",
"(",
"folder",
",",
"varFilename",
")",
")",
"||",
"project",
".",
"srcOrLibPath",
"(",
"`",
"${",
"varFilename",
"}",
"`",
")",
"||",
"project",
".",
"srcOrLibPath",
"(",
"varFilename",
")",
";",
"if",
"(",
"!",
"srcVar",
")",
"{",
"Fatal",
".",
"fire",
"(",
"`",
"${",
"varFilename",
"}",
"${",
"varFilename",
"}",
"`",
",",
"depAbsPath",
")",
";",
"}",
"Util",
".",
"pushUnique",
"(",
"watch",
",",
"srcVar",
")",
";",
"if",
"(",
"firstItem",
")",
"{",
"firstItem",
"=",
"false",
";",
"}",
"else",
"{",
"head",
"+=",
"','",
";",
"}",
"const",
"source",
"=",
"new",
"Source",
"(",
"project",
",",
"srcVar",
")",
";",
"head",
"+=",
"`",
"\\n",
"${",
"JSON",
".",
"stringify",
"(",
"varName",
")",
"}",
"${",
"JSON",
".",
"stringify",
"(",
"source",
".",
"read",
"(",
")",
")",
"}",
"`",
";",
"}",
")",
";",
"head",
"+=",
"\"};\\n\"",
";",
"return",
"head",
";",
"}"
] | In the DEP file, we can find the attribute "var".
It will load text file contents into the GLOBAL variable of the module.
@param {Project} project - Current project.
@param {objetc} depJSON - Parsing of the JSON DEP file.
@param {array} watch - Array of files to watch for rebuild.
@param {string} depAbsPath - Absolute path of the DEP file.
@returns {string} Javascript defining the const variable GLOBAL. | [
"In",
"the",
"DEP",
"file",
"we",
"can",
"find",
"the",
"attribute",
"var",
".",
"It",
"will",
"load",
"text",
"file",
"contents",
"into",
"the",
"GLOBAL",
"variable",
"of",
"the",
"module",
"."
] | 730845a833a9660ebfdb60ad027ebaab5ac871b6 | https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/lib/compiler-js.js#L154-L187 |
49,221 | tblobaum/fleet-panel | public/bundle.js | filtered | function filtered(js) {
return js.substr(1).split('|').reduce(function(js, filter){
var parts = filter.split(':')
, name = parts.shift()
, args = parts.shift() || '';
if (args) args = ', ' + args;
return 'filters.' + name + '(' + js + args + ')';
});
} | javascript | function filtered(js) {
return js.substr(1).split('|').reduce(function(js, filter){
var parts = filter.split(':')
, name = parts.shift()
, args = parts.shift() || '';
if (args) args = ', ' + args;
return 'filters.' + name + '(' + js + args + ')';
});
} | [
"function",
"filtered",
"(",
"js",
")",
"{",
"return",
"js",
".",
"substr",
"(",
"1",
")",
".",
"split",
"(",
"'|'",
")",
".",
"reduce",
"(",
"function",
"(",
"js",
",",
"filter",
")",
"{",
"var",
"parts",
"=",
"filter",
".",
"split",
"(",
"':'",
")",
",",
"name",
"=",
"parts",
".",
"shift",
"(",
")",
",",
"args",
"=",
"parts",
".",
"shift",
"(",
")",
"||",
"''",
";",
"if",
"(",
"args",
")",
"args",
"=",
"', '",
"+",
"args",
";",
"return",
"'filters.'",
"+",
"name",
"+",
"'('",
"+",
"js",
"+",
"args",
"+",
"')'",
";",
"}",
")",
";",
"}"
] | Translate filtered code into function calls.
@param {String} js
@return {String}
@api private | [
"Translate",
"filtered",
"code",
"into",
"function",
"calls",
"."
] | 0ec0b4df68e54ff7b0b60c7d21b8d8520075bceb | https://github.com/tblobaum/fleet-panel/blob/0ec0b4df68e54ff7b0b60c7d21b8d8520075bceb/public/bundle.js#L4604-L4612 |
49,222 | tblobaum/fleet-panel | public/bundle.js | resolveInclude | function resolveInclude(name, filename) {
var path = join(dirname(filename), name);
var ext = extname(name);
if (!ext) path += '.ejs';
return path;
} | javascript | function resolveInclude(name, filename) {
var path = join(dirname(filename), name);
var ext = extname(name);
if (!ext) path += '.ejs';
return path;
} | [
"function",
"resolveInclude",
"(",
"name",
",",
"filename",
")",
"{",
"var",
"path",
"=",
"join",
"(",
"dirname",
"(",
"filename",
")",
",",
"name",
")",
";",
"var",
"ext",
"=",
"extname",
"(",
"name",
")",
";",
"if",
"(",
"!",
"ext",
")",
"path",
"+=",
"'.ejs'",
";",
"return",
"path",
";",
"}"
] | Resolve include `name` relative to `filename`.
@param {String} name
@param {String} filename
@return {String}
@api private | [
"Resolve",
"include",
"name",
"relative",
"to",
"filename",
"."
] | 0ec0b4df68e54ff7b0b60c7d21b8d8520075bceb | https://github.com/tblobaum/fleet-panel/blob/0ec0b4df68e54ff7b0b60c7d21b8d8520075bceb/public/bundle.js#L4853-L4858 |
49,223 | bentomas/node-async-testing | lib/console-runner.js | suiteFinished | function suiteFinished(suite, status, results) {
suite.finished = true;
suite.status = status;
suite.duration = new Date() - suite.startTime;
suite.results = results;
delete suite.startTime;
if (suite.index == finishedIndex) {
for (var i = finishedIndex; i < suites.length; i++) {
if (suites[i].finished) {
while(suites[i].queuedTestResults.length) {
output.testDone(suites[i], suites[i].queuedTestResults.shift());
}
output.suiteDone(suites[i]);
}
else {
break;
}
}
finishedIndex = i;
}
if (finishedIndex >= suites.length) {
output.allDone();
}
startNextSuite();
} | javascript | function suiteFinished(suite, status, results) {
suite.finished = true;
suite.status = status;
suite.duration = new Date() - suite.startTime;
suite.results = results;
delete suite.startTime;
if (suite.index == finishedIndex) {
for (var i = finishedIndex; i < suites.length; i++) {
if (suites[i].finished) {
while(suites[i].queuedTestResults.length) {
output.testDone(suites[i], suites[i].queuedTestResults.shift());
}
output.suiteDone(suites[i]);
}
else {
break;
}
}
finishedIndex = i;
}
if (finishedIndex >= suites.length) {
output.allDone();
}
startNextSuite();
} | [
"function",
"suiteFinished",
"(",
"suite",
",",
"status",
",",
"results",
")",
"{",
"suite",
".",
"finished",
"=",
"true",
";",
"suite",
".",
"status",
"=",
"status",
";",
"suite",
".",
"duration",
"=",
"new",
"Date",
"(",
")",
"-",
"suite",
".",
"startTime",
";",
"suite",
".",
"results",
"=",
"results",
";",
"delete",
"suite",
".",
"startTime",
";",
"if",
"(",
"suite",
".",
"index",
"==",
"finishedIndex",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"finishedIndex",
";",
"i",
"<",
"suites",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"suites",
"[",
"i",
"]",
".",
"finished",
")",
"{",
"while",
"(",
"suites",
"[",
"i",
"]",
".",
"queuedTestResults",
".",
"length",
")",
"{",
"output",
".",
"testDone",
"(",
"suites",
"[",
"i",
"]",
",",
"suites",
"[",
"i",
"]",
".",
"queuedTestResults",
".",
"shift",
"(",
")",
")",
";",
"}",
"output",
".",
"suiteDone",
"(",
"suites",
"[",
"i",
"]",
")",
";",
"}",
"else",
"{",
"break",
";",
"}",
"}",
"finishedIndex",
"=",
"i",
";",
"}",
"if",
"(",
"finishedIndex",
">=",
"suites",
".",
"length",
")",
"{",
"output",
".",
"allDone",
"(",
")",
";",
"}",
"startNextSuite",
"(",
")",
";",
"}"
] | we want to output the suite results in the order they were given to us, so as suties finish we buffer them, and then output them in the right order when we can | [
"we",
"want",
"to",
"output",
"the",
"suite",
"results",
"in",
"the",
"order",
"they",
"were",
"given",
"to",
"us",
"so",
"as",
"suties",
"finish",
"we",
"buffer",
"them",
"and",
"then",
"output",
"them",
"in",
"the",
"right",
"order",
"when",
"we",
"can"
] | 82384ba4b8444e4659464bad661788827ea721aa | https://github.com/bentomas/node-async-testing/blob/82384ba4b8444e4659464bad661788827ea721aa/lib/console-runner.js#L127-L154 |
49,224 | BugBusterSWE/burstmake | src/solver.js | function ( config, actual ) {
// In this way, if any topic declare the compilerOptions this will not
// include in the tsconfig.json
if ( actual.compilerOptions !== undefined ) {
if ( config.compilerOptions === undefined ) {
// Attach an empty object
config.compilerOptions = {};
}
// In the case that a descendant set a option already set,
// the option will set at the value of descendant.
if ( actual.compilerOptions.module !== undefined ) {
config.compilerOptions.module = actual.compilerOptions.module;
} if ( actual.compilerOptions.target !== undefined ) {
config.compilerOptions.target = actual.compilerOptions.target;
} if ( actual.compilerOptions.moduleResolution !== undefined ) {
config.compilerOptions.moduleResolution =
actual.compilerOptions.moduleResolution;
} if ( actual.compilerOptions.noImplicitAny !== undefined ) {
config.compilerOptions.noImplicitAny =
actual.compilerOptions.noImplicitAny;
} if ( actual.compilerOptions.removeComments !== undefined ) {
config.compilerOptions.removeComments =
actual.compilerOptions.removeComments;
} if ( actual.compilerOptions.preserveConstEnums !== undefined ) {
config.compilerOptions.preserveConstEnums =
actual.compilerOptions.preserveConstEnums;
} if ( actual.compilerOptions.outDir !== undefined ) {
config.compilerOptions.outDir =
// Append a slash at the end of path because node return relative path
// but tsconfig want the path with the slah final
relative( actual.compilerOptions.outDir ) + "/";
} if ( actual.compilerOptions.outFile !== undefined ) {
config.compilerOptions.outFile =
relative( actual.compilerOptions.outFile );
} if ( actual.compilerOptions.sourceMap !== undefined ) {
config.compilerOptions.sourceMap =
actual.compilerOptions.sourceMap;
} if ( actual.compilerOptions.declaration !== undefined ) {
config.compilerOptions.declaration =
actual.compilerOptions.declaration;
} if ( actual.compilerOptions.noEmitOnError !== undefined ) {
config.compilerOptions.noEmitOnError =
actual.compilerOptions.noEmitOnError;
} if ( actual.compilerOptions.jsx !== undefined ) {
config.compilerOptions.jsx =
actual.compilerOptions.jsx;
}
} if ( actual.include !== undefined ) {
if ( config.include === undefined ) {
// Attach an empty array
config.include = [];
}
// Push all relative path
config.include = config.include.concat(
// Apply the transformation function
actual.include.map( relative )
);
} if ( actual.exclude !== undefined ) {
config.exclude = actual.exclude;
}
} | javascript | function ( config, actual ) {
// In this way, if any topic declare the compilerOptions this will not
// include in the tsconfig.json
if ( actual.compilerOptions !== undefined ) {
if ( config.compilerOptions === undefined ) {
// Attach an empty object
config.compilerOptions = {};
}
// In the case that a descendant set a option already set,
// the option will set at the value of descendant.
if ( actual.compilerOptions.module !== undefined ) {
config.compilerOptions.module = actual.compilerOptions.module;
} if ( actual.compilerOptions.target !== undefined ) {
config.compilerOptions.target = actual.compilerOptions.target;
} if ( actual.compilerOptions.moduleResolution !== undefined ) {
config.compilerOptions.moduleResolution =
actual.compilerOptions.moduleResolution;
} if ( actual.compilerOptions.noImplicitAny !== undefined ) {
config.compilerOptions.noImplicitAny =
actual.compilerOptions.noImplicitAny;
} if ( actual.compilerOptions.removeComments !== undefined ) {
config.compilerOptions.removeComments =
actual.compilerOptions.removeComments;
} if ( actual.compilerOptions.preserveConstEnums !== undefined ) {
config.compilerOptions.preserveConstEnums =
actual.compilerOptions.preserveConstEnums;
} if ( actual.compilerOptions.outDir !== undefined ) {
config.compilerOptions.outDir =
// Append a slash at the end of path because node return relative path
// but tsconfig want the path with the slah final
relative( actual.compilerOptions.outDir ) + "/";
} if ( actual.compilerOptions.outFile !== undefined ) {
config.compilerOptions.outFile =
relative( actual.compilerOptions.outFile );
} if ( actual.compilerOptions.sourceMap !== undefined ) {
config.compilerOptions.sourceMap =
actual.compilerOptions.sourceMap;
} if ( actual.compilerOptions.declaration !== undefined ) {
config.compilerOptions.declaration =
actual.compilerOptions.declaration;
} if ( actual.compilerOptions.noEmitOnError !== undefined ) {
config.compilerOptions.noEmitOnError =
actual.compilerOptions.noEmitOnError;
} if ( actual.compilerOptions.jsx !== undefined ) {
config.compilerOptions.jsx =
actual.compilerOptions.jsx;
}
} if ( actual.include !== undefined ) {
if ( config.include === undefined ) {
// Attach an empty array
config.include = [];
}
// Push all relative path
config.include = config.include.concat(
// Apply the transformation function
actual.include.map( relative )
);
} if ( actual.exclude !== undefined ) {
config.exclude = actual.exclude;
}
} | [
"function",
"(",
"config",
",",
"actual",
")",
"{",
"// In this way, if any topic declare the compilerOptions this will not",
"// include in the tsconfig.json",
"if",
"(",
"actual",
".",
"compilerOptions",
"!==",
"undefined",
")",
"{",
"if",
"(",
"config",
".",
"compilerOptions",
"===",
"undefined",
")",
"{",
"// Attach an empty object",
"config",
".",
"compilerOptions",
"=",
"{",
"}",
";",
"}",
"// In the case that a descendant set a option already set,",
"// the option will set at the value of descendant.",
"if",
"(",
"actual",
".",
"compilerOptions",
".",
"module",
"!==",
"undefined",
")",
"{",
"config",
".",
"compilerOptions",
".",
"module",
"=",
"actual",
".",
"compilerOptions",
".",
"module",
";",
"}",
"if",
"(",
"actual",
".",
"compilerOptions",
".",
"target",
"!==",
"undefined",
")",
"{",
"config",
".",
"compilerOptions",
".",
"target",
"=",
"actual",
".",
"compilerOptions",
".",
"target",
";",
"}",
"if",
"(",
"actual",
".",
"compilerOptions",
".",
"moduleResolution",
"!==",
"undefined",
")",
"{",
"config",
".",
"compilerOptions",
".",
"moduleResolution",
"=",
"actual",
".",
"compilerOptions",
".",
"moduleResolution",
";",
"}",
"if",
"(",
"actual",
".",
"compilerOptions",
".",
"noImplicitAny",
"!==",
"undefined",
")",
"{",
"config",
".",
"compilerOptions",
".",
"noImplicitAny",
"=",
"actual",
".",
"compilerOptions",
".",
"noImplicitAny",
";",
"}",
"if",
"(",
"actual",
".",
"compilerOptions",
".",
"removeComments",
"!==",
"undefined",
")",
"{",
"config",
".",
"compilerOptions",
".",
"removeComments",
"=",
"actual",
".",
"compilerOptions",
".",
"removeComments",
";",
"}",
"if",
"(",
"actual",
".",
"compilerOptions",
".",
"preserveConstEnums",
"!==",
"undefined",
")",
"{",
"config",
".",
"compilerOptions",
".",
"preserveConstEnums",
"=",
"actual",
".",
"compilerOptions",
".",
"preserveConstEnums",
";",
"}",
"if",
"(",
"actual",
".",
"compilerOptions",
".",
"outDir",
"!==",
"undefined",
")",
"{",
"config",
".",
"compilerOptions",
".",
"outDir",
"=",
"// Append a slash at the end of path because node return relative path",
"// but tsconfig want the path with the slah final",
"relative",
"(",
"actual",
".",
"compilerOptions",
".",
"outDir",
")",
"+",
"\"/\"",
";",
"}",
"if",
"(",
"actual",
".",
"compilerOptions",
".",
"outFile",
"!==",
"undefined",
")",
"{",
"config",
".",
"compilerOptions",
".",
"outFile",
"=",
"relative",
"(",
"actual",
".",
"compilerOptions",
".",
"outFile",
")",
";",
"}",
"if",
"(",
"actual",
".",
"compilerOptions",
".",
"sourceMap",
"!==",
"undefined",
")",
"{",
"config",
".",
"compilerOptions",
".",
"sourceMap",
"=",
"actual",
".",
"compilerOptions",
".",
"sourceMap",
";",
"}",
"if",
"(",
"actual",
".",
"compilerOptions",
".",
"declaration",
"!==",
"undefined",
")",
"{",
"config",
".",
"compilerOptions",
".",
"declaration",
"=",
"actual",
".",
"compilerOptions",
".",
"declaration",
";",
"}",
"if",
"(",
"actual",
".",
"compilerOptions",
".",
"noEmitOnError",
"!==",
"undefined",
")",
"{",
"config",
".",
"compilerOptions",
".",
"noEmitOnError",
"=",
"actual",
".",
"compilerOptions",
".",
"noEmitOnError",
";",
"}",
"if",
"(",
"actual",
".",
"compilerOptions",
".",
"jsx",
"!==",
"undefined",
")",
"{",
"config",
".",
"compilerOptions",
".",
"jsx",
"=",
"actual",
".",
"compilerOptions",
".",
"jsx",
";",
"}",
"}",
"if",
"(",
"actual",
".",
"include",
"!==",
"undefined",
")",
"{",
"if",
"(",
"config",
".",
"include",
"===",
"undefined",
")",
"{",
"// Attach an empty array",
"config",
".",
"include",
"=",
"[",
"]",
";",
"}",
"// Push all relative path",
"config",
".",
"include",
"=",
"config",
".",
"include",
".",
"concat",
"(",
"// Apply the transformation function",
"actual",
".",
"include",
".",
"map",
"(",
"relative",
")",
")",
";",
"}",
"if",
"(",
"actual",
".",
"exclude",
"!==",
"undefined",
")",
"{",
"config",
".",
"exclude",
"=",
"actual",
".",
"exclude",
";",
"}",
"}"
] | The function stored in buildRule tell as get the configuration in the actual level of hierarchy and how it integrate with them. | [
"The",
"function",
"stored",
"in",
"buildRule",
"tell",
"as",
"get",
"the",
"configuration",
"in",
"the",
"actual",
"level",
"of",
"hierarchy",
"and",
"how",
"it",
"integrate",
"with",
"them",
"."
] | 2027b650e451f49d1f9ef64af6038f93b4e744c5 | https://github.com/BugBusterSWE/burstmake/blob/2027b650e451f49d1f9ef64af6038f93b4e744c5/src/solver.js#L51-L126 |
|
49,225 | redisjs/jsr-exec | lib/database.js | proxy | function proxy(req, res) {
var method = req.db[req.cmd]
, args;
// append the request object to the args
// required so that database events can pass
// request and thereby connection information
// when emitting events by key, this allows
// transactional semantics
args = req.args.slice(0).concat(req);
return method.apply(req.db, args);
} | javascript | function proxy(req, res) {
var method = req.db[req.cmd]
, args;
// append the request object to the args
// required so that database events can pass
// request and thereby connection information
// when emitting events by key, this allows
// transactional semantics
args = req.args.slice(0).concat(req);
return method.apply(req.db, args);
} | [
"function",
"proxy",
"(",
"req",
",",
"res",
")",
"{",
"var",
"method",
"=",
"req",
".",
"db",
"[",
"req",
".",
"cmd",
"]",
",",
"args",
";",
"// append the request object to the args",
"// required so that database events can pass",
"// request and thereby connection information",
"// when emitting events by key, this allows",
"// transactional semantics",
"args",
"=",
"req",
".",
"args",
".",
"slice",
"(",
"0",
")",
".",
"concat",
"(",
"req",
")",
";",
"return",
"method",
".",
"apply",
"(",
"req",
".",
"db",
",",
"args",
")",
";",
"}"
] | Proxy command execution to a database method.
This method returns the reply from the database method
but does not send a reply to a client.
Sometimes command implementations may wish to operate on the reply
before returning to the client, typically to coerce a database response.
@param req The incoming request.
@param res The outbound response. | [
"Proxy",
"command",
"execution",
"to",
"a",
"database",
"method",
"."
] | aeaf62051b12487cf1c41125acacd03deb96d539 | https://github.com/redisjs/jsr-exec/blob/aeaf62051b12487cf1c41125acacd03deb96d539/lib/database.js#L27-L38 |
49,226 | redisjs/jsr-exec | lib/database.js | execute | function execute(req, res) {
var proxy = req.exec ? req.exec.proxy : this.proxy;
res.send(null, proxy(req, res));
} | javascript | function execute(req, res) {
var proxy = req.exec ? req.exec.proxy : this.proxy;
res.send(null, proxy(req, res));
} | [
"function",
"execute",
"(",
"req",
",",
"res",
")",
"{",
"var",
"proxy",
"=",
"req",
".",
"exec",
"?",
"req",
".",
"exec",
".",
"proxy",
":",
"this",
".",
"proxy",
";",
"res",
".",
"send",
"(",
"null",
",",
"proxy",
"(",
"req",
",",
"res",
")",
")",
";",
"}"
] | Abstract database command proxy.
@param req The incoming request.
@param res The outbound response. | [
"Abstract",
"database",
"command",
"proxy",
"."
] | aeaf62051b12487cf1c41125acacd03deb96d539 | https://github.com/redisjs/jsr-exec/blob/aeaf62051b12487cf1c41125acacd03deb96d539/lib/database.js#L46-L49 |
49,227 | ENOW-IJI/ENOW-console | dist/src/util.js | function (model, values, functionPrefix) {
// for a string, see if it has parameter matches, and if so, try to make the substitutions.
var getValue = function (fromString) {
var matches = fromString.match(/(\${.*?})/g);
if (matches != null) {
for (var i = 0; i < matches.length; i++) {
var val = values[matches[i].substring(2, matches[i].length - 1)] || "";
if (val != null) {
fromString = fromString.replace(matches[i], val);
}
}
}
return fromString;
},
// process one entry.
_one = function (d) {
if (d != null) {
if (_iss(d)) {
return getValue(d);
}
else if (_isf(d) && (functionPrefix == null || (d.name || "").indexOf(functionPrefix) === 0)) {
return d(values);
}
else if (_isa(d)) {
var r = [];
for (var i = 0; i < d.length; i++)
r.push(_one(d[i]));
return r;
}
else if (_iso(d)) {
var s = {};
for (var j in d) {
s[j] = _one(d[j]);
}
return s;
}
else {
return d;
}
}
};
return _one(model);
} | javascript | function (model, values, functionPrefix) {
// for a string, see if it has parameter matches, and if so, try to make the substitutions.
var getValue = function (fromString) {
var matches = fromString.match(/(\${.*?})/g);
if (matches != null) {
for (var i = 0; i < matches.length; i++) {
var val = values[matches[i].substring(2, matches[i].length - 1)] || "";
if (val != null) {
fromString = fromString.replace(matches[i], val);
}
}
}
return fromString;
},
// process one entry.
_one = function (d) {
if (d != null) {
if (_iss(d)) {
return getValue(d);
}
else if (_isf(d) && (functionPrefix == null || (d.name || "").indexOf(functionPrefix) === 0)) {
return d(values);
}
else if (_isa(d)) {
var r = [];
for (var i = 0; i < d.length; i++)
r.push(_one(d[i]));
return r;
}
else if (_iso(d)) {
var s = {};
for (var j in d) {
s[j] = _one(d[j]);
}
return s;
}
else {
return d;
}
}
};
return _one(model);
} | [
"function",
"(",
"model",
",",
"values",
",",
"functionPrefix",
")",
"{",
"// for a string, see if it has parameter matches, and if so, try to make the substitutions.",
"var",
"getValue",
"=",
"function",
"(",
"fromString",
")",
"{",
"var",
"matches",
"=",
"fromString",
".",
"match",
"(",
"/",
"(\\${.*?})",
"/",
"g",
")",
";",
"if",
"(",
"matches",
"!=",
"null",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"matches",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"val",
"=",
"values",
"[",
"matches",
"[",
"i",
"]",
".",
"substring",
"(",
"2",
",",
"matches",
"[",
"i",
"]",
".",
"length",
"-",
"1",
")",
"]",
"||",
"\"\"",
";",
"if",
"(",
"val",
"!=",
"null",
")",
"{",
"fromString",
"=",
"fromString",
".",
"replace",
"(",
"matches",
"[",
"i",
"]",
",",
"val",
")",
";",
"}",
"}",
"}",
"return",
"fromString",
";",
"}",
",",
"// process one entry.",
"_one",
"=",
"function",
"(",
"d",
")",
"{",
"if",
"(",
"d",
"!=",
"null",
")",
"{",
"if",
"(",
"_iss",
"(",
"d",
")",
")",
"{",
"return",
"getValue",
"(",
"d",
")",
";",
"}",
"else",
"if",
"(",
"_isf",
"(",
"d",
")",
"&&",
"(",
"functionPrefix",
"==",
"null",
"||",
"(",
"d",
".",
"name",
"||",
"\"\"",
")",
".",
"indexOf",
"(",
"functionPrefix",
")",
"===",
"0",
")",
")",
"{",
"return",
"d",
"(",
"values",
")",
";",
"}",
"else",
"if",
"(",
"_isa",
"(",
"d",
")",
")",
"{",
"var",
"r",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"d",
".",
"length",
";",
"i",
"++",
")",
"r",
".",
"push",
"(",
"_one",
"(",
"d",
"[",
"i",
"]",
")",
")",
";",
"return",
"r",
";",
"}",
"else",
"if",
"(",
"_iso",
"(",
"d",
")",
")",
"{",
"var",
"s",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"j",
"in",
"d",
")",
"{",
"s",
"[",
"j",
"]",
"=",
"_one",
"(",
"d",
"[",
"j",
"]",
")",
";",
"}",
"return",
"s",
";",
"}",
"else",
"{",
"return",
"d",
";",
"}",
"}",
"}",
";",
"return",
"_one",
"(",
"model",
")",
";",
"}"
] | take the given model and expand out any parameters. 'functionPrefix' is optional, and if present, helps jsplumb figure out what to do if a value is a Function. if you do not provide it, jsplumb will run the given values through any functions it finds, and use the function's output as the value in the result. if you do provide the prefix, only functions that are named and have this prefix will be executed; other functions will be passed as values to the output. | [
"take",
"the",
"given",
"model",
"and",
"expand",
"out",
"any",
"parameters",
".",
"functionPrefix",
"is",
"optional",
"and",
"if",
"present",
"helps",
"jsplumb",
"figure",
"out",
"what",
"to",
"do",
"if",
"a",
"value",
"is",
"a",
"Function",
".",
"if",
"you",
"do",
"not",
"provide",
"it",
"jsplumb",
"will",
"run",
"the",
"given",
"values",
"through",
"any",
"functions",
"it",
"finds",
"and",
"use",
"the",
"function",
"s",
"output",
"as",
"the",
"value",
"in",
"the",
"result",
".",
"if",
"you",
"do",
"provide",
"the",
"prefix",
"only",
"functions",
"that",
"are",
"named",
"and",
"have",
"this",
"prefix",
"will",
"be",
"executed",
";",
"other",
"functions",
"will",
"be",
"passed",
"as",
"values",
"to",
"the",
"output",
"."
] | f241ed4e645a7da0cd1a6ca86e896a5b73be53e5 | https://github.com/ENOW-IJI/ENOW-console/blob/f241ed4e645a7da0cd1a6ca86e896a5b73be53e5/dist/src/util.js#L187-L230 |
|
49,228 | IonicaBizau/barbe | lib/index.js | barbe | function barbe(text, arr, data) {
if (!Array.isArray(arr)) {
data = arr;
arr = ["{", "}"];
}
if (!data || data.constructor !== Object) {
return text;
}
arr = arr.map(regexEscape);
let deep = (obj, path) => {
iterateObject(obj, (value, c) => {
path.push(c);
if (typpy(value, Object)) {
deep(value, path);
path.pop();
return;
}
text = text.replace(
new RegExp(arr[0] + path.join(".") + arr[1], "gm")
, typpy(value, Function) ? value : String(value)
);
path.pop();
});
};
deep(data, []);
return text;
} | javascript | function barbe(text, arr, data) {
if (!Array.isArray(arr)) {
data = arr;
arr = ["{", "}"];
}
if (!data || data.constructor !== Object) {
return text;
}
arr = arr.map(regexEscape);
let deep = (obj, path) => {
iterateObject(obj, (value, c) => {
path.push(c);
if (typpy(value, Object)) {
deep(value, path);
path.pop();
return;
}
text = text.replace(
new RegExp(arr[0] + path.join(".") + arr[1], "gm")
, typpy(value, Function) ? value : String(value)
);
path.pop();
});
};
deep(data, []);
return text;
} | [
"function",
"barbe",
"(",
"text",
",",
"arr",
",",
"data",
")",
"{",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"arr",
")",
")",
"{",
"data",
"=",
"arr",
";",
"arr",
"=",
"[",
"\"{\"",
",",
"\"}\"",
"]",
";",
"}",
"if",
"(",
"!",
"data",
"||",
"data",
".",
"constructor",
"!==",
"Object",
")",
"{",
"return",
"text",
";",
"}",
"arr",
"=",
"arr",
".",
"map",
"(",
"regexEscape",
")",
";",
"let",
"deep",
"=",
"(",
"obj",
",",
"path",
")",
"=>",
"{",
"iterateObject",
"(",
"obj",
",",
"(",
"value",
",",
"c",
")",
"=>",
"{",
"path",
".",
"push",
"(",
"c",
")",
";",
"if",
"(",
"typpy",
"(",
"value",
",",
"Object",
")",
")",
"{",
"deep",
"(",
"value",
",",
"path",
")",
";",
"path",
".",
"pop",
"(",
")",
";",
"return",
";",
"}",
"text",
"=",
"text",
".",
"replace",
"(",
"new",
"RegExp",
"(",
"arr",
"[",
"0",
"]",
"+",
"path",
".",
"join",
"(",
"\".\"",
")",
"+",
"arr",
"[",
"1",
"]",
",",
"\"gm\"",
")",
",",
"typpy",
"(",
"value",
",",
"Function",
")",
"?",
"value",
":",
"String",
"(",
"value",
")",
")",
";",
"path",
".",
"pop",
"(",
")",
";",
"}",
")",
";",
"}",
";",
"deep",
"(",
"data",
",",
"[",
"]",
")",
";",
"return",
"text",
";",
"}"
] | barbe
Renders the input template including the data.
@name barbe
@function
@param {String} text The template text.
@param {Array} arr An array of two elements: the first one being the start snippet (default: `"{"`) and the second one being the end snippet (default: `"}"`).
@param {Object} data The template data.
@return {String} The rendered template. | [
"barbe",
"Renders",
"the",
"input",
"template",
"including",
"the",
"data",
"."
] | 6b3822ca9e166b2b99996d1a5c70f05fb20ff501 | https://github.com/IonicaBizau/barbe/blob/6b3822ca9e166b2b99996d1a5c70f05fb20ff501/lib/index.js#L19-L50 |
49,229 | robotlolita/specify-reporter-spec | index.js | pad | function pad(n, s) {
var before = Array(n + 1).join(' ')
return s.split(/\r\n|\r|\n/)
.map(function(a){ return before + a })
.join('\n')
} | javascript | function pad(n, s) {
var before = Array(n + 1).join(' ')
return s.split(/\r\n|\r|\n/)
.map(function(a){ return before + a })
.join('\n')
} | [
"function",
"pad",
"(",
"n",
",",
"s",
")",
"{",
"var",
"before",
"=",
"Array",
"(",
"n",
"+",
"1",
")",
".",
"join",
"(",
"' '",
")",
"return",
"s",
".",
"split",
"(",
"/",
"\\r\\n|\\r|\\n",
"/",
")",
".",
"map",
"(",
"function",
"(",
"a",
")",
"{",
"return",
"before",
"+",
"a",
"}",
")",
".",
"join",
"(",
"'\\n'",
")",
"}"
] | Pads a String with some whitespace.
@summary Number, String → String | [
"Pads",
"a",
"String",
"with",
"some",
"whitespace",
"."
] | 1e1f9ae8e0b3481783295df1de1e07f4a7d75648 | https://github.com/robotlolita/specify-reporter-spec/blob/1e1f9ae8e0b3481783295df1de1e07f4a7d75648/index.js#L29-L35 |
49,230 | robotlolita/specify-reporter-spec | index.js | maybeRenderSuite | function maybeRenderSuite(signal) { return function(a) {
return a.cata({
Suite: function(){ return Just([signal.path.length, a.name]) }
, Case: Nothing
})
}} | javascript | function maybeRenderSuite(signal) { return function(a) {
return a.cata({
Suite: function(){ return Just([signal.path.length, a.name]) }
, Case: Nothing
})
}} | [
"function",
"maybeRenderSuite",
"(",
"signal",
")",
"{",
"return",
"function",
"(",
"a",
")",
"{",
"return",
"a",
".",
"cata",
"(",
"{",
"Suite",
":",
"function",
"(",
")",
"{",
"return",
"Just",
"(",
"[",
"signal",
".",
"path",
".",
"length",
",",
"a",
".",
"name",
"]",
")",
"}",
",",
"Case",
":",
"Nothing",
"}",
")",
"}",
"}"
] | Shows that a suite has started.
@summary Signal → Test → Maybe[(Int, String)] | [
"Shows",
"that",
"a",
"suite",
"has",
"started",
"."
] | 1e1f9ae8e0b3481783295df1de1e07f4a7d75648 | https://github.com/robotlolita/specify-reporter-spec/blob/1e1f9ae8e0b3481783295df1de1e07f4a7d75648/index.js#L52-L57 |
49,231 | robotlolita/specify-reporter-spec | index.js | logs | function logs(a) {
return a.isIgnored? ''
: a.log.length === 0? ''
: /* otherwise */ '\n' + pad( 2
, '=== Captured logs:\n'
+ a.log.map(function(x){
return faded('- ' + show(x.log))})
.join('\n') + '\n---\n')
} | javascript | function logs(a) {
return a.isIgnored? ''
: a.log.length === 0? ''
: /* otherwise */ '\n' + pad( 2
, '=== Captured logs:\n'
+ a.log.map(function(x){
return faded('- ' + show(x.log))})
.join('\n') + '\n---\n')
} | [
"function",
"logs",
"(",
"a",
")",
"{",
"return",
"a",
".",
"isIgnored",
"?",
"''",
":",
"a",
".",
"log",
".",
"length",
"===",
"0",
"?",
"''",
":",
"/* otherwise */",
"'\\n'",
"+",
"pad",
"(",
"2",
",",
"'=== Captured logs:\\n'",
"+",
"a",
".",
"log",
".",
"map",
"(",
"function",
"(",
"x",
")",
"{",
"return",
"faded",
"(",
"'- '",
"+",
"show",
"(",
"x",
".",
"log",
")",
")",
"}",
")",
".",
"join",
"(",
"'\\n'",
")",
"+",
"'\\n---\\n'",
")",
"}"
] | Shows the logs of a result
@summary Result → String | [
"Shows",
"the",
"logs",
"of",
"a",
"result"
] | 1e1f9ae8e0b3481783295df1de1e07f4a7d75648 | https://github.com/robotlolita/specify-reporter-spec/blob/1e1f9ae8e0b3481783295df1de1e07f4a7d75648/index.js#L64-L72 |
49,232 | Psychopoulet/node-promfs | lib/extends/_filesToFile.js | _filesToFile | function _filesToFile (files, target, separator, callback) {
if ("undefined" === typeof files) {
throw new ReferenceError("missing \"files\" argument");
}
else if ("object" !== typeof files || !(files instanceof Array)) {
throw new TypeError("\"files\" argument is not an Array");
}
else if ("undefined" === typeof target) {
throw new ReferenceError("missing \"target\" argument");
}
else if ("string" !== typeof target) {
throw new TypeError("\"target\" argument is not a string");
}
else if ("undefined" === typeof callback && "undefined" === typeof separator) {
throw new ReferenceError("missing \"callback\" argument");
}
else if ("function" !== typeof callback && "function" !== typeof separator) {
throw new TypeError("\"callback\" argument is not a function");
}
else {
const _target = target.trim();
if ("" === _target) {
throw new Error("\"target\" argument is empty");
}
else {
const _callback = "undefined" === typeof callback ? separator : callback;
Promise.resolve().then(() => {
return isFileProm(_target);
}).then((exists) => {
return !exists ? Promise.resolve() : new Promise((resolve, reject) => {
fs.unlink(_target, (err) => {
return err ? reject(err) : resolve();
});
});
}).then(() => {
if (!files.length) {
return new Promise((resolve, reject) => {
fs.writeFile(_target, "", (err) => {
return err ? reject(err) : resolve();
});
});
}
else {
return filesToStreamProm(files, "string" === typeof separator ? separator : " ").then((readStream) => {
return new Promise((resolve, reject) => {
let error = false;
readStream.once("error", (_err) => {
error = true; reject(_err);
}).pipe(fs.createWriteStream(_target, { "flags": "a" }).once("error", (_err) => {
error = true; reject(_err);
}).once("close", () => {
if (!error) {
resolve();
}
}));
});
});
}
}).then(() => {
_callback(null);
}).catch(_callback);
}
}
} | javascript | function _filesToFile (files, target, separator, callback) {
if ("undefined" === typeof files) {
throw new ReferenceError("missing \"files\" argument");
}
else if ("object" !== typeof files || !(files instanceof Array)) {
throw new TypeError("\"files\" argument is not an Array");
}
else if ("undefined" === typeof target) {
throw new ReferenceError("missing \"target\" argument");
}
else if ("string" !== typeof target) {
throw new TypeError("\"target\" argument is not a string");
}
else if ("undefined" === typeof callback && "undefined" === typeof separator) {
throw new ReferenceError("missing \"callback\" argument");
}
else if ("function" !== typeof callback && "function" !== typeof separator) {
throw new TypeError("\"callback\" argument is not a function");
}
else {
const _target = target.trim();
if ("" === _target) {
throw new Error("\"target\" argument is empty");
}
else {
const _callback = "undefined" === typeof callback ? separator : callback;
Promise.resolve().then(() => {
return isFileProm(_target);
}).then((exists) => {
return !exists ? Promise.resolve() : new Promise((resolve, reject) => {
fs.unlink(_target, (err) => {
return err ? reject(err) : resolve();
});
});
}).then(() => {
if (!files.length) {
return new Promise((resolve, reject) => {
fs.writeFile(_target, "", (err) => {
return err ? reject(err) : resolve();
});
});
}
else {
return filesToStreamProm(files, "string" === typeof separator ? separator : " ").then((readStream) => {
return new Promise((resolve, reject) => {
let error = false;
readStream.once("error", (_err) => {
error = true; reject(_err);
}).pipe(fs.createWriteStream(_target, { "flags": "a" }).once("error", (_err) => {
error = true; reject(_err);
}).once("close", () => {
if (!error) {
resolve();
}
}));
});
});
}
}).then(() => {
_callback(null);
}).catch(_callback);
}
}
} | [
"function",
"_filesToFile",
"(",
"files",
",",
"target",
",",
"separator",
",",
"callback",
")",
"{",
"if",
"(",
"\"undefined\"",
"===",
"typeof",
"files",
")",
"{",
"throw",
"new",
"ReferenceError",
"(",
"\"missing \\\"files\\\" argument\"",
")",
";",
"}",
"else",
"if",
"(",
"\"object\"",
"!==",
"typeof",
"files",
"||",
"!",
"(",
"files",
"instanceof",
"Array",
")",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"\"\\\"files\\\" argument is not an Array\"",
")",
";",
"}",
"else",
"if",
"(",
"\"undefined\"",
"===",
"typeof",
"target",
")",
"{",
"throw",
"new",
"ReferenceError",
"(",
"\"missing \\\"target\\\" argument\"",
")",
";",
"}",
"else",
"if",
"(",
"\"string\"",
"!==",
"typeof",
"target",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"\"\\\"target\\\" argument is not a string\"",
")",
";",
"}",
"else",
"if",
"(",
"\"undefined\"",
"===",
"typeof",
"callback",
"&&",
"\"undefined\"",
"===",
"typeof",
"separator",
")",
"{",
"throw",
"new",
"ReferenceError",
"(",
"\"missing \\\"callback\\\" argument\"",
")",
";",
"}",
"else",
"if",
"(",
"\"function\"",
"!==",
"typeof",
"callback",
"&&",
"\"function\"",
"!==",
"typeof",
"separator",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"\"\\\"callback\\\" argument is not a function\"",
")",
";",
"}",
"else",
"{",
"const",
"_target",
"=",
"target",
".",
"trim",
"(",
")",
";",
"if",
"(",
"\"\"",
"===",
"_target",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"\\\"target\\\" argument is empty\"",
")",
";",
"}",
"else",
"{",
"const",
"_callback",
"=",
"\"undefined\"",
"===",
"typeof",
"callback",
"?",
"separator",
":",
"callback",
";",
"Promise",
".",
"resolve",
"(",
")",
".",
"then",
"(",
"(",
")",
"=>",
"{",
"return",
"isFileProm",
"(",
"_target",
")",
";",
"}",
")",
".",
"then",
"(",
"(",
"exists",
")",
"=>",
"{",
"return",
"!",
"exists",
"?",
"Promise",
".",
"resolve",
"(",
")",
":",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"fs",
".",
"unlink",
"(",
"_target",
",",
"(",
"err",
")",
"=>",
"{",
"return",
"err",
"?",
"reject",
"(",
"err",
")",
":",
"resolve",
"(",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
".",
"then",
"(",
"(",
")",
"=>",
"{",
"if",
"(",
"!",
"files",
".",
"length",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"fs",
".",
"writeFile",
"(",
"_target",
",",
"\"\"",
",",
"(",
"err",
")",
"=>",
"{",
"return",
"err",
"?",
"reject",
"(",
"err",
")",
":",
"resolve",
"(",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"return",
"filesToStreamProm",
"(",
"files",
",",
"\"string\"",
"===",
"typeof",
"separator",
"?",
"separator",
":",
"\" \"",
")",
".",
"then",
"(",
"(",
"readStream",
")",
"=>",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"let",
"error",
"=",
"false",
";",
"readStream",
".",
"once",
"(",
"\"error\"",
",",
"(",
"_err",
")",
"=>",
"{",
"error",
"=",
"true",
";",
"reject",
"(",
"_err",
")",
";",
"}",
")",
".",
"pipe",
"(",
"fs",
".",
"createWriteStream",
"(",
"_target",
",",
"{",
"\"flags\"",
":",
"\"a\"",
"}",
")",
".",
"once",
"(",
"\"error\"",
",",
"(",
"_err",
")",
"=>",
"{",
"error",
"=",
"true",
";",
"reject",
"(",
"_err",
")",
";",
"}",
")",
".",
"once",
"(",
"\"close\"",
",",
"(",
")",
"=>",
"{",
"if",
"(",
"!",
"error",
")",
"{",
"resolve",
"(",
")",
";",
"}",
"}",
")",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
"}",
")",
".",
"then",
"(",
"(",
")",
"=>",
"{",
"_callback",
"(",
"null",
")",
";",
"}",
")",
".",
"catch",
"(",
"_callback",
")",
";",
"}",
"}",
"}"
] | methods
Async filesToFile
@param {Array} files : files to read
@param {string} target : file to write in
@param {string} separator : files separator
@param {function|null} callback : operation's result
@returns {void} | [
"methods",
"Async",
"filesToFile"
] | 016e272fc58c6ef6eae5ea551a0e8873f0ac20cc | https://github.com/Psychopoulet/node-promfs/blob/016e272fc58c6ef6eae5ea551a0e8873f0ac20cc/lib/extends/_filesToFile.js#L29-L118 |
49,233 | Psychopoulet/node-promfs | lib/extends/_rmdirp.js | _removeDirectoryContentProm | function _removeDirectoryContentProm (contents) {
const content = contents.shift();
return isDirectoryProm(content).then((exists) => {
return exists ? new Promise((resolve, reject) => {
_rmdirp(content, (err) => {
return err ? reject(err) : resolve();
});
}) : new Promise((resolve, reject) => {
unlink(content, (err) => {
return err ? reject(err) : resolve();
});
});
}).then(() => {
return contents.length ? _removeDirectoryContentProm(contents) : Promise.resolve();
});
} | javascript | function _removeDirectoryContentProm (contents) {
const content = contents.shift();
return isDirectoryProm(content).then((exists) => {
return exists ? new Promise((resolve, reject) => {
_rmdirp(content, (err) => {
return err ? reject(err) : resolve();
});
}) : new Promise((resolve, reject) => {
unlink(content, (err) => {
return err ? reject(err) : resolve();
});
});
}).then(() => {
return contents.length ? _removeDirectoryContentProm(contents) : Promise.resolve();
});
} | [
"function",
"_removeDirectoryContentProm",
"(",
"contents",
")",
"{",
"const",
"content",
"=",
"contents",
".",
"shift",
"(",
")",
";",
"return",
"isDirectoryProm",
"(",
"content",
")",
".",
"then",
"(",
"(",
"exists",
")",
"=>",
"{",
"return",
"exists",
"?",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"_rmdirp",
"(",
"content",
",",
"(",
"err",
")",
"=>",
"{",
"return",
"err",
"?",
"reject",
"(",
"err",
")",
":",
"resolve",
"(",
")",
";",
"}",
")",
";",
"}",
")",
":",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"unlink",
"(",
"content",
",",
"(",
"err",
")",
"=>",
"{",
"return",
"err",
"?",
"reject",
"(",
"err",
")",
":",
"resolve",
"(",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
".",
"then",
"(",
"(",
")",
"=>",
"{",
"return",
"contents",
".",
"length",
"?",
"_removeDirectoryContentProm",
"(",
"contents",
")",
":",
"Promise",
".",
"resolve",
"(",
")",
";",
"}",
")",
";",
"}"
] | methods
Remove directory's content
@param {Array} contents : directory content
@returns {Promise}: Operation's result | [
"methods",
"Remove",
"directory",
"s",
"content"
] | 016e272fc58c6ef6eae5ea551a0e8873f0ac20cc | https://github.com/Psychopoulet/node-promfs/blob/016e272fc58c6ef6eae5ea551a0e8873f0ac20cc/lib/extends/_rmdirp.js#L25-L49 |
49,234 | Psychopoulet/node-promfs | lib/extends/_rmdirp.js | _emptyDirectoryProm | function _emptyDirectoryProm (directory) {
return new Promise((resolve, reject) => {
readdir(directory, (err, files) => {
return err ? reject(err) : resolve(files);
});
}).then((files) => {
const result = [];
for (let i = 0; i < files.length; ++i) {
result.push(join(directory, files[i]));
}
return Promise.resolve(result);
}).then((files) => {
return files.length ? _removeDirectoryContentProm(files) : Promise.resolve();
});
} | javascript | function _emptyDirectoryProm (directory) {
return new Promise((resolve, reject) => {
readdir(directory, (err, files) => {
return err ? reject(err) : resolve(files);
});
}).then((files) => {
const result = [];
for (let i = 0; i < files.length; ++i) {
result.push(join(directory, files[i]));
}
return Promise.resolve(result);
}).then((files) => {
return files.length ? _removeDirectoryContentProm(files) : Promise.resolve();
});
} | [
"function",
"_emptyDirectoryProm",
"(",
"directory",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"readdir",
"(",
"directory",
",",
"(",
"err",
",",
"files",
")",
"=>",
"{",
"return",
"err",
"?",
"reject",
"(",
"err",
")",
":",
"resolve",
"(",
"files",
")",
";",
"}",
")",
";",
"}",
")",
".",
"then",
"(",
"(",
"files",
")",
"=>",
"{",
"const",
"result",
"=",
"[",
"]",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"files",
".",
"length",
";",
"++",
"i",
")",
"{",
"result",
".",
"push",
"(",
"join",
"(",
"directory",
",",
"files",
"[",
"i",
"]",
")",
")",
";",
"}",
"return",
"Promise",
".",
"resolve",
"(",
"result",
")",
";",
"}",
")",
".",
"then",
"(",
"(",
"files",
")",
"=>",
"{",
"return",
"files",
".",
"length",
"?",
"_removeDirectoryContentProm",
"(",
"files",
")",
":",
"Promise",
".",
"resolve",
"(",
")",
";",
"}",
")",
";",
"}"
] | Async empty directory
@param {string} directory : directory path
@returns {Promise}: Operation's result | [
"Async",
"empty",
"directory"
] | 016e272fc58c6ef6eae5ea551a0e8873f0ac20cc | https://github.com/Psychopoulet/node-promfs/blob/016e272fc58c6ef6eae5ea551a0e8873f0ac20cc/lib/extends/_rmdirp.js#L56-L78 |
49,235 | tnantoka/LooseLeaf | skeleton/public/javascripts/lib/cleditor/plugins/jquery.cleditor.xhtml.js | parseEndTag | function parseEndTag(tag, tagName) {
// If no tag name is provided, clean shop
if (!tagName)
var pos = 0;
// Find the closest opened tag of the same type
else {
tagName = tagName.toLowerCase();
for (var pos = stack.length - 1; pos >= 0; pos--)
if (stack[pos] == tagName)
break;
}
if (pos >= 0) {
// Close all the open elements, up the stack
for (var i = stack.length - 1; i >= pos; i--)
results += "</" + stack[i] + ">";
// Remove the open elements from the stack
stack.length = pos;
}
} | javascript | function parseEndTag(tag, tagName) {
// If no tag name is provided, clean shop
if (!tagName)
var pos = 0;
// Find the closest opened tag of the same type
else {
tagName = tagName.toLowerCase();
for (var pos = stack.length - 1; pos >= 0; pos--)
if (stack[pos] == tagName)
break;
}
if (pos >= 0) {
// Close all the open elements, up the stack
for (var i = stack.length - 1; i >= pos; i--)
results += "</" + stack[i] + ">";
// Remove the open elements from the stack
stack.length = pos;
}
} | [
"function",
"parseEndTag",
"(",
"tag",
",",
"tagName",
")",
"{",
"// If no tag name is provided, clean shop\r",
"if",
"(",
"!",
"tagName",
")",
"var",
"pos",
"=",
"0",
";",
"// Find the closest opened tag of the same type\r",
"else",
"{",
"tagName",
"=",
"tagName",
".",
"toLowerCase",
"(",
")",
";",
"for",
"(",
"var",
"pos",
"=",
"stack",
".",
"length",
"-",
"1",
";",
"pos",
">=",
"0",
";",
"pos",
"--",
")",
"if",
"(",
"stack",
"[",
"pos",
"]",
"==",
"tagName",
")",
"break",
";",
"}",
"if",
"(",
"pos",
">=",
"0",
")",
"{",
"// Close all the open elements, up the stack\r",
"for",
"(",
"var",
"i",
"=",
"stack",
".",
"length",
"-",
"1",
";",
"i",
">=",
"pos",
";",
"i",
"--",
")",
"results",
"+=",
"\"</\"",
"+",
"stack",
"[",
"i",
"]",
"+",
"\">\"",
";",
"// Remove the open elements from the stack\r",
"stack",
".",
"length",
"=",
"pos",
";",
"}",
"}"
] | parseEndTag - handles a closing tag | [
"parseEndTag",
"-",
"handles",
"a",
"closing",
"tag"
] | 0c6333977224d8f4ef7ad40415aa69e0ff76f7b5 | https://github.com/tnantoka/LooseLeaf/blob/0c6333977224d8f4ef7ad40415aa69e0ff76f7b5/skeleton/public/javascripts/lib/cleditor/plugins/jquery.cleditor.xhtml.js#L198-L221 |
49,236 | kaelzhang/node-multi-profile | index.js | Profile | function Profile(options) {
this.path = node_path.resolve(profile.resolveHomePath(options.path));
this.schema = options.schema;
this.context = options.context || null;
this.raw_data = {};
this.codec = this._get_codec(options.codec);
this.options = options;
} | javascript | function Profile(options) {
this.path = node_path.resolve(profile.resolveHomePath(options.path));
this.schema = options.schema;
this.context = options.context || null;
this.raw_data = {};
this.codec = this._get_codec(options.codec);
this.options = options;
} | [
"function",
"Profile",
"(",
"options",
")",
"{",
"this",
".",
"path",
"=",
"node_path",
".",
"resolve",
"(",
"profile",
".",
"resolveHomePath",
"(",
"options",
".",
"path",
")",
")",
";",
"this",
".",
"schema",
"=",
"options",
".",
"schema",
";",
"this",
".",
"context",
"=",
"options",
".",
"context",
"||",
"null",
";",
"this",
".",
"raw_data",
"=",
"{",
"}",
";",
"this",
".",
"codec",
"=",
"this",
".",
"_get_codec",
"(",
"options",
".",
"codec",
")",
";",
"this",
".",
"options",
"=",
"options",
";",
"}"
] | Constructor of Profile has no fault-tolerance, make sure you pass the right parameters @param {Object} options - path: {node_path} path to save the profiles | [
"Constructor",
"of",
"Profile",
"has",
"no",
"fault",
"-",
"tolerance",
"make",
"sure",
"you",
"pass",
"the",
"right",
"parameters"
] | c801e3f3fd2d17b4495f0eed9af3efd72df3304d | https://github.com/kaelzhang/node-multi-profile/blob/c801e3f3fd2d17b4495f0eed9af3efd72df3304d/index.js#L87-L95 |
49,237 | kaelzhang/node-multi-profile | index.js | function(name, force, callback) {
var err = null;
var profiles = this.all();
if (~profiles.indexOf(name)) {
err = 'Profile "' + name + '" already exists.';
} else if (!force && ~RESERVED_PROFILE_NAME.indexOf(name)) {
err = 'Profile name "' + name + '" is reserved by `multi-profile`';
} else if (/^_/.test(name)) {
err = 'Profile name "' + name + '" should not begin with `_`';
} else {
profiles.push(name);
this.attr.set('profiles', profiles);
}
var data = {
err: err,
name: name
};
this.emit('add', data);
callback && callback(err, data);
} | javascript | function(name, force, callback) {
var err = null;
var profiles = this.all();
if (~profiles.indexOf(name)) {
err = 'Profile "' + name + '" already exists.';
} else if (!force && ~RESERVED_PROFILE_NAME.indexOf(name)) {
err = 'Profile name "' + name + '" is reserved by `multi-profile`';
} else if (/^_/.test(name)) {
err = 'Profile name "' + name + '" should not begin with `_`';
} else {
profiles.push(name);
this.attr.set('profiles', profiles);
}
var data = {
err: err,
name: name
};
this.emit('add', data);
callback && callback(err, data);
} | [
"function",
"(",
"name",
",",
"force",
",",
"callback",
")",
"{",
"var",
"err",
"=",
"null",
";",
"var",
"profiles",
"=",
"this",
".",
"all",
"(",
")",
";",
"if",
"(",
"~",
"profiles",
".",
"indexOf",
"(",
"name",
")",
")",
"{",
"err",
"=",
"'Profile \"'",
"+",
"name",
"+",
"'\" already exists.'",
";",
"}",
"else",
"if",
"(",
"!",
"force",
"&&",
"~",
"RESERVED_PROFILE_NAME",
".",
"indexOf",
"(",
"name",
")",
")",
"{",
"err",
"=",
"'Profile name \"'",
"+",
"name",
"+",
"'\" is reserved by `multi-profile`'",
";",
"}",
"else",
"if",
"(",
"/",
"^_",
"/",
".",
"test",
"(",
"name",
")",
")",
"{",
"err",
"=",
"'Profile name \"'",
"+",
"name",
"+",
"'\" should not begin with `_`'",
";",
"}",
"else",
"{",
"profiles",
".",
"push",
"(",
"name",
")",
";",
"this",
".",
"attr",
".",
"set",
"(",
"'profiles'",
",",
"profiles",
")",
";",
"}",
"var",
"data",
"=",
"{",
"err",
":",
"err",
",",
"name",
":",
"name",
"}",
";",
"this",
".",
"emit",
"(",
"'add'",
",",
"data",
")",
";",
"callback",
"&&",
"callback",
"(",
"err",
",",
"data",
")",
";",
"}"
] | Add a new profile. Adding a profile will not do nothing about initialization | [
"Add",
"a",
"new",
"profile",
".",
"Adding",
"a",
"profile",
"will",
"not",
"do",
"nothing",
"about",
"initialization"
] | c801e3f3fd2d17b4495f0eed9af3efd72df3304d | https://github.com/kaelzhang/node-multi-profile/blob/c801e3f3fd2d17b4495f0eed9af3efd72df3304d/index.js#L233-L258 |
|
49,238 | kaelzhang/node-multi-profile | index.js | function(name) {
this.profile = trait(Object.create(this.schema), {
context: this.context
});
var profile_dir = this.profile_dir = node_path.join(this.path, name);
if (!fs.isDir(profile_dir)) {
fs.mkdir(profile_dir);
}
var profile_file = this.profile_file = node_path.join(profile_dir, 'config');
if (!fs.isFile(profile_file)) {
fs.write(profile_file, '');
} else {
this.reload();
}
} | javascript | function(name) {
this.profile = trait(Object.create(this.schema), {
context: this.context
});
var profile_dir = this.profile_dir = node_path.join(this.path, name);
if (!fs.isDir(profile_dir)) {
fs.mkdir(profile_dir);
}
var profile_file = this.profile_file = node_path.join(profile_dir, 'config');
if (!fs.isFile(profile_file)) {
fs.write(profile_file, '');
} else {
this.reload();
}
} | [
"function",
"(",
"name",
")",
"{",
"this",
".",
"profile",
"=",
"trait",
"(",
"Object",
".",
"create",
"(",
"this",
".",
"schema",
")",
",",
"{",
"context",
":",
"this",
".",
"context",
"}",
")",
";",
"var",
"profile_dir",
"=",
"this",
".",
"profile_dir",
"=",
"node_path",
".",
"join",
"(",
"this",
".",
"path",
",",
"name",
")",
";",
"if",
"(",
"!",
"fs",
".",
"isDir",
"(",
"profile_dir",
")",
")",
"{",
"fs",
".",
"mkdir",
"(",
"profile_dir",
")",
";",
"}",
"var",
"profile_file",
"=",
"this",
".",
"profile_file",
"=",
"node_path",
".",
"join",
"(",
"profile_dir",
",",
"'config'",
")",
";",
"if",
"(",
"!",
"fs",
".",
"isFile",
"(",
"profile_file",
")",
")",
"{",
"fs",
".",
"write",
"(",
"profile_file",
",",
"''",
")",
";",
"}",
"else",
"{",
"this",
".",
"reload",
"(",
")",
";",
"}",
"}"
] | Initialize the current profile, and create necessary files and dirs if not exists. Initialize properties of current profile | [
"Initialize",
"the",
"current",
"profile",
"and",
"create",
"necessary",
"files",
"and",
"dirs",
"if",
"not",
"exists",
".",
"Initialize",
"properties",
"of",
"current",
"profile"
] | c801e3f3fd2d17b4495f0eed9af3efd72df3304d | https://github.com/kaelzhang/node-multi-profile/blob/c801e3f3fd2d17b4495f0eed9af3efd72df3304d/index.js#L423-L442 |
|
49,239 | pimbrouwers/ditto-hbs | src/index.js | discover | function discover(pattern, callback) {
glob(pattern, function (err, filepaths) {
if (err) callback(err);
callback(null, filepaths);
});
} | javascript | function discover(pattern, callback) {
glob(pattern, function (err, filepaths) {
if (err) callback(err);
callback(null, filepaths);
});
} | [
"function",
"discover",
"(",
"pattern",
",",
"callback",
")",
"{",
"glob",
"(",
"pattern",
",",
"function",
"(",
"err",
",",
"filepaths",
")",
"{",
"if",
"(",
"err",
")",
"callback",
"(",
"err",
")",
";",
"callback",
"(",
"null",
",",
"filepaths",
")",
";",
"}",
")",
";",
"}"
] | Discover files for given file pattern
@param {String} pattern glob pattern
@param {Function.<Error, Array.<string>>} callback | [
"Discover",
"files",
"for",
"given",
"file",
"pattern"
] | 50c7af39b51d9fd4bd627ea7a0ccebc62da8dc74 | https://github.com/pimbrouwers/ditto-hbs/blob/50c7af39b51d9fd4bd627ea7a0ccebc62da8dc74/src/index.js#L23-L28 |
49,240 | pimbrouwers/ditto-hbs | src/index.js | registerPartials | function registerPartials(filepaths, callback) {
async.map(filepaths, registerPartial, function (err) {
if (err) callback(err);
callback(null);
});
} | javascript | function registerPartials(filepaths, callback) {
async.map(filepaths, registerPartial, function (err) {
if (err) callback(err);
callback(null);
});
} | [
"function",
"registerPartials",
"(",
"filepaths",
",",
"callback",
")",
"{",
"async",
".",
"map",
"(",
"filepaths",
",",
"registerPartial",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"callback",
"(",
"err",
")",
";",
"callback",
"(",
"null",
")",
";",
"}",
")",
";",
"}"
] | Read hbs partial files
@param {Array.<String>} filepaths
@param {Function.<Error>} callback | [
"Read",
"hbs",
"partial",
"files"
] | 50c7af39b51d9fd4bd627ea7a0ccebc62da8dc74 | https://github.com/pimbrouwers/ditto-hbs/blob/50c7af39b51d9fd4bd627ea7a0ccebc62da8dc74/src/index.js#L51-L56 |
49,241 | pimbrouwers/ditto-hbs | src/index.js | registerPartial | function registerPartial(filepath, callback) {
fs.readFile(filepath, 'utf8', function (err, data) {
if (err) callback(err);
hbs.registerPartial(path.parse(filepath).name, data);
callback(null);
});
} | javascript | function registerPartial(filepath, callback) {
fs.readFile(filepath, 'utf8', function (err, data) {
if (err) callback(err);
hbs.registerPartial(path.parse(filepath).name, data);
callback(null);
});
} | [
"function",
"registerPartial",
"(",
"filepath",
",",
"callback",
")",
"{",
"fs",
".",
"readFile",
"(",
"filepath",
",",
"'utf8'",
",",
"function",
"(",
"err",
",",
"data",
")",
"{",
"if",
"(",
"err",
")",
"callback",
"(",
"err",
")",
";",
"hbs",
".",
"registerPartial",
"(",
"path",
".",
"parse",
"(",
"filepath",
")",
".",
"name",
",",
"data",
")",
";",
"callback",
"(",
"null",
")",
";",
"}",
")",
";",
"}"
] | Read file into buffer and register as hbs partials
@param {String} filepath
@param {Function.<Error>} callback | [
"Read",
"file",
"into",
"buffer",
"and",
"register",
"as",
"hbs",
"partials"
] | 50c7af39b51d9fd4bd627ea7a0ccebc62da8dc74 | https://github.com/pimbrouwers/ditto-hbs/blob/50c7af39b51d9fd4bd627ea7a0ccebc62da8dc74/src/index.js#L63-L69 |
49,242 | pimbrouwers/ditto-hbs | src/index.js | registerTemplates | function registerTemplates(filepaths, callback) {
async.map(filepaths, registerTemplate, function (err, templates) {
if (err) callback(err);
callback(null, templates);
});
} | javascript | function registerTemplates(filepaths, callback) {
async.map(filepaths, registerTemplate, function (err, templates) {
if (err) callback(err);
callback(null, templates);
});
} | [
"function",
"registerTemplates",
"(",
"filepaths",
",",
"callback",
")",
"{",
"async",
".",
"map",
"(",
"filepaths",
",",
"registerTemplate",
",",
"function",
"(",
"err",
",",
"templates",
")",
"{",
"if",
"(",
"err",
")",
"callback",
"(",
"err",
")",
";",
"callback",
"(",
"null",
",",
"templates",
")",
";",
"}",
")",
";",
"}"
] | Read hbs template files
@param {Array.<String>} filepaths
@param {Function.<Error>} callback | [
"Read",
"hbs",
"template",
"files"
] | 50c7af39b51d9fd4bd627ea7a0ccebc62da8dc74 | https://github.com/pimbrouwers/ditto-hbs/blob/50c7af39b51d9fd4bd627ea7a0ccebc62da8dc74/src/index.js#L76-L81 |
49,243 | pimbrouwers/ditto-hbs | src/index.js | registerTemplate | function registerTemplate(filepath, callback) {
fs.readFile(filepath, 'utf8', function (err, data) {
if (err) callback(err);
callback(null, {
name: path.parse(filepath).name,
template: hbs.compile(data)
});
});
} | javascript | function registerTemplate(filepath, callback) {
fs.readFile(filepath, 'utf8', function (err, data) {
if (err) callback(err);
callback(null, {
name: path.parse(filepath).name,
template: hbs.compile(data)
});
});
} | [
"function",
"registerTemplate",
"(",
"filepath",
",",
"callback",
")",
"{",
"fs",
".",
"readFile",
"(",
"filepath",
",",
"'utf8'",
",",
"function",
"(",
"err",
",",
"data",
")",
"{",
"if",
"(",
"err",
")",
"callback",
"(",
"err",
")",
";",
"callback",
"(",
"null",
",",
"{",
"name",
":",
"path",
".",
"parse",
"(",
"filepath",
")",
".",
"name",
",",
"template",
":",
"hbs",
".",
"compile",
"(",
"data",
")",
"}",
")",
";",
"}",
")",
";",
"}"
] | Read file into buffer and register as hbs template
@param {String} filepath
@param {Function.<Error, Object>} callback | [
"Read",
"file",
"into",
"buffer",
"and",
"register",
"as",
"hbs",
"template"
] | 50c7af39b51d9fd4bd627ea7a0ccebc62da8dc74 | https://github.com/pimbrouwers/ditto-hbs/blob/50c7af39b51d9fd4bd627ea7a0ccebc62da8dc74/src/index.js#L88-L96 |
49,244 | ChALkeR/Jergal | lib/versions.js | satisfies | function satisfies(version, range) {
range = range.trim();
// Range '<=99.999.99999' means "all versions", but fails on "2014.10.20-1"
if (range === '<=99.999.99999') return true;
// If semver satisfies, we return true
if (semver.satisfies(version, range)) return true;
// If range is a specific version, return eq
if (semver.valid(range)) return semver.eq(version, range);
if (range.includes('||')) {
// Multiple ranges, "or"
return range.split('||').some(sub => satisfies(version, sub.trim()));
}
if (range.includes(' ')) {
// Multiple ranges, "and"
return range.split(' ')
.map(x => x.trim())
.filter(x => x)
.every(sub => satisfies(version, sub));
}
// Comparison
if (range.startsWith('>=')) {
const sub = range.slice(2).trim();
if (semver.valid(sub)) return semver.gte(version, sub);
} else if (range.startsWith('<=')) {
const sub = range.slice(2).trim();
if (semver.valid(sub)) return semver.lte(version, sub);
} else if (range.startsWith('>')) {
const sub = range.slice(1).trim();
if (semver.valid(sub)) return semver.gt(version, sub);
} else if (range.startsWith('<')) {
const sub = range.slice(1).trim();
if (semver.valid(sub)) return semver.lt(version, sub);
}
console.error(`Unprocessed version/range: ${version}, ${JSON.stringify(range)}`);
return false;
} | javascript | function satisfies(version, range) {
range = range.trim();
// Range '<=99.999.99999' means "all versions", but fails on "2014.10.20-1"
if (range === '<=99.999.99999') return true;
// If semver satisfies, we return true
if (semver.satisfies(version, range)) return true;
// If range is a specific version, return eq
if (semver.valid(range)) return semver.eq(version, range);
if (range.includes('||')) {
// Multiple ranges, "or"
return range.split('||').some(sub => satisfies(version, sub.trim()));
}
if (range.includes(' ')) {
// Multiple ranges, "and"
return range.split(' ')
.map(x => x.trim())
.filter(x => x)
.every(sub => satisfies(version, sub));
}
// Comparison
if (range.startsWith('>=')) {
const sub = range.slice(2).trim();
if (semver.valid(sub)) return semver.gte(version, sub);
} else if (range.startsWith('<=')) {
const sub = range.slice(2).trim();
if (semver.valid(sub)) return semver.lte(version, sub);
} else if (range.startsWith('>')) {
const sub = range.slice(1).trim();
if (semver.valid(sub)) return semver.gt(version, sub);
} else if (range.startsWith('<')) {
const sub = range.slice(1).trim();
if (semver.valid(sub)) return semver.lt(version, sub);
}
console.error(`Unprocessed version/range: ${version}, ${JSON.stringify(range)}`);
return false;
} | [
"function",
"satisfies",
"(",
"version",
",",
"range",
")",
"{",
"range",
"=",
"range",
".",
"trim",
"(",
")",
";",
"// Range '<=99.999.99999' means \"all versions\", but fails on \"2014.10.20-1\"",
"if",
"(",
"range",
"===",
"'<=99.999.99999'",
")",
"return",
"true",
";",
"// If semver satisfies, we return true",
"if",
"(",
"semver",
".",
"satisfies",
"(",
"version",
",",
"range",
")",
")",
"return",
"true",
";",
"// If range is a specific version, return eq",
"if",
"(",
"semver",
".",
"valid",
"(",
"range",
")",
")",
"return",
"semver",
".",
"eq",
"(",
"version",
",",
"range",
")",
";",
"if",
"(",
"range",
".",
"includes",
"(",
"'||'",
")",
")",
"{",
"// Multiple ranges, \"or\"",
"return",
"range",
".",
"split",
"(",
"'||'",
")",
".",
"some",
"(",
"sub",
"=>",
"satisfies",
"(",
"version",
",",
"sub",
".",
"trim",
"(",
")",
")",
")",
";",
"}",
"if",
"(",
"range",
".",
"includes",
"(",
"' '",
")",
")",
"{",
"// Multiple ranges, \"and\"",
"return",
"range",
".",
"split",
"(",
"' '",
")",
".",
"map",
"(",
"x",
"=>",
"x",
".",
"trim",
"(",
")",
")",
".",
"filter",
"(",
"x",
"=>",
"x",
")",
".",
"every",
"(",
"sub",
"=>",
"satisfies",
"(",
"version",
",",
"sub",
")",
")",
";",
"}",
"// Comparison",
"if",
"(",
"range",
".",
"startsWith",
"(",
"'>='",
")",
")",
"{",
"const",
"sub",
"=",
"range",
".",
"slice",
"(",
"2",
")",
".",
"trim",
"(",
")",
";",
"if",
"(",
"semver",
".",
"valid",
"(",
"sub",
")",
")",
"return",
"semver",
".",
"gte",
"(",
"version",
",",
"sub",
")",
";",
"}",
"else",
"if",
"(",
"range",
".",
"startsWith",
"(",
"'<='",
")",
")",
"{",
"const",
"sub",
"=",
"range",
".",
"slice",
"(",
"2",
")",
".",
"trim",
"(",
")",
";",
"if",
"(",
"semver",
".",
"valid",
"(",
"sub",
")",
")",
"return",
"semver",
".",
"lte",
"(",
"version",
",",
"sub",
")",
";",
"}",
"else",
"if",
"(",
"range",
".",
"startsWith",
"(",
"'>'",
")",
")",
"{",
"const",
"sub",
"=",
"range",
".",
"slice",
"(",
"1",
")",
".",
"trim",
"(",
")",
";",
"if",
"(",
"semver",
".",
"valid",
"(",
"sub",
")",
")",
"return",
"semver",
".",
"gt",
"(",
"version",
",",
"sub",
")",
";",
"}",
"else",
"if",
"(",
"range",
".",
"startsWith",
"(",
"'<'",
")",
")",
"{",
"const",
"sub",
"=",
"range",
".",
"slice",
"(",
"1",
")",
".",
"trim",
"(",
")",
";",
"if",
"(",
"semver",
".",
"valid",
"(",
"sub",
")",
")",
"return",
"semver",
".",
"lt",
"(",
"version",
",",
"sub",
")",
";",
"}",
"console",
".",
"error",
"(",
"`",
"${",
"version",
"}",
"${",
"JSON",
".",
"stringify",
"(",
"range",
")",
"}",
"`",
")",
";",
"return",
"false",
";",
"}"
] | A more loose check that semver, using a simple order check | [
"A",
"more",
"loose",
"check",
"that",
"semver",
"using",
"a",
"simple",
"order",
"check"
] | 21141fb6c4af90d37af2c6cec074a58aaf67a5d0 | https://github.com/ChALkeR/Jergal/blob/21141fb6c4af90d37af2c6cec074a58aaf67a5d0/lib/versions.js#L4-L47 |
49,245 | b-heilman/bmoor | src/object.js | explode | function explode( target, mappings ){
if (!mappings ){
mappings = target;
target = {};
}
bmoor.iterate( mappings, function( val, mapping ){
bmoor.set( target, mapping, val );
});
return target;
} | javascript | function explode( target, mappings ){
if (!mappings ){
mappings = target;
target = {};
}
bmoor.iterate( mappings, function( val, mapping ){
bmoor.set( target, mapping, val );
});
return target;
} | [
"function",
"explode",
"(",
"target",
",",
"mappings",
")",
"{",
"if",
"(",
"!",
"mappings",
")",
"{",
"mappings",
"=",
"target",
";",
"target",
"=",
"{",
"}",
";",
"}",
"bmoor",
".",
"iterate",
"(",
"mappings",
",",
"function",
"(",
"val",
",",
"mapping",
")",
"{",
"bmoor",
".",
"set",
"(",
"target",
",",
"mapping",
",",
"val",
")",
";",
"}",
")",
";",
"return",
"target",
";",
"}"
] | Takes a hash and uses the indexs as namespaces to add properties to an objs
@function explode
@param {object} target The object to map the variables onto
@param {object} mappings An object orientended as [ namespace ] => value
@return {object} The object that has had content mapped into it | [
"Takes",
"a",
"hash",
"and",
"uses",
"the",
"indexs",
"as",
"namespaces",
"to",
"add",
"properties",
"to",
"an",
"objs"
] | b21a315b477093c14e5f32d857b4644a5a0a36fd | https://github.com/b-heilman/bmoor/blob/b21a315b477093c14e5f32d857b4644a5a0a36fd/src/object.js#L40-L51 |
49,246 | b-heilman/bmoor | src/object.js | mask | function mask( obj ){
if ( Object.create ){
var T = function Masked(){};
T.prototype = obj;
return new T();
}else{
return Object.create( obj );
}
} | javascript | function mask( obj ){
if ( Object.create ){
var T = function Masked(){};
T.prototype = obj;
return new T();
}else{
return Object.create( obj );
}
} | [
"function",
"mask",
"(",
"obj",
")",
"{",
"if",
"(",
"Object",
".",
"create",
")",
"{",
"var",
"T",
"=",
"function",
"Masked",
"(",
")",
"{",
"}",
";",
"T",
".",
"prototype",
"=",
"obj",
";",
"return",
"new",
"T",
"(",
")",
";",
"}",
"else",
"{",
"return",
"Object",
".",
"create",
"(",
"obj",
")",
";",
"}",
"}"
] | Create a new instance from an object and some arguments
@function mask
@param {function} obj The basis for the constructor
@param {array} args The arguments to pass to the constructor
@return {object} The new object that has been constructed | [
"Create",
"a",
"new",
"instance",
"from",
"an",
"object",
"and",
"some",
"arguments"
] | b21a315b477093c14e5f32d857b4644a5a0a36fd | https://github.com/b-heilman/bmoor/blob/b21a315b477093c14e5f32d857b4644a5a0a36fd/src/object.js#L115-L125 |
49,247 | b-heilman/bmoor | src/object.js | merge | function merge( to ){
var from,
i, c,
m = function( val, key ){
to[ key ] = merge( to[key], val );
};
for( i = 1, c = arguments.length; i < c; i++ ){
from = arguments[i];
if ( to === from ){
continue;
}else if ( to && to.merge ){
to.merge( from );
}else if ( !bmoor.isObject(from) ){
to = from;
}else if ( !bmoor.isObject(to) ){
to = merge( {}, from );
}else{
bmoor.safe( from, m );
}
}
return to;
} | javascript | function merge( to ){
var from,
i, c,
m = function( val, key ){
to[ key ] = merge( to[key], val );
};
for( i = 1, c = arguments.length; i < c; i++ ){
from = arguments[i];
if ( to === from ){
continue;
}else if ( to && to.merge ){
to.merge( from );
}else if ( !bmoor.isObject(from) ){
to = from;
}else if ( !bmoor.isObject(to) ){
to = merge( {}, from );
}else{
bmoor.safe( from, m );
}
}
return to;
} | [
"function",
"merge",
"(",
"to",
")",
"{",
"var",
"from",
",",
"i",
",",
"c",
",",
"m",
"=",
"function",
"(",
"val",
",",
"key",
")",
"{",
"to",
"[",
"key",
"]",
"=",
"merge",
"(",
"to",
"[",
"key",
"]",
",",
"val",
")",
";",
"}",
";",
"for",
"(",
"i",
"=",
"1",
",",
"c",
"=",
"arguments",
".",
"length",
";",
"i",
"<",
"c",
";",
"i",
"++",
")",
"{",
"from",
"=",
"arguments",
"[",
"i",
"]",
";",
"if",
"(",
"to",
"===",
"from",
")",
"{",
"continue",
";",
"}",
"else",
"if",
"(",
"to",
"&&",
"to",
".",
"merge",
")",
"{",
"to",
".",
"merge",
"(",
"from",
")",
";",
"}",
"else",
"if",
"(",
"!",
"bmoor",
".",
"isObject",
"(",
"from",
")",
")",
"{",
"to",
"=",
"from",
";",
"}",
"else",
"if",
"(",
"!",
"bmoor",
".",
"isObject",
"(",
"to",
")",
")",
"{",
"to",
"=",
"merge",
"(",
"{",
"}",
",",
"from",
")",
";",
"}",
"else",
"{",
"bmoor",
".",
"safe",
"(",
"from",
",",
"m",
")",
";",
"}",
"}",
"return",
"to",
";",
"}"
] | Deep copy version of extend | [
"Deep",
"copy",
"version",
"of",
"extend"
] | b21a315b477093c14e5f32d857b4644a5a0a36fd | https://github.com/b-heilman/bmoor/blob/b21a315b477093c14e5f32d857b4644a5a0a36fd/src/object.js#L165-L189 |
49,248 | b-heilman/bmoor | src/object.js | equals | function equals( obj1, obj2 ){
var t1 = typeof obj1,
t2 = typeof obj2,
c,
i,
keyCheck;
if ( obj1 === obj2 ){
return true;
}else if ( obj1 !== obj1 && obj2 !== obj2 ){
return true; // silly NaN
}else if ( obj1 === null || obj1 === undefined || obj2 === null || obj2 === undefined ){
return false; // undefined or null
}else if ( obj1.equals ){
return obj1.equals( obj2 );
}else if ( obj2.equals ){
return obj2.equals( obj1 ); // because maybe somene wants a class to be able to equal a simple object
}else if ( t1 === t2 ){
if ( t1 === 'object' ){
if ( bmoor.isArrayLike(obj1) ){
if ( !bmoor.isArrayLike(obj2) ){
return false;
}
if ( (c = obj1.length) === obj2.length ){
for( i = 0; i < c; i++ ){
if ( !equals(obj1[i], obj2[i]) ) {
return false;
}
}
return true;
}
}else if ( !bmoor.isArrayLike(obj2) ){
keyCheck = {};
for( i in obj1 ){
if ( obj1.hasOwnProperty(i) ){
if ( !equals(obj1[i],obj2[i]) ){
return false;
}
keyCheck[i] = true;
}
}
for( i in obj2 ){
if ( obj2.hasOwnProperty(i) ){
if ( !keyCheck && obj2[i] !== undefined ){
return false;
}
}
}
}
}
}
return false;
} | javascript | function equals( obj1, obj2 ){
var t1 = typeof obj1,
t2 = typeof obj2,
c,
i,
keyCheck;
if ( obj1 === obj2 ){
return true;
}else if ( obj1 !== obj1 && obj2 !== obj2 ){
return true; // silly NaN
}else if ( obj1 === null || obj1 === undefined || obj2 === null || obj2 === undefined ){
return false; // undefined or null
}else if ( obj1.equals ){
return obj1.equals( obj2 );
}else if ( obj2.equals ){
return obj2.equals( obj1 ); // because maybe somene wants a class to be able to equal a simple object
}else if ( t1 === t2 ){
if ( t1 === 'object' ){
if ( bmoor.isArrayLike(obj1) ){
if ( !bmoor.isArrayLike(obj2) ){
return false;
}
if ( (c = obj1.length) === obj2.length ){
for( i = 0; i < c; i++ ){
if ( !equals(obj1[i], obj2[i]) ) {
return false;
}
}
return true;
}
}else if ( !bmoor.isArrayLike(obj2) ){
keyCheck = {};
for( i in obj1 ){
if ( obj1.hasOwnProperty(i) ){
if ( !equals(obj1[i],obj2[i]) ){
return false;
}
keyCheck[i] = true;
}
}
for( i in obj2 ){
if ( obj2.hasOwnProperty(i) ){
if ( !keyCheck && obj2[i] !== undefined ){
return false;
}
}
}
}
}
}
return false;
} | [
"function",
"equals",
"(",
"obj1",
",",
"obj2",
")",
"{",
"var",
"t1",
"=",
"typeof",
"obj1",
",",
"t2",
"=",
"typeof",
"obj2",
",",
"c",
",",
"i",
",",
"keyCheck",
";",
"if",
"(",
"obj1",
"===",
"obj2",
")",
"{",
"return",
"true",
";",
"}",
"else",
"if",
"(",
"obj1",
"!==",
"obj1",
"&&",
"obj2",
"!==",
"obj2",
")",
"{",
"return",
"true",
";",
"// silly NaN\r",
"}",
"else",
"if",
"(",
"obj1",
"===",
"null",
"||",
"obj1",
"===",
"undefined",
"||",
"obj2",
"===",
"null",
"||",
"obj2",
"===",
"undefined",
")",
"{",
"return",
"false",
";",
"// undefined or null\r",
"}",
"else",
"if",
"(",
"obj1",
".",
"equals",
")",
"{",
"return",
"obj1",
".",
"equals",
"(",
"obj2",
")",
";",
"}",
"else",
"if",
"(",
"obj2",
".",
"equals",
")",
"{",
"return",
"obj2",
".",
"equals",
"(",
"obj1",
")",
";",
"// because maybe somene wants a class to be able to equal a simple object\r",
"}",
"else",
"if",
"(",
"t1",
"===",
"t2",
")",
"{",
"if",
"(",
"t1",
"===",
"'object'",
")",
"{",
"if",
"(",
"bmoor",
".",
"isArrayLike",
"(",
"obj1",
")",
")",
"{",
"if",
"(",
"!",
"bmoor",
".",
"isArrayLike",
"(",
"obj2",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"(",
"c",
"=",
"obj1",
".",
"length",
")",
"===",
"obj2",
".",
"length",
")",
"{",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"c",
";",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"equals",
"(",
"obj1",
"[",
"i",
"]",
",",
"obj2",
"[",
"i",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}",
"}",
"else",
"if",
"(",
"!",
"bmoor",
".",
"isArrayLike",
"(",
"obj2",
")",
")",
"{",
"keyCheck",
"=",
"{",
"}",
";",
"for",
"(",
"i",
"in",
"obj1",
")",
"{",
"if",
"(",
"obj1",
".",
"hasOwnProperty",
"(",
"i",
")",
")",
"{",
"if",
"(",
"!",
"equals",
"(",
"obj1",
"[",
"i",
"]",
",",
"obj2",
"[",
"i",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"keyCheck",
"[",
"i",
"]",
"=",
"true",
";",
"}",
"}",
"for",
"(",
"i",
"in",
"obj2",
")",
"{",
"if",
"(",
"obj2",
".",
"hasOwnProperty",
"(",
"i",
")",
")",
"{",
"if",
"(",
"!",
"keyCheck",
"&&",
"obj2",
"[",
"i",
"]",
"!==",
"undefined",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] | A general comparison algorithm to test if two objects are equal
@function equals
@param {object} obj1 The object to copy the content from
@param {object} obj2 The object into which to copy the content
@preturns {boolean} | [
"A",
"general",
"comparison",
"algorithm",
"to",
"test",
"if",
"two",
"objects",
"are",
"equal"
] | b21a315b477093c14e5f32d857b4644a5a0a36fd | https://github.com/b-heilman/bmoor/blob/b21a315b477093c14e5f32d857b4644a5a0a36fd/src/object.js#L199-L256 |
49,249 | unkelpehr/YAEventEmitter | index.js | exec | function exec (func, context, args) {
switch (args.length) {
case 0: func.call(context); break;
case 1: func.call(context, args[0]); break;
case 2: func.call(context, args[0], args[1]); break;
case 3: func.call(context, args[0], args[1], args[2]); break;
case 4: func.call(context, args[0], args[1], args[2], args[3]); break;
default: func.apply(context, args); break;
}
} | javascript | function exec (func, context, args) {
switch (args.length) {
case 0: func.call(context); break;
case 1: func.call(context, args[0]); break;
case 2: func.call(context, args[0], args[1]); break;
case 3: func.call(context, args[0], args[1], args[2]); break;
case 4: func.call(context, args[0], args[1], args[2], args[3]); break;
default: func.apply(context, args); break;
}
} | [
"function",
"exec",
"(",
"func",
",",
"context",
",",
"args",
")",
"{",
"switch",
"(",
"args",
".",
"length",
")",
"{",
"case",
"0",
":",
"func",
".",
"call",
"(",
"context",
")",
";",
"break",
";",
"case",
"1",
":",
"func",
".",
"call",
"(",
"context",
",",
"args",
"[",
"0",
"]",
")",
";",
"break",
";",
"case",
"2",
":",
"func",
".",
"call",
"(",
"context",
",",
"args",
"[",
"0",
"]",
",",
"args",
"[",
"1",
"]",
")",
";",
"break",
";",
"case",
"3",
":",
"func",
".",
"call",
"(",
"context",
",",
"args",
"[",
"0",
"]",
",",
"args",
"[",
"1",
"]",
",",
"args",
"[",
"2",
"]",
")",
";",
"break",
";",
"case",
"4",
":",
"func",
".",
"call",
"(",
"context",
",",
"args",
"[",
"0",
"]",
",",
"args",
"[",
"1",
"]",
",",
"args",
"[",
"2",
"]",
",",
"args",
"[",
"3",
"]",
")",
";",
"break",
";",
"default",
":",
"func",
".",
"apply",
"(",
"context",
",",
"args",
")",
";",
"break",
";",
"}",
"}"
] | Helper function for fast execution of functions with dynamic parameters.
@param {Function} func Function to execute
@param {Object} context Object used as `this`-value
@param {Array} args Array of arguments to pass | [
"Helper",
"function",
"for",
"fast",
"execution",
"of",
"functions",
"with",
"dynamic",
"parameters",
"."
] | 2015e0a482bfbb3d419d4820921b71e5a8db9d46 | https://github.com/unkelpehr/YAEventEmitter/blob/2015e0a482bfbb3d419d4820921b71e5a8db9d46/index.js#L7-L16 |
49,250 | unkelpehr/YAEventEmitter | index.js | propagate | function propagate (parent, prefix) {
var self = this;
if (!parent || typeof parent.emit !== 'function') {
throw new TypeError('"parent" argument must implement an "emit" method');
}
self.parent = parent;
self.parentPrefix = prefix;
return this;
} | javascript | function propagate (parent, prefix) {
var self = this;
if (!parent || typeof parent.emit !== 'function') {
throw new TypeError('"parent" argument must implement an "emit" method');
}
self.parent = parent;
self.parentPrefix = prefix;
return this;
} | [
"function",
"propagate",
"(",
"parent",
",",
"prefix",
")",
"{",
"var",
"self",
"=",
"this",
";",
"if",
"(",
"!",
"parent",
"||",
"typeof",
"parent",
".",
"emit",
"!==",
"'function'",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'\"parent\" argument must implement an \"emit\" method'",
")",
";",
"}",
"self",
".",
"parent",
"=",
"parent",
";",
"self",
".",
"parentPrefix",
"=",
"prefix",
";",
"return",
"this",
";",
"}"
] | Adds the parent eventemitter to the end of the bubblers array.
When this eventemitter has emitted an event it will emit the same event on the parent.
This function is namespaced under 'EventEmitter' because it's usually not part of what
people perceive as an event emitter.
@param {EventEmitter} parent The eventemitter to propagate events to.
@param {String} prefix Optional prefix for the eventName, like 'user-' => user-logout.
@return {Object} `this`-object. | [
"Adds",
"the",
"parent",
"eventemitter",
"to",
"the",
"end",
"of",
"the",
"bubblers",
"array",
".",
"When",
"this",
"eventemitter",
"has",
"emitted",
"an",
"event",
"it",
"will",
"emit",
"the",
"same",
"event",
"on",
"the",
"parent",
"."
] | 2015e0a482bfbb3d419d4820921b71e5a8db9d46 | https://github.com/unkelpehr/YAEventEmitter/blob/2015e0a482bfbb3d419d4820921b71e5a8db9d46/index.js#L51-L62 |
49,251 | rickyclegg/this | build/debug/this_debug_0.1.7.js | hasCompleteEventParams | function hasCompleteEventParams(eventType, listener) {
var hasParams = eventType && listener,
isTypeString = typeof eventType === 'string',
isTypeFunction = typeof listener === 'function';
if (!isTypeFunction) {
throw new TypeError(EventDispatcher.TYPE_ERROR);
}
return hasParams && isTypeString && isTypeFunction;
} | javascript | function hasCompleteEventParams(eventType, listener) {
var hasParams = eventType && listener,
isTypeString = typeof eventType === 'string',
isTypeFunction = typeof listener === 'function';
if (!isTypeFunction) {
throw new TypeError(EventDispatcher.TYPE_ERROR);
}
return hasParams && isTypeString && isTypeFunction;
} | [
"function",
"hasCompleteEventParams",
"(",
"eventType",
",",
"listener",
")",
"{",
"var",
"hasParams",
"=",
"eventType",
"&&",
"listener",
",",
"isTypeString",
"=",
"typeof",
"eventType",
"===",
"'string'",
",",
"isTypeFunction",
"=",
"typeof",
"listener",
"===",
"'function'",
";",
"if",
"(",
"!",
"isTypeFunction",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"EventDispatcher",
".",
"TYPE_ERROR",
")",
";",
"}",
"return",
"hasParams",
"&&",
"isTypeString",
"&&",
"isTypeFunction",
";",
"}"
] | Checks if params exist and match the correct types.
@param {String} eventType
@param {Function} listener
@returns {Boolean}
@private
@throws {TypeError} The listener specified is not a function. | [
"Checks",
"if",
"params",
"exist",
"and",
"match",
"the",
"correct",
"types",
"."
] | a3186c3d1c3be93734b7404998ff6305bf43f857 | https://github.com/rickyclegg/this/blob/a3186c3d1c3be93734b7404998ff6305bf43f857/build/debug/this_debug_0.1.7.js#L179-L189 |
49,252 | cli-kit/cli-description | index.js | Description | function Description(def) {
if(typeof def === 'string') {
this.parse(def);
}else if(def
&& typeof def === 'object'
&& typeof def.txt === 'string'
&& typeof def.md === 'string') {
this.md = def.md;
this.txt = def.txt;
}else{
throw new Error('invalid value for description');
}
} | javascript | function Description(def) {
if(typeof def === 'string') {
this.parse(def);
}else if(def
&& typeof def === 'object'
&& typeof def.txt === 'string'
&& typeof def.md === 'string') {
this.md = def.md;
this.txt = def.txt;
}else{
throw new Error('invalid value for description');
}
} | [
"function",
"Description",
"(",
"def",
")",
"{",
"if",
"(",
"typeof",
"def",
"===",
"'string'",
")",
"{",
"this",
".",
"parse",
"(",
"def",
")",
";",
"}",
"else",
"if",
"(",
"def",
"&&",
"typeof",
"def",
"===",
"'object'",
"&&",
"typeof",
"def",
".",
"txt",
"===",
"'string'",
"&&",
"typeof",
"def",
".",
"md",
"===",
"'string'",
")",
"{",
"this",
".",
"md",
"=",
"def",
".",
"md",
";",
"this",
".",
"txt",
"=",
"def",
".",
"txt",
";",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"'invalid value for description'",
")",
";",
"}",
"}"
] | Encapsulates a string represented as markdown and plain text. | [
"Encapsulates",
"a",
"string",
"represented",
"as",
"markdown",
"and",
"plain",
"text",
"."
] | 41779925dbf66bd41c6c039f6a834937113e3660 | https://github.com/cli-kit/cli-description/blob/41779925dbf66bd41c6c039f6a834937113e3660/index.js#L10-L22 |
49,253 | rhdeck/yarnif | index.js | useYarn | function useYarn(setYarn) {
if (typeof setYarn !== "undefined") {
allowYarn = setYarn;
}
if (typeof allowYarn !== "undefined") {
return allowYarn;
}
return getYarnVersionIfAvailable() ? true : false;
} | javascript | function useYarn(setYarn) {
if (typeof setYarn !== "undefined") {
allowYarn = setYarn;
}
if (typeof allowYarn !== "undefined") {
return allowYarn;
}
return getYarnVersionIfAvailable() ? true : false;
} | [
"function",
"useYarn",
"(",
"setYarn",
")",
"{",
"if",
"(",
"typeof",
"setYarn",
"!==",
"\"undefined\"",
")",
"{",
"allowYarn",
"=",
"setYarn",
";",
"}",
"if",
"(",
"typeof",
"allowYarn",
"!==",
"\"undefined\"",
")",
"{",
"return",
"allowYarn",
";",
"}",
"return",
"getYarnVersionIfAvailable",
"(",
")",
"?",
"true",
":",
"false",
";",
"}"
] | Use Yarn if available, it's much faster than the npm client. Return the version of yarn installed on the system, null if yarn is not available. | [
"Use",
"Yarn",
"if",
"available",
"it",
"s",
"much",
"faster",
"than",
"the",
"npm",
"client",
".",
"Return",
"the",
"version",
"of",
"yarn",
"installed",
"on",
"the",
"system",
"null",
"if",
"yarn",
"is",
"not",
"available",
"."
] | 6d9c587e634807ce4df4900f26430d063f49188d | https://github.com/rhdeck/yarnif/blob/6d9c587e634807ce4df4900f26430d063f49188d/index.js#L8-L16 |
49,254 | qiangyt/qnode-config | src/ConfigHelper.js | _load | function _load(file, defaultConfig, dump) {
const f = normalize(file);
const b = f.base;
const p = f.profile;
const ext = f.ext;
if (ext) {
const p = b + ext;
let r = loadSpecific(b, '.js', p, defaultConfig, dump);
if (r) return r;
if (defaultConfig) return defaultConfig;
throw new Error('file not found: ' + p);
}
let r = loadSpecific(b, '.yml', p, defaultConfig, dump);
if (r) return r;
r = loadSpecific(b, '.yaml', p, defaultConfig, dump);
if (r) return r;
r = loadSpecific(b, '.json', p, defaultConfig, dump);
if (r) return r;
r = loadSpecific(b, '.js', p, defaultConfig, dump);
if (r) return r;
if (defaultConfig) return defaultConfig;
throw new Error(`file not found: ${b}[.profile].yml( or .yaml/.json/.js)`);
} | javascript | function _load(file, defaultConfig, dump) {
const f = normalize(file);
const b = f.base;
const p = f.profile;
const ext = f.ext;
if (ext) {
const p = b + ext;
let r = loadSpecific(b, '.js', p, defaultConfig, dump);
if (r) return r;
if (defaultConfig) return defaultConfig;
throw new Error('file not found: ' + p);
}
let r = loadSpecific(b, '.yml', p, defaultConfig, dump);
if (r) return r;
r = loadSpecific(b, '.yaml', p, defaultConfig, dump);
if (r) return r;
r = loadSpecific(b, '.json', p, defaultConfig, dump);
if (r) return r;
r = loadSpecific(b, '.js', p, defaultConfig, dump);
if (r) return r;
if (defaultConfig) return defaultConfig;
throw new Error(`file not found: ${b}[.profile].yml( or .yaml/.json/.js)`);
} | [
"function",
"_load",
"(",
"file",
",",
"defaultConfig",
",",
"dump",
")",
"{",
"const",
"f",
"=",
"normalize",
"(",
"file",
")",
";",
"const",
"b",
"=",
"f",
".",
"base",
";",
"const",
"p",
"=",
"f",
".",
"profile",
";",
"const",
"ext",
"=",
"f",
".",
"ext",
";",
"if",
"(",
"ext",
")",
"{",
"const",
"p",
"=",
"b",
"+",
"ext",
";",
"let",
"r",
"=",
"loadSpecific",
"(",
"b",
",",
"'.js'",
",",
"p",
",",
"defaultConfig",
",",
"dump",
")",
";",
"if",
"(",
"r",
")",
"return",
"r",
";",
"if",
"(",
"defaultConfig",
")",
"return",
"defaultConfig",
";",
"throw",
"new",
"Error",
"(",
"'file not found: '",
"+",
"p",
")",
";",
"}",
"let",
"r",
"=",
"loadSpecific",
"(",
"b",
",",
"'.yml'",
",",
"p",
",",
"defaultConfig",
",",
"dump",
")",
";",
"if",
"(",
"r",
")",
"return",
"r",
";",
"r",
"=",
"loadSpecific",
"(",
"b",
",",
"'.yaml'",
",",
"p",
",",
"defaultConfig",
",",
"dump",
")",
";",
"if",
"(",
"r",
")",
"return",
"r",
";",
"r",
"=",
"loadSpecific",
"(",
"b",
",",
"'.json'",
",",
"p",
",",
"defaultConfig",
",",
"dump",
")",
";",
"if",
"(",
"r",
")",
"return",
"r",
";",
"r",
"=",
"loadSpecific",
"(",
"b",
",",
"'.js'",
",",
"p",
",",
"defaultConfig",
",",
"dump",
")",
";",
"if",
"(",
"r",
")",
"return",
"r",
";",
"if",
"(",
"defaultConfig",
")",
"return",
"defaultConfig",
";",
"throw",
"new",
"Error",
"(",
"`",
"${",
"b",
"}",
"`",
")",
";",
"}"
] | Read a configuration file.
Support format: yaml, json, js.
Support extension: .yml, .yaml, .json, .js
@param {*} file 1) if it is a string, I will think it a full path
2) if it is a object, I will think it is structured as:
{
dir: '', // directory name. optional, working dir by default
name: '', // file name, without ext. must.
ext: '', // force to be with this extension. optional.
}
@param defaultConfig default config if file not exists. optional
@param boolean dump true to dump the content | [
"Read",
"a",
"configuration",
"file",
"."
] | d7b15d6ed72e82d4ca26230d25811ae1669ba7a6 | https://github.com/qiangyt/qnode-config/blob/d7b15d6ed72e82d4ca26230d25811ae1669ba7a6/src/ConfigHelper.js#L131-L164 |
49,255 | microscopejs/microscope-web | src/HttpApplication.js | HttpApplication | function HttpApplication() {
this.app = express();
this._registerConfigurations();
this._registerMiddlewares();
this._registerControllers();
this._registerAreas();
this.initialize.apply(this, arguments);
} | javascript | function HttpApplication() {
this.app = express();
this._registerConfigurations();
this._registerMiddlewares();
this._registerControllers();
this._registerAreas();
this.initialize.apply(this, arguments);
} | [
"function",
"HttpApplication",
"(",
")",
"{",
"this",
".",
"app",
"=",
"express",
"(",
")",
";",
"this",
".",
"_registerConfigurations",
"(",
")",
";",
"this",
".",
"_registerMiddlewares",
"(",
")",
";",
"this",
".",
"_registerControllers",
"(",
")",
";",
"this",
".",
"_registerAreas",
"(",
")",
";",
"this",
".",
"initialize",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"}"
] | HttpApplication class Constructor instantiate express application | [
"HttpApplication",
"class",
"Constructor",
"instantiate",
"express",
"application"
] | 6571546825b2457e12b98048517f79ec62d16cc4 | https://github.com/microscopejs/microscope-web/blob/6571546825b2457e12b98048517f79ec62d16cc4/src/HttpApplication.js#L8-L15 |
49,256 | christkv/vitesse | lib/custom.js | function(parent, field, options) {
options = options || {};
// Unique id for this node's generated method
this.id = utils.generateId();
// Link to parent node
this.parent = parent;
// The field related to this node
this.field = field;
// Any options
this.options = options;
// Just some metadata
this.type = 'custom';
// Custom context
this.context = {};
} | javascript | function(parent, field, options) {
options = options || {};
// Unique id for this node's generated method
this.id = utils.generateId();
// Link to parent node
this.parent = parent;
// The field related to this node
this.field = field;
// Any options
this.options = options;
// Just some metadata
this.type = 'custom';
// Custom context
this.context = {};
} | [
"function",
"(",
"parent",
",",
"field",
",",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"// Unique id for this node's generated method",
"this",
".",
"id",
"=",
"utils",
".",
"generateId",
"(",
")",
";",
"// Link to parent node",
"this",
".",
"parent",
"=",
"parent",
";",
"// The field related to this node",
"this",
".",
"field",
"=",
"field",
";",
"// Any options",
"this",
".",
"options",
"=",
"options",
";",
"// Just some metadata",
"this",
".",
"type",
"=",
"'custom'",
";",
"// Custom context",
"this",
".",
"context",
"=",
"{",
"}",
";",
"}"
] | The CustomNode class represents a value that can be anything
@class
@return {CustomNode} a CustomNode instance. | [
"The",
"CustomNode",
"class",
"represents",
"a",
"value",
"that",
"can",
"be",
"anything"
] | 6f40f7eaafa7f22644c4c6df80c0bf0590c502ba | https://github.com/christkv/vitesse/blob/6f40f7eaafa7f22644c4c6df80c0bf0590c502ba/lib/custom.js#L13-L27 |
|
49,257 | kmulvey/grunt-beaker | tasks/beaker.js | statFile | function statFile(path, sizes_data, sizes_file_path){
writeFileData(path, fs.statSync(path).mtime.getTime(), fs.statSync(path).size, sizes_data, sizes_file_path);
} | javascript | function statFile(path, sizes_data, sizes_file_path){
writeFileData(path, fs.statSync(path).mtime.getTime(), fs.statSync(path).size, sizes_data, sizes_file_path);
} | [
"function",
"statFile",
"(",
"path",
",",
"sizes_data",
",",
"sizes_file_path",
")",
"{",
"writeFileData",
"(",
"path",
",",
"fs",
".",
"statSync",
"(",
"path",
")",
".",
"mtime",
".",
"getTime",
"(",
")",
",",
"fs",
".",
"statSync",
"(",
"path",
")",
".",
"size",
",",
"sizes_data",
",",
"sizes_file_path",
")",
";",
"}"
] | return the mtime and sizefor file | [
"return",
"the",
"mtime",
"and",
"sizefor",
"file"
] | 94b7a9082b178f0e7961fecf157fb627fc457dcd | https://github.com/kmulvey/grunt-beaker/blob/94b7a9082b178f0e7961fecf157fb627fc457dcd/tasks/beaker.js#L48-L50 |
49,258 | kmulvey/grunt-beaker | tasks/beaker.js | writeFileData | function writeFileData(file_path, time, size, sizes_data, sizes_file_path){
var file_ext = path.extname(file_path).replace('.','');
var file_name = path.basename(file_path);
// create file type object if it doesnt exist
if(sizes_data[file_ext] === undefined){
sizes_data[file_ext] = {};
}
// create file array
if(sizes_data[file_ext][file_name] === undefined){
sizes_data[file_ext][file_name] = [];
}
var time_obj = {
date: time,
size: size
};
grunt.log.writeln(file_path + " .... " + size + "b");
sizes_data[file_ext][file_name].push(time_obj);
fs.writeFileSync(sizes_file_path, JSON.stringify(sizes_data), 'utf8');
} | javascript | function writeFileData(file_path, time, size, sizes_data, sizes_file_path){
var file_ext = path.extname(file_path).replace('.','');
var file_name = path.basename(file_path);
// create file type object if it doesnt exist
if(sizes_data[file_ext] === undefined){
sizes_data[file_ext] = {};
}
// create file array
if(sizes_data[file_ext][file_name] === undefined){
sizes_data[file_ext][file_name] = [];
}
var time_obj = {
date: time,
size: size
};
grunt.log.writeln(file_path + " .... " + size + "b");
sizes_data[file_ext][file_name].push(time_obj);
fs.writeFileSync(sizes_file_path, JSON.stringify(sizes_data), 'utf8');
} | [
"function",
"writeFileData",
"(",
"file_path",
",",
"time",
",",
"size",
",",
"sizes_data",
",",
"sizes_file_path",
")",
"{",
"var",
"file_ext",
"=",
"path",
".",
"extname",
"(",
"file_path",
")",
".",
"replace",
"(",
"'.'",
",",
"''",
")",
";",
"var",
"file_name",
"=",
"path",
".",
"basename",
"(",
"file_path",
")",
";",
"// create file type object if it doesnt exist",
"if",
"(",
"sizes_data",
"[",
"file_ext",
"]",
"===",
"undefined",
")",
"{",
"sizes_data",
"[",
"file_ext",
"]",
"=",
"{",
"}",
";",
"}",
"// create file array",
"if",
"(",
"sizes_data",
"[",
"file_ext",
"]",
"[",
"file_name",
"]",
"===",
"undefined",
")",
"{",
"sizes_data",
"[",
"file_ext",
"]",
"[",
"file_name",
"]",
"=",
"[",
"]",
";",
"}",
"var",
"time_obj",
"=",
"{",
"date",
":",
"time",
",",
"size",
":",
"size",
"}",
";",
"grunt",
".",
"log",
".",
"writeln",
"(",
"file_path",
"+",
"\" .... \"",
"+",
"size",
"+",
"\"b\"",
")",
";",
"sizes_data",
"[",
"file_ext",
"]",
"[",
"file_name",
"]",
".",
"push",
"(",
"time_obj",
")",
";",
"fs",
".",
"writeFileSync",
"(",
"sizes_file_path",
",",
"JSON",
".",
"stringify",
"(",
"sizes_data",
")",
",",
"'utf8'",
")",
";",
"}"
] | create the correct data structure and write it to the file | [
"create",
"the",
"correct",
"data",
"structure",
"and",
"write",
"it",
"to",
"the",
"file"
] | 94b7a9082b178f0e7961fecf157fb627fc457dcd | https://github.com/kmulvey/grunt-beaker/blob/94b7a9082b178f0e7961fecf157fb627fc457dcd/tasks/beaker.js#L53-L74 |
49,259 | redisjs/jsr-script | lib/runner.js | ScriptRunner | function ScriptRunner() {
this.flush();
function onMessage(msg, handle) {
var script, digest;
switch(msg.event) {
case 'loglevel':
log.level(msg.level);
break;
case 'eval':
try {
script = this.load(msg.source).script;
this.run(script, msg.args);
}catch(e) {
process.send({err: true, data: e.message});
}
break;
case 'evalsha':
try {
script = this._cache[msg.sha];
if(!script) throw NoScript;
this.run(script, msg.args);
}catch(e) {
process.send({err: true, data: e.message});
}
break;
case 'load':
try {
digest = this.load(msg.source).sha;
process.send({data: digest});
}catch(e) {
process.send({err: true, data: e.message});
}
break;
case 'exists':
process.send({data: this.exists(msg.args)});
break;
case 'flush':
this.flush();
process.send({data: Constants.OK});
break;
}
}
process.on('message', onMessage.bind(this));
} | javascript | function ScriptRunner() {
this.flush();
function onMessage(msg, handle) {
var script, digest;
switch(msg.event) {
case 'loglevel':
log.level(msg.level);
break;
case 'eval':
try {
script = this.load(msg.source).script;
this.run(script, msg.args);
}catch(e) {
process.send({err: true, data: e.message});
}
break;
case 'evalsha':
try {
script = this._cache[msg.sha];
if(!script) throw NoScript;
this.run(script, msg.args);
}catch(e) {
process.send({err: true, data: e.message});
}
break;
case 'load':
try {
digest = this.load(msg.source).sha;
process.send({data: digest});
}catch(e) {
process.send({err: true, data: e.message});
}
break;
case 'exists':
process.send({data: this.exists(msg.args)});
break;
case 'flush':
this.flush();
process.send({data: Constants.OK});
break;
}
}
process.on('message', onMessage.bind(this));
} | [
"function",
"ScriptRunner",
"(",
")",
"{",
"this",
".",
"flush",
"(",
")",
";",
"function",
"onMessage",
"(",
"msg",
",",
"handle",
")",
"{",
"var",
"script",
",",
"digest",
";",
"switch",
"(",
"msg",
".",
"event",
")",
"{",
"case",
"'loglevel'",
":",
"log",
".",
"level",
"(",
"msg",
".",
"level",
")",
";",
"break",
";",
"case",
"'eval'",
":",
"try",
"{",
"script",
"=",
"this",
".",
"load",
"(",
"msg",
".",
"source",
")",
".",
"script",
";",
"this",
".",
"run",
"(",
"script",
",",
"msg",
".",
"args",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"process",
".",
"send",
"(",
"{",
"err",
":",
"true",
",",
"data",
":",
"e",
".",
"message",
"}",
")",
";",
"}",
"break",
";",
"case",
"'evalsha'",
":",
"try",
"{",
"script",
"=",
"this",
".",
"_cache",
"[",
"msg",
".",
"sha",
"]",
";",
"if",
"(",
"!",
"script",
")",
"throw",
"NoScript",
";",
"this",
".",
"run",
"(",
"script",
",",
"msg",
".",
"args",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"process",
".",
"send",
"(",
"{",
"err",
":",
"true",
",",
"data",
":",
"e",
".",
"message",
"}",
")",
";",
"}",
"break",
";",
"case",
"'load'",
":",
"try",
"{",
"digest",
"=",
"this",
".",
"load",
"(",
"msg",
".",
"source",
")",
".",
"sha",
";",
"process",
".",
"send",
"(",
"{",
"data",
":",
"digest",
"}",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"process",
".",
"send",
"(",
"{",
"err",
":",
"true",
",",
"data",
":",
"e",
".",
"message",
"}",
")",
";",
"}",
"break",
";",
"case",
"'exists'",
":",
"process",
".",
"send",
"(",
"{",
"data",
":",
"this",
".",
"exists",
"(",
"msg",
".",
"args",
")",
"}",
")",
";",
"break",
";",
"case",
"'flush'",
":",
"this",
".",
"flush",
"(",
")",
";",
"process",
".",
"send",
"(",
"{",
"data",
":",
"Constants",
".",
"OK",
"}",
")",
";",
"break",
";",
"}",
"}",
"process",
".",
"on",
"(",
"'message'",
",",
"onMessage",
".",
"bind",
"(",
"this",
")",
")",
";",
"}"
] | Encapsulates script cache, compilation and execution. | [
"Encapsulates",
"script",
"cache",
"compilation",
"and",
"execution",
"."
] | eab3df935372724a82a9ad9ba3bca7e6e165e9d1 | https://github.com/redisjs/jsr-script/blob/eab3df935372724a82a9ad9ba3bca7e6e165e9d1/lib/runner.js#L16-L61 |
49,260 | redisjs/jsr-script | lib/runner.js | sha1hex | function sha1hex(source) {
var hash = crypto.createHash(SHA1);
hash.update(new Buffer('' + source));
return hash.digest(ENCODING);
} | javascript | function sha1hex(source) {
var hash = crypto.createHash(SHA1);
hash.update(new Buffer('' + source));
return hash.digest(ENCODING);
} | [
"function",
"sha1hex",
"(",
"source",
")",
"{",
"var",
"hash",
"=",
"crypto",
".",
"createHash",
"(",
"SHA1",
")",
";",
"hash",
".",
"update",
"(",
"new",
"Buffer",
"(",
"''",
"+",
"source",
")",
")",
";",
"return",
"hash",
".",
"digest",
"(",
"ENCODING",
")",
";",
"}"
] | Utility to create an sha1 checksum from a source script. | [
"Utility",
"to",
"create",
"an",
"sha1",
"checksum",
"from",
"a",
"source",
"script",
"."
] | eab3df935372724a82a9ad9ba3bca7e6e165e9d1 | https://github.com/redisjs/jsr-script/blob/eab3df935372724a82a9ad9ba3bca7e6e165e9d1/lib/runner.js#L66-L70 |
49,261 | redisjs/jsr-script | lib/runner.js | load | function load(source) {
var redis
, method
, script
, name
, digest;
digest = sha1hex(source);
if(this._cache[digest]) {
return {script: this._cache[digest], sha: digest};
}
name = 'f_' + digest;
method = util.format(
'var method = function %s(KEYS, ARGS, cb) {%s}', name, source);
// declare the method
try {
script = vm.createScript(method, name);
}catch(e) {
return process.send(
{
err: true,
data: 'error compiling script (new function): user_script: '
+ e.message});
}
// cache the method by digest
this._cache[digest] = script;
log.debug('script load: %s', digest);
return {sha: digest, script: script};
} | javascript | function load(source) {
var redis
, method
, script
, name
, digest;
digest = sha1hex(source);
if(this._cache[digest]) {
return {script: this._cache[digest], sha: digest};
}
name = 'f_' + digest;
method = util.format(
'var method = function %s(KEYS, ARGS, cb) {%s}', name, source);
// declare the method
try {
script = vm.createScript(method, name);
}catch(e) {
return process.send(
{
err: true,
data: 'error compiling script (new function): user_script: '
+ e.message});
}
// cache the method by digest
this._cache[digest] = script;
log.debug('script load: %s', digest);
return {sha: digest, script: script};
} | [
"function",
"load",
"(",
"source",
")",
"{",
"var",
"redis",
",",
"method",
",",
"script",
",",
"name",
",",
"digest",
";",
"digest",
"=",
"sha1hex",
"(",
"source",
")",
";",
"if",
"(",
"this",
".",
"_cache",
"[",
"digest",
"]",
")",
"{",
"return",
"{",
"script",
":",
"this",
".",
"_cache",
"[",
"digest",
"]",
",",
"sha",
":",
"digest",
"}",
";",
"}",
"name",
"=",
"'f_'",
"+",
"digest",
";",
"method",
"=",
"util",
".",
"format",
"(",
"'var method = function %s(KEYS, ARGS, cb) {%s}'",
",",
"name",
",",
"source",
")",
";",
"// declare the method",
"try",
"{",
"script",
"=",
"vm",
".",
"createScript",
"(",
"method",
",",
"name",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"return",
"process",
".",
"send",
"(",
"{",
"err",
":",
"true",
",",
"data",
":",
"'error compiling script (new function): user_script: '",
"+",
"e",
".",
"message",
"}",
")",
";",
"}",
"// cache the method by digest",
"this",
".",
"_cache",
"[",
"digest",
"]",
"=",
"script",
";",
"log",
".",
"debug",
"(",
"'script load: %s'",
",",
"digest",
")",
";",
"return",
"{",
"sha",
":",
"digest",
",",
"script",
":",
"script",
"}",
";",
"}"
] | Compile a script, generate a digest and add it to the cache. | [
"Compile",
"a",
"script",
"generate",
"a",
"digest",
"and",
"add",
"it",
"to",
"the",
"cache",
"."
] | eab3df935372724a82a9ad9ba3bca7e6e165e9d1 | https://github.com/redisjs/jsr-script/blob/eab3df935372724a82a9ad9ba3bca7e6e165e9d1/lib/runner.js#L75-L107 |
49,262 | redisjs/jsr-script | lib/runner.js | exec | function exec(script, numkeys) {
var KEYS = slice.call(arguments, 2, 2 + numkeys);
var ARGS = slice.call(arguments, numkeys + 2);
function cb(err, reply) {
if(err) reply = err.message;
process.send(
{
err: (err instanceof Error),
data: reply,
str: (reply instanceof String)
});
}
var redis = {
sha1hex: sha1hex,
error_reply: function(err) {
return new Error(err)
},
status_reply: function(status) {
return new String(status)
},
call: function(cmd) {
//console.dir('calling out with: ' + cmd);
var args = slice.call(arguments, 1)
, callback = typeof args[args.length - 1] === 'function'
? args.pop() : null;
function onMessage(msg) {
if(cb) {
if(msg.err) return cb(new Error(msg.data));
cb(null, msg.data);
}
}
process.once('message', onMessage);
process.send({event: 'call', cmd: cmd, args: args});
return callback || cb;
},
LOG_DEBUG: logger.DEBUG,
LOG_VERBOSE: logger.VERBOSE,
LOG_NOTICE: logger.NOTICE,
LOG_WARNING: logger.WARNING,
log: function rlog() {
return log.log.apply(log, arguments);
}
}
//console.dir(redis);
var sandbox = {
Error: Error,
Buffer: Buffer,
JSON: JSON,
crypto: crypto,
util: util,
redis: redis,
KEYS: KEYS,
ARGS: ARGS,
cb: cb
}
script.runInNewContext(sandbox);
process.send({event: 'eval', data: sandbox.method.name});
var result;
try {
result = sandbox.method(sandbox.KEYS, sandbox.ARGS, sandbox.cb);
// coerce thrown errors
}catch(e) {
result = e;
}
//console.dir(result);
if(Buffer.isBuffer(result)) {
result = result.toString();
}
if(result
&& !(result instanceof Error)
&& typeof result === 'object') {
if(result.err) {
result = new Error(result.err);
}else if(result.ok) {
result = new String(result.ok);
}
}
//console.dir(result);
return {
result: result,
sandbox: sandbox,
script: script,
name: sandbox.method.name
};
} | javascript | function exec(script, numkeys) {
var KEYS = slice.call(arguments, 2, 2 + numkeys);
var ARGS = slice.call(arguments, numkeys + 2);
function cb(err, reply) {
if(err) reply = err.message;
process.send(
{
err: (err instanceof Error),
data: reply,
str: (reply instanceof String)
});
}
var redis = {
sha1hex: sha1hex,
error_reply: function(err) {
return new Error(err)
},
status_reply: function(status) {
return new String(status)
},
call: function(cmd) {
//console.dir('calling out with: ' + cmd);
var args = slice.call(arguments, 1)
, callback = typeof args[args.length - 1] === 'function'
? args.pop() : null;
function onMessage(msg) {
if(cb) {
if(msg.err) return cb(new Error(msg.data));
cb(null, msg.data);
}
}
process.once('message', onMessage);
process.send({event: 'call', cmd: cmd, args: args});
return callback || cb;
},
LOG_DEBUG: logger.DEBUG,
LOG_VERBOSE: logger.VERBOSE,
LOG_NOTICE: logger.NOTICE,
LOG_WARNING: logger.WARNING,
log: function rlog() {
return log.log.apply(log, arguments);
}
}
//console.dir(redis);
var sandbox = {
Error: Error,
Buffer: Buffer,
JSON: JSON,
crypto: crypto,
util: util,
redis: redis,
KEYS: KEYS,
ARGS: ARGS,
cb: cb
}
script.runInNewContext(sandbox);
process.send({event: 'eval', data: sandbox.method.name});
var result;
try {
result = sandbox.method(sandbox.KEYS, sandbox.ARGS, sandbox.cb);
// coerce thrown errors
}catch(e) {
result = e;
}
//console.dir(result);
if(Buffer.isBuffer(result)) {
result = result.toString();
}
if(result
&& !(result instanceof Error)
&& typeof result === 'object') {
if(result.err) {
result = new Error(result.err);
}else if(result.ok) {
result = new String(result.ok);
}
}
//console.dir(result);
return {
result: result,
sandbox: sandbox,
script: script,
name: sandbox.method.name
};
} | [
"function",
"exec",
"(",
"script",
",",
"numkeys",
")",
"{",
"var",
"KEYS",
"=",
"slice",
".",
"call",
"(",
"arguments",
",",
"2",
",",
"2",
"+",
"numkeys",
")",
";",
"var",
"ARGS",
"=",
"slice",
".",
"call",
"(",
"arguments",
",",
"numkeys",
"+",
"2",
")",
";",
"function",
"cb",
"(",
"err",
",",
"reply",
")",
"{",
"if",
"(",
"err",
")",
"reply",
"=",
"err",
".",
"message",
";",
"process",
".",
"send",
"(",
"{",
"err",
":",
"(",
"err",
"instanceof",
"Error",
")",
",",
"data",
":",
"reply",
",",
"str",
":",
"(",
"reply",
"instanceof",
"String",
")",
"}",
")",
";",
"}",
"var",
"redis",
"=",
"{",
"sha1hex",
":",
"sha1hex",
",",
"error_reply",
":",
"function",
"(",
"err",
")",
"{",
"return",
"new",
"Error",
"(",
"err",
")",
"}",
",",
"status_reply",
":",
"function",
"(",
"status",
")",
"{",
"return",
"new",
"String",
"(",
"status",
")",
"}",
",",
"call",
":",
"function",
"(",
"cmd",
")",
"{",
"//console.dir('calling out with: ' + cmd);",
"var",
"args",
"=",
"slice",
".",
"call",
"(",
"arguments",
",",
"1",
")",
",",
"callback",
"=",
"typeof",
"args",
"[",
"args",
".",
"length",
"-",
"1",
"]",
"===",
"'function'",
"?",
"args",
".",
"pop",
"(",
")",
":",
"null",
";",
"function",
"onMessage",
"(",
"msg",
")",
"{",
"if",
"(",
"cb",
")",
"{",
"if",
"(",
"msg",
".",
"err",
")",
"return",
"cb",
"(",
"new",
"Error",
"(",
"msg",
".",
"data",
")",
")",
";",
"cb",
"(",
"null",
",",
"msg",
".",
"data",
")",
";",
"}",
"}",
"process",
".",
"once",
"(",
"'message'",
",",
"onMessage",
")",
";",
"process",
".",
"send",
"(",
"{",
"event",
":",
"'call'",
",",
"cmd",
":",
"cmd",
",",
"args",
":",
"args",
"}",
")",
";",
"return",
"callback",
"||",
"cb",
";",
"}",
",",
"LOG_DEBUG",
":",
"logger",
".",
"DEBUG",
",",
"LOG_VERBOSE",
":",
"logger",
".",
"VERBOSE",
",",
"LOG_NOTICE",
":",
"logger",
".",
"NOTICE",
",",
"LOG_WARNING",
":",
"logger",
".",
"WARNING",
",",
"log",
":",
"function",
"rlog",
"(",
")",
"{",
"return",
"log",
".",
"log",
".",
"apply",
"(",
"log",
",",
"arguments",
")",
";",
"}",
"}",
"//console.dir(redis);",
"var",
"sandbox",
"=",
"{",
"Error",
":",
"Error",
",",
"Buffer",
":",
"Buffer",
",",
"JSON",
":",
"JSON",
",",
"crypto",
":",
"crypto",
",",
"util",
":",
"util",
",",
"redis",
":",
"redis",
",",
"KEYS",
":",
"KEYS",
",",
"ARGS",
":",
"ARGS",
",",
"cb",
":",
"cb",
"}",
"script",
".",
"runInNewContext",
"(",
"sandbox",
")",
";",
"process",
".",
"send",
"(",
"{",
"event",
":",
"'eval'",
",",
"data",
":",
"sandbox",
".",
"method",
".",
"name",
"}",
")",
";",
"var",
"result",
";",
"try",
"{",
"result",
"=",
"sandbox",
".",
"method",
"(",
"sandbox",
".",
"KEYS",
",",
"sandbox",
".",
"ARGS",
",",
"sandbox",
".",
"cb",
")",
";",
"// coerce thrown errors",
"}",
"catch",
"(",
"e",
")",
"{",
"result",
"=",
"e",
";",
"}",
"//console.dir(result);",
"if",
"(",
"Buffer",
".",
"isBuffer",
"(",
"result",
")",
")",
"{",
"result",
"=",
"result",
".",
"toString",
"(",
")",
";",
"}",
"if",
"(",
"result",
"&&",
"!",
"(",
"result",
"instanceof",
"Error",
")",
"&&",
"typeof",
"result",
"===",
"'object'",
")",
"{",
"if",
"(",
"result",
".",
"err",
")",
"{",
"result",
"=",
"new",
"Error",
"(",
"result",
".",
"err",
")",
";",
"}",
"else",
"if",
"(",
"result",
".",
"ok",
")",
"{",
"result",
"=",
"new",
"String",
"(",
"result",
".",
"ok",
")",
";",
"}",
"}",
"//console.dir(result);",
"return",
"{",
"result",
":",
"result",
",",
"sandbox",
":",
"sandbox",
",",
"script",
":",
"script",
",",
"name",
":",
"sandbox",
".",
"method",
".",
"name",
"}",
";",
"}"
] | Execute a pre-compiled script. | [
"Execute",
"a",
"pre",
"-",
"compiled",
"script",
"."
] | eab3df935372724a82a9ad9ba3bca7e6e165e9d1 | https://github.com/redisjs/jsr-script/blob/eab3df935372724a82a9ad9ba3bca7e6e165e9d1/lib/runner.js#L112-L207 |
49,263 | redisjs/jsr-script | lib/runner.js | run | function run(script, args) {
var res, result, name;
try {
res = this.exec.apply(this, [script].concat(args));
result = res.result;
//console.dir(result);
//console.dir(result instanceof Error);
if(typeof result === 'function') return;
if(result === undefined) {
throw new Error('undefined return value is not allowed');
}else if(
result !== null
&& !(result instanceof String)
&& !(result instanceof Error)
&& typeof result === 'object'
&& !Array.isArray(result)) {
throw new Error('object return value is not allowed');
}
}catch(e) {
name = res && res.name ? res.name : 'user_script';
result = new StoreError(
null, 'error running script (call to %s): %s', name, e.message);
}
if(typeof result === 'boolean') {
result = Number(result);
}
// TODO: check the return value is not an object!!!
//
var err = (result instanceof Error);
if(err) result = result.message;
process.send({err: err, data: result, str: (result instanceof String)});
} | javascript | function run(script, args) {
var res, result, name;
try {
res = this.exec.apply(this, [script].concat(args));
result = res.result;
//console.dir(result);
//console.dir(result instanceof Error);
if(typeof result === 'function') return;
if(result === undefined) {
throw new Error('undefined return value is not allowed');
}else if(
result !== null
&& !(result instanceof String)
&& !(result instanceof Error)
&& typeof result === 'object'
&& !Array.isArray(result)) {
throw new Error('object return value is not allowed');
}
}catch(e) {
name = res && res.name ? res.name : 'user_script';
result = new StoreError(
null, 'error running script (call to %s): %s', name, e.message);
}
if(typeof result === 'boolean') {
result = Number(result);
}
// TODO: check the return value is not an object!!!
//
var err = (result instanceof Error);
if(err) result = result.message;
process.send({err: err, data: result, str: (result instanceof String)});
} | [
"function",
"run",
"(",
"script",
",",
"args",
")",
"{",
"var",
"res",
",",
"result",
",",
"name",
";",
"try",
"{",
"res",
"=",
"this",
".",
"exec",
".",
"apply",
"(",
"this",
",",
"[",
"script",
"]",
".",
"concat",
"(",
"args",
")",
")",
";",
"result",
"=",
"res",
".",
"result",
";",
"//console.dir(result);",
"//console.dir(result instanceof Error);",
"if",
"(",
"typeof",
"result",
"===",
"'function'",
")",
"return",
";",
"if",
"(",
"result",
"===",
"undefined",
")",
"{",
"throw",
"new",
"Error",
"(",
"'undefined return value is not allowed'",
")",
";",
"}",
"else",
"if",
"(",
"result",
"!==",
"null",
"&&",
"!",
"(",
"result",
"instanceof",
"String",
")",
"&&",
"!",
"(",
"result",
"instanceof",
"Error",
")",
"&&",
"typeof",
"result",
"===",
"'object'",
"&&",
"!",
"Array",
".",
"isArray",
"(",
"result",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'object return value is not allowed'",
")",
";",
"}",
"}",
"catch",
"(",
"e",
")",
"{",
"name",
"=",
"res",
"&&",
"res",
".",
"name",
"?",
"res",
".",
"name",
":",
"'user_script'",
";",
"result",
"=",
"new",
"StoreError",
"(",
"null",
",",
"'error running script (call to %s): %s'",
",",
"name",
",",
"e",
".",
"message",
")",
";",
"}",
"if",
"(",
"typeof",
"result",
"===",
"'boolean'",
")",
"{",
"result",
"=",
"Number",
"(",
"result",
")",
";",
"}",
"// TODO: check the return value is not an object!!!",
"//",
"var",
"err",
"=",
"(",
"result",
"instanceof",
"Error",
")",
";",
"if",
"(",
"err",
")",
"result",
"=",
"result",
".",
"message",
";",
"process",
".",
"send",
"(",
"{",
"err",
":",
"err",
",",
"data",
":",
"result",
",",
"str",
":",
"(",
"result",
"instanceof",
"String",
")",
"}",
")",
";",
"}"
] | Run a script.
@param script The compiled script function.
@param args The script arguments. | [
"Run",
"a",
"script",
"."
] | eab3df935372724a82a9ad9ba3bca7e6e165e9d1 | https://github.com/redisjs/jsr-script/blob/eab3df935372724a82a9ad9ba3bca7e6e165e9d1/lib/runner.js#L215-L250 |
49,264 | redisjs/jsr-script | lib/runner.js | exists | function exists(args) {
var list = [];
for(var i = 0;i < args.length;i++) {
list.push(this._cache[args[i]] ? 1 : 0);
}
return list;
} | javascript | function exists(args) {
var list = [];
for(var i = 0;i < args.length;i++) {
list.push(this._cache[args[i]] ? 1 : 0);
}
return list;
} | [
"function",
"exists",
"(",
"args",
")",
"{",
"var",
"list",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"args",
".",
"length",
";",
"i",
"++",
")",
"{",
"list",
".",
"push",
"(",
"this",
".",
"_cache",
"[",
"args",
"[",
"i",
"]",
"]",
"?",
"1",
":",
"0",
")",
";",
"}",
"return",
"list",
";",
"}"
] | Get a script by sha digest. | [
"Get",
"a",
"script",
"by",
"sha",
"digest",
"."
] | eab3df935372724a82a9ad9ba3bca7e6e165e9d1 | https://github.com/redisjs/jsr-script/blob/eab3df935372724a82a9ad9ba3bca7e6e165e9d1/lib/runner.js#L255-L261 |
49,265 | tolokoban/ToloFrameWork | tst/www/js/@index.js | fixContainer | function fixContainer ( container ) {
var children = container.childNodes,
doc = container.ownerDocument,
wrapper = null,
i, l, child, isBR,
config = getSquireInstance( doc )._config;
for ( i = 0, l = children.length; i < l; i += 1 ) {
child = children[i];
isBR = child.nodeName === 'BR';
if ( !isBR && isInline( child ) ) {
if ( !wrapper ) {
wrapper = createElement( doc,
config.blockTag, config.blockAttributes );
}
wrapper.appendChild( child );
i -= 1;
l -= 1;
} else if ( isBR || wrapper ) {
if ( !wrapper ) {
wrapper = createElement( doc,
config.blockTag, config.blockAttributes );
}
fixCursor( wrapper );
if ( isBR ) {
container.replaceChild( wrapper, child );
} else {
container.insertBefore( wrapper, child );
i += 1;
l += 1;
}
wrapper = null;
}
if ( isContainer( child ) ) {
fixContainer( child );
}
}
if ( wrapper ) {
container.appendChild( fixCursor( wrapper ) );
}
return container;
} | javascript | function fixContainer ( container ) {
var children = container.childNodes,
doc = container.ownerDocument,
wrapper = null,
i, l, child, isBR,
config = getSquireInstance( doc )._config;
for ( i = 0, l = children.length; i < l; i += 1 ) {
child = children[i];
isBR = child.nodeName === 'BR';
if ( !isBR && isInline( child ) ) {
if ( !wrapper ) {
wrapper = createElement( doc,
config.blockTag, config.blockAttributes );
}
wrapper.appendChild( child );
i -= 1;
l -= 1;
} else if ( isBR || wrapper ) {
if ( !wrapper ) {
wrapper = createElement( doc,
config.blockTag, config.blockAttributes );
}
fixCursor( wrapper );
if ( isBR ) {
container.replaceChild( wrapper, child );
} else {
container.insertBefore( wrapper, child );
i += 1;
l += 1;
}
wrapper = null;
}
if ( isContainer( child ) ) {
fixContainer( child );
}
}
if ( wrapper ) {
container.appendChild( fixCursor( wrapper ) );
}
return container;
} | [
"function",
"fixContainer",
"(",
"container",
")",
"{",
"var",
"children",
"=",
"container",
".",
"childNodes",
",",
"doc",
"=",
"container",
".",
"ownerDocument",
",",
"wrapper",
"=",
"null",
",",
"i",
",",
"l",
",",
"child",
",",
"isBR",
",",
"config",
"=",
"getSquireInstance",
"(",
"doc",
")",
".",
"_config",
";",
"for",
"(",
"i",
"=",
"0",
",",
"l",
"=",
"children",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"+=",
"1",
")",
"{",
"child",
"=",
"children",
"[",
"i",
"]",
";",
"isBR",
"=",
"child",
".",
"nodeName",
"===",
"'BR'",
";",
"if",
"(",
"!",
"isBR",
"&&",
"isInline",
"(",
"child",
")",
")",
"{",
"if",
"(",
"!",
"wrapper",
")",
"{",
"wrapper",
"=",
"createElement",
"(",
"doc",
",",
"config",
".",
"blockTag",
",",
"config",
".",
"blockAttributes",
")",
";",
"}",
"wrapper",
".",
"appendChild",
"(",
"child",
")",
";",
"i",
"-=",
"1",
";",
"l",
"-=",
"1",
";",
"}",
"else",
"if",
"(",
"isBR",
"||",
"wrapper",
")",
"{",
"if",
"(",
"!",
"wrapper",
")",
"{",
"wrapper",
"=",
"createElement",
"(",
"doc",
",",
"config",
".",
"blockTag",
",",
"config",
".",
"blockAttributes",
")",
";",
"}",
"fixCursor",
"(",
"wrapper",
")",
";",
"if",
"(",
"isBR",
")",
"{",
"container",
".",
"replaceChild",
"(",
"wrapper",
",",
"child",
")",
";",
"}",
"else",
"{",
"container",
".",
"insertBefore",
"(",
"wrapper",
",",
"child",
")",
";",
"i",
"+=",
"1",
";",
"l",
"+=",
"1",
";",
"}",
"wrapper",
"=",
"null",
";",
"}",
"if",
"(",
"isContainer",
"(",
"child",
")",
")",
"{",
"fixContainer",
"(",
"child",
")",
";",
"}",
"}",
"if",
"(",
"wrapper",
")",
"{",
"container",
".",
"appendChild",
"(",
"fixCursor",
"(",
"wrapper",
")",
")",
";",
"}",
"return",
"container",
";",
"}"
] | Recursively examine container nodes and wrap any inline children. | [
"Recursively",
"examine",
"container",
"nodes",
"and",
"wrap",
"any",
"inline",
"children",
"."
] | 730845a833a9660ebfdb60ad027ebaab5ac871b6 | https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/tst/www/js/@index.js#L501-L542 |
49,266 | tolokoban/ToloFrameWork | tst/www/js/@index.js | function ( node, exemplar ) {
// If the node is completely contained by the range then
// we're going to remove all formatting so ignore it.
if ( isNodeContainedInRange( range, node, false ) ) {
return;
}
var isText = ( node.nodeType === TEXT_NODE ),
child, next;
// If not at least partially contained, wrap entire contents
// in a clone of the tag we're removing and we're done.
if ( !isNodeContainedInRange( range, node, true ) ) {
// Ignore bookmarks and empty text nodes
if ( node.nodeName !== 'INPUT' &&
( !isText || node.data ) ) {
toWrap.push([ exemplar, node ]);
}
return;
}
// Split any partially selected text nodes.
if ( isText ) {
if ( node === endContainer && endOffset !== node.length ) {
toWrap.push([ exemplar, node.splitText( endOffset ) ]);
}
if ( node === startContainer && startOffset ) {
node.splitText( startOffset );
toWrap.push([ exemplar, node ]);
}
}
// If not a text node, recurse onto all children.
// Beware, the tree may be rewritten with each call
// to examineNode, hence find the next sibling first.
else {
for ( child = node.firstChild; child; child = next ) {
next = child.nextSibling;
examineNode( child, exemplar );
}
}
} | javascript | function ( node, exemplar ) {
// If the node is completely contained by the range then
// we're going to remove all formatting so ignore it.
if ( isNodeContainedInRange( range, node, false ) ) {
return;
}
var isText = ( node.nodeType === TEXT_NODE ),
child, next;
// If not at least partially contained, wrap entire contents
// in a clone of the tag we're removing and we're done.
if ( !isNodeContainedInRange( range, node, true ) ) {
// Ignore bookmarks and empty text nodes
if ( node.nodeName !== 'INPUT' &&
( !isText || node.data ) ) {
toWrap.push([ exemplar, node ]);
}
return;
}
// Split any partially selected text nodes.
if ( isText ) {
if ( node === endContainer && endOffset !== node.length ) {
toWrap.push([ exemplar, node.splitText( endOffset ) ]);
}
if ( node === startContainer && startOffset ) {
node.splitText( startOffset );
toWrap.push([ exemplar, node ]);
}
}
// If not a text node, recurse onto all children.
// Beware, the tree may be rewritten with each call
// to examineNode, hence find the next sibling first.
else {
for ( child = node.firstChild; child; child = next ) {
next = child.nextSibling;
examineNode( child, exemplar );
}
}
} | [
"function",
"(",
"node",
",",
"exemplar",
")",
"{",
"// If the node is completely contained by the range then",
"// we're going to remove all formatting so ignore it.",
"if",
"(",
"isNodeContainedInRange",
"(",
"range",
",",
"node",
",",
"false",
")",
")",
"{",
"return",
";",
"}",
"var",
"isText",
"=",
"(",
"node",
".",
"nodeType",
"===",
"TEXT_NODE",
")",
",",
"child",
",",
"next",
";",
"// If not at least partially contained, wrap entire contents",
"// in a clone of the tag we're removing and we're done.",
"if",
"(",
"!",
"isNodeContainedInRange",
"(",
"range",
",",
"node",
",",
"true",
")",
")",
"{",
"// Ignore bookmarks and empty text nodes",
"if",
"(",
"node",
".",
"nodeName",
"!==",
"'INPUT'",
"&&",
"(",
"!",
"isText",
"||",
"node",
".",
"data",
")",
")",
"{",
"toWrap",
".",
"push",
"(",
"[",
"exemplar",
",",
"node",
"]",
")",
";",
"}",
"return",
";",
"}",
"// Split any partially selected text nodes.",
"if",
"(",
"isText",
")",
"{",
"if",
"(",
"node",
"===",
"endContainer",
"&&",
"endOffset",
"!==",
"node",
".",
"length",
")",
"{",
"toWrap",
".",
"push",
"(",
"[",
"exemplar",
",",
"node",
".",
"splitText",
"(",
"endOffset",
")",
"]",
")",
";",
"}",
"if",
"(",
"node",
"===",
"startContainer",
"&&",
"startOffset",
")",
"{",
"node",
".",
"splitText",
"(",
"startOffset",
")",
";",
"toWrap",
".",
"push",
"(",
"[",
"exemplar",
",",
"node",
"]",
")",
";",
"}",
"}",
"// If not a text node, recurse onto all children.",
"// Beware, the tree may be rewritten with each call",
"// to examineNode, hence find the next sibling first.",
"else",
"{",
"for",
"(",
"child",
"=",
"node",
".",
"firstChild",
";",
"child",
";",
"child",
"=",
"next",
")",
"{",
"next",
"=",
"child",
".",
"nextSibling",
";",
"examineNode",
"(",
"child",
",",
"exemplar",
")",
";",
"}",
"}",
"}"
] | Find text nodes inside formatTags that are not in selection and add an extra tag with the same formatting. | [
"Find",
"text",
"nodes",
"inside",
"formatTags",
"that",
"are",
"not",
"in",
"selection",
"and",
"add",
"an",
"extra",
"tag",
"with",
"the",
"same",
"formatting",
"."
] | 730845a833a9660ebfdb60ad027ebaab5ac871b6 | https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/tst/www/js/@index.js#L3231-L3271 |
|
49,267 | kyleburnett/error-engine | index.js | compose | function compose(auto_template, dictionary, key, params) {
var composer = dictionary[key];
// If auto_template is set to true, make dictionary value
if (auto_template) {
if (typeof composer === "string") {
composer = _.template(composer);
} else if (typeof composer !== "function" ) {
var msg = 'Expected value to auto-template - "' + composer + '" - to be type "string"';
msg += ' but got "' + typeof composer + '".';
throw new Error(msg);
}
}
switch (typeof composer) {
case "string": return composer;
case "function": return composer(params);
default:
{
var msg = 'Unprocessable message "' + composer + '" of type "' + typeof composer;
msg += '" for key "' + key + '".'
throw new Error(msg);
}
}
} | javascript | function compose(auto_template, dictionary, key, params) {
var composer = dictionary[key];
// If auto_template is set to true, make dictionary value
if (auto_template) {
if (typeof composer === "string") {
composer = _.template(composer);
} else if (typeof composer !== "function" ) {
var msg = 'Expected value to auto-template - "' + composer + '" - to be type "string"';
msg += ' but got "' + typeof composer + '".';
throw new Error(msg);
}
}
switch (typeof composer) {
case "string": return composer;
case "function": return composer(params);
default:
{
var msg = 'Unprocessable message "' + composer + '" of type "' + typeof composer;
msg += '" for key "' + key + '".'
throw new Error(msg);
}
}
} | [
"function",
"compose",
"(",
"auto_template",
",",
"dictionary",
",",
"key",
",",
"params",
")",
"{",
"var",
"composer",
"=",
"dictionary",
"[",
"key",
"]",
";",
"// If auto_template is set to true, make dictionary value",
"if",
"(",
"auto_template",
")",
"{",
"if",
"(",
"typeof",
"composer",
"===",
"\"string\"",
")",
"{",
"composer",
"=",
"_",
".",
"template",
"(",
"composer",
")",
";",
"}",
"else",
"if",
"(",
"typeof",
"composer",
"!==",
"\"function\"",
")",
"{",
"var",
"msg",
"=",
"'Expected value to auto-template - \"'",
"+",
"composer",
"+",
"'\" - to be type \"string\"'",
";",
"msg",
"+=",
"' but got \"'",
"+",
"typeof",
"composer",
"+",
"'\".'",
";",
"throw",
"new",
"Error",
"(",
"msg",
")",
";",
"}",
"}",
"switch",
"(",
"typeof",
"composer",
")",
"{",
"case",
"\"string\"",
":",
"return",
"composer",
";",
"case",
"\"function\"",
":",
"return",
"composer",
"(",
"params",
")",
";",
"default",
":",
"{",
"var",
"msg",
"=",
"'Unprocessable message \"'",
"+",
"composer",
"+",
"'\" of type \"'",
"+",
"typeof",
"composer",
";",
"msg",
"+=",
"'\" for key \"'",
"+",
"key",
"+",
"'\".'",
"throw",
"new",
"Error",
"(",
"msg",
")",
";",
"}",
"}",
"}"
] | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Local Functions | [
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~",
"Local",
"Functions"
] | 16be944e2f6457e3dc6755e080077e441f07e207 | https://github.com/kyleburnett/error-engine/blob/16be944e2f6457e3dc6755e080077e441f07e207/index.js#L12-L36 |
49,268 | fortyau/grunt-fg-codependent | tasks/componentize.js | resolveSerializer | function resolveSerializer(key) {
var serializer = SERIALIZERS[key] || key;
if (!_.isFunction(serializer)) {
grunt.fail.warn('Invalid serializer. Serializer needs to be a function.');
}
return serializer;
} | javascript | function resolveSerializer(key) {
var serializer = SERIALIZERS[key] || key;
if (!_.isFunction(serializer)) {
grunt.fail.warn('Invalid serializer. Serializer needs to be a function.');
}
return serializer;
} | [
"function",
"resolveSerializer",
"(",
"key",
")",
"{",
"var",
"serializer",
"=",
"SERIALIZERS",
"[",
"key",
"]",
"||",
"key",
";",
"if",
"(",
"!",
"_",
".",
"isFunction",
"(",
"serializer",
")",
")",
"{",
"grunt",
".",
"fail",
".",
"warn",
"(",
"'Invalid serializer. Serializer needs to be a function.'",
")",
";",
"}",
"return",
"serializer",
";",
"}"
] | Add delimiters that do not conflict with grunt | [
"Add",
"delimiters",
"that",
"do",
"not",
"conflict",
"with",
"grunt"
] | c7f57943eae6cdcade108e2a8ba8918297857394 | https://github.com/fortyau/grunt-fg-codependent/blob/c7f57943eae6cdcade108e2a8ba8918297857394/tasks/componentize.js#L95-L101 |
49,269 | tolokoban/ToloFrameWork | lib/module-analyser.js | extractInfoFromAst | function extractInfoFromAst( ast ) {
const output = {
requires: [],
exports: findExports( ast )
};
recursivelyExtractInfoFromAst( ast.program.body, output );
return output;
} | javascript | function extractInfoFromAst( ast ) {
const output = {
requires: [],
exports: findExports( ast )
};
recursivelyExtractInfoFromAst( ast.program.body, output );
return output;
} | [
"function",
"extractInfoFromAst",
"(",
"ast",
")",
"{",
"const",
"output",
"=",
"{",
"requires",
":",
"[",
"]",
",",
"exports",
":",
"findExports",
"(",
"ast",
")",
"}",
";",
"recursivelyExtractInfoFromAst",
"(",
"ast",
".",
"program",
".",
"body",
",",
"output",
")",
";",
"return",
"output",
";",
"}"
] | Try to figure oout which modules are needed from this javascript code.
@param {object} ast - Abstract Syntax Tree from Babel.
@returns {object} `{ requires: [] }`. | [
"Try",
"to",
"figure",
"oout",
"which",
"modules",
"are",
"needed",
"from",
"this",
"javascript",
"code",
"."
] | 730845a833a9660ebfdb60ad027ebaab5ac871b6 | https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/lib/module-analyser.js#L21-L28 |
49,270 | tolokoban/ToloFrameWork | lib/module-analyser.js | findExports | function findExports( ast ) {
try {
const
publics = {},
privates = {},
body = ast.program.body[ 0 ].expression.arguments[ 1 ].body.body;
body.forEach( function ( item ) {
if ( parseExports( item, publics ) ) return;
if ( parseModuleExports( item, publics ) ) return;
parseFunctionDeclaration( item, privates );
} );
const output = [];
Object.keys( publics ).forEach( function ( exportName ) {
const
exportValue = publics[ exportName ],
target = privates[ exportValue.target ];
if ( target ) {
exportValue.comments = exportValue.comments || target.comments;
exportValue.type = target.type;
exportValue.params = target.params;
}
output.push( {
id: exportName,
type: exportValue.type,
params: exportValue.params,
comments: exportValue.comments
} );
} );
return output;
} catch ( ex ) {
throw new Error( `${ex}\n...in module-analyser/findExports()` );
}
} | javascript | function findExports( ast ) {
try {
const
publics = {},
privates = {},
body = ast.program.body[ 0 ].expression.arguments[ 1 ].body.body;
body.forEach( function ( item ) {
if ( parseExports( item, publics ) ) return;
if ( parseModuleExports( item, publics ) ) return;
parseFunctionDeclaration( item, privates );
} );
const output = [];
Object.keys( publics ).forEach( function ( exportName ) {
const
exportValue = publics[ exportName ],
target = privates[ exportValue.target ];
if ( target ) {
exportValue.comments = exportValue.comments || target.comments;
exportValue.type = target.type;
exportValue.params = target.params;
}
output.push( {
id: exportName,
type: exportValue.type,
params: exportValue.params,
comments: exportValue.comments
} );
} );
return output;
} catch ( ex ) {
throw new Error( `${ex}\n...in module-analyser/findExports()` );
}
} | [
"function",
"findExports",
"(",
"ast",
")",
"{",
"try",
"{",
"const",
"publics",
"=",
"{",
"}",
",",
"privates",
"=",
"{",
"}",
",",
"body",
"=",
"ast",
".",
"program",
".",
"body",
"[",
"0",
"]",
".",
"expression",
".",
"arguments",
"[",
"1",
"]",
".",
"body",
".",
"body",
";",
"body",
".",
"forEach",
"(",
"function",
"(",
"item",
")",
"{",
"if",
"(",
"parseExports",
"(",
"item",
",",
"publics",
")",
")",
"return",
";",
"if",
"(",
"parseModuleExports",
"(",
"item",
",",
"publics",
")",
")",
"return",
";",
"parseFunctionDeclaration",
"(",
"item",
",",
"privates",
")",
";",
"}",
")",
";",
"const",
"output",
"=",
"[",
"]",
";",
"Object",
".",
"keys",
"(",
"publics",
")",
".",
"forEach",
"(",
"function",
"(",
"exportName",
")",
"{",
"const",
"exportValue",
"=",
"publics",
"[",
"exportName",
"]",
",",
"target",
"=",
"privates",
"[",
"exportValue",
".",
"target",
"]",
";",
"if",
"(",
"target",
")",
"{",
"exportValue",
".",
"comments",
"=",
"exportValue",
".",
"comments",
"||",
"target",
".",
"comments",
";",
"exportValue",
".",
"type",
"=",
"target",
".",
"type",
";",
"exportValue",
".",
"params",
"=",
"target",
".",
"params",
";",
"}",
"output",
".",
"push",
"(",
"{",
"id",
":",
"exportName",
",",
"type",
":",
"exportValue",
".",
"type",
",",
"params",
":",
"exportValue",
".",
"params",
",",
"comments",
":",
"exportValue",
".",
"comments",
"}",
")",
";",
"}",
")",
";",
"return",
"output",
";",
"}",
"catch",
"(",
"ex",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"ex",
"}",
"\\n",
"`",
")",
";",
"}",
"}"
] | Look for the exports of the module with their comments.
This will be used for documentation.
@param {object} ast - AST of the module.
@returns {array} `{ id, type, comments }` | [
"Look",
"for",
"the",
"exports",
"of",
"the",
"module",
"with",
"their",
"comments",
".",
"This",
"will",
"be",
"used",
"for",
"documentation",
"."
] | 730845a833a9660ebfdb60ad027ebaab5ac871b6 | https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/lib/module-analyser.js#L84-L119 |
49,271 | Phalanstere/VisualData | lib/readVisualData.js | exif | function exif (file) {
"use strict";
var deferred = Q.defer(), o = {};
new ExifImage({ image : file }, function (error, data) {
if (error)
{
// callback.call("error " + file);
deferred.reject("ERROR");
}
if (data)
{
o.file = file;
o.data = data;
deferred.resolve(o);
}
});
return deferred.promise;
} | javascript | function exif (file) {
"use strict";
var deferred = Q.defer(), o = {};
new ExifImage({ image : file }, function (error, data) {
if (error)
{
// callback.call("error " + file);
deferred.reject("ERROR");
}
if (data)
{
o.file = file;
o.data = data;
deferred.resolve(o);
}
});
return deferred.promise;
} | [
"function",
"exif",
"(",
"file",
")",
"{",
"\"use strict\"",
";",
"var",
"deferred",
"=",
"Q",
".",
"defer",
"(",
")",
",",
"o",
"=",
"{",
"}",
";",
"new",
"ExifImage",
"(",
"{",
"image",
":",
"file",
"}",
",",
"function",
"(",
"error",
",",
"data",
")",
"{",
"if",
"(",
"error",
")",
"{",
"// callback.call(\"error \" + file);",
"deferred",
".",
"reject",
"(",
"\"ERROR\"",
")",
";",
"}",
"if",
"(",
"data",
")",
"{",
"o",
".",
"file",
"=",
"file",
";",
"o",
".",
"data",
"=",
"data",
";",
"deferred",
".",
"resolve",
"(",
"o",
")",
";",
"}",
"}",
")",
";",
"return",
"deferred",
".",
"promise",
";",
"}"
] | liest die exif Daten des Bides ein | [
"liest",
"die",
"exif",
"Daten",
"des",
"Bides",
"ein"
] | 59bdc6cea190366d4bb466cf4e39e22f887e5104 | https://github.com/Phalanstere/VisualData/blob/59bdc6cea190366d4bb466cf4e39e22f887e5104/lib/readVisualData.js#L62-L81 |
49,272 | jmjuanes/utily | lib/index.js | function(index)
{
//Check the index value
if(index >= keys.length)
{
//Do the callback and exit
return cb(null);
}
else
{
//Get the key
var key = (is_array) ? index : keys[index];
//Get the value
var value = list[key];
//Call the provided method with the element of the array
return fn.call(null, key, value, function(error)
{
//Check the error
if(error)
{
//Do the callback with the provided error
return cb(error);
}
else
{
//Continue with the next item on the list
return each_async(index + 1);
}
});
}
} | javascript | function(index)
{
//Check the index value
if(index >= keys.length)
{
//Do the callback and exit
return cb(null);
}
else
{
//Get the key
var key = (is_array) ? index : keys[index];
//Get the value
var value = list[key];
//Call the provided method with the element of the array
return fn.call(null, key, value, function(error)
{
//Check the error
if(error)
{
//Do the callback with the provided error
return cb(error);
}
else
{
//Continue with the next item on the list
return each_async(index + 1);
}
});
}
} | [
"function",
"(",
"index",
")",
"{",
"//Check the index value",
"if",
"(",
"index",
">=",
"keys",
".",
"length",
")",
"{",
"//Do the callback and exit",
"return",
"cb",
"(",
"null",
")",
";",
"}",
"else",
"{",
"//Get the key",
"var",
"key",
"=",
"(",
"is_array",
")",
"?",
"index",
":",
"keys",
"[",
"index",
"]",
";",
"//Get the value",
"var",
"value",
"=",
"list",
"[",
"key",
"]",
";",
"//Call the provided method with the element of the array",
"return",
"fn",
".",
"call",
"(",
"null",
",",
"key",
",",
"value",
",",
"function",
"(",
"error",
")",
"{",
"//Check the error",
"if",
"(",
"error",
")",
"{",
"//Do the callback with the provided error",
"return",
"cb",
"(",
"error",
")",
";",
"}",
"else",
"{",
"//Continue with the next item on the list",
"return",
"each_async",
"(",
"index",
"+",
"1",
")",
";",
"}",
"}",
")",
";",
"}",
"}"
] | Call each element of the array | [
"Call",
"each",
"element",
"of",
"the",
"array"
] | f620180aa21fc8ece0f7b2c268cda335e9e28831 | https://github.com/jmjuanes/utily/blob/f620180aa21fc8ece0f7b2c268cda335e9e28831/lib/index.js#L71-L103 |
|
49,273 | jeswin-unmaintained/isotropy-koa-context-in-browser | lib/response.js | function(field, val){
if (2 == arguments.length) {
if (Array.isArray(val)) val = val.map(String);
else val = String(val);
this.res.setHeader(field, val);
} else {
for (var key in field) {
this.set(key, field[key]);
}
}
} | javascript | function(field, val){
if (2 == arguments.length) {
if (Array.isArray(val)) val = val.map(String);
else val = String(val);
this.res.setHeader(field, val);
} else {
for (var key in field) {
this.set(key, field[key]);
}
}
} | [
"function",
"(",
"field",
",",
"val",
")",
"{",
"if",
"(",
"2",
"==",
"arguments",
".",
"length",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"val",
")",
")",
"val",
"=",
"val",
".",
"map",
"(",
"String",
")",
";",
"else",
"val",
"=",
"String",
"(",
"val",
")",
";",
"this",
".",
"res",
".",
"setHeader",
"(",
"field",
",",
"val",
")",
";",
"}",
"else",
"{",
"for",
"(",
"var",
"key",
"in",
"field",
")",
"{",
"this",
".",
"set",
"(",
"key",
",",
"field",
"[",
"key",
"]",
")",
";",
"}",
"}",
"}"
] | Set header `field` to `val`, or pass
an object of header fields.
Examples:
this.set('Foo', ['bar', 'baz']);
this.set('Accept', 'application/json');
this.set({ Accept: 'text/plain', 'X-API-Key': 'tobi' });
@param {String|Object|Array} field
@param {String} val
@api public | [
"Set",
"header",
"field",
"to",
"val",
"or",
"pass",
"an",
"object",
"of",
"header",
"fields",
"."
] | 033a3ac0fd65ba6ac2b4ce715b3da54f873eed6f | https://github.com/jeswin-unmaintained/isotropy-koa-context-in-browser/blob/033a3ac0fd65ba6ac2b4ce715b3da54f873eed6f/lib/response.js#L334-L344 |
|
49,274 | jeswin-unmaintained/isotropy-koa-context-in-browser | lib/response.js | function(field, val){
var prev = this.get(field);
if (prev) {
val = Array.isArray(prev) ? prev.concat(val) : [prev].concat(val);
}
return this.set(field, val);
} | javascript | function(field, val){
var prev = this.get(field);
if (prev) {
val = Array.isArray(prev) ? prev.concat(val) : [prev].concat(val);
}
return this.set(field, val);
} | [
"function",
"(",
"field",
",",
"val",
")",
"{",
"var",
"prev",
"=",
"this",
".",
"get",
"(",
"field",
")",
";",
"if",
"(",
"prev",
")",
"{",
"val",
"=",
"Array",
".",
"isArray",
"(",
"prev",
")",
"?",
"prev",
".",
"concat",
"(",
"val",
")",
":",
"[",
"prev",
"]",
".",
"concat",
"(",
"val",
")",
";",
"}",
"return",
"this",
".",
"set",
"(",
"field",
",",
"val",
")",
";",
"}"
] | Append additional header `field` with value `val`.
Examples:
this.append('Link', ['<http://localhost/>', '<http://localhost:3000/>']);
this.append('Set-Cookie', 'foo=bar; Path=/; HttpOnly');
this.append('Warning', '199 Miscellaneous warning');
@param {String} field
@param {String|Array} val
@api public | [
"Append",
"additional",
"header",
"field",
"with",
"value",
"val",
"."
] | 033a3ac0fd65ba6ac2b4ce715b3da54f873eed6f | https://github.com/jeswin-unmaintained/isotropy-koa-context-in-browser/blob/033a3ac0fd65ba6ac2b4ce715b3da54f873eed6f/lib/response.js#L360-L368 |
|
49,275 | nbrownus/ppunit | lib/writers/ConsoleWriter.js | function (options) {
options = options || {}
this.isTTY = process.stdout.isTTY || false
this.useColors = options.useColors || this.isTTY
} | javascript | function (options) {
options = options || {}
this.isTTY = process.stdout.isTTY || false
this.useColors = options.useColors || this.isTTY
} | [
"function",
"(",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
"this",
".",
"isTTY",
"=",
"process",
".",
"stdout",
".",
"isTTY",
"||",
"false",
"this",
".",
"useColors",
"=",
"options",
".",
"useColors",
"||",
"this",
".",
"isTTY",
"}"
] | Handles writing output to stdout
@param {Object} options An object containing options pertaining to this writer
@param {Boolean} [options.useColors] Whether or not to use colors
default attempts to figure out if the tty supports colors
@constructor | [
"Handles",
"writing",
"output",
"to",
"stdout"
] | dcce602497d9548ce9085a8db115e65561dcc3de | https://github.com/nbrownus/ppunit/blob/dcce602497d9548ce9085a8db115e65561dcc3de/lib/writers/ConsoleWriter.js#L13-L17 |
|
49,276 | dreadcast/lowerdash | src/lowerdash.js | from | function from(arg){
if(!_.isArray(arg) && !_.isArguments(arg))
arg = [arg];
return _.toArray(arg);
} | javascript | function from(arg){
if(!_.isArray(arg) && !_.isArguments(arg))
arg = [arg];
return _.toArray(arg);
} | [
"function",
"from",
"(",
"arg",
")",
"{",
"if",
"(",
"!",
"_",
".",
"isArray",
"(",
"arg",
")",
"&&",
"!",
"_",
".",
"isArguments",
"(",
"arg",
")",
")",
"arg",
"=",
"[",
"arg",
"]",
";",
"return",
"_",
".",
"toArray",
"(",
"arg",
")",
";",
"}"
] | Creates an array containing passed argument or return argument if it is already an array.
@method from
@return {Array} Created or existing array | [
"Creates",
"an",
"array",
"containing",
"passed",
"argument",
"or",
"return",
"argument",
"if",
"it",
"is",
"already",
"an",
"array",
"."
] | 38c66969cea9ba2dbde9c761689df2fa1cb870e0 | https://github.com/dreadcast/lowerdash/blob/38c66969cea9ba2dbde9c761689df2fa1cb870e0/src/lowerdash.js#L23-L28 |
49,277 | dreadcast/lowerdash | src/lowerdash.js | joinLast | function joinLast(obj, glue, stick){
if(_.size(obj) == 1)
return obj[0];
var last = obj.pop();
return obj.join(glue) + stick + last;
} | javascript | function joinLast(obj, glue, stick){
if(_.size(obj) == 1)
return obj[0];
var last = obj.pop();
return obj.join(glue) + stick + last;
} | [
"function",
"joinLast",
"(",
"obj",
",",
"glue",
",",
"stick",
")",
"{",
"if",
"(",
"_",
".",
"size",
"(",
"obj",
")",
"==",
"1",
")",
"return",
"obj",
"[",
"0",
"]",
";",
"var",
"last",
"=",
"obj",
".",
"pop",
"(",
")",
";",
"return",
"obj",
".",
"join",
"(",
"glue",
")",
"+",
"stick",
"+",
"last",
";",
"}"
] | Joins items from an array with a different glue before last item
@method joinLast
@param {Array} obj Array to join
@param {String} glue Items delimiter
@param {String} stick Delimiter before last item
@return {String} Joined array | [
"Joins",
"items",
"from",
"an",
"array",
"with",
"a",
"different",
"glue",
"before",
"last",
"item"
] | 38c66969cea9ba2dbde9c761689df2fa1cb870e0 | https://github.com/dreadcast/lowerdash/blob/38c66969cea9ba2dbde9c761689df2fa1cb870e0/src/lowerdash.js#L48-L55 |
49,278 | dreadcast/lowerdash | src/lowerdash.js | getFromPath | function getFromPath(obj, path){
path = path.split('.');
for(var i = 0, l = path.length; i < l; i++){
if (hasOwnProperty.call(obj, path[i]))
obj = obj[path[i]];
else
return undefined;
}
return obj;
} | javascript | function getFromPath(obj, path){
path = path.split('.');
for(var i = 0, l = path.length; i < l; i++){
if (hasOwnProperty.call(obj, path[i]))
obj = obj[path[i]];
else
return undefined;
}
return obj;
} | [
"function",
"getFromPath",
"(",
"obj",
",",
"path",
")",
"{",
"path",
"=",
"path",
".",
"split",
"(",
"'.'",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"l",
"=",
"path",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"if",
"(",
"hasOwnProperty",
".",
"call",
"(",
"obj",
",",
"path",
"[",
"i",
"]",
")",
")",
"obj",
"=",
"obj",
"[",
"path",
"[",
"i",
"]",
"]",
";",
"else",
"return",
"undefined",
";",
"}",
"return",
"obj",
";",
"}"
] | Get property from object following provided path
@method getFromPath
@param {Object} obj Object to get property from
@param {String} path Path to property (Dot-delimited)
@return {Mixed} Property | [
"Get",
"property",
"from",
"object",
"following",
"provided",
"path"
] | 38c66969cea9ba2dbde9c761689df2fa1cb870e0 | https://github.com/dreadcast/lowerdash/blob/38c66969cea9ba2dbde9c761689df2fa1cb870e0/src/lowerdash.js#L63-L75 |
49,279 | dreadcast/lowerdash | src/lowerdash.js | setFromPath | function setFromPath(obj, path, value){
var parts = path.split('.');
for(var i = 0, l = parts.length; i < l; i++){
if(i < (l - 1) && !obj.hasOwnProperty(parts[i]))
obj[parts[i]] = {};
if(i == l - 1)
obj[parts[i]] = value;
else
obj = obj[parts[i]];
}
return obj;
} | javascript | function setFromPath(obj, path, value){
var parts = path.split('.');
for(var i = 0, l = parts.length; i < l; i++){
if(i < (l - 1) && !obj.hasOwnProperty(parts[i]))
obj[parts[i]] = {};
if(i == l - 1)
obj[parts[i]] = value;
else
obj = obj[parts[i]];
}
return obj;
} | [
"function",
"setFromPath",
"(",
"obj",
",",
"path",
",",
"value",
")",
"{",
"var",
"parts",
"=",
"path",
".",
"split",
"(",
"'.'",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"l",
"=",
"parts",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"if",
"(",
"i",
"<",
"(",
"l",
"-",
"1",
")",
"&&",
"!",
"obj",
".",
"hasOwnProperty",
"(",
"parts",
"[",
"i",
"]",
")",
")",
"obj",
"[",
"parts",
"[",
"i",
"]",
"]",
"=",
"{",
"}",
";",
"if",
"(",
"i",
"==",
"l",
"-",
"1",
")",
"obj",
"[",
"parts",
"[",
"i",
"]",
"]",
"=",
"value",
";",
"else",
"obj",
"=",
"obj",
"[",
"parts",
"[",
"i",
"]",
"]",
";",
"}",
"return",
"obj",
";",
"}"
] | Set property of object following provided path
@method setFromPath
@param {Object} obj Destination object
@param {String} path Path to property
@param {Mixed} value Property value
@return {Object} Object | [
"Set",
"property",
"of",
"object",
"following",
"provided",
"path"
] | 38c66969cea9ba2dbde9c761689df2fa1cb870e0 | https://github.com/dreadcast/lowerdash/blob/38c66969cea9ba2dbde9c761689df2fa1cb870e0/src/lowerdash.js#L85-L100 |
49,280 | dreadcast/lowerdash | src/lowerdash.js | eraseFromPath | function eraseFromPath(obj, path){
var parts = path.split('.'),
clone = obj;
for(var i = 0, l = parts.length; i < l; i++){
if (!obj.hasOwnProperty(parts[i])){
break;
} else if (i < l - 1){
obj = obj[parts[i]];
} else if(i == l - 1){
delete obj[parts[i]];
break;
}
}
return clone;
} | javascript | function eraseFromPath(obj, path){
var parts = path.split('.'),
clone = obj;
for(var i = 0, l = parts.length; i < l; i++){
if (!obj.hasOwnProperty(parts[i])){
break;
} else if (i < l - 1){
obj = obj[parts[i]];
} else if(i == l - 1){
delete obj[parts[i]];
break;
}
}
return clone;
} | [
"function",
"eraseFromPath",
"(",
"obj",
",",
"path",
")",
"{",
"var",
"parts",
"=",
"path",
".",
"split",
"(",
"'.'",
")",
",",
"clone",
"=",
"obj",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"l",
"=",
"parts",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"obj",
".",
"hasOwnProperty",
"(",
"parts",
"[",
"i",
"]",
")",
")",
"{",
"break",
";",
"}",
"else",
"if",
"(",
"i",
"<",
"l",
"-",
"1",
")",
"{",
"obj",
"=",
"obj",
"[",
"parts",
"[",
"i",
"]",
"]",
";",
"}",
"else",
"if",
"(",
"i",
"==",
"l",
"-",
"1",
")",
"{",
"delete",
"obj",
"[",
"parts",
"[",
"i",
"]",
"]",
";",
"break",
";",
"}",
"}",
"return",
"clone",
";",
"}"
] | Removes property of object following provided path
@method eraseFromPath
@param {Object} obj Object to remove property from
@param {String} path Path to property
@return {Object} Object | [
"Removes",
"property",
"of",
"object",
"following",
"provided",
"path"
] | 38c66969cea9ba2dbde9c761689df2fa1cb870e0 | https://github.com/dreadcast/lowerdash/blob/38c66969cea9ba2dbde9c761689df2fa1cb870e0/src/lowerdash.js#L109-L127 |
49,281 | dreadcast/lowerdash | src/lowerdash.js | keyOf | function keyOf(obj, value){
for(var key in obj)
if(Object.prototype.hasOwnProperty.call(obj, key) && obj[key] === value)
return key;
return null;
} | javascript | function keyOf(obj, value){
for(var key in obj)
if(Object.prototype.hasOwnProperty.call(obj, key) && obj[key] === value)
return key;
return null;
} | [
"function",
"keyOf",
"(",
"obj",
",",
"value",
")",
"{",
"for",
"(",
"var",
"key",
"in",
"obj",
")",
"if",
"(",
"Object",
".",
"prototype",
".",
"hasOwnProperty",
".",
"call",
"(",
"obj",
",",
"key",
")",
"&&",
"obj",
"[",
"key",
"]",
"===",
"value",
")",
"return",
"key",
";",
"return",
"null",
";",
"}"
] | Retrieve object's key paired to given property
@method keyOf
@param {Object} obj Object to get key from
@param {Mixed} value Value corresponding to key
@return {String} Key or null if no key was found | [
"Retrieve",
"object",
"s",
"key",
"paired",
"to",
"given",
"property"
] | 38c66969cea9ba2dbde9c761689df2fa1cb870e0 | https://github.com/dreadcast/lowerdash/blob/38c66969cea9ba2dbde9c761689df2fa1cb870e0/src/lowerdash.js#L136-L142 |
49,282 | dreadcast/lowerdash | src/lowerdash.js | isLaxEqual | function isLaxEqual(a, b){
if(_.isArray(a))
a = _.uniq(a.sort());
if(_.isArray(b))
b = _.uniq(b.sort());
return _.isEqual(a, b);
} | javascript | function isLaxEqual(a, b){
if(_.isArray(a))
a = _.uniq(a.sort());
if(_.isArray(b))
b = _.uniq(b.sort());
return _.isEqual(a, b);
} | [
"function",
"isLaxEqual",
"(",
"a",
",",
"b",
")",
"{",
"if",
"(",
"_",
".",
"isArray",
"(",
"a",
")",
")",
"a",
"=",
"_",
".",
"uniq",
"(",
"a",
".",
"sort",
"(",
")",
")",
";",
"if",
"(",
"_",
".",
"isArray",
"(",
"b",
")",
")",
"b",
"=",
"_",
".",
"uniq",
"(",
"b",
".",
"sort",
"(",
")",
")",
";",
"return",
"_",
".",
"isEqual",
"(",
"a",
",",
"b",
")",
";",
"}"
] | Lax isEqual, arrays are sorted and unique'd
@method isLaxEqual
@param {Mixed} a Value to compare
@param {Mixed} b Value to be compared
@return {Boolean} Lax equality | [
"Lax",
"isEqual",
"arrays",
"are",
"sorted",
"and",
"unique",
"d"
] | 38c66969cea9ba2dbde9c761689df2fa1cb870e0 | https://github.com/dreadcast/lowerdash/blob/38c66969cea9ba2dbde9c761689df2fa1cb870e0/src/lowerdash.js#L151-L159 |
49,283 | dreadcast/lowerdash | src/lowerdash.js | eachParallel | function eachParallel(obj, iterator, cb, max, bind){
if(!_.isFinite(max))
max = _.size(obj);
var stepsToGo = _.size(obj),
chunks = _.isIterable(obj) ? _.norris(obj, max) : _.chunk(obj, max);
_.eachAsync(chunks, function(chunk, chunkKey, chunkCursor){
var chunkIndex = 0;
_.each(chunk, function(item, key){
function cursor(){
stepsToGo--;
if(chunkIndex + 1 == max || stepsToGo == 0)
chunkCursor();
chunkIndex++;
};
iterator.call(bind, item, key, cursor, obj);
});
}, cb, bind);
return obj;
} | javascript | function eachParallel(obj, iterator, cb, max, bind){
if(!_.isFinite(max))
max = _.size(obj);
var stepsToGo = _.size(obj),
chunks = _.isIterable(obj) ? _.norris(obj, max) : _.chunk(obj, max);
_.eachAsync(chunks, function(chunk, chunkKey, chunkCursor){
var chunkIndex = 0;
_.each(chunk, function(item, key){
function cursor(){
stepsToGo--;
if(chunkIndex + 1 == max || stepsToGo == 0)
chunkCursor();
chunkIndex++;
};
iterator.call(bind, item, key, cursor, obj);
});
}, cb, bind);
return obj;
} | [
"function",
"eachParallel",
"(",
"obj",
",",
"iterator",
",",
"cb",
",",
"max",
",",
"bind",
")",
"{",
"if",
"(",
"!",
"_",
".",
"isFinite",
"(",
"max",
")",
")",
"max",
"=",
"_",
".",
"size",
"(",
"obj",
")",
";",
"var",
"stepsToGo",
"=",
"_",
".",
"size",
"(",
"obj",
")",
",",
"chunks",
"=",
"_",
".",
"isIterable",
"(",
"obj",
")",
"?",
"_",
".",
"norris",
"(",
"obj",
",",
"max",
")",
":",
"_",
".",
"chunk",
"(",
"obj",
",",
"max",
")",
";",
"_",
".",
"eachAsync",
"(",
"chunks",
",",
"function",
"(",
"chunk",
",",
"chunkKey",
",",
"chunkCursor",
")",
"{",
"var",
"chunkIndex",
"=",
"0",
";",
"_",
".",
"each",
"(",
"chunk",
",",
"function",
"(",
"item",
",",
"key",
")",
"{",
"function",
"cursor",
"(",
")",
"{",
"stepsToGo",
"--",
";",
"if",
"(",
"chunkIndex",
"+",
"1",
"==",
"max",
"||",
"stepsToGo",
"==",
"0",
")",
"chunkCursor",
"(",
")",
";",
"chunkIndex",
"++",
";",
"}",
";",
"iterator",
".",
"call",
"(",
"bind",
",",
"item",
",",
"key",
",",
"cursor",
",",
"obj",
")",
";",
"}",
")",
";",
"}",
",",
"cb",
",",
"bind",
")",
";",
"return",
"obj",
";",
"}"
] | Invoke passed iterator on each passed array entry
All iterations are concurrents
@method eachParallel
@param {Object} obj Object or array.
@param {Function} iterator Iterator, invoked on each obj entry.
Passed arguments are <code>item</code>, <code>index</code> or
<code>key</code> (if passed object is iterable),
<code>cursor</code> and passed <code>arr</code>.
@param {Function} [cb] Callback invoked when last iteration is done.
@param {Number} [max] Amount of concurrent tasks.
@param {Object} [bind] Object bound to iterator, default to passed <code>arr</code>. | [
"Invoke",
"passed",
"iterator",
"on",
"each",
"passed",
"array",
"entry",
"All",
"iterations",
"are",
"concurrents"
] | 38c66969cea9ba2dbde9c761689df2fa1cb870e0 | https://github.com/dreadcast/lowerdash/blob/38c66969cea9ba2dbde9c761689df2fa1cb870e0/src/lowerdash.js#L290-L315 |
49,284 | dreadcast/lowerdash | src/lowerdash.js | closest | function closest(obj, number){
if((current = obj.length) < 2)
return l - 1;
for(var current, previous = Math.abs(obj[--current] - number); current--;)
if(previous < (previous = Math.abs(obj[current] - number)))
break;
return obj[current + 1];
var closest = -1,
prev = Math.abs(obj[0] - number);
for (var i = 1; i < obj.length; i++){
var diff = Math.abs(obj[i] - number);
if (diff <= prev){
prev = diff;
closest = obj[i];
}
}
return closest;
} | javascript | function closest(obj, number){
if((current = obj.length) < 2)
return l - 1;
for(var current, previous = Math.abs(obj[--current] - number); current--;)
if(previous < (previous = Math.abs(obj[current] - number)))
break;
return obj[current + 1];
var closest = -1,
prev = Math.abs(obj[0] - number);
for (var i = 1; i < obj.length; i++){
var diff = Math.abs(obj[i] - number);
if (diff <= prev){
prev = diff;
closest = obj[i];
}
}
return closest;
} | [
"function",
"closest",
"(",
"obj",
",",
"number",
")",
"{",
"if",
"(",
"(",
"current",
"=",
"obj",
".",
"length",
")",
"<",
"2",
")",
"return",
"l",
"-",
"1",
";",
"for",
"(",
"var",
"current",
",",
"previous",
"=",
"Math",
".",
"abs",
"(",
"obj",
"[",
"--",
"current",
"]",
"-",
"number",
")",
";",
"current",
"--",
";",
")",
"if",
"(",
"previous",
"<",
"(",
"previous",
"=",
"Math",
".",
"abs",
"(",
"obj",
"[",
"current",
"]",
"-",
"number",
")",
")",
")",
"break",
";",
"return",
"obj",
"[",
"current",
"+",
"1",
"]",
";",
"var",
"closest",
"=",
"-",
"1",
",",
"prev",
"=",
"Math",
".",
"abs",
"(",
"obj",
"[",
"0",
"]",
"-",
"number",
")",
";",
"for",
"(",
"var",
"i",
"=",
"1",
";",
"i",
"<",
"obj",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"diff",
"=",
"Math",
".",
"abs",
"(",
"obj",
"[",
"i",
"]",
"-",
"number",
")",
";",
"if",
"(",
"diff",
"<=",
"prev",
")",
"{",
"prev",
"=",
"diff",
";",
"closest",
"=",
"obj",
"[",
"i",
"]",
";",
"}",
"}",
"return",
"closest",
";",
"}"
] | Find value closest to given number in an array of numbers
@method closest
@return {Number} Closest value | [
"Find",
"value",
"closest",
"to",
"given",
"number",
"in",
"an",
"array",
"of",
"numbers"
] | 38c66969cea9ba2dbde9c761689df2fa1cb870e0 | https://github.com/dreadcast/lowerdash/blob/38c66969cea9ba2dbde9c761689df2fa1cb870e0/src/lowerdash.js#L367-L390 |
49,285 | dreadcast/lowerdash | src/lowerdash.js | attempt | function attempt(fn){
try {
var args = _.from(arguments);
args.shift();
return fn.apply(this, args);
} catch(e){
return false;
}
} | javascript | function attempt(fn){
try {
var args = _.from(arguments);
args.shift();
return fn.apply(this, args);
} catch(e){
return false;
}
} | [
"function",
"attempt",
"(",
"fn",
")",
"{",
"try",
"{",
"var",
"args",
"=",
"_",
".",
"from",
"(",
"arguments",
")",
";",
"args",
".",
"shift",
"(",
")",
";",
"return",
"fn",
".",
"apply",
"(",
"this",
",",
"args",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"return",
"false",
";",
"}",
"}"
] | Attempts to execute function, return false if fails
@method attempt
@param {Function} fn Function to execute
@param {Mixed} arguments* Arguments to pass to function
@return {Mixed} Function result or false | [
"Attempts",
"to",
"execute",
"function",
"return",
"false",
"if",
"fails"
] | 38c66969cea9ba2dbde9c761689df2fa1cb870e0 | https://github.com/dreadcast/lowerdash/blob/38c66969cea9ba2dbde9c761689df2fa1cb870e0/src/lowerdash.js#L421-L430 |
49,286 | dreadcast/lowerdash | src/lowerdash.js | straitjacket | function straitjacket(fn, defaultValue){
return function(){
try {
var args = _.from(arguments);
return fn.apply(this, args);
} catch(e){
return defaultValue;
}
}
} | javascript | function straitjacket(fn, defaultValue){
return function(){
try {
var args = _.from(arguments);
return fn.apply(this, args);
} catch(e){
return defaultValue;
}
}
} | [
"function",
"straitjacket",
"(",
"fn",
",",
"defaultValue",
")",
"{",
"return",
"function",
"(",
")",
"{",
"try",
"{",
"var",
"args",
"=",
"_",
".",
"from",
"(",
"arguments",
")",
";",
"return",
"fn",
".",
"apply",
"(",
"this",
",",
"args",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"return",
"defaultValue",
";",
"}",
"}",
"}"
] | Return a wrapped function that will catch errors and return provided defaultValue or undefined
@method straitjacket
@param {Function} fn Function to catch errors from
@param {Mixed} [defaultValue] Returned value if invoking wrapped function fails
@return {Mixed} Function result or false | [
"Return",
"a",
"wrapped",
"function",
"that",
"will",
"catch",
"errors",
"and",
"return",
"provided",
"defaultValue",
"or",
"undefined"
] | 38c66969cea9ba2dbde9c761689df2fa1cb870e0 | https://github.com/dreadcast/lowerdash/blob/38c66969cea9ba2dbde9c761689df2fa1cb870e0/src/lowerdash.js#L439-L449 |
49,287 | linyngfly/omelo-protobuf | lib/client/protobuf.js | encodeArray | function encodeArray(array, proto, offset, buffer, protos){
let i = 0;
if(util.isSimpleType(proto.type)){
offset = writeBytes(buffer, offset, encodeTag(proto.type, proto.tag));
offset = writeBytes(buffer, offset, codec.encodeUInt32(array.length));
for(i = 0; i < array.length; i++){
offset = encodeProp(array[i], proto.type, offset, buffer);
}
}else{
for(i = 0; i < array.length; i++){
offset = writeBytes(buffer, offset, encodeTag(proto.type, proto.tag));
offset = encodeProp(array[i], proto.type, offset, buffer, protos);
}
}
return offset;
} | javascript | function encodeArray(array, proto, offset, buffer, protos){
let i = 0;
if(util.isSimpleType(proto.type)){
offset = writeBytes(buffer, offset, encodeTag(proto.type, proto.tag));
offset = writeBytes(buffer, offset, codec.encodeUInt32(array.length));
for(i = 0; i < array.length; i++){
offset = encodeProp(array[i], proto.type, offset, buffer);
}
}else{
for(i = 0; i < array.length; i++){
offset = writeBytes(buffer, offset, encodeTag(proto.type, proto.tag));
offset = encodeProp(array[i], proto.type, offset, buffer, protos);
}
}
return offset;
} | [
"function",
"encodeArray",
"(",
"array",
",",
"proto",
",",
"offset",
",",
"buffer",
",",
"protos",
")",
"{",
"let",
"i",
"=",
"0",
";",
"if",
"(",
"util",
".",
"isSimpleType",
"(",
"proto",
".",
"type",
")",
")",
"{",
"offset",
"=",
"writeBytes",
"(",
"buffer",
",",
"offset",
",",
"encodeTag",
"(",
"proto",
".",
"type",
",",
"proto",
".",
"tag",
")",
")",
";",
"offset",
"=",
"writeBytes",
"(",
"buffer",
",",
"offset",
",",
"codec",
".",
"encodeUInt32",
"(",
"array",
".",
"length",
")",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"array",
".",
"length",
";",
"i",
"++",
")",
"{",
"offset",
"=",
"encodeProp",
"(",
"array",
"[",
"i",
"]",
",",
"proto",
".",
"type",
",",
"offset",
",",
"buffer",
")",
";",
"}",
"}",
"else",
"{",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"array",
".",
"length",
";",
"i",
"++",
")",
"{",
"offset",
"=",
"writeBytes",
"(",
"buffer",
",",
"offset",
",",
"encodeTag",
"(",
"proto",
".",
"type",
",",
"proto",
".",
"tag",
")",
")",
";",
"offset",
"=",
"encodeProp",
"(",
"array",
"[",
"i",
"]",
",",
"proto",
".",
"type",
",",
"offset",
",",
"buffer",
",",
"protos",
")",
";",
"}",
"}",
"return",
"offset",
";",
"}"
] | Encode reapeated properties, simple msg and object are decode differented | [
"Encode",
"reapeated",
"properties",
"simple",
"msg",
"and",
"object",
"are",
"decode",
"differented"
] | 712e172fdcc7e92aa7d0f41a71e79882b302f451 | https://github.com/linyngfly/omelo-protobuf/blob/712e172fdcc7e92aa7d0f41a71e79882b302f451/lib/client/protobuf.js#L424-L441 |
49,288 | wordijp/flexi-require | lib/watch-additional.js | flush | function flush(done) {
if (checkWatchify(browserify)) {
var full_paths = mutils.toResolvePaths([].concat(options.files).concat(options.getFiles()));
// add require target files
mcached.collectRequirePaths(full_paths, function (collect_file_sources) {
var collect_full_paths = Object.keys(collect_file_sources);
// NOTE : keep wildcard path
watchFile(_.uniq(full_paths.concat(collect_full_paths)));
watched = true;
oncomplete();
});
} else {
watched = true;
}
done();
} | javascript | function flush(done) {
if (checkWatchify(browserify)) {
var full_paths = mutils.toResolvePaths([].concat(options.files).concat(options.getFiles()));
// add require target files
mcached.collectRequirePaths(full_paths, function (collect_file_sources) {
var collect_full_paths = Object.keys(collect_file_sources);
// NOTE : keep wildcard path
watchFile(_.uniq(full_paths.concat(collect_full_paths)));
watched = true;
oncomplete();
});
} else {
watched = true;
}
done();
} | [
"function",
"flush",
"(",
"done",
")",
"{",
"if",
"(",
"checkWatchify",
"(",
"browserify",
")",
")",
"{",
"var",
"full_paths",
"=",
"mutils",
".",
"toResolvePaths",
"(",
"[",
"]",
".",
"concat",
"(",
"options",
".",
"files",
")",
".",
"concat",
"(",
"options",
".",
"getFiles",
"(",
")",
")",
")",
";",
"// add require target files",
"mcached",
".",
"collectRequirePaths",
"(",
"full_paths",
",",
"function",
"(",
"collect_file_sources",
")",
"{",
"var",
"collect_full_paths",
"=",
"Object",
".",
"keys",
"(",
"collect_file_sources",
")",
";",
"// NOTE : keep wildcard path",
"watchFile",
"(",
"_",
".",
"uniq",
"(",
"full_paths",
".",
"concat",
"(",
"collect_full_paths",
")",
")",
")",
";",
"watched",
"=",
"true",
";",
"oncomplete",
"(",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"watched",
"=",
"true",
";",
"}",
"done",
"(",
")",
";",
"}"
] | no-op | [
"no",
"-",
"op"
] | f62a7141fd97f4a5b47c9808a5c4a3349aeccb43 | https://github.com/wordijp/flexi-require/blob/f62a7141fd97f4a5b47c9808a5c4a3349aeccb43/lib/watch-additional.js#L52-L69 |
49,289 | base/base-runner | index.js | RunnerContext | function RunnerContext(argv, config, env) {
argv.tasks = argv._.length ? argv._ : ['default'];
this.argv = argv;
this.config = config;
this.env = env;
this.json = loadConfig(this.argv.cwd, this.env);
this.pkg = loadPkg(this.argv.cwd, this.env);
this.pkgConfig = this.pkg[env.name] || {};
this.options = merge({}, this.pkgConfig.options, this.json.options);
} | javascript | function RunnerContext(argv, config, env) {
argv.tasks = argv._.length ? argv._ : ['default'];
this.argv = argv;
this.config = config;
this.env = env;
this.json = loadConfig(this.argv.cwd, this.env);
this.pkg = loadPkg(this.argv.cwd, this.env);
this.pkgConfig = this.pkg[env.name] || {};
this.options = merge({}, this.pkgConfig.options, this.json.options);
} | [
"function",
"RunnerContext",
"(",
"argv",
",",
"config",
",",
"env",
")",
"{",
"argv",
".",
"tasks",
"=",
"argv",
".",
"_",
".",
"length",
"?",
"argv",
".",
"_",
":",
"[",
"'default'",
"]",
";",
"this",
".",
"argv",
"=",
"argv",
";",
"this",
".",
"config",
"=",
"config",
";",
"this",
".",
"env",
"=",
"env",
";",
"this",
".",
"json",
"=",
"loadConfig",
"(",
"this",
".",
"argv",
".",
"cwd",
",",
"this",
".",
"env",
")",
";",
"this",
".",
"pkg",
"=",
"loadPkg",
"(",
"this",
".",
"argv",
".",
"cwd",
",",
"this",
".",
"env",
")",
";",
"this",
".",
"pkgConfig",
"=",
"this",
".",
"pkg",
"[",
"env",
".",
"name",
"]",
"||",
"{",
"}",
";",
"this",
".",
"options",
"=",
"merge",
"(",
"{",
"}",
",",
"this",
".",
"pkgConfig",
".",
"options",
",",
"this",
".",
"json",
".",
"options",
")",
";",
"}"
] | Create runner context | [
"Create",
"runner",
"context"
] | 07d5702771dfe5ced6d07b8a2c2927b9bc738a11 | https://github.com/base/base-runner/blob/07d5702771dfe5ced6d07b8a2c2927b9bc738a11/index.js#L177-L186 |
49,290 | base/base-runner | index.js | validateRunnerArgs | function validateRunnerArgs(Ctor, config, argv, cb) {
if (typeof cb !== 'function') {
throw new Error('expected a callback function');
}
if (argv == null || typeof argv !== 'object') {
return new Error('expected the third argument to be an options object');
}
if (config == null || typeof config !== 'object') {
return new Error('expected the second argument to be a liftoff config object');
}
if (typeof Ctor !== 'function' || typeof Ctor.namespace !== 'function') {
return new Error('expected the first argument to be a Base constructor');
}
} | javascript | function validateRunnerArgs(Ctor, config, argv, cb) {
if (typeof cb !== 'function') {
throw new Error('expected a callback function');
}
if (argv == null || typeof argv !== 'object') {
return new Error('expected the third argument to be an options object');
}
if (config == null || typeof config !== 'object') {
return new Error('expected the second argument to be a liftoff config object');
}
if (typeof Ctor !== 'function' || typeof Ctor.namespace !== 'function') {
return new Error('expected the first argument to be a Base constructor');
}
} | [
"function",
"validateRunnerArgs",
"(",
"Ctor",
",",
"config",
",",
"argv",
",",
"cb",
")",
"{",
"if",
"(",
"typeof",
"cb",
"!==",
"'function'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'expected a callback function'",
")",
";",
"}",
"if",
"(",
"argv",
"==",
"null",
"||",
"typeof",
"argv",
"!==",
"'object'",
")",
"{",
"return",
"new",
"Error",
"(",
"'expected the third argument to be an options object'",
")",
";",
"}",
"if",
"(",
"config",
"==",
"null",
"||",
"typeof",
"config",
"!==",
"'object'",
")",
"{",
"return",
"new",
"Error",
"(",
"'expected the second argument to be a liftoff config object'",
")",
";",
"}",
"if",
"(",
"typeof",
"Ctor",
"!==",
"'function'",
"||",
"typeof",
"Ctor",
".",
"namespace",
"!==",
"'function'",
")",
"{",
"return",
"new",
"Error",
"(",
"'expected the first argument to be a Base constructor'",
")",
";",
"}",
"}"
] | Handle invalid arguments | [
"Handle",
"invalid",
"arguments"
] | 07d5702771dfe5ced6d07b8a2c2927b9bc738a11 | https://github.com/base/base-runner/blob/07d5702771dfe5ced6d07b8a2c2927b9bc738a11/index.js#L213-L228 |
49,291 | christkv/vitesse | lib/compiler.js | function(err, stdout, stderr) {
if(err) return callback(err);
// Get the transformed source
var source = stdout;
// Compile the function
eval(source)
// Return the validation function
callback(null, {
validate: func
});
} | javascript | function(err, stdout, stderr) {
if(err) return callback(err);
// Get the transformed source
var source = stdout;
// Compile the function
eval(source)
// Return the validation function
callback(null, {
validate: func
});
} | [
"function",
"(",
"err",
",",
"stdout",
",",
"stderr",
")",
"{",
"if",
"(",
"err",
")",
"return",
"callback",
"(",
"err",
")",
";",
"// Get the transformed source",
"var",
"source",
"=",
"stdout",
";",
"// Compile the function",
"eval",
"(",
"source",
")",
"// Return the validation function",
"callback",
"(",
"null",
",",
"{",
"validate",
":",
"func",
"}",
")",
";",
"}"
] | Handle closure compiler result | [
"Handle",
"closure",
"compiler",
"result"
] | 6f40f7eaafa7f22644c4c6df80c0bf0590c502ba | https://github.com/christkv/vitesse/blob/6f40f7eaafa7f22644c4c6df80c0bf0590c502ba/lib/compiler.js#L192-L202 |
|
49,292 | alexpods/ClazzJS | src/components/meta/Property/Methods.js | function(object, methods, property) {
for (var i = 0, ii = methods.length; i < ii; ++i) {
this.addMethodToObject(methods[i], object, property);
}
} | javascript | function(object, methods, property) {
for (var i = 0, ii = methods.length; i < ii; ++i) {
this.addMethodToObject(methods[i], object, property);
}
} | [
"function",
"(",
"object",
",",
"methods",
",",
"property",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"ii",
"=",
"methods",
".",
"length",
";",
"i",
"<",
"ii",
";",
"++",
"i",
")",
"{",
"this",
".",
"addMethodToObject",
"(",
"methods",
"[",
"i",
"]",
",",
"object",
",",
"property",
")",
";",
"}",
"}"
] | Add common methods for property
@param {object} object Some object
@param {array} methods List of property methods
@param {string} property Property name
@this {metaProcessor} | [
"Add",
"common",
"methods",
"for",
"property"
] | 2f94496019669813c8246d48fcceb12a3e68a870 | https://github.com/alexpods/ClazzJS/blob/2f94496019669813c8246d48fcceb12a3e68a870/src/components/meta/Property/Methods.js#L16-L21 |
|
49,293 | alexpods/ClazzJS | src/components/meta/Property/Methods.js | function(name, object, property) {
var method = this.createMethod(name, property);
object[method.name] = method.body;
} | javascript | function(name, object, property) {
var method = this.createMethod(name, property);
object[method.name] = method.body;
} | [
"function",
"(",
"name",
",",
"object",
",",
"property",
")",
"{",
"var",
"method",
"=",
"this",
".",
"createMethod",
"(",
"name",
",",
"property",
")",
";",
"object",
"[",
"method",
".",
"name",
"]",
"=",
"method",
".",
"body",
";",
"}"
] | Add specified method to object
@param {string} name Object name
@param {object} object Object to which method will be added
@param {string} property Property name
@this {metaProcessor} | [
"Add",
"specified",
"method",
"to",
"object"
] | 2f94496019669813c8246d48fcceb12a3e68a870 | https://github.com/alexpods/ClazzJS/blob/2f94496019669813c8246d48fcceb12a3e68a870/src/components/meta/Property/Methods.js#L32-L35 |
|
49,294 | alexpods/ClazzJS | src/components/meta/Property/Methods.js | function(name, property) {
if (!(name in this._methods)) {
throw new Error('Method "' + name + '" does not exist!');
}
var method = this._methods[name](property);
if (_.isFunction(method)) {
method = {
name: this.getMethodName(property, name),
body: method
}
}
return method;
} | javascript | function(name, property) {
if (!(name in this._methods)) {
throw new Error('Method "' + name + '" does not exist!');
}
var method = this._methods[name](property);
if (_.isFunction(method)) {
method = {
name: this.getMethodName(property, name),
body: method
}
}
return method;
} | [
"function",
"(",
"name",
",",
"property",
")",
"{",
"if",
"(",
"!",
"(",
"name",
"in",
"this",
".",
"_methods",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Method \"'",
"+",
"name",
"+",
"'\" does not exist!'",
")",
";",
"}",
"var",
"method",
"=",
"this",
".",
"_methods",
"[",
"name",
"]",
"(",
"property",
")",
";",
"if",
"(",
"_",
".",
"isFunction",
"(",
"method",
")",
")",
"{",
"method",
"=",
"{",
"name",
":",
"this",
".",
"getMethodName",
"(",
"property",
",",
"name",
")",
",",
"body",
":",
"method",
"}",
"}",
"return",
"method",
";",
"}"
] | Creates method for specified property
@param {string} name Method name
@param {string} property Property name
@returns {function|object} Function or hash with 'name' and 'body' fields
@throws {Error} if method does not exist
@this {metaProcessor} | [
"Creates",
"method",
"for",
"specified",
"property"
] | 2f94496019669813c8246d48fcceb12a3e68a870 | https://github.com/alexpods/ClazzJS/blob/2f94496019669813c8246d48fcceb12a3e68a870/src/components/meta/Property/Methods.js#L49-L62 |
|
49,295 | alexpods/ClazzJS | src/components/meta/Property/Methods.js | function(property, method) {
var prefix = '';
property = property.replace(/^(_+)/g, function(str) {
prefix = str;
return '';
});
var methodName = 'is' === method && 0 === property.indexOf('is')
? property
: method + property[0].toUpperCase() + property.slice(1);
return prefix + methodName;
} | javascript | function(property, method) {
var prefix = '';
property = property.replace(/^(_+)/g, function(str) {
prefix = str;
return '';
});
var methodName = 'is' === method && 0 === property.indexOf('is')
? property
: method + property[0].toUpperCase() + property.slice(1);
return prefix + methodName;
} | [
"function",
"(",
"property",
",",
"method",
")",
"{",
"var",
"prefix",
"=",
"''",
";",
"property",
"=",
"property",
".",
"replace",
"(",
"/",
"^(_+)",
"/",
"g",
",",
"function",
"(",
"str",
")",
"{",
"prefix",
"=",
"str",
";",
"return",
"''",
";",
"}",
")",
";",
"var",
"methodName",
"=",
"'is'",
"===",
"method",
"&&",
"0",
"===",
"property",
".",
"indexOf",
"(",
"'is'",
")",
"?",
"property",
":",
"method",
"+",
"property",
"[",
"0",
"]",
".",
"toUpperCase",
"(",
")",
"+",
"property",
".",
"slice",
"(",
"1",
")",
";",
"return",
"prefix",
"+",
"methodName",
";",
"}"
] | Gets method name for specified property
Prepend property name with method name and capitalize first character of property name
@param {string} property Property name
@param {string} method Method name
@returns {string} Method name for specified property
@this {metaProcessor} | [
"Gets",
"method",
"name",
"for",
"specified",
"property",
"Prepend",
"property",
"name",
"with",
"method",
"name",
"and",
"capitalize",
"first",
"character",
"of",
"property",
"name"
] | 2f94496019669813c8246d48fcceb12a3e68a870 | https://github.com/alexpods/ClazzJS/blob/2f94496019669813c8246d48fcceb12a3e68a870/src/components/meta/Property/Methods.js#L75-L91 |
|
49,296 | alexpods/ClazzJS | src/components/meta/Property/Methods.js | function(property) {
return function(fields) {
fields = _.isString(fields) ? fields.split('.') : fields || [];
return this.__hasPropertyValue([property].concat(fields));
}
} | javascript | function(property) {
return function(fields) {
fields = _.isString(fields) ? fields.split('.') : fields || [];
return this.__hasPropertyValue([property].concat(fields));
}
} | [
"function",
"(",
"property",
")",
"{",
"return",
"function",
"(",
"fields",
")",
"{",
"fields",
"=",
"_",
".",
"isString",
"(",
"fields",
")",
"?",
"fields",
".",
"split",
"(",
"'.'",
")",
":",
"fields",
"||",
"[",
"]",
";",
"return",
"this",
".",
"__hasPropertyValue",
"(",
"[",
"property",
"]",
".",
"concat",
"(",
"fields",
")",
")",
";",
"}",
"}"
] | Check whether specified property with specified fields exist
@param property
@returns {Function} | [
"Check",
"whether",
"specified",
"property",
"with",
"specified",
"fields",
"exist"
] | 2f94496019669813c8246d48fcceb12a3e68a870 | https://github.com/alexpods/ClazzJS/blob/2f94496019669813c8246d48fcceb12a3e68a870/src/components/meta/Property/Methods.js#L202-L207 |
|
49,297 | tolokoban/ToloFrameWork | ker/mod/tfw.web-service.js | request | function request( url, args ) {
return new Promise( function( resolve, reject ) {
const xhr = new XMLHttpRequest();
xhr.open( "POST", url, true ); // true is for async.
xhr.onload = () => {
const DONE = 4;
if ( xhr.readyState !== DONE ) return;
console.info( "xhr.status=", xhr.status );
console.info( "xhr.responseText=", xhr.responseText );
if ( xhr.status === 200 ) resolve( xhr.responseText );
/*
else reject( {
id: exports.HTTP_ERROR,
msg: "(" + xhr.status + ") " + xhr.statusText,
status: xhr.status
} );
*/
};
xhr.onerror = function() {
reject( {
id: exports.HTTP_ERROR,
err: "HTTP_ERROR (" + xhr.status + ") " + xhr.statusText,
status: xhr.status
} );
};
const params = Object.keys( args )
.map( key => `${key}=${encodeURIComponent(args[key])}` )
.join( "&" );
xhr.setRequestHeader( "Content-type", "application/x-www-form-urlencoded" );
xhr.send( params );
} );
} | javascript | function request( url, args ) {
return new Promise( function( resolve, reject ) {
const xhr = new XMLHttpRequest();
xhr.open( "POST", url, true ); // true is for async.
xhr.onload = () => {
const DONE = 4;
if ( xhr.readyState !== DONE ) return;
console.info( "xhr.status=", xhr.status );
console.info( "xhr.responseText=", xhr.responseText );
if ( xhr.status === 200 ) resolve( xhr.responseText );
/*
else reject( {
id: exports.HTTP_ERROR,
msg: "(" + xhr.status + ") " + xhr.statusText,
status: xhr.status
} );
*/
};
xhr.onerror = function() {
reject( {
id: exports.HTTP_ERROR,
err: "HTTP_ERROR (" + xhr.status + ") " + xhr.statusText,
status: xhr.status
} );
};
const params = Object.keys( args )
.map( key => `${key}=${encodeURIComponent(args[key])}` )
.join( "&" );
xhr.setRequestHeader( "Content-type", "application/x-www-form-urlencoded" );
xhr.send( params );
} );
} | [
"function",
"request",
"(",
"url",
",",
"args",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"const",
"xhr",
"=",
"new",
"XMLHttpRequest",
"(",
")",
";",
"xhr",
".",
"open",
"(",
"\"POST\"",
",",
"url",
",",
"true",
")",
";",
"// true is for async.",
"xhr",
".",
"onload",
"=",
"(",
")",
"=>",
"{",
"const",
"DONE",
"=",
"4",
";",
"if",
"(",
"xhr",
".",
"readyState",
"!==",
"DONE",
")",
"return",
";",
"console",
".",
"info",
"(",
"\"xhr.status=\"",
",",
"xhr",
".",
"status",
")",
";",
"console",
".",
"info",
"(",
"\"xhr.responseText=\"",
",",
"xhr",
".",
"responseText",
")",
";",
"if",
"(",
"xhr",
".",
"status",
"===",
"200",
")",
"resolve",
"(",
"xhr",
".",
"responseText",
")",
";",
"/*\n else reject( {\n id: exports.HTTP_ERROR,\n msg: \"(\" + xhr.status + \") \" + xhr.statusText,\n status: xhr.status\n } );\n */",
"}",
";",
"xhr",
".",
"onerror",
"=",
"function",
"(",
")",
"{",
"reject",
"(",
"{",
"id",
":",
"exports",
".",
"HTTP_ERROR",
",",
"err",
":",
"\"HTTP_ERROR (\"",
"+",
"xhr",
".",
"status",
"+",
"\") \"",
"+",
"xhr",
".",
"statusText",
",",
"status",
":",
"xhr",
".",
"status",
"}",
")",
";",
"}",
";",
"const",
"params",
"=",
"Object",
".",
"keys",
"(",
"args",
")",
".",
"map",
"(",
"key",
"=>",
"`",
"${",
"key",
"}",
"${",
"encodeURIComponent",
"(",
"args",
"[",
"key",
"]",
")",
"}",
"`",
")",
".",
"join",
"(",
"\"&\"",
")",
";",
"xhr",
".",
"setRequestHeader",
"(",
"\"Content-type\"",
",",
"\"application/x-www-form-urlencoded\"",
")",
";",
"xhr",
".",
"send",
"(",
"params",
")",
";",
"}",
")",
";",
"}"
] | Request any web server with POST method and returns text.
@param {string} url - URL of the server to request. Can contain GET params.
@param {object} args - Arguments to send with the POST methos.
@returns {Promise} Resolves in the response as string. | [
"Request",
"any",
"web",
"server",
"with",
"POST",
"method",
"and",
"returns",
"text",
"."
] | 730845a833a9660ebfdb60ad027ebaab5ac871b6 | https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/ker/mod/tfw.web-service.js#L121-L153 |
49,298 | tolokoban/ToloFrameWork | ker/mod/tfw.web-service.js | loadJSON | function loadJSON( path ) {
return new Promise( function( resolve, reject ) {
var xhr = new XMLHttpRequest( {
mozSystem: true
} );
xhr.onload = function() {
var text = xhr.responseText;
try {
resolve( JSON.parse( text ) );
} catch ( ex ) {
reject( Error( "Bad JSON format for \"" + path + "\"!\n" + ex + "\n" + text ) );
}
};
xhr.onerror = function() {
reject( Error( "Unable to load file \"" + path + "\"!\n" + xhr.statusText ) );
};
xhr.open( "GET", path, true );
xhr.withCredentials = true; // Indispensable pour le CORS.
xhr.send();
} );
} | javascript | function loadJSON( path ) {
return new Promise( function( resolve, reject ) {
var xhr = new XMLHttpRequest( {
mozSystem: true
} );
xhr.onload = function() {
var text = xhr.responseText;
try {
resolve( JSON.parse( text ) );
} catch ( ex ) {
reject( Error( "Bad JSON format for \"" + path + "\"!\n" + ex + "\n" + text ) );
}
};
xhr.onerror = function() {
reject( Error( "Unable to load file \"" + path + "\"!\n" + xhr.statusText ) );
};
xhr.open( "GET", path, true );
xhr.withCredentials = true; // Indispensable pour le CORS.
xhr.send();
} );
} | [
"function",
"loadJSON",
"(",
"path",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"var",
"xhr",
"=",
"new",
"XMLHttpRequest",
"(",
"{",
"mozSystem",
":",
"true",
"}",
")",
";",
"xhr",
".",
"onload",
"=",
"function",
"(",
")",
"{",
"var",
"text",
"=",
"xhr",
".",
"responseText",
";",
"try",
"{",
"resolve",
"(",
"JSON",
".",
"parse",
"(",
"text",
")",
")",
";",
"}",
"catch",
"(",
"ex",
")",
"{",
"reject",
"(",
"Error",
"(",
"\"Bad JSON format for \\\"\"",
"+",
"path",
"+",
"\"\\\"!\\n\"",
"+",
"ex",
"+",
"\"\\n\"",
"+",
"text",
")",
")",
";",
"}",
"}",
";",
"xhr",
".",
"onerror",
"=",
"function",
"(",
")",
"{",
"reject",
"(",
"Error",
"(",
"\"Unable to load file \\\"\"",
"+",
"path",
"+",
"\"\\\"!\\n\"",
"+",
"xhr",
".",
"statusText",
")",
")",
";",
"}",
";",
"xhr",
".",
"open",
"(",
"\"GET\"",
",",
"path",
",",
"true",
")",
";",
"xhr",
".",
"withCredentials",
"=",
"true",
";",
"// Indispensable pour le CORS.",
"xhr",
".",
"send",
"(",
")",
";",
"}",
")",
";",
"}"
] | Load a JSON file and return a Promise.
@param {string} path Local path relative to the current HTML page. | [
"Load",
"a",
"JSON",
"file",
"and",
"return",
"a",
"Promise",
"."
] | 730845a833a9660ebfdb60ad027ebaab5ac871b6 | https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/ker/mod/tfw.web-service.js#L230-L250 |
49,299 | tolokoban/ToloFrameWork | ker/mod/tfw.web-service.js | logout | function logout() {
currentUser = null;
delete config.usr;
delete config.pwd;
Storage.local.set( "nigolotua", null );
exports.eventChange.fire();
return svc( "tfw.login.Logout" );
} | javascript | function logout() {
currentUser = null;
delete config.usr;
delete config.pwd;
Storage.local.set( "nigolotua", null );
exports.eventChange.fire();
return svc( "tfw.login.Logout" );
} | [
"function",
"logout",
"(",
")",
"{",
"currentUser",
"=",
"null",
";",
"delete",
"config",
".",
"usr",
";",
"delete",
"config",
".",
"pwd",
";",
"Storage",
".",
"local",
".",
"set",
"(",
"\"nigolotua\"",
",",
"null",
")",
";",
"exports",
".",
"eventChange",
".",
"fire",
"(",
")",
";",
"return",
"svc",
"(",
"\"tfw.login.Logout\"",
")",
";",
"}"
] | Disconnect current user.
@return {Promise} A _thenable_ object resolved as soon as the server answered. | [
"Disconnect",
"current",
"user",
"."
] | 730845a833a9660ebfdb60ad027ebaab5ac871b6 | https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/ker/mod/tfw.web-service.js#L265-L272 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.