id
int32
0
58k
repo
stringlengths
5
67
path
stringlengths
4
116
func_name
stringlengths
0
58
original_string
stringlengths
52
373k
language
stringclasses
1 value
code
stringlengths
52
373k
code_tokens
list
docstring
stringlengths
4
11.8k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
86
226
23,300
alexilyaev/stylelint-find-rules
src/lib/cli.js
printUserDeprecated
function printUserDeprecated() { if (!argv.deprecated) { return; } const userDeprecated = _.intersection(rules.stylelintDeprecated, rules.userRulesNames); if (!userDeprecated.length) { return; } const heading = chalk.red.underline('DEPRECATED: Configured rules that are deprecated:'); const rulesToPrint = _.map(userDeprecated, rule => { return { rule: chalk.redBright(rule), url: chalk.cyan(`https://stylelint.io/user-guide/rules/${rule}/`) }; }); printColumns(heading, rulesToPrint); }
javascript
function printUserDeprecated() { if (!argv.deprecated) { return; } const userDeprecated = _.intersection(rules.stylelintDeprecated, rules.userRulesNames); if (!userDeprecated.length) { return; } const heading = chalk.red.underline('DEPRECATED: Configured rules that are deprecated:'); const rulesToPrint = _.map(userDeprecated, rule => { return { rule: chalk.redBright(rule), url: chalk.cyan(`https://stylelint.io/user-guide/rules/${rule}/`) }; }); printColumns(heading, rulesToPrint); }
[ "function", "printUserDeprecated", "(", ")", "{", "if", "(", "!", "argv", ".", "deprecated", ")", "{", "return", ";", "}", "const", "userDeprecated", "=", "_", ".", "intersection", "(", "rules", ".", "stylelintDeprecated", ",", "rules", ".", "userRulesNames", ")", ";", "if", "(", "!", "userDeprecated", ".", "length", ")", "{", "return", ";", "}", "const", "heading", "=", "chalk", ".", "red", ".", "underline", "(", "'DEPRECATED: Configured rules that are deprecated:'", ")", ";", "const", "rulesToPrint", "=", "_", ".", "map", "(", "userDeprecated", ",", "rule", "=>", "{", "return", "{", "rule", ":", "chalk", ".", "redBright", "(", "rule", ")", ",", "url", ":", "chalk", ".", "cyan", "(", "`", "${", "rule", "}", "`", ")", "}", ";", "}", ")", ";", "printColumns", "(", "heading", ",", "rulesToPrint", ")", ";", "}" ]
Print user configured rules that are deprecated
[ "Print", "user", "configured", "rules", "that", "are", "deprecated" ]
5c23235686c56ef463fc61bf6f912e64b23acb94
https://github.com/alexilyaev/stylelint-find-rules/blob/5c23235686c56ef463fc61bf6f912e64b23acb94/src/lib/cli.js#L279-L299
23,301
alexilyaev/stylelint-find-rules
src/lib/cli.js
printUserUnused
function printUserUnused() { if (!argv.unused) { return; } const userUnconfigured = _.difference(rules.stylelintNoDeprecated, rules.userRulesNames); let heading; if (!userUnconfigured.length) { heading = chalk.green('All rules are up-to-date!'); printColumns(heading); return; } const rulesToPrint = _.map(userUnconfigured, rule => { return { rule, url: chalk.cyan(`https://stylelint.io/user-guide/rules/${rule}/`) }; }); heading = chalk.blue.underline('UNUSED: Available rules that are not configured:'); printColumns(heading, rulesToPrint); }
javascript
function printUserUnused() { if (!argv.unused) { return; } const userUnconfigured = _.difference(rules.stylelintNoDeprecated, rules.userRulesNames); let heading; if (!userUnconfigured.length) { heading = chalk.green('All rules are up-to-date!'); printColumns(heading); return; } const rulesToPrint = _.map(userUnconfigured, rule => { return { rule, url: chalk.cyan(`https://stylelint.io/user-guide/rules/${rule}/`) }; }); heading = chalk.blue.underline('UNUSED: Available rules that are not configured:'); printColumns(heading, rulesToPrint); }
[ "function", "printUserUnused", "(", ")", "{", "if", "(", "!", "argv", ".", "unused", ")", "{", "return", ";", "}", "const", "userUnconfigured", "=", "_", ".", "difference", "(", "rules", ".", "stylelintNoDeprecated", ",", "rules", ".", "userRulesNames", ")", ";", "let", "heading", ";", "if", "(", "!", "userUnconfigured", ".", "length", ")", "{", "heading", "=", "chalk", ".", "green", "(", "'All rules are up-to-date!'", ")", ";", "printColumns", "(", "heading", ")", ";", "return", ";", "}", "const", "rulesToPrint", "=", "_", ".", "map", "(", "userUnconfigured", ",", "rule", "=>", "{", "return", "{", "rule", ",", "url", ":", "chalk", ".", "cyan", "(", "`", "${", "rule", "}", "`", ")", "}", ";", "}", ")", ";", "heading", "=", "chalk", ".", "blue", ".", "underline", "(", "'UNUSED: Available rules that are not configured:'", ")", ";", "printColumns", "(", "heading", ",", "rulesToPrint", ")", ";", "}" ]
Print available stylelint rules that the user hasn't configured yet
[ "Print", "available", "stylelint", "rules", "that", "the", "user", "hasn", "t", "configured", "yet" ]
5c23235686c56ef463fc61bf6f912e64b23acb94
https://github.com/alexilyaev/stylelint-find-rules/blob/5c23235686c56ef463fc61bf6f912e64b23acb94/src/lib/cli.js#L304-L329
23,302
alexilyaev/stylelint-find-rules
src/lib/cli.js
printTimingAndExit
function printTimingAndExit(startTime) { const execTime = time() - startTime; printColumns(chalk.green(`Finished in: ${execTime.toFixed()}ms`)); process.exit(0); }
javascript
function printTimingAndExit(startTime) { const execTime = time() - startTime; printColumns(chalk.green(`Finished in: ${execTime.toFixed()}ms`)); process.exit(0); }
[ "function", "printTimingAndExit", "(", "startTime", ")", "{", "const", "execTime", "=", "time", "(", ")", "-", "startTime", ";", "printColumns", "(", "chalk", ".", "green", "(", "`", "${", "execTime", ".", "toFixed", "(", ")", "}", "`", ")", ")", ";", "process", ".", "exit", "(", "0", ")", ";", "}" ]
Print how long it took the tool to execute
[ "Print", "how", "long", "it", "took", "the", "tool", "to", "execute" ]
5c23235686c56ef463fc61bf6f912e64b23acb94
https://github.com/alexilyaev/stylelint-find-rules/blob/5c23235686c56ef463fc61bf6f912e64b23acb94/src/lib/cli.js#L334-L339
23,303
swissquote/crafty
packages/crafty/src/configuration.js
resolveModule
function resolveModule(module) { debug("resolveModule", module); const presetName = module; if (path.isAbsolute(presetName)) { return [getPresetName(module), module]; } try { // Try the naive way return [presetName, require.resolve(module)]; } catch (e) { // Try a more advanced way return [presetName, resolve.sync(process.cwd() + "/node_modules", module)]; } }
javascript
function resolveModule(module) { debug("resolveModule", module); const presetName = module; if (path.isAbsolute(presetName)) { return [getPresetName(module), module]; } try { // Try the naive way return [presetName, require.resolve(module)]; } catch (e) { // Try a more advanced way return [presetName, resolve.sync(process.cwd() + "/node_modules", module)]; } }
[ "function", "resolveModule", "(", "module", ")", "{", "debug", "(", "\"resolveModule\"", ",", "module", ")", ";", "const", "presetName", "=", "module", ";", "if", "(", "path", ".", "isAbsolute", "(", "presetName", ")", ")", "{", "return", "[", "getPresetName", "(", "module", ")", ",", "module", "]", ";", "}", "try", "{", "// Try the naive way", "return", "[", "presetName", ",", "require", ".", "resolve", "(", "module", ")", "]", ";", "}", "catch", "(", "e", ")", "{", "// Try a more advanced way", "return", "[", "presetName", ",", "resolve", ".", "sync", "(", "process", ".", "cwd", "(", ")", "+", "\"/node_modules\"", ",", "module", ")", "]", ";", "}", "}" ]
A module can be a a full path or just a module name From that we'll try to find the name of the preset and the file that contains it. @param {String} module
[ "A", "module", "can", "be", "a", "a", "full", "path", "or", "just", "a", "module", "name", "From", "that", "we", "ll", "try", "to", "find", "the", "name", "of", "the", "preset", "and", "the", "file", "that", "contains", "it", "." ]
ff88203810516a5ff73a0705d20afc6857bfd445
https://github.com/swissquote/crafty/blob/ff88203810516a5ff73a0705d20afc6857bfd445/packages/crafty/src/configuration.js#L21-L37
23,304
swissquote/crafty
packages/crafty/src/configuration.js
getPresetName
function getPresetName(file) { const packageJson = findUp.sync("package.json", { cwd: path.dirname(file) }); if (packageJson) { return require(packageJson).name || file; } return file; }
javascript
function getPresetName(file) { const packageJson = findUp.sync("package.json", { cwd: path.dirname(file) }); if (packageJson) { return require(packageJson).name || file; } return file; }
[ "function", "getPresetName", "(", "file", ")", "{", "const", "packageJson", "=", "findUp", ".", "sync", "(", "\"package.json\"", ",", "{", "cwd", ":", "path", ".", "dirname", "(", "file", ")", "}", ")", ";", "if", "(", "packageJson", ")", "{", "return", "require", "(", "packageJson", ")", ".", "name", "||", "file", ";", "}", "return", "file", ";", "}" ]
Get the package's name or the filename if nothing is found @param {*} file
[ "Get", "the", "package", "s", "name", "or", "the", "filename", "if", "nothing", "is", "found" ]
ff88203810516a5ff73a0705d20afc6857bfd445
https://github.com/swissquote/crafty/blob/ff88203810516a5ff73a0705d20afc6857bfd445/packages/crafty/src/configuration.js#L58-L66
23,305
swissquote/crafty
packages/crafty/src/configuration.js
getOverrides
function getOverrides() { const configPath = path.join(process.cwd(), "crafty.config.js"); if (fs.existsSync(configPath)) { return require(configPath); } console.log(`No crafty.config.js found in '${process.cwd()}', proceeding...`); return {}; }
javascript
function getOverrides() { const configPath = path.join(process.cwd(), "crafty.config.js"); if (fs.existsSync(configPath)) { return require(configPath); } console.log(`No crafty.config.js found in '${process.cwd()}', proceeding...`); return {}; }
[ "function", "getOverrides", "(", ")", "{", "const", "configPath", "=", "path", ".", "join", "(", "process", ".", "cwd", "(", ")", ",", "\"crafty.config.js\"", ")", ";", "if", "(", "fs", ".", "existsSync", "(", "configPath", ")", ")", "{", "return", "require", "(", "configPath", ")", ";", "}", "console", ".", "log", "(", "`", "${", "process", ".", "cwd", "(", ")", "}", "`", ")", ";", "return", "{", "}", ";", "}" ]
Get the user's configuration @return {*} A configuration object
[ "Get", "the", "user", "s", "configuration" ]
ff88203810516a5ff73a0705d20afc6857bfd445
https://github.com/swissquote/crafty/blob/ff88203810516a5ff73a0705d20afc6857bfd445/packages/crafty/src/configuration.js#L221-L230
23,306
swissquote/crafty
packages/crafty-runner-webpack/src/webpack_output.js
sortFiles
function sortFiles(files) { const modules = []; const assets = []; let isAssets = false; for (var i in files) { const row = files[i]; if (row[0] == "size" && row[2] == "asset") { isAssets = true; } if (row[0] == "size" || row[0] == "") { continue; } if (isAssets) { assets.push(row); } else { modules.push(row); } } const final = []; if (modules.length) { final.push(["size", "name", "module", "status"]); final.push(...modules.sort((a, b) => a[1] - b[1])); } if (modules.length && assets.length) { final.push(["", "", "", ""]); } if (assets.length) { final.push(["size", "name", "asset", "status"]); final.push( ...assets.sort((a, b) => { if (a[2] < b[2]) return -1; if (a[2] > b[2]) return 1; return 0; }) ); } // Replacing the file sizes in output log // to have predictable snapshot output // when testing Crafty. As webpack seems // to create differences in various environments // without differences in the actual output's size if (process.env.TESTING_CRAFTY) { return final.map(item => { if (item[0] != "" && item[0] != "size") { item[0] = 1000; } return item; }); } return final; }
javascript
function sortFiles(files) { const modules = []; const assets = []; let isAssets = false; for (var i in files) { const row = files[i]; if (row[0] == "size" && row[2] == "asset") { isAssets = true; } if (row[0] == "size" || row[0] == "") { continue; } if (isAssets) { assets.push(row); } else { modules.push(row); } } const final = []; if (modules.length) { final.push(["size", "name", "module", "status"]); final.push(...modules.sort((a, b) => a[1] - b[1])); } if (modules.length && assets.length) { final.push(["", "", "", ""]); } if (assets.length) { final.push(["size", "name", "asset", "status"]); final.push( ...assets.sort((a, b) => { if (a[2] < b[2]) return -1; if (a[2] > b[2]) return 1; return 0; }) ); } // Replacing the file sizes in output log // to have predictable snapshot output // when testing Crafty. As webpack seems // to create differences in various environments // without differences in the actual output's size if (process.env.TESTING_CRAFTY) { return final.map(item => { if (item[0] != "" && item[0] != "size") { item[0] = 1000; } return item; }); } return final; }
[ "function", "sortFiles", "(", "files", ")", "{", "const", "modules", "=", "[", "]", ";", "const", "assets", "=", "[", "]", ";", "let", "isAssets", "=", "false", ";", "for", "(", "var", "i", "in", "files", ")", "{", "const", "row", "=", "files", "[", "i", "]", ";", "if", "(", "row", "[", "0", "]", "==", "\"size\"", "&&", "row", "[", "2", "]", "==", "\"asset\"", ")", "{", "isAssets", "=", "true", ";", "}", "if", "(", "row", "[", "0", "]", "==", "\"size\"", "||", "row", "[", "0", "]", "==", "\"\"", ")", "{", "continue", ";", "}", "if", "(", "isAssets", ")", "{", "assets", ".", "push", "(", "row", ")", ";", "}", "else", "{", "modules", ".", "push", "(", "row", ")", ";", "}", "}", "const", "final", "=", "[", "]", ";", "if", "(", "modules", ".", "length", ")", "{", "final", ".", "push", "(", "[", "\"size\"", ",", "\"name\"", ",", "\"module\"", ",", "\"status\"", "]", ")", ";", "final", ".", "push", "(", "...", "modules", ".", "sort", "(", "(", "a", ",", "b", ")", "=>", "a", "[", "1", "]", "-", "b", "[", "1", "]", ")", ")", ";", "}", "if", "(", "modules", ".", "length", "&&", "assets", ".", "length", ")", "{", "final", ".", "push", "(", "[", "\"\"", ",", "\"\"", ",", "\"\"", ",", "\"\"", "]", ")", ";", "}", "if", "(", "assets", ".", "length", ")", "{", "final", ".", "push", "(", "[", "\"size\"", ",", "\"name\"", ",", "\"asset\"", ",", "\"status\"", "]", ")", ";", "final", ".", "push", "(", "...", "assets", ".", "sort", "(", "(", "a", ",", "b", ")", "=>", "{", "if", "(", "a", "[", "2", "]", "<", "b", "[", "2", "]", ")", "return", "-", "1", ";", "if", "(", "a", "[", "2", "]", ">", "b", "[", "2", "]", ")", "return", "1", ";", "return", "0", ";", "}", ")", ")", ";", "}", "// Replacing the file sizes in output log", "// to have predictable snapshot output", "// when testing Crafty. As webpack seems", "// to create differences in various environments", "// without differences in the actual output's size", "if", "(", "process", ".", "env", ".", "TESTING_CRAFTY", ")", "{", "return", "final", ".", "map", "(", "item", "=>", "{", "if", "(", "item", "[", "0", "]", "!=", "\"\"", "&&", "item", "[", "0", "]", "!=", "\"size\"", ")", "{", "item", "[", "0", "]", "=", "1000", ";", "}", "return", "item", ";", "}", ")", ";", "}", "return", "final", ";", "}" ]
Sort the files order. The main reason is that test snapshots need the order to stay the same. For some reason this isn't the case sometimes. @param {*} files
[ "Sort", "the", "files", "order", ".", "The", "main", "reason", "is", "that", "test", "snapshots", "need", "the", "order", "to", "stay", "the", "same", ".", "For", "some", "reason", "this", "isn", "t", "the", "case", "sometimes", "." ]
ff88203810516a5ff73a0705d20afc6857bfd445
https://github.com/swissquote/crafty/blob/ff88203810516a5ff73a0705d20afc6857bfd445/packages/crafty-runner-webpack/src/webpack_output.js#L14-L75
23,307
rafrex/react-interactive
src/inputTracker.js
updateMouse
function updateMouse(e) { input.mouse.clientX = e.clientX; input.mouse.clientY = e.clientY; input.mouse.buttons = e.buttons; if (e.type === 'mouseleave') input.mouse.mouseOnDocument = false; else input.mouse.mouseOnDocument = true; }
javascript
function updateMouse(e) { input.mouse.clientX = e.clientX; input.mouse.clientY = e.clientY; input.mouse.buttons = e.buttons; if (e.type === 'mouseleave') input.mouse.mouseOnDocument = false; else input.mouse.mouseOnDocument = true; }
[ "function", "updateMouse", "(", "e", ")", "{", "input", ".", "mouse", ".", "clientX", "=", "e", ".", "clientX", ";", "input", ".", "mouse", ".", "clientY", "=", "e", ".", "clientY", ";", "input", ".", "mouse", ".", "buttons", "=", "e", ".", "buttons", ";", "if", "(", "e", ".", "type", "===", "'mouseleave'", ")", "input", ".", "mouse", ".", "mouseOnDocument", "=", "false", ";", "else", "input", ".", "mouse", ".", "mouseOnDocument", "=", "true", ";", "}" ]
update mouse input tracking
[ "update", "mouse", "input", "tracking" ]
65b802b7915d1241c24cbba8770e6b066182c243
https://github.com/rafrex/react-interactive/blob/65b802b7915d1241c24cbba8770e6b066182c243/src/inputTracker.js#L50-L56
23,308
rafrex/react-interactive
src/inputTracker.js
updateHybridMouse
function updateHybridMouse(e) { if (input.touch.recentTouch || input.touch.touchOnScreen) return; updateMouse(e); }
javascript
function updateHybridMouse(e) { if (input.touch.recentTouch || input.touch.touchOnScreen) return; updateMouse(e); }
[ "function", "updateHybridMouse", "(", "e", ")", "{", "if", "(", "input", ".", "touch", ".", "recentTouch", "||", "input", ".", "touch", ".", "touchOnScreen", ")", "return", ";", "updateMouse", "(", "e", ")", ";", "}" ]
only update mouse if the mouse event is not from a touch event
[ "only", "update", "mouse", "if", "the", "mouse", "event", "is", "not", "from", "a", "touch", "event" ]
65b802b7915d1241c24cbba8770e6b066182c243
https://github.com/rafrex/react-interactive/blob/65b802b7915d1241c24cbba8770e6b066182c243/src/inputTracker.js#L59-L62
23,309
rafrex/react-interactive
src/notifier.js
handleNotifyNext
function handleNotifyNext(e) { if (notifyOfNextSubs[e.type].length === 0) return; e.persist = blankFunction; const reNotifyOfNext = []; const reNotifyOfNextIDs = {}; notifyOfNextSubs[e.type].forEach(sub => { if (sub.callback(e) === 'reNotifyOfNext') { reNotifyOfNextIDs[sub.id] = reNotifyOfNext.push(sub) - 1; } }); notifyOfNextSubs[e.type] = reNotifyOfNext; subsIDs[e.type] = reNotifyOfNextIDs; }
javascript
function handleNotifyNext(e) { if (notifyOfNextSubs[e.type].length === 0) return; e.persist = blankFunction; const reNotifyOfNext = []; const reNotifyOfNextIDs = {}; notifyOfNextSubs[e.type].forEach(sub => { if (sub.callback(e) === 'reNotifyOfNext') { reNotifyOfNextIDs[sub.id] = reNotifyOfNext.push(sub) - 1; } }); notifyOfNextSubs[e.type] = reNotifyOfNext; subsIDs[e.type] = reNotifyOfNextIDs; }
[ "function", "handleNotifyNext", "(", "e", ")", "{", "if", "(", "notifyOfNextSubs", "[", "e", ".", "type", "]", ".", "length", "===", "0", ")", "return", ";", "e", ".", "persist", "=", "blankFunction", ";", "const", "reNotifyOfNext", "=", "[", "]", ";", "const", "reNotifyOfNextIDs", "=", "{", "}", ";", "notifyOfNextSubs", "[", "e", ".", "type", "]", ".", "forEach", "(", "sub", "=>", "{", "if", "(", "sub", ".", "callback", "(", "e", ")", "===", "'reNotifyOfNext'", ")", "{", "reNotifyOfNextIDs", "[", "sub", ".", "id", "]", "=", "reNotifyOfNext", ".", "push", "(", "sub", ")", "-", "1", ";", "}", "}", ")", ";", "notifyOfNextSubs", "[", "e", ".", "type", "]", "=", "reNotifyOfNext", ";", "subsIDs", "[", "e", ".", "type", "]", "=", "reNotifyOfNextIDs", ";", "}" ]
notify next when event comes, if the callback returns 'reNotifyOfNext', then re-subscribe using the same id
[ "notify", "next", "when", "event", "comes", "if", "the", "callback", "returns", "reNotifyOfNext", "then", "re", "-", "subscribe", "using", "the", "same", "id" ]
65b802b7915d1241c24cbba8770e6b066182c243
https://github.com/rafrex/react-interactive/blob/65b802b7915d1241c24cbba8770e6b066182c243/src/notifier.js#L74-L86
23,310
rafrex/react-interactive
src/notifier.js
setupEvent
function setupEvent(element, eType, handler, capture) { notifyOfNextSubs[eType] = []; subsIDs[eType] = {}; element.addEventListener( eType, handler, passiveEventSupport ? { capture, // don't set click listener as passive because syntheticClick may call preventDefault passive: eType !== 'click', } : capture, ); }
javascript
function setupEvent(element, eType, handler, capture) { notifyOfNextSubs[eType] = []; subsIDs[eType] = {}; element.addEventListener( eType, handler, passiveEventSupport ? { capture, // don't set click listener as passive because syntheticClick may call preventDefault passive: eType !== 'click', } : capture, ); }
[ "function", "setupEvent", "(", "element", ",", "eType", ",", "handler", ",", "capture", ")", "{", "notifyOfNextSubs", "[", "eType", "]", "=", "[", "]", ";", "subsIDs", "[", "eType", "]", "=", "{", "}", ";", "element", ".", "addEventListener", "(", "eType", ",", "handler", ",", "passiveEventSupport", "?", "{", "capture", ",", "// don't set click listener as passive because syntheticClick may call preventDefault", "passive", ":", "eType", "!==", "'click'", ",", "}", ":", "capture", ",", ")", ";", "}" ]
setup event listeners and notification system for events
[ "setup", "event", "listeners", "and", "notification", "system", "for", "events" ]
65b802b7915d1241c24cbba8770e6b066182c243
https://github.com/rafrex/react-interactive/blob/65b802b7915d1241c24cbba8770e6b066182c243/src/notifier.js#L94-L108
23,311
tkalfigo/dotenvenc
index.js
exists
function exists(fileOrDir) { let stats; try { stats = statSync(fileOrDir); return stats.isFile() || stats.isDirectory(); } catch (err) { return false; } }
javascript
function exists(fileOrDir) { let stats; try { stats = statSync(fileOrDir); return stats.isFile() || stats.isDirectory(); } catch (err) { return false; } }
[ "function", "exists", "(", "fileOrDir", ")", "{", "let", "stats", ";", "try", "{", "stats", "=", "statSync", "(", "fileOrDir", ")", ";", "return", "stats", ".", "isFile", "(", ")", "||", "stats", ".", "isDirectory", "(", ")", ";", "}", "catch", "(", "err", ")", "{", "return", "false", ";", "}", "}" ]
Checks if a file or directory exists @param {String} fileOrDir name of file or directory @returns {Boolean} if @fileOrDir exists and is readable file or directory
[ "Checks", "if", "a", "file", "or", "directory", "exists" ]
1ebb0de439fa274b049029d79e02e1587be0f021
https://github.com/tkalfigo/dotenvenc/blob/1ebb0de439fa274b049029d79e02e1587be0f021/index.js#L17-L25
23,312
tkalfigo/dotenvenc
index.js
findFileLocation
function findFileLocation(file) { let location = './'; while (true) { if (exists(location + file)) { break; } else if (exists(location + 'package.json') || location === '/') { // Assumption is that reaching the app root folder or the system '/' marks the end of the search throw new Error(`Failed to find file "${file}" within the project`); } // Go one level up location = path.resolve('../' + location) + '/'; } return location; }
javascript
function findFileLocation(file) { let location = './'; while (true) { if (exists(location + file)) { break; } else if (exists(location + 'package.json') || location === '/') { // Assumption is that reaching the app root folder or the system '/' marks the end of the search throw new Error(`Failed to find file "${file}" within the project`); } // Go one level up location = path.resolve('../' + location) + '/'; } return location; }
[ "function", "findFileLocation", "(", "file", ")", "{", "let", "location", "=", "'./'", ";", "while", "(", "true", ")", "{", "if", "(", "exists", "(", "location", "+", "file", ")", ")", "{", "break", ";", "}", "else", "if", "(", "exists", "(", "location", "+", "'package.json'", ")", "||", "location", "===", "'/'", ")", "{", "// Assumption is that reaching the app root folder or the system '/' marks the end of the search", "throw", "new", "Error", "(", "`", "${", "file", "}", "`", ")", ";", "}", "// Go one level up", "location", "=", "path", ".", "resolve", "(", "'../'", "+", "location", ")", "+", "'/'", ";", "}", "return", "location", ";", "}" ]
Goes up folder hierarchy looking for encrypted file; search stops when either root folder or folder with 'package.json' is reached @param {String} file the file to look for @returns {String} the full pathname of passed @file or throws error if not found
[ "Goes", "up", "folder", "hierarchy", "looking", "for", "encrypted", "file", ";", "search", "stops", "when", "either", "root", "folder", "or", "folder", "with", "package", ".", "json", "is", "reached" ]
1ebb0de439fa274b049029d79e02e1587be0f021
https://github.com/tkalfigo/dotenvenc/blob/1ebb0de439fa274b049029d79e02e1587be0f021/index.js#L32-L45
23,313
mathiasvr/audio-oscilloscope
examples/custom.js
drawLoop
function drawLoop () { ctx.clearRect(0, 0, canvas.width, canvas.height) var centerX = canvas.width / 2 var centerY = canvas.height / 2 // draw circle ctx.beginPath() ctx.arc(centerX, centerY, 100, 0, 2 * Math.PI, false) ctx.fillStyle = 'yellow' ctx.fill() // draw three oscilloscopes in different positions and colors ctx.strokeStyle = 'lime' scope.draw(ctx, 0, 0, centerX, centerY) ctx.strokeStyle = 'cyan' scope.draw(ctx, centerX, 0, centerX, centerY) ctx.strokeStyle = 'red' scope.draw(ctx, 0, centerY, null, centerY) window.requestAnimationFrame(drawLoop) }
javascript
function drawLoop () { ctx.clearRect(0, 0, canvas.width, canvas.height) var centerX = canvas.width / 2 var centerY = canvas.height / 2 // draw circle ctx.beginPath() ctx.arc(centerX, centerY, 100, 0, 2 * Math.PI, false) ctx.fillStyle = 'yellow' ctx.fill() // draw three oscilloscopes in different positions and colors ctx.strokeStyle = 'lime' scope.draw(ctx, 0, 0, centerX, centerY) ctx.strokeStyle = 'cyan' scope.draw(ctx, centerX, 0, centerX, centerY) ctx.strokeStyle = 'red' scope.draw(ctx, 0, centerY, null, centerY) window.requestAnimationFrame(drawLoop) }
[ "function", "drawLoop", "(", ")", "{", "ctx", ".", "clearRect", "(", "0", ",", "0", ",", "canvas", ".", "width", ",", "canvas", ".", "height", ")", "var", "centerX", "=", "canvas", ".", "width", "/", "2", "var", "centerY", "=", "canvas", ".", "height", "/", "2", "// draw circle", "ctx", ".", "beginPath", "(", ")", "ctx", ".", "arc", "(", "centerX", ",", "centerY", ",", "100", ",", "0", ",", "2", "*", "Math", ".", "PI", ",", "false", ")", "ctx", ".", "fillStyle", "=", "'yellow'", "ctx", ".", "fill", "(", ")", "// draw three oscilloscopes in different positions and colors", "ctx", ".", "strokeStyle", "=", "'lime'", "scope", ".", "draw", "(", "ctx", ",", "0", ",", "0", ",", "centerX", ",", "centerY", ")", "ctx", ".", "strokeStyle", "=", "'cyan'", "scope", ".", "draw", "(", "ctx", ",", "centerX", ",", "0", ",", "centerX", ",", "centerY", ")", "ctx", ".", "strokeStyle", "=", "'red'", "scope", ".", "draw", "(", "ctx", ",", "0", ",", "centerY", ",", "null", ",", "centerY", ")", "window", ".", "requestAnimationFrame", "(", "drawLoop", ")", "}" ]
custom animation loop
[ "custom", "animation", "loop" ]
c93a6d3237dc2c13d4e5415e55136f9223b7dfc4
https://github.com/mathiasvr/audio-oscilloscope/blob/c93a6d3237dc2c13d4e5415e55136f9223b7dfc4/examples/custom.js#L30-L53
23,314
chinedufn/collada-dae-parser
demo/animated-model/animate/animation-target.js
ToggleAnimation
function ToggleAnimation (AppState) { var state = AppState.get() if ( state.currentAnimation[0] === animationDictionary.bend[0] && state.currentAnimation[1] === animationDictionary.bend[1] ) { state.currentAnimation = animationDictionary.jump } else { state.currentAnimation = animationDictionary.bend } AppState.set(state) }
javascript
function ToggleAnimation (AppState) { var state = AppState.get() if ( state.currentAnimation[0] === animationDictionary.bend[0] && state.currentAnimation[1] === animationDictionary.bend[1] ) { state.currentAnimation = animationDictionary.jump } else { state.currentAnimation = animationDictionary.bend } AppState.set(state) }
[ "function", "ToggleAnimation", "(", "AppState", ")", "{", "var", "state", "=", "AppState", ".", "get", "(", ")", "if", "(", "state", ".", "currentAnimation", "[", "0", "]", "===", "animationDictionary", ".", "bend", "[", "0", "]", "&&", "state", ".", "currentAnimation", "[", "1", "]", "===", "animationDictionary", ".", "bend", "[", "1", "]", ")", "{", "state", ".", "currentAnimation", "=", "animationDictionary", ".", "jump", "}", "else", "{", "state", ".", "currentAnimation", "=", "animationDictionary", ".", "bend", "}", "AppState", ".", "set", "(", "state", ")", "}" ]
We have two animations This switches from one animation to the other
[ "We", "have", "two", "animations", "This", "switches", "from", "one", "animation", "to", "the", "other" ]
b7f0c69bfc0b96e82a2c5b548d8b8fa73109b35e
https://github.com/chinedufn/collada-dae-parser/blob/b7f0c69bfc0b96e82a2c5b548d8b8fa73109b35e/demo/animated-model/animate/animation-target.js#L19-L31
23,315
chinedufn/collada-dae-parser
src/parse-collada.js
compactXML
function compactXML (res, xml) { var txt = Object.keys(xml.attributes).length === 0 && xml.children.length === 0 var r = {} if (!res[xml.name]) res[xml.name] = [] if (txt) { r = xml.content || '' } else { r.$ = xml.attributes r._ = xml.content || '' xml.children.forEach(function (ch) { compactXML(r, ch) }) } res[xml.name].push(r) return res }
javascript
function compactXML (res, xml) { var txt = Object.keys(xml.attributes).length === 0 && xml.children.length === 0 var r = {} if (!res[xml.name]) res[xml.name] = [] if (txt) { r = xml.content || '' } else { r.$ = xml.attributes r._ = xml.content || '' xml.children.forEach(function (ch) { compactXML(r, ch) }) } res[xml.name].push(r) return res }
[ "function", "compactXML", "(", "res", ",", "xml", ")", "{", "var", "txt", "=", "Object", ".", "keys", "(", "xml", ".", "attributes", ")", ".", "length", "===", "0", "&&", "xml", ".", "children", ".", "length", "===", "0", "var", "r", "=", "{", "}", "if", "(", "!", "res", "[", "xml", ".", "name", "]", ")", "res", "[", "xml", ".", "name", "]", "=", "[", "]", "if", "(", "txt", ")", "{", "r", "=", "xml", ".", "content", "||", "''", "}", "else", "{", "r", ".", "$", "=", "xml", ".", "attributes", "r", ".", "_", "=", "xml", ".", "content", "||", "''", "xml", ".", "children", ".", "forEach", "(", "function", "(", "ch", ")", "{", "compactXML", "(", "r", ",", "ch", ")", "}", ")", "}", "res", "[", "xml", ".", "name", "]", ".", "push", "(", "r", ")", "return", "res", "}" ]
We used to use a different XML parsing library. This recursively transforms the data that we get from our new XML parser to match the old one. This is a stopgap measure until we get around to changing the keys that we look while we parse to the keys that the new parser expects
[ "We", "used", "to", "use", "a", "different", "XML", "parsing", "library", ".", "This", "recursively", "transforms", "the", "data", "that", "we", "get", "from", "our", "new", "XML", "parser", "to", "match", "the", "old", "one", ".", "This", "is", "a", "stopgap", "measure", "until", "we", "get", "around", "to", "changing", "the", "keys", "that", "we", "look", "while", "we", "parse", "to", "the", "keys", "that", "the", "new", "parser", "expects" ]
b7f0c69bfc0b96e82a2c5b548d8b8fa73109b35e
https://github.com/chinedufn/collada-dae-parser/blob/b7f0c69bfc0b96e82a2c5b548d8b8fa73109b35e/src/parse-collada.js#L88-L103
23,316
chinedufn/collada-dae-parser
src/library_visual_scenes/parse-visual-scenes.js
parseJoints
function parseJoints (node, parentJointName, accumulator) { accumulator = accumulator || {} node.forEach(function (joint) { accumulator[joint.$.sid] = accumulator[joint.$.sid] || {} // The bind pose of the matrix. We don't make use of this right now, but you would // use it to render a model in bind pose. Right now we only render the model based on // their animated joint positions, so we ignore this bind pose data accumulator[joint.$.sid].jointMatrix = joint.matrix[0]._.split(' ').map(Number) accumulator[joint.$.sid].parent = parentJointName if (joint.node) { parseJoints(joint.node, joint.$.sid, accumulator) } }) return accumulator }
javascript
function parseJoints (node, parentJointName, accumulator) { accumulator = accumulator || {} node.forEach(function (joint) { accumulator[joint.$.sid] = accumulator[joint.$.sid] || {} // The bind pose of the matrix. We don't make use of this right now, but you would // use it to render a model in bind pose. Right now we only render the model based on // their animated joint positions, so we ignore this bind pose data accumulator[joint.$.sid].jointMatrix = joint.matrix[0]._.split(' ').map(Number) accumulator[joint.$.sid].parent = parentJointName if (joint.node) { parseJoints(joint.node, joint.$.sid, accumulator) } }) return accumulator }
[ "function", "parseJoints", "(", "node", ",", "parentJointName", ",", "accumulator", ")", "{", "accumulator", "=", "accumulator", "||", "{", "}", "node", ".", "forEach", "(", "function", "(", "joint", ")", "{", "accumulator", "[", "joint", ".", "$", ".", "sid", "]", "=", "accumulator", "[", "joint", ".", "$", ".", "sid", "]", "||", "{", "}", "// The bind pose of the matrix. We don't make use of this right now, but you would", "// use it to render a model in bind pose. Right now we only render the model based on", "// their animated joint positions, so we ignore this bind pose data", "accumulator", "[", "joint", ".", "$", ".", "sid", "]", ".", "jointMatrix", "=", "joint", ".", "matrix", "[", "0", "]", ".", "_", ".", "split", "(", "' '", ")", ".", "map", "(", "Number", ")", "accumulator", "[", "joint", ".", "$", ".", "sid", "]", ".", "parent", "=", "parentJointName", "if", "(", "joint", ".", "node", ")", "{", "parseJoints", "(", "joint", ".", "node", ",", "joint", ".", "$", ".", "sid", ",", "accumulator", ")", "}", "}", ")", "return", "accumulator", "}" ]
Recursively parse child joints
[ "Recursively", "parse", "child", "joints" ]
b7f0c69bfc0b96e82a2c5b548d8b8fa73109b35e
https://github.com/chinedufn/collada-dae-parser/blob/b7f0c69bfc0b96e82a2c5b548d8b8fa73109b35e/src/library_visual_scenes/parse-visual-scenes.js#L34-L49
23,317
WebReflection/workway
node/index.js
createSandbox
function createSandbox(filename, socket) { var self = new EventEmitter; var listeners = new WeakMap; self.addEventListener = function (type, listener) { if (!listeners.has(listener)) { var facade = function (event) { if (!event.canceled) listener.apply(this, arguments); }; listeners.set(listener, facade); self.on(type, facade); } }; self.removeEventListener = function (type, listener) { self.removeListener(type, listeners.get(listener)); }; self.__filename = filename; self.__dirname = path.dirname(filename); self.postMessage = function postMessage(data) { message(socket, data); }; self.console = console; self.process = process; self.Buffer = Buffer; self.clearImmediate = clearImmediate; self.clearInterval = clearInterval; self.clearTimeout = clearTimeout; self.setImmediate = setImmediate; self.setInterval = setInterval; self.setTimeout = setTimeout; self.module = module; self.global = self; self.self = self; self.require = function (file) { switch (true) { case file === 'workway': return self.workway; case /^[./]/.test(file): file = path.resolve(self.__dirname, file); default: return require(file); } }; return self; }
javascript
function createSandbox(filename, socket) { var self = new EventEmitter; var listeners = new WeakMap; self.addEventListener = function (type, listener) { if (!listeners.has(listener)) { var facade = function (event) { if (!event.canceled) listener.apply(this, arguments); }; listeners.set(listener, facade); self.on(type, facade); } }; self.removeEventListener = function (type, listener) { self.removeListener(type, listeners.get(listener)); }; self.__filename = filename; self.__dirname = path.dirname(filename); self.postMessage = function postMessage(data) { message(socket, data); }; self.console = console; self.process = process; self.Buffer = Buffer; self.clearImmediate = clearImmediate; self.clearInterval = clearInterval; self.clearTimeout = clearTimeout; self.setImmediate = setImmediate; self.setInterval = setInterval; self.setTimeout = setTimeout; self.module = module; self.global = self; self.self = self; self.require = function (file) { switch (true) { case file === 'workway': return self.workway; case /^[./]/.test(file): file = path.resolve(self.__dirname, file); default: return require(file); } }; return self; }
[ "function", "createSandbox", "(", "filename", ",", "socket", ")", "{", "var", "self", "=", "new", "EventEmitter", ";", "var", "listeners", "=", "new", "WeakMap", ";", "self", ".", "addEventListener", "=", "function", "(", "type", ",", "listener", ")", "{", "if", "(", "!", "listeners", ".", "has", "(", "listener", ")", ")", "{", "var", "facade", "=", "function", "(", "event", ")", "{", "if", "(", "!", "event", ".", "canceled", ")", "listener", ".", "apply", "(", "this", ",", "arguments", ")", ";", "}", ";", "listeners", ".", "set", "(", "listener", ",", "facade", ")", ";", "self", ".", "on", "(", "type", ",", "facade", ")", ";", "}", "}", ";", "self", ".", "removeEventListener", "=", "function", "(", "type", ",", "listener", ")", "{", "self", ".", "removeListener", "(", "type", ",", "listeners", ".", "get", "(", "listener", ")", ")", ";", "}", ";", "self", ".", "__filename", "=", "filename", ";", "self", ".", "__dirname", "=", "path", ".", "dirname", "(", "filename", ")", ";", "self", ".", "postMessage", "=", "function", "postMessage", "(", "data", ")", "{", "message", "(", "socket", ",", "data", ")", ";", "}", ";", "self", ".", "console", "=", "console", ";", "self", ".", "process", "=", "process", ";", "self", ".", "Buffer", "=", "Buffer", ";", "self", ".", "clearImmediate", "=", "clearImmediate", ";", "self", ".", "clearInterval", "=", "clearInterval", ";", "self", ".", "clearTimeout", "=", "clearTimeout", ";", "self", ".", "setImmediate", "=", "setImmediate", ";", "self", ".", "setInterval", "=", "setInterval", ";", "self", ".", "setTimeout", "=", "setTimeout", ";", "self", ".", "module", "=", "module", ";", "self", ".", "global", "=", "self", ";", "self", ".", "self", "=", "self", ";", "self", ".", "require", "=", "function", "(", "file", ")", "{", "switch", "(", "true", ")", "{", "case", "file", "===", "'workway'", ":", "return", "self", ".", "workway", ";", "case", "/", "^[./]", "/", ".", "test", "(", "file", ")", ":", "file", "=", "path", ".", "resolve", "(", "self", ".", "__dirname", ",", "file", ")", ";", "default", ":", "return", "require", "(", "file", ")", ";", "}", "}", ";", "return", "self", ";", "}" ]
return a new Worker sandbox
[ "return", "a", "new", "Worker", "sandbox" ]
0f1c33b5e95b714b54d72f97cba1bfbac03a62cc
https://github.com/WebReflection/workway/blob/0f1c33b5e95b714b54d72f97cba1bfbac03a62cc/node/index.js#L38-L79
23,318
WebReflection/workway
node/index.js
error
function error(socket, err) { socket.emit(SECRET + ':error', { message: err.message, stack: cleanedStack(err.stack) }); }
javascript
function error(socket, err) { socket.emit(SECRET + ':error', { message: err.message, stack: cleanedStack(err.stack) }); }
[ "function", "error", "(", "socket", ",", "err", ")", "{", "socket", ".", "emit", "(", "SECRET", "+", "':error'", ",", "{", "message", ":", "err", ".", "message", ",", "stack", ":", "cleanedStack", "(", "err", ".", "stack", ")", "}", ")", ";", "}" ]
notify the socket there was an error
[ "notify", "the", "socket", "there", "was", "an", "error" ]
0f1c33b5e95b714b54d72f97cba1bfbac03a62cc
https://github.com/WebReflection/workway/blob/0f1c33b5e95b714b54d72f97cba1bfbac03a62cc/node/index.js#L86-L91
23,319
nowa-webpack/nowa
src/index.js
findPluginPath
function findPluginPath(command) { if (command && /^\w+$/.test(command)) { try { return resolve.sync('nowa-' + command, { paths: moduleDirs }); } catch (e) { console.log(''); console.log(' ' + chalk.green.bold(command) + ' command is not installed.'); console.log(' You can try to install it by ' + chalk.blue.bold('nowa install ' + command) + '.'); console.log(''); } } }
javascript
function findPluginPath(command) { if (command && /^\w+$/.test(command)) { try { return resolve.sync('nowa-' + command, { paths: moduleDirs }); } catch (e) { console.log(''); console.log(' ' + chalk.green.bold(command) + ' command is not installed.'); console.log(' You can try to install it by ' + chalk.blue.bold('nowa install ' + command) + '.'); console.log(''); } } }
[ "function", "findPluginPath", "(", "command", ")", "{", "if", "(", "command", "&&", "/", "^\\w+$", "/", ".", "test", "(", "command", ")", ")", "{", "try", "{", "return", "resolve", ".", "sync", "(", "'nowa-'", "+", "command", ",", "{", "paths", ":", "moduleDirs", "}", ")", ";", "}", "catch", "(", "e", ")", "{", "console", ".", "log", "(", "''", ")", ";", "console", ".", "log", "(", "' '", "+", "chalk", ".", "green", ".", "bold", "(", "command", ")", "+", "' command is not installed.'", ")", ";", "console", ".", "log", "(", "' You can try to install it by '", "+", "chalk", ".", "blue", ".", "bold", "(", "'nowa install '", "+", "command", ")", "+", "'.'", ")", ";", "console", ".", "log", "(", "''", ")", ";", "}", "}", "}" ]
locate the plugin by command
[ "locate", "the", "plugin", "by", "command" ]
8da38f00b925f892da385205384835474cf82c86
https://github.com/nowa-webpack/nowa/blob/8da38f00b925f892da385205384835474cf82c86/src/index.js#L137-L150
23,320
nowa-webpack/nowa
src/index.js
loadDefaultOpts
function loadDefaultOpts(startDir, configFile) { try { return require(path.join(startDir, configFile)).options || {}; } catch (e) { var dir = path.dirname(startDir); if (dir === startDir) { return {}; } return loadDefaultOpts(dir, configFile); } }
javascript
function loadDefaultOpts(startDir, configFile) { try { return require(path.join(startDir, configFile)).options || {}; } catch (e) { var dir = path.dirname(startDir); if (dir === startDir) { return {}; } return loadDefaultOpts(dir, configFile); } }
[ "function", "loadDefaultOpts", "(", "startDir", ",", "configFile", ")", "{", "try", "{", "return", "require", "(", "path", ".", "join", "(", "startDir", ",", "configFile", ")", ")", ".", "options", "||", "{", "}", ";", "}", "catch", "(", "e", ")", "{", "var", "dir", "=", "path", ".", "dirname", "(", "startDir", ")", ";", "if", "(", "dir", "===", "startDir", ")", "{", "return", "{", "}", ";", "}", "return", "loadDefaultOpts", "(", "dir", ",", "configFile", ")", ";", "}", "}" ]
load default options
[ "load", "default", "options" ]
8da38f00b925f892da385205384835474cf82c86
https://github.com/nowa-webpack/nowa/blob/8da38f00b925f892da385205384835474cf82c86/src/index.js#L153-L163
23,321
jsdoc2md/jsdoc-api
index.js
explainSync
function explainSync (options) { options = new JsdocOptions(options) const ExplainSync = require('./lib/explain-sync') const command = new ExplainSync(options, exports.cache) return command.execute() }
javascript
function explainSync (options) { options = new JsdocOptions(options) const ExplainSync = require('./lib/explain-sync') const command = new ExplainSync(options, exports.cache) return command.execute() }
[ "function", "explainSync", "(", "options", ")", "{", "options", "=", "new", "JsdocOptions", "(", "options", ")", "const", "ExplainSync", "=", "require", "(", "'./lib/explain-sync'", ")", "const", "command", "=", "new", "ExplainSync", "(", "options", ",", "exports", ".", "cache", ")", "return", "command", ".", "execute", "(", ")", "}" ]
Returns jsdoc explain output. @param [options] {module:jsdoc-api~JsdocOptions} @returns {object[]} @static @prerequisite Requires node v0.12 or above
[ "Returns", "jsdoc", "explain", "output", "." ]
2cd5096c8b7db5d825e296204c30ca795ff0e0b2
https://github.com/jsdoc2md/jsdoc-api/blob/2cd5096c8b7db5d825e296204c30ca795ff0e0b2/index.js#L27-L32
23,322
jsdoc2md/jsdoc-api
index.js
explain
function explain (options) { options = new JsdocOptions(options) const Explain = require('./lib/explain') const command = new Explain(options, exports.cache) return command.execute() }
javascript
function explain (options) { options = new JsdocOptions(options) const Explain = require('./lib/explain') const command = new Explain(options, exports.cache) return command.execute() }
[ "function", "explain", "(", "options", ")", "{", "options", "=", "new", "JsdocOptions", "(", "options", ")", "const", "Explain", "=", "require", "(", "'./lib/explain'", ")", "const", "command", "=", "new", "Explain", "(", "options", ",", "exports", ".", "cache", ")", "return", "command", ".", "execute", "(", ")", "}" ]
Returns a promise for the jsdoc explain output. @param [options] {module:jsdoc-api~JsdocOptions} @fulfil {object[]} - jsdoc explain output @returns {Promise} @static
[ "Returns", "a", "promise", "for", "the", "jsdoc", "explain", "output", "." ]
2cd5096c8b7db5d825e296204c30ca795ff0e0b2
https://github.com/jsdoc2md/jsdoc-api/blob/2cd5096c8b7db5d825e296204c30ca795ff0e0b2/index.js#L42-L47
23,323
jsdoc2md/jsdoc-api
index.js
renderSync
function renderSync (options) { options = new JsdocOptions(options) const RenderSync = require('./lib/render-sync') const command = new RenderSync(options) return command.execute() }
javascript
function renderSync (options) { options = new JsdocOptions(options) const RenderSync = require('./lib/render-sync') const command = new RenderSync(options) return command.execute() }
[ "function", "renderSync", "(", "options", ")", "{", "options", "=", "new", "JsdocOptions", "(", "options", ")", "const", "RenderSync", "=", "require", "(", "'./lib/render-sync'", ")", "const", "command", "=", "new", "RenderSync", "(", "options", ")", "return", "command", ".", "execute", "(", ")", "}" ]
Render jsdoc documentation. @param [options] {module:jsdoc-api~JsdocOptions} @prerequisite Requires node v0.12 or above @static @example jsdoc.renderSync({ files: 'lib/*', destination: 'api-docs' })
[ "Render", "jsdoc", "documentation", "." ]
2cd5096c8b7db5d825e296204c30ca795ff0e0b2
https://github.com/jsdoc2md/jsdoc-api/blob/2cd5096c8b7db5d825e296204c30ca795ff0e0b2/index.js#L58-L63
23,324
felixhagspiel/jsOnlyLightbox
js/lightbox.js
addEvent
function addEvent(el, e, callback, capture) { if (el.addEventListener) { el.addEventListener(e, callback, capture || false); } else if (el.attachEvent) { el.attachEvent('on' + e, callback); } }
javascript
function addEvent(el, e, callback, capture) { if (el.addEventListener) { el.addEventListener(e, callback, capture || false); } else if (el.attachEvent) { el.attachEvent('on' + e, callback); } }
[ "function", "addEvent", "(", "el", ",", "e", ",", "callback", ",", "capture", ")", "{", "if", "(", "el", ".", "addEventListener", ")", "{", "el", ".", "addEventListener", "(", "e", ",", "callback", ",", "capture", "||", "false", ")", ";", "}", "else", "if", "(", "el", ".", "attachEvent", ")", "{", "el", ".", "attachEvent", "(", "'on'", "+", "e", ",", "callback", ")", ";", "}", "}" ]
Adds eventlisteners cross browser @param {Object} el The element which gets the listener @param {String} e The event type @param {Function} callback The action to execute on event @param {Boolean} capture The capture mode
[ "Adds", "eventlisteners", "cross", "browser" ]
894dad069c6b8f7b3dac26829dfebbd80efc84fc
https://github.com/felixhagspiel/jsOnlyLightbox/blob/894dad069c6b8f7b3dac26829dfebbd80efc84fc/js/lightbox.js#L92-L100
23,325
felixhagspiel/jsOnlyLightbox
js/lightbox.js
hasClass
function hasClass(el, className) { if (!el || !className) { return; } return (new RegExp('(^|\\s)' + className + '(\\s|$)').test(el.className)); }
javascript
function hasClass(el, className) { if (!el || !className) { return; } return (new RegExp('(^|\\s)' + className + '(\\s|$)').test(el.className)); }
[ "function", "hasClass", "(", "el", ",", "className", ")", "{", "if", "(", "!", "el", "||", "!", "className", ")", "{", "return", ";", "}", "return", "(", "new", "RegExp", "(", "'(^|\\\\s)'", "+", "className", "+", "'(\\\\s|$)'", ")", ".", "test", "(", "el", ".", "className", ")", ")", ";", "}" ]
Checks if element has a specific class @param {Object} el [description] @param {String} className [description] @return {Boolean} [description]
[ "Checks", "if", "element", "has", "a", "specific", "class" ]
894dad069c6b8f7b3dac26829dfebbd80efc84fc
https://github.com/felixhagspiel/jsOnlyLightbox/blob/894dad069c6b8f7b3dac26829dfebbd80efc84fc/js/lightbox.js#L108-L113
23,326
felixhagspiel/jsOnlyLightbox
js/lightbox.js
removeClass
function removeClass(el, className) { if (!el || !className) { return; } el.className = el.className.replace(new RegExp('(?:^|\\s)' + className + '(?!\\S)'), ''); return el; }
javascript
function removeClass(el, className) { if (!el || !className) { return; } el.className = el.className.replace(new RegExp('(?:^|\\s)' + className + '(?!\\S)'), ''); return el; }
[ "function", "removeClass", "(", "el", ",", "className", ")", "{", "if", "(", "!", "el", "||", "!", "className", ")", "{", "return", ";", "}", "el", ".", "className", "=", "el", ".", "className", ".", "replace", "(", "new", "RegExp", "(", "'(?:^|\\\\s)'", "+", "className", "+", "'(?!\\\\S)'", ")", ",", "''", ")", ";", "return", "el", ";", "}" ]
Removes class from element @param {Object} el @param {String} className @return {Object}
[ "Removes", "class", "from", "element" ]
894dad069c6b8f7b3dac26829dfebbd80efc84fc
https://github.com/felixhagspiel/jsOnlyLightbox/blob/894dad069c6b8f7b3dac26829dfebbd80efc84fc/js/lightbox.js#L121-L127
23,327
felixhagspiel/jsOnlyLightbox
js/lightbox.js
getAttr
function getAttr(obj, attr) { if (!obj || !isset(obj)) { return false; } var ret; if (obj.getAttribute) { ret = obj.getAttribute(attr); } else if (obj.getAttributeNode) { ret = obj.getAttributeNode(attr).value; } if (isset(ret) && ret !== '') { return ret; } return false; }
javascript
function getAttr(obj, attr) { if (!obj || !isset(obj)) { return false; } var ret; if (obj.getAttribute) { ret = obj.getAttribute(attr); } else if (obj.getAttributeNode) { ret = obj.getAttributeNode(attr).value; } if (isset(ret) && ret !== '') { return ret; } return false; }
[ "function", "getAttr", "(", "obj", ",", "attr", ")", "{", "if", "(", "!", "obj", "||", "!", "isset", "(", "obj", ")", ")", "{", "return", "false", ";", "}", "var", "ret", ";", "if", "(", "obj", ".", "getAttribute", ")", "{", "ret", "=", "obj", ".", "getAttribute", "(", "attr", ")", ";", "}", "else", "if", "(", "obj", ".", "getAttributeNode", ")", "{", "ret", "=", "obj", ".", "getAttributeNode", "(", "attr", ")", ".", "value", ";", "}", "if", "(", "isset", "(", "ret", ")", "&&", "ret", "!==", "''", ")", "{", "return", "ret", ";", "}", "return", "false", ";", "}" ]
Get attribute value cross-browser. Returns the attribute as string if found, otherwise returns false @param {Object} obj @param {String} attr @return {boolean || string}
[ "Get", "attribute", "value", "cross", "-", "browser", ".", "Returns", "the", "attribute", "as", "string", "if", "found", "otherwise", "returns", "false" ]
894dad069c6b8f7b3dac26829dfebbd80efc84fc
https://github.com/felixhagspiel/jsOnlyLightbox/blob/894dad069c6b8f7b3dac26829dfebbd80efc84fc/js/lightbox.js#L162-L178
23,328
felixhagspiel/jsOnlyLightbox
js/lightbox.js
clckHlpr
function clckHlpr(i) { addEvent(i, 'click', function (e) { stopPropagation(e); preventDefault(e); currGroup = getAttr(i, _const_dataattr + '-group') || false; currThumbnail = i; openBox(i, false, false, false); }, false); }
javascript
function clckHlpr(i) { addEvent(i, 'click', function (e) { stopPropagation(e); preventDefault(e); currGroup = getAttr(i, _const_dataattr + '-group') || false; currThumbnail = i; openBox(i, false, false, false); }, false); }
[ "function", "clckHlpr", "(", "i", ")", "{", "addEvent", "(", "i", ",", "'click'", ",", "function", "(", "e", ")", "{", "stopPropagation", "(", "e", ")", ";", "preventDefault", "(", "e", ")", ";", "currGroup", "=", "getAttr", "(", "i", ",", "_const_dataattr", "+", "'-group'", ")", "||", "false", ";", "currThumbnail", "=", "i", ";", "openBox", "(", "i", ",", "false", ",", "false", ",", "false", ")", ";", "}", ",", "false", ")", ";", "}" ]
Adds clickhandlers to thumbnails @param {Object} i
[ "Adds", "clickhandlers", "to", "thumbnails" ]
894dad069c6b8f7b3dac26829dfebbd80efc84fc
https://github.com/felixhagspiel/jsOnlyLightbox/blob/894dad069c6b8f7b3dac26829dfebbd80efc84fc/js/lightbox.js#L206-L214
23,329
felixhagspiel/jsOnlyLightbox
js/lightbox.js
getByGroup
function getByGroup(group) { var arr = []; for (var i = 0; i < CTX.thumbnails.length; i++) { if (getAttr(CTX.thumbnails[i], _const_dataattr + '-group') === group) { arr.push(CTX.thumbnails[i]); } } return arr; }
javascript
function getByGroup(group) { var arr = []; for (var i = 0; i < CTX.thumbnails.length; i++) { if (getAttr(CTX.thumbnails[i], _const_dataattr + '-group') === group) { arr.push(CTX.thumbnails[i]); } } return arr; }
[ "function", "getByGroup", "(", "group", ")", "{", "var", "arr", "=", "[", "]", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "CTX", ".", "thumbnails", ".", "length", ";", "i", "++", ")", "{", "if", "(", "getAttr", "(", "CTX", ".", "thumbnails", "[", "i", "]", ",", "_const_dataattr", "+", "'-group'", ")", "===", "group", ")", "{", "arr", ".", "push", "(", "CTX", ".", "thumbnails", "[", "i", "]", ")", ";", "}", "}", "return", "arr", ";", "}" ]
Get thumbnails by group @param {String} group @return {Object} Array containing the thumbnails
[ "Get", "thumbnails", "by", "group" ]
894dad069c6b8f7b3dac26829dfebbd80efc84fc
https://github.com/felixhagspiel/jsOnlyLightbox/blob/894dad069c6b8f7b3dac26829dfebbd80efc84fc/js/lightbox.js#L248-L256
23,330
felixhagspiel/jsOnlyLightbox
js/lightbox.js
getPos
function getPos(thumbnail, group) { var arr = getByGroup(group); for (var i = 0; i < arr.length; i++) { // compare elements if (getAttr(thumbnail, 'src') === getAttr(arr[i], 'src') && getAttr(thumbnail, _const_dataattr + '-index') === getAttr(arr[i], _const_dataattr + '-index') && getAttr(thumbnail, _const_dataattr) === getAttr(arr[i], _const_dataattr)) { return i; } } }
javascript
function getPos(thumbnail, group) { var arr = getByGroup(group); for (var i = 0; i < arr.length; i++) { // compare elements if (getAttr(thumbnail, 'src') === getAttr(arr[i], 'src') && getAttr(thumbnail, _const_dataattr + '-index') === getAttr(arr[i], _const_dataattr + '-index') && getAttr(thumbnail, _const_dataattr) === getAttr(arr[i], _const_dataattr)) { return i; } } }
[ "function", "getPos", "(", "thumbnail", ",", "group", ")", "{", "var", "arr", "=", "getByGroup", "(", "group", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "arr", ".", "length", ";", "i", "++", ")", "{", "// compare elements", "if", "(", "getAttr", "(", "thumbnail", ",", "'src'", ")", "===", "getAttr", "(", "arr", "[", "i", "]", ",", "'src'", ")", "&&", "getAttr", "(", "thumbnail", ",", "_const_dataattr", "+", "'-index'", ")", "===", "getAttr", "(", "arr", "[", "i", "]", ",", "_const_dataattr", "+", "'-index'", ")", "&&", "getAttr", "(", "thumbnail", ",", "_const_dataattr", ")", "===", "getAttr", "(", "arr", "[", "i", "]", ",", "_const_dataattr", ")", ")", "{", "return", "i", ";", "}", "}", "}" ]
Get the position of thumbnail in group-array @param {Object} thumbnail @param {String} group @return {number}
[ "Get", "the", "position", "of", "thumbnail", "in", "group", "-", "array" ]
894dad069c6b8f7b3dac26829dfebbd80efc84fc
https://github.com/felixhagspiel/jsOnlyLightbox/blob/894dad069c6b8f7b3dac26829dfebbd80efc84fc/js/lightbox.js#L264-L275
23,331
felixhagspiel/jsOnlyLightbox
js/lightbox.js
preload
function preload() { if (!currGroup) { return; } var prev = new Image(); var next = new Image(); var pos = getPos(currThumbnail, currGroup); if (pos === (currImages.length - 1)) { // last image in group, preload first image and the one before prev.src = getAttr(currImages[currImages.length - 1], _const_dataattr) || currImages[currImages.length - 1].src; next.src = getAttr(currImages[0].src, _const_dataattr) || currImages[0].src; } else if (pos === 0) { // first image in group, preload last image and the next one prev.src = getAttr(currImages[currImages.length - 1], _const_dataattr) || currImages[currImages.length - 1].src; next.src = getAttr(currImages[1], _const_dataattr) || currImages[1].src; } else { // in between, preload prev & next image prev.src = getAttr(currImages[pos - 1], _const_dataattr) || currImages[pos - 1].src; next.src = getAttr(currImages[pos + 1], _const_dataattr) || currImages[pos + 1].src; } }
javascript
function preload() { if (!currGroup) { return; } var prev = new Image(); var next = new Image(); var pos = getPos(currThumbnail, currGroup); if (pos === (currImages.length - 1)) { // last image in group, preload first image and the one before prev.src = getAttr(currImages[currImages.length - 1], _const_dataattr) || currImages[currImages.length - 1].src; next.src = getAttr(currImages[0].src, _const_dataattr) || currImages[0].src; } else if (pos === 0) { // first image in group, preload last image and the next one prev.src = getAttr(currImages[currImages.length - 1], _const_dataattr) || currImages[currImages.length - 1].src; next.src = getAttr(currImages[1], _const_dataattr) || currImages[1].src; } else { // in between, preload prev & next image prev.src = getAttr(currImages[pos - 1], _const_dataattr) || currImages[pos - 1].src; next.src = getAttr(currImages[pos + 1], _const_dataattr) || currImages[pos + 1].src; } }
[ "function", "preload", "(", ")", "{", "if", "(", "!", "currGroup", ")", "{", "return", ";", "}", "var", "prev", "=", "new", "Image", "(", ")", ";", "var", "next", "=", "new", "Image", "(", ")", ";", "var", "pos", "=", "getPos", "(", "currThumbnail", ",", "currGroup", ")", ";", "if", "(", "pos", "===", "(", "currImages", ".", "length", "-", "1", ")", ")", "{", "// last image in group, preload first image and the one before", "prev", ".", "src", "=", "getAttr", "(", "currImages", "[", "currImages", ".", "length", "-", "1", "]", ",", "_const_dataattr", ")", "||", "currImages", "[", "currImages", ".", "length", "-", "1", "]", ".", "src", ";", "next", ".", "src", "=", "getAttr", "(", "currImages", "[", "0", "]", ".", "src", ",", "_const_dataattr", ")", "||", "currImages", "[", "0", "]", ".", "src", ";", "}", "else", "if", "(", "pos", "===", "0", ")", "{", "// first image in group, preload last image and the next one", "prev", ".", "src", "=", "getAttr", "(", "currImages", "[", "currImages", ".", "length", "-", "1", "]", ",", "_const_dataattr", ")", "||", "currImages", "[", "currImages", ".", "length", "-", "1", "]", ".", "src", ";", "next", ".", "src", "=", "getAttr", "(", "currImages", "[", "1", "]", ",", "_const_dataattr", ")", "||", "currImages", "[", "1", "]", ".", "src", ";", "}", "else", "{", "// in between, preload prev & next image", "prev", ".", "src", "=", "getAttr", "(", "currImages", "[", "pos", "-", "1", "]", ",", "_const_dataattr", ")", "||", "currImages", "[", "pos", "-", "1", "]", ".", "src", ";", "next", ".", "src", "=", "getAttr", "(", "currImages", "[", "pos", "+", "1", "]", ",", "_const_dataattr", ")", "||", "currImages", "[", "pos", "+", "1", "]", ".", "src", ";", "}", "}" ]
Preloads next and prev images
[ "Preloads", "next", "and", "prev", "images" ]
894dad069c6b8f7b3dac26829dfebbd80efc84fc
https://github.com/felixhagspiel/jsOnlyLightbox/blob/894dad069c6b8f7b3dac26829dfebbd80efc84fc/js/lightbox.js#L280-L303
23,332
felixhagspiel/jsOnlyLightbox
js/lightbox.js
startAnimation
function startAnimation() { if (isIE8) { return; } // stop any already running animations stopAnimation(); var fnc = function () { addClass(CTX.box, _const_class_prefix + '-loading'); if (!isIE9 && typeof CTX.opt.loadingAnimation === 'number') { var index = 0; animationInt = setInterval(function () { addClass(animationChildren[index], _const_class_prefix + '-active'); setTimeout(function () { removeClass(animationChildren[index], _const_class_prefix + '-active'); }, CTX.opt.loadingAnimation); index = index >= animationChildren.length ? 0 : index += 1; }, CTX.opt.loadingAnimation); } }; // set timeout to not show loading animation on fast connections animationTimeout = setTimeout(fnc, 500); }
javascript
function startAnimation() { if (isIE8) { return; } // stop any already running animations stopAnimation(); var fnc = function () { addClass(CTX.box, _const_class_prefix + '-loading'); if (!isIE9 && typeof CTX.opt.loadingAnimation === 'number') { var index = 0; animationInt = setInterval(function () { addClass(animationChildren[index], _const_class_prefix + '-active'); setTimeout(function () { removeClass(animationChildren[index], _const_class_prefix + '-active'); }, CTX.opt.loadingAnimation); index = index >= animationChildren.length ? 0 : index += 1; }, CTX.opt.loadingAnimation); } }; // set timeout to not show loading animation on fast connections animationTimeout = setTimeout(fnc, 500); }
[ "function", "startAnimation", "(", ")", "{", "if", "(", "isIE8", ")", "{", "return", ";", "}", "// stop any already running animations", "stopAnimation", "(", ")", ";", "var", "fnc", "=", "function", "(", ")", "{", "addClass", "(", "CTX", ".", "box", ",", "_const_class_prefix", "+", "'-loading'", ")", ";", "if", "(", "!", "isIE9", "&&", "typeof", "CTX", ".", "opt", ".", "loadingAnimation", "===", "'number'", ")", "{", "var", "index", "=", "0", ";", "animationInt", "=", "setInterval", "(", "function", "(", ")", "{", "addClass", "(", "animationChildren", "[", "index", "]", ",", "_const_class_prefix", "+", "'-active'", ")", ";", "setTimeout", "(", "function", "(", ")", "{", "removeClass", "(", "animationChildren", "[", "index", "]", ",", "_const_class_prefix", "+", "'-active'", ")", ";", "}", ",", "CTX", ".", "opt", ".", "loadingAnimation", ")", ";", "index", "=", "index", ">=", "animationChildren", ".", "length", "?", "0", ":", "index", "+=", "1", ";", "}", ",", "CTX", ".", "opt", ".", "loadingAnimation", ")", ";", "}", "}", ";", "// set timeout to not show loading animation on fast connections", "animationTimeout", "=", "setTimeout", "(", "fnc", ",", "500", ")", ";", "}" ]
Starts the loading animation
[ "Starts", "the", "loading", "animation" ]
894dad069c6b8f7b3dac26829dfebbd80efc84fc
https://github.com/felixhagspiel/jsOnlyLightbox/blob/894dad069c6b8f7b3dac26829dfebbd80efc84fc/js/lightbox.js#L308-L329
23,333
felixhagspiel/jsOnlyLightbox
js/lightbox.js
stopAnimation
function stopAnimation() { if (isIE8) { return; } // hide animation-element removeClass(CTX.box, _const_class_prefix + '-loading'); // stop animation if (!isIE9 && typeof CTX.opt.loadingAnimation !== 'string' && CTX.opt.loadingAnimation) { clearInterval(animationInt); // do not use animationChildren.length here due to IE8/9 bugs for (var i = 0; i < animationChildren.length; i++) { removeClass(animationChildren[i], _const_class_prefix + '-active'); } } }
javascript
function stopAnimation() { if (isIE8) { return; } // hide animation-element removeClass(CTX.box, _const_class_prefix + '-loading'); // stop animation if (!isIE9 && typeof CTX.opt.loadingAnimation !== 'string' && CTX.opt.loadingAnimation) { clearInterval(animationInt); // do not use animationChildren.length here due to IE8/9 bugs for (var i = 0; i < animationChildren.length; i++) { removeClass(animationChildren[i], _const_class_prefix + '-active'); } } }
[ "function", "stopAnimation", "(", ")", "{", "if", "(", "isIE8", ")", "{", "return", ";", "}", "// hide animation-element", "removeClass", "(", "CTX", ".", "box", ",", "_const_class_prefix", "+", "'-loading'", ")", ";", "// stop animation", "if", "(", "!", "isIE9", "&&", "typeof", "CTX", ".", "opt", ".", "loadingAnimation", "!==", "'string'", "&&", "CTX", ".", "opt", ".", "loadingAnimation", ")", "{", "clearInterval", "(", "animationInt", ")", ";", "// do not use animationChildren.length here due to IE8/9 bugs", "for", "(", "var", "i", "=", "0", ";", "i", "<", "animationChildren", ".", "length", ";", "i", "++", ")", "{", "removeClass", "(", "animationChildren", "[", "i", "]", ",", "_const_class_prefix", "+", "'-active'", ")", ";", "}", "}", "}" ]
Stops the animation
[ "Stops", "the", "animation" ]
894dad069c6b8f7b3dac26829dfebbd80efc84fc
https://github.com/felixhagspiel/jsOnlyLightbox/blob/894dad069c6b8f7b3dac26829dfebbd80efc84fc/js/lightbox.js#L334-L348
23,334
felixhagspiel/jsOnlyLightbox
js/lightbox.js
initControls
function initControls() { if (!nextBtn) { // create & append next-btn nextBtn = document.createElement('span'); addClass(nextBtn, _const_class_prefix + '-next'); // add custom images if (CTX.opt.nextImg) { var nextBtnImg = document.createElement('img'); nextBtnImg.setAttribute('src', CTX.opt.nextImg); nextBtn.appendChild(nextBtnImg); } else { addClass(nextBtn, _const_class_prefix + '-no-img'); } addEvent(nextBtn, 'click', function (e) { stopPropagation(e); // prevent closing of lightbox CTX.next(); }, false); CTX.box.appendChild(nextBtn); } addClass(nextBtn, _const_class_prefix + '-active'); if (!prevBtn) { // create & append next-btn prevBtn = document.createElement('span'); addClass(prevBtn, _const_class_prefix + '-prev'); // add custom images if (CTX.opt.prevImg) { var prevBtnImg = document.createElement('img'); prevBtnImg.setAttribute('src', CTX.opt.prevImg); prevBtn.appendChild(prevBtnImg); } else { addClass(prevBtn, _const_class_prefix + '-no-img'); } addEvent(prevBtn, 'click', function (e) { stopPropagation(e); // prevent closing of lightbox CTX.prev(); }, false); CTX.box.appendChild(prevBtn); } addClass(prevBtn, _const_class_prefix + '-active'); }
javascript
function initControls() { if (!nextBtn) { // create & append next-btn nextBtn = document.createElement('span'); addClass(nextBtn, _const_class_prefix + '-next'); // add custom images if (CTX.opt.nextImg) { var nextBtnImg = document.createElement('img'); nextBtnImg.setAttribute('src', CTX.opt.nextImg); nextBtn.appendChild(nextBtnImg); } else { addClass(nextBtn, _const_class_prefix + '-no-img'); } addEvent(nextBtn, 'click', function (e) { stopPropagation(e); // prevent closing of lightbox CTX.next(); }, false); CTX.box.appendChild(nextBtn); } addClass(nextBtn, _const_class_prefix + '-active'); if (!prevBtn) { // create & append next-btn prevBtn = document.createElement('span'); addClass(prevBtn, _const_class_prefix + '-prev'); // add custom images if (CTX.opt.prevImg) { var prevBtnImg = document.createElement('img'); prevBtnImg.setAttribute('src', CTX.opt.prevImg); prevBtn.appendChild(prevBtnImg); } else { addClass(prevBtn, _const_class_prefix + '-no-img'); } addEvent(prevBtn, 'click', function (e) { stopPropagation(e); // prevent closing of lightbox CTX.prev(); }, false); CTX.box.appendChild(prevBtn); } addClass(prevBtn, _const_class_prefix + '-active'); }
[ "function", "initControls", "(", ")", "{", "if", "(", "!", "nextBtn", ")", "{", "// create & append next-btn", "nextBtn", "=", "document", ".", "createElement", "(", "'span'", ")", ";", "addClass", "(", "nextBtn", ",", "_const_class_prefix", "+", "'-next'", ")", ";", "// add custom images", "if", "(", "CTX", ".", "opt", ".", "nextImg", ")", "{", "var", "nextBtnImg", "=", "document", ".", "createElement", "(", "'img'", ")", ";", "nextBtnImg", ".", "setAttribute", "(", "'src'", ",", "CTX", ".", "opt", ".", "nextImg", ")", ";", "nextBtn", ".", "appendChild", "(", "nextBtnImg", ")", ";", "}", "else", "{", "addClass", "(", "nextBtn", ",", "_const_class_prefix", "+", "'-no-img'", ")", ";", "}", "addEvent", "(", "nextBtn", ",", "'click'", ",", "function", "(", "e", ")", "{", "stopPropagation", "(", "e", ")", ";", "// prevent closing of lightbox", "CTX", ".", "next", "(", ")", ";", "}", ",", "false", ")", ";", "CTX", ".", "box", ".", "appendChild", "(", "nextBtn", ")", ";", "}", "addClass", "(", "nextBtn", ",", "_const_class_prefix", "+", "'-active'", ")", ";", "if", "(", "!", "prevBtn", ")", "{", "// create & append next-btn", "prevBtn", "=", "document", ".", "createElement", "(", "'span'", ")", ";", "addClass", "(", "prevBtn", ",", "_const_class_prefix", "+", "'-prev'", ")", ";", "// add custom images", "if", "(", "CTX", ".", "opt", ".", "prevImg", ")", "{", "var", "prevBtnImg", "=", "document", ".", "createElement", "(", "'img'", ")", ";", "prevBtnImg", ".", "setAttribute", "(", "'src'", ",", "CTX", ".", "opt", ".", "prevImg", ")", ";", "prevBtn", ".", "appendChild", "(", "prevBtnImg", ")", ";", "}", "else", "{", "addClass", "(", "prevBtn", ",", "_const_class_prefix", "+", "'-no-img'", ")", ";", "}", "addEvent", "(", "prevBtn", ",", "'click'", ",", "function", "(", "e", ")", "{", "stopPropagation", "(", "e", ")", ";", "// prevent closing of lightbox", "CTX", ".", "prev", "(", ")", ";", "}", ",", "false", ")", ";", "CTX", ".", "box", ".", "appendChild", "(", "prevBtn", ")", ";", "}", "addClass", "(", "prevBtn", ",", "_const_class_prefix", "+", "'-active'", ")", ";", "}" ]
Initializes the control arrows
[ "Initializes", "the", "control", "arrows" ]
894dad069c6b8f7b3dac26829dfebbd80efc84fc
https://github.com/felixhagspiel/jsOnlyLightbox/blob/894dad069c6b8f7b3dac26829dfebbd80efc84fc/js/lightbox.js#L353-L396
23,335
felixhagspiel/jsOnlyLightbox
js/lightbox.js
repositionControls
function repositionControls() { if (CTX.opt.responsive && nextBtn && prevBtn) { var btnTop = (getHeight() / 2) - (nextBtn.offsetHeight / 2); nextBtn.style.top = btnTop + 'px'; prevBtn.style.top = btnTop + 'px'; } }
javascript
function repositionControls() { if (CTX.opt.responsive && nextBtn && prevBtn) { var btnTop = (getHeight() / 2) - (nextBtn.offsetHeight / 2); nextBtn.style.top = btnTop + 'px'; prevBtn.style.top = btnTop + 'px'; } }
[ "function", "repositionControls", "(", ")", "{", "if", "(", "CTX", ".", "opt", ".", "responsive", "&&", "nextBtn", "&&", "prevBtn", ")", "{", "var", "btnTop", "=", "(", "getHeight", "(", ")", "/", "2", ")", "-", "(", "nextBtn", ".", "offsetHeight", "/", "2", ")", ";", "nextBtn", ".", "style", ".", "top", "=", "btnTop", "+", "'px'", ";", "prevBtn", ".", "style", ".", "top", "=", "btnTop", "+", "'px'", ";", "}", "}" ]
Moves controls to correct position
[ "Moves", "controls", "to", "correct", "position" ]
894dad069c6b8f7b3dac26829dfebbd80efc84fc
https://github.com/felixhagspiel/jsOnlyLightbox/blob/894dad069c6b8f7b3dac26829dfebbd80efc84fc/js/lightbox.js#L401-L407
23,336
VFK/gulp-html-replace
lib/common.js
resolveSrcString
function resolveSrcString(srcProperty) { if (Array.isArray(srcProperty)) { // handle multiple tag replacement return Promise.all(srcProperty.map(function (item) { return resolveSrcString(item); })); } else if (isStream(srcProperty)) { return new Promise(function (resolve, reject) { var strings = []; srcProperty.pipe(buffer()) .on('data', function (file) { strings.push(file.contents.toString()); }) .on('error', function(error) { reject(error); this.end(); }) .once('end', function () { resolve(strings); }); }); } else { return Promise.resolve(srcProperty); } }
javascript
function resolveSrcString(srcProperty) { if (Array.isArray(srcProperty)) { // handle multiple tag replacement return Promise.all(srcProperty.map(function (item) { return resolveSrcString(item); })); } else if (isStream(srcProperty)) { return new Promise(function (resolve, reject) { var strings = []; srcProperty.pipe(buffer()) .on('data', function (file) { strings.push(file.contents.toString()); }) .on('error', function(error) { reject(error); this.end(); }) .once('end', function () { resolve(strings); }); }); } else { return Promise.resolve(srcProperty); } }
[ "function", "resolveSrcString", "(", "srcProperty", ")", "{", "if", "(", "Array", ".", "isArray", "(", "srcProperty", ")", ")", "{", "// handle multiple tag replacement", "return", "Promise", ".", "all", "(", "srcProperty", ".", "map", "(", "function", "(", "item", ")", "{", "return", "resolveSrcString", "(", "item", ")", ";", "}", ")", ")", ";", "}", "else", "if", "(", "isStream", "(", "srcProperty", ")", ")", "{", "return", "new", "Promise", "(", "function", "(", "resolve", ",", "reject", ")", "{", "var", "strings", "=", "[", "]", ";", "srcProperty", ".", "pipe", "(", "buffer", "(", ")", ")", ".", "on", "(", "'data'", ",", "function", "(", "file", ")", "{", "strings", ".", "push", "(", "file", ".", "contents", ".", "toString", "(", ")", ")", ";", "}", ")", ".", "on", "(", "'error'", ",", "function", "(", "error", ")", "{", "reject", "(", "error", ")", ";", "this", ".", "end", "(", ")", ";", "}", ")", ".", "once", "(", "'end'", ",", "function", "(", ")", "{", "resolve", "(", "strings", ")", ";", "}", ")", ";", "}", ")", ";", "}", "else", "{", "return", "Promise", ".", "resolve", "(", "srcProperty", ")", ";", "}", "}" ]
Takes the src property of the task configuration and deeply "resolves" any vinyl file stream in it by turning it into a string. This function doesn't change the "arborescence" of the given value: all the forms with strings accepted work with vinyl file streams. @returns {Promise}
[ "Takes", "the", "src", "property", "of", "the", "task", "configuration", "and", "deeply", "resolves", "any", "vinyl", "file", "stream", "in", "it", "by", "turning", "it", "into", "a", "string", "." ]
4b99045040b3fbf79a2702a64276ec78a2e2b771
https://github.com/VFK/gulp-html-replace/blob/4b99045040b3fbf79a2702a64276ec78a2e2b771/lib/common.js#L19-L44
23,337
datavis-tech/json-templates
index.js
type
function type(value) { let valueType = typeof value; if (Array.isArray(value)) { valueType = 'array'; } else if (value instanceof Date) { valueType = 'date'; } else if (value === null) { valueType = 'null'; } return valueType; }
javascript
function type(value) { let valueType = typeof value; if (Array.isArray(value)) { valueType = 'array'; } else if (value instanceof Date) { valueType = 'date'; } else if (value === null) { valueType = 'null'; } return valueType; }
[ "function", "type", "(", "value", ")", "{", "let", "valueType", "=", "typeof", "value", ";", "if", "(", "Array", ".", "isArray", "(", "value", ")", ")", "{", "valueType", "=", "'array'", ";", "}", "else", "if", "(", "value", "instanceof", "Date", ")", "{", "valueType", "=", "'date'", ";", "}", "else", "if", "(", "value", "===", "null", ")", "{", "valueType", "=", "'null'", ";", "}", "return", "valueType", ";", "}" ]
An enhanced version of `typeof` that handles arrays and dates as well.
[ "An", "enhanced", "version", "of", "typeof", "that", "handles", "arrays", "and", "dates", "as", "well", "." ]
d9cd78e71bdc8f189dba70ebdfc89093388ce05a
https://github.com/datavis-tech/json-templates/blob/d9cd78e71bdc8f189dba70ebdfc89093388ce05a/index.js#L10-L21
23,338
datavis-tech/json-templates
index.js
Template
function Template(fn, parameters) { // Paul Brewer Dec 2017 add deduplication call, use only key property to eliminate Object.assign(fn, { parameters: dedupe(parameters, item => item.key) }); return fn; }
javascript
function Template(fn, parameters) { // Paul Brewer Dec 2017 add deduplication call, use only key property to eliminate Object.assign(fn, { parameters: dedupe(parameters, item => item.key) }); return fn; }
[ "function", "Template", "(", "fn", ",", "parameters", ")", "{", "// Paul Brewer Dec 2017 add deduplication call, use only key property to eliminate", "Object", ".", "assign", "(", "fn", ",", "{", "parameters", ":", "dedupe", "(", "parameters", ",", "item", "=>", "item", ".", "key", ")", "}", ")", ";", "return", "fn", ";", "}" ]
Constructs a template function with deduped `parameters` property.
[ "Constructs", "a", "template", "function", "with", "deduped", "parameters", "property", "." ]
d9cd78e71bdc8f189dba70ebdfc89093388ce05a
https://github.com/datavis-tech/json-templates/blob/d9cd78e71bdc8f189dba70ebdfc89093388ce05a/index.js#L44-L51
23,339
datavis-tech/json-templates
index.js
parseObject
function parseObject(object) { const children = Object.keys(object).map(key => ({ keyTemplate: parseString(key), valueTemplate: parse(object[key]) })); const templateParameters = children.reduce( (parameters, child) => parameters.concat(child.valueTemplate.parameters, child.keyTemplate.parameters), [] ); const templateFn = context => { return children.reduce((newObject, child) => { newObject[child.keyTemplate(context)] = child.valueTemplate(context); return newObject; }, {}); }; return Template(templateFn, templateParameters); }
javascript
function parseObject(object) { const children = Object.keys(object).map(key => ({ keyTemplate: parseString(key), valueTemplate: parse(object[key]) })); const templateParameters = children.reduce( (parameters, child) => parameters.concat(child.valueTemplate.parameters, child.keyTemplate.parameters), [] ); const templateFn = context => { return children.reduce((newObject, child) => { newObject[child.keyTemplate(context)] = child.valueTemplate(context); return newObject; }, {}); }; return Template(templateFn, templateParameters); }
[ "function", "parseObject", "(", "object", ")", "{", "const", "children", "=", "Object", ".", "keys", "(", "object", ")", ".", "map", "(", "key", "=>", "(", "{", "keyTemplate", ":", "parseString", "(", "key", ")", ",", "valueTemplate", ":", "parse", "(", "object", "[", "key", "]", ")", "}", ")", ")", ";", "const", "templateParameters", "=", "children", ".", "reduce", "(", "(", "parameters", ",", "child", ")", "=>", "parameters", ".", "concat", "(", "child", ".", "valueTemplate", ".", "parameters", ",", "child", ".", "keyTemplate", ".", "parameters", ")", ",", "[", "]", ")", ";", "const", "templateFn", "=", "context", "=>", "{", "return", "children", ".", "reduce", "(", "(", "newObject", ",", "child", ")", "=>", "{", "newObject", "[", "child", ".", "keyTemplate", "(", "context", ")", "]", "=", "child", ".", "valueTemplate", "(", "context", ")", ";", "return", "newObject", ";", "}", ",", "{", "}", ")", ";", "}", ";", "return", "Template", "(", "templateFn", ",", "templateParameters", ")", ";", "}" ]
Parses non-leaf-nodes in the template object that are objects.
[ "Parses", "non", "-", "leaf", "-", "nodes", "in", "the", "template", "object", "that", "are", "objects", "." ]
d9cd78e71bdc8f189dba70ebdfc89093388ce05a
https://github.com/datavis-tech/json-templates/blob/d9cd78e71bdc8f189dba70ebdfc89093388ce05a/index.js#L117-L135
23,340
datavis-tech/json-templates
index.js
parseArray
function parseArray(array) { const templates = array.map(parse); const templateParameters = templates.reduce( (parameters, template) => parameters.concat(template.parameters), [] ); const templateFn = context => templates.map(template => template(context)); return Template(templateFn, templateParameters); }
javascript
function parseArray(array) { const templates = array.map(parse); const templateParameters = templates.reduce( (parameters, template) => parameters.concat(template.parameters), [] ); const templateFn = context => templates.map(template => template(context)); return Template(templateFn, templateParameters); }
[ "function", "parseArray", "(", "array", ")", "{", "const", "templates", "=", "array", ".", "map", "(", "parse", ")", ";", "const", "templateParameters", "=", "templates", ".", "reduce", "(", "(", "parameters", ",", "template", ")", "=>", "parameters", ".", "concat", "(", "template", ".", "parameters", ")", ",", "[", "]", ")", ";", "const", "templateFn", "=", "context", "=>", "templates", ".", "map", "(", "template", "=>", "template", "(", "context", ")", ")", ";", "return", "Template", "(", "templateFn", ",", "templateParameters", ")", ";", "}" ]
Parses non-leaf-nodes in the template object that are arrays.
[ "Parses", "non", "-", "leaf", "-", "nodes", "in", "the", "template", "object", "that", "are", "arrays", "." ]
d9cd78e71bdc8f189dba70ebdfc89093388ce05a
https://github.com/datavis-tech/json-templates/blob/d9cd78e71bdc8f189dba70ebdfc89093388ce05a/index.js#L138-L147
23,341
mkloubert/node-simple-socket
helpers.js
asBuffer
function asBuffer(data, encoding) { let result = data; if (!isNullOrUndefined(result)) { if ('object' !== typeof result) { // handle as string encoding = normalizeString(encoding); if (!encoding) { encoding = 'utf8'; } result = new Buffer(toStringSafe(result), encoding); } } return result; }
javascript
function asBuffer(data, encoding) { let result = data; if (!isNullOrUndefined(result)) { if ('object' !== typeof result) { // handle as string encoding = normalizeString(encoding); if (!encoding) { encoding = 'utf8'; } result = new Buffer(toStringSafe(result), encoding); } } return result; }
[ "function", "asBuffer", "(", "data", ",", "encoding", ")", "{", "let", "result", "=", "data", ";", "if", "(", "!", "isNullOrUndefined", "(", "result", ")", ")", "{", "if", "(", "'object'", "!==", "typeof", "result", ")", "{", "// handle as string\r", "encoding", "=", "normalizeString", "(", "encoding", ")", ";", "if", "(", "!", "encoding", ")", "{", "encoding", "=", "'utf8'", ";", "}", "result", "=", "new", "Buffer", "(", "toStringSafe", "(", "result", ")", ",", "encoding", ")", ";", "}", "}", "return", "result", ";", "}" ]
Returns data as buffer. @param {any} data The input data. @param {string} [encoding] The custom encoding to use if 'data' is NOT a buffer. @return {Buffer} The output data.
[ "Returns", "data", "as", "buffer", "." ]
a673f1987cd6d16f76c218c0a6a98723c42a12ce
https://github.com/mkloubert/node-simple-socket/blob/a673f1987cd6d16f76c218c0a6a98723c42a12ce/helpers.js#L11-L24
23,342
mkloubert/node-simple-socket
helpers.js
createSimplePromiseCompletedAction
function createSimplePromiseCompletedAction(resolve, reject) { return (err, result) => { if (err) { if (reject) { reject(err); } } else { if (resolve) { resolve(result); } } }; }
javascript
function createSimplePromiseCompletedAction(resolve, reject) { return (err, result) => { if (err) { if (reject) { reject(err); } } else { if (resolve) { resolve(result); } } }; }
[ "function", "createSimplePromiseCompletedAction", "(", "resolve", ",", "reject", ")", "{", "return", "(", "err", ",", "result", ")", "=>", "{", "if", "(", "err", ")", "{", "if", "(", "reject", ")", "{", "reject", "(", "err", ")", ";", "}", "}", "else", "{", "if", "(", "resolve", ")", "{", "resolve", "(", "result", ")", ";", "}", "}", "}", ";", "}" ]
Creates a simple 'completed' callback for a promise. @param {Function} resolve The 'succeeded' callback. @param {Function} reject The 'error' callback. @return {SimpleCompletedAction<TResult>} The created action.
[ "Creates", "a", "simple", "completed", "callback", "for", "a", "promise", "." ]
a673f1987cd6d16f76c218c0a6a98723c42a12ce
https://github.com/mkloubert/node-simple-socket/blob/a673f1987cd6d16f76c218c0a6a98723c42a12ce/helpers.js#L34-L47
23,343
mkloubert/node-simple-socket
helpers.js
normalizeString
function normalizeString(val, normalizer) { if (!normalizer) { normalizer = (str) => str.toLowerCase().trim(); } return normalizer(toStringSafe(val)); }
javascript
function normalizeString(val, normalizer) { if (!normalizer) { normalizer = (str) => str.toLowerCase().trim(); } return normalizer(toStringSafe(val)); }
[ "function", "normalizeString", "(", "val", ",", "normalizer", ")", "{", "if", "(", "!", "normalizer", ")", "{", "normalizer", "=", "(", "str", ")", "=>", "str", ".", "toLowerCase", "(", ")", ".", "trim", "(", ")", ";", "}", "return", "normalizer", "(", "toStringSafe", "(", "val", ")", ")", ";", "}" ]
Normalizes a value as string so that is comparable. @param {any} val The value to convert. @param {(str: string) => string} [normalizer] The custom normalizer. @return {string} The normalized value.
[ "Normalizes", "a", "value", "as", "string", "so", "that", "is", "comparable", "." ]
a673f1987cd6d16f76c218c0a6a98723c42a12ce
https://github.com/mkloubert/node-simple-socket/blob/a673f1987cd6d16f76c218c0a6a98723c42a12ce/helpers.js#L81-L86
23,344
mkloubert/node-simple-socket
helpers.js
readSocket
function readSocket(socket, numberOfBytes) { return new Promise((resolve, reject) => { let completed = createSimplePromiseCompletedAction(resolve, reject); try { let buff = socket.read(numberOfBytes); if (null === buff) { socket.once('readable', function () { readSocket(socket, numberOfBytes).then((b) => { completed(null, b); }, (err) => { completed(err); }); }); } else { completed(null, buff); } } catch (e) { completed(e); } }); }
javascript
function readSocket(socket, numberOfBytes) { return new Promise((resolve, reject) => { let completed = createSimplePromiseCompletedAction(resolve, reject); try { let buff = socket.read(numberOfBytes); if (null === buff) { socket.once('readable', function () { readSocket(socket, numberOfBytes).then((b) => { completed(null, b); }, (err) => { completed(err); }); }); } else { completed(null, buff); } } catch (e) { completed(e); } }); }
[ "function", "readSocket", "(", "socket", ",", "numberOfBytes", ")", "{", "return", "new", "Promise", "(", "(", "resolve", ",", "reject", ")", "=>", "{", "let", "completed", "=", "createSimplePromiseCompletedAction", "(", "resolve", ",", "reject", ")", ";", "try", "{", "let", "buff", "=", "socket", ".", "read", "(", "numberOfBytes", ")", ";", "if", "(", "null", "===", "buff", ")", "{", "socket", ".", "once", "(", "'readable'", ",", "function", "(", ")", "{", "readSocket", "(", "socket", ",", "numberOfBytes", ")", ".", "then", "(", "(", "b", ")", "=>", "{", "completed", "(", "null", ",", "b", ")", ";", "}", ",", "(", "err", ")", "=>", "{", "completed", "(", "err", ")", ";", "}", ")", ";", "}", ")", ";", "}", "else", "{", "completed", "(", "null", ",", "buff", ")", ";", "}", "}", "catch", "(", "e", ")", "{", "completed", "(", "e", ")", ";", "}", "}", ")", ";", "}" ]
Reads a number of bytes from a socket. @param {net.Socket} socket The socket. @param {Number} [numberOfBytes] The amount of bytes to read. @return {Promise<Buffer>} The promise.
[ "Reads", "a", "number", "of", "bytes", "from", "a", "socket", "." ]
a673f1987cd6d16f76c218c0a6a98723c42a12ce
https://github.com/mkloubert/node-simple-socket/blob/a673f1987cd6d16f76c218c0a6a98723c42a12ce/helpers.js#L96-L118
23,345
mkloubert/node-simple-socket
index.js
listen
function listen(port, cb) { return new Promise((resolve, reject) => { let completed = ssocket_helpers.createSimplePromiseCompletedAction(resolve, reject); try { let serverToClient; let server = Net.createServer((connectionWithClient) => { try { if (cb) { cb(null, createServer(connectionWithClient)); } } catch (e) { if (cb) { cb(e); } } }); let isListening = false; server.once('error', (err) => { if (!isListening && err) { completed(err); } }); server.on('listening', () => { isListening = true; completed(null, server); }); server.listen(port); } catch (e) { completed(e); } }); }
javascript
function listen(port, cb) { return new Promise((resolve, reject) => { let completed = ssocket_helpers.createSimplePromiseCompletedAction(resolve, reject); try { let serverToClient; let server = Net.createServer((connectionWithClient) => { try { if (cb) { cb(null, createServer(connectionWithClient)); } } catch (e) { if (cb) { cb(e); } } }); let isListening = false; server.once('error', (err) => { if (!isListening && err) { completed(err); } }); server.on('listening', () => { isListening = true; completed(null, server); }); server.listen(port); } catch (e) { completed(e); } }); }
[ "function", "listen", "(", "port", ",", "cb", ")", "{", "return", "new", "Promise", "(", "(", "resolve", ",", "reject", ")", "=>", "{", "let", "completed", "=", "ssocket_helpers", ".", "createSimplePromiseCompletedAction", "(", "resolve", ",", "reject", ")", ";", "try", "{", "let", "serverToClient", ";", "let", "server", "=", "Net", ".", "createServer", "(", "(", "connectionWithClient", ")", "=>", "{", "try", "{", "if", "(", "cb", ")", "{", "cb", "(", "null", ",", "createServer", "(", "connectionWithClient", ")", ")", ";", "}", "}", "catch", "(", "e", ")", "{", "if", "(", "cb", ")", "{", "cb", "(", "e", ")", ";", "}", "}", "}", ")", ";", "let", "isListening", "=", "false", ";", "server", ".", "once", "(", "'error'", ",", "(", "err", ")", "=>", "{", "if", "(", "!", "isListening", "&&", "err", ")", "{", "completed", "(", "err", ")", ";", "}", "}", ")", ";", "server", ".", "on", "(", "'listening'", ",", "(", ")", "=>", "{", "isListening", "=", "true", ";", "completed", "(", "null", ",", "server", ")", ";", "}", ")", ";", "server", ".", "listen", "(", "port", ")", ";", "}", "catch", "(", "e", ")", "{", "completed", "(", "e", ")", ";", "}", "}", ")", ";", "}" ]
Starts listening on a port. @param {number} port The TCP port to listen on. @param {ListenCallback} cb The listener callback. @return {Promise<Net.Server>} The promise.
[ "Starts", "listening", "on", "a", "port", "." ]
a673f1987cd6d16f76c218c0a6a98723c42a12ce
https://github.com/mkloubert/node-simple-socket/blob/a673f1987cd6d16f76c218c0a6a98723c42a12ce/index.js#L1253-L1286
23,346
octet-stream/node-yaml
lib/node-yaml.js
read
async function read(filename, options = undefined) { const {encoding, flag, ...opts} = normalizeOptions(options) if (!isNumber(filename)) { filename = await normalizePath(base, filename) opts.filename = filename } const content = await fs.readFile(filename, {encoding, flag}) return yaml.load(content, opts) }
javascript
async function read(filename, options = undefined) { const {encoding, flag, ...opts} = normalizeOptions(options) if (!isNumber(filename)) { filename = await normalizePath(base, filename) opts.filename = filename } const content = await fs.readFile(filename, {encoding, flag}) return yaml.load(content, opts) }
[ "async", "function", "read", "(", "filename", ",", "options", "=", "undefined", ")", "{", "const", "{", "encoding", ",", "flag", ",", "...", "opts", "}", "=", "normalizeOptions", "(", "options", ")", "if", "(", "!", "isNumber", "(", "filename", ")", ")", "{", "filename", "=", "await", "normalizePath", "(", "base", ",", "filename", ")", "opts", ".", "filename", "=", "filename", "}", "const", "content", "=", "await", "fs", ".", "readFile", "(", "filename", ",", "{", "encoding", ",", "flag", "}", ")", "return", "yaml", ".", "load", "(", "content", ",", "opts", ")", "}" ]
Read and parse YAML file from given path @param {string | number} filename @param {string | object} [options = undefined] @param {string} @return {Promise<object>} @api public
[ "Read", "and", "parse", "YAML", "file", "from", "given", "path" ]
cdbc81185b3769c20f9e9cabdec6d5ff7cb7a289
https://github.com/octet-stream/node-yaml/blob/cdbc81185b3769c20f9e9cabdec6d5ff7cb7a289/lib/node-yaml.js#L61-L73
23,347
octet-stream/node-yaml
lib/node-yaml.js
write
async function write(filename, object, options = undefined) { const {encoding, flag, ...opts} = normalizeOptions(options) if (!isNumber(filename)) { filename = toAbsolute(base, filename) opts.filename = filename } await fs.writeFile(filename, yaml.dump(object, opts), {encoding, flag}) }
javascript
async function write(filename, object, options = undefined) { const {encoding, flag, ...opts} = normalizeOptions(options) if (!isNumber(filename)) { filename = toAbsolute(base, filename) opts.filename = filename } await fs.writeFile(filename, yaml.dump(object, opts), {encoding, flag}) }
[ "async", "function", "write", "(", "filename", ",", "object", ",", "options", "=", "undefined", ")", "{", "const", "{", "encoding", ",", "flag", ",", "...", "opts", "}", "=", "normalizeOptions", "(", "options", ")", "if", "(", "!", "isNumber", "(", "filename", ")", ")", "{", "filename", "=", "toAbsolute", "(", "base", ",", "filename", ")", "opts", ".", "filename", "=", "filename", "}", "await", "fs", ".", "writeFile", "(", "filename", ",", "yaml", ".", "dump", "(", "object", ",", "opts", ")", ",", "{", "encoding", ",", "flag", "}", ")", "}" ]
Write given YAML content to disk @param {string | number} filename @param {object} object @param {options} [options = undefined] @return {void} @api public
[ "Write", "given", "YAML", "content", "to", "disk" ]
cdbc81185b3769c20f9e9cabdec6d5ff7cb7a289
https://github.com/octet-stream/node-yaml/blob/cdbc81185b3769c20f9e9cabdec6d5ff7cb7a289/lib/node-yaml.js#L110-L120
23,348
ebi-uniprot/ProtVista
gulpfile.js
exposeBundles
function exposeBundles(b){ b.add("./" + packageConfig.main, {expose: packageConfig.name }); if(packageConfig.sniper !== undefined && packageConfig.sniper.exposed !== undefined){ for(var i=0; i<packageConfig.sniper.exposed.length; i++){ b.require(packageConfig.sniper.exposed[i]); } } }
javascript
function exposeBundles(b){ b.add("./" + packageConfig.main, {expose: packageConfig.name }); if(packageConfig.sniper !== undefined && packageConfig.sniper.exposed !== undefined){ for(var i=0; i<packageConfig.sniper.exposed.length; i++){ b.require(packageConfig.sniper.exposed[i]); } } }
[ "function", "exposeBundles", "(", "b", ")", "{", "b", ".", "add", "(", "\"./\"", "+", "packageConfig", ".", "main", ",", "{", "expose", ":", "packageConfig", ".", "name", "}", ")", ";", "if", "(", "packageConfig", ".", "sniper", "!==", "undefined", "&&", "packageConfig", ".", "sniper", ".", "exposed", "!==", "undefined", ")", "{", "for", "(", "var", "i", "=", "0", ";", "i", "<", "packageConfig", ".", "sniper", ".", "exposed", ".", "length", ";", "i", "++", ")", "{", "b", ".", "require", "(", "packageConfig", ".", "sniper", ".", "exposed", "[", "i", "]", ")", ";", "}", "}", "}" ]
exposes the main package + checks the config whether it should expose other packages
[ "exposes", "the", "main", "package", "+", "checks", "the", "config", "whether", "it", "should", "expose", "other", "packages" ]
ea5172f18c5cc448db71111184ef3919daf67ce1
https://github.com/ebi-uniprot/ProtVista/blob/ea5172f18c5cc448db71111184ef3919daf67ce1/gulpfile.js#L178-L185
23,349
hex7c0/mkdir-recursive
index.js
mkdirSync
function mkdirSync(root, mode) { if (typeof root !== 'string') { throw new Error('missing root'); } var chunks = root.split(path.sep); // split in chunks var chunk; if (path.isAbsolute(root) === true) { // build from absolute path chunk = chunks.shift(); // remove "/" or C:/ if (!chunk) { // add "/" chunk = path.sep; } } else { chunk = path.resolve(); // build with relative path } return mkdirSyncRecursive(chunk, chunks, mode); }
javascript
function mkdirSync(root, mode) { if (typeof root !== 'string') { throw new Error('missing root'); } var chunks = root.split(path.sep); // split in chunks var chunk; if (path.isAbsolute(root) === true) { // build from absolute path chunk = chunks.shift(); // remove "/" or C:/ if (!chunk) { // add "/" chunk = path.sep; } } else { chunk = path.resolve(); // build with relative path } return mkdirSyncRecursive(chunk, chunks, mode); }
[ "function", "mkdirSync", "(", "root", ",", "mode", ")", "{", "if", "(", "typeof", "root", "!==", "'string'", ")", "{", "throw", "new", "Error", "(", "'missing root'", ")", ";", "}", "var", "chunks", "=", "root", ".", "split", "(", "path", ".", "sep", ")", ";", "// split in chunks", "var", "chunk", ";", "if", "(", "path", ".", "isAbsolute", "(", "root", ")", "===", "true", ")", "{", "// build from absolute path", "chunk", "=", "chunks", ".", "shift", "(", ")", ";", "// remove \"/\" or C:/", "if", "(", "!", "chunk", ")", "{", "// add \"/\"", "chunk", "=", "path", ".", "sep", ";", "}", "}", "else", "{", "chunk", "=", "path", ".", "resolve", "(", ")", ";", "// build with relative path", "}", "return", "mkdirSyncRecursive", "(", "chunk", ",", "chunks", ",", "mode", ")", ";", "}" ]
makeSync main. Check README.md @exports mkdirSync @function mkdirSync @param {String} root - pathname @param {Number} mode - directories mode, see Node documentation @return [{Object}]
[ "makeSync", "main", ".", "Check", "README", ".", "md" ]
25c6a044688043f8be8ff5d2432c22e25b393432
https://github.com/hex7c0/mkdir-recursive/blob/25c6a044688043f8be8ff5d2432c22e25b393432/index.js#L65-L83
23,350
hex7c0/mkdir-recursive
index.js
rmdir
function rmdir(root, callback) { if (typeof root !== 'string') { throw new Error('missing root'); } else if (typeof callback !== 'function') { throw new Error('missing callback'); } var chunks = root.split(path.sep); // split in chunks var chunk = path.resolve(root); // build absolute path // remove "/" from head and tail if (chunks[0] === '') { chunks.shift(); } if (chunks[chunks.length - 1] === '') { chunks.pop(); } return rmdirRecursive(chunk, chunks, callback); }
javascript
function rmdir(root, callback) { if (typeof root !== 'string') { throw new Error('missing root'); } else if (typeof callback !== 'function') { throw new Error('missing callback'); } var chunks = root.split(path.sep); // split in chunks var chunk = path.resolve(root); // build absolute path // remove "/" from head and tail if (chunks[0] === '') { chunks.shift(); } if (chunks[chunks.length - 1] === '') { chunks.pop(); } return rmdirRecursive(chunk, chunks, callback); }
[ "function", "rmdir", "(", "root", ",", "callback", ")", "{", "if", "(", "typeof", "root", "!==", "'string'", ")", "{", "throw", "new", "Error", "(", "'missing root'", ")", ";", "}", "else", "if", "(", "typeof", "callback", "!==", "'function'", ")", "{", "throw", "new", "Error", "(", "'missing callback'", ")", ";", "}", "var", "chunks", "=", "root", ".", "split", "(", "path", ".", "sep", ")", ";", "// split in chunks", "var", "chunk", "=", "path", ".", "resolve", "(", "root", ")", ";", "// build absolute path", "// remove \"/\" from head and tail", "if", "(", "chunks", "[", "0", "]", "===", "''", ")", "{", "chunks", ".", "shift", "(", ")", ";", "}", "if", "(", "chunks", "[", "chunks", ".", "length", "-", "1", "]", "===", "''", ")", "{", "chunks", ".", "pop", "(", ")", ";", "}", "return", "rmdirRecursive", "(", "chunk", ",", "chunks", ",", "callback", ")", ";", "}" ]
remove main. Check README.md @exports rmdir @function rmdir @param {String} root - pathname @param {Function} callback - next callback
[ "remove", "main", ".", "Check", "README", ".", "md" ]
25c6a044688043f8be8ff5d2432c22e25b393432
https://github.com/hex7c0/mkdir-recursive/blob/25c6a044688043f8be8ff5d2432c22e25b393432/index.js#L94-L113
23,351
hex7c0/mkdir-recursive
index.js
rmdirSync
function rmdirSync(root) { if (typeof root !== 'string') { throw new Error('missing root'); } var chunks = root.split(path.sep); // split in chunks var chunk = path.resolve(root); // build absolute path // remove "/" from head and tail if (chunks[0] === '') { chunks.shift(); } if (chunks[chunks.length - 1] === '') { chunks.pop(); } return rmdirSyncRecursive(chunk, chunks); }
javascript
function rmdirSync(root) { if (typeof root !== 'string') { throw new Error('missing root'); } var chunks = root.split(path.sep); // split in chunks var chunk = path.resolve(root); // build absolute path // remove "/" from head and tail if (chunks[0] === '') { chunks.shift(); } if (chunks[chunks.length - 1] === '') { chunks.pop(); } return rmdirSyncRecursive(chunk, chunks); }
[ "function", "rmdirSync", "(", "root", ")", "{", "if", "(", "typeof", "root", "!==", "'string'", ")", "{", "throw", "new", "Error", "(", "'missing root'", ")", ";", "}", "var", "chunks", "=", "root", ".", "split", "(", "path", ".", "sep", ")", ";", "// split in chunks", "var", "chunk", "=", "path", ".", "resolve", "(", "root", ")", ";", "// build absolute path", "// remove \"/\" from head and tail", "if", "(", "chunks", "[", "0", "]", "===", "''", ")", "{", "chunks", ".", "shift", "(", ")", ";", "}", "if", "(", "chunks", "[", "chunks", ".", "length", "-", "1", "]", "===", "''", ")", "{", "chunks", ".", "pop", "(", ")", ";", "}", "return", "rmdirSyncRecursive", "(", "chunk", ",", "chunks", ")", ";", "}" ]
removeSync main. Check README.md @exports rmdirSync @function rmdirSync @param {String} root - pathname @return [{Object}]
[ "removeSync", "main", ".", "Check", "README", ".", "md" ]
25c6a044688043f8be8ff5d2432c22e25b393432
https://github.com/hex7c0/mkdir-recursive/blob/25c6a044688043f8be8ff5d2432c22e25b393432/index.js#L124-L141
23,352
hex7c0/mkdir-recursive
index.js
mkdirSyncRecursive
function mkdirSyncRecursive(root, chunks, mode) { var chunk = chunks.shift(); if (!chunk) { return; } var root = path.join(root, chunk); if (fs.existsSync(root) === true) { // already done return mkdirSyncRecursive(root, chunks, mode); } var err = fs.mkdirSync(root, mode); return err ? err : mkdirSyncRecursive(root, chunks, mode); // let's magic }
javascript
function mkdirSyncRecursive(root, chunks, mode) { var chunk = chunks.shift(); if (!chunk) { return; } var root = path.join(root, chunk); if (fs.existsSync(root) === true) { // already done return mkdirSyncRecursive(root, chunks, mode); } var err = fs.mkdirSync(root, mode); return err ? err : mkdirSyncRecursive(root, chunks, mode); // let's magic }
[ "function", "mkdirSyncRecursive", "(", "root", ",", "chunks", ",", "mode", ")", "{", "var", "chunk", "=", "chunks", ".", "shift", "(", ")", ";", "if", "(", "!", "chunk", ")", "{", "return", ";", "}", "var", "root", "=", "path", ".", "join", "(", "root", ",", "chunk", ")", ";", "if", "(", "fs", ".", "existsSync", "(", "root", ")", "===", "true", ")", "{", "// already done", "return", "mkdirSyncRecursive", "(", "root", ",", "chunks", ",", "mode", ")", ";", "}", "var", "err", "=", "fs", ".", "mkdirSync", "(", "root", ",", "mode", ")", ";", "return", "err", "?", "err", ":", "mkdirSyncRecursive", "(", "root", ",", "chunks", ",", "mode", ")", ";", "// let's magic", "}" ]
make directory recursively. Sync version @function mkdirSyncRecursive @param {String} root - absolute root where append chunks @param {Array} chunks - directories chunks @param {Number} mode - directories mode, see Node documentation @return [{Object}]
[ "make", "directory", "recursively", ".", "Sync", "version" ]
25c6a044688043f8be8ff5d2432c22e25b393432
https://github.com/hex7c0/mkdir-recursive/blob/25c6a044688043f8be8ff5d2432c22e25b393432/index.js#L187-L200
23,353
hex7c0/mkdir-recursive
index.js
rmdirRecursive
function rmdirRecursive(root, chunks, callback) { var chunk = chunks.pop(); if (!chunk) { return callback(null); } var pathname = path.join(root, '..'); // backtrack return fs.exists(root, function(exists) { if (exists === false) { // already done return rmdirRecursive(root, chunks, callback); } return fs.rmdir(root, function(err) { if (err) { return callback(err); } return rmdirRecursive(pathname, chunks, callback); // let's magic }); }); }
javascript
function rmdirRecursive(root, chunks, callback) { var chunk = chunks.pop(); if (!chunk) { return callback(null); } var pathname = path.join(root, '..'); // backtrack return fs.exists(root, function(exists) { if (exists === false) { // already done return rmdirRecursive(root, chunks, callback); } return fs.rmdir(root, function(err) { if (err) { return callback(err); } return rmdirRecursive(pathname, chunks, callback); // let's magic }); }); }
[ "function", "rmdirRecursive", "(", "root", ",", "chunks", ",", "callback", ")", "{", "var", "chunk", "=", "chunks", ".", "pop", "(", ")", ";", "if", "(", "!", "chunk", ")", "{", "return", "callback", "(", "null", ")", ";", "}", "var", "pathname", "=", "path", ".", "join", "(", "root", ",", "'..'", ")", ";", "// backtrack", "return", "fs", ".", "exists", "(", "root", ",", "function", "(", "exists", ")", "{", "if", "(", "exists", "===", "false", ")", "{", "// already done", "return", "rmdirRecursive", "(", "root", ",", "chunks", ",", "callback", ")", ";", "}", "return", "fs", ".", "rmdir", "(", "root", ",", "function", "(", "err", ")", "{", "if", "(", "err", ")", "{", "return", "callback", "(", "err", ")", ";", "}", "return", "rmdirRecursive", "(", "pathname", ",", "chunks", ",", "callback", ")", ";", "// let's magic", "}", ")", ";", "}", ")", ";", "}" ]
remove directory recursively @function rmdirRecursive @param {String} root - absolute root where take chunks @param {Array} chunks - directories chunks @param {Function} callback - next callback
[ "remove", "directory", "recursively" ]
25c6a044688043f8be8ff5d2432c22e25b393432
https://github.com/hex7c0/mkdir-recursive/blob/25c6a044688043f8be8ff5d2432c22e25b393432/index.js#L210-L231
23,354
hex7c0/mkdir-recursive
index.js
rmdirSyncRecursive
function rmdirSyncRecursive(root, chunks) { var chunk = chunks.pop(); if (!chunk) { return; } var pathname = path.join(root, '..'); // backtrack if (fs.existsSync(root) === false) { // already done return rmdirSyncRecursive(root, chunks); } var err = fs.rmdirSync(root); return err ? err : rmdirSyncRecursive(pathname, chunks); // let's magic }
javascript
function rmdirSyncRecursive(root, chunks) { var chunk = chunks.pop(); if (!chunk) { return; } var pathname = path.join(root, '..'); // backtrack if (fs.existsSync(root) === false) { // already done return rmdirSyncRecursive(root, chunks); } var err = fs.rmdirSync(root); return err ? err : rmdirSyncRecursive(pathname, chunks); // let's magic }
[ "function", "rmdirSyncRecursive", "(", "root", ",", "chunks", ")", "{", "var", "chunk", "=", "chunks", ".", "pop", "(", ")", ";", "if", "(", "!", "chunk", ")", "{", "return", ";", "}", "var", "pathname", "=", "path", ".", "join", "(", "root", ",", "'..'", ")", ";", "// backtrack", "if", "(", "fs", ".", "existsSync", "(", "root", ")", "===", "false", ")", "{", "// already done", "return", "rmdirSyncRecursive", "(", "root", ",", "chunks", ")", ";", "}", "var", "err", "=", "fs", ".", "rmdirSync", "(", "root", ")", ";", "return", "err", "?", "err", ":", "rmdirSyncRecursive", "(", "pathname", ",", "chunks", ")", ";", "// let's magic", "}" ]
remove directory recursively. Sync version @function rmdirRecursive @param {String} root - absolute root where take chunks @param {Array} chunks - directories chunks @return [{Object}]
[ "remove", "directory", "recursively", ".", "Sync", "version" ]
25c6a044688043f8be8ff5d2432c22e25b393432
https://github.com/hex7c0/mkdir-recursive/blob/25c6a044688043f8be8ff5d2432c22e25b393432/index.js#L241-L254
23,355
doowb/group-array
examples/geojson.js
interval
function interval(prop) { // create a function that will use the intervals to check the group by property return function(intervals) { // create custom labels to use for the resulting object keys var labels = intervals.reduce(function(acc, val, i) { var min = val; var max = (intervals[i + 1] && intervals[i + 1] - 1) || '*'; acc[val] = min + ' - ' + max; return acc; }, {}); // create a function that does the grouping for each item return function(item) { // value to group by var val = item[prop]; // if the value falls between the interval range, return it // as an array to make the interval value the key being grouped by return intervals.filter(function(int, i) { var min = int; var max = intervals[i+1] || Infinity; return min <= val && val < max; }).map(function(int) { return labels[int]; }); }; }; }
javascript
function interval(prop) { // create a function that will use the intervals to check the group by property return function(intervals) { // create custom labels to use for the resulting object keys var labels = intervals.reduce(function(acc, val, i) { var min = val; var max = (intervals[i + 1] && intervals[i + 1] - 1) || '*'; acc[val] = min + ' - ' + max; return acc; }, {}); // create a function that does the grouping for each item return function(item) { // value to group by var val = item[prop]; // if the value falls between the interval range, return it // as an array to make the interval value the key being grouped by return intervals.filter(function(int, i) { var min = int; var max = intervals[i+1] || Infinity; return min <= val && val < max; }).map(function(int) { return labels[int]; }); }; }; }
[ "function", "interval", "(", "prop", ")", "{", "// create a function that will use the intervals to check the group by property", "return", "function", "(", "intervals", ")", "{", "// create custom labels to use for the resulting object keys", "var", "labels", "=", "intervals", ".", "reduce", "(", "function", "(", "acc", ",", "val", ",", "i", ")", "{", "var", "min", "=", "val", ";", "var", "max", "=", "(", "intervals", "[", "i", "+", "1", "]", "&&", "intervals", "[", "i", "+", "1", "]", "-", "1", ")", "||", "'*'", ";", "acc", "[", "val", "]", "=", "min", "+", "' - '", "+", "max", ";", "return", "acc", ";", "}", ",", "{", "}", ")", ";", "// create a function that does the grouping for each item", "return", "function", "(", "item", ")", "{", "// value to group by", "var", "val", "=", "item", "[", "prop", "]", ";", "// if the value falls between the interval range, return it", "// as an array to make the interval value the key being grouped by", "return", "intervals", ".", "filter", "(", "function", "(", "int", ",", "i", ")", "{", "var", "min", "=", "int", ";", "var", "max", "=", "intervals", "[", "i", "+", "1", "]", "||", "Infinity", ";", "return", "min", "<=", "val", "&&", "val", "<", "max", ";", "}", ")", ".", "map", "(", "function", "(", "int", ")", "{", "return", "labels", "[", "int", "]", ";", "}", ")", ";", "}", ";", "}", ";", "}" ]
create a function that will use the property provided to group on
[ "create", "a", "function", "that", "will", "use", "the", "property", "provided", "to", "group", "on" ]
69c01ca548146e7a5c12eb2ad7c0310161854cb9
https://github.com/doowb/group-array/blob/69c01ca548146e7a5c12eb2ad7c0310161854cb9/examples/geojson.js#L10-L40
23,356
ulivz/vue-foldable
docs/.vuepress/config.js
inferSiderbars
function inferSiderbars () { // You will need to update this config when directory was added or removed. const sidebars = [ // { title: 'JavaScript', dirname: 'javascript' }, // { title: 'CSS', dirname: 'css' }, ] return sidebars.map(({ title, dirname }) => { const dirpath = path.resolve(__dirname, '../' + dirname) return { title, collapsable: false, children: fs .readdirSync(dirpath) .filter(item => item.endsWith('.md') && fs.statSync(path.join(dirpath, item)).isFile()) .map(item => dirname + '/' + item.replace(/(README)?(.md)$/, '')) } }) }
javascript
function inferSiderbars () { // You will need to update this config when directory was added or removed. const sidebars = [ // { title: 'JavaScript', dirname: 'javascript' }, // { title: 'CSS', dirname: 'css' }, ] return sidebars.map(({ title, dirname }) => { const dirpath = path.resolve(__dirname, '../' + dirname) return { title, collapsable: false, children: fs .readdirSync(dirpath) .filter(item => item.endsWith('.md') && fs.statSync(path.join(dirpath, item)).isFile()) .map(item => dirname + '/' + item.replace(/(README)?(.md)$/, '')) } }) }
[ "function", "inferSiderbars", "(", ")", "{", "// You will need to update this config when directory was added or removed.", "const", "sidebars", "=", "[", "// { title: 'JavaScript', dirname: 'javascript' },", "// { title: 'CSS', dirname: 'css' },", "]", "return", "sidebars", ".", "map", "(", "(", "{", "title", ",", "dirname", "}", ")", "=>", "{", "const", "dirpath", "=", "path", ".", "resolve", "(", "__dirname", ",", "'../'", "+", "dirname", ")", "return", "{", "title", ",", "collapsable", ":", "false", ",", "children", ":", "fs", ".", "readdirSync", "(", "dirpath", ")", ".", "filter", "(", "item", "=>", "item", ".", "endsWith", "(", "'.md'", ")", "&&", "fs", ".", "statSync", "(", "path", ".", "join", "(", "dirpath", ",", "item", ")", ")", ".", "isFile", "(", ")", ")", ".", "map", "(", "item", "=>", "dirname", "+", "'/'", "+", "item", ".", "replace", "(", "/", "(README)?(.md)$", "/", ",", "''", ")", ")", "}", "}", ")", "}" ]
If you want to create a docs that automatically lists all files in all subdirectories, This method will help you complete this task. If you do not prefer this preset, just remove it and configure it according to the docs: https://vuepress.vuejs.org/default-theme-config/#sidebar @returns {Array}
[ "If", "you", "want", "to", "create", "a", "docs", "that", "automatically", "lists", "all", "files", "in", "all", "subdirectories", "This", "method", "will", "help", "you", "complete", "this", "task", "." ]
1c91ad97fb2f48941c6554d18a6997615c2164bb
https://github.com/ulivz/vue-foldable/blob/1c91ad97fb2f48941c6554d18a6997615c2164bb/docs/.vuepress/config.js#L53-L70
23,357
ulivz/vue-foldable
scripts/build.js
getBuildingConfigs
function getBuildingConfigs (target) { return target.map(({ dirname, name, version, entry, outDir, styleFilename }) => { return formats.map(format => { return { inputOptions: getInputOptions({ entry, outDir, styleFilename }), outputOptions: getOutputOptions({ outDir, name, version, format }) } }) }).reduce((prev, next) => prev.concat(next)) }
javascript
function getBuildingConfigs (target) { return target.map(({ dirname, name, version, entry, outDir, styleFilename }) => { return formats.map(format => { return { inputOptions: getInputOptions({ entry, outDir, styleFilename }), outputOptions: getOutputOptions({ outDir, name, version, format }) } }) }).reduce((prev, next) => prev.concat(next)) }
[ "function", "getBuildingConfigs", "(", "target", ")", "{", "return", "target", ".", "map", "(", "(", "{", "dirname", ",", "name", ",", "version", ",", "entry", ",", "outDir", ",", "styleFilename", "}", ")", "=>", "{", "return", "formats", ".", "map", "(", "format", "=>", "{", "return", "{", "inputOptions", ":", "getInputOptions", "(", "{", "entry", ",", "outDir", ",", "styleFilename", "}", ")", ",", "outputOptions", ":", "getOutputOptions", "(", "{", "outDir", ",", "name", ",", "version", ",", "format", "}", ")", "}", "}", ")", "}", ")", ".", "reduce", "(", "(", "prev", ",", "next", ")", "=>", "prev", ".", "concat", "(", "next", ")", ")", "}" ]
Get rollup building configurations @param target
[ "Get", "rollup", "building", "configurations" ]
1c91ad97fb2f48941c6554d18a6997615c2164bb
https://github.com/ulivz/vue-foldable/blob/1c91ad97fb2f48941c6554d18a6997615c2164bb/scripts/build.js#L67-L76
23,358
nodeca/unhomoglyph
update.js
save
function save(str) { let result = {}; console.log('Writing data...'); str.split(/\r?\n/g) .filter(line => line.length && line[0] !== '#') .forEach(line => { if (line.split(';').length < 2) return; let [ src, dst ] = line.split(';').slice(0, 2).map(s => s.trim()); src = String.fromCodePoint(parseInt(src, 16)); dst = dst .replace(/\s+/g, ' ') .split(' ') .map(code => !code ? '' : String.fromCodePoint(parseInt(code, 16))) .join(''); result[src] = dst; }); fs.writeFileSync(SAVE_PATH, JSON.stringify(result, null, ' ')); console.log('Done!'); }
javascript
function save(str) { let result = {}; console.log('Writing data...'); str.split(/\r?\n/g) .filter(line => line.length && line[0] !== '#') .forEach(line => { if (line.split(';').length < 2) return; let [ src, dst ] = line.split(';').slice(0, 2).map(s => s.trim()); src = String.fromCodePoint(parseInt(src, 16)); dst = dst .replace(/\s+/g, ' ') .split(' ') .map(code => !code ? '' : String.fromCodePoint(parseInt(code, 16))) .join(''); result[src] = dst; }); fs.writeFileSync(SAVE_PATH, JSON.stringify(result, null, ' ')); console.log('Done!'); }
[ "function", "save", "(", "str", ")", "{", "let", "result", "=", "{", "}", ";", "console", ".", "log", "(", "'Writing data...'", ")", ";", "str", ".", "split", "(", "/", "\\r?\\n", "/", "g", ")", ".", "filter", "(", "line", "=>", "line", ".", "length", "&&", "line", "[", "0", "]", "!==", "'#'", ")", ".", "forEach", "(", "line", "=>", "{", "if", "(", "line", ".", "split", "(", "';'", ")", ".", "length", "<", "2", ")", "return", ";", "let", "[", "src", ",", "dst", "]", "=", "line", ".", "split", "(", "';'", ")", ".", "slice", "(", "0", ",", "2", ")", ".", "map", "(", "s", "=>", "s", ".", "trim", "(", ")", ")", ";", "src", "=", "String", ".", "fromCodePoint", "(", "parseInt", "(", "src", ",", "16", ")", ")", ";", "dst", "=", "dst", ".", "replace", "(", "/", "\\s+", "/", "g", ",", "' '", ")", ".", "split", "(", "' '", ")", ".", "map", "(", "code", "=>", "!", "code", "?", "''", ":", "String", ".", "fromCodePoint", "(", "parseInt", "(", "code", ",", "16", ")", ")", ")", ".", "join", "(", "''", ")", ";", "result", "[", "src", "]", "=", "dst", ";", "}", ")", ";", "fs", ".", "writeFileSync", "(", "SAVE_PATH", ",", "JSON", ".", "stringify", "(", "result", ",", "null", ",", "' '", ")", ")", ";", "console", ".", "log", "(", "'Done!'", ")", ";", "}" ]
Parse & save mappings
[ "Parse", "&", "save", "mappings" ]
fed5576b38863d75cdc16414c2fa61d9f9f28442
https://github.com/nodeca/unhomoglyph/blob/fed5576b38863d75cdc16414c2fa61d9f9f28442/update.js#L19-L43
23,359
grantcarthew/node-rethinkdb-job-queue
src/queue-change.js
restartProcessing
function restartProcessing (q) { logger('restartProcessing') setTimeout(function randomRestart () { queueProcess.restart(q) }, Math.floor(Math.random() * 1000)) }
javascript
function restartProcessing (q) { logger('restartProcessing') setTimeout(function randomRestart () { queueProcess.restart(q) }, Math.floor(Math.random() * 1000)) }
[ "function", "restartProcessing", "(", "q", ")", "{", "logger", "(", "'restartProcessing'", ")", "setTimeout", "(", "function", "randomRestart", "(", ")", "{", "queueProcess", ".", "restart", "(", "q", ")", "}", ",", "Math", ".", "floor", "(", "Math", ".", "random", "(", ")", "*", "1000", ")", ")", "}" ]
Following is the list of supported change feed events; paused - Global event resumed - Global event reviewed - Global event added active progress completed cancelled failed terminated removed log
[ "Following", "is", "the", "list", "of", "supported", "change", "feed", "events", ";", "paused", "-", "Global", "event", "resumed", "-", "Global", "event", "reviewed", "-", "Global", "event", "added", "active", "progress", "completed", "cancelled", "failed", "terminated", "removed", "log" ]
ae3111cdd7596c552e05d60a32daadd4088af63f
https://github.com/grantcarthew/node-rethinkdb-job-queue/blob/ae3111cdd7596c552e05d60a32daadd4088af63f/src/queue-change.js#L22-L27
23,360
mudchina/webtelnet
webtelnet-proxy.js
unicodeStringToTypedArray
function unicodeStringToTypedArray(s) { var escstr = encodeURIComponent(s); var binstr = escstr.replace(/%([0-9A-F]{2})/g, function(match, p1) { return String.fromCharCode('0x' + p1); }); var ua = new Uint8Array(binstr.length); Array.prototype.forEach.call(binstr, function (ch, i) { ua[i] = ch.charCodeAt(0); }); return ua; }
javascript
function unicodeStringToTypedArray(s) { var escstr = encodeURIComponent(s); var binstr = escstr.replace(/%([0-9A-F]{2})/g, function(match, p1) { return String.fromCharCode('0x' + p1); }); var ua = new Uint8Array(binstr.length); Array.prototype.forEach.call(binstr, function (ch, i) { ua[i] = ch.charCodeAt(0); }); return ua; }
[ "function", "unicodeStringToTypedArray", "(", "s", ")", "{", "var", "escstr", "=", "encodeURIComponent", "(", "s", ")", ";", "var", "binstr", "=", "escstr", ".", "replace", "(", "/", "%([0-9A-F]{2})", "/", "g", ",", "function", "(", "match", ",", "p1", ")", "{", "return", "String", ".", "fromCharCode", "(", "'0x'", "+", "p1", ")", ";", "}", ")", ";", "var", "ua", "=", "new", "Uint8Array", "(", "binstr", ".", "length", ")", ";", "Array", ".", "prototype", ".", "forEach", ".", "call", "(", "binstr", ",", "function", "(", "ch", ",", "i", ")", "{", "ua", "[", "i", "]", "=", "ch", ".", "charCodeAt", "(", "0", ")", ";", "}", ")", ";", "return", "ua", ";", "}" ]
string to uint array
[ "string", "to", "uint", "array" ]
47b47d15040f1dd100099fa7b98e186723a1dbae
https://github.com/mudchina/webtelnet/blob/47b47d15040f1dd100099fa7b98e186723a1dbae/webtelnet-proxy.js#L10-L20
23,361
mudchina/webtelnet
webtelnet-proxy.js
typedArrayToUnicodeString
function typedArrayToUnicodeString(ua) { var binstr = Array.prototype.map.call(ua, function (ch) { return String.fromCharCode(ch); }).join(''); var escstr = binstr.replace(/(.)/g, function (m, p) { var code = p.charCodeAt(p).toString(16).toUpperCase(); if (code.length < 2) { code = '0' + code; } return '%' + code; }); return decodeURIComponent(escstr); }
javascript
function typedArrayToUnicodeString(ua) { var binstr = Array.prototype.map.call(ua, function (ch) { return String.fromCharCode(ch); }).join(''); var escstr = binstr.replace(/(.)/g, function (m, p) { var code = p.charCodeAt(p).toString(16).toUpperCase(); if (code.length < 2) { code = '0' + code; } return '%' + code; }); return decodeURIComponent(escstr); }
[ "function", "typedArrayToUnicodeString", "(", "ua", ")", "{", "var", "binstr", "=", "Array", ".", "prototype", ".", "map", ".", "call", "(", "ua", ",", "function", "(", "ch", ")", "{", "return", "String", ".", "fromCharCode", "(", "ch", ")", ";", "}", ")", ".", "join", "(", "''", ")", ";", "var", "escstr", "=", "binstr", ".", "replace", "(", "/", "(.)", "/", "g", ",", "function", "(", "m", ",", "p", ")", "{", "var", "code", "=", "p", ".", "charCodeAt", "(", "p", ")", ".", "toString", "(", "16", ")", ".", "toUpperCase", "(", ")", ";", "if", "(", "code", ".", "length", "<", "2", ")", "{", "code", "=", "'0'", "+", "code", ";", "}", "return", "'%'", "+", "code", ";", "}", ")", ";", "return", "decodeURIComponent", "(", "escstr", ")", ";", "}" ]
uint array to string
[ "uint", "array", "to", "string" ]
47b47d15040f1dd100099fa7b98e186723a1dbae
https://github.com/mudchina/webtelnet/blob/47b47d15040f1dd100099fa7b98e186723a1dbae/webtelnet-proxy.js#L23-L35
23,362
sam3d/vue-svg
index.js
setup
function setup(config, options) { const rule = config.module.rule("svg"); // Find the svg rule /* * Let's use the file loader option defaults for the svg loader again. Otherwise * we'll have to set our own and it's no longer consistent with the changing * vue-cli. */ const fileLoaderOptions = rule.use("file-loader").get("options"); // Get the file loader options options.external = _.merge(fileLoaderOptions, options.external); // Make sure we save the file loader options // Use file loader options for sprite name options.sprite = _.merge( { spriteFilename: fileLoaderOptions.name }, options.sprite ); rule.uses.clear(); // Clear out existing uses of the svg rule const query = parseResourceQuery(options); // Get the resource queries rule .oneOf("inline") .resourceQuery(query.inline) .use("vue-svg-loader") .loader("vue-svg-loader") .options(options.inline); rule .oneOf("sprite") .resourceQuery(query.sprite) .use("svg-sprite-loader") .loader("svg-sprite-loader") .options(options.sprite); rule .oneOf("data") .resourceQuery(query.data) .use("url-loader") .loader("url-loader") .options(options.data); rule .oneOf("external") .use("file-loader") .loader("file-loader") .options(options.external); }
javascript
function setup(config, options) { const rule = config.module.rule("svg"); // Find the svg rule /* * Let's use the file loader option defaults for the svg loader again. Otherwise * we'll have to set our own and it's no longer consistent with the changing * vue-cli. */ const fileLoaderOptions = rule.use("file-loader").get("options"); // Get the file loader options options.external = _.merge(fileLoaderOptions, options.external); // Make sure we save the file loader options // Use file loader options for sprite name options.sprite = _.merge( { spriteFilename: fileLoaderOptions.name }, options.sprite ); rule.uses.clear(); // Clear out existing uses of the svg rule const query = parseResourceQuery(options); // Get the resource queries rule .oneOf("inline") .resourceQuery(query.inline) .use("vue-svg-loader") .loader("vue-svg-loader") .options(options.inline); rule .oneOf("sprite") .resourceQuery(query.sprite) .use("svg-sprite-loader") .loader("svg-sprite-loader") .options(options.sprite); rule .oneOf("data") .resourceQuery(query.data) .use("url-loader") .loader("url-loader") .options(options.data); rule .oneOf("external") .use("file-loader") .loader("file-loader") .options(options.external); }
[ "function", "setup", "(", "config", ",", "options", ")", "{", "const", "rule", "=", "config", ".", "module", ".", "rule", "(", "\"svg\"", ")", ";", "// Find the svg rule", "/*\n * Let's use the file loader option defaults for the svg loader again. Otherwise\n * we'll have to set our own and it's no longer consistent with the changing\n * vue-cli.\n */", "const", "fileLoaderOptions", "=", "rule", ".", "use", "(", "\"file-loader\"", ")", ".", "get", "(", "\"options\"", ")", ";", "// Get the file loader options", "options", ".", "external", "=", "_", ".", "merge", "(", "fileLoaderOptions", ",", "options", ".", "external", ")", ";", "// Make sure we save the file loader options", "// Use file loader options for sprite name", "options", ".", "sprite", "=", "_", ".", "merge", "(", "{", "spriteFilename", ":", "fileLoaderOptions", ".", "name", "}", ",", "options", ".", "sprite", ")", ";", "rule", ".", "uses", ".", "clear", "(", ")", ";", "// Clear out existing uses of the svg rule", "const", "query", "=", "parseResourceQuery", "(", "options", ")", ";", "// Get the resource queries", "rule", ".", "oneOf", "(", "\"inline\"", ")", ".", "resourceQuery", "(", "query", ".", "inline", ")", ".", "use", "(", "\"vue-svg-loader\"", ")", ".", "loader", "(", "\"vue-svg-loader\"", ")", ".", "options", "(", "options", ".", "inline", ")", ";", "rule", ".", "oneOf", "(", "\"sprite\"", ")", ".", "resourceQuery", "(", "query", ".", "sprite", ")", ".", "use", "(", "\"svg-sprite-loader\"", ")", ".", "loader", "(", "\"svg-sprite-loader\"", ")", ".", "options", "(", "options", ".", "sprite", ")", ";", "rule", ".", "oneOf", "(", "\"data\"", ")", ".", "resourceQuery", "(", "query", ".", "data", ")", ".", "use", "(", "\"url-loader\"", ")", ".", "loader", "(", "\"url-loader\"", ")", ".", "options", "(", "options", ".", "data", ")", ";", "rule", ".", "oneOf", "(", "\"external\"", ")", ".", "use", "(", "\"file-loader\"", ")", ".", "loader", "(", "\"file-loader\"", ")", ".", "options", "(", "options", ".", "external", ")", ";", "}" ]
Perform the main setup of the svg rule parsing and rewriting. This uses the chainWebpack API modify the required rules. @param {ChainWebpack} config An instance of ChainWebpack @param {Object} options The svg options from the vue.config.js
[ "Perform", "the", "main", "setup", "of", "the", "svg", "rule", "parsing", "and", "rewriting", ".", "This", "uses", "the", "chainWebpack", "API", "modify", "the", "required", "rules", "." ]
6d83be536df4ef247ab94d57615b22c0b4e78aaf
https://github.com/sam3d/vue-svg/blob/6d83be536df4ef247ab94d57615b22c0b4e78aaf/index.js#L31-L77
23,363
sam3d/vue-svg
index.js
parseResourceQuery
function parseResourceQuery(options) { const query = {}; for (option in options) { if (!options[option].resourceQuery) continue; // Skip if no query query[option] = options[option].resourceQuery; // Get the query delete options[option].resourceQuery; // Delete the field (to prevent passing it as a loader option) } return query; }
javascript
function parseResourceQuery(options) { const query = {}; for (option in options) { if (!options[option].resourceQuery) continue; // Skip if no query query[option] = options[option].resourceQuery; // Get the query delete options[option].resourceQuery; // Delete the field (to prevent passing it as a loader option) } return query; }
[ "function", "parseResourceQuery", "(", "options", ")", "{", "const", "query", "=", "{", "}", ";", "for", "(", "option", "in", "options", ")", "{", "if", "(", "!", "options", "[", "option", "]", ".", "resourceQuery", ")", "continue", ";", "// Skip if no query", "query", "[", "option", "]", "=", "options", "[", "option", "]", ".", "resourceQuery", ";", "// Get the query", "delete", "options", "[", "option", "]", ".", "resourceQuery", ";", "// Delete the field (to prevent passing it as a loader option)", "}", "return", "query", ";", "}" ]
Processes the options object passed to the app by extracting the resource query options and returning them so that they can be used later. @param {object} options The plugin options object @return {object} An object containing the resource queries and their relevant config names
[ "Processes", "the", "options", "object", "passed", "to", "the", "app", "by", "extracting", "the", "resource", "query", "options", "and", "returning", "them", "so", "that", "they", "can", "be", "used", "later", "." ]
6d83be536df4ef247ab94d57615b22c0b4e78aaf
https://github.com/sam3d/vue-svg/blob/6d83be536df4ef247ab94d57615b22c0b4e78aaf/index.js#L100-L110
23,364
mz121star/NJBlog
public/lib/jquery.sly.js
slideTo
function slideTo(newPos, immediate) { // Align items if (itemNav && dragging.released) { var tempRel = getRelatives(newPos), isDetached = newPos > pos.start && newPos < pos.end; if (centeredNav) { if (isDetached) { newPos = items[tempRel.centerItem].center; } if (forceCenteredNav) { self.activate(tempRel.centerItem, 1); } } else if (isDetached) { newPos = items[tempRel.firstItem].start; } } // Handle overflowing position limits if (!dragging.released && dragging.source === 'slidee' && o.elasticBounds) { if (newPos > pos.end) { newPos = pos.end + (newPos - pos.end) / 6; } else if (newPos < pos.start) { newPos = pos.start + (newPos - pos.start) / 6; } } else { newPos = within(newPos, pos.start, pos.end); } // Update the animation object animation.start = +new Date(); animation.time = 0; animation.from = pos.cur; animation.to = newPos; animation.delta = newPos - pos.cur; animation.immediate = immediate; // Attach animation destination pos.dest = newPos; // Reset next cycle timeout resetCycle(); // Synchronize states updateRelatives(); updateNavButtonsState(); syncPagesbar(); // Render the animation if (newPos !== pos.cur) { trigger('change'); if (!renderID) { render(); } } }
javascript
function slideTo(newPos, immediate) { // Align items if (itemNav && dragging.released) { var tempRel = getRelatives(newPos), isDetached = newPos > pos.start && newPos < pos.end; if (centeredNav) { if (isDetached) { newPos = items[tempRel.centerItem].center; } if (forceCenteredNav) { self.activate(tempRel.centerItem, 1); } } else if (isDetached) { newPos = items[tempRel.firstItem].start; } } // Handle overflowing position limits if (!dragging.released && dragging.source === 'slidee' && o.elasticBounds) { if (newPos > pos.end) { newPos = pos.end + (newPos - pos.end) / 6; } else if (newPos < pos.start) { newPos = pos.start + (newPos - pos.start) / 6; } } else { newPos = within(newPos, pos.start, pos.end); } // Update the animation object animation.start = +new Date(); animation.time = 0; animation.from = pos.cur; animation.to = newPos; animation.delta = newPos - pos.cur; animation.immediate = immediate; // Attach animation destination pos.dest = newPos; // Reset next cycle timeout resetCycle(); // Synchronize states updateRelatives(); updateNavButtonsState(); syncPagesbar(); // Render the animation if (newPos !== pos.cur) { trigger('change'); if (!renderID) { render(); } } }
[ "function", "slideTo", "(", "newPos", ",", "immediate", ")", "{", "// Align items\r", "if", "(", "itemNav", "&&", "dragging", ".", "released", ")", "{", "var", "tempRel", "=", "getRelatives", "(", "newPos", ")", ",", "isDetached", "=", "newPos", ">", "pos", ".", "start", "&&", "newPos", "<", "pos", ".", "end", ";", "if", "(", "centeredNav", ")", "{", "if", "(", "isDetached", ")", "{", "newPos", "=", "items", "[", "tempRel", ".", "centerItem", "]", ".", "center", ";", "}", "if", "(", "forceCenteredNav", ")", "{", "self", ".", "activate", "(", "tempRel", ".", "centerItem", ",", "1", ")", ";", "}", "}", "else", "if", "(", "isDetached", ")", "{", "newPos", "=", "items", "[", "tempRel", ".", "firstItem", "]", ".", "start", ";", "}", "}", "// Handle overflowing position limits\r", "if", "(", "!", "dragging", ".", "released", "&&", "dragging", ".", "source", "===", "'slidee'", "&&", "o", ".", "elasticBounds", ")", "{", "if", "(", "newPos", ">", "pos", ".", "end", ")", "{", "newPos", "=", "pos", ".", "end", "+", "(", "newPos", "-", "pos", ".", "end", ")", "/", "6", ";", "}", "else", "if", "(", "newPos", "<", "pos", ".", "start", ")", "{", "newPos", "=", "pos", ".", "start", "+", "(", "newPos", "-", "pos", ".", "start", ")", "/", "6", ";", "}", "}", "else", "{", "newPos", "=", "within", "(", "newPos", ",", "pos", ".", "start", ",", "pos", ".", "end", ")", ";", "}", "// Update the animation object\r", "animation", ".", "start", "=", "+", "new", "Date", "(", ")", ";", "animation", ".", "time", "=", "0", ";", "animation", ".", "from", "=", "pos", ".", "cur", ";", "animation", ".", "to", "=", "newPos", ";", "animation", ".", "delta", "=", "newPos", "-", "pos", ".", "cur", ";", "animation", ".", "immediate", "=", "immediate", ";", "// Attach animation destination\r", "pos", ".", "dest", "=", "newPos", ";", "// Reset next cycle timeout\r", "resetCycle", "(", ")", ";", "// Synchronize states\r", "updateRelatives", "(", ")", ";", "updateNavButtonsState", "(", ")", ";", "syncPagesbar", "(", ")", ";", "// Render the animation\r", "if", "(", "newPos", "!==", "pos", ".", "cur", ")", "{", "trigger", "(", "'change'", ")", ";", "if", "(", "!", "renderID", ")", "{", "render", "(", ")", ";", "}", "}", "}" ]
Animate to a position. @param {Int} newPos New position. @param {Bool} immediate Reposition immediately without an animation. @return {Void}
[ "Animate", "to", "a", "position", "." ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/public/lib/jquery.sly.js#L291-L346
23,365
mz121star/NJBlog
public/lib/jquery.sly.js
render
function render() { // If first render call, wait for next animationFrame if (!renderID) { renderID = rAF(render); if (dragging.released) { trigger('moveStart'); } return; } // If immediate repositioning is requested, SLIDEE is being dragged, or animation duration would take // less than 2 frames, don't animate if (animation.immediate || (!dragging.released ? dragging.source === 'slidee' : o.speed < 33)) { pos.cur = animation.to; } // Use tweesing for animations without known end point else if (!dragging.released && dragging.source === 'handle') { pos.cur += (animation.to - pos.cur) * o.syncFactor; } // Use tweening for basic animations with known end point else { animation.time = Math.min(+new Date() - animation.start, o.speed); pos.cur = animation.from + animation.delta * jQuery.easing[o.easing](animation.time/o.speed, animation.time, 0, 1, o.speed); } // If there is nothing more to render (animation reached the end, or dragging has been released), // break the rendering loop, otherwise request another animation frame if (animation.to === Math.round(pos.cur) && (!dragging.released || animation.time >= o.speed)) { pos.cur = pos.dest; renderID = 0; } else { renderID = rAF(render); } trigger('move'); // Update SLIDEE position if (!parallax) { if (transform) { $slidee[0].style[transform] = gpuAcceleration + (o.horizontal ? 'translateX' : 'translateY') + '(' + (-pos.cur) + 'px)'; } else { $slidee[0].style[o.horizontal ? 'left' : 'top'] = -Math.round(pos.cur) + 'px'; } } // When animation reached the end, and dragging is not active, trigger moveEnd if (!renderID && dragging.released) { trigger('moveEnd'); } syncScrollbar(); }
javascript
function render() { // If first render call, wait for next animationFrame if (!renderID) { renderID = rAF(render); if (dragging.released) { trigger('moveStart'); } return; } // If immediate repositioning is requested, SLIDEE is being dragged, or animation duration would take // less than 2 frames, don't animate if (animation.immediate || (!dragging.released ? dragging.source === 'slidee' : o.speed < 33)) { pos.cur = animation.to; } // Use tweesing for animations without known end point else if (!dragging.released && dragging.source === 'handle') { pos.cur += (animation.to - pos.cur) * o.syncFactor; } // Use tweening for basic animations with known end point else { animation.time = Math.min(+new Date() - animation.start, o.speed); pos.cur = animation.from + animation.delta * jQuery.easing[o.easing](animation.time/o.speed, animation.time, 0, 1, o.speed); } // If there is nothing more to render (animation reached the end, or dragging has been released), // break the rendering loop, otherwise request another animation frame if (animation.to === Math.round(pos.cur) && (!dragging.released || animation.time >= o.speed)) { pos.cur = pos.dest; renderID = 0; } else { renderID = rAF(render); } trigger('move'); // Update SLIDEE position if (!parallax) { if (transform) { $slidee[0].style[transform] = gpuAcceleration + (o.horizontal ? 'translateX' : 'translateY') + '(' + (-pos.cur) + 'px)'; } else { $slidee[0].style[o.horizontal ? 'left' : 'top'] = -Math.round(pos.cur) + 'px'; } } // When animation reached the end, and dragging is not active, trigger moveEnd if (!renderID && dragging.released) { trigger('moveEnd'); } syncScrollbar(); }
[ "function", "render", "(", ")", "{", "// If first render call, wait for next animationFrame\r", "if", "(", "!", "renderID", ")", "{", "renderID", "=", "rAF", "(", "render", ")", ";", "if", "(", "dragging", ".", "released", ")", "{", "trigger", "(", "'moveStart'", ")", ";", "}", "return", ";", "}", "// If immediate repositioning is requested, SLIDEE is being dragged, or animation duration would take\r", "// less than 2 frames, don't animate\r", "if", "(", "animation", ".", "immediate", "||", "(", "!", "dragging", ".", "released", "?", "dragging", ".", "source", "===", "'slidee'", ":", "o", ".", "speed", "<", "33", ")", ")", "{", "pos", ".", "cur", "=", "animation", ".", "to", ";", "}", "// Use tweesing for animations without known end point\r", "else", "if", "(", "!", "dragging", ".", "released", "&&", "dragging", ".", "source", "===", "'handle'", ")", "{", "pos", ".", "cur", "+=", "(", "animation", ".", "to", "-", "pos", ".", "cur", ")", "*", "o", ".", "syncFactor", ";", "}", "// Use tweening for basic animations with known end point\r", "else", "{", "animation", ".", "time", "=", "Math", ".", "min", "(", "+", "new", "Date", "(", ")", "-", "animation", ".", "start", ",", "o", ".", "speed", ")", ";", "pos", ".", "cur", "=", "animation", ".", "from", "+", "animation", ".", "delta", "*", "jQuery", ".", "easing", "[", "o", ".", "easing", "]", "(", "animation", ".", "time", "/", "o", ".", "speed", ",", "animation", ".", "time", ",", "0", ",", "1", ",", "o", ".", "speed", ")", ";", "}", "// If there is nothing more to render (animation reached the end, or dragging has been released),\r", "// break the rendering loop, otherwise request another animation frame\r", "if", "(", "animation", ".", "to", "===", "Math", ".", "round", "(", "pos", ".", "cur", ")", "&&", "(", "!", "dragging", ".", "released", "||", "animation", ".", "time", ">=", "o", ".", "speed", ")", ")", "{", "pos", ".", "cur", "=", "pos", ".", "dest", ";", "renderID", "=", "0", ";", "}", "else", "{", "renderID", "=", "rAF", "(", "render", ")", ";", "}", "trigger", "(", "'move'", ")", ";", "// Update SLIDEE position\r", "if", "(", "!", "parallax", ")", "{", "if", "(", "transform", ")", "{", "$slidee", "[", "0", "]", ".", "style", "[", "transform", "]", "=", "gpuAcceleration", "+", "(", "o", ".", "horizontal", "?", "'translateX'", ":", "'translateY'", ")", "+", "'('", "+", "(", "-", "pos", ".", "cur", ")", "+", "'px)'", ";", "}", "else", "{", "$slidee", "[", "0", "]", ".", "style", "[", "o", ".", "horizontal", "?", "'left'", ":", "'top'", "]", "=", "-", "Math", ".", "round", "(", "pos", ".", "cur", ")", "+", "'px'", ";", "}", "}", "// When animation reached the end, and dragging is not active, trigger moveEnd\r", "if", "(", "!", "renderID", "&&", "dragging", ".", "released", ")", "{", "trigger", "(", "'moveEnd'", ")", ";", "}", "syncScrollbar", "(", ")", ";", "}" ]
Render animation frame. @return {Void}
[ "Render", "animation", "frame", "." ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/public/lib/jquery.sly.js#L353-L404
23,366
mz121star/NJBlog
public/lib/jquery.sly.js
syncScrollbar
function syncScrollbar() { if ($handle) { hPos.cur = pos.start === pos.end ? 0 : (((!dragging.released && dragging.source === 'handle') ? pos.dest : pos.cur) - pos.start) / (pos.end - pos.start) * hPos.end; hPos.cur = within(Math.round(hPos.cur), hPos.start, hPos.end); if (last.hPos !== hPos.cur) { last.hPos = hPos.cur; if (transform) { $handle[0].style[transform] = gpuAcceleration + (o.horizontal ? 'translateX' : 'translateY') + '(' + hPos.cur + 'px)'; } else { $handle[0].style[o.horizontal ? 'left' : 'top'] = hPos.cur + 'px'; } } } }
javascript
function syncScrollbar() { if ($handle) { hPos.cur = pos.start === pos.end ? 0 : (((!dragging.released && dragging.source === 'handle') ? pos.dest : pos.cur) - pos.start) / (pos.end - pos.start) * hPos.end; hPos.cur = within(Math.round(hPos.cur), hPos.start, hPos.end); if (last.hPos !== hPos.cur) { last.hPos = hPos.cur; if (transform) { $handle[0].style[transform] = gpuAcceleration + (o.horizontal ? 'translateX' : 'translateY') + '(' + hPos.cur + 'px)'; } else { $handle[0].style[o.horizontal ? 'left' : 'top'] = hPos.cur + 'px'; } } } }
[ "function", "syncScrollbar", "(", ")", "{", "if", "(", "$handle", ")", "{", "hPos", ".", "cur", "=", "pos", ".", "start", "===", "pos", ".", "end", "?", "0", ":", "(", "(", "(", "!", "dragging", ".", "released", "&&", "dragging", ".", "source", "===", "'handle'", ")", "?", "pos", ".", "dest", ":", "pos", ".", "cur", ")", "-", "pos", ".", "start", ")", "/", "(", "pos", ".", "end", "-", "pos", ".", "start", ")", "*", "hPos", ".", "end", ";", "hPos", ".", "cur", "=", "within", "(", "Math", ".", "round", "(", "hPos", ".", "cur", ")", ",", "hPos", ".", "start", ",", "hPos", ".", "end", ")", ";", "if", "(", "last", ".", "hPos", "!==", "hPos", ".", "cur", ")", "{", "last", ".", "hPos", "=", "hPos", ".", "cur", ";", "if", "(", "transform", ")", "{", "$handle", "[", "0", "]", ".", "style", "[", "transform", "]", "=", "gpuAcceleration", "+", "(", "o", ".", "horizontal", "?", "'translateX'", ":", "'translateY'", ")", "+", "'('", "+", "hPos", ".", "cur", "+", "'px)'", ";", "}", "else", "{", "$handle", "[", "0", "]", ".", "style", "[", "o", ".", "horizontal", "?", "'left'", ":", "'top'", "]", "=", "hPos", ".", "cur", "+", "'px'", ";", "}", "}", "}", "}" ]
Synchronizes scrollbar with the SLIDEE. @return {Void}
[ "Synchronizes", "scrollbar", "with", "the", "SLIDEE", "." ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/public/lib/jquery.sly.js#L411-L424
23,367
mz121star/NJBlog
public/lib/jquery.sly.js
syncPagesbar
function syncPagesbar() { if ($pages[0] && last.page !== rel.activePage) { last.page = rel.activePage; $pages.removeClass(o.activeClass).eq(rel.activePage).addClass(o.activeClass); } }
javascript
function syncPagesbar() { if ($pages[0] && last.page !== rel.activePage) { last.page = rel.activePage; $pages.removeClass(o.activeClass).eq(rel.activePage).addClass(o.activeClass); } }
[ "function", "syncPagesbar", "(", ")", "{", "if", "(", "$pages", "[", "0", "]", "&&", "last", ".", "page", "!==", "rel", ".", "activePage", ")", "{", "last", ".", "page", "=", "rel", ".", "activePage", ";", "$pages", ".", "removeClass", "(", "o", ".", "activeClass", ")", ".", "eq", "(", "rel", ".", "activePage", ")", ".", "addClass", "(", "o", ".", "activeClass", ")", ";", "}", "}" ]
Synchronizes pagesbar with SLIDEE. @return {Void}
[ "Synchronizes", "pagesbar", "with", "SLIDEE", "." ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/public/lib/jquery.sly.js#L431-L436
23,368
mz121star/NJBlog
public/lib/jquery.sly.js
to
function to(location, item, immediate) { // Optional arguments logic if (typeof item === 'boolean') { immediate = item; item = undefined; } if (item === undefined) { slideTo(pos[location]); } else { // You can't align items to sides of the frame // when centered navigation type is enabled if (centeredNav && location !== 'center') { return; } var itemPos = self.getPos(item); if (itemPos) { slideTo(itemPos[location], immediate); } } }
javascript
function to(location, item, immediate) { // Optional arguments logic if (typeof item === 'boolean') { immediate = item; item = undefined; } if (item === undefined) { slideTo(pos[location]); } else { // You can't align items to sides of the frame // when centered navigation type is enabled if (centeredNav && location !== 'center') { return; } var itemPos = self.getPos(item); if (itemPos) { slideTo(itemPos[location], immediate); } } }
[ "function", "to", "(", "location", ",", "item", ",", "immediate", ")", "{", "// Optional arguments logic\r", "if", "(", "typeof", "item", "===", "'boolean'", ")", "{", "immediate", "=", "item", ";", "item", "=", "undefined", ";", "}", "if", "(", "item", "===", "undefined", ")", "{", "slideTo", "(", "pos", "[", "location", "]", ")", ";", "}", "else", "{", "// You can't align items to sides of the frame\r", "// when centered navigation type is enabled\r", "if", "(", "centeredNav", "&&", "location", "!==", "'center'", ")", "{", "return", ";", "}", "var", "itemPos", "=", "self", ".", "getPos", "(", "item", ")", ";", "if", "(", "itemPos", ")", "{", "slideTo", "(", "itemPos", "[", "location", "]", ",", "immediate", ")", ";", "}", "}", "}" ]
Core method for handling `toLocation` methods. @param {String} location @param {Mixed} item @param {Bool} immediate @return {Void}
[ "Core", "method", "for", "handling", "toLocation", "methods", "." ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/public/lib/jquery.sly.js#L550-L571
23,369
mz121star/NJBlog
public/lib/jquery.sly.js
getIndex
function getIndex(item) { return isNumber(item) ? within(item, 0, items.length - 1) : item === undefined ? -1 : $items.index(item); }
javascript
function getIndex(item) { return isNumber(item) ? within(item, 0, items.length - 1) : item === undefined ? -1 : $items.index(item); }
[ "function", "getIndex", "(", "item", ")", "{", "return", "isNumber", "(", "item", ")", "?", "within", "(", "item", ",", "0", ",", "items", ".", "length", "-", "1", ")", ":", "item", "===", "undefined", "?", "-", "1", ":", "$items", ".", "index", "(", "item", ")", ";", "}" ]
Get the index of an item in SLIDEE. @param {Mixed} item Item DOM element, or index starting at 0. @return {Int}
[ "Get", "the", "index", "of", "an", "item", "in", "SLIDEE", "." ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/public/lib/jquery.sly.js#L616-L618
23,370
mz121star/NJBlog
public/lib/jquery.sly.js
getRelatives
function getRelatives(slideePos) { slideePos = within(isNumber(slideePos) ? slideePos : pos.dest, pos.start, pos.end); var relatives = {}, centerOffset = forceCenteredNav ? 0 : frameSize / 2; // Determine active page if (!parallax) { for (var p = 0, pl = pages.length; p < pl; p++) { if (slideePos >= pos.end || p === pages.length - 1) { relatives.activePage = pages.length - 1; break; } if (slideePos <= pages[p] + centerOffset) { relatives.activePage = p; break; } } } // Relative item indexes if (itemNav) { var first = false, last = false, center = false; // From start for (var i = 0, il = items.length; i < il; i++) { // First item if (first === false && slideePos <= items[i].start) { first = i; } // Centered item if (center === false && slideePos - items[i].size / 2 <= items[i].center) { center = i; } // Last item if (i === items.length - 1 || (last === false && slideePos < items[i + 1].end)) { last = i; } // Terminate if all are assigned if (last !== false) { break; } } // Safe assignment, just to be sure the false won't be returned relatives.firstItem = isNumber(first) ? first : 0; relatives.centerItem = isNumber(center) ? center : relatives.firstItem; relatives.lastItem = isNumber(last) ? last : relatives.centerItem; } return relatives; }
javascript
function getRelatives(slideePos) { slideePos = within(isNumber(slideePos) ? slideePos : pos.dest, pos.start, pos.end); var relatives = {}, centerOffset = forceCenteredNav ? 0 : frameSize / 2; // Determine active page if (!parallax) { for (var p = 0, pl = pages.length; p < pl; p++) { if (slideePos >= pos.end || p === pages.length - 1) { relatives.activePage = pages.length - 1; break; } if (slideePos <= pages[p] + centerOffset) { relatives.activePage = p; break; } } } // Relative item indexes if (itemNav) { var first = false, last = false, center = false; // From start for (var i = 0, il = items.length; i < il; i++) { // First item if (first === false && slideePos <= items[i].start) { first = i; } // Centered item if (center === false && slideePos - items[i].size / 2 <= items[i].center) { center = i; } // Last item if (i === items.length - 1 || (last === false && slideePos < items[i + 1].end)) { last = i; } // Terminate if all are assigned if (last !== false) { break; } } // Safe assignment, just to be sure the false won't be returned relatives.firstItem = isNumber(first) ? first : 0; relatives.centerItem = isNumber(center) ? center : relatives.firstItem; relatives.lastItem = isNumber(last) ? last : relatives.centerItem; } return relatives; }
[ "function", "getRelatives", "(", "slideePos", ")", "{", "slideePos", "=", "within", "(", "isNumber", "(", "slideePos", ")", "?", "slideePos", ":", "pos", ".", "dest", ",", "pos", ".", "start", ",", "pos", ".", "end", ")", ";", "var", "relatives", "=", "{", "}", ",", "centerOffset", "=", "forceCenteredNav", "?", "0", ":", "frameSize", "/", "2", ";", "// Determine active page\r", "if", "(", "!", "parallax", ")", "{", "for", "(", "var", "p", "=", "0", ",", "pl", "=", "pages", ".", "length", ";", "p", "<", "pl", ";", "p", "++", ")", "{", "if", "(", "slideePos", ">=", "pos", ".", "end", "||", "p", "===", "pages", ".", "length", "-", "1", ")", "{", "relatives", ".", "activePage", "=", "pages", ".", "length", "-", "1", ";", "break", ";", "}", "if", "(", "slideePos", "<=", "pages", "[", "p", "]", "+", "centerOffset", ")", "{", "relatives", ".", "activePage", "=", "p", ";", "break", ";", "}", "}", "}", "// Relative item indexes\r", "if", "(", "itemNav", ")", "{", "var", "first", "=", "false", ",", "last", "=", "false", ",", "center", "=", "false", ";", "// From start\r", "for", "(", "var", "i", "=", "0", ",", "il", "=", "items", ".", "length", ";", "i", "<", "il", ";", "i", "++", ")", "{", "// First item\r", "if", "(", "first", "===", "false", "&&", "slideePos", "<=", "items", "[", "i", "]", ".", "start", ")", "{", "first", "=", "i", ";", "}", "// Centered item\r", "if", "(", "center", "===", "false", "&&", "slideePos", "-", "items", "[", "i", "]", ".", "size", "/", "2", "<=", "items", "[", "i", "]", ".", "center", ")", "{", "center", "=", "i", ";", "}", "// Last item\r", "if", "(", "i", "===", "items", ".", "length", "-", "1", "||", "(", "last", "===", "false", "&&", "slideePos", "<", "items", "[", "i", "+", "1", "]", ".", "end", ")", ")", "{", "last", "=", "i", ";", "}", "// Terminate if all are assigned\r", "if", "(", "last", "!==", "false", ")", "{", "break", ";", "}", "}", "// Safe assignment, just to be sure the false won't be returned\r", "relatives", ".", "firstItem", "=", "isNumber", "(", "first", ")", "?", "first", ":", "0", ";", "relatives", ".", "centerItem", "=", "isNumber", "(", "center", ")", "?", "center", ":", "relatives", ".", "firstItem", ";", "relatives", ".", "lastItem", "=", "isNumber", "(", "last", ")", "?", "last", ":", "relatives", ".", "centerItem", ";", "}", "return", "relatives", ";", "}" ]
Return relative positions of items based on their visibility within FRAME. @param {Int} slideePos Position of SLIDEE. @return {Void}
[ "Return", "relative", "positions", "of", "items", "based", "on", "their", "visibility", "within", "FRAME", "." ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/public/lib/jquery.sly.js#L696-L753
23,371
mz121star/NJBlog
public/lib/jquery.sly.js
updateNavButtonsState
function updateNavButtonsState() { // Item navigation if (itemNav) { var isFirst = rel.activeItem === 0, isLast = rel.activeItem >= items.length - 1, itemsButtonState = isFirst ? 'first' : isLast ? 'last' : 'middle'; if (last.itemsButtonState !== itemsButtonState) { last.itemsButtonState = itemsButtonState; if ($prevButton.is('button,input')) { $prevButton.prop('disabled', isFirst); } if ($nextButton.is('button,input')) { $nextButton.prop('disabled', isLast); } $prevButton[isFirst ? 'removeClass' : 'addClass'](o.disabledClass); $nextButton[isLast ? 'removeClass' : 'addClass'](o.disabledClass); } } // Page navigation if ($pages[0]) { var isStart = pos.dest <= pos.start, isEnd = pos.dest >= pos.end, pagesButtonState = isStart ? 'first' : isEnd ? 'last' : 'middle'; // Update paging buttons only if there has been a change in their state if (last.pagesButtonState !== pagesButtonState) { last.pagesButtonState = pagesButtonState; if ($prevPageButton.is('button,input')) { $prevPageButton.prop('disabled', isStart); } if ($nextPageButton.is('button,input')) { $nextPageButton.prop('disabled', isEnd); } $prevPageButton[isStart ? 'removeClass' : 'addClass'](o.disabledClass); $nextPageButton[isEnd ? 'removeClass' : 'addClass'](o.disabledClass); } } }
javascript
function updateNavButtonsState() { // Item navigation if (itemNav) { var isFirst = rel.activeItem === 0, isLast = rel.activeItem >= items.length - 1, itemsButtonState = isFirst ? 'first' : isLast ? 'last' : 'middle'; if (last.itemsButtonState !== itemsButtonState) { last.itemsButtonState = itemsButtonState; if ($prevButton.is('button,input')) { $prevButton.prop('disabled', isFirst); } if ($nextButton.is('button,input')) { $nextButton.prop('disabled', isLast); } $prevButton[isFirst ? 'removeClass' : 'addClass'](o.disabledClass); $nextButton[isLast ? 'removeClass' : 'addClass'](o.disabledClass); } } // Page navigation if ($pages[0]) { var isStart = pos.dest <= pos.start, isEnd = pos.dest >= pos.end, pagesButtonState = isStart ? 'first' : isEnd ? 'last' : 'middle'; // Update paging buttons only if there has been a change in their state if (last.pagesButtonState !== pagesButtonState) { last.pagesButtonState = pagesButtonState; if ($prevPageButton.is('button,input')) { $prevPageButton.prop('disabled', isStart); } if ($nextPageButton.is('button,input')) { $nextPageButton.prop('disabled', isEnd); } $prevPageButton[isStart ? 'removeClass' : 'addClass'](o.disabledClass); $nextPageButton[isEnd ? 'removeClass' : 'addClass'](o.disabledClass); } } }
[ "function", "updateNavButtonsState", "(", ")", "{", "// Item navigation\r", "if", "(", "itemNav", ")", "{", "var", "isFirst", "=", "rel", ".", "activeItem", "===", "0", ",", "isLast", "=", "rel", ".", "activeItem", ">=", "items", ".", "length", "-", "1", ",", "itemsButtonState", "=", "isFirst", "?", "'first'", ":", "isLast", "?", "'last'", ":", "'middle'", ";", "if", "(", "last", ".", "itemsButtonState", "!==", "itemsButtonState", ")", "{", "last", ".", "itemsButtonState", "=", "itemsButtonState", ";", "if", "(", "$prevButton", ".", "is", "(", "'button,input'", ")", ")", "{", "$prevButton", ".", "prop", "(", "'disabled'", ",", "isFirst", ")", ";", "}", "if", "(", "$nextButton", ".", "is", "(", "'button,input'", ")", ")", "{", "$nextButton", ".", "prop", "(", "'disabled'", ",", "isLast", ")", ";", "}", "$prevButton", "[", "isFirst", "?", "'removeClass'", ":", "'addClass'", "]", "(", "o", ".", "disabledClass", ")", ";", "$nextButton", "[", "isLast", "?", "'removeClass'", ":", "'addClass'", "]", "(", "o", ".", "disabledClass", ")", ";", "}", "}", "// Page navigation\r", "if", "(", "$pages", "[", "0", "]", ")", "{", "var", "isStart", "=", "pos", ".", "dest", "<=", "pos", ".", "start", ",", "isEnd", "=", "pos", ".", "dest", ">=", "pos", ".", "end", ",", "pagesButtonState", "=", "isStart", "?", "'first'", ":", "isEnd", "?", "'last'", ":", "'middle'", ";", "// Update paging buttons only if there has been a change in their state\r", "if", "(", "last", ".", "pagesButtonState", "!==", "pagesButtonState", ")", "{", "last", ".", "pagesButtonState", "=", "pagesButtonState", ";", "if", "(", "$prevPageButton", ".", "is", "(", "'button,input'", ")", ")", "{", "$prevPageButton", ".", "prop", "(", "'disabled'", ",", "isStart", ")", ";", "}", "if", "(", "$nextPageButton", ".", "is", "(", "'button,input'", ")", ")", "{", "$nextPageButton", ".", "prop", "(", "'disabled'", ",", "isEnd", ")", ";", "}", "$prevPageButton", "[", "isStart", "?", "'removeClass'", ":", "'addClass'", "]", "(", "o", ".", "disabledClass", ")", ";", "$nextPageButton", "[", "isEnd", "?", "'removeClass'", ":", "'addClass'", "]", "(", "o", ".", "disabledClass", ")", ";", "}", "}", "}" ]
Disable navigation buttons when needed. Adds disabledClass, and when the button is <button> or <input>, activates :disabled state. @return {Void}
[ "Disable", "navigation", "buttons", "when", "needed", "." ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/public/lib/jquery.sly.js#L773-L818
23,372
mz121star/NJBlog
public/lib/jquery.sly.js
handleToSlidee
function handleToSlidee(handlePos) { return Math.round(within(handlePos, hPos.start, hPos.end) / hPos.end * (pos.end - pos.start)) + pos.start; }
javascript
function handleToSlidee(handlePos) { return Math.round(within(handlePos, hPos.start, hPos.end) / hPos.end * (pos.end - pos.start)) + pos.start; }
[ "function", "handleToSlidee", "(", "handlePos", ")", "{", "return", "Math", ".", "round", "(", "within", "(", "handlePos", ",", "hPos", ".", "start", ",", "hPos", ".", "end", ")", "/", "hPos", ".", "end", "*", "(", "pos", ".", "end", "-", "pos", ".", "start", ")", ")", "+", "pos", ".", "start", ";", "}" ]
Calculate SLIDEE representation of handle position. @param {Int} handlePos @return {Int}
[ "Calculate", "SLIDEE", "representation", "of", "handle", "position", "." ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/public/lib/jquery.sly.js#L900-L902
23,373
mz121star/NJBlog
public/lib/jquery.sly.js
dragInit
function dragInit(event) { var isTouch = event.type === 'touchstart', source = event.data.source, isSlidee = source === 'slidee'; // Ignore other than left mouse button if (isTouch || event.which <= 1) { stopDefault(event); // Update a dragging object dragging.source = source; dragging.$source = $(event.target); dragging.init = 0; dragging.released = 0; dragging.touch = isTouch; dragging.initLoc = (isTouch ? event.originalEvent.touches[0] : event)[o.horizontal ? 'pageX' : 'pageY']; dragging.initPos = isSlidee ? pos.cur : hPos.cur; dragging.start = +new Date(); dragging.time = 0; dragging.path = 0; dragging.pathMin = isSlidee ? -dragging.initLoc : -hPos.cur; dragging.pathMax = isSlidee ? document[o.horizontal ? 'width' : 'height'] - dragging.initLoc : hPos.end - hPos.cur; // Add dragging class (isSlidee ? $slidee : $handle).addClass(o.draggedClass); // Bind dragging events $doc.on(isTouch ? dragTouchEvents : dragMouseEvents, dragHandler); } }
javascript
function dragInit(event) { var isTouch = event.type === 'touchstart', source = event.data.source, isSlidee = source === 'slidee'; // Ignore other than left mouse button if (isTouch || event.which <= 1) { stopDefault(event); // Update a dragging object dragging.source = source; dragging.$source = $(event.target); dragging.init = 0; dragging.released = 0; dragging.touch = isTouch; dragging.initLoc = (isTouch ? event.originalEvent.touches[0] : event)[o.horizontal ? 'pageX' : 'pageY']; dragging.initPos = isSlidee ? pos.cur : hPos.cur; dragging.start = +new Date(); dragging.time = 0; dragging.path = 0; dragging.pathMin = isSlidee ? -dragging.initLoc : -hPos.cur; dragging.pathMax = isSlidee ? document[o.horizontal ? 'width' : 'height'] - dragging.initLoc : hPos.end - hPos.cur; // Add dragging class (isSlidee ? $slidee : $handle).addClass(o.draggedClass); // Bind dragging events $doc.on(isTouch ? dragTouchEvents : dragMouseEvents, dragHandler); } }
[ "function", "dragInit", "(", "event", ")", "{", "var", "isTouch", "=", "event", ".", "type", "===", "'touchstart'", ",", "source", "=", "event", ".", "data", ".", "source", ",", "isSlidee", "=", "source", "===", "'slidee'", ";", "// Ignore other than left mouse button\r", "if", "(", "isTouch", "||", "event", ".", "which", "<=", "1", ")", "{", "stopDefault", "(", "event", ")", ";", "// Update a dragging object\r", "dragging", ".", "source", "=", "source", ";", "dragging", ".", "$source", "=", "$", "(", "event", ".", "target", ")", ";", "dragging", ".", "init", "=", "0", ";", "dragging", ".", "released", "=", "0", ";", "dragging", ".", "touch", "=", "isTouch", ";", "dragging", ".", "initLoc", "=", "(", "isTouch", "?", "event", ".", "originalEvent", ".", "touches", "[", "0", "]", ":", "event", ")", "[", "o", ".", "horizontal", "?", "'pageX'", ":", "'pageY'", "]", ";", "dragging", ".", "initPos", "=", "isSlidee", "?", "pos", ".", "cur", ":", "hPos", ".", "cur", ";", "dragging", ".", "start", "=", "+", "new", "Date", "(", ")", ";", "dragging", ".", "time", "=", "0", ";", "dragging", ".", "path", "=", "0", ";", "dragging", ".", "pathMin", "=", "isSlidee", "?", "-", "dragging", ".", "initLoc", ":", "-", "hPos", ".", "cur", ";", "dragging", ".", "pathMax", "=", "isSlidee", "?", "document", "[", "o", ".", "horizontal", "?", "'width'", ":", "'height'", "]", "-", "dragging", ".", "initLoc", ":", "hPos", ".", "end", "-", "hPos", ".", "cur", ";", "// Add dragging class\r", "(", "isSlidee", "?", "$slidee", ":", "$handle", ")", ".", "addClass", "(", "o", ".", "draggedClass", ")", ";", "// Bind dragging events\r", "$doc", ".", "on", "(", "isTouch", "?", "dragTouchEvents", ":", "dragMouseEvents", ",", "dragHandler", ")", ";", "}", "}" ]
Dragging initiator. @param {Event} event @return {Void}
[ "Dragging", "initiator", "." ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/public/lib/jquery.sly.js#L911-L940
23,374
mz121star/NJBlog
public/lib/jquery.sly.js
dragHandler
function dragHandler(event) { dragging.released = event.type === 'mouseup' || event.type === 'touchend'; dragging.path = within( (dragging.touch ? event.originalEvent[dragging.released ? 'changedTouches' : 'touches'][0] : event)[o.horizontal ? 'pageX' : 'pageY'] - dragging.initLoc, dragging.pathMin, dragging.pathMax ); // Initialization if (!dragging.init && (Math.abs(dragging.path) > (dragging.touch ? 50 : 10) || dragging.source === 'handle')) { dragging.init = 1; if (dragging.source === 'slidee') { ignoreNextClick = 1; } // Pause ongoing cycle self.pause(1); // Disable click actions on source element, as they are unwelcome when dragging dragging.$source.on('click', function disableAction(event) { stopDefault(event, 1); if (dragging.source === 'slidee') { ignoreNextClick = 0; } dragging.$source.off('click', disableAction); }); // Trigger moveStart event trigger('moveStart'); } // Proceed when initialized if (dragging.init) { stopDefault(event); // Adjust path with a swing on mouse release if (dragging.released && dragging.source === 'slidee' && o.speed > 33) { dragging.path += dragging.path * 200 / (+new Date() - dragging.start); } slideTo(dragging.source === 'slidee' ? Math.round(dragging.initPos - dragging.path) : handleToSlidee(dragging.initPos + dragging.path)); } // Cleanup and trigger :moveEnd event on release if (dragging.released) { $doc.off(dragging.touch ? dragTouchEvents : dragMouseEvents, dragHandler); (dragging.source === 'slidee' ? $slidee : $handle).removeClass(o.draggedClass); // Account for item snapping position adjustment. if (pos.cur === pos.dest) { trigger('moveEnd'); } } }
javascript
function dragHandler(event) { dragging.released = event.type === 'mouseup' || event.type === 'touchend'; dragging.path = within( (dragging.touch ? event.originalEvent[dragging.released ? 'changedTouches' : 'touches'][0] : event)[o.horizontal ? 'pageX' : 'pageY'] - dragging.initLoc, dragging.pathMin, dragging.pathMax ); // Initialization if (!dragging.init && (Math.abs(dragging.path) > (dragging.touch ? 50 : 10) || dragging.source === 'handle')) { dragging.init = 1; if (dragging.source === 'slidee') { ignoreNextClick = 1; } // Pause ongoing cycle self.pause(1); // Disable click actions on source element, as they are unwelcome when dragging dragging.$source.on('click', function disableAction(event) { stopDefault(event, 1); if (dragging.source === 'slidee') { ignoreNextClick = 0; } dragging.$source.off('click', disableAction); }); // Trigger moveStart event trigger('moveStart'); } // Proceed when initialized if (dragging.init) { stopDefault(event); // Adjust path with a swing on mouse release if (dragging.released && dragging.source === 'slidee' && o.speed > 33) { dragging.path += dragging.path * 200 / (+new Date() - dragging.start); } slideTo(dragging.source === 'slidee' ? Math.round(dragging.initPos - dragging.path) : handleToSlidee(dragging.initPos + dragging.path)); } // Cleanup and trigger :moveEnd event on release if (dragging.released) { $doc.off(dragging.touch ? dragTouchEvents : dragMouseEvents, dragHandler); (dragging.source === 'slidee' ? $slidee : $handle).removeClass(o.draggedClass); // Account for item snapping position adjustment. if (pos.cur === pos.dest) { trigger('moveEnd'); } } }
[ "function", "dragHandler", "(", "event", ")", "{", "dragging", ".", "released", "=", "event", ".", "type", "===", "'mouseup'", "||", "event", ".", "type", "===", "'touchend'", ";", "dragging", ".", "path", "=", "within", "(", "(", "dragging", ".", "touch", "?", "event", ".", "originalEvent", "[", "dragging", ".", "released", "?", "'changedTouches'", ":", "'touches'", "]", "[", "0", "]", ":", "event", ")", "[", "o", ".", "horizontal", "?", "'pageX'", ":", "'pageY'", "]", "-", "dragging", ".", "initLoc", ",", "dragging", ".", "pathMin", ",", "dragging", ".", "pathMax", ")", ";", "// Initialization\r", "if", "(", "!", "dragging", ".", "init", "&&", "(", "Math", ".", "abs", "(", "dragging", ".", "path", ")", ">", "(", "dragging", ".", "touch", "?", "50", ":", "10", ")", "||", "dragging", ".", "source", "===", "'handle'", ")", ")", "{", "dragging", ".", "init", "=", "1", ";", "if", "(", "dragging", ".", "source", "===", "'slidee'", ")", "{", "ignoreNextClick", "=", "1", ";", "}", "// Pause ongoing cycle\r", "self", ".", "pause", "(", "1", ")", ";", "// Disable click actions on source element, as they are unwelcome when dragging\r", "dragging", ".", "$source", ".", "on", "(", "'click'", ",", "function", "disableAction", "(", "event", ")", "{", "stopDefault", "(", "event", ",", "1", ")", ";", "if", "(", "dragging", ".", "source", "===", "'slidee'", ")", "{", "ignoreNextClick", "=", "0", ";", "}", "dragging", ".", "$source", ".", "off", "(", "'click'", ",", "disableAction", ")", ";", "}", ")", ";", "// Trigger moveStart event\r", "trigger", "(", "'moveStart'", ")", ";", "}", "// Proceed when initialized\r", "if", "(", "dragging", ".", "init", ")", "{", "stopDefault", "(", "event", ")", ";", "// Adjust path with a swing on mouse release\r", "if", "(", "dragging", ".", "released", "&&", "dragging", ".", "source", "===", "'slidee'", "&&", "o", ".", "speed", ">", "33", ")", "{", "dragging", ".", "path", "+=", "dragging", ".", "path", "*", "200", "/", "(", "+", "new", "Date", "(", ")", "-", "dragging", ".", "start", ")", ";", "}", "slideTo", "(", "dragging", ".", "source", "===", "'slidee'", "?", "Math", ".", "round", "(", "dragging", ".", "initPos", "-", "dragging", ".", "path", ")", ":", "handleToSlidee", "(", "dragging", ".", "initPos", "+", "dragging", ".", "path", ")", ")", ";", "}", "// Cleanup and trigger :moveEnd event on release\r", "if", "(", "dragging", ".", "released", ")", "{", "$doc", ".", "off", "(", "dragging", ".", "touch", "?", "dragTouchEvents", ":", "dragMouseEvents", ",", "dragHandler", ")", ";", "(", "dragging", ".", "source", "===", "'slidee'", "?", "$slidee", ":", "$handle", ")", ".", "removeClass", "(", "o", ".", "draggedClass", ")", ";", "// Account for item snapping position adjustment.\r", "if", "(", "pos", ".", "cur", "===", "pos", ".", "dest", ")", "{", "trigger", "(", "'moveEnd'", ")", ";", "}", "}", "}" ]
Handler for dragging scrollbar handle or SLIDEE. @param {Event} event @return {Void}
[ "Handler", "for", "dragging", "scrollbar", "handle", "or", "SLIDEE", "." ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/public/lib/jquery.sly.js#L949-L1001
23,375
mz121star/NJBlog
public/lib/jquery.sly.js
trigger
function trigger(name, arg1, arg2, arg3, arg4) { // Common arguments for events switch (name) { case 'active': arg2 = arg1; arg1 = $items; break; case 'activePage': arg2 = arg1; arg1 = pages; break; default: arg4 = arg1; arg1 = pos; arg2 = $items; arg3 = rel; } if (callbacks[name]) { for (var i = 0, l = callbacks[name].length; i < l; i++) { callbacks[name][i].call(frame, arg1, arg2, arg3, arg4); } } if (o.domEvents && !parallax) { $frame.trigger(pluginName + ':' + name, [arg1, arg2, arg3, arg4]); } }
javascript
function trigger(name, arg1, arg2, arg3, arg4) { // Common arguments for events switch (name) { case 'active': arg2 = arg1; arg1 = $items; break; case 'activePage': arg2 = arg1; arg1 = pages; break; default: arg4 = arg1; arg1 = pos; arg2 = $items; arg3 = rel; } if (callbacks[name]) { for (var i = 0, l = callbacks[name].length; i < l; i++) { callbacks[name][i].call(frame, arg1, arg2, arg3, arg4); } } if (o.domEvents && !parallax) { $frame.trigger(pluginName + ':' + name, [arg1, arg2, arg3, arg4]); } }
[ "function", "trigger", "(", "name", ",", "arg1", ",", "arg2", ",", "arg3", ",", "arg4", ")", "{", "// Common arguments for events\r", "switch", "(", "name", ")", "{", "case", "'active'", ":", "arg2", "=", "arg1", ";", "arg1", "=", "$items", ";", "break", ";", "case", "'activePage'", ":", "arg2", "=", "arg1", ";", "arg1", "=", "pages", ";", "break", ";", "default", ":", "arg4", "=", "arg1", ";", "arg1", "=", "pos", ";", "arg2", "=", "$items", ";", "arg3", "=", "rel", ";", "}", "if", "(", "callbacks", "[", "name", "]", ")", "{", "for", "(", "var", "i", "=", "0", ",", "l", "=", "callbacks", "[", "name", "]", ".", "length", ";", "i", "<", "l", ";", "i", "++", ")", "{", "callbacks", "[", "name", "]", "[", "i", "]", ".", "call", "(", "frame", ",", "arg1", ",", "arg2", ",", "arg3", ",", "arg4", ")", ";", "}", "}", "if", "(", "o", ".", "domEvents", "&&", "!", "parallax", ")", "{", "$frame", ".", "trigger", "(", "pluginName", "+", "':'", "+", "name", ",", "[", "arg1", ",", "arg2", ",", "arg3", ",", "arg4", "]", ")", ";", "}", "}" ]
Trigger callbacks for event. @param {String} name Event name. @param {Mixed} argX Arguments passed to callback. @return {Void}
[ "Trigger", "callbacks", "for", "event", "." ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/public/lib/jquery.sly.js#L1087-L1116
23,376
mz121star/NJBlog
public/lib/jquery.sly.js
stopDefault
function stopDefault(event, noBubbles) { event = event || w.event; if (event.preventDefault) { event.preventDefault(); } else { event.returnValue = false; } if (noBubbles) { if (event.stopPropagation) { event.stopPropagation(); } else { event.cancelBubble = true; } } }
javascript
function stopDefault(event, noBubbles) { event = event || w.event; if (event.preventDefault) { event.preventDefault(); } else { event.returnValue = false; } if (noBubbles) { if (event.stopPropagation) { event.stopPropagation(); } else { event.cancelBubble = true; } } }
[ "function", "stopDefault", "(", "event", ",", "noBubbles", ")", "{", "event", "=", "event", "||", "w", ".", "event", ";", "if", "(", "event", ".", "preventDefault", ")", "{", "event", ".", "preventDefault", "(", ")", ";", "}", "else", "{", "event", ".", "returnValue", "=", "false", ";", "}", "if", "(", "noBubbles", ")", "{", "if", "(", "event", ".", "stopPropagation", ")", "{", "event", ".", "stopPropagation", "(", ")", ";", "}", "else", "{", "event", ".", "cancelBubble", "=", "true", ";", "}", "}", "}" ]
Crossbrowser reliable way to stop default event action. @param {Event} event Event object. @param {Bool} noBubbles Cancel event bubbling. @return {Void}
[ "Crossbrowser", "reliable", "way", "to", "stop", "default", "event", "action", "." ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/public/lib/jquery.sly.js#L1349-L1365
23,377
HaoyCn/iconfont-plugin-webpack
index.js
shouldReplace
function shouldReplace(svg, cssPath, newCssContent) { try { fs.accessSync(svg.path, fs.constants ? fs.constants.R_OK : fs.R_OK); fs.accessSync(cssPath, fs.constants ? fs.constants.R_OK : fs.R_OK); } catch(e) { return true; } const oldSvg = fs.readFileSync(svg.path).toString(); const newSvg = svg.contents.toString(); const oldCss = fs.readFileSync(cssPath).toString(); const svgDifferent = oldSvg !== newSvg; // returns true if new SVG is different const cssDifferent = oldCss !== newCssContent; // returns true if new SCSS is different // only rerender if svgs or scss are different return svgDifferent || cssDifferent ? true : false; }
javascript
function shouldReplace(svg, cssPath, newCssContent) { try { fs.accessSync(svg.path, fs.constants ? fs.constants.R_OK : fs.R_OK); fs.accessSync(cssPath, fs.constants ? fs.constants.R_OK : fs.R_OK); } catch(e) { return true; } const oldSvg = fs.readFileSync(svg.path).toString(); const newSvg = svg.contents.toString(); const oldCss = fs.readFileSync(cssPath).toString(); const svgDifferent = oldSvg !== newSvg; // returns true if new SVG is different const cssDifferent = oldCss !== newCssContent; // returns true if new SCSS is different // only rerender if svgs or scss are different return svgDifferent || cssDifferent ? true : false; }
[ "function", "shouldReplace", "(", "svg", ",", "cssPath", ",", "newCssContent", ")", "{", "try", "{", "fs", ".", "accessSync", "(", "svg", ".", "path", ",", "fs", ".", "constants", "?", "fs", ".", "constants", ".", "R_OK", ":", "fs", ".", "R_OK", ")", ";", "fs", ".", "accessSync", "(", "cssPath", ",", "fs", ".", "constants", "?", "fs", ".", "constants", ".", "R_OK", ":", "fs", ".", "R_OK", ")", ";", "}", "catch", "(", "e", ")", "{", "return", "true", ";", "}", "const", "oldSvg", "=", "fs", ".", "readFileSync", "(", "svg", ".", "path", ")", ".", "toString", "(", ")", ";", "const", "newSvg", "=", "svg", ".", "contents", ".", "toString", "(", ")", ";", "const", "oldCss", "=", "fs", ".", "readFileSync", "(", "cssPath", ")", ".", "toString", "(", ")", ";", "const", "svgDifferent", "=", "oldSvg", "!==", "newSvg", ";", "// returns true if new SVG is different", "const", "cssDifferent", "=", "oldCss", "!==", "newCssContent", ";", "// returns true if new SCSS is different", "// only rerender if svgs or scss are different", "return", "svgDifferent", "||", "cssDifferent", "?", "true", ":", "false", ";", "}" ]
checks if a recompilation is necessary
[ "checks", "if", "a", "recompilation", "is", "necessary" ]
8252e04898c4d53fbba1cb7dcb3293a90fbe32b2
https://github.com/HaoyCn/iconfont-plugin-webpack/blob/8252e04898c4d53fbba1cb7dcb3293a90fbe32b2/index.js#L11-L28
23,378
mz121star/NJBlog
libs/mocha/should.js
function(expr, msg, negatedMsg, expected, showDiff){ var msg = this.negate ? negatedMsg : msg , ok = this.negate ? !expr : expr , obj = this.obj; if (ok) return; var err = new AssertionError({ message: msg.call(this) , actual: obj , expected: expected , stackStartFunction: this.assert , negated: this.negate }); err.showDiff = showDiff; throw err; }
javascript
function(expr, msg, negatedMsg, expected, showDiff){ var msg = this.negate ? negatedMsg : msg , ok = this.negate ? !expr : expr , obj = this.obj; if (ok) return; var err = new AssertionError({ message: msg.call(this) , actual: obj , expected: expected , stackStartFunction: this.assert , negated: this.negate }); err.showDiff = showDiff; throw err; }
[ "function", "(", "expr", ",", "msg", ",", "negatedMsg", ",", "expected", ",", "showDiff", ")", "{", "var", "msg", "=", "this", ".", "negate", "?", "negatedMsg", ":", "msg", ",", "ok", "=", "this", ".", "negate", "?", "!", "expr", ":", "expr", ",", "obj", "=", "this", ".", "obj", ";", "if", "(", "ok", ")", "return", ";", "var", "err", "=", "new", "AssertionError", "(", "{", "message", ":", "msg", ".", "call", "(", "this", ")", ",", "actual", ":", "obj", ",", "expected", ":", "expected", ",", "stackStartFunction", ":", "this", ".", "assert", ",", "negated", ":", "this", ".", "negate", "}", ")", ";", "err", ".", "showDiff", "=", "showDiff", ";", "throw", "err", ";", "}" ]
Assert _expr_ with the given _msg_ and _negatedMsg_. @param {Boolean} expr @param {String} msg @param {String} negatedMsg @param {Object} expected @api private
[ "Assert", "_expr_", "with", "the", "given", "_msg_", "and", "_negatedMsg_", "." ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/libs/mocha/should.js#L113-L131
23,379
mz121star/NJBlog
libs/mocha/should.js
function(val, desc){ this.assert( eql(val, this.obj) , function(){ return 'expected ' + this.inspect + ' to equal ' + i(val) + (desc ? " | " + desc : "") } , function(){ return 'expected ' + this.inspect + ' to not equal ' + i(val) + (desc ? " | " + desc : "") } , val , true); return this; }
javascript
function(val, desc){ this.assert( eql(val, this.obj) , function(){ return 'expected ' + this.inspect + ' to equal ' + i(val) + (desc ? " | " + desc : "") } , function(){ return 'expected ' + this.inspect + ' to not equal ' + i(val) + (desc ? " | " + desc : "") } , val , true); return this; }
[ "function", "(", "val", ",", "desc", ")", "{", "this", ".", "assert", "(", "eql", "(", "val", ",", "this", ".", "obj", ")", ",", "function", "(", ")", "{", "return", "'expected '", "+", "this", ".", "inspect", "+", "' to equal '", "+", "i", "(", "val", ")", "+", "(", "desc", "?", "\" | \"", "+", "desc", ":", "\"\"", ")", "}", ",", "function", "(", ")", "{", "return", "'expected '", "+", "this", ".", "inspect", "+", "' to not equal '", "+", "i", "(", "val", ")", "+", "(", "desc", "?", "\" | \"", "+", "desc", ":", "\"\"", ")", "}", ",", "val", ",", "true", ")", ";", "return", "this", ";", "}" ]
Assert equal. @param {Mixed} val @param {String} description @api public
[ "Assert", "equal", "." ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/libs/mocha/should.js#L284-L292
23,380
mz121star/NJBlog
libs/mocha/should.js
function(val, desc){ this.assert( val.valueOf() === this.obj , function(){ return 'expected ' + this.inspect + ' to equal ' + i(val) + (desc ? " | " + desc : "") } , function(){ return 'expected ' + this.inspect + ' to not equal ' + i(val) + (desc ? " | " + desc : "") } , val); return this; }
javascript
function(val, desc){ this.assert( val.valueOf() === this.obj , function(){ return 'expected ' + this.inspect + ' to equal ' + i(val) + (desc ? " | " + desc : "") } , function(){ return 'expected ' + this.inspect + ' to not equal ' + i(val) + (desc ? " | " + desc : "") } , val); return this; }
[ "function", "(", "val", ",", "desc", ")", "{", "this", ".", "assert", "(", "val", ".", "valueOf", "(", ")", "===", "this", ".", "obj", ",", "function", "(", ")", "{", "return", "'expected '", "+", "this", ".", "inspect", "+", "' to equal '", "+", "i", "(", "val", ")", "+", "(", "desc", "?", "\" | \"", "+", "desc", ":", "\"\"", ")", "}", ",", "function", "(", ")", "{", "return", "'expected '", "+", "this", ".", "inspect", "+", "' to not equal '", "+", "i", "(", "val", ")", "+", "(", "desc", "?", "\" | \"", "+", "desc", ":", "\"\"", ")", "}", ",", "val", ")", ";", "return", "this", ";", "}" ]
Assert strict equal. @param {Mixed} val @param {String} description @api public
[ "Assert", "strict", "equal", "." ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/libs/mocha/should.js#L302-L309
23,381
mz121star/NJBlog
libs/mocha/should.js
function(type, desc){ this.assert( type == typeof this.obj , function(){ return 'expected ' + this.inspect + ' to be a ' + type + (desc ? " | " + desc : "") } , function(){ return 'expected ' + this.inspect + ' not to be a ' + type + (desc ? " | " + desc : "") }) return this; }
javascript
function(type, desc){ this.assert( type == typeof this.obj , function(){ return 'expected ' + this.inspect + ' to be a ' + type + (desc ? " | " + desc : "") } , function(){ return 'expected ' + this.inspect + ' not to be a ' + type + (desc ? " | " + desc : "") }) return this; }
[ "function", "(", "type", ",", "desc", ")", "{", "this", ".", "assert", "(", "type", "==", "typeof", "this", ".", "obj", ",", "function", "(", ")", "{", "return", "'expected '", "+", "this", ".", "inspect", "+", "' to be a '", "+", "type", "+", "(", "desc", "?", "\" | \"", "+", "desc", ":", "\"\"", ")", "}", ",", "function", "(", ")", "{", "return", "'expected '", "+", "this", ".", "inspect", "+", "' not to be a '", "+", "type", "+", "(", "desc", "?", "\" | \"", "+", "desc", ":", "\"\"", ")", "}", ")", "return", "this", ";", "}" ]
Assert typeof. @param {Mixed} type @param {String} description @api public
[ "Assert", "typeof", "." ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/libs/mocha/should.js#L350-L356
23,382
mz121star/NJBlog
libs/mocha/should.js
function(constructor, desc){ var name = constructor.name; this.assert( this.obj instanceof constructor , function(){ return 'expected ' + this.inspect + ' to be an instance of ' + name + (desc ? " | " + desc : "") } , function(){ return 'expected ' + this.inspect + ' not to be an instance of ' + name + (desc ? " | " + desc : "") }); return this; }
javascript
function(constructor, desc){ var name = constructor.name; this.assert( this.obj instanceof constructor , function(){ return 'expected ' + this.inspect + ' to be an instance of ' + name + (desc ? " | " + desc : "") } , function(){ return 'expected ' + this.inspect + ' not to be an instance of ' + name + (desc ? " | " + desc : "") }); return this; }
[ "function", "(", "constructor", ",", "desc", ")", "{", "var", "name", "=", "constructor", ".", "name", ";", "this", ".", "assert", "(", "this", ".", "obj", "instanceof", "constructor", ",", "function", "(", ")", "{", "return", "'expected '", "+", "this", ".", "inspect", "+", "' to be an instance of '", "+", "name", "+", "(", "desc", "?", "\" | \"", "+", "desc", ":", "\"\"", ")", "}", ",", "function", "(", ")", "{", "return", "'expected '", "+", "this", ".", "inspect", "+", "' not to be an instance of '", "+", "name", "+", "(", "desc", "?", "\" | \"", "+", "desc", ":", "\"\"", ")", "}", ")", ";", "return", "this", ";", "}" ]
Assert instanceof. @param {Function} constructor @param {String} description @api public
[ "Assert", "instanceof", "." ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/libs/mocha/should.js#L366-L373
23,383
mz121star/NJBlog
libs/mocha/should.js
function(n, desc){ this.assert( this.obj > n , function(){ return 'expected ' + this.inspect + ' to be above ' + n + (desc ? " | " + desc : "") } , function(){ return 'expected ' + this.inspect + ' to be below ' + n + (desc ? " | " + desc : "") }); return this; }
javascript
function(n, desc){ this.assert( this.obj > n , function(){ return 'expected ' + this.inspect + ' to be above ' + n + (desc ? " | " + desc : "") } , function(){ return 'expected ' + this.inspect + ' to be below ' + n + (desc ? " | " + desc : "") }); return this; }
[ "function", "(", "n", ",", "desc", ")", "{", "this", ".", "assert", "(", "this", ".", "obj", ">", "n", ",", "function", "(", ")", "{", "return", "'expected '", "+", "this", ".", "inspect", "+", "' to be above '", "+", "n", "+", "(", "desc", "?", "\" | \"", "+", "desc", ":", "\"\"", ")", "}", ",", "function", "(", ")", "{", "return", "'expected '", "+", "this", ".", "inspect", "+", "' to be below '", "+", "n", "+", "(", "desc", "?", "\" | \"", "+", "desc", ":", "\"\"", ")", "}", ")", ";", "return", "this", ";", "}" ]
Assert numeric value above _n_. @param {Number} n @param {String} description @api public
[ "Assert", "numeric", "value", "above", "_n_", "." ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/libs/mocha/should.js#L383-L389
23,384
mz121star/NJBlog
libs/mocha/should.js
function(regexp, desc){ this.assert( regexp.exec(this.obj) , function(){ return 'expected ' + this.inspect + ' to match ' + regexp + (desc ? " | " + desc : "") } , function(){ return 'expected ' + this.inspect + ' not to match ' + regexp + (desc ? " | " + desc : "") }); return this; }
javascript
function(regexp, desc){ this.assert( regexp.exec(this.obj) , function(){ return 'expected ' + this.inspect + ' to match ' + regexp + (desc ? " | " + desc : "") } , function(){ return 'expected ' + this.inspect + ' not to match ' + regexp + (desc ? " | " + desc : "") }); return this; }
[ "function", "(", "regexp", ",", "desc", ")", "{", "this", ".", "assert", "(", "regexp", ".", "exec", "(", "this", ".", "obj", ")", ",", "function", "(", ")", "{", "return", "'expected '", "+", "this", ".", "inspect", "+", "' to match '", "+", "regexp", "+", "(", "desc", "?", "\" | \"", "+", "desc", ":", "\"\"", ")", "}", ",", "function", "(", ")", "{", "return", "'expected '", "+", "this", ".", "inspect", "+", "' not to match '", "+", "regexp", "+", "(", "desc", "?", "\" | \"", "+", "desc", ":", "\"\"", ")", "}", ")", ";", "return", "this", ";", "}" ]
Assert string value matches _regexp_. @param {RegExp} regexp @param {String} description @api public
[ "Assert", "string", "value", "matches", "_regexp_", "." ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/libs/mocha/should.js#L415-L421
23,385
mz121star/NJBlog
libs/mocha/should.js
function(n, desc){ this.obj.should.have.property('length'); var len = this.obj.length; this.assert( n == len , function(){ return 'expected ' + this.inspect + ' to have a length of ' + n + ' but got ' + len + (desc ? " | " + desc : "") } , function(){ return 'expected ' + this.inspect + ' to not have a length of ' + len + (desc ? " | " + desc : "") }); return this; }
javascript
function(n, desc){ this.obj.should.have.property('length'); var len = this.obj.length; this.assert( n == len , function(){ return 'expected ' + this.inspect + ' to have a length of ' + n + ' but got ' + len + (desc ? " | " + desc : "") } , function(){ return 'expected ' + this.inspect + ' to not have a length of ' + len + (desc ? " | " + desc : "") }); return this; }
[ "function", "(", "n", ",", "desc", ")", "{", "this", ".", "obj", ".", "should", ".", "have", ".", "property", "(", "'length'", ")", ";", "var", "len", "=", "this", ".", "obj", ".", "length", ";", "this", ".", "assert", "(", "n", "==", "len", ",", "function", "(", ")", "{", "return", "'expected '", "+", "this", ".", "inspect", "+", "' to have a length of '", "+", "n", "+", "' but got '", "+", "len", "+", "(", "desc", "?", "\" | \"", "+", "desc", ":", "\"\"", ")", "}", ",", "function", "(", ")", "{", "return", "'expected '", "+", "this", ".", "inspect", "+", "' to not have a length of '", "+", "len", "+", "(", "desc", "?", "\" | \"", "+", "desc", ":", "\"\"", ")", "}", ")", ";", "return", "this", ";", "}" ]
Assert property "length" exists and has value of _n_. @param {Number} n @param {String} description @api public
[ "Assert", "property", "length", "exists", "and", "has", "value", "of", "_n_", "." ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/libs/mocha/should.js#L431-L439
23,386
mz121star/NJBlog
libs/mocha/should.js
function(name, val, desc){ if (this.negate && undefined !== val) { if (undefined === this.obj[name]) { throw new Error(this.inspect + ' has no property ' + i(name) + (desc ? " | " + desc : "")); } } else { this.assert( undefined !== this.obj[name] , function(){ return 'expected ' + this.inspect + ' to have a property ' + i(name) + (desc ? " | " + desc : "") } , function(){ return 'expected ' + this.inspect + ' to not have a property ' + i(name) + (desc ? " | " + desc : "") }); } if (undefined !== val) { this.assert( val === this.obj[name] , function(){ return 'expected ' + this.inspect + ' to have a property ' + i(name) + ' of ' + i(val) + ', but got ' + i(this.obj[name]) + (desc ? " | " + desc : "") } , function(){ return 'expected ' + this.inspect + ' to not have a property ' + i(name) + ' of ' + i(val) + (desc ? " | " + desc : "") }); } this.obj = this.obj[name]; return this; }
javascript
function(name, val, desc){ if (this.negate && undefined !== val) { if (undefined === this.obj[name]) { throw new Error(this.inspect + ' has no property ' + i(name) + (desc ? " | " + desc : "")); } } else { this.assert( undefined !== this.obj[name] , function(){ return 'expected ' + this.inspect + ' to have a property ' + i(name) + (desc ? " | " + desc : "") } , function(){ return 'expected ' + this.inspect + ' to not have a property ' + i(name) + (desc ? " | " + desc : "") }); } if (undefined !== val) { this.assert( val === this.obj[name] , function(){ return 'expected ' + this.inspect + ' to have a property ' + i(name) + ' of ' + i(val) + ', but got ' + i(this.obj[name]) + (desc ? " | " + desc : "") } , function(){ return 'expected ' + this.inspect + ' to not have a property ' + i(name) + ' of ' + i(val) + (desc ? " | " + desc : "") }); } this.obj = this.obj[name]; return this; }
[ "function", "(", "name", ",", "val", ",", "desc", ")", "{", "if", "(", "this", ".", "negate", "&&", "undefined", "!==", "val", ")", "{", "if", "(", "undefined", "===", "this", ".", "obj", "[", "name", "]", ")", "{", "throw", "new", "Error", "(", "this", ".", "inspect", "+", "' has no property '", "+", "i", "(", "name", ")", "+", "(", "desc", "?", "\" | \"", "+", "desc", ":", "\"\"", ")", ")", ";", "}", "}", "else", "{", "this", ".", "assert", "(", "undefined", "!==", "this", ".", "obj", "[", "name", "]", ",", "function", "(", ")", "{", "return", "'expected '", "+", "this", ".", "inspect", "+", "' to have a property '", "+", "i", "(", "name", ")", "+", "(", "desc", "?", "\" | \"", "+", "desc", ":", "\"\"", ")", "}", ",", "function", "(", ")", "{", "return", "'expected '", "+", "this", ".", "inspect", "+", "' to not have a property '", "+", "i", "(", "name", ")", "+", "(", "desc", "?", "\" | \"", "+", "desc", ":", "\"\"", ")", "}", ")", ";", "}", "if", "(", "undefined", "!==", "val", ")", "{", "this", ".", "assert", "(", "val", "===", "this", ".", "obj", "[", "name", "]", ",", "function", "(", ")", "{", "return", "'expected '", "+", "this", ".", "inspect", "+", "' to have a property '", "+", "i", "(", "name", ")", "+", "' of '", "+", "i", "(", "val", ")", "+", "', but got '", "+", "i", "(", "this", ".", "obj", "[", "name", "]", ")", "+", "(", "desc", "?", "\" | \"", "+", "desc", ":", "\"\"", ")", "}", ",", "function", "(", ")", "{", "return", "'expected '", "+", "this", ".", "inspect", "+", "' to not have a property '", "+", "i", "(", "name", ")", "+", "' of '", "+", "i", "(", "val", ")", "+", "(", "desc", "?", "\" | \"", "+", "desc", ":", "\"\"", ")", "}", ")", ";", "}", "this", ".", "obj", "=", "this", ".", "obj", "[", "name", "]", ";", "return", "this", ";", "}" ]
Assert property _name_ exists, with optional _val_. @param {String} name @param {Mixed} [val] @param {String} description @api public
[ "Assert", "property", "_name_", "exists", "with", "optional", "_val_", "." ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/libs/mocha/should.js#L450-L472
23,387
mz121star/NJBlog
libs/mocha/should.js
function(name, desc){ this.assert( this.obj.hasOwnProperty(name) , function(){ return 'expected ' + this.inspect + ' to have own property ' + i(name) + (desc ? " | " + desc : "") } , function(){ return 'expected ' + this.inspect + ' to not have own property ' + i(name) + (desc ? " | " + desc : "") }); this.obj = this.obj[name]; return this; }
javascript
function(name, desc){ this.assert( this.obj.hasOwnProperty(name) , function(){ return 'expected ' + this.inspect + ' to have own property ' + i(name) + (desc ? " | " + desc : "") } , function(){ return 'expected ' + this.inspect + ' to not have own property ' + i(name) + (desc ? " | " + desc : "") }); this.obj = this.obj[name]; return this; }
[ "function", "(", "name", ",", "desc", ")", "{", "this", ".", "assert", "(", "this", ".", "obj", ".", "hasOwnProperty", "(", "name", ")", ",", "function", "(", ")", "{", "return", "'expected '", "+", "this", ".", "inspect", "+", "' to have own property '", "+", "i", "(", "name", ")", "+", "(", "desc", "?", "\" | \"", "+", "desc", ":", "\"\"", ")", "}", ",", "function", "(", ")", "{", "return", "'expected '", "+", "this", ".", "inspect", "+", "' to not have own property '", "+", "i", "(", "name", ")", "+", "(", "desc", "?", "\" | \"", "+", "desc", ":", "\"\"", ")", "}", ")", ";", "this", ".", "obj", "=", "this", ".", "obj", "[", "name", "]", ";", "return", "this", ";", "}" ]
Assert own property _name_ exists. @param {String} name @param {String} description @api public
[ "Assert", "own", "property", "_name_", "exists", "." ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/libs/mocha/should.js#L482-L489
23,388
mz121star/NJBlog
libs/mocha/should.js
function(obj, desc){ this.assert( this.obj.some(function(item) { return eql(obj, item); }) , function(){ return 'expected ' + this.inspect + ' to include an object equal to ' + i(obj) + (desc ? " | " + desc : "") } , function(){ return 'expected ' + this.inspect + ' to not include an object equal to ' + i(obj) + (desc ? " | " + desc : "") }); return this; }
javascript
function(obj, desc){ this.assert( this.obj.some(function(item) { return eql(obj, item); }) , function(){ return 'expected ' + this.inspect + ' to include an object equal to ' + i(obj) + (desc ? " | " + desc : "") } , function(){ return 'expected ' + this.inspect + ' to not include an object equal to ' + i(obj) + (desc ? " | " + desc : "") }); return this; }
[ "function", "(", "obj", ",", "desc", ")", "{", "this", ".", "assert", "(", "this", ".", "obj", ".", "some", "(", "function", "(", "item", ")", "{", "return", "eql", "(", "obj", ",", "item", ")", ";", "}", ")", ",", "function", "(", ")", "{", "return", "'expected '", "+", "this", ".", "inspect", "+", "' to include an object equal to '", "+", "i", "(", "obj", ")", "+", "(", "desc", "?", "\" | \"", "+", "desc", ":", "\"\"", ")", "}", ",", "function", "(", ")", "{", "return", "'expected '", "+", "this", ".", "inspect", "+", "' to not include an object equal to '", "+", "i", "(", "obj", ")", "+", "(", "desc", "?", "\" | \"", "+", "desc", ":", "\"\"", ")", "}", ")", ";", "return", "this", ";", "}" ]
Assert that an object equal to `obj` is present. @param {Array} obj @param {String} description @api public
[ "Assert", "that", "an", "object", "equal", "to", "obj", "is", "present", "." ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/libs/mocha/should.js#L524-L530
23,389
mz121star/NJBlog
libs/mocha/should.js
function(obj){ console.warn('should.contain() is deprecated, use should.include()'); this.obj.should.be.an.instanceof(Array); this.assert( ~this.obj.indexOf(obj) , function(){ return 'expected ' + this.inspect + ' to contain ' + i(obj) } , function(){ return 'expected ' + this.inspect + ' to not contain ' + i(obj) }); return this; }
javascript
function(obj){ console.warn('should.contain() is deprecated, use should.include()'); this.obj.should.be.an.instanceof(Array); this.assert( ~this.obj.indexOf(obj) , function(){ return 'expected ' + this.inspect + ' to contain ' + i(obj) } , function(){ return 'expected ' + this.inspect + ' to not contain ' + i(obj) }); return this; }
[ "function", "(", "obj", ")", "{", "console", ".", "warn", "(", "'should.contain() is deprecated, use should.include()'", ")", ";", "this", ".", "obj", ".", "should", ".", "be", ".", "an", ".", "instanceof", "(", "Array", ")", ";", "this", ".", "assert", "(", "~", "this", ".", "obj", ".", "indexOf", "(", "obj", ")", ",", "function", "(", ")", "{", "return", "'expected '", "+", "this", ".", "inspect", "+", "' to contain '", "+", "i", "(", "obj", ")", "}", ",", "function", "(", ")", "{", "return", "'expected '", "+", "this", ".", "inspect", "+", "' to not contain '", "+", "i", "(", "obj", ")", "}", ")", ";", "return", "this", ";", "}" ]
Assert that the array contains _obj_. @param {Mixed} obj @api public
[ "Assert", "that", "the", "array", "contains", "_obj_", "." ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/libs/mocha/should.js#L539-L547
23,390
mz121star/NJBlog
libs/mocha/should.js
function(field, val){ this.obj.should .have.property('headers').and .have.property(field.toLowerCase(), val); return this; }
javascript
function(field, val){ this.obj.should .have.property('headers').and .have.property(field.toLowerCase(), val); return this; }
[ "function", "(", "field", ",", "val", ")", "{", "this", ".", "obj", ".", "should", ".", "have", ".", "property", "(", "'headers'", ")", ".", "and", ".", "have", ".", "property", "(", "field", ".", "toLowerCase", "(", ")", ",", "val", ")", ";", "return", "this", ";", "}" ]
Assert that header `field` has the given `val`. @param {String} field @param {String} val @return {Assertion} for chaining @api public
[ "Assert", "that", "header", "field", "has", "the", "given", "val", "." ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/libs/mocha/should.js#L609-L614
23,391
mz121star/NJBlog
libs/mocha/should.js
function(code){ this.obj.should.have.property('statusCode'); var status = this.obj.statusCode; this.assert( code == status , function(){ return 'expected response code of ' + code + ' ' + i(statusCodes[code]) + ', but got ' + status + ' ' + i(statusCodes[status]) } , function(){ return 'expected to not respond with ' + code + ' ' + i(statusCodes[code]) }); return this; }
javascript
function(code){ this.obj.should.have.property('statusCode'); var status = this.obj.statusCode; this.assert( code == status , function(){ return 'expected response code of ' + code + ' ' + i(statusCodes[code]) + ', but got ' + status + ' ' + i(statusCodes[status]) } , function(){ return 'expected to not respond with ' + code + ' ' + i(statusCodes[code]) }); return this; }
[ "function", "(", "code", ")", "{", "this", ".", "obj", ".", "should", ".", "have", ".", "property", "(", "'statusCode'", ")", ";", "var", "status", "=", "this", ".", "obj", ".", "statusCode", ";", "this", ".", "assert", "(", "code", "==", "status", ",", "function", "(", ")", "{", "return", "'expected response code of '", "+", "code", "+", "' '", "+", "i", "(", "statusCodes", "[", "code", "]", ")", "+", "', but got '", "+", "status", "+", "' '", "+", "i", "(", "statusCodes", "[", "status", "]", ")", "}", ",", "function", "(", ")", "{", "return", "'expected to not respond with '", "+", "code", "+", "' '", "+", "i", "(", "statusCodes", "[", "code", "]", ")", "}", ")", ";", "return", "this", ";", "}" ]
Assert `.statusCode` of `code`. @param {Number} code @return {Assertion} for chaining @api public
[ "Assert", ".", "statusCode", "of", "code", "." ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/libs/mocha/should.js#L624-L635
23,392
mz121star/NJBlog
public/lib/jquery/jquery-1.8.2.js
addToPrefiltersOrTransports
function addToPrefiltersOrTransports( structure ) { // dataTypeExpression is optional and defaults to "*" return function( dataTypeExpression, func ) { if ( typeof dataTypeExpression !== "string" ) { func = dataTypeExpression; dataTypeExpression = "*"; } var dataType, list, placeBefore, dataTypes = dataTypeExpression.toLowerCase().split( core_rspace ), i = 0, length = dataTypes.length; if ( jQuery.isFunction( func ) ) { // For each dataType in the dataTypeExpression for ( ; i < length; i++ ) { dataType = dataTypes[ i ]; // We control if we're asked to add before // any existing element placeBefore = /^\+/.test( dataType ); if ( placeBefore ) { dataType = dataType.substr( 1 ) || "*"; } list = structure[ dataType ] = structure[ dataType ] || []; // then we add to the structure accordingly list[ placeBefore ? "unshift" : "push" ]( func ); } } }; }
javascript
function addToPrefiltersOrTransports( structure ) { // dataTypeExpression is optional and defaults to "*" return function( dataTypeExpression, func ) { if ( typeof dataTypeExpression !== "string" ) { func = dataTypeExpression; dataTypeExpression = "*"; } var dataType, list, placeBefore, dataTypes = dataTypeExpression.toLowerCase().split( core_rspace ), i = 0, length = dataTypes.length; if ( jQuery.isFunction( func ) ) { // For each dataType in the dataTypeExpression for ( ; i < length; i++ ) { dataType = dataTypes[ i ]; // We control if we're asked to add before // any existing element placeBefore = /^\+/.test( dataType ); if ( placeBefore ) { dataType = dataType.substr( 1 ) || "*"; } list = structure[ dataType ] = structure[ dataType ] || []; // then we add to the structure accordingly list[ placeBefore ? "unshift" : "push" ]( func ); } } }; }
[ "function", "addToPrefiltersOrTransports", "(", "structure", ")", "{", "// dataTypeExpression is optional and defaults to \"*\"", "return", "function", "(", "dataTypeExpression", ",", "func", ")", "{", "if", "(", "typeof", "dataTypeExpression", "!==", "\"string\"", ")", "{", "func", "=", "dataTypeExpression", ";", "dataTypeExpression", "=", "\"*\"", ";", "}", "var", "dataType", ",", "list", ",", "placeBefore", ",", "dataTypes", "=", "dataTypeExpression", ".", "toLowerCase", "(", ")", ".", "split", "(", "core_rspace", ")", ",", "i", "=", "0", ",", "length", "=", "dataTypes", ".", "length", ";", "if", "(", "jQuery", ".", "isFunction", "(", "func", ")", ")", "{", "// For each dataType in the dataTypeExpression", "for", "(", ";", "i", "<", "length", ";", "i", "++", ")", "{", "dataType", "=", "dataTypes", "[", "i", "]", ";", "// We control if we're asked to add before", "// any existing element", "placeBefore", "=", "/", "^\\+", "/", ".", "test", "(", "dataType", ")", ";", "if", "(", "placeBefore", ")", "{", "dataType", "=", "dataType", ".", "substr", "(", "1", ")", "||", "\"*\"", ";", "}", "list", "=", "structure", "[", "dataType", "]", "=", "structure", "[", "dataType", "]", "||", "[", "]", ";", "// then we add to the structure accordingly", "list", "[", "placeBefore", "?", "\"unshift\"", ":", "\"push\"", "]", "(", "func", ")", ";", "}", "}", "}", ";", "}" ]
Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
[ "Base", "constructor", "for", "jQuery", ".", "ajaxPrefilter", "and", "jQuery", ".", "ajaxTransport" ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/public/lib/jquery/jquery-1.8.2.js#L7320-L7351
23,393
mz121star/NJBlog
public/lib/angular/angular-bootstrap-prettify.js
appendDecorations
function appendDecorations(basePos, sourceCode, langHandler, out) { if (!sourceCode) { return; } var job = { sourceCode: sourceCode, basePos: basePos }; langHandler(job); out.push.apply(out, job.decorations); }
javascript
function appendDecorations(basePos, sourceCode, langHandler, out) { if (!sourceCode) { return; } var job = { sourceCode: sourceCode, basePos: basePos }; langHandler(job); out.push.apply(out, job.decorations); }
[ "function", "appendDecorations", "(", "basePos", ",", "sourceCode", ",", "langHandler", ",", "out", ")", "{", "if", "(", "!", "sourceCode", ")", "{", "return", ";", "}", "var", "job", "=", "{", "sourceCode", ":", "sourceCode", ",", "basePos", ":", "basePos", "}", ";", "langHandler", "(", "job", ")", ";", "out", ".", "push", ".", "apply", "(", "out", ",", "job", ".", "decorations", ")", ";", "}" ]
Apply the given language handler to sourceCode and add the resulting decorations to out. @param {number} basePos the index of sourceCode within the chunk of source whose decorations are already present on out.
[ "Apply", "the", "given", "language", "handler", "to", "sourceCode", "and", "add", "the", "resulting", "decorations", "to", "out", "." ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/public/lib/angular/angular-bootstrap-prettify.js#L866-L874
23,394
mz121star/NJBlog
public/js/main-built.js
isWindow
function isWindow(obj) { return obj && obj.document && obj.location && obj.alert && obj.setInterval; }
javascript
function isWindow(obj) { return obj && obj.document && obj.location && obj.alert && obj.setInterval; }
[ "function", "isWindow", "(", "obj", ")", "{", "return", "obj", "&&", "obj", ".", "document", "&&", "obj", ".", "location", "&&", "obj", ".", "alert", "&&", "obj", ".", "setInterval", ";", "}" ]
Checks if `obj` is a window object. @private @param {*} obj Object to check @returns {boolean} True if `obj` is a window obj.
[ "Checks", "if", "obj", "is", "a", "window", "object", "." ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/public/js/main-built.js#L381-L383
23,395
mz121star/NJBlog
public/js/main-built.js
shallowCopy
function shallowCopy(src, dst) { dst = dst || {}; for(var key in src) { if (src.hasOwnProperty(key) && key.substr(0, 2) !== '$$') { dst[key] = src[key]; } } return dst; }
javascript
function shallowCopy(src, dst) { dst = dst || {}; for(var key in src) { if (src.hasOwnProperty(key) && key.substr(0, 2) !== '$$') { dst[key] = src[key]; } } return dst; }
[ "function", "shallowCopy", "(", "src", ",", "dst", ")", "{", "dst", "=", "dst", "||", "{", "}", ";", "for", "(", "var", "key", "in", "src", ")", "{", "if", "(", "src", ".", "hasOwnProperty", "(", "key", ")", "&&", "key", ".", "substr", "(", "0", ",", "2", ")", "!==", "'$$'", ")", "{", "dst", "[", "key", "]", "=", "src", "[", "key", "]", ";", "}", "}", "return", "dst", ";", "}" ]
Create a shallow copy of an object
[ "Create", "a", "shallow", "copy", "of", "an", "object" ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/public/js/main-built.js#L574-L584
23,396
mz121star/NJBlog
public/js/main-built.js
function(key, value) { var array = this[key = hashKey(key)]; if (!array) { this[key] = [value]; } else { array.push(value); } }
javascript
function(key, value) { var array = this[key = hashKey(key)]; if (!array) { this[key] = [value]; } else { array.push(value); } }
[ "function", "(", "key", ",", "value", ")", "{", "var", "array", "=", "this", "[", "key", "=", "hashKey", "(", "key", ")", "]", ";", "if", "(", "!", "array", ")", "{", "this", "[", "key", "]", "=", "[", "value", "]", ";", "}", "else", "{", "array", ".", "push", "(", "value", ")", ";", "}", "}" ]
Same as array push, but using an array as the value for the hash
[ "Same", "as", "array", "push", "but", "using", "an", "array", "as", "the", "value", "for", "the", "hash" ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/public/js/main-built.js#L2192-L2199
23,397
mz121star/NJBlog
public/js/main-built.js
function(key) { var array = this[key = hashKey(key)]; if (array) { if (array.length == 1) { delete this[key]; return array[0]; } else { return array.shift(); } } }
javascript
function(key) { var array = this[key = hashKey(key)]; if (array) { if (array.length == 1) { delete this[key]; return array[0]; } else { return array.shift(); } } }
[ "function", "(", "key", ")", "{", "var", "array", "=", "this", "[", "key", "=", "hashKey", "(", "key", ")", "]", ";", "if", "(", "array", ")", "{", "if", "(", "array", ".", "length", "==", "1", ")", "{", "delete", "this", "[", "key", "]", ";", "return", "array", "[", "0", "]", ";", "}", "else", "{", "return", "array", ".", "shift", "(", ")", ";", "}", "}", "}" ]
Same as array shift, but using an array as the value for the hash
[ "Same", "as", "array", "shift", "but", "using", "an", "array", "as", "the", "value", "for", "the", "hash" ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/public/js/main-built.js#L2204-L2214
23,398
mz121star/NJBlog
public/js/main-built.js
function(key, fn) { var attrs = this, $$observers = (attrs.$$observers || (attrs.$$observers = {})), listeners = ($$observers[key] || ($$observers[key] = [])); listeners.push(fn); $rootScope.$evalAsync(function() { if (!listeners.$$inter) { // no one registered attribute interpolation function, so lets call it manually fn(attrs[key]); } }); return fn; }
javascript
function(key, fn) { var attrs = this, $$observers = (attrs.$$observers || (attrs.$$observers = {})), listeners = ($$observers[key] || ($$observers[key] = [])); listeners.push(fn); $rootScope.$evalAsync(function() { if (!listeners.$$inter) { // no one registered attribute interpolation function, so lets call it manually fn(attrs[key]); } }); return fn; }
[ "function", "(", "key", ",", "fn", ")", "{", "var", "attrs", "=", "this", ",", "$$observers", "=", "(", "attrs", ".", "$$observers", "||", "(", "attrs", ".", "$$observers", "=", "{", "}", ")", ")", ",", "listeners", "=", "(", "$$observers", "[", "key", "]", "||", "(", "$$observers", "[", "key", "]", "=", "[", "]", ")", ")", ";", "listeners", ".", "push", "(", "fn", ")", ";", "$rootScope", ".", "$evalAsync", "(", "function", "(", ")", "{", "if", "(", "!", "listeners", ".", "$$inter", ")", "{", "// no one registered attribute interpolation function, so lets call it manually", "fn", "(", "attrs", "[", "key", "]", ")", ";", "}", "}", ")", ";", "return", "fn", ";", "}" ]
Observe an interpolated attribute. The observer will never be called, if given attribute is not interpolated. @param {string} key Normalized key. (ie ngAttribute) . @param {function(*)} fn Function that will be called whenever the attribute value changes. @returns {function(*)} the `fn` Function passed in.
[ "Observe", "an", "interpolated", "attribute", ".", "The", "observer", "will", "never", "be", "called", "if", "given", "attribute", "is", "not", "interpolated", "." ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/public/js/main-built.js#L3695-L3708
23,399
mz121star/NJBlog
public/js/main-built.js
$SnifferProvider
function $SnifferProvider() { this.$get = ['$window', function($window) { var eventSupport = {}, android = int((/android (\d+)/.exec(lowercase($window.navigator.userAgent)) || [])[1]); return { // Android has history.pushState, but it does not update location correctly // so let's not use the history API at all. // http://code.google.com/p/android/issues/detail?id=17471 // https://github.com/angular/angular.js/issues/904 history: !!($window.history && $window.history.pushState && !(android < 4)), hashchange: 'onhashchange' in $window && // IE8 compatible mode lies (!$window.document.documentMode || $window.document.documentMode > 7), hasEvent: function(event) { // IE9 implements 'input' event it's so fubared that we rather pretend that it doesn't have // it. In particular the event is not fired when backspace or delete key are pressed or // when cut operation is performed. if (event == 'input' && msie == 9) return false; if (isUndefined(eventSupport[event])) { var divElm = $window.document.createElement('div'); eventSupport[event] = 'on' + event in divElm; } return eventSupport[event]; }, // TODO(i): currently there is no way to feature detect CSP without triggering alerts csp: false }; }]; }
javascript
function $SnifferProvider() { this.$get = ['$window', function($window) { var eventSupport = {}, android = int((/android (\d+)/.exec(lowercase($window.navigator.userAgent)) || [])[1]); return { // Android has history.pushState, but it does not update location correctly // so let's not use the history API at all. // http://code.google.com/p/android/issues/detail?id=17471 // https://github.com/angular/angular.js/issues/904 history: !!($window.history && $window.history.pushState && !(android < 4)), hashchange: 'onhashchange' in $window && // IE8 compatible mode lies (!$window.document.documentMode || $window.document.documentMode > 7), hasEvent: function(event) { // IE9 implements 'input' event it's so fubared that we rather pretend that it doesn't have // it. In particular the event is not fired when backspace or delete key are pressed or // when cut operation is performed. if (event == 'input' && msie == 9) return false; if (isUndefined(eventSupport[event])) { var divElm = $window.document.createElement('div'); eventSupport[event] = 'on' + event in divElm; } return eventSupport[event]; }, // TODO(i): currently there is no way to feature detect CSP without triggering alerts csp: false }; }]; }
[ "function", "$SnifferProvider", "(", ")", "{", "this", ".", "$get", "=", "[", "'$window'", ",", "function", "(", "$window", ")", "{", "var", "eventSupport", "=", "{", "}", ",", "android", "=", "int", "(", "(", "/", "android (\\d+)", "/", ".", "exec", "(", "lowercase", "(", "$window", ".", "navigator", ".", "userAgent", ")", ")", "||", "[", "]", ")", "[", "1", "]", ")", ";", "return", "{", "// Android has history.pushState, but it does not update location correctly", "// so let's not use the history API at all.", "// http://code.google.com/p/android/issues/detail?id=17471", "// https://github.com/angular/angular.js/issues/904", "history", ":", "!", "!", "(", "$window", ".", "history", "&&", "$window", ".", "history", ".", "pushState", "&&", "!", "(", "android", "<", "4", ")", ")", ",", "hashchange", ":", "'onhashchange'", "in", "$window", "&&", "// IE8 compatible mode lies", "(", "!", "$window", ".", "document", ".", "documentMode", "||", "$window", ".", "document", ".", "documentMode", ">", "7", ")", ",", "hasEvent", ":", "function", "(", "event", ")", "{", "// IE9 implements 'input' event it's so fubared that we rather pretend that it doesn't have", "// it. In particular the event is not fired when backspace or delete key are pressed or", "// when cut operation is performed.", "if", "(", "event", "==", "'input'", "&&", "msie", "==", "9", ")", "return", "false", ";", "if", "(", "isUndefined", "(", "eventSupport", "[", "event", "]", ")", ")", "{", "var", "divElm", "=", "$window", ".", "document", ".", "createElement", "(", "'div'", ")", ";", "eventSupport", "[", "event", "]", "=", "'on'", "+", "event", "in", "divElm", ";", "}", "return", "eventSupport", "[", "event", "]", ";", "}", ",", "// TODO(i): currently there is no way to feature detect CSP without triggering alerts", "csp", ":", "false", "}", ";", "}", "]", ";", "}" ]
!!! This is an undocumented "private" service !!! @name ng.$sniffer @requires $window @property {boolean} history Does the browser support html5 history api ? @property {boolean} hashchange Does the browser support hashchange event ? @description This is very simple implementation of testing browser's features.
[ "!!!", "This", "is", "an", "undocumented", "private", "service", "!!!" ]
08be4473daa854e3e8942340998a6c282f3f8c44
https://github.com/mz121star/NJBlog/blob/08be4473daa854e3e8942340998a6c282f3f8c44/public/js/main-built.js#L8104-L8135