id int32 0 58k | repo stringlengths 5 67 | path stringlengths 4 116 | func_name stringlengths 0 58 | original_string stringlengths 52 373k | language stringclasses 1 value | code stringlengths 52 373k | code_tokens list | docstring stringlengths 4 11.8k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 86 226 |
|---|---|---|---|---|---|---|---|---|---|---|---|
22,700 | repetere/modelscript | build/modelscript.cjs.js | cross_validate_score | function cross_validate_score(options = {}) {
const config = Object.assign({}, {
// classifier,
// regression,
// dataset,
// testingset,
dependentFeatures: [['X', ], ],
independentFeatures: [['Y', ], ],
// random_state,
folds: 10,
accuracy: 'standardError',
use_train_x_matrix: true,
use_train_y_matrix: false,
use_train_y_vector: false,
use_estimates_y_vector: false,
}, options);
const classifier = config.classifier;
const regression = config.regression;
const folds = cross_validation_split(config.dataset, {
folds: config.folds,
random_state: config.random_state,
});
const testingDataSet = new DataSet(config.testingset);
const y_test_matrix = testingDataSet.columnMatrix(config.independentFeatures);
const x_test_matrix = testingDataSet.columnMatrix(config.dependentFeatures);
const actuals = util.pivotVector(y_test_matrix)[ 0 ];
// console.log({ actuals });
const prediction_accuracies = folds.map(fold => {
const trainingDataSet = new DataSet(fold);
const x_train = trainingDataSet.columnMatrix(config.dependentFeatures);
const y_train = trainingDataSet.columnMatrix(config.independentFeatures);
const x_train_matrix = (config.use_train_x_matrix)
? new Matrix(x_train)
: x_train;
const y_train_matrix = (config.use_train_y_matrix)
? new Matrix(y_train)
: (config.use_train_y_vector)
? util.pivotVector(y_train)[0]
: y_train;
if (regression) {
let regressor;
let pred_y_test;
if (typeof regression.train === 'function') {
regressor = regression.train(x_train_matrix, y_train_matrix, config.modelOptions);
pred_y_test = regression.predict(x_test_matrix);
} else {
regressor = new regression(x_train_matrix, y_train_matrix, config.modelOptions);
pred_y_test = regressor.predict(x_test_matrix);
}
// console.log({ x_test_matrix });
// console.log({ pred_y_test });
const estimates = pred_y_test;//util.pivotVector(pred_y_test)[0];
// console.log({ estimates, actuals });
return (config.accuracy === 'standardError')
? util.standardError(actuals, estimates)
: util.rSquared(actuals, estimates);
} else {
let classification;
let estimates;
if (typeof classifier.train === 'function') {
classifier.train(x_train_matrix, y_train_matrix, config.modelOptions);
estimates = classifier.predict(x_test_matrix);
} else {
classification = new classifier(x_train_matrix, y_train_matrix, config.modelOptions);
estimates = classification.predict(x_test_matrix);
}
// classification.train(x_train_matrix, y_train_matrix);
// classifier.train(x_train_matrix, y_train_matrix);
const compareEstimates = (config.use_estimates_y_vector)
? util.pivotVector(estimates)[ 0 ]
: estimates;
const CM = ConfusionMatrix.fromLabels(actuals, compareEstimates);
return CM.getAccuracy();
}
});
return prediction_accuracies;
} | javascript | function cross_validate_score(options = {}) {
const config = Object.assign({}, {
// classifier,
// regression,
// dataset,
// testingset,
dependentFeatures: [['X', ], ],
independentFeatures: [['Y', ], ],
// random_state,
folds: 10,
accuracy: 'standardError',
use_train_x_matrix: true,
use_train_y_matrix: false,
use_train_y_vector: false,
use_estimates_y_vector: false,
}, options);
const classifier = config.classifier;
const regression = config.regression;
const folds = cross_validation_split(config.dataset, {
folds: config.folds,
random_state: config.random_state,
});
const testingDataSet = new DataSet(config.testingset);
const y_test_matrix = testingDataSet.columnMatrix(config.independentFeatures);
const x_test_matrix = testingDataSet.columnMatrix(config.dependentFeatures);
const actuals = util.pivotVector(y_test_matrix)[ 0 ];
// console.log({ actuals });
const prediction_accuracies = folds.map(fold => {
const trainingDataSet = new DataSet(fold);
const x_train = trainingDataSet.columnMatrix(config.dependentFeatures);
const y_train = trainingDataSet.columnMatrix(config.independentFeatures);
const x_train_matrix = (config.use_train_x_matrix)
? new Matrix(x_train)
: x_train;
const y_train_matrix = (config.use_train_y_matrix)
? new Matrix(y_train)
: (config.use_train_y_vector)
? util.pivotVector(y_train)[0]
: y_train;
if (regression) {
let regressor;
let pred_y_test;
if (typeof regression.train === 'function') {
regressor = regression.train(x_train_matrix, y_train_matrix, config.modelOptions);
pred_y_test = regression.predict(x_test_matrix);
} else {
regressor = new regression(x_train_matrix, y_train_matrix, config.modelOptions);
pred_y_test = regressor.predict(x_test_matrix);
}
// console.log({ x_test_matrix });
// console.log({ pred_y_test });
const estimates = pred_y_test;//util.pivotVector(pred_y_test)[0];
// console.log({ estimates, actuals });
return (config.accuracy === 'standardError')
? util.standardError(actuals, estimates)
: util.rSquared(actuals, estimates);
} else {
let classification;
let estimates;
if (typeof classifier.train === 'function') {
classifier.train(x_train_matrix, y_train_matrix, config.modelOptions);
estimates = classifier.predict(x_test_matrix);
} else {
classification = new classifier(x_train_matrix, y_train_matrix, config.modelOptions);
estimates = classification.predict(x_test_matrix);
}
// classification.train(x_train_matrix, y_train_matrix);
// classifier.train(x_train_matrix, y_train_matrix);
const compareEstimates = (config.use_estimates_y_vector)
? util.pivotVector(estimates)[ 0 ]
: estimates;
const CM = ConfusionMatrix.fromLabels(actuals, compareEstimates);
return CM.getAccuracy();
}
});
return prediction_accuracies;
} | [
"function",
"cross_validate_score",
"(",
"options",
"=",
"{",
"}",
")",
"{",
"const",
"config",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"{",
"// classifier,\r",
"// regression,\r",
"// dataset,\r",
"// testingset,\r",
"dependentFeatures",
":",
"[",
"[",
"'X'",
",",
"]",
",",
"]",
",",
"independentFeatures",
":",
"[",
"[",
"'Y'",
",",
"]",
",",
"]",
",",
"// random_state,\r",
"folds",
":",
"10",
",",
"accuracy",
":",
"'standardError'",
",",
"use_train_x_matrix",
":",
"true",
",",
"use_train_y_matrix",
":",
"false",
",",
"use_train_y_vector",
":",
"false",
",",
"use_estimates_y_vector",
":",
"false",
",",
"}",
",",
"options",
")",
";",
"const",
"classifier",
"=",
"config",
".",
"classifier",
";",
"const",
"regression",
"=",
"config",
".",
"regression",
";",
"const",
"folds",
"=",
"cross_validation_split",
"(",
"config",
".",
"dataset",
",",
"{",
"folds",
":",
"config",
".",
"folds",
",",
"random_state",
":",
"config",
".",
"random_state",
",",
"}",
")",
";",
"const",
"testingDataSet",
"=",
"new",
"DataSet",
"(",
"config",
".",
"testingset",
")",
";",
"const",
"y_test_matrix",
"=",
"testingDataSet",
".",
"columnMatrix",
"(",
"config",
".",
"independentFeatures",
")",
";",
"const",
"x_test_matrix",
"=",
"testingDataSet",
".",
"columnMatrix",
"(",
"config",
".",
"dependentFeatures",
")",
";",
"const",
"actuals",
"=",
"util",
".",
"pivotVector",
"(",
"y_test_matrix",
")",
"[",
"0",
"]",
";",
"// console.log({ actuals });\r",
"const",
"prediction_accuracies",
"=",
"folds",
".",
"map",
"(",
"fold",
"=>",
"{",
"const",
"trainingDataSet",
"=",
"new",
"DataSet",
"(",
"fold",
")",
";",
"const",
"x_train",
"=",
"trainingDataSet",
".",
"columnMatrix",
"(",
"config",
".",
"dependentFeatures",
")",
";",
"const",
"y_train",
"=",
"trainingDataSet",
".",
"columnMatrix",
"(",
"config",
".",
"independentFeatures",
")",
";",
"const",
"x_train_matrix",
"=",
"(",
"config",
".",
"use_train_x_matrix",
")",
"?",
"new",
"Matrix",
"(",
"x_train",
")",
":",
"x_train",
";",
"const",
"y_train_matrix",
"=",
"(",
"config",
".",
"use_train_y_matrix",
")",
"?",
"new",
"Matrix",
"(",
"y_train",
")",
":",
"(",
"config",
".",
"use_train_y_vector",
")",
"?",
"util",
".",
"pivotVector",
"(",
"y_train",
")",
"[",
"0",
"]",
":",
"y_train",
";",
"if",
"(",
"regression",
")",
"{",
"let",
"regressor",
";",
"let",
"pred_y_test",
";",
"if",
"(",
"typeof",
"regression",
".",
"train",
"===",
"'function'",
")",
"{",
"regressor",
"=",
"regression",
".",
"train",
"(",
"x_train_matrix",
",",
"y_train_matrix",
",",
"config",
".",
"modelOptions",
")",
";",
"pred_y_test",
"=",
"regression",
".",
"predict",
"(",
"x_test_matrix",
")",
";",
"}",
"else",
"{",
"regressor",
"=",
"new",
"regression",
"(",
"x_train_matrix",
",",
"y_train_matrix",
",",
"config",
".",
"modelOptions",
")",
";",
"pred_y_test",
"=",
"regressor",
".",
"predict",
"(",
"x_test_matrix",
")",
";",
"}",
"// console.log({ x_test_matrix });\r",
"// console.log({ pred_y_test });\r",
"const",
"estimates",
"=",
"pred_y_test",
";",
"//util.pivotVector(pred_y_test)[0];\r",
"// console.log({ estimates, actuals });\r",
"return",
"(",
"config",
".",
"accuracy",
"===",
"'standardError'",
")",
"?",
"util",
".",
"standardError",
"(",
"actuals",
",",
"estimates",
")",
":",
"util",
".",
"rSquared",
"(",
"actuals",
",",
"estimates",
")",
";",
"}",
"else",
"{",
"let",
"classification",
";",
"let",
"estimates",
";",
"if",
"(",
"typeof",
"classifier",
".",
"train",
"===",
"'function'",
")",
"{",
"classifier",
".",
"train",
"(",
"x_train_matrix",
",",
"y_train_matrix",
",",
"config",
".",
"modelOptions",
")",
";",
"estimates",
"=",
"classifier",
".",
"predict",
"(",
"x_test_matrix",
")",
";",
"}",
"else",
"{",
"classification",
"=",
"new",
"classifier",
"(",
"x_train_matrix",
",",
"y_train_matrix",
",",
"config",
".",
"modelOptions",
")",
";",
"estimates",
"=",
"classification",
".",
"predict",
"(",
"x_test_matrix",
")",
";",
"}",
"// classification.train(x_train_matrix, y_train_matrix);\r",
"// classifier.train(x_train_matrix, y_train_matrix);\r",
"const",
"compareEstimates",
"=",
"(",
"config",
".",
"use_estimates_y_vector",
")",
"?",
"util",
".",
"pivotVector",
"(",
"estimates",
")",
"[",
"0",
"]",
":",
"estimates",
";",
"const",
"CM",
"=",
"ConfusionMatrix",
".",
"fromLabels",
"(",
"actuals",
",",
"compareEstimates",
")",
";",
"return",
"CM",
".",
"getAccuracy",
"(",
")",
";",
"}",
"}",
")",
";",
"return",
"prediction_accuracies",
";",
"}"
] | Used to test variance and bias of a prediction
@memberOf cross_validation
@param {object} options
@param {function} options.classifier - instance of classification model used for training, or function to train a model. e.g. new DecisionTreeClassifier({ gainFunction: 'gini', }) or ml.KNN
@param {function} options.regression - instance of regression model used for training, or function to train a model. e.g. new RandomForestRegression({ nEstimators: 300, }) or ml.MultivariateLinearRegression
@return {number[]} Array of accucracy calculations | [
"Used",
"to",
"test",
"variance",
"and",
"bias",
"of",
"a",
"prediction"
] | b507fad9b3ecfb4a9ec4d44d41052a8082dac763 | https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.cjs.js#L2316-L2392 |
22,701 | repetere/modelscript | build/modelscript.cjs.js | grid_search | function grid_search(options = {}) {
const config = Object.assign({}, {
return_parameters: false,
compare_score:'mean',
sortAccuracyScore:'desc',
parameters: {},
}, options);
const regressor = config.regression;
const classification = config.classifier;
const sortAccuracyScore = (!options.sortAccuracyScore && config.regression)
? 'asc'
: config.sortAccuracyScore;
// const scoreSorter = ;
const gs = new GridSearch({
params: config.parameters,
run_callback: (params) => {
if (config.regression) {
config.regression = new regressor(params);
} else {
config.classifier = new classification(params);
}
const score = cross_validate_score(config);
return (config.compare_score)
? util[config.compare_score](score)
: score;
},
});
gs.run();
const accuracySorter = (sortAccuracyScore === 'desc')
? (a, b) => b.results - a.results
: (a, b) => a.results - b.results;
const results = gs._results.sort(accuracySorter);
// GridSearch;
return config.return_parameters
? results
: results[ 0 ];
} | javascript | function grid_search(options = {}) {
const config = Object.assign({}, {
return_parameters: false,
compare_score:'mean',
sortAccuracyScore:'desc',
parameters: {},
}, options);
const regressor = config.regression;
const classification = config.classifier;
const sortAccuracyScore = (!options.sortAccuracyScore && config.regression)
? 'asc'
: config.sortAccuracyScore;
// const scoreSorter = ;
const gs = new GridSearch({
params: config.parameters,
run_callback: (params) => {
if (config.regression) {
config.regression = new regressor(params);
} else {
config.classifier = new classification(params);
}
const score = cross_validate_score(config);
return (config.compare_score)
? util[config.compare_score](score)
: score;
},
});
gs.run();
const accuracySorter = (sortAccuracyScore === 'desc')
? (a, b) => b.results - a.results
: (a, b) => a.results - b.results;
const results = gs._results.sort(accuracySorter);
// GridSearch;
return config.return_parameters
? results
: results[ 0 ];
} | [
"function",
"grid_search",
"(",
"options",
"=",
"{",
"}",
")",
"{",
"const",
"config",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"{",
"return_parameters",
":",
"false",
",",
"compare_score",
":",
"'mean'",
",",
"sortAccuracyScore",
":",
"'desc'",
",",
"parameters",
":",
"{",
"}",
",",
"}",
",",
"options",
")",
";",
"const",
"regressor",
"=",
"config",
".",
"regression",
";",
"const",
"classification",
"=",
"config",
".",
"classifier",
";",
"const",
"sortAccuracyScore",
"=",
"(",
"!",
"options",
".",
"sortAccuracyScore",
"&&",
"config",
".",
"regression",
")",
"?",
"'asc'",
":",
"config",
".",
"sortAccuracyScore",
";",
"// const scoreSorter = ;\r",
"const",
"gs",
"=",
"new",
"GridSearch",
"(",
"{",
"params",
":",
"config",
".",
"parameters",
",",
"run_callback",
":",
"(",
"params",
")",
"=>",
"{",
"if",
"(",
"config",
".",
"regression",
")",
"{",
"config",
".",
"regression",
"=",
"new",
"regressor",
"(",
"params",
")",
";",
"}",
"else",
"{",
"config",
".",
"classifier",
"=",
"new",
"classification",
"(",
"params",
")",
";",
"}",
"const",
"score",
"=",
"cross_validate_score",
"(",
"config",
")",
";",
"return",
"(",
"config",
".",
"compare_score",
")",
"?",
"util",
"[",
"config",
".",
"compare_score",
"]",
"(",
"score",
")",
":",
"score",
";",
"}",
",",
"}",
")",
";",
"gs",
".",
"run",
"(",
")",
";",
"const",
"accuracySorter",
"=",
"(",
"sortAccuracyScore",
"===",
"'desc'",
")",
"?",
"(",
"a",
",",
"b",
")",
"=>",
"b",
".",
"results",
"-",
"a",
".",
"results",
":",
"(",
"a",
",",
"b",
")",
"=>",
"a",
".",
"results",
"-",
"b",
".",
"results",
";",
"const",
"results",
"=",
"gs",
".",
"_results",
".",
"sort",
"(",
"accuracySorter",
")",
";",
"// GridSearch;\r",
"return",
"config",
".",
"return_parameters",
"?",
"results",
":",
"results",
"[",
"0",
"]",
";",
"}"
] | Used to test variance and bias of a prediction with parameter tuning
@memberOf cross_validation
@param {object} options
@param {function} options.classifier - instance of classification model used for training, or function to train a model. e.g. new DecisionTreeClassifier({ gainFunction: 'gini', }) or ml.KNN
@param {function} options.regression - instance of regression model used for training, or function to train a model. e.g. new RandomForestRegression({ nEstimators: 300, }) or ml.MultivariateLinearRegression
@return {number[]} Array of accucracy calculations | [
"Used",
"to",
"test",
"variance",
"and",
"bias",
"of",
"a",
"prediction",
"with",
"parameter",
"tuning"
] | b507fad9b3ecfb4a9ec4d44d41052a8082dac763 | https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.cjs.js#L2402-L2439 |
22,702 | jhotmann/node-rename-cli | bin.js | epipeError | function epipeError(err) {
if (err.code === 'EPIPE' || err.errno === 32) return process.exit;
if (process.stdout.listeners('error').length <= 1) {
process.stdout.removeAllListeners();
process.stdout.emit('error', err);
process.stdout.on('error', epipeError);
}
} | javascript | function epipeError(err) {
if (err.code === 'EPIPE' || err.errno === 32) return process.exit;
if (process.stdout.listeners('error').length <= 1) {
process.stdout.removeAllListeners();
process.stdout.emit('error', err);
process.stdout.on('error', epipeError);
}
} | [
"function",
"epipeError",
"(",
"err",
")",
"{",
"if",
"(",
"err",
".",
"code",
"===",
"'EPIPE'",
"||",
"err",
".",
"errno",
"===",
"32",
")",
"return",
"process",
".",
"exit",
";",
"if",
"(",
"process",
".",
"stdout",
".",
"listeners",
"(",
"'error'",
")",
".",
"length",
"<=",
"1",
")",
"{",
"process",
".",
"stdout",
".",
"removeAllListeners",
"(",
")",
";",
"process",
".",
"stdout",
".",
"emit",
"(",
"'error'",
",",
"err",
")",
";",
"process",
".",
"stdout",
".",
"on",
"(",
"'error'",
",",
"epipeError",
")",
";",
"}",
"}"
] | Handle EPIPE errors when user doesn't put quotes around output file name with parameters | [
"Handle",
"EPIPE",
"errors",
"when",
"user",
"doesn",
"t",
"put",
"quotes",
"around",
"output",
"file",
"name",
"with",
"parameters"
] | 5d75fdcfc774796efd6a5f830cad9815f6323f20 | https://github.com/jhotmann/node-rename-cli/blob/5d75fdcfc774796efd6a5f830cad9815f6323f20/bin.js#L3-L11 |
22,703 | FormidableLabs/builder-support | lib/dev.js | function (source, target, isExternal) {
// Clone source
var pkg = JSON.parse(JSON.stringify(source));
// Validation of source package.
["name", "description"].forEach(function (name) {
if (!pkg[name]) {
throw new Error("Source object missing field: " + name);
}
});
var nameRe = new RegExp("(^|.*\/)(" + source.name + ")(\/.*|$)");
// Update with internal "development" names
pkg.name += "-dev";
pkg.description += " (Development)";
// Update external fields to add `-dev` if applicable and present.
if (isExternal) {
[
"repository.url",
"bugs.url",
"homepage"
].forEach(function (paths) {
// Traverse the package structure.
var parts = paths.split(".");
var pkgPart = pkg;
parts.forEach(function (part, i) {
if (pkgPart && pkgPart[part]) {
if (i + 1 === parts.length) {
// Done! Update part if present.
if (nameRe.test(pkgPart[part])) {
pkgPart[part] = pkgPart[part].replace(nameRe, "$1" + pkg.name + "$3");
}
return;
}
// Increment
pkgPart = pkgPart[part];
return;
}
// Failed.
pkgPart = null;
});
});
}
// Copy back in dependencies from dev package
pkg.dependencies = (target || {}).dependencies || {};
pkg.peerDependencies = (target || {}).peerDependencies || {};
// Remove scripts, dev deps, etc.
pkg.scripts = {};
pkg.devDependencies = {};
return pkg;
} | javascript | function (source, target, isExternal) {
// Clone source
var pkg = JSON.parse(JSON.stringify(source));
// Validation of source package.
["name", "description"].forEach(function (name) {
if (!pkg[name]) {
throw new Error("Source object missing field: " + name);
}
});
var nameRe = new RegExp("(^|.*\/)(" + source.name + ")(\/.*|$)");
// Update with internal "development" names
pkg.name += "-dev";
pkg.description += " (Development)";
// Update external fields to add `-dev` if applicable and present.
if (isExternal) {
[
"repository.url",
"bugs.url",
"homepage"
].forEach(function (paths) {
// Traverse the package structure.
var parts = paths.split(".");
var pkgPart = pkg;
parts.forEach(function (part, i) {
if (pkgPart && pkgPart[part]) {
if (i + 1 === parts.length) {
// Done! Update part if present.
if (nameRe.test(pkgPart[part])) {
pkgPart[part] = pkgPart[part].replace(nameRe, "$1" + pkg.name + "$3");
}
return;
}
// Increment
pkgPart = pkgPart[part];
return;
}
// Failed.
pkgPart = null;
});
});
}
// Copy back in dependencies from dev package
pkg.dependencies = (target || {}).dependencies || {};
pkg.peerDependencies = (target || {}).peerDependencies || {};
// Remove scripts, dev deps, etc.
pkg.scripts = {};
pkg.devDependencies = {};
return pkg;
} | [
"function",
"(",
"source",
",",
"target",
",",
"isExternal",
")",
"{",
"// Clone source",
"var",
"pkg",
"=",
"JSON",
".",
"parse",
"(",
"JSON",
".",
"stringify",
"(",
"source",
")",
")",
";",
"// Validation of source package.",
"[",
"\"name\"",
",",
"\"description\"",
"]",
".",
"forEach",
"(",
"function",
"(",
"name",
")",
"{",
"if",
"(",
"!",
"pkg",
"[",
"name",
"]",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Source object missing field: \"",
"+",
"name",
")",
";",
"}",
"}",
")",
";",
"var",
"nameRe",
"=",
"new",
"RegExp",
"(",
"\"(^|.*\\/)(\"",
"+",
"source",
".",
"name",
"+",
"\")(\\/.*|$)\"",
")",
";",
"// Update with internal \"development\" names",
"pkg",
".",
"name",
"+=",
"\"-dev\"",
";",
"pkg",
".",
"description",
"+=",
"\" (Development)\"",
";",
"// Update external fields to add `-dev` if applicable and present.",
"if",
"(",
"isExternal",
")",
"{",
"[",
"\"repository.url\"",
",",
"\"bugs.url\"",
",",
"\"homepage\"",
"]",
".",
"forEach",
"(",
"function",
"(",
"paths",
")",
"{",
"// Traverse the package structure.",
"var",
"parts",
"=",
"paths",
".",
"split",
"(",
"\".\"",
")",
";",
"var",
"pkgPart",
"=",
"pkg",
";",
"parts",
".",
"forEach",
"(",
"function",
"(",
"part",
",",
"i",
")",
"{",
"if",
"(",
"pkgPart",
"&&",
"pkgPart",
"[",
"part",
"]",
")",
"{",
"if",
"(",
"i",
"+",
"1",
"===",
"parts",
".",
"length",
")",
"{",
"// Done! Update part if present.",
"if",
"(",
"nameRe",
".",
"test",
"(",
"pkgPart",
"[",
"part",
"]",
")",
")",
"{",
"pkgPart",
"[",
"part",
"]",
"=",
"pkgPart",
"[",
"part",
"]",
".",
"replace",
"(",
"nameRe",
",",
"\"$1\"",
"+",
"pkg",
".",
"name",
"+",
"\"$3\"",
")",
";",
"}",
"return",
";",
"}",
"// Increment",
"pkgPart",
"=",
"pkgPart",
"[",
"part",
"]",
";",
"return",
";",
"}",
"// Failed.",
"pkgPart",
"=",
"null",
";",
"}",
")",
";",
"}",
")",
";",
"}",
"// Copy back in dependencies from dev package",
"pkg",
".",
"dependencies",
"=",
"(",
"target",
"||",
"{",
"}",
")",
".",
"dependencies",
"||",
"{",
"}",
";",
"pkg",
".",
"peerDependencies",
"=",
"(",
"target",
"||",
"{",
"}",
")",
".",
"peerDependencies",
"||",
"{",
"}",
";",
"// Remove scripts, dev deps, etc.",
"pkg",
".",
"scripts",
"=",
"{",
"}",
";",
"pkg",
".",
"devDependencies",
"=",
"{",
"}",
";",
"return",
"pkg",
";",
"}"
] | Update `target` JSON structure with fields from `source`.
@param {Object} source Source JSON object
@param {Object} target Target JSON object
@param {Boolean} isExternal Is external (`../NAME-dev`) dev package.
@returns {Object} Updated JSON object | [
"Update",
"target",
"JSON",
"structure",
"with",
"fields",
"from",
"source",
"."
] | 675ef7c1243f02f1243bfee0c68ecd3c167f548d | https://github.com/FormidableLabs/builder-support/blob/675ef7c1243f02f1243bfee0c68ecd3c167f548d/lib/dev.js#L44-L101 | |
22,704 | soundar24/roundSlider | src/roundslider.js | function (value) {
var o = this.options, min = o.min, max = o.max;
this.bar.children().attr({ "aria-valuenow": value });
if (o.sliderType == "range") {
var handles = this._handles();
handles.eq(0).attr({ "aria-valuemin": min });
handles.eq(1).attr({ "aria-valuemax": max });
if (this._active == 1) handles.eq(1).attr({ "aria-valuemin": value });
else handles.eq(0).attr({ "aria-valuemax": value });
}
else this.bar.children().attr({ "aria-valuemin": min, "aria-valuemax": max });
} | javascript | function (value) {
var o = this.options, min = o.min, max = o.max;
this.bar.children().attr({ "aria-valuenow": value });
if (o.sliderType == "range") {
var handles = this._handles();
handles.eq(0).attr({ "aria-valuemin": min });
handles.eq(1).attr({ "aria-valuemax": max });
if (this._active == 1) handles.eq(1).attr({ "aria-valuemin": value });
else handles.eq(0).attr({ "aria-valuemax": value });
}
else this.bar.children().attr({ "aria-valuemin": min, "aria-valuemax": max });
} | [
"function",
"(",
"value",
")",
"{",
"var",
"o",
"=",
"this",
".",
"options",
",",
"min",
"=",
"o",
".",
"min",
",",
"max",
"=",
"o",
".",
"max",
";",
"this",
".",
"bar",
".",
"children",
"(",
")",
".",
"attr",
"(",
"{",
"\"aria-valuenow\"",
":",
"value",
"}",
")",
";",
"if",
"(",
"o",
".",
"sliderType",
"==",
"\"range\"",
")",
"{",
"var",
"handles",
"=",
"this",
".",
"_handles",
"(",
")",
";",
"handles",
".",
"eq",
"(",
"0",
")",
".",
"attr",
"(",
"{",
"\"aria-valuemin\"",
":",
"min",
"}",
")",
";",
"handles",
".",
"eq",
"(",
"1",
")",
".",
"attr",
"(",
"{",
"\"aria-valuemax\"",
":",
"max",
"}",
")",
";",
"if",
"(",
"this",
".",
"_active",
"==",
"1",
")",
"handles",
".",
"eq",
"(",
"1",
")",
".",
"attr",
"(",
"{",
"\"aria-valuemin\"",
":",
"value",
"}",
")",
";",
"else",
"handles",
".",
"eq",
"(",
"0",
")",
".",
"attr",
"(",
"{",
"\"aria-valuemax\"",
":",
"value",
"}",
")",
";",
"}",
"else",
"this",
".",
"bar",
".",
"children",
"(",
")",
".",
"attr",
"(",
"{",
"\"aria-valuemin\"",
":",
"min",
",",
"\"aria-valuemax\"",
":",
"max",
"}",
")",
";",
"}"
] | WAI-ARIA support | [
"WAI",
"-",
"ARIA",
"support"
] | b58cd164a894339a4047b568a2202f99dfaa49b8 | https://github.com/soundar24/roundSlider/blob/b58cd164a894339a4047b568a2202f99dfaa49b8/src/roundslider.js#L609-L621 | |
22,705 | soundar24/roundSlider | src/roundslider.js | function () {
var _data = this._dataElement().data("bind");
if (typeof _data == "string" && typeof ko == "object") {
var _vm = ko.dataFor(this._dataElement()[0]);
if (typeof _vm == "undefined") return true;
var _all = _data.split(","), _handler;
for (var i = 0; i < _all.length; i++) {
var d = _all[i].split(":");
if ($.trim(d[0]) == "value") {
_handler = $.trim(d[1]);
break;
}
}
if (_handler) {
this._isKO = true;
ko.computed(function () { this.option("value", _vm[_handler]()); }, this);
}
}
} | javascript | function () {
var _data = this._dataElement().data("bind");
if (typeof _data == "string" && typeof ko == "object") {
var _vm = ko.dataFor(this._dataElement()[0]);
if (typeof _vm == "undefined") return true;
var _all = _data.split(","), _handler;
for (var i = 0; i < _all.length; i++) {
var d = _all[i].split(":");
if ($.trim(d[0]) == "value") {
_handler = $.trim(d[1]);
break;
}
}
if (_handler) {
this._isKO = true;
ko.computed(function () { this.option("value", _vm[_handler]()); }, this);
}
}
} | [
"function",
"(",
")",
"{",
"var",
"_data",
"=",
"this",
".",
"_dataElement",
"(",
")",
".",
"data",
"(",
"\"bind\"",
")",
";",
"if",
"(",
"typeof",
"_data",
"==",
"\"string\"",
"&&",
"typeof",
"ko",
"==",
"\"object\"",
")",
"{",
"var",
"_vm",
"=",
"ko",
".",
"dataFor",
"(",
"this",
".",
"_dataElement",
"(",
")",
"[",
"0",
"]",
")",
";",
"if",
"(",
"typeof",
"_vm",
"==",
"\"undefined\"",
")",
"return",
"true",
";",
"var",
"_all",
"=",
"_data",
".",
"split",
"(",
"\",\"",
")",
",",
"_handler",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"_all",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"d",
"=",
"_all",
"[",
"i",
"]",
".",
"split",
"(",
"\":\"",
")",
";",
"if",
"(",
"$",
".",
"trim",
"(",
"d",
"[",
"0",
"]",
")",
"==",
"\"value\"",
")",
"{",
"_handler",
"=",
"$",
".",
"trim",
"(",
"d",
"[",
"1",
"]",
")",
";",
"break",
";",
"}",
"}",
"if",
"(",
"_handler",
")",
"{",
"this",
".",
"_isKO",
"=",
"true",
";",
"ko",
".",
"computed",
"(",
"function",
"(",
")",
"{",
"this",
".",
"option",
"(",
"\"value\"",
",",
"_vm",
"[",
"_handler",
"]",
"(",
")",
")",
";",
"}",
",",
"this",
")",
";",
"}",
"}",
"}"
] | Listener for KO binding | [
"Listener",
"for",
"KO",
"binding"
] | b58cd164a894339a4047b568a2202f99dfaa49b8 | https://github.com/soundar24/roundSlider/blob/b58cd164a894339a4047b568a2202f99dfaa49b8/src/roundslider.js#L623-L641 | |
22,706 | soundar24/roundSlider | src/roundslider.js | function () {
if (typeof angular == "object" && typeof angular.element == "function") {
this._ngName = this._dataElement().attr("ng-model");
if (typeof this._ngName == "string") {
this._isAngular = true; var that = this;
this._scope().$watch(this._ngName, function (newValue, oldValue) { that.option("value", newValue); });
}
}
} | javascript | function () {
if (typeof angular == "object" && typeof angular.element == "function") {
this._ngName = this._dataElement().attr("ng-model");
if (typeof this._ngName == "string") {
this._isAngular = true; var that = this;
this._scope().$watch(this._ngName, function (newValue, oldValue) { that.option("value", newValue); });
}
}
} | [
"function",
"(",
")",
"{",
"if",
"(",
"typeof",
"angular",
"==",
"\"object\"",
"&&",
"typeof",
"angular",
".",
"element",
"==",
"\"function\"",
")",
"{",
"this",
".",
"_ngName",
"=",
"this",
".",
"_dataElement",
"(",
")",
".",
"attr",
"(",
"\"ng-model\"",
")",
";",
"if",
"(",
"typeof",
"this",
".",
"_ngName",
"==",
"\"string\"",
")",
"{",
"this",
".",
"_isAngular",
"=",
"true",
";",
"var",
"that",
"=",
"this",
";",
"this",
".",
"_scope",
"(",
")",
".",
"$watch",
"(",
"this",
".",
"_ngName",
",",
"function",
"(",
"newValue",
",",
"oldValue",
")",
"{",
"that",
".",
"option",
"(",
"\"value\"",
",",
"newValue",
")",
";",
"}",
")",
";",
"}",
"}",
"}"
] | Listener for Angular binding | [
"Listener",
"for",
"Angular",
"binding"
] | b58cd164a894339a4047b568a2202f99dfaa49b8 | https://github.com/soundar24/roundSlider/blob/b58cd164a894339a4047b568a2202f99dfaa49b8/src/roundslider.js#L643-L651 | |
22,707 | soundar24/roundSlider | src/roundslider.js | CreateRoundSlider | function CreateRoundSlider(options, args) {
for (var i = 0; i < this.length; i++) {
var that = this[i], instance = $.data(that, pluginName);
if (!instance) {
var _this = new RoundSlider(that, options);
_this._saveInstanceOnElement();
_this._saveInstanceOnID();
if (_this._raise("beforeCreate") !== false) {
_this._init();
_this._raise("create");
}
else _this._removeData();
}
else if ($.isPlainObject(options)) {
if (typeof instance.option === "function") instance.option(options);
else if (that.id && window[that.id] && typeof window[that.id].option === "function") {
window[that.id].option(options);
}
}
else if (typeof options === "string") {
if (typeof instance[options] === "function") {
if ((options === "option" || options.indexOf("get") === 0) && args[2] === undefined) {
return instance[options](args[1]);
}
instance[options](args[1], args[2]);
}
}
}
return this;
} | javascript | function CreateRoundSlider(options, args) {
for (var i = 0; i < this.length; i++) {
var that = this[i], instance = $.data(that, pluginName);
if (!instance) {
var _this = new RoundSlider(that, options);
_this._saveInstanceOnElement();
_this._saveInstanceOnID();
if (_this._raise("beforeCreate") !== false) {
_this._init();
_this._raise("create");
}
else _this._removeData();
}
else if ($.isPlainObject(options)) {
if (typeof instance.option === "function") instance.option(options);
else if (that.id && window[that.id] && typeof window[that.id].option === "function") {
window[that.id].option(options);
}
}
else if (typeof options === "string") {
if (typeof instance[options] === "function") {
if ((options === "option" || options.indexOf("get") === 0) && args[2] === undefined) {
return instance[options](args[1]);
}
instance[options](args[1], args[2]);
}
}
}
return this;
} | [
"function",
"CreateRoundSlider",
"(",
"options",
",",
"args",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"that",
"=",
"this",
"[",
"i",
"]",
",",
"instance",
"=",
"$",
".",
"data",
"(",
"that",
",",
"pluginName",
")",
";",
"if",
"(",
"!",
"instance",
")",
"{",
"var",
"_this",
"=",
"new",
"RoundSlider",
"(",
"that",
",",
"options",
")",
";",
"_this",
".",
"_saveInstanceOnElement",
"(",
")",
";",
"_this",
".",
"_saveInstanceOnID",
"(",
")",
";",
"if",
"(",
"_this",
".",
"_raise",
"(",
"\"beforeCreate\"",
")",
"!==",
"false",
")",
"{",
"_this",
".",
"_init",
"(",
")",
";",
"_this",
".",
"_raise",
"(",
"\"create\"",
")",
";",
"}",
"else",
"_this",
".",
"_removeData",
"(",
")",
";",
"}",
"else",
"if",
"(",
"$",
".",
"isPlainObject",
"(",
"options",
")",
")",
"{",
"if",
"(",
"typeof",
"instance",
".",
"option",
"===",
"\"function\"",
")",
"instance",
".",
"option",
"(",
"options",
")",
";",
"else",
"if",
"(",
"that",
".",
"id",
"&&",
"window",
"[",
"that",
".",
"id",
"]",
"&&",
"typeof",
"window",
"[",
"that",
".",
"id",
"]",
".",
"option",
"===",
"\"function\"",
")",
"{",
"window",
"[",
"that",
".",
"id",
"]",
".",
"option",
"(",
"options",
")",
";",
"}",
"}",
"else",
"if",
"(",
"typeof",
"options",
"===",
"\"string\"",
")",
"{",
"if",
"(",
"typeof",
"instance",
"[",
"options",
"]",
"===",
"\"function\"",
")",
"{",
"if",
"(",
"(",
"options",
"===",
"\"option\"",
"||",
"options",
".",
"indexOf",
"(",
"\"get\"",
")",
"===",
"0",
")",
"&&",
"args",
"[",
"2",
"]",
"===",
"undefined",
")",
"{",
"return",
"instance",
"[",
"options",
"]",
"(",
"args",
"[",
"1",
"]",
")",
";",
"}",
"instance",
"[",
"options",
"]",
"(",
"args",
"[",
"1",
"]",
",",
"args",
"[",
"2",
"]",
")",
";",
"}",
"}",
"}",
"return",
"this",
";",
"}"
] | The plugin wrapper, prevents multiple instantiations | [
"The",
"plugin",
"wrapper",
"prevents",
"multiple",
"instantiations"
] | b58cd164a894339a4047b568a2202f99dfaa49b8 | https://github.com/soundar24/roundSlider/blob/b58cd164a894339a4047b568a2202f99dfaa49b8/src/roundslider.js#L1215-L1246 |
22,708 | sematext/sematable | src/selectors.js | filter | function filter(rows = [], filters = [], filterText, columns) {
let filteredRows = rows.slice(0);
if (filters.length === 0 && !filterText) {
return filteredRows;
}
const textFilters = [
...(filterText ? [filterText.toLowerCase()] : []),
...filters.filter(f => f.textFilter).map(f => f.value),
];
const valueFilters = filters.filter(f => f.valueFilter);
// apply text filters across all columns
if (textFilters.length > 0) {
filteredRows = _.filter(rows, row => _.some(columns, (column) => {
if (!column.searchable) {
return false;
}
const normalized = String(_.get(row, column.key)).toLowerCase();
return _.every(textFilters, f => normalized.indexOf(f) > -1);
}));
}
// apply value filters on filterable columns
if (valueFilters.length > 0) {
const groups = _.groupBy(valueFilters, 'key');
filteredRows = _.filter(filteredRows, row => _.every(
groups,
(groupFilters, groupKey) => {
const value = _.get(row, groupKey);
return _.some(groupFilters, f => f.value === value);
}
));
}
return filteredRows;
} | javascript | function filter(rows = [], filters = [], filterText, columns) {
let filteredRows = rows.slice(0);
if (filters.length === 0 && !filterText) {
return filteredRows;
}
const textFilters = [
...(filterText ? [filterText.toLowerCase()] : []),
...filters.filter(f => f.textFilter).map(f => f.value),
];
const valueFilters = filters.filter(f => f.valueFilter);
// apply text filters across all columns
if (textFilters.length > 0) {
filteredRows = _.filter(rows, row => _.some(columns, (column) => {
if (!column.searchable) {
return false;
}
const normalized = String(_.get(row, column.key)).toLowerCase();
return _.every(textFilters, f => normalized.indexOf(f) > -1);
}));
}
// apply value filters on filterable columns
if (valueFilters.length > 0) {
const groups = _.groupBy(valueFilters, 'key');
filteredRows = _.filter(filteredRows, row => _.every(
groups,
(groupFilters, groupKey) => {
const value = _.get(row, groupKey);
return _.some(groupFilters, f => f.value === value);
}
));
}
return filteredRows;
} | [
"function",
"filter",
"(",
"rows",
"=",
"[",
"]",
",",
"filters",
"=",
"[",
"]",
",",
"filterText",
",",
"columns",
")",
"{",
"let",
"filteredRows",
"=",
"rows",
".",
"slice",
"(",
"0",
")",
";",
"if",
"(",
"filters",
".",
"length",
"===",
"0",
"&&",
"!",
"filterText",
")",
"{",
"return",
"filteredRows",
";",
"}",
"const",
"textFilters",
"=",
"[",
"...",
"(",
"filterText",
"?",
"[",
"filterText",
".",
"toLowerCase",
"(",
")",
"]",
":",
"[",
"]",
")",
",",
"...",
"filters",
".",
"filter",
"(",
"f",
"=>",
"f",
".",
"textFilter",
")",
".",
"map",
"(",
"f",
"=>",
"f",
".",
"value",
")",
",",
"]",
";",
"const",
"valueFilters",
"=",
"filters",
".",
"filter",
"(",
"f",
"=>",
"f",
".",
"valueFilter",
")",
";",
"// apply text filters across all columns",
"if",
"(",
"textFilters",
".",
"length",
">",
"0",
")",
"{",
"filteredRows",
"=",
"_",
".",
"filter",
"(",
"rows",
",",
"row",
"=>",
"_",
".",
"some",
"(",
"columns",
",",
"(",
"column",
")",
"=>",
"{",
"if",
"(",
"!",
"column",
".",
"searchable",
")",
"{",
"return",
"false",
";",
"}",
"const",
"normalized",
"=",
"String",
"(",
"_",
".",
"get",
"(",
"row",
",",
"column",
".",
"key",
")",
")",
".",
"toLowerCase",
"(",
")",
";",
"return",
"_",
".",
"every",
"(",
"textFilters",
",",
"f",
"=>",
"normalized",
".",
"indexOf",
"(",
"f",
")",
">",
"-",
"1",
")",
";",
"}",
")",
")",
";",
"}",
"// apply value filters on filterable columns",
"if",
"(",
"valueFilters",
".",
"length",
">",
"0",
")",
"{",
"const",
"groups",
"=",
"_",
".",
"groupBy",
"(",
"valueFilters",
",",
"'key'",
")",
";",
"filteredRows",
"=",
"_",
".",
"filter",
"(",
"filteredRows",
",",
"row",
"=>",
"_",
".",
"every",
"(",
"groups",
",",
"(",
"groupFilters",
",",
"groupKey",
")",
"=>",
"{",
"const",
"value",
"=",
"_",
".",
"get",
"(",
"row",
",",
"groupKey",
")",
";",
"return",
"_",
".",
"some",
"(",
"groupFilters",
",",
"f",
"=>",
"f",
".",
"value",
"===",
"value",
")",
";",
"}",
")",
")",
";",
"}",
"return",
"filteredRows",
";",
"}"
] | rows - original data
filters - list of selected filters
filterText - currently entered text in filter input
columns - column definitions | [
"rows",
"-",
"original",
"data",
"filters",
"-",
"list",
"of",
"selected",
"filters",
"filterText",
"-",
"currently",
"entered",
"text",
"in",
"filter",
"input",
"columns",
"-",
"column",
"definitions"
] | 1572a90fb2a29ccb2626a451b951413491379fbe | https://github.com/sematext/sematable/blob/1572a90fb2a29ccb2626a451b951413491379fbe/src/selectors.js#L21-L58 |
22,709 | MazeMap/Leaflet.LayerGroup.Collision | src/Leaflet.LayerGroup.Collision.js | function (el) {
if (isMSIE8) {
// Fallback for MSIE8, will most probably fail on edge cases
return [ 0, 0, el.offsetWidth, el.offsetHeight];
}
var styles = window.getComputedStyle(el);
// getComputedStyle() should return values already in pixels, so using parseInt()
// is not as much as a hack as it seems to be.
return [
parseInt(styles.marginLeft),
parseInt(styles.marginTop),
parseInt(styles.marginLeft) + parseInt(styles.width),
parseInt(styles.marginTop) + parseInt(styles.height)
];
} | javascript | function (el) {
if (isMSIE8) {
// Fallback for MSIE8, will most probably fail on edge cases
return [ 0, 0, el.offsetWidth, el.offsetHeight];
}
var styles = window.getComputedStyle(el);
// getComputedStyle() should return values already in pixels, so using parseInt()
// is not as much as a hack as it seems to be.
return [
parseInt(styles.marginLeft),
parseInt(styles.marginTop),
parseInt(styles.marginLeft) + parseInt(styles.width),
parseInt(styles.marginTop) + parseInt(styles.height)
];
} | [
"function",
"(",
"el",
")",
"{",
"if",
"(",
"isMSIE8",
")",
"{",
"// Fallback for MSIE8, will most probably fail on edge cases",
"return",
"[",
"0",
",",
"0",
",",
"el",
".",
"offsetWidth",
",",
"el",
".",
"offsetHeight",
"]",
";",
"}",
"var",
"styles",
"=",
"window",
".",
"getComputedStyle",
"(",
"el",
")",
";",
"// getComputedStyle() should return values already in pixels, so using parseInt()",
"// is not as much as a hack as it seems to be.",
"return",
"[",
"parseInt",
"(",
"styles",
".",
"marginLeft",
")",
",",
"parseInt",
"(",
"styles",
".",
"marginTop",
")",
",",
"parseInt",
"(",
"styles",
".",
"marginLeft",
")",
"+",
"parseInt",
"(",
"styles",
".",
"width",
")",
",",
"parseInt",
"(",
"styles",
".",
"marginTop",
")",
"+",
"parseInt",
"(",
"styles",
".",
"height",
")",
"]",
";",
"}"
] | Returns a plain array with the relative dimensions of a L.Icon, based on the computed values from iconSize and iconAnchor. | [
"Returns",
"a",
"plain",
"array",
"with",
"the",
"relative",
"dimensions",
"of",
"a",
"L",
".",
"Icon",
"based",
"on",
"the",
"computed",
"values",
"from",
"iconSize",
"and",
"iconAnchor",
"."
] | 9543cab71dd2494f930d4ddce464e7742404cc28 | https://github.com/MazeMap/Leaflet.LayerGroup.Collision/blob/9543cab71dd2494f930d4ddce464e7742404cc28/src/Leaflet.LayerGroup.Collision.js#L122-L140 | |
22,710 | npm/npmconf | lib/load-uid.js | loadUid | function loadUid (cb) {
// if we're not in unsafe-perm mode, then figure out who
// to run stuff as. Do this first, to support `npm update npm -g`
if (!this.get("unsafe-perm")) {
getUid(this.get("user"), this.get("group"), cb)
} else {
process.nextTick(cb)
}
} | javascript | function loadUid (cb) {
// if we're not in unsafe-perm mode, then figure out who
// to run stuff as. Do this first, to support `npm update npm -g`
if (!this.get("unsafe-perm")) {
getUid(this.get("user"), this.get("group"), cb)
} else {
process.nextTick(cb)
}
} | [
"function",
"loadUid",
"(",
"cb",
")",
"{",
"// if we're not in unsafe-perm mode, then figure out who",
"// to run stuff as. Do this first, to support `npm update npm -g`",
"if",
"(",
"!",
"this",
".",
"get",
"(",
"\"unsafe-perm\"",
")",
")",
"{",
"getUid",
"(",
"this",
".",
"get",
"(",
"\"user\"",
")",
",",
"this",
".",
"get",
"(",
"\"group\"",
")",
",",
"cb",
")",
"}",
"else",
"{",
"process",
".",
"nextTick",
"(",
"cb",
")",
"}",
"}"
] | Call in the context of a npmconf object | [
"Call",
"in",
"the",
"context",
"of",
"a",
"npmconf",
"object"
] | 22827e4038d6eebaafeb5c13ed2b92cf97b8fb82 | https://github.com/npm/npmconf/blob/22827e4038d6eebaafeb5c13ed2b92cf97b8fb82/lib/load-uid.js#L7-L15 |
22,711 | Alex1990/tiny-cookie | src/util.js | computeExpires | function computeExpires(str) {
const lastCh = str.charAt(str.length - 1);
const value = parseInt(str, 10);
let expires = new Date();
switch (lastCh) {
case 'Y': expires.setFullYear(expires.getFullYear() + value); break;
case 'M': expires.setMonth(expires.getMonth() + value); break;
case 'D': expires.setDate(expires.getDate() + value); break;
case 'h': expires.setHours(expires.getHours() + value); break;
case 'm': expires.setMinutes(expires.getMinutes() + value); break;
case 's': expires.setSeconds(expires.getSeconds() + value); break;
default: expires = new Date(str);
}
return expires;
} | javascript | function computeExpires(str) {
const lastCh = str.charAt(str.length - 1);
const value = parseInt(str, 10);
let expires = new Date();
switch (lastCh) {
case 'Y': expires.setFullYear(expires.getFullYear() + value); break;
case 'M': expires.setMonth(expires.getMonth() + value); break;
case 'D': expires.setDate(expires.getDate() + value); break;
case 'h': expires.setHours(expires.getHours() + value); break;
case 'm': expires.setMinutes(expires.getMinutes() + value); break;
case 's': expires.setSeconds(expires.getSeconds() + value); break;
default: expires = new Date(str);
}
return expires;
} | [
"function",
"computeExpires",
"(",
"str",
")",
"{",
"const",
"lastCh",
"=",
"str",
".",
"charAt",
"(",
"str",
".",
"length",
"-",
"1",
")",
";",
"const",
"value",
"=",
"parseInt",
"(",
"str",
",",
"10",
")",
";",
"let",
"expires",
"=",
"new",
"Date",
"(",
")",
";",
"switch",
"(",
"lastCh",
")",
"{",
"case",
"'Y'",
":",
"expires",
".",
"setFullYear",
"(",
"expires",
".",
"getFullYear",
"(",
")",
"+",
"value",
")",
";",
"break",
";",
"case",
"'M'",
":",
"expires",
".",
"setMonth",
"(",
"expires",
".",
"getMonth",
"(",
")",
"+",
"value",
")",
";",
"break",
";",
"case",
"'D'",
":",
"expires",
".",
"setDate",
"(",
"expires",
".",
"getDate",
"(",
")",
"+",
"value",
")",
";",
"break",
";",
"case",
"'h'",
":",
"expires",
".",
"setHours",
"(",
"expires",
".",
"getHours",
"(",
")",
"+",
"value",
")",
";",
"break",
";",
"case",
"'m'",
":",
"expires",
".",
"setMinutes",
"(",
"expires",
".",
"getMinutes",
"(",
")",
"+",
"value",
")",
";",
"break",
";",
"case",
"'s'",
":",
"expires",
".",
"setSeconds",
"(",
"expires",
".",
"getSeconds",
"(",
")",
"+",
"value",
")",
";",
"break",
";",
"default",
":",
"expires",
"=",
"new",
"Date",
"(",
"str",
")",
";",
"}",
"return",
"expires",
";",
"}"
] | Return a future date by the given string. | [
"Return",
"a",
"future",
"date",
"by",
"the",
"given",
"string",
"."
] | 6fcecdb044465cf35fe0653b7ab6a495c697c3cc | https://github.com/Alex1990/tiny-cookie/blob/6fcecdb044465cf35fe0653b7ab6a495c697c3cc/src/util.js#L11-L27 |
22,712 | Alex1990/tiny-cookie | src/util.js | convert | function convert(opts) {
let res = '';
// eslint-disable-next-line
for (const key in opts) {
if (hasOwn(opts, key)) {
if (/^expires$/i.test(key)) {
let expires = opts[key];
if (typeof expires !== 'object') {
expires += typeof expires === 'number' ? 'D' : '';
expires = computeExpires(expires);
}
res += `;${key}=${expires.toUTCString()}`;
} else if (/^secure$/.test(key)) {
if (opts[key]) {
res += `;${key}`;
}
} else {
res += `;${key}=${opts[key]}`;
}
}
}
if (!hasOwn(opts, 'path')) {
res += ';path=/';
}
return res;
} | javascript | function convert(opts) {
let res = '';
// eslint-disable-next-line
for (const key in opts) {
if (hasOwn(opts, key)) {
if (/^expires$/i.test(key)) {
let expires = opts[key];
if (typeof expires !== 'object') {
expires += typeof expires === 'number' ? 'D' : '';
expires = computeExpires(expires);
}
res += `;${key}=${expires.toUTCString()}`;
} else if (/^secure$/.test(key)) {
if (opts[key]) {
res += `;${key}`;
}
} else {
res += `;${key}=${opts[key]}`;
}
}
}
if (!hasOwn(opts, 'path')) {
res += ';path=/';
}
return res;
} | [
"function",
"convert",
"(",
"opts",
")",
"{",
"let",
"res",
"=",
"''",
";",
"// eslint-disable-next-line",
"for",
"(",
"const",
"key",
"in",
"opts",
")",
"{",
"if",
"(",
"hasOwn",
"(",
"opts",
",",
"key",
")",
")",
"{",
"if",
"(",
"/",
"^expires$",
"/",
"i",
".",
"test",
"(",
"key",
")",
")",
"{",
"let",
"expires",
"=",
"opts",
"[",
"key",
"]",
";",
"if",
"(",
"typeof",
"expires",
"!==",
"'object'",
")",
"{",
"expires",
"+=",
"typeof",
"expires",
"===",
"'number'",
"?",
"'D'",
":",
"''",
";",
"expires",
"=",
"computeExpires",
"(",
"expires",
")",
";",
"}",
"res",
"+=",
"`",
"${",
"key",
"}",
"${",
"expires",
".",
"toUTCString",
"(",
")",
"}",
"`",
";",
"}",
"else",
"if",
"(",
"/",
"^secure$",
"/",
".",
"test",
"(",
"key",
")",
")",
"{",
"if",
"(",
"opts",
"[",
"key",
"]",
")",
"{",
"res",
"+=",
"`",
"${",
"key",
"}",
"`",
";",
"}",
"}",
"else",
"{",
"res",
"+=",
"`",
"${",
"key",
"}",
"${",
"opts",
"[",
"key",
"]",
"}",
"`",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"hasOwn",
"(",
"opts",
",",
"'path'",
")",
")",
"{",
"res",
"+=",
"';path=/'",
";",
"}",
"return",
"res",
";",
"}"
] | Convert an object to a cookie option string. | [
"Convert",
"an",
"object",
"to",
"a",
"cookie",
"option",
"string",
"."
] | 6fcecdb044465cf35fe0653b7ab6a495c697c3cc | https://github.com/Alex1990/tiny-cookie/blob/6fcecdb044465cf35fe0653b7ab6a495c697c3cc/src/util.js#L30-L59 |
22,713 | Alex1990/tiny-cookie | src/index.js | isEnabled | function isEnabled() {
const key = '@key@';
const value = '1';
const re = new RegExp(`(?:^|; )${key}=${value}(?:;|$)`);
document.cookie = `${key}=${value}`;
const enabled = re.test(document.cookie);
if (enabled) {
// eslint-disable-next-line
remove(key);
}
return enabled;
} | javascript | function isEnabled() {
const key = '@key@';
const value = '1';
const re = new RegExp(`(?:^|; )${key}=${value}(?:;|$)`);
document.cookie = `${key}=${value}`;
const enabled = re.test(document.cookie);
if (enabled) {
// eslint-disable-next-line
remove(key);
}
return enabled;
} | [
"function",
"isEnabled",
"(",
")",
"{",
"const",
"key",
"=",
"'@key@'",
";",
"const",
"value",
"=",
"'1'",
";",
"const",
"re",
"=",
"new",
"RegExp",
"(",
"`",
"${",
"key",
"}",
"${",
"value",
"}",
"`",
")",
";",
"document",
".",
"cookie",
"=",
"`",
"${",
"key",
"}",
"${",
"value",
"}",
"`",
";",
"const",
"enabled",
"=",
"re",
".",
"test",
"(",
"document",
".",
"cookie",
")",
";",
"if",
"(",
"enabled",
")",
"{",
"// eslint-disable-next-line",
"remove",
"(",
"key",
")",
";",
"}",
"return",
"enabled",
";",
"}"
] | Check if the browser cookie is enabled. | [
"Check",
"if",
"the",
"browser",
"cookie",
"is",
"enabled",
"."
] | 6fcecdb044465cf35fe0653b7ab6a495c697c3cc | https://github.com/Alex1990/tiny-cookie/blob/6fcecdb044465cf35fe0653b7ab6a495c697c3cc/src/index.js#L4-L19 |
22,714 | Alex1990/tiny-cookie | src/index.js | get | function get(key, decoder = decodeURIComponent) {
if ((typeof key !== 'string') || !key) {
return null;
}
const reKey = new RegExp(`(?:^|; )${escapeRe(key)}(?:=([^;]*))?(?:;|$)`);
const match = reKey.exec(document.cookie);
if (match === null) {
return null;
}
return typeof decoder === 'function' ? decoder(match[1]) : match[1];
} | javascript | function get(key, decoder = decodeURIComponent) {
if ((typeof key !== 'string') || !key) {
return null;
}
const reKey = new RegExp(`(?:^|; )${escapeRe(key)}(?:=([^;]*))?(?:;|$)`);
const match = reKey.exec(document.cookie);
if (match === null) {
return null;
}
return typeof decoder === 'function' ? decoder(match[1]) : match[1];
} | [
"function",
"get",
"(",
"key",
",",
"decoder",
"=",
"decodeURIComponent",
")",
"{",
"if",
"(",
"(",
"typeof",
"key",
"!==",
"'string'",
")",
"||",
"!",
"key",
")",
"{",
"return",
"null",
";",
"}",
"const",
"reKey",
"=",
"new",
"RegExp",
"(",
"`",
"${",
"escapeRe",
"(",
"key",
")",
"}",
"`",
")",
";",
"const",
"match",
"=",
"reKey",
".",
"exec",
"(",
"document",
".",
"cookie",
")",
";",
"if",
"(",
"match",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"return",
"typeof",
"decoder",
"===",
"'function'",
"?",
"decoder",
"(",
"match",
"[",
"1",
"]",
")",
":",
"match",
"[",
"1",
"]",
";",
"}"
] | Get the cookie value by key. | [
"Get",
"the",
"cookie",
"value",
"by",
"key",
"."
] | 6fcecdb044465cf35fe0653b7ab6a495c697c3cc | https://github.com/Alex1990/tiny-cookie/blob/6fcecdb044465cf35fe0653b7ab6a495c697c3cc/src/index.js#L22-L35 |
22,715 | Alex1990/tiny-cookie | src/index.js | getAll | function getAll(decoder = decodeURIComponent) {
const reKey = /(?:^|; )([^=]+?)(?:=([^;]*))?(?:;|$)/g;
const cookies = {};
let match;
/* eslint-disable no-cond-assign */
while ((match = reKey.exec(document.cookie))) {
reKey.lastIndex = (match.index + match.length) - 1;
cookies[match[1]] = typeof decoder === 'function' ? decoder(match[2]) : match[2];
}
return cookies;
} | javascript | function getAll(decoder = decodeURIComponent) {
const reKey = /(?:^|; )([^=]+?)(?:=([^;]*))?(?:;|$)/g;
const cookies = {};
let match;
/* eslint-disable no-cond-assign */
while ((match = reKey.exec(document.cookie))) {
reKey.lastIndex = (match.index + match.length) - 1;
cookies[match[1]] = typeof decoder === 'function' ? decoder(match[2]) : match[2];
}
return cookies;
} | [
"function",
"getAll",
"(",
"decoder",
"=",
"decodeURIComponent",
")",
"{",
"const",
"reKey",
"=",
"/",
"(?:^|; )([^=]+?)(?:=([^;]*))?(?:;|$)",
"/",
"g",
";",
"const",
"cookies",
"=",
"{",
"}",
";",
"let",
"match",
";",
"/* eslint-disable no-cond-assign */",
"while",
"(",
"(",
"match",
"=",
"reKey",
".",
"exec",
"(",
"document",
".",
"cookie",
")",
")",
")",
"{",
"reKey",
".",
"lastIndex",
"=",
"(",
"match",
".",
"index",
"+",
"match",
".",
"length",
")",
"-",
"1",
";",
"cookies",
"[",
"match",
"[",
"1",
"]",
"]",
"=",
"typeof",
"decoder",
"===",
"'function'",
"?",
"decoder",
"(",
"match",
"[",
"2",
"]",
")",
":",
"match",
"[",
"2",
"]",
";",
"}",
"return",
"cookies",
";",
"}"
] | The all cookies | [
"The",
"all",
"cookies"
] | 6fcecdb044465cf35fe0653b7ab6a495c697c3cc | https://github.com/Alex1990/tiny-cookie/blob/6fcecdb044465cf35fe0653b7ab6a495c697c3cc/src/index.js#L38-L50 |
22,716 | Alex1990/tiny-cookie | src/index.js | remove | function remove(key, options) {
let opts = { expires: -1 };
if (options) {
opts = { ...options, ...opts };
}
return set(key, 'a', opts);
} | javascript | function remove(key, options) {
let opts = { expires: -1 };
if (options) {
opts = { ...options, ...opts };
}
return set(key, 'a', opts);
} | [
"function",
"remove",
"(",
"key",
",",
"options",
")",
"{",
"let",
"opts",
"=",
"{",
"expires",
":",
"-",
"1",
"}",
";",
"if",
"(",
"options",
")",
"{",
"opts",
"=",
"{",
"...",
"options",
",",
"...",
"opts",
"}",
";",
"}",
"return",
"set",
"(",
"key",
",",
"'a'",
",",
"opts",
")",
";",
"}"
] | Remove a cookie by the specified key. | [
"Remove",
"a",
"cookie",
"by",
"the",
"specified",
"key",
"."
] | 6fcecdb044465cf35fe0653b7ab6a495c697c3cc | https://github.com/Alex1990/tiny-cookie/blob/6fcecdb044465cf35fe0653b7ab6a495c697c3cc/src/index.js#L67-L75 |
22,717 | helior/react-highlighter | lib/highlighter.js | function(subject) {
if (this.isScalar() && this.hasSearch()) {
var search = this.getSearch();
return this.highlightChildren(subject, search);
}
return this.props.children;
} | javascript | function(subject) {
if (this.isScalar() && this.hasSearch()) {
var search = this.getSearch();
return this.highlightChildren(subject, search);
}
return this.props.children;
} | [
"function",
"(",
"subject",
")",
"{",
"if",
"(",
"this",
".",
"isScalar",
"(",
")",
"&&",
"this",
".",
"hasSearch",
"(",
")",
")",
"{",
"var",
"search",
"=",
"this",
".",
"getSearch",
"(",
")",
";",
"return",
"this",
".",
"highlightChildren",
"(",
"subject",
",",
"search",
")",
";",
"}",
"return",
"this",
".",
"props",
".",
"children",
";",
"}"
] | A wrapper to the highlight method to determine when the highlighting
process should occur.
@param {string} subject
The body of text that will be searched for highlighted words.
@return {Array}
An array of ReactElements | [
"A",
"wrapper",
"to",
"the",
"highlight",
"method",
"to",
"determine",
"when",
"the",
"highlighting",
"process",
"should",
"occur",
"."
] | 9c59bfe8a19bc8df1fa02cb2298a94a6bbb13b3f | https://github.com/helior/react-highlighter/blob/9c59bfe8a19bc8df1fa02cb2298a94a6bbb13b3f/lib/highlighter.js#L72-L79 | |
22,718 | helior/react-highlighter | lib/highlighter.js | function() {
if (this.props.search instanceof RegExp) {
return this.props.search;
}
var flags = '';
if (!this.props.caseSensitive) {
flags +='i';
}
var search = this.props.search;
if (typeof this.props.search === 'string') {
search = escapeStringRegexp(search);
}
if (this.props.ignoreDiacritics) {
search = removeDiacritics(search, this.props.diacriticsBlacklist);
}
return new RegExp(search, flags);
} | javascript | function() {
if (this.props.search instanceof RegExp) {
return this.props.search;
}
var flags = '';
if (!this.props.caseSensitive) {
flags +='i';
}
var search = this.props.search;
if (typeof this.props.search === 'string') {
search = escapeStringRegexp(search);
}
if (this.props.ignoreDiacritics) {
search = removeDiacritics(search, this.props.diacriticsBlacklist);
}
return new RegExp(search, flags);
} | [
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"props",
".",
"search",
"instanceof",
"RegExp",
")",
"{",
"return",
"this",
".",
"props",
".",
"search",
";",
"}",
"var",
"flags",
"=",
"''",
";",
"if",
"(",
"!",
"this",
".",
"props",
".",
"caseSensitive",
")",
"{",
"flags",
"+=",
"'i'",
";",
"}",
"var",
"search",
"=",
"this",
".",
"props",
".",
"search",
";",
"if",
"(",
"typeof",
"this",
".",
"props",
".",
"search",
"===",
"'string'",
")",
"{",
"search",
"=",
"escapeStringRegexp",
"(",
"search",
")",
";",
"}",
"if",
"(",
"this",
".",
"props",
".",
"ignoreDiacritics",
")",
"{",
"search",
"=",
"removeDiacritics",
"(",
"search",
",",
"this",
".",
"props",
".",
"diacriticsBlacklist",
")",
";",
"}",
"return",
"new",
"RegExp",
"(",
"search",
",",
"flags",
")",
";",
"}"
] | Get the search prop, but always in the form of a regular expression. Use
this as a proxy to this.props.search for consistency.
@return {RegExp} | [
"Get",
"the",
"search",
"prop",
"but",
"always",
"in",
"the",
"form",
"of",
"a",
"regular",
"expression",
".",
"Use",
"this",
"as",
"a",
"proxy",
"to",
"this",
".",
"props",
".",
"search",
"for",
"consistency",
"."
] | 9c59bfe8a19bc8df1fa02cb2298a94a6bbb13b3f | https://github.com/helior/react-highlighter/blob/9c59bfe8a19bc8df1fa02cb2298a94a6bbb13b3f/lib/highlighter.js#L105-L125 | |
22,719 | helior/react-highlighter | lib/highlighter.js | function(subject, search) {
var matches = search.exec(subject);
if (matches) {
return {
first: matches.index,
last: matches.index + matches[0].length
};
}
} | javascript | function(subject, search) {
var matches = search.exec(subject);
if (matches) {
return {
first: matches.index,
last: matches.index + matches[0].length
};
}
} | [
"function",
"(",
"subject",
",",
"search",
")",
"{",
"var",
"matches",
"=",
"search",
".",
"exec",
"(",
"subject",
")",
";",
"if",
"(",
"matches",
")",
"{",
"return",
"{",
"first",
":",
"matches",
".",
"index",
",",
"last",
":",
"matches",
".",
"index",
"+",
"matches",
"[",
"0",
"]",
".",
"length",
"}",
";",
"}",
"}"
] | Get the indexes of the first and last characters of the matched string.
@param {string} subject
The string to search against.
@param {RegExp} search
The regex search query.
@return {Object}
An object consisting of "first" and "last" properties representing the
indexes of the first and last characters of a matching string. | [
"Get",
"the",
"indexes",
"of",
"the",
"first",
"and",
"last",
"characters",
"of",
"the",
"matched",
"string",
"."
] | 9c59bfe8a19bc8df1fa02cb2298a94a6bbb13b3f | https://github.com/helior/react-highlighter/blob/9c59bfe8a19bc8df1fa02cb2298a94a6bbb13b3f/lib/highlighter.js#L140-L148 | |
22,720 | helior/react-highlighter | lib/highlighter.js | function(subject, search) {
var children = [];
var remaining = subject;
while (remaining) {
var remainingCleaned = (this.props.ignoreDiacritics
? removeDiacritics(remaining, this.props.diacriticsBlacklist)
: remaining
);
if (!search.test(remainingCleaned)) {
children.push(this.renderPlain(remaining));
return children;
}
var boundaries = this.getMatchBoundaries(remainingCleaned, search);
if (boundaries.first === 0 && boundaries.last === 0) {
// Regex zero-width match
return children;
}
// Capture the string that leads up to a match...
var nonMatch = remaining.slice(0, boundaries.first);
if (nonMatch) {
children.push(this.renderPlain(nonMatch));
}
// Now, capture the matching string...
var match = remaining.slice(boundaries.first, boundaries.last);
if (match) {
children.push(this.renderHighlight(match));
}
// And if there's anything left over, recursively run this method again.
remaining = remaining.slice(boundaries.last);
}
return children;
} | javascript | function(subject, search) {
var children = [];
var remaining = subject;
while (remaining) {
var remainingCleaned = (this.props.ignoreDiacritics
? removeDiacritics(remaining, this.props.diacriticsBlacklist)
: remaining
);
if (!search.test(remainingCleaned)) {
children.push(this.renderPlain(remaining));
return children;
}
var boundaries = this.getMatchBoundaries(remainingCleaned, search);
if (boundaries.first === 0 && boundaries.last === 0) {
// Regex zero-width match
return children;
}
// Capture the string that leads up to a match...
var nonMatch = remaining.slice(0, boundaries.first);
if (nonMatch) {
children.push(this.renderPlain(nonMatch));
}
// Now, capture the matching string...
var match = remaining.slice(boundaries.first, boundaries.last);
if (match) {
children.push(this.renderHighlight(match));
}
// And if there's anything left over, recursively run this method again.
remaining = remaining.slice(boundaries.last);
}
return children;
} | [
"function",
"(",
"subject",
",",
"search",
")",
"{",
"var",
"children",
"=",
"[",
"]",
";",
"var",
"remaining",
"=",
"subject",
";",
"while",
"(",
"remaining",
")",
"{",
"var",
"remainingCleaned",
"=",
"(",
"this",
".",
"props",
".",
"ignoreDiacritics",
"?",
"removeDiacritics",
"(",
"remaining",
",",
"this",
".",
"props",
".",
"diacriticsBlacklist",
")",
":",
"remaining",
")",
";",
"if",
"(",
"!",
"search",
".",
"test",
"(",
"remainingCleaned",
")",
")",
"{",
"children",
".",
"push",
"(",
"this",
".",
"renderPlain",
"(",
"remaining",
")",
")",
";",
"return",
"children",
";",
"}",
"var",
"boundaries",
"=",
"this",
".",
"getMatchBoundaries",
"(",
"remainingCleaned",
",",
"search",
")",
";",
"if",
"(",
"boundaries",
".",
"first",
"===",
"0",
"&&",
"boundaries",
".",
"last",
"===",
"0",
")",
"{",
"// Regex zero-width match",
"return",
"children",
";",
"}",
"// Capture the string that leads up to a match...",
"var",
"nonMatch",
"=",
"remaining",
".",
"slice",
"(",
"0",
",",
"boundaries",
".",
"first",
")",
";",
"if",
"(",
"nonMatch",
")",
"{",
"children",
".",
"push",
"(",
"this",
".",
"renderPlain",
"(",
"nonMatch",
")",
")",
";",
"}",
"// Now, capture the matching string...",
"var",
"match",
"=",
"remaining",
".",
"slice",
"(",
"boundaries",
".",
"first",
",",
"boundaries",
".",
"last",
")",
";",
"if",
"(",
"match",
")",
"{",
"children",
".",
"push",
"(",
"this",
".",
"renderHighlight",
"(",
"match",
")",
")",
";",
"}",
"// And if there's anything left over, recursively run this method again.",
"remaining",
"=",
"remaining",
".",
"slice",
"(",
"boundaries",
".",
"last",
")",
";",
"}",
"return",
"children",
";",
"}"
] | Determines which strings of text should be highlighted or not.
@param {string} subject
The body of text that will be searched for highlighted words.
@param {string} search
The search used to search for highlighted words.
@return {Array}
An array of ReactElements | [
"Determines",
"which",
"strings",
"of",
"text",
"should",
"be",
"highlighted",
"or",
"not",
"."
] | 9c59bfe8a19bc8df1fa02cb2298a94a6bbb13b3f | https://github.com/helior/react-highlighter/blob/9c59bfe8a19bc8df1fa02cb2298a94a6bbb13b3f/lib/highlighter.js#L161-L201 | |
22,721 | helior/react-highlighter | lib/highlighter.js | function(string) {
this.count++;
return React.createElement(this.props.matchElement, {
key: this.count,
className: this.props.matchClass,
style: this.props.matchStyle,
children: string
});
} | javascript | function(string) {
this.count++;
return React.createElement(this.props.matchElement, {
key: this.count,
className: this.props.matchClass,
style: this.props.matchStyle,
children: string
});
} | [
"function",
"(",
"string",
")",
"{",
"this",
".",
"count",
"++",
";",
"return",
"React",
".",
"createElement",
"(",
"this",
".",
"props",
".",
"matchElement",
",",
"{",
"key",
":",
"this",
".",
"count",
",",
"className",
":",
"this",
".",
"props",
".",
"matchClass",
",",
"style",
":",
"this",
".",
"props",
".",
"matchStyle",
",",
"children",
":",
"string",
"}",
")",
";",
"}"
] | Responsible for rending a highlighted element.
@param {string} string
A string value to wrap an element around.
@return {ReactElement} | [
"Responsible",
"for",
"rending",
"a",
"highlighted",
"element",
"."
] | 9c59bfe8a19bc8df1fa02cb2298a94a6bbb13b3f | https://github.com/helior/react-highlighter/blob/9c59bfe8a19bc8df1fa02cb2298a94a6bbb13b3f/lib/highlighter.js#L224-L232 | |
22,722 | iVis-at-Bilkent/cytoscape.js-expand-collapse | src/cueUtilities.js | function(node, e){
if (node){
var currMousePos = e.position || e.cyPosition;
var topLeft = {
x: (node.position("x") - node.width() / 2 - parseFloat(node.css('padding-left'))),
y: (node.position("y") - node.height() / 2 - parseFloat(node.css('padding-top')))};
var bottomRight = {
x: (node.position("x") + node.width() / 2 + parseFloat(node.css('padding-right'))),
y: (node.position("y") + node.height() / 2+ parseFloat(node.css('padding-bottom')))};
if (currMousePos.x >= topLeft.x && currMousePos.y >= topLeft.y &&
currMousePos.x <= bottomRight.x && currMousePos.y <= bottomRight.y){
return true;
}
}
return false;
} | javascript | function(node, e){
if (node){
var currMousePos = e.position || e.cyPosition;
var topLeft = {
x: (node.position("x") - node.width() / 2 - parseFloat(node.css('padding-left'))),
y: (node.position("y") - node.height() / 2 - parseFloat(node.css('padding-top')))};
var bottomRight = {
x: (node.position("x") + node.width() / 2 + parseFloat(node.css('padding-right'))),
y: (node.position("y") + node.height() / 2+ parseFloat(node.css('padding-bottom')))};
if (currMousePos.x >= topLeft.x && currMousePos.y >= topLeft.y &&
currMousePos.x <= bottomRight.x && currMousePos.y <= bottomRight.y){
return true;
}
}
return false;
} | [
"function",
"(",
"node",
",",
"e",
")",
"{",
"if",
"(",
"node",
")",
"{",
"var",
"currMousePos",
"=",
"e",
".",
"position",
"||",
"e",
".",
"cyPosition",
";",
"var",
"topLeft",
"=",
"{",
"x",
":",
"(",
"node",
".",
"position",
"(",
"\"x\"",
")",
"-",
"node",
".",
"width",
"(",
")",
"/",
"2",
"-",
"parseFloat",
"(",
"node",
".",
"css",
"(",
"'padding-left'",
")",
")",
")",
",",
"y",
":",
"(",
"node",
".",
"position",
"(",
"\"y\"",
")",
"-",
"node",
".",
"height",
"(",
")",
"/",
"2",
"-",
"parseFloat",
"(",
"node",
".",
"css",
"(",
"'padding-top'",
")",
")",
")",
"}",
";",
"var",
"bottomRight",
"=",
"{",
"x",
":",
"(",
"node",
".",
"position",
"(",
"\"x\"",
")",
"+",
"node",
".",
"width",
"(",
")",
"/",
"2",
"+",
"parseFloat",
"(",
"node",
".",
"css",
"(",
"'padding-right'",
")",
")",
")",
",",
"y",
":",
"(",
"node",
".",
"position",
"(",
"\"y\"",
")",
"+",
"node",
".",
"height",
"(",
")",
"/",
"2",
"+",
"parseFloat",
"(",
"node",
".",
"css",
"(",
"'padding-bottom'",
")",
")",
")",
"}",
";",
"if",
"(",
"currMousePos",
".",
"x",
">=",
"topLeft",
".",
"x",
"&&",
"currMousePos",
".",
"y",
">=",
"topLeft",
".",
"y",
"&&",
"currMousePos",
".",
"x",
"<=",
"bottomRight",
".",
"x",
"&&",
"currMousePos",
".",
"y",
"<=",
"bottomRight",
".",
"y",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | check if mouse is inside given node | [
"check",
"if",
"mouse",
"is",
"inside",
"given",
"node"
] | 8a2e4157def5613e0e477e393dc2c0720e41c032 | https://github.com/iVis-at-Bilkent/cytoscape.js-expand-collapse/blob/8a2e4157def5613e0e477e393dc2c0720e41c032/src/cueUtilities.js#L208-L224 | |
22,723 | iVis-at-Bilkent/cytoscape.js-expand-collapse | src/index.js | evalOptions | function evalOptions(options) {
var animate = typeof options.animate === 'function' ? options.animate.call() : options.animate;
var fisheye = typeof options.fisheye === 'function' ? options.fisheye.call() : options.fisheye;
options.animate = animate;
options.fisheye = fisheye;
} | javascript | function evalOptions(options) {
var animate = typeof options.animate === 'function' ? options.animate.call() : options.animate;
var fisheye = typeof options.fisheye === 'function' ? options.fisheye.call() : options.fisheye;
options.animate = animate;
options.fisheye = fisheye;
} | [
"function",
"evalOptions",
"(",
"options",
")",
"{",
"var",
"animate",
"=",
"typeof",
"options",
".",
"animate",
"===",
"'function'",
"?",
"options",
".",
"animate",
".",
"call",
"(",
")",
":",
"options",
".",
"animate",
";",
"var",
"fisheye",
"=",
"typeof",
"options",
".",
"fisheye",
"===",
"'function'",
"?",
"options",
".",
"fisheye",
".",
"call",
"(",
")",
":",
"options",
".",
"fisheye",
";",
"options",
".",
"animate",
"=",
"animate",
";",
"options",
".",
"fisheye",
"=",
"fisheye",
";",
"}"
] | evaluate some specific options in case of they are specified as functions to be dynamically changed | [
"evaluate",
"some",
"specific",
"options",
"in",
"case",
"of",
"they",
"are",
"specified",
"as",
"functions",
"to",
"be",
"dynamically",
"changed"
] | 8a2e4157def5613e0e477e393dc2c0720e41c032 | https://github.com/iVis-at-Bilkent/cytoscape.js-expand-collapse/blob/8a2e4157def5613e0e477e393dc2c0720e41c032/src/index.js#L27-L33 |
22,724 | iVis-at-Bilkent/cytoscape.js-expand-collapse | src/expandCollapseUtilities.js | function (nodes, options) {
// If there is just one node to expand we need to animate for fisheye view, but if there are more then one node we do not
if (nodes.length === 1) {
var node = nodes[0];
if (node._private.data.collapsedChildren != null) {
// Expand the given node the third parameter indicates that the node is simple which ensures that fisheye parameter will be considered
this.expandNode(node, options.fisheye, true, options.animate, options.layoutBy);
}
}
else {
// First expand given nodes and then perform layout according to the layoutBy parameter
this.simpleExpandGivenNodes(nodes, options.fisheye);
this.endOperation(options.layoutBy);
}
/*
* return the nodes to undo the operation
*/
return nodes;
} | javascript | function (nodes, options) {
// If there is just one node to expand we need to animate for fisheye view, but if there are more then one node we do not
if (nodes.length === 1) {
var node = nodes[0];
if (node._private.data.collapsedChildren != null) {
// Expand the given node the third parameter indicates that the node is simple which ensures that fisheye parameter will be considered
this.expandNode(node, options.fisheye, true, options.animate, options.layoutBy);
}
}
else {
// First expand given nodes and then perform layout according to the layoutBy parameter
this.simpleExpandGivenNodes(nodes, options.fisheye);
this.endOperation(options.layoutBy);
}
/*
* return the nodes to undo the operation
*/
return nodes;
} | [
"function",
"(",
"nodes",
",",
"options",
")",
"{",
"// If there is just one node to expand we need to animate for fisheye view, but if there are more then one node we do not",
"if",
"(",
"nodes",
".",
"length",
"===",
"1",
")",
"{",
"var",
"node",
"=",
"nodes",
"[",
"0",
"]",
";",
"if",
"(",
"node",
".",
"_private",
".",
"data",
".",
"collapsedChildren",
"!=",
"null",
")",
"{",
"// Expand the given node the third parameter indicates that the node is simple which ensures that fisheye parameter will be considered",
"this",
".",
"expandNode",
"(",
"node",
",",
"options",
".",
"fisheye",
",",
"true",
",",
"options",
".",
"animate",
",",
"options",
".",
"layoutBy",
")",
";",
"}",
"}",
"else",
"{",
"// First expand given nodes and then perform layout according to the layoutBy parameter",
"this",
".",
"simpleExpandGivenNodes",
"(",
"nodes",
",",
"options",
".",
"fisheye",
")",
";",
"this",
".",
"endOperation",
"(",
"options",
".",
"layoutBy",
")",
";",
"}",
"/*\n * return the nodes to undo the operation\n */",
"return",
"nodes",
";",
"}"
] | Expand the given nodes perform end operation after expandation | [
"Expand",
"the",
"given",
"nodes",
"perform",
"end",
"operation",
"after",
"expandation"
] | 8a2e4157def5613e0e477e393dc2c0720e41c032 | https://github.com/iVis-at-Bilkent/cytoscape.js-expand-collapse/blob/8a2e4157def5613e0e477e393dc2c0720e41c032/src/expandCollapseUtilities.js#L129-L149 | |
22,725 | iVis-at-Bilkent/cytoscape.js-expand-collapse | src/expandCollapseUtilities.js | function (nodes, options) {
/*
* In collapse operation there is no fisheye view to be applied so there is no animation to be destroyed here. We can do this
* in a batch.
*/
cy.startBatch();
this.simpleCollapseGivenNodes(nodes, options);
cy.endBatch();
nodes.trigger("position"); // position not triggered by default when collapseNode is called
this.endOperation(options.layoutBy);
// Update the style
cy.style().update();
/*
* return the nodes to undo the operation
*/
return nodes;
} | javascript | function (nodes, options) {
/*
* In collapse operation there is no fisheye view to be applied so there is no animation to be destroyed here. We can do this
* in a batch.
*/
cy.startBatch();
this.simpleCollapseGivenNodes(nodes, options);
cy.endBatch();
nodes.trigger("position"); // position not triggered by default when collapseNode is called
this.endOperation(options.layoutBy);
// Update the style
cy.style().update();
/*
* return the nodes to undo the operation
*/
return nodes;
} | [
"function",
"(",
"nodes",
",",
"options",
")",
"{",
"/*\n * In collapse operation there is no fisheye view to be applied so there is no animation to be destroyed here. We can do this \n * in a batch.\n */",
"cy",
".",
"startBatch",
"(",
")",
";",
"this",
".",
"simpleCollapseGivenNodes",
"(",
"nodes",
",",
"options",
")",
";",
"cy",
".",
"endBatch",
"(",
")",
";",
"nodes",
".",
"trigger",
"(",
"\"position\"",
")",
";",
"// position not triggered by default when collapseNode is called",
"this",
".",
"endOperation",
"(",
"options",
".",
"layoutBy",
")",
";",
"// Update the style",
"cy",
".",
"style",
"(",
")",
".",
"update",
"(",
")",
";",
"/*\n * return the nodes to undo the operation\n */",
"return",
"nodes",
";",
"}"
] | collapse the given nodes then perform end operation | [
"collapse",
"the",
"given",
"nodes",
"then",
"perform",
"end",
"operation"
] | 8a2e4157def5613e0e477e393dc2c0720e41c032 | https://github.com/iVis-at-Bilkent/cytoscape.js-expand-collapse/blob/8a2e4157def5613e0e477e393dc2c0720e41c032/src/expandCollapseUtilities.js#L151-L170 | |
22,726 | iVis-at-Bilkent/cytoscape.js-expand-collapse | src/expandCollapseUtilities.js | function (root) {
var children = root.children();
for (var i = 0; i < children.length; i++) {
var node = children[i];
this.collapseBottomUp(node);
}
//If the root is a compound node to be collapsed then collapse it
if (root.data("collapse") && root.children().length > 0) {
this.collapseNode(root);
root.removeData("collapse");
}
} | javascript | function (root) {
var children = root.children();
for (var i = 0; i < children.length; i++) {
var node = children[i];
this.collapseBottomUp(node);
}
//If the root is a compound node to be collapsed then collapse it
if (root.data("collapse") && root.children().length > 0) {
this.collapseNode(root);
root.removeData("collapse");
}
} | [
"function",
"(",
"root",
")",
"{",
"var",
"children",
"=",
"root",
".",
"children",
"(",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"children",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"node",
"=",
"children",
"[",
"i",
"]",
";",
"this",
".",
"collapseBottomUp",
"(",
"node",
")",
";",
"}",
"//If the root is a compound node to be collapsed then collapse it",
"if",
"(",
"root",
".",
"data",
"(",
"\"collapse\"",
")",
"&&",
"root",
".",
"children",
"(",
")",
".",
"length",
">",
"0",
")",
"{",
"this",
".",
"collapseNode",
"(",
"root",
")",
";",
"root",
".",
"removeData",
"(",
"\"collapse\"",
")",
";",
"}",
"}"
] | collapse the nodes in bottom up order starting from the root | [
"collapse",
"the",
"nodes",
"in",
"bottom",
"up",
"order",
"starting",
"from",
"the",
"root"
] | 8a2e4157def5613e0e477e393dc2c0720e41c032 | https://github.com/iVis-at-Bilkent/cytoscape.js-expand-collapse/blob/8a2e4157def5613e0e477e393dc2c0720e41c032/src/expandCollapseUtilities.js#L172-L183 | |
22,727 | iVis-at-Bilkent/cytoscape.js-expand-collapse | src/expandCollapseUtilities.js | function (root, applyFishEyeViewToEachNode) {
if (root.data("expand") && root._private.data.collapsedChildren != null) {
// Expand the root and unmark its expand data to specify that it is no more to be expanded
this.expandNode(root, applyFishEyeViewToEachNode);
root.removeData("expand");
}
// Make a recursive call for children of root
var children = root.children();
for (var i = 0; i < children.length; i++) {
var node = children[i];
this.expandTopDown(node);
}
} | javascript | function (root, applyFishEyeViewToEachNode) {
if (root.data("expand") && root._private.data.collapsedChildren != null) {
// Expand the root and unmark its expand data to specify that it is no more to be expanded
this.expandNode(root, applyFishEyeViewToEachNode);
root.removeData("expand");
}
// Make a recursive call for children of root
var children = root.children();
for (var i = 0; i < children.length; i++) {
var node = children[i];
this.expandTopDown(node);
}
} | [
"function",
"(",
"root",
",",
"applyFishEyeViewToEachNode",
")",
"{",
"if",
"(",
"root",
".",
"data",
"(",
"\"expand\"",
")",
"&&",
"root",
".",
"_private",
".",
"data",
".",
"collapsedChildren",
"!=",
"null",
")",
"{",
"// Expand the root and unmark its expand data to specify that it is no more to be expanded",
"this",
".",
"expandNode",
"(",
"root",
",",
"applyFishEyeViewToEachNode",
")",
";",
"root",
".",
"removeData",
"(",
"\"expand\"",
")",
";",
"}",
"// Make a recursive call for children of root",
"var",
"children",
"=",
"root",
".",
"children",
"(",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"children",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"node",
"=",
"children",
"[",
"i",
"]",
";",
"this",
".",
"expandTopDown",
"(",
"node",
")",
";",
"}",
"}"
] | expand the nodes in top down order starting from the root | [
"expand",
"the",
"nodes",
"in",
"top",
"down",
"order",
"starting",
"from",
"the",
"root"
] | 8a2e4157def5613e0e477e393dc2c0720e41c032 | https://github.com/iVis-at-Bilkent/cytoscape.js-expand-collapse/blob/8a2e4157def5613e0e477e393dc2c0720e41c032/src/expandCollapseUtilities.js#L185-L197 | |
22,728 | iVis-at-Bilkent/cytoscape.js-expand-collapse | src/expandCollapseUtilities.js | function (renderedPosition) {
var pan = cy.pan();
var zoom = cy.zoom();
var x = (renderedPosition.x - pan.x) / zoom;
var y = (renderedPosition.y - pan.y) / zoom;
return {
x: x,
y: y
};
} | javascript | function (renderedPosition) {
var pan = cy.pan();
var zoom = cy.zoom();
var x = (renderedPosition.x - pan.x) / zoom;
var y = (renderedPosition.y - pan.y) / zoom;
return {
x: x,
y: y
};
} | [
"function",
"(",
"renderedPosition",
")",
"{",
"var",
"pan",
"=",
"cy",
".",
"pan",
"(",
")",
";",
"var",
"zoom",
"=",
"cy",
".",
"zoom",
"(",
")",
";",
"var",
"x",
"=",
"(",
"renderedPosition",
".",
"x",
"-",
"pan",
".",
"x",
")",
"/",
"zoom",
";",
"var",
"y",
"=",
"(",
"renderedPosition",
".",
"y",
"-",
"pan",
".",
"y",
")",
"/",
"zoom",
";",
"return",
"{",
"x",
":",
"x",
",",
"y",
":",
"y",
"}",
";",
"}"
] | Converst the rendered position to model position according to global pan and zoom values | [
"Converst",
"the",
"rendered",
"position",
"to",
"model",
"position",
"according",
"to",
"global",
"pan",
"and",
"zoom",
"values"
] | 8a2e4157def5613e0e477e393dc2c0720e41c032 | https://github.com/iVis-at-Bilkent/cytoscape.js-expand-collapse/blob/8a2e4157def5613e0e477e393dc2c0720e41c032/src/expandCollapseUtilities.js#L199-L210 | |
22,729 | iVis-at-Bilkent/cytoscape.js-expand-collapse | src/expandCollapseUtilities.js | function (node) {
if (node._private.data.collapsedChildren == null) {
node.data('position-before-collapse', {
x: node.position().x,
y: node.position().y
});
node.data('size-before-collapse', {
w: node.outerWidth(),
h: node.outerHeight()
});
var children = node.children();
children.unselect();
children.connectedEdges().unselect();
node.trigger("expandcollapse.beforecollapse");
this.barrowEdgesOfcollapsedChildren(node);
this.removeChildren(node, node);
node.addClass('cy-expand-collapse-collapsed-node');
node.trigger("expandcollapse.aftercollapse");
node.position(node.data('position-before-collapse'));
//return the node to undo the operation
return node;
}
} | javascript | function (node) {
if (node._private.data.collapsedChildren == null) {
node.data('position-before-collapse', {
x: node.position().x,
y: node.position().y
});
node.data('size-before-collapse', {
w: node.outerWidth(),
h: node.outerHeight()
});
var children = node.children();
children.unselect();
children.connectedEdges().unselect();
node.trigger("expandcollapse.beforecollapse");
this.barrowEdgesOfcollapsedChildren(node);
this.removeChildren(node, node);
node.addClass('cy-expand-collapse-collapsed-node');
node.trigger("expandcollapse.aftercollapse");
node.position(node.data('position-before-collapse'));
//return the node to undo the operation
return node;
}
} | [
"function",
"(",
"node",
")",
"{",
"if",
"(",
"node",
".",
"_private",
".",
"data",
".",
"collapsedChildren",
"==",
"null",
")",
"{",
"node",
".",
"data",
"(",
"'position-before-collapse'",
",",
"{",
"x",
":",
"node",
".",
"position",
"(",
")",
".",
"x",
",",
"y",
":",
"node",
".",
"position",
"(",
")",
".",
"y",
"}",
")",
";",
"node",
".",
"data",
"(",
"'size-before-collapse'",
",",
"{",
"w",
":",
"node",
".",
"outerWidth",
"(",
")",
",",
"h",
":",
"node",
".",
"outerHeight",
"(",
")",
"}",
")",
";",
"var",
"children",
"=",
"node",
".",
"children",
"(",
")",
";",
"children",
".",
"unselect",
"(",
")",
";",
"children",
".",
"connectedEdges",
"(",
")",
".",
"unselect",
"(",
")",
";",
"node",
".",
"trigger",
"(",
"\"expandcollapse.beforecollapse\"",
")",
";",
"this",
".",
"barrowEdgesOfcollapsedChildren",
"(",
"node",
")",
";",
"this",
".",
"removeChildren",
"(",
"node",
",",
"node",
")",
";",
"node",
".",
"addClass",
"(",
"'cy-expand-collapse-collapsed-node'",
")",
";",
"node",
".",
"trigger",
"(",
"\"expandcollapse.aftercollapse\"",
")",
";",
"node",
".",
"position",
"(",
"node",
".",
"data",
"(",
"'position-before-collapse'",
")",
")",
";",
"//return the node to undo the operation",
"return",
"node",
";",
"}",
"}"
] | collapse the given node without performing end operation | [
"collapse",
"the",
"given",
"node",
"without",
"performing",
"end",
"operation"
] | 8a2e4157def5613e0e477e393dc2c0720e41c032 | https://github.com/iVis-at-Bilkent/cytoscape.js-expand-collapse/blob/8a2e4157def5613e0e477e393dc2c0720e41c032/src/expandCollapseUtilities.js#L299-L329 | |
22,730 | iVis-at-Bilkent/cytoscape.js-expand-collapse | src/expandCollapseUtilities.js | function(node, collapsedChildren){
var children = node.data('collapsedChildren');
var i;
for (i=0; i < children.length; i++){
if (children[i].data('collapsedChildren')){
collapsedChildren = collapsedChildren.union(this.getCollapsedChildrenRecursively(children[i], collapsedChildren));
}
collapsedChildren = collapsedChildren.union(children[i]);
}
return collapsedChildren;
} | javascript | function(node, collapsedChildren){
var children = node.data('collapsedChildren');
var i;
for (i=0; i < children.length; i++){
if (children[i].data('collapsedChildren')){
collapsedChildren = collapsedChildren.union(this.getCollapsedChildrenRecursively(children[i], collapsedChildren));
}
collapsedChildren = collapsedChildren.union(children[i]);
}
return collapsedChildren;
} | [
"function",
"(",
"node",
",",
"collapsedChildren",
")",
"{",
"var",
"children",
"=",
"node",
".",
"data",
"(",
"'collapsedChildren'",
")",
";",
"var",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"children",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"children",
"[",
"i",
"]",
".",
"data",
"(",
"'collapsedChildren'",
")",
")",
"{",
"collapsedChildren",
"=",
"collapsedChildren",
".",
"union",
"(",
"this",
".",
"getCollapsedChildrenRecursively",
"(",
"children",
"[",
"i",
"]",
",",
"collapsedChildren",
")",
")",
";",
"}",
"collapsedChildren",
"=",
"collapsedChildren",
".",
"union",
"(",
"children",
"[",
"i",
"]",
")",
";",
"}",
"return",
"collapsedChildren",
";",
"}"
] | Get all collapsed children - including nested ones
@param node : a collapsed node
@param collapsedChildren : a collection to store the result
@return : collapsed children | [
"Get",
"all",
"collapsed",
"children",
"-",
"including",
"nested",
"ones"
] | 8a2e4157def5613e0e477e393dc2c0720e41c032 | https://github.com/iVis-at-Bilkent/cytoscape.js-expand-collapse/blob/8a2e4157def5613e0e477e393dc2c0720e41c032/src/expandCollapseUtilities.js#L656-L666 | |
22,731 | uupaa/UserAgent.js | docs/lib/WebModule.js | function(moduleName, moduleClosure) {
var wm = this; // GLOBAL.WebModule
// https://github.com/uupaa/WebModule/wiki/SwitchModulePattern
var alias = wm[moduleName] ? (moduleName + "_") : moduleName;
if (!wm[alias]) { // secondary module already exported -> skip
wm[alias] = moduleClosure(GLOBAL); // evaluate the module entity
wm.closure[alias] = moduleClosure + ""; // stock
if (wm.publish && !GLOBAL[alias]) {
GLOBAL[alias] = wm[alias]; // publish to global
}
}
return wm[alias];
} | javascript | function(moduleName, moduleClosure) {
var wm = this; // GLOBAL.WebModule
// https://github.com/uupaa/WebModule/wiki/SwitchModulePattern
var alias = wm[moduleName] ? (moduleName + "_") : moduleName;
if (!wm[alias]) { // secondary module already exported -> skip
wm[alias] = moduleClosure(GLOBAL); // evaluate the module entity
wm.closure[alias] = moduleClosure + ""; // stock
if (wm.publish && !GLOBAL[alias]) {
GLOBAL[alias] = wm[alias]; // publish to global
}
}
return wm[alias];
} | [
"function",
"(",
"moduleName",
",",
"moduleClosure",
")",
"{",
"var",
"wm",
"=",
"this",
";",
"// GLOBAL.WebModule",
"// https://github.com/uupaa/WebModule/wiki/SwitchModulePattern",
"var",
"alias",
"=",
"wm",
"[",
"moduleName",
"]",
"?",
"(",
"moduleName",
"+",
"\"_\"",
")",
":",
"moduleName",
";",
"if",
"(",
"!",
"wm",
"[",
"alias",
"]",
")",
"{",
"// secondary module already exported -> skip",
"wm",
"[",
"alias",
"]",
"=",
"moduleClosure",
"(",
"GLOBAL",
")",
";",
"// evaluate the module entity",
"wm",
".",
"closure",
"[",
"alias",
"]",
"=",
"moduleClosure",
"+",
"\"\"",
";",
"// stock",
"if",
"(",
"wm",
".",
"publish",
"&&",
"!",
"GLOBAL",
"[",
"alias",
"]",
")",
"{",
"GLOBAL",
"[",
"alias",
"]",
"=",
"wm",
"[",
"alias",
"]",
";",
"// publish to global",
"}",
"}",
"return",
"wm",
"[",
"alias",
"]",
";",
"}"
] | module script stocker | [
"module",
"script",
"stocker"
] | 5d90111f44c1a90a68c804f30f949b3feac436dd | https://github.com/uupaa/UserAgent.js/blob/5d90111f44c1a90a68c804f30f949b3feac436dd/docs/lib/WebModule.js#L39-L54 | |
22,732 | uupaa/UserAgent.js | lib/WebModule.js | function(moduleName, // @arg ModuleNameString
moduleClosure) { // @arg JavaScriptCodeString
// @ret ModuleObject
var wm = this; // GLOBAL.WebModule
// https://github.com/uupaa/WebModule/wiki/SwitchModulePattern
var alias = wm[moduleName] ? (moduleName + "_") : moduleName;
if (!wm[alias]) { // secondary module already exported -> skip
wm[alias] = moduleClosure(GLOBAL, wm, wm.VERIFY, wm.VERBOSE); // evaluate the module entity.
wm.CODE[alias] = moduleClosure + ""; // store to the container.
if (wm.PUBLISH && !GLOBAL[alias]) {
GLOBAL[alias] = wm[alias]; // module publish to global namespace.
}
}
return wm[alias];
} | javascript | function(moduleName, // @arg ModuleNameString
moduleClosure) { // @arg JavaScriptCodeString
// @ret ModuleObject
var wm = this; // GLOBAL.WebModule
// https://github.com/uupaa/WebModule/wiki/SwitchModulePattern
var alias = wm[moduleName] ? (moduleName + "_") : moduleName;
if (!wm[alias]) { // secondary module already exported -> skip
wm[alias] = moduleClosure(GLOBAL, wm, wm.VERIFY, wm.VERBOSE); // evaluate the module entity.
wm.CODE[alias] = moduleClosure + ""; // store to the container.
if (wm.PUBLISH && !GLOBAL[alias]) {
GLOBAL[alias] = wm[alias]; // module publish to global namespace.
}
}
return wm[alias];
} | [
"function",
"(",
"moduleName",
",",
"// @arg ModuleNameString",
"moduleClosure",
")",
"{",
"// @arg JavaScriptCodeString",
"// @ret ModuleObject",
"var",
"wm",
"=",
"this",
";",
"// GLOBAL.WebModule",
"// https://github.com/uupaa/WebModule/wiki/SwitchModulePattern",
"var",
"alias",
"=",
"wm",
"[",
"moduleName",
"]",
"?",
"(",
"moduleName",
"+",
"\"_\"",
")",
":",
"moduleName",
";",
"if",
"(",
"!",
"wm",
"[",
"alias",
"]",
")",
"{",
"// secondary module already exported -> skip",
"wm",
"[",
"alias",
"]",
"=",
"moduleClosure",
"(",
"GLOBAL",
",",
"wm",
",",
"wm",
".",
"VERIFY",
",",
"wm",
".",
"VERBOSE",
")",
";",
"// evaluate the module entity.",
"wm",
".",
"CODE",
"[",
"alias",
"]",
"=",
"moduleClosure",
"+",
"\"\"",
";",
"// store to the container.",
"if",
"(",
"wm",
".",
"PUBLISH",
"&&",
"!",
"GLOBAL",
"[",
"alias",
"]",
")",
"{",
"GLOBAL",
"[",
"alias",
"]",
"=",
"wm",
"[",
"alias",
"]",
";",
"// module publish to global namespace.",
"}",
"}",
"return",
"wm",
"[",
"alias",
"]",
";",
"}"
] | publish flag, module publish to global namespace. | [
"publish",
"flag",
"module",
"publish",
"to",
"global",
"namespace",
"."
] | 5d90111f44c1a90a68c804f30f949b3feac436dd | https://github.com/uupaa/UserAgent.js/blob/5d90111f44c1a90a68c804f30f949b3feac436dd/lib/WebModule.js#L39-L56 | |
22,733 | garrows/browser-serialport | index.js | buffer2ArrayBuffer | function buffer2ArrayBuffer(buffer) {
var buf = new ArrayBuffer(buffer.length);
var bufView = new Uint8Array(buf);
for (var i = 0; i < buffer.length; i++) {
bufView[i] = buffer[i];
}
return buf;
} | javascript | function buffer2ArrayBuffer(buffer) {
var buf = new ArrayBuffer(buffer.length);
var bufView = new Uint8Array(buf);
for (var i = 0; i < buffer.length; i++) {
bufView[i] = buffer[i];
}
return buf;
} | [
"function",
"buffer2ArrayBuffer",
"(",
"buffer",
")",
"{",
"var",
"buf",
"=",
"new",
"ArrayBuffer",
"(",
"buffer",
".",
"length",
")",
";",
"var",
"bufView",
"=",
"new",
"Uint8Array",
"(",
"buf",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"buffer",
".",
"length",
";",
"i",
"++",
")",
"{",
"bufView",
"[",
"i",
"]",
"=",
"buffer",
"[",
"i",
"]",
";",
"}",
"return",
"buf",
";",
"}"
] | Convert buffer to ArrayBuffer | [
"Convert",
"buffer",
"to",
"ArrayBuffer"
] | 3238bfa89a3f9d098a5263e1f63c3a7dbbeda759 | https://github.com/garrows/browser-serialport/blob/3238bfa89a3f9d098a5263e1f63c3a7dbbeda759/index.js#L400-L407 |
22,734 | feathers-plus/graphql | lib/run-time/feathers/feathers-batch-loader.js | batchLoaderFunc | function batchLoaderFunc(graphqlType, serializeRecordKey, getRecords) {
return keys => getRecords(keys)
.then(resultArray => getResultsByKey(
keys, extractAllItems(resultArray), serializeRecordKey, graphqlType,
{ onError: logger }
)
);
} | javascript | function batchLoaderFunc(graphqlType, serializeRecordKey, getRecords) {
return keys => getRecords(keys)
.then(resultArray => getResultsByKey(
keys, extractAllItems(resultArray), serializeRecordKey, graphqlType,
{ onError: logger }
)
);
} | [
"function",
"batchLoaderFunc",
"(",
"graphqlType",
",",
"serializeRecordKey",
",",
"getRecords",
")",
"{",
"return",
"keys",
"=>",
"getRecords",
"(",
"keys",
")",
".",
"then",
"(",
"resultArray",
"=>",
"getResultsByKey",
"(",
"keys",
",",
"extractAllItems",
"(",
"resultArray",
")",
",",
"serializeRecordKey",
",",
"graphqlType",
",",
"{",
"onError",
":",
"logger",
"}",
")",
")",
";",
"}"
] | Key loader function for BatchLoader. Note that serializeBatchLoaderKey has already been passed to BatchLoader as cacheKeyFn | [
"Key",
"loader",
"function",
"for",
"BatchLoader",
".",
"Note",
"that",
"serializeBatchLoaderKey",
"has",
"already",
"been",
"passed",
"to",
"BatchLoader",
"as",
"cacheKeyFn"
] | 259c0e6375d7054476d3ae24b2b27e194e375852 | https://github.com/feathers-plus/graphql/blob/259c0e6375d7054476d3ae24b2b27e194e375852/lib/run-time/feathers/feathers-batch-loader.js#L74-L81 |
22,735 | fshost/node-dir | lib/readfiles.js | extend | function extend(target, source, modify) {
var result = target ? modify ? target : extend({}, target, true) : {};
if (!source) return result;
for (var key in source) {
if (source.hasOwnProperty(key) && source[key] !== undefined) {
result[key] = source[key];
}
}
return result;
} | javascript | function extend(target, source, modify) {
var result = target ? modify ? target : extend({}, target, true) : {};
if (!source) return result;
for (var key in source) {
if (source.hasOwnProperty(key) && source[key] !== undefined) {
result[key] = source[key];
}
}
return result;
} | [
"function",
"extend",
"(",
"target",
",",
"source",
",",
"modify",
")",
"{",
"var",
"result",
"=",
"target",
"?",
"modify",
"?",
"target",
":",
"extend",
"(",
"{",
"}",
",",
"target",
",",
"true",
")",
":",
"{",
"}",
";",
"if",
"(",
"!",
"source",
")",
"return",
"result",
";",
"for",
"(",
"var",
"key",
"in",
"source",
")",
"{",
"if",
"(",
"source",
".",
"hasOwnProperty",
"(",
"key",
")",
"&&",
"source",
"[",
"key",
"]",
"!==",
"undefined",
")",
"{",
"result",
"[",
"key",
"]",
"=",
"source",
"[",
"key",
"]",
";",
"}",
"}",
"return",
"result",
";",
"}"
] | merge two objects by extending target object with source object
@param target object to merge
@param source object to merge
@param {Boolean} [modify] whether to modify the target
@returns {Object} extended object | [
"merge",
"two",
"objects",
"by",
"extending",
"target",
"object",
"with",
"source",
"object"
] | a57c3b1b571dd91f464ae398090ba40f64ba38a2 | https://github.com/fshost/node-dir/blob/a57c3b1b571dd91f464ae398090ba40f64ba38a2/lib/readfiles.js#L11-L20 |
22,736 | feathers-plus/graphql | lib/run-time/feathers/extract-items.js | extractAllItems | function extractAllItems (result) {
if (!result) return null;
if (!Array.isArray(result)) result = ('data' in result) ? result.data : result;
if (!result) return null;
if (!Array.isArray(result)) result = [result];
return result;
} | javascript | function extractAllItems (result) {
if (!result) return null;
if (!Array.isArray(result)) result = ('data' in result) ? result.data : result;
if (!result) return null;
if (!Array.isArray(result)) result = [result];
return result;
} | [
"function",
"extractAllItems",
"(",
"result",
")",
"{",
"if",
"(",
"!",
"result",
")",
"return",
"null",
";",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"result",
")",
")",
"result",
"=",
"(",
"'data'",
"in",
"result",
")",
"?",
"result",
".",
"data",
":",
"result",
";",
"if",
"(",
"!",
"result",
")",
"return",
"null",
";",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"result",
")",
")",
"result",
"=",
"[",
"result",
"]",
";",
"return",
"result",
";",
"}"
] | Return an array of objects from a Feathers service call. | [
"Return",
"an",
"array",
"of",
"objects",
"from",
"a",
"Feathers",
"service",
"call",
"."
] | 259c0e6375d7054476d3ae24b2b27e194e375852 | https://github.com/feathers-plus/graphql/blob/259c0e6375d7054476d3ae24b2b27e194e375852/lib/run-time/feathers/extract-items.js#L8-L17 |
22,737 | feathers-plus/graphql | lib/run-time/feathers/extract-items.js | extractFirstItem | function extractFirstItem (result) {
const data = extractAllItems(result);
if (!data) return null;
if (data.length > 1) throw new Error(`service.find expected 0 or 1 objects, not ${data.length}. (extractFirstItem)`);
return data.length ? data[0] : null;
} | javascript | function extractFirstItem (result) {
const data = extractAllItems(result);
if (!data) return null;
if (data.length > 1) throw new Error(`service.find expected 0 or 1 objects, not ${data.length}. (extractFirstItem)`);
return data.length ? data[0] : null;
} | [
"function",
"extractFirstItem",
"(",
"result",
")",
"{",
"const",
"data",
"=",
"extractAllItems",
"(",
"result",
")",
";",
"if",
"(",
"!",
"data",
")",
"return",
"null",
";",
"if",
"(",
"data",
".",
"length",
">",
"1",
")",
"throw",
"new",
"Error",
"(",
"`",
"${",
"data",
".",
"length",
"}",
"`",
")",
";",
"return",
"data",
".",
"length",
"?",
"data",
"[",
"0",
"]",
":",
"null",
";",
"}"
] | Return the first and only object from a Feathers service call, or null if none. | [
"Return",
"the",
"first",
"and",
"only",
"object",
"from",
"a",
"Feathers",
"service",
"call",
"or",
"null",
"if",
"none",
"."
] | 259c0e6375d7054476d3ae24b2b27e194e375852 | https://github.com/feathers-plus/graphql/blob/259c0e6375d7054476d3ae24b2b27e194e375852/lib/run-time/feathers/extract-items.js#L20-L27 |
22,738 | reinerBa/Vue-Responsive | src/index.js | checkDisplay | function checkDisplay () {
var myPermissions = self.allProperties[resizeListenerId] // JSON.parse(el.dataset.responsives)
var curWidth = window.innerWidth
var initial = el.dataset.initialDisplay ? el.dataset.initialDisplay : ''
var parameters = self._rPermissions[binding.arg]
for (let i in parameters) {
if (curWidth >= parameters[i].min && curWidth <= parameters[i].max) {
if (myPermissions.lastBp !== i) {
if (self.allProperties[resizeListenerId].useClass) {
el.classList.add(myPermissions.bpSet + '-' + i)
el.classList.remove(myPermissions.bpSet + '-' + myPermissions.lastBp)
} else {
el.style.display = myPermissions[i] ? initial : 'none'
}
self.allProperties[resizeListenerId].lastBp = i
}
break
}
}
} | javascript | function checkDisplay () {
var myPermissions = self.allProperties[resizeListenerId] // JSON.parse(el.dataset.responsives)
var curWidth = window.innerWidth
var initial = el.dataset.initialDisplay ? el.dataset.initialDisplay : ''
var parameters = self._rPermissions[binding.arg]
for (let i in parameters) {
if (curWidth >= parameters[i].min && curWidth <= parameters[i].max) {
if (myPermissions.lastBp !== i) {
if (self.allProperties[resizeListenerId].useClass) {
el.classList.add(myPermissions.bpSet + '-' + i)
el.classList.remove(myPermissions.bpSet + '-' + myPermissions.lastBp)
} else {
el.style.display = myPermissions[i] ? initial : 'none'
}
self.allProperties[resizeListenerId].lastBp = i
}
break
}
}
} | [
"function",
"checkDisplay",
"(",
")",
"{",
"var",
"myPermissions",
"=",
"self",
".",
"allProperties",
"[",
"resizeListenerId",
"]",
"// JSON.parse(el.dataset.responsives)",
"var",
"curWidth",
"=",
"window",
".",
"innerWidth",
"var",
"initial",
"=",
"el",
".",
"dataset",
".",
"initialDisplay",
"?",
"el",
".",
"dataset",
".",
"initialDisplay",
":",
"''",
"var",
"parameters",
"=",
"self",
".",
"_rPermissions",
"[",
"binding",
".",
"arg",
"]",
"for",
"(",
"let",
"i",
"in",
"parameters",
")",
"{",
"if",
"(",
"curWidth",
">=",
"parameters",
"[",
"i",
"]",
".",
"min",
"&&",
"curWidth",
"<=",
"parameters",
"[",
"i",
"]",
".",
"max",
")",
"{",
"if",
"(",
"myPermissions",
".",
"lastBp",
"!==",
"i",
")",
"{",
"if",
"(",
"self",
".",
"allProperties",
"[",
"resizeListenerId",
"]",
".",
"useClass",
")",
"{",
"el",
".",
"classList",
".",
"add",
"(",
"myPermissions",
".",
"bpSet",
"+",
"'-'",
"+",
"i",
")",
"el",
".",
"classList",
".",
"remove",
"(",
"myPermissions",
".",
"bpSet",
"+",
"'-'",
"+",
"myPermissions",
".",
"lastBp",
")",
"}",
"else",
"{",
"el",
".",
"style",
".",
"display",
"=",
"myPermissions",
"[",
"i",
"]",
"?",
"initial",
":",
"'none'",
"}",
"self",
".",
"allProperties",
"[",
"resizeListenerId",
"]",
".",
"lastBp",
"=",
"i",
"}",
"break",
"}",
"}",
"}"
] | This function checks the current breakpoint constraints for this element | [
"This",
"function",
"checks",
"the",
"current",
"breakpoint",
"constraints",
"for",
"this",
"element"
] | 9edf8298fc6e922d856bb74db5c38c5cd3d9c39c | https://github.com/reinerBa/Vue-Responsive/blob/9edf8298fc6e922d856bb74db5c38c5cd3d9c39c/src/index.js#L176-L196 |
22,739 | reinerBa/Vue-Responsive | src/index.js | function (el, binding, vnode) {
let resizeListenerId = el.dataset.responsives
delete self.resizeListeners[resizeListenerId]
} | javascript | function (el, binding, vnode) {
let resizeListenerId = el.dataset.responsives
delete self.resizeListeners[resizeListenerId]
} | [
"function",
"(",
"el",
",",
"binding",
",",
"vnode",
")",
"{",
"let",
"resizeListenerId",
"=",
"el",
".",
"dataset",
".",
"responsives",
"delete",
"self",
".",
"resizeListeners",
"[",
"resizeListenerId",
"]",
"}"
] | Is called when the html element is removed from DOM
@param {object} el html element
@param {object} binding the parameters of the mixin
@param {object} vnode the virtual html elment | [
"Is",
"called",
"when",
"the",
"html",
"element",
"is",
"removed",
"from",
"DOM"
] | 9edf8298fc6e922d856bb74db5c38c5cd3d9c39c | https://github.com/reinerBa/Vue-Responsive/blob/9edf8298fc6e922d856bb74db5c38c5cd3d9c39c/src/index.js#L208-L211 | |
22,740 | d3plus/d3plus-text | src/textWidth.js | htmlDecode | function htmlDecode(input) {
if (input === " ") return input;
const doc = new DOMParser().parseFromString(input.replace(/<[^>]+>/g, ""), "text/html");
return doc.documentElement.textContent;
} | javascript | function htmlDecode(input) {
if (input === " ") return input;
const doc = new DOMParser().parseFromString(input.replace(/<[^>]+>/g, ""), "text/html");
return doc.documentElement.textContent;
} | [
"function",
"htmlDecode",
"(",
"input",
")",
"{",
"if",
"(",
"input",
"===",
"\" \"",
")",
"return",
"input",
";",
"const",
"doc",
"=",
"new",
"DOMParser",
"(",
")",
".",
"parseFromString",
"(",
"input",
".",
"replace",
"(",
"/",
"<[^>]+>",
"/",
"g",
",",
"\"\"",
")",
",",
"\"text/html\"",
")",
";",
"return",
"doc",
".",
"documentElement",
".",
"textContent",
";",
"}"
] | Strips HTML and "un-escapes" escape characters.
@param {String} input | [
"Strips",
"HTML",
"and",
"un",
"-",
"escapes",
"escape",
"characters",
"."
] | 00af6bb99ff048e132c287dd7f43fcc3143264d5 | https://github.com/d3plus/d3plus-text/blob/00af6bb99ff048e132c287dd7f43fcc3143264d5/src/textWidth.js#L5-L9 |
22,741 | bencentra/jq-signature | jq-signature.js | function() {
this.id = 'jq-signature-canvas-' + (++idCounter);
// Set up the canvas
this.$canvas = $(canvasFixture).appendTo(this.$element);
this.$canvas.attr({
width: this.settings.width,
height: this.settings.height
});
this.$canvas.css({
boxSizing: 'border-box',
width: this.settings.width + 'px',
height: this.settings.height + 'px',
border: this.settings.border,
background: this.settings.background,
cursor: 'crosshair'
});
this.$canvas.attr('id', this.id);
// Fit canvas to width of parent
if (this.settings.autoFit === true) {
this._resizeCanvas();
// TODO - allow for dynamic canvas resizing
// (need to save canvas state before changing width to avoid getting cleared)
// var timeout = false;
// $(window).on('resize', $.proxy(function(e) {
// clearTimeout(timeout);
// timeout = setTimeout($.proxy(this._resizeCanvas, this), 250);
// }, this));
}
this.canvas = this.$canvas[0];
this._resetCanvas();
// Listen for pointer/mouse/touch events
// TODO - PointerEvent isn't fully supported, but eventually do something like this:
// if (window.PointerEvent) {
// this.$canvas.parent().css('-ms-touch-action', 'none');
// this.$canvas.on("pointerdown MSPointerDown", $.proxy(this._downHandler, this));
// this.$canvas.on("pointermove MSPointerMove", $.proxy(this._moveHandler, this));
// this.$canvas.on("pointerup MSPointerUp", $.proxy(this._upHandler, this));
// }
// else {
// this.$canvas.on('mousedown touchstart', $.proxy(this._downHandler, this));
// this.$canvas.on('mousemove touchmove', $.proxy(this._moveHandler, this));
// this.$canvas.on('mouseup touchend', $.proxy(this._upHandler, this));
// }
this.$canvas.on('mousedown touchstart', $.proxy(this._downHandler, this));
this.$canvas.on('mousemove touchmove', $.proxy(this._moveHandler, this));
this.$canvas.on('mouseup touchend', $.proxy(this._upHandler, this));
// Start drawing
var that = this;
(function drawLoop() {
window.requestAnimFrame(drawLoop);
that._renderCanvas();
})();
} | javascript | function() {
this.id = 'jq-signature-canvas-' + (++idCounter);
// Set up the canvas
this.$canvas = $(canvasFixture).appendTo(this.$element);
this.$canvas.attr({
width: this.settings.width,
height: this.settings.height
});
this.$canvas.css({
boxSizing: 'border-box',
width: this.settings.width + 'px',
height: this.settings.height + 'px',
border: this.settings.border,
background: this.settings.background,
cursor: 'crosshair'
});
this.$canvas.attr('id', this.id);
// Fit canvas to width of parent
if (this.settings.autoFit === true) {
this._resizeCanvas();
// TODO - allow for dynamic canvas resizing
// (need to save canvas state before changing width to avoid getting cleared)
// var timeout = false;
// $(window).on('resize', $.proxy(function(e) {
// clearTimeout(timeout);
// timeout = setTimeout($.proxy(this._resizeCanvas, this), 250);
// }, this));
}
this.canvas = this.$canvas[0];
this._resetCanvas();
// Listen for pointer/mouse/touch events
// TODO - PointerEvent isn't fully supported, but eventually do something like this:
// if (window.PointerEvent) {
// this.$canvas.parent().css('-ms-touch-action', 'none');
// this.$canvas.on("pointerdown MSPointerDown", $.proxy(this._downHandler, this));
// this.$canvas.on("pointermove MSPointerMove", $.proxy(this._moveHandler, this));
// this.$canvas.on("pointerup MSPointerUp", $.proxy(this._upHandler, this));
// }
// else {
// this.$canvas.on('mousedown touchstart', $.proxy(this._downHandler, this));
// this.$canvas.on('mousemove touchmove', $.proxy(this._moveHandler, this));
// this.$canvas.on('mouseup touchend', $.proxy(this._upHandler, this));
// }
this.$canvas.on('mousedown touchstart', $.proxy(this._downHandler, this));
this.$canvas.on('mousemove touchmove', $.proxy(this._moveHandler, this));
this.$canvas.on('mouseup touchend', $.proxy(this._upHandler, this));
// Start drawing
var that = this;
(function drawLoop() {
window.requestAnimFrame(drawLoop);
that._renderCanvas();
})();
} | [
"function",
"(",
")",
"{",
"this",
".",
"id",
"=",
"'jq-signature-canvas-'",
"+",
"(",
"++",
"idCounter",
")",
";",
"// Set up the canvas",
"this",
".",
"$canvas",
"=",
"$",
"(",
"canvasFixture",
")",
".",
"appendTo",
"(",
"this",
".",
"$element",
")",
";",
"this",
".",
"$canvas",
".",
"attr",
"(",
"{",
"width",
":",
"this",
".",
"settings",
".",
"width",
",",
"height",
":",
"this",
".",
"settings",
".",
"height",
"}",
")",
";",
"this",
".",
"$canvas",
".",
"css",
"(",
"{",
"boxSizing",
":",
"'border-box'",
",",
"width",
":",
"this",
".",
"settings",
".",
"width",
"+",
"'px'",
",",
"height",
":",
"this",
".",
"settings",
".",
"height",
"+",
"'px'",
",",
"border",
":",
"this",
".",
"settings",
".",
"border",
",",
"background",
":",
"this",
".",
"settings",
".",
"background",
",",
"cursor",
":",
"'crosshair'",
"}",
")",
";",
"this",
".",
"$canvas",
".",
"attr",
"(",
"'id'",
",",
"this",
".",
"id",
")",
";",
"// Fit canvas to width of parent",
"if",
"(",
"this",
".",
"settings",
".",
"autoFit",
"===",
"true",
")",
"{",
"this",
".",
"_resizeCanvas",
"(",
")",
";",
"// TODO - allow for dynamic canvas resizing",
"// (need to save canvas state before changing width to avoid getting cleared)",
"// var timeout = false;",
"// $(window).on('resize', $.proxy(function(e) {",
"// clearTimeout(timeout);",
"// timeout = setTimeout($.proxy(this._resizeCanvas, this), 250);",
"// }, this));",
"}",
"this",
".",
"canvas",
"=",
"this",
".",
"$canvas",
"[",
"0",
"]",
";",
"this",
".",
"_resetCanvas",
"(",
")",
";",
"// Listen for pointer/mouse/touch events",
"// TODO - PointerEvent isn't fully supported, but eventually do something like this:",
"// if (window.PointerEvent) {",
"// \tthis.$canvas.parent().css('-ms-touch-action', 'none');",
"// \tthis.$canvas.on(\"pointerdown MSPointerDown\", $.proxy(this._downHandler, this));",
"// this.$canvas.on(\"pointermove MSPointerMove\", $.proxy(this._moveHandler, this));",
"// \tthis.$canvas.on(\"pointerup MSPointerUp\", $.proxy(this._upHandler, this));",
"// }",
"// else {",
"// this.$canvas.on('mousedown touchstart', $.proxy(this._downHandler, this));",
"// this.$canvas.on('mousemove touchmove', $.proxy(this._moveHandler, this));",
"// this.$canvas.on('mouseup touchend', $.proxy(this._upHandler, this));",
"// }",
"this",
".",
"$canvas",
".",
"on",
"(",
"'mousedown touchstart'",
",",
"$",
".",
"proxy",
"(",
"this",
".",
"_downHandler",
",",
"this",
")",
")",
";",
"this",
".",
"$canvas",
".",
"on",
"(",
"'mousemove touchmove'",
",",
"$",
".",
"proxy",
"(",
"this",
".",
"_moveHandler",
",",
"this",
")",
")",
";",
"this",
".",
"$canvas",
".",
"on",
"(",
"'mouseup touchend'",
",",
"$",
".",
"proxy",
"(",
"this",
".",
"_upHandler",
",",
"this",
")",
")",
";",
"// Start drawing",
"var",
"that",
"=",
"this",
";",
"(",
"function",
"drawLoop",
"(",
")",
"{",
"window",
".",
"requestAnimFrame",
"(",
"drawLoop",
")",
";",
"that",
".",
"_renderCanvas",
"(",
")",
";",
"}",
")",
"(",
")",
";",
"}"
] | Initialize the signature canvas | [
"Initialize",
"the",
"signature",
"canvas"
] | 0316358410c41319977d076ece050fedd11411c4 | https://github.com/bencentra/jq-signature/blob/0316358410c41319977d076ece050fedd11411c4/jq-signature.js#L56-L112 | |
22,742 | bencentra/jq-signature | jq-signature.js | function (e) {
this.drawing = true;
this.lastPos = this.currentPos = this._getPosition(e);
// Prevent scrolling, etc
$('body').css('overflow', 'hidden');
e.preventDefault();
} | javascript | function (e) {
this.drawing = true;
this.lastPos = this.currentPos = this._getPosition(e);
// Prevent scrolling, etc
$('body').css('overflow', 'hidden');
e.preventDefault();
} | [
"function",
"(",
"e",
")",
"{",
"this",
".",
"drawing",
"=",
"true",
";",
"this",
".",
"lastPos",
"=",
"this",
".",
"currentPos",
"=",
"this",
".",
"_getPosition",
"(",
"e",
")",
";",
"// Prevent scrolling, etc",
"$",
"(",
"'body'",
")",
".",
"css",
"(",
"'overflow'",
",",
"'hidden'",
")",
";",
"e",
".",
"preventDefault",
"(",
")",
";",
"}"
] | Handle the start of a signature | [
"Handle",
"the",
"start",
"of",
"a",
"signature"
] | 0316358410c41319977d076ece050fedd11411c4 | https://github.com/bencentra/jq-signature/blob/0316358410c41319977d076ece050fedd11411c4/jq-signature.js#L126-L132 | |
22,743 | bencentra/jq-signature | jq-signature.js | function (e) {
this.drawing = false;
// Trigger a change event
var changedEvent = $.Event('jq.signature.changed');
this.$element.trigger(changedEvent);
// Allow scrolling again
$('body').css('overflow', 'auto');
e.preventDefault();
} | javascript | function (e) {
this.drawing = false;
// Trigger a change event
var changedEvent = $.Event('jq.signature.changed');
this.$element.trigger(changedEvent);
// Allow scrolling again
$('body').css('overflow', 'auto');
e.preventDefault();
} | [
"function",
"(",
"e",
")",
"{",
"this",
".",
"drawing",
"=",
"false",
";",
"// Trigger a change event",
"var",
"changedEvent",
"=",
"$",
".",
"Event",
"(",
"'jq.signature.changed'",
")",
";",
"this",
".",
"$element",
".",
"trigger",
"(",
"changedEvent",
")",
";",
"// Allow scrolling again",
"$",
"(",
"'body'",
")",
".",
"css",
"(",
"'overflow'",
",",
"'auto'",
")",
";",
"e",
".",
"preventDefault",
"(",
")",
";",
"}"
] | Handle the end of a signature | [
"Handle",
"the",
"end",
"of",
"a",
"signature"
] | 0316358410c41319977d076ece050fedd11411c4 | https://github.com/bencentra/jq-signature/blob/0316358410c41319977d076ece050fedd11411c4/jq-signature.js#L141-L149 | |
22,744 | bencentra/jq-signature | jq-signature.js | function() {
if (this.drawing) {
this.ctx.beginPath();
this.ctx.moveTo(this.lastPos.x, this.lastPos.y);
this.ctx.lineTo(this.currentPos.x, this.currentPos.y);
this.ctx.stroke();
this.lastPos = this.currentPos;
}
} | javascript | function() {
if (this.drawing) {
this.ctx.beginPath();
this.ctx.moveTo(this.lastPos.x, this.lastPos.y);
this.ctx.lineTo(this.currentPos.x, this.currentPos.y);
this.ctx.stroke();
this.lastPos = this.currentPos;
}
} | [
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"drawing",
")",
"{",
"this",
".",
"ctx",
".",
"beginPath",
"(",
")",
";",
"this",
".",
"ctx",
".",
"moveTo",
"(",
"this",
".",
"lastPos",
".",
"x",
",",
"this",
".",
"lastPos",
".",
"y",
")",
";",
"this",
".",
"ctx",
".",
"lineTo",
"(",
"this",
".",
"currentPos",
".",
"x",
",",
"this",
".",
"currentPos",
".",
"y",
")",
";",
"this",
".",
"ctx",
".",
"stroke",
"(",
")",
";",
"this",
".",
"lastPos",
"=",
"this",
".",
"currentPos",
";",
"}",
"}"
] | Render the signature to the canvas | [
"Render",
"the",
"signature",
"to",
"the",
"canvas"
] | 0316358410c41319977d076ece050fedd11411c4 | https://github.com/bencentra/jq-signature/blob/0316358410c41319977d076ece050fedd11411c4/jq-signature.js#L175-L183 | |
22,745 | bencentra/jq-signature | jq-signature.js | function() {
this.ctx = this.canvas.getContext("2d");
this.ctx.strokeStyle = this.settings.lineColor;
this.ctx.lineWidth = this.settings.lineWidth;
} | javascript | function() {
this.ctx = this.canvas.getContext("2d");
this.ctx.strokeStyle = this.settings.lineColor;
this.ctx.lineWidth = this.settings.lineWidth;
} | [
"function",
"(",
")",
"{",
"this",
".",
"ctx",
"=",
"this",
".",
"canvas",
".",
"getContext",
"(",
"\"2d\"",
")",
";",
"this",
".",
"ctx",
".",
"strokeStyle",
"=",
"this",
".",
"settings",
".",
"lineColor",
";",
"this",
".",
"ctx",
".",
"lineWidth",
"=",
"this",
".",
"settings",
".",
"lineWidth",
";",
"}"
] | Reset the canvas context | [
"Reset",
"the",
"canvas",
"context"
] | 0316358410c41319977d076ece050fedd11411c4 | https://github.com/bencentra/jq-signature/blob/0316358410c41319977d076ece050fedd11411c4/jq-signature.js#L186-L190 | |
22,746 | philbooth/bfj | src/read.js | read | function read (path, options) {
return parse(fs.createReadStream(path, options), Object.assign({}, options, { ndjson: false }))
} | javascript | function read (path, options) {
return parse(fs.createReadStream(path, options), Object.assign({}, options, { ndjson: false }))
} | [
"function",
"read",
"(",
"path",
",",
"options",
")",
"{",
"return",
"parse",
"(",
"fs",
".",
"createReadStream",
"(",
"path",
",",
"options",
")",
",",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"options",
",",
"{",
"ndjson",
":",
"false",
"}",
")",
")",
"}"
] | Public function `read`.
Returns a promise and asynchronously parses a JSON file read from disk. If
there are no errors, the promise is resolved with the parsed data. If errors
occur, the promise is rejected with the first error.
@param path: Path to the JSON file.
@option reviver: Transformation function, invoked depth-first.
@option yieldRate: The number of data items to process per timeslice,
default is 16384.
@option Promise: The promise constructor to use, defaults to bluebird. | [
"Public",
"function",
"read",
"."
] | 61087c194d5675c75569a2e08617a98609b16ead | https://github.com/philbooth/bfj/blob/61087c194d5675c75569a2e08617a98609b16ead/src/read.js#L24-L26 |
22,747 | philbooth/bfj | src/write.js | write | function write (path, data, options) {
const Promise = promise(options)
return new Promise((resolve, reject) => {
streamify(data, options)
.pipe(fs.createWriteStream(path, options))
.on('finish', () => {
resolve()
})
.on('error', reject)
.on('dataError', reject)
})
} | javascript | function write (path, data, options) {
const Promise = promise(options)
return new Promise((resolve, reject) => {
streamify(data, options)
.pipe(fs.createWriteStream(path, options))
.on('finish', () => {
resolve()
})
.on('error', reject)
.on('dataError', reject)
})
} | [
"function",
"write",
"(",
"path",
",",
"data",
",",
"options",
")",
"{",
"const",
"Promise",
"=",
"promise",
"(",
"options",
")",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"streamify",
"(",
"data",
",",
"options",
")",
".",
"pipe",
"(",
"fs",
".",
"createWriteStream",
"(",
"path",
",",
"options",
")",
")",
".",
"on",
"(",
"'finish'",
",",
"(",
")",
"=>",
"{",
"resolve",
"(",
")",
"}",
")",
".",
"on",
"(",
"'error'",
",",
"reject",
")",
".",
"on",
"(",
"'dataError'",
",",
"reject",
")",
"}",
")",
"}"
] | Public function `write`.
Returns a promise and asynchronously serialises a data structure to a
JSON file on disk. Sanely handles promises, buffers, maps and other
iterables.
@param path: Path to the JSON file.
@param data: The data to transform.
@option space: Indentation string, or the number of spaces
to indent each nested level by.
@option promises: 'resolve' or 'ignore', default is 'resolve'.
@option buffers: 'toString' or 'ignore', default is 'toString'.
@option maps: 'object' or 'ignore', default is 'object'.
@option iterables: 'array' or 'ignore', default is 'array'.
@option circular: 'error' or 'ignore', default is 'error'.
@option yieldRate: The number of data items to process per timeslice,
default is 16384.
@option bufferLength: The length of the buffer, default is 1024.
@option highWaterMark: If set, will be passed to the readable stream constructor
as the value for the highWaterMark option.
@option Promise: The promise constructor to use, defaults to bluebird. | [
"Public",
"function",
"write",
"."
] | 61087c194d5675c75569a2e08617a98609b16ead | https://github.com/philbooth/bfj/blob/61087c194d5675c75569a2e08617a98609b16ead/src/write.js#L43-L55 |
22,748 | philbooth/bfj | src/stringify.js | stringify | function stringify (data, options) {
const json = []
const Promise = promise(options)
const stream = streamify(data, options)
let resolve, reject
stream.on('data', read)
stream.on('end', end)
stream.on('error', error)
stream.on('dataError', error)
return new Promise((res, rej) => {
resolve = res
reject = rej
})
function read (chunk) {
json.push(chunk)
}
function end () {
resolve(json.join(''))
}
function error (e) {
reject(e)
}
} | javascript | function stringify (data, options) {
const json = []
const Promise = promise(options)
const stream = streamify(data, options)
let resolve, reject
stream.on('data', read)
stream.on('end', end)
stream.on('error', error)
stream.on('dataError', error)
return new Promise((res, rej) => {
resolve = res
reject = rej
})
function read (chunk) {
json.push(chunk)
}
function end () {
resolve(json.join(''))
}
function error (e) {
reject(e)
}
} | [
"function",
"stringify",
"(",
"data",
",",
"options",
")",
"{",
"const",
"json",
"=",
"[",
"]",
"const",
"Promise",
"=",
"promise",
"(",
"options",
")",
"const",
"stream",
"=",
"streamify",
"(",
"data",
",",
"options",
")",
"let",
"resolve",
",",
"reject",
"stream",
".",
"on",
"(",
"'data'",
",",
"read",
")",
"stream",
".",
"on",
"(",
"'end'",
",",
"end",
")",
"stream",
".",
"on",
"(",
"'error'",
",",
"error",
")",
"stream",
".",
"on",
"(",
"'dataError'",
",",
"error",
")",
"return",
"new",
"Promise",
"(",
"(",
"res",
",",
"rej",
")",
"=>",
"{",
"resolve",
"=",
"res",
"reject",
"=",
"rej",
"}",
")",
"function",
"read",
"(",
"chunk",
")",
"{",
"json",
".",
"push",
"(",
"chunk",
")",
"}",
"function",
"end",
"(",
")",
"{",
"resolve",
"(",
"json",
".",
"join",
"(",
"''",
")",
")",
"}",
"function",
"error",
"(",
"e",
")",
"{",
"reject",
"(",
"e",
")",
"}",
"}"
] | Public function `stringify`.
Returns a promise and asynchronously serialises a data structure to a
JSON string. Sanely handles promises, buffers, maps and other iterables.
@param data: The data to transform
@option space: Indentation string, or the number of spaces
to indent each nested level by.
@option promises: 'resolve' or 'ignore', default is 'resolve'.
@option buffers: 'toString' or 'ignore', default is 'toString'.
@option maps: 'object' or 'ignore', default is 'object'.
@option iterables: 'array' or 'ignore', default is 'array'.
@option circular: 'error' or 'ignore', default is 'error'.
@option yieldRate: The number of data items to process per timeslice,
default is 16384.
@option bufferLength: The length of the buffer, default is 1024.
@option highWaterMark: If set, will be passed to the readable stream constructor
as the value for the highWaterMark option.
@option Promise: The promise constructor to use, defaults to bluebird. | [
"Public",
"function",
"stringify",
"."
] | 61087c194d5675c75569a2e08617a98609b16ead | https://github.com/philbooth/bfj/blob/61087c194d5675c75569a2e08617a98609b16ead/src/stringify.js#L39-L67 |
22,749 | philbooth/bfj | src/unpipe.js | unpipe | function unpipe (callback, options) {
check.assert.function(callback, 'Invalid callback argument')
const jsonstream = new stream.PassThrough()
parse(jsonstream, Object.assign({}, options, { ndjson: false }))
.then(data => callback(null, data))
.catch(error => callback(error))
return jsonstream
} | javascript | function unpipe (callback, options) {
check.assert.function(callback, 'Invalid callback argument')
const jsonstream = new stream.PassThrough()
parse(jsonstream, Object.assign({}, options, { ndjson: false }))
.then(data => callback(null, data))
.catch(error => callback(error))
return jsonstream
} | [
"function",
"unpipe",
"(",
"callback",
",",
"options",
")",
"{",
"check",
".",
"assert",
".",
"function",
"(",
"callback",
",",
"'Invalid callback argument'",
")",
"const",
"jsonstream",
"=",
"new",
"stream",
".",
"PassThrough",
"(",
")",
"parse",
"(",
"jsonstream",
",",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"options",
",",
"{",
"ndjson",
":",
"false",
"}",
")",
")",
".",
"then",
"(",
"data",
"=>",
"callback",
"(",
"null",
",",
"data",
")",
")",
".",
"catch",
"(",
"error",
"=>",
"callback",
"(",
"error",
")",
")",
"return",
"jsonstream",
"}"
] | Public function `unpipe`.
Returns a writeable stream that can be passed to stream.pipe, then parses JSON
data read from the stream. If there are no errors, the callback is invoked with
the result as the second argument. If errors occur, the first error is passed to
the callback as the first argument.
@param callback: Function that will be called after parsing is complete.
@option reviver: Transformation function, invoked depth-first.
@option discard: The number of characters to process before discarding them
to save memory. The default value is `1048576`.
@option yieldRate: The number of data items to process per timeslice,
default is 16384. | [
"Public",
"function",
"unpipe",
"."
] | 61087c194d5675c75569a2e08617a98609b16ead | https://github.com/philbooth/bfj/blob/61087c194d5675c75569a2e08617a98609b16ead/src/unpipe.js#L27-L37 |
22,750 | kevinbeaty/any-promise | register.js | loadImplementation | function loadImplementation(implementation){
var impl = null
if(shouldPreferGlobalPromise(implementation)){
// if no implementation or env specified use global.Promise
impl = {
Promise: global.Promise,
implementation: 'global.Promise'
}
} else if(implementation){
// if implementation specified, require it
var lib = require(implementation)
impl = {
Promise: lib.Promise || lib,
implementation: implementation
}
} else {
// try to auto detect implementation. This is non-deterministic
// and should prefer other branches, but this is our last chance
// to load something without throwing error
impl = tryAutoDetect()
}
if(impl === null){
throw new Error('Cannot find any-promise implementation nor'+
' global.Promise. You must install polyfill or call'+
' require("any-promise/register") with your preferred'+
' implementation, e.g. require("any-promise/register/bluebird")'+
' on application load prior to any require("any-promise").')
}
return impl
} | javascript | function loadImplementation(implementation){
var impl = null
if(shouldPreferGlobalPromise(implementation)){
// if no implementation or env specified use global.Promise
impl = {
Promise: global.Promise,
implementation: 'global.Promise'
}
} else if(implementation){
// if implementation specified, require it
var lib = require(implementation)
impl = {
Promise: lib.Promise || lib,
implementation: implementation
}
} else {
// try to auto detect implementation. This is non-deterministic
// and should prefer other branches, but this is our last chance
// to load something without throwing error
impl = tryAutoDetect()
}
if(impl === null){
throw new Error('Cannot find any-promise implementation nor'+
' global.Promise. You must install polyfill or call'+
' require("any-promise/register") with your preferred'+
' implementation, e.g. require("any-promise/register/bluebird")'+
' on application load prior to any require("any-promise").')
}
return impl
} | [
"function",
"loadImplementation",
"(",
"implementation",
")",
"{",
"var",
"impl",
"=",
"null",
"if",
"(",
"shouldPreferGlobalPromise",
"(",
"implementation",
")",
")",
"{",
"// if no implementation or env specified use global.Promise",
"impl",
"=",
"{",
"Promise",
":",
"global",
".",
"Promise",
",",
"implementation",
":",
"'global.Promise'",
"}",
"}",
"else",
"if",
"(",
"implementation",
")",
"{",
"// if implementation specified, require it",
"var",
"lib",
"=",
"require",
"(",
"implementation",
")",
"impl",
"=",
"{",
"Promise",
":",
"lib",
".",
"Promise",
"||",
"lib",
",",
"implementation",
":",
"implementation",
"}",
"}",
"else",
"{",
"// try to auto detect implementation. This is non-deterministic",
"// and should prefer other branches, but this is our last chance",
"// to load something without throwing error",
"impl",
"=",
"tryAutoDetect",
"(",
")",
"}",
"if",
"(",
"impl",
"===",
"null",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Cannot find any-promise implementation nor'",
"+",
"' global.Promise. You must install polyfill or call'",
"+",
"' require(\"any-promise/register\") with your preferred'",
"+",
"' implementation, e.g. require(\"any-promise/register/bluebird\")'",
"+",
"' on application load prior to any require(\"any-promise\").'",
")",
"}",
"return",
"impl",
"}"
] | Node.js version of loadImplementation.
Requires the given implementation and returns the registration
containing {Promise, implementation}
If implementation is undefined or global.Promise, loads it
Otherwise uses require | [
"Node",
".",
"js",
"version",
"of",
"loadImplementation",
"."
] | c2029f9e37a15b04c303bd0ec19cf16d00ec8f3d | https://github.com/kevinbeaty/any-promise/blob/c2029f9e37a15b04c303bd0ec19cf16d00ec8f3d/register.js#L13-L45 |
22,751 | kevinbeaty/any-promise | register.js | shouldPreferGlobalPromise | function shouldPreferGlobalPromise(implementation){
if(implementation){
return implementation === 'global.Promise'
} else if(typeof global.Promise !== 'undefined'){
// Load global promise if implementation not specified
// Versions < 0.11 did not have global Promise
// Do not use for version < 0.12 as version 0.11 contained buggy versions
var version = (/v(\d+)\.(\d+)\.(\d+)/).exec(process.version)
return !(version && +version[1] == 0 && +version[2] < 12)
}
// do not have global.Promise or another implementation was specified
return false
} | javascript | function shouldPreferGlobalPromise(implementation){
if(implementation){
return implementation === 'global.Promise'
} else if(typeof global.Promise !== 'undefined'){
// Load global promise if implementation not specified
// Versions < 0.11 did not have global Promise
// Do not use for version < 0.12 as version 0.11 contained buggy versions
var version = (/v(\d+)\.(\d+)\.(\d+)/).exec(process.version)
return !(version && +version[1] == 0 && +version[2] < 12)
}
// do not have global.Promise or another implementation was specified
return false
} | [
"function",
"shouldPreferGlobalPromise",
"(",
"implementation",
")",
"{",
"if",
"(",
"implementation",
")",
"{",
"return",
"implementation",
"===",
"'global.Promise'",
"}",
"else",
"if",
"(",
"typeof",
"global",
".",
"Promise",
"!==",
"'undefined'",
")",
"{",
"// Load global promise if implementation not specified",
"// Versions < 0.11 did not have global Promise",
"// Do not use for version < 0.12 as version 0.11 contained buggy versions",
"var",
"version",
"=",
"(",
"/",
"v(\\d+)\\.(\\d+)\\.(\\d+)",
"/",
")",
".",
"exec",
"(",
"process",
".",
"version",
")",
"return",
"!",
"(",
"version",
"&&",
"+",
"version",
"[",
"1",
"]",
"==",
"0",
"&&",
"+",
"version",
"[",
"2",
"]",
"<",
"12",
")",
"}",
"// do not have global.Promise or another implementation was specified",
"return",
"false",
"}"
] | Determines if the global.Promise should be preferred if an implementation
has not been registered. | [
"Determines",
"if",
"the",
"global",
".",
"Promise",
"should",
"be",
"preferred",
"if",
"an",
"implementation",
"has",
"not",
"been",
"registered",
"."
] | c2029f9e37a15b04c303bd0ec19cf16d00ec8f3d | https://github.com/kevinbeaty/any-promise/blob/c2029f9e37a15b04c303bd0ec19cf16d00ec8f3d/register.js#L51-L64 |
22,752 | kevinbeaty/any-promise | register.js | tryAutoDetect | function tryAutoDetect(){
var libs = [
"es6-promise",
"promise",
"native-promise-only",
"bluebird",
"rsvp",
"when",
"q",
"pinkie",
"lie",
"vow"]
var i = 0, len = libs.length
for(; i < len; i++){
try {
return loadImplementation(libs[i])
} catch(e){}
}
return null
} | javascript | function tryAutoDetect(){
var libs = [
"es6-promise",
"promise",
"native-promise-only",
"bluebird",
"rsvp",
"when",
"q",
"pinkie",
"lie",
"vow"]
var i = 0, len = libs.length
for(; i < len; i++){
try {
return loadImplementation(libs[i])
} catch(e){}
}
return null
} | [
"function",
"tryAutoDetect",
"(",
")",
"{",
"var",
"libs",
"=",
"[",
"\"es6-promise\"",
",",
"\"promise\"",
",",
"\"native-promise-only\"",
",",
"\"bluebird\"",
",",
"\"rsvp\"",
",",
"\"when\"",
",",
"\"q\"",
",",
"\"pinkie\"",
",",
"\"lie\"",
",",
"\"vow\"",
"]",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"libs",
".",
"length",
"for",
"(",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"try",
"{",
"return",
"loadImplementation",
"(",
"libs",
"[",
"i",
"]",
")",
"}",
"catch",
"(",
"e",
")",
"{",
"}",
"}",
"return",
"null",
"}"
] | Look for common libs as last resort there is no guarantee that
this will return a desired implementation or even be deterministic.
The priority is also nearly arbitrary. We are only doing this
for older versions of Node.js <0.12 that do not have a reasonable
global.Promise implementation and we the user has not registered
the preference. This preserves the behavior of any-promise <= 0.1
and may be deprecated or removed in the future | [
"Look",
"for",
"common",
"libs",
"as",
"last",
"resort",
"there",
"is",
"no",
"guarantee",
"that",
"this",
"will",
"return",
"a",
"desired",
"implementation",
"or",
"even",
"be",
"deterministic",
".",
"The",
"priority",
"is",
"also",
"nearly",
"arbitrary",
".",
"We",
"are",
"only",
"doing",
"this",
"for",
"older",
"versions",
"of",
"Node",
".",
"js",
"<0",
".",
"12",
"that",
"do",
"not",
"have",
"a",
"reasonable",
"global",
".",
"Promise",
"implementation",
"and",
"we",
"the",
"user",
"has",
"not",
"registered",
"the",
"preference",
".",
"This",
"preserves",
"the",
"behavior",
"of",
"any",
"-",
"promise",
"<",
"=",
"0",
".",
"1",
"and",
"may",
"be",
"deprecated",
"or",
"removed",
"in",
"the",
"future"
] | c2029f9e37a15b04c303bd0ec19cf16d00ec8f3d | https://github.com/kevinbeaty/any-promise/blob/c2029f9e37a15b04c303bd0ec19cf16d00ec8f3d/register.js#L75-L94 |
22,753 | ranm8/requestify | lib/request.js | Request | function Request(url, options) {
if (!url) {
throw new Error('URL must in mandatory to initialize Request object');
}
if (!options.method) {
throw new Error('Cannot execute HTTP request without specifying method');
}
this.url = url;
this.method = options.method;
this.body = options.body || {};
this.params = options.params || {};
this.path = options.path || null;
this.headers = options.headers || {};
this.dataType = (options.dataType === undefined) ? 'json' : options.dataType;
this.auth = options.auth || {};
this.cache = options.cache || { cache: false, expires: 3600 };
this.timeout = options.timeout || 30000;
this.cookies(options.cookies);
this.redirect = options.redirect || false
} | javascript | function Request(url, options) {
if (!url) {
throw new Error('URL must in mandatory to initialize Request object');
}
if (!options.method) {
throw new Error('Cannot execute HTTP request without specifying method');
}
this.url = url;
this.method = options.method;
this.body = options.body || {};
this.params = options.params || {};
this.path = options.path || null;
this.headers = options.headers || {};
this.dataType = (options.dataType === undefined) ? 'json' : options.dataType;
this.auth = options.auth || {};
this.cache = options.cache || { cache: false, expires: 3600 };
this.timeout = options.timeout || 30000;
this.cookies(options.cookies);
this.redirect = options.redirect || false
} | [
"function",
"Request",
"(",
"url",
",",
"options",
")",
"{",
"if",
"(",
"!",
"url",
")",
"{",
"throw",
"new",
"Error",
"(",
"'URL must in mandatory to initialize Request object'",
")",
";",
"}",
"if",
"(",
"!",
"options",
".",
"method",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Cannot execute HTTP request without specifying method'",
")",
";",
"}",
"this",
".",
"url",
"=",
"url",
";",
"this",
".",
"method",
"=",
"options",
".",
"method",
";",
"this",
".",
"body",
"=",
"options",
".",
"body",
"||",
"{",
"}",
";",
"this",
".",
"params",
"=",
"options",
".",
"params",
"||",
"{",
"}",
";",
"this",
".",
"path",
"=",
"options",
".",
"path",
"||",
"null",
";",
"this",
".",
"headers",
"=",
"options",
".",
"headers",
"||",
"{",
"}",
";",
"this",
".",
"dataType",
"=",
"(",
"options",
".",
"dataType",
"===",
"undefined",
")",
"?",
"'json'",
":",
"options",
".",
"dataType",
";",
"this",
".",
"auth",
"=",
"options",
".",
"auth",
"||",
"{",
"}",
";",
"this",
".",
"cache",
"=",
"options",
".",
"cache",
"||",
"{",
"cache",
":",
"false",
",",
"expires",
":",
"3600",
"}",
";",
"this",
".",
"timeout",
"=",
"options",
".",
"timeout",
"||",
"30000",
";",
"this",
".",
"cookies",
"(",
"options",
".",
"cookies",
")",
";",
"this",
".",
"redirect",
"=",
"options",
".",
"redirect",
"||",
"false",
"}"
] | Constructor for the Request object
@param {string} url - Full endpoint URL (e.g. [protocol]://[host]/[uri]
@param {{ method: string, body: string|object, params: object, headers: object, dataType: string, auth: object, timeout: number, cookies: object }} options
@constructor | [
"Constructor",
"for",
"the",
"Request",
"object"
] | c7ca8b716ad04f94a12d94d69b2fe3a838c3d6e6 | https://github.com/ranm8/requestify/blob/c7ca8b716ad04f94a12d94d69b2fe3a838c3d6e6/lib/request.js#L13-L34 |
22,754 | ranm8/requestify | lib/response.js | Response | function Response(code, headers, body) {
this.code = code;
this.headers = headers;
this.body = body || '';
} | javascript | function Response(code, headers, body) {
this.code = code;
this.headers = headers;
this.body = body || '';
} | [
"function",
"Response",
"(",
"code",
",",
"headers",
",",
"body",
")",
"{",
"this",
".",
"code",
"=",
"code",
";",
"this",
".",
"headers",
"=",
"headers",
";",
"this",
".",
"body",
"=",
"body",
"||",
"''",
";",
"}"
] | Constructor to the Response object
@param {number} code - HTTP response code
@param {object} headers - Key value pairs of response headers
@param {string} body
@constructor | [
"Constructor",
"to",
"the",
"Response",
"object"
] | c7ca8b716ad04f94a12d94d69b2fe3a838c3d6e6 | https://github.com/ranm8/requestify/blob/c7ca8b716ad04f94a12d94d69b2fe3a838c3d6e6/lib/response.js#L15-L19 |
22,755 | fractal-code/meteor-azure | distribution/lib/bundle.js | compileBundle | function compileBundle(_ref) {
var customWebConfig = _ref.customWebConfig,
architecture = _ref.architecture;
var workingDir = _tmp.default.dirSync().name;
_winston.default.info('Compiling application bundle'); // Generate Meteor build
_winston.default.debug('generate meteor build');
_shelljs.default.exec(`meteor build ${workingDir} --directory --server-only --architecture os.windows.x86_${architecture}`); // Add custom web config
if (customWebConfig !== undefined) {
_winston.default.debug('add custom web config');
try {
_shelljs.default.cp(customWebConfig, _path.default.join(workingDir, 'bundle', 'web.config'));
} catch (error) {
throw new Error(`Could not read web config file at '${customWebConfig}'`);
}
} else {
_winston.default.warn('Using default web config');
} // Cleanup broken symlinks
_winston.default.debug('checking for broken symlinks');
_shelljs.default.find(_path.default.join(workingDir, 'bundle')).forEach(function (symlinkPath) {
// Matches symlinks that do not exist
if (_shelljs.default.test('-L', symlinkPath) && !_shelljs.default.test('-e', symlinkPath)) {
// Delete file
_shelljs.default.rm('-f', symlinkPath);
_winston.default.debug(`deleted symlink at '${symlinkPath}'`);
}
}); // Create tarball
_winston.default.debug('create tarball');
var tarballPath = _path.default.join(workingDir, 'bundle.tar.gz');
_tar.default.c({
file: tarballPath,
sync: true,
follow: true,
gzip: true,
cwd: workingDir
}, ['bundle']);
return tarballPath;
} | javascript | function compileBundle(_ref) {
var customWebConfig = _ref.customWebConfig,
architecture = _ref.architecture;
var workingDir = _tmp.default.dirSync().name;
_winston.default.info('Compiling application bundle'); // Generate Meteor build
_winston.default.debug('generate meteor build');
_shelljs.default.exec(`meteor build ${workingDir} --directory --server-only --architecture os.windows.x86_${architecture}`); // Add custom web config
if (customWebConfig !== undefined) {
_winston.default.debug('add custom web config');
try {
_shelljs.default.cp(customWebConfig, _path.default.join(workingDir, 'bundle', 'web.config'));
} catch (error) {
throw new Error(`Could not read web config file at '${customWebConfig}'`);
}
} else {
_winston.default.warn('Using default web config');
} // Cleanup broken symlinks
_winston.default.debug('checking for broken symlinks');
_shelljs.default.find(_path.default.join(workingDir, 'bundle')).forEach(function (symlinkPath) {
// Matches symlinks that do not exist
if (_shelljs.default.test('-L', symlinkPath) && !_shelljs.default.test('-e', symlinkPath)) {
// Delete file
_shelljs.default.rm('-f', symlinkPath);
_winston.default.debug(`deleted symlink at '${symlinkPath}'`);
}
}); // Create tarball
_winston.default.debug('create tarball');
var tarballPath = _path.default.join(workingDir, 'bundle.tar.gz');
_tar.default.c({
file: tarballPath,
sync: true,
follow: true,
gzip: true,
cwd: workingDir
}, ['bundle']);
return tarballPath;
} | [
"function",
"compileBundle",
"(",
"_ref",
")",
"{",
"var",
"customWebConfig",
"=",
"_ref",
".",
"customWebConfig",
",",
"architecture",
"=",
"_ref",
".",
"architecture",
";",
"var",
"workingDir",
"=",
"_tmp",
".",
"default",
".",
"dirSync",
"(",
")",
".",
"name",
";",
"_winston",
".",
"default",
".",
"info",
"(",
"'Compiling application bundle'",
")",
";",
"// Generate Meteor build",
"_winston",
".",
"default",
".",
"debug",
"(",
"'generate meteor build'",
")",
";",
"_shelljs",
".",
"default",
".",
"exec",
"(",
"`",
"${",
"workingDir",
"}",
"${",
"architecture",
"}",
"`",
")",
";",
"// Add custom web config",
"if",
"(",
"customWebConfig",
"!==",
"undefined",
")",
"{",
"_winston",
".",
"default",
".",
"debug",
"(",
"'add custom web config'",
")",
";",
"try",
"{",
"_shelljs",
".",
"default",
".",
"cp",
"(",
"customWebConfig",
",",
"_path",
".",
"default",
".",
"join",
"(",
"workingDir",
",",
"'bundle'",
",",
"'web.config'",
")",
")",
";",
"}",
"catch",
"(",
"error",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"customWebConfig",
"}",
"`",
")",
";",
"}",
"}",
"else",
"{",
"_winston",
".",
"default",
".",
"warn",
"(",
"'Using default web config'",
")",
";",
"}",
"// Cleanup broken symlinks",
"_winston",
".",
"default",
".",
"debug",
"(",
"'checking for broken symlinks'",
")",
";",
"_shelljs",
".",
"default",
".",
"find",
"(",
"_path",
".",
"default",
".",
"join",
"(",
"workingDir",
",",
"'bundle'",
")",
")",
".",
"forEach",
"(",
"function",
"(",
"symlinkPath",
")",
"{",
"// Matches symlinks that do not exist",
"if",
"(",
"_shelljs",
".",
"default",
".",
"test",
"(",
"'-L'",
",",
"symlinkPath",
")",
"&&",
"!",
"_shelljs",
".",
"default",
".",
"test",
"(",
"'-e'",
",",
"symlinkPath",
")",
")",
"{",
"// Delete file",
"_shelljs",
".",
"default",
".",
"rm",
"(",
"'-f'",
",",
"symlinkPath",
")",
";",
"_winston",
".",
"default",
".",
"debug",
"(",
"`",
"${",
"symlinkPath",
"}",
"`",
")",
";",
"}",
"}",
")",
";",
"// Create tarball",
"_winston",
".",
"default",
".",
"debug",
"(",
"'create tarball'",
")",
";",
"var",
"tarballPath",
"=",
"_path",
".",
"default",
".",
"join",
"(",
"workingDir",
",",
"'bundle.tar.gz'",
")",
";",
"_tar",
".",
"default",
".",
"c",
"(",
"{",
"file",
":",
"tarballPath",
",",
"sync",
":",
"true",
",",
"follow",
":",
"true",
",",
"gzip",
":",
"true",
",",
"cwd",
":",
"workingDir",
"}",
",",
"[",
"'bundle'",
"]",
")",
";",
"return",
"tarballPath",
";",
"}"
] | Bundle compilation method | [
"Bundle",
"compilation",
"method"
] | 87aaf8582be5734c78445c40569444101c02bc3f | https://github.com/fractal-code/meteor-azure/blob/87aaf8582be5734c78445c40569444101c02bc3f/distribution/lib/bundle.js#L21-L74 |
22,756 | bryanburgers/node-mustache-express | mustache-express.js | loadFile | function loadFile(fullFilePath, callback) {
fs.readFile(fullFilePath, "utf-8", function(err, data) {
if (err) {
return callback(err);
}
return callback(null, data);
});
} | javascript | function loadFile(fullFilePath, callback) {
fs.readFile(fullFilePath, "utf-8", function(err, data) {
if (err) {
return callback(err);
}
return callback(null, data);
});
} | [
"function",
"loadFile",
"(",
"fullFilePath",
",",
"callback",
")",
"{",
"fs",
".",
"readFile",
"(",
"fullFilePath",
",",
"\"utf-8\"",
",",
"function",
"(",
"err",
",",
"data",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"return",
"callback",
"(",
"null",
",",
"data",
")",
";",
"}",
")",
";",
"}"
] | Load a single file, and return the data. | [
"Load",
"a",
"single",
"file",
"and",
"return",
"the",
"data",
"."
] | 1700934e0ac510ee69225de226ccf4b4db41b65d | https://github.com/bryanburgers/node-mustache-express/blob/1700934e0ac510ee69225de226ccf4b4db41b65d/mustache-express.js#L17-L25 |
22,757 | bryanburgers/node-mustache-express | mustache-express.js | handleFile | function handleFile(name, file, options, cache, callback) {
var cachedData;
if(!options || !options.settings || options.settings['view cache'] !== false) {
cachedData = cache && cache.get(file);
}
if (!cachedData) {
loadFile(file, function(err, fileData) {
if (err) {
return callback(err);
}
var partials;
try {
partials = findPartials(fileData);
} catch (err) {
return callback(err);
}
var data = {
name: name,
data: fileData,
partials: partials
};
if (cache) {
cache.set(file, data);
}
return callback(null, data);
});
}
else {
return callback(null, cachedData);
}
} | javascript | function handleFile(name, file, options, cache, callback) {
var cachedData;
if(!options || !options.settings || options.settings['view cache'] !== false) {
cachedData = cache && cache.get(file);
}
if (!cachedData) {
loadFile(file, function(err, fileData) {
if (err) {
return callback(err);
}
var partials;
try {
partials = findPartials(fileData);
} catch (err) {
return callback(err);
}
var data = {
name: name,
data: fileData,
partials: partials
};
if (cache) {
cache.set(file, data);
}
return callback(null, data);
});
}
else {
return callback(null, cachedData);
}
} | [
"function",
"handleFile",
"(",
"name",
",",
"file",
",",
"options",
",",
"cache",
",",
"callback",
")",
"{",
"var",
"cachedData",
";",
"if",
"(",
"!",
"options",
"||",
"!",
"options",
".",
"settings",
"||",
"options",
".",
"settings",
"[",
"'view cache'",
"]",
"!==",
"false",
")",
"{",
"cachedData",
"=",
"cache",
"&&",
"cache",
".",
"get",
"(",
"file",
")",
";",
"}",
"if",
"(",
"!",
"cachedData",
")",
"{",
"loadFile",
"(",
"file",
",",
"function",
"(",
"err",
",",
"fileData",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"var",
"partials",
";",
"try",
"{",
"partials",
"=",
"findPartials",
"(",
"fileData",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"var",
"data",
"=",
"{",
"name",
":",
"name",
",",
"data",
":",
"fileData",
",",
"partials",
":",
"partials",
"}",
";",
"if",
"(",
"cache",
")",
"{",
"cache",
".",
"set",
"(",
"file",
",",
"data",
")",
";",
"}",
"return",
"callback",
"(",
"null",
",",
"data",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"return",
"callback",
"(",
"null",
",",
"cachedData",
")",
";",
"}",
"}"
] | Load a file, find it's partials, and return the relevant data. | [
"Load",
"a",
"file",
"find",
"it",
"s",
"partials",
"and",
"return",
"the",
"relevant",
"data",
"."
] | 1700934e0ac510ee69225de226ccf4b4db41b65d | https://github.com/bryanburgers/node-mustache-express/blob/1700934e0ac510ee69225de226ccf4b4db41b65d/mustache-express.js#L28-L60 |
22,758 | bryanburgers/node-mustache-express | mustache-express.js | consolidatePartials | function consolidatePartials(arr) {
var partialsSet = {};
arr.forEach(function(item) {
item.partials.forEach(function(partial) {
partialsSet[partial] = true;
});
});
return Object.keys(partialsSet);
} | javascript | function consolidatePartials(arr) {
var partialsSet = {};
arr.forEach(function(item) {
item.partials.forEach(function(partial) {
partialsSet[partial] = true;
});
});
return Object.keys(partialsSet);
} | [
"function",
"consolidatePartials",
"(",
"arr",
")",
"{",
"var",
"partialsSet",
"=",
"{",
"}",
";",
"arr",
".",
"forEach",
"(",
"function",
"(",
"item",
")",
"{",
"item",
".",
"partials",
".",
"forEach",
"(",
"function",
"(",
"partial",
")",
"{",
"partialsSet",
"[",
"partial",
"]",
"=",
"true",
";",
"}",
")",
";",
"}",
")",
";",
"return",
"Object",
".",
"keys",
"(",
"partialsSet",
")",
";",
"}"
] | Using the return data from all of the files, consolidate the partials into a single list | [
"Using",
"the",
"return",
"data",
"from",
"all",
"of",
"the",
"files",
"consolidate",
"the",
"partials",
"into",
"a",
"single",
"list"
] | 1700934e0ac510ee69225de226ccf4b4db41b65d | https://github.com/bryanburgers/node-mustache-express/blob/1700934e0ac510ee69225de226ccf4b4db41b65d/mustache-express.js#L64-L72 |
22,759 | bryanburgers/node-mustache-express | mustache-express.js | loadAllPartials | function loadAllPartials(unparsedPartials, partialsDirectory, partialsExtension, options, cache, partials, callback) {
if (!partials) {
partials = {};
}
// This function is called recursively. This is our base case: the point where we
// don't call recursively anymore.
// That point is when there are no partials that need to be parsed.
if (unparsedPartials.length === 0) {
return callback(null, partials);
}
async.map(unparsedPartials, function(partial, next) {
var fullFilePath;
if('function' === typeof partialsDirectory){
fullFilePath = partialsDirectory(partial,partialsExtension);
} else {
fullFilePath = path.resolve(partialsDirectory, partial + partialsExtension);
}
return handleFile(partial, fullFilePath, options, cache, next);
}, function(err, data) {
if (err) {
return callback(err);
}
// Add all of the data to the 'partials' object
data.forEach(function(partialData) {
partials[partialData.name] = partialData.data;
});
// Get all of the partials that are referenced by the data we've loaded
var consolidatedPartials = consolidatePartials(data);
// Get all of the partials that we haven't loaded yet.
var partialsToLoad = findUnloadedPartials(consolidatedPartials, partials);
// Recursive call.
return loadAllPartials(partialsToLoad, partialsDirectory, partialsExtension, options, cache, partials, callback);
});
} | javascript | function loadAllPartials(unparsedPartials, partialsDirectory, partialsExtension, options, cache, partials, callback) {
if (!partials) {
partials = {};
}
// This function is called recursively. This is our base case: the point where we
// don't call recursively anymore.
// That point is when there are no partials that need to be parsed.
if (unparsedPartials.length === 0) {
return callback(null, partials);
}
async.map(unparsedPartials, function(partial, next) {
var fullFilePath;
if('function' === typeof partialsDirectory){
fullFilePath = partialsDirectory(partial,partialsExtension);
} else {
fullFilePath = path.resolve(partialsDirectory, partial + partialsExtension);
}
return handleFile(partial, fullFilePath, options, cache, next);
}, function(err, data) {
if (err) {
return callback(err);
}
// Add all of the data to the 'partials' object
data.forEach(function(partialData) {
partials[partialData.name] = partialData.data;
});
// Get all of the partials that are referenced by the data we've loaded
var consolidatedPartials = consolidatePartials(data);
// Get all of the partials that we haven't loaded yet.
var partialsToLoad = findUnloadedPartials(consolidatedPartials, partials);
// Recursive call.
return loadAllPartials(partialsToLoad, partialsDirectory, partialsExtension, options, cache, partials, callback);
});
} | [
"function",
"loadAllPartials",
"(",
"unparsedPartials",
",",
"partialsDirectory",
",",
"partialsExtension",
",",
"options",
",",
"cache",
",",
"partials",
",",
"callback",
")",
"{",
"if",
"(",
"!",
"partials",
")",
"{",
"partials",
"=",
"{",
"}",
";",
"}",
"// This function is called recursively. This is our base case: the point where we",
"// don't call recursively anymore.",
"// That point is when there are no partials that need to be parsed.",
"if",
"(",
"unparsedPartials",
".",
"length",
"===",
"0",
")",
"{",
"return",
"callback",
"(",
"null",
",",
"partials",
")",
";",
"}",
"async",
".",
"map",
"(",
"unparsedPartials",
",",
"function",
"(",
"partial",
",",
"next",
")",
"{",
"var",
"fullFilePath",
";",
"if",
"(",
"'function'",
"===",
"typeof",
"partialsDirectory",
")",
"{",
"fullFilePath",
"=",
"partialsDirectory",
"(",
"partial",
",",
"partialsExtension",
")",
";",
"}",
"else",
"{",
"fullFilePath",
"=",
"path",
".",
"resolve",
"(",
"partialsDirectory",
",",
"partial",
"+",
"partialsExtension",
")",
";",
"}",
"return",
"handleFile",
"(",
"partial",
",",
"fullFilePath",
",",
"options",
",",
"cache",
",",
"next",
")",
";",
"}",
",",
"function",
"(",
"err",
",",
"data",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"// Add all of the data to the 'partials' object",
"data",
".",
"forEach",
"(",
"function",
"(",
"partialData",
")",
"{",
"partials",
"[",
"partialData",
".",
"name",
"]",
"=",
"partialData",
".",
"data",
";",
"}",
")",
";",
"// Get all of the partials that are referenced by the data we've loaded",
"var",
"consolidatedPartials",
"=",
"consolidatePartials",
"(",
"data",
")",
";",
"// Get all of the partials that we haven't loaded yet.",
"var",
"partialsToLoad",
"=",
"findUnloadedPartials",
"(",
"consolidatedPartials",
",",
"partials",
")",
";",
"// Recursive call.",
"return",
"loadAllPartials",
"(",
"partialsToLoad",
",",
"partialsDirectory",
",",
"partialsExtension",
",",
"options",
",",
"cache",
",",
"partials",
",",
"callback",
")",
";",
"}",
")",
";",
"}"
] | Load all of the partials recursively | [
"Load",
"all",
"of",
"the",
"partials",
"recursively"
] | 1700934e0ac510ee69225de226ccf4b4db41b65d | https://github.com/bryanburgers/node-mustache-express/blob/1700934e0ac510ee69225de226ccf4b4db41b65d/mustache-express.js#L82-L121 |
22,760 | bryanburgers/node-mustache-express | mustache-express.js | loadTemplateAndPartials | function loadTemplateAndPartials(templateFile, partialsDirectory, partialsExtension, options, cache, callback) {
handleFile(null, templateFile, options, cache, function(err, partialData) {
if (err) {
return callback(err);
}
return loadAllPartials(partialData.partials, partialsDirectory, partialsExtension, options, cache, null, function(err, partials) {
if (err) {
return callback(err);
}
return callback(null, partialData.data, partials);
});
});
} | javascript | function loadTemplateAndPartials(templateFile, partialsDirectory, partialsExtension, options, cache, callback) {
handleFile(null, templateFile, options, cache, function(err, partialData) {
if (err) {
return callback(err);
}
return loadAllPartials(partialData.partials, partialsDirectory, partialsExtension, options, cache, null, function(err, partials) {
if (err) {
return callback(err);
}
return callback(null, partialData.data, partials);
});
});
} | [
"function",
"loadTemplateAndPartials",
"(",
"templateFile",
",",
"partialsDirectory",
",",
"partialsExtension",
",",
"options",
",",
"cache",
",",
"callback",
")",
"{",
"handleFile",
"(",
"null",
",",
"templateFile",
",",
"options",
",",
"cache",
",",
"function",
"(",
"err",
",",
"partialData",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"return",
"loadAllPartials",
"(",
"partialData",
".",
"partials",
",",
"partialsDirectory",
",",
"partialsExtension",
",",
"options",
",",
"cache",
",",
"null",
",",
"function",
"(",
"err",
",",
"partials",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"return",
"callback",
"(",
"null",
",",
"partialData",
".",
"data",
",",
"partials",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Load the root template, and all of the partials that go with it | [
"Load",
"the",
"root",
"template",
"and",
"all",
"of",
"the",
"partials",
"that",
"go",
"with",
"it"
] | 1700934e0ac510ee69225de226ccf4b4db41b65d | https://github.com/bryanburgers/node-mustache-express/blob/1700934e0ac510ee69225de226ccf4b4db41b65d/mustache-express.js#L124-L138 |
22,761 | jaredhanson/oauthorize | examples/express2/auth.js | function(consumerKey, done) {
db.clients.findByConsumerKey(consumerKey, function(err, client) {
if (err) { return done(err); }
if (!client) { return done(null, false); }
return done(null, client, client.consumerSecret);
});
} | javascript | function(consumerKey, done) {
db.clients.findByConsumerKey(consumerKey, function(err, client) {
if (err) { return done(err); }
if (!client) { return done(null, false); }
return done(null, client, client.consumerSecret);
});
} | [
"function",
"(",
"consumerKey",
",",
"done",
")",
"{",
"db",
".",
"clients",
".",
"findByConsumerKey",
"(",
"consumerKey",
",",
"function",
"(",
"err",
",",
"client",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"done",
"(",
"err",
")",
";",
"}",
"if",
"(",
"!",
"client",
")",
"{",
"return",
"done",
"(",
"null",
",",
"false",
")",
";",
"}",
"return",
"done",
"(",
"null",
",",
"client",
",",
"client",
".",
"consumerSecret",
")",
";",
"}",
")",
";",
"}"
] | consumer callback This callback finds the registered client associated with `consumerKey`. The client should be supplied to the `done` callback as the second argument, and the consumer secret known by the server should be supplied as the third argument. The `ConsumerStrategy` will use this secret to validate the request signature, failing authentication if it does not match. | [
"consumer",
"callback",
"This",
"callback",
"finds",
"the",
"registered",
"client",
"associated",
"with",
"consumerKey",
".",
"The",
"client",
"should",
"be",
"supplied",
"to",
"the",
"done",
"callback",
"as",
"the",
"second",
"argument",
"and",
"the",
"consumer",
"secret",
"known",
"by",
"the",
"server",
"should",
"be",
"supplied",
"as",
"the",
"third",
"argument",
".",
"The",
"ConsumerStrategy",
"will",
"use",
"this",
"secret",
"to",
"validate",
"the",
"request",
"signature",
"failing",
"authentication",
"if",
"it",
"does",
"not",
"match",
"."
] | 3d9438c871f810fdec269596ccd40148dab31420 | https://github.com/jaredhanson/oauthorize/blob/3d9438c871f810fdec269596ccd40148dab31420/examples/express2/auth.js#L57-L63 | |
22,762 | jaredhanson/oauthorize | examples/express2/auth.js | function(requestToken, done) {
db.requestTokens.find(requestToken, function(err, token) {
if (err) { return done(err); }
var info = { verifier: token.verifier,
clientID: token.clientID,
userID: token.userID,
approved: token.approved
}
done(null, token.secret, info);
});
} | javascript | function(requestToken, done) {
db.requestTokens.find(requestToken, function(err, token) {
if (err) { return done(err); }
var info = { verifier: token.verifier,
clientID: token.clientID,
userID: token.userID,
approved: token.approved
}
done(null, token.secret, info);
});
} | [
"function",
"(",
"requestToken",
",",
"done",
")",
"{",
"db",
".",
"requestTokens",
".",
"find",
"(",
"requestToken",
",",
"function",
"(",
"err",
",",
"token",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"done",
"(",
"err",
")",
";",
"}",
"var",
"info",
"=",
"{",
"verifier",
":",
"token",
".",
"verifier",
",",
"clientID",
":",
"token",
".",
"clientID",
",",
"userID",
":",
"token",
".",
"userID",
",",
"approved",
":",
"token",
".",
"approved",
"}",
"done",
"(",
"null",
",",
"token",
".",
"secret",
",",
"info",
")",
";",
"}",
")",
";",
"}"
] | token callback This callback finds the request token identified by `requestToken`. This is typically only invoked when a client is exchanging a request token for an access token. The `done` callback accepts the corresponding token secret as the second argument. The `ConsumerStrategy` will use this secret to validate the request signature, failing authentication if it does not match. Furthermore, additional arbitrary `info` can be passed as the third argument to the callback. A request token will often have associated details such as the user who approved it, scope of access, etc. These details can be retrieved from the database during this step. They will then be made available by Passport at `req.authInfo` and carried through to other middleware and request handlers, avoiding the need to do additional unnecessary queries to the database. | [
"token",
"callback",
"This",
"callback",
"finds",
"the",
"request",
"token",
"identified",
"by",
"requestToken",
".",
"This",
"is",
"typically",
"only",
"invoked",
"when",
"a",
"client",
"is",
"exchanging",
"a",
"request",
"token",
"for",
"an",
"access",
"token",
".",
"The",
"done",
"callback",
"accepts",
"the",
"corresponding",
"token",
"secret",
"as",
"the",
"second",
"argument",
".",
"The",
"ConsumerStrategy",
"will",
"use",
"this",
"secret",
"to",
"validate",
"the",
"request",
"signature",
"failing",
"authentication",
"if",
"it",
"does",
"not",
"match",
".",
"Furthermore",
"additional",
"arbitrary",
"info",
"can",
"be",
"passed",
"as",
"the",
"third",
"argument",
"to",
"the",
"callback",
".",
"A",
"request",
"token",
"will",
"often",
"have",
"associated",
"details",
"such",
"as",
"the",
"user",
"who",
"approved",
"it",
"scope",
"of",
"access",
"etc",
".",
"These",
"details",
"can",
"be",
"retrieved",
"from",
"the",
"database",
"during",
"this",
"step",
".",
"They",
"will",
"then",
"be",
"made",
"available",
"by",
"Passport",
"at",
"req",
".",
"authInfo",
"and",
"carried",
"through",
"to",
"other",
"middleware",
"and",
"request",
"handlers",
"avoiding",
"the",
"need",
"to",
"do",
"additional",
"unnecessary",
"queries",
"to",
"the",
"database",
"."
] | 3d9438c871f810fdec269596ccd40148dab31420 | https://github.com/jaredhanson/oauthorize/blob/3d9438c871f810fdec269596ccd40148dab31420/examples/express2/auth.js#L80-L91 | |
22,763 | patrickkettner/grunt-compile-handlebars | tasks/compile-handlebars.js | function(config) {
if (!config) {
return [];
}
var files = grunt.file.expand(config);
if (files.length) {
return files;
}
return [config];
} | javascript | function(config) {
if (!config) {
return [];
}
var files = grunt.file.expand(config);
if (files.length) {
return files;
}
return [config];
} | [
"function",
"(",
"config",
")",
"{",
"if",
"(",
"!",
"config",
")",
"{",
"return",
"[",
"]",
";",
"}",
"var",
"files",
"=",
"grunt",
".",
"file",
".",
"expand",
"(",
"config",
")",
";",
"if",
"(",
"files",
".",
"length",
")",
"{",
"return",
"files",
";",
"}",
"return",
"[",
"config",
"]",
";",
"}"
] | Normalizes the input so that it is always an array for the forEach loop | [
"Normalizes",
"the",
"input",
"so",
"that",
"it",
"is",
"always",
"an",
"array",
"for",
"the",
"forEach",
"loop"
] | 92d7fb401340892a8f04d497d4e1508c9ed1f8bb | https://github.com/patrickkettner/grunt-compile-handlebars/blob/92d7fb401340892a8f04d497d4e1508c9ed1f8bb/tasks/compile-handlebars.js#L22-L34 | |
22,764 | patrickkettner/grunt-compile-handlebars | tasks/compile-handlebars.js | function(data, dontParse) {
// grunt.file chokes on objects, so we check for it immiedietly
if (typeof data === 'object') {
return data;
}
// `data` isn't an object, so its probably a file
try {
// alce allows us to parse single-quote JSON (which is tehcnically invalid, and thereby chokes JSON.parse)
data = grunt.file.read(data);
if (!dontParse) {
data = alce.parse(data);
}
}
catch (e) {}
return data;
} | javascript | function(data, dontParse) {
// grunt.file chokes on objects, so we check for it immiedietly
if (typeof data === 'object') {
return data;
}
// `data` isn't an object, so its probably a file
try {
// alce allows us to parse single-quote JSON (which is tehcnically invalid, and thereby chokes JSON.parse)
data = grunt.file.read(data);
if (!dontParse) {
data = alce.parse(data);
}
}
catch (e) {}
return data;
} | [
"function",
"(",
"data",
",",
"dontParse",
")",
"{",
"// grunt.file chokes on objects, so we check for it immiedietly",
"if",
"(",
"typeof",
"data",
"===",
"'object'",
")",
"{",
"return",
"data",
";",
"}",
"// `data` isn't an object, so its probably a file",
"try",
"{",
"// alce allows us to parse single-quote JSON (which is tehcnically invalid, and thereby chokes JSON.parse)",
"data",
"=",
"grunt",
".",
"file",
".",
"read",
"(",
"data",
")",
";",
"if",
"(",
"!",
"dontParse",
")",
"{",
"data",
"=",
"alce",
".",
"parse",
"(",
"data",
")",
";",
"}",
"}",
"catch",
"(",
"e",
")",
"{",
"}",
"return",
"data",
";",
"}"
] | Gets the final representation of the input, whether it be object, or string | [
"Gets",
"the",
"final",
"representation",
"of",
"the",
"input",
"whether",
"it",
"be",
"object",
"or",
"string"
] | 92d7fb401340892a8f04d497d4e1508c9ed1f8bb | https://github.com/patrickkettner/grunt-compile-handlebars/blob/92d7fb401340892a8f04d497d4e1508c9ed1f8bb/tasks/compile-handlebars.js#L37-L54 | |
22,765 | patrickkettner/grunt-compile-handlebars | tasks/compile-handlebars.js | function(filename) {
if (!filename || typeof filename === 'object') {
return;
}
var match = filename.match(/[^\*]*/);
if (match[0] !== filename) {
return match.pop();
}
} | javascript | function(filename) {
if (!filename || typeof filename === 'object') {
return;
}
var match = filename.match(/[^\*]*/);
if (match[0] !== filename) {
return match.pop();
}
} | [
"function",
"(",
"filename",
")",
"{",
"if",
"(",
"!",
"filename",
"||",
"typeof",
"filename",
"===",
"'object'",
")",
"{",
"return",
";",
"}",
"var",
"match",
"=",
"filename",
".",
"match",
"(",
"/",
"[^\\*]*",
"/",
")",
";",
"if",
"(",
"match",
"[",
"0",
"]",
"!==",
"filename",
")",
"{",
"return",
"match",
".",
"pop",
"(",
")",
";",
"}",
"}"
] | Checks if the input is a glob and if so, returns the unglobbed version of the filename | [
"Checks",
"if",
"the",
"input",
"is",
"a",
"glob",
"and",
"if",
"so",
"returns",
"the",
"unglobbed",
"version",
"of",
"the",
"filename"
] | 92d7fb401340892a8f04d497d4e1508c9ed1f8bb | https://github.com/patrickkettner/grunt-compile-handlebars/blob/92d7fb401340892a8f04d497d4e1508c9ed1f8bb/tasks/compile-handlebars.js#L57-L67 | |
22,766 | patrickkettner/grunt-compile-handlebars | tasks/compile-handlebars.js | function(filename, template, outputInInput) {
var basename;
var glob;
template = Array.isArray(template) ? filename : template;
glob = isGlob(template);
if (outputInInput) {
basename = _toArray(filename.split('.').pop()) ;
} else if (glob) {
basename = filename.slice(glob.length, filename.length).split('.');
basename.pop();
} else {
basename = filename.split('/').pop().split('.');
basename.pop();
}
return basename.join('.');
} | javascript | function(filename, template, outputInInput) {
var basename;
var glob;
template = Array.isArray(template) ? filename : template;
glob = isGlob(template);
if (outputInInput) {
basename = _toArray(filename.split('.').pop()) ;
} else if (glob) {
basename = filename.slice(glob.length, filename.length).split('.');
basename.pop();
} else {
basename = filename.split('/').pop().split('.');
basename.pop();
}
return basename.join('.');
} | [
"function",
"(",
"filename",
",",
"template",
",",
"outputInInput",
")",
"{",
"var",
"basename",
";",
"var",
"glob",
";",
"template",
"=",
"Array",
".",
"isArray",
"(",
"template",
")",
"?",
"filename",
":",
"template",
";",
"glob",
"=",
"isGlob",
"(",
"template",
")",
";",
"if",
"(",
"outputInInput",
")",
"{",
"basename",
"=",
"_toArray",
"(",
"filename",
".",
"split",
"(",
"'.'",
")",
".",
"pop",
"(",
")",
")",
";",
"}",
"else",
"if",
"(",
"glob",
")",
"{",
"basename",
"=",
"filename",
".",
"slice",
"(",
"glob",
".",
"length",
",",
"filename",
".",
"length",
")",
".",
"split",
"(",
"'.'",
")",
";",
"basename",
".",
"pop",
"(",
")",
";",
"}",
"else",
"{",
"basename",
"=",
"filename",
".",
"split",
"(",
"'/'",
")",
".",
"pop",
"(",
")",
".",
"split",
"(",
"'.'",
")",
";",
"basename",
".",
"pop",
"(",
")",
";",
"}",
"return",
"basename",
".",
"join",
"(",
"'.'",
")",
";",
"}"
] | Figures out the name of the file before any globs are used, so the globbed outputs can be generated | [
"Figures",
"out",
"the",
"name",
"of",
"the",
"file",
"before",
"any",
"globs",
"are",
"used",
"so",
"the",
"globbed",
"outputs",
"can",
"be",
"generated"
] | 92d7fb401340892a8f04d497d4e1508c9ed1f8bb | https://github.com/patrickkettner/grunt-compile-handlebars/blob/92d7fb401340892a8f04d497d4e1508c9ed1f8bb/tasks/compile-handlebars.js#L70-L86 | |
22,767 | hacdias/electron-menubar | positioner.js | calculateXAlign | function calculateXAlign (windowBounds, trayBounds, align) {
const display = getDisplay()
let x
switch (align) {
case 'right':
x = trayBounds.x
break
case 'left':
x = trayBounds.x + trayBounds.width - windowBounds.width
break
case 'center':
default:
x = Math.round(trayBounds.x + (trayBounds.width / 2) - (windowBounds.width / 2))
}
if (x + windowBounds.width > display.bounds.width && align !== 'left') {
// if window would overlap on right side align it to the end of the screen
x = display.bounds.width - windowBounds.width
} else if (x < 0 && align !== 'right') {
// if window would overlap on the left side align it to the beginning
x = 0
}
return x
} | javascript | function calculateXAlign (windowBounds, trayBounds, align) {
const display = getDisplay()
let x
switch (align) {
case 'right':
x = trayBounds.x
break
case 'left':
x = trayBounds.x + trayBounds.width - windowBounds.width
break
case 'center':
default:
x = Math.round(trayBounds.x + (trayBounds.width / 2) - (windowBounds.width / 2))
}
if (x + windowBounds.width > display.bounds.width && align !== 'left') {
// if window would overlap on right side align it to the end of the screen
x = display.bounds.width - windowBounds.width
} else if (x < 0 && align !== 'right') {
// if window would overlap on the left side align it to the beginning
x = 0
}
return x
} | [
"function",
"calculateXAlign",
"(",
"windowBounds",
",",
"trayBounds",
",",
"align",
")",
"{",
"const",
"display",
"=",
"getDisplay",
"(",
")",
"let",
"x",
"switch",
"(",
"align",
")",
"{",
"case",
"'right'",
":",
"x",
"=",
"trayBounds",
".",
"x",
"break",
"case",
"'left'",
":",
"x",
"=",
"trayBounds",
".",
"x",
"+",
"trayBounds",
".",
"width",
"-",
"windowBounds",
".",
"width",
"break",
"case",
"'center'",
":",
"default",
":",
"x",
"=",
"Math",
".",
"round",
"(",
"trayBounds",
".",
"x",
"+",
"(",
"trayBounds",
".",
"width",
"/",
"2",
")",
"-",
"(",
"windowBounds",
".",
"width",
"/",
"2",
")",
")",
"}",
"if",
"(",
"x",
"+",
"windowBounds",
".",
"width",
">",
"display",
".",
"bounds",
".",
"width",
"&&",
"align",
"!==",
"'left'",
")",
"{",
"// if window would overlap on right side align it to the end of the screen",
"x",
"=",
"display",
".",
"bounds",
".",
"width",
"-",
"windowBounds",
".",
"width",
"}",
"else",
"if",
"(",
"x",
"<",
"0",
"&&",
"align",
"!==",
"'right'",
")",
"{",
"// if window would overlap on the left side align it to the beginning",
"x",
"=",
"0",
"}",
"return",
"x",
"}"
] | Calculates the x position of the tray window
@param {Rectangle} windowBounds - electron BrowserWindow bounds of tray window to position
@param {Rectangle} trayBounds - tray bounds from electron Tray.getBounds()
@param {string} [align] - align left|center|right, default: center
@return {integer} - calculated x position | [
"Calculates",
"the",
"x",
"position",
"of",
"the",
"tray",
"window"
] | 57d850f2f53c4227df4413855907cbd48e28bc16 | https://github.com/hacdias/electron-menubar/blob/57d850f2f53c4227df4413855907cbd48e28bc16/positioner.js#L31-L56 |
22,768 | hacdias/electron-menubar | positioner.js | calculateYAlign | function calculateYAlign (windowBounds, trayBounds, align) {
const display = getDisplay()
let y
switch (align) {
case 'up':
y = trayBounds.y + trayBounds.height - windowBounds.height
break
case 'down':
y = trayBounds.y
break
case 'center':
default:
y = Math.round((trayBounds.y + (trayBounds.height / 2)) - (windowBounds.height / 2))
break
}
if (y + windowBounds.height > display.bounds.height && align !== 'up') {
y = trayBounds.y + trayBounds.height - windowBounds.height
} else if (y < 0 && align !== 'down') {
y = 0
}
return y
} | javascript | function calculateYAlign (windowBounds, trayBounds, align) {
const display = getDisplay()
let y
switch (align) {
case 'up':
y = trayBounds.y + trayBounds.height - windowBounds.height
break
case 'down':
y = trayBounds.y
break
case 'center':
default:
y = Math.round((trayBounds.y + (trayBounds.height / 2)) - (windowBounds.height / 2))
break
}
if (y + windowBounds.height > display.bounds.height && align !== 'up') {
y = trayBounds.y + trayBounds.height - windowBounds.height
} else if (y < 0 && align !== 'down') {
y = 0
}
return y
} | [
"function",
"calculateYAlign",
"(",
"windowBounds",
",",
"trayBounds",
",",
"align",
")",
"{",
"const",
"display",
"=",
"getDisplay",
"(",
")",
"let",
"y",
"switch",
"(",
"align",
")",
"{",
"case",
"'up'",
":",
"y",
"=",
"trayBounds",
".",
"y",
"+",
"trayBounds",
".",
"height",
"-",
"windowBounds",
".",
"height",
"break",
"case",
"'down'",
":",
"y",
"=",
"trayBounds",
".",
"y",
"break",
"case",
"'center'",
":",
"default",
":",
"y",
"=",
"Math",
".",
"round",
"(",
"(",
"trayBounds",
".",
"y",
"+",
"(",
"trayBounds",
".",
"height",
"/",
"2",
")",
")",
"-",
"(",
"windowBounds",
".",
"height",
"/",
"2",
")",
")",
"break",
"}",
"if",
"(",
"y",
"+",
"windowBounds",
".",
"height",
">",
"display",
".",
"bounds",
".",
"height",
"&&",
"align",
"!==",
"'up'",
")",
"{",
"y",
"=",
"trayBounds",
".",
"y",
"+",
"trayBounds",
".",
"height",
"-",
"windowBounds",
".",
"height",
"}",
"else",
"if",
"(",
"y",
"<",
"0",
"&&",
"align",
"!==",
"'down'",
")",
"{",
"y",
"=",
"0",
"}",
"return",
"y",
"}"
] | Calculates the y position of the tray window
@param {Rectangle} windowBounds - electron BrowserWindow bounds
@param {Rectangle} trayBounds - tray bounds from electron Tray.getBounds()
@param {string} [align] - align up|middle|down, default: down
@return {integer} - calculated y position | [
"Calculates",
"the",
"y",
"position",
"of",
"the",
"tray",
"window"
] | 57d850f2f53c4227df4413855907cbd48e28bc16 | https://github.com/hacdias/electron-menubar/blob/57d850f2f53c4227df4413855907cbd48e28bc16/positioner.js#L67-L91 |
22,769 | hacdias/electron-menubar | positioner.js | calculateByCursorPosition | function calculateByCursorPosition (windowBounds, display, cursor) {
let x = cursor.x
let y = cursor.y
if (x + windowBounds.width > display.bounds.width) {
// if window would overlap on right side of screen, align it to the left of the cursor
x -= windowBounds.width
}
if (y + windowBounds.height > display.bounds.height) {
// if window would overlap at bottom of screen, align it up from cursor position
y -= windowBounds.height
}
return {
x: x,
y: y
}
} | javascript | function calculateByCursorPosition (windowBounds, display, cursor) {
let x = cursor.x
let y = cursor.y
if (x + windowBounds.width > display.bounds.width) {
// if window would overlap on right side of screen, align it to the left of the cursor
x -= windowBounds.width
}
if (y + windowBounds.height > display.bounds.height) {
// if window would overlap at bottom of screen, align it up from cursor position
y -= windowBounds.height
}
return {
x: x,
y: y
}
} | [
"function",
"calculateByCursorPosition",
"(",
"windowBounds",
",",
"display",
",",
"cursor",
")",
"{",
"let",
"x",
"=",
"cursor",
".",
"x",
"let",
"y",
"=",
"cursor",
".",
"y",
"if",
"(",
"x",
"+",
"windowBounds",
".",
"width",
">",
"display",
".",
"bounds",
".",
"width",
")",
"{",
"// if window would overlap on right side of screen, align it to the left of the cursor",
"x",
"-=",
"windowBounds",
".",
"width",
"}",
"if",
"(",
"y",
"+",
"windowBounds",
".",
"height",
">",
"display",
".",
"bounds",
".",
"height",
")",
"{",
"// if window would overlap at bottom of screen, align it up from cursor position",
"y",
"-=",
"windowBounds",
".",
"height",
"}",
"return",
"{",
"x",
":",
"x",
",",
"y",
":",
"y",
"}",
"}"
] | Calculates the position of the tray window based on current cursor position
This method is used on linux where trayBounds are not available
@param {Rectangle} windowBounds - electron BrowserWindow bounds of tray window to position
@param {Eelectron.Display} display - display on which the cursor is currently
@param {Point} cursor - current cursor position
@return {Point} - Calculated point {x, y} where the window should be positioned | [
"Calculates",
"the",
"position",
"of",
"the",
"tray",
"window",
"based",
"on",
"current",
"cursor",
"position",
"This",
"method",
"is",
"used",
"on",
"linux",
"where",
"trayBounds",
"are",
"not",
"available"
] | 57d850f2f53c4227df4413855907cbd48e28bc16 | https://github.com/hacdias/electron-menubar/blob/57d850f2f53c4227df4413855907cbd48e28bc16/positioner.js#L103-L121 |
22,770 | robwierzbowski/node-pixrem | lib/pixrem.js | detectBrowser | function detectBrowser (browsers, browserQuery) {
var b = false;
browserQuery = browserslist(browserQuery);
for (var i = 0; i < browsers.length; i++) {
for (var j = 0; j < browserQuery.length; j++) {
if (browsers[i] === browserQuery[j]) {
b = true;
break;
}
}
if (b) { break; }
}
return b;
} | javascript | function detectBrowser (browsers, browserQuery) {
var b = false;
browserQuery = browserslist(browserQuery);
for (var i = 0; i < browsers.length; i++) {
for (var j = 0; j < browserQuery.length; j++) {
if (browsers[i] === browserQuery[j]) {
b = true;
break;
}
}
if (b) { break; }
}
return b;
} | [
"function",
"detectBrowser",
"(",
"browsers",
",",
"browserQuery",
")",
"{",
"var",
"b",
"=",
"false",
";",
"browserQuery",
"=",
"browserslist",
"(",
"browserQuery",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"browsers",
".",
"length",
";",
"i",
"++",
")",
"{",
"for",
"(",
"var",
"j",
"=",
"0",
";",
"j",
"<",
"browserQuery",
".",
"length",
";",
"j",
"++",
")",
"{",
"if",
"(",
"browsers",
"[",
"i",
"]",
"===",
"browserQuery",
"[",
"j",
"]",
")",
"{",
"b",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"b",
")",
"{",
"break",
";",
"}",
"}",
"return",
"b",
";",
"}"
] | Detect if one browser from the browserQuery is in browsers | [
"Detect",
"if",
"one",
"browser",
"from",
"the",
"browserQuery",
"is",
"in",
"browsers"
] | 80581f4416fd2d0962ee24d3203a310b7d520c1d | https://github.com/robwierzbowski/node-pixrem/blob/80581f4416fd2d0962ee24d3203a310b7d520c1d/lib/pixrem.js#L108-L121 |
22,771 | robwierzbowski/node-pixrem | lib/pixrem.js | toPx | function toPx (value, decl, result) {
value = (typeof value === 'string' && value.indexOf('calc(') !== -1) ? calc(value) : value;
var parts = /^(\d*\.?\d+)([a-zA-Z%]*)$/.exec(value);
if (parts !== null) {
var number = parts[1];
var unit = parts[2];
if (unit === 'px' || unit === '') {
return parseFloat(number);
}
else if (unit === 'em' || unit === 'rem') {
return parseFloat(number) * BASE_FONT_SIZE;
}
else if (unit === '%') {
return (parseFloat(number) / 100) * BASE_FONT_SIZE;
} else {
// other units: vw, ex, ch, etc...
result.warn('Unit cannot be used for conversion, so 16px is used.');
return BASE_FONT_SIZE;
}
} else {
throw decl.error('Root font-size is invalid', {plugin: 'pixrem'});
}
} | javascript | function toPx (value, decl, result) {
value = (typeof value === 'string' && value.indexOf('calc(') !== -1) ? calc(value) : value;
var parts = /^(\d*\.?\d+)([a-zA-Z%]*)$/.exec(value);
if (parts !== null) {
var number = parts[1];
var unit = parts[2];
if (unit === 'px' || unit === '') {
return parseFloat(number);
}
else if (unit === 'em' || unit === 'rem') {
return parseFloat(number) * BASE_FONT_SIZE;
}
else if (unit === '%') {
return (parseFloat(number) / 100) * BASE_FONT_SIZE;
} else {
// other units: vw, ex, ch, etc...
result.warn('Unit cannot be used for conversion, so 16px is used.');
return BASE_FONT_SIZE;
}
} else {
throw decl.error('Root font-size is invalid', {plugin: 'pixrem'});
}
} | [
"function",
"toPx",
"(",
"value",
",",
"decl",
",",
"result",
")",
"{",
"value",
"=",
"(",
"typeof",
"value",
"===",
"'string'",
"&&",
"value",
".",
"indexOf",
"(",
"'calc('",
")",
"!==",
"-",
"1",
")",
"?",
"calc",
"(",
"value",
")",
":",
"value",
";",
"var",
"parts",
"=",
"/",
"^(\\d*\\.?\\d+)([a-zA-Z%]*)$",
"/",
".",
"exec",
"(",
"value",
")",
";",
"if",
"(",
"parts",
"!==",
"null",
")",
"{",
"var",
"number",
"=",
"parts",
"[",
"1",
"]",
";",
"var",
"unit",
"=",
"parts",
"[",
"2",
"]",
";",
"if",
"(",
"unit",
"===",
"'px'",
"||",
"unit",
"===",
"''",
")",
"{",
"return",
"parseFloat",
"(",
"number",
")",
";",
"}",
"else",
"if",
"(",
"unit",
"===",
"'em'",
"||",
"unit",
"===",
"'rem'",
")",
"{",
"return",
"parseFloat",
"(",
"number",
")",
"*",
"BASE_FONT_SIZE",
";",
"}",
"else",
"if",
"(",
"unit",
"===",
"'%'",
")",
"{",
"return",
"(",
"parseFloat",
"(",
"number",
")",
"/",
"100",
")",
"*",
"BASE_FONT_SIZE",
";",
"}",
"else",
"{",
"// other units: vw, ex, ch, etc...",
"result",
".",
"warn",
"(",
"'Unit cannot be used for conversion, so 16px is used.'",
")",
";",
"return",
"BASE_FONT_SIZE",
";",
"}",
"}",
"else",
"{",
"throw",
"decl",
".",
"error",
"(",
"'Root font-size is invalid'",
",",
"{",
"plugin",
":",
"'pixrem'",
"}",
")",
";",
"}",
"}"
] | Return a unitless pixel value from any root font-size value. | [
"Return",
"a",
"unitless",
"pixel",
"value",
"from",
"any",
"root",
"font",
"-",
"size",
"value",
"."
] | 80581f4416fd2d0962ee24d3203a310b7d520c1d | https://github.com/robwierzbowski/node-pixrem/blob/80581f4416fd2d0962ee24d3203a310b7d520c1d/lib/pixrem.js#L124-L147 |
22,772 | mikolalysenko/box-intersect | lib/intersect.js | iterInit | function iterInit(d, count) {
var levels = (8 * bits.log2(count+1) * (d+1))|0
var maxInts = bits.nextPow2(IFRAME_SIZE*levels)
if(BOX_ISTACK.length < maxInts) {
pool.free(BOX_ISTACK)
BOX_ISTACK = pool.mallocInt32(maxInts)
}
var maxDoubles = bits.nextPow2(DFRAME_SIZE*levels)
if(BOX_DSTACK.length < maxDoubles) {
pool.free(BOX_DSTACK)
BOX_DSTACK = pool.mallocDouble(maxDoubles)
}
} | javascript | function iterInit(d, count) {
var levels = (8 * bits.log2(count+1) * (d+1))|0
var maxInts = bits.nextPow2(IFRAME_SIZE*levels)
if(BOX_ISTACK.length < maxInts) {
pool.free(BOX_ISTACK)
BOX_ISTACK = pool.mallocInt32(maxInts)
}
var maxDoubles = bits.nextPow2(DFRAME_SIZE*levels)
if(BOX_DSTACK.length < maxDoubles) {
pool.free(BOX_DSTACK)
BOX_DSTACK = pool.mallocDouble(maxDoubles)
}
} | [
"function",
"iterInit",
"(",
"d",
",",
"count",
")",
"{",
"var",
"levels",
"=",
"(",
"8",
"*",
"bits",
".",
"log2",
"(",
"count",
"+",
"1",
")",
"*",
"(",
"d",
"+",
"1",
")",
")",
"|",
"0",
"var",
"maxInts",
"=",
"bits",
".",
"nextPow2",
"(",
"IFRAME_SIZE",
"*",
"levels",
")",
"if",
"(",
"BOX_ISTACK",
".",
"length",
"<",
"maxInts",
")",
"{",
"pool",
".",
"free",
"(",
"BOX_ISTACK",
")",
"BOX_ISTACK",
"=",
"pool",
".",
"mallocInt32",
"(",
"maxInts",
")",
"}",
"var",
"maxDoubles",
"=",
"bits",
".",
"nextPow2",
"(",
"DFRAME_SIZE",
"*",
"levels",
")",
"if",
"(",
"BOX_DSTACK",
".",
"length",
"<",
"maxDoubles",
")",
"{",
"pool",
".",
"free",
"(",
"BOX_DSTACK",
")",
"BOX_DSTACK",
"=",
"pool",
".",
"mallocDouble",
"(",
"maxDoubles",
")",
"}",
"}"
] | Initialize iterative loop queue | [
"Initialize",
"iterative",
"loop",
"queue"
] | 7e6770bab1fb90217a92eec4b8e0f4c293a71801 | https://github.com/mikolalysenko/box-intersect/blob/7e6770bab1fb90217a92eec4b8e0f4c293a71801/lib/intersect.js#L54-L66 |
22,773 | mikolalysenko/box-intersect | lib/intersect.js | iterPush | function iterPush(ptr,
axis,
redStart, redEnd,
blueStart, blueEnd,
state,
lo, hi) {
var iptr = IFRAME_SIZE * ptr
BOX_ISTACK[iptr] = axis
BOX_ISTACK[iptr+1] = redStart
BOX_ISTACK[iptr+2] = redEnd
BOX_ISTACK[iptr+3] = blueStart
BOX_ISTACK[iptr+4] = blueEnd
BOX_ISTACK[iptr+5] = state
var dptr = DFRAME_SIZE * ptr
BOX_DSTACK[dptr] = lo
BOX_DSTACK[dptr+1] = hi
} | javascript | function iterPush(ptr,
axis,
redStart, redEnd,
blueStart, blueEnd,
state,
lo, hi) {
var iptr = IFRAME_SIZE * ptr
BOX_ISTACK[iptr] = axis
BOX_ISTACK[iptr+1] = redStart
BOX_ISTACK[iptr+2] = redEnd
BOX_ISTACK[iptr+3] = blueStart
BOX_ISTACK[iptr+4] = blueEnd
BOX_ISTACK[iptr+5] = state
var dptr = DFRAME_SIZE * ptr
BOX_DSTACK[dptr] = lo
BOX_DSTACK[dptr+1] = hi
} | [
"function",
"iterPush",
"(",
"ptr",
",",
"axis",
",",
"redStart",
",",
"redEnd",
",",
"blueStart",
",",
"blueEnd",
",",
"state",
",",
"lo",
",",
"hi",
")",
"{",
"var",
"iptr",
"=",
"IFRAME_SIZE",
"*",
"ptr",
"BOX_ISTACK",
"[",
"iptr",
"]",
"=",
"axis",
"BOX_ISTACK",
"[",
"iptr",
"+",
"1",
"]",
"=",
"redStart",
"BOX_ISTACK",
"[",
"iptr",
"+",
"2",
"]",
"=",
"redEnd",
"BOX_ISTACK",
"[",
"iptr",
"+",
"3",
"]",
"=",
"blueStart",
"BOX_ISTACK",
"[",
"iptr",
"+",
"4",
"]",
"=",
"blueEnd",
"BOX_ISTACK",
"[",
"iptr",
"+",
"5",
"]",
"=",
"state",
"var",
"dptr",
"=",
"DFRAME_SIZE",
"*",
"ptr",
"BOX_DSTACK",
"[",
"dptr",
"]",
"=",
"lo",
"BOX_DSTACK",
"[",
"dptr",
"+",
"1",
"]",
"=",
"hi",
"}"
] | Append item to queue | [
"Append",
"item",
"to",
"queue"
] | 7e6770bab1fb90217a92eec4b8e0f4c293a71801 | https://github.com/mikolalysenko/box-intersect/blob/7e6770bab1fb90217a92eec4b8e0f4c293a71801/lib/intersect.js#L69-L87 |
22,774 | mikolalysenko/box-intersect | index.js | convertBoxes | function convertBoxes(boxes, d, data, ids) {
var ptr = 0
var count = 0
for(var i=0, n=boxes.length; i<n; ++i) {
var b = boxes[i]
if(boxEmpty(d, b)) {
continue
}
for(var j=0; j<2*d; ++j) {
data[ptr++] = b[j]
}
ids[count++] = i
}
return count
} | javascript | function convertBoxes(boxes, d, data, ids) {
var ptr = 0
var count = 0
for(var i=0, n=boxes.length; i<n; ++i) {
var b = boxes[i]
if(boxEmpty(d, b)) {
continue
}
for(var j=0; j<2*d; ++j) {
data[ptr++] = b[j]
}
ids[count++] = i
}
return count
} | [
"function",
"convertBoxes",
"(",
"boxes",
",",
"d",
",",
"data",
",",
"ids",
")",
"{",
"var",
"ptr",
"=",
"0",
"var",
"count",
"=",
"0",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"n",
"=",
"boxes",
".",
"length",
";",
"i",
"<",
"n",
";",
"++",
"i",
")",
"{",
"var",
"b",
"=",
"boxes",
"[",
"i",
"]",
"if",
"(",
"boxEmpty",
"(",
"d",
",",
"b",
")",
")",
"{",
"continue",
"}",
"for",
"(",
"var",
"j",
"=",
"0",
";",
"j",
"<",
"2",
"*",
"d",
";",
"++",
"j",
")",
"{",
"data",
"[",
"ptr",
"++",
"]",
"=",
"b",
"[",
"j",
"]",
"}",
"ids",
"[",
"count",
"++",
"]",
"=",
"i",
"}",
"return",
"count",
"}"
] | Unpack boxes into a flat typed array, remove empty boxes | [
"Unpack",
"boxes",
"into",
"a",
"flat",
"typed",
"array",
"remove",
"empty",
"boxes"
] | 7e6770bab1fb90217a92eec4b8e0f4c293a71801 | https://github.com/mikolalysenko/box-intersect/blob/7e6770bab1fb90217a92eec4b8e0f4c293a71801/index.js#L19-L33 |
22,775 | mikolalysenko/box-intersect | index.js | boxIntersect | function boxIntersect(red, blue, visit, full) {
var n = red.length
var m = blue.length
//If either array is empty, then we can skip this whole thing
if(n <= 0 || m <= 0) {
return
}
//Compute dimension, if it is 0 then we skip
var d = (red[0].length)>>>1
if(d <= 0) {
return
}
var retval
//Convert red boxes
var redList = pool.mallocDouble(2*d*n)
var redIds = pool.mallocInt32(n)
n = convertBoxes(red, d, redList, redIds)
if(n > 0) {
if(d === 1 && full) {
//Special case: 1d complete
sweep.init(n)
retval = sweep.sweepComplete(
d, visit,
0, n, redList, redIds,
0, n, redList, redIds)
} else {
//Convert blue boxes
var blueList = pool.mallocDouble(2*d*m)
var blueIds = pool.mallocInt32(m)
m = convertBoxes(blue, d, blueList, blueIds)
if(m > 0) {
sweep.init(n+m)
if(d === 1) {
//Special case: 1d bipartite
retval = sweep.sweepBipartite(
d, visit,
0, n, redList, redIds,
0, m, blueList, blueIds)
} else {
//General case: d>1
retval = boxIntersectIter(
d, visit, full,
n, redList, redIds,
m, blueList, blueIds)
}
pool.free(blueList)
pool.free(blueIds)
}
}
pool.free(redList)
pool.free(redIds)
}
return retval
} | javascript | function boxIntersect(red, blue, visit, full) {
var n = red.length
var m = blue.length
//If either array is empty, then we can skip this whole thing
if(n <= 0 || m <= 0) {
return
}
//Compute dimension, if it is 0 then we skip
var d = (red[0].length)>>>1
if(d <= 0) {
return
}
var retval
//Convert red boxes
var redList = pool.mallocDouble(2*d*n)
var redIds = pool.mallocInt32(n)
n = convertBoxes(red, d, redList, redIds)
if(n > 0) {
if(d === 1 && full) {
//Special case: 1d complete
sweep.init(n)
retval = sweep.sweepComplete(
d, visit,
0, n, redList, redIds,
0, n, redList, redIds)
} else {
//Convert blue boxes
var blueList = pool.mallocDouble(2*d*m)
var blueIds = pool.mallocInt32(m)
m = convertBoxes(blue, d, blueList, blueIds)
if(m > 0) {
sweep.init(n+m)
if(d === 1) {
//Special case: 1d bipartite
retval = sweep.sweepBipartite(
d, visit,
0, n, redList, redIds,
0, m, blueList, blueIds)
} else {
//General case: d>1
retval = boxIntersectIter(
d, visit, full,
n, redList, redIds,
m, blueList, blueIds)
}
pool.free(blueList)
pool.free(blueIds)
}
}
pool.free(redList)
pool.free(redIds)
}
return retval
} | [
"function",
"boxIntersect",
"(",
"red",
",",
"blue",
",",
"visit",
",",
"full",
")",
"{",
"var",
"n",
"=",
"red",
".",
"length",
"var",
"m",
"=",
"blue",
".",
"length",
"//If either array is empty, then we can skip this whole thing",
"if",
"(",
"n",
"<=",
"0",
"||",
"m",
"<=",
"0",
")",
"{",
"return",
"}",
"//Compute dimension, if it is 0 then we skip",
"var",
"d",
"=",
"(",
"red",
"[",
"0",
"]",
".",
"length",
")",
">>>",
"1",
"if",
"(",
"d",
"<=",
"0",
")",
"{",
"return",
"}",
"var",
"retval",
"//Convert red boxes",
"var",
"redList",
"=",
"pool",
".",
"mallocDouble",
"(",
"2",
"*",
"d",
"*",
"n",
")",
"var",
"redIds",
"=",
"pool",
".",
"mallocInt32",
"(",
"n",
")",
"n",
"=",
"convertBoxes",
"(",
"red",
",",
"d",
",",
"redList",
",",
"redIds",
")",
"if",
"(",
"n",
">",
"0",
")",
"{",
"if",
"(",
"d",
"===",
"1",
"&&",
"full",
")",
"{",
"//Special case: 1d complete",
"sweep",
".",
"init",
"(",
"n",
")",
"retval",
"=",
"sweep",
".",
"sweepComplete",
"(",
"d",
",",
"visit",
",",
"0",
",",
"n",
",",
"redList",
",",
"redIds",
",",
"0",
",",
"n",
",",
"redList",
",",
"redIds",
")",
"}",
"else",
"{",
"//Convert blue boxes",
"var",
"blueList",
"=",
"pool",
".",
"mallocDouble",
"(",
"2",
"*",
"d",
"*",
"m",
")",
"var",
"blueIds",
"=",
"pool",
".",
"mallocInt32",
"(",
"m",
")",
"m",
"=",
"convertBoxes",
"(",
"blue",
",",
"d",
",",
"blueList",
",",
"blueIds",
")",
"if",
"(",
"m",
">",
"0",
")",
"{",
"sweep",
".",
"init",
"(",
"n",
"+",
"m",
")",
"if",
"(",
"d",
"===",
"1",
")",
"{",
"//Special case: 1d bipartite",
"retval",
"=",
"sweep",
".",
"sweepBipartite",
"(",
"d",
",",
"visit",
",",
"0",
",",
"n",
",",
"redList",
",",
"redIds",
",",
"0",
",",
"m",
",",
"blueList",
",",
"blueIds",
")",
"}",
"else",
"{",
"//General case: d>1",
"retval",
"=",
"boxIntersectIter",
"(",
"d",
",",
"visit",
",",
"full",
",",
"n",
",",
"redList",
",",
"redIds",
",",
"m",
",",
"blueList",
",",
"blueIds",
")",
"}",
"pool",
".",
"free",
"(",
"blueList",
")",
"pool",
".",
"free",
"(",
"blueIds",
")",
"}",
"}",
"pool",
".",
"free",
"(",
"redList",
")",
"pool",
".",
"free",
"(",
"redIds",
")",
"}",
"return",
"retval",
"}"
] | Perform type conversions, check bounds | [
"Perform",
"type",
"conversions",
"check",
"bounds"
] | 7e6770bab1fb90217a92eec4b8e0f4c293a71801 | https://github.com/mikolalysenko/box-intersect/blob/7e6770bab1fb90217a92eec4b8e0f4c293a71801/index.js#L36-L100 |
22,776 | mikolalysenko/box-intersect | index.js | boxIntersectWrapper | function boxIntersectWrapper(arg0, arg1, arg2) {
var result
switch(arguments.length) {
case 1:
return intersectFullArray(arg0)
case 2:
if(typeof arg1 === 'function') {
return boxIntersect(arg0, arg0, arg1, true)
} else {
return intersectBipartiteArray(arg0, arg1)
}
case 3:
return boxIntersect(arg0, arg1, arg2, false)
default:
throw new Error('box-intersect: Invalid arguments')
}
} | javascript | function boxIntersectWrapper(arg0, arg1, arg2) {
var result
switch(arguments.length) {
case 1:
return intersectFullArray(arg0)
case 2:
if(typeof arg1 === 'function') {
return boxIntersect(arg0, arg0, arg1, true)
} else {
return intersectBipartiteArray(arg0, arg1)
}
case 3:
return boxIntersect(arg0, arg1, arg2, false)
default:
throw new Error('box-intersect: Invalid arguments')
}
} | [
"function",
"boxIntersectWrapper",
"(",
"arg0",
",",
"arg1",
",",
"arg2",
")",
"{",
"var",
"result",
"switch",
"(",
"arguments",
".",
"length",
")",
"{",
"case",
"1",
":",
"return",
"intersectFullArray",
"(",
"arg0",
")",
"case",
"2",
":",
"if",
"(",
"typeof",
"arg1",
"===",
"'function'",
")",
"{",
"return",
"boxIntersect",
"(",
"arg0",
",",
"arg0",
",",
"arg1",
",",
"true",
")",
"}",
"else",
"{",
"return",
"intersectBipartiteArray",
"(",
"arg0",
",",
"arg1",
")",
"}",
"case",
"3",
":",
"return",
"boxIntersect",
"(",
"arg0",
",",
"arg1",
",",
"arg2",
",",
"false",
")",
"default",
":",
"throw",
"new",
"Error",
"(",
"'box-intersect: Invalid arguments'",
")",
"}",
"}"
] | User-friendly wrapper, handle full input and no-visitor cases | [
"User",
"-",
"friendly",
"wrapper",
"handle",
"full",
"input",
"and",
"no",
"-",
"visitor",
"cases"
] | 7e6770bab1fb90217a92eec4b8e0f4c293a71801 | https://github.com/mikolalysenko/box-intersect/blob/7e6770bab1fb90217a92eec4b8e0f4c293a71801/index.js#L122-L138 |
22,777 | mikolalysenko/box-intersect | lib/sweep.js | sqInit | function sqInit(count) {
var rcount = bits.nextPow2(count)
if(RED_SWEEP_QUEUE.length < rcount) {
pool.free(RED_SWEEP_QUEUE)
RED_SWEEP_QUEUE = pool.mallocInt32(rcount)
}
if(RED_SWEEP_INDEX.length < rcount) {
pool.free(RED_SWEEP_INDEX)
RED_SWEEP_INDEX = pool.mallocInt32(rcount)
}
if(BLUE_SWEEP_QUEUE.length < rcount) {
pool.free(BLUE_SWEEP_QUEUE)
BLUE_SWEEP_QUEUE = pool.mallocInt32(rcount)
}
if(BLUE_SWEEP_INDEX.length < rcount) {
pool.free(BLUE_SWEEP_INDEX)
BLUE_SWEEP_INDEX = pool.mallocInt32(rcount)
}
if(COMMON_SWEEP_QUEUE.length < rcount) {
pool.free(COMMON_SWEEP_QUEUE)
COMMON_SWEEP_QUEUE = pool.mallocInt32(rcount)
}
if(COMMON_SWEEP_INDEX.length < rcount) {
pool.free(COMMON_SWEEP_INDEX)
COMMON_SWEEP_INDEX = pool.mallocInt32(rcount)
}
var eventLength = 8 * rcount
if(SWEEP_EVENTS.length < eventLength) {
pool.free(SWEEP_EVENTS)
SWEEP_EVENTS = pool.mallocDouble(eventLength)
}
} | javascript | function sqInit(count) {
var rcount = bits.nextPow2(count)
if(RED_SWEEP_QUEUE.length < rcount) {
pool.free(RED_SWEEP_QUEUE)
RED_SWEEP_QUEUE = pool.mallocInt32(rcount)
}
if(RED_SWEEP_INDEX.length < rcount) {
pool.free(RED_SWEEP_INDEX)
RED_SWEEP_INDEX = pool.mallocInt32(rcount)
}
if(BLUE_SWEEP_QUEUE.length < rcount) {
pool.free(BLUE_SWEEP_QUEUE)
BLUE_SWEEP_QUEUE = pool.mallocInt32(rcount)
}
if(BLUE_SWEEP_INDEX.length < rcount) {
pool.free(BLUE_SWEEP_INDEX)
BLUE_SWEEP_INDEX = pool.mallocInt32(rcount)
}
if(COMMON_SWEEP_QUEUE.length < rcount) {
pool.free(COMMON_SWEEP_QUEUE)
COMMON_SWEEP_QUEUE = pool.mallocInt32(rcount)
}
if(COMMON_SWEEP_INDEX.length < rcount) {
pool.free(COMMON_SWEEP_INDEX)
COMMON_SWEEP_INDEX = pool.mallocInt32(rcount)
}
var eventLength = 8 * rcount
if(SWEEP_EVENTS.length < eventLength) {
pool.free(SWEEP_EVENTS)
SWEEP_EVENTS = pool.mallocDouble(eventLength)
}
} | [
"function",
"sqInit",
"(",
"count",
")",
"{",
"var",
"rcount",
"=",
"bits",
".",
"nextPow2",
"(",
"count",
")",
"if",
"(",
"RED_SWEEP_QUEUE",
".",
"length",
"<",
"rcount",
")",
"{",
"pool",
".",
"free",
"(",
"RED_SWEEP_QUEUE",
")",
"RED_SWEEP_QUEUE",
"=",
"pool",
".",
"mallocInt32",
"(",
"rcount",
")",
"}",
"if",
"(",
"RED_SWEEP_INDEX",
".",
"length",
"<",
"rcount",
")",
"{",
"pool",
".",
"free",
"(",
"RED_SWEEP_INDEX",
")",
"RED_SWEEP_INDEX",
"=",
"pool",
".",
"mallocInt32",
"(",
"rcount",
")",
"}",
"if",
"(",
"BLUE_SWEEP_QUEUE",
".",
"length",
"<",
"rcount",
")",
"{",
"pool",
".",
"free",
"(",
"BLUE_SWEEP_QUEUE",
")",
"BLUE_SWEEP_QUEUE",
"=",
"pool",
".",
"mallocInt32",
"(",
"rcount",
")",
"}",
"if",
"(",
"BLUE_SWEEP_INDEX",
".",
"length",
"<",
"rcount",
")",
"{",
"pool",
".",
"free",
"(",
"BLUE_SWEEP_INDEX",
")",
"BLUE_SWEEP_INDEX",
"=",
"pool",
".",
"mallocInt32",
"(",
"rcount",
")",
"}",
"if",
"(",
"COMMON_SWEEP_QUEUE",
".",
"length",
"<",
"rcount",
")",
"{",
"pool",
".",
"free",
"(",
"COMMON_SWEEP_QUEUE",
")",
"COMMON_SWEEP_QUEUE",
"=",
"pool",
".",
"mallocInt32",
"(",
"rcount",
")",
"}",
"if",
"(",
"COMMON_SWEEP_INDEX",
".",
"length",
"<",
"rcount",
")",
"{",
"pool",
".",
"free",
"(",
"COMMON_SWEEP_INDEX",
")",
"COMMON_SWEEP_INDEX",
"=",
"pool",
".",
"mallocInt32",
"(",
"rcount",
")",
"}",
"var",
"eventLength",
"=",
"8",
"*",
"rcount",
"if",
"(",
"SWEEP_EVENTS",
".",
"length",
"<",
"eventLength",
")",
"{",
"pool",
".",
"free",
"(",
"SWEEP_EVENTS",
")",
"SWEEP_EVENTS",
"=",
"pool",
".",
"mallocDouble",
"(",
"eventLength",
")",
"}",
"}"
] | Reserves memory for the 1D sweep data structures | [
"Reserves",
"memory",
"for",
"the",
"1D",
"sweep",
"data",
"structures"
] | 7e6770bab1fb90217a92eec4b8e0f4c293a71801 | https://github.com/mikolalysenko/box-intersect/blob/7e6770bab1fb90217a92eec4b8e0f4c293a71801/lib/sweep.js#L29-L60 |
22,778 | dmarcos/aframe-motion-capture-components | src/components/motion-capture-replayer.js | function (delta) {
var currentPose;
var currentEvent
var playingPoses = this.playingPoses;
var playingEvents = this.playingEvents;
currentPose = playingPoses && playingPoses[this.currentPoseIndex]
currentEvent = playingEvents && playingEvents[this.currentEventIndex];
this.currentPoseTime += delta;
this.currentEventTime += delta;
// Determine next pose.
// Comparing currentPoseTime to currentEvent.timestamp is not a typo.
while ((currentPose && this.currentPoseTime >= currentPose.timestamp) ||
(currentEvent && this.currentPoseTime >= currentEvent.timestamp)) {
// Pose.
if (currentPose && this.currentPoseTime >= currentPose.timestamp) {
if (this.currentPoseIndex === playingPoses.length - 1) {
if (this.data.loop) {
this.currentPoseIndex = 0;
this.currentPoseTime = playingPoses[0].timestamp;
} else {
this.stopReplaying();
}
}
applyPose(this.el, currentPose);
this.currentPoseIndex += 1;
currentPose = playingPoses[this.currentPoseIndex];
}
// Event.
if (currentEvent && this.currentPoseTime >= currentEvent.timestamp) {
if (this.currentEventIndex === playingEvents.length && this.data.loop) {
this.currentEventIndex = 0;
this.currentEventTime = playingEvents[0].timestamp;
}
this.el.emit(currentEvent.name, currentEvent.detail);
this.currentEventIndex += 1;
currentEvent = this.playingEvents[this.currentEventIndex];
}
}
} | javascript | function (delta) {
var currentPose;
var currentEvent
var playingPoses = this.playingPoses;
var playingEvents = this.playingEvents;
currentPose = playingPoses && playingPoses[this.currentPoseIndex]
currentEvent = playingEvents && playingEvents[this.currentEventIndex];
this.currentPoseTime += delta;
this.currentEventTime += delta;
// Determine next pose.
// Comparing currentPoseTime to currentEvent.timestamp is not a typo.
while ((currentPose && this.currentPoseTime >= currentPose.timestamp) ||
(currentEvent && this.currentPoseTime >= currentEvent.timestamp)) {
// Pose.
if (currentPose && this.currentPoseTime >= currentPose.timestamp) {
if (this.currentPoseIndex === playingPoses.length - 1) {
if (this.data.loop) {
this.currentPoseIndex = 0;
this.currentPoseTime = playingPoses[0].timestamp;
} else {
this.stopReplaying();
}
}
applyPose(this.el, currentPose);
this.currentPoseIndex += 1;
currentPose = playingPoses[this.currentPoseIndex];
}
// Event.
if (currentEvent && this.currentPoseTime >= currentEvent.timestamp) {
if (this.currentEventIndex === playingEvents.length && this.data.loop) {
this.currentEventIndex = 0;
this.currentEventTime = playingEvents[0].timestamp;
}
this.el.emit(currentEvent.name, currentEvent.detail);
this.currentEventIndex += 1;
currentEvent = this.playingEvents[this.currentEventIndex];
}
}
} | [
"function",
"(",
"delta",
")",
"{",
"var",
"currentPose",
";",
"var",
"currentEvent",
"var",
"playingPoses",
"=",
"this",
".",
"playingPoses",
";",
"var",
"playingEvents",
"=",
"this",
".",
"playingEvents",
";",
"currentPose",
"=",
"playingPoses",
"&&",
"playingPoses",
"[",
"this",
".",
"currentPoseIndex",
"]",
"currentEvent",
"=",
"playingEvents",
"&&",
"playingEvents",
"[",
"this",
".",
"currentEventIndex",
"]",
";",
"this",
".",
"currentPoseTime",
"+=",
"delta",
";",
"this",
".",
"currentEventTime",
"+=",
"delta",
";",
"// Determine next pose.",
"// Comparing currentPoseTime to currentEvent.timestamp is not a typo.",
"while",
"(",
"(",
"currentPose",
"&&",
"this",
".",
"currentPoseTime",
">=",
"currentPose",
".",
"timestamp",
")",
"||",
"(",
"currentEvent",
"&&",
"this",
".",
"currentPoseTime",
">=",
"currentEvent",
".",
"timestamp",
")",
")",
"{",
"// Pose.",
"if",
"(",
"currentPose",
"&&",
"this",
".",
"currentPoseTime",
">=",
"currentPose",
".",
"timestamp",
")",
"{",
"if",
"(",
"this",
".",
"currentPoseIndex",
"===",
"playingPoses",
".",
"length",
"-",
"1",
")",
"{",
"if",
"(",
"this",
".",
"data",
".",
"loop",
")",
"{",
"this",
".",
"currentPoseIndex",
"=",
"0",
";",
"this",
".",
"currentPoseTime",
"=",
"playingPoses",
"[",
"0",
"]",
".",
"timestamp",
";",
"}",
"else",
"{",
"this",
".",
"stopReplaying",
"(",
")",
";",
"}",
"}",
"applyPose",
"(",
"this",
".",
"el",
",",
"currentPose",
")",
";",
"this",
".",
"currentPoseIndex",
"+=",
"1",
";",
"currentPose",
"=",
"playingPoses",
"[",
"this",
".",
"currentPoseIndex",
"]",
";",
"}",
"// Event.",
"if",
"(",
"currentEvent",
"&&",
"this",
".",
"currentPoseTime",
">=",
"currentEvent",
".",
"timestamp",
")",
"{",
"if",
"(",
"this",
".",
"currentEventIndex",
"===",
"playingEvents",
".",
"length",
"&&",
"this",
".",
"data",
".",
"loop",
")",
"{",
"this",
".",
"currentEventIndex",
"=",
"0",
";",
"this",
".",
"currentEventTime",
"=",
"playingEvents",
"[",
"0",
"]",
".",
"timestamp",
";",
"}",
"this",
".",
"el",
".",
"emit",
"(",
"currentEvent",
".",
"name",
",",
"currentEvent",
".",
"detail",
")",
";",
"this",
".",
"currentEventIndex",
"+=",
"1",
";",
"currentEvent",
"=",
"this",
".",
"playingEvents",
"[",
"this",
".",
"currentEventIndex",
"]",
";",
"}",
"}",
"}"
] | Called on tick. | [
"Called",
"on",
"tick",
"."
] | 3a3cbd73ffc751285be95e9729a09121ff03c440 | https://github.com/dmarcos/aframe-motion-capture-components/blob/3a3cbd73ffc751285be95e9729a09121ff03c440/src/components/motion-capture-replayer.js#L164-L202 | |
22,779 | dmarcos/aframe-motion-capture-components | src/components/avatar-replayer.js | function () {
var data = this.data;
var sceneEl = this.el;
if (data.cameraOverride) {
// Specify which camera is the original camera (e.g., used by Inspector).
this.cameraEl = data.cameraOverride;
} else {
// Default camera.
this.cameraEl = sceneEl.camera.el;
// Make sure A-Frame doesn't automatically remove this camera.
this.cameraEl.removeAttribute('data-aframe-default-camera');
}
this.cameraEl.setAttribute('data-aframe-avatar-replayer-camera', '');
sceneEl.removeEventListener('camera-set-active', this.setupCamera);
this.configureHeadGeometry();
// Create spectator camera for either if we are in spectator mode or toggling to it.
this.initSpectatorCamera();
} | javascript | function () {
var data = this.data;
var sceneEl = this.el;
if (data.cameraOverride) {
// Specify which camera is the original camera (e.g., used by Inspector).
this.cameraEl = data.cameraOverride;
} else {
// Default camera.
this.cameraEl = sceneEl.camera.el;
// Make sure A-Frame doesn't automatically remove this camera.
this.cameraEl.removeAttribute('data-aframe-default-camera');
}
this.cameraEl.setAttribute('data-aframe-avatar-replayer-camera', '');
sceneEl.removeEventListener('camera-set-active', this.setupCamera);
this.configureHeadGeometry();
// Create spectator camera for either if we are in spectator mode or toggling to it.
this.initSpectatorCamera();
} | [
"function",
"(",
")",
"{",
"var",
"data",
"=",
"this",
".",
"data",
";",
"var",
"sceneEl",
"=",
"this",
".",
"el",
";",
"if",
"(",
"data",
".",
"cameraOverride",
")",
"{",
"// Specify which camera is the original camera (e.g., used by Inspector).",
"this",
".",
"cameraEl",
"=",
"data",
".",
"cameraOverride",
";",
"}",
"else",
"{",
"// Default camera.",
"this",
".",
"cameraEl",
"=",
"sceneEl",
".",
"camera",
".",
"el",
";",
"// Make sure A-Frame doesn't automatically remove this camera.",
"this",
".",
"cameraEl",
".",
"removeAttribute",
"(",
"'data-aframe-default-camera'",
")",
";",
"}",
"this",
".",
"cameraEl",
".",
"setAttribute",
"(",
"'data-aframe-avatar-replayer-camera'",
",",
"''",
")",
";",
"sceneEl",
".",
"removeEventListener",
"(",
"'camera-set-active'",
",",
"this",
".",
"setupCamera",
")",
";",
"this",
".",
"configureHeadGeometry",
"(",
")",
";",
"// Create spectator camera for either if we are in spectator mode or toggling to it.",
"this",
".",
"initSpectatorCamera",
"(",
")",
";",
"}"
] | Grab a handle to the "original" camera.
Initialize spectator camera and dummy geometry for original camera. | [
"Grab",
"a",
"handle",
"to",
"the",
"original",
"camera",
".",
"Initialize",
"spectator",
"camera",
"and",
"dummy",
"geometry",
"for",
"original",
"camera",
"."
] | 3a3cbd73ffc751285be95e9729a09121ff03c440 | https://github.com/dmarcos/aframe-motion-capture-components/blob/3a3cbd73ffc751285be95e9729a09121ff03c440/src/components/avatar-replayer.js#L83-L104 | |
22,780 | dmarcos/aframe-motion-capture-components | src/components/avatar-replayer.js | function () {
var spectatorCameraEl = this.spectatorCameraEl;
if (!spectatorCameraEl) {
this.el.addEventListener('spectatorcameracreated',
bind(this.activateSpectatorCamera, this));
return;
}
if (!spectatorCameraEl.hasLoaded) {
spectatorCameraEl.addEventListener('loaded', bind(this.activateSpectatorCamera, this));
return;
}
log('Activating spectator camera');
spectatorCameraEl.setAttribute('camera', 'active', true);
this.cameraEl.getObject3D('replayerMesh').visible = true;
} | javascript | function () {
var spectatorCameraEl = this.spectatorCameraEl;
if (!spectatorCameraEl) {
this.el.addEventListener('spectatorcameracreated',
bind(this.activateSpectatorCamera, this));
return;
}
if (!spectatorCameraEl.hasLoaded) {
spectatorCameraEl.addEventListener('loaded', bind(this.activateSpectatorCamera, this));
return;
}
log('Activating spectator camera');
spectatorCameraEl.setAttribute('camera', 'active', true);
this.cameraEl.getObject3D('replayerMesh').visible = true;
} | [
"function",
"(",
")",
"{",
"var",
"spectatorCameraEl",
"=",
"this",
".",
"spectatorCameraEl",
";",
"if",
"(",
"!",
"spectatorCameraEl",
")",
"{",
"this",
".",
"el",
".",
"addEventListener",
"(",
"'spectatorcameracreated'",
",",
"bind",
"(",
"this",
".",
"activateSpectatorCamera",
",",
"this",
")",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"spectatorCameraEl",
".",
"hasLoaded",
")",
"{",
"spectatorCameraEl",
".",
"addEventListener",
"(",
"'loaded'",
",",
"bind",
"(",
"this",
".",
"activateSpectatorCamera",
",",
"this",
")",
")",
";",
"return",
";",
"}",
"log",
"(",
"'Activating spectator camera'",
")",
";",
"spectatorCameraEl",
".",
"setAttribute",
"(",
"'camera'",
",",
"'active'",
",",
"true",
")",
";",
"this",
".",
"cameraEl",
".",
"getObject3D",
"(",
"'replayerMesh'",
")",
".",
"visible",
"=",
"true",
";",
"}"
] | Activate spectator camera, show replayer mesh. | [
"Activate",
"spectator",
"camera",
"show",
"replayer",
"mesh",
"."
] | 3a3cbd73ffc751285be95e9729a09121ff03c440 | https://github.com/dmarcos/aframe-motion-capture-components/blob/3a3cbd73ffc751285be95e9729a09121ff03c440/src/components/avatar-replayer.js#L122-L139 | |
22,781 | dmarcos/aframe-motion-capture-components | src/components/avatar-replayer.js | function () {
var data = this.data;
var sceneEl = this.el;
var spectatorCameraEl;
var spectatorCameraRigEl;
// Developer-defined spectator rig.
if (this.el.querySelector('#spectatorCameraRig')) {
this.spectatorCameraEl = sceneEl.querySelector('#spectatorCameraRig');
return;
}
// Create spectator camera rig.
spectatorCameraRigEl = sceneEl.querySelector('#spectatorCameraRig') ||
document.createElement('a-entity');
spectatorCameraRigEl.id = 'spectatorCameraRig';
spectatorCameraRigEl.setAttribute('position', data.spectatorPosition);
this.spectatorCameraRigEl = spectatorCameraRigEl;
// Create spectator camera.
spectatorCameraEl = sceneEl.querySelector('#spectatorCamera') ||
document.createElement('a-entity');
spectatorCameraEl.id = 'spectatorCamera';
spectatorCameraEl.setAttribute('camera', {active: data.spectatorMode, userHeight: 0});
spectatorCameraEl.setAttribute('look-controls', '');
spectatorCameraEl.setAttribute('wasd-controls', {fly: true});
this.spectatorCameraEl = spectatorCameraEl;
// Append rig.
spectatorCameraRigEl.appendChild(spectatorCameraEl);
sceneEl.appendChild(spectatorCameraRigEl);
sceneEl.emit('spectatorcameracreated');
} | javascript | function () {
var data = this.data;
var sceneEl = this.el;
var spectatorCameraEl;
var spectatorCameraRigEl;
// Developer-defined spectator rig.
if (this.el.querySelector('#spectatorCameraRig')) {
this.spectatorCameraEl = sceneEl.querySelector('#spectatorCameraRig');
return;
}
// Create spectator camera rig.
spectatorCameraRigEl = sceneEl.querySelector('#spectatorCameraRig') ||
document.createElement('a-entity');
spectatorCameraRigEl.id = 'spectatorCameraRig';
spectatorCameraRigEl.setAttribute('position', data.spectatorPosition);
this.spectatorCameraRigEl = spectatorCameraRigEl;
// Create spectator camera.
spectatorCameraEl = sceneEl.querySelector('#spectatorCamera') ||
document.createElement('a-entity');
spectatorCameraEl.id = 'spectatorCamera';
spectatorCameraEl.setAttribute('camera', {active: data.spectatorMode, userHeight: 0});
spectatorCameraEl.setAttribute('look-controls', '');
spectatorCameraEl.setAttribute('wasd-controls', {fly: true});
this.spectatorCameraEl = spectatorCameraEl;
// Append rig.
spectatorCameraRigEl.appendChild(spectatorCameraEl);
sceneEl.appendChild(spectatorCameraRigEl);
sceneEl.emit('spectatorcameracreated');
} | [
"function",
"(",
")",
"{",
"var",
"data",
"=",
"this",
".",
"data",
";",
"var",
"sceneEl",
"=",
"this",
".",
"el",
";",
"var",
"spectatorCameraEl",
";",
"var",
"spectatorCameraRigEl",
";",
"// Developer-defined spectator rig.",
"if",
"(",
"this",
".",
"el",
".",
"querySelector",
"(",
"'#spectatorCameraRig'",
")",
")",
"{",
"this",
".",
"spectatorCameraEl",
"=",
"sceneEl",
".",
"querySelector",
"(",
"'#spectatorCameraRig'",
")",
";",
"return",
";",
"}",
"// Create spectator camera rig.",
"spectatorCameraRigEl",
"=",
"sceneEl",
".",
"querySelector",
"(",
"'#spectatorCameraRig'",
")",
"||",
"document",
".",
"createElement",
"(",
"'a-entity'",
")",
";",
"spectatorCameraRigEl",
".",
"id",
"=",
"'spectatorCameraRig'",
";",
"spectatorCameraRigEl",
".",
"setAttribute",
"(",
"'position'",
",",
"data",
".",
"spectatorPosition",
")",
";",
"this",
".",
"spectatorCameraRigEl",
"=",
"spectatorCameraRigEl",
";",
"// Create spectator camera.",
"spectatorCameraEl",
"=",
"sceneEl",
".",
"querySelector",
"(",
"'#spectatorCamera'",
")",
"||",
"document",
".",
"createElement",
"(",
"'a-entity'",
")",
";",
"spectatorCameraEl",
".",
"id",
"=",
"'spectatorCamera'",
";",
"spectatorCameraEl",
".",
"setAttribute",
"(",
"'camera'",
",",
"{",
"active",
":",
"data",
".",
"spectatorMode",
",",
"userHeight",
":",
"0",
"}",
")",
";",
"spectatorCameraEl",
".",
"setAttribute",
"(",
"'look-controls'",
",",
"''",
")",
";",
"spectatorCameraEl",
".",
"setAttribute",
"(",
"'wasd-controls'",
",",
"{",
"fly",
":",
"true",
"}",
")",
";",
"this",
".",
"spectatorCameraEl",
"=",
"spectatorCameraEl",
";",
"// Append rig.",
"spectatorCameraRigEl",
".",
"appendChild",
"(",
"spectatorCameraEl",
")",
";",
"sceneEl",
".",
"appendChild",
"(",
"spectatorCameraRigEl",
")",
";",
"sceneEl",
".",
"emit",
"(",
"'spectatorcameracreated'",
")",
";",
"}"
] | Create and activate spectator camera if in spectator mode. | [
"Create",
"and",
"activate",
"spectator",
"camera",
"if",
"in",
"spectator",
"mode",
"."
] | 3a3cbd73ffc751285be95e9729a09121ff03c440 | https://github.com/dmarcos/aframe-motion-capture-components/blob/3a3cbd73ffc751285be95e9729a09121ff03c440/src/components/avatar-replayer.js#L153-L185 | |
22,782 | dmarcos/aframe-motion-capture-components | src/components/avatar-replayer.js | function () {
var data = this.data;
var recordingdb = this.el.systems.recordingdb;;
var recordingNames;
var src;
var self = this;
// Allow override to display replayer from query param.
if (new URLSearchParams(window.location.search).get('avatar-replayer-disabled') !== null) {
return;
}
recordingdb.getRecordingNames().then(function (recordingNames) {
// See if recording defined in query parameter.
var queryParamSrc = self.getSrcFromSearchParam();
// 1. Try `avatar-recorder` query parameter as recording name from IndexedDB.
if (recordingNames.indexOf(queryParamSrc) !== -1) {
log('Replaying `' + queryParamSrc + '` from IndexedDB.');
recordingdb.getRecording(queryParamSrc).then(bind(self.startReplaying, self));
return;
}
// 2. Use `avatar-recorder` query parameter or `data.src` as URL.
src = queryParamSrc || self.data.src;
if (src) {
if (self.data.src) {
log('Replaying from component `src`', src);
} else if (queryParamSrc) {
log('Replaying from query parameter `recording`', src);
}
self.loadRecordingFromUrl(src, false, bind(self.startReplaying, self));
return;
}
// 3. Use `data.recordingName` as recording name from IndexedDB.
if (recordingNames.indexOf(self.data.recordingName) !== -1) {
log('Replaying `' + self.data.recordingName + '` from IndexedDB.');
recordingdb.getRecording(self.data.recordingName).then(bind(self.startReplaying, self));
}
});
} | javascript | function () {
var data = this.data;
var recordingdb = this.el.systems.recordingdb;;
var recordingNames;
var src;
var self = this;
// Allow override to display replayer from query param.
if (new URLSearchParams(window.location.search).get('avatar-replayer-disabled') !== null) {
return;
}
recordingdb.getRecordingNames().then(function (recordingNames) {
// See if recording defined in query parameter.
var queryParamSrc = self.getSrcFromSearchParam();
// 1. Try `avatar-recorder` query parameter as recording name from IndexedDB.
if (recordingNames.indexOf(queryParamSrc) !== -1) {
log('Replaying `' + queryParamSrc + '` from IndexedDB.');
recordingdb.getRecording(queryParamSrc).then(bind(self.startReplaying, self));
return;
}
// 2. Use `avatar-recorder` query parameter or `data.src` as URL.
src = queryParamSrc || self.data.src;
if (src) {
if (self.data.src) {
log('Replaying from component `src`', src);
} else if (queryParamSrc) {
log('Replaying from query parameter `recording`', src);
}
self.loadRecordingFromUrl(src, false, bind(self.startReplaying, self));
return;
}
// 3. Use `data.recordingName` as recording name from IndexedDB.
if (recordingNames.indexOf(self.data.recordingName) !== -1) {
log('Replaying `' + self.data.recordingName + '` from IndexedDB.');
recordingdb.getRecording(self.data.recordingName).then(bind(self.startReplaying, self));
}
});
} | [
"function",
"(",
")",
"{",
"var",
"data",
"=",
"this",
".",
"data",
";",
"var",
"recordingdb",
"=",
"this",
".",
"el",
".",
"systems",
".",
"recordingdb",
";",
";",
"var",
"recordingNames",
";",
"var",
"src",
";",
"var",
"self",
"=",
"this",
";",
"// Allow override to display replayer from query param.",
"if",
"(",
"new",
"URLSearchParams",
"(",
"window",
".",
"location",
".",
"search",
")",
".",
"get",
"(",
"'avatar-replayer-disabled'",
")",
"!==",
"null",
")",
"{",
"return",
";",
"}",
"recordingdb",
".",
"getRecordingNames",
"(",
")",
".",
"then",
"(",
"function",
"(",
"recordingNames",
")",
"{",
"// See if recording defined in query parameter.",
"var",
"queryParamSrc",
"=",
"self",
".",
"getSrcFromSearchParam",
"(",
")",
";",
"// 1. Try `avatar-recorder` query parameter as recording name from IndexedDB.",
"if",
"(",
"recordingNames",
".",
"indexOf",
"(",
"queryParamSrc",
")",
"!==",
"-",
"1",
")",
"{",
"log",
"(",
"'Replaying `'",
"+",
"queryParamSrc",
"+",
"'` from IndexedDB.'",
")",
";",
"recordingdb",
".",
"getRecording",
"(",
"queryParamSrc",
")",
".",
"then",
"(",
"bind",
"(",
"self",
".",
"startReplaying",
",",
"self",
")",
")",
";",
"return",
";",
"}",
"// 2. Use `avatar-recorder` query parameter or `data.src` as URL.",
"src",
"=",
"queryParamSrc",
"||",
"self",
".",
"data",
".",
"src",
";",
"if",
"(",
"src",
")",
"{",
"if",
"(",
"self",
".",
"data",
".",
"src",
")",
"{",
"log",
"(",
"'Replaying from component `src`'",
",",
"src",
")",
";",
"}",
"else",
"if",
"(",
"queryParamSrc",
")",
"{",
"log",
"(",
"'Replaying from query parameter `recording`'",
",",
"src",
")",
";",
"}",
"self",
".",
"loadRecordingFromUrl",
"(",
"src",
",",
"false",
",",
"bind",
"(",
"self",
".",
"startReplaying",
",",
"self",
")",
")",
";",
"return",
";",
"}",
"// 3. Use `data.recordingName` as recording name from IndexedDB.",
"if",
"(",
"recordingNames",
".",
"indexOf",
"(",
"self",
".",
"data",
".",
"recordingName",
")",
"!==",
"-",
"1",
")",
"{",
"log",
"(",
"'Replaying `'",
"+",
"self",
".",
"data",
".",
"recordingName",
"+",
"'` from IndexedDB.'",
")",
";",
"recordingdb",
".",
"getRecording",
"(",
"self",
".",
"data",
".",
"recordingName",
")",
".",
"then",
"(",
"bind",
"(",
"self",
".",
"startReplaying",
",",
"self",
")",
")",
";",
"}",
"}",
")",
";",
"}"
] | Check for recording sources and play. | [
"Check",
"for",
"recording",
"sources",
"and",
"play",
"."
] | 3a3cbd73ffc751285be95e9729a09121ff03c440 | https://github.com/dmarcos/aframe-motion-capture-components/blob/3a3cbd73ffc751285be95e9729a09121ff03c440/src/components/avatar-replayer.js#L190-L231 | |
22,783 | dmarcos/aframe-motion-capture-components | src/components/avatar-replayer.js | function () {
var cameraEl = this.cameraEl;
var headMesh;
var leftEyeMesh;
var rightEyeMesh;
var leftEyeBallMesh;
var rightEyeBallMesh;
if (cameraEl.getObject3D('mesh') || cameraEl.getObject3D('replayerMesh')) { return; }
// Head.
headMesh = new THREE.Mesh();
headMesh.geometry = new THREE.BoxBufferGeometry(0.3, 0.3, 0.2);
headMesh.material = new THREE.MeshStandardMaterial({color: 'pink'});
headMesh.visible = this.data.spectatorMode;
// Left eye.
leftEyeMesh = new THREE.Mesh();
leftEyeMesh.geometry = new THREE.SphereBufferGeometry(0.05);
leftEyeMesh.material = new THREE.MeshBasicMaterial({color: 'white'});
leftEyeMesh.position.x -= 0.1;
leftEyeMesh.position.y += 0.1;
leftEyeMesh.position.z -= 0.1;
leftEyeBallMesh = new THREE.Mesh();
leftEyeBallMesh.geometry = new THREE.SphereBufferGeometry(0.025);
leftEyeBallMesh.material = new THREE.MeshBasicMaterial({color: 'black'});
leftEyeBallMesh.position.z -= 0.04;
leftEyeMesh.add(leftEyeBallMesh);
headMesh.add(leftEyeMesh);
// Right eye.
rightEyeMesh = new THREE.Mesh();
rightEyeMesh.geometry = new THREE.SphereBufferGeometry(0.05);
rightEyeMesh.material = new THREE.MeshBasicMaterial({color: 'white'});
rightEyeMesh.position.x += 0.1;
rightEyeMesh.position.y += 0.1;
rightEyeMesh.position.z -= 0.1;
rightEyeBallMesh = new THREE.Mesh();
rightEyeBallMesh.geometry = new THREE.SphereBufferGeometry(0.025);
rightEyeBallMesh.material = new THREE.MeshBasicMaterial({color: 'black'});
rightEyeBallMesh.position.z -= 0.04;
rightEyeMesh.add(rightEyeBallMesh);
headMesh.add(rightEyeMesh);
cameraEl.setObject3D('replayerMesh', headMesh);
} | javascript | function () {
var cameraEl = this.cameraEl;
var headMesh;
var leftEyeMesh;
var rightEyeMesh;
var leftEyeBallMesh;
var rightEyeBallMesh;
if (cameraEl.getObject3D('mesh') || cameraEl.getObject3D('replayerMesh')) { return; }
// Head.
headMesh = new THREE.Mesh();
headMesh.geometry = new THREE.BoxBufferGeometry(0.3, 0.3, 0.2);
headMesh.material = new THREE.MeshStandardMaterial({color: 'pink'});
headMesh.visible = this.data.spectatorMode;
// Left eye.
leftEyeMesh = new THREE.Mesh();
leftEyeMesh.geometry = new THREE.SphereBufferGeometry(0.05);
leftEyeMesh.material = new THREE.MeshBasicMaterial({color: 'white'});
leftEyeMesh.position.x -= 0.1;
leftEyeMesh.position.y += 0.1;
leftEyeMesh.position.z -= 0.1;
leftEyeBallMesh = new THREE.Mesh();
leftEyeBallMesh.geometry = new THREE.SphereBufferGeometry(0.025);
leftEyeBallMesh.material = new THREE.MeshBasicMaterial({color: 'black'});
leftEyeBallMesh.position.z -= 0.04;
leftEyeMesh.add(leftEyeBallMesh);
headMesh.add(leftEyeMesh);
// Right eye.
rightEyeMesh = new THREE.Mesh();
rightEyeMesh.geometry = new THREE.SphereBufferGeometry(0.05);
rightEyeMesh.material = new THREE.MeshBasicMaterial({color: 'white'});
rightEyeMesh.position.x += 0.1;
rightEyeMesh.position.y += 0.1;
rightEyeMesh.position.z -= 0.1;
rightEyeBallMesh = new THREE.Mesh();
rightEyeBallMesh.geometry = new THREE.SphereBufferGeometry(0.025);
rightEyeBallMesh.material = new THREE.MeshBasicMaterial({color: 'black'});
rightEyeBallMesh.position.z -= 0.04;
rightEyeMesh.add(rightEyeBallMesh);
headMesh.add(rightEyeMesh);
cameraEl.setObject3D('replayerMesh', headMesh);
} | [
"function",
"(",
")",
"{",
"var",
"cameraEl",
"=",
"this",
".",
"cameraEl",
";",
"var",
"headMesh",
";",
"var",
"leftEyeMesh",
";",
"var",
"rightEyeMesh",
";",
"var",
"leftEyeBallMesh",
";",
"var",
"rightEyeBallMesh",
";",
"if",
"(",
"cameraEl",
".",
"getObject3D",
"(",
"'mesh'",
")",
"||",
"cameraEl",
".",
"getObject3D",
"(",
"'replayerMesh'",
")",
")",
"{",
"return",
";",
"}",
"// Head.",
"headMesh",
"=",
"new",
"THREE",
".",
"Mesh",
"(",
")",
";",
"headMesh",
".",
"geometry",
"=",
"new",
"THREE",
".",
"BoxBufferGeometry",
"(",
"0.3",
",",
"0.3",
",",
"0.2",
")",
";",
"headMesh",
".",
"material",
"=",
"new",
"THREE",
".",
"MeshStandardMaterial",
"(",
"{",
"color",
":",
"'pink'",
"}",
")",
";",
"headMesh",
".",
"visible",
"=",
"this",
".",
"data",
".",
"spectatorMode",
";",
"// Left eye.",
"leftEyeMesh",
"=",
"new",
"THREE",
".",
"Mesh",
"(",
")",
";",
"leftEyeMesh",
".",
"geometry",
"=",
"new",
"THREE",
".",
"SphereBufferGeometry",
"(",
"0.05",
")",
";",
"leftEyeMesh",
".",
"material",
"=",
"new",
"THREE",
".",
"MeshBasicMaterial",
"(",
"{",
"color",
":",
"'white'",
"}",
")",
";",
"leftEyeMesh",
".",
"position",
".",
"x",
"-=",
"0.1",
";",
"leftEyeMesh",
".",
"position",
".",
"y",
"+=",
"0.1",
";",
"leftEyeMesh",
".",
"position",
".",
"z",
"-=",
"0.1",
";",
"leftEyeBallMesh",
"=",
"new",
"THREE",
".",
"Mesh",
"(",
")",
";",
"leftEyeBallMesh",
".",
"geometry",
"=",
"new",
"THREE",
".",
"SphereBufferGeometry",
"(",
"0.025",
")",
";",
"leftEyeBallMesh",
".",
"material",
"=",
"new",
"THREE",
".",
"MeshBasicMaterial",
"(",
"{",
"color",
":",
"'black'",
"}",
")",
";",
"leftEyeBallMesh",
".",
"position",
".",
"z",
"-=",
"0.04",
";",
"leftEyeMesh",
".",
"add",
"(",
"leftEyeBallMesh",
")",
";",
"headMesh",
".",
"add",
"(",
"leftEyeMesh",
")",
";",
"// Right eye.",
"rightEyeMesh",
"=",
"new",
"THREE",
".",
"Mesh",
"(",
")",
";",
"rightEyeMesh",
".",
"geometry",
"=",
"new",
"THREE",
".",
"SphereBufferGeometry",
"(",
"0.05",
")",
";",
"rightEyeMesh",
".",
"material",
"=",
"new",
"THREE",
".",
"MeshBasicMaterial",
"(",
"{",
"color",
":",
"'white'",
"}",
")",
";",
"rightEyeMesh",
".",
"position",
".",
"x",
"+=",
"0.1",
";",
"rightEyeMesh",
".",
"position",
".",
"y",
"+=",
"0.1",
";",
"rightEyeMesh",
".",
"position",
".",
"z",
"-=",
"0.1",
";",
"rightEyeBallMesh",
"=",
"new",
"THREE",
".",
"Mesh",
"(",
")",
";",
"rightEyeBallMesh",
".",
"geometry",
"=",
"new",
"THREE",
".",
"SphereBufferGeometry",
"(",
"0.025",
")",
";",
"rightEyeBallMesh",
".",
"material",
"=",
"new",
"THREE",
".",
"MeshBasicMaterial",
"(",
"{",
"color",
":",
"'black'",
"}",
")",
";",
"rightEyeBallMesh",
".",
"position",
".",
"z",
"-=",
"0.04",
";",
"rightEyeMesh",
".",
"add",
"(",
"rightEyeBallMesh",
")",
";",
"headMesh",
".",
"add",
"(",
"rightEyeMesh",
")",
";",
"cameraEl",
".",
"setObject3D",
"(",
"'replayerMesh'",
",",
"headMesh",
")",
";",
"}"
] | Create head geometry for spectator mode.
Always created in case we want to toggle, but only visible during spectator mode. | [
"Create",
"head",
"geometry",
"for",
"spectator",
"mode",
".",
"Always",
"created",
"in",
"case",
"we",
"want",
"to",
"toggle",
"but",
"only",
"visible",
"during",
"spectator",
"mode",
"."
] | 3a3cbd73ffc751285be95e9729a09121ff03c440 | https://github.com/dmarcos/aframe-motion-capture-components/blob/3a3cbd73ffc751285be95e9729a09121ff03c440/src/components/avatar-replayer.js#L296-L341 | |
22,784 | dmarcos/aframe-motion-capture-components | src/components/avatar-replayer.js | function () {
var self = this;
if (!this.isReplaying || !this.replayData) { return; }
this.isReplaying = false;
Object.keys(this.replayData).forEach(function removeReplayer (key) {
if (key === 'camera') {
self.cameraEl.removeComponent('motion-capture-replayer');
} else {
el = document.querySelector('#' + key);
if (!el) {
warn('No element with id ' + key);
return;
}
el.removeComponent('motion-capture-replayer');
}
});
} | javascript | function () {
var self = this;
if (!this.isReplaying || !this.replayData) { return; }
this.isReplaying = false;
Object.keys(this.replayData).forEach(function removeReplayer (key) {
if (key === 'camera') {
self.cameraEl.removeComponent('motion-capture-replayer');
} else {
el = document.querySelector('#' + key);
if (!el) {
warn('No element with id ' + key);
return;
}
el.removeComponent('motion-capture-replayer');
}
});
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"if",
"(",
"!",
"this",
".",
"isReplaying",
"||",
"!",
"this",
".",
"replayData",
")",
"{",
"return",
";",
"}",
"this",
".",
"isReplaying",
"=",
"false",
";",
"Object",
".",
"keys",
"(",
"this",
".",
"replayData",
")",
".",
"forEach",
"(",
"function",
"removeReplayer",
"(",
"key",
")",
"{",
"if",
"(",
"key",
"===",
"'camera'",
")",
"{",
"self",
".",
"cameraEl",
".",
"removeComponent",
"(",
"'motion-capture-replayer'",
")",
";",
"}",
"else",
"{",
"el",
"=",
"document",
".",
"querySelector",
"(",
"'#'",
"+",
"key",
")",
";",
"if",
"(",
"!",
"el",
")",
"{",
"warn",
"(",
"'No element with id '",
"+",
"key",
")",
";",
"return",
";",
"}",
"el",
".",
"removeComponent",
"(",
"'motion-capture-replayer'",
")",
";",
"}",
"}",
")",
";",
"}"
] | Remove motion-capture-replayer components. | [
"Remove",
"motion",
"-",
"capture",
"-",
"replayer",
"components",
"."
] | 3a3cbd73ffc751285be95e9729a09121ff03c440 | https://github.com/dmarcos/aframe-motion-capture-components/blob/3a3cbd73ffc751285be95e9729a09121ff03c440/src/components/avatar-replayer.js#L346-L364 | |
22,785 | dmarcos/aframe-motion-capture-components | src/components/avatar-replayer.js | function (url, binary, callback) {
var data;
var self = this;
fileLoader.crossOrigin = 'anonymous';
if (binary === true) {
fileLoader.setResponseType('arraybuffer');
}
fileLoader.load(url, function (buffer) {
if (binary === true) {
data = self.loadStrokeBinary(buffer);
} else {
data = JSON.parse(buffer);
}
if (callback) { callback(data); }
});
} | javascript | function (url, binary, callback) {
var data;
var self = this;
fileLoader.crossOrigin = 'anonymous';
if (binary === true) {
fileLoader.setResponseType('arraybuffer');
}
fileLoader.load(url, function (buffer) {
if (binary === true) {
data = self.loadStrokeBinary(buffer);
} else {
data = JSON.parse(buffer);
}
if (callback) { callback(data); }
});
} | [
"function",
"(",
"url",
",",
"binary",
",",
"callback",
")",
"{",
"var",
"data",
";",
"var",
"self",
"=",
"this",
";",
"fileLoader",
".",
"crossOrigin",
"=",
"'anonymous'",
";",
"if",
"(",
"binary",
"===",
"true",
")",
"{",
"fileLoader",
".",
"setResponseType",
"(",
"'arraybuffer'",
")",
";",
"}",
"fileLoader",
".",
"load",
"(",
"url",
",",
"function",
"(",
"buffer",
")",
"{",
"if",
"(",
"binary",
"===",
"true",
")",
"{",
"data",
"=",
"self",
".",
"loadStrokeBinary",
"(",
"buffer",
")",
";",
"}",
"else",
"{",
"data",
"=",
"JSON",
".",
"parse",
"(",
"buffer",
")",
";",
"}",
"if",
"(",
"callback",
")",
"{",
"callback",
"(",
"data",
")",
";",
"}",
"}",
")",
";",
"}"
] | XHR for data. | [
"XHR",
"for",
"data",
"."
] | 3a3cbd73ffc751285be95e9729a09121ff03c440 | https://github.com/dmarcos/aframe-motion-capture-components/blob/3a3cbd73ffc751285be95e9729a09121ff03c440/src/components/avatar-replayer.js#L369-L384 | |
22,786 | dmarcos/aframe-motion-capture-components | src/components/avatar-recorder.js | function () {
var self = this;
var trackedControllerEls = this.el.querySelectorAll('[tracked-controls]');
this.trackedControllerEls = {};
trackedControllerEls.forEach(function setupController (trackedControllerEl) {
if (!trackedControllerEl.id) {
warn('Found a tracked controller entity without an ID. ' +
'Provide an ID or this controller will not be recorded');
return;
}
trackedControllerEl.setAttribute('motion-capture-recorder', {
autoRecord: false,
visibleStroke: false
});
self.trackedControllerEls[trackedControllerEl.id] = trackedControllerEl;
if (self.isRecording) {
trackedControllerEl.components['motion-capture-recorder'].startRecording();
}
});
} | javascript | function () {
var self = this;
var trackedControllerEls = this.el.querySelectorAll('[tracked-controls]');
this.trackedControllerEls = {};
trackedControllerEls.forEach(function setupController (trackedControllerEl) {
if (!trackedControllerEl.id) {
warn('Found a tracked controller entity without an ID. ' +
'Provide an ID or this controller will not be recorded');
return;
}
trackedControllerEl.setAttribute('motion-capture-recorder', {
autoRecord: false,
visibleStroke: false
});
self.trackedControllerEls[trackedControllerEl.id] = trackedControllerEl;
if (self.isRecording) {
trackedControllerEl.components['motion-capture-recorder'].startRecording();
}
});
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"trackedControllerEls",
"=",
"this",
".",
"el",
".",
"querySelectorAll",
"(",
"'[tracked-controls]'",
")",
";",
"this",
".",
"trackedControllerEls",
"=",
"{",
"}",
";",
"trackedControllerEls",
".",
"forEach",
"(",
"function",
"setupController",
"(",
"trackedControllerEl",
")",
"{",
"if",
"(",
"!",
"trackedControllerEl",
".",
"id",
")",
"{",
"warn",
"(",
"'Found a tracked controller entity without an ID. '",
"+",
"'Provide an ID or this controller will not be recorded'",
")",
";",
"return",
";",
"}",
"trackedControllerEl",
".",
"setAttribute",
"(",
"'motion-capture-recorder'",
",",
"{",
"autoRecord",
":",
"false",
",",
"visibleStroke",
":",
"false",
"}",
")",
";",
"self",
".",
"trackedControllerEls",
"[",
"trackedControllerEl",
".",
"id",
"]",
"=",
"trackedControllerEl",
";",
"if",
"(",
"self",
".",
"isRecording",
")",
"{",
"trackedControllerEl",
".",
"components",
"[",
"'motion-capture-recorder'",
"]",
".",
"startRecording",
"(",
")",
";",
"}",
"}",
")",
";",
"}"
] | Poll for tracked controllers. | [
"Poll",
"for",
"tracked",
"controllers",
"."
] | 3a3cbd73ffc751285be95e9729a09121ff03c440 | https://github.com/dmarcos/aframe-motion-capture-components/blob/3a3cbd73ffc751285be95e9729a09121ff03c440/src/components/avatar-recorder.js#L33-L52 | |
22,787 | dmarcos/aframe-motion-capture-components | src/components/avatar-recorder.js | function (evt) {
var key = evt.keyCode;
var KEYS = {space: 32};
switch (key) {
// <space>: Toggle recording.
case KEYS.space: {
this.toggleRecording();
break;
}
}
} | javascript | function (evt) {
var key = evt.keyCode;
var KEYS = {space: 32};
switch (key) {
// <space>: Toggle recording.
case KEYS.space: {
this.toggleRecording();
break;
}
}
} | [
"function",
"(",
"evt",
")",
"{",
"var",
"key",
"=",
"evt",
".",
"keyCode",
";",
"var",
"KEYS",
"=",
"{",
"space",
":",
"32",
"}",
";",
"switch",
"(",
"key",
")",
"{",
"// <space>: Toggle recording.",
"case",
"KEYS",
".",
"space",
":",
"{",
"this",
".",
"toggleRecording",
"(",
")",
";",
"break",
";",
"}",
"}",
"}"
] | Keyboard shortcuts. | [
"Keyboard",
"shortcuts",
"."
] | 3a3cbd73ffc751285be95e9729a09121ff03c440 | https://github.com/dmarcos/aframe-motion-capture-components/blob/3a3cbd73ffc751285be95e9729a09121ff03c440/src/components/avatar-recorder.js#L65-L75 | |
22,788 | dmarcos/aframe-motion-capture-components | src/components/avatar-recorder.js | function (doneCb) {
var el = this.el;
var self = this;
if (this.data.cameraOverride) {
prepareCamera(this.data.cameraOverride);
return;
}
// Grab camera.
if (el.camera && el.camera.el) {
prepareCamera(el.camera.el);
return;
}
el.addEventListener('camera-set-active', function setup (evt) {
prepareCamera(evt.detail.cameraEl);
el.removeEventListener('camera-set-active', setup);
});
function prepareCamera (cameraEl) {
if (self.cameraEl) {
self.cameraEl.removeAttribute('motion-capture-recorder');
}
self.cameraEl = cameraEl;
cameraEl.setAttribute('motion-capture-recorder', {
autoRecord: false,
visibleStroke: false
});
doneCb(cameraEl)
}
} | javascript | function (doneCb) {
var el = this.el;
var self = this;
if (this.data.cameraOverride) {
prepareCamera(this.data.cameraOverride);
return;
}
// Grab camera.
if (el.camera && el.camera.el) {
prepareCamera(el.camera.el);
return;
}
el.addEventListener('camera-set-active', function setup (evt) {
prepareCamera(evt.detail.cameraEl);
el.removeEventListener('camera-set-active', setup);
});
function prepareCamera (cameraEl) {
if (self.cameraEl) {
self.cameraEl.removeAttribute('motion-capture-recorder');
}
self.cameraEl = cameraEl;
cameraEl.setAttribute('motion-capture-recorder', {
autoRecord: false,
visibleStroke: false
});
doneCb(cameraEl)
}
} | [
"function",
"(",
"doneCb",
")",
"{",
"var",
"el",
"=",
"this",
".",
"el",
";",
"var",
"self",
"=",
"this",
";",
"if",
"(",
"this",
".",
"data",
".",
"cameraOverride",
")",
"{",
"prepareCamera",
"(",
"this",
".",
"data",
".",
"cameraOverride",
")",
";",
"return",
";",
"}",
"// Grab camera.",
"if",
"(",
"el",
".",
"camera",
"&&",
"el",
".",
"camera",
".",
"el",
")",
"{",
"prepareCamera",
"(",
"el",
".",
"camera",
".",
"el",
")",
";",
"return",
";",
"}",
"el",
".",
"addEventListener",
"(",
"'camera-set-active'",
",",
"function",
"setup",
"(",
"evt",
")",
"{",
"prepareCamera",
"(",
"evt",
".",
"detail",
".",
"cameraEl",
")",
";",
"el",
".",
"removeEventListener",
"(",
"'camera-set-active'",
",",
"setup",
")",
";",
"}",
")",
";",
"function",
"prepareCamera",
"(",
"cameraEl",
")",
"{",
"if",
"(",
"self",
".",
"cameraEl",
")",
"{",
"self",
".",
"cameraEl",
".",
"removeAttribute",
"(",
"'motion-capture-recorder'",
")",
";",
"}",
"self",
".",
"cameraEl",
"=",
"cameraEl",
";",
"cameraEl",
".",
"setAttribute",
"(",
"'motion-capture-recorder'",
",",
"{",
"autoRecord",
":",
"false",
",",
"visibleStroke",
":",
"false",
"}",
")",
";",
"doneCb",
"(",
"cameraEl",
")",
"}",
"}"
] | Set motion capture recorder on the camera once the camera is ready. | [
"Set",
"motion",
"capture",
"recorder",
"on",
"the",
"camera",
"once",
"the",
"camera",
"is",
"ready",
"."
] | 3a3cbd73ffc751285be95e9729a09121ff03c440 | https://github.com/dmarcos/aframe-motion-capture-components/blob/3a3cbd73ffc751285be95e9729a09121ff03c440/src/components/avatar-recorder.js#L91-L122 | |
22,789 | dmarcos/aframe-motion-capture-components | src/components/avatar-recorder.js | function () {
var trackedControllerEls = this.trackedControllerEls;
var self = this;
if (this.isRecording) { return; }
log('Starting recording!');
if (this.el.components['avatar-replayer']) {
this.el.components['avatar-replayer'].stopReplaying();
}
// Get camera.
this.setupCamera(function cameraSetUp () {
self.isRecording = true;
// Record camera.
self.cameraEl.components['motion-capture-recorder'].startRecording();
// Record tracked controls.
Object.keys(trackedControllerEls).forEach(function startRecordingController (id) {
trackedControllerEls[id].components['motion-capture-recorder'].startRecording();
});
});
} | javascript | function () {
var trackedControllerEls = this.trackedControllerEls;
var self = this;
if (this.isRecording) { return; }
log('Starting recording!');
if (this.el.components['avatar-replayer']) {
this.el.components['avatar-replayer'].stopReplaying();
}
// Get camera.
this.setupCamera(function cameraSetUp () {
self.isRecording = true;
// Record camera.
self.cameraEl.components['motion-capture-recorder'].startRecording();
// Record tracked controls.
Object.keys(trackedControllerEls).forEach(function startRecordingController (id) {
trackedControllerEls[id].components['motion-capture-recorder'].startRecording();
});
});
} | [
"function",
"(",
")",
"{",
"var",
"trackedControllerEls",
"=",
"this",
".",
"trackedControllerEls",
";",
"var",
"self",
"=",
"this",
";",
"if",
"(",
"this",
".",
"isRecording",
")",
"{",
"return",
";",
"}",
"log",
"(",
"'Starting recording!'",
")",
";",
"if",
"(",
"this",
".",
"el",
".",
"components",
"[",
"'avatar-replayer'",
"]",
")",
"{",
"this",
".",
"el",
".",
"components",
"[",
"'avatar-replayer'",
"]",
".",
"stopReplaying",
"(",
")",
";",
"}",
"// Get camera.",
"this",
".",
"setupCamera",
"(",
"function",
"cameraSetUp",
"(",
")",
"{",
"self",
".",
"isRecording",
"=",
"true",
";",
"// Record camera.",
"self",
".",
"cameraEl",
".",
"components",
"[",
"'motion-capture-recorder'",
"]",
".",
"startRecording",
"(",
")",
";",
"// Record tracked controls.",
"Object",
".",
"keys",
"(",
"trackedControllerEls",
")",
".",
"forEach",
"(",
"function",
"startRecordingController",
"(",
"id",
")",
"{",
"trackedControllerEls",
"[",
"id",
"]",
".",
"components",
"[",
"'motion-capture-recorder'",
"]",
".",
"startRecording",
"(",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Start recording camera and tracked controls. | [
"Start",
"recording",
"camera",
"and",
"tracked",
"controls",
"."
] | 3a3cbd73ffc751285be95e9729a09121ff03c440 | https://github.com/dmarcos/aframe-motion-capture-components/blob/3a3cbd73ffc751285be95e9729a09121ff03c440/src/components/avatar-recorder.js#L127-L149 | |
22,790 | dmarcos/aframe-motion-capture-components | src/components/avatar-recorder.js | function () {
var trackedControllerEls = this.trackedControllerEls;
if (!this.isRecording) { return; }
log('Stopped recording.');
this.isRecording = false;
this.cameraEl.components['motion-capture-recorder'].stopRecording();
Object.keys(trackedControllerEls).forEach(function (id) {
trackedControllerEls[id].components['motion-capture-recorder'].stopRecording();
});
this.recordingData = this.getJSONData();
this.storeRecording(this.recordingData);
if (this.data.autoPlay) {
this.replayRecording();
}
} | javascript | function () {
var trackedControllerEls = this.trackedControllerEls;
if (!this.isRecording) { return; }
log('Stopped recording.');
this.isRecording = false;
this.cameraEl.components['motion-capture-recorder'].stopRecording();
Object.keys(trackedControllerEls).forEach(function (id) {
trackedControllerEls[id].components['motion-capture-recorder'].stopRecording();
});
this.recordingData = this.getJSONData();
this.storeRecording(this.recordingData);
if (this.data.autoPlay) {
this.replayRecording();
}
} | [
"function",
"(",
")",
"{",
"var",
"trackedControllerEls",
"=",
"this",
".",
"trackedControllerEls",
";",
"if",
"(",
"!",
"this",
".",
"isRecording",
")",
"{",
"return",
";",
"}",
"log",
"(",
"'Stopped recording.'",
")",
";",
"this",
".",
"isRecording",
"=",
"false",
";",
"this",
".",
"cameraEl",
".",
"components",
"[",
"'motion-capture-recorder'",
"]",
".",
"stopRecording",
"(",
")",
";",
"Object",
".",
"keys",
"(",
"trackedControllerEls",
")",
".",
"forEach",
"(",
"function",
"(",
"id",
")",
"{",
"trackedControllerEls",
"[",
"id",
"]",
".",
"components",
"[",
"'motion-capture-recorder'",
"]",
".",
"stopRecording",
"(",
")",
";",
"}",
")",
";",
"this",
".",
"recordingData",
"=",
"this",
".",
"getJSONData",
"(",
")",
";",
"this",
".",
"storeRecording",
"(",
"this",
".",
"recordingData",
")",
";",
"if",
"(",
"this",
".",
"data",
".",
"autoPlay",
")",
"{",
"this",
".",
"replayRecording",
"(",
")",
";",
"}",
"}"
] | Tell camera and tracked controls motion-capture-recorder components to stop recording.
Store recording and replay if autoPlay is on. | [
"Tell",
"camera",
"and",
"tracked",
"controls",
"motion",
"-",
"capture",
"-",
"recorder",
"components",
"to",
"stop",
"recording",
".",
"Store",
"recording",
"and",
"replay",
"if",
"autoPlay",
"is",
"on",
"."
] | 3a3cbd73ffc751285be95e9729a09121ff03c440 | https://github.com/dmarcos/aframe-motion-capture-components/blob/3a3cbd73ffc751285be95e9729a09121ff03c440/src/components/avatar-recorder.js#L155-L172 | |
22,791 | dmarcos/aframe-motion-capture-components | src/components/avatar-recorder.js | function (recordingData) {
var data = this.data;
if (!data.localStorage) { return; }
log('Recording stored in localStorage.');
this.el.systems.recordingdb.addRecording(data.recordingName, recordingData);
} | javascript | function (recordingData) {
var data = this.data;
if (!data.localStorage) { return; }
log('Recording stored in localStorage.');
this.el.systems.recordingdb.addRecording(data.recordingName, recordingData);
} | [
"function",
"(",
"recordingData",
")",
"{",
"var",
"data",
"=",
"this",
".",
"data",
";",
"if",
"(",
"!",
"data",
".",
"localStorage",
")",
"{",
"return",
";",
"}",
"log",
"(",
"'Recording stored in localStorage.'",
")",
";",
"this",
".",
"el",
".",
"systems",
".",
"recordingdb",
".",
"addRecording",
"(",
"data",
".",
"recordingName",
",",
"recordingData",
")",
";",
"}"
] | Store recording in IndexedDB using recordingdb system. | [
"Store",
"recording",
"in",
"IndexedDB",
"using",
"recordingdb",
"system",
"."
] | 3a3cbd73ffc751285be95e9729a09121ff03c440 | https://github.com/dmarcos/aframe-motion-capture-components/blob/3a3cbd73ffc751285be95e9729a09121ff03c440/src/components/avatar-recorder.js#L199-L204 | |
22,792 | dmarcos/aframe-motion-capture-components | src/systems/motion-capture-replayer.js | function (gamepads) {
var i;
var sceneEl = this.sceneEl;
var trackedControlsSystem = sceneEl.systems['tracked-controls'];
gamepads = gamepads || []
// convert from read-only GamepadList
gamepads = Array.from(gamepads)
this.gamepads.forEach(function (gamepad) {
if (gamepads[gamepad.index]) { return; }
// to pass check in updateControllerListOriginal
gamepad.pose = true;
gamepads[gamepad.index] = gamepad;
});
this.updateControllerListOriginal(gamepads);
} | javascript | function (gamepads) {
var i;
var sceneEl = this.sceneEl;
var trackedControlsSystem = sceneEl.systems['tracked-controls'];
gamepads = gamepads || []
// convert from read-only GamepadList
gamepads = Array.from(gamepads)
this.gamepads.forEach(function (gamepad) {
if (gamepads[gamepad.index]) { return; }
// to pass check in updateControllerListOriginal
gamepad.pose = true;
gamepads[gamepad.index] = gamepad;
});
this.updateControllerListOriginal(gamepads);
} | [
"function",
"(",
"gamepads",
")",
"{",
"var",
"i",
";",
"var",
"sceneEl",
"=",
"this",
".",
"sceneEl",
";",
"var",
"trackedControlsSystem",
"=",
"sceneEl",
".",
"systems",
"[",
"'tracked-controls'",
"]",
";",
"gamepads",
"=",
"gamepads",
"||",
"[",
"]",
"// convert from read-only GamepadList",
"gamepads",
"=",
"Array",
".",
"from",
"(",
"gamepads",
")",
"this",
".",
"gamepads",
".",
"forEach",
"(",
"function",
"(",
"gamepad",
")",
"{",
"if",
"(",
"gamepads",
"[",
"gamepad",
".",
"index",
"]",
")",
"{",
"return",
";",
"}",
"// to pass check in updateControllerListOriginal",
"gamepad",
".",
"pose",
"=",
"true",
";",
"gamepads",
"[",
"gamepad",
".",
"index",
"]",
"=",
"gamepad",
";",
"}",
")",
";",
"this",
".",
"updateControllerListOriginal",
"(",
"gamepads",
")",
";",
"}"
] | Wrap `updateControllerList` to stub in the gamepads and emit `controllersupdated`. | [
"Wrap",
"updateControllerList",
"to",
"stub",
"in",
"the",
"gamepads",
"and",
"emit",
"controllersupdated",
"."
] | 3a3cbd73ffc751285be95e9729a09121ff03c440 | https://github.com/dmarcos/aframe-motion-capture-components/blob/3a3cbd73ffc751285be95e9729a09121ff03c440/src/systems/motion-capture-replayer.js#L43-L59 | |
22,793 | Alhadis/Accordion | src/accordion.js | setToken | function setToken(list, token, enabled){
enabled ? list.add(token) : list.remove(token);
} | javascript | function setToken(list, token, enabled){
enabled ? list.add(token) : list.remove(token);
} | [
"function",
"setToken",
"(",
"list",
",",
"token",
",",
"enabled",
")",
"{",
"enabled",
"?",
"list",
".",
"add",
"(",
"token",
")",
":",
"list",
".",
"remove",
"(",
"token",
")",
";",
"}"
] | Conditionally add or remove a token from a token-list.
@param {DOMTokenList} list
@param {String} token
@param {Boolean} enabled | [
"Conditionally",
"add",
"or",
"remove",
"a",
"token",
"from",
"a",
"token",
"-",
"list",
"."
] | 057b2fdf9f875519120991df59e68e4ec0c06a6d | https://github.com/Alhadis/Accordion/blob/057b2fdf9f875519120991df59e68e4ec0c06a6d/src/accordion.js#L25-L27 |
22,794 | Alhadis/Accordion | src/accordion.js | debounce | function debounce(fn, limit, soon){
var limit = limit < 0 ? 0 : limit,
started, context, args, timer,
delayed = function(){
// Get the time between now and when the function was first fired
var timeSince = Date.now() - started;
if(timeSince >= limit){
if(!soon) fn.apply(context, args);
if(timer) clearTimeout(timer);
timer = context = args = null;
}
else timer = setTimeout(delayed, limit - timeSince);
};
// Debounced copy of the original function
return function(){
context = this,
args = arguments;
if(!limit)
return fn.apply(context, args);
started = Date.now();
if(!timer){
if(soon) fn.apply(context, args);
timer = setTimeout(delayed, limit);
}
};
} | javascript | function debounce(fn, limit, soon){
var limit = limit < 0 ? 0 : limit,
started, context, args, timer,
delayed = function(){
// Get the time between now and when the function was first fired
var timeSince = Date.now() - started;
if(timeSince >= limit){
if(!soon) fn.apply(context, args);
if(timer) clearTimeout(timer);
timer = context = args = null;
}
else timer = setTimeout(delayed, limit - timeSince);
};
// Debounced copy of the original function
return function(){
context = this,
args = arguments;
if(!limit)
return fn.apply(context, args);
started = Date.now();
if(!timer){
if(soon) fn.apply(context, args);
timer = setTimeout(delayed, limit);
}
};
} | [
"function",
"debounce",
"(",
"fn",
",",
"limit",
",",
"soon",
")",
"{",
"var",
"limit",
"=",
"limit",
"<",
"0",
"?",
"0",
":",
"limit",
",",
"started",
",",
"context",
",",
"args",
",",
"timer",
",",
"delayed",
"=",
"function",
"(",
")",
"{",
"// Get the time between now and when the function was first fired",
"var",
"timeSince",
"=",
"Date",
".",
"now",
"(",
")",
"-",
"started",
";",
"if",
"(",
"timeSince",
">=",
"limit",
")",
"{",
"if",
"(",
"!",
"soon",
")",
"fn",
".",
"apply",
"(",
"context",
",",
"args",
")",
";",
"if",
"(",
"timer",
")",
"clearTimeout",
"(",
"timer",
")",
";",
"timer",
"=",
"context",
"=",
"args",
"=",
"null",
";",
"}",
"else",
"timer",
"=",
"setTimeout",
"(",
"delayed",
",",
"limit",
"-",
"timeSince",
")",
";",
"}",
";",
"// Debounced copy of the original function",
"return",
"function",
"(",
")",
"{",
"context",
"=",
"this",
",",
"args",
"=",
"arguments",
";",
"if",
"(",
"!",
"limit",
")",
"return",
"fn",
".",
"apply",
"(",
"context",
",",
"args",
")",
";",
"started",
"=",
"Date",
".",
"now",
"(",
")",
";",
"if",
"(",
"!",
"timer",
")",
"{",
"if",
"(",
"soon",
")",
"fn",
".",
"apply",
"(",
"context",
",",
"args",
")",
";",
"timer",
"=",
"setTimeout",
"(",
"delayed",
",",
"limit",
")",
";",
"}",
"}",
";",
"}"
] | Stop a function from firing too quickly.
Returns a copy of the original function that runs only after the designated
number of milliseconds have elapsed. Useful for throttling onResize handlers.
@param {Number} limit - Threshold to stall execution by, in milliseconds.
@param {Boolean} soon - If TRUE, will call the function *before* the threshold's elapsed, rather than after.
@return {Function} | [
"Stop",
"a",
"function",
"from",
"firing",
"too",
"quickly",
"."
] | 057b2fdf9f875519120991df59e68e4ec0c06a6d | https://github.com/Alhadis/Accordion/blob/057b2fdf9f875519120991df59e68e4ec0c06a6d/src/accordion.js#L41-L74 |
22,795 | Alhadis/Accordion | src/accordion.js | fit | function fit(){
var height = THIS.headingHeight;
if(THIS.open) height += content.scrollHeight;
if(useBorders) height += THIS.elBorder;
THIS.height = height;
} | javascript | function fit(){
var height = THIS.headingHeight;
if(THIS.open) height += content.scrollHeight;
if(useBorders) height += THIS.elBorder;
THIS.height = height;
} | [
"function",
"fit",
"(",
")",
"{",
"var",
"height",
"=",
"THIS",
".",
"headingHeight",
";",
"if",
"(",
"THIS",
".",
"open",
")",
"height",
"+=",
"content",
".",
"scrollHeight",
";",
"if",
"(",
"useBorders",
")",
"height",
"+=",
"THIS",
".",
"elBorder",
";",
"THIS",
".",
"height",
"=",
"height",
";",
"}"
] | Adjust a fold's container to fit its content. | [
"Adjust",
"a",
"fold",
"s",
"container",
"to",
"fit",
"its",
"content",
"."
] | 057b2fdf9f875519120991df59e68e4ec0c06a6d | https://github.com/Alhadis/Accordion/blob/057b2fdf9f875519120991df59e68e4ec0c06a6d/src/accordion.js#L623-L628 |
22,796 | Alhadis/Accordion | src/accordion.js | updateFold | function updateFold(fold, offset){
var next = fold;
var parentFold = THIS.parentFold;
while(next = next.nextFold)
next.y += offset;
parentFold || edgeCheck(offset);
fold.height += offset;
THIS.height += offset;
parentFold && parentFold.open && THIS.parent.updateFold(parentFold, offset);
} | javascript | function updateFold(fold, offset){
var next = fold;
var parentFold = THIS.parentFold;
while(next = next.nextFold)
next.y += offset;
parentFold || edgeCheck(offset);
fold.height += offset;
THIS.height += offset;
parentFold && parentFold.open && THIS.parent.updateFold(parentFold, offset);
} | [
"function",
"updateFold",
"(",
"fold",
",",
"offset",
")",
"{",
"var",
"next",
"=",
"fold",
";",
"var",
"parentFold",
"=",
"THIS",
".",
"parentFold",
";",
"while",
"(",
"next",
"=",
"next",
".",
"nextFold",
")",
"next",
".",
"y",
"+=",
"offset",
";",
"parentFold",
"||",
"edgeCheck",
"(",
"offset",
")",
";",
"fold",
".",
"height",
"+=",
"offset",
";",
"THIS",
".",
"height",
"+=",
"offset",
";",
"parentFold",
"&&",
"parentFold",
".",
"open",
"&&",
"THIS",
".",
"parent",
".",
"updateFold",
"(",
"parentFold",
",",
"offset",
")",
";",
"}"
] | Update the vertical ordinate of each sibling for a particular fold.
@param {Fold} fold
@param {Number} offset - Pixel distance to adjust by | [
"Update",
"the",
"vertical",
"ordinate",
"of",
"each",
"sibling",
"for",
"a",
"particular",
"fold",
"."
] | 057b2fdf9f875519120991df59e68e4ec0c06a6d | https://github.com/Alhadis/Accordion/blob/057b2fdf9f875519120991df59e68e4ec0c06a6d/src/accordion.js#L906-L917 |
22,797 | Alhadis/Accordion | src/accordion.js | update | function update(){
var y = 0;
var height = 0;
var i = 0;
var l = folds.length;
var parentFold = THIS.parentFold;
var fold, diff;
for(; i < l; ++i){
fold = folds[i];
fold.y = y;
fold.fit();
y += fold.height;
height += fold.height;
}
diff = height - _height;
parentFold
? (parentFold.open && THIS.parent.updateFold(parentFold, diff))
: edgeCheck(diff);
THIS.height = height;
} | javascript | function update(){
var y = 0;
var height = 0;
var i = 0;
var l = folds.length;
var parentFold = THIS.parentFold;
var fold, diff;
for(; i < l; ++i){
fold = folds[i];
fold.y = y;
fold.fit();
y += fold.height;
height += fold.height;
}
diff = height - _height;
parentFold
? (parentFold.open && THIS.parent.updateFold(parentFold, diff))
: edgeCheck(diff);
THIS.height = height;
} | [
"function",
"update",
"(",
")",
"{",
"var",
"y",
"=",
"0",
";",
"var",
"height",
"=",
"0",
";",
"var",
"i",
"=",
"0",
";",
"var",
"l",
"=",
"folds",
".",
"length",
";",
"var",
"parentFold",
"=",
"THIS",
".",
"parentFold",
";",
"var",
"fold",
",",
"diff",
";",
"for",
"(",
";",
"i",
"<",
"l",
";",
"++",
"i",
")",
"{",
"fold",
"=",
"folds",
"[",
"i",
"]",
";",
"fold",
".",
"y",
"=",
"y",
";",
"fold",
".",
"fit",
"(",
")",
";",
"y",
"+=",
"fold",
".",
"height",
";",
"height",
"+=",
"fold",
".",
"height",
";",
"}",
"diff",
"=",
"height",
"-",
"_height",
";",
"parentFold",
"?",
"(",
"parentFold",
".",
"open",
"&&",
"THIS",
".",
"parent",
".",
"updateFold",
"(",
"parentFold",
",",
"diff",
")",
")",
":",
"edgeCheck",
"(",
"diff",
")",
";",
"THIS",
".",
"height",
"=",
"height",
";",
"}"
] | Update the height of each fold to fit its content. | [
"Update",
"the",
"height",
"of",
"each",
"fold",
"to",
"fit",
"its",
"content",
"."
] | 057b2fdf9f875519120991df59e68e4ec0c06a6d | https://github.com/Alhadis/Accordion/blob/057b2fdf9f875519120991df59e68e4ec0c06a6d/src/accordion.js#L923-L945 |
22,798 | Alhadis/Accordion | src/accordion.js | refresh | function refresh(allowSnap){
var snap = allowSnap ? snapClass : false;
snap && elClasses.add(snap);
THIS.update();
THIS.childAccordions && THIS.childAccordions.forEach(function(a){
a.parentFold.open
? a.refresh(allowSnap)
: (a.parentFold.needsRefresh = true);
});
snap && setTimeout(function(e){elClasses.remove(snap)}, 20);
} | javascript | function refresh(allowSnap){
var snap = allowSnap ? snapClass : false;
snap && elClasses.add(snap);
THIS.update();
THIS.childAccordions && THIS.childAccordions.forEach(function(a){
a.parentFold.open
? a.refresh(allowSnap)
: (a.parentFold.needsRefresh = true);
});
snap && setTimeout(function(e){elClasses.remove(snap)}, 20);
} | [
"function",
"refresh",
"(",
"allowSnap",
")",
"{",
"var",
"snap",
"=",
"allowSnap",
"?",
"snapClass",
":",
"false",
";",
"snap",
"&&",
"elClasses",
".",
"add",
"(",
"snap",
")",
";",
"THIS",
".",
"update",
"(",
")",
";",
"THIS",
".",
"childAccordions",
"&&",
"THIS",
".",
"childAccordions",
".",
"forEach",
"(",
"function",
"(",
"a",
")",
"{",
"a",
".",
"parentFold",
".",
"open",
"?",
"a",
".",
"refresh",
"(",
"allowSnap",
")",
":",
"(",
"a",
".",
"parentFold",
".",
"needsRefresh",
"=",
"true",
")",
";",
"}",
")",
";",
"snap",
"&&",
"setTimeout",
"(",
"function",
"(",
"e",
")",
"{",
"elClasses",
".",
"remove",
"(",
"snap",
")",
"}",
",",
"20",
")",
";",
"}"
] | Recalculate the boundaries of an Accordion and its descendants.
This method should only be called if the width of a container changes,
or a fold's contents have resized unexpectedly (such as when images load).
@param {Boolean} allowSnap - Snap folds instantly into place without transitioning | [
"Recalculate",
"the",
"boundaries",
"of",
"an",
"Accordion",
"and",
"its",
"descendants",
"."
] | 057b2fdf9f875519120991df59e68e4ec0c06a6d | https://github.com/Alhadis/Accordion/blob/057b2fdf9f875519120991df59e68e4ec0c06a6d/src/accordion.js#L957-L969 |
22,799 | decaffeinate/bulk-decaffeinate | src/config/resolveConfig.js | getCLIParamsConfig | function getCLIParamsConfig(config, commander) {
let {
file,
pathFile,
dir,
useJsModules,
landBase,
numWorkers,
skipVerify,
decaffeinatePath,
jscodeshiftPath,
eslintPath,
} = commander;
// As a special case, specifying files to process from the CLI should cause
// any equivalent config file settings to be ignored.
if ((file && file.length > 0) || dir || pathFile) {
config.filesToProcess = null;
config.searchDirectory = null;
config.pathFile = null;
}
if (file && file.length > 0) {
config.filesToProcess = file;
}
if (dir) {
config.searchDirectory = dir;
}
if (pathFile) {
config.pathFile = pathFile;
}
if (useJsModules) {
config.useJSModules = true;
}
if (landBase) {
config.landBase = landBase;
}
if (numWorkers) {
config.numWorkers = numWorkers;
}
if (skipVerify) {
config.skipVerify = true;
}
if (decaffeinatePath) {
config.decaffeinatePath = decaffeinatePath;
}
if (jscodeshiftPath) {
config.jscodeshiftPath = jscodeshiftPath;
}
if (eslintPath) {
config.eslintPath = eslintPath;
}
return config;
} | javascript | function getCLIParamsConfig(config, commander) {
let {
file,
pathFile,
dir,
useJsModules,
landBase,
numWorkers,
skipVerify,
decaffeinatePath,
jscodeshiftPath,
eslintPath,
} = commander;
// As a special case, specifying files to process from the CLI should cause
// any equivalent config file settings to be ignored.
if ((file && file.length > 0) || dir || pathFile) {
config.filesToProcess = null;
config.searchDirectory = null;
config.pathFile = null;
}
if (file && file.length > 0) {
config.filesToProcess = file;
}
if (dir) {
config.searchDirectory = dir;
}
if (pathFile) {
config.pathFile = pathFile;
}
if (useJsModules) {
config.useJSModules = true;
}
if (landBase) {
config.landBase = landBase;
}
if (numWorkers) {
config.numWorkers = numWorkers;
}
if (skipVerify) {
config.skipVerify = true;
}
if (decaffeinatePath) {
config.decaffeinatePath = decaffeinatePath;
}
if (jscodeshiftPath) {
config.jscodeshiftPath = jscodeshiftPath;
}
if (eslintPath) {
config.eslintPath = eslintPath;
}
return config;
} | [
"function",
"getCLIParamsConfig",
"(",
"config",
",",
"commander",
")",
"{",
"let",
"{",
"file",
",",
"pathFile",
",",
"dir",
",",
"useJsModules",
",",
"landBase",
",",
"numWorkers",
",",
"skipVerify",
",",
"decaffeinatePath",
",",
"jscodeshiftPath",
",",
"eslintPath",
",",
"}",
"=",
"commander",
";",
"// As a special case, specifying files to process from the CLI should cause",
"// any equivalent config file settings to be ignored.",
"if",
"(",
"(",
"file",
"&&",
"file",
".",
"length",
">",
"0",
")",
"||",
"dir",
"||",
"pathFile",
")",
"{",
"config",
".",
"filesToProcess",
"=",
"null",
";",
"config",
".",
"searchDirectory",
"=",
"null",
";",
"config",
".",
"pathFile",
"=",
"null",
";",
"}",
"if",
"(",
"file",
"&&",
"file",
".",
"length",
">",
"0",
")",
"{",
"config",
".",
"filesToProcess",
"=",
"file",
";",
"}",
"if",
"(",
"dir",
")",
"{",
"config",
".",
"searchDirectory",
"=",
"dir",
";",
"}",
"if",
"(",
"pathFile",
")",
"{",
"config",
".",
"pathFile",
"=",
"pathFile",
";",
"}",
"if",
"(",
"useJsModules",
")",
"{",
"config",
".",
"useJSModules",
"=",
"true",
";",
"}",
"if",
"(",
"landBase",
")",
"{",
"config",
".",
"landBase",
"=",
"landBase",
";",
"}",
"if",
"(",
"numWorkers",
")",
"{",
"config",
".",
"numWorkers",
"=",
"numWorkers",
";",
"}",
"if",
"(",
"skipVerify",
")",
"{",
"config",
".",
"skipVerify",
"=",
"true",
";",
"}",
"if",
"(",
"decaffeinatePath",
")",
"{",
"config",
".",
"decaffeinatePath",
"=",
"decaffeinatePath",
";",
"}",
"if",
"(",
"jscodeshiftPath",
")",
"{",
"config",
".",
"jscodeshiftPath",
"=",
"jscodeshiftPath",
";",
"}",
"if",
"(",
"eslintPath",
")",
"{",
"config",
".",
"eslintPath",
"=",
"eslintPath",
";",
"}",
"return",
"config",
";",
"}"
] | Fill in a configuration from the CLI arguments. | [
"Fill",
"in",
"a",
"configuration",
"from",
"the",
"CLI",
"arguments",
"."
] | 78a75de4eb3d7a3bd5a4d8e882a6b5d4ca8cd7f1 | https://github.com/decaffeinate/bulk-decaffeinate/blob/78a75de4eb3d7a3bd5a4d8e882a6b5d4ca8cd7f1/src/config/resolveConfig.js#L97-L149 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.