repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
sequence | docstring
stringlengths 4
11.8k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 86
226
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
zynga/atom | atom.js | provide | function provide(nucleus, key, provider) {
provider(preventMultiCall(function (result) {
set(nucleus, key, result);
}));
} | javascript | function provide(nucleus, key, provider) {
provider(preventMultiCall(function (result) {
set(nucleus, key, result);
}));
} | [
"function",
"provide",
"(",
"nucleus",
",",
"key",
",",
"provider",
")",
"{",
"provider",
"(",
"preventMultiCall",
"(",
"function",
"(",
"result",
")",
"{",
"set",
"(",
"nucleus",
",",
"key",
",",
"result",
")",
";",
"}",
")",
")",
";",
"}"
] | Helper function for setting up providers. | [
"Helper",
"function",
"for",
"setting",
"up",
"providers",
"."
] | cf204967e9267df47d51c2b5b628261c7ed0cec7 | https://github.com/zynga/atom/blob/cf204967e9267df47d51c2b5b628261c7ed0cec7/atom.js#L136-L140 | train |
zynga/atom | atom.js | doNext | function doNext() {
if (q) {
q.pending = q.next = (!q.next && q.length) ?
q.shift() : q.next;
q.args = slice.call(arguments, 0);
if (q.pending) {
q.next = 0;
q.pending.apply({}, [preventMultiCall(doNext)].concat(q.args));
}
}
} | javascript | function doNext() {
if (q) {
q.pending = q.next = (!q.next && q.length) ?
q.shift() : q.next;
q.args = slice.call(arguments, 0);
if (q.pending) {
q.next = 0;
q.pending.apply({}, [preventMultiCall(doNext)].concat(q.args));
}
}
} | [
"function",
"doNext",
"(",
")",
"{",
"if",
"(",
"q",
")",
"{",
"q",
".",
"pending",
"=",
"q",
".",
"next",
"=",
"(",
"!",
"q",
".",
"next",
"&&",
"q",
".",
"length",
")",
"?",
"q",
".",
"shift",
"(",
")",
":",
"q",
".",
"next",
";",
"q",
".",
"args",
"=",
"slice",
".",
"call",
"(",
"arguments",
",",
"0",
")",
";",
"if",
"(",
"q",
".",
"pending",
")",
"{",
"q",
".",
"next",
"=",
"0",
";",
"q",
".",
"pending",
".",
"apply",
"(",
"{",
"}",
",",
"[",
"preventMultiCall",
"(",
"doNext",
")",
"]",
".",
"concat",
"(",
"q",
".",
"args",
")",
")",
";",
"}",
"}",
"}"
] | Execute the next function in the async queue. | [
"Execute",
"the",
"next",
"function",
"in",
"the",
"async",
"queue",
"."
] | cf204967e9267df47d51c2b5b628261c7ed0cec7 | https://github.com/zynga/atom/blob/cf204967e9267df47d51c2b5b628261c7ed0cec7/atom.js#L168-L178 | train |
zynga/atom | atom.js | function () {
if (q) {
for (var i = 0, len = arguments.length; i < len; i++) {
q.push(arguments[i]);
if (!q.pending) {
doNext.apply({}, q.args || []);
}
}
}
return me;
} | javascript | function () {
if (q) {
for (var i = 0, len = arguments.length; i < len; i++) {
q.push(arguments[i]);
if (!q.pending) {
doNext.apply({}, q.args || []);
}
}
}
return me;
} | [
"function",
"(",
")",
"{",
"if",
"(",
"q",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"arguments",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"q",
".",
"push",
"(",
"arguments",
"[",
"i",
"]",
")",
";",
"if",
"(",
"!",
"q",
".",
"pending",
")",
"{",
"doNext",
".",
"apply",
"(",
"{",
"}",
",",
"q",
".",
"args",
"||",
"[",
"]",
")",
";",
"}",
"}",
"}",
"return",
"me",
";",
"}"
] | Add a function or functions to the async queue. Functions added thusly must call their first arg as a callback when done. Any args provided to the callback will be passed in to the next function in the queue. | [
"Add",
"a",
"function",
"or",
"functions",
"to",
"the",
"async",
"queue",
".",
"Functions",
"added",
"thusly",
"must",
"call",
"their",
"first",
"arg",
"as",
"a",
"callback",
"when",
"done",
".",
"Any",
"args",
"provided",
"to",
"the",
"callback",
"will",
"be",
"passed",
"in",
"to",
"the",
"next",
"function",
"in",
"the",
"queue",
"."
] | cf204967e9267df47d51c2b5b628261c7ed0cec7 | https://github.com/zynga/atom/blob/cf204967e9267df47d51c2b5b628261c7ed0cec7/atom.js#L186-L196 | train |
|
zynga/atom | atom.js | function () {
delete nucleus.props;
delete nucleus.needs;
delete nucleus.providers;
delete nucleus.listeners;
while (q.length) {
q.pop();
}
nucleus = props = needs = providers = listeners =
q = q.pending = q.next = q.args = 0;
} | javascript | function () {
delete nucleus.props;
delete nucleus.needs;
delete nucleus.providers;
delete nucleus.listeners;
while (q.length) {
q.pop();
}
nucleus = props = needs = providers = listeners =
q = q.pending = q.next = q.args = 0;
} | [
"function",
"(",
")",
"{",
"delete",
"nucleus",
".",
"props",
";",
"delete",
"nucleus",
".",
"needs",
";",
"delete",
"nucleus",
".",
"providers",
";",
"delete",
"nucleus",
".",
"listeners",
";",
"while",
"(",
"q",
".",
"length",
")",
"{",
"q",
".",
"pop",
"(",
")",
";",
"}",
"nucleus",
"=",
"props",
"=",
"needs",
"=",
"providers",
"=",
"listeners",
"=",
"q",
"=",
"q",
".",
"pending",
"=",
"q",
".",
"next",
"=",
"q",
".",
"args",
"=",
"0",
";",
"}"
] | Remove references to all properties and listeners. This releases memory, and effective stops the atom from working. | [
"Remove",
"references",
"to",
"all",
"properties",
"and",
"listeners",
".",
"This",
"releases",
"memory",
"and",
"effective",
"stops",
"the",
"atom",
"from",
"working",
"."
] | cf204967e9267df47d51c2b5b628261c7ed0cec7 | https://github.com/zynga/atom/blob/cf204967e9267df47d51c2b5b628261c7ed0cec7/atom.js#L200-L210 | train |
|
zynga/atom | atom.js | function (keyOrList, func) {
var keys = toArray(keyOrList), i = -1, len = keys.length, key;
while (++i < len) {
key = keys[i];
func(key, me.get(key));
}
return me;
} | javascript | function (keyOrList, func) {
var keys = toArray(keyOrList), i = -1, len = keys.length, key;
while (++i < len) {
key = keys[i];
func(key, me.get(key));
}
return me;
} | [
"function",
"(",
"keyOrList",
",",
"func",
")",
"{",
"var",
"keys",
"=",
"toArray",
"(",
"keyOrList",
")",
",",
"i",
"=",
"-",
"1",
",",
"len",
"=",
"keys",
".",
"length",
",",
"key",
";",
"while",
"(",
"++",
"i",
"<",
"len",
")",
"{",
"key",
"=",
"keys",
"[",
"i",
"]",
";",
"func",
"(",
"key",
",",
"me",
".",
"get",
"(",
"key",
")",
")",
";",
"}",
"return",
"me",
";",
"}"
] | Call `func` on each of the specified keys. The key is provided as the first arg, and the value as the second. | [
"Call",
"func",
"on",
"each",
"of",
"the",
"specified",
"keys",
".",
"The",
"key",
"is",
"provided",
"as",
"the",
"first",
"arg",
"and",
"the",
"value",
"as",
"the",
"second",
"."
] | cf204967e9267df47d51c2b5b628261c7ed0cec7 | https://github.com/zynga/atom/blob/cf204967e9267df47d51c2b5b628261c7ed0cec7/atom.js#L214-L221 | train |
|
zynga/atom | atom.js | function (keyOrList, func) {
var result = get(nucleus, keyOrList, func);
return func ? result : typeof keyOrList === 'string' ?
result.values[0] : result.values;
} | javascript | function (keyOrList, func) {
var result = get(nucleus, keyOrList, func);
return func ? result : typeof keyOrList === 'string' ?
result.values[0] : result.values;
} | [
"function",
"(",
"keyOrList",
",",
"func",
")",
"{",
"var",
"result",
"=",
"get",
"(",
"nucleus",
",",
"keyOrList",
",",
"func",
")",
";",
"return",
"func",
"?",
"result",
":",
"typeof",
"keyOrList",
"===",
"'string'",
"?",
"result",
".",
"values",
"[",
"0",
"]",
":",
"result",
".",
"values",
";",
"}"
] | Get current values for the specified keys. If `func` is provided, it will be called with the values as args. | [
"Get",
"current",
"values",
"for",
"the",
"specified",
"keys",
".",
"If",
"func",
"is",
"provided",
"it",
"will",
"be",
"called",
"with",
"the",
"values",
"as",
"args",
"."
] | cf204967e9267df47d51c2b5b628261c7ed0cec7 | https://github.com/zynga/atom/blob/cf204967e9267df47d51c2b5b628261c7ed0cec7/atom.js#L263-L267 | train |
|
zynga/atom | atom.js | function () {
var keys = [];
for (var key in props) {
if (hasOwn.call(props, key)) {
keys.push(key);
}
}
return keys;
} | javascript | function () {
var keys = [];
for (var key in props) {
if (hasOwn.call(props, key)) {
keys.push(key);
}
}
return keys;
} | [
"function",
"(",
")",
"{",
"var",
"keys",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"key",
"in",
"props",
")",
"{",
"if",
"(",
"hasOwn",
".",
"call",
"(",
"props",
",",
"key",
")",
")",
"{",
"keys",
".",
"push",
"(",
"key",
")",
";",
"}",
"}",
"return",
"keys",
";",
"}"
] | Return a list of all keys. | [
"Return",
"a",
"list",
"of",
"all",
"keys",
"."
] | cf204967e9267df47d51c2b5b628261c7ed0cec7 | https://github.com/zynga/atom/blob/cf204967e9267df47d51c2b5b628261c7ed0cec7/atom.js#L282-L290 | train |
|
zynga/atom | atom.js | function (obj) {
for (var p in obj) {
if (hasOwn.call(obj, p)) {
me[p] = obj[p];
}
}
return me;
} | javascript | function (obj) {
for (var p in obj) {
if (hasOwn.call(obj, p)) {
me[p] = obj[p];
}
}
return me;
} | [
"function",
"(",
"obj",
")",
"{",
"for",
"(",
"var",
"p",
"in",
"obj",
")",
"{",
"if",
"(",
"hasOwn",
".",
"call",
"(",
"obj",
",",
"p",
")",
")",
"{",
"me",
"[",
"p",
"]",
"=",
"obj",
"[",
"p",
"]",
";",
"}",
"}",
"return",
"me",
";",
"}"
] | Add arbitrary properties to this atom's interface. | [
"Add",
"arbitrary",
"properties",
"to",
"this",
"atom",
"s",
"interface",
"."
] | cf204967e9267df47d51c2b5b628261c7ed0cec7 | https://github.com/zynga/atom/blob/cf204967e9267df47d51c2b5b628261c7ed0cec7/atom.js#L293-L300 | train |
|
zynga/atom | atom.js | function (keyOrList, func) { // alias: `bind`
listeners.unshift({ keys: toArray(keyOrList), cb: func,
calls: Infinity });
return me;
} | javascript | function (keyOrList, func) { // alias: `bind`
listeners.unshift({ keys: toArray(keyOrList), cb: func,
calls: Infinity });
return me;
} | [
"function",
"(",
"keyOrList",
",",
"func",
")",
"{",
"listeners",
".",
"unshift",
"(",
"{",
"keys",
":",
"toArray",
"(",
"keyOrList",
")",
",",
"cb",
":",
"func",
",",
"calls",
":",
"Infinity",
"}",
")",
";",
"return",
"me",
";",
"}"
] | Call `func` whenever any of the specified keys change. The values of the keys will be provided as args to func. | [
"Call",
"func",
"whenever",
"any",
"of",
"the",
"specified",
"keys",
"change",
".",
"The",
"values",
"of",
"the",
"keys",
"will",
"be",
"provided",
"as",
"args",
"to",
"func",
"."
] | cf204967e9267df47d51c2b5b628261c7ed0cec7 | https://github.com/zynga/atom/blob/cf204967e9267df47d51c2b5b628261c7ed0cec7/atom.js#L359-L363 | train |
|
zynga/atom | atom.js | function (keyOrList, func) {
var keys = toArray(keyOrList),
results = get(nucleus, keys),
values = results.values,
missing = results.missing;
if (!missing) {
func.apply({}, values);
} else {
listeners.unshift(
{ keys: keys, cb: func, missing: missing, calls: 1 });
}
return me;
} | javascript | function (keyOrList, func) {
var keys = toArray(keyOrList),
results = get(nucleus, keys),
values = results.values,
missing = results.missing;
if (!missing) {
func.apply({}, values);
} else {
listeners.unshift(
{ keys: keys, cb: func, missing: missing, calls: 1 });
}
return me;
} | [
"function",
"(",
"keyOrList",
",",
"func",
")",
"{",
"var",
"keys",
"=",
"toArray",
"(",
"keyOrList",
")",
",",
"results",
"=",
"get",
"(",
"nucleus",
",",
"keys",
")",
",",
"values",
"=",
"results",
".",
"values",
",",
"missing",
"=",
"results",
".",
"missing",
";",
"if",
"(",
"!",
"missing",
")",
"{",
"func",
".",
"apply",
"(",
"{",
"}",
",",
"values",
")",
";",
"}",
"else",
"{",
"listeners",
".",
"unshift",
"(",
"{",
"keys",
":",
"keys",
",",
"cb",
":",
"func",
",",
"missing",
":",
"missing",
",",
"calls",
":",
"1",
"}",
")",
";",
"}",
"return",
"me",
";",
"}"
] | Call `func` as soon as all of the specified keys have been set. If they are already set, the function will be called immediately, with all the values provided as args. Guaranteed to be called no more than once. | [
"Call",
"func",
"as",
"soon",
"as",
"all",
"of",
"the",
"specified",
"keys",
"have",
"been",
"set",
".",
"If",
"they",
"are",
"already",
"set",
"the",
"function",
"will",
"be",
"called",
"immediately",
"with",
"all",
"the",
"values",
"provided",
"as",
"args",
".",
"Guaranteed",
"to",
"be",
"called",
"no",
"more",
"than",
"once",
"."
] | cf204967e9267df47d51c2b5b628261c7ed0cec7 | https://github.com/zynga/atom/blob/cf204967e9267df47d51c2b5b628261c7ed0cec7/atom.js#L369-L381 | train |
|
zynga/atom | atom.js | function (key, func) {
if (needs[key]) {
provide(nucleus, key, func);
} else if (!providers[key]) {
providers[key] = func;
}
return me;
} | javascript | function (key, func) {
if (needs[key]) {
provide(nucleus, key, func);
} else if (!providers[key]) {
providers[key] = func;
}
return me;
} | [
"function",
"(",
"key",
",",
"func",
")",
"{",
"if",
"(",
"needs",
"[",
"key",
"]",
")",
"{",
"provide",
"(",
"nucleus",
",",
"key",
",",
"func",
")",
";",
"}",
"else",
"if",
"(",
"!",
"providers",
"[",
"key",
"]",
")",
"{",
"providers",
"[",
"key",
"]",
"=",
"func",
";",
"}",
"return",
"me",
";",
"}"
] | Register a provider for a particular key. The provider `func` is a function that will be called if there is a need to create the key. It must call its first arg as a callback, with the value. Provider functions will be called at most once. | [
"Register",
"a",
"provider",
"for",
"a",
"particular",
"key",
".",
"The",
"provider",
"func",
"is",
"a",
"function",
"that",
"will",
"be",
"called",
"if",
"there",
"is",
"a",
"need",
"to",
"create",
"the",
"key",
".",
"It",
"must",
"call",
"its",
"first",
"arg",
"as",
"a",
"callback",
"with",
"the",
"value",
".",
"Provider",
"functions",
"will",
"be",
"called",
"at",
"most",
"once",
"."
] | cf204967e9267df47d51c2b5b628261c7ed0cec7 | https://github.com/zynga/atom/blob/cf204967e9267df47d51c2b5b628261c7ed0cec7/atom.js#L387-L394 | train |
|
zynga/atom | atom.js | function (keyOrMap, value) {
if (typeof keyOrMap === typeObj) {
for (var key in keyOrMap) {
if (hasOwn.call(keyOrMap, key)) {
set(nucleus, key, keyOrMap[key]);
}
}
} else {
set(nucleus, keyOrMap, value);
}
return me;
} | javascript | function (keyOrMap, value) {
if (typeof keyOrMap === typeObj) {
for (var key in keyOrMap) {
if (hasOwn.call(keyOrMap, key)) {
set(nucleus, key, keyOrMap[key]);
}
}
} else {
set(nucleus, keyOrMap, value);
}
return me;
} | [
"function",
"(",
"keyOrMap",
",",
"value",
")",
"{",
"if",
"(",
"typeof",
"keyOrMap",
"===",
"typeObj",
")",
"{",
"for",
"(",
"var",
"key",
"in",
"keyOrMap",
")",
"{",
"if",
"(",
"hasOwn",
".",
"call",
"(",
"keyOrMap",
",",
"key",
")",
")",
"{",
"set",
"(",
"nucleus",
",",
"key",
",",
"keyOrMap",
"[",
"key",
"]",
")",
";",
"}",
"}",
"}",
"else",
"{",
"set",
"(",
"nucleus",
",",
"keyOrMap",
",",
"value",
")",
";",
"}",
"return",
"me",
";",
"}"
] | Set value for a key, or if `keyOrMap` is an object then set all the keys' corresponding values. | [
"Set",
"value",
"for",
"a",
"key",
"or",
"if",
"keyOrMap",
"is",
"an",
"object",
"then",
"set",
"all",
"the",
"keys",
"corresponding",
"values",
"."
] | cf204967e9267df47d51c2b5b628261c7ed0cec7 | https://github.com/zynga/atom/blob/cf204967e9267df47d51c2b5b628261c7ed0cec7/atom.js#L398-L409 | train |
|
mkloubert/nativescript-stringformat | plugin/index.js | join | function join(separator, itemList) {
var result = "";
for (var i = 0; i < itemList.length; i++) {
if (i > 0) {
result += separator;
}
result += itemList[i];
}
return result;
} | javascript | function join(separator, itemList) {
var result = "";
for (var i = 0; i < itemList.length; i++) {
if (i > 0) {
result += separator;
}
result += itemList[i];
}
return result;
} | [
"function",
"join",
"(",
"separator",
",",
"itemList",
")",
"{",
"var",
"result",
"=",
"\"\"",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"itemList",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"i",
">",
"0",
")",
"{",
"result",
"+=",
"separator",
";",
"}",
"result",
"+=",
"itemList",
"[",
"i",
"]",
";",
"}",
"return",
"result",
";",
"}"
] | Joins items to one string.
@function join
@param {String} separator The separator.
@param {Array} itemList The list of items.
@return {String} The joined string. | [
"Joins",
"items",
"to",
"one",
"string",
"."
] | 83478b3a222574ad9e76f07076b798e6f2d8e6ac | https://github.com/mkloubert/nativescript-stringformat/blob/83478b3a222574ad9e76f07076b798e6f2d8e6ac/plugin/index.js#L564-L573 | train |
mkloubert/nativescript-stringformat | plugin/index.js | similarity | function similarity(left, right, ignoreCase, trim) {
if (left === right) {
return 1;
}
if (TypeUtils.isNullOrUndefined(left) ||
TypeUtils.isNullOrUndefined(right)) {
return 0;
}
if (arguments.length < 4) {
if (arguments.length < 3) {
ignoreCase = false;
}
trim = false;
}
if (ignoreCase) {
left = left.toLowerCase();
right = right.toLowerCase();
}
if (trim) {
left = left.trim();
right = right.trim();
}
var distance = 0;
if (left !== right) {
var matrix = new Array(left.length + 1);
for (var i = 0; i < matrix.length; i++) {
matrix[i] = new Array(right.length + 1);
for (var ii = 0; ii < matrix[i].length; ii++) {
matrix[i][ii] = 0;
}
}
for (var i = 0; i <= left.length; i++) {
// delete
matrix[i][0] = i;
}
for (var j = 0; j <= right.length; j++) {
// insert
matrix[0][j] = j;
}
for (var i = 0; i < left.length; i++) {
for (var j = 0; j < right.length; j++) {
if (left[i] === right[j]) {
matrix[i + 1][j + 1] = matrix[i][j];
}
else {
// delete or insert
matrix[i + 1][j + 1] = Math.min(matrix[i][j + 1] + 1, matrix[i + 1][j] + 1);
// substitution
matrix[i + 1][j + 1] = Math.min(matrix[i + 1][j + 1], matrix[i][j] + 1);
}
}
distance = matrix[left.length][right.length];
}
}
return 1.0 - distance / Math.max(left.length, right.length);
} | javascript | function similarity(left, right, ignoreCase, trim) {
if (left === right) {
return 1;
}
if (TypeUtils.isNullOrUndefined(left) ||
TypeUtils.isNullOrUndefined(right)) {
return 0;
}
if (arguments.length < 4) {
if (arguments.length < 3) {
ignoreCase = false;
}
trim = false;
}
if (ignoreCase) {
left = left.toLowerCase();
right = right.toLowerCase();
}
if (trim) {
left = left.trim();
right = right.trim();
}
var distance = 0;
if (left !== right) {
var matrix = new Array(left.length + 1);
for (var i = 0; i < matrix.length; i++) {
matrix[i] = new Array(right.length + 1);
for (var ii = 0; ii < matrix[i].length; ii++) {
matrix[i][ii] = 0;
}
}
for (var i = 0; i <= left.length; i++) {
// delete
matrix[i][0] = i;
}
for (var j = 0; j <= right.length; j++) {
// insert
matrix[0][j] = j;
}
for (var i = 0; i < left.length; i++) {
for (var j = 0; j < right.length; j++) {
if (left[i] === right[j]) {
matrix[i + 1][j + 1] = matrix[i][j];
}
else {
// delete or insert
matrix[i + 1][j + 1] = Math.min(matrix[i][j + 1] + 1, matrix[i + 1][j] + 1);
// substitution
matrix[i + 1][j + 1] = Math.min(matrix[i + 1][j + 1], matrix[i][j] + 1);
}
}
distance = matrix[left.length][right.length];
}
}
return 1.0 - distance / Math.max(left.length, right.length);
} | [
"function",
"similarity",
"(",
"left",
",",
"right",
",",
"ignoreCase",
",",
"trim",
")",
"{",
"if",
"(",
"left",
"===",
"right",
")",
"{",
"return",
"1",
";",
"}",
"if",
"(",
"TypeUtils",
".",
"isNullOrUndefined",
"(",
"left",
")",
"||",
"TypeUtils",
".",
"isNullOrUndefined",
"(",
"right",
")",
")",
"{",
"return",
"0",
";",
"}",
"if",
"(",
"arguments",
".",
"length",
"<",
"4",
")",
"{",
"if",
"(",
"arguments",
".",
"length",
"<",
"3",
")",
"{",
"ignoreCase",
"=",
"false",
";",
"}",
"trim",
"=",
"false",
";",
"}",
"if",
"(",
"ignoreCase",
")",
"{",
"left",
"=",
"left",
".",
"toLowerCase",
"(",
")",
";",
"right",
"=",
"right",
".",
"toLowerCase",
"(",
")",
";",
"}",
"if",
"(",
"trim",
")",
"{",
"left",
"=",
"left",
".",
"trim",
"(",
")",
";",
"right",
"=",
"right",
".",
"trim",
"(",
")",
";",
"}",
"var",
"distance",
"=",
"0",
";",
"if",
"(",
"left",
"!==",
"right",
")",
"{",
"var",
"matrix",
"=",
"new",
"Array",
"(",
"left",
".",
"length",
"+",
"1",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"matrix",
".",
"length",
";",
"i",
"++",
")",
"{",
"matrix",
"[",
"i",
"]",
"=",
"new",
"Array",
"(",
"right",
".",
"length",
"+",
"1",
")",
";",
"for",
"(",
"var",
"ii",
"=",
"0",
";",
"ii",
"<",
"matrix",
"[",
"i",
"]",
".",
"length",
";",
"ii",
"++",
")",
"{",
"matrix",
"[",
"i",
"]",
"[",
"ii",
"]",
"=",
"0",
";",
"}",
"}",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<=",
"left",
".",
"length",
";",
"i",
"++",
")",
"{",
"matrix",
"[",
"i",
"]",
"[",
"0",
"]",
"=",
"i",
";",
"}",
"for",
"(",
"var",
"j",
"=",
"0",
";",
"j",
"<=",
"right",
".",
"length",
";",
"j",
"++",
")",
"{",
"matrix",
"[",
"0",
"]",
"[",
"j",
"]",
"=",
"j",
";",
"}",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"left",
".",
"length",
";",
"i",
"++",
")",
"{",
"for",
"(",
"var",
"j",
"=",
"0",
";",
"j",
"<",
"right",
".",
"length",
";",
"j",
"++",
")",
"{",
"if",
"(",
"left",
"[",
"i",
"]",
"===",
"right",
"[",
"j",
"]",
")",
"{",
"matrix",
"[",
"i",
"+",
"1",
"]",
"[",
"j",
"+",
"1",
"]",
"=",
"matrix",
"[",
"i",
"]",
"[",
"j",
"]",
";",
"}",
"else",
"{",
"matrix",
"[",
"i",
"+",
"1",
"]",
"[",
"j",
"+",
"1",
"]",
"=",
"Math",
".",
"min",
"(",
"matrix",
"[",
"i",
"]",
"[",
"j",
"+",
"1",
"]",
"+",
"1",
",",
"matrix",
"[",
"i",
"+",
"1",
"]",
"[",
"j",
"]",
"+",
"1",
")",
";",
"matrix",
"[",
"i",
"+",
"1",
"]",
"[",
"j",
"+",
"1",
"]",
"=",
"Math",
".",
"min",
"(",
"matrix",
"[",
"i",
"+",
"1",
"]",
"[",
"j",
"+",
"1",
"]",
",",
"matrix",
"[",
"i",
"]",
"[",
"j",
"]",
"+",
"1",
")",
";",
"}",
"}",
"distance",
"=",
"matrix",
"[",
"left",
".",
"length",
"]",
"[",
"right",
".",
"length",
"]",
";",
"}",
"}",
"return",
"1.0",
"-",
"distance",
"/",
"Math",
".",
"max",
"(",
"left",
".",
"length",
",",
"right",
".",
"length",
")",
";",
"}"
] | Returns the similarity of strings.
@function similarity
@param {string} left The "left" string.
@param {string} right The "right" string.
@param {boolean} [ignoreCase] Compare case insensitive or not.
@param {boolean} [trim] Trim both strings before comparison or not.
@return {Number} The similarity between 0 (0 %) and 1 (100 %). | [
"Returns",
"the",
"similarity",
"of",
"strings",
"."
] | 83478b3a222574ad9e76f07076b798e6f2d8e6ac | https://github.com/mkloubert/nativescript-stringformat/blob/83478b3a222574ad9e76f07076b798e6f2d8e6ac/plugin/index.js#L587-L642 | train |
sheebz/phantom-proxy | lib/phantom.js | function (filename, callbackFn) {
var self = this;
request.post(this.options.hostAndPort + '/phantom/functions/injectJs', {form:{args:JSON.stringify(arguments)}},
function (error, response, body) {
if (response.statusCode === 200) {
callbackFn && callbackFn.call(self, body);
}
else {
console.error(body);
throw new Error(body);
}
});
} | javascript | function (filename, callbackFn) {
var self = this;
request.post(this.options.hostAndPort + '/phantom/functions/injectJs', {form:{args:JSON.stringify(arguments)}},
function (error, response, body) {
if (response.statusCode === 200) {
callbackFn && callbackFn.call(self, body);
}
else {
console.error(body);
throw new Error(body);
}
});
} | [
"function",
"(",
"filename",
",",
"callbackFn",
")",
"{",
"var",
"self",
"=",
"this",
";",
"request",
".",
"post",
"(",
"this",
".",
"options",
".",
"hostAndPort",
"+",
"'/phantom/functions/injectJs'",
",",
"{",
"form",
":",
"{",
"args",
":",
"JSON",
".",
"stringify",
"(",
"arguments",
")",
"}",
"}",
",",
"function",
"(",
"error",
",",
"response",
",",
"body",
")",
"{",
"if",
"(",
"response",
".",
"statusCode",
"===",
"200",
")",
"{",
"callbackFn",
"&&",
"callbackFn",
".",
"call",
"(",
"self",
",",
"body",
")",
";",
"}",
"else",
"{",
"console",
".",
"error",
"(",
"body",
")",
";",
"throw",
"new",
"Error",
"(",
"body",
")",
";",
"}",
"}",
")",
";",
"}"
] | Injects external script code from the specified file. If the file can not be found in the current directory, libraryPath is used for additional look up. This function returns true if injection is successful, otherwise it returns false. | [
"Injects",
"external",
"script",
"code",
"from",
"the",
"specified",
"file",
".",
"If",
"the",
"file",
"can",
"not",
"be",
"found",
"in",
"the",
"current",
"directory",
"libraryPath",
"is",
"used",
"for",
"additional",
"look",
"up",
".",
"This",
"function",
"returns",
"true",
"if",
"injection",
"is",
"successful",
"otherwise",
"it",
"returns",
"false",
"."
] | a4963662205400e542668938ce5cf1ab9a66fba0 | https://github.com/sheebz/phantom-proxy/blob/a4963662205400e542668938ce5cf1ab9a66fba0/lib/phantom.js#L106-L118 | train |
|
getdave/grunt-deployments | tasks/deployments.js | db_import | function db_import(config, src) {
var cmd;
// 1) Create cmd string from Lo-Dash template
var tpl_mysql = grunt.template.process(tpls.mysql, {
data: {
host: config.host,
user: config.user,
pass: config.pass,
database: config.database,
path: src
}
});
// 2) Test whether target MYSQL DB is local or whether requires remote access via SSH
if (typeof config.ssh_host === "undefined") { // it's a local connection
grunt.log.writeln("Importing into local database");
cmd = tpl_mysql + " < " + src;
} else { // it's a remote connection
var tpl_ssh = grunt.template.process(tpls.ssh, {
data: {
host: config.ssh_host
}
});
grunt.log.writeln("Importing DUMP into remote database");
cmd = tpl_ssh + " '" + tpl_mysql + "' < " + src;
}
// Execute cmd
shell.exec(cmd);
grunt.log.oklns("Database imported succesfully");
} | javascript | function db_import(config, src) {
var cmd;
// 1) Create cmd string from Lo-Dash template
var tpl_mysql = grunt.template.process(tpls.mysql, {
data: {
host: config.host,
user: config.user,
pass: config.pass,
database: config.database,
path: src
}
});
// 2) Test whether target MYSQL DB is local or whether requires remote access via SSH
if (typeof config.ssh_host === "undefined") { // it's a local connection
grunt.log.writeln("Importing into local database");
cmd = tpl_mysql + " < " + src;
} else { // it's a remote connection
var tpl_ssh = grunt.template.process(tpls.ssh, {
data: {
host: config.ssh_host
}
});
grunt.log.writeln("Importing DUMP into remote database");
cmd = tpl_ssh + " '" + tpl_mysql + "' < " + src;
}
// Execute cmd
shell.exec(cmd);
grunt.log.oklns("Database imported succesfully");
} | [
"function",
"db_import",
"(",
"config",
",",
"src",
")",
"{",
"var",
"cmd",
";",
"var",
"tpl_mysql",
"=",
"grunt",
".",
"template",
".",
"process",
"(",
"tpls",
".",
"mysql",
",",
"{",
"data",
":",
"{",
"host",
":",
"config",
".",
"host",
",",
"user",
":",
"config",
".",
"user",
",",
"pass",
":",
"config",
".",
"pass",
",",
"database",
":",
"config",
".",
"database",
",",
"path",
":",
"src",
"}",
"}",
")",
";",
"if",
"(",
"typeof",
"config",
".",
"ssh_host",
"===",
"\"undefined\"",
")",
"{",
"grunt",
".",
"log",
".",
"writeln",
"(",
"\"Importing into local database\"",
")",
";",
"cmd",
"=",
"tpl_mysql",
"+",
"\" < \"",
"+",
"src",
";",
"}",
"else",
"{",
"var",
"tpl_ssh",
"=",
"grunt",
".",
"template",
".",
"process",
"(",
"tpls",
".",
"ssh",
",",
"{",
"data",
":",
"{",
"host",
":",
"config",
".",
"ssh_host",
"}",
"}",
")",
";",
"grunt",
".",
"log",
".",
"writeln",
"(",
"\"Importing DUMP into remote database\"",
")",
";",
"cmd",
"=",
"tpl_ssh",
"+",
"\" '\"",
"+",
"tpl_mysql",
"+",
"\"' < \"",
"+",
"src",
";",
"}",
"shell",
".",
"exec",
"(",
"cmd",
")",
";",
"grunt",
".",
"log",
".",
"oklns",
"(",
"\"Database imported succesfully\"",
")",
";",
"}"
] | Imports a .sql file into the DB provided | [
"Imports",
"a",
".",
"sql",
"file",
"into",
"the",
"DB",
"provided"
] | 504a50e9ce4367d0ee5e74fd83dd7d18d46ad3e7 | https://github.com/getdave/grunt-deployments/blob/504a50e9ce4367d0ee5e74fd83dd7d18d46ad3e7/tasks/deployments.js#L134-L170 | train |
getdave/grunt-deployments | tasks/deployments.js | db_dump | function db_dump(config, output_paths) {
var cmd;
grunt.file.mkdir(output_paths.dir);
// 2) Compile MYSQL cmd via Lo-Dash template string
var tpl_mysqldump = grunt.template.process(tpls.mysqldump, {
data: {
user: config.user,
pass: config.pass,
database: config.database,
host: config.host
}
});
// 3) Test whether MYSQL DB is local or whether requires remote access via SSH
if (typeof config.ssh_host === "undefined") { // it's a local connection
grunt.log.writeln("Creating DUMP of local database");
cmd = tpl_mysqldump;
} else { // it's a remote connection
var tpl_ssh = grunt.template.process(tpls.ssh, {
data: {
host: config.ssh_host
}
});
grunt.log.writeln("Creating DUMP of remote database");
cmd = tpl_ssh + " \\ " + tpl_mysqldump;
}
// Capture output...
var output = shell.exec(cmd, {silent: true}).output;
// Write output to file using native Grunt methods
grunt.file.write( output_paths.file, output );
grunt.log.oklns("Database DUMP succesfully exported to: " + output_paths.file);
} | javascript | function db_dump(config, output_paths) {
var cmd;
grunt.file.mkdir(output_paths.dir);
// 2) Compile MYSQL cmd via Lo-Dash template string
var tpl_mysqldump = grunt.template.process(tpls.mysqldump, {
data: {
user: config.user,
pass: config.pass,
database: config.database,
host: config.host
}
});
// 3) Test whether MYSQL DB is local or whether requires remote access via SSH
if (typeof config.ssh_host === "undefined") { // it's a local connection
grunt.log.writeln("Creating DUMP of local database");
cmd = tpl_mysqldump;
} else { // it's a remote connection
var tpl_ssh = grunt.template.process(tpls.ssh, {
data: {
host: config.ssh_host
}
});
grunt.log.writeln("Creating DUMP of remote database");
cmd = tpl_ssh + " \\ " + tpl_mysqldump;
}
// Capture output...
var output = shell.exec(cmd, {silent: true}).output;
// Write output to file using native Grunt methods
grunt.file.write( output_paths.file, output );
grunt.log.oklns("Database DUMP succesfully exported to: " + output_paths.file);
} | [
"function",
"db_dump",
"(",
"config",
",",
"output_paths",
")",
"{",
"var",
"cmd",
";",
"grunt",
".",
"file",
".",
"mkdir",
"(",
"output_paths",
".",
"dir",
")",
";",
"var",
"tpl_mysqldump",
"=",
"grunt",
".",
"template",
".",
"process",
"(",
"tpls",
".",
"mysqldump",
",",
"{",
"data",
":",
"{",
"user",
":",
"config",
".",
"user",
",",
"pass",
":",
"config",
".",
"pass",
",",
"database",
":",
"config",
".",
"database",
",",
"host",
":",
"config",
".",
"host",
"}",
"}",
")",
";",
"if",
"(",
"typeof",
"config",
".",
"ssh_host",
"===",
"\"undefined\"",
")",
"{",
"grunt",
".",
"log",
".",
"writeln",
"(",
"\"Creating DUMP of local database\"",
")",
";",
"cmd",
"=",
"tpl_mysqldump",
";",
"}",
"else",
"{",
"var",
"tpl_ssh",
"=",
"grunt",
".",
"template",
".",
"process",
"(",
"tpls",
".",
"ssh",
",",
"{",
"data",
":",
"{",
"host",
":",
"config",
".",
"ssh_host",
"}",
"}",
")",
";",
"grunt",
".",
"log",
".",
"writeln",
"(",
"\"Creating DUMP of remote database\"",
")",
";",
"cmd",
"=",
"tpl_ssh",
"+",
"\" \\\\ \"",
"+",
"\\\\",
";",
"}",
"tpl_mysqldump",
"var",
"output",
"=",
"shell",
".",
"exec",
"(",
"cmd",
",",
"{",
"silent",
":",
"true",
"}",
")",
".",
"output",
";",
"grunt",
".",
"file",
".",
"write",
"(",
"output_paths",
".",
"file",
",",
"output",
")",
";",
"}"
] | Dumps a MYSQL database to a suitable backup location | [
"Dumps",
"a",
"MYSQL",
"database",
"to",
"a",
"suitable",
"backup",
"location"
] | 504a50e9ce4367d0ee5e74fd83dd7d18d46ad3e7 | https://github.com/getdave/grunt-deployments/blob/504a50e9ce4367d0ee5e74fd83dd7d18d46ad3e7/tasks/deployments.js#L177-L219 | train |
sheebz/phantom-proxy | lib/proxy.js | function (callbackFn) {
var self = this;
request.post(this.options.hostAndPort + '/phantom/functions/exit', {
form:{
}
},
function (error, response, body) {
if (response && response.statusCode === 200) { //server up
self.server.close();
callbackFn && callbackFn.call(self, true);
}
else { //server down
callbackFn.call(self, false);
}
});
} | javascript | function (callbackFn) {
var self = this;
request.post(this.options.hostAndPort + '/phantom/functions/exit', {
form:{
}
},
function (error, response, body) {
if (response && response.statusCode === 200) { //server up
self.server.close();
callbackFn && callbackFn.call(self, true);
}
else { //server down
callbackFn.call(self, false);
}
});
} | [
"function",
"(",
"callbackFn",
")",
"{",
"var",
"self",
"=",
"this",
";",
"request",
".",
"post",
"(",
"this",
".",
"options",
".",
"hostAndPort",
"+",
"'/phantom/functions/exit'",
",",
"{",
"form",
":",
"{",
"}",
"}",
",",
"function",
"(",
"error",
",",
"response",
",",
"body",
")",
"{",
"if",
"(",
"response",
"&&",
"response",
".",
"statusCode",
"===",
"200",
")",
"{",
"self",
".",
"server",
".",
"close",
"(",
")",
";",
"callbackFn",
"&&",
"callbackFn",
".",
"call",
"(",
"self",
",",
"true",
")",
";",
"}",
"else",
"{",
"callbackFn",
".",
"call",
"(",
"self",
",",
"false",
")",
";",
"}",
"}",
")",
";",
"}"
] | terminates phantomjs process | [
"terminates",
"phantomjs",
"process"
] | a4963662205400e542668938ce5cf1ab9a66fba0 | https://github.com/sheebz/phantom-proxy/blob/a4963662205400e542668938ce5cf1ab9a66fba0/lib/proxy.js#L245-L261 | train |
|
sheebz/phantom-proxy | lib/proxy.js | function (options, callbackFn) {
var self = this;
//compensate for optional options parm
if (typeof options === 'function') {
callbackFn = options;
options = {};
}
//assign default port
options.port = options.port || 1061;
options.host = options.host || 'localhost';
options.hostAndPort = 'http://' + options.host + ':' + options.port;
options.eventStreamPath = require('path').normalize(__dirname + '/../temp/events.txt');
options.phantomjsPath = options.phantomjsPath || 'phantomjs';
options.debug && console.log('creating proxy to %s', options.hostAndPort);
this.options = options;
//try starting server
createServer.call(self, options, function (proxy) {
callbackFn.call(self, proxy);
});
return this;//return this to chain end
} | javascript | function (options, callbackFn) {
var self = this;
//compensate for optional options parm
if (typeof options === 'function') {
callbackFn = options;
options = {};
}
//assign default port
options.port = options.port || 1061;
options.host = options.host || 'localhost';
options.hostAndPort = 'http://' + options.host + ':' + options.port;
options.eventStreamPath = require('path').normalize(__dirname + '/../temp/events.txt');
options.phantomjsPath = options.phantomjsPath || 'phantomjs';
options.debug && console.log('creating proxy to %s', options.hostAndPort);
this.options = options;
//try starting server
createServer.call(self, options, function (proxy) {
callbackFn.call(self, proxy);
});
return this;//return this to chain end
} | [
"function",
"(",
"options",
",",
"callbackFn",
")",
"{",
"var",
"self",
"=",
"this",
";",
"if",
"(",
"typeof",
"options",
"===",
"'function'",
")",
"{",
"callbackFn",
"=",
"options",
";",
"options",
"=",
"{",
"}",
";",
"}",
"options",
".",
"port",
"=",
"options",
".",
"port",
"||",
"1061",
";",
"options",
".",
"host",
"=",
"options",
".",
"host",
"||",
"'localhost'",
";",
"options",
".",
"hostAndPort",
"=",
"'http://'",
"+",
"options",
".",
"host",
"+",
"':'",
"+",
"options",
".",
"port",
";",
"options",
".",
"eventStreamPath",
"=",
"require",
"(",
"'path'",
")",
".",
"normalize",
"(",
"__dirname",
"+",
"'/../temp/events.txt'",
")",
";",
"options",
".",
"phantomjsPath",
"=",
"options",
".",
"phantomjsPath",
"||",
"'phantomjs'",
";",
"options",
".",
"debug",
"&&",
"console",
".",
"log",
"(",
"'creating proxy to %s'",
",",
"options",
".",
"hostAndPort",
")",
";",
"this",
".",
"options",
"=",
"options",
";",
"createServer",
".",
"call",
"(",
"self",
",",
"options",
",",
"function",
"(",
"proxy",
")",
"{",
"callbackFn",
".",
"call",
"(",
"self",
",",
"proxy",
")",
";",
"}",
")",
";",
"return",
"this",
";",
"}"
] | creates a new proxy session - creates phantomjs process and webserver module | [
"creates",
"a",
"new",
"proxy",
"session",
"-",
"creates",
"phantomjs",
"process",
"and",
"webserver",
"module"
] | a4963662205400e542668938ce5cf1ab9a66fba0 | https://github.com/sheebz/phantom-proxy/blob/a4963662205400e542668938ce5cf1ab9a66fba0/lib/proxy.js#L263-L289 | train |
|
frdmn/openssl-cert-tools | lib/information.js | function (cert, cb) {
var infoObject = {},
subjectElements = [],
err;
var openssl = spawn('openssl', ['req', '-noout', '-subject', '-nameopt', 'RFC2253']);
// Catch stderr
openssl.stderr.on('data', function (out) {
err = new Error(out);
// Callback and return array
return cb(err, infoObject);
});
openssl.stdout.on('data', function (out) {
var data = out.toString();
// Put each line into an array
var lineArray = data.split('\n');
// Filter out empty ones
lineArray = lineArray.filter(function(n){ return n !== undefined && n !== '' });
/* Construct infoObject */
// Certificate
infoObject.certificate = cert;
// Subject
infoObject.subject = {};
// Split by "/" prefix
subjectElements = lineArray[0].replace('subject=', '').split(',');
// For each elements
for (var iS = 0; iS < subjectElements.length; iS++) {
// Split keys and values by "=" separator
var subjectKeyValue = subjectElements[iS].split('=');
infoObject.subject[subjectKeyValue[0]] = subjectKeyValue[1];
}
// Callback and return array
return cb(err, infoObject);
});
openssl.stdin.write(cert);
openssl.stdin.end();
} | javascript | function (cert, cb) {
var infoObject = {},
subjectElements = [],
err;
var openssl = spawn('openssl', ['req', '-noout', '-subject', '-nameopt', 'RFC2253']);
// Catch stderr
openssl.stderr.on('data', function (out) {
err = new Error(out);
// Callback and return array
return cb(err, infoObject);
});
openssl.stdout.on('data', function (out) {
var data = out.toString();
// Put each line into an array
var lineArray = data.split('\n');
// Filter out empty ones
lineArray = lineArray.filter(function(n){ return n !== undefined && n !== '' });
/* Construct infoObject */
// Certificate
infoObject.certificate = cert;
// Subject
infoObject.subject = {};
// Split by "/" prefix
subjectElements = lineArray[0].replace('subject=', '').split(',');
// For each elements
for (var iS = 0; iS < subjectElements.length; iS++) {
// Split keys and values by "=" separator
var subjectKeyValue = subjectElements[iS].split('=');
infoObject.subject[subjectKeyValue[0]] = subjectKeyValue[1];
}
// Callback and return array
return cb(err, infoObject);
});
openssl.stdin.write(cert);
openssl.stdin.end();
} | [
"function",
"(",
"cert",
",",
"cb",
")",
"{",
"var",
"infoObject",
"=",
"{",
"}",
",",
"subjectElements",
"=",
"[",
"]",
",",
"err",
";",
"var",
"openssl",
"=",
"spawn",
"(",
"'openssl'",
",",
"[",
"'req'",
",",
"'-noout'",
",",
"'-subject'",
",",
"'-nameopt'",
",",
"'RFC2253'",
"]",
")",
";",
"openssl",
".",
"stderr",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"out",
")",
"{",
"err",
"=",
"new",
"Error",
"(",
"out",
")",
";",
"return",
"cb",
"(",
"err",
",",
"infoObject",
")",
";",
"}",
")",
";",
"openssl",
".",
"stdout",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"out",
")",
"{",
"var",
"data",
"=",
"out",
".",
"toString",
"(",
")",
";",
"var",
"lineArray",
"=",
"data",
".",
"split",
"(",
"'\\n'",
")",
";",
"\\n",
"lineArray",
"=",
"lineArray",
".",
"filter",
"(",
"function",
"(",
"n",
")",
"{",
"return",
"n",
"!==",
"undefined",
"&&",
"n",
"!==",
"''",
"}",
")",
";",
"infoObject",
".",
"certificate",
"=",
"cert",
";",
"infoObject",
".",
"subject",
"=",
"{",
"}",
";",
"subjectElements",
"=",
"lineArray",
"[",
"0",
"]",
".",
"replace",
"(",
"'subject='",
",",
"''",
")",
".",
"split",
"(",
"','",
")",
";",
"for",
"(",
"var",
"iS",
"=",
"0",
";",
"iS",
"<",
"subjectElements",
".",
"length",
";",
"iS",
"++",
")",
"{",
"var",
"subjectKeyValue",
"=",
"subjectElements",
"[",
"iS",
"]",
".",
"split",
"(",
"'='",
")",
";",
"infoObject",
".",
"subject",
"[",
"subjectKeyValue",
"[",
"0",
"]",
"]",
"=",
"subjectKeyValue",
"[",
"1",
"]",
";",
"}",
"}",
")",
";",
"return",
"cb",
"(",
"err",
",",
"infoObject",
")",
";",
"openssl",
".",
"stdin",
".",
"write",
"(",
"cert",
")",
";",
"}"
] | Decodes information from the provided certificate
sign request.
@param {String|Buffer} cert Input certificate
@param {Function} cb Callback
@return {Error} err, {Object} info Error and information object | [
"Decodes",
"information",
"from",
"the",
"provided",
"certificate",
"sign",
"request",
"."
] | 20cb9530459e83f0a22a928f06b776681c9d7dfa | https://github.com/frdmn/openssl-cert-tools/blob/20cb9530459e83f0a22a928f06b776681c9d7dfa/lib/information.js#L106-L152 | train |
|
mattdesl/garnish | index.js | toBunyan | function toBunyan (obj) {
if (obj.msg && !obj.message) {
obj.message = obj.msg
delete obj.msg
}
if (typeof obj.level === 'number') {
if (obj.level === 20) obj.level = 'debug'
if (obj.level === 30) obj.level = 'info'
if (obj.level === 40) obj.level = 'warn'
if (obj.level === 50) obj.level = 'error'
}
} | javascript | function toBunyan (obj) {
if (obj.msg && !obj.message) {
obj.message = obj.msg
delete obj.msg
}
if (typeof obj.level === 'number') {
if (obj.level === 20) obj.level = 'debug'
if (obj.level === 30) obj.level = 'info'
if (obj.level === 40) obj.level = 'warn'
if (obj.level === 50) obj.level = 'error'
}
} | [
"function",
"toBunyan",
"(",
"obj",
")",
"{",
"if",
"(",
"obj",
".",
"msg",
"&&",
"!",
"obj",
".",
"message",
")",
"{",
"obj",
".",
"message",
"=",
"obj",
".",
"msg",
"delete",
"obj",
".",
"msg",
"}",
"if",
"(",
"typeof",
"obj",
".",
"level",
"===",
"'number'",
")",
"{",
"if",
"(",
"obj",
".",
"level",
"===",
"20",
")",
"obj",
".",
"level",
"=",
"'debug'",
"if",
"(",
"obj",
".",
"level",
"===",
"30",
")",
"obj",
".",
"level",
"=",
"'info'",
"if",
"(",
"obj",
".",
"level",
"===",
"40",
")",
"obj",
".",
"level",
"=",
"'warn'",
"if",
"(",
"obj",
".",
"level",
"===",
"50",
")",
"obj",
".",
"level",
"=",
"'error'",
"}",
"}"
] | mutate a bole log to bunyan log obj -> null | [
"mutate",
"a",
"bole",
"log",
"to",
"bunyan",
"log",
"obj",
"-",
">",
"null"
] | 27e01cb2769cf5a7d3a1487478d8d9ae63879995 | https://github.com/mattdesl/garnish/blob/27e01cb2769cf5a7d3a1487478d8d9ae63879995/index.js#L47-L59 | train |
back4app/antframework | plugins/ant-graphql/functions/mock.js | mock | function mock (_, mockArgs, fieldArgs, currentValue) {
if (currentValue !== undefined) {
return currentValue;
}
if (mockArgs && mockArgs.with) {
if (fieldArgs) {
try {
return Mustache.render(mockArgs.with, fieldArgs);
} catch (e) {
logger.error(new AntError(
'Coould not renderize field template',
e
));
}
} else {
return mockArgs.with;
}
}
return null;
} | javascript | function mock (_, mockArgs, fieldArgs, currentValue) {
if (currentValue !== undefined) {
return currentValue;
}
if (mockArgs && mockArgs.with) {
if (fieldArgs) {
try {
return Mustache.render(mockArgs.with, fieldArgs);
} catch (e) {
logger.error(new AntError(
'Coould not renderize field template',
e
));
}
} else {
return mockArgs.with;
}
}
return null;
} | [
"function",
"mock",
"(",
"_",
",",
"mockArgs",
",",
"fieldArgs",
",",
"currentValue",
")",
"{",
"if",
"(",
"currentValue",
"!==",
"undefined",
")",
"{",
"return",
"currentValue",
";",
"}",
"if",
"(",
"mockArgs",
"&&",
"mockArgs",
".",
"with",
")",
"{",
"if",
"(",
"fieldArgs",
")",
"{",
"try",
"{",
"return",
"Mustache",
".",
"render",
"(",
"mockArgs",
".",
"with",
",",
"fieldArgs",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"logger",
".",
"error",
"(",
"new",
"AntError",
"(",
"'Coould not renderize field template'",
",",
"e",
")",
")",
";",
"}",
"}",
"else",
"{",
"return",
"mockArgs",
".",
"with",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | This function mocks a GraphQL field value. | [
"This",
"function",
"mocks",
"a",
"GraphQL",
"field",
"value",
"."
] | 7cba4eb6b4846648471662e0265aacd5a7f18645 | https://github.com/back4app/antframework/blob/7cba4eb6b4846648471662e0265aacd5a7f18645/plugins/ant-graphql/functions/mock.js#L11-L30 | train |
yanceyou/runge-kutta-4 | lib/RungeKutta4.js | function(derives, xStart, yStart, h) {
this.derives = derives
this.x = xStart
this.y = yStart || []
this.dimension = this.y.length
this.h = h || 0.01
// cache the k1, k2, k3, k4 of each step
this._k1
this._k2
this._k3
this._k4
} | javascript | function(derives, xStart, yStart, h) {
this.derives = derives
this.x = xStart
this.y = yStart || []
this.dimension = this.y.length
this.h = h || 0.01
// cache the k1, k2, k3, k4 of each step
this._k1
this._k2
this._k3
this._k4
} | [
"function",
"(",
"derives",
",",
"xStart",
",",
"yStart",
",",
"h",
")",
"{",
"this",
".",
"derives",
"=",
"derives",
"this",
".",
"x",
"=",
"xStart",
"this",
".",
"y",
"=",
"yStart",
"||",
"[",
"]",
"this",
".",
"dimension",
"=",
"this",
".",
"y",
".",
"length",
"this",
".",
"h",
"=",
"h",
"||",
"0.01",
"this",
".",
"_k1",
"this",
".",
"_k2",
"this",
".",
"_k3",
"this",
".",
"_k4",
"}"
] | The fourth order Runge-Kutta integration method
@class RungeKutta4
@param {Function} derives Differential equations which needed to integrate
@param {Number} xStart Initial value problem: x0
@param {Array} yStart Initial value problem: y0
@param {Number} h Each step-size value | [
"The",
"fourth",
"order",
"Runge",
"-",
"Kutta",
"integration",
"method"
] | 4d4f2b5a9366727f11006d5527398ca9f9dd5162 | https://github.com/yanceyou/runge-kutta-4/blob/4d4f2b5a9366727f11006d5527398ca9f9dd5162/lib/RungeKutta4.js#L12-L24 | train |
|
yanceyou/runge-kutta-4 | lib/RungeKutta4.js | function() {
var derives = this.derives,
x = this.x,
dimension = this.dimension,
h = this.h
var i, _y = []
// Alias: f() <=> this.derives()
// Xn <=> this.x
// Yn <=> this.y
// H <=> this.h
// K1 <=> this._k1
// calculate _k1: K1 = f(Xn, Yn)
this._k1 = derives(x, this.y)
// calculate _k2: K2 = f(Xn + 0.5 * H, Yn + 0.5 * H * K1)
for (i = 0; i < dimension; i++) {
_y[i] = this.y[i] + h * 0.5 * this._k1[i]
}
this._k2 = derives(x + h * 0.5, _y)
// calculate _k3: K3 = f(Xn + 0.5 * H, Yn + 0.5 * H * K2)
for (i = 0; i < dimension; i++) {
_y[i] = this.y[i] + h * 0.5 * this._k2[i]
}
this._k3 = derives(x + h * 0.5, _y)
// calculate _k4: K4 = f(Xn + H, Yn + H * K3)
for (i = 0; i < dimension; i++) {
_y[i] = this.y[i] + h * this._k3[i]
}
this._k4 = derives(x + h, _y)
// calculate yNext: Y(n + 1) = Yn + H / 6 * (K1 + 2 * K2 + 2 * K3 + K4)
for (i = 0; i < dimension; i++) {
this.y[i] += h / 6 * (this._k1[i] + 2 * this._k2[i] + 2 * this._k3[i] + this._k4[i])
}
// calculate xNext: X(n + 1) = Xn + H
this.x += h
return this.y
} | javascript | function() {
var derives = this.derives,
x = this.x,
dimension = this.dimension,
h = this.h
var i, _y = []
// Alias: f() <=> this.derives()
// Xn <=> this.x
// Yn <=> this.y
// H <=> this.h
// K1 <=> this._k1
// calculate _k1: K1 = f(Xn, Yn)
this._k1 = derives(x, this.y)
// calculate _k2: K2 = f(Xn + 0.5 * H, Yn + 0.5 * H * K1)
for (i = 0; i < dimension; i++) {
_y[i] = this.y[i] + h * 0.5 * this._k1[i]
}
this._k2 = derives(x + h * 0.5, _y)
// calculate _k3: K3 = f(Xn + 0.5 * H, Yn + 0.5 * H * K2)
for (i = 0; i < dimension; i++) {
_y[i] = this.y[i] + h * 0.5 * this._k2[i]
}
this._k3 = derives(x + h * 0.5, _y)
// calculate _k4: K4 = f(Xn + H, Yn + H * K3)
for (i = 0; i < dimension; i++) {
_y[i] = this.y[i] + h * this._k3[i]
}
this._k4 = derives(x + h, _y)
// calculate yNext: Y(n + 1) = Yn + H / 6 * (K1 + 2 * K2 + 2 * K3 + K4)
for (i = 0; i < dimension; i++) {
this.y[i] += h / 6 * (this._k1[i] + 2 * this._k2[i] + 2 * this._k3[i] + this._k4[i])
}
// calculate xNext: X(n + 1) = Xn + H
this.x += h
return this.y
} | [
"function",
"(",
")",
"{",
"var",
"derives",
"=",
"this",
".",
"derives",
",",
"x",
"=",
"this",
".",
"x",
",",
"dimension",
"=",
"this",
".",
"dimension",
",",
"h",
"=",
"this",
".",
"h",
"var",
"i",
",",
"_y",
"=",
"[",
"]",
"this",
".",
"_k1",
"=",
"derives",
"(",
"x",
",",
"this",
".",
"y",
")",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"dimension",
";",
"i",
"++",
")",
"{",
"_y",
"[",
"i",
"]",
"=",
"this",
".",
"y",
"[",
"i",
"]",
"+",
"h",
"*",
"0.5",
"*",
"this",
".",
"_k1",
"[",
"i",
"]",
"}",
"this",
".",
"_k2",
"=",
"derives",
"(",
"x",
"+",
"h",
"*",
"0.5",
",",
"_y",
")",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"dimension",
";",
"i",
"++",
")",
"{",
"_y",
"[",
"i",
"]",
"=",
"this",
".",
"y",
"[",
"i",
"]",
"+",
"h",
"*",
"0.5",
"*",
"this",
".",
"_k2",
"[",
"i",
"]",
"}",
"this",
".",
"_k3",
"=",
"derives",
"(",
"x",
"+",
"h",
"*",
"0.5",
",",
"_y",
")",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"dimension",
";",
"i",
"++",
")",
"{",
"_y",
"[",
"i",
"]",
"=",
"this",
".",
"y",
"[",
"i",
"]",
"+",
"h",
"*",
"this",
".",
"_k3",
"[",
"i",
"]",
"}",
"this",
".",
"_k4",
"=",
"derives",
"(",
"x",
"+",
"h",
",",
"_y",
")",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"dimension",
";",
"i",
"++",
")",
"{",
"this",
".",
"y",
"[",
"i",
"]",
"+=",
"h",
"/",
"6",
"*",
"(",
"this",
".",
"_k1",
"[",
"i",
"]",
"+",
"2",
"*",
"this",
".",
"_k2",
"[",
"i",
"]",
"+",
"2",
"*",
"this",
".",
"_k3",
"[",
"i",
"]",
"+",
"this",
".",
"_k4",
"[",
"i",
"]",
")",
"}",
"this",
".",
"x",
"+=",
"h",
"return",
"this",
".",
"y",
"}"
] | Calculate each step according to step-size h
@return {Array} calculated result at this.x | [
"Calculate",
"each",
"step",
"according",
"to",
"step",
"-",
"size",
"h"
] | 4d4f2b5a9366727f11006d5527398ca9f9dd5162 | https://github.com/yanceyou/runge-kutta-4/blob/4d4f2b5a9366727f11006d5527398ca9f9dd5162/lib/RungeKutta4.js#L32-L76 | train |
|
jasonmorita/react-redux-ui-state | dist/reducer.js | reducer | function reducer() {
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var action = arguments[1];
// add initial state
if (action.type === (0, _.generateType)(_.types.add, (0, _get2.default)(action, 'payload.name'))) {
return _extends({}, state, _defineProperty({}, action.payload.name, action.payload.state));
}
// delete state
if (action.type === (0, _.generateType)(_.types.delete, (0, _get2.default)(action, 'payload.name'))) {
var tempState = _extends({}, state);
delete tempState[action.payload.name];
return tempState;
}
// reset to initial state
if (action.type === (0, _.generateType)(_.types.reset, (0, _get2.default)(action, 'payload.name'))) {
return _extends({}, state, _defineProperty({}, action.payload.name, action.payload.state));
}
// shallow merge for state updates
if (action.type === (0, _.generateType)(_.types.set, (0, _get2.default)(action, 'payload.name'))) {
return (0, _immutabilityHelper2.default)(state,
// if store not created with combinedReducers, assume state is top-level
state[action.payload.name] ? _defineProperty({}, action.payload.name, { $merge: action.payload.state }) : { $merge: action.payload.state });
}
return state;
} | javascript | function reducer() {
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var action = arguments[1];
// add initial state
if (action.type === (0, _.generateType)(_.types.add, (0, _get2.default)(action, 'payload.name'))) {
return _extends({}, state, _defineProperty({}, action.payload.name, action.payload.state));
}
// delete state
if (action.type === (0, _.generateType)(_.types.delete, (0, _get2.default)(action, 'payload.name'))) {
var tempState = _extends({}, state);
delete tempState[action.payload.name];
return tempState;
}
// reset to initial state
if (action.type === (0, _.generateType)(_.types.reset, (0, _get2.default)(action, 'payload.name'))) {
return _extends({}, state, _defineProperty({}, action.payload.name, action.payload.state));
}
// shallow merge for state updates
if (action.type === (0, _.generateType)(_.types.set, (0, _get2.default)(action, 'payload.name'))) {
return (0, _immutabilityHelper2.default)(state,
// if store not created with combinedReducers, assume state is top-level
state[action.payload.name] ? _defineProperty({}, action.payload.name, { $merge: action.payload.state }) : { $merge: action.payload.state });
}
return state;
} | [
"function",
"reducer",
"(",
")",
"{",
"var",
"state",
"=",
"arguments",
".",
"length",
">",
"0",
"&&",
"arguments",
"[",
"0",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"0",
"]",
":",
"{",
"}",
";",
"var",
"action",
"=",
"arguments",
"[",
"1",
"]",
";",
"if",
"(",
"action",
".",
"type",
"===",
"(",
"0",
",",
"_",
".",
"generateType",
")",
"(",
"_",
".",
"types",
".",
"add",
",",
"(",
"0",
",",
"_get2",
".",
"default",
")",
"(",
"action",
",",
"'payload.name'",
")",
")",
")",
"{",
"return",
"_extends",
"(",
"{",
"}",
",",
"state",
",",
"_defineProperty",
"(",
"{",
"}",
",",
"action",
".",
"payload",
".",
"name",
",",
"action",
".",
"payload",
".",
"state",
")",
")",
";",
"}",
"if",
"(",
"action",
".",
"type",
"===",
"(",
"0",
",",
"_",
".",
"generateType",
")",
"(",
"_",
".",
"types",
".",
"delete",
",",
"(",
"0",
",",
"_get2",
".",
"default",
")",
"(",
"action",
",",
"'payload.name'",
")",
")",
")",
"{",
"var",
"tempState",
"=",
"_extends",
"(",
"{",
"}",
",",
"state",
")",
";",
"delete",
"tempState",
"[",
"action",
".",
"payload",
".",
"name",
"]",
";",
"return",
"tempState",
";",
"}",
"if",
"(",
"action",
".",
"type",
"===",
"(",
"0",
",",
"_",
".",
"generateType",
")",
"(",
"_",
".",
"types",
".",
"reset",
",",
"(",
"0",
",",
"_get2",
".",
"default",
")",
"(",
"action",
",",
"'payload.name'",
")",
")",
")",
"{",
"return",
"_extends",
"(",
"{",
"}",
",",
"state",
",",
"_defineProperty",
"(",
"{",
"}",
",",
"action",
".",
"payload",
".",
"name",
",",
"action",
".",
"payload",
".",
"state",
")",
")",
";",
"}",
"if",
"(",
"action",
".",
"type",
"===",
"(",
"0",
",",
"_",
".",
"generateType",
")",
"(",
"_",
".",
"types",
".",
"set",
",",
"(",
"0",
",",
"_get2",
".",
"default",
")",
"(",
"action",
",",
"'payload.name'",
")",
")",
")",
"{",
"return",
"(",
"0",
",",
"_immutabilityHelper2",
".",
"default",
")",
"(",
"state",
",",
"state",
"[",
"action",
".",
"payload",
".",
"name",
"]",
"?",
"_defineProperty",
"(",
"{",
"}",
",",
"action",
".",
"payload",
".",
"name",
",",
"{",
"$merge",
":",
"action",
".",
"payload",
".",
"state",
"}",
")",
":",
"{",
"$merge",
":",
"action",
".",
"payload",
".",
"state",
"}",
")",
";",
"}",
"return",
"state",
";",
"}"
] | this reducer handles all state changes for the uiState slice | [
"this",
"reducer",
"handles",
"all",
"state",
"changes",
"for",
"the",
"uiState",
"slice"
] | 366a896f260c0ec3948afed86b2edf80ba9307af | https://github.com/jasonmorita/react-redux-ui-state/blob/366a896f260c0ec3948afed86b2edf80ba9307af/dist/reducer.js#L26-L55 | train |
EdwonLim/node-sass-china | scripts/coverage.js | suite | function suite() {
process.env.NODESASS_COV = 1;
var coveralls = spawn(bin('coveralls'));
var args = [bin('_mocha')].concat(['--reporter', 'mocha-lcov-reporter']);
var mocha = spawn(process.sass.runtime.execPath, args, {
env: process.env
});
mocha.on('error', function(err) {
console.error(err);
process.exit(1);
});
mocha.stderr.setEncoding('utf8');
mocha.stderr.on('data', function(err) {
console.error(err);
process.exit(1);
});
mocha.stdout.pipe(coveralls.stdin);
} | javascript | function suite() {
process.env.NODESASS_COV = 1;
var coveralls = spawn(bin('coveralls'));
var args = [bin('_mocha')].concat(['--reporter', 'mocha-lcov-reporter']);
var mocha = spawn(process.sass.runtime.execPath, args, {
env: process.env
});
mocha.on('error', function(err) {
console.error(err);
process.exit(1);
});
mocha.stderr.setEncoding('utf8');
mocha.stderr.on('data', function(err) {
console.error(err);
process.exit(1);
});
mocha.stdout.pipe(coveralls.stdin);
} | [
"function",
"suite",
"(",
")",
"{",
"process",
".",
"env",
".",
"NODESASS_COV",
"=",
"1",
";",
"var",
"coveralls",
"=",
"spawn",
"(",
"bin",
"(",
"'coveralls'",
")",
")",
";",
"var",
"args",
"=",
"[",
"bin",
"(",
"'_mocha'",
")",
"]",
".",
"concat",
"(",
"[",
"'--reporter'",
",",
"'mocha-lcov-reporter'",
"]",
")",
";",
"var",
"mocha",
"=",
"spawn",
"(",
"process",
".",
"sass",
".",
"runtime",
".",
"execPath",
",",
"args",
",",
"{",
"env",
":",
"process",
".",
"env",
"}",
")",
";",
"mocha",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"err",
")",
";",
"process",
".",
"exit",
"(",
"1",
")",
";",
"}",
")",
";",
"mocha",
".",
"stderr",
".",
"setEncoding",
"(",
"'utf8'",
")",
";",
"mocha",
".",
"stderr",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"err",
")",
";",
"process",
".",
"exit",
"(",
"1",
")",
";",
"}",
")",
";",
"mocha",
".",
"stdout",
".",
"pipe",
"(",
"coveralls",
".",
"stdin",
")",
";",
"}"
] | Run test suite
@api private | [
"Run",
"test",
"suite"
] | 96c13a84e4d68f20d9c5388ad58e2750c2ce786f | https://github.com/EdwonLim/node-sass-china/blob/96c13a84e4d68f20d9c5388ad58e2750c2ce786f/scripts/coverage.js#L16-L38 | train |
EdwonLim/node-sass-china | scripts/coverage.js | coverage | function coverage() {
var jscoverage = spawn(bin('jscoverage'), ['lib', 'lib-cov']);
jscoverage.on('error', function(err) {
console.error(err);
process.exit(1);
});
jscoverage.stderr.setEncoding('utf8');
jscoverage.stderr.on('data', function(err) {
console.error(err);
process.exit(1);
});
jscoverage.on('close', suite);
} | javascript | function coverage() {
var jscoverage = spawn(bin('jscoverage'), ['lib', 'lib-cov']);
jscoverage.on('error', function(err) {
console.error(err);
process.exit(1);
});
jscoverage.stderr.setEncoding('utf8');
jscoverage.stderr.on('data', function(err) {
console.error(err);
process.exit(1);
});
jscoverage.on('close', suite);
} | [
"function",
"coverage",
"(",
")",
"{",
"var",
"jscoverage",
"=",
"spawn",
"(",
"bin",
"(",
"'jscoverage'",
")",
",",
"[",
"'lib'",
",",
"'lib-cov'",
"]",
")",
";",
"jscoverage",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"err",
")",
";",
"process",
".",
"exit",
"(",
"1",
")",
";",
"}",
")",
";",
"jscoverage",
".",
"stderr",
".",
"setEncoding",
"(",
"'utf8'",
")",
";",
"jscoverage",
".",
"stderr",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"err",
")",
";",
"process",
".",
"exit",
"(",
"1",
")",
";",
"}",
")",
";",
"jscoverage",
".",
"on",
"(",
"'close'",
",",
"suite",
")",
";",
"}"
] | Generate coverage files
@api private | [
"Generate",
"coverage",
"files"
] | 96c13a84e4d68f20d9c5388ad58e2750c2ce786f | https://github.com/EdwonLim/node-sass-china/blob/96c13a84e4d68f20d9c5388ad58e2750c2ce786f/scripts/coverage.js#L46-L61 | train |
mattdesl/garnish | lib/renderer.js | destructureMessage | function destructureMessage (msg) {
const keys = Object.keys(msg)
var res = ''
for (var i = 0; i < keys.length; i++) {
var key = keys[i]
var val = msg[key]
if (i !== 0) res += '\n'
res += chalk.blue(' "' + key + '"')
res += ': '
res += chalk.green('"' + val + '"')
}
return res
} | javascript | function destructureMessage (msg) {
const keys = Object.keys(msg)
var res = ''
for (var i = 0; i < keys.length; i++) {
var key = keys[i]
var val = msg[key]
if (i !== 0) res += '\n'
res += chalk.blue(' "' + key + '"')
res += ': '
res += chalk.green('"' + val + '"')
}
return res
} | [
"function",
"destructureMessage",
"(",
"msg",
")",
"{",
"const",
"keys",
"=",
"Object",
".",
"keys",
"(",
"msg",
")",
"var",
"res",
"=",
"''",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"keys",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"key",
"=",
"keys",
"[",
"i",
"]",
"var",
"val",
"=",
"msg",
"[",
"key",
"]",
"if",
"(",
"i",
"!==",
"0",
")",
"res",
"+=",
"'\\n'",
"\\n",
"res",
"+=",
"chalk",
".",
"blue",
"(",
"' \"'",
"+",
"key",
"+",
"'\"'",
")",
"res",
"+=",
"': '",
"}",
"res",
"+=",
"chalk",
".",
"green",
"(",
"'\"'",
"+",
"val",
"+",
"'\"'",
")",
"}"
] | destructure a message onto an object if the message is an object. obj -> str | [
"destructure",
"a",
"message",
"onto",
"an",
"object",
"if",
"the",
"message",
"is",
"an",
"object",
".",
"obj",
"-",
">",
"str"
] | 27e01cb2769cf5a7d3a1487478d8d9ae63879995 | https://github.com/mattdesl/garnish/blob/27e01cb2769cf5a7d3a1487478d8d9ae63879995/lib/renderer.js#L180-L192 | train |
glayzzle/php-reflection | src/utils/comment.js | function(ast) {
if (ast) {
try {
var doc = reader.parse(ast.lines);
} catch(e) {
console.error(e.stack);
console.log('Source : \n* ' + ast.lines.join('\n* '));
return;
}
this.summary = doc.summary;
this.tags = {};
this.annotations = [];
for(var i = 0; i < doc.body.length; i++) {
var child = doc.body[i];
if (child.kind === 'annotation') {
this.annotations.push(child);
} else {
var name = child.kind.toLowerCase();
if (typeof child.name === 'string') {
name = child.name.toLowerCase();
}
if (!this.tags.hasOwnProperty(name)) {
this.tags[name] = [];
}
this.tags[name].push(child);
}
}
}
} | javascript | function(ast) {
if (ast) {
try {
var doc = reader.parse(ast.lines);
} catch(e) {
console.error(e.stack);
console.log('Source : \n* ' + ast.lines.join('\n* '));
return;
}
this.summary = doc.summary;
this.tags = {};
this.annotations = [];
for(var i = 0; i < doc.body.length; i++) {
var child = doc.body[i];
if (child.kind === 'annotation') {
this.annotations.push(child);
} else {
var name = child.kind.toLowerCase();
if (typeof child.name === 'string') {
name = child.name.toLowerCase();
}
if (!this.tags.hasOwnProperty(name)) {
this.tags[name] = [];
}
this.tags[name].push(child);
}
}
}
} | [
"function",
"(",
"ast",
")",
"{",
"if",
"(",
"ast",
")",
"{",
"try",
"{",
"var",
"doc",
"=",
"reader",
".",
"parse",
"(",
"ast",
".",
"lines",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"console",
".",
"error",
"(",
"e",
".",
"stack",
")",
";",
"console",
".",
"log",
"(",
"'Source : \\n* '",
"+",
"\\n",
")",
";",
"ast",
".",
"lines",
".",
"join",
"(",
"'\\n* '",
")",
"}",
"\\n",
"return",
";",
"this",
".",
"summary",
"=",
"doc",
".",
"summary",
";",
"this",
".",
"tags",
"=",
"{",
"}",
";",
"}",
"}"
] | Initialize a comment declaration
@public
@constructor comment
@property {String} summary
@property {tag[]} tags
@property {annotation[]} annotations | [
"Initialize",
"a",
"comment",
"declaration"
] | 5a636a31a5f5e3f1745987c60d8b69665def3ca9 | https://github.com/glayzzle/php-reflection/blob/5a636a31a5f5e3f1745987c60d8b69665def3ca9/src/utils/comment.js#L20-L48 | train |
|
glayzzle/php-reflection | src/repository/parse.js | function(e) {
delete self._pending[filename];
self.emit('error', {
name: filename,
error: e
});
return reject(e);
} | javascript | function(e) {
delete self._pending[filename];
self.emit('error', {
name: filename,
error: e
});
return reject(e);
} | [
"function",
"(",
"e",
")",
"{",
"delete",
"self",
".",
"_pending",
"[",
"filename",
"]",
";",
"self",
".",
"emit",
"(",
"'error'",
",",
"{",
"name",
":",
"filename",
",",
"error",
":",
"e",
"}",
")",
";",
"return",
"reject",
"(",
"e",
")",
";",
"}"
] | error retrieved from worker | [
"error",
"retrieved",
"from",
"worker"
] | 5a636a31a5f5e3f1745987c60d8b69665def3ca9 | https://github.com/glayzzle/php-reflection/blob/5a636a31a5f5e3f1745987c60d8b69665def3ca9/src/repository/parse.js#L97-L104 | train |
|
back4app/antframework | packages/ant-cli/spec/bin/ant.spec.js | _expectUsageInstructions | async function _expectUsageInstructions(args) {
const { stdout, stderr } = await exec(getAntCommand(args));
expect(stdout).not.toBeNull();
expect(stdout.split('\n')[0]).toEqual(
'Usage: ant.js [--help] [--version] [--config <path>] [--verbose] <command>'
);
expect(stdout).toContain(
`Usage: ant.js [--help] [--version] [--config <path>] [--verbose] <command>
[<args>] [<options>]`
);
expect(stdout).toContain(`Commands:
ant.js create <service> [--template Create a new service
<template>]`);
expect(stdout).toContain(
'--help, -h Show help [boolean]'
);
expect(stdout).toContain(
'--version Show version number [boolean]'
);
expect(stdout).toContain(
'--config, -c Path to YAML config file'
);
expect(stdout).toContain(
'--verbose, -v Show execution logs and error stacks [boolean] [default: false]'
);
expect(stdout).toContain(`Plugins:
Core`);
expect(stdout).toContain(
'For more information, visit https://github.com/back4app/antframework'
);
expect(stderr).toEqual('');
} | javascript | async function _expectUsageInstructions(args) {
const { stdout, stderr } = await exec(getAntCommand(args));
expect(stdout).not.toBeNull();
expect(stdout.split('\n')[0]).toEqual(
'Usage: ant.js [--help] [--version] [--config <path>] [--verbose] <command>'
);
expect(stdout).toContain(
`Usage: ant.js [--help] [--version] [--config <path>] [--verbose] <command>
[<args>] [<options>]`
);
expect(stdout).toContain(`Commands:
ant.js create <service> [--template Create a new service
<template>]`);
expect(stdout).toContain(
'--help, -h Show help [boolean]'
);
expect(stdout).toContain(
'--version Show version number [boolean]'
);
expect(stdout).toContain(
'--config, -c Path to YAML config file'
);
expect(stdout).toContain(
'--verbose, -v Show execution logs and error stacks [boolean] [default: false]'
);
expect(stdout).toContain(`Plugins:
Core`);
expect(stdout).toContain(
'For more information, visit https://github.com/back4app/antframework'
);
expect(stderr).toEqual('');
} | [
"async",
"function",
"_expectUsageInstructions",
"(",
"args",
")",
"{",
"const",
"{",
"stdout",
",",
"stderr",
"}",
"=",
"await",
"exec",
"(",
"getAntCommand",
"(",
"args",
")",
")",
";",
"expect",
"(",
"stdout",
")",
".",
"not",
".",
"toBeNull",
"(",
")",
";",
"expect",
"(",
"stdout",
".",
"split",
"(",
"'\\n'",
")",
"[",
"\\n",
"]",
")",
".",
"0",
"toEqual",
";",
"(",
"'Usage: ant.js [--help] [--version] [--config <path>] [--verbose] <command>'",
")",
"expect",
"(",
"stdout",
")",
".",
"toContain",
"(",
"`",
"`",
")",
";",
"expect",
"(",
"stdout",
")",
".",
"toContain",
"(",
"`",
"`",
")",
";",
"expect",
"(",
"stdout",
")",
".",
"toContain",
"(",
"'--help, -h Show help [boolean]'",
")",
";",
"expect",
"(",
"stdout",
")",
".",
"toContain",
"(",
"'--version Show version number [boolean]'",
")",
";",
"expect",
"(",
"stdout",
")",
".",
"toContain",
"(",
"'--config, -c Path to YAML config file'",
")",
";",
"expect",
"(",
"stdout",
")",
".",
"toContain",
"(",
"'--verbose, -v Show execution logs and error stacks [boolean] [default: false]'",
")",
";",
"expect",
"(",
"stdout",
")",
".",
"toContain",
"(",
"`",
"`",
")",
";",
"expect",
"(",
"stdout",
")",
".",
"toContain",
"(",
"'For more information, visit https://github.com/back4app/antframework'",
")",
";",
"}"
] | Helper function to run the CLI command with args and check the expected
usage instructions as an output.
@param {string} args The args to be sent to the CLI command.
@async
@private | [
"Helper",
"function",
"to",
"run",
"the",
"CLI",
"command",
"with",
"args",
"and",
"check",
"the",
"expected",
"usage",
"instructions",
"as",
"an",
"output",
"."
] | 7cba4eb6b4846648471662e0265aacd5a7f18645 | https://github.com/back4app/antframework/blob/7cba4eb6b4846648471662e0265aacd5a7f18645/packages/ant-cli/spec/bin/ant.spec.js#L32-L63 | train |
back4app/antframework | packages/ant-cli/spec/bin/ant.spec.js | _expectErrorMessage | async function _expectErrorMessage(args, ...errorMessages) {
expect.hasAssertions();
try {
await exec(getAntCommand(args));
throw new Error('It is expected to throw some error');
} catch (e) {
const { code, stdout, stderr } = e;
expect(code).toEqual(1);
expect(stdout).toEqual('');
for(const errorMessage of errorMessages) {
expect(stderr).toContain(errorMessage);
}
}
} | javascript | async function _expectErrorMessage(args, ...errorMessages) {
expect.hasAssertions();
try {
await exec(getAntCommand(args));
throw new Error('It is expected to throw some error');
} catch (e) {
const { code, stdout, stderr } = e;
expect(code).toEqual(1);
expect(stdout).toEqual('');
for(const errorMessage of errorMessages) {
expect(stderr).toContain(errorMessage);
}
}
} | [
"async",
"function",
"_expectErrorMessage",
"(",
"args",
",",
"...",
"errorMessages",
")",
"{",
"expect",
".",
"hasAssertions",
"(",
")",
";",
"try",
"{",
"await",
"exec",
"(",
"getAntCommand",
"(",
"args",
")",
")",
";",
"throw",
"new",
"Error",
"(",
"'It is expected to throw some error'",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"const",
"{",
"code",
",",
"stdout",
",",
"stderr",
"}",
"=",
"e",
";",
"expect",
"(",
"code",
")",
".",
"toEqual",
"(",
"1",
")",
";",
"expect",
"(",
"stdout",
")",
".",
"toEqual",
"(",
"''",
")",
";",
"for",
"(",
"const",
"errorMessage",
"of",
"errorMessages",
")",
"{",
"expect",
"(",
"stderr",
")",
".",
"toContain",
"(",
"errorMessage",
")",
";",
"}",
"}",
"}"
] | Helper function to run the CLI command with args and check the expected error
messages as an output.
@param {string} args The args to be sent to the CLI command.
@param {string} errorMessages The expected error messages.
@async
@private | [
"Helper",
"function",
"to",
"run",
"the",
"CLI",
"command",
"with",
"args",
"and",
"check",
"the",
"expected",
"error",
"messages",
"as",
"an",
"output",
"."
] | 7cba4eb6b4846648471662e0265aacd5a7f18645 | https://github.com/back4app/antframework/blob/7cba4eb6b4846648471662e0265aacd5a7f18645/packages/ant-cli/spec/bin/ant.spec.js#L73-L86 | train |
back4app/antframework | packages/ant-cli/spec/bin/ant.spec.js | _expectSuccessMessage | async function _expectSuccessMessage(args, ...successMessages) {
const { stdout, stderr } = await exec(getAntCommand(args));
for (const successMessage of successMessages) {
expect(stdout).toContain(successMessage);
}
expect(stderr).toEqual('');
} | javascript | async function _expectSuccessMessage(args, ...successMessages) {
const { stdout, stderr } = await exec(getAntCommand(args));
for (const successMessage of successMessages) {
expect(stdout).toContain(successMessage);
}
expect(stderr).toEqual('');
} | [
"async",
"function",
"_expectSuccessMessage",
"(",
"args",
",",
"...",
"successMessages",
")",
"{",
"const",
"{",
"stdout",
",",
"stderr",
"}",
"=",
"await",
"exec",
"(",
"getAntCommand",
"(",
"args",
")",
")",
";",
"for",
"(",
"const",
"successMessage",
"of",
"successMessages",
")",
"{",
"expect",
"(",
"stdout",
")",
".",
"toContain",
"(",
"successMessage",
")",
";",
"}",
"expect",
"(",
"stderr",
")",
".",
"toEqual",
"(",
"''",
")",
";",
"}"
] | Helper function to run the CLI command with args and check the expected CLI
success message.
@param {String} args The args to be sent to the CLI command.
@param {String|Array<String>} successMessages The expected success messages.
@async
@private | [
"Helper",
"function",
"to",
"run",
"the",
"CLI",
"command",
"with",
"args",
"and",
"check",
"the",
"expected",
"CLI",
"success",
"message",
"."
] | 7cba4eb6b4846648471662e0265aacd5a7f18645 | https://github.com/back4app/antframework/blob/7cba4eb6b4846648471662e0265aacd5a7f18645/packages/ant-cli/spec/bin/ant.spec.js#L96-L102 | train |
back4app/antframework | packages/ant-cli/spec/bin/ant.spec.js | _expectPackageVersion | async function _expectPackageVersion(args) {
const packageVersion = require(
path.resolve(__dirname, '../../package.json')
).version;
await _expectSuccessMessage(args, `${packageVersion}\n`);
} | javascript | async function _expectPackageVersion(args) {
const packageVersion = require(
path.resolve(__dirname, '../../package.json')
).version;
await _expectSuccessMessage(args, `${packageVersion}\n`);
} | [
"async",
"function",
"_expectPackageVersion",
"(",
"args",
")",
"{",
"const",
"packageVersion",
"=",
"require",
"(",
"path",
".",
"resolve",
"(",
"__dirname",
",",
"'../../package.json'",
")",
")",
".",
"version",
";",
"await",
"_expectSuccessMessage",
"(",
"args",
",",
"`",
"${",
"packageVersion",
"}",
"\\n",
"`",
")",
";",
"}"
] | Helper function to run the CLI command with args and check the expected CLI
version.
@param {string} args The args to be sent to the CLI command.
@async
@private | [
"Helper",
"function",
"to",
"run",
"the",
"CLI",
"command",
"with",
"args",
"and",
"check",
"the",
"expected",
"CLI",
"version",
"."
] | 7cba4eb6b4846648471662e0265aacd5a7f18645 | https://github.com/back4app/antframework/blob/7cba4eb6b4846648471662e0265aacd5a7f18645/packages/ant-cli/spec/bin/ant.spec.js#L111-L116 | train |
glayzzle/php-reflection | src/utils/position.js | function(node) {
if (node) {
this.start = {
line: node.start.line,
column: node.start.column
};
this.end = {
line: node.end.line,
column: node.end.column
};
this.offset = {
start: node.start.offset,
end: node.end.offset
};
}
} | javascript | function(node) {
if (node) {
this.start = {
line: node.start.line,
column: node.start.column
};
this.end = {
line: node.end.line,
column: node.end.column
};
this.offset = {
start: node.start.offset,
end: node.end.offset
};
}
} | [
"function",
"(",
"node",
")",
"{",
"if",
"(",
"node",
")",
"{",
"this",
".",
"start",
"=",
"{",
"line",
":",
"node",
".",
"start",
".",
"line",
",",
"column",
":",
"node",
".",
"start",
".",
"column",
"}",
";",
"this",
".",
"end",
"=",
"{",
"line",
":",
"node",
".",
"end",
".",
"line",
",",
"column",
":",
"node",
".",
"end",
".",
"column",
"}",
";",
"this",
".",
"offset",
"=",
"{",
"start",
":",
"node",
".",
"start",
".",
"offset",
",",
"end",
":",
"node",
".",
"end",
".",
"offset",
"}",
";",
"}",
"}"
] | Defines a position object
@constructor Position
@property {Object} start
@property {Object} end
@property {Object} offset | [
"Defines",
"a",
"position",
"object"
] | 5a636a31a5f5e3f1745987c60d8b69665def3ca9 | https://github.com/glayzzle/php-reflection/blob/5a636a31a5f5e3f1745987c60d8b69665def3ca9/src/utils/position.js#L15-L30 | train |
|
jbhannah/amperize | lib/amperize.js | Amperize | function Amperize(options) {
this.config = _.merge({}, DEFAULTS, options || {});
this.emits = emits;
this.htmlParser = new html.Parser(
new html.DomHandler(this.emits('read'))
);
} | javascript | function Amperize(options) {
this.config = _.merge({}, DEFAULTS, options || {});
this.emits = emits;
this.htmlParser = new html.Parser(
new html.DomHandler(this.emits('read'))
);
} | [
"function",
"Amperize",
"(",
"options",
")",
"{",
"this",
".",
"config",
"=",
"_",
".",
"merge",
"(",
"{",
"}",
",",
"DEFAULTS",
",",
"options",
"||",
"{",
"}",
")",
";",
"this",
".",
"emits",
"=",
"emits",
";",
"this",
".",
"htmlParser",
"=",
"new",
"html",
".",
"Parser",
"(",
"new",
"html",
".",
"DomHandler",
"(",
"this",
".",
"emits",
"(",
"'read'",
")",
")",
")",
";",
"}"
] | Amperizer constructor. Borrows from Minimize.
https://github.com/Swaagie/minimize/blob/4b815e274a424ca89551d28c4e0dd8b06d9bbdc2/lib/minimize.js#L15
@constructor
@param {Object} options Options object
@api public | [
"Amperizer",
"constructor",
".",
"Borrows",
"from",
"Minimize",
"."
] | 07eaf97136176cc5282702c688cfeef3e70991fb | https://github.com/jbhannah/amperize/blob/07eaf97136176cc5282702c688cfeef3e70991fb/lib/amperize.js#L43-L50 | train |
back4app/antframework | plugins/ant-graphql/functions/resolve.js | resolve | async function resolve (ant, resolveArgs, fieldArgs, currentValue, model) {
let field = null;
if (model) {
field = model.field;
}
if (ant && resolveArgs && resolveArgs.to) {
const antFunction = ant.functionController.getFunction(resolveArgs.to);
if (!antFunction) {
logger.error(new AntError(
`Could not find "${resolveArgs.to}" function`
));
return null;
}
try {
currentValue = antFunction.run(
currentValue !== undefined ? currentValue : fieldArgs
);
if (currentValue instanceof Observable) {
if (
field &&
field.astNode &&
field.astNode.type &&
field.astNode.type.kind === 'ListType'
) {
return await currentValue.pipe(
flatMap(data => data instanceof Array ? data : [ data ]),
toArray()
).toPromise();
} else {
return await currentValue.toPromise();
}
} else {
return currentValue;
}
} catch (e) {
logger.error(new AntError(
`Could not run "${resolveArgs.to}" function`,
e
));
}
}
return null;
} | javascript | async function resolve (ant, resolveArgs, fieldArgs, currentValue, model) {
let field = null;
if (model) {
field = model.field;
}
if (ant && resolveArgs && resolveArgs.to) {
const antFunction = ant.functionController.getFunction(resolveArgs.to);
if (!antFunction) {
logger.error(new AntError(
`Could not find "${resolveArgs.to}" function`
));
return null;
}
try {
currentValue = antFunction.run(
currentValue !== undefined ? currentValue : fieldArgs
);
if (currentValue instanceof Observable) {
if (
field &&
field.astNode &&
field.astNode.type &&
field.astNode.type.kind === 'ListType'
) {
return await currentValue.pipe(
flatMap(data => data instanceof Array ? data : [ data ]),
toArray()
).toPromise();
} else {
return await currentValue.toPromise();
}
} else {
return currentValue;
}
} catch (e) {
logger.error(new AntError(
`Could not run "${resolveArgs.to}" function`,
e
));
}
}
return null;
} | [
"async",
"function",
"resolve",
"(",
"ant",
",",
"resolveArgs",
",",
"fieldArgs",
",",
"currentValue",
",",
"model",
")",
"{",
"let",
"field",
"=",
"null",
";",
"if",
"(",
"model",
")",
"{",
"field",
"=",
"model",
".",
"field",
";",
"}",
"if",
"(",
"ant",
"&&",
"resolveArgs",
"&&",
"resolveArgs",
".",
"to",
")",
"{",
"const",
"antFunction",
"=",
"ant",
".",
"functionController",
".",
"getFunction",
"(",
"resolveArgs",
".",
"to",
")",
";",
"if",
"(",
"!",
"antFunction",
")",
"{",
"logger",
".",
"error",
"(",
"new",
"AntError",
"(",
"`",
"${",
"resolveArgs",
".",
"to",
"}",
"`",
")",
")",
";",
"return",
"null",
";",
"}",
"try",
"{",
"currentValue",
"=",
"antFunction",
".",
"run",
"(",
"currentValue",
"!==",
"undefined",
"?",
"currentValue",
":",
"fieldArgs",
")",
";",
"if",
"(",
"currentValue",
"instanceof",
"Observable",
")",
"{",
"if",
"(",
"field",
"&&",
"field",
".",
"astNode",
"&&",
"field",
".",
"astNode",
".",
"type",
"&&",
"field",
".",
"astNode",
".",
"type",
".",
"kind",
"===",
"'ListType'",
")",
"{",
"return",
"await",
"currentValue",
".",
"pipe",
"(",
"flatMap",
"(",
"data",
"=>",
"data",
"instanceof",
"Array",
"?",
"data",
":",
"[",
"data",
"]",
")",
",",
"toArray",
"(",
")",
")",
".",
"toPromise",
"(",
")",
";",
"}",
"else",
"{",
"return",
"await",
"currentValue",
".",
"toPromise",
"(",
")",
";",
"}",
"}",
"else",
"{",
"return",
"currentValue",
";",
"}",
"}",
"catch",
"(",
"e",
")",
"{",
"logger",
".",
"error",
"(",
"new",
"AntError",
"(",
"`",
"${",
"resolveArgs",
".",
"to",
"}",
"`",
",",
"e",
")",
")",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | This function resolves a GraphQL field value. | [
"This",
"function",
"resolves",
"a",
"GraphQL",
"field",
"value",
"."
] | 7cba4eb6b4846648471662e0265aacd5a7f18645 | https://github.com/back4app/antframework/blob/7cba4eb6b4846648471662e0265aacd5a7f18645/plugins/ant-graphql/functions/resolve.js#L12-L54 | train |
jasonmorita/react-redux-ui-state | dist/index.js | dispatchToProps | function dispatchToProps(dispatch) {
return {
add: function add() {
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var name = arguments[1];
return dispatch({
type: generateType(types.add, name),
payload: {
name: name,
state: state
}
});
},
delete: function _delete(name) {
return dispatch({
type: generateType(types.delete, name),
payload: {
name: name
}
});
},
reset: function reset() {
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var name = arguments[1];
return dispatch({
type: generateType(types.reset, name),
payload: {
name: name,
state: state
}
});
},
set: function set() {
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var name = arguments[1];
return dispatch({
type: generateType(types.set, name),
payload: {
name: name,
state: state
}
});
}
};
} | javascript | function dispatchToProps(dispatch) {
return {
add: function add() {
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var name = arguments[1];
return dispatch({
type: generateType(types.add, name),
payload: {
name: name,
state: state
}
});
},
delete: function _delete(name) {
return dispatch({
type: generateType(types.delete, name),
payload: {
name: name
}
});
},
reset: function reset() {
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var name = arguments[1];
return dispatch({
type: generateType(types.reset, name),
payload: {
name: name,
state: state
}
});
},
set: function set() {
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var name = arguments[1];
return dispatch({
type: generateType(types.set, name),
payload: {
name: name,
state: state
}
});
}
};
} | [
"function",
"dispatchToProps",
"(",
"dispatch",
")",
"{",
"return",
"{",
"add",
":",
"function",
"add",
"(",
")",
"{",
"var",
"state",
"=",
"arguments",
".",
"length",
">",
"0",
"&&",
"arguments",
"[",
"0",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"0",
"]",
":",
"{",
"}",
";",
"var",
"name",
"=",
"arguments",
"[",
"1",
"]",
";",
"return",
"dispatch",
"(",
"{",
"type",
":",
"generateType",
"(",
"types",
".",
"add",
",",
"name",
")",
",",
"payload",
":",
"{",
"name",
":",
"name",
",",
"state",
":",
"state",
"}",
"}",
")",
";",
"}",
",",
"delete",
":",
"function",
"_delete",
"(",
"name",
")",
"{",
"return",
"dispatch",
"(",
"{",
"type",
":",
"generateType",
"(",
"types",
".",
"delete",
",",
"name",
")",
",",
"payload",
":",
"{",
"name",
":",
"name",
"}",
"}",
")",
";",
"}",
",",
"reset",
":",
"function",
"reset",
"(",
")",
"{",
"var",
"state",
"=",
"arguments",
".",
"length",
">",
"0",
"&&",
"arguments",
"[",
"0",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"0",
"]",
":",
"{",
"}",
";",
"var",
"name",
"=",
"arguments",
"[",
"1",
"]",
";",
"return",
"dispatch",
"(",
"{",
"type",
":",
"generateType",
"(",
"types",
".",
"reset",
",",
"name",
")",
",",
"payload",
":",
"{",
"name",
":",
"name",
",",
"state",
":",
"state",
"}",
"}",
")",
";",
"}",
",",
"set",
":",
"function",
"set",
"(",
")",
"{",
"var",
"state",
"=",
"arguments",
".",
"length",
">",
"0",
"&&",
"arguments",
"[",
"0",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"0",
"]",
":",
"{",
"}",
";",
"var",
"name",
"=",
"arguments",
"[",
"1",
"]",
";",
"return",
"dispatch",
"(",
"{",
"type",
":",
"generateType",
"(",
"types",
".",
"set",
",",
"name",
")",
",",
"payload",
":",
"{",
"name",
":",
"name",
",",
"state",
":",
"state",
"}",
"}",
")",
";",
"}",
"}",
";",
"}"
] | these are set as props on the HOC | [
"these",
"are",
"set",
"as",
"props",
"on",
"the",
"HOC"
] | 366a896f260c0ec3948afed86b2edf80ba9307af | https://github.com/jasonmorita/react-redux-ui-state/blob/366a896f260c0ec3948afed86b2edf80ba9307af/dist/index.js#L74-L121 | train |
dudemelo/sails-hook-flash | lib/flash.js | function (type) {
if (this.has(type)) {
var messages = req.session[_session_key][type];
delete req.session[_session_key][type];
}
return messages||[];
} | javascript | function (type) {
if (this.has(type)) {
var messages = req.session[_session_key][type];
delete req.session[_session_key][type];
}
return messages||[];
} | [
"function",
"(",
"type",
")",
"{",
"if",
"(",
"this",
".",
"has",
"(",
"type",
")",
")",
"{",
"var",
"messages",
"=",
"req",
".",
"session",
"[",
"_session_key",
"]",
"[",
"type",
"]",
";",
"delete",
"req",
".",
"session",
"[",
"_session_key",
"]",
"[",
"type",
"]",
";",
"}",
"return",
"messages",
"||",
"[",
"]",
";",
"}"
] | Get a specific type of flash messages
@param {string} type
@return {object} | [
"Get",
"a",
"specific",
"type",
"of",
"flash",
"messages"
] | f23f00239b4d2d9f1925920ebd7da45e42c3d79d | https://github.com/dudemelo/sails-hook-flash/blob/f23f00239b4d2d9f1925920ebd7da45e42c3d79d/lib/flash.js#L59-L65 | train |
|
frdmn/openssl-cert-tools | lib/certificate.js | function (host, port, cb) {
var err,
data = {};
var openssl = spawn('openssl', ['s_client', '-connect', host + ':' + port, '-servername', host]);
// Clear timeout when execution was successful
openssl.on('exit', function(){
clearTimeout(timeoutTimer);
});
// Catch stderr and search for possible errors
openssl.stderr.on('data', function (out) {
// Search for possible errors in stderr
var errorRegexp = /(Connection refused)|(Can't assign requested address)|(gethostbyname failure)|(getaddrinfo: nodename)/;
var regexTester = errorRegexp.test(out);
// If match, raise error
if (regexTester) {
err = new Error(out.toString().replace(/^\s+|\s+$/g, ''));
// Callback and return array
return cb(err, data);
}
});
openssl.stdout.on('data', function (out) {
var data = out.toString();
// Search for certificate in stdout
var matches = data.match(/-----BEGIN CERTIFICATE-----([\s\S.]*)-----END CERTIFICATE-----/);
try {
data = matches[0];
} catch (e) {
// ... otherwise raise error
err = new Error('Couldn\'t extract certificate for ' + host + ':' + port);
}
// ... callback and return certificate
return cb(err, data);
});
// End stdin (otherwise it'll run indefinitely)
openssl.stdin.end();
// Timeout function to kill in case of errors
var timeoutTimer = setTimeout(function(){
openssl.kill();
// ... otherwise throw error
err = new Error('Time out while trying to extract certificate for ' + host + ':' + port);
// and return
return cb(err, data);
}, 5000);
} | javascript | function (host, port, cb) {
var err,
data = {};
var openssl = spawn('openssl', ['s_client', '-connect', host + ':' + port, '-servername', host]);
// Clear timeout when execution was successful
openssl.on('exit', function(){
clearTimeout(timeoutTimer);
});
// Catch stderr and search for possible errors
openssl.stderr.on('data', function (out) {
// Search for possible errors in stderr
var errorRegexp = /(Connection refused)|(Can't assign requested address)|(gethostbyname failure)|(getaddrinfo: nodename)/;
var regexTester = errorRegexp.test(out);
// If match, raise error
if (regexTester) {
err = new Error(out.toString().replace(/^\s+|\s+$/g, ''));
// Callback and return array
return cb(err, data);
}
});
openssl.stdout.on('data', function (out) {
var data = out.toString();
// Search for certificate in stdout
var matches = data.match(/-----BEGIN CERTIFICATE-----([\s\S.]*)-----END CERTIFICATE-----/);
try {
data = matches[0];
} catch (e) {
// ... otherwise raise error
err = new Error('Couldn\'t extract certificate for ' + host + ':' + port);
}
// ... callback and return certificate
return cb(err, data);
});
// End stdin (otherwise it'll run indefinitely)
openssl.stdin.end();
// Timeout function to kill in case of errors
var timeoutTimer = setTimeout(function(){
openssl.kill();
// ... otherwise throw error
err = new Error('Time out while trying to extract certificate for ' + host + ':' + port);
// and return
return cb(err, data);
}, 5000);
} | [
"function",
"(",
"host",
",",
"port",
",",
"cb",
")",
"{",
"var",
"err",
",",
"data",
"=",
"{",
"}",
";",
"var",
"openssl",
"=",
"spawn",
"(",
"'openssl'",
",",
"[",
"'s_client'",
",",
"'-connect'",
",",
"host",
"+",
"':'",
"+",
"port",
",",
"'-servername'",
",",
"host",
"]",
")",
";",
"openssl",
".",
"on",
"(",
"'exit'",
",",
"function",
"(",
")",
"{",
"clearTimeout",
"(",
"timeoutTimer",
")",
";",
"}",
")",
";",
"openssl",
".",
"stderr",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"out",
")",
"{",
"var",
"errorRegexp",
"=",
"/",
"(Connection refused)|(Can't assign requested address)|(gethostbyname failure)|(getaddrinfo: nodename)",
"/",
";",
"var",
"regexTester",
"=",
"errorRegexp",
".",
"test",
"(",
"out",
")",
";",
"if",
"(",
"regexTester",
")",
"{",
"err",
"=",
"new",
"Error",
"(",
"out",
".",
"toString",
"(",
")",
".",
"replace",
"(",
"/",
"^\\s+|\\s+$",
"/",
"g",
",",
"''",
")",
")",
";",
"return",
"cb",
"(",
"err",
",",
"data",
")",
";",
"}",
"}",
")",
";",
"openssl",
".",
"stdout",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"out",
")",
"{",
"var",
"data",
"=",
"out",
".",
"toString",
"(",
")",
";",
"var",
"matches",
"=",
"data",
".",
"match",
"(",
"/",
"-----BEGIN CERTIFICATE-----([\\s\\S.]*)-----END CERTIFICATE-----",
"/",
")",
";",
"try",
"{",
"data",
"=",
"matches",
"[",
"0",
"]",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"err",
"=",
"new",
"Error",
"(",
"'Couldn\\'t extract certificate for '",
"+",
"\\'",
"+",
"host",
"+",
"':'",
")",
";",
"}",
"port",
"}",
")",
";",
"return",
"cb",
"(",
"err",
",",
"data",
")",
";",
"openssl",
".",
"stdin",
".",
"end",
"(",
")",
";",
"}"
] | Download certificate from remote host
@param {String} host Input hostname
@param {String} port Input port
@param {Function} cb Callback
@return {Error} err, {Object} data Error and data object | [
"Download",
"certificate",
"from",
"remote",
"host"
] | 20cb9530459e83f0a22a928f06b776681c9d7dfa | https://github.com/frdmn/openssl-cert-tools/blob/20cb9530459e83f0a22a928f06b776681c9d7dfa/lib/certificate.js#L19-L74 | train |
|
EdwonLim/node-sass-china | scripts/install.js | applyProxy | function applyProxy(options, cb) {
npmconf.load({}, function (er, conf) {
var proxyUrl;
if (!er) {
proxyUrl = conf.get('https-proxy') ||
conf.get('proxy') ||
conf.get('http-proxy');
}
var env = process.env;
options.proxy = proxyUrl ||
env.HTTPS_PROXY ||
env.https_proxy ||
env.HTTP_PROXY ||
env.http_proxy;
cb(options);
});
} | javascript | function applyProxy(options, cb) {
npmconf.load({}, function (er, conf) {
var proxyUrl;
if (!er) {
proxyUrl = conf.get('https-proxy') ||
conf.get('proxy') ||
conf.get('http-proxy');
}
var env = process.env;
options.proxy = proxyUrl ||
env.HTTPS_PROXY ||
env.https_proxy ||
env.HTTP_PROXY ||
env.http_proxy;
cb(options);
});
} | [
"function",
"applyProxy",
"(",
"options",
",",
"cb",
")",
"{",
"npmconf",
".",
"load",
"(",
"{",
"}",
",",
"function",
"(",
"er",
",",
"conf",
")",
"{",
"var",
"proxyUrl",
";",
"if",
"(",
"!",
"er",
")",
"{",
"proxyUrl",
"=",
"conf",
".",
"get",
"(",
"'https-proxy'",
")",
"||",
"conf",
".",
"get",
"(",
"'proxy'",
")",
"||",
"conf",
".",
"get",
"(",
"'http-proxy'",
")",
";",
"}",
"var",
"env",
"=",
"process",
".",
"env",
";",
"options",
".",
"proxy",
"=",
"proxyUrl",
"||",
"env",
".",
"HTTPS_PROXY",
"||",
"env",
".",
"https_proxy",
"||",
"env",
".",
"HTTP_PROXY",
"||",
"env",
".",
"http_proxy",
";",
"cb",
"(",
"options",
")",
";",
"}",
")",
";",
"}"
] | Get applyProxy settings
@param {Object} options
@param {Function} cb
@api private | [
"Get",
"applyProxy",
"settings"
] | 96c13a84e4d68f20d9c5388ad58e2750c2ce786f | https://github.com/EdwonLim/node-sass-china/blob/96c13a84e4d68f20d9c5388ad58e2750c2ce786f/scripts/install.js#L67-L87 | train |
ractivejs/ractive-load | dist/ractive-load.es.js | generateSourceMap | function generateSourceMap ( definition, options ) {
if ( options === void 0 ) { options = {}; }
if ( 'padding' in options ) {
options.offset = options.padding;
if ( !alreadyWarned ) {
console.warn( 'rcu: options.padding is deprecated, use options.offset instead' ); // eslint-disable-line no-console
alreadyWarned = true;
}
}
var mappings = '';
if ( definition.scriptStart ) {
// The generated code probably includes a load of module gubbins - we don't bother
// mapping that to anything, instead we just have a bunch of empty lines
var offset = new Array( ( options.offset || 0 ) + 1 ).join( ';' );
var lines = definition.script.split( '\n' );
var encoded;
if ( options.hires !== false ) {
var previousLineEnd = -definition.scriptStart.column;
encoded = lines.map( function ( line, i ) {
var lineOffset = i === 0 ? definition.scriptStart.line : 1;
var encoded = encode([ 0, 0, lineOffset, -previousLineEnd ]);
var lineEnd = line.length;
for ( var j = 1; j < lineEnd; j += 1 ) {
encoded += ',CAAC';
}
previousLineEnd = i === 0 ?
lineEnd + definition.scriptStart.column :
Math.max( 0, lineEnd - 1 );
return encoded;
});
} else {
encoded = lines.map( function ( line, i ) {
if ( i === 0 ) {
// first mapping points to code immediately following opening <script> tag
return encode([ 0, 0, definition.scriptStart.line, definition.scriptStart.column ]);
}
if ( i === 1 ) {
return encode([ 0, 0, 1, -definition.scriptStart.column ]);
}
return 'AACA'; // equates to [ 0, 0, 1, 0 ];
});
}
mappings = offset + encoded.join( ';' );
}
return new SourceMap({
file: options.file || null,
sources: [ options.source || null ],
sourcesContent: [ definition.source ],
names: [],
mappings: mappings
});
} | javascript | function generateSourceMap ( definition, options ) {
if ( options === void 0 ) { options = {}; }
if ( 'padding' in options ) {
options.offset = options.padding;
if ( !alreadyWarned ) {
console.warn( 'rcu: options.padding is deprecated, use options.offset instead' ); // eslint-disable-line no-console
alreadyWarned = true;
}
}
var mappings = '';
if ( definition.scriptStart ) {
// The generated code probably includes a load of module gubbins - we don't bother
// mapping that to anything, instead we just have a bunch of empty lines
var offset = new Array( ( options.offset || 0 ) + 1 ).join( ';' );
var lines = definition.script.split( '\n' );
var encoded;
if ( options.hires !== false ) {
var previousLineEnd = -definition.scriptStart.column;
encoded = lines.map( function ( line, i ) {
var lineOffset = i === 0 ? definition.scriptStart.line : 1;
var encoded = encode([ 0, 0, lineOffset, -previousLineEnd ]);
var lineEnd = line.length;
for ( var j = 1; j < lineEnd; j += 1 ) {
encoded += ',CAAC';
}
previousLineEnd = i === 0 ?
lineEnd + definition.scriptStart.column :
Math.max( 0, lineEnd - 1 );
return encoded;
});
} else {
encoded = lines.map( function ( line, i ) {
if ( i === 0 ) {
// first mapping points to code immediately following opening <script> tag
return encode([ 0, 0, definition.scriptStart.line, definition.scriptStart.column ]);
}
if ( i === 1 ) {
return encode([ 0, 0, 1, -definition.scriptStart.column ]);
}
return 'AACA'; // equates to [ 0, 0, 1, 0 ];
});
}
mappings = offset + encoded.join( ';' );
}
return new SourceMap({
file: options.file || null,
sources: [ options.source || null ],
sourcesContent: [ definition.source ],
names: [],
mappings: mappings
});
} | [
"function",
"generateSourceMap",
"(",
"definition",
",",
"options",
")",
"{",
"if",
"(",
"options",
"===",
"void",
"0",
")",
"{",
"options",
"=",
"{",
"}",
";",
"}",
"if",
"(",
"'padding'",
"in",
"options",
")",
"{",
"options",
".",
"offset",
"=",
"options",
".",
"padding",
";",
"if",
"(",
"!",
"alreadyWarned",
")",
"{",
"console",
".",
"warn",
"(",
"'rcu: options.padding is deprecated, use options.offset instead'",
")",
";",
"alreadyWarned",
"=",
"true",
";",
"}",
"}",
"var",
"mappings",
"=",
"''",
";",
"if",
"(",
"definition",
".",
"scriptStart",
")",
"{",
"var",
"offset",
"=",
"new",
"Array",
"(",
"(",
"options",
".",
"offset",
"||",
"0",
")",
"+",
"1",
")",
".",
"join",
"(",
"';'",
")",
";",
"var",
"lines",
"=",
"definition",
".",
"script",
".",
"split",
"(",
"'\\n'",
")",
";",
"\\n",
"var",
"encoded",
";",
"if",
"(",
"options",
".",
"hires",
"!==",
"false",
")",
"{",
"var",
"previousLineEnd",
"=",
"-",
"definition",
".",
"scriptStart",
".",
"column",
";",
"encoded",
"=",
"lines",
".",
"map",
"(",
"function",
"(",
"line",
",",
"i",
")",
"{",
"var",
"lineOffset",
"=",
"i",
"===",
"0",
"?",
"definition",
".",
"scriptStart",
".",
"line",
":",
"1",
";",
"var",
"encoded",
"=",
"encode",
"(",
"[",
"0",
",",
"0",
",",
"lineOffset",
",",
"-",
"previousLineEnd",
"]",
")",
";",
"var",
"lineEnd",
"=",
"line",
".",
"length",
";",
"for",
"(",
"var",
"j",
"=",
"1",
";",
"j",
"<",
"lineEnd",
";",
"j",
"+=",
"1",
")",
"{",
"encoded",
"+=",
"',CAAC'",
";",
"}",
"previousLineEnd",
"=",
"i",
"===",
"0",
"?",
"lineEnd",
"+",
"definition",
".",
"scriptStart",
".",
"column",
":",
"Math",
".",
"max",
"(",
"0",
",",
"lineEnd",
"-",
"1",
")",
";",
"return",
"encoded",
";",
"}",
")",
";",
"}",
"else",
"{",
"encoded",
"=",
"lines",
".",
"map",
"(",
"function",
"(",
"line",
",",
"i",
")",
"{",
"if",
"(",
"i",
"===",
"0",
")",
"{",
"return",
"encode",
"(",
"[",
"0",
",",
"0",
",",
"definition",
".",
"scriptStart",
".",
"line",
",",
"definition",
".",
"scriptStart",
".",
"column",
"]",
")",
";",
"}",
"if",
"(",
"i",
"===",
"1",
")",
"{",
"return",
"encode",
"(",
"[",
"0",
",",
"0",
",",
"1",
",",
"-",
"definition",
".",
"scriptStart",
".",
"column",
"]",
")",
";",
"}",
"return",
"'AACA'",
";",
"}",
")",
";",
"}",
"}",
"mappings",
"=",
"offset",
"+",
"encoded",
".",
"join",
"(",
"';'",
")",
";",
"}"
] | Generates a v3 sourcemap between an original source and its built form
@param {object} definition - the result of `rcu.parse( originalSource )`
@param {object} options
@param {string} options.source - the name of the original source file
@param {number=} options.offset - the number of lines in the generated
code that precede the script portion of the original source
@param {string=} options.file - the name of the generated file
@returns {object} | [
"Generates",
"a",
"v3",
"sourcemap",
"between",
"an",
"original",
"source",
"and",
"its",
"built",
"form"
] | 5fdb5e1b7c12c21330d7c96c8f281e149fb1df81 | https://github.com/ractivejs/ractive-load/blob/5fdb5e1b7c12c21330d7c96c8f281e149fb1df81/dist/ractive-load.es.js#L88-L155 | train |
back4app/antframework | packages/ant-util-yargs/lib/yargsHelper.js | handleErrorMessage | function handleErrorMessage (msg, err, command, exitProcess) {
setErrorHandled();
console.error(`Fatal => ${msg}`);
if (err) {
console.error();
if (isVerboseMode()) {
console.error('Error stack:');
console.error(err.stack);
} else {
console.error('For getting the error stack, use --verbose option');
}
}
console.error();
console.error('For getting help:');
console.error(
`${getCliFileName()} --help ${command ? command : '[command]'}`
);
if (!err && msg) {
err = new Error(msg);
}
if (!exitProcess) {
return Analytics.trackError(err).then(() => process.exit(1));
}
process.exit(1);
} | javascript | function handleErrorMessage (msg, err, command, exitProcess) {
setErrorHandled();
console.error(`Fatal => ${msg}`);
if (err) {
console.error();
if (isVerboseMode()) {
console.error('Error stack:');
console.error(err.stack);
} else {
console.error('For getting the error stack, use --verbose option');
}
}
console.error();
console.error('For getting help:');
console.error(
`${getCliFileName()} --help ${command ? command : '[command]'}`
);
if (!err && msg) {
err = new Error(msg);
}
if (!exitProcess) {
return Analytics.trackError(err).then(() => process.exit(1));
}
process.exit(1);
} | [
"function",
"handleErrorMessage",
"(",
"msg",
",",
"err",
",",
"command",
",",
"exitProcess",
")",
"{",
"setErrorHandled",
"(",
")",
";",
"console",
".",
"error",
"(",
"`",
"${",
"msg",
"}",
"`",
")",
";",
"if",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
")",
";",
"if",
"(",
"isVerboseMode",
"(",
")",
")",
"{",
"console",
".",
"error",
"(",
"'Error stack:'",
")",
";",
"console",
".",
"error",
"(",
"err",
".",
"stack",
")",
";",
"}",
"else",
"{",
"console",
".",
"error",
"(",
"'For getting the error stack, use --verbose option'",
")",
";",
"}",
"}",
"console",
".",
"error",
"(",
")",
";",
"console",
".",
"error",
"(",
"'For getting help:'",
")",
";",
"console",
".",
"error",
"(",
"`",
"${",
"getCliFileName",
"(",
")",
"}",
"${",
"command",
"?",
"command",
":",
"'[command]'",
"}",
"`",
")",
";",
"if",
"(",
"!",
"err",
"&&",
"msg",
")",
"{",
"err",
"=",
"new",
"Error",
"(",
"msg",
")",
";",
"}",
"if",
"(",
"!",
"exitProcess",
")",
"{",
"return",
"Analytics",
".",
"trackError",
"(",
"err",
")",
".",
"then",
"(",
"(",
")",
"=>",
"process",
".",
"exit",
"(",
"1",
")",
")",
";",
"}",
"process",
".",
"exit",
"(",
"1",
")",
";",
"}"
] | Helper function that can be used to handle and print error messages occurred
during Yargs parsing and execution.
@param {String} msg The error message.
@param {Error} err The error that generated the problem.
@param {String} command The command that failed.
@param {Boolean} exitProcess Flag indicating it should invoke process.exit
after logging error messages.
@returns {Promise} The error tracking request promise | [
"Helper",
"function",
"that",
"can",
"be",
"used",
"to",
"handle",
"and",
"print",
"error",
"messages",
"occurred",
"during",
"Yargs",
"parsing",
"and",
"execution",
"."
] | 7cba4eb6b4846648471662e0265aacd5a7f18645 | https://github.com/back4app/antframework/blob/7cba4eb6b4846648471662e0265aacd5a7f18645/packages/ant-util-yargs/lib/yargsHelper.js#L44-L68 | train |
back4app/antframework | packages/ant-util-yargs/lib/yargsHelper.js | attachFailHandler | function attachFailHandler (yargs, handler) {
yargs.fail((msg, err, usage) => {
// If failure was handled previously, does nothing.
if (errorHandled) {
return;
}
handler(msg, err, usage);
if (errorHandled) {
// Workaround to avoid yargs from running the command.
// Since yargs has no mechanisms to any error handler
// alert the command execution needs to be stopped, and we can't
// exit the process right away due to possible asynchronous
// error handlers, we need a way to prevent the command to be
// ran, since we are handling the error asynchronously.
// Setting this inner flag will prevent yargs to run the command.
yargs._setHasOutput();
}
});
} | javascript | function attachFailHandler (yargs, handler) {
yargs.fail((msg, err, usage) => {
// If failure was handled previously, does nothing.
if (errorHandled) {
return;
}
handler(msg, err, usage);
if (errorHandled) {
// Workaround to avoid yargs from running the command.
// Since yargs has no mechanisms to any error handler
// alert the command execution needs to be stopped, and we can't
// exit the process right away due to possible asynchronous
// error handlers, we need a way to prevent the command to be
// ran, since we are handling the error asynchronously.
// Setting this inner flag will prevent yargs to run the command.
yargs._setHasOutput();
}
});
} | [
"function",
"attachFailHandler",
"(",
"yargs",
",",
"handler",
")",
"{",
"yargs",
".",
"fail",
"(",
"(",
"msg",
",",
"err",
",",
"usage",
")",
"=>",
"{",
"if",
"(",
"errorHandled",
")",
"{",
"return",
";",
"}",
"handler",
"(",
"msg",
",",
"err",
",",
"usage",
")",
";",
"if",
"(",
"errorHandled",
")",
"{",
"yargs",
".",
"_setHasOutput",
"(",
")",
";",
"}",
"}",
")",
";",
"}"
] | Attaches an error handler into the Yargs instance.
Guarantees the single error handling with the `errorHandled` flag,
which can be set with the `setErrorHandled` function.
@param {!Yargs} yargs The [Yargs]{@link https://github.com/yargs/yargs/blob/master/yargs.js}
instance.
@param {!Function} handler The error handler | [
"Attaches",
"an",
"error",
"handler",
"into",
"the",
"Yargs",
"instance",
"."
] | 7cba4eb6b4846648471662e0265aacd5a7f18645 | https://github.com/back4app/antframework/blob/7cba4eb6b4846648471662e0265aacd5a7f18645/packages/ant-util-yargs/lib/yargsHelper.js#L80-L98 | train |
back4app/antframework | packages/ant-util-yargs/lib/yargsHelper.js | executeCommand | async function executeCommand(command, asyncFn) {
try {
await asyncFn();
process.exit(0);
} catch (e) {
handleErrorMessage(e.message, e, command);
}
} | javascript | async function executeCommand(command, asyncFn) {
try {
await asyncFn();
process.exit(0);
} catch (e) {
handleErrorMessage(e.message, e, command);
}
} | [
"async",
"function",
"executeCommand",
"(",
"command",
",",
"asyncFn",
")",
"{",
"try",
"{",
"await",
"asyncFn",
"(",
")",
";",
"process",
".",
"exit",
"(",
"0",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"handleErrorMessage",
"(",
"e",
".",
"message",
",",
"e",
",",
"command",
")",
";",
"}",
"}"
] | Helper function encapsulates an asynchronous function to be executed
and handled on any errors thrown, providing a friendly error message
based on the command that this function represents.
In case of success, the process is exit with code 0.
In case of failure, the process is exit with code 1.
@param {!String} command The command about to be executed
@param {!Function} asyncFn The asynchronous function to be executed | [
"Helper",
"function",
"encapsulates",
"an",
"asynchronous",
"function",
"to",
"be",
"executed",
"and",
"handled",
"on",
"any",
"errors",
"thrown",
"providing",
"a",
"friendly",
"error",
"message",
"based",
"on",
"the",
"command",
"that",
"this",
"function",
"represents",
".",
"In",
"case",
"of",
"success",
"the",
"process",
"is",
"exit",
"with",
"code",
"0",
".",
"In",
"case",
"of",
"failure",
"the",
"process",
"is",
"exit",
"with",
"code",
"1",
"."
] | 7cba4eb6b4846648471662e0265aacd5a7f18645 | https://github.com/back4app/antframework/blob/7cba4eb6b4846648471662e0265aacd5a7f18645/packages/ant-util-yargs/lib/yargsHelper.js#L129-L136 | train |
back4app/antframework | plugins/ant-graphql/functions/subscribe.js | subscribe | async function subscribe (ant, field, directiveArgs, fieldArgs) {
if (ant && field && directiveArgs && directiveArgs.to) {
const antFunction = ant.functionController.getFunction(directiveArgs.to);
if (!antFunction) {
logger.error(new AntError(
`Could not find "${directiveArgs.to}" function`
));
return null;
}
try {
const currentValue = antFunction.run(fieldArgs);
if (currentValue instanceof Observable) {
return new AsyncIterableObserver(field.fieldName, currentValue);
}
return currentValue;
} catch (e) {
logger.error(new AntError(
`Could not run "${directiveArgs.to}" function`,
e
));
}
}
return null;
} | javascript | async function subscribe (ant, field, directiveArgs, fieldArgs) {
if (ant && field && directiveArgs && directiveArgs.to) {
const antFunction = ant.functionController.getFunction(directiveArgs.to);
if (!antFunction) {
logger.error(new AntError(
`Could not find "${directiveArgs.to}" function`
));
return null;
}
try {
const currentValue = antFunction.run(fieldArgs);
if (currentValue instanceof Observable) {
return new AsyncIterableObserver(field.fieldName, currentValue);
}
return currentValue;
} catch (e) {
logger.error(new AntError(
`Could not run "${directiveArgs.to}" function`,
e
));
}
}
return null;
} | [
"async",
"function",
"subscribe",
"(",
"ant",
",",
"field",
",",
"directiveArgs",
",",
"fieldArgs",
")",
"{",
"if",
"(",
"ant",
"&&",
"field",
"&&",
"directiveArgs",
"&&",
"directiveArgs",
".",
"to",
")",
"{",
"const",
"antFunction",
"=",
"ant",
".",
"functionController",
".",
"getFunction",
"(",
"directiveArgs",
".",
"to",
")",
";",
"if",
"(",
"!",
"antFunction",
")",
"{",
"logger",
".",
"error",
"(",
"new",
"AntError",
"(",
"`",
"${",
"directiveArgs",
".",
"to",
"}",
"`",
")",
")",
";",
"return",
"null",
";",
"}",
"try",
"{",
"const",
"currentValue",
"=",
"antFunction",
".",
"run",
"(",
"fieldArgs",
")",
";",
"if",
"(",
"currentValue",
"instanceof",
"Observable",
")",
"{",
"return",
"new",
"AsyncIterableObserver",
"(",
"field",
".",
"fieldName",
",",
"currentValue",
")",
";",
"}",
"return",
"currentValue",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"logger",
".",
"error",
"(",
"new",
"AntError",
"(",
"`",
"${",
"directiveArgs",
".",
"to",
"}",
"`",
",",
"e",
")",
")",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | This function resolves a GraphQL @subscribe directive value. | [
"This",
"function",
"resolves",
"a",
"GraphQL"
] | 7cba4eb6b4846648471662e0265aacd5a7f18645 | https://github.com/back4app/antframework/blob/7cba4eb6b4846648471662e0265aacd5a7f18645/plugins/ant-graphql/functions/subscribe.js#L12-L35 | train |
bosonic/bosonic | dist/bosonic-runtime.js | function(inEvent) {
var eventCopy = Object.create(null);
var p;
for (var i = 0; i < CLONE_PROPS.length; i++) {
p = CLONE_PROPS[i];
eventCopy[p] = inEvent[p] || CLONE_DEFAULTS[i];
// Work around SVGInstanceElement shadow tree
// Return the <use> element that is represented by the instance for Safari, Chrome, IE.
// This is the behavior implemented by Firefox.
if (HAS_SVG_INSTANCE && (p === 'target' || p === 'relatedTarget')) {
if (eventCopy[p] instanceof SVGElementInstance) {
eventCopy[p] = eventCopy[p].correspondingUseElement;
}
}
}
// keep the semantics of preventDefault
if (inEvent.preventDefault) {
eventCopy.preventDefault = function() {
inEvent.preventDefault();
};
}
return eventCopy;
} | javascript | function(inEvent) {
var eventCopy = Object.create(null);
var p;
for (var i = 0; i < CLONE_PROPS.length; i++) {
p = CLONE_PROPS[i];
eventCopy[p] = inEvent[p] || CLONE_DEFAULTS[i];
// Work around SVGInstanceElement shadow tree
// Return the <use> element that is represented by the instance for Safari, Chrome, IE.
// This is the behavior implemented by Firefox.
if (HAS_SVG_INSTANCE && (p === 'target' || p === 'relatedTarget')) {
if (eventCopy[p] instanceof SVGElementInstance) {
eventCopy[p] = eventCopy[p].correspondingUseElement;
}
}
}
// keep the semantics of preventDefault
if (inEvent.preventDefault) {
eventCopy.preventDefault = function() {
inEvent.preventDefault();
};
}
return eventCopy;
} | [
"function",
"(",
"inEvent",
")",
"{",
"var",
"eventCopy",
"=",
"Object",
".",
"create",
"(",
"null",
")",
";",
"var",
"p",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"CLONE_PROPS",
".",
"length",
";",
"i",
"++",
")",
"{",
"p",
"=",
"CLONE_PROPS",
"[",
"i",
"]",
";",
"eventCopy",
"[",
"p",
"]",
"=",
"inEvent",
"[",
"p",
"]",
"||",
"CLONE_DEFAULTS",
"[",
"i",
"]",
";",
"if",
"(",
"HAS_SVG_INSTANCE",
"&&",
"(",
"p",
"===",
"'target'",
"||",
"p",
"===",
"'relatedTarget'",
")",
")",
"{",
"if",
"(",
"eventCopy",
"[",
"p",
"]",
"instanceof",
"SVGElementInstance",
")",
"{",
"eventCopy",
"[",
"p",
"]",
"=",
"eventCopy",
"[",
"p",
"]",
".",
"correspondingUseElement",
";",
"}",
"}",
"}",
"if",
"(",
"inEvent",
".",
"preventDefault",
")",
"{",
"eventCopy",
".",
"preventDefault",
"=",
"function",
"(",
")",
"{",
"inEvent",
".",
"preventDefault",
"(",
")",
";",
"}",
";",
"}",
"return",
"eventCopy",
";",
"}"
] | Returns a snapshot of inEvent, with writable properties.
@param {Event} inEvent An event that contains properties to copy.
@return {Object} An object containing shallow copies of `inEvent`'s
properties. | [
"Returns",
"a",
"snapshot",
"of",
"inEvent",
"with",
"writable",
"properties",
"."
] | b2d1b892e79f1d9bf7a9762205ea187cf24b8acd | https://github.com/bosonic/bosonic/blob/b2d1b892e79f1d9bf7a9762205ea187cf24b8acd/dist/bosonic-runtime.js#L426-L450 | train |
|
bosonic/bosonic | dist/bosonic-runtime.js | function(inEvent) {
var lts = mouse.lastTouches;
var t = inEvent.changedTouches[0];
// only the primary finger will synth mouse events
if (this.isPrimaryTouch(t)) {
// remember x/y of last touch
var lt = { x: t.clientX, y: t.clientY };
lts.push(lt);
var fn = (function(lts, lt) {
var i = lts.indexOf(lt);
if (i > -1) {
lts.splice(i, 1);
}
}).bind(null, lts, lt);
setTimeout(fn, DEDUP_TIMEOUT);
}
} | javascript | function(inEvent) {
var lts = mouse.lastTouches;
var t = inEvent.changedTouches[0];
// only the primary finger will synth mouse events
if (this.isPrimaryTouch(t)) {
// remember x/y of last touch
var lt = { x: t.clientX, y: t.clientY };
lts.push(lt);
var fn = (function(lts, lt) {
var i = lts.indexOf(lt);
if (i > -1) {
lts.splice(i, 1);
}
}).bind(null, lts, lt);
setTimeout(fn, DEDUP_TIMEOUT);
}
} | [
"function",
"(",
"inEvent",
")",
"{",
"var",
"lts",
"=",
"mouse",
".",
"lastTouches",
";",
"var",
"t",
"=",
"inEvent",
".",
"changedTouches",
"[",
"0",
"]",
";",
"if",
"(",
"this",
".",
"isPrimaryTouch",
"(",
"t",
")",
")",
"{",
"var",
"lt",
"=",
"{",
"x",
":",
"t",
".",
"clientX",
",",
"y",
":",
"t",
".",
"clientY",
"}",
";",
"lts",
".",
"push",
"(",
"lt",
")",
";",
"var",
"fn",
"=",
"(",
"function",
"(",
"lts",
",",
"lt",
")",
"{",
"var",
"i",
"=",
"lts",
".",
"indexOf",
"(",
"lt",
")",
";",
"if",
"(",
"i",
">",
"-",
"1",
")",
"{",
"lts",
".",
"splice",
"(",
"i",
",",
"1",
")",
";",
"}",
"}",
")",
".",
"bind",
"(",
"null",
",",
"lts",
",",
"lt",
")",
";",
"setTimeout",
"(",
"fn",
",",
"DEDUP_TIMEOUT",
")",
";",
"}",
"}"
] | prevent synth mouse events from creating pointer events | [
"prevent",
"synth",
"mouse",
"events",
"from",
"creating",
"pointer",
"events"
] | b2d1b892e79f1d9bf7a9762205ea187cf24b8acd | https://github.com/bosonic/bosonic/blob/b2d1b892e79f1d9bf7a9762205ea187cf24b8acd/dist/bosonic-runtime.js#L1237-L1255 | train |
|
bosonic/bosonic | dist/bosonic-runtime.js | function(name, bool, node) {
node = node || this;
if (arguments.length == 1) {
bool = !node.hasAttribute(name) || node.getAttribute(name) == 'false';
}
bool ? node.setAttribute(name, 'true') : node.setAttribute(name, 'false');
} | javascript | function(name, bool, node) {
node = node || this;
if (arguments.length == 1) {
bool = !node.hasAttribute(name) || node.getAttribute(name) == 'false';
}
bool ? node.setAttribute(name, 'true') : node.setAttribute(name, 'false');
} | [
"function",
"(",
"name",
",",
"bool",
",",
"node",
")",
"{",
"node",
"=",
"node",
"||",
"this",
";",
"if",
"(",
"arguments",
".",
"length",
"==",
"1",
")",
"{",
"bool",
"=",
"!",
"node",
".",
"hasAttribute",
"(",
"name",
")",
"||",
"node",
".",
"getAttribute",
"(",
"name",
")",
"==",
"'false'",
";",
"}",
"bool",
"?",
"node",
".",
"setAttribute",
"(",
"name",
",",
"'true'",
")",
":",
"node",
".",
"setAttribute",
"(",
"name",
",",
"'false'",
")",
";",
"}"
] | for ARIA state properties | [
"for",
"ARIA",
"state",
"properties"
] | b2d1b892e79f1d9bf7a9762205ea187cf24b8acd | https://github.com/bosonic/bosonic/blob/b2d1b892e79f1d9bf7a9762205ea187cf24b8acd/dist/bosonic-runtime.js#L1781-L1787 | train |
|
back4app/antframework | plugins/ant-graphql/lib/util/schemaHelper.js | generateSchema | function generateSchema(ant, graphQL, _model) {
let model = [];
if (graphQL) {
for (const directive of graphQL.directiveController.directives) {
const directiveDefinition = graphQL.directiveController
.getDirectiveDefinition(directive);
if (directiveDefinition) {
model.push(directiveDefinition);
}
}
}
if (_model === undefined && graphQL) {
_model = graphQL.getModel();
}
if (_model) {
model.push(_model);
}
model = model.join('\n');
if (model.length) {
const astDocument = parse(model);
const schema = buildASTSchema(astDocument);
// This code will be better componentized and improved. Essentially it
// visits a GraphQL schema and look for each of its types, then each of
// the fields of the types that were found before and finally each of the
// directives of the fields that were found before. If it is a "mock"
// directive, a resolve function is attached to the field.
for (const typeName in schema._typeMap) {
const type = schema._typeMap[typeName];
for (const fieldName in type._fields) {
const field = type._fields[fieldName];
if (field.astNode && field.astNode.directives) {
for (const directive of field.astNode.directives) {
const directiveName = directive.name.value;
let directiveResolved = false;
if (graphQL) {
const antDirective = graphQL.directiveController
.getDirective(directiveName);
if (antDirective) {
directiveResolved = true;
const directiveArgs = {};
for (const arg of directive.arguments) {
directiveArgs[arg.name.value] = arg.value.value;
}
if (directiveName === 'subscribe') {
field.subscribe = (source, fieldArgs, context, info) => antDirective.resolver.run(
ant,
info,
directiveArgs,
fieldArgs
);
continue;
}
const currentResolver = field.resolve;
const directiveResolver = antDirective.resolver;
field.resolve = (_, fieldArgs) => {
// We can't provide Ant to any kind of AntFunction, due to
// serialization issues, so the class check is needed here
const resolvedValue = directiveResolver.run(
directiveResolver.constructor.name === AntFunction.name ? ant : undefined,
directiveArgs,
fieldArgs,
currentResolver ? currentResolver(_, fieldArgs) : undefined,
{ type, field, directive }
);
// The resolver should garantee the content resolved is compatible
// with the type specified in the GraphQL model.
// If the GraphQL model requires an Array and the resolver returns an
// Observable, for instance, the resolver needs to pipe its Observable
// into toArray before returning it; since there is no way
// to predict what the resolver implementation returns and treat it somehow.
if (resolvedValue instanceof Observable) {
return resolvedValue.toPromise();
}
return resolvedValue;
};
}
}
if (!directiveResolved) {
logger.error(`Could not find "${directiveName}" directive`);
}
}
}
}
}
const errors = validateSchema(schema);
if (errors && errors.length) {
logger.error(
'There were some errors when validating the GraphQL schema:'
);
errors.forEach(error => logger.error(error.toString()));
}
return schema;
} else {
return null;
}
} | javascript | function generateSchema(ant, graphQL, _model) {
let model = [];
if (graphQL) {
for (const directive of graphQL.directiveController.directives) {
const directiveDefinition = graphQL.directiveController
.getDirectiveDefinition(directive);
if (directiveDefinition) {
model.push(directiveDefinition);
}
}
}
if (_model === undefined && graphQL) {
_model = graphQL.getModel();
}
if (_model) {
model.push(_model);
}
model = model.join('\n');
if (model.length) {
const astDocument = parse(model);
const schema = buildASTSchema(astDocument);
// This code will be better componentized and improved. Essentially it
// visits a GraphQL schema and look for each of its types, then each of
// the fields of the types that were found before and finally each of the
// directives of the fields that were found before. If it is a "mock"
// directive, a resolve function is attached to the field.
for (const typeName in schema._typeMap) {
const type = schema._typeMap[typeName];
for (const fieldName in type._fields) {
const field = type._fields[fieldName];
if (field.astNode && field.astNode.directives) {
for (const directive of field.astNode.directives) {
const directiveName = directive.name.value;
let directiveResolved = false;
if (graphQL) {
const antDirective = graphQL.directiveController
.getDirective(directiveName);
if (antDirective) {
directiveResolved = true;
const directiveArgs = {};
for (const arg of directive.arguments) {
directiveArgs[arg.name.value] = arg.value.value;
}
if (directiveName === 'subscribe') {
field.subscribe = (source, fieldArgs, context, info) => antDirective.resolver.run(
ant,
info,
directiveArgs,
fieldArgs
);
continue;
}
const currentResolver = field.resolve;
const directiveResolver = antDirective.resolver;
field.resolve = (_, fieldArgs) => {
// We can't provide Ant to any kind of AntFunction, due to
// serialization issues, so the class check is needed here
const resolvedValue = directiveResolver.run(
directiveResolver.constructor.name === AntFunction.name ? ant : undefined,
directiveArgs,
fieldArgs,
currentResolver ? currentResolver(_, fieldArgs) : undefined,
{ type, field, directive }
);
// The resolver should garantee the content resolved is compatible
// with the type specified in the GraphQL model.
// If the GraphQL model requires an Array and the resolver returns an
// Observable, for instance, the resolver needs to pipe its Observable
// into toArray before returning it; since there is no way
// to predict what the resolver implementation returns and treat it somehow.
if (resolvedValue instanceof Observable) {
return resolvedValue.toPromise();
}
return resolvedValue;
};
}
}
if (!directiveResolved) {
logger.error(`Could not find "${directiveName}" directive`);
}
}
}
}
}
const errors = validateSchema(schema);
if (errors && errors.length) {
logger.error(
'There were some errors when validating the GraphQL schema:'
);
errors.forEach(error => logger.error(error.toString()));
}
return schema;
} else {
return null;
}
} | [
"function",
"generateSchema",
"(",
"ant",
",",
"graphQL",
",",
"_model",
")",
"{",
"let",
"model",
"=",
"[",
"]",
";",
"if",
"(",
"graphQL",
")",
"{",
"for",
"(",
"const",
"directive",
"of",
"graphQL",
".",
"directiveController",
".",
"directives",
")",
"{",
"const",
"directiveDefinition",
"=",
"graphQL",
".",
"directiveController",
".",
"getDirectiveDefinition",
"(",
"directive",
")",
";",
"if",
"(",
"directiveDefinition",
")",
"{",
"model",
".",
"push",
"(",
"directiveDefinition",
")",
";",
"}",
"}",
"}",
"if",
"(",
"_model",
"===",
"undefined",
"&&",
"graphQL",
")",
"{",
"_model",
"=",
"graphQL",
".",
"getModel",
"(",
")",
";",
"}",
"if",
"(",
"_model",
")",
"{",
"model",
".",
"push",
"(",
"_model",
")",
";",
"}",
"model",
"=",
"model",
".",
"join",
"(",
"'\\n'",
")",
";",
"\\n",
"}"
] | Helper function that can be used to generate a GraphQL schema from Ant
Framework's config.
@param {Ant} ant The {@link Ant} framework instance.
@param {GraphQL} graphQL The {@link GraphQL} plugin instance.
@param {String} _model An optional pre-loaded GraphQL model to be used
instead of requiring the GraphQL plugin to load a new one.
@return {Object} The generated [GraphQLSchema]{@link https://github.com/graphql/graphql-js/blob/f8438f73baa64d8047fd766a8f38e169198ff141/src/type/schema.js#L79}. | [
"Helper",
"function",
"that",
"can",
"be",
"used",
"to",
"generate",
"a",
"GraphQL",
"schema",
"from",
"Ant",
"Framework",
"s",
"config",
"."
] | 7cba4eb6b4846648471662e0265aacd5a7f18645 | https://github.com/back4app/antframework/blob/7cba4eb6b4846648471662e0265aacd5a7f18645/plugins/ant-graphql/lib/util/schemaHelper.js#L21-L127 | train |
Adeptive/Loxone-NodeJS | loxone-api.js | function(url, callback) {
url = getBaseUrl() + url;
http.get(url, function(response) {
var output = "";
response.on('data', function (chunk) {
output += chunk;
});
response.on('end', function() {
output = JSON.parse(output);
if (debug) {console.log(output);}
if (output == undefined) {
output = {
LL: {
Code: 500,
value: undefined,
message: 'Unable to get response from Loxone Miniserver'
}
}
}
// return our current value
callback(output);
});
}).on('error', function(e) {
console.log("Got error: " + e.message);
callback({
LL: {
Code: 500,
value: undefined,
message: e.message
}
});
});
} | javascript | function(url, callback) {
url = getBaseUrl() + url;
http.get(url, function(response) {
var output = "";
response.on('data', function (chunk) {
output += chunk;
});
response.on('end', function() {
output = JSON.parse(output);
if (debug) {console.log(output);}
if (output == undefined) {
output = {
LL: {
Code: 500,
value: undefined,
message: 'Unable to get response from Loxone Miniserver'
}
}
}
// return our current value
callback(output);
});
}).on('error', function(e) {
console.log("Got error: " + e.message);
callback({
LL: {
Code: 500,
value: undefined,
message: e.message
}
});
});
} | [
"function",
"(",
"url",
",",
"callback",
")",
"{",
"url",
"=",
"getBaseUrl",
"(",
")",
"+",
"url",
";",
"http",
".",
"get",
"(",
"url",
",",
"function",
"(",
"response",
")",
"{",
"var",
"output",
"=",
"\"\"",
";",
"response",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"chunk",
")",
"{",
"output",
"+=",
"chunk",
";",
"}",
")",
";",
"response",
".",
"on",
"(",
"'end'",
",",
"function",
"(",
")",
"{",
"output",
"=",
"JSON",
".",
"parse",
"(",
"output",
")",
";",
"if",
"(",
"debug",
")",
"{",
"console",
".",
"log",
"(",
"output",
")",
";",
"}",
"if",
"(",
"output",
"==",
"undefined",
")",
"{",
"output",
"=",
"{",
"LL",
":",
"{",
"Code",
":",
"500",
",",
"value",
":",
"undefined",
",",
"message",
":",
"'Unable to get response from Loxone Miniserver'",
"}",
"}",
"}",
"callback",
"(",
"output",
")",
";",
"}",
")",
";",
"}",
")",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"e",
")",
"{",
"console",
".",
"log",
"(",
"\"Got error: \"",
"+",
"e",
".",
"message",
")",
";",
"callback",
"(",
"{",
"LL",
":",
"{",
"Code",
":",
"500",
",",
"value",
":",
"undefined",
",",
"message",
":",
"e",
".",
"message",
"}",
"}",
")",
";",
"}",
")",
";",
"}"
] | UTILITY METHODS +++++++++++++++++++++++++++++ | [
"UTILITY",
"METHODS",
"+++++++++++++++++++++++++++++"
] | 8e047dbace33341dc07da4f9a1c304ae0dc85c7f | https://github.com/Adeptive/Loxone-NodeJS/blob/8e047dbace33341dc07da4f9a1c304ae0dc85c7f/loxone-api.js#L77-L113 | train |
|
mikolalysenko/ao-mesher | mesh.js | facetAO | function facetAO(a00, a01, a02,
a10, a12,
a20, a21, a22) {
var s00 = (a00&OPAQUE_BIT) ? 1 : 0
, s01 = (a01&OPAQUE_BIT) ? 1 : 0
, s02 = (a02&OPAQUE_BIT) ? 1 : 0
, s10 = (a10&OPAQUE_BIT) ? 1 : 0
, s12 = (a12&OPAQUE_BIT) ? 1 : 0
, s20 = (a20&OPAQUE_BIT) ? 1 : 0
, s21 = (a21&OPAQUE_BIT) ? 1 : 0
, s22 = (a22&OPAQUE_BIT) ? 1 : 0
return (vertexAO(s10, s01, s00)<< AO_SHIFT) +
(vertexAO(s01, s12, s02)<<(AO_SHIFT+AO_BITS)) +
(vertexAO(s12, s21, s22)<<(AO_SHIFT+2*AO_BITS)) +
(vertexAO(s21, s10, s20)<<(AO_SHIFT+3*AO_BITS))
} | javascript | function facetAO(a00, a01, a02,
a10, a12,
a20, a21, a22) {
var s00 = (a00&OPAQUE_BIT) ? 1 : 0
, s01 = (a01&OPAQUE_BIT) ? 1 : 0
, s02 = (a02&OPAQUE_BIT) ? 1 : 0
, s10 = (a10&OPAQUE_BIT) ? 1 : 0
, s12 = (a12&OPAQUE_BIT) ? 1 : 0
, s20 = (a20&OPAQUE_BIT) ? 1 : 0
, s21 = (a21&OPAQUE_BIT) ? 1 : 0
, s22 = (a22&OPAQUE_BIT) ? 1 : 0
return (vertexAO(s10, s01, s00)<< AO_SHIFT) +
(vertexAO(s01, s12, s02)<<(AO_SHIFT+AO_BITS)) +
(vertexAO(s12, s21, s22)<<(AO_SHIFT+2*AO_BITS)) +
(vertexAO(s21, s10, s20)<<(AO_SHIFT+3*AO_BITS))
} | [
"function",
"facetAO",
"(",
"a00",
",",
"a01",
",",
"a02",
",",
"a10",
",",
"a12",
",",
"a20",
",",
"a21",
",",
"a22",
")",
"{",
"var",
"s00",
"=",
"(",
"a00",
"&",
"OPAQUE_BIT",
")",
"?",
"1",
":",
"0",
",",
"s01",
"=",
"(",
"a01",
"&",
"OPAQUE_BIT",
")",
"?",
"1",
":",
"0",
",",
"s02",
"=",
"(",
"a02",
"&",
"OPAQUE_BIT",
")",
"?",
"1",
":",
"0",
",",
"s10",
"=",
"(",
"a10",
"&",
"OPAQUE_BIT",
")",
"?",
"1",
":",
"0",
",",
"s12",
"=",
"(",
"a12",
"&",
"OPAQUE_BIT",
")",
"?",
"1",
":",
"0",
",",
"s20",
"=",
"(",
"a20",
"&",
"OPAQUE_BIT",
")",
"?",
"1",
":",
"0",
",",
"s21",
"=",
"(",
"a21",
"&",
"OPAQUE_BIT",
")",
"?",
"1",
":",
"0",
",",
"s22",
"=",
"(",
"a22",
"&",
"OPAQUE_BIT",
")",
"?",
"1",
":",
"0",
"return",
"(",
"vertexAO",
"(",
"s10",
",",
"s01",
",",
"s00",
")",
"<<",
"AO_SHIFT",
")",
"+",
"(",
"vertexAO",
"(",
"s01",
",",
"s12",
",",
"s02",
")",
"<<",
"(",
"AO_SHIFT",
"+",
"AO_BITS",
")",
")",
"+",
"(",
"vertexAO",
"(",
"s12",
",",
"s21",
",",
"s22",
")",
"<<",
"(",
"AO_SHIFT",
"+",
"2",
"*",
"AO_BITS",
")",
")",
"+",
"(",
"vertexAO",
"(",
"s21",
",",
"s10",
",",
"s20",
")",
"<<",
"(",
"AO_SHIFT",
"+",
"3",
"*",
"AO_BITS",
")",
")",
"}"
] | Calculates the ambient occlusion bit mask for a facet | [
"Calculates",
"the",
"ambient",
"occlusion",
"bit",
"mask",
"for",
"a",
"facet"
] | d0a22c2d20fae6e3f64ec64bb8a7f6e35745aeae | https://github.com/mikolalysenko/ao-mesher/blob/d0a22c2d20fae6e3f64ec64bb8a7f6e35745aeae/mesh.js#L48-L63 | train |
mikolalysenko/ao-mesher | mesh.js | generateSurfaceVoxel | function generateSurfaceVoxel(
v000, v001, v002,
v010, v011, v012,
v020, v021, v022,
v100, v101, v102,
v110, v111, v112,
v120, v121, v122) {
var t0 = !(v011 & OPAQUE_BIT)
, t1 = !(v111 & OPAQUE_BIT)
if(v111 && (!v011 || (t0 && !t1))) {
return v111 | FLIP_BIT | facetAO(v000, v001, v002,
v010, v012,
v020, v021, v022)
} else if(v011 && (!v111 || (t1 && !t0)) ) {
return v011 | facetAO(v100, v101, v102,
v110, v112,
v120, v121, v122)
}
} | javascript | function generateSurfaceVoxel(
v000, v001, v002,
v010, v011, v012,
v020, v021, v022,
v100, v101, v102,
v110, v111, v112,
v120, v121, v122) {
var t0 = !(v011 & OPAQUE_BIT)
, t1 = !(v111 & OPAQUE_BIT)
if(v111 && (!v011 || (t0 && !t1))) {
return v111 | FLIP_BIT | facetAO(v000, v001, v002,
v010, v012,
v020, v021, v022)
} else if(v011 && (!v111 || (t1 && !t0)) ) {
return v011 | facetAO(v100, v101, v102,
v110, v112,
v120, v121, v122)
}
} | [
"function",
"generateSurfaceVoxel",
"(",
"v000",
",",
"v001",
",",
"v002",
",",
"v010",
",",
"v011",
",",
"v012",
",",
"v020",
",",
"v021",
",",
"v022",
",",
"v100",
",",
"v101",
",",
"v102",
",",
"v110",
",",
"v111",
",",
"v112",
",",
"v120",
",",
"v121",
",",
"v122",
")",
"{",
"var",
"t0",
"=",
"!",
"(",
"v011",
"&",
"OPAQUE_BIT",
")",
",",
"t1",
"=",
"!",
"(",
"v111",
"&",
"OPAQUE_BIT",
")",
"if",
"(",
"v111",
"&&",
"(",
"!",
"v011",
"||",
"(",
"t0",
"&&",
"!",
"t1",
")",
")",
")",
"{",
"return",
"v111",
"|",
"FLIP_BIT",
"|",
"facetAO",
"(",
"v000",
",",
"v001",
",",
"v002",
",",
"v010",
",",
"v012",
",",
"v020",
",",
"v021",
",",
"v022",
")",
"}",
"else",
"if",
"(",
"v011",
"&&",
"(",
"!",
"v111",
"||",
"(",
"t1",
"&&",
"!",
"t0",
")",
")",
")",
"{",
"return",
"v011",
"|",
"facetAO",
"(",
"v100",
",",
"v101",
",",
"v102",
",",
"v110",
",",
"v112",
",",
"v120",
",",
"v121",
",",
"v122",
")",
"}",
"}"
] | Generates a surface voxel, complete with ambient occlusion type | [
"Generates",
"a",
"surface",
"voxel",
"complete",
"with",
"ambient",
"occlusion",
"type"
] | d0a22c2d20fae6e3f64ec64bb8a7f6e35745aeae | https://github.com/mikolalysenko/ao-mesher/blob/d0a22c2d20fae6e3f64ec64bb8a7f6e35745aeae/mesh.js#L66-L84 | train |
soplakanets/node-forecastio | index.js | ForecastIoAPIError | function ForecastIoAPIError(url, statusCode, body) {
this.response = {
statusCode: statusCode,
body: body
};
this.message = this._formatErrorMessage(body);
this.name = "ForecastIoAPIError";
Error.call(this);
Error.captureStackTrace(this, arguments.callee);
this.request = "GET " + url;
} | javascript | function ForecastIoAPIError(url, statusCode, body) {
this.response = {
statusCode: statusCode,
body: body
};
this.message = this._formatErrorMessage(body);
this.name = "ForecastIoAPIError";
Error.call(this);
Error.captureStackTrace(this, arguments.callee);
this.request = "GET " + url;
} | [
"function",
"ForecastIoAPIError",
"(",
"url",
",",
"statusCode",
",",
"body",
")",
"{",
"this",
".",
"response",
"=",
"{",
"statusCode",
":",
"statusCode",
",",
"body",
":",
"body",
"}",
";",
"this",
".",
"message",
"=",
"this",
".",
"_formatErrorMessage",
"(",
"body",
")",
";",
"this",
".",
"name",
"=",
"\"ForecastIoAPIError\"",
";",
"Error",
".",
"call",
"(",
"this",
")",
";",
"Error",
".",
"captureStackTrace",
"(",
"this",
",",
"arguments",
".",
"callee",
")",
";",
"this",
".",
"request",
"=",
"\"GET \"",
"+",
"url",
";",
"}"
] | Represents API errors. | [
"Represents",
"API",
"errors",
"."
] | 7082666ef19c358b3adcdf667aba34b5394d69e8 | https://github.com/soplakanets/node-forecastio/blob/7082666ef19c358b3adcdf667aba34b5394d69e8/index.js#L85-L95 | train |
EdwonLim/node-sass-china | lib/extensions.js | getRuntimeInfo | function getRuntimeInfo() {
var execPath = fs.realpathSync(process.execPath); // resolve symbolic link
var runtime = execPath
.split(/[\\/]+/).pop()
.split('.').shift();
runtime = runtime === 'nodejs' ? 'node' : runtime;
return {
name: runtime,
execPath: execPath
};
} | javascript | function getRuntimeInfo() {
var execPath = fs.realpathSync(process.execPath); // resolve symbolic link
var runtime = execPath
.split(/[\\/]+/).pop()
.split('.').shift();
runtime = runtime === 'nodejs' ? 'node' : runtime;
return {
name: runtime,
execPath: execPath
};
} | [
"function",
"getRuntimeInfo",
"(",
")",
"{",
"var",
"execPath",
"=",
"fs",
".",
"realpathSync",
"(",
"process",
".",
"execPath",
")",
";",
"var",
"runtime",
"=",
"execPath",
".",
"split",
"(",
"/",
"[\\\\/]+",
"/",
")",
".",
"pop",
"(",
")",
".",
"split",
"(",
"'.'",
")",
".",
"shift",
"(",
")",
";",
"runtime",
"=",
"runtime",
"===",
"'nodejs'",
"?",
"'node'",
":",
"runtime",
";",
"return",
"{",
"name",
":",
"runtime",
",",
"execPath",
":",
"execPath",
"}",
";",
"}"
] | Get Runtime Info
@api private | [
"Get",
"Runtime",
"Info"
] | 96c13a84e4d68f20d9c5388ad58e2750c2ce786f | https://github.com/EdwonLim/node-sass-china/blob/96c13a84e4d68f20d9c5388ad58e2750c2ce786f/lib/extensions.js#L34-L47 | train |
EdwonLim/node-sass-china | lib/extensions.js | getBinaryUrl | function getBinaryUrl() {
var site = flags['--sass-binary-site'] ||
process.env.SASS_BINARY_SITE ||
pkg.nodeSassConfig.binarySite;
return [site, 'v' + pkg.version, sass.binaryName].join('/');
} | javascript | function getBinaryUrl() {
var site = flags['--sass-binary-site'] ||
process.env.SASS_BINARY_SITE ||
pkg.nodeSassConfig.binarySite;
return [site, 'v' + pkg.version, sass.binaryName].join('/');
} | [
"function",
"getBinaryUrl",
"(",
")",
"{",
"var",
"site",
"=",
"flags",
"[",
"'--sass-binary-site'",
"]",
"||",
"process",
".",
"env",
".",
"SASS_BINARY_SITE",
"||",
"pkg",
".",
"nodeSassConfig",
".",
"binarySite",
";",
"return",
"[",
"site",
",",
"'v'",
"+",
"pkg",
".",
"version",
",",
"sass",
".",
"binaryName",
"]",
".",
"join",
"(",
"'/'",
")",
";",
"}"
] | Determine the URL to fetch binary file from.
By default feth from the node-sass distribution
site on GitHub.
The default URL can be overriden using
the environment variable SASS_BINARY_SITE
or a command line option --sass-binary-site:
node scripts/install.js --sass-binary-site http://example.com/
The URL should to the mirror of the repository
laid out as follows:
SASS_BINARY_SITE/
v3.0.0
v3.0.0/freebsd-x64-14_binding.node
....
v3.0.0
v3.0.0/freebsd-ia32-11_binding.node
v3.0.0/freebsd-x64-42_binding.node
... etc. for all supported versions and platforms
@api private | [
"Determine",
"the",
"URL",
"to",
"fetch",
"binary",
"file",
"from",
".",
"By",
"default",
"feth",
"from",
"the",
"node",
"-",
"sass",
"distribution",
"site",
"on",
"GitHub",
"."
] | 96c13a84e4d68f20d9c5388ad58e2750c2ce786f | https://github.com/EdwonLim/node-sass-china/blob/96c13a84e4d68f20d9c5388ad58e2750c2ce786f/lib/extensions.js#L104-L109 | train |
tntvis/tnt.genome | src/genome.js | function (where) {
if (where !== undefined) {
if (where.gene !== undefined) {
get_gene(where);
return;
} else {
if (where.species === undefined) {
where.species = genome_browser.species();
} else {
genome_browser.species(where.species);
}
if (where.chr === undefined) {
where.chr = genome_browser.chr();
} else {
genome_browser.chr(where.chr);
}
if (where.from === undefined) {
where.from = genome_browser.from();
} else {
genome_browser.from(where.from);
}
if (where.to === undefined) {
where.to = genome_browser.to();
} else {
genome_browser.to(where.to);
}
}
} else { // "where" is undef so look for gene or loc
if (genome_browser.gene() !== undefined) {
get_gene({ species : genome_browser.species(),
gene : genome_browser.gene()
});
return;
} else {
where = {};
where.species = genome_browser.species();
where.chr = genome_browser.chr();
where.from = genome_browser.from();
where.to = genome_browser.to();
}
}
// Min is 0 by default or use the provided promise
conf.min_coord
.then (function (min) {
genome_browser.min(min);
if (!conf.max_coord) {
var url = ensembl_rest.url()
.endpoint("info/assembly/:species/:region_name")
.parameters({
species: where.species,
region_name: where.chr
});
conf.max_coord = ensembl_rest.call (url)
.then (function (resp) {
return resp.body.length;
});
}
return conf.max_coord;
})
.then (function (max) {
genome_browser.max(max);
genome_browser._start();
});
} | javascript | function (where) {
if (where !== undefined) {
if (where.gene !== undefined) {
get_gene(where);
return;
} else {
if (where.species === undefined) {
where.species = genome_browser.species();
} else {
genome_browser.species(where.species);
}
if (where.chr === undefined) {
where.chr = genome_browser.chr();
} else {
genome_browser.chr(where.chr);
}
if (where.from === undefined) {
where.from = genome_browser.from();
} else {
genome_browser.from(where.from);
}
if (where.to === undefined) {
where.to = genome_browser.to();
} else {
genome_browser.to(where.to);
}
}
} else { // "where" is undef so look for gene or loc
if (genome_browser.gene() !== undefined) {
get_gene({ species : genome_browser.species(),
gene : genome_browser.gene()
});
return;
} else {
where = {};
where.species = genome_browser.species();
where.chr = genome_browser.chr();
where.from = genome_browser.from();
where.to = genome_browser.to();
}
}
// Min is 0 by default or use the provided promise
conf.min_coord
.then (function (min) {
genome_browser.min(min);
if (!conf.max_coord) {
var url = ensembl_rest.url()
.endpoint("info/assembly/:species/:region_name")
.parameters({
species: where.species,
region_name: where.chr
});
conf.max_coord = ensembl_rest.call (url)
.then (function (resp) {
return resp.body.length;
});
}
return conf.max_coord;
})
.then (function (max) {
genome_browser.max(max);
genome_browser._start();
});
} | [
"function",
"(",
"where",
")",
"{",
"if",
"(",
"where",
"!==",
"undefined",
")",
"{",
"if",
"(",
"where",
".",
"gene",
"!==",
"undefined",
")",
"{",
"get_gene",
"(",
"where",
")",
";",
"return",
";",
"}",
"else",
"{",
"if",
"(",
"where",
".",
"species",
"===",
"undefined",
")",
"{",
"where",
".",
"species",
"=",
"genome_browser",
".",
"species",
"(",
")",
";",
"}",
"else",
"{",
"genome_browser",
".",
"species",
"(",
"where",
".",
"species",
")",
";",
"}",
"if",
"(",
"where",
".",
"chr",
"===",
"undefined",
")",
"{",
"where",
".",
"chr",
"=",
"genome_browser",
".",
"chr",
"(",
")",
";",
"}",
"else",
"{",
"genome_browser",
".",
"chr",
"(",
"where",
".",
"chr",
")",
";",
"}",
"if",
"(",
"where",
".",
"from",
"===",
"undefined",
")",
"{",
"where",
".",
"from",
"=",
"genome_browser",
".",
"from",
"(",
")",
";",
"}",
"else",
"{",
"genome_browser",
".",
"from",
"(",
"where",
".",
"from",
")",
";",
"}",
"if",
"(",
"where",
".",
"to",
"===",
"undefined",
")",
"{",
"where",
".",
"to",
"=",
"genome_browser",
".",
"to",
"(",
")",
";",
"}",
"else",
"{",
"genome_browser",
".",
"to",
"(",
"where",
".",
"to",
")",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"genome_browser",
".",
"gene",
"(",
")",
"!==",
"undefined",
")",
"{",
"get_gene",
"(",
"{",
"species",
":",
"genome_browser",
".",
"species",
"(",
")",
",",
"gene",
":",
"genome_browser",
".",
"gene",
"(",
")",
"}",
")",
";",
"return",
";",
"}",
"else",
"{",
"where",
"=",
"{",
"}",
";",
"where",
".",
"species",
"=",
"genome_browser",
".",
"species",
"(",
")",
";",
"where",
".",
"chr",
"=",
"genome_browser",
".",
"chr",
"(",
")",
";",
"where",
".",
"from",
"=",
"genome_browser",
".",
"from",
"(",
")",
";",
"where",
".",
"to",
"=",
"genome_browser",
".",
"to",
"(",
")",
";",
"}",
"}",
"conf",
".",
"min_coord",
".",
"then",
"(",
"function",
"(",
"min",
")",
"{",
"genome_browser",
".",
"min",
"(",
"min",
")",
";",
"if",
"(",
"!",
"conf",
".",
"max_coord",
")",
"{",
"var",
"url",
"=",
"ensembl_rest",
".",
"url",
"(",
")",
".",
"endpoint",
"(",
"\"info/assembly/:species/:region_name\"",
")",
".",
"parameters",
"(",
"{",
"species",
":",
"where",
".",
"species",
",",
"region_name",
":",
"where",
".",
"chr",
"}",
")",
";",
"conf",
".",
"max_coord",
"=",
"ensembl_rest",
".",
"call",
"(",
"url",
")",
".",
"then",
"(",
"function",
"(",
"resp",
")",
"{",
"return",
"resp",
".",
"body",
".",
"length",
";",
"}",
")",
";",
"}",
"return",
"conf",
".",
"max_coord",
";",
"}",
")",
".",
"then",
"(",
"function",
"(",
"max",
")",
"{",
"genome_browser",
".",
"max",
"(",
"max",
")",
";",
"genome_browser",
".",
"_start",
"(",
")",
";",
"}",
")",
";",
"}"
] | We hijack parent's start method | [
"We",
"hijack",
"parent",
"s",
"start",
"method"
] | 3fe11fa8b6145f181bb4baa4607a22fb360c0892 | https://github.com/tntvis/tnt.genome/blob/3fe11fa8b6145f181bb4baa4607a22fb360c0892/src/genome.js#L74-L140 | train |
|
alphagov/govuk_frontend_toolkit_npm | javascripts/govuk/details.polyfill.js | function (node, type, callback) {
if (node.addEventListener) {
node.addEventListener(type, function (e) {
callback(e, e.target)
}, false)
} else if (node.attachEvent) {
node.attachEvent('on' + type, function (e) {
callback(e, e.srcElement)
})
}
} | javascript | function (node, type, callback) {
if (node.addEventListener) {
node.addEventListener(type, function (e) {
callback(e, e.target)
}, false)
} else if (node.attachEvent) {
node.attachEvent('on' + type, function (e) {
callback(e, e.srcElement)
})
}
} | [
"function",
"(",
"node",
",",
"type",
",",
"callback",
")",
"{",
"if",
"(",
"node",
".",
"addEventListener",
")",
"{",
"node",
".",
"addEventListener",
"(",
"type",
",",
"function",
"(",
"e",
")",
"{",
"callback",
"(",
"e",
",",
"e",
".",
"target",
")",
"}",
",",
"false",
")",
"}",
"else",
"if",
"(",
"node",
".",
"attachEvent",
")",
"{",
"node",
".",
"attachEvent",
"(",
"'on'",
"+",
"type",
",",
"function",
"(",
"e",
")",
"{",
"callback",
"(",
"e",
",",
"e",
".",
"srcElement",
")",
"}",
")",
"}",
"}"
] | Add event construct for modern browsers or IE which fires the callback with a pre-converted target reference | [
"Add",
"event",
"construct",
"for",
"modern",
"browsers",
"or",
"IE",
"which",
"fires",
"the",
"callback",
"with",
"a",
"pre",
"-",
"converted",
"target",
"reference"
] | 761632e5bed24c5106f4bdbd8cc99688d8ca616d | https://github.com/alphagov/govuk_frontend_toolkit_npm/blob/761632e5bed24c5106f4bdbd8cc99688d8ca616d/javascripts/govuk/details.polyfill.js#L25-L35 | train |
|
alphagov/govuk_frontend_toolkit_npm | javascripts/govuk/details.polyfill.js | function (node, callback) {
GOVUK.details.addEvent(node, 'keypress', function (e, target) {
// When the key gets pressed - check if it is enter or space
if (GOVUK.details.charCode(e) === GOVUK.details.KEY_ENTER || GOVUK.details.charCode(e) === GOVUK.details.KEY_SPACE) {
if (target.nodeName.toLowerCase() === 'summary') {
// Prevent space from scrolling the page
// and enter from submitting a form
GOVUK.details.preventDefault(e)
// Click to let the click event do all the necessary action
if (target.click) {
target.click()
} else {
// except Safari 5.1 and under don't support .click() here
callback(e, target)
}
}
}
})
// Prevent keyup to prevent clicking twice in Firefox when using space key
GOVUK.details.addEvent(node, 'keyup', function (e, target) {
if (GOVUK.details.charCode(e) === GOVUK.details.KEY_SPACE) {
if (target.nodeName === 'SUMMARY') {
GOVUK.details.preventDefault(e)
}
}
})
GOVUK.details.addEvent(node, 'click', function (e, target) {
callback(e, target)
})
} | javascript | function (node, callback) {
GOVUK.details.addEvent(node, 'keypress', function (e, target) {
// When the key gets pressed - check if it is enter or space
if (GOVUK.details.charCode(e) === GOVUK.details.KEY_ENTER || GOVUK.details.charCode(e) === GOVUK.details.KEY_SPACE) {
if (target.nodeName.toLowerCase() === 'summary') {
// Prevent space from scrolling the page
// and enter from submitting a form
GOVUK.details.preventDefault(e)
// Click to let the click event do all the necessary action
if (target.click) {
target.click()
} else {
// except Safari 5.1 and under don't support .click() here
callback(e, target)
}
}
}
})
// Prevent keyup to prevent clicking twice in Firefox when using space key
GOVUK.details.addEvent(node, 'keyup', function (e, target) {
if (GOVUK.details.charCode(e) === GOVUK.details.KEY_SPACE) {
if (target.nodeName === 'SUMMARY') {
GOVUK.details.preventDefault(e)
}
}
})
GOVUK.details.addEvent(node, 'click', function (e, target) {
callback(e, target)
})
} | [
"function",
"(",
"node",
",",
"callback",
")",
"{",
"GOVUK",
".",
"details",
".",
"addEvent",
"(",
"node",
",",
"'keypress'",
",",
"function",
"(",
"e",
",",
"target",
")",
"{",
"if",
"(",
"GOVUK",
".",
"details",
".",
"charCode",
"(",
"e",
")",
"===",
"GOVUK",
".",
"details",
".",
"KEY_ENTER",
"||",
"GOVUK",
".",
"details",
".",
"charCode",
"(",
"e",
")",
"===",
"GOVUK",
".",
"details",
".",
"KEY_SPACE",
")",
"{",
"if",
"(",
"target",
".",
"nodeName",
".",
"toLowerCase",
"(",
")",
"===",
"'summary'",
")",
"{",
"GOVUK",
".",
"details",
".",
"preventDefault",
"(",
"e",
")",
"if",
"(",
"target",
".",
"click",
")",
"{",
"target",
".",
"click",
"(",
")",
"}",
"else",
"{",
"callback",
"(",
"e",
",",
"target",
")",
"}",
"}",
"}",
"}",
")",
"GOVUK",
".",
"details",
".",
"addEvent",
"(",
"node",
",",
"'keyup'",
",",
"function",
"(",
"e",
",",
"target",
")",
"{",
"if",
"(",
"GOVUK",
".",
"details",
".",
"charCode",
"(",
"e",
")",
"===",
"GOVUK",
".",
"details",
".",
"KEY_SPACE",
")",
"{",
"if",
"(",
"target",
".",
"nodeName",
"===",
"'SUMMARY'",
")",
"{",
"GOVUK",
".",
"details",
".",
"preventDefault",
"(",
"e",
")",
"}",
"}",
"}",
")",
"GOVUK",
".",
"details",
".",
"addEvent",
"(",
"node",
",",
"'click'",
",",
"function",
"(",
"e",
",",
"target",
")",
"{",
"callback",
"(",
"e",
",",
"target",
")",
"}",
")",
"}"
] | Handle cross-modal click events | [
"Handle",
"cross",
"-",
"modal",
"click",
"events"
] | 761632e5bed24c5106f4bdbd8cc99688d8ca616d | https://github.com/alphagov/govuk_frontend_toolkit_npm/blob/761632e5bed24c5106f4bdbd8cc99688d8ca616d/javascripts/govuk/details.polyfill.js#L62-L93 | train |
|
alphagov/govuk_frontend_toolkit_npm | javascripts/govuk/details.polyfill.js | function (node, match) {
do {
if (!node || node.nodeName.toLowerCase() === match) {
break
}
node = node.parentNode
} while (node)
return node
} | javascript | function (node, match) {
do {
if (!node || node.nodeName.toLowerCase() === match) {
break
}
node = node.parentNode
} while (node)
return node
} | [
"function",
"(",
"node",
",",
"match",
")",
"{",
"do",
"{",
"if",
"(",
"!",
"node",
"||",
"node",
".",
"nodeName",
".",
"toLowerCase",
"(",
")",
"===",
"match",
")",
"{",
"break",
"}",
"node",
"=",
"node",
".",
"parentNode",
"}",
"while",
"(",
"node",
")",
"return",
"node",
"}"
] | Get the nearest ancestor element of a node that matches a given tag name | [
"Get",
"the",
"nearest",
"ancestor",
"element",
"of",
"a",
"node",
"that",
"matches",
"a",
"given",
"tag",
"name"
] | 761632e5bed24c5106f4bdbd8cc99688d8ca616d | https://github.com/alphagov/govuk_frontend_toolkit_npm/blob/761632e5bed24c5106f4bdbd8cc99688d8ca616d/javascripts/govuk/details.polyfill.js#L96-L105 | train |
|
alphagov/govuk_frontend_toolkit_npm | javascripts/govuk/details.polyfill.js | function (summary) {
var expanded = summary.__details.__summary.getAttribute('aria-expanded') === 'true'
var hidden = summary.__details.__content.getAttribute('aria-hidden') === 'true'
summary.__details.__summary.setAttribute('aria-expanded', (expanded ? 'false' : 'true'))
summary.__details.__content.setAttribute('aria-hidden', (hidden ? 'false' : 'true'))
if (!GOVUK.details.NATIVE_DETAILS) {
summary.__details.__content.style.display = (expanded ? 'none' : '')
var hasOpenAttr = summary.__details.getAttribute('open') !== null
if (!hasOpenAttr) {
summary.__details.setAttribute('open', 'open')
} else {
summary.__details.removeAttribute('open')
}
}
if (summary.__twisty) {
summary.__twisty.firstChild.nodeValue = (expanded ? '\u25ba' : '\u25bc')
summary.__twisty.setAttribute('class', (expanded ? 'arrow arrow-closed' : 'arrow arrow-open'))
}
return true
} | javascript | function (summary) {
var expanded = summary.__details.__summary.getAttribute('aria-expanded') === 'true'
var hidden = summary.__details.__content.getAttribute('aria-hidden') === 'true'
summary.__details.__summary.setAttribute('aria-expanded', (expanded ? 'false' : 'true'))
summary.__details.__content.setAttribute('aria-hidden', (hidden ? 'false' : 'true'))
if (!GOVUK.details.NATIVE_DETAILS) {
summary.__details.__content.style.display = (expanded ? 'none' : '')
var hasOpenAttr = summary.__details.getAttribute('open') !== null
if (!hasOpenAttr) {
summary.__details.setAttribute('open', 'open')
} else {
summary.__details.removeAttribute('open')
}
}
if (summary.__twisty) {
summary.__twisty.firstChild.nodeValue = (expanded ? '\u25ba' : '\u25bc')
summary.__twisty.setAttribute('class', (expanded ? 'arrow arrow-closed' : 'arrow arrow-open'))
}
return true
} | [
"function",
"(",
"summary",
")",
"{",
"var",
"expanded",
"=",
"summary",
".",
"__details",
".",
"__summary",
".",
"getAttribute",
"(",
"'aria-expanded'",
")",
"===",
"'true'",
"var",
"hidden",
"=",
"summary",
".",
"__details",
".",
"__content",
".",
"getAttribute",
"(",
"'aria-hidden'",
")",
"===",
"'true'",
"summary",
".",
"__details",
".",
"__summary",
".",
"setAttribute",
"(",
"'aria-expanded'",
",",
"(",
"expanded",
"?",
"'false'",
":",
"'true'",
")",
")",
"summary",
".",
"__details",
".",
"__content",
".",
"setAttribute",
"(",
"'aria-hidden'",
",",
"(",
"hidden",
"?",
"'false'",
":",
"'true'",
")",
")",
"if",
"(",
"!",
"GOVUK",
".",
"details",
".",
"NATIVE_DETAILS",
")",
"{",
"summary",
".",
"__details",
".",
"__content",
".",
"style",
".",
"display",
"=",
"(",
"expanded",
"?",
"'none'",
":",
"''",
")",
"var",
"hasOpenAttr",
"=",
"summary",
".",
"__details",
".",
"getAttribute",
"(",
"'open'",
")",
"!==",
"null",
"if",
"(",
"!",
"hasOpenAttr",
")",
"{",
"summary",
".",
"__details",
".",
"setAttribute",
"(",
"'open'",
",",
"'open'",
")",
"}",
"else",
"{",
"summary",
".",
"__details",
".",
"removeAttribute",
"(",
"'open'",
")",
"}",
"}",
"if",
"(",
"summary",
".",
"__twisty",
")",
"{",
"summary",
".",
"__twisty",
".",
"firstChild",
".",
"nodeValue",
"=",
"(",
"expanded",
"?",
"'\\u25ba'",
":",
"\\u25ba",
")",
"'\\u25bc'",
"}",
"\\u25bc",
"}"
] | Define a statechange function that updates aria-expanded and style.display Also update the arrow position | [
"Define",
"a",
"statechange",
"function",
"that",
"updates",
"aria",
"-",
"expanded",
"and",
"style",
".",
"display",
"Also",
"update",
"the",
"arrow",
"position"
] | 761632e5bed24c5106f4bdbd8cc99688d8ca616d | https://github.com/alphagov/govuk_frontend_toolkit_npm/blob/761632e5bed24c5106f4bdbd8cc99688d8ca616d/javascripts/govuk/details.polyfill.js#L201-L225 | train |
|
alphagov/govuk_frontend_toolkit_npm | javascripts/govuk/details.polyfill.js | function ($container) {
GOVUK.details.addEvent(document, 'DOMContentLoaded', GOVUK.details.addDetailsPolyfill)
GOVUK.details.addEvent(window, 'load', GOVUK.details.addDetailsPolyfill)
} | javascript | function ($container) {
GOVUK.details.addEvent(document, 'DOMContentLoaded', GOVUK.details.addDetailsPolyfill)
GOVUK.details.addEvent(window, 'load', GOVUK.details.addDetailsPolyfill)
} | [
"function",
"(",
"$container",
")",
"{",
"GOVUK",
".",
"details",
".",
"addEvent",
"(",
"document",
",",
"'DOMContentLoaded'",
",",
"GOVUK",
".",
"details",
".",
"addDetailsPolyfill",
")",
"GOVUK",
".",
"details",
".",
"addEvent",
"(",
"window",
",",
"'load'",
",",
"GOVUK",
".",
"details",
".",
"addDetailsPolyfill",
")",
"}"
] | Bind two load events for modern and older browsers If the first one fires it will set a flag to block the second one but if it's not supported then the second one will fire | [
"Bind",
"two",
"load",
"events",
"for",
"modern",
"and",
"older",
"browsers",
"If",
"the",
"first",
"one",
"fires",
"it",
"will",
"set",
"a",
"flag",
"to",
"block",
"the",
"second",
"one",
"but",
"if",
"it",
"s",
"not",
"supported",
"then",
"the",
"second",
"one",
"will",
"fire"
] | 761632e5bed24c5106f4bdbd8cc99688d8ca616d | https://github.com/alphagov/govuk_frontend_toolkit_npm/blob/761632e5bed24c5106f4bdbd8cc99688d8ca616d/javascripts/govuk/details.polyfill.js#L234-L237 | train |
|
lukem512/pronounceable | pronounceable.js | undef | function undef(w, i, depth, probs) {
if (depth <= 1) return typeof probs[w[i]] === "undefined";
if (typeof probs[w[i]] === "undefined") return true;
return undef(w, i + 1, depth - 1, probs[w[i]]);
} | javascript | function undef(w, i, depth, probs) {
if (depth <= 1) return typeof probs[w[i]] === "undefined";
if (typeof probs[w[i]] === "undefined") return true;
return undef(w, i + 1, depth - 1, probs[w[i]]);
} | [
"function",
"undef",
"(",
"w",
",",
"i",
",",
"depth",
",",
"probs",
")",
"{",
"if",
"(",
"depth",
"<=",
"1",
")",
"return",
"typeof",
"probs",
"[",
"w",
"[",
"i",
"]",
"]",
"===",
"\"undefined\"",
";",
"if",
"(",
"typeof",
"probs",
"[",
"w",
"[",
"i",
"]",
"]",
"===",
"\"undefined\"",
")",
"return",
"true",
";",
"return",
"undef",
"(",
"w",
",",
"i",
"+",
"1",
",",
"depth",
"-",
"1",
",",
"probs",
"[",
"w",
"[",
"i",
"]",
"]",
")",
";",
"}"
] | Check for undefined probabilities. | [
"Check",
"for",
"undefined",
"probabilities",
"."
] | 5719a96fe9e9b87e0f1f9b56c19b88f06a9ad9cf | https://github.com/lukem512/pronounceable/blob/5719a96fe9e9b87e0f1f9b56c19b88f06a9ad9cf/pronounceable.js#L29-L33 | train |
lukem512/pronounceable | pronounceable.js | trainTuples | function trainTuples(words) {
var probs = {};
var count = 0;
words.forEach(function(w) {
w = clean(w);
for (var i = 0; i < w.length - 1; i++) {
if (!probs[w[i]]) probs[w[i]] = {};
if (!probs[w[i]][w[i + 1]]) probs[w[i]][w[i + 1]] = 1;
else probs[w[i]][w[i + 1]]++;
count++;
}
});
Object.keys(probs).forEach(function(first) {
Object.keys(probs[first]).forEach(function(second) {
probs[first][second] = percent(probs[first][second], count);
});
});
return probs;
} | javascript | function trainTuples(words) {
var probs = {};
var count = 0;
words.forEach(function(w) {
w = clean(w);
for (var i = 0; i < w.length - 1; i++) {
if (!probs[w[i]]) probs[w[i]] = {};
if (!probs[w[i]][w[i + 1]]) probs[w[i]][w[i + 1]] = 1;
else probs[w[i]][w[i + 1]]++;
count++;
}
});
Object.keys(probs).forEach(function(first) {
Object.keys(probs[first]).forEach(function(second) {
probs[first][second] = percent(probs[first][second], count);
});
});
return probs;
} | [
"function",
"trainTuples",
"(",
"words",
")",
"{",
"var",
"probs",
"=",
"{",
"}",
";",
"var",
"count",
"=",
"0",
";",
"words",
".",
"forEach",
"(",
"function",
"(",
"w",
")",
"{",
"w",
"=",
"clean",
"(",
"w",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"w",
".",
"length",
"-",
"1",
";",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"probs",
"[",
"w",
"[",
"i",
"]",
"]",
")",
"probs",
"[",
"w",
"[",
"i",
"]",
"]",
"=",
"{",
"}",
";",
"if",
"(",
"!",
"probs",
"[",
"w",
"[",
"i",
"]",
"]",
"[",
"w",
"[",
"i",
"+",
"1",
"]",
"]",
")",
"probs",
"[",
"w",
"[",
"i",
"]",
"]",
"[",
"w",
"[",
"i",
"+",
"1",
"]",
"]",
"=",
"1",
";",
"else",
"probs",
"[",
"w",
"[",
"i",
"]",
"]",
"[",
"w",
"[",
"i",
"+",
"1",
"]",
"]",
"++",
";",
"count",
"++",
";",
"}",
"}",
")",
";",
"Object",
".",
"keys",
"(",
"probs",
")",
".",
"forEach",
"(",
"function",
"(",
"first",
")",
"{",
"Object",
".",
"keys",
"(",
"probs",
"[",
"first",
"]",
")",
".",
"forEach",
"(",
"function",
"(",
"second",
")",
"{",
"probs",
"[",
"first",
"]",
"[",
"second",
"]",
"=",
"percent",
"(",
"probs",
"[",
"first",
"]",
"[",
"second",
"]",
",",
"count",
")",
";",
"}",
")",
";",
"}",
")",
";",
"return",
"probs",
";",
"}"
] | Extract probabilities of word t uple. | [
"Extract",
"probabilities",
"of",
"word",
"t",
"uple",
"."
] | 5719a96fe9e9b87e0f1f9b56c19b88f06a9ad9cf | https://github.com/lukem512/pronounceable/blob/5719a96fe9e9b87e0f1f9b56c19b88f06a9ad9cf/pronounceable.js#L36-L58 | train |
lukem512/pronounceable | pronounceable.js | trainTriples | function trainTriples(words) {
var probs = {};
var count = 0;
words.forEach(function(w) {
w = clean(w);
for (var i = 0; i < w.length - 2; i++) {
if (!probs[w[i]]) probs[w[i]] = {};
if (!probs[w[i]][w[i + 1]]) probs[w[i]][w[i + 1]] = {};
if (!probs[w[i]][w[i + 1]][w[i + 2]]) probs[w[i]][w[i + 1]][w[i + 2]] = 1;
else probs[w[i]][w[i + 1]][w[i + 2]]++;
count++;
}
});
Object.keys(probs).forEach(function(first) {
Object.keys(probs[first]).forEach(function(second) {
Object.keys(probs[first][second]).forEach(function(third) {
probs[first][second][third] = percent(
probs[first][second][third],
count
);
});
});
});
return probs;
} | javascript | function trainTriples(words) {
var probs = {};
var count = 0;
words.forEach(function(w) {
w = clean(w);
for (var i = 0; i < w.length - 2; i++) {
if (!probs[w[i]]) probs[w[i]] = {};
if (!probs[w[i]][w[i + 1]]) probs[w[i]][w[i + 1]] = {};
if (!probs[w[i]][w[i + 1]][w[i + 2]]) probs[w[i]][w[i + 1]][w[i + 2]] = 1;
else probs[w[i]][w[i + 1]][w[i + 2]]++;
count++;
}
});
Object.keys(probs).forEach(function(first) {
Object.keys(probs[first]).forEach(function(second) {
Object.keys(probs[first][second]).forEach(function(third) {
probs[first][second][third] = percent(
probs[first][second][third],
count
);
});
});
});
return probs;
} | [
"function",
"trainTriples",
"(",
"words",
")",
"{",
"var",
"probs",
"=",
"{",
"}",
";",
"var",
"count",
"=",
"0",
";",
"words",
".",
"forEach",
"(",
"function",
"(",
"w",
")",
"{",
"w",
"=",
"clean",
"(",
"w",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"w",
".",
"length",
"-",
"2",
";",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"probs",
"[",
"w",
"[",
"i",
"]",
"]",
")",
"probs",
"[",
"w",
"[",
"i",
"]",
"]",
"=",
"{",
"}",
";",
"if",
"(",
"!",
"probs",
"[",
"w",
"[",
"i",
"]",
"]",
"[",
"w",
"[",
"i",
"+",
"1",
"]",
"]",
")",
"probs",
"[",
"w",
"[",
"i",
"]",
"]",
"[",
"w",
"[",
"i",
"+",
"1",
"]",
"]",
"=",
"{",
"}",
";",
"if",
"(",
"!",
"probs",
"[",
"w",
"[",
"i",
"]",
"]",
"[",
"w",
"[",
"i",
"+",
"1",
"]",
"]",
"[",
"w",
"[",
"i",
"+",
"2",
"]",
"]",
")",
"probs",
"[",
"w",
"[",
"i",
"]",
"]",
"[",
"w",
"[",
"i",
"+",
"1",
"]",
"]",
"[",
"w",
"[",
"i",
"+",
"2",
"]",
"]",
"=",
"1",
";",
"else",
"probs",
"[",
"w",
"[",
"i",
"]",
"]",
"[",
"w",
"[",
"i",
"+",
"1",
"]",
"]",
"[",
"w",
"[",
"i",
"+",
"2",
"]",
"]",
"++",
";",
"count",
"++",
";",
"}",
"}",
")",
";",
"Object",
".",
"keys",
"(",
"probs",
")",
".",
"forEach",
"(",
"function",
"(",
"first",
")",
"{",
"Object",
".",
"keys",
"(",
"probs",
"[",
"first",
"]",
")",
".",
"forEach",
"(",
"function",
"(",
"second",
")",
"{",
"Object",
".",
"keys",
"(",
"probs",
"[",
"first",
"]",
"[",
"second",
"]",
")",
".",
"forEach",
"(",
"function",
"(",
"third",
")",
"{",
"probs",
"[",
"first",
"]",
"[",
"second",
"]",
"[",
"third",
"]",
"=",
"percent",
"(",
"probs",
"[",
"first",
"]",
"[",
"second",
"]",
"[",
"third",
"]",
",",
"count",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"return",
"probs",
";",
"}"
] | Extract probabilities of word triples. | [
"Extract",
"probabilities",
"of",
"word",
"triples",
"."
] | 5719a96fe9e9b87e0f1f9b56c19b88f06a9ad9cf | https://github.com/lukem512/pronounceable/blob/5719a96fe9e9b87e0f1f9b56c19b88f06a9ad9cf/pronounceable.js#L61-L89 | train |
bvalosek/infusionsoft-api | infusionsoft/services/IOrderService.js | function(apiKey, contactId, creditCardId,
payPlanId, productIds, subscriptionPlanIds, processSpecials,
promoCodes, _leadAffiliatedId, _affiliatedId) {} | javascript | function(apiKey, contactId, creditCardId,
payPlanId, productIds, subscriptionPlanIds, processSpecials,
promoCodes, _leadAffiliatedId, _affiliatedId) {} | [
"function",
"(",
"apiKey",
",",
"contactId",
",",
"creditCardId",
",",
"payPlanId",
",",
"productIds",
",",
"subscriptionPlanIds",
",",
"processSpecials",
",",
"promoCodes",
",",
"_leadAffiliatedId",
",",
"_affiliatedId",
")",
"{",
"}"
] | Returns the result of order placement. The ids of the order and invoice that were created are returned along with the status of a credit card charge if one was made. | [
"Returns",
"the",
"result",
"of",
"order",
"placement",
".",
"The",
"ids",
"of",
"the",
"order",
"and",
"invoice",
"that",
"were",
"created",
"are",
"returned",
"along",
"with",
"the",
"status",
"of",
"a",
"credit",
"card",
"charge",
"if",
"one",
"was",
"made",
"."
] | 883955e23b6f6102db24209ed81a85fb0be596b6 | https://github.com/bvalosek/infusionsoft-api/blob/883955e23b6f6102db24209ed81a85fb0be596b6/infusionsoft/services/IOrderService.js#L13-L15 | train |
|
maurobussini/jslinq | src/jslinq.js | equals | function equals(first, second){
//If are the same instance, true
if (first === second)
return true;
//If values are equals, return true
if (first == second)
return true;
//If different type, false
if (typeof first != typeof second)
return false;
//If are not objects, check value
if (typeof first != "object")
return first == second;
//For each property on first
for (var current in first){
//Get property value from each element
var firstValue = first[current];
var secondValue = second[current];
//If current is object, invoke "Equals" on each
//member of the object; otherwise just check values
var isEqual = (typeof firstValue === 'object') ? equals(firstValue, secondValue) : firstValue == secondValue;
//If not equals, exit
if (!isEqual)
return false;
}
//Confirm
return true;
} | javascript | function equals(first, second){
//If are the same instance, true
if (first === second)
return true;
//If values are equals, return true
if (first == second)
return true;
//If different type, false
if (typeof first != typeof second)
return false;
//If are not objects, check value
if (typeof first != "object")
return first == second;
//For each property on first
for (var current in first){
//Get property value from each element
var firstValue = first[current];
var secondValue = second[current];
//If current is object, invoke "Equals" on each
//member of the object; otherwise just check values
var isEqual = (typeof firstValue === 'object') ? equals(firstValue, secondValue) : firstValue == secondValue;
//If not equals, exit
if (!isEqual)
return false;
}
//Confirm
return true;
} | [
"function",
"equals",
"(",
"first",
",",
"second",
")",
"{",
"if",
"(",
"first",
"===",
"second",
")",
"return",
"true",
";",
"if",
"(",
"first",
"==",
"second",
")",
"return",
"true",
";",
"if",
"(",
"typeof",
"first",
"!=",
"typeof",
"second",
")",
"return",
"false",
";",
"if",
"(",
"typeof",
"first",
"!=",
"\"object\"",
")",
"return",
"first",
"==",
"second",
";",
"for",
"(",
"var",
"current",
"in",
"first",
")",
"{",
"var",
"firstValue",
"=",
"first",
"[",
"current",
"]",
";",
"var",
"secondValue",
"=",
"second",
"[",
"current",
"]",
";",
"var",
"isEqual",
"=",
"(",
"typeof",
"firstValue",
"===",
"'object'",
")",
"?",
"equals",
"(",
"firstValue",
",",
"secondValue",
")",
":",
"firstValue",
"==",
"secondValue",
";",
"if",
"(",
"!",
"isEqual",
")",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Verify if first and second element are equals in values | [
"Verify",
"if",
"first",
"and",
"second",
"element",
"are",
"equals",
"in",
"values"
] | cb0bfbe079803a2899196de76916abf604664b55 | https://github.com/maurobussini/jslinq/blob/cb0bfbe079803a2899196de76916abf604664b55/src/jslinq.js#L61-L97 | train |
maurobussini/jslinq | src/jslinq.js | function(a, b){
//Get value for "a" and "b" element
var aValue = expression(a);
var bValue = expression(b);
//Check if one element is greater then the second one
if(aValue < bValue) return -1;
if(aValue > bValue) return 1;
return 0;
} | javascript | function(a, b){
//Get value for "a" and "b" element
var aValue = expression(a);
var bValue = expression(b);
//Check if one element is greater then the second one
if(aValue < bValue) return -1;
if(aValue > bValue) return 1;
return 0;
} | [
"function",
"(",
"a",
",",
"b",
")",
"{",
"var",
"aValue",
"=",
"expression",
"(",
"a",
")",
";",
"var",
"bValue",
"=",
"expression",
"(",
"b",
")",
";",
"if",
"(",
"aValue",
"<",
"bValue",
")",
"return",
"-",
"1",
";",
"if",
"(",
"aValue",
">",
"bValue",
")",
"return",
"1",
";",
"return",
"0",
";",
"}"
] | Define sort action estracting values from objects | [
"Define",
"sort",
"action",
"estracting",
"values",
"from",
"objects"
] | cb0bfbe079803a2899196de76916abf604664b55 | https://github.com/maurobussini/jslinq/blob/cb0bfbe079803a2899196de76916abf604664b55/src/jslinq.js#L284-L294 | train |
|
maurobussini/jslinq | src/jslinq.js | subtract | function subtract(otherData, compareExpression) {
//If other data is invalid, return empty array
if (!otherData)
return new jslinq([]);
//Data for output
var outData = [];
//Check every element of "items"
for (var n = 0; n < this.items.length; n++) {
//Current element on items
var currentOnItems = this.items[n];
//Set flag of "found match" as false
var aMatchWasFound = false;
//Check every element on "otherData"
for (var i = 0; i < otherData.length; i++) {
//If a match was already found, skip
if (aMatchWasFound)
continue;
//Current element on "otherData"
var currentOnOtherData = otherData[i];
//Fails by default matching of elements
var doesMatch = false;
//If compare expression was not set
if (!compareExpression){
//Compare on same instance
//doesMatch = currentOnItems == currentOnOtherData;
doesMatch = equals(currentOnItems, currentOnOtherData);
}
else{
//Calculate comparison value for each element
var comparisonForItems = compareExpression(currentOnItems);
var comparisonForOtherData = compareExpression(currentOnOtherData);
//Compare result of compare expressions
//doesMatch = comparisonForItems == comparisonForOtherData;
doesMatch = equals(comparisonForItems, comparisonForOtherData);
}
//If there's a match, set the flag
if (doesMatch){
aMatchWasFound = true;
}
}
//If no match was found, append element to output
if (!aMatchWasFound){
outData.push(currentOnItems);
}
}
//Return for chaining
return new jslinq(outData);
} | javascript | function subtract(otherData, compareExpression) {
//If other data is invalid, return empty array
if (!otherData)
return new jslinq([]);
//Data for output
var outData = [];
//Check every element of "items"
for (var n = 0; n < this.items.length; n++) {
//Current element on items
var currentOnItems = this.items[n];
//Set flag of "found match" as false
var aMatchWasFound = false;
//Check every element on "otherData"
for (var i = 0; i < otherData.length; i++) {
//If a match was already found, skip
if (aMatchWasFound)
continue;
//Current element on "otherData"
var currentOnOtherData = otherData[i];
//Fails by default matching of elements
var doesMatch = false;
//If compare expression was not set
if (!compareExpression){
//Compare on same instance
//doesMatch = currentOnItems == currentOnOtherData;
doesMatch = equals(currentOnItems, currentOnOtherData);
}
else{
//Calculate comparison value for each element
var comparisonForItems = compareExpression(currentOnItems);
var comparisonForOtherData = compareExpression(currentOnOtherData);
//Compare result of compare expressions
//doesMatch = comparisonForItems == comparisonForOtherData;
doesMatch = equals(comparisonForItems, comparisonForOtherData);
}
//If there's a match, set the flag
if (doesMatch){
aMatchWasFound = true;
}
}
//If no match was found, append element to output
if (!aMatchWasFound){
outData.push(currentOnItems);
}
}
//Return for chaining
return new jslinq(outData);
} | [
"function",
"subtract",
"(",
"otherData",
",",
"compareExpression",
")",
"{",
"if",
"(",
"!",
"otherData",
")",
"return",
"new",
"jslinq",
"(",
"[",
"]",
")",
";",
"var",
"outData",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"n",
"=",
"0",
";",
"n",
"<",
"this",
".",
"items",
".",
"length",
";",
"n",
"++",
")",
"{",
"var",
"currentOnItems",
"=",
"this",
".",
"items",
"[",
"n",
"]",
";",
"var",
"aMatchWasFound",
"=",
"false",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"otherData",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"aMatchWasFound",
")",
"continue",
";",
"var",
"currentOnOtherData",
"=",
"otherData",
"[",
"i",
"]",
";",
"var",
"doesMatch",
"=",
"false",
";",
"if",
"(",
"!",
"compareExpression",
")",
"{",
"doesMatch",
"=",
"equals",
"(",
"currentOnItems",
",",
"currentOnOtherData",
")",
";",
"}",
"else",
"{",
"var",
"comparisonForItems",
"=",
"compareExpression",
"(",
"currentOnItems",
")",
";",
"var",
"comparisonForOtherData",
"=",
"compareExpression",
"(",
"currentOnOtherData",
")",
";",
"doesMatch",
"=",
"equals",
"(",
"comparisonForItems",
",",
"comparisonForOtherData",
")",
";",
"}",
"if",
"(",
"doesMatch",
")",
"{",
"aMatchWasFound",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"!",
"aMatchWasFound",
")",
"{",
"outData",
".",
"push",
"(",
"currentOnItems",
")",
";",
"}",
"}",
"return",
"new",
"jslinq",
"(",
"outData",
")",
";",
"}"
] | Get only elements NOT contained on provided "otherData" using same instance or compare expression | [
"Get",
"only",
"elements",
"NOT",
"contained",
"on",
"provided",
"otherData",
"using",
"same",
"instance",
"or",
"compare",
"expression"
] | cb0bfbe079803a2899196de76916abf604664b55 | https://github.com/maurobussini/jslinq/blob/cb0bfbe079803a2899196de76916abf604664b55/src/jslinq.js#L757-L820 | train |
retextjs/retext-intensify | index.js | transformer | function transformer(tree, file) {
search(tree, phrases, searcher)
function searcher(match, index, parent, phrase) {
var type = weasel
var message
if (weasels.indexOf(phrase) === -1) {
type = fillers.indexOf(phrase) === -1 ? hedge : filler
}
message = file.warn(
'Don’t use ' + quote(toString(match), '“', '”') + ', ' + messages[type],
{
start: position.start(match[0]),
end: position.end(match[match.length - 1])
}
)
message.ruleId = type
message.source = 'retext-intensify'
}
} | javascript | function transformer(tree, file) {
search(tree, phrases, searcher)
function searcher(match, index, parent, phrase) {
var type = weasel
var message
if (weasels.indexOf(phrase) === -1) {
type = fillers.indexOf(phrase) === -1 ? hedge : filler
}
message = file.warn(
'Don’t use ' + quote(toString(match), '“', '”') + ', ' + messages[type],
{
start: position.start(match[0]),
end: position.end(match[match.length - 1])
}
)
message.ruleId = type
message.source = 'retext-intensify'
}
} | [
"function",
"transformer",
"(",
"tree",
",",
"file",
")",
"{",
"search",
"(",
"tree",
",",
"phrases",
",",
"searcher",
")",
"function",
"searcher",
"(",
"match",
",",
"index",
",",
"parent",
",",
"phrase",
")",
"{",
"var",
"type",
"=",
"weasel",
"var",
"message",
"if",
"(",
"weasels",
".",
"indexOf",
"(",
"phrase",
")",
"===",
"-",
"1",
")",
"{",
"type",
"=",
"fillers",
".",
"indexOf",
"(",
"phrase",
")",
"===",
"-",
"1",
"?",
"hedge",
":",
"filler",
"}",
"message",
"=",
"file",
".",
"warn",
"(",
"'Don’t use ' +",
"+",
"q",
"ote(t",
"o",
"String(m",
"a",
"tch),",
" ",
"'",
"', '”",
"”",
"'",
" + ',",
" ",
",",
" ",
" ",
" mes",
")",
" ",
"s",
"}",
"}"
] | Search `tree` for validations. | [
"Search",
"tree",
"for",
"validations",
"."
] | 8d52a7eb54de75a50d7f5c4fea18b151c1a656a2 | https://github.com/retextjs/retext-intensify/blob/8d52a7eb54de75a50d7f5c4fea18b151c1a656a2/index.js#L37-L59 | train |
jonschlinkert/html-toc | index.js | buildHTML | function buildHTML(navigation, first, sParentLink) {
return '<ul class="nav' + (first ? ' sidenav' : '') + '">' + navigation.map(function(loc) {
if (!loc || !loc.link) return '';
loc.link = (opts.parentLink && sParentLink ? sParentLink + '-' : '') + loc.link;
loc.$ele.attr('id', loc.link);
return '<li><a href="#' + loc.link + '">' + escape(loc.text) + '</a>' + (loc.children ? buildHTML(loc.children, false, loc.link) : '') + '</li>';
}).join('\n') + '</ul>';
} | javascript | function buildHTML(navigation, first, sParentLink) {
return '<ul class="nav' + (first ? ' sidenav' : '') + '">' + navigation.map(function(loc) {
if (!loc || !loc.link) return '';
loc.link = (opts.parentLink && sParentLink ? sParentLink + '-' : '') + loc.link;
loc.$ele.attr('id', loc.link);
return '<li><a href="#' + loc.link + '">' + escape(loc.text) + '</a>' + (loc.children ? buildHTML(loc.children, false, loc.link) : '') + '</li>';
}).join('\n') + '</ul>';
} | [
"function",
"buildHTML",
"(",
"navigation",
",",
"first",
",",
"sParentLink",
")",
"{",
"return",
"'<ul class=\"nav'",
"+",
"(",
"first",
"?",
"' sidenav'",
":",
"''",
")",
"+",
"'\">'",
"+",
"navigation",
".",
"map",
"(",
"function",
"(",
"loc",
")",
"{",
"if",
"(",
"!",
"loc",
"||",
"!",
"loc",
".",
"link",
")",
"return",
"''",
";",
"loc",
".",
"link",
"=",
"(",
"opts",
".",
"parentLink",
"&&",
"sParentLink",
"?",
"sParentLink",
"+",
"'-'",
":",
"''",
")",
"+",
"loc",
".",
"link",
";",
"loc",
".",
"$ele",
".",
"attr",
"(",
"'id'",
",",
"loc",
".",
"link",
")",
";",
"return",
"'<li><a href=\"#'",
"+",
"loc",
".",
"link",
"+",
"'\">'",
"+",
"escape",
"(",
"loc",
".",
"text",
")",
"+",
"'</a>'",
"+",
"(",
"loc",
".",
"children",
"?",
"buildHTML",
"(",
"loc",
".",
"children",
",",
"false",
",",
"loc",
".",
"link",
")",
":",
"''",
")",
"+",
"'</li>'",
";",
"}",
")",
".",
"join",
"(",
"'\\n'",
")",
"+",
"\\n",
";",
"}"
] | Build the HTML for side navigation. | [
"Build",
"the",
"HTML",
"for",
"side",
"navigation",
"."
] | c529bad2f5b964652c8230be7bb4270e31ba734d | https://github.com/jonschlinkert/html-toc/blob/c529bad2f5b964652c8230be7bb4270e31ba734d/index.js#L68-L77 | train |
fabienb4/meteor-jsdoc | example/meteor/client/templates/search.js | function(arrayOfSearchResultsArrays) {
let ids = {};
let dedupedResults = [];
_.each(arrayOfSearchResultsArrays, (searchResults) => {
_.each(searchResults, (item) => {
if (! ids.hasOwnProperty(item._id)) {
ids[item._id] = true;
dedupedResults.push(item);
}
});
});
return dedupedResults;
} | javascript | function(arrayOfSearchResultsArrays) {
let ids = {};
let dedupedResults = [];
_.each(arrayOfSearchResultsArrays, (searchResults) => {
_.each(searchResults, (item) => {
if (! ids.hasOwnProperty(item._id)) {
ids[item._id] = true;
dedupedResults.push(item);
}
});
});
return dedupedResults;
} | [
"function",
"(",
"arrayOfSearchResultsArrays",
")",
"{",
"let",
"ids",
"=",
"{",
"}",
";",
"let",
"dedupedResults",
"=",
"[",
"]",
";",
"_",
".",
"each",
"(",
"arrayOfSearchResultsArrays",
",",
"(",
"searchResults",
")",
"=>",
"{",
"_",
".",
"each",
"(",
"searchResults",
",",
"(",
"item",
")",
"=>",
"{",
"if",
"(",
"!",
"ids",
".",
"hasOwnProperty",
"(",
"item",
".",
"_id",
")",
")",
"{",
"ids",
"[",
"item",
".",
"_id",
"]",
"=",
"true",
";",
"dedupedResults",
".",
"push",
"(",
"item",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"return",
"dedupedResults",
";",
"}"
] | When you have two arrays of search results, use this function to deduplicate them | [
"When",
"you",
"have",
"two",
"arrays",
"of",
"search",
"results",
"use",
"this",
"function",
"to",
"deduplicate",
"them"
] | f11ea7d694fac18025f53cb4826cafe80c69c625 | https://github.com/fabienb4/meteor-jsdoc/blob/f11ea7d694fac18025f53cb4826cafe80c69c625/example/meteor/client/templates/search.js#L147-L162 | train |
|
mike-goodwin/connect-azuretables | lib/connect-azuretables.js | logOrThrow | function logOrThrow(error, result) {
if (result) {
self.log('connect-azuretables created table ' + self.table);
}
if (error) {
throw ('failed to create table: ' + error);
}
} | javascript | function logOrThrow(error, result) {
if (result) {
self.log('connect-azuretables created table ' + self.table);
}
if (error) {
throw ('failed to create table: ' + error);
}
} | [
"function",
"logOrThrow",
"(",
"error",
",",
"result",
")",
"{",
"if",
"(",
"result",
")",
"{",
"self",
".",
"log",
"(",
"'connect-azuretables created table '",
"+",
"self",
".",
"table",
")",
";",
"}",
"if",
"(",
"error",
")",
"{",
"throw",
"(",
"'failed to create table: '",
"+",
"error",
")",
";",
"}",
"}"
] | reducing function complexity to keep code climate happy | [
"reducing",
"function",
"complexity",
"to",
"keep",
"code",
"climate",
"happy"
] | b148c19ee6abcf636fd58d8c983aed0a3d0d21b2 | https://github.com/mike-goodwin/connect-azuretables/blob/b148c19ee6abcf636fd58d8c983aed0a3d0d21b2/lib/connect-azuretables.js#L79-L88 | train |
mike-goodwin/connect-azuretables | lib/connect-azuretables.js | errorOrResult | function errorOrResult(error, result, fn) {
return error ? fn(error) : fn(null, result);
} | javascript | function errorOrResult(error, result, fn) {
return error ? fn(error) : fn(null, result);
} | [
"function",
"errorOrResult",
"(",
"error",
",",
"result",
",",
"fn",
")",
"{",
"return",
"error",
"?",
"fn",
"(",
"error",
")",
":",
"fn",
"(",
"null",
",",
"result",
")",
";",
"}"
] | removing duplicate code to keep code climate happy | [
"removing",
"duplicate",
"code",
"to",
"keep",
"code",
"climate",
"happy"
] | b148c19ee6abcf636fd58d8c983aed0a3d0d21b2 | https://github.com/mike-goodwin/connect-azuretables/blob/b148c19ee6abcf636fd58d8c983aed0a3d0d21b2/lib/connect-azuretables.js#L259-L261 | train |
mike-goodwin/connect-azuretables | lib/connect-azuretables.js | getExpiryDate | function getExpiryDate(store, data) {
var offset;
if (data.cookie.originalMaxAge) {
offset = data.cookie.originalMaxAge;
} else {
offset = store.sessionTimeOut * 60000;
}
return offset ? new Date(Date.now() + offset) : null;
} | javascript | function getExpiryDate(store, data) {
var offset;
if (data.cookie.originalMaxAge) {
offset = data.cookie.originalMaxAge;
} else {
offset = store.sessionTimeOut * 60000;
}
return offset ? new Date(Date.now() + offset) : null;
} | [
"function",
"getExpiryDate",
"(",
"store",
",",
"data",
")",
"{",
"var",
"offset",
";",
"if",
"(",
"data",
".",
"cookie",
".",
"originalMaxAge",
")",
"{",
"offset",
"=",
"data",
".",
"cookie",
".",
"originalMaxAge",
";",
"}",
"else",
"{",
"offset",
"=",
"store",
".",
"sessionTimeOut",
"*",
"60000",
";",
"}",
"return",
"offset",
"?",
"new",
"Date",
"(",
"Date",
".",
"now",
"(",
")",
"+",
"offset",
")",
":",
"null",
";",
"}"
] | expiry date for sessions | [
"expiry",
"date",
"for",
"sessions"
] | b148c19ee6abcf636fd58d8c983aed0a3d0d21b2 | https://github.com/mike-goodwin/connect-azuretables/blob/b148c19ee6abcf636fd58d8c983aed0a3d0d21b2/lib/connect-azuretables.js#L264-L275 | train |
jaredLunde/react-emoji-component | examples/every-emoji/webpack/startServer.js | startListening | function startListening () {
if (isBuilt === false) {
app.listen(
parseInt(port),
host,
() => {
isBuilt = true
console.log(chalk.green(`[React Emoji Component SSR] ${host}:${port}`))
}
)
}
} | javascript | function startListening () {
if (isBuilt === false) {
app.listen(
parseInt(port),
host,
() => {
isBuilt = true
console.log(chalk.green(`[React Emoji Component SSR] ${host}:${port}`))
}
)
}
} | [
"function",
"startListening",
"(",
")",
"{",
"if",
"(",
"isBuilt",
"===",
"false",
")",
"{",
"app",
".",
"listen",
"(",
"parseInt",
"(",
"port",
")",
",",
"host",
",",
"(",
")",
"=>",
"{",
"isBuilt",
"=",
"true",
"console",
".",
"log",
"(",
"chalk",
".",
"green",
"(",
"`",
"${",
"host",
"}",
"${",
"port",
"}",
"`",
")",
")",
"}",
")",
"}",
"}"
] | express listener which is run after the compiler is done | [
"express",
"listener",
"which",
"is",
"run",
"after",
"the",
"compiler",
"is",
"done"
] | a5083fa3df2b546e66ccfab943623101954c5527 | https://github.com/jaredLunde/react-emoji-component/blob/a5083fa3df2b546e66ccfab943623101954c5527/examples/every-emoji/webpack/startServer.js#L32-L43 | train |
mjyc/cycle-robot-drivers | docs/slides/20190327_rosseattlemeetup/export/libs/reveal.js/3.7.0/plugin/zoom-js/zoom.js | magnify | function magnify( rect, scale ) {
var scrollOffset = getScrollOffset();
// Ensure a width/height is set
rect.width = rect.width || 1;
rect.height = rect.height || 1;
// Center the rect within the zoomed viewport
rect.x -= ( window.innerWidth - ( rect.width * scale ) ) / 2;
rect.y -= ( window.innerHeight - ( rect.height * scale ) ) / 2;
if( supportsTransforms ) {
// Reset
if( scale === 1 ) {
document.body.style.transform = '';
document.body.style.OTransform = '';
document.body.style.msTransform = '';
document.body.style.MozTransform = '';
document.body.style.WebkitTransform = '';
}
// Scale
else {
var origin = scrollOffset.x +'px '+ scrollOffset.y +'px',
transform = 'translate('+ -rect.x +'px,'+ -rect.y +'px) scale('+ scale +')';
document.body.style.transformOrigin = origin;
document.body.style.OTransformOrigin = origin;
document.body.style.msTransformOrigin = origin;
document.body.style.MozTransformOrigin = origin;
document.body.style.WebkitTransformOrigin = origin;
document.body.style.transform = transform;
document.body.style.OTransform = transform;
document.body.style.msTransform = transform;
document.body.style.MozTransform = transform;
document.body.style.WebkitTransform = transform;
}
}
else {
// Reset
if( scale === 1 ) {
document.body.style.position = '';
document.body.style.left = '';
document.body.style.top = '';
document.body.style.width = '';
document.body.style.height = '';
document.body.style.zoom = '';
}
// Scale
else {
document.body.style.position = 'relative';
document.body.style.left = ( - ( scrollOffset.x + rect.x ) / scale ) + 'px';
document.body.style.top = ( - ( scrollOffset.y + rect.y ) / scale ) + 'px';
document.body.style.width = ( scale * 100 ) + '%';
document.body.style.height = ( scale * 100 ) + '%';
document.body.style.zoom = scale;
}
}
level = scale;
if( document.documentElement.classList ) {
if( level !== 1 ) {
document.documentElement.classList.add( 'zoomed' );
}
else {
document.documentElement.classList.remove( 'zoomed' );
}
}
} | javascript | function magnify( rect, scale ) {
var scrollOffset = getScrollOffset();
// Ensure a width/height is set
rect.width = rect.width || 1;
rect.height = rect.height || 1;
// Center the rect within the zoomed viewport
rect.x -= ( window.innerWidth - ( rect.width * scale ) ) / 2;
rect.y -= ( window.innerHeight - ( rect.height * scale ) ) / 2;
if( supportsTransforms ) {
// Reset
if( scale === 1 ) {
document.body.style.transform = '';
document.body.style.OTransform = '';
document.body.style.msTransform = '';
document.body.style.MozTransform = '';
document.body.style.WebkitTransform = '';
}
// Scale
else {
var origin = scrollOffset.x +'px '+ scrollOffset.y +'px',
transform = 'translate('+ -rect.x +'px,'+ -rect.y +'px) scale('+ scale +')';
document.body.style.transformOrigin = origin;
document.body.style.OTransformOrigin = origin;
document.body.style.msTransformOrigin = origin;
document.body.style.MozTransformOrigin = origin;
document.body.style.WebkitTransformOrigin = origin;
document.body.style.transform = transform;
document.body.style.OTransform = transform;
document.body.style.msTransform = transform;
document.body.style.MozTransform = transform;
document.body.style.WebkitTransform = transform;
}
}
else {
// Reset
if( scale === 1 ) {
document.body.style.position = '';
document.body.style.left = '';
document.body.style.top = '';
document.body.style.width = '';
document.body.style.height = '';
document.body.style.zoom = '';
}
// Scale
else {
document.body.style.position = 'relative';
document.body.style.left = ( - ( scrollOffset.x + rect.x ) / scale ) + 'px';
document.body.style.top = ( - ( scrollOffset.y + rect.y ) / scale ) + 'px';
document.body.style.width = ( scale * 100 ) + '%';
document.body.style.height = ( scale * 100 ) + '%';
document.body.style.zoom = scale;
}
}
level = scale;
if( document.documentElement.classList ) {
if( level !== 1 ) {
document.documentElement.classList.add( 'zoomed' );
}
else {
document.documentElement.classList.remove( 'zoomed' );
}
}
} | [
"function",
"magnify",
"(",
"rect",
",",
"scale",
")",
"{",
"var",
"scrollOffset",
"=",
"getScrollOffset",
"(",
")",
";",
"rect",
".",
"width",
"=",
"rect",
".",
"width",
"||",
"1",
";",
"rect",
".",
"height",
"=",
"rect",
".",
"height",
"||",
"1",
";",
"rect",
".",
"x",
"-=",
"(",
"window",
".",
"innerWidth",
"-",
"(",
"rect",
".",
"width",
"*",
"scale",
")",
")",
"/",
"2",
";",
"rect",
".",
"y",
"-=",
"(",
"window",
".",
"innerHeight",
"-",
"(",
"rect",
".",
"height",
"*",
"scale",
")",
")",
"/",
"2",
";",
"if",
"(",
"supportsTransforms",
")",
"{",
"if",
"(",
"scale",
"===",
"1",
")",
"{",
"document",
".",
"body",
".",
"style",
".",
"transform",
"=",
"''",
";",
"document",
".",
"body",
".",
"style",
".",
"OTransform",
"=",
"''",
";",
"document",
".",
"body",
".",
"style",
".",
"msTransform",
"=",
"''",
";",
"document",
".",
"body",
".",
"style",
".",
"MozTransform",
"=",
"''",
";",
"document",
".",
"body",
".",
"style",
".",
"WebkitTransform",
"=",
"''",
";",
"}",
"else",
"{",
"var",
"origin",
"=",
"scrollOffset",
".",
"x",
"+",
"'px '",
"+",
"scrollOffset",
".",
"y",
"+",
"'px'",
",",
"transform",
"=",
"'translate('",
"+",
"-",
"rect",
".",
"x",
"+",
"'px,'",
"+",
"-",
"rect",
".",
"y",
"+",
"'px) scale('",
"+",
"scale",
"+",
"')'",
";",
"document",
".",
"body",
".",
"style",
".",
"transformOrigin",
"=",
"origin",
";",
"document",
".",
"body",
".",
"style",
".",
"OTransformOrigin",
"=",
"origin",
";",
"document",
".",
"body",
".",
"style",
".",
"msTransformOrigin",
"=",
"origin",
";",
"document",
".",
"body",
".",
"style",
".",
"MozTransformOrigin",
"=",
"origin",
";",
"document",
".",
"body",
".",
"style",
".",
"WebkitTransformOrigin",
"=",
"origin",
";",
"document",
".",
"body",
".",
"style",
".",
"transform",
"=",
"transform",
";",
"document",
".",
"body",
".",
"style",
".",
"OTransform",
"=",
"transform",
";",
"document",
".",
"body",
".",
"style",
".",
"msTransform",
"=",
"transform",
";",
"document",
".",
"body",
".",
"style",
".",
"MozTransform",
"=",
"transform",
";",
"document",
".",
"body",
".",
"style",
".",
"WebkitTransform",
"=",
"transform",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"scale",
"===",
"1",
")",
"{",
"document",
".",
"body",
".",
"style",
".",
"position",
"=",
"''",
";",
"document",
".",
"body",
".",
"style",
".",
"left",
"=",
"''",
";",
"document",
".",
"body",
".",
"style",
".",
"top",
"=",
"''",
";",
"document",
".",
"body",
".",
"style",
".",
"width",
"=",
"''",
";",
"document",
".",
"body",
".",
"style",
".",
"height",
"=",
"''",
";",
"document",
".",
"body",
".",
"style",
".",
"zoom",
"=",
"''",
";",
"}",
"else",
"{",
"document",
".",
"body",
".",
"style",
".",
"position",
"=",
"'relative'",
";",
"document",
".",
"body",
".",
"style",
".",
"left",
"=",
"(",
"-",
"(",
"scrollOffset",
".",
"x",
"+",
"rect",
".",
"x",
")",
"/",
"scale",
")",
"+",
"'px'",
";",
"document",
".",
"body",
".",
"style",
".",
"top",
"=",
"(",
"-",
"(",
"scrollOffset",
".",
"y",
"+",
"rect",
".",
"y",
")",
"/",
"scale",
")",
"+",
"'px'",
";",
"document",
".",
"body",
".",
"style",
".",
"width",
"=",
"(",
"scale",
"*",
"100",
")",
"+",
"'%'",
";",
"document",
".",
"body",
".",
"style",
".",
"height",
"=",
"(",
"scale",
"*",
"100",
")",
"+",
"'%'",
";",
"document",
".",
"body",
".",
"style",
".",
"zoom",
"=",
"scale",
";",
"}",
"}",
"level",
"=",
"scale",
";",
"if",
"(",
"document",
".",
"documentElement",
".",
"classList",
")",
"{",
"if",
"(",
"level",
"!==",
"1",
")",
"{",
"document",
".",
"documentElement",
".",
"classList",
".",
"add",
"(",
"'zoomed'",
")",
";",
"}",
"else",
"{",
"document",
".",
"documentElement",
".",
"classList",
".",
"remove",
"(",
"'zoomed'",
")",
";",
"}",
"}",
"}"
] | Applies the CSS required to zoom in, prefers the use of CSS3
transforms but falls back on zoom for IE.
@param {Object} rect
@param {Number} scale | [
"Applies",
"the",
"CSS",
"required",
"to",
"zoom",
"in",
"prefers",
"the",
"use",
"of",
"CSS3",
"transforms",
"but",
"falls",
"back",
"on",
"zoom",
"for",
"IE",
"."
] | acdc666150d686ee79b0ba917b6afcf09172c925 | https://github.com/mjyc/cycle-robot-drivers/blob/acdc666150d686ee79b0ba917b6afcf09172c925/docs/slides/20190327_rosseattlemeetup/export/libs/reveal.js/3.7.0/plugin/zoom-js/zoom.js#L85-L155 | train |
bvalosek/infusionsoft-api | lib/Queryable.js | function(T)
{
var ret = [];
_(typedef.signature(T)).each(function(info, key) {
if (info.decorations.FIELD)
ret.push(key);
});
return ret;
} | javascript | function(T)
{
var ret = [];
_(typedef.signature(T)).each(function(info, key) {
if (info.decorations.FIELD)
ret.push(key);
});
return ret;
} | [
"function",
"(",
"T",
")",
"{",
"var",
"ret",
"=",
"[",
"]",
";",
"_",
"(",
"typedef",
".",
"signature",
"(",
"T",
")",
")",
".",
"each",
"(",
"function",
"(",
"info",
",",
"key",
")",
"{",
"if",
"(",
"info",
".",
"decorations",
".",
"FIELD",
")",
"ret",
".",
"push",
"(",
"key",
")",
";",
"}",
")",
";",
"return",
"ret",
";",
"}"
] | Attempt to determine all the fields on a given type | [
"Attempt",
"to",
"determine",
"all",
"the",
"fields",
"on",
"a",
"given",
"type"
] | 883955e23b6f6102db24209ed81a85fb0be596b6 | https://github.com/bvalosek/infusionsoft-api/blob/883955e23b6f6102db24209ed81a85fb0be596b6/lib/Queryable.js#L35-L45 | train |
|
bvalosek/infusionsoft-api | lib/Queryable.js | function(o)
{
var q = this.clone();
q._orderBy = o;
q._ascending = true;
return q;
} | javascript | function(o)
{
var q = this.clone();
q._orderBy = o;
q._ascending = true;
return q;
} | [
"function",
"(",
"o",
")",
"{",
"var",
"q",
"=",
"this",
".",
"clone",
"(",
")",
";",
"q",
".",
"_orderBy",
"=",
"o",
";",
"q",
".",
"_ascending",
"=",
"true",
";",
"return",
"q",
";",
"}"
] | Field to order results | [
"Field",
"to",
"order",
"results"
] | 883955e23b6f6102db24209ed81a85fb0be596b6 | https://github.com/bvalosek/infusionsoft-api/blob/883955e23b6f6102db24209ed81a85fb0be596b6/lib/Queryable.js#L114-L120 | train |
|
bvalosek/infusionsoft-api | lib/Queryable.js | function(f)
{
var q = this.clone();
if (arguments.length > 1)
q._fields = _(arguments).toArray();
else if (f)
q._fields = _(f).isArray() ? f : [f];
else
q._fields = Queryable.getFields(this._T);
return q;
} | javascript | function(f)
{
var q = this.clone();
if (arguments.length > 1)
q._fields = _(arguments).toArray();
else if (f)
q._fields = _(f).isArray() ? f : [f];
else
q._fields = Queryable.getFields(this._T);
return q;
} | [
"function",
"(",
"f",
")",
"{",
"var",
"q",
"=",
"this",
".",
"clone",
"(",
")",
";",
"if",
"(",
"arguments",
".",
"length",
">",
"1",
")",
"q",
".",
"_fields",
"=",
"_",
"(",
"arguments",
")",
".",
"toArray",
"(",
")",
";",
"else",
"if",
"(",
"f",
")",
"q",
".",
"_fields",
"=",
"_",
"(",
"f",
")",
".",
"isArray",
"(",
")",
"?",
"f",
":",
"[",
"f",
"]",
";",
"else",
"q",
".",
"_fields",
"=",
"Queryable",
".",
"getFields",
"(",
"this",
".",
"_T",
")",
";",
"return",
"q",
";",
"}"
] | Set what fields we will be using | [
"Set",
"what",
"fields",
"we",
"will",
"be",
"using"
] | 883955e23b6f6102db24209ed81a85fb0be596b6 | https://github.com/bvalosek/infusionsoft-api/blob/883955e23b6f6102db24209ed81a85fb0be596b6/lib/Queryable.js#L131-L143 | train |
|
bvalosek/infusionsoft-api | lib/Queryable.js | function()
{
if (this._executePromise)
return this._executePromise;
var q = this.clone();
var table = q._T.__name__;
var page = q._page;
var fields = q._fields;
// Create the query from our stuff
var query = {};
_(q._where.concat(q._like)).each(function (q) {
query[q.key] = q.value;
});
var doneLoading = Q.defer();
this._executePromise = doneLoading.promise;
var left = q._take;
// A single iteration of fetching via the API. Called repeatedly in
// the case of large / unbounded TAKES
var loop = function() {
// always take 1000 unless we're almost done
var take = left < 1000 ? left : 1000;
// Hit the API and incremement the page
q._fetch(table, take, page++, query, fields).then(function(res) {
// publish progress
doneLoading.notify(q._results.length);
if (left !== undefined) left -= res.length;
// Either resolve the the promise with the results if we're
// done or call the loop again
if (q._doneLoading || left <= 0)
doneLoading.resolve(q._getResults());
else
process.nextTick(loop);
}).catch(function(err) {
doneLoading.reject(err);
});
};
// do tha damn thing
loop();
return doneLoading.promise;
} | javascript | function()
{
if (this._executePromise)
return this._executePromise;
var q = this.clone();
var table = q._T.__name__;
var page = q._page;
var fields = q._fields;
// Create the query from our stuff
var query = {};
_(q._where.concat(q._like)).each(function (q) {
query[q.key] = q.value;
});
var doneLoading = Q.defer();
this._executePromise = doneLoading.promise;
var left = q._take;
// A single iteration of fetching via the API. Called repeatedly in
// the case of large / unbounded TAKES
var loop = function() {
// always take 1000 unless we're almost done
var take = left < 1000 ? left : 1000;
// Hit the API and incremement the page
q._fetch(table, take, page++, query, fields).then(function(res) {
// publish progress
doneLoading.notify(q._results.length);
if (left !== undefined) left -= res.length;
// Either resolve the the promise with the results if we're
// done or call the loop again
if (q._doneLoading || left <= 0)
doneLoading.resolve(q._getResults());
else
process.nextTick(loop);
}).catch(function(err) {
doneLoading.reject(err);
});
};
// do tha damn thing
loop();
return doneLoading.promise;
} | [
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"_executePromise",
")",
"return",
"this",
".",
"_executePromise",
";",
"var",
"q",
"=",
"this",
".",
"clone",
"(",
")",
";",
"var",
"table",
"=",
"q",
".",
"_T",
".",
"__name__",
";",
"var",
"page",
"=",
"q",
".",
"_page",
";",
"var",
"fields",
"=",
"q",
".",
"_fields",
";",
"var",
"query",
"=",
"{",
"}",
";",
"_",
"(",
"q",
".",
"_where",
".",
"concat",
"(",
"q",
".",
"_like",
")",
")",
".",
"each",
"(",
"function",
"(",
"q",
")",
"{",
"query",
"[",
"q",
".",
"key",
"]",
"=",
"q",
".",
"value",
";",
"}",
")",
";",
"var",
"doneLoading",
"=",
"Q",
".",
"defer",
"(",
")",
";",
"this",
".",
"_executePromise",
"=",
"doneLoading",
".",
"promise",
";",
"var",
"left",
"=",
"q",
".",
"_take",
";",
"var",
"loop",
"=",
"function",
"(",
")",
"{",
"var",
"take",
"=",
"left",
"<",
"1000",
"?",
"left",
":",
"1000",
";",
"q",
".",
"_fetch",
"(",
"table",
",",
"take",
",",
"page",
"++",
",",
"query",
",",
"fields",
")",
".",
"then",
"(",
"function",
"(",
"res",
")",
"{",
"doneLoading",
".",
"notify",
"(",
"q",
".",
"_results",
".",
"length",
")",
";",
"if",
"(",
"left",
"!==",
"undefined",
")",
"left",
"-=",
"res",
".",
"length",
";",
"if",
"(",
"q",
".",
"_doneLoading",
"||",
"left",
"<=",
"0",
")",
"doneLoading",
".",
"resolve",
"(",
"q",
".",
"_getResults",
"(",
")",
")",
";",
"else",
"process",
".",
"nextTick",
"(",
"loop",
")",
";",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"err",
")",
"{",
"doneLoading",
".",
"reject",
"(",
"err",
")",
";",
"}",
")",
";",
"}",
";",
"loop",
"(",
")",
";",
"return",
"doneLoading",
".",
"promise",
";",
"}"
] | Actually hit the API. Returns a promise for the eventual value of these results. Ends up mutating the query and marking it as done If we already have a promise, return that, meaning that it can only be eecuted once | [
"Actually",
"hit",
"the",
"API",
".",
"Returns",
"a",
"promise",
"for",
"the",
"eventual",
"value",
"of",
"these",
"results",
".",
"Ends",
"up",
"mutating",
"the",
"query",
"and",
"marking",
"it",
"as",
"done",
"If",
"we",
"already",
"have",
"a",
"promise",
"return",
"that",
"meaning",
"that",
"it",
"can",
"only",
"be",
"eecuted",
"once"
] | 883955e23b6f6102db24209ed81a85fb0be596b6 | https://github.com/bvalosek/infusionsoft-api/blob/883955e23b6f6102db24209ed81a85fb0be596b6/lib/Queryable.js#L260-L313 | train |
|
bvalosek/infusionsoft-api | lib/Queryable.js | function(table, limit, page, query, fields)
{
if (this._doneLoading)
return;
var _this = this;
// Execute -- add orderBy and ascending?
var args = [table, limit, page, query, fields];
if (this._orderBy) {
args.push(this._orderBy);
args.push(this._ascending);
}
var p = this.dataService.query.apply(this.dataService.query, args)
// Pack results back into <T> and add it to our _results array
.then(function(results) {
results.forEach(function(r) {
var obj = new _this._T();
_(r).each(function(value, key) {
obj[key] = value;
});
_this._results.push(obj);
});
// If we hit the last page
if (results.length !== limit)
_this._doneLoading = true;
return _this._results;
});
return p;
} | javascript | function(table, limit, page, query, fields)
{
if (this._doneLoading)
return;
var _this = this;
// Execute -- add orderBy and ascending?
var args = [table, limit, page, query, fields];
if (this._orderBy) {
args.push(this._orderBy);
args.push(this._ascending);
}
var p = this.dataService.query.apply(this.dataService.query, args)
// Pack results back into <T> and add it to our _results array
.then(function(results) {
results.forEach(function(r) {
var obj = new _this._T();
_(r).each(function(value, key) {
obj[key] = value;
});
_this._results.push(obj);
});
// If we hit the last page
if (results.length !== limit)
_this._doneLoading = true;
return _this._results;
});
return p;
} | [
"function",
"(",
"table",
",",
"limit",
",",
"page",
",",
"query",
",",
"fields",
")",
"{",
"if",
"(",
"this",
".",
"_doneLoading",
")",
"return",
";",
"var",
"_this",
"=",
"this",
";",
"var",
"args",
"=",
"[",
"table",
",",
"limit",
",",
"page",
",",
"query",
",",
"fields",
"]",
";",
"if",
"(",
"this",
".",
"_orderBy",
")",
"{",
"args",
".",
"push",
"(",
"this",
".",
"_orderBy",
")",
";",
"args",
".",
"push",
"(",
"this",
".",
"_ascending",
")",
";",
"}",
"var",
"p",
"=",
"this",
".",
"dataService",
".",
"query",
".",
"apply",
"(",
"this",
".",
"dataService",
".",
"query",
",",
"args",
")",
".",
"then",
"(",
"function",
"(",
"results",
")",
"{",
"results",
".",
"forEach",
"(",
"function",
"(",
"r",
")",
"{",
"var",
"obj",
"=",
"new",
"_this",
".",
"_T",
"(",
")",
";",
"_",
"(",
"r",
")",
".",
"each",
"(",
"function",
"(",
"value",
",",
"key",
")",
"{",
"obj",
"[",
"key",
"]",
"=",
"value",
";",
"}",
")",
";",
"_this",
".",
"_results",
".",
"push",
"(",
"obj",
")",
";",
"}",
")",
";",
"if",
"(",
"results",
".",
"length",
"!==",
"limit",
")",
"_this",
".",
"_doneLoading",
"=",
"true",
";",
"return",
"_this",
".",
"_results",
";",
"}",
")",
";",
"return",
"p",
";",
"}"
] | Where the actual API call is fired off. Returns a promise for the eventual raw value from the API call | [
"Where",
"the",
"actual",
"API",
"call",
"is",
"fired",
"off",
".",
"Returns",
"a",
"promise",
"for",
"the",
"eventual",
"raw",
"value",
"from",
"the",
"API",
"call"
] | 883955e23b6f6102db24209ed81a85fb0be596b6 | https://github.com/bvalosek/infusionsoft-api/blob/883955e23b6f6102db24209ed81a85fb0be596b6/lib/Queryable.js#L317-L351 | train |
|
bvalosek/infusionsoft-api | infusionsoft/services/IAPIEmailService.js | function(apiKey, pieceTitle, categories,
fromAddress, toAddress, ccAddress, bccAddress, subject, textBody,
htmlBody, contentType, mergeContext) {} | javascript | function(apiKey, pieceTitle, categories,
fromAddress, toAddress, ccAddress, bccAddress, subject, textBody,
htmlBody, contentType, mergeContext) {} | [
"function",
"(",
"apiKey",
",",
"pieceTitle",
",",
"categories",
",",
"fromAddress",
",",
"toAddress",
",",
"ccAddress",
",",
"bccAddress",
",",
"subject",
",",
"textBody",
",",
"htmlBody",
",",
"contentType",
",",
"mergeContext",
")",
"{",
"}"
] | Create a new email template that can be used for future emails | [
"Create",
"a",
"new",
"email",
"template",
"that",
"can",
"be",
"used",
"for",
"future",
"emails"
] | 883955e23b6f6102db24209ed81a85fb0be596b6 | https://github.com/bvalosek/infusionsoft-api/blob/883955e23b6f6102db24209ed81a85fb0be596b6/infusionsoft/services/IAPIEmailService.js#L13-L15 | train |
|
bvalosek/infusionsoft-api | infusionsoft/services/IAPIEmailService.js | function(apiKey, contactId, fromName,
fromAddress, toAddress, ccAddresses, bccAddresses, contentType,
subject, htmlBody, textBody, header, receivedDate, sentDate,
emailSentType) {} | javascript | function(apiKey, contactId, fromName,
fromAddress, toAddress, ccAddresses, bccAddresses, contentType,
subject, htmlBody, textBody, header, receivedDate, sentDate,
emailSentType) {} | [
"function",
"(",
"apiKey",
",",
"contactId",
",",
"fromName",
",",
"fromAddress",
",",
"toAddress",
",",
"ccAddresses",
",",
"bccAddresses",
",",
"contentType",
",",
"subject",
",",
"htmlBody",
",",
"textBody",
",",
"header",
",",
"receivedDate",
",",
"sentDate",
",",
"emailSentType",
")",
"{",
"}"
] | This will create an item in the email history for a contact. This does not actually send the email, it only places an item into the email history. Using the API to instruct Infusionsoft to send an email will handle this automatically. | [
"This",
"will",
"create",
"an",
"item",
"in",
"the",
"email",
"history",
"for",
"a",
"contact",
".",
"This",
"does",
"not",
"actually",
"send",
"the",
"email",
"it",
"only",
"places",
"an",
"item",
"into",
"the",
"email",
"history",
".",
"Using",
"the",
"API",
"to",
"instruct",
"Infusionsoft",
"to",
"send",
"an",
"email",
"will",
"handle",
"this",
"automatically",
"."
] | 883955e23b6f6102db24209ed81a85fb0be596b6 | https://github.com/bvalosek/infusionsoft-api/blob/883955e23b6f6102db24209ed81a85fb0be596b6/infusionsoft/services/IAPIEmailService.js#L21-L24 | train |
|
bvalosek/infusionsoft-api | infusionsoft/services/IAPIEmailService.js | function(apiKey, contactList, fromAddress,
toAddress, ccAddresses, bccAddresses, contentType, subject, htmlBody,
textBody, _templateId) {} | javascript | function(apiKey, contactList, fromAddress,
toAddress, ccAddresses, bccAddresses, contentType, subject, htmlBody,
textBody, _templateId) {} | [
"function",
"(",
"apiKey",
",",
"contactList",
",",
"fromAddress",
",",
"toAddress",
",",
"ccAddresses",
",",
"bccAddresses",
",",
"contentType",
",",
"subject",
",",
"htmlBody",
",",
"textBody",
",",
"_templateId",
")",
"{",
"}"
] | This will send an email to a list of contacts, as well as record the email in the contacts' email history | [
"This",
"will",
"send",
"an",
"email",
"to",
"a",
"list",
"of",
"contacts",
"as",
"well",
"as",
"record",
"the",
"email",
"in",
"the",
"contacts",
"email",
"history"
] | 883955e23b6f6102db24209ed81a85fb0be596b6 | https://github.com/bvalosek/infusionsoft-api/blob/883955e23b6f6102db24209ed81a85fb0be596b6/infusionsoft/services/IAPIEmailService.js#L45-L47 | train |
|
bvalosek/infusionsoft-api | infusionsoft/services/IAPIEmailService.js | function(apiKey, templateId, pieceTitle,
category, fromAddress, toAddress, ccAddress, bccAddresses, subject,
textBody, htmlBody, contentType, mergeContext) {} | javascript | function(apiKey, templateId, pieceTitle,
category, fromAddress, toAddress, ccAddress, bccAddresses, subject,
textBody, htmlBody, contentType, mergeContext) {} | [
"function",
"(",
"apiKey",
",",
"templateId",
",",
"pieceTitle",
",",
"category",
",",
"fromAddress",
",",
"toAddress",
",",
"ccAddress",
",",
"bccAddresses",
",",
"subject",
",",
"textBody",
",",
"htmlBody",
",",
"contentType",
",",
"mergeContext",
")",
"{",
"}"
] | This method is used to update an already existing email template | [
"This",
"method",
"is",
"used",
"to",
"update",
"an",
"already",
"existing",
"email",
"template"
] | 883955e23b6f6102db24209ed81a85fb0be596b6 | https://github.com/bvalosek/infusionsoft-api/blob/883955e23b6f6102db24209ed81a85fb0be596b6/infusionsoft/services/IAPIEmailService.js#L54-L56 | train |
|
topaxi/postcss-selector-namespace | lib/plugin.js | parentIsAllowedAtRule | function parentIsAllowedAtRule(rule) {
return (
rule.parent &&
rule.parent.type === 'atrule' &&
!/(?:media|supports|for)$/.test(rule.parent.name)
)
} | javascript | function parentIsAllowedAtRule(rule) {
return (
rule.parent &&
rule.parent.type === 'atrule' &&
!/(?:media|supports|for)$/.test(rule.parent.name)
)
} | [
"function",
"parentIsAllowedAtRule",
"(",
"rule",
")",
"{",
"return",
"(",
"rule",
".",
"parent",
"&&",
"rule",
".",
"parent",
".",
"type",
"===",
"'atrule'",
"&&",
"!",
"/",
"(?:media|supports|for)$",
"/",
".",
"test",
"(",
"rule",
".",
"parent",
".",
"name",
")",
")",
"}"
] | Returns true if the parent rule is a not a media or supports atrule
@param {Rule} rule The rule to check
@return {boolean} true if the direct parent is a keyframe rule | [
"Returns",
"true",
"if",
"the",
"parent",
"rule",
"is",
"a",
"not",
"a",
"media",
"or",
"supports",
"atrule"
] | 96e02400bd2771c7559621af597f9e1de31c5981 | https://github.com/topaxi/postcss-selector-namespace/blob/96e02400bd2771c7559621af597f9e1de31c5981/lib/plugin.js#L85-L91 | train |
topaxi/postcss-selector-namespace | lib/plugin.js | hasParentRule | function hasParentRule(rule) {
if (!rule.parent) {
return false
}
if (rule.parent.type === 'rule') {
return true
}
return hasParentRule(rule.parent)
} | javascript | function hasParentRule(rule) {
if (!rule.parent) {
return false
}
if (rule.parent.type === 'rule') {
return true
}
return hasParentRule(rule.parent)
} | [
"function",
"hasParentRule",
"(",
"rule",
")",
"{",
"if",
"(",
"!",
"rule",
".",
"parent",
")",
"{",
"return",
"false",
"}",
"if",
"(",
"rule",
".",
"parent",
".",
"type",
"===",
"'rule'",
")",
"{",
"return",
"true",
"}",
"return",
"hasParentRule",
"(",
"rule",
".",
"parent",
")",
"}"
] | Returns true if any parent rule is of type 'rule'
@param {Rule} rule The rule to check
@return {boolean} true if any parent rule is of type 'rule' else false | [
"Returns",
"true",
"if",
"any",
"parent",
"rule",
"is",
"of",
"type",
"rule"
] | 96e02400bd2771c7559621af597f9e1de31c5981 | https://github.com/topaxi/postcss-selector-namespace/blob/96e02400bd2771c7559621af597f9e1de31c5981/lib/plugin.js#L99-L109 | train |
topaxi/postcss-selector-namespace | lib/plugin.js | regexpToGlobalRegexp | function regexpToGlobalRegexp(regexp) {
let source = regexp instanceof RegExp ? regexp.source : regexp
return new RegExp(source, 'g')
} | javascript | function regexpToGlobalRegexp(regexp) {
let source = regexp instanceof RegExp ? regexp.source : regexp
return new RegExp(source, 'g')
} | [
"function",
"regexpToGlobalRegexp",
"(",
"regexp",
")",
"{",
"let",
"source",
"=",
"regexp",
"instanceof",
"RegExp",
"?",
"regexp",
".",
"source",
":",
"regexp",
"return",
"new",
"RegExp",
"(",
"source",
",",
"'g'",
")",
"}"
] | Newer javascript engines allow setting flags when passing existing regexp
to the RegExp constructor, until then, we extract the regexp source and
build a new object.
@param {RegExp|string} regexp The regexp to modify
@return {RegExp} The new regexp instance | [
"Newer",
"javascript",
"engines",
"allow",
"setting",
"flags",
"when",
"passing",
"existing",
"regexp",
"to",
"the",
"RegExp",
"constructor",
"until",
"then",
"we",
"extract",
"the",
"regexp",
"source",
"and",
"build",
"a",
"new",
"object",
"."
] | 96e02400bd2771c7559621af597f9e1de31c5981 | https://github.com/topaxi/postcss-selector-namespace/blob/96e02400bd2771c7559621af597f9e1de31c5981/lib/plugin.js#L119-L123 | train |
alphagov/govuk_frontend_toolkit_npm | javascripts/govuk/show-hide-content.js | init | function init ($container, elementSelector, eventSelectors, handler) {
$container = $container || $(document.body)
// Handle control clicks
function deferred () {
var $control = $(this)
handler($control, getToggledContent($control))
}
// Prepare ARIA attributes
var $controls = $(elementSelector)
$controls.each(initToggledContent)
// Handle events
$.each(eventSelectors, function (idx, eventSelector) {
$container.on('click.' + selectors.namespace, eventSelector, deferred)
})
// Any already :checked on init?
if ($controls.is(':checked')) {
$controls.filter(':checked').each(deferred)
}
} | javascript | function init ($container, elementSelector, eventSelectors, handler) {
$container = $container || $(document.body)
// Handle control clicks
function deferred () {
var $control = $(this)
handler($control, getToggledContent($control))
}
// Prepare ARIA attributes
var $controls = $(elementSelector)
$controls.each(initToggledContent)
// Handle events
$.each(eventSelectors, function (idx, eventSelector) {
$container.on('click.' + selectors.namespace, eventSelector, deferred)
})
// Any already :checked on init?
if ($controls.is(':checked')) {
$controls.filter(':checked').each(deferred)
}
} | [
"function",
"init",
"(",
"$container",
",",
"elementSelector",
",",
"eventSelectors",
",",
"handler",
")",
"{",
"$container",
"=",
"$container",
"||",
"$",
"(",
"document",
".",
"body",
")",
"function",
"deferred",
"(",
")",
"{",
"var",
"$control",
"=",
"$",
"(",
"this",
")",
"handler",
"(",
"$control",
",",
"getToggledContent",
"(",
"$control",
")",
")",
"}",
"var",
"$controls",
"=",
"$",
"(",
"elementSelector",
")",
"$controls",
".",
"each",
"(",
"initToggledContent",
")",
"$",
".",
"each",
"(",
"eventSelectors",
",",
"function",
"(",
"idx",
",",
"eventSelector",
")",
"{",
"$container",
".",
"on",
"(",
"'click.'",
"+",
"selectors",
".",
"namespace",
",",
"eventSelector",
",",
"deferred",
")",
"}",
")",
"if",
"(",
"$controls",
".",
"is",
"(",
"':checked'",
")",
")",
"{",
"$controls",
".",
"filter",
"(",
"':checked'",
")",
".",
"each",
"(",
"deferred",
")",
"}",
"}"
] | Set up event handlers etc | [
"Set",
"up",
"event",
"handlers",
"etc"
] | 761632e5bed24c5106f4bdbd8cc99688d8ca616d | https://github.com/alphagov/govuk_frontend_toolkit_npm/blob/761632e5bed24c5106f4bdbd8cc99688d8ca616d/javascripts/govuk/show-hide-content.js#L102-L124 | train |
alphagov/govuk_frontend_toolkit_npm | javascripts/govuk/show-hide-content.js | getEventSelectorsForRadioGroups | function getEventSelectorsForRadioGroups () {
var radioGroups = []
// Build an array of radio group selectors
return $(selectors.radio).map(function () {
var groupName = $(this).attr('name')
if ($.inArray(groupName, radioGroups) === -1) {
radioGroups.push(groupName)
return 'input[type="radio"][name="' + $(this).attr('name') + '"]'
}
return null
})
} | javascript | function getEventSelectorsForRadioGroups () {
var radioGroups = []
// Build an array of radio group selectors
return $(selectors.radio).map(function () {
var groupName = $(this).attr('name')
if ($.inArray(groupName, radioGroups) === -1) {
radioGroups.push(groupName)
return 'input[type="radio"][name="' + $(this).attr('name') + '"]'
}
return null
})
} | [
"function",
"getEventSelectorsForRadioGroups",
"(",
")",
"{",
"var",
"radioGroups",
"=",
"[",
"]",
"return",
"$",
"(",
"selectors",
".",
"radio",
")",
".",
"map",
"(",
"function",
"(",
")",
"{",
"var",
"groupName",
"=",
"$",
"(",
"this",
")",
".",
"attr",
"(",
"'name'",
")",
"if",
"(",
"$",
".",
"inArray",
"(",
"groupName",
",",
"radioGroups",
")",
"===",
"-",
"1",
")",
"{",
"radioGroups",
".",
"push",
"(",
"groupName",
")",
"return",
"'input[type=\"radio\"][name=\"'",
"+",
"$",
"(",
"this",
")",
".",
"attr",
"(",
"'name'",
")",
"+",
"'\"]'",
"}",
"return",
"null",
"}",
")",
"}"
] | Get event selectors for all radio groups | [
"Get",
"event",
"selectors",
"for",
"all",
"radio",
"groups"
] | 761632e5bed24c5106f4bdbd8cc99688d8ca616d | https://github.com/alphagov/govuk_frontend_toolkit_npm/blob/761632e5bed24c5106f4bdbd8cc99688d8ca616d/javascripts/govuk/show-hide-content.js#L127-L140 | train |
jquense/react-layer | vendor/sinon-1.10.3.js | getIndex | function getIndex(objects, obj) {
var i;
for (i = 0; i < objects.length; i++) {
if (objects[i] === obj) {
return i;
}
}
return -1;
} | javascript | function getIndex(objects, obj) {
var i;
for (i = 0; i < objects.length; i++) {
if (objects[i] === obj) {
return i;
}
}
return -1;
} | [
"function",
"getIndex",
"(",
"objects",
",",
"obj",
")",
"{",
"var",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"objects",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"objects",
"[",
"i",
"]",
"===",
"obj",
")",
"{",
"return",
"i",
";",
"}",
"}",
"return",
"-",
"1",
";",
"}"
] | returns the index of the given object in the
given objects array, -1 if not contained
only needed for cyclic logic | [
"returns",
"the",
"index",
"of",
"the",
"given",
"object",
"in",
"the",
"given",
"objects",
"array",
"-",
"1",
"if",
"not",
"contained",
"only",
"needed",
"for",
"cyclic",
"logic"
] | 9b12a1a1af9715e39edbb67dcca0b9ef3277b461 | https://github.com/jquense/react-layer/blob/9b12a1a1af9715e39edbb67dcca0b9ef3277b461/vendor/sinon-1.10.3.js#L216-L226 | train |
bvalosek/infusionsoft-api | lib/DataContext.js | function()
{
var _this = this;
_(api.services).each(function(service, key) {
_this._addService(service);
});
} | javascript | function()
{
var _this = this;
_(api.services).each(function(service, key) {
_this._addService(service);
});
} | [
"function",
"(",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"_",
"(",
"api",
".",
"services",
")",
".",
"each",
"(",
"function",
"(",
"service",
",",
"key",
")",
"{",
"_this",
".",
"_addService",
"(",
"service",
")",
";",
"}",
")",
";",
"}"
] | Create all of the API services in this data context | [
"Create",
"all",
"of",
"the",
"API",
"services",
"in",
"this",
"data",
"context"
] | 883955e23b6f6102db24209ed81a85fb0be596b6 | https://github.com/bvalosek/infusionsoft-api/blob/883955e23b6f6102db24209ed81a85fb0be596b6/lib/DataContext.js#L31-L38 | train |
|
bvalosek/infusionsoft-api | lib/DataContext.js | function(T)
{
var tName = inflection.pluralize(T.__name__);
this[tName] = new Queryable(T, this.DataService);
} | javascript | function(T)
{
var tName = inflection.pluralize(T.__name__);
this[tName] = new Queryable(T, this.DataService);
} | [
"function",
"(",
"T",
")",
"{",
"var",
"tName",
"=",
"inflection",
".",
"pluralize",
"(",
"T",
".",
"__name__",
")",
";",
"this",
"[",
"tName",
"]",
"=",
"new",
"Queryable",
"(",
"T",
",",
"this",
".",
"DataService",
")",
";",
"}"
] | Create a queryable that can be used via data service | [
"Create",
"a",
"queryable",
"that",
"can",
"be",
"used",
"via",
"data",
"service"
] | 883955e23b6f6102db24209ed81a85fb0be596b6 | https://github.com/bvalosek/infusionsoft-api/blob/883955e23b6f6102db24209ed81a85fb0be596b6/lib/DataContext.js#L50-L54 | train |
|
bvalosek/infusionsoft-api | lib/DataContext.js | function(iface)
{
var hash = {};
var collection = iface.__name__.substring(1);
var dataContext = this;
_(typedef.signature(iface)).each(function (info, key) {
// create the function that calls method call and returns a promise
hash[key] = function() {
var args = [dataContext.apiKey].concat(_(arguments).toArray());
//http://community.infusionsoft.com/showthread.php/2140-API-vs-Web-Form?p=8853&viewfull=1#post8853
//There is an issue in the sendTemplate function, it needs to be sendEmail
if (key == 'sendTemplate') {
key = 'sendEmail';
}
var methodName = collection + '.' + key;
var d = Q.defer();
dataContext.client.methodCall(methodName, args, d.makeNodeResolver());
return d.promise;
};
});
// instantiate a version of this class
this[collection] = new (typedef.class(collection).define(hash))();
} | javascript | function(iface)
{
var hash = {};
var collection = iface.__name__.substring(1);
var dataContext = this;
_(typedef.signature(iface)).each(function (info, key) {
// create the function that calls method call and returns a promise
hash[key] = function() {
var args = [dataContext.apiKey].concat(_(arguments).toArray());
//http://community.infusionsoft.com/showthread.php/2140-API-vs-Web-Form?p=8853&viewfull=1#post8853
//There is an issue in the sendTemplate function, it needs to be sendEmail
if (key == 'sendTemplate') {
key = 'sendEmail';
}
var methodName = collection + '.' + key;
var d = Q.defer();
dataContext.client.methodCall(methodName, args, d.makeNodeResolver());
return d.promise;
};
});
// instantiate a version of this class
this[collection] = new (typedef.class(collection).define(hash))();
} | [
"function",
"(",
"iface",
")",
"{",
"var",
"hash",
"=",
"{",
"}",
";",
"var",
"collection",
"=",
"iface",
".",
"__name__",
".",
"substring",
"(",
"1",
")",
";",
"var",
"dataContext",
"=",
"this",
";",
"_",
"(",
"typedef",
".",
"signature",
"(",
"iface",
")",
")",
".",
"each",
"(",
"function",
"(",
"info",
",",
"key",
")",
"{",
"hash",
"[",
"key",
"]",
"=",
"function",
"(",
")",
"{",
"var",
"args",
"=",
"[",
"dataContext",
".",
"apiKey",
"]",
".",
"concat",
"(",
"_",
"(",
"arguments",
")",
".",
"toArray",
"(",
")",
")",
";",
"if",
"(",
"key",
"==",
"'sendTemplate'",
")",
"{",
"key",
"=",
"'sendEmail'",
";",
"}",
"var",
"methodName",
"=",
"collection",
"+",
"'.'",
"+",
"key",
";",
"var",
"d",
"=",
"Q",
".",
"defer",
"(",
")",
";",
"dataContext",
".",
"client",
".",
"methodCall",
"(",
"methodName",
",",
"args",
",",
"d",
".",
"makeNodeResolver",
"(",
")",
")",
";",
"return",
"d",
".",
"promise",
";",
"}",
";",
"}",
")",
";",
"this",
"[",
"collection",
"]",
"=",
"new",
"(",
"typedef",
".",
"class",
"(",
"collection",
")",
".",
"define",
"(",
"hash",
")",
")",
"(",
")",
";",
"}"
] | Given an interface, create and instantiate a class that let's us call all of the methods | [
"Given",
"an",
"interface",
"create",
"and",
"instantiate",
"a",
"class",
"that",
"let",
"s",
"us",
"call",
"all",
"of",
"the",
"methods"
] | 883955e23b6f6102db24209ed81a85fb0be596b6 | https://github.com/bvalosek/infusionsoft-api/blob/883955e23b6f6102db24209ed81a85fb0be596b6/lib/DataContext.js#L58-L85 | train |
|
deployd/dpd-dashboard | dashboard/js/lib/ui.js | Dialog | function Dialog(options) {
ui.Emitter.call(this);
options = options || {};
this.template = html;
this.el = $(this.template);
this.render(options);
if (active && !active.hiding) active.hide();
if (Dialog.effect) this.effect(Dialog.effect);
active = this;
} | javascript | function Dialog(options) {
ui.Emitter.call(this);
options = options || {};
this.template = html;
this.el = $(this.template);
this.render(options);
if (active && !active.hiding) active.hide();
if (Dialog.effect) this.effect(Dialog.effect);
active = this;
} | [
"function",
"Dialog",
"(",
"options",
")",
"{",
"ui",
".",
"Emitter",
".",
"call",
"(",
"this",
")",
";",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"this",
".",
"template",
"=",
"html",
";",
"this",
".",
"el",
"=",
"$",
"(",
"this",
".",
"template",
")",
";",
"this",
".",
"render",
"(",
"options",
")",
";",
"if",
"(",
"active",
"&&",
"!",
"active",
".",
"hiding",
")",
"active",
".",
"hide",
"(",
")",
";",
"if",
"(",
"Dialog",
".",
"effect",
")",
"this",
".",
"effect",
"(",
"Dialog",
".",
"effect",
")",
";",
"active",
"=",
"this",
";",
"}"
] | Initialize a new `Dialog`.
Options:
- `title` dialog title
- `message` a message to display
Emits:
- `show` when visible
- `hide` when hidden
@param {Object} options
@api public | [
"Initialize",
"a",
"new",
"Dialog",
"."
] | 1ffb4c09cbeba7bf040dfe388aa46f206292be18 | https://github.com/deployd/dpd-dashboard/blob/1ffb4c09cbeba7bf040dfe388aa46f206292be18/dashboard/js/lib/ui.js#L155-L164 | train |
deployd/dpd-dashboard | dashboard/js/lib/ui.js | ColorPicker | function ColorPicker() {
ui.Emitter.call(this);
this._colorPos = {};
this.el = $(html);
this.main = this.el.find('.main').get(0);
this.spectrum = this.el.find('.spectrum').get(0);
$(this.main).bind('selectstart', function(e){ e.preventDefault() });
$(this.spectrum).bind('selectstart', function(e){ e.preventDefault() });
this.hue(rgb(255, 0, 0));
this.spectrumEvents();
this.mainEvents();
this.w = 180;
this.h = 180;
this.render();
} | javascript | function ColorPicker() {
ui.Emitter.call(this);
this._colorPos = {};
this.el = $(html);
this.main = this.el.find('.main').get(0);
this.spectrum = this.el.find('.spectrum').get(0);
$(this.main).bind('selectstart', function(e){ e.preventDefault() });
$(this.spectrum).bind('selectstart', function(e){ e.preventDefault() });
this.hue(rgb(255, 0, 0));
this.spectrumEvents();
this.mainEvents();
this.w = 180;
this.h = 180;
this.render();
} | [
"function",
"ColorPicker",
"(",
")",
"{",
"ui",
".",
"Emitter",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"_colorPos",
"=",
"{",
"}",
";",
"this",
".",
"el",
"=",
"$",
"(",
"html",
")",
";",
"this",
".",
"main",
"=",
"this",
".",
"el",
".",
"find",
"(",
"'.main'",
")",
".",
"get",
"(",
"0",
")",
";",
"this",
".",
"spectrum",
"=",
"this",
".",
"el",
".",
"find",
"(",
"'.spectrum'",
")",
".",
"get",
"(",
"0",
")",
";",
"$",
"(",
"this",
".",
"main",
")",
".",
"bind",
"(",
"'selectstart'",
",",
"function",
"(",
"e",
")",
"{",
"e",
".",
"preventDefault",
"(",
")",
"}",
")",
";",
"$",
"(",
"this",
".",
"spectrum",
")",
".",
"bind",
"(",
"'selectstart'",
",",
"function",
"(",
"e",
")",
"{",
"e",
".",
"preventDefault",
"(",
")",
"}",
")",
";",
"this",
".",
"hue",
"(",
"rgb",
"(",
"255",
",",
"0",
",",
"0",
")",
")",
";",
"this",
".",
"spectrumEvents",
"(",
")",
";",
"this",
".",
"mainEvents",
"(",
")",
";",
"this",
".",
"w",
"=",
"180",
";",
"this",
".",
"h",
"=",
"180",
";",
"this",
".",
"render",
"(",
")",
";",
"}"
] | Initialize a new `ColorPicker`.
Emits:
- `change` with the given color object
@api public | [
"Initialize",
"a",
"new",
"ColorPicker",
"."
] | 1ffb4c09cbeba7bf040dfe388aa46f206292be18 | https://github.com/deployd/dpd-dashboard/blob/1ffb4c09cbeba7bf040dfe388aa46f206292be18/dashboard/js/lib/ui.js#L624-L638 | train |
deployd/dpd-dashboard | dashboard/js/lib/ui.js | type | function type(type) {
return function(title, msg){
return exports.notify.apply(this, arguments)
.type(type);
}
} | javascript | function type(type) {
return function(title, msg){
return exports.notify.apply(this, arguments)
.type(type);
}
} | [
"function",
"type",
"(",
"type",
")",
"{",
"return",
"function",
"(",
"title",
",",
"msg",
")",
"{",
"return",
"exports",
".",
"notify",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
".",
"type",
"(",
"type",
")",
";",
"}",
"}"
] | Construct a notification function for `type`.
@param {String} type
@return {Function}
@api private | [
"Construct",
"a",
"notification",
"function",
"for",
"type",
"."
] | 1ffb4c09cbeba7bf040dfe388aa46f206292be18 | https://github.com/deployd/dpd-dashboard/blob/1ffb4c09cbeba7bf040dfe388aa46f206292be18/dashboard/js/lib/ui.js#L983-L988 | train |
deployd/dpd-dashboard | dashboard/js/lib/ui.js | Notification | function Notification(options) {
ui.Emitter.call(this);
options = options || {};
this.template = html;
this.el = $(this.template);
this.render(options);
if (Notification.effect) this.effect(Notification.effect);
} | javascript | function Notification(options) {
ui.Emitter.call(this);
options = options || {};
this.template = html;
this.el = $(this.template);
this.render(options);
if (Notification.effect) this.effect(Notification.effect);
} | [
"function",
"Notification",
"(",
"options",
")",
"{",
"ui",
".",
"Emitter",
".",
"call",
"(",
"this",
")",
";",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"this",
".",
"template",
"=",
"html",
";",
"this",
".",
"el",
"=",
"$",
"(",
"this",
".",
"template",
")",
";",
"this",
".",
"render",
"(",
"options",
")",
";",
"if",
"(",
"Notification",
".",
"effect",
")",
"this",
".",
"effect",
"(",
"Notification",
".",
"effect",
")",
";",
"}"
] | Initialize a new `Notification`.
Options:
- `title` dialog title
- `message` a message to display
@param {Object} options
@api public | [
"Initialize",
"a",
"new",
"Notification",
"."
] | 1ffb4c09cbeba7bf040dfe388aa46f206292be18 | https://github.com/deployd/dpd-dashboard/blob/1ffb4c09cbeba7bf040dfe388aa46f206292be18/dashboard/js/lib/ui.js#L1010-L1017 | train |
deployd/dpd-dashboard | dashboard/js/lib/ui.js | SplitButton | function SplitButton(label) {
ui.Emitter.call(this);
this.el = $(html);
this.events();
this.render({ label: label });
this.state = 'hidden';
} | javascript | function SplitButton(label) {
ui.Emitter.call(this);
this.el = $(html);
this.events();
this.render({ label: label });
this.state = 'hidden';
} | [
"function",
"SplitButton",
"(",
"label",
")",
"{",
"ui",
".",
"Emitter",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"el",
"=",
"$",
"(",
"html",
")",
";",
"this",
".",
"events",
"(",
")",
";",
"this",
".",
"render",
"(",
"{",
"label",
":",
"label",
"}",
")",
";",
"this",
".",
"state",
"=",
"'hidden'",
";",
"}"
] | Initialize a new `SplitButton`
with an optional `label`.
@param {String} label
@api public | [
"Initialize",
"a",
"new",
"SplitButton",
"with",
"an",
"optional",
"label",
"."
] | 1ffb4c09cbeba7bf040dfe388aa46f206292be18 | https://github.com/deployd/dpd-dashboard/blob/1ffb4c09cbeba7bf040dfe388aa46f206292be18/dashboard/js/lib/ui.js#L1189-L1195 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.