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 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
googleapis/nodejs-vision | samples/textDetection.js | main | async function main(inputDir) {
const index = new Index();
try {
const files = await readdir(inputDir);
// Get a list of all files in the directory (filter out other directories)
const allImageFiles = (await Promise.all(
files.map(async file => {
const filename = path.join(inputDir, file)... | javascript | async function main(inputDir) {
const index = new Index();
try {
const files = await readdir(inputDir);
// Get a list of all files in the directory (filter out other directories)
const allImageFiles = (await Promise.all(
files.map(async file => {
const filename = path.join(inputDir, file)... | [
"async",
"function",
"main",
"(",
"inputDir",
")",
"{",
"const",
"index",
"=",
"new",
"Index",
"(",
")",
";",
"try",
"{",
"const",
"files",
"=",
"await",
"readdir",
"(",
"inputDir",
")",
";",
"// Get a list of all files in the directory (filter out other directori... | Main entry point for the program.
@param {string} inputDir The directory in which to run the sample.
@returns {Promise<void>} | [
"Main",
"entry",
"point",
"for",
"the",
"program",
"."
] | a64bf32d32997d3d4fcd9a99db1bec43c60efc49 | https://github.com/googleapis/nodejs-vision/blob/a64bf32d32997d3d4fcd9a99db1bec43c60efc49/samples/textDetection.js#L235-L280 | train |
gmetais/YellowLabTools | lib/server/datastores/resultsDatastore.js | saveScreenshotIfExists | function saveScreenshotIfExists(testResults) {
var deferred = Q.defer();
if (testResults.screenshotBuffer) {
var screenshotFilePath = path.join(resultsDir, testResults.runId, resultScreenshotName);
fs.writeFile(screenshotFilePath, testResults.screenshotBuffer);
del... | javascript | function saveScreenshotIfExists(testResults) {
var deferred = Q.defer();
if (testResults.screenshotBuffer) {
var screenshotFilePath = path.join(resultsDir, testResults.runId, resultScreenshotName);
fs.writeFile(screenshotFilePath, testResults.screenshotBuffer);
del... | [
"function",
"saveScreenshotIfExists",
"(",
"testResults",
")",
"{",
"var",
"deferred",
"=",
"Q",
".",
"defer",
"(",
")",
";",
"if",
"(",
"testResults",
".",
"screenshotBuffer",
")",
"{",
"var",
"screenshotFilePath",
"=",
"path",
".",
"join",
"(",
"resultsDir... | If there is a screenshot, save it as screenshot.jpg in the same folder as the results | [
"If",
"there",
"is",
"a",
"screenshot",
"save",
"it",
"as",
"screenshot",
".",
"jpg",
"in",
"the",
"same",
"folder",
"as",
"the",
"results"
] | c59e9fc3f5d3db4e8f8952f154891ab3194d8f76 | https://github.com/gmetais/YellowLabTools/blob/c59e9fc3f5d3db4e8f8952f154891ab3194d8f76/lib/server/datastores/resultsDatastore.js#L93-L108 | train |
gmetais/YellowLabTools | lib/tools/phantomas/custom_modules/core/scopeYLT/scopeYLT.js | spyEnabled | function spyEnabled(state, reason) {
enabled = (state === true);
phantomas.log('Spying ' + (enabled ? 'enabled' : 'disabled') + (reason ? ' - ' + reason : ''));
} | javascript | function spyEnabled(state, reason) {
enabled = (state === true);
phantomas.log('Spying ' + (enabled ? 'enabled' : 'disabled') + (reason ? ' - ' + reason : ''));
} | [
"function",
"spyEnabled",
"(",
"state",
",",
"reason",
")",
"{",
"enabled",
"=",
"(",
"state",
"===",
"true",
")",
";",
"phantomas",
".",
"log",
"(",
"'Spying '",
"+",
"(",
"enabled",
"?",
"'enabled'",
":",
"'disabled'",
")",
"+",
"(",
"reason",
"?",
... | turn off spying to not include internal phantomas actions | [
"turn",
"off",
"spying",
"to",
"not",
"include",
"internal",
"phantomas",
"actions"
] | c59e9fc3f5d3db4e8f8952f154891ab3194d8f76 | https://github.com/gmetais/YellowLabTools/blob/c59e9fc3f5d3db4e8f8952f154891ab3194d8f76/lib/tools/phantomas/custom_modules/core/scopeYLT/scopeYLT.js#L30-L34 | train |
gmetais/YellowLabTools | lib/tools/phantomas/custom_modules/core/scopeYLT/scopeYLT.js | pushContext | function pushContext(data) {
// Some data is not needed on subchildren
if (depth === 0) {
data.timestamp = Date.now() - responseEndTime;
data.loadingStep = phantomas.currentStep || '';
... | javascript | function pushContext(data) {
// Some data is not needed on subchildren
if (depth === 0) {
data.timestamp = Date.now() - responseEndTime;
data.loadingStep = phantomas.currentStep || '';
... | [
"function",
"pushContext",
"(",
"data",
")",
"{",
"// Some data is not needed on subchildren",
"if",
"(",
"depth",
"===",
"0",
")",
"{",
"data",
".",
"timestamp",
"=",
"Date",
".",
"now",
"(",
")",
"-",
"responseEndTime",
";",
"data",
".",
"loadingStep",
"="... | Add a child but don't enter its context | [
"Add",
"a",
"child",
"but",
"don",
"t",
"enter",
"its",
"context"
] | c59e9fc3f5d3db4e8f8952f154891ab3194d8f76 | https://github.com/gmetais/YellowLabTools/blob/c59e9fc3f5d3db4e8f8952f154891ab3194d8f76/lib/tools/phantomas/custom_modules/core/scopeYLT/scopeYLT.js#L112-L131 | train |
gmetais/YellowLabTools | lib/tools/phantomas/custom_modules/core/scopeYLT/scopeYLT.js | leaveContext | function leaveContext(moreData) {
// Some data is not needed on subchildren
if (depth === 1) {
currentContext.data.time = Date.now() - currentContext.data.timestamp - responseEndTime;
}
... | javascript | function leaveContext(moreData) {
// Some data is not needed on subchildren
if (depth === 1) {
currentContext.data.time = Date.now() - currentContext.data.timestamp - responseEndTime;
}
... | [
"function",
"leaveContext",
"(",
"moreData",
")",
"{",
"// Some data is not needed on subchildren",
"if",
"(",
"depth",
"===",
"1",
")",
"{",
"currentContext",
".",
"data",
".",
"time",
"=",
"Date",
".",
"now",
"(",
")",
"-",
"currentContext",
".",
"data",
"... | Save given data in the current context and jump change current context to its parent | [
"Save",
"given",
"data",
"in",
"the",
"current",
"context",
"and",
"jump",
"change",
"current",
"context",
"to",
"its",
"parent"
] | c59e9fc3f5d3db4e8f8952f154891ab3194d8f76 | https://github.com/gmetais/YellowLabTools/blob/c59e9fc3f5d3db4e8f8952f154891ab3194d8f76/lib/tools/phantomas/custom_modules/core/scopeYLT/scopeYLT.js#L158-L190 | train |
gmetais/YellowLabTools | lib/tools/phantomas/custom_modules/core/scopeYLT/scopeYLT.js | readFullTree | function readFullTree() {
// Return null if the contextTree is not correctly closed
if (root !== currentContext) {
return null;
}
function recusiveRead(node) {
if (nod... | javascript | function readFullTree() {
// Return null if the contextTree is not correctly closed
if (root !== currentContext) {
return null;
}
function recusiveRead(node) {
if (nod... | [
"function",
"readFullTree",
"(",
")",
"{",
"// Return null if the contextTree is not correctly closed",
"if",
"(",
"root",
"!==",
"currentContext",
")",
"{",
"return",
"null",
";",
"}",
"function",
"recusiveRead",
"(",
"node",
")",
"{",
"if",
"(",
"node",
".",
"... | Returns a clean object, without the parent which causes recursive loops | [
"Returns",
"a",
"clean",
"object",
"without",
"the",
"parent",
"which",
"causes",
"recursive",
"loops"
] | c59e9fc3f5d3db4e8f8952f154891ab3194d8f76 | https://github.com/gmetais/YellowLabTools/blob/c59e9fc3f5d3db4e8f8952f154891ab3194d8f76/lib/tools/phantomas/custom_modules/core/scopeYLT/scopeYLT.js#L197-L216 | train |
pocketjoso/penthouse | src/index.js | generateCriticalCssWrapped | async function generateCriticalCssWrapped (
options,
{ forceTryRestartBrowser } = {}
) {
const width = parseInt(options.width || DEFAULT_VIEWPORT_WIDTH, 10)
const height = parseInt(options.height || DEFAULT_VIEWPORT_HEIGHT, 10)
const timeoutWait = options.timeout || DEFAULT_TIMEOUT
// Merge properties with ... | javascript | async function generateCriticalCssWrapped (
options,
{ forceTryRestartBrowser } = {}
) {
const width = parseInt(options.width || DEFAULT_VIEWPORT_WIDTH, 10)
const height = parseInt(options.height || DEFAULT_VIEWPORT_HEIGHT, 10)
const timeoutWait = options.timeout || DEFAULT_TIMEOUT
// Merge properties with ... | [
"async",
"function",
"generateCriticalCssWrapped",
"(",
"options",
",",
"{",
"forceTryRestartBrowser",
"}",
"=",
"{",
"}",
")",
"{",
"const",
"width",
"=",
"parseInt",
"(",
"options",
".",
"width",
"||",
"DEFAULT_VIEWPORT_WIDTH",
",",
"10",
")",
"const",
"heig... | const so not hoisted, so can get regeneratorRuntime inlined above, needed for Node 4 | [
"const",
"so",
"not",
"hoisted",
"so",
"can",
"get",
"regeneratorRuntime",
"inlined",
"above",
"needed",
"for",
"Node",
"4"
] | a3b4701a31b60eb8080ab48eade94932b2fc2bf3 | https://github.com/pocketjoso/penthouse/blob/a3b4701a31b60eb8080ab48eade94932b2fc2bf3/src/index.js#L68-L186 | train |
pocketjoso/penthouse | examples/many-urls.js | startNewJob | function startNewJob () {
const url = urls.pop() // NOTE: mutates urls array
if (!url) {
// no more new jobs to process (might still be jobs currently in process)
return Promise.resolve()
}
return penthouse({
url,
...penthouseOptions
})
.then(criticalCss => {
// do something with you... | javascript | function startNewJob () {
const url = urls.pop() // NOTE: mutates urls array
if (!url) {
// no more new jobs to process (might still be jobs currently in process)
return Promise.resolve()
}
return penthouse({
url,
...penthouseOptions
})
.then(criticalCss => {
// do something with you... | [
"function",
"startNewJob",
"(",
")",
"{",
"const",
"url",
"=",
"urls",
".",
"pop",
"(",
")",
"// NOTE: mutates urls array",
"if",
"(",
"!",
"url",
")",
"{",
"// no more new jobs to process (might still be jobs currently in process)",
"return",
"Promise",
".",
"resolve... | recursively generates critical css for one url at the time, until all urls have been handled | [
"recursively",
"generates",
"critical",
"css",
"for",
"one",
"url",
"at",
"the",
"time",
"until",
"all",
"urls",
"have",
"been",
"handled"
] | a3b4701a31b60eb8080ab48eade94932b2fc2bf3 | https://github.com/pocketjoso/penthouse/blob/a3b4701a31b60eb8080ab48eade94932b2fc2bf3/examples/many-urls.js#L25-L40 | train |
dequelabs/axe-cli | index.js | function(url) {
if (silentMode) {
return;
}
console.log(
colors.bold('\nTesting ' + link(url)) +
' ... please wait, this may take a minute.'
);
if (program.timer) {
console.time('Total test time');
}
} | javascript | function(url) {
if (silentMode) {
return;
}
console.log(
colors.bold('\nTesting ' + link(url)) +
' ... please wait, this may take a minute.'
);
if (program.timer) {
console.time('Total test time');
}
} | [
"function",
"(",
"url",
")",
"{",
"if",
"(",
"silentMode",
")",
"{",
"return",
";",
"}",
"console",
".",
"log",
"(",
"colors",
".",
"bold",
"(",
"'\\nTesting '",
"+",
"link",
"(",
"url",
")",
")",
"+",
"' ... please wait, this may take a minute.'",
")",
... | Inform the user what page is tested | [
"Inform",
"the",
"user",
"what",
"page",
"is",
"tested"
] | 7ee59e99f6d351a098ac2cf25bc80ab4cdce8980 | https://github.com/dequelabs/axe-cli/blob/7ee59e99f6d351a098ac2cf25bc80ab4cdce8980/index.js#L136-L148 | train | |
dequelabs/axe-cli | index.js | logResults | function logResults(results) {
const { violations, testEngine, testEnvironment, testRunner } = results;
if (violations.length === 0) {
cliReporter(colors.green(' 0 violations found!'));
return;
}
const issueCount = violations.reduce((count, violation) => {
cliReporter(
'\n' +
error(' Viola... | javascript | function logResults(results) {
const { violations, testEngine, testEnvironment, testRunner } = results;
if (violations.length === 0) {
cliReporter(colors.green(' 0 violations found!'));
return;
}
const issueCount = violations.reduce((count, violation) => {
cliReporter(
'\n' +
error(' Viola... | [
"function",
"logResults",
"(",
"results",
")",
"{",
"const",
"{",
"violations",
",",
"testEngine",
",",
"testEnvironment",
",",
"testRunner",
"}",
"=",
"results",
";",
"if",
"(",
"violations",
".",
"length",
"===",
"0",
")",
"{",
"cliReporter",
"(",
"color... | Put the result in the console | [
"Put",
"the",
"result",
"in",
"the",
"console"
] | 7ee59e99f6d351a098ac2cf25bc80ab4cdce8980 | https://github.com/dequelabs/axe-cli/blob/7ee59e99f6d351a098ac2cf25bc80ab4cdce8980/index.js#L153-L192 | train |
janeasystems/nodejs-mobile-react-native | scripts/patch-package.js | patchPackageJSON_preNodeGyp_modulePath | function patchPackageJSON_preNodeGyp_modulePath(filePath)
{
let packageReadData = fs.readFileSync(filePath);
let packageJSON = JSON.parse(packageReadData);
if ( packageJSON && packageJSON.binary && packageJSON.binary.module_path ) {
let binaryPathConfiguration = packageJSON.binary.module_path;
binaryPathC... | javascript | function patchPackageJSON_preNodeGyp_modulePath(filePath)
{
let packageReadData = fs.readFileSync(filePath);
let packageJSON = JSON.parse(packageReadData);
if ( packageJSON && packageJSON.binary && packageJSON.binary.module_path ) {
let binaryPathConfiguration = packageJSON.binary.module_path;
binaryPathC... | [
"function",
"patchPackageJSON_preNodeGyp_modulePath",
"(",
"filePath",
")",
"{",
"let",
"packageReadData",
"=",
"fs",
".",
"readFileSync",
"(",
"filePath",
")",
";",
"let",
"packageJSON",
"=",
"JSON",
".",
"parse",
"(",
"packageReadData",
")",
";",
"if",
"(",
... | Patches a package.json in case it has variable substitution for the module's binary at runtime. Since we are cross-compiling for mobile, this substitution will have different values at build time and runtime, so we pre-substitute them with fixed values. | [
"Patches",
"a",
"package",
".",
"json",
"in",
"case",
"it",
"has",
"variable",
"substitution",
"for",
"the",
"module",
"s",
"binary",
"at",
"runtime",
".",
"Since",
"we",
"are",
"cross",
"-",
"compiling",
"for",
"mobile",
"this",
"substitution",
"will",
"h... | 1feb35d70cec536ae0980147a6b597bcbe5ba5eb | https://github.com/janeasystems/nodejs-mobile-react-native/blob/1feb35d70cec536ae0980147a6b597bcbe5ba5eb/scripts/patch-package.js#L9-L24 | train |
janeasystems/nodejs-mobile-react-native | scripts/patch-package.js | visitPackageJSON | function visitPackageJSON(folderPath)
{
let files = fs.readdirSync(folderPath);
for (var i in files) {
let name = files[i];
let filePath = path.join(folderPath, files[i]);
if(fs.statSync(filePath).isDirectory()) {
visitPackageJSON(filePath);
} else {
if (name === 'package.json') {
... | javascript | function visitPackageJSON(folderPath)
{
let files = fs.readdirSync(folderPath);
for (var i in files) {
let name = files[i];
let filePath = path.join(folderPath, files[i]);
if(fs.statSync(filePath).isDirectory()) {
visitPackageJSON(filePath);
} else {
if (name === 'package.json') {
... | [
"function",
"visitPackageJSON",
"(",
"folderPath",
")",
"{",
"let",
"files",
"=",
"fs",
".",
"readdirSync",
"(",
"folderPath",
")",
";",
"for",
"(",
"var",
"i",
"in",
"files",
")",
"{",
"let",
"name",
"=",
"files",
"[",
"i",
"]",
";",
"let",
"filePat... | Visits every package.json to apply patches. | [
"Visits",
"every",
"package",
".",
"json",
"to",
"apply",
"patches",
"."
] | 1feb35d70cec536ae0980147a6b597bcbe5ba5eb | https://github.com/janeasystems/nodejs-mobile-react-native/blob/1feb35d70cec536ae0980147a6b597bcbe5ba5eb/scripts/patch-package.js#L27-L50 | train |
janeasystems/nodejs-mobile-react-native | scripts/module-postlink.js | function(fileName)
{
var configurations = xcodeProject.pbxXCBuildConfigurationSection(),
INHERITED = '"$(inherited)"',
config, buildSettings, searchPaths;
var fileDir = path.dirname(fileName);
var filePos = '"\\"' + fileDir + '\\""';
for (config in configurations) {
... | javascript | function(fileName)
{
var configurations = xcodeProject.pbxXCBuildConfigurationSection(),
INHERITED = '"$(inherited)"',
config, buildSettings, searchPaths;
var fileDir = path.dirname(fileName);
var filePos = '"\\"' + fileDir + '\\""';
for (config in configurations) {
... | [
"function",
"(",
"fileName",
")",
"{",
"var",
"configurations",
"=",
"xcodeProject",
".",
"pbxXCBuildConfigurationSection",
"(",
")",
",",
"INHERITED",
"=",
"'\"$(inherited)\"'",
",",
"config",
",",
"buildSettings",
",",
"searchPaths",
";",
"var",
"fileDir",
"=",
... | Override addToFrameworkSearchPaths to add the framework path to all targets. The one provided in the xcode module adds the wrong path and not to the right target. | [
"Override",
"addToFrameworkSearchPaths",
"to",
"add",
"the",
"framework",
"path",
"to",
"all",
"targets",
".",
"The",
"one",
"provided",
"in",
"the",
"xcode",
"module",
"adds",
"the",
"wrong",
"path",
"and",
"not",
"to",
"the",
"right",
"target",
"."
] | 1feb35d70cec536ae0980147a6b597bcbe5ba5eb | https://github.com/janeasystems/nodejs-mobile-react-native/blob/1feb35d70cec536ae0980147a6b597bcbe5ba5eb/scripts/module-postlink.js#L120-L142 | train | |
hiddentao/squel | src/core.js | _extend | function _extend (dst, ...sources) {
if (dst && sources) {
for (let src of sources) {
if (typeof src === 'object') {
Object.getOwnPropertyNames(src).forEach(function (key) {
dst[key] = src[key];
});
}
}
}
return dst;
} | javascript | function _extend (dst, ...sources) {
if (dst && sources) {
for (let src of sources) {
if (typeof src === 'object') {
Object.getOwnPropertyNames(src).forEach(function (key) {
dst[key] = src[key];
});
}
}
}
return dst;
} | [
"function",
"_extend",
"(",
"dst",
",",
"...",
"sources",
")",
"{",
"if",
"(",
"dst",
"&&",
"sources",
")",
"{",
"for",
"(",
"let",
"src",
"of",
"sources",
")",
"{",
"if",
"(",
"typeof",
"src",
"===",
"'object'",
")",
"{",
"Object",
".",
"getOwnPro... | Extend given object's with other objects' properties, overriding existing ones if necessary | [
"Extend",
"given",
"object",
"s",
"with",
"other",
"objects",
"properties",
"overriding",
"existing",
"ones",
"if",
"necessary"
] | 8334ea2c83312961f12e9f45cf8b3cc8445482dc | https://github.com/hiddentao/squel/blob/8334ea2c83312961f12e9f45cf8b3cc8445482dc/src/core.js#L9-L21 | train |
hiddentao/squel | src/core.js | _clone | function _clone(src) {
if (!src) {
return src;
}
if (typeof src.clone === 'function') {
return src.clone();
} else if (_isPlainObject(src) || _isArray(src)) {
let ret = new (src.constructor);
Object.getOwnPropertyNames(src).forEach(function(key) {
if (typeof src[key] !== 'function') {
... | javascript | function _clone(src) {
if (!src) {
return src;
}
if (typeof src.clone === 'function') {
return src.clone();
} else if (_isPlainObject(src) || _isArray(src)) {
let ret = new (src.constructor);
Object.getOwnPropertyNames(src).forEach(function(key) {
if (typeof src[key] !== 'function') {
... | [
"function",
"_clone",
"(",
"src",
")",
"{",
"if",
"(",
"!",
"src",
")",
"{",
"return",
"src",
";",
"}",
"if",
"(",
"typeof",
"src",
".",
"clone",
"===",
"'function'",
")",
"{",
"return",
"src",
".",
"clone",
"(",
")",
";",
"}",
"else",
"if",
"(... | clone given item | [
"clone",
"given",
"item"
] | 8334ea2c83312961f12e9f45cf8b3cc8445482dc | https://github.com/hiddentao/squel/blob/8334ea2c83312961f12e9f45cf8b3cc8445482dc/src/core.js#L39-L59 | train |
hiddentao/squel | src/core.js | registerValueHandler | function registerValueHandler (handlers, type, handler) {
let typeofType = typeof type;
if (typeofType !== 'function' && typeofType !== 'string') {
throw new Error("type must be a class constructor or string");
}
if (typeof handler !== 'function') {
throw new Error("handler must be a function");
}
... | javascript | function registerValueHandler (handlers, type, handler) {
let typeofType = typeof type;
if (typeofType !== 'function' && typeofType !== 'string') {
throw new Error("type must be a class constructor or string");
}
if (typeof handler !== 'function') {
throw new Error("handler must be a function");
}
... | [
"function",
"registerValueHandler",
"(",
"handlers",
",",
"type",
",",
"handler",
")",
"{",
"let",
"typeofType",
"=",
"typeof",
"type",
";",
"if",
"(",
"typeofType",
"!==",
"'function'",
"&&",
"typeofType",
"!==",
"'string'",
")",
"{",
"throw",
"new",
"Error... | Register a value type handler
Note: this will override any existing handler registered for this value type. | [
"Register",
"a",
"value",
"type",
"handler"
] | 8334ea2c83312961f12e9f45cf8b3cc8445482dc | https://github.com/hiddentao/squel/blob/8334ea2c83312961f12e9f45cf8b3cc8445482dc/src/core.js#L67-L90 | train |
hiddentao/squel | src/core.js | getValueHandler | function getValueHandler (value, localHandlers, globalHandlers) {
return _getValueHandler(value, localHandlers) || _getValueHandler(value, globalHandlers);
} | javascript | function getValueHandler (value, localHandlers, globalHandlers) {
return _getValueHandler(value, localHandlers) || _getValueHandler(value, globalHandlers);
} | [
"function",
"getValueHandler",
"(",
"value",
",",
"localHandlers",
",",
"globalHandlers",
")",
"{",
"return",
"_getValueHandler",
"(",
"value",
",",
"localHandlers",
")",
"||",
"_getValueHandler",
"(",
"value",
",",
"globalHandlers",
")",
";",
"}"
] | Get value type handler for given type | [
"Get",
"value",
"type",
"handler",
"for",
"given",
"type"
] | 8334ea2c83312961f12e9f45cf8b3cc8445482dc | https://github.com/hiddentao/squel/blob/8334ea2c83312961f12e9f45cf8b3cc8445482dc/src/core.js#L98-L100 | train |
nicgirault/circosJS | src/layout/render.js | blockTicks | function blockTicks (d) {
const k = (d.end - d.start) / d.len
return range(0, d.len, conf.ticks.spacing).map((v, i) => {
return {
angle: v * k + d.start,
label: displayLabel(v, i)
}
})
} | javascript | function blockTicks (d) {
const k = (d.end - d.start) / d.len
return range(0, d.len, conf.ticks.spacing).map((v, i) => {
return {
angle: v * k + d.start,
label: displayLabel(v, i)
}
})
} | [
"function",
"blockTicks",
"(",
"d",
")",
"{",
"const",
"k",
"=",
"(",
"d",
".",
"end",
"-",
"d",
".",
"start",
")",
"/",
"d",
".",
"len",
"return",
"range",
"(",
"0",
",",
"d",
".",
"len",
",",
"conf",
".",
"ticks",
".",
"spacing",
")",
".",
... | Returns an array of tick angles and labels, given a block. | [
"Returns",
"an",
"array",
"of",
"tick",
"angles",
"and",
"labels",
"given",
"a",
"block",
"."
] | ff9106b39876c98126e894da07c03a7eb90d2356 | https://github.com/nicgirault/circosJS/blob/ff9106b39876c98126e894da07c03a7eb90d2356/src/layout/render.js#L34-L42 | train |
anvaka/ngraph.path | a-star/nba/index.js | forwardSearch | function forwardSearch() {
cameFrom = open1Set.pop();
if (cameFrom.closed) {
return;
}
cameFrom.closed = true;
if (cameFrom.f1 < lMin && (cameFrom.g1 + f2 - heuristic(from, cameFrom.node)) < lMin) {
graph.forEachLinkedNode(cameFrom.node.id, forwardVisitor);
}
... | javascript | function forwardSearch() {
cameFrom = open1Set.pop();
if (cameFrom.closed) {
return;
}
cameFrom.closed = true;
if (cameFrom.f1 < lMin && (cameFrom.g1 + f2 - heuristic(from, cameFrom.node)) < lMin) {
graph.forEachLinkedNode(cameFrom.node.id, forwardVisitor);
}
... | [
"function",
"forwardSearch",
"(",
")",
"{",
"cameFrom",
"=",
"open1Set",
".",
"pop",
"(",
")",
";",
"if",
"(",
"cameFrom",
".",
"closed",
")",
"{",
"return",
";",
"}",
"cameFrom",
".",
"closed",
"=",
"true",
";",
"if",
"(",
"cameFrom",
".",
"f1",
"... | the public API is over | [
"the",
"public",
"API",
"is",
"over"
] | 6798fc9818d17bc04fdffaa3cedcf55dac2090ca | https://github.com/anvaka/ngraph.path/blob/6798fc9818d17bc04fdffaa3cedcf55dac2090ca/a-star/nba/index.js#L137-L153 | train |
primus/primus | middleware/xss.js | xss | function xss(req, res) {
var agent = (req.headers['user-agent'] || '').toLowerCase();
if (agent && (~agent.indexOf(';msie') || ~agent.indexOf('trident/'))) {
setHeader(res, 'X-XSS-Protection', '0');
}
} | javascript | function xss(req, res) {
var agent = (req.headers['user-agent'] || '').toLowerCase();
if (agent && (~agent.indexOf(';msie') || ~agent.indexOf('trident/'))) {
setHeader(res, 'X-XSS-Protection', '0');
}
} | [
"function",
"xss",
"(",
"req",
",",
"res",
")",
"{",
"var",
"agent",
"=",
"(",
"req",
".",
"headers",
"[",
"'user-agent'",
"]",
"||",
"''",
")",
".",
"toLowerCase",
"(",
")",
";",
"if",
"(",
"agent",
"&&",
"(",
"~",
"agent",
".",
"indexOf",
"(",
... | Forcefully add x-xss-protection headers.
@param {Request} req The incoming HTTP request.
@param {Response} res The outgoing HTTP response.
@api public | [
"Forcefully",
"add",
"x",
"-",
"xss",
"-",
"protection",
"headers",
"."
] | 7d58d8ebeeed89d7f759ff6c5dfe026deba9666e | https://github.com/primus/primus/blob/7d58d8ebeeed89d7f759ff6c5dfe026deba9666e/middleware/xss.js#L12-L18 | train |
primus/primus | primus.js | context | function context(self, method) {
if (self instanceof Primus) return;
var failure = new Error('Primus#'+ method + '\'s context should called with a Primus instance');
if ('function' !== typeof self.listeners || !self.listeners('error').length) {
throw failure;
}
self.emit('error', failure);
} | javascript | function context(self, method) {
if (self instanceof Primus) return;
var failure = new Error('Primus#'+ method + '\'s context should called with a Primus instance');
if ('function' !== typeof self.listeners || !self.listeners('error').length) {
throw failure;
}
self.emit('error', failure);
} | [
"function",
"context",
"(",
"self",
",",
"method",
")",
"{",
"if",
"(",
"self",
"instanceof",
"Primus",
")",
"return",
";",
"var",
"failure",
"=",
"new",
"Error",
"(",
"'Primus#'",
"+",
"method",
"+",
"'\\'s context should called with a Primus instance'",
")",
... | Context assertion, ensure that some of our public Primus methods are called
with the correct context to ensure that
@param {Primus} self The context of the function.
@param {String} method The method name.
@api private | [
"Context",
"assertion",
"ensure",
"that",
"some",
"of",
"our",
"public",
"Primus",
"methods",
"are",
"called",
"with",
"the",
"correct",
"context",
"to",
"ensure",
"that"
] | 7d58d8ebeeed89d7f759ff6c5dfe026deba9666e | https://github.com/primus/primus/blob/7d58d8ebeeed89d7f759ff6c5dfe026deba9666e/primus.js#L22-L32 | train |
primus/primus | primus.js | remove | function remove() {
primus.removeListener('error', remove)
.removeListener('open', remove)
.removeListener('end', remove)
.timers.clear('connect');
} | javascript | function remove() {
primus.removeListener('error', remove)
.removeListener('open', remove)
.removeListener('end', remove)
.timers.clear('connect');
} | [
"function",
"remove",
"(",
")",
"{",
"primus",
".",
"removeListener",
"(",
"'error'",
",",
"remove",
")",
".",
"removeListener",
"(",
"'open'",
",",
"remove",
")",
".",
"removeListener",
"(",
"'end'",
",",
"remove",
")",
".",
"timers",
".",
"clear",
"(",... | Remove all references to the timeout listener as we've received an event
that can be used to determine state.
@api private | [
"Remove",
"all",
"references",
"to",
"the",
"timeout",
"listener",
"as",
"we",
"ve",
"received",
"an",
"event",
"that",
"can",
"be",
"used",
"to",
"determine",
"state",
"."
] | 7d58d8ebeeed89d7f759ff6c5dfe026deba9666e | https://github.com/primus/primus/blob/7d58d8ebeeed89d7f759ff6c5dfe026deba9666e/primus.js#L860-L865 | train |
primus/primus | examples/middleware/session.js | session | function session(req, res, next) {
//
// The session id is stored in the cookies.
// `req.signedCookies` is assigned by the `cookie-parser` middleware.
//
var sid = req.signedCookies[key];
//
// Default to an empty session.
//
req.session = {};
//
// If we don't have a sess... | javascript | function session(req, res, next) {
//
// The session id is stored in the cookies.
// `req.signedCookies` is assigned by the `cookie-parser` middleware.
//
var sid = req.signedCookies[key];
//
// Default to an empty session.
//
req.session = {};
//
// If we don't have a sess... | [
"function",
"session",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"//",
"// The session id is stored in the cookies.",
"// `req.signedCookies` is assigned by the `cookie-parser` middleware.",
"//",
"var",
"sid",
"=",
"req",
".",
"signedCookies",
"[",
"key",
"]",
";"... | The actual session middleware. This middleware is async so we need 3 arguments. | [
"The",
"actual",
"session",
"middleware",
".",
"This",
"middleware",
"is",
"async",
"so",
"we",
"need",
"3",
"arguments",
"."
] | 7d58d8ebeeed89d7f759ff6c5dfe026deba9666e | https://github.com/primus/primus/blob/7d58d8ebeeed89d7f759ff6c5dfe026deba9666e/examples/middleware/session.js#L26-L60 | train |
primus/primus | spark.js | Spark | function Spark(primus, headers, address, query, id, request, socket) {
this.fuse();
var writable = this.writable
, spark = this
, idgen = primus.options.idGenerator;
query = query || {};
id = idgen ? idgen() : (id || nanoid());
headers = headers || {};
address = address || {};
request = request ... | javascript | function Spark(primus, headers, address, query, id, request, socket) {
this.fuse();
var writable = this.writable
, spark = this
, idgen = primus.options.idGenerator;
query = query || {};
id = idgen ? idgen() : (id || nanoid());
headers = headers || {};
address = address || {};
request = request ... | [
"function",
"Spark",
"(",
"primus",
",",
"headers",
",",
"address",
",",
"query",
",",
"id",
",",
"request",
",",
"socket",
")",
"{",
"this",
".",
"fuse",
"(",
")",
";",
"var",
"writable",
"=",
"this",
".",
"writable",
",",
"spark",
"=",
"this",
",... | The Spark is an indefinable, indescribable energy or soul of a transformer
which can be used to create new transformers. In our case, it's a simple
wrapping interface.
@constructor
@param {Primus} primus Reference to the Primus server. (Set using .bind)
@param {Object} headers The request headers for this connection.
... | [
"The",
"Spark",
"is",
"an",
"indefinable",
"indescribable",
"energy",
"or",
"soul",
"of",
"a",
"transformer",
"which",
"can",
"be",
"used",
"to",
"create",
"new",
"transformers",
".",
"In",
"our",
"case",
"it",
"s",
"a",
"simple",
"wrapping",
"interface",
... | 7d58d8ebeeed89d7f759ff6c5dfe026deba9666e | https://github.com/primus/primus/blob/7d58d8ebeeed89d7f759ff6c5dfe026deba9666e/spark.js#L28-L64 | train |
primus/primus | transformers/sockjs/library.js | resolve | function resolve(relative, base) {
var path = (base || '/').split('/').slice(0, -1).concat(relative.split('/'))
, i = path.length
, last = path[i - 1]
, unshift = false
, up = 0;
while (i--) {
if (path[i] === '.') {
path.splice(i, 1);
} else if (path[i] === '..') {
path.splice(i... | javascript | function resolve(relative, base) {
var path = (base || '/').split('/').slice(0, -1).concat(relative.split('/'))
, i = path.length
, last = path[i - 1]
, unshift = false
, up = 0;
while (i--) {
if (path[i] === '.') {
path.splice(i, 1);
} else if (path[i] === '..') {
path.splice(i... | [
"function",
"resolve",
"(",
"relative",
",",
"base",
")",
"{",
"var",
"path",
"=",
"(",
"base",
"||",
"'/'",
")",
".",
"split",
"(",
"'/'",
")",
".",
"slice",
"(",
"0",
",",
"-",
"1",
")",
".",
"concat",
"(",
"relative",
".",
"split",
"(",
"'/'... | Resolve a relative URL pathname against a base URL pathname.
@param {String} relative Pathname of the relative URL.
@param {String} base Pathname of the base URL.
@return {String} Resolved pathname.
@private | [
"Resolve",
"a",
"relative",
"URL",
"pathname",
"against",
"a",
"base",
"URL",
"pathname",
"."
] | 7d58d8ebeeed89d7f759ff6c5dfe026deba9666e | https://github.com/primus/primus/blob/7d58d8ebeeed89d7f759ff6c5dfe026deba9666e/transformers/sockjs/library.js#L4571-L4595 | train |
primus/primus | transformers/sockjs/library.js | set | function set(part, value, fn) {
var url = this;
switch (part) {
case 'query':
if ('string' === typeof value && value.length) {
value = (fn || qs.parse)(value);
}
url[part] = value;
break;
case 'port':
url[part] = value;
if (!required(value, url.protocol)) {
... | javascript | function set(part, value, fn) {
var url = this;
switch (part) {
case 'query':
if ('string' === typeof value && value.length) {
value = (fn || qs.parse)(value);
}
url[part] = value;
break;
case 'port':
url[part] = value;
if (!required(value, url.protocol)) {
... | [
"function",
"set",
"(",
"part",
",",
"value",
",",
"fn",
")",
"{",
"var",
"url",
"=",
"this",
";",
"switch",
"(",
"part",
")",
"{",
"case",
"'query'",
":",
"if",
"(",
"'string'",
"===",
"typeof",
"value",
"&&",
"value",
".",
"length",
")",
"{",
"... | This is convenience method for changing properties in the URL instance to
insure that they all propagate correctly.
@param {String} part Property we need to adjust.
@param {Mixed} value The newly assigned value.
@param {Boolean|Function} fn When setting the query, it will be the function
used to par... | [
"This",
"is",
"convenience",
"method",
"for",
"changing",
"properties",
"in",
"the",
"URL",
"instance",
"to",
"insure",
"that",
"they",
"all",
"propagate",
"correctly",
"."
] | 7d58d8ebeeed89d7f759ff6c5dfe026deba9666e | https://github.com/primus/primus/blob/7d58d8ebeeed89d7f759ff6c5dfe026deba9666e/transformers/sockjs/library.js#L4758-L4835 | train |
primus/primus | errors.js | PrimusError | function PrimusError(message, logger) {
Error.captureStackTrace(this, this.constructor);
this.message = message;
this.name = this.constructor.name;
if (logger) {
logger.emit('log', 'error', this);
}
} | javascript | function PrimusError(message, logger) {
Error.captureStackTrace(this, this.constructor);
this.message = message;
this.name = this.constructor.name;
if (logger) {
logger.emit('log', 'error', this);
}
} | [
"function",
"PrimusError",
"(",
"message",
",",
"logger",
")",
"{",
"Error",
".",
"captureStackTrace",
"(",
"this",
",",
"this",
".",
"constructor",
")",
";",
"this",
".",
"message",
"=",
"message",
";",
"this",
".",
"name",
"=",
"this",
".",
"constructo... | Generic Primus error.
@constructor
@param {String} message The reason for the error
@param {EventEmitter} logger Optional EventEmitter to emit a `log` event on.
@api public | [
"Generic",
"Primus",
"error",
"."
] | 7d58d8ebeeed89d7f759ff6c5dfe026deba9666e | https://github.com/primus/primus/blob/7d58d8ebeeed89d7f759ff6c5dfe026deba9666e/errors.js#L13-L22 | train |
primus/primus | errors.js | ParserError | function ParserError(message, spark) {
Error.captureStackTrace(this, this.constructor);
this.message = message;
this.name = this.constructor.name;
if (spark) {
if (spark.listeners('error').length) spark.emit('error', this);
spark.primus.emit('log', 'error', this);
}
} | javascript | function ParserError(message, spark) {
Error.captureStackTrace(this, this.constructor);
this.message = message;
this.name = this.constructor.name;
if (spark) {
if (spark.listeners('error').length) spark.emit('error', this);
spark.primus.emit('log', 'error', this);
}
} | [
"function",
"ParserError",
"(",
"message",
",",
"spark",
")",
"{",
"Error",
".",
"captureStackTrace",
"(",
"this",
",",
"this",
".",
"constructor",
")",
";",
"this",
".",
"message",
"=",
"message",
";",
"this",
".",
"name",
"=",
"this",
".",
"constructor... | There was an error while parsing incoming or outgoing data.
@param {String} message The reason for the error.
@param {Spark} spark The spark that caused the error.
@api public | [
"There",
"was",
"an",
"error",
"while",
"parsing",
"incoming",
"or",
"outgoing",
"data",
"."
] | 7d58d8ebeeed89d7f759ff6c5dfe026deba9666e | https://github.com/primus/primus/blob/7d58d8ebeeed89d7f759ff6c5dfe026deba9666e/errors.js#L33-L43 | train |
primus/primus | transformers/engine.io/library.js | encodeArrayBuffer | function encodeArrayBuffer(packet, supportsBinary, callback) {
if (!supportsBinary) {
return exports.encodeBase64Packet(packet, callback);
}
var data = packet.data;
var contentArray = new Uint8Array(data);
var resultBuffer = new Uint8Array(1 + data.byteLength);
resultBuffer[0] = packets[packet.type];
... | javascript | function encodeArrayBuffer(packet, supportsBinary, callback) {
if (!supportsBinary) {
return exports.encodeBase64Packet(packet, callback);
}
var data = packet.data;
var contentArray = new Uint8Array(data);
var resultBuffer = new Uint8Array(1 + data.byteLength);
resultBuffer[0] = packets[packet.type];
... | [
"function",
"encodeArrayBuffer",
"(",
"packet",
",",
"supportsBinary",
",",
"callback",
")",
"{",
"if",
"(",
"!",
"supportsBinary",
")",
"{",
"return",
"exports",
".",
"encodeBase64Packet",
"(",
"packet",
",",
"callback",
")",
";",
"}",
"var",
"data",
"=",
... | Encode packet helpers for binary types | [
"Encode",
"packet",
"helpers",
"for",
"binary",
"types"
] | 7d58d8ebeeed89d7f759ff6c5dfe026deba9666e | https://github.com/primus/primus/blob/7d58d8ebeeed89d7f759ff6c5dfe026deba9666e/transformers/engine.io/library.js#L2616-L2631 | train |
primus/primus | transformers/engine.io/library.js | encode | function encode(num) {
var encoded = '';
do {
encoded = alphabet[num % length] + encoded;
num = Math.floor(num / length);
} while (num > 0);
return encoded;
} | javascript | function encode(num) {
var encoded = '';
do {
encoded = alphabet[num % length] + encoded;
num = Math.floor(num / length);
} while (num > 0);
return encoded;
} | [
"function",
"encode",
"(",
"num",
")",
"{",
"var",
"encoded",
"=",
"''",
";",
"do",
"{",
"encoded",
"=",
"alphabet",
"[",
"num",
"%",
"length",
"]",
"+",
"encoded",
";",
"num",
"=",
"Math",
".",
"floor",
"(",
"num",
"/",
"length",
")",
";",
"}",
... | Return a string representing the specified number.
@param {Number} num The number to convert.
@returns {String} The string representation of the number.
@api public | [
"Return",
"a",
"string",
"representing",
"the",
"specified",
"number",
"."
] | 7d58d8ebeeed89d7f759ff6c5dfe026deba9666e | https://github.com/primus/primus/blob/7d58d8ebeeed89d7f759ff6c5dfe026deba9666e/transformers/engine.io/library.js#L3623-L3632 | train |
primus/primus | transformers/engine.io/library.js | decode | function decode(str) {
var decoded = 0;
for (i = 0; i < str.length; i++) {
decoded = decoded * length + map[str.charAt(i)];
}
return decoded;
} | javascript | function decode(str) {
var decoded = 0;
for (i = 0; i < str.length; i++) {
decoded = decoded * length + map[str.charAt(i)];
}
return decoded;
} | [
"function",
"decode",
"(",
"str",
")",
"{",
"var",
"decoded",
"=",
"0",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"str",
".",
"length",
";",
"i",
"++",
")",
"{",
"decoded",
"=",
"decoded",
"*",
"length",
"+",
"map",
"[",
"str",
".",
"cha... | Return the integer value specified by the given string.
@param {String} str The string to convert.
@returns {Number} The integer value represented by the string.
@api public | [
"Return",
"the",
"integer",
"value",
"specified",
"by",
"the",
"given",
"string",
"."
] | 7d58d8ebeeed89d7f759ff6c5dfe026deba9666e | https://github.com/primus/primus/blob/7d58d8ebeeed89d7f759ff6c5dfe026deba9666e/transformers/engine.io/library.js#L3641-L3649 | train |
primus/primus | transformers/sockjs/update_tools/stripify.js | stripify | function stripify(file) {
if (/\.json$/.test(file)) return through();
var code = '';
function transform(chunk, encoding, next) {
code += chunk;
next();
}
function flush(done) {
/* jshint validthis: true */
var ast = rocambole.parse(code);
code = rocambole.moonwalk(ast, function strip(n... | javascript | function stripify(file) {
if (/\.json$/.test(file)) return through();
var code = '';
function transform(chunk, encoding, next) {
code += chunk;
next();
}
function flush(done) {
/* jshint validthis: true */
var ast = rocambole.parse(code);
code = rocambole.moonwalk(ast, function strip(n... | [
"function",
"stripify",
"(",
"file",
")",
"{",
"if",
"(",
"/",
"\\.json$",
"/",
".",
"test",
"(",
"file",
")",
")",
"return",
"through",
"(",
")",
";",
"var",
"code",
"=",
"''",
";",
"function",
"transform",
"(",
"chunk",
",",
"encoding",
",",
"nex... | Browserify transform to remove all debug statements.
@param {String} file File name
@returns {Stream} Transform stream
@api public | [
"Browserify",
"transform",
"to",
"remove",
"all",
"debug",
"statements",
"."
] | 7d58d8ebeeed89d7f759ff6c5dfe026deba9666e | https://github.com/primus/primus/blob/7d58d8ebeeed89d7f759ff6c5dfe026deba9666e/transformers/sockjs/update_tools/stripify.js#L19-L55 | train |
primus/primus | middleware/spec.js | spec | function spec(req, res) {
if (req.uri.pathname !== specification) return;
res.statusCode = 200;
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(primus.spec));
return true;
} | javascript | function spec(req, res) {
if (req.uri.pathname !== specification) return;
res.statusCode = 200;
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(primus.spec));
return true;
} | [
"function",
"spec",
"(",
"req",
",",
"res",
")",
"{",
"if",
"(",
"req",
".",
"uri",
".",
"pathname",
"!==",
"specification",
")",
"return",
";",
"res",
".",
"statusCode",
"=",
"200",
";",
"res",
".",
"setHeader",
"(",
"'Content-Type'",
",",
"'applicati... | The actual HTTP middleware.
@param {Request} req HTTP request.
@param {Response} res HTTP response.
@api private | [
"The",
"actual",
"HTTP",
"middleware",
"."
] | 7d58d8ebeeed89d7f759ff6c5dfe026deba9666e | https://github.com/primus/primus/blob/7d58d8ebeeed89d7f759ff6c5dfe026deba9666e/middleware/spec.js#L20-L28 | train |
yeojz/otplib | packages/otplib-utils/padSecret.js | padSecret | function padSecret(secretBuffer, size, encoding) {
const secret = secretBuffer.toString(encoding);
const len = secret.length;
if (size && len < size) {
const newSecret = new Array(size - len + 1).join(
secretBuffer.toString('hex')
);
return Buffer.from(newSecret, 'hex').slice(0, size);
}
r... | javascript | function padSecret(secretBuffer, size, encoding) {
const secret = secretBuffer.toString(encoding);
const len = secret.length;
if (size && len < size) {
const newSecret = new Array(size - len + 1).join(
secretBuffer.toString('hex')
);
return Buffer.from(newSecret, 'hex').slice(0, size);
}
r... | [
"function",
"padSecret",
"(",
"secretBuffer",
",",
"size",
",",
"encoding",
")",
"{",
"const",
"secret",
"=",
"secretBuffer",
".",
"toString",
"(",
"encoding",
")",
";",
"const",
"len",
"=",
"secret",
".",
"length",
";",
"if",
"(",
"size",
"&&",
"len",
... | Padding of secret to a certain buffer size.
@module otplib-utils/padSecret
@param {Buffer} secretBuffer - a buffer representation of your secret.
@param {number} size - number of bytes your secret should be.
@param {string} encoding - the encoding of secret
@return {Buffer} | [
"Padding",
"of",
"secret",
"to",
"a",
"certain",
"buffer",
"size",
"."
] | f81a4f11d63b3f00545c60bcef6543cdec2ddc0e | https://github.com/yeojz/otplib/blob/f81a4f11d63b3f00545c60bcef6543cdec2ddc0e/packages/otplib-utils/padSecret.js#L10-L22 | train |
yeojz/otplib | examples/cli.js | getCommandLineOptions | function getCommandLineOptions() {
return process.argv
.slice(2)
.map(arg => arg.split('='))
.reduce((accum, arg) => {
const key = arg[0].replace('--', '');
// if secret, do not put in config
if (key === 'secret') {
secret = arg[1];
return accum;
}
// If pro... | javascript | function getCommandLineOptions() {
return process.argv
.slice(2)
.map(arg => arg.split('='))
.reduce((accum, arg) => {
const key = arg[0].replace('--', '');
// if secret, do not put in config
if (key === 'secret') {
secret = arg[1];
return accum;
}
// If pro... | [
"function",
"getCommandLineOptions",
"(",
")",
"{",
"return",
"process",
".",
"argv",
".",
"slice",
"(",
"2",
")",
".",
"map",
"(",
"arg",
"=>",
"arg",
".",
"split",
"(",
"'='",
")",
")",
".",
"reduce",
"(",
"(",
"accum",
",",
"arg",
")",
"=>",
"... | Parse and prepare CLI values | [
"Parse",
"and",
"prepare",
"CLI",
"values"
] | f81a4f11d63b3f00545c60bcef6543cdec2ddc0e | https://github.com/yeojz/otplib/blob/f81a4f11d63b3f00545c60bcef6543cdec2ddc0e/examples/cli.js#L20-L47 | train |
yeojz/otplib | packages/otplib-core/totpCheckWithWindow.js | totpCheckWithWindow | function totpCheckWithWindow(token, secret, options) {
let opt = Object.assign({}, options);
const bounds = getWindowBounds(opt);
const checker = createChecker(token, secret, opt);
const backward = checker(-1, 0, bounds[0]);
return backward !== null ? backward : checker(1, 1, bounds[1]);
} | javascript | function totpCheckWithWindow(token, secret, options) {
let opt = Object.assign({}, options);
const bounds = getWindowBounds(opt);
const checker = createChecker(token, secret, opt);
const backward = checker(-1, 0, bounds[0]);
return backward !== null ? backward : checker(1, 1, bounds[1]);
} | [
"function",
"totpCheckWithWindow",
"(",
"token",
",",
"secret",
",",
"options",
")",
"{",
"let",
"opt",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"options",
")",
";",
"const",
"bounds",
"=",
"getWindowBounds",
"(",
"opt",
")",
";",
"const",
"ch... | Checks the provided OTP token against system generated token
with support for checking previous or future x time-step windows
@module otplib-core/totpCheckWithWindow
@param {string} token - the OTP token to check
@param {string} secret - your secret that is used to generate the token
@param {object} options - options ... | [
"Checks",
"the",
"provided",
"OTP",
"token",
"against",
"system",
"generated",
"token",
"with",
"support",
"for",
"checking",
"previous",
"or",
"future",
"x",
"time",
"-",
"step",
"windows"
] | f81a4f11d63b3f00545c60bcef6543cdec2ddc0e | https://github.com/yeojz/otplib/blob/f81a4f11d63b3f00545c60bcef6543cdec2ddc0e/packages/otplib-core/totpCheckWithWindow.js#L43-L50 | train |
yeojz/otplib | packages/otplib-utils/secretKey.js | secretKey | function secretKey(length, options = {}) {
if (!length || length < 1) {
return '';
}
if (!options.crypto || typeof options.crypto.randomBytes !== 'function') {
throw new Error('Expecting options.crypto to have a randomBytes function');
}
return options.crypto
.randomBytes(length)
.toString('... | javascript | function secretKey(length, options = {}) {
if (!length || length < 1) {
return '';
}
if (!options.crypto || typeof options.crypto.randomBytes !== 'function') {
throw new Error('Expecting options.crypto to have a randomBytes function');
}
return options.crypto
.randomBytes(length)
.toString('... | [
"function",
"secretKey",
"(",
"length",
",",
"options",
"=",
"{",
"}",
")",
"{",
"if",
"(",
"!",
"length",
"||",
"length",
"<",
"1",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"!",
"options",
".",
"crypto",
"||",
"typeof",
"options",
".",
"cr... | Naive secret key generation tool
@module otplib-utils/secretKey
@param {integer} length - the key length
@param {string} format - any format supported by node's `crypto`
@return {string} | [
"Naive",
"secret",
"key",
"generation",
"tool"
] | f81a4f11d63b3f00545c60bcef6543cdec2ddc0e | https://github.com/yeojz/otplib/blob/f81a4f11d63b3f00545c60bcef6543cdec2ddc0e/packages/otplib-utils/secretKey.js#L10-L23 | train |
yeojz/otplib | packages/otplib-core/hotpSecret.js | hotpSecret | function hotpSecret(secret, options) {
if (typeof options.encoding !== 'string') {
throw new Error('Expecting options.encoding to be a string');
}
return Buffer.from(secret, options.encoding);
} | javascript | function hotpSecret(secret, options) {
if (typeof options.encoding !== 'string') {
throw new Error('Expecting options.encoding to be a string');
}
return Buffer.from(secret, options.encoding);
} | [
"function",
"hotpSecret",
"(",
"secret",
",",
"options",
")",
"{",
"if",
"(",
"typeof",
"options",
".",
"encoding",
"!==",
"'string'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Expecting options.encoding to be a string'",
")",
";",
"}",
"return",
"Buffer",
"."... | Conversion of secret to buffer for HOTP
@module otplib-core/hotpSecret
@param {string} secret - your secret that is used to generate the token
@param {string} options.encoding - the encoding of secret
@return {object} | [
"Conversion",
"of",
"secret",
"to",
"buffer",
"for",
"HOTP"
] | f81a4f11d63b3f00545c60bcef6543cdec2ddc0e | https://github.com/yeojz/otplib/blob/f81a4f11d63b3f00545c60bcef6543cdec2ddc0e/packages/otplib-core/hotpSecret.js#L9-L15 | train |
yeojz/otplib | packages/otplib-utils/isSameToken.js | isSameToken | function isSameToken(token1, token2) {
if (isValidToken(token1) && isValidToken(token2)) {
return String(token1) === String(token2);
}
return false;
} | javascript | function isSameToken(token1, token2) {
if (isValidToken(token1) && isValidToken(token2)) {
return String(token1) === String(token2);
}
return false;
} | [
"function",
"isSameToken",
"(",
"token1",
",",
"token2",
")",
"{",
"if",
"(",
"isValidToken",
"(",
"token1",
")",
"&&",
"isValidToken",
"(",
"token2",
")",
")",
"{",
"return",
"String",
"(",
"token1",
")",
"===",
"String",
"(",
"token2",
")",
";",
"}",... | Simple comparison of 2 tokens
@module otplib-utils/isSameToken
@param {string | number} token1 - base value
@param {string | number} token2 - value to compare
@return {boolean} | [
"Simple",
"comparison",
"of",
"2",
"tokens"
] | f81a4f11d63b3f00545c60bcef6543cdec2ddc0e | https://github.com/yeojz/otplib/blob/f81a4f11d63b3f00545c60bcef6543cdec2ddc0e/packages/otplib-utils/isSameToken.js#L13-L19 | train |
yeojz/otplib | packages/otplib-core/hotpOptions.js | hotpOptions | function hotpOptions(options = {}) {
return Object.assign(
{
algorithm: 'sha1',
createHmacSecret: hotpSecret,
crypto: null,
digits: 6,
encoding: 'ascii'
},
options
);
} | javascript | function hotpOptions(options = {}) {
return Object.assign(
{
algorithm: 'sha1',
createHmacSecret: hotpSecret,
crypto: null,
digits: 6,
encoding: 'ascii'
},
options
);
} | [
"function",
"hotpOptions",
"(",
"options",
"=",
"{",
"}",
")",
"{",
"return",
"Object",
".",
"assign",
"(",
"{",
"algorithm",
":",
"'sha1'",
",",
"createHmacSecret",
":",
"hotpSecret",
",",
"crypto",
":",
"null",
",",
"digits",
":",
"6",
",",
"encoding",... | Generates options for HOTP
@module otplib-core/hotpOptions
@param {number} options.digits - the output token length
@param {string} options.encoding - the encoding of secret
@return {object} | [
"Generates",
"options",
"for",
"HOTP"
] | f81a4f11d63b3f00545c60bcef6543cdec2ddc0e | https://github.com/yeojz/otplib/blob/f81a4f11d63b3f00545c60bcef6543cdec2ddc0e/packages/otplib-core/hotpOptions.js#L11-L22 | train |
yeojz/otplib | packages/otplib-core/totpOptions.js | totpOptions | function totpOptions(options = {}) {
let opt = Object.assign(hotpOptions(), defaultOptions, options);
opt.epoch = typeof opt.epoch === 'number' ? opt.epoch * 1000 : Date.now();
return opt;
} | javascript | function totpOptions(options = {}) {
let opt = Object.assign(hotpOptions(), defaultOptions, options);
opt.epoch = typeof opt.epoch === 'number' ? opt.epoch * 1000 : Date.now();
return opt;
} | [
"function",
"totpOptions",
"(",
"options",
"=",
"{",
"}",
")",
"{",
"let",
"opt",
"=",
"Object",
".",
"assign",
"(",
"hotpOptions",
"(",
")",
",",
"defaultOptions",
",",
"options",
")",
";",
"opt",
".",
"epoch",
"=",
"typeof",
"opt",
".",
"epoch",
"=... | Generates options for TOTP
@module otplib-core/totpOptions
@param {number} options.digits - the output token length
@param {string} options.epoch - starting time since the UNIX epoch (seconds)
@param {number} options.step - time step (seconds)
@param {number|array} options.window - acceptable window where codes a vali... | [
"Generates",
"options",
"for",
"TOTP"
] | f81a4f11d63b3f00545c60bcef6543cdec2ddc0e | https://github.com/yeojz/otplib/blob/f81a4f11d63b3f00545c60bcef6543cdec2ddc0e/packages/otplib-core/totpOptions.js#L21-L26 | train |
yeojz/otplib | packages/otplib-core/hotpDigest.js | hotpDigest | function hotpDigest(secret, counter, options) {
if (!options.crypto || typeof options.crypto.createHmac !== 'function') {
throw new Error('Expecting options.crypto to have a createHmac function');
}
if (typeof options.createHmacSecret !== 'function') {
throw new Error('Expecting options.createHmacSecret ... | javascript | function hotpDigest(secret, counter, options) {
if (!options.crypto || typeof options.crypto.createHmac !== 'function') {
throw new Error('Expecting options.crypto to have a createHmac function');
}
if (typeof options.createHmacSecret !== 'function') {
throw new Error('Expecting options.createHmacSecret ... | [
"function",
"hotpDigest",
"(",
"secret",
",",
"counter",
",",
"options",
")",
"{",
"if",
"(",
"!",
"options",
".",
"crypto",
"||",
"typeof",
"options",
".",
"crypto",
".",
"createHmac",
"!==",
"'function'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Expec... | Intermediate HOTP Digests
@module otplib-core/hotpDigest
@param {string} secret - your secret that is used to generate the token
@param {number} counter - the OTP counter (usually it's an incremental count)
@param {string} options.algorithm - hmac algorithm
@param {function} options.createHmacSecret - the encoding fun... | [
"Intermediate",
"HOTP",
"Digests"
] | f81a4f11d63b3f00545c60bcef6543cdec2ddc0e | https://github.com/yeojz/otplib/blob/f81a4f11d63b3f00545c60bcef6543cdec2ddc0e/packages/otplib-core/hotpDigest.js#L14-L41 | train |
yeojz/otplib | packages/otplib-utils/stringToHex.js | stringToHex | function stringToHex(value) {
const val = value == null ? '' : value;
let hex = '';
let tmp = '';
for (let i = 0; i < val.length; i++) {
// Convert to Hex and Ensure it's in 2 digit sets
tmp = ('0000' + val.charCodeAt(i).toString(16)).slice(-2);
hex += '' + tmp;
}
return hex;
} | javascript | function stringToHex(value) {
const val = value == null ? '' : value;
let hex = '';
let tmp = '';
for (let i = 0; i < val.length; i++) {
// Convert to Hex and Ensure it's in 2 digit sets
tmp = ('0000' + val.charCodeAt(i).toString(16)).slice(-2);
hex += '' + tmp;
}
return hex;
} | [
"function",
"stringToHex",
"(",
"value",
")",
"{",
"const",
"val",
"=",
"value",
"==",
"null",
"?",
"''",
":",
"value",
";",
"let",
"hex",
"=",
"''",
";",
"let",
"tmp",
"=",
"''",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"val",
"... | Converts a string to Hex value
@module otplib-utils/stringToHex
@param {string} value - the string value to convert
@return {string} | [
"Converts",
"a",
"string",
"to",
"Hex",
"value"
] | f81a4f11d63b3f00545c60bcef6543cdec2ddc0e | https://github.com/yeojz/otplib/blob/f81a4f11d63b3f00545c60bcef6543cdec2ddc0e/packages/otplib-utils/stringToHex.js#L8-L21 | train |
yeojz/otplib | packages/otplib-core/totpSecret.js | totpSecret | function totpSecret(secret, options) {
if (typeof options.algorithm !== 'string') {
throw new Error('Expecting options.algorithm to be a string');
}
if (typeof options.encoding !== 'string') {
throw new Error('Expecting options.encoding to be a string');
}
const encoded = Buffer.from(secret, options... | javascript | function totpSecret(secret, options) {
if (typeof options.algorithm !== 'string') {
throw new Error('Expecting options.algorithm to be a string');
}
if (typeof options.encoding !== 'string') {
throw new Error('Expecting options.encoding to be a string');
}
const encoded = Buffer.from(secret, options... | [
"function",
"totpSecret",
"(",
"secret",
",",
"options",
")",
"{",
"if",
"(",
"typeof",
"options",
".",
"algorithm",
"!==",
"'string'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Expecting options.algorithm to be a string'",
")",
";",
"}",
"if",
"(",
"typeof",
... | Conversion of secret to buffer for TOTP
Seed for HMAC-SHA1 - 20 bytes
Seed for HMAC-SHA256 - 32 bytes
Seed for HMAC-SHA512 - 64 bytes
@module otplib-core/totpSecret
@param {string} secret - your secret that is used to generate the token
@param {string} options.algorithm - hmac algorithm
@param {string} options.encodi... | [
"Conversion",
"of",
"secret",
"to",
"buffer",
"for",
"TOTP"
] | f81a4f11d63b3f00545c60bcef6543cdec2ddc0e | https://github.com/yeojz/otplib/blob/f81a4f11d63b3f00545c60bcef6543cdec2ddc0e/packages/otplib-core/totpSecret.js#L16-L40 | train |
yeojz/otplib | packages/otplib-browser/randomBytes.js | randomBytes | function randomBytes(size) {
const crypto = window.crypto || window.msCrypto;
if (!crypto || typeof crypto.getRandomValues !== 'function') {
throw new Error(
'Unable to load crypto module. You may be on an older browser'
);
}
if (size > 65536) {
throw new Error('Requested size of random byte... | javascript | function randomBytes(size) {
const crypto = window.crypto || window.msCrypto;
if (!crypto || typeof crypto.getRandomValues !== 'function') {
throw new Error(
'Unable to load crypto module. You may be on an older browser'
);
}
if (size > 65536) {
throw new Error('Requested size of random byte... | [
"function",
"randomBytes",
"(",
"size",
")",
"{",
"const",
"crypto",
"=",
"window",
".",
"crypto",
"||",
"window",
".",
"msCrypto",
";",
"if",
"(",
"!",
"crypto",
"||",
"typeof",
"crypto",
".",
"getRandomValues",
"!==",
"'function'",
")",
"{",
"throw",
"... | randomBytes browser implementation.
Reference:
- https://github.com/crypto-browserify/randombytes
- https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues
@module otplib-browser/randomBytes
@param {string} size - the size
@return {string} | [
"randomBytes",
"browser",
"implementation",
"."
] | f81a4f11d63b3f00545c60bcef6543cdec2ddc0e | https://github.com/yeojz/otplib/blob/f81a4f11d63b3f00545c60bcef6543cdec2ddc0e/packages/otplib-browser/randomBytes.js#L12-L33 | train |
yeojz/otplib | packages/otplib-authenticator/keyuri.js | keyuri | function keyuri(user = 'user', service = 'service', secret = '') {
const protocol = 'otpauth://totp/';
const value = data
.replace('{user}', encodeURIComponent(user))
.replace('{secret}', secret)
.replace(/{service}/g, encodeURIComponent(service));
return protocol + value;
} | javascript | function keyuri(user = 'user', service = 'service', secret = '') {
const protocol = 'otpauth://totp/';
const value = data
.replace('{user}', encodeURIComponent(user))
.replace('{secret}', secret)
.replace(/{service}/g, encodeURIComponent(service));
return protocol + value;
} | [
"function",
"keyuri",
"(",
"user",
"=",
"'user'",
",",
"service",
"=",
"'service'",
",",
"secret",
"=",
"''",
")",
"{",
"const",
"protocol",
"=",
"'otpauth://totp/'",
";",
"const",
"value",
"=",
"data",
".",
"replace",
"(",
"'{user}'",
",",
"encodeURICompo... | Generates an otpauth uri
The "user" and "service" parameters will
be passed to encodeURIComponent for encoding
@namespace otplib/impl/authenticator
@module otplib-authenticator/keyuri
@param {string} user - the name/id of your user
@param {string} service - the name of your service
@param {string} secret - your secre... | [
"Generates",
"an",
"otpauth",
"uri"
] | f81a4f11d63b3f00545c60bcef6543cdec2ddc0e | https://github.com/yeojz/otplib/blob/f81a4f11d63b3f00545c60bcef6543cdec2ddc0e/packages/otplib-authenticator/keyuri.js#L16-L24 | train |
yeojz/otplib | packages/otplib-utils/leftPad.js | leftPad | function leftPad(value, length) {
const total = !length ? 0 : length;
let padded = value + '';
while (padded.length < total) {
padded = '0' + padded;
}
return padded;
} | javascript | function leftPad(value, length) {
const total = !length ? 0 : length;
let padded = value + '';
while (padded.length < total) {
padded = '0' + padded;
}
return padded;
} | [
"function",
"leftPad",
"(",
"value",
",",
"length",
")",
"{",
"const",
"total",
"=",
"!",
"length",
"?",
"0",
":",
"length",
";",
"let",
"padded",
"=",
"value",
"+",
"''",
";",
"while",
"(",
"padded",
".",
"length",
"<",
"total",
")",
"{",
"padded"... | Do a left padding if value's length less than total
@module otplib-utils/leftPad
@param {integer} value - the original value
@param {integer} length - the total length of the string
@return {string} | [
"Do",
"a",
"left",
"padding",
"if",
"value",
"s",
"length",
"less",
"than",
"total"
] | f81a4f11d63b3f00545c60bcef6543cdec2ddc0e | https://github.com/yeojz/otplib/blob/f81a4f11d63b3f00545c60bcef6543cdec2ddc0e/packages/otplib-utils/leftPad.js#L9-L19 | train |
jstat/jstat | src/linearalgebra.js | norm | function norm(arr, p) {
var nnorm = 0,
i = 0;
// check the p-value of the norm, and set for most common case
if (isNaN(p)) p = 2;
// check if multi-dimensional array, and make vector correction
if (isUsable(arr[0])) arr = arr[0];
// vector norm
for (; i < arr.length; i++) {
nnorm +... | javascript | function norm(arr, p) {
var nnorm = 0,
i = 0;
// check the p-value of the norm, and set for most common case
if (isNaN(p)) p = 2;
// check if multi-dimensional array, and make vector correction
if (isUsable(arr[0])) arr = arr[0];
// vector norm
for (; i < arr.length; i++) {
nnorm +... | [
"function",
"norm",
"(",
"arr",
",",
"p",
")",
"{",
"var",
"nnorm",
"=",
"0",
",",
"i",
"=",
"0",
";",
"// check the p-value of the norm, and set for most common case",
"if",
"(",
"isNaN",
"(",
"p",
")",
")",
"p",
"=",
"2",
";",
"// check if multi-dimensiona... | computes the p-norm of the vector In the case that a matrix is passed, uses the first row as the vector | [
"computes",
"the",
"p",
"-",
"norm",
"of",
"the",
"vector",
"In",
"the",
"case",
"that",
"a",
"matrix",
"is",
"passed",
"uses",
"the",
"first",
"row",
"as",
"the",
"vector"
] | 5d99205d806e72997d863be800ffaf7af1851b97 | https://github.com/jstat/jstat/blob/5d99205d806e72997d863be800ffaf7af1851b97/src/linearalgebra.js#L127-L139 | train |
jstat/jstat | src/regression.js | regress | function regress(jMatX,jMatY){
//print("regressin!");
//print(jMatX.toArray());
var innerinv = jStat.xtranspxinv(jMatX);
//print(innerinv);
var xtransp = jMatX.transpose();
var next = jStat.matrixmult(jStat(innerinv),xtransp);
return jStat.matrixmult(next,jMatY);
} | javascript | function regress(jMatX,jMatY){
//print("regressin!");
//print(jMatX.toArray());
var innerinv = jStat.xtranspxinv(jMatX);
//print(innerinv);
var xtransp = jMatX.transpose();
var next = jStat.matrixmult(jStat(innerinv),xtransp);
return jStat.matrixmult(next,jMatY);
} | [
"function",
"regress",
"(",
"jMatX",
",",
"jMatY",
")",
"{",
"//print(\"regressin!\");",
"//print(jMatX.toArray());",
"var",
"innerinv",
"=",
"jStat",
".",
"xtranspxinv",
"(",
"jMatX",
")",
";",
"//print(innerinv);",
"var",
"xtransp",
"=",
"jMatX",
".",
"transpose... | regress and regresst to be fixed | [
"regress",
"and",
"regresst",
"to",
"be",
"fixed"
] | 5d99205d806e72997d863be800ffaf7af1851b97 | https://github.com/jstat/jstat/blob/5d99205d806e72997d863be800ffaf7af1851b97/src/regression.js#L90-L99 | train |
jstat/jstat | build/doctool.js | loadIncludes | function loadIncludes(data, current_file) {
return data.replace(includeExpr, function(src, name, ext) {
try {
var include_path =
path.join(current_file, "../", name+"."+(ext || "markdown"))
return loadIncludes(fs.readFileSync(include_path, "utf8"), current_file);
} catch(e) {
retur... | javascript | function loadIncludes(data, current_file) {
return data.replace(includeExpr, function(src, name, ext) {
try {
var include_path =
path.join(current_file, "../", name+"."+(ext || "markdown"))
return loadIncludes(fs.readFileSync(include_path, "utf8"), current_file);
} catch(e) {
retur... | [
"function",
"loadIncludes",
"(",
"data",
",",
"current_file",
")",
"{",
"return",
"data",
".",
"replace",
"(",
"includeExpr",
",",
"function",
"(",
"src",
",",
"name",
",",
"ext",
")",
"{",
"try",
"{",
"var",
"include_path",
"=",
"path",
".",
"join",
"... | Allow including other pages in the data. | [
"Allow",
"including",
"other",
"pages",
"in",
"the",
"data",
"."
] | 5d99205d806e72997d863be800ffaf7af1851b97 | https://github.com/jstat/jstat/blob/5d99205d806e72997d863be800ffaf7af1851b97/build/doctool.js#L66-L76 | train |
jstat/jstat | doc/assets/sh_main.js | sh_extractTagsFromNodeList | function sh_extractTagsFromNodeList(nodeList, result) {
var length = nodeList.length;
for (var i = 0; i < length; i++) {
var node = nodeList.item(i);
switch (node.nodeType) {
case 1:
if (node.nodeName.toLowerCase() === 'br') {
var terminator;
if (/MSIE/.test(navigator.userAgent)) {... | javascript | function sh_extractTagsFromNodeList(nodeList, result) {
var length = nodeList.length;
for (var i = 0; i < length; i++) {
var node = nodeList.item(i);
switch (node.nodeType) {
case 1:
if (node.nodeName.toLowerCase() === 'br') {
var terminator;
if (/MSIE/.test(navigator.userAgent)) {... | [
"function",
"sh_extractTagsFromNodeList",
"(",
"nodeList",
",",
"result",
")",
"{",
"var",
"length",
"=",
"nodeList",
".",
"length",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"var",
"node",
"=",
"nodeLi... | Extracts the tags from an HTML DOM NodeList.
@param nodeList a DOM NodeList
@param result an object with text, tags and pos properties | [
"Extracts",
"the",
"tags",
"from",
"an",
"HTML",
"DOM",
"NodeList",
"."
] | 5d99205d806e72997d863be800ffaf7af1851b97 | https://github.com/jstat/jstat/blob/5d99205d806e72997d863be800ffaf7af1851b97/doc/assets/sh_main.js#L286-L316 | train |
jstat/jstat | doc/assets/sh_main.js | sh_extractTags | function sh_extractTags(element, tags) {
var result = {};
result.text = [];
result.tags = tags;
result.pos = 0;
sh_extractTagsFromNodeList(element.childNodes, result);
return result.text.join('');
} | javascript | function sh_extractTags(element, tags) {
var result = {};
result.text = [];
result.tags = tags;
result.pos = 0;
sh_extractTagsFromNodeList(element.childNodes, result);
return result.text.join('');
} | [
"function",
"sh_extractTags",
"(",
"element",
",",
"tags",
")",
"{",
"var",
"result",
"=",
"{",
"}",
";",
"result",
".",
"text",
"=",
"[",
"]",
";",
"result",
".",
"tags",
"=",
"tags",
";",
"result",
".",
"pos",
"=",
"0",
";",
"sh_extractTagsFromNode... | Extracts the tags from the text of an HTML element. The extracted tags will be
returned as an array of tag objects. See sh_highlightString for the format of
the tag objects.
@param element a DOM element
@param tags an empty array; the extracted tag objects will be returned in it
@return the text of the element
@se... | [
"Extracts",
"the",
"tags",
"from",
"the",
"text",
"of",
"an",
"HTML",
"element",
".",
"The",
"extracted",
"tags",
"will",
"be",
"returned",
"as",
"an",
"array",
"of",
"tag",
"objects",
".",
"See",
"sh_highlightString",
"for",
"the",
"format",
"of",
"the",
... | 5d99205d806e72997d863be800ffaf7af1851b97 | https://github.com/jstat/jstat/blob/5d99205d806e72997d863be800ffaf7af1851b97/doc/assets/sh_main.js#L327-L334 | train |
jstat/jstat | doc/assets/sh_main.js | sh_highlightElement | function sh_highlightElement(element, language) {
sh_addClass(element, 'sh_sourceCode');
var originalTags = [];
var inputString = sh_extractTags(element, originalTags);
var highlightTags = sh_highlightString(inputString, language);
var tags = sh_mergeTags(originalTags, highlightTags);
var documentFragment =... | javascript | function sh_highlightElement(element, language) {
sh_addClass(element, 'sh_sourceCode');
var originalTags = [];
var inputString = sh_extractTags(element, originalTags);
var highlightTags = sh_highlightString(inputString, language);
var tags = sh_mergeTags(originalTags, highlightTags);
var documentFragment =... | [
"function",
"sh_highlightElement",
"(",
"element",
",",
"language",
")",
"{",
"sh_addClass",
"(",
"element",
",",
"'sh_sourceCode'",
")",
";",
"var",
"originalTags",
"=",
"[",
"]",
";",
"var",
"inputString",
"=",
"sh_extractTags",
"(",
"element",
",",
"origina... | Highlights an element containing source code. Upon completion of this function,
the element will have been placed in the "sh_sourceCode" class.
@param element a DOM <pre> element containing the source code to be highlighted
@param language a language definition object | [
"Highlights",
"an",
"element",
"containing",
"source",
"code",
".",
"Upon",
"completion",
"of",
"this",
"function",
"the",
"element",
"will",
"have",
"been",
"placed",
"in",
"the",
"sh_sourceCode",
"class",
"."
] | 5d99205d806e72997d863be800ffaf7af1851b97 | https://github.com/jstat/jstat/blob/5d99205d806e72997d863be800ffaf7af1851b97/doc/assets/sh_main.js#L453-L464 | train |
jstat/jstat | build/lib/markdown.js | add | function add(li, loose, inline, nl) {
if (loose) {
li.push( [ "para" ].concat(inline) );
return;
}
// Hmmm, should this be any block level element or just paras?
var add_to = li[li.length -1] instanceof Array && li[li.length - 1][0] == "para"
? li... | javascript | function add(li, loose, inline, nl) {
if (loose) {
li.push( [ "para" ].concat(inline) );
return;
}
// Hmmm, should this be any block level element or just paras?
var add_to = li[li.length -1] instanceof Array && li[li.length - 1][0] == "para"
? li... | [
"function",
"add",
"(",
"li",
",",
"loose",
",",
"inline",
",",
"nl",
")",
"{",
"if",
"(",
"loose",
")",
"{",
"li",
".",
"push",
"(",
"[",
"\"para\"",
"]",
".",
"concat",
"(",
"inline",
")",
")",
";",
"return",
";",
"}",
"// Hmmm, should this be an... | Add inline content `inline` to `li`. inline comes from processInline so is an array of content | [
"Add",
"inline",
"content",
"inline",
"to",
"li",
".",
"inline",
"comes",
"from",
"processInline",
"so",
"is",
"an",
"array",
"of",
"content"
] | 5d99205d806e72997d863be800ffaf7af1851b97 | https://github.com/jstat/jstat/blob/5d99205d806e72997d863be800ffaf7af1851b97/build/lib/markdown.js#L429-L453 | train |
jstat/jstat | build/lib/markdown.js | merge_text_nodes | function merge_text_nodes( jsonml ) {
// skip the tag name and attribute hash
var i = extract_attr( jsonml ) ? 2 : 1;
while ( i < jsonml.length ) {
// if it's a string check the next item too
if ( typeof jsonml[ i ] === "string" ) {
if ( i + 1 < jsonml.length && typeof jsonml[ i + 1 ] === "string" ... | javascript | function merge_text_nodes( jsonml ) {
// skip the tag name and attribute hash
var i = extract_attr( jsonml ) ? 2 : 1;
while ( i < jsonml.length ) {
// if it's a string check the next item too
if ( typeof jsonml[ i ] === "string" ) {
if ( i + 1 < jsonml.length && typeof jsonml[ i + 1 ] === "string" ... | [
"function",
"merge_text_nodes",
"(",
"jsonml",
")",
"{",
"// skip the tag name and attribute hash",
"var",
"i",
"=",
"extract_attr",
"(",
"jsonml",
")",
"?",
"2",
":",
"1",
";",
"while",
"(",
"i",
"<",
"jsonml",
".",
"length",
")",
"{",
"// if it's a string ch... | merges adjacent text nodes into a single node | [
"merges",
"adjacent",
"text",
"nodes",
"into",
"a",
"single",
"node"
] | 5d99205d806e72997d863be800ffaf7af1851b97 | https://github.com/jstat/jstat/blob/5d99205d806e72997d863be800ffaf7af1851b97/build/lib/markdown.js#L1435-L1456 | train |
agraboso/redux-api-middleware | src/util.js | getJSON | async function getJSON(res) {
const contentType = res.headers.get('Content-Type');
const emptyCodes = [204, 205];
if (
!~emptyCodes.indexOf(res.status) &&
contentType &&
~contentType.indexOf('json')
) {
return await res.json();
} else {
return await Promise.resolve();
}
} | javascript | async function getJSON(res) {
const contentType = res.headers.get('Content-Type');
const emptyCodes = [204, 205];
if (
!~emptyCodes.indexOf(res.status) &&
contentType &&
~contentType.indexOf('json')
) {
return await res.json();
} else {
return await Promise.resolve();
}
} | [
"async",
"function",
"getJSON",
"(",
"res",
")",
"{",
"const",
"contentType",
"=",
"res",
".",
"headers",
".",
"get",
"(",
"'Content-Type'",
")",
";",
"const",
"emptyCodes",
"=",
"[",
"204",
",",
"205",
"]",
";",
"if",
"(",
"!",
"~",
"emptyCodes",
".... | Extract JSON body from a server response
@function getJSON
@access public
@param {object} res - A raw response object
@returns {promise|undefined} | [
"Extract",
"JSON",
"body",
"from",
"a",
"server",
"response"
] | 6e782cdea6d5451e6e96406de631db7c11df1a2d | https://github.com/agraboso/redux-api-middleware/blob/6e782cdea6d5451e6e96406de631db7c11df1a2d/src/util.js#L11-L24 | train |
agraboso/redux-api-middleware | src/util.js | normalizeTypeDescriptors | function normalizeTypeDescriptors(types) {
let [requestType, successType, failureType] = types;
if (typeof requestType === 'string' || typeof requestType === 'symbol') {
requestType = { type: requestType };
}
if (typeof successType === 'string' || typeof successType === 'symbol') {
successType = { typ... | javascript | function normalizeTypeDescriptors(types) {
let [requestType, successType, failureType] = types;
if (typeof requestType === 'string' || typeof requestType === 'symbol') {
requestType = { type: requestType };
}
if (typeof successType === 'string' || typeof successType === 'symbol') {
successType = { typ... | [
"function",
"normalizeTypeDescriptors",
"(",
"types",
")",
"{",
"let",
"[",
"requestType",
",",
"successType",
",",
"failureType",
"]",
"=",
"types",
";",
"if",
"(",
"typeof",
"requestType",
"===",
"'string'",
"||",
"typeof",
"requestType",
"===",
"'symbol'",
... | Blow up string or symbol types into full-fledged type descriptors,
and add defaults
@function normalizeTypeDescriptors
@access private
@param {array} types - The [RSAA].types from a validated RSAA
@returns {array} | [
"Blow",
"up",
"string",
"or",
"symbol",
"types",
"into",
"full",
"-",
"fledged",
"type",
"descriptors",
"and",
"add",
"defaults"
] | 6e782cdea6d5451e6e96406de631db7c11df1a2d | https://github.com/agraboso/redux-api-middleware/blob/6e782cdea6d5451e6e96406de631db7c11df1a2d/src/util.js#L35-L60 | train |
agraboso/redux-api-middleware | src/util.js | actionWith | async function actionWith(descriptor, args = []) {
try {
descriptor.payload =
typeof descriptor.payload === 'function'
? await descriptor.payload(...args)
: descriptor.payload;
} catch (e) {
descriptor.payload = new InternalError(e.message);
descriptor.error = true;
}
try {
... | javascript | async function actionWith(descriptor, args = []) {
try {
descriptor.payload =
typeof descriptor.payload === 'function'
? await descriptor.payload(...args)
: descriptor.payload;
} catch (e) {
descriptor.payload = new InternalError(e.message);
descriptor.error = true;
}
try {
... | [
"async",
"function",
"actionWith",
"(",
"descriptor",
",",
"args",
"=",
"[",
"]",
")",
"{",
"try",
"{",
"descriptor",
".",
"payload",
"=",
"typeof",
"descriptor",
".",
"payload",
"===",
"'function'",
"?",
"await",
"descriptor",
".",
"payload",
"(",
"...",
... | Evaluate a type descriptor to an FSA
@function actionWith
@access private
@param {object} descriptor - A type descriptor
@param {array} args - The array of arguments for `payload` and `meta` function properties
@returns {object} | [
"Evaluate",
"a",
"type",
"descriptor",
"to",
"an",
"FSA"
] | 6e782cdea6d5451e6e96406de631db7c11df1a2d | https://github.com/agraboso/redux-api-middleware/blob/6e782cdea6d5451e6e96406de631db7c11df1a2d/src/util.js#L71-L94 | train |
agraboso/redux-api-middleware | src/validation.js | isValidTypeDescriptor | function isValidTypeDescriptor(obj) {
const validKeys = ['type', 'payload', 'meta'];
if (!isPlainObject(obj)) {
return false;
}
for (let key in obj) {
if (!~validKeys.indexOf(key)) {
return false;
}
}
if (!('type' in obj)) {
return false;
} else if (typeof obj.type !== 'string' && t... | javascript | function isValidTypeDescriptor(obj) {
const validKeys = ['type', 'payload', 'meta'];
if (!isPlainObject(obj)) {
return false;
}
for (let key in obj) {
if (!~validKeys.indexOf(key)) {
return false;
}
}
if (!('type' in obj)) {
return false;
} else if (typeof obj.type !== 'string' && t... | [
"function",
"isValidTypeDescriptor",
"(",
"obj",
")",
"{",
"const",
"validKeys",
"=",
"[",
"'type'",
",",
"'payload'",
",",
"'meta'",
"]",
";",
"if",
"(",
"!",
"isPlainObject",
"(",
"obj",
")",
")",
"{",
"return",
"false",
";",
"}",
"for",
"(",
"let",
... | Is the given object a valid type descriptor?
@function isValidTypeDescriptor
@access private
@param {object} obj - The object to check agains the type descriptor definition
@returns {boolean} | [
"Is",
"the",
"given",
"object",
"a",
"valid",
"type",
"descriptor?"
] | 6e782cdea6d5451e6e96406de631db7c11df1a2d | https://github.com/agraboso/redux-api-middleware/blob/6e782cdea6d5451e6e96406de631db7c11df1a2d/src/validation.js#L39-L57 | train |
NEYouFan/nei-toolkit | lib/util/io.js | function (cache, listener) {
if (Object.keys(cache).length <= 0) {
listener.forEach(function (callback) {
try {
callback();
} catch (ex) {
console.error(ex.stack);
}
});
}
} | javascript | function (cache, listener) {
if (Object.keys(cache).length <= 0) {
listener.forEach(function (callback) {
try {
callback();
} catch (ex) {
console.error(ex.stack);
}
});
}
} | [
"function",
"(",
"cache",
",",
"listener",
")",
"{",
"if",
"(",
"Object",
".",
"keys",
"(",
"cache",
")",
".",
"length",
"<=",
"0",
")",
"{",
"listener",
".",
"forEach",
"(",
"function",
"(",
"callback",
")",
"{",
"try",
"{",
"callback",
"(",
")",
... | check event trigger | [
"check",
"event",
"trigger"
] | a2a8bfcfb3d6a4d685afcbcb275277c9e344e295 | https://github.com/NEYouFan/nei-toolkit/blob/a2a8bfcfb3d6a4d685afcbcb275277c9e344e295/lib/util/io.js#L38-L48 | train | |
NEYouFan/nei-toolkit | lib/util/file.js | function (file, content, charset, callback) {
try {
if (!file) {
return;
}
charset = (charset || 'utf-8').toLowerCase();
if (charset !== 'utf-8') {
content = require('iconv-lite').encode(content + '\r\n', charset);
}
callback.call(this, file, c... | javascript | function (file, content, charset, callback) {
try {
if (!file) {
return;
}
charset = (charset || 'utf-8').toLowerCase();
if (charset !== 'utf-8') {
content = require('iconv-lite').encode(content + '\r\n', charset);
}
callback.call(this, file, c... | [
"function",
"(",
"file",
",",
"content",
",",
"charset",
",",
"callback",
")",
"{",
"try",
"{",
"if",
"(",
"!",
"file",
")",
"{",
"return",
";",
"}",
"charset",
"=",
"(",
"charset",
"||",
"'utf-8'",
")",
".",
"toLowerCase",
"(",
")",
";",
"if",
"... | write content to file
@param {string} file - absolute file path
@param {string} content - file content
@param {string} charset - content charset, default is utf-8
@return {undefined} | [
"write",
"content",
"to",
"file"
] | a2a8bfcfb3d6a4d685afcbcb275277c9e344e295 | https://github.com/NEYouFan/nei-toolkit/blob/a2a8bfcfb3d6a4d685afcbcb275277c9e344e295/lib/util/file.js#L91-L104 | train | |
ccampbell/rainbow | src/rainbow.js | _messageWorker | function _messageWorker(message, callback) {
const worker = _getWorker();
function _listen(e) {
if (e.data.id === message.id) {
callback(e.data);
worker.removeEventListener('message', _listen);
}
}
worker.addEventListener('message', _listen);
worker.postMess... | javascript | function _messageWorker(message, callback) {
const worker = _getWorker();
function _listen(e) {
if (e.data.id === message.id) {
callback(e.data);
worker.removeEventListener('message', _listen);
}
}
worker.addEventListener('message', _listen);
worker.postMess... | [
"function",
"_messageWorker",
"(",
"message",
",",
"callback",
")",
"{",
"const",
"worker",
"=",
"_getWorker",
"(",
")",
";",
"function",
"_listen",
"(",
"e",
")",
"{",
"if",
"(",
"e",
".",
"data",
".",
"id",
"===",
"message",
".",
"id",
")",
"{",
... | Helper for matching up callbacks directly with the
post message requests to a web worker.
@param {object} message data to send to web worker
@param {Function} callback callback function for worker to reply to
@return {void} | [
"Helper",
"for",
"matching",
"up",
"callbacks",
"directly",
"with",
"the",
"post",
"message",
"requests",
"to",
"a",
"web",
"worker",
"."
] | 83308dfd7ce8ecfa05d5dde48dfad4a239382dfb | https://github.com/ccampbell/rainbow/blob/83308dfd7ce8ecfa05d5dde48dfad4a239382dfb/src/rainbow.js#L85-L97 | train |
ccampbell/rainbow | src/rainbow.js | _generateHandler | function _generateHandler(element, waitingOn, callback) {
return function _handleResponseFromWorker(data) {
element.innerHTML = data.result;
element.classList.remove('loading');
element.classList.add('rainbow-show');
if (element.parentNode.tagName === 'PRE') {
element.pa... | javascript | function _generateHandler(element, waitingOn, callback) {
return function _handleResponseFromWorker(data) {
element.innerHTML = data.result;
element.classList.remove('loading');
element.classList.add('rainbow-show');
if (element.parentNode.tagName === 'PRE') {
element.pa... | [
"function",
"_generateHandler",
"(",
"element",
",",
"waitingOn",
",",
"callback",
")",
"{",
"return",
"function",
"_handleResponseFromWorker",
"(",
"data",
")",
"{",
"element",
".",
"innerHTML",
"=",
"data",
".",
"result",
";",
"element",
".",
"classList",
".... | Browser Only - Handles response from web worker, updates DOM with
resulting code, and fires callback
@param {Element} element
@param {object} waitingOn
@param {Function} callback
@return {void} | [
"Browser",
"Only",
"-",
"Handles",
"response",
"from",
"web",
"worker",
"updates",
"DOM",
"with",
"resulting",
"code",
"and",
"fires",
"callback"
] | 83308dfd7ce8ecfa05d5dde48dfad4a239382dfb | https://github.com/ccampbell/rainbow/blob/83308dfd7ce8ecfa05d5dde48dfad4a239382dfb/src/rainbow.js#L108-L135 | train |
ccampbell/rainbow | src/rainbow.js | _getPrismOptions | function _getPrismOptions(options) {
return {
patterns,
inheritenceMap,
aliases,
globalClass: options.globalClass,
delay: !isNaN(options.delay) ? options.delay : 0
};
} | javascript | function _getPrismOptions(options) {
return {
patterns,
inheritenceMap,
aliases,
globalClass: options.globalClass,
delay: !isNaN(options.delay) ? options.delay : 0
};
} | [
"function",
"_getPrismOptions",
"(",
"options",
")",
"{",
"return",
"{",
"patterns",
",",
"inheritenceMap",
",",
"aliases",
",",
"globalClass",
":",
"options",
".",
"globalClass",
",",
"delay",
":",
"!",
"isNaN",
"(",
"options",
".",
"delay",
")",
"?",
"op... | Gets options needed to pass into Prism
@param {object} options
@return {object} | [
"Gets",
"options",
"needed",
"to",
"pass",
"into",
"Prism"
] | 83308dfd7ce8ecfa05d5dde48dfad4a239382dfb | https://github.com/ccampbell/rainbow/blob/83308dfd7ce8ecfa05d5dde48dfad4a239382dfb/src/rainbow.js#L143-L151 | train |
ccampbell/rainbow | src/rainbow.js | _getWorkerData | function _getWorkerData(code, lang) {
let options = {};
if (typeof lang === 'object') {
options = lang;
lang = options.language;
}
lang = aliases[lang] || lang;
const workerData = {
id: id++,
code,
lang,
options: _getPrismOptions(options),
is... | javascript | function _getWorkerData(code, lang) {
let options = {};
if (typeof lang === 'object') {
options = lang;
lang = options.language;
}
lang = aliases[lang] || lang;
const workerData = {
id: id++,
code,
lang,
options: _getPrismOptions(options),
is... | [
"function",
"_getWorkerData",
"(",
"code",
",",
"lang",
")",
"{",
"let",
"options",
"=",
"{",
"}",
";",
"if",
"(",
"typeof",
"lang",
"===",
"'object'",
")",
"{",
"options",
"=",
"lang",
";",
"lang",
"=",
"options",
".",
"language",
";",
"}",
"lang",
... | Gets data to send to webworker
@param {string} code
@param {string} lang
@return {object} | [
"Gets",
"data",
"to",
"send",
"to",
"webworker"
] | 83308dfd7ce8ecfa05d5dde48dfad4a239382dfb | https://github.com/ccampbell/rainbow/blob/83308dfd7ce8ecfa05d5dde48dfad4a239382dfb/src/rainbow.js#L160-L178 | train |
ccampbell/rainbow | src/rainbow.js | _highlightCodeBlocks | function _highlightCodeBlocks(codeBlocks, callback) {
const waitingOn = { c: 0 };
for (const block of codeBlocks) {
const language = getLanguageForBlock(block);
if (block.classList.contains('rainbow') || !language) {
continue;
}
// This cancels the pending animation ... | javascript | function _highlightCodeBlocks(codeBlocks, callback) {
const waitingOn = { c: 0 };
for (const block of codeBlocks) {
const language = getLanguageForBlock(block);
if (block.classList.contains('rainbow') || !language) {
continue;
}
// This cancels the pending animation ... | [
"function",
"_highlightCodeBlocks",
"(",
"codeBlocks",
",",
"callback",
")",
"{",
"const",
"waitingOn",
"=",
"{",
"c",
":",
"0",
"}",
";",
"for",
"(",
"const",
"block",
"of",
"codeBlocks",
")",
"{",
"const",
"language",
"=",
"getLanguageForBlock",
"(",
"bl... | Browser Only - Sends messages to web worker to highlight elements passed
in
@param {Array} codeBlocks
@param {Function} callback
@return {void} | [
"Browser",
"Only",
"-",
"Sends",
"messages",
"to",
"web",
"worker",
"to",
"highlight",
"elements",
"passed",
"in"
] | 83308dfd7ce8ecfa05d5dde48dfad4a239382dfb | https://github.com/ccampbell/rainbow/blob/83308dfd7ce8ecfa05d5dde48dfad4a239382dfb/src/rainbow.js#L188-L218 | train |
ccampbell/rainbow | src/rainbow.js | _highlight | function _highlight(node, callback) {
callback = callback || function() {};
// The first argument can be an Event or a DOM Element.
//
// I was originally checking instanceof Event but that made it break
// when using mootools.
//
// @see https://github.com/ccampbell/rainbow/issues/32
n... | javascript | function _highlight(node, callback) {
callback = callback || function() {};
// The first argument can be an Event or a DOM Element.
//
// I was originally checking instanceof Event but that made it break
// when using mootools.
//
// @see https://github.com/ccampbell/rainbow/issues/32
n... | [
"function",
"_highlight",
"(",
"node",
",",
"callback",
")",
"{",
"callback",
"=",
"callback",
"||",
"function",
"(",
")",
"{",
"}",
";",
"// The first argument can be an Event or a DOM Element.",
"//",
"// I was originally checking instanceof Event but that made it break",
... | Browser Only - Start highlighting all the code blocks
@param {Element} node HTMLElement to search within
@param {Function} callback
@return {void} | [
"Browser",
"Only",
"-",
"Start",
"highlighting",
"all",
"the",
"code",
"blocks"
] | 83308dfd7ce8ecfa05d5dde48dfad4a239382dfb | https://github.com/ccampbell/rainbow/blob/83308dfd7ce8ecfa05d5dde48dfad4a239382dfb/src/rainbow.js#L236-L298 | train |
ccampbell/rainbow | src/rainbow.js | extend | function extend(language, languagePatterns, inherits) {
// If we extend a language again we shouldn't need to specify the
// inheritence for it. For example, if you are adding special highlighting
// for a javascript function that is not in the base javascript rules, you
// should be able to do
//
... | javascript | function extend(language, languagePatterns, inherits) {
// If we extend a language again we shouldn't need to specify the
// inheritence for it. For example, if you are adding special highlighting
// for a javascript function that is not in the base javascript rules, you
// should be able to do
//
... | [
"function",
"extend",
"(",
"language",
",",
"languagePatterns",
",",
"inherits",
")",
"{",
"// If we extend a language again we shouldn't need to specify the",
"// inheritence for it. For example, if you are adding special highlighting",
"// for a javascript function that is not in the base ... | Extends the language pattern matches
@param {string} language name of language
@param {object} languagePatterns object of patterns to add on
@param {string|undefined} inherits optional language that this language
should inherit rules from | [
"Extends",
"the",
"language",
"pattern",
"matches"
] | 83308dfd7ce8ecfa05d5dde48dfad4a239382dfb | https://github.com/ccampbell/rainbow/blob/83308dfd7ce8ecfa05d5dde48dfad4a239382dfb/src/rainbow.js#L319-L334 | train |
ccampbell/rainbow | src/rainbow.js | color | function color(...args) {
// If you want to straight up highlight a string you can pass the
// string of code, the language, and a callback function.
//
// Example:
//
// Rainbow.color(code, language, function(highlightedCode, language) {
// // this code block is now highlighted
// ... | javascript | function color(...args) {
// If you want to straight up highlight a string you can pass the
// string of code, the language, and a callback function.
//
// Example:
//
// Rainbow.color(code, language, function(highlightedCode, language) {
// // this code block is now highlighted
// ... | [
"function",
"color",
"(",
"...",
"args",
")",
"{",
"// If you want to straight up highlight a string you can pass the",
"// string of code, the language, and a callback function.",
"//",
"// Example:",
"//",
"// Rainbow.color(code, language, function(highlightedCode, language) {",
"// ... | Starts the magic rainbow
@return {void} | [
"Starts",
"the",
"magic",
"rainbow"
] | 83308dfd7ce8ecfa05d5dde48dfad4a239382dfb | https://github.com/ccampbell/rainbow/blob/83308dfd7ce8ecfa05d5dde48dfad4a239382dfb/src/rainbow.js#L346-L397 | train |
nfriedly/node-unblocker | lib/charsets.js | MetaCharsetReplacerStream | function MetaCharsetReplacerStream(options) {
options = options || {};
this.encoding = options.encoding = 'utf8'; // this is the *output* encoding
options.decodeStrings = false; // don't turn my strings back into a buffer!
Transform.call(this, options);
} | javascript | function MetaCharsetReplacerStream(options) {
options = options || {};
this.encoding = options.encoding = 'utf8'; // this is the *output* encoding
options.decodeStrings = false; // don't turn my strings back into a buffer!
Transform.call(this, options);
} | [
"function",
"MetaCharsetReplacerStream",
"(",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"this",
".",
"encoding",
"=",
"options",
".",
"encoding",
"=",
"'utf8'",
";",
"// this is the *output* encoding",
"options",
".",
"decodeStrings",
... | similar to the charset_finder, except global | [
"similar",
"to",
"the",
"charset_finder",
"except",
"global"
] | 30874bcbab993ab8ed525c0751ae2572ae20fdac | https://github.com/nfriedly/node-unblocker/blob/30874bcbab993ab8ed525c0751ae2572ae20fdac/lib/charsets.js#L160-L165 | train |
nfriedly/node-unblocker | lib/proxy.js | proxyRequest | function proxyRequest(data, next) {
debug('proxying %s %s', data.clientRequest.method, data.url);
var middlewareHandledRequest = _.some(config.requestMiddleware, function(middleware) {
middleware(data);
return data.clientResponse.headersSent; // if true, then _.some will stop p... | javascript | function proxyRequest(data, next) {
debug('proxying %s %s', data.clientRequest.method, data.url);
var middlewareHandledRequest = _.some(config.requestMiddleware, function(middleware) {
middleware(data);
return data.clientResponse.headersSent; // if true, then _.some will stop p... | [
"function",
"proxyRequest",
"(",
"data",
",",
"next",
")",
"{",
"debug",
"(",
"'proxying %s %s'",
",",
"data",
".",
"clientRequest",
".",
"method",
",",
"data",
".",
"url",
")",
";",
"var",
"middlewareHandledRequest",
"=",
"_",
".",
"some",
"(",
"config",
... | Makes the outgoing request and relays it to the client, modifying it along the way if necessary | [
"Makes",
"the",
"outgoing",
"request",
"and",
"relays",
"it",
"to",
"the",
"client",
"modifying",
"it",
"along",
"the",
"way",
"if",
"necessary"
] | 30874bcbab993ab8ed525c0751ae2572ae20fdac | https://github.com/nfriedly/node-unblocker/blob/30874bcbab993ab8ed525c0751ae2572ae20fdac/lib/proxy.js#L14-L59 | train |
ljagis/leaflet-measure | src/leaflet-measure.js | function() {
this._locked = true;
this._measureVertexes = L.featureGroup().addTo(this._layer);
this._captureMarker = L.marker(this._map.getCenter(), {
clickable: true,
zIndexOffset: this.options.captureZIndex,
opacity: 0
}).addTo(this._layer);
this._setCaptureMarkerIcon();
thi... | javascript | function() {
this._locked = true;
this._measureVertexes = L.featureGroup().addTo(this._layer);
this._captureMarker = L.marker(this._map.getCenter(), {
clickable: true,
zIndexOffset: this.options.captureZIndex,
opacity: 0
}).addTo(this._layer);
this._setCaptureMarkerIcon();
thi... | [
"function",
"(",
")",
"{",
"this",
".",
"_locked",
"=",
"true",
";",
"this",
".",
"_measureVertexes",
"=",
"L",
".",
"featureGroup",
"(",
")",
".",
"addTo",
"(",
"this",
".",
"_layer",
")",
";",
"this",
".",
"_captureMarker",
"=",
"L",
".",
"marker",... | get state vars and interface ready for measure | [
"get",
"state",
"vars",
"and",
"interface",
"ready",
"for",
"measure"
] | 756dff840e42a884e7a41bc512e5fd5be130f1ce | https://github.com/ljagis/leaflet-measure/blob/756dff840e42a884e7a41bc512e5fd5be130f1ce/src/leaflet-measure.js#L145-L171 | train | |
ljagis/leaflet-measure | src/leaflet-measure.js | function() {
const model = L.extend({}, this._resultsModel, { points: this._latlngs });
this._locked = false;
L.DomEvent.off(this._container, 'mouseover', this._handleMapMouseOut, this);
this._clearMeasure();
this._captureMarker
.off('mouseout', this._handleMapMouseOut, this)
.off('d... | javascript | function() {
const model = L.extend({}, this._resultsModel, { points: this._latlngs });
this._locked = false;
L.DomEvent.off(this._container, 'mouseover', this._handleMapMouseOut, this);
this._clearMeasure();
this._captureMarker
.off('mouseout', this._handleMapMouseOut, this)
.off('d... | [
"function",
"(",
")",
"{",
"const",
"model",
"=",
"L",
".",
"extend",
"(",
"{",
"}",
",",
"this",
".",
"_resultsModel",
",",
"{",
"points",
":",
"this",
".",
"_latlngs",
"}",
")",
";",
"this",
".",
"_locked",
"=",
"false",
";",
"L",
".",
"DomEven... | return to state with no measure in progress, undo `this._startMeasure` | [
"return",
"to",
"state",
"with",
"no",
"measure",
"in",
"progress",
"undo",
"this",
".",
"_startMeasure"
] | 756dff840e42a884e7a41bc512e5fd5be130f1ce | https://github.com/ljagis/leaflet-measure/blob/756dff840e42a884e7a41bc512e5fd5be130f1ce/src/leaflet-measure.js#L173-L200 | train | |
ljagis/leaflet-measure | src/leaflet-measure.js | function() {
this._latlngs = [];
this._resultsModel = null;
this._measureVertexes.clearLayers();
if (this._measureDrag) {
this._layer.removeLayer(this._measureDrag);
}
if (this._measureArea) {
this._layer.removeLayer(this._measureArea);
}
if (this._measureBoundary) {
th... | javascript | function() {
this._latlngs = [];
this._resultsModel = null;
this._measureVertexes.clearLayers();
if (this._measureDrag) {
this._layer.removeLayer(this._measureDrag);
}
if (this._measureArea) {
this._layer.removeLayer(this._measureArea);
}
if (this._measureBoundary) {
th... | [
"function",
"(",
")",
"{",
"this",
".",
"_latlngs",
"=",
"[",
"]",
";",
"this",
".",
"_resultsModel",
"=",
"null",
";",
"this",
".",
"_measureVertexes",
".",
"clearLayers",
"(",
")",
";",
"if",
"(",
"this",
".",
"_measureDrag",
")",
"{",
"this",
".",... | clear all running measure data | [
"clear",
"all",
"running",
"measure",
"data"
] | 756dff840e42a884e7a41bc512e5fd5be130f1ce | https://github.com/ljagis/leaflet-measure/blob/756dff840e42a884e7a41bc512e5fd5be130f1ce/src/leaflet-measure.js#L202-L218 | train | |
ljagis/leaflet-measure | src/leaflet-measure.js | function() {
const calced = calc(this._latlngs);
const model = (this._resultsModel = L.extend(
{},
calced,
this._getMeasurementDisplayStrings(calced),
{
pointCount: this._latlngs.length
}
));
this.$results.innerHTML = resultsTemplateCompiled({ model });
} | javascript | function() {
const calced = calc(this._latlngs);
const model = (this._resultsModel = L.extend(
{},
calced,
this._getMeasurementDisplayStrings(calced),
{
pointCount: this._latlngs.length
}
));
this.$results.innerHTML = resultsTemplateCompiled({ model });
} | [
"function",
"(",
")",
"{",
"const",
"calced",
"=",
"calc",
"(",
"this",
".",
"_latlngs",
")",
";",
"const",
"model",
"=",
"(",
"this",
".",
"_resultsModel",
"=",
"L",
".",
"extend",
"(",
"{",
"}",
",",
"calced",
",",
"this",
".",
"_getMeasurementDisp... | update results area of dom with calced measure from `this._latlngs` | [
"update",
"results",
"area",
"of",
"dom",
"with",
"calced",
"measure",
"from",
"this",
".",
"_latlngs"
] | 756dff840e42a884e7a41bc512e5fd5be130f1ce | https://github.com/ljagis/leaflet-measure/blob/756dff840e42a884e7a41bc512e5fd5be130f1ce/src/leaflet-measure.js#L295-L306 | train | |
ljagis/leaflet-measure | src/leaflet-measure.js | function(evt) {
if (!this._measureDrag) {
this._measureDrag = L.circleMarker(evt.latlng, this._symbols.getSymbol('measureDrag')).addTo(
this._layer
);
} else {
this._measureDrag.setLatLng(evt.latlng);
}
this._measureDrag.bringToFront();
} | javascript | function(evt) {
if (!this._measureDrag) {
this._measureDrag = L.circleMarker(evt.latlng, this._symbols.getSymbol('measureDrag')).addTo(
this._layer
);
} else {
this._measureDrag.setLatLng(evt.latlng);
}
this._measureDrag.bringToFront();
} | [
"function",
"(",
"evt",
")",
"{",
"if",
"(",
"!",
"this",
".",
"_measureDrag",
")",
"{",
"this",
".",
"_measureDrag",
"=",
"L",
".",
"circleMarker",
"(",
"evt",
".",
"latlng",
",",
"this",
".",
"_symbols",
".",
"getSymbol",
"(",
"'measureDrag'",
")",
... | mouse move handler while measure in progress adds floating measure marker under cursor | [
"mouse",
"move",
"handler",
"while",
"measure",
"in",
"progress",
"adds",
"floating",
"measure",
"marker",
"under",
"cursor"
] | 756dff840e42a884e7a41bc512e5fd5be130f1ce | https://github.com/ljagis/leaflet-measure/blob/756dff840e42a884e7a41bc512e5fd5be130f1ce/src/leaflet-measure.js#L309-L318 | train | |
ljagis/leaflet-measure | src/leaflet-measure.js | function() {
const latlngs = this._latlngs;
let resultFeature, popupContent;
this._finishMeasure();
if (!latlngs.length) {
return;
}
if (latlngs.length > 2) {
latlngs.push(latlngs[0]); // close path to get full perimeter measurement for areas
}
const calced = calc(latlngs... | javascript | function() {
const latlngs = this._latlngs;
let resultFeature, popupContent;
this._finishMeasure();
if (!latlngs.length) {
return;
}
if (latlngs.length > 2) {
latlngs.push(latlngs[0]); // close path to get full perimeter measurement for areas
}
const calced = calc(latlngs... | [
"function",
"(",
")",
"{",
"const",
"latlngs",
"=",
"this",
".",
"_latlngs",
";",
"let",
"resultFeature",
",",
"popupContent",
";",
"this",
".",
"_finishMeasure",
"(",
")",
";",
"if",
"(",
"!",
"latlngs",
".",
"length",
")",
"{",
"return",
";",
"}",
... | handler for both double click and clicking finish button do final calc and finish out current measure, clear dom and internal state, add permanent map features | [
"handler",
"for",
"both",
"double",
"click",
"and",
"clicking",
"finish",
"button",
"do",
"final",
"calc",
"and",
"finish",
"out",
"current",
"measure",
"clear",
"dom",
"and",
"internal",
"state",
"add",
"permanent",
"map",
"features"
] | 756dff840e42a884e7a41bc512e5fd5be130f1ce | https://github.com/ljagis/leaflet-measure/blob/756dff840e42a884e7a41bc512e5fd5be130f1ce/src/leaflet-measure.js#L321-L398 | train | |
ljagis/leaflet-measure | src/leaflet-measure.js | function(evt) {
const latlng = this._map.mouseEventToLatLng(evt.originalEvent), // get actual latlng instead of the marker's latlng from originalEvent
lastClick = this._latlngs[this._latlngs.length - 1],
vertexSymbol = this._symbols.getSymbol('measureVertex');
if (!lastClick || !latlng.equals(lastC... | javascript | function(evt) {
const latlng = this._map.mouseEventToLatLng(evt.originalEvent), // get actual latlng instead of the marker's latlng from originalEvent
lastClick = this._latlngs[this._latlngs.length - 1],
vertexSymbol = this._symbols.getSymbol('measureVertex');
if (!lastClick || !latlng.equals(lastC... | [
"function",
"(",
"evt",
")",
"{",
"const",
"latlng",
"=",
"this",
".",
"_map",
".",
"mouseEventToLatLng",
"(",
"evt",
".",
"originalEvent",
")",
",",
"// get actual latlng instead of the marker's latlng from originalEvent",
"lastClick",
"=",
"this",
".",
"_latlngs",
... | handle map click during ongoing measurement add new clicked point, update measure layers and results ui | [
"handle",
"map",
"click",
"during",
"ongoing",
"measurement",
"add",
"new",
"clicked",
"point",
"update",
"measure",
"layers",
"and",
"results",
"ui"
] | 756dff840e42a884e7a41bc512e5fd5be130f1ce | https://github.com/ljagis/leaflet-measure/blob/756dff840e42a884e7a41bc512e5fd5be130f1ce/src/leaflet-measure.js#L401-L432 | train | |
que-etc/resize-observer-polyfill | src/utils/geometry.js | getBordersSize | function getBordersSize(styles, ...positions) {
return positions.reduce((size, position) => {
const value = styles['border-' + position + '-width'];
return size + toFloat(value);
}, 0);
} | javascript | function getBordersSize(styles, ...positions) {
return positions.reduce((size, position) => {
const value = styles['border-' + position + '-width'];
return size + toFloat(value);
}, 0);
} | [
"function",
"getBordersSize",
"(",
"styles",
",",
"...",
"positions",
")",
"{",
"return",
"positions",
".",
"reduce",
"(",
"(",
"size",
",",
"position",
")",
"=>",
"{",
"const",
"value",
"=",
"styles",
"[",
"'border-'",
"+",
"position",
"+",
"'-width'",
... | Extracts borders size from provided styles.
@param {CSSStyleDeclaration} styles
@param {...string} positions - Borders positions (top, right, ...)
@returns {number} | [
"Extracts",
"borders",
"size",
"from",
"provided",
"styles",
"."
] | 4a148452494a155656e4d04b9732b5914896b2e0 | https://github.com/que-etc/resize-observer-polyfill/blob/4a148452494a155656e4d04b9732b5914896b2e0/src/utils/geometry.js#L25-L31 | train |
que-etc/resize-observer-polyfill | src/utils/geometry.js | getPaddings | function getPaddings(styles) {
const positions = ['top', 'right', 'bottom', 'left'];
const paddings = {};
for (const position of positions) {
const value = styles['padding-' + position];
paddings[position] = toFloat(value);
}
return paddings;
} | javascript | function getPaddings(styles) {
const positions = ['top', 'right', 'bottom', 'left'];
const paddings = {};
for (const position of positions) {
const value = styles['padding-' + position];
paddings[position] = toFloat(value);
}
return paddings;
} | [
"function",
"getPaddings",
"(",
"styles",
")",
"{",
"const",
"positions",
"=",
"[",
"'top'",
",",
"'right'",
",",
"'bottom'",
",",
"'left'",
"]",
";",
"const",
"paddings",
"=",
"{",
"}",
";",
"for",
"(",
"const",
"position",
"of",
"positions",
")",
"{"... | Extracts paddings sizes from provided styles.
@param {CSSStyleDeclaration} styles
@returns {Object} Paddings box. | [
"Extracts",
"paddings",
"sizes",
"from",
"provided",
"styles",
"."
] | 4a148452494a155656e4d04b9732b5914896b2e0 | https://github.com/que-etc/resize-observer-polyfill/blob/4a148452494a155656e4d04b9732b5914896b2e0/src/utils/geometry.js#L39-L50 | train |
que-etc/resize-observer-polyfill | src/utils/geometry.js | getSVGContentRect | function getSVGContentRect(target) {
const bbox = target.getBBox();
return createRectInit(0, 0, bbox.width, bbox.height);
} | javascript | function getSVGContentRect(target) {
const bbox = target.getBBox();
return createRectInit(0, 0, bbox.width, bbox.height);
} | [
"function",
"getSVGContentRect",
"(",
"target",
")",
"{",
"const",
"bbox",
"=",
"target",
".",
"getBBox",
"(",
")",
";",
"return",
"createRectInit",
"(",
"0",
",",
"0",
",",
"bbox",
".",
"width",
",",
"bbox",
".",
"height",
")",
";",
"}"
] | Calculates content rectangle of provided SVG element.
@param {SVGGraphicsElement} target - Element content rectangle of which needs
to be calculated.
@returns {DOMRectInit} | [
"Calculates",
"content",
"rectangle",
"of",
"provided",
"SVG",
"element",
"."
] | 4a148452494a155656e4d04b9732b5914896b2e0 | https://github.com/que-etc/resize-observer-polyfill/blob/4a148452494a155656e4d04b9732b5914896b2e0/src/utils/geometry.js#L59-L63 | train |
que-etc/resize-observer-polyfill | src/utils/geometry.js | getHTMLElementContentRect | function getHTMLElementContentRect(target) {
// Client width & height properties can't be
// used exclusively as they provide rounded values.
const {clientWidth, clientHeight} = target;
// By this condition we can catch all non-replaced inline, hidden and
// detached elements. Though elements with ... | javascript | function getHTMLElementContentRect(target) {
// Client width & height properties can't be
// used exclusively as they provide rounded values.
const {clientWidth, clientHeight} = target;
// By this condition we can catch all non-replaced inline, hidden and
// detached elements. Though elements with ... | [
"function",
"getHTMLElementContentRect",
"(",
"target",
")",
"{",
"// Client width & height properties can't be",
"// used exclusively as they provide rounded values.",
"const",
"{",
"clientWidth",
",",
"clientHeight",
"}",
"=",
"target",
";",
"// By this condition we can catch all... | Calculates content rectangle of provided HTMLElement.
@param {HTMLElement} target - Element for which to calculate the content rectangle.
@returns {DOMRectInit} | [
"Calculates",
"content",
"rectangle",
"of",
"provided",
"HTMLElement",
"."
] | 4a148452494a155656e4d04b9732b5914896b2e0 | https://github.com/que-etc/resize-observer-polyfill/blob/4a148452494a155656e4d04b9732b5914896b2e0/src/utils/geometry.js#L71-L145 | train |
jhipster/prettier-java | packages/java-parser/scripts/unicode.js | pushInUnicode | function pushInUnicode(cat, elt) {
if (!unicode.hasOwnProperty(cat)) {
unicode[cat] = {
unicode: [],
ranges: []
};
}
if (Array.isArray(elt)) {
unicode[cat].ranges.push(elt);
} else {
unicode[cat].unicode.push(elt);
}
} | javascript | function pushInUnicode(cat, elt) {
if (!unicode.hasOwnProperty(cat)) {
unicode[cat] = {
unicode: [],
ranges: []
};
}
if (Array.isArray(elt)) {
unicode[cat].ranges.push(elt);
} else {
unicode[cat].unicode.push(elt);
}
} | [
"function",
"pushInUnicode",
"(",
"cat",
",",
"elt",
")",
"{",
"if",
"(",
"!",
"unicode",
".",
"hasOwnProperty",
"(",
"cat",
")",
")",
"{",
"unicode",
"[",
"cat",
"]",
"=",
"{",
"unicode",
":",
"[",
"]",
",",
"ranges",
":",
"[",
"]",
"}",
";",
... | Function that pushes in an object an attribute to store the characters | [
"Function",
"that",
"pushes",
"in",
"an",
"object",
"an",
"attribute",
"to",
"store",
"the",
"characters"
] | 3555a0c6e53697f0026bf8bf56403bb6b7719b17 | https://github.com/jhipster/prettier-java/blob/3555a0c6e53697f0026bf8bf56403bb6b7719b17/packages/java-parser/scripts/unicode.js#L35-L48 | train |
jhipster/prettier-java | packages/java-parser/scripts/unicode.js | generateFile | function generateFile() {
let data = `
/*File generated with ../scripts/unicode.js using ../resources/Unicode/UnicodeData.txt.
* As Java Identifiers may contains unicodes letters, this file defines two sets of unicode
* characters, firstIdentChar used to help to determine if a character can be the first letter
... | javascript | function generateFile() {
let data = `
/*File generated with ../scripts/unicode.js using ../resources/Unicode/UnicodeData.txt.
* As Java Identifiers may contains unicodes letters, this file defines two sets of unicode
* characters, firstIdentChar used to help to determine if a character can be the first letter
... | [
"function",
"generateFile",
"(",
")",
"{",
"let",
"data",
"=",
"`",
"`",
";",
"firstIdentCharCategories",
".",
"forEach",
"(",
"el",
"=>",
"{",
"unicode",
"[",
"el",
"]",
".",
"unicode",
".",
"forEach",
"(",
"value",
"=>",
"{",
"data",
"+=",
"`",
"${... | Generating a unicodesets.js file so that we don't have to reparse the file each time the parser is called. | [
"Generating",
"a",
"unicodesets",
".",
"js",
"file",
"so",
"that",
"we",
"don",
"t",
"have",
"to",
"reparse",
"the",
"file",
"each",
"time",
"the",
"parser",
"is",
"called",
"."
] | 3555a0c6e53697f0026bf8bf56403bb6b7719b17 | https://github.com/jhipster/prettier-java/blob/3555a0c6e53697f0026bf8bf56403bb6b7719b17/packages/java-parser/scripts/unicode.js#L151-L237 | train |
stampit-org/stampit | src/stampit.js | standardiseDescriptor | function standardiseDescriptor(descr) {
var4 = {};
var4[_methods] = descr[_methods] || _undefined;
var1 = descr[_properties];
var2 = descr.props;
var4[_properties] = isObject(var1 || var2) ? assign({}, var2, var1) : _undefined;
var4[_initializers] = extractUniqueFunctions(descr.init, descr[_i... | javascript | function standardiseDescriptor(descr) {
var4 = {};
var4[_methods] = descr[_methods] || _undefined;
var1 = descr[_properties];
var2 = descr.props;
var4[_properties] = isObject(var1 || var2) ? assign({}, var2, var1) : _undefined;
var4[_initializers] = extractUniqueFunctions(descr.init, descr[_i... | [
"function",
"standardiseDescriptor",
"(",
"descr",
")",
"{",
"var4",
"=",
"{",
"}",
";",
"var4",
"[",
"_methods",
"]",
"=",
"descr",
"[",
"_methods",
"]",
"||",
"_undefined",
";",
"var1",
"=",
"descr",
"[",
"_properties",
"]",
";",
"var2",
"=",
"descr"... | Converts stampit extended descriptor to a standard one.
@param {Object|*} descr
methods
properties
props
initializers
init
deepProperties
deepProps
propertyDescriptors
staticProperties
statics
staticDeepProperties
deepStatics
staticPropertyDescriptors
configuration
conf
deepConfiguration
deepConf
composers
@returns {De... | [
"Converts",
"stampit",
"extended",
"descriptor",
"to",
"a",
"standard",
"one",
"."
] | 11b1aaad02e5942450366b97f1881346b1171685 | https://github.com/stampit-org/stampit/blob/11b1aaad02e5942450366b97f1881346b1171685/src/stampit.js#L133-L173 | train |
ionic-team/ionic-app-scripts | bin/ion-dev.js | function(msg) {
var status = 'success';
if (msg.type === 'started') {
status = 'active';
this.buildingNotification(true);
} else {
if (msg.data.reloadApp) {
this.reloadApp();
return;
}
status = msg.data.diagnosticsHtml ? 'error' : 'success';
this.buil... | javascript | function(msg) {
var status = 'success';
if (msg.type === 'started') {
status = 'active';
this.buildingNotification(true);
} else {
if (msg.data.reloadApp) {
this.reloadApp();
return;
}
status = msg.data.diagnosticsHtml ? 'error' : 'success';
this.buil... | [
"function",
"(",
"msg",
")",
"{",
"var",
"status",
"=",
"'success'",
";",
"if",
"(",
"msg",
".",
"type",
"===",
"'started'",
")",
"{",
"status",
"=",
"'active'",
";",
"this",
".",
"buildingNotification",
"(",
"true",
")",
";",
"}",
"else",
"{",
"if",... | Process a build update message and display something to the friendly user. | [
"Process",
"a",
"build",
"update",
"message",
"and",
"display",
"something",
"to",
"the",
"friendly",
"user",
"."
] | 5d7ca3825e1aada6a9457a98572d4e86d5e4b0e6 | https://github.com/ionic-team/ionic-app-scripts/blob/5d7ca3825e1aada6a9457a98572d4e86d5e4b0e6/bin/ion-dev.js#L183-L239 | train | |
ionic-team/ionic-app-scripts | lab/static/js/lab.js | bindToggles | function bindToggles() {
// Watch for changes on the checkboxes in the device dropdown
var iphone = $('#device-iphone');
var android = $('#device-android');
var windows = $('#device-windows');
var devices = [iphone, android, windows];
for(var i in devices) {
devices[i].addEventListener('change', functi... | javascript | function bindToggles() {
// Watch for changes on the checkboxes in the device dropdown
var iphone = $('#device-iphone');
var android = $('#device-android');
var windows = $('#device-windows');
var devices = [iphone, android, windows];
for(var i in devices) {
devices[i].addEventListener('change', functi... | [
"function",
"bindToggles",
"(",
")",
"{",
"// Watch for changes on the checkboxes in the device dropdown",
"var",
"iphone",
"=",
"$",
"(",
"'#device-iphone'",
")",
";",
"var",
"android",
"=",
"$",
"(",
"'#device-android'",
")",
";",
"var",
"windows",
"=",
"$",
"("... | Bind the dropdown platform toggles | [
"Bind",
"the",
"dropdown",
"platform",
"toggles"
] | 5d7ca3825e1aada6a9457a98572d4e86d5e4b0e6 | https://github.com/ionic-team/ionic-app-scripts/blob/5d7ca3825e1aada6a9457a98572d4e86d5e4b0e6/lab/static/js/lab.js#L96-L112 | train |
ionic-team/ionic-app-scripts | lab/static/js/lab.js | showDevice | function showDevice(device, isShowing) {
$('#device-' + device).checked = isShowing;
var rendered = $('#' + device);
if(!rendered) {
var template = $('#' + device + '-frame-template');
var clone = document.importNode(template, true);
$('preview').appendChild(clone.content);
//check for extra para... | javascript | function showDevice(device, isShowing) {
$('#device-' + device).checked = isShowing;
var rendered = $('#' + device);
if(!rendered) {
var template = $('#' + device + '-frame-template');
var clone = document.importNode(template, true);
$('preview').appendChild(clone.content);
//check for extra para... | [
"function",
"showDevice",
"(",
"device",
",",
"isShowing",
")",
"{",
"$",
"(",
"'#device-'",
"+",
"device",
")",
".",
"checked",
"=",
"isShowing",
";",
"var",
"rendered",
"=",
"$",
"(",
"'#'",
"+",
"device",
")",
";",
"if",
"(",
"!",
"rendered",
")",... | Show one of the devices | [
"Show",
"one",
"of",
"the",
"devices"
] | 5d7ca3825e1aada6a9457a98572d4e86d5e4b0e6 | https://github.com/ionic-team/ionic-app-scripts/blob/5d7ca3825e1aada6a9457a98572d4e86d5e4b0e6/lab/static/js/lab.js#L115-L133 | train |
angular-slider/angularjs-slider | demo/lib/ui-bootstrap-tpls.js | toggleTopWindowClass | function toggleTopWindowClass(toggleSwitch) {
var modalWindow;
if (openedWindows.length() > 0) {
modalWindow = openedWindows.top().value;
modalWindow.modalDomEl.toggleClass(modalWindow.windowTopClass || '', toggleSwitch);
}
} | javascript | function toggleTopWindowClass(toggleSwitch) {
var modalWindow;
if (openedWindows.length() > 0) {
modalWindow = openedWindows.top().value;
modalWindow.modalDomEl.toggleClass(modalWindow.windowTopClass || '', toggleSwitch);
}
} | [
"function",
"toggleTopWindowClass",
"(",
"toggleSwitch",
")",
"{",
"var",
"modalWindow",
";",
"if",
"(",
"openedWindows",
".",
"length",
"(",
")",
">",
"0",
")",
"{",
"modalWindow",
"=",
"openedWindows",
".",
"top",
"(",
")",
".",
"value",
";",
"modalWindo... | Add or remove "windowTopClass" from the top window in the stack | [
"Add",
"or",
"remove",
"windowTopClass",
"from",
"the",
"top",
"window",
"in",
"the",
"stack"
] | 28bf4e71c5c8e87bce4517974d2c65e6d8a5c295 | https://github.com/angular-slider/angularjs-slider/blob/28bf4e71c5c8e87bce4517974d2c65e6d8a5c295/demo/lib/ui-bootstrap-tpls.js#L3786-L3793 | train |
angular-slider/angularjs-slider | demo/lib/ui-bootstrap-tpls.js | prepareTooltip | function prepareTooltip() {
ttScope.title = attrs[prefix + 'Title'];
if (contentParse) {
ttScope.content = contentParse(scope);
} else {
ttScope.content = attrs[ttType];
}
ttScope.popupClass = attrs[prefix + 'Class'];... | javascript | function prepareTooltip() {
ttScope.title = attrs[prefix + 'Title'];
if (contentParse) {
ttScope.content = contentParse(scope);
} else {
ttScope.content = attrs[ttType];
}
ttScope.popupClass = attrs[prefix + 'Class'];... | [
"function",
"prepareTooltip",
"(",
")",
"{",
"ttScope",
".",
"title",
"=",
"attrs",
"[",
"prefix",
"+",
"'Title'",
"]",
";",
"if",
"(",
"contentParse",
")",
"{",
"ttScope",
".",
"content",
"=",
"contentParse",
"(",
"scope",
")",
";",
"}",
"else",
"{",
... | Set the inital scope values. Once
the tooltip is created, the observers
will be added to keep things in synch. | [
"Set",
"the",
"inital",
"scope",
"values",
".",
"Once",
"the",
"tooltip",
"is",
"created",
"the",
"observers",
"will",
"be",
"added",
"to",
"keep",
"things",
"in",
"synch",
"."
] | 28bf4e71c5c8e87bce4517974d2c65e6d8a5c295 | https://github.com/angular-slider/angularjs-slider/blob/28bf4e71c5c8e87bce4517974d2c65e6d8a5c295/demo/lib/ui-bootstrap-tpls.js#L5204-L5219 | train |
angular-slider/angularjs-slider | demo/lib/ui-bootstrap-tpls.js | recalculatePosition | function recalculatePosition() {
scope.position = appendToBody ? $position.offset(element) : $position.position(element);
scope.position.top += element.prop('offsetHeight');
} | javascript | function recalculatePosition() {
scope.position = appendToBody ? $position.offset(element) : $position.position(element);
scope.position.top += element.prop('offsetHeight');
} | [
"function",
"recalculatePosition",
"(",
")",
"{",
"scope",
".",
"position",
"=",
"appendToBody",
"?",
"$position",
".",
"offset",
"(",
"element",
")",
":",
"$position",
".",
"position",
"(",
"element",
")",
";",
"scope",
".",
"position",
".",
"top",
"+=",
... | recalculate actual position and set new values to scope after digest loop is popup in right position | [
"recalculate",
"actual",
"position",
"and",
"set",
"new",
"values",
"to",
"scope",
"after",
"digest",
"loop",
"is",
"popup",
"in",
"right",
"position"
] | 28bf4e71c5c8e87bce4517974d2c65e6d8a5c295 | https://github.com/angular-slider/angularjs-slider/blob/28bf4e71c5c8e87bce4517974d2c65e6d8a5c295/demo/lib/ui-bootstrap-tpls.js#L7312-L7315 | train |
angular-slider/angularjs-slider | demo/lib/ui-bootstrap-tpls.js | function(evt) {
// Issue #3973
// Firefox treats right click as a click on document
if (element[0] !== evt.target && evt.which !== 3 && scope.matches.length !== 0) {
resetMatches();
if (!$rootScope.$$phase) {
scope.$digest();
}
}
} | javascript | function(evt) {
// Issue #3973
// Firefox treats right click as a click on document
if (element[0] !== evt.target && evt.which !== 3 && scope.matches.length !== 0) {
resetMatches();
if (!$rootScope.$$phase) {
scope.$digest();
}
}
} | [
"function",
"(",
"evt",
")",
"{",
"// Issue #3973",
"// Firefox treats right click as a click on document",
"if",
"(",
"element",
"[",
"0",
"]",
"!==",
"evt",
".",
"target",
"&&",
"evt",
".",
"which",
"!==",
"3",
"&&",
"scope",
".",
"matches",
".",
"length",
... | Keep reference to click handler to unbind it. | [
"Keep",
"reference",
"to",
"click",
"handler",
"to",
"unbind",
"it",
"."
] | 28bf4e71c5c8e87bce4517974d2c65e6d8a5c295 | https://github.com/angular-slider/angularjs-slider/blob/28bf4e71c5c8e87bce4517974d2c65e6d8a5c295/demo/lib/ui-bootstrap-tpls.js#L7410-L7419 | train | |
icebob/fastest-validator | lib/validator.js | Validator | function Validator(opts) {
this.opts = {
messages: deepExtend({}, defaultMessages)
};
if (opts)
deepExtend(this.opts, opts);
this.messages = this.opts.messages;
this.messageKeys = Object.keys(this.messages);
// Load rules
this.rules = loadRules();
this.cache = new Map();
} | javascript | function Validator(opts) {
this.opts = {
messages: deepExtend({}, defaultMessages)
};
if (opts)
deepExtend(this.opts, opts);
this.messages = this.opts.messages;
this.messageKeys = Object.keys(this.messages);
// Load rules
this.rules = loadRules();
this.cache = new Map();
} | [
"function",
"Validator",
"(",
"opts",
")",
"{",
"this",
".",
"opts",
"=",
"{",
"messages",
":",
"deepExtend",
"(",
"{",
"}",
",",
"defaultMessages",
")",
"}",
";",
"if",
"(",
"opts",
")",
"deepExtend",
"(",
"this",
".",
"opts",
",",
"opts",
")",
";... | Validator class constructor
@param {Object} opts | [
"Validator",
"class",
"constructor"
] | a5f2b056bd9d92037b90dd214d0aa2a43073bd6b | https://github.com/icebob/fastest-validator/blob/a5f2b056bd9d92037b90dd214d0aa2a43073bd6b/lib/validator.js#L59-L73 | train |
icebob/fastest-validator | lib/helpers/flatten.js | flatten | function flatten(array, target) {
const result = target || [];
for (let i = 0; i < array.length; ++i) {
if (Array.isArray(array[i])) {
flatten(array[i], result);
}
else {
result.push(array[i]);
}
}
return result;
} | javascript | function flatten(array, target) {
const result = target || [];
for (let i = 0; i < array.length; ++i) {
if (Array.isArray(array[i])) {
flatten(array[i], result);
}
else {
result.push(array[i]);
}
}
return result;
} | [
"function",
"flatten",
"(",
"array",
",",
"target",
")",
"{",
"const",
"result",
"=",
"target",
"||",
"[",
"]",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"array",
".",
"length",
";",
"++",
"i",
")",
"{",
"if",
"(",
"Array",
".",
"... | Flatten an array
@param {Array} array
@param {Array} target
@returns Array flattened array | [
"Flatten",
"an",
"array"
] | a5f2b056bd9d92037b90dd214d0aa2a43073bd6b | https://github.com/icebob/fastest-validator/blob/a5f2b056bd9d92037b90dd214d0aa2a43073bd6b/lib/helpers/flatten.js#L9-L22 | train |
maxazan/jquery-treegrid | js/jquery.treegrid.js | function() {
var $this = $(this);
//Save state on change
$this.on("change", function() {
var $this = $(this);
if (typeof($this.treegrid('getSetting', 'onChange')) === "function") {
$this.treegrid('getSetting', 'onChange').appl... | javascript | function() {
var $this = $(this);
//Save state on change
$this.on("change", function() {
var $this = $(this);
if (typeof($this.treegrid('getSetting', 'onChange')) === "function") {
$this.treegrid('getSetting', 'onChange').appl... | [
"function",
"(",
")",
"{",
"var",
"$this",
"=",
"$",
"(",
"this",
")",
";",
"//Save state on change\r",
"$this",
".",
"on",
"(",
"\"change\"",
",",
"function",
"(",
")",
"{",
"var",
"$this",
"=",
"$",
"(",
"this",
")",
";",
"if",
"(",
"typeof",
"("... | Initialize events from settings
@returns {Node} | [
"Initialize",
"events",
"from",
"settings"
] | 447d66237275cd52ff4c50624920a221caa41ec7 | https://github.com/maxazan/jquery-treegrid/blob/447d66237275cd52ff4c50624920a221caa41ec7/js/jquery.treegrid.js#L80-L106 | train | |
maxazan/jquery-treegrid | js/jquery.treegrid.js | function() {
var $this = $(this);
var cell = $this.find('td').get($this.treegrid('getSetting', 'treeColumn'));
var tpl = $this.treegrid('getSetting', 'expanderTemplate');
var expander = $this.treegrid('getSetting', 'getExpander').apply(this);
if (expander... | javascript | function() {
var $this = $(this);
var cell = $this.find('td').get($this.treegrid('getSetting', 'treeColumn'));
var tpl = $this.treegrid('getSetting', 'expanderTemplate');
var expander = $this.treegrid('getSetting', 'getExpander').apply(this);
if (expander... | [
"function",
"(",
")",
"{",
"var",
"$this",
"=",
"$",
"(",
"this",
")",
";",
"var",
"cell",
"=",
"$this",
".",
"find",
"(",
"'td'",
")",
".",
"get",
"(",
"$this",
".",
"treegrid",
"(",
"'getSetting'",
",",
"'treeColumn'",
")",
")",
";",
"var",
"tp... | Initialize expander for node
@returns {Node} | [
"Initialize",
"expander",
"for",
"node"
] | 447d66237275cd52ff4c50624920a221caa41ec7 | https://github.com/maxazan/jquery-treegrid/blob/447d66237275cd52ff4c50624920a221caa41ec7/js/jquery.treegrid.js#L112-L124 | train | |
maxazan/jquery-treegrid | js/jquery.treegrid.js | function() {
var $this = $(this);
$this.find('.treegrid-indent').remove();
var tpl = $this.treegrid('getSetting', 'indentTemplate');
var expander = $this.find('.treegrid-expander');
var depth = $this.treegrid('getDepth');
for (var i = 0; i < ... | javascript | function() {
var $this = $(this);
$this.find('.treegrid-indent').remove();
var tpl = $this.treegrid('getSetting', 'indentTemplate');
var expander = $this.find('.treegrid-expander');
var depth = $this.treegrid('getDepth');
for (var i = 0; i < ... | [
"function",
"(",
")",
"{",
"var",
"$this",
"=",
"$",
"(",
"this",
")",
";",
"$this",
".",
"find",
"(",
"'.treegrid-indent'",
")",
".",
"remove",
"(",
")",
";",
"var",
"tpl",
"=",
"$this",
".",
"treegrid",
"(",
"'getSetting'",
",",
"'indentTemplate'",
... | Initialize indent for node
@returns {Node} | [
"Initialize",
"indent",
"for",
"node"
] | 447d66237275cd52ff4c50624920a221caa41ec7 | https://github.com/maxazan/jquery-treegrid/blob/447d66237275cd52ff4c50624920a221caa41ec7/js/jquery.treegrid.js#L130-L140 | train | |
maxazan/jquery-treegrid | js/jquery.treegrid.js | function() {
var tree = $(this).treegrid('getTreeContainer');
if (tree.data('first_init') === undefined) {
tree.data('first_init', $.cookie(tree.treegrid('getSetting', 'saveStateName')) === undefined);
}
return tree.data('first_init');
} | javascript | function() {
var tree = $(this).treegrid('getTreeContainer');
if (tree.data('first_init') === undefined) {
tree.data('first_init', $.cookie(tree.treegrid('getSetting', 'saveStateName')) === undefined);
}
return tree.data('first_init');
} | [
"function",
"(",
")",
"{",
"var",
"tree",
"=",
"$",
"(",
"this",
")",
".",
"treegrid",
"(",
"'getTreeContainer'",
")",
";",
"if",
"(",
"tree",
".",
"data",
"(",
"'first_init'",
")",
"===",
"undefined",
")",
"{",
"tree",
".",
"data",
"(",
"'first_init... | Return true if this tree was never been initialised
@returns {Boolean} | [
"Return",
"true",
"if",
"this",
"tree",
"was",
"never",
"been",
"initialised"
] | 447d66237275cd52ff4c50624920a221caa41ec7 | https://github.com/maxazan/jquery-treegrid/blob/447d66237275cd52ff4c50624920a221caa41ec7/js/jquery.treegrid.js#L164-L170 | train | |
maxazan/jquery-treegrid | js/jquery.treegrid.js | function() {
var $this = $(this);
if ($this.treegrid('getSetting', 'saveStateMethod') === 'cookie') {
var stateArrayString = $.cookie($this.treegrid('getSetting', 'saveStateName')) || '';
var stateArray = (stateArrayString === '' ? [] : stateArrayString.spli... | javascript | function() {
var $this = $(this);
if ($this.treegrid('getSetting', 'saveStateMethod') === 'cookie') {
var stateArrayString = $.cookie($this.treegrid('getSetting', 'saveStateName')) || '';
var stateArray = (stateArrayString === '' ? [] : stateArrayString.spli... | [
"function",
"(",
")",
"{",
"var",
"$this",
"=",
"$",
"(",
"this",
")",
";",
"if",
"(",
"$this",
".",
"treegrid",
"(",
"'getSetting'",
",",
"'saveStateMethod'",
")",
"===",
"'cookie'",
")",
"{",
"var",
"stateArrayString",
"=",
"$",
".",
"cookie",
"(",
... | Save state of current node
@returns {Node} | [
"Save",
"state",
"of",
"current",
"node"
] | 447d66237275cd52ff4c50624920a221caa41ec7 | https://github.com/maxazan/jquery-treegrid/blob/447d66237275cd52ff4c50624920a221caa41ec7/js/jquery.treegrid.js#L176-L196 | train | |
maxazan/jquery-treegrid | js/jquery.treegrid.js | function() {
var $this = $(this);
if ($this.treegrid('getSetting', 'saveStateMethod') === 'cookie') {
var stateArray = $.cookie($this.treegrid('getSetting', 'saveStateName')).split(',');
if ($.inArray($this.treegrid('getNodeId'), stateArray) !== -1) {
... | javascript | function() {
var $this = $(this);
if ($this.treegrid('getSetting', 'saveStateMethod') === 'cookie') {
var stateArray = $.cookie($this.treegrid('getSetting', 'saveStateName')).split(',');
if ($.inArray($this.treegrid('getNodeId'), stateArray) !== -1) {
... | [
"function",
"(",
")",
"{",
"var",
"$this",
"=",
"$",
"(",
"this",
")",
";",
"if",
"(",
"$this",
".",
"treegrid",
"(",
"'getSetting'",
",",
"'saveStateMethod'",
")",
"===",
"'cookie'",
")",
"{",
"var",
"stateArray",
"=",
"$",
".",
"cookie",
"(",
"$thi... | Restore state of current node.
@returns {Node} | [
"Restore",
"state",
"of",
"current",
"node",
"."
] | 447d66237275cd52ff4c50624920a221caa41ec7 | https://github.com/maxazan/jquery-treegrid/blob/447d66237275cd52ff4c50624920a221caa41ec7/js/jquery.treegrid.js#L202-L214 | train |
Subsets and Splits
SQL Console for semeru/code-text-javascript
Retrieves 20,000 non-null code samples labeled as JavaScript, providing a basic overview of the dataset.