id int32 0 58k | repo stringlengths 5 67 | path stringlengths 4 116 | func_name stringlengths 0 58 | original_string stringlengths 52 373k | language stringclasses 1 value | code stringlengths 52 373k | code_tokens list | docstring stringlengths 4 11.8k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 86 226 |
|---|---|---|---|---|---|---|---|---|---|---|---|
21,200 | cheminfo-js/netcdfjs | src/types.js | readType | function readType(buffer, type, size) {
switch (type) {
case types.BYTE:
return buffer.readBytes(size);
case types.CHAR:
return trimNull(buffer.readChars(size));
case types.SHORT:
return readNumber(size, buffer.readInt16.bind(buffer));
case types.INT:
return readNumber(size, buffer.readInt32.bind(buffer));
case types.FLOAT:
return readNumber(size, buffer.readFloat32.bind(buffer));
case types.DOUBLE:
return readNumber(size, buffer.readFloat64.bind(buffer));
/* istanbul ignore next */
default:
notNetcdf(true, `non valid type ${type}`);
return undefined;
}
} | javascript | function readType(buffer, type, size) {
switch (type) {
case types.BYTE:
return buffer.readBytes(size);
case types.CHAR:
return trimNull(buffer.readChars(size));
case types.SHORT:
return readNumber(size, buffer.readInt16.bind(buffer));
case types.INT:
return readNumber(size, buffer.readInt32.bind(buffer));
case types.FLOAT:
return readNumber(size, buffer.readFloat32.bind(buffer));
case types.DOUBLE:
return readNumber(size, buffer.readFloat64.bind(buffer));
/* istanbul ignore next */
default:
notNetcdf(true, `non valid type ${type}`);
return undefined;
}
} | [
"function",
"readType",
"(",
"buffer",
",",
"type",
",",
"size",
")",
"{",
"switch",
"(",
"type",
")",
"{",
"case",
"types",
".",
"BYTE",
":",
"return",
"buffer",
".",
"readBytes",
"(",
"size",
")",
";",
"case",
"types",
".",
"CHAR",
":",
"return",
"trimNull",
"(",
"buffer",
".",
"readChars",
"(",
"size",
")",
")",
";",
"case",
"types",
".",
"SHORT",
":",
"return",
"readNumber",
"(",
"size",
",",
"buffer",
".",
"readInt16",
".",
"bind",
"(",
"buffer",
")",
")",
";",
"case",
"types",
".",
"INT",
":",
"return",
"readNumber",
"(",
"size",
",",
"buffer",
".",
"readInt32",
".",
"bind",
"(",
"buffer",
")",
")",
";",
"case",
"types",
".",
"FLOAT",
":",
"return",
"readNumber",
"(",
"size",
",",
"buffer",
".",
"readFloat32",
".",
"bind",
"(",
"buffer",
")",
")",
";",
"case",
"types",
".",
"DOUBLE",
":",
"return",
"readNumber",
"(",
"size",
",",
"buffer",
".",
"readFloat64",
".",
"bind",
"(",
"buffer",
")",
")",
";",
"/* istanbul ignore next */",
"default",
":",
"notNetcdf",
"(",
"true",
",",
"`",
"${",
"type",
"}",
"`",
")",
";",
"return",
"undefined",
";",
"}",
"}"
] | Given a type and a size reads the next element
@ignore
@param {IOBuffer} buffer - Buffer for the file data
@param {number} type - Type of the data to read
@param {number} size - Size of the element to read
@return {string|Array<number>|number} | [
"Given",
"a",
"type",
"and",
"a",
"size",
"reads",
"the",
"next",
"element"
] | ac528ad0fa6b78de001c3fe86eebb2728d1d27e4 | https://github.com/cheminfo-js/netcdfjs/blob/ac528ad0fa6b78de001c3fe86eebb2728d1d27e4/src/types.js#L119-L138 |
21,201 | cheminfo-js/netcdfjs | src/types.js | trimNull | function trimNull(value) {
if (value.charCodeAt(value.length - 1) === 0) {
return value.substring(0, value.length - 1);
}
return value;
} | javascript | function trimNull(value) {
if (value.charCodeAt(value.length - 1) === 0) {
return value.substring(0, value.length - 1);
}
return value;
} | [
"function",
"trimNull",
"(",
"value",
")",
"{",
"if",
"(",
"value",
".",
"charCodeAt",
"(",
"value",
".",
"length",
"-",
"1",
")",
"===",
"0",
")",
"{",
"return",
"value",
".",
"substring",
"(",
"0",
",",
"value",
".",
"length",
"-",
"1",
")",
";",
"}",
"return",
"value",
";",
"}"
] | Removes null terminate value
@ignore
@param {string} value - String to trim
@return {string} - Trimmed string | [
"Removes",
"null",
"terminate",
"value"
] | ac528ad0fa6b78de001c3fe86eebb2728d1d27e4 | https://github.com/cheminfo-js/netcdfjs/blob/ac528ad0fa6b78de001c3fe86eebb2728d1d27e4/src/types.js#L146-L151 |
21,202 | cheminfo-js/netcdfjs | src/utils.js | readName | function readName(buffer) {
// Read name
var nameLength = buffer.readUint32();
var name = buffer.readChars(nameLength);
// validate name
// TODO
// Apply padding
padding(buffer);
return name;
} | javascript | function readName(buffer) {
// Read name
var nameLength = buffer.readUint32();
var name = buffer.readChars(nameLength);
// validate name
// TODO
// Apply padding
padding(buffer);
return name;
} | [
"function",
"readName",
"(",
"buffer",
")",
"{",
"// Read name",
"var",
"nameLength",
"=",
"buffer",
".",
"readUint32",
"(",
")",
";",
"var",
"name",
"=",
"buffer",
".",
"readChars",
"(",
"nameLength",
")",
";",
"// validate name",
"// TODO",
"// Apply padding",
"padding",
"(",
"buffer",
")",
";",
"return",
"name",
";",
"}"
] | Reads the name
@ignore
@param {IOBuffer} buffer - Buffer for the file data
@return {string} - Name | [
"Reads",
"the",
"name"
] | ac528ad0fa6b78de001c3fe86eebb2728d1d27e4 | https://github.com/cheminfo-js/netcdfjs/blob/ac528ad0fa6b78de001c3fe86eebb2728d1d27e4/src/utils.js#L33-L44 |
21,203 | demimonde/exif2css | build/index.js | exif2css | function exif2css(orientation) {
const s = `${orientation}`
const transforms = transformsMap[s]
const transform = expandTransform(transforms)
const transformOrigin = transformOriginMap[s]
const allTransforms = expandTransforms(transforms)
const allTransformStrings = expandTransformStrings(transforms)
const css = {}
if (transform) {
css['transform'] = transform
}
if (transformOrigin) {
css['transform-origin'] = transformOrigin
}
if (allTransforms) {
css['transforms'] = allTransforms
}
if (allTransformStrings) {
css['transformStrings'] = allTransformStrings
}
return css
} | javascript | function exif2css(orientation) {
const s = `${orientation}`
const transforms = transformsMap[s]
const transform = expandTransform(transforms)
const transformOrigin = transformOriginMap[s]
const allTransforms = expandTransforms(transforms)
const allTransformStrings = expandTransformStrings(transforms)
const css = {}
if (transform) {
css['transform'] = transform
}
if (transformOrigin) {
css['transform-origin'] = transformOrigin
}
if (allTransforms) {
css['transforms'] = allTransforms
}
if (allTransformStrings) {
css['transformStrings'] = allTransformStrings
}
return css
} | [
"function",
"exif2css",
"(",
"orientation",
")",
"{",
"const",
"s",
"=",
"`",
"${",
"orientation",
"}",
"`",
"const",
"transforms",
"=",
"transformsMap",
"[",
"s",
"]",
"const",
"transform",
"=",
"expandTransform",
"(",
"transforms",
")",
"const",
"transformOrigin",
"=",
"transformOriginMap",
"[",
"s",
"]",
"const",
"allTransforms",
"=",
"expandTransforms",
"(",
"transforms",
")",
"const",
"allTransformStrings",
"=",
"expandTransformStrings",
"(",
"transforms",
")",
"const",
"css",
"=",
"{",
"}",
"if",
"(",
"transform",
")",
"{",
"css",
"[",
"'transform'",
"]",
"=",
"transform",
"}",
"if",
"(",
"transformOrigin",
")",
"{",
"css",
"[",
"'transform-origin'",
"]",
"=",
"transformOrigin",
"}",
"if",
"(",
"allTransforms",
")",
"{",
"css",
"[",
"'transforms'",
"]",
"=",
"allTransforms",
"}",
"if",
"(",
"allTransformStrings",
")",
"{",
"css",
"[",
"'transformStrings'",
"]",
"=",
"allTransformStrings",
"}",
"return",
"css",
"}"
] | Takes the input EXIF orientation and returns the CSS rules needed to display the image correctly in the browser.
@param {(number|string)} orientation The EXIF orientation.
@returns {Exif2CssReturn} An object with `transform`, `transform-origin` (not shown in JSDoc because of hyphen), `transforms` and `transformStrings` properties. | [
"Takes",
"the",
"input",
"EXIF",
"orientation",
"and",
"returns",
"the",
"CSS",
"rules",
"needed",
"to",
"display",
"the",
"image",
"correctly",
"in",
"the",
"browser",
"."
] | 917f33f4a6853d48c62aceb8da0691c9db480d94 | https://github.com/demimonde/exif2css/blob/917f33f4a6853d48c62aceb8da0691c9db480d94/build/index.js#L91-L114 |
21,204 | seglo/connect-prism | lib/services/mock-filename-generator.js | defaultMockFilename | function defaultMockFilename(config, req) {
var reqData = prismUtils.filterUrl(config, req.url);
// include request body in hash
if (config.hashFullRequest(config, req)) {
reqData = req.body + reqData;
}
var shasum = crypto.createHash('sha1');
shasum.update(reqData);
return shasum.digest('hex') + '.json';
} | javascript | function defaultMockFilename(config, req) {
var reqData = prismUtils.filterUrl(config, req.url);
// include request body in hash
if (config.hashFullRequest(config, req)) {
reqData = req.body + reqData;
}
var shasum = crypto.createHash('sha1');
shasum.update(reqData);
return shasum.digest('hex') + '.json';
} | [
"function",
"defaultMockFilename",
"(",
"config",
",",
"req",
")",
"{",
"var",
"reqData",
"=",
"prismUtils",
".",
"filterUrl",
"(",
"config",
",",
"req",
".",
"url",
")",
";",
"// include request body in hash",
"if",
"(",
"config",
".",
"hashFullRequest",
"(",
"config",
",",
"req",
")",
")",
"{",
"reqData",
"=",
"req",
".",
"body",
"+",
"reqData",
";",
"}",
"var",
"shasum",
"=",
"crypto",
".",
"createHash",
"(",
"'sha1'",
")",
";",
"shasum",
".",
"update",
"(",
"reqData",
")",
";",
"return",
"shasum",
".",
"digest",
"(",
"'hex'",
")",
"+",
"'.json'",
";",
"}"
] | This is the default implementation to generate a filename for the recorded
responses. It will create a sha1 hash of the request URL and optionally,
the body of the request if the `hashFullRequest` config is set to true.
This function can be overidden in config with the responseFilenameCallback
setting. | [
"This",
"is",
"the",
"default",
"implementation",
"to",
"generate",
"a",
"filename",
"for",
"the",
"recorded",
"responses",
".",
"It",
"will",
"create",
"a",
"sha1",
"hash",
"of",
"the",
"request",
"URL",
"and",
"optionally",
"the",
"body",
"of",
"the",
"request",
"if",
"the",
"hashFullRequest",
"config",
"is",
"set",
"to",
"true",
".",
"This",
"function",
"can",
"be",
"overidden",
"in",
"config",
"with",
"the",
"responseFilenameCallback",
"setting",
"."
] | bfe2e3fae556fc6ab64bdde401e27a550a628217 | https://github.com/seglo/connect-prism/blob/bfe2e3fae556fc6ab64bdde401e27a550a628217/lib/services/mock-filename-generator.js#L17-L27 |
21,205 | brisket/brisket | lib/controlling/isExternalLinkTarget.js | isExternalLinkTarget | function isExternalLinkTarget(target) {
return target === "_blank" ||
(target === "_parent" && window.parent !== window.self) ||
(target === "_top" && window.top !== window.self) ||
(typeof target === "string" && target !== "_self");
} | javascript | function isExternalLinkTarget(target) {
return target === "_blank" ||
(target === "_parent" && window.parent !== window.self) ||
(target === "_top" && window.top !== window.self) ||
(typeof target === "string" && target !== "_self");
} | [
"function",
"isExternalLinkTarget",
"(",
"target",
")",
"{",
"return",
"target",
"===",
"\"_blank\"",
"||",
"(",
"target",
"===",
"\"_parent\"",
"&&",
"window",
".",
"parent",
"!==",
"window",
".",
"self",
")",
"||",
"(",
"target",
"===",
"\"_top\"",
"&&",
"window",
".",
"top",
"!==",
"window",
".",
"self",
")",
"||",
"(",
"typeof",
"target",
"===",
"\"string\"",
"&&",
"target",
"!==",
"\"_self\"",
")",
";",
"}"
] | Determines whether the target points to a different window, and thus outside of
the current instance of the application.
@param {String} target The value of the link's target attribute.
@returns {Boolean} true when the target is:
- "_blank",
- "_parent", and the parent window isn't the current window,
- "_top", and the top window isn't the current window.
- a named window or frame (any other value besides "_self"). | [
"Determines",
"whether",
"the",
"target",
"points",
"to",
"a",
"different",
"window",
"and",
"thus",
"outside",
"of",
"the",
"current",
"instance",
"of",
"the",
"application",
"."
] | 8504d6d3957fa67bcdf60cf387b92fa1ffb45fd3 | https://github.com/brisket/brisket/blob/8504d6d3957fa67bcdf60cf387b92fa1ffb45fd3/lib/controlling/isExternalLinkTarget.js#L13-L18 |
21,206 | brisket/brisket | lib/metatags/Metatags.js | function(escape) {
var pairs = this.pairs;
var type = this.type;
var names = Object.keys(pairs);
var html = "";
var escapeHtml = escape || IDENTITY;
var name;
var computedType;
for (var i = 0, len = names.length; i < len; i++) {
name = names[i];
computedType = typeof type === "function" ? type(name) : type;
html += asHtml(computedType, name, escapeHtml(pairs[name]));
}
return html;
} | javascript | function(escape) {
var pairs = this.pairs;
var type = this.type;
var names = Object.keys(pairs);
var html = "";
var escapeHtml = escape || IDENTITY;
var name;
var computedType;
for (var i = 0, len = names.length; i < len; i++) {
name = names[i];
computedType = typeof type === "function" ? type(name) : type;
html += asHtml(computedType, name, escapeHtml(pairs[name]));
}
return html;
} | [
"function",
"(",
"escape",
")",
"{",
"var",
"pairs",
"=",
"this",
".",
"pairs",
";",
"var",
"type",
"=",
"this",
".",
"type",
";",
"var",
"names",
"=",
"Object",
".",
"keys",
"(",
"pairs",
")",
";",
"var",
"html",
"=",
"\"\"",
";",
"var",
"escapeHtml",
"=",
"escape",
"||",
"IDENTITY",
";",
"var",
"name",
";",
"var",
"computedType",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"names",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"name",
"=",
"names",
"[",
"i",
"]",
";",
"computedType",
"=",
"typeof",
"type",
"===",
"\"function\"",
"?",
"type",
"(",
"name",
")",
":",
"type",
";",
"html",
"+=",
"asHtml",
"(",
"computedType",
",",
"name",
",",
"escapeHtml",
"(",
"pairs",
"[",
"name",
"]",
")",
")",
";",
"}",
"return",
"html",
";",
"}"
] | wawjr3d pass in escape strategy so client doesn't need to bundle escape-html | [
"wawjr3d",
"pass",
"in",
"escape",
"strategy",
"so",
"client",
"doesn",
"t",
"need",
"to",
"bundle",
"escape",
"-",
"html"
] | 8504d6d3957fa67bcdf60cf387b92fa1ffb45fd3 | https://github.com/brisket/brisket/blob/8504d6d3957fa67bcdf60cf387b92fa1ffb45fd3/lib/metatags/Metatags.js#L58-L75 | |
21,207 | componitable/format-number | index.js | addIntegerSeparators | function addIntegerSeparators(x, separator) {
x += '';
if (!separator) return x;
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x)) {
x = x.replace(rgx, '$1' + separator + '$2');
}
return x;
} | javascript | function addIntegerSeparators(x, separator) {
x += '';
if (!separator) return x;
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x)) {
x = x.replace(rgx, '$1' + separator + '$2');
}
return x;
} | [
"function",
"addIntegerSeparators",
"(",
"x",
",",
"separator",
")",
"{",
"x",
"+=",
"''",
";",
"if",
"(",
"!",
"separator",
")",
"return",
"x",
";",
"var",
"rgx",
"=",
"/",
"(\\d+)(\\d{3})",
"/",
";",
"while",
"(",
"rgx",
".",
"test",
"(",
"x",
")",
")",
"{",
"x",
"=",
"x",
".",
"replace",
"(",
"rgx",
",",
"'$1'",
"+",
"separator",
"+",
"'$2'",
")",
";",
"}",
"return",
"x",
";",
"}"
] | where x is already the integer part of the number | [
"where",
"x",
"is",
"already",
"the",
"integer",
"part",
"of",
"the",
"number"
] | 5a2a755359f1926a79bd1b4014fe8d43a85adb12 | https://github.com/componitable/format-number/blob/5a2a755359f1926a79bd1b4014fe8d43a85adb12/index.js#L176-L184 |
21,208 | componitable/format-number | index.js | addDecimalSeparators | function addDecimalSeparators(x, separator) {
x += '';
if (!separator) return x;
var rgx = /(\d{3})(\d+)/;
while (rgx.test(x)) {
x = x.replace(rgx, '$1' + separator + '$2');
}
return x;
} | javascript | function addDecimalSeparators(x, separator) {
x += '';
if (!separator) return x;
var rgx = /(\d{3})(\d+)/;
while (rgx.test(x)) {
x = x.replace(rgx, '$1' + separator + '$2');
}
return x;
} | [
"function",
"addDecimalSeparators",
"(",
"x",
",",
"separator",
")",
"{",
"x",
"+=",
"''",
";",
"if",
"(",
"!",
"separator",
")",
"return",
"x",
";",
"var",
"rgx",
"=",
"/",
"(\\d{3})(\\d+)",
"/",
";",
"while",
"(",
"rgx",
".",
"test",
"(",
"x",
")",
")",
"{",
"x",
"=",
"x",
".",
"replace",
"(",
"rgx",
",",
"'$1'",
"+",
"separator",
"+",
"'$2'",
")",
";",
"}",
"return",
"x",
";",
"}"
] | where x is already the decimal part of the number | [
"where",
"x",
"is",
"already",
"the",
"decimal",
"part",
"of",
"the",
"number"
] | 5a2a755359f1926a79bd1b4014fe8d43a85adb12 | https://github.com/componitable/format-number/blob/5a2a755359f1926a79bd1b4014fe8d43a85adb12/index.js#L187-L195 |
21,209 | componitable/format-number | index.js | padLeft | function padLeft(x, padding) {
x = x + '';
var buf = [];
while (buf.length + x.length < padding) {
buf.push('0');
}
return buf.join('') + x;
} | javascript | function padLeft(x, padding) {
x = x + '';
var buf = [];
while (buf.length + x.length < padding) {
buf.push('0');
}
return buf.join('') + x;
} | [
"function",
"padLeft",
"(",
"x",
",",
"padding",
")",
"{",
"x",
"=",
"x",
"+",
"''",
";",
"var",
"buf",
"=",
"[",
"]",
";",
"while",
"(",
"buf",
".",
"length",
"+",
"x",
".",
"length",
"<",
"padding",
")",
"{",
"buf",
".",
"push",
"(",
"'0'",
")",
";",
"}",
"return",
"buf",
".",
"join",
"(",
"''",
")",
"+",
"x",
";",
"}"
] | where x is the integer part of the number | [
"where",
"x",
"is",
"the",
"integer",
"part",
"of",
"the",
"number"
] | 5a2a755359f1926a79bd1b4014fe8d43a85adb12 | https://github.com/componitable/format-number/blob/5a2a755359f1926a79bd1b4014fe8d43a85adb12/index.js#L198-L205 |
21,210 | componitable/format-number | index.js | padRight | function padRight(x, padding) {
if (x) {
x += '';
} else {
x = '';
}
var buf = [];
while (buf.length + x.length < padding) {
buf.push('0');
}
return x + buf.join('');
} | javascript | function padRight(x, padding) {
if (x) {
x += '';
} else {
x = '';
}
var buf = [];
while (buf.length + x.length < padding) {
buf.push('0');
}
return x + buf.join('');
} | [
"function",
"padRight",
"(",
"x",
",",
"padding",
")",
"{",
"if",
"(",
"x",
")",
"{",
"x",
"+=",
"''",
";",
"}",
"else",
"{",
"x",
"=",
"''",
";",
"}",
"var",
"buf",
"=",
"[",
"]",
";",
"while",
"(",
"buf",
".",
"length",
"+",
"x",
".",
"length",
"<",
"padding",
")",
"{",
"buf",
".",
"push",
"(",
"'0'",
")",
";",
"}",
"return",
"x",
"+",
"buf",
".",
"join",
"(",
"''",
")",
";",
"}"
] | where x is the decimals part of the number | [
"where",
"x",
"is",
"the",
"decimals",
"part",
"of",
"the",
"number"
] | 5a2a755359f1926a79bd1b4014fe8d43a85adb12 | https://github.com/componitable/format-number/blob/5a2a755359f1926a79bd1b4014fe8d43a85adb12/index.js#L208-L219 |
21,211 | ngx-kit/ngx-kit | packages/cli/lib/schematize/process-module.js | schematize | function schematize(content, name) {
return content
.replace(new RegExp(`${name}`, 'g'), '<%= dasherize(name) %>', 'g')
.replace(new RegExp(`${classify(name)}`, 'g'), '<%= classify(name) %>', 'g')
.replace(new RegExp(`${camelize(name)}`, 'g'), '<%= camelize(name) %>', 'g')
.replace(new RegExp(`${classify(name)}`, 'g'), '<%= classify(name) %>', 'g');
} | javascript | function schematize(content, name) {
return content
.replace(new RegExp(`${name}`, 'g'), '<%= dasherize(name) %>', 'g')
.replace(new RegExp(`${classify(name)}`, 'g'), '<%= classify(name) %>', 'g')
.replace(new RegExp(`${camelize(name)}`, 'g'), '<%= camelize(name) %>', 'g')
.replace(new RegExp(`${classify(name)}`, 'g'), '<%= classify(name) %>', 'g');
} | [
"function",
"schematize",
"(",
"content",
",",
"name",
")",
"{",
"return",
"content",
".",
"replace",
"(",
"new",
"RegExp",
"(",
"`",
"${",
"name",
"}",
"`",
",",
"'g'",
")",
",",
"'<%= dasherize(name) %>'",
",",
"'g'",
")",
".",
"replace",
"(",
"new",
"RegExp",
"(",
"`",
"${",
"classify",
"(",
"name",
")",
"}",
"`",
",",
"'g'",
")",
",",
"'<%= classify(name) %>'",
",",
"'g'",
")",
".",
"replace",
"(",
"new",
"RegExp",
"(",
"`",
"${",
"camelize",
"(",
"name",
")",
"}",
"`",
",",
"'g'",
")",
",",
"'<%= camelize(name) %>'",
",",
"'g'",
")",
".",
"replace",
"(",
"new",
"RegExp",
"(",
"`",
"${",
"classify",
"(",
"name",
")",
"}",
"`",
",",
"'g'",
")",
",",
"'<%= classify(name) %>'",
",",
"'g'",
")",
";",
"}"
] | Templates-var replacement | [
"Templates",
"-",
"var",
"replacement"
] | 20478b952841828e55cb5bc8f6fb912aae1502da | https://github.com/ngx-kit/ngx-kit/blob/20478b952841828e55cb5bc8f6fb912aae1502da/packages/cli/lib/schematize/process-module.js#L42-L48 |
21,212 | TeselaGen/teselagen-react-components | src/DataTable/utils/queryParams.js | setSearchTerm | function setSearchTerm(searchTerm, currentParams) {
let newParams = {
...currentParams,
page: undefined, //set page undefined to return the table to page 1
searchTerm: searchTerm === defaults.searchTerm ? undefined : searchTerm
};
setNewParams(newParams);
updateSearch(searchTerm);
onlyOneFilter && clearFilters();
} | javascript | function setSearchTerm(searchTerm, currentParams) {
let newParams = {
...currentParams,
page: undefined, //set page undefined to return the table to page 1
searchTerm: searchTerm === defaults.searchTerm ? undefined : searchTerm
};
setNewParams(newParams);
updateSearch(searchTerm);
onlyOneFilter && clearFilters();
} | [
"function",
"setSearchTerm",
"(",
"searchTerm",
",",
"currentParams",
")",
"{",
"let",
"newParams",
"=",
"{",
"...",
"currentParams",
",",
"page",
":",
"undefined",
",",
"//set page undefined to return the table to page 1",
"searchTerm",
":",
"searchTerm",
"===",
"defaults",
".",
"searchTerm",
"?",
"undefined",
":",
"searchTerm",
"}",
";",
"setNewParams",
"(",
"newParams",
")",
";",
"updateSearch",
"(",
"searchTerm",
")",
";",
"onlyOneFilter",
"&&",
"clearFilters",
"(",
")",
";",
"}"
] | all of these actions have currentParams bound to them as their last arg in withTableParams | [
"all",
"of",
"these",
"actions",
"have",
"currentParams",
"bound",
"to",
"them",
"as",
"their",
"last",
"arg",
"in",
"withTableParams"
] | 320ab3fe77fb5749d7ca74f6b0fb444310cb8ee8 | https://github.com/TeselaGen/teselagen-react-components/blob/320ab3fe77fb5749d7ca74f6b0fb444310cb8ee8/src/DataTable/utils/queryParams.js#L436-L445 |
21,213 | TeselaGen/teselagen-react-components | src/DataTable/utils/queryParams.js | cleanupFilter | function cleanupFilter(filter) {
let filterToUse = filter;
if (
filterToUse.selectedFilter === "inList" &&
typeof filterToUse.filterValue === "number"
) {
filterToUse = {
...filterToUse,
filterValue: filterToUse.filterValue.toString()
};
}
if (filterToUse.selectedFilter === "inList") {
filterToUse = {
...filterToUse,
filterValue: filterToUse.filterValue.replace(/, |,/g, ".")
};
}
return filterToUse;
} | javascript | function cleanupFilter(filter) {
let filterToUse = filter;
if (
filterToUse.selectedFilter === "inList" &&
typeof filterToUse.filterValue === "number"
) {
filterToUse = {
...filterToUse,
filterValue: filterToUse.filterValue.toString()
};
}
if (filterToUse.selectedFilter === "inList") {
filterToUse = {
...filterToUse,
filterValue: filterToUse.filterValue.replace(/, |,/g, ".")
};
}
return filterToUse;
} | [
"function",
"cleanupFilter",
"(",
"filter",
")",
"{",
"let",
"filterToUse",
"=",
"filter",
";",
"if",
"(",
"filterToUse",
".",
"selectedFilter",
"===",
"\"inList\"",
"&&",
"typeof",
"filterToUse",
".",
"filterValue",
"===",
"\"number\"",
")",
"{",
"filterToUse",
"=",
"{",
"...",
"filterToUse",
",",
"filterValue",
":",
"filterToUse",
".",
"filterValue",
".",
"toString",
"(",
")",
"}",
";",
"}",
"if",
"(",
"filterToUse",
".",
"selectedFilter",
"===",
"\"inList\"",
")",
"{",
"filterToUse",
"=",
"{",
"...",
"filterToUse",
",",
"filterValue",
":",
"filterToUse",
".",
"filterValue",
".",
"replace",
"(",
"/",
", |,",
"/",
"g",
",",
"\".\"",
")",
"}",
";",
"}",
"return",
"filterToUse",
";",
"}"
] | if an inList value only has two items like 2.3 then it will get parsed to a number and break, convert it back to a string here | [
"if",
"an",
"inList",
"value",
"only",
"has",
"two",
"items",
"like",
"2",
".",
"3",
"then",
"it",
"will",
"get",
"parsed",
"to",
"a",
"number",
"and",
"break",
"convert",
"it",
"back",
"to",
"a",
"string",
"here"
] | 320ab3fe77fb5749d7ca74f6b0fb444310cb8ee8 | https://github.com/TeselaGen/teselagen-react-components/blob/320ab3fe77fb5749d7ca74f6b0fb444310cb8ee8/src/DataTable/utils/queryParams.js#L541-L559 |
21,214 | sutoiku/jsdox | lib/generateMD.js | processTag | function processTag(tag, targets) {
if (tag.description) {
tag.description = replaceLink(tag.description, targets);
}
if (tag.params) {
tag.params.forEach(function (param) {
if (param.description) {
param.description = replaceLink(param.description, targets);
}
});
}
if (tag.members) {
tag.members.forEach(function (member) {
processTag(member, targets);
});
}
if (tag.methods) {
tag.methods.forEach(function (method) {
processTag(method, targets);
});
}
} | javascript | function processTag(tag, targets) {
if (tag.description) {
tag.description = replaceLink(tag.description, targets);
}
if (tag.params) {
tag.params.forEach(function (param) {
if (param.description) {
param.description = replaceLink(param.description, targets);
}
});
}
if (tag.members) {
tag.members.forEach(function (member) {
processTag(member, targets);
});
}
if (tag.methods) {
tag.methods.forEach(function (method) {
processTag(method, targets);
});
}
} | [
"function",
"processTag",
"(",
"tag",
",",
"targets",
")",
"{",
"if",
"(",
"tag",
".",
"description",
")",
"{",
"tag",
".",
"description",
"=",
"replaceLink",
"(",
"tag",
".",
"description",
",",
"targets",
")",
";",
"}",
"if",
"(",
"tag",
".",
"params",
")",
"{",
"tag",
".",
"params",
".",
"forEach",
"(",
"function",
"(",
"param",
")",
"{",
"if",
"(",
"param",
".",
"description",
")",
"{",
"param",
".",
"description",
"=",
"replaceLink",
"(",
"param",
".",
"description",
",",
"targets",
")",
";",
"}",
"}",
")",
";",
"}",
"if",
"(",
"tag",
".",
"members",
")",
"{",
"tag",
".",
"members",
".",
"forEach",
"(",
"function",
"(",
"member",
")",
"{",
"processTag",
"(",
"member",
",",
"targets",
")",
";",
"}",
")",
";",
"}",
"if",
"(",
"tag",
".",
"methods",
")",
"{",
"tag",
".",
"methods",
".",
"forEach",
"(",
"function",
"(",
"method",
")",
"{",
"processTag",
"(",
"method",
",",
"targets",
")",
";",
"}",
")",
";",
"}",
"}"
] | Processes a tag for Markdown replacements.
@param {Object} tag - tag to process
@param {Object} targets - map of targets to use for links (optional) | [
"Processes",
"a",
"tag",
"for",
"Markdown",
"replacements",
"."
] | fd43230c1aeae74962ca07a22d97525a81624516 | https://github.com/sutoiku/jsdox/blob/fd43230c1aeae74962ca07a22d97525a81624516/lib/generateMD.js#L35-L56 |
21,215 | sutoiku/jsdox | lib/analyze.js | setPipedTypesString | function setPipedTypesString(node) {
if (!node.type) { return ''; }
node.typesString = node.type.names.join(' | ');
} | javascript | function setPipedTypesString(node) {
if (!node.type) { return ''; }
node.typesString = node.type.names.join(' | ');
} | [
"function",
"setPipedTypesString",
"(",
"node",
")",
"{",
"if",
"(",
"!",
"node",
".",
"type",
")",
"{",
"return",
"''",
";",
"}",
"node",
".",
"typesString",
"=",
"node",
".",
"type",
".",
"names",
".",
"join",
"(",
"' | '",
")",
";",
"}"
] | Attaches a 'typesString' pipe-separated attribute
containing the node's types
@param {AST} node - May or may not contain a type attribute | [
"Attaches",
"a",
"typesString",
"pipe",
"-",
"separated",
"attribute",
"containing",
"the",
"node",
"s",
"types"
] | fd43230c1aeae74962ca07a22d97525a81624516 | https://github.com/sutoiku/jsdox/blob/fd43230c1aeae74962ca07a22d97525a81624516/lib/analyze.js#L217-L221 |
21,216 | tsmith/node-control | lib/controller.js | addListenersToStream | function addListenersToStream(listeners, stream) {
var evt, callback;
if (listeners) {
for (evt in listeners) {
if (listeners.hasOwnProperty(evt)) {
callback = listeners[evt];
stream.on(evt, callback);
}
}
}
} | javascript | function addListenersToStream(listeners, stream) {
var evt, callback;
if (listeners) {
for (evt in listeners) {
if (listeners.hasOwnProperty(evt)) {
callback = listeners[evt];
stream.on(evt, callback);
}
}
}
} | [
"function",
"addListenersToStream",
"(",
"listeners",
",",
"stream",
")",
"{",
"var",
"evt",
",",
"callback",
";",
"if",
"(",
"listeners",
")",
"{",
"for",
"(",
"evt",
"in",
"listeners",
")",
"{",
"if",
"(",
"listeners",
".",
"hasOwnProperty",
"(",
"evt",
")",
")",
"{",
"callback",
"=",
"listeners",
"[",
"evt",
"]",
";",
"stream",
".",
"on",
"(",
"evt",
",",
"callback",
")",
";",
"}",
"}",
"}",
"}"
] | Controller support for adding listeners to subprocess stream upon call | [
"Controller",
"support",
"for",
"adding",
"listeners",
"to",
"subprocess",
"stream",
"upon",
"call"
] | 6bd8a39a6bb1faaa9efccc300ca2ec48ebcaffa0 | https://github.com/tsmith/node-control/blob/6bd8a39a6bb1faaa9efccc300ca2ec48ebcaffa0/lib/controller.js#L58-L68 |
21,217 | tsmith/node-control | lib/configurator.js | chain | function chain(a, b) {
var prop, descriptor = {};
for (prop in a) {
if (a.hasOwnProperty(prop)) {
descriptor[prop] = Object.getOwnPropertyDescriptor(a, prop);
}
}
return Object.create(b, descriptor);
} | javascript | function chain(a, b) {
var prop, descriptor = {};
for (prop in a) {
if (a.hasOwnProperty(prop)) {
descriptor[prop] = Object.getOwnPropertyDescriptor(a, prop);
}
}
return Object.create(b, descriptor);
} | [
"function",
"chain",
"(",
"a",
",",
"b",
")",
"{",
"var",
"prop",
",",
"descriptor",
"=",
"{",
"}",
";",
"for",
"(",
"prop",
"in",
"a",
")",
"{",
"if",
"(",
"a",
".",
"hasOwnProperty",
"(",
"prop",
")",
")",
"{",
"descriptor",
"[",
"prop",
"]",
"=",
"Object",
".",
"getOwnPropertyDescriptor",
"(",
"a",
",",
"prop",
")",
";",
"}",
"}",
"return",
"Object",
".",
"create",
"(",
"b",
",",
"descriptor",
")",
";",
"}"
] | Return a copy of a with prototype of b | [
"Return",
"a",
"copy",
"of",
"a",
"with",
"prototype",
"of",
"b"
] | 6bd8a39a6bb1faaa9efccc300ca2ec48ebcaffa0 | https://github.com/tsmith/node-control/blob/6bd8a39a6bb1faaa9efccc300ca2ec48ebcaffa0/lib/configurator.js#L7-L15 |
21,218 | bitpay/bitcore-payment-protocol | update-rootcerts.js | getRootCerts | function getRootCerts(callback) {
return request(certUrl, function(err, res, body) {
if (err) return callback(err);
// Delete preprocesor macros
body = body.replace(/#[^\n]+/g, '');
// Delete the trailing comma
body = body.replace(/,\s*$/, '');
// Make sure each C string is concatenated
body = body.replace(/"\r?\n"/g, '');
// Make sue we turn the cert names into property names
body = body.replace(/\/\*([^*]+)\*\/\n(?=")/g, function(_, name) {
var key = name.trim();
return '"' + key + '":\n';
});
// Delete Comments
body = body.replace(/\/\* tools\/\.\.\/src[^\0]+?\*\//, '');
body = body.replace(/\/\* @\(#\)[^\n]+/, '');
// \xff -> \u00ff
body = body.replace(/\\x([0-9a-fA-F]{2})/g, '\\u00$1');
// Trim Whitespace
body = body.trim();
// Wrap into a JSON Object
body = '{\n' + body + '\n}\n';
// Ensure JSON parses properly
try {
body = JSON.stringify(JSON.parse(body), null, 2);
} catch (e) {
return callback(e);
}
return callback(null, body);
});
} | javascript | function getRootCerts(callback) {
return request(certUrl, function(err, res, body) {
if (err) return callback(err);
// Delete preprocesor macros
body = body.replace(/#[^\n]+/g, '');
// Delete the trailing comma
body = body.replace(/,\s*$/, '');
// Make sure each C string is concatenated
body = body.replace(/"\r?\n"/g, '');
// Make sue we turn the cert names into property names
body = body.replace(/\/\*([^*]+)\*\/\n(?=")/g, function(_, name) {
var key = name.trim();
return '"' + key + '":\n';
});
// Delete Comments
body = body.replace(/\/\* tools\/\.\.\/src[^\0]+?\*\//, '');
body = body.replace(/\/\* @\(#\)[^\n]+/, '');
// \xff -> \u00ff
body = body.replace(/\\x([0-9a-fA-F]{2})/g, '\\u00$1');
// Trim Whitespace
body = body.trim();
// Wrap into a JSON Object
body = '{\n' + body + '\n}\n';
// Ensure JSON parses properly
try {
body = JSON.stringify(JSON.parse(body), null, 2);
} catch (e) {
return callback(e);
}
return callback(null, body);
});
} | [
"function",
"getRootCerts",
"(",
"callback",
")",
"{",
"return",
"request",
"(",
"certUrl",
",",
"function",
"(",
"err",
",",
"res",
",",
"body",
")",
"{",
"if",
"(",
"err",
")",
"return",
"callback",
"(",
"err",
")",
";",
"// Delete preprocesor macros",
"body",
"=",
"body",
".",
"replace",
"(",
"/",
"#[^\\n]+",
"/",
"g",
",",
"''",
")",
";",
"// Delete the trailing comma",
"body",
"=",
"body",
".",
"replace",
"(",
"/",
",\\s*$",
"/",
",",
"''",
")",
";",
"// Make sure each C string is concatenated",
"body",
"=",
"body",
".",
"replace",
"(",
"/",
"\"\\r?\\n\"",
"/",
"g",
",",
"''",
")",
";",
"// Make sue we turn the cert names into property names",
"body",
"=",
"body",
".",
"replace",
"(",
"/",
"\\/\\*([^*]+)\\*\\/\\n(?=\")",
"/",
"g",
",",
"function",
"(",
"_",
",",
"name",
")",
"{",
"var",
"key",
"=",
"name",
".",
"trim",
"(",
")",
";",
"return",
"'\"'",
"+",
"key",
"+",
"'\":\\n'",
";",
"}",
")",
";",
"// Delete Comments",
"body",
"=",
"body",
".",
"replace",
"(",
"/",
"\\/\\* tools\\/\\.\\.\\/src[^\\0]+?\\*\\/",
"/",
",",
"''",
")",
";",
"body",
"=",
"body",
".",
"replace",
"(",
"/",
"\\/\\* @\\(#\\)[^\\n]+",
"/",
",",
"''",
")",
";",
"// \\xff -> \\u00ff",
"body",
"=",
"body",
".",
"replace",
"(",
"/",
"\\\\x([0-9a-fA-F]{2})",
"/",
"g",
",",
"'\\\\u00$1'",
")",
";",
"// Trim Whitespace",
"body",
"=",
"body",
".",
"trim",
"(",
")",
";",
"// Wrap into a JSON Object",
"body",
"=",
"'{\\n'",
"+",
"body",
"+",
"'\\n}\\n'",
";",
"// Ensure JSON parses properly",
"try",
"{",
"body",
"=",
"JSON",
".",
"stringify",
"(",
"JSON",
".",
"parse",
"(",
"body",
")",
",",
"null",
",",
"2",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"return",
"callback",
"(",
"e",
")",
";",
"}",
"return",
"callback",
"(",
"null",
",",
"body",
")",
";",
"}",
")",
";",
"}"
] | Get Root Certs | [
"Get",
"Root",
"Certs"
] | aee23c347f15476616144a9c258d5d28f2338a94 | https://github.com/bitpay/bitcore-payment-protocol/blob/aee23c347f15476616144a9c258d5d28f2338a94/update-rootcerts.js#L15-L60 |
21,219 | square/field-kit | src/expiry_date_formatter.js | interpretTwoDigitYear | function interpretTwoDigitYear(year) {
const thisYear = new Date().getFullYear();
const thisCentury = thisYear - (thisYear % 100);
const centuries = [thisCentury, thisCentury - 100, thisCentury + 100].sort(function(a, b) {
return Math.abs(thisYear - (year + a)) - Math.abs(thisYear - (year + b));
});
return year + centuries[0];
} | javascript | function interpretTwoDigitYear(year) {
const thisYear = new Date().getFullYear();
const thisCentury = thisYear - (thisYear % 100);
const centuries = [thisCentury, thisCentury - 100, thisCentury + 100].sort(function(a, b) {
return Math.abs(thisYear - (year + a)) - Math.abs(thisYear - (year + b));
});
return year + centuries[0];
} | [
"function",
"interpretTwoDigitYear",
"(",
"year",
")",
"{",
"const",
"thisYear",
"=",
"new",
"Date",
"(",
")",
".",
"getFullYear",
"(",
")",
";",
"const",
"thisCentury",
"=",
"thisYear",
"-",
"(",
"thisYear",
"%",
"100",
")",
";",
"const",
"centuries",
"=",
"[",
"thisCentury",
",",
"thisCentury",
"-",
"100",
",",
"thisCentury",
"+",
"100",
"]",
".",
"sort",
"(",
"function",
"(",
"a",
",",
"b",
")",
"{",
"return",
"Math",
".",
"abs",
"(",
"thisYear",
"-",
"(",
"year",
"+",
"a",
")",
")",
"-",
"Math",
".",
"abs",
"(",
"thisYear",
"-",
"(",
"year",
"+",
"b",
")",
")",
";",
"}",
")",
";",
"return",
"year",
"+",
"centuries",
"[",
"0",
"]",
";",
"}"
] | Give this function a 2 digit year it'll return with 4.
@example
interpretTwoDigitYear(15);
// => 2015
interpretTwoDigitYear(97);
// => 1997
@param {number} year
@returns {number}
@private | [
"Give",
"this",
"function",
"a",
"2",
"digit",
"year",
"it",
"ll",
"return",
"with",
"4",
"."
] | 86e5f45598b8c943d2b37ca244ab93084cb00c73 | https://github.com/square/field-kit/blob/86e5f45598b8c943d2b37ca244ab93084cb00c73/src/expiry_date_formatter.js#L16-L23 |
21,220 | square/field-kit | src/number_formatter.js | get | function get(object, key, ...args) {
if (object) {
const value = object[key];
if (typeof value === 'function') {
return value(...args);
} else {
return value;
}
}
} | javascript | function get(object, key, ...args) {
if (object) {
const value = object[key];
if (typeof value === 'function') {
return value(...args);
} else {
return value;
}
}
} | [
"function",
"get",
"(",
"object",
",",
"key",
",",
"...",
"args",
")",
"{",
"if",
"(",
"object",
")",
"{",
"const",
"value",
"=",
"object",
"[",
"key",
"]",
";",
"if",
"(",
"typeof",
"value",
"===",
"'function'",
")",
"{",
"return",
"value",
"(",
"...",
"args",
")",
";",
"}",
"else",
"{",
"return",
"value",
";",
"}",
"}",
"}"
] | This simple property getter assumes that properties will never be functions
and so attempts to run those functions using the given args.
@private | [
"This",
"simple",
"property",
"getter",
"assumes",
"that",
"properties",
"will",
"never",
"be",
"functions",
"and",
"so",
"attempts",
"to",
"run",
"those",
"functions",
"using",
"the",
"given",
"args",
"."
] | 86e5f45598b8c943d2b37ca244ab93084cb00c73 | https://github.com/square/field-kit/blob/86e5f45598b8c943d2b37ca244ab93084cb00c73/src/number_formatter.js#L34-L43 |
21,221 | punkave/uploadfs | lib/storage/azure.js | setContainerProperties | function setContainerProperties(blobSvc, options, result, callback) {
blobSvc.getServiceProperties(function(error, result, response) {
if (error) {
return callback(error);
}
var serviceProperties = result;
var allowedOrigins = options.allowedOrigins || ['*'];
var allowedMethods = options.allowedMethods || ['GET', 'PUT', 'POST'];
var allowedHeaders = options.allowedHeaders || ['*'];
var exposedHeaders = options.exposedHeaders || ['*'];
var maxAgeInSeconds = options.maxAgeInSeconds || DEFAULT_MAX_AGE_IN_SECONDS;
serviceProperties.Cors = {
CorsRule: [
{
AllowedOrigins: allowedOrigins,
AllowedMethods: allowedMethods,
AllowedHeaders: allowedHeaders,
ExposedHeaders: exposedHeaders,
MaxAgeInSeconds: maxAgeInSeconds
}
]
};
blobSvc.setServiceProperties(serviceProperties, function(error, result, response) {
if (error) {
return callback(error);
}
return callback(null, blobSvc);
});
});
} | javascript | function setContainerProperties(blobSvc, options, result, callback) {
blobSvc.getServiceProperties(function(error, result, response) {
if (error) {
return callback(error);
}
var serviceProperties = result;
var allowedOrigins = options.allowedOrigins || ['*'];
var allowedMethods = options.allowedMethods || ['GET', 'PUT', 'POST'];
var allowedHeaders = options.allowedHeaders || ['*'];
var exposedHeaders = options.exposedHeaders || ['*'];
var maxAgeInSeconds = options.maxAgeInSeconds || DEFAULT_MAX_AGE_IN_SECONDS;
serviceProperties.Cors = {
CorsRule: [
{
AllowedOrigins: allowedOrigins,
AllowedMethods: allowedMethods,
AllowedHeaders: allowedHeaders,
ExposedHeaders: exposedHeaders,
MaxAgeInSeconds: maxAgeInSeconds
}
]
};
blobSvc.setServiceProperties(serviceProperties, function(error, result, response) {
if (error) {
return callback(error);
}
return callback(null, blobSvc);
});
});
} | [
"function",
"setContainerProperties",
"(",
"blobSvc",
",",
"options",
",",
"result",
",",
"callback",
")",
"{",
"blobSvc",
".",
"getServiceProperties",
"(",
"function",
"(",
"error",
",",
"result",
",",
"response",
")",
"{",
"if",
"(",
"error",
")",
"{",
"return",
"callback",
"(",
"error",
")",
";",
"}",
"var",
"serviceProperties",
"=",
"result",
";",
"var",
"allowedOrigins",
"=",
"options",
".",
"allowedOrigins",
"||",
"[",
"'*'",
"]",
";",
"var",
"allowedMethods",
"=",
"options",
".",
"allowedMethods",
"||",
"[",
"'GET'",
",",
"'PUT'",
",",
"'POST'",
"]",
";",
"var",
"allowedHeaders",
"=",
"options",
".",
"allowedHeaders",
"||",
"[",
"'*'",
"]",
";",
"var",
"exposedHeaders",
"=",
"options",
".",
"exposedHeaders",
"||",
"[",
"'*'",
"]",
";",
"var",
"maxAgeInSeconds",
"=",
"options",
".",
"maxAgeInSeconds",
"||",
"DEFAULT_MAX_AGE_IN_SECONDS",
";",
"serviceProperties",
".",
"Cors",
"=",
"{",
"CorsRule",
":",
"[",
"{",
"AllowedOrigins",
":",
"allowedOrigins",
",",
"AllowedMethods",
":",
"allowedMethods",
",",
"AllowedHeaders",
":",
"allowedHeaders",
",",
"ExposedHeaders",
":",
"exposedHeaders",
",",
"MaxAgeInSeconds",
":",
"maxAgeInSeconds",
"}",
"]",
"}",
";",
"blobSvc",
".",
"setServiceProperties",
"(",
"serviceProperties",
",",
"function",
"(",
"error",
",",
"result",
",",
"response",
")",
"{",
"if",
"(",
"error",
")",
"{",
"return",
"callback",
"(",
"error",
")",
";",
"}",
"return",
"callback",
"(",
"null",
",",
"blobSvc",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Set the main properties of the selected container.
@param {AzureService} blobSvc Azure service object
@param {Object} options Options passed to UploadFS library
@param {Object} result Service Properties
@param {Function} callback Callback to be called when operation is terminated
@return {any} Return the service which has been initialized | [
"Set",
"the",
"main",
"properties",
"of",
"the",
"selected",
"container",
"."
] | e4e252bc93eaecea9cf2e721f8e6031519d14257 | https://github.com/punkave/uploadfs/blob/e4e252bc93eaecea9cf2e721f8e6031519d14257/lib/storage/azure.js#L32-L63 |
21,222 | punkave/uploadfs | lib/storage/azure.js | initializeContainer | function initializeContainer(blobSvc, container, options, callback) {
blobSvc.setContainerAcl(container, null, { publicAccessLevel: 'container' }, function(error, result, response) {
if (error) {
return callback(error);
}
return setContainerProperties(blobSvc, options, result, callback);
});
} | javascript | function initializeContainer(blobSvc, container, options, callback) {
blobSvc.setContainerAcl(container, null, { publicAccessLevel: 'container' }, function(error, result, response) {
if (error) {
return callback(error);
}
return setContainerProperties(blobSvc, options, result, callback);
});
} | [
"function",
"initializeContainer",
"(",
"blobSvc",
",",
"container",
",",
"options",
",",
"callback",
")",
"{",
"blobSvc",
".",
"setContainerAcl",
"(",
"container",
",",
"null",
",",
"{",
"publicAccessLevel",
":",
"'container'",
"}",
",",
"function",
"(",
"error",
",",
"result",
",",
"response",
")",
"{",
"if",
"(",
"error",
")",
"{",
"return",
"callback",
"(",
"error",
")",
";",
"}",
"return",
"setContainerProperties",
"(",
"blobSvc",
",",
"options",
",",
"result",
",",
"callback",
")",
";",
"}",
")",
";",
"}"
] | Initialize the container ACLs
@param {AzureService} blobSvc Azure Service object
@param {String} container Container name
@param {Object} options Options passed to UploadFS library
@param {Function} callback Callback to be called when operation is terminated
@return {any} Returns the result of `setContainerProperties` | [
"Initialize",
"the",
"container",
"ACLs"
] | e4e252bc93eaecea9cf2e721f8e6031519d14257 | https://github.com/punkave/uploadfs/blob/e4e252bc93eaecea9cf2e721f8e6031519d14257/lib/storage/azure.js#L73-L80 |
21,223 | punkave/uploadfs | lib/storage/azure.js | createContainer | function createContainer(cluster, options, callback) {
var blobSvc = azure.createBlobService(cluster.account, cluster.key);
var container = cluster.container || options.container;
blobSvc.createContainerIfNotExists(container, function(error, result, response) {
if (error) {
return callback(error);
}
return initializeContainer(blobSvc, container, options, callback);
});
} | javascript | function createContainer(cluster, options, callback) {
var blobSvc = azure.createBlobService(cluster.account, cluster.key);
var container = cluster.container || options.container;
blobSvc.createContainerIfNotExists(container, function(error, result, response) {
if (error) {
return callback(error);
}
return initializeContainer(blobSvc, container, options, callback);
});
} | [
"function",
"createContainer",
"(",
"cluster",
",",
"options",
",",
"callback",
")",
"{",
"var",
"blobSvc",
"=",
"azure",
".",
"createBlobService",
"(",
"cluster",
".",
"account",
",",
"cluster",
".",
"key",
")",
";",
"var",
"container",
"=",
"cluster",
".",
"container",
"||",
"options",
".",
"container",
";",
"blobSvc",
".",
"createContainerIfNotExists",
"(",
"container",
",",
"function",
"(",
"error",
",",
"result",
",",
"response",
")",
"{",
"if",
"(",
"error",
")",
"{",
"return",
"callback",
"(",
"error",
")",
";",
"}",
"return",
"initializeContainer",
"(",
"blobSvc",
",",
"container",
",",
"options",
",",
"callback",
")",
";",
"}",
")",
";",
"}"
] | Create an Azure Container
@param {Object} cluster Azure Cluster Info
@param {Object} options Options passed to UploadFS library
@param {Function} callback Callback to be called when operation is terminated
@return {any} Returns the initialized service | [
"Create",
"an",
"Azure",
"Container"
] | e4e252bc93eaecea9cf2e721f8e6031519d14257 | https://github.com/punkave/uploadfs/blob/e4e252bc93eaecea9cf2e721f8e6031519d14257/lib/storage/azure.js#L89-L98 |
21,224 | punkave/uploadfs | lib/storage/azure.js | createContainerBlob | function createContainerBlob(blob, path, localPath, _gzip, callback) {
// Draw the extension from uploadfs, where we know they will be using
// reasonable extensions, not from what could be a temporary file
// that came from the gzip code. -Tom
var extension = extname(path).substring(1);
var contentSettings = {
cacheControl: `max-age=${DEFAULT_MAX_CACHE}, public`,
// contentEncoding: _gzip ? 'gzip' : 'deflate',
contentType: contentTypes[extension] || 'application/octet-stream'
};
if (_gzip) {
contentSettings.contentEncoding = 'gzip';
}
blob.svc.createBlockBlobFromLocalFile(
blob.container,
path,
localPath,
{
contentSettings: contentSettings
},
function(error, result, response) {
return callback(error);
}
);
} | javascript | function createContainerBlob(blob, path, localPath, _gzip, callback) {
// Draw the extension from uploadfs, where we know they will be using
// reasonable extensions, not from what could be a temporary file
// that came from the gzip code. -Tom
var extension = extname(path).substring(1);
var contentSettings = {
cacheControl: `max-age=${DEFAULT_MAX_CACHE}, public`,
// contentEncoding: _gzip ? 'gzip' : 'deflate',
contentType: contentTypes[extension] || 'application/octet-stream'
};
if (_gzip) {
contentSettings.contentEncoding = 'gzip';
}
blob.svc.createBlockBlobFromLocalFile(
blob.container,
path,
localPath,
{
contentSettings: contentSettings
},
function(error, result, response) {
return callback(error);
}
);
} | [
"function",
"createContainerBlob",
"(",
"blob",
",",
"path",
",",
"localPath",
",",
"_gzip",
",",
"callback",
")",
"{",
"// Draw the extension from uploadfs, where we know they will be using",
"// reasonable extensions, not from what could be a temporary file",
"// that came from the gzip code. -Tom",
"var",
"extension",
"=",
"extname",
"(",
"path",
")",
".",
"substring",
"(",
"1",
")",
";",
"var",
"contentSettings",
"=",
"{",
"cacheControl",
":",
"`",
"${",
"DEFAULT_MAX_CACHE",
"}",
"`",
",",
"// contentEncoding: _gzip ? 'gzip' : 'deflate',",
"contentType",
":",
"contentTypes",
"[",
"extension",
"]",
"||",
"'application/octet-stream'",
"}",
";",
"if",
"(",
"_gzip",
")",
"{",
"contentSettings",
".",
"contentEncoding",
"=",
"'gzip'",
";",
"}",
"blob",
".",
"svc",
".",
"createBlockBlobFromLocalFile",
"(",
"blob",
".",
"container",
",",
"path",
",",
"localPath",
",",
"{",
"contentSettings",
":",
"contentSettings",
"}",
",",
"function",
"(",
"error",
",",
"result",
",",
"response",
")",
"{",
"return",
"callback",
"(",
"error",
")",
";",
"}",
")",
";",
"}"
] | Send a binary file to a specified container and a specified service
@param {Object} blob Azure Service info and container
@param {String} path Remote path
@param {String} localPath Local file path
@param {Function} callback Callback to be called when operation is terminated
@return {any} Result of the callback | [
"Send",
"a",
"binary",
"file",
"to",
"a",
"specified",
"container",
"and",
"a",
"specified",
"service"
] | e4e252bc93eaecea9cf2e721f8e6031519d14257 | https://github.com/punkave/uploadfs/blob/e4e252bc93eaecea9cf2e721f8e6031519d14257/lib/storage/azure.js#L120-L144 |
21,225 | punkave/uploadfs | lib/storage/azure.js | removeContainerBlob | function removeContainerBlob(blob, path, callback) {
blob.svc.deleteBlobIfExists(blob.container, path, function(error, result, response) {
if (error) {
__log('Cannot delete ' + path + 'on container ' + blob.container);
}
return callback(error);
});
} | javascript | function removeContainerBlob(blob, path, callback) {
blob.svc.deleteBlobIfExists(blob.container, path, function(error, result, response) {
if (error) {
__log('Cannot delete ' + path + 'on container ' + blob.container);
}
return callback(error);
});
} | [
"function",
"removeContainerBlob",
"(",
"blob",
",",
"path",
",",
"callback",
")",
"{",
"blob",
".",
"svc",
".",
"deleteBlobIfExists",
"(",
"blob",
".",
"container",
",",
"path",
",",
"function",
"(",
"error",
",",
"result",
",",
"response",
")",
"{",
"if",
"(",
"error",
")",
"{",
"__log",
"(",
"'Cannot delete '",
"+",
"path",
"+",
"'on container '",
"+",
"blob",
".",
"container",
")",
";",
"}",
"return",
"callback",
"(",
"error",
")",
";",
"}",
")",
";",
"}"
] | Remove remote container binary file
@param {Object} param0 Azure Service info and container
@param {String} path Remote file path
@param {Function} callback Callback to be called when operation is terminated
@return {any} Result of the callback | [
"Remove",
"remote",
"container",
"binary",
"file"
] | e4e252bc93eaecea9cf2e721f8e6031519d14257 | https://github.com/punkave/uploadfs/blob/e4e252bc93eaecea9cf2e721f8e6031519d14257/lib/storage/azure.js#L153-L161 |
21,226 | punkave/uploadfs | lib/storage/azure.js | function(gzipEncoding) {
var gzipSettings = gzipEncoding || {};
var { whitelist, blacklist } = Object.keys(gzipSettings).reduce((prev, key) => {
if (gzipSettings[key]) {
prev['whitelist'].push(key);
} else {
prev['blacklist'].push(key);
}
return prev;
}, { whitelist: [], blacklist: [] });
// @NOTE - we REMOVE whitelisted types from the blacklist array
var gzipBlacklist = defaultGzipBlacklist.concat(blacklist).filter(el => whitelist.indexOf(el));
return _.uniq(gzipBlacklist);
} | javascript | function(gzipEncoding) {
var gzipSettings = gzipEncoding || {};
var { whitelist, blacklist } = Object.keys(gzipSettings).reduce((prev, key) => {
if (gzipSettings[key]) {
prev['whitelist'].push(key);
} else {
prev['blacklist'].push(key);
}
return prev;
}, { whitelist: [], blacklist: [] });
// @NOTE - we REMOVE whitelisted types from the blacklist array
var gzipBlacklist = defaultGzipBlacklist.concat(blacklist).filter(el => whitelist.indexOf(el));
return _.uniq(gzipBlacklist);
} | [
"function",
"(",
"gzipEncoding",
")",
"{",
"var",
"gzipSettings",
"=",
"gzipEncoding",
"||",
"{",
"}",
";",
"var",
"{",
"whitelist",
",",
"blacklist",
"}",
"=",
"Object",
".",
"keys",
"(",
"gzipSettings",
")",
".",
"reduce",
"(",
"(",
"prev",
",",
"key",
")",
"=>",
"{",
"if",
"(",
"gzipSettings",
"[",
"key",
"]",
")",
"{",
"prev",
"[",
"'whitelist'",
"]",
".",
"push",
"(",
"key",
")",
";",
"}",
"else",
"{",
"prev",
"[",
"'blacklist'",
"]",
".",
"push",
"(",
"key",
")",
";",
"}",
"return",
"prev",
";",
"}",
",",
"{",
"whitelist",
":",
"[",
"]",
",",
"blacklist",
":",
"[",
"]",
"}",
")",
";",
"// @NOTE - we REMOVE whitelisted types from the blacklist array",
"var",
"gzipBlacklist",
"=",
"defaultGzipBlacklist",
".",
"concat",
"(",
"blacklist",
")",
".",
"filter",
"(",
"el",
"=>",
"whitelist",
".",
"indexOf",
"(",
"el",
")",
")",
";",
"return",
"_",
".",
"uniq",
"(",
"gzipBlacklist",
")",
";",
"}"
] | Use sane defaults and user config to get array of file extensions to avoid gzipping
@param gzipEncoding {Object} ex: {jpg: true, rando: false}
@retyrb {Array} An array of file extensions to ignore | [
"Use",
"sane",
"defaults",
"and",
"user",
"config",
"to",
"get",
"array",
"of",
"file",
"extensions",
"to",
"avoid",
"gzipping"
] | e4e252bc93eaecea9cf2e721f8e6031519d14257 | https://github.com/punkave/uploadfs/blob/e4e252bc93eaecea9cf2e721f8e6031519d14257/lib/storage/azure.js#L409-L424 | |
21,227 | uber-web/mjolnir.js | src/utils/hammer-overrides.js | some | function some(array, predict) {
for (let i = 0; i < array.length; i++) {
if (predict(array[i])) {
return true;
}
}
return false;
} | javascript | function some(array, predict) {
for (let i = 0; i < array.length; i++) {
if (predict(array[i])) {
return true;
}
}
return false;
} | [
"function",
"some",
"(",
"array",
",",
"predict",
")",
"{",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"array",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"predict",
"(",
"array",
"[",
"i",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Helper function that returns true if any element in an array meets given criteria.
Because older browsers do not support `Array.prototype.some`
@params array {Array}
@params predict {Function} | [
"Helper",
"function",
"that",
"returns",
"true",
"if",
"any",
"element",
"in",
"an",
"array",
"meets",
"given",
"criteria",
".",
"Because",
"older",
"browsers",
"do",
"not",
"support",
"Array",
".",
"prototype",
".",
"some"
] | d4a09d9761b51c671addc271f8317ccfec77a5fe | https://github.com/uber-web/mjolnir.js/blob/d4a09d9761b51c671addc271f8317ccfec77a5fe/src/utils/hammer-overrides.js#L22-L29 |
21,228 | punkave/uploadfs | lib/utils.js | function(path, disabledFileKey) {
var hmac = crypto.createHmac('sha256', disabledFileKey);
hmac.update(path);
var disabledPath = path + '-disabled-' + hmac.digest('hex');
return disabledPath;
} | javascript | function(path, disabledFileKey) {
var hmac = crypto.createHmac('sha256', disabledFileKey);
hmac.update(path);
var disabledPath = path + '-disabled-' + hmac.digest('hex');
return disabledPath;
} | [
"function",
"(",
"path",
",",
"disabledFileKey",
")",
"{",
"var",
"hmac",
"=",
"crypto",
".",
"createHmac",
"(",
"'sha256'",
",",
"disabledFileKey",
")",
";",
"hmac",
".",
"update",
"(",
"path",
")",
";",
"var",
"disabledPath",
"=",
"path",
"+",
"'-disabled-'",
"+",
"hmac",
".",
"digest",
"(",
"'hex'",
")",
";",
"return",
"disabledPath",
";",
"}"
] | Use an unguessable filename suffix to disable files. This is secure at the web level if the webserver is not configured to serve indexes of files, and it does not impede the use of rsync etc. Used when options.disabledFileKey is set. Use of an HMAC to do this for each filename ensures that even if one such filename is exposed, the others remain secure | [
"Use",
"an",
"unguessable",
"filename",
"suffix",
"to",
"disable",
"files",
".",
"This",
"is",
"secure",
"at",
"the",
"web",
"level",
"if",
"the",
"webserver",
"is",
"not",
"configured",
"to",
"serve",
"indexes",
"of",
"files",
"and",
"it",
"does",
"not",
"impede",
"the",
"use",
"of",
"rsync",
"etc",
".",
"Used",
"when",
"options",
".",
"disabledFileKey",
"is",
"set",
".",
"Use",
"of",
"an",
"HMAC",
"to",
"do",
"this",
"for",
"each",
"filename",
"ensures",
"that",
"even",
"if",
"one",
"such",
"filename",
"is",
"exposed",
"the",
"others",
"remain",
"secure"
] | e4e252bc93eaecea9cf2e721f8e6031519d14257 | https://github.com/punkave/uploadfs/blob/e4e252bc93eaecea9cf2e721f8e6031519d14257/lib/utils.js#L13-L18 | |
21,229 | punkave/uploadfs | uploadfs.js | function (callback) {
if (!imageSizes.length) {
return callback();
}
tempPath = options.tempPath;
if (!fs.existsSync(options.tempPath)) {
fs.mkdirSync(options.tempPath);
}
return callback(null);
} | javascript | function (callback) {
if (!imageSizes.length) {
return callback();
}
tempPath = options.tempPath;
if (!fs.existsSync(options.tempPath)) {
fs.mkdirSync(options.tempPath);
}
return callback(null);
} | [
"function",
"(",
"callback",
")",
"{",
"if",
"(",
"!",
"imageSizes",
".",
"length",
")",
"{",
"return",
"callback",
"(",
")",
";",
"}",
"tempPath",
"=",
"options",
".",
"tempPath",
";",
"if",
"(",
"!",
"fs",
".",
"existsSync",
"(",
"options",
".",
"tempPath",
")",
")",
"{",
"fs",
".",
"mkdirSync",
"(",
"options",
".",
"tempPath",
")",
";",
"}",
"return",
"callback",
"(",
"null",
")",
";",
"}"
] | create temp folder if needed | [
"create",
"temp",
"folder",
"if",
"needed"
] | e4e252bc93eaecea9cf2e721f8e6031519d14257 | https://github.com/punkave/uploadfs/blob/e4e252bc93eaecea9cf2e721f8e6031519d14257/uploadfs.js#L77-L88 | |
21,230 | punkave/uploadfs | uploadfs.js | function (callback) {
if (!self._image) {
var paths = (process.env.PATH || '').split(delimiter);
if (!_.find(paths, function(p) {
if (fs.existsSync(p + '/imagecrunch')) {
self._image = require('./lib/image/imagecrunch.js')();
return true;
}
// Allow for Windows and Unix filenames for identify. Silly oversight
// after getting delimiter right (:
if (fs.existsSync(p + '/identify') || fs.existsSync(p + '/identify.exe')) {
self._image = require('./lib/image/imagemagick.js')();
return true;
}
})) {
// Fall back to jimp, no need for an error
self._image = require('./lib/image/jimp.js')();
}
}
return callback(null);
} | javascript | function (callback) {
if (!self._image) {
var paths = (process.env.PATH || '').split(delimiter);
if (!_.find(paths, function(p) {
if (fs.existsSync(p + '/imagecrunch')) {
self._image = require('./lib/image/imagecrunch.js')();
return true;
}
// Allow for Windows and Unix filenames for identify. Silly oversight
// after getting delimiter right (:
if (fs.existsSync(p + '/identify') || fs.existsSync(p + '/identify.exe')) {
self._image = require('./lib/image/imagemagick.js')();
return true;
}
})) {
// Fall back to jimp, no need for an error
self._image = require('./lib/image/jimp.js')();
}
}
return callback(null);
} | [
"function",
"(",
"callback",
")",
"{",
"if",
"(",
"!",
"self",
".",
"_image",
")",
"{",
"var",
"paths",
"=",
"(",
"process",
".",
"env",
".",
"PATH",
"||",
"''",
")",
".",
"split",
"(",
"delimiter",
")",
";",
"if",
"(",
"!",
"_",
".",
"find",
"(",
"paths",
",",
"function",
"(",
"p",
")",
"{",
"if",
"(",
"fs",
".",
"existsSync",
"(",
"p",
"+",
"'/imagecrunch'",
")",
")",
"{",
"self",
".",
"_image",
"=",
"require",
"(",
"'./lib/image/imagecrunch.js'",
")",
"(",
")",
";",
"return",
"true",
";",
"}",
"// Allow for Windows and Unix filenames for identify. Silly oversight",
"// after getting delimiter right (:",
"if",
"(",
"fs",
".",
"existsSync",
"(",
"p",
"+",
"'/identify'",
")",
"||",
"fs",
".",
"existsSync",
"(",
"p",
"+",
"'/identify.exe'",
")",
")",
"{",
"self",
".",
"_image",
"=",
"require",
"(",
"'./lib/image/imagemagick.js'",
")",
"(",
")",
";",
"return",
"true",
";",
"}",
"}",
")",
")",
"{",
"// Fall back to jimp, no need for an error",
"self",
".",
"_image",
"=",
"require",
"(",
"'./lib/image/jimp.js'",
")",
"(",
")",
";",
"}",
"}",
"return",
"callback",
"(",
"null",
")",
";",
"}"
] | Autodetect image backend if necessary | [
"Autodetect",
"image",
"backend",
"if",
"necessary"
] | e4e252bc93eaecea9cf2e721f8e6031519d14257 | https://github.com/punkave/uploadfs/blob/e4e252bc93eaecea9cf2e721f8e6031519d14257/uploadfs.js#L96-L116 | |
21,231 | punkave/uploadfs | uploadfs.js | identify | function identify(path, callback) {
return self.identifyLocalImage(path, function(err, info) {
if (err) {
return callback(err);
}
context.info = info;
context.extension = info.extension;
return callback(null);
});
} | javascript | function identify(path, callback) {
return self.identifyLocalImage(path, function(err, info) {
if (err) {
return callback(err);
}
context.info = info;
context.extension = info.extension;
return callback(null);
});
} | [
"function",
"identify",
"(",
"path",
",",
"callback",
")",
"{",
"return",
"self",
".",
"identifyLocalImage",
"(",
"path",
",",
"function",
"(",
"err",
",",
"info",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"context",
".",
"info",
"=",
"info",
";",
"context",
".",
"extension",
"=",
"info",
".",
"extension",
";",
"return",
"callback",
"(",
"null",
")",
";",
"}",
")",
";",
"}"
] | Identify the file type, size, etc. Stuff them into context.info and context.extension | [
"Identify",
"the",
"file",
"type",
"size",
"etc",
".",
"Stuff",
"them",
"into",
"context",
".",
"info",
"and",
"context",
".",
"extension"
] | e4e252bc93eaecea9cf2e721f8e6031519d14257 | https://github.com/punkave/uploadfs/blob/e4e252bc93eaecea9cf2e721f8e6031519d14257/uploadfs.js#L241-L250 |
21,232 | punkave/uploadfs | uploadfs.js | function (callback) {
// Name the destination folder
context.tempName = generateId();
// Create destination folder
if (imageSizes.length) {
context.tempFolder = tempPath + '/' + context.tempName;
return fs.mkdir(context.tempFolder, callback);
} else {
return callback(null);
}
} | javascript | function (callback) {
// Name the destination folder
context.tempName = generateId();
// Create destination folder
if (imageSizes.length) {
context.tempFolder = tempPath + '/' + context.tempName;
return fs.mkdir(context.tempFolder, callback);
} else {
return callback(null);
}
} | [
"function",
"(",
"callback",
")",
"{",
"// Name the destination folder",
"context",
".",
"tempName",
"=",
"generateId",
"(",
")",
";",
"// Create destination folder",
"if",
"(",
"imageSizes",
".",
"length",
")",
"{",
"context",
".",
"tempFolder",
"=",
"tempPath",
"+",
"'/'",
"+",
"context",
".",
"tempName",
";",
"return",
"fs",
".",
"mkdir",
"(",
"context",
".",
"tempFolder",
",",
"callback",
")",
";",
"}",
"else",
"{",
"return",
"callback",
"(",
"null",
")",
";",
"}",
"}"
] | make a temporary folder for our work | [
"make",
"a",
"temporary",
"folder",
"for",
"our",
"work"
] | e4e252bc93eaecea9cf2e721f8e6031519d14257 | https://github.com/punkave/uploadfs/blob/e4e252bc93eaecea9cf2e721f8e6031519d14257/uploadfs.js#L267-L277 | |
21,233 | punkave/uploadfs | uploadfs.js | function (callback) {
context.basePath = path.replace(/\.\w+$/, '');
context.workingPath = localPath;
// Indulge their wild claims about the extension the original
// should have if any, otherwise provide the truth from identify
if (path.match(/\.\w+$/)) {
originalPath = path;
} else {
originalPath = path + '.' + context.extension;
}
return callback(null);
} | javascript | function (callback) {
context.basePath = path.replace(/\.\w+$/, '');
context.workingPath = localPath;
// Indulge their wild claims about the extension the original
// should have if any, otherwise provide the truth from identify
if (path.match(/\.\w+$/)) {
originalPath = path;
} else {
originalPath = path + '.' + context.extension;
}
return callback(null);
} | [
"function",
"(",
"callback",
")",
"{",
"context",
".",
"basePath",
"=",
"path",
".",
"replace",
"(",
"/",
"\\.\\w+$",
"/",
",",
"''",
")",
";",
"context",
".",
"workingPath",
"=",
"localPath",
";",
"// Indulge their wild claims about the extension the original",
"// should have if any, otherwise provide the truth from identify",
"if",
"(",
"path",
".",
"match",
"(",
"/",
"\\.\\w+$",
"/",
")",
")",
"{",
"originalPath",
"=",
"path",
";",
"}",
"else",
"{",
"originalPath",
"=",
"path",
"+",
"'.'",
"+",
"context",
".",
"extension",
";",
"}",
"return",
"callback",
"(",
"null",
")",
";",
"}"
] | Determine base path in uploadfs, working path for temporary files, and final uploadfs path of the original | [
"Determine",
"base",
"path",
"in",
"uploadfs",
"working",
"path",
"for",
"temporary",
"files",
"and",
"final",
"uploadfs",
"path",
"of",
"the",
"original"
] | e4e252bc93eaecea9cf2e721f8e6031519d14257 | https://github.com/punkave/uploadfs/blob/e4e252bc93eaecea9cf2e721f8e6031519d14257/uploadfs.js#L280-L292 | |
21,234 | punkave/uploadfs | lib/image/imagecrunch.js | function(callback) {
if (!context.copyOriginal) {
return callback(null);
}
var suffix = 'original.' + context.extension;
var tempFile = context.tempFolder + '/' + suffix;
if (context.extension !== 'jpg') {
// Don't forget to tell the caller that we did the work,
// even if it was just a copy
context.adjustedOriginal = tempFile;
return copyFile(context.workingPath, tempFile, callback);
}
var args = [ context.workingPath ];
if (context.crop) {
args.push('-crop');
args.push(context.crop.left);
args.push(context.crop.top);
args.push(context.crop.width);
args.push(context.crop.height);
}
args.push('-write');
args.push(tempFile);
context.adjustedOriginal = tempFile;
var proc = childProcess.spawn('imagecrunch', args);
proc.on('close', function(code) {
if (code !== 0) {
return callback(code);
}
return callback(null);
});
} | javascript | function(callback) {
if (!context.copyOriginal) {
return callback(null);
}
var suffix = 'original.' + context.extension;
var tempFile = context.tempFolder + '/' + suffix;
if (context.extension !== 'jpg') {
// Don't forget to tell the caller that we did the work,
// even if it was just a copy
context.adjustedOriginal = tempFile;
return copyFile(context.workingPath, tempFile, callback);
}
var args = [ context.workingPath ];
if (context.crop) {
args.push('-crop');
args.push(context.crop.left);
args.push(context.crop.top);
args.push(context.crop.width);
args.push(context.crop.height);
}
args.push('-write');
args.push(tempFile);
context.adjustedOriginal = tempFile;
var proc = childProcess.spawn('imagecrunch', args);
proc.on('close', function(code) {
if (code !== 0) {
return callback(code);
}
return callback(null);
});
} | [
"function",
"(",
"callback",
")",
"{",
"if",
"(",
"!",
"context",
".",
"copyOriginal",
")",
"{",
"return",
"callback",
"(",
"null",
")",
";",
"}",
"var",
"suffix",
"=",
"'original.'",
"+",
"context",
".",
"extension",
";",
"var",
"tempFile",
"=",
"context",
".",
"tempFolder",
"+",
"'/'",
"+",
"suffix",
";",
"if",
"(",
"context",
".",
"extension",
"!==",
"'jpg'",
")",
"{",
"// Don't forget to tell the caller that we did the work,",
"// even if it was just a copy",
"context",
".",
"adjustedOriginal",
"=",
"tempFile",
";",
"return",
"copyFile",
"(",
"context",
".",
"workingPath",
",",
"tempFile",
",",
"callback",
")",
";",
"}",
"var",
"args",
"=",
"[",
"context",
".",
"workingPath",
"]",
";",
"if",
"(",
"context",
".",
"crop",
")",
"{",
"args",
".",
"push",
"(",
"'-crop'",
")",
";",
"args",
".",
"push",
"(",
"context",
".",
"crop",
".",
"left",
")",
";",
"args",
".",
"push",
"(",
"context",
".",
"crop",
".",
"top",
")",
";",
"args",
".",
"push",
"(",
"context",
".",
"crop",
".",
"width",
")",
";",
"args",
".",
"push",
"(",
"context",
".",
"crop",
".",
"height",
")",
";",
"}",
"args",
".",
"push",
"(",
"'-write'",
")",
";",
"args",
".",
"push",
"(",
"tempFile",
")",
";",
"context",
".",
"adjustedOriginal",
"=",
"tempFile",
";",
"var",
"proc",
"=",
"childProcess",
".",
"spawn",
"(",
"'imagecrunch'",
",",
"args",
")",
";",
"proc",
".",
"on",
"(",
"'close'",
",",
"function",
"(",
"code",
")",
"{",
"if",
"(",
"code",
"!==",
"0",
")",
"{",
"return",
"callback",
"(",
"code",
")",
";",
"}",
"return",
"callback",
"(",
"null",
")",
";",
"}",
")",
";",
"}"
] | Autorotated "original" copied in if desired | [
"Autorotated",
"original",
"copied",
"in",
"if",
"desired"
] | e4e252bc93eaecea9cf2e721f8e6031519d14257 | https://github.com/punkave/uploadfs/blob/e4e252bc93eaecea9cf2e721f8e6031519d14257/lib/image/imagecrunch.js#L140-L172 | |
21,235 | fortunejs/fortune-postgres | lib/index.js | mapValueCast | function mapValueCast (value) {
index++
parameters.push(inputValue(value))
let cast = ''
if (Buffer.isBuffer(value))
cast = '::bytea'
else if (typeof value === 'number' && value % 1 === 0)
cast = '::int'
return `$${index}${cast}`
} | javascript | function mapValueCast (value) {
index++
parameters.push(inputValue(value))
let cast = ''
if (Buffer.isBuffer(value))
cast = '::bytea'
else if (typeof value === 'number' && value % 1 === 0)
cast = '::int'
return `$${index}${cast}`
} | [
"function",
"mapValueCast",
"(",
"value",
")",
"{",
"index",
"++",
"parameters",
".",
"push",
"(",
"inputValue",
"(",
"value",
")",
")",
"let",
"cast",
"=",
"''",
"if",
"(",
"Buffer",
".",
"isBuffer",
"(",
"value",
")",
")",
"cast",
"=",
"'::bytea'",
"else",
"if",
"(",
"typeof",
"value",
"===",
"'number'",
"&&",
"value",
"%",
"1",
"===",
"0",
")",
"cast",
"=",
"'::int'",
"return",
"`",
"${",
"index",
"}",
"${",
"cast",
"}",
"`",
"}"
] | These functions modify the variables in this closure. | [
"These",
"functions",
"modify",
"the",
"variables",
"in",
"this",
"closure",
"."
] | 7d158ec79334584049fc2f8de404527eb24ae598 | https://github.com/fortunejs/fortune-postgres/blob/7d158ec79334584049fc2f8de404527eb24ae598/lib/index.js#L350-L362 |
21,236 | Mogztter/antora-lunr | lib/generate-index.js | generateIndex | function generateIndex (playbook, pages) {
let siteUrl = playbook.site.url
if (!siteUrl) {
// Uses relative links when site URL is not set
siteUrl = '';
}
if (siteUrl.charAt(siteUrl.length - 1) === '/') siteUrl = siteUrl.substr(0, siteUrl.length - 1)
if (!pages.length) return {}
// Map of Lunr ref to document
const documentsStore = {}
const documents = pages.map((page) => {
const html = page.contents.toString()
const $ = cheerio.load(html)
const $h1 = $('h1')
const documentTitle = $h1.text()
$h1.remove()
const titles = []
$('h2,h3,h4,h5,h6').each(function () {
let $title = $(this)
// If the title does not have an Id then Lunr will throw a TypeError
// cannot read property 'text' of undefined.
if ($title.attr('id')) {
titles.push({
text: $title.text(),
id: $title.attr('id'),
})
}
$title.remove()
})
// HTML document as text
let text = $('article').text()
// Decode HTML
text = entities.decode(text)
// Strip HTML tags
text = text.replace(/(<([^>]+)>)/ig, '')
.replace(/\n/g, ' ')
.replace(/\r/g, ' ')
.replace(/\s+/g, ' ')
.trim()
return {
text: text,
title: documentTitle,
component: page.src.component,
version: page.src.version,
name: page.src.stem,
url: siteUrl + page.pub.url,
titles: titles, // TODO get title id to be able to use fragment identifier
}
})
const index = lunr(function () {
const self = this
self.ref('url')
self.field('title', {boost: 10})
self.field('name')
self.field('text')
self.field('component')
self.metadataWhitelist = ['position']
documents.forEach(function (doc) {
self.add(doc)
doc.titles.forEach(function (title) {
self.add({
title: title.text,
url: `${doc.url}#${title.id}`,
})
}, self)
}, self)
})
documents.forEach(function (doc) {
documentsStore[doc.url] = doc
})
return {
index: index,
store: documentsStore,
}
} | javascript | function generateIndex (playbook, pages) {
let siteUrl = playbook.site.url
if (!siteUrl) {
// Uses relative links when site URL is not set
siteUrl = '';
}
if (siteUrl.charAt(siteUrl.length - 1) === '/') siteUrl = siteUrl.substr(0, siteUrl.length - 1)
if (!pages.length) return {}
// Map of Lunr ref to document
const documentsStore = {}
const documents = pages.map((page) => {
const html = page.contents.toString()
const $ = cheerio.load(html)
const $h1 = $('h1')
const documentTitle = $h1.text()
$h1.remove()
const titles = []
$('h2,h3,h4,h5,h6').each(function () {
let $title = $(this)
// If the title does not have an Id then Lunr will throw a TypeError
// cannot read property 'text' of undefined.
if ($title.attr('id')) {
titles.push({
text: $title.text(),
id: $title.attr('id'),
})
}
$title.remove()
})
// HTML document as text
let text = $('article').text()
// Decode HTML
text = entities.decode(text)
// Strip HTML tags
text = text.replace(/(<([^>]+)>)/ig, '')
.replace(/\n/g, ' ')
.replace(/\r/g, ' ')
.replace(/\s+/g, ' ')
.trim()
return {
text: text,
title: documentTitle,
component: page.src.component,
version: page.src.version,
name: page.src.stem,
url: siteUrl + page.pub.url,
titles: titles, // TODO get title id to be able to use fragment identifier
}
})
const index = lunr(function () {
const self = this
self.ref('url')
self.field('title', {boost: 10})
self.field('name')
self.field('text')
self.field('component')
self.metadataWhitelist = ['position']
documents.forEach(function (doc) {
self.add(doc)
doc.titles.forEach(function (title) {
self.add({
title: title.text,
url: `${doc.url}#${title.id}`,
})
}, self)
}, self)
})
documents.forEach(function (doc) {
documentsStore[doc.url] = doc
})
return {
index: index,
store: documentsStore,
}
} | [
"function",
"generateIndex",
"(",
"playbook",
",",
"pages",
")",
"{",
"let",
"siteUrl",
"=",
"playbook",
".",
"site",
".",
"url",
"if",
"(",
"!",
"siteUrl",
")",
"{",
"// Uses relative links when site URL is not set",
"siteUrl",
"=",
"''",
";",
"}",
"if",
"(",
"siteUrl",
".",
"charAt",
"(",
"siteUrl",
".",
"length",
"-",
"1",
")",
"===",
"'/'",
")",
"siteUrl",
"=",
"siteUrl",
".",
"substr",
"(",
"0",
",",
"siteUrl",
".",
"length",
"-",
"1",
")",
"if",
"(",
"!",
"pages",
".",
"length",
")",
"return",
"{",
"}",
"// Map of Lunr ref to document",
"const",
"documentsStore",
"=",
"{",
"}",
"const",
"documents",
"=",
"pages",
".",
"map",
"(",
"(",
"page",
")",
"=>",
"{",
"const",
"html",
"=",
"page",
".",
"contents",
".",
"toString",
"(",
")",
"const",
"$",
"=",
"cheerio",
".",
"load",
"(",
"html",
")",
"const",
"$h1",
"=",
"$",
"(",
"'h1'",
")",
"const",
"documentTitle",
"=",
"$h1",
".",
"text",
"(",
")",
"$h1",
".",
"remove",
"(",
")",
"const",
"titles",
"=",
"[",
"]",
"$",
"(",
"'h2,h3,h4,h5,h6'",
")",
".",
"each",
"(",
"function",
"(",
")",
"{",
"let",
"$title",
"=",
"$",
"(",
"this",
")",
"// If the title does not have an Id then Lunr will throw a TypeError",
"// cannot read property 'text' of undefined.",
"if",
"(",
"$title",
".",
"attr",
"(",
"'id'",
")",
")",
"{",
"titles",
".",
"push",
"(",
"{",
"text",
":",
"$title",
".",
"text",
"(",
")",
",",
"id",
":",
"$title",
".",
"attr",
"(",
"'id'",
")",
",",
"}",
")",
"}",
"$title",
".",
"remove",
"(",
")",
"}",
")",
"// HTML document as text",
"let",
"text",
"=",
"$",
"(",
"'article'",
")",
".",
"text",
"(",
")",
"// Decode HTML",
"text",
"=",
"entities",
".",
"decode",
"(",
"text",
")",
"// Strip HTML tags",
"text",
"=",
"text",
".",
"replace",
"(",
"/",
"(<([^>]+)>)",
"/",
"ig",
",",
"''",
")",
".",
"replace",
"(",
"/",
"\\n",
"/",
"g",
",",
"' '",
")",
".",
"replace",
"(",
"/",
"\\r",
"/",
"g",
",",
"' '",
")",
".",
"replace",
"(",
"/",
"\\s+",
"/",
"g",
",",
"' '",
")",
".",
"trim",
"(",
")",
"return",
"{",
"text",
":",
"text",
",",
"title",
":",
"documentTitle",
",",
"component",
":",
"page",
".",
"src",
".",
"component",
",",
"version",
":",
"page",
".",
"src",
".",
"version",
",",
"name",
":",
"page",
".",
"src",
".",
"stem",
",",
"url",
":",
"siteUrl",
"+",
"page",
".",
"pub",
".",
"url",
",",
"titles",
":",
"titles",
",",
"// TODO get title id to be able to use fragment identifier",
"}",
"}",
")",
"const",
"index",
"=",
"lunr",
"(",
"function",
"(",
")",
"{",
"const",
"self",
"=",
"this",
"self",
".",
"ref",
"(",
"'url'",
")",
"self",
".",
"field",
"(",
"'title'",
",",
"{",
"boost",
":",
"10",
"}",
")",
"self",
".",
"field",
"(",
"'name'",
")",
"self",
".",
"field",
"(",
"'text'",
")",
"self",
".",
"field",
"(",
"'component'",
")",
"self",
".",
"metadataWhitelist",
"=",
"[",
"'position'",
"]",
"documents",
".",
"forEach",
"(",
"function",
"(",
"doc",
")",
"{",
"self",
".",
"add",
"(",
"doc",
")",
"doc",
".",
"titles",
".",
"forEach",
"(",
"function",
"(",
"title",
")",
"{",
"self",
".",
"add",
"(",
"{",
"title",
":",
"title",
".",
"text",
",",
"url",
":",
"`",
"${",
"doc",
".",
"url",
"}",
"${",
"title",
".",
"id",
"}",
"`",
",",
"}",
")",
"}",
",",
"self",
")",
"}",
",",
"self",
")",
"}",
")",
"documents",
".",
"forEach",
"(",
"function",
"(",
"doc",
")",
"{",
"documentsStore",
"[",
"doc",
".",
"url",
"]",
"=",
"doc",
"}",
")",
"return",
"{",
"index",
":",
"index",
",",
"store",
":",
"documentsStore",
",",
"}",
"}"
] | Generate a Lunr index.
Iterates over the specified pages and creates a Lunr index.
@memberof generate-index
@param {Object} playbook - The configuration object for Antora.
@param {Object} playbook.site - Site-related configuration data.
@param {String} playbook.site.url - The base URL of the site.
@param {Array<File>} pages - The publishable pages to map.
@returns {Object} An JSON object with a Lunr index and a documents store. | [
"Generate",
"a",
"Lunr",
"index",
"."
] | 4126ac53cfead104e8742f2d00e797afdec7c252 | https://github.com/Mogztter/antora-lunr/blob/4126ac53cfead104e8742f2d00e797afdec7c252/lib/generate-index.js#L21-L96 |
21,237 | midudev/react-slidy | src/slidy.js | _translate | function _translate(duration, ease = '', x = false) {
slidesDOMEl.style.cssText = getTranslationCSS(duration, ease, index, x)
} | javascript | function _translate(duration, ease = '', x = false) {
slidesDOMEl.style.cssText = getTranslationCSS(duration, ease, index, x)
} | [
"function",
"_translate",
"(",
"duration",
",",
"ease",
"=",
"''",
",",
"x",
"=",
"false",
")",
"{",
"slidesDOMEl",
".",
"style",
".",
"cssText",
"=",
"getTranslationCSS",
"(",
"duration",
",",
"ease",
",",
"index",
",",
"x",
")",
"}"
] | translates to a given position in a given time in milliseconds
@duration {number} time in milliseconds for the transistion
@ease {string} easing css property
@x {number} Number of pixels to fine tuning translation | [
"translates",
"to",
"a",
"given",
"position",
"in",
"a",
"given",
"time",
"in",
"milliseconds"
] | 81fbc58d7984af3ef3fb8000e0795f8435c0df7d | https://github.com/midudev/react-slidy/blob/81fbc58d7984af3ef3fb8000e0795f8435c0df7d/src/slidy.js#L72-L74 |
21,238 | midudev/react-slidy | src/slidy.js | slide | function slide(direction) {
const movement = direction === true ? 1 : -1
let duration = slideSpeed
// calculate the nextIndex according to the movement
let nextIndex = index + 1 * movement
// nextIndex should be between 0 and items minus 1
nextIndex = clampNumber(nextIndex, 0, items - 1)
// if the nextIndex and the current is the same, we don't need to do the slide
if (nextIndex === index) return
// if the nextIndex is possible according to number of items, then use it
if (nextIndex <= items) {
// execute the callback from the options before sliding
doBeforeSlide({currentSlide: index, nextSlide: nextIndex})
// execute the internal callback
direction ? onNext(nextIndex) : onPrev(nextIndex)
index = nextIndex
}
// translate to the next index by a defined duration and ease function
_translate(duration, ease)
// execute the callback from the options after sliding
slidesDOMEl.addEventListener(TRANSITION_END, function cb(e) {
doAfterSlide({currentSlide: index})
e.currentTarget.removeEventListener(e.type, cb)
})
} | javascript | function slide(direction) {
const movement = direction === true ? 1 : -1
let duration = slideSpeed
// calculate the nextIndex according to the movement
let nextIndex = index + 1 * movement
// nextIndex should be between 0 and items minus 1
nextIndex = clampNumber(nextIndex, 0, items - 1)
// if the nextIndex and the current is the same, we don't need to do the slide
if (nextIndex === index) return
// if the nextIndex is possible according to number of items, then use it
if (nextIndex <= items) {
// execute the callback from the options before sliding
doBeforeSlide({currentSlide: index, nextSlide: nextIndex})
// execute the internal callback
direction ? onNext(nextIndex) : onPrev(nextIndex)
index = nextIndex
}
// translate to the next index by a defined duration and ease function
_translate(duration, ease)
// execute the callback from the options after sliding
slidesDOMEl.addEventListener(TRANSITION_END, function cb(e) {
doAfterSlide({currentSlide: index})
e.currentTarget.removeEventListener(e.type, cb)
})
} | [
"function",
"slide",
"(",
"direction",
")",
"{",
"const",
"movement",
"=",
"direction",
"===",
"true",
"?",
"1",
":",
"-",
"1",
"let",
"duration",
"=",
"slideSpeed",
"// calculate the nextIndex according to the movement",
"let",
"nextIndex",
"=",
"index",
"+",
"1",
"*",
"movement",
"// nextIndex should be between 0 and items minus 1",
"nextIndex",
"=",
"clampNumber",
"(",
"nextIndex",
",",
"0",
",",
"items",
"-",
"1",
")",
"// if the nextIndex and the current is the same, we don't need to do the slide",
"if",
"(",
"nextIndex",
"===",
"index",
")",
"return",
"// if the nextIndex is possible according to number of items, then use it",
"if",
"(",
"nextIndex",
"<=",
"items",
")",
"{",
"// execute the callback from the options before sliding",
"doBeforeSlide",
"(",
"{",
"currentSlide",
":",
"index",
",",
"nextSlide",
":",
"nextIndex",
"}",
")",
"// execute the internal callback",
"direction",
"?",
"onNext",
"(",
"nextIndex",
")",
":",
"onPrev",
"(",
"nextIndex",
")",
"index",
"=",
"nextIndex",
"}",
"// translate to the next index by a defined duration and ease function",
"_translate",
"(",
"duration",
",",
"ease",
")",
"// execute the callback from the options after sliding",
"slidesDOMEl",
".",
"addEventListener",
"(",
"TRANSITION_END",
",",
"function",
"cb",
"(",
"e",
")",
"{",
"doAfterSlide",
"(",
"{",
"currentSlide",
":",
"index",
"}",
")",
"e",
".",
"currentTarget",
".",
"removeEventListener",
"(",
"e",
".",
"type",
",",
"cb",
")",
"}",
")",
"}"
] | slide function called by prev, next & touchend
determine nextIndex and slide to next postion
under restrictions of the defined options
@direction {boolean} 'true' for right, 'false' for left | [
"slide",
"function",
"called",
"by",
"prev",
"next",
"&",
"touchend"
] | 81fbc58d7984af3ef3fb8000e0795f8435c0df7d | https://github.com/midudev/react-slidy/blob/81fbc58d7984af3ef3fb8000e0795f8435c0df7d/src/slidy.js#L84-L114 |
21,239 | midudev/react-slidy | src/slidy.js | _setup | function _setup() {
slidesDOMEl.addEventListener(TRANSITION_END, onTransitionEnd)
containerDOMEl.addEventListener('touchstart', onTouchstart, EVENT_OPTIONS)
containerDOMEl.addEventListener('touchmove', onTouchmove, EVENT_OPTIONS)
containerDOMEl.addEventListener('touchend', onTouchend, EVENT_OPTIONS)
if (index !== 0) {
_translate(0)
}
} | javascript | function _setup() {
slidesDOMEl.addEventListener(TRANSITION_END, onTransitionEnd)
containerDOMEl.addEventListener('touchstart', onTouchstart, EVENT_OPTIONS)
containerDOMEl.addEventListener('touchmove', onTouchmove, EVENT_OPTIONS)
containerDOMEl.addEventListener('touchend', onTouchend, EVENT_OPTIONS)
if (index !== 0) {
_translate(0)
}
} | [
"function",
"_setup",
"(",
")",
"{",
"slidesDOMEl",
".",
"addEventListener",
"(",
"TRANSITION_END",
",",
"onTransitionEnd",
")",
"containerDOMEl",
".",
"addEventListener",
"(",
"'touchstart'",
",",
"onTouchstart",
",",
"EVENT_OPTIONS",
")",
"containerDOMEl",
".",
"addEventListener",
"(",
"'touchmove'",
",",
"onTouchmove",
",",
"EVENT_OPTIONS",
")",
"containerDOMEl",
".",
"addEventListener",
"(",
"'touchend'",
",",
"onTouchend",
",",
"EVENT_OPTIONS",
")",
"if",
"(",
"index",
"!==",
"0",
")",
"{",
"_translate",
"(",
"0",
")",
"}",
"}"
] | public
setup function | [
"public",
"setup",
"function"
] | 81fbc58d7984af3ef3fb8000e0795f8435c0df7d | https://github.com/midudev/react-slidy/blob/81fbc58d7984af3ef3fb8000e0795f8435c0df7d/src/slidy.js#L202-L211 |
21,240 | globant-ui/arialinter | lib/rules/element.js | function(options) {
return {
element: options.element,
name: 'Do not use ' + options.element + ' element',
message: 'Please remove the ' + options.element + ' element',
ruleUrl: options.ruleUrl,
level: options.level,
template: true,
callback: createGenericCallback(options.element)
};
} | javascript | function(options) {
return {
element: options.element,
name: 'Do not use ' + options.element + ' element',
message: 'Please remove the ' + options.element + ' element',
ruleUrl: options.ruleUrl,
level: options.level,
template: true,
callback: createGenericCallback(options.element)
};
} | [
"function",
"(",
"options",
")",
"{",
"return",
"{",
"element",
":",
"options",
".",
"element",
",",
"name",
":",
"'Do not use '",
"+",
"options",
".",
"element",
"+",
"' element'",
",",
"message",
":",
"'Please remove the '",
"+",
"options",
".",
"element",
"+",
"' element'",
",",
"ruleUrl",
":",
"options",
".",
"ruleUrl",
",",
"level",
":",
"options",
".",
"level",
",",
"template",
":",
"true",
",",
"callback",
":",
"createGenericCallback",
"(",
"options",
".",
"element",
")",
"}",
";",
"}"
] | Creates an options json that stores the options for a generic rule. | [
"Creates",
"an",
"options",
"json",
"that",
"stores",
"the",
"options",
"for",
"a",
"generic",
"rule",
"."
] | edc9ef953a142df398fa6c2cb118239055acc623 | https://github.com/globant-ui/arialinter/blob/edc9ef953a142df398fa6c2cb118239055acc623/lib/rules/element.js#L23-L33 | |
21,241 | globant-ui/arialinter | build/lib/rulefactory.js | function(element) {
'use strict';
return function(dom, reporter) {
var that = this;
dom.$(element).each(function(index, item){
reporter.error(that.message, 0, that.name);
throw dom.$(item).parent().html();
});
};
} | javascript | function(element) {
'use strict';
return function(dom, reporter) {
var that = this;
dom.$(element).each(function(index, item){
reporter.error(that.message, 0, that.name);
throw dom.$(item).parent().html();
});
};
} | [
"function",
"(",
"element",
")",
"{",
"'use strict'",
";",
"return",
"function",
"(",
"dom",
",",
"reporter",
")",
"{",
"var",
"that",
"=",
"this",
";",
"dom",
".",
"$",
"(",
"element",
")",
".",
"each",
"(",
"function",
"(",
"index",
",",
"item",
")",
"{",
"reporter",
".",
"error",
"(",
"that",
".",
"message",
",",
"0",
",",
"that",
".",
"name",
")",
";",
"throw",
"dom",
".",
"$",
"(",
"item",
")",
".",
"parent",
"(",
")",
".",
"html",
"(",
")",
";",
"}",
")",
";",
"}",
";",
"}"
] | RuleFactory object.
Decouples rule creation from AriaLinter
Given an element, generates a function that checks that that element is not in the dom. | [
"RuleFactory",
"object",
".",
"Decouples",
"rule",
"creation",
"from",
"AriaLinter",
"Given",
"an",
"element",
"generates",
"a",
"function",
"that",
"checks",
"that",
"that",
"element",
"is",
"not",
"in",
"the",
"dom",
"."
] | edc9ef953a142df398fa6c2cb118239055acc623 | https://github.com/globant-ui/arialinter/blob/edc9ef953a142df398fa6c2cb118239055acc623/build/lib/rulefactory.js#L11-L23 | |
21,242 | retrohacker/getos | index.js | customLogic | function customLogic (os, name, file, cb) {
var logic = './logic/' + name + '.js'
try { require(logic)(os, file, cb) } catch (e) { cb(null, os) }
} | javascript | function customLogic (os, name, file, cb) {
var logic = './logic/' + name + '.js'
try { require(logic)(os, file, cb) } catch (e) { cb(null, os) }
} | [
"function",
"customLogic",
"(",
"os",
",",
"name",
",",
"file",
",",
"cb",
")",
"{",
"var",
"logic",
"=",
"'./logic/'",
"+",
"name",
"+",
"'.js'",
"try",
"{",
"require",
"(",
"logic",
")",
"(",
"os",
",",
"file",
",",
"cb",
")",
"}",
"catch",
"(",
"e",
")",
"{",
"cb",
"(",
"null",
",",
"os",
")",
"}",
"}"
] | Loads a custom logic module to populate additional distribution information | [
"Loads",
"a",
"custom",
"logic",
"module",
"to",
"populate",
"additional",
"distribution",
"information"
] | c58eef6b097f105de0957897f8c134df07437b67 | https://github.com/retrohacker/getos/blob/c58eef6b097f105de0957897f8c134df07437b67/index.js#L122-L125 |
21,243 | braintree/restricted-input | lib/restricted-input.js | RestrictedInput | function RestrictedInput(options) {
options = options || {};
if (!isValidElement(options.element)) {
throw new Error(constants.errors.INVALID_ELEMENT);
}
if (!options.pattern) {
throw new Error(constants.errors.PATTERN_MISSING);
}
if (!RestrictedInput.supportsFormatting()) {
this.strategy = new NoopStrategy(options);
} else if (device.isIos()) {
this.strategy = new IosStrategy(options);
} else if (device.isKitKatWebview()) {
this.strategy = new KitKatChromiumBasedWebViewStrategy(options);
} else if (device.isAndroidChrome()) {
this.strategy = new AndroidChromeStrategy(options);
} else if (device.isIE9()) {
this.strategy = new IE9Strategy(options);
} else {
this.strategy = new BaseStrategy(options);
}
} | javascript | function RestrictedInput(options) {
options = options || {};
if (!isValidElement(options.element)) {
throw new Error(constants.errors.INVALID_ELEMENT);
}
if (!options.pattern) {
throw new Error(constants.errors.PATTERN_MISSING);
}
if (!RestrictedInput.supportsFormatting()) {
this.strategy = new NoopStrategy(options);
} else if (device.isIos()) {
this.strategy = new IosStrategy(options);
} else if (device.isKitKatWebview()) {
this.strategy = new KitKatChromiumBasedWebViewStrategy(options);
} else if (device.isAndroidChrome()) {
this.strategy = new AndroidChromeStrategy(options);
} else if (device.isIE9()) {
this.strategy = new IE9Strategy(options);
} else {
this.strategy = new BaseStrategy(options);
}
} | [
"function",
"RestrictedInput",
"(",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"if",
"(",
"!",
"isValidElement",
"(",
"options",
".",
"element",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"constants",
".",
"errors",
".",
"INVALID_ELEMENT",
")",
";",
"}",
"if",
"(",
"!",
"options",
".",
"pattern",
")",
"{",
"throw",
"new",
"Error",
"(",
"constants",
".",
"errors",
".",
"PATTERN_MISSING",
")",
";",
"}",
"if",
"(",
"!",
"RestrictedInput",
".",
"supportsFormatting",
"(",
")",
")",
"{",
"this",
".",
"strategy",
"=",
"new",
"NoopStrategy",
"(",
"options",
")",
";",
"}",
"else",
"if",
"(",
"device",
".",
"isIos",
"(",
")",
")",
"{",
"this",
".",
"strategy",
"=",
"new",
"IosStrategy",
"(",
"options",
")",
";",
"}",
"else",
"if",
"(",
"device",
".",
"isKitKatWebview",
"(",
")",
")",
"{",
"this",
".",
"strategy",
"=",
"new",
"KitKatChromiumBasedWebViewStrategy",
"(",
"options",
")",
";",
"}",
"else",
"if",
"(",
"device",
".",
"isAndroidChrome",
"(",
")",
")",
"{",
"this",
".",
"strategy",
"=",
"new",
"AndroidChromeStrategy",
"(",
"options",
")",
";",
"}",
"else",
"if",
"(",
"device",
".",
"isIE9",
"(",
")",
")",
"{",
"this",
".",
"strategy",
"=",
"new",
"IE9Strategy",
"(",
"options",
")",
";",
"}",
"else",
"{",
"this",
".",
"strategy",
"=",
"new",
"BaseStrategy",
"(",
"options",
")",
";",
"}",
"}"
] | Instances of this class can be used to modify the formatter for an input
@class
@param {object} options The initialization paramaters for this class
@param {object} options.element - A Input DOM object that RestrictedInput operates on
@param {string} options.pattern - The pattern to enforce on this element | [
"Instances",
"of",
"this",
"class",
"can",
"be",
"used",
"to",
"modify",
"the",
"formatter",
"for",
"an",
"input"
] | 62dffd19c890f0c7008707f869eb9526e80f6748 | https://github.com/braintree/restricted-input/blob/62dffd19c890f0c7008707f869eb9526e80f6748/lib/restricted-input.js#L21-L45 |
21,244 | ds300/derivablejs | resources/js/sticky.js | Sticky | function Sticky(head, title, toc, page, gradientBit) {
page.style.paddingTop = maxHeadHeight;
head.style.height = maxHeadHeight + "px";
var padding = minHeadPadding + ((maxHeadPadding - minHeadPadding) * ((maxHeadHeight - minHeadHeight) / (maxHeadHeight - minHeadHeight)));
head.style.padding = padding + "px 0px";
title.style.fontSize = (maxHeadHeight - (padding * 2)) * 0.7;
var pageScroll = Derivable.atom(window.scrollY);
var tocScroll = Derivable.atom(toc.scrollTop);
window.addEventListener('scroll', function () { pageScroll.set(window.scrollY); });
toc.addEventListener('scroll', function () { tocScroll.set(this.scrollTop); });
var headHeight = pageScroll.derive(function (scroll) {
return Math.max(maxHeadHeight - scroll, minHeadHeight);
});
headHeight.react(function (headHeight) {
spacer.style.height = headHeight + "px";
gradientBit.style.marginTop = headHeight + "px";
var scale = headHeight / maxHeadHeight;
head.style.transform = "scale("+scale+","+scale+")";
});
var gradientOpacity = tocScroll.derive(function (scroll) {
return Math.min(scroll / 20, 1);
});
gradientOpacity.react(function (opacity) {
gradientBit.style.opacity = opacity;
});
} | javascript | function Sticky(head, title, toc, page, gradientBit) {
page.style.paddingTop = maxHeadHeight;
head.style.height = maxHeadHeight + "px";
var padding = minHeadPadding + ((maxHeadPadding - minHeadPadding) * ((maxHeadHeight - minHeadHeight) / (maxHeadHeight - minHeadHeight)));
head.style.padding = padding + "px 0px";
title.style.fontSize = (maxHeadHeight - (padding * 2)) * 0.7;
var pageScroll = Derivable.atom(window.scrollY);
var tocScroll = Derivable.atom(toc.scrollTop);
window.addEventListener('scroll', function () { pageScroll.set(window.scrollY); });
toc.addEventListener('scroll', function () { tocScroll.set(this.scrollTop); });
var headHeight = pageScroll.derive(function (scroll) {
return Math.max(maxHeadHeight - scroll, minHeadHeight);
});
headHeight.react(function (headHeight) {
spacer.style.height = headHeight + "px";
gradientBit.style.marginTop = headHeight + "px";
var scale = headHeight / maxHeadHeight;
head.style.transform = "scale("+scale+","+scale+")";
});
var gradientOpacity = tocScroll.derive(function (scroll) {
return Math.min(scroll / 20, 1);
});
gradientOpacity.react(function (opacity) {
gradientBit.style.opacity = opacity;
});
} | [
"function",
"Sticky",
"(",
"head",
",",
"title",
",",
"toc",
",",
"page",
",",
"gradientBit",
")",
"{",
"page",
".",
"style",
".",
"paddingTop",
"=",
"maxHeadHeight",
";",
"head",
".",
"style",
".",
"height",
"=",
"maxHeadHeight",
"+",
"\"px\"",
";",
"var",
"padding",
"=",
"minHeadPadding",
"+",
"(",
"(",
"maxHeadPadding",
"-",
"minHeadPadding",
")",
"*",
"(",
"(",
"maxHeadHeight",
"-",
"minHeadHeight",
")",
"/",
"(",
"maxHeadHeight",
"-",
"minHeadHeight",
")",
")",
")",
";",
"head",
".",
"style",
".",
"padding",
"=",
"padding",
"+",
"\"px 0px\"",
";",
"title",
".",
"style",
".",
"fontSize",
"=",
"(",
"maxHeadHeight",
"-",
"(",
"padding",
"*",
"2",
")",
")",
"*",
"0.7",
";",
"var",
"pageScroll",
"=",
"Derivable",
".",
"atom",
"(",
"window",
".",
"scrollY",
")",
";",
"var",
"tocScroll",
"=",
"Derivable",
".",
"atom",
"(",
"toc",
".",
"scrollTop",
")",
";",
"window",
".",
"addEventListener",
"(",
"'scroll'",
",",
"function",
"(",
")",
"{",
"pageScroll",
".",
"set",
"(",
"window",
".",
"scrollY",
")",
";",
"}",
")",
";",
"toc",
".",
"addEventListener",
"(",
"'scroll'",
",",
"function",
"(",
")",
"{",
"tocScroll",
".",
"set",
"(",
"this",
".",
"scrollTop",
")",
";",
"}",
")",
";",
"var",
"headHeight",
"=",
"pageScroll",
".",
"derive",
"(",
"function",
"(",
"scroll",
")",
"{",
"return",
"Math",
".",
"max",
"(",
"maxHeadHeight",
"-",
"scroll",
",",
"minHeadHeight",
")",
";",
"}",
")",
";",
"headHeight",
".",
"react",
"(",
"function",
"(",
"headHeight",
")",
"{",
"spacer",
".",
"style",
".",
"height",
"=",
"headHeight",
"+",
"\"px\"",
";",
"gradientBit",
".",
"style",
".",
"marginTop",
"=",
"headHeight",
"+",
"\"px\"",
";",
"var",
"scale",
"=",
"headHeight",
"/",
"maxHeadHeight",
";",
"head",
".",
"style",
".",
"transform",
"=",
"\"scale(\"",
"+",
"scale",
"+",
"\",\"",
"+",
"scale",
"+",
"\")\"",
";",
"}",
")",
";",
"var",
"gradientOpacity",
"=",
"tocScroll",
".",
"derive",
"(",
"function",
"(",
"scroll",
")",
"{",
"return",
"Math",
".",
"min",
"(",
"scroll",
"/",
"20",
",",
"1",
")",
";",
"}",
")",
";",
"gradientOpacity",
".",
"react",
"(",
"function",
"(",
"opacity",
")",
"{",
"gradientBit",
".",
"style",
".",
"opacity",
"=",
"opacity",
";",
"}",
")",
";",
"}"
] | assumes offset parent is at top for the sake of simplicity | [
"assumes",
"offset",
"parent",
"is",
"at",
"top",
"for",
"the",
"sake",
"of",
"simplicity"
] | f334daa1950940d09751f86630ce9af2041f9b69 | https://github.com/ds300/derivablejs/blob/f334daa1950940d09751f86630ce9af2041f9b69/resources/js/sticky.js#L10-L41 |
21,245 | ds300/derivablejs | examples/bmi-calculator-advanced/react/main.js | cm2feetInches | function cm2feetInches (cm) {
const totalInches = (cm * 0.393701);
let feet = Math.floor(totalInches / 12);
let inches = Math.round(totalInches - (feet * 12));
if (inches === 12) {
feet += 1;
inches = 0;
}
return { feet, inches };
} | javascript | function cm2feetInches (cm) {
const totalInches = (cm * 0.393701);
let feet = Math.floor(totalInches / 12);
let inches = Math.round(totalInches - (feet * 12));
if (inches === 12) {
feet += 1;
inches = 0;
}
return { feet, inches };
} | [
"function",
"cm2feetInches",
"(",
"cm",
")",
"{",
"const",
"totalInches",
"=",
"(",
"cm",
"*",
"0.393701",
")",
";",
"let",
"feet",
"=",
"Math",
".",
"floor",
"(",
"totalInches",
"/",
"12",
")",
";",
"let",
"inches",
"=",
"Math",
".",
"round",
"(",
"totalInches",
"-",
"(",
"feet",
"*",
"12",
")",
")",
";",
"if",
"(",
"inches",
"===",
"12",
")",
"{",
"feet",
"+=",
"1",
";",
"inches",
"=",
"0",
";",
"}",
"return",
"{",
"feet",
",",
"inches",
"}",
";",
"}"
] | convert a length in centimters to feet and inches components,
rounding to the nearest inch | [
"convert",
"a",
"length",
"in",
"centimters",
"to",
"feet",
"and",
"inches",
"components",
"rounding",
"to",
"the",
"nearest",
"inch"
] | f334daa1950940d09751f86630ce9af2041f9b69 | https://github.com/ds300/derivablejs/blob/f334daa1950940d09751f86630ce9af2041f9b69/examples/bmi-calculator-advanced/react/main.js#L18-L27 |
21,246 | TooTallNate/pcre-to-regexp | index.js | PCRE | function PCRE (pattern, namedCaptures) {
pattern = String(pattern || '').trim();
var originalPattern = pattern;
var delim;
var flags = '';
// A delimiter can be any non-alphanumeric, non-backslash,
// non-whitespace character.
var hasDelim = /^[^a-zA-Z\\\s]/.test(pattern);
if (hasDelim) {
delim = pattern[0];
var lastDelimIndex = pattern.lastIndexOf(delim);
// pull out the flags in the pattern
flags += pattern.substring(lastDelimIndex + 1);
// strip the delims from the pattern
pattern = pattern.substring(1, lastDelimIndex);
}
// populate namedCaptures array and removed named captures from the `pattern`
var numGroups = 0;
pattern = replaceCaptureGroups(pattern, function (group) {
if (/^\(\?[P<']/.test(group)) {
// PCRE-style "named capture"
// It is possible to name a subpattern using the syntax (?P<name>pattern).
// This subpattern will then be indexed in the matches array by its normal
// numeric position and also by name. PHP 5.2.2 introduced two alternative
// syntaxes (?<name>pattern) and (?'name'pattern).
var match = /^\(\?P?[<']([^>']+)[>']/.exec(group);
var capture = group.substring(match[0].length, group.length - 1);
if (namedCaptures) {
namedCaptures[numGroups] = match[1];
}
numGroups++;
return '(' + capture + ')';
} else if ('(?:' === group.substring(0, 3)) {
// non-capture group, leave untouched
return group;
} else {
// regular capture, leave untouched
numGroups++;
return group;
}
});
// replace "character classes" with their raw RegExp equivalent
pattern = pattern.replace(/\[\:([^\:]+)\:\]/g, function (characterClass, name) {
return exports.characterClasses[name] || characterClass;
});
// TODO: convert PCRE-only flags to JS
// TODO: handle lots more stuff....
// http://www.php.net/manual/en/reference.pcre.pattern.syntax.php
var regexp = new RegExp(pattern, flags);
regexp.delimiter = delim;
regexp.pcrePattern = originalPattern;
regexp.pcreFlags = flags;
return regexp;
} | javascript | function PCRE (pattern, namedCaptures) {
pattern = String(pattern || '').trim();
var originalPattern = pattern;
var delim;
var flags = '';
// A delimiter can be any non-alphanumeric, non-backslash,
// non-whitespace character.
var hasDelim = /^[^a-zA-Z\\\s]/.test(pattern);
if (hasDelim) {
delim = pattern[0];
var lastDelimIndex = pattern.lastIndexOf(delim);
// pull out the flags in the pattern
flags += pattern.substring(lastDelimIndex + 1);
// strip the delims from the pattern
pattern = pattern.substring(1, lastDelimIndex);
}
// populate namedCaptures array and removed named captures from the `pattern`
var numGroups = 0;
pattern = replaceCaptureGroups(pattern, function (group) {
if (/^\(\?[P<']/.test(group)) {
// PCRE-style "named capture"
// It is possible to name a subpattern using the syntax (?P<name>pattern).
// This subpattern will then be indexed in the matches array by its normal
// numeric position and also by name. PHP 5.2.2 introduced two alternative
// syntaxes (?<name>pattern) and (?'name'pattern).
var match = /^\(\?P?[<']([^>']+)[>']/.exec(group);
var capture = group.substring(match[0].length, group.length - 1);
if (namedCaptures) {
namedCaptures[numGroups] = match[1];
}
numGroups++;
return '(' + capture + ')';
} else if ('(?:' === group.substring(0, 3)) {
// non-capture group, leave untouched
return group;
} else {
// regular capture, leave untouched
numGroups++;
return group;
}
});
// replace "character classes" with their raw RegExp equivalent
pattern = pattern.replace(/\[\:([^\:]+)\:\]/g, function (characterClass, name) {
return exports.characterClasses[name] || characterClass;
});
// TODO: convert PCRE-only flags to JS
// TODO: handle lots more stuff....
// http://www.php.net/manual/en/reference.pcre.pattern.syntax.php
var regexp = new RegExp(pattern, flags);
regexp.delimiter = delim;
regexp.pcrePattern = originalPattern;
regexp.pcreFlags = flags;
return regexp;
} | [
"function",
"PCRE",
"(",
"pattern",
",",
"namedCaptures",
")",
"{",
"pattern",
"=",
"String",
"(",
"pattern",
"||",
"''",
")",
".",
"trim",
"(",
")",
";",
"var",
"originalPattern",
"=",
"pattern",
";",
"var",
"delim",
";",
"var",
"flags",
"=",
"''",
";",
"// A delimiter can be any non-alphanumeric, non-backslash,",
"// non-whitespace character.",
"var",
"hasDelim",
"=",
"/",
"^[^a-zA-Z\\\\\\s]",
"/",
".",
"test",
"(",
"pattern",
")",
";",
"if",
"(",
"hasDelim",
")",
"{",
"delim",
"=",
"pattern",
"[",
"0",
"]",
";",
"var",
"lastDelimIndex",
"=",
"pattern",
".",
"lastIndexOf",
"(",
"delim",
")",
";",
"// pull out the flags in the pattern",
"flags",
"+=",
"pattern",
".",
"substring",
"(",
"lastDelimIndex",
"+",
"1",
")",
";",
"// strip the delims from the pattern",
"pattern",
"=",
"pattern",
".",
"substring",
"(",
"1",
",",
"lastDelimIndex",
")",
";",
"}",
"// populate namedCaptures array and removed named captures from the `pattern`",
"var",
"numGroups",
"=",
"0",
";",
"pattern",
"=",
"replaceCaptureGroups",
"(",
"pattern",
",",
"function",
"(",
"group",
")",
"{",
"if",
"(",
"/",
"^\\(\\?[P<']",
"/",
".",
"test",
"(",
"group",
")",
")",
"{",
"// PCRE-style \"named capture\"",
"// It is possible to name a subpattern using the syntax (?P<name>pattern).",
"// This subpattern will then be indexed in the matches array by its normal",
"// numeric position and also by name. PHP 5.2.2 introduced two alternative",
"// syntaxes (?<name>pattern) and (?'name'pattern).",
"var",
"match",
"=",
"/",
"^\\(\\?P?[<']([^>']+)[>']",
"/",
".",
"exec",
"(",
"group",
")",
";",
"var",
"capture",
"=",
"group",
".",
"substring",
"(",
"match",
"[",
"0",
"]",
".",
"length",
",",
"group",
".",
"length",
"-",
"1",
")",
";",
"if",
"(",
"namedCaptures",
")",
"{",
"namedCaptures",
"[",
"numGroups",
"]",
"=",
"match",
"[",
"1",
"]",
";",
"}",
"numGroups",
"++",
";",
"return",
"'('",
"+",
"capture",
"+",
"')'",
";",
"}",
"else",
"if",
"(",
"'(?:'",
"===",
"group",
".",
"substring",
"(",
"0",
",",
"3",
")",
")",
"{",
"// non-capture group, leave untouched",
"return",
"group",
";",
"}",
"else",
"{",
"// regular capture, leave untouched",
"numGroups",
"++",
";",
"return",
"group",
";",
"}",
"}",
")",
";",
"// replace \"character classes\" with their raw RegExp equivalent",
"pattern",
"=",
"pattern",
".",
"replace",
"(",
"/",
"\\[\\:([^\\:]+)\\:\\]",
"/",
"g",
",",
"function",
"(",
"characterClass",
",",
"name",
")",
"{",
"return",
"exports",
".",
"characterClasses",
"[",
"name",
"]",
"||",
"characterClass",
";",
"}",
")",
";",
"// TODO: convert PCRE-only flags to JS",
"// TODO: handle lots more stuff....",
"// http://www.php.net/manual/en/reference.pcre.pattern.syntax.php",
"var",
"regexp",
"=",
"new",
"RegExp",
"(",
"pattern",
",",
"flags",
")",
";",
"regexp",
".",
"delimiter",
"=",
"delim",
";",
"regexp",
".",
"pcrePattern",
"=",
"originalPattern",
";",
"regexp",
".",
"pcreFlags",
"=",
"flags",
";",
"return",
"regexp",
";",
"}"
] | Returns a JavaScript RegExp instance from the given PCRE-compatible string.
Flags may be passed in after the final delimiter in the `format` string.
An empty array may be passsed in as the second argument, which will be
populated with the "named capture group" names as Strings in the Array,
once the RegExp has been returned.
@param {String} pattern - PCRE regexp string to compile to a JS RegExp
@param {Array} [namedCaptures] - optional empty array, which will be populated with the named captures extracted from the PCRE regexp
@return {RegExp} returns a JavaScript RegExp instance from the given `pattern` and optionally `flags`
@public | [
"Returns",
"a",
"JavaScript",
"RegExp",
"instance",
"from",
"the",
"given",
"PCRE",
"-",
"compatible",
"string",
".",
"Flags",
"may",
"be",
"passed",
"in",
"after",
"the",
"final",
"delimiter",
"in",
"the",
"format",
"string",
"."
] | e8446efcce02d606bdded76a8359c196fda9e93c | https://github.com/TooTallNate/pcre-to-regexp/blob/e8446efcce02d606bdded76a8359c196fda9e93c/index.js#L45-L107 |
21,247 | TooTallNate/pcre-to-regexp | index.js | replaceCaptureGroups | function replaceCaptureGroups (pattern, fn) {
var start;
var depth = 0;
var escaped = false;
for (var i = 0; i < pattern.length; i++) {
var cur = pattern[i];
if (escaped) {
// skip this letter, it's been escaped
escaped = false;
continue;
}
switch (cur) {
case '(':
// we're only interested in groups when the depth reaches 0
if (0 === depth) {
start = i;
}
depth++;
break;
case ')':
if (depth > 0) {
depth--;
// we're only interested in groups when the depth reaches 0
if (0 === depth) {
var end = i + 1;
var l = start === 0 ? '' : pattern.substring(0, start);
var r = pattern.substring(end);
var v = String(fn(pattern.substring(start, end)));
pattern = l + v + r;
i = start;
}
}
break;
case '\\':
escaped = true;
break;
}
}
return pattern;
} | javascript | function replaceCaptureGroups (pattern, fn) {
var start;
var depth = 0;
var escaped = false;
for (var i = 0; i < pattern.length; i++) {
var cur = pattern[i];
if (escaped) {
// skip this letter, it's been escaped
escaped = false;
continue;
}
switch (cur) {
case '(':
// we're only interested in groups when the depth reaches 0
if (0 === depth) {
start = i;
}
depth++;
break;
case ')':
if (depth > 0) {
depth--;
// we're only interested in groups when the depth reaches 0
if (0 === depth) {
var end = i + 1;
var l = start === 0 ? '' : pattern.substring(0, start);
var r = pattern.substring(end);
var v = String(fn(pattern.substring(start, end)));
pattern = l + v + r;
i = start;
}
}
break;
case '\\':
escaped = true;
break;
}
}
return pattern;
} | [
"function",
"replaceCaptureGroups",
"(",
"pattern",
",",
"fn",
")",
"{",
"var",
"start",
";",
"var",
"depth",
"=",
"0",
";",
"var",
"escaped",
"=",
"false",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"pattern",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"cur",
"=",
"pattern",
"[",
"i",
"]",
";",
"if",
"(",
"escaped",
")",
"{",
"// skip this letter, it's been escaped",
"escaped",
"=",
"false",
";",
"continue",
";",
"}",
"switch",
"(",
"cur",
")",
"{",
"case",
"'('",
":",
"// we're only interested in groups when the depth reaches 0",
"if",
"(",
"0",
"===",
"depth",
")",
"{",
"start",
"=",
"i",
";",
"}",
"depth",
"++",
";",
"break",
";",
"case",
"')'",
":",
"if",
"(",
"depth",
">",
"0",
")",
"{",
"depth",
"--",
";",
"// we're only interested in groups when the depth reaches 0",
"if",
"(",
"0",
"===",
"depth",
")",
"{",
"var",
"end",
"=",
"i",
"+",
"1",
";",
"var",
"l",
"=",
"start",
"===",
"0",
"?",
"''",
":",
"pattern",
".",
"substring",
"(",
"0",
",",
"start",
")",
";",
"var",
"r",
"=",
"pattern",
".",
"substring",
"(",
"end",
")",
";",
"var",
"v",
"=",
"String",
"(",
"fn",
"(",
"pattern",
".",
"substring",
"(",
"start",
",",
"end",
")",
")",
")",
";",
"pattern",
"=",
"l",
"+",
"v",
"+",
"r",
";",
"i",
"=",
"start",
";",
"}",
"}",
"break",
";",
"case",
"'\\\\'",
":",
"escaped",
"=",
"true",
";",
"break",
";",
"}",
"}",
"return",
"pattern",
";",
"}"
] | Invokes `fn` for each "capture group" encountered in the PCRE `pattern`,
and inserts the returned value into the pattern instead of the capture
group itself.
@private | [
"Invokes",
"fn",
"for",
"each",
"capture",
"group",
"encountered",
"in",
"the",
"PCRE",
"pattern",
"and",
"inserts",
"the",
"returned",
"value",
"into",
"the",
"pattern",
"instead",
"of",
"the",
"capture",
"group",
"itself",
"."
] | e8446efcce02d606bdded76a8359c196fda9e93c | https://github.com/TooTallNate/pcre-to-regexp/blob/e8446efcce02d606bdded76a8359c196fda9e93c/index.js#L117-L158 |
21,248 | gl-vis/gl-plot3d | scene.js | renderPick | function renderPick() {
if(checkContextLoss()) {
return
}
gl.colorMask(true, true, true, true)
gl.depthMask(true)
gl.disable(gl.BLEND)
gl.enable(gl.DEPTH_TEST)
var numObjs = objects.length
var numPick = pickBuffers.length
for(var j=0; j<numPick; ++j) {
var buf = pickBuffers[j]
buf.shape = pickShape
buf.begin()
for(var i=0; i<numObjs; ++i) {
if(pickBufferIds[i] !== j) {
continue
}
var obj = objects[i]
if(obj.drawPick) {
obj.pixelRatio = 1
obj.drawPick(cameraParams)
}
}
buf.end()
}
} | javascript | function renderPick() {
if(checkContextLoss()) {
return
}
gl.colorMask(true, true, true, true)
gl.depthMask(true)
gl.disable(gl.BLEND)
gl.enable(gl.DEPTH_TEST)
var numObjs = objects.length
var numPick = pickBuffers.length
for(var j=0; j<numPick; ++j) {
var buf = pickBuffers[j]
buf.shape = pickShape
buf.begin()
for(var i=0; i<numObjs; ++i) {
if(pickBufferIds[i] !== j) {
continue
}
var obj = objects[i]
if(obj.drawPick) {
obj.pixelRatio = 1
obj.drawPick(cameraParams)
}
}
buf.end()
}
} | [
"function",
"renderPick",
"(",
")",
"{",
"if",
"(",
"checkContextLoss",
"(",
")",
")",
"{",
"return",
"}",
"gl",
".",
"colorMask",
"(",
"true",
",",
"true",
",",
"true",
",",
"true",
")",
"gl",
".",
"depthMask",
"(",
"true",
")",
"gl",
".",
"disable",
"(",
"gl",
".",
"BLEND",
")",
"gl",
".",
"enable",
"(",
"gl",
".",
"DEPTH_TEST",
")",
"var",
"numObjs",
"=",
"objects",
".",
"length",
"var",
"numPick",
"=",
"pickBuffers",
".",
"length",
"for",
"(",
"var",
"j",
"=",
"0",
";",
"j",
"<",
"numPick",
";",
"++",
"j",
")",
"{",
"var",
"buf",
"=",
"pickBuffers",
"[",
"j",
"]",
"buf",
".",
"shape",
"=",
"pickShape",
"buf",
".",
"begin",
"(",
")",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"numObjs",
";",
"++",
"i",
")",
"{",
"if",
"(",
"pickBufferIds",
"[",
"i",
"]",
"!==",
"j",
")",
"{",
"continue",
"}",
"var",
"obj",
"=",
"objects",
"[",
"i",
"]",
"if",
"(",
"obj",
".",
"drawPick",
")",
"{",
"obj",
".",
"pixelRatio",
"=",
"1",
"obj",
".",
"drawPick",
"(",
"cameraParams",
")",
"}",
"}",
"buf",
".",
"end",
"(",
")",
"}",
"}"
] | Render the scene for mouse picking | [
"Render",
"the",
"scene",
"for",
"mouse",
"picking"
] | 43b2412ed8107dea33a0c8886e506be3e1d82613 | https://github.com/gl-vis/gl-plot3d/blob/43b2412ed8107dea33a0c8886e506be3e1d82613/scene.js#L459-L487 |
21,249 | ipfs-shipyard/peer-crdt | src/types/treedoc.js | walkDepthFirst | function walkDepthFirst (tree, visitor) {
const val = walkDepthFirstRecursive(tree, visitor)
if (val !== undefined) {
return val
} else {
return visitor(null)
}
} | javascript | function walkDepthFirst (tree, visitor) {
const val = walkDepthFirstRecursive(tree, visitor)
if (val !== undefined) {
return val
} else {
return visitor(null)
}
} | [
"function",
"walkDepthFirst",
"(",
"tree",
",",
"visitor",
")",
"{",
"const",
"val",
"=",
"walkDepthFirstRecursive",
"(",
"tree",
",",
"visitor",
")",
"if",
"(",
"val",
"!==",
"undefined",
")",
"{",
"return",
"val",
"}",
"else",
"{",
"return",
"visitor",
"(",
"null",
")",
"}",
"}"
] | Walk the tree | [
"Walk",
"the",
"tree"
] | ba6b30a65d4bf932dfdb5a0f68e1c03495cb594e | https://github.com/ipfs-shipyard/peer-crdt/blob/ba6b30a65d4bf932dfdb5a0f68e1c03495cb594e/src/types/treedoc.js#L341-L348 |
21,250 | ipfs-shipyard/peer-crdt | src/types/treedoc.js | newPosId | function newPosId (p, f) {
const pPath = p && p[0]
const fPath = f && f[0]
let path
let uid
if (pPath && fPath && isSibling(pPath, fPath)) {
path = [pPath[0], pPath[1]]
if (f[1].length > p[1].length) {
const difference = f[1].substring(p[1].length)
uid = p[1] + halfOf(difference) + cuid()
} else {
uid = p[1] + cuid()
}
} else {
path = newPath(pPath, fPath)
uid = cuid()
}
return [path, uid]
} | javascript | function newPosId (p, f) {
const pPath = p && p[0]
const fPath = f && f[0]
let path
let uid
if (pPath && fPath && isSibling(pPath, fPath)) {
path = [pPath[0], pPath[1]]
if (f[1].length > p[1].length) {
const difference = f[1].substring(p[1].length)
uid = p[1] + halfOf(difference) + cuid()
} else {
uid = p[1] + cuid()
}
} else {
path = newPath(pPath, fPath)
uid = cuid()
}
return [path, uid]
} | [
"function",
"newPosId",
"(",
"p",
",",
"f",
")",
"{",
"const",
"pPath",
"=",
"p",
"&&",
"p",
"[",
"0",
"]",
"const",
"fPath",
"=",
"f",
"&&",
"f",
"[",
"0",
"]",
"let",
"path",
"let",
"uid",
"if",
"(",
"pPath",
"&&",
"fPath",
"&&",
"isSibling",
"(",
"pPath",
",",
"fPath",
")",
")",
"{",
"path",
"=",
"[",
"pPath",
"[",
"0",
"]",
",",
"pPath",
"[",
"1",
"]",
"]",
"if",
"(",
"f",
"[",
"1",
"]",
".",
"length",
">",
"p",
"[",
"1",
"]",
".",
"length",
")",
"{",
"const",
"difference",
"=",
"f",
"[",
"1",
"]",
".",
"substring",
"(",
"p",
"[",
"1",
"]",
".",
"length",
")",
"uid",
"=",
"p",
"[",
"1",
"]",
"+",
"halfOf",
"(",
"difference",
")",
"+",
"cuid",
"(",
")",
"}",
"else",
"{",
"uid",
"=",
"p",
"[",
"1",
"]",
"+",
"cuid",
"(",
")",
"}",
"}",
"else",
"{",
"path",
"=",
"newPath",
"(",
"pPath",
",",
"fPath",
")",
"uid",
"=",
"cuid",
"(",
")",
"}",
"return",
"[",
"path",
",",
"uid",
"]",
"}"
] | PosIds and Paths | [
"PosIds",
"and",
"Paths"
] | ba6b30a65d4bf932dfdb5a0f68e1c03495cb594e | https://github.com/ipfs-shipyard/peer-crdt/blob/ba6b30a65d4bf932dfdb5a0f68e1c03495cb594e/src/types/treedoc.js#L402-L421 |
21,251 | gl-vis/regl-scatter2d | bundle.js | color | function color(c, group) {
if (c == null) c = Scatter.defaults.color;
c = _this3.updateColor(c);
hasColor++;
return c;
} | javascript | function color(c, group) {
if (c == null) c = Scatter.defaults.color;
c = _this3.updateColor(c);
hasColor++;
return c;
} | [
"function",
"color",
"(",
"c",
",",
"group",
")",
"{",
"if",
"(",
"c",
"==",
"null",
")",
"c",
"=",
"Scatter",
".",
"defaults",
".",
"color",
";",
"c",
"=",
"_this3",
".",
"updateColor",
"(",
"c",
")",
";",
"hasColor",
"++",
";",
"return",
"c",
";",
"}"
] | add colors to palette, save references | [
"add",
"colors",
"to",
"palette",
"save",
"references"
] | cda45ae30e5e1f841d65ced2404c9e36a618415f | https://github.com/gl-vis/regl-scatter2d/blob/cda45ae30e5e1f841d65ced2404c9e36a618415f/bundle.js#L556-L561 |
21,252 | gl-vis/regl-scatter2d | bundle.js | marker | function marker(markers, group, options) {
var activation = group.activation; // reset marker elements
activation.forEach(function (buffer) {
return buffer && buffer.destroy && buffer.destroy();
});
activation.length = 0; // single sdf marker
if (!markers || typeof markers[0] === 'number') {
var id = _this3.addMarker(markers);
activation[id] = true;
} // per-point markers use mask buffers to enable markers in vert shader
else {
var markerMasks = [];
for (var _i = 0, l = Math.min(markers.length, group.count); _i < l; _i++) {
var _id = _this3.addMarker(markers[_i]);
if (!markerMasks[_id]) markerMasks[_id] = new Uint8Array(group.count); // enable marker by default
markerMasks[_id][_i] = 1;
}
for (var _id2 = 0; _id2 < markerMasks.length; _id2++) {
if (!markerMasks[_id2]) continue;
var opts = {
data: markerMasks[_id2],
type: 'uint8',
usage: 'static'
};
if (!activation[_id2]) {
activation[_id2] = regl.buffer(opts);
} else {
activation[_id2](opts);
}
activation[_id2].data = markerMasks[_id2];
}
}
return markers;
} | javascript | function marker(markers, group, options) {
var activation = group.activation; // reset marker elements
activation.forEach(function (buffer) {
return buffer && buffer.destroy && buffer.destroy();
});
activation.length = 0; // single sdf marker
if (!markers || typeof markers[0] === 'number') {
var id = _this3.addMarker(markers);
activation[id] = true;
} // per-point markers use mask buffers to enable markers in vert shader
else {
var markerMasks = [];
for (var _i = 0, l = Math.min(markers.length, group.count); _i < l; _i++) {
var _id = _this3.addMarker(markers[_i]);
if (!markerMasks[_id]) markerMasks[_id] = new Uint8Array(group.count); // enable marker by default
markerMasks[_id][_i] = 1;
}
for (var _id2 = 0; _id2 < markerMasks.length; _id2++) {
if (!markerMasks[_id2]) continue;
var opts = {
data: markerMasks[_id2],
type: 'uint8',
usage: 'static'
};
if (!activation[_id2]) {
activation[_id2] = regl.buffer(opts);
} else {
activation[_id2](opts);
}
activation[_id2].data = markerMasks[_id2];
}
}
return markers;
} | [
"function",
"marker",
"(",
"markers",
",",
"group",
",",
"options",
")",
"{",
"var",
"activation",
"=",
"group",
".",
"activation",
";",
"// reset marker elements",
"activation",
".",
"forEach",
"(",
"function",
"(",
"buffer",
")",
"{",
"return",
"buffer",
"&&",
"buffer",
".",
"destroy",
"&&",
"buffer",
".",
"destroy",
"(",
")",
";",
"}",
")",
";",
"activation",
".",
"length",
"=",
"0",
";",
"// single sdf marker",
"if",
"(",
"!",
"markers",
"||",
"typeof",
"markers",
"[",
"0",
"]",
"===",
"'number'",
")",
"{",
"var",
"id",
"=",
"_this3",
".",
"addMarker",
"(",
"markers",
")",
";",
"activation",
"[",
"id",
"]",
"=",
"true",
";",
"}",
"// per-point markers use mask buffers to enable markers in vert shader",
"else",
"{",
"var",
"markerMasks",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"_i",
"=",
"0",
",",
"l",
"=",
"Math",
".",
"min",
"(",
"markers",
".",
"length",
",",
"group",
".",
"count",
")",
";",
"_i",
"<",
"l",
";",
"_i",
"++",
")",
"{",
"var",
"_id",
"=",
"_this3",
".",
"addMarker",
"(",
"markers",
"[",
"_i",
"]",
")",
";",
"if",
"(",
"!",
"markerMasks",
"[",
"_id",
"]",
")",
"markerMasks",
"[",
"_id",
"]",
"=",
"new",
"Uint8Array",
"(",
"group",
".",
"count",
")",
";",
"// enable marker by default",
"markerMasks",
"[",
"_id",
"]",
"[",
"_i",
"]",
"=",
"1",
";",
"}",
"for",
"(",
"var",
"_id2",
"=",
"0",
";",
"_id2",
"<",
"markerMasks",
".",
"length",
";",
"_id2",
"++",
")",
"{",
"if",
"(",
"!",
"markerMasks",
"[",
"_id2",
"]",
")",
"continue",
";",
"var",
"opts",
"=",
"{",
"data",
":",
"markerMasks",
"[",
"_id2",
"]",
",",
"type",
":",
"'uint8'",
",",
"usage",
":",
"'static'",
"}",
";",
"if",
"(",
"!",
"activation",
"[",
"_id2",
"]",
")",
"{",
"activation",
"[",
"_id2",
"]",
"=",
"regl",
".",
"buffer",
"(",
"opts",
")",
";",
"}",
"else",
"{",
"activation",
"[",
"_id2",
"]",
"(",
"opts",
")",
";",
"}",
"activation",
"[",
"_id2",
"]",
".",
"data",
"=",
"markerMasks",
"[",
"_id2",
"]",
";",
"}",
"}",
"return",
"markers",
";",
"}"
] | create marker ids corresponding to known marker textures | [
"create",
"marker",
"ids",
"corresponding",
"to",
"known",
"marker",
"textures"
] | cda45ae30e5e1f841d65ced2404c9e36a618415f | https://github.com/gl-vis/regl-scatter2d/blob/cda45ae30e5e1f841d65ced2404c9e36a618415f/bundle.js#L669-L712 |
21,253 | iyobo/jollofjs | packages/jollof/lib/data/jollofql/index.js | jql | function jql(queryChunks, ...injects) {
try {
let res = '';
for (let i = 0; i < injects.length; i++) {
let value = injects[i];
let q = queryChunks[i];
if (typeof value === 'string') {
//make string value safe
value = cleanString(value);
}
else if (Array.isArray(value)) {
//We do not support nested arrays or objects
value = value.map((it) => {
if (Array.isArray(it))
throw new Error('JQL: Nested arrays not supported . Consider using a nativeFunction for that query instead.')
if (typeof it === 'string') {
//make string value safe
it = cleanString(it);
}
return it;
})
value = "(" + value.join(', ') + ")";
}
res += q + value;
}
res += queryChunks[queryChunks.length - 1];
//console.log('query:', res);
return res;
} catch (err) {
throw new Boom.badRequest('Bad JQL:', err)
}
} | javascript | function jql(queryChunks, ...injects) {
try {
let res = '';
for (let i = 0; i < injects.length; i++) {
let value = injects[i];
let q = queryChunks[i];
if (typeof value === 'string') {
//make string value safe
value = cleanString(value);
}
else if (Array.isArray(value)) {
//We do not support nested arrays or objects
value = value.map((it) => {
if (Array.isArray(it))
throw new Error('JQL: Nested arrays not supported . Consider using a nativeFunction for that query instead.')
if (typeof it === 'string') {
//make string value safe
it = cleanString(it);
}
return it;
})
value = "(" + value.join(', ') + ")";
}
res += q + value;
}
res += queryChunks[queryChunks.length - 1];
//console.log('query:', res);
return res;
} catch (err) {
throw new Boom.badRequest('Bad JQL:', err)
}
} | [
"function",
"jql",
"(",
"queryChunks",
",",
"...",
"injects",
")",
"{",
"try",
"{",
"let",
"res",
"=",
"''",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"injects",
".",
"length",
";",
"i",
"++",
")",
"{",
"let",
"value",
"=",
"injects",
"[",
"i",
"]",
";",
"let",
"q",
"=",
"queryChunks",
"[",
"i",
"]",
";",
"if",
"(",
"typeof",
"value",
"===",
"'string'",
")",
"{",
"//make string value safe",
"value",
"=",
"cleanString",
"(",
"value",
")",
";",
"}",
"else",
"if",
"(",
"Array",
".",
"isArray",
"(",
"value",
")",
")",
"{",
"//We do not support nested arrays or objects",
"value",
"=",
"value",
".",
"map",
"(",
"(",
"it",
")",
"=>",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"it",
")",
")",
"throw",
"new",
"Error",
"(",
"'JQL: Nested arrays not supported . Consider using a nativeFunction for that query instead.'",
")",
"if",
"(",
"typeof",
"it",
"===",
"'string'",
")",
"{",
"//make string value safe",
"it",
"=",
"cleanString",
"(",
"it",
")",
";",
"}",
"return",
"it",
";",
"}",
")",
"value",
"=",
"\"(\"",
"+",
"value",
".",
"join",
"(",
"', '",
")",
"+",
"\")\"",
";",
"}",
"res",
"+=",
"q",
"+",
"value",
";",
"}",
"res",
"+=",
"queryChunks",
"[",
"queryChunks",
".",
"length",
"-",
"1",
"]",
";",
"//console.log('query:', res);",
"return",
"res",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"throw",
"new",
"Boom",
".",
"badRequest",
"(",
"'Bad JQL:'",
",",
"err",
")",
"}",
"}"
] | A tag to be used with ES6 string literals to prevent JQL injection.
Helps to build JQL queries.
@param queryChunks
@param injects
@returns {string} | [
"A",
"tag",
"to",
"be",
"used",
"with",
"ES6",
"string",
"literals",
"to",
"prevent",
"JQL",
"injection",
".",
"Helps",
"to",
"build",
"JQL",
"queries",
"."
] | faae48701d9476189c39a29552a4dcacd550d6aa | https://github.com/iyobo/jollofjs/blob/faae48701d9476189c39a29552a4dcacd550d6aa/packages/jollof/lib/data/jollofql/index.js#L19-L65 |
21,254 | commenthol/astronomia | src/planetary.js | Ca | function Ca (A, B, M0, M1) {
this.A = A
this.B = B
this.M0 = M0
this.M1 = M1
} | javascript | function Ca (A, B, M0, M1) {
this.A = A
this.B = B
this.M0 = M0
this.M1 = M1
} | [
"function",
"Ca",
"(",
"A",
",",
"B",
",",
"M0",
",",
"M1",
")",
"{",
"this",
".",
"A",
"=",
"A",
"this",
".",
"B",
"=",
"B",
"this",
".",
"M0",
"=",
"M0",
"this",
".",
"M1",
"=",
"M1",
"}"
] | ca holds coefficients from one line of table 36.A, p. 250 | [
"ca",
"holds",
"coefficients",
"from",
"one",
"line",
"of",
"table",
"36",
".",
"A",
"p",
".",
"250"
] | 3882325be11589186b84dd023c559ed06c4e1145 | https://github.com/commenthol/astronomia/blob/3882325be11589186b84dd023c559ed06c4e1145/src/planetary.js#L202-L207 |
21,255 | iyobo/jollofjs | packages/jollof/lib/data/modelizer.js | identifyRefsInSchemaFields | function identifyRefsInSchemaFields(structure, prefix) {
_.each(structure.schema, (fieldStructure, fieldName) => {
const name = prefix ? prefix + '.' + fieldName : fieldName;
//If field has a schema, then it is a collection
if (fieldStructure.schema) {
// is this an object or an array?
if (fieldStructure.meta && fieldStructure.meta.type === 'Array') {
//array
identifyRefsInSchemaFields(fieldStructure, name + '.*')
} else {
//object. loop through schema.fields
identifyRefsInSchemaFields(fieldStructure, name)
}
} else if (fieldStructure.meta && fieldStructure.meta.ref) {
//ref field found!
refFields[name] = 1;
}
});
} | javascript | function identifyRefsInSchemaFields(structure, prefix) {
_.each(structure.schema, (fieldStructure, fieldName) => {
const name = prefix ? prefix + '.' + fieldName : fieldName;
//If field has a schema, then it is a collection
if (fieldStructure.schema) {
// is this an object or an array?
if (fieldStructure.meta && fieldStructure.meta.type === 'Array') {
//array
identifyRefsInSchemaFields(fieldStructure, name + '.*')
} else {
//object. loop through schema.fields
identifyRefsInSchemaFields(fieldStructure, name)
}
} else if (fieldStructure.meta && fieldStructure.meta.ref) {
//ref field found!
refFields[name] = 1;
}
});
} | [
"function",
"identifyRefsInSchemaFields",
"(",
"structure",
",",
"prefix",
")",
"{",
"_",
".",
"each",
"(",
"structure",
".",
"schema",
",",
"(",
"fieldStructure",
",",
"fieldName",
")",
"=>",
"{",
"const",
"name",
"=",
"prefix",
"?",
"prefix",
"+",
"'.'",
"+",
"fieldName",
":",
"fieldName",
";",
"//If field has a schema, then it is a collection",
"if",
"(",
"fieldStructure",
".",
"schema",
")",
"{",
"// is this an object or an array?",
"if",
"(",
"fieldStructure",
".",
"meta",
"&&",
"fieldStructure",
".",
"meta",
".",
"type",
"===",
"'Array'",
")",
"{",
"//array",
"identifyRefsInSchemaFields",
"(",
"fieldStructure",
",",
"name",
"+",
"'.*'",
")",
"}",
"else",
"{",
"//object. loop through schema.fields",
"identifyRefsInSchemaFields",
"(",
"fieldStructure",
",",
"name",
")",
"}",
"}",
"else",
"if",
"(",
"fieldStructure",
".",
"meta",
"&&",
"fieldStructure",
".",
"meta",
".",
"ref",
")",
"{",
"//ref field found!",
"refFields",
"[",
"name",
"]",
"=",
"1",
";",
"}",
"}",
")",
";",
"}"
] | Identify all refs in the structure and store path names of ref fields
@param criteria | [
"Identify",
"all",
"refs",
"in",
"the",
"structure",
"and",
"store",
"path",
"names",
"of",
"ref",
"fields"
] | faae48701d9476189c39a29552a4dcacd550d6aa | https://github.com/iyobo/jollofjs/blob/faae48701d9476189c39a29552a4dcacd550d6aa/packages/jollof/lib/data/modelizer.js#L126-L151 |
21,256 | iyobo/jollofjs | packages/jollof/lib/util/fileUtil.js | function (str) {
return str.replace
(/(^[a-z]+)|[0-9]+|[A-Z][a-z]+|[A-Z]+(?=[A-Z][a-z]|[0-9])/g
, function (match, first) {
if (first) match = match[0].toUpperCase() + match.substr(1);
return match + ' ';
}
)
} | javascript | function (str) {
return str.replace
(/(^[a-z]+)|[0-9]+|[A-Z][a-z]+|[A-Z]+(?=[A-Z][a-z]|[0-9])/g
, function (match, first) {
if (first) match = match[0].toUpperCase() + match.substr(1);
return match + ' ';
}
)
} | [
"function",
"(",
"str",
")",
"{",
"return",
"str",
".",
"replace",
"(",
"/",
"(^[a-z]+)|[0-9]+|[A-Z][a-z]+|[A-Z]+(?=[A-Z][a-z]|[0-9])",
"/",
"g",
",",
"function",
"(",
"match",
",",
"first",
")",
"{",
"if",
"(",
"first",
")",
"match",
"=",
"match",
"[",
"0",
"]",
".",
"toUpperCase",
"(",
")",
"+",
"match",
".",
"substr",
"(",
"1",
")",
";",
"return",
"match",
"+",
"' '",
";",
"}",
")",
"}"
] | Stores a file depending on app-specified file storage engine
@param str
@returns {*} | [
"Stores",
"a",
"file",
"depending",
"on",
"app",
"-",
"specified",
"file",
"storage",
"engine"
] | faae48701d9476189c39a29552a4dcacd550d6aa | https://github.com/iyobo/jollofjs/blob/faae48701d9476189c39a29552a4dcacd550d6aa/packages/jollof/lib/util/fileUtil.js#L11-L19 | |
21,257 | commenthol/astronomia | src/sexagesimal.js | modf | function modf (float) {
const i = Math.trunc(float)
const f = Math.abs(float - i)
return [i, f]
} | javascript | function modf (float) {
const i = Math.trunc(float)
const f = Math.abs(float - i)
return [i, f]
} | [
"function",
"modf",
"(",
"float",
")",
"{",
"const",
"i",
"=",
"Math",
".",
"trunc",
"(",
"float",
")",
"const",
"f",
"=",
"Math",
".",
"abs",
"(",
"float",
"-",
"i",
")",
"return",
"[",
"i",
",",
"f",
"]",
"}"
] | separate fix `i` from fraction `f`
@private
@param {Number} float
@returns {Array} [i, f]
{Number} i - (int) fix value
{Number} f - (float) fractional portion; always > 1 | [
"separate",
"fix",
"i",
"from",
"fraction",
"f"
] | 3882325be11589186b84dd023c559ed06c4e1145 | https://github.com/commenthol/astronomia/blob/3882325be11589186b84dd023c559ed06c4e1145/src/sexagesimal.js#L357-L361 |
21,258 | commenthol/astronomia | src/sexagesimal.js | round | function round (float, precision) {
precision = (precision === undefined ? 10 : precision)
return parseFloat(float.toFixed(precision), 10)
} | javascript | function round (float, precision) {
precision = (precision === undefined ? 10 : precision)
return parseFloat(float.toFixed(precision), 10)
} | [
"function",
"round",
"(",
"float",
",",
"precision",
")",
"{",
"precision",
"=",
"(",
"precision",
"===",
"undefined",
"?",
"10",
":",
"precision",
")",
"return",
"parseFloat",
"(",
"float",
".",
"toFixed",
"(",
"precision",
")",
",",
"10",
")",
"}"
] | Rounds `float` value by precision
@private
@param {Number} float - value to round
@param {Number} precision - (int) number of post decimal positions
@return {Number} rounded `float` | [
"Rounds",
"float",
"value",
"by",
"precision"
] | 3882325be11589186b84dd023c559ed06c4e1145 | https://github.com/commenthol/astronomia/blob/3882325be11589186b84dd023c559ed06c4e1145/src/sexagesimal.js#L370-L373 |
21,259 | commenthol/astronomia | src/rise.js | _compatibility | function _compatibility (rs) {
const _rs = [rs.rise, rs.transit, rs.set]
_rs.rise = rs.rise
_rs.transit = rs.transit
_rs.set = rs.set
return _rs
} | javascript | function _compatibility (rs) {
const _rs = [rs.rise, rs.transit, rs.set]
_rs.rise = rs.rise
_rs.transit = rs.transit
_rs.set = rs.set
return _rs
} | [
"function",
"_compatibility",
"(",
"rs",
")",
"{",
"const",
"_rs",
"=",
"[",
"rs",
".",
"rise",
",",
"rs",
".",
"transit",
",",
"rs",
".",
"set",
"]",
"_rs",
".",
"rise",
"=",
"rs",
".",
"rise",
"_rs",
".",
"transit",
"=",
"rs",
".",
"transit",
"_rs",
".",
"set",
"=",
"rs",
".",
"set",
"return",
"_rs",
"}"
] | maintain backward compatibility - will be removed in v2 return value in future will be an object not an array | [
"maintain",
"backward",
"compatibility",
"-",
"will",
"be",
"removed",
"in",
"v2",
"return",
"value",
"in",
"future",
"will",
"be",
"an",
"object",
"not",
"an",
"array"
] | 3882325be11589186b84dd023c559ed06c4e1145 | https://github.com/commenthol/astronomia/blob/3882325be11589186b84dd023c559ed06c4e1145/src/rise.js#L135-L141 |
21,260 | commenthol/astronomia | src/deltat.js | interpolate | function interpolate (dyear, data) {
const d3 = interp.len3ForInterpolateX(dyear,
data.first, data.last, data.table
)
return d3.interpolateX(dyear)
} | javascript | function interpolate (dyear, data) {
const d3 = interp.len3ForInterpolateX(dyear,
data.first, data.last, data.table
)
return d3.interpolateX(dyear)
} | [
"function",
"interpolate",
"(",
"dyear",
",",
"data",
")",
"{",
"const",
"d3",
"=",
"interp",
".",
"len3ForInterpolateX",
"(",
"dyear",
",",
"data",
".",
"first",
",",
"data",
".",
"last",
",",
"data",
".",
"table",
")",
"return",
"d3",
".",
"interpolateX",
"(",
"dyear",
")",
"}"
] | interpolation of dataset
@private
@param {Number} dyear - julian year
@returns {Number} ΔT in seconds. | [
"interpolation",
"of",
"dataset"
] | 3882325be11589186b84dd023c559ed06c4e1145 | https://github.com/commenthol/astronomia/blob/3882325be11589186b84dd023c559ed06c4e1145/src/deltat.js#L86-L91 |
21,261 | commenthol/astronomia | src/deltat.js | interpolateData | function interpolateData (dyear, data) {
const [fyear, fmonth] = data.firstYM
const {year, month, first, last} = monthOfYear(dyear)
const pos = 12 * (year - fyear) + (month - fmonth)
const table = data.table.slice(pos, pos + 3)
const d3 = new interp.Len3(first, last, table)
return d3.interpolateX(dyear)
} | javascript | function interpolateData (dyear, data) {
const [fyear, fmonth] = data.firstYM
const {year, month, first, last} = monthOfYear(dyear)
const pos = 12 * (year - fyear) + (month - fmonth)
const table = data.table.slice(pos, pos + 3)
const d3 = new interp.Len3(first, last, table)
return d3.interpolateX(dyear)
} | [
"function",
"interpolateData",
"(",
"dyear",
",",
"data",
")",
"{",
"const",
"[",
"fyear",
",",
"fmonth",
"]",
"=",
"data",
".",
"firstYM",
"const",
"{",
"year",
",",
"month",
",",
"first",
",",
"last",
"}",
"=",
"monthOfYear",
"(",
"dyear",
")",
"const",
"pos",
"=",
"12",
"*",
"(",
"year",
"-",
"fyear",
")",
"+",
"(",
"month",
"-",
"fmonth",
")",
"const",
"table",
"=",
"data",
".",
"table",
".",
"slice",
"(",
"pos",
",",
"pos",
"+",
"3",
")",
"const",
"d3",
"=",
"new",
"interp",
".",
"Len3",
"(",
"first",
",",
"last",
",",
"table",
")",
"return",
"d3",
".",
"interpolateX",
"(",
"dyear",
")",
"}"
] | interpolation of dataset from finals2000A with is one entry per month
linear interpolation over whole dataset is inaccurate as points per month
are not equidistant. Therefore points are approximated using 2nd diff. interpolation
from current month using the following two points
@private
@param {Number} dyear - julian year
@returns {Number} ΔT in seconds. | [
"interpolation",
"of",
"dataset",
"from",
"finals2000A",
"with",
"is",
"one",
"entry",
"per",
"month",
"linear",
"interpolation",
"over",
"whole",
"dataset",
"is",
"inaccurate",
"as",
"points",
"per",
"month",
"are",
"not",
"equidistant",
".",
"Therefore",
"points",
"are",
"approximated",
"using",
"2nd",
"diff",
".",
"interpolation",
"from",
"current",
"month",
"using",
"the",
"following",
"two",
"points"
] | 3882325be11589186b84dd023c559ed06c4e1145 | https://github.com/commenthol/astronomia/blob/3882325be11589186b84dd023c559ed06c4e1145/src/deltat.js#L103-L110 |
21,262 | commenthol/astronomia | src/deltat.js | monthOfYear | function monthOfYear (dyear) {
if (!monthOfYear.data) { // memoize yearly fractions per month
monthOfYear.data = {0: [], 1: []}
for (let m = 0; m <= 12; m++) {
monthOfYear.data[0][m] = new Calendar(1999, m, 1).toYear() - 1999 // non leap year
monthOfYear.data[1][m] = new Calendar(2000, m, 1).toYear() - 2000 // leap year
}
}
const year = dyear | 0
const f = dyear - year
const d = LeapYearGregorian(year) ? 1 : 0
const data = monthOfYear.data[d]
let month = 12 // TODO loop could be improved
while (month > 0 && data[month] > f) {
month--
}
const first = year + data[month]
const last = month < 11 ? year + data[month + 2] : year + 1 + data[(month + 2) % 12]
return {year, month, first, last}
} | javascript | function monthOfYear (dyear) {
if (!monthOfYear.data) { // memoize yearly fractions per month
monthOfYear.data = {0: [], 1: []}
for (let m = 0; m <= 12; m++) {
monthOfYear.data[0][m] = new Calendar(1999, m, 1).toYear() - 1999 // non leap year
monthOfYear.data[1][m] = new Calendar(2000, m, 1).toYear() - 2000 // leap year
}
}
const year = dyear | 0
const f = dyear - year
const d = LeapYearGregorian(year) ? 1 : 0
const data = monthOfYear.data[d]
let month = 12 // TODO loop could be improved
while (month > 0 && data[month] > f) {
month--
}
const first = year + data[month]
const last = month < 11 ? year + data[month + 2] : year + 1 + data[(month + 2) % 12]
return {year, month, first, last}
} | [
"function",
"monthOfYear",
"(",
"dyear",
")",
"{",
"if",
"(",
"!",
"monthOfYear",
".",
"data",
")",
"{",
"// memoize yearly fractions per month",
"monthOfYear",
".",
"data",
"=",
"{",
"0",
":",
"[",
"]",
",",
"1",
":",
"[",
"]",
"}",
"for",
"(",
"let",
"m",
"=",
"0",
";",
"m",
"<=",
"12",
";",
"m",
"++",
")",
"{",
"monthOfYear",
".",
"data",
"[",
"0",
"]",
"[",
"m",
"]",
"=",
"new",
"Calendar",
"(",
"1999",
",",
"m",
",",
"1",
")",
".",
"toYear",
"(",
")",
"-",
"1999",
"// non leap year",
"monthOfYear",
".",
"data",
"[",
"1",
"]",
"[",
"m",
"]",
"=",
"new",
"Calendar",
"(",
"2000",
",",
"m",
",",
"1",
")",
".",
"toYear",
"(",
")",
"-",
"2000",
"// leap year",
"}",
"}",
"const",
"year",
"=",
"dyear",
"|",
"0",
"const",
"f",
"=",
"dyear",
"-",
"year",
"const",
"d",
"=",
"LeapYearGregorian",
"(",
"year",
")",
"?",
"1",
":",
"0",
"const",
"data",
"=",
"monthOfYear",
".",
"data",
"[",
"d",
"]",
"let",
"month",
"=",
"12",
"// TODO loop could be improved",
"while",
"(",
"month",
">",
"0",
"&&",
"data",
"[",
"month",
"]",
">",
"f",
")",
"{",
"month",
"--",
"}",
"const",
"first",
"=",
"year",
"+",
"data",
"[",
"month",
"]",
"const",
"last",
"=",
"month",
"<",
"11",
"?",
"year",
"+",
"data",
"[",
"month",
"+",
"2",
"]",
":",
"year",
"+",
"1",
"+",
"data",
"[",
"(",
"month",
"+",
"2",
")",
"%",
"12",
"]",
"return",
"{",
"year",
",",
"month",
",",
"first",
",",
"last",
"}",
"}"
] | Get month of Year from fraction. Fraction differs at leap years.
@private
@param {Number} dyear - decimal year
@return {Object} `{year: Number, month: Number, first: Number, last}` | [
"Get",
"month",
"of",
"Year",
"from",
"fraction",
".",
"Fraction",
"differs",
"at",
"leap",
"years",
"."
] | 3882325be11589186b84dd023c559ed06c4e1145 | https://github.com/commenthol/astronomia/blob/3882325be11589186b84dd023c559ed06c4e1145/src/deltat.js#L118-L138 |
21,263 | iyobo/jollofjs | packages/jollof/lib/admin/rClient/util/convertToFormData.js | appendRecursively | function appendRecursively(formData, collection, parentkey, parentIsArray) {
//console.log(...arguments)
for (let k in collection) {
const val = collection[k];
if (val === undefined) continue;
if (val instanceof File) {
let mkey = (parentkey ? parentkey + '.' : '') + k;
// if(parentIsArray)
// mkey = parentkey
// else
// mkey = k
val.foo = 'bar'
formData.append(mkey, val)
}
else if (Array.isArray(val)) {
let mkey = '';
if (parentIsArray) {
mkey = parentkey; //parentKey can/should never be empty if parentISarray
} else {
mkey = (parentkey ? parentkey + '.' + k : k);
}
appendRecursively(formData, val, mkey, true);
}
else if (typeof val === 'object') {
let mkey = (parentkey ? parentkey + '.' : '') + k;
appendRecursively(formData, val, mkey, false);
}
else {
let mkey = (parentkey ? parentkey + '.' : '') + k;
formData.append(mkey, val)
}
}
} | javascript | function appendRecursively(formData, collection, parentkey, parentIsArray) {
//console.log(...arguments)
for (let k in collection) {
const val = collection[k];
if (val === undefined) continue;
if (val instanceof File) {
let mkey = (parentkey ? parentkey + '.' : '') + k;
// if(parentIsArray)
// mkey = parentkey
// else
// mkey = k
val.foo = 'bar'
formData.append(mkey, val)
}
else if (Array.isArray(val)) {
let mkey = '';
if (parentIsArray) {
mkey = parentkey; //parentKey can/should never be empty if parentISarray
} else {
mkey = (parentkey ? parentkey + '.' + k : k);
}
appendRecursively(formData, val, mkey, true);
}
else if (typeof val === 'object') {
let mkey = (parentkey ? parentkey + '.' : '') + k;
appendRecursively(formData, val, mkey, false);
}
else {
let mkey = (parentkey ? parentkey + '.' : '') + k;
formData.append(mkey, val)
}
}
} | [
"function",
"appendRecursively",
"(",
"formData",
",",
"collection",
",",
"parentkey",
",",
"parentIsArray",
")",
"{",
"//console.log(...arguments)",
"for",
"(",
"let",
"k",
"in",
"collection",
")",
"{",
"const",
"val",
"=",
"collection",
"[",
"k",
"]",
";",
"if",
"(",
"val",
"===",
"undefined",
")",
"continue",
";",
"if",
"(",
"val",
"instanceof",
"File",
")",
"{",
"let",
"mkey",
"=",
"(",
"parentkey",
"?",
"parentkey",
"+",
"'.'",
":",
"''",
")",
"+",
"k",
";",
"// if(parentIsArray)",
"// \tmkey = parentkey",
"// else",
"// \tmkey = k",
"val",
".",
"foo",
"=",
"'bar'",
"formData",
".",
"append",
"(",
"mkey",
",",
"val",
")",
"}",
"else",
"if",
"(",
"Array",
".",
"isArray",
"(",
"val",
")",
")",
"{",
"let",
"mkey",
"=",
"''",
";",
"if",
"(",
"parentIsArray",
")",
"{",
"mkey",
"=",
"parentkey",
";",
"//parentKey can/should never be empty if parentISarray",
"}",
"else",
"{",
"mkey",
"=",
"(",
"parentkey",
"?",
"parentkey",
"+",
"'.'",
"+",
"k",
":",
"k",
")",
";",
"}",
"appendRecursively",
"(",
"formData",
",",
"val",
",",
"mkey",
",",
"true",
")",
";",
"}",
"else",
"if",
"(",
"typeof",
"val",
"===",
"'object'",
")",
"{",
"let",
"mkey",
"=",
"(",
"parentkey",
"?",
"parentkey",
"+",
"'.'",
":",
"''",
")",
"+",
"k",
";",
"appendRecursively",
"(",
"formData",
",",
"val",
",",
"mkey",
",",
"false",
")",
";",
"}",
"else",
"{",
"let",
"mkey",
"=",
"(",
"parentkey",
"?",
"parentkey",
"+",
"'.'",
":",
"''",
")",
"+",
"k",
";",
"formData",
".",
"append",
"(",
"mkey",
",",
"val",
")",
"}",
"}",
"}"
] | Created by iyobo on 2017-04-25. | [
"Created",
"by",
"iyobo",
"on",
"2017",
"-",
"04",
"-",
"25",
"."
] | faae48701d9476189c39a29552a4dcacd550d6aa | https://github.com/iyobo/jollofjs/blob/faae48701d9476189c39a29552a4dcacd550d6aa/packages/jollof/lib/admin/rClient/util/convertToFormData.js#L4-L46 |
21,264 | commenthol/astronomia | src/moonphase.js | snap | function snap (y, q) {
const k = (y - 2000) * 12.3685 // (49.2) p. 350
return Math.floor(k - q + 0.5) + q
} | javascript | function snap (y, q) {
const k = (y - 2000) * 12.3685 // (49.2) p. 350
return Math.floor(k - q + 0.5) + q
} | [
"function",
"snap",
"(",
"y",
",",
"q",
")",
"{",
"const",
"k",
"=",
"(",
"y",
"-",
"2000",
")",
"*",
"12.3685",
"// (49.2) p. 350",
"return",
"Math",
".",
"floor",
"(",
"k",
"-",
"q",
"+",
"0.5",
")",
"+",
"q",
"}"
] | snap returns k at specified quarter q nearest year y. | [
"snap",
"returns",
"k",
"at",
"specified",
"quarter",
"q",
"nearest",
"year",
"y",
"."
] | 3882325be11589186b84dd023c559ed06c4e1145 | https://github.com/commenthol/astronomia/blob/3882325be11589186b84dd023c559ed06c4e1145/src/moonphase.js#L29-L32 |
21,265 | jslicense/spdx-expression-parse.js | scan.js | read | function read (value) {
if (value instanceof RegExp) {
var chars = source.slice(index)
var match = chars.match(value)
if (match) {
index += match[0].length
return match[0]
}
} else {
if (source.indexOf(value, index) === index) {
index += value.length
return value
}
}
} | javascript | function read (value) {
if (value instanceof RegExp) {
var chars = source.slice(index)
var match = chars.match(value)
if (match) {
index += match[0].length
return match[0]
}
} else {
if (source.indexOf(value, index) === index) {
index += value.length
return value
}
}
} | [
"function",
"read",
"(",
"value",
")",
"{",
"if",
"(",
"value",
"instanceof",
"RegExp",
")",
"{",
"var",
"chars",
"=",
"source",
".",
"slice",
"(",
"index",
")",
"var",
"match",
"=",
"chars",
".",
"match",
"(",
"value",
")",
"if",
"(",
"match",
")",
"{",
"index",
"+=",
"match",
"[",
"0",
"]",
".",
"length",
"return",
"match",
"[",
"0",
"]",
"}",
"}",
"else",
"{",
"if",
"(",
"source",
".",
"indexOf",
"(",
"value",
",",
"index",
")",
"===",
"index",
")",
"{",
"index",
"+=",
"value",
".",
"length",
"return",
"value",
"}",
"}",
"}"
] | `value` can be a regexp or a string. If it is recognized, the matching source string is returned and the index is incremented. Otherwise `undefined` is returned. | [
"value",
"can",
"be",
"a",
"regexp",
"or",
"a",
"string",
".",
"If",
"it",
"is",
"recognized",
"the",
"matching",
"source",
"string",
"is",
"returned",
"and",
"the",
"index",
"is",
"incremented",
".",
"Otherwise",
"undefined",
"is",
"returned",
"."
] | 2cece31d85e721cf522436a17ccb4e990f4cd413 | https://github.com/jslicense/spdx-expression-parse.js/blob/2cece31d85e721cf522436a17ccb4e990f4cd413/scan.js#L18-L32 |
21,266 | kensho/ng-describe | dist/ng-describe.js | parse | function parse(string) {
var match = isoDateExpression.exec(string);
if (match) {
// parse months, days, hours, minutes, seconds, and milliseconds
// provide default values if necessary
// parse the UTC offset component
var year = $Number(match[1]),
month = $Number(match[2] || 1) - 1,
day = $Number(match[3] || 1) - 1,
hour = $Number(match[4] || 0),
minute = $Number(match[5] || 0),
second = $Number(match[6] || 0),
millisecond = Math.floor($Number(match[7] || 0) * 1000),
// When time zone is missed, local offset should be used
// (ES 5.1 bug)
// see https://bugs.ecmascript.org/show_bug.cgi?id=112
isLocalTime = Boolean(match[4] && !match[8]),
signOffset = match[9] === '-' ? 1 : -1,
hourOffset = $Number(match[10] || 0),
minuteOffset = $Number(match[11] || 0),
result;
var hasMinutesOrSecondsOrMilliseconds = minute > 0 || second > 0 || millisecond > 0;
if (
hour < (hasMinutesOrSecondsOrMilliseconds ? 24 : 25) &&
minute < 60 && second < 60 && millisecond < 1000 &&
month > -1 && month < 12 && hourOffset < 24 &&
minuteOffset < 60 && // detect invalid offsets
day > -1 &&
day < (dayFromMonth(year, month + 1) - dayFromMonth(year, month))
) {
result = (
(dayFromMonth(year, month) + day) * 24 +
hour +
hourOffset * signOffset
) * 60;
result = (
(result + minute + minuteOffset * signOffset) * 60 +
second
) * 1000 + millisecond;
if (isLocalTime) {
result = toUTC(result);
}
if (-8.64e15 <= result && result <= 8.64e15) {
return result;
}
}
return NaN;
}
return NativeDate.parse.apply(this, arguments);
} | javascript | function parse(string) {
var match = isoDateExpression.exec(string);
if (match) {
// parse months, days, hours, minutes, seconds, and milliseconds
// provide default values if necessary
// parse the UTC offset component
var year = $Number(match[1]),
month = $Number(match[2] || 1) - 1,
day = $Number(match[3] || 1) - 1,
hour = $Number(match[4] || 0),
minute = $Number(match[5] || 0),
second = $Number(match[6] || 0),
millisecond = Math.floor($Number(match[7] || 0) * 1000),
// When time zone is missed, local offset should be used
// (ES 5.1 bug)
// see https://bugs.ecmascript.org/show_bug.cgi?id=112
isLocalTime = Boolean(match[4] && !match[8]),
signOffset = match[9] === '-' ? 1 : -1,
hourOffset = $Number(match[10] || 0),
minuteOffset = $Number(match[11] || 0),
result;
var hasMinutesOrSecondsOrMilliseconds = minute > 0 || second > 0 || millisecond > 0;
if (
hour < (hasMinutesOrSecondsOrMilliseconds ? 24 : 25) &&
minute < 60 && second < 60 && millisecond < 1000 &&
month > -1 && month < 12 && hourOffset < 24 &&
minuteOffset < 60 && // detect invalid offsets
day > -1 &&
day < (dayFromMonth(year, month + 1) - dayFromMonth(year, month))
) {
result = (
(dayFromMonth(year, month) + day) * 24 +
hour +
hourOffset * signOffset
) * 60;
result = (
(result + minute + minuteOffset * signOffset) * 60 +
second
) * 1000 + millisecond;
if (isLocalTime) {
result = toUTC(result);
}
if (-8.64e15 <= result && result <= 8.64e15) {
return result;
}
}
return NaN;
}
return NativeDate.parse.apply(this, arguments);
} | [
"function",
"parse",
"(",
"string",
")",
"{",
"var",
"match",
"=",
"isoDateExpression",
".",
"exec",
"(",
"string",
")",
";",
"if",
"(",
"match",
")",
"{",
"// parse months, days, hours, minutes, seconds, and milliseconds",
"// provide default values if necessary",
"// parse the UTC offset component",
"var",
"year",
"=",
"$Number",
"(",
"match",
"[",
"1",
"]",
")",
",",
"month",
"=",
"$Number",
"(",
"match",
"[",
"2",
"]",
"||",
"1",
")",
"-",
"1",
",",
"day",
"=",
"$Number",
"(",
"match",
"[",
"3",
"]",
"||",
"1",
")",
"-",
"1",
",",
"hour",
"=",
"$Number",
"(",
"match",
"[",
"4",
"]",
"||",
"0",
")",
",",
"minute",
"=",
"$Number",
"(",
"match",
"[",
"5",
"]",
"||",
"0",
")",
",",
"second",
"=",
"$Number",
"(",
"match",
"[",
"6",
"]",
"||",
"0",
")",
",",
"millisecond",
"=",
"Math",
".",
"floor",
"(",
"$Number",
"(",
"match",
"[",
"7",
"]",
"||",
"0",
")",
"*",
"1000",
")",
",",
"// When time zone is missed, local offset should be used",
"// (ES 5.1 bug)",
"// see https://bugs.ecmascript.org/show_bug.cgi?id=112",
"isLocalTime",
"=",
"Boolean",
"(",
"match",
"[",
"4",
"]",
"&&",
"!",
"match",
"[",
"8",
"]",
")",
",",
"signOffset",
"=",
"match",
"[",
"9",
"]",
"===",
"'-'",
"?",
"1",
":",
"-",
"1",
",",
"hourOffset",
"=",
"$Number",
"(",
"match",
"[",
"10",
"]",
"||",
"0",
")",
",",
"minuteOffset",
"=",
"$Number",
"(",
"match",
"[",
"11",
"]",
"||",
"0",
")",
",",
"result",
";",
"var",
"hasMinutesOrSecondsOrMilliseconds",
"=",
"minute",
">",
"0",
"||",
"second",
">",
"0",
"||",
"millisecond",
">",
"0",
";",
"if",
"(",
"hour",
"<",
"(",
"hasMinutesOrSecondsOrMilliseconds",
"?",
"24",
":",
"25",
")",
"&&",
"minute",
"<",
"60",
"&&",
"second",
"<",
"60",
"&&",
"millisecond",
"<",
"1000",
"&&",
"month",
">",
"-",
"1",
"&&",
"month",
"<",
"12",
"&&",
"hourOffset",
"<",
"24",
"&&",
"minuteOffset",
"<",
"60",
"&&",
"// detect invalid offsets",
"day",
">",
"-",
"1",
"&&",
"day",
"<",
"(",
"dayFromMonth",
"(",
"year",
",",
"month",
"+",
"1",
")",
"-",
"dayFromMonth",
"(",
"year",
",",
"month",
")",
")",
")",
"{",
"result",
"=",
"(",
"(",
"dayFromMonth",
"(",
"year",
",",
"month",
")",
"+",
"day",
")",
"*",
"24",
"+",
"hour",
"+",
"hourOffset",
"*",
"signOffset",
")",
"*",
"60",
";",
"result",
"=",
"(",
"(",
"result",
"+",
"minute",
"+",
"minuteOffset",
"*",
"signOffset",
")",
"*",
"60",
"+",
"second",
")",
"*",
"1000",
"+",
"millisecond",
";",
"if",
"(",
"isLocalTime",
")",
"{",
"result",
"=",
"toUTC",
"(",
"result",
")",
";",
"}",
"if",
"(",
"-",
"8.64e15",
"<=",
"result",
"&&",
"result",
"<=",
"8.64e15",
")",
"{",
"return",
"result",
";",
"}",
"}",
"return",
"NaN",
";",
"}",
"return",
"NativeDate",
".",
"parse",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"}"
] | Upgrade Date.parse to handle simplified ISO 8601 strings | [
"Upgrade",
"Date",
".",
"parse",
"to",
"handle",
"simplified",
"ISO",
"8601",
"strings"
] | 884c4ac0cfdba88d248053c36fa4b672f735734b | https://github.com/kensho/ng-describe/blob/884c4ac0cfdba88d248053c36fa4b672f735734b/dist/ng-describe.js#L1501-L1550 |
21,267 | kensho/ng-describe | dist/ng-describe.js | sameLength | function sameLength(a, b) {
return typeof a === typeof b &&
a && b &&
a.length === b.length;
} | javascript | function sameLength(a, b) {
return typeof a === typeof b &&
a && b &&
a.length === b.length;
} | [
"function",
"sameLength",
"(",
"a",
",",
"b",
")",
"{",
"return",
"typeof",
"a",
"===",
"typeof",
"b",
"&&",
"a",
"&&",
"b",
"&&",
"a",
".",
"length",
"===",
"b",
".",
"length",
";",
"}"
] | Returns true if both objects are the same type and have same length property
@method sameLength | [
"Returns",
"true",
"if",
"both",
"objects",
"are",
"the",
"same",
"type",
"and",
"have",
"same",
"length",
"property"
] | 884c4ac0cfdba88d248053c36fa4b672f735734b | https://github.com/kensho/ng-describe/blob/884c4ac0cfdba88d248053c36fa4b672f735734b/dist/ng-describe.js#L2283-L2287 |
21,268 | kensho/ng-describe | dist/ng-describe.js | allSame | function allSame(arr) {
if (!check.array(arr)) {
return false;
}
if (!arr.length) {
return true;
}
var first = arr[0];
return arr.every(function (item) {
return item === first;
});
} | javascript | function allSame(arr) {
if (!check.array(arr)) {
return false;
}
if (!arr.length) {
return true;
}
var first = arr[0];
return arr.every(function (item) {
return item === first;
});
} | [
"function",
"allSame",
"(",
"arr",
")",
"{",
"if",
"(",
"!",
"check",
".",
"array",
"(",
"arr",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"arr",
".",
"length",
")",
"{",
"return",
"true",
";",
"}",
"var",
"first",
"=",
"arr",
"[",
"0",
"]",
";",
"return",
"arr",
".",
"every",
"(",
"function",
"(",
"item",
")",
"{",
"return",
"item",
"===",
"first",
";",
"}",
")",
";",
"}"
] | Returns true if all items in an array are the same reference
@method allSame | [
"Returns",
"true",
"if",
"all",
"items",
"in",
"an",
"array",
"are",
"the",
"same",
"reference"
] | 884c4ac0cfdba88d248053c36fa4b672f735734b | https://github.com/kensho/ng-describe/blob/884c4ac0cfdba88d248053c36fa4b672f735734b/dist/ng-describe.js#L2294-L2305 |
21,269 | kensho/ng-describe | dist/ng-describe.js | oneOf | function oneOf(arr, x) {
check.verify.array(arr, 'expected an array');
return arr.indexOf(x) !== -1;
} | javascript | function oneOf(arr, x) {
check.verify.array(arr, 'expected an array');
return arr.indexOf(x) !== -1;
} | [
"function",
"oneOf",
"(",
"arr",
",",
"x",
")",
"{",
"check",
".",
"verify",
".",
"array",
"(",
"arr",
",",
"'expected an array'",
")",
";",
"return",
"arr",
".",
"indexOf",
"(",
"x",
")",
"!==",
"-",
"1",
";",
"}"
] | Returns true if given item is in the array
@method oneOf | [
"Returns",
"true",
"if",
"given",
"item",
"is",
"in",
"the",
"array"
] | 884c4ac0cfdba88d248053c36fa4b672f735734b | https://github.com/kensho/ng-describe/blob/884c4ac0cfdba88d248053c36fa4b672f735734b/dist/ng-describe.js#L2312-L2315 |
21,270 | kensho/ng-describe | dist/ng-describe.js | has | function has(o, property) {
if (arguments.length !== 2) {
throw new Error('Expected two arguments to check.has, got only ' + arguments.length);
}
return Boolean(o && property &&
typeof property === 'string' &&
typeof o[property] !== 'undefined');
} | javascript | function has(o, property) {
if (arguments.length !== 2) {
throw new Error('Expected two arguments to check.has, got only ' + arguments.length);
}
return Boolean(o && property &&
typeof property === 'string' &&
typeof o[property] !== 'undefined');
} | [
"function",
"has",
"(",
"o",
",",
"property",
")",
"{",
"if",
"(",
"arguments",
".",
"length",
"!==",
"2",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Expected two arguments to check.has, got only '",
"+",
"arguments",
".",
"length",
")",
";",
"}",
"return",
"Boolean",
"(",
"o",
"&&",
"property",
"&&",
"typeof",
"property",
"===",
"'string'",
"&&",
"typeof",
"o",
"[",
"property",
"]",
"!==",
"'undefined'",
")",
";",
"}"
] | Checks if given object has a property
@method has | [
"Checks",
"if",
"given",
"object",
"has",
"a",
"property"
] | 884c4ac0cfdba88d248053c36fa4b672f735734b | https://github.com/kensho/ng-describe/blob/884c4ac0cfdba88d248053c36fa4b672f735734b/dist/ng-describe.js#L2349-L2356 |
21,271 | kensho/ng-describe | dist/ng-describe.js | badItems | function badItems(rule, a) {
check.verify.array(a, 'expected array to find bad items');
return a.filter(notModifier(rule));
} | javascript | function badItems(rule, a) {
check.verify.array(a, 'expected array to find bad items');
return a.filter(notModifier(rule));
} | [
"function",
"badItems",
"(",
"rule",
",",
"a",
")",
"{",
"check",
".",
"verify",
".",
"array",
"(",
"a",
",",
"'expected array to find bad items'",
")",
";",
"return",
"a",
".",
"filter",
"(",
"notModifier",
"(",
"rule",
")",
")",
";",
"}"
] | Returns items from array that do not passes the predicate
@method badItems
@param rule Predicate function
@param a Array with items | [
"Returns",
"items",
"from",
"array",
"that",
"do",
"not",
"passes",
"the",
"predicate"
] | 884c4ac0cfdba88d248053c36fa4b672f735734b | https://github.com/kensho/ng-describe/blob/884c4ac0cfdba88d248053c36fa4b672f735734b/dist/ng-describe.js#L2391-L2394 |
21,272 | kensho/ng-describe | dist/ng-describe.js | arrayOfStrings | function arrayOfStrings(a, checkLowerCase) {
var v = check.array(a) && a.every(check.string);
if (v && check.bool(checkLowerCase) && checkLowerCase) {
return a.every(check.lowerCase);
}
return v;
} | javascript | function arrayOfStrings(a, checkLowerCase) {
var v = check.array(a) && a.every(check.string);
if (v && check.bool(checkLowerCase) && checkLowerCase) {
return a.every(check.lowerCase);
}
return v;
} | [
"function",
"arrayOfStrings",
"(",
"a",
",",
"checkLowerCase",
")",
"{",
"var",
"v",
"=",
"check",
".",
"array",
"(",
"a",
")",
"&&",
"a",
".",
"every",
"(",
"check",
".",
"string",
")",
";",
"if",
"(",
"v",
"&&",
"check",
".",
"bool",
"(",
"checkLowerCase",
")",
"&&",
"checkLowerCase",
")",
"{",
"return",
"a",
".",
"every",
"(",
"check",
".",
"lowerCase",
")",
";",
"}",
"return",
"v",
";",
"}"
] | Returns true if given array only has strings
@method arrayOfStrings
@param a Array to check
@param checkLowerCase Checks if all strings are lowercase | [
"Returns",
"true",
"if",
"given",
"array",
"only",
"has",
"strings"
] | 884c4ac0cfdba88d248053c36fa4b672f735734b | https://github.com/kensho/ng-describe/blob/884c4ac0cfdba88d248053c36fa4b672f735734b/dist/ng-describe.js#L2402-L2408 |
21,273 | kensho/ng-describe | dist/ng-describe.js | arrayOfArraysOfStrings | function arrayOfArraysOfStrings(a, checkLowerCase) {
return check.array(a) && a.every(function (arr) {
return check.arrayOfStrings(arr, checkLowerCase);
});
} | javascript | function arrayOfArraysOfStrings(a, checkLowerCase) {
return check.array(a) && a.every(function (arr) {
return check.arrayOfStrings(arr, checkLowerCase);
});
} | [
"function",
"arrayOfArraysOfStrings",
"(",
"a",
",",
"checkLowerCase",
")",
"{",
"return",
"check",
".",
"array",
"(",
"a",
")",
"&&",
"a",
".",
"every",
"(",
"function",
"(",
"arr",
")",
"{",
"return",
"check",
".",
"arrayOfStrings",
"(",
"arr",
",",
"checkLowerCase",
")",
";",
"}",
")",
";",
"}"
] | Returns true if given argument is array of arrays of strings
@method arrayOfArraysOfStrings
@param a Array to check
@param checkLowerCase Checks if all strings are lowercase | [
"Returns",
"true",
"if",
"given",
"argument",
"is",
"array",
"of",
"arrays",
"of",
"strings"
] | 884c4ac0cfdba88d248053c36fa4b672f735734b | https://github.com/kensho/ng-describe/blob/884c4ac0cfdba88d248053c36fa4b672f735734b/dist/ng-describe.js#L2416-L2420 |
21,274 | kensho/ng-describe | dist/ng-describe.js | all | function all(obj, predicates) {
check.verify.fn(check.every, 'missing check.every method');
check.verify.fn(check.map, 'missing check.map method');
check.verify.object(obj, 'missing object to check');
check.verify.object(predicates, 'missing predicates object');
Object.keys(predicates).forEach(function (property) {
if (!check.fn(predicates[property])) {
throw new Error('not a predicate function for ' + property + ' but ' + predicates[property]);
}
});
return check.every(check.map(obj, predicates));
} | javascript | function all(obj, predicates) {
check.verify.fn(check.every, 'missing check.every method');
check.verify.fn(check.map, 'missing check.map method');
check.verify.object(obj, 'missing object to check');
check.verify.object(predicates, 'missing predicates object');
Object.keys(predicates).forEach(function (property) {
if (!check.fn(predicates[property])) {
throw new Error('not a predicate function for ' + property + ' but ' + predicates[property]);
}
});
return check.every(check.map(obj, predicates));
} | [
"function",
"all",
"(",
"obj",
",",
"predicates",
")",
"{",
"check",
".",
"verify",
".",
"fn",
"(",
"check",
".",
"every",
",",
"'missing check.every method'",
")",
";",
"check",
".",
"verify",
".",
"fn",
"(",
"check",
".",
"map",
",",
"'missing check.map method'",
")",
";",
"check",
".",
"verify",
".",
"object",
"(",
"obj",
",",
"'missing object to check'",
")",
";",
"check",
".",
"verify",
".",
"object",
"(",
"predicates",
",",
"'missing predicates object'",
")",
";",
"Object",
".",
"keys",
"(",
"predicates",
")",
".",
"forEach",
"(",
"function",
"(",
"property",
")",
"{",
"if",
"(",
"!",
"check",
".",
"fn",
"(",
"predicates",
"[",
"property",
"]",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'not a predicate function for '",
"+",
"property",
"+",
"' but '",
"+",
"predicates",
"[",
"property",
"]",
")",
";",
"}",
"}",
")",
";",
"return",
"check",
".",
"every",
"(",
"check",
".",
"map",
"(",
"obj",
",",
"predicates",
")",
")",
";",
"}"
] | Checks if object passes all rules in predicates.
check.all({ foo: 'foo' }, { foo: check.string }, 'wrong object');
This is a composition of check.every(check.map ...) calls
https://github.com/philbooth/check-types.js#batch-operations
@method all
@param {object} object object to check
@param {object} predicates rules to check. Usually one per property.
@public
@returns true or false | [
"Checks",
"if",
"object",
"passes",
"all",
"rules",
"in",
"predicates",
"."
] | 884c4ac0cfdba88d248053c36fa4b672f735734b | https://github.com/kensho/ng-describe/blob/884c4ac0cfdba88d248053c36fa4b672f735734b/dist/ng-describe.js#L2436-L2448 |
21,275 | kensho/ng-describe | dist/ng-describe.js | raises | function raises(fn, errorValidator) {
check.verify.fn(fn, 'expected function that raises');
try {
fn();
} catch (err) {
if (typeof errorValidator === 'undefined') {
return true;
}
if (typeof errorValidator === 'function') {
return errorValidator(err);
}
return false;
}
// error has not been raised
return false;
} | javascript | function raises(fn, errorValidator) {
check.verify.fn(fn, 'expected function that raises');
try {
fn();
} catch (err) {
if (typeof errorValidator === 'undefined') {
return true;
}
if (typeof errorValidator === 'function') {
return errorValidator(err);
}
return false;
}
// error has not been raised
return false;
} | [
"function",
"raises",
"(",
"fn",
",",
"errorValidator",
")",
"{",
"check",
".",
"verify",
".",
"fn",
"(",
"fn",
",",
"'expected function that raises'",
")",
";",
"try",
"{",
"fn",
"(",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"if",
"(",
"typeof",
"errorValidator",
"===",
"'undefined'",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"typeof",
"errorValidator",
"===",
"'function'",
")",
"{",
"return",
"errorValidator",
"(",
"err",
")",
";",
"}",
"return",
"false",
";",
"}",
"// error has not been raised",
"return",
"false",
";",
"}"
] | Checks if given function raises an error
@method raises | [
"Checks",
"if",
"given",
"function",
"raises",
"an",
"error"
] | 884c4ac0cfdba88d248053c36fa4b672f735734b | https://github.com/kensho/ng-describe/blob/884c4ac0cfdba88d248053c36fa4b672f735734b/dist/ng-describe.js#L2462-L2477 |
21,276 | kensho/ng-describe | dist/ng-describe.js | unempty | function unempty(a) {
var hasLength = typeof a === 'string' ||
Array.isArray(a);
if (hasLength) {
return a.length;
}
if (a instanceof Object) {
return Object.keys(a).length;
}
return true;
} | javascript | function unempty(a) {
var hasLength = typeof a === 'string' ||
Array.isArray(a);
if (hasLength) {
return a.length;
}
if (a instanceof Object) {
return Object.keys(a).length;
}
return true;
} | [
"function",
"unempty",
"(",
"a",
")",
"{",
"var",
"hasLength",
"=",
"typeof",
"a",
"===",
"'string'",
"||",
"Array",
".",
"isArray",
"(",
"a",
")",
";",
"if",
"(",
"hasLength",
")",
"{",
"return",
"a",
".",
"length",
";",
"}",
"if",
"(",
"a",
"instanceof",
"Object",
")",
"{",
"return",
"Object",
".",
"keys",
"(",
"a",
")",
".",
"length",
";",
"}",
"return",
"true",
";",
"}"
] | Returns true if given value has .length and it is not zero, or has properties
@method unempty | [
"Returns",
"true",
"if",
"given",
"value",
"has",
".",
"length",
"and",
"it",
"is",
"not",
"zero",
"or",
"has",
"properties"
] | 884c4ac0cfdba88d248053c36fa4b672f735734b | https://github.com/kensho/ng-describe/blob/884c4ac0cfdba88d248053c36fa4b672f735734b/dist/ng-describe.js#L2507-L2517 |
21,277 | kensho/ng-describe | dist/ng-describe.js | commitId | function commitId(id) {
return check.string(id) &&
id.length === 40 &&
shaReg.test(id);
} | javascript | function commitId(id) {
return check.string(id) &&
id.length === 40 &&
shaReg.test(id);
} | [
"function",
"commitId",
"(",
"id",
")",
"{",
"return",
"check",
".",
"string",
"(",
"id",
")",
"&&",
"id",
".",
"length",
"===",
"40",
"&&",
"shaReg",
".",
"test",
"(",
"id",
")",
";",
"}"
] | Returns true if the given string is 40 digit SHA commit id
@method commitId | [
"Returns",
"true",
"if",
"the",
"given",
"string",
"is",
"40",
"digit",
"SHA",
"commit",
"id"
] | 884c4ac0cfdba88d248053c36fa4b672f735734b | https://github.com/kensho/ng-describe/blob/884c4ac0cfdba88d248053c36fa4b672f735734b/dist/ng-describe.js#L2546-L2550 |
21,278 | kensho/ng-describe | dist/ng-describe.js | shortCommitId | function shortCommitId(id) {
return check.string(id) &&
id.length === 7 &&
shortShaReg.test(id);
} | javascript | function shortCommitId(id) {
return check.string(id) &&
id.length === 7 &&
shortShaReg.test(id);
} | [
"function",
"shortCommitId",
"(",
"id",
")",
"{",
"return",
"check",
".",
"string",
"(",
"id",
")",
"&&",
"id",
".",
"length",
"===",
"7",
"&&",
"shortShaReg",
".",
"test",
"(",
"id",
")",
";",
"}"
] | Returns true if the given string is short 7 character SHA id part
@method shortCommitId | [
"Returns",
"true",
"if",
"the",
"given",
"string",
"is",
"short",
"7",
"character",
"SHA",
"id",
"part"
] | 884c4ac0cfdba88d248053c36fa4b672f735734b | https://github.com/kensho/ng-describe/blob/884c4ac0cfdba88d248053c36fa4b672f735734b/dist/ng-describe.js#L2559-L2563 |
21,279 | kensho/ng-describe | dist/ng-describe.js | or | function or() {
var predicates = Array.prototype.slice.call(arguments, 0);
if (!predicates.length) {
throw new Error('empty list of arguments to or');
}
return function orCheck() {
var values = Array.prototype.slice.call(arguments, 0);
return predicates.some(function (predicate) {
try {
return check.fn(predicate) ?
predicate.apply(null, values) : Boolean(predicate);
} catch (err) {
// treat exceptions as false
return false;
}
});
};
} | javascript | function or() {
var predicates = Array.prototype.slice.call(arguments, 0);
if (!predicates.length) {
throw new Error('empty list of arguments to or');
}
return function orCheck() {
var values = Array.prototype.slice.call(arguments, 0);
return predicates.some(function (predicate) {
try {
return check.fn(predicate) ?
predicate.apply(null, values) : Boolean(predicate);
} catch (err) {
// treat exceptions as false
return false;
}
});
};
} | [
"function",
"or",
"(",
")",
"{",
"var",
"predicates",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"0",
")",
";",
"if",
"(",
"!",
"predicates",
".",
"length",
")",
"{",
"throw",
"new",
"Error",
"(",
"'empty list of arguments to or'",
")",
";",
"}",
"return",
"function",
"orCheck",
"(",
")",
"{",
"var",
"values",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"0",
")",
";",
"return",
"predicates",
".",
"some",
"(",
"function",
"(",
"predicate",
")",
"{",
"try",
"{",
"return",
"check",
".",
"fn",
"(",
"predicate",
")",
"?",
"predicate",
".",
"apply",
"(",
"null",
",",
"values",
")",
":",
"Boolean",
"(",
"predicate",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"// treat exceptions as false",
"return",
"false",
";",
"}",
"}",
")",
";",
"}",
";",
"}"
] | Combines multiple predicate functions to produce new OR predicate
@method or | [
"Combines",
"multiple",
"predicate",
"functions",
"to",
"produce",
"new",
"OR",
"predicate"
] | 884c4ac0cfdba88d248053c36fa4b672f735734b | https://github.com/kensho/ng-describe/blob/884c4ac0cfdba88d248053c36fa4b672f735734b/dist/ng-describe.js#L2610-L2628 |
21,280 | kensho/ng-describe | dist/ng-describe.js | and | function and() {
var predicates = Array.prototype.slice.call(arguments, 0);
if (!predicates.length) {
throw new Error('empty list of arguments to or');
}
return function orCheck() {
var values = Array.prototype.slice.call(arguments, 0);
return predicates.every(function (predicate) {
return check.fn(predicate) ?
predicate.apply(null, values) : Boolean(predicate);
});
};
} | javascript | function and() {
var predicates = Array.prototype.slice.call(arguments, 0);
if (!predicates.length) {
throw new Error('empty list of arguments to or');
}
return function orCheck() {
var values = Array.prototype.slice.call(arguments, 0);
return predicates.every(function (predicate) {
return check.fn(predicate) ?
predicate.apply(null, values) : Boolean(predicate);
});
};
} | [
"function",
"and",
"(",
")",
"{",
"var",
"predicates",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"0",
")",
";",
"if",
"(",
"!",
"predicates",
".",
"length",
")",
"{",
"throw",
"new",
"Error",
"(",
"'empty list of arguments to or'",
")",
";",
"}",
"return",
"function",
"orCheck",
"(",
")",
"{",
"var",
"values",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"0",
")",
";",
"return",
"predicates",
".",
"every",
"(",
"function",
"(",
"predicate",
")",
"{",
"return",
"check",
".",
"fn",
"(",
"predicate",
")",
"?",
"predicate",
".",
"apply",
"(",
"null",
",",
"values",
")",
":",
"Boolean",
"(",
"predicate",
")",
";",
"}",
")",
";",
"}",
";",
"}"
] | Combines multiple predicate functions to produce new AND predicate
@method or | [
"Combines",
"multiple",
"predicate",
"functions",
"to",
"produce",
"new",
"AND",
"predicate"
] | 884c4ac0cfdba88d248053c36fa4b672f735734b | https://github.com/kensho/ng-describe/blob/884c4ac0cfdba88d248053c36fa4b672f735734b/dist/ng-describe.js#L2634-L2647 |
21,281 | kensho/ng-describe | dist/ng-describe.js | verifyModifier | function verifyModifier(predicate, defaultMessage) {
return function () {
var message;
if (predicate.apply(null, arguments) === false) {
message = arguments[arguments.length - 1];
throw new Error(check.unemptyString(message) ? message : defaultMessage);
}
};
} | javascript | function verifyModifier(predicate, defaultMessage) {
return function () {
var message;
if (predicate.apply(null, arguments) === false) {
message = arguments[arguments.length - 1];
throw new Error(check.unemptyString(message) ? message : defaultMessage);
}
};
} | [
"function",
"verifyModifier",
"(",
"predicate",
",",
"defaultMessage",
")",
"{",
"return",
"function",
"(",
")",
"{",
"var",
"message",
";",
"if",
"(",
"predicate",
".",
"apply",
"(",
"null",
",",
"arguments",
")",
"===",
"false",
")",
"{",
"message",
"=",
"arguments",
"[",
"arguments",
".",
"length",
"-",
"1",
"]",
";",
"throw",
"new",
"Error",
"(",
"check",
".",
"unemptyString",
"(",
"message",
")",
"?",
"message",
":",
"defaultMessage",
")",
";",
"}",
"}",
";",
"}"
] | Public modifier `verify`.
Throws if `predicate` returns `false`.
copied from check-types.js | [
"Public",
"modifier",
"verify",
"."
] | 884c4ac0cfdba88d248053c36fa4b672f735734b | https://github.com/kensho/ng-describe/blob/884c4ac0cfdba88d248053c36fa4b672f735734b/dist/ng-describe.js#L2719-L2727 |
21,282 | siddharthkp/ci-env | utils/drone.js | getLegacyRepo | function getLegacyRepo(env) {
// default to process.env if no argument provided
if (!env) { env = process.env }
// bail if neither variable exists
let remote = env.DRONE_REMOTE || env.CI_REMOTE
if (!remote) { return '' }
// parse out the org and repo name from the git URL
let parts = remote.split('/').slice(-2)
let org = parts[0]
let reponame = parts[1].replace(/\.git$/, '')
let repo = '' + org + '/' + reponame
return repo
} | javascript | function getLegacyRepo(env) {
// default to process.env if no argument provided
if (!env) { env = process.env }
// bail if neither variable exists
let remote = env.DRONE_REMOTE || env.CI_REMOTE
if (!remote) { return '' }
// parse out the org and repo name from the git URL
let parts = remote.split('/').slice(-2)
let org = parts[0]
let reponame = parts[1].replace(/\.git$/, '')
let repo = '' + org + '/' + reponame
return repo
} | [
"function",
"getLegacyRepo",
"(",
"env",
")",
"{",
"// default to process.env if no argument provided",
"if",
"(",
"!",
"env",
")",
"{",
"env",
"=",
"process",
".",
"env",
"}",
"// bail if neither variable exists",
"let",
"remote",
"=",
"env",
".",
"DRONE_REMOTE",
"||",
"env",
".",
"CI_REMOTE",
"if",
"(",
"!",
"remote",
")",
"{",
"return",
"''",
"}",
"// parse out the org and repo name from the git URL",
"let",
"parts",
"=",
"remote",
".",
"split",
"(",
"'/'",
")",
".",
"slice",
"(",
"-",
"2",
")",
"let",
"org",
"=",
"parts",
"[",
"0",
"]",
"let",
"reponame",
"=",
"parts",
"[",
"1",
"]",
".",
"replace",
"(",
"/",
"\\.git$",
"/",
",",
"''",
")",
"let",
"repo",
"=",
"''",
"+",
"org",
"+",
"'/'",
"+",
"reponame",
"return",
"repo",
"}"
] | Parses a git URL, extracting the org and repo name.
Older versions of drone (< v4.0) do not export `DRONE_REPO` or `CI_REPO`.
They do export `DRONE_REMOTE` and / or `CI_REMOTE` with the git URL.
e.g., `DRONE_REMOTE=git://github.com/siddharthkp/ci-env.git`
@param {Object} env object in shape of `process.env`
@param {String} env.DRONE_REMOTE git URL of remote repository
@param {String} env.CI_REMOTE git URL of remote repository
@returns {String} org/repo (without .git extension) | [
"Parses",
"a",
"git",
"URL",
"extracting",
"the",
"org",
"and",
"repo",
"name",
"."
] | 73a46437295b3cc2372a8e90f289eab1d7e82f32 | https://github.com/siddharthkp/ci-env/blob/73a46437295b3cc2372a8e90f289eab1d7e82f32/utils/drone.js#L14-L28 |
21,283 | wework/we-js-logger | src/client.js | getStreams | function getStreams(config) {
// Any passed in streams
const streams = Array.isArray(config.streams)
? [...config.streams]
: [];
// Nice console output
if (config.stdout) {
streams.push({
name: 'stdout',
level: config.level,
stream: new ClientConsoleLogger(),
type: 'raw',
});
}
// Rollbar Transport
// Messages at the warn level or higher are transported to Rollbar
// Detects presence of global Rollbar and passed in token
if (isGlobalRollbarConfigured()) {
if (config.rollbarToken) {
streams.push({
name: 'rollbar',
level: 'warn',
stream: new ClientRollbarLogger({
token: config.rollbarToken,
environment: config.environment,
codeVersion: config.codeVersion,
}),
type: 'raw',
});
}
} else {
/* eslint-disable no-console */
console.warn('Client rollbar is not correctly configured');
/* eslint-enable */
}
// Transport client logs
if (config.logentriesToken) {
streams.push({
name: 'logentries',
level: config.level,
stream: new ClientLogentriesLogger({
name: config.name,
token: config.logentriesToken,
}),
type: 'raw',
});
}
return streams;
} | javascript | function getStreams(config) {
// Any passed in streams
const streams = Array.isArray(config.streams)
? [...config.streams]
: [];
// Nice console output
if (config.stdout) {
streams.push({
name: 'stdout',
level: config.level,
stream: new ClientConsoleLogger(),
type: 'raw',
});
}
// Rollbar Transport
// Messages at the warn level or higher are transported to Rollbar
// Detects presence of global Rollbar and passed in token
if (isGlobalRollbarConfigured()) {
if (config.rollbarToken) {
streams.push({
name: 'rollbar',
level: 'warn',
stream: new ClientRollbarLogger({
token: config.rollbarToken,
environment: config.environment,
codeVersion: config.codeVersion,
}),
type: 'raw',
});
}
} else {
/* eslint-disable no-console */
console.warn('Client rollbar is not correctly configured');
/* eslint-enable */
}
// Transport client logs
if (config.logentriesToken) {
streams.push({
name: 'logentries',
level: config.level,
stream: new ClientLogentriesLogger({
name: config.name,
token: config.logentriesToken,
}),
type: 'raw',
});
}
return streams;
} | [
"function",
"getStreams",
"(",
"config",
")",
"{",
"// Any passed in streams",
"const",
"streams",
"=",
"Array",
".",
"isArray",
"(",
"config",
".",
"streams",
")",
"?",
"[",
"...",
"config",
".",
"streams",
"]",
":",
"[",
"]",
";",
"// Nice console output",
"if",
"(",
"config",
".",
"stdout",
")",
"{",
"streams",
".",
"push",
"(",
"{",
"name",
":",
"'stdout'",
",",
"level",
":",
"config",
".",
"level",
",",
"stream",
":",
"new",
"ClientConsoleLogger",
"(",
")",
",",
"type",
":",
"'raw'",
",",
"}",
")",
";",
"}",
"// Rollbar Transport",
"// Messages at the warn level or higher are transported to Rollbar",
"// Detects presence of global Rollbar and passed in token",
"if",
"(",
"isGlobalRollbarConfigured",
"(",
")",
")",
"{",
"if",
"(",
"config",
".",
"rollbarToken",
")",
"{",
"streams",
".",
"push",
"(",
"{",
"name",
":",
"'rollbar'",
",",
"level",
":",
"'warn'",
",",
"stream",
":",
"new",
"ClientRollbarLogger",
"(",
"{",
"token",
":",
"config",
".",
"rollbarToken",
",",
"environment",
":",
"config",
".",
"environment",
",",
"codeVersion",
":",
"config",
".",
"codeVersion",
",",
"}",
")",
",",
"type",
":",
"'raw'",
",",
"}",
")",
";",
"}",
"}",
"else",
"{",
"/* eslint-disable no-console */",
"console",
".",
"warn",
"(",
"'Client rollbar is not correctly configured'",
")",
";",
"/* eslint-enable */",
"}",
"// Transport client logs",
"if",
"(",
"config",
".",
"logentriesToken",
")",
"{",
"streams",
".",
"push",
"(",
"{",
"name",
":",
"'logentries'",
",",
"level",
":",
"config",
".",
"level",
",",
"stream",
":",
"new",
"ClientLogentriesLogger",
"(",
"{",
"name",
":",
"config",
".",
"name",
",",
"token",
":",
"config",
".",
"logentriesToken",
",",
"}",
")",
",",
"type",
":",
"'raw'",
",",
"}",
")",
";",
"}",
"return",
"streams",
";",
"}"
] | Add standard Client logger streams to `config.streams`
@private
@param {Object} config
@param {Array?} config.streams
@returns {Array} | [
"Add",
"standard",
"Client",
"logger",
"streams",
"to",
"config",
".",
"streams"
] | 57b66dd40ffe5f44d2cf553d1d1ecfd47973c567 | https://github.com/wework/we-js-logger/blob/57b66dd40ffe5f44d2cf553d1d1ecfd47973c567/src/client.js#L20-L72 |
21,284 | wework/we-js-logger | src/node.js | getStreams | function getStreams(config) {
const streams = Array.isArray(config.streams)
? [...config.streams]
: [];
// Nice output to stdout
if (config.stdout) {
streams.push({
name: 'stdout',
level: config.level,
stream: bunyanFormat({ outputMode: 'short' }),
type: 'stream',
});
}
// Rollbar Transport
// Messages at the warn level or higher are transported to Rollbar
// Messages with an `err` and/or `req` data params are handled specially
if (config.rollbarToken) {
streams.push({
name: 'rollbar',
level: 'warn',
stream: new ServerRollbarLogger({
token: config.rollbarToken,
environment: config.environment,
codeVersion: config.codeVersion,
}),
type: 'raw',
});
}
// Transport server logs
if (config.logentriesToken) {
streams.push(new ServerLogentriesLogger({
name: config.name,
token: config.logentriesToken,
level: config.level,
}));
}
return streams;
} | javascript | function getStreams(config) {
const streams = Array.isArray(config.streams)
? [...config.streams]
: [];
// Nice output to stdout
if (config.stdout) {
streams.push({
name: 'stdout',
level: config.level,
stream: bunyanFormat({ outputMode: 'short' }),
type: 'stream',
});
}
// Rollbar Transport
// Messages at the warn level or higher are transported to Rollbar
// Messages with an `err` and/or `req` data params are handled specially
if (config.rollbarToken) {
streams.push({
name: 'rollbar',
level: 'warn',
stream: new ServerRollbarLogger({
token: config.rollbarToken,
environment: config.environment,
codeVersion: config.codeVersion,
}),
type: 'raw',
});
}
// Transport server logs
if (config.logentriesToken) {
streams.push(new ServerLogentriesLogger({
name: config.name,
token: config.logentriesToken,
level: config.level,
}));
}
return streams;
} | [
"function",
"getStreams",
"(",
"config",
")",
"{",
"const",
"streams",
"=",
"Array",
".",
"isArray",
"(",
"config",
".",
"streams",
")",
"?",
"[",
"...",
"config",
".",
"streams",
"]",
":",
"[",
"]",
";",
"// Nice output to stdout",
"if",
"(",
"config",
".",
"stdout",
")",
"{",
"streams",
".",
"push",
"(",
"{",
"name",
":",
"'stdout'",
",",
"level",
":",
"config",
".",
"level",
",",
"stream",
":",
"bunyanFormat",
"(",
"{",
"outputMode",
":",
"'short'",
"}",
")",
",",
"type",
":",
"'stream'",
",",
"}",
")",
";",
"}",
"// Rollbar Transport",
"// Messages at the warn level or higher are transported to Rollbar",
"// Messages with an `err` and/or `req` data params are handled specially",
"if",
"(",
"config",
".",
"rollbarToken",
")",
"{",
"streams",
".",
"push",
"(",
"{",
"name",
":",
"'rollbar'",
",",
"level",
":",
"'warn'",
",",
"stream",
":",
"new",
"ServerRollbarLogger",
"(",
"{",
"token",
":",
"config",
".",
"rollbarToken",
",",
"environment",
":",
"config",
".",
"environment",
",",
"codeVersion",
":",
"config",
".",
"codeVersion",
",",
"}",
")",
",",
"type",
":",
"'raw'",
",",
"}",
")",
";",
"}",
"// Transport server logs",
"if",
"(",
"config",
".",
"logentriesToken",
")",
"{",
"streams",
".",
"push",
"(",
"new",
"ServerLogentriesLogger",
"(",
"{",
"name",
":",
"config",
".",
"name",
",",
"token",
":",
"config",
".",
"logentriesToken",
",",
"level",
":",
"config",
".",
"level",
",",
"}",
")",
")",
";",
"}",
"return",
"streams",
";",
"}"
] | Add standard Node logger streams to `config.streams`
@private
@param {Object} config
@param {Array?} config.streams
@returns {Array} | [
"Add",
"standard",
"Node",
"logger",
"streams",
"to",
"config",
".",
"streams"
] | 57b66dd40ffe5f44d2cf553d1d1ecfd47973c567 | https://github.com/wework/we-js-logger/blob/57b66dd40ffe5f44d2cf553d1d1ecfd47973c567/src/node.js#L19-L60 |
21,285 | netifi-proteus/proteus-js | resources/bumpVersion.js | getDependents | function getDependents(dependencyName) {
return Object.values(allPackages).filter(({info: pkg}) => {
return (
pkg.dependencies &&
Object.keys(pkg.dependencies).indexOf(dependencyName) !== -1
);
});
} | javascript | function getDependents(dependencyName) {
return Object.values(allPackages).filter(({info: pkg}) => {
return (
pkg.dependencies &&
Object.keys(pkg.dependencies).indexOf(dependencyName) !== -1
);
});
} | [
"function",
"getDependents",
"(",
"dependencyName",
")",
"{",
"return",
"Object",
".",
"values",
"(",
"allPackages",
")",
".",
"filter",
"(",
"(",
"{",
"info",
":",
"pkg",
"}",
")",
"=>",
"{",
"return",
"(",
"pkg",
".",
"dependencies",
"&&",
"Object",
".",
"keys",
"(",
"pkg",
".",
"dependencies",
")",
".",
"indexOf",
"(",
"dependencyName",
")",
"!==",
"-",
"1",
")",
";",
"}",
")",
";",
"}"
] | Get the direct dependents of `dependency`. | [
"Get",
"the",
"direct",
"dependents",
"of",
"dependency",
"."
] | dc29a797efa82bd8aef5c9d8512d7c72d7c9bc4f | https://github.com/netifi-proteus/proteus-js/blob/dc29a797efa82bd8aef5c9d8512d7c72d7c9bc4f/resources/bumpVersion.js#L144-L151 |
21,286 | zyra/cordova-plugin-stripe | www/CordovaStripe.js | function(key, success, error) {
success = success || noop;
error = error || noop;
exec(success, error, "CordovaStripe", "setPublishableKey", [key]);
} | javascript | function(key, success, error) {
success = success || noop;
error = error || noop;
exec(success, error, "CordovaStripe", "setPublishableKey", [key]);
} | [
"function",
"(",
"key",
",",
"success",
",",
"error",
")",
"{",
"success",
"=",
"success",
"||",
"noop",
";",
"error",
"=",
"error",
"||",
"noop",
";",
"exec",
"(",
"success",
",",
"error",
",",
"\"CordovaStripe\"",
",",
"\"setPublishableKey\"",
",",
"[",
"key",
"]",
")",
";",
"}"
] | Set publishable key
@param key {string} Publishable key
@param [success] {Function} Success callback
@param [error] {Function} Error callback | [
"Set",
"publishable",
"key"
] | df50d5631d9cf1accd0e593ae74de74ce206e2dc | https://github.com/zyra/cordova-plugin-stripe/blob/df50d5631d9cf1accd0e593ae74de74ce206e2dc/www/CordovaStripe.js#L49-L53 | |
21,287 | zyra/cordova-plugin-stripe | www/CordovaStripe.js | function(creditCard, success, error) {
success = success || noop;
error = error || noop;
exec(success, error, "CordovaStripe", "createCardToken", [creditCard]);
} | javascript | function(creditCard, success, error) {
success = success || noop;
error = error || noop;
exec(success, error, "CordovaStripe", "createCardToken", [creditCard]);
} | [
"function",
"(",
"creditCard",
",",
"success",
",",
"error",
")",
"{",
"success",
"=",
"success",
"||",
"noop",
";",
"error",
"=",
"error",
"||",
"noop",
";",
"exec",
"(",
"success",
",",
"error",
",",
"\"CordovaStripe\"",
",",
"\"createCardToken\"",
",",
"[",
"creditCard",
"]",
")",
";",
"}"
] | Create a credit card token
@param creditCard {module:stripe.CreditCardTokenParams} Credit card information
@param success {Function} Success callback
@param error {Function} Error callback | [
"Create",
"a",
"credit",
"card",
"token"
] | df50d5631d9cf1accd0e593ae74de74ce206e2dc | https://github.com/zyra/cordova-plugin-stripe/blob/df50d5631d9cf1accd0e593ae74de74ce206e2dc/www/CordovaStripe.js#L61-L65 | |
21,288 | zyra/cordova-plugin-stripe | www/CordovaStripe.js | function(bankAccount, success, error) {
success = success || noop;
error = error || noop;
exec(success, error, "CordovaStripe", "createBankAccountToken", [bankAccount]);
} | javascript | function(bankAccount, success, error) {
success = success || noop;
error = error || noop;
exec(success, error, "CordovaStripe", "createBankAccountToken", [bankAccount]);
} | [
"function",
"(",
"bankAccount",
",",
"success",
",",
"error",
")",
"{",
"success",
"=",
"success",
"||",
"noop",
";",
"error",
"=",
"error",
"||",
"noop",
";",
"exec",
"(",
"success",
",",
"error",
",",
"\"CordovaStripe\"",
",",
"\"createBankAccountToken\"",
",",
"[",
"bankAccount",
"]",
")",
";",
"}"
] | Create a bank account token
@param bankAccount {module:stripe.BankAccountTokenParams} Bank account information
@param {Function} success Success callback
@param {Function} error Error callback | [
"Create",
"a",
"bank",
"account",
"token"
] | df50d5631d9cf1accd0e593ae74de74ce206e2dc | https://github.com/zyra/cordova-plugin-stripe/blob/df50d5631d9cf1accd0e593ae74de74ce206e2dc/www/CordovaStripe.js#L73-L77 | |
21,289 | zyra/cordova-plugin-stripe | www/CordovaStripe.js | function(cardNumber, success, error) {
success = success || noop;
error = error || noop;
exec(success, error, "CordovaStripe", "validateCardNumber", [cardNumber]);
} | javascript | function(cardNumber, success, error) {
success = success || noop;
error = error || noop;
exec(success, error, "CordovaStripe", "validateCardNumber", [cardNumber]);
} | [
"function",
"(",
"cardNumber",
",",
"success",
",",
"error",
")",
"{",
"success",
"=",
"success",
"||",
"noop",
";",
"error",
"=",
"error",
"||",
"noop",
";",
"exec",
"(",
"success",
",",
"error",
",",
"\"CordovaStripe\"",
",",
"\"validateCardNumber\"",
",",
"[",
"cardNumber",
"]",
")",
";",
"}"
] | Validates card number
@param cardNumber {String} Credit card number
@param {Function} success Success callback that will be called if card number is valid
@param {Function} error Error callback that will be called if card number is invalid | [
"Validates",
"card",
"number"
] | df50d5631d9cf1accd0e593ae74de74ce206e2dc | https://github.com/zyra/cordova-plugin-stripe/blob/df50d5631d9cf1accd0e593ae74de74ce206e2dc/www/CordovaStripe.js#L85-L89 | |
21,290 | zyra/cordova-plugin-stripe | www/CordovaStripe.js | function(expMonth, expYear, success, error) {
success = success || noop;
error = error || noop;
exec(success, error, "CordovaStripe", "validateExpiryDate", [expMonth, expYear]);
} | javascript | function(expMonth, expYear, success, error) {
success = success || noop;
error = error || noop;
exec(success, error, "CordovaStripe", "validateExpiryDate", [expMonth, expYear]);
} | [
"function",
"(",
"expMonth",
",",
"expYear",
",",
"success",
",",
"error",
")",
"{",
"success",
"=",
"success",
"||",
"noop",
";",
"error",
"=",
"error",
"||",
"noop",
";",
"exec",
"(",
"success",
",",
"error",
",",
"\"CordovaStripe\"",
",",
"\"validateExpiryDate\"",
",",
"[",
"expMonth",
",",
"expYear",
"]",
")",
";",
"}"
] | Validates the expiry date of a card
@param {number} expMonth Expiry month
@param {number} expYear Expiry year
@param {Function} success
@param {Function} error | [
"Validates",
"the",
"expiry",
"date",
"of",
"a",
"card"
] | df50d5631d9cf1accd0e593ae74de74ce206e2dc | https://github.com/zyra/cordova-plugin-stripe/blob/df50d5631d9cf1accd0e593ae74de74ce206e2dc/www/CordovaStripe.js#L98-L102 | |
21,291 | Templarian/ui.bootstrap.contextMenu | contextMenu.js | processItem | function processItem(params) {
var nestedMenu = extractNestedMenu(params);
// if html property is not defined, fallback to text, otherwise use default text
// if first item in the item array is a function then invoke .call()
// if first item is a string, then text should be the string.
var text = DEFAULT_ITEM_TEXT;
var currItemParam = angular.extend({}, params);
var item = params.item;
var enabled = item.enabled === undefined ? item[2] : item.enabled;
currItemParam.nestedMenu = nestedMenu;
currItemParam.enabled = resolveBoolOrFunc(enabled, params);
currItemParam.text = createAndAddOptionText(currItemParam);
registerCurrentItemEvents(currItemParam);
} | javascript | function processItem(params) {
var nestedMenu = extractNestedMenu(params);
// if html property is not defined, fallback to text, otherwise use default text
// if first item in the item array is a function then invoke .call()
// if first item is a string, then text should be the string.
var text = DEFAULT_ITEM_TEXT;
var currItemParam = angular.extend({}, params);
var item = params.item;
var enabled = item.enabled === undefined ? item[2] : item.enabled;
currItemParam.nestedMenu = nestedMenu;
currItemParam.enabled = resolveBoolOrFunc(enabled, params);
currItemParam.text = createAndAddOptionText(currItemParam);
registerCurrentItemEvents(currItemParam);
} | [
"function",
"processItem",
"(",
"params",
")",
"{",
"var",
"nestedMenu",
"=",
"extractNestedMenu",
"(",
"params",
")",
";",
"// if html property is not defined, fallback to text, otherwise use default text",
"// if first item in the item array is a function then invoke .call()",
"// if first item is a string, then text should be the string.",
"var",
"text",
"=",
"DEFAULT_ITEM_TEXT",
";",
"var",
"currItemParam",
"=",
"angular",
".",
"extend",
"(",
"{",
"}",
",",
"params",
")",
";",
"var",
"item",
"=",
"params",
".",
"item",
";",
"var",
"enabled",
"=",
"item",
".",
"enabled",
"===",
"undefined",
"?",
"item",
"[",
"2",
"]",
":",
"item",
".",
"enabled",
";",
"currItemParam",
".",
"nestedMenu",
"=",
"nestedMenu",
";",
"currItemParam",
".",
"enabled",
"=",
"resolveBoolOrFunc",
"(",
"enabled",
",",
"params",
")",
";",
"currItemParam",
".",
"text",
"=",
"createAndAddOptionText",
"(",
"currItemParam",
")",
";",
"registerCurrentItemEvents",
"(",
"currItemParam",
")",
";",
"}"
] | Process each individual item
Properties of params:
- $scope
- event
- modelValue
- level
- item
- $ul
- $li
- $promises | [
"Process",
"each",
"individual",
"item"
] | 08b66bc3854ffe874b50fedd1597587059edc687 | https://github.com/Templarian/ui.bootstrap.contextMenu/blob/08b66bc3854ffe874b50fedd1597587059edc687/contextMenu.js#L134-L152 |
21,292 | Templarian/ui.bootstrap.contextMenu | contextMenu.js | renderContextMenu | function renderContextMenu (params) {
/// <summary>Render context menu recursively.</summary>
// Destructuring:
var $scope = params.$scope;
var event = params.event;
var options = params.options;
var modelValue = params.modelValue;
var level = params.level;
var customClass = params.customClass;
// Initialize the container. This will be passed around
var $ul = initContextMenuContainer(params);
params.$ul = $ul;
// Register this level of the context menu
_contextMenus.push($ul);
/*
* This object will contain any promises that we have
* to wait for before trying to adjust the context menu.
*/
var $promises = [];
params.$promises = $promises;
angular.forEach(options, function (item) {
if (item === null) {
appendDivider($ul);
} else {
// If displayed is anything other than a function or a boolean
var displayed = resolveBoolOrFunc(item.displayed, params);
// Only add the <li> if the item is displayed
if (displayed) {
var $li = $('<li>');
var itemParams = angular.extend({}, params);
itemParams.item = item;
itemParams.$li = $li;
if (typeof item[0] === 'object') {
custom.initialize($li, item);
} else {
processItem(itemParams);
}
if (resolveBoolOrFunc(item.hasTopDivider, itemParams, false)) {
appendDivider($ul);
}
$ul.append($li);
if (resolveBoolOrFunc(item.hasBottomDivider, itemParams, false)) {
appendDivider($ul);
}
}
}
});
if ($ul.children().length === 0) {
var $emptyLi = angular.element('<li>');
setElementDisabled($emptyLi);
$emptyLi.html('<a>' + _emptyText + '</a>');
$ul.append($emptyLi);
}
$document.find('body').append($ul);
doAfterAllPromises(params);
$rootScope.$broadcast(ContextMenuEvents.ContextMenuOpened, {
context: _clickedElement,
contextMenu: $ul,
params: params
});
} | javascript | function renderContextMenu (params) {
/// <summary>Render context menu recursively.</summary>
// Destructuring:
var $scope = params.$scope;
var event = params.event;
var options = params.options;
var modelValue = params.modelValue;
var level = params.level;
var customClass = params.customClass;
// Initialize the container. This will be passed around
var $ul = initContextMenuContainer(params);
params.$ul = $ul;
// Register this level of the context menu
_contextMenus.push($ul);
/*
* This object will contain any promises that we have
* to wait for before trying to adjust the context menu.
*/
var $promises = [];
params.$promises = $promises;
angular.forEach(options, function (item) {
if (item === null) {
appendDivider($ul);
} else {
// If displayed is anything other than a function or a boolean
var displayed = resolveBoolOrFunc(item.displayed, params);
// Only add the <li> if the item is displayed
if (displayed) {
var $li = $('<li>');
var itemParams = angular.extend({}, params);
itemParams.item = item;
itemParams.$li = $li;
if (typeof item[0] === 'object') {
custom.initialize($li, item);
} else {
processItem(itemParams);
}
if (resolveBoolOrFunc(item.hasTopDivider, itemParams, false)) {
appendDivider($ul);
}
$ul.append($li);
if (resolveBoolOrFunc(item.hasBottomDivider, itemParams, false)) {
appendDivider($ul);
}
}
}
});
if ($ul.children().length === 0) {
var $emptyLi = angular.element('<li>');
setElementDisabled($emptyLi);
$emptyLi.html('<a>' + _emptyText + '</a>');
$ul.append($emptyLi);
}
$document.find('body').append($ul);
doAfterAllPromises(params);
$rootScope.$broadcast(ContextMenuEvents.ContextMenuOpened, {
context: _clickedElement,
contextMenu: $ul,
params: params
});
} | [
"function",
"renderContextMenu",
"(",
"params",
")",
"{",
"/// <summary>Render context menu recursively.</summary>",
"// Destructuring:",
"var",
"$scope",
"=",
"params",
".",
"$scope",
";",
"var",
"event",
"=",
"params",
".",
"event",
";",
"var",
"options",
"=",
"params",
".",
"options",
";",
"var",
"modelValue",
"=",
"params",
".",
"modelValue",
";",
"var",
"level",
"=",
"params",
".",
"level",
";",
"var",
"customClass",
"=",
"params",
".",
"customClass",
";",
"// Initialize the container. This will be passed around",
"var",
"$ul",
"=",
"initContextMenuContainer",
"(",
"params",
")",
";",
"params",
".",
"$ul",
"=",
"$ul",
";",
"// Register this level of the context menu",
"_contextMenus",
".",
"push",
"(",
"$ul",
")",
";",
"/*\n * This object will contain any promises that we have\n * to wait for before trying to adjust the context menu.\n */",
"var",
"$promises",
"=",
"[",
"]",
";",
"params",
".",
"$promises",
"=",
"$promises",
";",
"angular",
".",
"forEach",
"(",
"options",
",",
"function",
"(",
"item",
")",
"{",
"if",
"(",
"item",
"===",
"null",
")",
"{",
"appendDivider",
"(",
"$ul",
")",
";",
"}",
"else",
"{",
"// If displayed is anything other than a function or a boolean",
"var",
"displayed",
"=",
"resolveBoolOrFunc",
"(",
"item",
".",
"displayed",
",",
"params",
")",
";",
"// Only add the <li> if the item is displayed",
"if",
"(",
"displayed",
")",
"{",
"var",
"$li",
"=",
"$",
"(",
"'<li>'",
")",
";",
"var",
"itemParams",
"=",
"angular",
".",
"extend",
"(",
"{",
"}",
",",
"params",
")",
";",
"itemParams",
".",
"item",
"=",
"item",
";",
"itemParams",
".",
"$li",
"=",
"$li",
";",
"if",
"(",
"typeof",
"item",
"[",
"0",
"]",
"===",
"'object'",
")",
"{",
"custom",
".",
"initialize",
"(",
"$li",
",",
"item",
")",
";",
"}",
"else",
"{",
"processItem",
"(",
"itemParams",
")",
";",
"}",
"if",
"(",
"resolveBoolOrFunc",
"(",
"item",
".",
"hasTopDivider",
",",
"itemParams",
",",
"false",
")",
")",
"{",
"appendDivider",
"(",
"$ul",
")",
";",
"}",
"$ul",
".",
"append",
"(",
"$li",
")",
";",
"if",
"(",
"resolveBoolOrFunc",
"(",
"item",
".",
"hasBottomDivider",
",",
"itemParams",
",",
"false",
")",
")",
"{",
"appendDivider",
"(",
"$ul",
")",
";",
"}",
"}",
"}",
"}",
")",
";",
"if",
"(",
"$ul",
".",
"children",
"(",
")",
".",
"length",
"===",
"0",
")",
"{",
"var",
"$emptyLi",
"=",
"angular",
".",
"element",
"(",
"'<li>'",
")",
";",
"setElementDisabled",
"(",
"$emptyLi",
")",
";",
"$emptyLi",
".",
"html",
"(",
"'<a>'",
"+",
"_emptyText",
"+",
"'</a>'",
")",
";",
"$ul",
".",
"append",
"(",
"$emptyLi",
")",
";",
"}",
"$document",
".",
"find",
"(",
"'body'",
")",
".",
"append",
"(",
"$ul",
")",
";",
"doAfterAllPromises",
"(",
"params",
")",
";",
"$rootScope",
".",
"$broadcast",
"(",
"ContextMenuEvents",
".",
"ContextMenuOpened",
",",
"{",
"context",
":",
"_clickedElement",
",",
"contextMenu",
":",
"$ul",
",",
"params",
":",
"params",
"}",
")",
";",
"}"
] | Responsible for the actual rendering of the context menu.
The parameters in params are:
- $scope = the scope of this context menu
- event = the event that triggered this context menu
- options = the options for this context menu
- modelValue = the value of the model attached to this context menu
- level = the current context menu level (defauts to 0)
- customClass = the custom class to be used for the context menu | [
"Responsible",
"for",
"the",
"actual",
"rendering",
"of",
"the",
"context",
"menu",
"."
] | 08b66bc3854ffe874b50fedd1597587059edc687 | https://github.com/Templarian/ui.bootstrap.contextMenu/blob/08b66bc3854ffe874b50fedd1597587059edc687/contextMenu.js#L298-L370 |
21,293 | Templarian/ui.bootstrap.contextMenu | contextMenu.js | removeContextMenus | function removeContextMenus (level) {
while (_contextMenus.length && (!level || _contextMenus.length > level)) {
var cm = _contextMenus.pop();
$rootScope.$broadcast(ContextMenuEvents.ContextMenuClosed, { context: _clickedElement, contextMenu: cm });
cm.remove();
}
if(!level) {
$rootScope.$broadcast(ContextMenuEvents.ContextMenuAllClosed, { context: _clickedElement });
}
} | javascript | function removeContextMenus (level) {
while (_contextMenus.length && (!level || _contextMenus.length > level)) {
var cm = _contextMenus.pop();
$rootScope.$broadcast(ContextMenuEvents.ContextMenuClosed, { context: _clickedElement, contextMenu: cm });
cm.remove();
}
if(!level) {
$rootScope.$broadcast(ContextMenuEvents.ContextMenuAllClosed, { context: _clickedElement });
}
} | [
"function",
"removeContextMenus",
"(",
"level",
")",
"{",
"while",
"(",
"_contextMenus",
".",
"length",
"&&",
"(",
"!",
"level",
"||",
"_contextMenus",
".",
"length",
">",
"level",
")",
")",
"{",
"var",
"cm",
"=",
"_contextMenus",
".",
"pop",
"(",
")",
";",
"$rootScope",
".",
"$broadcast",
"(",
"ContextMenuEvents",
".",
"ContextMenuClosed",
",",
"{",
"context",
":",
"_clickedElement",
",",
"contextMenu",
":",
"cm",
"}",
")",
";",
"cm",
".",
"remove",
"(",
")",
";",
"}",
"if",
"(",
"!",
"level",
")",
"{",
"$rootScope",
".",
"$broadcast",
"(",
"ContextMenuEvents",
".",
"ContextMenuAllClosed",
",",
"{",
"context",
":",
"_clickedElement",
"}",
")",
";",
"}",
"}"
] | Removes the context menus with level greater than or equal
to the value passed. If undefined, null or 0, all context menus
are removed. | [
"Removes",
"the",
"context",
"menus",
"with",
"level",
"greater",
"than",
"or",
"equal",
"to",
"the",
"value",
"passed",
".",
"If",
"undefined",
"null",
"or",
"0",
"all",
"context",
"menus",
"are",
"removed",
"."
] | 08b66bc3854ffe874b50fedd1597587059edc687 | https://github.com/Templarian/ui.bootstrap.contextMenu/blob/08b66bc3854ffe874b50fedd1597587059edc687/contextMenu.js#L485-L494 |
21,294 | Templarian/ui.bootstrap.contextMenu | contextMenu.js | resolveBoolOrFunc | function resolveBoolOrFunc(a, params, defaultValue) {
var item = params.item;
var $scope = params.$scope;
var event = params.event;
var modelValue = params.modelValue;
defaultValue = isBoolean(defaultValue) ? defaultValue : true;
if (isBoolean(a)) {
return a;
} else if (angular.isFunction(a)) {
return a.call($scope, $scope, event, modelValue);
} else {
return defaultValue;
}
} | javascript | function resolveBoolOrFunc(a, params, defaultValue) {
var item = params.item;
var $scope = params.$scope;
var event = params.event;
var modelValue = params.modelValue;
defaultValue = isBoolean(defaultValue) ? defaultValue : true;
if (isBoolean(a)) {
return a;
} else if (angular.isFunction(a)) {
return a.call($scope, $scope, event, modelValue);
} else {
return defaultValue;
}
} | [
"function",
"resolveBoolOrFunc",
"(",
"a",
",",
"params",
",",
"defaultValue",
")",
"{",
"var",
"item",
"=",
"params",
".",
"item",
";",
"var",
"$scope",
"=",
"params",
".",
"$scope",
";",
"var",
"event",
"=",
"params",
".",
"event",
";",
"var",
"modelValue",
"=",
"params",
".",
"modelValue",
";",
"defaultValue",
"=",
"isBoolean",
"(",
"defaultValue",
")",
"?",
"defaultValue",
":",
"true",
";",
"if",
"(",
"isBoolean",
"(",
"a",
")",
")",
"{",
"return",
"a",
";",
"}",
"else",
"if",
"(",
"angular",
".",
"isFunction",
"(",
"a",
")",
")",
"{",
"return",
"a",
".",
"call",
"(",
"$scope",
",",
"$scope",
",",
"event",
",",
"modelValue",
")",
";",
"}",
"else",
"{",
"return",
"defaultValue",
";",
"}",
"}"
] | Resolves a boolean or a function that returns a boolean
Returns true by default if the param is null or undefined
@param a - the parameter to be checked
@param params - the object for the item's parameters
@param defaultValue - the default boolean value to use if the parameter is
neither a boolean nor function. True by default. | [
"Resolves",
"a",
"boolean",
"or",
"a",
"function",
"that",
"returns",
"a",
"boolean",
"Returns",
"true",
"by",
"default",
"if",
"the",
"param",
"is",
"null",
"or",
"undefined"
] | 08b66bc3854ffe874b50fedd1597587059edc687 | https://github.com/Templarian/ui.bootstrap.contextMenu/blob/08b66bc3854ffe874b50fedd1597587059edc687/contextMenu.js#L537-L552 |
21,295 | gameclosure/js.io | packages/jsio.js | ModuleDef | function ModuleDef (path) {
this.path = path;
this.friendlyPath = path;
util.splitPath(path, this);
this.directory = util.resolve(ENV.getCwd(), this.directory);
} | javascript | function ModuleDef (path) {
this.path = path;
this.friendlyPath = path;
util.splitPath(path, this);
this.directory = util.resolve(ENV.getCwd(), this.directory);
} | [
"function",
"ModuleDef",
"(",
"path",
")",
"{",
"this",
".",
"path",
"=",
"path",
";",
"this",
".",
"friendlyPath",
"=",
"path",
";",
"util",
".",
"splitPath",
"(",
"path",
",",
"this",
")",
";",
"this",
".",
"directory",
"=",
"util",
".",
"resolve",
"(",
"ENV",
".",
"getCwd",
"(",
")",
",",
"this",
".",
"directory",
")",
";",
"}"
] | Creates an object containing metadata about a module. | [
"Creates",
"an",
"object",
"containing",
"metadata",
"about",
"a",
"module",
"."
] | 369377ea92b4c9b41e6e646c1afaa785b598a753 | https://github.com/gameclosure/js.io/blob/369377ea92b4c9b41e6e646c1afaa785b598a753/packages/jsio.js#L61-L67 |
21,296 | gameclosure/js.io | packages/jsio.js | loadModule | function loadModule (baseLoader, fromDir, fromFile, item, opts) {
var modulePath = item.from;
var possibilities = util.resolveModulePath(modulePath, fromDir);
for (var i = 0, p; p = possibilities[i]; ++i) {
var path = possibilities[i].path;
if (!opts.reload && (path in jsio.__modules)) {
return possibilities[i];
}
if (path in failedFetch) { possibilities.splice(i--, 1); }
}
if (!possibilities.length) {
if (opts.suppressErrors) { return false; }
var e = new Error('Could not import `' + item.from + '`'
+ "\tImport Stack:\n"
+ "\t\t" + processStack().join("\n\t\t"));
e.jsioLogged = true;
e.code = MODULE_NOT_FOUND;
throw e;
}
var moduleDef = findModule(possibilities);
if (!moduleDef) {
if (opts.suppressErrors) { return false; }
var paths = [];
for (var i = 0, p; p = possibilities[i]; ++i) { paths.push(p.path); }
var e = new Error("Could not import `" + modulePath + "`\n"
+ "\tlooked in:\n"
+ "\t\t" + paths.join('\n\t\t') + "\n"
+ "\tImport Stack:\n"
+ "\t\t" + processStack().join("\n\t\t"));
e.code = MODULE_NOT_FOUND;
throw e;
}
// a (potentially) nicer way to refer to a module -- how it was referenced in code when it was first imported
moduleDef.friendlyPath = modulePath;
// cache the base module's path in the path cache so we don't have to
// try out all paths the next time we see the same base module.
if (moduleDef.baseMod && !(moduleDef.baseMod in jsioPath.cache)) {
jsioPath.cache[moduleDef.baseMod] = moduleDef.basePath;
}
// don't apply the standard preprocessors to base.js. If we're reloading
// the source code, always apply them. We also don't want to run them
// if they've been run once -- moduleDef.pre is set to true already
// if we're reading the code from the source cache.
if (modulePath != 'base' && (opts.reload || !opts.dontPreprocess && !moduleDef.pre)) {
moduleDef.pre = true;
applyPreprocessors(fromDir, moduleDef, ["import", "inlineSlice"], opts);
}
// any additional preprocessors?
if (opts.preprocessors) {
applyPreprocessors(fromDir, moduleDef, opts.preprocessors, opts);
}
return moduleDef;
} | javascript | function loadModule (baseLoader, fromDir, fromFile, item, opts) {
var modulePath = item.from;
var possibilities = util.resolveModulePath(modulePath, fromDir);
for (var i = 0, p; p = possibilities[i]; ++i) {
var path = possibilities[i].path;
if (!opts.reload && (path in jsio.__modules)) {
return possibilities[i];
}
if (path in failedFetch) { possibilities.splice(i--, 1); }
}
if (!possibilities.length) {
if (opts.suppressErrors) { return false; }
var e = new Error('Could not import `' + item.from + '`'
+ "\tImport Stack:\n"
+ "\t\t" + processStack().join("\n\t\t"));
e.jsioLogged = true;
e.code = MODULE_NOT_FOUND;
throw e;
}
var moduleDef = findModule(possibilities);
if (!moduleDef) {
if (opts.suppressErrors) { return false; }
var paths = [];
for (var i = 0, p; p = possibilities[i]; ++i) { paths.push(p.path); }
var e = new Error("Could not import `" + modulePath + "`\n"
+ "\tlooked in:\n"
+ "\t\t" + paths.join('\n\t\t') + "\n"
+ "\tImport Stack:\n"
+ "\t\t" + processStack().join("\n\t\t"));
e.code = MODULE_NOT_FOUND;
throw e;
}
// a (potentially) nicer way to refer to a module -- how it was referenced in code when it was first imported
moduleDef.friendlyPath = modulePath;
// cache the base module's path in the path cache so we don't have to
// try out all paths the next time we see the same base module.
if (moduleDef.baseMod && !(moduleDef.baseMod in jsioPath.cache)) {
jsioPath.cache[moduleDef.baseMod] = moduleDef.basePath;
}
// don't apply the standard preprocessors to base.js. If we're reloading
// the source code, always apply them. We also don't want to run them
// if they've been run once -- moduleDef.pre is set to true already
// if we're reading the code from the source cache.
if (modulePath != 'base' && (opts.reload || !opts.dontPreprocess && !moduleDef.pre)) {
moduleDef.pre = true;
applyPreprocessors(fromDir, moduleDef, ["import", "inlineSlice"], opts);
}
// any additional preprocessors?
if (opts.preprocessors) {
applyPreprocessors(fromDir, moduleDef, opts.preprocessors, opts);
}
return moduleDef;
} | [
"function",
"loadModule",
"(",
"baseLoader",
",",
"fromDir",
",",
"fromFile",
",",
"item",
",",
"opts",
")",
"{",
"var",
"modulePath",
"=",
"item",
".",
"from",
";",
"var",
"possibilities",
"=",
"util",
".",
"resolveModulePath",
"(",
"modulePath",
",",
"fromDir",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"p",
";",
"p",
"=",
"possibilities",
"[",
"i",
"]",
";",
"++",
"i",
")",
"{",
"var",
"path",
"=",
"possibilities",
"[",
"i",
"]",
".",
"path",
";",
"if",
"(",
"!",
"opts",
".",
"reload",
"&&",
"(",
"path",
"in",
"jsio",
".",
"__modules",
")",
")",
"{",
"return",
"possibilities",
"[",
"i",
"]",
";",
"}",
"if",
"(",
"path",
"in",
"failedFetch",
")",
"{",
"possibilities",
".",
"splice",
"(",
"i",
"--",
",",
"1",
")",
";",
"}",
"}",
"if",
"(",
"!",
"possibilities",
".",
"length",
")",
"{",
"if",
"(",
"opts",
".",
"suppressErrors",
")",
"{",
"return",
"false",
";",
"}",
"var",
"e",
"=",
"new",
"Error",
"(",
"'Could not import `'",
"+",
"item",
".",
"from",
"+",
"'`'",
"+",
"\"\\tImport Stack:\\n\"",
"+",
"\"\\t\\t\"",
"+",
"processStack",
"(",
")",
".",
"join",
"(",
"\"\\n\\t\\t\"",
")",
")",
";",
"e",
".",
"jsioLogged",
"=",
"true",
";",
"e",
".",
"code",
"=",
"MODULE_NOT_FOUND",
";",
"throw",
"e",
";",
"}",
"var",
"moduleDef",
"=",
"findModule",
"(",
"possibilities",
")",
";",
"if",
"(",
"!",
"moduleDef",
")",
"{",
"if",
"(",
"opts",
".",
"suppressErrors",
")",
"{",
"return",
"false",
";",
"}",
"var",
"paths",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"p",
";",
"p",
"=",
"possibilities",
"[",
"i",
"]",
";",
"++",
"i",
")",
"{",
"paths",
".",
"push",
"(",
"p",
".",
"path",
")",
";",
"}",
"var",
"e",
"=",
"new",
"Error",
"(",
"\"Could not import `\"",
"+",
"modulePath",
"+",
"\"`\\n\"",
"+",
"\"\\tlooked in:\\n\"",
"+",
"\"\\t\\t\"",
"+",
"paths",
".",
"join",
"(",
"'\\n\\t\\t'",
")",
"+",
"\"\\n\"",
"+",
"\"\\tImport Stack:\\n\"",
"+",
"\"\\t\\t\"",
"+",
"processStack",
"(",
")",
".",
"join",
"(",
"\"\\n\\t\\t\"",
")",
")",
";",
"e",
".",
"code",
"=",
"MODULE_NOT_FOUND",
";",
"throw",
"e",
";",
"}",
"// a (potentially) nicer way to refer to a module -- how it was referenced in code when it was first imported",
"moduleDef",
".",
"friendlyPath",
"=",
"modulePath",
";",
"// cache the base module's path in the path cache so we don't have to",
"// try out all paths the next time we see the same base module.",
"if",
"(",
"moduleDef",
".",
"baseMod",
"&&",
"!",
"(",
"moduleDef",
".",
"baseMod",
"in",
"jsioPath",
".",
"cache",
")",
")",
"{",
"jsioPath",
".",
"cache",
"[",
"moduleDef",
".",
"baseMod",
"]",
"=",
"moduleDef",
".",
"basePath",
";",
"}",
"// don't apply the standard preprocessors to base.js. If we're reloading",
"// the source code, always apply them. We also don't want to run them",
"// if they've been run once -- moduleDef.pre is set to true already",
"// if we're reading the code from the source cache.",
"if",
"(",
"modulePath",
"!=",
"'base'",
"&&",
"(",
"opts",
".",
"reload",
"||",
"!",
"opts",
".",
"dontPreprocess",
"&&",
"!",
"moduleDef",
".",
"pre",
")",
")",
"{",
"moduleDef",
".",
"pre",
"=",
"true",
";",
"applyPreprocessors",
"(",
"fromDir",
",",
"moduleDef",
",",
"[",
"\"import\"",
",",
"\"inlineSlice\"",
"]",
",",
"opts",
")",
";",
"}",
"// any additional preprocessors?",
"if",
"(",
"opts",
".",
"preprocessors",
")",
"{",
"applyPreprocessors",
"(",
"fromDir",
",",
"moduleDef",
",",
"opts",
".",
"preprocessors",
",",
"opts",
")",
";",
"}",
"return",
"moduleDef",
";",
"}"
] | load a module from a file | [
"load",
"a",
"module",
"from",
"a",
"file"
] | 369377ea92b4c9b41e6e646c1afaa785b598a753 | https://github.com/gameclosure/js.io/blob/369377ea92b4c9b41e6e646c1afaa785b598a753/packages/jsio.js#L672-L733 |
21,297 | sourcejs/Source | Gruntfile.js | function() {
var packageName;
var parentFolderName = path.basename(path.resolve('..'));
var isSubPackage = parentFolderName === 'node_modules';
var isLocalDepsAvailable = fs.existsSync('node_modules/grunt-autoprefixer') && fs.existsSync('node_modules/grunt-contrib-cssmin');
if (isSubPackage && !isLocalDepsAvailable) {
packageName = 'load-grunt-parent-tasks';
} else {
packageName = 'load-grunt-tasks';
}
return packageName;
} | javascript | function() {
var packageName;
var parentFolderName = path.basename(path.resolve('..'));
var isSubPackage = parentFolderName === 'node_modules';
var isLocalDepsAvailable = fs.existsSync('node_modules/grunt-autoprefixer') && fs.existsSync('node_modules/grunt-contrib-cssmin');
if (isSubPackage && !isLocalDepsAvailable) {
packageName = 'load-grunt-parent-tasks';
} else {
packageName = 'load-grunt-tasks';
}
return packageName;
} | [
"function",
"(",
")",
"{",
"var",
"packageName",
";",
"var",
"parentFolderName",
"=",
"path",
".",
"basename",
"(",
"path",
".",
"resolve",
"(",
"'..'",
")",
")",
";",
"var",
"isSubPackage",
"=",
"parentFolderName",
"===",
"'node_modules'",
";",
"var",
"isLocalDepsAvailable",
"=",
"fs",
".",
"existsSync",
"(",
"'node_modules/grunt-autoprefixer'",
")",
"&&",
"fs",
".",
"existsSync",
"(",
"'node_modules/grunt-contrib-cssmin'",
")",
";",
"if",
"(",
"isSubPackage",
"&&",
"!",
"isLocalDepsAvailable",
")",
"{",
"packageName",
"=",
"'load-grunt-parent-tasks'",
";",
"}",
"else",
"{",
"packageName",
"=",
"'load-grunt-tasks'",
";",
"}",
"return",
"packageName",
";",
"}"
] | NPM 3 compatibility fix | [
"NPM",
"3",
"compatibility",
"fix"
] | e6461409302486c5db1085bb44a81f310403eb90 | https://github.com/sourcejs/Source/blob/e6461409302486c5db1085bb44a81f310403eb90/Gruntfile.js#L11-L24 | |
21,298 | sourcejs/Source | core/api/index.js | function (req, res, parseObj) {
var data = {};
var body = req.body;
var reqID = body.id || req.query.id;
var cats = body.cats || req.query.cats;
var reqFilter = body.filter || req.query.filter;
var reqFilterOut = body.filterOut || req.query.filterOut;
var parsedData = parseObj;
var msgDataNotFound = 'API: Specs data not found, please restart the app.';
if (reqID) {
var dataByID = parsedData.getByID(reqID);
if (dataByID && typeof dataByID === 'object') {
res.status(config.statusCodes.OK).json(dataByID);
} else {
if (typeof dataByID === 'undefined') console.warn(msgDataNotFound);
res.status(config.statusCodes.notFound).json({
message: "id not found"
});
}
} else if (reqFilter || reqFilterOut) {
var dataFiltered = parsedData.getFilteredData({
filter: reqFilter,
filterOut: reqFilterOut
});
if (dataFiltered && typeof dataFiltered === 'object') {
res.status(config.statusCodes.OK).json(dataFiltered);
} else {
console.warn(msgDataNotFound);
res.status(config.statusCodes.notFound).json({
message: "data not found"
});
}
} else {
data = parsedData.getAll(cats);
if (data) {
res.status(config.statusCodes.OK).json(data);
} else {
console.warn(msgDataNotFound);
res.status(config.statusCodes.notFound).json({
message: "data not found"
});
}
}
} | javascript | function (req, res, parseObj) {
var data = {};
var body = req.body;
var reqID = body.id || req.query.id;
var cats = body.cats || req.query.cats;
var reqFilter = body.filter || req.query.filter;
var reqFilterOut = body.filterOut || req.query.filterOut;
var parsedData = parseObj;
var msgDataNotFound = 'API: Specs data not found, please restart the app.';
if (reqID) {
var dataByID = parsedData.getByID(reqID);
if (dataByID && typeof dataByID === 'object') {
res.status(config.statusCodes.OK).json(dataByID);
} else {
if (typeof dataByID === 'undefined') console.warn(msgDataNotFound);
res.status(config.statusCodes.notFound).json({
message: "id not found"
});
}
} else if (reqFilter || reqFilterOut) {
var dataFiltered = parsedData.getFilteredData({
filter: reqFilter,
filterOut: reqFilterOut
});
if (dataFiltered && typeof dataFiltered === 'object') {
res.status(config.statusCodes.OK).json(dataFiltered);
} else {
console.warn(msgDataNotFound);
res.status(config.statusCodes.notFound).json({
message: "data not found"
});
}
} else {
data = parsedData.getAll(cats);
if (data) {
res.status(config.statusCodes.OK).json(data);
} else {
console.warn(msgDataNotFound);
res.status(config.statusCodes.notFound).json({
message: "data not found"
});
}
}
} | [
"function",
"(",
"req",
",",
"res",
",",
"parseObj",
")",
"{",
"var",
"data",
"=",
"{",
"}",
";",
"var",
"body",
"=",
"req",
".",
"body",
";",
"var",
"reqID",
"=",
"body",
".",
"id",
"||",
"req",
".",
"query",
".",
"id",
";",
"var",
"cats",
"=",
"body",
".",
"cats",
"||",
"req",
".",
"query",
".",
"cats",
";",
"var",
"reqFilter",
"=",
"body",
".",
"filter",
"||",
"req",
".",
"query",
".",
"filter",
";",
"var",
"reqFilterOut",
"=",
"body",
".",
"filterOut",
"||",
"req",
".",
"query",
".",
"filterOut",
";",
"var",
"parsedData",
"=",
"parseObj",
";",
"var",
"msgDataNotFound",
"=",
"'API: Specs data not found, please restart the app.'",
";",
"if",
"(",
"reqID",
")",
"{",
"var",
"dataByID",
"=",
"parsedData",
".",
"getByID",
"(",
"reqID",
")",
";",
"if",
"(",
"dataByID",
"&&",
"typeof",
"dataByID",
"===",
"'object'",
")",
"{",
"res",
".",
"status",
"(",
"config",
".",
"statusCodes",
".",
"OK",
")",
".",
"json",
"(",
"dataByID",
")",
";",
"}",
"else",
"{",
"if",
"(",
"typeof",
"dataByID",
"===",
"'undefined'",
")",
"console",
".",
"warn",
"(",
"msgDataNotFound",
")",
";",
"res",
".",
"status",
"(",
"config",
".",
"statusCodes",
".",
"notFound",
")",
".",
"json",
"(",
"{",
"message",
":",
"\"id not found\"",
"}",
")",
";",
"}",
"}",
"else",
"if",
"(",
"reqFilter",
"||",
"reqFilterOut",
")",
"{",
"var",
"dataFiltered",
"=",
"parsedData",
".",
"getFilteredData",
"(",
"{",
"filter",
":",
"reqFilter",
",",
"filterOut",
":",
"reqFilterOut",
"}",
")",
";",
"if",
"(",
"dataFiltered",
"&&",
"typeof",
"dataFiltered",
"===",
"'object'",
")",
"{",
"res",
".",
"status",
"(",
"config",
".",
"statusCodes",
".",
"OK",
")",
".",
"json",
"(",
"dataFiltered",
")",
";",
"}",
"else",
"{",
"console",
".",
"warn",
"(",
"msgDataNotFound",
")",
";",
"res",
".",
"status",
"(",
"config",
".",
"statusCodes",
".",
"notFound",
")",
".",
"json",
"(",
"{",
"message",
":",
"\"data not found\"",
"}",
")",
";",
"}",
"}",
"else",
"{",
"data",
"=",
"parsedData",
".",
"getAll",
"(",
"cats",
")",
";",
"if",
"(",
"data",
")",
"{",
"res",
".",
"status",
"(",
"config",
".",
"statusCodes",
".",
"OK",
")",
".",
"json",
"(",
"data",
")",
";",
"}",
"else",
"{",
"console",
".",
"warn",
"(",
"msgDataNotFound",
")",
";",
"res",
".",
"status",
"(",
"config",
".",
"statusCodes",
".",
"notFound",
")",
".",
"json",
"(",
"{",
"message",
":",
"\"data not found\"",
"}",
")",
";",
"}",
"}",
"}"
] | getSpecs REST api processor
@param {Object} req - express request
@param {Object} res - express response
@param {Object} parseObj - initiated parseData instance
Writes result to res object | [
"getSpecs",
"REST",
"api",
"processor"
] | e6461409302486c5db1085bb44a81f310403eb90 | https://github.com/sourcejs/Source/blob/e6461409302486c5db1085bb44a81f310403eb90/core/api/index.js#L33-L85 | |
21,299 | sourcejs/Source | core/api/index.js | function (req, res, parseObj) {
var data = {};
var body = req.body;
var reqID = body.id || req.query.id;
var reqSections = body.sections || req.query.sections;
var sections = reqSections ? reqSections.split(',') : undefined;
var parsedData = parseObj;
var msgDataNotFound = 'API: HTML data not found, please sync API or run PhantomJS parser.';
if (reqID) {
var responseData = '';
if (reqSections) {
responseData = parsedData.getBySection(reqID, sections);
} else {
responseData = parsedData.getByID(reqID);
}
if (responseData && typeof responseData === 'object') {
res.status(config.statusCodes.OK).json(responseData);
} else {
if (typeof responseData === 'undefined') console.warn(msgDataNotFound);
res.status(config.statusCodes.notFound).json({
message: "id and requested sections not found"
});
}
} else {
data = parsedData.getAll();
if (data) {
res.status(config.statusCodes.OK).json(data);
} else {
console.warn(msgDataNotFound);
res.status(config.statusCodes.notFound).json({
message: "data not found"
});
}
}
} | javascript | function (req, res, parseObj) {
var data = {};
var body = req.body;
var reqID = body.id || req.query.id;
var reqSections = body.sections || req.query.sections;
var sections = reqSections ? reqSections.split(',') : undefined;
var parsedData = parseObj;
var msgDataNotFound = 'API: HTML data not found, please sync API or run PhantomJS parser.';
if (reqID) {
var responseData = '';
if (reqSections) {
responseData = parsedData.getBySection(reqID, sections);
} else {
responseData = parsedData.getByID(reqID);
}
if (responseData && typeof responseData === 'object') {
res.status(config.statusCodes.OK).json(responseData);
} else {
if (typeof responseData === 'undefined') console.warn(msgDataNotFound);
res.status(config.statusCodes.notFound).json({
message: "id and requested sections not found"
});
}
} else {
data = parsedData.getAll();
if (data) {
res.status(config.statusCodes.OK).json(data);
} else {
console.warn(msgDataNotFound);
res.status(config.statusCodes.notFound).json({
message: "data not found"
});
}
}
} | [
"function",
"(",
"req",
",",
"res",
",",
"parseObj",
")",
"{",
"var",
"data",
"=",
"{",
"}",
";",
"var",
"body",
"=",
"req",
".",
"body",
";",
"var",
"reqID",
"=",
"body",
".",
"id",
"||",
"req",
".",
"query",
".",
"id",
";",
"var",
"reqSections",
"=",
"body",
".",
"sections",
"||",
"req",
".",
"query",
".",
"sections",
";",
"var",
"sections",
"=",
"reqSections",
"?",
"reqSections",
".",
"split",
"(",
"','",
")",
":",
"undefined",
";",
"var",
"parsedData",
"=",
"parseObj",
";",
"var",
"msgDataNotFound",
"=",
"'API: HTML data not found, please sync API or run PhantomJS parser.'",
";",
"if",
"(",
"reqID",
")",
"{",
"var",
"responseData",
"=",
"''",
";",
"if",
"(",
"reqSections",
")",
"{",
"responseData",
"=",
"parsedData",
".",
"getBySection",
"(",
"reqID",
",",
"sections",
")",
";",
"}",
"else",
"{",
"responseData",
"=",
"parsedData",
".",
"getByID",
"(",
"reqID",
")",
";",
"}",
"if",
"(",
"responseData",
"&&",
"typeof",
"responseData",
"===",
"'object'",
")",
"{",
"res",
".",
"status",
"(",
"config",
".",
"statusCodes",
".",
"OK",
")",
".",
"json",
"(",
"responseData",
")",
";",
"}",
"else",
"{",
"if",
"(",
"typeof",
"responseData",
"===",
"'undefined'",
")",
"console",
".",
"warn",
"(",
"msgDataNotFound",
")",
";",
"res",
".",
"status",
"(",
"config",
".",
"statusCodes",
".",
"notFound",
")",
".",
"json",
"(",
"{",
"message",
":",
"\"id and requested sections not found\"",
"}",
")",
";",
"}",
"}",
"else",
"{",
"data",
"=",
"parsedData",
".",
"getAll",
"(",
")",
";",
"if",
"(",
"data",
")",
"{",
"res",
".",
"status",
"(",
"config",
".",
"statusCodes",
".",
"OK",
")",
".",
"json",
"(",
"data",
")",
";",
"}",
"else",
"{",
"console",
".",
"warn",
"(",
"msgDataNotFound",
")",
";",
"res",
".",
"status",
"(",
"config",
".",
"statusCodes",
".",
"notFound",
")",
".",
"json",
"(",
"{",
"message",
":",
"\"data not found\"",
"}",
")",
";",
"}",
"}",
"}"
] | getHTML REST api processor
@param {Object} req - express request
@param {Object} res - express response
@param {Object} parseObj - initiated parseData instance
Writes result to res object | [
"getHTML",
"REST",
"api",
"processor"
] | e6461409302486c5db1085bb44a81f310403eb90 | https://github.com/sourcejs/Source/blob/e6461409302486c5db1085bb44a81f310403eb90/core/api/index.js#L96-L137 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.