id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
sequence | docstring
stringlengths 4
11.8k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
8,000 | downshift-js/downshift | src/utils.js | debounce | function debounce(fn, time) {
let timeoutId
function cancel() {
if (timeoutId) {
clearTimeout(timeoutId)
}
}
function wrapper(...args) {
cancel()
timeoutId = setTimeout(() => {
timeoutId = null
fn(...args)
}, time)
}
wrapper.cancel = cancel
return wrapper
} | javascript | function debounce(fn, time) {
let timeoutId
function cancel() {
if (timeoutId) {
clearTimeout(timeoutId)
}
}
function wrapper(...args) {
cancel()
timeoutId = setTimeout(() => {
timeoutId = null
fn(...args)
}, time)
}
wrapper.cancel = cancel
return wrapper
} | [
"function",
"debounce",
"(",
"fn",
",",
"time",
")",
"{",
"let",
"timeoutId",
"function",
"cancel",
"(",
")",
"{",
"if",
"(",
"timeoutId",
")",
"{",
"clearTimeout",
"(",
"timeoutId",
")",
"}",
"}",
"function",
"wrapper",
"(",
"...",
"args",
")",
"{",
"cancel",
"(",
")",
"timeoutId",
"=",
"setTimeout",
"(",
"(",
")",
"=>",
"{",
"timeoutId",
"=",
"null",
"fn",
"(",
"...",
"args",
")",
"}",
",",
"time",
")",
"}",
"wrapper",
".",
"cancel",
"=",
"cancel",
"return",
"wrapper",
"}"
] | Simple debounce implementation. Will call the given
function once after the time given has passed since
it was last called.
@param {Function} fn the function to call after the time
@param {Number} time the time to wait
@return {Function} the debounced function | [
"Simple",
"debounce",
"implementation",
".",
"Will",
"call",
"the",
"given",
"function",
"once",
"after",
"the",
"time",
"given",
"has",
"passed",
"since",
"it",
"was",
"last",
"called",
"."
] | 7dc7a5b4a06c640f0c375878b78b82b65119f89b | https://github.com/downshift-js/downshift/blob/7dc7a5b4a06c640f0c375878b78b82b65119f89b/src/utils.js#L58-L78 |
8,001 | downshift-js/downshift | src/utils.js | callAllEventHandlers | function callAllEventHandlers(...fns) {
return (event, ...args) =>
fns.some(fn => {
if (fn) {
fn(event, ...args)
}
return (
event.preventDownshiftDefault ||
(event.hasOwnProperty('nativeEvent') &&
event.nativeEvent.preventDownshiftDefault)
)
})
} | javascript | function callAllEventHandlers(...fns) {
return (event, ...args) =>
fns.some(fn => {
if (fn) {
fn(event, ...args)
}
return (
event.preventDownshiftDefault ||
(event.hasOwnProperty('nativeEvent') &&
event.nativeEvent.preventDownshiftDefault)
)
})
} | [
"function",
"callAllEventHandlers",
"(",
"...",
"fns",
")",
"{",
"return",
"(",
"event",
",",
"...",
"args",
")",
"=>",
"fns",
".",
"some",
"(",
"fn",
"=>",
"{",
"if",
"(",
"fn",
")",
"{",
"fn",
"(",
"event",
",",
"...",
"args",
")",
"}",
"return",
"(",
"event",
".",
"preventDownshiftDefault",
"||",
"(",
"event",
".",
"hasOwnProperty",
"(",
"'nativeEvent'",
")",
"&&",
"event",
".",
"nativeEvent",
".",
"preventDownshiftDefault",
")",
")",
"}",
")",
"}"
] | This is intended to be used to compose event handlers.
They are executed in order until one of them sets
`event.preventDownshiftDefault = true`.
@param {...Function} fns the event handler functions
@return {Function} the event handler to add to an element | [
"This",
"is",
"intended",
"to",
"be",
"used",
"to",
"compose",
"event",
"handlers",
".",
"They",
"are",
"executed",
"in",
"order",
"until",
"one",
"of",
"them",
"sets",
"event",
".",
"preventDownshiftDefault",
"=",
"true",
"."
] | 7dc7a5b4a06c640f0c375878b78b82b65119f89b | https://github.com/downshift-js/downshift/blob/7dc7a5b4a06c640f0c375878b78b82b65119f89b/src/utils.js#L87-L99 |
8,002 | downshift-js/downshift | src/utils.js | getNextWrappingIndex | function getNextWrappingIndex(moveAmount, baseIndex, itemCount) {
const itemsLastIndex = itemCount - 1
if (
typeof baseIndex !== 'number' ||
baseIndex < 0 ||
baseIndex >= itemCount
) {
baseIndex = moveAmount > 0 ? -1 : itemsLastIndex + 1
}
let newIndex = baseIndex + moveAmount
if (newIndex < 0) {
newIndex = itemsLastIndex
} else if (newIndex > itemsLastIndex) {
newIndex = 0
}
return newIndex
} | javascript | function getNextWrappingIndex(moveAmount, baseIndex, itemCount) {
const itemsLastIndex = itemCount - 1
if (
typeof baseIndex !== 'number' ||
baseIndex < 0 ||
baseIndex >= itemCount
) {
baseIndex = moveAmount > 0 ? -1 : itemsLastIndex + 1
}
let newIndex = baseIndex + moveAmount
if (newIndex < 0) {
newIndex = itemsLastIndex
} else if (newIndex > itemsLastIndex) {
newIndex = 0
}
return newIndex
} | [
"function",
"getNextWrappingIndex",
"(",
"moveAmount",
",",
"baseIndex",
",",
"itemCount",
")",
"{",
"const",
"itemsLastIndex",
"=",
"itemCount",
"-",
"1",
"if",
"(",
"typeof",
"baseIndex",
"!==",
"'number'",
"||",
"baseIndex",
"<",
"0",
"||",
"baseIndex",
">=",
"itemCount",
")",
"{",
"baseIndex",
"=",
"moveAmount",
">",
"0",
"?",
"-",
"1",
":",
"itemsLastIndex",
"+",
"1",
"}",
"let",
"newIndex",
"=",
"baseIndex",
"+",
"moveAmount",
"if",
"(",
"newIndex",
"<",
"0",
")",
"{",
"newIndex",
"=",
"itemsLastIndex",
"}",
"else",
"if",
"(",
"newIndex",
">",
"itemsLastIndex",
")",
"{",
"newIndex",
"=",
"0",
"}",
"return",
"newIndex",
"}"
] | Returns the new index in the list, in a circular way. If next value is out of bonds from the total,
it will wrap to either 0 or itemCount - 1.
@param {number} moveAmount Number of positions to move. Negative to move backwards, positive forwards.
@param {number} baseIndex The initial position to move from.
@param {number} itemCount The total number of items.
@returns {number} The new index after the move. | [
"Returns",
"the",
"new",
"index",
"in",
"the",
"list",
"in",
"a",
"circular",
"way",
".",
"If",
"next",
"value",
"is",
"out",
"of",
"bonds",
"from",
"the",
"total",
"it",
"will",
"wrap",
"to",
"either",
"0",
"or",
"itemCount",
"-",
"1",
"."
] | 7dc7a5b4a06c640f0c375878b78b82b65119f89b | https://github.com/downshift-js/downshift/blob/7dc7a5b4a06c640f0c375878b78b82b65119f89b/src/utils.js#L276-L293 |
8,003 | downshift-js/downshift | src/set-a11y-status.js | getStatusDiv | function getStatusDiv() {
if (statusDiv) {
return statusDiv
}
statusDiv = document.createElement('div')
statusDiv.setAttribute('id', 'a11y-status-message')
statusDiv.setAttribute('role', 'status')
statusDiv.setAttribute('aria-live', 'polite')
statusDiv.setAttribute('aria-relevant', 'additions text')
Object.assign(statusDiv.style, {
border: '0',
clip: 'rect(0 0 0 0)',
height: '1px',
margin: '-1px',
overflow: 'hidden',
padding: '0',
position: 'absolute',
width: '1px',
})
document.body.appendChild(statusDiv)
return statusDiv
} | javascript | function getStatusDiv() {
if (statusDiv) {
return statusDiv
}
statusDiv = document.createElement('div')
statusDiv.setAttribute('id', 'a11y-status-message')
statusDiv.setAttribute('role', 'status')
statusDiv.setAttribute('aria-live', 'polite')
statusDiv.setAttribute('aria-relevant', 'additions text')
Object.assign(statusDiv.style, {
border: '0',
clip: 'rect(0 0 0 0)',
height: '1px',
margin: '-1px',
overflow: 'hidden',
padding: '0',
position: 'absolute',
width: '1px',
})
document.body.appendChild(statusDiv)
return statusDiv
} | [
"function",
"getStatusDiv",
"(",
")",
"{",
"if",
"(",
"statusDiv",
")",
"{",
"return",
"statusDiv",
"}",
"statusDiv",
"=",
"document",
".",
"createElement",
"(",
"'div'",
")",
"statusDiv",
".",
"setAttribute",
"(",
"'id'",
",",
"'a11y-status-message'",
")",
"statusDiv",
".",
"setAttribute",
"(",
"'role'",
",",
"'status'",
")",
"statusDiv",
".",
"setAttribute",
"(",
"'aria-live'",
",",
"'polite'",
")",
"statusDiv",
".",
"setAttribute",
"(",
"'aria-relevant'",
",",
"'additions text'",
")",
"Object",
".",
"assign",
"(",
"statusDiv",
".",
"style",
",",
"{",
"border",
":",
"'0'",
",",
"clip",
":",
"'rect(0 0 0 0)'",
",",
"height",
":",
"'1px'",
",",
"margin",
":",
"'-1px'",
",",
"overflow",
":",
"'hidden'",
",",
"padding",
":",
"'0'",
",",
"position",
":",
"'absolute'",
",",
"width",
":",
"'1px'",
",",
"}",
")",
"document",
".",
"body",
".",
"appendChild",
"(",
"statusDiv",
")",
"return",
"statusDiv",
"}"
] | Get the status node or create it if it does not already exist
@return {HTMLElement} the status node | [
"Get",
"the",
"status",
"node",
"or",
"create",
"it",
"if",
"it",
"does",
"not",
"already",
"exist"
] | 7dc7a5b4a06c640f0c375878b78b82b65119f89b | https://github.com/downshift-js/downshift/blob/7dc7a5b4a06c640f0c375878b78b82b65119f89b/src/set-a11y-status.js#L34-L55 |
8,004 | dataarts/dat.gui | src/dat/gui/GUI.js | function(controller) {
// TODO listening?
this.__ul.removeChild(controller.__li);
this.__controllers.splice(this.__controllers.indexOf(controller), 1);
const _this = this;
common.defer(function() {
_this.onResize();
});
} | javascript | function(controller) {
// TODO listening?
this.__ul.removeChild(controller.__li);
this.__controllers.splice(this.__controllers.indexOf(controller), 1);
const _this = this;
common.defer(function() {
_this.onResize();
});
} | [
"function",
"(",
"controller",
")",
"{",
"// TODO listening?",
"this",
".",
"__ul",
".",
"removeChild",
"(",
"controller",
".",
"__li",
")",
";",
"this",
".",
"__controllers",
".",
"splice",
"(",
"this",
".",
"__controllers",
".",
"indexOf",
"(",
"controller",
")",
",",
"1",
")",
";",
"const",
"_this",
"=",
"this",
";",
"common",
".",
"defer",
"(",
"function",
"(",
")",
"{",
"_this",
".",
"onResize",
"(",
")",
";",
"}",
")",
";",
"}"
] | Removes the given controller from the GUI.
@param {Controller} controller
@instance | [
"Removes",
"the",
"given",
"controller",
"from",
"the",
"GUI",
"."
] | c2edd82e39d99e9d8b9f1e79011c675bc81eff52 | https://github.com/dataarts/dat.gui/blob/c2edd82e39d99e9d8b9f1e79011c675bc81eff52/src/dat/gui/GUI.js#L564-L572 |
|
8,005 | immersive-web/webvr-polyfill | examples/third_party/three.js/VREffect.js | getEyeMatrices | function getEyeMatrices( frameData ) {
// Compute the matrix for the position of the head based on the pose
if ( frameData.pose.orientation ) {
poseOrientation.fromArray( frameData.pose.orientation );
headMatrix.makeRotationFromQuaternion( poseOrientation );
} else {
headMatrix.identity();
}
if ( frameData.pose.position ) {
posePosition.fromArray( frameData.pose.position );
headMatrix.setPosition( posePosition );
}
// The view matrix transforms vertices from sitting space to eye space. As such, the view matrix can be thought of as a product of two matrices:
// headToEyeMatrix * sittingToHeadMatrix
// The headMatrix that we've calculated above is the model matrix of the head in sitting space, which is the inverse of sittingToHeadMatrix.
// So when we multiply the view matrix with headMatrix, we're left with headToEyeMatrix:
// viewMatrix * headMatrix = headToEyeMatrix * sittingToHeadMatrix * headMatrix = headToEyeMatrix
eyeMatrixL.fromArray( frameData.leftViewMatrix );
eyeMatrixL.multiply( headMatrix );
eyeMatrixR.fromArray( frameData.rightViewMatrix );
eyeMatrixR.multiply( headMatrix );
// The eye's model matrix in head space is the inverse of headToEyeMatrix we calculated above.
eyeMatrixL.getInverse( eyeMatrixL );
eyeMatrixR.getInverse( eyeMatrixR );
} | javascript | function getEyeMatrices( frameData ) {
// Compute the matrix for the position of the head based on the pose
if ( frameData.pose.orientation ) {
poseOrientation.fromArray( frameData.pose.orientation );
headMatrix.makeRotationFromQuaternion( poseOrientation );
} else {
headMatrix.identity();
}
if ( frameData.pose.position ) {
posePosition.fromArray( frameData.pose.position );
headMatrix.setPosition( posePosition );
}
// The view matrix transforms vertices from sitting space to eye space. As such, the view matrix can be thought of as a product of two matrices:
// headToEyeMatrix * sittingToHeadMatrix
// The headMatrix that we've calculated above is the model matrix of the head in sitting space, which is the inverse of sittingToHeadMatrix.
// So when we multiply the view matrix with headMatrix, we're left with headToEyeMatrix:
// viewMatrix * headMatrix = headToEyeMatrix * sittingToHeadMatrix * headMatrix = headToEyeMatrix
eyeMatrixL.fromArray( frameData.leftViewMatrix );
eyeMatrixL.multiply( headMatrix );
eyeMatrixR.fromArray( frameData.rightViewMatrix );
eyeMatrixR.multiply( headMatrix );
// The eye's model matrix in head space is the inverse of headToEyeMatrix we calculated above.
eyeMatrixL.getInverse( eyeMatrixL );
eyeMatrixR.getInverse( eyeMatrixR );
} | [
"function",
"getEyeMatrices",
"(",
"frameData",
")",
"{",
"// Compute the matrix for the position of the head based on the pose",
"if",
"(",
"frameData",
".",
"pose",
".",
"orientation",
")",
"{",
"poseOrientation",
".",
"fromArray",
"(",
"frameData",
".",
"pose",
".",
"orientation",
")",
";",
"headMatrix",
".",
"makeRotationFromQuaternion",
"(",
"poseOrientation",
")",
";",
"}",
"else",
"{",
"headMatrix",
".",
"identity",
"(",
")",
";",
"}",
"if",
"(",
"frameData",
".",
"pose",
".",
"position",
")",
"{",
"posePosition",
".",
"fromArray",
"(",
"frameData",
".",
"pose",
".",
"position",
")",
";",
"headMatrix",
".",
"setPosition",
"(",
"posePosition",
")",
";",
"}",
"// The view matrix transforms vertices from sitting space to eye space. As such, the view matrix can be thought of as a product of two matrices:",
"// headToEyeMatrix * sittingToHeadMatrix",
"// The headMatrix that we've calculated above is the model matrix of the head in sitting space, which is the inverse of sittingToHeadMatrix.",
"// So when we multiply the view matrix with headMatrix, we're left with headToEyeMatrix:",
"// viewMatrix * headMatrix = headToEyeMatrix * sittingToHeadMatrix * headMatrix = headToEyeMatrix",
"eyeMatrixL",
".",
"fromArray",
"(",
"frameData",
".",
"leftViewMatrix",
")",
";",
"eyeMatrixL",
".",
"multiply",
"(",
"headMatrix",
")",
";",
"eyeMatrixR",
".",
"fromArray",
"(",
"frameData",
".",
"rightViewMatrix",
")",
";",
"eyeMatrixR",
".",
"multiply",
"(",
"headMatrix",
")",
";",
"// The eye's model matrix in head space is the inverse of headToEyeMatrix we calculated above.",
"eyeMatrixL",
".",
"getInverse",
"(",
"eyeMatrixL",
")",
";",
"eyeMatrixR",
".",
"getInverse",
"(",
"eyeMatrixR",
")",
";",
"}"
] | Compute model matrices of the eyes with respect to the head. | [
"Compute",
"model",
"matrices",
"of",
"the",
"eyes",
"with",
"respect",
"to",
"the",
"head",
"."
] | ceb80d0e2d1d66e318782e30d89e0a09ca4857cd | https://github.com/immersive-web/webvr-polyfill/blob/ceb80d0e2d1d66e318782e30d89e0a09ca4857cd/examples/third_party/three.js/VREffect.js#L422-L460 |
8,006 | IdentityModel/oidc-client-js | jsrsasign/ext/rng.js | rng_seed_int | function rng_seed_int(x) {
rng_pool[rng_pptr++] ^= x & 255;
rng_pool[rng_pptr++] ^= (x >> 8) & 255;
rng_pool[rng_pptr++] ^= (x >> 16) & 255;
rng_pool[rng_pptr++] ^= (x >> 24) & 255;
if(rng_pptr >= rng_psize) rng_pptr -= rng_psize;
} | javascript | function rng_seed_int(x) {
rng_pool[rng_pptr++] ^= x & 255;
rng_pool[rng_pptr++] ^= (x >> 8) & 255;
rng_pool[rng_pptr++] ^= (x >> 16) & 255;
rng_pool[rng_pptr++] ^= (x >> 24) & 255;
if(rng_pptr >= rng_psize) rng_pptr -= rng_psize;
} | [
"function",
"rng_seed_int",
"(",
"x",
")",
"{",
"rng_pool",
"[",
"rng_pptr",
"++",
"]",
"^=",
"x",
"&",
"255",
";",
"rng_pool",
"[",
"rng_pptr",
"++",
"]",
"^=",
"(",
"x",
">>",
"8",
")",
"&",
"255",
";",
"rng_pool",
"[",
"rng_pptr",
"++",
"]",
"^=",
"(",
"x",
">>",
"16",
")",
"&",
"255",
";",
"rng_pool",
"[",
"rng_pptr",
"++",
"]",
"^=",
"(",
"x",
">>",
"24",
")",
"&",
"255",
";",
"if",
"(",
"rng_pptr",
">=",
"rng_psize",
")",
"rng_pptr",
"-=",
"rng_psize",
";",
"}"
] | Mix in a 32-bit integer into the pool | [
"Mix",
"in",
"a",
"32",
"-",
"bit",
"integer",
"into",
"the",
"pool"
] | 9adbe5627b82a84fe7b5a6cb0441e4cc1a624500 | https://github.com/IdentityModel/oidc-client-js/blob/9adbe5627b82a84fe7b5a6cb0441e4cc1a624500/jsrsasign/ext/rng.js#L14-L20 |
8,007 | IdentityModel/oidc-client-js | jsrsasign/ext/ec.js | curveFpDecodePointHex | function curveFpDecodePointHex(s) {
switch(parseInt(s.substr(0,2), 16)) { // first byte
case 0:
return this.infinity;
case 2:
case 3:
// point compression not supported yet
return null;
case 4:
case 6:
case 7:
var len = (s.length - 2) / 2;
var xHex = s.substr(2, len);
var yHex = s.substr(len+2, len);
return new ECPointFp(this,
this.fromBigInteger(new BigInteger(xHex, 16)),
this.fromBigInteger(new BigInteger(yHex, 16)));
default: // unsupported
return null;
}
} | javascript | function curveFpDecodePointHex(s) {
switch(parseInt(s.substr(0,2), 16)) { // first byte
case 0:
return this.infinity;
case 2:
case 3:
// point compression not supported yet
return null;
case 4:
case 6:
case 7:
var len = (s.length - 2) / 2;
var xHex = s.substr(2, len);
var yHex = s.substr(len+2, len);
return new ECPointFp(this,
this.fromBigInteger(new BigInteger(xHex, 16)),
this.fromBigInteger(new BigInteger(yHex, 16)));
default: // unsupported
return null;
}
} | [
"function",
"curveFpDecodePointHex",
"(",
"s",
")",
"{",
"switch",
"(",
"parseInt",
"(",
"s",
".",
"substr",
"(",
"0",
",",
"2",
")",
",",
"16",
")",
")",
"{",
"// first byte",
"case",
"0",
":",
"return",
"this",
".",
"infinity",
";",
"case",
"2",
":",
"case",
"3",
":",
"// point compression not supported yet",
"return",
"null",
";",
"case",
"4",
":",
"case",
"6",
":",
"case",
"7",
":",
"var",
"len",
"=",
"(",
"s",
".",
"length",
"-",
"2",
")",
"/",
"2",
";",
"var",
"xHex",
"=",
"s",
".",
"substr",
"(",
"2",
",",
"len",
")",
";",
"var",
"yHex",
"=",
"s",
".",
"substr",
"(",
"len",
"+",
"2",
",",
"len",
")",
";",
"return",
"new",
"ECPointFp",
"(",
"this",
",",
"this",
".",
"fromBigInteger",
"(",
"new",
"BigInteger",
"(",
"xHex",
",",
"16",
")",
")",
",",
"this",
".",
"fromBigInteger",
"(",
"new",
"BigInteger",
"(",
"yHex",
",",
"16",
")",
")",
")",
";",
"default",
":",
"// unsupported",
"return",
"null",
";",
"}",
"}"
] | for now, work with hex strings because they're easier in JS | [
"for",
"now",
"work",
"with",
"hex",
"strings",
"because",
"they",
"re",
"easier",
"in",
"JS"
] | 9adbe5627b82a84fe7b5a6cb0441e4cc1a624500 | https://github.com/IdentityModel/oidc-client-js/blob/9adbe5627b82a84fe7b5a6cb0441e4cc1a624500/jsrsasign/ext/ec.js#L288-L310 |
8,008 | IdentityModel/oidc-client-js | gulpfile.js | build_lib_sourcemap | function build_lib_sourcemap(){
// run webpack
return gulp.src('index.js').pipe(webpackStream(createWebpackConfig({
mode: 'development',
entry: npmEntry,
output: {
filename:'oidc-client.js',
libraryTarget:'umd',
// Workaround for https://github.com/webpack/webpack/issues/6642
globalObject: 'this'
},
plugins: [],
devtool:'inline-source-map'
}), webpack))
.pipe(gulp.dest('lib/'));
} | javascript | function build_lib_sourcemap(){
// run webpack
return gulp.src('index.js').pipe(webpackStream(createWebpackConfig({
mode: 'development',
entry: npmEntry,
output: {
filename:'oidc-client.js',
libraryTarget:'umd',
// Workaround for https://github.com/webpack/webpack/issues/6642
globalObject: 'this'
},
plugins: [],
devtool:'inline-source-map'
}), webpack))
.pipe(gulp.dest('lib/'));
} | [
"function",
"build_lib_sourcemap",
"(",
")",
"{",
"// run webpack",
"return",
"gulp",
".",
"src",
"(",
"'index.js'",
")",
".",
"pipe",
"(",
"webpackStream",
"(",
"createWebpackConfig",
"(",
"{",
"mode",
":",
"'development'",
",",
"entry",
":",
"npmEntry",
",",
"output",
":",
"{",
"filename",
":",
"'oidc-client.js'",
",",
"libraryTarget",
":",
"'umd'",
",",
"// Workaround for https://github.com/webpack/webpack/issues/6642",
"globalObject",
":",
"'this'",
"}",
",",
"plugins",
":",
"[",
"]",
",",
"devtool",
":",
"'inline-source-map'",
"}",
")",
",",
"webpack",
")",
")",
".",
"pipe",
"(",
"gulp",
".",
"dest",
"(",
"'lib/'",
")",
")",
";",
"}"
] | npm compliant build with source-maps | [
"npm",
"compliant",
"build",
"with",
"source",
"-",
"maps"
] | 9adbe5627b82a84fe7b5a6cb0441e4cc1a624500 | https://github.com/IdentityModel/oidc-client-js/blob/9adbe5627b82a84fe7b5a6cb0441e4cc1a624500/gulpfile.js#L13-L28 |
8,009 | IdentityModel/oidc-client-js | gulpfile.js | build_lib_min | function build_lib_min(){
// run webpack
return gulp.src('index.js').pipe(webpackStream(createWebpackConfig({
mode: 'production',
entry: npmEntry,
output: {
filename:'oidc-client.min.js',
libraryTarget:'umd',
// Workaround for https://github.com/webpack/webpack/issues/6642
globalObject: 'this'
},
plugins: [],
devtool: false,
optimization: {
minimizer: [
new UglifyJsPlugin({
uglifyOptions: {
keep_fnames: true
}
})
]
}
}), webpack))
.pipe(gulp.dest('lib/'));
} | javascript | function build_lib_min(){
// run webpack
return gulp.src('index.js').pipe(webpackStream(createWebpackConfig({
mode: 'production',
entry: npmEntry,
output: {
filename:'oidc-client.min.js',
libraryTarget:'umd',
// Workaround for https://github.com/webpack/webpack/issues/6642
globalObject: 'this'
},
plugins: [],
devtool: false,
optimization: {
minimizer: [
new UglifyJsPlugin({
uglifyOptions: {
keep_fnames: true
}
})
]
}
}), webpack))
.pipe(gulp.dest('lib/'));
} | [
"function",
"build_lib_min",
"(",
")",
"{",
"// run webpack",
"return",
"gulp",
".",
"src",
"(",
"'index.js'",
")",
".",
"pipe",
"(",
"webpackStream",
"(",
"createWebpackConfig",
"(",
"{",
"mode",
":",
"'production'",
",",
"entry",
":",
"npmEntry",
",",
"output",
":",
"{",
"filename",
":",
"'oidc-client.min.js'",
",",
"libraryTarget",
":",
"'umd'",
",",
"// Workaround for https://github.com/webpack/webpack/issues/6642",
"globalObject",
":",
"'this'",
"}",
",",
"plugins",
":",
"[",
"]",
",",
"devtool",
":",
"false",
",",
"optimization",
":",
"{",
"minimizer",
":",
"[",
"new",
"UglifyJsPlugin",
"(",
"{",
"uglifyOptions",
":",
"{",
"keep_fnames",
":",
"true",
"}",
"}",
")",
"]",
"}",
"}",
")",
",",
"webpack",
")",
")",
".",
"pipe",
"(",
"gulp",
".",
"dest",
"(",
"'lib/'",
")",
")",
";",
"}"
] | npm compliant build without source-maps & minified | [
"npm",
"compliant",
"build",
"without",
"source",
"-",
"maps",
"&",
"minified"
] | 9adbe5627b82a84fe7b5a6cb0441e4cc1a624500 | https://github.com/IdentityModel/oidc-client-js/blob/9adbe5627b82a84fe7b5a6cb0441e4cc1a624500/gulpfile.js#L31-L55 |
8,010 | IdentityModel/oidc-client-js | gulpfile.js | build_dist_sourcemap | function build_dist_sourcemap(){
// run webpack
return gulp.src('index.js').pipe(webpackStream(createWebpackConfig({
mode: 'development',
entry: classicEntry,
output: {
filename:'oidc-client.js',
libraryTarget:'var',
library:'Oidc'
},
plugins: [],
devtool:'inline-source-map'
}), webpack))
.pipe(gulp.dest('dist/'));
} | javascript | function build_dist_sourcemap(){
// run webpack
return gulp.src('index.js').pipe(webpackStream(createWebpackConfig({
mode: 'development',
entry: classicEntry,
output: {
filename:'oidc-client.js',
libraryTarget:'var',
library:'Oidc'
},
plugins: [],
devtool:'inline-source-map'
}), webpack))
.pipe(gulp.dest('dist/'));
} | [
"function",
"build_dist_sourcemap",
"(",
")",
"{",
"// run webpack",
"return",
"gulp",
".",
"src",
"(",
"'index.js'",
")",
".",
"pipe",
"(",
"webpackStream",
"(",
"createWebpackConfig",
"(",
"{",
"mode",
":",
"'development'",
",",
"entry",
":",
"classicEntry",
",",
"output",
":",
"{",
"filename",
":",
"'oidc-client.js'",
",",
"libraryTarget",
":",
"'var'",
",",
"library",
":",
"'Oidc'",
"}",
",",
"plugins",
":",
"[",
"]",
",",
"devtool",
":",
"'inline-source-map'",
"}",
")",
",",
"webpack",
")",
")",
".",
"pipe",
"(",
"gulp",
".",
"dest",
"(",
"'dist/'",
")",
")",
";",
"}"
] | classic build with sourcemaps | [
"classic",
"build",
"with",
"sourcemaps"
] | 9adbe5627b82a84fe7b5a6cb0441e4cc1a624500 | https://github.com/IdentityModel/oidc-client-js/blob/9adbe5627b82a84fe7b5a6cb0441e4cc1a624500/gulpfile.js#L58-L72 |
8,011 | IdentityModel/oidc-client-js | gulpfile.js | build_dist_min | function build_dist_min(){
// run webpack
return gulp.src('index.js').pipe(webpackStream(createWebpackConfig({
mode: 'production',
entry: classicEntry,
output: {
filename:'oidc-client.min.js',
libraryTarget:'var',
library:'Oidc'
},
plugins: [],
devtool: false,
optimization: {
minimizer: [
new UglifyJsPlugin({
uglifyOptions: {
keep_fnames: true
}
})
]
}
}), webpack))
.pipe(gulp.dest('dist/'));
} | javascript | function build_dist_min(){
// run webpack
return gulp.src('index.js').pipe(webpackStream(createWebpackConfig({
mode: 'production',
entry: classicEntry,
output: {
filename:'oidc-client.min.js',
libraryTarget:'var',
library:'Oidc'
},
plugins: [],
devtool: false,
optimization: {
minimizer: [
new UglifyJsPlugin({
uglifyOptions: {
keep_fnames: true
}
})
]
}
}), webpack))
.pipe(gulp.dest('dist/'));
} | [
"function",
"build_dist_min",
"(",
")",
"{",
"// run webpack",
"return",
"gulp",
".",
"src",
"(",
"'index.js'",
")",
".",
"pipe",
"(",
"webpackStream",
"(",
"createWebpackConfig",
"(",
"{",
"mode",
":",
"'production'",
",",
"entry",
":",
"classicEntry",
",",
"output",
":",
"{",
"filename",
":",
"'oidc-client.min.js'",
",",
"libraryTarget",
":",
"'var'",
",",
"library",
":",
"'Oidc'",
"}",
",",
"plugins",
":",
"[",
"]",
",",
"devtool",
":",
"false",
",",
"optimization",
":",
"{",
"minimizer",
":",
"[",
"new",
"UglifyJsPlugin",
"(",
"{",
"uglifyOptions",
":",
"{",
"keep_fnames",
":",
"true",
"}",
"}",
")",
"]",
"}",
"}",
")",
",",
"webpack",
")",
")",
".",
"pipe",
"(",
"gulp",
".",
"dest",
"(",
"'dist/'",
")",
")",
";",
"}"
] | classic build without sourcemaps & minified | [
"classic",
"build",
"without",
"sourcemaps",
"&",
"minified"
] | 9adbe5627b82a84fe7b5a6cb0441e4cc1a624500 | https://github.com/IdentityModel/oidc-client-js/blob/9adbe5627b82a84fe7b5a6cb0441e4cc1a624500/gulpfile.js#L75-L98 |
8,012 | overtrue/share.js | src/js/social-share.js | share | function share(elem, options) {
var data = mixin({}, defaults, options || {}, dataset(elem));
if (data.imageSelector) {
data.image = querySelectorAlls(data.imageSelector).map(function(item) {
return item.src;
}).join('||');
}
addClass(elem, 'share-component social-share');
createIcons(elem, data);
createWechat(elem, data);
elem.initialized = true;
} | javascript | function share(elem, options) {
var data = mixin({}, defaults, options || {}, dataset(elem));
if (data.imageSelector) {
data.image = querySelectorAlls(data.imageSelector).map(function(item) {
return item.src;
}).join('||');
}
addClass(elem, 'share-component social-share');
createIcons(elem, data);
createWechat(elem, data);
elem.initialized = true;
} | [
"function",
"share",
"(",
"elem",
",",
"options",
")",
"{",
"var",
"data",
"=",
"mixin",
"(",
"{",
"}",
",",
"defaults",
",",
"options",
"||",
"{",
"}",
",",
"dataset",
"(",
"elem",
")",
")",
";",
"if",
"(",
"data",
".",
"imageSelector",
")",
"{",
"data",
".",
"image",
"=",
"querySelectorAlls",
"(",
"data",
".",
"imageSelector",
")",
".",
"map",
"(",
"function",
"(",
"item",
")",
"{",
"return",
"item",
".",
"src",
";",
"}",
")",
".",
"join",
"(",
"'||'",
")",
";",
"}",
"addClass",
"(",
"elem",
",",
"'share-component social-share'",
")",
";",
"createIcons",
"(",
"elem",
",",
"data",
")",
";",
"createWechat",
"(",
"elem",
",",
"data",
")",
";",
"elem",
".",
"initialized",
"=",
"true",
";",
"}"
] | Initialize a share bar.
@param {Object} $options globals (optional).
@return {Void} | [
"Initialize",
"a",
"share",
"bar",
"."
] | ddc699dfabf56b41f11865b6195dda05614f1e2a | https://github.com/overtrue/share.js/blob/ddc699dfabf56b41f11865b6195dda05614f1e2a/src/js/social-share.js#L101-L115 |
8,013 | overtrue/share.js | src/js/social-share.js | makeUrl | function makeUrl(name, data) {
if (! data['summary']){
data['summary'] = data['description'];
}
return templates[name].replace(/\{\{(\w)(\w*)\}\}/g, function (m, fix, key) {
var nameKey = name + fix + key.toLowerCase();
key = (fix + key).toLowerCase();
return encodeURIComponent((data[nameKey] === undefined ? data[key] : data[nameKey]) || '');
});
} | javascript | function makeUrl(name, data) {
if (! data['summary']){
data['summary'] = data['description'];
}
return templates[name].replace(/\{\{(\w)(\w*)\}\}/g, function (m, fix, key) {
var nameKey = name + fix + key.toLowerCase();
key = (fix + key).toLowerCase();
return encodeURIComponent((data[nameKey] === undefined ? data[key] : data[nameKey]) || '');
});
} | [
"function",
"makeUrl",
"(",
"name",
",",
"data",
")",
"{",
"if",
"(",
"!",
"data",
"[",
"'summary'",
"]",
")",
"{",
"data",
"[",
"'summary'",
"]",
"=",
"data",
"[",
"'description'",
"]",
";",
"}",
"return",
"templates",
"[",
"name",
"]",
".",
"replace",
"(",
"/",
"\\{\\{(\\w)(\\w*)\\}\\}",
"/",
"g",
",",
"function",
"(",
"m",
",",
"fix",
",",
"key",
")",
"{",
"var",
"nameKey",
"=",
"name",
"+",
"fix",
"+",
"key",
".",
"toLowerCase",
"(",
")",
";",
"key",
"=",
"(",
"fix",
"+",
"key",
")",
".",
"toLowerCase",
"(",
")",
";",
"return",
"encodeURIComponent",
"(",
"(",
"data",
"[",
"nameKey",
"]",
"===",
"undefined",
"?",
"data",
"[",
"key",
"]",
":",
"data",
"[",
"nameKey",
"]",
")",
"||",
"''",
")",
";",
"}",
")",
";",
"}"
] | Build the url of icon.
@param {String} name
@param {Object} data
@returns {String} | [
"Build",
"the",
"url",
"of",
"icon",
"."
] | ddc699dfabf56b41f11865b6195dda05614f1e2a | https://github.com/overtrue/share.js/blob/ddc699dfabf56b41f11865b6195dda05614f1e2a/src/js/social-share.js#L215-L227 |
8,014 | overtrue/share.js | src/js/social-share.js | querySelectorAlls | function querySelectorAlls(str) {
return (document.querySelectorAll || window.jQuery || window.Zepto || selector).call(document, str);
} | javascript | function querySelectorAlls(str) {
return (document.querySelectorAll || window.jQuery || window.Zepto || selector).call(document, str);
} | [
"function",
"querySelectorAlls",
"(",
"str",
")",
"{",
"return",
"(",
"document",
".",
"querySelectorAll",
"||",
"window",
".",
"jQuery",
"||",
"window",
".",
"Zepto",
"||",
"selector",
")",
".",
"call",
"(",
"document",
",",
"str",
")",
";",
"}"
] | Supports querySelectorAll, jQuery, Zepto and simple selector.
@param str
@returns {*} | [
"Supports",
"querySelectorAll",
"jQuery",
"Zepto",
"and",
"simple",
"selector",
"."
] | ddc699dfabf56b41f11865b6195dda05614f1e2a | https://github.com/overtrue/share.js/blob/ddc699dfabf56b41f11865b6195dda05614f1e2a/src/js/social-share.js#L237-L239 |
8,015 | overtrue/share.js | src/js/social-share.js | selector | function selector(str) {
var elems = [];
each(str.split(/\s*,\s*/), function(s) {
var m = s.match(/([#.])(\w+)/);
if (m === null) {
throw Error('Supports only simple single #ID or .CLASS selector.');
}
if (m[1]) {
var elem = document.getElementById(m[2]);
if (elem) {
elems.push(elem);
}
}
elems = elems.concat(getElementsByClassName(str));
});
return elems;
} | javascript | function selector(str) {
var elems = [];
each(str.split(/\s*,\s*/), function(s) {
var m = s.match(/([#.])(\w+)/);
if (m === null) {
throw Error('Supports only simple single #ID or .CLASS selector.');
}
if (m[1]) {
var elem = document.getElementById(m[2]);
if (elem) {
elems.push(elem);
}
}
elems = elems.concat(getElementsByClassName(str));
});
return elems;
} | [
"function",
"selector",
"(",
"str",
")",
"{",
"var",
"elems",
"=",
"[",
"]",
";",
"each",
"(",
"str",
".",
"split",
"(",
"/",
"\\s*,\\s*",
"/",
")",
",",
"function",
"(",
"s",
")",
"{",
"var",
"m",
"=",
"s",
".",
"match",
"(",
"/",
"([#.])(\\w+)",
"/",
")",
";",
"if",
"(",
"m",
"===",
"null",
")",
"{",
"throw",
"Error",
"(",
"'Supports only simple single #ID or .CLASS selector.'",
")",
";",
"}",
"if",
"(",
"m",
"[",
"1",
"]",
")",
"{",
"var",
"elem",
"=",
"document",
".",
"getElementById",
"(",
"m",
"[",
"2",
"]",
")",
";",
"if",
"(",
"elem",
")",
"{",
"elems",
".",
"push",
"(",
"elem",
")",
";",
"}",
"}",
"elems",
"=",
"elems",
".",
"concat",
"(",
"getElementsByClassName",
"(",
"str",
")",
")",
";",
"}",
")",
";",
"return",
"elems",
";",
"}"
] | Simple selector.
@param {String} str #ID or .CLASS
@returns {Array} | [
"Simple",
"selector",
"."
] | ddc699dfabf56b41f11865b6195dda05614f1e2a | https://github.com/overtrue/share.js/blob/ddc699dfabf56b41f11865b6195dda05614f1e2a/src/js/social-share.js#L249-L270 |
8,016 | overtrue/share.js | src/js/social-share.js | addClass | function addClass(elem, value) {
if (value && typeof value === "string") {
var classNames = (elem.className + ' ' + value).split(/\s+/);
var setClass = ' ';
each(classNames, function (className) {
if (setClass.indexOf(' ' + className + ' ') < 0) {
setClass += className + ' ';
}
});
elem.className = setClass.slice(1, -1);
}
} | javascript | function addClass(elem, value) {
if (value && typeof value === "string") {
var classNames = (elem.className + ' ' + value).split(/\s+/);
var setClass = ' ';
each(classNames, function (className) {
if (setClass.indexOf(' ' + className + ' ') < 0) {
setClass += className + ' ';
}
});
elem.className = setClass.slice(1, -1);
}
} | [
"function",
"addClass",
"(",
"elem",
",",
"value",
")",
"{",
"if",
"(",
"value",
"&&",
"typeof",
"value",
"===",
"\"string\"",
")",
"{",
"var",
"classNames",
"=",
"(",
"elem",
".",
"className",
"+",
"' '",
"+",
"value",
")",
".",
"split",
"(",
"/",
"\\s+",
"/",
")",
";",
"var",
"setClass",
"=",
"' '",
";",
"each",
"(",
"classNames",
",",
"function",
"(",
"className",
")",
"{",
"if",
"(",
"setClass",
".",
"indexOf",
"(",
"' '",
"+",
"className",
"+",
"' '",
")",
"<",
"0",
")",
"{",
"setClass",
"+=",
"className",
"+",
"' '",
";",
"}",
"}",
")",
";",
"elem",
".",
"className",
"=",
"setClass",
".",
"slice",
"(",
"1",
",",
"-",
"1",
")",
";",
"}",
"}"
] | Add the classNames for element.
@param {Element} elem
@param {String} value | [
"Add",
"the",
"classNames",
"for",
"element",
"."
] | ddc699dfabf56b41f11865b6195dda05614f1e2a | https://github.com/overtrue/share.js/blob/ddc699dfabf56b41f11865b6195dda05614f1e2a/src/js/social-share.js#L279-L292 |
8,017 | overtrue/share.js | src/js/social-share.js | getElementsByClassName | function getElementsByClassName(elem, name, tag) {
if (elem.getElementsByClassName) {
return elem.getElementsByClassName(name);
}
var elements = [];
var elems = elem.getElementsByTagName(tag || '*');
name = ' ' + name + ' ';
each(elems, function (elem) {
if ((' ' + (elem.className || '') + ' ').indexOf(name) >= 0) {
elements.push(elem);
}
});
return elements;
} | javascript | function getElementsByClassName(elem, name, tag) {
if (elem.getElementsByClassName) {
return elem.getElementsByClassName(name);
}
var elements = [];
var elems = elem.getElementsByTagName(tag || '*');
name = ' ' + name + ' ';
each(elems, function (elem) {
if ((' ' + (elem.className || '') + ' ').indexOf(name) >= 0) {
elements.push(elem);
}
});
return elements;
} | [
"function",
"getElementsByClassName",
"(",
"elem",
",",
"name",
",",
"tag",
")",
"{",
"if",
"(",
"elem",
".",
"getElementsByClassName",
")",
"{",
"return",
"elem",
".",
"getElementsByClassName",
"(",
"name",
")",
";",
"}",
"var",
"elements",
"=",
"[",
"]",
";",
"var",
"elems",
"=",
"elem",
".",
"getElementsByTagName",
"(",
"tag",
"||",
"'*'",
")",
";",
"name",
"=",
"' '",
"+",
"name",
"+",
"' '",
";",
"each",
"(",
"elems",
",",
"function",
"(",
"elem",
")",
"{",
"if",
"(",
"(",
"' '",
"+",
"(",
"elem",
".",
"className",
"||",
"''",
")",
"+",
"' '",
")",
".",
"indexOf",
"(",
"name",
")",
">=",
"0",
")",
"{",
"elements",
".",
"push",
"(",
"elem",
")",
";",
"}",
"}",
")",
";",
"return",
"elements",
";",
"}"
] | Get elements By className for IE8-
@param {Element} elem element
@param {String} name className
@param {String} tag tagName
@returns {HTMLCollection|Array} | [
"Get",
"elements",
"By",
"className",
"for",
"IE8",
"-"
] | ddc699dfabf56b41f11865b6195dda05614f1e2a | https://github.com/overtrue/share.js/blob/ddc699dfabf56b41f11865b6195dda05614f1e2a/src/js/social-share.js#L316-L332 |
8,018 | overtrue/share.js | src/js/social-share.js | createElementByString | function createElementByString(str) {
var div = document.createElement('div');
div.innerHTML = str;
return div.childNodes;
} | javascript | function createElementByString(str) {
var div = document.createElement('div');
div.innerHTML = str;
return div.childNodes;
} | [
"function",
"createElementByString",
"(",
"str",
")",
"{",
"var",
"div",
"=",
"document",
".",
"createElement",
"(",
"'div'",
")",
";",
"div",
".",
"innerHTML",
"=",
"str",
";",
"return",
"div",
".",
"childNodes",
";",
"}"
] | Create element by string.
@param {String} str
@returns {NodeList} | [
"Create",
"element",
"by",
"string",
"."
] | ddc699dfabf56b41f11865b6195dda05614f1e2a | https://github.com/overtrue/share.js/blob/ddc699dfabf56b41f11865b6195dda05614f1e2a/src/js/social-share.js#L342-L347 |
8,019 | overtrue/share.js | src/js/social-share.js | mixin | function mixin() {
var args = arguments;
if (Object$assign) {
return Object$assign.apply(null, args);
}
var target = {};
each(args, function (it) {
each(it, function (v, k) {
target[k] = v;
});
});
return args[0] = target;
} | javascript | function mixin() {
var args = arguments;
if (Object$assign) {
return Object$assign.apply(null, args);
}
var target = {};
each(args, function (it) {
each(it, function (v, k) {
target[k] = v;
});
});
return args[0] = target;
} | [
"function",
"mixin",
"(",
")",
"{",
"var",
"args",
"=",
"arguments",
";",
"if",
"(",
"Object$assign",
")",
"{",
"return",
"Object$assign",
".",
"apply",
"(",
"null",
",",
"args",
")",
";",
"}",
"var",
"target",
"=",
"{",
"}",
";",
"each",
"(",
"args",
",",
"function",
"(",
"it",
")",
"{",
"each",
"(",
"it",
",",
"function",
"(",
"v",
",",
"k",
")",
"{",
"target",
"[",
"k",
"]",
"=",
"v",
";",
"}",
")",
";",
"}",
")",
";",
"return",
"args",
"[",
"0",
"]",
"=",
"target",
";",
"}"
] | Merge objects.
@returns {Object} | [
"Merge",
"objects",
"."
] | ddc699dfabf56b41f11865b6195dda05614f1e2a | https://github.com/overtrue/share.js/blob/ddc699dfabf56b41f11865b6195dda05614f1e2a/src/js/social-share.js#L355-L371 |
8,020 | overtrue/share.js | src/js/social-share.js | dataset | function dataset(elem) {
if (elem.dataset) {
return JSON.parse(JSON.stringify(elem.dataset));
}
var target = {};
if (elem.hasAttributes()) {
each(elem.attributes, function (attr) {
var name = attr.name;
if (name.indexOf('data-') !== 0) {
return true;
}
name = name.replace(/^data-/i, '')
.replace(/-(\w)/g, function (all, letter) {
return letter.toUpperCase();
});
target[name] = attr.value;
});
return target;
}
return {};
} | javascript | function dataset(elem) {
if (elem.dataset) {
return JSON.parse(JSON.stringify(elem.dataset));
}
var target = {};
if (elem.hasAttributes()) {
each(elem.attributes, function (attr) {
var name = attr.name;
if (name.indexOf('data-') !== 0) {
return true;
}
name = name.replace(/^data-/i, '')
.replace(/-(\w)/g, function (all, letter) {
return letter.toUpperCase();
});
target[name] = attr.value;
});
return target;
}
return {};
} | [
"function",
"dataset",
"(",
"elem",
")",
"{",
"if",
"(",
"elem",
".",
"dataset",
")",
"{",
"return",
"JSON",
".",
"parse",
"(",
"JSON",
".",
"stringify",
"(",
"elem",
".",
"dataset",
")",
")",
";",
"}",
"var",
"target",
"=",
"{",
"}",
";",
"if",
"(",
"elem",
".",
"hasAttributes",
"(",
")",
")",
"{",
"each",
"(",
"elem",
".",
"attributes",
",",
"function",
"(",
"attr",
")",
"{",
"var",
"name",
"=",
"attr",
".",
"name",
";",
"if",
"(",
"name",
".",
"indexOf",
"(",
"'data-'",
")",
"!==",
"0",
")",
"{",
"return",
"true",
";",
"}",
"name",
"=",
"name",
".",
"replace",
"(",
"/",
"^data-",
"/",
"i",
",",
"''",
")",
".",
"replace",
"(",
"/",
"-(\\w)",
"/",
"g",
",",
"function",
"(",
"all",
",",
"letter",
")",
"{",
"return",
"letter",
".",
"toUpperCase",
"(",
")",
";",
"}",
")",
";",
"target",
"[",
"name",
"]",
"=",
"attr",
".",
"value",
";",
"}",
")",
";",
"return",
"target",
";",
"}",
"return",
"{",
"}",
";",
"}"
] | Get dataset object.
@param {Element} elem
@returns {Object} | [
"Get",
"dataset",
"object",
"."
] | ddc699dfabf56b41f11865b6195dda05614f1e2a | https://github.com/overtrue/share.js/blob/ddc699dfabf56b41f11865b6195dda05614f1e2a/src/js/social-share.js#L381-L407 |
8,021 | overtrue/share.js | src/js/social-share.js | inArray | function inArray(elem, arr, i) {
var len;
if (arr) {
if (Array$indexOf) {
return Array$indexOf.call(arr, elem, i);
}
len = arr.length;
i = i ? i < 0 ? Math.max(0, len + i) : i : 0;
for (; i < len; i++) {
// Skip accessing in sparse arrays
if (i in arr && arr[i] === elem) {
return i;
}
}
}
return -1;
} | javascript | function inArray(elem, arr, i) {
var len;
if (arr) {
if (Array$indexOf) {
return Array$indexOf.call(arr, elem, i);
}
len = arr.length;
i = i ? i < 0 ? Math.max(0, len + i) : i : 0;
for (; i < len; i++) {
// Skip accessing in sparse arrays
if (i in arr && arr[i] === elem) {
return i;
}
}
}
return -1;
} | [
"function",
"inArray",
"(",
"elem",
",",
"arr",
",",
"i",
")",
"{",
"var",
"len",
";",
"if",
"(",
"arr",
")",
"{",
"if",
"(",
"Array$indexOf",
")",
"{",
"return",
"Array$indexOf",
".",
"call",
"(",
"arr",
",",
"elem",
",",
"i",
")",
";",
"}",
"len",
"=",
"arr",
".",
"length",
";",
"i",
"=",
"i",
"?",
"i",
"<",
"0",
"?",
"Math",
".",
"max",
"(",
"0",
",",
"len",
"+",
"i",
")",
":",
"i",
":",
"0",
";",
"for",
"(",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"// Skip accessing in sparse arrays",
"if",
"(",
"i",
"in",
"arr",
"&&",
"arr",
"[",
"i",
"]",
"===",
"elem",
")",
"{",
"return",
"i",
";",
"}",
"}",
"}",
"return",
"-",
"1",
";",
"}"
] | found element in the array.
@param {Array|Object} elem
@param {Array} arr
@param {Number} i
@returns {Number} | [
"found",
"element",
"in",
"the",
"array",
"."
] | ddc699dfabf56b41f11865b6195dda05614f1e2a | https://github.com/overtrue/share.js/blob/ddc699dfabf56b41f11865b6195dda05614f1e2a/src/js/social-share.js#L419-L439 |
8,022 | overtrue/share.js | src/js/social-share.js | each | function each(obj, callback) {
var length = obj.length;
if (length === undefined) {
for (var name in obj) {
if (obj.hasOwnProperty(name)) {
if (callback.call(obj[name], obj[name], name) === false) {
break;
}
}
}
} else {
for (var i = 0; i < length; i++) {
if (callback.call(obj[i], obj[i], i) === false) {
break;
}
}
}
} | javascript | function each(obj, callback) {
var length = obj.length;
if (length === undefined) {
for (var name in obj) {
if (obj.hasOwnProperty(name)) {
if (callback.call(obj[name], obj[name], name) === false) {
break;
}
}
}
} else {
for (var i = 0; i < length; i++) {
if (callback.call(obj[i], obj[i], i) === false) {
break;
}
}
}
} | [
"function",
"each",
"(",
"obj",
",",
"callback",
")",
"{",
"var",
"length",
"=",
"obj",
".",
"length",
";",
"if",
"(",
"length",
"===",
"undefined",
")",
"{",
"for",
"(",
"var",
"name",
"in",
"obj",
")",
"{",
"if",
"(",
"obj",
".",
"hasOwnProperty",
"(",
"name",
")",
")",
"{",
"if",
"(",
"callback",
".",
"call",
"(",
"obj",
"[",
"name",
"]",
",",
"obj",
"[",
"name",
"]",
",",
"name",
")",
"===",
"false",
")",
"{",
"break",
";",
"}",
"}",
"}",
"}",
"else",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"callback",
".",
"call",
"(",
"obj",
"[",
"i",
"]",
",",
"obj",
"[",
"i",
"]",
",",
"i",
")",
"===",
"false",
")",
"{",
"break",
";",
"}",
"}",
"}",
"}"
] | Simple each.
@param {Array|Object} obj
@param {Function} callback
@returns {*} | [
"Simple",
"each",
"."
] | ddc699dfabf56b41f11865b6195dda05614f1e2a | https://github.com/overtrue/share.js/blob/ddc699dfabf56b41f11865b6195dda05614f1e2a/src/js/social-share.js#L450-L468 |
8,023 | overtrue/share.js | src/js/social-share.js | alReady | function alReady ( fn ) {
var add = 'addEventListener';
var pre = document[ add ] ? '' : 'on';
~document.readyState.indexOf( 'm' ) ? fn() :
'load DOMContentLoaded readystatechange'.replace( /\w+/g, function( type, i ) {
( i ? document : window )
[ pre ? 'attachEvent' : add ]
(
pre + type,
function(){ if ( fn ) if ( i < 6 || ~document.readyState.indexOf( 'm' ) ) fn(), fn = 0 },
!1
)
})
} | javascript | function alReady ( fn ) {
var add = 'addEventListener';
var pre = document[ add ] ? '' : 'on';
~document.readyState.indexOf( 'm' ) ? fn() :
'load DOMContentLoaded readystatechange'.replace( /\w+/g, function( type, i ) {
( i ? document : window )
[ pre ? 'attachEvent' : add ]
(
pre + type,
function(){ if ( fn ) if ( i < 6 || ~document.readyState.indexOf( 'm' ) ) fn(), fn = 0 },
!1
)
})
} | [
"function",
"alReady",
"(",
"fn",
")",
"{",
"var",
"add",
"=",
"'addEventListener'",
";",
"var",
"pre",
"=",
"document",
"[",
"add",
"]",
"?",
"''",
":",
"'on'",
";",
"~",
"document",
".",
"readyState",
".",
"indexOf",
"(",
"'m'",
")",
"?",
"fn",
"(",
")",
":",
"'load DOMContentLoaded readystatechange'",
".",
"replace",
"(",
"/",
"\\w+",
"/",
"g",
",",
"function",
"(",
"type",
",",
"i",
")",
"{",
"(",
"i",
"?",
"document",
":",
"window",
")",
"[",
"pre",
"?",
"'attachEvent'",
":",
"add",
"]",
"(",
"pre",
"+",
"type",
",",
"function",
"(",
")",
"{",
"if",
"(",
"fn",
")",
"if",
"(",
"i",
"<",
"6",
"||",
"~",
"document",
".",
"readyState",
".",
"indexOf",
"(",
"'m'",
")",
")",
"fn",
"(",
")",
",",
"fn",
"=",
"0",
"}",
",",
"!",
"1",
")",
"}",
")",
"}"
] | Dom ready.
@param {Function} fn
@link https://github.com/jed/alReady.js | [
"Dom",
"ready",
"."
] | ddc699dfabf56b41f11865b6195dda05614f1e2a | https://github.com/overtrue/share.js/blob/ddc699dfabf56b41f11865b6195dda05614f1e2a/src/js/social-share.js#L478-L492 |
8,024 | overtrue/share.js | src/js/qrcode.js | _getAndroid | function _getAndroid() {
var android = false;
var sAgent = navigator.userAgent;
if (/android/i.test(sAgent)) { // android
android = true;
var aMat = sAgent.toString().match(/android ([0-9]\.[0-9])/i);
if (aMat && aMat[1]) {
android = parseFloat(aMat[1]);
}
}
return android;
} | javascript | function _getAndroid() {
var android = false;
var sAgent = navigator.userAgent;
if (/android/i.test(sAgent)) { // android
android = true;
var aMat = sAgent.toString().match(/android ([0-9]\.[0-9])/i);
if (aMat && aMat[1]) {
android = parseFloat(aMat[1]);
}
}
return android;
} | [
"function",
"_getAndroid",
"(",
")",
"{",
"var",
"android",
"=",
"false",
";",
"var",
"sAgent",
"=",
"navigator",
".",
"userAgent",
";",
"if",
"(",
"/",
"android",
"/",
"i",
".",
"test",
"(",
"sAgent",
")",
")",
"{",
"// android",
"android",
"=",
"true",
";",
"var",
"aMat",
"=",
"sAgent",
".",
"toString",
"(",
")",
".",
"match",
"(",
"/",
"android ([0-9]\\.[0-9])",
"/",
"i",
")",
";",
"if",
"(",
"aMat",
"&&",
"aMat",
"[",
"1",
"]",
")",
"{",
"android",
"=",
"parseFloat",
"(",
"aMat",
"[",
"1",
"]",
")",
";",
"}",
"}",
"return",
"android",
";",
"}"
] | android 2.x doesn't support Data-URI spec | [
"android",
"2",
".",
"x",
"doesn",
"t",
"support",
"Data",
"-",
"URI",
"spec"
] | ddc699dfabf56b41f11865b6195dda05614f1e2a | https://github.com/overtrue/share.js/blob/ddc699dfabf56b41f11865b6195dda05614f1e2a/src/js/qrcode.js#L159-L173 |
8,025 | overtrue/share.js | src/js/qrcode.js | _safeSetDataURI | function _safeSetDataURI(fSuccess, fFail) {
var self = this;
self._fFail = fFail;
self._fSuccess = fSuccess;
// Check it just once
if (self._bSupportDataURI === null) {
var el = document.createElement("img");
var fOnError = function() {
self._bSupportDataURI = false;
if (self._fFail) {
self._fFail.call(self);
}
};
var fOnSuccess = function() {
self._bSupportDataURI = true;
if (self._fSuccess) {
self._fSuccess.call(self);
}
};
el.onabort = fOnError;
el.onerror = fOnError;
el.onload = fOnSuccess;
el.src = "data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="; // the Image contains 1px data.
return;
} else if (self._bSupportDataURI === true && self._fSuccess) {
self._fSuccess.call(self);
} else if (self._bSupportDataURI === false && self._fFail) {
self._fFail.call(self);
}
} | javascript | function _safeSetDataURI(fSuccess, fFail) {
var self = this;
self._fFail = fFail;
self._fSuccess = fSuccess;
// Check it just once
if (self._bSupportDataURI === null) {
var el = document.createElement("img");
var fOnError = function() {
self._bSupportDataURI = false;
if (self._fFail) {
self._fFail.call(self);
}
};
var fOnSuccess = function() {
self._bSupportDataURI = true;
if (self._fSuccess) {
self._fSuccess.call(self);
}
};
el.onabort = fOnError;
el.onerror = fOnError;
el.onload = fOnSuccess;
el.src = "data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="; // the Image contains 1px data.
return;
} else if (self._bSupportDataURI === true && self._fSuccess) {
self._fSuccess.call(self);
} else if (self._bSupportDataURI === false && self._fFail) {
self._fFail.call(self);
}
} | [
"function",
"_safeSetDataURI",
"(",
"fSuccess",
",",
"fFail",
")",
"{",
"var",
"self",
"=",
"this",
";",
"self",
".",
"_fFail",
"=",
"fFail",
";",
"self",
".",
"_fSuccess",
"=",
"fSuccess",
";",
"// Check it just once",
"if",
"(",
"self",
".",
"_bSupportDataURI",
"===",
"null",
")",
"{",
"var",
"el",
"=",
"document",
".",
"createElement",
"(",
"\"img\"",
")",
";",
"var",
"fOnError",
"=",
"function",
"(",
")",
"{",
"self",
".",
"_bSupportDataURI",
"=",
"false",
";",
"if",
"(",
"self",
".",
"_fFail",
")",
"{",
"self",
".",
"_fFail",
".",
"call",
"(",
"self",
")",
";",
"}",
"}",
";",
"var",
"fOnSuccess",
"=",
"function",
"(",
")",
"{",
"self",
".",
"_bSupportDataURI",
"=",
"true",
";",
"if",
"(",
"self",
".",
"_fSuccess",
")",
"{",
"self",
".",
"_fSuccess",
".",
"call",
"(",
"self",
")",
";",
"}",
"}",
";",
"el",
".",
"onabort",
"=",
"fOnError",
";",
"el",
".",
"onerror",
"=",
"fOnError",
";",
"el",
".",
"onload",
"=",
"fOnSuccess",
";",
"el",
".",
"src",
"=",
"\"data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==\"",
";",
"// the Image contains 1px data.",
"return",
";",
"}",
"else",
"if",
"(",
"self",
".",
"_bSupportDataURI",
"===",
"true",
"&&",
"self",
".",
"_fSuccess",
")",
"{",
"self",
".",
"_fSuccess",
".",
"call",
"(",
"self",
")",
";",
"}",
"else",
"if",
"(",
"self",
".",
"_bSupportDataURI",
"===",
"false",
"&&",
"self",
".",
"_fFail",
")",
"{",
"self",
".",
"_fFail",
".",
"call",
"(",
"self",
")",
";",
"}",
"}"
] | Check whether the user's browser supports Data URI or not
@private
@param {Function} fSuccess Occurs if it supports Data URI
@param {Function} fFail Occurs if it doesn't support Data URI | [
"Check",
"whether",
"the",
"user",
"s",
"browser",
"supports",
"Data",
"URI",
"or",
"not"
] | ddc699dfabf56b41f11865b6195dda05614f1e2a | https://github.com/overtrue/share.js/blob/ddc699dfabf56b41f11865b6195dda05614f1e2a/src/js/qrcode.js#L310-L343 |
8,026 | overtrue/share.js | src/js/qrcode.js | function (el, htOption) {
this._bIsPainted = false;
this._android = _getAndroid();
this._htOption = htOption;
this._elCanvas = document.createElement("canvas");
this._elCanvas.width = htOption.width;
this._elCanvas.height = htOption.height;
el.appendChild(this._elCanvas);
this._el = el;
this._oContext = this._elCanvas.getContext("2d");
this._bIsPainted = false;
this._elImage = document.createElement("img");
this._elImage.alt = "Scan me!";
this._elImage.style.display = "none";
this._el.appendChild(this._elImage);
this._bSupportDataURI = null;
} | javascript | function (el, htOption) {
this._bIsPainted = false;
this._android = _getAndroid();
this._htOption = htOption;
this._elCanvas = document.createElement("canvas");
this._elCanvas.width = htOption.width;
this._elCanvas.height = htOption.height;
el.appendChild(this._elCanvas);
this._el = el;
this._oContext = this._elCanvas.getContext("2d");
this._bIsPainted = false;
this._elImage = document.createElement("img");
this._elImage.alt = "Scan me!";
this._elImage.style.display = "none";
this._el.appendChild(this._elImage);
this._bSupportDataURI = null;
} | [
"function",
"(",
"el",
",",
"htOption",
")",
"{",
"this",
".",
"_bIsPainted",
"=",
"false",
";",
"this",
".",
"_android",
"=",
"_getAndroid",
"(",
")",
";",
"this",
".",
"_htOption",
"=",
"htOption",
";",
"this",
".",
"_elCanvas",
"=",
"document",
".",
"createElement",
"(",
"\"canvas\"",
")",
";",
"this",
".",
"_elCanvas",
".",
"width",
"=",
"htOption",
".",
"width",
";",
"this",
".",
"_elCanvas",
".",
"height",
"=",
"htOption",
".",
"height",
";",
"el",
".",
"appendChild",
"(",
"this",
".",
"_elCanvas",
")",
";",
"this",
".",
"_el",
"=",
"el",
";",
"this",
".",
"_oContext",
"=",
"this",
".",
"_elCanvas",
".",
"getContext",
"(",
"\"2d\"",
")",
";",
"this",
".",
"_bIsPainted",
"=",
"false",
";",
"this",
".",
"_elImage",
"=",
"document",
".",
"createElement",
"(",
"\"img\"",
")",
";",
"this",
".",
"_elImage",
".",
"alt",
"=",
"\"Scan me!\"",
";",
"this",
".",
"_elImage",
".",
"style",
".",
"display",
"=",
"\"none\"",
";",
"this",
".",
"_el",
".",
"appendChild",
"(",
"this",
".",
"_elImage",
")",
";",
"this",
".",
"_bSupportDataURI",
"=",
"null",
";",
"}"
] | Drawing QRCode by using canvas
@constructor
@param {HTMLElement} el
@param {Object} htOption QRCode Options | [
"Drawing",
"QRCode",
"by",
"using",
"canvas"
] | ddc699dfabf56b41f11865b6195dda05614f1e2a | https://github.com/overtrue/share.js/blob/ddc699dfabf56b41f11865b6195dda05614f1e2a/src/js/qrcode.js#L352-L369 |
|
8,027 | overtrue/share.js | src/js/qrcode.js | _getTypeNumber | function _getTypeNumber(sText, nCorrectLevel) {
var nType = 1;
var length = _getUTF8Length(sText);
for (var i = 0, len = QRCodeLimitLength.length; i <= len; i++) {
var nLimit = 0;
switch (nCorrectLevel) {
case QRErrorCorrectLevel.L :
nLimit = QRCodeLimitLength[i][0];
break;
case QRErrorCorrectLevel.M :
nLimit = QRCodeLimitLength[i][1];
break;
case QRErrorCorrectLevel.Q :
nLimit = QRCodeLimitLength[i][2];
break;
case QRErrorCorrectLevel.H :
nLimit = QRCodeLimitLength[i][3];
break;
}
if (length <= nLimit) {
break;
} else {
nType++;
}
}
if (nType > QRCodeLimitLength.length) {
throw new Error("Too long data");
}
return nType;
} | javascript | function _getTypeNumber(sText, nCorrectLevel) {
var nType = 1;
var length = _getUTF8Length(sText);
for (var i = 0, len = QRCodeLimitLength.length; i <= len; i++) {
var nLimit = 0;
switch (nCorrectLevel) {
case QRErrorCorrectLevel.L :
nLimit = QRCodeLimitLength[i][0];
break;
case QRErrorCorrectLevel.M :
nLimit = QRCodeLimitLength[i][1];
break;
case QRErrorCorrectLevel.Q :
nLimit = QRCodeLimitLength[i][2];
break;
case QRErrorCorrectLevel.H :
nLimit = QRCodeLimitLength[i][3];
break;
}
if (length <= nLimit) {
break;
} else {
nType++;
}
}
if (nType > QRCodeLimitLength.length) {
throw new Error("Too long data");
}
return nType;
} | [
"function",
"_getTypeNumber",
"(",
"sText",
",",
"nCorrectLevel",
")",
"{",
"var",
"nType",
"=",
"1",
";",
"var",
"length",
"=",
"_getUTF8Length",
"(",
"sText",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"QRCodeLimitLength",
".",
"length",
";",
"i",
"<=",
"len",
";",
"i",
"++",
")",
"{",
"var",
"nLimit",
"=",
"0",
";",
"switch",
"(",
"nCorrectLevel",
")",
"{",
"case",
"QRErrorCorrectLevel",
".",
"L",
":",
"nLimit",
"=",
"QRCodeLimitLength",
"[",
"i",
"]",
"[",
"0",
"]",
";",
"break",
";",
"case",
"QRErrorCorrectLevel",
".",
"M",
":",
"nLimit",
"=",
"QRCodeLimitLength",
"[",
"i",
"]",
"[",
"1",
"]",
";",
"break",
";",
"case",
"QRErrorCorrectLevel",
".",
"Q",
":",
"nLimit",
"=",
"QRCodeLimitLength",
"[",
"i",
"]",
"[",
"2",
"]",
";",
"break",
";",
"case",
"QRErrorCorrectLevel",
".",
"H",
":",
"nLimit",
"=",
"QRCodeLimitLength",
"[",
"i",
"]",
"[",
"3",
"]",
";",
"break",
";",
"}",
"if",
"(",
"length",
"<=",
"nLimit",
")",
"{",
"break",
";",
"}",
"else",
"{",
"nType",
"++",
";",
"}",
"}",
"if",
"(",
"nType",
">",
"QRCodeLimitLength",
".",
"length",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Too long data\"",
")",
";",
"}",
"return",
"nType",
";",
"}"
] | Get the type by string length
@private
@param {String} sText
@param {Number} nCorrectLevel
@return {Number} type | [
"Get",
"the",
"type",
"by",
"string",
"length"
] | ddc699dfabf56b41f11865b6195dda05614f1e2a | https://github.com/overtrue/share.js/blob/ddc699dfabf56b41f11865b6195dda05614f1e2a/src/js/qrcode.js#L469-L503 |
8,028 | conventional-changelog/standard-version | lib/lifecycles/bump.js | getCurrentActiveType | function getCurrentActiveType (version) {
let typelist = TypeList
for (let i = 0; i < typelist.length; i++) {
if (semver[typelist[i]](version)) {
return typelist[i]
}
}
} | javascript | function getCurrentActiveType (version) {
let typelist = TypeList
for (let i = 0; i < typelist.length; i++) {
if (semver[typelist[i]](version)) {
return typelist[i]
}
}
} | [
"function",
"getCurrentActiveType",
"(",
"version",
")",
"{",
"let",
"typelist",
"=",
"TypeList",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"typelist",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"semver",
"[",
"typelist",
"[",
"i",
"]",
"]",
"(",
"version",
")",
")",
"{",
"return",
"typelist",
"[",
"i",
"]",
"}",
"}",
"}"
] | extract the in-pre-release type in target version
@param version
@return {string} | [
"extract",
"the",
"in",
"-",
"pre",
"-",
"release",
"type",
"in",
"target",
"version"
] | a5ac84545a51ce8eb5ea2db0cf06fb8b39188e82 | https://github.com/conventional-changelog/standard-version/blob/a5ac84545a51ce8eb5ea2db0cf06fb8b39188e82/lib/lifecycles/bump.js#L112-L119 |
8,029 | bitinn/node-fetch | src/body.js | consumeBody | function consumeBody() {
if (this[INTERNALS].disturbed) {
return Body.Promise.reject(new TypeError(`body used already for: ${this.url}`));
}
this[INTERNALS].disturbed = true;
if (this[INTERNALS].error) {
return Body.Promise.reject(this[INTERNALS].error);
}
let body = this.body;
// body is null
if (body === null) {
return Body.Promise.resolve(Buffer.alloc(0));
}
// body is blob
if (isBlob(body)) {
body = body.stream();
}
// body is buffer
if (Buffer.isBuffer(body)) {
return Body.Promise.resolve(body);
}
// istanbul ignore if: should never happen
if (!(body instanceof Stream)) {
return Body.Promise.resolve(Buffer.alloc(0));
}
// body is stream
// get ready to actually consume the body
let accum = [];
let accumBytes = 0;
let abort = false;
return new Body.Promise((resolve, reject) => {
let resTimeout;
// allow timeout on slow response body
if (this.timeout) {
resTimeout = setTimeout(() => {
abort = true;
reject(new FetchError(`Response timeout while trying to fetch ${this.url} (over ${this.timeout}ms)`, 'body-timeout'));
}, this.timeout);
}
// handle stream errors
body.on('error', err => {
if (err.name === 'AbortError') {
// if the request was aborted, reject with this Error
abort = true;
reject(err);
} else {
// other errors, such as incorrect content-encoding
reject(new FetchError(`Invalid response body while trying to fetch ${this.url}: ${err.message}`, 'system', err));
}
});
body.on('data', chunk => {
if (abort || chunk === null) {
return;
}
if (this.size && accumBytes + chunk.length > this.size) {
abort = true;
reject(new FetchError(`content size at ${this.url} over limit: ${this.size}`, 'max-size'));
return;
}
accumBytes += chunk.length;
accum.push(chunk);
});
body.on('end', () => {
if (abort) {
return;
}
clearTimeout(resTimeout);
try {
resolve(Buffer.concat(accum, accumBytes));
} catch (err) {
// handle streams that have accumulated too much data (issue #414)
reject(new FetchError(`Could not create Buffer from response body for ${this.url}: ${err.message}`, 'system', err));
}
});
});
} | javascript | function consumeBody() {
if (this[INTERNALS].disturbed) {
return Body.Promise.reject(new TypeError(`body used already for: ${this.url}`));
}
this[INTERNALS].disturbed = true;
if (this[INTERNALS].error) {
return Body.Promise.reject(this[INTERNALS].error);
}
let body = this.body;
// body is null
if (body === null) {
return Body.Promise.resolve(Buffer.alloc(0));
}
// body is blob
if (isBlob(body)) {
body = body.stream();
}
// body is buffer
if (Buffer.isBuffer(body)) {
return Body.Promise.resolve(body);
}
// istanbul ignore if: should never happen
if (!(body instanceof Stream)) {
return Body.Promise.resolve(Buffer.alloc(0));
}
// body is stream
// get ready to actually consume the body
let accum = [];
let accumBytes = 0;
let abort = false;
return new Body.Promise((resolve, reject) => {
let resTimeout;
// allow timeout on slow response body
if (this.timeout) {
resTimeout = setTimeout(() => {
abort = true;
reject(new FetchError(`Response timeout while trying to fetch ${this.url} (over ${this.timeout}ms)`, 'body-timeout'));
}, this.timeout);
}
// handle stream errors
body.on('error', err => {
if (err.name === 'AbortError') {
// if the request was aborted, reject with this Error
abort = true;
reject(err);
} else {
// other errors, such as incorrect content-encoding
reject(new FetchError(`Invalid response body while trying to fetch ${this.url}: ${err.message}`, 'system', err));
}
});
body.on('data', chunk => {
if (abort || chunk === null) {
return;
}
if (this.size && accumBytes + chunk.length > this.size) {
abort = true;
reject(new FetchError(`content size at ${this.url} over limit: ${this.size}`, 'max-size'));
return;
}
accumBytes += chunk.length;
accum.push(chunk);
});
body.on('end', () => {
if (abort) {
return;
}
clearTimeout(resTimeout);
try {
resolve(Buffer.concat(accum, accumBytes));
} catch (err) {
// handle streams that have accumulated too much data (issue #414)
reject(new FetchError(`Could not create Buffer from response body for ${this.url}: ${err.message}`, 'system', err));
}
});
});
} | [
"function",
"consumeBody",
"(",
")",
"{",
"if",
"(",
"this",
"[",
"INTERNALS",
"]",
".",
"disturbed",
")",
"{",
"return",
"Body",
".",
"Promise",
".",
"reject",
"(",
"new",
"TypeError",
"(",
"`",
"${",
"this",
".",
"url",
"}",
"`",
")",
")",
";",
"}",
"this",
"[",
"INTERNALS",
"]",
".",
"disturbed",
"=",
"true",
";",
"if",
"(",
"this",
"[",
"INTERNALS",
"]",
".",
"error",
")",
"{",
"return",
"Body",
".",
"Promise",
".",
"reject",
"(",
"this",
"[",
"INTERNALS",
"]",
".",
"error",
")",
";",
"}",
"let",
"body",
"=",
"this",
".",
"body",
";",
"// body is null",
"if",
"(",
"body",
"===",
"null",
")",
"{",
"return",
"Body",
".",
"Promise",
".",
"resolve",
"(",
"Buffer",
".",
"alloc",
"(",
"0",
")",
")",
";",
"}",
"// body is blob",
"if",
"(",
"isBlob",
"(",
"body",
")",
")",
"{",
"body",
"=",
"body",
".",
"stream",
"(",
")",
";",
"}",
"// body is buffer",
"if",
"(",
"Buffer",
".",
"isBuffer",
"(",
"body",
")",
")",
"{",
"return",
"Body",
".",
"Promise",
".",
"resolve",
"(",
"body",
")",
";",
"}",
"// istanbul ignore if: should never happen",
"if",
"(",
"!",
"(",
"body",
"instanceof",
"Stream",
")",
")",
"{",
"return",
"Body",
".",
"Promise",
".",
"resolve",
"(",
"Buffer",
".",
"alloc",
"(",
"0",
")",
")",
";",
"}",
"// body is stream",
"// get ready to actually consume the body",
"let",
"accum",
"=",
"[",
"]",
";",
"let",
"accumBytes",
"=",
"0",
";",
"let",
"abort",
"=",
"false",
";",
"return",
"new",
"Body",
".",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"let",
"resTimeout",
";",
"// allow timeout on slow response body",
"if",
"(",
"this",
".",
"timeout",
")",
"{",
"resTimeout",
"=",
"setTimeout",
"(",
"(",
")",
"=>",
"{",
"abort",
"=",
"true",
";",
"reject",
"(",
"new",
"FetchError",
"(",
"`",
"${",
"this",
".",
"url",
"}",
"${",
"this",
".",
"timeout",
"}",
"`",
",",
"'body-timeout'",
")",
")",
";",
"}",
",",
"this",
".",
"timeout",
")",
";",
"}",
"// handle stream errors",
"body",
".",
"on",
"(",
"'error'",
",",
"err",
"=>",
"{",
"if",
"(",
"err",
".",
"name",
"===",
"'AbortError'",
")",
"{",
"// if the request was aborted, reject with this Error",
"abort",
"=",
"true",
";",
"reject",
"(",
"err",
")",
";",
"}",
"else",
"{",
"// other errors, such as incorrect content-encoding",
"reject",
"(",
"new",
"FetchError",
"(",
"`",
"${",
"this",
".",
"url",
"}",
"${",
"err",
".",
"message",
"}",
"`",
",",
"'system'",
",",
"err",
")",
")",
";",
"}",
"}",
")",
";",
"body",
".",
"on",
"(",
"'data'",
",",
"chunk",
"=>",
"{",
"if",
"(",
"abort",
"||",
"chunk",
"===",
"null",
")",
"{",
"return",
";",
"}",
"if",
"(",
"this",
".",
"size",
"&&",
"accumBytes",
"+",
"chunk",
".",
"length",
">",
"this",
".",
"size",
")",
"{",
"abort",
"=",
"true",
";",
"reject",
"(",
"new",
"FetchError",
"(",
"`",
"${",
"this",
".",
"url",
"}",
"${",
"this",
".",
"size",
"}",
"`",
",",
"'max-size'",
")",
")",
";",
"return",
";",
"}",
"accumBytes",
"+=",
"chunk",
".",
"length",
";",
"accum",
".",
"push",
"(",
"chunk",
")",
";",
"}",
")",
";",
"body",
".",
"on",
"(",
"'end'",
",",
"(",
")",
"=>",
"{",
"if",
"(",
"abort",
")",
"{",
"return",
";",
"}",
"clearTimeout",
"(",
"resTimeout",
")",
";",
"try",
"{",
"resolve",
"(",
"Buffer",
".",
"concat",
"(",
"accum",
",",
"accumBytes",
")",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"// handle streams that have accumulated too much data (issue #414)",
"reject",
"(",
"new",
"FetchError",
"(",
"`",
"${",
"this",
".",
"url",
"}",
"${",
"err",
".",
"message",
"}",
"`",
",",
"'system'",
",",
"err",
")",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}"
] | Consume and convert an entire Body to a Buffer.
Ref: https://fetch.spec.whatwg.org/#concept-body-consume-body
@return Promise | [
"Consume",
"and",
"convert",
"an",
"entire",
"Body",
"to",
"a",
"Buffer",
"."
] | bf8b4e8db350ec76dbb9236620f774fcc21b8c12 | https://github.com/bitinn/node-fetch/blob/bf8b4e8db350ec76dbb9236620f774fcc21b8c12/src/body.js#L182-L274 |
8,030 | bitinn/node-fetch | src/headers.js | find | function find(map, name) {
name = name.toLowerCase();
for (const key in map) {
if (key.toLowerCase() === name) {
return key;
}
}
return undefined;
} | javascript | function find(map, name) {
name = name.toLowerCase();
for (const key in map) {
if (key.toLowerCase() === name) {
return key;
}
}
return undefined;
} | [
"function",
"find",
"(",
"map",
",",
"name",
")",
"{",
"name",
"=",
"name",
".",
"toLowerCase",
"(",
")",
";",
"for",
"(",
"const",
"key",
"in",
"map",
")",
"{",
"if",
"(",
"key",
".",
"toLowerCase",
"(",
")",
"===",
"name",
")",
"{",
"return",
"key",
";",
"}",
"}",
"return",
"undefined",
";",
"}"
] | Find the key in the map object given a header name.
Returns undefined if not found.
@param String name Header name
@return String|Undefined | [
"Find",
"the",
"key",
"in",
"the",
"map",
"object",
"given",
"a",
"header",
"name",
"."
] | bf8b4e8db350ec76dbb9236620f774fcc21b8c12 | https://github.com/bitinn/node-fetch/blob/bf8b4e8db350ec76dbb9236620f774fcc21b8c12/src/headers.js#L33-L41 |
8,031 | isaachinman/next-i18next | src/utils/console-message.js | logMessage | function logMessage(messageType, message) {
if (Object.values(messageTypes).includes(messageType)) {
console[messageType](message)
} else {
console.info(message)
}
} | javascript | function logMessage(messageType, message) {
if (Object.values(messageTypes).includes(messageType)) {
console[messageType](message)
} else {
console.info(message)
}
} | [
"function",
"logMessage",
"(",
"messageType",
",",
"message",
")",
"{",
"if",
"(",
"Object",
".",
"values",
"(",
"messageTypes",
")",
".",
"includes",
"(",
"messageType",
")",
")",
"{",
"console",
"[",
"messageType",
"]",
"(",
"message",
")",
"}",
"else",
"{",
"console",
".",
"info",
"(",
"message",
")",
"}",
"}"
] | Logs a custom message to console
@param {messageTypes} messageType One of: error, warn or info
@param {String} message | [
"Logs",
"a",
"custom",
"message",
"to",
"console"
] | a78dcc52fd3312e1ddd8c3ba62110918ce81b5b5 | https://github.com/isaachinman/next-i18next/blob/a78dcc52fd3312e1ddd8c3ba62110918ce81b5b5/src/utils/console-message.js#L20-L26 |
8,032 | MetaMask/web3-provider-engine | util/async.js | function(fns, done) {
done = done || function() {};
this.map(fns, function(fn, callback) {
fn(callback);
}, done);
} | javascript | function(fns, done) {
done = done || function() {};
this.map(fns, function(fn, callback) {
fn(callback);
}, done);
} | [
"function",
"(",
"fns",
",",
"done",
")",
"{",
"done",
"=",
"done",
"||",
"function",
"(",
")",
"{",
"}",
";",
"this",
".",
"map",
"(",
"fns",
",",
"function",
"(",
"fn",
",",
"callback",
")",
"{",
"fn",
"(",
"callback",
")",
";",
"}",
",",
"done",
")",
";",
"}"
] | Works the same as async.parallel | [
"Works",
"the",
"same",
"as",
"async",
".",
"parallel"
] | 5f7acf6c96028f151b5d3ad2a99cb935056f2b71 | https://github.com/MetaMask/web3-provider-engine/blob/5f7acf6c96028f151b5d3ad2a99cb935056f2b71/util/async.js#L3-L8 |
|
8,033 | MetaMask/web3-provider-engine | util/async.js | function(items, iterator, done) {
done = done || function() {};
var results = [];
var failure = false;
var expected = items.length;
var actual = 0;
var createIntermediary = function(index) {
return function(err, result) {
// Return if we found a failure anywhere.
// We can't stop execution of functions since they've already
// been fired off; but we can prevent excessive handling of callbacks.
if (failure != false) {
return;
}
if (err != null) {
failure = true;
done(err, result);
return;
}
actual += 1;
if (actual == expected) {
done(null, results);
}
};
};
for (var i = 0; i < items.length; i++) {
var item = items[i];
iterator(item, createIntermediary(i));
}
if (items.length == 0) {
done(null, []);
}
} | javascript | function(items, iterator, done) {
done = done || function() {};
var results = [];
var failure = false;
var expected = items.length;
var actual = 0;
var createIntermediary = function(index) {
return function(err, result) {
// Return if we found a failure anywhere.
// We can't stop execution of functions since they've already
// been fired off; but we can prevent excessive handling of callbacks.
if (failure != false) {
return;
}
if (err != null) {
failure = true;
done(err, result);
return;
}
actual += 1;
if (actual == expected) {
done(null, results);
}
};
};
for (var i = 0; i < items.length; i++) {
var item = items[i];
iterator(item, createIntermediary(i));
}
if (items.length == 0) {
done(null, []);
}
} | [
"function",
"(",
"items",
",",
"iterator",
",",
"done",
")",
"{",
"done",
"=",
"done",
"||",
"function",
"(",
")",
"{",
"}",
";",
"var",
"results",
"=",
"[",
"]",
";",
"var",
"failure",
"=",
"false",
";",
"var",
"expected",
"=",
"items",
".",
"length",
";",
"var",
"actual",
"=",
"0",
";",
"var",
"createIntermediary",
"=",
"function",
"(",
"index",
")",
"{",
"return",
"function",
"(",
"err",
",",
"result",
")",
"{",
"// Return if we found a failure anywhere.",
"// We can't stop execution of functions since they've already",
"// been fired off; but we can prevent excessive handling of callbacks.",
"if",
"(",
"failure",
"!=",
"false",
")",
"{",
"return",
";",
"}",
"if",
"(",
"err",
"!=",
"null",
")",
"{",
"failure",
"=",
"true",
";",
"done",
"(",
"err",
",",
"result",
")",
";",
"return",
";",
"}",
"actual",
"+=",
"1",
";",
"if",
"(",
"actual",
"==",
"expected",
")",
"{",
"done",
"(",
"null",
",",
"results",
")",
";",
"}",
"}",
";",
"}",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"items",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"item",
"=",
"items",
"[",
"i",
"]",
";",
"iterator",
"(",
"item",
",",
"createIntermediary",
"(",
"i",
")",
")",
";",
"}",
"if",
"(",
"items",
".",
"length",
"==",
"0",
")",
"{",
"done",
"(",
"null",
",",
"[",
"]",
")",
";",
"}",
"}"
] | Works the same as async.map | [
"Works",
"the",
"same",
"as",
"async",
".",
"map"
] | 5f7acf6c96028f151b5d3ad2a99cb935056f2b71 | https://github.com/MetaMask/web3-provider-engine/blob/5f7acf6c96028f151b5d3ad2a99cb935056f2b71/util/async.js#L11-L48 |
|
8,034 | MetaMask/web3-provider-engine | util/async.js | function(items, iterator, done) {
done = done || function() {};
var results = [];
var failure = false;
var expected = items.length;
var current = -1;
function callback(err, result) {
if (err) return done(err);
results.push(result);
if (current == expected) {
return done(null, results);
} else {
next();
}
}
function next() {
current += 1;
var item = items[current];
iterator(item, callback);
}
next()
} | javascript | function(items, iterator, done) {
done = done || function() {};
var results = [];
var failure = false;
var expected = items.length;
var current = -1;
function callback(err, result) {
if (err) return done(err);
results.push(result);
if (current == expected) {
return done(null, results);
} else {
next();
}
}
function next() {
current += 1;
var item = items[current];
iterator(item, callback);
}
next()
} | [
"function",
"(",
"items",
",",
"iterator",
",",
"done",
")",
"{",
"done",
"=",
"done",
"||",
"function",
"(",
")",
"{",
"}",
";",
"var",
"results",
"=",
"[",
"]",
";",
"var",
"failure",
"=",
"false",
";",
"var",
"expected",
"=",
"items",
".",
"length",
";",
"var",
"current",
"=",
"-",
"1",
";",
"function",
"callback",
"(",
"err",
",",
"result",
")",
"{",
"if",
"(",
"err",
")",
"return",
"done",
"(",
"err",
")",
";",
"results",
".",
"push",
"(",
"result",
")",
";",
"if",
"(",
"current",
"==",
"expected",
")",
"{",
"return",
"done",
"(",
"null",
",",
"results",
")",
";",
"}",
"else",
"{",
"next",
"(",
")",
";",
"}",
"}",
"function",
"next",
"(",
")",
"{",
"current",
"+=",
"1",
";",
"var",
"item",
"=",
"items",
"[",
"current",
"]",
";",
"iterator",
"(",
"item",
",",
"callback",
")",
";",
"}",
"next",
"(",
")",
"}"
] | Works like async.eachSeries | [
"Works",
"like",
"async",
".",
"eachSeries"
] | 5f7acf6c96028f151b5d3ad2a99cb935056f2b71 | https://github.com/MetaMask/web3-provider-engine/blob/5f7acf6c96028f151b5d3ad2a99cb935056f2b71/util/async.js#L51-L78 |
|
8,035 | MetaMask/web3-provider-engine | subproviders/hooked-wallet.js | cloneTxParams | function cloneTxParams(txParams){
return {
from: txParams.from,
to: txParams.to,
value: txParams.value,
data: txParams.data,
gas: txParams.gas,
gasPrice: txParams.gasPrice,
nonce: txParams.nonce,
}
} | javascript | function cloneTxParams(txParams){
return {
from: txParams.from,
to: txParams.to,
value: txParams.value,
data: txParams.data,
gas: txParams.gas,
gasPrice: txParams.gasPrice,
nonce: txParams.nonce,
}
} | [
"function",
"cloneTxParams",
"(",
"txParams",
")",
"{",
"return",
"{",
"from",
":",
"txParams",
".",
"from",
",",
"to",
":",
"txParams",
".",
"to",
",",
"value",
":",
"txParams",
".",
"value",
",",
"data",
":",
"txParams",
".",
"data",
",",
"gas",
":",
"txParams",
".",
"gas",
",",
"gasPrice",
":",
"txParams",
".",
"gasPrice",
",",
"nonce",
":",
"txParams",
".",
"nonce",
",",
"}",
"}"
] | util we use this to clean any custom params from the txParams | [
"util",
"we",
"use",
"this",
"to",
"clean",
"any",
"custom",
"params",
"from",
"the",
"txParams"
] | 5f7acf6c96028f151b5d3ad2a99cb935056f2b71 | https://github.com/MetaMask/web3-provider-engine/blob/5f7acf6c96028f151b5d3ad2a99cb935056f2b71/subproviders/hooked-wallet.js#L549-L559 |
8,036 | MetaMask/web3-provider-engine | subproviders/hooked-wallet.js | resemblesData | function resemblesData (string) {
const fixed = ethUtil.addHexPrefix(string)
const isValidAddress = ethUtil.isValidAddress(fixed)
return !isValidAddress && isValidHex(string)
} | javascript | function resemblesData (string) {
const fixed = ethUtil.addHexPrefix(string)
const isValidAddress = ethUtil.isValidAddress(fixed)
return !isValidAddress && isValidHex(string)
} | [
"function",
"resemblesData",
"(",
"string",
")",
"{",
"const",
"fixed",
"=",
"ethUtil",
".",
"addHexPrefix",
"(",
"string",
")",
"const",
"isValidAddress",
"=",
"ethUtil",
".",
"isValidAddress",
"(",
"fixed",
")",
"return",
"!",
"isValidAddress",
"&&",
"isValidHex",
"(",
"string",
")",
"}"
] | Returns true if resembles hex data but definitely not a valid address. | [
"Returns",
"true",
"if",
"resembles",
"hex",
"data",
"but",
"definitely",
"not",
"a",
"valid",
"address",
"."
] | 5f7acf6c96028f151b5d3ad2a99cb935056f2b71 | https://github.com/MetaMask/web3-provider-engine/blob/5f7acf6c96028f151b5d3ad2a99cb935056f2b71/subproviders/hooked-wallet.js#L573-L577 |
8,037 | simonbengtsson/jsPDF-AutoTable | examples/examples.js | function(data) {
if (data.row.index === 5) {
data.cell.styles.fillColor = [40, 170, 100];
}
if ((data.row.section === 'head' || data.row.section === 'foot') && data.column.dataKey === "expenses") {
data.cell.text = '' // Use an icon in didDrawCell instead
}
if (data.row.index === 0 && data.row.section === 'body' && data.column.dataKey === 'city') {
data.cell.text = 'とうきょう'
}
} | javascript | function(data) {
if (data.row.index === 5) {
data.cell.styles.fillColor = [40, 170, 100];
}
if ((data.row.section === 'head' || data.row.section === 'foot') && data.column.dataKey === "expenses") {
data.cell.text = '' // Use an icon in didDrawCell instead
}
if (data.row.index === 0 && data.row.section === 'body' && data.column.dataKey === 'city') {
data.cell.text = 'とうきょう'
}
} | [
"function",
"(",
"data",
")",
"{",
"if",
"(",
"data",
".",
"row",
".",
"index",
"===",
"5",
")",
"{",
"data",
".",
"cell",
".",
"styles",
".",
"fillColor",
"=",
"[",
"40",
",",
"170",
",",
"100",
"]",
";",
"}",
"if",
"(",
"(",
"data",
".",
"row",
".",
"section",
"===",
"'head'",
"||",
"data",
".",
"row",
".",
"section",
"===",
"'foot'",
")",
"&&",
"data",
".",
"column",
".",
"dataKey",
"===",
"\"expenses\"",
")",
"{",
"data",
".",
"cell",
".",
"text",
"=",
"''",
"// Use an icon in didDrawCell instead",
"}",
"if",
"(",
"data",
".",
"row",
".",
"index",
"===",
"0",
"&&",
"data",
".",
"row",
".",
"section",
"===",
"'body'",
"&&",
"data",
".",
"column",
".",
"dataKey",
"===",
"'city'",
")",
"{",
"data",
".",
"cell",
".",
"text",
"=",
"'とうきょう'",
"}",
"}"
] | Use for customizing texts or styles of specific cells after they have been formatted by this plugin. This hook is called just before the column width and other features are computed. | [
"Use",
"for",
"customizing",
"texts",
"or",
"styles",
"of",
"specific",
"cells",
"after",
"they",
"have",
"been",
"formatted",
"by",
"this",
"plugin",
".",
"This",
"hook",
"is",
"called",
"just",
"before",
"the",
"column",
"width",
"and",
"other",
"features",
"are",
"computed",
"."
] | 3a2f64f113bafec212e5680aba22f548168b670c | https://github.com/simonbengtsson/jsPDF-AutoTable/blob/3a2f64f113bafec212e5680aba22f548168b670c/examples/examples.js#L359-L371 |
|
8,038 | simonbengtsson/jsPDF-AutoTable | examples/examples.js | function(data) {
if (data.row.section === 'body' && data.column.dataKey === "expenses") {
if (data.cell.raw > 750) {
doc.setTextColor(231, 76, 60); // Red
doc.setFontStyle('bold');
}
}
} | javascript | function(data) {
if (data.row.section === 'body' && data.column.dataKey === "expenses") {
if (data.cell.raw > 750) {
doc.setTextColor(231, 76, 60); // Red
doc.setFontStyle('bold');
}
}
} | [
"function",
"(",
"data",
")",
"{",
"if",
"(",
"data",
".",
"row",
".",
"section",
"===",
"'body'",
"&&",
"data",
".",
"column",
".",
"dataKey",
"===",
"\"expenses\"",
")",
"{",
"if",
"(",
"data",
".",
"cell",
".",
"raw",
">",
"750",
")",
"{",
"doc",
".",
"setTextColor",
"(",
"231",
",",
"76",
",",
"60",
")",
";",
"// Red",
"doc",
".",
"setFontStyle",
"(",
"'bold'",
")",
";",
"}",
"}",
"}"
] | Use for changing styles with jspdf functions or customize the positioning of cells or cell text just before they are drawn to the page. | [
"Use",
"for",
"changing",
"styles",
"with",
"jspdf",
"functions",
"or",
"customize",
"the",
"positioning",
"of",
"cells",
"or",
"cell",
"text",
"just",
"before",
"they",
"are",
"drawn",
"to",
"the",
"page",
"."
] | 3a2f64f113bafec212e5680aba22f548168b670c | https://github.com/simonbengtsson/jsPDF-AutoTable/blob/3a2f64f113bafec212e5680aba22f548168b670c/examples/examples.js#L374-L381 |
|
8,039 | simonbengtsson/jsPDF-AutoTable | examples/examples.js | function(data) {
if ((data.row.section === 'head' || data.row.section === 'foot') && data.column.dataKey === "expenses" && coinBase64Img) {
doc.addImage(coinBase64Img, 'PNG', data.cell.x + 5, data.cell.y + 2, 5, 5);
}
} | javascript | function(data) {
if ((data.row.section === 'head' || data.row.section === 'foot') && data.column.dataKey === "expenses" && coinBase64Img) {
doc.addImage(coinBase64Img, 'PNG', data.cell.x + 5, data.cell.y + 2, 5, 5);
}
} | [
"function",
"(",
"data",
")",
"{",
"if",
"(",
"(",
"data",
".",
"row",
".",
"section",
"===",
"'head'",
"||",
"data",
".",
"row",
".",
"section",
"===",
"'foot'",
")",
"&&",
"data",
".",
"column",
".",
"dataKey",
"===",
"\"expenses\"",
"&&",
"coinBase64Img",
")",
"{",
"doc",
".",
"addImage",
"(",
"coinBase64Img",
",",
"'PNG'",
",",
"data",
".",
"cell",
".",
"x",
"+",
"5",
",",
"data",
".",
"cell",
".",
"y",
"+",
"2",
",",
"5",
",",
"5",
")",
";",
"}",
"}"
] | Use for adding content to the cells after they are drawn. This could be images or links. You can also use this to draw other custom jspdf content to cells with doc.text or doc.rect for example. | [
"Use",
"for",
"adding",
"content",
"to",
"the",
"cells",
"after",
"they",
"are",
"drawn",
".",
"This",
"could",
"be",
"images",
"or",
"links",
".",
"You",
"can",
"also",
"use",
"this",
"to",
"draw",
"other",
"custom",
"jspdf",
"content",
"to",
"cells",
"with",
"doc",
".",
"text",
"or",
"doc",
".",
"rect",
"for",
"example",
"."
] | 3a2f64f113bafec212e5680aba22f548168b670c | https://github.com/simonbengtsson/jsPDF-AutoTable/blob/3a2f64f113bafec212e5680aba22f548168b670c/examples/examples.js#L385-L389 |
|
8,040 | simonbengtsson/jsPDF-AutoTable | examples/examples.js | function(data) {
doc.setFontSize(18);
doc.text("Custom styling with hooks", data.settings.margin.left, 22);
doc.setFontSize(12);
doc.text("Conditional styling of cells, rows and columns, cell and table borders, custom font, image in cell", data.settings.margin.left, 30)
} | javascript | function(data) {
doc.setFontSize(18);
doc.text("Custom styling with hooks", data.settings.margin.left, 22);
doc.setFontSize(12);
doc.text("Conditional styling of cells, rows and columns, cell and table borders, custom font, image in cell", data.settings.margin.left, 30)
} | [
"function",
"(",
"data",
")",
"{",
"doc",
".",
"setFontSize",
"(",
"18",
")",
";",
"doc",
".",
"text",
"(",
"\"Custom styling with hooks\"",
",",
"data",
".",
"settings",
".",
"margin",
".",
"left",
",",
"22",
")",
";",
"doc",
".",
"setFontSize",
"(",
"12",
")",
";",
"doc",
".",
"text",
"(",
"\"Conditional styling of cells, rows and columns, cell and table borders, custom font, image in cell\"",
",",
"data",
".",
"settings",
".",
"margin",
".",
"left",
",",
"30",
")",
"}"
] | Use this to add content to each page that has the autoTable on it. This can be page headers, page footers and page numbers for example. | [
"Use",
"this",
"to",
"add",
"content",
"to",
"each",
"page",
"that",
"has",
"the",
"autoTable",
"on",
"it",
".",
"This",
"can",
"be",
"page",
"headers",
"page",
"footers",
"and",
"page",
"numbers",
"for",
"example",
"."
] | 3a2f64f113bafec212e5680aba22f548168b670c | https://github.com/simonbengtsson/jsPDF-AutoTable/blob/3a2f64f113bafec212e5680aba22f548168b670c/examples/examples.js#L392-L397 |
|
8,041 | needim/noty | docs/_assets/docsify.js | findAll | function findAll (el, node) {
return [].slice.call(node ? el.querySelectorAll(node) : $.querySelectorAll(el))
} | javascript | function findAll (el, node) {
return [].slice.call(node ? el.querySelectorAll(node) : $.querySelectorAll(el))
} | [
"function",
"findAll",
"(",
"el",
",",
"node",
")",
"{",
"return",
"[",
"]",
".",
"slice",
".",
"call",
"(",
"node",
"?",
"el",
".",
"querySelectorAll",
"(",
"node",
")",
":",
"$",
".",
"querySelectorAll",
"(",
"el",
")",
")",
"}"
] | Find all elements
@example
findAll('a') => [].slice.call(document.querySelectorAll('a'))
findAll(nav, 'a') => [].slice.call(nav.querySelectorAll('a')) | [
"Find",
"all",
"elements"
] | ec741ca366b180292ca81d9412936006ae50e16e | https://github.com/needim/noty/blob/ec741ca366b180292ca81d9412936006ae50e16e/docs/_assets/docsify.js#L200-L202 |
8,042 | needim/noty | docs/_assets/docsify.js | corner | function corner (data) {
if (!data) { return '' }
if (!/\/\//.test(data)) { data = 'https://github.com/' + data; }
data = data.replace(/^git\+/, '');
return (
"<a href=\"" + data + "\" class=\"github-corner\" aria-label=\"View source on Github\">" +
'<svg viewBox="0 0 250 250" aria-hidden="true">' +
'<path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>' +
'<path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>' +
'<path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path>' +
'</svg>' +
'</a>')
} | javascript | function corner (data) {
if (!data) { return '' }
if (!/\/\//.test(data)) { data = 'https://github.com/' + data; }
data = data.replace(/^git\+/, '');
return (
"<a href=\"" + data + "\" class=\"github-corner\" aria-label=\"View source on Github\">" +
'<svg viewBox="0 0 250 250" aria-hidden="true">' +
'<path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>' +
'<path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>' +
'<path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path>' +
'</svg>' +
'</a>')
} | [
"function",
"corner",
"(",
"data",
")",
"{",
"if",
"(",
"!",
"data",
")",
"{",
"return",
"''",
"}",
"if",
"(",
"!",
"/",
"\\/\\/",
"/",
".",
"test",
"(",
"data",
")",
")",
"{",
"data",
"=",
"'https://github.com/'",
"+",
"data",
";",
"}",
"data",
"=",
"data",
".",
"replace",
"(",
"/",
"^git\\+",
"/",
",",
"''",
")",
";",
"return",
"(",
"\"<a href=\\\"\"",
"+",
"data",
"+",
"\"\\\" class=\\\"github-corner\\\" aria-label=\\\"View source on Github\\\">\"",
"+",
"'<svg viewBox=\"0 0 250 250\" aria-hidden=\"true\">'",
"+",
"'<path d=\"M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z\"></path>'",
"+",
"'<path d=\"M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2\" fill=\"currentColor\" style=\"transform-origin: 130px 106px;\" class=\"octo-arm\"></path>'",
"+",
"'<path d=\"M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z\" fill=\"currentColor\" class=\"octo-body\"></path>'",
"+",
"'</svg>'",
"+",
"'</a>'",
")",
"}"
] | Render github corner
@param {Object} data
@return {String} | [
"Render",
"github",
"corner"
] | ec741ca366b180292ca81d9412936006ae50e16e | https://github.com/needim/noty/blob/ec741ca366b180292ca81d9412936006ae50e16e/docs/_assets/docsify.js#L278-L291 |
8,043 | needim/noty | docs/_assets/docsify.js | main | function main (config) {
var aside = (
'<button class="sidebar-toggle">' +
'<div class="sidebar-toggle-button">' +
'<span></span><span></span><span></span>' +
'</div>' +
'</button>' +
'<aside class="sidebar">' +
(config.name
? ("<h1><a class=\"app-name-link\" data-nosearch>" + (config.name) + "</a></h1>")
: '') +
'<div class="sidebar-nav"><!--sidebar--></div>' +
'</aside>');
return (isMobile ? (aside + "<main>") : ("<main>" + aside)) +
'<section class="content">' +
'<article class="markdown-section" id="main"><!--main--></article>' +
'</section>' +
'</main>'
} | javascript | function main (config) {
var aside = (
'<button class="sidebar-toggle">' +
'<div class="sidebar-toggle-button">' +
'<span></span><span></span><span></span>' +
'</div>' +
'</button>' +
'<aside class="sidebar">' +
(config.name
? ("<h1><a class=\"app-name-link\" data-nosearch>" + (config.name) + "</a></h1>")
: '') +
'<div class="sidebar-nav"><!--sidebar--></div>' +
'</aside>');
return (isMobile ? (aside + "<main>") : ("<main>" + aside)) +
'<section class="content">' +
'<article class="markdown-section" id="main"><!--main--></article>' +
'</section>' +
'</main>'
} | [
"function",
"main",
"(",
"config",
")",
"{",
"var",
"aside",
"=",
"(",
"'<button class=\"sidebar-toggle\">'",
"+",
"'<div class=\"sidebar-toggle-button\">'",
"+",
"'<span></span><span></span><span></span>'",
"+",
"'</div>'",
"+",
"'</button>'",
"+",
"'<aside class=\"sidebar\">'",
"+",
"(",
"config",
".",
"name",
"?",
"(",
"\"<h1><a class=\\\"app-name-link\\\" data-nosearch>\"",
"+",
"(",
"config",
".",
"name",
")",
"+",
"\"</a></h1>\"",
")",
":",
"''",
")",
"+",
"'<div class=\"sidebar-nav\"><!--sidebar--></div>'",
"+",
"'</aside>'",
")",
";",
"return",
"(",
"isMobile",
"?",
"(",
"aside",
"+",
"\"<main>\"",
")",
":",
"(",
"\"<main>\"",
"+",
"aside",
")",
")",
"+",
"'<section class=\"content\">'",
"+",
"'<article class=\"markdown-section\" id=\"main\"><!--main--></article>'",
"+",
"'</section>'",
"+",
"'</main>'",
"}"
] | Render main content | [
"Render",
"main",
"content"
] | ec741ca366b180292ca81d9412936006ae50e16e | https://github.com/needim/noty/blob/ec741ca366b180292ca81d9412936006ae50e16e/docs/_assets/docsify.js#L296-L315 |
8,044 | needim/noty | docs/_assets/docsify.js | init | function init () {
var div = create('div');
div.classList.add('progress');
appendTo(body, div);
barEl = div;
} | javascript | function init () {
var div = create('div');
div.classList.add('progress');
appendTo(body, div);
barEl = div;
} | [
"function",
"init",
"(",
")",
"{",
"var",
"div",
"=",
"create",
"(",
"'div'",
")",
";",
"div",
".",
"classList",
".",
"add",
"(",
"'progress'",
")",
";",
"appendTo",
"(",
"body",
",",
"div",
")",
";",
"barEl",
"=",
"div",
";",
"}"
] | Init progress component | [
"Init",
"progress",
"component"
] | ec741ca366b180292ca81d9412936006ae50e16e | https://github.com/needim/noty/blob/ec741ca366b180292ca81d9412936006ae50e16e/docs/_assets/docsify.js#L367-L373 |
8,045 | needim/noty | docs/_assets/docsify.js | function (ref) {
var loaded = ref.loaded;
var total = ref.total;
var step = ref.step;
var num;
!barEl && init();
if (step) {
num = parseInt(barEl.style.width || 0, 10) + step;
num = num > 80 ? 80 : num;
} else {
num = Math.floor(loaded / total * 100);
}
barEl.style.opacity = 1;
barEl.style.width = num >= 95 ? '100%' : num + '%';
if (num >= 95) {
clearTimeout(timeId);
timeId = setTimeout(function (_) {
barEl.style.opacity = 0;
barEl.style.width = '0%';
}, 200);
}
} | javascript | function (ref) {
var loaded = ref.loaded;
var total = ref.total;
var step = ref.step;
var num;
!barEl && init();
if (step) {
num = parseInt(barEl.style.width || 0, 10) + step;
num = num > 80 ? 80 : num;
} else {
num = Math.floor(loaded / total * 100);
}
barEl.style.opacity = 1;
barEl.style.width = num >= 95 ? '100%' : num + '%';
if (num >= 95) {
clearTimeout(timeId);
timeId = setTimeout(function (_) {
barEl.style.opacity = 0;
barEl.style.width = '0%';
}, 200);
}
} | [
"function",
"(",
"ref",
")",
"{",
"var",
"loaded",
"=",
"ref",
".",
"loaded",
";",
"var",
"total",
"=",
"ref",
".",
"total",
";",
"var",
"step",
"=",
"ref",
".",
"step",
";",
"var",
"num",
";",
"!",
"barEl",
"&&",
"init",
"(",
")",
";",
"if",
"(",
"step",
")",
"{",
"num",
"=",
"parseInt",
"(",
"barEl",
".",
"style",
".",
"width",
"||",
"0",
",",
"10",
")",
"+",
"step",
";",
"num",
"=",
"num",
">",
"80",
"?",
"80",
":",
"num",
";",
"}",
"else",
"{",
"num",
"=",
"Math",
".",
"floor",
"(",
"loaded",
"/",
"total",
"*",
"100",
")",
";",
"}",
"barEl",
".",
"style",
".",
"opacity",
"=",
"1",
";",
"barEl",
".",
"style",
".",
"width",
"=",
"num",
">=",
"95",
"?",
"'100%'",
":",
"num",
"+",
"'%'",
";",
"if",
"(",
"num",
">=",
"95",
")",
"{",
"clearTimeout",
"(",
"timeId",
")",
";",
"timeId",
"=",
"setTimeout",
"(",
"function",
"(",
"_",
")",
"{",
"barEl",
".",
"style",
".",
"opacity",
"=",
"0",
";",
"barEl",
".",
"style",
".",
"width",
"=",
"'0%'",
";",
"}",
",",
"200",
")",
";",
"}",
"}"
] | Render progress bar | [
"Render",
"progress",
"bar"
] | ec741ca366b180292ca81d9412936006ae50e16e | https://github.com/needim/noty/blob/ec741ca366b180292ca81d9412936006ae50e16e/docs/_assets/docsify.js#L377-L403 |
|
8,046 | needim/noty | docs/_assets/docsify.js | genTree | function genTree (toc, maxLevel) {
var headlines = [];
var last = {};
toc.forEach(function (headline) {
var level = headline.level || 1;
var len = level - 1;
if (level > maxLevel) { return }
if (last[len]) {
last[len].children = (last[len].children || []).concat(headline);
} else {
headlines.push(headline);
}
last[level] = headline;
});
return headlines
} | javascript | function genTree (toc, maxLevel) {
var headlines = [];
var last = {};
toc.forEach(function (headline) {
var level = headline.level || 1;
var len = level - 1;
if (level > maxLevel) { return }
if (last[len]) {
last[len].children = (last[len].children || []).concat(headline);
} else {
headlines.push(headline);
}
last[level] = headline;
});
return headlines
} | [
"function",
"genTree",
"(",
"toc",
",",
"maxLevel",
")",
"{",
"var",
"headlines",
"=",
"[",
"]",
";",
"var",
"last",
"=",
"{",
"}",
";",
"toc",
".",
"forEach",
"(",
"function",
"(",
"headline",
")",
"{",
"var",
"level",
"=",
"headline",
".",
"level",
"||",
"1",
";",
"var",
"len",
"=",
"level",
"-",
"1",
";",
"if",
"(",
"level",
">",
"maxLevel",
")",
"{",
"return",
"}",
"if",
"(",
"last",
"[",
"len",
"]",
")",
"{",
"last",
"[",
"len",
"]",
".",
"children",
"=",
"(",
"last",
"[",
"len",
"]",
".",
"children",
"||",
"[",
"]",
")",
".",
"concat",
"(",
"headline",
")",
";",
"}",
"else",
"{",
"headlines",
".",
"push",
"(",
"headline",
")",
";",
"}",
"last",
"[",
"level",
"]",
"=",
"headline",
";",
"}",
")",
";",
"return",
"headlines",
"}"
] | gen toc tree
@link https://github.com/killercup/grock/blob/5280ae63e16c5739e9233d9009bc235ed7d79a50/styles/solarized/assets/js/behavior.coffee#L54-L81
@param {Array} toc
@param {Number} maxLevel
@return {Array} | [
"gen",
"toc",
"tree"
] | ec741ca366b180292ca81d9412936006ae50e16e | https://github.com/needim/noty/blob/ec741ca366b180292ca81d9412936006ae50e16e/docs/_assets/docsify.js#L2646-L2664 |
8,047 | needim/noty | docs/_assets/docsify.js | getAndActive | function getAndActive (router, el, isParent, autoTitle) {
el = getNode(el);
var links = findAll(el, 'a');
var hash = router.toURL(router.getCurrentPath());
var target;
links
.sort(function (a, b) { return b.href.length - a.href.length; })
.forEach(function (a) {
var href = a.getAttribute('href');
var node = isParent ? a.parentNode : a;
if (hash.indexOf(href) === 0 && !target) {
target = a;
toggleClass(node, 'add', 'active');
} else {
toggleClass(node, 'remove', 'active');
}
});
if (autoTitle) {
$.title = target ? ((target.innerText) + " - " + title) : title;
}
return target
} | javascript | function getAndActive (router, el, isParent, autoTitle) {
el = getNode(el);
var links = findAll(el, 'a');
var hash = router.toURL(router.getCurrentPath());
var target;
links
.sort(function (a, b) { return b.href.length - a.href.length; })
.forEach(function (a) {
var href = a.getAttribute('href');
var node = isParent ? a.parentNode : a;
if (hash.indexOf(href) === 0 && !target) {
target = a;
toggleClass(node, 'add', 'active');
} else {
toggleClass(node, 'remove', 'active');
}
});
if (autoTitle) {
$.title = target ? ((target.innerText) + " - " + title) : title;
}
return target
} | [
"function",
"getAndActive",
"(",
"router",
",",
"el",
",",
"isParent",
",",
"autoTitle",
")",
"{",
"el",
"=",
"getNode",
"(",
"el",
")",
";",
"var",
"links",
"=",
"findAll",
"(",
"el",
",",
"'a'",
")",
";",
"var",
"hash",
"=",
"router",
".",
"toURL",
"(",
"router",
".",
"getCurrentPath",
"(",
")",
")",
";",
"var",
"target",
";",
"links",
".",
"sort",
"(",
"function",
"(",
"a",
",",
"b",
")",
"{",
"return",
"b",
".",
"href",
".",
"length",
"-",
"a",
".",
"href",
".",
"length",
";",
"}",
")",
".",
"forEach",
"(",
"function",
"(",
"a",
")",
"{",
"var",
"href",
"=",
"a",
".",
"getAttribute",
"(",
"'href'",
")",
";",
"var",
"node",
"=",
"isParent",
"?",
"a",
".",
"parentNode",
":",
"a",
";",
"if",
"(",
"hash",
".",
"indexOf",
"(",
"href",
")",
"===",
"0",
"&&",
"!",
"target",
")",
"{",
"target",
"=",
"a",
";",
"toggleClass",
"(",
"node",
",",
"'add'",
",",
"'active'",
")",
";",
"}",
"else",
"{",
"toggleClass",
"(",
"node",
",",
"'remove'",
",",
"'active'",
")",
";",
"}",
"}",
")",
";",
"if",
"(",
"autoTitle",
")",
"{",
"$",
".",
"title",
"=",
"target",
"?",
"(",
"(",
"target",
".",
"innerText",
")",
"+",
"\" - \"",
"+",
"title",
")",
":",
"title",
";",
"}",
"return",
"target",
"}"
] | Get and active link
@param {object} router
@param {string|element} el
@param {Boolean} isParent acitve parent
@param {Boolean} autoTitle auto set title
@return {element} | [
"Get",
"and",
"active",
"link"
] | ec741ca366b180292ca81d9412936006ae50e16e | https://github.com/needim/noty/blob/ec741ca366b180292ca81d9412936006ae50e16e/docs/_assets/docsify.js#L2995-L3021 |
8,048 | needim/noty | docs/v2/vendor/noty-2.4.1/js/noty/jquery.noty.js | function () {
var self = this;
delete $.noty.store[self.options.id]; // deleting noty from store
if (self.options.theme.callback && self.options.theme.callback.onClose) {
self.options.theme.callback.onClose.apply(self);
}
if (!self.options.dismissQueue) {
// Queue render
$.noty.ontap = true;
$.notyRenderer.render();
}
if (self.options.maxVisible > 0 && self.options.dismissQueue) {
$.notyRenderer.render();
}
} | javascript | function () {
var self = this;
delete $.noty.store[self.options.id]; // deleting noty from store
if (self.options.theme.callback && self.options.theme.callback.onClose) {
self.options.theme.callback.onClose.apply(self);
}
if (!self.options.dismissQueue) {
// Queue render
$.noty.ontap = true;
$.notyRenderer.render();
}
if (self.options.maxVisible > 0 && self.options.dismissQueue) {
$.notyRenderer.render();
}
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"delete",
"$",
".",
"noty",
".",
"store",
"[",
"self",
".",
"options",
".",
"id",
"]",
";",
"// deleting noty from store",
"if",
"(",
"self",
".",
"options",
".",
"theme",
".",
"callback",
"&&",
"self",
".",
"options",
".",
"theme",
".",
"callback",
".",
"onClose",
")",
"{",
"self",
".",
"options",
".",
"theme",
".",
"callback",
".",
"onClose",
".",
"apply",
"(",
"self",
")",
";",
"}",
"if",
"(",
"!",
"self",
".",
"options",
".",
"dismissQueue",
")",
"{",
"// Queue render",
"$",
".",
"noty",
".",
"ontap",
"=",
"true",
";",
"$",
".",
"notyRenderer",
".",
"render",
"(",
")",
";",
"}",
"if",
"(",
"self",
".",
"options",
".",
"maxVisible",
">",
"0",
"&&",
"self",
".",
"options",
".",
"dismissQueue",
")",
"{",
"$",
".",
"notyRenderer",
".",
"render",
"(",
")",
";",
"}",
"}"
] | end close clean up | [
"end",
"close",
"clean",
"up"
] | ec741ca366b180292ca81d9412936006ae50e16e | https://github.com/needim/noty/blob/ec741ca366b180292ca81d9412936006ae50e16e/docs/v2/vendor/noty-2.4.1/js/noty/jquery.noty.js#L387-L406 |
|
8,049 | needim/noty | docs/v2/vendor/showdown/showdown.js | listen | function listen(name, callback) {
if (!showdown.helper.isString(name)) {
throw Error('Invalid argument in converter.listen() method: name must be a string, but ' + typeof name + ' given');
}
if (typeof callback !== 'function') {
throw Error('Invalid argument in converter.listen() method: callback must be a function, but ' + typeof callback + ' given');
}
if (!listeners.hasOwnProperty(name)) {
listeners[name] = [];
}
listeners[name].push(callback);
} | javascript | function listen(name, callback) {
if (!showdown.helper.isString(name)) {
throw Error('Invalid argument in converter.listen() method: name must be a string, but ' + typeof name + ' given');
}
if (typeof callback !== 'function') {
throw Error('Invalid argument in converter.listen() method: callback must be a function, but ' + typeof callback + ' given');
}
if (!listeners.hasOwnProperty(name)) {
listeners[name] = [];
}
listeners[name].push(callback);
} | [
"function",
"listen",
"(",
"name",
",",
"callback",
")",
"{",
"if",
"(",
"!",
"showdown",
".",
"helper",
".",
"isString",
"(",
"name",
")",
")",
"{",
"throw",
"Error",
"(",
"'Invalid argument in converter.listen() method: name must be a string, but '",
"+",
"typeof",
"name",
"+",
"' given'",
")",
";",
"}",
"if",
"(",
"typeof",
"callback",
"!==",
"'function'",
")",
"{",
"throw",
"Error",
"(",
"'Invalid argument in converter.listen() method: callback must be a function, but '",
"+",
"typeof",
"callback",
"+",
"' given'",
")",
";",
"}",
"if",
"(",
"!",
"listeners",
".",
"hasOwnProperty",
"(",
"name",
")",
")",
"{",
"listeners",
"[",
"name",
"]",
"=",
"[",
"]",
";",
"}",
"listeners",
"[",
"name",
"]",
".",
"push",
"(",
"callback",
")",
";",
"}"
] | Listen to an event
@param {string} name
@param {function} callback | [
"Listen",
"to",
"an",
"event"
] | ec741ca366b180292ca81d9412936006ae50e16e | https://github.com/needim/noty/blob/ec741ca366b180292ca81d9412936006ae50e16e/docs/v2/vendor/showdown/showdown.js#L893-L906 |
8,050 | BrowserSync/browser-sync | examples/middleware.css.injection.js | function(req, res, next) {
var parsed = require("url").parse(req.url);
if (parsed.pathname.match(/\.less$/)) {
return less(parsed.pathname).then(function(o) {
res.setHeader("Content-Type", "text/css");
res.end(o.css);
});
}
next();
} | javascript | function(req, res, next) {
var parsed = require("url").parse(req.url);
if (parsed.pathname.match(/\.less$/)) {
return less(parsed.pathname).then(function(o) {
res.setHeader("Content-Type", "text/css");
res.end(o.css);
});
}
next();
} | [
"function",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"var",
"parsed",
"=",
"require",
"(",
"\"url\"",
")",
".",
"parse",
"(",
"req",
".",
"url",
")",
";",
"if",
"(",
"parsed",
".",
"pathname",
".",
"match",
"(",
"/",
"\\.less$",
"/",
")",
")",
"{",
"return",
"less",
"(",
"parsed",
".",
"pathname",
")",
".",
"then",
"(",
"function",
"(",
"o",
")",
"{",
"res",
".",
"setHeader",
"(",
"\"Content-Type\"",
",",
"\"text/css\"",
")",
";",
"res",
".",
"end",
"(",
"o",
".",
"css",
")",
";",
"}",
")",
";",
"}",
"next",
"(",
")",
";",
"}"
] | Catch all requests, if any are for .less files, recompile on the fly and
send back a CSS response | [
"Catch",
"all",
"requests",
"if",
"any",
"are",
"for",
".",
"less",
"files",
"recompile",
"on",
"the",
"fly",
"and",
"send",
"back",
"a",
"CSS",
"response"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/examples/middleware.css.injection.js#L38-L47 |
|
8,051 | BrowserSync/browser-sync | packages/browser-sync/lib/lodash.custom.js | iteratorToArray | function iteratorToArray(iterator) {
var data,
result = [];
while (!(data = iterator.next()).done) {
result.push(data.value);
}
return result;
} | javascript | function iteratorToArray(iterator) {
var data,
result = [];
while (!(data = iterator.next()).done) {
result.push(data.value);
}
return result;
} | [
"function",
"iteratorToArray",
"(",
"iterator",
")",
"{",
"var",
"data",
",",
"result",
"=",
"[",
"]",
";",
"while",
"(",
"!",
"(",
"data",
"=",
"iterator",
".",
"next",
"(",
")",
")",
".",
"done",
")",
"{",
"result",
".",
"push",
"(",
"data",
".",
"value",
")",
";",
"}",
"return",
"result",
";",
"}"
] | Converts `iterator` to an array.
@private
@param {Object} iterator The iterator to convert.
@returns {Array} Returns the converted array. | [
"Converts",
"iterator",
"to",
"an",
"array",
"."
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync/lib/lodash.custom.js#L646-L654 |
8,052 | BrowserSync/browser-sync | packages/browser-sync/lib/lodash.custom.js | getIteratee | function getIteratee() {
var result = lodash.iteratee || iteratee;
result = result === iteratee ? baseIteratee : result;
return arguments.length ? result(arguments[0], arguments[1]) : result;
} | javascript | function getIteratee() {
var result = lodash.iteratee || iteratee;
result = result === iteratee ? baseIteratee : result;
return arguments.length ? result(arguments[0], arguments[1]) : result;
} | [
"function",
"getIteratee",
"(",
")",
"{",
"var",
"result",
"=",
"lodash",
".",
"iteratee",
"||",
"iteratee",
";",
"result",
"=",
"result",
"===",
"iteratee",
"?",
"baseIteratee",
":",
"result",
";",
"return",
"arguments",
".",
"length",
"?",
"result",
"(",
"arguments",
"[",
"0",
"]",
",",
"arguments",
"[",
"1",
"]",
")",
":",
"result",
";",
"}"
] | Gets the appropriate "iteratee" function. If `_.iteratee` is customized,
this function returns the custom method, otherwise it returns `baseIteratee`.
If arguments are provided, the chosen function is invoked with them and
its result is returned.
@private
@param {*} [value] The value to convert to an iteratee.
@param {number} [arity] The arity of the created iteratee.
@returns {Function} Returns the chosen function or its result. | [
"Gets",
"the",
"appropriate",
"iteratee",
"function",
".",
"If",
"_",
".",
"iteratee",
"is",
"customized",
"this",
"function",
"returns",
"the",
"custom",
"method",
"otherwise",
"it",
"returns",
"baseIteratee",
".",
"If",
"arguments",
"are",
"provided",
"the",
"chosen",
"function",
"is",
"invoked",
"with",
"them",
"and",
"its",
"result",
"is",
"returned",
"."
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync/lib/lodash.custom.js#L3150-L3154 |
8,053 | BrowserSync/browser-sync | packages/browser-sync/lib/lodash.custom.js | memoizeCapped | function memoizeCapped(func) {
var result = memoize(func, function(key) {
if (cache.size === MAX_MEMOIZE_SIZE) {
cache.clear();
}
return key;
});
var cache = result.cache;
return result;
} | javascript | function memoizeCapped(func) {
var result = memoize(func, function(key) {
if (cache.size === MAX_MEMOIZE_SIZE) {
cache.clear();
}
return key;
});
var cache = result.cache;
return result;
} | [
"function",
"memoizeCapped",
"(",
"func",
")",
"{",
"var",
"result",
"=",
"memoize",
"(",
"func",
",",
"function",
"(",
"key",
")",
"{",
"if",
"(",
"cache",
".",
"size",
"===",
"MAX_MEMOIZE_SIZE",
")",
"{",
"cache",
".",
"clear",
"(",
")",
";",
"}",
"return",
"key",
";",
"}",
")",
";",
"var",
"cache",
"=",
"result",
".",
"cache",
";",
"return",
"result",
";",
"}"
] | A specialized version of `_.memoize` which clears the memoized function's
cache when it exceeds `MAX_MEMOIZE_SIZE`.
@private
@param {Function} func The function to have its output memoized.
@returns {Function} Returns the new memoized function. | [
"A",
"specialized",
"version",
"of",
"_",
".",
"memoize",
"which",
"clears",
"the",
"memoized",
"function",
"s",
"cache",
"when",
"it",
"exceeds",
"MAX_MEMOIZE_SIZE",
"."
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync/lib/lodash.custom.js#L3604-L3614 |
8,054 | BrowserSync/browser-sync | packages/browser-sync/lib/lodash.custom.js | toInteger | function toInteger(value) {
var result = toFinite(value),
remainder = result % 1;
return result === result
? remainder ? result - remainder : result
: 0;
} | javascript | function toInteger(value) {
var result = toFinite(value),
remainder = result % 1;
return result === result
? remainder ? result - remainder : result
: 0;
} | [
"function",
"toInteger",
"(",
"value",
")",
"{",
"var",
"result",
"=",
"toFinite",
"(",
"value",
")",
",",
"remainder",
"=",
"result",
"%",
"1",
";",
"return",
"result",
"===",
"result",
"?",
"remainder",
"?",
"result",
"-",
"remainder",
":",
"result",
":",
"0",
";",
"}"
] | Converts `value` to an integer.
**Note:** This method is loosely based on
[`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
@static
@memberOf _
@since 4.0.0
@category Lang
@param {*} value The value to convert.
@returns {number} Returns the converted integer.
@example
_.toInteger(3.2);
// => 3
_.toInteger(Number.MIN_VALUE);
// => 0
_.toInteger(Infinity);
// => 1.7976931348623157e+308
_.toInteger('3.2');
// => 3 | [
"Converts",
"value",
"to",
"an",
"integer",
"."
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync/lib/lodash.custom.js#L4480-L4487 |
8,055 | BrowserSync/browser-sync | packages/browser-sync/lib/plugins.js | requirePlugin | function requirePlugin(item) {
/**
* if the "module" property already exists and
* is not a string, then we bail and don't bother looking
* for the file
*/
if (item.get("module") && typeof item.get("module") !== "string") {
return item;
}
try {
/**
* Try a raw node require() call - this will be how
* regular "npm installed" plugins wil work
*/
var maybe = require.resolve(item.get("name"));
return item.set("module", require(maybe));
} catch (e) {
/**
* If require threw an MODULE_NOT_FOUND error, try again
* by resolving from cwd. This is needed since cli
* users will not add ./ to the front of a path (which
* node requires to resolve from cwd)
*/
if (e.code === "MODULE_NOT_FOUND") {
var maybe = path.resolve(process.cwd(), item.get("name"));
if (fs.existsSync(maybe)) {
return item.set("module", require(maybe));
} else {
/**
* Finally return a plugin that contains the error
* this will be picked up later and discarded
*/
return item.update("errors", function(errors) {
return errors.concat(e);
});
}
}
throw e;
}
} | javascript | function requirePlugin(item) {
/**
* if the "module" property already exists and
* is not a string, then we bail and don't bother looking
* for the file
*/
if (item.get("module") && typeof item.get("module") !== "string") {
return item;
}
try {
/**
* Try a raw node require() call - this will be how
* regular "npm installed" plugins wil work
*/
var maybe = require.resolve(item.get("name"));
return item.set("module", require(maybe));
} catch (e) {
/**
* If require threw an MODULE_NOT_FOUND error, try again
* by resolving from cwd. This is needed since cli
* users will not add ./ to the front of a path (which
* node requires to resolve from cwd)
*/
if (e.code === "MODULE_NOT_FOUND") {
var maybe = path.resolve(process.cwd(), item.get("name"));
if (fs.existsSync(maybe)) {
return item.set("module", require(maybe));
} else {
/**
* Finally return a plugin that contains the error
* this will be picked up later and discarded
*/
return item.update("errors", function(errors) {
return errors.concat(e);
});
}
}
throw e;
}
} | [
"function",
"requirePlugin",
"(",
"item",
")",
"{",
"/**\n * if the \"module\" property already exists and\n * is not a string, then we bail and don't bother looking\n * for the file\n */",
"if",
"(",
"item",
".",
"get",
"(",
"\"module\"",
")",
"&&",
"typeof",
"item",
".",
"get",
"(",
"\"module\"",
")",
"!==",
"\"string\"",
")",
"{",
"return",
"item",
";",
"}",
"try",
"{",
"/**\n * Try a raw node require() call - this will be how\n * regular \"npm installed\" plugins wil work\n */",
"var",
"maybe",
"=",
"require",
".",
"resolve",
"(",
"item",
".",
"get",
"(",
"\"name\"",
")",
")",
";",
"return",
"item",
".",
"set",
"(",
"\"module\"",
",",
"require",
"(",
"maybe",
")",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"/**\n * If require threw an MODULE_NOT_FOUND error, try again\n * by resolving from cwd. This is needed since cli\n * users will not add ./ to the front of a path (which\n * node requires to resolve from cwd)\n */",
"if",
"(",
"e",
".",
"code",
"===",
"\"MODULE_NOT_FOUND\"",
")",
"{",
"var",
"maybe",
"=",
"path",
".",
"resolve",
"(",
"process",
".",
"cwd",
"(",
")",
",",
"item",
".",
"get",
"(",
"\"name\"",
")",
")",
";",
"if",
"(",
"fs",
".",
"existsSync",
"(",
"maybe",
")",
")",
"{",
"return",
"item",
".",
"set",
"(",
"\"module\"",
",",
"require",
"(",
"maybe",
")",
")",
";",
"}",
"else",
"{",
"/**\n * Finally return a plugin that contains the error\n * this will be picked up later and discarded\n */",
"return",
"item",
".",
"update",
"(",
"\"errors\"",
",",
"function",
"(",
"errors",
")",
"{",
"return",
"errors",
".",
"concat",
"(",
"e",
")",
";",
"}",
")",
";",
"}",
"}",
"throw",
"e",
";",
"}",
"}"
] | Load a plugin from disk
@param item
@returns {*} | [
"Load",
"a",
"plugin",
"from",
"disk"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync/lib/plugins.js#L122-L162 |
8,056 | BrowserSync/browser-sync | packages/browser-sync/lib/logger.js | function(bs, data) {
if (canLogFileChange(bs, data)) {
if (data.path[0] === "*") {
return logger.info(
"{cyan:Reloading files that match: {magenta:%s",
data.path
);
}
logger.info(
"{cyan:File event [" + data.event + "] : {magenta:%s",
data.path
);
}
} | javascript | function(bs, data) {
if (canLogFileChange(bs, data)) {
if (data.path[0] === "*") {
return logger.info(
"{cyan:Reloading files that match: {magenta:%s",
data.path
);
}
logger.info(
"{cyan:File event [" + data.event + "] : {magenta:%s",
data.path
);
}
} | [
"function",
"(",
"bs",
",",
"data",
")",
"{",
"if",
"(",
"canLogFileChange",
"(",
"bs",
",",
"data",
")",
")",
"{",
"if",
"(",
"data",
".",
"path",
"[",
"0",
"]",
"===",
"\"*\"",
")",
"{",
"return",
"logger",
".",
"info",
"(",
"\"{cyan:Reloading files that match: {magenta:%s\"",
",",
"data",
".",
"path",
")",
";",
"}",
"logger",
".",
"info",
"(",
"\"{cyan:File event [\"",
"+",
"data",
".",
"event",
"+",
"\"] : {magenta:%s\"",
",",
"data",
".",
"path",
")",
";",
"}",
"}"
] | Log when a file changes
@param {BrowserSync} bs
@param data | [
"Log",
"when",
"a",
"file",
"changes"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync/lib/logger.js#L45-L59 |
|
8,057 | BrowserSync/browser-sync | packages/browser-sync/lib/logger.js | function(bs, data) {
var uaString = utils.getUaString(data.ua);
var msg = "{cyan:Browser Connected: {magenta:%s, version: %s}";
var method = "info";
if (!bs.options.get("logConnections")) {
method = "debug";
}
logger.log(method, msg, uaString.name, uaString.version);
} | javascript | function(bs, data) {
var uaString = utils.getUaString(data.ua);
var msg = "{cyan:Browser Connected: {magenta:%s, version: %s}";
var method = "info";
if (!bs.options.get("logConnections")) {
method = "debug";
}
logger.log(method, msg, uaString.name, uaString.version);
} | [
"function",
"(",
"bs",
",",
"data",
")",
"{",
"var",
"uaString",
"=",
"utils",
".",
"getUaString",
"(",
"data",
".",
"ua",
")",
";",
"var",
"msg",
"=",
"\"{cyan:Browser Connected: {magenta:%s, version: %s}\"",
";",
"var",
"method",
"=",
"\"info\"",
";",
"if",
"(",
"!",
"bs",
".",
"options",
".",
"get",
"(",
"\"logConnections\"",
")",
")",
"{",
"method",
"=",
"\"debug\"",
";",
"}",
"logger",
".",
"log",
"(",
"method",
",",
"msg",
",",
"uaString",
".",
"name",
",",
"uaString",
".",
"version",
")",
";",
"}"
] | Client connected logging
@param {BrowserSync} bs
@param data | [
"Client",
"connected",
"logging"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync/lib/logger.js#L106-L116 |
|
8,058 | BrowserSync/browser-sync | packages/browser-sync/lib/logger.js | function(bs, data) {
const type = data.type;
if (bs.options.get('json')) {
return console.log(JSON.stringify({
"service:running": {
"options": bs.options.toJS()
}
}));
}
if (type === "server") {
var baseDir = bs.options.getIn(["server", "baseDir"]);
logUrls(bs.options.get("urls").toJS());
if (baseDir) {
if (utils.isList(baseDir)) {
baseDir.forEach(serveFiles);
} else {
serveFiles(baseDir);
}
}
}
if (type === "proxy") {
logger.info(
"Proxying: {cyan:%s}",
bs.options.getIn(["proxy", "target"])
);
logUrls(bs.options.get("urls").toJS());
}
if (type === "snippet") {
if (bs.options.get("logSnippet")) {
logger.info(
"{bold:Copy the following snippet into your website, " +
"just before the closing {cyan:</body>} tag"
);
logger.unprefixed("info", messages.scriptTags(bs.options));
}
logUrls(
bs.options
.get("urls")
.filter(function(value, key) {
return key.slice(0, 2) === "ui";
})
.toJS()
);
}
function serveFiles(base) {
logger.info("Serving files from: {magenta:%s}", base);
}
} | javascript | function(bs, data) {
const type = data.type;
if (bs.options.get('json')) {
return console.log(JSON.stringify({
"service:running": {
"options": bs.options.toJS()
}
}));
}
if (type === "server") {
var baseDir = bs.options.getIn(["server", "baseDir"]);
logUrls(bs.options.get("urls").toJS());
if (baseDir) {
if (utils.isList(baseDir)) {
baseDir.forEach(serveFiles);
} else {
serveFiles(baseDir);
}
}
}
if (type === "proxy") {
logger.info(
"Proxying: {cyan:%s}",
bs.options.getIn(["proxy", "target"])
);
logUrls(bs.options.get("urls").toJS());
}
if (type === "snippet") {
if (bs.options.get("logSnippet")) {
logger.info(
"{bold:Copy the following snippet into your website, " +
"just before the closing {cyan:</body>} tag"
);
logger.unprefixed("info", messages.scriptTags(bs.options));
}
logUrls(
bs.options
.get("urls")
.filter(function(value, key) {
return key.slice(0, 2) === "ui";
})
.toJS()
);
}
function serveFiles(base) {
logger.info("Serving files from: {magenta:%s}", base);
}
} | [
"function",
"(",
"bs",
",",
"data",
")",
"{",
"const",
"type",
"=",
"data",
".",
"type",
";",
"if",
"(",
"bs",
".",
"options",
".",
"get",
"(",
"'json'",
")",
")",
"{",
"return",
"console",
".",
"log",
"(",
"JSON",
".",
"stringify",
"(",
"{",
"\"service:running\"",
":",
"{",
"\"options\"",
":",
"bs",
".",
"options",
".",
"toJS",
"(",
")",
"}",
"}",
")",
")",
";",
"}",
"if",
"(",
"type",
"===",
"\"server\"",
")",
"{",
"var",
"baseDir",
"=",
"bs",
".",
"options",
".",
"getIn",
"(",
"[",
"\"server\"",
",",
"\"baseDir\"",
"]",
")",
";",
"logUrls",
"(",
"bs",
".",
"options",
".",
"get",
"(",
"\"urls\"",
")",
".",
"toJS",
"(",
")",
")",
";",
"if",
"(",
"baseDir",
")",
"{",
"if",
"(",
"utils",
".",
"isList",
"(",
"baseDir",
")",
")",
"{",
"baseDir",
".",
"forEach",
"(",
"serveFiles",
")",
";",
"}",
"else",
"{",
"serveFiles",
"(",
"baseDir",
")",
";",
"}",
"}",
"}",
"if",
"(",
"type",
"===",
"\"proxy\"",
")",
"{",
"logger",
".",
"info",
"(",
"\"Proxying: {cyan:%s}\"",
",",
"bs",
".",
"options",
".",
"getIn",
"(",
"[",
"\"proxy\"",
",",
"\"target\"",
"]",
")",
")",
";",
"logUrls",
"(",
"bs",
".",
"options",
".",
"get",
"(",
"\"urls\"",
")",
".",
"toJS",
"(",
")",
")",
";",
"}",
"if",
"(",
"type",
"===",
"\"snippet\"",
")",
"{",
"if",
"(",
"bs",
".",
"options",
".",
"get",
"(",
"\"logSnippet\"",
")",
")",
"{",
"logger",
".",
"info",
"(",
"\"{bold:Copy the following snippet into your website, \"",
"+",
"\"just before the closing {cyan:</body>} tag\"",
")",
";",
"logger",
".",
"unprefixed",
"(",
"\"info\"",
",",
"messages",
".",
"scriptTags",
"(",
"bs",
".",
"options",
")",
")",
";",
"}",
"logUrls",
"(",
"bs",
".",
"options",
".",
"get",
"(",
"\"urls\"",
")",
".",
"filter",
"(",
"function",
"(",
"value",
",",
"key",
")",
"{",
"return",
"key",
".",
"slice",
"(",
"0",
",",
"2",
")",
"===",
"\"ui\"",
";",
"}",
")",
".",
"toJS",
"(",
")",
")",
";",
"}",
"function",
"serveFiles",
"(",
"base",
")",
"{",
"logger",
".",
"info",
"(",
"\"Serving files from: {magenta:%s}\"",
",",
"base",
")",
";",
"}",
"}"
] | Main logging when the service is running
@param {BrowserSync} bs
@param data | [
"Main",
"logging",
"when",
"the",
"service",
"is",
"running"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync/lib/logger.js#L122-L176 |
|
8,059 | BrowserSync/browser-sync | packages/browser-sync/lib/logger.js | getKeyName | function getKeyName(key) {
if (key.indexOf("ui") > -1) {
if (key === "ui") {
return "UI";
}
if (key === "ui-external") {
return "UI External";
}
}
return key.substr(0, 1).toUpperCase() + key.substring(1);
} | javascript | function getKeyName(key) {
if (key.indexOf("ui") > -1) {
if (key === "ui") {
return "UI";
}
if (key === "ui-external") {
return "UI External";
}
}
return key.substr(0, 1).toUpperCase() + key.substring(1);
} | [
"function",
"getKeyName",
"(",
"key",
")",
"{",
"if",
"(",
"key",
".",
"indexOf",
"(",
"\"ui\"",
")",
">",
"-",
"1",
")",
"{",
"if",
"(",
"key",
"===",
"\"ui\"",
")",
"{",
"return",
"\"UI\"",
";",
"}",
"if",
"(",
"key",
"===",
"\"ui-external\"",
")",
"{",
"return",
"\"UI External\"",
";",
"}",
"}",
"return",
"key",
".",
"substr",
"(",
"0",
",",
"1",
")",
".",
"toUpperCase",
"(",
")",
"+",
"key",
".",
"substring",
"(",
"1",
")",
";",
"}"
] | Transform url-key names into something more presentable
@param key
@returns {string} | [
"Transform",
"url",
"-",
"key",
"names",
"into",
"something",
"more",
"presentable"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync/lib/logger.js#L277-L287 |
8,060 | BrowserSync/browser-sync | packages/browser-sync/lib/logger.js | canLogFileChange | function canLogFileChange(bs, data) {
if (data && data.log === false) {
return false;
}
return bs.options.get("logFileChanges");
} | javascript | function canLogFileChange(bs, data) {
if (data && data.log === false) {
return false;
}
return bs.options.get("logFileChanges");
} | [
"function",
"canLogFileChange",
"(",
"bs",
",",
"data",
")",
"{",
"if",
"(",
"data",
"&&",
"data",
".",
"log",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"return",
"bs",
".",
"options",
".",
"get",
"(",
"\"logFileChanges\"",
")",
";",
"}"
] | Determine if file changes should be logged
@param bs
@param data
@returns {boolean} | [
"Determine",
"if",
"file",
"changes",
"should",
"be",
"logged"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync/lib/logger.js#L295-L301 |
8,061 | BrowserSync/browser-sync | packages/browser-sync/lib/server/index.js | createServer | function createServer(bs) {
var proxy = bs.options.get("proxy");
var server = bs.options.get("server");
if (!proxy && !server) {
return require("./snippet-server")(bs);
}
if (proxy) {
return require("./proxy-server")(bs);
}
if (server) {
return require("./static-server")(bs);
}
} | javascript | function createServer(bs) {
var proxy = bs.options.get("proxy");
var server = bs.options.get("server");
if (!proxy && !server) {
return require("./snippet-server")(bs);
}
if (proxy) {
return require("./proxy-server")(bs);
}
if (server) {
return require("./static-server")(bs);
}
} | [
"function",
"createServer",
"(",
"bs",
")",
"{",
"var",
"proxy",
"=",
"bs",
".",
"options",
".",
"get",
"(",
"\"proxy\"",
")",
";",
"var",
"server",
"=",
"bs",
".",
"options",
".",
"get",
"(",
"\"server\"",
")",
";",
"if",
"(",
"!",
"proxy",
"&&",
"!",
"server",
")",
"{",
"return",
"require",
"(",
"\"./snippet-server\"",
")",
"(",
"bs",
")",
";",
"}",
"if",
"(",
"proxy",
")",
"{",
"return",
"require",
"(",
"\"./proxy-server\"",
")",
"(",
"bs",
")",
";",
"}",
"if",
"(",
"server",
")",
"{",
"return",
"require",
"(",
"\"./static-server\"",
")",
"(",
"bs",
")",
";",
"}",
"}"
] | Launch the server for serving the client JS plus static files
@param {BrowserSync} bs
@returns {{staticServer: (http.Server), proxyServer: (http.Server)}} | [
"Launch",
"the",
"server",
"for",
"serving",
"the",
"client",
"JS",
"plus",
"static",
"files"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync/lib/server/index.js#L85-L100 |
8,062 | BrowserSync/browser-sync | packages/browser-sync-ui/tasks/icons.js | icons | function icons (opts, ctx, done) {
return vfs.src(opts.input)
.pipe(easysvg.stream({js: false}))
.on('error', done)
.pipe(vfs.dest(opts.output))
} | javascript | function icons (opts, ctx, done) {
return vfs.src(opts.input)
.pipe(easysvg.stream({js: false}))
.on('error', done)
.pipe(vfs.dest(opts.output))
} | [
"function",
"icons",
"(",
"opts",
",",
"ctx",
",",
"done",
")",
"{",
"return",
"vfs",
".",
"src",
"(",
"opts",
".",
"input",
")",
".",
"pipe",
"(",
"easysvg",
".",
"stream",
"(",
"{",
"js",
":",
"false",
"}",
")",
")",
".",
"on",
"(",
"'error'",
",",
"done",
")",
".",
"pipe",
"(",
"vfs",
".",
"dest",
"(",
"opts",
".",
"output",
")",
")",
"}"
] | Compile SVG Symbols | [
"Compile",
"SVG",
"Symbols"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync-ui/tasks/icons.js#L7-L12 |
8,063 | BrowserSync/browser-sync | packages/browser-sync-ui/src/scripts/services/Pages.js | function ($section) {
angular.forEach(pagesConfig, function (item) {
item.active = false;
});
$section.active = true;
return pagesConfig;
} | javascript | function ($section) {
angular.forEach(pagesConfig, function (item) {
item.active = false;
});
$section.active = true;
return pagesConfig;
} | [
"function",
"(",
"$section",
")",
"{",
"angular",
".",
"forEach",
"(",
"pagesConfig",
",",
"function",
"(",
"item",
")",
"{",
"item",
".",
"active",
"=",
"false",
";",
"}",
")",
";",
"$section",
".",
"active",
"=",
"true",
";",
"return",
"pagesConfig",
";",
"}"
] | Enable a single Item
@param $section
@returns {*} | [
"Enable",
"a",
"single",
"Item"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync-ui/src/scripts/services/Pages.js#L22-L28 |
|
8,064 | BrowserSync/browser-sync | packages/browser-sync-ui/src/scripts/services/Pages.js | function () {
if ($location.path() === "/") {
return pagesConfig["overview"];
}
var match;
angular.forEach(pagesConfig, function (item) {
if (item.path === $location.path()) {
match = item;
}
});
return match;
} | javascript | function () {
if ($location.path() === "/") {
return pagesConfig["overview"];
}
var match;
angular.forEach(pagesConfig, function (item) {
if (item.path === $location.path()) {
match = item;
}
});
return match;
} | [
"function",
"(",
")",
"{",
"if",
"(",
"$location",
".",
"path",
"(",
")",
"===",
"\"/\"",
")",
"{",
"return",
"pagesConfig",
"[",
"\"overview\"",
"]",
";",
"}",
"var",
"match",
";",
"angular",
".",
"forEach",
"(",
"pagesConfig",
",",
"function",
"(",
"item",
")",
"{",
"if",
"(",
"item",
".",
"path",
"===",
"$location",
".",
"path",
"(",
")",
")",
"{",
"match",
"=",
"item",
";",
"}",
"}",
")",
";",
"return",
"match",
";",
"}"
] | Get the current section based on the path
@returns {*} | [
"Get",
"the",
"current",
"section",
"based",
"on",
"the",
"path"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync-ui/src/scripts/services/Pages.js#L43-L54 |
|
8,065 | BrowserSync/browser-sync | packages/browser-sync-ui/lib/async.js | function (ui, done) {
Object.keys(ui.defaultPlugins).forEach(function (key) {
ui.pluginManager.get(key)(ui, ui.bs);
});
done();
} | javascript | function (ui, done) {
Object.keys(ui.defaultPlugins).forEach(function (key) {
ui.pluginManager.get(key)(ui, ui.bs);
});
done();
} | [
"function",
"(",
"ui",
",",
"done",
")",
"{",
"Object",
".",
"keys",
"(",
"ui",
".",
"defaultPlugins",
")",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"ui",
".",
"pluginManager",
".",
"get",
"(",
"key",
")",
"(",
"ui",
",",
"ui",
".",
"bs",
")",
";",
"}",
")",
";",
"done",
"(",
")",
";",
"}"
] | Run default plugins
@param ui
@param done | [
"Run",
"default",
"plugins"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync-ui/lib/async.js#L158-L163 |
|
8,066 | BrowserSync/browser-sync | packages/browser-sync-ui/lib/async.js | function (ui, done) {
var bs = ui.bs;
ui.clients.on("connection", function (client) {
client.emit("ui:connection", ui.options.toJS());
ui.options.get("clientFiles").map(function (item) {
if (item.get("active")) {
ui.addElement(client, item.toJS());
}
});
});
ui.socket.on("connection", function (client) {
client.emit("connection", bs.getOptions().toJS());
client.emit("ui:connection", ui.options.toJS());
client.on("ui:get:options", function () {
client.emit("ui:receive:options", {
bs: bs.getOptions().toJS(),
ui: ui.options.toJS()
});
});
// proxy client events
client.on("ui:client:proxy", function (evt) {
ui.clients.emit(evt.event, evt.data);
});
client.on("ui", function (data) {
ui.delegateEvent(data);
});
});
done();
} | javascript | function (ui, done) {
var bs = ui.bs;
ui.clients.on("connection", function (client) {
client.emit("ui:connection", ui.options.toJS());
ui.options.get("clientFiles").map(function (item) {
if (item.get("active")) {
ui.addElement(client, item.toJS());
}
});
});
ui.socket.on("connection", function (client) {
client.emit("connection", bs.getOptions().toJS());
client.emit("ui:connection", ui.options.toJS());
client.on("ui:get:options", function () {
client.emit("ui:receive:options", {
bs: bs.getOptions().toJS(),
ui: ui.options.toJS()
});
});
// proxy client events
client.on("ui:client:proxy", function (evt) {
ui.clients.emit(evt.event, evt.data);
});
client.on("ui", function (data) {
ui.delegateEvent(data);
});
});
done();
} | [
"function",
"(",
"ui",
",",
"done",
")",
"{",
"var",
"bs",
"=",
"ui",
".",
"bs",
";",
"ui",
".",
"clients",
".",
"on",
"(",
"\"connection\"",
",",
"function",
"(",
"client",
")",
"{",
"client",
".",
"emit",
"(",
"\"ui:connection\"",
",",
"ui",
".",
"options",
".",
"toJS",
"(",
")",
")",
";",
"ui",
".",
"options",
".",
"get",
"(",
"\"clientFiles\"",
")",
".",
"map",
"(",
"function",
"(",
"item",
")",
"{",
"if",
"(",
"item",
".",
"get",
"(",
"\"active\"",
")",
")",
"{",
"ui",
".",
"addElement",
"(",
"client",
",",
"item",
".",
"toJS",
"(",
")",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"ui",
".",
"socket",
".",
"on",
"(",
"\"connection\"",
",",
"function",
"(",
"client",
")",
"{",
"client",
".",
"emit",
"(",
"\"connection\"",
",",
"bs",
".",
"getOptions",
"(",
")",
".",
"toJS",
"(",
")",
")",
";",
"client",
".",
"emit",
"(",
"\"ui:connection\"",
",",
"ui",
".",
"options",
".",
"toJS",
"(",
")",
")",
";",
"client",
".",
"on",
"(",
"\"ui:get:options\"",
",",
"function",
"(",
")",
"{",
"client",
".",
"emit",
"(",
"\"ui:receive:options\"",
",",
"{",
"bs",
":",
"bs",
".",
"getOptions",
"(",
")",
".",
"toJS",
"(",
")",
",",
"ui",
":",
"ui",
".",
"options",
".",
"toJS",
"(",
")",
"}",
")",
";",
"}",
")",
";",
"// proxy client events",
"client",
".",
"on",
"(",
"\"ui:client:proxy\"",
",",
"function",
"(",
"evt",
")",
"{",
"ui",
".",
"clients",
".",
"emit",
"(",
"evt",
".",
"event",
",",
"evt",
".",
"data",
")",
";",
"}",
")",
";",
"client",
".",
"on",
"(",
"\"ui\"",
",",
"function",
"(",
"data",
")",
"{",
"ui",
".",
"delegateEvent",
"(",
"data",
")",
";",
"}",
")",
";",
"}",
")",
";",
"done",
"(",
")",
";",
"}"
] | The most important event is the initial connection where
the options are received from the socket
@param ui
@param done | [
"The",
"most",
"important",
"event",
"is",
"the",
"initial",
"connection",
"where",
"the",
"options",
"are",
"received",
"from",
"the",
"socket"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync-ui/lib/async.js#L170-L208 |
|
8,067 | BrowserSync/browser-sync | packages/browser-sync/lib/file-watcher.js | function(event, path) {
emitter.emit("file:changed", {
event: event,
path: path,
namespace: namespace
});
} | javascript | function(event, path) {
emitter.emit("file:changed", {
event: event,
path: path,
namespace: namespace
});
} | [
"function",
"(",
"event",
",",
"path",
")",
"{",
"emitter",
".",
"emit",
"(",
"\"file:changed\"",
",",
"{",
"event",
":",
"event",
",",
"path",
":",
"path",
",",
"namespace",
":",
"namespace",
"}",
")",
";",
"}"
] | Default CB when not given
@param event
@param path | [
"Default",
"CB",
"when",
"not",
"given"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync/lib/file-watcher.js#L23-L29 |
|
8,068 | BrowserSync/browser-sync | packages/browser-sync/lib/index.js | noop | function noop(name) {
return function() {
var args = Array.prototype.slice.call(arguments);
if (singleton) {
return singleton[name].apply(singleton, args);
} else {
if (publicUtils.isStreamArg(name, args)) {
return new PassThrough({ objectMode: true });
}
}
};
} | javascript | function noop(name) {
return function() {
var args = Array.prototype.slice.call(arguments);
if (singleton) {
return singleton[name].apply(singleton, args);
} else {
if (publicUtils.isStreamArg(name, args)) {
return new PassThrough({ objectMode: true });
}
}
};
} | [
"function",
"noop",
"(",
"name",
")",
"{",
"return",
"function",
"(",
")",
"{",
"var",
"args",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
";",
"if",
"(",
"singleton",
")",
"{",
"return",
"singleton",
"[",
"name",
"]",
".",
"apply",
"(",
"singleton",
",",
"args",
")",
";",
"}",
"else",
"{",
"if",
"(",
"publicUtils",
".",
"isStreamArg",
"(",
"name",
",",
"args",
")",
")",
"{",
"return",
"new",
"PassThrough",
"(",
"{",
"objectMode",
":",
"true",
"}",
")",
";",
"}",
"}",
"}",
";",
"}"
] | Helper to allow methods to be called on the module export
before there's a running instance
@param {String} name
@returns {Function} | [
"Helper",
"to",
"allow",
"methods",
"to",
"be",
"called",
"on",
"the",
"module",
"export",
"before",
"there",
"s",
"a",
"running",
"instance"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync/lib/index.js#L220-L231 |
8,069 | BrowserSync/browser-sync | packages/browser-sync/lib/index.js | getSingle | function getSingle(name) {
if (instances.length) {
var match = instances.filter(function(item) {
return item.name === name;
});
if (match.length) {
return match[0];
}
}
return false;
} | javascript | function getSingle(name) {
if (instances.length) {
var match = instances.filter(function(item) {
return item.name === name;
});
if (match.length) {
return match[0];
}
}
return false;
} | [
"function",
"getSingle",
"(",
"name",
")",
"{",
"if",
"(",
"instances",
".",
"length",
")",
"{",
"var",
"match",
"=",
"instances",
".",
"filter",
"(",
"function",
"(",
"item",
")",
"{",
"return",
"item",
".",
"name",
"===",
"name",
";",
"}",
")",
";",
"if",
"(",
"match",
".",
"length",
")",
"{",
"return",
"match",
"[",
"0",
"]",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Get a single instance by name
@param {String} name
@returns {Object|Boolean} | [
"Get",
"a",
"single",
"instance",
"by",
"name"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync/lib/index.js#L286-L296 |
8,070 | BrowserSync/browser-sync | packages/browser-sync-ui/lib/plugins/network-throttle/network-throttle.js | getUrls | function getUrls (opts) {
var list = [];
var bsLocal = require("url").parse(opts.urls.local);
list.push([bsLocal.protocol + "//", bsLocal.hostname, ":", opts.port].join(""));
if (opts.urls.external) {
var external = require("url").parse(opts.urls.external);
list.push([bsLocal.protocol + "//", external.hostname, ":", opts.port].join(""));
}
return Immutable.List(list);
} | javascript | function getUrls (opts) {
var list = [];
var bsLocal = require("url").parse(opts.urls.local);
list.push([bsLocal.protocol + "//", bsLocal.hostname, ":", opts.port].join(""));
if (opts.urls.external) {
var external = require("url").parse(opts.urls.external);
list.push([bsLocal.protocol + "//", external.hostname, ":", opts.port].join(""));
}
return Immutable.List(list);
} | [
"function",
"getUrls",
"(",
"opts",
")",
"{",
"var",
"list",
"=",
"[",
"]",
";",
"var",
"bsLocal",
"=",
"require",
"(",
"\"url\"",
")",
".",
"parse",
"(",
"opts",
".",
"urls",
".",
"local",
")",
";",
"list",
".",
"push",
"(",
"[",
"bsLocal",
".",
"protocol",
"+",
"\"//\"",
",",
"bsLocal",
".",
"hostname",
",",
"\":\"",
",",
"opts",
".",
"port",
"]",
".",
"join",
"(",
"\"\"",
")",
")",
";",
"if",
"(",
"opts",
".",
"urls",
".",
"external",
")",
"{",
"var",
"external",
"=",
"require",
"(",
"\"url\"",
")",
".",
"parse",
"(",
"opts",
".",
"urls",
".",
"external",
")",
";",
"list",
".",
"push",
"(",
"[",
"bsLocal",
".",
"protocol",
"+",
"\"//\"",
",",
"external",
".",
"hostname",
",",
"\":\"",
",",
"opts",
".",
"port",
"]",
".",
"join",
"(",
"\"\"",
")",
")",
";",
"}",
"return",
"Immutable",
".",
"List",
"(",
"list",
")",
";",
"}"
] | Get local + external urls with a different port
@param opts
@returns {List<T>|List<any>} | [
"Get",
"local",
"+",
"external",
"urls",
"with",
"a",
"different",
"port"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync-ui/lib/plugins/network-throttle/network-throttle.js#L146-L160 |
8,071 | BrowserSync/browser-sync | packages/browser-sync-ui/lib/plugins/history/history.js | function (current, temp) {
if (!Immutable.is(current, temp)) {
validUrls = temp;
methods.sendUpdatedUrls(validUrls);
}
} | javascript | function (current, temp) {
if (!Immutable.is(current, temp)) {
validUrls = temp;
methods.sendUpdatedUrls(validUrls);
}
} | [
"function",
"(",
"current",
",",
"temp",
")",
"{",
"if",
"(",
"!",
"Immutable",
".",
"is",
"(",
"current",
",",
"temp",
")",
")",
"{",
"validUrls",
"=",
"temp",
";",
"methods",
".",
"sendUpdatedUrls",
"(",
"validUrls",
")",
";",
"}",
"}"
] | Only send to UI if list changed
@param current
@param temp | [
"Only",
"send",
"to",
"UI",
"if",
"list",
"changed"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync-ui/lib/plugins/history/history.js#L21-L26 |
|
8,072 | BrowserSync/browser-sync | packages/browser-sync-ui/lib/plugins/history/history.js | function (data) {
var temp = addPath(validUrls, url.parse(data.href), bs.options.get("mode"));
methods.sendUpdatedIfChanged(validUrls, temp, ui.socket);
} | javascript | function (data) {
var temp = addPath(validUrls, url.parse(data.href), bs.options.get("mode"));
methods.sendUpdatedIfChanged(validUrls, temp, ui.socket);
} | [
"function",
"(",
"data",
")",
"{",
"var",
"temp",
"=",
"addPath",
"(",
"validUrls",
",",
"url",
".",
"parse",
"(",
"data",
".",
"href",
")",
",",
"bs",
".",
"options",
".",
"get",
"(",
"\"mode\"",
")",
")",
";",
"methods",
".",
"sendUpdatedIfChanged",
"(",
"validUrls",
",",
"temp",
",",
"ui",
".",
"socket",
")",
";",
"}"
] | Add a new path
@param data | [
"Add",
"a",
"new",
"path"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync-ui/lib/plugins/history/history.js#L46-L49 |
|
8,073 | BrowserSync/browser-sync | packages/browser-sync-ui/lib/plugins/history/history.js | function (data) {
var temp = removePath(validUrls, data.path);
methods.sendUpdatedIfChanged(validUrls, temp, ui.socket);
} | javascript | function (data) {
var temp = removePath(validUrls, data.path);
methods.sendUpdatedIfChanged(validUrls, temp, ui.socket);
} | [
"function",
"(",
"data",
")",
"{",
"var",
"temp",
"=",
"removePath",
"(",
"validUrls",
",",
"data",
".",
"path",
")",
";",
"methods",
".",
"sendUpdatedIfChanged",
"(",
"validUrls",
",",
"temp",
",",
"ui",
".",
"socket",
")",
";",
"}"
] | Remove a path
@param data | [
"Remove",
"a",
"path"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync-ui/lib/plugins/history/history.js#L54-L57 |
|
8,074 | BrowserSync/browser-sync | packages/browser-sync/lib/server/proxy-utils.js | rewriteCookies | function rewriteCookies(rawCookie) {
var objCookie = (function() {
// simple parse function (does not remove quotes)
var obj = {};
var pairs = rawCookie.split(/; */);
pairs.forEach(function(pair) {
var eqIndex = pair.indexOf("=");
// skip things that don't look like key=value
if (eqIndex < 0) {
return;
}
var key = pair.substr(0, eqIndex).trim();
obj[key] = pair.substr(eqIndex + 1, pair.length).trim();
});
return obj;
})();
var pairs = Object.keys(objCookie)
.filter(function(item) {
return item.toLowerCase() !== "domain";
})
.map(function(key) {
return key + "=" + objCookie[key];
});
if (rawCookie.match(/httponly/i)) {
pairs.push("HttpOnly");
}
return pairs.join("; ");
} | javascript | function rewriteCookies(rawCookie) {
var objCookie = (function() {
// simple parse function (does not remove quotes)
var obj = {};
var pairs = rawCookie.split(/; */);
pairs.forEach(function(pair) {
var eqIndex = pair.indexOf("=");
// skip things that don't look like key=value
if (eqIndex < 0) {
return;
}
var key = pair.substr(0, eqIndex).trim();
obj[key] = pair.substr(eqIndex + 1, pair.length).trim();
});
return obj;
})();
var pairs = Object.keys(objCookie)
.filter(function(item) {
return item.toLowerCase() !== "domain";
})
.map(function(key) {
return key + "=" + objCookie[key];
});
if (rawCookie.match(/httponly/i)) {
pairs.push("HttpOnly");
}
return pairs.join("; ");
} | [
"function",
"rewriteCookies",
"(",
"rawCookie",
")",
"{",
"var",
"objCookie",
"=",
"(",
"function",
"(",
")",
"{",
"// simple parse function (does not remove quotes)",
"var",
"obj",
"=",
"{",
"}",
";",
"var",
"pairs",
"=",
"rawCookie",
".",
"split",
"(",
"/",
"; *",
"/",
")",
";",
"pairs",
".",
"forEach",
"(",
"function",
"(",
"pair",
")",
"{",
"var",
"eqIndex",
"=",
"pair",
".",
"indexOf",
"(",
"\"=\"",
")",
";",
"// skip things that don't look like key=value",
"if",
"(",
"eqIndex",
"<",
"0",
")",
"{",
"return",
";",
"}",
"var",
"key",
"=",
"pair",
".",
"substr",
"(",
"0",
",",
"eqIndex",
")",
".",
"trim",
"(",
")",
";",
"obj",
"[",
"key",
"]",
"=",
"pair",
".",
"substr",
"(",
"eqIndex",
"+",
"1",
",",
"pair",
".",
"length",
")",
".",
"trim",
"(",
")",
";",
"}",
")",
";",
"return",
"obj",
";",
"}",
")",
"(",
")",
";",
"var",
"pairs",
"=",
"Object",
".",
"keys",
"(",
"objCookie",
")",
".",
"filter",
"(",
"function",
"(",
"item",
")",
"{",
"return",
"item",
".",
"toLowerCase",
"(",
")",
"!==",
"\"domain\"",
";",
"}",
")",
".",
"map",
"(",
"function",
"(",
"key",
")",
"{",
"return",
"key",
"+",
"\"=\"",
"+",
"objCookie",
"[",
"key",
"]",
";",
"}",
")",
";",
"if",
"(",
"rawCookie",
".",
"match",
"(",
"/",
"httponly",
"/",
"i",
")",
")",
"{",
"pairs",
".",
"push",
"(",
"\"HttpOnly\"",
")",
";",
"}",
"return",
"pairs",
".",
"join",
"(",
"\"; \"",
")",
";",
"}"
] | Remove the domain from any cookies.
@param rawCookie
@returns {string} | [
"Remove",
"the",
"domain",
"from",
"any",
"cookies",
"."
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync/lib/server/proxy-utils.js#L122-L156 |
8,075 | BrowserSync/browser-sync | packages/browser-sync/lib/server/proxy-server.js | applyFns | function applyFns(name, fns) {
if (!List.isList(fns)) fns = [fns];
proxy.on(name, function() {
var args = arguments;
fns.forEach(function(fn) {
if (typeof fn === "function") {
fn.apply(null, args);
}
});
});
} | javascript | function applyFns(name, fns) {
if (!List.isList(fns)) fns = [fns];
proxy.on(name, function() {
var args = arguments;
fns.forEach(function(fn) {
if (typeof fn === "function") {
fn.apply(null, args);
}
});
});
} | [
"function",
"applyFns",
"(",
"name",
",",
"fns",
")",
"{",
"if",
"(",
"!",
"List",
".",
"isList",
"(",
"fns",
")",
")",
"fns",
"=",
"[",
"fns",
"]",
";",
"proxy",
".",
"on",
"(",
"name",
",",
"function",
"(",
")",
"{",
"var",
"args",
"=",
"arguments",
";",
"fns",
".",
"forEach",
"(",
"function",
"(",
"fn",
")",
"{",
"if",
"(",
"typeof",
"fn",
"===",
"\"function\"",
")",
"{",
"fn",
".",
"apply",
"(",
"null",
",",
"args",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}"
] | Apply functions to proxy events
@param {string} name - the name of the http-proxy event
@param {Array} fns - functions to call on each event | [
"Apply",
"functions",
"to",
"proxy",
"events"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync/lib/server/proxy-server.js#L127-L137 |
8,076 | BrowserSync/browser-sync | packages/browser-sync/lib/sockets.js | handleConnection | function handleConnection(client) {
// set ghostmode callbacks
if (bs.options.get("ghostMode")) {
addGhostMode(client);
}
client.emit("connection", bs.options.toJS()); //todo - trim the amount of options sent to clients
emitter.emit("client:connected", {
ua: client.handshake.headers["user-agent"]
});
} | javascript | function handleConnection(client) {
// set ghostmode callbacks
if (bs.options.get("ghostMode")) {
addGhostMode(client);
}
client.emit("connection", bs.options.toJS()); //todo - trim the amount of options sent to clients
emitter.emit("client:connected", {
ua: client.handshake.headers["user-agent"]
});
} | [
"function",
"handleConnection",
"(",
"client",
")",
"{",
"// set ghostmode callbacks",
"if",
"(",
"bs",
".",
"options",
".",
"get",
"(",
"\"ghostMode\"",
")",
")",
"{",
"addGhostMode",
"(",
"client",
")",
";",
"}",
"client",
".",
"emit",
"(",
"\"connection\"",
",",
"bs",
".",
"options",
".",
"toJS",
"(",
")",
")",
";",
"//todo - trim the amount of options sent to clients",
"emitter",
".",
"emit",
"(",
"\"client:connected\"",
",",
"{",
"ua",
":",
"client",
".",
"handshake",
".",
"headers",
"[",
"\"user-agent\"",
"]",
"}",
")",
";",
"}"
] | Handle each new connection
@param {Object} client | [
"Handle",
"each",
"new",
"connection"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync/lib/sockets.js#L54-L65 |
8,077 | BrowserSync/browser-sync | packages/browser-sync-ui/lib/hooks.js | function (hooks, ui) {
var config = hooks
.map(transformConfig)
.reduce(createConfigItem, {});
return {
/**
* pagesConfig - This is the angular configuration such as routes
*/
pagesConfig: configTmpl
.replace("%when%", hooks.reduce(
createAngularRoutes,
""
))
.replace("%pages%", JSON.stringify(
config,
null,
4
)),
/**
* pagesConfig in object form
*/
pagesObj: config,
pageMarkup: function () {
return preAngular(ui.pluginManager.plugins, config, ui);
}
};
} | javascript | function (hooks, ui) {
var config = hooks
.map(transformConfig)
.reduce(createConfigItem, {});
return {
/**
* pagesConfig - This is the angular configuration such as routes
*/
pagesConfig: configTmpl
.replace("%when%", hooks.reduce(
createAngularRoutes,
""
))
.replace("%pages%", JSON.stringify(
config,
null,
4
)),
/**
* pagesConfig in object form
*/
pagesObj: config,
pageMarkup: function () {
return preAngular(ui.pluginManager.plugins, config, ui);
}
};
} | [
"function",
"(",
"hooks",
",",
"ui",
")",
"{",
"var",
"config",
"=",
"hooks",
".",
"map",
"(",
"transformConfig",
")",
".",
"reduce",
"(",
"createConfigItem",
",",
"{",
"}",
")",
";",
"return",
"{",
"/**\n * pagesConfig - This is the angular configuration such as routes\n */",
"pagesConfig",
":",
"configTmpl",
".",
"replace",
"(",
"\"%when%\"",
",",
"hooks",
".",
"reduce",
"(",
"createAngularRoutes",
",",
"\"\"",
")",
")",
".",
"replace",
"(",
"\"%pages%\"",
",",
"JSON",
".",
"stringify",
"(",
"config",
",",
"null",
",",
"4",
")",
")",
",",
"/**\n * pagesConfig in object form\n */",
"pagesObj",
":",
"config",
",",
"pageMarkup",
":",
"function",
"(",
")",
"{",
"return",
"preAngular",
"(",
"ui",
".",
"pluginManager",
".",
"plugins",
",",
"config",
",",
"ui",
")",
";",
"}",
"}",
";",
"}"
] | Create the url config for each section of the ui
@param hooks
@param ui | [
"Create",
"the",
"url",
"config",
"for",
"each",
"section",
"of",
"the",
"ui"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync-ui/lib/hooks.js#L23-L51 |
|
8,078 | BrowserSync/browser-sync | packages/browser-sync-ui/lib/hooks.js | function (hooks) {
var obj = {};
hooks.forEach(function (elements) {
elements.forEach(function (item) {
if (!obj[item.name]) {
obj[item.name] = item;
}
});
});
return obj;
} | javascript | function (hooks) {
var obj = {};
hooks.forEach(function (elements) {
elements.forEach(function (item) {
if (!obj[item.name]) {
obj[item.name] = item;
}
});
});
return obj;
} | [
"function",
"(",
"hooks",
")",
"{",
"var",
"obj",
"=",
"{",
"}",
";",
"hooks",
".",
"forEach",
"(",
"function",
"(",
"elements",
")",
"{",
"elements",
".",
"forEach",
"(",
"function",
"(",
"item",
")",
"{",
"if",
"(",
"!",
"obj",
"[",
"item",
".",
"name",
"]",
")",
"{",
"obj",
"[",
"item",
".",
"name",
"]",
"=",
"item",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"return",
"obj",
";",
"}"
] | Allow plugins to register toggle-able elements
@param hooks
@returns {{}} | [
"Allow",
"plugins",
"to",
"register",
"toggle",
"-",
"able",
"elements"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync-ui/lib/hooks.js#L148-L158 |
|
8,079 | BrowserSync/browser-sync | packages/browser-sync/lib/server/utils.js | function(app, options) {
return {
server: (function() {
var httpModule = serverUtils.getHttpModule(options);
if (
options.get("scheme") === "https" ||
options.get("httpModule") === "http2"
) {
var opts = serverUtils.getHttpsOptions(options);
return httpModule.createServer(opts.toJS(), app);
}
return httpModule.createServer(app);
})(),
app: app
};
} | javascript | function(app, options) {
return {
server: (function() {
var httpModule = serverUtils.getHttpModule(options);
if (
options.get("scheme") === "https" ||
options.get("httpModule") === "http2"
) {
var opts = serverUtils.getHttpsOptions(options);
return httpModule.createServer(opts.toJS(), app);
}
return httpModule.createServer(app);
})(),
app: app
};
} | [
"function",
"(",
"app",
",",
"options",
")",
"{",
"return",
"{",
"server",
":",
"(",
"function",
"(",
")",
"{",
"var",
"httpModule",
"=",
"serverUtils",
".",
"getHttpModule",
"(",
"options",
")",
";",
"if",
"(",
"options",
".",
"get",
"(",
"\"scheme\"",
")",
"===",
"\"https\"",
"||",
"options",
".",
"get",
"(",
"\"httpModule\"",
")",
"===",
"\"http2\"",
")",
"{",
"var",
"opts",
"=",
"serverUtils",
".",
"getHttpsOptions",
"(",
"options",
")",
";",
"return",
"httpModule",
".",
"createServer",
"(",
"opts",
".",
"toJS",
"(",
")",
",",
"app",
")",
";",
"}",
"return",
"httpModule",
".",
"createServer",
"(",
"app",
")",
";",
"}",
")",
"(",
")",
",",
"app",
":",
"app",
"}",
";",
"}"
] | Get either http or https server
or use the httpModule provided in options if present | [
"Get",
"either",
"http",
"or",
"https",
"server",
"or",
"use",
"the",
"httpModule",
"provided",
"in",
"options",
"if",
"present"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync/lib/server/utils.js#L86-L103 |
|
8,080 | BrowserSync/browser-sync | packages/browser-sync/lib/public/public-utils.js | function(name, args) {
if (name === "stream") {
return true;
}
if (name !== "reload") {
return false;
}
var firstArg = args[0];
/**
* If here, it's reload with args
*/
if (_.isObject(firstArg)) {
if (!Array.isArray(firstArg) && Object.keys(firstArg).length) {
return firstArg.stream === true;
}
}
return false;
} | javascript | function(name, args) {
if (name === "stream") {
return true;
}
if (name !== "reload") {
return false;
}
var firstArg = args[0];
/**
* If here, it's reload with args
*/
if (_.isObject(firstArg)) {
if (!Array.isArray(firstArg) && Object.keys(firstArg).length) {
return firstArg.stream === true;
}
}
return false;
} | [
"function",
"(",
"name",
",",
"args",
")",
"{",
"if",
"(",
"name",
"===",
"\"stream\"",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"name",
"!==",
"\"reload\"",
")",
"{",
"return",
"false",
";",
"}",
"var",
"firstArg",
"=",
"args",
"[",
"0",
"]",
";",
"/**\n * If here, it's reload with args\n */",
"if",
"(",
"_",
".",
"isObject",
"(",
"firstArg",
")",
")",
"{",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"firstArg",
")",
"&&",
"Object",
".",
"keys",
"(",
"firstArg",
")",
".",
"length",
")",
"{",
"return",
"firstArg",
".",
"stream",
"===",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | This code handles the switch between .reload & .stream
since 2.6.0
@param name
@param args
@returns {boolean} | [
"This",
"code",
"handles",
"the",
"switch",
"between",
".",
"reload",
"&",
".",
"stream",
"since",
"2",
".",
"6",
".",
"0"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync/lib/public/public-utils.js#L42-L63 |
|
8,081 | BrowserSync/browser-sync | packages/browser-sync/lib/async.js | function(bs, done) {
utils.getPorts(bs.options, function(err, port) {
if (err) {
return utils.fail(true, err, bs.cb);
}
bs.debug("Found a free port: {magenta:%s", port);
done(null, {
options: {
port: port
}
});
});
} | javascript | function(bs, done) {
utils.getPorts(bs.options, function(err, port) {
if (err) {
return utils.fail(true, err, bs.cb);
}
bs.debug("Found a free port: {magenta:%s", port);
done(null, {
options: {
port: port
}
});
});
} | [
"function",
"(",
"bs",
",",
"done",
")",
"{",
"utils",
".",
"getPorts",
"(",
"bs",
".",
"options",
",",
"function",
"(",
"err",
",",
"port",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"utils",
".",
"fail",
"(",
"true",
",",
"err",
",",
"bs",
".",
"cb",
")",
";",
"}",
"bs",
".",
"debug",
"(",
"\"Found a free port: {magenta:%s\"",
",",
"port",
")",
";",
"done",
"(",
"null",
",",
"{",
"options",
":",
"{",
"port",
":",
"port",
"}",
"}",
")",
";",
"}",
")",
";",
"}"
] | BrowserSync needs at least 1 free port.
It will check the one provided in config
and keep incrementing until an available one is found.
@param {BrowserSync} bs
@param {Function} done | [
"BrowserSync",
"needs",
"at",
"least",
"1",
"free",
"port",
".",
"It",
"will",
"check",
"the",
"one",
"provided",
"in",
"config",
"and",
"keep",
"incrementing",
"until",
"an",
"available",
"one",
"is",
"found",
"."
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync/lib/async.js#L18-L30 |
|
8,082 | BrowserSync/browser-sync | packages/browser-sync/lib/async.js | function(bs, done) {
/**
* An extra port is not needed in snippet/server mode
*/
if (bs.options.get("mode") !== "proxy") {
return done();
}
/**
* Web socket support is disabled by default
*/
if (!bs.options.getIn(["proxy", "ws"])) {
return done();
}
/**
* Use 1 higher than server port by default...
*/
var socketPort = bs.options.get("port") + 1;
/**
* Or use the user-defined socket.port option instead
*/
if (bs.options.hasIn(["socket", "port"])) {
socketPort = bs.options.getIn(["socket", "port"]);
}
utils.getPort(bs.options.get("listen", "localhost"), socketPort, null, function(err, port) {
if (err) {
return utils.fail(true, err, bs.cb);
}
done(null, {
optionsIn: [
{
path: ["socket", "port"],
value: port
}
]
});
});
} | javascript | function(bs, done) {
/**
* An extra port is not needed in snippet/server mode
*/
if (bs.options.get("mode") !== "proxy") {
return done();
}
/**
* Web socket support is disabled by default
*/
if (!bs.options.getIn(["proxy", "ws"])) {
return done();
}
/**
* Use 1 higher than server port by default...
*/
var socketPort = bs.options.get("port") + 1;
/**
* Or use the user-defined socket.port option instead
*/
if (bs.options.hasIn(["socket", "port"])) {
socketPort = bs.options.getIn(["socket", "port"]);
}
utils.getPort(bs.options.get("listen", "localhost"), socketPort, null, function(err, port) {
if (err) {
return utils.fail(true, err, bs.cb);
}
done(null, {
optionsIn: [
{
path: ["socket", "port"],
value: port
}
]
});
});
} | [
"function",
"(",
"bs",
",",
"done",
")",
"{",
"/**\n * An extra port is not needed in snippet/server mode\n */",
"if",
"(",
"bs",
".",
"options",
".",
"get",
"(",
"\"mode\"",
")",
"!==",
"\"proxy\"",
")",
"{",
"return",
"done",
"(",
")",
";",
"}",
"/**\n * Web socket support is disabled by default\n */",
"if",
"(",
"!",
"bs",
".",
"options",
".",
"getIn",
"(",
"[",
"\"proxy\"",
",",
"\"ws\"",
"]",
")",
")",
"{",
"return",
"done",
"(",
")",
";",
"}",
"/**\n * Use 1 higher than server port by default...\n */",
"var",
"socketPort",
"=",
"bs",
".",
"options",
".",
"get",
"(",
"\"port\"",
")",
"+",
"1",
";",
"/**\n * Or use the user-defined socket.port option instead\n */",
"if",
"(",
"bs",
".",
"options",
".",
"hasIn",
"(",
"[",
"\"socket\"",
",",
"\"port\"",
"]",
")",
")",
"{",
"socketPort",
"=",
"bs",
".",
"options",
".",
"getIn",
"(",
"[",
"\"socket\"",
",",
"\"port\"",
"]",
")",
";",
"}",
"utils",
".",
"getPort",
"(",
"bs",
".",
"options",
".",
"get",
"(",
"\"listen\"",
",",
"\"localhost\"",
")",
",",
"socketPort",
",",
"null",
",",
"function",
"(",
"err",
",",
"port",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"utils",
".",
"fail",
"(",
"true",
",",
"err",
",",
"bs",
".",
"cb",
")",
";",
"}",
"done",
"(",
"null",
",",
"{",
"optionsIn",
":",
"[",
"{",
"path",
":",
"[",
"\"socket\"",
",",
"\"port\"",
"]",
",",
"value",
":",
"port",
"}",
"]",
"}",
")",
";",
"}",
")",
";",
"}"
] | If the running mode is proxy, we'll use a separate port
for the Browsersync web-socket server. This is to eliminate any issues
with trying to proxy web sockets through to the users server.
@param bs
@param done | [
"If",
"the",
"running",
"mode",
"is",
"proxy",
"we",
"ll",
"use",
"a",
"separate",
"port",
"for",
"the",
"Browsersync",
"web",
"-",
"socket",
"server",
".",
"This",
"is",
"to",
"eliminate",
"any",
"issues",
"with",
"trying",
"to",
"proxy",
"web",
"sockets",
"through",
"to",
"the",
"users",
"server",
"."
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync/lib/async.js#L38-L78 |
|
8,083 | BrowserSync/browser-sync | packages/browser-sync/lib/async.js | function(bs, done) {
var plugins = bs.options
.get("plugins")
.map(pluginUtils.resolvePlugin)
.map(pluginUtils.requirePlugin);
plugins.forEach(function(plugin) {
if (plugin.get("errors").size) {
return logPluginError(plugin);
}
var jsPlugin = plugin.toJS();
jsPlugin.options = jsPlugin.options || {};
jsPlugin.options.moduleName = jsPlugin.moduleName;
bs.registerPlugin(jsPlugin.module, jsPlugin.options);
});
function logPluginError(plugin) {
utils.fail(true, plugin.getIn(["errors", 0]), bs.cb);
}
done();
} | javascript | function(bs, done) {
var plugins = bs.options
.get("plugins")
.map(pluginUtils.resolvePlugin)
.map(pluginUtils.requirePlugin);
plugins.forEach(function(plugin) {
if (plugin.get("errors").size) {
return logPluginError(plugin);
}
var jsPlugin = plugin.toJS();
jsPlugin.options = jsPlugin.options || {};
jsPlugin.options.moduleName = jsPlugin.moduleName;
bs.registerPlugin(jsPlugin.module, jsPlugin.options);
});
function logPluginError(plugin) {
utils.fail(true, plugin.getIn(["errors", 0]), bs.cb);
}
done();
} | [
"function",
"(",
"bs",
",",
"done",
")",
"{",
"var",
"plugins",
"=",
"bs",
".",
"options",
".",
"get",
"(",
"\"plugins\"",
")",
".",
"map",
"(",
"pluginUtils",
".",
"resolvePlugin",
")",
".",
"map",
"(",
"pluginUtils",
".",
"requirePlugin",
")",
";",
"plugins",
".",
"forEach",
"(",
"function",
"(",
"plugin",
")",
"{",
"if",
"(",
"plugin",
".",
"get",
"(",
"\"errors\"",
")",
".",
"size",
")",
"{",
"return",
"logPluginError",
"(",
"plugin",
")",
";",
"}",
"var",
"jsPlugin",
"=",
"plugin",
".",
"toJS",
"(",
")",
";",
"jsPlugin",
".",
"options",
"=",
"jsPlugin",
".",
"options",
"||",
"{",
"}",
";",
"jsPlugin",
".",
"options",
".",
"moduleName",
"=",
"jsPlugin",
".",
"moduleName",
";",
"bs",
".",
"registerPlugin",
"(",
"jsPlugin",
".",
"module",
",",
"jsPlugin",
".",
"options",
")",
";",
"}",
")",
";",
"function",
"logPluginError",
"(",
"plugin",
")",
"{",
"utils",
".",
"fail",
"(",
"true",
",",
"plugin",
".",
"getIn",
"(",
"[",
"\"errors\"",
",",
"0",
"]",
")",
",",
"bs",
".",
"cb",
")",
";",
"}",
"done",
"(",
")",
";",
"}"
] | Try to load plugins that were given in options
@param {BrowserSync} bs
@param {Function} done | [
"Try",
"to",
"load",
"plugins",
"that",
"were",
"given",
"in",
"options"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync/lib/async.js#L119-L140 |
|
8,084 | BrowserSync/browser-sync | packages/browser-sync/lib/internal-events.js | function(data) {
var mode = bs.options.get("mode");
var open = bs.options.get("open");
if (
mode === "proxy" ||
mode === "server" ||
open === "ui" ||
open === "ui-external"
) {
utils.openBrowser(data.url, bs.options, bs);
}
// log about any file watching
if (bs.watchers) {
bs.events.emit("file:watching", bs.watchers);
}
} | javascript | function(data) {
var mode = bs.options.get("mode");
var open = bs.options.get("open");
if (
mode === "proxy" ||
mode === "server" ||
open === "ui" ||
open === "ui-external"
) {
utils.openBrowser(data.url, bs.options, bs);
}
// log about any file watching
if (bs.watchers) {
bs.events.emit("file:watching", bs.watchers);
}
} | [
"function",
"(",
"data",
")",
"{",
"var",
"mode",
"=",
"bs",
".",
"options",
".",
"get",
"(",
"\"mode\"",
")",
";",
"var",
"open",
"=",
"bs",
".",
"options",
".",
"get",
"(",
"\"open\"",
")",
";",
"if",
"(",
"mode",
"===",
"\"proxy\"",
"||",
"mode",
"===",
"\"server\"",
"||",
"open",
"===",
"\"ui\"",
"||",
"open",
"===",
"\"ui-external\"",
")",
"{",
"utils",
".",
"openBrowser",
"(",
"data",
".",
"url",
",",
"bs",
".",
"options",
",",
"bs",
")",
";",
"}",
"// log about any file watching",
"if",
"(",
"bs",
".",
"watchers",
")",
"{",
"bs",
".",
"events",
".",
"emit",
"(",
"\"file:watching\"",
",",
"bs",
".",
"watchers",
")",
";",
"}",
"}"
] | Things that happened after the service is running
@param data | [
"Things",
"that",
"happened",
"after",
"the",
"service",
"is",
"running"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync/lib/internal-events.js#L35-L52 |
|
8,085 | BrowserSync/browser-sync | packages/browser-sync/lib/internal-events.js | function(data) {
if (data.active) {
bs.pluginManager.enablePlugin(data.name);
} else {
bs.pluginManager.disablePlugin(data.name);
}
bs.setOption("userPlugins", bs.getUserPlugins());
} | javascript | function(data) {
if (data.active) {
bs.pluginManager.enablePlugin(data.name);
} else {
bs.pluginManager.disablePlugin(data.name);
}
bs.setOption("userPlugins", bs.getUserPlugins());
} | [
"function",
"(",
"data",
")",
"{",
"if",
"(",
"data",
".",
"active",
")",
"{",
"bs",
".",
"pluginManager",
".",
"enablePlugin",
"(",
"data",
".",
"name",
")",
";",
"}",
"else",
"{",
"bs",
".",
"pluginManager",
".",
"disablePlugin",
"(",
"data",
".",
"name",
")",
";",
"}",
"bs",
".",
"setOption",
"(",
"\"userPlugins\"",
",",
"bs",
".",
"getUserPlugins",
"(",
")",
")",
";",
"}"
] | Plugin configuration setting
@param data | [
"Plugin",
"configuration",
"setting"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync/lib/internal-events.js#L66-L73 |
|
8,086 | BrowserSync/browser-sync | packages/browser-sync-client/index.js | setHeaders | function setHeaders(res, body) {
res.setHeader("Cache-Control", "public, max-age=0");
res.setHeader("Content-Type", "text/javascript");
res.setHeader("ETag", etag(body));
} | javascript | function setHeaders(res, body) {
res.setHeader("Cache-Control", "public, max-age=0");
res.setHeader("Content-Type", "text/javascript");
res.setHeader("ETag", etag(body));
} | [
"function",
"setHeaders",
"(",
"res",
",",
"body",
")",
"{",
"res",
".",
"setHeader",
"(",
"\"Cache-Control\"",
",",
"\"public, max-age=0\"",
")",
";",
"res",
".",
"setHeader",
"(",
"\"Content-Type\"",
",",
"\"text/javascript\"",
")",
";",
"res",
".",
"setHeader",
"(",
"\"ETag\"",
",",
"etag",
"(",
"body",
")",
")",
";",
"}"
] | Set headers on the response
@param {Object} res
@param {String} body | [
"Set",
"headers",
"on",
"the",
"response"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync-client/index.js#L27-L31 |
8,087 | BrowserSync/browser-sync | packages/browser-sync-client/index.js | init | function init(options, requestBody, type) {
/**
* If the user asked for a file, simply return the string.
*/
if (type && type === "file") {
return processItems(requestBody);
}
/**
* Otherwise return a function to be used a middleware
*/
return function(req, res) {
/**
* default to using the uncompressed string
* @type {String}
*/
var output = processItems(requestBody);
/**
* Set the appropriate headers for caching
*/
setHeaders(res, output);
if (isConditionalGet(req) && fresh(req.headers, res._headers)) {
return notModified(res);
}
/**
* If gzip is supported, compress the string once
* and save for future requests
*/
if (supportsGzip(req)) {
res.setHeader("Content-Encoding", "gzip");
var buf = new Buffer(output, "utf-8");
zlib.gzip(buf, function(_, result) {
res.end(result);
});
} else {
res.end(output);
}
};
} | javascript | function init(options, requestBody, type) {
/**
* If the user asked for a file, simply return the string.
*/
if (type && type === "file") {
return processItems(requestBody);
}
/**
* Otherwise return a function to be used a middleware
*/
return function(req, res) {
/**
* default to using the uncompressed string
* @type {String}
*/
var output = processItems(requestBody);
/**
* Set the appropriate headers for caching
*/
setHeaders(res, output);
if (isConditionalGet(req) && fresh(req.headers, res._headers)) {
return notModified(res);
}
/**
* If gzip is supported, compress the string once
* and save for future requests
*/
if (supportsGzip(req)) {
res.setHeader("Content-Encoding", "gzip");
var buf = new Buffer(output, "utf-8");
zlib.gzip(buf, function(_, result) {
res.end(result);
});
} else {
res.end(output);
}
};
} | [
"function",
"init",
"(",
"options",
",",
"requestBody",
",",
"type",
")",
"{",
"/**\n * If the user asked for a file, simply return the string.\n */",
"if",
"(",
"type",
"&&",
"type",
"===",
"\"file\"",
")",
"{",
"return",
"processItems",
"(",
"requestBody",
")",
";",
"}",
"/**\n * Otherwise return a function to be used a middleware\n */",
"return",
"function",
"(",
"req",
",",
"res",
")",
"{",
"/**\n * default to using the uncompressed string\n * @type {String}\n */",
"var",
"output",
"=",
"processItems",
"(",
"requestBody",
")",
";",
"/**\n * Set the appropriate headers for caching\n */",
"setHeaders",
"(",
"res",
",",
"output",
")",
";",
"if",
"(",
"isConditionalGet",
"(",
"req",
")",
"&&",
"fresh",
"(",
"req",
".",
"headers",
",",
"res",
".",
"_headers",
")",
")",
"{",
"return",
"notModified",
"(",
"res",
")",
";",
"}",
"/**\n * If gzip is supported, compress the string once\n * and save for future requests\n */",
"if",
"(",
"supportsGzip",
"(",
"req",
")",
")",
"{",
"res",
".",
"setHeader",
"(",
"\"Content-Encoding\"",
",",
"\"gzip\"",
")",
";",
"var",
"buf",
"=",
"new",
"Buffer",
"(",
"output",
",",
"\"utf-8\"",
")",
";",
"zlib",
".",
"gzip",
"(",
"buf",
",",
"function",
"(",
"_",
",",
"result",
")",
"{",
"res",
".",
"end",
"(",
"result",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"res",
".",
"end",
"(",
"output",
")",
";",
"}",
"}",
";",
"}"
] | Public method for returning either a middleware fn
or the content as a string
@param {Object} options
@param requestBody
@param {String} type - either `file` or `middleware`
@returns {*} | [
"Public",
"method",
"for",
"returning",
"either",
"a",
"middleware",
"fn",
"or",
"the",
"content",
"as",
"a",
"string"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync-client/index.js#L73-L113 |
8,088 | BrowserSync/browser-sync | packages/browser-sync/lib/browser-sync.js | setOptions | function setOptions(bs, options) {
/**
* If multiple options were set, act on the immutable map
* in an efficient way
*/
if (Object.keys(options).length > 1) {
bs.setMany(function(item) {
Object.keys(options).forEach(function(key) {
item.set(key, options[key]);
return item;
});
});
} else {
Object.keys(options).forEach(function(key) {
bs.setOption(key, options[key]);
});
}
} | javascript | function setOptions(bs, options) {
/**
* If multiple options were set, act on the immutable map
* in an efficient way
*/
if (Object.keys(options).length > 1) {
bs.setMany(function(item) {
Object.keys(options).forEach(function(key) {
item.set(key, options[key]);
return item;
});
});
} else {
Object.keys(options).forEach(function(key) {
bs.setOption(key, options[key]);
});
}
} | [
"function",
"setOptions",
"(",
"bs",
",",
"options",
")",
"{",
"/**\n * If multiple options were set, act on the immutable map\n * in an efficient way\n */",
"if",
"(",
"Object",
".",
"keys",
"(",
"options",
")",
".",
"length",
">",
"1",
")",
"{",
"bs",
".",
"setMany",
"(",
"function",
"(",
"item",
")",
"{",
"Object",
".",
"keys",
"(",
"options",
")",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"item",
".",
"set",
"(",
"key",
",",
"options",
"[",
"key",
"]",
")",
";",
"return",
"item",
";",
"}",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"Object",
".",
"keys",
"(",
"options",
")",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"bs",
".",
"setOption",
"(",
"key",
",",
"options",
"[",
"key",
"]",
")",
";",
"}",
")",
";",
"}",
"}"
] | Update the options Map
@param bs
@param options | [
"Update",
"the",
"options",
"Map"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync/lib/browser-sync.js#L201-L218 |
8,089 | BrowserSync/browser-sync | packages/browser-sync/lib/browser-sync.js | tasksComplete | function tasksComplete(bs) {
return function(err) {
if (err) {
bs.logger.setOnce("useLevelPrefixes", true).error(err.message);
}
/**
* Set active flag
*/
bs.active = true;
/**
* @deprecated
*/
bs.events.emit("init", bs);
/**
* This is no-longer needed as the Callback now only resolves
* when everything (including slow things, like the tunnel) is ready.
* It's here purely for backwards compatibility.
* @deprecated
*/
bs.events.emit("service:running", {
options: bs.options,
baseDir: bs.options.getIn(["server", "baseDir"]),
type: bs.options.get("mode"),
port: bs.options.get("port"),
url: bs.options.getIn(["urls", "local"]),
urls: bs.options.get("urls").toJS(),
tunnel: bs.options.getIn(["urls", "tunnel"])
});
/**
* Call any option-provided callbacks
*/
bs.callback("ready", null, bs);
/**
* Finally, call the user-provided callback given as last arg
*/
bs.cb(null, bs);
};
} | javascript | function tasksComplete(bs) {
return function(err) {
if (err) {
bs.logger.setOnce("useLevelPrefixes", true).error(err.message);
}
/**
* Set active flag
*/
bs.active = true;
/**
* @deprecated
*/
bs.events.emit("init", bs);
/**
* This is no-longer needed as the Callback now only resolves
* when everything (including slow things, like the tunnel) is ready.
* It's here purely for backwards compatibility.
* @deprecated
*/
bs.events.emit("service:running", {
options: bs.options,
baseDir: bs.options.getIn(["server", "baseDir"]),
type: bs.options.get("mode"),
port: bs.options.get("port"),
url: bs.options.getIn(["urls", "local"]),
urls: bs.options.get("urls").toJS(),
tunnel: bs.options.getIn(["urls", "tunnel"])
});
/**
* Call any option-provided callbacks
*/
bs.callback("ready", null, bs);
/**
* Finally, call the user-provided callback given as last arg
*/
bs.cb(null, bs);
};
} | [
"function",
"tasksComplete",
"(",
"bs",
")",
"{",
"return",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"bs",
".",
"logger",
".",
"setOnce",
"(",
"\"useLevelPrefixes\"",
",",
"true",
")",
".",
"error",
"(",
"err",
".",
"message",
")",
";",
"}",
"/**\n * Set active flag\n */",
"bs",
".",
"active",
"=",
"true",
";",
"/**\n * @deprecated\n */",
"bs",
".",
"events",
".",
"emit",
"(",
"\"init\"",
",",
"bs",
")",
";",
"/**\n * This is no-longer needed as the Callback now only resolves\n * when everything (including slow things, like the tunnel) is ready.\n * It's here purely for backwards compatibility.\n * @deprecated\n */",
"bs",
".",
"events",
".",
"emit",
"(",
"\"service:running\"",
",",
"{",
"options",
":",
"bs",
".",
"options",
",",
"baseDir",
":",
"bs",
".",
"options",
".",
"getIn",
"(",
"[",
"\"server\"",
",",
"\"baseDir\"",
"]",
")",
",",
"type",
":",
"bs",
".",
"options",
".",
"get",
"(",
"\"mode\"",
")",
",",
"port",
":",
"bs",
".",
"options",
".",
"get",
"(",
"\"port\"",
")",
",",
"url",
":",
"bs",
".",
"options",
".",
"getIn",
"(",
"[",
"\"urls\"",
",",
"\"local\"",
"]",
")",
",",
"urls",
":",
"bs",
".",
"options",
".",
"get",
"(",
"\"urls\"",
")",
".",
"toJS",
"(",
")",
",",
"tunnel",
":",
"bs",
".",
"options",
".",
"getIn",
"(",
"[",
"\"urls\"",
",",
"\"tunnel\"",
"]",
")",
"}",
")",
";",
"/**\n * Call any option-provided callbacks\n */",
"bs",
".",
"callback",
"(",
"\"ready\"",
",",
"null",
",",
"bs",
")",
";",
"/**\n * Finally, call the user-provided callback given as last arg\n */",
"bs",
".",
"cb",
"(",
"null",
",",
"bs",
")",
";",
"}",
";",
"}"
] | At this point, ALL async tasks have completed
@param {BrowserSync} bs
@returns {Function} | [
"At",
"this",
"point",
"ALL",
"async",
"tasks",
"have",
"completed"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync/lib/browser-sync.js#L225-L267 |
8,090 | BrowserSync/browser-sync | packages/browser-sync-ui/lib/UI.js | taskRunner | function taskRunner (ui) {
return function (item, cb) {
ui.logger.debug("Starting Step: " + item.step);
/**
* Give each step access to the UI Instance
*/
item.fn(ui, function (err, out) {
if (err) {
return cb(err);
}
if (out) {
handleOut(ui, out);
}
ui.logger.debug("{green:Step Complete: " + item.step);
cb();
});
};
} | javascript | function taskRunner (ui) {
return function (item, cb) {
ui.logger.debug("Starting Step: " + item.step);
/**
* Give each step access to the UI Instance
*/
item.fn(ui, function (err, out) {
if (err) {
return cb(err);
}
if (out) {
handleOut(ui, out);
}
ui.logger.debug("{green:Step Complete: " + item.step);
cb();
});
};
} | [
"function",
"taskRunner",
"(",
"ui",
")",
"{",
"return",
"function",
"(",
"item",
",",
"cb",
")",
"{",
"ui",
".",
"logger",
".",
"debug",
"(",
"\"Starting Step: \"",
"+",
"item",
".",
"step",
")",
";",
"/**\n * Give each step access to the UI Instance\n */",
"item",
".",
"fn",
"(",
"ui",
",",
"function",
"(",
"err",
",",
"out",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"cb",
"(",
"err",
")",
";",
"}",
"if",
"(",
"out",
")",
"{",
"handleOut",
"(",
"ui",
",",
"out",
")",
";",
"}",
"ui",
".",
"logger",
".",
"debug",
"(",
"\"{green:Step Complete: \"",
"+",
"item",
".",
"step",
")",
";",
"cb",
"(",
")",
";",
"}",
")",
";",
"}",
";",
"}"
] | Run each setup task in sequence
@param ui
@returns {Function} | [
"Run",
"each",
"setup",
"task",
"in",
"sequence"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync-ui/lib/UI.js#L175-L195 |
8,091 | BrowserSync/browser-sync | packages/browser-sync-ui/lib/UI.js | handleOut | function handleOut (ui, out) {
if (out.options) {
Object.keys(out.options).forEach(function (key) {
ui.options = ui.options.set(key, out.options[key]);
});
}
if (out.optionsIn) {
out.optionsIn.forEach(function (item) {
ui.options = ui.options.setIn(item.path, item.value);
});
}
if (out.instance) {
Object.keys(out.instance).forEach(function (key) {
ui[key] = out.instance[key];
});
}
} | javascript | function handleOut (ui, out) {
if (out.options) {
Object.keys(out.options).forEach(function (key) {
ui.options = ui.options.set(key, out.options[key]);
});
}
if (out.optionsIn) {
out.optionsIn.forEach(function (item) {
ui.options = ui.options.setIn(item.path, item.value);
});
}
if (out.instance) {
Object.keys(out.instance).forEach(function (key) {
ui[key] = out.instance[key];
});
}
} | [
"function",
"handleOut",
"(",
"ui",
",",
"out",
")",
"{",
"if",
"(",
"out",
".",
"options",
")",
"{",
"Object",
".",
"keys",
"(",
"out",
".",
"options",
")",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"ui",
".",
"options",
"=",
"ui",
".",
"options",
".",
"set",
"(",
"key",
",",
"out",
".",
"options",
"[",
"key",
"]",
")",
";",
"}",
")",
";",
"}",
"if",
"(",
"out",
".",
"optionsIn",
")",
"{",
"out",
".",
"optionsIn",
".",
"forEach",
"(",
"function",
"(",
"item",
")",
"{",
"ui",
".",
"options",
"=",
"ui",
".",
"options",
".",
"setIn",
"(",
"item",
".",
"path",
",",
"item",
".",
"value",
")",
";",
"}",
")",
";",
"}",
"if",
"(",
"out",
".",
"instance",
")",
"{",
"Object",
".",
"keys",
"(",
"out",
".",
"instance",
")",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"ui",
"[",
"key",
"]",
"=",
"out",
".",
"instance",
"[",
"key",
"]",
";",
"}",
")",
";",
"}",
"}"
] | Setup tasks may return options or instance properties to be set
@param {UI} ui
@param {Object} out | [
"Setup",
"tasks",
"may",
"return",
"options",
"or",
"instance",
"properties",
"to",
"be",
"set"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync-ui/lib/UI.js#L202-L221 |
8,092 | BrowserSync/browser-sync | packages/browser-sync-ui/lib/UI.js | tasksComplete | function tasksComplete (ui) {
return function (err) {
/**
* Log any error according to BrowserSync's Logging level
*/
if (err) {
ui.logger.setOnce("useLevelPrefixes", true).error(err.message || err);
}
/**
* Running event
*/
ui.events.emit("ui:running", {instance: ui, options: ui.options});
/**
* Finally call the user-provided callback
*/
ui.cb(null, ui);
};
} | javascript | function tasksComplete (ui) {
return function (err) {
/**
* Log any error according to BrowserSync's Logging level
*/
if (err) {
ui.logger.setOnce("useLevelPrefixes", true).error(err.message || err);
}
/**
* Running event
*/
ui.events.emit("ui:running", {instance: ui, options: ui.options});
/**
* Finally call the user-provided callback
*/
ui.cb(null, ui);
};
} | [
"function",
"tasksComplete",
"(",
"ui",
")",
"{",
"return",
"function",
"(",
"err",
")",
"{",
"/**\n * Log any error according to BrowserSync's Logging level\n */",
"if",
"(",
"err",
")",
"{",
"ui",
".",
"logger",
".",
"setOnce",
"(",
"\"useLevelPrefixes\"",
",",
"true",
")",
".",
"error",
"(",
"err",
".",
"message",
"||",
"err",
")",
";",
"}",
"/**\n * Running event\n */",
"ui",
".",
"events",
".",
"emit",
"(",
"\"ui:running\"",
",",
"{",
"instance",
":",
"ui",
",",
"options",
":",
"ui",
".",
"options",
"}",
")",
";",
"/**\n * Finally call the user-provided callback\n */",
"ui",
".",
"cb",
"(",
"null",
",",
"ui",
")",
";",
"}",
";",
"}"
] | All async tasks complete at this point
@param ui | [
"All",
"async",
"tasks",
"complete",
"at",
"this",
"point"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync-ui/lib/UI.js#L227-L248 |
8,093 | BrowserSync/browser-sync | packages/browser-sync-ui/lib/plugins/connections/lib/connections.js | decorateClients | function decorateClients(clients, clientsInfo) {
return clients.map(function (item) {
clientsInfo.forEach(function (client) {
if (client.id === item.id) {
item.data = client.data;
return false;
}
});
return item;
});
} | javascript | function decorateClients(clients, clientsInfo) {
return clients.map(function (item) {
clientsInfo.forEach(function (client) {
if (client.id === item.id) {
item.data = client.data;
return false;
}
});
return item;
});
} | [
"function",
"decorateClients",
"(",
"clients",
",",
"clientsInfo",
")",
"{",
"return",
"clients",
".",
"map",
"(",
"function",
"(",
"item",
")",
"{",
"clientsInfo",
".",
"forEach",
"(",
"function",
"(",
"client",
")",
"{",
"if",
"(",
"client",
".",
"id",
"===",
"item",
".",
"id",
")",
"{",
"item",
".",
"data",
"=",
"client",
".",
"data",
";",
"return",
"false",
";",
"}",
"}",
")",
";",
"return",
"item",
";",
"}",
")",
";",
"}"
] | Use heart-beated data to decorate clients
@param clients
@param clientsInfo
@returns {*} | [
"Use",
"heart",
"-",
"beated",
"data",
"to",
"decorate",
"clients"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync-ui/lib/plugins/connections/lib/connections.js#L88-L98 |
8,094 | BrowserSync/browser-sync | packages/browser-sync-ui/lib/resolve-plugins.js | resolvePluginFiles | function resolvePluginFiles (collection, relPath) {
return Immutable.fromJS(collection.reduce(function (all, item) {
var full = path.join(relPath, item);
if (fs.existsSync(full)) {
all[full] = fs.readFileSync(full, "utf8");
}
return all;
}, {}));
} | javascript | function resolvePluginFiles (collection, relPath) {
return Immutable.fromJS(collection.reduce(function (all, item) {
var full = path.join(relPath, item);
if (fs.existsSync(full)) {
all[full] = fs.readFileSync(full, "utf8");
}
return all;
}, {}));
} | [
"function",
"resolvePluginFiles",
"(",
"collection",
",",
"relPath",
")",
"{",
"return",
"Immutable",
".",
"fromJS",
"(",
"collection",
".",
"reduce",
"(",
"function",
"(",
"all",
",",
"item",
")",
"{",
"var",
"full",
"=",
"path",
".",
"join",
"(",
"relPath",
",",
"item",
")",
";",
"if",
"(",
"fs",
".",
"existsSync",
"(",
"full",
")",
")",
"{",
"all",
"[",
"full",
"]",
"=",
"fs",
".",
"readFileSync",
"(",
"full",
",",
"\"utf8\"",
")",
";",
"}",
"return",
"all",
";",
"}",
",",
"{",
"}",
")",
")",
";",
"}"
] | Read & store a file from a plugin
@param {Array|Immutable.List} collection
@param {String} relPath
@returns {any} | [
"Read",
"&",
"store",
"a",
"file",
"from",
"a",
"plugin"
] | 6dd2d560f9afd0daa1188a797d55165f4e2a5763 | https://github.com/BrowserSync/browser-sync/blob/6dd2d560f9afd0daa1188a797d55165f4e2a5763/packages/browser-sync-ui/lib/resolve-plugins.js#L109-L117 |
8,095 | smooth-code/svgr | packages/hast-util-to-babel-ast/src/stringToObjectStyle.js | formatKey | function formatKey(key) {
key = key.toLowerCase()
// Don't capitalize -ms- prefix
if (/^-ms-/.test(key)) key = key.substr(1)
return t.identifier(hyphenToCamelCase(key))
} | javascript | function formatKey(key) {
key = key.toLowerCase()
// Don't capitalize -ms- prefix
if (/^-ms-/.test(key)) key = key.substr(1)
return t.identifier(hyphenToCamelCase(key))
} | [
"function",
"formatKey",
"(",
"key",
")",
"{",
"key",
"=",
"key",
".",
"toLowerCase",
"(",
")",
"// Don't capitalize -ms- prefix",
"if",
"(",
"/",
"^-ms-",
"/",
".",
"test",
"(",
"key",
")",
")",
"key",
"=",
"key",
".",
"substr",
"(",
"1",
")",
"return",
"t",
".",
"identifier",
"(",
"hyphenToCamelCase",
"(",
"key",
")",
")",
"}"
] | Format style key into JSX style object key.
@param {string} key
@return {string} | [
"Format",
"style",
"key",
"into",
"JSX",
"style",
"object",
"key",
"."
] | 94fd1fa09066c0d65e9867a281879d1f085dc69e | https://github.com/smooth-code/svgr/blob/94fd1fa09066c0d65e9867a281879d1f085dc69e/packages/hast-util-to-babel-ast/src/stringToObjectStyle.js#L22-L27 |
8,096 | smooth-code/svgr | packages/hast-util-to-babel-ast/src/stringToObjectStyle.js | formatValue | function formatValue(value) {
if (isNumeric(value)) return t.numericLiteral(Number(value))
if (isConvertiblePixelValue(value))
return t.numericLiteral(Number(trimEnd(value, 'px')))
return t.stringLiteral(value)
} | javascript | function formatValue(value) {
if (isNumeric(value)) return t.numericLiteral(Number(value))
if (isConvertiblePixelValue(value))
return t.numericLiteral(Number(trimEnd(value, 'px')))
return t.stringLiteral(value)
} | [
"function",
"formatValue",
"(",
"value",
")",
"{",
"if",
"(",
"isNumeric",
"(",
"value",
")",
")",
"return",
"t",
".",
"numericLiteral",
"(",
"Number",
"(",
"value",
")",
")",
"if",
"(",
"isConvertiblePixelValue",
"(",
"value",
")",
")",
"return",
"t",
".",
"numericLiteral",
"(",
"Number",
"(",
"trimEnd",
"(",
"value",
",",
"'px'",
")",
")",
")",
"return",
"t",
".",
"stringLiteral",
"(",
"value",
")",
"}"
] | Format style value into JSX style object value.
@param {string} key
@return {string} | [
"Format",
"style",
"value",
"into",
"JSX",
"style",
"object",
"value",
"."
] | 94fd1fa09066c0d65e9867a281879d1f085dc69e | https://github.com/smooth-code/svgr/blob/94fd1fa09066c0d65e9867a281879d1f085dc69e/packages/hast-util-to-babel-ast/src/stringToObjectStyle.js#L35-L40 |
8,097 | smooth-code/svgr | packages/hast-util-to-babel-ast/src/stringToObjectStyle.js | stringToObjectStyle | function stringToObjectStyle(rawStyle) {
const entries = rawStyle.split(';')
const properties = []
let index = -1
while (++index < entries.length) {
const entry = entries[index]
const style = entry.trim()
const firstColon = style.indexOf(':')
const value = style.substr(firstColon + 1).trim()
const key = style.substr(0, firstColon)
if (key !== '') {
const property = t.objectProperty(formatKey(key), formatValue(value))
properties.push(property)
}
}
return t.objectExpression(properties)
} | javascript | function stringToObjectStyle(rawStyle) {
const entries = rawStyle.split(';')
const properties = []
let index = -1
while (++index < entries.length) {
const entry = entries[index]
const style = entry.trim()
const firstColon = style.indexOf(':')
const value = style.substr(firstColon + 1).trim()
const key = style.substr(0, firstColon)
if (key !== '') {
const property = t.objectProperty(formatKey(key), formatValue(value))
properties.push(property)
}
}
return t.objectExpression(properties)
} | [
"function",
"stringToObjectStyle",
"(",
"rawStyle",
")",
"{",
"const",
"entries",
"=",
"rawStyle",
".",
"split",
"(",
"';'",
")",
"const",
"properties",
"=",
"[",
"]",
"let",
"index",
"=",
"-",
"1",
"while",
"(",
"++",
"index",
"<",
"entries",
".",
"length",
")",
"{",
"const",
"entry",
"=",
"entries",
"[",
"index",
"]",
"const",
"style",
"=",
"entry",
".",
"trim",
"(",
")",
"const",
"firstColon",
"=",
"style",
".",
"indexOf",
"(",
"':'",
")",
"const",
"value",
"=",
"style",
".",
"substr",
"(",
"firstColon",
"+",
"1",
")",
".",
"trim",
"(",
")",
"const",
"key",
"=",
"style",
".",
"substr",
"(",
"0",
",",
"firstColon",
")",
"if",
"(",
"key",
"!==",
"''",
")",
"{",
"const",
"property",
"=",
"t",
".",
"objectProperty",
"(",
"formatKey",
"(",
"key",
")",
",",
"formatValue",
"(",
"value",
")",
")",
"properties",
".",
"push",
"(",
"property",
")",
"}",
"}",
"return",
"t",
".",
"objectExpression",
"(",
"properties",
")",
"}"
] | Handle parsing of inline styles.
@param {string} rawStyle
@returns {object} | [
"Handle",
"parsing",
"of",
"inline",
"styles",
"."
] | 94fd1fa09066c0d65e9867a281879d1f085dc69e | https://github.com/smooth-code/svgr/blob/94fd1fa09066c0d65e9867a281879d1f085dc69e/packages/hast-util-to-babel-ast/src/stringToObjectStyle.js#L48-L67 |
8,098 | dfahlander/Dexie.js | samples/remote-sync/websocket/WebSocketSyncServer.js | function (table, key, obj, clientIdentity) {
// Create table if it doesnt exist:
db.tables[table] = db.tables[table] || {};
// Put the obj into to table
db.tables[table][key] = obj;
// Register the change:
db.changes.push({
rev: ++db.revision,
source: clientIdentity,
type: CREATE,
table: table,
key: key,
obj: obj
});
db.trigger();
} | javascript | function (table, key, obj, clientIdentity) {
// Create table if it doesnt exist:
db.tables[table] = db.tables[table] || {};
// Put the obj into to table
db.tables[table][key] = obj;
// Register the change:
db.changes.push({
rev: ++db.revision,
source: clientIdentity,
type: CREATE,
table: table,
key: key,
obj: obj
});
db.trigger();
} | [
"function",
"(",
"table",
",",
"key",
",",
"obj",
",",
"clientIdentity",
")",
"{",
"// Create table if it doesnt exist:",
"db",
".",
"tables",
"[",
"table",
"]",
"=",
"db",
".",
"tables",
"[",
"table",
"]",
"||",
"{",
"}",
";",
"// Put the obj into to table",
"db",
".",
"tables",
"[",
"table",
"]",
"[",
"key",
"]",
"=",
"obj",
";",
"// Register the change:",
"db",
".",
"changes",
".",
"push",
"(",
"{",
"rev",
":",
"++",
"db",
".",
"revision",
",",
"source",
":",
"clientIdentity",
",",
"type",
":",
"CREATE",
",",
"table",
":",
"table",
",",
"key",
":",
"key",
",",
"obj",
":",
"obj",
"}",
")",
";",
"db",
".",
"trigger",
"(",
")",
";",
"}"
] | Subscribers to when database got changes. Used by server connections to be able to push out changes to their clients as they occur. | [
"Subscribers",
"to",
"when",
"database",
"got",
"changes",
".",
"Used",
"by",
"server",
"connections",
"to",
"be",
"able",
"to",
"push",
"out",
"changes",
"to",
"their",
"clients",
"as",
"they",
"occur",
"."
] | 80b53e4df4ec82e5902d12eb8f3db5369b9bd6a8 | https://github.com/dfahlander/Dexie.js/blob/80b53e4df4ec82e5902d12eb8f3db5369b9bd6a8/samples/remote-sync/websocket/WebSocketSyncServer.js#L43-L58 |
|
8,099 | dfahlander/Dexie.js | samples/remote-sync/websocket/WebSocketSyncServer.js | sendAnyChanges | function sendAnyChanges() {
// Get all changes after syncedRevision that was not performed by the client we're talkin' to.
var changes = db.changes.filter(function (change) { return change.rev > syncedRevision && change.source !== conn.clientIdentity; });
// Compact changes so that multiple changes on same object is merged into a single change.
var reducedSet = reduceChanges(changes, conn.clientIdentity);
// Convert the reduced set into an array again.
var reducedArray = Object.keys(reducedSet).map(function (key) { return reducedSet[key]; });
// Notice the current revision of the database. We want to send it to client so it knows what to ask for next time.
var currentRevision = db.revision;
conn.sendText(JSON.stringify({
type: "changes",
changes: reducedArray,
currentRevision: currentRevision,
partial: false // Tell client that these are the only changes we are aware of. Since our mem DB is syncronous, we got all changes in one chunk.
}));
syncedRevision = currentRevision; // Make sure we only send revisions coming after this revision next time and not resend the above changes over and over.
} | javascript | function sendAnyChanges() {
// Get all changes after syncedRevision that was not performed by the client we're talkin' to.
var changes = db.changes.filter(function (change) { return change.rev > syncedRevision && change.source !== conn.clientIdentity; });
// Compact changes so that multiple changes on same object is merged into a single change.
var reducedSet = reduceChanges(changes, conn.clientIdentity);
// Convert the reduced set into an array again.
var reducedArray = Object.keys(reducedSet).map(function (key) { return reducedSet[key]; });
// Notice the current revision of the database. We want to send it to client so it knows what to ask for next time.
var currentRevision = db.revision;
conn.sendText(JSON.stringify({
type: "changes",
changes: reducedArray,
currentRevision: currentRevision,
partial: false // Tell client that these are the only changes we are aware of. Since our mem DB is syncronous, we got all changes in one chunk.
}));
syncedRevision = currentRevision; // Make sure we only send revisions coming after this revision next time and not resend the above changes over and over.
} | [
"function",
"sendAnyChanges",
"(",
")",
"{",
"// Get all changes after syncedRevision that was not performed by the client we're talkin' to.",
"var",
"changes",
"=",
"db",
".",
"changes",
".",
"filter",
"(",
"function",
"(",
"change",
")",
"{",
"return",
"change",
".",
"rev",
">",
"syncedRevision",
"&&",
"change",
".",
"source",
"!==",
"conn",
".",
"clientIdentity",
";",
"}",
")",
";",
"// Compact changes so that multiple changes on same object is merged into a single change.",
"var",
"reducedSet",
"=",
"reduceChanges",
"(",
"changes",
",",
"conn",
".",
"clientIdentity",
")",
";",
"// Convert the reduced set into an array again.",
"var",
"reducedArray",
"=",
"Object",
".",
"keys",
"(",
"reducedSet",
")",
".",
"map",
"(",
"function",
"(",
"key",
")",
"{",
"return",
"reducedSet",
"[",
"key",
"]",
";",
"}",
")",
";",
"// Notice the current revision of the database. We want to send it to client so it knows what to ask for next time.",
"var",
"currentRevision",
"=",
"db",
".",
"revision",
";",
"conn",
".",
"sendText",
"(",
"JSON",
".",
"stringify",
"(",
"{",
"type",
":",
"\"changes\"",
",",
"changes",
":",
"reducedArray",
",",
"currentRevision",
":",
"currentRevision",
",",
"partial",
":",
"false",
"// Tell client that these are the only changes we are aware of. Since our mem DB is syncronous, we got all changes in one chunk.",
"}",
")",
")",
";",
"syncedRevision",
"=",
"currentRevision",
";",
"// Make sure we only send revisions coming after this revision next time and not resend the above changes over and over.",
"}"
] | Used when sending changes to client. Only send changes above syncedRevision since client is already in sync with syncedRevision. | [
"Used",
"when",
"sending",
"changes",
"to",
"client",
".",
"Only",
"send",
"changes",
"above",
"syncedRevision",
"since",
"client",
"is",
"already",
"in",
"sync",
"with",
"syncedRevision",
"."
] | 80b53e4df4ec82e5902d12eb8f3db5369b9bd6a8 | https://github.com/dfahlander/Dexie.js/blob/80b53e4df4ec82e5902d12eb8f3db5369b9bd6a8/samples/remote-sync/websocket/WebSocketSyncServer.js#L141-L159 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.