id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
list | docstring
stringlengths 4
11.8k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
44,200 | dutchenkoOleg/node-w3c-validator | lib/validator.js | getOptions | function getOptions (userOptions = {}) {
let options = _.cloneDeep(userOptions);
if (options.format === 'html') {
options.outputAsHtml = true;
options.verbose = true;
options.format = 'json';
}
return options;
} | javascript | function getOptions (userOptions = {}) {
let options = _.cloneDeep(userOptions);
if (options.format === 'html') {
options.outputAsHtml = true;
options.verbose = true;
options.format = 'json';
}
return options;
} | [
"function",
"getOptions",
"(",
"userOptions",
"=",
"{",
"}",
")",
"{",
"let",
"options",
"=",
"_",
".",
"cloneDeep",
"(",
"userOptions",
")",
";",
"if",
"(",
"options",
".",
"format",
"===",
"'html'",
")",
"{",
"options",
".",
"outputAsHtml",
"=",
"true",
";",
"options",
".",
"verbose",
"=",
"true",
";",
"options",
".",
"format",
"=",
"'json'",
";",
"}",
"return",
"options",
";",
"}"
]
| Get run options from user settled options
@param {Object} [userOptions={}]
@returns {Object}
@private
@sourceCode | [
"Get",
"run",
"options",
"from",
"user",
"settled",
"options"
]
| 79bc6ee63bdfad0208c6c6d8dcd5e25a629b006e | https://github.com/dutchenkoOleg/node-w3c-validator/blob/79bc6ee63bdfad0208c6c6d8dcd5e25a629b006e/lib/validator.js#L83-L93 |
44,201 | dutchenkoOleg/node-w3c-validator | lib/validator.js | getArgvFromObject | function getArgvFromObject (options) {
let argv = [];
let format = options.format;
if (formatList.get(format)) {
argv.push(`--format ${format}`);
}
if (options.asciiquotes) {
argv.push('--asciiquotes yes');
}
if (options.stream === false) {
argv.push('--no-stream');
}
if (options.langdetect === false) {
argv.push('--no-langdetect');
}
if (options.filterfile) {
argv.push(`--filterfile ${options.filterfile}`);
}
if (options.filterpattern) {
argv.push(`--filterpattern ${options.filterpattern}`);
}
booleanArgs.forEach(key => {
if (options[key]) {
argv.push(`--${camel2dash(key)}`);
}
});
return argv;
} | javascript | function getArgvFromObject (options) {
let argv = [];
let format = options.format;
if (formatList.get(format)) {
argv.push(`--format ${format}`);
}
if (options.asciiquotes) {
argv.push('--asciiquotes yes');
}
if (options.stream === false) {
argv.push('--no-stream');
}
if (options.langdetect === false) {
argv.push('--no-langdetect');
}
if (options.filterfile) {
argv.push(`--filterfile ${options.filterfile}`);
}
if (options.filterpattern) {
argv.push(`--filterpattern ${options.filterpattern}`);
}
booleanArgs.forEach(key => {
if (options[key]) {
argv.push(`--${camel2dash(key)}`);
}
});
return argv;
} | [
"function",
"getArgvFromObject",
"(",
"options",
")",
"{",
"let",
"argv",
"=",
"[",
"]",
";",
"let",
"format",
"=",
"options",
".",
"format",
";",
"if",
"(",
"formatList",
".",
"get",
"(",
"format",
")",
")",
"{",
"argv",
".",
"push",
"(",
"`",
"${",
"format",
"}",
"`",
")",
";",
"}",
"if",
"(",
"options",
".",
"asciiquotes",
")",
"{",
"argv",
".",
"push",
"(",
"'--asciiquotes yes'",
")",
";",
"}",
"if",
"(",
"options",
".",
"stream",
"===",
"false",
")",
"{",
"argv",
".",
"push",
"(",
"'--no-stream'",
")",
";",
"}",
"if",
"(",
"options",
".",
"langdetect",
"===",
"false",
")",
"{",
"argv",
".",
"push",
"(",
"'--no-langdetect'",
")",
";",
"}",
"if",
"(",
"options",
".",
"filterfile",
")",
"{",
"argv",
".",
"push",
"(",
"`",
"${",
"options",
".",
"filterfile",
"}",
"`",
")",
";",
"}",
"if",
"(",
"options",
".",
"filterpattern",
")",
"{",
"argv",
".",
"push",
"(",
"`",
"${",
"options",
".",
"filterpattern",
"}",
"`",
")",
";",
"}",
"booleanArgs",
".",
"forEach",
"(",
"key",
"=>",
"{",
"if",
"(",
"options",
"[",
"key",
"]",
")",
"{",
"argv",
".",
"push",
"(",
"`",
"${",
"camel2dash",
"(",
"key",
")",
"}",
"`",
")",
";",
"}",
"}",
")",
";",
"return",
"argv",
";",
"}"
]
| Get arguments from given object
@param {Object} options
@returns {Array}
@private
@sourceCode | [
"Get",
"arguments",
"from",
"given",
"object"
]
| 79bc6ee63bdfad0208c6c6d8dcd5e25a629b006e | https://github.com/dutchenkoOleg/node-w3c-validator/blob/79bc6ee63bdfad0208c6c6d8dcd5e25a629b006e/lib/validator.js#L102-L137 |
44,202 | flitbit/fpipe | examples/example.js | doSomethingUninteresting | function doSomethingUninteresting(data) {
// simulate latency
var wait = randomWait(1000);
return Promise.delay(wait).then(
() => `It took me ${wait} milliseconds to notice you gave me ${data}.`
);
} | javascript | function doSomethingUninteresting(data) {
// simulate latency
var wait = randomWait(1000);
return Promise.delay(wait).then(
() => `It took me ${wait} milliseconds to notice you gave me ${data}.`
);
} | [
"function",
"doSomethingUninteresting",
"(",
"data",
")",
"{",
"// simulate latency",
"var",
"wait",
"=",
"randomWait",
"(",
"1000",
")",
";",
"return",
"Promise",
".",
"delay",
"(",
"wait",
")",
".",
"then",
"(",
"(",
")",
"=>",
"`",
"${",
"wait",
"}",
"${",
"data",
"}",
"`",
")",
";",
"}"
]
| Waits a random period of time before returning a dumb message to the callback given. | [
"Waits",
"a",
"random",
"period",
"of",
"time",
"before",
"returning",
"a",
"dumb",
"message",
"to",
"the",
"callback",
"given",
"."
]
| 39509c0f4e2c46e62c48a94e15b8ba8ed05c7d77 | https://github.com/flitbit/fpipe/blob/39509c0f4e2c46e62c48a94e15b8ba8ed05c7d77/examples/example.js#L12-L18 |
44,203 | andreypopp/rrouter | src/data.js | fetchProps | function fetchProps(props, match) {
var newProps = {};
var deferreds = {};
var promises = {};
var tasks = {};
var name;
for (name in props) {
var m = isPromisePropRe.exec(name);
if (m) {
var promiseName = m[1];
var deferred = Promise.defer();
tasks[promiseName] = makeTask(props[name], deferred);
deferreds[promiseName] = deferred.promise;
} else {
newProps[name] = props[name];
}
}
// not *Promise props, shortcircuit!
if (Object.keys(deferreds).length === 0) {
return Promise.resolve(props);
}
var isFulfilled = true;
for (name in tasks) {
var promise = tasks[name](newProps, deferreds, match);
isFulfilled = isFulfilled && promise.isFulfilled();
promises[name] = promise.isFulfilled() ? promise.value() : promise;
}
// every promise is resolved (probably from some DB cache?), shortcircuit!
if (isFulfilled) {
return Promise.resolve(merge(newProps, promises));
}
return Promise.props(promises)
.then((props) => merge(newProps, props))
.finally(() => {
for (var name in deferreds) {
deferreds[name].catch(emptyFunction);
}
});
} | javascript | function fetchProps(props, match) {
var newProps = {};
var deferreds = {};
var promises = {};
var tasks = {};
var name;
for (name in props) {
var m = isPromisePropRe.exec(name);
if (m) {
var promiseName = m[1];
var deferred = Promise.defer();
tasks[promiseName] = makeTask(props[name], deferred);
deferreds[promiseName] = deferred.promise;
} else {
newProps[name] = props[name];
}
}
// not *Promise props, shortcircuit!
if (Object.keys(deferreds).length === 0) {
return Promise.resolve(props);
}
var isFulfilled = true;
for (name in tasks) {
var promise = tasks[name](newProps, deferreds, match);
isFulfilled = isFulfilled && promise.isFulfilled();
promises[name] = promise.isFulfilled() ? promise.value() : promise;
}
// every promise is resolved (probably from some DB cache?), shortcircuit!
if (isFulfilled) {
return Promise.resolve(merge(newProps, promises));
}
return Promise.props(promises)
.then((props) => merge(newProps, props))
.finally(() => {
for (var name in deferreds) {
deferreds[name].catch(emptyFunction);
}
});
} | [
"function",
"fetchProps",
"(",
"props",
",",
"match",
")",
"{",
"var",
"newProps",
"=",
"{",
"}",
";",
"var",
"deferreds",
"=",
"{",
"}",
";",
"var",
"promises",
"=",
"{",
"}",
";",
"var",
"tasks",
"=",
"{",
"}",
";",
"var",
"name",
";",
"for",
"(",
"name",
"in",
"props",
")",
"{",
"var",
"m",
"=",
"isPromisePropRe",
".",
"exec",
"(",
"name",
")",
";",
"if",
"(",
"m",
")",
"{",
"var",
"promiseName",
"=",
"m",
"[",
"1",
"]",
";",
"var",
"deferred",
"=",
"Promise",
".",
"defer",
"(",
")",
";",
"tasks",
"[",
"promiseName",
"]",
"=",
"makeTask",
"(",
"props",
"[",
"name",
"]",
",",
"deferred",
")",
";",
"deferreds",
"[",
"promiseName",
"]",
"=",
"deferred",
".",
"promise",
";",
"}",
"else",
"{",
"newProps",
"[",
"name",
"]",
"=",
"props",
"[",
"name",
"]",
";",
"}",
"}",
"// not *Promise props, shortcircuit!",
"if",
"(",
"Object",
".",
"keys",
"(",
"deferreds",
")",
".",
"length",
"===",
"0",
")",
"{",
"return",
"Promise",
".",
"resolve",
"(",
"props",
")",
";",
"}",
"var",
"isFulfilled",
"=",
"true",
";",
"for",
"(",
"name",
"in",
"tasks",
")",
"{",
"var",
"promise",
"=",
"tasks",
"[",
"name",
"]",
"(",
"newProps",
",",
"deferreds",
",",
"match",
")",
";",
"isFulfilled",
"=",
"isFulfilled",
"&&",
"promise",
".",
"isFulfilled",
"(",
")",
";",
"promises",
"[",
"name",
"]",
"=",
"promise",
".",
"isFulfilled",
"(",
")",
"?",
"promise",
".",
"value",
"(",
")",
":",
"promise",
";",
"}",
"// every promise is resolved (probably from some DB cache?), shortcircuit!",
"if",
"(",
"isFulfilled",
")",
"{",
"return",
"Promise",
".",
"resolve",
"(",
"merge",
"(",
"newProps",
",",
"promises",
")",
")",
";",
"}",
"return",
"Promise",
".",
"props",
"(",
"promises",
")",
".",
"then",
"(",
"(",
"props",
")",
"=>",
"merge",
"(",
"newProps",
",",
"props",
")",
")",
".",
"finally",
"(",
"(",
")",
"=>",
"{",
"for",
"(",
"var",
"name",
"in",
"deferreds",
")",
"{",
"deferreds",
"[",
"name",
"]",
".",
"catch",
"(",
"emptyFunction",
")",
";",
"}",
"}",
")",
";",
"}"
]
| Fetch all promises defined in props
@param {Object} props
@returns {Promise<Object>} | [
"Fetch",
"all",
"promises",
"defined",
"in",
"props"
]
| 4287dc666254af61f1d169c12fb61a1bfd7e2623 | https://github.com/andreypopp/rrouter/blob/4287dc666254af61f1d169c12fb61a1bfd7e2623/src/data.js#L48-L94 |
44,204 | Jam3/gl-pixel-stream | demo.js | renderScene | function renderScene () {
gl.clearColor(0, 0, 0, 1)
gl.clear(gl.COLOR_BUFFER_BIT)
gl.viewport(0, 0, shape[0], shape[1])
shader.bind()
shader.uniforms.iResolution = shape
shader.uniforms.iGlobalTime = 0
triangle(gl)
} | javascript | function renderScene () {
gl.clearColor(0, 0, 0, 1)
gl.clear(gl.COLOR_BUFFER_BIT)
gl.viewport(0, 0, shape[0], shape[1])
shader.bind()
shader.uniforms.iResolution = shape
shader.uniforms.iGlobalTime = 0
triangle(gl)
} | [
"function",
"renderScene",
"(",
")",
"{",
"gl",
".",
"clearColor",
"(",
"0",
",",
"0",
",",
"0",
",",
"1",
")",
"gl",
".",
"clear",
"(",
"gl",
".",
"COLOR_BUFFER_BIT",
")",
"gl",
".",
"viewport",
"(",
"0",
",",
"0",
",",
"shape",
"[",
"0",
"]",
",",
"shape",
"[",
"1",
"]",
")",
"shader",
".",
"bind",
"(",
")",
"shader",
".",
"uniforms",
".",
"iResolution",
"=",
"shape",
"shader",
".",
"uniforms",
".",
"iGlobalTime",
"=",
"0",
"triangle",
"(",
"gl",
")",
"}"
]
| can be any type of render function | [
"can",
"be",
"any",
"type",
"of",
"render",
"function"
]
| 7da1fc9da0b5895d5c5a54d5208193e3cf1ab237 | https://github.com/Jam3/gl-pixel-stream/blob/7da1fc9da0b5895d5c5a54d5208193e3cf1ab237/demo.js#L59-L67 |
44,205 | wyicwx/bone | lib/fs.js | FileSystem | function FileSystem(base, options) {
options || (options = {});
this.base = this.pathResolve(base);
if(options.captureFile) {
this._readFiles = [];
}
if(options.globalAct) {
this.globalAct = options.globalAct;
}
} | javascript | function FileSystem(base, options) {
options || (options = {});
this.base = this.pathResolve(base);
if(options.captureFile) {
this._readFiles = [];
}
if(options.globalAct) {
this.globalAct = options.globalAct;
}
} | [
"function",
"FileSystem",
"(",
"base",
",",
"options",
")",
"{",
"options",
"||",
"(",
"options",
"=",
"{",
"}",
")",
";",
"this",
".",
"base",
"=",
"this",
".",
"pathResolve",
"(",
"base",
")",
";",
"if",
"(",
"options",
".",
"captureFile",
")",
"{",
"this",
".",
"_readFiles",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"options",
".",
"globalAct",
")",
"{",
"this",
".",
"globalAct",
"=",
"options",
".",
"globalAct",
";",
"}",
"}"
]
| file path src | [
"file",
"path",
"src"
]
| eb6c12080f6da8c5a20767d567bf80a49a099430 | https://github.com/wyicwx/bone/blob/eb6c12080f6da8c5a20767d567bf80a49a099430/lib/fs.js#L12-L21 |
44,206 | jdeal/doctor | view/default/jquery-ui/development-bundle/ui/jquery-ui-1.8.16.custom.js | function(pos) {
var topOffset = $(this).css(pos).offset().top;
if (topOffset < 0) {
$(this).css('top', pos.top - topOffset);
}
} | javascript | function(pos) {
var topOffset = $(this).css(pos).offset().top;
if (topOffset < 0) {
$(this).css('top', pos.top - topOffset);
}
} | [
"function",
"(",
"pos",
")",
"{",
"var",
"topOffset",
"=",
"$",
"(",
"this",
")",
".",
"css",
"(",
"pos",
")",
".",
"offset",
"(",
")",
".",
"top",
";",
"if",
"(",
"topOffset",
"<",
"0",
")",
"{",
"$",
"(",
"this",
")",
".",
"css",
"(",
"'top'",
",",
"pos",
".",
"top",
"-",
"topOffset",
")",
";",
"}",
"}"
]
| ensure that the titlebar is never outside the document | [
"ensure",
"that",
"the",
"titlebar",
"is",
"never",
"outside",
"the",
"document"
]
| e1516f9cac6a899dbf3c624026deac3061f4ec63 | https://github.com/jdeal/doctor/blob/e1516f9cac6a899dbf3c624026deac3061f4ec63/view/default/jquery-ui/development-bundle/ui/jquery-ui-1.8.16.custom.js#L6015-L6020 |
|
44,207 | jdeal/doctor | view/default/jquery-ui/development-bundle/ui/jquery-ui-1.8.16.custom.js | function(force, event) {
var self = this,
options = self.options,
saveScroll;
if ((options.modal && !force) ||
(!options.stack && !options.modal)) {
return self._trigger('focus', event);
}
if (options.zIndex > $.ui.dialog.maxZ) {
$.ui.dialog.maxZ = options.zIndex;
}
if (self.overlay) {
$.ui.dialog.maxZ += 1;
self.overlay.$el.css('z-index', $.ui.dialog.overlay.maxZ = $.ui.dialog.maxZ);
}
//Save and then restore scroll since Opera 9.5+ resets when parent z-Index is changed.
// http://ui.jquery.com/bugs/ticket/3193
saveScroll = { scrollTop: self.element.scrollTop(), scrollLeft: self.element.scrollLeft() };
$.ui.dialog.maxZ += 1;
self.uiDialog.css('z-index', $.ui.dialog.maxZ);
self.element.attr(saveScroll);
self._trigger('focus', event);
return self;
} | javascript | function(force, event) {
var self = this,
options = self.options,
saveScroll;
if ((options.modal && !force) ||
(!options.stack && !options.modal)) {
return self._trigger('focus', event);
}
if (options.zIndex > $.ui.dialog.maxZ) {
$.ui.dialog.maxZ = options.zIndex;
}
if (self.overlay) {
$.ui.dialog.maxZ += 1;
self.overlay.$el.css('z-index', $.ui.dialog.overlay.maxZ = $.ui.dialog.maxZ);
}
//Save and then restore scroll since Opera 9.5+ resets when parent z-Index is changed.
// http://ui.jquery.com/bugs/ticket/3193
saveScroll = { scrollTop: self.element.scrollTop(), scrollLeft: self.element.scrollLeft() };
$.ui.dialog.maxZ += 1;
self.uiDialog.css('z-index', $.ui.dialog.maxZ);
self.element.attr(saveScroll);
self._trigger('focus', event);
return self;
} | [
"function",
"(",
"force",
",",
"event",
")",
"{",
"var",
"self",
"=",
"this",
",",
"options",
"=",
"self",
".",
"options",
",",
"saveScroll",
";",
"if",
"(",
"(",
"options",
".",
"modal",
"&&",
"!",
"force",
")",
"||",
"(",
"!",
"options",
".",
"stack",
"&&",
"!",
"options",
".",
"modal",
")",
")",
"{",
"return",
"self",
".",
"_trigger",
"(",
"'focus'",
",",
"event",
")",
";",
"}",
"if",
"(",
"options",
".",
"zIndex",
">",
"$",
".",
"ui",
".",
"dialog",
".",
"maxZ",
")",
"{",
"$",
".",
"ui",
".",
"dialog",
".",
"maxZ",
"=",
"options",
".",
"zIndex",
";",
"}",
"if",
"(",
"self",
".",
"overlay",
")",
"{",
"$",
".",
"ui",
".",
"dialog",
".",
"maxZ",
"+=",
"1",
";",
"self",
".",
"overlay",
".",
"$el",
".",
"css",
"(",
"'z-index'",
",",
"$",
".",
"ui",
".",
"dialog",
".",
"overlay",
".",
"maxZ",
"=",
"$",
".",
"ui",
".",
"dialog",
".",
"maxZ",
")",
";",
"}",
"//Save and then restore scroll since Opera 9.5+ resets when parent z-Index is changed.",
"// http://ui.jquery.com/bugs/ticket/3193",
"saveScroll",
"=",
"{",
"scrollTop",
":",
"self",
".",
"element",
".",
"scrollTop",
"(",
")",
",",
"scrollLeft",
":",
"self",
".",
"element",
".",
"scrollLeft",
"(",
")",
"}",
";",
"$",
".",
"ui",
".",
"dialog",
".",
"maxZ",
"+=",
"1",
";",
"self",
".",
"uiDialog",
".",
"css",
"(",
"'z-index'",
",",
"$",
".",
"ui",
".",
"dialog",
".",
"maxZ",
")",
";",
"self",
".",
"element",
".",
"attr",
"(",
"saveScroll",
")",
";",
"self",
".",
"_trigger",
"(",
"'focus'",
",",
"event",
")",
";",
"return",
"self",
";",
"}"
]
| the force parameter allows us to move modal dialogs to their correct position on open | [
"the",
"force",
"parameter",
"allows",
"us",
"to",
"move",
"modal",
"dialogs",
"to",
"their",
"correct",
"position",
"on",
"open"
]
| e1516f9cac6a899dbf3c624026deac3061f4ec63 | https://github.com/jdeal/doctor/blob/e1516f9cac6a899dbf3c624026deac3061f4ec63/view/default/jquery-ui/development-bundle/ui/jquery-ui-1.8.16.custom.js#L6230-L6257 |
|
44,208 | jdeal/doctor | view/default/jquery-ui/development-bundle/ui/jquery-ui-1.8.16.custom.js | function(match, value, len) {
var num = '' + value;
if (lookAhead(match))
while (num.length < len)
num = '0' + num;
return num;
} | javascript | function(match, value, len) {
var num = '' + value;
if (lookAhead(match))
while (num.length < len)
num = '0' + num;
return num;
} | [
"function",
"(",
"match",
",",
"value",
",",
"len",
")",
"{",
"var",
"num",
"=",
"''",
"+",
"value",
";",
"if",
"(",
"lookAhead",
"(",
"match",
")",
")",
"while",
"(",
"num",
".",
"length",
"<",
"len",
")",
"num",
"=",
"'0'",
"+",
"num",
";",
"return",
"num",
";",
"}"
]
| Format a number, with leading zero if necessary | [
"Format",
"a",
"number",
"with",
"leading",
"zero",
"if",
"necessary"
]
| e1516f9cac6a899dbf3c624026deac3061f4ec63 | https://github.com/jdeal/doctor/blob/e1516f9cac6a899dbf3c624026deac3061f4ec63/view/default/jquery-ui/development-bundle/ui/jquery-ui-1.8.16.custom.js#L9423-L9429 |
|
44,209 | ivee-tech/three-asciieffect | index.js | asciifyImage | function asciifyImage( canvasRenderer, oAscii ) {
oCtx.clearRect( 0, 0, iWidth, iHeight );
oCtx.drawImage( oCanvasImg, 0, 0, iWidth, iHeight );
var oImgData = oCtx.getImageData( 0, 0, iWidth, iHeight ).data;
// Coloring loop starts now
var strChars = "";
// console.time('rendering');
for ( var y = 0; y < iHeight; y += 2 ) {
for ( var x = 0; x < iWidth; x ++ ) {
var iOffset = ( y * iWidth + x ) * 4;
var iRed = oImgData[ iOffset ];
var iGreen = oImgData[ iOffset + 1 ];
var iBlue = oImgData[ iOffset + 2 ];
var iAlpha = oImgData[ iOffset + 3 ];
var iCharIdx;
var fBrightness;
fBrightness = ( 0.3 * iRed + 0.59 * iGreen + 0.11 * iBlue ) / 255;
// fBrightness = (0.3*iRed + 0.5*iGreen + 0.3*iBlue) / 255;
if ( iAlpha == 0 ) {
// should calculate alpha instead, but quick hack :)
//fBrightness *= (iAlpha / 255);
fBrightness = 1;
}
iCharIdx = Math.floor( ( 1 - fBrightness ) * ( aCharList.length - 1 ) );
if ( bInvert ) {
iCharIdx = aCharList.length - iCharIdx - 1;
}
// good for debugging
//fBrightness = Math.floor(fBrightness * 10);
//strThisChar = fBrightness;
var strThisChar = aCharList[ iCharIdx ];
if ( strThisChar === undefined || strThisChar == " " )
strThisChar = " ";
if ( bColor ) {
strChars += "<span style='"
+ "color:rgb(" + iRed + "," + iGreen + "," + iBlue + ");"
+ ( bBlock ? "background-color:rgb(" + iRed + "," + iGreen + "," + iBlue + ");" : "" )
+ ( bAlpha ? "opacity:" + ( iAlpha / 255 ) + ";" : "" )
+ "'>" + strThisChar + "</span>";
} else {
strChars += strThisChar;
}
}
strChars += "<br/>";
}
oAscii.innerHTML = "<tr><td>" + strChars + "</td></tr>";
// console.timeEnd('rendering');
// return oAscii;
} | javascript | function asciifyImage( canvasRenderer, oAscii ) {
oCtx.clearRect( 0, 0, iWidth, iHeight );
oCtx.drawImage( oCanvasImg, 0, 0, iWidth, iHeight );
var oImgData = oCtx.getImageData( 0, 0, iWidth, iHeight ).data;
// Coloring loop starts now
var strChars = "";
// console.time('rendering');
for ( var y = 0; y < iHeight; y += 2 ) {
for ( var x = 0; x < iWidth; x ++ ) {
var iOffset = ( y * iWidth + x ) * 4;
var iRed = oImgData[ iOffset ];
var iGreen = oImgData[ iOffset + 1 ];
var iBlue = oImgData[ iOffset + 2 ];
var iAlpha = oImgData[ iOffset + 3 ];
var iCharIdx;
var fBrightness;
fBrightness = ( 0.3 * iRed + 0.59 * iGreen + 0.11 * iBlue ) / 255;
// fBrightness = (0.3*iRed + 0.5*iGreen + 0.3*iBlue) / 255;
if ( iAlpha == 0 ) {
// should calculate alpha instead, but quick hack :)
//fBrightness *= (iAlpha / 255);
fBrightness = 1;
}
iCharIdx = Math.floor( ( 1 - fBrightness ) * ( aCharList.length - 1 ) );
if ( bInvert ) {
iCharIdx = aCharList.length - iCharIdx - 1;
}
// good for debugging
//fBrightness = Math.floor(fBrightness * 10);
//strThisChar = fBrightness;
var strThisChar = aCharList[ iCharIdx ];
if ( strThisChar === undefined || strThisChar == " " )
strThisChar = " ";
if ( bColor ) {
strChars += "<span style='"
+ "color:rgb(" + iRed + "," + iGreen + "," + iBlue + ");"
+ ( bBlock ? "background-color:rgb(" + iRed + "," + iGreen + "," + iBlue + ");" : "" )
+ ( bAlpha ? "opacity:" + ( iAlpha / 255 ) + ";" : "" )
+ "'>" + strThisChar + "</span>";
} else {
strChars += strThisChar;
}
}
strChars += "<br/>";
}
oAscii.innerHTML = "<tr><td>" + strChars + "</td></tr>";
// console.timeEnd('rendering');
// return oAscii;
} | [
"function",
"asciifyImage",
"(",
"canvasRenderer",
",",
"oAscii",
")",
"{",
"oCtx",
".",
"clearRect",
"(",
"0",
",",
"0",
",",
"iWidth",
",",
"iHeight",
")",
";",
"oCtx",
".",
"drawImage",
"(",
"oCanvasImg",
",",
"0",
",",
"0",
",",
"iWidth",
",",
"iHeight",
")",
";",
"var",
"oImgData",
"=",
"oCtx",
".",
"getImageData",
"(",
"0",
",",
"0",
",",
"iWidth",
",",
"iHeight",
")",
".",
"data",
";",
"// Coloring loop starts now",
"var",
"strChars",
"=",
"\"\"",
";",
"// console.time('rendering');",
"for",
"(",
"var",
"y",
"=",
"0",
";",
"y",
"<",
"iHeight",
";",
"y",
"+=",
"2",
")",
"{",
"for",
"(",
"var",
"x",
"=",
"0",
";",
"x",
"<",
"iWidth",
";",
"x",
"++",
")",
"{",
"var",
"iOffset",
"=",
"(",
"y",
"*",
"iWidth",
"+",
"x",
")",
"*",
"4",
";",
"var",
"iRed",
"=",
"oImgData",
"[",
"iOffset",
"]",
";",
"var",
"iGreen",
"=",
"oImgData",
"[",
"iOffset",
"+",
"1",
"]",
";",
"var",
"iBlue",
"=",
"oImgData",
"[",
"iOffset",
"+",
"2",
"]",
";",
"var",
"iAlpha",
"=",
"oImgData",
"[",
"iOffset",
"+",
"3",
"]",
";",
"var",
"iCharIdx",
";",
"var",
"fBrightness",
";",
"fBrightness",
"=",
"(",
"0.3",
"*",
"iRed",
"+",
"0.59",
"*",
"iGreen",
"+",
"0.11",
"*",
"iBlue",
")",
"/",
"255",
";",
"// fBrightness = (0.3*iRed + 0.5*iGreen + 0.3*iBlue) / 255;",
"if",
"(",
"iAlpha",
"==",
"0",
")",
"{",
"// should calculate alpha instead, but quick hack :)",
"//fBrightness *= (iAlpha / 255);",
"fBrightness",
"=",
"1",
";",
"}",
"iCharIdx",
"=",
"Math",
".",
"floor",
"(",
"(",
"1",
"-",
"fBrightness",
")",
"*",
"(",
"aCharList",
".",
"length",
"-",
"1",
")",
")",
";",
"if",
"(",
"bInvert",
")",
"{",
"iCharIdx",
"=",
"aCharList",
".",
"length",
"-",
"iCharIdx",
"-",
"1",
";",
"}",
"// good for debugging",
"//fBrightness = Math.floor(fBrightness * 10);",
"//strThisChar = fBrightness;",
"var",
"strThisChar",
"=",
"aCharList",
"[",
"iCharIdx",
"]",
";",
"if",
"(",
"strThisChar",
"===",
"undefined",
"||",
"strThisChar",
"==",
"\" \"",
")",
"strThisChar",
"=",
"\" \"",
";",
"if",
"(",
"bColor",
")",
"{",
"strChars",
"+=",
"\"<span style='\"",
"+",
"\"color:rgb(\"",
"+",
"iRed",
"+",
"\",\"",
"+",
"iGreen",
"+",
"\",\"",
"+",
"iBlue",
"+",
"\");\"",
"+",
"(",
"bBlock",
"?",
"\"background-color:rgb(\"",
"+",
"iRed",
"+",
"\",\"",
"+",
"iGreen",
"+",
"\",\"",
"+",
"iBlue",
"+",
"\");\"",
":",
"\"\"",
")",
"+",
"(",
"bAlpha",
"?",
"\"opacity:\"",
"+",
"(",
"iAlpha",
"/",
"255",
")",
"+",
"\";\"",
":",
"\"\"",
")",
"+",
"\"'>\"",
"+",
"strThisChar",
"+",
"\"</span>\"",
";",
"}",
"else",
"{",
"strChars",
"+=",
"strThisChar",
";",
"}",
"}",
"strChars",
"+=",
"\"<br/>\"",
";",
"}",
"oAscii",
".",
"innerHTML",
"=",
"\"<tr><td>\"",
"+",
"strChars",
"+",
"\"</td></tr>\"",
";",
"// console.timeEnd('rendering');",
"// return oAscii;",
"}"
]
| can't get a span or div to flow like an img element, but a table works? convert img element to ascii | [
"can",
"t",
"get",
"a",
"span",
"or",
"div",
"to",
"flow",
"like",
"an",
"img",
"element",
"but",
"a",
"table",
"works?",
"convert",
"img",
"element",
"to",
"ascii"
]
| 19194b28547c40a4901bfc0494047cdcc40e02cf | https://github.com/ivee-tech/three-asciieffect/blob/19194b28547c40a4901bfc0494047cdcc40e02cf/index.js#L205-L283 |
44,210 | sergiolepore/hexo-broken-link-checker | lib/core/brokenLinkChecker.js | BrokenLinkChecker | function BrokenLinkChecker(options) {
this.runningScope = options.scope || BrokenLinkChecker.RUNNING_SCOPE_COMMAND;
this.pluginConfig = {};
this.pluginConfig.enabled = (typeof userConfig.enabled !== 'undefined')? userConfig.enabled : true;
this.pluginConfig.storageDir = userConfig.storage_dir || 'temp/link_checker';
this.pluginConfig.silentLogs = options.silentLogs || userConfig.silent_logs || false;
this.workingDirectory = hexo.base_dir + this.pluginConfig.storageDir;
this.storageFile = 'data.json';
this.logFile = 'log.json';
this._storageTemplateFile = __dirname + '/../data/storageTemplate.json';
this._jsonStorage = null;
// the path must end with a slash
if (this.workingDirectory.substr(-1) != '/') {
this.workingDirectory += '/';
}
var loggerOptions = {
defaultPrefix: null,
infoPrefix: null,
warnPrefix: null,
errPrefix: null,
silent: this.pluginConfig.silentLogs,
logFile: this.workingDirectory+this.logFile
};
// change the log prefix based on the running scope
// command:
// (i) Text
// filter:
// [BrokenLinkChecker Info] Text
switch (this.runningScope) {
case BrokenLinkChecker.RUNNING_SCOPE_COMMAND:
loggerOptions.defaultPrefix = '(i) '.cyan;
loggerOptions.warnPrefix = '(!) '.yellow;
loggerOptions.errPrefix = '(x) '.red;
break;
case BrokenLinkChecker.RUNNING_SCOPE_FILTER:
loggerOptions.defaultPrefix = '['+(this.toString()+' Info').cyan+'] ';
loggerOptions.warnPrefix = '['+(this.toString()+' Warning').yellow+'] ';
loggerOptions.errPrefix = '['+(this.toString()+' Error').red+'] ';
break;
}
this.logger = new Logger(loggerOptions);
} | javascript | function BrokenLinkChecker(options) {
this.runningScope = options.scope || BrokenLinkChecker.RUNNING_SCOPE_COMMAND;
this.pluginConfig = {};
this.pluginConfig.enabled = (typeof userConfig.enabled !== 'undefined')? userConfig.enabled : true;
this.pluginConfig.storageDir = userConfig.storage_dir || 'temp/link_checker';
this.pluginConfig.silentLogs = options.silentLogs || userConfig.silent_logs || false;
this.workingDirectory = hexo.base_dir + this.pluginConfig.storageDir;
this.storageFile = 'data.json';
this.logFile = 'log.json';
this._storageTemplateFile = __dirname + '/../data/storageTemplate.json';
this._jsonStorage = null;
// the path must end with a slash
if (this.workingDirectory.substr(-1) != '/') {
this.workingDirectory += '/';
}
var loggerOptions = {
defaultPrefix: null,
infoPrefix: null,
warnPrefix: null,
errPrefix: null,
silent: this.pluginConfig.silentLogs,
logFile: this.workingDirectory+this.logFile
};
// change the log prefix based on the running scope
// command:
// (i) Text
// filter:
// [BrokenLinkChecker Info] Text
switch (this.runningScope) {
case BrokenLinkChecker.RUNNING_SCOPE_COMMAND:
loggerOptions.defaultPrefix = '(i) '.cyan;
loggerOptions.warnPrefix = '(!) '.yellow;
loggerOptions.errPrefix = '(x) '.red;
break;
case BrokenLinkChecker.RUNNING_SCOPE_FILTER:
loggerOptions.defaultPrefix = '['+(this.toString()+' Info').cyan+'] ';
loggerOptions.warnPrefix = '['+(this.toString()+' Warning').yellow+'] ';
loggerOptions.errPrefix = '['+(this.toString()+' Error').red+'] ';
break;
}
this.logger = new Logger(loggerOptions);
} | [
"function",
"BrokenLinkChecker",
"(",
"options",
")",
"{",
"this",
".",
"runningScope",
"=",
"options",
".",
"scope",
"||",
"BrokenLinkChecker",
".",
"RUNNING_SCOPE_COMMAND",
";",
"this",
".",
"pluginConfig",
"=",
"{",
"}",
";",
"this",
".",
"pluginConfig",
".",
"enabled",
"=",
"(",
"typeof",
"userConfig",
".",
"enabled",
"!==",
"'undefined'",
")",
"?",
"userConfig",
".",
"enabled",
":",
"true",
";",
"this",
".",
"pluginConfig",
".",
"storageDir",
"=",
"userConfig",
".",
"storage_dir",
"||",
"'temp/link_checker'",
";",
"this",
".",
"pluginConfig",
".",
"silentLogs",
"=",
"options",
".",
"silentLogs",
"||",
"userConfig",
".",
"silent_logs",
"||",
"false",
";",
"this",
".",
"workingDirectory",
"=",
"hexo",
".",
"base_dir",
"+",
"this",
".",
"pluginConfig",
".",
"storageDir",
";",
"this",
".",
"storageFile",
"=",
"'data.json'",
";",
"this",
".",
"logFile",
"=",
"'log.json'",
";",
"this",
".",
"_storageTemplateFile",
"=",
"__dirname",
"+",
"'/../data/storageTemplate.json'",
";",
"this",
".",
"_jsonStorage",
"=",
"null",
";",
"// the path must end with a slash",
"if",
"(",
"this",
".",
"workingDirectory",
".",
"substr",
"(",
"-",
"1",
")",
"!=",
"'/'",
")",
"{",
"this",
".",
"workingDirectory",
"+=",
"'/'",
";",
"}",
"var",
"loggerOptions",
"=",
"{",
"defaultPrefix",
":",
"null",
",",
"infoPrefix",
":",
"null",
",",
"warnPrefix",
":",
"null",
",",
"errPrefix",
":",
"null",
",",
"silent",
":",
"this",
".",
"pluginConfig",
".",
"silentLogs",
",",
"logFile",
":",
"this",
".",
"workingDirectory",
"+",
"this",
".",
"logFile",
"}",
";",
"// change the log prefix based on the running scope",
"// command:",
"// (i) Text",
"// filter:",
"// [BrokenLinkChecker Info] Text",
"switch",
"(",
"this",
".",
"runningScope",
")",
"{",
"case",
"BrokenLinkChecker",
".",
"RUNNING_SCOPE_COMMAND",
":",
"loggerOptions",
".",
"defaultPrefix",
"=",
"'(i) '",
".",
"cyan",
";",
"loggerOptions",
".",
"warnPrefix",
"=",
"'(!) '",
".",
"yellow",
";",
"loggerOptions",
".",
"errPrefix",
"=",
"'(x) '",
".",
"red",
";",
"break",
";",
"case",
"BrokenLinkChecker",
".",
"RUNNING_SCOPE_FILTER",
":",
"loggerOptions",
".",
"defaultPrefix",
"=",
"'['",
"+",
"(",
"this",
".",
"toString",
"(",
")",
"+",
"' Info'",
")",
".",
"cyan",
"+",
"'] '",
";",
"loggerOptions",
".",
"warnPrefix",
"=",
"'['",
"+",
"(",
"this",
".",
"toString",
"(",
")",
"+",
"' Warning'",
")",
".",
"yellow",
"+",
"'] '",
";",
"loggerOptions",
".",
"errPrefix",
"=",
"'['",
"+",
"(",
"this",
".",
"toString",
"(",
")",
"+",
"' Error'",
")",
".",
"red",
"+",
"'] '",
";",
"break",
";",
"}",
"this",
".",
"logger",
"=",
"new",
"Logger",
"(",
"loggerOptions",
")",
";",
"}"
]
| BrokenLinkChecker constructor.
Options:
- `scope`: BrokenLinkChecker.RUNNING_SCOPE_*
- `silentLogs`: output all log info to a file, instead
using the stdout.
@class BrokenLinkChecker
@constructor
@param {Object} options | [
"BrokenLinkChecker",
"constructor",
"."
]
| b2da55b87a77609b3e07e34666c32971a523b88d | https://github.com/sergiolepore/hexo-broken-link-checker/blob/b2da55b87a77609b3e07e34666c32971a523b88d/lib/core/brokenLinkChecker.js#L33-L80 |
44,211 | emalherbi/grunt-php-shield | tasks/php_shield.js | function(src, dest) {
if (grunt.file.isDir(src)) {
grunt.file.mkdir(dest);
if (options.log) {
Utils.writeln(chalk.gray.bold(' create dir => ' + dest));
}
return true;
}
return false;
} | javascript | function(src, dest) {
if (grunt.file.isDir(src)) {
grunt.file.mkdir(dest);
if (options.log) {
Utils.writeln(chalk.gray.bold(' create dir => ' + dest));
}
return true;
}
return false;
} | [
"function",
"(",
"src",
",",
"dest",
")",
"{",
"if",
"(",
"grunt",
".",
"file",
".",
"isDir",
"(",
"src",
")",
")",
"{",
"grunt",
".",
"file",
".",
"mkdir",
"(",
"dest",
")",
";",
"if",
"(",
"options",
".",
"log",
")",
"{",
"Utils",
".",
"writeln",
"(",
"chalk",
".",
"gray",
".",
"bold",
"(",
"' create dir => '",
"+",
"dest",
")",
")",
";",
"}",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
]
| create a dir | [
"create",
"a",
"dir"
]
| 40eec9f08cd6c88ec93cef3b6cacf977f5b1b1ca | https://github.com/emalherbi/grunt-php-shield/blob/40eec9f08cd6c88ec93cef3b6cacf977f5b1b1ca/tasks/php_shield.js#L46-L55 |
|
44,212 | postmanlabs/generic-bitmask | lib/descriptor.js | function (names) {
this.names = Object.keys(names); // store the keys
this.hash = util.map(names, function (value) { // store values for corresponding keys
return parseInt(value, 10);
});
} | javascript | function (names) {
this.names = Object.keys(names); // store the keys
this.hash = util.map(names, function (value) { // store values for corresponding keys
return parseInt(value, 10);
});
} | [
"function",
"(",
"names",
")",
"{",
"this",
".",
"names",
"=",
"Object",
".",
"keys",
"(",
"names",
")",
";",
"// store the keys",
"this",
".",
"hash",
"=",
"util",
".",
"map",
"(",
"names",
",",
"function",
"(",
"value",
")",
"{",
"// store values for corresponding keys",
"return",
"parseInt",
"(",
"value",
",",
"10",
")",
";",
"}",
")",
";",
"}"
]
| Set the named bits for the descriptors.
@param {object<number>} values | [
"Set",
"the",
"named",
"bits",
"for",
"the",
"descriptors",
"."
]
| 9c940f6ef7c2fdef2f8523b1cb562ebcc8b8a50d | https://github.com/postmanlabs/generic-bitmask/blob/9c940f6ef7c2fdef2f8523b1cb562ebcc8b8a50d/lib/descriptor.js#L23-L28 |
|
44,213 | postmanlabs/generic-bitmask | lib/descriptor.js | function (name, lazy) {
return Array.isArray(name) ? (name.length ? name.every(function (name) {
return this.defined(name, lazy);
}, this) : !!lazy) : (name ? !!this.hash[name] : !!lazy);
} | javascript | function (name, lazy) {
return Array.isArray(name) ? (name.length ? name.every(function (name) {
return this.defined(name, lazy);
}, this) : !!lazy) : (name ? !!this.hash[name] : !!lazy);
} | [
"function",
"(",
"name",
",",
"lazy",
")",
"{",
"return",
"Array",
".",
"isArray",
"(",
"name",
")",
"?",
"(",
"name",
".",
"length",
"?",
"name",
".",
"every",
"(",
"function",
"(",
"name",
")",
"{",
"return",
"this",
".",
"defined",
"(",
"name",
",",
"lazy",
")",
";",
"}",
",",
"this",
")",
":",
"!",
"!",
"lazy",
")",
":",
"(",
"name",
"?",
"!",
"!",
"this",
".",
"hash",
"[",
"name",
"]",
":",
"!",
"!",
"lazy",
")",
";",
"}"
]
| Verifies whether the specified named bits are defined in the descriptor
@param {Array<string>|string} name
@param {boolean=} [lazy=false] - if set to true, this function will return true for empty names or array
@return {boolean} | [
"Verifies",
"whether",
"the",
"specified",
"named",
"bits",
"are",
"defined",
"in",
"the",
"descriptor"
]
| 9c940f6ef7c2fdef2f8523b1cb562ebcc8b8a50d | https://github.com/postmanlabs/generic-bitmask/blob/9c940f6ef7c2fdef2f8523b1cb562ebcc8b8a50d/lib/descriptor.js#L36-L40 |
|
44,214 | postmanlabs/generic-bitmask | lib/descriptor.js | function (name) {
return Array.isArray(name) ? (name.map(this.valueOf.bind(this))) : this.hash[name];
} | javascript | function (name) {
return Array.isArray(name) ? (name.map(this.valueOf.bind(this))) : this.hash[name];
} | [
"function",
"(",
"name",
")",
"{",
"return",
"Array",
".",
"isArray",
"(",
"name",
")",
"?",
"(",
"name",
".",
"map",
"(",
"this",
".",
"valueOf",
".",
"bind",
"(",
"this",
")",
")",
")",
":",
"this",
".",
"hash",
"[",
"name",
"]",
";",
"}"
]
| Returns the value of a descriptor name
@param {Array<string>|string} name
@returns {number} | [
"Returns",
"the",
"value",
"of",
"a",
"descriptor",
"name"
]
| 9c940f6ef7c2fdef2f8523b1cb562ebcc8b8a50d | https://github.com/postmanlabs/generic-bitmask/blob/9c940f6ef7c2fdef2f8523b1cb562ebcc8b8a50d/lib/descriptor.js#L48-L50 |
|
44,215 | wyicwx/bone | lib/utils.js | function(file) {
var FileSystem = require('./fs.js');
var ReadStream = require('./read_stream.js');
if(FileSystem.fs.existFile(file)) {
file = FileSystem.fs.pathResolve(file);
var readStream = new ReadStream(file);
return _.clone(readStream.trackStack);
} else {
return false;
}
} | javascript | function(file) {
var FileSystem = require('./fs.js');
var ReadStream = require('./read_stream.js');
if(FileSystem.fs.existFile(file)) {
file = FileSystem.fs.pathResolve(file);
var readStream = new ReadStream(file);
return _.clone(readStream.trackStack);
} else {
return false;
}
} | [
"function",
"(",
"file",
")",
"{",
"var",
"FileSystem",
"=",
"require",
"(",
"'./fs.js'",
")",
";",
"var",
"ReadStream",
"=",
"require",
"(",
"'./read_stream.js'",
")",
";",
"if",
"(",
"FileSystem",
".",
"fs",
".",
"existFile",
"(",
"file",
")",
")",
"{",
"file",
"=",
"FileSystem",
".",
"fs",
".",
"pathResolve",
"(",
"file",
")",
";",
"var",
"readStream",
"=",
"new",
"ReadStream",
"(",
"file",
")",
";",
"return",
"_",
".",
"clone",
"(",
"readStream",
".",
"trackStack",
")",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
]
| track file stack | [
"track",
"file",
"stack"
]
| eb6c12080f6da8c5a20767d567bf80a49a099430 | https://github.com/wyicwx/bone/blob/eb6c12080f6da8c5a20767d567bf80a49a099430/lib/utils.js#L12-L24 |
|
44,216 | simonepri/osm-countries | index.js | get | function get(code) {
if (!Object.prototype.hasOwnProperty.call(osm, code)) {
throw new TypeError('The alpha-3 code provided was not found: ' + code);
}
return osm[code];
} | javascript | function get(code) {
if (!Object.prototype.hasOwnProperty.call(osm, code)) {
throw new TypeError('The alpha-3 code provided was not found: ' + code);
}
return osm[code];
} | [
"function",
"get",
"(",
"code",
")",
"{",
"if",
"(",
"!",
"Object",
".",
"prototype",
".",
"hasOwnProperty",
".",
"call",
"(",
"osm",
",",
"code",
")",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'The alpha-3 code provided was not found: '",
"+",
"code",
")",
";",
"}",
"return",
"osm",
"[",
"code",
"]",
";",
"}"
]
| Converts an alpha-3 iso 3166-1 code to its corrispective relation id on OSM.
@public
@param {string} code Alpha-3 iso 3166-1 country code.
@return {string} OSM relation id of the given country. | [
"Converts",
"an",
"alpha",
"-",
"3",
"iso",
"3166",
"-",
"1",
"code",
"to",
"its",
"corrispective",
"relation",
"id",
"on",
"OSM",
"."
]
| 60aa88eb5fd7199f26ac7c5410cbae0936378ebb | https://github.com/simonepri/osm-countries/blob/60aa88eb5fd7199f26ac7c5410cbae0936378ebb/index.js#L11-L16 |
44,217 | clubedaentrega/validate-fields | types/numeric.js | registerDual | function registerDual(numberType, numericType, checkFn, toJSONSchema) {
context.registerType(numberType, 'number', checkFn, numberType, extra => toJSONSchema('number', extra))
context.registerType(numericType, 'string', value => {
let numberValue = toNumber(value)
checkFn(numberValue)
return numberValue
}, numericType, () => ({
type: 'string',
format: numericType
}))
} | javascript | function registerDual(numberType, numericType, checkFn, toJSONSchema) {
context.registerType(numberType, 'number', checkFn, numberType, extra => toJSONSchema('number', extra))
context.registerType(numericType, 'string', value => {
let numberValue = toNumber(value)
checkFn(numberValue)
return numberValue
}, numericType, () => ({
type: 'string',
format: numericType
}))
} | [
"function",
"registerDual",
"(",
"numberType",
",",
"numericType",
",",
"checkFn",
",",
"toJSONSchema",
")",
"{",
"context",
".",
"registerType",
"(",
"numberType",
",",
"'number'",
",",
"checkFn",
",",
"numberType",
",",
"extra",
"=>",
"toJSONSchema",
"(",
"'number'",
",",
"extra",
")",
")",
"context",
".",
"registerType",
"(",
"numericType",
",",
"'string'",
",",
"value",
"=>",
"{",
"let",
"numberValue",
"=",
"toNumber",
"(",
"value",
")",
"checkFn",
"(",
"numberValue",
")",
"return",
"numberValue",
"}",
",",
"numericType",
",",
"(",
")",
"=>",
"(",
"{",
"type",
":",
"'string'",
",",
"format",
":",
"numericType",
"}",
")",
")",
"}"
]
| Register number and numeric dual basic types
@param {string} numberType
@param {string} numericType
@param {Function} checkFn
@param {function(string, *):Object} toJSONSchema
@private | [
"Register",
"number",
"and",
"numeric",
"dual",
"basic",
"types"
]
| 7213b20c082ddabe4cbe926100d72fc44da69327 | https://github.com/clubedaentrega/validate-fields/blob/7213b20c082ddabe4cbe926100d72fc44da69327/types/numeric.js#L139-L150 |
44,218 | clubedaentrega/validate-fields | types/numeric.js | registerTaggedDual | function registerTaggedDual(numberTag, numericTag, checkFn, toJSONSchema) {
context.registerTaggedType({
tag: numberTag,
jsonType: 'number',
minArgs: 2,
maxArgs: 2,
sparse: true,
numeric: true
}, checkFn, returnOriginal, toJSONSchema)
context.registerTaggedType({
tag: numericTag,
jsonType: 'string',
minArgs: 2,
maxArgs: 2,
sparse: true,
numeric: true
}, (value, args) => {
let numberValue = toNumber(value)
checkFn(numberValue, args)
return numberValue
}, returnOriginal, extra => ({
type: 'string',
format: extra.original
}))
} | javascript | function registerTaggedDual(numberTag, numericTag, checkFn, toJSONSchema) {
context.registerTaggedType({
tag: numberTag,
jsonType: 'number',
minArgs: 2,
maxArgs: 2,
sparse: true,
numeric: true
}, checkFn, returnOriginal, toJSONSchema)
context.registerTaggedType({
tag: numericTag,
jsonType: 'string',
minArgs: 2,
maxArgs: 2,
sparse: true,
numeric: true
}, (value, args) => {
let numberValue = toNumber(value)
checkFn(numberValue, args)
return numberValue
}, returnOriginal, extra => ({
type: 'string',
format: extra.original
}))
} | [
"function",
"registerTaggedDual",
"(",
"numberTag",
",",
"numericTag",
",",
"checkFn",
",",
"toJSONSchema",
")",
"{",
"context",
".",
"registerTaggedType",
"(",
"{",
"tag",
":",
"numberTag",
",",
"jsonType",
":",
"'number'",
",",
"minArgs",
":",
"2",
",",
"maxArgs",
":",
"2",
",",
"sparse",
":",
"true",
",",
"numeric",
":",
"true",
"}",
",",
"checkFn",
",",
"returnOriginal",
",",
"toJSONSchema",
")",
"context",
".",
"registerTaggedType",
"(",
"{",
"tag",
":",
"numericTag",
",",
"jsonType",
":",
"'string'",
",",
"minArgs",
":",
"2",
",",
"maxArgs",
":",
"2",
",",
"sparse",
":",
"true",
",",
"numeric",
":",
"true",
"}",
",",
"(",
"value",
",",
"args",
")",
"=>",
"{",
"let",
"numberValue",
"=",
"toNumber",
"(",
"value",
")",
"checkFn",
"(",
"numberValue",
",",
"args",
")",
"return",
"numberValue",
"}",
",",
"returnOriginal",
",",
"extra",
"=>",
"(",
"{",
"type",
":",
"'string'",
",",
"format",
":",
"extra",
".",
"original",
"}",
")",
")",
"}"
]
| Register number and numeric dual tagged types
@param {string} numberTag
@param {string} numericTag
@param {Function} checkFn
@param {function(*):Object} toJSONSchema
@private | [
"Register",
"number",
"and",
"numeric",
"dual",
"tagged",
"types"
]
| 7213b20c082ddabe4cbe926100d72fc44da69327 | https://github.com/clubedaentrega/validate-fields/blob/7213b20c082ddabe4cbe926100d72fc44da69327/types/numeric.js#L160-L185 |
44,219 | gamtiq/eva | src/eva.js | createFunction | function createFunction(sCode, settings) {
/*jshint evil:true, laxbreak:true, quotmark:false*/
var nI, params, sName;
if (! settings) {
settings = {};
}
params = settings.paramNames;
if (settings.expression) {
sCode = "return (" + sCode + ");";
}
if (settings.scope) {
if (params) {
nI = params.indexOf(",");
if (nI > -1) {
sName = params.substring(0, nI);
}
else {
sName = params;
}
}
else {
params = sName = "sc";
}
sCode = "with(" + sName + ") {" + sCode + "}";
}
if (settings.debug && (settings.debugFunc
|| (typeof console === "object" && console && typeof console.log === "function"))) {
sCode = 'try{'
+ sCode
+ '}catch(_e_){'
+ (settings.debugFunc || 'console.log')
+ '("'
+ (settings.debugMessage
? settings.debugMessage.replace(/"/g, '\\\"')
: 'Error in created function:')
+ '", _e_);}';
}
return params ? new Function(params, sCode) : new Function(sCode);
} | javascript | function createFunction(sCode, settings) {
/*jshint evil:true, laxbreak:true, quotmark:false*/
var nI, params, sName;
if (! settings) {
settings = {};
}
params = settings.paramNames;
if (settings.expression) {
sCode = "return (" + sCode + ");";
}
if (settings.scope) {
if (params) {
nI = params.indexOf(",");
if (nI > -1) {
sName = params.substring(0, nI);
}
else {
sName = params;
}
}
else {
params = sName = "sc";
}
sCode = "with(" + sName + ") {" + sCode + "}";
}
if (settings.debug && (settings.debugFunc
|| (typeof console === "object" && console && typeof console.log === "function"))) {
sCode = 'try{'
+ sCode
+ '}catch(_e_){'
+ (settings.debugFunc || 'console.log')
+ '("'
+ (settings.debugMessage
? settings.debugMessage.replace(/"/g, '\\\"')
: 'Error in created function:')
+ '", _e_);}';
}
return params ? new Function(params, sCode) : new Function(sCode);
} | [
"function",
"createFunction",
"(",
"sCode",
",",
"settings",
")",
"{",
"/*jshint evil:true, laxbreak:true, quotmark:false*/",
"var",
"nI",
",",
"params",
",",
"sName",
";",
"if",
"(",
"!",
"settings",
")",
"{",
"settings",
"=",
"{",
"}",
";",
"}",
"params",
"=",
"settings",
".",
"paramNames",
";",
"if",
"(",
"settings",
".",
"expression",
")",
"{",
"sCode",
"=",
"\"return (\"",
"+",
"sCode",
"+",
"\");\"",
";",
"}",
"if",
"(",
"settings",
".",
"scope",
")",
"{",
"if",
"(",
"params",
")",
"{",
"nI",
"=",
"params",
".",
"indexOf",
"(",
"\",\"",
")",
";",
"if",
"(",
"nI",
">",
"-",
"1",
")",
"{",
"sName",
"=",
"params",
".",
"substring",
"(",
"0",
",",
"nI",
")",
";",
"}",
"else",
"{",
"sName",
"=",
"params",
";",
"}",
"}",
"else",
"{",
"params",
"=",
"sName",
"=",
"\"sc\"",
";",
"}",
"sCode",
"=",
"\"with(\"",
"+",
"sName",
"+",
"\") {\"",
"+",
"sCode",
"+",
"\"}\"",
";",
"}",
"if",
"(",
"settings",
".",
"debug",
"&&",
"(",
"settings",
".",
"debugFunc",
"||",
"(",
"typeof",
"console",
"===",
"\"object\"",
"&&",
"console",
"&&",
"typeof",
"console",
".",
"log",
"===",
"\"function\"",
")",
")",
")",
"{",
"sCode",
"=",
"'try{'",
"+",
"sCode",
"+",
"'}catch(_e_){'",
"+",
"(",
"settings",
".",
"debugFunc",
"||",
"'console.log'",
")",
"+",
"'(\"'",
"+",
"(",
"settings",
".",
"debugMessage",
"?",
"settings",
".",
"debugMessage",
".",
"replace",
"(",
"/",
"\"",
"/",
"g",
",",
"'\\\\\\\"'",
")",
":",
"'Error in created function:'",
")",
"+",
"'\", _e_);}'",
";",
"}",
"return",
"params",
"?",
"new",
"Function",
"(",
"params",
",",
"sCode",
")",
":",
"new",
"Function",
"(",
"sCode",
")",
";",
"}"
]
| Create function to further use.
@param {String} sCode
Function's code.
@param {Object} [settings]
Operation settings. Keys are settings names, values are corresponding settings values.
The following settings are supported (setting's default value is specified in parentheses):
* `debug`: `Boolean` (`false`) - specifies whether simple means for debugging should be added into function;
when `true` value is specified (debug mode), the function's code is enclosed in `try` statement;
the corresponding `catch` block contains `console.log` statement to display message
(namely, value of `debugMessage` setting) and details about error
* `debugFunc`: `String` (`console.log`) - expression specifying a function that should be used to process error
when the error is caught in debug mode; the expression should be resolvable in global scope;
debug message (value of `debugMessage` setting) and error object will be passed into the function
* `debugMessage`: `String` (`Error in created function:`) - specifies message that should be shown/passed
before data about error when the error is caught in debug mode
* `expression`: `Boolean` (`false`) - specifies whether function's code is an expression;
when `true` value is specified, `return` statement is added at the beginning of function's code
* `paramNames`: `String` (`''`) - specifies names of function parameters
* `scope`: `Boolean` (`false`) - specifies whether function's code should be wrapped in `with` statement;
the value of function's first parameter is used as expression for `with` statement
@return {Function}
Created function.
@alias module:eva.createFunction | [
"Create",
"function",
"to",
"further",
"use",
"."
]
| ae2987da163d7f0a59e4e551cbcc8d4f4dae4cd5 | https://github.com/gamtiq/eva/blob/ae2987da163d7f0a59e4e551cbcc8d4f4dae4cd5/src/eva.js#L47-L85 |
44,220 | gamtiq/eva | src/eva.js | createDelegateMethod | function createDelegateMethod(delegate, sMethod, settings) {
var result = function() {
return delegate[sMethod].apply(delegate, arguments);
};
if (settings && settings.destination) {
settings.destination[settings.destinationMethod || sMethod] = result;
}
return result;
} | javascript | function createDelegateMethod(delegate, sMethod, settings) {
var result = function() {
return delegate[sMethod].apply(delegate, arguments);
};
if (settings && settings.destination) {
settings.destination[settings.destinationMethod || sMethod] = result;
}
return result;
} | [
"function",
"createDelegateMethod",
"(",
"delegate",
",",
"sMethod",
",",
"settings",
")",
"{",
"var",
"result",
"=",
"function",
"(",
")",
"{",
"return",
"delegate",
"[",
"sMethod",
"]",
".",
"apply",
"(",
"delegate",
",",
"arguments",
")",
";",
"}",
";",
"if",
"(",
"settings",
"&&",
"settings",
".",
"destination",
")",
"{",
"settings",
".",
"destination",
"[",
"settings",
".",
"destinationMethod",
"||",
"sMethod",
"]",
"=",
"result",
";",
"}",
"return",
"result",
";",
"}"
]
| Create function that executes specified method of the given object.
@param {Object} delegate
Object whose method will be executed when created function is called.
@param {String} sMethod
Name of method that will be executed.
@param {Object} [settings]
Operation settings. Keys are settings names, values are corresponding settings values.
The following settings are supported:
* `destination`: `Object` - target object into which the method will be added that should be used
to access the created function
* `destinationMethod`: `String` - name of method of the target object that will be used to access
the created function; the value of `sMethod` parameter by default
@return {Function}
Created function.
@alias module:eva.createDelegateMethod | [
"Create",
"function",
"that",
"executes",
"specified",
"method",
"of",
"the",
"given",
"object",
"."
]
| ae2987da163d7f0a59e4e551cbcc8d4f4dae4cd5 | https://github.com/gamtiq/eva/blob/ae2987da163d7f0a59e4e551cbcc8d4f4dae4cd5/src/eva.js#L125-L133 |
44,221 | gamtiq/eva | src/eva.js | closure | function closure(action, paramList, context, settings) {
if (! settings) {
settings = {};
}
var bUseArgs = ! settings.ignoreArgs,
bAppendArgs = ! settings.prependArgs;
return function() {
var params;
if (bUseArgs) {
params = paramList ? Array.prototype.slice.call(paramList, 0) : [];
if (bAppendArgs) {
params.push.apply(params, arguments);
}
else {
params = Array.prototype.slice.call(arguments, 0).concat(params);
}
}
else {
params = paramList || [];
}
return action.apply(context || null, params);
};
} | javascript | function closure(action, paramList, context, settings) {
if (! settings) {
settings = {};
}
var bUseArgs = ! settings.ignoreArgs,
bAppendArgs = ! settings.prependArgs;
return function() {
var params;
if (bUseArgs) {
params = paramList ? Array.prototype.slice.call(paramList, 0) : [];
if (bAppendArgs) {
params.push.apply(params, arguments);
}
else {
params = Array.prototype.slice.call(arguments, 0).concat(params);
}
}
else {
params = paramList || [];
}
return action.apply(context || null, params);
};
} | [
"function",
"closure",
"(",
"action",
",",
"paramList",
",",
"context",
",",
"settings",
")",
"{",
"if",
"(",
"!",
"settings",
")",
"{",
"settings",
"=",
"{",
"}",
";",
"}",
"var",
"bUseArgs",
"=",
"!",
"settings",
".",
"ignoreArgs",
",",
"bAppendArgs",
"=",
"!",
"settings",
".",
"prependArgs",
";",
"return",
"function",
"(",
")",
"{",
"var",
"params",
";",
"if",
"(",
"bUseArgs",
")",
"{",
"params",
"=",
"paramList",
"?",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"paramList",
",",
"0",
")",
":",
"[",
"]",
";",
"if",
"(",
"bAppendArgs",
")",
"{",
"params",
".",
"push",
".",
"apply",
"(",
"params",
",",
"arguments",
")",
";",
"}",
"else",
"{",
"params",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"0",
")",
".",
"concat",
"(",
"params",
")",
";",
"}",
"}",
"else",
"{",
"params",
"=",
"paramList",
"||",
"[",
"]",
";",
"}",
"return",
"action",
".",
"apply",
"(",
"context",
"||",
"null",
",",
"params",
")",
";",
"}",
";",
"}"
]
| Create function that executes specified function with given parameters and context and returns result of call.
@param {Function} action
Target function that will be executed when created function is called.
@param {Array} [paramList]
Array-like object representing parameters that should be passed into the target function specified in `action` argument.
@param {Object} [context]
Object that will be used as `this` value when calling the target function specified in `action` argument.
Default value is `null`.
@param {Object} [settings]
Operation settings. Keys are settings names, values are corresponding settings values.
The following settings are supported:
* `ignoreArgs`: `Boolean` - Whether arguments passed into the created function should be ignored.
Default value is `false` and means that arguments will be included in parameters list for the target function
depending of the value of `prependArgs` setting.
* `prependArgs`: `Boolean` - Whether arguments passed into the created function should be passed into the target function
before parameters specified in `paramList` argument. Default value is `false` and means that parameters list
for the target function will contain values from `paramList` argument followed by arguments passed into the created function
(this is similar to `Function.prototype.bind` behavior).
@return {Function}
Created function.
@alias module:eva.closure | [
"Create",
"function",
"that",
"executes",
"specified",
"function",
"with",
"given",
"parameters",
"and",
"context",
"and",
"returns",
"result",
"of",
"call",
"."
]
| ae2987da163d7f0a59e4e551cbcc8d4f4dae4cd5 | https://github.com/gamtiq/eva/blob/ae2987da163d7f0a59e4e551cbcc8d4f4dae4cd5/src/eva.js#L160-L183 |
44,222 | gamtiq/eva | src/eva.js | map | function map(funcList, paramList, context, settings) {
/*jshint laxbreak:true*/
var result = [],
nL = funcList.length,
bGetContext, bGetParamList, func, nI;
if (! paramList) {
paramList = [];
}
if (! context) {
context = null;
}
if (! settings) {
settings = {};
}
bGetContext = typeof context === "function" && ! settings.funcContext;
bGetParamList = typeof paramList === "function";
for (nI = 0; nI < nL; nI++) {
func = funcList[nI];
result[nI] = func.apply(bGetContext
? context(func, nI, funcList)
: context,
bGetParamList
? paramList(func, nI, funcList)
: paramList);
}
return result;
} | javascript | function map(funcList, paramList, context, settings) {
/*jshint laxbreak:true*/
var result = [],
nL = funcList.length,
bGetContext, bGetParamList, func, nI;
if (! paramList) {
paramList = [];
}
if (! context) {
context = null;
}
if (! settings) {
settings = {};
}
bGetContext = typeof context === "function" && ! settings.funcContext;
bGetParamList = typeof paramList === "function";
for (nI = 0; nI < nL; nI++) {
func = funcList[nI];
result[nI] = func.apply(bGetContext
? context(func, nI, funcList)
: context,
bGetParamList
? paramList(func, nI, funcList)
: paramList);
}
return result;
} | [
"function",
"map",
"(",
"funcList",
",",
"paramList",
",",
"context",
",",
"settings",
")",
"{",
"/*jshint laxbreak:true*/",
"var",
"result",
"=",
"[",
"]",
",",
"nL",
"=",
"funcList",
".",
"length",
",",
"bGetContext",
",",
"bGetParamList",
",",
"func",
",",
"nI",
";",
"if",
"(",
"!",
"paramList",
")",
"{",
"paramList",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"!",
"context",
")",
"{",
"context",
"=",
"null",
";",
"}",
"if",
"(",
"!",
"settings",
")",
"{",
"settings",
"=",
"{",
"}",
";",
"}",
"bGetContext",
"=",
"typeof",
"context",
"===",
"\"function\"",
"&&",
"!",
"settings",
".",
"funcContext",
";",
"bGetParamList",
"=",
"typeof",
"paramList",
"===",
"\"function\"",
";",
"for",
"(",
"nI",
"=",
"0",
";",
"nI",
"<",
"nL",
";",
"nI",
"++",
")",
"{",
"func",
"=",
"funcList",
"[",
"nI",
"]",
";",
"result",
"[",
"nI",
"]",
"=",
"func",
".",
"apply",
"(",
"bGetContext",
"?",
"context",
"(",
"func",
",",
"nI",
",",
"funcList",
")",
":",
"context",
",",
"bGetParamList",
"?",
"paramList",
"(",
"func",
",",
"nI",
",",
"funcList",
")",
":",
"paramList",
")",
";",
"}",
"return",
"result",
";",
"}"
]
| Call each function from specified list and return array containing results of calls.
@param {Array} funcList
Target functions that should be called.
@param {Array | Function} [paramList]
Parameters that should be passed into each target function.
If function is specified it should return array that will be used as parameters for target functions.
The following parameters will be passed into the function:
* a target function for which parameters list should be returned
* index of the target function
* array of all target functions
@param {Object | Function} [context]
Object that will be used as `this` value when calling each target function.
Default value is `null`.
If function is specified it should return object that will be used as `this` value.
Parameters of the function are equal to parameters of `paramList` function (see above).
@param {Object} [settings]
Operation settings. Keys are settings names, values are corresponding settings values.
The following settings are supported:
* `funcContext`: `Boolean` - Whether function that is specified as `context` parameter should be used directly
as `this` value. Default value is `false`.
@return {Array}
Results of functions calling.
@alias module:eva.map | [
"Call",
"each",
"function",
"from",
"specified",
"list",
"and",
"return",
"array",
"containing",
"results",
"of",
"calls",
"."
]
| ae2987da163d7f0a59e4e551cbcc8d4f4dae4cd5 | https://github.com/gamtiq/eva/blob/ae2987da163d7f0a59e4e551cbcc8d4f4dae4cd5/src/eva.js#L213-L239 |
44,223 | klarstil/lifx-http-api | source/utils.js | function(response, body) {
var responseCodes = [
{ codes: 400, message: 'Request was invalid.' },
{ codes: 401, message: 'Bad access token.' },
{ codes: 403, message: 'Bad OAuth scope.' },
{ codes: 404, message: 'Selector did not match any lights.' },
{ codes: 422, message: 'Missing or malformed parameters' },
{ codes: 426, message: 'HTTP was used to make the request instead of HTTPS. Repeat the request using HTTPS instead.' },
{ codes: 429, message: 'The request exceeded a rate limit.' },
{ codes: [ 500, 502, 503, 523 ], message: 'Something went wrong on Lif\'s end.' }
];
var error = '';
responseCodes.every(function(responseCode) {
if(_.isArray(responseCode.codes)) {
responseCode.codes.forEach(function(code) {
if (code === response.statusCode) {
error = responseCode.message;
return false;
}
return true;
});
}
});
// Special case HTTP code 422 Unprocessable Entity
if(response && response.statusCode === 422) {
error = body.error;
}
return error;
} | javascript | function(response, body) {
var responseCodes = [
{ codes: 400, message: 'Request was invalid.' },
{ codes: 401, message: 'Bad access token.' },
{ codes: 403, message: 'Bad OAuth scope.' },
{ codes: 404, message: 'Selector did not match any lights.' },
{ codes: 422, message: 'Missing or malformed parameters' },
{ codes: 426, message: 'HTTP was used to make the request instead of HTTPS. Repeat the request using HTTPS instead.' },
{ codes: 429, message: 'The request exceeded a rate limit.' },
{ codes: [ 500, 502, 503, 523 ], message: 'Something went wrong on Lif\'s end.' }
];
var error = '';
responseCodes.every(function(responseCode) {
if(_.isArray(responseCode.codes)) {
responseCode.codes.forEach(function(code) {
if (code === response.statusCode) {
error = responseCode.message;
return false;
}
return true;
});
}
});
// Special case HTTP code 422 Unprocessable Entity
if(response && response.statusCode === 422) {
error = body.error;
}
return error;
} | [
"function",
"(",
"response",
",",
"body",
")",
"{",
"var",
"responseCodes",
"=",
"[",
"{",
"codes",
":",
"400",
",",
"message",
":",
"'Request was invalid.'",
"}",
",",
"{",
"codes",
":",
"401",
",",
"message",
":",
"'Bad access token.'",
"}",
",",
"{",
"codes",
":",
"403",
",",
"message",
":",
"'Bad OAuth scope.'",
"}",
",",
"{",
"codes",
":",
"404",
",",
"message",
":",
"'Selector did not match any lights.'",
"}",
",",
"{",
"codes",
":",
"422",
",",
"message",
":",
"'Missing or malformed parameters'",
"}",
",",
"{",
"codes",
":",
"426",
",",
"message",
":",
"'HTTP was used to make the request instead of HTTPS. Repeat the request using HTTPS instead.'",
"}",
",",
"{",
"codes",
":",
"429",
",",
"message",
":",
"'The request exceeded a rate limit.'",
"}",
",",
"{",
"codes",
":",
"[",
"500",
",",
"502",
",",
"503",
",",
"523",
"]",
",",
"message",
":",
"'Something went wrong on Lif\\'s end.'",
"}",
"]",
";",
"var",
"error",
"=",
"''",
";",
"responseCodes",
".",
"every",
"(",
"function",
"(",
"responseCode",
")",
"{",
"if",
"(",
"_",
".",
"isArray",
"(",
"responseCode",
".",
"codes",
")",
")",
"{",
"responseCode",
".",
"codes",
".",
"forEach",
"(",
"function",
"(",
"code",
")",
"{",
"if",
"(",
"code",
"===",
"response",
".",
"statusCode",
")",
"{",
"error",
"=",
"responseCode",
".",
"message",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}",
")",
";",
"}",
"}",
")",
";",
"// Special case HTTP code 422 Unprocessable Entity",
"if",
"(",
"response",
"&&",
"response",
".",
"statusCode",
"===",
"422",
")",
"{",
"error",
"=",
"body",
".",
"error",
";",
"}",
"return",
"error",
";",
"}"
]
| Checks the HTTP response code and returns the according error message.
See: <http://api.developer.lifx.com/docs/errors>
@param {object} response
@param {string} body
@returns {string} | [
"Checks",
"the",
"HTTP",
"response",
"code",
"and",
"returns",
"the",
"according",
"error",
"message",
"."
]
| 90afb556c30ea5d1ac14958a159490f6f579241a | https://github.com/klarstil/lifx-http-api/blob/90afb556c30ea5d1ac14958a159490f6f579241a/source/utils.js#L14-L46 |
|
44,224 | klarstil/lifx-http-api | source/utils.js | function(selector) {
var validSelectors = [
'all',
'label:',
'id:',
'group_id:',
'group:',
'location_id:',
'location:',
'scene_id:'
], isValid = false;
if(!selector || !selector.length) {
return false;
}
validSelectors.every(function(sel) {
if(selector.startsWith(sel)) {
isValid = true;
return false;
}
return true;
});
return isValid;
} | javascript | function(selector) {
var validSelectors = [
'all',
'label:',
'id:',
'group_id:',
'group:',
'location_id:',
'location:',
'scene_id:'
], isValid = false;
if(!selector || !selector.length) {
return false;
}
validSelectors.every(function(sel) {
if(selector.startsWith(sel)) {
isValid = true;
return false;
}
return true;
});
return isValid;
} | [
"function",
"(",
"selector",
")",
"{",
"var",
"validSelectors",
"=",
"[",
"'all'",
",",
"'label:'",
",",
"'id:'",
",",
"'group_id:'",
",",
"'group:'",
",",
"'location_id:'",
",",
"'location:'",
",",
"'scene_id:'",
"]",
",",
"isValid",
"=",
"false",
";",
"if",
"(",
"!",
"selector",
"||",
"!",
"selector",
".",
"length",
")",
"{",
"return",
"false",
";",
"}",
"validSelectors",
".",
"every",
"(",
"function",
"(",
"sel",
")",
"{",
"if",
"(",
"selector",
".",
"startsWith",
"(",
"sel",
")",
")",
"{",
"isValid",
"=",
"true",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}",
")",
";",
"return",
"isValid",
";",
"}"
]
| Checks the light selector if it's valid.
See: <http://api.developer.lifx.com/docs/selectors>
@param {string} selector
@returns {boolean} | [
"Checks",
"the",
"light",
"selector",
"if",
"it",
"s",
"valid",
"."
]
| 90afb556c30ea5d1ac14958a159490f6f579241a | https://github.com/klarstil/lifx-http-api/blob/90afb556c30ea5d1ac14958a159490f6f579241a/source/utils.js#L56-L83 |
|
44,225 | clubedaentrega/validate-fields | index.js | context | function context(schema, value, options) {
schema = context.parse(schema)
let ret = schema.validate(value, options)
context.lastError = schema.lastError
context.lastErrorMessage = schema.lastErrorMessage
context.lastErrorPath = schema.lastErrorPath
return ret
} | javascript | function context(schema, value, options) {
schema = context.parse(schema)
let ret = schema.validate(value, options)
context.lastError = schema.lastError
context.lastErrorMessage = schema.lastErrorMessage
context.lastErrorPath = schema.lastErrorPath
return ret
} | [
"function",
"context",
"(",
"schema",
",",
"value",
",",
"options",
")",
"{",
"schema",
"=",
"context",
".",
"parse",
"(",
"schema",
")",
"let",
"ret",
"=",
"schema",
".",
"validate",
"(",
"value",
",",
"options",
")",
"context",
".",
"lastError",
"=",
"schema",
".",
"lastError",
"context",
".",
"lastErrorMessage",
"=",
"schema",
".",
"lastErrorMessage",
"context",
".",
"lastErrorPath",
"=",
"schema",
".",
"lastErrorPath",
"return",
"ret",
"}"
]
| Validate the given value against the given schema
@param {*} schema
@param {*} value The value can be altered by the validation
@param {Object} [options] Validation options
@returns {boolean} whether the value is valid or nor
@throw if the schema is invalid | [
"Validate",
"the",
"given",
"value",
"against",
"the",
"given",
"schema"
]
| 7213b20c082ddabe4cbe926100d72fc44da69327 | https://github.com/clubedaentrega/validate-fields/blob/7213b20c082ddabe4cbe926100d72fc44da69327/index.js#L36-L43 |
44,226 | clubedaentrega/validate-fields | index.js | parseTagged | function parseTagged(definition, taggedTypes) {
let match = definition.match(/^(\w+)(?:\((.*)\))?$/),
tag, args, typeInfo
if (!match) {
return
}
// Get type info
tag = match[1]
typeInfo = taggedTypes[tag]
if (!typeInfo) {
return
}
// Special no-'()' case: only match 'tag' if minArgs is zero
if (typeInfo.minArgs > 0 && match[2] === undefined) {
return
}
// Parse and check args
args = (match[2] || '').trim().split(/\s*,\s*/)
if (args.length === 1 && args[0] === '') {
// Especial empty case
args = []
}
args = args.map((arg, i) => {
if (!arg) {
if (!typeInfo.sparse) {
throw new Error('Missing argument at position ' + i + ' for tagged type ' + tag)
}
return
}
if (typeInfo.numeric) {
arg = Number(arg)
if (isNaN(arg)) {
throw new Error('Invalid numeric argument at position ' + i + ' for tagged type ' + tag)
}
}
return arg
})
args.original = definition
if (args.length < typeInfo.minArgs) {
throw new Error('Too few arguments for tagged type ' + tag)
} else if (typeInfo.maxArgs && args.length > typeInfo.maxArgs) {
throw new Error('Too many arguments for tagged type ' + tag)
}
return new Field(typeInfo.type, typeInfo.parseArgs ? typeInfo.parseArgs(args) : args)
} | javascript | function parseTagged(definition, taggedTypes) {
let match = definition.match(/^(\w+)(?:\((.*)\))?$/),
tag, args, typeInfo
if (!match) {
return
}
// Get type info
tag = match[1]
typeInfo = taggedTypes[tag]
if (!typeInfo) {
return
}
// Special no-'()' case: only match 'tag' if minArgs is zero
if (typeInfo.minArgs > 0 && match[2] === undefined) {
return
}
// Parse and check args
args = (match[2] || '').trim().split(/\s*,\s*/)
if (args.length === 1 && args[0] === '') {
// Especial empty case
args = []
}
args = args.map((arg, i) => {
if (!arg) {
if (!typeInfo.sparse) {
throw new Error('Missing argument at position ' + i + ' for tagged type ' + tag)
}
return
}
if (typeInfo.numeric) {
arg = Number(arg)
if (isNaN(arg)) {
throw new Error('Invalid numeric argument at position ' + i + ' for tagged type ' + tag)
}
}
return arg
})
args.original = definition
if (args.length < typeInfo.minArgs) {
throw new Error('Too few arguments for tagged type ' + tag)
} else if (typeInfo.maxArgs && args.length > typeInfo.maxArgs) {
throw new Error('Too many arguments for tagged type ' + tag)
}
return new Field(typeInfo.type, typeInfo.parseArgs ? typeInfo.parseArgs(args) : args)
} | [
"function",
"parseTagged",
"(",
"definition",
",",
"taggedTypes",
")",
"{",
"let",
"match",
"=",
"definition",
".",
"match",
"(",
"/",
"^(\\w+)(?:\\((.*)\\))?$",
"/",
")",
",",
"tag",
",",
"args",
",",
"typeInfo",
"if",
"(",
"!",
"match",
")",
"{",
"return",
"}",
"// Get type info",
"tag",
"=",
"match",
"[",
"1",
"]",
"typeInfo",
"=",
"taggedTypes",
"[",
"tag",
"]",
"if",
"(",
"!",
"typeInfo",
")",
"{",
"return",
"}",
"// Special no-'()' case: only match 'tag' if minArgs is zero",
"if",
"(",
"typeInfo",
".",
"minArgs",
">",
"0",
"&&",
"match",
"[",
"2",
"]",
"===",
"undefined",
")",
"{",
"return",
"}",
"// Parse and check args",
"args",
"=",
"(",
"match",
"[",
"2",
"]",
"||",
"''",
")",
".",
"trim",
"(",
")",
".",
"split",
"(",
"/",
"\\s*,\\s*",
"/",
")",
"if",
"(",
"args",
".",
"length",
"===",
"1",
"&&",
"args",
"[",
"0",
"]",
"===",
"''",
")",
"{",
"// Especial empty case",
"args",
"=",
"[",
"]",
"}",
"args",
"=",
"args",
".",
"map",
"(",
"(",
"arg",
",",
"i",
")",
"=>",
"{",
"if",
"(",
"!",
"arg",
")",
"{",
"if",
"(",
"!",
"typeInfo",
".",
"sparse",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Missing argument at position '",
"+",
"i",
"+",
"' for tagged type '",
"+",
"tag",
")",
"}",
"return",
"}",
"if",
"(",
"typeInfo",
".",
"numeric",
")",
"{",
"arg",
"=",
"Number",
"(",
"arg",
")",
"if",
"(",
"isNaN",
"(",
"arg",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Invalid numeric argument at position '",
"+",
"i",
"+",
"' for tagged type '",
"+",
"tag",
")",
"}",
"}",
"return",
"arg",
"}",
")",
"args",
".",
"original",
"=",
"definition",
"if",
"(",
"args",
".",
"length",
"<",
"typeInfo",
".",
"minArgs",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Too few arguments for tagged type '",
"+",
"tag",
")",
"}",
"else",
"if",
"(",
"typeInfo",
".",
"maxArgs",
"&&",
"args",
".",
"length",
">",
"typeInfo",
".",
"maxArgs",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Too many arguments for tagged type '",
"+",
"tag",
")",
"}",
"return",
"new",
"Field",
"(",
"typeInfo",
".",
"type",
",",
"typeInfo",
".",
"parseArgs",
"?",
"typeInfo",
".",
"parseArgs",
"(",
"args",
")",
":",
"args",
")",
"}"
]
| Try to parse a string definition as a tagged type
@private
@param {string} definition
@param {Object<String, Object>} taggedTypes
@returns {?Field} | [
"Try",
"to",
"parse",
"a",
"string",
"definition",
"as",
"a",
"tagged",
"type"
]
| 7213b20c082ddabe4cbe926100d72fc44da69327 | https://github.com/clubedaentrega/validate-fields/blob/7213b20c082ddabe4cbe926100d72fc44da69327/index.js#L279-L329 |
44,227 | postmanlabs/generic-bitmask | lib/util.js | function (recipient, donor) {
for (var prop in donor) {
donor.hasOwnProperty(prop) && (recipient[prop] = donor[prop]);
}
return recipient;
} | javascript | function (recipient, donor) {
for (var prop in donor) {
donor.hasOwnProperty(prop) && (recipient[prop] = donor[prop]);
}
return recipient;
} | [
"function",
"(",
"recipient",
",",
"donor",
")",
"{",
"for",
"(",
"var",
"prop",
"in",
"donor",
")",
"{",
"donor",
".",
"hasOwnProperty",
"(",
"prop",
")",
"&&",
"(",
"recipient",
"[",
"prop",
"]",
"=",
"donor",
"[",
"prop",
"]",
")",
";",
"}",
"return",
"recipient",
";",
"}"
]
| Performs shallow copy of one object into another.
@param {object} recipient
@param {object} donor
@returns {object} - returns the seeded recipient parameter | [
"Performs",
"shallow",
"copy",
"of",
"one",
"object",
"into",
"another",
"."
]
| 9c940f6ef7c2fdef2f8523b1cb562ebcc8b8a50d | https://github.com/postmanlabs/generic-bitmask/blob/9c940f6ef7c2fdef2f8523b1cb562ebcc8b8a50d/lib/util.js#L12-L17 |
|
44,228 | postmanlabs/generic-bitmask | lib/util.js | function (obj, mapper, scope) {
var map = {},
prop;
scope = scope || obj;
for (prop in obj) {
obj.hasOwnProperty(prop) && (map[prop] = mapper.call(scope, obj[prop], prop, obj));
}
return map;
} | javascript | function (obj, mapper, scope) {
var map = {},
prop;
scope = scope || obj;
for (prop in obj) {
obj.hasOwnProperty(prop) && (map[prop] = mapper.call(scope, obj[prop], prop, obj));
}
return map;
} | [
"function",
"(",
"obj",
",",
"mapper",
",",
"scope",
")",
"{",
"var",
"map",
"=",
"{",
"}",
",",
"prop",
";",
"scope",
"=",
"scope",
"||",
"obj",
";",
"for",
"(",
"prop",
"in",
"obj",
")",
"{",
"obj",
".",
"hasOwnProperty",
"(",
"prop",
")",
"&&",
"(",
"map",
"[",
"prop",
"]",
"=",
"mapper",
".",
"call",
"(",
"scope",
",",
"obj",
"[",
"prop",
"]",
",",
"prop",
",",
"obj",
")",
")",
";",
"}",
"return",
"map",
";",
"}"
]
| Creates a new object with mapped values from another object
@param {object} obj
@param {function} mapper
@param {*=} [scope]
@returns {object} | [
"Creates",
"a",
"new",
"object",
"with",
"mapped",
"values",
"from",
"another",
"object"
]
| 9c940f6ef7c2fdef2f8523b1cb562ebcc8b8a50d | https://github.com/postmanlabs/generic-bitmask/blob/9c940f6ef7c2fdef2f8523b1cb562ebcc8b8a50d/lib/util.js#L27-L37 |
|
44,229 | frankgerhardt/botkit-matrix | matrixClient.js | verifyDevice | async function verifyDevice (userId, deviceId) {
await exports.matrixClient.setDeviceKnown(userId, deviceId, true);
await exports.matrixClient.setDeviceVerified(userId, deviceId, true);
} | javascript | async function verifyDevice (userId, deviceId) {
await exports.matrixClient.setDeviceKnown(userId, deviceId, true);
await exports.matrixClient.setDeviceVerified(userId, deviceId, true);
} | [
"async",
"function",
"verifyDevice",
"(",
"userId",
",",
"deviceId",
")",
"{",
"await",
"exports",
".",
"matrixClient",
".",
"setDeviceKnown",
"(",
"userId",
",",
"deviceId",
",",
"true",
")",
";",
"await",
"exports",
".",
"matrixClient",
".",
"setDeviceVerified",
"(",
"userId",
",",
"deviceId",
",",
"true",
")",
";",
"}"
]
| This function calls the functions from matrix-js-sdk to verify
the devices.
Implicitly returns a Promise because it's an async function.
@function verifyDevice
@param userId - The user who's devices has to be verified
@param deviceId - The ID of the device which has to be verified
@returns {Promise<void>} | [
"This",
"function",
"calls",
"the",
"functions",
"from",
"matrix",
"-",
"js",
"-",
"sdk",
"to",
"verify",
"the",
"devices",
".",
"Implicitly",
"returns",
"a",
"Promise",
"because",
"it",
"s",
"an",
"async",
"function",
"."
]
| 3d7ae1f0c46af6905f6edbe945d43585b5de4bd1 | https://github.com/frankgerhardt/botkit-matrix/blob/3d7ae1f0c46af6905f6edbe945d43585b5de4bd1/matrixClient.js#L54-L57 |
44,230 | azu/textlint-plugin-asciidoc-loose | src/NodeBuilder.js | fixParagraphNode | function fixParagraphNode(node, fullText) {
const firstNode = node.children[0];
const lastNode = node.children[node.children.length - 1];
node.range = [firstNode.range[0], lastNode.range[1]];
node.raw = fullText.slice(node.range[0], node.range[1]);
node.loc = {
start: {
line: firstNode.loc.start.line,
column: firstNode.loc.start.column
},
end: {
line: lastNode.loc.end.line,
column: lastNode.loc.end.column
}
};
} | javascript | function fixParagraphNode(node, fullText) {
const firstNode = node.children[0];
const lastNode = node.children[node.children.length - 1];
node.range = [firstNode.range[0], lastNode.range[1]];
node.raw = fullText.slice(node.range[0], node.range[1]);
node.loc = {
start: {
line: firstNode.loc.start.line,
column: firstNode.loc.start.column
},
end: {
line: lastNode.loc.end.line,
column: lastNode.loc.end.column
}
};
} | [
"function",
"fixParagraphNode",
"(",
"node",
",",
"fullText",
")",
"{",
"const",
"firstNode",
"=",
"node",
".",
"children",
"[",
"0",
"]",
";",
"const",
"lastNode",
"=",
"node",
".",
"children",
"[",
"node",
".",
"children",
".",
"length",
"-",
"1",
"]",
";",
"node",
".",
"range",
"=",
"[",
"firstNode",
".",
"range",
"[",
"0",
"]",
",",
"lastNode",
".",
"range",
"[",
"1",
"]",
"]",
";",
"node",
".",
"raw",
"=",
"fullText",
".",
"slice",
"(",
"node",
".",
"range",
"[",
"0",
"]",
",",
"node",
".",
"range",
"[",
"1",
"]",
")",
";",
"node",
".",
"loc",
"=",
"{",
"start",
":",
"{",
"line",
":",
"firstNode",
".",
"loc",
".",
"start",
".",
"line",
",",
"column",
":",
"firstNode",
".",
"loc",
".",
"start",
".",
"column",
"}",
",",
"end",
":",
"{",
"line",
":",
"lastNode",
".",
"loc",
".",
"end",
".",
"line",
",",
"column",
":",
"lastNode",
".",
"loc",
".",
"end",
".",
"column",
"}",
"}",
";",
"}"
]
| fill properties of paragraph node.
@param {TxtNode} node - Paragraph node to modify
@param {string} fullText - Full text of the document | [
"fill",
"properties",
"of",
"paragraph",
"node",
"."
]
| 7a69051adbb550bcc874fa25d84ebec07fa481ac | https://github.com/azu/textlint-plugin-asciidoc-loose/blob/7a69051adbb550bcc874fa25d84ebec07fa481ac/src/NodeBuilder.js#L25-L40 |
44,231 | jdeal/doctor | report/default.js | fixSignatureParams | function fixSignatureParams(node, item, signature) {
signature.params = [];
for (var i = 0; i < signature.arity; i++) {
var paramCopy = _.extend({}, item.params[i]);
if (node && node.paramTags) {
if (node.paramTags[paramCopy.name]) {
_.extend(paramCopy, node.paramTags[paramCopy.name]);
}
}
signature.params.push(paramCopy);
}
} | javascript | function fixSignatureParams(node, item, signature) {
signature.params = [];
for (var i = 0; i < signature.arity; i++) {
var paramCopy = _.extend({}, item.params[i]);
if (node && node.paramTags) {
if (node.paramTags[paramCopy.name]) {
_.extend(paramCopy, node.paramTags[paramCopy.name]);
}
}
signature.params.push(paramCopy);
}
} | [
"function",
"fixSignatureParams",
"(",
"node",
",",
"item",
",",
"signature",
")",
"{",
"signature",
".",
"params",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"signature",
".",
"arity",
";",
"i",
"++",
")",
"{",
"var",
"paramCopy",
"=",
"_",
".",
"extend",
"(",
"{",
"}",
",",
"item",
".",
"params",
"[",
"i",
"]",
")",
";",
"if",
"(",
"node",
"&&",
"node",
".",
"paramTags",
")",
"{",
"if",
"(",
"node",
".",
"paramTags",
"[",
"paramCopy",
".",
"name",
"]",
")",
"{",
"_",
".",
"extend",
"(",
"paramCopy",
",",
"node",
".",
"paramTags",
"[",
"paramCopy",
".",
"name",
"]",
")",
";",
"}",
"}",
"signature",
".",
"params",
".",
"push",
"(",
"paramCopy",
")",
";",
"}",
"}"
]
| make a set of params to match the signature | [
"make",
"a",
"set",
"of",
"params",
"to",
"match",
"the",
"signature"
]
| e1516f9cac6a899dbf3c624026deac3061f4ec63 | https://github.com/jdeal/doctor/blob/e1516f9cac6a899dbf3c624026deac3061f4ec63/report/default.js#L7-L18 |
44,232 | enmasseio/distribus | lib/Host.js | closeHost | function closeHost() {
// close the host itself
me.addresses = {};
if (me.server) {
me.server.close();
me.server = null;
me.address = null;
me.port = null;
me.url = null;
}
return me;
} | javascript | function closeHost() {
// close the host itself
me.addresses = {};
if (me.server) {
me.server.close();
me.server = null;
me.address = null;
me.port = null;
me.url = null;
}
return me;
} | [
"function",
"closeHost",
"(",
")",
"{",
"// close the host itself",
"me",
".",
"addresses",
"=",
"{",
"}",
";",
"if",
"(",
"me",
".",
"server",
")",
"{",
"me",
".",
"server",
".",
"close",
"(",
")",
";",
"me",
".",
"server",
"=",
"null",
";",
"me",
".",
"address",
"=",
"null",
";",
"me",
".",
"port",
"=",
"null",
";",
"me",
".",
"url",
"=",
"null",
";",
"}",
"return",
"me",
";",
"}"
]
| close the host, and clean up cache | [
"close",
"the",
"host",
"and",
"clean",
"up",
"cache"
]
| ce8dd12cd2fdf15de7eee89426e291b26e70bdc8 | https://github.com/enmasseio/distribus/blob/ce8dd12cd2fdf15de7eee89426e291b26e70bdc8/lib/Host.js#L562-L575 |
44,233 | filefog/filefog | lib/errors.js | FFParameterRejected | function FFParameterRejected(parameter) {
Error.call(this);
Error.captureStackTrace(this, arguments.callee);
this.message = 'A parameter provided is absent, malformed or invalid for other reasons: '+parameter;
} | javascript | function FFParameterRejected(parameter) {
Error.call(this);
Error.captureStackTrace(this, arguments.callee);
this.message = 'A parameter provided is absent, malformed or invalid for other reasons: '+parameter;
} | [
"function",
"FFParameterRejected",
"(",
"parameter",
")",
"{",
"Error",
".",
"call",
"(",
"this",
")",
";",
"Error",
".",
"captureStackTrace",
"(",
"this",
",",
"arguments",
".",
"callee",
")",
";",
"this",
".",
"message",
"=",
"'A parameter provided is absent, malformed or invalid for other reasons: '",
"+",
"parameter",
";",
"}"
]
| Thrown when a parameter provided is absent, malformed or invalid for other reasons
@constructor FFParameterRejected
@method FFParameterRejected
@param {String} parameter - the name of the parameter that is invalid
@return | [
"Thrown",
"when",
"a",
"parameter",
"provided",
"is",
"absent",
"malformed",
"or",
"invalid",
"for",
"other",
"reasons"
]
| 16040ef431e0af8aeee08b445c046a6805242cf3 | https://github.com/filefog/filefog/blob/16040ef431e0af8aeee08b445c046a6805242cf3/lib/errors.js#L10-L14 |
44,234 | jeremenichelli/web-component-refs | src/web-component-refs.js | collectRefs | function collectRefs() {
// check if there's a shadow root in the element
if (typeof this.shadowRoot === 'undefined') {
throw new Error('You must create a shadowRoot on the element');
}
// create refs base object
this.refs = {};
var refsList = this.shadowRoot.querySelectorAll('[ref]');
// collect refs if any
if (refsList.length > 0) {
var refsArray = _toArray(refsList);
refsArray.map(_assignRef.bind(this));
}
// observe added and removed child nodes
var refsMutationObserver = new MutationObserver(_handleMutations.bind(this));
refsMutationObserver.observe(this.shadowRoot, {
childList: true,
subtree: true
});
} | javascript | function collectRefs() {
// check if there's a shadow root in the element
if (typeof this.shadowRoot === 'undefined') {
throw new Error('You must create a shadowRoot on the element');
}
// create refs base object
this.refs = {};
var refsList = this.shadowRoot.querySelectorAll('[ref]');
// collect refs if any
if (refsList.length > 0) {
var refsArray = _toArray(refsList);
refsArray.map(_assignRef.bind(this));
}
// observe added and removed child nodes
var refsMutationObserver = new MutationObserver(_handleMutations.bind(this));
refsMutationObserver.observe(this.shadowRoot, {
childList: true,
subtree: true
});
} | [
"function",
"collectRefs",
"(",
")",
"{",
"// check if there's a shadow root in the element",
"if",
"(",
"typeof",
"this",
".",
"shadowRoot",
"===",
"'undefined'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'You must create a shadowRoot on the element'",
")",
";",
"}",
"// create refs base object",
"this",
".",
"refs",
"=",
"{",
"}",
";",
"var",
"refsList",
"=",
"this",
".",
"shadowRoot",
".",
"querySelectorAll",
"(",
"'[ref]'",
")",
";",
"// collect refs if any",
"if",
"(",
"refsList",
".",
"length",
">",
"0",
")",
"{",
"var",
"refsArray",
"=",
"_toArray",
"(",
"refsList",
")",
";",
"refsArray",
".",
"map",
"(",
"_assignRef",
".",
"bind",
"(",
"this",
")",
")",
";",
"}",
"// observe added and removed child nodes",
"var",
"refsMutationObserver",
"=",
"new",
"MutationObserver",
"(",
"_handleMutations",
".",
"bind",
"(",
"this",
")",
")",
";",
"refsMutationObserver",
".",
"observe",
"(",
"this",
".",
"shadowRoot",
",",
"{",
"childList",
":",
"true",
",",
"subtree",
":",
"true",
"}",
")",
";",
"}"
]
| Inspects shadow root and creates a refs object in a custom element
@method collectRefs
@returns {undefined} | [
"Inspects",
"shadow",
"root",
"and",
"creates",
"a",
"refs",
"object",
"in",
"a",
"custom",
"element"
]
| c98c04ee458084773fa5a3eac533da289ba4348c | https://github.com/jeremenichelli/web-component-refs/blob/c98c04ee458084773fa5a3eac533da289ba4348c/src/web-component-refs.js#L6-L31 |
44,235 | jeremenichelli/web-component-refs | src/web-component-refs.js | _isRefNode | function _isRefNode(node) {
return (
node.nodeType
&& node.nodeType === 1
&& (node.hasAttribute('ref') || typeof node.__refString__ === 'string')
);
} | javascript | function _isRefNode(node) {
return (
node.nodeType
&& node.nodeType === 1
&& (node.hasAttribute('ref') || typeof node.__refString__ === 'string')
);
} | [
"function",
"_isRefNode",
"(",
"node",
")",
"{",
"return",
"(",
"node",
".",
"nodeType",
"&&",
"node",
".",
"nodeType",
"===",
"1",
"&&",
"(",
"node",
".",
"hasAttribute",
"(",
"'ref'",
")",
"||",
"typeof",
"node",
".",
"__refString__",
"===",
"'string'",
")",
")",
";",
"}"
]
| Checks if node has a ref attribute
@method _isRefNode
@param {Node} node
@returns {Boolean} | [
"Checks",
"if",
"node",
"has",
"a",
"ref",
"attribute"
]
| c98c04ee458084773fa5a3eac533da289ba4348c | https://github.com/jeremenichelli/web-component-refs/blob/c98c04ee458084773fa5a3eac533da289ba4348c/src/web-component-refs.js#L49-L55 |
44,236 | jeremenichelli/web-component-refs | src/web-component-refs.js | _handleSingleMutation | function _handleSingleMutation(mutation) {
var addedNodes = _toArray(mutation.addedNodes);
var addedRefs = addedNodes.filter(_isRefNode);
// assign added nodes
addedRefs.map(_assignRef.bind(this));
var removedNodes = _toArray(mutation.removedNodes);
var removedRefs = removedNodes.filter(_isRefNode);
// assign removed nodes
removedRefs.map(_deleteRef.bind(this));
} | javascript | function _handleSingleMutation(mutation) {
var addedNodes = _toArray(mutation.addedNodes);
var addedRefs = addedNodes.filter(_isRefNode);
// assign added nodes
addedRefs.map(_assignRef.bind(this));
var removedNodes = _toArray(mutation.removedNodes);
var removedRefs = removedNodes.filter(_isRefNode);
// assign removed nodes
removedRefs.map(_deleteRef.bind(this));
} | [
"function",
"_handleSingleMutation",
"(",
"mutation",
")",
"{",
"var",
"addedNodes",
"=",
"_toArray",
"(",
"mutation",
".",
"addedNodes",
")",
";",
"var",
"addedRefs",
"=",
"addedNodes",
".",
"filter",
"(",
"_isRefNode",
")",
";",
"// assign added nodes",
"addedRefs",
".",
"map",
"(",
"_assignRef",
".",
"bind",
"(",
"this",
")",
")",
";",
"var",
"removedNodes",
"=",
"_toArray",
"(",
"mutation",
".",
"removedNodes",
")",
";",
"var",
"removedRefs",
"=",
"removedNodes",
".",
"filter",
"(",
"_isRefNode",
")",
";",
"// assign removed nodes",
"removedRefs",
".",
"map",
"(",
"_deleteRef",
".",
"bind",
"(",
"this",
")",
")",
";",
"}"
]
| Callback to detect added and removed nodes from a single mutation
@method _handleSingleMutation
@param {MutationRecord} mutation
@returns {undefined} | [
"Callback",
"to",
"detect",
"added",
"and",
"removed",
"nodes",
"from",
"a",
"single",
"mutation"
]
| c98c04ee458084773fa5a3eac533da289ba4348c | https://github.com/jeremenichelli/web-component-refs/blob/c98c04ee458084773fa5a3eac533da289ba4348c/src/web-component-refs.js#L91-L103 |
44,237 | rjrodger/seneca-jsonrest-api | jsonrest-api.js | action_putpost | function action_putpost(si,args,done) {
var ent_type = parse_ent(args)
var ent = si.make(ent_type.zone,ent_type.base,ent_type.name)
var data = args.data || {}
var good = _.filter(_.keys(data),function(k){return !~k.indexOf('$')})
var fields = _.pick(data,good)
ent.data$(fields)
if( null != ent_type.entid ) {
ent.id = ent_type.entid
}
else if( null != data.id$ && options.allow_id ) {
ent.id$ = data.id$
}
save_aspect(si,{args:args,ent:ent},done,function(ctxt,done){
ctxt.ent.save$(function(err,ent){
var data = ent ? ent.data$(true,'string') : null
done(err, data)
})
})
} | javascript | function action_putpost(si,args,done) {
var ent_type = parse_ent(args)
var ent = si.make(ent_type.zone,ent_type.base,ent_type.name)
var data = args.data || {}
var good = _.filter(_.keys(data),function(k){return !~k.indexOf('$')})
var fields = _.pick(data,good)
ent.data$(fields)
if( null != ent_type.entid ) {
ent.id = ent_type.entid
}
else if( null != data.id$ && options.allow_id ) {
ent.id$ = data.id$
}
save_aspect(si,{args:args,ent:ent},done,function(ctxt,done){
ctxt.ent.save$(function(err,ent){
var data = ent ? ent.data$(true,'string') : null
done(err, data)
})
})
} | [
"function",
"action_putpost",
"(",
"si",
",",
"args",
",",
"done",
")",
"{",
"var",
"ent_type",
"=",
"parse_ent",
"(",
"args",
")",
"var",
"ent",
"=",
"si",
".",
"make",
"(",
"ent_type",
".",
"zone",
",",
"ent_type",
".",
"base",
",",
"ent_type",
".",
"name",
")",
"var",
"data",
"=",
"args",
".",
"data",
"||",
"{",
"}",
"var",
"good",
"=",
"_",
".",
"filter",
"(",
"_",
".",
"keys",
"(",
"data",
")",
",",
"function",
"(",
"k",
")",
"{",
"return",
"!",
"~",
"k",
".",
"indexOf",
"(",
"'$'",
")",
"}",
")",
"var",
"fields",
"=",
"_",
".",
"pick",
"(",
"data",
",",
"good",
")",
"ent",
".",
"data$",
"(",
"fields",
")",
"if",
"(",
"null",
"!=",
"ent_type",
".",
"entid",
")",
"{",
"ent",
".",
"id",
"=",
"ent_type",
".",
"entid",
"}",
"else",
"if",
"(",
"null",
"!=",
"data",
".",
"id$",
"&&",
"options",
".",
"allow_id",
")",
"{",
"ent",
".",
"id$",
"=",
"data",
".",
"id$",
"}",
"save_aspect",
"(",
"si",
",",
"{",
"args",
":",
"args",
",",
"ent",
":",
"ent",
"}",
",",
"done",
",",
"function",
"(",
"ctxt",
",",
"done",
")",
"{",
"ctxt",
".",
"ent",
".",
"save$",
"(",
"function",
"(",
"err",
",",
"ent",
")",
"{",
"var",
"data",
"=",
"ent",
"?",
"ent",
".",
"data$",
"(",
"true",
",",
"'string'",
")",
":",
"null",
"done",
"(",
"err",
",",
"data",
")",
"}",
")",
"}",
")",
"}"
]
| lenient with PUT and POST - treat them as aliases, and both can create new entities | [
"lenient",
"with",
"PUT",
"and",
"POST",
"-",
"treat",
"them",
"as",
"aliases",
"and",
"both",
"can",
"create",
"new",
"entities"
]
| b5c749de78694c599f67b999f1c1e47e36708133 | https://github.com/rjrodger/seneca-jsonrest-api/blob/b5c749de78694c599f67b999f1c1e47e36708133/jsonrest-api.js#L194-L219 |
44,238 | johnsonjo4531/videojs-gifplayer | src/plugin.js | handleVisibilityChange | function handleVisibilityChange() {
if (document[hidden]) {
let gifPlayers = document.querySelectorAll('.vjs-gifplayer');
for (let gifPlayer of gifPlayers) {
let player = gifPlayer.player;
if (player) {
player.pause();
}
}
} else {
autoPlayGifs();
}
} | javascript | function handleVisibilityChange() {
if (document[hidden]) {
let gifPlayers = document.querySelectorAll('.vjs-gifplayer');
for (let gifPlayer of gifPlayers) {
let player = gifPlayer.player;
if (player) {
player.pause();
}
}
} else {
autoPlayGifs();
}
} | [
"function",
"handleVisibilityChange",
"(",
")",
"{",
"if",
"(",
"document",
"[",
"hidden",
"]",
")",
"{",
"let",
"gifPlayers",
"=",
"document",
".",
"querySelectorAll",
"(",
"'.vjs-gifplayer'",
")",
";",
"for",
"(",
"let",
"gifPlayer",
"of",
"gifPlayers",
")",
"{",
"let",
"player",
"=",
"gifPlayer",
".",
"player",
";",
"if",
"(",
"player",
")",
"{",
"player",
".",
"pause",
"(",
")",
";",
"}",
"}",
"}",
"else",
"{",
"autoPlayGifs",
"(",
")",
";",
"}",
"}"
]
| If the page is hidden, pause the video; if the page is shown, play the video | [
"If",
"the",
"page",
"is",
"hidden",
"pause",
"the",
"video",
";",
"if",
"the",
"page",
"is",
"shown",
"play",
"the",
"video"
]
| 101c4f6f791e33c3185e4ba2e380177447bee125 | https://github.com/johnsonjo4531/videojs-gifplayer/blob/101c4f6f791e33c3185e4ba2e380177447bee125/src/plugin.js#L98-L112 |
44,239 | bodil/pink | lib/mousetrap.js | _getKeyInfo | function _getKeyInfo(combination, action) {
var keys,
key,
i,
modifiers = [];
// take the keys from this pattern and figure out what the actual
// pattern is all about
keys = _keysFromString(combination);
for (i = 0; i < keys.length; ++i) {
key = keys[i];
// normalize key names
if (_SPECIAL_ALIASES[key]) {
key = _SPECIAL_ALIASES[key];
}
// if this is not a keypress event then we should
// be smart about using shift keys
// this will only work for US keyboards however
if (action && action != 'keypress' && _SHIFT_MAP[key]) {
key = _SHIFT_MAP[key];
modifiers.push('shift');
}
// if this key is a modifier then add it to the list of modifiers
if (_isModifier(key)) {
modifiers.push(key);
}
}
// depending on what the key combination is
// we will try to pick the best event for it
action = _pickBestAction(key, modifiers, action);
return {
key: key,
modifiers: modifiers,
action: action
};
} | javascript | function _getKeyInfo(combination, action) {
var keys,
key,
i,
modifiers = [];
// take the keys from this pattern and figure out what the actual
// pattern is all about
keys = _keysFromString(combination);
for (i = 0; i < keys.length; ++i) {
key = keys[i];
// normalize key names
if (_SPECIAL_ALIASES[key]) {
key = _SPECIAL_ALIASES[key];
}
// if this is not a keypress event then we should
// be smart about using shift keys
// this will only work for US keyboards however
if (action && action != 'keypress' && _SHIFT_MAP[key]) {
key = _SHIFT_MAP[key];
modifiers.push('shift');
}
// if this key is a modifier then add it to the list of modifiers
if (_isModifier(key)) {
modifiers.push(key);
}
}
// depending on what the key combination is
// we will try to pick the best event for it
action = _pickBestAction(key, modifiers, action);
return {
key: key,
modifiers: modifiers,
action: action
};
} | [
"function",
"_getKeyInfo",
"(",
"combination",
",",
"action",
")",
"{",
"var",
"keys",
",",
"key",
",",
"i",
",",
"modifiers",
"=",
"[",
"]",
";",
"// take the keys from this pattern and figure out what the actual",
"// pattern is all about",
"keys",
"=",
"_keysFromString",
"(",
"combination",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"keys",
".",
"length",
";",
"++",
"i",
")",
"{",
"key",
"=",
"keys",
"[",
"i",
"]",
";",
"// normalize key names",
"if",
"(",
"_SPECIAL_ALIASES",
"[",
"key",
"]",
")",
"{",
"key",
"=",
"_SPECIAL_ALIASES",
"[",
"key",
"]",
";",
"}",
"// if this is not a keypress event then we should",
"// be smart about using shift keys",
"// this will only work for US keyboards however",
"if",
"(",
"action",
"&&",
"action",
"!=",
"'keypress'",
"&&",
"_SHIFT_MAP",
"[",
"key",
"]",
")",
"{",
"key",
"=",
"_SHIFT_MAP",
"[",
"key",
"]",
";",
"modifiers",
".",
"push",
"(",
"'shift'",
")",
";",
"}",
"// if this key is a modifier then add it to the list of modifiers",
"if",
"(",
"_isModifier",
"(",
"key",
")",
")",
"{",
"modifiers",
".",
"push",
"(",
"key",
")",
";",
"}",
"}",
"// depending on what the key combination is",
"// we will try to pick the best event for it",
"action",
"=",
"_pickBestAction",
"(",
"key",
",",
"modifiers",
",",
"action",
")",
";",
"return",
"{",
"key",
":",
"key",
",",
"modifiers",
":",
"modifiers",
",",
"action",
":",
"action",
"}",
";",
"}"
]
| Gets info for a specific key combination
@param {string} combination key combination ("command+s" or "a" or "*")
@param {string=} action
@returns {Object} | [
"Gets",
"info",
"for",
"a",
"specific",
"key",
"combination"
]
| 1c0496e03e39b2bbc0330eb514f5f15ff965a073 | https://github.com/bodil/pink/blob/1c0496e03e39b2bbc0330eb514f5f15ff965a073/lib/mousetrap.js#L735-L776 |
44,240 | bodil/pink | lib/mousetrap.js | function(keys, callback, action) {
keys = keys instanceof Array ? keys : [keys];
_bindMultiple(keys, callback, action);
return this;
} | javascript | function(keys, callback, action) {
keys = keys instanceof Array ? keys : [keys];
_bindMultiple(keys, callback, action);
return this;
} | [
"function",
"(",
"keys",
",",
"callback",
",",
"action",
")",
"{",
"keys",
"=",
"keys",
"instanceof",
"Array",
"?",
"keys",
":",
"[",
"keys",
"]",
";",
"_bindMultiple",
"(",
"keys",
",",
"callback",
",",
"action",
")",
";",
"return",
"this",
";",
"}"
]
| binds an event to mousetrap
can be a single key, a combination of keys separated with +,
an array of keys, or a sequence of keys separated by spaces
be sure to list the modifier keys first to make sure that the
correct key ends up getting bound (the last key in the pattern)
@param {string|Array} keys
@param {Function} callback
@param {string=} action - 'keypress', 'keydown', or 'keyup'
@returns void | [
"binds",
"an",
"event",
"to",
"mousetrap"
]
| 1c0496e03e39b2bbc0330eb514f5f15ff965a073 | https://github.com/bodil/pink/blob/1c0496e03e39b2bbc0330eb514f5f15ff965a073/lib/mousetrap.js#L866-L870 |
|
44,241 | bodil/pink | lib/mousetrap.js | function(e, element) {
// if the element has the class "mousetrap" then no need to stop
if ((' ' + element.className + ' ').indexOf(' mousetrap ') > -1) {
return false;
}
// stop for input, select, and textarea
return element.tagName == 'INPUT' || element.tagName == 'SELECT' || element.tagName == 'TEXTAREA' || element.isContentEditable;
} | javascript | function(e, element) {
// if the element has the class "mousetrap" then no need to stop
if ((' ' + element.className + ' ').indexOf(' mousetrap ') > -1) {
return false;
}
// stop for input, select, and textarea
return element.tagName == 'INPUT' || element.tagName == 'SELECT' || element.tagName == 'TEXTAREA' || element.isContentEditable;
} | [
"function",
"(",
"e",
",",
"element",
")",
"{",
"// if the element has the class \"mousetrap\" then no need to stop",
"if",
"(",
"(",
"' '",
"+",
"element",
".",
"className",
"+",
"' '",
")",
".",
"indexOf",
"(",
"' mousetrap '",
")",
">",
"-",
"1",
")",
"{",
"return",
"false",
";",
"}",
"// stop for input, select, and textarea",
"return",
"element",
".",
"tagName",
"==",
"'INPUT'",
"||",
"element",
".",
"tagName",
"==",
"'SELECT'",
"||",
"element",
".",
"tagName",
"==",
"'TEXTAREA'",
"||",
"element",
".",
"isContentEditable",
";",
"}"
]
| should we stop this event before firing off callbacks
@param {Event} e
@param {Element} element
@return {boolean} | [
"should",
"we",
"stop",
"this",
"event",
"before",
"firing",
"off",
"callbacks"
]
| 1c0496e03e39b2bbc0330eb514f5f15ff965a073 | https://github.com/bodil/pink/blob/1c0496e03e39b2bbc0330eb514f5f15ff965a073/lib/mousetrap.js#L927-L936 |
|
44,242 | filefog/filefog | lib/wrapper/provider_wrapper.js | function (name, transform, config, filefog_options){
this.name = name;
this.config = config || {};
this._transform = transform;
this.filefog_options = extend(true, {transform:true, include_raw:true, auto_paginate:true,root_identifier:null}, filefog_options || {});
base_provider.call(this, name);
} | javascript | function (name, transform, config, filefog_options){
this.name = name;
this.config = config || {};
this._transform = transform;
this.filefog_options = extend(true, {transform:true, include_raw:true, auto_paginate:true,root_identifier:null}, filefog_options || {});
base_provider.call(this, name);
} | [
"function",
"(",
"name",
",",
"transform",
",",
"config",
",",
"filefog_options",
")",
"{",
"this",
".",
"name",
"=",
"name",
";",
"this",
".",
"config",
"=",
"config",
"||",
"{",
"}",
";",
"this",
".",
"_transform",
"=",
"transform",
";",
"this",
".",
"filefog_options",
"=",
"extend",
"(",
"true",
",",
"{",
"transform",
":",
"true",
",",
"include_raw",
":",
"true",
",",
"auto_paginate",
":",
"true",
",",
"root_identifier",
":",
"null",
"}",
",",
"filefog_options",
"||",
"{",
"}",
")",
";",
"base_provider",
".",
"call",
"(",
"this",
",",
"name",
")",
";",
"}"
]
| Wraps the provided base Provider constructor and provides instance variables.
@constructor ProviderWrapper
@method ProviderWrapper
@param {String} name - the name the provider is registered with (using the use method)
@param {Transform} transform - the provider specified transforms for all the client methods.
@param {Object} config
@param {} filefog_options
@return | [
"Wraps",
"the",
"provided",
"base",
"Provider",
"constructor",
"and",
"provides",
"instance",
"variables",
"."
]
| 16040ef431e0af8aeee08b445c046a6805242cf3 | https://github.com/filefog/filefog/blob/16040ef431e0af8aeee08b445c046a6805242cf3/lib/wrapper/provider_wrapper.js#L27-L33 |
|
44,243 | bodil/pink | lib/events.js | on | function on(emitter, eventName, handler, context) {
handler = context ? handler.bind(context) : handler;
emitter.addEventListener(eventName, handler);
return handler;
} | javascript | function on(emitter, eventName, handler, context) {
handler = context ? handler.bind(context) : handler;
emitter.addEventListener(eventName, handler);
return handler;
} | [
"function",
"on",
"(",
"emitter",
",",
"eventName",
",",
"handler",
",",
"context",
")",
"{",
"handler",
"=",
"context",
"?",
"handler",
".",
"bind",
"(",
"context",
")",
":",
"handler",
";",
"emitter",
".",
"addEventListener",
"(",
"eventName",
",",
"handler",
")",
";",
"return",
"handler",
";",
"}"
]
| Register to receive events. | [
"Register",
"to",
"receive",
"events",
"."
]
| 1c0496e03e39b2bbc0330eb514f5f15ff965a073 | https://github.com/bodil/pink/blob/1c0496e03e39b2bbc0330eb514f5f15ff965a073/lib/events.js#L33-L37 |
44,244 | bodil/pink | lib/events.js | once | function once(emitter, eventName, handler, context) {
handler = context ? handler.bind(context) : handler;
let wrapper = function onceHandler(event) {
emitter.removeEventListener(eventName, onceHandler);
handler(event);
};
emitter.addEventListener(eventName, wrapper);
return wrapper;
} | javascript | function once(emitter, eventName, handler, context) {
handler = context ? handler.bind(context) : handler;
let wrapper = function onceHandler(event) {
emitter.removeEventListener(eventName, onceHandler);
handler(event);
};
emitter.addEventListener(eventName, wrapper);
return wrapper;
} | [
"function",
"once",
"(",
"emitter",
",",
"eventName",
",",
"handler",
",",
"context",
")",
"{",
"handler",
"=",
"context",
"?",
"handler",
".",
"bind",
"(",
"context",
")",
":",
"handler",
";",
"let",
"wrapper",
"=",
"function",
"onceHandler",
"(",
"event",
")",
"{",
"emitter",
".",
"removeEventListener",
"(",
"eventName",
",",
"onceHandler",
")",
";",
"handler",
"(",
"event",
")",
";",
"}",
";",
"emitter",
".",
"addEventListener",
"(",
"eventName",
",",
"wrapper",
")",
";",
"return",
"wrapper",
";",
"}"
]
| Register to receive one single event. | [
"Register",
"to",
"receive",
"one",
"single",
"event",
"."
]
| 1c0496e03e39b2bbc0330eb514f5f15ff965a073 | https://github.com/bodil/pink/blob/1c0496e03e39b2bbc0330eb514f5f15ff965a073/lib/events.js#L40-L48 |
44,245 | bodil/pink | lib/events.js | until | function until(emitter, eventName, handler, context) {
handler = context ? handler.bind(context) : handler;
let wrapper = function untilHandler(event) {
if (handler(event))
emitter.removeEventListener(eventName, untilHandler);
};
emitter.addEventListener(eventName, wrapper);
return wrapper;
} | javascript | function until(emitter, eventName, handler, context) {
handler = context ? handler.bind(context) : handler;
let wrapper = function untilHandler(event) {
if (handler(event))
emitter.removeEventListener(eventName, untilHandler);
};
emitter.addEventListener(eventName, wrapper);
return wrapper;
} | [
"function",
"until",
"(",
"emitter",
",",
"eventName",
",",
"handler",
",",
"context",
")",
"{",
"handler",
"=",
"context",
"?",
"handler",
".",
"bind",
"(",
"context",
")",
":",
"handler",
";",
"let",
"wrapper",
"=",
"function",
"untilHandler",
"(",
"event",
")",
"{",
"if",
"(",
"handler",
"(",
"event",
")",
")",
"emitter",
".",
"removeEventListener",
"(",
"eventName",
",",
"untilHandler",
")",
";",
"}",
";",
"emitter",
".",
"addEventListener",
"(",
"eventName",
",",
"wrapper",
")",
";",
"return",
"wrapper",
";",
"}"
]
| Register to receive events until the handler function returns true. | [
"Register",
"to",
"receive",
"events",
"until",
"the",
"handler",
"function",
"returns",
"true",
"."
]
| 1c0496e03e39b2bbc0330eb514f5f15ff965a073 | https://github.com/bodil/pink/blob/1c0496e03e39b2bbc0330eb514f5f15ff965a073/lib/events.js#L51-L59 |
44,246 | ololoepepe/vk-openapi | index.js | function(cb, settings) {
if (!VK._apiId) {
return false;
}
var url = VK._domain.main + VK._path.login + '?client_id='+VK._apiId+'&display=popup&redirect_uri=close.html&response_type=token';
if (settings && parseInt(settings, 10) > 0) {
url += '&scope=' + settings;
}
VK.Observer.unsubscribe('auth.onLogin');
VK.Observer.subscribe('auth.onLogin', cb);
VK.UI.popup({
width: 665,
height: 370,
url: url
});
var authCallback = function() {
VK.Auth.getLoginStatus(function(resp) {
VK.Observer.publish('auth.onLogin', resp);
VK.Observer.unsubscribe('auth.onLogin');
}, true);
}
VK.UI.popupOpened = true;
var popupCheck = function() {
if (!VK.UI.popupOpened) {
return false;
}
try {
if (!VK.UI.active.top || VK.UI.active.closed) {
VK.UI.popupOpened = false;
authCallback();
return true;
}
} catch(e) {
VK.UI.popupOpened = false;
authCallback();
return true;
}
setTimeout(popupCheck, 100);
};
setTimeout(popupCheck, 100);
} | javascript | function(cb, settings) {
if (!VK._apiId) {
return false;
}
var url = VK._domain.main + VK._path.login + '?client_id='+VK._apiId+'&display=popup&redirect_uri=close.html&response_type=token';
if (settings && parseInt(settings, 10) > 0) {
url += '&scope=' + settings;
}
VK.Observer.unsubscribe('auth.onLogin');
VK.Observer.subscribe('auth.onLogin', cb);
VK.UI.popup({
width: 665,
height: 370,
url: url
});
var authCallback = function() {
VK.Auth.getLoginStatus(function(resp) {
VK.Observer.publish('auth.onLogin', resp);
VK.Observer.unsubscribe('auth.onLogin');
}, true);
}
VK.UI.popupOpened = true;
var popupCheck = function() {
if (!VK.UI.popupOpened) {
return false;
}
try {
if (!VK.UI.active.top || VK.UI.active.closed) {
VK.UI.popupOpened = false;
authCallback();
return true;
}
} catch(e) {
VK.UI.popupOpened = false;
authCallback();
return true;
}
setTimeout(popupCheck, 100);
};
setTimeout(popupCheck, 100);
} | [
"function",
"(",
"cb",
",",
"settings",
")",
"{",
"if",
"(",
"!",
"VK",
".",
"_apiId",
")",
"{",
"return",
"false",
";",
"}",
"var",
"url",
"=",
"VK",
".",
"_domain",
".",
"main",
"+",
"VK",
".",
"_path",
".",
"login",
"+",
"'?client_id='",
"+",
"VK",
".",
"_apiId",
"+",
"'&display=popup&redirect_uri=close.html&response_type=token'",
";",
"if",
"(",
"settings",
"&&",
"parseInt",
"(",
"settings",
",",
"10",
")",
">",
"0",
")",
"{",
"url",
"+=",
"'&scope='",
"+",
"settings",
";",
"}",
"VK",
".",
"Observer",
".",
"unsubscribe",
"(",
"'auth.onLogin'",
")",
";",
"VK",
".",
"Observer",
".",
"subscribe",
"(",
"'auth.onLogin'",
",",
"cb",
")",
";",
"VK",
".",
"UI",
".",
"popup",
"(",
"{",
"width",
":",
"665",
",",
"height",
":",
"370",
",",
"url",
":",
"url",
"}",
")",
";",
"var",
"authCallback",
"=",
"function",
"(",
")",
"{",
"VK",
".",
"Auth",
".",
"getLoginStatus",
"(",
"function",
"(",
"resp",
")",
"{",
"VK",
".",
"Observer",
".",
"publish",
"(",
"'auth.onLogin'",
",",
"resp",
")",
";",
"VK",
".",
"Observer",
".",
"unsubscribe",
"(",
"'auth.onLogin'",
")",
";",
"}",
",",
"true",
")",
";",
"}",
"VK",
".",
"UI",
".",
"popupOpened",
"=",
"true",
";",
"var",
"popupCheck",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"!",
"VK",
".",
"UI",
".",
"popupOpened",
")",
"{",
"return",
"false",
";",
"}",
"try",
"{",
"if",
"(",
"!",
"VK",
".",
"UI",
".",
"active",
".",
"top",
"||",
"VK",
".",
"UI",
".",
"active",
".",
"closed",
")",
"{",
"VK",
".",
"UI",
".",
"popupOpened",
"=",
"false",
";",
"authCallback",
"(",
")",
";",
"return",
"true",
";",
"}",
"}",
"catch",
"(",
"e",
")",
"{",
"VK",
".",
"UI",
".",
"popupOpened",
"=",
"false",
";",
"authCallback",
"(",
")",
";",
"return",
"true",
";",
"}",
"setTimeout",
"(",
"popupCheck",
",",
"100",
")",
";",
"}",
";",
"setTimeout",
"(",
"popupCheck",
",",
"100",
")",
";",
"}"
]
| Public VK.Auth methods | [
"Public",
"VK",
".",
"Auth",
"methods"
]
| 0e2213f78b3e03c27ea908ed6041e268572211db | https://github.com/ololoepepe/vk-openapi/blob/0e2213f78b3e03c27ea908ed6041e268572211db/index.js#L416-L463 |
|
44,247 | kevinconway/Defer.js | defer/defer.js | postMessage | function postMessage(ctx) {
var queue = [],
message = "nextTick";
function handle(event) {
if (event.source === ctx && event.data === message) {
if (!!event.stopPropogation) {
event.stopPropogation();
}
if (queue.length > 0) {
queue.shift()();
}
}
}
if (!!ctx.addEventListener) {
ctx.addEventListener("message", handle, true);
} else {
ctx.attachEvent("onmessage", handle);
}
return function defer(fn) {
queue.push(fn);
ctx.postMessage(message, '*');
};
} | javascript | function postMessage(ctx) {
var queue = [],
message = "nextTick";
function handle(event) {
if (event.source === ctx && event.data === message) {
if (!!event.stopPropogation) {
event.stopPropogation();
}
if (queue.length > 0) {
queue.shift()();
}
}
}
if (!!ctx.addEventListener) {
ctx.addEventListener("message", handle, true);
} else {
ctx.attachEvent("onmessage", handle);
}
return function defer(fn) {
queue.push(fn);
ctx.postMessage(message, '*');
};
} | [
"function",
"postMessage",
"(",
"ctx",
")",
"{",
"var",
"queue",
"=",
"[",
"]",
",",
"message",
"=",
"\"nextTick\"",
";",
"function",
"handle",
"(",
"event",
")",
"{",
"if",
"(",
"event",
".",
"source",
"===",
"ctx",
"&&",
"event",
".",
"data",
"===",
"message",
")",
"{",
"if",
"(",
"!",
"!",
"event",
".",
"stopPropogation",
")",
"{",
"event",
".",
"stopPropogation",
"(",
")",
";",
"}",
"if",
"(",
"queue",
".",
"length",
">",
"0",
")",
"{",
"queue",
".",
"shift",
"(",
")",
"(",
")",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"!",
"ctx",
".",
"addEventListener",
")",
"{",
"ctx",
".",
"addEventListener",
"(",
"\"message\"",
",",
"handle",
",",
"true",
")",
";",
"}",
"else",
"{",
"ctx",
".",
"attachEvent",
"(",
"\"onmessage\"",
",",
"handle",
")",
";",
"}",
"return",
"function",
"defer",
"(",
"fn",
")",
"{",
"queue",
".",
"push",
"(",
"fn",
")",
";",
"ctx",
".",
"postMessage",
"(",
"message",
",",
"'*'",
")",
";",
"}",
";",
"}"
]
| window.postMessage is refered to quite a bit in articles discussing a potential setZeroTimeout for browsers. The problem it attempts to solve is that setTimeout has a minimum wait time in all browsers. This means your function is not scheduled to run on the next cycle of the event loop but, rather, at the next cycle of the event loop after the timeout has passed. Instead, this method uses a message passing features that has been integrated into modern browsers to replicate the functionality of process.nextTick. | [
"window",
".",
"postMessage",
"is",
"refered",
"to",
"quite",
"a",
"bit",
"in",
"articles",
"discussing",
"a",
"potential",
"setZeroTimeout",
"for",
"browsers",
".",
"The",
"problem",
"it",
"attempts",
"to",
"solve",
"is",
"that",
"setTimeout",
"has",
"a",
"minimum",
"wait",
"time",
"in",
"all",
"browsers",
".",
"This",
"means",
"your",
"function",
"is",
"not",
"scheduled",
"to",
"run",
"on",
"the",
"next",
"cycle",
"of",
"the",
"event",
"loop",
"but",
"rather",
"at",
"the",
"next",
"cycle",
"of",
"the",
"event",
"loop",
"after",
"the",
"timeout",
"has",
"passed",
".",
"Instead",
"this",
"method",
"uses",
"a",
"message",
"passing",
"features",
"that",
"has",
"been",
"integrated",
"into",
"modern",
"browsers",
"to",
"replicate",
"the",
"functionality",
"of",
"process",
".",
"nextTick",
"."
]
| f8925ff6536d16eb4388487845ed603aa85d4cb4 | https://github.com/kevinconway/Defer.js/blob/f8925ff6536d16eb4388487845ed603aa85d4cb4/defer/defer.js#L58-L98 |
44,248 | mylisabox/lisa-ui | src/scripts/primus.js | send | function send(ev, data, fn) {
/* jshint validthis: true */
// ignore newListener event to avoid this error in node 0.8
// https://github.com/cayasso/primus-emitter/issues/3
if (/^(newListener|removeListener)/.test(ev)) return this;
this.emitter.send.apply(this.emitter, arguments);
return this;
} | javascript | function send(ev, data, fn) {
/* jshint validthis: true */
// ignore newListener event to avoid this error in node 0.8
// https://github.com/cayasso/primus-emitter/issues/3
if (/^(newListener|removeListener)/.test(ev)) return this;
this.emitter.send.apply(this.emitter, arguments);
return this;
} | [
"function",
"send",
"(",
"ev",
",",
"data",
",",
"fn",
")",
"{",
"/* jshint validthis: true */",
"// ignore newListener event to avoid this error in node 0.8",
"// https://github.com/cayasso/primus-emitter/issues/3",
"if",
"(",
"/",
"^(newListener|removeListener)",
"/",
".",
"test",
"(",
"ev",
")",
")",
"return",
"this",
";",
"this",
".",
"emitter",
".",
"send",
".",
"apply",
"(",
"this",
".",
"emitter",
",",
"arguments",
")",
";",
"return",
"this",
";",
"}"
]
| Emits to this Spark.
@param {String} ev The event
@param {Mixed} [data] The data to broadcast
@param {Function} [fn] The callback function
@return {Primus|Spark} this
@api public | [
"Emits",
"to",
"this",
"Spark",
"."
]
| 1fa0ef0ff894882d1f982210a796d37d7aeb36e3 | https://github.com/mylisabox/lisa-ui/blob/1fa0ef0ff894882d1f982210a796d37d7aeb36e3/src/scripts/primus.js#L3352-L3359 |
44,249 | mylisabox/lisa-ui | src/scripts/primus.js | Emitter | function Emitter(conn) {
if (!(this instanceof Emitter)) return new Emitter(conn);
this.ids = 1;
this.acks = {};
this.conn = conn;
if (this.conn) this.bind();
} | javascript | function Emitter(conn) {
if (!(this instanceof Emitter)) return new Emitter(conn);
this.ids = 1;
this.acks = {};
this.conn = conn;
if (this.conn) this.bind();
} | [
"function",
"Emitter",
"(",
"conn",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Emitter",
")",
")",
"return",
"new",
"Emitter",
"(",
"conn",
")",
";",
"this",
".",
"ids",
"=",
"1",
";",
"this",
".",
"acks",
"=",
"{",
"}",
";",
"this",
".",
"conn",
"=",
"conn",
";",
"if",
"(",
"this",
".",
"conn",
")",
"this",
".",
"bind",
"(",
")",
";",
"}"
]
| Initialize a new `Emitter`.
@param {Primus|Spark} conn
@return {Emitter} `Emitter` instance
@api public | [
"Initialize",
"a",
"new",
"Emitter",
"."
]
| 1fa0ef0ff894882d1f982210a796d37d7aeb36e3 | https://github.com/mylisabox/lisa-ui/blob/1fa0ef0ff894882d1f982210a796d37d7aeb36e3/src/scripts/primus.js#L3395-L3401 |
44,250 | Lanfei/webpack-isomorphic | example/ssr.js | renderToString | function renderToString(reactClass, data) {
let classPath = path.join(viewsDir, reactClass);
let element = React.createElement(require(classPath).default, data);
return ReactDOMServer.renderToString(element);
} | javascript | function renderToString(reactClass, data) {
let classPath = path.join(viewsDir, reactClass);
let element = React.createElement(require(classPath).default, data);
return ReactDOMServer.renderToString(element);
} | [
"function",
"renderToString",
"(",
"reactClass",
",",
"data",
")",
"{",
"let",
"classPath",
"=",
"path",
".",
"join",
"(",
"viewsDir",
",",
"reactClass",
")",
";",
"let",
"element",
"=",
"React",
".",
"createElement",
"(",
"require",
"(",
"classPath",
")",
".",
"default",
",",
"data",
")",
";",
"return",
"ReactDOMServer",
".",
"renderToString",
"(",
"element",
")",
";",
"}"
]
| Render a react class to string | [
"Render",
"a",
"react",
"class",
"to",
"string"
]
| 6e808f58681a3c103a81c493fdb38a702ad7daad | https://github.com/Lanfei/webpack-isomorphic/blob/6e808f58681a3c103a81c493fdb38a702ad7daad/example/ssr.js#L13-L17 |
44,251 | tanhauhau/generator-badge | lib/cmd/installed.js | installed | function installed(){
findUp('README.*')
.then(function(filepath){
if(filepath === null){
return process.cwd();
}else{
return path.resolve(filepath[0], '../');
}
})
.then(function(parent){
return config.readLocal(parent);
})
.then(data => {
if(data.installed.length === 0){
console.log(chalk.bold('No badges installed.'));
}else{
// console.log(chalk.bold.underline(`Installed(${data.installed.length}):`));
_.each(data.installed, i => { console.log(i) });
console.log(chalk.bgBlue.bold(`Total: ${data.installed.length} `))
}
});
} | javascript | function installed(){
findUp('README.*')
.then(function(filepath){
if(filepath === null){
return process.cwd();
}else{
return path.resolve(filepath[0], '../');
}
})
.then(function(parent){
return config.readLocal(parent);
})
.then(data => {
if(data.installed.length === 0){
console.log(chalk.bold('No badges installed.'));
}else{
// console.log(chalk.bold.underline(`Installed(${data.installed.length}):`));
_.each(data.installed, i => { console.log(i) });
console.log(chalk.bgBlue.bold(`Total: ${data.installed.length} `))
}
});
} | [
"function",
"installed",
"(",
")",
"{",
"findUp",
"(",
"'README.*'",
")",
".",
"then",
"(",
"function",
"(",
"filepath",
")",
"{",
"if",
"(",
"filepath",
"===",
"null",
")",
"{",
"return",
"process",
".",
"cwd",
"(",
")",
";",
"}",
"else",
"{",
"return",
"path",
".",
"resolve",
"(",
"filepath",
"[",
"0",
"]",
",",
"'../'",
")",
";",
"}",
"}",
")",
".",
"then",
"(",
"function",
"(",
"parent",
")",
"{",
"return",
"config",
".",
"readLocal",
"(",
"parent",
")",
";",
"}",
")",
".",
"then",
"(",
"data",
"=>",
"{",
"if",
"(",
"data",
".",
"installed",
".",
"length",
"===",
"0",
")",
"{",
"console",
".",
"log",
"(",
"chalk",
".",
"bold",
"(",
"'No badges installed.'",
")",
")",
";",
"}",
"else",
"{",
"// console.log(chalk.bold.underline(`Installed(${data.installed.length}):`));",
"_",
".",
"each",
"(",
"data",
".",
"installed",
",",
"i",
"=>",
"{",
"console",
".",
"log",
"(",
"i",
")",
"}",
")",
";",
"console",
".",
"log",
"(",
"chalk",
".",
"bgBlue",
".",
"bold",
"(",
"`",
"${",
"data",
".",
"installed",
".",
"length",
"}",
"`",
")",
")",
"}",
"}",
")",
";",
"}"
]
| List installed badges, based on .badge.json | [
"List",
"installed",
"badges",
"based",
"on",
".",
"badge",
".",
"json"
]
| 32279bdf1eeab39fef86d8ece9f2b6b07e2b6baf | https://github.com/tanhauhau/generator-badge/blob/32279bdf1eeab39fef86d8ece9f2b6b07e2b6baf/lib/cmd/installed.js#L9-L30 |
44,252 | filefog/filefog | lib/wrapper/client_wrapper.js | function(name,transform, provider_config, credentials, filefog_options){
this.name = name;
this.config = provider_config || {};
this.credentials = credentials || {};
this.filefog_options = extend(true, {transform:true, include_raw:true, auto_paginate:true,root_identifier:null}, filefog_options || {});
this._transform = transform;
base_client.call(this);
} | javascript | function(name,transform, provider_config, credentials, filefog_options){
this.name = name;
this.config = provider_config || {};
this.credentials = credentials || {};
this.filefog_options = extend(true, {transform:true, include_raw:true, auto_paginate:true,root_identifier:null}, filefog_options || {});
this._transform = transform;
base_client.call(this);
} | [
"function",
"(",
"name",
",",
"transform",
",",
"provider_config",
",",
"credentials",
",",
"filefog_options",
")",
"{",
"this",
".",
"name",
"=",
"name",
";",
"this",
".",
"config",
"=",
"provider_config",
"||",
"{",
"}",
";",
"this",
".",
"credentials",
"=",
"credentials",
"||",
"{",
"}",
";",
"this",
".",
"filefog_options",
"=",
"extend",
"(",
"true",
",",
"{",
"transform",
":",
"true",
",",
"include_raw",
":",
"true",
",",
"auto_paginate",
":",
"true",
",",
"root_identifier",
":",
"null",
"}",
",",
"filefog_options",
"||",
"{",
"}",
")",
";",
"this",
".",
"_transform",
"=",
"transform",
";",
"base_client",
".",
"call",
"(",
"this",
")",
";",
"}"
]
| Wraps the provided base Client constructor and provides instance variables to be used by provider Clients.
@constructor ClientWrapper
@method ClientWrapper
@param {String} name - the name that the provider is registered with.
@param {Transform} transform - the provider specified transforms for all the client methods.
@param {Object} provider_config - the configuration for this client (OAuth client keys, etc)
@param {Object} credentials - the user specific credentials for the Client (access token, refresh token, etc)
@param {} filefog_options
@return | [
"Wraps",
"the",
"provided",
"base",
"Client",
"constructor",
"and",
"provides",
"instance",
"variables",
"to",
"be",
"used",
"by",
"provider",
"Clients",
"."
]
| 16040ef431e0af8aeee08b445c046a6805242cf3 | https://github.com/filefog/filefog/blob/16040ef431e0af8aeee08b445c046a6805242cf3/lib/wrapper/client_wrapper.js#L30-L38 |
|
44,253 | scripting/reader | davereader.js | convertOutline | function convertOutline (jstruct) { //7/16/14 by DW
var theNewOutline = {}, atts, subs;
if (jstruct ["source:outline"] != undefined) {
if (jstruct ["@"] != undefined) {
atts = jstruct ["@"];
subs = jstruct ["source:outline"];
}
else {
atts = jstruct ["source:outline"] ["@"];
subs = jstruct ["source:outline"] ["source:outline"];
}
}
else {
atts = jstruct ["@"];
subs = undefined;
}
for (var x in atts) {
theNewOutline [x] = atts [x];
}
if (subs != undefined) {
theNewOutline.subs = [];
if (subs instanceof Array) {
for (var i = 0; i < subs.length; i++) {
theNewOutline.subs [i] = convertOutline (subs [i]);
}
}
else {
theNewOutline.subs = [];
theNewOutline.subs [0] = {};
for (var x in subs ["@"]) {
theNewOutline.subs [0] [x] = subs ["@"] [x];
}
}
}
return (theNewOutline);
} | javascript | function convertOutline (jstruct) { //7/16/14 by DW
var theNewOutline = {}, atts, subs;
if (jstruct ["source:outline"] != undefined) {
if (jstruct ["@"] != undefined) {
atts = jstruct ["@"];
subs = jstruct ["source:outline"];
}
else {
atts = jstruct ["source:outline"] ["@"];
subs = jstruct ["source:outline"] ["source:outline"];
}
}
else {
atts = jstruct ["@"];
subs = undefined;
}
for (var x in atts) {
theNewOutline [x] = atts [x];
}
if (subs != undefined) {
theNewOutline.subs = [];
if (subs instanceof Array) {
for (var i = 0; i < subs.length; i++) {
theNewOutline.subs [i] = convertOutline (subs [i]);
}
}
else {
theNewOutline.subs = [];
theNewOutline.subs [0] = {};
for (var x in subs ["@"]) {
theNewOutline.subs [0] [x] = subs ["@"] [x];
}
}
}
return (theNewOutline);
} | [
"function",
"convertOutline",
"(",
"jstruct",
")",
"{",
"//7/16/14 by DW",
"var",
"theNewOutline",
"=",
"{",
"}",
",",
"atts",
",",
"subs",
";",
"if",
"(",
"jstruct",
"[",
"\"source:outline\"",
"]",
"!=",
"undefined",
")",
"{",
"if",
"(",
"jstruct",
"[",
"\"@\"",
"]",
"!=",
"undefined",
")",
"{",
"atts",
"=",
"jstruct",
"[",
"\"@\"",
"]",
";",
"subs",
"=",
"jstruct",
"[",
"\"source:outline\"",
"]",
";",
"}",
"else",
"{",
"atts",
"=",
"jstruct",
"[",
"\"source:outline\"",
"]",
"[",
"\"@\"",
"]",
";",
"subs",
"=",
"jstruct",
"[",
"\"source:outline\"",
"]",
"[",
"\"source:outline\"",
"]",
";",
"}",
"}",
"else",
"{",
"atts",
"=",
"jstruct",
"[",
"\"@\"",
"]",
";",
"subs",
"=",
"undefined",
";",
"}",
"for",
"(",
"var",
"x",
"in",
"atts",
")",
"{",
"theNewOutline",
"[",
"x",
"]",
"=",
"atts",
"[",
"x",
"]",
";",
"}",
"if",
"(",
"subs",
"!=",
"undefined",
")",
"{",
"theNewOutline",
".",
"subs",
"=",
"[",
"]",
";",
"if",
"(",
"subs",
"instanceof",
"Array",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"subs",
".",
"length",
";",
"i",
"++",
")",
"{",
"theNewOutline",
".",
"subs",
"[",
"i",
"]",
"=",
"convertOutline",
"(",
"subs",
"[",
"i",
"]",
")",
";",
"}",
"}",
"else",
"{",
"theNewOutline",
".",
"subs",
"=",
"[",
"]",
";",
"theNewOutline",
".",
"subs",
"[",
"0",
"]",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"x",
"in",
"subs",
"[",
"\"@\"",
"]",
")",
"{",
"theNewOutline",
".",
"subs",
"[",
"0",
"]",
"[",
"x",
"]",
"=",
"subs",
"[",
"\"@\"",
"]",
"[",
"x",
"]",
";",
"}",
"}",
"}",
"return",
"(",
"theNewOutline",
")",
";",
"}"
]
| copy selected elements from the object from feedparser, into the item for the river | [
"copy",
"selected",
"elements",
"from",
"the",
"object",
"from",
"feedparser",
"into",
"the",
"item",
"for",
"the",
"river"
]
| 40050c7ecffe0512e73c5915436358fd3f3f1032 | https://github.com/scripting/reader/blob/40050c7ecffe0512e73c5915436358fd3f3f1032/davereader.js#L1608-L1643 |
44,254 | carloscuesta/react-native-layout-debug | index.js | getDebugger | function getDebugger() {
const isCustom = arguments.length === 1;
const layoutDebug = isCustom ? new Debugger(arguments[0]) : defaultDebugger;
return isCustom ? debuggerDecorator.bind(layoutDebug) : debuggerDecorator.call(layoutDebug, ...arguments);
} | javascript | function getDebugger() {
const isCustom = arguments.length === 1;
const layoutDebug = isCustom ? new Debugger(arguments[0]) : defaultDebugger;
return isCustom ? debuggerDecorator.bind(layoutDebug) : debuggerDecorator.call(layoutDebug, ...arguments);
} | [
"function",
"getDebugger",
"(",
")",
"{",
"const",
"isCustom",
"=",
"arguments",
".",
"length",
"===",
"1",
";",
"const",
"layoutDebug",
"=",
"isCustom",
"?",
"new",
"Debugger",
"(",
"arguments",
"[",
"0",
"]",
")",
":",
"defaultDebugger",
";",
"return",
"isCustom",
"?",
"debuggerDecorator",
".",
"bind",
"(",
"layoutDebug",
")",
":",
"debuggerDecorator",
".",
"call",
"(",
"layoutDebug",
",",
"...",
"arguments",
")",
";",
"}"
]
| Wrapper for debugger decorator to allow custom params
@return {Function} | [
"Wrapper",
"for",
"debugger",
"decorator",
"to",
"allow",
"custom",
"params"
]
| 77fb74185d4d6cf99f494e6196d3b8101d608e4c | https://github.com/carloscuesta/react-native-layout-debug/blob/77fb74185d4d6cf99f494e6196d3b8101d608e4c/index.js#L32-L36 |
44,255 | audiojs/web-audio-write | index.js | consume | function consume (len) {
count -= len
if (count < 0) {
count = 0;
console.warn('Not enough samples fed for the next data frame. Expected frame is ' + samplesPerFrame + ' samples ' + channels + ' channels')
}
if (!callbackMarks.length) return
for (let i = 0, l = callbackMarks.length; i < l; i++) {
callbackMarks[i] = Math.max(callbackMarks[i] - len, 0)
}
while (callbackMarks[0] <= 0) {
callbackMarks.shift()
let cb = callbackQueue.shift()
cb()
}
} | javascript | function consume (len) {
count -= len
if (count < 0) {
count = 0;
console.warn('Not enough samples fed for the next data frame. Expected frame is ' + samplesPerFrame + ' samples ' + channels + ' channels')
}
if (!callbackMarks.length) return
for (let i = 0, l = callbackMarks.length; i < l; i++) {
callbackMarks[i] = Math.max(callbackMarks[i] - len, 0)
}
while (callbackMarks[0] <= 0) {
callbackMarks.shift()
let cb = callbackQueue.shift()
cb()
}
} | [
"function",
"consume",
"(",
"len",
")",
"{",
"count",
"-=",
"len",
"if",
"(",
"count",
"<",
"0",
")",
"{",
"count",
"=",
"0",
";",
"console",
".",
"warn",
"(",
"'Not enough samples fed for the next data frame. Expected frame is '",
"+",
"samplesPerFrame",
"+",
"' samples '",
"+",
"channels",
"+",
"' channels'",
")",
"}",
"if",
"(",
"!",
"callbackMarks",
".",
"length",
")",
"return",
"for",
"(",
"let",
"i",
"=",
"0",
",",
"l",
"=",
"callbackMarks",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"callbackMarks",
"[",
"i",
"]",
"=",
"Math",
".",
"max",
"(",
"callbackMarks",
"[",
"i",
"]",
"-",
"len",
",",
"0",
")",
"}",
"while",
"(",
"callbackMarks",
"[",
"0",
"]",
"<=",
"0",
")",
"{",
"callbackMarks",
".",
"shift",
"(",
")",
"let",
"cb",
"=",
"callbackQueue",
".",
"shift",
"(",
")",
"cb",
"(",
")",
"}",
"}"
]
| walk over callback stack, invoke according callbacks | [
"walk",
"over",
"callback",
"stack",
"invoke",
"according",
"callbacks"
]
| 2a1a623b98b028a9e6ff5b08601fa0324e010e74 | https://github.com/audiojs/web-audio-write/blob/2a1a623b98b028a9e6ff5b08601fa0324e010e74/index.js#L262-L280 |
44,256 | johanlahti/intro-guide-js | gulpfile.js | getLibPaths | function getLibPaths(libs, inject) {
inject = inject || false;
var libName,
libSrcs = [],
outSrcs = [];
for (libName in libs) {
libSrcs = libs[libName];
if (typeof libSrcs === "string") {
libSrcs = [libSrcs];
}
var basePath;
if (inject === true) {
// Adapt basepath for inject
basePath = path.join(p.dest, p.libsDestSubDir, libName);
}
else {
// Adapt basepath for libs' origin
basePath = path.join(p.libsDir, libName);
}
libSrcs = libSrcs.map(function(src) {
return path.join(basePath, src);
});
outSrcs = outSrcs.concat(libSrcs);
}
return outSrcs;
} | javascript | function getLibPaths(libs, inject) {
inject = inject || false;
var libName,
libSrcs = [],
outSrcs = [];
for (libName in libs) {
libSrcs = libs[libName];
if (typeof libSrcs === "string") {
libSrcs = [libSrcs];
}
var basePath;
if (inject === true) {
// Adapt basepath for inject
basePath = path.join(p.dest, p.libsDestSubDir, libName);
}
else {
// Adapt basepath for libs' origin
basePath = path.join(p.libsDir, libName);
}
libSrcs = libSrcs.map(function(src) {
return path.join(basePath, src);
});
outSrcs = outSrcs.concat(libSrcs);
}
return outSrcs;
} | [
"function",
"getLibPaths",
"(",
"libs",
",",
"inject",
")",
"{",
"inject",
"=",
"inject",
"||",
"false",
";",
"var",
"libName",
",",
"libSrcs",
"=",
"[",
"]",
",",
"outSrcs",
"=",
"[",
"]",
";",
"for",
"(",
"libName",
"in",
"libs",
")",
"{",
"libSrcs",
"=",
"libs",
"[",
"libName",
"]",
";",
"if",
"(",
"typeof",
"libSrcs",
"===",
"\"string\"",
")",
"{",
"libSrcs",
"=",
"[",
"libSrcs",
"]",
";",
"}",
"var",
"basePath",
";",
"if",
"(",
"inject",
"===",
"true",
")",
"{",
"// Adapt basepath for inject",
"basePath",
"=",
"path",
".",
"join",
"(",
"p",
".",
"dest",
",",
"p",
".",
"libsDestSubDir",
",",
"libName",
")",
";",
"}",
"else",
"{",
"// Adapt basepath for libs' origin",
"basePath",
"=",
"path",
".",
"join",
"(",
"p",
".",
"libsDir",
",",
"libName",
")",
";",
"}",
"libSrcs",
"=",
"libSrcs",
".",
"map",
"(",
"function",
"(",
"src",
")",
"{",
"return",
"path",
".",
"join",
"(",
"basePath",
",",
"src",
")",
";",
"}",
")",
";",
"outSrcs",
"=",
"outSrcs",
".",
"concat",
"(",
"libSrcs",
")",
";",
"}",
"return",
"outSrcs",
";",
"}"
]
| Adapts the lib paths for moving and injecting by
adding a basepath.
@param {Object} libs The libs in original key-value format
@param {Boolean} inject Get paths adapted for inject (if false, paths point to the lib source)
@return {Array} Array of libs | [
"Adapts",
"the",
"lib",
"paths",
"for",
"moving",
"and",
"injecting",
"by",
"adding",
"a",
"basepath",
"."
]
| 02aa607dfcbe66dd19a4401c8aa900147b409196 | https://github.com/johanlahti/intro-guide-js/blob/02aa607dfcbe66dd19a4401c8aa900147b409196/gulpfile.js#L85-L112 |
44,257 | jasontbradshaw/irobot | lib/sensors.js | function (valueKey, signed) {
return function (bytes) {
var result = {};
result[valueKey] = misc.bufferToInt(bytes, signed);
return result;
};
} | javascript | function (valueKey, signed) {
return function (bytes) {
var result = {};
result[valueKey] = misc.bufferToInt(bytes, signed);
return result;
};
} | [
"function",
"(",
"valueKey",
",",
"signed",
")",
"{",
"return",
"function",
"(",
"bytes",
")",
"{",
"var",
"result",
"=",
"{",
"}",
";",
"result",
"[",
"valueKey",
"]",
"=",
"misc",
".",
"bufferToInt",
"(",
"bytes",
",",
"signed",
")",
";",
"return",
"result",
";",
"}",
";",
"}"
]
| build a function that takes in some bytes, parses them as an integer, and returns an object with that value assigned to the given key. | [
"build",
"a",
"function",
"that",
"takes",
"in",
"some",
"bytes",
"parses",
"them",
"as",
"an",
"integer",
"and",
"returns",
"an",
"object",
"with",
"that",
"value",
"assigned",
"to",
"the",
"given",
"key",
"."
]
| 20efd28ea603c17b9c15701f4e364a4ebb507c45 | https://github.com/jasontbradshaw/irobot/blob/20efd28ea603c17b9c15701f4e364a4ebb507c45/lib/sensors.js#L10-L16 |
|
44,258 | jasontbradshaw/irobot | lib/sensors.js | function (options) {
return function (bytes) {
var result = {
min: options.min,
max: options.max,
range: options.max - options.min,
raw: misc.bufferToInt(bytes)
};
result.magnitude = 1.0 * result.raw / result.range;
return result;
};
} | javascript | function (options) {
return function (bytes) {
var result = {
min: options.min,
max: options.max,
range: options.max - options.min,
raw: misc.bufferToInt(bytes)
};
result.magnitude = 1.0 * result.raw / result.range;
return result;
};
} | [
"function",
"(",
"options",
")",
"{",
"return",
"function",
"(",
"bytes",
")",
"{",
"var",
"result",
"=",
"{",
"min",
":",
"options",
".",
"min",
",",
"max",
":",
"options",
".",
"max",
",",
"range",
":",
"options",
".",
"max",
"-",
"options",
".",
"min",
",",
"raw",
":",
"misc",
".",
"bufferToInt",
"(",
"bytes",
")",
"}",
";",
"result",
".",
"magnitude",
"=",
"1.0",
"*",
"result",
".",
"raw",
"/",
"result",
".",
"range",
";",
"return",
"result",
";",
"}",
";",
"}"
]
| build a function that takes in some bytes, parses them as an unsigned int, and returns an object with useful data about the value's magnitude between some minimum and maximum. | [
"build",
"a",
"function",
"that",
"takes",
"in",
"some",
"bytes",
"parses",
"them",
"as",
"an",
"unsigned",
"int",
"and",
"returns",
"an",
"object",
"with",
"useful",
"data",
"about",
"the",
"value",
"s",
"magnitude",
"between",
"some",
"minimum",
"and",
"maximum",
"."
]
| 20efd28ea603c17b9c15701f4e364a4ebb507c45 | https://github.com/jasontbradshaw/irobot/blob/20efd28ea603c17b9c15701f4e364a4ebb507c45/lib/sensors.js#L37-L50 |
|
44,259 | jasontbradshaw/irobot | lib/sensors.js | function (name, id, bytes, parser) {
this.name = name;
this.id = id;
this.bytes = bytes;
// the parser is null by default, otherwise the specified function
this.parser = _.isFunction(parser) ? parser : function () {};
} | javascript | function (name, id, bytes, parser) {
this.name = name;
this.id = id;
this.bytes = bytes;
// the parser is null by default, otherwise the specified function
this.parser = _.isFunction(parser) ? parser : function () {};
} | [
"function",
"(",
"name",
",",
"id",
",",
"bytes",
",",
"parser",
")",
"{",
"this",
".",
"name",
"=",
"name",
";",
"this",
".",
"id",
"=",
"id",
";",
"this",
".",
"bytes",
"=",
"bytes",
";",
"// the parser is null by default, otherwise the specified function",
"this",
".",
"parser",
"=",
"_",
".",
"isFunction",
"(",
"parser",
")",
"?",
"parser",
":",
"function",
"(",
")",
"{",
"}",
";",
"}"
]
| stores data about a sensor packet, and holds a function that parses its raw bytes into a more descriptive object format. | [
"stores",
"data",
"about",
"a",
"sensor",
"packet",
"and",
"holds",
"a",
"function",
"that",
"parses",
"its",
"raw",
"bytes",
"into",
"a",
"more",
"descriptive",
"object",
"format",
"."
]
| 20efd28ea603c17b9c15701f4e364a4ebb507c45 | https://github.com/jasontbradshaw/irobot/blob/20efd28ea603c17b9c15701f4e364a4ebb507c45/lib/sensors.js#L54-L61 |
|
44,260 | andrewdavey/vogue | src/VogueClient.js | VogueClient | function VogueClient(clientSocket, watcher) {
this.socket = clientSocket;
this.watcher = watcher;
this.watchedFiles = {};
clientSocket.on('watch', this.handleMessage.bind(this));
clientSocket.on('disconnect', this.disconnect.bind(this));
} | javascript | function VogueClient(clientSocket, watcher) {
this.socket = clientSocket;
this.watcher = watcher;
this.watchedFiles = {};
clientSocket.on('watch', this.handleMessage.bind(this));
clientSocket.on('disconnect', this.disconnect.bind(this));
} | [
"function",
"VogueClient",
"(",
"clientSocket",
",",
"watcher",
")",
"{",
"this",
".",
"socket",
"=",
"clientSocket",
";",
"this",
".",
"watcher",
"=",
"watcher",
";",
"this",
".",
"watchedFiles",
"=",
"{",
"}",
";",
"clientSocket",
".",
"on",
"(",
"'watch'",
",",
"this",
".",
"handleMessage",
".",
"bind",
"(",
"this",
")",
")",
";",
"clientSocket",
".",
"on",
"(",
"'disconnect'",
",",
"this",
".",
"disconnect",
".",
"bind",
"(",
"this",
")",
")",
";",
"}"
]
| Encapsulates a web socket client connection from a web browser. | [
"Encapsulates",
"a",
"web",
"socket",
"client",
"connection",
"from",
"a",
"web",
"browser",
"."
]
| 46e38b373c7a86bbbb15177822e1ea3ff1ecda6c | https://github.com/andrewdavey/vogue/blob/46e38b373c7a86bbbb15177822e1ea3ff1ecda6c/src/VogueClient.js#L6-L12 |
44,261 | alexindigo/configly | lib/load.js | load | function load(context)
{
var files
, layers
, cacheKey
;
// TODO: make it proper optional param
context = context || {};
// create new context
// in case if `load` called without context
context = typeOf(context) == 'function' ? context : this.new(context);
// fallback to defaults
context.directories = context.directories || context.defaults.directories;
// prepare cache key
cacheKey = getCacheKey.call(context);
// get config files names suitable for the situation
files = getFiles.call(context, process.env);
// load all available files
layers = loadFiles.call(context, context.directories, files);
// merge loaded layers
this._cache[cacheKey] = mergeLayers.call(context, layers);
// return immutable copy
return clone.call({
useCustomTypeOf: clone.behaviors.useCustomTypeOf,
'typeof': context.mergeTypeOf
}, this._cache[cacheKey]);
} | javascript | function load(context)
{
var files
, layers
, cacheKey
;
// TODO: make it proper optional param
context = context || {};
// create new context
// in case if `load` called without context
context = typeOf(context) == 'function' ? context : this.new(context);
// fallback to defaults
context.directories = context.directories || context.defaults.directories;
// prepare cache key
cacheKey = getCacheKey.call(context);
// get config files names suitable for the situation
files = getFiles.call(context, process.env);
// load all available files
layers = loadFiles.call(context, context.directories, files);
// merge loaded layers
this._cache[cacheKey] = mergeLayers.call(context, layers);
// return immutable copy
return clone.call({
useCustomTypeOf: clone.behaviors.useCustomTypeOf,
'typeof': context.mergeTypeOf
}, this._cache[cacheKey]);
} | [
"function",
"load",
"(",
"context",
")",
"{",
"var",
"files",
",",
"layers",
",",
"cacheKey",
";",
"// TODO: make it proper optional param",
"context",
"=",
"context",
"||",
"{",
"}",
";",
"// create new context",
"// in case if `load` called without context",
"context",
"=",
"typeOf",
"(",
"context",
")",
"==",
"'function'",
"?",
"context",
":",
"this",
".",
"new",
"(",
"context",
")",
";",
"// fallback to defaults",
"context",
".",
"directories",
"=",
"context",
".",
"directories",
"||",
"context",
".",
"defaults",
".",
"directories",
";",
"// prepare cache key",
"cacheKey",
"=",
"getCacheKey",
".",
"call",
"(",
"context",
")",
";",
"// get config files names suitable for the situation",
"files",
"=",
"getFiles",
".",
"call",
"(",
"context",
",",
"process",
".",
"env",
")",
";",
"// load all available files",
"layers",
"=",
"loadFiles",
".",
"call",
"(",
"context",
",",
"context",
".",
"directories",
",",
"files",
")",
";",
"// merge loaded layers",
"this",
".",
"_cache",
"[",
"cacheKey",
"]",
"=",
"mergeLayers",
".",
"call",
"(",
"context",
",",
"layers",
")",
";",
"// return immutable copy",
"return",
"clone",
".",
"call",
"(",
"{",
"useCustomTypeOf",
":",
"clone",
".",
"behaviors",
".",
"useCustomTypeOf",
",",
"'typeof'",
":",
"context",
".",
"mergeTypeOf",
"}",
",",
"this",
".",
"_cache",
"[",
"cacheKey",
"]",
")",
";",
"}"
]
| Loads config objects from several environment-derived files
and merges them in specific order.
By default it loads JSON files, also custom pluggable parsers are supported.
@param {function|object} [context] - custom context to use for search and loading config files
@returns {object} - result merged config object | [
"Loads",
"config",
"objects",
"from",
"several",
"environment",
"-",
"derived",
"files",
"and",
"merges",
"them",
"in",
"specific",
"order",
".",
"By",
"default",
"it",
"loads",
"JSON",
"files",
"also",
"custom",
"pluggable",
"parsers",
"are",
"supported",
"."
]
| 026423ba0e036cf8ca33cd2fd160df519715272d | https://github.com/alexindigo/configly/blob/026423ba0e036cf8ca33cd2fd160df519715272d/lib/load.js#L20-L54 |
44,262 | simbo/gulp-static-site-generator | index.js | transformChunk | function transformChunk(chunk, encoding, done) {
if (chunk.isNull()) return done();
if (chunk.isStream()) return this.emit('error', new PluginError(logFlag, 'Streaming not supported'));
if (
!(chunk.isMarkdown = options.regexpMarkdown.test(chunk.relative)) &&
!(chunk.isTemplate = options.regexpTemplate.test(chunk.relative)) &&
!(chunk.isHtml = options.regexpHtml.test(chunk.relative))
) {
return options.passThrough ? done(null, chunk) : done();
}
transformChunkData(chunk);
if (chunk.data.draft && process.env.NODE_ENV !== 'development') return done();
if (buffer.hasOwnProperty(chunk.relative)) {
logDuplicate(chunk);
return done();
}
transformChunkContents.call(this, chunk);
buffer[chunk.relative] = chunk;
done(null, chunk);
} | javascript | function transformChunk(chunk, encoding, done) {
if (chunk.isNull()) return done();
if (chunk.isStream()) return this.emit('error', new PluginError(logFlag, 'Streaming not supported'));
if (
!(chunk.isMarkdown = options.regexpMarkdown.test(chunk.relative)) &&
!(chunk.isTemplate = options.regexpTemplate.test(chunk.relative)) &&
!(chunk.isHtml = options.regexpHtml.test(chunk.relative))
) {
return options.passThrough ? done(null, chunk) : done();
}
transformChunkData(chunk);
if (chunk.data.draft && process.env.NODE_ENV !== 'development') return done();
if (buffer.hasOwnProperty(chunk.relative)) {
logDuplicate(chunk);
return done();
}
transformChunkContents.call(this, chunk);
buffer[chunk.relative] = chunk;
done(null, chunk);
} | [
"function",
"transformChunk",
"(",
"chunk",
",",
"encoding",
",",
"done",
")",
"{",
"if",
"(",
"chunk",
".",
"isNull",
"(",
")",
")",
"return",
"done",
"(",
")",
";",
"if",
"(",
"chunk",
".",
"isStream",
"(",
")",
")",
"return",
"this",
".",
"emit",
"(",
"'error'",
",",
"new",
"PluginError",
"(",
"logFlag",
",",
"'Streaming not supported'",
")",
")",
";",
"if",
"(",
"!",
"(",
"chunk",
".",
"isMarkdown",
"=",
"options",
".",
"regexpMarkdown",
".",
"test",
"(",
"chunk",
".",
"relative",
")",
")",
"&&",
"!",
"(",
"chunk",
".",
"isTemplate",
"=",
"options",
".",
"regexpTemplate",
".",
"test",
"(",
"chunk",
".",
"relative",
")",
")",
"&&",
"!",
"(",
"chunk",
".",
"isHtml",
"=",
"options",
".",
"regexpHtml",
".",
"test",
"(",
"chunk",
".",
"relative",
")",
")",
")",
"{",
"return",
"options",
".",
"passThrough",
"?",
"done",
"(",
"null",
",",
"chunk",
")",
":",
"done",
"(",
")",
";",
"}",
"transformChunkData",
"(",
"chunk",
")",
";",
"if",
"(",
"chunk",
".",
"data",
".",
"draft",
"&&",
"process",
".",
"env",
".",
"NODE_ENV",
"!==",
"'development'",
")",
"return",
"done",
"(",
")",
";",
"if",
"(",
"buffer",
".",
"hasOwnProperty",
"(",
"chunk",
".",
"relative",
")",
")",
"{",
"logDuplicate",
"(",
"chunk",
")",
";",
"return",
"done",
"(",
")",
";",
"}",
"transformChunkContents",
".",
"call",
"(",
"this",
",",
"chunk",
")",
";",
"buffer",
"[",
"chunk",
".",
"relative",
"]",
"=",
"chunk",
";",
"done",
"(",
"null",
",",
"chunk",
")",
";",
"}"
]
| transforms a stream chunk
@param {object} chunk chunk object
@param {string} encoding file encoding
@param {Function} done callback
@return {undefined} | [
"transforms",
"a",
"stream",
"chunk"
]
| 5bedaa01d6da11feb76c4c67a4d40337177d4d4f | https://github.com/simbo/gulp-static-site-generator/blob/5bedaa01d6da11feb76c4c67a4d40337177d4d4f/index.js#L73-L92 |
44,263 | simbo/gulp-static-site-generator | index.js | transformChunkData | function transformChunkData(chunk) {
var matter = grayMatter(String(chunk.contents)),
relPath = chunk.hasOwnProperty('data') && chunk.data.relativePath ?
chunk.data.relativePath : getRelativePath(chunk.relative),
absPath = path.normalize(path.join(options.basePath, relPath));
chunk.data = merge.recursive({},
options.data,
{
basePath: options.basePath,
relativePath: relPath,
path: absPath,
urlPath: options.prettyUrls ? path.dirname(absPath) + '/' : absPath,
srcBasePath: chunk.base,
srcRelativePath: chunk.relative,
srcPath: chunk.path,
contents: '',
draft: false,
layout: options.defaultLayout
},
chunk.data || {},
matter.data
);
chunk.contents = new Buffer(matter.content);
chunk.path = path.join(chunk.base, relPath);
return chunk;
} | javascript | function transformChunkData(chunk) {
var matter = grayMatter(String(chunk.contents)),
relPath = chunk.hasOwnProperty('data') && chunk.data.relativePath ?
chunk.data.relativePath : getRelativePath(chunk.relative),
absPath = path.normalize(path.join(options.basePath, relPath));
chunk.data = merge.recursive({},
options.data,
{
basePath: options.basePath,
relativePath: relPath,
path: absPath,
urlPath: options.prettyUrls ? path.dirname(absPath) + '/' : absPath,
srcBasePath: chunk.base,
srcRelativePath: chunk.relative,
srcPath: chunk.path,
contents: '',
draft: false,
layout: options.defaultLayout
},
chunk.data || {},
matter.data
);
chunk.contents = new Buffer(matter.content);
chunk.path = path.join(chunk.base, relPath);
return chunk;
} | [
"function",
"transformChunkData",
"(",
"chunk",
")",
"{",
"var",
"matter",
"=",
"grayMatter",
"(",
"String",
"(",
"chunk",
".",
"contents",
")",
")",
",",
"relPath",
"=",
"chunk",
".",
"hasOwnProperty",
"(",
"'data'",
")",
"&&",
"chunk",
".",
"data",
".",
"relativePath",
"?",
"chunk",
".",
"data",
".",
"relativePath",
":",
"getRelativePath",
"(",
"chunk",
".",
"relative",
")",
",",
"absPath",
"=",
"path",
".",
"normalize",
"(",
"path",
".",
"join",
"(",
"options",
".",
"basePath",
",",
"relPath",
")",
")",
";",
"chunk",
".",
"data",
"=",
"merge",
".",
"recursive",
"(",
"{",
"}",
",",
"options",
".",
"data",
",",
"{",
"basePath",
":",
"options",
".",
"basePath",
",",
"relativePath",
":",
"relPath",
",",
"path",
":",
"absPath",
",",
"urlPath",
":",
"options",
".",
"prettyUrls",
"?",
"path",
".",
"dirname",
"(",
"absPath",
")",
"+",
"'/'",
":",
"absPath",
",",
"srcBasePath",
":",
"chunk",
".",
"base",
",",
"srcRelativePath",
":",
"chunk",
".",
"relative",
",",
"srcPath",
":",
"chunk",
".",
"path",
",",
"contents",
":",
"''",
",",
"draft",
":",
"false",
",",
"layout",
":",
"options",
".",
"defaultLayout",
"}",
",",
"chunk",
".",
"data",
"||",
"{",
"}",
",",
"matter",
".",
"data",
")",
";",
"chunk",
".",
"contents",
"=",
"new",
"Buffer",
"(",
"matter",
".",
"content",
")",
";",
"chunk",
".",
"path",
"=",
"path",
".",
"join",
"(",
"chunk",
".",
"base",
",",
"relPath",
")",
";",
"return",
"chunk",
";",
"}"
]
| merge site data, options data, frontmatter data into chunk data
@param {object} chunk stream chunk object
@return {object} chunk with transformed data | [
"merge",
"site",
"data",
"options",
"data",
"frontmatter",
"data",
"into",
"chunk",
"data"
]
| 5bedaa01d6da11feb76c4c67a4d40337177d4d4f | https://github.com/simbo/gulp-static-site-generator/blob/5bedaa01d6da11feb76c4c67a4d40337177d4d4f/index.js#L99-L124 |
44,264 | simbo/gulp-static-site-generator | index.js | transformChunkContents | function transformChunkContents(chunk) {
var contents = String(chunk.contents);
try {
if (chunk.isMarkdown) {
contents = options.renderMarkdown(contents);
}
if (chunk.isTemplate) {
contents = options.renderTemplate(contents, chunk.data, chunk.data.srcPath);
}
chunk.contents = new Buffer(contents);
if (chunk.data.layout) applyLayout(chunk);
} catch (err) {
this.emit('error', new PluginError(logFlag, err.stack || err));
}
return chunk;
} | javascript | function transformChunkContents(chunk) {
var contents = String(chunk.contents);
try {
if (chunk.isMarkdown) {
contents = options.renderMarkdown(contents);
}
if (chunk.isTemplate) {
contents = options.renderTemplate(contents, chunk.data, chunk.data.srcPath);
}
chunk.contents = new Buffer(contents);
if (chunk.data.layout) applyLayout(chunk);
} catch (err) {
this.emit('error', new PluginError(logFlag, err.stack || err));
}
return chunk;
} | [
"function",
"transformChunkContents",
"(",
"chunk",
")",
"{",
"var",
"contents",
"=",
"String",
"(",
"chunk",
".",
"contents",
")",
";",
"try",
"{",
"if",
"(",
"chunk",
".",
"isMarkdown",
")",
"{",
"contents",
"=",
"options",
".",
"renderMarkdown",
"(",
"contents",
")",
";",
"}",
"if",
"(",
"chunk",
".",
"isTemplate",
")",
"{",
"contents",
"=",
"options",
".",
"renderTemplate",
"(",
"contents",
",",
"chunk",
".",
"data",
",",
"chunk",
".",
"data",
".",
"srcPath",
")",
";",
"}",
"chunk",
".",
"contents",
"=",
"new",
"Buffer",
"(",
"contents",
")",
";",
"if",
"(",
"chunk",
".",
"data",
".",
"layout",
")",
"applyLayout",
"(",
"chunk",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"this",
".",
"emit",
"(",
"'error'",
",",
"new",
"PluginError",
"(",
"logFlag",
",",
"err",
".",
"stack",
"||",
"err",
")",
")",
";",
"}",
"return",
"chunk",
";",
"}"
]
| render chunk contents with markdown renderer, wrap layout, render template
@param {object} chunk stream chunk object
@return {object} chunk with transformed contents | [
"render",
"chunk",
"contents",
"with",
"markdown",
"renderer",
"wrap",
"layout",
"render",
"template"
]
| 5bedaa01d6da11feb76c4c67a4d40337177d4d4f | https://github.com/simbo/gulp-static-site-generator/blob/5bedaa01d6da11feb76c4c67a4d40337177d4d4f/index.js#L131-L146 |
44,265 | simbo/gulp-static-site-generator | index.js | renderTemplate | function renderTemplate(contents, data, filename) {
if (!templateCache.hasOwnProperty(contents)) {
var jadeOptions = merge.recursive({}, options.jadeOptions, {filename: filename});
templateCache[contents] = options.jade.compile(contents, jadeOptions);
}
var locals = merge.recursive({}, data, {locals: locals});
return templateCache[contents](data);
} | javascript | function renderTemplate(contents, data, filename) {
if (!templateCache.hasOwnProperty(contents)) {
var jadeOptions = merge.recursive({}, options.jadeOptions, {filename: filename});
templateCache[contents] = options.jade.compile(contents, jadeOptions);
}
var locals = merge.recursive({}, data, {locals: locals});
return templateCache[contents](data);
} | [
"function",
"renderTemplate",
"(",
"contents",
",",
"data",
",",
"filename",
")",
"{",
"if",
"(",
"!",
"templateCache",
".",
"hasOwnProperty",
"(",
"contents",
")",
")",
"{",
"var",
"jadeOptions",
"=",
"merge",
".",
"recursive",
"(",
"{",
"}",
",",
"options",
".",
"jadeOptions",
",",
"{",
"filename",
":",
"filename",
"}",
")",
";",
"templateCache",
"[",
"contents",
"]",
"=",
"options",
".",
"jade",
".",
"compile",
"(",
"contents",
",",
"jadeOptions",
")",
";",
"}",
"var",
"locals",
"=",
"merge",
".",
"recursive",
"(",
"{",
"}",
",",
"data",
",",
"{",
"locals",
":",
"locals",
"}",
")",
";",
"return",
"templateCache",
"[",
"contents",
"]",
"(",
"data",
")",
";",
"}"
]
| render a template string with optional data
@param {string} contents template
@param {object} data optional template data
@param {object} filename optional template path for importing/mergeing
@return {string} rendered template | [
"render",
"a",
"template",
"string",
"with",
"optional",
"data"
]
| 5bedaa01d6da11feb76c4c67a4d40337177d4d4f | https://github.com/simbo/gulp-static-site-generator/blob/5bedaa01d6da11feb76c4c67a4d40337177d4d4f/index.js#L155-L162 |
44,266 | simbo/gulp-static-site-generator | index.js | applyLayout | function applyLayout(chunk) {
chunk.data.contents = String(chunk.contents);
var layout = getLayout(chunk.data.layout),
contents = options.renderTemplate(layout.contents, chunk.data, layout.path);
chunk.contents = new Buffer(contents);
return chunk;
} | javascript | function applyLayout(chunk) {
chunk.data.contents = String(chunk.contents);
var layout = getLayout(chunk.data.layout),
contents = options.renderTemplate(layout.contents, chunk.data, layout.path);
chunk.contents = new Buffer(contents);
return chunk;
} | [
"function",
"applyLayout",
"(",
"chunk",
")",
"{",
"chunk",
".",
"data",
".",
"contents",
"=",
"String",
"(",
"chunk",
".",
"contents",
")",
";",
"var",
"layout",
"=",
"getLayout",
"(",
"chunk",
".",
"data",
".",
"layout",
")",
",",
"contents",
"=",
"options",
".",
"renderTemplate",
"(",
"layout",
".",
"contents",
",",
"chunk",
".",
"data",
",",
"layout",
".",
"path",
")",
";",
"chunk",
".",
"contents",
"=",
"new",
"Buffer",
"(",
"contents",
")",
";",
"return",
"chunk",
";",
"}"
]
| set chunk contents as template data property and render it with a layout
@param {object} chunk stream chunk object
@return {object} chunk with applied layout | [
"set",
"chunk",
"contents",
"as",
"template",
"data",
"property",
"and",
"render",
"it",
"with",
"a",
"layout"
]
| 5bedaa01d6da11feb76c4c67a4d40337177d4d4f | https://github.com/simbo/gulp-static-site-generator/blob/5bedaa01d6da11feb76c4c67a4d40337177d4d4f/index.js#L190-L196 |
44,267 | simbo/gulp-static-site-generator | index.js | getRelativePath | function getRelativePath(filePath) {
var urlPath = path.join(
path.dirname(filePath),
path.basename(filePath, path.extname(filePath))
);
if (options.slugify) {
urlPath = urlPath.split('/').map(function(part) {
return slug(part, options.slugOptions);
}).join('/');
}
urlPath += !options.prettyUrls || (/(^|\/)index$/i).test(urlPath) ?
'.html' : '/index.html';
return urlPath;
} | javascript | function getRelativePath(filePath) {
var urlPath = path.join(
path.dirname(filePath),
path.basename(filePath, path.extname(filePath))
);
if (options.slugify) {
urlPath = urlPath.split('/').map(function(part) {
return slug(part, options.slugOptions);
}).join('/');
}
urlPath += !options.prettyUrls || (/(^|\/)index$/i).test(urlPath) ?
'.html' : '/index.html';
return urlPath;
} | [
"function",
"getRelativePath",
"(",
"filePath",
")",
"{",
"var",
"urlPath",
"=",
"path",
".",
"join",
"(",
"path",
".",
"dirname",
"(",
"filePath",
")",
",",
"path",
".",
"basename",
"(",
"filePath",
",",
"path",
".",
"extname",
"(",
"filePath",
")",
")",
")",
";",
"if",
"(",
"options",
".",
"slugify",
")",
"{",
"urlPath",
"=",
"urlPath",
".",
"split",
"(",
"'/'",
")",
".",
"map",
"(",
"function",
"(",
"part",
")",
"{",
"return",
"slug",
"(",
"part",
",",
"options",
".",
"slugOptions",
")",
";",
"}",
")",
".",
"join",
"(",
"'/'",
")",
";",
"}",
"urlPath",
"+=",
"!",
"options",
".",
"prettyUrls",
"||",
"(",
"/",
"(^|\\/)index$",
"/",
"i",
")",
".",
"test",
"(",
"urlPath",
")",
"?",
"'.html'",
":",
"'/index.html'",
";",
"return",
"urlPath",
";",
"}"
]
| transform a src file path into an relative url path
@param {string} filePath file path
@return {string} url | [
"transform",
"a",
"src",
"file",
"path",
"into",
"an",
"relative",
"url",
"path"
]
| 5bedaa01d6da11feb76c4c67a4d40337177d4d4f | https://github.com/simbo/gulp-static-site-generator/blob/5bedaa01d6da11feb76c4c67a4d40337177d4d4f/index.js#L203-L216 |
44,268 | simbo/gulp-static-site-generator | index.js | getLayout | function getLayout(layout) {
if (!layoutCache.hasOwnProperty(layout)) {
var layoutContents = false,
layoutPath = path.join(
path.isAbsolute(options.layoutPath) ?
options.layoutPath : path.join(process.cwd(), options.layoutPath),
layout
);
try {
layoutContents = fs.readFileSync(layoutPath, 'utf8');
} catch (err) {
throw new PluginError(logFlag, 'Could not read layout: \'' + layoutPath + '\'\n');
}
layoutCache[layout] = {
contents: layoutContents,
path: layoutPath
};
}
return layoutCache[layout];
} | javascript | function getLayout(layout) {
if (!layoutCache.hasOwnProperty(layout)) {
var layoutContents = false,
layoutPath = path.join(
path.isAbsolute(options.layoutPath) ?
options.layoutPath : path.join(process.cwd(), options.layoutPath),
layout
);
try {
layoutContents = fs.readFileSync(layoutPath, 'utf8');
} catch (err) {
throw new PluginError(logFlag, 'Could not read layout: \'' + layoutPath + '\'\n');
}
layoutCache[layout] = {
contents: layoutContents,
path: layoutPath
};
}
return layoutCache[layout];
} | [
"function",
"getLayout",
"(",
"layout",
")",
"{",
"if",
"(",
"!",
"layoutCache",
".",
"hasOwnProperty",
"(",
"layout",
")",
")",
"{",
"var",
"layoutContents",
"=",
"false",
",",
"layoutPath",
"=",
"path",
".",
"join",
"(",
"path",
".",
"isAbsolute",
"(",
"options",
".",
"layoutPath",
")",
"?",
"options",
".",
"layoutPath",
":",
"path",
".",
"join",
"(",
"process",
".",
"cwd",
"(",
")",
",",
"options",
".",
"layoutPath",
")",
",",
"layout",
")",
";",
"try",
"{",
"layoutContents",
"=",
"fs",
".",
"readFileSync",
"(",
"layoutPath",
",",
"'utf8'",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"throw",
"new",
"PluginError",
"(",
"logFlag",
",",
"'Could not read layout: \\''",
"+",
"layoutPath",
"+",
"'\\'\\n'",
")",
";",
"}",
"layoutCache",
"[",
"layout",
"]",
"=",
"{",
"contents",
":",
"layoutContents",
",",
"path",
":",
"layoutPath",
"}",
";",
"}",
"return",
"layoutCache",
"[",
"layout",
"]",
";",
"}"
]
| read a layout file from given path; store it in cache object for further
usage; return object with layout contents and absolute path
@param {string} layout path to layout
@return {object} layout contents and path | [
"read",
"a",
"layout",
"file",
"from",
"given",
"path",
";",
"store",
"it",
"in",
"cache",
"object",
"for",
"further",
"usage",
";",
"return",
"object",
"with",
"layout",
"contents",
"and",
"absolute",
"path"
]
| 5bedaa01d6da11feb76c4c67a4d40337177d4d4f | https://github.com/simbo/gulp-static-site-generator/blob/5bedaa01d6da11feb76c4c67a4d40337177d4d4f/index.js#L224-L243 |
44,269 | simbo/gulp-static-site-generator | index.js | logDuplicate | function logDuplicate(chunk) {
log(logFlag,
chalk.black.bgYellow('WARNING') + ' skipping ' +
chalk.magenta(chunk.data.srcRelativePath) +
' as it would output to same path as ' +
chalk.magenta(buffer[chunk.relative].data.srcRelativePath)
);
} | javascript | function logDuplicate(chunk) {
log(logFlag,
chalk.black.bgYellow('WARNING') + ' skipping ' +
chalk.magenta(chunk.data.srcRelativePath) +
' as it would output to same path as ' +
chalk.magenta(buffer[chunk.relative].data.srcRelativePath)
);
} | [
"function",
"logDuplicate",
"(",
"chunk",
")",
"{",
"log",
"(",
"logFlag",
",",
"chalk",
".",
"black",
".",
"bgYellow",
"(",
"'WARNING'",
")",
"+",
"' skipping '",
"+",
"chalk",
".",
"magenta",
"(",
"chunk",
".",
"data",
".",
"srcRelativePath",
")",
"+",
"' as it would output to same path as '",
"+",
"chalk",
".",
"magenta",
"(",
"buffer",
"[",
"chunk",
".",
"relative",
"]",
".",
"data",
".",
"srcRelativePath",
")",
")",
";",
"}"
]
| log possible output overwrite to console
@param {object} chunk stream chunk object
@return {undefined} | [
"log",
"possible",
"output",
"overwrite",
"to",
"console"
]
| 5bedaa01d6da11feb76c4c67a4d40337177d4d4f | https://github.com/simbo/gulp-static-site-generator/blob/5bedaa01d6da11feb76c4c67a4d40337177d4d4f/index.js#L250-L257 |
44,270 | alexindigo/configly | lib/include_files.js | includeFiles | function includeFiles(config, backRef)
{
backRef = backRef || [];
Object.keys(config).forEach(function(key)
{
var value, oneOffContext;
if (typeof config[key] == 'string')
{
// create temp context
oneOffContext = merge.call(cloneFunction, this, { files: [config[key]] });
// try to load data from file
value = this.load(oneOffContext);
// keep the entry if something's been resolved
// empty or unchanged value signal otherwise
if (isEmpty(value))
{
delete config[key];
}
else
{
config[key] = value;
}
}
else if (isObject(config[key]))
{
includeFiles.call(this, config[key], backRef.concat(key));
}
// Unsupported entry type
else
{
throw new Error('Illegal key type for custom-include-files at ' + backRef.concat(key).join('.') + ': ' + Object.prototype.toString.call(config[key]));
}
}.bind(this));
return config;
} | javascript | function includeFiles(config, backRef)
{
backRef = backRef || [];
Object.keys(config).forEach(function(key)
{
var value, oneOffContext;
if (typeof config[key] == 'string')
{
// create temp context
oneOffContext = merge.call(cloneFunction, this, { files: [config[key]] });
// try to load data from file
value = this.load(oneOffContext);
// keep the entry if something's been resolved
// empty or unchanged value signal otherwise
if (isEmpty(value))
{
delete config[key];
}
else
{
config[key] = value;
}
}
else if (isObject(config[key]))
{
includeFiles.call(this, config[key], backRef.concat(key));
}
// Unsupported entry type
else
{
throw new Error('Illegal key type for custom-include-files at ' + backRef.concat(key).join('.') + ': ' + Object.prototype.toString.call(config[key]));
}
}.bind(this));
return config;
} | [
"function",
"includeFiles",
"(",
"config",
",",
"backRef",
")",
"{",
"backRef",
"=",
"backRef",
"||",
"[",
"]",
";",
"Object",
".",
"keys",
"(",
"config",
")",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"var",
"value",
",",
"oneOffContext",
";",
"if",
"(",
"typeof",
"config",
"[",
"key",
"]",
"==",
"'string'",
")",
"{",
"// create temp context",
"oneOffContext",
"=",
"merge",
".",
"call",
"(",
"cloneFunction",
",",
"this",
",",
"{",
"files",
":",
"[",
"config",
"[",
"key",
"]",
"]",
"}",
")",
";",
"// try to load data from file",
"value",
"=",
"this",
".",
"load",
"(",
"oneOffContext",
")",
";",
"// keep the entry if something's been resolved",
"// empty or unchanged value signal otherwise",
"if",
"(",
"isEmpty",
"(",
"value",
")",
")",
"{",
"delete",
"config",
"[",
"key",
"]",
";",
"}",
"else",
"{",
"config",
"[",
"key",
"]",
"=",
"value",
";",
"}",
"}",
"else",
"if",
"(",
"isObject",
"(",
"config",
"[",
"key",
"]",
")",
")",
"{",
"includeFiles",
".",
"call",
"(",
"this",
",",
"config",
"[",
"key",
"]",
",",
"backRef",
".",
"concat",
"(",
"key",
")",
")",
";",
"}",
"// Unsupported entry type",
"else",
"{",
"throw",
"new",
"Error",
"(",
"'Illegal key type for custom-include-files at '",
"+",
"backRef",
".",
"concat",
"(",
"key",
")",
".",
"join",
"(",
"'.'",
")",
"+",
"': '",
"+",
"Object",
".",
"prototype",
".",
"toString",
".",
"call",
"(",
"config",
"[",
"key",
"]",
")",
")",
";",
"}",
"}",
".",
"bind",
"(",
"this",
")",
")",
";",
"return",
"config",
";",
"}"
]
| Replaces object's elements with content of corresponding files, if exist
@param {object} config - config object to process
@param {array} [backRef] - back reference to the parent element
@returns {object} - resolved object | [
"Replaces",
"object",
"s",
"elements",
"with",
"content",
"of",
"corresponding",
"files",
"if",
"exist"
]
| 026423ba0e036cf8ca33cd2fd160df519715272d | https://github.com/alexindigo/configly/blob/026423ba0e036cf8ca33cd2fd160df519715272d/lib/include_files.js#L21-L60 |
44,271 | jansanchez/gulp-email | lib/gulp-email.js | GulpEmail | function GulpEmail(opts, cb) {
this.fullContent = '';
this.default = {};
this.cb = cb || this.callback;
this.options = extend(this.default, opts);
this.stream = new Transform({objectMode: true});
this.stream._transform = function(chunk, encoding, callback){
var fullPath = null,
file = {},
relative = chunk.relative;
file.base = chunk.base;
file.contents = chunk.contents;
file.extname = Path.extname(relative);
file.basename = Path.basename(relative, file.extname);
file.dirname = Path.dirname(relative);
file.newDirname = utils.fixDirName(file.dirname);
fullPath = file.newDirname + file.basename + file.extname;
file.path = Path.join(chunk.base, fullPath);
callback(null, self.readContent(file));
};
this.stream.on('end', function() {
//console.log(self.fullContent);
self.sendEmail(self.prepareCurl(self.fullContent));
});
var self = this;
return this.stream;
} | javascript | function GulpEmail(opts, cb) {
this.fullContent = '';
this.default = {};
this.cb = cb || this.callback;
this.options = extend(this.default, opts);
this.stream = new Transform({objectMode: true});
this.stream._transform = function(chunk, encoding, callback){
var fullPath = null,
file = {},
relative = chunk.relative;
file.base = chunk.base;
file.contents = chunk.contents;
file.extname = Path.extname(relative);
file.basename = Path.basename(relative, file.extname);
file.dirname = Path.dirname(relative);
file.newDirname = utils.fixDirName(file.dirname);
fullPath = file.newDirname + file.basename + file.extname;
file.path = Path.join(chunk.base, fullPath);
callback(null, self.readContent(file));
};
this.stream.on('end', function() {
//console.log(self.fullContent);
self.sendEmail(self.prepareCurl(self.fullContent));
});
var self = this;
return this.stream;
} | [
"function",
"GulpEmail",
"(",
"opts",
",",
"cb",
")",
"{",
"this",
".",
"fullContent",
"=",
"''",
";",
"this",
".",
"default",
"=",
"{",
"}",
";",
"this",
".",
"cb",
"=",
"cb",
"||",
"this",
".",
"callback",
";",
"this",
".",
"options",
"=",
"extend",
"(",
"this",
".",
"default",
",",
"opts",
")",
";",
"this",
".",
"stream",
"=",
"new",
"Transform",
"(",
"{",
"objectMode",
":",
"true",
"}",
")",
";",
"this",
".",
"stream",
".",
"_transform",
"=",
"function",
"(",
"chunk",
",",
"encoding",
",",
"callback",
")",
"{",
"var",
"fullPath",
"=",
"null",
",",
"file",
"=",
"{",
"}",
",",
"relative",
"=",
"chunk",
".",
"relative",
";",
"file",
".",
"base",
"=",
"chunk",
".",
"base",
";",
"file",
".",
"contents",
"=",
"chunk",
".",
"contents",
";",
"file",
".",
"extname",
"=",
"Path",
".",
"extname",
"(",
"relative",
")",
";",
"file",
".",
"basename",
"=",
"Path",
".",
"basename",
"(",
"relative",
",",
"file",
".",
"extname",
")",
";",
"file",
".",
"dirname",
"=",
"Path",
".",
"dirname",
"(",
"relative",
")",
";",
"file",
".",
"newDirname",
"=",
"utils",
".",
"fixDirName",
"(",
"file",
".",
"dirname",
")",
";",
"fullPath",
"=",
"file",
".",
"newDirname",
"+",
"file",
".",
"basename",
"+",
"file",
".",
"extname",
";",
"file",
".",
"path",
"=",
"Path",
".",
"join",
"(",
"chunk",
".",
"base",
",",
"fullPath",
")",
";",
"callback",
"(",
"null",
",",
"self",
".",
"readContent",
"(",
"file",
")",
")",
";",
"}",
";",
"this",
".",
"stream",
".",
"on",
"(",
"'end'",
",",
"function",
"(",
")",
"{",
"//console.log(self.fullContent);",
"self",
".",
"sendEmail",
"(",
"self",
".",
"prepareCurl",
"(",
"self",
".",
"fullContent",
")",
")",
";",
"}",
")",
";",
"var",
"self",
"=",
"this",
";",
"return",
"this",
".",
"stream",
";",
"}"
]
| Gulp Email. | [
"Gulp",
"Email",
"."
]
| d0821e3434a13b90780581ef4752b14e422b2726 | https://github.com/jansanchez/gulp-email/blob/d0821e3434a13b90780581ef4752b14e422b2726/lib/gulp-email.js#L19-L54 |
44,272 | akabekobeko/npm-wpxml2md | src/lib/gfm.js | Cell | function Cell (node, content) {
let index = 0
if (node.parentNode && node.parentNode.childNodes) {
index = Util.arrayIndexOf(node.parentNode.childNodes, node)
}
const prefix = (index === 0 ? '| ' : ' ')
return prefix + content + ' |'
} | javascript | function Cell (node, content) {
let index = 0
if (node.parentNode && node.parentNode.childNodes) {
index = Util.arrayIndexOf(node.parentNode.childNodes, node)
}
const prefix = (index === 0 ? '| ' : ' ')
return prefix + content + ' |'
} | [
"function",
"Cell",
"(",
"node",
",",
"content",
")",
"{",
"let",
"index",
"=",
"0",
"if",
"(",
"node",
".",
"parentNode",
"&&",
"node",
".",
"parentNode",
".",
"childNodes",
")",
"{",
"index",
"=",
"Util",
".",
"arrayIndexOf",
"(",
"node",
".",
"parentNode",
".",
"childNodes",
",",
"node",
")",
"}",
"const",
"prefix",
"=",
"(",
"index",
"===",
"0",
"?",
"'| '",
":",
"' '",
")",
"return",
"prefix",
"+",
"content",
"+",
"' |'",
"}"
]
| Convert the DOM node to cell text of the table.
@param {Node} node DOM node.
@param {String} content Content text.
@return {String} Cell text. | [
"Convert",
"the",
"DOM",
"node",
"to",
"cell",
"text",
"of",
"the",
"table",
"."
]
| 87d81074407db4a9b8b62e17a21db13cf5d835dd | https://github.com/akabekobeko/npm-wpxml2md/blob/87d81074407db4a9b8b62e17a21db13cf5d835dd/src/lib/gfm.js#L11-L19 |
44,273 | alexindigo/configly | lib/get_var.js | getVar | function getVar(token, env)
{
var modifiers = token.split(/\s+/)
, name = modifiers.pop()
, result = ''
;
if (typeof env[name] == 'string' && env[name].length > 0)
{
result = env[name];
// process value with modifiers, right to left
result = modifiers.reverse().reduce(function(accumulatedValue, modifierName)
{
if (typeOf(this.modifiers[modifierName]) != 'function') {
throw new Error('Unable to find requested modifier `' + modifierName + '` among available modifiers: [' + Object.keys(this.modifiers).join('], [') + '].');
}
return this.modifiers[modifierName](accumulatedValue);
}.bind(this), result);
}
return result;
} | javascript | function getVar(token, env)
{
var modifiers = token.split(/\s+/)
, name = modifiers.pop()
, result = ''
;
if (typeof env[name] == 'string' && env[name].length > 0)
{
result = env[name];
// process value with modifiers, right to left
result = modifiers.reverse().reduce(function(accumulatedValue, modifierName)
{
if (typeOf(this.modifiers[modifierName]) != 'function') {
throw new Error('Unable to find requested modifier `' + modifierName + '` among available modifiers: [' + Object.keys(this.modifiers).join('], [') + '].');
}
return this.modifiers[modifierName](accumulatedValue);
}.bind(this), result);
}
return result;
} | [
"function",
"getVar",
"(",
"token",
",",
"env",
")",
"{",
"var",
"modifiers",
"=",
"token",
".",
"split",
"(",
"/",
"\\s+",
"/",
")",
",",
"name",
"=",
"modifiers",
".",
"pop",
"(",
")",
",",
"result",
"=",
"''",
";",
"if",
"(",
"typeof",
"env",
"[",
"name",
"]",
"==",
"'string'",
"&&",
"env",
"[",
"name",
"]",
".",
"length",
">",
"0",
")",
"{",
"result",
"=",
"env",
"[",
"name",
"]",
";",
"// process value with modifiers, right to left",
"result",
"=",
"modifiers",
".",
"reverse",
"(",
")",
".",
"reduce",
"(",
"function",
"(",
"accumulatedValue",
",",
"modifierName",
")",
"{",
"if",
"(",
"typeOf",
"(",
"this",
".",
"modifiers",
"[",
"modifierName",
"]",
")",
"!=",
"'function'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Unable to find requested modifier `'",
"+",
"modifierName",
"+",
"'` among available modifiers: ['",
"+",
"Object",
".",
"keys",
"(",
"this",
".",
"modifiers",
")",
".",
"join",
"(",
"'], ['",
")",
"+",
"'].'",
")",
";",
"}",
"return",
"this",
".",
"modifiers",
"[",
"modifierName",
"]",
"(",
"accumulatedValue",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
",",
"result",
")",
";",
"}",
"return",
"result",
";",
"}"
]
| Gets environment variable by provided name,
or return empty string if it doesn't exists
@param {string} token - variable token (name + modifiers) to process
@param {object} env - object to search within
@returns {string} - either variable if it exists or empty string | [
"Gets",
"environment",
"variable",
"by",
"provided",
"name",
"or",
"return",
"empty",
"string",
"if",
"it",
"doesn",
"t",
"exists"
]
| 026423ba0e036cf8ca33cd2fd160df519715272d | https://github.com/alexindigo/configly/blob/026423ba0e036cf8ca33cd2fd160df519715272d/lib/get_var.js#L14-L36 |
44,274 | sergeche/grunt-frontend | tasks/lib/javascript.js | function(config, env) {
return env.grunt.util._.extend({
banner: '',
compress: {
warnings: false
},
mangle: {},
beautify: false,
report: false
}, env.task.options(config.uglify || {}));
} | javascript | function(config, env) {
return env.grunt.util._.extend({
banner: '',
compress: {
warnings: false
},
mangle: {},
beautify: false,
report: false
}, env.task.options(config.uglify || {}));
} | [
"function",
"(",
"config",
",",
"env",
")",
"{",
"return",
"env",
".",
"grunt",
".",
"util",
".",
"_",
".",
"extend",
"(",
"{",
"banner",
":",
"''",
",",
"compress",
":",
"{",
"warnings",
":",
"false",
"}",
",",
"mangle",
":",
"{",
"}",
",",
"beautify",
":",
"false",
",",
"report",
":",
"false",
"}",
",",
"env",
".",
"task",
".",
"options",
"(",
"config",
".",
"uglify",
"||",
"{",
"}",
")",
")",
";",
"}"
]
| Returns config for UglifyJS
@param {Objecy} config Current config
@param {Objecy} env Task environment (`grunt` and `task` properties)
@return {Object} | [
"Returns",
"config",
"for",
"UglifyJS"
]
| e6552c178651b40f20d4ff2e297bc3efa9446f33 | https://github.com/sergeche/grunt-frontend/blob/e6552c178651b40f20d4ff2e297bc3efa9446f33/tasks/lib/javascript.js#L51-L61 |
|
44,275 | sergeche/grunt-frontend | tasks/lib/javascript.js | function(files, config, catalog, env) {
var uglifyConfig = this.uglifyConfig(config, env);
var grunt = env.grunt;
var _ = grunt.util._;
files.forEach(function(f) {
var src = validFiles(f.src, grunt, config);
var dest = utils.fileInfo(f.dest, config);
grunt.log.write('Processing ' + dest.catalogPath.cyan);
// check if current file should be compiled
if (!shouldProcess(dest, src, config, catalog)) {
grunt.log.writeln(' [skip]'.grey);
return false;
}
grunt.verbose.writeln('');
if (config.minify) {
grunt.verbose.writeln('Minifying JS files');
var uglified = uglify.minify(_.pluck(src, '_path'), dest.absPath, uglifyConfig);
dest.content = uglified.code;
} else {
dest.content = _.pluck(src, '_path')
.map(function(src) {
return grunt.file.read(src);
})
.join('');
}
if (config.postProcess) {
dest.content = config.postProcess(dest.content, dest);
}
grunt.file.write(dest.absPath, dest.content);
// Otherwise, print a success message....
grunt.log.writeln(' [save]'.green);
// update catalog entry
catalog[dest.catalogPath] = {
hash: dest.hash,
date: utils.timestamp(),
versioned: dest.versionedUrl(config),
files: src.map(function(f) {
return {
file: f.catalogPath,
hash: f.hash,
versioned: f.versionedUrl(config)
};
}, this)
};
});
return catalog;
} | javascript | function(files, config, catalog, env) {
var uglifyConfig = this.uglifyConfig(config, env);
var grunt = env.grunt;
var _ = grunt.util._;
files.forEach(function(f) {
var src = validFiles(f.src, grunt, config);
var dest = utils.fileInfo(f.dest, config);
grunt.log.write('Processing ' + dest.catalogPath.cyan);
// check if current file should be compiled
if (!shouldProcess(dest, src, config, catalog)) {
grunt.log.writeln(' [skip]'.grey);
return false;
}
grunt.verbose.writeln('');
if (config.minify) {
grunt.verbose.writeln('Minifying JS files');
var uglified = uglify.minify(_.pluck(src, '_path'), dest.absPath, uglifyConfig);
dest.content = uglified.code;
} else {
dest.content = _.pluck(src, '_path')
.map(function(src) {
return grunt.file.read(src);
})
.join('');
}
if (config.postProcess) {
dest.content = config.postProcess(dest.content, dest);
}
grunt.file.write(dest.absPath, dest.content);
// Otherwise, print a success message....
grunt.log.writeln(' [save]'.green);
// update catalog entry
catalog[dest.catalogPath] = {
hash: dest.hash,
date: utils.timestamp(),
versioned: dest.versionedUrl(config),
files: src.map(function(f) {
return {
file: f.catalogPath,
hash: f.hash,
versioned: f.versionedUrl(config)
};
}, this)
};
});
return catalog;
} | [
"function",
"(",
"files",
",",
"config",
",",
"catalog",
",",
"env",
")",
"{",
"var",
"uglifyConfig",
"=",
"this",
".",
"uglifyConfig",
"(",
"config",
",",
"env",
")",
";",
"var",
"grunt",
"=",
"env",
".",
"grunt",
";",
"var",
"_",
"=",
"grunt",
".",
"util",
".",
"_",
";",
"files",
".",
"forEach",
"(",
"function",
"(",
"f",
")",
"{",
"var",
"src",
"=",
"validFiles",
"(",
"f",
".",
"src",
",",
"grunt",
",",
"config",
")",
";",
"var",
"dest",
"=",
"utils",
".",
"fileInfo",
"(",
"f",
".",
"dest",
",",
"config",
")",
";",
"grunt",
".",
"log",
".",
"write",
"(",
"'Processing '",
"+",
"dest",
".",
"catalogPath",
".",
"cyan",
")",
";",
"// check if current file should be compiled",
"if",
"(",
"!",
"shouldProcess",
"(",
"dest",
",",
"src",
",",
"config",
",",
"catalog",
")",
")",
"{",
"grunt",
".",
"log",
".",
"writeln",
"(",
"' [skip]'",
".",
"grey",
")",
";",
"return",
"false",
";",
"}",
"grunt",
".",
"verbose",
".",
"writeln",
"(",
"''",
")",
";",
"if",
"(",
"config",
".",
"minify",
")",
"{",
"grunt",
".",
"verbose",
".",
"writeln",
"(",
"'Minifying JS files'",
")",
";",
"var",
"uglified",
"=",
"uglify",
".",
"minify",
"(",
"_",
".",
"pluck",
"(",
"src",
",",
"'_path'",
")",
",",
"dest",
".",
"absPath",
",",
"uglifyConfig",
")",
";",
"dest",
".",
"content",
"=",
"uglified",
".",
"code",
";",
"}",
"else",
"{",
"dest",
".",
"content",
"=",
"_",
".",
"pluck",
"(",
"src",
",",
"'_path'",
")",
".",
"map",
"(",
"function",
"(",
"src",
")",
"{",
"return",
"grunt",
".",
"file",
".",
"read",
"(",
"src",
")",
";",
"}",
")",
".",
"join",
"(",
"''",
")",
";",
"}",
"if",
"(",
"config",
".",
"postProcess",
")",
"{",
"dest",
".",
"content",
"=",
"config",
".",
"postProcess",
"(",
"dest",
".",
"content",
",",
"dest",
")",
";",
"}",
"grunt",
".",
"file",
".",
"write",
"(",
"dest",
".",
"absPath",
",",
"dest",
".",
"content",
")",
";",
"// Otherwise, print a success message....",
"grunt",
".",
"log",
".",
"writeln",
"(",
"' [save]'",
".",
"green",
")",
";",
"// update catalog entry",
"catalog",
"[",
"dest",
".",
"catalogPath",
"]",
"=",
"{",
"hash",
":",
"dest",
".",
"hash",
",",
"date",
":",
"utils",
".",
"timestamp",
"(",
")",
",",
"versioned",
":",
"dest",
".",
"versionedUrl",
"(",
"config",
")",
",",
"files",
":",
"src",
".",
"map",
"(",
"function",
"(",
"f",
")",
"{",
"return",
"{",
"file",
":",
"f",
".",
"catalogPath",
",",
"hash",
":",
"f",
".",
"hash",
",",
"versioned",
":",
"f",
".",
"versionedUrl",
"(",
"config",
")",
"}",
";",
"}",
",",
"this",
")",
"}",
";",
"}",
")",
";",
"return",
"catalog",
";",
"}"
]
| Processes given JS files
@param {Array} files Normalized Grunt task file list
@param {Object} config Current task config
@param {Object} catalog Output catalog
@param {Object} env Task environment (`grunt` and `task` properties)
@return {Object} Updated catalog | [
"Processes",
"given",
"JS",
"files"
]
| e6552c178651b40f20d4ff2e297bc3efa9446f33 | https://github.com/sergeche/grunt-frontend/blob/e6552c178651b40f20d4ff2e297bc3efa9446f33/tasks/lib/javascript.js#L71-L125 |
|
44,276 | alexindigo/configly | lib/get_cache_key.js | getCacheKey | function getCacheKey()
{
// use the one from the context
var directories = this.directories || this.defaults.directories;
return resolveDir(directories)
+ ':'
+ getFiles.call(this, process.env).join(',')
+ ':'
+ resolveExts.call(this).join(',')
;
} | javascript | function getCacheKey()
{
// use the one from the context
var directories = this.directories || this.defaults.directories;
return resolveDir(directories)
+ ':'
+ getFiles.call(this, process.env).join(',')
+ ':'
+ resolveExts.call(this).join(',')
;
} | [
"function",
"getCacheKey",
"(",
")",
"{",
"// use the one from the context",
"var",
"directories",
"=",
"this",
".",
"directories",
"||",
"this",
".",
"defaults",
".",
"directories",
";",
"return",
"resolveDir",
"(",
"directories",
")",
"+",
"':'",
"+",
"getFiles",
".",
"call",
"(",
"this",
",",
"process",
".",
"env",
")",
".",
"join",
"(",
"','",
")",
"+",
"':'",
"+",
"resolveExts",
".",
"call",
"(",
"this",
")",
".",
"join",
"(",
"','",
")",
";",
"}"
]
| Generates cache key from the search directories
and provided list of parsers
@returns {string} - cache key | [
"Generates",
"cache",
"key",
"from",
"the",
"search",
"directories",
"and",
"provided",
"list",
"of",
"parsers"
]
| 026423ba0e036cf8ca33cd2fd160df519715272d | https://github.com/alexindigo/configly/blob/026423ba0e036cf8ca33cd2fd160df519715272d/lib/get_cache_key.js#L16-L27 |
44,277 | alexindigo/configly | lib/get_cache_key.js | resolveDir | function resolveDir(directories)
{
var directoriesAbsPath;
if (typeOf(directories) == 'array')
{
directoriesAbsPath = directories.map(function(d)
{
return path.resolve(d);
}).join('|');
}
else
{
directoriesAbsPath = path.resolve(directories);
}
return directoriesAbsPath;
} | javascript | function resolveDir(directories)
{
var directoriesAbsPath;
if (typeOf(directories) == 'array')
{
directoriesAbsPath = directories.map(function(d)
{
return path.resolve(d);
}).join('|');
}
else
{
directoriesAbsPath = path.resolve(directories);
}
return directoriesAbsPath;
} | [
"function",
"resolveDir",
"(",
"directories",
")",
"{",
"var",
"directoriesAbsPath",
";",
"if",
"(",
"typeOf",
"(",
"directories",
")",
"==",
"'array'",
")",
"{",
"directoriesAbsPath",
"=",
"directories",
".",
"map",
"(",
"function",
"(",
"d",
")",
"{",
"return",
"path",
".",
"resolve",
"(",
"d",
")",
";",
"}",
")",
".",
"join",
"(",
"'|'",
")",
";",
"}",
"else",
"{",
"directoriesAbsPath",
"=",
"path",
".",
"resolve",
"(",
"directories",
")",
";",
"}",
"return",
"directoriesAbsPath",
";",
"}"
]
| Resolves `directories` argument into a absolute path
@param {array|string} directories - directories to resolve
@returns {string} - absolute path to the directories | [
"Resolves",
"directories",
"argument",
"into",
"a",
"absolute",
"path"
]
| 026423ba0e036cf8ca33cd2fd160df519715272d | https://github.com/alexindigo/configly/blob/026423ba0e036cf8ca33cd2fd160df519715272d/lib/get_cache_key.js#L35-L52 |
44,278 | CezaryDanielNowak/node-api-cache-proxy | index.js | function(href) {
var url = extract(href)
var queryObj = omit(url.qs, this.config.excludeRequestParams)
var desiredUrlParams = Object.keys(queryObj).map(function(paramName) {
return paramName + '=' + encodeURIComponent(queryObj[paramName])
}).join('&')
return desiredUrlParams ? url.url + '?' + desiredUrlParams : url.url
} | javascript | function(href) {
var url = extract(href)
var queryObj = omit(url.qs, this.config.excludeRequestParams)
var desiredUrlParams = Object.keys(queryObj).map(function(paramName) {
return paramName + '=' + encodeURIComponent(queryObj[paramName])
}).join('&')
return desiredUrlParams ? url.url + '?' + desiredUrlParams : url.url
} | [
"function",
"(",
"href",
")",
"{",
"var",
"url",
"=",
"extract",
"(",
"href",
")",
"var",
"queryObj",
"=",
"omit",
"(",
"url",
".",
"qs",
",",
"this",
".",
"config",
".",
"excludeRequestParams",
")",
"var",
"desiredUrlParams",
"=",
"Object",
".",
"keys",
"(",
"queryObj",
")",
".",
"map",
"(",
"function",
"(",
"paramName",
")",
"{",
"return",
"paramName",
"+",
"'='",
"+",
"encodeURIComponent",
"(",
"queryObj",
"[",
"paramName",
"]",
")",
"}",
")",
".",
"join",
"(",
"'&'",
")",
"return",
"desiredUrlParams",
"?",
"url",
".",
"url",
"+",
"'?'",
"+",
"desiredUrlParams",
":",
"url",
".",
"url",
"}"
]
| clearURL takes url string as input and remove parameters, that are
listed in config.excludeRequestParams
@param {string} href
@return {string} | [
"clearURL",
"takes",
"url",
"string",
"as",
"input",
"and",
"remove",
"parameters",
"that",
"are",
"listed",
"in",
"config",
".",
"excludeRequestParams"
]
| 7499f9a92161903693a49d51e615ef79b2027cb1 | https://github.com/CezaryDanielNowak/node-api-cache-proxy/blob/7499f9a92161903693a49d51e615ef79b2027cb1/index.js#L143-L152 |
|
44,279 | CezaryDanielNowak/node-api-cache-proxy | index.js | function(envelope) {
var filePath = this._getFileName(envelope)
filendir.writeFile(filePath, JSON.stringify(envelope), function(err) {
if (err) {
log('File could not be saved in ' + this.config.cacheDir)
throw err
}
}.bind(this))
} | javascript | function(envelope) {
var filePath = this._getFileName(envelope)
filendir.writeFile(filePath, JSON.stringify(envelope), function(err) {
if (err) {
log('File could not be saved in ' + this.config.cacheDir)
throw err
}
}.bind(this))
} | [
"function",
"(",
"envelope",
")",
"{",
"var",
"filePath",
"=",
"this",
".",
"_getFileName",
"(",
"envelope",
")",
"filendir",
".",
"writeFile",
"(",
"filePath",
",",
"JSON",
".",
"stringify",
"(",
"envelope",
")",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"log",
"(",
"'File could not be saved in '",
"+",
"this",
".",
"config",
".",
"cacheDir",
")",
"throw",
"err",
"}",
"}",
".",
"bind",
"(",
"this",
")",
")",
"}"
]
| Save request to file
@param {object} envelope
@return {none} | [
"Save",
"request",
"to",
"file"
]
| 7499f9a92161903693a49d51e615ef79b2027cb1 | https://github.com/CezaryDanielNowak/node-api-cache-proxy/blob/7499f9a92161903693a49d51e615ef79b2027cb1/index.js#L171-L180 |
|
44,280 | CezaryDanielNowak/node-api-cache-proxy | index.js | function(req, returnReference) {
getRawBody(req).then(function(bodyBuffer) {
returnReference.requestBody = bodyBuffer.toString()
}).catch(function() {
log('Unhandled error in getRawBody', arguments)
})
} | javascript | function(req, returnReference) {
getRawBody(req).then(function(bodyBuffer) {
returnReference.requestBody = bodyBuffer.toString()
}).catch(function() {
log('Unhandled error in getRawBody', arguments)
})
} | [
"function",
"(",
"req",
",",
"returnReference",
")",
"{",
"getRawBody",
"(",
"req",
")",
".",
"then",
"(",
"function",
"(",
"bodyBuffer",
")",
"{",
"returnReference",
".",
"requestBody",
"=",
"bodyBuffer",
".",
"toString",
"(",
")",
"}",
")",
".",
"catch",
"(",
"function",
"(",
")",
"{",
"log",
"(",
"'Unhandled error in getRawBody'",
",",
"arguments",
")",
"}",
")",
"}"
]
| POST, PUT methods' payload need to be taken out from request object.
@param {object} req Request object | [
"POST",
"PUT",
"methods",
"payload",
"need",
"to",
"be",
"taken",
"out",
"from",
"request",
"object",
"."
]
| 7499f9a92161903693a49d51e615ef79b2027cb1 | https://github.com/CezaryDanielNowak/node-api-cache-proxy/blob/7499f9a92161903693a49d51e615ef79b2027cb1/index.js#L196-L202 |
|
44,281 | alexindigo/configly | lib/create_new.js | createNew | function createNew(options)
{
var copy = cloneFunction(configly)
, instance = copy.bind(copy)
;
// enrich copy with helper methods
// mind baked-in context of the copies
applyProps.call(this, copy, options);
// get fresh list of filenames
// if needed
copy.files = copy.files || getFilenames.call(copy);
// expose public methods on the outside
// mind baked in context of the copies
copyProps.call(copy, instance);
return instance;
} | javascript | function createNew(options)
{
var copy = cloneFunction(configly)
, instance = copy.bind(copy)
;
// enrich copy with helper methods
// mind baked-in context of the copies
applyProps.call(this, copy, options);
// get fresh list of filenames
// if needed
copy.files = copy.files || getFilenames.call(copy);
// expose public methods on the outside
// mind baked in context of the copies
copyProps.call(copy, instance);
return instance;
} | [
"function",
"createNew",
"(",
"options",
")",
"{",
"var",
"copy",
"=",
"cloneFunction",
"(",
"configly",
")",
",",
"instance",
"=",
"copy",
".",
"bind",
"(",
"copy",
")",
";",
"// enrich copy with helper methods",
"// mind baked-in context of the copies",
"applyProps",
".",
"call",
"(",
"this",
",",
"copy",
",",
"options",
")",
";",
"// get fresh list of filenames",
"// if needed",
"copy",
".",
"files",
"=",
"copy",
".",
"files",
"||",
"getFilenames",
".",
"call",
"(",
"copy",
")",
";",
"// expose public methods on the outside",
"// mind baked in context of the copies",
"copyProps",
".",
"call",
"(",
"copy",
",",
"instance",
")",
";",
"return",
"instance",
";",
"}"
]
| Creates new copy of configly
immutable to singleton modifications
which will help to keep it stable
when used with in the libraries
@param {object} [options] - custom options to set as new defaults on the new instance
@returns {function} - immutable copy of configly | [
"Creates",
"new",
"copy",
"of",
"configly",
"immutable",
"to",
"singleton",
"modifications",
"which",
"will",
"help",
"to",
"keep",
"it",
"stable",
"when",
"used",
"with",
"in",
"the",
"libraries"
]
| 026423ba0e036cf8ca33cd2fd160df519715272d | https://github.com/alexindigo/configly/blob/026423ba0e036cf8ca33cd2fd160df519715272d/lib/create_new.js#L19-L38 |
44,282 | alexindigo/configly | lib/create_new.js | copyProps | function copyProps(target)
{
Object.keys(this).forEach(function(key)
{
target[key] = typeof this[key] == 'function' ? this[key].bind(this) : this[key];
}.bind(this));
return target;
} | javascript | function copyProps(target)
{
Object.keys(this).forEach(function(key)
{
target[key] = typeof this[key] == 'function' ? this[key].bind(this) : this[key];
}.bind(this));
return target;
} | [
"function",
"copyProps",
"(",
"target",
")",
"{",
"Object",
".",
"keys",
"(",
"this",
")",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"target",
"[",
"key",
"]",
"=",
"typeof",
"this",
"[",
"key",
"]",
"==",
"'function'",
"?",
"this",
"[",
"key",
"]",
".",
"bind",
"(",
"this",
")",
":",
"this",
"[",
"key",
"]",
";",
"}",
".",
"bind",
"(",
"this",
")",
")",
";",
"return",
"target",
";",
"}"
]
| Copies public properties to the provided target
@param {object} target - properties copy destination
@returns {object} - updated target object | [
"Copies",
"public",
"properties",
"to",
"the",
"provided",
"target"
]
| 026423ba0e036cf8ca33cd2fd160df519715272d | https://github.com/alexindigo/configly/blob/026423ba0e036cf8ca33cd2fd160df519715272d/lib/create_new.js#L80-L88 |
44,283 | alexindigo/configly | lib/create_new.js | getFilenames | function getFilenames()
{
var hostname = getHostname()
, host = hostname.split('.')[0]
;
return [
'default',
'', // allow suffixes as a basename (e.g. `environment`)
host,
hostname,
'local',
this.defaults.customIncludeFiles,
this.defaults.customEnvVars,
'runtime'
];
} | javascript | function getFilenames()
{
var hostname = getHostname()
, host = hostname.split('.')[0]
;
return [
'default',
'', // allow suffixes as a basename (e.g. `environment`)
host,
hostname,
'local',
this.defaults.customIncludeFiles,
this.defaults.customEnvVars,
'runtime'
];
} | [
"function",
"getFilenames",
"(",
")",
"{",
"var",
"hostname",
"=",
"getHostname",
"(",
")",
",",
"host",
"=",
"hostname",
".",
"split",
"(",
"'.'",
")",
"[",
"0",
"]",
";",
"return",
"[",
"'default'",
",",
"''",
",",
"// allow suffixes as a basename (e.g. `environment`)",
"host",
",",
"hostname",
",",
"'local'",
",",
"this",
".",
"defaults",
".",
"customIncludeFiles",
",",
"this",
".",
"defaults",
".",
"customEnvVars",
",",
"'runtime'",
"]",
";",
"}"
]
| Creates list of filenames to search with
@returns {array} - list of the filenames | [
"Creates",
"list",
"of",
"filenames",
"to",
"search",
"with"
]
| 026423ba0e036cf8ca33cd2fd160df519715272d | https://github.com/alexindigo/configly/blob/026423ba0e036cf8ca33cd2fd160df519715272d/lib/create_new.js#L105-L121 |
44,284 | kunruch/mmpilot | lib/utils.js | deepMerge | function deepMerge (base, custom) {
Object.keys(custom).forEach(function (key) {
if (!base.hasOwnProperty(key) || typeof base[key] !== 'object') {
base[key] = custom[key]
} else {
base[key] = deepMerge(base[key], custom[key])
}
})
return base
} | javascript | function deepMerge (base, custom) {
Object.keys(custom).forEach(function (key) {
if (!base.hasOwnProperty(key) || typeof base[key] !== 'object') {
base[key] = custom[key]
} else {
base[key] = deepMerge(base[key], custom[key])
}
})
return base
} | [
"function",
"deepMerge",
"(",
"base",
",",
"custom",
")",
"{",
"Object",
".",
"keys",
"(",
"custom",
")",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"if",
"(",
"!",
"base",
".",
"hasOwnProperty",
"(",
"key",
")",
"||",
"typeof",
"base",
"[",
"key",
"]",
"!==",
"'object'",
")",
"{",
"base",
"[",
"key",
"]",
"=",
"custom",
"[",
"key",
"]",
"}",
"else",
"{",
"base",
"[",
"key",
"]",
"=",
"deepMerge",
"(",
"base",
"[",
"key",
"]",
",",
"custom",
"[",
"key",
"]",
")",
"}",
"}",
")",
"return",
"base",
"}"
]
| Recusrsively merge config and custom, overriding the base value with custom values | [
"Recusrsively",
"merge",
"config",
"and",
"custom",
"overriding",
"the",
"base",
"value",
"with",
"custom",
"values"
]
| 7a996b632ea244c807d20673d96d4ad564666022 | https://github.com/kunruch/mmpilot/blob/7a996b632ea244c807d20673d96d4ad564666022/lib/utils.js#L6-L16 |
44,285 | kunruch/mmpilot | lib/utils.js | iterateFiles | function iterateFiles (dir, options, cb) {
var iterateOptions = {
ext: [], // extensions to look for
dirs: false, // do callback for dirs too
skip_: true, // skip files & dirs starting with _
recursive: true // do a recursive find
}
options = deepMerge(iterateOptions, options)
// console.log('options: ' + JSON.stringify(options))
iterateRecurse(dir, options, cb)
} | javascript | function iterateFiles (dir, options, cb) {
var iterateOptions = {
ext: [], // extensions to look for
dirs: false, // do callback for dirs too
skip_: true, // skip files & dirs starting with _
recursive: true // do a recursive find
}
options = deepMerge(iterateOptions, options)
// console.log('options: ' + JSON.stringify(options))
iterateRecurse(dir, options, cb)
} | [
"function",
"iterateFiles",
"(",
"dir",
",",
"options",
",",
"cb",
")",
"{",
"var",
"iterateOptions",
"=",
"{",
"ext",
":",
"[",
"]",
",",
"// extensions to look for",
"dirs",
":",
"false",
",",
"// do callback for dirs too",
"skip_",
":",
"true",
",",
"// skip files & dirs starting with _",
"recursive",
":",
"true",
"// do a recursive find",
"}",
"options",
"=",
"deepMerge",
"(",
"iterateOptions",
",",
"options",
")",
"// console.log('options: ' + JSON.stringify(options))",
"iterateRecurse",
"(",
"dir",
",",
"options",
",",
"cb",
")",
"}"
]
| Iterates through a given folder and calls cb for each file found based on given options | [
"Iterates",
"through",
"a",
"given",
"folder",
"and",
"calls",
"cb",
"for",
"each",
"file",
"found",
"based",
"on",
"given",
"options"
]
| 7a996b632ea244c807d20673d96d4ad564666022 | https://github.com/kunruch/mmpilot/blob/7a996b632ea244c807d20673d96d4ad564666022/lib/utils.js#L21-L32 |
44,286 | kunruch/mmpilot | lib/utils.js | iterateRecurse | function iterateRecurse (dir, options, cb) {
try {
var files = fs.readdirSync(dir)
files.forEach(function (file, index) {
var parsedPath = path.parse(file)
var name = parsedPath.name
var ext = parsedPath.ext
var srcpath = path.join(dir, file)
if (options.skip_ && name.charAt(0) === '_') {
logger.debug('Skipping file/folder: ' + srcpath)
} else {
if (fs.lstatSync(srcpath).isDirectory()) {
if (options.dirs) {
cb(srcpath, name)
}
// Do recursive search when needed
if (options.recursive) {
iterateRecurse(srcpath, options, cb)
}
} else {
for (var i = 0; i < options.ext.length; i++) {
if (ext === options.ext[i]) {
cb(srcpath, name, ext)
}
}
}
}
})
} catch (e) {
logger.debug('Error iterating files: ' + e)
}
} | javascript | function iterateRecurse (dir, options, cb) {
try {
var files = fs.readdirSync(dir)
files.forEach(function (file, index) {
var parsedPath = path.parse(file)
var name = parsedPath.name
var ext = parsedPath.ext
var srcpath = path.join(dir, file)
if (options.skip_ && name.charAt(0) === '_') {
logger.debug('Skipping file/folder: ' + srcpath)
} else {
if (fs.lstatSync(srcpath).isDirectory()) {
if (options.dirs) {
cb(srcpath, name)
}
// Do recursive search when needed
if (options.recursive) {
iterateRecurse(srcpath, options, cb)
}
} else {
for (var i = 0; i < options.ext.length; i++) {
if (ext === options.ext[i]) {
cb(srcpath, name, ext)
}
}
}
}
})
} catch (e) {
logger.debug('Error iterating files: ' + e)
}
} | [
"function",
"iterateRecurse",
"(",
"dir",
",",
"options",
",",
"cb",
")",
"{",
"try",
"{",
"var",
"files",
"=",
"fs",
".",
"readdirSync",
"(",
"dir",
")",
"files",
".",
"forEach",
"(",
"function",
"(",
"file",
",",
"index",
")",
"{",
"var",
"parsedPath",
"=",
"path",
".",
"parse",
"(",
"file",
")",
"var",
"name",
"=",
"parsedPath",
".",
"name",
"var",
"ext",
"=",
"parsedPath",
".",
"ext",
"var",
"srcpath",
"=",
"path",
".",
"join",
"(",
"dir",
",",
"file",
")",
"if",
"(",
"options",
".",
"skip_",
"&&",
"name",
".",
"charAt",
"(",
"0",
")",
"===",
"'_'",
")",
"{",
"logger",
".",
"debug",
"(",
"'Skipping file/folder: '",
"+",
"srcpath",
")",
"}",
"else",
"{",
"if",
"(",
"fs",
".",
"lstatSync",
"(",
"srcpath",
")",
".",
"isDirectory",
"(",
")",
")",
"{",
"if",
"(",
"options",
".",
"dirs",
")",
"{",
"cb",
"(",
"srcpath",
",",
"name",
")",
"}",
"// Do recursive search when needed",
"if",
"(",
"options",
".",
"recursive",
")",
"{",
"iterateRecurse",
"(",
"srcpath",
",",
"options",
",",
"cb",
")",
"}",
"}",
"else",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"options",
".",
"ext",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"ext",
"===",
"options",
".",
"ext",
"[",
"i",
"]",
")",
"{",
"cb",
"(",
"srcpath",
",",
"name",
",",
"ext",
")",
"}",
"}",
"}",
"}",
"}",
")",
"}",
"catch",
"(",
"e",
")",
"{",
"logger",
".",
"debug",
"(",
"'Error iterating files: '",
"+",
"e",
")",
"}",
"}"
]
| Private recursive method for doing the above | [
"Private",
"recursive",
"method",
"for",
"doing",
"the",
"above"
]
| 7a996b632ea244c807d20673d96d4ad564666022 | https://github.com/kunruch/mmpilot/blob/7a996b632ea244c807d20673d96d4ad564666022/lib/utils.js#L37-L70 |
44,287 | revin/innertext | index.js | innertext | function innertext (html) {
// Drop everything inside <...> (i.e., tags/elements), and keep the text.
// Unlike browser innerText, this removes newlines; it also doesn't handle
// un-encoded `<` or `>` characters very well, so don't feed it malformed HTML
return entities.decode(html.split(/<[^>]+>/)
.map(function (chunk) { return chunk.trim() })
.filter(function (trimmedChunk) { return trimmedChunk.length > 0 })
.join(' ')
);
} | javascript | function innertext (html) {
// Drop everything inside <...> (i.e., tags/elements), and keep the text.
// Unlike browser innerText, this removes newlines; it also doesn't handle
// un-encoded `<` or `>` characters very well, so don't feed it malformed HTML
return entities.decode(html.split(/<[^>]+>/)
.map(function (chunk) { return chunk.trim() })
.filter(function (trimmedChunk) { return trimmedChunk.length > 0 })
.join(' ')
);
} | [
"function",
"innertext",
"(",
"html",
")",
"{",
"// Drop everything inside <...> (i.e., tags/elements), and keep the text.",
"// Unlike browser innerText, this removes newlines; it also doesn't handle",
"// un-encoded `<` or `>` characters very well, so don't feed it malformed HTML",
"return",
"entities",
".",
"decode",
"(",
"html",
".",
"split",
"(",
"/",
"<[^>]+>",
"/",
")",
".",
"map",
"(",
"function",
"(",
"chunk",
")",
"{",
"return",
"chunk",
".",
"trim",
"(",
")",
"}",
")",
".",
"filter",
"(",
"function",
"(",
"trimmedChunk",
")",
"{",
"return",
"trimmedChunk",
".",
"length",
">",
"0",
"}",
")",
".",
"join",
"(",
"' '",
")",
")",
";",
"}"
]
| Quick and dirty way of getting the text representation of a string of HTML, basically close to what a DOM node's innerText property would be | [
"Quick",
"and",
"dirty",
"way",
"of",
"getting",
"the",
"text",
"representation",
"of",
"a",
"string",
"of",
"HTML",
"basically",
"close",
"to",
"what",
"a",
"DOM",
"node",
"s",
"innerText",
"property",
"would",
"be"
]
| 3fc61111e10d381dc701206e734249793eca8034 | https://github.com/revin/innertext/blob/3fc61111e10d381dc701206e734249793eca8034/index.js#L8-L17 |
44,288 | akabekobeko/npm-wpxml2md | examples/util.js | existsSync | function existsSync (path) {
try {
Fs.accessSync(Path.resolve(path), Fs.F_OK)
return true
} catch (err) {
return false
}
} | javascript | function existsSync (path) {
try {
Fs.accessSync(Path.resolve(path), Fs.F_OK)
return true
} catch (err) {
return false
}
} | [
"function",
"existsSync",
"(",
"path",
")",
"{",
"try",
"{",
"Fs",
".",
"accessSync",
"(",
"Path",
".",
"resolve",
"(",
"path",
")",
",",
"Fs",
".",
"F_OK",
")",
"return",
"true",
"}",
"catch",
"(",
"err",
")",
"{",
"return",
"false",
"}",
"}"
]
| Check the existence of a file or folder.
@param {String} path Path of the file or folder.
@return {Boolean} True if exists. Otherwise false. | [
"Check",
"the",
"existence",
"of",
"a",
"file",
"or",
"folder",
"."
]
| 87d81074407db4a9b8b62e17a21db13cf5d835dd | https://github.com/akabekobeko/npm-wpxml2md/blob/87d81074407db4a9b8b62e17a21db13cf5d835dd/examples/util.js#L11-L18 |
44,289 | alexindigo/configly | lib/get_files.js | getFiles | function getFiles(env)
{
var files = []
, environment = env['NODE_ENV'] || this.defaults.environment
, appInstance = env['NODE_APP_INSTANCE']
;
// generate config files variations
this.files.forEach(function(baseName)
{
// check for variables
// keep baseName if no variables found
baseName = parseTokens(baseName, env) || baseName;
// add base name with available suffixes
addWithSuffixes.call(this, files, baseName, appInstance);
addWithSuffixes.call(this, files, baseName, environment, appInstance);
}.bind(this));
return files;
} | javascript | function getFiles(env)
{
var files = []
, environment = env['NODE_ENV'] || this.defaults.environment
, appInstance = env['NODE_APP_INSTANCE']
;
// generate config files variations
this.files.forEach(function(baseName)
{
// check for variables
// keep baseName if no variables found
baseName = parseTokens(baseName, env) || baseName;
// add base name with available suffixes
addWithSuffixes.call(this, files, baseName, appInstance);
addWithSuffixes.call(this, files, baseName, environment, appInstance);
}.bind(this));
return files;
} | [
"function",
"getFiles",
"(",
"env",
")",
"{",
"var",
"files",
"=",
"[",
"]",
",",
"environment",
"=",
"env",
"[",
"'NODE_ENV'",
"]",
"||",
"this",
".",
"defaults",
".",
"environment",
",",
"appInstance",
"=",
"env",
"[",
"'NODE_APP_INSTANCE'",
"]",
";",
"// generate config files variations",
"this",
".",
"files",
".",
"forEach",
"(",
"function",
"(",
"baseName",
")",
"{",
"// check for variables",
"// keep baseName if no variables found",
"baseName",
"=",
"parseTokens",
"(",
"baseName",
",",
"env",
")",
"||",
"baseName",
";",
"// add base name with available suffixes",
"addWithSuffixes",
".",
"call",
"(",
"this",
",",
"files",
",",
"baseName",
",",
"appInstance",
")",
";",
"addWithSuffixes",
".",
"call",
"(",
"this",
",",
"files",
",",
"baseName",
",",
"environment",
",",
"appInstance",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
")",
";",
"return",
"files",
";",
"}"
]
| Creates list of files to load configuration from
derived from the passed environment-like object
@param {object} env - environment-like object (e.g. `process.env`)
@returns {array} - ordered list of config files to load | [
"Creates",
"list",
"of",
"files",
"to",
"load",
"configuration",
"from",
"derived",
"from",
"the",
"passed",
"environment",
"-",
"like",
"object"
]
| 026423ba0e036cf8ca33cd2fd160df519715272d | https://github.com/alexindigo/configly/blob/026423ba0e036cf8ca33cd2fd160df519715272d/lib/get_files.js#L15-L35 |
44,290 | alexindigo/configly | lib/merge_layers.js | mergeLayers | function mergeLayers(layers)
{
var _instance = this
, result = null
;
layers.forEach(function(layer)
{
layer.exts.forEach(function(ext)
{
ext.dirs.forEach(function(cfg)
{
// have customizable's array merge function
result = merge.call({
useCustomAdapters: merge.behaviors.useCustomAdapters,
'array': _instance.arrayMerge,
useCustomTypeOf: merge.behaviors.useCustomTypeOf,
'typeof': _instance.mergeTypeOf
}, result || {}, cfg.config);
});
});
});
// return `null` if noting found
// and let downstream layers to make the decision
return result;
} | javascript | function mergeLayers(layers)
{
var _instance = this
, result = null
;
layers.forEach(function(layer)
{
layer.exts.forEach(function(ext)
{
ext.dirs.forEach(function(cfg)
{
// have customizable's array merge function
result = merge.call({
useCustomAdapters: merge.behaviors.useCustomAdapters,
'array': _instance.arrayMerge,
useCustomTypeOf: merge.behaviors.useCustomTypeOf,
'typeof': _instance.mergeTypeOf
}, result || {}, cfg.config);
});
});
});
// return `null` if noting found
// and let downstream layers to make the decision
return result;
} | [
"function",
"mergeLayers",
"(",
"layers",
")",
"{",
"var",
"_instance",
"=",
"this",
",",
"result",
"=",
"null",
";",
"layers",
".",
"forEach",
"(",
"function",
"(",
"layer",
")",
"{",
"layer",
".",
"exts",
".",
"forEach",
"(",
"function",
"(",
"ext",
")",
"{",
"ext",
".",
"dirs",
".",
"forEach",
"(",
"function",
"(",
"cfg",
")",
"{",
"// have customizable's array merge function",
"result",
"=",
"merge",
".",
"call",
"(",
"{",
"useCustomAdapters",
":",
"merge",
".",
"behaviors",
".",
"useCustomAdapters",
",",
"'array'",
":",
"_instance",
".",
"arrayMerge",
",",
"useCustomTypeOf",
":",
"merge",
".",
"behaviors",
".",
"useCustomTypeOf",
",",
"'typeof'",
":",
"_instance",
".",
"mergeTypeOf",
"}",
",",
"result",
"||",
"{",
"}",
",",
"cfg",
".",
"config",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"// return `null` if noting found",
"// and let downstream layers to make the decision",
"return",
"result",
";",
"}"
]
| Merges provided layers into a single config object,
respecting order of the layers
@param {array} layers - list of config objects
@returns {object} - single config object | [
"Merges",
"provided",
"layers",
"into",
"a",
"single",
"config",
"object",
"respecting",
"order",
"of",
"the",
"layers"
]
| 026423ba0e036cf8ca33cd2fd160df519715272d | https://github.com/alexindigo/configly/blob/026423ba0e036cf8ca33cd2fd160df519715272d/lib/merge_layers.js#L13-L39 |
44,291 | noerw/gitbook-plugin-localized-footer | index.js | function() {
cfg = this.config.get('pluginsConfig.localized-footer'), _this = this;
try {
fs.statSync(this.resolve(cfg.filename));
hasFooterFile = true;
} catch (e) {
hasFooterFile = false;
return;
}
deprecationWarning(this);
this.readFileAsString(cfg.filename)
.then(function(data) {
return _this.renderBlock('markdown', data);
}, this.log.error)
.then(function(html) {
footerString = html;
}, this.log.error);
} | javascript | function() {
cfg = this.config.get('pluginsConfig.localized-footer'), _this = this;
try {
fs.statSync(this.resolve(cfg.filename));
hasFooterFile = true;
} catch (e) {
hasFooterFile = false;
return;
}
deprecationWarning(this);
this.readFileAsString(cfg.filename)
.then(function(data) {
return _this.renderBlock('markdown', data);
}, this.log.error)
.then(function(html) {
footerString = html;
}, this.log.error);
} | [
"function",
"(",
")",
"{",
"cfg",
"=",
"this",
".",
"config",
".",
"get",
"(",
"'pluginsConfig.localized-footer'",
")",
",",
"_this",
"=",
"this",
";",
"try",
"{",
"fs",
".",
"statSync",
"(",
"this",
".",
"resolve",
"(",
"cfg",
".",
"filename",
")",
")",
";",
"hasFooterFile",
"=",
"true",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"hasFooterFile",
"=",
"false",
";",
"return",
";",
"}",
"deprecationWarning",
"(",
"this",
")",
";",
"this",
".",
"readFileAsString",
"(",
"cfg",
".",
"filename",
")",
".",
"then",
"(",
"function",
"(",
"data",
")",
"{",
"return",
"_this",
".",
"renderBlock",
"(",
"'markdown'",
",",
"data",
")",
";",
"}",
",",
"this",
".",
"log",
".",
"error",
")",
".",
"then",
"(",
"function",
"(",
"html",
")",
"{",
"footerString",
"=",
"html",
";",
"}",
",",
"this",
".",
"log",
".",
"error",
")",
";",
"}"
]
| called on each book & each language book | [
"called",
"on",
"each",
"book",
"&",
"each",
"language",
"book"
]
| 6dd48632e6c39b8bb223f0aed3ee832be17dab99 | https://github.com/noerw/gitbook-plugin-localized-footer/blob/6dd48632e6c39b8bb223f0aed3ee832be17dab99/index.js#L9-L29 |
|
44,292 | alexindigo/configly | lib/apply_hooks.js | applyHooks | function applyHooks(config, filename)
{
// sort hooks short first + alphabetically
Object.keys(this.hooks).sort(compareHooks).forEach(function(hook)
{
// in order to match hook should either the same length
// as the filename or smaller
if (filename.substr(0, hook.length) === hook)
{
config = this.hooks[hook].call(this, config);
}
}.bind(this));
return config;
} | javascript | function applyHooks(config, filename)
{
// sort hooks short first + alphabetically
Object.keys(this.hooks).sort(compareHooks).forEach(function(hook)
{
// in order to match hook should either the same length
// as the filename or smaller
if (filename.substr(0, hook.length) === hook)
{
config = this.hooks[hook].call(this, config);
}
}.bind(this));
return config;
} | [
"function",
"applyHooks",
"(",
"config",
",",
"filename",
")",
"{",
"// sort hooks short first + alphabetically",
"Object",
".",
"keys",
"(",
"this",
".",
"hooks",
")",
".",
"sort",
"(",
"compareHooks",
")",
".",
"forEach",
"(",
"function",
"(",
"hook",
")",
"{",
"// in order to match hook should either the same length",
"// as the filename or smaller",
"if",
"(",
"filename",
".",
"substr",
"(",
"0",
",",
"hook",
".",
"length",
")",
"===",
"hook",
")",
"{",
"config",
"=",
"this",
".",
"hooks",
"[",
"hook",
"]",
".",
"call",
"(",
"this",
",",
"config",
")",
";",
"}",
"}",
".",
"bind",
"(",
"this",
")",
")",
";",
"return",
"config",
";",
"}"
]
| Applies matched hooks
@param {object} config - config object to apply hooks to
@param {string} filename - base filename to match hooks against
@returns {object} - modified config object | [
"Applies",
"matched",
"hooks"
]
| 026423ba0e036cf8ca33cd2fd160df519715272d | https://github.com/alexindigo/configly/blob/026423ba0e036cf8ca33cd2fd160df519715272d/lib/apply_hooks.js#L11-L25 |
44,293 | alexindigo/configly | lib/apply_hooks.js | compareHooks | function compareHooks(a, b)
{
return a.length < b.length ? -1 : (a.length > b.length ? 1 : (a < b ? -1 : (a > b ? 1 : 0)));
} | javascript | function compareHooks(a, b)
{
return a.length < b.length ? -1 : (a.length > b.length ? 1 : (a < b ? -1 : (a > b ? 1 : 0)));
} | [
"function",
"compareHooks",
"(",
"a",
",",
"b",
")",
"{",
"return",
"a",
".",
"length",
"<",
"b",
".",
"length",
"?",
"-",
"1",
":",
"(",
"a",
".",
"length",
">",
"b",
".",
"length",
"?",
"1",
":",
"(",
"a",
"<",
"b",
"?",
"-",
"1",
":",
"(",
"a",
">",
"b",
"?",
"1",
":",
"0",
")",
")",
")",
";",
"}"
]
| Compares hook names shorter to longer and alphabetically
@param {string} a - first key
@param {string} b - second key
@returns {number} -1 - `a` comes first, 0 - positions unchanged, 1 - `b` comes first | [
"Compares",
"hook",
"names",
"shorter",
"to",
"longer",
"and",
"alphabetically"
]
| 026423ba0e036cf8ca33cd2fd160df519715272d | https://github.com/alexindigo/configly/blob/026423ba0e036cf8ca33cd2fd160df519715272d/lib/apply_hooks.js#L34-L37 |
44,294 | alexindigo/configly | lib/has_value.js | hasValue | function hasValue(value)
{
if (typeOf(value) === 'string') {
return value.length > 0;
} else {
return typeOf(value) !== 'undefined' && typeOf(value) !== 'nan';
}
} | javascript | function hasValue(value)
{
if (typeOf(value) === 'string') {
return value.length > 0;
} else {
return typeOf(value) !== 'undefined' && typeOf(value) !== 'nan';
}
} | [
"function",
"hasValue",
"(",
"value",
")",
"{",
"if",
"(",
"typeOf",
"(",
"value",
")",
"===",
"'string'",
")",
"{",
"return",
"value",
".",
"length",
">",
"0",
";",
"}",
"else",
"{",
"return",
"typeOf",
"(",
"value",
")",
"!==",
"'undefined'",
"&&",
"typeOf",
"(",
"value",
")",
"!==",
"'nan'",
";",
"}",
"}"
]
| Checks if provided variable has value,
consider empty only if it's a string and has zero length, or it's NaN,
or it's `undefined` value, everything else consider a legit value
@param {mixed} value - string to check
@returns {boolean} - true is string is not empty, false otherwise | [
"Checks",
"if",
"provided",
"variable",
"has",
"value",
"consider",
"empty",
"only",
"if",
"it",
"s",
"a",
"string",
"and",
"has",
"zero",
"length",
"or",
"it",
"s",
"NaN",
"or",
"it",
"s",
"undefined",
"value",
"everything",
"else",
"consider",
"a",
"legit",
"value"
]
| 026423ba0e036cf8ca33cd2fd160df519715272d | https://github.com/alexindigo/configly/blob/026423ba0e036cf8ca33cd2fd160df519715272d/lib/has_value.js#L14-L21 |
44,295 | andrewdavey/vogue | src/client/vogue-client.js | watchAllStylesheets | function watchAllStylesheets() {
var href;
for (href in stylesheets) {
if (hop.call(stylesheets, href)) {
socket.emit("watch", {
href: href
});
}
}
} | javascript | function watchAllStylesheets() {
var href;
for (href in stylesheets) {
if (hop.call(stylesheets, href)) {
socket.emit("watch", {
href: href
});
}
}
} | [
"function",
"watchAllStylesheets",
"(",
")",
"{",
"var",
"href",
";",
"for",
"(",
"href",
"in",
"stylesheets",
")",
"{",
"if",
"(",
"hop",
".",
"call",
"(",
"stylesheets",
",",
"href",
")",
")",
"{",
"socket",
".",
"emit",
"(",
"\"watch\"",
",",
"{",
"href",
":",
"href",
"}",
")",
";",
"}",
"}",
"}"
]
| Watch for all available stylesheets. | [
"Watch",
"for",
"all",
"available",
"stylesheets",
"."
]
| 46e38b373c7a86bbbb15177822e1ea3ff1ecda6c | https://github.com/andrewdavey/vogue/blob/46e38b373c7a86bbbb15177822e1ea3ff1ecda6c/src/client/vogue-client.js#L15-L24 |
44,296 | andrewdavey/vogue | src/client/vogue-client.js | reloadStylesheet | function reloadStylesheet(href) {
var newHref = stylesheets[href].href +
(href.indexOf("?") >= 0 ? "&" : "?") +
"_vogue_nocache=" + (new Date).getTime(),
stylesheet;
// Check if the appropriate DOM Node is there.
if (!stylesheets[href].setAttribute) {
// Create the link.
stylesheet = document.createElement("link");
stylesheet.setAttribute("rel", "stylesheet");
stylesheet.setAttribute("href", newHref);
head.appendChild(stylesheet);
// Update the reference to the newly created link.
stylesheets[href] = stylesheet;
} else {
// Update the href to the new URL.
stylesheets[href].href = newHref;
}
} | javascript | function reloadStylesheet(href) {
var newHref = stylesheets[href].href +
(href.indexOf("?") >= 0 ? "&" : "?") +
"_vogue_nocache=" + (new Date).getTime(),
stylesheet;
// Check if the appropriate DOM Node is there.
if (!stylesheets[href].setAttribute) {
// Create the link.
stylesheet = document.createElement("link");
stylesheet.setAttribute("rel", "stylesheet");
stylesheet.setAttribute("href", newHref);
head.appendChild(stylesheet);
// Update the reference to the newly created link.
stylesheets[href] = stylesheet;
} else {
// Update the href to the new URL.
stylesheets[href].href = newHref;
}
} | [
"function",
"reloadStylesheet",
"(",
"href",
")",
"{",
"var",
"newHref",
"=",
"stylesheets",
"[",
"href",
"]",
".",
"href",
"+",
"(",
"href",
".",
"indexOf",
"(",
"\"?\"",
")",
">=",
"0",
"?",
"\"&\"",
":",
"\"?\"",
")",
"+",
"\"_vogue_nocache=\"",
"+",
"(",
"new",
"Date",
")",
".",
"getTime",
"(",
")",
",",
"stylesheet",
";",
"// Check if the appropriate DOM Node is there.",
"if",
"(",
"!",
"stylesheets",
"[",
"href",
"]",
".",
"setAttribute",
")",
"{",
"// Create the link.",
"stylesheet",
"=",
"document",
".",
"createElement",
"(",
"\"link\"",
")",
";",
"stylesheet",
".",
"setAttribute",
"(",
"\"rel\"",
",",
"\"stylesheet\"",
")",
";",
"stylesheet",
".",
"setAttribute",
"(",
"\"href\"",
",",
"newHref",
")",
";",
"head",
".",
"appendChild",
"(",
"stylesheet",
")",
";",
"// Update the reference to the newly created link.",
"stylesheets",
"[",
"href",
"]",
"=",
"stylesheet",
";",
"}",
"else",
"{",
"// Update the href to the new URL.",
"stylesheets",
"[",
"href",
"]",
".",
"href",
"=",
"newHref",
";",
"}",
"}"
]
| Reload a stylesheet.
@param {String} href The URL of the stylesheet to be reloaded. | [
"Reload",
"a",
"stylesheet",
"."
]
| 46e38b373c7a86bbbb15177822e1ea3ff1ecda6c | https://github.com/andrewdavey/vogue/blob/46e38b373c7a86bbbb15177822e1ea3ff1ecda6c/src/client/vogue-client.js#L31-L50 |
44,297 | andrewdavey/vogue | src/client/vogue-client.js | getLocalStylesheets | function getLocalStylesheets() {
/**
* Checks if the stylesheet is local.
*
* @param {Object} link The link to check for.
* @returns {Boolean}
*/
function isLocalStylesheet(link) {
var href, i, isExternal = true;
if (link.getAttribute("rel") !== "stylesheet") {
return false;
}
href = link.href;
for (i = 0; i < script.bases.length; i += 1) {
if (href.indexOf(script.bases[i]) > -1) {
isExternal = false;
break;
}
}
return !(isExternal && href.match(/^https?:/));
}
/**
* Checks if the stylesheet's media attribute is 'print'
*
* @param (Object) link The stylesheet element to check.
* @returns (Boolean)
*/
function isPrintStylesheet(link) {
return link.getAttribute("media") === "print";
}
/**
* Get the link's base URL.
*
* @param {String} href The URL to check.
* @returns {String|Boolean} The base URL, or false if no matches found.
*/
function getBase(href) {
var base, j;
for (j = 0; j < script.bases.length; j += 1) {
base = script.bases[j];
if (href.indexOf(base) > -1) {
return href.substr(base.length);
}
}
return false;
}
function getProperty(property) {
return this[property];
}
var stylesheets = {},
reImport = /@import\s+url\(["']?([^"'\)]+)["']?\)/g,
links = document.getElementsByTagName("link"),
link, href, matches, content, i, m;
// Go through all the links in the page, looking for stylesheets.
for (i = 0, m = links.length; i < m; i += 1) {
link = links[i];
if (isPrintStylesheet(link)) continue;
if (!isLocalStylesheet(link)) continue;
// Link is local, get the base URL.
href = getBase(link.href);
if (href !== false) {
stylesheets[href] = link;
}
}
// Go through all the style tags, looking for @import tags.
links = document.getElementsByTagName("style");
for (i = 0, m = links.length; i < m; i += 1) {
if (isPrintStylesheet(links[i])) continue;
content = links[i].text || links[i].textContent;
while ((matches = reImport.exec(content))) {
link = {
rel: "stylesheet",
href: matches[1],
getAttribute: getProperty
};
if (isLocalStylesheet(link)) {
// Link is local, get the base URL.
href = getBase(link.href);
if (href !== false) {
stylesheets[href] = link;
}
}
}
}
return stylesheets;
} | javascript | function getLocalStylesheets() {
/**
* Checks if the stylesheet is local.
*
* @param {Object} link The link to check for.
* @returns {Boolean}
*/
function isLocalStylesheet(link) {
var href, i, isExternal = true;
if (link.getAttribute("rel") !== "stylesheet") {
return false;
}
href = link.href;
for (i = 0; i < script.bases.length; i += 1) {
if (href.indexOf(script.bases[i]) > -1) {
isExternal = false;
break;
}
}
return !(isExternal && href.match(/^https?:/));
}
/**
* Checks if the stylesheet's media attribute is 'print'
*
* @param (Object) link The stylesheet element to check.
* @returns (Boolean)
*/
function isPrintStylesheet(link) {
return link.getAttribute("media") === "print";
}
/**
* Get the link's base URL.
*
* @param {String} href The URL to check.
* @returns {String|Boolean} The base URL, or false if no matches found.
*/
function getBase(href) {
var base, j;
for (j = 0; j < script.bases.length; j += 1) {
base = script.bases[j];
if (href.indexOf(base) > -1) {
return href.substr(base.length);
}
}
return false;
}
function getProperty(property) {
return this[property];
}
var stylesheets = {},
reImport = /@import\s+url\(["']?([^"'\)]+)["']?\)/g,
links = document.getElementsByTagName("link"),
link, href, matches, content, i, m;
// Go through all the links in the page, looking for stylesheets.
for (i = 0, m = links.length; i < m; i += 1) {
link = links[i];
if (isPrintStylesheet(link)) continue;
if (!isLocalStylesheet(link)) continue;
// Link is local, get the base URL.
href = getBase(link.href);
if (href !== false) {
stylesheets[href] = link;
}
}
// Go through all the style tags, looking for @import tags.
links = document.getElementsByTagName("style");
for (i = 0, m = links.length; i < m; i += 1) {
if (isPrintStylesheet(links[i])) continue;
content = links[i].text || links[i].textContent;
while ((matches = reImport.exec(content))) {
link = {
rel: "stylesheet",
href: matches[1],
getAttribute: getProperty
};
if (isLocalStylesheet(link)) {
// Link is local, get the base URL.
href = getBase(link.href);
if (href !== false) {
stylesheets[href] = link;
}
}
}
}
return stylesheets;
} | [
"function",
"getLocalStylesheets",
"(",
")",
"{",
"/**\n * Checks if the stylesheet is local.\n *\n * @param {Object} link The link to check for.\n * @returns {Boolean}\n */",
"function",
"isLocalStylesheet",
"(",
"link",
")",
"{",
"var",
"href",
",",
"i",
",",
"isExternal",
"=",
"true",
";",
"if",
"(",
"link",
".",
"getAttribute",
"(",
"\"rel\"",
")",
"!==",
"\"stylesheet\"",
")",
"{",
"return",
"false",
";",
"}",
"href",
"=",
"link",
".",
"href",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"script",
".",
"bases",
".",
"length",
";",
"i",
"+=",
"1",
")",
"{",
"if",
"(",
"href",
".",
"indexOf",
"(",
"script",
".",
"bases",
"[",
"i",
"]",
")",
">",
"-",
"1",
")",
"{",
"isExternal",
"=",
"false",
";",
"break",
";",
"}",
"}",
"return",
"!",
"(",
"isExternal",
"&&",
"href",
".",
"match",
"(",
"/",
"^https?:",
"/",
")",
")",
";",
"}",
"/**\n * Checks if the stylesheet's media attribute is 'print'\n *\n * @param (Object) link The stylesheet element to check.\n * @returns (Boolean)\n */",
"function",
"isPrintStylesheet",
"(",
"link",
")",
"{",
"return",
"link",
".",
"getAttribute",
"(",
"\"media\"",
")",
"===",
"\"print\"",
";",
"}",
"/**\n * Get the link's base URL.\n *\n * @param {String} href The URL to check.\n * @returns {String|Boolean} The base URL, or false if no matches found.\n */",
"function",
"getBase",
"(",
"href",
")",
"{",
"var",
"base",
",",
"j",
";",
"for",
"(",
"j",
"=",
"0",
";",
"j",
"<",
"script",
".",
"bases",
".",
"length",
";",
"j",
"+=",
"1",
")",
"{",
"base",
"=",
"script",
".",
"bases",
"[",
"j",
"]",
";",
"if",
"(",
"href",
".",
"indexOf",
"(",
"base",
")",
">",
"-",
"1",
")",
"{",
"return",
"href",
".",
"substr",
"(",
"base",
".",
"length",
")",
";",
"}",
"}",
"return",
"false",
";",
"}",
"function",
"getProperty",
"(",
"property",
")",
"{",
"return",
"this",
"[",
"property",
"]",
";",
"}",
"var",
"stylesheets",
"=",
"{",
"}",
",",
"reImport",
"=",
"/",
"@import\\s+url\\([\"']?([^\"'\\)]+)[\"']?\\)",
"/",
"g",
",",
"links",
"=",
"document",
".",
"getElementsByTagName",
"(",
"\"link\"",
")",
",",
"link",
",",
"href",
",",
"matches",
",",
"content",
",",
"i",
",",
"m",
";",
"// Go through all the links in the page, looking for stylesheets.",
"for",
"(",
"i",
"=",
"0",
",",
"m",
"=",
"links",
".",
"length",
";",
"i",
"<",
"m",
";",
"i",
"+=",
"1",
")",
"{",
"link",
"=",
"links",
"[",
"i",
"]",
";",
"if",
"(",
"isPrintStylesheet",
"(",
"link",
")",
")",
"continue",
";",
"if",
"(",
"!",
"isLocalStylesheet",
"(",
"link",
")",
")",
"continue",
";",
"// Link is local, get the base URL.",
"href",
"=",
"getBase",
"(",
"link",
".",
"href",
")",
";",
"if",
"(",
"href",
"!==",
"false",
")",
"{",
"stylesheets",
"[",
"href",
"]",
"=",
"link",
";",
"}",
"}",
"// Go through all the style tags, looking for @import tags.",
"links",
"=",
"document",
".",
"getElementsByTagName",
"(",
"\"style\"",
")",
";",
"for",
"(",
"i",
"=",
"0",
",",
"m",
"=",
"links",
".",
"length",
";",
"i",
"<",
"m",
";",
"i",
"+=",
"1",
")",
"{",
"if",
"(",
"isPrintStylesheet",
"(",
"links",
"[",
"i",
"]",
")",
")",
"continue",
";",
"content",
"=",
"links",
"[",
"i",
"]",
".",
"text",
"||",
"links",
"[",
"i",
"]",
".",
"textContent",
";",
"while",
"(",
"(",
"matches",
"=",
"reImport",
".",
"exec",
"(",
"content",
")",
")",
")",
"{",
"link",
"=",
"{",
"rel",
":",
"\"stylesheet\"",
",",
"href",
":",
"matches",
"[",
"1",
"]",
",",
"getAttribute",
":",
"getProperty",
"}",
";",
"if",
"(",
"isLocalStylesheet",
"(",
"link",
")",
")",
"{",
"// Link is local, get the base URL.",
"href",
"=",
"getBase",
"(",
"link",
".",
"href",
")",
";",
"if",
"(",
"href",
"!==",
"false",
")",
"{",
"stylesheets",
"[",
"href",
"]",
"=",
"link",
";",
"}",
"}",
"}",
"}",
"return",
"stylesheets",
";",
"}"
]
| Fetch all the local stylesheets from the page.
@returns {Object} The list of local stylesheets keyed by their base URL. | [
"Fetch",
"all",
"the",
"local",
"stylesheets",
"from",
"the",
"page",
"."
]
| 46e38b373c7a86bbbb15177822e1ea3ff1ecda6c | https://github.com/andrewdavey/vogue/blob/46e38b373c7a86bbbb15177822e1ea3ff1ecda6c/src/client/vogue-client.js#L68-L162 |
44,298 | andrewdavey/vogue | src/client/vogue-client.js | isLocalStylesheet | function isLocalStylesheet(link) {
var href, i, isExternal = true;
if (link.getAttribute("rel") !== "stylesheet") {
return false;
}
href = link.href;
for (i = 0; i < script.bases.length; i += 1) {
if (href.indexOf(script.bases[i]) > -1) {
isExternal = false;
break;
}
}
return !(isExternal && href.match(/^https?:/));
} | javascript | function isLocalStylesheet(link) {
var href, i, isExternal = true;
if (link.getAttribute("rel") !== "stylesheet") {
return false;
}
href = link.href;
for (i = 0; i < script.bases.length; i += 1) {
if (href.indexOf(script.bases[i]) > -1) {
isExternal = false;
break;
}
}
return !(isExternal && href.match(/^https?:/));
} | [
"function",
"isLocalStylesheet",
"(",
"link",
")",
"{",
"var",
"href",
",",
"i",
",",
"isExternal",
"=",
"true",
";",
"if",
"(",
"link",
".",
"getAttribute",
"(",
"\"rel\"",
")",
"!==",
"\"stylesheet\"",
")",
"{",
"return",
"false",
";",
"}",
"href",
"=",
"link",
".",
"href",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"script",
".",
"bases",
".",
"length",
";",
"i",
"+=",
"1",
")",
"{",
"if",
"(",
"href",
".",
"indexOf",
"(",
"script",
".",
"bases",
"[",
"i",
"]",
")",
">",
"-",
"1",
")",
"{",
"isExternal",
"=",
"false",
";",
"break",
";",
"}",
"}",
"return",
"!",
"(",
"isExternal",
"&&",
"href",
".",
"match",
"(",
"/",
"^https?:",
"/",
")",
")",
";",
"}"
]
| Checks if the stylesheet is local.
@param {Object} link The link to check for.
@returns {Boolean} | [
"Checks",
"if",
"the",
"stylesheet",
"is",
"local",
"."
]
| 46e38b373c7a86bbbb15177822e1ea3ff1ecda6c | https://github.com/andrewdavey/vogue/blob/46e38b373c7a86bbbb15177822e1ea3ff1ecda6c/src/client/vogue-client.js#L76-L91 |
44,299 | andrewdavey/vogue | src/client/vogue-client.js | getBase | function getBase(href) {
var base, j;
for (j = 0; j < script.bases.length; j += 1) {
base = script.bases[j];
if (href.indexOf(base) > -1) {
return href.substr(base.length);
}
}
return false;
} | javascript | function getBase(href) {
var base, j;
for (j = 0; j < script.bases.length; j += 1) {
base = script.bases[j];
if (href.indexOf(base) > -1) {
return href.substr(base.length);
}
}
return false;
} | [
"function",
"getBase",
"(",
"href",
")",
"{",
"var",
"base",
",",
"j",
";",
"for",
"(",
"j",
"=",
"0",
";",
"j",
"<",
"script",
".",
"bases",
".",
"length",
";",
"j",
"+=",
"1",
")",
"{",
"base",
"=",
"script",
".",
"bases",
"[",
"j",
"]",
";",
"if",
"(",
"href",
".",
"indexOf",
"(",
"base",
")",
">",
"-",
"1",
")",
"{",
"return",
"href",
".",
"substr",
"(",
"base",
".",
"length",
")",
";",
"}",
"}",
"return",
"false",
";",
"}"
]
| Get the link's base URL.
@param {String} href The URL to check.
@returns {String|Boolean} The base URL, or false if no matches found. | [
"Get",
"the",
"link",
"s",
"base",
"URL",
"."
]
| 46e38b373c7a86bbbb15177822e1ea3ff1ecda6c | https://github.com/andrewdavey/vogue/blob/46e38b373c7a86bbbb15177822e1ea3ff1ecda6c/src/client/vogue-client.js#L109-L118 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.