id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
list | docstring
stringlengths 4
11.8k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
43,300 | insin/redux-action-utils | lib/index.js | optionsActionCreator | function optionsActionCreator(type) {
var props = Array.isArray(arguments[1]) ? arguments[1] : slice.call(arguments, 1)
return function(options) {
var copyProps = props.length === 0 ? Object.keys(options) : props
return copyProps.reduce(function(action, prop) {
return (action[prop] = options[prop], action)
}, {type: type})
}
} | javascript | function optionsActionCreator(type) {
var props = Array.isArray(arguments[1]) ? arguments[1] : slice.call(arguments, 1)
return function(options) {
var copyProps = props.length === 0 ? Object.keys(options) : props
return copyProps.reduce(function(action, prop) {
return (action[prop] = options[prop], action)
}, {type: type})
}
} | [
"function",
"optionsActionCreator",
"(",
"type",
")",
"{",
"var",
"props",
"=",
"Array",
".",
"isArray",
"(",
"arguments",
"[",
"1",
"]",
")",
"?",
"arguments",
"[",
"1",
"]",
":",
"slice",
".",
"call",
"(",
"arguments",
",",
"1",
")",
"return",
"function",
"(",
"options",
")",
"{",
"var",
"copyProps",
"=",
"props",
".",
"length",
"===",
"0",
"?",
"Object",
".",
"keys",
"(",
"options",
")",
":",
"props",
"return",
"copyProps",
".",
"reduce",
"(",
"function",
"(",
"action",
",",
"prop",
")",
"{",
"return",
"(",
"action",
"[",
"prop",
"]",
"=",
"options",
"[",
"prop",
"]",
",",
"action",
")",
"}",
",",
"{",
"type",
":",
"type",
"}",
")",
"}",
"}"
]
| Creates an action creator for the given action type which also takes an
options object argument, which will either have all of its properties
or only specified properties added to the action object.
Property names can be specified as an Array of strings or as any number of
addiitonal String arguments. | [
"Creates",
"an",
"action",
"creator",
"for",
"the",
"given",
"action",
"type",
"which",
"also",
"takes",
"an",
"options",
"object",
"argument",
"which",
"will",
"either",
"have",
"all",
"of",
"its",
"properties",
"or",
"only",
"specified",
"properties",
"added",
"to",
"the",
"action",
"object",
"."
]
| 10a0464815751355fb9d43281cf5e41a9a65d1ae | https://github.com/insin/redux-action-utils/blob/10a0464815751355fb9d43281cf5e41a9a65d1ae/lib/index.js#L35-L43 |
43,301 | alexindigo/fbbot | incoming/type_cast.js | typeCast | function typeCast(payload, callback)
{
var type = find(types, function(t){ return (t in payload); });
if (type)
{
payload.type = normalize(type);
}
callback(null, payload);
} | javascript | function typeCast(payload, callback)
{
var type = find(types, function(t){ return (t in payload); });
if (type)
{
payload.type = normalize(type);
}
callback(null, payload);
} | [
"function",
"typeCast",
"(",
"payload",
",",
"callback",
")",
"{",
"var",
"type",
"=",
"find",
"(",
"types",
",",
"function",
"(",
"t",
")",
"{",
"return",
"(",
"t",
"in",
"payload",
")",
";",
"}",
")",
";",
"if",
"(",
"type",
")",
"{",
"payload",
".",
"type",
"=",
"normalize",
"(",
"type",
")",
";",
"}",
"callback",
"(",
"null",
",",
"payload",
")",
";",
"}"
]
| Casts message type based on the present fields from the list
@this Fbbot#
@param {object} payload - message object
@param {function} callback - invoked after type casting is done | [
"Casts",
"message",
"type",
"based",
"on",
"the",
"present",
"fields",
"from",
"the",
"list"
]
| b78a0418ebdfd106723348d94b4378ac67f7d4bf | https://github.com/alexindigo/fbbot/blob/b78a0418ebdfd106723348d94b4378ac67f7d4bf/incoming/type_cast.js#L32-L42 |
43,302 | alexindigo/fbbot | outgoing/button_postback.js | buttonPostback | function buttonPostback(payload, callback)
{
if (typeof payload.payload != 'string')
{
payload.payload = JSON.stringify(payload.payload);
}
callback(null, payload);
} | javascript | function buttonPostback(payload, callback)
{
if (typeof payload.payload != 'string')
{
payload.payload = JSON.stringify(payload.payload);
}
callback(null, payload);
} | [
"function",
"buttonPostback",
"(",
"payload",
",",
"callback",
")",
"{",
"if",
"(",
"typeof",
"payload",
".",
"payload",
"!=",
"'string'",
")",
"{",
"payload",
".",
"payload",
"=",
"JSON",
".",
"stringify",
"(",
"payload",
".",
"payload",
")",
";",
"}",
"callback",
"(",
"null",
",",
"payload",
")",
";",
"}"
]
| Stringifies provided button.postback payload
@this Fbbot#
@param {object} payload - button.postback object
@param {function} callback - invoked after stringification is done | [
"Stringifies",
"provided",
"button",
".",
"postback",
"payload"
]
| b78a0418ebdfd106723348d94b4378ac67f7d4bf | https://github.com/alexindigo/fbbot/blob/b78a0418ebdfd106723348d94b4378ac67f7d4bf/outgoing/button_postback.js#L10-L18 |
43,303 | sean-perkins/ngx-select | examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js | function () {
return {
centered: this.centered,
speedFactor: this.speedFactor * (this._globalOptions.baseSpeedFactor || 1),
radius: this.radius,
color: this.color
};
} | javascript | function () {
return {
centered: this.centered,
speedFactor: this.speedFactor * (this._globalOptions.baseSpeedFactor || 1),
radius: this.radius,
color: this.color
};
} | [
"function",
"(",
")",
"{",
"return",
"{",
"centered",
":",
"this",
".",
"centered",
",",
"speedFactor",
":",
"this",
".",
"speedFactor",
"*",
"(",
"this",
".",
"_globalOptions",
".",
"baseSpeedFactor",
"||",
"1",
")",
",",
"radius",
":",
"this",
".",
"radius",
",",
"color",
":",
"this",
".",
"color",
"}",
";",
"}"
]
| Ripple configuration from the directive's input values.
@return {?} | [
"Ripple",
"configuration",
"from",
"the",
"directive",
"s",
"input",
"values",
"."
]
| 27eb48f8e49cdaeb4e79937e58e7b16e43e7e390 | https://github.com/sean-perkins/ngx-select/blob/27eb48f8e49cdaeb4e79937e58e7b16e43e7e390/examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js#L7506-L7513 |
|
43,304 | sean-perkins/ngx-select | examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js | isNativeFormElement | function isNativeFormElement(element) {
var /** @type {?} */ nodeName = element.nodeName.toLowerCase();
return nodeName === 'input' ||
nodeName === 'select' ||
nodeName === 'button' ||
nodeName === 'textarea';
} | javascript | function isNativeFormElement(element) {
var /** @type {?} */ nodeName = element.nodeName.toLowerCase();
return nodeName === 'input' ||
nodeName === 'select' ||
nodeName === 'button' ||
nodeName === 'textarea';
} | [
"function",
"isNativeFormElement",
"(",
"element",
")",
"{",
"var",
"/** @type {?} */",
"nodeName",
"=",
"element",
".",
"nodeName",
".",
"toLowerCase",
"(",
")",
";",
"return",
"nodeName",
"===",
"'input'",
"||",
"nodeName",
"===",
"'select'",
"||",
"nodeName",
"===",
"'button'",
"||",
"nodeName",
"===",
"'textarea'",
";",
"}"
]
| Gets whether an element's
@param {?} element
@return {?} | [
"Gets",
"whether",
"an",
"element",
"s"
]
| 27eb48f8e49cdaeb4e79937e58e7b16e43e7e390 | https://github.com/sean-perkins/ngx-select/blob/27eb48f8e49cdaeb4e79937e58e7b16e43e7e390/examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js#L10082-L10088 |
43,305 | sean-perkins/ngx-select | examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js | hasValidTabIndex | function hasValidTabIndex(element) {
if (!element.hasAttribute('tabindex') || element.tabIndex === undefined) {
return false;
}
var /** @type {?} */ tabIndex = element.getAttribute('tabindex');
// IE11 parses tabindex="" as the value "-32768"
if (tabIndex == '-32768') {
return false;
}
return !!(tabIndex && !isNaN(parseInt(tabIndex, 10)));
} | javascript | function hasValidTabIndex(element) {
if (!element.hasAttribute('tabindex') || element.tabIndex === undefined) {
return false;
}
var /** @type {?} */ tabIndex = element.getAttribute('tabindex');
// IE11 parses tabindex="" as the value "-32768"
if (tabIndex == '-32768') {
return false;
}
return !!(tabIndex && !isNaN(parseInt(tabIndex, 10)));
} | [
"function",
"hasValidTabIndex",
"(",
"element",
")",
"{",
"if",
"(",
"!",
"element",
".",
"hasAttribute",
"(",
"'tabindex'",
")",
"||",
"element",
".",
"tabIndex",
"===",
"undefined",
")",
"{",
"return",
"false",
";",
"}",
"var",
"/** @type {?} */",
"tabIndex",
"=",
"element",
".",
"getAttribute",
"(",
"'tabindex'",
")",
";",
"// IE11 parses tabindex=\"\" as the value \"-32768\"",
"if",
"(",
"tabIndex",
"==",
"'-32768'",
")",
"{",
"return",
"false",
";",
"}",
"return",
"!",
"!",
"(",
"tabIndex",
"&&",
"!",
"isNaN",
"(",
"parseInt",
"(",
"tabIndex",
",",
"10",
")",
")",
")",
";",
"}"
]
| Gets whether an element has a valid tabindex.
@param {?} element
@return {?} | [
"Gets",
"whether",
"an",
"element",
"has",
"a",
"valid",
"tabindex",
"."
]
| 27eb48f8e49cdaeb4e79937e58e7b16e43e7e390 | https://github.com/sean-perkins/ngx-select/blob/27eb48f8e49cdaeb4e79937e58e7b16e43e7e390/examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js#L10126-L10136 |
43,306 | sean-perkins/ngx-select | examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js | getTabIndexValue | function getTabIndexValue(element) {
if (!hasValidTabIndex(element)) {
return null;
}
// See browser issue in Gecko https://bugzilla.mozilla.org/show_bug.cgi?id=1128054
var /** @type {?} */ tabIndex = parseInt(element.getAttribute('tabindex'), 10);
return isNaN(tabIndex) ? -1 : tabIndex;
} | javascript | function getTabIndexValue(element) {
if (!hasValidTabIndex(element)) {
return null;
}
// See browser issue in Gecko https://bugzilla.mozilla.org/show_bug.cgi?id=1128054
var /** @type {?} */ tabIndex = parseInt(element.getAttribute('tabindex'), 10);
return isNaN(tabIndex) ? -1 : tabIndex;
} | [
"function",
"getTabIndexValue",
"(",
"element",
")",
"{",
"if",
"(",
"!",
"hasValidTabIndex",
"(",
"element",
")",
")",
"{",
"return",
"null",
";",
"}",
"// See browser issue in Gecko https://bugzilla.mozilla.org/show_bug.cgi?id=1128054",
"var",
"/** @type {?} */",
"tabIndex",
"=",
"parseInt",
"(",
"element",
".",
"getAttribute",
"(",
"'tabindex'",
")",
",",
"10",
")",
";",
"return",
"isNaN",
"(",
"tabIndex",
")",
"?",
"-",
"1",
":",
"tabIndex",
";",
"}"
]
| Returns the parsed tabindex from the element attributes instead of returning the
evaluated tabindex from the browsers defaults.
@param {?} element
@return {?} | [
"Returns",
"the",
"parsed",
"tabindex",
"from",
"the",
"element",
"attributes",
"instead",
"of",
"returning",
"the",
"evaluated",
"tabindex",
"from",
"the",
"browsers",
"defaults",
"."
]
| 27eb48f8e49cdaeb4e79937e58e7b16e43e7e390 | https://github.com/sean-perkins/ngx-select/blob/27eb48f8e49cdaeb4e79937e58e7b16e43e7e390/examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js#L10143-L10150 |
43,307 | sean-perkins/ngx-select | examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js | isPotentiallyTabbableIOS | function isPotentiallyTabbableIOS(element) {
var /** @type {?} */ nodeName = element.nodeName.toLowerCase();
var /** @type {?} */ inputType = nodeName === 'input' && ((element)).type;
return inputType === 'text'
|| inputType === 'password'
|| nodeName === 'select'
|| nodeName === 'textarea';
} | javascript | function isPotentiallyTabbableIOS(element) {
var /** @type {?} */ nodeName = element.nodeName.toLowerCase();
var /** @type {?} */ inputType = nodeName === 'input' && ((element)).type;
return inputType === 'text'
|| inputType === 'password'
|| nodeName === 'select'
|| nodeName === 'textarea';
} | [
"function",
"isPotentiallyTabbableIOS",
"(",
"element",
")",
"{",
"var",
"/** @type {?} */",
"nodeName",
"=",
"element",
".",
"nodeName",
".",
"toLowerCase",
"(",
")",
";",
"var",
"/** @type {?} */",
"inputType",
"=",
"nodeName",
"===",
"'input'",
"&&",
"(",
"(",
"element",
")",
")",
".",
"type",
";",
"return",
"inputType",
"===",
"'text'",
"||",
"inputType",
"===",
"'password'",
"||",
"nodeName",
"===",
"'select'",
"||",
"nodeName",
"===",
"'textarea'",
";",
"}"
]
| Checks whether the specified element is potentially tabbable on iOS
@param {?} element
@return {?} | [
"Checks",
"whether",
"the",
"specified",
"element",
"is",
"potentially",
"tabbable",
"on",
"iOS"
]
| 27eb48f8e49cdaeb4e79937e58e7b16e43e7e390 | https://github.com/sean-perkins/ngx-select/blob/27eb48f8e49cdaeb4e79937e58e7b16e43e7e390/examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js#L10156-L10163 |
43,308 | sean-perkins/ngx-select | examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js | applyCssTransform | function applyCssTransform(element, transformValue) {
// It's important to trim the result, because the browser will ignore the set operation
// if the string contains only whitespace.
var /** @type {?} */ value = transformValue.trim();
element.style.transform = value;
element.style.webkitTransform = value;
} | javascript | function applyCssTransform(element, transformValue) {
// It's important to trim the result, because the browser will ignore the set operation
// if the string contains only whitespace.
var /** @type {?} */ value = transformValue.trim();
element.style.transform = value;
element.style.webkitTransform = value;
} | [
"function",
"applyCssTransform",
"(",
"element",
",",
"transformValue",
")",
"{",
"// It's important to trim the result, because the browser will ignore the set operation",
"// if the string contains only whitespace.",
"var",
"/** @type {?} */",
"value",
"=",
"transformValue",
".",
"trim",
"(",
")",
";",
"element",
".",
"style",
".",
"transform",
"=",
"value",
";",
"element",
".",
"style",
".",
"webkitTransform",
"=",
"value",
";",
"}"
]
| Applies a CSS transform to an element, including browser-prefixed properties.
@param {?} element
@param {?} transformValue
@return {?} | [
"Applies",
"a",
"CSS",
"transform",
"to",
"an",
"element",
"including",
"browser",
"-",
"prefixed",
"properties",
"."
]
| 27eb48f8e49cdaeb4e79937e58e7b16e43e7e390 | https://github.com/sean-perkins/ngx-select/blob/27eb48f8e49cdaeb4e79937e58e7b16e43e7e390/examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js#L11384-L11390 |
43,309 | sean-perkins/ngx-select | examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js | function () {
if (this._multiple) {
var /** @type {?} */ selectedOptions = this._selectionModel.selected.map(function (option) { return option.viewValue; });
if (this._isRtl()) {
selectedOptions.reverse();
}
// TODO(crisbeto): delimiter should be configurable for proper localization.
return selectedOptions.join(', ');
}
return this._selectionModel.selected[0].viewValue;
} | javascript | function () {
if (this._multiple) {
var /** @type {?} */ selectedOptions = this._selectionModel.selected.map(function (option) { return option.viewValue; });
if (this._isRtl()) {
selectedOptions.reverse();
}
// TODO(crisbeto): delimiter should be configurable for proper localization.
return selectedOptions.join(', ');
}
return this._selectionModel.selected[0].viewValue;
} | [
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"_multiple",
")",
"{",
"var",
"/** @type {?} */",
"selectedOptions",
"=",
"this",
".",
"_selectionModel",
".",
"selected",
".",
"map",
"(",
"function",
"(",
"option",
")",
"{",
"return",
"option",
".",
"viewValue",
";",
"}",
")",
";",
"if",
"(",
"this",
".",
"_isRtl",
"(",
")",
")",
"{",
"selectedOptions",
".",
"reverse",
"(",
")",
";",
"}",
"// TODO(crisbeto): delimiter should be configurable for proper localization.",
"return",
"selectedOptions",
".",
"join",
"(",
"', '",
")",
";",
"}",
"return",
"this",
".",
"_selectionModel",
".",
"selected",
"[",
"0",
"]",
".",
"viewValue",
";",
"}"
]
| The value displayed in the trigger.
@return {?} | [
"The",
"value",
"displayed",
"in",
"the",
"trigger",
"."
]
| 27eb48f8e49cdaeb4e79937e58e7b16e43e7e390 | https://github.com/sean-perkins/ngx-select/blob/27eb48f8e49cdaeb4e79937e58e7b16e43e7e390/examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js#L14285-L14295 |
|
43,310 | sean-perkins/ngx-select | examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js | function () {
var /** @type {?} */ axis = this.vertical ? 'Y' : 'X';
// For a horizontal slider in RTL languages we push the ticks container off the left edge
// instead of the right edge to avoid causing a horizontal scrollbar to appear.
var /** @type {?} */ sign = !this.vertical && this._direction == 'rtl' ? '' : '-';
var /** @type {?} */ offset = this._tickIntervalPercent / 2 * 100;
return {
'transform': "translate" + axis + "(" + sign + offset + "%)"
};
} | javascript | function () {
var /** @type {?} */ axis = this.vertical ? 'Y' : 'X';
// For a horizontal slider in RTL languages we push the ticks container off the left edge
// instead of the right edge to avoid causing a horizontal scrollbar to appear.
var /** @type {?} */ sign = !this.vertical && this._direction == 'rtl' ? '' : '-';
var /** @type {?} */ offset = this._tickIntervalPercent / 2 * 100;
return {
'transform': "translate" + axis + "(" + sign + offset + "%)"
};
} | [
"function",
"(",
")",
"{",
"var",
"/** @type {?} */",
"axis",
"=",
"this",
".",
"vertical",
"?",
"'Y'",
":",
"'X'",
";",
"// For a horizontal slider in RTL languages we push the ticks container off the left edge",
"// instead of the right edge to avoid causing a horizontal scrollbar to appear.",
"var",
"/** @type {?} */",
"sign",
"=",
"!",
"this",
".",
"vertical",
"&&",
"this",
".",
"_direction",
"==",
"'rtl'",
"?",
"''",
":",
"'-'",
";",
"var",
"/** @type {?} */",
"offset",
"=",
"this",
".",
"_tickIntervalPercent",
"/",
"2",
"*",
"100",
";",
"return",
"{",
"'transform'",
":",
"\"translate\"",
"+",
"axis",
"+",
"\"(\"",
"+",
"sign",
"+",
"offset",
"+",
"\"%)\"",
"}",
";",
"}"
]
| CSS styles for the ticks container element.
@return {?} | [
"CSS",
"styles",
"for",
"the",
"ticks",
"container",
"element",
"."
]
| 27eb48f8e49cdaeb4e79937e58e7b16e43e7e390 | https://github.com/sean-perkins/ngx-select/blob/27eb48f8e49cdaeb4e79937e58e7b16e43e7e390/examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js#L15727-L15736 |
|
43,311 | sean-perkins/ngx-select | examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js | function () {
var /** @type {?} */ tickSize = this._tickIntervalPercent * 100;
var /** @type {?} */ backgroundSize = this.vertical ? "2px " + tickSize + "%" : tickSize + "% 2px";
var /** @type {?} */ axis = this.vertical ? 'Y' : 'X';
// Depending on the direction we pushed the ticks container, push the ticks the opposite
// direction to re-center them but clip off the end edge. In RTL languages we need to flip the
// ticks 180 degrees so we're really cutting off the end edge abd not the start.
var /** @type {?} */ sign = !this.vertical && this._direction == 'rtl' ? '-' : '';
var /** @type {?} */ rotate = !this.vertical && this._direction == 'rtl' ? ' rotate(180deg)' : '';
var /** @type {?} */ styles = {
'backgroundSize': backgroundSize,
// Without translateZ ticks sometimes jitter as the slider moves on Chrome & Firefox.
'transform': "translateZ(0) translate" + axis + "(" + sign + tickSize / 2 + "%)" + rotate
};
if (this._isMinValue && this._thumbGap) {
var /** @type {?} */ side = this.vertical ?
(this._invertAxis ? 'Bottom' : 'Top') :
(this._invertAxis ? 'Right' : 'Left');
styles["padding" + side] = this._thumbGap + "px";
}
return styles;
} | javascript | function () {
var /** @type {?} */ tickSize = this._tickIntervalPercent * 100;
var /** @type {?} */ backgroundSize = this.vertical ? "2px " + tickSize + "%" : tickSize + "% 2px";
var /** @type {?} */ axis = this.vertical ? 'Y' : 'X';
// Depending on the direction we pushed the ticks container, push the ticks the opposite
// direction to re-center them but clip off the end edge. In RTL languages we need to flip the
// ticks 180 degrees so we're really cutting off the end edge abd not the start.
var /** @type {?} */ sign = !this.vertical && this._direction == 'rtl' ? '-' : '';
var /** @type {?} */ rotate = !this.vertical && this._direction == 'rtl' ? ' rotate(180deg)' : '';
var /** @type {?} */ styles = {
'backgroundSize': backgroundSize,
// Without translateZ ticks sometimes jitter as the slider moves on Chrome & Firefox.
'transform': "translateZ(0) translate" + axis + "(" + sign + tickSize / 2 + "%)" + rotate
};
if (this._isMinValue && this._thumbGap) {
var /** @type {?} */ side = this.vertical ?
(this._invertAxis ? 'Bottom' : 'Top') :
(this._invertAxis ? 'Right' : 'Left');
styles["padding" + side] = this._thumbGap + "px";
}
return styles;
} | [
"function",
"(",
")",
"{",
"var",
"/** @type {?} */",
"tickSize",
"=",
"this",
".",
"_tickIntervalPercent",
"*",
"100",
";",
"var",
"/** @type {?} */",
"backgroundSize",
"=",
"this",
".",
"vertical",
"?",
"\"2px \"",
"+",
"tickSize",
"+",
"\"%\"",
":",
"tickSize",
"+",
"\"% 2px\"",
";",
"var",
"/** @type {?} */",
"axis",
"=",
"this",
".",
"vertical",
"?",
"'Y'",
":",
"'X'",
";",
"// Depending on the direction we pushed the ticks container, push the ticks the opposite",
"// direction to re-center them but clip off the end edge. In RTL languages we need to flip the",
"// ticks 180 degrees so we're really cutting off the end edge abd not the start.",
"var",
"/** @type {?} */",
"sign",
"=",
"!",
"this",
".",
"vertical",
"&&",
"this",
".",
"_direction",
"==",
"'rtl'",
"?",
"'-'",
":",
"''",
";",
"var",
"/** @type {?} */",
"rotate",
"=",
"!",
"this",
".",
"vertical",
"&&",
"this",
".",
"_direction",
"==",
"'rtl'",
"?",
"' rotate(180deg)'",
":",
"''",
";",
"var",
"/** @type {?} */",
"styles",
"=",
"{",
"'backgroundSize'",
":",
"backgroundSize",
",",
"// Without translateZ ticks sometimes jitter as the slider moves on Chrome & Firefox.",
"'transform'",
":",
"\"translateZ(0) translate\"",
"+",
"axis",
"+",
"\"(\"",
"+",
"sign",
"+",
"tickSize",
"/",
"2",
"+",
"\"%)\"",
"+",
"rotate",
"}",
";",
"if",
"(",
"this",
".",
"_isMinValue",
"&&",
"this",
".",
"_thumbGap",
")",
"{",
"var",
"/** @type {?} */",
"side",
"=",
"this",
".",
"vertical",
"?",
"(",
"this",
".",
"_invertAxis",
"?",
"'Bottom'",
":",
"'Top'",
")",
":",
"(",
"this",
".",
"_invertAxis",
"?",
"'Right'",
":",
"'Left'",
")",
";",
"styles",
"[",
"\"padding\"",
"+",
"side",
"]",
"=",
"this",
".",
"_thumbGap",
"+",
"\"px\"",
";",
"}",
"return",
"styles",
";",
"}"
]
| CSS styles for the ticks element.
@return {?} | [
"CSS",
"styles",
"for",
"the",
"ticks",
"element",
"."
]
| 27eb48f8e49cdaeb4e79937e58e7b16e43e7e390 | https://github.com/sean-perkins/ngx-select/blob/27eb48f8e49cdaeb4e79937e58e7b16e43e7e390/examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js#L15745-L15766 |
|
43,312 | sean-perkins/ngx-select | examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js | polarToCartesian | function polarToCartesian(radius, pathRadius, angleInDegrees) {
var /** @type {?} */ angleInRadians = (angleInDegrees - 90) * DEGREE_IN_RADIANS;
return (radius + (pathRadius * Math.cos(angleInRadians))) +
',' + (radius + (pathRadius * Math.sin(angleInRadians)));
} | javascript | function polarToCartesian(radius, pathRadius, angleInDegrees) {
var /** @type {?} */ angleInRadians = (angleInDegrees - 90) * DEGREE_IN_RADIANS;
return (radius + (pathRadius * Math.cos(angleInRadians))) +
',' + (radius + (pathRadius * Math.sin(angleInRadians)));
} | [
"function",
"polarToCartesian",
"(",
"radius",
",",
"pathRadius",
",",
"angleInDegrees",
")",
"{",
"var",
"/** @type {?} */",
"angleInRadians",
"=",
"(",
"angleInDegrees",
"-",
"90",
")",
"*",
"DEGREE_IN_RADIANS",
";",
"return",
"(",
"radius",
"+",
"(",
"pathRadius",
"*",
"Math",
".",
"cos",
"(",
"angleInRadians",
")",
")",
")",
"+",
"','",
"+",
"(",
"radius",
"+",
"(",
"pathRadius",
"*",
"Math",
".",
"sin",
"(",
"angleInRadians",
")",
")",
")",
";",
"}"
]
| Converts Polar coordinates to Cartesian.
@param {?} radius
@param {?} pathRadius
@param {?} angleInDegrees
@return {?} | [
"Converts",
"Polar",
"coordinates",
"to",
"Cartesian",
"."
]
| 27eb48f8e49cdaeb4e79937e58e7b16e43e7e390 | https://github.com/sean-perkins/ngx-select/blob/27eb48f8e49cdaeb4e79937e58e7b16e43e7e390/examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js#L19950-L19954 |
43,313 | sean-perkins/ngx-select | examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js | materialEase | function materialEase(currentTime, startValue, changeInValue, duration) {
var /** @type {?} */ time = currentTime / duration;
var /** @type {?} */ timeCubed = Math.pow(time, 3);
var /** @type {?} */ timeQuad = Math.pow(time, 4);
var /** @type {?} */ timeQuint = Math.pow(time, 5);
return startValue + changeInValue * ((6 * timeQuint) + (-15 * timeQuad) + (10 * timeCubed));
} | javascript | function materialEase(currentTime, startValue, changeInValue, duration) {
var /** @type {?} */ time = currentTime / duration;
var /** @type {?} */ timeCubed = Math.pow(time, 3);
var /** @type {?} */ timeQuad = Math.pow(time, 4);
var /** @type {?} */ timeQuint = Math.pow(time, 5);
return startValue + changeInValue * ((6 * timeQuint) + (-15 * timeQuad) + (10 * timeCubed));
} | [
"function",
"materialEase",
"(",
"currentTime",
",",
"startValue",
",",
"changeInValue",
",",
"duration",
")",
"{",
"var",
"/** @type {?} */",
"time",
"=",
"currentTime",
"/",
"duration",
";",
"var",
"/** @type {?} */",
"timeCubed",
"=",
"Math",
".",
"pow",
"(",
"time",
",",
"3",
")",
";",
"var",
"/** @type {?} */",
"timeQuad",
"=",
"Math",
".",
"pow",
"(",
"time",
",",
"4",
")",
";",
"var",
"/** @type {?} */",
"timeQuint",
"=",
"Math",
".",
"pow",
"(",
"time",
",",
"5",
")",
";",
"return",
"startValue",
"+",
"changeInValue",
"*",
"(",
"(",
"6",
"*",
"timeQuint",
")",
"+",
"(",
"-",
"15",
"*",
"timeQuad",
")",
"+",
"(",
"10",
"*",
"timeCubed",
")",
")",
";",
"}"
]
| Easing function to match material design indeterminate animation.
@param {?} currentTime
@param {?} startValue
@param {?} changeInValue
@param {?} duration
@return {?} | [
"Easing",
"function",
"to",
"match",
"material",
"design",
"indeterminate",
"animation",
"."
]
| 27eb48f8e49cdaeb4e79937e58e7b16e43e7e390 | https://github.com/sean-perkins/ngx-select/blob/27eb48f8e49cdaeb4e79937e58e7b16e43e7e390/examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js#L19974-L19980 |
43,314 | sean-perkins/ngx-select | examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js | getSvgArc | function getSvgArc(currentValue, rotation) {
var /** @type {?} */ startPoint = rotation || 0;
var /** @type {?} */ radius = 50;
var /** @type {?} */ pathRadius = 40;
var /** @type {?} */ startAngle = startPoint * MAX_ANGLE;
var /** @type {?} */ endAngle = currentValue * MAX_ANGLE;
var /** @type {?} */ start = polarToCartesian(radius, pathRadius, startAngle);
var /** @type {?} */ end = polarToCartesian(radius, pathRadius, endAngle + startAngle);
var /** @type {?} */ arcSweep = endAngle < 0 ? 0 : 1;
var /** @type {?} */ largeArcFlag;
if (endAngle < 0) {
largeArcFlag = endAngle >= -180 ? 0 : 1;
}
else {
largeArcFlag = endAngle <= 180 ? 0 : 1;
}
return "M" + start + "A" + pathRadius + "," + pathRadius + " 0 " + largeArcFlag + "," + arcSweep + " " + end;
} | javascript | function getSvgArc(currentValue, rotation) {
var /** @type {?} */ startPoint = rotation || 0;
var /** @type {?} */ radius = 50;
var /** @type {?} */ pathRadius = 40;
var /** @type {?} */ startAngle = startPoint * MAX_ANGLE;
var /** @type {?} */ endAngle = currentValue * MAX_ANGLE;
var /** @type {?} */ start = polarToCartesian(radius, pathRadius, startAngle);
var /** @type {?} */ end = polarToCartesian(radius, pathRadius, endAngle + startAngle);
var /** @type {?} */ arcSweep = endAngle < 0 ? 0 : 1;
var /** @type {?} */ largeArcFlag;
if (endAngle < 0) {
largeArcFlag = endAngle >= -180 ? 0 : 1;
}
else {
largeArcFlag = endAngle <= 180 ? 0 : 1;
}
return "M" + start + "A" + pathRadius + "," + pathRadius + " 0 " + largeArcFlag + "," + arcSweep + " " + end;
} | [
"function",
"getSvgArc",
"(",
"currentValue",
",",
"rotation",
")",
"{",
"var",
"/** @type {?} */",
"startPoint",
"=",
"rotation",
"||",
"0",
";",
"var",
"/** @type {?} */",
"radius",
"=",
"50",
";",
"var",
"/** @type {?} */",
"pathRadius",
"=",
"40",
";",
"var",
"/** @type {?} */",
"startAngle",
"=",
"startPoint",
"*",
"MAX_ANGLE",
";",
"var",
"/** @type {?} */",
"endAngle",
"=",
"currentValue",
"*",
"MAX_ANGLE",
";",
"var",
"/** @type {?} */",
"start",
"=",
"polarToCartesian",
"(",
"radius",
",",
"pathRadius",
",",
"startAngle",
")",
";",
"var",
"/** @type {?} */",
"end",
"=",
"polarToCartesian",
"(",
"radius",
",",
"pathRadius",
",",
"endAngle",
"+",
"startAngle",
")",
";",
"var",
"/** @type {?} */",
"arcSweep",
"=",
"endAngle",
"<",
"0",
"?",
"0",
":",
"1",
";",
"var",
"/** @type {?} */",
"largeArcFlag",
";",
"if",
"(",
"endAngle",
"<",
"0",
")",
"{",
"largeArcFlag",
"=",
"endAngle",
">=",
"-",
"180",
"?",
"0",
":",
"1",
";",
"}",
"else",
"{",
"largeArcFlag",
"=",
"endAngle",
"<=",
"180",
"?",
"0",
":",
"1",
";",
"}",
"return",
"\"M\"",
"+",
"start",
"+",
"\"A\"",
"+",
"pathRadius",
"+",
"\",\"",
"+",
"pathRadius",
"+",
"\" 0 \"",
"+",
"largeArcFlag",
"+",
"\",\"",
"+",
"arcSweep",
"+",
"\" \"",
"+",
"end",
";",
"}"
]
| Determines the path value to define the arc. Converting percentage values to to polar
coordinates on the circle, and then to cartesian coordinates in the viewport.
@param {?} currentValue The current percentage value of the progress circle, the percentage of the
circle to fill.
@param {?} rotation The starting point of the circle with 0 being the 0 degree point.
@return {?} A string for an SVG path representing a circle filled from the starting point to the
percentage value provided. | [
"Determines",
"the",
"path",
"value",
"to",
"define",
"the",
"arc",
".",
"Converting",
"percentage",
"values",
"to",
"to",
"polar",
"coordinates",
"on",
"the",
"circle",
"and",
"then",
"to",
"cartesian",
"coordinates",
"in",
"the",
"viewport",
"."
]
| 27eb48f8e49cdaeb4e79937e58e7b16e43e7e390 | https://github.com/sean-perkins/ngx-select/blob/27eb48f8e49cdaeb4e79937e58e7b16e43e7e390/examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js#L19991-L20008 |
43,315 | sean-perkins/ngx-select | examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js | clamp$1 | function clamp$1(v, min, max) {
if (min === void 0) { min = 0; }
if (max === void 0) { max = 100; }
return Math.max(min, Math.min(max, v));
} | javascript | function clamp$1(v, min, max) {
if (min === void 0) { min = 0; }
if (max === void 0) { max = 100; }
return Math.max(min, Math.min(max, v));
} | [
"function",
"clamp$1",
"(",
"v",
",",
"min",
",",
"max",
")",
"{",
"if",
"(",
"min",
"===",
"void",
"0",
")",
"{",
"min",
"=",
"0",
";",
"}",
"if",
"(",
"max",
"===",
"void",
"0",
")",
"{",
"max",
"=",
"100",
";",
"}",
"return",
"Math",
".",
"max",
"(",
"min",
",",
"Math",
".",
"min",
"(",
"max",
",",
"v",
")",
")",
";",
"}"
]
| Clamps a value to be between two numbers, by default 0 and 100.
@param {?} v
@param {?=} min
@param {?=} max
@return {?} | [
"Clamps",
"a",
"value",
"to",
"be",
"between",
"two",
"numbers",
"by",
"default",
"0",
"and",
"100",
"."
]
| 27eb48f8e49cdaeb4e79937e58e7b16e43e7e390 | https://github.com/sean-perkins/ngx-select/blob/27eb48f8e49cdaeb4e79937e58e7b16e43e7e390/examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js#L20144-L20148 |
43,316 | sean-perkins/ngx-select | examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js | function (origin) {
if (origin == null) {
return;
}
var /** @type {?} */ dir = this._getLayoutDirection();
if ((dir == 'ltr' && origin <= 0) || (dir == 'rtl' && origin > 0)) {
this._origin = 'left';
}
else {
this._origin = 'right';
}
} | javascript | function (origin) {
if (origin == null) {
return;
}
var /** @type {?} */ dir = this._getLayoutDirection();
if ((dir == 'ltr' && origin <= 0) || (dir == 'rtl' && origin > 0)) {
this._origin = 'left';
}
else {
this._origin = 'right';
}
} | [
"function",
"(",
"origin",
")",
"{",
"if",
"(",
"origin",
"==",
"null",
")",
"{",
"return",
";",
"}",
"var",
"/** @type {?} */",
"dir",
"=",
"this",
".",
"_getLayoutDirection",
"(",
")",
";",
"if",
"(",
"(",
"dir",
"==",
"'ltr'",
"&&",
"origin",
"<=",
"0",
")",
"||",
"(",
"dir",
"==",
"'rtl'",
"&&",
"origin",
">",
"0",
")",
")",
"{",
"this",
".",
"_origin",
"=",
"'left'",
";",
"}",
"else",
"{",
"this",
".",
"_origin",
"=",
"'right'",
";",
"}",
"}"
]
| The origin position from which this tab should appear when it is centered into view.
@param {?} origin
@return {?} | [
"The",
"origin",
"position",
"from",
"which",
"this",
"tab",
"should",
"appear",
"when",
"it",
"is",
"centered",
"into",
"view",
"."
]
| 27eb48f8e49cdaeb4e79937e58e7b16e43e7e390 | https://github.com/sean-perkins/ngx-select/blob/27eb48f8e49cdaeb4e79937e58e7b16e43e7e390/examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js#L22255-L22266 |
|
43,317 | sean-perkins/ngx-select | examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js | function (value) {
if (!this._isValidIndex(value) || this._focusIndex == value) {
return;
}
this._focusIndex = value;
this.indexFocused.emit(value);
this._setTabFocus(value);
} | javascript | function (value) {
if (!this._isValidIndex(value) || this._focusIndex == value) {
return;
}
this._focusIndex = value;
this.indexFocused.emit(value);
this._setTabFocus(value);
} | [
"function",
"(",
"value",
")",
"{",
"if",
"(",
"!",
"this",
".",
"_isValidIndex",
"(",
"value",
")",
"||",
"this",
".",
"_focusIndex",
"==",
"value",
")",
"{",
"return",
";",
"}",
"this",
".",
"_focusIndex",
"=",
"value",
";",
"this",
".",
"indexFocused",
".",
"emit",
"(",
"value",
")",
";",
"this",
".",
"_setTabFocus",
"(",
"value",
")",
";",
"}"
]
| When the focus index is set, we must manually send focus to the correct label
@param {?} value
@return {?} | [
"When",
"the",
"focus",
"index",
"is",
"set",
"we",
"must",
"manually",
"send",
"focus",
"to",
"the",
"correct",
"label"
]
| 27eb48f8e49cdaeb4e79937e58e7b16e43e7e390 | https://github.com/sean-perkins/ngx-select/blob/27eb48f8e49cdaeb4e79937e58e7b16e43e7e390/examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js#L22538-L22545 |
|
43,318 | sean-perkins/ngx-select | examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js | function (v) {
this._scrollDistance = Math.max(0, Math.min(this._getMaxScrollDistance(), v));
// Mark that the scroll distance has changed so that after the view is checked, the CSS
// transformation can move the header.
this._scrollDistanceChanged = true;
this._checkScrollingControls();
} | javascript | function (v) {
this._scrollDistance = Math.max(0, Math.min(this._getMaxScrollDistance(), v));
// Mark that the scroll distance has changed so that after the view is checked, the CSS
// transformation can move the header.
this._scrollDistanceChanged = true;
this._checkScrollingControls();
} | [
"function",
"(",
"v",
")",
"{",
"this",
".",
"_scrollDistance",
"=",
"Math",
".",
"max",
"(",
"0",
",",
"Math",
".",
"min",
"(",
"this",
".",
"_getMaxScrollDistance",
"(",
")",
",",
"v",
")",
")",
";",
"// Mark that the scroll distance has changed so that after the view is checked, the CSS",
"// transformation can move the header.",
"this",
".",
"_scrollDistanceChanged",
"=",
"true",
";",
"this",
".",
"_checkScrollingControls",
"(",
")",
";",
"}"
]
| Sets the distance in pixels that the tab header should be transformed in the X-axis.
@param {?} v
@return {?} | [
"Sets",
"the",
"distance",
"in",
"pixels",
"that",
"the",
"tab",
"header",
"should",
"be",
"transformed",
"in",
"the",
"X",
"-",
"axis",
"."
]
| 27eb48f8e49cdaeb4e79937e58e7b16e43e7e390 | https://github.com/sean-perkins/ngx-select/blob/27eb48f8e49cdaeb4e79937e58e7b16e43e7e390/examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js#L22646-L22652 |
|
43,319 | sean-perkins/ngx-select | examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js | function (classes) {
this._classList = classes.split(' ').reduce(function (obj, className) {
obj[className] = true;
return obj;
}, {});
this.setPositionClasses(this.positionX, this.positionY);
} | javascript | function (classes) {
this._classList = classes.split(' ').reduce(function (obj, className) {
obj[className] = true;
return obj;
}, {});
this.setPositionClasses(this.positionX, this.positionY);
} | [
"function",
"(",
"classes",
")",
"{",
"this",
".",
"_classList",
"=",
"classes",
".",
"split",
"(",
"' '",
")",
".",
"reduce",
"(",
"function",
"(",
"obj",
",",
"className",
")",
"{",
"obj",
"[",
"className",
"]",
"=",
"true",
";",
"return",
"obj",
";",
"}",
",",
"{",
"}",
")",
";",
"this",
".",
"setPositionClasses",
"(",
"this",
".",
"positionX",
",",
"this",
".",
"positionY",
")",
";",
"}"
]
| This method takes classes set on the host md-menu element and applies them on the
menu template that displays in the overlay container. Otherwise, it's difficult
to style the containing menu from outside the component.
@param {?} classes list of class names
@return {?} | [
"This",
"method",
"takes",
"classes",
"set",
"on",
"the",
"host",
"md",
"-",
"menu",
"element",
"and",
"applies",
"them",
"on",
"the",
"menu",
"template",
"that",
"displays",
"in",
"the",
"overlay",
"container",
".",
"Otherwise",
"it",
"s",
"difficult",
"to",
"style",
"the",
"containing",
"menu",
"from",
"outside",
"the",
"component",
"."
]
| 27eb48f8e49cdaeb4e79937e58e7b16e43e7e390 | https://github.com/sean-perkins/ngx-select/blob/27eb48f8e49cdaeb4e79937e58e7b16e43e7e390/examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js#L23796-L23802 |
|
43,320 | sean-perkins/ngx-select | examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js | function () {
return __WEBPACK_IMPORTED_MODULE_4_rxjs_Observable__["Observable"].merge.apply(__WEBPACK_IMPORTED_MODULE_4_rxjs_Observable__["Observable"], this.autocomplete.options.map(function (option) { return option.onSelectionChange; }));
} | javascript | function () {
return __WEBPACK_IMPORTED_MODULE_4_rxjs_Observable__["Observable"].merge.apply(__WEBPACK_IMPORTED_MODULE_4_rxjs_Observable__["Observable"], this.autocomplete.options.map(function (option) { return option.onSelectionChange; }));
} | [
"function",
"(",
")",
"{",
"return",
"__WEBPACK_IMPORTED_MODULE_4_rxjs_Observable__",
"[",
"\"Observable\"",
"]",
".",
"merge",
".",
"apply",
"(",
"__WEBPACK_IMPORTED_MODULE_4_rxjs_Observable__",
"[",
"\"Observable\"",
"]",
",",
"this",
".",
"autocomplete",
".",
"options",
".",
"map",
"(",
"function",
"(",
"option",
")",
"{",
"return",
"option",
".",
"onSelectionChange",
";",
"}",
")",
")",
";",
"}"
]
| Stream of autocomplete option selections.
@return {?} | [
"Stream",
"of",
"autocomplete",
"option",
"selections",
"."
]
| 27eb48f8e49cdaeb4e79937e58e7b16e43e7e390 | https://github.com/sean-perkins/ngx-select/blob/27eb48f8e49cdaeb4e79937e58e7b16e43e7e390/examples/webpack/dist/0.e100c23eefa4ef71b346.chunk.js#L25105-L25107 |
|
43,321 | alexindigo/fbbot | lib/verify_endpoint.js | verifyEndpoint | function verifyEndpoint(request, respond)
{
var challenge;
if (typeof request.query == 'string')
{
request.query = qs.parse(request.query);
}
if (typeof request.query == 'object'
&& ((request.query['hub.verify_token'] === this.credentials.secret)
// for hapi@10 and restify/express with queryParser check for `hub` object
|| (typeof request.query.hub == 'object' && request.query.hub['verify_token'] === this.credentials.secret)
)
)
{
challenge = request.query['hub.challenge'] || (request.query.hub ? request.query.hub.challenge : null);
this.logger.debug({message: 'Successfully verified', challenge: challenge});
respond(challenge);
return;
}
this.logger.error({message: 'Unable to verify endpoint', query: request.query});
respond(400, 'Error, wrong validation token');
} | javascript | function verifyEndpoint(request, respond)
{
var challenge;
if (typeof request.query == 'string')
{
request.query = qs.parse(request.query);
}
if (typeof request.query == 'object'
&& ((request.query['hub.verify_token'] === this.credentials.secret)
// for hapi@10 and restify/express with queryParser check for `hub` object
|| (typeof request.query.hub == 'object' && request.query.hub['verify_token'] === this.credentials.secret)
)
)
{
challenge = request.query['hub.challenge'] || (request.query.hub ? request.query.hub.challenge : null);
this.logger.debug({message: 'Successfully verified', challenge: challenge});
respond(challenge);
return;
}
this.logger.error({message: 'Unable to verify endpoint', query: request.query});
respond(400, 'Error, wrong validation token');
} | [
"function",
"verifyEndpoint",
"(",
"request",
",",
"respond",
")",
"{",
"var",
"challenge",
";",
"if",
"(",
"typeof",
"request",
".",
"query",
"==",
"'string'",
")",
"{",
"request",
".",
"query",
"=",
"qs",
".",
"parse",
"(",
"request",
".",
"query",
")",
";",
"}",
"if",
"(",
"typeof",
"request",
".",
"query",
"==",
"'object'",
"&&",
"(",
"(",
"request",
".",
"query",
"[",
"'hub.verify_token'",
"]",
"===",
"this",
".",
"credentials",
".",
"secret",
")",
"// for hapi@10 and restify/express with queryParser check for `hub` object",
"||",
"(",
"typeof",
"request",
".",
"query",
".",
"hub",
"==",
"'object'",
"&&",
"request",
".",
"query",
".",
"hub",
"[",
"'verify_token'",
"]",
"===",
"this",
".",
"credentials",
".",
"secret",
")",
")",
")",
"{",
"challenge",
"=",
"request",
".",
"query",
"[",
"'hub.challenge'",
"]",
"||",
"(",
"request",
".",
"query",
".",
"hub",
"?",
"request",
".",
"query",
".",
"hub",
".",
"challenge",
":",
"null",
")",
";",
"this",
".",
"logger",
".",
"debug",
"(",
"{",
"message",
":",
"'Successfully verified'",
",",
"challenge",
":",
"challenge",
"}",
")",
";",
"respond",
"(",
"challenge",
")",
";",
"return",
";",
"}",
"this",
".",
"logger",
".",
"error",
"(",
"{",
"message",
":",
"'Unable to verify endpoint'",
",",
"query",
":",
"request",
".",
"query",
"}",
")",
";",
"respond",
"(",
"400",
",",
"'Error, wrong validation token'",
")",
";",
"}"
]
| Verifies endpoint by replying with the provided challenge
@this Fbbot#
@param {EventEmitter} request - incoming http request object
@param {function} respond - http response function | [
"Verifies",
"endpoint",
"by",
"replying",
"with",
"the",
"provided",
"challenge"
]
| b78a0418ebdfd106723348d94b4378ac67f7d4bf | https://github.com/alexindigo/fbbot/blob/b78a0418ebdfd106723348d94b4378ac67f7d4bf/lib/verify_endpoint.js#L12-L37 |
43,322 | yahoo/preceptor | lib/client.js | function (options, send) {
var clientPath = options.clientPath,
coverage = options.coverage,
parentId = options.parentId,
configuration = options.configuration,
globalConfig = options.globalConfig,
decorators = options.decorators,
decoratorPlugins = options.decoratorPlugins,
ClientClass,
clientInstance,
coverageVar = '__preceptorCoverage__',
instrumenter,
transformer,
globalCoverageConfig = globalConfig.coverage,
coverageIncludes = globalCoverageConfig.includes || ['**/*.js'],
coverageExcludes = globalCoverageConfig.excludes || ['**/node_modules/**', '**/test/**', '**/tests/**'];
// Make global configuration available
global.PRECEPTOR = {
config: globalConfig
};
// Create client and run it
ClientClass = require(clientPath);
clientInstance = new ClientClass(decorators, decoratorPlugins, configuration);
clientInstance.on('reportMessage', function (messageType, data) {
send({
type: "reportMessage",
messageType: messageType,
data: data
});
});
// Is coverage requested?
if (((coverage === undefined) || (coverage === true)) && globalCoverageConfig.active) {
// Prepare coverage instrumentation
instrumenter = new istanbul.Instrumenter({ coverageVariable: coverageVar, preserveComments: true });
transformer = instrumenter.instrumentSync.bind(instrumenter);
// Hook-up transformer for every new file loaded
istanbul.hook.hookRequire(function (filePath) {
var allowed = false;
// Inclusion
_.each(coverageIncludes, function (include) {
allowed = allowed || minimatch(filePath, include);
});
if (allowed) {
// Exclusion
_.each(coverageExcludes, function (exclude) {
allowed = allowed && !minimatch(filePath, exclude);
});
}
return allowed;
}, transformer, {});
// Prepare variable
global[coverageVar] = {};
}
// Run client
clientInstance.run(parentId).then(function () {
send({
type: "completion",
data: {
success: true,
coverage: global[coverageVar]
}
});
global[coverageVar] = {}; // Reset
}, function (err) {
send({
type: "completion",
data: {
success: false,
coverage: global[coverageVar],
context: err.stack
}
});
global[coverageVar] = {}; // Reset
});
} | javascript | function (options, send) {
var clientPath = options.clientPath,
coverage = options.coverage,
parentId = options.parentId,
configuration = options.configuration,
globalConfig = options.globalConfig,
decorators = options.decorators,
decoratorPlugins = options.decoratorPlugins,
ClientClass,
clientInstance,
coverageVar = '__preceptorCoverage__',
instrumenter,
transformer,
globalCoverageConfig = globalConfig.coverage,
coverageIncludes = globalCoverageConfig.includes || ['**/*.js'],
coverageExcludes = globalCoverageConfig.excludes || ['**/node_modules/**', '**/test/**', '**/tests/**'];
// Make global configuration available
global.PRECEPTOR = {
config: globalConfig
};
// Create client and run it
ClientClass = require(clientPath);
clientInstance = new ClientClass(decorators, decoratorPlugins, configuration);
clientInstance.on('reportMessage', function (messageType, data) {
send({
type: "reportMessage",
messageType: messageType,
data: data
});
});
// Is coverage requested?
if (((coverage === undefined) || (coverage === true)) && globalCoverageConfig.active) {
// Prepare coverage instrumentation
instrumenter = new istanbul.Instrumenter({ coverageVariable: coverageVar, preserveComments: true });
transformer = instrumenter.instrumentSync.bind(instrumenter);
// Hook-up transformer for every new file loaded
istanbul.hook.hookRequire(function (filePath) {
var allowed = false;
// Inclusion
_.each(coverageIncludes, function (include) {
allowed = allowed || minimatch(filePath, include);
});
if (allowed) {
// Exclusion
_.each(coverageExcludes, function (exclude) {
allowed = allowed && !minimatch(filePath, exclude);
});
}
return allowed;
}, transformer, {});
// Prepare variable
global[coverageVar] = {};
}
// Run client
clientInstance.run(parentId).then(function () {
send({
type: "completion",
data: {
success: true,
coverage: global[coverageVar]
}
});
global[coverageVar] = {}; // Reset
}, function (err) {
send({
type: "completion",
data: {
success: false,
coverage: global[coverageVar],
context: err.stack
}
});
global[coverageVar] = {}; // Reset
});
} | [
"function",
"(",
"options",
",",
"send",
")",
"{",
"var",
"clientPath",
"=",
"options",
".",
"clientPath",
",",
"coverage",
"=",
"options",
".",
"coverage",
",",
"parentId",
"=",
"options",
".",
"parentId",
",",
"configuration",
"=",
"options",
".",
"configuration",
",",
"globalConfig",
"=",
"options",
".",
"globalConfig",
",",
"decorators",
"=",
"options",
".",
"decorators",
",",
"decoratorPlugins",
"=",
"options",
".",
"decoratorPlugins",
",",
"ClientClass",
",",
"clientInstance",
",",
"coverageVar",
"=",
"'__preceptorCoverage__'",
",",
"instrumenter",
",",
"transformer",
",",
"globalCoverageConfig",
"=",
"globalConfig",
".",
"coverage",
",",
"coverageIncludes",
"=",
"globalCoverageConfig",
".",
"includes",
"||",
"[",
"'**/*.js'",
"]",
",",
"coverageExcludes",
"=",
"globalCoverageConfig",
".",
"excludes",
"||",
"[",
"'**/node_modules/**'",
",",
"'**/test/**'",
",",
"'**/tests/**'",
"]",
";",
"// Make global configuration available",
"global",
".",
"PRECEPTOR",
"=",
"{",
"config",
":",
"globalConfig",
"}",
";",
"// Create client and run it",
"ClientClass",
"=",
"require",
"(",
"clientPath",
")",
";",
"clientInstance",
"=",
"new",
"ClientClass",
"(",
"decorators",
",",
"decoratorPlugins",
",",
"configuration",
")",
";",
"clientInstance",
".",
"on",
"(",
"'reportMessage'",
",",
"function",
"(",
"messageType",
",",
"data",
")",
"{",
"send",
"(",
"{",
"type",
":",
"\"reportMessage\"",
",",
"messageType",
":",
"messageType",
",",
"data",
":",
"data",
"}",
")",
";",
"}",
")",
";",
"// Is coverage requested?",
"if",
"(",
"(",
"(",
"coverage",
"===",
"undefined",
")",
"||",
"(",
"coverage",
"===",
"true",
")",
")",
"&&",
"globalCoverageConfig",
".",
"active",
")",
"{",
"// Prepare coverage instrumentation",
"instrumenter",
"=",
"new",
"istanbul",
".",
"Instrumenter",
"(",
"{",
"coverageVariable",
":",
"coverageVar",
",",
"preserveComments",
":",
"true",
"}",
")",
";",
"transformer",
"=",
"instrumenter",
".",
"instrumentSync",
".",
"bind",
"(",
"instrumenter",
")",
";",
"// Hook-up transformer for every new file loaded",
"istanbul",
".",
"hook",
".",
"hookRequire",
"(",
"function",
"(",
"filePath",
")",
"{",
"var",
"allowed",
"=",
"false",
";",
"// Inclusion",
"_",
".",
"each",
"(",
"coverageIncludes",
",",
"function",
"(",
"include",
")",
"{",
"allowed",
"=",
"allowed",
"||",
"minimatch",
"(",
"filePath",
",",
"include",
")",
";",
"}",
")",
";",
"if",
"(",
"allowed",
")",
"{",
"// Exclusion",
"_",
".",
"each",
"(",
"coverageExcludes",
",",
"function",
"(",
"exclude",
")",
"{",
"allowed",
"=",
"allowed",
"&&",
"!",
"minimatch",
"(",
"filePath",
",",
"exclude",
")",
";",
"}",
")",
";",
"}",
"return",
"allowed",
";",
"}",
",",
"transformer",
",",
"{",
"}",
")",
";",
"// Prepare variable",
"global",
"[",
"coverageVar",
"]",
"=",
"{",
"}",
";",
"}",
"// Run client",
"clientInstance",
".",
"run",
"(",
"parentId",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"send",
"(",
"{",
"type",
":",
"\"completion\"",
",",
"data",
":",
"{",
"success",
":",
"true",
",",
"coverage",
":",
"global",
"[",
"coverageVar",
"]",
"}",
"}",
")",
";",
"global",
"[",
"coverageVar",
"]",
"=",
"{",
"}",
";",
"// Reset",
"}",
",",
"function",
"(",
"err",
")",
"{",
"send",
"(",
"{",
"type",
":",
"\"completion\"",
",",
"data",
":",
"{",
"success",
":",
"false",
",",
"coverage",
":",
"global",
"[",
"coverageVar",
"]",
",",
"context",
":",
"err",
".",
"stack",
"}",
"}",
")",
";",
"global",
"[",
"coverageVar",
"]",
"=",
"{",
"}",
";",
"// Reset",
"}",
")",
";",
"}"
]
| Runs the client
@class Client
@method run
@param {object} options
@param {function} send
@private | [
"Runs",
"the",
"client"
]
| 061ffeca8751344b06e6768a281cc7a2679fd679 | https://github.com/yahoo/preceptor/blob/061ffeca8751344b06e6768a281cc7a2679fd679/lib/client.js#L18-L107 |
|
43,323 | citizenmatt/gitbook-plugin-multipart | index.js | function(summary) {
// If the file contains an h2, we need to reformat it
if (summary.content.match(/^## /m)) {
var parts = summary.content.split(/(?=##)/);
for (var i = 0; i < parts.length; i++) {
// Remove any blank lines
parts[i] = parts[i].replace(/(\*.*)\n\n/gm, "$1\n");
// If the part has a heading, replace it and indent the child items in the list
// Mark a heading as a part by smuggling some text into the list item.
// Messy, but it's the only way.
if (parts[i].indexOf('##') == 0) {
parts[i] = parts[i].replace(/^([ \t]*\* .+)$/gm, " $1")
.replace(/^## (.*)$/gm, "* -XPARTX-$1")
}
}
summary.content = parts.join('');
}
return summary;
} | javascript | function(summary) {
// If the file contains an h2, we need to reformat it
if (summary.content.match(/^## /m)) {
var parts = summary.content.split(/(?=##)/);
for (var i = 0; i < parts.length; i++) {
// Remove any blank lines
parts[i] = parts[i].replace(/(\*.*)\n\n/gm, "$1\n");
// If the part has a heading, replace it and indent the child items in the list
// Mark a heading as a part by smuggling some text into the list item.
// Messy, but it's the only way.
if (parts[i].indexOf('##') == 0) {
parts[i] = parts[i].replace(/^([ \t]*\* .+)$/gm, " $1")
.replace(/^## (.*)$/gm, "* -XPARTX-$1")
}
}
summary.content = parts.join('');
}
return summary;
} | [
"function",
"(",
"summary",
")",
"{",
"// If the file contains an h2, we need to reformat it",
"if",
"(",
"summary",
".",
"content",
".",
"match",
"(",
"/",
"^## ",
"/",
"m",
")",
")",
"{",
"var",
"parts",
"=",
"summary",
".",
"content",
".",
"split",
"(",
"/",
"(?=##)",
"/",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"parts",
".",
"length",
";",
"i",
"++",
")",
"{",
"// Remove any blank lines",
"parts",
"[",
"i",
"]",
"=",
"parts",
"[",
"i",
"]",
".",
"replace",
"(",
"/",
"(\\*.*)\\n\\n",
"/",
"gm",
",",
"\"$1\\n\"",
")",
";",
"// If the part has a heading, replace it and indent the child items in the list",
"// Mark a heading as a part by smuggling some text into the list item.",
"// Messy, but it's the only way.",
"if",
"(",
"parts",
"[",
"i",
"]",
".",
"indexOf",
"(",
"'##'",
")",
"==",
"0",
")",
"{",
"parts",
"[",
"i",
"]",
"=",
"parts",
"[",
"i",
"]",
".",
"replace",
"(",
"/",
"^([ \\t]*\\* .+)$",
"/",
"gm",
",",
"\" $1\"",
")",
".",
"replace",
"(",
"/",
"^## (.*)$",
"/",
"gm",
",",
"\"* -XPARTX-$1\"",
")",
"}",
"}",
"summary",
".",
"content",
"=",
"parts",
".",
"join",
"(",
"''",
")",
";",
"}",
"return",
"summary",
";",
"}"
]
| Gets plain text content | [
"Gets",
"plain",
"text",
"content"
]
| 6ba8f01d3e83915516d8614e119f0c34390aad96 | https://github.com/citizenmatt/gitbook-plugin-multipart/blob/6ba8f01d3e83915516d8614e119f0c34390aad96/index.js#L10-L32 |
|
43,324 | citizenmatt/gitbook-plugin-multipart | index.js | function(page) {
var $ = cheerio.load(page.content);
// Replace top level li.chapter with li.part
$('ul.summary > li.chapter').each(function(i, elem) {
var li = $(elem);
// Replace the classes if the chapter is actually a part, and add a divider
if (li.text().indexOf('-XPARTX-') > 0) {
li.removeClass('chapter');
li.addClass('part');
// Don't add a divider before the first part, let it come straight after the Introduction page
if (i > 1)
li.before('<li class="part divider" />');
}
});
// remove chapter numbers from any intro pages (and child pages)
$('ul.summary > li.chapter span > b').remove();
$('ul.summary > li.chapter a > b').remove();
// Remove the chapter number from the part header
$('ul.summary > li.part > span > b').remove();
$('ul.summary > li.part > a > b').remove();
// Replace the nasty munging of the name for part heading
$('ul.summary > li.part > span').each(function(i, elem) {
var span = $(elem);
span.text(span.text().replace(/-XPARTX-/, ""));
});
// Bump the remaining chapter numbers so each chapter is only unique
// within the part
$('ul.summary > li.part li.chapter b').each(function(i, elem) {
var b = $(elem);
var text = b.text();
var index = text.indexOf('.');
if (index > -1)
b.text(text.substring(index + 1));
});
page.content = $.html();
return page;
} | javascript | function(page) {
var $ = cheerio.load(page.content);
// Replace top level li.chapter with li.part
$('ul.summary > li.chapter').each(function(i, elem) {
var li = $(elem);
// Replace the classes if the chapter is actually a part, and add a divider
if (li.text().indexOf('-XPARTX-') > 0) {
li.removeClass('chapter');
li.addClass('part');
// Don't add a divider before the first part, let it come straight after the Introduction page
if (i > 1)
li.before('<li class="part divider" />');
}
});
// remove chapter numbers from any intro pages (and child pages)
$('ul.summary > li.chapter span > b').remove();
$('ul.summary > li.chapter a > b').remove();
// Remove the chapter number from the part header
$('ul.summary > li.part > span > b').remove();
$('ul.summary > li.part > a > b').remove();
// Replace the nasty munging of the name for part heading
$('ul.summary > li.part > span').each(function(i, elem) {
var span = $(elem);
span.text(span.text().replace(/-XPARTX-/, ""));
});
// Bump the remaining chapter numbers so each chapter is only unique
// within the part
$('ul.summary > li.part li.chapter b').each(function(i, elem) {
var b = $(elem);
var text = b.text();
var index = text.indexOf('.');
if (index > -1)
b.text(text.substring(index + 1));
});
page.content = $.html();
return page;
} | [
"function",
"(",
"page",
")",
"{",
"var",
"$",
"=",
"cheerio",
".",
"load",
"(",
"page",
".",
"content",
")",
";",
"// Replace top level li.chapter with li.part",
"$",
"(",
"'ul.summary > li.chapter'",
")",
".",
"each",
"(",
"function",
"(",
"i",
",",
"elem",
")",
"{",
"var",
"li",
"=",
"$",
"(",
"elem",
")",
";",
"// Replace the classes if the chapter is actually a part, and add a divider",
"if",
"(",
"li",
".",
"text",
"(",
")",
".",
"indexOf",
"(",
"'-XPARTX-'",
")",
">",
"0",
")",
"{",
"li",
".",
"removeClass",
"(",
"'chapter'",
")",
";",
"li",
".",
"addClass",
"(",
"'part'",
")",
";",
"// Don't add a divider before the first part, let it come straight after the Introduction page",
"if",
"(",
"i",
">",
"1",
")",
"li",
".",
"before",
"(",
"'<li class=\"part divider\" />'",
")",
";",
"}",
"}",
")",
";",
"// remove chapter numbers from any intro pages (and child pages)",
"$",
"(",
"'ul.summary > li.chapter span > b'",
")",
".",
"remove",
"(",
")",
";",
"$",
"(",
"'ul.summary > li.chapter a > b'",
")",
".",
"remove",
"(",
")",
";",
"// Remove the chapter number from the part header",
"$",
"(",
"'ul.summary > li.part > span > b'",
")",
".",
"remove",
"(",
")",
";",
"$",
"(",
"'ul.summary > li.part > a > b'",
")",
".",
"remove",
"(",
")",
";",
"// Replace the nasty munging of the name for part heading",
"$",
"(",
"'ul.summary > li.part > span'",
")",
".",
"each",
"(",
"function",
"(",
"i",
",",
"elem",
")",
"{",
"var",
"span",
"=",
"$",
"(",
"elem",
")",
";",
"span",
".",
"text",
"(",
"span",
".",
"text",
"(",
")",
".",
"replace",
"(",
"/",
"-XPARTX-",
"/",
",",
"\"\"",
")",
")",
";",
"}",
")",
";",
"// Bump the remaining chapter numbers so each chapter is only unique",
"// within the part",
"$",
"(",
"'ul.summary > li.part li.chapter b'",
")",
".",
"each",
"(",
"function",
"(",
"i",
",",
"elem",
")",
"{",
"var",
"b",
"=",
"$",
"(",
"elem",
")",
";",
"var",
"text",
"=",
"b",
".",
"text",
"(",
")",
";",
"var",
"index",
"=",
"text",
".",
"indexOf",
"(",
"'.'",
")",
";",
"if",
"(",
"index",
">",
"-",
"1",
")",
"b",
".",
"text",
"(",
"text",
".",
"substring",
"(",
"index",
"+",
"1",
")",
")",
";",
"}",
")",
";",
"page",
".",
"content",
"=",
"$",
".",
"html",
"(",
")",
";",
"return",
"page",
";",
"}"
]
| Requires an unhealthy knowledge of the generated template... | [
"Requires",
"an",
"unhealthy",
"knowledge",
"of",
"the",
"generated",
"template",
"..."
]
| 6ba8f01d3e83915516d8614e119f0c34390aad96 | https://github.com/citizenmatt/gitbook-plugin-multipart/blob/6ba8f01d3e83915516d8614e119f0c34390aad96/index.js#L35-L80 |
|
43,325 | alexindigo/fbbot | index.js | Fbbot | function Fbbot(options)
{
if (!(this instanceof Fbbot)) return new Fbbot(options);
/**
* Custom options per instance
* @type {object}
*/
this.options = merge(Fbbot.defaults, options || {});
/**
* Store credentials
* @type {object}
*/
this.credentials =
{
// keep simple naming for internal reference
token : this.options.pageAccessToken || this.options.token,
secret: this.options.verifyToken || this.options.secret
};
if (!this.credentials.token || !this.credentials.secret)
{
throw new Error('Both `token` (pageAccessToken) and `secret` (verifyToken) are required');
}
// compose apiUrl
this.options.apiUrl += this.credentials.token;
/**
* expose logger
* @type {object}
*/
this.logger = options.logger || bole(options.name || 'fbbot');
/**
* middleware storage (per event)
* @type {object}
* @private
*/
this._stack = {};
/**
* lock-in public methods
* wrap `_handler` with agnostic to accommodate different http servers
* @type {function}
*/
this.requestHandler = agnostic(this._handler.bind(this));
// attach lifecycle filters
inMiddleware(this);
outMiddleware(this);
/**
* create incoming traverse paths
* @type {Traverse}
* @private
*/
this._incoming = new Traverse(inTraverse.steps, {
entry : middleware.entryPoint,
middleware: inTraverse.middleware.bind(this),
emitter : inTraverse.emitter.bind(this),
prefix : inTraverse.prefix
});
// wrap linkParent method
this._incoming.linkParent = inTraverse.linkParent.bind(null, this._incoming.linkParent);
/**
* create outgoing traverse paths
* @type {Traverse}
* @private
*/
this._outgoing = new Traverse(outTraverse.steps, {
middleware: outTraverse.middleware.bind(this),
emitter : outTraverse.emitter.bind(this),
prefix : outTraverse.prefix
});
// wrap linkParent method
this._outgoing.linkParent = outTraverse.linkParent.bind(null, this._outgoing.linkParent);
} | javascript | function Fbbot(options)
{
if (!(this instanceof Fbbot)) return new Fbbot(options);
/**
* Custom options per instance
* @type {object}
*/
this.options = merge(Fbbot.defaults, options || {});
/**
* Store credentials
* @type {object}
*/
this.credentials =
{
// keep simple naming for internal reference
token : this.options.pageAccessToken || this.options.token,
secret: this.options.verifyToken || this.options.secret
};
if (!this.credentials.token || !this.credentials.secret)
{
throw new Error('Both `token` (pageAccessToken) and `secret` (verifyToken) are required');
}
// compose apiUrl
this.options.apiUrl += this.credentials.token;
/**
* expose logger
* @type {object}
*/
this.logger = options.logger || bole(options.name || 'fbbot');
/**
* middleware storage (per event)
* @type {object}
* @private
*/
this._stack = {};
/**
* lock-in public methods
* wrap `_handler` with agnostic to accommodate different http servers
* @type {function}
*/
this.requestHandler = agnostic(this._handler.bind(this));
// attach lifecycle filters
inMiddleware(this);
outMiddleware(this);
/**
* create incoming traverse paths
* @type {Traverse}
* @private
*/
this._incoming = new Traverse(inTraverse.steps, {
entry : middleware.entryPoint,
middleware: inTraverse.middleware.bind(this),
emitter : inTraverse.emitter.bind(this),
prefix : inTraverse.prefix
});
// wrap linkParent method
this._incoming.linkParent = inTraverse.linkParent.bind(null, this._incoming.linkParent);
/**
* create outgoing traverse paths
* @type {Traverse}
* @private
*/
this._outgoing = new Traverse(outTraverse.steps, {
middleware: outTraverse.middleware.bind(this),
emitter : outTraverse.emitter.bind(this),
prefix : outTraverse.prefix
});
// wrap linkParent method
this._outgoing.linkParent = outTraverse.linkParent.bind(null, this._outgoing.linkParent);
} | [
"function",
"Fbbot",
"(",
"options",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Fbbot",
")",
")",
"return",
"new",
"Fbbot",
"(",
"options",
")",
";",
"/**\n * Custom options per instance\n * @type {object}\n */",
"this",
".",
"options",
"=",
"merge",
"(",
"Fbbot",
".",
"defaults",
",",
"options",
"||",
"{",
"}",
")",
";",
"/**\n * Store credentials\n * @type {object}\n */",
"this",
".",
"credentials",
"=",
"{",
"// keep simple naming for internal reference",
"token",
":",
"this",
".",
"options",
".",
"pageAccessToken",
"||",
"this",
".",
"options",
".",
"token",
",",
"secret",
":",
"this",
".",
"options",
".",
"verifyToken",
"||",
"this",
".",
"options",
".",
"secret",
"}",
";",
"if",
"(",
"!",
"this",
".",
"credentials",
".",
"token",
"||",
"!",
"this",
".",
"credentials",
".",
"secret",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Both `token` (pageAccessToken) and `secret` (verifyToken) are required'",
")",
";",
"}",
"// compose apiUrl",
"this",
".",
"options",
".",
"apiUrl",
"+=",
"this",
".",
"credentials",
".",
"token",
";",
"/**\n * expose logger\n * @type {object}\n */",
"this",
".",
"logger",
"=",
"options",
".",
"logger",
"||",
"bole",
"(",
"options",
".",
"name",
"||",
"'fbbot'",
")",
";",
"/**\n * middleware storage (per event)\n * @type {object}\n * @private\n */",
"this",
".",
"_stack",
"=",
"{",
"}",
";",
"/**\n * lock-in public methods\n * wrap `_handler` with agnostic to accommodate different http servers\n * @type {function}\n */",
"this",
".",
"requestHandler",
"=",
"agnostic",
"(",
"this",
".",
"_handler",
".",
"bind",
"(",
"this",
")",
")",
";",
"// attach lifecycle filters",
"inMiddleware",
"(",
"this",
")",
";",
"outMiddleware",
"(",
"this",
")",
";",
"/**\n * create incoming traverse paths\n * @type {Traverse}\n * @private\n */",
"this",
".",
"_incoming",
"=",
"new",
"Traverse",
"(",
"inTraverse",
".",
"steps",
",",
"{",
"entry",
":",
"middleware",
".",
"entryPoint",
",",
"middleware",
":",
"inTraverse",
".",
"middleware",
".",
"bind",
"(",
"this",
")",
",",
"emitter",
":",
"inTraverse",
".",
"emitter",
".",
"bind",
"(",
"this",
")",
",",
"prefix",
":",
"inTraverse",
".",
"prefix",
"}",
")",
";",
"// wrap linkParent method",
"this",
".",
"_incoming",
".",
"linkParent",
"=",
"inTraverse",
".",
"linkParent",
".",
"bind",
"(",
"null",
",",
"this",
".",
"_incoming",
".",
"linkParent",
")",
";",
"/**\n * create outgoing traverse paths\n * @type {Traverse}\n * @private\n */",
"this",
".",
"_outgoing",
"=",
"new",
"Traverse",
"(",
"outTraverse",
".",
"steps",
",",
"{",
"middleware",
":",
"outTraverse",
".",
"middleware",
".",
"bind",
"(",
"this",
")",
",",
"emitter",
":",
"outTraverse",
".",
"emitter",
".",
"bind",
"(",
"this",
")",
",",
"prefix",
":",
"outTraverse",
".",
"prefix",
"}",
")",
";",
"// wrap linkParent method",
"this",
".",
"_outgoing",
".",
"linkParent",
"=",
"outTraverse",
".",
"linkParent",
".",
"bind",
"(",
"null",
",",
"this",
".",
"_outgoing",
".",
"linkParent",
")",
";",
"}"
]
| Fbbot instance constructor
@this Fbbot#
@param {object} options - list of customization parameters
@constructor | [
"Fbbot",
"instance",
"constructor"
]
| b78a0418ebdfd106723348d94b4378ac67f7d4bf | https://github.com/alexindigo/fbbot/blob/b78a0418ebdfd106723348d94b4378ac67f7d4bf/index.js#L57-L136 |
43,326 | Gambiit/mcp3008.js | nodes/core/hardware/37-mcp3008.js | read | function read(mode,callback) {
if (spi === undefined) {return;};
var txBuf = new Buffer([1,mode,0]);
var rxBuf = new Buffer([0,0,0]);
spi.transfer(txBuf,rxBuf,function(dev,buffer) {
var value = ((buffer[1] & 3)<< 8) + buffer[2];
callback(value);
});
} | javascript | function read(mode,callback) {
if (spi === undefined) {return;};
var txBuf = new Buffer([1,mode,0]);
var rxBuf = new Buffer([0,0,0]);
spi.transfer(txBuf,rxBuf,function(dev,buffer) {
var value = ((buffer[1] & 3)<< 8) + buffer[2];
callback(value);
});
} | [
"function",
"read",
"(",
"mode",
",",
"callback",
")",
"{",
"if",
"(",
"spi",
"===",
"undefined",
")",
"{",
"return",
";",
"}",
";",
"var",
"txBuf",
"=",
"new",
"Buffer",
"(",
"[",
"1",
",",
"mode",
",",
"0",
"]",
")",
";",
"var",
"rxBuf",
"=",
"new",
"Buffer",
"(",
"[",
"0",
",",
"0",
",",
"0",
"]",
")",
";",
"spi",
".",
"transfer",
"(",
"txBuf",
",",
"rxBuf",
",",
"function",
"(",
"dev",
",",
"buffer",
")",
"{",
"var",
"value",
"=",
"(",
"(",
"buffer",
"[",
"1",
"]",
"&",
"3",
")",
"<<",
"8",
")",
"+",
"buffer",
"[",
"2",
"]",
";",
"callback",
"(",
"value",
")",
";",
"}",
")",
";",
"}"
]
| lit l'interface spi | [
"lit",
"l",
"interface",
"spi"
]
| 0d3ea73bce000cb8bd1d10242e427e19ede5745d | https://github.com/Gambiit/mcp3008.js/blob/0d3ea73bce000cb8bd1d10242e427e19ede5745d/nodes/core/hardware/37-mcp3008.js#L31-L40 |
43,327 | ddliu/grunt-push-svn | tasks/push_svn.js | function(callback) {
grunt.log.writeln('Prepare tmp path...');
if (!grunt.file.isDir(tmpPath)) {
if (grunt.file.exists(tmpPath)) {
callback(new Error(util.format('"%s" is not a directory', tmpPath)));
}
else {
grunt.file.mkdir(tmpPath);
callback(null);
}
}
else {
callback(null);
}
} | javascript | function(callback) {
grunt.log.writeln('Prepare tmp path...');
if (!grunt.file.isDir(tmpPath)) {
if (grunt.file.exists(tmpPath)) {
callback(new Error(util.format('"%s" is not a directory', tmpPath)));
}
else {
grunt.file.mkdir(tmpPath);
callback(null);
}
}
else {
callback(null);
}
} | [
"function",
"(",
"callback",
")",
"{",
"grunt",
".",
"log",
".",
"writeln",
"(",
"'Prepare tmp path...'",
")",
";",
"if",
"(",
"!",
"grunt",
".",
"file",
".",
"isDir",
"(",
"tmpPath",
")",
")",
"{",
"if",
"(",
"grunt",
".",
"file",
".",
"exists",
"(",
"tmpPath",
")",
")",
"{",
"callback",
"(",
"new",
"Error",
"(",
"util",
".",
"format",
"(",
"'\"%s\" is not a directory'",
",",
"tmpPath",
")",
")",
")",
";",
"}",
"else",
"{",
"grunt",
".",
"file",
".",
"mkdir",
"(",
"tmpPath",
")",
";",
"callback",
"(",
"null",
")",
";",
"}",
"}",
"else",
"{",
"callback",
"(",
"null",
")",
";",
"}",
"}"
]
| make sure tmpPath exists | [
"make",
"sure",
"tmpPath",
"exists"
]
| 59dc07216fffaf05712d7a4936f2227435a1badf | https://github.com/ddliu/grunt-push-svn/blob/59dc07216fffaf05712d7a4936f2227435a1badf/tasks/push_svn.js#L101-L115 |
|
43,328 | ddliu/grunt-push-svn | tasks/push_svn.js | function(callback) {
grunt.log.writeln('Push to tmp path...');
// remove
if (options.remove) {
grunt.file.recurse(tmpPath, function(abs, rootdir, subdir, filename) {
if (typeof subdir !== 'string') {
subdir = '';
}
var subPath = path.join(subdir, filename);
if (testIgnore(subPath, ['.svn', '.git'])) {
return;
}
if (
!grunt.file.exists(path.join(src, subPath)) &&
!grunt.file.isMatch(options.removeIgnore, subPath)
) {
// remove it
grunt.log.writeln(util.format('Remove "%s"...', subPath));
grunt.file.delete(abs);
}
});
}
// copy
grunt.file.recurse(src, function(abs, rootdir, subdir, filename) {
if (typeof subdir !== 'string') {
subdir = '';
}
var subPath = path.join(subdir, filename),
srcFile = abs,
destFile = path.join(tmpPath, subPath),
srcStats = fs.statSync(srcFile),
destStats;
if (testIgnore(subPath, ['.svn', '.git'])) {
return;
}
if (!options.pushIgnore || !grunt.file.isMatch(options.pushIgnore, subPath)) {
// dir
if (grunt.file.isDir(srcFile)) {
if (!grunt.file.isDir(destFile)) {
if (grunt.file.exists(destFile)) {
grunt.file.delete(destFile);
}
grunt.log.writeln(util.format('Create folder "%s"...', subPath));
grunt.file.mkdir(destFile);
}
}
else {
if (grunt.file.isDir(destFile)) {
grunt.file.delete(destFile);
}
else if (grunt.file.exists(destFile)) {
destStats = fs.statSync(destFile);
if (srcStats.size !== destStats.size || (destStats.mtime - srcStats.mtime !== 0)) {
grunt.log.writeln(util.format('Push changed file "%s"...', subPath));
grunt.file.copy(srcFile, destFile);
fs.utimesSync(destFile, srcStats.atime, srcStats.mtime);
}
}
else {
grunt.log.writeln(util.format('Push new file "%s"...', subPath));
grunt.file.copy(srcFile, destFile);
fs.utimesSync(destFile, srcStats.atime, srcStats.mtime);
}
}
}
});
callback(null);
} | javascript | function(callback) {
grunt.log.writeln('Push to tmp path...');
// remove
if (options.remove) {
grunt.file.recurse(tmpPath, function(abs, rootdir, subdir, filename) {
if (typeof subdir !== 'string') {
subdir = '';
}
var subPath = path.join(subdir, filename);
if (testIgnore(subPath, ['.svn', '.git'])) {
return;
}
if (
!grunt.file.exists(path.join(src, subPath)) &&
!grunt.file.isMatch(options.removeIgnore, subPath)
) {
// remove it
grunt.log.writeln(util.format('Remove "%s"...', subPath));
grunt.file.delete(abs);
}
});
}
// copy
grunt.file.recurse(src, function(abs, rootdir, subdir, filename) {
if (typeof subdir !== 'string') {
subdir = '';
}
var subPath = path.join(subdir, filename),
srcFile = abs,
destFile = path.join(tmpPath, subPath),
srcStats = fs.statSync(srcFile),
destStats;
if (testIgnore(subPath, ['.svn', '.git'])) {
return;
}
if (!options.pushIgnore || !grunt.file.isMatch(options.pushIgnore, subPath)) {
// dir
if (grunt.file.isDir(srcFile)) {
if (!grunt.file.isDir(destFile)) {
if (grunt.file.exists(destFile)) {
grunt.file.delete(destFile);
}
grunt.log.writeln(util.format('Create folder "%s"...', subPath));
grunt.file.mkdir(destFile);
}
}
else {
if (grunt.file.isDir(destFile)) {
grunt.file.delete(destFile);
}
else if (grunt.file.exists(destFile)) {
destStats = fs.statSync(destFile);
if (srcStats.size !== destStats.size || (destStats.mtime - srcStats.mtime !== 0)) {
grunt.log.writeln(util.format('Push changed file "%s"...', subPath));
grunt.file.copy(srcFile, destFile);
fs.utimesSync(destFile, srcStats.atime, srcStats.mtime);
}
}
else {
grunt.log.writeln(util.format('Push new file "%s"...', subPath));
grunt.file.copy(srcFile, destFile);
fs.utimesSync(destFile, srcStats.atime, srcStats.mtime);
}
}
}
});
callback(null);
} | [
"function",
"(",
"callback",
")",
"{",
"grunt",
".",
"log",
".",
"writeln",
"(",
"'Push to tmp path...'",
")",
";",
"// remove",
"if",
"(",
"options",
".",
"remove",
")",
"{",
"grunt",
".",
"file",
".",
"recurse",
"(",
"tmpPath",
",",
"function",
"(",
"abs",
",",
"rootdir",
",",
"subdir",
",",
"filename",
")",
"{",
"if",
"(",
"typeof",
"subdir",
"!==",
"'string'",
")",
"{",
"subdir",
"=",
"''",
";",
"}",
"var",
"subPath",
"=",
"path",
".",
"join",
"(",
"subdir",
",",
"filename",
")",
";",
"if",
"(",
"testIgnore",
"(",
"subPath",
",",
"[",
"'.svn'",
",",
"'.git'",
"]",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"grunt",
".",
"file",
".",
"exists",
"(",
"path",
".",
"join",
"(",
"src",
",",
"subPath",
")",
")",
"&&",
"!",
"grunt",
".",
"file",
".",
"isMatch",
"(",
"options",
".",
"removeIgnore",
",",
"subPath",
")",
")",
"{",
"// remove it",
"grunt",
".",
"log",
".",
"writeln",
"(",
"util",
".",
"format",
"(",
"'Remove \"%s\"...'",
",",
"subPath",
")",
")",
";",
"grunt",
".",
"file",
".",
"delete",
"(",
"abs",
")",
";",
"}",
"}",
")",
";",
"}",
"// copy",
"grunt",
".",
"file",
".",
"recurse",
"(",
"src",
",",
"function",
"(",
"abs",
",",
"rootdir",
",",
"subdir",
",",
"filename",
")",
"{",
"if",
"(",
"typeof",
"subdir",
"!==",
"'string'",
")",
"{",
"subdir",
"=",
"''",
";",
"}",
"var",
"subPath",
"=",
"path",
".",
"join",
"(",
"subdir",
",",
"filename",
")",
",",
"srcFile",
"=",
"abs",
",",
"destFile",
"=",
"path",
".",
"join",
"(",
"tmpPath",
",",
"subPath",
")",
",",
"srcStats",
"=",
"fs",
".",
"statSync",
"(",
"srcFile",
")",
",",
"destStats",
";",
"if",
"(",
"testIgnore",
"(",
"subPath",
",",
"[",
"'.svn'",
",",
"'.git'",
"]",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"options",
".",
"pushIgnore",
"||",
"!",
"grunt",
".",
"file",
".",
"isMatch",
"(",
"options",
".",
"pushIgnore",
",",
"subPath",
")",
")",
"{",
"// dir",
"if",
"(",
"grunt",
".",
"file",
".",
"isDir",
"(",
"srcFile",
")",
")",
"{",
"if",
"(",
"!",
"grunt",
".",
"file",
".",
"isDir",
"(",
"destFile",
")",
")",
"{",
"if",
"(",
"grunt",
".",
"file",
".",
"exists",
"(",
"destFile",
")",
")",
"{",
"grunt",
".",
"file",
".",
"delete",
"(",
"destFile",
")",
";",
"}",
"grunt",
".",
"log",
".",
"writeln",
"(",
"util",
".",
"format",
"(",
"'Create folder \"%s\"...'",
",",
"subPath",
")",
")",
";",
"grunt",
".",
"file",
".",
"mkdir",
"(",
"destFile",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"grunt",
".",
"file",
".",
"isDir",
"(",
"destFile",
")",
")",
"{",
"grunt",
".",
"file",
".",
"delete",
"(",
"destFile",
")",
";",
"}",
"else",
"if",
"(",
"grunt",
".",
"file",
".",
"exists",
"(",
"destFile",
")",
")",
"{",
"destStats",
"=",
"fs",
".",
"statSync",
"(",
"destFile",
")",
";",
"if",
"(",
"srcStats",
".",
"size",
"!==",
"destStats",
".",
"size",
"||",
"(",
"destStats",
".",
"mtime",
"-",
"srcStats",
".",
"mtime",
"!==",
"0",
")",
")",
"{",
"grunt",
".",
"log",
".",
"writeln",
"(",
"util",
".",
"format",
"(",
"'Push changed file \"%s\"...'",
",",
"subPath",
")",
")",
";",
"grunt",
".",
"file",
".",
"copy",
"(",
"srcFile",
",",
"destFile",
")",
";",
"fs",
".",
"utimesSync",
"(",
"destFile",
",",
"srcStats",
".",
"atime",
",",
"srcStats",
".",
"mtime",
")",
";",
"}",
"}",
"else",
"{",
"grunt",
".",
"log",
".",
"writeln",
"(",
"util",
".",
"format",
"(",
"'Push new file \"%s\"...'",
",",
"subPath",
")",
")",
";",
"grunt",
".",
"file",
".",
"copy",
"(",
"srcFile",
",",
"destFile",
")",
";",
"fs",
".",
"utimesSync",
"(",
"destFile",
",",
"srcStats",
".",
"atime",
",",
"srcStats",
".",
"mtime",
")",
";",
"}",
"}",
"}",
"}",
")",
";",
"callback",
"(",
"null",
")",
";",
"}"
]
| sync with tmp working directory | [
"sync",
"with",
"tmp",
"working",
"directory"
]
| 59dc07216fffaf05712d7a4936f2227435a1badf | https://github.com/ddliu/grunt-push-svn/blob/59dc07216fffaf05712d7a4936f2227435a1badf/tasks/push_svn.js#L159-L231 |
|
43,329 | alexindigo/fbbot | traverse/incoming.js | linkParent | function linkParent(original, branch, parentPayload, nextPayload)
{
// get proper name
var normalized = normalize(branch);
var result = original(branch, parentPayload, nextPayload);
// add normalized handle reference
// skip if it's empty string
if (normalized)
{
result.__proto__[normalized] = parentPayload;
}
// add user object reference
if (parentPayload.user)
{
result.__proto__['user'] = parentPayload.user;
}
return result;
} | javascript | function linkParent(original, branch, parentPayload, nextPayload)
{
// get proper name
var normalized = normalize(branch);
var result = original(branch, parentPayload, nextPayload);
// add normalized handle reference
// skip if it's empty string
if (normalized)
{
result.__proto__[normalized] = parentPayload;
}
// add user object reference
if (parentPayload.user)
{
result.__proto__['user'] = parentPayload.user;
}
return result;
} | [
"function",
"linkParent",
"(",
"original",
",",
"branch",
",",
"parentPayload",
",",
"nextPayload",
")",
"{",
"// get proper name",
"var",
"normalized",
"=",
"normalize",
"(",
"branch",
")",
";",
"var",
"result",
"=",
"original",
"(",
"branch",
",",
"parentPayload",
",",
"nextPayload",
")",
";",
"// add normalized handle reference",
"// skip if it's empty string",
"if",
"(",
"normalized",
")",
"{",
"result",
".",
"__proto__",
"[",
"normalized",
"]",
"=",
"parentPayload",
";",
"}",
"// add user object reference",
"if",
"(",
"parentPayload",
".",
"user",
")",
"{",
"result",
".",
"__proto__",
"[",
"'user'",
"]",
"=",
"parentPayload",
".",
"user",
";",
"}",
"return",
"result",
";",
"}"
]
| Wraps original linkParent method
and adds normalized handle reference to the parent object
@param {function} original - original linkParent method
@param {string} branch - current branch of the payload
@param {object} parentPayload - parent payload object
@param {mixed} nextPayload - next step payload object
@returns {mixed} - augmented next step payload object | [
"Wraps",
"original",
"linkParent",
"method",
"and",
"adds",
"normalized",
"handle",
"reference",
"to",
"the",
"parent",
"object"
]
| b78a0418ebdfd106723348d94b4378ac67f7d4bf | https://github.com/alexindigo/fbbot/blob/b78a0418ebdfd106723348d94b4378ac67f7d4bf/traverse/incoming.js#L30-L51 |
43,330 | alexindigo/fbbot | traverse/incoming.js | middleware | function middleware(branch, payload, callback)
{
// get proper name
var normalized = normalize(branch);
this.logger.debug({message: 'Running middleware for incoming payload', branch: branch, normalized: normalized, payload: payload});
// add branch reference to the parent object
// run through all registered middleware
this._run(normalized, payload, function(error, resolvedPayload)
{
var normalizeType;
if (payload.type)
{
normalizeType = normalize(payload.type);
this._run([normalized, normalizeType].join('.'), resolvedPayload, callback);
}
// be done here
else
{
callback(error, resolvedPayload);
}
}.bind(this));
} | javascript | function middleware(branch, payload, callback)
{
// get proper name
var normalized = normalize(branch);
this.logger.debug({message: 'Running middleware for incoming payload', branch: branch, normalized: normalized, payload: payload});
// add branch reference to the parent object
// run through all registered middleware
this._run(normalized, payload, function(error, resolvedPayload)
{
var normalizeType;
if (payload.type)
{
normalizeType = normalize(payload.type);
this._run([normalized, normalizeType].join('.'), resolvedPayload, callback);
}
// be done here
else
{
callback(error, resolvedPayload);
}
}.bind(this));
} | [
"function",
"middleware",
"(",
"branch",
",",
"payload",
",",
"callback",
")",
"{",
"// get proper name",
"var",
"normalized",
"=",
"normalize",
"(",
"branch",
")",
";",
"this",
".",
"logger",
".",
"debug",
"(",
"{",
"message",
":",
"'Running middleware for incoming payload'",
",",
"branch",
":",
"branch",
",",
"normalized",
":",
"normalized",
",",
"payload",
":",
"payload",
"}",
")",
";",
"// add branch reference to the parent object",
"// run through all registered middleware",
"this",
".",
"_run",
"(",
"normalized",
",",
"payload",
",",
"function",
"(",
"error",
",",
"resolvedPayload",
")",
"{",
"var",
"normalizeType",
";",
"if",
"(",
"payload",
".",
"type",
")",
"{",
"normalizeType",
"=",
"normalize",
"(",
"payload",
".",
"type",
")",
";",
"this",
".",
"_run",
"(",
"[",
"normalized",
",",
"normalizeType",
"]",
".",
"join",
"(",
"'.'",
")",
",",
"resolvedPayload",
",",
"callback",
")",
";",
"}",
"// be done here",
"else",
"{",
"callback",
"(",
"error",
",",
"resolvedPayload",
")",
";",
"}",
"}",
".",
"bind",
"(",
"this",
")",
")",
";",
"}"
]
| Traverse middleware for incoming flow
@this Fbbot#
@param {string} branch - branch name of the payload
@param {object} payload - initial payload object from facebook messenger
@param {function} callback - invoked upon error or when all entries were processed | [
"Traverse",
"middleware",
"for",
"incoming",
"flow"
]
| b78a0418ebdfd106723348d94b4378ac67f7d4bf | https://github.com/alexindigo/fbbot/blob/b78a0418ebdfd106723348d94b4378ac67f7d4bf/traverse/incoming.js#L61-L86 |
43,331 | neoziro/smime | index.js | sign | function sign(options, cb) {
return new Promise(function (resolve, reject) {
options = options || {};
if (!options.content)
throw new Error('Invalid content.');
if (!options.key)
throw new Error('Invalid key.');
if (!options.cert)
throw new Error('Invalid certificate.');
var command = util.format(
'openssl smime -sign -text -signer %s -inkey %s -outform DER -binary',
options.cert,
options.key
);
if (options.password)
command += util.format(' -passin pass:%s', options.password);
var args = command.split(' ');
var child = spawn(args[0], args.splice(1));
var der = [];
child.stdout.on('data', function (chunk) {
der.push(chunk);
});
child.on('close', function (code) {
if (code !== 0)
reject(new Error('Process failed.'));
else
resolve({
child: child,
der: Buffer.concat(der)
});
});
options.content.pipe(child.stdin);
})
.nodeify(cb);
} | javascript | function sign(options, cb) {
return new Promise(function (resolve, reject) {
options = options || {};
if (!options.content)
throw new Error('Invalid content.');
if (!options.key)
throw new Error('Invalid key.');
if (!options.cert)
throw new Error('Invalid certificate.');
var command = util.format(
'openssl smime -sign -text -signer %s -inkey %s -outform DER -binary',
options.cert,
options.key
);
if (options.password)
command += util.format(' -passin pass:%s', options.password);
var args = command.split(' ');
var child = spawn(args[0], args.splice(1));
var der = [];
child.stdout.on('data', function (chunk) {
der.push(chunk);
});
child.on('close', function (code) {
if (code !== 0)
reject(new Error('Process failed.'));
else
resolve({
child: child,
der: Buffer.concat(der)
});
});
options.content.pipe(child.stdin);
})
.nodeify(cb);
} | [
"function",
"sign",
"(",
"options",
",",
"cb",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"if",
"(",
"!",
"options",
".",
"content",
")",
"throw",
"new",
"Error",
"(",
"'Invalid content.'",
")",
";",
"if",
"(",
"!",
"options",
".",
"key",
")",
"throw",
"new",
"Error",
"(",
"'Invalid key.'",
")",
";",
"if",
"(",
"!",
"options",
".",
"cert",
")",
"throw",
"new",
"Error",
"(",
"'Invalid certificate.'",
")",
";",
"var",
"command",
"=",
"util",
".",
"format",
"(",
"'openssl smime -sign -text -signer %s -inkey %s -outform DER -binary'",
",",
"options",
".",
"cert",
",",
"options",
".",
"key",
")",
";",
"if",
"(",
"options",
".",
"password",
")",
"command",
"+=",
"util",
".",
"format",
"(",
"' -passin pass:%s'",
",",
"options",
".",
"password",
")",
";",
"var",
"args",
"=",
"command",
".",
"split",
"(",
"' '",
")",
";",
"var",
"child",
"=",
"spawn",
"(",
"args",
"[",
"0",
"]",
",",
"args",
".",
"splice",
"(",
"1",
")",
")",
";",
"var",
"der",
"=",
"[",
"]",
";",
"child",
".",
"stdout",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"chunk",
")",
"{",
"der",
".",
"push",
"(",
"chunk",
")",
";",
"}",
")",
";",
"child",
".",
"on",
"(",
"'close'",
",",
"function",
"(",
"code",
")",
"{",
"if",
"(",
"code",
"!==",
"0",
")",
"reject",
"(",
"new",
"Error",
"(",
"'Process failed.'",
")",
")",
";",
"else",
"resolve",
"(",
"{",
"child",
":",
"child",
",",
"der",
":",
"Buffer",
".",
"concat",
"(",
"der",
")",
"}",
")",
";",
"}",
")",
";",
"options",
".",
"content",
".",
"pipe",
"(",
"child",
".",
"stdin",
")",
";",
"}",
")",
".",
"nodeify",
"(",
"cb",
")",
";",
"}"
]
| Sign a file.
@param {object} options Options
@param {stream.Readable} options.content Content stream
@param {string} options.key Key path
@param {string} options.cert Cert path
@param {string} [options.password] Key password
@param {function} [cb] Optional callback
@returns {object} result Result
@returns {string} result.der Der signature
@returns {ChildProcess} result.child Child process | [
"Sign",
"a",
"file",
"."
]
| 9ada09c5a0a30ef3e8beac3db181f2cbb3602f2c | https://github.com/neoziro/smime/blob/9ada09c5a0a30ef3e8beac3db181f2cbb3602f2c/index.js#L22-L66 |
43,332 | alexindigo/fbbot | lib/attach.js | attach | function attach(filters, instance)
{
Object.keys(filters).forEach(function(step)
{
filters[step].forEach(function(filter)
{
instance.use(step, filter);
});
});
} | javascript | function attach(filters, instance)
{
Object.keys(filters).forEach(function(step)
{
filters[step].forEach(function(filter)
{
instance.use(step, filter);
});
});
} | [
"function",
"attach",
"(",
"filters",
",",
"instance",
")",
"{",
"Object",
".",
"keys",
"(",
"filters",
")",
".",
"forEach",
"(",
"function",
"(",
"step",
")",
"{",
"filters",
"[",
"step",
"]",
".",
"forEach",
"(",
"function",
"(",
"filter",
")",
"{",
"instance",
".",
"use",
"(",
"step",
",",
"filter",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| Attaches list of middleware filters to the provided instance
@param {object} filters - list of filters per step (event)
@param {function} instance - filter instance to attach to an event (step) | [
"Attaches",
"list",
"of",
"middleware",
"filters",
"to",
"the",
"provided",
"instance"
]
| b78a0418ebdfd106723348d94b4378ac67f7d4bf | https://github.com/alexindigo/fbbot/blob/b78a0418ebdfd106723348d94b4378ac67f7d4bf/lib/attach.js#L9-L18 |
43,333 | doochik/react-native-vksdk | index.ios.js | function() {
return new Promise(function(resolve, reject) {
VkSdkLoginManager.authorize(function(error, result) {
if (error) {
reject(error);
} else {
resolve(result);
}
});
});
} | javascript | function() {
return new Promise(function(resolve, reject) {
VkSdkLoginManager.authorize(function(error, result) {
if (error) {
reject(error);
} else {
resolve(result);
}
});
});
} | [
"function",
"(",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"VkSdkLoginManager",
".",
"authorize",
"(",
"function",
"(",
"error",
",",
"result",
")",
"{",
"if",
"(",
"error",
")",
"{",
"reject",
"(",
"error",
")",
";",
"}",
"else",
"{",
"resolve",
"(",
"result",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}"
]
| Starts authorization process to retrieve unlimited token.
If VKapp is available in system, it will opens and requests access from user.
Otherwise Mobile Safari will be opened for access request.
@returns {Promise} | [
"Starts",
"authorization",
"process",
"to",
"retrieve",
"unlimited",
"token",
".",
"If",
"VKapp",
"is",
"available",
"in",
"system",
"it",
"will",
"opens",
"and",
"requests",
"access",
"from",
"user",
".",
"Otherwise",
"Mobile",
"Safari",
"will",
"be",
"opened",
"for",
"access",
"request",
"."
]
| e06494b5a64121eea155414162b6416a0589b58c | https://github.com/doochik/react-native-vksdk/blob/e06494b5a64121eea155414162b6416a0589b58c/index.ios.js#L13-L23 |
|
43,334 | alexindigo/fbbot | lib/pipeline.js | pipeline | function pipeline(list, payload, handler, callback)
{
var item;
if (!list.length)
{
callback(null, payload);
return;
}
list = list.concat();
item = list.shift();
// pipeline it
handler(item, payload, async(function(err, updatedPayload)
{
if (err)
{
callback(err, updatedPayload);
return;
}
// rinse, repeat
pipeline(list, updatedPayload, handler, callback);
}));
} | javascript | function pipeline(list, payload, handler, callback)
{
var item;
if (!list.length)
{
callback(null, payload);
return;
}
list = list.concat();
item = list.shift();
// pipeline it
handler(item, payload, async(function(err, updatedPayload)
{
if (err)
{
callback(err, updatedPayload);
return;
}
// rinse, repeat
pipeline(list, updatedPayload, handler, callback);
}));
} | [
"function",
"pipeline",
"(",
"list",
",",
"payload",
",",
"handler",
",",
"callback",
")",
"{",
"var",
"item",
";",
"if",
"(",
"!",
"list",
".",
"length",
")",
"{",
"callback",
"(",
"null",
",",
"payload",
")",
";",
"return",
";",
"}",
"list",
"=",
"list",
".",
"concat",
"(",
")",
";",
"item",
"=",
"list",
".",
"shift",
"(",
")",
";",
"// pipeline it",
"handler",
"(",
"item",
",",
"payload",
",",
"async",
"(",
"function",
"(",
"err",
",",
"updatedPayload",
")",
"{",
"if",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
",",
"updatedPayload",
")",
";",
"return",
";",
"}",
"// rinse, repeat",
"pipeline",
"(",
"list",
",",
"updatedPayload",
",",
"handler",
",",
"callback",
")",
";",
"}",
")",
")",
";",
"}"
]
| Pipelines provided payload through the list of of item via handler
@param {array} list - items to iterate over
@param {object} payload - object to pass to pass iteratees
@param {function} handler - function to invoke for each item/payload iteration
@param {function} callback - invoked after all item were processed | [
"Pipelines",
"provided",
"payload",
"through",
"the",
"list",
"of",
"of",
"item",
"via",
"handler"
]
| b78a0418ebdfd106723348d94b4378ac67f7d4bf | https://github.com/alexindigo/fbbot/blob/b78a0418ebdfd106723348d94b4378ac67f7d4bf/lib/pipeline.js#L13-L38 |
43,335 | JamesMGreene/qunit-assert-compare | qunit-assert-compare.js | gte | function gte(num1, num2, message) {
var output,
input = {
operand1: num1,
operand2: num2,
expected: 1, // Untrue but... internal usage, so meh!
message: message
},
cleanedInput = _validateAndClean(input),
pushContext = _getPushContext(this);
if (cleanedInput) {
// Array-ify
cleanedInput.expected = [0, 1];
output = _compare(cleanedInput);
pushContext.push(output.result, output.actual, output.expected, output.message);
}
} | javascript | function gte(num1, num2, message) {
var output,
input = {
operand1: num1,
operand2: num2,
expected: 1, // Untrue but... internal usage, so meh!
message: message
},
cleanedInput = _validateAndClean(input),
pushContext = _getPushContext(this);
if (cleanedInput) {
// Array-ify
cleanedInput.expected = [0, 1];
output = _compare(cleanedInput);
pushContext.push(output.result, output.actual, output.expected, output.message);
}
} | [
"function",
"gte",
"(",
"num1",
",",
"num2",
",",
"message",
")",
"{",
"var",
"output",
",",
"input",
"=",
"{",
"operand1",
":",
"num1",
",",
"operand2",
":",
"num2",
",",
"expected",
":",
"1",
",",
"// Untrue but... internal usage, so meh!",
"message",
":",
"message",
"}",
",",
"cleanedInput",
"=",
"_validateAndClean",
"(",
"input",
")",
",",
"pushContext",
"=",
"_getPushContext",
"(",
"this",
")",
";",
"if",
"(",
"cleanedInput",
")",
"{",
"// Array-ify",
"cleanedInput",
".",
"expected",
"=",
"[",
"0",
",",
"1",
"]",
";",
"output",
"=",
"_compare",
"(",
"cleanedInput",
")",
";",
"pushContext",
".",
"push",
"(",
"output",
".",
"result",
",",
"output",
".",
"actual",
",",
"output",
".",
"expected",
",",
"output",
".",
"message",
")",
";",
"}",
"}"
]
| Is `num1` greater than or equal to `num2`?
@example assert.gte(2, 2, "2 is greater than or equal to 2");
@example assert.gte(2, 1, "2 is greater than or equal to 1");
@param Number num1 The actual left operand
@param Number num2 The actual right operand
@param String message (optional) | [
"Is",
"num1",
"greater",
"than",
"or",
"equal",
"to",
"num2",
"?"
]
| 512118ead5a40dd351c766e1b098ab9cf3de3cc4 | https://github.com/JamesMGreene/qunit-assert-compare/blob/512118ead5a40dd351c766e1b098ab9cf3de3cc4/qunit-assert-compare.js#L330-L348 |
43,336 | segmentio/localstorage-retry | lib/store.js | Store | function Store(name, id, keys, optionalEngine) {
this.id = id;
this.name = name;
this.keys = keys || {};
this.engine = optionalEngine || defaultEngine;
} | javascript | function Store(name, id, keys, optionalEngine) {
this.id = id;
this.name = name;
this.keys = keys || {};
this.engine = optionalEngine || defaultEngine;
} | [
"function",
"Store",
"(",
"name",
",",
"id",
",",
"keys",
",",
"optionalEngine",
")",
"{",
"this",
".",
"id",
"=",
"id",
";",
"this",
".",
"name",
"=",
"name",
";",
"this",
".",
"keys",
"=",
"keys",
"||",
"{",
"}",
";",
"this",
".",
"engine",
"=",
"optionalEngine",
"||",
"defaultEngine",
";",
"}"
]
| Store Implementation with dedicated | [
"Store",
"Implementation",
"with",
"dedicated"
]
| 0632fb943fc111b6dbf8f36bff5abc6568ffc65e | https://github.com/segmentio/localstorage-retry/blob/0632fb943fc111b6dbf8f36bff5abc6568ffc65e/lib/store.js#L13-L18 |
43,337 | koistya/gulp-render | index.js | renderToString | function renderToString(page) {
var layout = null, child = null, props = {};
while ((layout = page.type.layout || (page.defaultProps && page.defaultProps.layout))) {
child = React.createElement(page, props, child);
_.extend(props, page.defaultProps);
React.renderToString(React.createElement(page, props, child));
page = layout;
}
return React.renderToString(React.createElement(page, props, child));
} | javascript | function renderToString(page) {
var layout = null, child = null, props = {};
while ((layout = page.type.layout || (page.defaultProps && page.defaultProps.layout))) {
child = React.createElement(page, props, child);
_.extend(props, page.defaultProps);
React.renderToString(React.createElement(page, props, child));
page = layout;
}
return React.renderToString(React.createElement(page, props, child));
} | [
"function",
"renderToString",
"(",
"page",
")",
"{",
"var",
"layout",
"=",
"null",
",",
"child",
"=",
"null",
",",
"props",
"=",
"{",
"}",
";",
"while",
"(",
"(",
"layout",
"=",
"page",
".",
"type",
".",
"layout",
"||",
"(",
"page",
".",
"defaultProps",
"&&",
"page",
".",
"defaultProps",
".",
"layout",
")",
")",
")",
"{",
"child",
"=",
"React",
".",
"createElement",
"(",
"page",
",",
"props",
",",
"child",
")",
";",
"_",
".",
"extend",
"(",
"props",
",",
"page",
".",
"defaultProps",
")",
";",
"React",
".",
"renderToString",
"(",
"React",
".",
"createElement",
"(",
"page",
",",
"props",
",",
"child",
")",
")",
";",
"page",
"=",
"layout",
";",
"}",
"return",
"React",
".",
"renderToString",
"(",
"React",
".",
"createElement",
"(",
"page",
",",
"props",
",",
"child",
")",
")",
";",
"}"
]
| Check if Page component has a layout property; and if yes, wrap the page
into the specified layout, then render to a string. | [
"Check",
"if",
"Page",
"component",
"has",
"a",
"layout",
"property",
";",
"and",
"if",
"yes",
"wrap",
"the",
"page",
"into",
"the",
"specified",
"layout",
"then",
"render",
"to",
"a",
"string",
"."
]
| 97e69fd5c1c7c02017cb6597fe9c5dcc620ed92f | https://github.com/koistya/gulp-render/blob/97e69fd5c1c7c02017cb6597fe9c5dcc620ed92f/index.js#L38-L47 |
43,338 | mysidewalk/jsonapi-parse | dist/jsonapi.js | deserialize | function deserialize(json) {
var data, deserialized;
var includedMap = {};
each(json.included, function(value) {
var key = value.type + '-' + value.id;
includedMap[key] = value;
});
if (isArray(json.data)) {
data = map(
json.data,
function(record) {
populateRelatedFields(record, includedMap);
return flatten(record);
}
);
}
else if (isObject(json.data)) {
populateRelatedFields(json.data, includedMap);
data = flatten(json.data);
}
deserialized = {
data: data,
jsonapi: json.jsonapi || {}
};
if (json.meta) {
deserialized.meta = json.meta;
}
if (json.errors) {
deserialized.errors = json.errors;
}
if (json.links) {
deserialized.links = json.links;
}
return deserialized;
} | javascript | function deserialize(json) {
var data, deserialized;
var includedMap = {};
each(json.included, function(value) {
var key = value.type + '-' + value.id;
includedMap[key] = value;
});
if (isArray(json.data)) {
data = map(
json.data,
function(record) {
populateRelatedFields(record, includedMap);
return flatten(record);
}
);
}
else if (isObject(json.data)) {
populateRelatedFields(json.data, includedMap);
data = flatten(json.data);
}
deserialized = {
data: data,
jsonapi: json.jsonapi || {}
};
if (json.meta) {
deserialized.meta = json.meta;
}
if (json.errors) {
deserialized.errors = json.errors;
}
if (json.links) {
deserialized.links = json.links;
}
return deserialized;
} | [
"function",
"deserialize",
"(",
"json",
")",
"{",
"var",
"data",
",",
"deserialized",
";",
"var",
"includedMap",
"=",
"{",
"}",
";",
"each",
"(",
"json",
".",
"included",
",",
"function",
"(",
"value",
")",
"{",
"var",
"key",
"=",
"value",
".",
"type",
"+",
"'-'",
"+",
"value",
".",
"id",
";",
"includedMap",
"[",
"key",
"]",
"=",
"value",
";",
"}",
")",
";",
"if",
"(",
"isArray",
"(",
"json",
".",
"data",
")",
")",
"{",
"data",
"=",
"map",
"(",
"json",
".",
"data",
",",
"function",
"(",
"record",
")",
"{",
"populateRelatedFields",
"(",
"record",
",",
"includedMap",
")",
";",
"return",
"flatten",
"(",
"record",
")",
";",
"}",
")",
";",
"}",
"else",
"if",
"(",
"isObject",
"(",
"json",
".",
"data",
")",
")",
"{",
"populateRelatedFields",
"(",
"json",
".",
"data",
",",
"includedMap",
")",
";",
"data",
"=",
"flatten",
"(",
"json",
".",
"data",
")",
";",
"}",
"deserialized",
"=",
"{",
"data",
":",
"data",
",",
"jsonapi",
":",
"json",
".",
"jsonapi",
"||",
"{",
"}",
"}",
";",
"if",
"(",
"json",
".",
"meta",
")",
"{",
"deserialized",
".",
"meta",
"=",
"json",
".",
"meta",
";",
"}",
"if",
"(",
"json",
".",
"errors",
")",
"{",
"deserialized",
".",
"errors",
"=",
"json",
".",
"errors",
";",
"}",
"if",
"(",
"json",
".",
"links",
")",
"{",
"deserialized",
".",
"links",
"=",
"json",
".",
"links",
";",
"}",
"return",
"deserialized",
";",
"}"
]
| Deserialize the JSONAPI formatted object | [
"Deserialize",
"the",
"JSONAPI",
"formatted",
"object"
]
| caf8437908586d649756e6e3e4ee444e78a66cf7 | https://github.com/mysidewalk/jsonapi-parse/blob/caf8437908586d649756e6e3e4ee444e78a66cf7/dist/jsonapi.js#L48-L89 |
43,339 | mysidewalk/jsonapi-parse | dist/jsonapi.js | populateRelatedFields | function populateRelatedFields(record, includedMap, parents) {
// IF: Object has relationships, update so this record is listed as a parent
if (record.relationships) {
parents = parents ? parents.concat([record]) : [record] ;
}
each(
record.relationships,
function(relationship, property) {
// IF: relationship describes non-record specific meta;
// append relationship meta to the record
if (relationship && isObject(relationship.meta)) {
record.meta = record.meta || {};
record.meta[property] = relationship.meta;
}
// IF: No relationship data, don't add anything
if (!relationship.data) {
return;
}
// IF: Relationship has multiple matches, create an array for matched records
// ELSE: Assign relationship directly to the property
if (isArray(relationship.data)) {
record.attributes[property] = map(
relationship.data,
function(data) {
return getMatchingRecord(data, includedMap, parents);
}
);
}
else {
record.attributes[property] = getMatchingRecord(
relationship.data,
includedMap,
parents
);
}
}
);
} | javascript | function populateRelatedFields(record, includedMap, parents) {
// IF: Object has relationships, update so this record is listed as a parent
if (record.relationships) {
parents = parents ? parents.concat([record]) : [record] ;
}
each(
record.relationships,
function(relationship, property) {
// IF: relationship describes non-record specific meta;
// append relationship meta to the record
if (relationship && isObject(relationship.meta)) {
record.meta = record.meta || {};
record.meta[property] = relationship.meta;
}
// IF: No relationship data, don't add anything
if (!relationship.data) {
return;
}
// IF: Relationship has multiple matches, create an array for matched records
// ELSE: Assign relationship directly to the property
if (isArray(relationship.data)) {
record.attributes[property] = map(
relationship.data,
function(data) {
return getMatchingRecord(data, includedMap, parents);
}
);
}
else {
record.attributes[property] = getMatchingRecord(
relationship.data,
includedMap,
parents
);
}
}
);
} | [
"function",
"populateRelatedFields",
"(",
"record",
",",
"includedMap",
",",
"parents",
")",
"{",
"// IF: Object has relationships, update so this record is listed as a parent",
"if",
"(",
"record",
".",
"relationships",
")",
"{",
"parents",
"=",
"parents",
"?",
"parents",
".",
"concat",
"(",
"[",
"record",
"]",
")",
":",
"[",
"record",
"]",
";",
"}",
"each",
"(",
"record",
".",
"relationships",
",",
"function",
"(",
"relationship",
",",
"property",
")",
"{",
"// IF: relationship describes non-record specific meta;",
"// append relationship meta to the record",
"if",
"(",
"relationship",
"&&",
"isObject",
"(",
"relationship",
".",
"meta",
")",
")",
"{",
"record",
".",
"meta",
"=",
"record",
".",
"meta",
"||",
"{",
"}",
";",
"record",
".",
"meta",
"[",
"property",
"]",
"=",
"relationship",
".",
"meta",
";",
"}",
"// IF: No relationship data, don't add anything",
"if",
"(",
"!",
"relationship",
".",
"data",
")",
"{",
"return",
";",
"}",
"// IF: Relationship has multiple matches, create an array for matched records",
"// ELSE: Assign relationship directly to the property",
"if",
"(",
"isArray",
"(",
"relationship",
".",
"data",
")",
")",
"{",
"record",
".",
"attributes",
"[",
"property",
"]",
"=",
"map",
"(",
"relationship",
".",
"data",
",",
"function",
"(",
"data",
")",
"{",
"return",
"getMatchingRecord",
"(",
"data",
",",
"includedMap",
",",
"parents",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"record",
".",
"attributes",
"[",
"property",
"]",
"=",
"getMatchingRecord",
"(",
"relationship",
".",
"data",
",",
"includedMap",
",",
"parents",
")",
";",
"}",
"}",
")",
";",
"}"
]
| Populate relations of the provided record from the included objects | [
"Populate",
"relations",
"of",
"the",
"provided",
"record",
"from",
"the",
"included",
"objects"
]
| caf8437908586d649756e6e3e4ee444e78a66cf7 | https://github.com/mysidewalk/jsonapi-parse/blob/caf8437908586d649756e6e3e4ee444e78a66cf7/dist/jsonapi.js#L92-L133 |
43,340 | mysidewalk/jsonapi-parse | dist/jsonapi.js | getMatchingRecord | function getMatchingRecord(relationship, included, parents) {
var circular, match;
circular = findWhere(
parents,
{
id: relationship.id,
type: relationship.type
}
);
if (circular) {
return relationship;
}
var key = relationship.type + '-' + relationship.id;
match = included[key];
// IF: No match or match is the same as parent, return the relationship information
if (!match) {
return relationship;
}
populateRelatedFields(match, included, parents);
// IF: relationship defined meta, merge with record provided meta
var contextSpecificMeta = {};
if (relationship && isObject(relationship.meta)) {
contextSpecificMeta = extend({}, match.meta, relationship.meta);
}
return flatten(match, contextSpecificMeta);
} | javascript | function getMatchingRecord(relationship, included, parents) {
var circular, match;
circular = findWhere(
parents,
{
id: relationship.id,
type: relationship.type
}
);
if (circular) {
return relationship;
}
var key = relationship.type + '-' + relationship.id;
match = included[key];
// IF: No match or match is the same as parent, return the relationship information
if (!match) {
return relationship;
}
populateRelatedFields(match, included, parents);
// IF: relationship defined meta, merge with record provided meta
var contextSpecificMeta = {};
if (relationship && isObject(relationship.meta)) {
contextSpecificMeta = extend({}, match.meta, relationship.meta);
}
return flatten(match, contextSpecificMeta);
} | [
"function",
"getMatchingRecord",
"(",
"relationship",
",",
"included",
",",
"parents",
")",
"{",
"var",
"circular",
",",
"match",
";",
"circular",
"=",
"findWhere",
"(",
"parents",
",",
"{",
"id",
":",
"relationship",
".",
"id",
",",
"type",
":",
"relationship",
".",
"type",
"}",
")",
";",
"if",
"(",
"circular",
")",
"{",
"return",
"relationship",
";",
"}",
"var",
"key",
"=",
"relationship",
".",
"type",
"+",
"'-'",
"+",
"relationship",
".",
"id",
";",
"match",
"=",
"included",
"[",
"key",
"]",
";",
"// IF: No match or match is the same as parent, return the relationship information",
"if",
"(",
"!",
"match",
")",
"{",
"return",
"relationship",
";",
"}",
"populateRelatedFields",
"(",
"match",
",",
"included",
",",
"parents",
")",
";",
"// IF: relationship defined meta, merge with record provided meta",
"var",
"contextSpecificMeta",
"=",
"{",
"}",
";",
"if",
"(",
"relationship",
"&&",
"isObject",
"(",
"relationship",
".",
"meta",
")",
")",
"{",
"contextSpecificMeta",
"=",
"extend",
"(",
"{",
"}",
",",
"match",
".",
"meta",
",",
"relationship",
".",
"meta",
")",
";",
"}",
"return",
"flatten",
"(",
"match",
",",
"contextSpecificMeta",
")",
";",
"}"
]
| Retrieves the record from the included objects that matches the provided relationship | [
"Retrieves",
"the",
"record",
"from",
"the",
"included",
"objects",
"that",
"matches",
"the",
"provided",
"relationship"
]
| caf8437908586d649756e6e3e4ee444e78a66cf7 | https://github.com/mysidewalk/jsonapi-parse/blob/caf8437908586d649756e6e3e4ee444e78a66cf7/dist/jsonapi.js#L136-L168 |
43,341 | mysidewalk/jsonapi-parse | dist/jsonapi.js | flatten | function flatten(record, extraMeta) {
var meta = extend({}, record.meta, extraMeta)
return extend(
{},
{ links: record.links, meta: meta },
record.attributes,
{ id: record.id, type: record.type }
);
} | javascript | function flatten(record, extraMeta) {
var meta = extend({}, record.meta, extraMeta)
return extend(
{},
{ links: record.links, meta: meta },
record.attributes,
{ id: record.id, type: record.type }
);
} | [
"function",
"flatten",
"(",
"record",
",",
"extraMeta",
")",
"{",
"var",
"meta",
"=",
"extend",
"(",
"{",
"}",
",",
"record",
".",
"meta",
",",
"extraMeta",
")",
"return",
"extend",
"(",
"{",
"}",
",",
"{",
"links",
":",
"record",
".",
"links",
",",
"meta",
":",
"meta",
"}",
",",
"record",
".",
"attributes",
",",
"{",
"id",
":",
"record",
".",
"id",
",",
"type",
":",
"record",
".",
"type",
"}",
")",
";",
"}"
]
| Flatten the ID of an object with the rest of the attributes on a new object | [
"Flatten",
"the",
"ID",
"of",
"an",
"object",
"with",
"the",
"rest",
"of",
"the",
"attributes",
"on",
"a",
"new",
"object"
]
| caf8437908586d649756e6e3e4ee444e78a66cf7 | https://github.com/mysidewalk/jsonapi-parse/blob/caf8437908586d649756e6e3e4ee444e78a66cf7/dist/jsonapi.js#L171-L179 |
43,342 | marijnh/getdocs | src/index.js | extend | function extend(from, to, path, overrideLoc) {
for (var prop in from) {
if (!(prop in to) || (prop == "loc" && overrideLoc)) {
to[prop] = from[prop]
} else if (prop == "properties" || prop == "staticProperties") {
extend(from[prop], to[prop], path.concat(prop))
} else {
var msg = "Conflicting information for " + path.join(".") + "." + prop
if (to.loc) msg += " at " + to.loc.file + ":" + to.loc.line
if (from.loc) msg += (to.loc ? " and " : " at ") + from.loc.file + ":" + from.loc.line
throw new SyntaxError(msg)
}
}
return to
} | javascript | function extend(from, to, path, overrideLoc) {
for (var prop in from) {
if (!(prop in to) || (prop == "loc" && overrideLoc)) {
to[prop] = from[prop]
} else if (prop == "properties" || prop == "staticProperties") {
extend(from[prop], to[prop], path.concat(prop))
} else {
var msg = "Conflicting information for " + path.join(".") + "." + prop
if (to.loc) msg += " at " + to.loc.file + ":" + to.loc.line
if (from.loc) msg += (to.loc ? " and " : " at ") + from.loc.file + ":" + from.loc.line
throw new SyntaxError(msg)
}
}
return to
} | [
"function",
"extend",
"(",
"from",
",",
"to",
",",
"path",
",",
"overrideLoc",
")",
"{",
"for",
"(",
"var",
"prop",
"in",
"from",
")",
"{",
"if",
"(",
"!",
"(",
"prop",
"in",
"to",
")",
"||",
"(",
"prop",
"==",
"\"loc\"",
"&&",
"overrideLoc",
")",
")",
"{",
"to",
"[",
"prop",
"]",
"=",
"from",
"[",
"prop",
"]",
"}",
"else",
"if",
"(",
"prop",
"==",
"\"properties\"",
"||",
"prop",
"==",
"\"staticProperties\"",
")",
"{",
"extend",
"(",
"from",
"[",
"prop",
"]",
",",
"to",
"[",
"prop",
"]",
",",
"path",
".",
"concat",
"(",
"prop",
")",
")",
"}",
"else",
"{",
"var",
"msg",
"=",
"\"Conflicting information for \"",
"+",
"path",
".",
"join",
"(",
"\".\"",
")",
"+",
"\".\"",
"+",
"prop",
"if",
"(",
"to",
".",
"loc",
")",
"msg",
"+=",
"\" at \"",
"+",
"to",
".",
"loc",
".",
"file",
"+",
"\":\"",
"+",
"to",
".",
"loc",
".",
"line",
"if",
"(",
"from",
".",
"loc",
")",
"msg",
"+=",
"(",
"to",
".",
"loc",
"?",
"\" and \"",
":",
"\" at \"",
")",
"+",
"from",
".",
"loc",
".",
"file",
"+",
"\":\"",
"+",
"from",
".",
"loc",
".",
"line",
"throw",
"new",
"SyntaxError",
"(",
"msg",
")",
"}",
"}",
"return",
"to",
"}"
]
| Deriving context from ancestor nodes | [
"Deriving",
"context",
"from",
"ancestor",
"nodes"
]
| 74181d582e041013cb742d057bf53801358b4d93 | https://github.com/marijnh/getdocs/blob/74181d582e041013cb742d057bf53801358b4d93/src/index.js#L283-L297 |
43,343 | lmangani/parsip | lib/Parser.js | getHeader | function getHeader(data, headerStart)
{
// 'start' position of the header.
let start = headerStart;
// 'end' position of the header.
let end = 0;
// 'partial end' position of the header.
let partialEnd = 0;
// End of message.
if (data.substring(start, start + 2).match(/(^\r\n)/))
{
return -2;
}
while (end === 0)
{
// Partial End of Header.
partialEnd = data.indexOf('\r\n', start);
// 'indexOf' returns -1 if the value to be found never occurs.
if (partialEnd === -1)
{
return partialEnd;
}
if (!data.substring(partialEnd + 2, partialEnd + 4).match(/(^\r\n)/) && data.charAt(partialEnd + 2).match(/(^\s+)/))
{
// Not the end of the message. Continue from the next position.
start = partialEnd + 2;
}
else
{
end = partialEnd;
}
}
return end;
} | javascript | function getHeader(data, headerStart)
{
// 'start' position of the header.
let start = headerStart;
// 'end' position of the header.
let end = 0;
// 'partial end' position of the header.
let partialEnd = 0;
// End of message.
if (data.substring(start, start + 2).match(/(^\r\n)/))
{
return -2;
}
while (end === 0)
{
// Partial End of Header.
partialEnd = data.indexOf('\r\n', start);
// 'indexOf' returns -1 if the value to be found never occurs.
if (partialEnd === -1)
{
return partialEnd;
}
if (!data.substring(partialEnd + 2, partialEnd + 4).match(/(^\r\n)/) && data.charAt(partialEnd + 2).match(/(^\s+)/))
{
// Not the end of the message. Continue from the next position.
start = partialEnd + 2;
}
else
{
end = partialEnd;
}
}
return end;
} | [
"function",
"getHeader",
"(",
"data",
",",
"headerStart",
")",
"{",
"// 'start' position of the header.",
"let",
"start",
"=",
"headerStart",
";",
"// 'end' position of the header.",
"let",
"end",
"=",
"0",
";",
"// 'partial end' position of the header.",
"let",
"partialEnd",
"=",
"0",
";",
"// End of message.",
"if",
"(",
"data",
".",
"substring",
"(",
"start",
",",
"start",
"+",
"2",
")",
".",
"match",
"(",
"/",
"(^\\r\\n)",
"/",
")",
")",
"{",
"return",
"-",
"2",
";",
"}",
"while",
"(",
"end",
"===",
"0",
")",
"{",
"// Partial End of Header.",
"partialEnd",
"=",
"data",
".",
"indexOf",
"(",
"'\\r\\n'",
",",
"start",
")",
";",
"// 'indexOf' returns -1 if the value to be found never occurs.",
"if",
"(",
"partialEnd",
"===",
"-",
"1",
")",
"{",
"return",
"partialEnd",
";",
"}",
"if",
"(",
"!",
"data",
".",
"substring",
"(",
"partialEnd",
"+",
"2",
",",
"partialEnd",
"+",
"4",
")",
".",
"match",
"(",
"/",
"(^\\r\\n)",
"/",
")",
"&&",
"data",
".",
"charAt",
"(",
"partialEnd",
"+",
"2",
")",
".",
"match",
"(",
"/",
"(^\\s+)",
"/",
")",
")",
"{",
"// Not the end of the message. Continue from the next position.",
"start",
"=",
"partialEnd",
"+",
"2",
";",
"}",
"else",
"{",
"end",
"=",
"partialEnd",
";",
"}",
"}",
"return",
"end",
";",
"}"
]
| Extract and parse every header of a SIP message. | [
"Extract",
"and",
"parse",
"every",
"header",
"of",
"a",
"SIP",
"message",
"."
]
| fa1fd873199e9933ed56124760c564c8e6c571d7 | https://github.com/lmangani/parsip/blob/fa1fd873199e9933ed56124760c564c8e6c571d7/lib/Parser.js#L103-L141 |
43,344 | adplabs/JQL | lib/JQL.js | find | function find(prefix, suffix)
{
if(valStack.length > 0)
{
var currentVal = valStack[valStack.length - 1];
if(prefix.length > 0)
{
// Manipulate prefix and suffix
var currentField = prefix.shift();
suffix.push(currentField);
if(currentVal.hasOwnProperty(currentField))
{
if(prefix.length > 0)
{
valStack.push(currentVal[currentField]);
find(prefix, suffix);
valStack.pop();
}
else
{
//finalResults.push(currentVal[currentField]);
store(suffix, currentVal[currentField]);
}
}
else if(currentField == "$")
{
find(prefix, suffix);
}
else if(currentField == "*")
{
findInEachChild(prefix, suffix);
}
else if(currentField == "^")
{
findInParent(prefix, suffix);
}
else if(currentField == "~")
{
findInAllDescendants(prefix, suffix);
}
else if(currentField.indexOf(",") >= 0)
{
findMultiple(prefix, suffix);
}
else if(currentField.substr(0, 1) == "?")
{
findByCondition(currentField.replace(/^\?\((.*?)\)$/,"$1"), prefix, suffix);
}
else
{
// alert("Property not found");
// NOOP
}
// Restore prefix and suffix
prefix.unshift(suffix.pop());
}
else
{
// alert("prefix is empty!");
//finalResults.push(currentVal);
store(suffix, currentVal);
}
}
else
{
// alert("valStack is empty!");
// NOOP
}
} | javascript | function find(prefix, suffix)
{
if(valStack.length > 0)
{
var currentVal = valStack[valStack.length - 1];
if(prefix.length > 0)
{
// Manipulate prefix and suffix
var currentField = prefix.shift();
suffix.push(currentField);
if(currentVal.hasOwnProperty(currentField))
{
if(prefix.length > 0)
{
valStack.push(currentVal[currentField]);
find(prefix, suffix);
valStack.pop();
}
else
{
//finalResults.push(currentVal[currentField]);
store(suffix, currentVal[currentField]);
}
}
else if(currentField == "$")
{
find(prefix, suffix);
}
else if(currentField == "*")
{
findInEachChild(prefix, suffix);
}
else if(currentField == "^")
{
findInParent(prefix, suffix);
}
else if(currentField == "~")
{
findInAllDescendants(prefix, suffix);
}
else if(currentField.indexOf(",") >= 0)
{
findMultiple(prefix, suffix);
}
else if(currentField.substr(0, 1) == "?")
{
findByCondition(currentField.replace(/^\?\((.*?)\)$/,"$1"), prefix, suffix);
}
else
{
// alert("Property not found");
// NOOP
}
// Restore prefix and suffix
prefix.unshift(suffix.pop());
}
else
{
// alert("prefix is empty!");
//finalResults.push(currentVal);
store(suffix, currentVal);
}
}
else
{
// alert("valStack is empty!");
// NOOP
}
} | [
"function",
"find",
"(",
"prefix",
",",
"suffix",
")",
"{",
"if",
"(",
"valStack",
".",
"length",
">",
"0",
")",
"{",
"var",
"currentVal",
"=",
"valStack",
"[",
"valStack",
".",
"length",
"-",
"1",
"]",
";",
"if",
"(",
"prefix",
".",
"length",
">",
"0",
")",
"{",
"// Manipulate prefix and suffix",
"var",
"currentField",
"=",
"prefix",
".",
"shift",
"(",
")",
";",
"suffix",
".",
"push",
"(",
"currentField",
")",
";",
"if",
"(",
"currentVal",
".",
"hasOwnProperty",
"(",
"currentField",
")",
")",
"{",
"if",
"(",
"prefix",
".",
"length",
">",
"0",
")",
"{",
"valStack",
".",
"push",
"(",
"currentVal",
"[",
"currentField",
"]",
")",
";",
"find",
"(",
"prefix",
",",
"suffix",
")",
";",
"valStack",
".",
"pop",
"(",
")",
";",
"}",
"else",
"{",
"//finalResults.push(currentVal[currentField]);",
"store",
"(",
"suffix",
",",
"currentVal",
"[",
"currentField",
"]",
")",
";",
"}",
"}",
"else",
"if",
"(",
"currentField",
"==",
"\"$\"",
")",
"{",
"find",
"(",
"prefix",
",",
"suffix",
")",
";",
"}",
"else",
"if",
"(",
"currentField",
"==",
"\"*\"",
")",
"{",
"findInEachChild",
"(",
"prefix",
",",
"suffix",
")",
";",
"}",
"else",
"if",
"(",
"currentField",
"==",
"\"^\"",
")",
"{",
"findInParent",
"(",
"prefix",
",",
"suffix",
")",
";",
"}",
"else",
"if",
"(",
"currentField",
"==",
"\"~\"",
")",
"{",
"findInAllDescendants",
"(",
"prefix",
",",
"suffix",
")",
";",
"}",
"else",
"if",
"(",
"currentField",
".",
"indexOf",
"(",
"\",\"",
")",
">=",
"0",
")",
"{",
"findMultiple",
"(",
"prefix",
",",
"suffix",
")",
";",
"}",
"else",
"if",
"(",
"currentField",
".",
"substr",
"(",
"0",
",",
"1",
")",
"==",
"\"?\"",
")",
"{",
"findByCondition",
"(",
"currentField",
".",
"replace",
"(",
"/",
"^\\?\\((.*?)\\)$",
"/",
",",
"\"$1\"",
")",
",",
"prefix",
",",
"suffix",
")",
";",
"}",
"else",
"{",
"// alert(\"Property not found\");",
"// NOOP",
"}",
"// Restore prefix and suffix",
"prefix",
".",
"unshift",
"(",
"suffix",
".",
"pop",
"(",
")",
")",
";",
"}",
"else",
"{",
"// alert(\"prefix is empty!\");",
"//finalResults.push(currentVal);",
"store",
"(",
"suffix",
",",
"currentVal",
")",
";",
"}",
"}",
"else",
"{",
"// alert(\"valStack is empty!\");",
"// NOOP",
"}",
"}"
]
| This is the foundation of all searching in JQL; it chooses specific search types based upon the current part of the JQL string
@private
@param {Array} prefix - Initial part of path
@param {Array} suffix - Final part of path | [
"This",
"is",
"the",
"foundation",
"of",
"all",
"searching",
"in",
"JQL",
";",
"it",
"chooses",
"specific",
"search",
"types",
"based",
"upon",
"the",
"current",
"part",
"of",
"the",
"JQL",
"string"
]
| f4e63693c599dd9ad614327c8ca487b9ca576ffd | https://github.com/adplabs/JQL/blob/f4e63693c599dd9ad614327c8ca487b9ca576ffd/lib/JQL.js#L449-L520 |
43,345 | kengz/telegram-bot-bootstrap | API.js | function(token) {
this.token = token;
this.baseUrl = 'https://api.telegram.org/bot' + this.token;
// A sample Telegram bot JSON data, for req options
this.formData = {
chat_id: "87654321",
text: "Hello there"
};
// template options for req the Telegram Bot API
this.baseoptions = {
method: 'POST',
baseUrl: this.baseUrl,
url: "sendMessage",
formData: this.formData
};
///////////////////////////////
// Internal, private methods //
///////////////////////////////
// Convert an data to format proper for HTTP methods
this.toHTTPProper = function(data) {
// currently serialize Array now, leave stream/string
return _.isArray(data) ? JSON.stringify(data) : data;
// return data;
}
// serialize a whole object proper for HTTP methods
// discard key-value pair if value is undefined
// only returns non-empty JSON
this.serialize = function(obj) {
// var ser = _.omit(
// _.mapValues(_.flattenJSON(obj), this.toHTTPProper)
// , _.isUndefined);
var ser = _.omit(
_.mapValues(obj, this.toHTTPProper)
, _.isUndefined);
if (!_.isEmpty(ser)) return ser;
}
// properly set req as its method
this.req = req;
// Extends the options for req for the Telegram Bot.
// @param {string} botMethod Telegram bot API method.
// @param {JSON} JSONdata A JSON object with the required fields (see API).
// @param {string} [HTTPMethod=POST] Optionally change method if need to.
// @returns {JSON} option The extended option.
//
// @example
// extOpt('sendMessage', {chat_id: 123456, text: 'hello world'})
// → {
// method: 'POST',
// baseUrl: 'https://api.telegram.org/bot...',
// url: 'sendMessage',
// formData: {chat_id: 123456, text: 'hello world'} }
this.extOpt = function(botMethod, JSONdata, HTTPMethod) {
var opt = _.clone({
method: 'POST',
baseUrl: this.baseUrl,
url: "sendMessage",
formData: this.formData
});
_.assign(opt, {
url: botMethod
})
if (JSONdata) _.assign(opt, {
formData: this.serialize(JSONdata)
})
if (HTTPMethod) _.assign(opt, {
botMethod: HTTPMethod
});
return opt;
}
// shorthand composition: bot's HTTP request
this.reqBot = _.flow(this.extOpt, this.req)
} | javascript | function(token) {
this.token = token;
this.baseUrl = 'https://api.telegram.org/bot' + this.token;
// A sample Telegram bot JSON data, for req options
this.formData = {
chat_id: "87654321",
text: "Hello there"
};
// template options for req the Telegram Bot API
this.baseoptions = {
method: 'POST',
baseUrl: this.baseUrl,
url: "sendMessage",
formData: this.formData
};
///////////////////////////////
// Internal, private methods //
///////////////////////////////
// Convert an data to format proper for HTTP methods
this.toHTTPProper = function(data) {
// currently serialize Array now, leave stream/string
return _.isArray(data) ? JSON.stringify(data) : data;
// return data;
}
// serialize a whole object proper for HTTP methods
// discard key-value pair if value is undefined
// only returns non-empty JSON
this.serialize = function(obj) {
// var ser = _.omit(
// _.mapValues(_.flattenJSON(obj), this.toHTTPProper)
// , _.isUndefined);
var ser = _.omit(
_.mapValues(obj, this.toHTTPProper)
, _.isUndefined);
if (!_.isEmpty(ser)) return ser;
}
// properly set req as its method
this.req = req;
// Extends the options for req for the Telegram Bot.
// @param {string} botMethod Telegram bot API method.
// @param {JSON} JSONdata A JSON object with the required fields (see API).
// @param {string} [HTTPMethod=POST] Optionally change method if need to.
// @returns {JSON} option The extended option.
//
// @example
// extOpt('sendMessage', {chat_id: 123456, text: 'hello world'})
// → {
// method: 'POST',
// baseUrl: 'https://api.telegram.org/bot...',
// url: 'sendMessage',
// formData: {chat_id: 123456, text: 'hello world'} }
this.extOpt = function(botMethod, JSONdata, HTTPMethod) {
var opt = _.clone({
method: 'POST',
baseUrl: this.baseUrl,
url: "sendMessage",
formData: this.formData
});
_.assign(opt, {
url: botMethod
})
if (JSONdata) _.assign(opt, {
formData: this.serialize(JSONdata)
})
if (HTTPMethod) _.assign(opt, {
botMethod: HTTPMethod
});
return opt;
}
// shorthand composition: bot's HTTP request
this.reqBot = _.flow(this.extOpt, this.req)
} | [
"function",
"(",
"token",
")",
"{",
"this",
".",
"token",
"=",
"token",
";",
"this",
".",
"baseUrl",
"=",
"'https://api.telegram.org/bot'",
"+",
"this",
".",
"token",
";",
"// A sample Telegram bot JSON data, for req options",
"this",
".",
"formData",
"=",
"{",
"chat_id",
":",
"\"87654321\"",
",",
"text",
":",
"\"Hello there\"",
"}",
";",
"// template options for req the Telegram Bot API",
"this",
".",
"baseoptions",
"=",
"{",
"method",
":",
"'POST'",
",",
"baseUrl",
":",
"this",
".",
"baseUrl",
",",
"url",
":",
"\"sendMessage\"",
",",
"formData",
":",
"this",
".",
"formData",
"}",
";",
"///////////////////////////////",
"// Internal, private methods //",
"///////////////////////////////",
"// Convert an data to format proper for HTTP methods",
"this",
".",
"toHTTPProper",
"=",
"function",
"(",
"data",
")",
"{",
"// currently serialize Array now, leave stream/string",
"return",
"_",
".",
"isArray",
"(",
"data",
")",
"?",
"JSON",
".",
"stringify",
"(",
"data",
")",
":",
"data",
";",
"// return data;",
"}",
"// serialize a whole object proper for HTTP methods",
"// discard key-value pair if value is undefined",
"// only returns non-empty JSON",
"this",
".",
"serialize",
"=",
"function",
"(",
"obj",
")",
"{",
"// var ser = _.omit(",
"// _.mapValues(_.flattenJSON(obj), this.toHTTPProper)",
"// , _.isUndefined);",
"var",
"ser",
"=",
"_",
".",
"omit",
"(",
"_",
".",
"mapValues",
"(",
"obj",
",",
"this",
".",
"toHTTPProper",
")",
",",
"_",
".",
"isUndefined",
")",
";",
"if",
"(",
"!",
"_",
".",
"isEmpty",
"(",
"ser",
")",
")",
"return",
"ser",
";",
"}",
"// properly set req as its method",
"this",
".",
"req",
"=",
"req",
";",
"// Extends the options for req for the Telegram Bot.",
"// @param {string} botMethod Telegram bot API method.",
"// @param {JSON} JSONdata A JSON object with the required fields (see API).",
"// @param {string} [HTTPMethod=POST] Optionally change method if need to.",
"// @returns {JSON} option The extended option.",
"// ",
"// @example",
"// extOpt('sendMessage', {chat_id: 123456, text: 'hello world'})",
"// → {",
"// method: 'POST',",
"// baseUrl: 'https://api.telegram.org/bot...',",
"// url: 'sendMessage',",
"// formData: {chat_id: 123456, text: 'hello world'} }",
"this",
".",
"extOpt",
"=",
"function",
"(",
"botMethod",
",",
"JSONdata",
",",
"HTTPMethod",
")",
"{",
"var",
"opt",
"=",
"_",
".",
"clone",
"(",
"{",
"method",
":",
"'POST'",
",",
"baseUrl",
":",
"this",
".",
"baseUrl",
",",
"url",
":",
"\"sendMessage\"",
",",
"formData",
":",
"this",
".",
"formData",
"}",
")",
";",
"_",
".",
"assign",
"(",
"opt",
",",
"{",
"url",
":",
"botMethod",
"}",
")",
"if",
"(",
"JSONdata",
")",
"_",
".",
"assign",
"(",
"opt",
",",
"{",
"formData",
":",
"this",
".",
"serialize",
"(",
"JSONdata",
")",
"}",
")",
"if",
"(",
"HTTPMethod",
")",
"_",
".",
"assign",
"(",
"opt",
",",
"{",
"botMethod",
":",
"HTTPMethod",
"}",
")",
";",
"return",
"opt",
";",
"}",
"// shorthand composition: bot's HTTP request",
"this",
".",
"reqBot",
"=",
"_",
".",
"flow",
"(",
"this",
".",
"extOpt",
",",
"this",
".",
"req",
")",
"}"
]
| The API object prototype
The API bot constructor.
@category Telegram API
@param {string} token Your Telegram bot token.
@returns {Bot} The bot able to call methods.
@example
var fs = require('fs');
var bot = require('telegram-bot-bootstrap');
var Alice = new bot(your_bot_token);
Alice.sendMessage(user_chat_id, 'Hey wanna see some cool art?');
Alice.sendPhoto(user_chat_id, fs.createReadStream(__dirname+'/alexiuss.jpg'), * 'Chronoscape by Alexiuss').then(console.log)
var kb = {
keyboard: [
['one'],
['two', 'three'],
['four', 'five', 'six']
],
one_time_keyboard: true
};
Alice.sendMessage(user_chat_id, "Choose a lucky number", undefined, undefined, * kb)
// → The messages and photos are sent to user. | [
"The",
"API",
"object",
"prototype",
"The",
"API",
"bot",
"constructor",
"."
]
| c99281393a1fa3d7c0f81df55634bb956072d20a | https://github.com/kengz/telegram-bot-bootstrap/blob/c99281393a1fa3d7c0f81df55634bb956072d20a/API.js#L39-L120 |
|
43,346 | lmangani/parsip | lib/SIPMessage.js | function(name, value) {
var header = { raw: value };
name = Utils.headerize(name);
if(this.headers[name]) {
this.headers[name].push(header);
} else {
this.headers[name] = [header];
}
} | javascript | function(name, value) {
var header = { raw: value };
name = Utils.headerize(name);
if(this.headers[name]) {
this.headers[name].push(header);
} else {
this.headers[name] = [header];
}
} | [
"function",
"(",
"name",
",",
"value",
")",
"{",
"var",
"header",
"=",
"{",
"raw",
":",
"value",
"}",
";",
"name",
"=",
"Utils",
".",
"headerize",
"(",
"name",
")",
";",
"if",
"(",
"this",
".",
"headers",
"[",
"name",
"]",
")",
"{",
"this",
".",
"headers",
"[",
"name",
"]",
".",
"push",
"(",
"header",
")",
";",
"}",
"else",
"{",
"this",
".",
"headers",
"[",
"name",
"]",
"=",
"[",
"header",
"]",
";",
"}",
"}"
]
| Insert a header of the given name and value into the last position of the
header array. | [
"Insert",
"a",
"header",
"of",
"the",
"given",
"name",
"and",
"value",
"into",
"the",
"last",
"position",
"of",
"the",
"header",
"array",
"."
]
| fa1fd873199e9933ed56124760c564c8e6c571d7 | https://github.com/lmangani/parsip/blob/fa1fd873199e9933ed56124760c564c8e6c571d7/lib/SIPMessage.js#L311-L321 |
|
43,347 | lmangani/parsip | lib/SIPMessage.js | function(name) {
var header = this.headers[Utils.headerize(name)];
if(header) {
if(header[0]) {
return header[0].raw;
}
} else {
return;
}
} | javascript | function(name) {
var header = this.headers[Utils.headerize(name)];
if(header) {
if(header[0]) {
return header[0].raw;
}
} else {
return;
}
} | [
"function",
"(",
"name",
")",
"{",
"var",
"header",
"=",
"this",
".",
"headers",
"[",
"Utils",
".",
"headerize",
"(",
"name",
")",
"]",
";",
"if",
"(",
"header",
")",
"{",
"if",
"(",
"header",
"[",
"0",
"]",
")",
"{",
"return",
"header",
"[",
"0",
"]",
".",
"raw",
";",
"}",
"}",
"else",
"{",
"return",
";",
"}",
"}"
]
| Get the value of the given header name at the given position. | [
"Get",
"the",
"value",
"of",
"the",
"given",
"header",
"name",
"at",
"the",
"given",
"position",
"."
]
| fa1fd873199e9933ed56124760c564c8e6c571d7 | https://github.com/lmangani/parsip/blob/fa1fd873199e9933ed56124760c564c8e6c571d7/lib/SIPMessage.js#L326-L336 |
|
43,348 | semibran/pack | lib/pack.js | whitespace | function whitespace(layout) {
var whitespace = layout.size[0] * layout.size[1]
for (var i = 0; i < layout.boxes.length; i++) {
var box = layout.boxes[i]
whitespace -= box.size[0] * box.size[1]
}
return whitespace
} | javascript | function whitespace(layout) {
var whitespace = layout.size[0] * layout.size[1]
for (var i = 0; i < layout.boxes.length; i++) {
var box = layout.boxes[i]
whitespace -= box.size[0] * box.size[1]
}
return whitespace
} | [
"function",
"whitespace",
"(",
"layout",
")",
"{",
"var",
"whitespace",
"=",
"layout",
".",
"size",
"[",
"0",
"]",
"*",
"layout",
".",
"size",
"[",
"1",
"]",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"layout",
".",
"boxes",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"box",
"=",
"layout",
".",
"boxes",
"[",
"i",
"]",
"whitespace",
"-=",
"box",
".",
"size",
"[",
"0",
"]",
"*",
"box",
".",
"size",
"[",
"1",
"]",
"}",
"return",
"whitespace",
"}"
]
| determines the amount of whitespace area remaining in `layout` | [
"determines",
"the",
"amount",
"of",
"whitespace",
"area",
"remaining",
"in",
"layout"
]
| 27103c7b53111ec96624d926b295b2976ea850af | https://github.com/semibran/pack/blob/27103c7b53111ec96624d926b295b2976ea850af/lib/pack.js#L65-L72 |
43,349 | semibran/pack | lib/pack.js | validate | function validate(boxes, box) {
var a = box
for (var i = 0; i < boxes.length; i++) {
var b = boxes[i]
if (intersects(a, b)) {
return false
}
}
return true
} | javascript | function validate(boxes, box) {
var a = box
for (var i = 0; i < boxes.length; i++) {
var b = boxes[i]
if (intersects(a, b)) {
return false
}
}
return true
} | [
"function",
"validate",
"(",
"boxes",
",",
"box",
")",
"{",
"var",
"a",
"=",
"box",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"boxes",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"b",
"=",
"boxes",
"[",
"i",
"]",
"if",
"(",
"intersects",
"(",
"a",
",",
"b",
")",
")",
"{",
"return",
"false",
"}",
"}",
"return",
"true",
"}"
]
| determines if the region specified by `box` is clear of all other `boxes` | [
"determines",
"if",
"the",
"region",
"specified",
"by",
"box",
"is",
"clear",
"of",
"all",
"other",
"boxes"
]
| 27103c7b53111ec96624d926b295b2976ea850af | https://github.com/semibran/pack/blob/27103c7b53111ec96624d926b295b2976ea850af/lib/pack.js#L93-L102 |
43,350 | semibran/pack | lib/pack.js | intersects | function intersects(a, b) {
return a.position[0] < b.position[0] + b.size[0] && a.position[0] + a.size[0] > b.position[0]
&& a.position[1] < b.position[1] + b.size[1] && a.position[1] + a.size[1] > b.position[1]
} | javascript | function intersects(a, b) {
return a.position[0] < b.position[0] + b.size[0] && a.position[0] + a.size[0] > b.position[0]
&& a.position[1] < b.position[1] + b.size[1] && a.position[1] + a.size[1] > b.position[1]
} | [
"function",
"intersects",
"(",
"a",
",",
"b",
")",
"{",
"return",
"a",
".",
"position",
"[",
"0",
"]",
"<",
"b",
".",
"position",
"[",
"0",
"]",
"+",
"b",
".",
"size",
"[",
"0",
"]",
"&&",
"a",
".",
"position",
"[",
"0",
"]",
"+",
"a",
".",
"size",
"[",
"0",
"]",
">",
"b",
".",
"position",
"[",
"0",
"]",
"&&",
"a",
".",
"position",
"[",
"1",
"]",
"<",
"b",
".",
"position",
"[",
"1",
"]",
"+",
"b",
".",
"size",
"[",
"1",
"]",
"&&",
"a",
".",
"position",
"[",
"1",
"]",
"+",
"a",
".",
"size",
"[",
"1",
"]",
">",
"b",
".",
"position",
"[",
"1",
"]",
"}"
]
| determines if box `a` and box `b` intersect | [
"determines",
"if",
"box",
"a",
"and",
"box",
"b",
"intersect"
]
| 27103c7b53111ec96624d926b295b2976ea850af | https://github.com/semibran/pack/blob/27103c7b53111ec96624d926b295b2976ea850af/lib/pack.js#L105-L108 |
43,351 | lxe/stream-replace | stream-replace.js | replaceStream | function replaceStream(needle, replacer) {
var ts = new Transform();
var chunks = [], len = 0, pos = 0;
ts._transform = function _transform(chunk, enc, cb) {
chunks.push(chunk);
len += chunk.length;
if (pos === 1) {
var data = Buffer.concat(chunks, len)
.toString()
.replace(needle, replacer);
// TODO: examine and profile garbage
chunks = [];
len = 0;
this.push(data);
}
pos = 1 ^ pos;
cb(null);
};
ts._flush = function _flush(cb) {
if (chunks.length) {
this.push(Buffer.concat(chunks, len)
.toString()
.replace(needle, replacer))
}
cb(null);
}
return ts;
} | javascript | function replaceStream(needle, replacer) {
var ts = new Transform();
var chunks = [], len = 0, pos = 0;
ts._transform = function _transform(chunk, enc, cb) {
chunks.push(chunk);
len += chunk.length;
if (pos === 1) {
var data = Buffer.concat(chunks, len)
.toString()
.replace(needle, replacer);
// TODO: examine and profile garbage
chunks = [];
len = 0;
this.push(data);
}
pos = 1 ^ pos;
cb(null);
};
ts._flush = function _flush(cb) {
if (chunks.length) {
this.push(Buffer.concat(chunks, len)
.toString()
.replace(needle, replacer))
}
cb(null);
}
return ts;
} | [
"function",
"replaceStream",
"(",
"needle",
",",
"replacer",
")",
"{",
"var",
"ts",
"=",
"new",
"Transform",
"(",
")",
";",
"var",
"chunks",
"=",
"[",
"]",
",",
"len",
"=",
"0",
",",
"pos",
"=",
"0",
";",
"ts",
".",
"_transform",
"=",
"function",
"_transform",
"(",
"chunk",
",",
"enc",
",",
"cb",
")",
"{",
"chunks",
".",
"push",
"(",
"chunk",
")",
";",
"len",
"+=",
"chunk",
".",
"length",
";",
"if",
"(",
"pos",
"===",
"1",
")",
"{",
"var",
"data",
"=",
"Buffer",
".",
"concat",
"(",
"chunks",
",",
"len",
")",
".",
"toString",
"(",
")",
".",
"replace",
"(",
"needle",
",",
"replacer",
")",
";",
"// TODO: examine and profile garbage",
"chunks",
"=",
"[",
"]",
";",
"len",
"=",
"0",
";",
"this",
".",
"push",
"(",
"data",
")",
";",
"}",
"pos",
"=",
"1",
"^",
"pos",
";",
"cb",
"(",
"null",
")",
";",
"}",
";",
"ts",
".",
"_flush",
"=",
"function",
"_flush",
"(",
"cb",
")",
"{",
"if",
"(",
"chunks",
".",
"length",
")",
"{",
"this",
".",
"push",
"(",
"Buffer",
".",
"concat",
"(",
"chunks",
",",
"len",
")",
".",
"toString",
"(",
")",
".",
"replace",
"(",
"needle",
",",
"replacer",
")",
")",
"}",
"cb",
"(",
"null",
")",
";",
"}",
"return",
"ts",
";",
"}"
]
| Returns a transform stream that replaces
'needle' with 'replacer' in the data piped into it.
All read data is converted ot utf-8 strings before
the replacement isperformed.
Honors needles appearing on chunk boundaries.
Abides by the same rules as String.replace();
@param {String|RegExp} needle needle
@param {String|Function} replacer replacer
@return {TransformStream} | [
"Returns",
"a",
"transform",
"stream",
"that",
"replaces",
"needle",
"with",
"replacer",
"in",
"the",
"data",
"piped",
"into",
"it",
"."
]
| 043595c23b99a262fc07c744f975b0bd3d9689b0 | https://github.com/lxe/stream-replace/blob/043595c23b99a262fc07c744f975b0bd3d9689b0/stream-replace.js#L40-L76 |
43,352 | Mik13/nuki-bridge-api | lib/callback.js | Callback | function Callback (connection, callbackId, callbackUrl, nuki) {
EventEmitter.call(this);
this.connection = connection;
this.nuki = nuki;
this.callbackId = callbackId;
this.url = callbackUrl;
} | javascript | function Callback (connection, callbackId, callbackUrl, nuki) {
EventEmitter.call(this);
this.connection = connection;
this.nuki = nuki;
this.callbackId = callbackId;
this.url = callbackUrl;
} | [
"function",
"Callback",
"(",
"connection",
",",
"callbackId",
",",
"callbackUrl",
",",
"nuki",
")",
"{",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"connection",
"=",
"connection",
";",
"this",
".",
"nuki",
"=",
"nuki",
";",
"this",
".",
"callbackId",
"=",
"callbackId",
";",
"this",
".",
"url",
"=",
"callbackUrl",
";",
"}"
]
| The constructor for callbacks via bridge or nuki.
If called from nuki it will emit on it and check the battery level,
otherwise (called from bridge) it will only emit on itself (for every nuki connected to bridge).
@class Callback
@param {Bridge} connection the bridge
@param {Number} callbackId the id of the callback
@param {Number} callbackUrl the url of the callback
@param {Nuki} [nuki] the nuki
@constructor | [
"The",
"constructor",
"for",
"callbacks",
"via",
"bridge",
"or",
"nuki",
"."
]
| 65e802f5eee2cf9e9c9d1b391b749f4a69648876 | https://github.com/Mik13/nuki-bridge-api/blob/65e802f5eee2cf9e9c9d1b391b749f4a69648876/lib/callback.js#L22-L29 |
43,353 | azusa0127/simple-semaphore | example.js | main | async function main () {
console.log(`\n\n[Single step producer]`);
const workers1 = [
new Producer(100),
new Producer(100),
new Producer(100),
new Producer(100),
new Producer(100),
new Consumer(200),
new Consumer(300),
];
await Promise.all(workers1.map(x => x.work()));
console.log(`\n\n[Efficient producer]`);
const workers2 = [
new EfficientProducer(10),
new Consumer(10),
new Consumer(10),
new Consumer(10),
new Consumer(10),
new Consumer(10),
new Consumer(10),
new Consumer(20),
new Consumer(20),
];
await Promise.all(workers2.map(x => x.work()));
console.log(`\n\n[RejectAll() API test]`);
const p = new Consumer(1).work();
stock.notempty.rejectAll();
p.then(
() => console.error(`[ERROR] This promise should not resolve.`),
err => console.log(`Successfully received a rejected Error - ${err.message}`)
);
} | javascript | async function main () {
console.log(`\n\n[Single step producer]`);
const workers1 = [
new Producer(100),
new Producer(100),
new Producer(100),
new Producer(100),
new Producer(100),
new Consumer(200),
new Consumer(300),
];
await Promise.all(workers1.map(x => x.work()));
console.log(`\n\n[Efficient producer]`);
const workers2 = [
new EfficientProducer(10),
new Consumer(10),
new Consumer(10),
new Consumer(10),
new Consumer(10),
new Consumer(10),
new Consumer(10),
new Consumer(20),
new Consumer(20),
];
await Promise.all(workers2.map(x => x.work()));
console.log(`\n\n[RejectAll() API test]`);
const p = new Consumer(1).work();
stock.notempty.rejectAll();
p.then(
() => console.error(`[ERROR] This promise should not resolve.`),
err => console.log(`Successfully received a rejected Error - ${err.message}`)
);
} | [
"async",
"function",
"main",
"(",
")",
"{",
"console",
".",
"log",
"(",
"`",
"\\n",
"\\n",
"`",
")",
";",
"const",
"workers1",
"=",
"[",
"new",
"Producer",
"(",
"100",
")",
",",
"new",
"Producer",
"(",
"100",
")",
",",
"new",
"Producer",
"(",
"100",
")",
",",
"new",
"Producer",
"(",
"100",
")",
",",
"new",
"Producer",
"(",
"100",
")",
",",
"new",
"Consumer",
"(",
"200",
")",
",",
"new",
"Consumer",
"(",
"300",
")",
",",
"]",
";",
"await",
"Promise",
".",
"all",
"(",
"workers1",
".",
"map",
"(",
"x",
"=>",
"x",
".",
"work",
"(",
")",
")",
")",
";",
"console",
".",
"log",
"(",
"`",
"\\n",
"\\n",
"`",
")",
";",
"const",
"workers2",
"=",
"[",
"new",
"EfficientProducer",
"(",
"10",
")",
",",
"new",
"Consumer",
"(",
"10",
")",
",",
"new",
"Consumer",
"(",
"10",
")",
",",
"new",
"Consumer",
"(",
"10",
")",
",",
"new",
"Consumer",
"(",
"10",
")",
",",
"new",
"Consumer",
"(",
"10",
")",
",",
"new",
"Consumer",
"(",
"10",
")",
",",
"new",
"Consumer",
"(",
"20",
")",
",",
"new",
"Consumer",
"(",
"20",
")",
",",
"]",
";",
"await",
"Promise",
".",
"all",
"(",
"workers2",
".",
"map",
"(",
"x",
"=>",
"x",
".",
"work",
"(",
")",
")",
")",
";",
"console",
".",
"log",
"(",
"`",
"\\n",
"\\n",
"`",
")",
";",
"const",
"p",
"=",
"new",
"Consumer",
"(",
"1",
")",
".",
"work",
"(",
")",
";",
"stock",
".",
"notempty",
".",
"rejectAll",
"(",
")",
";",
"p",
".",
"then",
"(",
"(",
")",
"=>",
"console",
".",
"error",
"(",
"`",
"`",
")",
",",
"err",
"=>",
"console",
".",
"log",
"(",
"`",
"${",
"err",
".",
"message",
"}",
"`",
")",
")",
";",
"}"
]
| Async wrapped main function. | [
"Async",
"wrapped",
"main",
"function",
"."
]
| db97a7bd4e7d1397143c614d70d02de65f8ff6fe | https://github.com/azusa0127/simple-semaphore/blob/db97a7bd4e7d1397143c614d70d02de65f8ff6fe/example.js#L68-L102 |
43,354 | Mik13/nuki-bridge-api | lib/bridge.js | Bridge | function Bridge (ip, port, token, options) {
if (!(this instanceof Bridge)) {
return new Bridge(ip, port, token);
}
this.ip = ip;
this.port = parseInt(port, 10);
this.token = token;
this.delayBetweenRequests = options && options.delayBetweenRequests || 250;
this.delayer = Promise.resolve();
if (!this.ip || !this.port || !this.token || this.port < 1 || this.port > 65536) {
throw new Error('Please check the arguments!');
}
} | javascript | function Bridge (ip, port, token, options) {
if (!(this instanceof Bridge)) {
return new Bridge(ip, port, token);
}
this.ip = ip;
this.port = parseInt(port, 10);
this.token = token;
this.delayBetweenRequests = options && options.delayBetweenRequests || 250;
this.delayer = Promise.resolve();
if (!this.ip || !this.port || !this.token || this.port < 1 || this.port > 65536) {
throw new Error('Please check the arguments!');
}
} | [
"function",
"Bridge",
"(",
"ip",
",",
"port",
",",
"token",
",",
"options",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Bridge",
")",
")",
"{",
"return",
"new",
"Bridge",
"(",
"ip",
",",
"port",
",",
"token",
")",
";",
"}",
"this",
".",
"ip",
"=",
"ip",
";",
"this",
".",
"port",
"=",
"parseInt",
"(",
"port",
",",
"10",
")",
";",
"this",
".",
"token",
"=",
"token",
";",
"this",
".",
"delayBetweenRequests",
"=",
"options",
"&&",
"options",
".",
"delayBetweenRequests",
"||",
"250",
";",
"this",
".",
"delayer",
"=",
"Promise",
".",
"resolve",
"(",
")",
";",
"if",
"(",
"!",
"this",
".",
"ip",
"||",
"!",
"this",
".",
"port",
"||",
"!",
"this",
".",
"token",
"||",
"this",
".",
"port",
"<",
"1",
"||",
"this",
".",
"port",
">",
"65536",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Please check the arguments!'",
")",
";",
"}",
"}"
]
| The constructor for a connection to a bridge.
@class Bridge
@param {String} ip the ip of the bridge
@param {String} port the port of the bridge
@param {String} token the token of the bridge
@param {Object} [options] additional options
@param {Number} [options.delayBetweenRequests] delay in ms between requests made to the bridge (default=250)
@returns {Bridge}
@constructor | [
"The",
"constructor",
"for",
"a",
"connection",
"to",
"a",
"bridge",
"."
]
| 65e802f5eee2cf9e9c9d1b391b749f4a69648876 | https://github.com/Mik13/nuki-bridge-api/blob/65e802f5eee2cf9e9c9d1b391b749f4a69648876/lib/bridge.js#L18-L32 |
43,355 | slickplaid/node-slack-mailgun | lib/mailgun-verify.js | verifyMailgun | function verifyMailgun(apikey, token, timestamp, signature) {
var data = [timestamp, token].join('');
var hmac = crypto.createHmac('sha256', apikey).update(data);
var ourSig = hmac.digest('hex');
var output = {
apikey: apikey,
token: token,
timestamp: timestamp,
signature: signature,
generatedSignature: ourSig,
valid: ourSig === signature
};
return output;
} | javascript | function verifyMailgun(apikey, token, timestamp, signature) {
var data = [timestamp, token].join('');
var hmac = crypto.createHmac('sha256', apikey).update(data);
var ourSig = hmac.digest('hex');
var output = {
apikey: apikey,
token: token,
timestamp: timestamp,
signature: signature,
generatedSignature: ourSig,
valid: ourSig === signature
};
return output;
} | [
"function",
"verifyMailgun",
"(",
"apikey",
",",
"token",
",",
"timestamp",
",",
"signature",
")",
"{",
"var",
"data",
"=",
"[",
"timestamp",
",",
"token",
"]",
".",
"join",
"(",
"''",
")",
";",
"var",
"hmac",
"=",
"crypto",
".",
"createHmac",
"(",
"'sha256'",
",",
"apikey",
")",
".",
"update",
"(",
"data",
")",
";",
"var",
"ourSig",
"=",
"hmac",
".",
"digest",
"(",
"'hex'",
")",
";",
"var",
"output",
"=",
"{",
"apikey",
":",
"apikey",
",",
"token",
":",
"token",
",",
"timestamp",
":",
"timestamp",
",",
"signature",
":",
"signature",
",",
"generatedSignature",
":",
"ourSig",
",",
"valid",
":",
"ourSig",
"===",
"signature",
"}",
";",
"return",
"output",
";",
"}"
]
| Verify mailgun HMAC authentication token | [
"Verify",
"mailgun",
"HMAC",
"authentication",
"token"
]
| 54e523336a85e69766e4d6a2f6a308ebdd0869e9 | https://github.com/slickplaid/node-slack-mailgun/blob/54e523336a85e69766e4d6a2f6a308ebdd0869e9/lib/mailgun-verify.js#L27-L42 |
43,356 | brycebaril/timestreamdb | timestreamdb.js | TimestreamDB | function TimestreamDB(instance, options) {
if (!(this instanceof TimestreamDB))
return new TimestreamDB(instance, options)
var db = Version(instance, options)
db.ts = function (key, options) {
var opts = {reverse: true}
if (options.start) opts.minVersion = options.start
if (options.until) opts.maxVersion = options.until
return ts(db.versionStream(key, opts).pipe(toTimestream()))
}
db.timeStream = db.ts
return db
} | javascript | function TimestreamDB(instance, options) {
if (!(this instanceof TimestreamDB))
return new TimestreamDB(instance, options)
var db = Version(instance, options)
db.ts = function (key, options) {
var opts = {reverse: true}
if (options.start) opts.minVersion = options.start
if (options.until) opts.maxVersion = options.until
return ts(db.versionStream(key, opts).pipe(toTimestream()))
}
db.timeStream = db.ts
return db
} | [
"function",
"TimestreamDB",
"(",
"instance",
",",
"options",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"TimestreamDB",
")",
")",
"return",
"new",
"TimestreamDB",
"(",
"instance",
",",
"options",
")",
"var",
"db",
"=",
"Version",
"(",
"instance",
",",
"options",
")",
"db",
".",
"ts",
"=",
"function",
"(",
"key",
",",
"options",
")",
"{",
"var",
"opts",
"=",
"{",
"reverse",
":",
"true",
"}",
"if",
"(",
"options",
".",
"start",
")",
"opts",
".",
"minVersion",
"=",
"options",
".",
"start",
"if",
"(",
"options",
".",
"until",
")",
"opts",
".",
"maxVersion",
"=",
"options",
".",
"until",
"return",
"ts",
"(",
"db",
".",
"versionStream",
"(",
"key",
",",
"opts",
")",
".",
"pipe",
"(",
"toTimestream",
"(",
")",
")",
")",
"}",
"db",
".",
"timeStream",
"=",
"db",
".",
"ts",
"return",
"db",
"}"
]
| Create a new TimestreamDB
@param {LevelUp} instance A LevelUp instance
@param {object} options Configuration options for level-version | [
"Create",
"a",
"new",
"TimestreamDB"
]
| cebb50ea8d09f39c70937b0ba8e34020025e216e | https://github.com/brycebaril/timestreamdb/blob/cebb50ea8d09f39c70937b0ba8e34020025e216e/timestreamdb.js#L33-L49 |
43,357 | Erudika/para-client-js | lib/Constraint.js | Constraint | function Constraint(constraintName, constraintPayload) {
var name = constraintName;
var payload = constraintPayload;
/**
* The constraint name.
* @returns {String} a name
*/
this.getName = function () {
return name;
};
/**
* Sets the name of the constraint.
* @param {String} n name
*/
this.setName = function (n) {
name = n;
};
/**
* The payload (a map)
* @returns {Object} an object
*/
this.getPayload = function () {
return payload;
};
/**
* Sets the payload.
* @param {Object} p the payload object
*/
this.setPayload = function (p) {
payload = p;
};
} | javascript | function Constraint(constraintName, constraintPayload) {
var name = constraintName;
var payload = constraintPayload;
/**
* The constraint name.
* @returns {String} a name
*/
this.getName = function () {
return name;
};
/**
* Sets the name of the constraint.
* @param {String} n name
*/
this.setName = function (n) {
name = n;
};
/**
* The payload (a map)
* @returns {Object} an object
*/
this.getPayload = function () {
return payload;
};
/**
* Sets the payload.
* @param {Object} p the payload object
*/
this.setPayload = function (p) {
payload = p;
};
} | [
"function",
"Constraint",
"(",
"constraintName",
",",
"constraintPayload",
")",
"{",
"var",
"name",
"=",
"constraintName",
";",
"var",
"payload",
"=",
"constraintPayload",
";",
"/**\n\t * The constraint name.\n\t * @returns {String} a name\n\t */",
"this",
".",
"getName",
"=",
"function",
"(",
")",
"{",
"return",
"name",
";",
"}",
";",
"/**\n\t * Sets the name of the constraint.\n\t * @param {String} n name\n\t */",
"this",
".",
"setName",
"=",
"function",
"(",
"n",
")",
"{",
"name",
"=",
"n",
";",
"}",
";",
"/**\n\t * The payload (a map)\n\t * @returns {Object} an object\n\t */",
"this",
".",
"getPayload",
"=",
"function",
"(",
")",
"{",
"return",
"payload",
";",
"}",
";",
"/**\n\t * Sets the payload.\n\t * @param {Object} p the payload object\n\t */",
"this",
".",
"setPayload",
"=",
"function",
"(",
"p",
")",
"{",
"payload",
"=",
"p",
";",
"}",
";",
"}"
]
| Represents a validation constraint.
@author Alex Bogdanovski [[email protected]]
@param {String} constraintName name
@param {Object} constraintPayload payload
@returns {Constraint} | [
"Represents",
"a",
"validation",
"constraint",
"."
]
| 6bcbe7b206ea2b50e65615048b06b43a1fad19f0 | https://github.com/Erudika/para-client-js/blob/6bcbe7b206ea2b50e65615048b06b43a1fad19f0/lib/Constraint.js#L29-L64 |
43,358 | jackzampolin/influx-express | index.js | function (options) {
if (options.username && options.password) {
return (options.protocol + "://" + options.username + ":" + options.password + "@" + options.host + ":" + options.port + "/" + options.database)
}
return (options.protocol + "://" + options.host + ":" + options.port + "/" + options.database)
} | javascript | function (options) {
if (options.username && options.password) {
return (options.protocol + "://" + options.username + ":" + options.password + "@" + options.host + ":" + options.port + "/" + options.database)
}
return (options.protocol + "://" + options.host + ":" + options.port + "/" + options.database)
} | [
"function",
"(",
"options",
")",
"{",
"if",
"(",
"options",
".",
"username",
"&&",
"options",
".",
"password",
")",
"{",
"return",
"(",
"options",
".",
"protocol",
"+",
"\"://\"",
"+",
"options",
".",
"username",
"+",
"\":\"",
"+",
"options",
".",
"password",
"+",
"\"@\"",
"+",
"options",
".",
"host",
"+",
"\":\"",
"+",
"options",
".",
"port",
"+",
"\"/\"",
"+",
"options",
".",
"database",
")",
"}",
"return",
"(",
"options",
".",
"protocol",
"+",
"\"://\"",
"+",
"options",
".",
"host",
"+",
"\":\"",
"+",
"options",
".",
"port",
"+",
"\"/\"",
"+",
"options",
".",
"database",
")",
"}"
]
| This is a convinence function for creating the InfluxDB connection string | [
"This",
"is",
"a",
"convinence",
"function",
"for",
"creating",
"the",
"InfluxDB",
"connection",
"string"
]
| 599ba9a2485fc6fd2f6bcd434f9d6818c094a497 | https://github.com/jackzampolin/influx-express/blob/599ba9a2485fc6fd2f6bcd434f9d6818c094a497/index.js#L20-L25 |
|
43,359 | jackzampolin/influx-express | index.js | function () {
var len = this.points.length
// Check the length of the point buffer
if (len >= options.batchSize) {
// Write the points and log error if any
client.writePoints(this.points).catch(function (error) {
console.log(error.message)
})
// Reset point buffer
this.points = []
}
} | javascript | function () {
var len = this.points.length
// Check the length of the point buffer
if (len >= options.batchSize) {
// Write the points and log error if any
client.writePoints(this.points).catch(function (error) {
console.log(error.message)
})
// Reset point buffer
this.points = []
}
} | [
"function",
"(",
")",
"{",
"var",
"len",
"=",
"this",
".",
"points",
".",
"length",
"// Check the length of the point buffer",
"if",
"(",
"len",
">=",
"options",
".",
"batchSize",
")",
"{",
"// Write the points and log error if any",
"client",
".",
"writePoints",
"(",
"this",
".",
"points",
")",
".",
"catch",
"(",
"function",
"(",
"error",
")",
"{",
"console",
".",
"log",
"(",
"error",
".",
"message",
")",
"}",
")",
"// Reset point buffer",
"this",
".",
"points",
"=",
"[",
"]",
"}",
"}"
]
| When each point is added check the size of the batch and send if >= batchSize | [
"When",
"each",
"point",
"is",
"added",
"check",
"the",
"size",
"of",
"the",
"batch",
"and",
"send",
"if",
">",
"=",
"batchSize"
]
| 599ba9a2485fc6fd2f6bcd434f9d6818c094a497 | https://github.com/jackzampolin/influx-express/blob/599ba9a2485fc6fd2f6bcd434f9d6818c094a497/index.js#L36-L49 |
|
43,360 | jackzampolin/influx-express | index.js | makePoint | function makePoint() {
// Pull start time from req and log responseTime
var responseTime = Date.now() - req.start;
// Add the new point to the batch of points
batch.points.push({
measurement: "requests",
"tags": {
"path": req.path,
"host": req.hostname,
"verb": req.method,
"status": res.statusCode,
},
"fields": {
"responseTime": responseTime,
},
})
// Emit the 'addPoint' event
batch.emit("addPoint")
} | javascript | function makePoint() {
// Pull start time from req and log responseTime
var responseTime = Date.now() - req.start;
// Add the new point to the batch of points
batch.points.push({
measurement: "requests",
"tags": {
"path": req.path,
"host": req.hostname,
"verb": req.method,
"status": res.statusCode,
},
"fields": {
"responseTime": responseTime,
},
})
// Emit the 'addPoint' event
batch.emit("addPoint")
} | [
"function",
"makePoint",
"(",
")",
"{",
"// Pull start time from req and log responseTime",
"var",
"responseTime",
"=",
"Date",
".",
"now",
"(",
")",
"-",
"req",
".",
"start",
";",
"// Add the new point to the batch of points",
"batch",
".",
"points",
".",
"push",
"(",
"{",
"measurement",
":",
"\"requests\"",
",",
"\"tags\"",
":",
"{",
"\"path\"",
":",
"req",
".",
"path",
",",
"\"host\"",
":",
"req",
".",
"hostname",
",",
"\"verb\"",
":",
"req",
".",
"method",
",",
"\"status\"",
":",
"res",
".",
"statusCode",
",",
"}",
",",
"\"fields\"",
":",
"{",
"\"responseTime\"",
":",
"responseTime",
",",
"}",
",",
"}",
")",
"// Emit the 'addPoint' event",
"batch",
".",
"emit",
"(",
"\"addPoint\"",
")",
"}"
]
| Make line protocol point and add to batcher | [
"Make",
"line",
"protocol",
"point",
"and",
"add",
"to",
"batcher"
]
| 599ba9a2485fc6fd2f6bcd434f9d6818c094a497 | https://github.com/jackzampolin/influx-express/blob/599ba9a2485fc6fd2f6bcd434f9d6818c094a497/index.js#L60-L80 |
43,361 | WebReflection/wru | src/wru.DOM.functions.js | isGonnaBeLegen | function isGonnaBeLegen() {
current = shift.call(queue);
if (current) {
if (typeof current == "function") {
current = {name: current[NAME] || "anonymous", test: current};
}
(node = putItThereAndGimmeBack(
putItThereAndGimmeBack(wru.node, "div"),
"span"
))[INNERHTML] = (
(iHasIt(current, NAME) && current[NAME])
||
(iHasIt(current, DESCRIPTION) && current[DESCRIPTION])
||
UNKNOWN
) + EMPTY + EMPTY;
pass = [];
fail = [];
fatal = [];
tmp = {};
giveItATry("setup");
fatal[LENGTH] || giveItATry("test");
waitForIt || Dary();
} else {
showSummary();
}
} | javascript | function isGonnaBeLegen() {
current = shift.call(queue);
if (current) {
if (typeof current == "function") {
current = {name: current[NAME] || "anonymous", test: current};
}
(node = putItThereAndGimmeBack(
putItThereAndGimmeBack(wru.node, "div"),
"span"
))[INNERHTML] = (
(iHasIt(current, NAME) && current[NAME])
||
(iHasIt(current, DESCRIPTION) && current[DESCRIPTION])
||
UNKNOWN
) + EMPTY + EMPTY;
pass = [];
fail = [];
fatal = [];
tmp = {};
giveItATry("setup");
fatal[LENGTH] || giveItATry("test");
waitForIt || Dary();
} else {
showSummary();
}
} | [
"function",
"isGonnaBeLegen",
"(",
")",
"{",
"current",
"=",
"shift",
".",
"call",
"(",
"queue",
")",
";",
"if",
"(",
"current",
")",
"{",
"if",
"(",
"typeof",
"current",
"==",
"\"function\"",
")",
"{",
"current",
"=",
"{",
"name",
":",
"current",
"[",
"NAME",
"]",
"||",
"\"anonymous\"",
",",
"test",
":",
"current",
"}",
";",
"}",
"(",
"node",
"=",
"putItThereAndGimmeBack",
"(",
"putItThereAndGimmeBack",
"(",
"wru",
".",
"node",
",",
"\"div\"",
")",
",",
"\"span\"",
")",
")",
"[",
"INNERHTML",
"]",
"=",
"(",
"(",
"iHasIt",
"(",
"current",
",",
"NAME",
")",
"&&",
"current",
"[",
"NAME",
"]",
")",
"||",
"(",
"iHasIt",
"(",
"current",
",",
"DESCRIPTION",
")",
"&&",
"current",
"[",
"DESCRIPTION",
"]",
")",
"||",
"UNKNOWN",
")",
"+",
"EMPTY",
"+",
"EMPTY",
";",
"pass",
"=",
"[",
"]",
";",
"fail",
"=",
"[",
"]",
";",
"fatal",
"=",
"[",
"]",
";",
"tmp",
"=",
"{",
"}",
";",
"giveItATry",
"(",
"\"setup\"",
")",
";",
"fatal",
"[",
"LENGTH",
"]",
"||",
"giveItATry",
"(",
"\"test\"",
")",
";",
"waitForIt",
"||",
"Dary",
"(",
")",
";",
"}",
"else",
"{",
"showSummary",
"(",
")",
";",
"}",
"}"
]
| DOM specific version | [
"DOM",
"specific",
"version"
]
| 705b9629ce0eb1f86989f88fde4dc39796c1d545 | https://github.com/WebReflection/wru/blob/705b9629ce0eb1f86989f88fde4dc39796c1d545/src/wru.DOM.functions.js#L2-L28 |
43,362 | fgnass/tamper | index.js | patch | function patch(obj, properties) {
var old = {};
for (var name in properties) {
old[name] = obj[name];
obj[name] = properties[name];
}
return old;
} | javascript | function patch(obj, properties) {
var old = {};
for (var name in properties) {
old[name] = obj[name];
obj[name] = properties[name];
}
return old;
} | [
"function",
"patch",
"(",
"obj",
",",
"properties",
")",
"{",
"var",
"old",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"name",
"in",
"properties",
")",
"{",
"old",
"[",
"name",
"]",
"=",
"obj",
"[",
"name",
"]",
";",
"obj",
"[",
"name",
"]",
"=",
"properties",
"[",
"name",
"]",
";",
"}",
"return",
"old",
";",
"}"
]
| Overwrites properties of the given object and returns the old values | [
"Overwrites",
"properties",
"of",
"the",
"given",
"object",
"and",
"returns",
"the",
"old",
"values"
]
| ae46c87dee0510298571f0343bf647116f9868de | https://github.com/fgnass/tamper/blob/ae46c87dee0510298571f0343bf647116f9868de/index.js#L67-L74 |
43,363 | WebReflection/wru | src/wru.functions.js | giveItATry | function giveItATry(name) {
if (iHasIt(current, name)) {
try {
current[name](tmp);
} catch(doooodeThisIsBAD) {
push.call(fatal, EMPTY + doooodeThisIsBAD);
}
}
} | javascript | function giveItATry(name) {
if (iHasIt(current, name)) {
try {
current[name](tmp);
} catch(doooodeThisIsBAD) {
push.call(fatal, EMPTY + doooodeThisIsBAD);
}
}
} | [
"function",
"giveItATry",
"(",
"name",
")",
"{",
"if",
"(",
"iHasIt",
"(",
"current",
",",
"name",
")",
")",
"{",
"try",
"{",
"current",
"[",
"name",
"]",
"(",
"tmp",
")",
";",
"}",
"catch",
"(",
"doooodeThisIsBAD",
")",
"{",
"push",
".",
"call",
"(",
"fatal",
",",
"EMPTY",
"+",
"doooodeThisIsBAD",
")",
";",
"}",
"}",
"}"
]
| common functions for all versions | [
"common",
"functions",
"for",
"all",
"versions"
]
| 705b9629ce0eb1f86989f88fde4dc39796c1d545 | https://github.com/WebReflection/wru/blob/705b9629ce0eb1f86989f88fde4dc39796c1d545/src/wru.functions.js#L2-L10 |
43,364 | WebReflection/wru | src/wru.console.functions.js | isGonnaBeLegen | function isGonnaBeLegen() {
current = shift.call(queue);
if (current) {
if (typeof current == "function") {
current = {name: current[NAME] || "anonymous", test: current};
}
log(OUTPUT_SEPARATOR);
log(
(iHasIt(current, NAME) && current[NAME])
||
(iHasIt(current, DESCRIPTION) && current[DESCRIPTION])
||
UNKNOWN
);
pass = [];
fail = [];
fatal = [];
tmp = {};
giveItATry("setup");
fatal[LENGTH] || giveItATry("test");
waitForIt || Dary();
} else {
showSummary();
}
} | javascript | function isGonnaBeLegen() {
current = shift.call(queue);
if (current) {
if (typeof current == "function") {
current = {name: current[NAME] || "anonymous", test: current};
}
log(OUTPUT_SEPARATOR);
log(
(iHasIt(current, NAME) && current[NAME])
||
(iHasIt(current, DESCRIPTION) && current[DESCRIPTION])
||
UNKNOWN
);
pass = [];
fail = [];
fatal = [];
tmp = {};
giveItATry("setup");
fatal[LENGTH] || giveItATry("test");
waitForIt || Dary();
} else {
showSummary();
}
} | [
"function",
"isGonnaBeLegen",
"(",
")",
"{",
"current",
"=",
"shift",
".",
"call",
"(",
"queue",
")",
";",
"if",
"(",
"current",
")",
"{",
"if",
"(",
"typeof",
"current",
"==",
"\"function\"",
")",
"{",
"current",
"=",
"{",
"name",
":",
"current",
"[",
"NAME",
"]",
"||",
"\"anonymous\"",
",",
"test",
":",
"current",
"}",
";",
"}",
"log",
"(",
"OUTPUT_SEPARATOR",
")",
";",
"log",
"(",
"(",
"iHasIt",
"(",
"current",
",",
"NAME",
")",
"&&",
"current",
"[",
"NAME",
"]",
")",
"||",
"(",
"iHasIt",
"(",
"current",
",",
"DESCRIPTION",
")",
"&&",
"current",
"[",
"DESCRIPTION",
"]",
")",
"||",
"UNKNOWN",
")",
";",
"pass",
"=",
"[",
"]",
";",
"fail",
"=",
"[",
"]",
";",
"fatal",
"=",
"[",
"]",
";",
"tmp",
"=",
"{",
"}",
";",
"giveItATry",
"(",
"\"setup\"",
")",
";",
"fatal",
"[",
"LENGTH",
"]",
"||",
"giveItATry",
"(",
"\"test\"",
")",
";",
"waitForIt",
"||",
"Dary",
"(",
")",
";",
"}",
"else",
"{",
"showSummary",
"(",
")",
";",
"}",
"}"
]
| console specific version | [
"console",
"specific",
"version"
]
| 705b9629ce0eb1f86989f88fde4dc39796c1d545 | https://github.com/WebReflection/wru/blob/705b9629ce0eb1f86989f88fde4dc39796c1d545/src/wru.console.functions.js#L2-L26 |
43,365 | luxp/jqmath | src/jqmath.js | checkVertStretch | function checkVertStretch (up, dn, g, doP) /* non-MathML */ {
if (g.nodeName.toLowerCase() == 'mo' && g.childNodes.length == 1) {
var c = g.firstChild, s = c.data;
if (c.nodeType == 3 /* Text */ && (up > 0.9 || dn > 0.9)
&& (M.prefix_[s] < 25 || M.postfix_[s] < 25
|| '|\u2016\u221A' /* ‖ √ */.indexOf(s) != -1 || doP)) {
var r = (up + dn) / 1.2, radicQ = s == '\u221A',
v = (radicQ ? 0.26 : 0.35) + ((radicQ ? 0.15 : 0.25) - dn) / r;
g.style.fontSize = r.toFixed(3) + 'em';
g.style.verticalAlign = v.toFixed(3) + 'em';
g.fmUp = up;
g.fmDn = dn;
g.style.display = 'inline-block';
g.style.transform = g.style.msTransform = g.style.MozTransform =
g.style.WebkitTransform = 'scaleX(0.5)';
}
}
} | javascript | function checkVertStretch (up, dn, g, doP) /* non-MathML */ {
if (g.nodeName.toLowerCase() == 'mo' && g.childNodes.length == 1) {
var c = g.firstChild, s = c.data;
if (c.nodeType == 3 /* Text */ && (up > 0.9 || dn > 0.9)
&& (M.prefix_[s] < 25 || M.postfix_[s] < 25
|| '|\u2016\u221A' /* ‖ √ */.indexOf(s) != -1 || doP)) {
var r = (up + dn) / 1.2, radicQ = s == '\u221A',
v = (radicQ ? 0.26 : 0.35) + ((radicQ ? 0.15 : 0.25) - dn) / r;
g.style.fontSize = r.toFixed(3) + 'em';
g.style.verticalAlign = v.toFixed(3) + 'em';
g.fmUp = up;
g.fmDn = dn;
g.style.display = 'inline-block';
g.style.transform = g.style.msTransform = g.style.MozTransform =
g.style.WebkitTransform = 'scaleX(0.5)';
}
}
} | [
"function",
"checkVertStretch",
"(",
"up",
",",
"dn",
",",
"g",
",",
"doP",
")",
"/* non-MathML */",
"{",
"if",
"(",
"g",
".",
"nodeName",
".",
"toLowerCase",
"(",
")",
"==",
"'mo'",
"&&",
"g",
".",
"childNodes",
".",
"length",
"==",
"1",
")",
"{",
"var",
"c",
"=",
"g",
".",
"firstChild",
",",
"s",
"=",
"c",
".",
"data",
";",
"if",
"(",
"c",
".",
"nodeType",
"==",
"3",
"/* Text */",
"&&",
"(",
"up",
">",
"0.9",
"||",
"dn",
">",
"0.9",
")",
"&&",
"(",
"M",
".",
"prefix_",
"[",
"s",
"]",
"<",
"25",
"||",
"M",
".",
"postfix_",
"[",
"s",
"]",
"<",
"25",
"||",
"'|\\u2016\\u221A'",
"/* ‖ √ */.i",
"n",
"dexOf(s",
")",
" ",
"!",
" -",
" ",
"|",
" d",
"P))",
" ",
"{",
"",
"var",
"r",
"=",
"(",
"up",
"+",
"dn",
")",
"/",
"1.2",
",",
"radicQ",
"=",
"s",
"==",
"'\\u221A'",
",",
"v",
"=",
"(",
"radicQ",
"?",
"0.26",
":",
"0.35",
")",
"+",
"(",
"(",
"radicQ",
"?",
"0.15",
":",
"0.25",
")",
"-",
"dn",
")",
"/",
"r",
";",
"g",
".",
"style",
".",
"fontSize",
"=",
"r",
".",
"toFixed",
"(",
"3",
")",
"+",
"'em'",
";",
"g",
".",
"style",
".",
"verticalAlign",
"=",
"v",
".",
"toFixed",
"(",
"3",
")",
"+",
"'em'",
";",
"g",
".",
"fmUp",
"=",
"up",
";",
"g",
".",
"fmDn",
"=",
"dn",
";",
"g",
".",
"style",
".",
"display",
"=",
"'inline-block'",
";",
"g",
".",
"style",
".",
"transform",
"=",
"g",
".",
"style",
".",
"msTransform",
"=",
"g",
".",
"style",
".",
"MozTransform",
"=",
"g",
".",
"style",
".",
"WebkitTransform",
"=",
"'scaleX(0.5)'",
";",
"}",
"}",
"}"
]
| fmUp is mid-x to outer top, fmDn is mid-x to outer bottom, both approx. & in parent ems | [
"fmUp",
"is",
"mid",
"-",
"x",
"to",
"outer",
"top",
"fmDn",
"is",
"mid",
"-",
"x",
"to",
"outer",
"bottom",
"both",
"approx",
".",
"&",
"in",
"parent",
"ems"
]
| 7a6051159c11e69e0f6ecba6e3f89801ef7e3984 | https://github.com/luxp/jqmath/blob/7a6051159c11e69e0f6ecba6e3f89801ef7e3984/src/jqmath.js#L258-L275 |
43,366 | luxp/jqmath | src/jqmath.js | parse_table_tokP | function parse_table_tokP (dtableQ) {
if (dtableQ === undefined) dtableQ = M.dtableQ;
var mtrs = [];
while (true) {
var mtrP_tokP = parse_mtr_tokP(mtrs.length == 0), mtrP = mtrP_tokP[0],
tokP = mtrP_tokP[1] || scanTokP();
if (mtrP) mtrs.push(mtrP);
if (!(tokP && tokP[1] == ';'))
return [newMe_('mtable', mtrs, dtableQ ? {displaystyle: true} : undefined),
tokP];
}
} | javascript | function parse_table_tokP (dtableQ) {
if (dtableQ === undefined) dtableQ = M.dtableQ;
var mtrs = [];
while (true) {
var mtrP_tokP = parse_mtr_tokP(mtrs.length == 0), mtrP = mtrP_tokP[0],
tokP = mtrP_tokP[1] || scanTokP();
if (mtrP) mtrs.push(mtrP);
if (!(tokP && tokP[1] == ';'))
return [newMe_('mtable', mtrs, dtableQ ? {displaystyle: true} : undefined),
tokP];
}
} | [
"function",
"parse_table_tokP",
"(",
"dtableQ",
")",
"{",
"if",
"(",
"dtableQ",
"===",
"undefined",
")",
"dtableQ",
"=",
"M",
".",
"dtableQ",
";",
"var",
"mtrs",
"=",
"[",
"]",
";",
"while",
"(",
"true",
")",
"{",
"var",
"mtrP_tokP",
"=",
"parse_mtr_tokP",
"(",
"mtrs",
".",
"length",
"==",
"0",
")",
",",
"mtrP",
"=",
"mtrP_tokP",
"[",
"0",
"]",
",",
"tokP",
"=",
"mtrP_tokP",
"[",
"1",
"]",
"||",
"scanTokP",
"(",
")",
";",
"if",
"(",
"mtrP",
")",
"mtrs",
".",
"push",
"(",
"mtrP",
")",
";",
"if",
"(",
"!",
"(",
"tokP",
"&&",
"tokP",
"[",
"1",
"]",
"==",
"';'",
")",
")",
"return",
"[",
"newMe_",
"(",
"'mtable'",
",",
"mtrs",
",",
"dtableQ",
"?",
"{",
"displaystyle",
":",
"true",
"}",
":",
"undefined",
")",
",",
"tokP",
"]",
";",
"}",
"}"
]
| whether \table defaults to \dtable | [
"whether",
"\\",
"table",
"defaults",
"to",
"\\",
"dtable"
]
| 7a6051159c11e69e0f6ecba6e3f89801ef7e3984 | https://github.com/luxp/jqmath/blob/7a6051159c11e69e0f6ecba6e3f89801ef7e3984/src/jqmath.js#L1101-L1113 |
43,367 | mhkeller/joiner | dist/joiner.node.js | listCacheSet$1 | function listCacheSet$1(key, value) {
var data = this.__data__,
index = assocIndexOf$4(data, key);
if (index < 0) {
++this.size;
data.push([key, value]);
} else {
data[index][1] = value;
}
return this;
} | javascript | function listCacheSet$1(key, value) {
var data = this.__data__,
index = assocIndexOf$4(data, key);
if (index < 0) {
++this.size;
data.push([key, value]);
} else {
data[index][1] = value;
}
return this;
} | [
"function",
"listCacheSet$1",
"(",
"key",
",",
"value",
")",
"{",
"var",
"data",
"=",
"this",
".",
"__data__",
",",
"index",
"=",
"assocIndexOf$4",
"(",
"data",
",",
"key",
")",
";",
"if",
"(",
"index",
"<",
"0",
")",
"{",
"++",
"this",
".",
"size",
";",
"data",
".",
"push",
"(",
"[",
"key",
",",
"value",
"]",
")",
";",
"}",
"else",
"{",
"data",
"[",
"index",
"]",
"[",
"1",
"]",
"=",
"value",
";",
"}",
"return",
"this",
";",
"}"
]
| Sets the list cache `key` to `value`.
@private
@name set
@memberOf ListCache
@param {string} key The key of the value to set.
@param {*} value The value to set.
@returns {Object} Returns the list cache instance. | [
"Sets",
"the",
"list",
"cache",
"key",
"to",
"value",
"."
]
| 97d3010f8b61e8899a4ca068cbf8d467de6dc4e6 | https://github.com/mhkeller/joiner/blob/97d3010f8b61e8899a4ca068cbf8d467de6dc4e6/dist/joiner.node.js#L162-L173 |
43,368 | mhkeller/joiner | dist/joiner.node.js | hashDelete$1 | function hashDelete$1(key) {
var result = this.has(key) && delete this.__data__[key];
this.size -= result ? 1 : 0;
return result;
} | javascript | function hashDelete$1(key) {
var result = this.has(key) && delete this.__data__[key];
this.size -= result ? 1 : 0;
return result;
} | [
"function",
"hashDelete$1",
"(",
"key",
")",
"{",
"var",
"result",
"=",
"this",
".",
"has",
"(",
"key",
")",
"&&",
"delete",
"this",
".",
"__data__",
"[",
"key",
"]",
";",
"this",
".",
"size",
"-=",
"result",
"?",
"1",
":",
"0",
";",
"return",
"result",
";",
"}"
]
| Removes `key` and its value from the hash.
@private
@name delete
@memberOf Hash
@param {Object} hash The hash to modify.
@param {string} key The key of the value to remove.
@returns {boolean} Returns `true` if the entry was removed, else `false`. | [
"Removes",
"key",
"and",
"its",
"value",
"from",
"the",
"hash",
"."
]
| 97d3010f8b61e8899a4ca068cbf8d467de6dc4e6 | https://github.com/mhkeller/joiner/blob/97d3010f8b61e8899a4ca068cbf8d467de6dc4e6/dist/joiner.node.js#L647-L651 |
43,369 | mhkeller/joiner | dist/joiner.node.js | getMapData$1 | function getMapData$1(map, key) {
var data = map.__data__;
return isKeyable(key) ? data[typeof key == 'string' ? 'string' : 'hash'] : data.map;
} | javascript | function getMapData$1(map, key) {
var data = map.__data__;
return isKeyable(key) ? data[typeof key == 'string' ? 'string' : 'hash'] : data.map;
} | [
"function",
"getMapData$1",
"(",
"map",
",",
"key",
")",
"{",
"var",
"data",
"=",
"map",
".",
"__data__",
";",
"return",
"isKeyable",
"(",
"key",
")",
"?",
"data",
"[",
"typeof",
"key",
"==",
"'string'",
"?",
"'string'",
":",
"'hash'",
"]",
":",
"data",
".",
"map",
";",
"}"
]
| Gets the data for `map`.
@private
@param {Object} map The map to query.
@param {string} key The reference key.
@returns {*} Returns the map data. | [
"Gets",
"the",
"data",
"for",
"map",
"."
]
| 97d3010f8b61e8899a4ca068cbf8d467de6dc4e6 | https://github.com/mhkeller/joiner/blob/97d3010f8b61e8899a4ca068cbf8d467de6dc4e6/dist/joiner.node.js#L813-L816 |
43,370 | mhkeller/joiner | dist/joiner.node.js | arrayEach$1 | function arrayEach$1(array, iteratee) {
var index = -1,
length = array == null ? 0 : array.length;
while (++index < length) {
if (iteratee(array[index], index, array) === false) {
break;
}
}
return array;
} | javascript | function arrayEach$1(array, iteratee) {
var index = -1,
length = array == null ? 0 : array.length;
while (++index < length) {
if (iteratee(array[index], index, array) === false) {
break;
}
}
return array;
} | [
"function",
"arrayEach$1",
"(",
"array",
",",
"iteratee",
")",
"{",
"var",
"index",
"=",
"-",
"1",
",",
"length",
"=",
"array",
"==",
"null",
"?",
"0",
":",
"array",
".",
"length",
";",
"while",
"(",
"++",
"index",
"<",
"length",
")",
"{",
"if",
"(",
"iteratee",
"(",
"array",
"[",
"index",
"]",
",",
"index",
",",
"array",
")",
"===",
"false",
")",
"{",
"break",
";",
"}",
"}",
"return",
"array",
";",
"}"
]
| A specialized version of `_.forEach` for arrays without support for
iteratee shorthands.
@private
@param {Array} [array] The array to iterate over.
@param {Function} iteratee The function invoked per iteration.
@returns {Array} Returns `array`. | [
"A",
"specialized",
"version",
"of",
"_",
".",
"forEach",
"for",
"arrays",
"without",
"support",
"for",
"iteratee",
"shorthands",
"."
]
| 97d3010f8b61e8899a4ca068cbf8d467de6dc4e6 | https://github.com/mhkeller/joiner/blob/97d3010f8b61e8899a4ca068cbf8d467de6dc4e6/dist/joiner.node.js#L1001-L1011 |
43,371 | mhkeller/joiner | dist/joiner.node.js | copyArray$1 | function copyArray$1(source, array) {
var index = -1,
length = source.length;
array || (array = Array(length));
while (++index < length) {
array[index] = source[index];
}
return array;
} | javascript | function copyArray$1(source, array) {
var index = -1,
length = source.length;
array || (array = Array(length));
while (++index < length) {
array[index] = source[index];
}
return array;
} | [
"function",
"copyArray$1",
"(",
"source",
",",
"array",
")",
"{",
"var",
"index",
"=",
"-",
"1",
",",
"length",
"=",
"source",
".",
"length",
";",
"array",
"||",
"(",
"array",
"=",
"Array",
"(",
"length",
")",
")",
";",
"while",
"(",
"++",
"index",
"<",
"length",
")",
"{",
"array",
"[",
"index",
"]",
"=",
"source",
"[",
"index",
"]",
";",
"}",
"return",
"array",
";",
"}"
]
| Copies the values of `source` to `array`.
@private
@param {Array} source The array to copy values from.
@param {Array} [array=[]] The array to copy values to.
@returns {Array} Returns `array`. | [
"Copies",
"the",
"values",
"of",
"source",
"to",
"array",
"."
]
| 97d3010f8b61e8899a4ca068cbf8d467de6dc4e6 | https://github.com/mhkeller/joiner/blob/97d3010f8b61e8899a4ca068cbf8d467de6dc4e6/dist/joiner.node.js#L1851-L1860 |
43,372 | mhkeller/joiner | dist/joiner.node.js | arrayPush$1 | function arrayPush$1(array, values) {
var index = -1,
length = values.length,
offset = array.length;
while (++index < length) {
array[offset + index] = values[index];
}
return array;
} | javascript | function arrayPush$1(array, values) {
var index = -1,
length = values.length,
offset = array.length;
while (++index < length) {
array[offset + index] = values[index];
}
return array;
} | [
"function",
"arrayPush$1",
"(",
"array",
",",
"values",
")",
"{",
"var",
"index",
"=",
"-",
"1",
",",
"length",
"=",
"values",
".",
"length",
",",
"offset",
"=",
"array",
".",
"length",
";",
"while",
"(",
"++",
"index",
"<",
"length",
")",
"{",
"array",
"[",
"offset",
"+",
"index",
"]",
"=",
"values",
"[",
"index",
"]",
";",
"}",
"return",
"array",
";",
"}"
]
| Appends the elements of `values` to `array`.
@private
@param {Array} array The array to modify.
@param {Array} values The values to append.
@returns {Array} Returns `array`. | [
"Appends",
"the",
"elements",
"of",
"values",
"to",
"array",
"."
]
| 97d3010f8b61e8899a4ca068cbf8d467de6dc4e6 | https://github.com/mhkeller/joiner/blob/97d3010f8b61e8899a4ca068cbf8d467de6dc4e6/dist/joiner.node.js#L1970-L1979 |
43,373 | mhkeller/joiner | dist/joiner.node.js | setToArray$1 | function setToArray$1(set) {
var index = -1,
result = Array(set.size);
set.forEach(function (value) {
result[++index] = value;
});
return result;
} | javascript | function setToArray$1(set) {
var index = -1,
result = Array(set.size);
set.forEach(function (value) {
result[++index] = value;
});
return result;
} | [
"function",
"setToArray$1",
"(",
"set",
")",
"{",
"var",
"index",
"=",
"-",
"1",
",",
"result",
"=",
"Array",
"(",
"set",
".",
"size",
")",
";",
"set",
".",
"forEach",
"(",
"function",
"(",
"value",
")",
"{",
"result",
"[",
"++",
"index",
"]",
"=",
"value",
";",
"}",
")",
";",
"return",
"result",
";",
"}"
]
| Converts `set` to an array of its values.
@private
@param {Object} set The set to convert.
@returns {Array} Returns the values. | [
"Converts",
"set",
"to",
"an",
"array",
"of",
"its",
"values",
"."
]
| 97d3010f8b61e8899a4ca068cbf8d467de6dc4e6 | https://github.com/mhkeller/joiner/blob/97d3010f8b61e8899a4ca068cbf8d467de6dc4e6/dist/joiner.node.js#L2375-L2383 |
43,374 | mhkeller/joiner | dist/joiner.node.js | arrayMap$1 | function arrayMap$1(array, iteratee) {
var index = -1,
length = array == null ? 0 : array.length,
result = Array(length);
while (++index < length) {
result[index] = iteratee(array[index], index, array);
}
return result;
} | javascript | function arrayMap$1(array, iteratee) {
var index = -1,
length = array == null ? 0 : array.length,
result = Array(length);
while (++index < length) {
result[index] = iteratee(array[index], index, array);
}
return result;
} | [
"function",
"arrayMap$1",
"(",
"array",
",",
"iteratee",
")",
"{",
"var",
"index",
"=",
"-",
"1",
",",
"length",
"=",
"array",
"==",
"null",
"?",
"0",
":",
"array",
".",
"length",
",",
"result",
"=",
"Array",
"(",
"length",
")",
";",
"while",
"(",
"++",
"index",
"<",
"length",
")",
"{",
"result",
"[",
"index",
"]",
"=",
"iteratee",
"(",
"array",
"[",
"index",
"]",
",",
"index",
",",
"array",
")",
";",
"}",
"return",
"result",
";",
"}"
]
| A specialized version of `_.map` for arrays without support for iteratee
shorthands.
@private
@param {Array} [array] The array to iterate over.
@param {Function} iteratee The function invoked per iteration.
@returns {Array} Returns the new mapped array. | [
"A",
"specialized",
"version",
"of",
"_",
".",
"map",
"for",
"arrays",
"without",
"support",
"for",
"iteratee",
"shorthands",
"."
]
| 97d3010f8b61e8899a4ca068cbf8d467de6dc4e6 | https://github.com/mhkeller/joiner/blob/97d3010f8b61e8899a4ca068cbf8d467de6dc4e6/dist/joiner.node.js#L2940-L2949 |
43,375 | mhkeller/joiner | dist/joiner.node.js | baseSet$1 | function baseSet$1(object, path, value, customizer) {
if (!isObject$6(object)) {
return object;
}
path = castPath$2(path, object);
var index = -1,
length = path.length,
lastIndex = length - 1,
nested = object;
while (nested != null && ++index < length) {
var key = toKey$2(path[index]),
newValue = value;
if (index != lastIndex) {
var objValue = nested[key];
newValue = customizer ? customizer(objValue, key, nested) : undefined;
if (newValue === undefined) {
newValue = isObject$6(objValue) ? objValue : isIndex$2(path[index + 1]) ? [] : {};
}
}
assignValue$3(nested, key, newValue);
nested = nested[key];
}
return object;
} | javascript | function baseSet$1(object, path, value, customizer) {
if (!isObject$6(object)) {
return object;
}
path = castPath$2(path, object);
var index = -1,
length = path.length,
lastIndex = length - 1,
nested = object;
while (nested != null && ++index < length) {
var key = toKey$2(path[index]),
newValue = value;
if (index != lastIndex) {
var objValue = nested[key];
newValue = customizer ? customizer(objValue, key, nested) : undefined;
if (newValue === undefined) {
newValue = isObject$6(objValue) ? objValue : isIndex$2(path[index + 1]) ? [] : {};
}
}
assignValue$3(nested, key, newValue);
nested = nested[key];
}
return object;
} | [
"function",
"baseSet$1",
"(",
"object",
",",
"path",
",",
"value",
",",
"customizer",
")",
"{",
"if",
"(",
"!",
"isObject$6",
"(",
"object",
")",
")",
"{",
"return",
"object",
";",
"}",
"path",
"=",
"castPath$2",
"(",
"path",
",",
"object",
")",
";",
"var",
"index",
"=",
"-",
"1",
",",
"length",
"=",
"path",
".",
"length",
",",
"lastIndex",
"=",
"length",
"-",
"1",
",",
"nested",
"=",
"object",
";",
"while",
"(",
"nested",
"!=",
"null",
"&&",
"++",
"index",
"<",
"length",
")",
"{",
"var",
"key",
"=",
"toKey$2",
"(",
"path",
"[",
"index",
"]",
")",
",",
"newValue",
"=",
"value",
";",
"if",
"(",
"index",
"!=",
"lastIndex",
")",
"{",
"var",
"objValue",
"=",
"nested",
"[",
"key",
"]",
";",
"newValue",
"=",
"customizer",
"?",
"customizer",
"(",
"objValue",
",",
"key",
",",
"nested",
")",
":",
"undefined",
";",
"if",
"(",
"newValue",
"===",
"undefined",
")",
"{",
"newValue",
"=",
"isObject$6",
"(",
"objValue",
")",
"?",
"objValue",
":",
"isIndex$2",
"(",
"path",
"[",
"index",
"+",
"1",
"]",
")",
"?",
"[",
"]",
":",
"{",
"}",
";",
"}",
"}",
"assignValue$3",
"(",
"nested",
",",
"key",
",",
"newValue",
")",
";",
"nested",
"=",
"nested",
"[",
"key",
"]",
";",
"}",
"return",
"object",
";",
"}"
]
| The base implementation of `_.set`.
@private
@param {Object} object The object to modify.
@param {Array|string} path The path of the property to set.
@param {*} value The value to set.
@param {Function} [customizer] The function to customize path creation.
@returns {Object} Returns `object`. | [
"The",
"base",
"implementation",
"of",
"_",
".",
"set",
"."
]
| 97d3010f8b61e8899a4ca068cbf8d467de6dc4e6 | https://github.com/mhkeller/joiner/blob/97d3010f8b61e8899a4ca068cbf8d467de6dc4e6/dist/joiner.node.js#L3139-L3165 |
43,376 | mhkeller/joiner | dist/joiner.node.js | baseSlice$1 | function baseSlice$1(array, start, end) {
var index = -1,
length = array.length;
if (start < 0) {
start = -start > length ? 0 : length + start;
}
end = end > length ? length : end;
if (end < 0) {
end += length;
}
length = start > end ? 0 : end - start >>> 0;
start >>>= 0;
var result = Array(length);
while (++index < length) {
result[index] = array[index + start];
}
return result;
} | javascript | function baseSlice$1(array, start, end) {
var index = -1,
length = array.length;
if (start < 0) {
start = -start > length ? 0 : length + start;
}
end = end > length ? length : end;
if (end < 0) {
end += length;
}
length = start > end ? 0 : end - start >>> 0;
start >>>= 0;
var result = Array(length);
while (++index < length) {
result[index] = array[index + start];
}
return result;
} | [
"function",
"baseSlice$1",
"(",
"array",
",",
"start",
",",
"end",
")",
"{",
"var",
"index",
"=",
"-",
"1",
",",
"length",
"=",
"array",
".",
"length",
";",
"if",
"(",
"start",
"<",
"0",
")",
"{",
"start",
"=",
"-",
"start",
">",
"length",
"?",
"0",
":",
"length",
"+",
"start",
";",
"}",
"end",
"=",
"end",
">",
"length",
"?",
"length",
":",
"end",
";",
"if",
"(",
"end",
"<",
"0",
")",
"{",
"end",
"+=",
"length",
";",
"}",
"length",
"=",
"start",
">",
"end",
"?",
"0",
":",
"end",
"-",
"start",
">>>",
"0",
";",
"start",
">>>=",
"0",
";",
"var",
"result",
"=",
"Array",
"(",
"length",
")",
";",
"while",
"(",
"++",
"index",
"<",
"length",
")",
"{",
"result",
"[",
"index",
"]",
"=",
"array",
"[",
"index",
"+",
"start",
"]",
";",
"}",
"return",
"result",
";",
"}"
]
| The base implementation of `_.slice` without an iteratee call guard.
@private
@param {Array} array The array to slice.
@param {number} [start=0] The start position.
@param {number} [end=array.length] The end position.
@returns {Array} Returns the slice of `array`. | [
"The",
"base",
"implementation",
"of",
"_",
".",
"slice",
"without",
"an",
"iteratee",
"call",
"guard",
"."
]
| 97d3010f8b61e8899a4ca068cbf8d467de6dc4e6 | https://github.com/mhkeller/joiner/blob/97d3010f8b61e8899a4ca068cbf8d467de6dc4e6/dist/joiner.node.js#L3235-L3254 |
43,377 | mhkeller/joiner | dist/joiner.node.js | baseUnset$1 | function baseUnset$1(object, path) {
path = castPath$3(path, object);
object = parent(object, path);
return object == null || delete object[toKey$3(last(path))];
} | javascript | function baseUnset$1(object, path) {
path = castPath$3(path, object);
object = parent(object, path);
return object == null || delete object[toKey$3(last(path))];
} | [
"function",
"baseUnset$1",
"(",
"object",
",",
"path",
")",
"{",
"path",
"=",
"castPath$3",
"(",
"path",
",",
"object",
")",
";",
"object",
"=",
"parent",
"(",
"object",
",",
"path",
")",
";",
"return",
"object",
"==",
"null",
"||",
"delete",
"object",
"[",
"toKey$3",
"(",
"last",
"(",
"path",
")",
")",
"]",
";",
"}"
]
| The base implementation of `_.unset`.
@private
@param {Object} object The object to modify.
@param {Array|string} path The property path to unset.
@returns {boolean} Returns `true` if the property is deleted, else `false`. | [
"The",
"base",
"implementation",
"of",
"_",
".",
"unset",
"."
]
| 97d3010f8b61e8899a4ca068cbf8d467de6dc4e6 | https://github.com/mhkeller/joiner/blob/97d3010f8b61e8899a4ca068cbf8d467de6dc4e6/dist/joiner.node.js#L3288-L3292 |
43,378 | mhkeller/joiner | dist/joiner.node.js | baseFindIndex$1 | function baseFindIndex$1(array, predicate, fromIndex, fromRight) {
var length = array.length,
index = fromIndex + (fromRight ? 1 : -1);
while (fromRight ? index-- : ++index < length) {
if (predicate(array[index], index, array)) {
return index;
}
}
return -1;
} | javascript | function baseFindIndex$1(array, predicate, fromIndex, fromRight) {
var length = array.length,
index = fromIndex + (fromRight ? 1 : -1);
while (fromRight ? index-- : ++index < length) {
if (predicate(array[index], index, array)) {
return index;
}
}
return -1;
} | [
"function",
"baseFindIndex$1",
"(",
"array",
",",
"predicate",
",",
"fromIndex",
",",
"fromRight",
")",
"{",
"var",
"length",
"=",
"array",
".",
"length",
",",
"index",
"=",
"fromIndex",
"+",
"(",
"fromRight",
"?",
"1",
":",
"-",
"1",
")",
";",
"while",
"(",
"fromRight",
"?",
"index",
"--",
":",
"++",
"index",
"<",
"length",
")",
"{",
"if",
"(",
"predicate",
"(",
"array",
"[",
"index",
"]",
",",
"index",
",",
"array",
")",
")",
"{",
"return",
"index",
";",
"}",
"}",
"return",
"-",
"1",
";",
"}"
]
| The base implementation of `_.findIndex` and `_.findLastIndex` without
support for iteratee shorthands.
@private
@param {Array} array The array to inspect.
@param {Function} predicate The function invoked per iteration.
@param {number} fromIndex The index to search from.
@param {boolean} [fromRight] Specify iterating from right to left.
@returns {number} Returns the index of the matched value, else `-1`. | [
"The",
"base",
"implementation",
"of",
"_",
".",
"findIndex",
"and",
"_",
".",
"findLastIndex",
"without",
"support",
"for",
"iteratee",
"shorthands",
"."
]
| 97d3010f8b61e8899a4ca068cbf8d467de6dc4e6 | https://github.com/mhkeller/joiner/blob/97d3010f8b61e8899a4ca068cbf8d467de6dc4e6/dist/joiner.node.js#L3405-L3415 |
43,379 | mhkeller/joiner | dist/joiner.node.js | baseIndexOf$1 | function baseIndexOf$1(array, value, fromIndex) {
return value === value ? strictIndexOf(array, value, fromIndex) : baseFindIndex(array, baseIsNaN, fromIndex);
} | javascript | function baseIndexOf$1(array, value, fromIndex) {
return value === value ? strictIndexOf(array, value, fromIndex) : baseFindIndex(array, baseIsNaN, fromIndex);
} | [
"function",
"baseIndexOf$1",
"(",
"array",
",",
"value",
",",
"fromIndex",
")",
"{",
"return",
"value",
"===",
"value",
"?",
"strictIndexOf",
"(",
"array",
",",
"value",
",",
"fromIndex",
")",
":",
"baseFindIndex",
"(",
"array",
",",
"baseIsNaN",
",",
"fromIndex",
")",
";",
"}"
]
| The base implementation of `_.indexOf` without `fromIndex` bounds checks.
@private
@param {Array} array The array to inspect.
@param {*} value The value to search for.
@param {number} fromIndex The index to search from.
@returns {number} Returns the index of the matched value, else `-1`. | [
"The",
"base",
"implementation",
"of",
"_",
".",
"indexOf",
"without",
"fromIndex",
"bounds",
"checks",
"."
]
| 97d3010f8b61e8899a4ca068cbf8d467de6dc4e6 | https://github.com/mhkeller/joiner/blob/97d3010f8b61e8899a4ca068cbf8d467de6dc4e6/dist/joiner.node.js#L3469-L3471 |
43,380 | mhkeller/joiner | dist/joiner.node.js | shortOut$1 | function shortOut$1(func) {
var count = 0,
lastCalled = 0;
return function () {
var stamp = nativeNow(),
remaining = HOT_SPAN - (stamp - lastCalled);
lastCalled = stamp;
if (remaining > 0) {
if (++count >= HOT_COUNT) {
return arguments[0];
}
} else {
count = 0;
}
return func.apply(undefined, arguments);
};
} | javascript | function shortOut$1(func) {
var count = 0,
lastCalled = 0;
return function () {
var stamp = nativeNow(),
remaining = HOT_SPAN - (stamp - lastCalled);
lastCalled = stamp;
if (remaining > 0) {
if (++count >= HOT_COUNT) {
return arguments[0];
}
} else {
count = 0;
}
return func.apply(undefined, arguments);
};
} | [
"function",
"shortOut$1",
"(",
"func",
")",
"{",
"var",
"count",
"=",
"0",
",",
"lastCalled",
"=",
"0",
";",
"return",
"function",
"(",
")",
"{",
"var",
"stamp",
"=",
"nativeNow",
"(",
")",
",",
"remaining",
"=",
"HOT_SPAN",
"-",
"(",
"stamp",
"-",
"lastCalled",
")",
";",
"lastCalled",
"=",
"stamp",
";",
"if",
"(",
"remaining",
">",
"0",
")",
"{",
"if",
"(",
"++",
"count",
">=",
"HOT_COUNT",
")",
"{",
"return",
"arguments",
"[",
"0",
"]",
";",
"}",
"}",
"else",
"{",
"count",
"=",
"0",
";",
"}",
"return",
"func",
".",
"apply",
"(",
"undefined",
",",
"arguments",
")",
";",
"}",
";",
"}"
]
| Creates a function that'll short out and invoke `identity` instead
of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
milliseconds.
@private
@param {Function} func The function to restrict.
@returns {Function} Returns the new shortable function. | [
"Creates",
"a",
"function",
"that",
"ll",
"short",
"out",
"and",
"invoke",
"identity",
"instead",
"of",
"func",
"when",
"it",
"s",
"called",
"HOT_COUNT",
"or",
"more",
"times",
"in",
"HOT_SPAN",
"milliseconds",
"."
]
| 97d3010f8b61e8899a4ca068cbf8d467de6dc4e6 | https://github.com/mhkeller/joiner/blob/97d3010f8b61e8899a4ca068cbf8d467de6dc4e6/dist/joiner.node.js#L3747-L3765 |
43,381 | mhkeller/joiner | dist/joiner.node.js | baseDifference$1 | function baseDifference$1(array, values, iteratee, comparator) {
var index = -1,
includes = arrayIncludes$2,
isCommon = true,
length = array.length,
result = [],
valuesLength = values.length;
if (!length) {
return result;
}
if (iteratee) {
values = arrayMap$4(values, baseUnary$3(iteratee));
}
if (comparator) {
includes = arrayIncludesWith$2;
isCommon = false;
} else if (values.length >= LARGE_ARRAY_SIZE$1) {
includes = cacheHas$2;
isCommon = false;
values = new SetCache$2(values);
}
outer: while (++index < length) {
var value = array[index],
computed = iteratee == null ? value : iteratee(value);
value = comparator || value !== 0 ? value : 0;
if (isCommon && computed === computed) {
var valuesIndex = valuesLength;
while (valuesIndex--) {
if (values[valuesIndex] === computed) {
continue outer;
}
}
result.push(value);
} else if (!includes(values, computed, comparator)) {
result.push(value);
}
}
return result;
} | javascript | function baseDifference$1(array, values, iteratee, comparator) {
var index = -1,
includes = arrayIncludes$2,
isCommon = true,
length = array.length,
result = [],
valuesLength = values.length;
if (!length) {
return result;
}
if (iteratee) {
values = arrayMap$4(values, baseUnary$3(iteratee));
}
if (comparator) {
includes = arrayIncludesWith$2;
isCommon = false;
} else if (values.length >= LARGE_ARRAY_SIZE$1) {
includes = cacheHas$2;
isCommon = false;
values = new SetCache$2(values);
}
outer: while (++index < length) {
var value = array[index],
computed = iteratee == null ? value : iteratee(value);
value = comparator || value !== 0 ? value : 0;
if (isCommon && computed === computed) {
var valuesIndex = valuesLength;
while (valuesIndex--) {
if (values[valuesIndex] === computed) {
continue outer;
}
}
result.push(value);
} else if (!includes(values, computed, comparator)) {
result.push(value);
}
}
return result;
} | [
"function",
"baseDifference$1",
"(",
"array",
",",
"values",
",",
"iteratee",
",",
"comparator",
")",
"{",
"var",
"index",
"=",
"-",
"1",
",",
"includes",
"=",
"arrayIncludes$2",
",",
"isCommon",
"=",
"true",
",",
"length",
"=",
"array",
".",
"length",
",",
"result",
"=",
"[",
"]",
",",
"valuesLength",
"=",
"values",
".",
"length",
";",
"if",
"(",
"!",
"length",
")",
"{",
"return",
"result",
";",
"}",
"if",
"(",
"iteratee",
")",
"{",
"values",
"=",
"arrayMap$4",
"(",
"values",
",",
"baseUnary$3",
"(",
"iteratee",
")",
")",
";",
"}",
"if",
"(",
"comparator",
")",
"{",
"includes",
"=",
"arrayIncludesWith$2",
";",
"isCommon",
"=",
"false",
";",
"}",
"else",
"if",
"(",
"values",
".",
"length",
">=",
"LARGE_ARRAY_SIZE$1",
")",
"{",
"includes",
"=",
"cacheHas$2",
";",
"isCommon",
"=",
"false",
";",
"values",
"=",
"new",
"SetCache$2",
"(",
"values",
")",
";",
"}",
"outer",
":",
"while",
"(",
"++",
"index",
"<",
"length",
")",
"{",
"var",
"value",
"=",
"array",
"[",
"index",
"]",
",",
"computed",
"=",
"iteratee",
"==",
"null",
"?",
"value",
":",
"iteratee",
"(",
"value",
")",
";",
"value",
"=",
"comparator",
"||",
"value",
"!==",
"0",
"?",
"value",
":",
"0",
";",
"if",
"(",
"isCommon",
"&&",
"computed",
"===",
"computed",
")",
"{",
"var",
"valuesIndex",
"=",
"valuesLength",
";",
"while",
"(",
"valuesIndex",
"--",
")",
"{",
"if",
"(",
"values",
"[",
"valuesIndex",
"]",
"===",
"computed",
")",
"{",
"continue",
"outer",
";",
"}",
"}",
"result",
".",
"push",
"(",
"value",
")",
";",
"}",
"else",
"if",
"(",
"!",
"includes",
"(",
"values",
",",
"computed",
",",
"comparator",
")",
")",
"{",
"result",
".",
"push",
"(",
"value",
")",
";",
"}",
"}",
"return",
"result",
";",
"}"
]
| The base implementation of methods like `_.difference` without support
for excluding multiple arrays or iteratee shorthands.
@private
@param {Array} array The array to inspect.
@param {Array} values The values to exclude.
@param {Function} [iteratee] The iteratee invoked per element.
@param {Function} [comparator] The comparator invoked per element.
@returns {Array} Returns the new array of filtered values. | [
"The",
"base",
"implementation",
"of",
"methods",
"like",
"_",
".",
"difference",
"without",
"support",
"for",
"excluding",
"multiple",
"arrays",
"or",
"iteratee",
"shorthands",
"."
]
| 97d3010f8b61e8899a4ca068cbf8d467de6dc4e6 | https://github.com/mhkeller/joiner/blob/97d3010f8b61e8899a4ca068cbf8d467de6dc4e6/dist/joiner.node.js#L3901-L3941 |
43,382 | mhkeller/joiner | dist/joiner.node.js | baseFlatten$1 | function baseFlatten$1(array, depth, predicate, isStrict, result) {
var index = -1,
length = array.length;
predicate || (predicate = isFlattenable);
result || (result = []);
while (++index < length) {
var value = array[index];
if (depth > 0 && predicate(value)) {
if (depth > 1) {
// Recursively flatten arrays (susceptible to call stack limits).
baseFlatten$1(value, depth - 1, predicate, isStrict, result);
} else {
arrayPush$3(result, value);
}
} else if (!isStrict) {
result[result.length] = value;
}
}
return result;
} | javascript | function baseFlatten$1(array, depth, predicate, isStrict, result) {
var index = -1,
length = array.length;
predicate || (predicate = isFlattenable);
result || (result = []);
while (++index < length) {
var value = array[index];
if (depth > 0 && predicate(value)) {
if (depth > 1) {
// Recursively flatten arrays (susceptible to call stack limits).
baseFlatten$1(value, depth - 1, predicate, isStrict, result);
} else {
arrayPush$3(result, value);
}
} else if (!isStrict) {
result[result.length] = value;
}
}
return result;
} | [
"function",
"baseFlatten$1",
"(",
"array",
",",
"depth",
",",
"predicate",
",",
"isStrict",
",",
"result",
")",
"{",
"var",
"index",
"=",
"-",
"1",
",",
"length",
"=",
"array",
".",
"length",
";",
"predicate",
"||",
"(",
"predicate",
"=",
"isFlattenable",
")",
";",
"result",
"||",
"(",
"result",
"=",
"[",
"]",
")",
";",
"while",
"(",
"++",
"index",
"<",
"length",
")",
"{",
"var",
"value",
"=",
"array",
"[",
"index",
"]",
";",
"if",
"(",
"depth",
">",
"0",
"&&",
"predicate",
"(",
"value",
")",
")",
"{",
"if",
"(",
"depth",
">",
"1",
")",
"{",
"// Recursively flatten arrays (susceptible to call stack limits).",
"baseFlatten$1",
"(",
"value",
",",
"depth",
"-",
"1",
",",
"predicate",
",",
"isStrict",
",",
"result",
")",
";",
"}",
"else",
"{",
"arrayPush$3",
"(",
"result",
",",
"value",
")",
";",
"}",
"}",
"else",
"if",
"(",
"!",
"isStrict",
")",
"{",
"result",
"[",
"result",
".",
"length",
"]",
"=",
"value",
";",
"}",
"}",
"return",
"result",
";",
"}"
]
| The base implementation of `_.flatten` with support for restricting flattening.
@private
@param {Array} array The array to flatten.
@param {number} depth The maximum recursion depth.
@param {boolean} [predicate=isFlattenable] The function invoked per iteration.
@param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
@param {Array} [result=[]] The initial result value.
@returns {Array} Returns the new flattened array. | [
"The",
"base",
"implementation",
"of",
"_",
".",
"flatten",
"with",
"support",
"for",
"restricting",
"flattening",
"."
]
| 97d3010f8b61e8899a4ca068cbf8d467de6dc4e6 | https://github.com/mhkeller/joiner/blob/97d3010f8b61e8899a4ca068cbf8d467de6dc4e6/dist/joiner.node.js#L3979-L4000 |
43,383 | krauskopf/node-red-contrib-avr-yamaha | avr-yamaha.js | function() {
if (node.debug) {
node.log('STARTING event listener');
}
var net = require('net');
var dgram = require('dgram');
node.inputSocket = dgram.createSocket({type:'udp4', reuseAddr: true});
node.inputSocket.on('notify', function (event) {
if (node.debug) {
node.log('Got a notification.', event)
}
});
node.inputSocket.on('message', function (msg, rinfo) {
//node.log("[" + rinfo.address + "] --> " + msg.toString());
if (rinfo.address == node.address) {
if (node.debug) {
node.log("UPnP Event from [" + rinfo.address + "] --> " );//+ msg.toString());
}
// Split to header and body
msg = msg.toString().split('\r\n\r\n');
var header = msg[0];
var body = msg[1];
// Ignore UPNP search requests
var method = header.split('\r\n').shift().split(' ').shift().trim();
if (method == 'M-SEARCH'){
return;
}
// Parse rest of header
var arr = header.match(/[^\r\n]+/g);
var headerInfo = {};
for (var i = 1; i < arr.length; ++i){
var tem = arr[i].split(/:(.+)?/);
if (typeof(tem[1]) == 'string'){ tem[1] = tem[1].trim(); }
headerInfo[tem[0].toLowerCase()] = tem[1];
};
//node.log("METHOD: " + method);
//node.log("BODY: " + body);
//node.log("NTS: " + headerInfo['nts']);
// NOTIFY messages tell us about the properties that changed
if (method == 'NOTIFY' && headerInfo['nts'] == 'yamaha:propchange') {
var parseString = require('xml2js').parseString;
parseString(body, function (err, result) {
if (err) {
node.error('Failed to parse the event with error: ' + err);
return;
}
// Check the received object
var zoneName = undefined;
if (result.hasOwnProperty('YAMAHA_AV')) {
if (result.YAMAHA_AV.hasOwnProperty('Main_Zone')) {
zoneName = 'Main_Zone';
} else if (result.YAMAHA_AV.hasOwnProperty('Zone_2')) {
zoneName = 'Zone_2';
} else if (result.YAMAHA_AV.hasOwnProperty('Zone_3')) {
zoneName = 'Zone_3';
} else if (result.YAMAHA_AV.hasOwnProperty('Zone_4')) {
zoneName = 'Zone_4';
}
}
if (zoneName === undefined
|| result.YAMAHA_AV[zoneName] === undefined
|| result.YAMAHA_AV[zoneName][0] === undefined) {
if (node.debug) {
node.warn('Unknown event message format: ' + JSON.stringify(result));
}
return;
}
for (var i in result.YAMAHA_AV[zoneName][0].Property) {
var prop = result.YAMAHA_AV[zoneName][0].Property[i];
if (node.debug) {
node.log('Property-Change: ' + prop);
}
// Event Notification only notifies that there is a change in each item.
// It is necessary to issue the GET command to obtain the content of the item with the change.
if (prop == 'Power') {
// Get current power state and publish to all subscriber.
node.sendGetCommand(zoneName + '.Power_Control.Power').then(function(value) {
for (var s in node.subscriptions) {
node.subscriptions[s].handler(zoneName + '.Power_Control.Power', value);
}
}).catch(function(error) {
node.error('Failed to request data from AVR with error: ' + error);
});
} else if (prop == 'Input') {
// Get current input selection and publish to all subscriber.
node.sendGetCommand(zoneName + '.Input.Input_Sel').then(function(value) {
for (var s in node.subscriptions) {
node.subscriptions[s].handler(zoneName + '.Input.Input_Sel', value);
}
}).catch(function(error) {
node.error('Failed to request data from AVR with error: ' + error);
});
} else if (prop == 'Volume') {
// We don't know from the event itself if volume changed or mute/unmute was pressed.
// Therefore we read both states.
node.sendGetCommand(zoneName + '.Volume.Lvl').then(function(value) {
for (var s in node.subscriptions) {
node.subscriptions[s].handler(zoneName + '.Volume.Lvl', value);
}
}).catch(function(error) {
node.error('Failed to request data from AVR with error: ' + error);
});
node.sendGetCommand(zoneName + '.Volume.Mute').then(function(value) {
for (var s in node.subscriptions) {
node.subscriptions[s].handler(zoneName + '.Volume.Mute', value);
}
}).catch(function(error) {
node.error('Failed to request data from AVR with error: ' + error);
});
} else if (prop == 'Play_Info') {
// When getting the Play_Info event we need to check the current input mode and then read
// the corresponding item that holds info about current mode.
node.sendGetCommand(zoneName + '.Input.Input_Sel').then(function(value) {
var validInputs = {
'TUNER': 'Tuner', 'Napster': 'Napster', 'Spotify': 'Spotify', 'JUKE': 'JUKE', 'SERVER': 'SERVER',
'NET RADIO': 'NET_RADIO', 'USB': 'USB', 'iPod_USB': 'iPod_USB', 'AirPlay': 'AirPlay'
};
if (validInputs.hasOwnProperty(value)) {
node.sendGetCommand(validInputs[value] + '.Play_Info').then(function(value2) {
for (var s in node.subscriptions) {
node.subscriptions[s].handler(value + '.Play_Info', value2);
}
}).catch(function(error) {
node.error('Received event Play_Info but failed to read play info of current input selection: ' + error);
});
} else {
if (node.debug) {
node.log('Received event Play_Info but do not know or support current input selection ' + value);
}
}
}).catch(function(error) {
node.error('Received event Play_Info but failed to read current input selection: ' + error);
});
} else if (prop == 'List_Info') {
// When getting the List_info event we need to check the current input mode and then read
// the corresponding item that holds info about current mode.
node.sendGetCommand(zoneName + '.Input.Input_Sel').then(function(value) {
var validInputs = {
'Napster': 'Napster', 'JUKE': 'JUKE', 'SERVER': 'SERVER',
'NET RADIO': 'NET_RADIO', 'USB': 'USB', 'iPod_USB': 'iPod_USB'
};
if (validInputs.hasOwnProperty(value)) {
node.sendGetCommand(validInputs[value] + '.List_Info').then(function(value2) {
for (var s in node.subscriptions) {
node.subscriptions[s].handler(value + '.List_Info', value2);
}
}).catch(function(error) {
node.error('Received event List_Info but failed to read play info of current input selection: ' + error);
});
} else {
if (node.debug) {
node.log('Received event List_Info but do not know or support current input selection ' + value);
}
}
}).catch(function(error) {
node.error('Received event List_Info but failed to read current input selection: ' + error);
});
} else {
// The event is not known. Maybe the AVR is too new.
if (node.debug) {
node.log('Received unsupported Property-Change via multicast: ' + prop);
}
return;
}
}
});
}
}
});
node.inputSocket.on('listening', function () {
try {
var address = node.inputSocket.address();
node.log('UDP client listening on ' + address.address + ":" + address.port);
node.inputSocket.setBroadcast(true)
node.inputSocket.setMulticastTTL(5);
node.inputSocket.addMembership('239.255.255.250');
//node.inputSocket.addMembership('239.255.255.250', '192.168.0.101');
//node.inputSocket.addMembership('239.255.255.250', '127.0.0.1');
/*
var message = new Buffer(
"M-SEARCH * HTTP/1.1\r\n" +
"HOST: 239.255.255.250:1900\r\n" +
"MAN: \"ssdp:discover\"\r\n" +
"ST: ssdp:all\r\n" + // Essential, used by the client to specify what they want to discover, eg 'ST:ge:fridge'
"MX: 3\r\n" + // 1 second to respond (but they all respond immediately?)
"\r\n");
*/
//node.inputSocket.send(message, 0, message.length, 1900, "239.255.255.250");
} catch (err) {
node.warn('Cannot bind address for UPNP event listener. Port probably already in use. Error: ' + err);
}
});
try {
node.inputSocket.bind(1900);
}
catch (err) {
node.warn('Cannot bind address for UPNP event listener. Port probably already in use. Error: ' + err);
}
} | javascript | function() {
if (node.debug) {
node.log('STARTING event listener');
}
var net = require('net');
var dgram = require('dgram');
node.inputSocket = dgram.createSocket({type:'udp4', reuseAddr: true});
node.inputSocket.on('notify', function (event) {
if (node.debug) {
node.log('Got a notification.', event)
}
});
node.inputSocket.on('message', function (msg, rinfo) {
//node.log("[" + rinfo.address + "] --> " + msg.toString());
if (rinfo.address == node.address) {
if (node.debug) {
node.log("UPnP Event from [" + rinfo.address + "] --> " );//+ msg.toString());
}
// Split to header and body
msg = msg.toString().split('\r\n\r\n');
var header = msg[0];
var body = msg[1];
// Ignore UPNP search requests
var method = header.split('\r\n').shift().split(' ').shift().trim();
if (method == 'M-SEARCH'){
return;
}
// Parse rest of header
var arr = header.match(/[^\r\n]+/g);
var headerInfo = {};
for (var i = 1; i < arr.length; ++i){
var tem = arr[i].split(/:(.+)?/);
if (typeof(tem[1]) == 'string'){ tem[1] = tem[1].trim(); }
headerInfo[tem[0].toLowerCase()] = tem[1];
};
//node.log("METHOD: " + method);
//node.log("BODY: " + body);
//node.log("NTS: " + headerInfo['nts']);
// NOTIFY messages tell us about the properties that changed
if (method == 'NOTIFY' && headerInfo['nts'] == 'yamaha:propchange') {
var parseString = require('xml2js').parseString;
parseString(body, function (err, result) {
if (err) {
node.error('Failed to parse the event with error: ' + err);
return;
}
// Check the received object
var zoneName = undefined;
if (result.hasOwnProperty('YAMAHA_AV')) {
if (result.YAMAHA_AV.hasOwnProperty('Main_Zone')) {
zoneName = 'Main_Zone';
} else if (result.YAMAHA_AV.hasOwnProperty('Zone_2')) {
zoneName = 'Zone_2';
} else if (result.YAMAHA_AV.hasOwnProperty('Zone_3')) {
zoneName = 'Zone_3';
} else if (result.YAMAHA_AV.hasOwnProperty('Zone_4')) {
zoneName = 'Zone_4';
}
}
if (zoneName === undefined
|| result.YAMAHA_AV[zoneName] === undefined
|| result.YAMAHA_AV[zoneName][0] === undefined) {
if (node.debug) {
node.warn('Unknown event message format: ' + JSON.stringify(result));
}
return;
}
for (var i in result.YAMAHA_AV[zoneName][0].Property) {
var prop = result.YAMAHA_AV[zoneName][0].Property[i];
if (node.debug) {
node.log('Property-Change: ' + prop);
}
// Event Notification only notifies that there is a change in each item.
// It is necessary to issue the GET command to obtain the content of the item with the change.
if (prop == 'Power') {
// Get current power state and publish to all subscriber.
node.sendGetCommand(zoneName + '.Power_Control.Power').then(function(value) {
for (var s in node.subscriptions) {
node.subscriptions[s].handler(zoneName + '.Power_Control.Power', value);
}
}).catch(function(error) {
node.error('Failed to request data from AVR with error: ' + error);
});
} else if (prop == 'Input') {
// Get current input selection and publish to all subscriber.
node.sendGetCommand(zoneName + '.Input.Input_Sel').then(function(value) {
for (var s in node.subscriptions) {
node.subscriptions[s].handler(zoneName + '.Input.Input_Sel', value);
}
}).catch(function(error) {
node.error('Failed to request data from AVR with error: ' + error);
});
} else if (prop == 'Volume') {
// We don't know from the event itself if volume changed or mute/unmute was pressed.
// Therefore we read both states.
node.sendGetCommand(zoneName + '.Volume.Lvl').then(function(value) {
for (var s in node.subscriptions) {
node.subscriptions[s].handler(zoneName + '.Volume.Lvl', value);
}
}).catch(function(error) {
node.error('Failed to request data from AVR with error: ' + error);
});
node.sendGetCommand(zoneName + '.Volume.Mute').then(function(value) {
for (var s in node.subscriptions) {
node.subscriptions[s].handler(zoneName + '.Volume.Mute', value);
}
}).catch(function(error) {
node.error('Failed to request data from AVR with error: ' + error);
});
} else if (prop == 'Play_Info') {
// When getting the Play_Info event we need to check the current input mode and then read
// the corresponding item that holds info about current mode.
node.sendGetCommand(zoneName + '.Input.Input_Sel').then(function(value) {
var validInputs = {
'TUNER': 'Tuner', 'Napster': 'Napster', 'Spotify': 'Spotify', 'JUKE': 'JUKE', 'SERVER': 'SERVER',
'NET RADIO': 'NET_RADIO', 'USB': 'USB', 'iPod_USB': 'iPod_USB', 'AirPlay': 'AirPlay'
};
if (validInputs.hasOwnProperty(value)) {
node.sendGetCommand(validInputs[value] + '.Play_Info').then(function(value2) {
for (var s in node.subscriptions) {
node.subscriptions[s].handler(value + '.Play_Info', value2);
}
}).catch(function(error) {
node.error('Received event Play_Info but failed to read play info of current input selection: ' + error);
});
} else {
if (node.debug) {
node.log('Received event Play_Info but do not know or support current input selection ' + value);
}
}
}).catch(function(error) {
node.error('Received event Play_Info but failed to read current input selection: ' + error);
});
} else if (prop == 'List_Info') {
// When getting the List_info event we need to check the current input mode and then read
// the corresponding item that holds info about current mode.
node.sendGetCommand(zoneName + '.Input.Input_Sel').then(function(value) {
var validInputs = {
'Napster': 'Napster', 'JUKE': 'JUKE', 'SERVER': 'SERVER',
'NET RADIO': 'NET_RADIO', 'USB': 'USB', 'iPod_USB': 'iPod_USB'
};
if (validInputs.hasOwnProperty(value)) {
node.sendGetCommand(validInputs[value] + '.List_Info').then(function(value2) {
for (var s in node.subscriptions) {
node.subscriptions[s].handler(value + '.List_Info', value2);
}
}).catch(function(error) {
node.error('Received event List_Info but failed to read play info of current input selection: ' + error);
});
} else {
if (node.debug) {
node.log('Received event List_Info but do not know or support current input selection ' + value);
}
}
}).catch(function(error) {
node.error('Received event List_Info but failed to read current input selection: ' + error);
});
} else {
// The event is not known. Maybe the AVR is too new.
if (node.debug) {
node.log('Received unsupported Property-Change via multicast: ' + prop);
}
return;
}
}
});
}
}
});
node.inputSocket.on('listening', function () {
try {
var address = node.inputSocket.address();
node.log('UDP client listening on ' + address.address + ":" + address.port);
node.inputSocket.setBroadcast(true)
node.inputSocket.setMulticastTTL(5);
node.inputSocket.addMembership('239.255.255.250');
//node.inputSocket.addMembership('239.255.255.250', '192.168.0.101');
//node.inputSocket.addMembership('239.255.255.250', '127.0.0.1');
/*
var message = new Buffer(
"M-SEARCH * HTTP/1.1\r\n" +
"HOST: 239.255.255.250:1900\r\n" +
"MAN: \"ssdp:discover\"\r\n" +
"ST: ssdp:all\r\n" + // Essential, used by the client to specify what they want to discover, eg 'ST:ge:fridge'
"MX: 3\r\n" + // 1 second to respond (but they all respond immediately?)
"\r\n");
*/
//node.inputSocket.send(message, 0, message.length, 1900, "239.255.255.250");
} catch (err) {
node.warn('Cannot bind address for UPNP event listener. Port probably already in use. Error: ' + err);
}
});
try {
node.inputSocket.bind(1900);
}
catch (err) {
node.warn('Cannot bind address for UPNP event listener. Port probably already in use. Error: ' + err);
}
} | [
"function",
"(",
")",
"{",
"if",
"(",
"node",
".",
"debug",
")",
"{",
"node",
".",
"log",
"(",
"'STARTING event listener'",
")",
";",
"}",
"var",
"net",
"=",
"require",
"(",
"'net'",
")",
";",
"var",
"dgram",
"=",
"require",
"(",
"'dgram'",
")",
";",
"node",
".",
"inputSocket",
"=",
"dgram",
".",
"createSocket",
"(",
"{",
"type",
":",
"'udp4'",
",",
"reuseAddr",
":",
"true",
"}",
")",
";",
"node",
".",
"inputSocket",
".",
"on",
"(",
"'notify'",
",",
"function",
"(",
"event",
")",
"{",
"if",
"(",
"node",
".",
"debug",
")",
"{",
"node",
".",
"log",
"(",
"'Got a notification.'",
",",
"event",
")",
"}",
"}",
")",
";",
"node",
".",
"inputSocket",
".",
"on",
"(",
"'message'",
",",
"function",
"(",
"msg",
",",
"rinfo",
")",
"{",
"//node.log(\"[\" + rinfo.address + \"] --> \" + msg.toString());",
"if",
"(",
"rinfo",
".",
"address",
"==",
"node",
".",
"address",
")",
"{",
"if",
"(",
"node",
".",
"debug",
")",
"{",
"node",
".",
"log",
"(",
"\"UPnP Event from [\"",
"+",
"rinfo",
".",
"address",
"+",
"\"] --> \"",
")",
";",
"//+ msg.toString());",
"}",
"// Split to header and body",
"msg",
"=",
"msg",
".",
"toString",
"(",
")",
".",
"split",
"(",
"'\\r\\n\\r\\n'",
")",
";",
"var",
"header",
"=",
"msg",
"[",
"0",
"]",
";",
"var",
"body",
"=",
"msg",
"[",
"1",
"]",
";",
"// Ignore UPNP search requests",
"var",
"method",
"=",
"header",
".",
"split",
"(",
"'\\r\\n'",
")",
".",
"shift",
"(",
")",
".",
"split",
"(",
"' '",
")",
".",
"shift",
"(",
")",
".",
"trim",
"(",
")",
";",
"if",
"(",
"method",
"==",
"'M-SEARCH'",
")",
"{",
"return",
";",
"}",
"// Parse rest of header",
"var",
"arr",
"=",
"header",
".",
"match",
"(",
"/",
"[^\\r\\n]+",
"/",
"g",
")",
";",
"var",
"headerInfo",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"i",
"=",
"1",
";",
"i",
"<",
"arr",
".",
"length",
";",
"++",
"i",
")",
"{",
"var",
"tem",
"=",
"arr",
"[",
"i",
"]",
".",
"split",
"(",
"/",
":(.+)?",
"/",
")",
";",
"if",
"(",
"typeof",
"(",
"tem",
"[",
"1",
"]",
")",
"==",
"'string'",
")",
"{",
"tem",
"[",
"1",
"]",
"=",
"tem",
"[",
"1",
"]",
".",
"trim",
"(",
")",
";",
"}",
"headerInfo",
"[",
"tem",
"[",
"0",
"]",
".",
"toLowerCase",
"(",
")",
"]",
"=",
"tem",
"[",
"1",
"]",
";",
"}",
";",
"//node.log(\"METHOD: \" + method);",
"//node.log(\"BODY: \" + body);",
"//node.log(\"NTS: \" + headerInfo['nts']);",
"// NOTIFY messages tell us about the properties that changed",
"if",
"(",
"method",
"==",
"'NOTIFY'",
"&&",
"headerInfo",
"[",
"'nts'",
"]",
"==",
"'yamaha:propchange'",
")",
"{",
"var",
"parseString",
"=",
"require",
"(",
"'xml2js'",
")",
".",
"parseString",
";",
"parseString",
"(",
"body",
",",
"function",
"(",
"err",
",",
"result",
")",
"{",
"if",
"(",
"err",
")",
"{",
"node",
".",
"error",
"(",
"'Failed to parse the event with error: '",
"+",
"err",
")",
";",
"return",
";",
"}",
"// Check the received object",
"var",
"zoneName",
"=",
"undefined",
";",
"if",
"(",
"result",
".",
"hasOwnProperty",
"(",
"'YAMAHA_AV'",
")",
")",
"{",
"if",
"(",
"result",
".",
"YAMAHA_AV",
".",
"hasOwnProperty",
"(",
"'Main_Zone'",
")",
")",
"{",
"zoneName",
"=",
"'Main_Zone'",
";",
"}",
"else",
"if",
"(",
"result",
".",
"YAMAHA_AV",
".",
"hasOwnProperty",
"(",
"'Zone_2'",
")",
")",
"{",
"zoneName",
"=",
"'Zone_2'",
";",
"}",
"else",
"if",
"(",
"result",
".",
"YAMAHA_AV",
".",
"hasOwnProperty",
"(",
"'Zone_3'",
")",
")",
"{",
"zoneName",
"=",
"'Zone_3'",
";",
"}",
"else",
"if",
"(",
"result",
".",
"YAMAHA_AV",
".",
"hasOwnProperty",
"(",
"'Zone_4'",
")",
")",
"{",
"zoneName",
"=",
"'Zone_4'",
";",
"}",
"}",
"if",
"(",
"zoneName",
"===",
"undefined",
"||",
"result",
".",
"YAMAHA_AV",
"[",
"zoneName",
"]",
"===",
"undefined",
"||",
"result",
".",
"YAMAHA_AV",
"[",
"zoneName",
"]",
"[",
"0",
"]",
"===",
"undefined",
")",
"{",
"if",
"(",
"node",
".",
"debug",
")",
"{",
"node",
".",
"warn",
"(",
"'Unknown event message format: '",
"+",
"JSON",
".",
"stringify",
"(",
"result",
")",
")",
";",
"}",
"return",
";",
"}",
"for",
"(",
"var",
"i",
"in",
"result",
".",
"YAMAHA_AV",
"[",
"zoneName",
"]",
"[",
"0",
"]",
".",
"Property",
")",
"{",
"var",
"prop",
"=",
"result",
".",
"YAMAHA_AV",
"[",
"zoneName",
"]",
"[",
"0",
"]",
".",
"Property",
"[",
"i",
"]",
";",
"if",
"(",
"node",
".",
"debug",
")",
"{",
"node",
".",
"log",
"(",
"'Property-Change: '",
"+",
"prop",
")",
";",
"}",
"// Event Notification only notifies that there is a change in each item.",
"// It is necessary to issue the GET command to obtain the content of the item with the change.",
"if",
"(",
"prop",
"==",
"'Power'",
")",
"{",
"// Get current power state and publish to all subscriber.",
"node",
".",
"sendGetCommand",
"(",
"zoneName",
"+",
"'.Power_Control.Power'",
")",
".",
"then",
"(",
"function",
"(",
"value",
")",
"{",
"for",
"(",
"var",
"s",
"in",
"node",
".",
"subscriptions",
")",
"{",
"node",
".",
"subscriptions",
"[",
"s",
"]",
".",
"handler",
"(",
"zoneName",
"+",
"'.Power_Control.Power'",
",",
"value",
")",
";",
"}",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"error",
")",
"{",
"node",
".",
"error",
"(",
"'Failed to request data from AVR with error: '",
"+",
"error",
")",
";",
"}",
")",
";",
"}",
"else",
"if",
"(",
"prop",
"==",
"'Input'",
")",
"{",
"// Get current input selection and publish to all subscriber.",
"node",
".",
"sendGetCommand",
"(",
"zoneName",
"+",
"'.Input.Input_Sel'",
")",
".",
"then",
"(",
"function",
"(",
"value",
")",
"{",
"for",
"(",
"var",
"s",
"in",
"node",
".",
"subscriptions",
")",
"{",
"node",
".",
"subscriptions",
"[",
"s",
"]",
".",
"handler",
"(",
"zoneName",
"+",
"'.Input.Input_Sel'",
",",
"value",
")",
";",
"}",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"error",
")",
"{",
"node",
".",
"error",
"(",
"'Failed to request data from AVR with error: '",
"+",
"error",
")",
";",
"}",
")",
";",
"}",
"else",
"if",
"(",
"prop",
"==",
"'Volume'",
")",
"{",
"// We don't know from the event itself if volume changed or mute/unmute was pressed.",
"// Therefore we read both states.",
"node",
".",
"sendGetCommand",
"(",
"zoneName",
"+",
"'.Volume.Lvl'",
")",
".",
"then",
"(",
"function",
"(",
"value",
")",
"{",
"for",
"(",
"var",
"s",
"in",
"node",
".",
"subscriptions",
")",
"{",
"node",
".",
"subscriptions",
"[",
"s",
"]",
".",
"handler",
"(",
"zoneName",
"+",
"'.Volume.Lvl'",
",",
"value",
")",
";",
"}",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"error",
")",
"{",
"node",
".",
"error",
"(",
"'Failed to request data from AVR with error: '",
"+",
"error",
")",
";",
"}",
")",
";",
"node",
".",
"sendGetCommand",
"(",
"zoneName",
"+",
"'.Volume.Mute'",
")",
".",
"then",
"(",
"function",
"(",
"value",
")",
"{",
"for",
"(",
"var",
"s",
"in",
"node",
".",
"subscriptions",
")",
"{",
"node",
".",
"subscriptions",
"[",
"s",
"]",
".",
"handler",
"(",
"zoneName",
"+",
"'.Volume.Mute'",
",",
"value",
")",
";",
"}",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"error",
")",
"{",
"node",
".",
"error",
"(",
"'Failed to request data from AVR with error: '",
"+",
"error",
")",
";",
"}",
")",
";",
"}",
"else",
"if",
"(",
"prop",
"==",
"'Play_Info'",
")",
"{",
"// When getting the Play_Info event we need to check the current input mode and then read",
"// the corresponding item that holds info about current mode.",
"node",
".",
"sendGetCommand",
"(",
"zoneName",
"+",
"'.Input.Input_Sel'",
")",
".",
"then",
"(",
"function",
"(",
"value",
")",
"{",
"var",
"validInputs",
"=",
"{",
"'TUNER'",
":",
"'Tuner'",
",",
"'Napster'",
":",
"'Napster'",
",",
"'Spotify'",
":",
"'Spotify'",
",",
"'JUKE'",
":",
"'JUKE'",
",",
"'SERVER'",
":",
"'SERVER'",
",",
"'NET RADIO'",
":",
"'NET_RADIO'",
",",
"'USB'",
":",
"'USB'",
",",
"'iPod_USB'",
":",
"'iPod_USB'",
",",
"'AirPlay'",
":",
"'AirPlay'",
"}",
";",
"if",
"(",
"validInputs",
".",
"hasOwnProperty",
"(",
"value",
")",
")",
"{",
"node",
".",
"sendGetCommand",
"(",
"validInputs",
"[",
"value",
"]",
"+",
"'.Play_Info'",
")",
".",
"then",
"(",
"function",
"(",
"value2",
")",
"{",
"for",
"(",
"var",
"s",
"in",
"node",
".",
"subscriptions",
")",
"{",
"node",
".",
"subscriptions",
"[",
"s",
"]",
".",
"handler",
"(",
"value",
"+",
"'.Play_Info'",
",",
"value2",
")",
";",
"}",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"error",
")",
"{",
"node",
".",
"error",
"(",
"'Received event Play_Info but failed to read play info of current input selection: '",
"+",
"error",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"if",
"(",
"node",
".",
"debug",
")",
"{",
"node",
".",
"log",
"(",
"'Received event Play_Info but do not know or support current input selection '",
"+",
"value",
")",
";",
"}",
"}",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"error",
")",
"{",
"node",
".",
"error",
"(",
"'Received event Play_Info but failed to read current input selection: '",
"+",
"error",
")",
";",
"}",
")",
";",
"}",
"else",
"if",
"(",
"prop",
"==",
"'List_Info'",
")",
"{",
"// When getting the List_info event we need to check the current input mode and then read",
"// the corresponding item that holds info about current mode.",
"node",
".",
"sendGetCommand",
"(",
"zoneName",
"+",
"'.Input.Input_Sel'",
")",
".",
"then",
"(",
"function",
"(",
"value",
")",
"{",
"var",
"validInputs",
"=",
"{",
"'Napster'",
":",
"'Napster'",
",",
"'JUKE'",
":",
"'JUKE'",
",",
"'SERVER'",
":",
"'SERVER'",
",",
"'NET RADIO'",
":",
"'NET_RADIO'",
",",
"'USB'",
":",
"'USB'",
",",
"'iPod_USB'",
":",
"'iPod_USB'",
"}",
";",
"if",
"(",
"validInputs",
".",
"hasOwnProperty",
"(",
"value",
")",
")",
"{",
"node",
".",
"sendGetCommand",
"(",
"validInputs",
"[",
"value",
"]",
"+",
"'.List_Info'",
")",
".",
"then",
"(",
"function",
"(",
"value2",
")",
"{",
"for",
"(",
"var",
"s",
"in",
"node",
".",
"subscriptions",
")",
"{",
"node",
".",
"subscriptions",
"[",
"s",
"]",
".",
"handler",
"(",
"value",
"+",
"'.List_Info'",
",",
"value2",
")",
";",
"}",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"error",
")",
"{",
"node",
".",
"error",
"(",
"'Received event List_Info but failed to read play info of current input selection: '",
"+",
"error",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"if",
"(",
"node",
".",
"debug",
")",
"{",
"node",
".",
"log",
"(",
"'Received event List_Info but do not know or support current input selection '",
"+",
"value",
")",
";",
"}",
"}",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"error",
")",
"{",
"node",
".",
"error",
"(",
"'Received event List_Info but failed to read current input selection: '",
"+",
"error",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"// The event is not known. Maybe the AVR is too new.",
"if",
"(",
"node",
".",
"debug",
")",
"{",
"node",
".",
"log",
"(",
"'Received unsupported Property-Change via multicast: '",
"+",
"prop",
")",
";",
"}",
"return",
";",
"}",
"}",
"}",
")",
";",
"}",
"}",
"}",
")",
";",
"node",
".",
"inputSocket",
".",
"on",
"(",
"'listening'",
",",
"function",
"(",
")",
"{",
"try",
"{",
"var",
"address",
"=",
"node",
".",
"inputSocket",
".",
"address",
"(",
")",
";",
"node",
".",
"log",
"(",
"'UDP client listening on '",
"+",
"address",
".",
"address",
"+",
"\":\"",
"+",
"address",
".",
"port",
")",
";",
"node",
".",
"inputSocket",
".",
"setBroadcast",
"(",
"true",
")",
"node",
".",
"inputSocket",
".",
"setMulticastTTL",
"(",
"5",
")",
";",
"node",
".",
"inputSocket",
".",
"addMembership",
"(",
"'239.255.255.250'",
")",
";",
"//node.inputSocket.addMembership('239.255.255.250', '192.168.0.101');",
"//node.inputSocket.addMembership('239.255.255.250', '127.0.0.1');",
"/*\n var message = new Buffer(\n \"M-SEARCH * HTTP/1.1\\r\\n\" +\n \"HOST: 239.255.255.250:1900\\r\\n\" +\n \"MAN: \\\"ssdp:discover\\\"\\r\\n\" +\n \"ST: ssdp:all\\r\\n\" + // Essential, used by the client to specify what they want to discover, eg 'ST:ge:fridge'\n \"MX: 3\\r\\n\" + // 1 second to respond (but they all respond immediately?)\n \"\\r\\n\");\n */",
"//node.inputSocket.send(message, 0, message.length, 1900, \"239.255.255.250\");",
"}",
"catch",
"(",
"err",
")",
"{",
"node",
".",
"warn",
"(",
"'Cannot bind address for UPNP event listener. Port probably already in use. Error: '",
"+",
"err",
")",
";",
"}",
"}",
")",
";",
"try",
"{",
"node",
".",
"inputSocket",
".",
"bind",
"(",
"1900",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"node",
".",
"warn",
"(",
"'Cannot bind address for UPNP event listener. Port probably already in use. Error: '",
"+",
"err",
")",
";",
"}",
"}"
]
| Internal sub routines | [
"Internal",
"sub",
"routines"
]
| 88c66f4831c3b739c75173756bf62883cdf9391d | https://github.com/krauskopf/node-red-contrib-avr-yamaha/blob/88c66f4831c3b739c75173756bf62883cdf9391d/avr-yamaha.js#L318-L548 |
|
43,384 | doowb/unlazy-loader | index.js | transform | function transform(str) {
str = str.split(/^lazy\(/gm).join('require(');
var lines = str.split(/\r\n|\n/);
var len = lines.length;
var re = regex();
var idx = 0;
var start = false;
var isExported = false;
var namespace;
var res = '';
while (idx < len) {
var line = lines[idx++];
res += '\n';
if (/(?:var fn = require|require = utils)/.test(line)) {
continue;
}
if (/^require = fn/.test(line)) {
continue;
}
// adding this line to catch other variable names than the more specific cases above
if (/^require = (?:.*)/.test(line)) {
continue;
}
var match = re.exec(line);
if (!match) {
res += line;
continue;
}
if (match && (match[2] === 'lazy-cache' || match[3] === 'lazy-cache')) {
namespace = toNamespace(match[1]);
if (/module\.exports/.test(match[1])) {
isExported = true;
}
line = 'var ' + namespace + ' = {};';
start = true;
res += line;
continue;
}
if (!start) {
res += line;
continue;
}
var variable = toVariable(match);
var prefix = toProperty(namespace, variable, match[2]);
line = line.split(match[0]).join(prefix);
res += line;
}
if (isExported) {
res += '\nmodule.exports = ' + namespace + ';';
}
return res.replace(/^\s+/, '');
} | javascript | function transform(str) {
str = str.split(/^lazy\(/gm).join('require(');
var lines = str.split(/\r\n|\n/);
var len = lines.length;
var re = regex();
var idx = 0;
var start = false;
var isExported = false;
var namespace;
var res = '';
while (idx < len) {
var line = lines[idx++];
res += '\n';
if (/(?:var fn = require|require = utils)/.test(line)) {
continue;
}
if (/^require = fn/.test(line)) {
continue;
}
// adding this line to catch other variable names than the more specific cases above
if (/^require = (?:.*)/.test(line)) {
continue;
}
var match = re.exec(line);
if (!match) {
res += line;
continue;
}
if (match && (match[2] === 'lazy-cache' || match[3] === 'lazy-cache')) {
namespace = toNamespace(match[1]);
if (/module\.exports/.test(match[1])) {
isExported = true;
}
line = 'var ' + namespace + ' = {};';
start = true;
res += line;
continue;
}
if (!start) {
res += line;
continue;
}
var variable = toVariable(match);
var prefix = toProperty(namespace, variable, match[2]);
line = line.split(match[0]).join(prefix);
res += line;
}
if (isExported) {
res += '\nmodule.exports = ' + namespace + ';';
}
return res.replace(/^\s+/, '');
} | [
"function",
"transform",
"(",
"str",
")",
"{",
"str",
"=",
"str",
".",
"split",
"(",
"/",
"^lazy\\(",
"/",
"gm",
")",
".",
"join",
"(",
"'require('",
")",
";",
"var",
"lines",
"=",
"str",
".",
"split",
"(",
"/",
"\\r\\n|\\n",
"/",
")",
";",
"var",
"len",
"=",
"lines",
".",
"length",
";",
"var",
"re",
"=",
"regex",
"(",
")",
";",
"var",
"idx",
"=",
"0",
";",
"var",
"start",
"=",
"false",
";",
"var",
"isExported",
"=",
"false",
";",
"var",
"namespace",
";",
"var",
"res",
"=",
"''",
";",
"while",
"(",
"idx",
"<",
"len",
")",
"{",
"var",
"line",
"=",
"lines",
"[",
"idx",
"++",
"]",
";",
"res",
"+=",
"'\\n'",
";",
"if",
"(",
"/",
"(?:var fn = require|require = utils)",
"/",
".",
"test",
"(",
"line",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"/",
"^require = fn",
"/",
".",
"test",
"(",
"line",
")",
")",
"{",
"continue",
";",
"}",
"// adding this line to catch other variable names than the more specific cases above",
"if",
"(",
"/",
"^require = (?:.*)",
"/",
".",
"test",
"(",
"line",
")",
")",
"{",
"continue",
";",
"}",
"var",
"match",
"=",
"re",
".",
"exec",
"(",
"line",
")",
";",
"if",
"(",
"!",
"match",
")",
"{",
"res",
"+=",
"line",
";",
"continue",
";",
"}",
"if",
"(",
"match",
"&&",
"(",
"match",
"[",
"2",
"]",
"===",
"'lazy-cache'",
"||",
"match",
"[",
"3",
"]",
"===",
"'lazy-cache'",
")",
")",
"{",
"namespace",
"=",
"toNamespace",
"(",
"match",
"[",
"1",
"]",
")",
";",
"if",
"(",
"/",
"module\\.exports",
"/",
".",
"test",
"(",
"match",
"[",
"1",
"]",
")",
")",
"{",
"isExported",
"=",
"true",
";",
"}",
"line",
"=",
"'var '",
"+",
"namespace",
"+",
"' = {};'",
";",
"start",
"=",
"true",
";",
"res",
"+=",
"line",
";",
"continue",
";",
"}",
"if",
"(",
"!",
"start",
")",
"{",
"res",
"+=",
"line",
";",
"continue",
";",
"}",
"var",
"variable",
"=",
"toVariable",
"(",
"match",
")",
";",
"var",
"prefix",
"=",
"toProperty",
"(",
"namespace",
",",
"variable",
",",
"match",
"[",
"2",
"]",
")",
";",
"line",
"=",
"line",
".",
"split",
"(",
"match",
"[",
"0",
"]",
")",
".",
"join",
"(",
"prefix",
")",
";",
"res",
"+=",
"line",
";",
"}",
"if",
"(",
"isExported",
")",
"{",
"res",
"+=",
"'\\nmodule.exports = '",
"+",
"namespace",
"+",
"';'",
";",
"}",
"return",
"res",
".",
"replace",
"(",
"/",
"^\\s+",
"/",
",",
"''",
")",
";",
"}"
]
| Transform source code containing lazy-cache statements into a requirable file usable with webpack.
@param {String} `source` Source code.
@return {String} Transformed source code. | [
"Transform",
"source",
"code",
"containing",
"lazy",
"-",
"cache",
"statements",
"into",
"a",
"requirable",
"file",
"usable",
"with",
"webpack",
"."
]
| 52bc36ef8ce08a72d2181f25b7370f5f5271ea47 | https://github.com/doowb/unlazy-loader/blob/52bc36ef8ce08a72d2181f25b7370f5f5271ea47/index.js#L48-L107 |
43,385 | doowb/unlazy-loader | index.js | camelcase | function camelcase(str) {
if (!/[\s\W]/.test(str)) return str;
if (str.length === 1) {
return str.toLowerCase();
}
str = str.replace(/^[\W_]+|[\W_]+$/g, '').toLowerCase();
return str.replace(/[\W_]+(\w|$)/g, function(_, ch) {
return ch.toUpperCase();
});
} | javascript | function camelcase(str) {
if (!/[\s\W]/.test(str)) return str;
if (str.length === 1) {
return str.toLowerCase();
}
str = str.replace(/^[\W_]+|[\W_]+$/g, '').toLowerCase();
return str.replace(/[\W_]+(\w|$)/g, function(_, ch) {
return ch.toUpperCase();
});
} | [
"function",
"camelcase",
"(",
"str",
")",
"{",
"if",
"(",
"!",
"/",
"[\\s\\W]",
"/",
".",
"test",
"(",
"str",
")",
")",
"return",
"str",
";",
"if",
"(",
"str",
".",
"length",
"===",
"1",
")",
"{",
"return",
"str",
".",
"toLowerCase",
"(",
")",
";",
"}",
"str",
"=",
"str",
".",
"replace",
"(",
"/",
"^[\\W_]+|[\\W_]+$",
"/",
"g",
",",
"''",
")",
".",
"toLowerCase",
"(",
")",
";",
"return",
"str",
".",
"replace",
"(",
"/",
"[\\W_]+(\\w|$)",
"/",
"g",
",",
"function",
"(",
"_",
",",
"ch",
")",
"{",
"return",
"ch",
".",
"toUpperCase",
"(",
")",
";",
"}",
")",
";",
"}"
]
| Used to camelcase the module if a variable is not defined.
@param {String} `str` String containing `_`, `.`, `-` or whitespace that will be camelcased.
@return {String} camelcased string. | [
"Used",
"to",
"camelcase",
"the",
"module",
"if",
"a",
"variable",
"is",
"not",
"defined",
"."
]
| 52bc36ef8ce08a72d2181f25b7370f5f5271ea47 | https://github.com/doowb/unlazy-loader/blob/52bc36ef8ce08a72d2181f25b7370f5f5271ea47/index.js#L133-L142 |
43,386 | dongsik-yoo/assemblyscript-live-loader | lib/index.js | createWasmModule | function createWasmModule(source, wasm) {
var length = wasm.length;
var buffer = [];
for (var i = 0; i < length; i += 1) {
buffer.push(wasm[i]);
}
var module = "var buffer = new ArrayBuffer(" + wasm.length + ");\n var uint8 = new Uint8Array(buffer);\n uint8.set([" + buffer.join(',') + "]);\n " + wasmFooter;
return module;
} | javascript | function createWasmModule(source, wasm) {
var length = wasm.length;
var buffer = [];
for (var i = 0; i < length; i += 1) {
buffer.push(wasm[i]);
}
var module = "var buffer = new ArrayBuffer(" + wasm.length + ");\n var uint8 = new Uint8Array(buffer);\n uint8.set([" + buffer.join(',') + "]);\n " + wasmFooter;
return module;
} | [
"function",
"createWasmModule",
"(",
"source",
",",
"wasm",
")",
"{",
"var",
"length",
"=",
"wasm",
".",
"length",
";",
"var",
"buffer",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"+=",
"1",
")",
"{",
"buffer",
".",
"push",
"(",
"wasm",
"[",
"i",
"]",
")",
";",
"}",
"var",
"module",
"=",
"\"var buffer = new ArrayBuffer(\"",
"+",
"wasm",
".",
"length",
"+",
"\");\\n var uint8 = new Uint8Array(buffer);\\n uint8.set([\"",
"+",
"buffer",
".",
"join",
"(",
"','",
")",
"+",
"\"]);\\n \"",
"+",
"wasmFooter",
";",
"return",
"module",
";",
"}"
]
| Create a module using WebAssembly.Module
@param {string} source assemblyscript source
@param {Buffer} wasm WebAssembly Buffer
@returns {string} module string | [
"Create",
"a",
"module",
"using",
"WebAssembly",
".",
"Module"
]
| f1b5b4b28a66d2a8534224d0a962ff90bd3741a0 | https://github.com/dongsik-yoo/assemblyscript-live-loader/blob/f1b5b4b28a66d2a8534224d0a962ff90bd3741a0/lib/index.js#L37-L45 |
43,387 | dongsik-yoo/assemblyscript-live-loader | lib/index.js | createJsModule | function createJsModule(source) {
var compilerOptions = {
compilerOptions: {
target: ts.ScriptTarget.ES5,
module: ts.ModuleKind.CommonJS,
alwaysStrict: false
}
};
var transpiled = ts.transpileModule(source, compilerOptions);
return transpiled.outputText;
} | javascript | function createJsModule(source) {
var compilerOptions = {
compilerOptions: {
target: ts.ScriptTarget.ES5,
module: ts.ModuleKind.CommonJS,
alwaysStrict: false
}
};
var transpiled = ts.transpileModule(source, compilerOptions);
return transpiled.outputText;
} | [
"function",
"createJsModule",
"(",
"source",
")",
"{",
"var",
"compilerOptions",
"=",
"{",
"compilerOptions",
":",
"{",
"target",
":",
"ts",
".",
"ScriptTarget",
".",
"ES5",
",",
"module",
":",
"ts",
".",
"ModuleKind",
".",
"CommonJS",
",",
"alwaysStrict",
":",
"false",
"}",
"}",
";",
"var",
"transpiled",
"=",
"ts",
".",
"transpileModule",
"(",
"source",
",",
"compilerOptions",
")",
";",
"return",
"transpiled",
".",
"outputText",
";",
"}"
]
| Creates commonjs module for javascript
@param {string} source assemblyscript source
@returns {string} module string | [
"Creates",
"commonjs",
"module",
"for",
"javascript"
]
| f1b5b4b28a66d2a8534224d0a962ff90bd3741a0 | https://github.com/dongsik-yoo/assemblyscript-live-loader/blob/f1b5b4b28a66d2a8534224d0a962ff90bd3741a0/lib/index.js#L51-L61 |
43,388 | dongsik-yoo/assemblyscript-live-loader | lib/index.js | AssemblyScriptLiveLoader | function AssemblyScriptLiveLoader(source) {
var jsModule;
var wasmModule;
if (this.cacheable) {
this.cacheable();
}
this.addDependency(wasmFooterPath);
jsModule = createJsModule(source);
wasmModule = createWasmModule(source, compile(source));
return createCompatibleModule(jsModule, wasmModule);
} | javascript | function AssemblyScriptLiveLoader(source) {
var jsModule;
var wasmModule;
if (this.cacheable) {
this.cacheable();
}
this.addDependency(wasmFooterPath);
jsModule = createJsModule(source);
wasmModule = createWasmModule(source, compile(source));
return createCompatibleModule(jsModule, wasmModule);
} | [
"function",
"AssemblyScriptLiveLoader",
"(",
"source",
")",
"{",
"var",
"jsModule",
";",
"var",
"wasmModule",
";",
"if",
"(",
"this",
".",
"cacheable",
")",
"{",
"this",
".",
"cacheable",
"(",
")",
";",
"}",
"this",
".",
"addDependency",
"(",
"wasmFooterPath",
")",
";",
"jsModule",
"=",
"createJsModule",
"(",
"source",
")",
";",
"wasmModule",
"=",
"createWasmModule",
"(",
"source",
",",
"compile",
"(",
"source",
")",
")",
";",
"return",
"createCompatibleModule",
"(",
"jsModule",
",",
"wasmModule",
")",
";",
"}"
]
| Webpack loader for assemblyscript to transform wasm and bundle it
@param {string} source - assemblyscript source file
@returns {string} module string | [
"Webpack",
"loader",
"for",
"assemblyscript",
"to",
"transform",
"wasm",
"and",
"bundle",
"it"
]
| f1b5b4b28a66d2a8534224d0a962ff90bd3741a0 | https://github.com/dongsik-yoo/assemblyscript-live-loader/blob/f1b5b4b28a66d2a8534224d0a962ff90bd3741a0/lib/index.js#L89-L99 |
43,389 | otothea/node-twitchcmd | lib/helpers.js | createTimeout | function createTimeout(timer, i, callback) {
return setTimeout(function() {
callback(timer, i);
}, timer.seconds * 1000);
} | javascript | function createTimeout(timer, i, callback) {
return setTimeout(function() {
callback(timer, i);
}, timer.seconds * 1000);
} | [
"function",
"createTimeout",
"(",
"timer",
",",
"i",
",",
"callback",
")",
"{",
"return",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"callback",
"(",
"timer",
",",
"i",
")",
";",
"}",
",",
"timer",
".",
"seconds",
"*",
"1000",
")",
";",
"}"
]
| Create a new timeout
@param timer {object} - timer to use for the timeout
@param i {number} - index of the timer object
@param callback {function} - function to call when the timeout triggers | [
"Create",
"a",
"new",
"timeout"
]
| 8fd3e0ceda2e9ee179721bc53b9ce8f31ca6f638 | https://github.com/otothea/node-twitchcmd/blob/8fd3e0ceda2e9ee179721bc53b9ce8f31ca6f638/lib/helpers.js#L78-L82 |
43,390 | otothea/node-twitchcmd | index.js | init | function init(_config) {
if (initialized)
return;
// Validate the config
config = helpers.validateConfig(_config);
// Create a user for the bot
users[config.name] = helpers.createUser(true);
// Create a user for the channel owner
var name = config.channel.replace('#', '');
users[name] = helpers.createUser(true);
// Init the client
ircClient = new irc.Client(config.server, config.name, {
userName: config.name,
realName: config.name,
password: config.password,
port: config.port,
secure: config.secure,
});
// Add listeners
ircClient.addListener('error', onError);
ircClient.addListener('registered', onRegistered);
ircClient.addListener('join' + config.channel, onJoin);
ircClient.addListener('part' + config.channel, onPart);
ircClient.addListener('motd', onMotd);
ircClient.addListener('notice', onNotice);
ircClient.addListener('message' + config.channel, onMessage);
ircClient.addListener('raw', onRaw);
// If there is a discord token
if (config.discordToken) {
// Init the discord client
discordClient = new Discord.Client({
token: config.discordToken,
autorun: true,
});
// Add listeners
discordClient.on('ready', onDiscordReady);
discordClient.on('message', onDiscordMessage);
}
// If we are logging, create the directory if not exists
if (config.log && typeof config.log === 'string')
mkdirp.sync(config.log);
// Init stream checker
if (config.autoExit || config.discordToken)
streamInterval = setInterval(onCheckStream, 60 * 1000)
initialized = true;
} | javascript | function init(_config) {
if (initialized)
return;
// Validate the config
config = helpers.validateConfig(_config);
// Create a user for the bot
users[config.name] = helpers.createUser(true);
// Create a user for the channel owner
var name = config.channel.replace('#', '');
users[name] = helpers.createUser(true);
// Init the client
ircClient = new irc.Client(config.server, config.name, {
userName: config.name,
realName: config.name,
password: config.password,
port: config.port,
secure: config.secure,
});
// Add listeners
ircClient.addListener('error', onError);
ircClient.addListener('registered', onRegistered);
ircClient.addListener('join' + config.channel, onJoin);
ircClient.addListener('part' + config.channel, onPart);
ircClient.addListener('motd', onMotd);
ircClient.addListener('notice', onNotice);
ircClient.addListener('message' + config.channel, onMessage);
ircClient.addListener('raw', onRaw);
// If there is a discord token
if (config.discordToken) {
// Init the discord client
discordClient = new Discord.Client({
token: config.discordToken,
autorun: true,
});
// Add listeners
discordClient.on('ready', onDiscordReady);
discordClient.on('message', onDiscordMessage);
}
// If we are logging, create the directory if not exists
if (config.log && typeof config.log === 'string')
mkdirp.sync(config.log);
// Init stream checker
if (config.autoExit || config.discordToken)
streamInterval = setInterval(onCheckStream, 60 * 1000)
initialized = true;
} | [
"function",
"init",
"(",
"_config",
")",
"{",
"if",
"(",
"initialized",
")",
"return",
";",
"// Validate the config",
"config",
"=",
"helpers",
".",
"validateConfig",
"(",
"_config",
")",
";",
"// Create a user for the bot",
"users",
"[",
"config",
".",
"name",
"]",
"=",
"helpers",
".",
"createUser",
"(",
"true",
")",
";",
"// Create a user for the channel owner",
"var",
"name",
"=",
"config",
".",
"channel",
".",
"replace",
"(",
"'#'",
",",
"''",
")",
";",
"users",
"[",
"name",
"]",
"=",
"helpers",
".",
"createUser",
"(",
"true",
")",
";",
"// Init the client",
"ircClient",
"=",
"new",
"irc",
".",
"Client",
"(",
"config",
".",
"server",
",",
"config",
".",
"name",
",",
"{",
"userName",
":",
"config",
".",
"name",
",",
"realName",
":",
"config",
".",
"name",
",",
"password",
":",
"config",
".",
"password",
",",
"port",
":",
"config",
".",
"port",
",",
"secure",
":",
"config",
".",
"secure",
",",
"}",
")",
";",
"// Add listeners",
"ircClient",
".",
"addListener",
"(",
"'error'",
",",
"onError",
")",
";",
"ircClient",
".",
"addListener",
"(",
"'registered'",
",",
"onRegistered",
")",
";",
"ircClient",
".",
"addListener",
"(",
"'join'",
"+",
"config",
".",
"channel",
",",
"onJoin",
")",
";",
"ircClient",
".",
"addListener",
"(",
"'part'",
"+",
"config",
".",
"channel",
",",
"onPart",
")",
";",
"ircClient",
".",
"addListener",
"(",
"'motd'",
",",
"onMotd",
")",
";",
"ircClient",
".",
"addListener",
"(",
"'notice'",
",",
"onNotice",
")",
";",
"ircClient",
".",
"addListener",
"(",
"'message'",
"+",
"config",
".",
"channel",
",",
"onMessage",
")",
";",
"ircClient",
".",
"addListener",
"(",
"'raw'",
",",
"onRaw",
")",
";",
"// If there is a discord token",
"if",
"(",
"config",
".",
"discordToken",
")",
"{",
"// Init the discord client",
"discordClient",
"=",
"new",
"Discord",
".",
"Client",
"(",
"{",
"token",
":",
"config",
".",
"discordToken",
",",
"autorun",
":",
"true",
",",
"}",
")",
";",
"// Add listeners",
"discordClient",
".",
"on",
"(",
"'ready'",
",",
"onDiscordReady",
")",
";",
"discordClient",
".",
"on",
"(",
"'message'",
",",
"onDiscordMessage",
")",
";",
"}",
"// If we are logging, create the directory if not exists",
"if",
"(",
"config",
".",
"log",
"&&",
"typeof",
"config",
".",
"log",
"===",
"'string'",
")",
"mkdirp",
".",
"sync",
"(",
"config",
".",
"log",
")",
";",
"// Init stream checker",
"if",
"(",
"config",
".",
"autoExit",
"||",
"config",
".",
"discordToken",
")",
"streamInterval",
"=",
"setInterval",
"(",
"onCheckStream",
",",
"60",
"*",
"1000",
")",
"initialized",
"=",
"true",
";",
"}"
]
| Init the twitch bot
@param _config {object} - config to init the bot with | [
"Init",
"the",
"twitch",
"bot"
]
| 8fd3e0ceda2e9ee179721bc53b9ce8f31ca6f638 | https://github.com/otothea/node-twitchcmd/blob/8fd3e0ceda2e9ee179721bc53b9ce8f31ca6f638/index.js#L43-L98 |
43,391 | otothea/node-twitchcmd | index.js | exit | function exit() {
if (!initialized || exited)
return;
log('Exiting...', true);
// Leave the twitch channel
if (ircClient)
ircClient.part(config.channel);
// Leave discord
if (discordClient)
discordClient.disconnect();
// Clear the stream check interval
if (streamInterval)
clearInterval(streamInterval);
// Clear all the timeouts
timeouts.forEach(function(t) {
clearTimeout(t);
});
exited = true;
} | javascript | function exit() {
if (!initialized || exited)
return;
log('Exiting...', true);
// Leave the twitch channel
if (ircClient)
ircClient.part(config.channel);
// Leave discord
if (discordClient)
discordClient.disconnect();
// Clear the stream check interval
if (streamInterval)
clearInterval(streamInterval);
// Clear all the timeouts
timeouts.forEach(function(t) {
clearTimeout(t);
});
exited = true;
} | [
"function",
"exit",
"(",
")",
"{",
"if",
"(",
"!",
"initialized",
"||",
"exited",
")",
"return",
";",
"log",
"(",
"'Exiting...'",
",",
"true",
")",
";",
"// Leave the twitch channel",
"if",
"(",
"ircClient",
")",
"ircClient",
".",
"part",
"(",
"config",
".",
"channel",
")",
";",
"// Leave discord",
"if",
"(",
"discordClient",
")",
"discordClient",
".",
"disconnect",
"(",
")",
";",
"// Clear the stream check interval",
"if",
"(",
"streamInterval",
")",
"clearInterval",
"(",
"streamInterval",
")",
";",
"// Clear all the timeouts",
"timeouts",
".",
"forEach",
"(",
"function",
"(",
"t",
")",
"{",
"clearTimeout",
"(",
"t",
")",
";",
"}",
")",
";",
"exited",
"=",
"true",
";",
"}"
]
| Exit the twitch bot | [
"Exit",
"the",
"twitch",
"bot"
]
| 8fd3e0ceda2e9ee179721bc53b9ce8f31ca6f638 | https://github.com/otothea/node-twitchcmd/blob/8fd3e0ceda2e9ee179721bc53b9ce8f31ca6f638/index.js#L103-L127 |
43,392 | otothea/node-twitchcmd | index.js | isSpam | function isSpam(from, message) {
if (!config.filterSpam)
return false;
// Skip if this is a mod
if (users[from] && users[from].mod)
return false;
// Check for capital letter spam
var uppercaseCount = message.replace(/[^A-Z]/g, '').length;
if (uppercaseCount >= 10 && uppercaseCount >= message.length / 2) {
timeoutUser(from, null, 'stop using capital letters');
return true;
}
return false;
} | javascript | function isSpam(from, message) {
if (!config.filterSpam)
return false;
// Skip if this is a mod
if (users[from] && users[from].mod)
return false;
// Check for capital letter spam
var uppercaseCount = message.replace(/[^A-Z]/g, '').length;
if (uppercaseCount >= 10 && uppercaseCount >= message.length / 2) {
timeoutUser(from, null, 'stop using capital letters');
return true;
}
return false;
} | [
"function",
"isSpam",
"(",
"from",
",",
"message",
")",
"{",
"if",
"(",
"!",
"config",
".",
"filterSpam",
")",
"return",
"false",
";",
"// Skip if this is a mod",
"if",
"(",
"users",
"[",
"from",
"]",
"&&",
"users",
"[",
"from",
"]",
".",
"mod",
")",
"return",
"false",
";",
"// Check for capital letter spam",
"var",
"uppercaseCount",
"=",
"message",
".",
"replace",
"(",
"/",
"[^A-Z]",
"/",
"g",
",",
"''",
")",
".",
"length",
";",
"if",
"(",
"uppercaseCount",
">=",
"10",
"&&",
"uppercaseCount",
">=",
"message",
".",
"length",
"/",
"2",
")",
"{",
"timeoutUser",
"(",
"from",
",",
"null",
",",
"'stop using capital letters'",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
]
| Helper functions
Check if message is spam
@param from {string} - nickname of user who sent the message
@param message {string} - message being sent
@returns {boolean} - true if spam, false if not | [
"Helper",
"functions",
"Check",
"if",
"message",
"is",
"spam"
]
| 8fd3e0ceda2e9ee179721bc53b9ce8f31ca6f638 | https://github.com/otothea/node-twitchcmd/blob/8fd3e0ceda2e9ee179721bc53b9ce8f31ca6f638/index.js#L367-L383 |
43,393 | otothea/node-twitchcmd | index.js | timeoutUser | function timeoutUser(name, seconds, reason) {
// Create a user if it doesn't exist
users[name] = users[name] || helpers.createUser();
users[name].offenses++;
var offenses = users[name].offenses;
if (offenses > config.maxOffenses)
banUser(name);
else {
seconds = seconds || (offenses === 1 ? 10 : 60);
twitchCommand('timeout', name + ' ' + seconds + ' ' + reason + ' - warning ' + offenses + ' of ' + config.maxOffenses);
}
} | javascript | function timeoutUser(name, seconds, reason) {
// Create a user if it doesn't exist
users[name] = users[name] || helpers.createUser();
users[name].offenses++;
var offenses = users[name].offenses;
if (offenses > config.maxOffenses)
banUser(name);
else {
seconds = seconds || (offenses === 1 ? 10 : 60);
twitchCommand('timeout', name + ' ' + seconds + ' ' + reason + ' - warning ' + offenses + ' of ' + config.maxOffenses);
}
} | [
"function",
"timeoutUser",
"(",
"name",
",",
"seconds",
",",
"reason",
")",
"{",
"// Create a user if it doesn't exist",
"users",
"[",
"name",
"]",
"=",
"users",
"[",
"name",
"]",
"||",
"helpers",
".",
"createUser",
"(",
")",
";",
"users",
"[",
"name",
"]",
".",
"offenses",
"++",
";",
"var",
"offenses",
"=",
"users",
"[",
"name",
"]",
".",
"offenses",
";",
"if",
"(",
"offenses",
">",
"config",
".",
"maxOffenses",
")",
"banUser",
"(",
"name",
")",
";",
"else",
"{",
"seconds",
"=",
"seconds",
"||",
"(",
"offenses",
"===",
"1",
"?",
"10",
":",
"60",
")",
";",
"twitchCommand",
"(",
"'timeout'",
",",
"name",
"+",
"' '",
"+",
"seconds",
"+",
"' '",
"+",
"reason",
"+",
"' - warning '",
"+",
"offenses",
"+",
"' of '",
"+",
"config",
".",
"maxOffenses",
")",
";",
"}",
"}"
]
| Timeout a user in chat
@param name {string} - nickname of the user to timeout
@param seconds {number|null} - number of seconds to timeout
@param reason {string} - the reason for the timeout | [
"Timeout",
"a",
"user",
"in",
"chat"
]
| 8fd3e0ceda2e9ee179721bc53b9ce8f31ca6f638 | https://github.com/otothea/node-twitchcmd/blob/8fd3e0ceda2e9ee179721bc53b9ce8f31ca6f638/index.js#L406-L419 |
43,394 | otothea/node-twitchcmd | index.js | say | function say(message, channelId) {
channelId = channelId || false;
if (channelId) {
sendDiscordMessage(channelId, message);
return;
}
if (!ircClient || typeof message !== 'string')
return;
ircClient.say(config.channel, message);
} | javascript | function say(message, channelId) {
channelId = channelId || false;
if (channelId) {
sendDiscordMessage(channelId, message);
return;
}
if (!ircClient || typeof message !== 'string')
return;
ircClient.say(config.channel, message);
} | [
"function",
"say",
"(",
"message",
",",
"channelId",
")",
"{",
"channelId",
"=",
"channelId",
"||",
"false",
";",
"if",
"(",
"channelId",
")",
"{",
"sendDiscordMessage",
"(",
"channelId",
",",
"message",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"ircClient",
"||",
"typeof",
"message",
"!==",
"'string'",
")",
"return",
";",
"ircClient",
".",
"say",
"(",
"config",
".",
"channel",
",",
"message",
")",
";",
"}"
]
| Say a message to chat
@param message {string} - send a message to chat
@param [channelId] {string} - id of discord channel | [
"Say",
"a",
"message",
"to",
"chat"
]
| 8fd3e0ceda2e9ee179721bc53b9ce8f31ca6f638 | https://github.com/otothea/node-twitchcmd/blob/8fd3e0ceda2e9ee179721bc53b9ce8f31ca6f638/index.js#L436-L448 |
43,395 | otothea/node-twitchcmd | index.js | sendDiscordMessage | function sendDiscordMessage(id, message) {
if (!discordClient || typeof id !== 'string' || typeof message !== 'string')
return;
discordClient.sendMessage({
to: id,
message: message,
});
} | javascript | function sendDiscordMessage(id, message) {
if (!discordClient || typeof id !== 'string' || typeof message !== 'string')
return;
discordClient.sendMessage({
to: id,
message: message,
});
} | [
"function",
"sendDiscordMessage",
"(",
"id",
",",
"message",
")",
"{",
"if",
"(",
"!",
"discordClient",
"||",
"typeof",
"id",
"!==",
"'string'",
"||",
"typeof",
"message",
"!==",
"'string'",
")",
"return",
";",
"discordClient",
".",
"sendMessage",
"(",
"{",
"to",
":",
"id",
",",
"message",
":",
"message",
",",
"}",
")",
";",
"}"
]
| Send a message to Discord channel
@param id {string} - id of the channel to send message
@param message {string} - message to send to channel | [
"Send",
"a",
"message",
"to",
"Discord",
"channel"
]
| 8fd3e0ceda2e9ee179721bc53b9ce8f31ca6f638 | https://github.com/otothea/node-twitchcmd/blob/8fd3e0ceda2e9ee179721bc53b9ce8f31ca6f638/index.js#L456-L464 |
43,396 | otothea/node-twitchcmd | index.js | logChat | function logChat(from, message) {
if (typeof config.log !== 'string' || !from || typeof message !== 'string')
return;
// Get the current moment
var now = moment();
// Create the file name
var file = path.join(config.log, now.format('YYYY-MM-DD') + '-' + 'chat.log');
// Create the text to log based on moment and chat info
var text = '[' + now.format('YYYY-MM-DD hh:mm A') + '] ' + from + ': ' + message + '\n';
// Append the text to the log file
fs.appendFile(file, text, function(err) {
if (err)
error(err);
});
} | javascript | function logChat(from, message) {
if (typeof config.log !== 'string' || !from || typeof message !== 'string')
return;
// Get the current moment
var now = moment();
// Create the file name
var file = path.join(config.log, now.format('YYYY-MM-DD') + '-' + 'chat.log');
// Create the text to log based on moment and chat info
var text = '[' + now.format('YYYY-MM-DD hh:mm A') + '] ' + from + ': ' + message + '\n';
// Append the text to the log file
fs.appendFile(file, text, function(err) {
if (err)
error(err);
});
} | [
"function",
"logChat",
"(",
"from",
",",
"message",
")",
"{",
"if",
"(",
"typeof",
"config",
".",
"log",
"!==",
"'string'",
"||",
"!",
"from",
"||",
"typeof",
"message",
"!==",
"'string'",
")",
"return",
";",
"// Get the current moment",
"var",
"now",
"=",
"moment",
"(",
")",
";",
"// Create the file name",
"var",
"file",
"=",
"path",
".",
"join",
"(",
"config",
".",
"log",
",",
"now",
".",
"format",
"(",
"'YYYY-MM-DD'",
")",
"+",
"'-'",
"+",
"'chat.log'",
")",
";",
"// Create the text to log based on moment and chat info",
"var",
"text",
"=",
"'['",
"+",
"now",
".",
"format",
"(",
"'YYYY-MM-DD hh:mm A'",
")",
"+",
"'] '",
"+",
"from",
"+",
"': '",
"+",
"message",
"+",
"'\\n'",
";",
"// Append the text to the log file",
"fs",
".",
"appendFile",
"(",
"file",
",",
"text",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"error",
"(",
"err",
")",
";",
"}",
")",
";",
"}"
]
| Log message to chat logs
@param from {string} - name of person sending the message
@param message {string} - the message sent | [
"Log",
"message",
"to",
"chat",
"logs"
]
| 8fd3e0ceda2e9ee179721bc53b9ce8f31ca6f638 | https://github.com/otothea/node-twitchcmd/blob/8fd3e0ceda2e9ee179721bc53b9ce8f31ca6f638/index.js#L472-L490 |
43,397 | jfairbank/marionette.component | src/marionette.component.js | function(region) {
if (this._isShown) {
throw new Error('This component is already shown in a region.');
}
if (!region) {
throw new Error('Please supply a region to show inside.');
}
this.region = region;
this.triggerMethod('before:show');
this._showView();
this._isShown = true;
this.triggerMethod('show');
} | javascript | function(region) {
if (this._isShown) {
throw new Error('This component is already shown in a region.');
}
if (!region) {
throw new Error('Please supply a region to show inside.');
}
this.region = region;
this.triggerMethod('before:show');
this._showView();
this._isShown = true;
this.triggerMethod('show');
} | [
"function",
"(",
"region",
")",
"{",
"if",
"(",
"this",
".",
"_isShown",
")",
"{",
"throw",
"new",
"Error",
"(",
"'This component is already shown in a region.'",
")",
";",
"}",
"if",
"(",
"!",
"region",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Please supply a region to show inside.'",
")",
";",
"}",
"this",
".",
"region",
"=",
"region",
";",
"this",
".",
"triggerMethod",
"(",
"'before:show'",
")",
";",
"this",
".",
"_showView",
"(",
")",
";",
"this",
".",
"_isShown",
"=",
"true",
";",
"this",
".",
"triggerMethod",
"(",
"'show'",
")",
";",
"}"
]
| Show this component inside a region | [
"Show",
"this",
"component",
"inside",
"a",
"region"
]
| 590c12ea65add290b46f44cdf465b5f2cc9d1e2e | https://github.com/jfairbank/marionette.component/blob/590c12ea65add290b46f44cdf465b5f2cc9d1e2e/src/marionette.component.js#L18-L35 |
|
43,398 | jfairbank/marionette.component | src/marionette.component.js | function() {
var view = this.view = this._getView();
this._initializeViewEvents();
// Trigger show:view after the view is shown in the region
this.listenTo(view, 'show', _.partial(this.triggerMethod, 'show:view'));
// Trigger before:show before the region shows the view
this.triggerMethod('before:show:view');
// Show the view in the region
this.region.show(view);
// Destroy the component if the region is emptied because it destroys
// the view
this.listenToOnce(this.region, 'empty', this.destroy);
} | javascript | function() {
var view = this.view = this._getView();
this._initializeViewEvents();
// Trigger show:view after the view is shown in the region
this.listenTo(view, 'show', _.partial(this.triggerMethod, 'show:view'));
// Trigger before:show before the region shows the view
this.triggerMethod('before:show:view');
// Show the view in the region
this.region.show(view);
// Destroy the component if the region is emptied because it destroys
// the view
this.listenToOnce(this.region, 'empty', this.destroy);
} | [
"function",
"(",
")",
"{",
"var",
"view",
"=",
"this",
".",
"view",
"=",
"this",
".",
"_getView",
"(",
")",
";",
"this",
".",
"_initializeViewEvents",
"(",
")",
";",
"// Trigger show:view after the view is shown in the region",
"this",
".",
"listenTo",
"(",
"view",
",",
"'show'",
",",
"_",
".",
"partial",
"(",
"this",
".",
"triggerMethod",
",",
"'show:view'",
")",
")",
";",
"// Trigger before:show before the region shows the view",
"this",
".",
"triggerMethod",
"(",
"'before:show:view'",
")",
";",
"// Show the view in the region",
"this",
".",
"region",
".",
"show",
"(",
"view",
")",
";",
"// Destroy the component if the region is emptied because it destroys",
"// the view",
"this",
".",
"listenToOnce",
"(",
"this",
".",
"region",
",",
"'empty'",
",",
"this",
".",
"destroy",
")",
";",
"}"
]
| Show the view in the region | [
"Show",
"the",
"view",
"in",
"the",
"region"
]
| 590c12ea65add290b46f44cdf465b5f2cc9d1e2e | https://github.com/jfairbank/marionette.component/blob/590c12ea65add290b46f44cdf465b5f2cc9d1e2e/src/marionette.component.js#L55-L72 |
|
43,399 | yamadapc/mocha-spec-cov-alt | bin/index.js | any | function any(target, fn) {
var keys = Object.keys(target);
for(var i = 0, len = keys.length; i < len; i++) {
var key = keys[i];
var value = target[key];
if(fn(value, key)) return true;
}
return false;
} | javascript | function any(target, fn) {
var keys = Object.keys(target);
for(var i = 0, len = keys.length; i < len; i++) {
var key = keys[i];
var value = target[key];
if(fn(value, key)) return true;
}
return false;
} | [
"function",
"any",
"(",
"target",
",",
"fn",
")",
"{",
"var",
"keys",
"=",
"Object",
".",
"keys",
"(",
"target",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"keys",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"var",
"key",
"=",
"keys",
"[",
"i",
"]",
";",
"var",
"value",
"=",
"target",
"[",
"key",
"]",
";",
"if",
"(",
"fn",
"(",
"value",
",",
"key",
")",
")",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
]
| Applies a predicate to collection and returns true if any of the items match
it | [
"Applies",
"a",
"predicate",
"to",
"collection",
"and",
"returns",
"true",
"if",
"any",
"of",
"the",
"items",
"match",
"it"
]
| 2f834c58e15bc186441cf21d0e2c586de13c6e9b | https://github.com/yamadapc/mocha-spec-cov-alt/blob/2f834c58e15bc186441cf21d0e2c586de13c6e9b/bin/index.js#L65-L73 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.