repo stringlengths 5 67 | path stringlengths 4 116 | func_name stringlengths 0 58 | original_string stringlengths 52 373k | language stringclasses 1
value | code stringlengths 52 373k | code_tokens list | docstring stringlengths 4 11.8k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 86 226 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
splunk/splunk-sdk-javascript | client/splunk.js | function(name, params, callback) {
// If we get (name, callback) instead of (name, params, callback)
// do the necessary variable swap
if (utils.isFunction(params) && !callback) {
callback = params;
params = {};
}
params = para... | javascript | function(name, params, callback) {
// If we get (name, callback) instead of (name, params, callback)
// do the necessary variable swap
if (utils.isFunction(params) && !callback) {
callback = params;
params = {};
}
params = para... | [
"function",
"(",
"name",
",",
"params",
",",
"callback",
")",
"{",
"// If we get (name, callback) instead of (name, params, callback)",
"// do the necessary variable swap",
"if",
"(",
"utils",
".",
"isFunction",
"(",
"params",
")",
"&&",
"!",
"callback",
")",
"{",
"ca... | Creates a new `DataModel` object with the given name and parameters.
It is preferred that you create data models through the Splunk
Enterprise with a browser.
@param {String} name The name of the data model to create. If it contains spaces they will be replaced
with underscores.
@param {Object} params A dictionary of ... | [
"Creates",
"a",
"new",
"DataModel",
"object",
"with",
"the",
"given",
"name",
"and",
"parameters",
".",
"It",
"is",
"preferred",
"that",
"you",
"create",
"data",
"models",
"through",
"the",
"Splunk",
"Enterprise",
"with",
"a",
"browser",
"."
] | 9aec5443860926654c2ab8ee3bf198a407c53b07 | https://github.com/splunk/splunk-sdk-javascript/blob/9aec5443860926654c2ab8ee3bf198a407c53b07/client/splunk.js#L7827-L7849 | train | |
splunk/splunk-sdk-javascript | client/splunk.js | function(callback) {
callback = callback || function() {};
var that = this;
var params = {
count: this._pagesize,
offset: this._offset
};
return this._endpoint(params, function(err, results) {
if (er... | javascript | function(callback) {
callback = callback || function() {};
var that = this;
var params = {
count: this._pagesize,
offset: this._offset
};
return this._endpoint(params, function(err, results) {
if (er... | [
"function",
"(",
"callback",
")",
"{",
"callback",
"=",
"callback",
"||",
"function",
"(",
")",
"{",
"}",
";",
"var",
"that",
"=",
"this",
";",
"var",
"params",
"=",
"{",
"count",
":",
"this",
".",
"_pagesize",
",",
"offset",
":",
"this",
".",
"_of... | Fetches the next page from the endpoint. | [
"Fetches",
"the",
"next",
"page",
"from",
"the",
"endpoint",
"."
] | 9aec5443860926654c2ab8ee3bf198a407c53b07 | https://github.com/splunk/splunk-sdk-javascript/blob/9aec5443860926654c2ab8ee3bf198a407c53b07/client/splunk.js#L7879-L7898 | train | |
splunk/splunk-sdk-javascript | client/splunk.js | EventWriter | function EventWriter(output, error) {
this._out = utils.isUndefined(output) ? process.stdout : output;
this._err = utils.isUndefined(error) ? process.stderr : error;
// Has the opening <stream> tag been written yet?
this._headerWritten = false;
} | javascript | function EventWriter(output, error) {
this._out = utils.isUndefined(output) ? process.stdout : output;
this._err = utils.isUndefined(error) ? process.stderr : error;
// Has the opening <stream> tag been written yet?
this._headerWritten = false;
} | [
"function",
"EventWriter",
"(",
"output",
",",
"error",
")",
"{",
"this",
".",
"_out",
"=",
"utils",
".",
"isUndefined",
"(",
"output",
")",
"?",
"process",
".",
"stdout",
":",
"output",
";",
"this",
".",
"_err",
"=",
"utils",
".",
"isUndefined",
"(",
... | `EventWriter` writes events and error messages to Splunk from a modular input.
Its two important methods are `writeEvent`, which takes an `Event` object,
and `log`, which takes a severity and an error message.
@param {Object} output A stream to output data, defaults to `process.stdout`
@param {Object} error A stream ... | [
"EventWriter",
"writes",
"events",
"and",
"error",
"messages",
"to",
"Splunk",
"from",
"a",
"modular",
"input",
"."
] | 9aec5443860926654c2ab8ee3bf198a407c53b07 | https://github.com/splunk/splunk-sdk-javascript/blob/9aec5443860926654c2ab8ee3bf198a407c53b07/client/splunk.js#L12034-L12040 | train |
splunk/splunk-sdk-javascript | client/splunk.js | Scheme | function Scheme(title) {
this.title = utils.isUndefined(title) ? "" : title;
// Set the defaults.
this.description = null;
this.useExternalValidation = true;
this.useSingleInstance = false;
this.streamingMode = Scheme.streamingModeXML;
// List of Argument object... | javascript | function Scheme(title) {
this.title = utils.isUndefined(title) ? "" : title;
// Set the defaults.
this.description = null;
this.useExternalValidation = true;
this.useSingleInstance = false;
this.streamingMode = Scheme.streamingModeXML;
// List of Argument object... | [
"function",
"Scheme",
"(",
"title",
")",
"{",
"this",
".",
"title",
"=",
"utils",
".",
"isUndefined",
"(",
"title",
")",
"?",
"\"\"",
":",
"title",
";",
"// Set the defaults.",
"this",
".",
"description",
"=",
"null",
";",
"this",
".",
"useExternalValidati... | Class representing the metadata for a modular input kind.
A `Scheme` specifies a title, description, several options of how Splunk
should run modular inputs of this kind, and a set of arguments that define
a particular modular input's properties.
The primary use of `Scheme` is to abstract away the construction of XML
... | [
"Class",
"representing",
"the",
"metadata",
"for",
"a",
"modular",
"input",
"kind",
"."
] | 9aec5443860926654c2ab8ee3bf198a407c53b07 | https://github.com/splunk/splunk-sdk-javascript/blob/9aec5443860926654c2ab8ee3bf198a407c53b07/client/splunk.js#L12388-L12399 | train |
splunk/splunk-sdk-javascript | client/splunk.js | stringifyArray | function stringifyArray(arr, prefix) {
var ret = [];
if (!prefix) throw new TypeError('stringify expects an object');
for (var i = 0; i < arr.length; i++) {
ret.push(stringify(arr[i], prefix + '[]'));
}
return ret.join('&');
} | javascript | function stringifyArray(arr, prefix) {
var ret = [];
if (!prefix) throw new TypeError('stringify expects an object');
for (var i = 0; i < arr.length; i++) {
ret.push(stringify(arr[i], prefix + '[]'));
}
return ret.join('&');
} | [
"function",
"stringifyArray",
"(",
"arr",
",",
"prefix",
")",
"{",
"var",
"ret",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"prefix",
")",
"throw",
"new",
"TypeError",
"(",
"'stringify expects an object'",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i... | Stringify the given `arr`.
@param {Array} arr
@param {String} prefix
@return {String}
@api private | [
"Stringify",
"the",
"given",
"arr",
"."
] | 9aec5443860926654c2ab8ee3bf198a407c53b07 | https://github.com/splunk/splunk-sdk-javascript/blob/9aec5443860926654c2ab8ee3bf198a407c53b07/client/splunk.js#L13533-L13540 | train |
splunk/splunk-sdk-javascript | client/splunk.js | lastBraceInKey | function lastBraceInKey(str) {
var len = str.length
, brace
, c;
for (var i = 0; i < len; ++i) {
c = str[i];
if (']' == c) brace = false;
if ('[' == c) brace = true;
if ('=' == c && !brace) return i;
}
} | javascript | function lastBraceInKey(str) {
var len = str.length
, brace
, c;
for (var i = 0; i < len; ++i) {
c = str[i];
if (']' == c) brace = false;
if ('[' == c) brace = true;
if ('=' == c && !brace) return i;
}
} | [
"function",
"lastBraceInKey",
"(",
"str",
")",
"{",
"var",
"len",
"=",
"str",
".",
"length",
",",
"brace",
",",
"c",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"len",
";",
"++",
"i",
")",
"{",
"c",
"=",
"str",
"[",
"i",
"]",
";",... | Locate last brace in `str` within the key.
@param {String} str
@return {Number}
@api private | [
"Locate",
"last",
"brace",
"in",
"str",
"within",
"the",
"key",
"."
] | 9aec5443860926654c2ab8ee3bf198a407c53b07 | https://github.com/splunk/splunk-sdk-javascript/blob/9aec5443860926654c2ab8ee3bf198a407c53b07/client/splunk.js#L13594-L13604 | train |
splunk/splunk-sdk-javascript | examples/browser/minisplunk/jquery.fn.gmap.js | function(a, b) {
c = this;
if (!b) {
return c.options[a];
} else {
c._u(a, b);
}
} | javascript | function(a, b) {
c = this;
if (!b) {
return c.options[a];
} else {
c._u(a, b);
}
} | [
"function",
"(",
"a",
",",
"b",
")",
"{",
"c",
"=",
"this",
";",
"if",
"(",
"!",
"b",
")",
"{",
"return",
"c",
".",
"options",
"[",
"a",
"]",
";",
"}",
"else",
"{",
"c",
".",
"_u",
"(",
"a",
",",
"b",
")",
";",
"}",
"}"
] | Get or set options
@param key:string
@param options:object | [
"Get",
"or",
"set",
"options"
] | 9aec5443860926654c2ab8ee3bf198a407c53b07 | https://github.com/splunk/splunk-sdk-javascript/blob/9aec5443860926654c2ab8ee3bf198a407c53b07/examples/browser/minisplunk/jquery.fn.gmap.js#L52-L59 | train | |
splunk/splunk-sdk-javascript | examples/browser/minisplunk/jquery.fn.gmap.js | function( a, b ) {
this.id = b.attr('id');
this.instances = [];
this.element = b;
this.options = jQuery.extend(this.options, a);
this._create();
if ( this._init ) {
this._init();
}
} | javascript | function( a, b ) {
this.id = b.attr('id');
this.instances = [];
this.element = b;
this.options = jQuery.extend(this.options, a);
this._create();
if ( this._init ) {
this._init();
}
} | [
"function",
"(",
"a",
",",
"b",
")",
"{",
"this",
".",
"id",
"=",
"b",
".",
"attr",
"(",
"'id'",
")",
";",
"this",
".",
"instances",
"=",
"[",
"]",
";",
"this",
".",
"element",
"=",
"b",
";",
"this",
".",
"options",
"=",
"jQuery",
".",
"exten... | Setup plugin basics,
Set the jQuery UI Widget this.element, so extensions will work on both plugins | [
"Setup",
"plugin",
"basics",
"Set",
"the",
"jQuery",
"UI",
"Widget",
"this",
".",
"element",
"so",
"extensions",
"will",
"work",
"on",
"both",
"plugins"
] | 9aec5443860926654c2ab8ee3bf198a407c53b07 | https://github.com/splunk/splunk-sdk-javascript/blob/9aec5443860926654c2ab8ee3bf198a407c53b07/examples/browser/minisplunk/jquery.fn.gmap.js#L65-L74 | train | |
splunk/splunk-sdk-javascript | examples/browser/minisplunk/jquery.fn.gmap.js | function(a, b) {
var map = this.get('map');
jQuery.extend(this.options, { 'center': map.getCenter(), 'mapTypeId': map.getMapTypeId(), 'zoom': map.getZoom() } );
if (a && b) {
this.options[a] = b;
}
map.setOptions(this.options);
// ... | javascript | function(a, b) {
var map = this.get('map');
jQuery.extend(this.options, { 'center': map.getCenter(), 'mapTypeId': map.getMapTypeId(), 'zoom': map.getZoom() } );
if (a && b) {
this.options[a] = b;
}
map.setOptions(this.options);
// ... | [
"function",
"(",
"a",
",",
"b",
")",
"{",
"var",
"map",
"=",
"this",
".",
"get",
"(",
"'map'",
")",
";",
"jQuery",
".",
"extend",
"(",
"this",
".",
"options",
",",
"{",
"'center'",
":",
"map",
".",
"getCenter",
"(",
")",
",",
"'mapTypeId'",
":",
... | Set map options
@param key:string (optional)
@param value:object (optional) | [
"Set",
"map",
"options"
] | 9aec5443860926654c2ab8ee3bf198a407c53b07 | https://github.com/splunk/splunk-sdk-javascript/blob/9aec5443860926654c2ab8ee3bf198a407c53b07/examples/browser/minisplunk/jquery.fn.gmap.js#L97-L111 | train | |
splunk/splunk-sdk-javascript | examples/browser/minisplunk/jquery.fn.gmap.js | function(a) {
this.get('bounds', new google.maps.LatLngBounds()).extend(this._latLng(a));
this.get('map').fitBounds(this.get('bounds'));
} | javascript | function(a) {
this.get('bounds', new google.maps.LatLngBounds()).extend(this._latLng(a));
this.get('map').fitBounds(this.get('bounds'));
} | [
"function",
"(",
"a",
")",
"{",
"this",
".",
"get",
"(",
"'bounds'",
",",
"new",
"google",
".",
"maps",
".",
"LatLngBounds",
"(",
")",
")",
".",
"extend",
"(",
"this",
".",
"_latLng",
"(",
"a",
")",
")",
";",
"this",
".",
"get",
"(",
"'map'",
"... | Adds a latitude longitude pair to the bounds.
@param position:google.maps.LatLng/string | [
"Adds",
"a",
"latitude",
"longitude",
"pair",
"to",
"the",
"bounds",
"."
] | 9aec5443860926654c2ab8ee3bf198a407c53b07 | https://github.com/splunk/splunk-sdk-javascript/blob/9aec5443860926654c2ab8ee3bf198a407c53b07/examples/browser/minisplunk/jquery.fn.gmap.js#L117-L120 | train | |
splunk/splunk-sdk-javascript | examples/browser/minisplunk/jquery.fn.gmap.js | function(a, b, c) {
var d = this.get('map');
var c = c || google.maps.Marker;
a.position = (a.position) ? this._latLng(a.position) : null;
var e = new c( jQuery.extend({'map': d, 'bounds': false}, a) );
var f = this.get('markers', []);
if ( e.id ) ... | javascript | function(a, b, c) {
var d = this.get('map');
var c = c || google.maps.Marker;
a.position = (a.position) ? this._latLng(a.position) : null;
var e = new c( jQuery.extend({'map': d, 'bounds': false}, a) );
var f = this.get('markers', []);
if ( e.id ) ... | [
"function",
"(",
"a",
",",
"b",
",",
"c",
")",
"{",
"var",
"d",
"=",
"this",
".",
"get",
"(",
"'map'",
")",
";",
"var",
"c",
"=",
"c",
"||",
"google",
".",
"maps",
".",
"Marker",
";",
"a",
".",
"position",
"=",
"(",
"a",
".",
"position",
")... | Adds a Marker to the map
@param markerOptions:google.maps.MarkerOptions (optional)
@param callback:function(map:google.maps.Map, marker:google.maps.Marker) (optional)
@param marker:function (optional)
@return $(google.maps.Marker)
@see http://code.google.com/intl/sv-SE/apis/maps/documentation/javascript/reference.html#... | [
"Adds",
"a",
"Marker",
"to",
"the",
"map"
] | 9aec5443860926654c2ab8ee3bf198a407c53b07 | https://github.com/splunk/splunk-sdk-javascript/blob/9aec5443860926654c2ab8ee3bf198a407c53b07/examples/browser/minisplunk/jquery.fn.gmap.js#L140-L156 | train | |
splunk/splunk-sdk-javascript | examples/browser/minisplunk/jquery.fn.gmap.js | function(a, b) {
var c = new google.maps.InfoWindow(a);
this._call(b, c);
return $(c);
} | javascript | function(a, b) {
var c = new google.maps.InfoWindow(a);
this._call(b, c);
return $(c);
} | [
"function",
"(",
"a",
",",
"b",
")",
"{",
"var",
"c",
"=",
"new",
"google",
".",
"maps",
".",
"InfoWindow",
"(",
"a",
")",
";",
"this",
".",
"_call",
"(",
"b",
",",
"c",
")",
";",
"return",
"$",
"(",
"c",
")",
";",
"}"
] | Adds an InfoWindow to the map
@param infoWindowOptions:google.maps.InfoWindowOptions (optional)
@param callback:function(InfoWindow:google.maps.InfoWindowOptions) (optional)
@return $(google.maps.InfoWindowOptions)
@see http://code.google.com/intl/sv-SE/apis/maps/documentation/javascript/reference.html#InfoWindowOption... | [
"Adds",
"an",
"InfoWindow",
"to",
"the",
"map"
] | 9aec5443860926654c2ab8ee3bf198a407c53b07 | https://github.com/splunk/splunk-sdk-javascript/blob/9aec5443860926654c2ab8ee3bf198a407c53b07/examples/browser/minisplunk/jquery.fn.gmap.js#L165-L169 | train | |
splunk/splunk-sdk-javascript | examples/browser/minisplunk/jquery.fn.gmap.js | function(a, b) {
var c = this.instances[this.id];
if (!c[a]) {
if ( a.indexOf('>') > -1 ) {
var e = a.replace(/ /g, '').split('>');
for ( var i = 0; i < e.length; i++ ) {
if ( !c[e[i]] ) {
... | javascript | function(a, b) {
var c = this.instances[this.id];
if (!c[a]) {
if ( a.indexOf('>') > -1 ) {
var e = a.replace(/ /g, '').split('>');
for ( var i = 0; i < e.length; i++ ) {
if ( !c[e[i]] ) {
... | [
"function",
"(",
"a",
",",
"b",
")",
"{",
"var",
"c",
"=",
"this",
".",
"instances",
"[",
"this",
".",
"id",
"]",
";",
"if",
"(",
"!",
"c",
"[",
"a",
"]",
")",
"{",
"if",
"(",
"a",
".",
"indexOf",
"(",
"'>'",
")",
">",
"-",
"1",
")",
"{... | Returns an instance property by key. Has the ability to set an object if the property does not exist
@param key:string
@param value:object(optional) | [
"Returns",
"an",
"instance",
"property",
"by",
"key",
".",
"Has",
"the",
"ability",
"to",
"set",
"an",
"object",
"if",
"the",
"property",
"does",
"not",
"exist"
] | 9aec5443860926654c2ab8ee3bf198a407c53b07 | https://github.com/splunk/splunk-sdk-javascript/blob/9aec5443860926654c2ab8ee3bf198a407c53b07/examples/browser/minisplunk/jquery.fn.gmap.js#L212-L233 | train | |
splunk/splunk-sdk-javascript | examples/browser/minisplunk/jquery.fn.gmap.js | function(a, b) {
this.get('iw', new google.maps.InfoWindow).setOptions(a);
this.get('iw').open(this.get('map'), this._unwrap(b));
} | javascript | function(a, b) {
this.get('iw', new google.maps.InfoWindow).setOptions(a);
this.get('iw').open(this.get('map'), this._unwrap(b));
} | [
"function",
"(",
"a",
",",
"b",
")",
"{",
"this",
".",
"get",
"(",
"'iw'",
",",
"new",
"google",
".",
"maps",
".",
"InfoWindow",
")",
".",
"setOptions",
"(",
"a",
")",
";",
"this",
".",
"get",
"(",
"'iw'",
")",
".",
"open",
"(",
"this",
".",
... | Triggers an InfoWindow to open
@param infoWindowOptions:google.maps.InfoWindowOptions
@param marker:google.maps.Marker (optional)
@see http://code.google.com/intl/sv-SE/apis/maps/documentation/javascript/reference.html#InfoWindowOptions | [
"Triggers",
"an",
"InfoWindow",
"to",
"open"
] | 9aec5443860926654c2ab8ee3bf198a407c53b07 | https://github.com/splunk/splunk-sdk-javascript/blob/9aec5443860926654c2ab8ee3bf198a407c53b07/examples/browser/minisplunk/jquery.fn.gmap.js#L241-L244 | train | |
splunk/splunk-sdk-javascript | examples/browser/minisplunk/jquery.fn.gmap.js | function() {
this.clear('markers');
this.clear('services');
this.clear('overlays');
var a = this.instances[this.id];
for ( b in a ) {
a[b] = null;
}
} | javascript | function() {
this.clear('markers');
this.clear('services');
this.clear('overlays');
var a = this.instances[this.id];
for ( b in a ) {
a[b] = null;
}
} | [
"function",
"(",
")",
"{",
"this",
".",
"clear",
"(",
"'markers'",
")",
";",
"this",
".",
"clear",
"(",
"'services'",
")",
";",
"this",
".",
"clear",
"(",
"'overlays'",
")",
";",
"var",
"a",
"=",
"this",
".",
"instances",
"[",
"this",
".",
"id",
... | Destroys the plugin. | [
"Destroys",
"the",
"plugin",
"."
] | 9aec5443860926654c2ab8ee3bf198a407c53b07 | https://github.com/splunk/splunk-sdk-javascript/blob/9aec5443860926654c2ab8ee3bf198a407c53b07/examples/browser/minisplunk/jquery.fn.gmap.js#L266-L274 | train | |
splunk/splunk-sdk-javascript | examples/browser/minisplunk/jquery.fn.gmap.js | function(a) {
if ( $.isFunction(a) ) {
a.apply(this, Array.prototype.slice.call(arguments, 1));
}
} | javascript | function(a) {
if ( $.isFunction(a) ) {
a.apply(this, Array.prototype.slice.call(arguments, 1));
}
} | [
"function",
"(",
"a",
")",
"{",
"if",
"(",
"$",
".",
"isFunction",
"(",
"a",
")",
")",
"{",
"a",
".",
"apply",
"(",
"this",
",",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"1",
")",
")",
";",
"}",
"}"
] | Helper method for calling a function
@param callback | [
"Helper",
"method",
"for",
"calling",
"a",
"function"
] | 9aec5443860926654c2ab8ee3bf198a407c53b07 | https://github.com/splunk/splunk-sdk-javascript/blob/9aec5443860926654c2ab8ee3bf198a407c53b07/examples/browser/minisplunk/jquery.fn.gmap.js#L280-L284 | train | |
splunk/splunk-sdk-javascript | examples/browser/minisplunk/jquery.fn.gmap.js | function(a) {
if ( a instanceof google.maps.LatLng ) {
return a;
} else {
var b = a.replace(/ /g,'').split(',');
return new google.maps.LatLng(b[0], b[1]);
}
} | javascript | function(a) {
if ( a instanceof google.maps.LatLng ) {
return a;
} else {
var b = a.replace(/ /g,'').split(',');
return new google.maps.LatLng(b[0], b[1]);
}
} | [
"function",
"(",
"a",
")",
"{",
"if",
"(",
"a",
"instanceof",
"google",
".",
"maps",
".",
"LatLng",
")",
"{",
"return",
"a",
";",
"}",
"else",
"{",
"var",
"b",
"=",
"a",
".",
"replace",
"(",
"/",
" ",
"/",
"g",
",",
"''",
")",
".",
"split",
... | Helper method for google.maps.Latlng
@param callback | [
"Helper",
"method",
"for",
"google",
".",
"maps",
".",
"Latlng"
] | 9aec5443860926654c2ab8ee3bf198a407c53b07 | https://github.com/splunk/splunk-sdk-javascript/blob/9aec5443860926654c2ab8ee3bf198a407c53b07/examples/browser/minisplunk/jquery.fn.gmap.js#L290-L297 | train | |
splunk/splunk-sdk-javascript | bin/cli.js | function(sourceDir, newDirLocation, opts) {
if (!opts || !opts.preserve) {
try {
if(fs.statSync(newDirLocation).isDirectory()) {
exports.rmdirSyncRecursive(newDirLocation);
}
}
catch(e) { }
}
/* Create the... | javascript | function(sourceDir, newDirLocation, opts) {
if (!opts || !opts.preserve) {
try {
if(fs.statSync(newDirLocation).isDirectory()) {
exports.rmdirSyncRecursive(newDirLocation);
}
}
catch(e) { }
}
/* Create the... | [
"function",
"(",
"sourceDir",
",",
"newDirLocation",
",",
"opts",
")",
"{",
"if",
"(",
"!",
"opts",
"||",
"!",
"opts",
".",
"preserve",
")",
"{",
"try",
"{",
"if",
"(",
"fs",
".",
"statSync",
"(",
"newDirLocation",
")",
".",
"isDirectory",
"(",
")",
... | Taken from wrench.js | [
"Taken",
"from",
"wrench",
".",
"js"
] | 9aec5443860926654c2ab8ee3bf198a407c53b07 | https://github.com/splunk/splunk-sdk-javascript/blob/9aec5443860926654c2ab8ee3bf198a407c53b07/bin/cli.js#L208-L250 | train | |
splunk/splunk-sdk-javascript | examples/node/search.js | function(job, done) {
Async.whilst(
function() { return !job.properties().isDone; },
function(iterationDone) {
job.fetch(function(err, job) {
if (err) {
cal... | javascript | function(job, done) {
Async.whilst(
function() { return !job.properties().isDone; },
function(iterationDone) {
job.fetch(function(err, job) {
if (err) {
cal... | [
"function",
"(",
"job",
",",
"done",
")",
"{",
"Async",
".",
"whilst",
"(",
"function",
"(",
")",
"{",
"return",
"!",
"job",
".",
"properties",
"(",
")",
".",
"isDone",
";",
"}",
",",
"function",
"(",
"iterationDone",
")",
"{",
"job",
".",
"fetch",... | Poll until the search is complete | [
"Poll",
"until",
"the",
"search",
"is",
"complete"
] | 9aec5443860926654c2ab8ee3bf198a407c53b07 | https://github.com/splunk/splunk-sdk-javascript/blob/9aec5443860926654c2ab8ee3bf198a407c53b07/examples/node/search.js#L62-L98 | train | |
splunk/splunk-sdk-javascript | examples/node/results.js | function(results) {
for(var i = 0; i < results.rows.length; i++) {
console.log("Result " + (i + 1) + ": ");
var row = results.rows[i];
for(var j = 0; j < results.fields.length; j++) {
var field = results.fields[j];
var value = row[j];
... | javascript | function(results) {
for(var i = 0; i < results.rows.length; i++) {
console.log("Result " + (i + 1) + ": ");
var row = results.rows[i];
for(var j = 0; j < results.fields.length; j++) {
var field = results.fields[j];
var value = row[j];
... | [
"function",
"(",
"results",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"results",
".",
"rows",
".",
"length",
";",
"i",
"++",
")",
"{",
"console",
".",
"log",
"(",
"\"Result \"",
"+",
"(",
"i",
"+",
"1",
")",
"+",
"\": \"",
")... | Print the result rows | [
"Print",
"the",
"result",
"rows"
] | 9aec5443860926654c2ab8ee3bf198a407c53b07 | https://github.com/splunk/splunk-sdk-javascript/blob/9aec5443860926654c2ab8ee3bf198a407c53b07/examples/node/results.js#L24-L35 | train | |
splunk/splunk-sdk-javascript | examples/node/results.js | function(results) {
var rows = [];
var cols = results.columns;
var mapFirst = function(col) { return col.shift(); };
while(cols.length > 0 && cols[0].length > 0) {
rows.push(cols.map(mapFirst));
}
results.rows = rows;
retu... | javascript | function(results) {
var rows = [];
var cols = results.columns;
var mapFirst = function(col) { return col.shift(); };
while(cols.length > 0 && cols[0].length > 0) {
rows.push(cols.map(mapFirst));
}
results.rows = rows;
retu... | [
"function",
"(",
"results",
")",
"{",
"var",
"rows",
"=",
"[",
"]",
";",
"var",
"cols",
"=",
"results",
".",
"columns",
";",
"var",
"mapFirst",
"=",
"function",
"(",
"col",
")",
"{",
"return",
"col",
".",
"shift",
"(",
")",
";",
"}",
";",
"while"... | Instead of trying to print the column-major format, we just transpose it | [
"Instead",
"of",
"trying",
"to",
"print",
"the",
"column",
"-",
"major",
"format",
"we",
"just",
"transpose",
"it"
] | 9aec5443860926654c2ab8ee3bf198a407c53b07 | https://github.com/splunk/splunk-sdk-javascript/blob/9aec5443860926654c2ab8ee3bf198a407c53b07/examples/node/results.js#L39-L51 | train | |
splunk/splunk-sdk-javascript | examples/node/results.js | function(results) {
if (results) {
var isRows = !!results.rows;
var numResults = (results.rows ? results.rows.length : (results.columns[0] || []).length);
console.log("====== " + numResults + " RESULTS (preview: " + !!results.preview + ") ======");
... | javascript | function(results) {
if (results) {
var isRows = !!results.rows;
var numResults = (results.rows ? results.rows.length : (results.columns[0] || []).length);
console.log("====== " + numResults + " RESULTS (preview: " + !!results.preview + ") ======");
... | [
"function",
"(",
"results",
")",
"{",
"if",
"(",
"results",
")",
"{",
"var",
"isRows",
"=",
"!",
"!",
"results",
".",
"rows",
";",
"var",
"numResults",
"=",
"(",
"results",
".",
"rows",
"?",
"results",
".",
"rows",
".",
"length",
":",
"(",
"results... | Print the results | [
"Print",
"the",
"results"
] | 9aec5443860926654c2ab8ee3bf198a407c53b07 | https://github.com/splunk/splunk-sdk-javascript/blob/9aec5443860926654c2ab8ee3bf198a407c53b07/examples/node/results.js#L54-L68 | train | |
lampaa/com.lampa.startapp | www/startApp.manually.js | function(params, extra) {
var output = [params];
if(extra != undefined) {
output.push(extra);
}
else {
output.push(null);
}
return {
start: function(completeCallback, errorCallback, messageCallback) {
completeCallback = completeCallback || function() {};
errorCallback = errorCallback... | javascript | function(params, extra) {
var output = [params];
if(extra != undefined) {
output.push(extra);
}
else {
output.push(null);
}
return {
start: function(completeCallback, errorCallback, messageCallback) {
completeCallback = completeCallback || function() {};
errorCallback = errorCallback... | [
"function",
"(",
"params",
",",
"extra",
")",
"{",
"var",
"output",
"=",
"[",
"params",
"]",
";",
"if",
"(",
"extra",
"!=",
"undefined",
")",
"{",
"output",
".",
"push",
"(",
"extra",
")",
";",
"}",
"else",
"{",
"output",
".",
"push",
"(",
"null"... | Set application params
@param {Mixed} params params, view documentation https://github.com/lampaa/com.lampa.startapp
@param {Mixed} extra Extra fields
@param {Function} errorCallback The callback that is called when an error occurred when the program starts. | [
"Set",
"application",
"params"
] | 2fa54b40316e45411e457d4227b4c409f15227b0 | https://github.com/lampaa/com.lampa.startapp/blob/2fa54b40316e45411e457d4227b4c409f15227b0/www/startApp.manually.js#L22-L77 | train | |
raml2html/raml2html | index.js | render | function render(source, config, options) {
config = config || {};
config.raml2HtmlVersion = pjson.version;
// Check if option is old boolean `validation` to keep backward compatibility
if (typeof options === 'boolean') {
options = {
validate: options,
};
}
if (options === undefined) {
op... | javascript | function render(source, config, options) {
config = config || {};
config.raml2HtmlVersion = pjson.version;
// Check if option is old boolean `validation` to keep backward compatibility
if (typeof options === 'boolean') {
options = {
validate: options,
};
}
if (options === undefined) {
op... | [
"function",
"render",
"(",
"source",
",",
"config",
",",
"options",
")",
"{",
"config",
"=",
"config",
"||",
"{",
"}",
";",
"config",
".",
"raml2HtmlVersion",
"=",
"pjson",
".",
"version",
";",
"// Check if option is old boolean `validation` to keep backward compati... | Render the source RAML object using the config's processOutput function
The config object should contain at least the following property:
processRamlObj: function that takes the raw RAML object and returns a promise with the rendered HTML
@param {(String|Object)} source - The source RAML file. Can be a filename, url,... | [
"Render",
"the",
"source",
"RAML",
"object",
"using",
"the",
"config",
"s",
"processOutput",
"function"
] | 3f0c479bb2ec7280a72ca953fca7eb965dbf28c9 | https://github.com/raml2html/raml2html/blob/3f0c479bb2ec7280a72ca953fca7eb965dbf28c9/index.js#L25-L59 | train |
stovmascript/react-native-version | index.js | getPlistFilenames | function getPlistFilenames(xcode) {
return unique(
flattenDeep(
xcode.document.projects.map(project => {
return project.targets.filter(Boolean).map(target => {
return target.buildConfigurationsList.buildConfigurations.map(
config => {
return config.ast.value.get("buildSettings").get("INFOPLI... | javascript | function getPlistFilenames(xcode) {
return unique(
flattenDeep(
xcode.document.projects.map(project => {
return project.targets.filter(Boolean).map(target => {
return target.buildConfigurationsList.buildConfigurations.map(
config => {
return config.ast.value.get("buildSettings").get("INFOPLI... | [
"function",
"getPlistFilenames",
"(",
"xcode",
")",
"{",
"return",
"unique",
"(",
"flattenDeep",
"(",
"xcode",
".",
"document",
".",
"projects",
".",
"map",
"(",
"project",
"=>",
"{",
"return",
"project",
".",
"targets",
".",
"filter",
"(",
"Boolean",
")",... | Returns Info.plist filenames
@private
@param {Xcode} xcode Opened Xcode project file
@return {Array} Plist filenames | [
"Returns",
"Info",
".",
"plist",
"filenames"
] | 0ff1d9a95d0a6c98ea24a0a46a3b3319b7945e21 | https://github.com/stovmascript/react-native-version/blob/0ff1d9a95d0a6c98ea24a0a46a3b3319b7945e21/index.js#L47-L62 | train |
stovmascript/react-native-version | index.js | isExpoProject | function isExpoProject(projPath) {
try {
let module = resolveFrom(projPath, "expo");
let appInfo = require(`${projPath}/app.json`);
return !!(module && appInfo.expo);
} catch (err) {
return false;
}
} | javascript | function isExpoProject(projPath) {
try {
let module = resolveFrom(projPath, "expo");
let appInfo = require(`${projPath}/app.json`);
return !!(module && appInfo.expo);
} catch (err) {
return false;
}
} | [
"function",
"isExpoProject",
"(",
"projPath",
")",
"{",
"try",
"{",
"let",
"module",
"=",
"resolveFrom",
"(",
"projPath",
",",
"\"expo\"",
")",
";",
"let",
"appInfo",
"=",
"require",
"(",
"`",
"${",
"projPath",
"}",
"`",
")",
";",
"return",
"!",
"!",
... | Determines whether the project is an Expo app or a plain React Native app
@private
@return {Boolean} true if the project is an Expo app | [
"Determines",
"whether",
"the",
"project",
"is",
"an",
"Expo",
"app",
"or",
"a",
"plain",
"React",
"Native",
"app"
] | 0ff1d9a95d0a6c98ea24a0a46a3b3319b7945e21 | https://github.com/stovmascript/react-native-version/blob/0ff1d9a95d0a6c98ea24a0a46a3b3319b7945e21/index.js#L69-L78 | train |
stovmascript/react-native-version | util.js | log | function log(msg, silent) {
if (!silent) {
console.log("[RNV]", chalk[msg.style || "reset"](msg.text));
}
} | javascript | function log(msg, silent) {
if (!silent) {
console.log("[RNV]", chalk[msg.style || "reset"](msg.text));
}
} | [
"function",
"log",
"(",
"msg",
",",
"silent",
")",
"{",
"if",
"(",
"!",
"silent",
")",
"{",
"console",
".",
"log",
"(",
"\"[RNV]\"",
",",
"chalk",
"[",
"msg",
".",
"style",
"||",
"\"reset\"",
"]",
"(",
"msg",
".",
"text",
")",
")",
";",
"}",
"}... | Logs a message into the console with style
@param {Object} msg Object containing the message text and chalk style
@param {boolean} silent Whether log should be quiet | [
"Logs",
"a",
"message",
"into",
"the",
"console",
"with",
"style"
] | 0ff1d9a95d0a6c98ea24a0a46a3b3319b7945e21 | https://github.com/stovmascript/react-native-version/blob/0ff1d9a95d0a6c98ea24a0a46a3b3319b7945e21/util.js#L17-L21 | train |
videojs/videojs-vr | src/orbit-orientation-controls.js | Quat2Angle | function Quat2Angle(x, y, z, w) {
const test = x * y + z * w;
// singularity at north pole
if (test > 0.499) {
const yaw = 2 * Math.atan2(x, w);
const pitch = Math.PI / 2;
const roll = 0;
return new THREE.Vector3(pitch, roll, yaw);
}
// singularity at south pole
if (test < -0.499) {
c... | javascript | function Quat2Angle(x, y, z, w) {
const test = x * y + z * w;
// singularity at north pole
if (test > 0.499) {
const yaw = 2 * Math.atan2(x, w);
const pitch = Math.PI / 2;
const roll = 0;
return new THREE.Vector3(pitch, roll, yaw);
}
// singularity at south pole
if (test < -0.499) {
c... | [
"function",
"Quat2Angle",
"(",
"x",
",",
"y",
",",
"z",
",",
"w",
")",
"{",
"const",
"test",
"=",
"x",
"*",
"y",
"+",
"z",
"*",
"w",
";",
"// singularity at north pole",
"if",
"(",
"test",
">",
"0.499",
")",
"{",
"const",
"yaw",
"=",
"2",
"*",
... | Convert a quaternion to an angle
Taken from https://stackoverflow.com/a/35448946
Thanks P. Ellul | [
"Convert",
"a",
"quaternion",
"to",
"an",
"angle"
] | b2ee7945e30fb8f913cc555d03120fd4b467f5b5 | https://github.com/videojs/videojs-vr/blob/b2ee7945e30fb8f913cc555d03120fd4b467f5b5/src/orbit-orientation-controls.js#L11-L40 | train |
tommoor/react-emoji-render | src/unicodeToCodepoint.js | toCodePoint | function toCodePoint(input, separator = "-") {
const codePoints = [];
for (let codePoint of input) {
codePoints.push(codePoint.codePointAt(0).toString(16));
}
return codePoints.join(separator);
} | javascript | function toCodePoint(input, separator = "-") {
const codePoints = [];
for (let codePoint of input) {
codePoints.push(codePoint.codePointAt(0).toString(16));
}
return codePoints.join(separator);
} | [
"function",
"toCodePoint",
"(",
"input",
",",
"separator",
"=",
"\"-\"",
")",
"{",
"const",
"codePoints",
"=",
"[",
"]",
";",
"for",
"(",
"let",
"codePoint",
"of",
"input",
")",
"{",
"codePoints",
".",
"push",
"(",
"codePoint",
".",
"codePointAt",
"(",
... | convert utf16 into code points | [
"convert",
"utf16",
"into",
"code",
"points"
] | 7122d0fbe91766cd4836c123c8dd3944c1af1ffd | https://github.com/tommoor/react-emoji-render/blob/7122d0fbe91766cd4836c123c8dd3944c1af1ffd/src/unicodeToCodepoint.js#L11-L17 | train |
ngVue/ngVue | src/plugins/filters.js | registerFilters | function registerFilters (filters) {
if (isArray(filters)) {
lazyStringFilters = lazyStringFilters.concat(filters)
} else if (isObject(filters)) {
Object.keys(filters).forEach(name => {
addFilter(name, filters[name])
})
}
} | javascript | function registerFilters (filters) {
if (isArray(filters)) {
lazyStringFilters = lazyStringFilters.concat(filters)
} else if (isObject(filters)) {
Object.keys(filters).forEach(name => {
addFilter(name, filters[name])
})
}
} | [
"function",
"registerFilters",
"(",
"filters",
")",
"{",
"if",
"(",
"isArray",
"(",
"filters",
")",
")",
"{",
"lazyStringFilters",
"=",
"lazyStringFilters",
".",
"concat",
"(",
"filters",
")",
"}",
"else",
"if",
"(",
"isObject",
"(",
"filters",
")",
")",
... | register a list of ng filters to ngVue | [
"register",
"a",
"list",
"of",
"ng",
"filters",
"to",
"ngVue"
] | 0ceb8a7b025aea1de86ab4e7175e7e6057dfb8fa | https://github.com/ngVue/ngVue/blob/0ceb8a7b025aea1de86ab4e7175e7e6057dfb8fa/src/plugins/filters.js#L27-L35 | train |
lynndylanhurley/redux-auth | dummy/src/server.js | getMarkup | function getMarkup(webserver, provider) {
var markup = renderToString(provider),
styles = "";
if (process.env.NODE_ENV === "production") {
styles = `<link href="${webserver}/dist/main.css" rel="stylesheet"></link>`;
}
return `<!doctype html>
<html>
<head>
... | javascript | function getMarkup(webserver, provider) {
var markup = renderToString(provider),
styles = "";
if (process.env.NODE_ENV === "production") {
styles = `<link href="${webserver}/dist/main.css" rel="stylesheet"></link>`;
}
return `<!doctype html>
<html>
<head>
... | [
"function",
"getMarkup",
"(",
"webserver",
",",
"provider",
")",
"{",
"var",
"markup",
"=",
"renderToString",
"(",
"provider",
")",
",",
"styles",
"=",
"\"\"",
";",
"if",
"(",
"process",
".",
"env",
".",
"NODE_ENV",
"===",
"\"production\"",
")",
"{",
"st... | base html template | [
"base",
"html",
"template"
] | dc27f381cb7d16fcd4c812c7c1a2f9f921d73164 | https://github.com/lynndylanhurley/redux-auth/blob/dc27f381cb7d16fcd4c812c7c1a2f9f921d73164/dummy/src/server.js#L16-L38 | train |
MABelanger/jslib-html5-camera-photo | src/demo/AppSimpleVanillaJs.js | takePhoto | function takePhoto () {
let sizeFactor = 1;
let imageType = IMAGE_TYPES.JPG;
let imageCompression = 1;
let config = {
sizeFactor,
imageType,
imageCompression
};
let dataUri = cameraPhoto.getDataUri(config);
imgElement.src = dataUri;
} | javascript | function takePhoto () {
let sizeFactor = 1;
let imageType = IMAGE_TYPES.JPG;
let imageCompression = 1;
let config = {
sizeFactor,
imageType,
imageCompression
};
let dataUri = cameraPhoto.getDataUri(config);
imgElement.src = dataUri;
} | [
"function",
"takePhoto",
"(",
")",
"{",
"let",
"sizeFactor",
"=",
"1",
";",
"let",
"imageType",
"=",
"IMAGE_TYPES",
".",
"JPG",
";",
"let",
"imageCompression",
"=",
"1",
";",
"let",
"config",
"=",
"{",
"sizeFactor",
",",
"imageType",
",",
"imageCompression... | function called by the buttons. | [
"function",
"called",
"by",
"the",
"buttons",
"."
] | dafa2f415caf4d0728743aae69285707c4c21ab9 | https://github.com/MABelanger/jslib-html5-camera-photo/blob/dafa2f415caf4d0728743aae69285707c4c21ab9/src/demo/AppSimpleVanillaJs.js#L56-L69 | train |
BenjaminBrandmeier/angular2-image-gallery | browserstack/browserstack_local.conf.js | function () {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
console.log("Connecting local");
return new Promise(function (resolve, reject) {
exports.bs_local = new browserstack.Local();
exports.bs_local.start({'key': exports.config.capabilities['browserstack.key']}... | javascript | function () {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
console.log("Connecting local");
return new Promise(function (resolve, reject) {
exports.bs_local = new browserstack.Local();
exports.bs_local.start({'key': exports.config.capabilities['browserstack.key']}... | [
"function",
"(",
")",
"{",
"require",
"(",
"'ts-node'",
")",
".",
"register",
"(",
"{",
"project",
":",
"'e2e/tsconfig.e2e.json'",
"}",
")",
";",
"console",
".",
"log",
"(",
"\"Connecting local\"",
")",
";",
"return",
"new",
"Promise",
"(",
"function",
"("... | Code to start browserstack local before start of test | [
"Code",
"to",
"start",
"browserstack",
"local",
"before",
"start",
"of",
"test"
] | 504629c02516ae058c73433d1b5184f98ca47733 | https://github.com/BenjaminBrandmeier/angular2-image-gallery/blob/504629c02516ae058c73433d1b5184f98ca47733/browserstack/browserstack_local.conf.js#L21-L35 | train | |
mongodb-js/mongodb-core | lib/utils.js | relayEvents | function relayEvents(listener, emitter, events) {
events.forEach(eventName => listener.on(eventName, event => emitter.emit(eventName, event)));
} | javascript | function relayEvents(listener, emitter, events) {
events.forEach(eventName => listener.on(eventName, event => emitter.emit(eventName, event)));
} | [
"function",
"relayEvents",
"(",
"listener",
",",
"emitter",
",",
"events",
")",
"{",
"events",
".",
"forEach",
"(",
"eventName",
"=>",
"listener",
".",
"on",
"(",
"eventName",
",",
"event",
"=>",
"emitter",
".",
"emit",
"(",
"eventName",
",",
"event",
")... | Relays events for a given listener and emitter
@param {EventEmitter} listener the EventEmitter to listen to the events from
@param {EventEmitter} emitter the EventEmitter to relay the events to | [
"Relays",
"events",
"for",
"a",
"given",
"listener",
"and",
"emitter"
] | bcb87caa89f5841272955fb4b320f75d632856f7 | https://github.com/mongodb-js/mongodb-core/blob/bcb87caa89f5841272955fb4b320f75d632856f7/lib/utils.js#L33-L35 | train |
mongodb-js/mongodb-core | lib/utils.js | retrieveEJSON | function retrieveEJSON() {
let EJSON = null;
try {
EJSON = requireOptional('mongodb-extjson');
} catch (error) {} // eslint-disable-line
if (!EJSON) {
EJSON = {
parse: noEJSONError,
deserialize: noEJSONError,
serialize: noEJSONError,
stringify: noEJSONError,
setBSONModule: ... | javascript | function retrieveEJSON() {
let EJSON = null;
try {
EJSON = requireOptional('mongodb-extjson');
} catch (error) {} // eslint-disable-line
if (!EJSON) {
EJSON = {
parse: noEJSONError,
deserialize: noEJSONError,
serialize: noEJSONError,
stringify: noEJSONError,
setBSONModule: ... | [
"function",
"retrieveEJSON",
"(",
")",
"{",
"let",
"EJSON",
"=",
"null",
";",
"try",
"{",
"EJSON",
"=",
"requireOptional",
"(",
"'mongodb-extjson'",
")",
";",
"}",
"catch",
"(",
"error",
")",
"{",
"}",
"// eslint-disable-line",
"if",
"(",
"!",
"EJSON",
"... | Facilitate loading EJSON optionally | [
"Facilitate",
"loading",
"EJSON",
"optionally"
] | bcb87caa89f5841272955fb4b320f75d632856f7 | https://github.com/mongodb-js/mongodb-core/blob/bcb87caa89f5841272955fb4b320f75d632856f7/lib/utils.js#L59-L76 | train |
mongodb-js/mongodb-core | lib/utils.js | maxWireVersion | function maxWireVersion(topologyOrServer) {
if (topologyOrServer.ismaster) {
return topologyOrServer.ismaster.maxWireVersion;
}
if (topologyOrServer.description) {
return topologyOrServer.description.maxWireVersion;
}
return null;
} | javascript | function maxWireVersion(topologyOrServer) {
if (topologyOrServer.ismaster) {
return topologyOrServer.ismaster.maxWireVersion;
}
if (topologyOrServer.description) {
return topologyOrServer.description.maxWireVersion;
}
return null;
} | [
"function",
"maxWireVersion",
"(",
"topologyOrServer",
")",
"{",
"if",
"(",
"topologyOrServer",
".",
"ismaster",
")",
"{",
"return",
"topologyOrServer",
".",
"ismaster",
".",
"maxWireVersion",
";",
"}",
"if",
"(",
"topologyOrServer",
".",
"description",
")",
"{"... | A helper function for determining `maxWireVersion` between legacy and new topology
instances
@private
@param {(Topology|Server)} topologyOrServer | [
"A",
"helper",
"function",
"for",
"determining",
"maxWireVersion",
"between",
"legacy",
"and",
"new",
"topology",
"instances"
] | bcb87caa89f5841272955fb4b320f75d632856f7 | https://github.com/mongodb-js/mongodb-core/blob/bcb87caa89f5841272955fb4b320f75d632856f7/lib/utils.js#L85-L95 | train |
mongodb-js/mongodb-core | lib/sdam/server_selectors.js | writableServerSelector | function writableServerSelector() {
return function(topologyDescription, servers) {
return latencyWindowReducer(topologyDescription, servers.filter(s => s.isWritable));
};
} | javascript | function writableServerSelector() {
return function(topologyDescription, servers) {
return latencyWindowReducer(topologyDescription, servers.filter(s => s.isWritable));
};
} | [
"function",
"writableServerSelector",
"(",
")",
"{",
"return",
"function",
"(",
"topologyDescription",
",",
"servers",
")",
"{",
"return",
"latencyWindowReducer",
"(",
"topologyDescription",
",",
"servers",
".",
"filter",
"(",
"s",
"=>",
"s",
".",
"isWritable",
... | Returns a server selector that selects for writable servers | [
"Returns",
"a",
"server",
"selector",
"that",
"selects",
"for",
"writable",
"servers"
] | bcb87caa89f5841272955fb4b320f75d632856f7 | https://github.com/mongodb-js/mongodb-core/blob/bcb87caa89f5841272955fb4b320f75d632856f7/lib/sdam/server_selectors.js#L14-L18 | train |
mongodb-js/mongodb-core | lib/sdam/server_selectors.js | tagSetMatch | function tagSetMatch(tagSet, serverTags) {
const keys = Object.keys(tagSet);
const serverTagKeys = Object.keys(serverTags);
for (let i = 0; i < keys.length; ++i) {
const key = keys[i];
if (serverTagKeys.indexOf(key) === -1 || serverTags[key] !== tagSet[key]) {
return false;
}
}
return true;... | javascript | function tagSetMatch(tagSet, serverTags) {
const keys = Object.keys(tagSet);
const serverTagKeys = Object.keys(serverTags);
for (let i = 0; i < keys.length; ++i) {
const key = keys[i];
if (serverTagKeys.indexOf(key) === -1 || serverTags[key] !== tagSet[key]) {
return false;
}
}
return true;... | [
"function",
"tagSetMatch",
"(",
"tagSet",
",",
"serverTags",
")",
"{",
"const",
"keys",
"=",
"Object",
".",
"keys",
"(",
"tagSet",
")",
";",
"const",
"serverTagKeys",
"=",
"Object",
".",
"keys",
"(",
"serverTags",
")",
";",
"for",
"(",
"let",
"i",
"=",... | Determines whether a server's tags match a given set of tags
@param {String[]} tagSet The requested tag set to match
@param {String[]} serverTags The server's tags | [
"Determines",
"whether",
"a",
"server",
"s",
"tags",
"match",
"a",
"given",
"set",
"of",
"tags"
] | bcb87caa89f5841272955fb4b320f75d632856f7 | https://github.com/mongodb-js/mongodb-core/blob/bcb87caa89f5841272955fb4b320f75d632856f7/lib/sdam/server_selectors.js#L81-L92 | train |
mongodb-js/mongodb-core | lib/sdam/server_selectors.js | tagSetReducer | function tagSetReducer(readPreference, servers) {
if (
readPreference.tags == null ||
(Array.isArray(readPreference.tags) && readPreference.tags.length === 0)
) {
return servers;
}
for (let i = 0; i < readPreference.tags.length; ++i) {
const tagSet = readPreference.tags[i];
const serversMat... | javascript | function tagSetReducer(readPreference, servers) {
if (
readPreference.tags == null ||
(Array.isArray(readPreference.tags) && readPreference.tags.length === 0)
) {
return servers;
}
for (let i = 0; i < readPreference.tags.length; ++i) {
const tagSet = readPreference.tags[i];
const serversMat... | [
"function",
"tagSetReducer",
"(",
"readPreference",
",",
"servers",
")",
"{",
"if",
"(",
"readPreference",
".",
"tags",
"==",
"null",
"||",
"(",
"Array",
".",
"isArray",
"(",
"readPreference",
".",
"tags",
")",
"&&",
"readPreference",
".",
"tags",
".",
"le... | Reduces a set of server descriptions based on tags requested by the read preference
@param {ReadPreference} readPreference The read preference providing the requested tags
@param {ServerDescription[]} servers The list of server descriptions to reduce
@return {ServerDescription[]} The list of servers matching the reque... | [
"Reduces",
"a",
"set",
"of",
"server",
"descriptions",
"based",
"on",
"tags",
"requested",
"by",
"the",
"read",
"preference"
] | bcb87caa89f5841272955fb4b320f75d632856f7 | https://github.com/mongodb-js/mongodb-core/blob/bcb87caa89f5841272955fb4b320f75d632856f7/lib/sdam/server_selectors.js#L101-L122 | train |
mongodb-js/mongodb-core | lib/auth/defaultAuthProviders.js | defaultAuthProviders | function defaultAuthProviders(bson) {
return {
mongocr: new MongoCR(bson),
x509: new X509(bson),
plain: new Plain(bson),
gssapi: new GSSAPI(bson),
sspi: new SSPI(bson),
'scram-sha-1': new ScramSHA1(bson),
'scram-sha-256': new ScramSHA256(bson)
};
} | javascript | function defaultAuthProviders(bson) {
return {
mongocr: new MongoCR(bson),
x509: new X509(bson),
plain: new Plain(bson),
gssapi: new GSSAPI(bson),
sspi: new SSPI(bson),
'scram-sha-1': new ScramSHA1(bson),
'scram-sha-256': new ScramSHA256(bson)
};
} | [
"function",
"defaultAuthProviders",
"(",
"bson",
")",
"{",
"return",
"{",
"mongocr",
":",
"new",
"MongoCR",
"(",
"bson",
")",
",",
"x509",
":",
"new",
"X509",
"(",
"bson",
")",
",",
"plain",
":",
"new",
"Plain",
"(",
"bson",
")",
",",
"gssapi",
":",
... | Returns the default authentication providers.
@param {BSON} bson Bson definition
@returns {Object} a mapping of auth names to auth types | [
"Returns",
"the",
"default",
"authentication",
"providers",
"."
] | bcb87caa89f5841272955fb4b320f75d632856f7 | https://github.com/mongodb-js/mongodb-core/blob/bcb87caa89f5841272955fb4b320f75d632856f7/lib/auth/defaultAuthProviders.js#L17-L27 | train |
mongodb-js/mongodb-core | lib/connection/pool.js | canCompress | function canCompress(command) {
const commandDoc = command instanceof Msg ? command.command : command.query;
const commandName = Object.keys(commandDoc)[0];
return uncompressibleCommands.indexOf(commandName) === -1;
} | javascript | function canCompress(command) {
const commandDoc = command instanceof Msg ? command.command : command.query;
const commandName = Object.keys(commandDoc)[0];
return uncompressibleCommands.indexOf(commandName) === -1;
} | [
"function",
"canCompress",
"(",
"command",
")",
"{",
"const",
"commandDoc",
"=",
"command",
"instanceof",
"Msg",
"?",
"command",
".",
"command",
":",
"command",
".",
"query",
";",
"const",
"commandName",
"=",
"Object",
".",
"keys",
"(",
"commandDoc",
")",
... | Return whether a command contains an uncompressible command term Will return true if command contains no uncompressible command terms | [
"Return",
"whether",
"a",
"command",
"contains",
"an",
"uncompressible",
"command",
"term",
"Will",
"return",
"true",
"if",
"command",
"contains",
"no",
"uncompressible",
"command",
"terms"
] | bcb87caa89f5841272955fb4b320f75d632856f7 | https://github.com/mongodb-js/mongodb-core/blob/bcb87caa89f5841272955fb4b320f75d632856f7/lib/connection/pool.js#L953-L957 | train |
mongodb-js/mongodb-core | lib/connection/pool.js | remove | function remove(connection, connections) {
for (var i = 0; i < connections.length; i++) {
if (connections[i] === connection) {
connections.splice(i, 1);
return true;
}
}
} | javascript | function remove(connection, connections) {
for (var i = 0; i < connections.length; i++) {
if (connections[i] === connection) {
connections.splice(i, 1);
return true;
}
}
} | [
"function",
"remove",
"(",
"connection",
",",
"connections",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"connections",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"connections",
"[",
"i",
"]",
"===",
"connection",
")",
"{",
... | Remove connection method | [
"Remove",
"connection",
"method"
] | bcb87caa89f5841272955fb4b320f75d632856f7 | https://github.com/mongodb-js/mongodb-core/blob/bcb87caa89f5841272955fb4b320f75d632856f7/lib/connection/pool.js#L960-L967 | train |
mongodb-js/mongodb-core | lib/connection/utils.js | retrieveSnappy | function retrieveSnappy() {
var snappy = null;
try {
snappy = require_optional('snappy');
} catch (error) {} // eslint-disable-line
if (!snappy) {
snappy = {
compress: noSnappyWarning,
uncompress: noSnappyWarning,
compressSync: noSnappyWarning,
uncompressSync: noSnappyWarning
... | javascript | function retrieveSnappy() {
var snappy = null;
try {
snappy = require_optional('snappy');
} catch (error) {} // eslint-disable-line
if (!snappy) {
snappy = {
compress: noSnappyWarning,
uncompress: noSnappyWarning,
compressSync: noSnappyWarning,
uncompressSync: noSnappyWarning
... | [
"function",
"retrieveSnappy",
"(",
")",
"{",
"var",
"snappy",
"=",
"null",
";",
"try",
"{",
"snappy",
"=",
"require_optional",
"(",
"'snappy'",
")",
";",
"}",
"catch",
"(",
"error",
")",
"{",
"}",
"// eslint-disable-line",
"if",
"(",
"!",
"snappy",
")",
... | Facilitate loading Snappy optionally | [
"Facilitate",
"loading",
"Snappy",
"optionally"
] | bcb87caa89f5841272955fb4b320f75d632856f7 | https://github.com/mongodb-js/mongodb-core/blob/bcb87caa89f5841272955fb4b320f75d632856f7/lib/connection/utils.js#L37-L51 | train |
mongodb-js/mongodb-core | lib/uri_parser.js | matchesParentDomain | function matchesParentDomain(srvAddress, parentDomain) {
const regex = /^.*?\./;
const srv = `.${srvAddress.replace(regex, '')}`;
const parent = `.${parentDomain.replace(regex, '')}`;
return srv.endsWith(parent);
} | javascript | function matchesParentDomain(srvAddress, parentDomain) {
const regex = /^.*?\./;
const srv = `.${srvAddress.replace(regex, '')}`;
const parent = `.${parentDomain.replace(regex, '')}`;
return srv.endsWith(parent);
} | [
"function",
"matchesParentDomain",
"(",
"srvAddress",
",",
"parentDomain",
")",
"{",
"const",
"regex",
"=",
"/",
"^.*?\\.",
"/",
";",
"const",
"srv",
"=",
"`",
"${",
"srvAddress",
".",
"replace",
"(",
"regex",
",",
"''",
")",
"}",
"`",
";",
"const",
"p... | Determines whether a provided address matches the provided parent domain in order
to avoid certain attack vectors.
@param {String} srvAddress The address to check against a domain
@param {String} parentDomain The domain to check the provided address against
@return {Boolean} Whether the provided address matches the pa... | [
"Determines",
"whether",
"a",
"provided",
"address",
"matches",
"the",
"provided",
"parent",
"domain",
"in",
"order",
"to",
"avoid",
"certain",
"attack",
"vectors",
"."
] | bcb87caa89f5841272955fb4b320f75d632856f7 | https://github.com/mongodb-js/mongodb-core/blob/bcb87caa89f5841272955fb4b320f75d632856f7/lib/uri_parser.js#L22-L27 | train |
mongodb-js/mongodb-core | lib/uri_parser.js | parseSrvConnectionString | function parseSrvConnectionString(uri, options, callback) {
const result = URL.parse(uri, true);
if (result.hostname.split('.').length < 3) {
return callback(new MongoParseError('URI does not have hostname, domain name and tld'));
}
result.domainLength = result.hostname.split('.').length;
if (result.pat... | javascript | function parseSrvConnectionString(uri, options, callback) {
const result = URL.parse(uri, true);
if (result.hostname.split('.').length < 3) {
return callback(new MongoParseError('URI does not have hostname, domain name and tld'));
}
result.domainLength = result.hostname.split('.').length;
if (result.pat... | [
"function",
"parseSrvConnectionString",
"(",
"uri",
",",
"options",
",",
"callback",
")",
"{",
"const",
"result",
"=",
"URL",
".",
"parse",
"(",
"uri",
",",
"true",
")",
";",
"if",
"(",
"result",
".",
"hostname",
".",
"split",
"(",
"'.'",
")",
".",
"... | Lookup a `mongodb+srv` connection string, combine the parts and reparse it as a normal
connection string.
@param {string} uri The connection string to parse
@param {object} options Optional user provided connection string options
@param {function} callback | [
"Lookup",
"a",
"mongodb",
"+",
"srv",
"connection",
"string",
"combine",
"the",
"parts",
"and",
"reparse",
"it",
"as",
"a",
"normal",
"connection",
"string",
"."
] | bcb87caa89f5841272955fb4b320f75d632856f7 | https://github.com/mongodb-js/mongodb-core/blob/bcb87caa89f5841272955fb4b320f75d632856f7/lib/uri_parser.js#L37-L113 | train |
mongodb-js/mongodb-core | lib/uri_parser.js | parseQueryStringItemValue | function parseQueryStringItemValue(key, value) {
if (Array.isArray(value)) {
// deduplicate and simplify arrays
value = value.filter((v, idx) => value.indexOf(v) === idx);
if (value.length === 1) value = value[0];
} else if (value.indexOf(':') > 0) {
value = value.split(',').reduce((result, pair) =>... | javascript | function parseQueryStringItemValue(key, value) {
if (Array.isArray(value)) {
// deduplicate and simplify arrays
value = value.filter((v, idx) => value.indexOf(v) === idx);
if (value.length === 1) value = value[0];
} else if (value.indexOf(':') > 0) {
value = value.split(',').reduce((result, pair) =>... | [
"function",
"parseQueryStringItemValue",
"(",
"key",
",",
"value",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"value",
")",
")",
"{",
"// deduplicate and simplify arrays",
"value",
"=",
"value",
".",
"filter",
"(",
"(",
"v",
",",
"idx",
")",
"=>",
... | Parses a query string item according to the connection string spec
@param {string} key The key for the parsed value
@param {Array|String} value The value to parse
@return {Array|Object|String} The parsed value | [
"Parses",
"a",
"query",
"string",
"item",
"according",
"to",
"the",
"connection",
"string",
"spec"
] | bcb87caa89f5841272955fb4b320f75d632856f7 | https://github.com/mongodb-js/mongodb-core/blob/bcb87caa89f5841272955fb4b320f75d632856f7/lib/uri_parser.js#L122-L147 | train |
mongodb-js/mongodb-core | lib/uri_parser.js | applyConnectionStringOption | function applyConnectionStringOption(obj, key, value, options) {
// simple key translation
if (key === 'journal') {
key = 'j';
} else if (key === 'wtimeoutms') {
key = 'wtimeout';
}
// more complicated translation
if (BOOLEAN_OPTIONS.has(key)) {
value = value === 'true' || value === true;
} e... | javascript | function applyConnectionStringOption(obj, key, value, options) {
// simple key translation
if (key === 'journal') {
key = 'j';
} else if (key === 'wtimeoutms') {
key = 'wtimeout';
}
// more complicated translation
if (BOOLEAN_OPTIONS.has(key)) {
value = value === 'true' || value === true;
} e... | [
"function",
"applyConnectionStringOption",
"(",
"obj",
",",
"key",
",",
"value",
",",
"options",
")",
"{",
"// simple key translation",
"if",
"(",
"key",
"===",
"'journal'",
")",
"{",
"key",
"=",
"'j'",
";",
"}",
"else",
"if",
"(",
"key",
"===",
"'wtimeout... | Sets the value for `key`, allowing for any required translation
@param {object} obj The object to set the key on
@param {string} key The key to set the value for
@param {*} value The value to set
@param {object} options The options used for option parsing | [
"Sets",
"the",
"value",
"for",
"key",
"allowing",
"for",
"any",
"required",
"translation"
] | bcb87caa89f5841272955fb4b320f75d632856f7 | https://github.com/mongodb-js/mongodb-core/blob/bcb87caa89f5841272955fb4b320f75d632856f7/lib/uri_parser.js#L221-L292 | train |
mongodb-js/mongodb-core | lib/uri_parser.js | applyAuthExpectations | function applyAuthExpectations(parsed) {
if (parsed.options == null) {
return;
}
const options = parsed.options;
const authSource = options.authsource || options.authSource;
if (authSource != null) {
parsed.auth = Object.assign({}, parsed.auth, { db: authSource });
}
const authMechanism = option... | javascript | function applyAuthExpectations(parsed) {
if (parsed.options == null) {
return;
}
const options = parsed.options;
const authSource = options.authsource || options.authSource;
if (authSource != null) {
parsed.auth = Object.assign({}, parsed.auth, { db: authSource });
}
const authMechanism = option... | [
"function",
"applyAuthExpectations",
"(",
"parsed",
")",
"{",
"if",
"(",
"parsed",
".",
"options",
"==",
"null",
")",
"{",
"return",
";",
"}",
"const",
"options",
"=",
"parsed",
".",
"options",
";",
"const",
"authSource",
"=",
"options",
".",
"authsource",... | Modifies the parsed connection string object taking into account expectations we
have for authentication-related options.
@param {object} parsed The parsed connection string result
@return The parsed connection string result possibly modified for auth expectations | [
"Modifies",
"the",
"parsed",
"connection",
"string",
"object",
"taking",
"into",
"account",
"expectations",
"we",
"have",
"for",
"authentication",
"-",
"related",
"options",
"."
] | bcb87caa89f5841272955fb4b320f75d632856f7 | https://github.com/mongodb-js/mongodb-core/blob/bcb87caa89f5841272955fb4b320f75d632856f7/lib/uri_parser.js#L323-L380 | train |
mongodb-js/mongodb-core | lib/uri_parser.js | checkTLSOptions | function checkTLSOptions(queryString) {
const queryStringKeys = Object.keys(queryString);
if (
queryStringKeys.indexOf('tlsInsecure') !== -1 &&
(queryStringKeys.indexOf('tlsAllowInvalidCertificates') !== -1 ||
queryStringKeys.indexOf('tlsAllowInvalidHostnames') !== -1)
) {
throw new MongoParseEr... | javascript | function checkTLSOptions(queryString) {
const queryStringKeys = Object.keys(queryString);
if (
queryStringKeys.indexOf('tlsInsecure') !== -1 &&
(queryStringKeys.indexOf('tlsAllowInvalidCertificates') !== -1 ||
queryStringKeys.indexOf('tlsAllowInvalidHostnames') !== -1)
) {
throw new MongoParseEr... | [
"function",
"checkTLSOptions",
"(",
"queryString",
")",
"{",
"const",
"queryStringKeys",
"=",
"Object",
".",
"keys",
"(",
"queryString",
")",
";",
"if",
"(",
"queryStringKeys",
".",
"indexOf",
"(",
"'tlsInsecure'",
")",
"!==",
"-",
"1",
"&&",
"(",
"queryStri... | Checks a query string for invalid tls options according to the URI options spec.
@param {string} queryString The query string to check
@throws {MongoParseError} | [
"Checks",
"a",
"query",
"string",
"for",
"invalid",
"tls",
"options",
"according",
"to",
"the",
"URI",
"options",
"spec",
"."
] | bcb87caa89f5841272955fb4b320f75d632856f7 | https://github.com/mongodb-js/mongodb-core/blob/bcb87caa89f5841272955fb4b320f75d632856f7/lib/uri_parser.js#L421-L441 | train |
mongodb-js/mongodb-core | lib/topologies/replset.js | function(self, server, cb) {
// Measure running time
var start = new Date().getTime();
// Emit the server heartbeat start
emitSDAMEvent(self, 'serverHeartbeatStarted', { connectionId: server.name });
// Execute ismaster
// Set the socketTimeout for a monitoring message to a low number
// Ensuring ismast... | javascript | function(self, server, cb) {
// Measure running time
var start = new Date().getTime();
// Emit the server heartbeat start
emitSDAMEvent(self, 'serverHeartbeatStarted', { connectionId: server.name });
// Execute ismaster
// Set the socketTimeout for a monitoring message to a low number
// Ensuring ismast... | [
"function",
"(",
"self",
",",
"server",
",",
"cb",
")",
"{",
"// Measure running time",
"var",
"start",
"=",
"new",
"Date",
"(",
")",
".",
"getTime",
"(",
")",
";",
"// Emit the server heartbeat start",
"emitSDAMEvent",
"(",
"self",
",",
"'serverHeartbeatStarted... | Ping the server | [
"Ping",
"the",
"server"
] | bcb87caa89f5841272955fb4b320f75d632856f7 | https://github.com/mongodb-js/mongodb-core/blob/bcb87caa89f5841272955fb4b320f75d632856f7/lib/topologies/replset.js#L390-L478 | train | |
mongodb-js/mongodb-core | lib/topologies/replset.js | function(host, self, options) {
// If this is not the initial scan
// Is this server already being monitoried, then skip monitoring
if (!options.haInterval) {
for (var i = 0; i < self.intervalIds.length; i++) {
if (self.intervalIds[i].__host === host) {
return;
}
}
}
// Get the ha... | javascript | function(host, self, options) {
// If this is not the initial scan
// Is this server already being monitoried, then skip monitoring
if (!options.haInterval) {
for (var i = 0; i < self.intervalIds.length; i++) {
if (self.intervalIds[i].__host === host) {
return;
}
}
}
// Get the ha... | [
"function",
"(",
"host",
",",
"self",
",",
"options",
")",
"{",
"// If this is not the initial scan",
"// Is this server already being monitoried, then skip monitoring",
"if",
"(",
"!",
"options",
".",
"haInterval",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
... | Each server is monitored in parallel in their own timeout loop | [
"Each",
"server",
"is",
"monitored",
"in",
"parallel",
"in",
"their",
"own",
"timeout",
"loop"
] | bcb87caa89f5841272955fb4b320f75d632856f7 | https://github.com/mongodb-js/mongodb-core/blob/bcb87caa89f5841272955fb4b320f75d632856f7/lib/topologies/replset.js#L481-L587 | train | |
mongodb-js/mongodb-core | lib/topologies/replset.js | executeReconnect | function executeReconnect(self) {
return function() {
if (self.state === DESTROYED || self.state === UNREFERENCED) {
return;
}
connectNewServers(self, self.s.replicaSetState.unknownServers, function() {
var monitoringFrequencey = self.s.replicaSetState.hasPrimary()
? _ha... | javascript | function executeReconnect(self) {
return function() {
if (self.state === DESTROYED || self.state === UNREFERENCED) {
return;
}
connectNewServers(self, self.s.replicaSetState.unknownServers, function() {
var monitoringFrequencey = self.s.replicaSetState.hasPrimary()
? _ha... | [
"function",
"executeReconnect",
"(",
"self",
")",
"{",
"return",
"function",
"(",
")",
"{",
"if",
"(",
"self",
".",
"state",
"===",
"DESTROYED",
"||",
"self",
".",
"state",
"===",
"UNREFERENCED",
")",
"{",
"return",
";",
"}",
"connectNewServers",
"(",
"s... | Run the reconnect process | [
"Run",
"the",
"reconnect",
"process"
] | bcb87caa89f5841272955fb4b320f75d632856f7 | https://github.com/mongodb-js/mongodb-core/blob/bcb87caa89f5841272955fb4b320f75d632856f7/lib/topologies/replset.js#L643-L658 | train |
mongodb-js/mongodb-core | lib/topologies/replset.js | emitSDAMEvent | function emitSDAMEvent(self, event, description) {
if (self.listeners(event).length > 0) {
self.emit(event, description);
}
} | javascript | function emitSDAMEvent(self, event, description) {
if (self.listeners(event).length > 0) {
self.emit(event, description);
}
} | [
"function",
"emitSDAMEvent",
"(",
"self",
",",
"event",
",",
"description",
")",
"{",
"if",
"(",
"self",
".",
"listeners",
"(",
"event",
")",
".",
"length",
">",
"0",
")",
"{",
"self",
".",
"emit",
"(",
"event",
",",
"description",
")",
";",
"}",
"... | Emit event if it exists
@method | [
"Emit",
"event",
"if",
"it",
"exists"
] | bcb87caa89f5841272955fb4b320f75d632856f7 | https://github.com/mongodb-js/mongodb-core/blob/bcb87caa89f5841272955fb4b320f75d632856f7/lib/topologies/replset.js#L884-L888 | train |
mongodb-js/mongodb-core | lib/topologies/replset.js | executeWriteOperation | function executeWriteOperation(args, options, callback) {
if (typeof options === 'function') (callback = options), (options = {});
options = options || {};
// TODO: once we drop Node 4, use destructuring either here or in arguments.
const self = args.self;
const op = args.op;
const ns = args.ns;
const op... | javascript | function executeWriteOperation(args, options, callback) {
if (typeof options === 'function') (callback = options), (options = {});
options = options || {};
// TODO: once we drop Node 4, use destructuring either here or in arguments.
const self = args.self;
const op = args.op;
const ns = args.ns;
const op... | [
"function",
"executeWriteOperation",
"(",
"args",
",",
"options",
",",
"callback",
")",
"{",
"if",
"(",
"typeof",
"options",
"===",
"'function'",
")",
"(",
"callback",
"=",
"options",
")",
",",
"(",
"options",
"=",
"{",
"}",
")",
";",
"options",
"=",
"... | Execute write operation | [
"Execute",
"write",
"operation"
] | bcb87caa89f5841272955fb4b320f75d632856f7 | https://github.com/mongodb-js/mongodb-core/blob/bcb87caa89f5841272955fb4b320f75d632856f7/lib/topologies/replset.js#L1123-L1184 | train |
mongodb-js/mongodb-core | lib/auth/scram.js | xor | function xor(a, b) {
if (!Buffer.isBuffer(a)) a = Buffer.from(a);
if (!Buffer.isBuffer(b)) b = Buffer.from(b);
const length = Math.max(a.length, b.length);
const res = [];
for (let i = 0; i < length; i += 1) {
res.push(a[i] ^ b[i]);
}
return Buffer.from(res).toString('base64');
} | javascript | function xor(a, b) {
if (!Buffer.isBuffer(a)) a = Buffer.from(a);
if (!Buffer.isBuffer(b)) b = Buffer.from(b);
const length = Math.max(a.length, b.length);
const res = [];
for (let i = 0; i < length; i += 1) {
res.push(a[i] ^ b[i]);
}
return Buffer.from(res).toString('base64');
} | [
"function",
"xor",
"(",
"a",
",",
"b",
")",
"{",
"if",
"(",
"!",
"Buffer",
".",
"isBuffer",
"(",
"a",
")",
")",
"a",
"=",
"Buffer",
".",
"from",
"(",
"a",
")",
";",
"if",
"(",
"!",
"Buffer",
".",
"isBuffer",
"(",
"b",
")",
")",
"b",
"=",
... | XOR two buffers | [
"XOR",
"two",
"buffers"
] | bcb87caa89f5841272955fb4b320f75d632856f7 | https://github.com/mongodb-js/mongodb-core/blob/bcb87caa89f5841272955fb4b320f75d632856f7/lib/auth/scram.js#L43-L54 | train |
mongodb-js/mongodb-core | lib/error.js | isRetryableError | function isRetryableError(error) {
return (
RETRYABLE_ERROR_CODES.has(error.code) ||
error instanceof MongoNetworkError ||
error.message.match(/not master/) ||
error.message.match(/node is recovering/)
);
} | javascript | function isRetryableError(error) {
return (
RETRYABLE_ERROR_CODES.has(error.code) ||
error instanceof MongoNetworkError ||
error.message.match(/not master/) ||
error.message.match(/node is recovering/)
);
} | [
"function",
"isRetryableError",
"(",
"error",
")",
"{",
"return",
"(",
"RETRYABLE_ERROR_CODES",
".",
"has",
"(",
"error",
".",
"code",
")",
"||",
"error",
"instanceof",
"MongoNetworkError",
"||",
"error",
".",
"message",
".",
"match",
"(",
"/",
"not master",
... | Determines whether an error is something the driver should attempt to retry
@param {MongoError|Error} error | [
"Determines",
"whether",
"an",
"error",
"is",
"something",
"the",
"driver",
"should",
"attempt",
"to",
"retry"
] | bcb87caa89f5841272955fb4b320f75d632856f7 | https://github.com/mongodb-js/mongodb-core/blob/bcb87caa89f5841272955fb4b320f75d632856f7/lib/error.js#L146-L153 | train |
mongodb-js/mongodb-core | lib/sdam/server_description.js | parseServerType | function parseServerType(ismaster) {
if (!ismaster || !ismaster.ok) {
return ServerType.Unknown;
}
if (ismaster.isreplicaset) {
return ServerType.RSGhost;
}
if (ismaster.msg && ismaster.msg === 'isdbgrid') {
return ServerType.Mongos;
}
if (ismaster.setName) {
if (ismaster.hidden) {
... | javascript | function parseServerType(ismaster) {
if (!ismaster || !ismaster.ok) {
return ServerType.Unknown;
}
if (ismaster.isreplicaset) {
return ServerType.RSGhost;
}
if (ismaster.msg && ismaster.msg === 'isdbgrid') {
return ServerType.Mongos;
}
if (ismaster.setName) {
if (ismaster.hidden) {
... | [
"function",
"parseServerType",
"(",
"ismaster",
")",
"{",
"if",
"(",
"!",
"ismaster",
"||",
"!",
"ismaster",
".",
"ok",
")",
"{",
"return",
"ServerType",
".",
"Unknown",
";",
"}",
"if",
"(",
"ismaster",
".",
"isreplicaset",
")",
"{",
"return",
"ServerTyp... | Parses an `ismaster` message and determines the server type
@param {Object} ismaster The `ismaster` message to parse
@return {ServerType} | [
"Parses",
"an",
"ismaster",
"message",
"and",
"determines",
"the",
"server",
"type"
] | bcb87caa89f5841272955fb4b320f75d632856f7 | https://github.com/mongodb-js/mongodb-core/blob/bcb87caa89f5841272955fb4b320f75d632856f7/lib/sdam/server_description.js#L116-L144 | train |
mongodb-js/mongodb-core | lib/sdam/topology.js | destroyServer | function destroyServer(server, topology, callback) {
LOCAL_SERVER_EVENTS.forEach(event => server.removeAllListeners(event));
server.destroy(() => {
topology.emit(
'serverClosed',
new monitoring.ServerClosedEvent(topology.s.id, server.description.address)
);
if (typeof callback === 'functio... | javascript | function destroyServer(server, topology, callback) {
LOCAL_SERVER_EVENTS.forEach(event => server.removeAllListeners(event));
server.destroy(() => {
topology.emit(
'serverClosed',
new monitoring.ServerClosedEvent(topology.s.id, server.description.address)
);
if (typeof callback === 'functio... | [
"function",
"destroyServer",
"(",
"server",
",",
"topology",
",",
"callback",
")",
"{",
"LOCAL_SERVER_EVENTS",
".",
"forEach",
"(",
"event",
"=>",
"server",
".",
"removeAllListeners",
"(",
"event",
")",
")",
";",
"server",
".",
"destroy",
"(",
"(",
")",
"=... | Destroys a server, and removes all event listeners from the instance
@param {Server} server | [
"Destroys",
"a",
"server",
"and",
"removes",
"all",
"event",
"listeners",
"from",
"the",
"instance"
] | bcb87caa89f5841272955fb4b320f75d632856f7 | https://github.com/mongodb-js/mongodb-core/blob/bcb87caa89f5841272955fb4b320f75d632856f7/lib/sdam/topology.js#L652-L663 | train |
mongodb-js/mongodb-core | lib/sdam/topology.js | parseStringSeedlist | function parseStringSeedlist(seedlist) {
return seedlist.split(',').map(seed => ({
host: seed.split(':')[0],
port: seed.split(':')[1] || 27017
}));
} | javascript | function parseStringSeedlist(seedlist) {
return seedlist.split(',').map(seed => ({
host: seed.split(':')[0],
port: seed.split(':')[1] || 27017
}));
} | [
"function",
"parseStringSeedlist",
"(",
"seedlist",
")",
"{",
"return",
"seedlist",
".",
"split",
"(",
"','",
")",
".",
"map",
"(",
"seed",
"=>",
"(",
"{",
"host",
":",
"seed",
".",
"split",
"(",
"':'",
")",
"[",
"0",
"]",
",",
"port",
":",
"seed",... | Parses a basic seedlist in string form
@param {string} seedlist The seedlist to parse | [
"Parses",
"a",
"basic",
"seedlist",
"in",
"string",
"form"
] | bcb87caa89f5841272955fb4b320f75d632856f7 | https://github.com/mongodb-js/mongodb-core/blob/bcb87caa89f5841272955fb4b320f75d632856f7/lib/sdam/topology.js#L670-L675 | train |
mongodb-js/mongodb-core | lib/sdam/topology.js | resetServerState | function resetServerState(server, error, options) {
options = Object.assign({}, { clearPool: false }, options);
function resetState() {
server.emit(
'descriptionReceived',
new ServerDescription(server.description.address, null, { error })
);
}
if (options.clearPool && server.pool) {
se... | javascript | function resetServerState(server, error, options) {
options = Object.assign({}, { clearPool: false }, options);
function resetState() {
server.emit(
'descriptionReceived',
new ServerDescription(server.description.address, null, { error })
);
}
if (options.clearPool && server.pool) {
se... | [
"function",
"resetServerState",
"(",
"server",
",",
"error",
",",
"options",
")",
"{",
"options",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"{",
"clearPool",
":",
"false",
"}",
",",
"options",
")",
";",
"function",
"resetState",
"(",
")",
"{",
... | Resets the internal state of this server to `Unknown` by simulating an empty ismaster
@private
@param {Server} server
@param {MongoError} error The error that caused the state reset
@param {object} [options] Optional settings
@param {boolean} [options.clearPool=false] Pool should be cleared out on state reset | [
"Resets",
"the",
"internal",
"state",
"of",
"this",
"server",
"to",
"Unknown",
"by",
"simulating",
"an",
"empty",
"ismaster"
] | bcb87caa89f5841272955fb4b320f75d632856f7 | https://github.com/mongodb-js/mongodb-core/blob/bcb87caa89f5841272955fb4b320f75d632856f7/lib/sdam/topology.js#L930-L946 | train |
mongodb-js/mongodb-core | lib/topologies/mongos.js | function(seedlist, options) {
options = options || {};
// Get replSet Id
this.id = id++;
// Internal state
this.s = {
options: Object.assign({}, options),
// BSON instance
bson:
options.bson ||
new BSON([
BSON.Binary,
BSON.Code,
BSON.DBRef,
BSON.Decima... | javascript | function(seedlist, options) {
options = options || {};
// Get replSet Id
this.id = id++;
// Internal state
this.s = {
options: Object.assign({}, options),
// BSON instance
bson:
options.bson ||
new BSON([
BSON.Binary,
BSON.Code,
BSON.DBRef,
BSON.Decima... | [
"function",
"(",
"seedlist",
",",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"// Get replSet Id",
"this",
".",
"id",
"=",
"id",
"++",
";",
"// Internal state",
"this",
".",
"s",
"=",
"{",
"options",
":",
"Object",
".",
"assign... | Creates a new Mongos instance
@class
@param {array} seedlist A list of seeds for the replicaset
@param {number} [options.haInterval=5000] The High availability period for replicaset inquiry
@param {Cursor} [options.cursorFactory=Cursor] The cursor factory class used for all query cursors
@param {number} [options.size=5... | [
"Creates",
"a",
"new",
"Mongos",
"instance"
] | bcb87caa89f5841272955fb4b320f75d632856f7 | https://github.com/mongodb-js/mongodb-core/blob/bcb87caa89f5841272955fb4b320f75d632856f7/lib/topologies/mongos.js#L123-L219 | train | |
mongodb-js/mongodb-core | lib/topologies/mongos.js | pingServer | function pingServer(_self, _server, cb) {
// Measure running time
var start = new Date().getTime();
// Emit the server heartbeat start
emitSDAMEvent(self, 'serverHeartbeatStarted', { connectionId: _server.name });
// Execute ismaster
_server.command(
'admin.$cmd',
{... | javascript | function pingServer(_self, _server, cb) {
// Measure running time
var start = new Date().getTime();
// Emit the server heartbeat start
emitSDAMEvent(self, 'serverHeartbeatStarted', { connectionId: _server.name });
// Execute ismaster
_server.command(
'admin.$cmd',
{... | [
"function",
"pingServer",
"(",
"_self",
",",
"_server",
",",
"cb",
")",
"{",
"// Measure running time",
"var",
"start",
"=",
"new",
"Date",
"(",
")",
".",
"getTime",
"(",
")",
";",
"// Emit the server heartbeat start",
"emitSDAMEvent",
"(",
"self",
",",
"'serv... | If the count is zero schedule a new fast | [
"If",
"the",
"count",
"is",
"zero",
"schedule",
"a",
"new",
"fast"
] | bcb87caa89f5841272955fb4b320f75d632856f7 | https://github.com/mongodb-js/mongodb-core/blob/bcb87caa89f5841272955fb4b320f75d632856f7/lib/topologies/mongos.js#L676-L730 | train |
mongodb-js/mongodb-core | lib/topologies/shared.js | resolveClusterTime | function resolveClusterTime(topology, $clusterTime) {
if (topology.clusterTime == null) {
topology.clusterTime = $clusterTime;
} else {
if ($clusterTime.clusterTime.greaterThan(topology.clusterTime.clusterTime)) {
topology.clusterTime = $clusterTime;
}
}
} | javascript | function resolveClusterTime(topology, $clusterTime) {
if (topology.clusterTime == null) {
topology.clusterTime = $clusterTime;
} else {
if ($clusterTime.clusterTime.greaterThan(topology.clusterTime.clusterTime)) {
topology.clusterTime = $clusterTime;
}
}
} | [
"function",
"resolveClusterTime",
"(",
"topology",
",",
"$clusterTime",
")",
"{",
"if",
"(",
"topology",
".",
"clusterTime",
"==",
"null",
")",
"{",
"topology",
".",
"clusterTime",
"=",
"$clusterTime",
";",
"}",
"else",
"{",
"if",
"(",
"$clusterTime",
".",
... | Shared function to determine clusterTime for a given topology
@param {*} topology
@param {*} clusterTime | [
"Shared",
"function",
"to",
"determine",
"clusterTime",
"for",
"a",
"given",
"topology"
] | bcb87caa89f5841272955fb4b320f75d632856f7 | https://github.com/mongodb-js/mongodb-core/blob/bcb87caa89f5841272955fb4b320f75d632856f7/lib/topologies/shared.js#L366-L374 | train |
mongodb-js/mongodb-core | lib/topologies/shared.js | function(topology) {
const maxWireVersion = topology.lastIsMaster().maxWireVersion;
if (maxWireVersion < RETRYABLE_WIRE_VERSION) {
return false;
}
if (!topology.logicalSessionTimeoutMinutes) {
return false;
}
if (topologyType(topology) === TopologyType.Single) {
return false;
}
return tru... | javascript | function(topology) {
const maxWireVersion = topology.lastIsMaster().maxWireVersion;
if (maxWireVersion < RETRYABLE_WIRE_VERSION) {
return false;
}
if (!topology.logicalSessionTimeoutMinutes) {
return false;
}
if (topologyType(topology) === TopologyType.Single) {
return false;
}
return tru... | [
"function",
"(",
"topology",
")",
"{",
"const",
"maxWireVersion",
"=",
"topology",
".",
"lastIsMaster",
"(",
")",
".",
"maxWireVersion",
";",
"if",
"(",
"maxWireVersion",
"<",
"RETRYABLE_WIRE_VERSION",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
... | Determines whether the provided topology supports retryable writes
@param {Mongos|Replset} topology | [
"Determines",
"whether",
"the",
"provided",
"topology",
"supports",
"retryable",
"writes"
] | bcb87caa89f5841272955fb4b320f75d632856f7 | https://github.com/mongodb-js/mongodb-core/blob/bcb87caa89f5841272955fb4b320f75d632856f7/lib/topologies/shared.js#L423-L438 | train | |
mongodb-js/mongodb-core | lib/topologies/replset_state.js | function(readPreference, servers) {
if (readPreference.tags == null) return servers;
var filteredServers = [];
var tagsArray = Array.isArray(readPreference.tags) ? readPreference.tags : [readPreference.tags];
// Iterate over the tags
for (var j = 0; j < tagsArray.length; j++) {
var tags = tagsArray[j];
... | javascript | function(readPreference, servers) {
if (readPreference.tags == null) return servers;
var filteredServers = [];
var tagsArray = Array.isArray(readPreference.tags) ? readPreference.tags : [readPreference.tags];
// Iterate over the tags
for (var j = 0; j < tagsArray.length; j++) {
var tags = tagsArray[j];
... | [
"function",
"(",
"readPreference",
",",
"servers",
")",
"{",
"if",
"(",
"readPreference",
".",
"tags",
"==",
"null",
")",
"return",
"servers",
";",
"var",
"filteredServers",
"=",
"[",
"]",
";",
"var",
"tagsArray",
"=",
"Array",
".",
"isArray",
"(",
"read... | Filter serves by tags | [
"Filter",
"serves",
"by",
"tags"
] | bcb87caa89f5841272955fb4b320f75d632856f7 | https://github.com/mongodb-js/mongodb-core/blob/bcb87caa89f5841272955fb4b320f75d632856f7/lib/topologies/replset_state.js#L837-L868 | train | |
mongodb-js/mongodb-core | lib/topologies/server.js | function(options) {
options = options || {};
// Add event listener
EventEmitter.call(this);
// Server instance id
this.id = id++;
// Internal state
this.s = {
// Options
options: options,
// Logger
logger: Logger('Server', options),
// Factory overrides
Cursor: options.cursorFac... | javascript | function(options) {
options = options || {};
// Add event listener
EventEmitter.call(this);
// Server instance id
this.id = id++;
// Internal state
this.s = {
// Options
options: options,
// Logger
logger: Logger('Server', options),
// Factory overrides
Cursor: options.cursorFac... | [
"function",
"(",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"// Add event listener",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"// Server instance id",
"this",
".",
"id",
"=",
"id",
"++",
";",
"// Internal state",
"this",
... | Creates a new Server instance
@class
@param {boolean} [options.reconnect=true] Server will attempt to reconnect on loss of connection
@param {number} [options.reconnectTries=30] Server attempt to reconnect #times
@param {number} [options.reconnectInterval=1000] Server will wait # milliseconds between retries
@param {nu... | [
"Creates",
"a",
"new",
"Server",
"instance"
] | bcb87caa89f5841272955fb4b320f75d632856f7 | https://github.com/mongodb-js/mongodb-core/blob/bcb87caa89f5841272955fb4b320f75d632856f7/lib/topologies/server.js#L107-L186 | train | |
mongodb-js/mongodb-core | lib/wireprotocol/shared.js | function(message) {
return {
length: message.readInt32LE(0),
requestId: message.readInt32LE(4),
responseTo: message.readInt32LE(8),
opCode: message.readInt32LE(12)
};
} | javascript | function(message) {
return {
length: message.readInt32LE(0),
requestId: message.readInt32LE(4),
responseTo: message.readInt32LE(8),
opCode: message.readInt32LE(12)
};
} | [
"function",
"(",
"message",
")",
"{",
"return",
"{",
"length",
":",
"message",
".",
"readInt32LE",
"(",
"0",
")",
",",
"requestId",
":",
"message",
".",
"readInt32LE",
"(",
"4",
")",
",",
"responseTo",
":",
"message",
".",
"readInt32LE",
"(",
"8",
")",... | Parses the header of a wire protocol message | [
"Parses",
"the",
"header",
"of",
"a",
"wire",
"protocol",
"message"
] | bcb87caa89f5841272955fb4b320f75d632856f7 | https://github.com/mongodb-js/mongodb-core/blob/bcb87caa89f5841272955fb4b320f75d632856f7/lib/wireprotocol/shared.js#L45-L52 | train | |
DoctorMcKay/node-steam-user | components/connection_protocols/tcp.js | TCPConnection | function TCPConnection(user) {
this.user = user;
// Pick a CM randomly
if (!user._cmList || !user._cmList.tcp_servers) {
throw new Error("Nothing to connect to: " + (user._cmList ? "no TCP server list" : "no CM list"));
}
let tcpCm = user._cmList.tcp_servers[Math.floor(Math.random() * user._cmList.tcp_servers.... | javascript | function TCPConnection(user) {
this.user = user;
// Pick a CM randomly
if (!user._cmList || !user._cmList.tcp_servers) {
throw new Error("Nothing to connect to: " + (user._cmList ? "no TCP server list" : "no CM list"));
}
let tcpCm = user._cmList.tcp_servers[Math.floor(Math.random() * user._cmList.tcp_servers.... | [
"function",
"TCPConnection",
"(",
"user",
")",
"{",
"this",
".",
"user",
"=",
"user",
";",
"// Pick a CM randomly",
"if",
"(",
"!",
"user",
".",
"_cmList",
"||",
"!",
"user",
".",
"_cmList",
".",
"tcp_servers",
")",
"{",
"throw",
"new",
"Error",
"(",
"... | Create a new TCP connection, and connect
@param {SteamUser} user
@constructor | [
"Create",
"a",
"new",
"TCP",
"connection",
"and",
"connect"
] | a58d91287cde03873a26cd12fee64fbd6ff3edd7 | https://github.com/DoctorMcKay/node-steam-user/blob/a58d91287cde03873a26cd12fee64fbd6ff3edd7/components/connection_protocols/tcp.js#L19-L90 | train |
DoctorMcKay/node-steam-user | components/chat.js | toChatID | function toChatID(steamID) {
steamID = Helpers.steamID(steamID);
if (steamID.type == SteamID.Type.CLAN) {
steamID.type = SteamID.Type.CHAT;
steamID.instance |= SteamID.ChatInstanceFlags.Clan;
}
return steamID;
} | javascript | function toChatID(steamID) {
steamID = Helpers.steamID(steamID);
if (steamID.type == SteamID.Type.CLAN) {
steamID.type = SteamID.Type.CHAT;
steamID.instance |= SteamID.ChatInstanceFlags.Clan;
}
return steamID;
} | [
"function",
"toChatID",
"(",
"steamID",
")",
"{",
"steamID",
"=",
"Helpers",
".",
"steamID",
"(",
"steamID",
")",
";",
"if",
"(",
"steamID",
".",
"type",
"==",
"SteamID",
".",
"Type",
".",
"CLAN",
")",
"{",
"steamID",
".",
"type",
"=",
"SteamID",
"."... | Private functions
If steamID is a clan ID, converts to the appropriate chat ID. Otherwise, returns it untouched.
@param {SteamID} steamID
@returns SteamID | [
"Private",
"functions",
"If",
"steamID",
"is",
"a",
"clan",
"ID",
"converts",
"to",
"the",
"appropriate",
"chat",
"ID",
".",
"Otherwise",
"returns",
"it",
"untouched",
"."
] | a58d91287cde03873a26cd12fee64fbd6ff3edd7 | https://github.com/DoctorMcKay/node-steam-user/blob/a58d91287cde03873a26cd12fee64fbd6ff3edd7/components/chat.js#L512-L521 | train |
DoctorMcKay/node-steam-user | components/chat.js | fromChatID | function fromChatID(steamID) {
steamID = Helpers.steamID(steamID);
if (steamID.isGroupChat()) {
steamID.type = SteamID.Type.CLAN;
steamID.instance &= ~SteamID.ChatInstanceFlags.Clan;
}
return steamID;
} | javascript | function fromChatID(steamID) {
steamID = Helpers.steamID(steamID);
if (steamID.isGroupChat()) {
steamID.type = SteamID.Type.CLAN;
steamID.instance &= ~SteamID.ChatInstanceFlags.Clan;
}
return steamID;
} | [
"function",
"fromChatID",
"(",
"steamID",
")",
"{",
"steamID",
"=",
"Helpers",
".",
"steamID",
"(",
"steamID",
")",
";",
"if",
"(",
"steamID",
".",
"isGroupChat",
"(",
")",
")",
"{",
"steamID",
".",
"type",
"=",
"SteamID",
".",
"Type",
".",
"CLAN",
"... | If steamID is a clan chat ID, converts to the appropriate clan ID. Otherwise, returns it untouched.
@param {SteamID} steamID
@returns SteamID | [
"If",
"steamID",
"is",
"a",
"clan",
"chat",
"ID",
"converts",
"to",
"the",
"appropriate",
"clan",
"ID",
".",
"Otherwise",
"returns",
"it",
"untouched",
"."
] | a58d91287cde03873a26cd12fee64fbd6ff3edd7 | https://github.com/DoctorMcKay/node-steam-user/blob/a58d91287cde03873a26cd12fee64fbd6ff3edd7/components/chat.js#L528-L537 | train |
DoctorMcKay/node-steam-user | components/chat.js | decomposeChatFlags | function decomposeChatFlags(chat, chatFlags) {
chat.private = !!(chatFlags & SteamUser.EChatFlags.Locked);
chat.invisibleToFriends = !!(chatFlags & SteamUser.EChatFlags.InvisibleToFriends);
chat.officersOnlyChat = !!(chatFlags & SteamUser.EChatFlags.Moderated);
chat.unjoinable = !!(chatFlags & SteamUser.EChatFlags.... | javascript | function decomposeChatFlags(chat, chatFlags) {
chat.private = !!(chatFlags & SteamUser.EChatFlags.Locked);
chat.invisibleToFriends = !!(chatFlags & SteamUser.EChatFlags.InvisibleToFriends);
chat.officersOnlyChat = !!(chatFlags & SteamUser.EChatFlags.Moderated);
chat.unjoinable = !!(chatFlags & SteamUser.EChatFlags.... | [
"function",
"decomposeChatFlags",
"(",
"chat",
",",
"chatFlags",
")",
"{",
"chat",
".",
"private",
"=",
"!",
"!",
"(",
"chatFlags",
"&",
"SteamUser",
".",
"EChatFlags",
".",
"Locked",
")",
";",
"chat",
".",
"invisibleToFriends",
"=",
"!",
"!",
"(",
"chat... | Converts chat flags into properties on a chat room object
@param {Object} chat
@param {number} chatFlags | [
"Converts",
"chat",
"flags",
"into",
"properties",
"on",
"a",
"chat",
"room",
"object"
] | a58d91287cde03873a26cd12fee64fbd6ff3edd7 | https://github.com/DoctorMcKay/node-steam-user/blob/a58d91287cde03873a26cd12fee64fbd6ff3edd7/components/chat.js#L544-L549 | train |
DoctorMcKay/node-steam-user | components/chatroom.js | processChatRoomSummaryPair | function processChatRoomSummaryPair(summaryPair, preProcessed) {
if (!preProcessed) {
summaryPair = preProcessObject(summaryPair);
}
summaryPair.group_state = processUserChatGroupState(summaryPair.user_chat_group_state, true);
summaryPair.group_summary = processChatGroupSummary(summaryPair.group_summary, true);
... | javascript | function processChatRoomSummaryPair(summaryPair, preProcessed) {
if (!preProcessed) {
summaryPair = preProcessObject(summaryPair);
}
summaryPair.group_state = processUserChatGroupState(summaryPair.user_chat_group_state, true);
summaryPair.group_summary = processChatGroupSummary(summaryPair.group_summary, true);
... | [
"function",
"processChatRoomSummaryPair",
"(",
"summaryPair",
",",
"preProcessed",
")",
"{",
"if",
"(",
"!",
"preProcessed",
")",
"{",
"summaryPair",
"=",
"preProcessObject",
"(",
"summaryPair",
")",
";",
"}",
"summaryPair",
".",
"group_state",
"=",
"processUserCh... | Process a chat room summary pair.
@param {object} summaryPair
@param {boolean} [preProcessed=false]
@returns {object} | [
"Process",
"a",
"chat",
"room",
"summary",
"pair",
"."
] | a58d91287cde03873a26cd12fee64fbd6ff3edd7 | https://github.com/DoctorMcKay/node-steam-user/blob/a58d91287cde03873a26cd12fee64fbd6ff3edd7/components/chatroom.js#L678-L687 | train |
DoctorMcKay/node-steam-user | components/chatroom.js | processChatGroupSummary | function processChatGroupSummary(groupSummary, preProcessed) {
if (!preProcessed) {
groupSummary = preProcessObject(groupSummary);
}
if (groupSummary.top_members) {
groupSummary.top_members = groupSummary.top_members.map(accountid => SteamID.fromIndividualAccountID(accountid));
}
return groupSummary;
} | javascript | function processChatGroupSummary(groupSummary, preProcessed) {
if (!preProcessed) {
groupSummary = preProcessObject(groupSummary);
}
if (groupSummary.top_members) {
groupSummary.top_members = groupSummary.top_members.map(accountid => SteamID.fromIndividualAccountID(accountid));
}
return groupSummary;
} | [
"function",
"processChatGroupSummary",
"(",
"groupSummary",
",",
"preProcessed",
")",
"{",
"if",
"(",
"!",
"preProcessed",
")",
"{",
"groupSummary",
"=",
"preProcessObject",
"(",
"groupSummary",
")",
";",
"}",
"if",
"(",
"groupSummary",
".",
"top_members",
")",
... | Process a chat group summary.
@param {object} groupSummary
@param {boolean} [preProcessed=false]
@returns {object} | [
"Process",
"a",
"chat",
"group",
"summary",
"."
] | a58d91287cde03873a26cd12fee64fbd6ff3edd7 | https://github.com/DoctorMcKay/node-steam-user/blob/a58d91287cde03873a26cd12fee64fbd6ff3edd7/components/chatroom.js#L695-L705 | train |
DoctorMcKay/node-steam-user | components/chatroom.js | preProcessObject | function preProcessObject(obj) {
for (let key in obj) {
if (!obj.hasOwnProperty(key)) {
continue;
}
let val = obj[key];
if (key.match(/^steamid_/) && typeof val === 'string' && val != '0') {
obj[key] = new SteamID(val.toString());
} else if (key == 'timestamp' || key.match(/^time_/) || key.match(/_tim... | javascript | function preProcessObject(obj) {
for (let key in obj) {
if (!obj.hasOwnProperty(key)) {
continue;
}
let val = obj[key];
if (key.match(/^steamid_/) && typeof val === 'string' && val != '0') {
obj[key] = new SteamID(val.toString());
} else if (key == 'timestamp' || key.match(/^time_/) || key.match(/_tim... | [
"function",
"preProcessObject",
"(",
"obj",
")",
"{",
"for",
"(",
"let",
"key",
"in",
"obj",
")",
"{",
"if",
"(",
"!",
"obj",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"continue",
";",
"}",
"let",
"val",
"=",
"obj",
"[",
"key",
"]",
";",
... | Pre-process a generic chat object.
@param {object} obj
@returns {object} | [
"Pre",
"-",
"process",
"a",
"generic",
"chat",
"object",
"."
] | a58d91287cde03873a26cd12fee64fbd6ff3edd7 | https://github.com/DoctorMcKay/node-steam-user/blob/a58d91287cde03873a26cd12fee64fbd6ff3edd7/components/chatroom.js#L763-L810 | train |
choojs/bankai | lib/graph-document.js | extractFonts | function extractFonts (state) {
var list = String(state.list.buffer).split(',')
var res = list.filter(function (font) {
var extname = path.extname(font)
return extname === '.woff' ||
extname === '.woff2' ||
extname === '.eot' ||
extname === '.ttf'
})
return res
} | javascript | function extractFonts (state) {
var list = String(state.list.buffer).split(',')
var res = list.filter(function (font) {
var extname = path.extname(font)
return extname === '.woff' ||
extname === '.woff2' ||
extname === '.eot' ||
extname === '.ttf'
})
return res
} | [
"function",
"extractFonts",
"(",
"state",
")",
"{",
"var",
"list",
"=",
"String",
"(",
"state",
".",
"list",
".",
"buffer",
")",
".",
"split",
"(",
"','",
")",
"var",
"res",
"=",
"list",
".",
"filter",
"(",
"function",
"(",
"font",
")",
"{",
"var",... | Specific to the document node's layout | [
"Specific",
"to",
"the",
"document",
"node",
"s",
"layout"
] | 29cb370f3901316f66e9ee582d3a62305051b5be | https://github.com/choojs/bankai/blob/29cb370f3901316f66e9ee582d3a62305051b5be/lib/graph-document.js#L261-L274 | train |
choojs/bankai | lib/track-dir.js | init | function init (dirname, done) {
dirname = path.join(basedir, dirname)
fs.access(dirname, function (err) {
if (err) return done()
readdir(dirname, function (err, _list) {
if (err) return done(err)
list = list.concat(_list)
done()
})
})
} | javascript | function init (dirname, done) {
dirname = path.join(basedir, dirname)
fs.access(dirname, function (err) {
if (err) return done()
readdir(dirname, function (err, _list) {
if (err) return done(err)
list = list.concat(_list)
done()
})
})
} | [
"function",
"init",
"(",
"dirname",
",",
"done",
")",
"{",
"dirname",
"=",
"path",
".",
"join",
"(",
"basedir",
",",
"dirname",
")",
"fs",
".",
"access",
"(",
"dirname",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"return",
"done"... | Run only once at the start of the pass. | [
"Run",
"only",
"once",
"at",
"the",
"start",
"of",
"the",
"pass",
"."
] | 29cb370f3901316f66e9ee582d3a62305051b5be | https://github.com/choojs/bankai/blob/29cb370f3901316f66e9ee582d3a62305051b5be/lib/track-dir.js#L74-L84 | train |
kentcdodds/match-sorter | src/index.js | matchSorter | function matchSorter(items, value, options = {}) {
// not performing any search/sort if value(search term) is empty
if (!value) return items
const {keys, threshold = rankings.MATCHES} = options
const matchedItems = items.reduce(reduceItemsToRanked, [])
return matchedItems.sort(sortRankedItems).map(({item}) =... | javascript | function matchSorter(items, value, options = {}) {
// not performing any search/sort if value(search term) is empty
if (!value) return items
const {keys, threshold = rankings.MATCHES} = options
const matchedItems = items.reduce(reduceItemsToRanked, [])
return matchedItems.sort(sortRankedItems).map(({item}) =... | [
"function",
"matchSorter",
"(",
"items",
",",
"value",
",",
"options",
"=",
"{",
"}",
")",
"{",
"// not performing any search/sort if value(search term) is empty",
"if",
"(",
"!",
"value",
")",
"return",
"items",
"const",
"{",
"keys",
",",
"threshold",
"=",
"ran... | Takes an array of items and a value and returns a new array with the items that match the given value
@param {Array} items - the items to sort
@param {String} value - the value to use for ranking
@param {Object} options - Some options to configure the sorter
@return {Array} - the new sorted array | [
"Takes",
"an",
"array",
"of",
"items",
"and",
"a",
"value",
"and",
"returns",
"a",
"new",
"array",
"with",
"the",
"items",
"that",
"match",
"the",
"given",
"value"
] | fa454c568c6b5f117a85855806e4754daf5961a0 | https://github.com/kentcdodds/match-sorter/blob/fa454c568c6b5f117a85855806e4754daf5961a0/src/index.js#L40-L60 | train |
kentcdodds/match-sorter | src/index.js | getHighestRanking | function getHighestRanking(item, keys, value, options) {
if (!keys) {
return {
rank: getMatchRanking(item, value, options),
keyIndex: -1,
keyThreshold: options.threshold,
}
}
const valuesToRank = getAllValuesToRank(item, keys)
return valuesToRank.reduce(
({rank, keyIndex, keyThresh... | javascript | function getHighestRanking(item, keys, value, options) {
if (!keys) {
return {
rank: getMatchRanking(item, value, options),
keyIndex: -1,
keyThreshold: options.threshold,
}
}
const valuesToRank = getAllValuesToRank(item, keys)
return valuesToRank.reduce(
({rank, keyIndex, keyThresh... | [
"function",
"getHighestRanking",
"(",
"item",
",",
"keys",
",",
"value",
",",
"options",
")",
"{",
"if",
"(",
"!",
"keys",
")",
"{",
"return",
"{",
"rank",
":",
"getMatchRanking",
"(",
"item",
",",
"value",
",",
"options",
")",
",",
"keyIndex",
":",
... | Gets the highest ranking for value for the given item based on its values for the given keys
@param {*} item - the item to rank
@param {Array} keys - the keys to get values from the item for the ranking
@param {String} value - the value to rank against
@param {Object} options - options to control the ranking
@return {{... | [
"Gets",
"the",
"highest",
"ranking",
"for",
"value",
"for",
"the",
"given",
"item",
"based",
"on",
"its",
"values",
"for",
"the",
"given",
"keys"
] | fa454c568c6b5f117a85855806e4754daf5961a0 | https://github.com/kentcdodds/match-sorter/blob/fa454c568c6b5f117a85855806e4754daf5961a0/src/index.js#L70-L97 | train |
kentcdodds/match-sorter | src/index.js | getMatchRanking | function getMatchRanking(testString, stringToRank, options) {
/* eslint complexity:[2, 12] */
testString = prepareValueForComparison(testString, options)
stringToRank = prepareValueForComparison(stringToRank, options)
// too long
if (stringToRank.length > testString.length) {
return rankings.NO_MATCH
}... | javascript | function getMatchRanking(testString, stringToRank, options) {
/* eslint complexity:[2, 12] */
testString = prepareValueForComparison(testString, options)
stringToRank = prepareValueForComparison(stringToRank, options)
// too long
if (stringToRank.length > testString.length) {
return rankings.NO_MATCH
}... | [
"function",
"getMatchRanking",
"(",
"testString",
",",
"stringToRank",
",",
"options",
")",
"{",
"/* eslint complexity:[2, 12] */",
"testString",
"=",
"prepareValueForComparison",
"(",
"testString",
",",
"options",
")",
"stringToRank",
"=",
"prepareValueForComparison",
"(... | Gives a rankings score based on how well the two strings match.
@param {String} testString - the string to test against
@param {String} stringToRank - the string to rank
@param {Object} options - options for the match (like keepDiacritics for comparison)
@returns {Number} the ranking for how well stringToRank matches t... | [
"Gives",
"a",
"rankings",
"score",
"based",
"on",
"how",
"well",
"the",
"two",
"strings",
"match",
"."
] | fa454c568c6b5f117a85855806e4754daf5961a0 | https://github.com/kentcdodds/match-sorter/blob/fa454c568c6b5f117a85855806e4754daf5961a0/src/index.js#L106-L172 | train |
kentcdodds/match-sorter | src/index.js | getCaseRanking | function getCaseRanking(testString) {
const containsUpperCase = testString.toLowerCase() !== testString
const containsDash = testString.indexOf('-') >= 0
const containsUnderscore = testString.indexOf('_') >= 0
if (!containsUpperCase && !containsUnderscore && containsDash) {
return caseRankings.KEBAB
}
... | javascript | function getCaseRanking(testString) {
const containsUpperCase = testString.toLowerCase() !== testString
const containsDash = testString.indexOf('-') >= 0
const containsUnderscore = testString.indexOf('_') >= 0
if (!containsUpperCase && !containsUnderscore && containsDash) {
return caseRankings.KEBAB
}
... | [
"function",
"getCaseRanking",
"(",
"testString",
")",
"{",
"const",
"containsUpperCase",
"=",
"testString",
".",
"toLowerCase",
"(",
")",
"!==",
"testString",
"const",
"containsDash",
"=",
"testString",
".",
"indexOf",
"(",
"'-'",
")",
">=",
"0",
"const",
"con... | Returns a score base on the case of the testString
@param {String} testString - the string to test against
@returns {Number} the number of the ranking,
based on the case between 0 and 1 for how the testString matches the case | [
"Returns",
"a",
"score",
"base",
"on",
"the",
"case",
"of",
"the",
"testString"
] | fa454c568c6b5f117a85855806e4754daf5961a0 | https://github.com/kentcdodds/match-sorter/blob/fa454c568c6b5f117a85855806e4754daf5961a0/src/index.js#L198-L221 | train |
kentcdodds/match-sorter | src/index.js | isCaseAcronym | function isCaseAcronym(testString, stringToRank, caseRank) {
let splitValue = null
switch (caseRank) {
case caseRankings.SNAKE:
splitValue = '_'
break
case caseRankings.KEBAB:
splitValue = '-'
break
case caseRankings.PASCAL:
case caseRankings.CAMEL:
splitValue = /(?=[A-... | javascript | function isCaseAcronym(testString, stringToRank, caseRank) {
let splitValue = null
switch (caseRank) {
case caseRankings.SNAKE:
splitValue = '_'
break
case caseRankings.KEBAB:
splitValue = '-'
break
case caseRankings.PASCAL:
case caseRankings.CAMEL:
splitValue = /(?=[A-... | [
"function",
"isCaseAcronym",
"(",
"testString",
",",
"stringToRank",
",",
"caseRank",
")",
"{",
"let",
"splitValue",
"=",
"null",
"switch",
"(",
"caseRank",
")",
"{",
"case",
"caseRankings",
".",
"SNAKE",
":",
"splitValue",
"=",
"'_'",
"break",
"case",
"case... | Check if stringToRank is an acronym for a partial case
@example
// returns true
isCaseAcronym('super_duper_file', 'sdf', caseRankings.SNAKE)
@param {String} testString - the string to test against
@param {String} stringToRank - the acronym to test
@param {Number} caseRank - the ranking of the case
@returns {Boolean} wh... | [
"Check",
"if",
"stringToRank",
"is",
"an",
"acronym",
"for",
"a",
"partial",
"case"
] | fa454c568c6b5f117a85855806e4754daf5961a0 | https://github.com/kentcdodds/match-sorter/blob/fa454c568c6b5f117a85855806e4754daf5961a0/src/index.js#L265-L290 | train |
kentcdodds/match-sorter | src/index.js | getClosenessRanking | function getClosenessRanking(testString, stringToRank) {
let charNumber = 0
function findMatchingCharacter(matchChar, string, index) {
for (let j = index; j < string.length; j++) {
const stringChar = string[j]
if (stringChar === matchChar) {
return j + 1
}
}
return -1
}
fun... | javascript | function getClosenessRanking(testString, stringToRank) {
let charNumber = 0
function findMatchingCharacter(matchChar, string, index) {
for (let j = index; j < string.length; j++) {
const stringChar = string[j]
if (stringChar === matchChar) {
return j + 1
}
}
return -1
}
fun... | [
"function",
"getClosenessRanking",
"(",
"testString",
",",
"stringToRank",
")",
"{",
"let",
"charNumber",
"=",
"0",
"function",
"findMatchingCharacter",
"(",
"matchChar",
",",
"string",
",",
"index",
")",
"{",
"for",
"(",
"let",
"j",
"=",
"index",
";",
"j",
... | Returns a score based on how spread apart the
characters from the stringToRank are within the testString.
A number close to rankings.MATCHES represents a loose match. A number close
to rankings.MATCHES + 1 represents a loose match.
@param {String} testString - the string to test against
@param {String} stringToRank - t... | [
"Returns",
"a",
"score",
"based",
"on",
"how",
"spread",
"apart",
"the",
"characters",
"from",
"the",
"stringToRank",
"are",
"within",
"the",
"testString",
".",
"A",
"number",
"close",
"to",
"rankings",
".",
"MATCHES",
"represents",
"a",
"loose",
"match",
".... | fa454c568c6b5f117a85855806e4754daf5961a0 | https://github.com/kentcdodds/match-sorter/blob/fa454c568c6b5f117a85855806e4754daf5961a0/src/index.js#L302-L334 | train |
kentcdodds/match-sorter | src/index.js | sortRankedItems | function sortRankedItems(a, b) {
const aFirst = -1
const bFirst = 1
const {rank: aRank, index: aIndex, keyIndex: aKeyIndex} = a
const {rank: bRank, index: bIndex, keyIndex: bKeyIndex} = b
const same = aRank === bRank
if (same) {
if (aKeyIndex === bKeyIndex) {
return aIndex < bIndex ? aFirst : bFir... | javascript | function sortRankedItems(a, b) {
const aFirst = -1
const bFirst = 1
const {rank: aRank, index: aIndex, keyIndex: aKeyIndex} = a
const {rank: bRank, index: bIndex, keyIndex: bKeyIndex} = b
const same = aRank === bRank
if (same) {
if (aKeyIndex === bKeyIndex) {
return aIndex < bIndex ? aFirst : bFir... | [
"function",
"sortRankedItems",
"(",
"a",
",",
"b",
")",
"{",
"const",
"aFirst",
"=",
"-",
"1",
"const",
"bFirst",
"=",
"1",
"const",
"{",
"rank",
":",
"aRank",
",",
"index",
":",
"aIndex",
",",
"keyIndex",
":",
"aKeyIndex",
"}",
"=",
"a",
"const",
... | Sorts items that have a rank, index, and keyIndex
@param {Object} a - the first item to sort
@param {Object} b - the second item to sort
@return {Number} -1 if a should come first, 1 if b should come first
Note: will never return 0 | [
"Sorts",
"items",
"that",
"have",
"a",
"rank",
"index",
"and",
"keyIndex"
] | fa454c568c6b5f117a85855806e4754daf5961a0 | https://github.com/kentcdodds/match-sorter/blob/fa454c568c6b5f117a85855806e4754daf5961a0/src/index.js#L343-L358 | train |
kentcdodds/match-sorter | src/index.js | getItemValues | function getItemValues(item, key) {
if (typeof key === 'object') {
key = key.key
}
let value
if (typeof key === 'function') {
value = key(item)
// eslint-disable-next-line no-negated-condition
} else if (key.indexOf('.') !== -1) {
// handle nested keys
value = key
.split('.')
.... | javascript | function getItemValues(item, key) {
if (typeof key === 'object') {
key = key.key
}
let value
if (typeof key === 'function') {
value = key(item)
// eslint-disable-next-line no-negated-condition
} else if (key.indexOf('.') !== -1) {
// handle nested keys
value = key
.split('.')
.... | [
"function",
"getItemValues",
"(",
"item",
",",
"key",
")",
"{",
"if",
"(",
"typeof",
"key",
"===",
"'object'",
")",
"{",
"key",
"=",
"key",
".",
"key",
"}",
"let",
"value",
"if",
"(",
"typeof",
"key",
"===",
"'function'",
")",
"{",
"value",
"=",
"k... | Gets value for key in item at arbitrarily nested keypath
@param {Object} item - the item
@param {Object|Function} key - the potentially nested keypath or property callback
@return {Array} - an array containing the value(s) at the nested keypath | [
"Gets",
"value",
"for",
"key",
"in",
"item",
"at",
"arbitrarily",
"nested",
"keypath"
] | fa454c568c6b5f117a85855806e4754daf5961a0 | https://github.com/kentcdodds/match-sorter/blob/fa454c568c6b5f117a85855806e4754daf5961a0/src/index.js#L380-L402 | train |
kentcdodds/match-sorter | src/index.js | getAllValuesToRank | function getAllValuesToRank(item, keys) {
return keys.reduce((allVals, key) => {
const values = getItemValues(item, key)
if (values) {
values.forEach(itemValue => {
allVals.push({
itemValue,
attributes: getKeyAttributes(key),
})
})
}
return allVals
}, ... | javascript | function getAllValuesToRank(item, keys) {
return keys.reduce((allVals, key) => {
const values = getItemValues(item, key)
if (values) {
values.forEach(itemValue => {
allVals.push({
itemValue,
attributes: getKeyAttributes(key),
})
})
}
return allVals
}, ... | [
"function",
"getAllValuesToRank",
"(",
"item",
",",
"keys",
")",
"{",
"return",
"keys",
".",
"reduce",
"(",
"(",
"allVals",
",",
"key",
")",
"=>",
"{",
"const",
"values",
"=",
"getItemValues",
"(",
"item",
",",
"key",
")",
"if",
"(",
"values",
")",
"... | Gets all the values for the given keys in the given item and returns an array of those values
@param {Object} item - the item from which the values will be retrieved
@param {Array} keys - the keys to use to retrieve the values
@return {Array} objects with {itemValue, attributes} | [
"Gets",
"all",
"the",
"values",
"for",
"the",
"given",
"keys",
"in",
"the",
"given",
"item",
"and",
"returns",
"an",
"array",
"of",
"those",
"values"
] | fa454c568c6b5f117a85855806e4754daf5961a0 | https://github.com/kentcdodds/match-sorter/blob/fa454c568c6b5f117a85855806e4754daf5961a0/src/index.js#L410-L423 | train |
kentcdodds/match-sorter | src/index.js | getKeyAttributes | function getKeyAttributes(key) {
if (typeof key === 'string') {
key = {key}
}
return {
maxRanking: Infinity,
minRanking: -Infinity,
...key,
}
} | javascript | function getKeyAttributes(key) {
if (typeof key === 'string') {
key = {key}
}
return {
maxRanking: Infinity,
minRanking: -Infinity,
...key,
}
} | [
"function",
"getKeyAttributes",
"(",
"key",
")",
"{",
"if",
"(",
"typeof",
"key",
"===",
"'string'",
")",
"{",
"key",
"=",
"{",
"key",
"}",
"}",
"return",
"{",
"maxRanking",
":",
"Infinity",
",",
"minRanking",
":",
"-",
"Infinity",
",",
"...",
"key",
... | Gets all the attributes for the given key
@param {Object|String} key - the key from which the attributes will be retrieved
@return {Object} object containing the key's attributes | [
"Gets",
"all",
"the",
"attributes",
"for",
"the",
"given",
"key"
] | fa454c568c6b5f117a85855806e4754daf5961a0 | https://github.com/kentcdodds/match-sorter/blob/fa454c568c6b5f117a85855806e4754daf5961a0/src/index.js#L430-L439 | train |
mapbox/concaveman | index.js | sqSegBoxDist | function sqSegBoxDist(a, b, bbox) {
if (inside(a, bbox) || inside(b, bbox)) return 0;
var d1 = sqSegSegDist(a[0], a[1], b[0], b[1], bbox.minX, bbox.minY, bbox.maxX, bbox.minY);
if (d1 === 0) return 0;
var d2 = sqSegSegDist(a[0], a[1], b[0], b[1], bbox.minX, bbox.minY, bbox.minX, bbox.maxY);
if (d2 =... | javascript | function sqSegBoxDist(a, b, bbox) {
if (inside(a, bbox) || inside(b, bbox)) return 0;
var d1 = sqSegSegDist(a[0], a[1], b[0], b[1], bbox.minX, bbox.minY, bbox.maxX, bbox.minY);
if (d1 === 0) return 0;
var d2 = sqSegSegDist(a[0], a[1], b[0], b[1], bbox.minX, bbox.minY, bbox.minX, bbox.maxY);
if (d2 =... | [
"function",
"sqSegBoxDist",
"(",
"a",
",",
"b",
",",
"bbox",
")",
"{",
"if",
"(",
"inside",
"(",
"a",
",",
"bbox",
")",
"||",
"inside",
"(",
"b",
",",
"bbox",
")",
")",
"return",
"0",
";",
"var",
"d1",
"=",
"sqSegSegDist",
"(",
"a",
"[",
"0",
... | square distance from a segment bounding box to the given one | [
"square",
"distance",
"from",
"a",
"segment",
"bounding",
"box",
"to",
"the",
"given",
"one"
] | 30b83eca5801fe87a5b72f9a1e1818c38ff8fb50 | https://github.com/mapbox/concaveman/blob/30b83eca5801fe87a5b72f9a1e1818c38ff8fb50/index.js#L127-L138 | train |
mapbox/concaveman | index.js | updateBBox | function updateBBox(node) {
var p1 = node.p;
var p2 = node.next.p;
node.minX = Math.min(p1[0], p2[0]);
node.minY = Math.min(p1[1], p2[1]);
node.maxX = Math.max(p1[0], p2[0]);
node.maxY = Math.max(p1[1], p2[1]);
return node;
} | javascript | function updateBBox(node) {
var p1 = node.p;
var p2 = node.next.p;
node.minX = Math.min(p1[0], p2[0]);
node.minY = Math.min(p1[1], p2[1]);
node.maxX = Math.max(p1[0], p2[0]);
node.maxY = Math.max(p1[1], p2[1]);
return node;
} | [
"function",
"updateBBox",
"(",
"node",
")",
"{",
"var",
"p1",
"=",
"node",
".",
"p",
";",
"var",
"p2",
"=",
"node",
".",
"next",
".",
"p",
";",
"node",
".",
"minX",
"=",
"Math",
".",
"min",
"(",
"p1",
"[",
"0",
"]",
",",
"p2",
"[",
"0",
"]"... | update the bounding box of a node's edge | [
"update",
"the",
"bounding",
"box",
"of",
"a",
"node",
"s",
"edge"
] | 30b83eca5801fe87a5b72f9a1e1818c38ff8fb50 | https://github.com/mapbox/concaveman/blob/30b83eca5801fe87a5b72f9a1e1818c38ff8fb50/index.js#L169-L177 | train |
mapbox/concaveman | index.js | fastConvexHull | function fastConvexHull(points) {
var left = points[0];
var top = points[0];
var right = points[0];
var bottom = points[0];
// find the leftmost, rightmost, topmost and bottommost points
for (var i = 0; i < points.length; i++) {
var p = points[i];
if (p[0] < left[0]) left = p;
... | javascript | function fastConvexHull(points) {
var left = points[0];
var top = points[0];
var right = points[0];
var bottom = points[0];
// find the leftmost, rightmost, topmost and bottommost points
for (var i = 0; i < points.length; i++) {
var p = points[i];
if (p[0] < left[0]) left = p;
... | [
"function",
"fastConvexHull",
"(",
"points",
")",
"{",
"var",
"left",
"=",
"points",
"[",
"0",
"]",
";",
"var",
"top",
"=",
"points",
"[",
"0",
"]",
";",
"var",
"right",
"=",
"points",
"[",
"0",
"]",
";",
"var",
"bottom",
"=",
"points",
"[",
"0",... | speed up convex hull by filtering out points inside quadrilateral formed by 4 extreme points | [
"speed",
"up",
"convex",
"hull",
"by",
"filtering",
"out",
"points",
"inside",
"quadrilateral",
"formed",
"by",
"4",
"extreme",
"points"
] | 30b83eca5801fe87a5b72f9a1e1818c38ff8fb50 | https://github.com/mapbox/concaveman/blob/30b83eca5801fe87a5b72f9a1e1818c38ff8fb50/index.js#L180-L209 | train |
mapbox/concaveman | index.js | insertNode | function insertNode(p, prev) {
var node = {
p: p,
prev: null,
next: null,
minX: 0,
minY: 0,
maxX: 0,
maxY: 0
};
if (!prev) {
node.prev = node;
node.next = node;
} else {
node.next = prev.next;
node.prev = prev;
... | javascript | function insertNode(p, prev) {
var node = {
p: p,
prev: null,
next: null,
minX: 0,
minY: 0,
maxX: 0,
maxY: 0
};
if (!prev) {
node.prev = node;
node.next = node;
} else {
node.next = prev.next;
node.prev = prev;
... | [
"function",
"insertNode",
"(",
"p",
",",
"prev",
")",
"{",
"var",
"node",
"=",
"{",
"p",
":",
"p",
",",
"prev",
":",
"null",
",",
"next",
":",
"null",
",",
"minX",
":",
"0",
",",
"minY",
":",
"0",
",",
"maxX",
":",
"0",
",",
"maxY",
":",
"0... | create a new node in a doubly linked list | [
"create",
"a",
"new",
"node",
"in",
"a",
"doubly",
"linked",
"list"
] | 30b83eca5801fe87a5b72f9a1e1818c38ff8fb50 | https://github.com/mapbox/concaveman/blob/30b83eca5801fe87a5b72f9a1e1818c38ff8fb50/index.js#L212-L234 | train |
mapbox/concaveman | index.js | getSqDist | function getSqDist(p1, p2) {
var dx = p1[0] - p2[0],
dy = p1[1] - p2[1];
return dx * dx + dy * dy;
} | javascript | function getSqDist(p1, p2) {
var dx = p1[0] - p2[0],
dy = p1[1] - p2[1];
return dx * dx + dy * dy;
} | [
"function",
"getSqDist",
"(",
"p1",
",",
"p2",
")",
"{",
"var",
"dx",
"=",
"p1",
"[",
"0",
"]",
"-",
"p2",
"[",
"0",
"]",
",",
"dy",
"=",
"p1",
"[",
"1",
"]",
"-",
"p2",
"[",
"1",
"]",
";",
"return",
"dx",
"*",
"dx",
"+",
"dy",
"*",
"dy... | square distance between 2 points | [
"square",
"distance",
"between",
"2",
"points"
] | 30b83eca5801fe87a5b72f9a1e1818c38ff8fb50 | https://github.com/mapbox/concaveman/blob/30b83eca5801fe87a5b72f9a1e1818c38ff8fb50/index.js#L237-L243 | train |
adrai/node-eventstore | lib/snapshot.js | Snapshot | function Snapshot (id, obj) {
if (!id) {
var errIdMsg = 'id not injected!';
debug(errIdMsg);
throw new Error(errIdMsg);
}
if (!obj) {
var errObjMsg = 'object not injected!';
debug(errObjMsg);
throw new Error(errObjMsg);
}
if (!obj.aggregateId) {
var errAggIdMsg = 'object.aggregat... | javascript | function Snapshot (id, obj) {
if (!id) {
var errIdMsg = 'id not injected!';
debug(errIdMsg);
throw new Error(errIdMsg);
}
if (!obj) {
var errObjMsg = 'object not injected!';
debug(errObjMsg);
throw new Error(errObjMsg);
}
if (!obj.aggregateId) {
var errAggIdMsg = 'object.aggregat... | [
"function",
"Snapshot",
"(",
"id",
",",
"obj",
")",
"{",
"if",
"(",
"!",
"id",
")",
"{",
"var",
"errIdMsg",
"=",
"'id not injected!'",
";",
"debug",
"(",
"errIdMsg",
")",
";",
"throw",
"new",
"Error",
"(",
"errIdMsg",
")",
";",
"}",
"if",
"(",
"!",... | Snapshot constructor
The snapshot object will be persisted to the store.
@param {String} id the id of the snapshot
@param {Object} obj the snapshot object infos
@constructor | [
"Snapshot",
"constructor",
"The",
"snapshot",
"object",
"will",
"be",
"persisted",
"to",
"the",
"store",
"."
] | 5ba58aa68d79b2ff81dd390b2464dab62f5c4c40 | https://github.com/adrai/node-eventstore/blob/5ba58aa68d79b2ff81dd390b2464dab62f5c4c40/lib/snapshot.js#L10-L44 | train |
adrai/node-eventstore | lib/eventStream.js | EventStream | function EventStream (eventstore, query, events) {
if (!eventstore) {
var errESMsg = 'eventstore not injected!';
debug(errESMsg);
throw new Error(errESMsg);
}
if (typeof eventstore.commit !== 'function') {
var errESfnMsg = 'eventstore.commit not injected!';
debug(errESfnMsg);
throw new Er... | javascript | function EventStream (eventstore, query, events) {
if (!eventstore) {
var errESMsg = 'eventstore not injected!';
debug(errESMsg);
throw new Error(errESMsg);
}
if (typeof eventstore.commit !== 'function') {
var errESfnMsg = 'eventstore.commit not injected!';
debug(errESfnMsg);
throw new Er... | [
"function",
"EventStream",
"(",
"eventstore",
",",
"query",
",",
"events",
")",
"{",
"if",
"(",
"!",
"eventstore",
")",
"{",
"var",
"errESMsg",
"=",
"'eventstore not injected!'",
";",
"debug",
"(",
"errESMsg",
")",
";",
"throw",
"new",
"Error",
"(",
"errES... | EventStream constructor
The eventstream is one of the main objects to interagate with the eventstore.
@param {Object} eventstore the eventstore that should be injected
@param {Object} query the query object
@param {Array} events the events (from store)
@constructor | [
"EventStream",
"constructor",
"The",
"eventstream",
"is",
"one",
"of",
"the",
"main",
"objects",
"to",
"interagate",
"with",
"the",
"eventstore",
"."
] | 5ba58aa68d79b2ff81dd390b2464dab62f5c4c40 | https://github.com/adrai/node-eventstore/blob/5ba58aa68d79b2ff81dd390b2464dab62f5c4c40/lib/eventStream.js#L13-L68 | train |
adrai/node-eventstore | lib/eventStream.js | function() {
for (var i = 0, len = this.events.length; i < len; i++) {
if (this.events[i].streamRevision > this.lastRevision) {
this.lastRevision = this.events[i].streamRevision;
}
}
return this.lastRevision;
} | javascript | function() {
for (var i = 0, len = this.events.length; i < len; i++) {
if (this.events[i].streamRevision > this.lastRevision) {
this.lastRevision = this.events[i].streamRevision;
}
}
return this.lastRevision;
} | [
"function",
"(",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"this",
".",
"events",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"if",
"(",
"this",
".",
"events",
"[",
"i",
"]",
".",
"streamRevision",
">",
... | This helper function calculates and returns the current stream revision.
@returns {Number} lastRevision | [
"This",
"helper",
"function",
"calculates",
"and",
"returns",
"the",
"current",
"stream",
"revision",
"."
] | 5ba58aa68d79b2ff81dd390b2464dab62f5c4c40 | https://github.com/adrai/node-eventstore/blob/5ba58aa68d79b2ff81dd390b2464dab62f5c4c40/lib/eventStream.js#L76-L84 | train | |
adrai/node-eventstore | lib/eventStream.js | function(events) {
if (!_.isArray(events)) {
var errEvtsArrMsg = 'events should be an array!';
debug(errEvtsArrMsg);
throw new Error(errEvtsArrMsg);
}
var self = this;
_.each(events, function(evt) {
self.addEvent(evt);
});
} | javascript | function(events) {
if (!_.isArray(events)) {
var errEvtsArrMsg = 'events should be an array!';
debug(errEvtsArrMsg);
throw new Error(errEvtsArrMsg);
}
var self = this;
_.each(events, function(evt) {
self.addEvent(evt);
});
} | [
"function",
"(",
"events",
")",
"{",
"if",
"(",
"!",
"_",
".",
"isArray",
"(",
"events",
")",
")",
"{",
"var",
"errEvtsArrMsg",
"=",
"'events should be an array!'",
";",
"debug",
"(",
"errEvtsArrMsg",
")",
";",
"throw",
"new",
"Error",
"(",
"errEvtsArrMsg"... | adds an array of events to the uncommittedEvents array
@param {Array} events | [
"adds",
"an",
"array",
"of",
"events",
"to",
"the",
"uncommittedEvents",
"array"
] | 5ba58aa68d79b2ff81dd390b2464dab62f5c4c40 | https://github.com/adrai/node-eventstore/blob/5ba58aa68d79b2ff81dd390b2464dab62f5c4c40/lib/eventStream.js#L98-L108 | train | |
adrai/node-eventstore | lib/eventDispatcher.js | trigger | function trigger (dispatcher) {
var queue = dispatcher.undispatchedEventsQueue || []
var event;
// if the last loop is still in progress leave this loop
if (dispatcher.isRunning) return;
dispatcher.isRunning = true;
(function next (e) {
// dipatch one event in queue and call the _next_ callback, whi... | javascript | function trigger (dispatcher) {
var queue = dispatcher.undispatchedEventsQueue || []
var event;
// if the last loop is still in progress leave this loop
if (dispatcher.isRunning) return;
dispatcher.isRunning = true;
(function next (e) {
// dipatch one event in queue and call the _next_ callback, whi... | [
"function",
"trigger",
"(",
"dispatcher",
")",
"{",
"var",
"queue",
"=",
"dispatcher",
".",
"undispatchedEventsQueue",
"||",
"[",
"]",
"var",
"event",
";",
"// if the last loop is still in progress leave this loop",
"if",
"(",
"dispatcher",
".",
"isRunning",
")",
"r... | Triggers to publish all events in undispatchedEventsQueue. | [
"Triggers",
"to",
"publish",
"all",
"events",
"in",
"undispatchedEventsQueue",
"."
] | 5ba58aa68d79b2ff81dd390b2464dab62f5c4c40 | https://github.com/adrai/node-eventstore/blob/5ba58aa68d79b2ff81dd390b2464dab62f5c4c40/lib/eventDispatcher.js#L19-L63 | train |
adrai/node-eventstore | lib/eventDispatcher.js | process | function process (event, nxt) {
// Publish it now...
debug('publish event...');
dispatcher.publisher(event.payload, function(err) {
if (err) {
return debug(err);
}
// ...and set the published event to dispatched.
debug('set event to dispatched...');
d... | javascript | function process (event, nxt) {
// Publish it now...
debug('publish event...');
dispatcher.publisher(event.payload, function(err) {
if (err) {
return debug(err);
}
// ...and set the published event to dispatched.
debug('set event to dispatched...');
d... | [
"function",
"process",
"(",
"event",
",",
"nxt",
")",
"{",
"// Publish it now...",
"debug",
"(",
"'publish event...'",
")",
";",
"dispatcher",
".",
"publisher",
"(",
"event",
".",
"payload",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"... | dipatch one event in queue and call the _next_ callback, which will call _process_ for the next undispatched event in queue. | [
"dipatch",
"one",
"event",
"in",
"queue",
"and",
"call",
"the",
"_next_",
"callback",
"which",
"will",
"call",
"_process_",
"for",
"the",
"next",
"undispatched",
"event",
"in",
"queue",
"."
] | 5ba58aa68d79b2ff81dd390b2464dab62f5c4c40 | https://github.com/adrai/node-eventstore/blob/5ba58aa68d79b2ff81dd390b2464dab62f5c4c40/lib/eventDispatcher.js#L32-L52 | train |
adrai/node-eventstore | lib/eventDispatcher.js | function(events) {
var self = this;
events.forEach(function(event) {
self.undispatchedEventsQueue.push(event);
});
trigger(this);
} | javascript | function(events) {
var self = this;
events.forEach(function(event) {
self.undispatchedEventsQueue.push(event);
});
trigger(this);
} | [
"function",
"(",
"events",
")",
"{",
"var",
"self",
"=",
"this",
";",
"events",
".",
"forEach",
"(",
"function",
"(",
"event",
")",
"{",
"self",
".",
"undispatchedEventsQueue",
".",
"push",
"(",
"event",
")",
";",
"}",
")",
";",
"trigger",
"(",
"this... | Queues the passed in events for dispatching.
@param events | [
"Queues",
"the",
"passed",
"in",
"events",
"for",
"dispatching",
"."
] | 5ba58aa68d79b2ff81dd390b2464dab62f5c4c40 | https://github.com/adrai/node-eventstore/blob/5ba58aa68d79b2ff81dd390b2464dab62f5c4c40/lib/eventDispatcher.js#L71-L77 | train | |
adrai/node-eventstore | lib/eventDispatcher.js | function(callback) {
if (typeof this.publisher !== 'function') {
var pubErrMsg = 'publisher not injected!';
debug(pubErrMsg);
if (callback) callback(new Error(pubErrMsg));
return;
}
if (!this.store || typeof this.store.getUndispatchedEvents !== 'function'
|| typ... | javascript | function(callback) {
if (typeof this.publisher !== 'function') {
var pubErrMsg = 'publisher not injected!';
debug(pubErrMsg);
if (callback) callback(new Error(pubErrMsg));
return;
}
if (!this.store || typeof this.store.getUndispatchedEvents !== 'function'
|| typ... | [
"function",
"(",
"callback",
")",
"{",
"if",
"(",
"typeof",
"this",
".",
"publisher",
"!==",
"'function'",
")",
"{",
"var",
"pubErrMsg",
"=",
"'publisher not injected!'",
";",
"debug",
"(",
"pubErrMsg",
")",
";",
"if",
"(",
"callback",
")",
"callback",
"("... | Starts the instance to publish all undispatched events.
@param callback the function that will be called when this action has finished | [
"Starts",
"the",
"instance",
"to",
"publish",
"all",
"undispatched",
"events",
"."
] | 5ba58aa68d79b2ff81dd390b2464dab62f5c4c40 | https://github.com/adrai/node-eventstore/blob/5ba58aa68d79b2ff81dd390b2464dab62f5c4c40/lib/eventDispatcher.js#L83-L131 | train | |
adrai/node-eventstore | lib/eventstore.js | function (fn) {
if (fn.length === 1) {
fn = _.wrap(fn, function(func, evt, callback) {
func(evt);
callback(null);
});
}
this.publisher = fn;
return this;
} | javascript | function (fn) {
if (fn.length === 1) {
fn = _.wrap(fn, function(func, evt, callback) {
func(evt);
callback(null);
});
}
this.publisher = fn;
return this;
} | [
"function",
"(",
"fn",
")",
"{",
"if",
"(",
"fn",
".",
"length",
"===",
"1",
")",
"{",
"fn",
"=",
"_",
".",
"wrap",
"(",
"fn",
",",
"function",
"(",
"func",
",",
"evt",
",",
"callback",
")",
"{",
"func",
"(",
"evt",
")",
";",
"callback",
"(",... | Inject function for event publishing.
@param {Function} fn the function to be injected
@returns {Eventstore} to be able to chain... | [
"Inject",
"function",
"for",
"event",
"publishing",
"."
] | 5ba58aa68d79b2ff81dd390b2464dab62f5c4c40 | https://github.com/adrai/node-eventstore/blob/5ba58aa68d79b2ff81dd390b2464dab62f5c4c40/lib/eventstore.js#L35-L46 | train |
Subsets and Splits
SQL Console for semeru/code-text-javascript
Retrieves 20,000 non-null code samples labeled as JavaScript, providing a basic overview of the dataset.