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
|
---|---|---|---|---|---|---|---|---|---|---|---|
47,500 | saggiyogesh/nodeportal | public/ckeditor/_source/plugins/xml/plugin.js | function( xpath, contextNode )
{
var baseXml = this.baseXml;
if ( contextNode || ( contextNode = baseXml ) )
{
if ( CKEDITOR.env.ie || contextNode.selectSingleNode ) // IE
return contextNode.selectSingleNode( xpath );
else if ( baseXml.evaluate ) // Others
{
var result = baseXml.evaluate( xpath, contextNode, null, 9, null);
return ( result && result.singleNodeValue ) || null;
}
}
return null;
} | javascript | function( xpath, contextNode )
{
var baseXml = this.baseXml;
if ( contextNode || ( contextNode = baseXml ) )
{
if ( CKEDITOR.env.ie || contextNode.selectSingleNode ) // IE
return contextNode.selectSingleNode( xpath );
else if ( baseXml.evaluate ) // Others
{
var result = baseXml.evaluate( xpath, contextNode, null, 9, null);
return ( result && result.singleNodeValue ) || null;
}
}
return null;
} | [
"function",
"(",
"xpath",
",",
"contextNode",
")",
"{",
"var",
"baseXml",
"=",
"this",
".",
"baseXml",
";",
"if",
"(",
"contextNode",
"||",
"(",
"contextNode",
"=",
"baseXml",
")",
")",
"{",
"if",
"(",
"CKEDITOR",
".",
"env",
".",
"ie",
"||",
"contextNode",
".",
"selectSingleNode",
")",
"// IE\r",
"return",
"contextNode",
".",
"selectSingleNode",
"(",
"xpath",
")",
";",
"else",
"if",
"(",
"baseXml",
".",
"evaluate",
")",
"// Others\r",
"{",
"var",
"result",
"=",
"baseXml",
".",
"evaluate",
"(",
"xpath",
",",
"contextNode",
",",
"null",
",",
"9",
",",
"null",
")",
";",
"return",
"(",
"result",
"&&",
"result",
".",
"singleNodeValue",
")",
"||",
"null",
";",
"}",
"}",
"return",
"null",
";",
"}"
]
| Get a single node from the XML document, based on a XPath query.
@param {String} xpath The XPath query to execute.
@param {Object} [contextNode] The XML DOM node to be used as the context
for the XPath query. The document root is used by default.
@returns {Object} A XML node element or null if the query has no results.
@example
// Create the XML instance.
var xml = new CKEDITOR.xml( '<list><item id="test1" /><item id="test2" /></list>' );
// Get the first <item> node.
var itemNode = <b>xml.selectSingleNode( 'list/item' )</b>;
// Alert "item".
alert( itemNode.nodeName ); | [
"Get",
"a",
"single",
"node",
"from",
"the",
"XML",
"document",
"based",
"on",
"a",
"XPath",
"query",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/plugins/xml/plugin.js#L76-L92 |
|
47,501 | saggiyogesh/nodeportal | public/ckeditor/_source/plugins/xml/plugin.js | function( xpath, contextNode )
{
var baseXml = this.baseXml,
nodes = [];
if ( contextNode || ( contextNode = baseXml ) )
{
if ( CKEDITOR.env.ie || contextNode.selectNodes ) // IE
return contextNode.selectNodes( xpath );
else if ( baseXml.evaluate ) // Others
{
var result = baseXml.evaluate( xpath, contextNode, null, 5, null);
if ( result )
{
var node;
while ( ( node = result.iterateNext() ) )
nodes.push( node );
}
}
}
return nodes;
} | javascript | function( xpath, contextNode )
{
var baseXml = this.baseXml,
nodes = [];
if ( contextNode || ( contextNode = baseXml ) )
{
if ( CKEDITOR.env.ie || contextNode.selectNodes ) // IE
return contextNode.selectNodes( xpath );
else if ( baseXml.evaluate ) // Others
{
var result = baseXml.evaluate( xpath, contextNode, null, 5, null);
if ( result )
{
var node;
while ( ( node = result.iterateNext() ) )
nodes.push( node );
}
}
}
return nodes;
} | [
"function",
"(",
"xpath",
",",
"contextNode",
")",
"{",
"var",
"baseXml",
"=",
"this",
".",
"baseXml",
",",
"nodes",
"=",
"[",
"]",
";",
"if",
"(",
"contextNode",
"||",
"(",
"contextNode",
"=",
"baseXml",
")",
")",
"{",
"if",
"(",
"CKEDITOR",
".",
"env",
".",
"ie",
"||",
"contextNode",
".",
"selectNodes",
")",
"// IE\r",
"return",
"contextNode",
".",
"selectNodes",
"(",
"xpath",
")",
";",
"else",
"if",
"(",
"baseXml",
".",
"evaluate",
")",
"// Others\r",
"{",
"var",
"result",
"=",
"baseXml",
".",
"evaluate",
"(",
"xpath",
",",
"contextNode",
",",
"null",
",",
"5",
",",
"null",
")",
";",
"if",
"(",
"result",
")",
"{",
"var",
"node",
";",
"while",
"(",
"(",
"node",
"=",
"result",
".",
"iterateNext",
"(",
")",
")",
")",
"nodes",
".",
"push",
"(",
"node",
")",
";",
"}",
"}",
"}",
"return",
"nodes",
";",
"}"
]
| Gets a list node from the XML document, based on a XPath query.
@param {String} xpath The XPath query to execute.
@param {Object} [contextNode] The XML DOM node to be used as the context
for the XPath query. The document root is used by default.
@returns {ArrayLike} An array containing all matched nodes. The array will
be empty if the query has no results.
@example
// Create the XML instance.
var xml = new CKEDITOR.xml( '<list><item id="test1" /><item id="test2" /></list>' );
// Get the first <item> node.
var itemNodes = xml.selectSingleNode( 'list/item' );
// Alert "item" twice, one for each <item>.
for ( var i = 0 ; i < itemNodes.length ; i++ )
alert( itemNodes[i].nodeName ); | [
"Gets",
"a",
"list",
"node",
"from",
"the",
"XML",
"document",
"based",
"on",
"a",
"XPath",
"query",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/plugins/xml/plugin.js#L110-L133 |
|
47,502 | saggiyogesh/nodeportal | public/ckeditor/_source/plugins/xml/plugin.js | function( xpath, contextNode )
{
var node = this.selectSingleNode( xpath, contextNode ),
xml = [];
if ( node )
{
node = node.firstChild;
while ( node )
{
if ( node.xml ) // IE
xml.push( node.xml );
else if ( window.XMLSerializer ) // Others
xml.push( ( new XMLSerializer() ).serializeToString( node ) );
node = node.nextSibling;
}
}
return xml.length ? xml.join( '' ) : null;
} | javascript | function( xpath, contextNode )
{
var node = this.selectSingleNode( xpath, contextNode ),
xml = [];
if ( node )
{
node = node.firstChild;
while ( node )
{
if ( node.xml ) // IE
xml.push( node.xml );
else if ( window.XMLSerializer ) // Others
xml.push( ( new XMLSerializer() ).serializeToString( node ) );
node = node.nextSibling;
}
}
return xml.length ? xml.join( '' ) : null;
} | [
"function",
"(",
"xpath",
",",
"contextNode",
")",
"{",
"var",
"node",
"=",
"this",
".",
"selectSingleNode",
"(",
"xpath",
",",
"contextNode",
")",
",",
"xml",
"=",
"[",
"]",
";",
"if",
"(",
"node",
")",
"{",
"node",
"=",
"node",
".",
"firstChild",
";",
"while",
"(",
"node",
")",
"{",
"if",
"(",
"node",
".",
"xml",
")",
"// IE\r",
"xml",
".",
"push",
"(",
"node",
".",
"xml",
")",
";",
"else",
"if",
"(",
"window",
".",
"XMLSerializer",
")",
"// Others\r",
"xml",
".",
"push",
"(",
"(",
"new",
"XMLSerializer",
"(",
")",
")",
".",
"serializeToString",
"(",
"node",
")",
")",
";",
"node",
"=",
"node",
".",
"nextSibling",
";",
"}",
"}",
"return",
"xml",
".",
"length",
"?",
"xml",
".",
"join",
"(",
"''",
")",
":",
"null",
";",
"}"
]
| Gets the string representation of hte inner contents of a XML node,
based on a XPath query.
@param {String} xpath The XPath query to execute.
@param {Object} [contextNode] The XML DOM node to be used as the context
for the XPath query. The document root is used by default.
@returns {String} The textual representation of the inner contents of
the node or null if the query has no results.
@example
// Create the XML instance.
var xml = new CKEDITOR.xml( '<list><item id="test1" /><item id="test2" /></list>' );
// Alert "<item id="test1" /><item id="test2" />".
alert( xml.getInnerXml( 'list' ) ); | [
"Gets",
"the",
"string",
"representation",
"of",
"hte",
"inner",
"contents",
"of",
"a",
"XML",
"node",
"based",
"on",
"a",
"XPath",
"query",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/plugins/xml/plugin.js#L149-L168 |
|
47,503 | nodejitsu/npm-search-pagelet | httpsgc.js | request | function request(url, using, fn, disk) {
if ('function' === typeof using) {
disk = fn;
fn = using;
using = null;
}
if (!using) {
if (curl) using = 'curl';
else if (wget) using = 'wget';
else using = 'node';
}
debug('requesting '+ url +' using '+ using);
request[using + ( disk ? 'd' : '')](url, fn);
} | javascript | function request(url, using, fn, disk) {
if ('function' === typeof using) {
disk = fn;
fn = using;
using = null;
}
if (!using) {
if (curl) using = 'curl';
else if (wget) using = 'wget';
else using = 'node';
}
debug('requesting '+ url +' using '+ using);
request[using + ( disk ? 'd' : '')](url, fn);
} | [
"function",
"request",
"(",
"url",
",",
"using",
",",
"fn",
",",
"disk",
")",
"{",
"if",
"(",
"'function'",
"===",
"typeof",
"using",
")",
"{",
"disk",
"=",
"fn",
";",
"fn",
"=",
"using",
";",
"using",
"=",
"null",
";",
"}",
"if",
"(",
"!",
"using",
")",
"{",
"if",
"(",
"curl",
")",
"using",
"=",
"'curl'",
";",
"else",
"if",
"(",
"wget",
")",
"using",
"=",
"'wget'",
";",
"else",
"using",
"=",
"'node'",
";",
"}",
"debug",
"(",
"'requesting '",
"+",
"url",
"+",
"' using '",
"+",
"using",
")",
";",
"request",
"[",
"using",
"+",
"(",
"disk",
"?",
"'d'",
":",
"''",
")",
"]",
"(",
"url",
",",
"fn",
")",
";",
"}"
]
| Request a HTTP resource and return it's contents.
@param {String} url The HTTPS URL that we need to fetch.
@param {String} using Optionally force which fetch engine we should use.
@param {Function} fn Completion callback.
@param {Boolean} disk Store file to disk instead of streaming spawns.
@api private | [
"Request",
"a",
"HTTP",
"resource",
"and",
"return",
"it",
"s",
"contents",
"."
]
| a6086c627b69c36c0cf638dc994c25f3d9d5df72 | https://github.com/nodejitsu/npm-search-pagelet/blob/a6086c627b69c36c0cf638dc994c25f3d9d5df72/httpsgc.js#L40-L55 |
47,504 | lazd/PseudoClass | source/Class.js | extendThis | function extendThis() {
var i, ni, objects, object, prop;
objects = arguments;
for (i = 0, ni = objects.length; i < ni; i++) {
object = objects[i];
for (prop in object) {
this[prop] = object[prop];
}
}
return this;
} | javascript | function extendThis() {
var i, ni, objects, object, prop;
objects = arguments;
for (i = 0, ni = objects.length; i < ni; i++) {
object = objects[i];
for (prop in object) {
this[prop] = object[prop];
}
}
return this;
} | [
"function",
"extendThis",
"(",
")",
"{",
"var",
"i",
",",
"ni",
",",
"objects",
",",
"object",
",",
"prop",
";",
"objects",
"=",
"arguments",
";",
"for",
"(",
"i",
"=",
"0",
",",
"ni",
"=",
"objects",
".",
"length",
";",
"i",
"<",
"ni",
";",
"i",
"++",
")",
"{",
"object",
"=",
"objects",
"[",
"i",
"]",
";",
"for",
"(",
"prop",
"in",
"object",
")",
"{",
"this",
"[",
"prop",
"]",
"=",
"object",
"[",
"prop",
"]",
";",
"}",
"}",
"return",
"this",
";",
"}"
]
| Extend the current context by the passed objects | [
"Extend",
"the",
"current",
"context",
"by",
"the",
"passed",
"objects"
]
| 6cb3ac83d18b8782d3943b7461cc4ee0d8f6ce08 | https://github.com/lazd/PseudoClass/blob/6cb3ac83d18b8782d3943b7461cc4ee0d8f6ce08/source/Class.js#L40-L51 |
47,505 | lazd/PseudoClass | source/Class.js | defineAndInheritProperties | function defineAndInheritProperties(Component, properties) {
var constructor,
descriptor,
property,
propertyDescriptors,
propertyDescriptorHash,
propertyDescriptorQueue;
// Set properties
Component.properties = properties;
// Traverse the chain of constructors and gather all property descriptors
// Build a queue of property descriptors for combination
propertyDescriptorHash = {};
constructor = Component;
do {
if (constructor.properties) {
for (property in constructor.properties) {
propertyDescriptorQueue = propertyDescriptorHash[property] || (propertyDescriptorHash[property] = []);
propertyDescriptorQueue.unshift(constructor.properties[property]);
}
}
constructor = constructor.superConstructor;
}
while (constructor);
// Combine property descriptors, allowing overriding of individual properties
propertyDescriptors = {};
for (property in propertyDescriptorHash) {
descriptor = propertyDescriptors[property] = extendThis.apply({}, propertyDescriptorHash[property]);
// Allow setters to be strings
// An additional wrapping function is used to allow monkey-patching
// apply is used to handle cases where the setter is called directly
if (typeof descriptor.set === 'string') {
descriptor.set = makeApplier(descriptor.set);
}
if (typeof descriptor.get === 'string') {
descriptor.get = makeApplier(descriptor.get);
}
}
// Store option descriptors on the constructor
Component.properties = propertyDescriptors;
} | javascript | function defineAndInheritProperties(Component, properties) {
var constructor,
descriptor,
property,
propertyDescriptors,
propertyDescriptorHash,
propertyDescriptorQueue;
// Set properties
Component.properties = properties;
// Traverse the chain of constructors and gather all property descriptors
// Build a queue of property descriptors for combination
propertyDescriptorHash = {};
constructor = Component;
do {
if (constructor.properties) {
for (property in constructor.properties) {
propertyDescriptorQueue = propertyDescriptorHash[property] || (propertyDescriptorHash[property] = []);
propertyDescriptorQueue.unshift(constructor.properties[property]);
}
}
constructor = constructor.superConstructor;
}
while (constructor);
// Combine property descriptors, allowing overriding of individual properties
propertyDescriptors = {};
for (property in propertyDescriptorHash) {
descriptor = propertyDescriptors[property] = extendThis.apply({}, propertyDescriptorHash[property]);
// Allow setters to be strings
// An additional wrapping function is used to allow monkey-patching
// apply is used to handle cases where the setter is called directly
if (typeof descriptor.set === 'string') {
descriptor.set = makeApplier(descriptor.set);
}
if (typeof descriptor.get === 'string') {
descriptor.get = makeApplier(descriptor.get);
}
}
// Store option descriptors on the constructor
Component.properties = propertyDescriptors;
} | [
"function",
"defineAndInheritProperties",
"(",
"Component",
",",
"properties",
")",
"{",
"var",
"constructor",
",",
"descriptor",
",",
"property",
",",
"propertyDescriptors",
",",
"propertyDescriptorHash",
",",
"propertyDescriptorQueue",
";",
"// Set properties",
"Component",
".",
"properties",
"=",
"properties",
";",
"// Traverse the chain of constructors and gather all property descriptors",
"// Build a queue of property descriptors for combination",
"propertyDescriptorHash",
"=",
"{",
"}",
";",
"constructor",
"=",
"Component",
";",
"do",
"{",
"if",
"(",
"constructor",
".",
"properties",
")",
"{",
"for",
"(",
"property",
"in",
"constructor",
".",
"properties",
")",
"{",
"propertyDescriptorQueue",
"=",
"propertyDescriptorHash",
"[",
"property",
"]",
"||",
"(",
"propertyDescriptorHash",
"[",
"property",
"]",
"=",
"[",
"]",
")",
";",
"propertyDescriptorQueue",
".",
"unshift",
"(",
"constructor",
".",
"properties",
"[",
"property",
"]",
")",
";",
"}",
"}",
"constructor",
"=",
"constructor",
".",
"superConstructor",
";",
"}",
"while",
"(",
"constructor",
")",
";",
"// Combine property descriptors, allowing overriding of individual properties",
"propertyDescriptors",
"=",
"{",
"}",
";",
"for",
"(",
"property",
"in",
"propertyDescriptorHash",
")",
"{",
"descriptor",
"=",
"propertyDescriptors",
"[",
"property",
"]",
"=",
"extendThis",
".",
"apply",
"(",
"{",
"}",
",",
"propertyDescriptorHash",
"[",
"property",
"]",
")",
";",
"// Allow setters to be strings",
"// An additional wrapping function is used to allow monkey-patching",
"// apply is used to handle cases where the setter is called directly",
"if",
"(",
"typeof",
"descriptor",
".",
"set",
"===",
"'string'",
")",
"{",
"descriptor",
".",
"set",
"=",
"makeApplier",
"(",
"descriptor",
".",
"set",
")",
";",
"}",
"if",
"(",
"typeof",
"descriptor",
".",
"get",
"===",
"'string'",
")",
"{",
"descriptor",
".",
"get",
"=",
"makeApplier",
"(",
"descriptor",
".",
"get",
")",
";",
"}",
"}",
"// Store option descriptors on the constructor",
"Component",
".",
"properties",
"=",
"propertyDescriptors",
";",
"}"
]
| Merge and define properties | [
"Merge",
"and",
"define",
"properties"
]
| 6cb3ac83d18b8782d3943b7461cc4ee0d8f6ce08 | https://github.com/lazd/PseudoClass/blob/6cb3ac83d18b8782d3943b7461cc4ee0d8f6ce08/source/Class.js#L61-L105 |
47,506 | lazd/PseudoClass | source/Class.js | function(name, func, superPrototype) {
return function PseudoClass_setStaticSuper() {
// Store the old super
var previousSuper = this._super;
// Use the method from the superclass' prototype
// This strategy allows monkey patching (modification of superclass prototypes)
this._super = superPrototype[name];
// Call the actual function
var ret = func.apply(this, arguments);
// Restore the previous value of super
// This is required so that calls to methods that use _super within methods that use _super work
this._super = previousSuper;
return ret;
};
} | javascript | function(name, func, superPrototype) {
return function PseudoClass_setStaticSuper() {
// Store the old super
var previousSuper = this._super;
// Use the method from the superclass' prototype
// This strategy allows monkey patching (modification of superclass prototypes)
this._super = superPrototype[name];
// Call the actual function
var ret = func.apply(this, arguments);
// Restore the previous value of super
// This is required so that calls to methods that use _super within methods that use _super work
this._super = previousSuper;
return ret;
};
} | [
"function",
"(",
"name",
",",
"func",
",",
"superPrototype",
")",
"{",
"return",
"function",
"PseudoClass_setStaticSuper",
"(",
")",
"{",
"// Store the old super",
"var",
"previousSuper",
"=",
"this",
".",
"_super",
";",
"// Use the method from the superclass' prototype",
"// This strategy allows monkey patching (modification of superclass prototypes)",
"this",
".",
"_super",
"=",
"superPrototype",
"[",
"name",
"]",
";",
"// Call the actual function",
"var",
"ret",
"=",
"func",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"// Restore the previous value of super",
"// This is required so that calls to methods that use _super within methods that use _super work",
"this",
".",
"_super",
"=",
"previousSuper",
";",
"return",
"ret",
";",
"}",
";",
"}"
]
| Bind an overriding method such that it gets the overridden method as its first argument | [
"Bind",
"an",
"overriding",
"method",
"such",
"that",
"it",
"gets",
"the",
"overridden",
"method",
"as",
"its",
"first",
"argument"
]
| 6cb3ac83d18b8782d3943b7461cc4ee0d8f6ce08 | https://github.com/lazd/PseudoClass/blob/6cb3ac83d18b8782d3943b7461cc4ee0d8f6ce08/source/Class.js#L116-L134 |
|
47,507 | lazd/PseudoClass | source/Class.js | function(properties) {
// If a class-like object is passed as properties.extend, just call extend on it
if (properties && properties.extend)
return properties.extend.extend(properties);
// Otherwise, just create a new class with the passed properties
return PseudoClass.extend(properties);
} | javascript | function(properties) {
// If a class-like object is passed as properties.extend, just call extend on it
if (properties && properties.extend)
return properties.extend.extend(properties);
// Otherwise, just create a new class with the passed properties
return PseudoClass.extend(properties);
} | [
"function",
"(",
"properties",
")",
"{",
"// If a class-like object is passed as properties.extend, just call extend on it",
"if",
"(",
"properties",
"&&",
"properties",
".",
"extend",
")",
"return",
"properties",
".",
"extend",
".",
"extend",
"(",
"properties",
")",
";",
"// Otherwise, just create a new class with the passed properties",
"return",
"PseudoClass",
".",
"extend",
"(",
"properties",
")",
";",
"}"
]
| The base Class implementation acts as extend alias, with the exception that it can take properties.extend as the Class to extend | [
"The",
"base",
"Class",
"implementation",
"acts",
"as",
"extend",
"alias",
"with",
"the",
"exception",
"that",
"it",
"can",
"take",
"properties",
".",
"extend",
"as",
"the",
"Class",
"to",
"extend"
]
| 6cb3ac83d18b8782d3943b7461cc4ee0d8f6ce08 | https://github.com/lazd/PseudoClass/blob/6cb3ac83d18b8782d3943b7461cc4ee0d8f6ce08/source/Class.js#L187-L194 |
|
47,508 | EightMedia/discodip | lib/render.js | render | function render(q) {
if (!q.length) {
complete();
return;
}
const item = q.shift();
// render HTML file
fs.writeFile(`${item.file}.html`, item.html, err => {
if (err) throw err;
// if prerendering is enabled
if (typeof options.prerender === "object" && options.prerender !== null) {
// wait for response from browser
puppet.once("message", height => {
// store height
item.json.height = height;
// render JSON file
fs.writeFile(`${item.file}.json`, JSON.stringify(item.json), err => {
if (err) throw err;
process.send(`success::Generated ${item.name}`);
// render next
render(q);
});
});
// open html file in browser
puppet.send({
url: `http://localhost:${options.prerender.port}/${
options.prerender.path
}/${item.slug}.html`
});
// if no prerendering is to be done
} else {
// render JSON file
fs.writeFile(`${item.file}.json`, JSON.stringify(item.json), err => {
if (err) throw err;
process.send(`success::Generated ${item.name}`);
// render next
render(q);
});
}
});
} | javascript | function render(q) {
if (!q.length) {
complete();
return;
}
const item = q.shift();
// render HTML file
fs.writeFile(`${item.file}.html`, item.html, err => {
if (err) throw err;
// if prerendering is enabled
if (typeof options.prerender === "object" && options.prerender !== null) {
// wait for response from browser
puppet.once("message", height => {
// store height
item.json.height = height;
// render JSON file
fs.writeFile(`${item.file}.json`, JSON.stringify(item.json), err => {
if (err) throw err;
process.send(`success::Generated ${item.name}`);
// render next
render(q);
});
});
// open html file in browser
puppet.send({
url: `http://localhost:${options.prerender.port}/${
options.prerender.path
}/${item.slug}.html`
});
// if no prerendering is to be done
} else {
// render JSON file
fs.writeFile(`${item.file}.json`, JSON.stringify(item.json), err => {
if (err) throw err;
process.send(`success::Generated ${item.name}`);
// render next
render(q);
});
}
});
} | [
"function",
"render",
"(",
"q",
")",
"{",
"if",
"(",
"!",
"q",
".",
"length",
")",
"{",
"complete",
"(",
")",
";",
"return",
";",
"}",
"const",
"item",
"=",
"q",
".",
"shift",
"(",
")",
";",
"// render HTML file",
"fs",
".",
"writeFile",
"(",
"`",
"${",
"item",
".",
"file",
"}",
"`",
",",
"item",
".",
"html",
",",
"err",
"=>",
"{",
"if",
"(",
"err",
")",
"throw",
"err",
";",
"// if prerendering is enabled",
"if",
"(",
"typeof",
"options",
".",
"prerender",
"===",
"\"object\"",
"&&",
"options",
".",
"prerender",
"!==",
"null",
")",
"{",
"// wait for response from browser",
"puppet",
".",
"once",
"(",
"\"message\"",
",",
"height",
"=>",
"{",
"// store height",
"item",
".",
"json",
".",
"height",
"=",
"height",
";",
"// render JSON file",
"fs",
".",
"writeFile",
"(",
"`",
"${",
"item",
".",
"file",
"}",
"`",
",",
"JSON",
".",
"stringify",
"(",
"item",
".",
"json",
")",
",",
"err",
"=>",
"{",
"if",
"(",
"err",
")",
"throw",
"err",
";",
"process",
".",
"send",
"(",
"`",
"${",
"item",
".",
"name",
"}",
"`",
")",
";",
"// render next",
"render",
"(",
"q",
")",
";",
"}",
")",
";",
"}",
")",
";",
"// open html file in browser",
"puppet",
".",
"send",
"(",
"{",
"url",
":",
"`",
"${",
"options",
".",
"prerender",
".",
"port",
"}",
"${",
"options",
".",
"prerender",
".",
"path",
"}",
"${",
"item",
".",
"slug",
"}",
"`",
"}",
")",
";",
"// if no prerendering is to be done",
"}",
"else",
"{",
"// render JSON file",
"fs",
".",
"writeFile",
"(",
"`",
"${",
"item",
".",
"file",
"}",
"`",
",",
"JSON",
".",
"stringify",
"(",
"item",
".",
"json",
")",
",",
"err",
"=>",
"{",
"if",
"(",
"err",
")",
"throw",
"err",
";",
"process",
".",
"send",
"(",
"`",
"${",
"item",
".",
"name",
"}",
"`",
")",
";",
"// render next",
"render",
"(",
"q",
")",
";",
"}",
")",
";",
"}",
"}",
")",
";",
"}"
]
| Recursive render
generates component html file
and json file after that | [
"Recursive",
"render",
"generates",
"component",
"html",
"file",
"and",
"json",
"file",
"after",
"that"
]
| 9311bf6c7cb774c8663e40fed1c158dffe2690cb | https://github.com/EightMedia/discodip/blob/9311bf6c7cb774c8663e40fed1c158dffe2690cb/lib/render.js#L174-L222 |
47,509 | EightMedia/discodip | lib/render.js | complete | function complete() {
quit();
const deleteQueue = [];
fs.readdir(paths.output, (err, files) => {
if (files) {
// lookup array for quick search inside existing component names
const componentsLookup = components.map(item => {
return slugify(item.meta.name);
});
// loop over files
for (let i = 0, l = files.length; i < l; ++i) {
const file = files[i];
const ext = path.extname(file);
// ignore dot files
if (file.indexOf(".") === 0) {
continue;
}
// if json+html file isn't inside lookup, mark for deletion
if (componentsLookup.indexOf(path.basename(file, ext)) === -1) {
deleteQueue.push(file);
}
}
}
// remove file by passing shorter queue
function removeFile(q) {
if (!q.length) {
process.send(true);
return;
}
const file = q.shift();
rimraf(path.resolve(paths.output, file), { read: false }, () => {
removeFile(q);
});
}
removeFile(deleteQueue);
});
} | javascript | function complete() {
quit();
const deleteQueue = [];
fs.readdir(paths.output, (err, files) => {
if (files) {
// lookup array for quick search inside existing component names
const componentsLookup = components.map(item => {
return slugify(item.meta.name);
});
// loop over files
for (let i = 0, l = files.length; i < l; ++i) {
const file = files[i];
const ext = path.extname(file);
// ignore dot files
if (file.indexOf(".") === 0) {
continue;
}
// if json+html file isn't inside lookup, mark for deletion
if (componentsLookup.indexOf(path.basename(file, ext)) === -1) {
deleteQueue.push(file);
}
}
}
// remove file by passing shorter queue
function removeFile(q) {
if (!q.length) {
process.send(true);
return;
}
const file = q.shift();
rimraf(path.resolve(paths.output, file), { read: false }, () => {
removeFile(q);
});
}
removeFile(deleteQueue);
});
} | [
"function",
"complete",
"(",
")",
"{",
"quit",
"(",
")",
";",
"const",
"deleteQueue",
"=",
"[",
"]",
";",
"fs",
".",
"readdir",
"(",
"paths",
".",
"output",
",",
"(",
"err",
",",
"files",
")",
"=>",
"{",
"if",
"(",
"files",
")",
"{",
"// lookup array for quick search inside existing component names",
"const",
"componentsLookup",
"=",
"components",
".",
"map",
"(",
"item",
"=>",
"{",
"return",
"slugify",
"(",
"item",
".",
"meta",
".",
"name",
")",
";",
"}",
")",
";",
"// loop over files",
"for",
"(",
"let",
"i",
"=",
"0",
",",
"l",
"=",
"files",
".",
"length",
";",
"i",
"<",
"l",
";",
"++",
"i",
")",
"{",
"const",
"file",
"=",
"files",
"[",
"i",
"]",
";",
"const",
"ext",
"=",
"path",
".",
"extname",
"(",
"file",
")",
";",
"// ignore dot files",
"if",
"(",
"file",
".",
"indexOf",
"(",
"\".\"",
")",
"===",
"0",
")",
"{",
"continue",
";",
"}",
"// if json+html file isn't inside lookup, mark for deletion",
"if",
"(",
"componentsLookup",
".",
"indexOf",
"(",
"path",
".",
"basename",
"(",
"file",
",",
"ext",
")",
")",
"===",
"-",
"1",
")",
"{",
"deleteQueue",
".",
"push",
"(",
"file",
")",
";",
"}",
"}",
"}",
"// remove file by passing shorter queue",
"function",
"removeFile",
"(",
"q",
")",
"{",
"if",
"(",
"!",
"q",
".",
"length",
")",
"{",
"process",
".",
"send",
"(",
"true",
")",
";",
"return",
";",
"}",
"const",
"file",
"=",
"q",
".",
"shift",
"(",
")",
";",
"rimraf",
"(",
"path",
".",
"resolve",
"(",
"paths",
".",
"output",
",",
"file",
")",
",",
"{",
"read",
":",
"false",
"}",
",",
"(",
")",
"=>",
"{",
"removeFile",
"(",
"q",
")",
";",
"}",
")",
";",
"}",
"removeFile",
"(",
"deleteQueue",
")",
";",
"}",
")",
";",
"}"
]
| Clean up unused files and shut down | [
"Clean",
"up",
"unused",
"files",
"and",
"shut",
"down"
]
| 9311bf6c7cb774c8663e40fed1c158dffe2690cb | https://github.com/EightMedia/discodip/blob/9311bf6c7cb774c8663e40fed1c158dffe2690cb/lib/render.js#L228-L271 |
47,510 | EightMedia/discodip | lib/render.js | removeFile | function removeFile(q) {
if (!q.length) {
process.send(true);
return;
}
const file = q.shift();
rimraf(path.resolve(paths.output, file), { read: false }, () => {
removeFile(q);
});
} | javascript | function removeFile(q) {
if (!q.length) {
process.send(true);
return;
}
const file = q.shift();
rimraf(path.resolve(paths.output, file), { read: false }, () => {
removeFile(q);
});
} | [
"function",
"removeFile",
"(",
"q",
")",
"{",
"if",
"(",
"!",
"q",
".",
"length",
")",
"{",
"process",
".",
"send",
"(",
"true",
")",
";",
"return",
";",
"}",
"const",
"file",
"=",
"q",
".",
"shift",
"(",
")",
";",
"rimraf",
"(",
"path",
".",
"resolve",
"(",
"paths",
".",
"output",
",",
"file",
")",
",",
"{",
"read",
":",
"false",
"}",
",",
"(",
")",
"=>",
"{",
"removeFile",
"(",
"q",
")",
";",
"}",
")",
";",
"}"
]
| remove file by passing shorter queue | [
"remove",
"file",
"by",
"passing",
"shorter",
"queue"
]
| 9311bf6c7cb774c8663e40fed1c158dffe2690cb | https://github.com/EightMedia/discodip/blob/9311bf6c7cb774c8663e40fed1c158dffe2690cb/lib/render.js#L257-L267 |
47,511 | EightMedia/discodip | lib/render.js | slugify | function slugify(str) {
return str
.toString()
.toLowerCase()
.replace(/\s+/g, "-") // Replace spaces with -
.replace(/[^\w-]+/g, "") // Remove all non-word chars
.replace(/--+/g, "-") // Replace multiple - with single -
.replace(/^-+/, "") // Trim - from start of text
.replace(/-+$/, ""); // Trim - from end of text
} | javascript | function slugify(str) {
return str
.toString()
.toLowerCase()
.replace(/\s+/g, "-") // Replace spaces with -
.replace(/[^\w-]+/g, "") // Remove all non-word chars
.replace(/--+/g, "-") // Replace multiple - with single -
.replace(/^-+/, "") // Trim - from start of text
.replace(/-+$/, ""); // Trim - from end of text
} | [
"function",
"slugify",
"(",
"str",
")",
"{",
"return",
"str",
".",
"toString",
"(",
")",
".",
"toLowerCase",
"(",
")",
".",
"replace",
"(",
"/",
"\\s+",
"/",
"g",
",",
"\"-\"",
")",
"// Replace spaces with -",
".",
"replace",
"(",
"/",
"[^\\w-]+",
"/",
"g",
",",
"\"\"",
")",
"// Remove all non-word chars",
".",
"replace",
"(",
"/",
"--+",
"/",
"g",
",",
"\"-\"",
")",
"// Replace multiple - with single -",
".",
"replace",
"(",
"/",
"^-+",
"/",
",",
"\"\"",
")",
"// Trim - from start of text",
".",
"replace",
"(",
"/",
"-+$",
"/",
",",
"\"\"",
")",
";",
"// Trim - from end of text",
"}"
]
| Basic slugify function
Used to build the output filenames | [
"Basic",
"slugify",
"function",
"Used",
"to",
"build",
"the",
"output",
"filenames"
]
| 9311bf6c7cb774c8663e40fed1c158dffe2690cb | https://github.com/EightMedia/discodip/blob/9311bf6c7cb774c8663e40fed1c158dffe2690cb/lib/render.js#L278-L287 |
47,512 | saggiyogesh/nodeportal | lib/PageScript/index.js | PageScript | function PageScript(req) {
var codeList = [], bottomScriptList = [], cacheKey;
/**
* Add plugin load code. Called for each configured plugin on page.
* @param pluginOptions {Object} Plugin options object described in plugin properties
*/
this.addPluginLoad = function (pluginOptions) {
var pluginLoadJSCode = "Rocket.Plugin.onLoad(" + JSON.stringify(pluginOptions) + ")";
codeList.push({modules: PLUGIN_MODULE, code: pluginLoadJSCode});
};
/**
* Method adds the code & required modules
* @param modules {String} Comma separated list of modules, will be passed to require.js
* @param code {String} Client script Code
*/
this.add = function (modules, code) {
codeList.push({modules: modules, code: code});
};
/**
* Method used to include the code block passed to "BottomScript" mixin
* @param block {Function} jade mixin function
* @param opts {Object} locals or opts passed to "BottomScript" mixin
*/
this.addPageBottomCode = function (block, opts) {
opts.jade = jadeRuntime;
var func = new Function(_.keys(opts), "var jade_debug = [{filename: ''}]," +
" buf = [], jade_indent = [], jade_interp;" +
"(" + block + ")(); return buf.join('')");
bottomScriptList.push(func.apply(null, _.values(opts)).replace(/<[\/]{0,1}(script|SCRIPT)[^><]*>/g, "").trim());
};
/**
* Renders the scripts added or included in this object into html
* @param cb {Function} callback function - arguments - err, html
*/
this.render = function (cb) {
//if cache is configured, get cache key
if (ScriptsCache) {
var page = req.attrs.page;
cacheKey ||
(cacheKey = utils.replaceAll(req.url.replace(/\/$/, ""), "/", "_")+ "__" + page.pageId + "__" + req.session.user.userId);
}
/**
* Function renders html.
* @param callback {Function} callback function - arguments - err, html
*/
function renderHTML(callback) {
async.map(codeList, function (locals, n) {
locals.req = req;
ViewHelper.render({
cache: true,
path: SCRIPT_JADE
}, locals, n)
}, function (err, buf) {
if (!err) {
buf = buf || [];
buf.splice(0, 0, SCRIPT_START_TAG);
buf.push(bottomScriptList.join(""));
buf.push(SCRIPT_END_TAG);
}
callback(err, buf.join(""));
});
}
if (ScriptsCache) {
ScriptsCache.wrap(cacheKey, function (callback) {
renderHTML(callback)
}, cb);
}
else {
renderHTML(cb);
}
}
} | javascript | function PageScript(req) {
var codeList = [], bottomScriptList = [], cacheKey;
/**
* Add plugin load code. Called for each configured plugin on page.
* @param pluginOptions {Object} Plugin options object described in plugin properties
*/
this.addPluginLoad = function (pluginOptions) {
var pluginLoadJSCode = "Rocket.Plugin.onLoad(" + JSON.stringify(pluginOptions) + ")";
codeList.push({modules: PLUGIN_MODULE, code: pluginLoadJSCode});
};
/**
* Method adds the code & required modules
* @param modules {String} Comma separated list of modules, will be passed to require.js
* @param code {String} Client script Code
*/
this.add = function (modules, code) {
codeList.push({modules: modules, code: code});
};
/**
* Method used to include the code block passed to "BottomScript" mixin
* @param block {Function} jade mixin function
* @param opts {Object} locals or opts passed to "BottomScript" mixin
*/
this.addPageBottomCode = function (block, opts) {
opts.jade = jadeRuntime;
var func = new Function(_.keys(opts), "var jade_debug = [{filename: ''}]," +
" buf = [], jade_indent = [], jade_interp;" +
"(" + block + ")(); return buf.join('')");
bottomScriptList.push(func.apply(null, _.values(opts)).replace(/<[\/]{0,1}(script|SCRIPT)[^><]*>/g, "").trim());
};
/**
* Renders the scripts added or included in this object into html
* @param cb {Function} callback function - arguments - err, html
*/
this.render = function (cb) {
//if cache is configured, get cache key
if (ScriptsCache) {
var page = req.attrs.page;
cacheKey ||
(cacheKey = utils.replaceAll(req.url.replace(/\/$/, ""), "/", "_")+ "__" + page.pageId + "__" + req.session.user.userId);
}
/**
* Function renders html.
* @param callback {Function} callback function - arguments - err, html
*/
function renderHTML(callback) {
async.map(codeList, function (locals, n) {
locals.req = req;
ViewHelper.render({
cache: true,
path: SCRIPT_JADE
}, locals, n)
}, function (err, buf) {
if (!err) {
buf = buf || [];
buf.splice(0, 0, SCRIPT_START_TAG);
buf.push(bottomScriptList.join(""));
buf.push(SCRIPT_END_TAG);
}
callback(err, buf.join(""));
});
}
if (ScriptsCache) {
ScriptsCache.wrap(cacheKey, function (callback) {
renderHTML(callback)
}, cb);
}
else {
renderHTML(cb);
}
}
} | [
"function",
"PageScript",
"(",
"req",
")",
"{",
"var",
"codeList",
"=",
"[",
"]",
",",
"bottomScriptList",
"=",
"[",
"]",
",",
"cacheKey",
";",
"/**\n * Add plugin load code. Called for each configured plugin on page.\n * @param pluginOptions {Object} Plugin options object described in plugin properties\n */",
"this",
".",
"addPluginLoad",
"=",
"function",
"(",
"pluginOptions",
")",
"{",
"var",
"pluginLoadJSCode",
"=",
"\"Rocket.Plugin.onLoad(\"",
"+",
"JSON",
".",
"stringify",
"(",
"pluginOptions",
")",
"+",
"\")\"",
";",
"codeList",
".",
"push",
"(",
"{",
"modules",
":",
"PLUGIN_MODULE",
",",
"code",
":",
"pluginLoadJSCode",
"}",
")",
";",
"}",
";",
"/**\n * Method adds the code & required modules\n * @param modules {String} Comma separated list of modules, will be passed to require.js\n * @param code {String} Client script Code\n */",
"this",
".",
"add",
"=",
"function",
"(",
"modules",
",",
"code",
")",
"{",
"codeList",
".",
"push",
"(",
"{",
"modules",
":",
"modules",
",",
"code",
":",
"code",
"}",
")",
";",
"}",
";",
"/**\n * Method used to include the code block passed to \"BottomScript\" mixin\n * @param block {Function} jade mixin function\n * @param opts {Object} locals or opts passed to \"BottomScript\" mixin\n */",
"this",
".",
"addPageBottomCode",
"=",
"function",
"(",
"block",
",",
"opts",
")",
"{",
"opts",
".",
"jade",
"=",
"jadeRuntime",
";",
"var",
"func",
"=",
"new",
"Function",
"(",
"_",
".",
"keys",
"(",
"opts",
")",
",",
"\"var jade_debug = [{filename: ''}],\"",
"+",
"\" buf = [], jade_indent = [], jade_interp;\"",
"+",
"\"(\"",
"+",
"block",
"+",
"\")(); return buf.join('')\"",
")",
";",
"bottomScriptList",
".",
"push",
"(",
"func",
".",
"apply",
"(",
"null",
",",
"_",
".",
"values",
"(",
"opts",
")",
")",
".",
"replace",
"(",
"/",
"<[\\/]{0,1}(script|SCRIPT)[^><]*>",
"/",
"g",
",",
"\"\"",
")",
".",
"trim",
"(",
")",
")",
";",
"}",
";",
"/**\n * Renders the scripts added or included in this object into html\n * @param cb {Function} callback function - arguments - err, html\n */",
"this",
".",
"render",
"=",
"function",
"(",
"cb",
")",
"{",
"//if cache is configured, get cache key",
"if",
"(",
"ScriptsCache",
")",
"{",
"var",
"page",
"=",
"req",
".",
"attrs",
".",
"page",
";",
"cacheKey",
"||",
"(",
"cacheKey",
"=",
"utils",
".",
"replaceAll",
"(",
"req",
".",
"url",
".",
"replace",
"(",
"/",
"\\/$",
"/",
",",
"\"\"",
")",
",",
"\"/\"",
",",
"\"_\"",
")",
"+",
"\"__\"",
"+",
"page",
".",
"pageId",
"+",
"\"__\"",
"+",
"req",
".",
"session",
".",
"user",
".",
"userId",
")",
";",
"}",
"/**\n * Function renders html.\n * @param callback {Function} callback function - arguments - err, html\n */",
"function",
"renderHTML",
"(",
"callback",
")",
"{",
"async",
".",
"map",
"(",
"codeList",
",",
"function",
"(",
"locals",
",",
"n",
")",
"{",
"locals",
".",
"req",
"=",
"req",
";",
"ViewHelper",
".",
"render",
"(",
"{",
"cache",
":",
"true",
",",
"path",
":",
"SCRIPT_JADE",
"}",
",",
"locals",
",",
"n",
")",
"}",
",",
"function",
"(",
"err",
",",
"buf",
")",
"{",
"if",
"(",
"!",
"err",
")",
"{",
"buf",
"=",
"buf",
"||",
"[",
"]",
";",
"buf",
".",
"splice",
"(",
"0",
",",
"0",
",",
"SCRIPT_START_TAG",
")",
";",
"buf",
".",
"push",
"(",
"bottomScriptList",
".",
"join",
"(",
"\"\"",
")",
")",
";",
"buf",
".",
"push",
"(",
"SCRIPT_END_TAG",
")",
";",
"}",
"callback",
"(",
"err",
",",
"buf",
".",
"join",
"(",
"\"\"",
")",
")",
";",
"}",
")",
";",
"}",
"if",
"(",
"ScriptsCache",
")",
"{",
"ScriptsCache",
".",
"wrap",
"(",
"cacheKey",
",",
"function",
"(",
"callback",
")",
"{",
"renderHTML",
"(",
"callback",
")",
"}",
",",
"cb",
")",
";",
"}",
"else",
"{",
"renderHTML",
"(",
"cb",
")",
";",
"}",
"}",
"}"
]
| Constructor to create a PageScript object for each request.
Client js code added will be rendered at last in the html.
@param req {Object} Request object
@constructor | [
"Constructor",
"to",
"create",
"a",
"PageScript",
"object",
"for",
"each",
"request",
".",
"Client",
"js",
"code",
"added",
"will",
"be",
"rendered",
"at",
"last",
"in",
"the",
"html",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/lib/PageScript/index.js#L25-L104 |
47,513 | saggiyogesh/nodeportal | lib/PageScript/index.js | renderHTML | function renderHTML(callback) {
async.map(codeList, function (locals, n) {
locals.req = req;
ViewHelper.render({
cache: true,
path: SCRIPT_JADE
}, locals, n)
}, function (err, buf) {
if (!err) {
buf = buf || [];
buf.splice(0, 0, SCRIPT_START_TAG);
buf.push(bottomScriptList.join(""));
buf.push(SCRIPT_END_TAG);
}
callback(err, buf.join(""));
});
} | javascript | function renderHTML(callback) {
async.map(codeList, function (locals, n) {
locals.req = req;
ViewHelper.render({
cache: true,
path: SCRIPT_JADE
}, locals, n)
}, function (err, buf) {
if (!err) {
buf = buf || [];
buf.splice(0, 0, SCRIPT_START_TAG);
buf.push(bottomScriptList.join(""));
buf.push(SCRIPT_END_TAG);
}
callback(err, buf.join(""));
});
} | [
"function",
"renderHTML",
"(",
"callback",
")",
"{",
"async",
".",
"map",
"(",
"codeList",
",",
"function",
"(",
"locals",
",",
"n",
")",
"{",
"locals",
".",
"req",
"=",
"req",
";",
"ViewHelper",
".",
"render",
"(",
"{",
"cache",
":",
"true",
",",
"path",
":",
"SCRIPT_JADE",
"}",
",",
"locals",
",",
"n",
")",
"}",
",",
"function",
"(",
"err",
",",
"buf",
")",
"{",
"if",
"(",
"!",
"err",
")",
"{",
"buf",
"=",
"buf",
"||",
"[",
"]",
";",
"buf",
".",
"splice",
"(",
"0",
",",
"0",
",",
"SCRIPT_START_TAG",
")",
";",
"buf",
".",
"push",
"(",
"bottomScriptList",
".",
"join",
"(",
"\"\"",
")",
")",
";",
"buf",
".",
"push",
"(",
"SCRIPT_END_TAG",
")",
";",
"}",
"callback",
"(",
"err",
",",
"buf",
".",
"join",
"(",
"\"\"",
")",
")",
";",
"}",
")",
";",
"}"
]
| Function renders html.
@param callback {Function} callback function - arguments - err, html | [
"Function",
"renders",
"html",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/lib/PageScript/index.js#L76-L92 |
47,514 | boneskull/angular-autoselect | demo/demo.js | run | function run($templateCache) {
angular.forEach(examples, function (example) {
$templateCache.put(example.id + '-template', example.html);
$templateCache.put(example.id + '-description', example.description);
});
} | javascript | function run($templateCache) {
angular.forEach(examples, function (example) {
$templateCache.put(example.id + '-template', example.html);
$templateCache.put(example.id + '-description', example.description);
});
} | [
"function",
"run",
"(",
"$templateCache",
")",
"{",
"angular",
".",
"forEach",
"(",
"examples",
",",
"function",
"(",
"example",
")",
"{",
"$templateCache",
".",
"put",
"(",
"example",
".",
"id",
"+",
"'-template'",
",",
"example",
".",
"html",
")",
";",
"$templateCache",
".",
"put",
"(",
"example",
".",
"id",
"+",
"'-description'",
",",
"example",
".",
"description",
")",
";",
"}",
")",
";",
"}"
]
| Puts the templates into the template cache | [
"Puts",
"the",
"templates",
"into",
"the",
"template",
"cache"
]
| ebd8682012ae7d056470410ebecd3269babddd3a | https://github.com/boneskull/angular-autoselect/blob/ebd8682012ae7d056470410ebecd3269babddd3a/demo/demo.js#L44-L49 |
47,515 | boneskull/angular-autoselect | demo/demo.js | ExampleCtrl | function ExampleCtrl($scope, $timeout) {
var pomo_nonsense = 'The fallacy of disciplinary boundaries thematizes the figuralization of civil society.',
regex = /(of\s.+\sboundaries|eht)/;
$scope.reset = function reset() {
delete $scope.data.pomo_nonsense;
$timeout(function () {
$scope.data.pomo_nonsense = pomo_nonsense;
});
};
$scope.reverse = function reverse() {
var arr = Array.prototype.slice.call($scope.data.pomo_nonsense);
arr.reverse();
$scope.data.pomo_nonsense = arr.join('');
};
$scope.data = {
regex: regex,
pomo_nonsense: pomo_nonsense
};
} | javascript | function ExampleCtrl($scope, $timeout) {
var pomo_nonsense = 'The fallacy of disciplinary boundaries thematizes the figuralization of civil society.',
regex = /(of\s.+\sboundaries|eht)/;
$scope.reset = function reset() {
delete $scope.data.pomo_nonsense;
$timeout(function () {
$scope.data.pomo_nonsense = pomo_nonsense;
});
};
$scope.reverse = function reverse() {
var arr = Array.prototype.slice.call($scope.data.pomo_nonsense);
arr.reverse();
$scope.data.pomo_nonsense = arr.join('');
};
$scope.data = {
regex: regex,
pomo_nonsense: pomo_nonsense
};
} | [
"function",
"ExampleCtrl",
"(",
"$scope",
",",
"$timeout",
")",
"{",
"var",
"pomo_nonsense",
"=",
"'The fallacy of disciplinary boundaries thematizes the figuralization of civil society.'",
",",
"regex",
"=",
"/",
"(of\\s.+\\sboundaries|eht)",
"/",
";",
"$scope",
".",
"reset",
"=",
"function",
"reset",
"(",
")",
"{",
"delete",
"$scope",
".",
"data",
".",
"pomo_nonsense",
";",
"$timeout",
"(",
"function",
"(",
")",
"{",
"$scope",
".",
"data",
".",
"pomo_nonsense",
"=",
"pomo_nonsense",
";",
"}",
")",
";",
"}",
";",
"$scope",
".",
"reverse",
"=",
"function",
"reverse",
"(",
")",
"{",
"var",
"arr",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"$scope",
".",
"data",
".",
"pomo_nonsense",
")",
";",
"arr",
".",
"reverse",
"(",
")",
";",
"$scope",
".",
"data",
".",
"pomo_nonsense",
"=",
"arr",
".",
"join",
"(",
"''",
")",
";",
"}",
";",
"$scope",
".",
"data",
"=",
"{",
"regex",
":",
"regex",
",",
"pomo_nonsense",
":",
"pomo_nonsense",
"}",
";",
"}"
]
| Controls a singular example | [
"Controls",
"a",
"singular",
"example"
]
| ebd8682012ae7d056470410ebecd3269babddd3a | https://github.com/boneskull/angular-autoselect/blob/ebd8682012ae7d056470410ebecd3269babddd3a/demo/demo.js#L55-L76 |
47,516 | boneskull/angular-autoselect | demo/demo.js | MainCtrl | function MainCtrl($scope, $location) {
$scope.select = function select(id) {
$scope.selected = $scope.selected === id ? null : id;
$location.path('/' + id);
};
$scope.examples = examples;
$scope.select($location.path().substring(1) || examples[0].id);
} | javascript | function MainCtrl($scope, $location) {
$scope.select = function select(id) {
$scope.selected = $scope.selected === id ? null : id;
$location.path('/' + id);
};
$scope.examples = examples;
$scope.select($location.path().substring(1) || examples[0].id);
} | [
"function",
"MainCtrl",
"(",
"$scope",
",",
"$location",
")",
"{",
"$scope",
".",
"select",
"=",
"function",
"select",
"(",
"id",
")",
"{",
"$scope",
".",
"selected",
"=",
"$scope",
".",
"selected",
"===",
"id",
"?",
"null",
":",
"id",
";",
"$location",
".",
"path",
"(",
"'/'",
"+",
"id",
")",
";",
"}",
";",
"$scope",
".",
"examples",
"=",
"examples",
";",
"$scope",
".",
"select",
"(",
"$location",
".",
"path",
"(",
")",
".",
"substring",
"(",
"1",
")",
"||",
"examples",
"[",
"0",
"]",
".",
"id",
")",
";",
"}"
]
| Controls the example navigation | [
"Controls",
"the",
"example",
"navigation"
]
| ebd8682012ae7d056470410ebecd3269babddd3a | https://github.com/boneskull/angular-autoselect/blob/ebd8682012ae7d056470410ebecd3269babddd3a/demo/demo.js#L81-L91 |
47,517 | boneskull/angular-autoselect | demo/demo.js | code | function code($window) {
return {
restrict: 'E',
require: '?ngModel',
/**
*
* @param {$rootScope.Scope} scope Element Scope
* @param {angular.element} element AngularJS element
* @param {$compile.directive.Attributes} attrs AngularJS Attributes object
* @param {NgModelController} ngModel ngModel controller object
*/
link: function link(scope, element, attrs, ngModel) {
var pre;
if (!ngModel) {
return;
}
pre = element.wrap('<pre></pre>');
element.addClass(attrs.lang);
ngModel.$render = function $render() {
element.text(ngModel.$viewValue);
$window.hljs.highlightBlock(pre[0]);
};
}
};
} | javascript | function code($window) {
return {
restrict: 'E',
require: '?ngModel',
/**
*
* @param {$rootScope.Scope} scope Element Scope
* @param {angular.element} element AngularJS element
* @param {$compile.directive.Attributes} attrs AngularJS Attributes object
* @param {NgModelController} ngModel ngModel controller object
*/
link: function link(scope, element, attrs, ngModel) {
var pre;
if (!ngModel) {
return;
}
pre = element.wrap('<pre></pre>');
element.addClass(attrs.lang);
ngModel.$render = function $render() {
element.text(ngModel.$viewValue);
$window.hljs.highlightBlock(pre[0]);
};
}
};
} | [
"function",
"code",
"(",
"$window",
")",
"{",
"return",
"{",
"restrict",
":",
"'E'",
",",
"require",
":",
"'?ngModel'",
",",
"/**\n *\n * @param {$rootScope.Scope} scope Element Scope\n * @param {angular.element} element AngularJS element\n * @param {$compile.directive.Attributes} attrs AngularJS Attributes object\n * @param {NgModelController} ngModel ngModel controller object\n */",
"link",
":",
"function",
"link",
"(",
"scope",
",",
"element",
",",
"attrs",
",",
"ngModel",
")",
"{",
"var",
"pre",
";",
"if",
"(",
"!",
"ngModel",
")",
"{",
"return",
";",
"}",
"pre",
"=",
"element",
".",
"wrap",
"(",
"'<pre></pre>'",
")",
";",
"element",
".",
"addClass",
"(",
"attrs",
".",
"lang",
")",
";",
"ngModel",
".",
"$render",
"=",
"function",
"$render",
"(",
")",
"{",
"element",
".",
"text",
"(",
"ngModel",
".",
"$viewValue",
")",
";",
"$window",
".",
"hljs",
".",
"highlightBlock",
"(",
"pre",
"[",
"0",
"]",
")",
";",
"}",
";",
"}",
"}",
";",
"}"
]
| Renders source code with highlight.js
@example
$scope.foo = "var bar = 'baz';";
// <source ng-model="foo" lang="js"></source> | [
"Renders",
"source",
"code",
"with",
"highlight",
".",
"js"
]
| ebd8682012ae7d056470410ebecd3269babddd3a | https://github.com/boneskull/angular-autoselect/blob/ebd8682012ae7d056470410ebecd3269babddd3a/demo/demo.js#L100-L127 |
47,518 | levilindsey/physx | src/collisions/src/collision-utils.js | detectIntersection | function detectIntersection(a, b) {
if (a instanceof Sphere) {
if (b instanceof Sphere) {
return sphereCollisionDetection.sphereVsSphere(a, b);
} else if (b instanceof Aabb) {
return sphereCollisionDetection.sphereVsAabb(a, b);
} else if (b instanceof Capsule) {
return sphereCollisionDetection.sphereVsCapsule(a, b);
} else if (b instanceof Obb) {
return sphereCollisionDetection.sphereVsObb(a, b);
} else {
return sphereCollisionDetection.sphereVsPoint(a, b);
}
} else if (a instanceof Aabb) {
if (b instanceof Sphere) {
return aabbCollisionDetection.aabbVsSphere(a, b);
} else if (b instanceof Aabb) {
return aabbCollisionDetection.aabbVsAabb(a, b);
} else if (b instanceof Capsule) {
return aabbCollisionDetection.aabbVsCapsule(a, b);
} else if (b instanceof Obb) {
return aabbCollisionDetection.aabbVsObb(a, b);
} else {
return aabbCollisionDetection.aabbVsPoint(a, b);
}
} else if (a instanceof Capsule) {
if (b instanceof Sphere) {
return capsuleCollisionDetection.capsuleVsSphere(a, b);
} else if (b instanceof Aabb) {
return capsuleCollisionDetection.capsuleVsAabb(a, b);
} else if (b instanceof Capsule) {
return capsuleCollisionDetection.capsuleVsCapsule(a, b);
} else if (b instanceof Obb) {
return capsuleCollisionDetection.capsuleVsObb(a, b);
} else {
return capsuleCollisionDetection.capsuleVsPoint(a, b);
}
} else if (a instanceof Obb) {
if (b instanceof Sphere) {
return obbCollisionDetection.obbVsSphere(a, b);
} else if (b instanceof Aabb) {
return obbCollisionDetection.obbVsAabb(a, b);
} else if (b instanceof Capsule) {
return obbCollisionDetection.obbVsCapsule(a, b);
} else if (b instanceof Obb) {
return obbCollisionDetection.obbVsObb(a, b);
} else {
return obbCollisionDetection.obbVsPoint(a, b);
}
} else {
if (b instanceof Sphere) {
return sphereCollisionDetection.sphereVsPoint(b, a);
} else if (b instanceof Aabb) {
return aabbCollisionDetection.aabbVsPoint(b, a);
} else if (b instanceof Capsule) {
return capsuleCollisionDetection.capsuleVsPoint(b, a);
} else if (b instanceof Obb) {
return obbCollisionDetection.obbVsPoint(b, a);
} else {
return false;
}
}
} | javascript | function detectIntersection(a, b) {
if (a instanceof Sphere) {
if (b instanceof Sphere) {
return sphereCollisionDetection.sphereVsSphere(a, b);
} else if (b instanceof Aabb) {
return sphereCollisionDetection.sphereVsAabb(a, b);
} else if (b instanceof Capsule) {
return sphereCollisionDetection.sphereVsCapsule(a, b);
} else if (b instanceof Obb) {
return sphereCollisionDetection.sphereVsObb(a, b);
} else {
return sphereCollisionDetection.sphereVsPoint(a, b);
}
} else if (a instanceof Aabb) {
if (b instanceof Sphere) {
return aabbCollisionDetection.aabbVsSphere(a, b);
} else if (b instanceof Aabb) {
return aabbCollisionDetection.aabbVsAabb(a, b);
} else if (b instanceof Capsule) {
return aabbCollisionDetection.aabbVsCapsule(a, b);
} else if (b instanceof Obb) {
return aabbCollisionDetection.aabbVsObb(a, b);
} else {
return aabbCollisionDetection.aabbVsPoint(a, b);
}
} else if (a instanceof Capsule) {
if (b instanceof Sphere) {
return capsuleCollisionDetection.capsuleVsSphere(a, b);
} else if (b instanceof Aabb) {
return capsuleCollisionDetection.capsuleVsAabb(a, b);
} else if (b instanceof Capsule) {
return capsuleCollisionDetection.capsuleVsCapsule(a, b);
} else if (b instanceof Obb) {
return capsuleCollisionDetection.capsuleVsObb(a, b);
} else {
return capsuleCollisionDetection.capsuleVsPoint(a, b);
}
} else if (a instanceof Obb) {
if (b instanceof Sphere) {
return obbCollisionDetection.obbVsSphere(a, b);
} else if (b instanceof Aabb) {
return obbCollisionDetection.obbVsAabb(a, b);
} else if (b instanceof Capsule) {
return obbCollisionDetection.obbVsCapsule(a, b);
} else if (b instanceof Obb) {
return obbCollisionDetection.obbVsObb(a, b);
} else {
return obbCollisionDetection.obbVsPoint(a, b);
}
} else {
if (b instanceof Sphere) {
return sphereCollisionDetection.sphereVsPoint(b, a);
} else if (b instanceof Aabb) {
return aabbCollisionDetection.aabbVsPoint(b, a);
} else if (b instanceof Capsule) {
return capsuleCollisionDetection.capsuleVsPoint(b, a);
} else if (b instanceof Obb) {
return obbCollisionDetection.obbVsPoint(b, a);
} else {
return false;
}
}
} | [
"function",
"detectIntersection",
"(",
"a",
",",
"b",
")",
"{",
"if",
"(",
"a",
"instanceof",
"Sphere",
")",
"{",
"if",
"(",
"b",
"instanceof",
"Sphere",
")",
"{",
"return",
"sphereCollisionDetection",
".",
"sphereVsSphere",
"(",
"a",
",",
"b",
")",
";",
"}",
"else",
"if",
"(",
"b",
"instanceof",
"Aabb",
")",
"{",
"return",
"sphereCollisionDetection",
".",
"sphereVsAabb",
"(",
"a",
",",
"b",
")",
";",
"}",
"else",
"if",
"(",
"b",
"instanceof",
"Capsule",
")",
"{",
"return",
"sphereCollisionDetection",
".",
"sphereVsCapsule",
"(",
"a",
",",
"b",
")",
";",
"}",
"else",
"if",
"(",
"b",
"instanceof",
"Obb",
")",
"{",
"return",
"sphereCollisionDetection",
".",
"sphereVsObb",
"(",
"a",
",",
"b",
")",
";",
"}",
"else",
"{",
"return",
"sphereCollisionDetection",
".",
"sphereVsPoint",
"(",
"a",
",",
"b",
")",
";",
"}",
"}",
"else",
"if",
"(",
"a",
"instanceof",
"Aabb",
")",
"{",
"if",
"(",
"b",
"instanceof",
"Sphere",
")",
"{",
"return",
"aabbCollisionDetection",
".",
"aabbVsSphere",
"(",
"a",
",",
"b",
")",
";",
"}",
"else",
"if",
"(",
"b",
"instanceof",
"Aabb",
")",
"{",
"return",
"aabbCollisionDetection",
".",
"aabbVsAabb",
"(",
"a",
",",
"b",
")",
";",
"}",
"else",
"if",
"(",
"b",
"instanceof",
"Capsule",
")",
"{",
"return",
"aabbCollisionDetection",
".",
"aabbVsCapsule",
"(",
"a",
",",
"b",
")",
";",
"}",
"else",
"if",
"(",
"b",
"instanceof",
"Obb",
")",
"{",
"return",
"aabbCollisionDetection",
".",
"aabbVsObb",
"(",
"a",
",",
"b",
")",
";",
"}",
"else",
"{",
"return",
"aabbCollisionDetection",
".",
"aabbVsPoint",
"(",
"a",
",",
"b",
")",
";",
"}",
"}",
"else",
"if",
"(",
"a",
"instanceof",
"Capsule",
")",
"{",
"if",
"(",
"b",
"instanceof",
"Sphere",
")",
"{",
"return",
"capsuleCollisionDetection",
".",
"capsuleVsSphere",
"(",
"a",
",",
"b",
")",
";",
"}",
"else",
"if",
"(",
"b",
"instanceof",
"Aabb",
")",
"{",
"return",
"capsuleCollisionDetection",
".",
"capsuleVsAabb",
"(",
"a",
",",
"b",
")",
";",
"}",
"else",
"if",
"(",
"b",
"instanceof",
"Capsule",
")",
"{",
"return",
"capsuleCollisionDetection",
".",
"capsuleVsCapsule",
"(",
"a",
",",
"b",
")",
";",
"}",
"else",
"if",
"(",
"b",
"instanceof",
"Obb",
")",
"{",
"return",
"capsuleCollisionDetection",
".",
"capsuleVsObb",
"(",
"a",
",",
"b",
")",
";",
"}",
"else",
"{",
"return",
"capsuleCollisionDetection",
".",
"capsuleVsPoint",
"(",
"a",
",",
"b",
")",
";",
"}",
"}",
"else",
"if",
"(",
"a",
"instanceof",
"Obb",
")",
"{",
"if",
"(",
"b",
"instanceof",
"Sphere",
")",
"{",
"return",
"obbCollisionDetection",
".",
"obbVsSphere",
"(",
"a",
",",
"b",
")",
";",
"}",
"else",
"if",
"(",
"b",
"instanceof",
"Aabb",
")",
"{",
"return",
"obbCollisionDetection",
".",
"obbVsAabb",
"(",
"a",
",",
"b",
")",
";",
"}",
"else",
"if",
"(",
"b",
"instanceof",
"Capsule",
")",
"{",
"return",
"obbCollisionDetection",
".",
"obbVsCapsule",
"(",
"a",
",",
"b",
")",
";",
"}",
"else",
"if",
"(",
"b",
"instanceof",
"Obb",
")",
"{",
"return",
"obbCollisionDetection",
".",
"obbVsObb",
"(",
"a",
",",
"b",
")",
";",
"}",
"else",
"{",
"return",
"obbCollisionDetection",
".",
"obbVsPoint",
"(",
"a",
",",
"b",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"b",
"instanceof",
"Sphere",
")",
"{",
"return",
"sphereCollisionDetection",
".",
"sphereVsPoint",
"(",
"b",
",",
"a",
")",
";",
"}",
"else",
"if",
"(",
"b",
"instanceof",
"Aabb",
")",
"{",
"return",
"aabbCollisionDetection",
".",
"aabbVsPoint",
"(",
"b",
",",
"a",
")",
";",
"}",
"else",
"if",
"(",
"b",
"instanceof",
"Capsule",
")",
"{",
"return",
"capsuleCollisionDetection",
".",
"capsuleVsPoint",
"(",
"b",
",",
"a",
")",
";",
"}",
"else",
"if",
"(",
"b",
"instanceof",
"Obb",
")",
"{",
"return",
"obbCollisionDetection",
".",
"obbVsPoint",
"(",
"b",
",",
"a",
")",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"}"
]
| This module defines a collection of static utility functions for detecting and responding to
collisions.
@param {Collidable} a
@param {Collidable} b
@returns {boolean} | [
"This",
"module",
"defines",
"a",
"collection",
"of",
"static",
"utility",
"functions",
"for",
"detecting",
"and",
"responding",
"to",
"collisions",
"."
]
| 62df9f6968082ed34aa784a23f3db6c8feca6f3a | https://github.com/levilindsey/physx/blob/62df9f6968082ed34aa784a23f3db6c8feca6f3a/src/collisions/src/collision-utils.js#L32-L94 |
47,519 | psastras/swagger2aglio | index.js | convert | function convert(program, callback) {
// define no-op callback
if (!callback) {
callback = function (err, blueprint) { }
}
// Read in the file
refparser.parse(program.input, function (err, schema) {
if (err) isMain ? halt(err) : callback(err);
// Read in aglio options
var options = {
themeTemplate: (program.themeTemplate === 'triple' || program.themeTemplate === 'index' || !program.themeTemplate) ?
path.resolve(__dirname, 'templates/' + (program.themeTemplate || 'index') + '.jade') :
themeTemplate,
themeVariables: program.themeVariables,
themeFullWidth: program.themeFullWidth,
noThemeCondense: program.noThemeCondense,
themeStyle: program.themeStyle,
locals: {
livePreview: program.server,
host: ((schema.schemes && schema.schemes.length > 0 && schema.host) ?
(schema.schemes[0] || 'https')
: 'https')
+ '://' + schema.host + (schema.basePath || '')
}
};
swag2blue.run({ '_': [program.input] }, function (err, blueprint) {
if (err) isMain ? halt(err) : callback(err);
aglio.render(blueprint, options, function (err, html, warnings) {
if (err) isMain ? halt(err) : callback(err);
// If we had warnings and not outputting to console, print them out and continue.
if (warnings && !program.output && isMain) {
warn('Encountered ' + warnings.length + ' warnings: \n');
warnings.forEach(function (warning) {
warn("\n");
warn(prettyjson.render(warning, { noColor: true }));
});
warn("\n");
}
if (!program.noMinify) {
html = minify(html, {
collapseBooleanAttributes: true,
collapseWhitespace: true,
minifyCSS: true,
minifyJS: true,
minifyURLs: true,
removeAttributeQuotes: true,
removeComments: true,
removeEmptyAttributes: true,
removeOptionalTags: true,
removeRedundantAttributes: true,
useShortDoctype: true
});
}
// If output is specified, write to file. Otherwise write to console.
if (program.output) {
fs.writeFile(program.output, html, function (err) {
if (err) isMain ? halt(err) : callback(err);
success("Success! Output written to: " + program.output);
callback(null, html);
});
} else {
if (isMain) console.log(html);
callback(null, html);
}
});
});
});
} | javascript | function convert(program, callback) {
// define no-op callback
if (!callback) {
callback = function (err, blueprint) { }
}
// Read in the file
refparser.parse(program.input, function (err, schema) {
if (err) isMain ? halt(err) : callback(err);
// Read in aglio options
var options = {
themeTemplate: (program.themeTemplate === 'triple' || program.themeTemplate === 'index' || !program.themeTemplate) ?
path.resolve(__dirname, 'templates/' + (program.themeTemplate || 'index') + '.jade') :
themeTemplate,
themeVariables: program.themeVariables,
themeFullWidth: program.themeFullWidth,
noThemeCondense: program.noThemeCondense,
themeStyle: program.themeStyle,
locals: {
livePreview: program.server,
host: ((schema.schemes && schema.schemes.length > 0 && schema.host) ?
(schema.schemes[0] || 'https')
: 'https')
+ '://' + schema.host + (schema.basePath || '')
}
};
swag2blue.run({ '_': [program.input] }, function (err, blueprint) {
if (err) isMain ? halt(err) : callback(err);
aglio.render(blueprint, options, function (err, html, warnings) {
if (err) isMain ? halt(err) : callback(err);
// If we had warnings and not outputting to console, print them out and continue.
if (warnings && !program.output && isMain) {
warn('Encountered ' + warnings.length + ' warnings: \n');
warnings.forEach(function (warning) {
warn("\n");
warn(prettyjson.render(warning, { noColor: true }));
});
warn("\n");
}
if (!program.noMinify) {
html = minify(html, {
collapseBooleanAttributes: true,
collapseWhitespace: true,
minifyCSS: true,
minifyJS: true,
minifyURLs: true,
removeAttributeQuotes: true,
removeComments: true,
removeEmptyAttributes: true,
removeOptionalTags: true,
removeRedundantAttributes: true,
useShortDoctype: true
});
}
// If output is specified, write to file. Otherwise write to console.
if (program.output) {
fs.writeFile(program.output, html, function (err) {
if (err) isMain ? halt(err) : callback(err);
success("Success! Output written to: " + program.output);
callback(null, html);
});
} else {
if (isMain) console.log(html);
callback(null, html);
}
});
});
});
} | [
"function",
"convert",
"(",
"program",
",",
"callback",
")",
"{",
"// define no-op callback",
"if",
"(",
"!",
"callback",
")",
"{",
"callback",
"=",
"function",
"(",
"err",
",",
"blueprint",
")",
"{",
"}",
"}",
"// Read in the file",
"refparser",
".",
"parse",
"(",
"program",
".",
"input",
",",
"function",
"(",
"err",
",",
"schema",
")",
"{",
"if",
"(",
"err",
")",
"isMain",
"?",
"halt",
"(",
"err",
")",
":",
"callback",
"(",
"err",
")",
";",
"// Read in aglio options",
"var",
"options",
"=",
"{",
"themeTemplate",
":",
"(",
"program",
".",
"themeTemplate",
"===",
"'triple'",
"||",
"program",
".",
"themeTemplate",
"===",
"'index'",
"||",
"!",
"program",
".",
"themeTemplate",
")",
"?",
"path",
".",
"resolve",
"(",
"__dirname",
",",
"'templates/'",
"+",
"(",
"program",
".",
"themeTemplate",
"||",
"'index'",
")",
"+",
"'.jade'",
")",
":",
"themeTemplate",
",",
"themeVariables",
":",
"program",
".",
"themeVariables",
",",
"themeFullWidth",
":",
"program",
".",
"themeFullWidth",
",",
"noThemeCondense",
":",
"program",
".",
"noThemeCondense",
",",
"themeStyle",
":",
"program",
".",
"themeStyle",
",",
"locals",
":",
"{",
"livePreview",
":",
"program",
".",
"server",
",",
"host",
":",
"(",
"(",
"schema",
".",
"schemes",
"&&",
"schema",
".",
"schemes",
".",
"length",
">",
"0",
"&&",
"schema",
".",
"host",
")",
"?",
"(",
"schema",
".",
"schemes",
"[",
"0",
"]",
"||",
"'https'",
")",
":",
"'https'",
")",
"+",
"'://'",
"+",
"schema",
".",
"host",
"+",
"(",
"schema",
".",
"basePath",
"||",
"''",
")",
"}",
"}",
";",
"swag2blue",
".",
"run",
"(",
"{",
"'_'",
":",
"[",
"program",
".",
"input",
"]",
"}",
",",
"function",
"(",
"err",
",",
"blueprint",
")",
"{",
"if",
"(",
"err",
")",
"isMain",
"?",
"halt",
"(",
"err",
")",
":",
"callback",
"(",
"err",
")",
";",
"aglio",
".",
"render",
"(",
"blueprint",
",",
"options",
",",
"function",
"(",
"err",
",",
"html",
",",
"warnings",
")",
"{",
"if",
"(",
"err",
")",
"isMain",
"?",
"halt",
"(",
"err",
")",
":",
"callback",
"(",
"err",
")",
";",
"// If we had warnings and not outputting to console, print them out and continue.",
"if",
"(",
"warnings",
"&&",
"!",
"program",
".",
"output",
"&&",
"isMain",
")",
"{",
"warn",
"(",
"'Encountered '",
"+",
"warnings",
".",
"length",
"+",
"' warnings: \\n'",
")",
";",
"warnings",
".",
"forEach",
"(",
"function",
"(",
"warning",
")",
"{",
"warn",
"(",
"\"\\n\"",
")",
";",
"warn",
"(",
"prettyjson",
".",
"render",
"(",
"warning",
",",
"{",
"noColor",
":",
"true",
"}",
")",
")",
";",
"}",
")",
";",
"warn",
"(",
"\"\\n\"",
")",
";",
"}",
"if",
"(",
"!",
"program",
".",
"noMinify",
")",
"{",
"html",
"=",
"minify",
"(",
"html",
",",
"{",
"collapseBooleanAttributes",
":",
"true",
",",
"collapseWhitespace",
":",
"true",
",",
"minifyCSS",
":",
"true",
",",
"minifyJS",
":",
"true",
",",
"minifyURLs",
":",
"true",
",",
"removeAttributeQuotes",
":",
"true",
",",
"removeComments",
":",
"true",
",",
"removeEmptyAttributes",
":",
"true",
",",
"removeOptionalTags",
":",
"true",
",",
"removeRedundantAttributes",
":",
"true",
",",
"useShortDoctype",
":",
"true",
"}",
")",
";",
"}",
"// If output is specified, write to file. Otherwise write to console.",
"if",
"(",
"program",
".",
"output",
")",
"{",
"fs",
".",
"writeFile",
"(",
"program",
".",
"output",
",",
"html",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"isMain",
"?",
"halt",
"(",
"err",
")",
":",
"callback",
"(",
"err",
")",
";",
"success",
"(",
"\"Success! Output written to: \"",
"+",
"program",
".",
"output",
")",
";",
"callback",
"(",
"null",
",",
"html",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"if",
"(",
"isMain",
")",
"console",
".",
"log",
"(",
"html",
")",
";",
"callback",
"(",
"null",
",",
"html",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| End program
Helper functions | [
"End",
"program",
"Helper",
"functions"
]
| 42869876ecd28526a68814c07a93ccf188127f06 | https://github.com/psastras/swagger2aglio/blob/42869876ecd28526a68814c07a93ccf188127f06/index.js#L44-L117 |
47,520 | psastras/swagger2aglio | index.js | check_input | function check_input(input, message) {
if (!input) {
error('\n Error: ' + message);
program.outputHelp(colors.red);
process.exit(1);
}
} | javascript | function check_input(input, message) {
if (!input) {
error('\n Error: ' + message);
program.outputHelp(colors.red);
process.exit(1);
}
} | [
"function",
"check_input",
"(",
"input",
",",
"message",
")",
"{",
"if",
"(",
"!",
"input",
")",
"{",
"error",
"(",
"'\\n Error: '",
"+",
"message",
")",
";",
"program",
".",
"outputHelp",
"(",
"colors",
".",
"red",
")",
";",
"process",
".",
"exit",
"(",
"1",
")",
";",
"}",
"}"
]
| Checks that the given input is defined. If it is defined, this is a no-op. Else
this prints the error message and halts the program with exit code 1.
@param {input} input - The input to check
@param {message} txt - The text to display if the check fails | [
"Checks",
"that",
"the",
"given",
"input",
"is",
"defined",
".",
"If",
"it",
"is",
"defined",
"this",
"is",
"a",
"no",
"-",
"op",
".",
"Else",
"this",
"prints",
"the",
"error",
"message",
"and",
"halts",
"the",
"program",
"with",
"exit",
"code",
"1",
"."
]
| 42869876ecd28526a68814c07a93ccf188127f06 | https://github.com/psastras/swagger2aglio/blob/42869876ecd28526a68814c07a93ccf188127f06/index.js#L125-L131 |
47,521 | slideme/rorschach | lib/builders/create.js | adjustPath | function adjustPath(builder, path) {
if (builder.protection) {
var pathAndNode = utils.pathAndNode(path);
var nodeName = getProtectedPrefix(builder.protectedId) + pathAndNode.node;
path = utils.join(pathAndNode.path, nodeName);
}
return path;
} | javascript | function adjustPath(builder, path) {
if (builder.protection) {
var pathAndNode = utils.pathAndNode(path);
var nodeName = getProtectedPrefix(builder.protectedId) + pathAndNode.node;
path = utils.join(pathAndNode.path, nodeName);
}
return path;
} | [
"function",
"adjustPath",
"(",
"builder",
",",
"path",
")",
"{",
"if",
"(",
"builder",
".",
"protection",
")",
"{",
"var",
"pathAndNode",
"=",
"utils",
".",
"pathAndNode",
"(",
"path",
")",
";",
"var",
"nodeName",
"=",
"getProtectedPrefix",
"(",
"builder",
".",
"protectedId",
")",
"+",
"pathAndNode",
".",
"node",
";",
"path",
"=",
"utils",
".",
"join",
"(",
"pathAndNode",
".",
"path",
",",
"nodeName",
")",
";",
"}",
"return",
"path",
";",
"}"
]
| Get final path
@param {CreateBuilder} builder
@param {String} path | [
"Get",
"final",
"path"
]
| 899339baf31682f8a62b2960cdd26fbb58a9e3a1 | https://github.com/slideme/rorschach/blob/899339baf31682f8a62b2960cdd26fbb58a9e3a1/lib/builders/create.js#L98-L105 |
47,522 | slideme/rorschach | lib/builders/create.js | findNode | function findNode(children, path, protectedId) {
var prefix = getProtectedPrefix(protectedId);
var i = 0;
var node;
while ((node = children[i++])) {
if (node.indexOf(prefix) === 0) {
return utils.join(path, node);
}
}
return null;
} | javascript | function findNode(children, path, protectedId) {
var prefix = getProtectedPrefix(protectedId);
var i = 0;
var node;
while ((node = children[i++])) {
if (node.indexOf(prefix) === 0) {
return utils.join(path, node);
}
}
return null;
} | [
"function",
"findNode",
"(",
"children",
",",
"path",
",",
"protectedId",
")",
"{",
"var",
"prefix",
"=",
"getProtectedPrefix",
"(",
"protectedId",
")",
";",
"var",
"i",
"=",
"0",
";",
"var",
"node",
";",
"while",
"(",
"(",
"node",
"=",
"children",
"[",
"i",
"++",
"]",
")",
")",
"{",
"if",
"(",
"node",
".",
"indexOf",
"(",
"prefix",
")",
"===",
"0",
")",
"{",
"return",
"utils",
".",
"join",
"(",
"path",
",",
"node",
")",
";",
"}",
"}",
"return",
"null",
";",
"}"
]
| Find znode among children list with given prefix.
@param {Array.<String>} children
@param {String} path
@param {String} protectedId
@returns {String|null} | [
"Find",
"znode",
"among",
"children",
"list",
"with",
"given",
"prefix",
"."
]
| 899339baf31682f8a62b2960cdd26fbb58a9e3a1 | https://github.com/slideme/rorschach/blob/899339baf31682f8a62b2960cdd26fbb58a9e3a1/lib/builders/create.js#L173-L183 |
47,523 | slideme/rorschach | lib/builders/create.js | findProtectedNode | function findProtectedNode(builder, path, callback) {
var zk = builder.client.zk;
var pathAndNode = utils.pathAndNode(path);
zk.getChildren(pathAndNode.path, afterCheck);
function afterCheck(err, children) {
if (err && err.getCode() === Exception.NO_NODE) {
callback();
}
else if (err) {
callback(err);
}
else if (children.length) {
var result = findNode(children, pathAndNode.path, builder.protectedId);
callback(null, result);
}
else {
callback();
}
}
} | javascript | function findProtectedNode(builder, path, callback) {
var zk = builder.client.zk;
var pathAndNode = utils.pathAndNode(path);
zk.getChildren(pathAndNode.path, afterCheck);
function afterCheck(err, children) {
if (err && err.getCode() === Exception.NO_NODE) {
callback();
}
else if (err) {
callback(err);
}
else if (children.length) {
var result = findNode(children, pathAndNode.path, builder.protectedId);
callback(null, result);
}
else {
callback();
}
}
} | [
"function",
"findProtectedNode",
"(",
"builder",
",",
"path",
",",
"callback",
")",
"{",
"var",
"zk",
"=",
"builder",
".",
"client",
".",
"zk",
";",
"var",
"pathAndNode",
"=",
"utils",
".",
"pathAndNode",
"(",
"path",
")",
";",
"zk",
".",
"getChildren",
"(",
"pathAndNode",
".",
"path",
",",
"afterCheck",
")",
";",
"function",
"afterCheck",
"(",
"err",
",",
"children",
")",
"{",
"if",
"(",
"err",
"&&",
"err",
".",
"getCode",
"(",
")",
"===",
"Exception",
".",
"NO_NODE",
")",
"{",
"callback",
"(",
")",
";",
"}",
"else",
"if",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
")",
";",
"}",
"else",
"if",
"(",
"children",
".",
"length",
")",
"{",
"var",
"result",
"=",
"findNode",
"(",
"children",
",",
"pathAndNode",
".",
"path",
",",
"builder",
".",
"protectedId",
")",
";",
"callback",
"(",
"null",
",",
"result",
")",
";",
"}",
"else",
"{",
"callback",
"(",
")",
";",
"}",
"}",
"}"
]
| Try to find protected node with same `protectedId`.
@param {CreateBuilder} builder Builder instance
@param {String} path Desired path
@param {Function} callback Callback function: <code>(err, nodePath)</code> | [
"Try",
"to",
"find",
"protected",
"node",
"with",
"same",
"protectedId",
"."
]
| 899339baf31682f8a62b2960cdd26fbb58a9e3a1 | https://github.com/slideme/rorschach/blob/899339baf31682f8a62b2960cdd26fbb58a9e3a1/lib/builders/create.js#L195-L215 |
47,524 | slideme/rorschach | lib/builders/create.js | performCreate | function performCreate(builder, path, data, callback) {
var client = builder.client;
var zk = client.zk;
var firstTime = true;
client.retryLoop(exec, callback);
function exec(cb) {
if (firstTime && builder.protection) {
findProtectedNode(builder, path, createIfNotExist);
}
else {
createIfNotExist();
}
firstTime = false;
function createIfNotExist(err, nodePath) {
if (err) {
var args = operationArguments(builder, path, data);
return cb(new ExecutionError('create', args, err));
}
else if (nodePath) {
return cb(null, nodePath);
}
zk.create(path, data, builder.acls, builder.mode, afterCreate);
}
function afterCreate(err, nodePath) {
if (nodePath) {
cb(null, nodePath);
}
else if (err.getCode() === Exception.NO_NODE && builder.createParents) {
utils.mkdirs(zk, path, false, null, createIfNotExist);
}
else {
var args = operationArguments(builder, path, data);
cb(new ExecutionError('create', args, err));
}
}
}
} | javascript | function performCreate(builder, path, data, callback) {
var client = builder.client;
var zk = client.zk;
var firstTime = true;
client.retryLoop(exec, callback);
function exec(cb) {
if (firstTime && builder.protection) {
findProtectedNode(builder, path, createIfNotExist);
}
else {
createIfNotExist();
}
firstTime = false;
function createIfNotExist(err, nodePath) {
if (err) {
var args = operationArguments(builder, path, data);
return cb(new ExecutionError('create', args, err));
}
else if (nodePath) {
return cb(null, nodePath);
}
zk.create(path, data, builder.acls, builder.mode, afterCreate);
}
function afterCreate(err, nodePath) {
if (nodePath) {
cb(null, nodePath);
}
else if (err.getCode() === Exception.NO_NODE && builder.createParents) {
utils.mkdirs(zk, path, false, null, createIfNotExist);
}
else {
var args = operationArguments(builder, path, data);
cb(new ExecutionError('create', args, err));
}
}
}
} | [
"function",
"performCreate",
"(",
"builder",
",",
"path",
",",
"data",
",",
"callback",
")",
"{",
"var",
"client",
"=",
"builder",
".",
"client",
";",
"var",
"zk",
"=",
"client",
".",
"zk",
";",
"var",
"firstTime",
"=",
"true",
";",
"client",
".",
"retryLoop",
"(",
"exec",
",",
"callback",
")",
";",
"function",
"exec",
"(",
"cb",
")",
"{",
"if",
"(",
"firstTime",
"&&",
"builder",
".",
"protection",
")",
"{",
"findProtectedNode",
"(",
"builder",
",",
"path",
",",
"createIfNotExist",
")",
";",
"}",
"else",
"{",
"createIfNotExist",
"(",
")",
";",
"}",
"firstTime",
"=",
"false",
";",
"function",
"createIfNotExist",
"(",
"err",
",",
"nodePath",
")",
"{",
"if",
"(",
"err",
")",
"{",
"var",
"args",
"=",
"operationArguments",
"(",
"builder",
",",
"path",
",",
"data",
")",
";",
"return",
"cb",
"(",
"new",
"ExecutionError",
"(",
"'create'",
",",
"args",
",",
"err",
")",
")",
";",
"}",
"else",
"if",
"(",
"nodePath",
")",
"{",
"return",
"cb",
"(",
"null",
",",
"nodePath",
")",
";",
"}",
"zk",
".",
"create",
"(",
"path",
",",
"data",
",",
"builder",
".",
"acls",
",",
"builder",
".",
"mode",
",",
"afterCreate",
")",
";",
"}",
"function",
"afterCreate",
"(",
"err",
",",
"nodePath",
")",
"{",
"if",
"(",
"nodePath",
")",
"{",
"cb",
"(",
"null",
",",
"nodePath",
")",
";",
"}",
"else",
"if",
"(",
"err",
".",
"getCode",
"(",
")",
"===",
"Exception",
".",
"NO_NODE",
"&&",
"builder",
".",
"createParents",
")",
"{",
"utils",
".",
"mkdirs",
"(",
"zk",
",",
"path",
",",
"false",
",",
"null",
",",
"createIfNotExist",
")",
";",
"}",
"else",
"{",
"var",
"args",
"=",
"operationArguments",
"(",
"builder",
",",
"path",
",",
"data",
")",
";",
"cb",
"(",
"new",
"ExecutionError",
"(",
"'create'",
",",
"args",
",",
"err",
")",
")",
";",
"}",
"}",
"}",
"}"
]
| Create node and it's parents if needed.
@param {CreateBuilder} builder
@param {String} path Node path
@param {Buffer} data Node data
@param {Function} callback Callback function: <code>(err)</code> | [
"Create",
"node",
"and",
"it",
"s",
"parents",
"if",
"needed",
"."
]
| 899339baf31682f8a62b2960cdd26fbb58a9e3a1 | https://github.com/slideme/rorschach/blob/899339baf31682f8a62b2960cdd26fbb58a9e3a1/lib/builders/create.js#L290-L332 |
47,525 | fvsch/gulp-task-maker | example/tasks/mincss/index.js | mincss | function mincss(config, tools) {
return tools.simpleStream(config, [
config.autoprefixer && autoprefixer(config.autoprefixer),
config.concat && concat(config.concat),
config.minify && csso(config.csso)
])
} | javascript | function mincss(config, tools) {
return tools.simpleStream(config, [
config.autoprefixer && autoprefixer(config.autoprefixer),
config.concat && concat(config.concat),
config.minify && csso(config.csso)
])
} | [
"function",
"mincss",
"(",
"config",
",",
"tools",
")",
"{",
"return",
"tools",
".",
"simpleStream",
"(",
"config",
",",
"[",
"config",
".",
"autoprefixer",
"&&",
"autoprefixer",
"(",
"config",
".",
"autoprefixer",
")",
",",
"config",
".",
"concat",
"&&",
"concat",
"(",
"config",
".",
"concat",
")",
",",
"config",
".",
"minify",
"&&",
"csso",
"(",
"config",
".",
"csso",
")",
"]",
")",
"}"
]
| Make a CSS build, optionally concatenated and minified
@param {object} config - task configuration
@param {object} tools - gtm utility functions
@return {object} | [
"Make",
"a",
"CSS",
"build",
"optionally",
"concatenated",
"and",
"minified"
]
| 20ab4245f2d75174786ad140793e9438c025d546 | https://github.com/fvsch/gulp-task-maker/blob/20ab4245f2d75174786ad140793e9438c025d546/example/tasks/mincss/index.js#L11-L17 |
47,526 | saggiyogesh/nodeportal | lib/Renderer/PageRenderer.js | PageRenderer | function PageRenderer(req, res) {
var page = req.attrs.page;
Object.defineProperties(this, {
req: {
value: req
},
res: {
value: res
},
page: {
value: _.clone(page)
},
themeDBAction: {
value: DBActions.getInstance(req, THEME_SCHEMA)
},
layoutDBAction: {
value: DBActions.getInstance(req, LAYOUT_SCHEMA)
},
pageInstanceDBAction: {
value: DBActions.getAuthInstance(req, PAGE_SCHEMA, PAGE_PERMISSION_SCHEMA)
},
pluginInstanceDBAction: {
value: DBActions.getInstance(req, PLUGIN_INSTANCE_SCHEMA)
},
pagePermissionValidator: {
value: new PermissionValidator(req, PAGE_PERMISSION_SCHEMA, PAGE_SCHEMA)
},
pluginPermissionValidator: {
value: new PermissionValidator(req, PLUGIN_PERMISSION_SCHEMA, PLUGIN_INSTANCE_SCHEMA)
},
isExclusive: {
value: req.query && req.query.mode === "exclusive"
}
});
} | javascript | function PageRenderer(req, res) {
var page = req.attrs.page;
Object.defineProperties(this, {
req: {
value: req
},
res: {
value: res
},
page: {
value: _.clone(page)
},
themeDBAction: {
value: DBActions.getInstance(req, THEME_SCHEMA)
},
layoutDBAction: {
value: DBActions.getInstance(req, LAYOUT_SCHEMA)
},
pageInstanceDBAction: {
value: DBActions.getAuthInstance(req, PAGE_SCHEMA, PAGE_PERMISSION_SCHEMA)
},
pluginInstanceDBAction: {
value: DBActions.getInstance(req, PLUGIN_INSTANCE_SCHEMA)
},
pagePermissionValidator: {
value: new PermissionValidator(req, PAGE_PERMISSION_SCHEMA, PAGE_SCHEMA)
},
pluginPermissionValidator: {
value: new PermissionValidator(req, PLUGIN_PERMISSION_SCHEMA, PLUGIN_INSTANCE_SCHEMA)
},
isExclusive: {
value: req.query && req.query.mode === "exclusive"
}
});
} | [
"function",
"PageRenderer",
"(",
"req",
",",
"res",
")",
"{",
"var",
"page",
"=",
"req",
".",
"attrs",
".",
"page",
";",
"Object",
".",
"defineProperties",
"(",
"this",
",",
"{",
"req",
":",
"{",
"value",
":",
"req",
"}",
",",
"res",
":",
"{",
"value",
":",
"res",
"}",
",",
"page",
":",
"{",
"value",
":",
"_",
".",
"clone",
"(",
"page",
")",
"}",
",",
"themeDBAction",
":",
"{",
"value",
":",
"DBActions",
".",
"getInstance",
"(",
"req",
",",
"THEME_SCHEMA",
")",
"}",
",",
"layoutDBAction",
":",
"{",
"value",
":",
"DBActions",
".",
"getInstance",
"(",
"req",
",",
"LAYOUT_SCHEMA",
")",
"}",
",",
"pageInstanceDBAction",
":",
"{",
"value",
":",
"DBActions",
".",
"getAuthInstance",
"(",
"req",
",",
"PAGE_SCHEMA",
",",
"PAGE_PERMISSION_SCHEMA",
")",
"}",
",",
"pluginInstanceDBAction",
":",
"{",
"value",
":",
"DBActions",
".",
"getInstance",
"(",
"req",
",",
"PLUGIN_INSTANCE_SCHEMA",
")",
"}",
",",
"pagePermissionValidator",
":",
"{",
"value",
":",
"new",
"PermissionValidator",
"(",
"req",
",",
"PAGE_PERMISSION_SCHEMA",
",",
"PAGE_SCHEMA",
")",
"}",
",",
"pluginPermissionValidator",
":",
"{",
"value",
":",
"new",
"PermissionValidator",
"(",
"req",
",",
"PLUGIN_PERMISSION_SCHEMA",
",",
"PLUGIN_INSTANCE_SCHEMA",
")",
"}",
",",
"isExclusive",
":",
"{",
"value",
":",
"req",
".",
"query",
"&&",
"req",
".",
"query",
".",
"mode",
"===",
"\"exclusive\"",
"}",
"}",
")",
";",
"}"
]
| Constructor to create PageRenderer to render page for current request
@param req
@param res
@constructor | [
"Constructor",
"to",
"create",
"PageRenderer",
"to",
"render",
"page",
"for",
"current",
"request"
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/lib/Renderer/PageRenderer.js#L35-L69 |
47,527 | Ajedi32/metalsmith-matters | lib/index.js | extractFrontmatter | function extractFrontmatter(file, filePath, options, grayMatterOptions){
if (utf8(file.contents)) {
var parsed;
try {
parsed = matter(file.contents.toString(), grayMatterOptions);
} catch (e) {
var errMsg = 'Invalid frontmatter in file';
if (filePath !== undefined) errMsg += ": " + filePath;
var err = new Error(errMsg);
err.code = 'invalid_frontmatter';
err.cause = e;
throw err;
}
if (options.hasOwnProperty('namespace')){
var nsData = {}; nsData[options.namespace] = parsed.data;
Object.assign(file, nsData);
} else {
Object.assign(file, parsed.data);
}
file.contents = new Buffer(parsed.content);
}
} | javascript | function extractFrontmatter(file, filePath, options, grayMatterOptions){
if (utf8(file.contents)) {
var parsed;
try {
parsed = matter(file.contents.toString(), grayMatterOptions);
} catch (e) {
var errMsg = 'Invalid frontmatter in file';
if (filePath !== undefined) errMsg += ": " + filePath;
var err = new Error(errMsg);
err.code = 'invalid_frontmatter';
err.cause = e;
throw err;
}
if (options.hasOwnProperty('namespace')){
var nsData = {}; nsData[options.namespace] = parsed.data;
Object.assign(file, nsData);
} else {
Object.assign(file, parsed.data);
}
file.contents = new Buffer(parsed.content);
}
} | [
"function",
"extractFrontmatter",
"(",
"file",
",",
"filePath",
",",
"options",
",",
"grayMatterOptions",
")",
"{",
"if",
"(",
"utf8",
"(",
"file",
".",
"contents",
")",
")",
"{",
"var",
"parsed",
";",
"try",
"{",
"parsed",
"=",
"matter",
"(",
"file",
".",
"contents",
".",
"toString",
"(",
")",
",",
"grayMatterOptions",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"var",
"errMsg",
"=",
"'Invalid frontmatter in file'",
";",
"if",
"(",
"filePath",
"!==",
"undefined",
")",
"errMsg",
"+=",
"\": \"",
"+",
"filePath",
";",
"var",
"err",
"=",
"new",
"Error",
"(",
"errMsg",
")",
";",
"err",
".",
"code",
"=",
"'invalid_frontmatter'",
";",
"err",
".",
"cause",
"=",
"e",
";",
"throw",
"err",
";",
"}",
"if",
"(",
"options",
".",
"hasOwnProperty",
"(",
"'namespace'",
")",
")",
"{",
"var",
"nsData",
"=",
"{",
"}",
";",
"nsData",
"[",
"options",
".",
"namespace",
"]",
"=",
"parsed",
".",
"data",
";",
"Object",
".",
"assign",
"(",
"file",
",",
"nsData",
")",
";",
"}",
"else",
"{",
"Object",
".",
"assign",
"(",
"file",
",",
"parsed",
".",
"data",
")",
";",
"}",
"file",
".",
"contents",
"=",
"new",
"Buffer",
"(",
"parsed",
".",
"content",
")",
";",
"}",
"}"
]
| Assign metadata in `file` based on the YAML frontmatter in `file.contents`.
@param {Object} file The Metalsmith file object to extract frontmatter from
@param {string} filePath The path to the file represented by `file`
@param {Object} options Options for the extraction routine
@param {Object} grayMatterOptions Options for gray-matter | [
"Assign",
"metadata",
"in",
"file",
"based",
"on",
"the",
"YAML",
"frontmatter",
"in",
"file",
".",
"contents",
"."
]
| 42393d7c0ebf7df35c4eccef40018075c160b31c | https://github.com/Ajedi32/metalsmith-matters/blob/42393d7c0ebf7df35c4eccef40018075c160b31c/lib/index.js#L19-L42 |
47,528 | Ajedi32/metalsmith-matters | lib/index.js | frontmatter | function frontmatter(opts){
var options = {}, grayMatterOptions = {};
Object.keys(opts || {}).forEach(function(key){
if (key === 'namespace'){
options[key] = opts[key];
} else {
grayMatterOptions[key] = opts[key];
}
});
return each(function(file, filePath){
extractFrontmatter(file, filePath, options, grayMatterOptions);
});
} | javascript | function frontmatter(opts){
var options = {}, grayMatterOptions = {};
Object.keys(opts || {}).forEach(function(key){
if (key === 'namespace'){
options[key] = opts[key];
} else {
grayMatterOptions[key] = opts[key];
}
});
return each(function(file, filePath){
extractFrontmatter(file, filePath, options, grayMatterOptions);
});
} | [
"function",
"frontmatter",
"(",
"opts",
")",
"{",
"var",
"options",
"=",
"{",
"}",
",",
"grayMatterOptions",
"=",
"{",
"}",
";",
"Object",
".",
"keys",
"(",
"opts",
"||",
"{",
"}",
")",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"if",
"(",
"key",
"===",
"'namespace'",
")",
"{",
"options",
"[",
"key",
"]",
"=",
"opts",
"[",
"key",
"]",
";",
"}",
"else",
"{",
"grayMatterOptions",
"[",
"key",
"]",
"=",
"opts",
"[",
"key",
"]",
";",
"}",
"}",
")",
";",
"return",
"each",
"(",
"function",
"(",
"file",
",",
"filePath",
")",
"{",
"extractFrontmatter",
"(",
"file",
",",
"filePath",
",",
"options",
",",
"grayMatterOptions",
")",
";",
"}",
")",
";",
"}"
]
| Metalsmith plugin to extract metadata from frontmatter in file contents.
@param {Object} options - `Namespace` is used, the rest is passed on to `gray-matter`
@return {Function} | [
"Metalsmith",
"plugin",
"to",
"extract",
"metadata",
"from",
"frontmatter",
"in",
"file",
"contents",
"."
]
| 42393d7c0ebf7df35c4eccef40018075c160b31c | https://github.com/Ajedi32/metalsmith-matters/blob/42393d7c0ebf7df35c4eccef40018075c160b31c/lib/index.js#L50-L63 |
47,529 | saggiyogesh/nodeportal | lib/plugins.js | loadPlugin | function loadPlugin(id) {
var plugin = PLUGINS[id];
plugin.exec.load(plugin.id, {
id: plugin.id
});
} | javascript | function loadPlugin(id) {
var plugin = PLUGINS[id];
plugin.exec.load(plugin.id, {
id: plugin.id
});
} | [
"function",
"loadPlugin",
"(",
"id",
")",
"{",
"var",
"plugin",
"=",
"PLUGINS",
"[",
"id",
"]",
";",
"plugin",
".",
"exec",
".",
"load",
"(",
"plugin",
".",
"id",
",",
"{",
"id",
":",
"plugin",
".",
"id",
"}",
")",
";",
"}"
]
| After adding a plugin, it also should be loaded, otherwise it'll raise an err for listenload event | [
"After",
"adding",
"a",
"plugin",
"it",
"also",
"should",
"be",
"loaded",
"otherwise",
"it",
"ll",
"raise",
"an",
"err",
"for",
"listenload",
"event"
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/lib/plugins.js#L45-L50 |
47,530 | yuanqing/modal | modal.js | bindToClick | function bindToClick(selector, handler) {
var elems = document.querySelectorAll(selector);
var i = -1;
var len = elems.length;
while (++i < len) {
elems[i].addEventListener('click', handler);
}
} | javascript | function bindToClick(selector, handler) {
var elems = document.querySelectorAll(selector);
var i = -1;
var len = elems.length;
while (++i < len) {
elems[i].addEventListener('click', handler);
}
} | [
"function",
"bindToClick",
"(",
"selector",
",",
"handler",
")",
"{",
"var",
"elems",
"=",
"document",
".",
"querySelectorAll",
"(",
"selector",
")",
";",
"var",
"i",
"=",
"-",
"1",
";",
"var",
"len",
"=",
"elems",
".",
"length",
";",
"while",
"(",
"++",
"i",
"<",
"len",
")",
"{",
"elems",
"[",
"i",
"]",
".",
"addEventListener",
"(",
"'click'",
",",
"handler",
")",
";",
"}",
"}"
]
| Binds the given `handler` to all elements that match the `selector`. | [
"Binds",
"the",
"given",
"handler",
"to",
"all",
"elements",
"that",
"match",
"the",
"selector",
"."
]
| f9a4913a427e022d649956d11c160ceed33213d3 | https://github.com/yuanqing/modal/blob/f9a4913a427e022d649956d11c160ceed33213d3/modal.js#L26-L33 |
47,531 | shlomiassaf/resty-stone | lib/decoration/sessionDecorator.js | sessionDecorator | function sessionDecorator() {
// save token header to be used in cookieParserDecorator middleware.
tokenHeaderName = rs.keystone.get('resty token header');
rs.keystone.session = RestySession.factory(rs.keystone);
rs.keystone.set('session', rs.keystone.session.persist);
} | javascript | function sessionDecorator() {
// save token header to be used in cookieParserDecorator middleware.
tokenHeaderName = rs.keystone.get('resty token header');
rs.keystone.session = RestySession.factory(rs.keystone);
rs.keystone.set('session', rs.keystone.session.persist);
} | [
"function",
"sessionDecorator",
"(",
")",
"{",
"// save token header to be used in cookieParserDecorator middleware.",
"tokenHeaderName",
"=",
"rs",
".",
"keystone",
".",
"get",
"(",
"'resty token header'",
")",
";",
"rs",
".",
"keystone",
".",
"session",
"=",
"RestySession",
".",
"factory",
"(",
"rs",
".",
"keystone",
")",
";",
"rs",
".",
"keystone",
".",
"set",
"(",
"'session'",
",",
"rs",
".",
"keystone",
".",
"session",
".",
"persist",
")",
";",
"}"
]
| Replaces keystone session API with a proxy to handle authentication different the cookie auth.
@param keystone | [
"Replaces",
"keystone",
"session",
"API",
"with",
"a",
"proxy",
"to",
"handle",
"authentication",
"different",
"the",
"cookie",
"auth",
"."
]
| 9ab093272ea7b68c6fe0aba45384206571896295 | https://github.com/shlomiassaf/resty-stone/blob/9ab093272ea7b68c6fe0aba45384206571896295/lib/decoration/sessionDecorator.js#L14-L20 |
47,532 | shlomiassaf/resty-stone | lib/decoration/sessionDecorator.js | cookieParserDecorator | function cookieParserDecorator(req, res, next) {
// run express.cookieParser() only when were not visiting the api.
if (req.isResty) {
// get token from headers.
var token = req.headers[tokenHeaderName] || undefined;
if (token) {
try {
// decode token, it holds and create a fake cookie.
jwt.decode(req.secret, token, function (err, decode) {
if (! err) {
// set the fake cookie, it will now have a keystone session id
req.signedCookies = decode;
}
});
}
catch(ex) {
// when token does not parse to an object.
}
}
var listenersCount = EventEmitter.listenerCount(res, 'header');
originalSessionMiddleware(req, res, function(){
if (EventEmitter.listenerCount(res, 'header') > listenersCount) {
res.removeListener('header', res.listeners('header')[listenersCount]);
}
next();
});
}
else {
// run the original cookie parser.
originalCookieParserMiddleware(req, res, function() {
originalSessionMiddleware(req, res, next);
});
}
} | javascript | function cookieParserDecorator(req, res, next) {
// run express.cookieParser() only when were not visiting the api.
if (req.isResty) {
// get token from headers.
var token = req.headers[tokenHeaderName] || undefined;
if (token) {
try {
// decode token, it holds and create a fake cookie.
jwt.decode(req.secret, token, function (err, decode) {
if (! err) {
// set the fake cookie, it will now have a keystone session id
req.signedCookies = decode;
}
});
}
catch(ex) {
// when token does not parse to an object.
}
}
var listenersCount = EventEmitter.listenerCount(res, 'header');
originalSessionMiddleware(req, res, function(){
if (EventEmitter.listenerCount(res, 'header') > listenersCount) {
res.removeListener('header', res.listeners('header')[listenersCount]);
}
next();
});
}
else {
// run the original cookie parser.
originalCookieParserMiddleware(req, res, function() {
originalSessionMiddleware(req, res, next);
});
}
} | [
"function",
"cookieParserDecorator",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"// run express.cookieParser() only when were not visiting the api.",
"if",
"(",
"req",
".",
"isResty",
")",
"{",
"// get token from headers.",
"var",
"token",
"=",
"req",
".",
"headers",
"[",
"tokenHeaderName",
"]",
"||",
"undefined",
";",
"if",
"(",
"token",
")",
"{",
"try",
"{",
"// decode token, it holds and create a fake cookie.",
"jwt",
".",
"decode",
"(",
"req",
".",
"secret",
",",
"token",
",",
"function",
"(",
"err",
",",
"decode",
")",
"{",
"if",
"(",
"!",
"err",
")",
"{",
"// set the fake cookie, it will now have a keystone session id",
"req",
".",
"signedCookies",
"=",
"decode",
";",
"}",
"}",
")",
";",
"}",
"catch",
"(",
"ex",
")",
"{",
"// when token does not parse to an object.",
"}",
"}",
"var",
"listenersCount",
"=",
"EventEmitter",
".",
"listenerCount",
"(",
"res",
",",
"'header'",
")",
";",
"originalSessionMiddleware",
"(",
"req",
",",
"res",
",",
"function",
"(",
")",
"{",
"if",
"(",
"EventEmitter",
".",
"listenerCount",
"(",
"res",
",",
"'header'",
")",
">",
"listenersCount",
")",
"{",
"res",
".",
"removeListener",
"(",
"'header'",
",",
"res",
".",
"listeners",
"(",
"'header'",
")",
"[",
"listenersCount",
"]",
")",
";",
"}",
"next",
"(",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"// run the original cookie parser.",
"originalCookieParserMiddleware",
"(",
"req",
",",
"res",
",",
"function",
"(",
")",
"{",
"originalSessionMiddleware",
"(",
"req",
",",
"res",
",",
"next",
")",
";",
"}",
")",
";",
"}",
"}"
]
| Replace the default cookie parser with a proxy cookie parser middleware.
The proxy is then used to decide what parser is right for the task.
If we are not in the api realm, use the default cookie parser.
In any other case, use the appropriate one.
This approach is used to create fake "cookie" data.
By faking cookie data we can use default session middleware as is without the need to replace it.
@param req
@param res
@param next | [
"Replace",
"the",
"default",
"cookie",
"parser",
"with",
"a",
"proxy",
"cookie",
"parser",
"middleware",
".",
"The",
"proxy",
"is",
"then",
"used",
"to",
"decide",
"what",
"parser",
"is",
"right",
"for",
"the",
"task",
".",
"If",
"we",
"are",
"not",
"in",
"the",
"api",
"realm",
"use",
"the",
"default",
"cookie",
"parser",
".",
"In",
"any",
"other",
"case",
"use",
"the",
"appropriate",
"one",
"."
]
| 9ab093272ea7b68c6fe0aba45384206571896295 | https://github.com/shlomiassaf/resty-stone/blob/9ab093272ea7b68c6fe0aba45384206571896295/lib/decoration/sessionDecorator.js#L34-L71 |
47,533 | ForbesLindesay/stop | lib/status-codes.js | statusCodes | function statusCodes(allowed, ignored, options) {
var stream = new Transform({objectMode: true});
var errored = false;
stream._transform = function (page, _, callback) {
if (errored) return callback(null);
if (ignored && ignored.indexOf(page.statusCode) !== -1) return callback(null);
if (!allowed || allowed.indexOf(page.statusCode) !== -1) {
stream.push(page);
return callback(null);
}
errored = true;
stream.emit('error', new Error('Invalid status code ' + page.statusCode + ' - ' + page.url));
callback(null);
};
return stream;
} | javascript | function statusCodes(allowed, ignored, options) {
var stream = new Transform({objectMode: true});
var errored = false;
stream._transform = function (page, _, callback) {
if (errored) return callback(null);
if (ignored && ignored.indexOf(page.statusCode) !== -1) return callback(null);
if (!allowed || allowed.indexOf(page.statusCode) !== -1) {
stream.push(page);
return callback(null);
}
errored = true;
stream.emit('error', new Error('Invalid status code ' + page.statusCode + ' - ' + page.url));
callback(null);
};
return stream;
} | [
"function",
"statusCodes",
"(",
"allowed",
",",
"ignored",
",",
"options",
")",
"{",
"var",
"stream",
"=",
"new",
"Transform",
"(",
"{",
"objectMode",
":",
"true",
"}",
")",
";",
"var",
"errored",
"=",
"false",
";",
"stream",
".",
"_transform",
"=",
"function",
"(",
"page",
",",
"_",
",",
"callback",
")",
"{",
"if",
"(",
"errored",
")",
"return",
"callback",
"(",
"null",
")",
";",
"if",
"(",
"ignored",
"&&",
"ignored",
".",
"indexOf",
"(",
"page",
".",
"statusCode",
")",
"!==",
"-",
"1",
")",
"return",
"callback",
"(",
"null",
")",
";",
"if",
"(",
"!",
"allowed",
"||",
"allowed",
".",
"indexOf",
"(",
"page",
".",
"statusCode",
")",
"!==",
"-",
"1",
")",
"{",
"stream",
".",
"push",
"(",
"page",
")",
";",
"return",
"callback",
"(",
"null",
")",
";",
"}",
"errored",
"=",
"true",
";",
"stream",
".",
"emit",
"(",
"'error'",
",",
"new",
"Error",
"(",
"'Invalid status code '",
"+",
"page",
".",
"statusCode",
"+",
"' - '",
"+",
"page",
".",
"url",
")",
")",
";",
"callback",
"(",
"null",
")",
";",
"}",
";",
"return",
"stream",
";",
"}"
]
| Limit status codes to a list of allowed status codes
@param {Array.<Number>} allowed
@param {Array.<Number>} ignored
@returns {TransformStream} | [
"Limit",
"status",
"codes",
"to",
"a",
"list",
"of",
"allowed",
"status",
"codes"
]
| 61db8899bdde604dc45cfc8f11fffa1beaa27abb | https://github.com/ForbesLindesay/stop/blob/61db8899bdde604dc45cfc8f11fffa1beaa27abb/lib/status-codes.js#L14-L31 |
47,534 | slideme/rorschach | lib/ReadWriteLock.js | ReadWriteLock | function ReadWriteLock(client, basePath) {
var readLockDriver = new ReadLockDriver(this);
var writeLockDriver = new SortingLockDriver();
/**
* Read mutex.
*
* @type {Lock}
*/
this.readMutex = new Lock(client, basePath, READ_LOCK_NAME, readLockDriver);
this.readMutex.setMaxLeases(Infinity);
/**
* Write mutex.
*
* @type {Lock}
*/
this.writeMutex = new Lock(client, basePath, WRITE_LOCK_NAME,
writeLockDriver);
} | javascript | function ReadWriteLock(client, basePath) {
var readLockDriver = new ReadLockDriver(this);
var writeLockDriver = new SortingLockDriver();
/**
* Read mutex.
*
* @type {Lock}
*/
this.readMutex = new Lock(client, basePath, READ_LOCK_NAME, readLockDriver);
this.readMutex.setMaxLeases(Infinity);
/**
* Write mutex.
*
* @type {Lock}
*/
this.writeMutex = new Lock(client, basePath, WRITE_LOCK_NAME,
writeLockDriver);
} | [
"function",
"ReadWriteLock",
"(",
"client",
",",
"basePath",
")",
"{",
"var",
"readLockDriver",
"=",
"new",
"ReadLockDriver",
"(",
"this",
")",
";",
"var",
"writeLockDriver",
"=",
"new",
"SortingLockDriver",
"(",
")",
";",
"/**\n * Read mutex.\n *\n * @type {Lock}\n */",
"this",
".",
"readMutex",
"=",
"new",
"Lock",
"(",
"client",
",",
"basePath",
",",
"READ_LOCK_NAME",
",",
"readLockDriver",
")",
";",
"this",
".",
"readMutex",
".",
"setMaxLeases",
"(",
"Infinity",
")",
";",
"/**\n * Write mutex.\n *\n * @type {Lock}\n */",
"this",
".",
"writeMutex",
"=",
"new",
"Lock",
"(",
"client",
",",
"basePath",
",",
"WRITE_LOCK_NAME",
",",
"writeLockDriver",
")",
";",
"}"
]
| Implementation of re-entrant readers-writer mutex.
@constructor
@param {Rorschach} client Rorschach instance
@param {String} basePath Base lock path | [
"Implementation",
"of",
"re",
"-",
"entrant",
"readers",
"-",
"writer",
"mutex",
"."
]
| 899339baf31682f8a62b2960cdd26fbb58a9e3a1 | https://github.com/slideme/rorschach/blob/899339baf31682f8a62b2960cdd26fbb58a9e3a1/lib/ReadWriteLock.js#L42-L63 |
47,535 | shinout/LineStream | LineStream.js | emit | function emit() {
if (arguments.length) this.emitted.push(arguments);
while (!this.paused && this.emitted.length && this.readable) {
var emitArgs = this.emitted.shift();
this.emit.apply(this, emitArgs);
if (emitArgs[0] == 'end') {
this.readable = false;
}
}
} | javascript | function emit() {
if (arguments.length) this.emitted.push(arguments);
while (!this.paused && this.emitted.length && this.readable) {
var emitArgs = this.emitted.shift();
this.emit.apply(this, emitArgs);
if (emitArgs[0] == 'end') {
this.readable = false;
}
}
} | [
"function",
"emit",
"(",
")",
"{",
"if",
"(",
"arguments",
".",
"length",
")",
"this",
".",
"emitted",
".",
"push",
"(",
"arguments",
")",
";",
"while",
"(",
"!",
"this",
".",
"paused",
"&&",
"this",
".",
"emitted",
".",
"length",
"&&",
"this",
".",
"readable",
")",
"{",
"var",
"emitArgs",
"=",
"this",
".",
"emitted",
".",
"shift",
"(",
")",
";",
"this",
".",
"emit",
".",
"apply",
"(",
"this",
",",
"emitArgs",
")",
";",
"if",
"(",
"emitArgs",
"[",
"0",
"]",
"==",
"'end'",
")",
"{",
"this",
".",
"readable",
"=",
"false",
";",
"}",
"}",
"}"
]
| add emit events to the event queue.
(private method) | [
"add",
"emit",
"events",
"to",
"the",
"event",
"queue",
"."
]
| 7df667d67521b9c2145901117ea61a35b2d4b55c | https://github.com/shinout/LineStream/blob/7df667d67521b9c2145901117ea61a35b2d4b55c/LineStream.js#L220-L229 |
47,536 | shinout/LineStream | LineStream.js | emitLine | function emitLine(line, isEnd) {
if (this.filters.every(function(fn) { return fn(line) }))
emit.call(this, 'data', line, !!isEnd);
} | javascript | function emitLine(line, isEnd) {
if (this.filters.every(function(fn) { return fn(line) }))
emit.call(this, 'data', line, !!isEnd);
} | [
"function",
"emitLine",
"(",
"line",
",",
"isEnd",
")",
"{",
"if",
"(",
"this",
".",
"filters",
".",
"every",
"(",
"function",
"(",
"fn",
")",
"{",
"return",
"fn",
"(",
"line",
")",
"}",
")",
")",
"emit",
".",
"call",
"(",
"this",
",",
"'data'",
",",
"line",
",",
"!",
"!",
"isEnd",
")",
";",
"}"
]
| emit data event if the given line is valid.
(private method) | [
"emit",
"data",
"event",
"if",
"the",
"given",
"line",
"is",
"valid",
"."
]
| 7df667d67521b9c2145901117ea61a35b2d4b55c | https://github.com/shinout/LineStream/blob/7df667d67521b9c2145901117ea61a35b2d4b55c/LineStream.js#L237-L240 |
47,537 | Raynos/contract | src/contract.js | _create | function _create(f) {
var c = Object.create(Contract);
c._wrapped = f;
return c;
} | javascript | function _create(f) {
var c = Object.create(Contract);
c._wrapped = f;
return c;
} | [
"function",
"_create",
"(",
"f",
")",
"{",
"var",
"c",
"=",
"Object",
".",
"create",
"(",
"Contract",
")",
";",
"c",
".",
"_wrapped",
"=",
"f",
";",
"return",
"c",
";",
"}"
]
| ContractFactory generates a new Contract based on the passed function `f` | [
"ContractFactory",
"generates",
"a",
"new",
"Contract",
"based",
"on",
"the",
"passed",
"function",
"f"
]
| 4e41fffe494e2844fd6df7924ef43cfa1d6936b9 | https://github.com/Raynos/contract/blob/4e41fffe494e2844fd6df7924ef43cfa1d6936b9/src/contract.js#L77-L81 |
47,538 | Raynos/contract | src/contract.js | defineProperties | function defineProperties(obj) {
Object.defineProperties(obj, {
"pre": {
value: Contract.pre,
configurable: true
},
"post": {
value: Contract.post,
configurable: true
},
"invariant": {
value: Contract.invariant,
configurable: true
}
});
} | javascript | function defineProperties(obj) {
Object.defineProperties(obj, {
"pre": {
value: Contract.pre,
configurable: true
},
"post": {
value: Contract.post,
configurable: true
},
"invariant": {
value: Contract.invariant,
configurable: true
}
});
} | [
"function",
"defineProperties",
"(",
"obj",
")",
"{",
"Object",
".",
"defineProperties",
"(",
"obj",
",",
"{",
"\"pre\"",
":",
"{",
"value",
":",
"Contract",
".",
"pre",
",",
"configurable",
":",
"true",
"}",
",",
"\"post\"",
":",
"{",
"value",
":",
"Contract",
".",
"post",
",",
"configurable",
":",
"true",
"}",
",",
"\"invariant\"",
":",
"{",
"value",
":",
"Contract",
".",
"invariant",
",",
"configurable",
":",
"true",
"}",
"}",
")",
";",
"}"
]
| Define the pre, post & invariant objects onto an object. | [
"Define",
"the",
"pre",
"post",
"&",
"invariant",
"objects",
"onto",
"an",
"object",
"."
]
| 4e41fffe494e2844fd6df7924ef43cfa1d6936b9 | https://github.com/Raynos/contract/blob/4e41fffe494e2844fd6df7924ef43cfa1d6936b9/src/contract.js#L104-L119 |
47,539 | EightMedia/discodip | lib/puppeteer.js | getHeight | async function getHeight(url) {
await page.goto(url);
const height = await page.evaluate(() => {
return document.body.getBoundingClientRect().height;
});
return height;
} | javascript | async function getHeight(url) {
await page.goto(url);
const height = await page.evaluate(() => {
return document.body.getBoundingClientRect().height;
});
return height;
} | [
"async",
"function",
"getHeight",
"(",
"url",
")",
"{",
"await",
"page",
".",
"goto",
"(",
"url",
")",
";",
"const",
"height",
"=",
"await",
"page",
".",
"evaluate",
"(",
"(",
")",
"=>",
"{",
"return",
"document",
".",
"body",
".",
"getBoundingClientRect",
"(",
")",
".",
"height",
";",
"}",
")",
";",
"return",
"height",
";",
"}"
]
| Get page height | [
"Get",
"page",
"height"
]
| 9311bf6c7cb774c8663e40fed1c158dffe2690cb | https://github.com/EightMedia/discodip/blob/9311bf6c7cb774c8663e40fed1c158dffe2690cb/lib/puppeteer.js#L26-L34 |
47,540 | fvsch/gulp-task-maker | add.js | defineTasksForConfig | function defineTasksForConfig(taskData) {
// Define gulp tasks (build and optionally watch)
// For the task name:
// - single config, no 'name' key: <callback>
// - single config, 'name' key: <callback>_<name>
// - multiple configs, no 'name' key: <callback>_<index>
const { callback, name, normalizedConfigs } = taskData
normalizedConfigs.forEach((config, index) => {
let taskId = name
if (typeof config.name === 'string') {
taskId += `_${config.name.trim()}`
} else if (normalizedConfigs.length > 1) {
taskId += `_${index + 1}`
}
const buildId = options.buildPrefix + taskId
const watchId = options.watchPrefix + taskId
// Register build task
gulp.task(buildId, done => {
return callback(config, {
done: done,
catchErrors: catchErrors,
showError: showError,
showSizes: showSizes,
simpleStream: simpleStream
})
})
// Register matching watch task
if (Array.isArray(config.watch) && config.watch.length > 0) {
gulp.task(watchId, () => {
return gulp.watch(config.watch, gulp.series(buildId))
})
}
})
} | javascript | function defineTasksForConfig(taskData) {
// Define gulp tasks (build and optionally watch)
// For the task name:
// - single config, no 'name' key: <callback>
// - single config, 'name' key: <callback>_<name>
// - multiple configs, no 'name' key: <callback>_<index>
const { callback, name, normalizedConfigs } = taskData
normalizedConfigs.forEach((config, index) => {
let taskId = name
if (typeof config.name === 'string') {
taskId += `_${config.name.trim()}`
} else if (normalizedConfigs.length > 1) {
taskId += `_${index + 1}`
}
const buildId = options.buildPrefix + taskId
const watchId = options.watchPrefix + taskId
// Register build task
gulp.task(buildId, done => {
return callback(config, {
done: done,
catchErrors: catchErrors,
showError: showError,
showSizes: showSizes,
simpleStream: simpleStream
})
})
// Register matching watch task
if (Array.isArray(config.watch) && config.watch.length > 0) {
gulp.task(watchId, () => {
return gulp.watch(config.watch, gulp.series(buildId))
})
}
})
} | [
"function",
"defineTasksForConfig",
"(",
"taskData",
")",
"{",
"// Define gulp tasks (build and optionally watch)",
"// For the task name:",
"// - single config, no 'name' key: <callback>",
"// - single config, 'name' key: <callback>_<name>",
"// - multiple configs, no 'name' key: <callback>_<index>",
"const",
"{",
"callback",
",",
"name",
",",
"normalizedConfigs",
"}",
"=",
"taskData",
"normalizedConfigs",
".",
"forEach",
"(",
"(",
"config",
",",
"index",
")",
"=>",
"{",
"let",
"taskId",
"=",
"name",
"if",
"(",
"typeof",
"config",
".",
"name",
"===",
"'string'",
")",
"{",
"taskId",
"+=",
"`",
"${",
"config",
".",
"name",
".",
"trim",
"(",
")",
"}",
"`",
"}",
"else",
"if",
"(",
"normalizedConfigs",
".",
"length",
">",
"1",
")",
"{",
"taskId",
"+=",
"`",
"${",
"index",
"+",
"1",
"}",
"`",
"}",
"const",
"buildId",
"=",
"options",
".",
"buildPrefix",
"+",
"taskId",
"const",
"watchId",
"=",
"options",
".",
"watchPrefix",
"+",
"taskId",
"// Register build task",
"gulp",
".",
"task",
"(",
"buildId",
",",
"done",
"=>",
"{",
"return",
"callback",
"(",
"config",
",",
"{",
"done",
":",
"done",
",",
"catchErrors",
":",
"catchErrors",
",",
"showError",
":",
"showError",
",",
"showSizes",
":",
"showSizes",
",",
"simpleStream",
":",
"simpleStream",
"}",
")",
"}",
")",
"// Register matching watch task",
"if",
"(",
"Array",
".",
"isArray",
"(",
"config",
".",
"watch",
")",
"&&",
"config",
".",
"watch",
".",
"length",
">",
"0",
")",
"{",
"gulp",
".",
"task",
"(",
"watchId",
",",
"(",
")",
"=>",
"{",
"return",
"gulp",
".",
"watch",
"(",
"config",
".",
"watch",
",",
"gulp",
".",
"series",
"(",
"buildId",
")",
")",
"}",
")",
"}",
"}",
")",
"}"
]
| Register matching 'build' and 'watch' gulp tasks
@param {object} taskData | [
"Register",
"matching",
"build",
"and",
"watch",
"gulp",
"tasks"
]
| 20ab4245f2d75174786ad140793e9438c025d546 | https://github.com/fvsch/gulp-task-maker/blob/20ab4245f2d75174786ad140793e9438c025d546/add.js#L107-L142 |
47,541 | fvsch/gulp-task-maker | add.js | getTaskCallback | function getTaskCallback(callback) {
let result = null
// Get the callback function; throw errors, because we can't log them
// later until we have identified a task name
if (typeof callback === 'function') {
result = callback
} else if (typeof callback === 'string') {
let id = callback.trim()
// treat like a local path if it looks like one
if (
id.startsWith('./') ||
id.startsWith('../') ||
id.endsWith('.js') ||
(id.includes('/') && !id.startsWith('@'))
) {
if (path.isAbsolute(id) === false) {
id = path.join(process.cwd(), id)
}
}
try {
result = require(id)
} catch (err) {
throw new Error(`Could not load module '${id}':\n${err}`)
}
if (typeof result !== 'function') {
throw new Error(
`Expected module '${id}' to export a function, was ${typeof result}`
)
}
} else {
throw new Error(
`Callback argument must be a string or a named function\n${USAGE_INFO}`
)
}
const { displayName, name } = result || {}
if (typeof displayName !== 'string' && typeof name !== 'string') {
throw new Error(
`Callback function cannot be anonymous\n(Use a function declaration or the displayName property.)\n${USAGE_INFO}`
)
}
return result
} | javascript | function getTaskCallback(callback) {
let result = null
// Get the callback function; throw errors, because we can't log them
// later until we have identified a task name
if (typeof callback === 'function') {
result = callback
} else if (typeof callback === 'string') {
let id = callback.trim()
// treat like a local path if it looks like one
if (
id.startsWith('./') ||
id.startsWith('../') ||
id.endsWith('.js') ||
(id.includes('/') && !id.startsWith('@'))
) {
if (path.isAbsolute(id) === false) {
id = path.join(process.cwd(), id)
}
}
try {
result = require(id)
} catch (err) {
throw new Error(`Could not load module '${id}':\n${err}`)
}
if (typeof result !== 'function') {
throw new Error(
`Expected module '${id}' to export a function, was ${typeof result}`
)
}
} else {
throw new Error(
`Callback argument must be a string or a named function\n${USAGE_INFO}`
)
}
const { displayName, name } = result || {}
if (typeof displayName !== 'string' && typeof name !== 'string') {
throw new Error(
`Callback function cannot be anonymous\n(Use a function declaration or the displayName property.)\n${USAGE_INFO}`
)
}
return result
} | [
"function",
"getTaskCallback",
"(",
"callback",
")",
"{",
"let",
"result",
"=",
"null",
"// Get the callback function; throw errors, because we can't log them",
"// later until we have identified a task name",
"if",
"(",
"typeof",
"callback",
"===",
"'function'",
")",
"{",
"result",
"=",
"callback",
"}",
"else",
"if",
"(",
"typeof",
"callback",
"===",
"'string'",
")",
"{",
"let",
"id",
"=",
"callback",
".",
"trim",
"(",
")",
"// treat like a local path if it looks like one",
"if",
"(",
"id",
".",
"startsWith",
"(",
"'./'",
")",
"||",
"id",
".",
"startsWith",
"(",
"'../'",
")",
"||",
"id",
".",
"endsWith",
"(",
"'.js'",
")",
"||",
"(",
"id",
".",
"includes",
"(",
"'/'",
")",
"&&",
"!",
"id",
".",
"startsWith",
"(",
"'@'",
")",
")",
")",
"{",
"if",
"(",
"path",
".",
"isAbsolute",
"(",
"id",
")",
"===",
"false",
")",
"{",
"id",
"=",
"path",
".",
"join",
"(",
"process",
".",
"cwd",
"(",
")",
",",
"id",
")",
"}",
"}",
"try",
"{",
"result",
"=",
"require",
"(",
"id",
")",
"}",
"catch",
"(",
"err",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"id",
"}",
"\\n",
"${",
"err",
"}",
"`",
")",
"}",
"if",
"(",
"typeof",
"result",
"!==",
"'function'",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"id",
"}",
"${",
"typeof",
"result",
"}",
"`",
")",
"}",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"`",
"\\n",
"${",
"USAGE_INFO",
"}",
"`",
")",
"}",
"const",
"{",
"displayName",
",",
"name",
"}",
"=",
"result",
"||",
"{",
"}",
"if",
"(",
"typeof",
"displayName",
"!==",
"'string'",
"&&",
"typeof",
"name",
"!==",
"'string'",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"\\n",
"\\n",
"${",
"USAGE_INFO",
"}",
"`",
")",
"}",
"return",
"result",
"}"
]
| Check that a declared task uses a valid callback function
@param {string|Function} callback
@return {Function}
@throws {Error} | [
"Check",
"that",
"a",
"declared",
"task",
"uses",
"a",
"valid",
"callback",
"function"
]
| 20ab4245f2d75174786ad140793e9438c025d546 | https://github.com/fvsch/gulp-task-maker/blob/20ab4245f2d75174786ad140793e9438c025d546/add.js#L150-L191 |
47,542 | jlewczyk/git-hooks-js-win | lib/git-hooks.js | function (workingDirectory) {
var gitPath = getClosestGitPath(workingDirectory);
if (!gitPath) {
throw new Error('git-hooks must be run inside a git repository');
}
var hooksPath = path.resolve(gitPath, HOOKS_DIRNAME);
var hooksOldPath = path.resolve(gitPath, HOOKS_OLD_DIRNAME);
if (!fsHelpers.exists(hooksPath)) {
throw new Error('git-hooks is not installed');
}
fsHelpers.removeDir(hooksPath);
if (fsHelpers.exists(hooksOldPath)) {
fs.renameSync(hooksOldPath, hooksPath);
}
} | javascript | function (workingDirectory) {
var gitPath = getClosestGitPath(workingDirectory);
if (!gitPath) {
throw new Error('git-hooks must be run inside a git repository');
}
var hooksPath = path.resolve(gitPath, HOOKS_DIRNAME);
var hooksOldPath = path.resolve(gitPath, HOOKS_OLD_DIRNAME);
if (!fsHelpers.exists(hooksPath)) {
throw new Error('git-hooks is not installed');
}
fsHelpers.removeDir(hooksPath);
if (fsHelpers.exists(hooksOldPath)) {
fs.renameSync(hooksOldPath, hooksPath);
}
} | [
"function",
"(",
"workingDirectory",
")",
"{",
"var",
"gitPath",
"=",
"getClosestGitPath",
"(",
"workingDirectory",
")",
";",
"if",
"(",
"!",
"gitPath",
")",
"{",
"throw",
"new",
"Error",
"(",
"'git-hooks must be run inside a git repository'",
")",
";",
"}",
"var",
"hooksPath",
"=",
"path",
".",
"resolve",
"(",
"gitPath",
",",
"HOOKS_DIRNAME",
")",
";",
"var",
"hooksOldPath",
"=",
"path",
".",
"resolve",
"(",
"gitPath",
",",
"HOOKS_OLD_DIRNAME",
")",
";",
"if",
"(",
"!",
"fsHelpers",
".",
"exists",
"(",
"hooksPath",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'git-hooks is not installed'",
")",
";",
"}",
"fsHelpers",
".",
"removeDir",
"(",
"hooksPath",
")",
";",
"if",
"(",
"fsHelpers",
".",
"exists",
"(",
"hooksOldPath",
")",
")",
"{",
"fs",
".",
"renameSync",
"(",
"hooksOldPath",
",",
"hooksPath",
")",
";",
"}",
"}"
]
| Uninstalls git hooks.
@param {String} [workingDirectory]
@throws {Error} | [
"Uninstalls",
"git",
"hooks",
"."
]
| e156f88ad7aec76c9180c70656c5568ad89f9de7 | https://github.com/jlewczyk/git-hooks-js-win/blob/e156f88ad7aec76c9180c70656c5568ad89f9de7/lib/git-hooks.js#L96-L115 |
|
47,543 | jlewczyk/git-hooks-js-win | lib/git-hooks.js | spawnHook | function spawnHook(hookName, args) {
var stats = fs.statSync(hookName);
var command = hookName;
var opts = args;
var hook;
if (isWin32) {
hook = fs.readFileSync(hookName).toString();
if (!require('shebang-regex').test(hook)) {
throw new Error('Cannot find shebang in hook: ' + hookName + '.');
}
command = require('shebang-command')(require('shebang-regex').exec(hook)[0]);
opts = [hookName].concat(opts);
if (command === 'node') {
command = 'node.exe';
}
} else if (!(stats && stats.isFile() && isExecutable(stats))) {
throw new Error('Cannot execute hook: ' + hookName + '. Please check file permissions.');
}
return spawn(command, opts, {stdio: 'inherit'});
} | javascript | function spawnHook(hookName, args) {
var stats = fs.statSync(hookName);
var command = hookName;
var opts = args;
var hook;
if (isWin32) {
hook = fs.readFileSync(hookName).toString();
if (!require('shebang-regex').test(hook)) {
throw new Error('Cannot find shebang in hook: ' + hookName + '.');
}
command = require('shebang-command')(require('shebang-regex').exec(hook)[0]);
opts = [hookName].concat(opts);
if (command === 'node') {
command = 'node.exe';
}
} else if (!(stats && stats.isFile() && isExecutable(stats))) {
throw new Error('Cannot execute hook: ' + hookName + '. Please check file permissions.');
}
return spawn(command, opts, {stdio: 'inherit'});
} | [
"function",
"spawnHook",
"(",
"hookName",
",",
"args",
")",
"{",
"var",
"stats",
"=",
"fs",
".",
"statSync",
"(",
"hookName",
")",
";",
"var",
"command",
"=",
"hookName",
";",
"var",
"opts",
"=",
"args",
";",
"var",
"hook",
";",
"if",
"(",
"isWin32",
")",
"{",
"hook",
"=",
"fs",
".",
"readFileSync",
"(",
"hookName",
")",
".",
"toString",
"(",
")",
";",
"if",
"(",
"!",
"require",
"(",
"'shebang-regex'",
")",
".",
"test",
"(",
"hook",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Cannot find shebang in hook: '",
"+",
"hookName",
"+",
"'.'",
")",
";",
"}",
"command",
"=",
"require",
"(",
"'shebang-command'",
")",
"(",
"require",
"(",
"'shebang-regex'",
")",
".",
"exec",
"(",
"hook",
")",
"[",
"0",
"]",
")",
";",
"opts",
"=",
"[",
"hookName",
"]",
".",
"concat",
"(",
"opts",
")",
";",
"if",
"(",
"command",
"===",
"'node'",
")",
"{",
"command",
"=",
"'node.exe'",
";",
"}",
"}",
"else",
"if",
"(",
"!",
"(",
"stats",
"&&",
"stats",
".",
"isFile",
"(",
")",
"&&",
"isExecutable",
"(",
"stats",
")",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Cannot execute hook: '",
"+",
"hookName",
"+",
"'. Please check file permissions.'",
")",
";",
"}",
"return",
"spawn",
"(",
"command",
",",
"opts",
",",
"{",
"stdio",
":",
"'inherit'",
"}",
")",
";",
"}"
]
| Spawns hook as a separate process.
@param {String} hookName
@param {String[]} args
@returns {ChildProcess} | [
"Spawns",
"hook",
"as",
"a",
"separate",
"process",
"."
]
| e156f88ad7aec76c9180c70656c5568ad89f9de7 | https://github.com/jlewczyk/git-hooks-js-win/blob/e156f88ad7aec76c9180c70656c5568ad89f9de7/lib/git-hooks.js#L185-L205 |
47,544 | jlewczyk/git-hooks-js-win | lib/git-hooks.js | getClosestGitPath | function getClosestGitPath(currentPath) {
currentPath = currentPath || process.cwd();
var dirnamePath = path.join(currentPath, '.git');
if (fsHelpers.exists(dirnamePath)) {
return dirnamePath;
}
var nextPath = path.resolve(currentPath, '..');
if (nextPath === currentPath) {
return;
}
return getClosestGitPath(nextPath);
} | javascript | function getClosestGitPath(currentPath) {
currentPath = currentPath || process.cwd();
var dirnamePath = path.join(currentPath, '.git');
if (fsHelpers.exists(dirnamePath)) {
return dirnamePath;
}
var nextPath = path.resolve(currentPath, '..');
if (nextPath === currentPath) {
return;
}
return getClosestGitPath(nextPath);
} | [
"function",
"getClosestGitPath",
"(",
"currentPath",
")",
"{",
"currentPath",
"=",
"currentPath",
"||",
"process",
".",
"cwd",
"(",
")",
";",
"var",
"dirnamePath",
"=",
"path",
".",
"join",
"(",
"currentPath",
",",
"'.git'",
")",
";",
"if",
"(",
"fsHelpers",
".",
"exists",
"(",
"dirnamePath",
")",
")",
"{",
"return",
"dirnamePath",
";",
"}",
"var",
"nextPath",
"=",
"path",
".",
"resolve",
"(",
"currentPath",
",",
"'..'",
")",
";",
"if",
"(",
"nextPath",
"===",
"currentPath",
")",
"{",
"return",
";",
"}",
"return",
"getClosestGitPath",
"(",
"nextPath",
")",
";",
"}"
]
| Returns the closest git directory.
It starts looking from the current directory and does it up to the fs root.
It returns undefined in case where the specified directory isn't found.
@param {String} [currentPath] Current started path to search.
@returns {String|undefined} | [
"Returns",
"the",
"closest",
"git",
"directory",
".",
"It",
"starts",
"looking",
"from",
"the",
"current",
"directory",
"and",
"does",
"it",
"up",
"to",
"the",
"fs",
"root",
".",
"It",
"returns",
"undefined",
"in",
"case",
"where",
"the",
"specified",
"directory",
"isn",
"t",
"found",
"."
]
| e156f88ad7aec76c9180c70656c5568ad89f9de7 | https://github.com/jlewczyk/git-hooks-js-win/blob/e156f88ad7aec76c9180c70656c5568ad89f9de7/lib/git-hooks.js#L215-L231 |
47,545 | saggiyogesh/nodeportal | public/js/fileuploader.js | function(parent, type){
var element = qq.getByClass(parent, this._options.classes[type])[0];
if (!element){
throw new Error('element not found ' + type);
}
return element;
} | javascript | function(parent, type){
var element = qq.getByClass(parent, this._options.classes[type])[0];
if (!element){
throw new Error('element not found ' + type);
}
return element;
} | [
"function",
"(",
"parent",
",",
"type",
")",
"{",
"var",
"element",
"=",
"qq",
".",
"getByClass",
"(",
"parent",
",",
"this",
".",
"_options",
".",
"classes",
"[",
"type",
"]",
")",
"[",
"0",
"]",
";",
"if",
"(",
"!",
"element",
")",
"{",
"throw",
"new",
"Error",
"(",
"'element not found '",
"+",
"type",
")",
";",
"}",
"return",
"element",
";",
"}"
]
| Gets one of the elements listed in this._options.classes | [
"Gets",
"one",
"of",
"the",
"elements",
"listed",
"in",
"this",
".",
"_options",
".",
"classes"
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/js/fileuploader.js#L542-L549 |
|
47,546 | saggiyogesh/nodeportal | public/js/fileuploader.js | function(){
var self = this,
list = this._listElement;
qq.attach(list, 'click', function(e){
e = e || window.event;
var target = e.target || e.srcElement;
if (qq.hasClass(target, self._classes.cancel)){
qq.preventDefault(e);
var item = target.parentNode;
self._handler.cancel(item.qqFileId);
qq.remove(item);
}
});
} | javascript | function(){
var self = this,
list = this._listElement;
qq.attach(list, 'click', function(e){
e = e || window.event;
var target = e.target || e.srcElement;
if (qq.hasClass(target, self._classes.cancel)){
qq.preventDefault(e);
var item = target.parentNode;
self._handler.cancel(item.qqFileId);
qq.remove(item);
}
});
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
",",
"list",
"=",
"this",
".",
"_listElement",
";",
"qq",
".",
"attach",
"(",
"list",
",",
"'click'",
",",
"function",
"(",
"e",
")",
"{",
"e",
"=",
"e",
"||",
"window",
".",
"event",
";",
"var",
"target",
"=",
"e",
".",
"target",
"||",
"e",
".",
"srcElement",
";",
"if",
"(",
"qq",
".",
"hasClass",
"(",
"target",
",",
"self",
".",
"_classes",
".",
"cancel",
")",
")",
"{",
"qq",
".",
"preventDefault",
"(",
"e",
")",
";",
"var",
"item",
"=",
"target",
".",
"parentNode",
";",
"self",
".",
"_handler",
".",
"cancel",
"(",
"item",
".",
"qqFileId",
")",
";",
"qq",
".",
"remove",
"(",
"item",
")",
";",
"}",
"}",
")",
";",
"}"
]
| delegate click event for cancel link | [
"delegate",
"click",
"event",
"for",
"cancel",
"link"
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/js/fileuploader.js#L647-L663 |
|
47,547 | saggiyogesh/nodeportal | public/js/fileuploader.js | function(id){
// We can't use following code as the name attribute
// won't be properly registered in IE6, and new window
// on form submit will open
// var iframe = document.createElement('iframe');
// iframe.setAttribute('name', id);
var iframe = qq.toElement('<iframe src="javascript:false;" name="' + id + '" />');
// src="javascript:false;" removes ie6 prompt on https
iframe.setAttribute('id', id);
iframe.style.display = 'none';
document.body.appendChild(iframe);
return iframe;
} | javascript | function(id){
// We can't use following code as the name attribute
// won't be properly registered in IE6, and new window
// on form submit will open
// var iframe = document.createElement('iframe');
// iframe.setAttribute('name', id);
var iframe = qq.toElement('<iframe src="javascript:false;" name="' + id + '" />');
// src="javascript:false;" removes ie6 prompt on https
iframe.setAttribute('id', id);
iframe.style.display = 'none';
document.body.appendChild(iframe);
return iframe;
} | [
"function",
"(",
"id",
")",
"{",
"// We can't use following code as the name attribute",
"// won't be properly registered in IE6, and new window",
"// on form submit will open",
"// var iframe = document.createElement('iframe');",
"// iframe.setAttribute('name', id);",
"var",
"iframe",
"=",
"qq",
".",
"toElement",
"(",
"'<iframe src=\"javascript:false;\" name=\"'",
"+",
"id",
"+",
"'\" />'",
")",
";",
"// src=\"javascript:false;\" removes ie6 prompt on https",
"iframe",
".",
"setAttribute",
"(",
"'id'",
",",
"id",
")",
";",
"iframe",
".",
"style",
".",
"display",
"=",
"'none'",
";",
"document",
".",
"body",
".",
"appendChild",
"(",
"iframe",
")",
";",
"return",
"iframe",
";",
"}"
]
| Creates iframe with unique name | [
"Creates",
"iframe",
"with",
"unique",
"name"
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/js/fileuploader.js#L1074-L1090 |
|
47,548 | slawrence/grunt-properties-reader | tasks/properties_reader.js | _convertStringIfTrue | function _convertStringIfTrue(original) {
var str;
if (original && typeof original === "string") {
str = original.toLowerCase().trim();
return (str === "true" || str === "false") ? (str === "true") : original;
}
return original;
} | javascript | function _convertStringIfTrue(original) {
var str;
if (original && typeof original === "string") {
str = original.toLowerCase().trim();
return (str === "true" || str === "false") ? (str === "true") : original;
}
return original;
} | [
"function",
"_convertStringIfTrue",
"(",
"original",
")",
"{",
"var",
"str",
";",
"if",
"(",
"original",
"&&",
"typeof",
"original",
"===",
"\"string\"",
")",
"{",
"str",
"=",
"original",
".",
"toLowerCase",
"(",
")",
".",
"trim",
"(",
")",
";",
"return",
"(",
"str",
"===",
"\"true\"",
"||",
"str",
"===",
"\"false\"",
")",
"?",
"(",
"str",
"===",
"\"true\"",
")",
":",
"original",
";",
"}",
"return",
"original",
";",
"}"
]
| If a string is "true" "TRUE", or " TrUE" convert to boolean type else
leave as is | [
"If",
"a",
"string",
"is",
"true",
"TRUE",
"or",
"TrUE",
"convert",
"to",
"boolean",
"type",
"else",
"leave",
"as",
"is"
]
| e8da99c688e2609838d76ea3b1c69a3e6027692e | https://github.com/slawrence/grunt-properties-reader/blob/e8da99c688e2609838d76ea3b1c69a3e6027692e/tasks/properties_reader.js#L15-L22 |
47,549 | slawrence/grunt-properties-reader | tasks/properties_reader.js | convertPropsToJson | function convertPropsToJson(text) {
var configObject = {};
if (text && text.length) {
// handle multi-line values terminated with a backslash
text = text.replace(/\\\r?\n\s*/g, '');
text.split(/\r?\n/g).forEach(function (line) {
var props,
name,
val;
line = line.trim();
if (line && line.indexOf("#") !== 0 && line.indexOf("!") !== 0) {
props = line.split(/\=(.+)?/);
name = props[0] && props[0].trim();
val = props[1] && props[1].trim();
configObject[name] = _convertStringIfTrue(val);
}
});
}
return configObject;
} | javascript | function convertPropsToJson(text) {
var configObject = {};
if (text && text.length) {
// handle multi-line values terminated with a backslash
text = text.replace(/\\\r?\n\s*/g, '');
text.split(/\r?\n/g).forEach(function (line) {
var props,
name,
val;
line = line.trim();
if (line && line.indexOf("#") !== 0 && line.indexOf("!") !== 0) {
props = line.split(/\=(.+)?/);
name = props[0] && props[0].trim();
val = props[1] && props[1].trim();
configObject[name] = _convertStringIfTrue(val);
}
});
}
return configObject;
} | [
"function",
"convertPropsToJson",
"(",
"text",
")",
"{",
"var",
"configObject",
"=",
"{",
"}",
";",
"if",
"(",
"text",
"&&",
"text",
".",
"length",
")",
"{",
"// handle multi-line values terminated with a backslash",
"text",
"=",
"text",
".",
"replace",
"(",
"/",
"\\\\\\r?\\n\\s*",
"/",
"g",
",",
"''",
")",
";",
"text",
".",
"split",
"(",
"/",
"\\r?\\n",
"/",
"g",
")",
".",
"forEach",
"(",
"function",
"(",
"line",
")",
"{",
"var",
"props",
",",
"name",
",",
"val",
";",
"line",
"=",
"line",
".",
"trim",
"(",
")",
";",
"if",
"(",
"line",
"&&",
"line",
".",
"indexOf",
"(",
"\"#\"",
")",
"!==",
"0",
"&&",
"line",
".",
"indexOf",
"(",
"\"!\"",
")",
"!==",
"0",
")",
"{",
"props",
"=",
"line",
".",
"split",
"(",
"/",
"\\=(.+)?",
"/",
")",
";",
"name",
"=",
"props",
"[",
"0",
"]",
"&&",
"props",
"[",
"0",
"]",
".",
"trim",
"(",
")",
";",
"val",
"=",
"props",
"[",
"1",
"]",
"&&",
"props",
"[",
"1",
"]",
".",
"trim",
"(",
")",
";",
"configObject",
"[",
"name",
"]",
"=",
"_convertStringIfTrue",
"(",
"val",
")",
";",
"}",
"}",
")",
";",
"}",
"return",
"configObject",
";",
"}"
]
| Convert properties string into a json object
Only supports boolean and string types | [
"Convert",
"properties",
"string",
"into",
"a",
"json",
"object",
"Only",
"supports",
"boolean",
"and",
"string",
"types"
]
| e8da99c688e2609838d76ea3b1c69a3e6027692e | https://github.com/slawrence/grunt-properties-reader/blob/e8da99c688e2609838d76ea3b1c69a3e6027692e/tasks/properties_reader.js#L28-L47 |
47,550 | jchook/virtual-dom-handlebars | lib/VTree.js | VTree | function VTree(body, config) {
var i;
config = extend({ allowJSON: false }, config);
Object.defineProperty(this, 'config', { enumerable: false, value: config });
if (body && body.length) {
for (i=0; i<body.length; i++) {
this.push(body[i]);
}
}
} | javascript | function VTree(body, config) {
var i;
config = extend({ allowJSON: false }, config);
Object.defineProperty(this, 'config', { enumerable: false, value: config });
if (body && body.length) {
for (i=0; i<body.length; i++) {
this.push(body[i]);
}
}
} | [
"function",
"VTree",
"(",
"body",
",",
"config",
")",
"{",
"var",
"i",
";",
"config",
"=",
"extend",
"(",
"{",
"allowJSON",
":",
"false",
"}",
",",
"config",
")",
";",
"Object",
".",
"defineProperty",
"(",
"this",
",",
"'config'",
",",
"{",
"enumerable",
":",
"false",
",",
"value",
":",
"config",
"}",
")",
";",
"if",
"(",
"body",
"&&",
"body",
".",
"length",
")",
"{",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"body",
".",
"length",
";",
"i",
"++",
")",
"{",
"this",
".",
"push",
"(",
"body",
"[",
"i",
"]",
")",
";",
"}",
"}",
"}"
]
| Array of VText, VNode, and Block Expressions | [
"Array",
"of",
"VText",
"VNode",
"and",
"Block",
"Expressions"
]
| d1c2015449bad8489572114fe3d8facef2cce367 | https://github.com/jchook/virtual-dom-handlebars/blob/d1c2015449bad8489572114fe3d8facef2cce367/lib/VTree.js#L6-L15 |
47,551 | jchook/virtual-dom-handlebars | lib/Runtime.js | function(object, options) {
var i, r = [];
for (i in object) {
if (object.hasOwnProperty(i)) {
r = r.concat(options.fn(object[i]));
}
}
return r;
} | javascript | function(object, options) {
var i, r = [];
for (i in object) {
if (object.hasOwnProperty(i)) {
r = r.concat(options.fn(object[i]));
}
}
return r;
} | [
"function",
"(",
"object",
",",
"options",
")",
"{",
"var",
"i",
",",
"r",
"=",
"[",
"]",
";",
"for",
"(",
"i",
"in",
"object",
")",
"{",
"if",
"(",
"object",
".",
"hasOwnProperty",
"(",
"i",
")",
")",
"{",
"r",
"=",
"r",
".",
"concat",
"(",
"options",
".",
"fn",
"(",
"object",
"[",
"i",
"]",
")",
")",
";",
"}",
"}",
"return",
"r",
";",
"}"
]
| Block helpers always return an array of VNodes | [
"Block",
"helpers",
"always",
"return",
"an",
"array",
"of",
"VNodes"
]
| d1c2015449bad8489572114fe3d8facef2cce367 | https://github.com/jchook/virtual-dom-handlebars/blob/d1c2015449bad8489572114fe3d8facef2cce367/lib/Runtime.js#L85-L93 |
|
47,552 | wilmoore/dotsplit.js | index.js | dotsplit | function dotsplit (string) {
var idx = -1
var str = compact(normalize(string).split('.'))
var end = str.length
var out = []
while (++idx < end) {
out.push(todots(str[idx]))
}
return out
} | javascript | function dotsplit (string) {
var idx = -1
var str = compact(normalize(string).split('.'))
var end = str.length
var out = []
while (++idx < end) {
out.push(todots(str[idx]))
}
return out
} | [
"function",
"dotsplit",
"(",
"string",
")",
"{",
"var",
"idx",
"=",
"-",
"1",
"var",
"str",
"=",
"compact",
"(",
"normalize",
"(",
"string",
")",
".",
"split",
"(",
"'.'",
")",
")",
"var",
"end",
"=",
"str",
".",
"length",
"var",
"out",
"=",
"[",
"]",
"while",
"(",
"++",
"idx",
"<",
"end",
")",
"{",
"out",
".",
"push",
"(",
"todots",
"(",
"str",
"[",
"idx",
"]",
")",
")",
"}",
"return",
"out",
"}"
]
| Transform dot-delimited strings to array of strings.
@param {String} string
Dot-delimited string.
@return {Array}
Array of strings. | [
"Transform",
"dot",
"-",
"delimited",
"strings",
"to",
"array",
"of",
"strings",
"."
]
| 5334735bd130dbb9089bdf2ccdc73723f1a49419 | https://github.com/wilmoore/dotsplit.js/blob/5334735bd130dbb9089bdf2ccdc73723f1a49419/index.js#L15-L26 |
47,553 | wilmoore/dotsplit.js | index.js | compact | function compact (arr) {
var idx = -1
var end = arr.length
var out = []
while (++idx < end) {
if (arr[idx]) out.push(arr[idx])
}
return out
} | javascript | function compact (arr) {
var idx = -1
var end = arr.length
var out = []
while (++idx < end) {
if (arr[idx]) out.push(arr[idx])
}
return out
} | [
"function",
"compact",
"(",
"arr",
")",
"{",
"var",
"idx",
"=",
"-",
"1",
"var",
"end",
"=",
"arr",
".",
"length",
"var",
"out",
"=",
"[",
"]",
"while",
"(",
"++",
"idx",
"<",
"end",
")",
"{",
"if",
"(",
"arr",
"[",
"idx",
"]",
")",
"out",
".",
"push",
"(",
"arr",
"[",
"idx",
"]",
")",
"}",
"return",
"out",
"}"
]
| Drop empty values from array.
@param {Array} array
Array of strings.
@return {Array}
Array of strings (empty values dropped). | [
"Drop",
"empty",
"values",
"from",
"array",
"."
]
| 5334735bd130dbb9089bdf2ccdc73723f1a49419 | https://github.com/wilmoore/dotsplit.js/blob/5334735bd130dbb9089bdf2ccdc73723f1a49419/index.js#L52-L62 |
47,554 | IonicaBizau/read-file-cache | lib/index.js | readFileCache | function readFileCache (path, noCache, cb) {
path = abs(path);
if (typeof noCache === "function") {
cb = noCache;
noCache = false;
}
// TODO: Callback buffering
if (_cache[path] && noCache !== true) {
return cb(null, _cache[path]);
}
read(path, (err, data) => {
if (err) { return cb(err); }
cb(null, _cache[path] = data);
});
} | javascript | function readFileCache (path, noCache, cb) {
path = abs(path);
if (typeof noCache === "function") {
cb = noCache;
noCache = false;
}
// TODO: Callback buffering
if (_cache[path] && noCache !== true) {
return cb(null, _cache[path]);
}
read(path, (err, data) => {
if (err) { return cb(err); }
cb(null, _cache[path] = data);
});
} | [
"function",
"readFileCache",
"(",
"path",
",",
"noCache",
",",
"cb",
")",
"{",
"path",
"=",
"abs",
"(",
"path",
")",
";",
"if",
"(",
"typeof",
"noCache",
"===",
"\"function\"",
")",
"{",
"cb",
"=",
"noCache",
";",
"noCache",
"=",
"false",
";",
"}",
"// TODO: Callback buffering",
"if",
"(",
"_cache",
"[",
"path",
"]",
"&&",
"noCache",
"!==",
"true",
")",
"{",
"return",
"cb",
"(",
"null",
",",
"_cache",
"[",
"path",
"]",
")",
";",
"}",
"read",
"(",
"path",
",",
"(",
"err",
",",
"data",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"cb",
"(",
"err",
")",
";",
"}",
"cb",
"(",
"null",
",",
"_cache",
"[",
"path",
"]",
"=",
"data",
")",
";",
"}",
")",
";",
"}"
]
| readFileCache
Reads the file asyncronously.
@name readFileCache
@function
@param {String} path The file path.
@param {Boolean} noCache If `true`, the file will be read from the disk.
@param {Function} cb The callback function. | [
"readFileCache",
"Reads",
"the",
"file",
"asyncronously",
"."
]
| 3bc33aa244169bdf6a48dad96b6a94dcf91d8d59 | https://github.com/IonicaBizau/read-file-cache/blob/3bc33aa244169bdf6a48dad96b6a94dcf91d8d59/lib/index.js#L19-L36 |
47,555 | ryanseys/node-jawbone-up | index.js | function(options, callback) {
request({
method: 'post',
url: options.url,
headers: {
'Authorization': 'Bearer ' + access_token,
'Content-Type': 'application/x-www-form-urlencoded'
},
form: options.data
},
function(error, response, body) {
callback(error, body);
});
} | javascript | function(options, callback) {
request({
method: 'post',
url: options.url,
headers: {
'Authorization': 'Bearer ' + access_token,
'Content-Type': 'application/x-www-form-urlencoded'
},
form: options.data
},
function(error, response, body) {
callback(error, body);
});
} | [
"function",
"(",
"options",
",",
"callback",
")",
"{",
"request",
"(",
"{",
"method",
":",
"'post'",
",",
"url",
":",
"options",
".",
"url",
",",
"headers",
":",
"{",
"'Authorization'",
":",
"'Bearer '",
"+",
"access_token",
",",
"'Content-Type'",
":",
"'application/x-www-form-urlencoded'",
"}",
",",
"form",
":",
"options",
".",
"data",
"}",
",",
"function",
"(",
"error",
",",
"response",
",",
"body",
")",
"{",
"callback",
"(",
"error",
",",
"body",
")",
";",
"}",
")",
";",
"}"
]
| Makes a POST request to the API with options.
@private
@param {Object} options Options that includes the `url` to POST and
`data` object to include in POST request.
@param {Function} callback Function to callback with response. | [
"Makes",
"a",
"POST",
"request",
"to",
"the",
"API",
"with",
"options",
"."
]
| 6856b7960530e43682e7dd9bf8d4f97e852637cf | https://github.com/ryanseys/node-jawbone-up/blob/6856b7960530e43682e7dd9bf8d4f97e852637cf/index.js#L102-L115 |
|
47,556 | dailymotion/react-collider | lib/client.js | reanderPage | function reanderPage(Handler, data) {
React.render(React.createElement(Handler, { data: data }), document);
} | javascript | function reanderPage(Handler, data) {
React.render(React.createElement(Handler, { data: data }), document);
} | [
"function",
"reanderPage",
"(",
"Handler",
",",
"data",
")",
"{",
"React",
".",
"render",
"(",
"React",
".",
"createElement",
"(",
"Handler",
",",
"{",
"data",
":",
"data",
"}",
")",
",",
"document",
")",
";",
"}"
]
| Client side rendering | [
"Client",
"side",
"rendering"
]
| 00cea5d25928d4a3ff0c68b6535edbc231d2b0a1 | https://github.com/dailymotion/react-collider/blob/00cea5d25928d4a3ff0c68b6535edbc231d2b0a1/lib/client.js#L26-L28 |
47,557 | francois2metz/node-spore | lib/httpclient.js | function(path, params) {
var queryString = this.query_string;
for (var param in params) {
var re = new RegExp(":"+ param)
var found = false;
if (path.search(re) != -1) {
path = path.replace(re, params[param]);
found = true;
}
for (var query in queryString) {
if (queryString[query].search
&& queryString[query].search(re) != -1) {
queryString[query] = queryString[query].replace(re, params[param]);
found = true;
}
}
// exclude params in headers
for (var header in this.headers) {
if (this.headers[header].search(re) != -1) {
found = true;
}
}
if (!found)
queryString[param] = params[param];
}
var query = querystring.stringify(queryString);
return path + ((query != "") ? "?"+ query : "");
} | javascript | function(path, params) {
var queryString = this.query_string;
for (var param in params) {
var re = new RegExp(":"+ param)
var found = false;
if (path.search(re) != -1) {
path = path.replace(re, params[param]);
found = true;
}
for (var query in queryString) {
if (queryString[query].search
&& queryString[query].search(re) != -1) {
queryString[query] = queryString[query].replace(re, params[param]);
found = true;
}
}
// exclude params in headers
for (var header in this.headers) {
if (this.headers[header].search(re) != -1) {
found = true;
}
}
if (!found)
queryString[param] = params[param];
}
var query = querystring.stringify(queryString);
return path + ((query != "") ? "?"+ query : "");
} | [
"function",
"(",
"path",
",",
"params",
")",
"{",
"var",
"queryString",
"=",
"this",
".",
"query_string",
";",
"for",
"(",
"var",
"param",
"in",
"params",
")",
"{",
"var",
"re",
"=",
"new",
"RegExp",
"(",
"\":\"",
"+",
"param",
")",
"var",
"found",
"=",
"false",
";",
"if",
"(",
"path",
".",
"search",
"(",
"re",
")",
"!=",
"-",
"1",
")",
"{",
"path",
"=",
"path",
".",
"replace",
"(",
"re",
",",
"params",
"[",
"param",
"]",
")",
";",
"found",
"=",
"true",
";",
"}",
"for",
"(",
"var",
"query",
"in",
"queryString",
")",
"{",
"if",
"(",
"queryString",
"[",
"query",
"]",
".",
"search",
"&&",
"queryString",
"[",
"query",
"]",
".",
"search",
"(",
"re",
")",
"!=",
"-",
"1",
")",
"{",
"queryString",
"[",
"query",
"]",
"=",
"queryString",
"[",
"query",
"]",
".",
"replace",
"(",
"re",
",",
"params",
"[",
"param",
"]",
")",
";",
"found",
"=",
"true",
";",
"}",
"}",
"// exclude params in headers",
"for",
"(",
"var",
"header",
"in",
"this",
".",
"headers",
")",
"{",
"if",
"(",
"this",
".",
"headers",
"[",
"header",
"]",
".",
"search",
"(",
"re",
")",
"!=",
"-",
"1",
")",
"{",
"found",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"!",
"found",
")",
"queryString",
"[",
"param",
"]",
"=",
"params",
"[",
"param",
"]",
";",
"}",
"var",
"query",
"=",
"querystring",
".",
"stringify",
"(",
"queryString",
")",
";",
"return",
"path",
"+",
"(",
"(",
"query",
"!=",
"\"\"",
")",
"?",
"\"?\"",
"+",
"query",
":",
"\"\"",
")",
";",
"}"
]
| Format uri with params
add orphelin params in query string | [
"Format",
"uri",
"with",
"params",
"add",
"orphelin",
"params",
"in",
"query",
"string"
]
| a74df36300852d8bab70c83506e4a3301137b6a0 | https://github.com/francois2metz/node-spore/blob/a74df36300852d8bab70c83506e4a3301137b6a0/lib/httpclient.js#L41-L68 |
|
47,558 | francois2metz/node-spore | lib/httpclient.js | function(headers, params) {
var newHeaders = {};
for (var header in headers)
newHeaders[header] = headers[header];
for (var param in params) {
var re = new RegExp(":"+ param);
for (var header in newHeaders) {
if (newHeaders[header].search(re) != -1) {
newHeaders[header] = newHeaders[header].replace(re, params[param]);
}
}
}
return newHeaders;
} | javascript | function(headers, params) {
var newHeaders = {};
for (var header in headers)
newHeaders[header] = headers[header];
for (var param in params) {
var re = new RegExp(":"+ param);
for (var header in newHeaders) {
if (newHeaders[header].search(re) != -1) {
newHeaders[header] = newHeaders[header].replace(re, params[param]);
}
}
}
return newHeaders;
} | [
"function",
"(",
"headers",
",",
"params",
")",
"{",
"var",
"newHeaders",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"header",
"in",
"headers",
")",
"newHeaders",
"[",
"header",
"]",
"=",
"headers",
"[",
"header",
"]",
";",
"for",
"(",
"var",
"param",
"in",
"params",
")",
"{",
"var",
"re",
"=",
"new",
"RegExp",
"(",
"\":\"",
"+",
"param",
")",
";",
"for",
"(",
"var",
"header",
"in",
"newHeaders",
")",
"{",
"if",
"(",
"newHeaders",
"[",
"header",
"]",
".",
"search",
"(",
"re",
")",
"!=",
"-",
"1",
")",
"{",
"newHeaders",
"[",
"header",
"]",
"=",
"newHeaders",
"[",
"header",
"]",
".",
"replace",
"(",
"re",
",",
"params",
"[",
"param",
"]",
")",
";",
"}",
"}",
"}",
"return",
"newHeaders",
";",
"}"
]
| format final headers | [
"format",
"final",
"headers"
]
| a74df36300852d8bab70c83506e4a3301137b6a0 | https://github.com/francois2metz/node-spore/blob/a74df36300852d8bab70c83506e4a3301137b6a0/lib/httpclient.js#L72-L85 |
|
47,559 | tradle/zlorp | lib/peer.js | Peer | function Peer (options) {
EventEmitter.call(this)
bindFns(this)
extend(this, options)
var addr = this.address
var hp = addr.split(':')
this.host = hp[0]
this.port = Number(hp[1])
this._deliveryTrackers = []
this.setMaxListeners(0)
this._debug('new peer')
} | javascript | function Peer (options) {
EventEmitter.call(this)
bindFns(this)
extend(this, options)
var addr = this.address
var hp = addr.split(':')
this.host = hp[0]
this.port = Number(hp[1])
this._deliveryTrackers = []
this.setMaxListeners(0)
this._debug('new peer')
} | [
"function",
"Peer",
"(",
"options",
")",
"{",
"EventEmitter",
".",
"call",
"(",
"this",
")",
"bindFns",
"(",
"this",
")",
"extend",
"(",
"this",
",",
"options",
")",
"var",
"addr",
"=",
"this",
".",
"address",
"var",
"hp",
"=",
"addr",
".",
"split",
"(",
"':'",
")",
"this",
".",
"host",
"=",
"hp",
"[",
"0",
"]",
"this",
".",
"port",
"=",
"Number",
"(",
"hp",
"[",
"1",
"]",
")",
"this",
".",
"_deliveryTrackers",
"=",
"[",
"]",
"this",
".",
"setMaxListeners",
"(",
"0",
")",
"this",
".",
"_debug",
"(",
"'new peer'",
")",
"}"
]
| A connection with whoever can prove ownership of a pubKey
@param {[type]} options [description] | [
"A",
"connection",
"with",
"whoever",
"can",
"prove",
"ownership",
"of",
"a",
"pubKey"
]
| 6d23d855fdafed49cb6d77a0e1930f6465f11d6e | https://github.com/tradle/zlorp/blob/6d23d855fdafed49cb6d77a0e1930f6465f11d6e/lib/peer.js#L29-L41 |
47,560 | levilindsey/physx | src/collisions/collision-detection/src/sphere-collision-detection.js | sphereVsPoint | function sphereVsPoint(sphere, point) {
return vec3.squaredDistance(point, sphere.centerOfVolume) <= sphere.radius * sphere.radius;
} | javascript | function sphereVsPoint(sphere, point) {
return vec3.squaredDistance(point, sphere.centerOfVolume) <= sphere.radius * sphere.radius;
} | [
"function",
"sphereVsPoint",
"(",
"sphere",
",",
"point",
")",
"{",
"return",
"vec3",
".",
"squaredDistance",
"(",
"point",
",",
"sphere",
".",
"centerOfVolume",
")",
"<=",
"sphere",
".",
"radius",
"*",
"sphere",
".",
"radius",
";",
"}"
]
| This module defines utility methods for detecting whether intersection has occurred between
spheres and other shapes.
@param {Sphere} sphere
@param {vec3} point
@returns {boolean} | [
"This",
"module",
"defines",
"utility",
"methods",
"for",
"detecting",
"whether",
"intersection",
"has",
"occurred",
"between",
"spheres",
"and",
"other",
"shapes",
"."
]
| 62df9f6968082ed34aa784a23f3db6c8feca6f3a | https://github.com/levilindsey/physx/blob/62df9f6968082ed34aa784a23f3db6c8feca6f3a/src/collisions/collision-detection/src/sphere-collision-detection.js#L15-L17 |
47,561 | joelcolucci/geolocation-distance-between | lib/index.js | _haversineCalculation | function _haversineCalculation(coordinateOne, coordinateTwo) {
// Credits
// https://www.movable-type.co.uk/scripts/latlong.html
// https://en.wikipedia.org/wiki/Haversine_formula
let latitudeOneRadians = _convertDegreesToRadians(coordinateOne.latitude);
let latitudeTwoRadians = _convertDegreesToRadians(coordinateTwo.latitude);
let longitudeOneRadians = _convertDegreesToRadians(coordinateOne.longitude);
let longitudeTwoRadians = _convertDegreesToRadians(coordinateTwo.longitude);
let differenceOfLatitude = latitudeOneRadians - latitudeTwoRadians;
let differenceOfLongitude = longitudeOneRadians - longitudeTwoRadians;
// The square of half the chord length between the points
let a = Math.sin(differenceOfLatitude / 2) * Math.sin(differenceOfLatitude / 2)
+ Math.sin(differenceOfLongitude / 2) * Math.sin(differenceOfLongitude / 2)
* Math.cos(latitudeOneRadians) * Math.cos(latitudeTwoRadians);
let angularDistanceInRadians = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
let distanceBetweenKM = EARTH_RADIUS_KM * angularDistanceInRadians;
return distanceBetweenKM;
} | javascript | function _haversineCalculation(coordinateOne, coordinateTwo) {
// Credits
// https://www.movable-type.co.uk/scripts/latlong.html
// https://en.wikipedia.org/wiki/Haversine_formula
let latitudeOneRadians = _convertDegreesToRadians(coordinateOne.latitude);
let latitudeTwoRadians = _convertDegreesToRadians(coordinateTwo.latitude);
let longitudeOneRadians = _convertDegreesToRadians(coordinateOne.longitude);
let longitudeTwoRadians = _convertDegreesToRadians(coordinateTwo.longitude);
let differenceOfLatitude = latitudeOneRadians - latitudeTwoRadians;
let differenceOfLongitude = longitudeOneRadians - longitudeTwoRadians;
// The square of half the chord length between the points
let a = Math.sin(differenceOfLatitude / 2) * Math.sin(differenceOfLatitude / 2)
+ Math.sin(differenceOfLongitude / 2) * Math.sin(differenceOfLongitude / 2)
* Math.cos(latitudeOneRadians) * Math.cos(latitudeTwoRadians);
let angularDistanceInRadians = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
let distanceBetweenKM = EARTH_RADIUS_KM * angularDistanceInRadians;
return distanceBetweenKM;
} | [
"function",
"_haversineCalculation",
"(",
"coordinateOne",
",",
"coordinateTwo",
")",
"{",
"// Credits",
"// https://www.movable-type.co.uk/scripts/latlong.html",
"// https://en.wikipedia.org/wiki/Haversine_formula",
"let",
"latitudeOneRadians",
"=",
"_convertDegreesToRadians",
"(",
"coordinateOne",
".",
"latitude",
")",
";",
"let",
"latitudeTwoRadians",
"=",
"_convertDegreesToRadians",
"(",
"coordinateTwo",
".",
"latitude",
")",
";",
"let",
"longitudeOneRadians",
"=",
"_convertDegreesToRadians",
"(",
"coordinateOne",
".",
"longitude",
")",
";",
"let",
"longitudeTwoRadians",
"=",
"_convertDegreesToRadians",
"(",
"coordinateTwo",
".",
"longitude",
")",
";",
"let",
"differenceOfLatitude",
"=",
"latitudeOneRadians",
"-",
"latitudeTwoRadians",
";",
"let",
"differenceOfLongitude",
"=",
"longitudeOneRadians",
"-",
"longitudeTwoRadians",
";",
"// The square of half the chord length between the points",
"let",
"a",
"=",
"Math",
".",
"sin",
"(",
"differenceOfLatitude",
"/",
"2",
")",
"*",
"Math",
".",
"sin",
"(",
"differenceOfLatitude",
"/",
"2",
")",
"+",
"Math",
".",
"sin",
"(",
"differenceOfLongitude",
"/",
"2",
")",
"*",
"Math",
".",
"sin",
"(",
"differenceOfLongitude",
"/",
"2",
")",
"*",
"Math",
".",
"cos",
"(",
"latitudeOneRadians",
")",
"*",
"Math",
".",
"cos",
"(",
"latitudeTwoRadians",
")",
";",
"let",
"angularDistanceInRadians",
"=",
"2",
"*",
"Math",
".",
"atan2",
"(",
"Math",
".",
"sqrt",
"(",
"a",
")",
",",
"Math",
".",
"sqrt",
"(",
"1",
"-",
"a",
")",
")",
";",
"let",
"distanceBetweenKM",
"=",
"EARTH_RADIUS_KM",
"*",
"angularDistanceInRadians",
";",
"return",
"distanceBetweenKM",
";",
"}"
]
| Return distance between two coordinates using Haversine formula
@param {Object} coordinateOne Object containing latitude, and longitude keys
@param {Object} coordinateTwo Object containing latitude, and longitude keys
@return {Float} | [
"Return",
"distance",
"between",
"two",
"coordinates",
"using",
"Haversine",
"formula"
]
| 8f5437c1a87176891febbee4dc06e51af73c7f8d | https://github.com/joelcolucci/geolocation-distance-between/blob/8f5437c1a87176891febbee4dc06e51af73c7f8d/lib/index.js#L19-L42 |
47,562 | slideme/rorschach | lib/utils.js | join | function join(args) {
var arg;
var i = 0;
var path = '';
if (arguments.length === 0) {
return utils.sep;
}
while ((arg = arguments[i++])) {
if (typeof arg !== 'string') {
throw new TypeError('utils.join() expects string arguments');
}
path += utils.sep + arg;
}
path = path.replace(/\/+/g, utils.sep);
if (path[path.length - 1] === utils.sep) {
path = path.substring(0, path.length - 1);
}
return path;
} | javascript | function join(args) {
var arg;
var i = 0;
var path = '';
if (arguments.length === 0) {
return utils.sep;
}
while ((arg = arguments[i++])) {
if (typeof arg !== 'string') {
throw new TypeError('utils.join() expects string arguments');
}
path += utils.sep + arg;
}
path = path.replace(/\/+/g, utils.sep);
if (path[path.length - 1] === utils.sep) {
path = path.substring(0, path.length - 1);
}
return path;
} | [
"function",
"join",
"(",
"args",
")",
"{",
"var",
"arg",
";",
"var",
"i",
"=",
"0",
";",
"var",
"path",
"=",
"''",
";",
"if",
"(",
"arguments",
".",
"length",
"===",
"0",
")",
"{",
"return",
"utils",
".",
"sep",
";",
"}",
"while",
"(",
"(",
"arg",
"=",
"arguments",
"[",
"i",
"++",
"]",
")",
")",
"{",
"if",
"(",
"typeof",
"arg",
"!==",
"'string'",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'utils.join() expects string arguments'",
")",
";",
"}",
"path",
"+=",
"utils",
".",
"sep",
"+",
"arg",
";",
"}",
"path",
"=",
"path",
".",
"replace",
"(",
"/",
"\\/+",
"/",
"g",
",",
"utils",
".",
"sep",
")",
";",
"if",
"(",
"path",
"[",
"path",
".",
"length",
"-",
"1",
"]",
"===",
"utils",
".",
"sep",
")",
"{",
"path",
"=",
"path",
".",
"substring",
"(",
"0",
",",
"path",
".",
"length",
"-",
"1",
")",
";",
"}",
"return",
"path",
";",
"}"
]
| Join paths.
@param {...String} args Paths
@returns {String} | [
"Join",
"paths",
"."
]
| 899339baf31682f8a62b2960cdd26fbb58a9e3a1 | https://github.com/slideme/rorschach/blob/899339baf31682f8a62b2960cdd26fbb58a9e3a1/lib/utils.js#L113-L135 |
47,563 | wprl/wainwright | index.js | extractMetadata | function extractMetadata (content, callback) {
var end;
var result;
var metadata = '';
var body = content;
// Metadata is defined by either starting and ending line,
if (content.slice(0, 3) === '---') {
result = content.match(/^-{3,}\s([\s\S]*?)-{3,}(\s[\s\S]*|\s?)$/);
if (result && result.length === 3) {
metadata = result[1];
body = result[2];
}
}
// or Markdown metadata section at beginning of file.
else if (content.slice(0, 12) === '```metadata\n') {
end = content.indexOf('\n```\n');
if (end !== -1) {
metadata = content.substring(12, end);
body = content.substring(end + 5);
}
}
parseMetadata(metadata, function (error, parsed) {
if (error) return callback(error);
callback(null, {
metadata: parsed,
body: body
});
});
} | javascript | function extractMetadata (content, callback) {
var end;
var result;
var metadata = '';
var body = content;
// Metadata is defined by either starting and ending line,
if (content.slice(0, 3) === '---') {
result = content.match(/^-{3,}\s([\s\S]*?)-{3,}(\s[\s\S]*|\s?)$/);
if (result && result.length === 3) {
metadata = result[1];
body = result[2];
}
}
// or Markdown metadata section at beginning of file.
else if (content.slice(0, 12) === '```metadata\n') {
end = content.indexOf('\n```\n');
if (end !== -1) {
metadata = content.substring(12, end);
body = content.substring(end + 5);
}
}
parseMetadata(metadata, function (error, parsed) {
if (error) return callback(error);
callback(null, {
metadata: parsed,
body: body
});
});
} | [
"function",
"extractMetadata",
"(",
"content",
",",
"callback",
")",
"{",
"var",
"end",
";",
"var",
"result",
";",
"var",
"metadata",
"=",
"''",
";",
"var",
"body",
"=",
"content",
";",
"// Metadata is defined by either starting and ending line,",
"if",
"(",
"content",
".",
"slice",
"(",
"0",
",",
"3",
")",
"===",
"'---'",
")",
"{",
"result",
"=",
"content",
".",
"match",
"(",
"/",
"^-{3,}\\s([\\s\\S]*?)-{3,}(\\s[\\s\\S]*|\\s?)$",
"/",
")",
";",
"if",
"(",
"result",
"&&",
"result",
".",
"length",
"===",
"3",
")",
"{",
"metadata",
"=",
"result",
"[",
"1",
"]",
";",
"body",
"=",
"result",
"[",
"2",
"]",
";",
"}",
"}",
"// or Markdown metadata section at beginning of file.",
"else",
"if",
"(",
"content",
".",
"slice",
"(",
"0",
",",
"12",
")",
"===",
"'```metadata\\n'",
")",
"{",
"end",
"=",
"content",
".",
"indexOf",
"(",
"'\\n```\\n'",
")",
";",
"if",
"(",
"end",
"!==",
"-",
"1",
")",
"{",
"metadata",
"=",
"content",
".",
"substring",
"(",
"12",
",",
"end",
")",
";",
"body",
"=",
"content",
".",
"substring",
"(",
"end",
"+",
"5",
")",
";",
"}",
"}",
"parseMetadata",
"(",
"metadata",
",",
"function",
"(",
"error",
",",
"parsed",
")",
"{",
"if",
"(",
"error",
")",
"return",
"callback",
"(",
"error",
")",
";",
"callback",
"(",
"null",
",",
"{",
"metadata",
":",
"parsed",
",",
"body",
":",
"body",
"}",
")",
";",
"}",
")",
";",
"}"
]
| Also from the wintersmith markdown plugin. | [
"Also",
"from",
"the",
"wintersmith",
"markdown",
"plugin",
"."
]
| 4a87298d3f097e27acf741157fe0e0b495ff4df9 | https://github.com/wprl/wainwright/blob/4a87298d3f097e27acf741157fe0e0b495ff4df9/index.js#L52-L82 |
47,564 | romainhild/node-xmlrpc-socket | lib/client.js | Client | function Client(host, port) {
// Invokes with new if called without
if (false === (this instanceof Client)) {
return new Client(host, port)
}
this.host = host;
this.port = port;
} | javascript | function Client(host, port) {
// Invokes with new if called without
if (false === (this instanceof Client)) {
return new Client(host, port)
}
this.host = host;
this.port = port;
} | [
"function",
"Client",
"(",
"host",
",",
"port",
")",
"{",
"// Invokes with new if called without",
"if",
"(",
"false",
"===",
"(",
"this",
"instanceof",
"Client",
")",
")",
"{",
"return",
"new",
"Client",
"(",
"host",
",",
"port",
")",
"}",
"this",
".",
"host",
"=",
"host",
";",
"this",
".",
"port",
"=",
"port",
";",
"}"
]
| Creates a Client object for making XML-RPC method calls via socket
@constructor
@param {String} host host to connect
@param {Number} port port to connect
@return {Client} | [
"Creates",
"a",
"Client",
"object",
"for",
"making",
"XML",
"-",
"RPC",
"method",
"calls",
"via",
"socket"
]
| 44a1112632a1db332bea3754c913609f05570d0a | https://github.com/romainhild/node-xmlrpc-socket/blob/44a1112632a1db332bea3754c913609f05570d0a/lib/client.js#L14-L22 |
47,565 | UsabilityDynamics/node-wordpress-client | lib/wordpress-client.js | Client | function Client(settings, callback) {
this.debug('new Client', settings.url);
var self = this;
// Mixing settings and emitter into instance.
require('object-emitter').mixin(this);
require('object-settings').mixin(this);
// Set defaults and instance settings.
this.set(Client.defaults).set(settings);
// Set properties from parsed URL.
this.set('hostname', this.common.parseURL(this.get('url')).hostname);
this.set('auth', this.common.parseURL(this.get('url')).auth);
this.set('blog', this.get('blog') || this.get('blogId'));
// Instance Properties.
Object.defineProperties(this, {
__client: {
value: this.common.createClient({
url: settings.url,
username: settings.username,
password: settings.password,
blogId: self.get('blog')
}),
enumerable: false,
configurable: true,
writable: false
},
__queue: {
value: [],
enumerable: false,
configurable: true,
writable: false
}
});
this.detectBlog(function (err, blog, response) {
if (err) {
return self.onceReady.call(self, err);
}
self.set('blogs', response);
// Schedule initial RPC call to verify target is valid.
self.listMethods(self.onceReady.bind(self));
// Schedule callback, if provided.
if (_.isFunction(callback)) {
self.once('connected', callback);
}
// Emit ready event on next tick.
self.nextTick(self.emit, 'ready', null, self);
});
// @chainable
return this;
} | javascript | function Client(settings, callback) {
this.debug('new Client', settings.url);
var self = this;
// Mixing settings and emitter into instance.
require('object-emitter').mixin(this);
require('object-settings').mixin(this);
// Set defaults and instance settings.
this.set(Client.defaults).set(settings);
// Set properties from parsed URL.
this.set('hostname', this.common.parseURL(this.get('url')).hostname);
this.set('auth', this.common.parseURL(this.get('url')).auth);
this.set('blog', this.get('blog') || this.get('blogId'));
// Instance Properties.
Object.defineProperties(this, {
__client: {
value: this.common.createClient({
url: settings.url,
username: settings.username,
password: settings.password,
blogId: self.get('blog')
}),
enumerable: false,
configurable: true,
writable: false
},
__queue: {
value: [],
enumerable: false,
configurable: true,
writable: false
}
});
this.detectBlog(function (err, blog, response) {
if (err) {
return self.onceReady.call(self, err);
}
self.set('blogs', response);
// Schedule initial RPC call to verify target is valid.
self.listMethods(self.onceReady.bind(self));
// Schedule callback, if provided.
if (_.isFunction(callback)) {
self.once('connected', callback);
}
// Emit ready event on next tick.
self.nextTick(self.emit, 'ready', null, self);
});
// @chainable
return this;
} | [
"function",
"Client",
"(",
"settings",
",",
"callback",
")",
"{",
"this",
".",
"debug",
"(",
"'new Client'",
",",
"settings",
".",
"url",
")",
";",
"var",
"self",
"=",
"this",
";",
"// Mixing settings and emitter into instance.",
"require",
"(",
"'object-emitter'",
")",
".",
"mixin",
"(",
"this",
")",
";",
"require",
"(",
"'object-settings'",
")",
".",
"mixin",
"(",
"this",
")",
";",
"// Set defaults and instance settings.",
"this",
".",
"set",
"(",
"Client",
".",
"defaults",
")",
".",
"set",
"(",
"settings",
")",
";",
"// Set properties from parsed URL.",
"this",
".",
"set",
"(",
"'hostname'",
",",
"this",
".",
"common",
".",
"parseURL",
"(",
"this",
".",
"get",
"(",
"'url'",
")",
")",
".",
"hostname",
")",
";",
"this",
".",
"set",
"(",
"'auth'",
",",
"this",
".",
"common",
".",
"parseURL",
"(",
"this",
".",
"get",
"(",
"'url'",
")",
")",
".",
"auth",
")",
";",
"this",
".",
"set",
"(",
"'blog'",
",",
"this",
".",
"get",
"(",
"'blog'",
")",
"||",
"this",
".",
"get",
"(",
"'blogId'",
")",
")",
";",
"// Instance Properties.",
"Object",
".",
"defineProperties",
"(",
"this",
",",
"{",
"__client",
":",
"{",
"value",
":",
"this",
".",
"common",
".",
"createClient",
"(",
"{",
"url",
":",
"settings",
".",
"url",
",",
"username",
":",
"settings",
".",
"username",
",",
"password",
":",
"settings",
".",
"password",
",",
"blogId",
":",
"self",
".",
"get",
"(",
"'blog'",
")",
"}",
")",
",",
"enumerable",
":",
"false",
",",
"configurable",
":",
"true",
",",
"writable",
":",
"false",
"}",
",",
"__queue",
":",
"{",
"value",
":",
"[",
"]",
",",
"enumerable",
":",
"false",
",",
"configurable",
":",
"true",
",",
"writable",
":",
"false",
"}",
"}",
")",
";",
"this",
".",
"detectBlog",
"(",
"function",
"(",
"err",
",",
"blog",
",",
"response",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"self",
".",
"onceReady",
".",
"call",
"(",
"self",
",",
"err",
")",
";",
"}",
"self",
".",
"set",
"(",
"'blogs'",
",",
"response",
")",
";",
"// Schedule initial RPC call to verify target is valid.",
"self",
".",
"listMethods",
"(",
"self",
".",
"onceReady",
".",
"bind",
"(",
"self",
")",
")",
";",
"// Schedule callback, if provided.",
"if",
"(",
"_",
".",
"isFunction",
"(",
"callback",
")",
")",
"{",
"self",
".",
"once",
"(",
"'connected'",
",",
"callback",
")",
";",
"}",
"// Emit ready event on next tick.",
"self",
".",
"nextTick",
"(",
"self",
".",
"emit",
",",
"'ready'",
",",
"null",
",",
"self",
")",
";",
"}",
")",
";",
"// @chainable",
"return",
"this",
";",
"}"
]
| WordPress Client.
@todo Add support for 30X redirect.
### Events
* ready - Once client instance created.
* connected - Once client instance created and list of supported methods is returned.
* authenticated - Once client instance created and list of supported methods is returned.
* error - Emitted on any response error.
### Settings
* url - URL to XML-RPC endpoint.
* username - Username to use.
* password - Password to use.
* blog - ID of blog
* key - As an alternative to usrname and password, if WordPress site supports it.
* methods - Set with supported RPC methods once client connection is created.
* forceBlog - when true blog detection function will not replace blogId if it doesn't equal to found one
@param settings
@param callback
@returns {Client}
@constructor | [
"WordPress",
"Client",
"."
]
| 2b47a7c5cadd3d8f2cfd255f997f36af14a5d843 | https://github.com/UsabilityDynamics/node-wordpress-client/blob/2b47a7c5cadd3d8f2cfd255f997f36af14a5d843/lib/wordpress-client.js#L30-L88 |
47,566 | UsabilityDynamics/node-wordpress-client | lib/wordpress-client.js | onceReady | function onceReady(error, methods) {
this.debug(error ? 'No methods (%d) found, unable to connect to %s.' : 'onceReady: Found %d methods on %s.', ( methods ? methods.length : 0 ), this.get('url'));
// Set Methods.
this.set('methods', this.common.trim(methods));
if (error) {
this.emit('error', error, this);
}
this.emit('connected', error, this);
// @chainable
return this;
} | javascript | function onceReady(error, methods) {
this.debug(error ? 'No methods (%d) found, unable to connect to %s.' : 'onceReady: Found %d methods on %s.', ( methods ? methods.length : 0 ), this.get('url'));
// Set Methods.
this.set('methods', this.common.trim(methods));
if (error) {
this.emit('error', error, this);
}
this.emit('connected', error, this);
// @chainable
return this;
} | [
"function",
"onceReady",
"(",
"error",
",",
"methods",
")",
"{",
"this",
".",
"debug",
"(",
"error",
"?",
"'No methods (%d) found, unable to connect to %s.'",
":",
"'onceReady: Found %d methods on %s.'",
",",
"(",
"methods",
"?",
"methods",
".",
"length",
":",
"0",
")",
",",
"this",
".",
"get",
"(",
"'url'",
")",
")",
";",
"// Set Methods.",
"this",
".",
"set",
"(",
"'methods'",
",",
"this",
".",
"common",
".",
"trim",
"(",
"methods",
")",
")",
";",
"if",
"(",
"error",
")",
"{",
"this",
".",
"emit",
"(",
"'error'",
",",
"error",
",",
"this",
")",
";",
"}",
"this",
".",
"emit",
"(",
"'connected'",
",",
"error",
",",
"this",
")",
";",
"// @chainable",
"return",
"this",
";",
"}"
]
| Callback for Connection Verification.
@param error
@param methods
@returns {*} | [
"Callback",
"for",
"Connection",
"Verification",
"."
]
| 2b47a7c5cadd3d8f2cfd255f997f36af14a5d843 | https://github.com/UsabilityDynamics/node-wordpress-client/blob/2b47a7c5cadd3d8f2cfd255f997f36af14a5d843/lib/wordpress-client.js#L103-L118 |
47,567 | UsabilityDynamics/node-wordpress-client | lib/wordpress-client.js | callbackWrapper | function callbackWrapper(error, response) {
self.debug('methodCall->callbackWrapper', error, response);
// TODO: error should be customized to handle more error types
if (error /*&& error.code === "ENOTFOUND" && error.syscall === "getaddrinfo"*/) {
error.message = "Unable to connect to WordPress.";
return callback.call(self, error);
}
// Parse Response.
if (_.isString(response) && self.common.is_numeric(response)) {
response = parseInt(response);
}
callback.call(self, error, response);
} | javascript | function callbackWrapper(error, response) {
self.debug('methodCall->callbackWrapper', error, response);
// TODO: error should be customized to handle more error types
if (error /*&& error.code === "ENOTFOUND" && error.syscall === "getaddrinfo"*/) {
error.message = "Unable to connect to WordPress.";
return callback.call(self, error);
}
// Parse Response.
if (_.isString(response) && self.common.is_numeric(response)) {
response = parseInt(response);
}
callback.call(self, error, response);
} | [
"function",
"callbackWrapper",
"(",
"error",
",",
"response",
")",
"{",
"self",
".",
"debug",
"(",
"'methodCall->callbackWrapper'",
",",
"error",
",",
"response",
")",
";",
"// TODO: error should be customized to handle more error types",
"if",
"(",
"error",
"/*&& error.code === \"ENOTFOUND\" && error.syscall === \"getaddrinfo\"*/",
")",
"{",
"error",
".",
"message",
"=",
"\"Unable to connect to WordPress.\"",
";",
"return",
"callback",
".",
"call",
"(",
"self",
",",
"error",
")",
";",
"}",
"// Parse Response.",
"if",
"(",
"_",
".",
"isString",
"(",
"response",
")",
"&&",
"self",
".",
"common",
".",
"is_numeric",
"(",
"response",
")",
")",
"{",
"response",
"=",
"parseInt",
"(",
"response",
")",
";",
"}",
"callback",
".",
"call",
"(",
"self",
",",
"error",
",",
"response",
")",
";",
"}"
]
| Handle RPC Method Callback.
@param {Error} error
@param {string} response
@returns {*} | [
"Handle",
"RPC",
"Method",
"Callback",
"."
]
| 2b47a7c5cadd3d8f2cfd255f997f36af14a5d843 | https://github.com/UsabilityDynamics/node-wordpress-client/blob/2b47a7c5cadd3d8f2cfd255f997f36af14a5d843/lib/wordpress-client.js#L193-L206 |
47,568 | UsabilityDynamics/node-wordpress-client | lib/wordpress-client.js | nextTick | function nextTick(callback) {
var context = this;
var args = Array.prototype.slice.call(arguments, 1);
// Do not schedule callback if not a valid function.
if ('function' !== typeof callback) {
return this;
}
// Execute callback on next tick.
process.nextTick(function nextTickHandler() {
context.debug('nextTick', callback.name);
callback.apply(context, args);
});
// @chainable
return this;
} | javascript | function nextTick(callback) {
var context = this;
var args = Array.prototype.slice.call(arguments, 1);
// Do not schedule callback if not a valid function.
if ('function' !== typeof callback) {
return this;
}
// Execute callback on next tick.
process.nextTick(function nextTickHandler() {
context.debug('nextTick', callback.name);
callback.apply(context, args);
});
// @chainable
return this;
} | [
"function",
"nextTick",
"(",
"callback",
")",
"{",
"var",
"context",
"=",
"this",
";",
"var",
"args",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"1",
")",
";",
"// Do not schedule callback if not a valid function.",
"if",
"(",
"'function'",
"!==",
"typeof",
"callback",
")",
"{",
"return",
"this",
";",
"}",
"// Execute callback on next tick.",
"process",
".",
"nextTick",
"(",
"function",
"nextTickHandler",
"(",
")",
"{",
"context",
".",
"debug",
"(",
"'nextTick'",
",",
"callback",
".",
"name",
")",
";",
"callback",
".",
"apply",
"(",
"context",
",",
"args",
")",
";",
"}",
")",
";",
"// @chainable",
"return",
"this",
";",
"}"
]
| Call Method on Next Tick.
@param callback
@returns {*} | [
"Call",
"Method",
"on",
"Next",
"Tick",
"."
]
| 2b47a7c5cadd3d8f2cfd255f997f36af14a5d843 | https://github.com/UsabilityDynamics/node-wordpress-client/blob/2b47a7c5cadd3d8f2cfd255f997f36af14a5d843/lib/wordpress-client.js#L435-L454 |
47,569 | levilindsey/physx | src/collisions/contact-calculation/src/capsule-contact-calculation.js | capsuleVsSphere | function capsuleVsSphere(contactPoint, contactNormal, capsule, sphere) {
const sphereCenter = sphere.centerOfVolume;
findClosestPointOnSegmentToPoint(contactPoint, capsule.segment, sphereCenter);
vec3.subtract(contactNormal, sphereCenter, contactPoint);
vec3.normalize(contactNormal, contactNormal);
vec3.scaleAndAdd(contactPoint, contactPoint, contactNormal, capsule.radius);
} | javascript | function capsuleVsSphere(contactPoint, contactNormal, capsule, sphere) {
const sphereCenter = sphere.centerOfVolume;
findClosestPointOnSegmentToPoint(contactPoint, capsule.segment, sphereCenter);
vec3.subtract(contactNormal, sphereCenter, contactPoint);
vec3.normalize(contactNormal, contactNormal);
vec3.scaleAndAdd(contactPoint, contactPoint, contactNormal, capsule.radius);
} | [
"function",
"capsuleVsSphere",
"(",
"contactPoint",
",",
"contactNormal",
",",
"capsule",
",",
"sphere",
")",
"{",
"const",
"sphereCenter",
"=",
"sphere",
".",
"centerOfVolume",
";",
"findClosestPointOnSegmentToPoint",
"(",
"contactPoint",
",",
"capsule",
".",
"segment",
",",
"sphereCenter",
")",
";",
"vec3",
".",
"subtract",
"(",
"contactNormal",
",",
"sphereCenter",
",",
"contactPoint",
")",
";",
"vec3",
".",
"normalize",
"(",
"contactNormal",
",",
"contactNormal",
")",
";",
"vec3",
".",
"scaleAndAdd",
"(",
"contactPoint",
",",
"contactPoint",
",",
"contactNormal",
",",
"capsule",
".",
"radius",
")",
";",
"}"
]
| Finds the closest point on the surface of the capsule to the sphere center.
@param {vec3} contactPoint Output param.
@param {vec3} contactNormal Output param.
@param {Capsule} capsule
@param {Sphere} sphere | [
"Finds",
"the",
"closest",
"point",
"on",
"the",
"surface",
"of",
"the",
"capsule",
"to",
"the",
"sphere",
"center",
"."
]
| 62df9f6968082ed34aa784a23f3db6c8feca6f3a | https://github.com/levilindsey/physx/blob/62df9f6968082ed34aa784a23f3db6c8feca6f3a/src/collisions/contact-calculation/src/capsule-contact-calculation.js#L39-L45 |
47,570 | levilindsey/physx | src/collisions/contact-calculation/src/capsule-contact-calculation.js | capsuleVsAabb | function capsuleVsAabb(contactPoint, contactNormal, capsule, aabb) {
// tmpVec1 represents the closest point on the capsule to the AABB. tmpVec2
// represents the closest point on the AABB to the capsule.
//
// Check whether the two capsule ends intersect the AABB (sphere vs AABB) (addresses the
// capsule-vs-AABB-face case).
//
const squaredRadius = capsule.radius * capsule.radius;
let doesAabbIntersectAnEndPoint = false;
let endPoint = capsule.segment.start;
findClosestPointFromAabbToPoint(tmpVec2, aabb, endPoint);
if (vec3.squaredDistance(tmpVec2, endPoint) <= squaredRadius) {
doesAabbIntersectAnEndPoint = true;
} else {
endPoint = capsule.segment.end;
findClosestPointFromAabbToPoint(tmpVec2, aabb, endPoint);
if (vec3.squaredDistance(tmpVec2, endPoint) <= squaredRadius) {
doesAabbIntersectAnEndPoint = true;
}
}
if (!doesAabbIntersectAnEndPoint) {
//
// Check whether the capsule intersects with any AABB edge (addresses the capsule-vs-AABB-edge
// case).
//
aabb.someEdge(edge => {
findClosestPointsFromSegmentToSegment(tmpVec1, tmpVec2,
capsule.segment, edge);
const distance = vec3.squaredDistance(tmpVec1, tmpVec2);
return distance <= squaredRadius;
});
}
// (The capsule-vs-AABB-vertex case is covered by the capsule-vs-AABB-edge case).
findClosestPointOnSegmentToPoint(tmpVec1, capsule.segment, tmpVec2);
vec3.subtract(contactNormal, tmpVec2, tmpVec1);
vec3.normalize(contactNormal, contactNormal);
vec3.scaleAndAdd(contactPoint, tmpVec1, contactNormal, capsule.radius);
} | javascript | function capsuleVsAabb(contactPoint, contactNormal, capsule, aabb) {
// tmpVec1 represents the closest point on the capsule to the AABB. tmpVec2
// represents the closest point on the AABB to the capsule.
//
// Check whether the two capsule ends intersect the AABB (sphere vs AABB) (addresses the
// capsule-vs-AABB-face case).
//
const squaredRadius = capsule.radius * capsule.radius;
let doesAabbIntersectAnEndPoint = false;
let endPoint = capsule.segment.start;
findClosestPointFromAabbToPoint(tmpVec2, aabb, endPoint);
if (vec3.squaredDistance(tmpVec2, endPoint) <= squaredRadius) {
doesAabbIntersectAnEndPoint = true;
} else {
endPoint = capsule.segment.end;
findClosestPointFromAabbToPoint(tmpVec2, aabb, endPoint);
if (vec3.squaredDistance(tmpVec2, endPoint) <= squaredRadius) {
doesAabbIntersectAnEndPoint = true;
}
}
if (!doesAabbIntersectAnEndPoint) {
//
// Check whether the capsule intersects with any AABB edge (addresses the capsule-vs-AABB-edge
// case).
//
aabb.someEdge(edge => {
findClosestPointsFromSegmentToSegment(tmpVec1, tmpVec2,
capsule.segment, edge);
const distance = vec3.squaredDistance(tmpVec1, tmpVec2);
return distance <= squaredRadius;
});
}
// (The capsule-vs-AABB-vertex case is covered by the capsule-vs-AABB-edge case).
findClosestPointOnSegmentToPoint(tmpVec1, capsule.segment, tmpVec2);
vec3.subtract(contactNormal, tmpVec2, tmpVec1);
vec3.normalize(contactNormal, contactNormal);
vec3.scaleAndAdd(contactPoint, tmpVec1, contactNormal, capsule.radius);
} | [
"function",
"capsuleVsAabb",
"(",
"contactPoint",
",",
"contactNormal",
",",
"capsule",
",",
"aabb",
")",
"{",
"// tmpVec1 represents the closest point on the capsule to the AABB. tmpVec2",
"// represents the closest point on the AABB to the capsule.",
"//",
"// Check whether the two capsule ends intersect the AABB (sphere vs AABB) (addresses the",
"// capsule-vs-AABB-face case).",
"//",
"const",
"squaredRadius",
"=",
"capsule",
".",
"radius",
"*",
"capsule",
".",
"radius",
";",
"let",
"doesAabbIntersectAnEndPoint",
"=",
"false",
";",
"let",
"endPoint",
"=",
"capsule",
".",
"segment",
".",
"start",
";",
"findClosestPointFromAabbToPoint",
"(",
"tmpVec2",
",",
"aabb",
",",
"endPoint",
")",
";",
"if",
"(",
"vec3",
".",
"squaredDistance",
"(",
"tmpVec2",
",",
"endPoint",
")",
"<=",
"squaredRadius",
")",
"{",
"doesAabbIntersectAnEndPoint",
"=",
"true",
";",
"}",
"else",
"{",
"endPoint",
"=",
"capsule",
".",
"segment",
".",
"end",
";",
"findClosestPointFromAabbToPoint",
"(",
"tmpVec2",
",",
"aabb",
",",
"endPoint",
")",
";",
"if",
"(",
"vec3",
".",
"squaredDistance",
"(",
"tmpVec2",
",",
"endPoint",
")",
"<=",
"squaredRadius",
")",
"{",
"doesAabbIntersectAnEndPoint",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"!",
"doesAabbIntersectAnEndPoint",
")",
"{",
"//",
"// Check whether the capsule intersects with any AABB edge (addresses the capsule-vs-AABB-edge",
"// case).",
"//",
"aabb",
".",
"someEdge",
"(",
"edge",
"=>",
"{",
"findClosestPointsFromSegmentToSegment",
"(",
"tmpVec1",
",",
"tmpVec2",
",",
"capsule",
".",
"segment",
",",
"edge",
")",
";",
"const",
"distance",
"=",
"vec3",
".",
"squaredDistance",
"(",
"tmpVec1",
",",
"tmpVec2",
")",
";",
"return",
"distance",
"<=",
"squaredRadius",
";",
"}",
")",
";",
"}",
"// (The capsule-vs-AABB-vertex case is covered by the capsule-vs-AABB-edge case).",
"findClosestPointOnSegmentToPoint",
"(",
"tmpVec1",
",",
"capsule",
".",
"segment",
",",
"tmpVec2",
")",
";",
"vec3",
".",
"subtract",
"(",
"contactNormal",
",",
"tmpVec2",
",",
"tmpVec1",
")",
";",
"vec3",
".",
"normalize",
"(",
"contactNormal",
",",
"contactNormal",
")",
";",
"vec3",
".",
"scaleAndAdd",
"(",
"contactPoint",
",",
"tmpVec1",
",",
"contactNormal",
",",
"capsule",
".",
"radius",
")",
";",
"}"
]
| Finds the closest point on the surface of the capsule to the AABB.
NOTE: This implementation cheats by checking whether vertices from one shape lie within the
other. Due to the tunnelling problem, it is possible that intersection occurs without any
vertices lying within the other shape. However, (A) this is unlikely, and (B) we are ignoring the
tunnelling problem for the rest of this collision system anyway.
@param {vec3} contactPoint Output param.
@param {vec3} contactNormal Output param.
@param {Capsule} capsule
@param {Aabb} aabb | [
"Finds",
"the",
"closest",
"point",
"on",
"the",
"surface",
"of",
"the",
"capsule",
"to",
"the",
"AABB",
"."
]
| 62df9f6968082ed34aa784a23f3db6c8feca6f3a | https://github.com/levilindsey/physx/blob/62df9f6968082ed34aa784a23f3db6c8feca6f3a/src/collisions/contact-calculation/src/capsule-contact-calculation.js#L60-L103 |
47,571 | levilindsey/physx | src/collisions/contact-calculation/src/capsule-contact-calculation.js | capsuleVsCapsule | function capsuleVsCapsule(contactPoint, contactNormal, capsuleA, capsuleB) {
findClosestPointsFromSegmentToSegment(tmpVec1, tmpVec2,
capsuleA.segment, capsuleB.segment);
vec3.subtract(contactNormal, tmpVec2, tmpVec1);
vec3.normalize(contactNormal, contactNormal);
vec3.scaleAndAdd(contactPoint, tmpVec1, contactNormal, capsuleA.radius);
} | javascript | function capsuleVsCapsule(contactPoint, contactNormal, capsuleA, capsuleB) {
findClosestPointsFromSegmentToSegment(tmpVec1, tmpVec2,
capsuleA.segment, capsuleB.segment);
vec3.subtract(contactNormal, tmpVec2, tmpVec1);
vec3.normalize(contactNormal, contactNormal);
vec3.scaleAndAdd(contactPoint, tmpVec1, contactNormal, capsuleA.radius);
} | [
"function",
"capsuleVsCapsule",
"(",
"contactPoint",
",",
"contactNormal",
",",
"capsuleA",
",",
"capsuleB",
")",
"{",
"findClosestPointsFromSegmentToSegment",
"(",
"tmpVec1",
",",
"tmpVec2",
",",
"capsuleA",
".",
"segment",
",",
"capsuleB",
".",
"segment",
")",
";",
"vec3",
".",
"subtract",
"(",
"contactNormal",
",",
"tmpVec2",
",",
"tmpVec1",
")",
";",
"vec3",
".",
"normalize",
"(",
"contactNormal",
",",
"contactNormal",
")",
";",
"vec3",
".",
"scaleAndAdd",
"(",
"contactPoint",
",",
"tmpVec1",
",",
"contactNormal",
",",
"capsuleA",
".",
"radius",
")",
";",
"}"
]
| Finds the closest point on the surface of capsule A to capsule B.
@param {vec3} contactPoint Output param.
@param {vec3} contactNormal Output param.
@param {Capsule} capsuleA
@param {Capsule} capsuleB | [
"Finds",
"the",
"closest",
"point",
"on",
"the",
"surface",
"of",
"capsule",
"A",
"to",
"capsule",
"B",
"."
]
| 62df9f6968082ed34aa784a23f3db6c8feca6f3a | https://github.com/levilindsey/physx/blob/62df9f6968082ed34aa784a23f3db6c8feca6f3a/src/collisions/contact-calculation/src/capsule-contact-calculation.js#L124-L130 |
47,572 | GochoMugo/elbow | src/lib/index.js | loadSchema | function loadSchema(uri) {
return new Promise(function(resolve, reject) {
request.get(uri).end(function(error, response) {
if (error || !response.ok) {
error = error || new Error(response.body);
debug("error fetching remote schema:", error);
return reject(error);
}
return resolve(response.body);
});
});
} | javascript | function loadSchema(uri) {
return new Promise(function(resolve, reject) {
request.get(uri).end(function(error, response) {
if (error || !response.ok) {
error = error || new Error(response.body);
debug("error fetching remote schema:", error);
return reject(error);
}
return resolve(response.body);
});
});
} | [
"function",
"loadSchema",
"(",
"uri",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"request",
".",
"get",
"(",
"uri",
")",
".",
"end",
"(",
"function",
"(",
"error",
",",
"response",
")",
"{",
"if",
"(",
"error",
"||",
"!",
"response",
".",
"ok",
")",
"{",
"error",
"=",
"error",
"||",
"new",
"Error",
"(",
"response",
".",
"body",
")",
";",
"debug",
"(",
"\"error fetching remote schema:\"",
",",
"error",
")",
";",
"return",
"reject",
"(",
"error",
")",
";",
"}",
"return",
"resolve",
"(",
"response",
".",
"body",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| Loads schema from remote server using a HTTP URI.
@private
@param {String} uri - HTTP URI to schema
@return {Promise}
@see https://github.com/epoberezkin/ajv#asynchronous-schema-compilation | [
"Loads",
"schema",
"from",
"remote",
"server",
"using",
"a",
"HTTP",
"URI",
"."
]
| 2211c50c6019dc45acb192e07f765ab0daabe3cd | https://github.com/GochoMugo/elbow/blob/2211c50c6019dc45acb192e07f765ab0daabe3cd/src/lib/index.js#L44-L55 |
47,573 | GochoMugo/elbow | src/lib/index.js | requireAll | function requireAll(schemaDir, options, callback) {
debug("loading schemas");
if (!callback) {
callback = options;
options = {};
}
const opts = _.assign({
extensions: ["json"],
}, options);
let files;
try {
files = fs.readdirSync(schemaDir);
} catch(errReaddir) {
return callback(errReaddir);
}
let schemas = [];
for (let index = 0; index < files.length; index++) {
const file = files[index];
const ext = path.extname(file).slice(1);
if (opts.extensions.indexOf(ext) === -1) {
continue;
}
const abspath = path.join(schemaDir, file);
let schema;
// try load the schema! If it fails, stop immediately
try {
schema = require(abspath);
} catch (errRequire) {
return callback(errRequire);
}
schema.filepath = abspath;
schemas.push(schema);
}
return callback(null, schemas);
} | javascript | function requireAll(schemaDir, options, callback) {
debug("loading schemas");
if (!callback) {
callback = options;
options = {};
}
const opts = _.assign({
extensions: ["json"],
}, options);
let files;
try {
files = fs.readdirSync(schemaDir);
} catch(errReaddir) {
return callback(errReaddir);
}
let schemas = [];
for (let index = 0; index < files.length; index++) {
const file = files[index];
const ext = path.extname(file).slice(1);
if (opts.extensions.indexOf(ext) === -1) {
continue;
}
const abspath = path.join(schemaDir, file);
let schema;
// try load the schema! If it fails, stop immediately
try {
schema = require(abspath);
} catch (errRequire) {
return callback(errRequire);
}
schema.filepath = abspath;
schemas.push(schema);
}
return callback(null, schemas);
} | [
"function",
"requireAll",
"(",
"schemaDir",
",",
"options",
",",
"callback",
")",
"{",
"debug",
"(",
"\"loading schemas\"",
")",
";",
"if",
"(",
"!",
"callback",
")",
"{",
"callback",
"=",
"options",
";",
"options",
"=",
"{",
"}",
";",
"}",
"const",
"opts",
"=",
"_",
".",
"assign",
"(",
"{",
"extensions",
":",
"[",
"\"json\"",
"]",
",",
"}",
",",
"options",
")",
";",
"let",
"files",
";",
"try",
"{",
"files",
"=",
"fs",
".",
"readdirSync",
"(",
"schemaDir",
")",
";",
"}",
"catch",
"(",
"errReaddir",
")",
"{",
"return",
"callback",
"(",
"errReaddir",
")",
";",
"}",
"let",
"schemas",
"=",
"[",
"]",
";",
"for",
"(",
"let",
"index",
"=",
"0",
";",
"index",
"<",
"files",
".",
"length",
";",
"index",
"++",
")",
"{",
"const",
"file",
"=",
"files",
"[",
"index",
"]",
";",
"const",
"ext",
"=",
"path",
".",
"extname",
"(",
"file",
")",
".",
"slice",
"(",
"1",
")",
";",
"if",
"(",
"opts",
".",
"extensions",
".",
"indexOf",
"(",
"ext",
")",
"===",
"-",
"1",
")",
"{",
"continue",
";",
"}",
"const",
"abspath",
"=",
"path",
".",
"join",
"(",
"schemaDir",
",",
"file",
")",
";",
"let",
"schema",
";",
"// try load the schema! If it fails, stop immediately",
"try",
"{",
"schema",
"=",
"require",
"(",
"abspath",
")",
";",
"}",
"catch",
"(",
"errRequire",
")",
"{",
"return",
"callback",
"(",
"errRequire",
")",
";",
"}",
"schema",
".",
"filepath",
"=",
"abspath",
";",
"schemas",
".",
"push",
"(",
"schema",
")",
";",
"}",
"return",
"callback",
"(",
"null",
",",
"schemas",
")",
";",
"}"
]
| Loads all the Schemas into memory.
@param {String} schemaDir - path to directory holding schemas
@param {Object} [options]
@param {String[]} [options.extensions=["json"]] Extension of schema files
@param {Function} callback - callback(err, schemas) | [
"Loads",
"all",
"the",
"Schemas",
"into",
"memory",
"."
]
| 2211c50c6019dc45acb192e07f765ab0daabe3cd | https://github.com/GochoMugo/elbow/blob/2211c50c6019dc45acb192e07f765ab0daabe3cd/src/lib/index.js#L66-L108 |
47,574 | GochoMugo/elbow | src/lib/index.js | expandVars | function expandVars(target, options) {
const vars = options.vars || {};
const regexp = /\$\{(\w+)\}/g;
if (typeof target === "string") {
return _expand(target);
}
for (let key in target) {
target[key] = _expand(target[key]);
}
return target;
function _expand(val) {
let expanded = val;
let match;
while (match = regexp.exec(val)) {
const varname = match[1];
const varval = vars[varname] || process.env[varname];
if (!varval) {
debug(`could not expand variable \${${varname}}`);
continue;
}
expanded = expanded.replace(`\${${varname}}`, varval);
}
return expanded;
}
} | javascript | function expandVars(target, options) {
const vars = options.vars || {};
const regexp = /\$\{(\w+)\}/g;
if (typeof target === "string") {
return _expand(target);
}
for (let key in target) {
target[key] = _expand(target[key]);
}
return target;
function _expand(val) {
let expanded = val;
let match;
while (match = regexp.exec(val)) {
const varname = match[1];
const varval = vars[varname] || process.env[varname];
if (!varval) {
debug(`could not expand variable \${${varname}}`);
continue;
}
expanded = expanded.replace(`\${${varname}}`, varval);
}
return expanded;
}
} | [
"function",
"expandVars",
"(",
"target",
",",
"options",
")",
"{",
"const",
"vars",
"=",
"options",
".",
"vars",
"||",
"{",
"}",
";",
"const",
"regexp",
"=",
"/",
"\\$\\{(\\w+)\\}",
"/",
"g",
";",
"if",
"(",
"typeof",
"target",
"===",
"\"string\"",
")",
"{",
"return",
"_expand",
"(",
"target",
")",
";",
"}",
"for",
"(",
"let",
"key",
"in",
"target",
")",
"{",
"target",
"[",
"key",
"]",
"=",
"_expand",
"(",
"target",
"[",
"key",
"]",
")",
";",
"}",
"return",
"target",
";",
"function",
"_expand",
"(",
"val",
")",
"{",
"let",
"expanded",
"=",
"val",
";",
"let",
"match",
";",
"while",
"(",
"match",
"=",
"regexp",
".",
"exec",
"(",
"val",
")",
")",
"{",
"const",
"varname",
"=",
"match",
"[",
"1",
"]",
";",
"const",
"varval",
"=",
"vars",
"[",
"varname",
"]",
"||",
"process",
".",
"env",
"[",
"varname",
"]",
";",
"if",
"(",
"!",
"varval",
")",
"{",
"debug",
"(",
"`",
"\\$",
"${",
"varname",
"}",
"`",
")",
";",
"continue",
";",
"}",
"expanded",
"=",
"expanded",
".",
"replace",
"(",
"`",
"\\$",
"${",
"varname",
"}",
"`",
",",
"varval",
")",
";",
"}",
"return",
"expanded",
";",
"}",
"}"
]
| Expand variables, using variables from the `options` object,
or process environment.
Modifies the passed object in place.
@private
@param {String|Object} target - object with parameters
@param {Object} options - test configurations
@return {String|Object} | [
"Expand",
"variables",
"using",
"variables",
"from",
"the",
"options",
"object",
"or",
"process",
"environment",
".",
"Modifies",
"the",
"passed",
"object",
"in",
"place",
"."
]
| 2211c50c6019dc45acb192e07f765ab0daabe3cd | https://github.com/GochoMugo/elbow/blob/2211c50c6019dc45acb192e07f765ab0daabe3cd/src/lib/index.js#L183-L210 |
47,575 | GochoMugo/elbow | src/lib/index.js | validateResponse | function validateResponse(schema, response, options, done) {
debug(`validating response for ${schema.endpoint}`);
// testing status code
if (schema.status) {
should(response.status).eql(schema.status);
}
return validator.compileAsync(schema).then((validate) => {
const valid = validate(response.body);
if (!valid) {
const errors = validate.errors;
should(errors).not.be.ok();
return done(errors);
}
if (schema.export) {
const body = response.body;
options.vars = options.vars || {};
for (let dest in schema.export) {
const propPath = schema.export[dest];
_.set(options.vars, dest, _.get(body, propPath));
}
}
return done(null, response);
}).catch(done);
} | javascript | function validateResponse(schema, response, options, done) {
debug(`validating response for ${schema.endpoint}`);
// testing status code
if (schema.status) {
should(response.status).eql(schema.status);
}
return validator.compileAsync(schema).then((validate) => {
const valid = validate(response.body);
if (!valid) {
const errors = validate.errors;
should(errors).not.be.ok();
return done(errors);
}
if (schema.export) {
const body = response.body;
options.vars = options.vars || {};
for (let dest in schema.export) {
const propPath = schema.export[dest];
_.set(options.vars, dest, _.get(body, propPath));
}
}
return done(null, response);
}).catch(done);
} | [
"function",
"validateResponse",
"(",
"schema",
",",
"response",
",",
"options",
",",
"done",
")",
"{",
"debug",
"(",
"`",
"${",
"schema",
".",
"endpoint",
"}",
"`",
")",
";",
"// testing status code",
"if",
"(",
"schema",
".",
"status",
")",
"{",
"should",
"(",
"response",
".",
"status",
")",
".",
"eql",
"(",
"schema",
".",
"status",
")",
";",
"}",
"return",
"validator",
".",
"compileAsync",
"(",
"schema",
")",
".",
"then",
"(",
"(",
"validate",
")",
"=>",
"{",
"const",
"valid",
"=",
"validate",
"(",
"response",
".",
"body",
")",
";",
"if",
"(",
"!",
"valid",
")",
"{",
"const",
"errors",
"=",
"validate",
".",
"errors",
";",
"should",
"(",
"errors",
")",
".",
"not",
".",
"be",
".",
"ok",
"(",
")",
";",
"return",
"done",
"(",
"errors",
")",
";",
"}",
"if",
"(",
"schema",
".",
"export",
")",
"{",
"const",
"body",
"=",
"response",
".",
"body",
";",
"options",
".",
"vars",
"=",
"options",
".",
"vars",
"||",
"{",
"}",
";",
"for",
"(",
"let",
"dest",
"in",
"schema",
".",
"export",
")",
"{",
"const",
"propPath",
"=",
"schema",
".",
"export",
"[",
"dest",
"]",
";",
"_",
".",
"set",
"(",
"options",
".",
"vars",
",",
"dest",
",",
"_",
".",
"get",
"(",
"body",
",",
"propPath",
")",
")",
";",
"}",
"}",
"return",
"done",
"(",
"null",
",",
"response",
")",
";",
"}",
")",
".",
"catch",
"(",
"done",
")",
";",
"}"
]
| Validate a Http response using schema.
This handles the actual JSON schema validation.
@private
@param {Object} schema - schema used to validate against
@param {*} response - http response
@param {Object} options - test configurations
@param {Function} done - called once validation is completed
@TODO Remove our "extensions" i.e. any custom properties in the
schema that we have added for the purpose of the elbow utility. | [
"Validate",
"a",
"Http",
"response",
"using",
"schema",
".",
"This",
"handles",
"the",
"actual",
"JSON",
"schema",
"validation",
"."
]
| 2211c50c6019dc45acb192e07f765ab0daabe3cd | https://github.com/GochoMugo/elbow/blob/2211c50c6019dc45acb192e07f765ab0daabe3cd/src/lib/index.js#L226-L249 |
47,576 | GochoMugo/elbow | src/lib/index.js | makeRequest | function makeRequest(baseUrl, method, schema, options, done) {
debug(`making ${method.toUpperCase()} request to ${schema.endpoint}`);
const endpoint = expandVars(schema.endpoint, options);
const apiPath = url.resolve(baseUrl + "/", _.trimStart(endpoint, "/"));
const headers = Object.assign({}, options.headers, schema.headers);
const query = Object.assign({}, options.query, schema.query);
const body = Object.assign({}, options.body, schema.body);
let req = request[getMethodFuncName(method)](apiPath);
// NOTE/deprecate: params
if (schema.params) {
deprecate("'params' property/extension in schema is deprecated. Use 'headers', 'query' or 'body' instead.");
req = req[getParamFuncName(method)](schema.params);
}
if (Object.keys(headers).length) {
expandVars(headers, options);
for (let key in headers) {
req = req.set(key, headers[key]);
}
}
if (Object.keys(query).length) {
expandVars(query, options);
req = req.query(query);
}
if (Object.keys(body).length) {
expandVars(body, options);
req = req.send(body);
}
return req.end(function(error, response) {
// catch network errors, etc.
if (!response) {
should(error).not.be.ok();
}
should(response).be.ok();
should(response.body).be.ok();
return validateResponse(schema, response, options, done);
});
} | javascript | function makeRequest(baseUrl, method, schema, options, done) {
debug(`making ${method.toUpperCase()} request to ${schema.endpoint}`);
const endpoint = expandVars(schema.endpoint, options);
const apiPath = url.resolve(baseUrl + "/", _.trimStart(endpoint, "/"));
const headers = Object.assign({}, options.headers, schema.headers);
const query = Object.assign({}, options.query, schema.query);
const body = Object.assign({}, options.body, schema.body);
let req = request[getMethodFuncName(method)](apiPath);
// NOTE/deprecate: params
if (schema.params) {
deprecate("'params' property/extension in schema is deprecated. Use 'headers', 'query' or 'body' instead.");
req = req[getParamFuncName(method)](schema.params);
}
if (Object.keys(headers).length) {
expandVars(headers, options);
for (let key in headers) {
req = req.set(key, headers[key]);
}
}
if (Object.keys(query).length) {
expandVars(query, options);
req = req.query(query);
}
if (Object.keys(body).length) {
expandVars(body, options);
req = req.send(body);
}
return req.end(function(error, response) {
// catch network errors, etc.
if (!response) {
should(error).not.be.ok();
}
should(response).be.ok();
should(response.body).be.ok();
return validateResponse(schema, response, options, done);
});
} | [
"function",
"makeRequest",
"(",
"baseUrl",
",",
"method",
",",
"schema",
",",
"options",
",",
"done",
")",
"{",
"debug",
"(",
"`",
"${",
"method",
".",
"toUpperCase",
"(",
")",
"}",
"${",
"schema",
".",
"endpoint",
"}",
"`",
")",
";",
"const",
"endpoint",
"=",
"expandVars",
"(",
"schema",
".",
"endpoint",
",",
"options",
")",
";",
"const",
"apiPath",
"=",
"url",
".",
"resolve",
"(",
"baseUrl",
"+",
"\"/\"",
",",
"_",
".",
"trimStart",
"(",
"endpoint",
",",
"\"/\"",
")",
")",
";",
"const",
"headers",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"options",
".",
"headers",
",",
"schema",
".",
"headers",
")",
";",
"const",
"query",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"options",
".",
"query",
",",
"schema",
".",
"query",
")",
";",
"const",
"body",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"options",
".",
"body",
",",
"schema",
".",
"body",
")",
";",
"let",
"req",
"=",
"request",
"[",
"getMethodFuncName",
"(",
"method",
")",
"]",
"(",
"apiPath",
")",
";",
"// NOTE/deprecate: params",
"if",
"(",
"schema",
".",
"params",
")",
"{",
"deprecate",
"(",
"\"'params' property/extension in schema is deprecated. Use 'headers', 'query' or 'body' instead.\"",
")",
";",
"req",
"=",
"req",
"[",
"getParamFuncName",
"(",
"method",
")",
"]",
"(",
"schema",
".",
"params",
")",
";",
"}",
"if",
"(",
"Object",
".",
"keys",
"(",
"headers",
")",
".",
"length",
")",
"{",
"expandVars",
"(",
"headers",
",",
"options",
")",
";",
"for",
"(",
"let",
"key",
"in",
"headers",
")",
"{",
"req",
"=",
"req",
".",
"set",
"(",
"key",
",",
"headers",
"[",
"key",
"]",
")",
";",
"}",
"}",
"if",
"(",
"Object",
".",
"keys",
"(",
"query",
")",
".",
"length",
")",
"{",
"expandVars",
"(",
"query",
",",
"options",
")",
";",
"req",
"=",
"req",
".",
"query",
"(",
"query",
")",
";",
"}",
"if",
"(",
"Object",
".",
"keys",
"(",
"body",
")",
".",
"length",
")",
"{",
"expandVars",
"(",
"body",
",",
"options",
")",
";",
"req",
"=",
"req",
".",
"send",
"(",
"body",
")",
";",
"}",
"return",
"req",
".",
"end",
"(",
"function",
"(",
"error",
",",
"response",
")",
"{",
"// catch network errors, etc.",
"if",
"(",
"!",
"response",
")",
"{",
"should",
"(",
"error",
")",
".",
"not",
".",
"be",
".",
"ok",
"(",
")",
";",
"}",
"should",
"(",
"response",
")",
".",
"be",
".",
"ok",
"(",
")",
";",
"should",
"(",
"response",
".",
"body",
")",
".",
"be",
".",
"ok",
"(",
")",
";",
"return",
"validateResponse",
"(",
"schema",
",",
"response",
",",
"options",
",",
"done",
")",
";",
"}",
")",
";",
"}"
]
| Make a HTTP request against the remote server and validate the
response.
@private
@param {String} baseUrl - base url e.g. "http://localhost:9090/"
@param {String} method - http method to use for request e.g. "get"
@param {Object} schema - schema used to validate response
@param {Object} options - test configurations
@param {Function} done - function called once request is completed | [
"Make",
"a",
"HTTP",
"request",
"against",
"the",
"remote",
"server",
"and",
"validate",
"the",
"response",
"."
]
| 2211c50c6019dc45acb192e07f765ab0daabe3cd | https://github.com/GochoMugo/elbow/blob/2211c50c6019dc45acb192e07f765ab0daabe3cd/src/lib/index.js#L263-L302 |
47,577 | saggiyogesh/nodeportal | public/ckeditor/_source/plugins/domiterator/plugin.js | getNextSourceNode | function getNextSourceNode( node, startFromSibling, lastNode )
{
var next = node.getNextSourceNode( startFromSibling, null, lastNode );
while ( !bookmarkGuard( next ) )
next = next.getNextSourceNode( startFromSibling, null, lastNode );
return next;
} | javascript | function getNextSourceNode( node, startFromSibling, lastNode )
{
var next = node.getNextSourceNode( startFromSibling, null, lastNode );
while ( !bookmarkGuard( next ) )
next = next.getNextSourceNode( startFromSibling, null, lastNode );
return next;
} | [
"function",
"getNextSourceNode",
"(",
"node",
",",
"startFromSibling",
",",
"lastNode",
")",
"{",
"var",
"next",
"=",
"node",
".",
"getNextSourceNode",
"(",
"startFromSibling",
",",
"null",
",",
"lastNode",
")",
";",
"while",
"(",
"!",
"bookmarkGuard",
"(",
"next",
")",
")",
"next",
"=",
"next",
".",
"getNextSourceNode",
"(",
"startFromSibling",
",",
"null",
",",
"lastNode",
")",
";",
"return",
"next",
";",
"}"
]
| Get a reference for the next element, bookmark nodes are skipped. | [
"Get",
"a",
"reference",
"for",
"the",
"next",
"element",
"bookmark",
"nodes",
"are",
"skipped",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/plugins/domiterator/plugin.js#L39-L45 |
47,578 | saggiyogesh/nodeportal | public/ckeditor/_source/core/dom/domobject.js | function( domObject, eventName )
{
return function( domEvent )
{
// In FF, when reloading the page with the editor focused, it may
// throw an error because the CKEDITOR global is not anymore
// available. So, we check it here first. (#2923)
if ( typeof CKEDITOR != 'undefined' )
domObject.fire( eventName, new CKEDITOR.dom.event( domEvent ) );
};
} | javascript | function( domObject, eventName )
{
return function( domEvent )
{
// In FF, when reloading the page with the editor focused, it may
// throw an error because the CKEDITOR global is not anymore
// available. So, we check it here first. (#2923)
if ( typeof CKEDITOR != 'undefined' )
domObject.fire( eventName, new CKEDITOR.dom.event( domEvent ) );
};
} | [
"function",
"(",
"domObject",
",",
"eventName",
")",
"{",
"return",
"function",
"(",
"domEvent",
")",
"{",
"// In FF, when reloading the page with the editor focused, it may\r",
"// throw an error because the CKEDITOR global is not anymore\r",
"// available. So, we check it here first. (#2923)\r",
"if",
"(",
"typeof",
"CKEDITOR",
"!=",
"'undefined'",
")",
"domObject",
".",
"fire",
"(",
"eventName",
",",
"new",
"CKEDITOR",
".",
"dom",
".",
"event",
"(",
"domEvent",
")",
")",
";",
"}",
";",
"}"
]
| Do not define other local variables here. We want to keep the native listener closures as clean as possible. | [
"Do",
"not",
"define",
"other",
"local",
"variables",
"here",
".",
"We",
"want",
"to",
"keep",
"the",
"native",
"listener",
"closures",
"as",
"clean",
"as",
"possible",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/core/dom/domobject.js#L40-L50 |
|
47,579 | saggiyogesh/nodeportal | public/ckeditor/_source/core/dom/domobject.js | function()
{
var nativeListeners = this.getCustomData( '_cke_nativeListeners' );
for ( var eventName in nativeListeners )
{
var listener = nativeListeners[ eventName ];
if ( this.$.detachEvent )
this.$.detachEvent( 'on' + eventName, listener );
else if ( this.$.removeEventListener )
this.$.removeEventListener( eventName, listener, false );
delete nativeListeners[ eventName ];
}
} | javascript | function()
{
var nativeListeners = this.getCustomData( '_cke_nativeListeners' );
for ( var eventName in nativeListeners )
{
var listener = nativeListeners[ eventName ];
if ( this.$.detachEvent )
this.$.detachEvent( 'on' + eventName, listener );
else if ( this.$.removeEventListener )
this.$.removeEventListener( eventName, listener, false );
delete nativeListeners[ eventName ];
}
} | [
"function",
"(",
")",
"{",
"var",
"nativeListeners",
"=",
"this",
".",
"getCustomData",
"(",
"'_cke_nativeListeners'",
")",
";",
"for",
"(",
"var",
"eventName",
"in",
"nativeListeners",
")",
"{",
"var",
"listener",
"=",
"nativeListeners",
"[",
"eventName",
"]",
";",
"if",
"(",
"this",
".",
"$",
".",
"detachEvent",
")",
"this",
".",
"$",
".",
"detachEvent",
"(",
"'on'",
"+",
"eventName",
",",
"listener",
")",
";",
"else",
"if",
"(",
"this",
".",
"$",
".",
"removeEventListener",
")",
"this",
".",
"$",
".",
"removeEventListener",
"(",
"eventName",
",",
"listener",
",",
"false",
")",
";",
"delete",
"nativeListeners",
"[",
"eventName",
"]",
";",
"}",
"}"
]
| Removes any listener set on this object.
To avoid memory leaks we must assure that there are no
references left after the object is no longer needed. | [
"Removes",
"any",
"listener",
"set",
"on",
"this",
"object",
".",
"To",
"avoid",
"memory",
"leaks",
"we",
"must",
"assure",
"that",
"there",
"are",
"no",
"references",
"left",
"after",
"the",
"object",
"is",
"no",
"longer",
"needed",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/core/dom/domobject.js#L125-L138 |
|
47,580 | saggiyogesh/nodeportal | public/ckeditor/_source/core/lang.js | function( languageCode, defaultLanguage, callback )
{
// If no languageCode - fallback to browser or default.
// If languageCode - fallback to no-localized version or default.
if ( !languageCode || !CKEDITOR.lang.languages[ languageCode ] )
languageCode = this.detect( defaultLanguage, languageCode );
if ( !this[ languageCode ] )
{
CKEDITOR.scriptLoader.load( CKEDITOR.getUrl(
'_source/' + // @Packager.RemoveLine
'lang/' + languageCode + '.js' ),
function()
{
callback( languageCode, this[ languageCode ] );
}
, this );
}
else
callback( languageCode, this[ languageCode ] );
} | javascript | function( languageCode, defaultLanguage, callback )
{
// If no languageCode - fallback to browser or default.
// If languageCode - fallback to no-localized version or default.
if ( !languageCode || !CKEDITOR.lang.languages[ languageCode ] )
languageCode = this.detect( defaultLanguage, languageCode );
if ( !this[ languageCode ] )
{
CKEDITOR.scriptLoader.load( CKEDITOR.getUrl(
'_source/' + // @Packager.RemoveLine
'lang/' + languageCode + '.js' ),
function()
{
callback( languageCode, this[ languageCode ] );
}
, this );
}
else
callback( languageCode, this[ languageCode ] );
} | [
"function",
"(",
"languageCode",
",",
"defaultLanguage",
",",
"callback",
")",
"{",
"// If no languageCode - fallback to browser or default.\r",
"// If languageCode - fallback to no-localized version or default.\r",
"if",
"(",
"!",
"languageCode",
"||",
"!",
"CKEDITOR",
".",
"lang",
".",
"languages",
"[",
"languageCode",
"]",
")",
"languageCode",
"=",
"this",
".",
"detect",
"(",
"defaultLanguage",
",",
"languageCode",
")",
";",
"if",
"(",
"!",
"this",
"[",
"languageCode",
"]",
")",
"{",
"CKEDITOR",
".",
"scriptLoader",
".",
"load",
"(",
"CKEDITOR",
".",
"getUrl",
"(",
"'_source/'",
"+",
"// @Packager.RemoveLine\r",
"'lang/'",
"+",
"languageCode",
"+",
"'.js'",
")",
",",
"function",
"(",
")",
"{",
"callback",
"(",
"languageCode",
",",
"this",
"[",
"languageCode",
"]",
")",
";",
"}",
",",
"this",
")",
";",
"}",
"else",
"callback",
"(",
"languageCode",
",",
"this",
"[",
"languageCode",
"]",
")",
";",
"}"
]
| Loads a specific language file, or auto detect it. A callback is
then called when the file gets loaded.
@param {String} languageCode The code of the language file to be
loaded. If null or empty, autodetection will be performed. The
same happens if the language is not supported.
@param {String} defaultLanguage The language to be used if
languageCode is not supported or if the autodetection fails.
@param {Function} callback A function to be called once the
language file is loaded. Two parameters are passed to this
function: the language code and the loaded language entries.
@example | [
"Loads",
"a",
"specific",
"language",
"file",
"or",
"auto",
"detect",
"it",
".",
"A",
"callback",
"is",
"then",
"called",
"when",
"the",
"file",
"gets",
"loaded",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/core/lang.js#L97-L117 |
|
47,581 | saggiyogesh/nodeportal | public/ckeditor/_source/core/lang.js | function( defaultLanguage, probeLanguage )
{
var languages = this.languages;
probeLanguage = probeLanguage || navigator.userLanguage || navigator.language || defaultLanguage;
var parts = probeLanguage
.toLowerCase()
.match( /([a-z]+)(?:-([a-z]+))?/ ),
lang = parts[1],
locale = parts[2];
if ( languages[ lang + '-' + locale ] )
lang = lang + '-' + locale;
else if ( !languages[ lang ] )
lang = null;
CKEDITOR.lang.detect = lang ?
function() { return lang; } :
function( defaultLanguage ) { return defaultLanguage; };
return lang || defaultLanguage;
} | javascript | function( defaultLanguage, probeLanguage )
{
var languages = this.languages;
probeLanguage = probeLanguage || navigator.userLanguage || navigator.language || defaultLanguage;
var parts = probeLanguage
.toLowerCase()
.match( /([a-z]+)(?:-([a-z]+))?/ ),
lang = parts[1],
locale = parts[2];
if ( languages[ lang + '-' + locale ] )
lang = lang + '-' + locale;
else if ( !languages[ lang ] )
lang = null;
CKEDITOR.lang.detect = lang ?
function() { return lang; } :
function( defaultLanguage ) { return defaultLanguage; };
return lang || defaultLanguage;
} | [
"function",
"(",
"defaultLanguage",
",",
"probeLanguage",
")",
"{",
"var",
"languages",
"=",
"this",
".",
"languages",
";",
"probeLanguage",
"=",
"probeLanguage",
"||",
"navigator",
".",
"userLanguage",
"||",
"navigator",
".",
"language",
"||",
"defaultLanguage",
";",
"var",
"parts",
"=",
"probeLanguage",
".",
"toLowerCase",
"(",
")",
".",
"match",
"(",
"/",
"([a-z]+)(?:-([a-z]+))?",
"/",
")",
",",
"lang",
"=",
"parts",
"[",
"1",
"]",
",",
"locale",
"=",
"parts",
"[",
"2",
"]",
";",
"if",
"(",
"languages",
"[",
"lang",
"+",
"'-'",
"+",
"locale",
"]",
")",
"lang",
"=",
"lang",
"+",
"'-'",
"+",
"locale",
";",
"else",
"if",
"(",
"!",
"languages",
"[",
"lang",
"]",
")",
"lang",
"=",
"null",
";",
"CKEDITOR",
".",
"lang",
".",
"detect",
"=",
"lang",
"?",
"function",
"(",
")",
"{",
"return",
"lang",
";",
"}",
":",
"function",
"(",
"defaultLanguage",
")",
"{",
"return",
"defaultLanguage",
";",
"}",
";",
"return",
"lang",
"||",
"defaultLanguage",
";",
"}"
]
| Returns the language that best fit the user language. For example,
suppose that the user language is "pt-br". If this language is
supported by the editor, it is returned. Otherwise, if only "pt" is
supported, it is returned instead. If none of the previous are
supported, a default language is then returned.
@param {String} defaultLanguage The default language to be returned
if the user language is not supported.
@param {String} [probeLanguage] A language code to try to use,
instead of the browser based autodetection.
@returns {String} The detected language code.
@example
alert( CKEDITOR.lang.detect( 'en' ) ); // e.g., in a German browser: "de" | [
"Returns",
"the",
"language",
"that",
"best",
"fit",
"the",
"user",
"language",
".",
"For",
"example",
"suppose",
"that",
"the",
"user",
"language",
"is",
"pt",
"-",
"br",
".",
"If",
"this",
"language",
"is",
"supported",
"by",
"the",
"editor",
"it",
"is",
"returned",
".",
"Otherwise",
"if",
"only",
"pt",
"is",
"supported",
"it",
"is",
"returned",
"instead",
".",
"If",
"none",
"of",
"the",
"previous",
"are",
"supported",
"a",
"default",
"language",
"is",
"then",
"returned",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/core/lang.js#L133-L154 |
|
47,582 | ForbesLindesay/stop | lib/favicon.js | addFavicons | function addFavicons() {
var stream = new Transform({objectMode: true, highWaterMark: 2});
var hosts = {};
var downloads = [];
stream._transform = function (page, _, callback) {
stream.push(page);
var host = url.parse(page.url).host;
if (!hosts[host]) {
downloads.push(hosts[host] = download(url.resolve(page.url, '/favicon.ico')).then(function (result) {
if (result.statusCode === 200 &&
!(result.headers['content-type'] &&
result.headers['content-type'].indexOf('html') !== -1)) {
stream.push(result);
}
}, function () {
//ignore errors downloading favicons
}));
}
callback(null);
};
stream._flush = function (callback) {
Promise.all(downloads).done(function () {
callback();
}, function (err) {
stream.emit('error', err);
callback();
});
};
return stream;
} | javascript | function addFavicons() {
var stream = new Transform({objectMode: true, highWaterMark: 2});
var hosts = {};
var downloads = [];
stream._transform = function (page, _, callback) {
stream.push(page);
var host = url.parse(page.url).host;
if (!hosts[host]) {
downloads.push(hosts[host] = download(url.resolve(page.url, '/favicon.ico')).then(function (result) {
if (result.statusCode === 200 &&
!(result.headers['content-type'] &&
result.headers['content-type'].indexOf('html') !== -1)) {
stream.push(result);
}
}, function () {
//ignore errors downloading favicons
}));
}
callback(null);
};
stream._flush = function (callback) {
Promise.all(downloads).done(function () {
callback();
}, function (err) {
stream.emit('error', err);
callback();
});
};
return stream;
} | [
"function",
"addFavicons",
"(",
")",
"{",
"var",
"stream",
"=",
"new",
"Transform",
"(",
"{",
"objectMode",
":",
"true",
",",
"highWaterMark",
":",
"2",
"}",
")",
";",
"var",
"hosts",
"=",
"{",
"}",
";",
"var",
"downloads",
"=",
"[",
"]",
";",
"stream",
".",
"_transform",
"=",
"function",
"(",
"page",
",",
"_",
",",
"callback",
")",
"{",
"stream",
".",
"push",
"(",
"page",
")",
";",
"var",
"host",
"=",
"url",
".",
"parse",
"(",
"page",
".",
"url",
")",
".",
"host",
";",
"if",
"(",
"!",
"hosts",
"[",
"host",
"]",
")",
"{",
"downloads",
".",
"push",
"(",
"hosts",
"[",
"host",
"]",
"=",
"download",
"(",
"url",
".",
"resolve",
"(",
"page",
".",
"url",
",",
"'/favicon.ico'",
")",
")",
".",
"then",
"(",
"function",
"(",
"result",
")",
"{",
"if",
"(",
"result",
".",
"statusCode",
"===",
"200",
"&&",
"!",
"(",
"result",
".",
"headers",
"[",
"'content-type'",
"]",
"&&",
"result",
".",
"headers",
"[",
"'content-type'",
"]",
".",
"indexOf",
"(",
"'html'",
")",
"!==",
"-",
"1",
")",
")",
"{",
"stream",
".",
"push",
"(",
"result",
")",
";",
"}",
"}",
",",
"function",
"(",
")",
"{",
"//ignore errors downloading favicons",
"}",
")",
")",
";",
"}",
"callback",
"(",
"null",
")",
";",
"}",
";",
"stream",
".",
"_flush",
"=",
"function",
"(",
"callback",
")",
"{",
"Promise",
".",
"all",
"(",
"downloads",
")",
".",
"done",
"(",
"function",
"(",
")",
"{",
"callback",
"(",
")",
";",
"}",
",",
"function",
"(",
"err",
")",
"{",
"stream",
".",
"emit",
"(",
"'error'",
",",
"err",
")",
";",
"callback",
"(",
")",
";",
"}",
")",
";",
"}",
";",
"return",
"stream",
";",
"}"
]
| Look for favicons and add them to the stream if they exist
@returns {TransformStream} | [
"Look",
"for",
"favicons",
"and",
"add",
"them",
"to",
"the",
"stream",
"if",
"they",
"exist"
]
| 61db8899bdde604dc45cfc8f11fffa1beaa27abb | https://github.com/ForbesLindesay/stop/blob/61db8899bdde604dc45cfc8f11fffa1beaa27abb/lib/favicon.js#L15-L46 |
47,583 | saggiyogesh/nodeportal | public/ckeditor/_source/plugins/styles/plugin.js | function( elementPath )
{
switch ( this.type )
{
case CKEDITOR.STYLE_BLOCK :
return this.checkElementRemovable( elementPath.block || elementPath.blockLimit, true );
case CKEDITOR.STYLE_OBJECT :
case CKEDITOR.STYLE_INLINE :
var elements = elementPath.elements;
for ( var i = 0, element ; i < elements.length ; i++ )
{
element = elements[ i ];
if ( this.type == CKEDITOR.STYLE_INLINE
&& ( element == elementPath.block || element == elementPath.blockLimit ) )
continue;
if( this.type == CKEDITOR.STYLE_OBJECT )
{
var name = element.getName();
if ( !( typeof this.element == 'string' ? name == this.element : name in this.element ) )
continue;
}
if ( this.checkElementRemovable( element, true ) )
return true;
}
}
return false;
} | javascript | function( elementPath )
{
switch ( this.type )
{
case CKEDITOR.STYLE_BLOCK :
return this.checkElementRemovable( elementPath.block || elementPath.blockLimit, true );
case CKEDITOR.STYLE_OBJECT :
case CKEDITOR.STYLE_INLINE :
var elements = elementPath.elements;
for ( var i = 0, element ; i < elements.length ; i++ )
{
element = elements[ i ];
if ( this.type == CKEDITOR.STYLE_INLINE
&& ( element == elementPath.block || element == elementPath.blockLimit ) )
continue;
if( this.type == CKEDITOR.STYLE_OBJECT )
{
var name = element.getName();
if ( !( typeof this.element == 'string' ? name == this.element : name in this.element ) )
continue;
}
if ( this.checkElementRemovable( element, true ) )
return true;
}
}
return false;
} | [
"function",
"(",
"elementPath",
")",
"{",
"switch",
"(",
"this",
".",
"type",
")",
"{",
"case",
"CKEDITOR",
".",
"STYLE_BLOCK",
":",
"return",
"this",
".",
"checkElementRemovable",
"(",
"elementPath",
".",
"block",
"||",
"elementPath",
".",
"blockLimit",
",",
"true",
")",
";",
"case",
"CKEDITOR",
".",
"STYLE_OBJECT",
":",
"case",
"CKEDITOR",
".",
"STYLE_INLINE",
":",
"var",
"elements",
"=",
"elementPath",
".",
"elements",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"element",
";",
"i",
"<",
"elements",
".",
"length",
";",
"i",
"++",
")",
"{",
"element",
"=",
"elements",
"[",
"i",
"]",
";",
"if",
"(",
"this",
".",
"type",
"==",
"CKEDITOR",
".",
"STYLE_INLINE",
"&&",
"(",
"element",
"==",
"elementPath",
".",
"block",
"||",
"element",
"==",
"elementPath",
".",
"blockLimit",
")",
")",
"continue",
";",
"if",
"(",
"this",
".",
"type",
"==",
"CKEDITOR",
".",
"STYLE_OBJECT",
")",
"{",
"var",
"name",
"=",
"element",
".",
"getName",
"(",
")",
";",
"if",
"(",
"!",
"(",
"typeof",
"this",
".",
"element",
"==",
"'string'",
"?",
"name",
"==",
"this",
".",
"element",
":",
"name",
"in",
"this",
".",
"element",
")",
")",
"continue",
";",
"}",
"if",
"(",
"this",
".",
"checkElementRemovable",
"(",
"element",
",",
"true",
")",
")",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
]
| Get the style state inside an element path. Returns "true" if the
element is active in the path. | [
"Get",
"the",
"style",
"state",
"inside",
"an",
"element",
"path",
".",
"Returns",
"true",
"if",
"the",
"element",
"is",
"active",
"in",
"the",
"path",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/plugins/styles/plugin.js#L168-L200 |
|
47,584 | saggiyogesh/nodeportal | public/ckeditor/_source/plugins/styles/plugin.js | function( elementPath )
{
switch ( this.type )
{
case CKEDITOR.STYLE_INLINE :
case CKEDITOR.STYLE_BLOCK :
break;
case CKEDITOR.STYLE_OBJECT :
return elementPath.lastElement.getAscendant( this.element, true );
}
return true;
} | javascript | function( elementPath )
{
switch ( this.type )
{
case CKEDITOR.STYLE_INLINE :
case CKEDITOR.STYLE_BLOCK :
break;
case CKEDITOR.STYLE_OBJECT :
return elementPath.lastElement.getAscendant( this.element, true );
}
return true;
} | [
"function",
"(",
"elementPath",
")",
"{",
"switch",
"(",
"this",
".",
"type",
")",
"{",
"case",
"CKEDITOR",
".",
"STYLE_INLINE",
":",
"case",
"CKEDITOR",
".",
"STYLE_BLOCK",
":",
"break",
";",
"case",
"CKEDITOR",
".",
"STYLE_OBJECT",
":",
"return",
"elementPath",
".",
"lastElement",
".",
"getAscendant",
"(",
"this",
".",
"element",
",",
"true",
")",
";",
"}",
"return",
"true",
";",
"}"
]
| Whether this style can be applied at the element path.
@param elementPath | [
"Whether",
"this",
"style",
"can",
"be",
"applied",
"at",
"the",
"element",
"path",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/plugins/styles/plugin.js#L206-L219 |
|
47,585 | saggiyogesh/nodeportal | public/ckeditor/_source/plugins/styles/plugin.js | function( label )
{
var styleDefinition = this._.definition,
html = [],
elementName = styleDefinition.element;
// Avoid <bdo> in the preview.
if ( elementName == 'bdo' )
elementName = 'span';
html = [ '<', elementName ];
// Assign all defined attributes.
var attribs = styleDefinition.attributes;
if ( attribs )
{
for ( var att in attribs )
{
html.push( ' ', att, '="', attribs[ att ], '"' );
}
}
// Assign the style attribute.
var cssStyle = CKEDITOR.style.getStyleText( styleDefinition );
if ( cssStyle )
html.push( ' style="', cssStyle, '"' );
html.push( '>', ( label || styleDefinition.name ), '</', elementName, '>' );
return html.join( '' );
} | javascript | function( label )
{
var styleDefinition = this._.definition,
html = [],
elementName = styleDefinition.element;
// Avoid <bdo> in the preview.
if ( elementName == 'bdo' )
elementName = 'span';
html = [ '<', elementName ];
// Assign all defined attributes.
var attribs = styleDefinition.attributes;
if ( attribs )
{
for ( var att in attribs )
{
html.push( ' ', att, '="', attribs[ att ], '"' );
}
}
// Assign the style attribute.
var cssStyle = CKEDITOR.style.getStyleText( styleDefinition );
if ( cssStyle )
html.push( ' style="', cssStyle, '"' );
html.push( '>', ( label || styleDefinition.name ), '</', elementName, '>' );
return html.join( '' );
} | [
"function",
"(",
"label",
")",
"{",
"var",
"styleDefinition",
"=",
"this",
".",
"_",
".",
"definition",
",",
"html",
"=",
"[",
"]",
",",
"elementName",
"=",
"styleDefinition",
".",
"element",
";",
"// Avoid <bdo> in the preview.\r",
"if",
"(",
"elementName",
"==",
"'bdo'",
")",
"elementName",
"=",
"'span'",
";",
"html",
"=",
"[",
"'<'",
",",
"elementName",
"]",
";",
"// Assign all defined attributes.\r",
"var",
"attribs",
"=",
"styleDefinition",
".",
"attributes",
";",
"if",
"(",
"attribs",
")",
"{",
"for",
"(",
"var",
"att",
"in",
"attribs",
")",
"{",
"html",
".",
"push",
"(",
"' '",
",",
"att",
",",
"'=\"'",
",",
"attribs",
"[",
"att",
"]",
",",
"'\"'",
")",
";",
"}",
"}",
"// Assign the style attribute.\r",
"var",
"cssStyle",
"=",
"CKEDITOR",
".",
"style",
".",
"getStyleText",
"(",
"styleDefinition",
")",
";",
"if",
"(",
"cssStyle",
")",
"html",
".",
"push",
"(",
"' style=\"'",
",",
"cssStyle",
",",
"'\"'",
")",
";",
"html",
".",
"push",
"(",
"'>'",
",",
"(",
"label",
"||",
"styleDefinition",
".",
"name",
")",
",",
"'</'",
",",
"elementName",
",",
"'>'",
")",
";",
"return",
"html",
".",
"join",
"(",
"''",
")",
";",
"}"
]
| Builds the preview HTML based on the styles definition. | [
"Builds",
"the",
"preview",
"HTML",
"based",
"on",
"the",
"styles",
"definition",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/plugins/styles/plugin.js#L302-L332 |
|
47,586 | saggiyogesh/nodeportal | public/ckeditor/_source/plugins/styles/plugin.js | removeFromInsideElement | function removeFromInsideElement( style, element )
{
var def = style._.definition,
attribs = def.attributes,
styles = def.styles,
overrides = getOverrides( style ),
innerElements = element.getElementsByTag( style.element );
for ( var i = innerElements.count(); --i >= 0 ; )
removeFromElement( style, innerElements.getItem( i ) );
// Now remove any other element with different name that is
// defined to be overriden.
for ( var overrideElement in overrides )
{
if ( overrideElement != style.element )
{
innerElements = element.getElementsByTag( overrideElement ) ;
for ( i = innerElements.count() - 1 ; i >= 0 ; i-- )
{
var innerElement = innerElements.getItem( i );
removeOverrides( innerElement, overrides[ overrideElement ] ) ;
}
}
}
} | javascript | function removeFromInsideElement( style, element )
{
var def = style._.definition,
attribs = def.attributes,
styles = def.styles,
overrides = getOverrides( style ),
innerElements = element.getElementsByTag( style.element );
for ( var i = innerElements.count(); --i >= 0 ; )
removeFromElement( style, innerElements.getItem( i ) );
// Now remove any other element with different name that is
// defined to be overriden.
for ( var overrideElement in overrides )
{
if ( overrideElement != style.element )
{
innerElements = element.getElementsByTag( overrideElement ) ;
for ( i = innerElements.count() - 1 ; i >= 0 ; i-- )
{
var innerElement = innerElements.getItem( i );
removeOverrides( innerElement, overrides[ overrideElement ] ) ;
}
}
}
} | [
"function",
"removeFromInsideElement",
"(",
"style",
",",
"element",
")",
"{",
"var",
"def",
"=",
"style",
".",
"_",
".",
"definition",
",",
"attribs",
"=",
"def",
".",
"attributes",
",",
"styles",
"=",
"def",
".",
"styles",
",",
"overrides",
"=",
"getOverrides",
"(",
"style",
")",
",",
"innerElements",
"=",
"element",
".",
"getElementsByTag",
"(",
"style",
".",
"element",
")",
";",
"for",
"(",
"var",
"i",
"=",
"innerElements",
".",
"count",
"(",
")",
";",
"--",
"i",
">=",
"0",
";",
")",
"removeFromElement",
"(",
"style",
",",
"innerElements",
".",
"getItem",
"(",
"i",
")",
")",
";",
"// Now remove any other element with different name that is\r",
"// defined to be overriden.\r",
"for",
"(",
"var",
"overrideElement",
"in",
"overrides",
")",
"{",
"if",
"(",
"overrideElement",
"!=",
"style",
".",
"element",
")",
"{",
"innerElements",
"=",
"element",
".",
"getElementsByTag",
"(",
"overrideElement",
")",
";",
"for",
"(",
"i",
"=",
"innerElements",
".",
"count",
"(",
")",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"var",
"innerElement",
"=",
"innerElements",
".",
"getItem",
"(",
"i",
")",
";",
"removeOverrides",
"(",
"innerElement",
",",
"overrides",
"[",
"overrideElement",
"]",
")",
";",
"}",
"}",
"}",
"}"
]
| Removes a style from inside an element. | [
"Removes",
"a",
"style",
"from",
"inside",
"an",
"element",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/plugins/styles/plugin.js#L1171-L1196 |
47,587 | saggiyogesh/nodeportal | public/ckeditor/_source/plugins/styles/plugin.js | removeNoAttribsElement | function removeNoAttribsElement( element )
{
// If no more attributes remained in the element, remove it,
// leaving its children.
if ( !element.hasAttributes() )
{
if ( CKEDITOR.dtd.$block[ element.getName() ] )
{
var previous = element.getPrevious( nonWhitespaces ),
next = element.getNext( nonWhitespaces );
if ( previous && ( previous.type == CKEDITOR.NODE_TEXT || !previous.isBlockBoundary( { br : 1 } ) ) )
element.append( 'br', 1 );
if ( next && ( next.type == CKEDITOR.NODE_TEXT || !next.isBlockBoundary( { br : 1 } ) ) )
element.append( 'br' );
element.remove( true );
}
else
{
// Removing elements may open points where merging is possible,
// so let's cache the first and last nodes for later checking.
var firstChild = element.getFirst();
var lastChild = element.getLast();
element.remove( true );
if ( firstChild )
{
// Check the cached nodes for merging.
firstChild.type == CKEDITOR.NODE_ELEMENT && firstChild.mergeSiblings();
if ( lastChild && !firstChild.equals( lastChild )
&& lastChild.type == CKEDITOR.NODE_ELEMENT )
lastChild.mergeSiblings();
}
}
}
} | javascript | function removeNoAttribsElement( element )
{
// If no more attributes remained in the element, remove it,
// leaving its children.
if ( !element.hasAttributes() )
{
if ( CKEDITOR.dtd.$block[ element.getName() ] )
{
var previous = element.getPrevious( nonWhitespaces ),
next = element.getNext( nonWhitespaces );
if ( previous && ( previous.type == CKEDITOR.NODE_TEXT || !previous.isBlockBoundary( { br : 1 } ) ) )
element.append( 'br', 1 );
if ( next && ( next.type == CKEDITOR.NODE_TEXT || !next.isBlockBoundary( { br : 1 } ) ) )
element.append( 'br' );
element.remove( true );
}
else
{
// Removing elements may open points where merging is possible,
// so let's cache the first and last nodes for later checking.
var firstChild = element.getFirst();
var lastChild = element.getLast();
element.remove( true );
if ( firstChild )
{
// Check the cached nodes for merging.
firstChild.type == CKEDITOR.NODE_ELEMENT && firstChild.mergeSiblings();
if ( lastChild && !firstChild.equals( lastChild )
&& lastChild.type == CKEDITOR.NODE_ELEMENT )
lastChild.mergeSiblings();
}
}
}
} | [
"function",
"removeNoAttribsElement",
"(",
"element",
")",
"{",
"// If no more attributes remained in the element, remove it,\r",
"// leaving its children.\r",
"if",
"(",
"!",
"element",
".",
"hasAttributes",
"(",
")",
")",
"{",
"if",
"(",
"CKEDITOR",
".",
"dtd",
".",
"$block",
"[",
"element",
".",
"getName",
"(",
")",
"]",
")",
"{",
"var",
"previous",
"=",
"element",
".",
"getPrevious",
"(",
"nonWhitespaces",
")",
",",
"next",
"=",
"element",
".",
"getNext",
"(",
"nonWhitespaces",
")",
";",
"if",
"(",
"previous",
"&&",
"(",
"previous",
".",
"type",
"==",
"CKEDITOR",
".",
"NODE_TEXT",
"||",
"!",
"previous",
".",
"isBlockBoundary",
"(",
"{",
"br",
":",
"1",
"}",
")",
")",
")",
"element",
".",
"append",
"(",
"'br'",
",",
"1",
")",
";",
"if",
"(",
"next",
"&&",
"(",
"next",
".",
"type",
"==",
"CKEDITOR",
".",
"NODE_TEXT",
"||",
"!",
"next",
".",
"isBlockBoundary",
"(",
"{",
"br",
":",
"1",
"}",
")",
")",
")",
"element",
".",
"append",
"(",
"'br'",
")",
";",
"element",
".",
"remove",
"(",
"true",
")",
";",
"}",
"else",
"{",
"// Removing elements may open points where merging is possible,\r",
"// so let's cache the first and last nodes for later checking.\r",
"var",
"firstChild",
"=",
"element",
".",
"getFirst",
"(",
")",
";",
"var",
"lastChild",
"=",
"element",
".",
"getLast",
"(",
")",
";",
"element",
".",
"remove",
"(",
"true",
")",
";",
"if",
"(",
"firstChild",
")",
"{",
"// Check the cached nodes for merging.\r",
"firstChild",
".",
"type",
"==",
"CKEDITOR",
".",
"NODE_ELEMENT",
"&&",
"firstChild",
".",
"mergeSiblings",
"(",
")",
";",
"if",
"(",
"lastChild",
"&&",
"!",
"firstChild",
".",
"equals",
"(",
"lastChild",
")",
"&&",
"lastChild",
".",
"type",
"==",
"CKEDITOR",
".",
"NODE_ELEMENT",
")",
"lastChild",
".",
"mergeSiblings",
"(",
")",
";",
"}",
"}",
"}",
"}"
]
| If the element has no more attributes, remove it. | [
"If",
"the",
"element",
"has",
"no",
"more",
"attributes",
"remove",
"it",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/plugins/styles/plugin.js#L1236-L1275 |
47,588 | saggiyogesh/nodeportal | public/ckeditor/_source/plugins/styles/plugin.js | getOverrides | function getOverrides( style )
{
if ( style._.overrides )
return style._.overrides;
var overrides = ( style._.overrides = {} ),
definition = style._.definition.overrides;
if ( definition )
{
// The override description can be a string, object or array.
// Internally, well handle arrays only, so transform it if needed.
if ( !CKEDITOR.tools.isArray( definition ) )
definition = [ definition ];
// Loop through all override definitions.
for ( var i = 0 ; i < definition.length ; i++ )
{
var override = definition[i];
var elementName;
var overrideEl;
var attrs;
// If can be a string with the element name.
if ( typeof override == 'string' )
elementName = override.toLowerCase();
// Or an object.
else
{
elementName = override.element ? override.element.toLowerCase() : style.element;
attrs = override.attributes;
}
// We can have more than one override definition for the same
// element name, so we attempt to simply append information to
// it if it already exists.
overrideEl = overrides[ elementName ] || ( overrides[ elementName ] = {} );
if ( attrs )
{
// The returning attributes list is an array, because we
// could have different override definitions for the same
// attribute name.
var overrideAttrs = ( overrideEl.attributes = overrideEl.attributes || new Array() );
for ( var attName in attrs )
{
// Each item in the attributes array is also an array,
// where [0] is the attribute name and [1] is the
// override value.
overrideAttrs.push( [ attName.toLowerCase(), attrs[ attName ] ] );
}
}
}
}
return overrides;
} | javascript | function getOverrides( style )
{
if ( style._.overrides )
return style._.overrides;
var overrides = ( style._.overrides = {} ),
definition = style._.definition.overrides;
if ( definition )
{
// The override description can be a string, object or array.
// Internally, well handle arrays only, so transform it if needed.
if ( !CKEDITOR.tools.isArray( definition ) )
definition = [ definition ];
// Loop through all override definitions.
for ( var i = 0 ; i < definition.length ; i++ )
{
var override = definition[i];
var elementName;
var overrideEl;
var attrs;
// If can be a string with the element name.
if ( typeof override == 'string' )
elementName = override.toLowerCase();
// Or an object.
else
{
elementName = override.element ? override.element.toLowerCase() : style.element;
attrs = override.attributes;
}
// We can have more than one override definition for the same
// element name, so we attempt to simply append information to
// it if it already exists.
overrideEl = overrides[ elementName ] || ( overrides[ elementName ] = {} );
if ( attrs )
{
// The returning attributes list is an array, because we
// could have different override definitions for the same
// attribute name.
var overrideAttrs = ( overrideEl.attributes = overrideEl.attributes || new Array() );
for ( var attName in attrs )
{
// Each item in the attributes array is also an array,
// where [0] is the attribute name and [1] is the
// override value.
overrideAttrs.push( [ attName.toLowerCase(), attrs[ attName ] ] );
}
}
}
}
return overrides;
} | [
"function",
"getOverrides",
"(",
"style",
")",
"{",
"if",
"(",
"style",
".",
"_",
".",
"overrides",
")",
"return",
"style",
".",
"_",
".",
"overrides",
";",
"var",
"overrides",
"=",
"(",
"style",
".",
"_",
".",
"overrides",
"=",
"{",
"}",
")",
",",
"definition",
"=",
"style",
".",
"_",
".",
"definition",
".",
"overrides",
";",
"if",
"(",
"definition",
")",
"{",
"// The override description can be a string, object or array.\r",
"// Internally, well handle arrays only, so transform it if needed.\r",
"if",
"(",
"!",
"CKEDITOR",
".",
"tools",
".",
"isArray",
"(",
"definition",
")",
")",
"definition",
"=",
"[",
"definition",
"]",
";",
"// Loop through all override definitions.\r",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"definition",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"override",
"=",
"definition",
"[",
"i",
"]",
";",
"var",
"elementName",
";",
"var",
"overrideEl",
";",
"var",
"attrs",
";",
"// If can be a string with the element name.\r",
"if",
"(",
"typeof",
"override",
"==",
"'string'",
")",
"elementName",
"=",
"override",
".",
"toLowerCase",
"(",
")",
";",
"// Or an object.\r",
"else",
"{",
"elementName",
"=",
"override",
".",
"element",
"?",
"override",
".",
"element",
".",
"toLowerCase",
"(",
")",
":",
"style",
".",
"element",
";",
"attrs",
"=",
"override",
".",
"attributes",
";",
"}",
"// We can have more than one override definition for the same\r",
"// element name, so we attempt to simply append information to\r",
"// it if it already exists.\r",
"overrideEl",
"=",
"overrides",
"[",
"elementName",
"]",
"||",
"(",
"overrides",
"[",
"elementName",
"]",
"=",
"{",
"}",
")",
";",
"if",
"(",
"attrs",
")",
"{",
"// The returning attributes list is an array, because we\r",
"// could have different override definitions for the same\r",
"// attribute name.\r",
"var",
"overrideAttrs",
"=",
"(",
"overrideEl",
".",
"attributes",
"=",
"overrideEl",
".",
"attributes",
"||",
"new",
"Array",
"(",
")",
")",
";",
"for",
"(",
"var",
"attName",
"in",
"attrs",
")",
"{",
"// Each item in the attributes array is also an array,\r",
"// where [0] is the attribute name and [1] is the\r",
"// override value.\r",
"overrideAttrs",
".",
"push",
"(",
"[",
"attName",
".",
"toLowerCase",
"(",
")",
",",
"attrs",
"[",
"attName",
"]",
"]",
")",
";",
"}",
"}",
"}",
"}",
"return",
"overrides",
";",
"}"
]
| Get the the collection used to compare the elements and attributes,
defined in this style overrides, with other element. All information in
it is lowercased.
@param {CKEDITOR.style} style | [
"Get",
"the",
"the",
"collection",
"used",
"to",
"compare",
"the",
"elements",
"and",
"attributes",
"defined",
"in",
"this",
"style",
"overrides",
"with",
"other",
"element",
".",
"All",
"information",
"in",
"it",
"is",
"lowercased",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/plugins/styles/plugin.js#L1385-L1441 |
47,589 | saggiyogesh/nodeportal | public/ckeditor/_source/plugins/styles/plugin.js | normalizeProperty | function normalizeProperty( name, value, isStyle )
{
var temp = new CKEDITOR.dom.element( 'span' );
temp [ isStyle ? 'setStyle' : 'setAttribute' ]( name, value );
return temp[ isStyle ? 'getStyle' : 'getAttribute' ]( name );
} | javascript | function normalizeProperty( name, value, isStyle )
{
var temp = new CKEDITOR.dom.element( 'span' );
temp [ isStyle ? 'setStyle' : 'setAttribute' ]( name, value );
return temp[ isStyle ? 'getStyle' : 'getAttribute' ]( name );
} | [
"function",
"normalizeProperty",
"(",
"name",
",",
"value",
",",
"isStyle",
")",
"{",
"var",
"temp",
"=",
"new",
"CKEDITOR",
".",
"dom",
".",
"element",
"(",
"'span'",
")",
";",
"temp",
"[",
"isStyle",
"?",
"'setStyle'",
":",
"'setAttribute'",
"]",
"(",
"name",
",",
"value",
")",
";",
"return",
"temp",
"[",
"isStyle",
"?",
"'getStyle'",
":",
"'getAttribute'",
"]",
"(",
"name",
")",
";",
"}"
]
| Make the comparison of attribute value easier by standardizing it. | [
"Make",
"the",
"comparison",
"of",
"attribute",
"value",
"easier",
"by",
"standardizing",
"it",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/plugins/styles/plugin.js#L1444-L1449 |
47,590 | saggiyogesh/nodeportal | public/ckeditor/_source/plugins/styles/plugin.js | normalizeCssText | function normalizeCssText( unparsedCssText, nativeNormalize )
{
var styleText;
if ( nativeNormalize !== false )
{
// Injects the style in a temporary span object, so the browser parses it,
// retrieving its final format.
var temp = new CKEDITOR.dom.element( 'span' );
temp.setAttribute( 'style', unparsedCssText );
styleText = temp.getAttribute( 'style' ) || '';
}
else
styleText = unparsedCssText;
// Normalize font-family property, ignore quotes and being case insensitive. (#7322)
// http://www.w3.org/TR/css3-fonts/#font-family-the-font-family-property
styleText = styleText.replace( /(font-family:)(.*?)(?=;|$)/, function ( match, prop, val )
{
var names = val.split( ',' );
for ( var i = 0; i < names.length; i++ )
names[ i ] = CKEDITOR.tools.trim( names[ i ].replace( /["']/g, '' ) );
return prop + names.join( ',' );
});
// Shrinking white-spaces around colon and semi-colon (#4147).
// Compensate tail semi-colon.
return styleText.replace( /\s*([;:])\s*/, '$1' )
.replace( /([^\s;])$/, '$1;')
// Trimming spaces after comma(#4107),
// remove quotations(#6403),
// mostly for differences on "font-family".
.replace( /,\s+/g, ',' )
.replace( /\"/g,'' )
.toLowerCase();
} | javascript | function normalizeCssText( unparsedCssText, nativeNormalize )
{
var styleText;
if ( nativeNormalize !== false )
{
// Injects the style in a temporary span object, so the browser parses it,
// retrieving its final format.
var temp = new CKEDITOR.dom.element( 'span' );
temp.setAttribute( 'style', unparsedCssText );
styleText = temp.getAttribute( 'style' ) || '';
}
else
styleText = unparsedCssText;
// Normalize font-family property, ignore quotes and being case insensitive. (#7322)
// http://www.w3.org/TR/css3-fonts/#font-family-the-font-family-property
styleText = styleText.replace( /(font-family:)(.*?)(?=;|$)/, function ( match, prop, val )
{
var names = val.split( ',' );
for ( var i = 0; i < names.length; i++ )
names[ i ] = CKEDITOR.tools.trim( names[ i ].replace( /["']/g, '' ) );
return prop + names.join( ',' );
});
// Shrinking white-spaces around colon and semi-colon (#4147).
// Compensate tail semi-colon.
return styleText.replace( /\s*([;:])\s*/, '$1' )
.replace( /([^\s;])$/, '$1;')
// Trimming spaces after comma(#4107),
// remove quotations(#6403),
// mostly for differences on "font-family".
.replace( /,\s+/g, ',' )
.replace( /\"/g,'' )
.toLowerCase();
} | [
"function",
"normalizeCssText",
"(",
"unparsedCssText",
",",
"nativeNormalize",
")",
"{",
"var",
"styleText",
";",
"if",
"(",
"nativeNormalize",
"!==",
"false",
")",
"{",
"// Injects the style in a temporary span object, so the browser parses it,\r",
"// retrieving its final format.\r",
"var",
"temp",
"=",
"new",
"CKEDITOR",
".",
"dom",
".",
"element",
"(",
"'span'",
")",
";",
"temp",
".",
"setAttribute",
"(",
"'style'",
",",
"unparsedCssText",
")",
";",
"styleText",
"=",
"temp",
".",
"getAttribute",
"(",
"'style'",
")",
"||",
"''",
";",
"}",
"else",
"styleText",
"=",
"unparsedCssText",
";",
"// Normalize font-family property, ignore quotes and being case insensitive. (#7322)\r",
"// http://www.w3.org/TR/css3-fonts/#font-family-the-font-family-property\r",
"styleText",
"=",
"styleText",
".",
"replace",
"(",
"/",
"(font-family:)(.*?)(?=;|$)",
"/",
",",
"function",
"(",
"match",
",",
"prop",
",",
"val",
")",
"{",
"var",
"names",
"=",
"val",
".",
"split",
"(",
"','",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"names",
".",
"length",
";",
"i",
"++",
")",
"names",
"[",
"i",
"]",
"=",
"CKEDITOR",
".",
"tools",
".",
"trim",
"(",
"names",
"[",
"i",
"]",
".",
"replace",
"(",
"/",
"[\"']",
"/",
"g",
",",
"''",
")",
")",
";",
"return",
"prop",
"+",
"names",
".",
"join",
"(",
"','",
")",
";",
"}",
")",
";",
"// Shrinking white-spaces around colon and semi-colon (#4147).\r",
"// Compensate tail semi-colon.\r",
"return",
"styleText",
".",
"replace",
"(",
"/",
"\\s*([;:])\\s*",
"/",
",",
"'$1'",
")",
".",
"replace",
"(",
"/",
"([^\\s;])$",
"/",
",",
"'$1;'",
")",
"// Trimming spaces after comma(#4107),\r",
"// remove quotations(#6403),\r",
"// mostly for differences on \"font-family\".\r",
".",
"replace",
"(",
"/",
",\\s+",
"/",
"g",
",",
"','",
")",
".",
"replace",
"(",
"/",
"\\\"",
"/",
"g",
",",
"''",
")",
".",
"toLowerCase",
"(",
")",
";",
"}"
]
| Make the comparison of style text easier by standardizing it. | [
"Make",
"the",
"comparison",
"of",
"style",
"text",
"easier",
"by",
"standardizing",
"it",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/plugins/styles/plugin.js#L1452-L1486 |
47,591 | saggiyogesh/nodeportal | public/ckeditor/_source/plugins/styles/plugin.js | parseStyleText | function parseStyleText( styleText )
{
var retval = {};
styleText
.replace( /"/g, '"' )
.replace( /\s*([^ :;]+)\s*:\s*([^;]+)\s*(?=;|$)/g, function( match, name, value )
{
retval[ name ] = value;
} );
return retval;
} | javascript | function parseStyleText( styleText )
{
var retval = {};
styleText
.replace( /"/g, '"' )
.replace( /\s*([^ :;]+)\s*:\s*([^;]+)\s*(?=;|$)/g, function( match, name, value )
{
retval[ name ] = value;
} );
return retval;
} | [
"function",
"parseStyleText",
"(",
"styleText",
")",
"{",
"var",
"retval",
"=",
"{",
"}",
";",
"styleText",
".",
"replace",
"(",
"/",
""",
"/",
"g",
",",
"'\"'",
")",
".",
"replace",
"(",
"/",
"\\s*([^ :;]+)\\s*:\\s*([^;]+)\\s*(?=;|$)",
"/",
"g",
",",
"function",
"(",
"match",
",",
"name",
",",
"value",
")",
"{",
"retval",
"[",
"name",
"]",
"=",
"value",
";",
"}",
")",
";",
"return",
"retval",
";",
"}"
]
| Turn inline style text properties into one hash. | [
"Turn",
"inline",
"style",
"text",
"properties",
"into",
"one",
"hash",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/plugins/styles/plugin.js#L1489-L1499 |
47,592 | Pegase745/node-gandi | src/gandi.js | defaultApikey | function defaultApikey(apikey) {
if (typeof apikey !== 'undefined') {
if (typeof apikey !== 'string') {
throw new TypeError('`apikey` argument must be a string');
}
if (apikey.length !== 24) {
throw new TypeError('`apikey` argument must be 24 characters long');
}
return apikey;
}
throw new TypeError('Gandi client needs an apikey as a first argument');
} | javascript | function defaultApikey(apikey) {
if (typeof apikey !== 'undefined') {
if (typeof apikey !== 'string') {
throw new TypeError('`apikey` argument must be a string');
}
if (apikey.length !== 24) {
throw new TypeError('`apikey` argument must be 24 characters long');
}
return apikey;
}
throw new TypeError('Gandi client needs an apikey as a first argument');
} | [
"function",
"defaultApikey",
"(",
"apikey",
")",
"{",
"if",
"(",
"typeof",
"apikey",
"!==",
"'undefined'",
")",
"{",
"if",
"(",
"typeof",
"apikey",
"!==",
"'string'",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'`apikey` argument must be a string'",
")",
";",
"}",
"if",
"(",
"apikey",
".",
"length",
"!==",
"24",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'`apikey` argument must be 24 characters long'",
")",
";",
"}",
"return",
"apikey",
";",
"}",
"throw",
"new",
"TypeError",
"(",
"'Gandi client needs an apikey as a first argument'",
")",
";",
"}"
]
| Returns apikey to constructor after some validation.
@param {string} apikey - Apikey passed onto the constructor.
@private | [
"Returns",
"apikey",
"to",
"constructor",
"after",
"some",
"validation",
"."
]
| 86566ffa092bb2e16d3d819c244b2be97d62582e | https://github.com/Pegase745/node-gandi/blob/86566ffa092bb2e16d3d819c244b2be97d62582e/src/gandi.js#L23-L36 |
47,593 | Sobesednik/exiftool-context | src/ExiftoolContext.js | makeTempFile | function makeTempFile() {
const n = Math.floor(Math.random() * 100000)
const tempFile = path.join(os.tmpdir(), `node-exiftool_test_${n}.jpg`)
return new Promise((resolve, reject) => {
const rs = fs.createReadStream(jpegFile)
const ws = fs.createWriteStream(tempFile)
rs.on('error', reject)
ws.on('error', reject)
ws.on('close', () => {
resolve(tempFile)
})
rs.pipe(ws)
})
} | javascript | function makeTempFile() {
const n = Math.floor(Math.random() * 100000)
const tempFile = path.join(os.tmpdir(), `node-exiftool_test_${n}.jpg`)
return new Promise((resolve, reject) => {
const rs = fs.createReadStream(jpegFile)
const ws = fs.createWriteStream(tempFile)
rs.on('error', reject)
ws.on('error', reject)
ws.on('close', () => {
resolve(tempFile)
})
rs.pipe(ws)
})
} | [
"function",
"makeTempFile",
"(",
")",
"{",
"const",
"n",
"=",
"Math",
".",
"floor",
"(",
"Math",
".",
"random",
"(",
")",
"*",
"100000",
")",
"const",
"tempFile",
"=",
"path",
".",
"join",
"(",
"os",
".",
"tmpdir",
"(",
")",
",",
"`",
"${",
"n",
"}",
"`",
")",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"const",
"rs",
"=",
"fs",
".",
"createReadStream",
"(",
"jpegFile",
")",
"const",
"ws",
"=",
"fs",
".",
"createWriteStream",
"(",
"tempFile",
")",
"rs",
".",
"on",
"(",
"'error'",
",",
"reject",
")",
"ws",
".",
"on",
"(",
"'error'",
",",
"reject",
")",
"ws",
".",
"on",
"(",
"'close'",
",",
"(",
")",
"=>",
"{",
"resolve",
"(",
"tempFile",
")",
"}",
")",
"rs",
".",
"pipe",
"(",
"ws",
")",
"}",
")",
"}"
]
| create temp file for writing metadata | [
"create",
"temp",
"file",
"for",
"writing",
"metadata"
]
| a6c44d2fd146898fae894ac08c1d381b4a969e2e | https://github.com/Sobesednik/exiftool-context/blob/a6c44d2fd146898fae894ac08c1d381b4a969e2e/src/ExiftoolContext.js#L42-L55 |
47,594 | ghornich/sort-paths | sort-paths.js | sortPaths | function sortPaths(items/* , [iteratee, ] dirSeparator */) {
assert(arguments.length >= 2, 'too few arguments');
assert(arguments.length <= 3, 'too many arguments');
var iteratee, dirSeparator;
if (arguments.length === 2) {
iteratee = identity;
dirSeparator = arguments[1];
}
else {
iteratee = arguments[1];
dirSeparator = arguments[2];
}
assert(isArray(items), 'items is not an array');
assert(isFunction(iteratee), 'iteratee is not a function');
assert(typeof dirSeparator === 'string', 'dirSeparator is not a String');
assert(dirSeparator.length === 1, 'dirSeparator must be a single character');
//encapsulate into DTOs
var itemDTOs = items.map(function (item) {
var path = iteratee(item);
assert(typeof path === 'string', 'item or iteratee(item) must be a String');
return {
item: item,
pathTokens: splitRetain(path, dirSeparator)
};
});
//sort DTOs
itemDTOs.sort(createItemDTOComparator(dirSeparator));
//decapsulate sorted DTOs and return
return itemDTOs.map(function (itemDTO) {
return itemDTO.item;
});
} | javascript | function sortPaths(items/* , [iteratee, ] dirSeparator */) {
assert(arguments.length >= 2, 'too few arguments');
assert(arguments.length <= 3, 'too many arguments');
var iteratee, dirSeparator;
if (arguments.length === 2) {
iteratee = identity;
dirSeparator = arguments[1];
}
else {
iteratee = arguments[1];
dirSeparator = arguments[2];
}
assert(isArray(items), 'items is not an array');
assert(isFunction(iteratee), 'iteratee is not a function');
assert(typeof dirSeparator === 'string', 'dirSeparator is not a String');
assert(dirSeparator.length === 1, 'dirSeparator must be a single character');
//encapsulate into DTOs
var itemDTOs = items.map(function (item) {
var path = iteratee(item);
assert(typeof path === 'string', 'item or iteratee(item) must be a String');
return {
item: item,
pathTokens: splitRetain(path, dirSeparator)
};
});
//sort DTOs
itemDTOs.sort(createItemDTOComparator(dirSeparator));
//decapsulate sorted DTOs and return
return itemDTOs.map(function (itemDTO) {
return itemDTO.item;
});
} | [
"function",
"sortPaths",
"(",
"items",
"/* , [iteratee, ] dirSeparator */",
")",
"{",
"assert",
"(",
"arguments",
".",
"length",
">=",
"2",
",",
"'too few arguments'",
")",
";",
"assert",
"(",
"arguments",
".",
"length",
"<=",
"3",
",",
"'too many arguments'",
")",
";",
"var",
"iteratee",
",",
"dirSeparator",
";",
"if",
"(",
"arguments",
".",
"length",
"===",
"2",
")",
"{",
"iteratee",
"=",
"identity",
";",
"dirSeparator",
"=",
"arguments",
"[",
"1",
"]",
";",
"}",
"else",
"{",
"iteratee",
"=",
"arguments",
"[",
"1",
"]",
";",
"dirSeparator",
"=",
"arguments",
"[",
"2",
"]",
";",
"}",
"assert",
"(",
"isArray",
"(",
"items",
")",
",",
"'items is not an array'",
")",
";",
"assert",
"(",
"isFunction",
"(",
"iteratee",
")",
",",
"'iteratee is not a function'",
")",
";",
"assert",
"(",
"typeof",
"dirSeparator",
"===",
"'string'",
",",
"'dirSeparator is not a String'",
")",
";",
"assert",
"(",
"dirSeparator",
".",
"length",
"===",
"1",
",",
"'dirSeparator must be a single character'",
")",
";",
"//encapsulate into DTOs",
"var",
"itemDTOs",
"=",
"items",
".",
"map",
"(",
"function",
"(",
"item",
")",
"{",
"var",
"path",
"=",
"iteratee",
"(",
"item",
")",
";",
"assert",
"(",
"typeof",
"path",
"===",
"'string'",
",",
"'item or iteratee(item) must be a String'",
")",
";",
"return",
"{",
"item",
":",
"item",
",",
"pathTokens",
":",
"splitRetain",
"(",
"path",
",",
"dirSeparator",
")",
"}",
";",
"}",
")",
";",
"//sort DTOs",
"itemDTOs",
".",
"sort",
"(",
"createItemDTOComparator",
"(",
"dirSeparator",
")",
")",
";",
"//decapsulate sorted DTOs and return",
"return",
"itemDTOs",
".",
"map",
"(",
"function",
"(",
"itemDTO",
")",
"{",
"return",
"itemDTO",
".",
"item",
";",
"}",
")",
";",
"}"
]
| Allows sorting arbitrary items without modifying or copying them
@typedef {Object} itemDTO
@param {String|Object} item - original item
@param {Array} pathTokens - split path tokens. Extracted from `item` using `iteratee` and split using `splitRetain` | [
"Allows",
"sorting",
"arbitrary",
"items",
"without",
"modifying",
"or",
"copying",
"them"
]
| 3b8b86f26319748c8d429980145099ad8bb71b8e | https://github.com/ghornich/sort-paths/blob/3b8b86f26319748c8d429980145099ad8bb71b8e/sort-paths.js#L17-L56 |
47,595 | fvsch/gulp-task-maker | state.js | setOptions | function setOptions(input) {
if (!isObject(input)) {
throw new Error('gtm.conf method expects a config object')
}
for (const key of ['debug', 'notify', 'parallel', 'strict']) {
const value = input[key]
if (typeof value === 'boolean') options[key] = value
else if (value != null) options[key] = strToBool(value)
}
for (const key of ['buildPrefix', 'watchPrefix']) {
const value = input[key]
if (typeof value === 'string') {
const trimmed = value.replace(/\s+/g, '')
if (trimmed !== '') options[key] = trimmed
}
}
if (isObject(input.groups)) {
for (const name of Object.keys(input.groups)) {
const value = input.groups[name]
if (typeof value === 'function' || Array.isArray(value)) {
options.groups[name] = value
} else if (!value) {
options.groups[name] = null // falsy values disable a group
}
}
}
} | javascript | function setOptions(input) {
if (!isObject(input)) {
throw new Error('gtm.conf method expects a config object')
}
for (const key of ['debug', 'notify', 'parallel', 'strict']) {
const value = input[key]
if (typeof value === 'boolean') options[key] = value
else if (value != null) options[key] = strToBool(value)
}
for (const key of ['buildPrefix', 'watchPrefix']) {
const value = input[key]
if (typeof value === 'string') {
const trimmed = value.replace(/\s+/g, '')
if (trimmed !== '') options[key] = trimmed
}
}
if (isObject(input.groups)) {
for (const name of Object.keys(input.groups)) {
const value = input.groups[name]
if (typeof value === 'function' || Array.isArray(value)) {
options.groups[name] = value
} else if (!value) {
options.groups[name] = null // falsy values disable a group
}
}
}
} | [
"function",
"setOptions",
"(",
"input",
")",
"{",
"if",
"(",
"!",
"isObject",
"(",
"input",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'gtm.conf method expects a config object'",
")",
"}",
"for",
"(",
"const",
"key",
"of",
"[",
"'debug'",
",",
"'notify'",
",",
"'parallel'",
",",
"'strict'",
"]",
")",
"{",
"const",
"value",
"=",
"input",
"[",
"key",
"]",
"if",
"(",
"typeof",
"value",
"===",
"'boolean'",
")",
"options",
"[",
"key",
"]",
"=",
"value",
"else",
"if",
"(",
"value",
"!=",
"null",
")",
"options",
"[",
"key",
"]",
"=",
"strToBool",
"(",
"value",
")",
"}",
"for",
"(",
"const",
"key",
"of",
"[",
"'buildPrefix'",
",",
"'watchPrefix'",
"]",
")",
"{",
"const",
"value",
"=",
"input",
"[",
"key",
"]",
"if",
"(",
"typeof",
"value",
"===",
"'string'",
")",
"{",
"const",
"trimmed",
"=",
"value",
".",
"replace",
"(",
"/",
"\\s+",
"/",
"g",
",",
"''",
")",
"if",
"(",
"trimmed",
"!==",
"''",
")",
"options",
"[",
"key",
"]",
"=",
"trimmed",
"}",
"}",
"if",
"(",
"isObject",
"(",
"input",
".",
"groups",
")",
")",
"{",
"for",
"(",
"const",
"name",
"of",
"Object",
".",
"keys",
"(",
"input",
".",
"groups",
")",
")",
"{",
"const",
"value",
"=",
"input",
".",
"groups",
"[",
"name",
"]",
"if",
"(",
"typeof",
"value",
"===",
"'function'",
"||",
"Array",
".",
"isArray",
"(",
"value",
")",
")",
"{",
"options",
".",
"groups",
"[",
"name",
"]",
"=",
"value",
"}",
"else",
"if",
"(",
"!",
"value",
")",
"{",
"options",
".",
"groups",
"[",
"name",
"]",
"=",
"null",
"// falsy values disable a group",
"}",
"}",
"}",
"}"
]
| Override default gulp-task-maker options
@param {object} [input] - options, or undefined to return the current config
@property {string|boolean|number} [input.notify]
@property {string|boolean|number} [input.strict]
@property {object} [input.prefix]
@property {object} [input.groups]
@return {object} | [
"Override",
"default",
"gulp",
"-",
"task",
"-",
"maker",
"options"
]
| 20ab4245f2d75174786ad140793e9438c025d546 | https://github.com/fvsch/gulp-task-maker/blob/20ab4245f2d75174786ad140793e9438c025d546/state.js#L38-L64 |
47,596 | saggiyogesh/nodeportal | public/ckeditor/_source/plugins/bidi/plugin.js | getElementForDirection | function getElementForDirection( node )
{
while ( node && !( node.getName() in allGuardElements || node.is( 'body' ) ) )
{
var parent = node.getParent();
if ( !parent )
break;
node = parent;
}
return node;
} | javascript | function getElementForDirection( node )
{
while ( node && !( node.getName() in allGuardElements || node.is( 'body' ) ) )
{
var parent = node.getParent();
if ( !parent )
break;
node = parent;
}
return node;
} | [
"function",
"getElementForDirection",
"(",
"node",
")",
"{",
"while",
"(",
"node",
"&&",
"!",
"(",
"node",
".",
"getName",
"(",
")",
"in",
"allGuardElements",
"||",
"node",
".",
"is",
"(",
"'body'",
")",
")",
")",
"{",
"var",
"parent",
"=",
"node",
".",
"getParent",
"(",
")",
";",
"if",
"(",
"!",
"parent",
")",
"break",
";",
"node",
"=",
"parent",
";",
"}",
"return",
"node",
";",
"}"
]
| Returns element with possibility of applying the direction.
@param node | [
"Returns",
"element",
"with",
"possibility",
"of",
"applying",
"the",
"direction",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/plugins/bidi/plugin.js#L70-L82 |
47,597 | saggiyogesh/nodeportal | public/ckeditor/_source/plugins/autogrow/plugin.js | contentHeight | function contentHeight( scrollable )
{
var overflowY = scrollable.getStyle( 'overflow-y' );
var doc = scrollable.getDocument();
// Create a temporary marker element.
var marker = CKEDITOR.dom.element.createFromHtml( '<span style="margin:0;padding:0;border:0;clear:both;width:1px;height:1px;display:block;">' + ( CKEDITOR.env.webkit ? ' ' : '' ) + '</span>', doc );
doc[ CKEDITOR.env.ie? 'getBody' : 'getDocumentElement']().append( marker );
var height = marker.getDocumentPosition( doc ).y + marker.$.offsetHeight;
marker.remove();
scrollable.setStyle( 'overflow-y', overflowY );
return height;
} | javascript | function contentHeight( scrollable )
{
var overflowY = scrollable.getStyle( 'overflow-y' );
var doc = scrollable.getDocument();
// Create a temporary marker element.
var marker = CKEDITOR.dom.element.createFromHtml( '<span style="margin:0;padding:0;border:0;clear:both;width:1px;height:1px;display:block;">' + ( CKEDITOR.env.webkit ? ' ' : '' ) + '</span>', doc );
doc[ CKEDITOR.env.ie? 'getBody' : 'getDocumentElement']().append( marker );
var height = marker.getDocumentPosition( doc ).y + marker.$.offsetHeight;
marker.remove();
scrollable.setStyle( 'overflow-y', overflowY );
return height;
} | [
"function",
"contentHeight",
"(",
"scrollable",
")",
"{",
"var",
"overflowY",
"=",
"scrollable",
".",
"getStyle",
"(",
"'overflow-y'",
")",
";",
"var",
"doc",
"=",
"scrollable",
".",
"getDocument",
"(",
")",
";",
"// Create a temporary marker element.\r",
"var",
"marker",
"=",
"CKEDITOR",
".",
"dom",
".",
"element",
".",
"createFromHtml",
"(",
"'<span style=\"margin:0;padding:0;border:0;clear:both;width:1px;height:1px;display:block;\">'",
"+",
"(",
"CKEDITOR",
".",
"env",
".",
"webkit",
"?",
"' '",
":",
"''",
")",
"+",
"'</span>'",
",",
"doc",
")",
";",
"doc",
"[",
"CKEDITOR",
".",
"env",
".",
"ie",
"?",
"'getBody'",
":",
"'getDocumentElement'",
"]",
"(",
")",
".",
"append",
"(",
"marker",
")",
";",
"var",
"height",
"=",
"marker",
".",
"getDocumentPosition",
"(",
"doc",
")",
".",
"y",
"+",
"marker",
".",
"$",
".",
"offsetHeight",
";",
"marker",
".",
"remove",
"(",
")",
";",
"scrollable",
".",
"setStyle",
"(",
"'overflow-y'",
",",
"overflowY",
")",
";",
"return",
"height",
";",
"}"
]
| Actual content height, figured out by appending check the last element's document position. | [
"Actual",
"content",
"height",
"figured",
"out",
"by",
"appending",
"check",
"the",
"last",
"element",
"s",
"document",
"position",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/plugins/autogrow/plugin.js#L12-L25 |
47,598 | twolfson/value-mapper | lib/value-mapper.js | ValueMapper | function ValueMapper(input, options) {
// Save input for later
this.input = input;
// Save placeholder middlewares
this.middlewares = [];
// Fallback options
options = options || {};
// Add each of the middlewares
var middlewares = options.middlewares || [];
middlewares.forEach(this.addMiddleware, this);
} | javascript | function ValueMapper(input, options) {
// Save input for later
this.input = input;
// Save placeholder middlewares
this.middlewares = [];
// Fallback options
options = options || {};
// Add each of the middlewares
var middlewares = options.middlewares || [];
middlewares.forEach(this.addMiddleware, this);
} | [
"function",
"ValueMapper",
"(",
"input",
",",
"options",
")",
"{",
"// Save input for later",
"this",
".",
"input",
"=",
"input",
";",
"// Save placeholder middlewares",
"this",
".",
"middlewares",
"=",
"[",
"]",
";",
"// Fallback options",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"// Add each of the middlewares",
"var",
"middlewares",
"=",
"options",
".",
"middlewares",
"||",
"[",
"]",
";",
"middlewares",
".",
"forEach",
"(",
"this",
".",
"addMiddleware",
",",
"this",
")",
";",
"}"
]
| Constructor for mapping values
@param {Object} input Key-value pairs to map values across
@param {Object} [options] Flags to adjust how the mapping is performed
@param {Function[]} [options.middlewares] Middlewares to process resolved value through | [
"Constructor",
"for",
"mapping",
"values"
]
| 956cfa193e02b6c4ae0e607b14eea41a15b7331d | https://github.com/twolfson/value-mapper/blob/956cfa193e02b6c4ae0e607b14eea41a15b7331d/lib/value-mapper.js#L13-L26 |
47,599 | twolfson/value-mapper | lib/value-mapper.js | function (key) {
// Assume the middleware is a function
var middleware = key;
// If the middleware is a string
if (typeof middleware === 'string') {
// Look it up and assert it was found
middleware = MIDDLEWARES[key];
assert(middleware, 'value-mapper middleware "' + key + '" could not be found."');
}
// Add the middleware to our stack
this.middlewares.push(middleware);
} | javascript | function (key) {
// Assume the middleware is a function
var middleware = key;
// If the middleware is a string
if (typeof middleware === 'string') {
// Look it up and assert it was found
middleware = MIDDLEWARES[key];
assert(middleware, 'value-mapper middleware "' + key + '" could not be found."');
}
// Add the middleware to our stack
this.middlewares.push(middleware);
} | [
"function",
"(",
"key",
")",
"{",
"// Assume the middleware is a function",
"var",
"middleware",
"=",
"key",
";",
"// If the middleware is a string",
"if",
"(",
"typeof",
"middleware",
"===",
"'string'",
")",
"{",
"// Look it up and assert it was found",
"middleware",
"=",
"MIDDLEWARES",
"[",
"key",
"]",
";",
"assert",
"(",
"middleware",
",",
"'value-mapper middleware \"'",
"+",
"key",
"+",
"'\" could not be found.\"'",
")",
";",
"}",
"// Add the middleware to our stack",
"this",
".",
"middlewares",
".",
"push",
"(",
"middleware",
")",
";",
"}"
]
| Add middleware to instance | [
"Add",
"middleware",
"to",
"instance"
]
| 956cfa193e02b6c4ae0e607b14eea41a15b7331d | https://github.com/twolfson/value-mapper/blob/956cfa193e02b6c4ae0e607b14eea41a15b7331d/lib/value-mapper.js#L29-L42 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.