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
sequence | docstring
stringlengths 4
11.8k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
53,700 | smartface/styler | src/styler.js | styler | function styler(...rawStyles) {
const stylesBundle = buildStyles.apply(null, rawStyles);
/**
* Styling composer
*
* @param {...string} classNames - Class names of desired styles
*/
return function stylingComposer(classNames, error) {
var parsedClassNames;
const styles = [];
const notFound = [];
if (classNames) {
const commands = stylesBundle.__runtime_commands__;
parsedClassNames = findClassNames(classNames).map((classNm) => classNm ? classNm.join("") : "");
parsedClassNames.forEach((className) => {
if(!stylesBundle[className]){
notFound.push(className);
return;
}
let style = stylesBundle[className];
let factories = commands[className]
? commandsManager.getRuntimeCommands()
: null;
if (factories) {
factories.forEach(factory => {
commands[className].forEach(command => {
let fn = factory(command.type);
fn && (style = merge(style, fn(command)));
});
});
}
styles.push(style);
});
} else {
const commands = stylesBundle.__runtime_commands__;
const factories = commandsManager.getRuntimeCommands();
styles.push(stylesBundle);
// if runtime commands and command factories exist
if (factories.length > 0 && commands) {
// run all runtime commands of the styles
Object.keys(commands).forEach(className => {
commands[className].forEach(command => {
factories.forEach(factory => {
let style = {};
const fn = factory(command.type);
fn && (style[className] = merge(stylesBundle[className], fn(command)));
styles.push(style);
});
});
});
}
}
const style = merge.apply(null, styles);
if(notFound.length > 0 && error){
error(notFound.join(", ")+" cannot be found.");
}
/**
* Styles mapper. If passed a function as the argument then return styles to the funtion or null then return style object.
*
* @param {?function=} [null] fn - Mapping callback function
*/
return function stylesComposer(fn = null) {
//create deepcopy of the style
if (fn) {
let result = {};
// parsedClassNames.forEach((className) => {
if(style){
Object.keys(style).forEach((key) => {
let value = style[key] !== null &&
style[key] instanceof Object
? merge(style[key])
: style[key];
result[key] = fn(classNames, key, value);
});
}
// });
return result;
};
return style;
};
};
} | javascript | function styler(...rawStyles) {
const stylesBundle = buildStyles.apply(null, rawStyles);
/**
* Styling composer
*
* @param {...string} classNames - Class names of desired styles
*/
return function stylingComposer(classNames, error) {
var parsedClassNames;
const styles = [];
const notFound = [];
if (classNames) {
const commands = stylesBundle.__runtime_commands__;
parsedClassNames = findClassNames(classNames).map((classNm) => classNm ? classNm.join("") : "");
parsedClassNames.forEach((className) => {
if(!stylesBundle[className]){
notFound.push(className);
return;
}
let style = stylesBundle[className];
let factories = commands[className]
? commandsManager.getRuntimeCommands()
: null;
if (factories) {
factories.forEach(factory => {
commands[className].forEach(command => {
let fn = factory(command.type);
fn && (style = merge(style, fn(command)));
});
});
}
styles.push(style);
});
} else {
const commands = stylesBundle.__runtime_commands__;
const factories = commandsManager.getRuntimeCommands();
styles.push(stylesBundle);
// if runtime commands and command factories exist
if (factories.length > 0 && commands) {
// run all runtime commands of the styles
Object.keys(commands).forEach(className => {
commands[className].forEach(command => {
factories.forEach(factory => {
let style = {};
const fn = factory(command.type);
fn && (style[className] = merge(stylesBundle[className], fn(command)));
styles.push(style);
});
});
});
}
}
const style = merge.apply(null, styles);
if(notFound.length > 0 && error){
error(notFound.join(", ")+" cannot be found.");
}
/**
* Styles mapper. If passed a function as the argument then return styles to the funtion or null then return style object.
*
* @param {?function=} [null] fn - Mapping callback function
*/
return function stylesComposer(fn = null) {
//create deepcopy of the style
if (fn) {
let result = {};
// parsedClassNames.forEach((className) => {
if(style){
Object.keys(style).forEach((key) => {
let value = style[key] !== null &&
style[key] instanceof Object
? merge(style[key])
: style[key];
result[key] = fn(classNames, key, value);
});
}
// });
return result;
};
return style;
};
};
} | [
"function",
"styler",
"(",
"...",
"rawStyles",
")",
"{",
"const",
"stylesBundle",
"=",
"buildStyles",
".",
"apply",
"(",
"null",
",",
"rawStyles",
")",
";",
"/**\n * Styling composer\n * \n * @param {...string} classNames - Class names of desired styles\n */",
"return",
"function",
"stylingComposer",
"(",
"classNames",
",",
"error",
")",
"{",
"var",
"parsedClassNames",
";",
"const",
"styles",
"=",
"[",
"]",
";",
"const",
"notFound",
"=",
"[",
"]",
";",
"if",
"(",
"classNames",
")",
"{",
"const",
"commands",
"=",
"stylesBundle",
".",
"__runtime_commands__",
";",
"parsedClassNames",
"=",
"findClassNames",
"(",
"classNames",
")",
".",
"map",
"(",
"(",
"classNm",
")",
"=>",
"classNm",
"?",
"classNm",
".",
"join",
"(",
"\"\"",
")",
":",
"\"\"",
")",
";",
"parsedClassNames",
".",
"forEach",
"(",
"(",
"className",
")",
"=>",
"{",
"if",
"(",
"!",
"stylesBundle",
"[",
"className",
"]",
")",
"{",
"notFound",
".",
"push",
"(",
"className",
")",
";",
"return",
";",
"}",
"let",
"style",
"=",
"stylesBundle",
"[",
"className",
"]",
";",
"let",
"factories",
"=",
"commands",
"[",
"className",
"]",
"?",
"commandsManager",
".",
"getRuntimeCommands",
"(",
")",
":",
"null",
";",
"if",
"(",
"factories",
")",
"{",
"factories",
".",
"forEach",
"(",
"factory",
"=>",
"{",
"commands",
"[",
"className",
"]",
".",
"forEach",
"(",
"command",
"=>",
"{",
"let",
"fn",
"=",
"factory",
"(",
"command",
".",
"type",
")",
";",
"fn",
"&&",
"(",
"style",
"=",
"merge",
"(",
"style",
",",
"fn",
"(",
"command",
")",
")",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
"styles",
".",
"push",
"(",
"style",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"const",
"commands",
"=",
"stylesBundle",
".",
"__runtime_commands__",
";",
"const",
"factories",
"=",
"commandsManager",
".",
"getRuntimeCommands",
"(",
")",
";",
"styles",
".",
"push",
"(",
"stylesBundle",
")",
";",
"// if runtime commands and command factories exist",
"if",
"(",
"factories",
".",
"length",
">",
"0",
"&&",
"commands",
")",
"{",
"// run all runtime commands of the styles",
"Object",
".",
"keys",
"(",
"commands",
")",
".",
"forEach",
"(",
"className",
"=>",
"{",
"commands",
"[",
"className",
"]",
".",
"forEach",
"(",
"command",
"=>",
"{",
"factories",
".",
"forEach",
"(",
"factory",
"=>",
"{",
"let",
"style",
"=",
"{",
"}",
";",
"const",
"fn",
"=",
"factory",
"(",
"command",
".",
"type",
")",
";",
"fn",
"&&",
"(",
"style",
"[",
"className",
"]",
"=",
"merge",
"(",
"stylesBundle",
"[",
"className",
"]",
",",
"fn",
"(",
"command",
")",
")",
")",
";",
"styles",
".",
"push",
"(",
"style",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
"}",
"const",
"style",
"=",
"merge",
".",
"apply",
"(",
"null",
",",
"styles",
")",
";",
"if",
"(",
"notFound",
".",
"length",
">",
"0",
"&&",
"error",
")",
"{",
"error",
"(",
"notFound",
".",
"join",
"(",
"\", \"",
")",
"+",
"\" cannot be found.\"",
")",
";",
"}",
"/**\n * Styles mapper. If passed a function as the argument then return styles to the funtion or null then return style object.\n * \n * @param {?function=} [null] fn - Mapping callback function\n */",
"return",
"function",
"stylesComposer",
"(",
"fn",
"=",
"null",
")",
"{",
"//create deepcopy of the style",
"if",
"(",
"fn",
")",
"{",
"let",
"result",
"=",
"{",
"}",
";",
"// parsedClassNames.forEach((className) => {",
"if",
"(",
"style",
")",
"{",
"Object",
".",
"keys",
"(",
"style",
")",
".",
"forEach",
"(",
"(",
"key",
")",
"=>",
"{",
"let",
"value",
"=",
"style",
"[",
"key",
"]",
"!==",
"null",
"&&",
"style",
"[",
"key",
"]",
"instanceof",
"Object",
"?",
"merge",
"(",
"style",
"[",
"key",
"]",
")",
":",
"style",
"[",
"key",
"]",
";",
"result",
"[",
"key",
"]",
"=",
"fn",
"(",
"classNames",
",",
"key",
",",
"value",
")",
";",
"}",
")",
";",
"}",
"// });",
"return",
"result",
";",
"}",
";",
"return",
"style",
";",
"}",
";",
"}",
";",
"}"
] | Styling Wrapper. In order to return desired styles. Makes styles flatted then merge all by classNames then pass merged styles to callback.
@example
const styler = require("@smartface/styler").styler or require("@smartface/styler/lib/styler");
const styles = {
".button"{
widht: "100px",
height: "30px",
".blue": {
color: "blue"
},
".red": {
color: "red"
}
}
}
const styling = styler(styles);
const blueButtonStyle = {};
const redButtonStyle = {};
styling(".button.blue")(function(className, key, value){
blueButtonStyle[key] = value;
});
// blueButtonStyle equals to {width: "100px", height: "20px", color: "blue"}
styling(".button.red")(function(className, key, value){
redButtonStyle[key] = value;
});
// redButtonStyle equals to {width: "100px", height: "20px", color: "red"}
@param {...Object.<string, (string | number | function | Object)>} - Style Objects
@returns {function} - Styling composer | [
"Styling",
"Wrapper",
".",
"In",
"order",
"to",
"return",
"desired",
"styles",
".",
"Makes",
"styles",
"flatted",
"then",
"merge",
"all",
"by",
"classNames",
"then",
"pass",
"merged",
"styles",
"to",
"callback",
"."
] | fca15ea571a73f0acffa2e6f44668993b127daf1 | https://github.com/smartface/styler/blob/fca15ea571a73f0acffa2e6f44668993b127daf1/src/styler.js#L49-L147 |
53,701 | chrishayesmu/DubBotBase | src/utils.js | checkHasValue | function checkHasValue(value, message) {
checkNotEmpty(message, "No error message passed to checkHasValue");
if (value === null || typeof value === "undefined") {
throw new Error(message);
}
} | javascript | function checkHasValue(value, message) {
checkNotEmpty(message, "No error message passed to checkHasValue");
if (value === null || typeof value === "undefined") {
throw new Error(message);
}
} | [
"function",
"checkHasValue",
"(",
"value",
",",
"message",
")",
"{",
"checkNotEmpty",
"(",
"message",
",",
"\"No error message passed to checkHasValue\"",
")",
";",
"if",
"(",
"value",
"===",
"null",
"||",
"typeof",
"value",
"===",
"\"undefined\"",
")",
"{",
"throw",
"new",
"Error",
"(",
"message",
")",
";",
"}",
"}"
] | Ensures that the value passed in is not null or undefined.
If it is, throws an error with the message provided.
@param {mixed} value - Anything which should not be null or undefined
@param {string} message - A message to throw in an Error if no value is present | [
"Ensures",
"that",
"the",
"value",
"passed",
"in",
"is",
"not",
"null",
"or",
"undefined",
".",
"If",
"it",
"is",
"throws",
"an",
"error",
"with",
"the",
"message",
"provided",
"."
] | 0e4b5e65531c23293d22ac766850c802b1266e48 | https://github.com/chrishayesmu/DubBotBase/blob/0e4b5e65531c23293d22ac766850c802b1266e48/src/utils.js#L35-L41 |
53,702 | chrishayesmu/DubBotBase | src/utils.js | checkNotEmpty | function checkNotEmpty(string, message) {
if (!message || !message.trim()) {
throw new Error("No error message passed to checkNotEmpty");
}
if (!string || !string.trim()) {
throw new Error(message);
}
} | javascript | function checkNotEmpty(string, message) {
if (!message || !message.trim()) {
throw new Error("No error message passed to checkNotEmpty");
}
if (!string || !string.trim()) {
throw new Error(message);
}
} | [
"function",
"checkNotEmpty",
"(",
"string",
",",
"message",
")",
"{",
"if",
"(",
"!",
"message",
"||",
"!",
"message",
".",
"trim",
"(",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"No error message passed to checkNotEmpty\"",
")",
";",
"}",
"if",
"(",
"!",
"string",
"||",
"!",
"string",
".",
"trim",
"(",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"message",
")",
";",
"}",
"}"
] | Checks that the string passed in is not null, empty or entirely whitespace.
If this is not the case, throws an error with the message provided.
@param {string} string - The string to check
@param {string} message - A message to throw in an Error if the string is empty | [
"Checks",
"that",
"the",
"string",
"passed",
"in",
"is",
"not",
"null",
"empty",
"or",
"entirely",
"whitespace",
".",
"If",
"this",
"is",
"not",
"the",
"case",
"throws",
"an",
"error",
"with",
"the",
"message",
"provided",
"."
] | 0e4b5e65531c23293d22ac766850c802b1266e48 | https://github.com/chrishayesmu/DubBotBase/blob/0e4b5e65531c23293d22ac766850c802b1266e48/src/utils.js#L50-L58 |
53,703 | chrishayesmu/DubBotBase | src/utils.js | checkValueIsInObject | function checkValueIsInObject(value, object, message) {
checkNotEmpty(message, "No error message passed to checkValueIsInObject");
var key = findValueInObject(value, object);
if (typeof key === "undefined") {
// Make sure the value's actually missing and it's not hidden behind undefined
if (!(undefined in object && deepEquals(value, object[undefined]))) {
throw new Error(message);
}
}
} | javascript | function checkValueIsInObject(value, object, message) {
checkNotEmpty(message, "No error message passed to checkValueIsInObject");
var key = findValueInObject(value, object);
if (typeof key === "undefined") {
// Make sure the value's actually missing and it's not hidden behind undefined
if (!(undefined in object && deepEquals(value, object[undefined]))) {
throw new Error(message);
}
}
} | [
"function",
"checkValueIsInObject",
"(",
"value",
",",
"object",
",",
"message",
")",
"{",
"checkNotEmpty",
"(",
"message",
",",
"\"No error message passed to checkValueIsInObject\"",
")",
";",
"var",
"key",
"=",
"findValueInObject",
"(",
"value",
",",
"object",
")",
";",
"if",
"(",
"typeof",
"key",
"===",
"\"undefined\"",
")",
"{",
"// Make sure the value's actually missing and it's not hidden behind undefined",
"if",
"(",
"!",
"(",
"undefined",
"in",
"object",
"&&",
"deepEquals",
"(",
"value",
",",
"object",
"[",
"undefined",
"]",
")",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"message",
")",
";",
"}",
"}",
"}"
] | Checks that the value provided exists under one of the top-level
keys in the object provided. If it does not, an error is thrown
containing the message given.
@param {mixed} value - A value to search for
@param {object} object - An object to search in
@param {string} message - A message to throw in an Error if the string is empty | [
"Checks",
"that",
"the",
"value",
"provided",
"exists",
"under",
"one",
"of",
"the",
"top",
"-",
"level",
"keys",
"in",
"the",
"object",
"provided",
".",
"If",
"it",
"does",
"not",
"an",
"error",
"is",
"thrown",
"containing",
"the",
"message",
"given",
"."
] | 0e4b5e65531c23293d22ac766850c802b1266e48 | https://github.com/chrishayesmu/DubBotBase/blob/0e4b5e65531c23293d22ac766850c802b1266e48/src/utils.js#L69-L80 |
53,704 | chrishayesmu/DubBotBase | src/utils.js | deepEquals | function deepEquals(obj1, obj2) {
if (typeof obj1 !== typeof obj2) {
return false;
}
// NaN check
if (obj1 !== obj1) {
return obj2 !== obj2;
}
// Non-object types will compare correctly with ===
if (typeof obj1 !== "object") {
return obj1 === obj2;
}
if (!_checkKeysFromFirstAreInSecond(obj1, obj2)) {
return false;
}
if (!_checkKeysFromFirstAreInSecond(obj2, obj1)) {
return false;
}
return true;
} | javascript | function deepEquals(obj1, obj2) {
if (typeof obj1 !== typeof obj2) {
return false;
}
// NaN check
if (obj1 !== obj1) {
return obj2 !== obj2;
}
// Non-object types will compare correctly with ===
if (typeof obj1 !== "object") {
return obj1 === obj2;
}
if (!_checkKeysFromFirstAreInSecond(obj1, obj2)) {
return false;
}
if (!_checkKeysFromFirstAreInSecond(obj2, obj1)) {
return false;
}
return true;
} | [
"function",
"deepEquals",
"(",
"obj1",
",",
"obj2",
")",
"{",
"if",
"(",
"typeof",
"obj1",
"!==",
"typeof",
"obj2",
")",
"{",
"return",
"false",
";",
"}",
"// NaN check",
"if",
"(",
"obj1",
"!==",
"obj1",
")",
"{",
"return",
"obj2",
"!==",
"obj2",
";",
"}",
"// Non-object types will compare correctly with ===",
"if",
"(",
"typeof",
"obj1",
"!==",
"\"object\"",
")",
"{",
"return",
"obj1",
"===",
"obj2",
";",
"}",
"if",
"(",
"!",
"_checkKeysFromFirstAreInSecond",
"(",
"obj1",
",",
"obj2",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"_checkKeysFromFirstAreInSecond",
"(",
"obj2",
",",
"obj1",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Performs a deep check to see if the two values provided are equal. For
non-object types, this refers to simple equality; for object types, the
two objects must contain all of the same keys and have the same values behind
all of those keys.
THIS METHOD DOES NOT CHECK FOR CYCLES IN THE OBJECTS PROVIDED. Don't try to
use it with any objects that may have cycles or you'll likely find your thread
frozen forever.
@param {object} obj1 - The first object to check
@param {object} obj2 - The second object to check
@returns {boolean} True if the two values are equal and all of the values contained in them are also equal | [
"Performs",
"a",
"deep",
"check",
"to",
"see",
"if",
"the",
"two",
"values",
"provided",
"are",
"equal",
".",
"For",
"non",
"-",
"object",
"types",
"this",
"refers",
"to",
"simple",
"equality",
";",
"for",
"object",
"types",
"the",
"two",
"objects",
"must",
"contain",
"all",
"of",
"the",
"same",
"keys",
"and",
"have",
"the",
"same",
"values",
"behind",
"all",
"of",
"those",
"keys",
"."
] | 0e4b5e65531c23293d22ac766850c802b1266e48 | https://github.com/chrishayesmu/DubBotBase/blob/0e4b5e65531c23293d22ac766850c802b1266e48/src/utils.js#L96-L120 |
53,705 | chrishayesmu/DubBotBase | src/utils.js | findValueInObject | function findValueInObject(value, object) {
checkHasType(object, "object", "Non-object value provided as second argument to findValueInObject");
checkHasValue(object, "Invalid null object provided as second argument to findValueInObject");
for (var key in object) {
var objValue = object[key];
if (deepEquals(value, objValue)) {
return key;
}
}
return; // explicit return of undefined
} | javascript | function findValueInObject(value, object) {
checkHasType(object, "object", "Non-object value provided as second argument to findValueInObject");
checkHasValue(object, "Invalid null object provided as second argument to findValueInObject");
for (var key in object) {
var objValue = object[key];
if (deepEquals(value, objValue)) {
return key;
}
}
return; // explicit return of undefined
} | [
"function",
"findValueInObject",
"(",
"value",
",",
"object",
")",
"{",
"checkHasType",
"(",
"object",
",",
"\"object\"",
",",
"\"Non-object value provided as second argument to findValueInObject\"",
")",
";",
"checkHasValue",
"(",
"object",
",",
"\"Invalid null object provided as second argument to findValueInObject\"",
")",
";",
"for",
"(",
"var",
"key",
"in",
"object",
")",
"{",
"var",
"objValue",
"=",
"object",
"[",
"key",
"]",
";",
"if",
"(",
"deepEquals",
"(",
"value",
",",
"objValue",
")",
")",
"{",
"return",
"key",
";",
"}",
"}",
"return",
";",
"// explicit return of undefined",
"}"
] | Locates the value provided under the first level of keys in the given object.
Since this function uses undefined as a return value when the provided value
is not found, it is not possible to directly search for anything where the key
is actually undefined. Anyone interested in this functionality can easily wrap
this method to check if undefined is a key in their object.
@param {mixed} value - A value to search for
@param {object} object - An object to search in
@returns {mixed} The key where the object was found, or undefined if it was not found | [
"Locates",
"the",
"value",
"provided",
"under",
"the",
"first",
"level",
"of",
"keys",
"in",
"the",
"given",
"object",
".",
"Since",
"this",
"function",
"uses",
"undefined",
"as",
"a",
"return",
"value",
"when",
"the",
"provided",
"value",
"is",
"not",
"found",
"it",
"is",
"not",
"possible",
"to",
"directly",
"search",
"for",
"anything",
"where",
"the",
"key",
"is",
"actually",
"undefined",
".",
"Anyone",
"interested",
"in",
"this",
"functionality",
"can",
"easily",
"wrap",
"this",
"method",
"to",
"check",
"if",
"undefined",
"is",
"a",
"key",
"in",
"their",
"object",
"."
] | 0e4b5e65531c23293d22ac766850c802b1266e48 | https://github.com/chrishayesmu/DubBotBase/blob/0e4b5e65531c23293d22ac766850c802b1266e48/src/utils.js#L133-L146 |
53,706 | chrishayesmu/DubBotBase | src/utils.js | getAllFilePathsUnderDirectory | function getAllFilePathsUnderDirectory(directory) {
// TODO: make this run in parallel, async
var filesInBaseDir = fs.readdirSync(directory);
var allFiles = [];
if (!filesInBaseDir) {
return allFiles;
}
for (var i = 0; i < filesInBaseDir.length; i++) {
var filePath = path.resolve(directory, filesInBaseDir[i]);
var fileStats = fs.statSync(filePath);
if (fileStats.isDirectory()) {
allFiles = allFiles.concat(getAllFilePathsUnderDirectory(filePath));
}
else if (fileStats.isFile()) {
allFiles.push(filePath);
}
}
return allFiles;
} | javascript | function getAllFilePathsUnderDirectory(directory) {
// TODO: make this run in parallel, async
var filesInBaseDir = fs.readdirSync(directory);
var allFiles = [];
if (!filesInBaseDir) {
return allFiles;
}
for (var i = 0; i < filesInBaseDir.length; i++) {
var filePath = path.resolve(directory, filesInBaseDir[i]);
var fileStats = fs.statSync(filePath);
if (fileStats.isDirectory()) {
allFiles = allFiles.concat(getAllFilePathsUnderDirectory(filePath));
}
else if (fileStats.isFile()) {
allFiles.push(filePath);
}
}
return allFiles;
} | [
"function",
"getAllFilePathsUnderDirectory",
"(",
"directory",
")",
"{",
"// TODO: make this run in parallel, async",
"var",
"filesInBaseDir",
"=",
"fs",
".",
"readdirSync",
"(",
"directory",
")",
";",
"var",
"allFiles",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"filesInBaseDir",
")",
"{",
"return",
"allFiles",
";",
"}",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"filesInBaseDir",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"filePath",
"=",
"path",
".",
"resolve",
"(",
"directory",
",",
"filesInBaseDir",
"[",
"i",
"]",
")",
";",
"var",
"fileStats",
"=",
"fs",
".",
"statSync",
"(",
"filePath",
")",
";",
"if",
"(",
"fileStats",
".",
"isDirectory",
"(",
")",
")",
"{",
"allFiles",
"=",
"allFiles",
".",
"concat",
"(",
"getAllFilePathsUnderDirectory",
"(",
"filePath",
")",
")",
";",
"}",
"else",
"if",
"(",
"fileStats",
".",
"isFile",
"(",
")",
")",
"{",
"allFiles",
".",
"push",
"(",
"filePath",
")",
";",
"}",
"}",
"return",
"allFiles",
";",
"}"
] | Retrieves all of the file paths which can be found in the base directory
provided. The method recurses through all subdirectories within the base
directory. Only file paths are returned; directories, symbolic links, etc,
are not included.
@param {string} directory - The path (relative or absolute) to the base directory to look in
@returns {array} An array of strings which are all of the files found under the base directory | [
"Retrieves",
"all",
"of",
"the",
"file",
"paths",
"which",
"can",
"be",
"found",
"in",
"the",
"base",
"directory",
"provided",
".",
"The",
"method",
"recurses",
"through",
"all",
"subdirectories",
"within",
"the",
"base",
"directory",
".",
"Only",
"file",
"paths",
"are",
"returned",
";",
"directories",
"symbolic",
"links",
"etc",
"are",
"not",
"included",
"."
] | 0e4b5e65531c23293d22ac766850c802b1266e48 | https://github.com/chrishayesmu/DubBotBase/blob/0e4b5e65531c23293d22ac766850c802b1266e48/src/utils.js#L157-L180 |
53,707 | chrishayesmu/DubBotBase | src/utils.js | _checkKeysFromFirstAreInSecond | function _checkKeysFromFirstAreInSecond(first, second) {
for (var key in first) {
if (!(key in second)) {
return false;
}
var value1 = first[key];
var value2 = second[key];
if (!deepEquals(value1, value2)) {
return false;
}
}
return true;
} | javascript | function _checkKeysFromFirstAreInSecond(first, second) {
for (var key in first) {
if (!(key in second)) {
return false;
}
var value1 = first[key];
var value2 = second[key];
if (!deepEquals(value1, value2)) {
return false;
}
}
return true;
} | [
"function",
"_checkKeysFromFirstAreInSecond",
"(",
"first",
",",
"second",
")",
"{",
"for",
"(",
"var",
"key",
"in",
"first",
")",
"{",
"if",
"(",
"!",
"(",
"key",
"in",
"second",
")",
")",
"{",
"return",
"false",
";",
"}",
"var",
"value1",
"=",
"first",
"[",
"key",
"]",
";",
"var",
"value2",
"=",
"second",
"[",
"key",
"]",
";",
"if",
"(",
"!",
"deepEquals",
"(",
"value1",
",",
"value2",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Checks that the keys which are in the first object are also in the second object,
and that they have the same value in both places.
@param {object} first - The first object to check
@param {object} second - The second object to check
@returns {boolean} True if all of the keys from the first are present and equal in the second | [
"Checks",
"that",
"the",
"keys",
"which",
"are",
"in",
"the",
"first",
"object",
"are",
"also",
"in",
"the",
"second",
"object",
"and",
"that",
"they",
"have",
"the",
"same",
"value",
"in",
"both",
"places",
"."
] | 0e4b5e65531c23293d22ac766850c802b1266e48 | https://github.com/chrishayesmu/DubBotBase/blob/0e4b5e65531c23293d22ac766850c802b1266e48/src/utils.js#L210-L225 |
53,708 | Val-istar-Guo/koa-ajax-params | src/index.js | getBody | function getBody(req) {
return new Promise((resolve, reject) => {
let data = '';
req
.on('data', (chunk) => {
data += chunk;
})
.on('end', () => {
resolve(data);
})
.on('error', reject);
});
} | javascript | function getBody(req) {
return new Promise((resolve, reject) => {
let data = '';
req
.on('data', (chunk) => {
data += chunk;
})
.on('end', () => {
resolve(data);
})
.on('error', reject);
});
} | [
"function",
"getBody",
"(",
"req",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"let",
"data",
"=",
"''",
";",
"req",
".",
"on",
"(",
"'data'",
",",
"(",
"chunk",
")",
"=>",
"{",
"data",
"+=",
"chunk",
";",
"}",
")",
".",
"on",
"(",
"'end'",
",",
"(",
")",
"=>",
"{",
"resolve",
"(",
"data",
")",
";",
"}",
")",
".",
"on",
"(",
"'error'",
",",
"reject",
")",
";",
"}",
")",
";",
"}"
] | import querystring from 'querystring'; | [
"import",
"querystring",
"from",
"querystring",
";"
] | 2f51b918421709479469f1e8908917ede25eb306 | https://github.com/Val-istar-Guo/koa-ajax-params/blob/2f51b918421709479469f1e8908917ede25eb306/src/index.js#L4-L16 |
53,709 | CleverStack/clever-accounts | controllers/AccountController.js | function(req, res, next) {
var accData = req.user.Account
, newData = {
name: req.body.name || accData.name,
logo: req.body.logo || accData.logo,
info: req.body.info || accData.info,
email: req.body.email || accData.email,
themeColor: req.body.themeColor || accData.themeColor
};
req.body = newData;
next();
} | javascript | function(req, res, next) {
var accData = req.user.Account
, newData = {
name: req.body.name || accData.name,
logo: req.body.logo || accData.logo,
info: req.body.info || accData.info,
email: req.body.email || accData.email,
themeColor: req.body.themeColor || accData.themeColor
};
req.body = newData;
next();
} | [
"function",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"var",
"accData",
"=",
"req",
".",
"user",
".",
"Account",
",",
"newData",
"=",
"{",
"name",
":",
"req",
".",
"body",
".",
"name",
"||",
"accData",
".",
"name",
",",
"logo",
":",
"req",
".",
"body",
".",
"logo",
"||",
"accData",
".",
"logo",
",",
"info",
":",
"req",
".",
"body",
".",
"info",
"||",
"accData",
".",
"info",
",",
"email",
":",
"req",
".",
"body",
".",
"email",
"||",
"accData",
".",
"email",
",",
"themeColor",
":",
"req",
".",
"body",
".",
"themeColor",
"||",
"accData",
".",
"themeColor",
"}",
";",
"req",
".",
"body",
"=",
"newData",
";",
"next",
"(",
")",
";",
"}"
] | Middleware helper function to format data in POST or PUT requests
@param {Request} req The Request Object
@param {Response} res The response object
@param {Function} next Continue past this middleware
@return {void} | [
"Middleware",
"helper",
"function",
"to",
"format",
"data",
"in",
"POST",
"or",
"PUT",
"requests"
] | d9e136eef41ebd92884bc13d017ba8f5f66e5c67 | https://github.com/CleverStack/clever-accounts/blob/d9e136eef41ebd92884bc13d017ba8f5f66e5c67/controllers/AccountController.js#L36-L48 |
|
53,710 | CleverStack/clever-accounts | controllers/AccountController.js | function(req, res, next){
var subdomain = req.body.subdomain;
if (!subdomain) {
return res.json(400, 'Company subdomain is mandatory!');
}
AccountService
.find({
where: {
subdomain: subdomain
}
})
.then(function(result){
if(result.length){
return res.json(403, 'This URL "' + subdomain + '" is already taken');
}
next();
})
.catch(function(err){
return res.json(500, 'There was an error: ' + err);
});
} | javascript | function(req, res, next){
var subdomain = req.body.subdomain;
if (!subdomain) {
return res.json(400, 'Company subdomain is mandatory!');
}
AccountService
.find({
where: {
subdomain: subdomain
}
})
.then(function(result){
if(result.length){
return res.json(403, 'This URL "' + subdomain + '" is already taken');
}
next();
})
.catch(function(err){
return res.json(500, 'There was an error: ' + err);
});
} | [
"function",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"var",
"subdomain",
"=",
"req",
".",
"body",
".",
"subdomain",
";",
"if",
"(",
"!",
"subdomain",
")",
"{",
"return",
"res",
".",
"json",
"(",
"400",
",",
"'Company subdomain is mandatory!'",
")",
";",
"}",
"AccountService",
".",
"find",
"(",
"{",
"where",
":",
"{",
"subdomain",
":",
"subdomain",
"}",
"}",
")",
".",
"then",
"(",
"function",
"(",
"result",
")",
"{",
"if",
"(",
"result",
".",
"length",
")",
"{",
"return",
"res",
".",
"json",
"(",
"403",
",",
"'This URL \"'",
"+",
"subdomain",
"+",
"'\" is already taken'",
")",
";",
"}",
"next",
"(",
")",
";",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"err",
")",
"{",
"return",
"res",
".",
"json",
"(",
"500",
",",
"'There was an error: '",
"+",
"err",
")",
";",
"}",
")",
";",
"}"
] | Middleware helper function for requiring a unique subDomain for a given POST request
@param {Request} req The Request Object
@param {Response} res The response object
@param {Function} next Continue past this middleware
@return {void} | [
"Middleware",
"helper",
"function",
"for",
"requiring",
"a",
"unique",
"subDomain",
"for",
"a",
"given",
"POST",
"request"
] | d9e136eef41ebd92884bc13d017ba8f5f66e5c67 | https://github.com/CleverStack/clever-accounts/blob/d9e136eef41ebd92884bc13d017ba8f5f66e5c67/controllers/AccountController.js#L58-L80 |
|
53,711 | liymax/pddux | lib/index.js | finalize | function finalize(base, path, patches, inversePatches) {
if (isProxy(base)) {
var state = base[PROXY_STATE];
if (state.modified === true) {
if (state.finalized === true) return state.copy;
state.finalized = true;
var result = finalizeObject(useProxies ? state.copy : state.copy = shallowCopy(base), state, path, patches, inversePatches);
generatePatches(state, path, patches, inversePatches, state.base, result);
return result;
} else {
return state.base;
}
}
finalizeNonProxiedObject(base);
return base;
} | javascript | function finalize(base, path, patches, inversePatches) {
if (isProxy(base)) {
var state = base[PROXY_STATE];
if (state.modified === true) {
if (state.finalized === true) return state.copy;
state.finalized = true;
var result = finalizeObject(useProxies ? state.copy : state.copy = shallowCopy(base), state, path, patches, inversePatches);
generatePatches(state, path, patches, inversePatches, state.base, result);
return result;
} else {
return state.base;
}
}
finalizeNonProxiedObject(base);
return base;
} | [
"function",
"finalize",
"(",
"base",
",",
"path",
",",
"patches",
",",
"inversePatches",
")",
"{",
"if",
"(",
"isProxy",
"(",
"base",
")",
")",
"{",
"var",
"state",
"=",
"base",
"[",
"PROXY_STATE",
"]",
";",
"if",
"(",
"state",
".",
"modified",
"===",
"true",
")",
"{",
"if",
"(",
"state",
".",
"finalized",
"===",
"true",
")",
"return",
"state",
".",
"copy",
";",
"state",
".",
"finalized",
"=",
"true",
";",
"var",
"result",
"=",
"finalizeObject",
"(",
"useProxies",
"?",
"state",
".",
"copy",
":",
"state",
".",
"copy",
"=",
"shallowCopy",
"(",
"base",
")",
",",
"state",
",",
"path",
",",
"patches",
",",
"inversePatches",
")",
";",
"generatePatches",
"(",
"state",
",",
"path",
",",
"patches",
",",
"inversePatches",
",",
"state",
".",
"base",
",",
"result",
")",
";",
"return",
"result",
";",
"}",
"else",
"{",
"return",
"state",
".",
"base",
";",
"}",
"}",
"finalizeNonProxiedObject",
"(",
"base",
")",
";",
"return",
"base",
";",
"}"
] | given a base object, returns it if unmodified, or return the changed cloned if modified | [
"given",
"a",
"base",
"object",
"returns",
"it",
"if",
"unmodified",
"or",
"return",
"the",
"changed",
"cloned",
"if",
"modified"
] | cb1c8c74e5d32bbd9802eb2248cd9bcab8518749 | https://github.com/liymax/pddux/blob/cb1c8c74e5d32bbd9802eb2248cd9bcab8518749/lib/index.js#L167-L182 |
53,712 | liymax/pddux | lib/index.js | produce | function produce(baseState, producer, patchListener) {
// prettier-ignore
if (arguments.length < 1 || arguments.length > 3) throw new Error("produce expects 1 to 3 arguments, got " + arguments.length);
// curried invocation
if (typeof baseState === "function") {
// prettier-ignore
if (typeof producer === "function") throw new Error("if first argument is a function (curried invocation), the second argument to produce cannot be a function");
var initialState = producer;
var recipe = baseState;
return function () {
var args = arguments;
var currentState = args[0] === undefined && initialState !== undefined ? initialState : args[0];
return produce(currentState, function (draft) {
args[0] = draft; // blegh!
return recipe.apply(draft, args);
});
};
}
// prettier-ignore
{
if (typeof producer !== "function") throw new Error("if first argument is not a function, the second argument to produce should be a function");
if (patchListener !== undefined && typeof patchListener !== "function") throw new Error("the third argument of a producer should not be set or a function");
}
// if state is a primitive, don't bother proxying at all
if ((typeof baseState === "undefined" ? "undefined" : _typeof(baseState)) !== "object" || baseState === null) {
var returnValue = producer(baseState);
return returnValue === undefined ? baseState : returnValue;
}
if (!isProxyable(baseState)) throw new Error("the first argument to an immer producer should be a primitive, plain object or array, got " + (typeof baseState === "undefined" ? "undefined" : _typeof(baseState)) + ": \"" + baseState + "\"");
return getUseProxies() ? produceProxy(baseState, producer, patchListener) : produceEs5(baseState, producer, patchListener);
} | javascript | function produce(baseState, producer, patchListener) {
// prettier-ignore
if (arguments.length < 1 || arguments.length > 3) throw new Error("produce expects 1 to 3 arguments, got " + arguments.length);
// curried invocation
if (typeof baseState === "function") {
// prettier-ignore
if (typeof producer === "function") throw new Error("if first argument is a function (curried invocation), the second argument to produce cannot be a function");
var initialState = producer;
var recipe = baseState;
return function () {
var args = arguments;
var currentState = args[0] === undefined && initialState !== undefined ? initialState : args[0];
return produce(currentState, function (draft) {
args[0] = draft; // blegh!
return recipe.apply(draft, args);
});
};
}
// prettier-ignore
{
if (typeof producer !== "function") throw new Error("if first argument is not a function, the second argument to produce should be a function");
if (patchListener !== undefined && typeof patchListener !== "function") throw new Error("the third argument of a producer should not be set or a function");
}
// if state is a primitive, don't bother proxying at all
if ((typeof baseState === "undefined" ? "undefined" : _typeof(baseState)) !== "object" || baseState === null) {
var returnValue = producer(baseState);
return returnValue === undefined ? baseState : returnValue;
}
if (!isProxyable(baseState)) throw new Error("the first argument to an immer producer should be a primitive, plain object or array, got " + (typeof baseState === "undefined" ? "undefined" : _typeof(baseState)) + ": \"" + baseState + "\"");
return getUseProxies() ? produceProxy(baseState, producer, patchListener) : produceEs5(baseState, producer, patchListener);
} | [
"function",
"produce",
"(",
"baseState",
",",
"producer",
",",
"patchListener",
")",
"{",
"// prettier-ignore",
"if",
"(",
"arguments",
".",
"length",
"<",
"1",
"||",
"arguments",
".",
"length",
">",
"3",
")",
"throw",
"new",
"Error",
"(",
"\"produce expects 1 to 3 arguments, got \"",
"+",
"arguments",
".",
"length",
")",
";",
"// curried invocation",
"if",
"(",
"typeof",
"baseState",
"===",
"\"function\"",
")",
"{",
"// prettier-ignore",
"if",
"(",
"typeof",
"producer",
"===",
"\"function\"",
")",
"throw",
"new",
"Error",
"(",
"\"if first argument is a function (curried invocation), the second argument to produce cannot be a function\"",
")",
";",
"var",
"initialState",
"=",
"producer",
";",
"var",
"recipe",
"=",
"baseState",
";",
"return",
"function",
"(",
")",
"{",
"var",
"args",
"=",
"arguments",
";",
"var",
"currentState",
"=",
"args",
"[",
"0",
"]",
"===",
"undefined",
"&&",
"initialState",
"!==",
"undefined",
"?",
"initialState",
":",
"args",
"[",
"0",
"]",
";",
"return",
"produce",
"(",
"currentState",
",",
"function",
"(",
"draft",
")",
"{",
"args",
"[",
"0",
"]",
"=",
"draft",
";",
"// blegh!",
"return",
"recipe",
".",
"apply",
"(",
"draft",
",",
"args",
")",
";",
"}",
")",
";",
"}",
";",
"}",
"// prettier-ignore",
"{",
"if",
"(",
"typeof",
"producer",
"!==",
"\"function\"",
")",
"throw",
"new",
"Error",
"(",
"\"if first argument is not a function, the second argument to produce should be a function\"",
")",
";",
"if",
"(",
"patchListener",
"!==",
"undefined",
"&&",
"typeof",
"patchListener",
"!==",
"\"function\"",
")",
"throw",
"new",
"Error",
"(",
"\"the third argument of a producer should not be set or a function\"",
")",
";",
"}",
"// if state is a primitive, don't bother proxying at all",
"if",
"(",
"(",
"typeof",
"baseState",
"===",
"\"undefined\"",
"?",
"\"undefined\"",
":",
"_typeof",
"(",
"baseState",
")",
")",
"!==",
"\"object\"",
"||",
"baseState",
"===",
"null",
")",
"{",
"var",
"returnValue",
"=",
"producer",
"(",
"baseState",
")",
";",
"return",
"returnValue",
"===",
"undefined",
"?",
"baseState",
":",
"returnValue",
";",
"}",
"if",
"(",
"!",
"isProxyable",
"(",
"baseState",
")",
")",
"throw",
"new",
"Error",
"(",
"\"the first argument to an immer producer should be a primitive, plain object or array, got \"",
"+",
"(",
"typeof",
"baseState",
"===",
"\"undefined\"",
"?",
"\"undefined\"",
":",
"_typeof",
"(",
"baseState",
")",
")",
"+",
"\": \\\"\"",
"+",
"baseState",
"+",
"\"\\\"\"",
")",
";",
"return",
"getUseProxies",
"(",
")",
"?",
"produceProxy",
"(",
"baseState",
",",
"producer",
",",
"patchListener",
")",
":",
"produceEs5",
"(",
"baseState",
",",
"producer",
",",
"patchListener",
")",
";",
"}"
] | produce takes a state, and runs a function against it.
That function can freely mutate the state, as it will create copies-on-write.
This means that the original state will stay unchanged, and once the function finishes, the modified state is returned
@export
@param {any} baseState - the state to start with
@param {Function} producer - function that receives a proxy of the base state as first argument and which can be freely modified
@param {Function} patchListener - optional function that will be called with all the patches produces here
@returns {any} a new state, or the base state if nothing was modified | [
"produce",
"takes",
"a",
"state",
"and",
"runs",
"a",
"function",
"against",
"it",
".",
"That",
"function",
"can",
"freely",
"mutate",
"the",
"state",
"as",
"it",
"will",
"create",
"copies",
"-",
"on",
"-",
"write",
".",
"This",
"means",
"that",
"the",
"original",
"state",
"will",
"stay",
"unchanged",
"and",
"once",
"the",
"function",
"finishes",
"the",
"modified",
"state",
"is",
"returned"
] | cb1c8c74e5d32bbd9802eb2248cd9bcab8518749 | https://github.com/liymax/pddux/blob/cb1c8c74e5d32bbd9802eb2248cd9bcab8518749/lib/index.js#L639-L677 |
53,713 | lesx/lesx-jsx | lib/babel-core/src/config/option-manager.js | mergeOptions | function mergeOptions(config, pass) {
var _this = this;
var result = loadConfig(config);
var plugins = result.plugins.map(function (descriptor) {
return loadPluginDescriptor(descriptor);
});
var presets = result.presets.map(function (descriptor) {
return loadPresetDescriptor(descriptor);
});
if (config.options.passPerPreset != null && typeof config.options.passPerPreset !== "boolean") {
throw new Error(".passPerPreset must be a boolean or undefined");
}
var passPerPreset = config.options.passPerPreset;
pass = pass || this.passes[0];
// resolve presets
if (presets.length > 0) {
var presetPasses = null;
if (passPerPreset) {
var _passes;
presetPasses = presets.map(function () {
return [];
});
// The passes are created in the same order as the preset list, but are inserted before any
// existing additional passes.
(_passes = this.passes).splice.apply(_passes, [1, 0].concat((0, _toConsumableArray3.default)(presetPasses)));
}
presets.forEach(function (presetConfig, i) {
_this.mergeOptions(presetConfig, presetPasses ? presetPasses[i] : pass);
});
}
// resolve plugins
if (plugins.length > 0) {
var _pass;
(_pass = pass).unshift.apply(_pass, (0, _toConsumableArray3.default)(plugins));
}
(0, _merge2.default)(this.options, result.options);
} | javascript | function mergeOptions(config, pass) {
var _this = this;
var result = loadConfig(config);
var plugins = result.plugins.map(function (descriptor) {
return loadPluginDescriptor(descriptor);
});
var presets = result.presets.map(function (descriptor) {
return loadPresetDescriptor(descriptor);
});
if (config.options.passPerPreset != null && typeof config.options.passPerPreset !== "boolean") {
throw new Error(".passPerPreset must be a boolean or undefined");
}
var passPerPreset = config.options.passPerPreset;
pass = pass || this.passes[0];
// resolve presets
if (presets.length > 0) {
var presetPasses = null;
if (passPerPreset) {
var _passes;
presetPasses = presets.map(function () {
return [];
});
// The passes are created in the same order as the preset list, but are inserted before any
// existing additional passes.
(_passes = this.passes).splice.apply(_passes, [1, 0].concat((0, _toConsumableArray3.default)(presetPasses)));
}
presets.forEach(function (presetConfig, i) {
_this.mergeOptions(presetConfig, presetPasses ? presetPasses[i] : pass);
});
}
// resolve plugins
if (plugins.length > 0) {
var _pass;
(_pass = pass).unshift.apply(_pass, (0, _toConsumableArray3.default)(plugins));
}
(0, _merge2.default)(this.options, result.options);
} | [
"function",
"mergeOptions",
"(",
"config",
",",
"pass",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"var",
"result",
"=",
"loadConfig",
"(",
"config",
")",
";",
"var",
"plugins",
"=",
"result",
".",
"plugins",
".",
"map",
"(",
"function",
"(",
"descriptor",
")",
"{",
"return",
"loadPluginDescriptor",
"(",
"descriptor",
")",
";",
"}",
")",
";",
"var",
"presets",
"=",
"result",
".",
"presets",
".",
"map",
"(",
"function",
"(",
"descriptor",
")",
"{",
"return",
"loadPresetDescriptor",
"(",
"descriptor",
")",
";",
"}",
")",
";",
"if",
"(",
"config",
".",
"options",
".",
"passPerPreset",
"!=",
"null",
"&&",
"typeof",
"config",
".",
"options",
".",
"passPerPreset",
"!==",
"\"boolean\"",
")",
"{",
"throw",
"new",
"Error",
"(",
"\".passPerPreset must be a boolean or undefined\"",
")",
";",
"}",
"var",
"passPerPreset",
"=",
"config",
".",
"options",
".",
"passPerPreset",
";",
"pass",
"=",
"pass",
"||",
"this",
".",
"passes",
"[",
"0",
"]",
";",
"// resolve presets",
"if",
"(",
"presets",
".",
"length",
">",
"0",
")",
"{",
"var",
"presetPasses",
"=",
"null",
";",
"if",
"(",
"passPerPreset",
")",
"{",
"var",
"_passes",
";",
"presetPasses",
"=",
"presets",
".",
"map",
"(",
"function",
"(",
")",
"{",
"return",
"[",
"]",
";",
"}",
")",
";",
"// The passes are created in the same order as the preset list, but are inserted before any",
"// existing additional passes.",
"(",
"_passes",
"=",
"this",
".",
"passes",
")",
".",
"splice",
".",
"apply",
"(",
"_passes",
",",
"[",
"1",
",",
"0",
"]",
".",
"concat",
"(",
"(",
"0",
",",
"_toConsumableArray3",
".",
"default",
")",
"(",
"presetPasses",
")",
")",
")",
";",
"}",
"presets",
".",
"forEach",
"(",
"function",
"(",
"presetConfig",
",",
"i",
")",
"{",
"_this",
".",
"mergeOptions",
"(",
"presetConfig",
",",
"presetPasses",
"?",
"presetPasses",
"[",
"i",
"]",
":",
"pass",
")",
";",
"}",
")",
";",
"}",
"// resolve plugins",
"if",
"(",
"plugins",
".",
"length",
">",
"0",
")",
"{",
"var",
"_pass",
";",
"(",
"_pass",
"=",
"pass",
")",
".",
"unshift",
".",
"apply",
"(",
"_pass",
",",
"(",
"0",
",",
"_toConsumableArray3",
".",
"default",
")",
"(",
"plugins",
")",
")",
";",
"}",
"(",
"0",
",",
"_merge2",
".",
"default",
")",
"(",
"this",
".",
"options",
",",
"result",
".",
"options",
")",
";",
"}"
] | This is called when we want to merge the input `opts` into the
base options.
- `alias` is used to output pretty traces back to the original source.
- `loc` is used to point to the original config.
- `dirname` is used to resolve plugins relative to it. | [
"This",
"is",
"called",
"when",
"we",
"want",
"to",
"merge",
"the",
"input",
"opts",
"into",
"the",
"base",
"options",
"."
] | 6b82f5ee115add3fb61b83c8e22e83fad66ad437 | https://github.com/lesx/lesx-jsx/blob/6b82f5ee115add3fb61b83c8e22e83fad66ad437/lib/babel-core/src/config/option-manager.js#L143-L188 |
53,714 | lesx/lesx-jsx | lib/babel-core/src/config/option-manager.js | loadConfig | function loadConfig(config) {
var options = normalizeOptions(config);
if (config.options.plugins != null && !Array.isArray(config.options.plugins)) {
throw new Error(".plugins should be an array, null, or undefined");
}
var plugins = (config.options.plugins || []).map(function (plugin, index) {
var _normalizePair = normalizePair(plugin, _files.loadPlugin, config.dirname),
filepath = _normalizePair.filepath,
value = _normalizePair.value,
options = _normalizePair.options;
return {
alias: filepath || config.loc + "$" + index,
loc: filepath || config.loc,
value: value,
options: options,
dirname: config.dirname
};
});
if (config.options.presets != null && !Array.isArray(config.options.presets)) {
throw new Error(".presets should be an array, null, or undefined");
}
var presets = (config.options.presets || []).map(function (preset, index) {
var _normalizePair2 = normalizePair(preset, _files.loadPreset, config.dirname),
filepath = _normalizePair2.filepath,
value = _normalizePair2.value,
options = _normalizePair2.options;
return {
alias: filepath || config.loc + "$" + index,
loc: filepath || config.loc,
value: value,
options: options,
dirname: config.dirname
};
});
return { options: options, plugins: plugins, presets: presets };
} | javascript | function loadConfig(config) {
var options = normalizeOptions(config);
if (config.options.plugins != null && !Array.isArray(config.options.plugins)) {
throw new Error(".plugins should be an array, null, or undefined");
}
var plugins = (config.options.plugins || []).map(function (plugin, index) {
var _normalizePair = normalizePair(plugin, _files.loadPlugin, config.dirname),
filepath = _normalizePair.filepath,
value = _normalizePair.value,
options = _normalizePair.options;
return {
alias: filepath || config.loc + "$" + index,
loc: filepath || config.loc,
value: value,
options: options,
dirname: config.dirname
};
});
if (config.options.presets != null && !Array.isArray(config.options.presets)) {
throw new Error(".presets should be an array, null, or undefined");
}
var presets = (config.options.presets || []).map(function (preset, index) {
var _normalizePair2 = normalizePair(preset, _files.loadPreset, config.dirname),
filepath = _normalizePair2.filepath,
value = _normalizePair2.value,
options = _normalizePair2.options;
return {
alias: filepath || config.loc + "$" + index,
loc: filepath || config.loc,
value: value,
options: options,
dirname: config.dirname
};
});
return { options: options, plugins: plugins, presets: presets };
} | [
"function",
"loadConfig",
"(",
"config",
")",
"{",
"var",
"options",
"=",
"normalizeOptions",
"(",
"config",
")",
";",
"if",
"(",
"config",
".",
"options",
".",
"plugins",
"!=",
"null",
"&&",
"!",
"Array",
".",
"isArray",
"(",
"config",
".",
"options",
".",
"plugins",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"\".plugins should be an array, null, or undefined\"",
")",
";",
"}",
"var",
"plugins",
"=",
"(",
"config",
".",
"options",
".",
"plugins",
"||",
"[",
"]",
")",
".",
"map",
"(",
"function",
"(",
"plugin",
",",
"index",
")",
"{",
"var",
"_normalizePair",
"=",
"normalizePair",
"(",
"plugin",
",",
"_files",
".",
"loadPlugin",
",",
"config",
".",
"dirname",
")",
",",
"filepath",
"=",
"_normalizePair",
".",
"filepath",
",",
"value",
"=",
"_normalizePair",
".",
"value",
",",
"options",
"=",
"_normalizePair",
".",
"options",
";",
"return",
"{",
"alias",
":",
"filepath",
"||",
"config",
".",
"loc",
"+",
"\"$\"",
"+",
"index",
",",
"loc",
":",
"filepath",
"||",
"config",
".",
"loc",
",",
"value",
":",
"value",
",",
"options",
":",
"options",
",",
"dirname",
":",
"config",
".",
"dirname",
"}",
";",
"}",
")",
";",
"if",
"(",
"config",
".",
"options",
".",
"presets",
"!=",
"null",
"&&",
"!",
"Array",
".",
"isArray",
"(",
"config",
".",
"options",
".",
"presets",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"\".presets should be an array, null, or undefined\"",
")",
";",
"}",
"var",
"presets",
"=",
"(",
"config",
".",
"options",
".",
"presets",
"||",
"[",
"]",
")",
".",
"map",
"(",
"function",
"(",
"preset",
",",
"index",
")",
"{",
"var",
"_normalizePair2",
"=",
"normalizePair",
"(",
"preset",
",",
"_files",
".",
"loadPreset",
",",
"config",
".",
"dirname",
")",
",",
"filepath",
"=",
"_normalizePair2",
".",
"filepath",
",",
"value",
"=",
"_normalizePair2",
".",
"value",
",",
"options",
"=",
"_normalizePair2",
".",
"options",
";",
"return",
"{",
"alias",
":",
"filepath",
"||",
"config",
".",
"loc",
"+",
"\"$\"",
"+",
"index",
",",
"loc",
":",
"filepath",
"||",
"config",
".",
"loc",
",",
"value",
":",
"value",
",",
"options",
":",
"options",
",",
"dirname",
":",
"config",
".",
"dirname",
"}",
";",
"}",
")",
";",
"return",
"{",
"options",
":",
"options",
",",
"plugins",
":",
"plugins",
",",
"presets",
":",
"presets",
"}",
";",
"}"
] | Load and validate the given config into a set of options, plugins, and presets. | [
"Load",
"and",
"validate",
"the",
"given",
"config",
"into",
"a",
"set",
"of",
"options",
"plugins",
"and",
"presets",
"."
] | 6b82f5ee115add3fb61b83c8e22e83fad66ad437 | https://github.com/lesx/lesx-jsx/blob/6b82f5ee115add3fb61b83c8e22e83fad66ad437/lib/babel-core/src/config/option-manager.js#L281-L323 |
53,715 | lesx/lesx-jsx | lib/babel-core/src/config/option-manager.js | loadPresetDescriptor | function loadPresetDescriptor(descriptor) {
return {
type: "preset",
options: loadDescriptor(descriptor).value,
alias: descriptor.alias,
loc: descriptor.loc,
dirname: descriptor.dirname
};
} | javascript | function loadPresetDescriptor(descriptor) {
return {
type: "preset",
options: loadDescriptor(descriptor).value,
alias: descriptor.alias,
loc: descriptor.loc,
dirname: descriptor.dirname
};
} | [
"function",
"loadPresetDescriptor",
"(",
"descriptor",
")",
"{",
"return",
"{",
"type",
":",
"\"preset\"",
",",
"options",
":",
"loadDescriptor",
"(",
"descriptor",
")",
".",
"value",
",",
"alias",
":",
"descriptor",
".",
"alias",
",",
"loc",
":",
"descriptor",
".",
"loc",
",",
"dirname",
":",
"descriptor",
".",
"dirname",
"}",
";",
"}"
] | Generate a config object that will act as the root of a new nested config. | [
"Generate",
"a",
"config",
"object",
"that",
"will",
"act",
"as",
"the",
"root",
"of",
"a",
"new",
"nested",
"config",
"."
] | 6b82f5ee115add3fb61b83c8e22e83fad66ad437 | https://github.com/lesx/lesx-jsx/blob/6b82f5ee115add3fb61b83c8e22e83fad66ad437/lib/babel-core/src/config/option-manager.js#L419-L427 |
53,716 | karfcz/kff | src/View.js | function(options)
{
options = options || {};
this._modelBindersMap = null;
this._collectionBinder = null;
this._bindingIndex = null;
this._itemAlias = null;
this._subviewsStruct = null;
this._explicitSubviewsStruct = null;
this._pendingRefresh = false;
this._pendingRefreshRoot = false;
this._subviewsArgs = null;
this._isRunning = false;
this._isSuspended = false;
this._template = null;
this._isolated = false;
this.subviews = null;
if(options.isolated)
{
this._isolated = true;
}
if(options.parentView)
{
this.scope = options.scope || null;
this._setParentView(options.parentView);
}
else if(options.scope) this.scope = mixin({}, options.scope);
else this.scope = {};
options.scope = null;
if(options.events)
{
this.domEvents = options.events.slice();
}
else this.domEvents = [];
if(options.dispatcher)
{
this.dispatcher = options.dispatcher;
}
else this.dispatcher = null;
if(options.actions)
{
this.actions = mixin({
set: actionSet
}, options.actions);
}
else if((this.parentView == null || this._isolated )&& !options._clone)
{
this.actions = {
set: actionSet
};
}
else this.actions = null;
if(options.env)
{
this.env = options.env;
}
else this.env = { document: document, window: window };
if(options.element)
{
this.element = options.element
options.element = null;
}
else this.element = this.env.document.body;
this.options = options;
} | javascript | function(options)
{
options = options || {};
this._modelBindersMap = null;
this._collectionBinder = null;
this._bindingIndex = null;
this._itemAlias = null;
this._subviewsStruct = null;
this._explicitSubviewsStruct = null;
this._pendingRefresh = false;
this._pendingRefreshRoot = false;
this._subviewsArgs = null;
this._isRunning = false;
this._isSuspended = false;
this._template = null;
this._isolated = false;
this.subviews = null;
if(options.isolated)
{
this._isolated = true;
}
if(options.parentView)
{
this.scope = options.scope || null;
this._setParentView(options.parentView);
}
else if(options.scope) this.scope = mixin({}, options.scope);
else this.scope = {};
options.scope = null;
if(options.events)
{
this.domEvents = options.events.slice();
}
else this.domEvents = [];
if(options.dispatcher)
{
this.dispatcher = options.dispatcher;
}
else this.dispatcher = null;
if(options.actions)
{
this.actions = mixin({
set: actionSet
}, options.actions);
}
else if((this.parentView == null || this._isolated )&& !options._clone)
{
this.actions = {
set: actionSet
};
}
else this.actions = null;
if(options.env)
{
this.env = options.env;
}
else this.env = { document: document, window: window };
if(options.element)
{
this.element = options.element
options.element = null;
}
else this.element = this.env.document.body;
this.options = options;
} | [
"function",
"(",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"this",
".",
"_modelBindersMap",
"=",
"null",
";",
"this",
".",
"_collectionBinder",
"=",
"null",
";",
"this",
".",
"_bindingIndex",
"=",
"null",
";",
"this",
".",
"_itemAlias",
"=",
"null",
";",
"this",
".",
"_subviewsStruct",
"=",
"null",
";",
"this",
".",
"_explicitSubviewsStruct",
"=",
"null",
";",
"this",
".",
"_pendingRefresh",
"=",
"false",
";",
"this",
".",
"_pendingRefreshRoot",
"=",
"false",
";",
"this",
".",
"_subviewsArgs",
"=",
"null",
";",
"this",
".",
"_isRunning",
"=",
"false",
";",
"this",
".",
"_isSuspended",
"=",
"false",
";",
"this",
".",
"_template",
"=",
"null",
";",
"this",
".",
"_isolated",
"=",
"false",
";",
"this",
".",
"subviews",
"=",
"null",
";",
"if",
"(",
"options",
".",
"isolated",
")",
"{",
"this",
".",
"_isolated",
"=",
"true",
";",
"}",
"if",
"(",
"options",
".",
"parentView",
")",
"{",
"this",
".",
"scope",
"=",
"options",
".",
"scope",
"||",
"null",
";",
"this",
".",
"_setParentView",
"(",
"options",
".",
"parentView",
")",
";",
"}",
"else",
"if",
"(",
"options",
".",
"scope",
")",
"this",
".",
"scope",
"=",
"mixin",
"(",
"{",
"}",
",",
"options",
".",
"scope",
")",
";",
"else",
"this",
".",
"scope",
"=",
"{",
"}",
";",
"options",
".",
"scope",
"=",
"null",
";",
"if",
"(",
"options",
".",
"events",
")",
"{",
"this",
".",
"domEvents",
"=",
"options",
".",
"events",
".",
"slice",
"(",
")",
";",
"}",
"else",
"this",
".",
"domEvents",
"=",
"[",
"]",
";",
"if",
"(",
"options",
".",
"dispatcher",
")",
"{",
"this",
".",
"dispatcher",
"=",
"options",
".",
"dispatcher",
";",
"}",
"else",
"this",
".",
"dispatcher",
"=",
"null",
";",
"if",
"(",
"options",
".",
"actions",
")",
"{",
"this",
".",
"actions",
"=",
"mixin",
"(",
"{",
"set",
":",
"actionSet",
"}",
",",
"options",
".",
"actions",
")",
";",
"}",
"else",
"if",
"(",
"(",
"this",
".",
"parentView",
"==",
"null",
"||",
"this",
".",
"_isolated",
")",
"&&",
"!",
"options",
".",
"_clone",
")",
"{",
"this",
".",
"actions",
"=",
"{",
"set",
":",
"actionSet",
"}",
";",
"}",
"else",
"this",
".",
"actions",
"=",
"null",
";",
"if",
"(",
"options",
".",
"env",
")",
"{",
"this",
".",
"env",
"=",
"options",
".",
"env",
";",
"}",
"else",
"this",
".",
"env",
"=",
"{",
"document",
":",
"document",
",",
"window",
":",
"window",
"}",
";",
"if",
"(",
"options",
".",
"element",
")",
"{",
"this",
".",
"element",
"=",
"options",
".",
"element",
"options",
".",
"element",
"=",
"null",
";",
"}",
"else",
"this",
".",
"element",
"=",
"this",
".",
"env",
".",
"document",
".",
"body",
";",
"this",
".",
"options",
"=",
"options",
";",
"}"
] | Base class for views
@constructs
@param {Object} options Options object
@param {DOM Element|jQuery} options.element A DOM element that will be a root element of the view
@param {Array} options.scope Array of model instances to be used by the view | [
"Base",
"class",
"for",
"views"
] | 533b69e8bc9e9b7f60b403d776678bf1c06ac502 | https://github.com/karfcz/kff/blob/533b69e8bc9e9b7f60b403d776678bf1c06ac502/src/View.js#L90-L165 |
|
53,717 | karfcz/kff | src/View.js | function()
{
if(!this._modelBindersMap) this._initBinding();
if(!this._collectionBinder)
{
this._explicitSubviewsStruct = null;
if(this._template) this.element.innerHTML = this._template;
if(this.render !== noop) this.render();
this.renderSubviews();
}
} | javascript | function()
{
if(!this._modelBindersMap) this._initBinding();
if(!this._collectionBinder)
{
this._explicitSubviewsStruct = null;
if(this._template) this.element.innerHTML = this._template;
if(this.render !== noop) this.render();
this.renderSubviews();
}
} | [
"function",
"(",
")",
"{",
"if",
"(",
"!",
"this",
".",
"_modelBindersMap",
")",
"this",
".",
"_initBinding",
"(",
")",
";",
"if",
"(",
"!",
"this",
".",
"_collectionBinder",
")",
"{",
"this",
".",
"_explicitSubviewsStruct",
"=",
"null",
";",
"if",
"(",
"this",
".",
"_template",
")",
"this",
".",
"element",
".",
"innerHTML",
"=",
"this",
".",
"_template",
";",
"if",
"(",
"this",
".",
"render",
"!==",
"noop",
")",
"this",
".",
"render",
"(",
")",
";",
"this",
".",
"renderSubviews",
"(",
")",
";",
"}",
"}"
] | Renders the view. It will be called automatically. Should not be called
directly. | [
"Renders",
"the",
"view",
".",
"It",
"will",
"be",
"called",
"automatically",
".",
"Should",
"not",
"be",
"called",
"directly",
"."
] | 533b69e8bc9e9b7f60b403d776678bf1c06ac502 | https://github.com/karfcz/kff/blob/533b69e8bc9e9b7f60b403d776678bf1c06ac502/src/View.js#L208-L220 |
|
53,718 | karfcz/kff | src/View.js | function()
{
if(this._isRunning && !this._isSuspended)
{
var shouldRefresh = true;
if(typeof this.shouldRefresh === 'function') shouldRefresh = this.shouldRefresh();
if(shouldRefresh)
{
if(typeof this.refresh === 'function') this.refresh();
if(this._collectionBinder)
{
this._collectionBinder.refreshBoundViews();
this._collectionBinder.refreshAll();
}
else
{
this._rebindCursors();
this._refreshOwnBinders();
if(this.subviews !== null)
{
for(var i = 0, l = this.subviews.length; i < l; i++) this.subviews[i].refreshAll();
}
}
}
this._pendingRefresh = false;
}
} | javascript | function()
{
if(this._isRunning && !this._isSuspended)
{
var shouldRefresh = true;
if(typeof this.shouldRefresh === 'function') shouldRefresh = this.shouldRefresh();
if(shouldRefresh)
{
if(typeof this.refresh === 'function') this.refresh();
if(this._collectionBinder)
{
this._collectionBinder.refreshBoundViews();
this._collectionBinder.refreshAll();
}
else
{
this._rebindCursors();
this._refreshOwnBinders();
if(this.subviews !== null)
{
for(var i = 0, l = this.subviews.length; i < l; i++) this.subviews[i].refreshAll();
}
}
}
this._pendingRefresh = false;
}
} | [
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"_isRunning",
"&&",
"!",
"this",
".",
"_isSuspended",
")",
"{",
"var",
"shouldRefresh",
"=",
"true",
";",
"if",
"(",
"typeof",
"this",
".",
"shouldRefresh",
"===",
"'function'",
")",
"shouldRefresh",
"=",
"this",
".",
"shouldRefresh",
"(",
")",
";",
"if",
"(",
"shouldRefresh",
")",
"{",
"if",
"(",
"typeof",
"this",
".",
"refresh",
"===",
"'function'",
")",
"this",
".",
"refresh",
"(",
")",
";",
"if",
"(",
"this",
".",
"_collectionBinder",
")",
"{",
"this",
".",
"_collectionBinder",
".",
"refreshBoundViews",
"(",
")",
";",
"this",
".",
"_collectionBinder",
".",
"refreshAll",
"(",
")",
";",
"}",
"else",
"{",
"this",
".",
"_rebindCursors",
"(",
")",
";",
"this",
".",
"_refreshOwnBinders",
"(",
")",
";",
"if",
"(",
"this",
".",
"subviews",
"!==",
"null",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"l",
"=",
"this",
".",
"subviews",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"this",
".",
"subviews",
"[",
"i",
"]",
".",
"refreshAll",
"(",
")",
";",
"}",
"}",
"}",
"this",
".",
"_pendingRefresh",
"=",
"false",
";",
"}",
"}"
] | Refreshes all binders, subviews and bound views | [
"Refreshes",
"all",
"binders",
"subviews",
"and",
"bound",
"views"
] | 533b69e8bc9e9b7f60b403d776678bf1c06ac502 | https://github.com/karfcz/kff/blob/533b69e8bc9e9b7f60b403d776678bf1c06ac502/src/View.js#L350-L376 |
|
53,719 | karfcz/kff | src/View.js | function()
{
var view = this;
while(view.parentView)
{
view = view.parentView;
}
if(view.dispatcher !== null)
{
view.dispatcher.trigger({ type: 'refresh' });
this._pendingRefreshRoot = false;
}
} | javascript | function()
{
var view = this;
while(view.parentView)
{
view = view.parentView;
}
if(view.dispatcher !== null)
{
view.dispatcher.trigger({ type: 'refresh' });
this._pendingRefreshRoot = false;
}
} | [
"function",
"(",
")",
"{",
"var",
"view",
"=",
"this",
";",
"while",
"(",
"view",
".",
"parentView",
")",
"{",
"view",
"=",
"view",
".",
"parentView",
";",
"}",
"if",
"(",
"view",
".",
"dispatcher",
"!==",
"null",
")",
"{",
"view",
".",
"dispatcher",
".",
"trigger",
"(",
"{",
"type",
":",
"'refresh'",
"}",
")",
";",
"this",
".",
"_pendingRefreshRoot",
"=",
"false",
";",
"}",
"}"
] | Refreshes all views from root | [
"Refreshes",
"all",
"views",
"from",
"root"
] | 533b69e8bc9e9b7f60b403d776678bf1c06ac502 | https://github.com/karfcz/kff/blob/533b69e8bc9e9b7f60b403d776678bf1c06ac502/src/View.js#L381-L394 |
|
53,720 | karfcz/kff | src/View.js | function()
{
this._destroyBinding();
if(this._collectionBinder) this._collectionBinder.destroyBoundViews();
this._modelBindersMap = null;
this._collectionBinder = null;
this._bindingIndex = null;
this._itemAlias = null;
this.element.removeAttribute(settings.DATA_RENDERED_ATTR);
this.undelegateEvents();
this.destroySubviews();
if(this.dispatcher)
{
this.dispatcher.off('refresh', this.f('refreshAll'));
this.dispatcher.off('refreshFromRoot', this.f('refreshFromRoot'));
this.dispatcher.off('refreshRaf', this.f('requestRefreshAll'));
this.dispatcher.off('refreshFromRootRaf', this.f('requestRefreshAllFromRoot'));
this.dispatcher.off('dispatcher:noaction', this.f('_dispatchNoAction'));
}
if(this.destroy !== noop) this.destroy();
if(typeof this.afterDestroy === 'function') this.afterDestroy();
this._subviewsStruct = null;
this._explicitSubviewsStruct = null;
this.subviews = null;
this._isRunning = false;
this._isSuspended = false;
} | javascript | function()
{
this._destroyBinding();
if(this._collectionBinder) this._collectionBinder.destroyBoundViews();
this._modelBindersMap = null;
this._collectionBinder = null;
this._bindingIndex = null;
this._itemAlias = null;
this.element.removeAttribute(settings.DATA_RENDERED_ATTR);
this.undelegateEvents();
this.destroySubviews();
if(this.dispatcher)
{
this.dispatcher.off('refresh', this.f('refreshAll'));
this.dispatcher.off('refreshFromRoot', this.f('refreshFromRoot'));
this.dispatcher.off('refreshRaf', this.f('requestRefreshAll'));
this.dispatcher.off('refreshFromRootRaf', this.f('requestRefreshAllFromRoot'));
this.dispatcher.off('dispatcher:noaction', this.f('_dispatchNoAction'));
}
if(this.destroy !== noop) this.destroy();
if(typeof this.afterDestroy === 'function') this.afterDestroy();
this._subviewsStruct = null;
this._explicitSubviewsStruct = null;
this.subviews = null;
this._isRunning = false;
this._isSuspended = false;
} | [
"function",
"(",
")",
"{",
"this",
".",
"_destroyBinding",
"(",
")",
";",
"if",
"(",
"this",
".",
"_collectionBinder",
")",
"this",
".",
"_collectionBinder",
".",
"destroyBoundViews",
"(",
")",
";",
"this",
".",
"_modelBindersMap",
"=",
"null",
";",
"this",
".",
"_collectionBinder",
"=",
"null",
";",
"this",
".",
"_bindingIndex",
"=",
"null",
";",
"this",
".",
"_itemAlias",
"=",
"null",
";",
"this",
".",
"element",
".",
"removeAttribute",
"(",
"settings",
".",
"DATA_RENDERED_ATTR",
")",
";",
"this",
".",
"undelegateEvents",
"(",
")",
";",
"this",
".",
"destroySubviews",
"(",
")",
";",
"if",
"(",
"this",
".",
"dispatcher",
")",
"{",
"this",
".",
"dispatcher",
".",
"off",
"(",
"'refresh'",
",",
"this",
".",
"f",
"(",
"'refreshAll'",
")",
")",
";",
"this",
".",
"dispatcher",
".",
"off",
"(",
"'refreshFromRoot'",
",",
"this",
".",
"f",
"(",
"'refreshFromRoot'",
")",
")",
";",
"this",
".",
"dispatcher",
".",
"off",
"(",
"'refreshRaf'",
",",
"this",
".",
"f",
"(",
"'requestRefreshAll'",
")",
")",
";",
"this",
".",
"dispatcher",
".",
"off",
"(",
"'refreshFromRootRaf'",
",",
"this",
".",
"f",
"(",
"'requestRefreshAllFromRoot'",
")",
")",
";",
"this",
".",
"dispatcher",
".",
"off",
"(",
"'dispatcher:noaction'",
",",
"this",
".",
"f",
"(",
"'_dispatchNoAction'",
")",
")",
";",
"}",
"if",
"(",
"this",
".",
"destroy",
"!==",
"noop",
")",
"this",
".",
"destroy",
"(",
")",
";",
"if",
"(",
"typeof",
"this",
".",
"afterDestroy",
"===",
"'function'",
")",
"this",
".",
"afterDestroy",
"(",
")",
";",
"this",
".",
"_subviewsStruct",
"=",
"null",
";",
"this",
".",
"_explicitSubviewsStruct",
"=",
"null",
";",
"this",
".",
"subviews",
"=",
"null",
";",
"this",
".",
"_isRunning",
"=",
"false",
";",
"this",
".",
"_isSuspended",
"=",
"false",
";",
"}"
] | Destroys the view (destroys all subviews and unbinds previously bound DOM events.
It will be called automatically. Should not be called directly. | [
"Destroys",
"the",
"view",
"(",
"destroys",
"all",
"subviews",
"and",
"unbinds",
"previously",
"bound",
"DOM",
"events",
".",
"It",
"will",
"be",
"called",
"automatically",
".",
"Should",
"not",
"be",
"called",
"directly",
"."
] | 533b69e8bc9e9b7f60b403d776678bf1c06ac502 | https://github.com/karfcz/kff/blob/533b69e8bc9e9b7f60b403d776678bf1c06ac502/src/View.js#L400-L431 |
|
53,721 | karfcz/kff | src/View.js | function()
{
if(this._collectionBinder)
{
this._collectionBinder.destroyBoundViews();
}
else
{
var subView, i, l;
// Destroy subviews
if(this.subviews !== null)
{
for(i = 0, l = this.subviews.length; i < l; i++)
{
subView = this.subviews[i];
subView.destroyAll();
}
}
this.subviews = null;
this._subviewsStruct = null;
}
} | javascript | function()
{
if(this._collectionBinder)
{
this._collectionBinder.destroyBoundViews();
}
else
{
var subView, i, l;
// Destroy subviews
if(this.subviews !== null)
{
for(i = 0, l = this.subviews.length; i < l; i++)
{
subView = this.subviews[i];
subView.destroyAll();
}
}
this.subviews = null;
this._subviewsStruct = null;
}
} | [
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"_collectionBinder",
")",
"{",
"this",
".",
"_collectionBinder",
".",
"destroyBoundViews",
"(",
")",
";",
"}",
"else",
"{",
"var",
"subView",
",",
"i",
",",
"l",
";",
"// Destroy subviews",
"if",
"(",
"this",
".",
"subviews",
"!==",
"null",
")",
"{",
"for",
"(",
"i",
"=",
"0",
",",
"l",
"=",
"this",
".",
"subviews",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"subView",
"=",
"this",
".",
"subviews",
"[",
"i",
"]",
";",
"subView",
".",
"destroyAll",
"(",
")",
";",
"}",
"}",
"this",
".",
"subviews",
"=",
"null",
";",
"this",
".",
"_subviewsStruct",
"=",
"null",
";",
"}",
"}"
] | Destroys the subviews. It will be called automatically. Should not be called directly. | [
"Destroys",
"the",
"subviews",
".",
"It",
"will",
"be",
"called",
"automatically",
".",
"Should",
"not",
"be",
"called",
"directly",
"."
] | 533b69e8bc9e9b7f60b403d776678bf1c06ac502 | https://github.com/karfcz/kff/blob/533b69e8bc9e9b7f60b403d776678bf1c06ac502/src/View.js#L532-L554 |
|
53,722 | karfcz/kff | src/View.js | function(keyPath)
{
if(typeof keyPath === 'string') keyPath = keyPath.split('.');
var rootCursorName = keyPath[0];
keyPath = keyPath.slice(1);
var rootCursor = this.scope[rootCursorName];
if(!(rootCursor instanceof Cursor)) rootCursor = new Cursor(rootCursor, keyPath);
var cursor = rootCursor.refine(keyPath);
return cursor;
} | javascript | function(keyPath)
{
if(typeof keyPath === 'string') keyPath = keyPath.split('.');
var rootCursorName = keyPath[0];
keyPath = keyPath.slice(1);
var rootCursor = this.scope[rootCursorName];
if(!(rootCursor instanceof Cursor)) rootCursor = new Cursor(rootCursor, keyPath);
var cursor = rootCursor.refine(keyPath);
return cursor;
} | [
"function",
"(",
"keyPath",
")",
"{",
"if",
"(",
"typeof",
"keyPath",
"===",
"'string'",
")",
"keyPath",
"=",
"keyPath",
".",
"split",
"(",
"'.'",
")",
";",
"var",
"rootCursorName",
"=",
"keyPath",
"[",
"0",
"]",
";",
"keyPath",
"=",
"keyPath",
".",
"slice",
"(",
"1",
")",
";",
"var",
"rootCursor",
"=",
"this",
".",
"scope",
"[",
"rootCursorName",
"]",
";",
"if",
"(",
"!",
"(",
"rootCursor",
"instanceof",
"Cursor",
")",
")",
"rootCursor",
"=",
"new",
"Cursor",
"(",
"rootCursor",
",",
"keyPath",
")",
";",
"var",
"cursor",
"=",
"rootCursor",
".",
"refine",
"(",
"keyPath",
")",
";",
"return",
"cursor",
";",
"}"
] | Returns a model object bound to the view or to the parent view.
Accepts the model name as a string or key path in the form of "modelName.attribute.nextAttribute etc.".
Will search for "modelName" in current view, then in parent view etc. When found, returns a value of
"attribute.nextAtrribute" using model's mget method.
@param {string} modelPath Key path of model in the form of "modelName.attribute.nextAttribute etc.".
@return {mixed} A model instance or attribute value or null if not found. | [
"Returns",
"a",
"model",
"object",
"bound",
"to",
"the",
"view",
"or",
"to",
"the",
"parent",
"view",
"."
] | 533b69e8bc9e9b7f60b403d776678bf1c06ac502 | https://github.com/karfcz/kff/blob/533b69e8bc9e9b7f60b403d776678bf1c06ac502/src/View.js#L578-L590 |
|
53,723 | karfcz/kff | src/View.js | function(events)
{
if(!Array.isArray(events))
{
if(arguments.length === 2 || arguments.length === 3) this.domEvents.push(Array.prototype.slice.apply(arguments));
return;
}
else if(!Array.isArray(events[0]))
{
events = Array.prototype.slice.apply(arguments);
}
Array.prototype.push.apply(this.domEvents, events);
} | javascript | function(events)
{
if(!Array.isArray(events))
{
if(arguments.length === 2 || arguments.length === 3) this.domEvents.push(Array.prototype.slice.apply(arguments));
return;
}
else if(!Array.isArray(events[0]))
{
events = Array.prototype.slice.apply(arguments);
}
Array.prototype.push.apply(this.domEvents, events);
} | [
"function",
"(",
"events",
")",
"{",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"events",
")",
")",
"{",
"if",
"(",
"arguments",
".",
"length",
"===",
"2",
"||",
"arguments",
".",
"length",
"===",
"3",
")",
"this",
".",
"domEvents",
".",
"push",
"(",
"Array",
".",
"prototype",
".",
"slice",
".",
"apply",
"(",
"arguments",
")",
")",
";",
"return",
";",
"}",
"else",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"events",
"[",
"0",
"]",
")",
")",
"{",
"events",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"apply",
"(",
"arguments",
")",
";",
"}",
"Array",
".",
"prototype",
".",
"push",
".",
"apply",
"(",
"this",
".",
"domEvents",
",",
"events",
")",
";",
"}"
] | Adds events config to the internal events array.
@private
@param {Array} events Array of arrays of binding config | [
"Adds",
"events",
"config",
"to",
"the",
"internal",
"events",
"array",
"."
] | 533b69e8bc9e9b7f60b403d776678bf1c06ac502 | https://github.com/karfcz/kff/blob/533b69e8bc9e9b7f60b403d776678bf1c06ac502/src/View.js#L598-L610 |
|
53,724 | karfcz/kff | src/View.js | function(viewName, options)
{
var subView, args;
if(this._subviewsArgs && Array.isArray(this._subviewsArgs[viewName]))
{
args = this._subviewsArgs[viewName];
if(typeof args[0] === 'object' && args[0] !== null) options = immerge(options, args[0]);
}
options.parentView = this;
if(viewName === 'View') subView = new View(options);
else if(viewName in this.scope) subView = new this.scope[viewName](options);
if(subView instanceof View)
{
if(this.subviews === null) this.subviews = [];
this.subviews.push(subView);
}
return subView;
} | javascript | function(viewName, options)
{
var subView, args;
if(this._subviewsArgs && Array.isArray(this._subviewsArgs[viewName]))
{
args = this._subviewsArgs[viewName];
if(typeof args[0] === 'object' && args[0] !== null) options = immerge(options, args[0]);
}
options.parentView = this;
if(viewName === 'View') subView = new View(options);
else if(viewName in this.scope) subView = new this.scope[viewName](options);
if(subView instanceof View)
{
if(this.subviews === null) this.subviews = [];
this.subviews.push(subView);
}
return subView;
} | [
"function",
"(",
"viewName",
",",
"options",
")",
"{",
"var",
"subView",
",",
"args",
";",
"if",
"(",
"this",
".",
"_subviewsArgs",
"&&",
"Array",
".",
"isArray",
"(",
"this",
".",
"_subviewsArgs",
"[",
"viewName",
"]",
")",
")",
"{",
"args",
"=",
"this",
".",
"_subviewsArgs",
"[",
"viewName",
"]",
";",
"if",
"(",
"typeof",
"args",
"[",
"0",
"]",
"===",
"'object'",
"&&",
"args",
"[",
"0",
"]",
"!==",
"null",
")",
"options",
"=",
"immerge",
"(",
"options",
",",
"args",
"[",
"0",
"]",
")",
";",
"}",
"options",
".",
"parentView",
"=",
"this",
";",
"if",
"(",
"viewName",
"===",
"'View'",
")",
"subView",
"=",
"new",
"View",
"(",
"options",
")",
";",
"else",
"if",
"(",
"viewName",
"in",
"this",
".",
"scope",
")",
"subView",
"=",
"new",
"this",
".",
"scope",
"[",
"viewName",
"]",
"(",
"options",
")",
";",
"if",
"(",
"subView",
"instanceof",
"View",
")",
"{",
"if",
"(",
"this",
".",
"subviews",
"===",
"null",
")",
"this",
".",
"subviews",
"=",
"[",
"]",
";",
"this",
".",
"subviews",
".",
"push",
"(",
"subView",
")",
";",
"}",
"return",
"subView",
";",
"}"
] | Creates a new subview and adds it to the internal subviews list.
Do not use this method directly, use addSubview method instead.
@private
@param {String} viewName Name of the view
@param {Object} options Options object for the subview constructor
@return {View} Created view | [
"Creates",
"a",
"new",
"subview",
"and",
"adds",
"it",
"to",
"the",
"internal",
"subviews",
"list",
".",
"Do",
"not",
"use",
"this",
"method",
"directly",
"use",
"addSubview",
"method",
"instead",
"."
] | 533b69e8bc9e9b7f60b403d776678bf1c06ac502 | https://github.com/karfcz/kff/blob/533b69e8bc9e9b7f60b403d776678bf1c06ac502/src/View.js#L709-L729 |
|
53,725 | karfcz/kff | src/View.js | function(element, viewName, options)
{
if(this._explicitSubviewsStruct === null) this._explicitSubviewsStruct = [];
this._explicitSubviewsStruct.push({
viewName: viewName,
element: element,
options: options || {}
});
} | javascript | function(element, viewName, options)
{
if(this._explicitSubviewsStruct === null) this._explicitSubviewsStruct = [];
this._explicitSubviewsStruct.push({
viewName: viewName,
element: element,
options: options || {}
});
} | [
"function",
"(",
"element",
",",
"viewName",
",",
"options",
")",
"{",
"if",
"(",
"this",
".",
"_explicitSubviewsStruct",
"===",
"null",
")",
"this",
".",
"_explicitSubviewsStruct",
"=",
"[",
"]",
";",
"this",
".",
"_explicitSubviewsStruct",
".",
"push",
"(",
"{",
"viewName",
":",
"viewName",
",",
"element",
":",
"element",
",",
"options",
":",
"options",
"||",
"{",
"}",
"}",
")",
";",
"}"
] | Adds subview metadata to the internal list. The subviews from this list
are then rendered in renderSubviews method which is automatically called
when the view is rendered.
This method can be used is in the render method to manually create a view
that is not parsed from html/template (for example for an element that
sits at the end od the body element).
@param {DOM element} element Element of the subview
@param {String} viewName Name of the view
@param {[type]} options Options object for the subview constructor | [
"Adds",
"subview",
"metadata",
"to",
"the",
"internal",
"list",
".",
"The",
"subviews",
"from",
"this",
"list",
"are",
"then",
"rendered",
"in",
"renderSubviews",
"method",
"which",
"is",
"automatically",
"called",
"when",
"the",
"view",
"is",
"rendered",
"."
] | 533b69e8bc9e9b7f60b403d776678bf1c06ac502 | https://github.com/karfcz/kff/blob/533b69e8bc9e9b7f60b403d776678bf1c06ac502/src/View.js#L744-L752 |
|
53,726 | karfcz/kff | src/View.js | function(force)
{
if(this._collectionBinder)
{
this._collectionBinder.refreshBinders(force);
}
else
{
this._refreshOwnBinders(force);
if(this.subviews !== null)
{
for(var i = 0, l = this.subviews.length; i < l; i++) this.subviews[i].refreshBinders(force);
}
}
} | javascript | function(force)
{
if(this._collectionBinder)
{
this._collectionBinder.refreshBinders(force);
}
else
{
this._refreshOwnBinders(force);
if(this.subviews !== null)
{
for(var i = 0, l = this.subviews.length; i < l; i++) this.subviews[i].refreshBinders(force);
}
}
} | [
"function",
"(",
"force",
")",
"{",
"if",
"(",
"this",
".",
"_collectionBinder",
")",
"{",
"this",
".",
"_collectionBinder",
".",
"refreshBinders",
"(",
"force",
")",
";",
"}",
"else",
"{",
"this",
".",
"_refreshOwnBinders",
"(",
"force",
")",
";",
"if",
"(",
"this",
".",
"subviews",
"!==",
"null",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"l",
"=",
"this",
".",
"subviews",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"this",
".",
"subviews",
"[",
"i",
"]",
".",
"refreshBinders",
"(",
"force",
")",
";",
"}",
"}",
"}"
] | Refreshes data-binders in all subviews.
@param {Object} event Any event object that caused refreshing | [
"Refreshes",
"data",
"-",
"binders",
"in",
"all",
"subviews",
"."
] | 533b69e8bc9e9b7f60b403d776678bf1c06ac502 | https://github.com/karfcz/kff/blob/533b69e8bc9e9b7f60b403d776678bf1c06ac502/src/View.js#L764-L778 |
|
53,727 | karfcz/kff | src/View.js | function()
{
if(this._collectionBinder)
{
this._collectionBinder.refreshIndexedBinders();
}
else
{
if(this._modelBindersMap)
{
this._modelBindersMap.refreshIndexedBinders();
}
if(this.subviews !== null)
{
for(var i = 0, l = this.subviews.length; i < l; i++) this.subviews[i].refreshIndexedBinders();
}
}
} | javascript | function()
{
if(this._collectionBinder)
{
this._collectionBinder.refreshIndexedBinders();
}
else
{
if(this._modelBindersMap)
{
this._modelBindersMap.refreshIndexedBinders();
}
if(this.subviews !== null)
{
for(var i = 0, l = this.subviews.length; i < l; i++) this.subviews[i].refreshIndexedBinders();
}
}
} | [
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"_collectionBinder",
")",
"{",
"this",
".",
"_collectionBinder",
".",
"refreshIndexedBinders",
"(",
")",
";",
"}",
"else",
"{",
"if",
"(",
"this",
".",
"_modelBindersMap",
")",
"{",
"this",
".",
"_modelBindersMap",
".",
"refreshIndexedBinders",
"(",
")",
";",
"}",
"if",
"(",
"this",
".",
"subviews",
"!==",
"null",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"l",
"=",
"this",
".",
"subviews",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"this",
".",
"subviews",
"[",
"i",
"]",
".",
"refreshIndexedBinders",
"(",
")",
";",
"}",
"}",
"}"
] | Refreshes all indexed binders of this view or subviews
@private
@return {[type]} [description] | [
"Refreshes",
"all",
"indexed",
"binders",
"of",
"this",
"view",
"or",
"subviews"
] | 533b69e8bc9e9b7f60b403d776678bf1c06ac502 | https://github.com/karfcz/kff/blob/533b69e8bc9e9b7f60b403d776678bf1c06ac502/src/View.js#L786-L803 |
|
53,728 | karfcz/kff | src/View.js | function()
{
var l;
var clonedSubview;
var options = this.options;
options.parentView = null;
options.env = this.env;
options._clone = true;
var clonedView = new this.constructor(options);
if(this.subviews !== null)
{
l = this.subviews.length;
clonedView.subviews = new Array(l);
while(l--)
{
clonedSubview = this.subviews[l]._clone();
clonedView.subviews[l] = clonedSubview;
}
}
if(this._subviewsStruct !== null)
{
clonedView._subviewsStruct = this._subviewsStruct.slice();
}
if(this._explicitSubviewsStruct !== null)
{
clonedView._explicitSubviewsStruct = this._explicitSubviewsStruct.slice();
}
if(this._collectionBinder)
{
clonedView._collectionBinder = new CollectionBinder(
{
view: clonedView,
keyPath: this._collectionBinder.keyPath,
animate: this._collectionBinder.animate,
keyProp: this._collectionBinder.keyProp,
collection: null,
collectionPathArray: this._collectionBinder.collectionPathArray
});
}
if(this._modelBindersMap)
{
clonedView._modelBindersMap = this._modelBindersMap.clone();
clonedView._modelBindersMap.setView(clonedView);
}
clonedView._itemAlias = this._itemAlias;
return clonedView;
} | javascript | function()
{
var l;
var clonedSubview;
var options = this.options;
options.parentView = null;
options.env = this.env;
options._clone = true;
var clonedView = new this.constructor(options);
if(this.subviews !== null)
{
l = this.subviews.length;
clonedView.subviews = new Array(l);
while(l--)
{
clonedSubview = this.subviews[l]._clone();
clonedView.subviews[l] = clonedSubview;
}
}
if(this._subviewsStruct !== null)
{
clonedView._subviewsStruct = this._subviewsStruct.slice();
}
if(this._explicitSubviewsStruct !== null)
{
clonedView._explicitSubviewsStruct = this._explicitSubviewsStruct.slice();
}
if(this._collectionBinder)
{
clonedView._collectionBinder = new CollectionBinder(
{
view: clonedView,
keyPath: this._collectionBinder.keyPath,
animate: this._collectionBinder.animate,
keyProp: this._collectionBinder.keyProp,
collection: null,
collectionPathArray: this._collectionBinder.collectionPathArray
});
}
if(this._modelBindersMap)
{
clonedView._modelBindersMap = this._modelBindersMap.clone();
clonedView._modelBindersMap.setView(clonedView);
}
clonedView._itemAlias = this._itemAlias;
return clonedView;
} | [
"function",
"(",
")",
"{",
"var",
"l",
";",
"var",
"clonedSubview",
";",
"var",
"options",
"=",
"this",
".",
"options",
";",
"options",
".",
"parentView",
"=",
"null",
";",
"options",
".",
"env",
"=",
"this",
".",
"env",
";",
"options",
".",
"_clone",
"=",
"true",
";",
"var",
"clonedView",
"=",
"new",
"this",
".",
"constructor",
"(",
"options",
")",
";",
"if",
"(",
"this",
".",
"subviews",
"!==",
"null",
")",
"{",
"l",
"=",
"this",
".",
"subviews",
".",
"length",
";",
"clonedView",
".",
"subviews",
"=",
"new",
"Array",
"(",
"l",
")",
";",
"while",
"(",
"l",
"--",
")",
"{",
"clonedSubview",
"=",
"this",
".",
"subviews",
"[",
"l",
"]",
".",
"_clone",
"(",
")",
";",
"clonedView",
".",
"subviews",
"[",
"l",
"]",
"=",
"clonedSubview",
";",
"}",
"}",
"if",
"(",
"this",
".",
"_subviewsStruct",
"!==",
"null",
")",
"{",
"clonedView",
".",
"_subviewsStruct",
"=",
"this",
".",
"_subviewsStruct",
".",
"slice",
"(",
")",
";",
"}",
"if",
"(",
"this",
".",
"_explicitSubviewsStruct",
"!==",
"null",
")",
"{",
"clonedView",
".",
"_explicitSubviewsStruct",
"=",
"this",
".",
"_explicitSubviewsStruct",
".",
"slice",
"(",
")",
";",
"}",
"if",
"(",
"this",
".",
"_collectionBinder",
")",
"{",
"clonedView",
".",
"_collectionBinder",
"=",
"new",
"CollectionBinder",
"(",
"{",
"view",
":",
"clonedView",
",",
"keyPath",
":",
"this",
".",
"_collectionBinder",
".",
"keyPath",
",",
"animate",
":",
"this",
".",
"_collectionBinder",
".",
"animate",
",",
"keyProp",
":",
"this",
".",
"_collectionBinder",
".",
"keyProp",
",",
"collection",
":",
"null",
",",
"collectionPathArray",
":",
"this",
".",
"_collectionBinder",
".",
"collectionPathArray",
"}",
")",
";",
"}",
"if",
"(",
"this",
".",
"_modelBindersMap",
")",
"{",
"clonedView",
".",
"_modelBindersMap",
"=",
"this",
".",
"_modelBindersMap",
".",
"clone",
"(",
")",
";",
"clonedView",
".",
"_modelBindersMap",
".",
"setView",
"(",
"clonedView",
")",
";",
"}",
"clonedView",
".",
"_itemAlias",
"=",
"this",
".",
"_itemAlias",
";",
"return",
"clonedView",
";",
"}"
] | Clones this binding view
@return {View} Cloned view | [
"Clones",
"this",
"binding",
"view"
] | 533b69e8bc9e9b7f60b403d776678bf1c06ac502 | https://github.com/karfcz/kff/blob/533b69e8bc9e9b7f60b403d776678bf1c06ac502/src/View.js#L888-L941 |
|
53,729 | karfcz/kff | src/View.js | function(element)
{
var i, l;
this.element = element;
this._rebindSubViews(element, {
subviewIndex: 0,
subviewsStructIndex: 0,
index: 0
});
if(this._modelBindersMap)
{
this._modelBindersMap.setView(this);
}
if(this._collectionBinder)
{
this._collectionBinder.view = this;
}
} | javascript | function(element)
{
var i, l;
this.element = element;
this._rebindSubViews(element, {
subviewIndex: 0,
subviewsStructIndex: 0,
index: 0
});
if(this._modelBindersMap)
{
this._modelBindersMap.setView(this);
}
if(this._collectionBinder)
{
this._collectionBinder.view = this;
}
} | [
"function",
"(",
"element",
")",
"{",
"var",
"i",
",",
"l",
";",
"this",
".",
"element",
"=",
"element",
";",
"this",
".",
"_rebindSubViews",
"(",
"element",
",",
"{",
"subviewIndex",
":",
"0",
",",
"subviewsStructIndex",
":",
"0",
",",
"index",
":",
"0",
"}",
")",
";",
"if",
"(",
"this",
".",
"_modelBindersMap",
")",
"{",
"this",
".",
"_modelBindersMap",
".",
"setView",
"(",
"this",
")",
";",
"}",
"if",
"(",
"this",
".",
"_collectionBinder",
")",
"{",
"this",
".",
"_collectionBinder",
".",
"view",
"=",
"this",
";",
"}",
"}"
] | Rebinds the view to another DOM element
@private
@param {DOMELement} element New DOM element of the view | [
"Rebinds",
"the",
"view",
"to",
"another",
"DOM",
"element"
] | 533b69e8bc9e9b7f60b403d776678bf1c06ac502 | https://github.com/karfcz/kff/blob/533b69e8bc9e9b7f60b403d776678bf1c06ac502/src/View.js#L982-L1004 |
|
53,730 | binder-project/binder-logging | lib/reader.js | BinderLogReader | function BinderLogReader () {
this.config = defaultConfig
var staticLogsUrl = this.config.host + ':' + this.config.elasticsearch.port
this.client = new elasticsearch.Client({
host: staticLogsUrl,
log: 'error'
})
} | javascript | function BinderLogReader () {
this.config = defaultConfig
var staticLogsUrl = this.config.host + ':' + this.config.elasticsearch.port
this.client = new elasticsearch.Client({
host: staticLogsUrl,
log: 'error'
})
} | [
"function",
"BinderLogReader",
"(",
")",
"{",
"this",
".",
"config",
"=",
"defaultConfig",
"var",
"staticLogsUrl",
"=",
"this",
".",
"config",
".",
"host",
"+",
"':'",
"+",
"this",
".",
"config",
".",
"elasticsearch",
".",
"port",
"this",
".",
"client",
"=",
"new",
"elasticsearch",
".",
"Client",
"(",
"{",
"host",
":",
"staticLogsUrl",
",",
"log",
":",
"'error'",
"}",
")",
"}"
] | Reads or streams Binder log messages, optionally for a specific application
@constructor | [
"Reads",
"or",
"streams",
"Binder",
"log",
"messages",
"optionally",
"for",
"a",
"specific",
"application"
] | e31b21a4fd3fa815664dc79c9c2a95a0dbfc7632 | https://github.com/binder-project/binder-logging/blob/e31b21a4fd3fa815664dc79c9c2a95a0dbfc7632/lib/reader.js#L30-L37 |
53,731 | binder-project/binder-logging | lib/reader.js | function (config) {
if (!config) {
config = defaultConfig
}
var error = validateConfig(config)
if (error) {
}
config = assign(defaultConfig, config)
return new BinderLogReader(config)
} | javascript | function (config) {
if (!config) {
config = defaultConfig
}
var error = validateConfig(config)
if (error) {
}
config = assign(defaultConfig, config)
return new BinderLogReader(config)
} | [
"function",
"(",
"config",
")",
"{",
"if",
"(",
"!",
"config",
")",
"{",
"config",
"=",
"defaultConfig",
"}",
"var",
"error",
"=",
"validateConfig",
"(",
"config",
")",
"if",
"(",
"error",
")",
"{",
"}",
"config",
"=",
"assign",
"(",
"defaultConfig",
",",
"config",
")",
"return",
"new",
"BinderLogReader",
"(",
"config",
")",
"}"
] | Returns an instance of BinderLogReader
@param {object} config - BinderLogReader configuration options | [
"Returns",
"an",
"instance",
"of",
"BinderLogReader"
] | e31b21a4fd3fa815664dc79c9c2a95a0dbfc7632 | https://github.com/binder-project/binder-logging/blob/e31b21a4fd3fa815664dc79c9c2a95a0dbfc7632/lib/reader.js#L161-L170 |
|
53,732 | AndreasMadsen/steer | lib/extension.js | function(done) {
var source = __dirname + '/background.js';
var dest = self.dir + '/background.js';
fs.readFile(source, 'utf8', function(err, background) {
if (err) return done(err);
// Make background.js connect with the websocket server on
// this port
background = background.replace('$PORT', self.port);
fs.writeFile(dest, background, done);
});
} | javascript | function(done) {
var source = __dirname + '/background.js';
var dest = self.dir + '/background.js';
fs.readFile(source, 'utf8', function(err, background) {
if (err) return done(err);
// Make background.js connect with the websocket server on
// this port
background = background.replace('$PORT', self.port);
fs.writeFile(dest, background, done);
});
} | [
"function",
"(",
"done",
")",
"{",
"var",
"source",
"=",
"__dirname",
"+",
"'/background.js'",
";",
"var",
"dest",
"=",
"self",
".",
"dir",
"+",
"'/background.js'",
";",
"fs",
".",
"readFile",
"(",
"source",
",",
"'utf8'",
",",
"function",
"(",
"err",
",",
"background",
")",
"{",
"if",
"(",
"err",
")",
"return",
"done",
"(",
"err",
")",
";",
"// Make background.js connect with the websocket server on",
"// this port",
"background",
"=",
"background",
".",
"replace",
"(",
"'$PORT'",
",",
"self",
".",
"port",
")",
";",
"fs",
".",
"writeFile",
"(",
"dest",
",",
"background",
",",
"done",
")",
";",
"}",
")",
";",
"}"
] | write background.js the file that connect to the websocket server defined in this file | [
"write",
"background",
".",
"js",
"the",
"file",
"that",
"connect",
"to",
"the",
"websocket",
"server",
"defined",
"in",
"this",
"file"
] | 5f19587abb1d6384bcff3e4bdede1fdce178d7b2 | https://github.com/AndreasMadsen/steer/blob/5f19587abb1d6384bcff3e4bdede1fdce178d7b2/lib/extension.js#L78-L90 |
|
53,733 | AndreasMadsen/steer | lib/extension.js | closeServer | function closeServer(done) {
if (self.server) {
self.server.close();
self.server.removeListener('error', handlers.relayError);
}
self.httpServer.close(done);
} | javascript | function closeServer(done) {
if (self.server) {
self.server.close();
self.server.removeListener('error', handlers.relayError);
}
self.httpServer.close(done);
} | [
"function",
"closeServer",
"(",
"done",
")",
"{",
"if",
"(",
"self",
".",
"server",
")",
"{",
"self",
".",
"server",
".",
"close",
"(",
")",
";",
"self",
".",
"server",
".",
"removeListener",
"(",
"'error'",
",",
"handlers",
".",
"relayError",
")",
";",
"}",
"self",
".",
"httpServer",
".",
"close",
"(",
"done",
")",
";",
"}"
] | close down the the server used for websockets | [
"close",
"down",
"the",
"the",
"server",
"used",
"for",
"websockets"
] | 5f19587abb1d6384bcff3e4bdede1fdce178d7b2 | https://github.com/AndreasMadsen/steer/blob/5f19587abb1d6384bcff3e4bdede1fdce178d7b2/lib/extension.js#L123-L129 |
53,734 | AndreasMadsen/steer | lib/extension.js | removeExtensionDir | function removeExtensionDir(done) {
if (!self.dir) return done(null);
rimraf(self.dir, done);
} | javascript | function removeExtensionDir(done) {
if (!self.dir) return done(null);
rimraf(self.dir, done);
} | [
"function",
"removeExtensionDir",
"(",
"done",
")",
"{",
"if",
"(",
"!",
"self",
".",
"dir",
")",
"return",
"done",
"(",
"null",
")",
";",
"rimraf",
"(",
"self",
".",
"dir",
",",
"done",
")",
";",
"}"
] | remove extension files | [
"remove",
"extension",
"files"
] | 5f19587abb1d6384bcff3e4bdede1fdce178d7b2 | https://github.com/AndreasMadsen/steer/blob/5f19587abb1d6384bcff3e4bdede1fdce178d7b2/lib/extension.js#L132-L136 |
53,735 | thlorenz/ispawn | ispawn.js | createAndSpawn | function createAndSpawn(opts) {
const spawned = createSpawn(opts)
const termination = spawned.spawn()
return { termination, proc: spawned.proc }
} | javascript | function createAndSpawn(opts) {
const spawned = createSpawn(opts)
const termination = spawned.spawn()
return { termination, proc: spawned.proc }
} | [
"function",
"createAndSpawn",
"(",
"opts",
")",
"{",
"const",
"spawned",
"=",
"createSpawn",
"(",
"opts",
")",
"const",
"termination",
"=",
"spawned",
".",
"spawn",
"(",
")",
"return",
"{",
"termination",
",",
"proc",
":",
"spawned",
".",
"proc",
"}",
"}"
] | Spawns a process with the given options allowing to intercept `stdout`
and `stderr` output of the application itself or the underlying process,
i.e. V8 and Node.js messages.
### onStdout and onStderr interceptors
The functions, `onStdout`, `onStderr` called with each line written to the
respective file descriptor have the following signature:
`onStdout(line:String, fromApp:Boolean)` where `fromApp` is `true` when the
line came from the app itself and `false` when it came from the underlying
runtime, i.e. Node.js or V8 when flags triggered diagnostics output.
To mark a line as _handled_ return `true` from the function and it will not
be printed to the console.
### Example
```js
function onStdout(line, fromApp) {
// Don't intercept app output, just have it printed as usual
if (fromApp) return false
// Do something with diagnositics messages here ...
return true
}
const { termination } = spawn({
execArgv: [ '--trace-turbo-inlining' ]
, argv: [ require.resolve('./bind.js') ]
, onStdout
})
try {
const code = await termination
console.log('The app returned with code', code)
} catch (err) {
console.error(err)
}
```
[full example](https://github.com/thlorenz/ispawn/blob/master/example/map-inlines)
@name spawn
@param {Object} $0 options
@param {Array.<String>} [$0.execArgv = []] arguments passed to Node.js/V8 directly (not to your app)
@param {Array.<String>} $0.argv file to run followed by flags to pass to your app
@param {String} [$0.node = process.execPath] path to Node.js executable
@param {Object} [$0.spawnOpts = {}] options passed to `child_process.spawn`
@param {Function} [$0.onStdout = null] function to call with each line written to stdout
@param {Function} [$0.onStderr = null] function to call with each line written to stderr
@returns {Object} with the following properties
- termination: {Promise} that resolves when process exits
- proc: the spawned process | [
"Spawns",
"a",
"process",
"with",
"the",
"given",
"options",
"allowing",
"to",
"intercept",
"stdout",
"and",
"stderr",
"output",
"of",
"the",
"application",
"itself",
"or",
"the",
"underlying",
"process",
"i",
".",
"e",
".",
"V8",
"and",
"Node",
".",
"js",
"messages",
"."
] | 5709839b44764d60f2cd78e1cf78a6a5afed9ac2 | https://github.com/thlorenz/ispawn/blob/5709839b44764d60f2cd78e1cf78a6a5afed9ac2/ispawn.js#L172-L176 |
53,736 | JimmyRobz/mokuai | utils/bool-string-option.js | boolStringOption | function boolStringOption(value){
if(value === 'true' || value === true) return true;
if(value === 'false' || value === false) return false;
return value;
} | javascript | function boolStringOption(value){
if(value === 'true' || value === true) return true;
if(value === 'false' || value === false) return false;
return value;
} | [
"function",
"boolStringOption",
"(",
"value",
")",
"{",
"if",
"(",
"value",
"===",
"'true'",
"||",
"value",
"===",
"true",
")",
"return",
"true",
";",
"if",
"(",
"value",
"===",
"'false'",
"||",
"value",
"===",
"false",
")",
"return",
"false",
";",
"return",
"value",
";",
"}"
] | Utility function to get the option value from string or boolean value | [
"Utility",
"function",
"to",
"get",
"the",
"option",
"value",
"from",
"string",
"or",
"boolean",
"value"
] | 02ba6dfd6fb61b4a124e15a8252cff7e940132ac | https://github.com/JimmyRobz/mokuai/blob/02ba6dfd6fb61b4a124e15a8252cff7e940132ac/utils/bool-string-option.js#L2-L6 |
53,737 | spacemaus/postvox | vox-server/interchangeserver.js | createExpressAppServer | function createExpressAppServer(app, port) {
return new P(function(resolve, reject) {
var appServer = app.listen(port, function() {
var addr = appServer.address();
resolve({
app: app,
appServer: appServer,
serverUrl: url.format({ protocol: 'http', hostname: addr.address, port: addr.port })
});
});
});
} | javascript | function createExpressAppServer(app, port) {
return new P(function(resolve, reject) {
var appServer = app.listen(port, function() {
var addr = appServer.address();
resolve({
app: app,
appServer: appServer,
serverUrl: url.format({ protocol: 'http', hostname: addr.address, port: addr.port })
});
});
});
} | [
"function",
"createExpressAppServer",
"(",
"app",
",",
"port",
")",
"{",
"return",
"new",
"P",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"var",
"appServer",
"=",
"app",
".",
"listen",
"(",
"port",
",",
"function",
"(",
")",
"{",
"var",
"addr",
"=",
"appServer",
".",
"address",
"(",
")",
";",
"resolve",
"(",
"{",
"app",
":",
"app",
",",
"appServer",
":",
"appServer",
",",
"serverUrl",
":",
"url",
".",
"format",
"(",
"{",
"protocol",
":",
"'http'",
",",
"hostname",
":",
"addr",
".",
"address",
",",
"port",
":",
"addr",
".",
"port",
"}",
")",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Creates an Express app and begins listening on the configured address.
@param {Function} app The express app.
@param {Number} port The port to listen on.
@returns {Promise<Object>}
app_server: The server listening to the given port.
serverUrl: The url to report to clients. | [
"Creates",
"an",
"Express",
"app",
"and",
"begins",
"listening",
"on",
"the",
"configured",
"address",
"."
] | de98e5ed37edaee1b1edadf93e15eb8f8d21f457 | https://github.com/spacemaus/postvox/blob/de98e5ed37edaee1b1edadf93e15eb8f8d21f457/vox-server/interchangeserver.js#L71-L82 |
53,738 | MauroJr/amp | src/encode.js | encode | function encode(args) {
const argc = args.length;
let len = 1;
let off = 0;
var i;
// data length
for (i = 0; i < argc; i += 1) {
len += 4 + args[i].length;
}
// buffer
const buf = Buffer.alloc(len);
// pack meta
buf[off += 1] = (VERSION << 4) | argc;
// pack args
for (i = 0; i < argc; i += 1) {
const arg = args[i];
buf.writeUInt32BE(arg.length, off);
off += 4;
arg.copy(buf, off);
off += arg.length;
}
return buf;
} | javascript | function encode(args) {
const argc = args.length;
let len = 1;
let off = 0;
var i;
// data length
for (i = 0; i < argc; i += 1) {
len += 4 + args[i].length;
}
// buffer
const buf = Buffer.alloc(len);
// pack meta
buf[off += 1] = (VERSION << 4) | argc;
// pack args
for (i = 0; i < argc; i += 1) {
const arg = args[i];
buf.writeUInt32BE(arg.length, off);
off += 4;
arg.copy(buf, off);
off += arg.length;
}
return buf;
} | [
"function",
"encode",
"(",
"args",
")",
"{",
"const",
"argc",
"=",
"args",
".",
"length",
";",
"let",
"len",
"=",
"1",
";",
"let",
"off",
"=",
"0",
";",
"var",
"i",
";",
"// data length",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"argc",
";",
"i",
"+=",
"1",
")",
"{",
"len",
"+=",
"4",
"+",
"args",
"[",
"i",
"]",
".",
"length",
";",
"}",
"// buffer",
"const",
"buf",
"=",
"Buffer",
".",
"alloc",
"(",
"len",
")",
";",
"// pack meta",
"buf",
"[",
"off",
"+=",
"1",
"]",
"=",
"(",
"VERSION",
"<<",
"4",
")",
"|",
"argc",
";",
"// pack args",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"argc",
";",
"i",
"+=",
"1",
")",
"{",
"const",
"arg",
"=",
"args",
"[",
"i",
"]",
";",
"buf",
".",
"writeUInt32BE",
"(",
"arg",
".",
"length",
",",
"off",
")",
";",
"off",
"+=",
"4",
";",
"arg",
".",
"copy",
"(",
"buf",
",",
"off",
")",
";",
"off",
"+=",
"arg",
".",
"length",
";",
"}",
"return",
"buf",
";",
"}"
] | Encode `msg` and `args`.
@param {Array} args
@return {Buffer}
@api public | [
"Encode",
"msg",
"and",
"args",
"."
] | 2b7df0bcf91228d02bdd6d6f1e1238743dbbb086 | https://github.com/MauroJr/amp/blob/2b7df0bcf91228d02bdd6d6f1e1238743dbbb086/src/encode.js#L18-L47 |
53,739 | tmpfs/ttycolor | index.js | proxy | function proxy(options, format) {
var tty = options.tty
, method = options.method
, re = /(%[sdj])+/g
, start
, end;
if(arguments.length === 1) {
return method.apply(console, []);
}
var arg, i, replacing, replacements, matches, tag;
replacing = (typeof format === 'string')
&& re.test(format) && arguments.length > 2;
replacements = [].slice.call(arguments, 2);
if(format instanceof AnsiColor) {
replacing = true;
if(!replacements.length) {
replacements.unshift(format); format = '%s';
}
}
if(!replacing) {
replacements.unshift(format);
return method.apply(console, replacements);
}
matches = (format && (typeof format.match === 'function')) ?
format.match(re) : [];
if(format instanceof AnsiColor) {
if(!tty) {
format = format.v;
}else{
tag = format.start(tty);
format = format.valueOf(tty);
}
}
//console.dir('is tty: ' + tty);
if(tty) {
re = /(%[sdj])/g;
var fmt, result, j = 0;
while((result = re.exec(format))) {
if(j === replacements.length) {
break;
}
arg = replacements[j];
//console.dir('processing ansi replacement: ' + typeof(arg));
fmt = result[1];
start = format.substr(0, result.index);
end = format.substr(result.index + result[0].length);
//console.dir('re format: ' + fmt);
//console.dir('re start: ' + start);
//console.dir('re end: ' + end);
if((arg instanceof AnsiColor)) {
//console.dir('update arg value: ' + typeof(arg.v));
if(fmt === '%j') {
arg.v = JSON.stringify(arg.v, circular());
}
format = start + '%s' + end;
}
j++;
}
}
for(i = 0;i < replacements.length;i++) {
arg = replacements[i];
if(arg instanceof AnsiColor) {
replacements[i] = arg.valueOf(tty, tag);
}
}
replacements.unshift(format);
return method.apply(options.scope ? options.scope : console, replacements);
} | javascript | function proxy(options, format) {
var tty = options.tty
, method = options.method
, re = /(%[sdj])+/g
, start
, end;
if(arguments.length === 1) {
return method.apply(console, []);
}
var arg, i, replacing, replacements, matches, tag;
replacing = (typeof format === 'string')
&& re.test(format) && arguments.length > 2;
replacements = [].slice.call(arguments, 2);
if(format instanceof AnsiColor) {
replacing = true;
if(!replacements.length) {
replacements.unshift(format); format = '%s';
}
}
if(!replacing) {
replacements.unshift(format);
return method.apply(console, replacements);
}
matches = (format && (typeof format.match === 'function')) ?
format.match(re) : [];
if(format instanceof AnsiColor) {
if(!tty) {
format = format.v;
}else{
tag = format.start(tty);
format = format.valueOf(tty);
}
}
//console.dir('is tty: ' + tty);
if(tty) {
re = /(%[sdj])/g;
var fmt, result, j = 0;
while((result = re.exec(format))) {
if(j === replacements.length) {
break;
}
arg = replacements[j];
//console.dir('processing ansi replacement: ' + typeof(arg));
fmt = result[1];
start = format.substr(0, result.index);
end = format.substr(result.index + result[0].length);
//console.dir('re format: ' + fmt);
//console.dir('re start: ' + start);
//console.dir('re end: ' + end);
if((arg instanceof AnsiColor)) {
//console.dir('update arg value: ' + typeof(arg.v));
if(fmt === '%j') {
arg.v = JSON.stringify(arg.v, circular());
}
format = start + '%s' + end;
}
j++;
}
}
for(i = 0;i < replacements.length;i++) {
arg = replacements[i];
if(arg instanceof AnsiColor) {
replacements[i] = arg.valueOf(tty, tag);
}
}
replacements.unshift(format);
return method.apply(options.scope ? options.scope : console, replacements);
} | [
"function",
"proxy",
"(",
"options",
",",
"format",
")",
"{",
"var",
"tty",
"=",
"options",
".",
"tty",
",",
"method",
"=",
"options",
".",
"method",
",",
"re",
"=",
"/",
"(%[sdj])+",
"/",
"g",
",",
"start",
",",
"end",
";",
"if",
"(",
"arguments",
".",
"length",
"===",
"1",
")",
"{",
"return",
"method",
".",
"apply",
"(",
"console",
",",
"[",
"]",
")",
";",
"}",
"var",
"arg",
",",
"i",
",",
"replacing",
",",
"replacements",
",",
"matches",
",",
"tag",
";",
"replacing",
"=",
"(",
"typeof",
"format",
"===",
"'string'",
")",
"&&",
"re",
".",
"test",
"(",
"format",
")",
"&&",
"arguments",
".",
"length",
">",
"2",
";",
"replacements",
"=",
"[",
"]",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"2",
")",
";",
"if",
"(",
"format",
"instanceof",
"AnsiColor",
")",
"{",
"replacing",
"=",
"true",
";",
"if",
"(",
"!",
"replacements",
".",
"length",
")",
"{",
"replacements",
".",
"unshift",
"(",
"format",
")",
";",
"format",
"=",
"'%s'",
";",
"}",
"}",
"if",
"(",
"!",
"replacing",
")",
"{",
"replacements",
".",
"unshift",
"(",
"format",
")",
";",
"return",
"method",
".",
"apply",
"(",
"console",
",",
"replacements",
")",
";",
"}",
"matches",
"=",
"(",
"format",
"&&",
"(",
"typeof",
"format",
".",
"match",
"===",
"'function'",
")",
")",
"?",
"format",
".",
"match",
"(",
"re",
")",
":",
"[",
"]",
";",
"if",
"(",
"format",
"instanceof",
"AnsiColor",
")",
"{",
"if",
"(",
"!",
"tty",
")",
"{",
"format",
"=",
"format",
".",
"v",
";",
"}",
"else",
"{",
"tag",
"=",
"format",
".",
"start",
"(",
"tty",
")",
";",
"format",
"=",
"format",
".",
"valueOf",
"(",
"tty",
")",
";",
"}",
"}",
"//console.dir('is tty: ' + tty);",
"if",
"(",
"tty",
")",
"{",
"re",
"=",
"/",
"(%[sdj])",
"/",
"g",
";",
"var",
"fmt",
",",
"result",
",",
"j",
"=",
"0",
";",
"while",
"(",
"(",
"result",
"=",
"re",
".",
"exec",
"(",
"format",
")",
")",
")",
"{",
"if",
"(",
"j",
"===",
"replacements",
".",
"length",
")",
"{",
"break",
";",
"}",
"arg",
"=",
"replacements",
"[",
"j",
"]",
";",
"//console.dir('processing ansi replacement: ' + typeof(arg));",
"fmt",
"=",
"result",
"[",
"1",
"]",
";",
"start",
"=",
"format",
".",
"substr",
"(",
"0",
",",
"result",
".",
"index",
")",
";",
"end",
"=",
"format",
".",
"substr",
"(",
"result",
".",
"index",
"+",
"result",
"[",
"0",
"]",
".",
"length",
")",
";",
"//console.dir('re format: ' + fmt);",
"//console.dir('re start: ' + start);",
"//console.dir('re end: ' + end);",
"if",
"(",
"(",
"arg",
"instanceof",
"AnsiColor",
")",
")",
"{",
"//console.dir('update arg value: ' + typeof(arg.v));",
"if",
"(",
"fmt",
"===",
"'%j'",
")",
"{",
"arg",
".",
"v",
"=",
"JSON",
".",
"stringify",
"(",
"arg",
".",
"v",
",",
"circular",
"(",
")",
")",
";",
"}",
"format",
"=",
"start",
"+",
"'%s'",
"+",
"end",
";",
"}",
"j",
"++",
";",
"}",
"}",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"replacements",
".",
"length",
";",
"i",
"++",
")",
"{",
"arg",
"=",
"replacements",
"[",
"i",
"]",
";",
"if",
"(",
"arg",
"instanceof",
"AnsiColor",
")",
"{",
"replacements",
"[",
"i",
"]",
"=",
"arg",
".",
"valueOf",
"(",
"tty",
",",
"tag",
")",
";",
"}",
"}",
"replacements",
".",
"unshift",
"(",
"format",
")",
";",
"return",
"method",
".",
"apply",
"(",
"options",
".",
"scope",
"?",
"options",
".",
"scope",
":",
"console",
",",
"replacements",
")",
";",
"}"
] | Escapes replacement values.
@param options Proxy configuration options.
@param options.tty A boolean indicating whether the output is a tty.
@param options.method A method to proxy to.
@param options.stream A writable stream to write to.
@param format The format string.
@param ... The format string arguments. | [
"Escapes",
"replacement",
"values",
"."
] | 4b72de7f61bfd922f227f3f4e7c61fb95ff9c023 | https://github.com/tmpfs/ttycolor/blob/4b72de7f61bfd922f227f3f4e7c61fb95ff9c023/index.js#L23-L92 |
53,740 | tmpfs/ttycolor | index.js | format | function format(fmt) {
var args = [].slice.call(arguments, 0);
var tty = true;
var test = (typeof fmt === 'function') ? fmt : null;
if(test) {
tty = test();
args.shift();
}
args.unshift({scope: util, method: util.format, tty: tty});
//console.dir(args);
return proxy.apply(null, args);
} | javascript | function format(fmt) {
var args = [].slice.call(arguments, 0);
var tty = true;
var test = (typeof fmt === 'function') ? fmt : null;
if(test) {
tty = test();
args.shift();
}
args.unshift({scope: util, method: util.format, tty: tty});
//console.dir(args);
return proxy.apply(null, args);
} | [
"function",
"format",
"(",
"fmt",
")",
"{",
"var",
"args",
"=",
"[",
"]",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"0",
")",
";",
"var",
"tty",
"=",
"true",
";",
"var",
"test",
"=",
"(",
"typeof",
"fmt",
"===",
"'function'",
")",
"?",
"fmt",
":",
"null",
";",
"if",
"(",
"test",
")",
"{",
"tty",
"=",
"test",
"(",
")",
";",
"args",
".",
"shift",
"(",
")",
";",
"}",
"args",
".",
"unshift",
"(",
"{",
"scope",
":",
"util",
",",
"method",
":",
"util",
".",
"format",
",",
"tty",
":",
"tty",
"}",
")",
";",
"//console.dir(args);",
"return",
"proxy",
".",
"apply",
"(",
"null",
",",
"args",
")",
";",
"}"
] | Retrieve a formatted string. | [
"Retrieve",
"a",
"formatted",
"string",
"."
] | 4b72de7f61bfd922f227f3f4e7c61fb95ff9c023 | https://github.com/tmpfs/ttycolor/blob/4b72de7f61bfd922f227f3f4e7c61fb95ff9c023/index.js#L150-L161 |
53,741 | tmpfs/ttycolor | index.js | main | function main(option, parser, force) {
if(typeof option === 'function') {
parser = option;
option = null;
}
if(option !== false) {
option = option || parse.option;
parser = parser || parse;
}
//var mode = parse.auto;
if(typeof parser === 'function') {
module.exports.mode = parser(parse.modes, option, process.argv.slice(2));
}
initialize(force);
return module.exports;
} | javascript | function main(option, parser, force) {
if(typeof option === 'function') {
parser = option;
option = null;
}
if(option !== false) {
option = option || parse.option;
parser = parser || parse;
}
//var mode = parse.auto;
if(typeof parser === 'function') {
module.exports.mode = parser(parse.modes, option, process.argv.slice(2));
}
initialize(force);
return module.exports;
} | [
"function",
"main",
"(",
"option",
",",
"parser",
",",
"force",
")",
"{",
"if",
"(",
"typeof",
"option",
"===",
"'function'",
")",
"{",
"parser",
"=",
"option",
";",
"option",
"=",
"null",
";",
"}",
"if",
"(",
"option",
"!==",
"false",
")",
"{",
"option",
"=",
"option",
"||",
"parse",
".",
"option",
";",
"parser",
"=",
"parser",
"||",
"parse",
";",
"}",
"//var mode = parse.auto;",
"if",
"(",
"typeof",
"parser",
"===",
"'function'",
")",
"{",
"module",
".",
"exports",
".",
"mode",
"=",
"parser",
"(",
"parse",
".",
"modes",
",",
"option",
",",
"process",
".",
"argv",
".",
"slice",
"(",
"2",
")",
")",
";",
"}",
"initialize",
"(",
"force",
")",
";",
"return",
"module",
".",
"exports",
";",
"}"
] | Module main entry point to initialize
console method overrides.
@param option The option name to use when parsing
command line argments.
@param parser The command line parser implementation.
@param force Force initialization. | [
"Module",
"main",
"entry",
"point",
"to",
"initialize",
"console",
"method",
"overrides",
"."
] | 4b72de7f61bfd922f227f3f4e7c61fb95ff9c023 | https://github.com/tmpfs/ttycolor/blob/4b72de7f61bfd922f227f3f4e7c61fb95ff9c023/index.js#L201-L216 |
53,742 | samsonjs/gitter | lib/index.js | camel | function camel(s) {
return s.replace(/_(.)/g, function(_, l) { return l.toUpperCase() })
} | javascript | function camel(s) {
return s.replace(/_(.)/g, function(_, l) { return l.toUpperCase() })
} | [
"function",
"camel",
"(",
"s",
")",
"{",
"return",
"s",
".",
"replace",
"(",
"/",
"_(.)",
"/",
"g",
",",
"function",
"(",
"_",
",",
"l",
")",
"{",
"return",
"l",
".",
"toUpperCase",
"(",
")",
"}",
")",
"}"
] | created_at => createdAt | [
"created_at",
"=",
">",
"createdAt"
] | ac9f2f618154f03b68a8b49addd28cfd55a260bc | https://github.com/samsonjs/gitter/blob/ac9f2f618154f03b68a8b49addd28cfd55a260bc/lib/index.js#L455-L457 |
53,743 | samsonjs/gitter | lib/index.js | camelize | function camelize(obj) {
if (!obj || typeof obj === 'string') return obj
if (Array.isArray(obj)) return obj.map(camelize)
if (typeof obj === 'object') {
return Object.keys(obj).reduce(function(camelizedObj, k) {
camelizedObj[camel(k)] = camelize(obj[k])
return camelizedObj
}, {})
}
return obj
} | javascript | function camelize(obj) {
if (!obj || typeof obj === 'string') return obj
if (Array.isArray(obj)) return obj.map(camelize)
if (typeof obj === 'object') {
return Object.keys(obj).reduce(function(camelizedObj, k) {
camelizedObj[camel(k)] = camelize(obj[k])
return camelizedObj
}, {})
}
return obj
} | [
"function",
"camelize",
"(",
"obj",
")",
"{",
"if",
"(",
"!",
"obj",
"||",
"typeof",
"obj",
"===",
"'string'",
")",
"return",
"obj",
"if",
"(",
"Array",
".",
"isArray",
"(",
"obj",
")",
")",
"return",
"obj",
".",
"map",
"(",
"camelize",
")",
"if",
"(",
"typeof",
"obj",
"===",
"'object'",
")",
"{",
"return",
"Object",
".",
"keys",
"(",
"obj",
")",
".",
"reduce",
"(",
"function",
"(",
"camelizedObj",
",",
"k",
")",
"{",
"camelizedObj",
"[",
"camel",
"(",
"k",
")",
"]",
"=",
"camelize",
"(",
"obj",
"[",
"k",
"]",
")",
"return",
"camelizedObj",
"}",
",",
"{",
"}",
")",
"}",
"return",
"obj",
"}"
] | camelize all keys of an object, or all objects in an array | [
"camelize",
"all",
"keys",
"of",
"an",
"object",
"or",
"all",
"objects",
"in",
"an",
"array"
] | ac9f2f618154f03b68a8b49addd28cfd55a260bc | https://github.com/samsonjs/gitter/blob/ac9f2f618154f03b68a8b49addd28cfd55a260bc/lib/index.js#L460-L470 |
53,744 | MD4/potato-masher | lib/map.js | _mainMap | function _mainMap(data, schema, options) {
options = options || {};
var mapping = _map(data, schema, options);
if (options.removeChanged) {
var mappedFields = _getMappedFields(schema);
mappedFields.forEach(function (field) {
_removeMappedFields(mapping, field);
});
mapping = _cleanArrays(mapping);
}
return mapping;
} | javascript | function _mainMap(data, schema, options) {
options = options || {};
var mapping = _map(data, schema, options);
if (options.removeChanged) {
var mappedFields = _getMappedFields(schema);
mappedFields.forEach(function (field) {
_removeMappedFields(mapping, field);
});
mapping = _cleanArrays(mapping);
}
return mapping;
} | [
"function",
"_mainMap",
"(",
"data",
",",
"schema",
",",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"var",
"mapping",
"=",
"_map",
"(",
"data",
",",
"schema",
",",
"options",
")",
";",
"if",
"(",
"options",
".",
"removeChanged",
")",
"{",
"var",
"mappedFields",
"=",
"_getMappedFields",
"(",
"schema",
")",
";",
"mappedFields",
".",
"forEach",
"(",
"function",
"(",
"field",
")",
"{",
"_removeMappedFields",
"(",
"mapping",
",",
"field",
")",
";",
"}",
")",
";",
"mapping",
"=",
"_cleanArrays",
"(",
"mapping",
")",
";",
"}",
"return",
"mapping",
";",
"}"
] | Main map function
Returns a new object with its new aspect given by the schema
@param data
@param schema
@param options
@returns {*}
@private | [
"Main",
"map",
"function",
"Returns",
"a",
"new",
"object",
"with",
"its",
"new",
"aspect",
"given",
"by",
"the",
"schema"
] | 88e21a45350e7204f4102e7186c5beaa8753bd7f | https://github.com/MD4/potato-masher/blob/88e21a45350e7204f4102e7186c5beaa8753bd7f/lib/map.js#L20-L31 |
53,745 | MD4/potato-masher | lib/map.js | _map | function _map(data, schema, options) {
options = options || {};
if (!schema || data === null) {
return data;
}
if (schema instanceof Array) {
return _mapArray(data, schema, options);
}
if (typeof schema === 'object') {
return _mapObject(data, schema, options);
}
return schema;
} | javascript | function _map(data, schema, options) {
options = options || {};
if (!schema || data === null) {
return data;
}
if (schema instanceof Array) {
return _mapArray(data, schema, options);
}
if (typeof schema === 'object') {
return _mapObject(data, schema, options);
}
return schema;
} | [
"function",
"_map",
"(",
"data",
",",
"schema",
",",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"if",
"(",
"!",
"schema",
"||",
"data",
"===",
"null",
")",
"{",
"return",
"data",
";",
"}",
"if",
"(",
"schema",
"instanceof",
"Array",
")",
"{",
"return",
"_mapArray",
"(",
"data",
",",
"schema",
",",
"options",
")",
";",
"}",
"if",
"(",
"typeof",
"schema",
"===",
"'object'",
")",
"{",
"return",
"_mapObject",
"(",
"data",
",",
"schema",
",",
"options",
")",
";",
"}",
"return",
"schema",
";",
"}"
] | Returns a new object with its new aspect given by the schema
@param data Object to map
@param schema Fields to map
@param options Options
@returns {*}
@private | [
"Returns",
"a",
"new",
"object",
"with",
"its",
"new",
"aspect",
"given",
"by",
"the",
"schema"
] | 88e21a45350e7204f4102e7186c5beaa8753bd7f | https://github.com/MD4/potato-masher/blob/88e21a45350e7204f4102e7186c5beaa8753bd7f/lib/map.js#L41-L53 |
53,746 | MD4/potato-masher | lib/map.js | _removeMappedFields | function _removeMappedFields(mapping, path) {
if (typeof path === 'number') {
delete mapping[path];
return mapping;
}
var keys = path.split(_separator);
if (keys.length <= 1) {
delete mapping[path];
return mapping;
}
return _removeMappedFields(
mapping[path[0]],
keys
.slice(1)
.join(_separator)
);
} | javascript | function _removeMappedFields(mapping, path) {
if (typeof path === 'number') {
delete mapping[path];
return mapping;
}
var keys = path.split(_separator);
if (keys.length <= 1) {
delete mapping[path];
return mapping;
}
return _removeMappedFields(
mapping[path[0]],
keys
.slice(1)
.join(_separator)
);
} | [
"function",
"_removeMappedFields",
"(",
"mapping",
",",
"path",
")",
"{",
"if",
"(",
"typeof",
"path",
"===",
"'number'",
")",
"{",
"delete",
"mapping",
"[",
"path",
"]",
";",
"return",
"mapping",
";",
"}",
"var",
"keys",
"=",
"path",
".",
"split",
"(",
"_separator",
")",
";",
"if",
"(",
"keys",
".",
"length",
"<=",
"1",
")",
"{",
"delete",
"mapping",
"[",
"path",
"]",
";",
"return",
"mapping",
";",
"}",
"return",
"_removeMappedFields",
"(",
"mapping",
"[",
"path",
"[",
"0",
"]",
"]",
",",
"keys",
".",
"slice",
"(",
"1",
")",
".",
"join",
"(",
"_separator",
")",
")",
";",
"}"
] | !! Function with side effects !!
Removes given fields of a dataset
@param mapping Data to clean
@param path Path to field to delete
@returns {*}
@private | [
"!!",
"Function",
"with",
"side",
"effects",
"!!",
"Removes",
"given",
"fields",
"of",
"a",
"dataset"
] | 88e21a45350e7204f4102e7186c5beaa8753bd7f | https://github.com/MD4/potato-masher/blob/88e21a45350e7204f4102e7186c5beaa8753bd7f/lib/map.js#L93-L109 |
53,747 | MD4/potato-masher | lib/map.js | _getMappedFields | function _getMappedFields(schema) {
if (schema === undefined ||
schema === null) {
return;
}
if (schema instanceof Array) {
return schema
.reduce(function (memo, key) {
var mappedField = _getMappedFields(key);
if (mappedField !== undefined) {
memo = memo.concat(mappedField);
}
return memo;
}, []);
}
if (typeof schema === 'object') {
return Object
.keys(schema)
.reduce(function (memo, key) {
var mappedField = _getMappedFields(schema[key]);
if (mappedField !== undefined) {
memo = memo.concat(mappedField);
}
return memo;
}, []);
}
if (typeof schema === 'string' ||
typeof schema === 'number') {
return schema;
}
} | javascript | function _getMappedFields(schema) {
if (schema === undefined ||
schema === null) {
return;
}
if (schema instanceof Array) {
return schema
.reduce(function (memo, key) {
var mappedField = _getMappedFields(key);
if (mappedField !== undefined) {
memo = memo.concat(mappedField);
}
return memo;
}, []);
}
if (typeof schema === 'object') {
return Object
.keys(schema)
.reduce(function (memo, key) {
var mappedField = _getMappedFields(schema[key]);
if (mappedField !== undefined) {
memo = memo.concat(mappedField);
}
return memo;
}, []);
}
if (typeof schema === 'string' ||
typeof schema === 'number') {
return schema;
}
} | [
"function",
"_getMappedFields",
"(",
"schema",
")",
"{",
"if",
"(",
"schema",
"===",
"undefined",
"||",
"schema",
"===",
"null",
")",
"{",
"return",
";",
"}",
"if",
"(",
"schema",
"instanceof",
"Array",
")",
"{",
"return",
"schema",
".",
"reduce",
"(",
"function",
"(",
"memo",
",",
"key",
")",
"{",
"var",
"mappedField",
"=",
"_getMappedFields",
"(",
"key",
")",
";",
"if",
"(",
"mappedField",
"!==",
"undefined",
")",
"{",
"memo",
"=",
"memo",
".",
"concat",
"(",
"mappedField",
")",
";",
"}",
"return",
"memo",
";",
"}",
",",
"[",
"]",
")",
";",
"}",
"if",
"(",
"typeof",
"schema",
"===",
"'object'",
")",
"{",
"return",
"Object",
".",
"keys",
"(",
"schema",
")",
".",
"reduce",
"(",
"function",
"(",
"memo",
",",
"key",
")",
"{",
"var",
"mappedField",
"=",
"_getMappedFields",
"(",
"schema",
"[",
"key",
"]",
")",
";",
"if",
"(",
"mappedField",
"!==",
"undefined",
")",
"{",
"memo",
"=",
"memo",
".",
"concat",
"(",
"mappedField",
")",
";",
"}",
"return",
"memo",
";",
"}",
",",
"[",
"]",
")",
";",
"}",
"if",
"(",
"typeof",
"schema",
"===",
"'string'",
"||",
"typeof",
"schema",
"===",
"'number'",
")",
"{",
"return",
"schema",
";",
"}",
"}"
] | Returns the fields which are used in the final object
@param schema Target schema
@returns {*}
@private | [
"Returns",
"the",
"fields",
"which",
"are",
"used",
"in",
"the",
"final",
"object"
] | 88e21a45350e7204f4102e7186c5beaa8753bd7f | https://github.com/MD4/potato-masher/blob/88e21a45350e7204f4102e7186c5beaa8753bd7f/lib/map.js#L117-L147 |
53,748 | MD4/potato-masher | lib/map.js | _mapArray | function _mapArray(data, schema, options) {
var base = [];
if (data instanceof Array && options.keep) {
base = _clone(data);
}
if (typeof data === 'object' && options.keep) {
base = Object
.keys(data)
.map(function(key) {
return data[key];
});
}
return schema
.reduce(function (memo, nestedSchema) {
memo.push(_mapDataValue(data, nestedSchema));
return memo;
}, base);
} | javascript | function _mapArray(data, schema, options) {
var base = [];
if (data instanceof Array && options.keep) {
base = _clone(data);
}
if (typeof data === 'object' && options.keep) {
base = Object
.keys(data)
.map(function(key) {
return data[key];
});
}
return schema
.reduce(function (memo, nestedSchema) {
memo.push(_mapDataValue(data, nestedSchema));
return memo;
}, base);
} | [
"function",
"_mapArray",
"(",
"data",
",",
"schema",
",",
"options",
")",
"{",
"var",
"base",
"=",
"[",
"]",
";",
"if",
"(",
"data",
"instanceof",
"Array",
"&&",
"options",
".",
"keep",
")",
"{",
"base",
"=",
"_clone",
"(",
"data",
")",
";",
"}",
"if",
"(",
"typeof",
"data",
"===",
"'object'",
"&&",
"options",
".",
"keep",
")",
"{",
"base",
"=",
"Object",
".",
"keys",
"(",
"data",
")",
".",
"map",
"(",
"function",
"(",
"key",
")",
"{",
"return",
"data",
"[",
"key",
"]",
";",
"}",
")",
";",
"}",
"return",
"schema",
".",
"reduce",
"(",
"function",
"(",
"memo",
",",
"nestedSchema",
")",
"{",
"memo",
".",
"push",
"(",
"_mapDataValue",
"(",
"data",
",",
"nestedSchema",
")",
")",
";",
"return",
"memo",
";",
"}",
",",
"base",
")",
";",
"}"
] | Returns a new object with its new aspect from an array schema
@param data Object to map
@param schema Fields to map
@param options Options
@returns {*}
@private | [
"Returns",
"a",
"new",
"object",
"with",
"its",
"new",
"aspect",
"from",
"an",
"array",
"schema"
] | 88e21a45350e7204f4102e7186c5beaa8753bd7f | https://github.com/MD4/potato-masher/blob/88e21a45350e7204f4102e7186c5beaa8753bd7f/lib/map.js#L157-L174 |
53,749 | MD4/potato-masher | lib/map.js | _mapObject | function _mapObject(data, schema, options) {
return Object
.keys(schema)
.reduce(function (memo, key) {
memo[key] = _mapDataValue(data, schema[key]);
return memo;
}, options.keep ? _clone(data) : {});
} | javascript | function _mapObject(data, schema, options) {
return Object
.keys(schema)
.reduce(function (memo, key) {
memo[key] = _mapDataValue(data, schema[key]);
return memo;
}, options.keep ? _clone(data) : {});
} | [
"function",
"_mapObject",
"(",
"data",
",",
"schema",
",",
"options",
")",
"{",
"return",
"Object",
".",
"keys",
"(",
"schema",
")",
".",
"reduce",
"(",
"function",
"(",
"memo",
",",
"key",
")",
"{",
"memo",
"[",
"key",
"]",
"=",
"_mapDataValue",
"(",
"data",
",",
"schema",
"[",
"key",
"]",
")",
";",
"return",
"memo",
";",
"}",
",",
"options",
".",
"keep",
"?",
"_clone",
"(",
"data",
")",
":",
"{",
"}",
")",
";",
"}"
] | Returns a new object with its new aspect from an object schema
@param data Object to map
@param schema Fields to map
@param options Options
@returns {*}
@private | [
"Returns",
"a",
"new",
"object",
"with",
"its",
"new",
"aspect",
"from",
"an",
"object",
"schema"
] | 88e21a45350e7204f4102e7186c5beaa8753bd7f | https://github.com/MD4/potato-masher/blob/88e21a45350e7204f4102e7186c5beaa8753bd7f/lib/map.js#L184-L191 |
53,750 | MD4/potato-masher | lib/map.js | _mapDataValue | function _mapDataValue(data, nestedSchema) {
if (typeof nestedSchema === 'function') {
return nestedSchema.apply(data);
} else if (typeof nestedSchema === 'object') {
return _map(data, nestedSchema);
} else {
return _getDataValue(data, nestedSchema);
}
} | javascript | function _mapDataValue(data, nestedSchema) {
if (typeof nestedSchema === 'function') {
return nestedSchema.apply(data);
} else if (typeof nestedSchema === 'object') {
return _map(data, nestedSchema);
} else {
return _getDataValue(data, nestedSchema);
}
} | [
"function",
"_mapDataValue",
"(",
"data",
",",
"nestedSchema",
")",
"{",
"if",
"(",
"typeof",
"nestedSchema",
"===",
"'function'",
")",
"{",
"return",
"nestedSchema",
".",
"apply",
"(",
"data",
")",
";",
"}",
"else",
"if",
"(",
"typeof",
"nestedSchema",
"===",
"'object'",
")",
"{",
"return",
"_map",
"(",
"data",
",",
"nestedSchema",
")",
";",
"}",
"else",
"{",
"return",
"_getDataValue",
"(",
"data",
",",
"nestedSchema",
")",
";",
"}",
"}"
] | Returns the value of an object from a nested schema
@param data Object to map
@param nestedSchema Path to value, function to execute or nested schema
@returns {*}
@private | [
"Returns",
"the",
"value",
"of",
"an",
"object",
"from",
"a",
"nested",
"schema"
] | 88e21a45350e7204f4102e7186c5beaa8753bd7f | https://github.com/MD4/potato-masher/blob/88e21a45350e7204f4102e7186c5beaa8753bd7f/lib/map.js#L200-L208 |
53,751 | MD4/potato-masher | lib/map.js | _getDataValue | function _getDataValue(data, path) {
if (data === undefined) {
return undefined;
}
if (typeof path === 'number') {
return data[path];
}
if (typeof path === 'string') {
var keys = path.split(_separator);
if (keys.length <= 1) {
return data[keys[0]];
}
return _getDataValue(
data[keys[0]],
keys
.slice(1)
.join(_separator)
);
}
return undefined;
} | javascript | function _getDataValue(data, path) {
if (data === undefined) {
return undefined;
}
if (typeof path === 'number') {
return data[path];
}
if (typeof path === 'string') {
var keys = path.split(_separator);
if (keys.length <= 1) {
return data[keys[0]];
}
return _getDataValue(
data[keys[0]],
keys
.slice(1)
.join(_separator)
);
}
return undefined;
} | [
"function",
"_getDataValue",
"(",
"data",
",",
"path",
")",
"{",
"if",
"(",
"data",
"===",
"undefined",
")",
"{",
"return",
"undefined",
";",
"}",
"if",
"(",
"typeof",
"path",
"===",
"'number'",
")",
"{",
"return",
"data",
"[",
"path",
"]",
";",
"}",
"if",
"(",
"typeof",
"path",
"===",
"'string'",
")",
"{",
"var",
"keys",
"=",
"path",
".",
"split",
"(",
"_separator",
")",
";",
"if",
"(",
"keys",
".",
"length",
"<=",
"1",
")",
"{",
"return",
"data",
"[",
"keys",
"[",
"0",
"]",
"]",
";",
"}",
"return",
"_getDataValue",
"(",
"data",
"[",
"keys",
"[",
"0",
"]",
"]",
",",
"keys",
".",
"slice",
"(",
"1",
")",
".",
"join",
"(",
"_separator",
")",
")",
";",
"}",
"return",
"undefined",
";",
"}"
] | Returns the value of an object from its path
@param data Object to map
@param path Path to value in object
@returns {*}
@private | [
"Returns",
"the",
"value",
"of",
"an",
"object",
"from",
"its",
"path"
] | 88e21a45350e7204f4102e7186c5beaa8753bd7f | https://github.com/MD4/potato-masher/blob/88e21a45350e7204f4102e7186c5beaa8753bd7f/lib/map.js#L217-L237 |
53,752 | linyngfly/omelo | lib/server/server.js | function (app) {
let p = pathUtil.getCronPath(app.getBase(), app.getServerType());
if (p) {
return Loader.load(p, app);
}
} | javascript | function (app) {
let p = pathUtil.getCronPath(app.getBase(), app.getServerType());
if (p) {
return Loader.load(p, app);
}
} | [
"function",
"(",
"app",
")",
"{",
"let",
"p",
"=",
"pathUtil",
".",
"getCronPath",
"(",
"app",
".",
"getBase",
"(",
")",
",",
"app",
".",
"getServerType",
"(",
")",
")",
";",
"if",
"(",
"p",
")",
"{",
"return",
"Loader",
".",
"load",
"(",
"p",
",",
"app",
")",
";",
"}",
"}"
] | Load cron handlers from current application | [
"Load",
"cron",
"handlers",
"from",
"current",
"application"
] | fb5f79fa31c69de36bd1c370bad5edfa753ca601 | https://github.com/linyngfly/omelo/blob/fb5f79fa31c69de36bd1c370bad5edfa753ca601/lib/server/server.js#L194-L199 |
|
53,753 | linyngfly/omelo | lib/server/server.js | function (server, app) {
let env = app.get(Constants.RESERVED.ENV);
let p = path.join(app.getBase(), app.get(Constants.RESERVED.SERVICE_PATH), Constants.FILEPATH.CRON);
if (!fs.existsSync(p)) {
p = path.join(app.getBase(), Constants.FILEPATH.CONFIG_DIR, env, path.basename(Constants.FILEPATH.CRON));
if (!fs.existsSync(p)) {
return;
}
}
app.loadConfigBaseApp(Constants.RESERVED.CRONS, app.get(Constants.RESERVED.SERVICE_PATH), Constants.FILEPATH.CRON);
let crons = app.get(Constants.RESERVED.CRONS);
for (let serverType in crons) {
if (app.serverType === serverType) {
let list = crons[serverType];
for (let i = 0; i < list.length; i++) {
if (!list[i].serverId) {
checkAndAdd(list[i], server.crons, server);
} else {
if (app.serverId === list[i].serverId) {
checkAndAdd(list[i], server.crons, server);
}
}
}
}
}
} | javascript | function (server, app) {
let env = app.get(Constants.RESERVED.ENV);
let p = path.join(app.getBase(), app.get(Constants.RESERVED.SERVICE_PATH), Constants.FILEPATH.CRON);
if (!fs.existsSync(p)) {
p = path.join(app.getBase(), Constants.FILEPATH.CONFIG_DIR, env, path.basename(Constants.FILEPATH.CRON));
if (!fs.existsSync(p)) {
return;
}
}
app.loadConfigBaseApp(Constants.RESERVED.CRONS, app.get(Constants.RESERVED.SERVICE_PATH), Constants.FILEPATH.CRON);
let crons = app.get(Constants.RESERVED.CRONS);
for (let serverType in crons) {
if (app.serverType === serverType) {
let list = crons[serverType];
for (let i = 0; i < list.length; i++) {
if (!list[i].serverId) {
checkAndAdd(list[i], server.crons, server);
} else {
if (app.serverId === list[i].serverId) {
checkAndAdd(list[i], server.crons, server);
}
}
}
}
}
} | [
"function",
"(",
"server",
",",
"app",
")",
"{",
"let",
"env",
"=",
"app",
".",
"get",
"(",
"Constants",
".",
"RESERVED",
".",
"ENV",
")",
";",
"let",
"p",
"=",
"path",
".",
"join",
"(",
"app",
".",
"getBase",
"(",
")",
",",
"app",
".",
"get",
"(",
"Constants",
".",
"RESERVED",
".",
"SERVICE_PATH",
")",
",",
"Constants",
".",
"FILEPATH",
".",
"CRON",
")",
";",
"if",
"(",
"!",
"fs",
".",
"existsSync",
"(",
"p",
")",
")",
"{",
"p",
"=",
"path",
".",
"join",
"(",
"app",
".",
"getBase",
"(",
")",
",",
"Constants",
".",
"FILEPATH",
".",
"CONFIG_DIR",
",",
"env",
",",
"path",
".",
"basename",
"(",
"Constants",
".",
"FILEPATH",
".",
"CRON",
")",
")",
";",
"if",
"(",
"!",
"fs",
".",
"existsSync",
"(",
"p",
")",
")",
"{",
"return",
";",
"}",
"}",
"app",
".",
"loadConfigBaseApp",
"(",
"Constants",
".",
"RESERVED",
".",
"CRONS",
",",
"app",
".",
"get",
"(",
"Constants",
".",
"RESERVED",
".",
"SERVICE_PATH",
")",
",",
"Constants",
".",
"FILEPATH",
".",
"CRON",
")",
";",
"let",
"crons",
"=",
"app",
".",
"get",
"(",
"Constants",
".",
"RESERVED",
".",
"CRONS",
")",
";",
"for",
"(",
"let",
"serverType",
"in",
"crons",
")",
"{",
"if",
"(",
"app",
".",
"serverType",
"===",
"serverType",
")",
"{",
"let",
"list",
"=",
"crons",
"[",
"serverType",
"]",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"list",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"list",
"[",
"i",
"]",
".",
"serverId",
")",
"{",
"checkAndAdd",
"(",
"list",
"[",
"i",
"]",
",",
"server",
".",
"crons",
",",
"server",
")",
";",
"}",
"else",
"{",
"if",
"(",
"app",
".",
"serverId",
"===",
"list",
"[",
"i",
"]",
".",
"serverId",
")",
"{",
"checkAndAdd",
"(",
"list",
"[",
"i",
"]",
",",
"server",
".",
"crons",
",",
"server",
")",
";",
"}",
"}",
"}",
"}",
"}",
"}"
] | Load crons from configure file | [
"Load",
"crons",
"from",
"configure",
"file"
] | fb5f79fa31c69de36bd1c370bad5edfa753ca601 | https://github.com/linyngfly/omelo/blob/fb5f79fa31c69de36bd1c370bad5edfa753ca601/lib/server/server.js#L204-L229 |
|
53,754 | linyngfly/omelo | lib/server/server.js | function (isGlobal, server, err, msg, session, resp, opts, cb) {
let fm;
if (isGlobal) {
fm = server.globalFilterService;
} else {
fm = server.filterService;
}
if (fm) {
if (isGlobal) {
fm.afterFilter(err, msg, session, resp, function () {
// do nothing
});
} else {
fm.afterFilter(err, msg, session, resp, function (err) {
cb(err, resp, opts);
});
}
}
} | javascript | function (isGlobal, server, err, msg, session, resp, opts, cb) {
let fm;
if (isGlobal) {
fm = server.globalFilterService;
} else {
fm = server.filterService;
}
if (fm) {
if (isGlobal) {
fm.afterFilter(err, msg, session, resp, function () {
// do nothing
});
} else {
fm.afterFilter(err, msg, session, resp, function (err) {
cb(err, resp, opts);
});
}
}
} | [
"function",
"(",
"isGlobal",
",",
"server",
",",
"err",
",",
"msg",
",",
"session",
",",
"resp",
",",
"opts",
",",
"cb",
")",
"{",
"let",
"fm",
";",
"if",
"(",
"isGlobal",
")",
"{",
"fm",
"=",
"server",
".",
"globalFilterService",
";",
"}",
"else",
"{",
"fm",
"=",
"server",
".",
"filterService",
";",
"}",
"if",
"(",
"fm",
")",
"{",
"if",
"(",
"isGlobal",
")",
"{",
"fm",
".",
"afterFilter",
"(",
"err",
",",
"msg",
",",
"session",
",",
"resp",
",",
"function",
"(",
")",
"{",
"// do nothing",
"}",
")",
";",
"}",
"else",
"{",
"fm",
".",
"afterFilter",
"(",
"err",
",",
"msg",
",",
"session",
",",
"resp",
",",
"function",
"(",
"err",
")",
"{",
"cb",
"(",
"err",
",",
"resp",
",",
"opts",
")",
";",
"}",
")",
";",
"}",
"}",
"}"
] | Fire after filter chain if have | [
"Fire",
"after",
"filter",
"chain",
"if",
"have"
] | fb5f79fa31c69de36bd1c370bad5edfa753ca601 | https://github.com/linyngfly/omelo/blob/fb5f79fa31c69de36bd1c370bad5edfa753ca601/lib/server/server.js#L251-L269 |
|
53,755 | linyngfly/omelo | lib/server/server.js | function (isGlobal, server, err, msg, session, resp, opts, cb) {
let handler;
if (isGlobal) {
handler = server.app.get(Constants.RESERVED.GLOBAL_ERROR_HANDLER);
} else {
handler = server.app.get(Constants.RESERVED.ERROR_HANDLER);
}
if (!handler) {
logger.debug('no default error handler to resolve unknown exception. ' + err.stack);
utils.invokeCallback(cb, err, resp, opts);
} else {
if (handler.length === 5) {
handler(err, msg, resp, session, cb);
} else {
handler(err, msg, resp, session, opts, cb);
}
}
} | javascript | function (isGlobal, server, err, msg, session, resp, opts, cb) {
let handler;
if (isGlobal) {
handler = server.app.get(Constants.RESERVED.GLOBAL_ERROR_HANDLER);
} else {
handler = server.app.get(Constants.RESERVED.ERROR_HANDLER);
}
if (!handler) {
logger.debug('no default error handler to resolve unknown exception. ' + err.stack);
utils.invokeCallback(cb, err, resp, opts);
} else {
if (handler.length === 5) {
handler(err, msg, resp, session, cb);
} else {
handler(err, msg, resp, session, opts, cb);
}
}
} | [
"function",
"(",
"isGlobal",
",",
"server",
",",
"err",
",",
"msg",
",",
"session",
",",
"resp",
",",
"opts",
",",
"cb",
")",
"{",
"let",
"handler",
";",
"if",
"(",
"isGlobal",
")",
"{",
"handler",
"=",
"server",
".",
"app",
".",
"get",
"(",
"Constants",
".",
"RESERVED",
".",
"GLOBAL_ERROR_HANDLER",
")",
";",
"}",
"else",
"{",
"handler",
"=",
"server",
".",
"app",
".",
"get",
"(",
"Constants",
".",
"RESERVED",
".",
"ERROR_HANDLER",
")",
";",
"}",
"if",
"(",
"!",
"handler",
")",
"{",
"logger",
".",
"debug",
"(",
"'no default error handler to resolve unknown exception. '",
"+",
"err",
".",
"stack",
")",
";",
"utils",
".",
"invokeCallback",
"(",
"cb",
",",
"err",
",",
"resp",
",",
"opts",
")",
";",
"}",
"else",
"{",
"if",
"(",
"handler",
".",
"length",
"===",
"5",
")",
"{",
"handler",
"(",
"err",
",",
"msg",
",",
"resp",
",",
"session",
",",
"cb",
")",
";",
"}",
"else",
"{",
"handler",
"(",
"err",
",",
"msg",
",",
"resp",
",",
"session",
",",
"opts",
",",
"cb",
")",
";",
"}",
"}",
"}"
] | pass err to the global error handler if specified | [
"pass",
"err",
"to",
"the",
"global",
"error",
"handler",
"if",
"specified"
] | fb5f79fa31c69de36bd1c370bad5edfa753ca601 | https://github.com/linyngfly/omelo/blob/fb5f79fa31c69de36bd1c370bad5edfa753ca601/lib/server/server.js#L274-L291 |
|
53,756 | linyngfly/omelo | lib/server/server.js | function (route) {
if (!route) {
return null;
}
let ts = route.split('.');
if (ts.length !== 3) {
return null;
}
return {
route: route,
serverType: ts[0],
handler: ts[1],
method: ts[2]
};
} | javascript | function (route) {
if (!route) {
return null;
}
let ts = route.split('.');
if (ts.length !== 3) {
return null;
}
return {
route: route,
serverType: ts[0],
handler: ts[1],
method: ts[2]
};
} | [
"function",
"(",
"route",
")",
"{",
"if",
"(",
"!",
"route",
")",
"{",
"return",
"null",
";",
"}",
"let",
"ts",
"=",
"route",
".",
"split",
"(",
"'.'",
")",
";",
"if",
"(",
"ts",
".",
"length",
"!==",
"3",
")",
"{",
"return",
"null",
";",
"}",
"return",
"{",
"route",
":",
"route",
",",
"serverType",
":",
"ts",
"[",
"0",
"]",
",",
"handler",
":",
"ts",
"[",
"1",
"]",
",",
"method",
":",
"ts",
"[",
"2",
"]",
"}",
";",
"}"
] | Parse route string.
@param {String} route route string, such as: serverName.handlerName.methodName
@return {Object} parse result object or null for illeagle route string | [
"Parse",
"route",
"string",
"."
] | fb5f79fa31c69de36bd1c370bad5edfa753ca601 | https://github.com/linyngfly/omelo/blob/fb5f79fa31c69de36bd1c370bad5edfa753ca601/lib/server/server.js#L313-L328 |
|
53,757 | mbroadst/rethunk | lib/metadata.js | Metadata | function Metadata(resolve, reject, query, options) {
this.resolve = this._wrapResolveForProfile(resolve);
this.reject = reject;
this.query = query; // The query in case we have to build a backtrace
this.options = options || {};
this.cursor = false;
} | javascript | function Metadata(resolve, reject, query, options) {
this.resolve = this._wrapResolveForProfile(resolve);
this.reject = reject;
this.query = query; // The query in case we have to build a backtrace
this.options = options || {};
this.cursor = false;
} | [
"function",
"Metadata",
"(",
"resolve",
",",
"reject",
",",
"query",
",",
"options",
")",
"{",
"this",
".",
"resolve",
"=",
"this",
".",
"_wrapResolveForProfile",
"(",
"resolve",
")",
";",
"this",
".",
"reject",
"=",
"reject",
";",
"this",
".",
"query",
"=",
"query",
";",
"// The query in case we have to build a backtrace",
"this",
".",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"this",
".",
"cursor",
"=",
"false",
";",
"}"
] | Metadata we keep per query | [
"Metadata",
"we",
"keep",
"per",
"query"
] | 48cad0fa139883f49489b93afbb87502532a876a | https://github.com/mbroadst/rethunk/blob/48cad0fa139883f49489b93afbb87502532a876a/lib/metadata.js#L3-L9 |
53,758 | iolo/express-toybox | server.js | start | function start(app, config, callback) {
if (httpServer) {
DEBUG && debug('***ignore*** http server is already running!');
callback && callback(false);
return httpServer;
}
config = _.merge({}, DEF_CONFIG, config);
DEBUG && debug('start http server http://' + config.host + ':' + config.port);
httpServer = http.createServer(app).listen(config.port, config.host, callback);
httpServer.on('close', function () {
DEBUG && debug('close http server');
httpServer = null;
});
process.on('exit', function () {
stop();
});
if (process.env.NODE_ENV === 'production') {
process.on('uncaughtException', function (err) {
console.error('***uncaughtException***', err);
});
}
return httpServer;
} | javascript | function start(app, config, callback) {
if (httpServer) {
DEBUG && debug('***ignore*** http server is already running!');
callback && callback(false);
return httpServer;
}
config = _.merge({}, DEF_CONFIG, config);
DEBUG && debug('start http server http://' + config.host + ':' + config.port);
httpServer = http.createServer(app).listen(config.port, config.host, callback);
httpServer.on('close', function () {
DEBUG && debug('close http server');
httpServer = null;
});
process.on('exit', function () {
stop();
});
if (process.env.NODE_ENV === 'production') {
process.on('uncaughtException', function (err) {
console.error('***uncaughtException***', err);
});
}
return httpServer;
} | [
"function",
"start",
"(",
"app",
",",
"config",
",",
"callback",
")",
"{",
"if",
"(",
"httpServer",
")",
"{",
"DEBUG",
"&&",
"debug",
"(",
"'***ignore*** http server is already running!'",
")",
";",
"callback",
"&&",
"callback",
"(",
"false",
")",
";",
"return",
"httpServer",
";",
"}",
"config",
"=",
"_",
".",
"merge",
"(",
"{",
"}",
",",
"DEF_CONFIG",
",",
"config",
")",
";",
"DEBUG",
"&&",
"debug",
"(",
"'start http server http://'",
"+",
"config",
".",
"host",
"+",
"':'",
"+",
"config",
".",
"port",
")",
";",
"httpServer",
"=",
"http",
".",
"createServer",
"(",
"app",
")",
".",
"listen",
"(",
"config",
".",
"port",
",",
"config",
".",
"host",
",",
"callback",
")",
";",
"httpServer",
".",
"on",
"(",
"'close'",
",",
"function",
"(",
")",
"{",
"DEBUG",
"&&",
"debug",
"(",
"'close http server'",
")",
";",
"httpServer",
"=",
"null",
";",
"}",
")",
";",
"process",
".",
"on",
"(",
"'exit'",
",",
"function",
"(",
")",
"{",
"stop",
"(",
")",
";",
"}",
")",
";",
"if",
"(",
"process",
".",
"env",
".",
"NODE_ENV",
"===",
"'production'",
")",
"{",
"process",
".",
"on",
"(",
"'uncaughtException'",
",",
"function",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"'***uncaughtException***'",
",",
"err",
")",
";",
"}",
")",
";",
"}",
"return",
"httpServer",
";",
"}"
] | start http server.
@param {*} app request listener. might be express(or connect) application instance.
@param {*} [config] http server configurations
@param {String} [config.host='localhost']
@param {Number} [config.port=3000]
@param {Function(http.Server)} callback
@returns {http.Server} http server instance | [
"start",
"http",
"server",
"."
] | c375a1388cfc167017e8dcd2325e71ca86ccb994 | https://github.com/iolo/express-toybox/blob/c375a1388cfc167017e8dcd2325e71ca86ccb994/server.js#L26-L54 |
53,759 | iolo/express-toybox | server.js | stop | function stop(callback) {
if (httpServer) {
DEBUG && debug('stop http server');
try {
httpServer.close();
} catch (e) {
}
httpServer = null;
} else {
DEBUG && debug('***ignore*** http server is not running!');
}
callback && callback(false);
} | javascript | function stop(callback) {
if (httpServer) {
DEBUG && debug('stop http server');
try {
httpServer.close();
} catch (e) {
}
httpServer = null;
} else {
DEBUG && debug('***ignore*** http server is not running!');
}
callback && callback(false);
} | [
"function",
"stop",
"(",
"callback",
")",
"{",
"if",
"(",
"httpServer",
")",
"{",
"DEBUG",
"&&",
"debug",
"(",
"'stop http server'",
")",
";",
"try",
"{",
"httpServer",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"}",
"httpServer",
"=",
"null",
";",
"}",
"else",
"{",
"DEBUG",
"&&",
"debug",
"(",
"'***ignore*** http server is not running!'",
")",
";",
"}",
"callback",
"&&",
"callback",
"(",
"false",
")",
";",
"}"
] | stop http server
@param {Function} callback | [
"stop",
"http",
"server"
] | c375a1388cfc167017e8dcd2325e71ca86ccb994 | https://github.com/iolo/express-toybox/blob/c375a1388cfc167017e8dcd2325e71ca86ccb994/server.js#L61-L73 |
53,760 | myndzi/should-eventually | index.js | function (resolved, val) {
var should = (negate ?
(new Assertion(val)).not :
(new Assertion(val))
);
if (storedAssertions[0][0] !== 'throw' && !resolved) {
throw val;
}
var result = storedAssertions.reduce(function (accum, cur) {
// 'throw' must immediately follow 'eventually' if it is used
if (cur[0] === 'throw') {
// should.throw is a special case; it expects a function
// that it will then call to discern whether an error was thrown
// or not, but we have a (potentially) rejected value of a promise,
// so we need to wrap that value in a function for should.throw to call
var obj = accum.obj;
accum.obj = function () {
if (resolved) { return obj; }
else { throw obj; }
};
}
// this block is separated from the above intentionally;
// the above deals with putting the data in the expected format,
// while this deals with whether or not to throw an error
if (cur[0] === 'throw') {
// these conditions are acceptable:
// resolved === true && negate === true - promise succeeded, throw check is negated
// resolved === false && negate !== true - promise rejected, throw check is not negated
if (resolved === !!accum.negate) {
caught = true;
} else {
throw new AssertionError({
message: 'Expected promise to be ' + (negate ? 'resolved' : 'rejected') +
' but instead it was ' + (resolved ? 'resolved' : 'rejected') + ' with ' + inspect(val),
actual: val
});
}
}
if (cur.length === 1) {
// assertion was a getter, apply to current value
return accum[cur[0]];
} else {
// assertion was a function, apply to current value
return accum[cur[0]].apply(accum, cur[1]);
}
}, should); // call .should on our resolved value to begin the assertion chain
if (!resolved && !caught) {
throw new AssertionError({
message: 'Promise was rejected unexpectedly with ' + inspect(val),
actual: val
});
}
return result;
} | javascript | function (resolved, val) {
var should = (negate ?
(new Assertion(val)).not :
(new Assertion(val))
);
if (storedAssertions[0][0] !== 'throw' && !resolved) {
throw val;
}
var result = storedAssertions.reduce(function (accum, cur) {
// 'throw' must immediately follow 'eventually' if it is used
if (cur[0] === 'throw') {
// should.throw is a special case; it expects a function
// that it will then call to discern whether an error was thrown
// or not, but we have a (potentially) rejected value of a promise,
// so we need to wrap that value in a function for should.throw to call
var obj = accum.obj;
accum.obj = function () {
if (resolved) { return obj; }
else { throw obj; }
};
}
// this block is separated from the above intentionally;
// the above deals with putting the data in the expected format,
// while this deals with whether or not to throw an error
if (cur[0] === 'throw') {
// these conditions are acceptable:
// resolved === true && negate === true - promise succeeded, throw check is negated
// resolved === false && negate !== true - promise rejected, throw check is not negated
if (resolved === !!accum.negate) {
caught = true;
} else {
throw new AssertionError({
message: 'Expected promise to be ' + (negate ? 'resolved' : 'rejected') +
' but instead it was ' + (resolved ? 'resolved' : 'rejected') + ' with ' + inspect(val),
actual: val
});
}
}
if (cur.length === 1) {
// assertion was a getter, apply to current value
return accum[cur[0]];
} else {
// assertion was a function, apply to current value
return accum[cur[0]].apply(accum, cur[1]);
}
}, should); // call .should on our resolved value to begin the assertion chain
if (!resolved && !caught) {
throw new AssertionError({
message: 'Promise was rejected unexpectedly with ' + inspect(val),
actual: val
});
}
return result;
} | [
"function",
"(",
"resolved",
",",
"val",
")",
"{",
"var",
"should",
"=",
"(",
"negate",
"?",
"(",
"new",
"Assertion",
"(",
"val",
")",
")",
".",
"not",
":",
"(",
"new",
"Assertion",
"(",
"val",
")",
")",
")",
";",
"if",
"(",
"storedAssertions",
"[",
"0",
"]",
"[",
"0",
"]",
"!==",
"'throw'",
"&&",
"!",
"resolved",
")",
"{",
"throw",
"val",
";",
"}",
"var",
"result",
"=",
"storedAssertions",
".",
"reduce",
"(",
"function",
"(",
"accum",
",",
"cur",
")",
"{",
"// 'throw' must immediately follow 'eventually' if it is used",
"if",
"(",
"cur",
"[",
"0",
"]",
"===",
"'throw'",
")",
"{",
"// should.throw is a special case; it expects a function",
"// that it will then call to discern whether an error was thrown",
"// or not, but we have a (potentially) rejected value of a promise,",
"// so we need to wrap that value in a function for should.throw to call",
"var",
"obj",
"=",
"accum",
".",
"obj",
";",
"accum",
".",
"obj",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"resolved",
")",
"{",
"return",
"obj",
";",
"}",
"else",
"{",
"throw",
"obj",
";",
"}",
"}",
";",
"}",
"// this block is separated from the above intentionally;",
"// the above deals with putting the data in the expected format,",
"// while this deals with whether or not to throw an error",
"if",
"(",
"cur",
"[",
"0",
"]",
"===",
"'throw'",
")",
"{",
"// these conditions are acceptable:",
"// resolved === true && negate === true - promise succeeded, throw check is negated",
"// resolved === false && negate !== true - promise rejected, throw check is not negated",
"if",
"(",
"resolved",
"===",
"!",
"!",
"accum",
".",
"negate",
")",
"{",
"caught",
"=",
"true",
";",
"}",
"else",
"{",
"throw",
"new",
"AssertionError",
"(",
"{",
"message",
":",
"'Expected promise to be '",
"+",
"(",
"negate",
"?",
"'resolved'",
":",
"'rejected'",
")",
"+",
"' but instead it was '",
"+",
"(",
"resolved",
"?",
"'resolved'",
":",
"'rejected'",
")",
"+",
"' with '",
"+",
"inspect",
"(",
"val",
")",
",",
"actual",
":",
"val",
"}",
")",
";",
"}",
"}",
"if",
"(",
"cur",
".",
"length",
"===",
"1",
")",
"{",
"// assertion was a getter, apply to current value",
"return",
"accum",
"[",
"cur",
"[",
"0",
"]",
"]",
";",
"}",
"else",
"{",
"// assertion was a function, apply to current value",
"return",
"accum",
"[",
"cur",
"[",
"0",
"]",
"]",
".",
"apply",
"(",
"accum",
",",
"cur",
"[",
"1",
"]",
")",
";",
"}",
"}",
",",
"should",
")",
";",
"// call .should on our resolved value to begin the assertion chain",
"if",
"(",
"!",
"resolved",
"&&",
"!",
"caught",
")",
"{",
"throw",
"new",
"AssertionError",
"(",
"{",
"message",
":",
"'Promise was rejected unexpectedly with '",
"+",
"inspect",
"(",
"val",
")",
",",
"actual",
":",
"val",
"}",
")",
";",
"}",
"return",
"result",
";",
"}"
] | this function will kick off the new chain of assertions on the setttled result of the promise | [
"this",
"function",
"will",
"kick",
"off",
"the",
"new",
"chain",
"of",
"assertions",
"on",
"the",
"setttled",
"result",
"of",
"the",
"promise"
] | 96abbae69f4ee46cda5864b0c59c1a570984ad42 | https://github.com/myndzi/should-eventually/blob/96abbae69f4ee46cda5864b0c59c1a570984ad42/index.js#L88-L146 |
|
53,761 | thommeo/generator-fe | app/templates/foundation/js/foundation/foundation.clearing.js | function () {
var self = this;
$(this.scope)
.on('click.fndtn.clearing', 'ul[data-clearing] li',
function (e, current, target) {
var current = current || $(this),
target = target || current,
next = current.next('li'),
settings = self.get_data(current.parent()),
image = $(e.target);
e.preventDefault();
if (!settings) self.init();
// if clearing is open and the current image is
// clicked, go to the next image in sequence
if (target.hasClass('visible')
&& current[0] === target[0]
&& next.length > 0 && self.is_open(current)) {
target = next;
image = target.find('img');
}
// set current and target to the clicked li if not otherwise defined.
self.open(image, current, target);
self.update_paddles(target);
})
.on('click.fndtn.clearing', '.clearing-main-next',
function (e) { this.nav(e, 'next') }.bind(this))
.on('click.fndtn.clearing', '.clearing-main-prev',
function (e) { this.nav(e, 'prev') }.bind(this))
.on('click.fndtn.clearing', this.settings.close_selectors,
function (e) { Foundation.libs.clearing.close(e, this) })
.on('keydown.fndtn.clearing',
function (e) { this.keydown(e) }.bind(this));
$(window).on('resize.fndtn.clearing',
function () { this.resize() }.bind(this));
this.settings.init = true;
return this;
} | javascript | function () {
var self = this;
$(this.scope)
.on('click.fndtn.clearing', 'ul[data-clearing] li',
function (e, current, target) {
var current = current || $(this),
target = target || current,
next = current.next('li'),
settings = self.get_data(current.parent()),
image = $(e.target);
e.preventDefault();
if (!settings) self.init();
// if clearing is open and the current image is
// clicked, go to the next image in sequence
if (target.hasClass('visible')
&& current[0] === target[0]
&& next.length > 0 && self.is_open(current)) {
target = next;
image = target.find('img');
}
// set current and target to the clicked li if not otherwise defined.
self.open(image, current, target);
self.update_paddles(target);
})
.on('click.fndtn.clearing', '.clearing-main-next',
function (e) { this.nav(e, 'next') }.bind(this))
.on('click.fndtn.clearing', '.clearing-main-prev',
function (e) { this.nav(e, 'prev') }.bind(this))
.on('click.fndtn.clearing', this.settings.close_selectors,
function (e) { Foundation.libs.clearing.close(e, this) })
.on('keydown.fndtn.clearing',
function (e) { this.keydown(e) }.bind(this));
$(window).on('resize.fndtn.clearing',
function () { this.resize() }.bind(this));
this.settings.init = true;
return this;
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"$",
"(",
"this",
".",
"scope",
")",
".",
"on",
"(",
"'click.fndtn.clearing'",
",",
"'ul[data-clearing] li'",
",",
"function",
"(",
"e",
",",
"current",
",",
"target",
")",
"{",
"var",
"current",
"=",
"current",
"||",
"$",
"(",
"this",
")",
",",
"target",
"=",
"target",
"||",
"current",
",",
"next",
"=",
"current",
".",
"next",
"(",
"'li'",
")",
",",
"settings",
"=",
"self",
".",
"get_data",
"(",
"current",
".",
"parent",
"(",
")",
")",
",",
"image",
"=",
"$",
"(",
"e",
".",
"target",
")",
";",
"e",
".",
"preventDefault",
"(",
")",
";",
"if",
"(",
"!",
"settings",
")",
"self",
".",
"init",
"(",
")",
";",
"// if clearing is open and the current image is",
"// clicked, go to the next image in sequence",
"if",
"(",
"target",
".",
"hasClass",
"(",
"'visible'",
")",
"&&",
"current",
"[",
"0",
"]",
"===",
"target",
"[",
"0",
"]",
"&&",
"next",
".",
"length",
">",
"0",
"&&",
"self",
".",
"is_open",
"(",
"current",
")",
")",
"{",
"target",
"=",
"next",
";",
"image",
"=",
"target",
".",
"find",
"(",
"'img'",
")",
";",
"}",
"// set current and target to the clicked li if not otherwise defined.",
"self",
".",
"open",
"(",
"image",
",",
"current",
",",
"target",
")",
";",
"self",
".",
"update_paddles",
"(",
"target",
")",
";",
"}",
")",
".",
"on",
"(",
"'click.fndtn.clearing'",
",",
"'.clearing-main-next'",
",",
"function",
"(",
"e",
")",
"{",
"this",
".",
"nav",
"(",
"e",
",",
"'next'",
")",
"}",
".",
"bind",
"(",
"this",
")",
")",
".",
"on",
"(",
"'click.fndtn.clearing'",
",",
"'.clearing-main-prev'",
",",
"function",
"(",
"e",
")",
"{",
"this",
".",
"nav",
"(",
"e",
",",
"'prev'",
")",
"}",
".",
"bind",
"(",
"this",
")",
")",
".",
"on",
"(",
"'click.fndtn.clearing'",
",",
"this",
".",
"settings",
".",
"close_selectors",
",",
"function",
"(",
"e",
")",
"{",
"Foundation",
".",
"libs",
".",
"clearing",
".",
"close",
"(",
"e",
",",
"this",
")",
"}",
")",
".",
"on",
"(",
"'keydown.fndtn.clearing'",
",",
"function",
"(",
"e",
")",
"{",
"this",
".",
"keydown",
"(",
"e",
")",
"}",
".",
"bind",
"(",
"this",
")",
")",
";",
"$",
"(",
"window",
")",
".",
"on",
"(",
"'resize.fndtn.clearing'",
",",
"function",
"(",
")",
"{",
"this",
".",
"resize",
"(",
")",
"}",
".",
"bind",
"(",
"this",
")",
")",
";",
"this",
".",
"settings",
".",
"init",
"=",
"true",
";",
"return",
"this",
";",
"}"
] | event binding and initial setup | [
"event",
"binding",
"and",
"initial",
"setup"
] | 186d1464fcf628604ecb7f39e56312ee1b08415f | https://github.com/thommeo/generator-fe/blob/186d1464fcf628604ecb7f39e56312ee1b08415f/app/templates/foundation/js/foundation/foundation.clearing.js#L65-L108 |
|
53,762 | mattdesl/kami-mesh-buffer | index.js | Mesh | function Mesh(context, isStatic, numVerts, numIndices, vertexAttribs) {
//TODO: use options here...
if (!numVerts)
throw "numVerts not specified, must be > 0";
BaseObject.call(this, context);
this.gl = this.context.gl;
this.numVerts = null;
this.numIndices = null;
this.vertices = null;
this.indices = null;
this.vertexBuffer = null;
this.indexBuffer = null;
this.verticesDirty = true;
this.indicesDirty = true;
this.indexUsage = null;
this.vertexUsage = null;
/**
* @property
* @private
*/
this._vertexAttribs = null;
/**
* The stride for one vertex _in bytes_.
*
* @property {Number} vertexStride
*/
this.vertexStride = null;
this.numVerts = numVerts;
this.numIndices = numIndices || 0;
this.vertexUsage = isStatic ? this.gl.STATIC_DRAW : this.gl.DYNAMIC_DRAW;
this.indexUsage = isStatic ? this.gl.STATIC_DRAW : this.gl.DYNAMIC_DRAW;
this._vertexAttribs = vertexAttribs || [];
this.indicesDirty = true;
this.verticesDirty = true;
//determine the vertex stride based on given attributes
var totalNumComponents = 0;
for (var i=0; i<this._vertexAttribs.length; i++)
totalNumComponents += this._vertexAttribs[i].offsetCount;
this.vertexStride = totalNumComponents * 4; // in bytes
this.vertices = new Float32Array(this.numVerts);
this.indices = new Uint16Array(this.numIndices);
//add this VBO to the managed cache
this.context.addManagedObject(this);
this.create();
} | javascript | function Mesh(context, isStatic, numVerts, numIndices, vertexAttribs) {
//TODO: use options here...
if (!numVerts)
throw "numVerts not specified, must be > 0";
BaseObject.call(this, context);
this.gl = this.context.gl;
this.numVerts = null;
this.numIndices = null;
this.vertices = null;
this.indices = null;
this.vertexBuffer = null;
this.indexBuffer = null;
this.verticesDirty = true;
this.indicesDirty = true;
this.indexUsage = null;
this.vertexUsage = null;
/**
* @property
* @private
*/
this._vertexAttribs = null;
/**
* The stride for one vertex _in bytes_.
*
* @property {Number} vertexStride
*/
this.vertexStride = null;
this.numVerts = numVerts;
this.numIndices = numIndices || 0;
this.vertexUsage = isStatic ? this.gl.STATIC_DRAW : this.gl.DYNAMIC_DRAW;
this.indexUsage = isStatic ? this.gl.STATIC_DRAW : this.gl.DYNAMIC_DRAW;
this._vertexAttribs = vertexAttribs || [];
this.indicesDirty = true;
this.verticesDirty = true;
//determine the vertex stride based on given attributes
var totalNumComponents = 0;
for (var i=0; i<this._vertexAttribs.length; i++)
totalNumComponents += this._vertexAttribs[i].offsetCount;
this.vertexStride = totalNumComponents * 4; // in bytes
this.vertices = new Float32Array(this.numVerts);
this.indices = new Uint16Array(this.numIndices);
//add this VBO to the managed cache
this.context.addManagedObject(this);
this.create();
} | [
"function",
"Mesh",
"(",
"context",
",",
"isStatic",
",",
"numVerts",
",",
"numIndices",
",",
"vertexAttribs",
")",
"{",
"//TODO: use options here...",
"if",
"(",
"!",
"numVerts",
")",
"throw",
"\"numVerts not specified, must be > 0\"",
";",
"BaseObject",
".",
"call",
"(",
"this",
",",
"context",
")",
";",
"this",
".",
"gl",
"=",
"this",
".",
"context",
".",
"gl",
";",
"this",
".",
"numVerts",
"=",
"null",
";",
"this",
".",
"numIndices",
"=",
"null",
";",
"this",
".",
"vertices",
"=",
"null",
";",
"this",
".",
"indices",
"=",
"null",
";",
"this",
".",
"vertexBuffer",
"=",
"null",
";",
"this",
".",
"indexBuffer",
"=",
"null",
";",
"this",
".",
"verticesDirty",
"=",
"true",
";",
"this",
".",
"indicesDirty",
"=",
"true",
";",
"this",
".",
"indexUsage",
"=",
"null",
";",
"this",
".",
"vertexUsage",
"=",
"null",
";",
"/** \n\t\t * @property\n\t\t * @private\n\t\t */",
"this",
".",
"_vertexAttribs",
"=",
"null",
";",
"/** \n\t\t * The stride for one vertex _in bytes_. \n\t\t * \n\t\t * @property {Number} vertexStride\n\t\t */",
"this",
".",
"vertexStride",
"=",
"null",
";",
"this",
".",
"numVerts",
"=",
"numVerts",
";",
"this",
".",
"numIndices",
"=",
"numIndices",
"||",
"0",
";",
"this",
".",
"vertexUsage",
"=",
"isStatic",
"?",
"this",
".",
"gl",
".",
"STATIC_DRAW",
":",
"this",
".",
"gl",
".",
"DYNAMIC_DRAW",
";",
"this",
".",
"indexUsage",
"=",
"isStatic",
"?",
"this",
".",
"gl",
".",
"STATIC_DRAW",
":",
"this",
".",
"gl",
".",
"DYNAMIC_DRAW",
";",
"this",
".",
"_vertexAttribs",
"=",
"vertexAttribs",
"||",
"[",
"]",
";",
"this",
".",
"indicesDirty",
"=",
"true",
";",
"this",
".",
"verticesDirty",
"=",
"true",
";",
"//determine the vertex stride based on given attributes",
"var",
"totalNumComponents",
"=",
"0",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"_vertexAttribs",
".",
"length",
";",
"i",
"++",
")",
"totalNumComponents",
"+=",
"this",
".",
"_vertexAttribs",
"[",
"i",
"]",
".",
"offsetCount",
";",
"this",
".",
"vertexStride",
"=",
"totalNumComponents",
"*",
"4",
";",
"// in bytes",
"this",
".",
"vertices",
"=",
"new",
"Float32Array",
"(",
"this",
".",
"numVerts",
")",
";",
"this",
".",
"indices",
"=",
"new",
"Uint16Array",
"(",
"this",
".",
"numIndices",
")",
";",
"//add this VBO to the managed cache",
"this",
".",
"context",
".",
"addManagedObject",
"(",
"this",
")",
";",
"this",
".",
"create",
"(",
")",
";",
"}"
] | Creates a new Mesh with the provided parameters.
If numIndices is 0 or falsy, no index buffer will be used
and indices will be an empty ArrayBuffer and a null indexBuffer.
If isStatic is true, then vertexUsage and indexUsage will
be set to gl.STATIC_DRAW. Otherwise they will use gl.DYNAMIC_DRAW.
You may want to adjust these after initialization for further control.
@param {WebGLContext} context the context for management
@param {Boolean} isStatic a hint as to whether this geometry is static
@param {[type]} numVerts [description]
@param {[type]} numIndices [description]
@param {[type]} vertexAttribs [description]
@return {[type]} [description] | [
"Creates",
"a",
"new",
"Mesh",
"with",
"the",
"provided",
"parameters",
"."
] | b9b486eaba215728df31d1c1d2a5bf94c83a1337 | https://github.com/mattdesl/kami-mesh-buffer/blob/b9b486eaba215728df31d1c1d2a5bf94c83a1337/index.js#L51-L108 |
53,763 | mattdesl/kami-mesh-buffer | index.js | function() {
this.gl = this.context.gl;
var gl = this.gl;
this.vertexBuffer = gl.createBuffer();
//ignore index buffer if we haven't specified any
this.indexBuffer = this.numIndices > 0
? gl.createBuffer()
: null;
this.dirty = true;
} | javascript | function() {
this.gl = this.context.gl;
var gl = this.gl;
this.vertexBuffer = gl.createBuffer();
//ignore index buffer if we haven't specified any
this.indexBuffer = this.numIndices > 0
? gl.createBuffer()
: null;
this.dirty = true;
} | [
"function",
"(",
")",
"{",
"this",
".",
"gl",
"=",
"this",
".",
"context",
".",
"gl",
";",
"var",
"gl",
"=",
"this",
".",
"gl",
";",
"this",
".",
"vertexBuffer",
"=",
"gl",
".",
"createBuffer",
"(",
")",
";",
"//ignore index buffer if we haven't specified any",
"this",
".",
"indexBuffer",
"=",
"this",
".",
"numIndices",
">",
"0",
"?",
"gl",
".",
"createBuffer",
"(",
")",
":",
"null",
";",
"this",
".",
"dirty",
"=",
"true",
";",
"}"
] | recreates the buffers on context loss | [
"recreates",
"the",
"buffers",
"on",
"context",
"loss"
] | b9b486eaba215728df31d1c1d2a5bf94c83a1337 | https://github.com/mattdesl/kami-mesh-buffer/blob/b9b486eaba215728df31d1c1d2a5bf94c83a1337/index.js#L111-L122 |
|
53,764 | mattdesl/kami-mesh-buffer | index.js | function(shader) {
var gl = this.gl;
var offset = 0;
var stride = this.vertexStride;
//bind and update our vertex data before binding attributes
this._updateBuffers();
//for each attribtue
for (var i=0; i<this._vertexAttribs.length; i++) {
var a = this._vertexAttribs[i];
//location of the attribute
var loc = a.location === null
? shader.getAttributeLocation(a.name)
: a.location;
//TODO: We may want to skip unfound attribs
// if (loc!==0 && !loc)
// console.warn("WARN:", a.name, "is not enabled");
//first, enable the vertex array
gl.enableVertexAttribArray(loc);
//then specify our vertex format
gl.vertexAttribPointer(loc, a.numComponents, a.type || gl.FLOAT,
a.normalize, stride, offset);
//and increase the offset...
offset += a.offsetCount * 4; //in bytes
}
} | javascript | function(shader) {
var gl = this.gl;
var offset = 0;
var stride = this.vertexStride;
//bind and update our vertex data before binding attributes
this._updateBuffers();
//for each attribtue
for (var i=0; i<this._vertexAttribs.length; i++) {
var a = this._vertexAttribs[i];
//location of the attribute
var loc = a.location === null
? shader.getAttributeLocation(a.name)
: a.location;
//TODO: We may want to skip unfound attribs
// if (loc!==0 && !loc)
// console.warn("WARN:", a.name, "is not enabled");
//first, enable the vertex array
gl.enableVertexAttribArray(loc);
//then specify our vertex format
gl.vertexAttribPointer(loc, a.numComponents, a.type || gl.FLOAT,
a.normalize, stride, offset);
//and increase the offset...
offset += a.offsetCount * 4; //in bytes
}
} | [
"function",
"(",
"shader",
")",
"{",
"var",
"gl",
"=",
"this",
".",
"gl",
";",
"var",
"offset",
"=",
"0",
";",
"var",
"stride",
"=",
"this",
".",
"vertexStride",
";",
"//bind and update our vertex data before binding attributes",
"this",
".",
"_updateBuffers",
"(",
")",
";",
"//for each attribtue",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"_vertexAttribs",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"a",
"=",
"this",
".",
"_vertexAttribs",
"[",
"i",
"]",
";",
"//location of the attribute",
"var",
"loc",
"=",
"a",
".",
"location",
"===",
"null",
"?",
"shader",
".",
"getAttributeLocation",
"(",
"a",
".",
"name",
")",
":",
"a",
".",
"location",
";",
"//TODO: We may want to skip unfound attribs",
"// if (loc!==0 && !loc)",
"// \tconsole.warn(\"WARN:\", a.name, \"is not enabled\");",
"//first, enable the vertex array",
"gl",
".",
"enableVertexAttribArray",
"(",
"loc",
")",
";",
"//then specify our vertex format",
"gl",
".",
"vertexAttribPointer",
"(",
"loc",
",",
"a",
".",
"numComponents",
",",
"a",
".",
"type",
"||",
"gl",
".",
"FLOAT",
",",
"a",
".",
"normalize",
",",
"stride",
",",
"offset",
")",
";",
"//and increase the offset...",
"offset",
"+=",
"a",
".",
"offsetCount",
"*",
"4",
";",
"//in bytes",
"}",
"}"
] | binds this mesh's vertex attributes for the given shader | [
"binds",
"this",
"mesh",
"s",
"vertex",
"attributes",
"for",
"the",
"given",
"shader"
] | b9b486eaba215728df31d1c1d2a5bf94c83a1337 | https://github.com/mattdesl/kami-mesh-buffer/blob/b9b486eaba215728df31d1c1d2a5bf94c83a1337/index.js#L193-L225 |
|
53,765 | mattdesl/kami-mesh-buffer | index.js | function(name, numComponents, location, type, normalize, offsetCount) {
this.name = name;
this.numComponents = numComponents;
this.location = typeof location === "number" ? location : null;
this.type = type;
this.normalize = Boolean(normalize);
this.offsetCount = typeof offsetCount === "number" ? offsetCount : this.numComponents;
} | javascript | function(name, numComponents, location, type, normalize, offsetCount) {
this.name = name;
this.numComponents = numComponents;
this.location = typeof location === "number" ? location : null;
this.type = type;
this.normalize = Boolean(normalize);
this.offsetCount = typeof offsetCount === "number" ? offsetCount : this.numComponents;
} | [
"function",
"(",
"name",
",",
"numComponents",
",",
"location",
",",
"type",
",",
"normalize",
",",
"offsetCount",
")",
"{",
"this",
".",
"name",
"=",
"name",
";",
"this",
".",
"numComponents",
"=",
"numComponents",
";",
"this",
".",
"location",
"=",
"typeof",
"location",
"===",
"\"number\"",
"?",
"location",
":",
"null",
";",
"this",
".",
"type",
"=",
"type",
";",
"this",
".",
"normalize",
"=",
"Boolean",
"(",
"normalize",
")",
";",
"this",
".",
"offsetCount",
"=",
"typeof",
"offsetCount",
"===",
"\"number\"",
"?",
"offsetCount",
":",
"this",
".",
"numComponents",
";",
"}"
] | Mesh vertex attribute holder.
Location is optional and for advanced users that
want vertex arrays to match across shaders. Any non-numerical
value will be converted to null, and ignored. If a numerical
value is given, it will override the position of this attribute
when given to a mesh.
@class Mesh.Attrib
@constructor
@param {String} name the name of the attribute
@param {Number} numComponents the number of components, e.g. 2 for vec2
@param {Number} location optional attribute index location
@param {Number} type defaults to GL_FLOAT
@param {Number} normalize whether to normalize to 0-1, default false | [
"Mesh",
"vertex",
"attribute",
"holder",
"."
] | b9b486eaba215728df31d1c1d2a5bf94c83a1337 | https://github.com/mattdesl/kami-mesh-buffer/blob/b9b486eaba215728df31d1c1d2a5bf94c83a1337/index.js#L269-L276 |
|
53,766 | HarryStevens/fsz | index.js | writeJSON | function writeJSON(file, json){
var s = file.split(".");
if (s.length > 0) {
var ext = s[s.length - 1];
if (ext != "json"){
file = file + ".json";
}
}
fs.writeFileSync(file, JSON.stringify(json));
} | javascript | function writeJSON(file, json){
var s = file.split(".");
if (s.length > 0) {
var ext = s[s.length - 1];
if (ext != "json"){
file = file + ".json";
}
}
fs.writeFileSync(file, JSON.stringify(json));
} | [
"function",
"writeJSON",
"(",
"file",
",",
"json",
")",
"{",
"var",
"s",
"=",
"file",
".",
"split",
"(",
"\".\"",
")",
";",
"if",
"(",
"s",
".",
"length",
">",
"0",
")",
"{",
"var",
"ext",
"=",
"s",
"[",
"s",
".",
"length",
"-",
"1",
"]",
";",
"if",
"(",
"ext",
"!=",
"\"json\"",
")",
"{",
"file",
"=",
"file",
"+",
"\".json\"",
";",
"}",
"}",
"fs",
".",
"writeFileSync",
"(",
"file",
",",
"JSON",
".",
"stringify",
"(",
"json",
")",
")",
";",
"}"
] | Writes a JSON file
@param {string} file Name of the output file (.json extension will be added)
@param {string} json The JSON variable | [
"Writes",
"a",
"JSON",
"file"
] | 2b87d0de824c4270f8cb311ccc34a44ef36a6d33 | https://github.com/HarryStevens/fsz/blob/2b87d0de824c4270f8cb311ccc34a44ef36a6d33/index.js#L49-L58 |
53,767 | HarryStevens/fsz | index.js | getDirectories | function getDirectories(path){
return fs.readdirSync(path).filter(function (file) {
return fs.statSync(path + "/" + file).isDirectory();
});
} | javascript | function getDirectories(path){
return fs.readdirSync(path).filter(function (file) {
return fs.statSync(path + "/" + file).isDirectory();
});
} | [
"function",
"getDirectories",
"(",
"path",
")",
"{",
"return",
"fs",
".",
"readdirSync",
"(",
"path",
")",
".",
"filter",
"(",
"function",
"(",
"file",
")",
"{",
"return",
"fs",
".",
"statSync",
"(",
"path",
"+",
"\"/\"",
"+",
"file",
")",
".",
"isDirectory",
"(",
")",
";",
"}",
")",
";",
"}"
] | Returns a list of all directories in a parent directory
@param {string} path The path of the parent directory
@return {array} An array with a list of directories | [
"Returns",
"a",
"list",
"of",
"all",
"directories",
"in",
"a",
"parent",
"directory"
] | 2b87d0de824c4270f8cb311ccc34a44ef36a6d33 | https://github.com/HarryStevens/fsz/blob/2b87d0de824c4270f8cb311ccc34a44ef36a6d33/index.js#L67-L71 |
53,768 | wilmoore/knex-pg-middleware | lib/knex.js | create | function create(options) {
return knex(extend({
client: "pg",
debug: debug(),
connection: connection(),
pool: pool()
}, options));
} | javascript | function create(options) {
return knex(extend({
client: "pg",
debug: debug(),
connection: connection(),
pool: pool()
}, options));
} | [
"function",
"create",
"(",
"options",
")",
"{",
"return",
"knex",
"(",
"extend",
"(",
"{",
"client",
":",
"\"pg\"",
",",
"debug",
":",
"debug",
"(",
")",
",",
"connection",
":",
"connection",
"(",
")",
",",
"pool",
":",
"pool",
"(",
")",
"}",
",",
"options",
")",
")",
";",
"}"
] | Create and return a knex connection.
@param {Object} options
@api public | [
"Create",
"and",
"return",
"a",
"knex",
"connection",
"."
] | 615c391b87d4f60a7ed18518f3dd5d69bb396911 | https://github.com/wilmoore/knex-pg-middleware/blob/615c391b87d4f60a7ed18518f3dd5d69bb396911/lib/knex.js#L23-L30 |
53,769 | wilmoore/knex-pg-middleware | lib/knex.js | connection | function connection() {
return {
ssl: JSON.parse(JSON.stringify(process.env.DATABASE_SSL || "")),
host: process.env.DATABASE_HOST || "localhost",
user: process.env.DATABASE_USER || "",
charset: process.env.DATABASE_CHARSET || "utf8",
password: process.env.DATABASE_PASS || "",
database: process.env.DATABASE_NAME || ""
};
} | javascript | function connection() {
return {
ssl: JSON.parse(JSON.stringify(process.env.DATABASE_SSL || "")),
host: process.env.DATABASE_HOST || "localhost",
user: process.env.DATABASE_USER || "",
charset: process.env.DATABASE_CHARSET || "utf8",
password: process.env.DATABASE_PASS || "",
database: process.env.DATABASE_NAME || ""
};
} | [
"function",
"connection",
"(",
")",
"{",
"return",
"{",
"ssl",
":",
"JSON",
".",
"parse",
"(",
"JSON",
".",
"stringify",
"(",
"process",
".",
"env",
".",
"DATABASE_SSL",
"||",
"\"\"",
")",
")",
",",
"host",
":",
"process",
".",
"env",
".",
"DATABASE_HOST",
"||",
"\"localhost\"",
",",
"user",
":",
"process",
".",
"env",
".",
"DATABASE_USER",
"||",
"\"\"",
",",
"charset",
":",
"process",
".",
"env",
".",
"DATABASE_CHARSET",
"||",
"\"utf8\"",
",",
"password",
":",
"process",
".",
"env",
".",
"DATABASE_PASS",
"||",
"\"\"",
",",
"database",
":",
"process",
".",
"env",
".",
"DATABASE_NAME",
"||",
"\"\"",
"}",
";",
"}"
] | Return connection configuration. | [
"Return",
"connection",
"configuration",
"."
] | 615c391b87d4f60a7ed18518f3dd5d69bb396911 | https://github.com/wilmoore/knex-pg-middleware/blob/615c391b87d4f60a7ed18518f3dd5d69bb396911/lib/knex.js#L36-L45 |
53,770 | bredele/salute | index.js | type | function type (response) {
return value => {
if (!(value instanceof Error)) {
response.setHeader(
'Content-Type',
lookup(typeof value === 'object' ? 'json' : 'text')
)
}
return value instanceof Array ? JSON.stringify(value) : value
}
} | javascript | function type (response) {
return value => {
if (!(value instanceof Error)) {
response.setHeader(
'Content-Type',
lookup(typeof value === 'object' ? 'json' : 'text')
)
}
return value instanceof Array ? JSON.stringify(value) : value
}
} | [
"function",
"type",
"(",
"response",
")",
"{",
"return",
"value",
"=>",
"{",
"if",
"(",
"!",
"(",
"value",
"instanceof",
"Error",
")",
")",
"{",
"response",
".",
"setHeader",
"(",
"'Content-Type'",
",",
"lookup",
"(",
"typeof",
"value",
"===",
"'object'",
"?",
"'json'",
":",
"'text'",
")",
")",
"}",
"return",
"value",
"instanceof",
"Array",
"?",
"JSON",
".",
"stringify",
"(",
"value",
")",
":",
"value",
"}",
"}"
] | Set response content type header.
@param {Object} response
@return {Function}
@api private | [
"Set",
"response",
"content",
"type",
"header",
"."
] | 6a14a9001a97917e93230adc1145e84300b6edc2 | https://github.com/bredele/salute/blob/6a14a9001a97917e93230adc1145e84300b6edc2/index.js#L50-L60 |
53,771 | bredele/salute | index.js | status | function status (res) {
return err => {
const code = err.statusCode
error(res, code || 500)
if (!code) console.log(err)
}
} | javascript | function status (res) {
return err => {
const code = err.statusCode
error(res, code || 500)
if (!code) console.log(err)
}
} | [
"function",
"status",
"(",
"res",
")",
"{",
"return",
"err",
"=>",
"{",
"const",
"code",
"=",
"err",
".",
"statusCode",
"error",
"(",
"res",
",",
"code",
"||",
"500",
")",
"if",
"(",
"!",
"code",
")",
"console",
".",
"log",
"(",
"err",
")",
"}",
"}"
] | Set response status code and message.
@param {Object} response
@return {Function}
@api private | [
"Set",
"response",
"status",
"code",
"and",
"message",
"."
] | 6a14a9001a97917e93230adc1145e84300b6edc2 | https://github.com/bredele/salute/blob/6a14a9001a97917e93230adc1145e84300b6edc2/index.js#L71-L77 |
53,772 | jakobmattsson/jscov | spec/scaffolding/oss/express 3.0.6/router/index.js | callbacks | function callbacks(err) {
var fn = route.callbacks[i++];
try {
if ('route' == err) {
nextRoute();
} else if (err && fn) {
if (fn.length < 4) return callbacks(err);
fn(err, req, res, callbacks);
} else if (fn) {
if (fn.length < 4) return fn(req, res, callbacks);
callbacks();
} else {
nextRoute(err);
}
} catch (err) {
callbacks(err);
}
} | javascript | function callbacks(err) {
var fn = route.callbacks[i++];
try {
if ('route' == err) {
nextRoute();
} else if (err && fn) {
if (fn.length < 4) return callbacks(err);
fn(err, req, res, callbacks);
} else if (fn) {
if (fn.length < 4) return fn(req, res, callbacks);
callbacks();
} else {
nextRoute(err);
}
} catch (err) {
callbacks(err);
}
} | [
"function",
"callbacks",
"(",
"err",
")",
"{",
"var",
"fn",
"=",
"route",
".",
"callbacks",
"[",
"i",
"++",
"]",
";",
"try",
"{",
"if",
"(",
"'route'",
"==",
"err",
")",
"{",
"nextRoute",
"(",
")",
";",
"}",
"else",
"if",
"(",
"err",
"&&",
"fn",
")",
"{",
"if",
"(",
"fn",
".",
"length",
"<",
"4",
")",
"return",
"callbacks",
"(",
"err",
")",
";",
"fn",
"(",
"err",
",",
"req",
",",
"res",
",",
"callbacks",
")",
";",
"}",
"else",
"if",
"(",
"fn",
")",
"{",
"if",
"(",
"fn",
".",
"length",
"<",
"4",
")",
"return",
"fn",
"(",
"req",
",",
"res",
",",
"callbacks",
")",
";",
"callbacks",
"(",
")",
";",
"}",
"else",
"{",
"nextRoute",
"(",
"err",
")",
";",
"}",
"}",
"catch",
"(",
"err",
")",
"{",
"callbacks",
"(",
"err",
")",
";",
"}",
"}"
] | invoke route callbacks | [
"invoke",
"route",
"callbacks"
] | ff9f5dd9e720ea0dd00e8d0607f0f1ae84d99b78 | https://github.com/jakobmattsson/jscov/blob/ff9f5dd9e720ea0dd00e8d0607f0f1ae84d99b78/spec/scaffolding/oss/express 3.0.6/router/index.js#L152-L169 |
53,773 | punchcard-cms/input-plugin-file | lib/script.js | clear | function clear (node) {
const replace = node.cloneNode(false);
node.parentNode.replaceChild(replace, node);
return replace;
} | javascript | function clear (node) {
const replace = node.cloneNode(false);
node.parentNode.replaceChild(replace, node);
return replace;
} | [
"function",
"clear",
"(",
"node",
")",
"{",
"const",
"replace",
"=",
"node",
".",
"cloneNode",
"(",
"false",
")",
";",
"node",
".",
"parentNode",
".",
"replaceChild",
"(",
"replace",
",",
"node",
")",
";",
"return",
"replace",
";",
"}"
] | Clear a node's contents
@param {object} node - obj to be emptied | [
"Clear",
"a",
"node",
"s",
"contents"
] | 31ac6f170ad4c8022b5dc28fffb3ebc9bf266f96 | https://github.com/punchcard-cms/input-plugin-file/blob/31ac6f170ad4c8022b5dc28fffb3ebc9bf266f96/lib/script.js#L35-L39 |
53,774 | punchcard-cms/input-plugin-file | lib/script.js | loadHandler | function loadHandler (event) {
const target = event.target;
// change the link to the new file
link.setAttribute('href', target.result);
// make sure checkbox is no longer checked
checkbox.checked = false;
// make link not hidden
link.style.display = '';
// make delete checkbox not hidden
deleter.style.display = '';
// image uploaded
if (file.type.match('image.*')) {
// create image
const image = new Image();
image.title = file.name;
image.src = target.result;
// replace file--link contents
link = clear(link);
link.appendChild(image);
}
else {
// non-image file
link.textContent = file.name;
}
} | javascript | function loadHandler (event) {
const target = event.target;
// change the link to the new file
link.setAttribute('href', target.result);
// make sure checkbox is no longer checked
checkbox.checked = false;
// make link not hidden
link.style.display = '';
// make delete checkbox not hidden
deleter.style.display = '';
// image uploaded
if (file.type.match('image.*')) {
// create image
const image = new Image();
image.title = file.name;
image.src = target.result;
// replace file--link contents
link = clear(link);
link.appendChild(image);
}
else {
// non-image file
link.textContent = file.name;
}
} | [
"function",
"loadHandler",
"(",
"event",
")",
"{",
"const",
"target",
"=",
"event",
".",
"target",
";",
"// change the link to the new file",
"link",
".",
"setAttribute",
"(",
"'href'",
",",
"target",
".",
"result",
")",
";",
"// make sure checkbox is no longer checked",
"checkbox",
".",
"checked",
"=",
"false",
";",
"// make link not hidden",
"link",
".",
"style",
".",
"display",
"=",
"''",
";",
"// make delete checkbox not hidden",
"deleter",
".",
"style",
".",
"display",
"=",
"''",
";",
"// image uploaded",
"if",
"(",
"file",
".",
"type",
".",
"match",
"(",
"'image.*'",
")",
")",
"{",
"// create image",
"const",
"image",
"=",
"new",
"Image",
"(",
")",
";",
"image",
".",
"title",
"=",
"file",
".",
"name",
";",
"image",
".",
"src",
"=",
"target",
".",
"result",
";",
"// replace file--link contents",
"link",
"=",
"clear",
"(",
"link",
")",
";",
"link",
".",
"appendChild",
"(",
"image",
")",
";",
"}",
"else",
"{",
"// non-image file",
"link",
".",
"textContent",
"=",
"file",
".",
"name",
";",
"}",
"}"
] | Load handler for FileReader
@param {[type]} event - handler executed when the load event is fired | [
"Load",
"handler",
"for",
"FileReader"
] | 31ac6f170ad4c8022b5dc28fffb3ebc9bf266f96 | https://github.com/punchcard-cms/input-plugin-file/blob/31ac6f170ad4c8022b5dc28fffb3ebc9bf266f96/lib/script.js#L45-L75 |
53,775 | punchcard-cms/input-plugin-file | lib/script.js | uploadHandler | function uploadHandler (event) {
const target = event.target;
if (target.files && target.files[0]) {
file = target.files[0];
const reader = new FileReader();
reader.addEventListener('load', loadHandler);
reader.readAsDataURL(file);
}
} | javascript | function uploadHandler (event) {
const target = event.target;
if (target.files && target.files[0]) {
file = target.files[0];
const reader = new FileReader();
reader.addEventListener('load', loadHandler);
reader.readAsDataURL(file);
}
} | [
"function",
"uploadHandler",
"(",
"event",
")",
"{",
"const",
"target",
"=",
"event",
".",
"target",
";",
"if",
"(",
"target",
".",
"files",
"&&",
"target",
".",
"files",
"[",
"0",
"]",
")",
"{",
"file",
"=",
"target",
".",
"files",
"[",
"0",
"]",
";",
"const",
"reader",
"=",
"new",
"FileReader",
"(",
")",
";",
"reader",
".",
"addEventListener",
"(",
"'load'",
",",
"loadHandler",
")",
";",
"reader",
".",
"readAsDataURL",
"(",
"file",
")",
";",
"}",
"}"
] | Upload handler for file upload element
@param {[type]} event - handler executed when the load event is fired | [
"Upload",
"handler",
"for",
"file",
"upload",
"element"
] | 31ac6f170ad4c8022b5dc28fffb3ebc9bf266f96 | https://github.com/punchcard-cms/input-plugin-file/blob/31ac6f170ad4c8022b5dc28fffb3ebc9bf266f96/lib/script.js#L81-L92 |
53,776 | punchcard-cms/input-plugin-file | lib/script.js | checkboxHandler | function checkboxHandler (event) {
const target = event.target;
if (target.checked) {
link.style.display = 'none';
if (upload.value) {
upload.value = '';
link = clear(link);
}
}
else {
link.style.display = '';
}
} | javascript | function checkboxHandler (event) {
const target = event.target;
if (target.checked) {
link.style.display = 'none';
if (upload.value) {
upload.value = '';
link = clear(link);
}
}
else {
link.style.display = '';
}
} | [
"function",
"checkboxHandler",
"(",
"event",
")",
"{",
"const",
"target",
"=",
"event",
".",
"target",
";",
"if",
"(",
"target",
".",
"checked",
")",
"{",
"link",
".",
"style",
".",
"display",
"=",
"'none'",
";",
"if",
"(",
"upload",
".",
"value",
")",
"{",
"upload",
".",
"value",
"=",
"''",
";",
"link",
"=",
"clear",
"(",
"link",
")",
";",
"}",
"}",
"else",
"{",
"link",
".",
"style",
".",
"display",
"=",
"''",
";",
"}",
"}"
] | Checkbox handler for file delete checkbox
@param {[type]} event - handler executed when the load event is fired | [
"Checkbox",
"handler",
"for",
"file",
"delete",
"checkbox"
] | 31ac6f170ad4c8022b5dc28fffb3ebc9bf266f96 | https://github.com/punchcard-cms/input-plugin-file/blob/31ac6f170ad4c8022b5dc28fffb3ebc9bf266f96/lib/script.js#L98-L111 |
53,777 | scisco/yaml-files | index.js | construct | function construct(data) {
const basepath = process.cwd();
const files = data.map((f) => {
const fullpath = p.join(basepath, f);
const src = fs.readFileSync(fullpath, 'utf8');
const t = yaml.load(src, {
schema: YAML_FILES_SCHEMA,
filename: fullpath
});
return t;
});
const t = files.reduce((m, f) => merge(m, f));
return t;
} | javascript | function construct(data) {
const basepath = process.cwd();
const files = data.map((f) => {
const fullpath = p.join(basepath, f);
const src = fs.readFileSync(fullpath, 'utf8');
const t = yaml.load(src, {
schema: YAML_FILES_SCHEMA,
filename: fullpath
});
return t;
});
const t = files.reduce((m, f) => merge(m, f));
return t;
} | [
"function",
"construct",
"(",
"data",
")",
"{",
"const",
"basepath",
"=",
"process",
".",
"cwd",
"(",
")",
";",
"const",
"files",
"=",
"data",
".",
"map",
"(",
"(",
"f",
")",
"=>",
"{",
"const",
"fullpath",
"=",
"p",
".",
"join",
"(",
"basepath",
",",
"f",
")",
";",
"const",
"src",
"=",
"fs",
".",
"readFileSync",
"(",
"fullpath",
",",
"'utf8'",
")",
";",
"const",
"t",
"=",
"yaml",
".",
"load",
"(",
"src",
",",
"{",
"schema",
":",
"YAML_FILES_SCHEMA",
",",
"filename",
":",
"fullpath",
"}",
")",
";",
"return",
"t",
";",
"}",
")",
";",
"const",
"t",
"=",
"files",
".",
"reduce",
"(",
"(",
"m",
",",
"f",
")",
"=>",
"merge",
"(",
"m",
",",
"f",
")",
")",
";",
"return",
"t",
";",
"}"
] | Construct function for the yaml schema that reads a list of files
parse them and then merge them
@param {Object} data - input to the schema marker
@returns {Object} a parsed yaml object | [
"Construct",
"function",
"for",
"the",
"yaml",
"schema",
"that",
"reads",
"a",
"list",
"of",
"files",
"parse",
"them",
"and",
"then",
"merge",
"them"
] | 71de1364800a24a5cf86b12264fb6345eaf8f283 | https://github.com/scisco/yaml-files/blob/71de1364800a24a5cf86b12264fb6345eaf8f283/index.js#L42-L58 |
53,778 | 2createStudio/postcss-bad-selectors | lib/index.js | plugin | function plugin(cb) {
return function(css) {
if (lodash.isFunction(cb)) {
var token = cb(css.source.input.file);
if (!lodash.isNull(token)) {
css.eachRule(function(rule) {
if (!areSelectorsValid(rule.selectors, token)) {
throw rule.error('Wrong selector');
}
});
}
}
}
} | javascript | function plugin(cb) {
return function(css) {
if (lodash.isFunction(cb)) {
var token = cb(css.source.input.file);
if (!lodash.isNull(token)) {
css.eachRule(function(rule) {
if (!areSelectorsValid(rule.selectors, token)) {
throw rule.error('Wrong selector');
}
});
}
}
}
} | [
"function",
"plugin",
"(",
"cb",
")",
"{",
"return",
"function",
"(",
"css",
")",
"{",
"if",
"(",
"lodash",
".",
"isFunction",
"(",
"cb",
")",
")",
"{",
"var",
"token",
"=",
"cb",
"(",
"css",
".",
"source",
".",
"input",
".",
"file",
")",
";",
"if",
"(",
"!",
"lodash",
".",
"isNull",
"(",
"token",
")",
")",
"{",
"css",
".",
"eachRule",
"(",
"function",
"(",
"rule",
")",
"{",
"if",
"(",
"!",
"areSelectorsValid",
"(",
"rule",
".",
"selectors",
",",
"token",
")",
")",
"{",
"throw",
"rule",
".",
"error",
"(",
"'Wrong selector'",
")",
";",
"}",
"}",
")",
";",
"}",
"}",
"}",
"}"
] | PostCSS plugin definition.
@param {Function} cb
@return {Function} | [
"PostCSS",
"plugin",
"definition",
"."
] | 9c5cf7f32d21fd0cd172785a92db714457feb076 | https://github.com/2createStudio/postcss-bad-selectors/blob/9c5cf7f32d21fd0cd172785a92db714457feb076/lib/index.js#L20-L34 |
53,779 | 2createStudio/postcss-bad-selectors | lib/index.js | areSelectorsValid | function areSelectorsValid(selectors, token) {
return lodash.every(selectors, function(selector) {
if (lodash.isRegExp(token)) {
return token.test(lodash.trim(selector));
} else {
return lodash.startsWith(lodash.trim(selector), token);
}
});
} | javascript | function areSelectorsValid(selectors, token) {
return lodash.every(selectors, function(selector) {
if (lodash.isRegExp(token)) {
return token.test(lodash.trim(selector));
} else {
return lodash.startsWith(lodash.trim(selector), token);
}
});
} | [
"function",
"areSelectorsValid",
"(",
"selectors",
",",
"token",
")",
"{",
"return",
"lodash",
".",
"every",
"(",
"selectors",
",",
"function",
"(",
"selector",
")",
"{",
"if",
"(",
"lodash",
".",
"isRegExp",
"(",
"token",
")",
")",
"{",
"return",
"token",
".",
"test",
"(",
"lodash",
".",
"trim",
"(",
"selector",
")",
")",
";",
"}",
"else",
"{",
"return",
"lodash",
".",
"startsWith",
"(",
"lodash",
".",
"trim",
"(",
"selector",
")",
",",
"token",
")",
";",
"}",
"}",
")",
";",
"}"
] | Checks if all selectors in collection are valid.
@param {Array} selectors
@param {String} token
@return {Boolean} | [
"Checks",
"if",
"all",
"selectors",
"in",
"collection",
"are",
"valid",
"."
] | 9c5cf7f32d21fd0cd172785a92db714457feb076 | https://github.com/2createStudio/postcss-bad-selectors/blob/9c5cf7f32d21fd0cd172785a92db714457feb076/lib/index.js#L43-L51 |
53,780 | lmammino/indexed-string-variation | lib/index.js | cleanAlphabet | function cleanAlphabet(alphabet) {
return alphabet.split('').filter(function (item, pos, self) {
return self.indexOf(item) === pos;
}).join('');
} | javascript | function cleanAlphabet(alphabet) {
return alphabet.split('').filter(function (item, pos, self) {
return self.indexOf(item) === pos;
}).join('');
} | [
"function",
"cleanAlphabet",
"(",
"alphabet",
")",
"{",
"return",
"alphabet",
".",
"split",
"(",
"''",
")",
".",
"filter",
"(",
"function",
"(",
"item",
",",
"pos",
",",
"self",
")",
"{",
"return",
"self",
".",
"indexOf",
"(",
"item",
")",
"===",
"pos",
";",
"}",
")",
".",
"join",
"(",
"''",
")",
";",
"}"
] | remove duplicates from alphabets | [
"remove",
"duplicates",
"from",
"alphabets"
] | 52fb6b5b05940138fb58f9a1c937531ad90adda5 | https://github.com/lmammino/indexed-string-variation/blob/52fb6b5b05940138fb58f9a1c937531ad90adda5/lib/index.js#L26-L30 |
53,781 | lmammino/indexed-string-variation | lib/index.js | generate | function generate(index) {
return index instanceof _bigInteger2.default ? (0, _generateBigInt2.default)(index, alphabet) : (0, _generateInt2.default)(index, alphabet);
} | javascript | function generate(index) {
return index instanceof _bigInteger2.default ? (0, _generateBigInt2.default)(index, alphabet) : (0, _generateInt2.default)(index, alphabet);
} | [
"function",
"generate",
"(",
"index",
")",
"{",
"return",
"index",
"instanceof",
"_bigInteger2",
".",
"default",
"?",
"(",
"0",
",",
"_generateBigInt2",
".",
"default",
")",
"(",
"index",
",",
"alphabet",
")",
":",
"(",
"0",
",",
"_generateInt2",
".",
"default",
")",
"(",
"index",
",",
"alphabet",
")",
";",
"}"
] | string generation function | [
"string",
"generation",
"function"
] | 52fb6b5b05940138fb58f9a1c937531ad90adda5 | https://github.com/lmammino/indexed-string-variation/blob/52fb6b5b05940138fb58f9a1c937531ad90adda5/lib/index.js#L39-L41 |
53,782 | davidfig/settingspanel | docs/code.js | number | function number()
{
const number = document.createElement('div')
document.body.appendChild(number)
number.innerHTML = rand(1000)
number.style.fontSize = '300%'
number.style.position = 'fixed'
number.style.left = number.style.top = '50%'
number.style.color = 'red'
number.style.opacity = 1
return number
} | javascript | function number()
{
const number = document.createElement('div')
document.body.appendChild(number)
number.innerHTML = rand(1000)
number.style.fontSize = '300%'
number.style.position = 'fixed'
number.style.left = number.style.top = '50%'
number.style.color = 'red'
number.style.opacity = 1
return number
} | [
"function",
"number",
"(",
")",
"{",
"const",
"number",
"=",
"document",
".",
"createElement",
"(",
"'div'",
")",
"document",
".",
"body",
".",
"appendChild",
"(",
"number",
")",
"number",
".",
"innerHTML",
"=",
"rand",
"(",
"1000",
")",
"number",
".",
"style",
".",
"fontSize",
"=",
"'300%'",
"number",
".",
"style",
".",
"position",
"=",
"'fixed'",
"number",
".",
"style",
".",
"left",
"=",
"number",
".",
"style",
".",
"top",
"=",
"'50%'",
"number",
".",
"style",
".",
"color",
"=",
"'red'",
"number",
".",
"style",
".",
"opacity",
"=",
"1",
"return",
"number",
"}"
] | create and style test text | [
"create",
"and",
"style",
"test",
"text"
] | d9ba20d9b6d398e9dc5ba199d81dfc4fb08b9cfe | https://github.com/davidfig/settingspanel/blob/d9ba20d9b6d398e9dc5ba199d81dfc4fb08b9cfe/docs/code.js#L55-L66 |
53,783 | rohithpr/ipc-messenger | ipc-messenger.js | function(message) {
var pack = {
toMaster: true,
toWorkers: false,
toSource: false,
message: message,
source: process.pid
}
dispatch(pack)
} | javascript | function(message) {
var pack = {
toMaster: true,
toWorkers: false,
toSource: false,
message: message,
source: process.pid
}
dispatch(pack)
} | [
"function",
"(",
"message",
")",
"{",
"var",
"pack",
"=",
"{",
"toMaster",
":",
"true",
",",
"toWorkers",
":",
"false",
",",
"toSource",
":",
"false",
",",
"message",
":",
"message",
",",
"source",
":",
"process",
".",
"pid",
"}",
"dispatch",
"(",
"pack",
")",
"}"
] | This function can be used by workers to send a message to the master | [
"This",
"function",
"can",
"be",
"used",
"by",
"workers",
"to",
"send",
"a",
"message",
"to",
"the",
"master"
] | 46fd7471bb4e99367b7da6d23f93ff4eecd43d04 | https://github.com/rohithpr/ipc-messenger/blob/46fd7471bb4e99367b7da6d23f93ff4eecd43d04/ipc-messenger.js#L10-L19 |
|
53,784 | rohithpr/ipc-messenger | ipc-messenger.js | function(pack) {
if (pack.toSource !== false || pack.source !== process.pid) {
CALLBACK(pack.message)
}
} | javascript | function(pack) {
if (pack.toSource !== false || pack.source !== process.pid) {
CALLBACK(pack.message)
}
} | [
"function",
"(",
"pack",
")",
"{",
"if",
"(",
"pack",
".",
"toSource",
"!==",
"false",
"||",
"pack",
".",
"source",
"!==",
"process",
".",
"pid",
")",
"{",
"CALLBACK",
"(",
"pack",
".",
"message",
")",
"}",
"}"
] | Message receiver of the workers | [
"Message",
"receiver",
"of",
"the",
"workers"
] | 46fd7471bb4e99367b7da6d23f93ff4eecd43d04 | https://github.com/rohithpr/ipc-messenger/blob/46fd7471bb4e99367b7da6d23f93ff4eecd43d04/ipc-messenger.js#L55-L59 |
|
53,785 | rohithpr/ipc-messenger | ipc-messenger.js | function(pack) {
if (cluster.isMaster) {
if (pack.toWorkers === true) {
for (var key in cluster.workers) {
cluster.workers[key].send(pack)
}
}
}
else {
if (pack.toMaster === true || pack.toWorkers === true) {
process.send(pack)
}
}
} | javascript | function(pack) {
if (cluster.isMaster) {
if (pack.toWorkers === true) {
for (var key in cluster.workers) {
cluster.workers[key].send(pack)
}
}
}
else {
if (pack.toMaster === true || pack.toWorkers === true) {
process.send(pack)
}
}
} | [
"function",
"(",
"pack",
")",
"{",
"if",
"(",
"cluster",
".",
"isMaster",
")",
"{",
"if",
"(",
"pack",
".",
"toWorkers",
"===",
"true",
")",
"{",
"for",
"(",
"var",
"key",
"in",
"cluster",
".",
"workers",
")",
"{",
"cluster",
".",
"workers",
"[",
"key",
"]",
".",
"send",
"(",
"pack",
")",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"pack",
".",
"toMaster",
"===",
"true",
"||",
"pack",
".",
"toWorkers",
"===",
"true",
")",
"{",
"process",
".",
"send",
"(",
"pack",
")",
"}",
"}",
"}"
] | Common function called to send messages to other processes | [
"Common",
"function",
"called",
"to",
"send",
"messages",
"to",
"other",
"processes"
] | 46fd7471bb4e99367b7da6d23f93ff4eecd43d04 | https://github.com/rohithpr/ipc-messenger/blob/46fd7471bb4e99367b7da6d23f93ff4eecd43d04/ipc-messenger.js#L62-L75 |
|
53,786 | rohithpr/ipc-messenger | ipc-messenger.js | function(process, callback) {
if (callback !== undefined && typeof callback === 'function') {
CALLBACK = callback
}
if (cluster.isMaster) {
process.on('message', masterHandler)
}
else {
process.on('message', workerHandler)
}
} | javascript | function(process, callback) {
if (callback !== undefined && typeof callback === 'function') {
CALLBACK = callback
}
if (cluster.isMaster) {
process.on('message', masterHandler)
}
else {
process.on('message', workerHandler)
}
} | [
"function",
"(",
"process",
",",
"callback",
")",
"{",
"if",
"(",
"callback",
"!==",
"undefined",
"&&",
"typeof",
"callback",
"===",
"'function'",
")",
"{",
"CALLBACK",
"=",
"callback",
"}",
"if",
"(",
"cluster",
".",
"isMaster",
")",
"{",
"process",
".",
"on",
"(",
"'message'",
",",
"masterHandler",
")",
"}",
"else",
"{",
"process",
".",
"on",
"(",
"'message'",
",",
"workerHandler",
")",
"}",
"}"
] | Used to register processes and custom callback functions | [
"Used",
"to",
"register",
"processes",
"and",
"custom",
"callback",
"functions"
] | 46fd7471bb4e99367b7da6d23f93ff4eecd43d04 | https://github.com/rohithpr/ipc-messenger/blob/46fd7471bb4e99367b7da6d23f93ff4eecd43d04/ipc-messenger.js#L78-L88 |
|
53,787 | reworkcss/rework-plugin-function | index.js | func | function func(declarations, functions, functionMatcher, parseArgs) {
if (!declarations) return;
if (false !== parseArgs) parseArgs = true;
declarations.forEach(function(decl){
if ('comment' == decl.type) return;
var generatedFuncs = [], result, generatedFunc;
while (decl.value.match(functionMatcher)) {
decl.value = decl.value.replace(functionMatcher, function(_, name, args){
if (parseArgs) {
args = args.split(/\s*,\s*/).map(strip);
} else {
args = [strip(args)];
}
// Ensure result is string
result = '' + functions[name].apply(decl, args);
// Prevent fall into infinite loop like this:
//
// {
// url: function(path) {
// return 'url(' + '/some/prefix' + path + ')'
// }
// }
//
generatedFunc = {from: name, to: name + getRandomString()};
result = result.replace(functionMatcherBuilder(name), generatedFunc.to + '($2)');
generatedFuncs.push(generatedFunc);
return result;
});
}
generatedFuncs.forEach(function(func) {
decl.value = decl.value.replace(func.to, func.from);
})
});
} | javascript | function func(declarations, functions, functionMatcher, parseArgs) {
if (!declarations) return;
if (false !== parseArgs) parseArgs = true;
declarations.forEach(function(decl){
if ('comment' == decl.type) return;
var generatedFuncs = [], result, generatedFunc;
while (decl.value.match(functionMatcher)) {
decl.value = decl.value.replace(functionMatcher, function(_, name, args){
if (parseArgs) {
args = args.split(/\s*,\s*/).map(strip);
} else {
args = [strip(args)];
}
// Ensure result is string
result = '' + functions[name].apply(decl, args);
// Prevent fall into infinite loop like this:
//
// {
// url: function(path) {
// return 'url(' + '/some/prefix' + path + ')'
// }
// }
//
generatedFunc = {from: name, to: name + getRandomString()};
result = result.replace(functionMatcherBuilder(name), generatedFunc.to + '($2)');
generatedFuncs.push(generatedFunc);
return result;
});
}
generatedFuncs.forEach(function(func) {
decl.value = decl.value.replace(func.to, func.from);
})
});
} | [
"function",
"func",
"(",
"declarations",
",",
"functions",
",",
"functionMatcher",
",",
"parseArgs",
")",
"{",
"if",
"(",
"!",
"declarations",
")",
"return",
";",
"if",
"(",
"false",
"!==",
"parseArgs",
")",
"parseArgs",
"=",
"true",
";",
"declarations",
".",
"forEach",
"(",
"function",
"(",
"decl",
")",
"{",
"if",
"(",
"'comment'",
"==",
"decl",
".",
"type",
")",
"return",
";",
"var",
"generatedFuncs",
"=",
"[",
"]",
",",
"result",
",",
"generatedFunc",
";",
"while",
"(",
"decl",
".",
"value",
".",
"match",
"(",
"functionMatcher",
")",
")",
"{",
"decl",
".",
"value",
"=",
"decl",
".",
"value",
".",
"replace",
"(",
"functionMatcher",
",",
"function",
"(",
"_",
",",
"name",
",",
"args",
")",
"{",
"if",
"(",
"parseArgs",
")",
"{",
"args",
"=",
"args",
".",
"split",
"(",
"/",
"\\s*,\\s*",
"/",
")",
".",
"map",
"(",
"strip",
")",
";",
"}",
"else",
"{",
"args",
"=",
"[",
"strip",
"(",
"args",
")",
"]",
";",
"}",
"// Ensure result is string",
"result",
"=",
"''",
"+",
"functions",
"[",
"name",
"]",
".",
"apply",
"(",
"decl",
",",
"args",
")",
";",
"// Prevent fall into infinite loop like this:",
"//",
"// {",
"// url: function(path) {",
"// return 'url(' + '/some/prefix' + path + ')'",
"// }",
"// }",
"//",
"generatedFunc",
"=",
"{",
"from",
":",
"name",
",",
"to",
":",
"name",
"+",
"getRandomString",
"(",
")",
"}",
";",
"result",
"=",
"result",
".",
"replace",
"(",
"functionMatcherBuilder",
"(",
"name",
")",
",",
"generatedFunc",
".",
"to",
"+",
"'($2)'",
")",
";",
"generatedFuncs",
".",
"push",
"(",
"generatedFunc",
")",
";",
"return",
"result",
";",
"}",
")",
";",
"}",
"generatedFuncs",
".",
"forEach",
"(",
"function",
"(",
"func",
")",
"{",
"decl",
".",
"value",
"=",
"decl",
".",
"value",
".",
"replace",
"(",
"func",
".",
"to",
",",
"func",
".",
"from",
")",
";",
"}",
")",
"}",
")",
";",
"}"
] | Visit declarations and apply functions.
@param {Array} declarations
@param {Object} functions
@param {RegExp} functionMatcher
@param {Boolean} [parseArgs]
@api private | [
"Visit",
"declarations",
"and",
"apply",
"functions",
"."
] | a5b83c1e3a103bad7ec21afba44c7aa015151e30 | https://github.com/reworkcss/rework-plugin-function/blob/a5b83c1e3a103bad7ec21afba44c7aa015151e30/index.js#L33-L70 |
53,788 | iolo/express-toybox | error500.js | error500 | function error500(options) {
options = _.merge({}, DEF_CONFIG, options);
// pre-compile underscore template if available
if (typeof options.template === 'string' && options.template.length > 0) {
options.template = _.template(options.template);
}
return function (err, req, res, next) {
console.error('uncaught express error:', err);
DEBUG && debug(err.stack);
var error = _.extend({
status: err.status || options.status,
code: err.code || options.code,
message: err.message || String(err),
cause: err.cause
}, options.mappings[err.name], options.mappings[err.code]);
if (options.stack) {
error.stack = (err.stack && err.stack.split('\n')) || [];
}
res.status(error.status);
switch (req.accepts(['json', 'html'])) {
case 'json':
return res.json(error);
case 'html':
if (typeof options.template === 'function') {
res.type('html');
return res.send(options.template({error: error}));
}
return res.render(options.view, {error: error});
}
return res.send(util.inspect(error));
};
} | javascript | function error500(options) {
options = _.merge({}, DEF_CONFIG, options);
// pre-compile underscore template if available
if (typeof options.template === 'string' && options.template.length > 0) {
options.template = _.template(options.template);
}
return function (err, req, res, next) {
console.error('uncaught express error:', err);
DEBUG && debug(err.stack);
var error = _.extend({
status: err.status || options.status,
code: err.code || options.code,
message: err.message || String(err),
cause: err.cause
}, options.mappings[err.name], options.mappings[err.code]);
if (options.stack) {
error.stack = (err.stack && err.stack.split('\n')) || [];
}
res.status(error.status);
switch (req.accepts(['json', 'html'])) {
case 'json':
return res.json(error);
case 'html':
if (typeof options.template === 'function') {
res.type('html');
return res.send(options.template({error: error}));
}
return res.render(options.view, {error: error});
}
return res.send(util.inspect(error));
};
} | [
"function",
"error500",
"(",
"options",
")",
"{",
"options",
"=",
"_",
".",
"merge",
"(",
"{",
"}",
",",
"DEF_CONFIG",
",",
"options",
")",
";",
"// pre-compile underscore template if available",
"if",
"(",
"typeof",
"options",
".",
"template",
"===",
"'string'",
"&&",
"options",
".",
"template",
".",
"length",
">",
"0",
")",
"{",
"options",
".",
"template",
"=",
"_",
".",
"template",
"(",
"options",
".",
"template",
")",
";",
"}",
"return",
"function",
"(",
"err",
",",
"req",
",",
"res",
",",
"next",
")",
"{",
"console",
".",
"error",
"(",
"'uncaught express error:'",
",",
"err",
")",
";",
"DEBUG",
"&&",
"debug",
"(",
"err",
".",
"stack",
")",
";",
"var",
"error",
"=",
"_",
".",
"extend",
"(",
"{",
"status",
":",
"err",
".",
"status",
"||",
"options",
".",
"status",
",",
"code",
":",
"err",
".",
"code",
"||",
"options",
".",
"code",
",",
"message",
":",
"err",
".",
"message",
"||",
"String",
"(",
"err",
")",
",",
"cause",
":",
"err",
".",
"cause",
"}",
",",
"options",
".",
"mappings",
"[",
"err",
".",
"name",
"]",
",",
"options",
".",
"mappings",
"[",
"err",
".",
"code",
"]",
")",
";",
"if",
"(",
"options",
".",
"stack",
")",
"{",
"error",
".",
"stack",
"=",
"(",
"err",
".",
"stack",
"&&",
"err",
".",
"stack",
".",
"split",
"(",
"'\\n'",
")",
")",
"||",
"[",
"]",
";",
"}",
"res",
".",
"status",
"(",
"error",
".",
"status",
")",
";",
"switch",
"(",
"req",
".",
"accepts",
"(",
"[",
"'json'",
",",
"'html'",
"]",
")",
")",
"{",
"case",
"'json'",
":",
"return",
"res",
".",
"json",
"(",
"error",
")",
";",
"case",
"'html'",
":",
"if",
"(",
"typeof",
"options",
".",
"template",
"===",
"'function'",
")",
"{",
"res",
".",
"type",
"(",
"'html'",
")",
";",
"return",
"res",
".",
"send",
"(",
"options",
".",
"template",
"(",
"{",
"error",
":",
"error",
"}",
")",
")",
";",
"}",
"return",
"res",
".",
"render",
"(",
"options",
".",
"view",
",",
"{",
"error",
":",
"error",
"}",
")",
";",
"}",
"return",
"res",
".",
"send",
"(",
"util",
".",
"inspect",
"(",
"error",
")",
")",
";",
"}",
";",
"}"
] | express uncaught error handler.
@param {*} options
@param {Number} [options.status=500]
@param {Number} [options.code=8500]
@param {*} [options.mappings={}] map err.name/err.code to error response.
@param {Boolean} [options.stack=false]
@param {String|Function} [options.template] lodash(underscore) micro template for html error page.
@param {String} [options.view='errors/500'] express view path of html error page.
@returns {Function} express error handler | [
"express",
"uncaught",
"error",
"handler",
"."
] | c375a1388cfc167017e8dcd2325e71ca86ccb994 | https://github.com/iolo/express-toybox/blob/c375a1388cfc167017e8dcd2325e71ca86ccb994/error500.js#L33-L70 |
53,789 | pd4d10/userscript-meta | index.js | parse | function parse(meta) {
if (typeof meta !== 'string') {
throw new Error('`Parse`\'s first argument should be a string')
}
return meta.split(/[\r\n]/)
.filter(function (line) { // remove blank line
return /\S+/.test(line) &&
line.indexOf('==UserScript==') === -1 &&
line.indexOf('==/UserScript==') === -1
})
.reduce(function (obj, line) {
var arr = line.trim().replace(/^\/\//, '').trim().split(/\s+/)
var key = arr[0].slice(1)
var value = arr.slice(1).join(' ')
if (isUndefined(obj[key])) {
obj[key] = value
} else if (Array.isArray(obj[key])) {
obj[key].push(value)
} else {
obj[key] = [obj[key], value]
}
return obj
}, {})
} | javascript | function parse(meta) {
if (typeof meta !== 'string') {
throw new Error('`Parse`\'s first argument should be a string')
}
return meta.split(/[\r\n]/)
.filter(function (line) { // remove blank line
return /\S+/.test(line) &&
line.indexOf('==UserScript==') === -1 &&
line.indexOf('==/UserScript==') === -1
})
.reduce(function (obj, line) {
var arr = line.trim().replace(/^\/\//, '').trim().split(/\s+/)
var key = arr[0].slice(1)
var value = arr.slice(1).join(' ')
if (isUndefined(obj[key])) {
obj[key] = value
} else if (Array.isArray(obj[key])) {
obj[key].push(value)
} else {
obj[key] = [obj[key], value]
}
return obj
}, {})
} | [
"function",
"parse",
"(",
"meta",
")",
"{",
"if",
"(",
"typeof",
"meta",
"!==",
"'string'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'`Parse`\\'s first argument should be a string'",
")",
"}",
"return",
"meta",
".",
"split",
"(",
"/",
"[\\r\\n]",
"/",
")",
".",
"filter",
"(",
"function",
"(",
"line",
")",
"{",
"// remove blank line",
"return",
"/",
"\\S+",
"/",
".",
"test",
"(",
"line",
")",
"&&",
"line",
".",
"indexOf",
"(",
"'==UserScript=='",
")",
"===",
"-",
"1",
"&&",
"line",
".",
"indexOf",
"(",
"'==/UserScript=='",
")",
"===",
"-",
"1",
"}",
")",
".",
"reduce",
"(",
"function",
"(",
"obj",
",",
"line",
")",
"{",
"var",
"arr",
"=",
"line",
".",
"trim",
"(",
")",
".",
"replace",
"(",
"/",
"^\\/\\/",
"/",
",",
"''",
")",
".",
"trim",
"(",
")",
".",
"split",
"(",
"/",
"\\s+",
"/",
")",
"var",
"key",
"=",
"arr",
"[",
"0",
"]",
".",
"slice",
"(",
"1",
")",
"var",
"value",
"=",
"arr",
".",
"slice",
"(",
"1",
")",
".",
"join",
"(",
"' '",
")",
"if",
"(",
"isUndefined",
"(",
"obj",
"[",
"key",
"]",
")",
")",
"{",
"obj",
"[",
"key",
"]",
"=",
"value",
"}",
"else",
"if",
"(",
"Array",
".",
"isArray",
"(",
"obj",
"[",
"key",
"]",
")",
")",
"{",
"obj",
"[",
"key",
"]",
".",
"push",
"(",
"value",
")",
"}",
"else",
"{",
"obj",
"[",
"key",
"]",
"=",
"[",
"obj",
"[",
"key",
"]",
",",
"value",
"]",
"}",
"return",
"obj",
"}",
",",
"{",
"}",
")",
"}"
] | Parse metadata to an object | [
"Parse",
"metadata",
"to",
"an",
"object"
] | f5592b55ff40e782a91020cc7e9560594493f39a | https://github.com/pd4d10/userscript-meta/blob/f5592b55ff40e782a91020cc7e9560594493f39a/index.js#L12-L38 |
53,790 | pd4d10/userscript-meta | index.js | stringify | function stringify(obj) {
if (!isObject(obj)) {
throw new Error('`Stringify`\'s first argument should be an object')
}
var meta = Object.keys(obj)
.map(function (key) {
return getLine(key, obj[key])
}).join('')
return '// ==UserScript==\n' + meta + '// ==/UserScript==\n'
} | javascript | function stringify(obj) {
if (!isObject(obj)) {
throw new Error('`Stringify`\'s first argument should be an object')
}
var meta = Object.keys(obj)
.map(function (key) {
return getLine(key, obj[key])
}).join('')
return '// ==UserScript==\n' + meta + '// ==/UserScript==\n'
} | [
"function",
"stringify",
"(",
"obj",
")",
"{",
"if",
"(",
"!",
"isObject",
"(",
"obj",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'`Stringify`\\'s first argument should be an object'",
")",
"}",
"var",
"meta",
"=",
"Object",
".",
"keys",
"(",
"obj",
")",
".",
"map",
"(",
"function",
"(",
"key",
")",
"{",
"return",
"getLine",
"(",
"key",
",",
"obj",
"[",
"key",
"]",
")",
"}",
")",
".",
"join",
"(",
"''",
")",
"return",
"'// ==UserScript==\\n'",
"+",
"meta",
"+",
"'// ==/UserScript==\\n'",
"}"
] | Stringify metadata from an object | [
"Stringify",
"metadata",
"from",
"an",
"object"
] | f5592b55ff40e782a91020cc7e9560594493f39a | https://github.com/pd4d10/userscript-meta/blob/f5592b55ff40e782a91020cc7e9560594493f39a/index.js#L52-L63 |
53,791 | haasz/laravel-mix-ext | src/index.js | addOutProperty | function addOutProperty(out, directory, extensions) {
out[directory] = {
extensions: extensions
};
Object.defineProperty(
out[directory],
'directory',
{
get: function () {
return Config.fileLoaderDirs[directory];
},
set: function (value) {
Config.fileLoaderDirs[directory] = value;
},
enumerable: true,
configurable: false
}
);
out[directory].directory = out[directory].directory || directory;
} | javascript | function addOutProperty(out, directory, extensions) {
out[directory] = {
extensions: extensions
};
Object.defineProperty(
out[directory],
'directory',
{
get: function () {
return Config.fileLoaderDirs[directory];
},
set: function (value) {
Config.fileLoaderDirs[directory] = value;
},
enumerable: true,
configurable: false
}
);
out[directory].directory = out[directory].directory || directory;
} | [
"function",
"addOutProperty",
"(",
"out",
",",
"directory",
",",
"extensions",
")",
"{",
"out",
"[",
"directory",
"]",
"=",
"{",
"extensions",
":",
"extensions",
"}",
";",
"Object",
".",
"defineProperty",
"(",
"out",
"[",
"directory",
"]",
",",
"'directory'",
",",
"{",
"get",
":",
"function",
"(",
")",
"{",
"return",
"Config",
".",
"fileLoaderDirs",
"[",
"directory",
"]",
";",
"}",
",",
"set",
":",
"function",
"(",
"value",
")",
"{",
"Config",
".",
"fileLoaderDirs",
"[",
"directory",
"]",
"=",
"value",
";",
"}",
",",
"enumerable",
":",
"true",
",",
"configurable",
":",
"false",
"}",
")",
";",
"out",
"[",
"directory",
"]",
".",
"directory",
"=",
"out",
"[",
"directory",
"]",
".",
"directory",
"||",
"directory",
";",
"}"
] | Add an output directory settings to the configuration.
@param {Object} out The output configuration.
@param {string} directory The directory setting key and default name.
@param {string[]} extensions The file extensions. | [
"Add",
"an",
"output",
"directory",
"settings",
"to",
"the",
"configuration",
"."
] | bd1c794bdbf934dae233ab697dc5d5593d4b1124 | https://github.com/haasz/laravel-mix-ext/blob/bd1c794bdbf934dae233ab697dc5d5593d4b1124/src/index.js#L232-L251 |
53,792 | haasz/laravel-mix-ext | src/index.js | arraySubtraction | function arraySubtraction(arrA, arrB) {
arrA = arrA.slice();
for (let i = 0; i < arrB.length; ++i) {
arrA = arrA.filter(function (value) {
return value !== arrB[i];
});
}
return arrA;
} | javascript | function arraySubtraction(arrA, arrB) {
arrA = arrA.slice();
for (let i = 0; i < arrB.length; ++i) {
arrA = arrA.filter(function (value) {
return value !== arrB[i];
});
}
return arrA;
} | [
"function",
"arraySubtraction",
"(",
"arrA",
",",
"arrB",
")",
"{",
"arrA",
"=",
"arrA",
".",
"slice",
"(",
")",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"arrB",
".",
"length",
";",
"++",
"i",
")",
"{",
"arrA",
"=",
"arrA",
".",
"filter",
"(",
"function",
"(",
"value",
")",
"{",
"return",
"value",
"!==",
"arrB",
"[",
"i",
"]",
";",
"}",
")",
";",
"}",
"return",
"arrA",
";",
"}"
] | Array subtraction.
@param {Array} arrA The minuend array.
@param {Array} arrB The subtrahend array.
@return {Array} The difference array. | [
"Array",
"subtraction",
"."
] | bd1c794bdbf934dae233ab697dc5d5593d4b1124 | https://github.com/haasz/laravel-mix-ext/blob/bd1c794bdbf934dae233ab697dc5d5593d4b1124/src/index.js#L336-L344 |
53,793 | haasz/laravel-mix-ext | src/index.js | getDirFromPublicPath | function getDirFromPublicPath(file) {
return path.posix.dirname(
path.posix.normalize(
path.posix.sep
+ file.path().replace(
new RegExp(
'^' + escapeStringRegExp(path.resolve(Config.publicPath))
),
''
).split(path.sep).join(path.posix.sep)
)
);
} | javascript | function getDirFromPublicPath(file) {
return path.posix.dirname(
path.posix.normalize(
path.posix.sep
+ file.path().replace(
new RegExp(
'^' + escapeStringRegExp(path.resolve(Config.publicPath))
),
''
).split(path.sep).join(path.posix.sep)
)
);
} | [
"function",
"getDirFromPublicPath",
"(",
"file",
")",
"{",
"return",
"path",
".",
"posix",
".",
"dirname",
"(",
"path",
".",
"posix",
".",
"normalize",
"(",
"path",
".",
"posix",
".",
"sep",
"+",
"file",
".",
"path",
"(",
")",
".",
"replace",
"(",
"new",
"RegExp",
"(",
"'^'",
"+",
"escapeStringRegExp",
"(",
"path",
".",
"resolve",
"(",
"Config",
".",
"publicPath",
")",
")",
")",
",",
"''",
")",
".",
"split",
"(",
"path",
".",
"sep",
")",
".",
"join",
"(",
"path",
".",
"posix",
".",
"sep",
")",
")",
")",
";",
"}"
] | Get the directory of file from public path.
@param {Object} file The file.
@return {string} The directory of file from public path. | [
"Get",
"the",
"directory",
"of",
"file",
"from",
"public",
"path",
"."
] | bd1c794bdbf934dae233ab697dc5d5593d4b1124 | https://github.com/haasz/laravel-mix-ext/blob/bd1c794bdbf934dae233ab697dc5d5593d4b1124/src/index.js#L499-L511 |
53,794 | haasz/laravel-mix-ext | src/index.js | replaceTplTag | function replaceTplTag(dirFromPublicPath, tag, replacements, templateFileLog) {
let tagPath = tag.replace(new RegExp(tplTagPathRegExpStr), '$1');
let tagPathFromPublicPath = path.posix.resolve(dirFromPublicPath, tagPath);
if (
tagPathFromPublicPath in replacements
&&
replacements.hasOwnProperty(tagPathFromPublicPath)
) {
let result = (
path.posix.isAbsolute(tagPath)
? replacements[tagPathFromPublicPath]
: path.posix.relative(
dirFromPublicPath,
replacements[tagPathFromPublicPath]
)
);
templateFileLog.addTemplateTagLog(tag, result);
return result;
}
templateFileLog.addTemplateTagLog(tag);
return tag;
} | javascript | function replaceTplTag(dirFromPublicPath, tag, replacements, templateFileLog) {
let tagPath = tag.replace(new RegExp(tplTagPathRegExpStr), '$1');
let tagPathFromPublicPath = path.posix.resolve(dirFromPublicPath, tagPath);
if (
tagPathFromPublicPath in replacements
&&
replacements.hasOwnProperty(tagPathFromPublicPath)
) {
let result = (
path.posix.isAbsolute(tagPath)
? replacements[tagPathFromPublicPath]
: path.posix.relative(
dirFromPublicPath,
replacements[tagPathFromPublicPath]
)
);
templateFileLog.addTemplateTagLog(tag, result);
return result;
}
templateFileLog.addTemplateTagLog(tag);
return tag;
} | [
"function",
"replaceTplTag",
"(",
"dirFromPublicPath",
",",
"tag",
",",
"replacements",
",",
"templateFileLog",
")",
"{",
"let",
"tagPath",
"=",
"tag",
".",
"replace",
"(",
"new",
"RegExp",
"(",
"tplTagPathRegExpStr",
")",
",",
"'$1'",
")",
";",
"let",
"tagPathFromPublicPath",
"=",
"path",
".",
"posix",
".",
"resolve",
"(",
"dirFromPublicPath",
",",
"tagPath",
")",
";",
"if",
"(",
"tagPathFromPublicPath",
"in",
"replacements",
"&&",
"replacements",
".",
"hasOwnProperty",
"(",
"tagPathFromPublicPath",
")",
")",
"{",
"let",
"result",
"=",
"(",
"path",
".",
"posix",
".",
"isAbsolute",
"(",
"tagPath",
")",
"?",
"replacements",
"[",
"tagPathFromPublicPath",
"]",
":",
"path",
".",
"posix",
".",
"relative",
"(",
"dirFromPublicPath",
",",
"replacements",
"[",
"tagPathFromPublicPath",
"]",
")",
")",
";",
"templateFileLog",
".",
"addTemplateTagLog",
"(",
"tag",
",",
"result",
")",
";",
"return",
"result",
";",
"}",
"templateFileLog",
".",
"addTemplateTagLog",
"(",
"tag",
")",
";",
"return",
"tag",
";",
"}"
] | Replace a template tag.
@param {string} dirFromPublicPath The directory of the file that contains the template tag.
@param {string} tag The template tag.
@param {Object} replacements The replacements.
@param {Object} templateFileLog The template file log.
@return {string} The replaced (or original) template tag. | [
"Replace",
"a",
"template",
"tag",
"."
] | bd1c794bdbf934dae233ab697dc5d5593d4b1124 | https://github.com/haasz/laravel-mix-ext/blob/bd1c794bdbf934dae233ab697dc5d5593d4b1124/src/index.js#L524-L545 |
53,795 | haasz/laravel-mix-ext | src/index.js | getCompiledContent | function getCompiledContent(file, fragments, tags, replacements, templateFileLog) {
let content = '';
let fragmentStep = numberOfTplTagRegExpParts + 1;
let dirFromPublicPath = getDirFromPublicPath(file);
let i = 0;
for (; i < tags.length; ++i) {
content += fragments[i * fragmentStep];
content += replaceTplTag(
dirFromPublicPath,
tags[i],
replacements,
templateFileLog
);
}
content += fragments[i * fragmentStep];
return content;
} | javascript | function getCompiledContent(file, fragments, tags, replacements, templateFileLog) {
let content = '';
let fragmentStep = numberOfTplTagRegExpParts + 1;
let dirFromPublicPath = getDirFromPublicPath(file);
let i = 0;
for (; i < tags.length; ++i) {
content += fragments[i * fragmentStep];
content += replaceTplTag(
dirFromPublicPath,
tags[i],
replacements,
templateFileLog
);
}
content += fragments[i * fragmentStep];
return content;
} | [
"function",
"getCompiledContent",
"(",
"file",
",",
"fragments",
",",
"tags",
",",
"replacements",
",",
"templateFileLog",
")",
"{",
"let",
"content",
"=",
"''",
";",
"let",
"fragmentStep",
"=",
"numberOfTplTagRegExpParts",
"+",
"1",
";",
"let",
"dirFromPublicPath",
"=",
"getDirFromPublicPath",
"(",
"file",
")",
";",
"let",
"i",
"=",
"0",
";",
"for",
"(",
";",
"i",
"<",
"tags",
".",
"length",
";",
"++",
"i",
")",
"{",
"content",
"+=",
"fragments",
"[",
"i",
"*",
"fragmentStep",
"]",
";",
"content",
"+=",
"replaceTplTag",
"(",
"dirFromPublicPath",
",",
"tags",
"[",
"i",
"]",
",",
"replacements",
",",
"templateFileLog",
")",
";",
"}",
"content",
"+=",
"fragments",
"[",
"i",
"*",
"fragmentStep",
"]",
";",
"return",
"content",
";",
"}"
] | Get the compiled content of template file.
@param {Object} file The template file.
@param {string[]} fragments The content fragments.
@param {string[]} tags The template tags in original content.
@param {Object} replacements The replacements.
@param {Object} templateFileLog The template file log.
@return {string} The compiled content. | [
"Get",
"the",
"compiled",
"content",
"of",
"template",
"file",
"."
] | bd1c794bdbf934dae233ab697dc5d5593d4b1124 | https://github.com/haasz/laravel-mix-ext/blob/bd1c794bdbf934dae233ab697dc5d5593d4b1124/src/index.js#L559-L575 |
53,796 | haasz/laravel-mix-ext | src/index.js | compileTemplate | function compileTemplate(file, replacements, templateFileLog) {
file = File.find(path.resolve(file));
let content = file.read();
let tags = content.match(new RegExp(tplTagRegExpStr, 'g'));
if (tags && tags.length) {
content = getCompiledContent(
file,
content.split(new RegExp(tplTagRegExpStr)),
tags,
replacements,
templateFileLog
);
file.write(content);
}
} | javascript | function compileTemplate(file, replacements, templateFileLog) {
file = File.find(path.resolve(file));
let content = file.read();
let tags = content.match(new RegExp(tplTagRegExpStr, 'g'));
if (tags && tags.length) {
content = getCompiledContent(
file,
content.split(new RegExp(tplTagRegExpStr)),
tags,
replacements,
templateFileLog
);
file.write(content);
}
} | [
"function",
"compileTemplate",
"(",
"file",
",",
"replacements",
",",
"templateFileLog",
")",
"{",
"file",
"=",
"File",
".",
"find",
"(",
"path",
".",
"resolve",
"(",
"file",
")",
")",
";",
"let",
"content",
"=",
"file",
".",
"read",
"(",
")",
";",
"let",
"tags",
"=",
"content",
".",
"match",
"(",
"new",
"RegExp",
"(",
"tplTagRegExpStr",
",",
"'g'",
")",
")",
";",
"if",
"(",
"tags",
"&&",
"tags",
".",
"length",
")",
"{",
"content",
"=",
"getCompiledContent",
"(",
"file",
",",
"content",
".",
"split",
"(",
"new",
"RegExp",
"(",
"tplTagRegExpStr",
")",
")",
",",
"tags",
",",
"replacements",
",",
"templateFileLog",
")",
";",
"file",
".",
"write",
"(",
"content",
")",
";",
"}",
"}"
] | Compile the template file.
@param {string} file The template file.
@param {Object} replacements The replacements.
@param {Object} templateFileLog The template file log. | [
"Compile",
"the",
"template",
"file",
"."
] | bd1c794bdbf934dae233ab697dc5d5593d4b1124 | https://github.com/haasz/laravel-mix-ext/blob/bd1c794bdbf934dae233ab697dc5d5593d4b1124/src/index.js#L585-L599 |
53,797 | haasz/laravel-mix-ext | src/index.js | processTemplates | function processTemplates(templates) {
var templateProcessingLog = logger.createTemplateProcessingLog();
var replacements = Mix.manifest.get();
for (let template in templates) {
if (templates.hasOwnProperty(template)) {
// Copy to target
fs.copySync(template, templates[template]);
// Compile
compileTemplate(
templates[template],
replacements,
templateProcessingLog.addTemplateFileLog(
template,
templates[template]
)
);
}
}
templateProcessingLog.print();
} | javascript | function processTemplates(templates) {
var templateProcessingLog = logger.createTemplateProcessingLog();
var replacements = Mix.manifest.get();
for (let template in templates) {
if (templates.hasOwnProperty(template)) {
// Copy to target
fs.copySync(template, templates[template]);
// Compile
compileTemplate(
templates[template],
replacements,
templateProcessingLog.addTemplateFileLog(
template,
templates[template]
)
);
}
}
templateProcessingLog.print();
} | [
"function",
"processTemplates",
"(",
"templates",
")",
"{",
"var",
"templateProcessingLog",
"=",
"logger",
".",
"createTemplateProcessingLog",
"(",
")",
";",
"var",
"replacements",
"=",
"Mix",
".",
"manifest",
".",
"get",
"(",
")",
";",
"for",
"(",
"let",
"template",
"in",
"templates",
")",
"{",
"if",
"(",
"templates",
".",
"hasOwnProperty",
"(",
"template",
")",
")",
"{",
"// Copy to target",
"fs",
".",
"copySync",
"(",
"template",
",",
"templates",
"[",
"template",
"]",
")",
";",
"// Compile",
"compileTemplate",
"(",
"templates",
"[",
"template",
"]",
",",
"replacements",
",",
"templateProcessingLog",
".",
"addTemplateFileLog",
"(",
"template",
",",
"templates",
"[",
"template",
"]",
")",
")",
";",
"}",
"}",
"templateProcessingLog",
".",
"print",
"(",
")",
";",
"}"
] | Process the template files.
@param {Object} templates The templates. | [
"Process",
"the",
"template",
"files",
"."
] | bd1c794bdbf934dae233ab697dc5d5593d4b1124 | https://github.com/haasz/laravel-mix-ext/blob/bd1c794bdbf934dae233ab697dc5d5593d4b1124/src/index.js#L607-L626 |
53,798 | haasz/laravel-mix-ext | src/index.js | watchFile | function watchFile(file, callback) {
let absolutePath = File.find(file).path();
let watcher = chokidar
.watch(
absolutePath,
{
persistent: true
}
)
.on(
'change',
function () {
if (typeof callback === 'function') {
callback(file);
}
watcher.unwatch(absolutePath);
watchFile(file, callback);
}
)
;
} | javascript | function watchFile(file, callback) {
let absolutePath = File.find(file).path();
let watcher = chokidar
.watch(
absolutePath,
{
persistent: true
}
)
.on(
'change',
function () {
if (typeof callback === 'function') {
callback(file);
}
watcher.unwatch(absolutePath);
watchFile(file, callback);
}
)
;
} | [
"function",
"watchFile",
"(",
"file",
",",
"callback",
")",
"{",
"let",
"absolutePath",
"=",
"File",
".",
"find",
"(",
"file",
")",
".",
"path",
"(",
")",
";",
"let",
"watcher",
"=",
"chokidar",
".",
"watch",
"(",
"absolutePath",
",",
"{",
"persistent",
":",
"true",
"}",
")",
".",
"on",
"(",
"'change'",
",",
"function",
"(",
")",
"{",
"if",
"(",
"typeof",
"callback",
"===",
"'function'",
")",
"{",
"callback",
"(",
"file",
")",
";",
"}",
"watcher",
".",
"unwatch",
"(",
"absolutePath",
")",
";",
"watchFile",
"(",
"file",
",",
"callback",
")",
";",
"}",
")",
";",
"}"
] | Watch the file's changes.
@param {string} file The file.
@param {Function} callback The callback function. | [
"Watch",
"the",
"file",
"s",
"changes",
"."
] | bd1c794bdbf934dae233ab697dc5d5593d4b1124 | https://github.com/haasz/laravel-mix-ext/blob/bd1c794bdbf934dae233ab697dc5d5593d4b1124/src/index.js#L635-L655 |
53,799 | haasz/laravel-mix-ext | src/index.js | notify | function notify(message) {
if (Mix.isUsing('notifications')) {
let contentImage = path.join(__dirname, '../img/sunshine.png');
notifier.notify({
title: 'The Extension of Laravel Mix',
message: message,
contentImage: contentImage,
icon: (os.platform() === 'win32' || os.platform() === 'linux') ? contentImage : undefined
});
}
} | javascript | function notify(message) {
if (Mix.isUsing('notifications')) {
let contentImage = path.join(__dirname, '../img/sunshine.png');
notifier.notify({
title: 'The Extension of Laravel Mix',
message: message,
contentImage: contentImage,
icon: (os.platform() === 'win32' || os.platform() === 'linux') ? contentImage : undefined
});
}
} | [
"function",
"notify",
"(",
"message",
")",
"{",
"if",
"(",
"Mix",
".",
"isUsing",
"(",
"'notifications'",
")",
")",
"{",
"let",
"contentImage",
"=",
"path",
".",
"join",
"(",
"__dirname",
",",
"'../img/sunshine.png'",
")",
";",
"notifier",
".",
"notify",
"(",
"{",
"title",
":",
"'The Extension of Laravel Mix'",
",",
"message",
":",
"message",
",",
"contentImage",
":",
"contentImage",
",",
"icon",
":",
"(",
"os",
".",
"platform",
"(",
")",
"===",
"'win32'",
"||",
"os",
".",
"platform",
"(",
")",
"===",
"'linux'",
")",
"?",
"contentImage",
":",
"undefined",
"}",
")",
";",
"}",
"}"
] | Send a cross platform native notification.
@param {string} message The message. | [
"Send",
"a",
"cross",
"platform",
"native",
"notification",
"."
] | bd1c794bdbf934dae233ab697dc5d5593d4b1124 | https://github.com/haasz/laravel-mix-ext/blob/bd1c794bdbf934dae233ab697dc5d5593d4b1124/src/index.js#L663-L673 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.