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,400 | derrickpelletier/geohash-poly | index.js | function (point, geopoly) {
var inside = 0;
if(geopoly.type !== "Polygon" && geopoly.type !== "MultiPolygon") return false;
var shape = geopoly.type === 'Polygon' ? [geopoly.coordinates] : geopoly.coordinates;
shape.forEach(function (polygon) {
polygon.forEach(function (ring) {
if(pip([point.longitude, point.latitude], ring)) inside++;
});
});
return inside % 2;
} | javascript | function (point, geopoly) {
var inside = 0;
if(geopoly.type !== "Polygon" && geopoly.type !== "MultiPolygon") return false;
var shape = geopoly.type === 'Polygon' ? [geopoly.coordinates] : geopoly.coordinates;
shape.forEach(function (polygon) {
polygon.forEach(function (ring) {
if(pip([point.longitude, point.latitude], ring)) inside++;
});
});
return inside % 2;
} | [
"function",
"(",
"point",
",",
"geopoly",
")",
"{",
"var",
"inside",
"=",
"0",
";",
"if",
"(",
"geopoly",
".",
"type",
"!==",
"\"Polygon\"",
"&&",
"geopoly",
".",
"type",
"!==",
"\"MultiPolygon\"",
")",
"return",
"false",
";",
"var",
"shape",
"=",
"geopoly",
".",
"type",
"===",
"'Polygon'",
"?",
"[",
"geopoly",
".",
"coordinates",
"]",
":",
"geopoly",
".",
"coordinates",
";",
"shape",
".",
"forEach",
"(",
"function",
"(",
"polygon",
")",
"{",
"polygon",
".",
"forEach",
"(",
"function",
"(",
"ring",
")",
"{",
"if",
"(",
"pip",
"(",
"[",
"point",
".",
"longitude",
",",
"point",
".",
"latitude",
"]",
",",
"ring",
")",
")",
"inside",
"++",
";",
"}",
")",
";",
"}",
")",
";",
"return",
"inside",
"%",
"2",
";",
"}"
] | utilizing point-in-poly but providing support for geojson polys and holes. | [
"utilizing",
"point",
"-",
"in",
"-",
"poly",
"but",
"providing",
"support",
"for",
"geojson",
"polys",
"and",
"holes",
"."
] | 0965a3b1035186895a3b5fa8121a1624dfb792d3 | https://github.com/derrickpelletier/geohash-poly/blob/0965a3b1035186895a3b5fa8121a1624dfb792d3/index.js#L21-L33 | |
21,401 | nirvanatikku/jQuery-TubePlayer-Plugin | dist/jquery.tubeplayer.js | function(fn) {
return function(evt, param) {
var p = TP.getPkg(evt);
if (p.ytplayer) {
var ret = fn(evt, param, p);
if (typeof(ret) === "undefined") {
ret = p.$player;
}
return ret;
}
return p.$player;
};
} | javascript | function(fn) {
return function(evt, param) {
var p = TP.getPkg(evt);
if (p.ytplayer) {
var ret = fn(evt, param, p);
if (typeof(ret) === "undefined") {
ret = p.$player;
}
return ret;
}
return p.$player;
};
} | [
"function",
"(",
"fn",
")",
"{",
"return",
"function",
"(",
"evt",
",",
"param",
")",
"{",
"var",
"p",
"=",
"TP",
".",
"getPkg",
"(",
"evt",
")",
";",
"if",
"(",
"p",
".",
"ytplayer",
")",
"{",
"var",
"ret",
"=",
"fn",
"(",
"evt",
",",
"param",
",",
"p",
")",
";",
"if",
"(",
"typeof",
"(",
"ret",
")",
"===",
"\"undefined\"",
")",
"{",
"ret",
"=",
"p",
".",
"$player",
";",
"}",
"return",
"ret",
";",
"}",
"return",
"p",
".",
"$player",
";",
"}",
";",
"}"
] | This method is the base method for all the events
that are bound to the TubePlayer. | [
"This",
"method",
"is",
"the",
"base",
"method",
"for",
"all",
"the",
"events",
"that",
"are",
"bound",
"to",
"the",
"TubePlayer",
"."
] | d03aef44a7b157776e218338705ba12e65831f00 | https://github.com/nirvanatikku/jQuery-TubePlayer-Plugin/blob/d03aef44a7b157776e218338705ba12e65831f00/dist/jquery.tubeplayer.js#L246-L258 | |
21,402 | screener-io/screener-storybook | src/runner.js | function(storybook, baseUrl, previewRoute) {
// clean baseUrl. remove query/hash/trailing-slash
var urlObj = url.parse(baseUrl);
urlObj = omit(urlObj, 'hash', 'search', 'query');
urlObj.pathname = urlObj.pathname.replace(/\/$/, '');
baseUrl = url.format(urlObj);
// transform into states
var states = [];
storybook.forEach(function(component) {
component.stories.forEach(function(story) {
var previewUrl = baseUrl + previewRoute + '?dataId=0&selectedKind=' + encodeURIComponent(component.kind) + '&selectedStory=' + encodeURIComponent(story.name);
var state = {
url: previewUrl,
name: component.kind + ': ' + story.name
};
if (story.steps) {
state.steps = story.steps;
}
states.push(state);
});
});
return states;
} | javascript | function(storybook, baseUrl, previewRoute) {
// clean baseUrl. remove query/hash/trailing-slash
var urlObj = url.parse(baseUrl);
urlObj = omit(urlObj, 'hash', 'search', 'query');
urlObj.pathname = urlObj.pathname.replace(/\/$/, '');
baseUrl = url.format(urlObj);
// transform into states
var states = [];
storybook.forEach(function(component) {
component.stories.forEach(function(story) {
var previewUrl = baseUrl + previewRoute + '?dataId=0&selectedKind=' + encodeURIComponent(component.kind) + '&selectedStory=' + encodeURIComponent(story.name);
var state = {
url: previewUrl,
name: component.kind + ': ' + story.name
};
if (story.steps) {
state.steps = story.steps;
}
states.push(state);
});
});
return states;
} | [
"function",
"(",
"storybook",
",",
"baseUrl",
",",
"previewRoute",
")",
"{",
"// clean baseUrl. remove query/hash/trailing-slash",
"var",
"urlObj",
"=",
"url",
".",
"parse",
"(",
"baseUrl",
")",
";",
"urlObj",
"=",
"omit",
"(",
"urlObj",
",",
"'hash'",
",",
"'search'",
",",
"'query'",
")",
";",
"urlObj",
".",
"pathname",
"=",
"urlObj",
".",
"pathname",
".",
"replace",
"(",
"/",
"\\/$",
"/",
",",
"''",
")",
";",
"baseUrl",
"=",
"url",
".",
"format",
"(",
"urlObj",
")",
";",
"// transform into states",
"var",
"states",
"=",
"[",
"]",
";",
"storybook",
".",
"forEach",
"(",
"function",
"(",
"component",
")",
"{",
"component",
".",
"stories",
".",
"forEach",
"(",
"function",
"(",
"story",
")",
"{",
"var",
"previewUrl",
"=",
"baseUrl",
"+",
"previewRoute",
"+",
"'?dataId=0&selectedKind='",
"+",
"encodeURIComponent",
"(",
"component",
".",
"kind",
")",
"+",
"'&selectedStory='",
"+",
"encodeURIComponent",
"(",
"story",
".",
"name",
")",
";",
"var",
"state",
"=",
"{",
"url",
":",
"previewUrl",
",",
"name",
":",
"component",
".",
"kind",
"+",
"': '",
"+",
"story",
".",
"name",
"}",
";",
"if",
"(",
"story",
".",
"steps",
")",
"{",
"state",
".",
"steps",
"=",
"story",
".",
"steps",
";",
"}",
"states",
".",
"push",
"(",
"state",
")",
";",
"}",
")",
";",
"}",
")",
";",
"return",
"states",
";",
"}"
] | transform storybook object into screener states | [
"transform",
"storybook",
"object",
"into",
"screener",
"states"
] | 48854c1814f49ffcd3954864bc2505b665626843 | https://github.com/screener-io/screener-storybook/blob/48854c1814f49ffcd3954864bc2505b665626843/src/runner.js#L9-L31 | |
21,403 | screener-io/screener-storybook | src/scripts/story-steps.js | function(current) {
if (current && current.props) {
if (current.props.isScreenerComponent === true) {
return current.props.steps;
} else {
var steps = null;
if (typeof current.props.story === 'function') {
steps = findScreenerSteps(current.props.story());
}
if (!steps && typeof current.props.storyFn === 'function') {
steps = findScreenerSteps(current.props.storyFn());
}
if (!steps && current.props.initialContent) {
steps = findScreenerSteps(current.props.initialContent);
}
if (!steps && typeof current.type === 'function') {
try {
steps = findScreenerSteps(current.type());
} catch(ex) { /**/ }
}
if (!steps && current.props.children) {
var children = current.props.children;
// handle array of children
if (typeof children === 'object' && typeof children.map === 'function' && children.length > 0) {
for (var i = 0, len = children.length; i < len; i++) {
steps = findScreenerSteps(children[i]);
if (steps) break;
}
} else {
steps = findScreenerSteps(children);
}
}
return steps;
}
}
} | javascript | function(current) {
if (current && current.props) {
if (current.props.isScreenerComponent === true) {
return current.props.steps;
} else {
var steps = null;
if (typeof current.props.story === 'function') {
steps = findScreenerSteps(current.props.story());
}
if (!steps && typeof current.props.storyFn === 'function') {
steps = findScreenerSteps(current.props.storyFn());
}
if (!steps && current.props.initialContent) {
steps = findScreenerSteps(current.props.initialContent);
}
if (!steps && typeof current.type === 'function') {
try {
steps = findScreenerSteps(current.type());
} catch(ex) { /**/ }
}
if (!steps && current.props.children) {
var children = current.props.children;
// handle array of children
if (typeof children === 'object' && typeof children.map === 'function' && children.length > 0) {
for (var i = 0, len = children.length; i < len; i++) {
steps = findScreenerSteps(children[i]);
if (steps) break;
}
} else {
steps = findScreenerSteps(children);
}
}
return steps;
}
}
} | [
"function",
"(",
"current",
")",
"{",
"if",
"(",
"current",
"&&",
"current",
".",
"props",
")",
"{",
"if",
"(",
"current",
".",
"props",
".",
"isScreenerComponent",
"===",
"true",
")",
"{",
"return",
"current",
".",
"props",
".",
"steps",
";",
"}",
"else",
"{",
"var",
"steps",
"=",
"null",
";",
"if",
"(",
"typeof",
"current",
".",
"props",
".",
"story",
"===",
"'function'",
")",
"{",
"steps",
"=",
"findScreenerSteps",
"(",
"current",
".",
"props",
".",
"story",
"(",
")",
")",
";",
"}",
"if",
"(",
"!",
"steps",
"&&",
"typeof",
"current",
".",
"props",
".",
"storyFn",
"===",
"'function'",
")",
"{",
"steps",
"=",
"findScreenerSteps",
"(",
"current",
".",
"props",
".",
"storyFn",
"(",
")",
")",
";",
"}",
"if",
"(",
"!",
"steps",
"&&",
"current",
".",
"props",
".",
"initialContent",
")",
"{",
"steps",
"=",
"findScreenerSteps",
"(",
"current",
".",
"props",
".",
"initialContent",
")",
";",
"}",
"if",
"(",
"!",
"steps",
"&&",
"typeof",
"current",
".",
"type",
"===",
"'function'",
")",
"{",
"try",
"{",
"steps",
"=",
"findScreenerSteps",
"(",
"current",
".",
"type",
"(",
")",
")",
";",
"}",
"catch",
"(",
"ex",
")",
"{",
"/**/",
"}",
"}",
"if",
"(",
"!",
"steps",
"&&",
"current",
".",
"props",
".",
"children",
")",
"{",
"var",
"children",
"=",
"current",
".",
"props",
".",
"children",
";",
"// handle array of children",
"if",
"(",
"typeof",
"children",
"===",
"'object'",
"&&",
"typeof",
"children",
".",
"map",
"===",
"'function'",
"&&",
"children",
".",
"length",
">",
"0",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"children",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"steps",
"=",
"findScreenerSteps",
"(",
"children",
"[",
"i",
"]",
")",
";",
"if",
"(",
"steps",
")",
"break",
";",
"}",
"}",
"else",
"{",
"steps",
"=",
"findScreenerSteps",
"(",
"children",
")",
";",
"}",
"}",
"return",
"steps",
";",
"}",
"}",
"}"
] | recursively find screener steps | [
"recursively",
"find",
"screener",
"steps"
] | 48854c1814f49ffcd3954864bc2505b665626843 | https://github.com/screener-io/screener-storybook/blob/48854c1814f49ffcd3954864bc2505b665626843/src/scripts/story-steps.js#L40-L75 | |
21,404 | screener-io/screener-storybook | src/scripts/story-steps.js | function(current) {
if (typeof current.steps === 'object' && typeof current.steps.map === 'function' && current.steps.length > 0) {
return current.steps;
}
var steps = null;
if (typeof current.render === 'function') {
try {
steps = findScreenerStepsInRender(current.render(function(fn) {
return fn;
}));
} catch (ex) {
steps = null;
}
}
if (typeof current.components === 'object' && typeof current.components.story === 'object' && typeof current.components.story.render === 'function') {
try {
steps = findScreenerStepsInRender(current.components.story.render(function(fn) {
return fn;
}, {}));
} catch (ex) {
steps = null;
}
}
return steps;
} | javascript | function(current) {
if (typeof current.steps === 'object' && typeof current.steps.map === 'function' && current.steps.length > 0) {
return current.steps;
}
var steps = null;
if (typeof current.render === 'function') {
try {
steps = findScreenerStepsInRender(current.render(function(fn) {
return fn;
}));
} catch (ex) {
steps = null;
}
}
if (typeof current.components === 'object' && typeof current.components.story === 'object' && typeof current.components.story.render === 'function') {
try {
steps = findScreenerStepsInRender(current.components.story.render(function(fn) {
return fn;
}, {}));
} catch (ex) {
steps = null;
}
}
return steps;
} | [
"function",
"(",
"current",
")",
"{",
"if",
"(",
"typeof",
"current",
".",
"steps",
"===",
"'object'",
"&&",
"typeof",
"current",
".",
"steps",
".",
"map",
"===",
"'function'",
"&&",
"current",
".",
"steps",
".",
"length",
">",
"0",
")",
"{",
"return",
"current",
".",
"steps",
";",
"}",
"var",
"steps",
"=",
"null",
";",
"if",
"(",
"typeof",
"current",
".",
"render",
"===",
"'function'",
")",
"{",
"try",
"{",
"steps",
"=",
"findScreenerStepsInRender",
"(",
"current",
".",
"render",
"(",
"function",
"(",
"fn",
")",
"{",
"return",
"fn",
";",
"}",
")",
")",
";",
"}",
"catch",
"(",
"ex",
")",
"{",
"steps",
"=",
"null",
";",
"}",
"}",
"if",
"(",
"typeof",
"current",
".",
"components",
"===",
"'object'",
"&&",
"typeof",
"current",
".",
"components",
".",
"story",
"===",
"'object'",
"&&",
"typeof",
"current",
".",
"components",
".",
"story",
".",
"render",
"===",
"'function'",
")",
"{",
"try",
"{",
"steps",
"=",
"findScreenerStepsInRender",
"(",
"current",
".",
"components",
".",
"story",
".",
"render",
"(",
"function",
"(",
"fn",
")",
"{",
"return",
"fn",
";",
"}",
",",
"{",
"}",
")",
")",
";",
"}",
"catch",
"(",
"ex",
")",
"{",
"steps",
"=",
"null",
";",
"}",
"}",
"return",
"steps",
";",
"}"
] | recursively find screener steps in render function | [
"recursively",
"find",
"screener",
"steps",
"in",
"render",
"function"
] | 48854c1814f49ffcd3954864bc2505b665626843 | https://github.com/screener-io/screener-storybook/blob/48854c1814f49ffcd3954864bc2505b665626843/src/scripts/story-steps.js#L83-L107 | |
21,405 | vacuumlabs/babel-plugin-extensible-destructuring | src/index.js | hasRest | function hasRest(pattern) {
for (let elem of pattern.elements) {
if (isRestElement(t, elem)) {
return true
}
}
return false
} | javascript | function hasRest(pattern) {
for (let elem of pattern.elements) {
if (isRestElement(t, elem)) {
return true
}
}
return false
} | [
"function",
"hasRest",
"(",
"pattern",
")",
"{",
"for",
"(",
"let",
"elem",
"of",
"pattern",
".",
"elements",
")",
"{",
"if",
"(",
"isRestElement",
"(",
"t",
",",
"elem",
")",
")",
"{",
"return",
"true",
"}",
"}",
"return",
"false",
"}"
] | Test if an ArrayPattern's elements contain any RestElements. | [
"Test",
"if",
"an",
"ArrayPattern",
"s",
"elements",
"contain",
"any",
"RestElements",
"."
] | ac5d8b0737628b1af4923d30a92162b26ec582bf | https://github.com/vacuumlabs/babel-plugin-extensible-destructuring/blob/ac5d8b0737628b1af4923d30a92162b26ec582bf/src/index.js#L102-L109 |
21,406 | vacuumlabs/babel-plugin-extensible-destructuring | src/index.js | getDirective | function getDirective(path) {
for (let directive of path.node.directives) {
let dirstr = directive.value.value
if (dirstr.startsWith('use ')) {
let uses = dirstr.substr(4).split(',').map((use) => use.trim())
if (uses.indexOf('extensible') !== -1) {
return 1
}
if (uses.indexOf('!extensible') !== -1) {
return -1
}
}
}
return 0
} | javascript | function getDirective(path) {
for (let directive of path.node.directives) {
let dirstr = directive.value.value
if (dirstr.startsWith('use ')) {
let uses = dirstr.substr(4).split(',').map((use) => use.trim())
if (uses.indexOf('extensible') !== -1) {
return 1
}
if (uses.indexOf('!extensible') !== -1) {
return -1
}
}
}
return 0
} | [
"function",
"getDirective",
"(",
"path",
")",
"{",
"for",
"(",
"let",
"directive",
"of",
"path",
".",
"node",
".",
"directives",
")",
"{",
"let",
"dirstr",
"=",
"directive",
".",
"value",
".",
"value",
"if",
"(",
"dirstr",
".",
"startsWith",
"(",
"'use '",
")",
")",
"{",
"let",
"uses",
"=",
"dirstr",
".",
"substr",
"(",
"4",
")",
".",
"split",
"(",
"','",
")",
".",
"map",
"(",
"(",
"use",
")",
"=>",
"use",
".",
"trim",
"(",
")",
")",
"if",
"(",
"uses",
".",
"indexOf",
"(",
"'extensible'",
")",
"!==",
"-",
"1",
")",
"{",
"return",
"1",
"}",
"if",
"(",
"uses",
".",
"indexOf",
"(",
"'!extensible'",
")",
"!==",
"-",
"1",
")",
"{",
"return",
"-",
"1",
"}",
"}",
"}",
"return",
"0",
"}"
] | 0 - no directive 1 - 'use extensible' directive -1 - 'use !extensible' directive | [
"0",
"-",
"no",
"directive",
"1",
"-",
"use",
"extensible",
"directive",
"-",
"1",
"-",
"use",
"!extensible",
"directive"
] | ac5d8b0737628b1af4923d30a92162b26ec582bf | https://github.com/vacuumlabs/babel-plugin-extensible-destructuring/blob/ac5d8b0737628b1af4923d30a92162b26ec582bf/src/index.js#L384-L398 |
21,407 | johansatge/jpeg-autorotate | src/transform.js | flipPixels | function flipPixels(buffer, width, height) {
const newBuffer = Buffer.alloc(buffer.length)
for (let x = 0; x < width; x += 1) {
for (let y = 0; y < height; y += 1) {
const offset = (width * y + x) << 2
const newOffset = (width * y + width - 1 - x) << 2
const pixel = buffer.readUInt32BE(offset, true)
newBuffer.writeUInt32BE(pixel, newOffset, true)
}
}
return newBuffer
} | javascript | function flipPixels(buffer, width, height) {
const newBuffer = Buffer.alloc(buffer.length)
for (let x = 0; x < width; x += 1) {
for (let y = 0; y < height; y += 1) {
const offset = (width * y + x) << 2
const newOffset = (width * y + width - 1 - x) << 2
const pixel = buffer.readUInt32BE(offset, true)
newBuffer.writeUInt32BE(pixel, newOffset, true)
}
}
return newBuffer
} | [
"function",
"flipPixels",
"(",
"buffer",
",",
"width",
",",
"height",
")",
"{",
"const",
"newBuffer",
"=",
"Buffer",
".",
"alloc",
"(",
"buffer",
".",
"length",
")",
"for",
"(",
"let",
"x",
"=",
"0",
";",
"x",
"<",
"width",
";",
"x",
"+=",
"1",
")",
"{",
"for",
"(",
"let",
"y",
"=",
"0",
";",
"y",
"<",
"height",
";",
"y",
"+=",
"1",
")",
"{",
"const",
"offset",
"=",
"(",
"width",
"*",
"y",
"+",
"x",
")",
"<<",
"2",
"const",
"newOffset",
"=",
"(",
"width",
"*",
"y",
"+",
"width",
"-",
"1",
"-",
"x",
")",
"<<",
"2",
"const",
"pixel",
"=",
"buffer",
".",
"readUInt32BE",
"(",
"offset",
",",
"true",
")",
"newBuffer",
".",
"writeUInt32BE",
"(",
"pixel",
",",
"newOffset",
",",
"true",
")",
"}",
"}",
"return",
"newBuffer",
"}"
] | Flip a buffer horizontally | [
"Flip",
"a",
"buffer",
"horizontally"
] | 2b4a37f9b929122b3e29b19ddc1f5c16e6db6733 | https://github.com/johansatge/jpeg-autorotate/blob/2b4a37f9b929122b3e29b19ddc1f5c16e6db6733/src/transform.js#L73-L84 |
21,408 | johansatge/jpeg-autorotate | src/main.js | parseOrientationTag | function parseOrientationTag({buffer, exifData}) {
let orientation = null
if (exifData['0th'] && exifData['0th'][piexif.ImageIFD.Orientation]) {
orientation = parseInt(exifData['0th'][piexif.ImageIFD.Orientation])
}
if (orientation === null) {
throw new CustomError(m.errors.no_orientation, 'No orientation tag found in EXIF', buffer)
}
if (isNaN(orientation) || orientation < 1 || orientation > 8) {
throw new CustomError(m.errors.unknown_orientation, 'Unknown orientation (' + orientation + ')', buffer)
}
if (orientation === 1) {
throw new CustomError(m.errors.correct_orientation, 'Orientation already correct', buffer)
}
return orientation
} | javascript | function parseOrientationTag({buffer, exifData}) {
let orientation = null
if (exifData['0th'] && exifData['0th'][piexif.ImageIFD.Orientation]) {
orientation = parseInt(exifData['0th'][piexif.ImageIFD.Orientation])
}
if (orientation === null) {
throw new CustomError(m.errors.no_orientation, 'No orientation tag found in EXIF', buffer)
}
if (isNaN(orientation) || orientation < 1 || orientation > 8) {
throw new CustomError(m.errors.unknown_orientation, 'Unknown orientation (' + orientation + ')', buffer)
}
if (orientation === 1) {
throw new CustomError(m.errors.correct_orientation, 'Orientation already correct', buffer)
}
return orientation
} | [
"function",
"parseOrientationTag",
"(",
"{",
"buffer",
",",
"exifData",
"}",
")",
"{",
"let",
"orientation",
"=",
"null",
"if",
"(",
"exifData",
"[",
"'0th'",
"]",
"&&",
"exifData",
"[",
"'0th'",
"]",
"[",
"piexif",
".",
"ImageIFD",
".",
"Orientation",
"]",
")",
"{",
"orientation",
"=",
"parseInt",
"(",
"exifData",
"[",
"'0th'",
"]",
"[",
"piexif",
".",
"ImageIFD",
".",
"Orientation",
"]",
")",
"}",
"if",
"(",
"orientation",
"===",
"null",
")",
"{",
"throw",
"new",
"CustomError",
"(",
"m",
".",
"errors",
".",
"no_orientation",
",",
"'No orientation tag found in EXIF'",
",",
"buffer",
")",
"}",
"if",
"(",
"isNaN",
"(",
"orientation",
")",
"||",
"orientation",
"<",
"1",
"||",
"orientation",
">",
"8",
")",
"{",
"throw",
"new",
"CustomError",
"(",
"m",
".",
"errors",
".",
"unknown_orientation",
",",
"'Unknown orientation ('",
"+",
"orientation",
"+",
"')'",
",",
"buffer",
")",
"}",
"if",
"(",
"orientation",
"===",
"1",
")",
"{",
"throw",
"new",
"CustomError",
"(",
"m",
".",
"errors",
".",
"correct_orientation",
",",
"'Orientation already correct'",
",",
"buffer",
")",
"}",
"return",
"orientation",
"}"
] | Extract the orientation tag from the given EXIF data | [
"Extract",
"the",
"orientation",
"tag",
"from",
"the",
"given",
"EXIF",
"data"
] | 2b4a37f9b929122b3e29b19ddc1f5c16e6db6733 | https://github.com/johansatge/jpeg-autorotate/blob/2b4a37f9b929122b3e29b19ddc1f5c16e6db6733/src/main.js#L96-L111 |
21,409 | johansatge/jpeg-autorotate | src/main.js | computeFinalBuffer | function computeFinalBuffer(image, thumbnail, exifData, orientation) {
exifData['0th'][piexif.ImageIFD.Orientation] = 1
if (typeof exifData['Exif'][piexif.ExifIFD.PixelXDimension] !== 'undefined') {
exifData['Exif'][piexif.ExifIFD.PixelXDimension] = image.width
}
if (typeof exifData['Exif'][piexif.ExifIFD.PixelYDimension] !== 'undefined') {
exifData['Exif'][piexif.ExifIFD.PixelYDimension] = image.height
}
if (thumbnail.buffer) {
exifData['thumbnail'] = thumbnail.buffer.toString('binary')
}
const exifBytes = piexif.dump(exifData)
const updatedBuffer = Buffer.from(piexif.insert(exifBytes, image.buffer.toString('binary')), 'binary')
const updatedDimensions = {
height: image.height,
width: image.width,
}
return Promise.resolve({updatedBuffer, orientation, updatedDimensions})
} | javascript | function computeFinalBuffer(image, thumbnail, exifData, orientation) {
exifData['0th'][piexif.ImageIFD.Orientation] = 1
if (typeof exifData['Exif'][piexif.ExifIFD.PixelXDimension] !== 'undefined') {
exifData['Exif'][piexif.ExifIFD.PixelXDimension] = image.width
}
if (typeof exifData['Exif'][piexif.ExifIFD.PixelYDimension] !== 'undefined') {
exifData['Exif'][piexif.ExifIFD.PixelYDimension] = image.height
}
if (thumbnail.buffer) {
exifData['thumbnail'] = thumbnail.buffer.toString('binary')
}
const exifBytes = piexif.dump(exifData)
const updatedBuffer = Buffer.from(piexif.insert(exifBytes, image.buffer.toString('binary')), 'binary')
const updatedDimensions = {
height: image.height,
width: image.width,
}
return Promise.resolve({updatedBuffer, orientation, updatedDimensions})
} | [
"function",
"computeFinalBuffer",
"(",
"image",
",",
"thumbnail",
",",
"exifData",
",",
"orientation",
")",
"{",
"exifData",
"[",
"'0th'",
"]",
"[",
"piexif",
".",
"ImageIFD",
".",
"Orientation",
"]",
"=",
"1",
"if",
"(",
"typeof",
"exifData",
"[",
"'Exif'",
"]",
"[",
"piexif",
".",
"ExifIFD",
".",
"PixelXDimension",
"]",
"!==",
"'undefined'",
")",
"{",
"exifData",
"[",
"'Exif'",
"]",
"[",
"piexif",
".",
"ExifIFD",
".",
"PixelXDimension",
"]",
"=",
"image",
".",
"width",
"}",
"if",
"(",
"typeof",
"exifData",
"[",
"'Exif'",
"]",
"[",
"piexif",
".",
"ExifIFD",
".",
"PixelYDimension",
"]",
"!==",
"'undefined'",
")",
"{",
"exifData",
"[",
"'Exif'",
"]",
"[",
"piexif",
".",
"ExifIFD",
".",
"PixelYDimension",
"]",
"=",
"image",
".",
"height",
"}",
"if",
"(",
"thumbnail",
".",
"buffer",
")",
"{",
"exifData",
"[",
"'thumbnail'",
"]",
"=",
"thumbnail",
".",
"buffer",
".",
"toString",
"(",
"'binary'",
")",
"}",
"const",
"exifBytes",
"=",
"piexif",
".",
"dump",
"(",
"exifData",
")",
"const",
"updatedBuffer",
"=",
"Buffer",
".",
"from",
"(",
"piexif",
".",
"insert",
"(",
"exifBytes",
",",
"image",
".",
"buffer",
".",
"toString",
"(",
"'binary'",
")",
")",
",",
"'binary'",
")",
"const",
"updatedDimensions",
"=",
"{",
"height",
":",
"image",
".",
"height",
",",
"width",
":",
"image",
".",
"width",
",",
"}",
"return",
"Promise",
".",
"resolve",
"(",
"{",
"updatedBuffer",
",",
"orientation",
",",
"updatedDimensions",
"}",
")",
"}"
] | Compute the final buffer by updating the original EXIF data and linking it to the rotated buffer | [
"Compute",
"the",
"final",
"buffer",
"by",
"updating",
"the",
"original",
"EXIF",
"data",
"and",
"linking",
"it",
"to",
"the",
"rotated",
"buffer"
] | 2b4a37f9b929122b3e29b19ddc1f5c16e6db6733 | https://github.com/johansatge/jpeg-autorotate/blob/2b4a37f9b929122b3e29b19ddc1f5c16e6db6733/src/main.js#L131-L149 |
21,410 | chrisyip/koa-pug | src/pug.js | contextRenderer | function contextRenderer (tpl, locals, options, noCache) {
var finalLocals = merge({}, helpers, defaultLocals, this.state, locals)
this.body = renderer(tpl, finalLocals, options, noCache)
this.type = 'text/html'
return this
} | javascript | function contextRenderer (tpl, locals, options, noCache) {
var finalLocals = merge({}, helpers, defaultLocals, this.state, locals)
this.body = renderer(tpl, finalLocals, options, noCache)
this.type = 'text/html'
return this
} | [
"function",
"contextRenderer",
"(",
"tpl",
",",
"locals",
",",
"options",
",",
"noCache",
")",
"{",
"var",
"finalLocals",
"=",
"merge",
"(",
"{",
"}",
",",
"helpers",
",",
"defaultLocals",
",",
"this",
".",
"state",
",",
"locals",
")",
"this",
".",
"body",
"=",
"renderer",
"(",
"tpl",
",",
"finalLocals",
",",
"options",
",",
"noCache",
")",
"this",
".",
"type",
"=",
"'text/html'",
"return",
"this",
"}"
] | Render function that attached to app context
@param {String} tpl the template path, search start from viewPath
@param {Object} locals locals, will merged with global locals and ctx.state
@param {Object} options options that pass to Pug compiler, merged with global default options
@param {Boolean} noCache use cache or not | [
"Render",
"function",
"that",
"attached",
"to",
"app",
"context"
] | 1ac559fdd1a6d43c91bec8c83cde9c3853d8fa12 | https://github.com/chrisyip/koa-pug/blob/1ac559fdd1a6d43c91bec8c83cde9c3853d8fa12/src/pug.js#L103-L109 |
21,411 | netceteragroup/valdr | src/message/valdrMessage-directive.js | function (restrict) {
return ['$compile', function ($compile) {
return {
restrict: restrict,
require: ['?^valdrType', '?^ngModel', '?^valdrFormGroup'],
link: function (scope, element, attrs, controllers) {
var valdrTypeController = controllers[0],
ngModelController = controllers[1],
valdrFormGroupController = controllers[2],
valdrNoValidate = attrs.valdrNoValidate,
valdrNoMessage = attrs.valdrNoMessage,
fieldName = attrs.name;
/**
* Don't do anything if
* - this is an <input> that's not inside of a valdr-type or valdr-form-group block
* - there is no ng-model bound to input
* - there is a 'valdr-no-validate' or 'valdr-no-message' attribute present
*/
if (!valdrTypeController || !valdrFormGroupController || !ngModelController ||
angular.isDefined(valdrNoValidate) || angular.isDefined(valdrNoMessage)) {
return;
}
var valdrMessageElement = angular.element('<span valdr-message="' + fieldName + '"></span>');
$compile(valdrMessageElement)(scope);
valdrFormGroupController.addMessageElement(ngModelController, valdrMessageElement);
scope.$on('$destroy', function () {
valdrFormGroupController.removeMessageElement(ngModelController);
});
}
};
}];
} | javascript | function (restrict) {
return ['$compile', function ($compile) {
return {
restrict: restrict,
require: ['?^valdrType', '?^ngModel', '?^valdrFormGroup'],
link: function (scope, element, attrs, controllers) {
var valdrTypeController = controllers[0],
ngModelController = controllers[1],
valdrFormGroupController = controllers[2],
valdrNoValidate = attrs.valdrNoValidate,
valdrNoMessage = attrs.valdrNoMessage,
fieldName = attrs.name;
/**
* Don't do anything if
* - this is an <input> that's not inside of a valdr-type or valdr-form-group block
* - there is no ng-model bound to input
* - there is a 'valdr-no-validate' or 'valdr-no-message' attribute present
*/
if (!valdrTypeController || !valdrFormGroupController || !ngModelController ||
angular.isDefined(valdrNoValidate) || angular.isDefined(valdrNoMessage)) {
return;
}
var valdrMessageElement = angular.element('<span valdr-message="' + fieldName + '"></span>');
$compile(valdrMessageElement)(scope);
valdrFormGroupController.addMessageElement(ngModelController, valdrMessageElement);
scope.$on('$destroy', function () {
valdrFormGroupController.removeMessageElement(ngModelController);
});
}
};
}];
} | [
"function",
"(",
"restrict",
")",
"{",
"return",
"[",
"'$compile'",
",",
"function",
"(",
"$compile",
")",
"{",
"return",
"{",
"restrict",
":",
"restrict",
",",
"require",
":",
"[",
"'?^valdrType'",
",",
"'?^ngModel'",
",",
"'?^valdrFormGroup'",
"]",
",",
"link",
":",
"function",
"(",
"scope",
",",
"element",
",",
"attrs",
",",
"controllers",
")",
"{",
"var",
"valdrTypeController",
"=",
"controllers",
"[",
"0",
"]",
",",
"ngModelController",
"=",
"controllers",
"[",
"1",
"]",
",",
"valdrFormGroupController",
"=",
"controllers",
"[",
"2",
"]",
",",
"valdrNoValidate",
"=",
"attrs",
".",
"valdrNoValidate",
",",
"valdrNoMessage",
"=",
"attrs",
".",
"valdrNoMessage",
",",
"fieldName",
"=",
"attrs",
".",
"name",
";",
"/**\n * Don't do anything if\n * - this is an <input> that's not inside of a valdr-type or valdr-form-group block\n * - there is no ng-model bound to input\n * - there is a 'valdr-no-validate' or 'valdr-no-message' attribute present\n */",
"if",
"(",
"!",
"valdrTypeController",
"||",
"!",
"valdrFormGroupController",
"||",
"!",
"ngModelController",
"||",
"angular",
".",
"isDefined",
"(",
"valdrNoValidate",
")",
"||",
"angular",
".",
"isDefined",
"(",
"valdrNoMessage",
")",
")",
"{",
"return",
";",
"}",
"var",
"valdrMessageElement",
"=",
"angular",
".",
"element",
"(",
"'<span valdr-message=\"'",
"+",
"fieldName",
"+",
"'\"></span>'",
")",
";",
"$compile",
"(",
"valdrMessageElement",
")",
"(",
"scope",
")",
";",
"valdrFormGroupController",
".",
"addMessageElement",
"(",
"ngModelController",
",",
"valdrMessageElement",
")",
";",
"scope",
".",
"$on",
"(",
"'$destroy'",
",",
"function",
"(",
")",
"{",
"valdrFormGroupController",
".",
"removeMessageElement",
"(",
"ngModelController",
")",
";",
"}",
")",
";",
"}",
"}",
";",
"}",
"]",
";",
"}"
] | This directive appends a validation message to the parent element of any input, select or textarea element, which
is nested in a valdr-type directive and has an ng-model bound to it.
If the form element is wrapped in an element marked with the class defined in valdrClasses.formGroup,
the messages is appended to this element instead of the direct parent.
To prevent adding messages to specific input fields, the attribute 'valdr-no-message' can be added to those input
or select fields. The valdr-message directive is used to do the actual rendering of the violation messages. | [
"This",
"directive",
"appends",
"a",
"validation",
"message",
"to",
"the",
"parent",
"element",
"of",
"any",
"input",
"select",
"or",
"textarea",
"element",
"which",
"is",
"nested",
"in",
"a",
"valdr",
"-",
"type",
"directive",
"and",
"has",
"an",
"ng",
"-",
"model",
"bound",
"to",
"it",
".",
"If",
"the",
"form",
"element",
"is",
"wrapped",
"in",
"an",
"element",
"marked",
"with",
"the",
"class",
"defined",
"in",
"valdrClasses",
".",
"formGroup",
"the",
"messages",
"is",
"appended",
"to",
"this",
"element",
"instead",
"of",
"the",
"direct",
"parent",
".",
"To",
"prevent",
"adding",
"messages",
"to",
"specific",
"input",
"fields",
"the",
"attribute",
"valdr",
"-",
"no",
"-",
"message",
"can",
"be",
"added",
"to",
"those",
"input",
"or",
"select",
"fields",
".",
"The",
"valdr",
"-",
"message",
"directive",
"is",
"used",
"to",
"do",
"the",
"actual",
"rendering",
"of",
"the",
"violation",
"messages",
"."
] | 2a6174f18402087602c98b82b33a7ed05dfb8020 | https://github.com/netceteragroup/valdr/blob/2a6174f18402087602c98b82b33a7ed05dfb8020/src/message/valdrMessage-directive.js#L9-L45 | |
21,412 | netceteragroup/valdr | src/core/valdrUtil-service.js | function (value, prefix) {
return angular.isString(value) &&
angular.isString(prefix) &&
value.lastIndexOf(prefix, 0) === 0;
} | javascript | function (value, prefix) {
return angular.isString(value) &&
angular.isString(prefix) &&
value.lastIndexOf(prefix, 0) === 0;
} | [
"function",
"(",
"value",
",",
"prefix",
")",
"{",
"return",
"angular",
".",
"isString",
"(",
"value",
")",
"&&",
"angular",
".",
"isString",
"(",
"prefix",
")",
"&&",
"value",
".",
"lastIndexOf",
"(",
"prefix",
",",
"0",
")",
"===",
"0",
";",
"}"
] | Checks if a string value starts with a given prefix.
@param value the value
@param prefix the prefix
@returns {boolean} true if the given value starts with the given prefix. | [
"Checks",
"if",
"a",
"string",
"value",
"starts",
"with",
"a",
"given",
"prefix",
"."
] | 2a6174f18402087602c98b82b33a7ed05dfb8020 | https://github.com/netceteragroup/valdr/blob/2a6174f18402087602c98b82b33a7ed05dfb8020/src/core/valdrUtil-service.js#L90-L94 | |
21,413 | netceteragroup/valdr | src/core/validators/patternValidator.js | function (value, constraint) {
var pattern = asRegExp(constraint.value);
return valdrUtil.isEmpty(value) || pattern.test(value);
} | javascript | function (value, constraint) {
var pattern = asRegExp(constraint.value);
return valdrUtil.isEmpty(value) || pattern.test(value);
} | [
"function",
"(",
"value",
",",
"constraint",
")",
"{",
"var",
"pattern",
"=",
"asRegExp",
"(",
"constraint",
".",
"value",
")",
";",
"return",
"valdrUtil",
".",
"isEmpty",
"(",
"value",
")",
"||",
"pattern",
".",
"test",
"(",
"value",
")",
";",
"}"
] | Checks if the value matches the pattern defined in the constraint.
@param value the value to validate
@param constraint the constraint with the regexp as value
@returns {boolean} true if valid | [
"Checks",
"if",
"the",
"value",
"matches",
"the",
"pattern",
"defined",
"in",
"the",
"constraint",
"."
] | 2a6174f18402087602c98b82b33a7ed05dfb8020 | https://github.com/netceteragroup/valdr/blob/2a6174f18402087602c98b82b33a7ed05dfb8020/src/core/validators/patternValidator.js#L39-L42 | |
21,414 | netceteragroup/valdr | src/core/validators/digitsValidator.js | function (value, constraint) {
if (valdrUtil.isEmpty(value)) {
return true;
}
if (valdrUtil.isNaN(Number(value))) {
return false;
}
return doValidate(value, constraint);
} | javascript | function (value, constraint) {
if (valdrUtil.isEmpty(value)) {
return true;
}
if (valdrUtil.isNaN(Number(value))) {
return false;
}
return doValidate(value, constraint);
} | [
"function",
"(",
"value",
",",
"constraint",
")",
"{",
"if",
"(",
"valdrUtil",
".",
"isEmpty",
"(",
"value",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"valdrUtil",
".",
"isNaN",
"(",
"Number",
"(",
"value",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"doValidate",
"(",
"value",
",",
"constraint",
")",
";",
"}"
] | Checks if the value is a number within accepted range.
@param value the value to validate
@param constraint the validation constraint, it is expected to have integer and fraction properties (maximum
number of integral/fractional digits accepted for this number)
@returns {boolean} true if valid | [
"Checks",
"if",
"the",
"value",
"is",
"a",
"number",
"within",
"accepted",
"range",
"."
] | 2a6174f18402087602c98b82b33a7ed05dfb8020 | https://github.com/netceteragroup/valdr/blob/2a6174f18402087602c98b82b33a7ed05dfb8020/src/core/validators/digitsValidator.js#L44-L54 | |
21,415 | netceteragroup/valdr | src/core/valdr-service.js | function (typeName, fieldName, value) {
var validResult = { valid: true },
typeConstraints = constraintsForType(typeName);
if (valdrUtil.has(typeConstraints, fieldName)) {
var fieldConstraints = typeConstraints[fieldName],
fieldIsValid = true,
validationResults = [],
violations = [];
angular.forEach(fieldConstraints, function (constraint, validatorName) {
var validator = validators[validatorName];
if (angular.isUndefined(validator)) {
$log.warn('No validator defined for \'' + validatorName +
'\'. Can not validate field \'' + fieldName + '\'');
return validResult;
}
var valid = validator.validate(value, constraint);
var validationResult = {
valid: valid,
value: value,
field: fieldName,
type: typeName,
validator: validatorName
};
angular.extend(validationResult, constraint);
validationResults.push(validationResult);
if (!valid) {
violations.push(validationResult);
}
fieldIsValid = fieldIsValid && valid;
});
return {
valid: fieldIsValid,
violations: violations.length === 0 ? undefined : violations,
validationResults: validationResults.length === 0 ? undefined : validationResults
};
} else {
return validResult;
}
} | javascript | function (typeName, fieldName, value) {
var validResult = { valid: true },
typeConstraints = constraintsForType(typeName);
if (valdrUtil.has(typeConstraints, fieldName)) {
var fieldConstraints = typeConstraints[fieldName],
fieldIsValid = true,
validationResults = [],
violations = [];
angular.forEach(fieldConstraints, function (constraint, validatorName) {
var validator = validators[validatorName];
if (angular.isUndefined(validator)) {
$log.warn('No validator defined for \'' + validatorName +
'\'. Can not validate field \'' + fieldName + '\'');
return validResult;
}
var valid = validator.validate(value, constraint);
var validationResult = {
valid: valid,
value: value,
field: fieldName,
type: typeName,
validator: validatorName
};
angular.extend(validationResult, constraint);
validationResults.push(validationResult);
if (!valid) {
violations.push(validationResult);
}
fieldIsValid = fieldIsValid && valid;
});
return {
valid: fieldIsValid,
violations: violations.length === 0 ? undefined : violations,
validationResults: validationResults.length === 0 ? undefined : validationResults
};
} else {
return validResult;
}
} | [
"function",
"(",
"typeName",
",",
"fieldName",
",",
"value",
")",
"{",
"var",
"validResult",
"=",
"{",
"valid",
":",
"true",
"}",
",",
"typeConstraints",
"=",
"constraintsForType",
"(",
"typeName",
")",
";",
"if",
"(",
"valdrUtil",
".",
"has",
"(",
"typeConstraints",
",",
"fieldName",
")",
")",
"{",
"var",
"fieldConstraints",
"=",
"typeConstraints",
"[",
"fieldName",
"]",
",",
"fieldIsValid",
"=",
"true",
",",
"validationResults",
"=",
"[",
"]",
",",
"violations",
"=",
"[",
"]",
";",
"angular",
".",
"forEach",
"(",
"fieldConstraints",
",",
"function",
"(",
"constraint",
",",
"validatorName",
")",
"{",
"var",
"validator",
"=",
"validators",
"[",
"validatorName",
"]",
";",
"if",
"(",
"angular",
".",
"isUndefined",
"(",
"validator",
")",
")",
"{",
"$log",
".",
"warn",
"(",
"'No validator defined for \\''",
"+",
"validatorName",
"+",
"'\\'. Can not validate field \\''",
"+",
"fieldName",
"+",
"'\\''",
")",
";",
"return",
"validResult",
";",
"}",
"var",
"valid",
"=",
"validator",
".",
"validate",
"(",
"value",
",",
"constraint",
")",
";",
"var",
"validationResult",
"=",
"{",
"valid",
":",
"valid",
",",
"value",
":",
"value",
",",
"field",
":",
"fieldName",
",",
"type",
":",
"typeName",
",",
"validator",
":",
"validatorName",
"}",
";",
"angular",
".",
"extend",
"(",
"validationResult",
",",
"constraint",
")",
";",
"validationResults",
".",
"push",
"(",
"validationResult",
")",
";",
"if",
"(",
"!",
"valid",
")",
"{",
"violations",
".",
"push",
"(",
"validationResult",
")",
";",
"}",
"fieldIsValid",
"=",
"fieldIsValid",
"&&",
"valid",
";",
"}",
")",
";",
"return",
"{",
"valid",
":",
"fieldIsValid",
",",
"violations",
":",
"violations",
".",
"length",
"===",
"0",
"?",
"undefined",
":",
"violations",
",",
"validationResults",
":",
"validationResults",
".",
"length",
"===",
"0",
"?",
"undefined",
":",
"validationResults",
"}",
";",
"}",
"else",
"{",
"return",
"validResult",
";",
"}",
"}"
] | Validates the value of the given type with the constraints for the given field name.
@param typeName the type name
@param fieldName the field name
@param value the value to validate
@returns {*} | [
"Validates",
"the",
"value",
"of",
"the",
"given",
"type",
"with",
"the",
"constraints",
"for",
"the",
"given",
"field",
"name",
"."
] | 2a6174f18402087602c98b82b33a7ed05dfb8020 | https://github.com/netceteragroup/valdr/blob/2a6174f18402087602c98b82b33a7ed05dfb8020/src/core/valdr-service.js#L102-L147 | |
21,416 | netceteragroup/valdr | src/core/validators/hibernateEmailValidator.js | function (value) {
if (valdrUtil.isEmpty(value)) {
return true;
}
// split email at '@' and consider local and domain part separately
var emailParts = value.split('@');
if (emailParts.length !== 2) {
return false;
}
if (!localPattern.test(emailParts[0])) {
return false;
}
return domainPattern.test(emailParts[1]);
} | javascript | function (value) {
if (valdrUtil.isEmpty(value)) {
return true;
}
// split email at '@' and consider local and domain part separately
var emailParts = value.split('@');
if (emailParts.length !== 2) {
return false;
}
if (!localPattern.test(emailParts[0])) {
return false;
}
return domainPattern.test(emailParts[1]);
} | [
"function",
"(",
"value",
")",
"{",
"if",
"(",
"valdrUtil",
".",
"isEmpty",
"(",
"value",
")",
")",
"{",
"return",
"true",
";",
"}",
"// split email at '@' and consider local and domain part separately",
"var",
"emailParts",
"=",
"value",
".",
"split",
"(",
"'@'",
")",
";",
"if",
"(",
"emailParts",
".",
"length",
"!==",
"2",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"localPattern",
".",
"test",
"(",
"emailParts",
"[",
"0",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"domainPattern",
".",
"test",
"(",
"emailParts",
"[",
"1",
"]",
")",
";",
"}"
] | Checks if the value is a valid email address using the same patterns as Hibernate uses in its bean validation
implementation.
@param value the value to validate
@returns {boolean} true if valid | [
"Checks",
"if",
"the",
"value",
"is",
"a",
"valid",
"email",
"address",
"using",
"the",
"same",
"patterns",
"as",
"Hibernate",
"uses",
"in",
"its",
"bean",
"validation",
"implementation",
"."
] | 2a6174f18402087602c98b82b33a7ed05dfb8020 | https://github.com/netceteragroup/valdr/blob/2a6174f18402087602c98b82b33a7ed05dfb8020/src/core/validators/hibernateEmailValidator.js#L21-L37 | |
21,417 | bem-archive/bem-tools | lib/nodes/bundle.js | function(tech) {
return (this.level.getConfig().bundleBuildLevels || [])
.concat([PATH.resolve(this.root, PATH.dirname(this.getNodePrefix()), 'blocks')]);
} | javascript | function(tech) {
return (this.level.getConfig().bundleBuildLevels || [])
.concat([PATH.resolve(this.root, PATH.dirname(this.getNodePrefix()), 'blocks')]);
} | [
"function",
"(",
"tech",
")",
"{",
"return",
"(",
"this",
".",
"level",
".",
"getConfig",
"(",
")",
".",
"bundleBuildLevels",
"||",
"[",
"]",
")",
".",
"concat",
"(",
"[",
"PATH",
".",
"resolve",
"(",
"this",
".",
"root",
",",
"PATH",
".",
"dirname",
"(",
"this",
".",
"getNodePrefix",
"(",
")",
")",
",",
"'blocks'",
")",
"]",
")",
";",
"}"
] | Constructs array of levels to build tech from.
@param {String} tech Tech name.
@return {Array} Array of levels. | [
"Constructs",
"array",
"of",
"levels",
"to",
"build",
"tech",
"from",
"."
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/nodes/bundle.js#L156-L159 | |
21,418 | bem-archive/bem-tools | lib/nodes/bundle.js | function(techName, techPath, declPath, bundleNode, magicNode, forked) {
var arch = this.ctx.arch,
buildNode = new BemBuildNode.BemBuildNode({
root: this.root,
bundlesLevel: this.level,
levels: this.getLevels(techName),
declPath: declPath,
techPath: techPath,
techName: techName,
output: this.getNodePrefix(),
forked: forked === undefined? ~this.getForkedTechs().indexOf(techName): forked
});
var tech = this.level.getTech(techName, techPath),
metaNode;
/* techs-v2: don't create meta node */
if (tech.API_VER !== 2) metaNode = buildNode.getMetaNode();
// Set bem build node to arch and add dependencies to it
arch.setNode(buildNode)
.addChildren(buildNode, buildNode.getDependencies());
// Add file aliases to arch and link with buildNode as parents
buildNode.getFiles().forEach(function(f) {
if (buildNode.getId() === f) return;
var alias = new fileNodes.FileNode({ path: f, root: this.root });
arch.setNode(alias).addParents(buildNode, alias);
}, this);
bundleNode && arch.addParents(buildNode, bundleNode);
magicNode && arch.addChildren(buildNode, magicNode);
/* techs-v2: don't add dependency on meta node */
if (metaNode) {
// Set bem build meta node to arch
arch.setNode(metaNode)
.addParents(metaNode, buildNode)
.addChildren(metaNode, metaNode.getDependencies());
}
return buildNode;
} | javascript | function(techName, techPath, declPath, bundleNode, magicNode, forked) {
var arch = this.ctx.arch,
buildNode = new BemBuildNode.BemBuildNode({
root: this.root,
bundlesLevel: this.level,
levels: this.getLevels(techName),
declPath: declPath,
techPath: techPath,
techName: techName,
output: this.getNodePrefix(),
forked: forked === undefined? ~this.getForkedTechs().indexOf(techName): forked
});
var tech = this.level.getTech(techName, techPath),
metaNode;
/* techs-v2: don't create meta node */
if (tech.API_VER !== 2) metaNode = buildNode.getMetaNode();
// Set bem build node to arch and add dependencies to it
arch.setNode(buildNode)
.addChildren(buildNode, buildNode.getDependencies());
// Add file aliases to arch and link with buildNode as parents
buildNode.getFiles().forEach(function(f) {
if (buildNode.getId() === f) return;
var alias = new fileNodes.FileNode({ path: f, root: this.root });
arch.setNode(alias).addParents(buildNode, alias);
}, this);
bundleNode && arch.addParents(buildNode, bundleNode);
magicNode && arch.addChildren(buildNode, magicNode);
/* techs-v2: don't add dependency on meta node */
if (metaNode) {
// Set bem build meta node to arch
arch.setNode(metaNode)
.addParents(metaNode, buildNode)
.addChildren(metaNode, metaNode.getDependencies());
}
return buildNode;
} | [
"function",
"(",
"techName",
",",
"techPath",
",",
"declPath",
",",
"bundleNode",
",",
"magicNode",
",",
"forked",
")",
"{",
"var",
"arch",
"=",
"this",
".",
"ctx",
".",
"arch",
",",
"buildNode",
"=",
"new",
"BemBuildNode",
".",
"BemBuildNode",
"(",
"{",
"root",
":",
"this",
".",
"root",
",",
"bundlesLevel",
":",
"this",
".",
"level",
",",
"levels",
":",
"this",
".",
"getLevels",
"(",
"techName",
")",
",",
"declPath",
":",
"declPath",
",",
"techPath",
":",
"techPath",
",",
"techName",
":",
"techName",
",",
"output",
":",
"this",
".",
"getNodePrefix",
"(",
")",
",",
"forked",
":",
"forked",
"===",
"undefined",
"?",
"~",
"this",
".",
"getForkedTechs",
"(",
")",
".",
"indexOf",
"(",
"techName",
")",
":",
"forked",
"}",
")",
";",
"var",
"tech",
"=",
"this",
".",
"level",
".",
"getTech",
"(",
"techName",
",",
"techPath",
")",
",",
"metaNode",
";",
"/* techs-v2: don't create meta node */",
"if",
"(",
"tech",
".",
"API_VER",
"!==",
"2",
")",
"metaNode",
"=",
"buildNode",
".",
"getMetaNode",
"(",
")",
";",
"// Set bem build node to arch and add dependencies to it",
"arch",
".",
"setNode",
"(",
"buildNode",
")",
".",
"addChildren",
"(",
"buildNode",
",",
"buildNode",
".",
"getDependencies",
"(",
")",
")",
";",
"// Add file aliases to arch and link with buildNode as parents",
"buildNode",
".",
"getFiles",
"(",
")",
".",
"forEach",
"(",
"function",
"(",
"f",
")",
"{",
"if",
"(",
"buildNode",
".",
"getId",
"(",
")",
"===",
"f",
")",
"return",
";",
"var",
"alias",
"=",
"new",
"fileNodes",
".",
"FileNode",
"(",
"{",
"path",
":",
"f",
",",
"root",
":",
"this",
".",
"root",
"}",
")",
";",
"arch",
".",
"setNode",
"(",
"alias",
")",
".",
"addParents",
"(",
"buildNode",
",",
"alias",
")",
";",
"}",
",",
"this",
")",
";",
"bundleNode",
"&&",
"arch",
".",
"addParents",
"(",
"buildNode",
",",
"bundleNode",
")",
";",
"magicNode",
"&&",
"arch",
".",
"addChildren",
"(",
"buildNode",
",",
"magicNode",
")",
";",
"/* techs-v2: don't add dependency on meta node */",
"if",
"(",
"metaNode",
")",
"{",
"// Set bem build meta node to arch",
"arch",
".",
"setNode",
"(",
"metaNode",
")",
".",
"addParents",
"(",
"metaNode",
",",
"buildNode",
")",
".",
"addChildren",
"(",
"metaNode",
",",
"metaNode",
".",
"getDependencies",
"(",
")",
")",
";",
"}",
"return",
"buildNode",
";",
"}"
] | Create a bem build node, add it to the arch, add
dependencies to it. Then create a meta node and link
it to the build node.
@param {String} techName
@param {String} techPath
@param {String} declPath
@param {String} bundleNode
@param {String} magicNode
@param {Boolean} [forked]
@return {Node} | [
"Create",
"a",
"bem",
"build",
"node",
"add",
"it",
"to",
"the",
"arch",
"add",
"dependencies",
"to",
"it",
".",
"Then",
"create",
"a",
"meta",
"node",
"and",
"link",
"it",
"to",
"the",
"build",
"node",
"."
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/nodes/bundle.js#L206-L253 | |
21,419 | bem-archive/bem-tools | lib/nodes/bundle.js | function(techName, techPath, bundleNode, magicNode, force, forked) {
var arch = this.ctx.arch,
node = this.useFileOrBuild(new BemCreateNode.BemCreateNode({
root: this.root,
level: this.level,
item: this.item,
techPath: techPath,
techName: techName,
force: force,
forked: forked === undefined? ~this.getForkedTechs().indexOf(techName): forked
}));
if (!node) return;
// Set bem create node to arch and add dependencies to it
arch.setNode(node)
.addChildren(node, node.getDependencies());
// Add file aliases to arch and link with node as parents
node.getFiles && node.getFiles().forEach(function(f) {
if (node.getId() === f) return;
var alias = new fileNodes.FileNode({ path: f, root: this.root });
arch.setNode(alias).addParents(node, alias);
}, this);
bundleNode && arch.addParents(node, bundleNode);
magicNode && arch.addChildren(node, magicNode);
return node;
} | javascript | function(techName, techPath, bundleNode, magicNode, force, forked) {
var arch = this.ctx.arch,
node = this.useFileOrBuild(new BemCreateNode.BemCreateNode({
root: this.root,
level: this.level,
item: this.item,
techPath: techPath,
techName: techName,
force: force,
forked: forked === undefined? ~this.getForkedTechs().indexOf(techName): forked
}));
if (!node) return;
// Set bem create node to arch and add dependencies to it
arch.setNode(node)
.addChildren(node, node.getDependencies());
// Add file aliases to arch and link with node as parents
node.getFiles && node.getFiles().forEach(function(f) {
if (node.getId() === f) return;
var alias = new fileNodes.FileNode({ path: f, root: this.root });
arch.setNode(alias).addParents(node, alias);
}, this);
bundleNode && arch.addParents(node, bundleNode);
magicNode && arch.addChildren(node, magicNode);
return node;
} | [
"function",
"(",
"techName",
",",
"techPath",
",",
"bundleNode",
",",
"magicNode",
",",
"force",
",",
"forked",
")",
"{",
"var",
"arch",
"=",
"this",
".",
"ctx",
".",
"arch",
",",
"node",
"=",
"this",
".",
"useFileOrBuild",
"(",
"new",
"BemCreateNode",
".",
"BemCreateNode",
"(",
"{",
"root",
":",
"this",
".",
"root",
",",
"level",
":",
"this",
".",
"level",
",",
"item",
":",
"this",
".",
"item",
",",
"techPath",
":",
"techPath",
",",
"techName",
":",
"techName",
",",
"force",
":",
"force",
",",
"forked",
":",
"forked",
"===",
"undefined",
"?",
"~",
"this",
".",
"getForkedTechs",
"(",
")",
".",
"indexOf",
"(",
"techName",
")",
":",
"forked",
"}",
")",
")",
";",
"if",
"(",
"!",
"node",
")",
"return",
";",
"// Set bem create node to arch and add dependencies to it",
"arch",
".",
"setNode",
"(",
"node",
")",
".",
"addChildren",
"(",
"node",
",",
"node",
".",
"getDependencies",
"(",
")",
")",
";",
"// Add file aliases to arch and link with node as parents",
"node",
".",
"getFiles",
"&&",
"node",
".",
"getFiles",
"(",
")",
".",
"forEach",
"(",
"function",
"(",
"f",
")",
"{",
"if",
"(",
"node",
".",
"getId",
"(",
")",
"===",
"f",
")",
"return",
";",
"var",
"alias",
"=",
"new",
"fileNodes",
".",
"FileNode",
"(",
"{",
"path",
":",
"f",
",",
"root",
":",
"this",
".",
"root",
"}",
")",
";",
"arch",
".",
"setNode",
"(",
"alias",
")",
".",
"addParents",
"(",
"node",
",",
"alias",
")",
";",
"}",
",",
"this",
")",
";",
"bundleNode",
"&&",
"arch",
".",
"addParents",
"(",
"node",
",",
"bundleNode",
")",
";",
"magicNode",
"&&",
"arch",
".",
"addChildren",
"(",
"node",
",",
"magicNode",
")",
";",
"return",
"node",
";",
"}"
] | Create a bem create node, add it to the arch,
add dependencies to it.
@param {String} techName
@param {String} techPath
@param {String} bundleNode
@param {String} magicNode
@param {Boolean} [force]
@param {Boolean} [forked]
@return {Node | undefined} | [
"Create",
"a",
"bem",
"create",
"node",
"add",
"it",
"to",
"the",
"arch",
"add",
"dependencies",
"to",
"it",
"."
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/nodes/bundle.js#L267-L301 | |
21,420 | bem-archive/bem-tools | lib/nodes/bundle.js | function(tech, bundleNode, magicNode) {
var arch = this.ctx.arch,
filePath = this.getBundlePath(tech);
if (!PATH.existsSync(PATH.resolve(this.root, filePath))) return;
var node = new fileNodes.FileNode({
root: this.root,
path: filePath
});
arch.setNode(node);
bundleNode && arch.addParents(node, bundleNode);
magicNode && arch.addChildren(node, magicNode);
return node;
} | javascript | function(tech, bundleNode, magicNode) {
var arch = this.ctx.arch,
filePath = this.getBundlePath(tech);
if (!PATH.existsSync(PATH.resolve(this.root, filePath))) return;
var node = new fileNodes.FileNode({
root: this.root,
path: filePath
});
arch.setNode(node);
bundleNode && arch.addParents(node, bundleNode);
magicNode && arch.addChildren(node, magicNode);
return node;
} | [
"function",
"(",
"tech",
",",
"bundleNode",
",",
"magicNode",
")",
"{",
"var",
"arch",
"=",
"this",
".",
"ctx",
".",
"arch",
",",
"filePath",
"=",
"this",
".",
"getBundlePath",
"(",
"tech",
")",
";",
"if",
"(",
"!",
"PATH",
".",
"existsSync",
"(",
"PATH",
".",
"resolve",
"(",
"this",
".",
"root",
",",
"filePath",
")",
")",
")",
"return",
";",
"var",
"node",
"=",
"new",
"fileNodes",
".",
"FileNode",
"(",
"{",
"root",
":",
"this",
".",
"root",
",",
"path",
":",
"filePath",
"}",
")",
";",
"arch",
".",
"setNode",
"(",
"node",
")",
";",
"bundleNode",
"&&",
"arch",
".",
"addParents",
"(",
"node",
",",
"bundleNode",
")",
";",
"magicNode",
"&&",
"arch",
".",
"addChildren",
"(",
"node",
",",
"magicNode",
")",
";",
"return",
"node",
";",
"}"
] | Create file node, add it to the arch, add dependencies to it.
@param {String} tech
@param {String} bundleNode
@param {String} magicNode
@return {Node | undefined} | [
"Create",
"file",
"node",
"add",
"it",
"to",
"the",
"arch",
"add",
"dependencies",
"to",
"it",
"."
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/nodes/bundle.js#L311-L330 | |
21,421 | bem-archive/bem-tools | lib/nodes/bundle.js | function(tech, bundleNode, magicNode) {
var ctx = this.ctx,
arch = ctx.arch,
levelNode = arch.getNode(PATH.relative(this.root, this.level.dir)),
depsTech = this.level.getTech('deps.js').getTechName(),
bundles = arch.getChildren(levelNode)
.filter(function(b) {
var n = arch.getNode(b);
return n instanceof exports.BundleNode && n !== this;
}, this)
.map(function(b) {
return U.getNodeTechPath(this.level, arch.getNode(b).item, depsTech);
}, this);
return this.setBemDeclNode(
tech,
this.level.resolveTech(tech),
bundleNode,
magicNode,
'merge',
bundles);
} | javascript | function(tech, bundleNode, magicNode) {
var ctx = this.ctx,
arch = ctx.arch,
levelNode = arch.getNode(PATH.relative(this.root, this.level.dir)),
depsTech = this.level.getTech('deps.js').getTechName(),
bundles = arch.getChildren(levelNode)
.filter(function(b) {
var n = arch.getNode(b);
return n instanceof exports.BundleNode && n !== this;
}, this)
.map(function(b) {
return U.getNodeTechPath(this.level, arch.getNode(b).item, depsTech);
}, this);
return this.setBemDeclNode(
tech,
this.level.resolveTech(tech),
bundleNode,
magicNode,
'merge',
bundles);
} | [
"function",
"(",
"tech",
",",
"bundleNode",
",",
"magicNode",
")",
"{",
"var",
"ctx",
"=",
"this",
".",
"ctx",
",",
"arch",
"=",
"ctx",
".",
"arch",
",",
"levelNode",
"=",
"arch",
".",
"getNode",
"(",
"PATH",
".",
"relative",
"(",
"this",
".",
"root",
",",
"this",
".",
"level",
".",
"dir",
")",
")",
",",
"depsTech",
"=",
"this",
".",
"level",
".",
"getTech",
"(",
"'deps.js'",
")",
".",
"getTechName",
"(",
")",
",",
"bundles",
"=",
"arch",
".",
"getChildren",
"(",
"levelNode",
")",
".",
"filter",
"(",
"function",
"(",
"b",
")",
"{",
"var",
"n",
"=",
"arch",
".",
"getNode",
"(",
"b",
")",
";",
"return",
"n",
"instanceof",
"exports",
".",
"BundleNode",
"&&",
"n",
"!==",
"this",
";",
"}",
",",
"this",
")",
".",
"map",
"(",
"function",
"(",
"b",
")",
"{",
"return",
"U",
".",
"getNodeTechPath",
"(",
"this",
".",
"level",
",",
"arch",
".",
"getNode",
"(",
"b",
")",
".",
"item",
",",
"depsTech",
")",
";",
"}",
",",
"this",
")",
";",
"return",
"this",
".",
"setBemDeclNode",
"(",
"tech",
",",
"this",
".",
"level",
".",
"resolveTech",
"(",
"tech",
")",
",",
"bundleNode",
",",
"magicNode",
",",
"'merge'",
",",
"bundles",
")",
";",
"}"
] | Overriden. Creates BemDecl node linked to the deps.js nodes of the bundles within containing level.
@param tech
@param bundleNode
@param magicNode
@return {*} | [
"Overriden",
".",
"Creates",
"BemDecl",
"node",
"linked",
"to",
"the",
"deps",
".",
"js",
"nodes",
"of",
"the",
"bundles",
"within",
"containing",
"level",
"."
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/nodes/bundle.js#L489-L512 | |
21,422 | bem-archive/bem-tools | lib/nodesregistry.js | function(nodeName, objectOrBaseName, objectOrStatic, staticObject) {
var explicitBase = typeof objectOrBaseName === 'string',
baseName = explicitBase? objectOrBaseName : nodeName,
staticObj = typeof objectOrBaseName !== 'string'? objectOrStatic: staticObject,
obj = explicitBase? objectOrStatic : objectOrBaseName,
base = baseName;
if (typeof baseName === 'string') {
base = baseName === nodeName? cache[baseName] : this.getNodeClass(baseName);
}
if (typeof objectOrStatic === 'function') {
cache[nodeName] = objectOrStatic;
} else {
cache[nodeName] = base? INHERIT(base, obj, staticObj) : INHERIT(obj, staticObj);
}
return cache;
} | javascript | function(nodeName, objectOrBaseName, objectOrStatic, staticObject) {
var explicitBase = typeof objectOrBaseName === 'string',
baseName = explicitBase? objectOrBaseName : nodeName,
staticObj = typeof objectOrBaseName !== 'string'? objectOrStatic: staticObject,
obj = explicitBase? objectOrStatic : objectOrBaseName,
base = baseName;
if (typeof baseName === 'string') {
base = baseName === nodeName? cache[baseName] : this.getNodeClass(baseName);
}
if (typeof objectOrStatic === 'function') {
cache[nodeName] = objectOrStatic;
} else {
cache[nodeName] = base? INHERIT(base, obj, staticObj) : INHERIT(obj, staticObj);
}
return cache;
} | [
"function",
"(",
"nodeName",
",",
"objectOrBaseName",
",",
"objectOrStatic",
",",
"staticObject",
")",
"{",
"var",
"explicitBase",
"=",
"typeof",
"objectOrBaseName",
"===",
"'string'",
",",
"baseName",
"=",
"explicitBase",
"?",
"objectOrBaseName",
":",
"nodeName",
",",
"staticObj",
"=",
"typeof",
"objectOrBaseName",
"!==",
"'string'",
"?",
"objectOrStatic",
":",
"staticObject",
",",
"obj",
"=",
"explicitBase",
"?",
"objectOrStatic",
":",
"objectOrBaseName",
",",
"base",
"=",
"baseName",
";",
"if",
"(",
"typeof",
"baseName",
"===",
"'string'",
")",
"{",
"base",
"=",
"baseName",
"===",
"nodeName",
"?",
"cache",
"[",
"baseName",
"]",
":",
"this",
".",
"getNodeClass",
"(",
"baseName",
")",
";",
"}",
"if",
"(",
"typeof",
"objectOrStatic",
"===",
"'function'",
")",
"{",
"cache",
"[",
"nodeName",
"]",
"=",
"objectOrStatic",
";",
"}",
"else",
"{",
"cache",
"[",
"nodeName",
"]",
"=",
"base",
"?",
"INHERIT",
"(",
"base",
",",
"obj",
",",
"staticObj",
")",
":",
"INHERIT",
"(",
"obj",
",",
"staticObj",
")",
";",
"}",
"return",
"cache",
";",
"}"
] | Calls INHERIT for specified parameters set and put the result into cache.
@param {String} nodeName Name of the node
@param {Object|String} objectOrBaseName Object definition or name of the class to inherit from
@param {Object|Object} objectOrStatic Object with static members definition|object definition
@param {Object} staticObject Object with static members definition
@return {Object} cache
@private | [
"Calls",
"INHERIT",
"for",
"specified",
"parameters",
"set",
"and",
"put",
"the",
"result",
"into",
"cache",
"."
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/nodesregistry.js#L22-L42 | |
21,423 | bem-archive/bem-tools | lib/nodesregistry.js | function(nodeName, objectOrBaseName, objectOrStatic, staticObject) {
cache = {};
var stack = registry[nodeName] || [];
stack.push(Array.prototype.slice.call(arguments, 0));
registry[nodeName] = stack;
} | javascript | function(nodeName, objectOrBaseName, objectOrStatic, staticObject) {
cache = {};
var stack = registry[nodeName] || [];
stack.push(Array.prototype.slice.call(arguments, 0));
registry[nodeName] = stack;
} | [
"function",
"(",
"nodeName",
",",
"objectOrBaseName",
",",
"objectOrStatic",
",",
"staticObject",
")",
"{",
"cache",
"=",
"{",
"}",
";",
"var",
"stack",
"=",
"registry",
"[",
"nodeName",
"]",
"||",
"[",
"]",
";",
"stack",
".",
"push",
"(",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"0",
")",
")",
";",
"registry",
"[",
"nodeName",
"]",
"=",
"stack",
";",
"}"
] | Stores specified arguments into registry for further processing with INHERIT.
@param {String} nodeName Name of the node
@param {Object|String} objectOrBaseName Object definition or name of the class to inherit from
@param {Object|Object} objectOrStatic Object with static members definition|object definition
@param {Object} staticObject Object with static members definition | [
"Stores",
"specified",
"arguments",
"into",
"registry",
"for",
"further",
"processing",
"with",
"INHERIT",
"."
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/nodesregistry.js#L66-L75 | |
21,424 | bem-archive/bem-tools | lib/data/d3.js | d3_format_group | function d3_format_group(value) {
var i = value.lastIndexOf("."),
f = i >= 0 ? value.substring(i) : (i = value.length, ""),
t = [];
while (i > 0) t.push(value.substring(i -= 3, i + 3));
return t.reverse().join(",") + f;
} | javascript | function d3_format_group(value) {
var i = value.lastIndexOf("."),
f = i >= 0 ? value.substring(i) : (i = value.length, ""),
t = [];
while (i > 0) t.push(value.substring(i -= 3, i + 3));
return t.reverse().join(",") + f;
} | [
"function",
"d3_format_group",
"(",
"value",
")",
"{",
"var",
"i",
"=",
"value",
".",
"lastIndexOf",
"(",
"\".\"",
")",
",",
"f",
"=",
"i",
">=",
"0",
"?",
"value",
".",
"substring",
"(",
"i",
")",
":",
"(",
"i",
"=",
"value",
".",
"length",
",",
"\"\"",
")",
",",
"t",
"=",
"[",
"]",
";",
"while",
"(",
"i",
">",
"0",
")",
"t",
".",
"push",
"(",
"value",
".",
"substring",
"(",
"i",
"-=",
"3",
",",
"i",
"+",
"3",
")",
")",
";",
"return",
"t",
".",
"reverse",
"(",
")",
".",
"join",
"(",
"\",\"",
")",
"+",
"f",
";",
"}"
] | Apply comma grouping for thousands. | [
"Apply",
"comma",
"grouping",
"for",
"thousands",
"."
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/data/d3.js#L712-L718 |
21,425 | bem-archive/bem-tools | lib/data/d3.js | l | function l(e) {
var o = d3.event; // Events can be reentrant (e.g., focus).
d3.event = e;
try {
listener.call(node, node.__data__, i);
} finally {
d3.event = o;
}
} | javascript | function l(e) {
var o = d3.event; // Events can be reentrant (e.g., focus).
d3.event = e;
try {
listener.call(node, node.__data__, i);
} finally {
d3.event = o;
}
} | [
"function",
"l",
"(",
"e",
")",
"{",
"var",
"o",
"=",
"d3",
".",
"event",
";",
"// Events can be reentrant (e.g., focus).",
"d3",
".",
"event",
"=",
"e",
";",
"try",
"{",
"listener",
".",
"call",
"(",
"node",
",",
"node",
".",
"__data__",
",",
"i",
")",
";",
"}",
"finally",
"{",
"d3",
".",
"event",
"=",
"o",
";",
"}",
"}"
] | wrapped event listener that preserves i | [
"wrapped",
"event",
"listener",
"that",
"preserves",
"i"
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/data/d3.js#L2001-L2009 |
21,426 | bem-archive/bem-tools | lib/data/d3.js | brush | function brush(g) {
g.each(function() {
var g = d3.select(this),
bg = g.selectAll(".background").data([0]),
fg = g.selectAll(".extent").data([0]),
tz = g.selectAll(".resize").data(resizes, String),
e;
// Prepare the brush container for events.
g
.style("pointer-events", "all")
.on("mousedown.brush", brushstart)
.on("touchstart.brush", brushstart);
// An invisible, mouseable area for starting a new brush.
bg.enter().append("rect")
.attr("class", "background")
.style("visibility", "hidden")
.style("cursor", "crosshair");
// The visible brush extent; style this as you like!
fg.enter().append("rect")
.attr("class", "extent")
.style("cursor", "move");
// More invisible rects for resizing the extent.
tz.enter().append("g")
.attr("class", function(d) { return "resize " + d; })
.style("cursor", function(d) { return d3_svg_brushCursor[d]; })
.append("rect")
.attr("x", function(d) { return /[ew]$/.test(d) ? -3 : null; })
.attr("y", function(d) { return /^[ns]/.test(d) ? -3 : null; })
.attr("width", 6)
.attr("height", 6)
.style("visibility", "hidden");
// Show or hide the resizers.
tz.style("display", brush.empty() ? "none" : null);
// Remove any superfluous resizers.
tz.exit().remove();
// Initialize the background to fill the defined range.
// If the range isn't defined, you can post-process.
if (x) {
e = d3_scaleRange(x);
bg.attr("x", e[0]).attr("width", e[1] - e[0]);
redrawX(g);
}
if (y) {
e = d3_scaleRange(y);
bg.attr("y", e[0]).attr("height", e[1] - e[0]);
redrawY(g);
}
redraw(g);
});
} | javascript | function brush(g) {
g.each(function() {
var g = d3.select(this),
bg = g.selectAll(".background").data([0]),
fg = g.selectAll(".extent").data([0]),
tz = g.selectAll(".resize").data(resizes, String),
e;
// Prepare the brush container for events.
g
.style("pointer-events", "all")
.on("mousedown.brush", brushstart)
.on("touchstart.brush", brushstart);
// An invisible, mouseable area for starting a new brush.
bg.enter().append("rect")
.attr("class", "background")
.style("visibility", "hidden")
.style("cursor", "crosshair");
// The visible brush extent; style this as you like!
fg.enter().append("rect")
.attr("class", "extent")
.style("cursor", "move");
// More invisible rects for resizing the extent.
tz.enter().append("g")
.attr("class", function(d) { return "resize " + d; })
.style("cursor", function(d) { return d3_svg_brushCursor[d]; })
.append("rect")
.attr("x", function(d) { return /[ew]$/.test(d) ? -3 : null; })
.attr("y", function(d) { return /^[ns]/.test(d) ? -3 : null; })
.attr("width", 6)
.attr("height", 6)
.style("visibility", "hidden");
// Show or hide the resizers.
tz.style("display", brush.empty() ? "none" : null);
// Remove any superfluous resizers.
tz.exit().remove();
// Initialize the background to fill the defined range.
// If the range isn't defined, you can post-process.
if (x) {
e = d3_scaleRange(x);
bg.attr("x", e[0]).attr("width", e[1] - e[0]);
redrawX(g);
}
if (y) {
e = d3_scaleRange(y);
bg.attr("y", e[0]).attr("height", e[1] - e[0]);
redrawY(g);
}
redraw(g);
});
} | [
"function",
"brush",
"(",
"g",
")",
"{",
"g",
".",
"each",
"(",
"function",
"(",
")",
"{",
"var",
"g",
"=",
"d3",
".",
"select",
"(",
"this",
")",
",",
"bg",
"=",
"g",
".",
"selectAll",
"(",
"\".background\"",
")",
".",
"data",
"(",
"[",
"0",
"]",
")",
",",
"fg",
"=",
"g",
".",
"selectAll",
"(",
"\".extent\"",
")",
".",
"data",
"(",
"[",
"0",
"]",
")",
",",
"tz",
"=",
"g",
".",
"selectAll",
"(",
"\".resize\"",
")",
".",
"data",
"(",
"resizes",
",",
"String",
")",
",",
"e",
";",
"// Prepare the brush container for events.",
"g",
".",
"style",
"(",
"\"pointer-events\"",
",",
"\"all\"",
")",
".",
"on",
"(",
"\"mousedown.brush\"",
",",
"brushstart",
")",
".",
"on",
"(",
"\"touchstart.brush\"",
",",
"brushstart",
")",
";",
"// An invisible, mouseable area for starting a new brush.",
"bg",
".",
"enter",
"(",
")",
".",
"append",
"(",
"\"rect\"",
")",
".",
"attr",
"(",
"\"class\"",
",",
"\"background\"",
")",
".",
"style",
"(",
"\"visibility\"",
",",
"\"hidden\"",
")",
".",
"style",
"(",
"\"cursor\"",
",",
"\"crosshair\"",
")",
";",
"// The visible brush extent; style this as you like!",
"fg",
".",
"enter",
"(",
")",
".",
"append",
"(",
"\"rect\"",
")",
".",
"attr",
"(",
"\"class\"",
",",
"\"extent\"",
")",
".",
"style",
"(",
"\"cursor\"",
",",
"\"move\"",
")",
";",
"// More invisible rects for resizing the extent.",
"tz",
".",
"enter",
"(",
")",
".",
"append",
"(",
"\"g\"",
")",
".",
"attr",
"(",
"\"class\"",
",",
"function",
"(",
"d",
")",
"{",
"return",
"\"resize \"",
"+",
"d",
";",
"}",
")",
".",
"style",
"(",
"\"cursor\"",
",",
"function",
"(",
"d",
")",
"{",
"return",
"d3_svg_brushCursor",
"[",
"d",
"]",
";",
"}",
")",
".",
"append",
"(",
"\"rect\"",
")",
".",
"attr",
"(",
"\"x\"",
",",
"function",
"(",
"d",
")",
"{",
"return",
"/",
"[ew]$",
"/",
".",
"test",
"(",
"d",
")",
"?",
"-",
"3",
":",
"null",
";",
"}",
")",
".",
"attr",
"(",
"\"y\"",
",",
"function",
"(",
"d",
")",
"{",
"return",
"/",
"^[ns]",
"/",
".",
"test",
"(",
"d",
")",
"?",
"-",
"3",
":",
"null",
";",
"}",
")",
".",
"attr",
"(",
"\"width\"",
",",
"6",
")",
".",
"attr",
"(",
"\"height\"",
",",
"6",
")",
".",
"style",
"(",
"\"visibility\"",
",",
"\"hidden\"",
")",
";",
"// Show or hide the resizers.",
"tz",
".",
"style",
"(",
"\"display\"",
",",
"brush",
".",
"empty",
"(",
")",
"?",
"\"none\"",
":",
"null",
")",
";",
"// Remove any superfluous resizers.",
"tz",
".",
"exit",
"(",
")",
".",
"remove",
"(",
")",
";",
"// Initialize the background to fill the defined range.",
"// If the range isn't defined, you can post-process.",
"if",
"(",
"x",
")",
"{",
"e",
"=",
"d3_scaleRange",
"(",
"x",
")",
";",
"bg",
".",
"attr",
"(",
"\"x\"",
",",
"e",
"[",
"0",
"]",
")",
".",
"attr",
"(",
"\"width\"",
",",
"e",
"[",
"1",
"]",
"-",
"e",
"[",
"0",
"]",
")",
";",
"redrawX",
"(",
"g",
")",
";",
"}",
"if",
"(",
"y",
")",
"{",
"e",
"=",
"d3_scaleRange",
"(",
"y",
")",
";",
"bg",
".",
"attr",
"(",
"\"y\"",
",",
"e",
"[",
"0",
"]",
")",
".",
"attr",
"(",
"\"height\"",
",",
"e",
"[",
"1",
"]",
"-",
"e",
"[",
"0",
"]",
")",
";",
"redrawY",
"(",
"g",
")",
";",
"}",
"redraw",
"(",
"g",
")",
";",
"}",
")",
";",
"}"
] | the extent in data space, lazily created | [
"the",
"extent",
"in",
"data",
"space",
"lazily",
"created"
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/data/d3.js#L4288-L4344 |
21,427 | bem-archive/bem-tools | lib/data/d3.js | recurse | function recurse(data, depth, nodes) {
var childs = children.call(hierarchy, data, depth),
node = d3_layout_hierarchyInline ? data : {data: data};
node.depth = depth;
nodes.push(node);
if (childs && (n = childs.length)) {
var i = -1,
n,
c = node.children = [],
v = 0,
j = depth + 1,
d;
while (++i < n) {
d = recurse(childs[i], j, nodes);
d.parent = node;
c.push(d);
v += d.value;
}
if (sort) c.sort(sort);
if (value) node.value = v;
} else if (value) {
node.value = +value.call(hierarchy, data, depth) || 0;
}
return node;
} | javascript | function recurse(data, depth, nodes) {
var childs = children.call(hierarchy, data, depth),
node = d3_layout_hierarchyInline ? data : {data: data};
node.depth = depth;
nodes.push(node);
if (childs && (n = childs.length)) {
var i = -1,
n,
c = node.children = [],
v = 0,
j = depth + 1,
d;
while (++i < n) {
d = recurse(childs[i], j, nodes);
d.parent = node;
c.push(d);
v += d.value;
}
if (sort) c.sort(sort);
if (value) node.value = v;
} else if (value) {
node.value = +value.call(hierarchy, data, depth) || 0;
}
return node;
} | [
"function",
"recurse",
"(",
"data",
",",
"depth",
",",
"nodes",
")",
"{",
"var",
"childs",
"=",
"children",
".",
"call",
"(",
"hierarchy",
",",
"data",
",",
"depth",
")",
",",
"node",
"=",
"d3_layout_hierarchyInline",
"?",
"data",
":",
"{",
"data",
":",
"data",
"}",
";",
"node",
".",
"depth",
"=",
"depth",
";",
"nodes",
".",
"push",
"(",
"node",
")",
";",
"if",
"(",
"childs",
"&&",
"(",
"n",
"=",
"childs",
".",
"length",
")",
")",
"{",
"var",
"i",
"=",
"-",
"1",
",",
"n",
",",
"c",
"=",
"node",
".",
"children",
"=",
"[",
"]",
",",
"v",
"=",
"0",
",",
"j",
"=",
"depth",
"+",
"1",
",",
"d",
";",
"while",
"(",
"++",
"i",
"<",
"n",
")",
"{",
"d",
"=",
"recurse",
"(",
"childs",
"[",
"i",
"]",
",",
"j",
",",
"nodes",
")",
";",
"d",
".",
"parent",
"=",
"node",
";",
"c",
".",
"push",
"(",
"d",
")",
";",
"v",
"+=",
"d",
".",
"value",
";",
"}",
"if",
"(",
"sort",
")",
"c",
".",
"sort",
"(",
"sort",
")",
";",
"if",
"(",
"value",
")",
"node",
".",
"value",
"=",
"v",
";",
"}",
"else",
"if",
"(",
"value",
")",
"{",
"node",
".",
"value",
"=",
"+",
"value",
".",
"call",
"(",
"hierarchy",
",",
"data",
",",
"depth",
")",
"||",
"0",
";",
"}",
"return",
"node",
";",
"}"
] | Recursively compute the node depth and value. Also converts the data representation into a standard hierarchy structure. | [
"Recursively",
"compute",
"the",
"node",
"depth",
"and",
"value",
".",
"Also",
"converts",
"the",
"data",
"representation",
"into",
"a",
"standard",
"hierarchy",
"structure",
"."
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/data/d3.js#L5979-L6003 |
21,428 | bem-archive/bem-tools | lib/data/d3.js | revalue | function revalue(node, depth) {
var children = node.children,
v = 0;
if (children && (n = children.length)) {
var i = -1,
n,
j = depth + 1;
while (++i < n) v += revalue(children[i], j);
} else if (value) {
v = +value.call(hierarchy, d3_layout_hierarchyInline ? node : node.data, depth) || 0;
}
if (value) node.value = v;
return v;
} | javascript | function revalue(node, depth) {
var children = node.children,
v = 0;
if (children && (n = children.length)) {
var i = -1,
n,
j = depth + 1;
while (++i < n) v += revalue(children[i], j);
} else if (value) {
v = +value.call(hierarchy, d3_layout_hierarchyInline ? node : node.data, depth) || 0;
}
if (value) node.value = v;
return v;
} | [
"function",
"revalue",
"(",
"node",
",",
"depth",
")",
"{",
"var",
"children",
"=",
"node",
".",
"children",
",",
"v",
"=",
"0",
";",
"if",
"(",
"children",
"&&",
"(",
"n",
"=",
"children",
".",
"length",
")",
")",
"{",
"var",
"i",
"=",
"-",
"1",
",",
"n",
",",
"j",
"=",
"depth",
"+",
"1",
";",
"while",
"(",
"++",
"i",
"<",
"n",
")",
"v",
"+=",
"revalue",
"(",
"children",
"[",
"i",
"]",
",",
"j",
")",
";",
"}",
"else",
"if",
"(",
"value",
")",
"{",
"v",
"=",
"+",
"value",
".",
"call",
"(",
"hierarchy",
",",
"d3_layout_hierarchyInline",
"?",
"node",
":",
"node",
".",
"data",
",",
"depth",
")",
"||",
"0",
";",
"}",
"if",
"(",
"value",
")",
"node",
".",
"value",
"=",
"v",
";",
"return",
"v",
";",
"}"
] | Recursively re-evaluates the node value. | [
"Recursively",
"re",
"-",
"evaluates",
"the",
"node",
"value",
"."
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/data/d3.js#L6006-L6019 |
21,429 | bem-archive/bem-tools | lib/data/d3.js | d3_layout_hierarchyRebind | function d3_layout_hierarchyRebind(object, hierarchy) {
d3.rebind(object, hierarchy, "sort", "children", "value");
// Add an alias for links, for convenience.
object.links = d3_layout_hierarchyLinks;
// If the new API is used, enabling inlining.
object.nodes = function(d) {
d3_layout_hierarchyInline = true;
return (object.nodes = object)(d);
};
return object;
} | javascript | function d3_layout_hierarchyRebind(object, hierarchy) {
d3.rebind(object, hierarchy, "sort", "children", "value");
// Add an alias for links, for convenience.
object.links = d3_layout_hierarchyLinks;
// If the new API is used, enabling inlining.
object.nodes = function(d) {
d3_layout_hierarchyInline = true;
return (object.nodes = object)(d);
};
return object;
} | [
"function",
"d3_layout_hierarchyRebind",
"(",
"object",
",",
"hierarchy",
")",
"{",
"d3",
".",
"rebind",
"(",
"object",
",",
"hierarchy",
",",
"\"sort\"",
",",
"\"children\"",
",",
"\"value\"",
")",
";",
"// Add an alias for links, for convenience.",
"object",
".",
"links",
"=",
"d3_layout_hierarchyLinks",
";",
"// If the new API is used, enabling inlining.",
"object",
".",
"nodes",
"=",
"function",
"(",
"d",
")",
"{",
"d3_layout_hierarchyInline",
"=",
"true",
";",
"return",
"(",
"object",
".",
"nodes",
"=",
"object",
")",
"(",
"d",
")",
";",
"}",
";",
"return",
"object",
";",
"}"
] | A method assignment helper for hierarchy subclasses. | [
"A",
"method",
"assignment",
"helper",
"for",
"hierarchy",
"subclasses",
"."
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/data/d3.js#L6055-L6068 |
21,430 | bem-archive/bem-tools | lib/data/d3.js | squarify | function squarify(node) {
var children = node.children;
if (children && children.length) {
var rect = pad(node),
row = [],
remaining = children.slice(), // copy-on-write
child,
best = Infinity, // the best row score so far
score, // the current row score
u = Math.min(rect.dx, rect.dy), // initial orientation
n;
scale(remaining, rect.dx * rect.dy / node.value);
row.area = 0;
while ((n = remaining.length) > 0) {
row.push(child = remaining[n - 1]);
row.area += child.area;
if ((score = worst(row, u)) <= best) { // continue with this orientation
remaining.pop();
best = score;
} else { // abort, and try a different orientation
row.area -= row.pop().area;
position(row, u, rect, false);
u = Math.min(rect.dx, rect.dy);
row.length = row.area = 0;
best = Infinity;
}
}
if (row.length) {
position(row, u, rect, true);
row.length = row.area = 0;
}
children.forEach(squarify);
}
} | javascript | function squarify(node) {
var children = node.children;
if (children && children.length) {
var rect = pad(node),
row = [],
remaining = children.slice(), // copy-on-write
child,
best = Infinity, // the best row score so far
score, // the current row score
u = Math.min(rect.dx, rect.dy), // initial orientation
n;
scale(remaining, rect.dx * rect.dy / node.value);
row.area = 0;
while ((n = remaining.length) > 0) {
row.push(child = remaining[n - 1]);
row.area += child.area;
if ((score = worst(row, u)) <= best) { // continue with this orientation
remaining.pop();
best = score;
} else { // abort, and try a different orientation
row.area -= row.pop().area;
position(row, u, rect, false);
u = Math.min(rect.dx, rect.dy);
row.length = row.area = 0;
best = Infinity;
}
}
if (row.length) {
position(row, u, rect, true);
row.length = row.area = 0;
}
children.forEach(squarify);
}
} | [
"function",
"squarify",
"(",
"node",
")",
"{",
"var",
"children",
"=",
"node",
".",
"children",
";",
"if",
"(",
"children",
"&&",
"children",
".",
"length",
")",
"{",
"var",
"rect",
"=",
"pad",
"(",
"node",
")",
",",
"row",
"=",
"[",
"]",
",",
"remaining",
"=",
"children",
".",
"slice",
"(",
")",
",",
"// copy-on-write",
"child",
",",
"best",
"=",
"Infinity",
",",
"// the best row score so far",
"score",
",",
"// the current row score",
"u",
"=",
"Math",
".",
"min",
"(",
"rect",
".",
"dx",
",",
"rect",
".",
"dy",
")",
",",
"// initial orientation",
"n",
";",
"scale",
"(",
"remaining",
",",
"rect",
".",
"dx",
"*",
"rect",
".",
"dy",
"/",
"node",
".",
"value",
")",
";",
"row",
".",
"area",
"=",
"0",
";",
"while",
"(",
"(",
"n",
"=",
"remaining",
".",
"length",
")",
">",
"0",
")",
"{",
"row",
".",
"push",
"(",
"child",
"=",
"remaining",
"[",
"n",
"-",
"1",
"]",
")",
";",
"row",
".",
"area",
"+=",
"child",
".",
"area",
";",
"if",
"(",
"(",
"score",
"=",
"worst",
"(",
"row",
",",
"u",
")",
")",
"<=",
"best",
")",
"{",
"// continue with this orientation",
"remaining",
".",
"pop",
"(",
")",
";",
"best",
"=",
"score",
";",
"}",
"else",
"{",
"// abort, and try a different orientation",
"row",
".",
"area",
"-=",
"row",
".",
"pop",
"(",
")",
".",
"area",
";",
"position",
"(",
"row",
",",
"u",
",",
"rect",
",",
"false",
")",
";",
"u",
"=",
"Math",
".",
"min",
"(",
"rect",
".",
"dx",
",",
"rect",
".",
"dy",
")",
";",
"row",
".",
"length",
"=",
"row",
".",
"area",
"=",
"0",
";",
"best",
"=",
"Infinity",
";",
"}",
"}",
"if",
"(",
"row",
".",
"length",
")",
"{",
"position",
"(",
"row",
",",
"u",
",",
"rect",
",",
"true",
")",
";",
"row",
".",
"length",
"=",
"row",
".",
"area",
"=",
"0",
";",
"}",
"children",
".",
"forEach",
"(",
"squarify",
")",
";",
"}",
"}"
] | Recursively arranges the specified node's children into squarified rows. | [
"Recursively",
"arranges",
"the",
"specified",
"node",
"s",
"children",
"into",
"squarified",
"rows",
"."
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/data/d3.js#L6629-L6662 |
21,431 | bem-archive/bem-tools | lib/data/d3.js | stickify | function stickify(node) {
var children = node.children;
if (children && children.length) {
var rect = pad(node),
remaining = children.slice(), // copy-on-write
child,
row = [];
scale(remaining, rect.dx * rect.dy / node.value);
row.area = 0;
while (child = remaining.pop()) {
row.push(child);
row.area += child.area;
if (child.z != null) {
position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length);
row.length = row.area = 0;
}
}
children.forEach(stickify);
}
} | javascript | function stickify(node) {
var children = node.children;
if (children && children.length) {
var rect = pad(node),
remaining = children.slice(), // copy-on-write
child,
row = [];
scale(remaining, rect.dx * rect.dy / node.value);
row.area = 0;
while (child = remaining.pop()) {
row.push(child);
row.area += child.area;
if (child.z != null) {
position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length);
row.length = row.area = 0;
}
}
children.forEach(stickify);
}
} | [
"function",
"stickify",
"(",
"node",
")",
"{",
"var",
"children",
"=",
"node",
".",
"children",
";",
"if",
"(",
"children",
"&&",
"children",
".",
"length",
")",
"{",
"var",
"rect",
"=",
"pad",
"(",
"node",
")",
",",
"remaining",
"=",
"children",
".",
"slice",
"(",
")",
",",
"// copy-on-write",
"child",
",",
"row",
"=",
"[",
"]",
";",
"scale",
"(",
"remaining",
",",
"rect",
".",
"dx",
"*",
"rect",
".",
"dy",
"/",
"node",
".",
"value",
")",
";",
"row",
".",
"area",
"=",
"0",
";",
"while",
"(",
"child",
"=",
"remaining",
".",
"pop",
"(",
")",
")",
"{",
"row",
".",
"push",
"(",
"child",
")",
";",
"row",
".",
"area",
"+=",
"child",
".",
"area",
";",
"if",
"(",
"child",
".",
"z",
"!=",
"null",
")",
"{",
"position",
"(",
"row",
",",
"child",
".",
"z",
"?",
"rect",
".",
"dx",
":",
"rect",
".",
"dy",
",",
"rect",
",",
"!",
"remaining",
".",
"length",
")",
";",
"row",
".",
"length",
"=",
"row",
".",
"area",
"=",
"0",
";",
"}",
"}",
"children",
".",
"forEach",
"(",
"stickify",
")",
";",
"}",
"}"
] | Recursively resizes the specified node's children into existing rows. Preserves the existing layout! | [
"Recursively",
"resizes",
"the",
"specified",
"node",
"s",
"children",
"into",
"existing",
"rows",
".",
"Preserves",
"the",
"existing",
"layout!"
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/data/d3.js#L6666-L6685 |
21,432 | bem-archive/bem-tools | lib/data/d3.js | token | function token() {
if (re.lastIndex >= text.length) return EOF; // special case: end of file
if (eol) { eol = false; return EOL; } // special case: end of line
// special case: quotes
var j = re.lastIndex;
if (text.charCodeAt(j) === 34) {
var i = j;
while (i++ < text.length) {
if (text.charCodeAt(i) === 34) {
if (text.charCodeAt(i + 1) !== 34) break;
i++;
}
}
re.lastIndex = i + 2;
var c = text.charCodeAt(i + 1);
if (c === 13) {
eol = true;
if (text.charCodeAt(i + 2) === 10) re.lastIndex++;
} else if (c === 10) {
eol = true;
}
return text.substring(j + 1, i).replace(/""/g, "\"");
}
// common case
var m = re.exec(text);
if (m) {
eol = m[0].charCodeAt(0) !== 44;
return text.substring(j, m.index);
}
re.lastIndex = text.length;
return text.substring(j);
} | javascript | function token() {
if (re.lastIndex >= text.length) return EOF; // special case: end of file
if (eol) { eol = false; return EOL; } // special case: end of line
// special case: quotes
var j = re.lastIndex;
if (text.charCodeAt(j) === 34) {
var i = j;
while (i++ < text.length) {
if (text.charCodeAt(i) === 34) {
if (text.charCodeAt(i + 1) !== 34) break;
i++;
}
}
re.lastIndex = i + 2;
var c = text.charCodeAt(i + 1);
if (c === 13) {
eol = true;
if (text.charCodeAt(i + 2) === 10) re.lastIndex++;
} else if (c === 10) {
eol = true;
}
return text.substring(j + 1, i).replace(/""/g, "\"");
}
// common case
var m = re.exec(text);
if (m) {
eol = m[0].charCodeAt(0) !== 44;
return text.substring(j, m.index);
}
re.lastIndex = text.length;
return text.substring(j);
} | [
"function",
"token",
"(",
")",
"{",
"if",
"(",
"re",
".",
"lastIndex",
">=",
"text",
".",
"length",
")",
"return",
"EOF",
";",
"// special case: end of file",
"if",
"(",
"eol",
")",
"{",
"eol",
"=",
"false",
";",
"return",
"EOL",
";",
"}",
"// special case: end of line",
"// special case: quotes",
"var",
"j",
"=",
"re",
".",
"lastIndex",
";",
"if",
"(",
"text",
".",
"charCodeAt",
"(",
"j",
")",
"===",
"34",
")",
"{",
"var",
"i",
"=",
"j",
";",
"while",
"(",
"i",
"++",
"<",
"text",
".",
"length",
")",
"{",
"if",
"(",
"text",
".",
"charCodeAt",
"(",
"i",
")",
"===",
"34",
")",
"{",
"if",
"(",
"text",
".",
"charCodeAt",
"(",
"i",
"+",
"1",
")",
"!==",
"34",
")",
"break",
";",
"i",
"++",
";",
"}",
"}",
"re",
".",
"lastIndex",
"=",
"i",
"+",
"2",
";",
"var",
"c",
"=",
"text",
".",
"charCodeAt",
"(",
"i",
"+",
"1",
")",
";",
"if",
"(",
"c",
"===",
"13",
")",
"{",
"eol",
"=",
"true",
";",
"if",
"(",
"text",
".",
"charCodeAt",
"(",
"i",
"+",
"2",
")",
"===",
"10",
")",
"re",
".",
"lastIndex",
"++",
";",
"}",
"else",
"if",
"(",
"c",
"===",
"10",
")",
"{",
"eol",
"=",
"true",
";",
"}",
"return",
"text",
".",
"substring",
"(",
"j",
"+",
"1",
",",
"i",
")",
".",
"replace",
"(",
"/",
"\"\"",
"/",
"g",
",",
"\"\\\"\"",
")",
";",
"}",
"// common case",
"var",
"m",
"=",
"re",
".",
"exec",
"(",
"text",
")",
";",
"if",
"(",
"m",
")",
"{",
"eol",
"=",
"m",
"[",
"0",
"]",
".",
"charCodeAt",
"(",
"0",
")",
"!==",
"44",
";",
"return",
"text",
".",
"substring",
"(",
"j",
",",
"m",
".",
"index",
")",
";",
"}",
"re",
".",
"lastIndex",
"=",
"text",
".",
"length",
";",
"return",
"text",
".",
"substring",
"(",
"j",
")",
";",
"}"
] | work-around bug in FF 3.6 @private Returns the next token. | [
"work",
"-",
"around",
"bug",
"in",
"FF",
"3",
".",
"6"
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/data/d3.js#L6852-L6885 |
21,433 | bem-archive/bem-tools | lib/data/d3.js | resample | function resample(coordinates) {
var i = 0,
n = coordinates.length,
j,
m,
resampled = n ? [coordinates[0]] : coordinates,
resamples,
origin = arc.source();
while (++i < n) {
resamples = arc.source(coordinates[i - 1])(coordinates[i]).coordinates;
for (j = 0, m = resamples.length; ++j < m;) resampled.push(resamples[j]);
}
arc.source(origin);
return resampled;
} | javascript | function resample(coordinates) {
var i = 0,
n = coordinates.length,
j,
m,
resampled = n ? [coordinates[0]] : coordinates,
resamples,
origin = arc.source();
while (++i < n) {
resamples = arc.source(coordinates[i - 1])(coordinates[i]).coordinates;
for (j = 0, m = resamples.length; ++j < m;) resampled.push(resamples[j]);
}
arc.source(origin);
return resampled;
} | [
"function",
"resample",
"(",
"coordinates",
")",
"{",
"var",
"i",
"=",
"0",
",",
"n",
"=",
"coordinates",
".",
"length",
",",
"j",
",",
"m",
",",
"resampled",
"=",
"n",
"?",
"[",
"coordinates",
"[",
"0",
"]",
"]",
":",
"coordinates",
",",
"resamples",
",",
"origin",
"=",
"arc",
".",
"source",
"(",
")",
";",
"while",
"(",
"++",
"i",
"<",
"n",
")",
"{",
"resamples",
"=",
"arc",
".",
"source",
"(",
"coordinates",
"[",
"i",
"-",
"1",
"]",
")",
"(",
"coordinates",
"[",
"i",
"]",
")",
".",
"coordinates",
";",
"for",
"(",
"j",
"=",
"0",
",",
"m",
"=",
"resamples",
".",
"length",
";",
"++",
"j",
"<",
"m",
";",
")",
"resampled",
".",
"push",
"(",
"resamples",
"[",
"j",
"]",
")",
";",
"}",
"arc",
".",
"source",
"(",
"origin",
")",
";",
"return",
"resampled",
";",
"}"
] | Resample coordinates, creating great arcs between each. | [
"Resample",
"coordinates",
"creating",
"great",
"arcs",
"between",
"each",
"."
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/data/d3.js#L7729-L7745 |
21,434 | bem-archive/bem-tools | lib/data/d3.js | d3_geom_hullCCW | function d3_geom_hullCCW(i1, i2, i3, v) {
var t, a, b, c, d, e, f;
t = v[i1]; a = t[0]; b = t[1];
t = v[i2]; c = t[0]; d = t[1];
t = v[i3]; e = t[0]; f = t[1];
return ((f-b)*(c-a) - (d-b)*(e-a)) > 0;
} | javascript | function d3_geom_hullCCW(i1, i2, i3, v) {
var t, a, b, c, d, e, f;
t = v[i1]; a = t[0]; b = t[1];
t = v[i2]; c = t[0]; d = t[1];
t = v[i3]; e = t[0]; f = t[1];
return ((f-b)*(c-a) - (d-b)*(e-a)) > 0;
} | [
"function",
"d3_geom_hullCCW",
"(",
"i1",
",",
"i2",
",",
"i3",
",",
"v",
")",
"{",
"var",
"t",
",",
"a",
",",
"b",
",",
"c",
",",
"d",
",",
"e",
",",
"f",
";",
"t",
"=",
"v",
"[",
"i1",
"]",
";",
"a",
"=",
"t",
"[",
"0",
"]",
";",
"b",
"=",
"t",
"[",
"1",
"]",
";",
"t",
"=",
"v",
"[",
"i2",
"]",
";",
"c",
"=",
"t",
"[",
"0",
"]",
";",
"d",
"=",
"t",
"[",
"1",
"]",
";",
"t",
"=",
"v",
"[",
"i3",
"]",
";",
"e",
"=",
"t",
"[",
"0",
"]",
";",
"f",
"=",
"t",
"[",
"1",
"]",
";",
"return",
"(",
"(",
"f",
"-",
"b",
")",
"*",
"(",
"c",
"-",
"a",
")",
"-",
"(",
"d",
"-",
"b",
")",
"*",
"(",
"e",
"-",
"a",
")",
")",
">",
"0",
";",
"}"
] | are three points in counter-clockwise order? | [
"are",
"three",
"points",
"in",
"counter",
"-",
"clockwise",
"order?"
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/data/d3.js#L8019-L8025 |
21,435 | bem-archive/bem-tools | lib/data/d3.js | d3_geom_polygonIntersect | function d3_geom_polygonIntersect(c, d, a, b) {
var x1 = c[0], x2 = d[0], x3 = a[0], x4 = b[0],
y1 = c[1], y2 = d[1], y3 = a[1], y4 = b[1],
x13 = x1 - x3,
x21 = x2 - x1,
x43 = x4 - x3,
y13 = y1 - y3,
y21 = y2 - y1,
y43 = y4 - y3,
ua = (x43 * y13 - y43 * x13) / (y43 * x21 - x43 * y21);
return [x1 + ua * x21, y1 + ua * y21];
} | javascript | function d3_geom_polygonIntersect(c, d, a, b) {
var x1 = c[0], x2 = d[0], x3 = a[0], x4 = b[0],
y1 = c[1], y2 = d[1], y3 = a[1], y4 = b[1],
x13 = x1 - x3,
x21 = x2 - x1,
x43 = x4 - x3,
y13 = y1 - y3,
y21 = y2 - y1,
y43 = y4 - y3,
ua = (x43 * y13 - y43 * x13) / (y43 * x21 - x43 * y21);
return [x1 + ua * x21, y1 + ua * y21];
} | [
"function",
"d3_geom_polygonIntersect",
"(",
"c",
",",
"d",
",",
"a",
",",
"b",
")",
"{",
"var",
"x1",
"=",
"c",
"[",
"0",
"]",
",",
"x2",
"=",
"d",
"[",
"0",
"]",
",",
"x3",
"=",
"a",
"[",
"0",
"]",
",",
"x4",
"=",
"b",
"[",
"0",
"]",
",",
"y1",
"=",
"c",
"[",
"1",
"]",
",",
"y2",
"=",
"d",
"[",
"1",
"]",
",",
"y3",
"=",
"a",
"[",
"1",
"]",
",",
"y4",
"=",
"b",
"[",
"1",
"]",
",",
"x13",
"=",
"x1",
"-",
"x3",
",",
"x21",
"=",
"x2",
"-",
"x1",
",",
"x43",
"=",
"x4",
"-",
"x3",
",",
"y13",
"=",
"y1",
"-",
"y3",
",",
"y21",
"=",
"y2",
"-",
"y1",
",",
"y43",
"=",
"y4",
"-",
"y3",
",",
"ua",
"=",
"(",
"x43",
"*",
"y13",
"-",
"y43",
"*",
"x13",
")",
"/",
"(",
"y43",
"*",
"x21",
"-",
"x43",
"*",
"y21",
")",
";",
"return",
"[",
"x1",
"+",
"ua",
"*",
"x21",
",",
"y1",
"+",
"ua",
"*",
"y21",
"]",
";",
"}"
] | Intersect two infinite lines cd and ab. | [
"Intersect",
"two",
"infinite",
"lines",
"cd",
"and",
"ab",
"."
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/data/d3.js#L8102-L8113 |
21,436 | bem-archive/bem-tools | lib/nodes/lib.js | function(o) {
this.__base(o);
this.root = o.root;
this.target = o.target;
this.npmPackages = o.npmPackages === undefined? ['package.json']: o.npmPackages;
} | javascript | function(o) {
this.__base(o);
this.root = o.root;
this.target = o.target;
this.npmPackages = o.npmPackages === undefined? ['package.json']: o.npmPackages;
} | [
"function",
"(",
"o",
")",
"{",
"this",
".",
"__base",
"(",
"o",
")",
";",
"this",
".",
"root",
"=",
"o",
".",
"root",
";",
"this",
".",
"target",
"=",
"o",
".",
"target",
";",
"this",
".",
"npmPackages",
"=",
"o",
".",
"npmPackages",
"===",
"undefined",
"?",
"[",
"'package.json'",
"]",
":",
"o",
".",
"npmPackages",
";",
"}"
] | LibraryNode instance constructor.
@class LibraryNode
@constructs
@param {Object} o Node options.
@param {String} o.root Project root path.
@param {String} o.target Library path. | [
"LibraryNode",
"instance",
"constructor",
"."
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/nodes/lib.js#L38-L43 | |
21,437 | bem-archive/bem-tools | lib/nodes/lib.js | function() {
var _this = this;
return QFS.statLink(this.getPath())
.fail(function() {
return false;
})
.then(function(stat) {
if (!stat) return;
/* jshint -W109 */
if (!stat.isSymbolicLink()) {
return Q.reject(UTIL.format("SymlinkLibraryNode: Path '%s' is exists and is not a symbolic link",
_this.getPath()));
}
/* jshint +W109 */
return QFS.remove(_this.getPath());
})
.then(function() {
var parent = PATH.dirname(_this.getPath());
return QFS.exists(parent)
.then(function(exists) {
/* jshint -W109 */
if(!exists) {
LOGGER.verbose("SymlinkLibraryNode: Creating parent directory for target '%s'",
_this.getPath());
return QFS.makeTree(parent);
}
/* jshint +W109 */
});
})
.then(function() {
return QFS.symbolicLink(_this.getPath(), _this.relative);
});
} | javascript | function() {
var _this = this;
return QFS.statLink(this.getPath())
.fail(function() {
return false;
})
.then(function(stat) {
if (!stat) return;
/* jshint -W109 */
if (!stat.isSymbolicLink()) {
return Q.reject(UTIL.format("SymlinkLibraryNode: Path '%s' is exists and is not a symbolic link",
_this.getPath()));
}
/* jshint +W109 */
return QFS.remove(_this.getPath());
})
.then(function() {
var parent = PATH.dirname(_this.getPath());
return QFS.exists(parent)
.then(function(exists) {
/* jshint -W109 */
if(!exists) {
LOGGER.verbose("SymlinkLibraryNode: Creating parent directory for target '%s'",
_this.getPath());
return QFS.makeTree(parent);
}
/* jshint +W109 */
});
})
.then(function() {
return QFS.symbolicLink(_this.getPath(), _this.relative);
});
} | [
"function",
"(",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"return",
"QFS",
".",
"statLink",
"(",
"this",
".",
"getPath",
"(",
")",
")",
".",
"fail",
"(",
"function",
"(",
")",
"{",
"return",
"false",
";",
"}",
")",
".",
"then",
"(",
"function",
"(",
"stat",
")",
"{",
"if",
"(",
"!",
"stat",
")",
"return",
";",
"/* jshint -W109 */",
"if",
"(",
"!",
"stat",
".",
"isSymbolicLink",
"(",
")",
")",
"{",
"return",
"Q",
".",
"reject",
"(",
"UTIL",
".",
"format",
"(",
"\"SymlinkLibraryNode: Path '%s' is exists and is not a symbolic link\"",
",",
"_this",
".",
"getPath",
"(",
")",
")",
")",
";",
"}",
"/* jshint +W109 */",
"return",
"QFS",
".",
"remove",
"(",
"_this",
".",
"getPath",
"(",
")",
")",
";",
"}",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"var",
"parent",
"=",
"PATH",
".",
"dirname",
"(",
"_this",
".",
"getPath",
"(",
")",
")",
";",
"return",
"QFS",
".",
"exists",
"(",
"parent",
")",
".",
"then",
"(",
"function",
"(",
"exists",
")",
"{",
"/* jshint -W109 */",
"if",
"(",
"!",
"exists",
")",
"{",
"LOGGER",
".",
"verbose",
"(",
"\"SymlinkLibraryNode: Creating parent directory for target '%s'\"",
",",
"_this",
".",
"getPath",
"(",
")",
")",
";",
"return",
"QFS",
".",
"makeTree",
"(",
"parent",
")",
";",
"}",
"/* jshint +W109 */",
"}",
")",
";",
"}",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"return",
"QFS",
".",
"symbolicLink",
"(",
"_this",
".",
"getPath",
"(",
")",
",",
"_this",
".",
"relative",
")",
";",
"}",
")",
";",
"}"
] | Make node.
@return {Promise * Undefined} | [
"Make",
"node",
"."
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/nodes/lib.js#L180-L222 | |
21,438 | bem-archive/bem-tools | lib/nodes/lib.js | function(o) {
this.__base(o);
this.url = o.url;
this.paths = [''];
this.timeout = typeof o.timeout !== 'undefined'? Number(o.timeout) : SCM_VALIDITY_TIMEOUT;
} | javascript | function(o) {
this.__base(o);
this.url = o.url;
this.paths = [''];
this.timeout = typeof o.timeout !== 'undefined'? Number(o.timeout) : SCM_VALIDITY_TIMEOUT;
} | [
"function",
"(",
"o",
")",
"{",
"this",
".",
"__base",
"(",
"o",
")",
";",
"this",
".",
"url",
"=",
"o",
".",
"url",
";",
"this",
".",
"paths",
"=",
"[",
"''",
"]",
";",
"this",
".",
"timeout",
"=",
"typeof",
"o",
".",
"timeout",
"!==",
"'undefined'",
"?",
"Number",
"(",
"o",
".",
"timeout",
")",
":",
"SCM_VALIDITY_TIMEOUT",
";",
"}"
] | ScmLibraryNode instance constructor.
@class ScmLibraryNode
@constructs
@param {Object} o Node options.
@param {String} o.root Project root path.
@param {String} o.target Library path.
@param {String} o.url Repository URL.
@param {String[]} [o.paths=['']] Paths to checkout. | [
"ScmLibraryNode",
"instance",
"constructor",
"."
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/nodes/lib.js#L247-L252 | |
21,439 | bem-archive/bem-tools | lib/nodes/lib.js | function(o) {
this.__base(o);
this.treeish = o.treeish;
this.branch = o.branch || 'master';
this.origin = o.origin || 'origin';
} | javascript | function(o) {
this.__base(o);
this.treeish = o.treeish;
this.branch = o.branch || 'master';
this.origin = o.origin || 'origin';
} | [
"function",
"(",
"o",
")",
"{",
"this",
".",
"__base",
"(",
"o",
")",
";",
"this",
".",
"treeish",
"=",
"o",
".",
"treeish",
";",
"this",
".",
"branch",
"=",
"o",
".",
"branch",
"||",
"'master'",
";",
"this",
".",
"origin",
"=",
"o",
".",
"origin",
"||",
"'origin'",
";",
"}"
] | GitLibraryNode instance constructor.
@class GitLibraryNode
@constructs
@param {Object} o Node options.
@param {String} o.root Project root path.
@param {String} o.target Library path.
@param {String} o.url Repository URL.
@param {String[]} [o.paths=['']] Paths to checkout.
@param {String} [o.treeish] Treeish (commit hash or tag) to checkout.
@param {String} [o.branch='master'] Branch to checkout.
@param {String} [o.origin='origin'] Remote name. | [
"GitLibraryNode",
"instance",
"constructor",
"."
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/nodes/lib.js#L366-L371 | |
21,440 | bem-archive/bem-tools | lib/nodes/lib.js | function(o) {
this.__base(o);
this.paths = Array.isArray(o.paths)? o.paths : [o.paths || ''];
this.revision = o.revision || 'HEAD';
} | javascript | function(o) {
this.__base(o);
this.paths = Array.isArray(o.paths)? o.paths : [o.paths || ''];
this.revision = o.revision || 'HEAD';
} | [
"function",
"(",
"o",
")",
"{",
"this",
".",
"__base",
"(",
"o",
")",
";",
"this",
".",
"paths",
"=",
"Array",
".",
"isArray",
"(",
"o",
".",
"paths",
")",
"?",
"o",
".",
"paths",
":",
"[",
"o",
".",
"paths",
"||",
"''",
"]",
";",
"this",
".",
"revision",
"=",
"o",
".",
"revision",
"||",
"'HEAD'",
";",
"}"
] | SvnLibraryNode instance constructor.
@class SvnLibraryNode
@constructs
@param {Object} o Node options.
@param {String} o.root Project root path.
@param {String} o.target Library path.
@param {String} o.url Repository URL.
@param {String[]} [o.paths=['']] Paths to checkout.
@param {String} [o.revision='HEAD'] Revision to checkout. | [
"SvnLibraryNode",
"instance",
"constructor",
"."
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/nodes/lib.js#L474-L478 | |
21,441 | bem-archive/bem-tools | lib/nodes/lib.js | function() {
var _this = this,
base = this.__base();
if (this.revision === 'HEAD') return base;
return Q.all(this.paths.map(function(path) {
return QFS.exists(PATH.resolve(_this.root, _this.target, path))
.then(function(exists) {
return exists && _this.getInfo(path)
.then(function(info) {
return String(info.revision) === String(_this.revision);
});
});
}))
.then(function(checks) {
return checks.reduce(function(cur, prev) {
return cur && prev;
}, true) || base;
});
} | javascript | function() {
var _this = this,
base = this.__base();
if (this.revision === 'HEAD') return base;
return Q.all(this.paths.map(function(path) {
return QFS.exists(PATH.resolve(_this.root, _this.target, path))
.then(function(exists) {
return exists && _this.getInfo(path)
.then(function(info) {
return String(info.revision) === String(_this.revision);
});
});
}))
.then(function(checks) {
return checks.reduce(function(cur, prev) {
return cur && prev;
}, true) || base;
});
} | [
"function",
"(",
")",
"{",
"var",
"_this",
"=",
"this",
",",
"base",
"=",
"this",
".",
"__base",
"(",
")",
";",
"if",
"(",
"this",
".",
"revision",
"===",
"'HEAD'",
")",
"return",
"base",
";",
"return",
"Q",
".",
"all",
"(",
"this",
".",
"paths",
".",
"map",
"(",
"function",
"(",
"path",
")",
"{",
"return",
"QFS",
".",
"exists",
"(",
"PATH",
".",
"resolve",
"(",
"_this",
".",
"root",
",",
"_this",
".",
"target",
",",
"path",
")",
")",
".",
"then",
"(",
"function",
"(",
"exists",
")",
"{",
"return",
"exists",
"&&",
"_this",
".",
"getInfo",
"(",
"path",
")",
".",
"then",
"(",
"function",
"(",
"info",
")",
"{",
"return",
"String",
"(",
"info",
".",
"revision",
")",
"===",
"String",
"(",
"_this",
".",
"revision",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
")",
".",
"then",
"(",
"function",
"(",
"checks",
")",
"{",
"return",
"checks",
".",
"reduce",
"(",
"function",
"(",
"cur",
",",
"prev",
")",
"{",
"return",
"cur",
"&&",
"prev",
";",
"}",
",",
"true",
")",
"||",
"base",
";",
"}",
")",
";",
"}"
] | Check validity of node.
Use output of `svn info` to check revision property.
If revision is the same as in config on all paths then
return promised true.
@return {Promise * Boolean} | [
"Check",
"validity",
"of",
"node",
"."
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/nodes/lib.js#L489-L514 | |
21,442 | bem-archive/bem-tools | lib/level.js | function(path, opts) {
opts = opts || {};
this.dir = PATH.resolve(path.path || path);
this.projectRoot = opts.projectRoot || PATH.resolve('');
// NOTE: keep this.path for backwards compatibility
this.path = this.bemDir = PATH.join(this.dir, '.bem');
path = PATH.relative(this.projectRoot, this.dir);
this.cache = useCache;
for(var e in exceptLevels) {
var except = exceptLevels[e];
if (path.substr(0, except.length) === except) {
this.cache = !this.cache;
break;
}
}
// NOTE: tech modules cache
this._techsCache = {};
} | javascript | function(path, opts) {
opts = opts || {};
this.dir = PATH.resolve(path.path || path);
this.projectRoot = opts.projectRoot || PATH.resolve('');
// NOTE: keep this.path for backwards compatibility
this.path = this.bemDir = PATH.join(this.dir, '.bem');
path = PATH.relative(this.projectRoot, this.dir);
this.cache = useCache;
for(var e in exceptLevels) {
var except = exceptLevels[e];
if (path.substr(0, except.length) === except) {
this.cache = !this.cache;
break;
}
}
// NOTE: tech modules cache
this._techsCache = {};
} | [
"function",
"(",
"path",
",",
"opts",
")",
"{",
"opts",
"=",
"opts",
"||",
"{",
"}",
";",
"this",
".",
"dir",
"=",
"PATH",
".",
"resolve",
"(",
"path",
".",
"path",
"||",
"path",
")",
";",
"this",
".",
"projectRoot",
"=",
"opts",
".",
"projectRoot",
"||",
"PATH",
".",
"resolve",
"(",
"''",
")",
";",
"// NOTE: keep this.path for backwards compatibility",
"this",
".",
"path",
"=",
"this",
".",
"bemDir",
"=",
"PATH",
".",
"join",
"(",
"this",
".",
"dir",
",",
"'.bem'",
")",
";",
"path",
"=",
"PATH",
".",
"relative",
"(",
"this",
".",
"projectRoot",
",",
"this",
".",
"dir",
")",
";",
"this",
".",
"cache",
"=",
"useCache",
";",
"for",
"(",
"var",
"e",
"in",
"exceptLevels",
")",
"{",
"var",
"except",
"=",
"exceptLevels",
"[",
"e",
"]",
";",
"if",
"(",
"path",
".",
"substr",
"(",
"0",
",",
"except",
".",
"length",
")",
"===",
"except",
")",
"{",
"this",
".",
"cache",
"=",
"!",
"this",
".",
"cache",
";",
"break",
";",
"}",
"}",
"// NOTE: tech modules cache",
"this",
".",
"_techsCache",
"=",
"{",
"}",
";",
"}"
] | Construct an instance of Level.
@class Level base class.
@constructs
@param {String | Object} path Level directory path.
@param {Object} [opts] Optional parameters | [
"Construct",
"an",
"instance",
"of",
"Level",
"."
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/level.js#L126-L146 | |
21,443 | bem-archive/bem-tools | lib/level.js | function(techIdent, opts) {
if (typeof opts === 'boolean') {
//legacy code used `force` second argument
opts = {force: opts};
}
opts = opts || {};
if(bemUtil.isPath(techIdent)) {
return this.resolveTechPath(techIdent);
}
if(!opts.force && this.getTechs().hasOwnProperty(techIdent)) {
return this.resolveTechName(techIdent);
}
return bemUtil.getBemTechPath(techIdent, opts);
} | javascript | function(techIdent, opts) {
if (typeof opts === 'boolean') {
//legacy code used `force` second argument
opts = {force: opts};
}
opts = opts || {};
if(bemUtil.isPath(techIdent)) {
return this.resolveTechPath(techIdent);
}
if(!opts.force && this.getTechs().hasOwnProperty(techIdent)) {
return this.resolveTechName(techIdent);
}
return bemUtil.getBemTechPath(techIdent, opts);
} | [
"function",
"(",
"techIdent",
",",
"opts",
")",
"{",
"if",
"(",
"typeof",
"opts",
"===",
"'boolean'",
")",
"{",
"//legacy code used `force` second argument",
"opts",
"=",
"{",
"force",
":",
"opts",
"}",
";",
"}",
"opts",
"=",
"opts",
"||",
"{",
"}",
";",
"if",
"(",
"bemUtil",
".",
"isPath",
"(",
"techIdent",
")",
")",
"{",
"return",
"this",
".",
"resolveTechPath",
"(",
"techIdent",
")",
";",
"}",
"if",
"(",
"!",
"opts",
".",
"force",
"&&",
"this",
".",
"getTechs",
"(",
")",
".",
"hasOwnProperty",
"(",
"techIdent",
")",
")",
"{",
"return",
"this",
".",
"resolveTechName",
"(",
"techIdent",
")",
";",
"}",
"return",
"bemUtil",
".",
"getBemTechPath",
"(",
"techIdent",
",",
"opts",
")",
";",
"}"
] | Resolve tech identifier into tech module path.
@param {String} techIdent Tech identifier.
@param {Object|Boolean} [opts] Options to use during resolution. If boolean value
is passed, it gets used as `options.force` for backward compatibility.
@param {Boolean} [opts.force=false] Flag to not use tech name resolution.
@param {Boolean} [opts.throwWhenUnresolved=false] Throw an error, if tech cannot be
resoled. If false, will return base tech instead of unresolved.
@param {Number} [version=1] Version of a tech to load, for bem-tools techs.
@return {String} Tech module path. | [
"Resolve",
"tech",
"identifier",
"into",
"tech",
"module",
"path",
"."
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/level.js#L221-L234 | |
21,444 | bem-archive/bem-tools | lib/level.js | function(techName) {
var p = this.getTechs()[techName];
return typeof p !== 'undefined'? this.resolveTech(p, {force: true}) : null;
} | javascript | function(techName) {
var p = this.getTechs()[techName];
return typeof p !== 'undefined'? this.resolveTech(p, {force: true}) : null;
} | [
"function",
"(",
"techName",
")",
"{",
"var",
"p",
"=",
"this",
".",
"getTechs",
"(",
")",
"[",
"techName",
"]",
";",
"return",
"typeof",
"p",
"!==",
"'undefined'",
"?",
"this",
".",
"resolveTech",
"(",
"p",
",",
"{",
"force",
":",
"true",
"}",
")",
":",
"null",
";",
"}"
] | Resolve tech name into tech module path.
@param {String} techName Tech name.
@return {String} Tech module path. | [
"Resolve",
"tech",
"name",
"into",
"tech",
"module",
"path",
"."
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/level.js#L242-L245 | |
21,445 | bem-archive/bem-tools | lib/level.js | function(techPath) {
// Get absolute path if path starts with "."
// NOTE: Can not replace check to !isAbsolute()
if(techPath.substring(0, 1) === '.') {
// Resolve relative path starting at level `.bem/` directory
techPath = PATH.join(this.bemDir, techPath);
/* jshint -W109 */
if(!isRequireable(techPath)) {
throw new Error("Tech module on path '" + techPath + "' not found");
}
/* jshint +W109 */
return techPath;
}
// Trying absolute of relative-without-dot path
if(isRequireable(techPath)) {
return techPath;
}
/* jshint -W109 */
try {
return require.resolve('./' + PATH.join('./techs', techPath));
} catch (err) {
throw new Error("Tech module with path '" + techPath + "' not found on require search paths");
}
/* jshint +W109 */
} | javascript | function(techPath) {
// Get absolute path if path starts with "."
// NOTE: Can not replace check to !isAbsolute()
if(techPath.substring(0, 1) === '.') {
// Resolve relative path starting at level `.bem/` directory
techPath = PATH.join(this.bemDir, techPath);
/* jshint -W109 */
if(!isRequireable(techPath)) {
throw new Error("Tech module on path '" + techPath + "' not found");
}
/* jshint +W109 */
return techPath;
}
// Trying absolute of relative-without-dot path
if(isRequireable(techPath)) {
return techPath;
}
/* jshint -W109 */
try {
return require.resolve('./' + PATH.join('./techs', techPath));
} catch (err) {
throw new Error("Tech module with path '" + techPath + "' not found on require search paths");
}
/* jshint +W109 */
} | [
"function",
"(",
"techPath",
")",
"{",
"// Get absolute path if path starts with \".\"",
"// NOTE: Can not replace check to !isAbsolute()",
"if",
"(",
"techPath",
".",
"substring",
"(",
"0",
",",
"1",
")",
"===",
"'.'",
")",
"{",
"// Resolve relative path starting at level `.bem/` directory",
"techPath",
"=",
"PATH",
".",
"join",
"(",
"this",
".",
"bemDir",
",",
"techPath",
")",
";",
"/* jshint -W109 */",
"if",
"(",
"!",
"isRequireable",
"(",
"techPath",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Tech module on path '\"",
"+",
"techPath",
"+",
"\"' not found\"",
")",
";",
"}",
"/* jshint +W109 */",
"return",
"techPath",
";",
"}",
"// Trying absolute of relative-without-dot path",
"if",
"(",
"isRequireable",
"(",
"techPath",
")",
")",
"{",
"return",
"techPath",
";",
"}",
"/* jshint -W109 */",
"try",
"{",
"return",
"require",
".",
"resolve",
"(",
"'./'",
"+",
"PATH",
".",
"join",
"(",
"'./techs'",
",",
"techPath",
")",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Tech module with path '\"",
"+",
"techPath",
"+",
"\"' not found on require search paths\"",
")",
";",
"}",
"/* jshint +W109 */",
"}"
] | Resolve tech module path.
@throws {Error} In case when tech module is not found.
@param {String} techPath Tech path (relative or absolute).
@return {String} Tech module path. | [
"Resolve",
"tech",
"module",
"path",
"."
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/level.js#L254-L283 | |
21,446 | bem-archive/bem-tools | lib/level.js | function(item) {
var getter, args;
if (item.block) {
getter = 'block';
args = [item.block];
if (item.elem) {
getter = 'elem';
args.push(item.elem);
}
if (item.mod) {
getter += '-mod';
args.push(item.mod);
if (item.val) {
getter += '-val';
args.push(item.val);
}
}
return this.getRel(getter, args);
}
return '';
} | javascript | function(item) {
var getter, args;
if (item.block) {
getter = 'block';
args = [item.block];
if (item.elem) {
getter = 'elem';
args.push(item.elem);
}
if (item.mod) {
getter += '-mod';
args.push(item.mod);
if (item.val) {
getter += '-val';
args.push(item.val);
}
}
return this.getRel(getter, args);
}
return '';
} | [
"function",
"(",
"item",
")",
"{",
"var",
"getter",
",",
"args",
";",
"if",
"(",
"item",
".",
"block",
")",
"{",
"getter",
"=",
"'block'",
";",
"args",
"=",
"[",
"item",
".",
"block",
"]",
";",
"if",
"(",
"item",
".",
"elem",
")",
"{",
"getter",
"=",
"'elem'",
";",
"args",
".",
"push",
"(",
"item",
".",
"elem",
")",
";",
"}",
"if",
"(",
"item",
".",
"mod",
")",
"{",
"getter",
"+=",
"'-mod'",
";",
"args",
".",
"push",
"(",
"item",
".",
"mod",
")",
";",
"if",
"(",
"item",
".",
"val",
")",
"{",
"getter",
"+=",
"'-val'",
";",
"args",
".",
"push",
"(",
"item",
".",
"val",
")",
";",
"}",
"}",
"return",
"this",
".",
"getRel",
"(",
"getter",
",",
"args",
")",
";",
"}",
"return",
"''",
";",
"}"
] | Get relative to level directory path prefix on the filesystem
to specified BEM entity described as an object with special
properties.
@param {Object} item BEM entity object.
@param {String} item.block Block name.
@param {String} item.elem Element name.
@param {String} item.mod Modifier name.
@param {String} item.val Modifier value.
@return {String} Relative path prefix. | [
"Get",
"relative",
"to",
"level",
"directory",
"path",
"prefix",
"on",
"the",
"filesystem",
"to",
"specified",
"BEM",
"entity",
"described",
"as",
"an",
"object",
"with",
"special",
"properties",
"."
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/level.js#L455-L475 | |
21,447 | bem-archive/bem-tools | lib/level.js | function(block, mod) {
return PATH.join.apply(null,
[block,
'_' + mod,
block + '_' + mod]);
} | javascript | function(block, mod) {
return PATH.join.apply(null,
[block,
'_' + mod,
block + '_' + mod]);
} | [
"function",
"(",
"block",
",",
"mod",
")",
"{",
"return",
"PATH",
".",
"join",
".",
"apply",
"(",
"null",
",",
"[",
"block",
",",
"'_'",
"+",
"mod",
",",
"block",
"+",
"'_'",
"+",
"mod",
"]",
")",
";",
"}"
] | Get relative path prefix for block modifier.
@param {String} block Block name.
@param {String} mod Modifier name.
@return {String} Path prefix. | [
"Get",
"relative",
"path",
"prefix",
"for",
"block",
"modifier",
"."
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/level.js#L519-L524 | |
21,448 | bem-archive/bem-tools | lib/level.js | function(path) {
if (PATH.isAbsolute(path)) path = PATH.relative(this.dir, path);
var matchTechs = this.matchTechsOrder().map(function(t) {
return this.getTech(t);
}, this);
return this.matchOrder().reduce(function(match, matcher) {
// Skip if already matched
if (match) return match;
// Try matcher
match = this.match(matcher, path);
// Skip if not matched
if (!match) return false;
// Try to match for tech
match.tech = matchTechs.reduce(function(tech, t) {
if (tech || !t.matchSuffix(match.suffix)) return tech;
return t.getTechName();
}, match.tech);
return match;
}.bind(this), false);
} | javascript | function(path) {
if (PATH.isAbsolute(path)) path = PATH.relative(this.dir, path);
var matchTechs = this.matchTechsOrder().map(function(t) {
return this.getTech(t);
}, this);
return this.matchOrder().reduce(function(match, matcher) {
// Skip if already matched
if (match) return match;
// Try matcher
match = this.match(matcher, path);
// Skip if not matched
if (!match) return false;
// Try to match for tech
match.tech = matchTechs.reduce(function(tech, t) {
if (tech || !t.matchSuffix(match.suffix)) return tech;
return t.getTechName();
}, match.tech);
return match;
}.bind(this), false);
} | [
"function",
"(",
"path",
")",
"{",
"if",
"(",
"PATH",
".",
"isAbsolute",
"(",
"path",
")",
")",
"path",
"=",
"PATH",
".",
"relative",
"(",
"this",
".",
"dir",
",",
"path",
")",
";",
"var",
"matchTechs",
"=",
"this",
".",
"matchTechsOrder",
"(",
")",
".",
"map",
"(",
"function",
"(",
"t",
")",
"{",
"return",
"this",
".",
"getTech",
"(",
"t",
")",
";",
"}",
",",
"this",
")",
";",
"return",
"this",
".",
"matchOrder",
"(",
")",
".",
"reduce",
"(",
"function",
"(",
"match",
",",
"matcher",
")",
"{",
"// Skip if already matched",
"if",
"(",
"match",
")",
"return",
"match",
";",
"// Try matcher",
"match",
"=",
"this",
".",
"match",
"(",
"matcher",
",",
"path",
")",
";",
"// Skip if not matched",
"if",
"(",
"!",
"match",
")",
"return",
"false",
";",
"// Try to match for tech",
"match",
".",
"tech",
"=",
"matchTechs",
".",
"reduce",
"(",
"function",
"(",
"tech",
",",
"t",
")",
"{",
"if",
"(",
"tech",
"||",
"!",
"t",
".",
"matchSuffix",
"(",
"match",
".",
"suffix",
")",
")",
"return",
"tech",
";",
"return",
"t",
".",
"getTechName",
"(",
")",
";",
"}",
",",
"match",
".",
"tech",
")",
";",
"return",
"match",
";",
"}",
".",
"bind",
"(",
"this",
")",
",",
"false",
")",
";",
"}"
] | Match path against all matchers and return first match.
Match object will contain `block`, `suffix` and `tech` fields
and can also contain any of the `elem`, `mod` and `val` fields
or all of them.
@param {String} path Path to match (absolute or relative).
@return {Boolean|Object} BEM entity object in case of positive match and false otherwise. | [
"Match",
"path",
"against",
"all",
"matchers",
"and",
"return",
"first",
"match",
"."
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/level.js#L628-L655 | |
21,449 | bem-archive/bem-tools | lib/level.js | function(blockName) {
// TODO: support any custom naming scheme, e.g. flat, when there are
// no directories for blocks
var decl = this.getDeclByIntrospection(PATH.dirname(this.get('block', [blockName])));
return decl.length? decl.shift() : {};
} | javascript | function(blockName) {
// TODO: support any custom naming scheme, e.g. flat, when there are
// no directories for blocks
var decl = this.getDeclByIntrospection(PATH.dirname(this.get('block', [blockName])));
return decl.length? decl.shift() : {};
} | [
"function",
"(",
"blockName",
")",
"{",
"// TODO: support any custom naming scheme, e.g. flat, when there are",
"// no directories for blocks",
"var",
"decl",
"=",
"this",
".",
"getDeclByIntrospection",
"(",
"PATH",
".",
"dirname",
"(",
"this",
".",
"get",
"(",
"'block'",
",",
"[",
"blockName",
"]",
")",
")",
")",
";",
"return",
"decl",
".",
"length",
"?",
"decl",
".",
"shift",
"(",
")",
":",
"{",
"}",
";",
"}"
] | Get declaration for block.
@param {String} blockName Block name to get declaration for.
@return {Object} Block declaration object. | [
"Get",
"declaration",
"for",
"block",
"."
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/level.js#L887-L892 | |
21,450 | bem-archive/bem-tools | lib/level.js | function(from) {
this._declIntrospector || (this._declIntrospector = this.createIntrospector({
creator: function(res, match) {
if (match && match.tech) {
return this._mergeMatchToDecl(match, res);
}
return res;
}
}));
return this._declIntrospector(from);
} | javascript | function(from) {
this._declIntrospector || (this._declIntrospector = this.createIntrospector({
creator: function(res, match) {
if (match && match.tech) {
return this._mergeMatchToDecl(match, res);
}
return res;
}
}));
return this._declIntrospector(from);
} | [
"function",
"(",
"from",
")",
"{",
"this",
".",
"_declIntrospector",
"||",
"(",
"this",
".",
"_declIntrospector",
"=",
"this",
".",
"createIntrospector",
"(",
"{",
"creator",
":",
"function",
"(",
"res",
",",
"match",
")",
"{",
"if",
"(",
"match",
"&&",
"match",
".",
"tech",
")",
"{",
"return",
"this",
".",
"_mergeMatchToDecl",
"(",
"match",
",",
"res",
")",
";",
"}",
"return",
"res",
";",
"}",
"}",
")",
")",
";",
"return",
"this",
".",
"_declIntrospector",
"(",
"from",
")",
";",
"}"
] | Get declaration of level directory or one of its subdirectories.
@param {String} [from] Relative path to subdirectory of level directory to start introspection from.
@return {Array} Array of declaration. | [
"Get",
"declaration",
"of",
"level",
"directory",
"or",
"one",
"of",
"its",
"subdirectories",
"."
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/level.js#L900-L914 | |
21,451 | bem-archive/bem-tools | lib/level.js | function(opts) {
var level = this;
if (!opts) opts = {
opts: false
};
// clone opts
opts = bemUtil.extend({}, opts);
// set default options
opts.from || (opts.from = '.');
// initial value initializer
opts.init || (opts.init = function() {
return [];
});
// paths filter function
opts.filter || (opts.filter = function(path) {
return !this.isIgnorablePath(path);
});
// matcher function
opts.matcher || (opts.matcher = function(path) {
return this.matchAny(path);
});
// result creator function
opts.creator || (opts.creator = function(res, match) {
if (match && match.tech) res.push(match);
return res;
});
/**
* Introspection function.
*
* @param {String} [from] Relative path to subdirectory of level directory to start introspection from.
* @param {*} [res] Initial introspection value to extend.
* @return {*}
*/
return function(from, res) {
if (opts.opts === false) {
level.scanFiles();
return level.files.blocks;
}
from = PATH.resolve(level.dir, from || opts.from);
res || (res = opts.init.call(level));
bemUtil.fsWalkTree(from, function(path) {
res = opts.creator.call(level, res, opts.matcher.call(level, path));
},
opts.filter,
level);
return res;
};
} | javascript | function(opts) {
var level = this;
if (!opts) opts = {
opts: false
};
// clone opts
opts = bemUtil.extend({}, opts);
// set default options
opts.from || (opts.from = '.');
// initial value initializer
opts.init || (opts.init = function() {
return [];
});
// paths filter function
opts.filter || (opts.filter = function(path) {
return !this.isIgnorablePath(path);
});
// matcher function
opts.matcher || (opts.matcher = function(path) {
return this.matchAny(path);
});
// result creator function
opts.creator || (opts.creator = function(res, match) {
if (match && match.tech) res.push(match);
return res;
});
/**
* Introspection function.
*
* @param {String} [from] Relative path to subdirectory of level directory to start introspection from.
* @param {*} [res] Initial introspection value to extend.
* @return {*}
*/
return function(from, res) {
if (opts.opts === false) {
level.scanFiles();
return level.files.blocks;
}
from = PATH.resolve(level.dir, from || opts.from);
res || (res = opts.init.call(level));
bemUtil.fsWalkTree(from, function(path) {
res = opts.creator.call(level, res, opts.matcher.call(level, path));
},
opts.filter,
level);
return res;
};
} | [
"function",
"(",
"opts",
")",
"{",
"var",
"level",
"=",
"this",
";",
"if",
"(",
"!",
"opts",
")",
"opts",
"=",
"{",
"opts",
":",
"false",
"}",
";",
"// clone opts",
"opts",
"=",
"bemUtil",
".",
"extend",
"(",
"{",
"}",
",",
"opts",
")",
";",
"// set default options",
"opts",
".",
"from",
"||",
"(",
"opts",
".",
"from",
"=",
"'.'",
")",
";",
"// initial value initializer",
"opts",
".",
"init",
"||",
"(",
"opts",
".",
"init",
"=",
"function",
"(",
")",
"{",
"return",
"[",
"]",
";",
"}",
")",
";",
"// paths filter function",
"opts",
".",
"filter",
"||",
"(",
"opts",
".",
"filter",
"=",
"function",
"(",
"path",
")",
"{",
"return",
"!",
"this",
".",
"isIgnorablePath",
"(",
"path",
")",
";",
"}",
")",
";",
"// matcher function",
"opts",
".",
"matcher",
"||",
"(",
"opts",
".",
"matcher",
"=",
"function",
"(",
"path",
")",
"{",
"return",
"this",
".",
"matchAny",
"(",
"path",
")",
";",
"}",
")",
";",
"// result creator function",
"opts",
".",
"creator",
"||",
"(",
"opts",
".",
"creator",
"=",
"function",
"(",
"res",
",",
"match",
")",
"{",
"if",
"(",
"match",
"&&",
"match",
".",
"tech",
")",
"res",
".",
"push",
"(",
"match",
")",
";",
"return",
"res",
";",
"}",
")",
";",
"/**\n * Introspection function.\n *\n * @param {String} [from] Relative path to subdirectory of level directory to start introspection from.\n * @param {*} [res] Initial introspection value to extend.\n * @return {*}\n */",
"return",
"function",
"(",
"from",
",",
"res",
")",
"{",
"if",
"(",
"opts",
".",
"opts",
"===",
"false",
")",
"{",
"level",
".",
"scanFiles",
"(",
")",
";",
"return",
"level",
".",
"files",
".",
"blocks",
";",
"}",
"from",
"=",
"PATH",
".",
"resolve",
"(",
"level",
".",
"dir",
",",
"from",
"||",
"opts",
".",
"from",
")",
";",
"res",
"||",
"(",
"res",
"=",
"opts",
".",
"init",
".",
"call",
"(",
"level",
")",
")",
";",
"bemUtil",
".",
"fsWalkTree",
"(",
"from",
",",
"function",
"(",
"path",
")",
"{",
"res",
"=",
"opts",
".",
"creator",
".",
"call",
"(",
"level",
",",
"res",
",",
"opts",
".",
"matcher",
".",
"call",
"(",
"level",
",",
"path",
")",
")",
";",
"}",
",",
"opts",
".",
"filter",
",",
"level",
")",
";",
"return",
"res",
";",
"}",
";",
"}"
] | Creates preconfigured introspection functions.
@param {Object} [opts] Introspector options.
@param {String} [opts.from] Relative path to subdirectory of level directory to start introspection from.
@param {Function} [opts.init] Function to return initial value of introspection.
@param {Function} [opts.filter] Function to filter paths to introspect, must return {Boolean}.
@param {Function} [opts.matcher] Function to perform match of paths, must return introspected value.
@param {Function} [opts.creator] Function to modify introspection object with matched value, must return new introspection.
@return {Function} Introspection function. | [
"Creates",
"preconfigured",
"introspection",
"functions",
"."
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/level.js#L1239-L1301 | |
21,452 | bem-archive/bem-tools | lib/techs/v2/project.js | function(path, opts) {
var bemDir = PATH.join(path, '.bem'),
levels = PATH.join(bemDir, 'levels'),
// .bem/levels/create blocks.js level prototype
blocks = this.createLevel({
forceTech: ['examples', 'tech-docs'],
outputDir: levels,
force: opts.force
}, ['blocks.js']),
// create .bem/levels/bundles.js level prototype
bundles = this.createLevel({
forceTech: ['bemjson.js', 'blocks'],
outputDir: levels,
force: opts.force
}, ['bundles.js']),
// create .bem/levels/examples.js level prototype
examples = bundles.then(function() {
return this.createLevel({
level: PATH.resolve(levels, 'bundles.js'),
outputDir: levels,
force: opts.force
}, ['examples.js']);
}.bind(this)),
// create .bem/levels/docs.js level prototype
docs = this.createLevel({
forceTech: ['md'],
outputDir: levels,
force: opts.force
}, ['docs.js']),
// create .bem/levels/tech-docs.js level prototype
techDocs = this.createLevel({
forceTech: ['docs', 'md'],
outputDir: levels,
force: opts.force,
level: 'simple'
}, ['tech-docs.js']),
// create .bem/techs and node_modules/ directories
dirs = Q.all([
U.mkdirp(PATH.join(bemDir, 'techs')),
U.mkdirp(PATH.join(path, 'node_modules'))
]),
// run `npm link bem` command
linkBem = U.exec('npm link bem', { cwd: path, env: process.env });
return Q.all([blocks, bundles, examples, docs, techDocs, dirs, linkBem])
.then(function() {});
} | javascript | function(path, opts) {
var bemDir = PATH.join(path, '.bem'),
levels = PATH.join(bemDir, 'levels'),
// .bem/levels/create blocks.js level prototype
blocks = this.createLevel({
forceTech: ['examples', 'tech-docs'],
outputDir: levels,
force: opts.force
}, ['blocks.js']),
// create .bem/levels/bundles.js level prototype
bundles = this.createLevel({
forceTech: ['bemjson.js', 'blocks'],
outputDir: levels,
force: opts.force
}, ['bundles.js']),
// create .bem/levels/examples.js level prototype
examples = bundles.then(function() {
return this.createLevel({
level: PATH.resolve(levels, 'bundles.js'),
outputDir: levels,
force: opts.force
}, ['examples.js']);
}.bind(this)),
// create .bem/levels/docs.js level prototype
docs = this.createLevel({
forceTech: ['md'],
outputDir: levels,
force: opts.force
}, ['docs.js']),
// create .bem/levels/tech-docs.js level prototype
techDocs = this.createLevel({
forceTech: ['docs', 'md'],
outputDir: levels,
force: opts.force,
level: 'simple'
}, ['tech-docs.js']),
// create .bem/techs and node_modules/ directories
dirs = Q.all([
U.mkdirp(PATH.join(bemDir, 'techs')),
U.mkdirp(PATH.join(path, 'node_modules'))
]),
// run `npm link bem` command
linkBem = U.exec('npm link bem', { cwd: path, env: process.env });
return Q.all([blocks, bundles, examples, docs, techDocs, dirs, linkBem])
.then(function() {});
} | [
"function",
"(",
"path",
",",
"opts",
")",
"{",
"var",
"bemDir",
"=",
"PATH",
".",
"join",
"(",
"path",
",",
"'.bem'",
")",
",",
"levels",
"=",
"PATH",
".",
"join",
"(",
"bemDir",
",",
"'levels'",
")",
",",
"// .bem/levels/create blocks.js level prototype",
"blocks",
"=",
"this",
".",
"createLevel",
"(",
"{",
"forceTech",
":",
"[",
"'examples'",
",",
"'tech-docs'",
"]",
",",
"outputDir",
":",
"levels",
",",
"force",
":",
"opts",
".",
"force",
"}",
",",
"[",
"'blocks.js'",
"]",
")",
",",
"// create .bem/levels/bundles.js level prototype",
"bundles",
"=",
"this",
".",
"createLevel",
"(",
"{",
"forceTech",
":",
"[",
"'bemjson.js'",
",",
"'blocks'",
"]",
",",
"outputDir",
":",
"levels",
",",
"force",
":",
"opts",
".",
"force",
"}",
",",
"[",
"'bundles.js'",
"]",
")",
",",
"// create .bem/levels/examples.js level prototype",
"examples",
"=",
"bundles",
".",
"then",
"(",
"function",
"(",
")",
"{",
"return",
"this",
".",
"createLevel",
"(",
"{",
"level",
":",
"PATH",
".",
"resolve",
"(",
"levels",
",",
"'bundles.js'",
")",
",",
"outputDir",
":",
"levels",
",",
"force",
":",
"opts",
".",
"force",
"}",
",",
"[",
"'examples.js'",
"]",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
")",
",",
"// create .bem/levels/docs.js level prototype",
"docs",
"=",
"this",
".",
"createLevel",
"(",
"{",
"forceTech",
":",
"[",
"'md'",
"]",
",",
"outputDir",
":",
"levels",
",",
"force",
":",
"opts",
".",
"force",
"}",
",",
"[",
"'docs.js'",
"]",
")",
",",
"// create .bem/levels/tech-docs.js level prototype",
"techDocs",
"=",
"this",
".",
"createLevel",
"(",
"{",
"forceTech",
":",
"[",
"'docs'",
",",
"'md'",
"]",
",",
"outputDir",
":",
"levels",
",",
"force",
":",
"opts",
".",
"force",
",",
"level",
":",
"'simple'",
"}",
",",
"[",
"'tech-docs.js'",
"]",
")",
",",
"// create .bem/techs and node_modules/ directories",
"dirs",
"=",
"Q",
".",
"all",
"(",
"[",
"U",
".",
"mkdirp",
"(",
"PATH",
".",
"join",
"(",
"bemDir",
",",
"'techs'",
")",
")",
",",
"U",
".",
"mkdirp",
"(",
"PATH",
".",
"join",
"(",
"path",
",",
"'node_modules'",
")",
")",
"]",
")",
",",
"// run `npm link bem` command",
"linkBem",
"=",
"U",
".",
"exec",
"(",
"'npm link bem'",
",",
"{",
"cwd",
":",
"path",
",",
"env",
":",
"process",
".",
"env",
"}",
")",
";",
"return",
"Q",
".",
"all",
"(",
"[",
"blocks",
",",
"bundles",
",",
"examples",
",",
"docs",
",",
"techDocs",
",",
"dirs",
",",
"linkBem",
"]",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"}",
")",
";",
"}"
] | Create the following project structure
.bem/
levels/
blocks.js
bundles.js
docs.js
examplex.js
tech-docs.js
techs/
level.js
node_modules/
@param {String} path Absolute path to the project directory
@param {Object} opts Options to the `bem create` command
@return {Promise * Undefined} | [
"Create",
"the",
"following",
"project",
"structure"
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/techs/v2/project.js#L45-L100 | |
21,453 | bem-archive/bem-tools | lib/nodes/build.js | function() {
return Q.all(this.tech
.getPaths(PATH.resolve(this.root, this.output), this.tech.getBuildSuffixes())
.map(function(path) {
return QFS.lastModified(path)
.fail(function() {
return -1;
});
}))
.spread(Math.min);
} | javascript | function() {
return Q.all(this.tech
.getPaths(PATH.resolve(this.root, this.output), this.tech.getBuildSuffixes())
.map(function(path) {
return QFS.lastModified(path)
.fail(function() {
return -1;
});
}))
.spread(Math.min);
} | [
"function",
"(",
")",
"{",
"return",
"Q",
".",
"all",
"(",
"this",
".",
"tech",
".",
"getPaths",
"(",
"PATH",
".",
"resolve",
"(",
"this",
".",
"root",
",",
"this",
".",
"output",
")",
",",
"this",
".",
"tech",
".",
"getBuildSuffixes",
"(",
")",
")",
".",
"map",
"(",
"function",
"(",
"path",
")",
"{",
"return",
"QFS",
".",
"lastModified",
"(",
"path",
")",
".",
"fail",
"(",
"function",
"(",
")",
"{",
"return",
"-",
"1",
";",
"}",
")",
";",
"}",
")",
")",
".",
"spread",
"(",
"Math",
".",
"min",
")",
";",
"}"
] | Get files minimum mtime in milliseconds or -1 in case of any file doesn't exist.
@return {Promise * Number} | [
"Get",
"files",
"minimum",
"mtime",
"in",
"milliseconds",
"or",
"-",
"1",
"in",
"case",
"of",
"any",
"file",
"doesn",
"t",
"exist",
"."
] | c3a167e86deb7c5e178c18244f3190dfda101f90 | https://github.com/bem-archive/bem-tools/blob/c3a167e86deb7c5e178c18244f3190dfda101f90/lib/nodes/build.js#L250-L264 | |
21,454 | nodeca/embedza | lib/domains/vimeo.com.js | vimeo_fetcher | async function vimeo_fetcher(env) {
tpl.query.url = env.src;
let response;
try {
response = await env.self.request(url.format(tpl));
} catch (err) {
if (err.statusCode) {
throw new EmbedzaError(
`Vimeo fetcher: Bad response code: ${err.statusCode}`,
'EHTTP',
err.statusCode);
}
throw err;
}
// that should not happen
/* istanbul ignore next */
if (response.statusCode !== 200) {
throw new EmbedzaError(
`Vimeo fetcher: Bad response code: ${response.statusCode}`,
'EHTTP',
response.statusCode);
}
try {
env.data.oembed = JSON.parse(response.body);
} catch (__) {
throw new EmbedzaError(
"Vimeo fetcher: Can't parse oembed JSON response",
'ECONTENT');
}
} | javascript | async function vimeo_fetcher(env) {
tpl.query.url = env.src;
let response;
try {
response = await env.self.request(url.format(tpl));
} catch (err) {
if (err.statusCode) {
throw new EmbedzaError(
`Vimeo fetcher: Bad response code: ${err.statusCode}`,
'EHTTP',
err.statusCode);
}
throw err;
}
// that should not happen
/* istanbul ignore next */
if (response.statusCode !== 200) {
throw new EmbedzaError(
`Vimeo fetcher: Bad response code: ${response.statusCode}`,
'EHTTP',
response.statusCode);
}
try {
env.data.oembed = JSON.parse(response.body);
} catch (__) {
throw new EmbedzaError(
"Vimeo fetcher: Can't parse oembed JSON response",
'ECONTENT');
}
} | [
"async",
"function",
"vimeo_fetcher",
"(",
"env",
")",
"{",
"tpl",
".",
"query",
".",
"url",
"=",
"env",
".",
"src",
";",
"let",
"response",
";",
"try",
"{",
"response",
"=",
"await",
"env",
".",
"self",
".",
"request",
"(",
"url",
".",
"format",
"(",
"tpl",
")",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"if",
"(",
"err",
".",
"statusCode",
")",
"{",
"throw",
"new",
"EmbedzaError",
"(",
"`",
"${",
"err",
".",
"statusCode",
"}",
"`",
",",
"'EHTTP'",
",",
"err",
".",
"statusCode",
")",
";",
"}",
"throw",
"err",
";",
"}",
"// that should not happen",
"/* istanbul ignore next */",
"if",
"(",
"response",
".",
"statusCode",
"!==",
"200",
")",
"{",
"throw",
"new",
"EmbedzaError",
"(",
"`",
"${",
"response",
".",
"statusCode",
"}",
"`",
",",
"'EHTTP'",
",",
"response",
".",
"statusCode",
")",
";",
"}",
"try",
"{",
"env",
".",
"data",
".",
"oembed",
"=",
"JSON",
".",
"parse",
"(",
"response",
".",
"body",
")",
";",
"}",
"catch",
"(",
"__",
")",
"{",
"throw",
"new",
"EmbedzaError",
"(",
"\"Vimeo fetcher: Can't parse oembed JSON response\"",
",",
"'ECONTENT'",
")",
";",
"}",
"}"
] | Add a custom fetcher that retrieves only oembed data using a hardcoded endpoint. The reason being that we have quite a lot of vimeo videos, and fetching html page for each of them triggers a temporary 1-day ip+user-agent ban with 429 status code. This way fetcher misses out on favicon and flashplayer urls, but this data is not necessary to generate embedded videos with the templates we have now. | [
"Add",
"a",
"custom",
"fetcher",
"that",
"retrieves",
"only",
"oembed",
"data",
"using",
"a",
"hardcoded",
"endpoint",
".",
"The",
"reason",
"being",
"that",
"we",
"have",
"quite",
"a",
"lot",
"of",
"vimeo",
"videos",
"and",
"fetching",
"html",
"page",
"for",
"each",
"of",
"them",
"triggers",
"a",
"temporary",
"1",
"-",
"day",
"ip",
"+",
"user",
"-",
"agent",
"ban",
"with",
"429",
"status",
"code",
".",
"This",
"way",
"fetcher",
"misses",
"out",
"on",
"favicon",
"and",
"flashplayer",
"urls",
"but",
"this",
"data",
"is",
"not",
"necessary",
"to",
"generate",
"embedded",
"videos",
"with",
"the",
"templates",
"we",
"have",
"now",
"."
] | e2b127cba4f655513cdc5254deef8ee125273da8 | https://github.com/nodeca/embedza/blob/e2b127cba4f655513cdc5254deef8ee125273da8/lib/domains/vimeo.com.js#L37-L70 |
21,455 | nodeca/embedza | lib/utils/index.js | findMeta | function findMeta(meta, names) {
if (!meta) return null;
if (!_.isArray(names)) names = [ names ];
let record;
names.some((name) => {
record = _.find(meta, (item) => item.name === name);
return record;
});
return (record || {}).value;
} | javascript | function findMeta(meta, names) {
if (!meta) return null;
if (!_.isArray(names)) names = [ names ];
let record;
names.some((name) => {
record = _.find(meta, (item) => item.name === name);
return record;
});
return (record || {}).value;
} | [
"function",
"findMeta",
"(",
"meta",
",",
"names",
")",
"{",
"if",
"(",
"!",
"meta",
")",
"return",
"null",
";",
"if",
"(",
"!",
"_",
".",
"isArray",
"(",
"names",
")",
")",
"names",
"=",
"[",
"names",
"]",
";",
"let",
"record",
";",
"names",
".",
"some",
"(",
"(",
"name",
")",
"=>",
"{",
"record",
"=",
"_",
".",
"find",
"(",
"meta",
",",
"(",
"item",
")",
"=>",
"item",
".",
"name",
"===",
"name",
")",
";",
"return",
"record",
";",
"}",
")",
";",
"return",
"(",
"record",
"||",
"{",
"}",
")",
".",
"value",
";",
"}"
] | Get meta value by list of names in priority order | [
"Get",
"meta",
"value",
"by",
"list",
"of",
"names",
"in",
"priority",
"order"
] | e2b127cba4f655513cdc5254deef8ee125273da8 | https://github.com/nodeca/embedza/blob/e2b127cba4f655513cdc5254deef8ee125273da8/lib/utils/index.js#L11-L24 |
21,456 | nodeca/embedza | lib/utils/index.js | wlCheck | function wlCheck(wl, record, value) {
if (!value) value = 'allow';
let wlItem = _.get(wl, record);
if (_.isArray(wlItem)) return wlItem.indexOf(value) !== -1;
return wlItem === value;
} | javascript | function wlCheck(wl, record, value) {
if (!value) value = 'allow';
let wlItem = _.get(wl, record);
if (_.isArray(wlItem)) return wlItem.indexOf(value) !== -1;
return wlItem === value;
} | [
"function",
"wlCheck",
"(",
"wl",
",",
"record",
",",
"value",
")",
"{",
"if",
"(",
"!",
"value",
")",
"value",
"=",
"'allow'",
";",
"let",
"wlItem",
"=",
"_",
".",
"get",
"(",
"wl",
",",
"record",
")",
";",
"if",
"(",
"_",
".",
"isArray",
"(",
"wlItem",
")",
")",
"return",
"wlItem",
".",
"indexOf",
"(",
"value",
")",
"!==",
"-",
"1",
";",
"return",
"wlItem",
"===",
"value",
";",
"}"
] | Check record allowed in whitelist | [
"Check",
"record",
"allowed",
"in",
"whitelist"
] | e2b127cba4f655513cdc5254deef8ee125273da8 | https://github.com/nodeca/embedza/blob/e2b127cba4f655513cdc5254deef8ee125273da8/lib/utils/index.js#L84-L92 |
21,457 | mozilla-jetpack/jpm | lib/rdf.js | createUpdateRDF | function createUpdateRDF(manifest) {
var header = [{
name: "RDF",
attrs: {
"xmlns": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"xmlns:em": "http://www.mozilla.org/2004/em-rdf#"
},
children: []
}];
var description = {
name: "Description",
attrs: {
"about": "urn:mozilla:extension:" + getID(manifest)
},
children: []
};
var enginesDescription = {
name: "Description",
children: []
};
var updateRdfTree = {
name: "em:updates",
children: [
{
name: "Seq",
children: [
{
name: "li",
children: []
}
]
}
]
};
var jetpackMeta = {
"em:version": manifest.version || "0.0.0"
};
enginesDescription.children.push(jetpackMeta);
var engines = Object.keys(manifest.engines || {});
// If engines defined, use them
if (engines.length) {
engines.forEach(function(engine) {
enginesDescription.children.push(createApplication(
engine, manifest.engines[engine]));
});
}
// Otherwise, assume default Firefox support
else {
enginesDescription.children.push(createApplication("Firefox"));
}
//we add the updateLink for each engine
enginesDescription.children.forEach(function(descriptionData, index) {
if (descriptionData.hasOwnProperty("em:targetApplication")) {
enginesDescription.children[index][Object.keys(descriptionData)].
Description["em:updateLink"] = manifest.updateLink;
}
});
updateRdfTree.children[0].children[0].children.push(enginesDescription);
description.children.push(updateRdfTree);
header[0].children.push(description);
var xml = jsontoxml(header, {
prettyPrint: true,
xmlHeader: true,
indent: " ",
escape: true
});
return xml;
} | javascript | function createUpdateRDF(manifest) {
var header = [{
name: "RDF",
attrs: {
"xmlns": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"xmlns:em": "http://www.mozilla.org/2004/em-rdf#"
},
children: []
}];
var description = {
name: "Description",
attrs: {
"about": "urn:mozilla:extension:" + getID(manifest)
},
children: []
};
var enginesDescription = {
name: "Description",
children: []
};
var updateRdfTree = {
name: "em:updates",
children: [
{
name: "Seq",
children: [
{
name: "li",
children: []
}
]
}
]
};
var jetpackMeta = {
"em:version": manifest.version || "0.0.0"
};
enginesDescription.children.push(jetpackMeta);
var engines = Object.keys(manifest.engines || {});
// If engines defined, use them
if (engines.length) {
engines.forEach(function(engine) {
enginesDescription.children.push(createApplication(
engine, manifest.engines[engine]));
});
}
// Otherwise, assume default Firefox support
else {
enginesDescription.children.push(createApplication("Firefox"));
}
//we add the updateLink for each engine
enginesDescription.children.forEach(function(descriptionData, index) {
if (descriptionData.hasOwnProperty("em:targetApplication")) {
enginesDescription.children[index][Object.keys(descriptionData)].
Description["em:updateLink"] = manifest.updateLink;
}
});
updateRdfTree.children[0].children[0].children.push(enginesDescription);
description.children.push(updateRdfTree);
header[0].children.push(description);
var xml = jsontoxml(header, {
prettyPrint: true,
xmlHeader: true,
indent: " ",
escape: true
});
return xml;
} | [
"function",
"createUpdateRDF",
"(",
"manifest",
")",
"{",
"var",
"header",
"=",
"[",
"{",
"name",
":",
"\"RDF\"",
",",
"attrs",
":",
"{",
"\"xmlns\"",
":",
"\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"",
",",
"\"xmlns:em\"",
":",
"\"http://www.mozilla.org/2004/em-rdf#\"",
"}",
",",
"children",
":",
"[",
"]",
"}",
"]",
";",
"var",
"description",
"=",
"{",
"name",
":",
"\"Description\"",
",",
"attrs",
":",
"{",
"\"about\"",
":",
"\"urn:mozilla:extension:\"",
"+",
"getID",
"(",
"manifest",
")",
"}",
",",
"children",
":",
"[",
"]",
"}",
";",
"var",
"enginesDescription",
"=",
"{",
"name",
":",
"\"Description\"",
",",
"children",
":",
"[",
"]",
"}",
";",
"var",
"updateRdfTree",
"=",
"{",
"name",
":",
"\"em:updates\"",
",",
"children",
":",
"[",
"{",
"name",
":",
"\"Seq\"",
",",
"children",
":",
"[",
"{",
"name",
":",
"\"li\"",
",",
"children",
":",
"[",
"]",
"}",
"]",
"}",
"]",
"}",
";",
"var",
"jetpackMeta",
"=",
"{",
"\"em:version\"",
":",
"manifest",
".",
"version",
"||",
"\"0.0.0\"",
"}",
";",
"enginesDescription",
".",
"children",
".",
"push",
"(",
"jetpackMeta",
")",
";",
"var",
"engines",
"=",
"Object",
".",
"keys",
"(",
"manifest",
".",
"engines",
"||",
"{",
"}",
")",
";",
"// If engines defined, use them",
"if",
"(",
"engines",
".",
"length",
")",
"{",
"engines",
".",
"forEach",
"(",
"function",
"(",
"engine",
")",
"{",
"enginesDescription",
".",
"children",
".",
"push",
"(",
"createApplication",
"(",
"engine",
",",
"manifest",
".",
"engines",
"[",
"engine",
"]",
")",
")",
";",
"}",
")",
";",
"}",
"// Otherwise, assume default Firefox support",
"else",
"{",
"enginesDescription",
".",
"children",
".",
"push",
"(",
"createApplication",
"(",
"\"Firefox\"",
")",
")",
";",
"}",
"//we add the updateLink for each engine",
"enginesDescription",
".",
"children",
".",
"forEach",
"(",
"function",
"(",
"descriptionData",
",",
"index",
")",
"{",
"if",
"(",
"descriptionData",
".",
"hasOwnProperty",
"(",
"\"em:targetApplication\"",
")",
")",
"{",
"enginesDescription",
".",
"children",
"[",
"index",
"]",
"[",
"Object",
".",
"keys",
"(",
"descriptionData",
")",
"]",
".",
"Description",
"[",
"\"em:updateLink\"",
"]",
"=",
"manifest",
".",
"updateLink",
";",
"}",
"}",
")",
";",
"updateRdfTree",
".",
"children",
"[",
"0",
"]",
".",
"children",
"[",
"0",
"]",
".",
"children",
".",
"push",
"(",
"enginesDescription",
")",
";",
"description",
".",
"children",
".",
"push",
"(",
"updateRdfTree",
")",
";",
"header",
"[",
"0",
"]",
".",
"children",
".",
"push",
"(",
"description",
")",
";",
"var",
"xml",
"=",
"jsontoxml",
"(",
"header",
",",
"{",
"prettyPrint",
":",
"true",
",",
"xmlHeader",
":",
"true",
",",
"indent",
":",
"\" \"",
",",
"escape",
":",
"true",
"}",
")",
";",
"return",
"xml",
";",
"}"
] | Creates an `update.rdf` file based off of an addon's `package.json`
object manifest. Returns a string of the composed RDF file.
@param {Object} manifest
@return {String} | [
"Creates",
"an",
"update",
".",
"rdf",
"file",
"based",
"off",
"of",
"an",
"addon",
"s",
"package",
".",
"json",
"object",
"manifest",
".",
"Returns",
"a",
"string",
"of",
"the",
"composed",
"RDF",
"file",
"."
] | 5e671fc7745fbf08b373557e40eac6cc74cc65d3 | https://github.com/mozilla-jetpack/jpm/blob/5e671fc7745fbf08b373557e40eac6cc74cc65d3/lib/rdf.js#L200-L272 |
21,458 | mozilla-jetpack/jpm | lib/zip.js | filter | function filter(options, includes, root, filepath, stat) {
var paths = path.relative(root, filepath).split(path.sep);
// always include test/tests directory when running jpm test
if (options.command === "test") {
if (/^tests?$/.test(paths[0])) {
if (paths.length === 1 && stat.isDirectory()) {
return true;
}
if (paths.length > 1) {
return true;
}
}
}
return includes.indexOf(filepath) !== -1;
} | javascript | function filter(options, includes, root, filepath, stat) {
var paths = path.relative(root, filepath).split(path.sep);
// always include test/tests directory when running jpm test
if (options.command === "test") {
if (/^tests?$/.test(paths[0])) {
if (paths.length === 1 && stat.isDirectory()) {
return true;
}
if (paths.length > 1) {
return true;
}
}
}
return includes.indexOf(filepath) !== -1;
} | [
"function",
"filter",
"(",
"options",
",",
"includes",
",",
"root",
",",
"filepath",
",",
"stat",
")",
"{",
"var",
"paths",
"=",
"path",
".",
"relative",
"(",
"root",
",",
"filepath",
")",
".",
"split",
"(",
"path",
".",
"sep",
")",
";",
"// always include test/tests directory when running jpm test",
"if",
"(",
"options",
".",
"command",
"===",
"\"test\"",
")",
"{",
"if",
"(",
"/",
"^tests?$",
"/",
".",
"test",
"(",
"paths",
"[",
"0",
"]",
")",
")",
"{",
"if",
"(",
"paths",
".",
"length",
"===",
"1",
"&&",
"stat",
".",
"isDirectory",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"paths",
".",
"length",
">",
"1",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"includes",
".",
"indexOf",
"(",
"filepath",
")",
"!==",
"-",
"1",
";",
"}"
] | Filter for deciding what is included in a xpi based on a list of included files | [
"Filter",
"for",
"deciding",
"what",
"is",
"included",
"in",
"a",
"xpi",
"based",
"on",
"a",
"list",
"of",
"included",
"files"
] | 5e671fc7745fbf08b373557e40eac6cc74cc65d3 | https://github.com/mozilla-jetpack/jpm/blob/5e671fc7745fbf08b373557e40eac6cc74cc65d3/lib/zip.js#L52-L66 |
21,459 | mozilla-jetpack/jpm | lib/ignore.js | ignore | function ignore(dir, options) {
var jpmignore = path.join(dir, ".jpmignore");
var defaultRules = ["*.zip", ".*", "test/", ".jpmignore", "*.xpi"];
return utils.getManifest({addonDir: options.addonDir})
.then(function(manifest) {
return fs.exists(jpmignore);
})
.then(function(exists) {
if (exists) {
if (options.verbose) {
console.log(".jpmignore found");
}
return fs.stat(jpmignore)
.then(function(stat) {
if (stat.isFile()) {
return fs.readFile(jpmignore)
.then(function(data) {
return data.toString().replace(/[\r\n]/, "\n").split("\n");
});
} else {
console.warn(
".jpmignore is not a file, fallback to use " +
"default filter rules");
return defaultRules;
}
});
} else {
if (options.verbose) {
console.warn(
".jpmignore does not exist, fallback to use default filter rules");
}
return defaultRules;
}
})
.then(function(lines) {
// Add "manifest.json" to always exclude it from the xpi (See
// https://github.com/mozilla-jetpack/jpm/pull/566 for rationale),
// but ensure the "webextension/manifest.json", that is used for the
// webextension embedded in an SDK hybrid add-on, is always included
// (See https://github.com/mozilla-jetpack/jpm/pull/578 for rationale).
lines = ["manifest.json", "!webextension/manifest.json"].concat(lines);
var rules = lines.filter(function(e) {
// exclude blank lines and comments
return !/^\s*(#|$)/.test(e);
});
// http://git-scm.com/docs/gitignore
// the last matching pattern decides the outcome
// reverse rules and break at first matched rule when filtering
return rules.reverse().map(function(rule) {
return new Minimatch(rule, {
matchBase: true,
dot: true,
flipNegate: true
});
});
})
.then(function(rules) {
return listdir(dir, rules, dir, true);
});
} | javascript | function ignore(dir, options) {
var jpmignore = path.join(dir, ".jpmignore");
var defaultRules = ["*.zip", ".*", "test/", ".jpmignore", "*.xpi"];
return utils.getManifest({addonDir: options.addonDir})
.then(function(manifest) {
return fs.exists(jpmignore);
})
.then(function(exists) {
if (exists) {
if (options.verbose) {
console.log(".jpmignore found");
}
return fs.stat(jpmignore)
.then(function(stat) {
if (stat.isFile()) {
return fs.readFile(jpmignore)
.then(function(data) {
return data.toString().replace(/[\r\n]/, "\n").split("\n");
});
} else {
console.warn(
".jpmignore is not a file, fallback to use " +
"default filter rules");
return defaultRules;
}
});
} else {
if (options.verbose) {
console.warn(
".jpmignore does not exist, fallback to use default filter rules");
}
return defaultRules;
}
})
.then(function(lines) {
// Add "manifest.json" to always exclude it from the xpi (See
// https://github.com/mozilla-jetpack/jpm/pull/566 for rationale),
// but ensure the "webextension/manifest.json", that is used for the
// webextension embedded in an SDK hybrid add-on, is always included
// (See https://github.com/mozilla-jetpack/jpm/pull/578 for rationale).
lines = ["manifest.json", "!webextension/manifest.json"].concat(lines);
var rules = lines.filter(function(e) {
// exclude blank lines and comments
return !/^\s*(#|$)/.test(e);
});
// http://git-scm.com/docs/gitignore
// the last matching pattern decides the outcome
// reverse rules and break at first matched rule when filtering
return rules.reverse().map(function(rule) {
return new Minimatch(rule, {
matchBase: true,
dot: true,
flipNegate: true
});
});
})
.then(function(rules) {
return listdir(dir, rules, dir, true);
});
} | [
"function",
"ignore",
"(",
"dir",
",",
"options",
")",
"{",
"var",
"jpmignore",
"=",
"path",
".",
"join",
"(",
"dir",
",",
"\".jpmignore\"",
")",
";",
"var",
"defaultRules",
"=",
"[",
"\"*.zip\"",
",",
"\".*\"",
",",
"\"test/\"",
",",
"\".jpmignore\"",
",",
"\"*.xpi\"",
"]",
";",
"return",
"utils",
".",
"getManifest",
"(",
"{",
"addonDir",
":",
"options",
".",
"addonDir",
"}",
")",
".",
"then",
"(",
"function",
"(",
"manifest",
")",
"{",
"return",
"fs",
".",
"exists",
"(",
"jpmignore",
")",
";",
"}",
")",
".",
"then",
"(",
"function",
"(",
"exists",
")",
"{",
"if",
"(",
"exists",
")",
"{",
"if",
"(",
"options",
".",
"verbose",
")",
"{",
"console",
".",
"log",
"(",
"\".jpmignore found\"",
")",
";",
"}",
"return",
"fs",
".",
"stat",
"(",
"jpmignore",
")",
".",
"then",
"(",
"function",
"(",
"stat",
")",
"{",
"if",
"(",
"stat",
".",
"isFile",
"(",
")",
")",
"{",
"return",
"fs",
".",
"readFile",
"(",
"jpmignore",
")",
".",
"then",
"(",
"function",
"(",
"data",
")",
"{",
"return",
"data",
".",
"toString",
"(",
")",
".",
"replace",
"(",
"/",
"[\\r\\n]",
"/",
",",
"\"\\n\"",
")",
".",
"split",
"(",
"\"\\n\"",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"console",
".",
"warn",
"(",
"\".jpmignore is not a file, fallback to use \"",
"+",
"\"default filter rules\"",
")",
";",
"return",
"defaultRules",
";",
"}",
"}",
")",
";",
"}",
"else",
"{",
"if",
"(",
"options",
".",
"verbose",
")",
"{",
"console",
".",
"warn",
"(",
"\".jpmignore does not exist, fallback to use default filter rules\"",
")",
";",
"}",
"return",
"defaultRules",
";",
"}",
"}",
")",
".",
"then",
"(",
"function",
"(",
"lines",
")",
"{",
"// Add \"manifest.json\" to always exclude it from the xpi (See",
"// https://github.com/mozilla-jetpack/jpm/pull/566 for rationale),",
"// but ensure the \"webextension/manifest.json\", that is used for the",
"// webextension embedded in an SDK hybrid add-on, is always included",
"// (See https://github.com/mozilla-jetpack/jpm/pull/578 for rationale).",
"lines",
"=",
"[",
"\"manifest.json\"",
",",
"\"!webextension/manifest.json\"",
"]",
".",
"concat",
"(",
"lines",
")",
";",
"var",
"rules",
"=",
"lines",
".",
"filter",
"(",
"function",
"(",
"e",
")",
"{",
"// exclude blank lines and comments",
"return",
"!",
"/",
"^\\s*(#|$)",
"/",
".",
"test",
"(",
"e",
")",
";",
"}",
")",
";",
"// http://git-scm.com/docs/gitignore",
"// the last matching pattern decides the outcome",
"// reverse rules and break at first matched rule when filtering",
"return",
"rules",
".",
"reverse",
"(",
")",
".",
"map",
"(",
"function",
"(",
"rule",
")",
"{",
"return",
"new",
"Minimatch",
"(",
"rule",
",",
"{",
"matchBase",
":",
"true",
",",
"dot",
":",
"true",
",",
"flipNegate",
":",
"true",
"}",
")",
";",
"}",
")",
";",
"}",
")",
".",
"then",
"(",
"function",
"(",
"rules",
")",
"{",
"return",
"listdir",
"(",
"dir",
",",
"rules",
",",
"dir",
",",
"true",
")",
";",
"}",
")",
";",
"}"
] | Look for .jpmignore in the given directory and use it to filter files
and sub-directories fallback to use default filter rules if .jpmignore
doesn't exist.
@param {String} dir
@param {Object} options
@return {Promise} | [
"Look",
"for",
".",
"jpmignore",
"in",
"the",
"given",
"directory",
"and",
"use",
"it",
"to",
"filter",
"files",
"and",
"sub",
"-",
"directories",
"fallback",
"to",
"use",
"default",
"filter",
"rules",
"if",
".",
"jpmignore",
"doesn",
"t",
"exist",
"."
] | 5e671fc7745fbf08b373557e40eac6cc74cc65d3 | https://github.com/mozilla-jetpack/jpm/blob/5e671fc7745fbf08b373557e40eac6cc74cc65d3/lib/ignore.js#L22-L83 |
21,460 | mozilla-jetpack/jpm | lib/ignore.js | listdir | function listdir(dir, rules, root, included) {
return fs.readdir(dir)
.then(function(files) {
return when.all(files.map(function(f) {
f = path.join(dir, f);
return when(fs.stat(f), function(stat) {
return {
path: f,
isDirectory: stat.isDirectory()
};
});
}));
})
.then(function(arr) {
var files = [];
var subdirs = [];
arr.forEach(function(e) {
if (e.isDirectory) {
subdirs.push(e.path);
} else {
files.push(e.path);
}
});
files = files.filter(function(f) {
return filter(f, rules, root, false, included);
});
return when.all(subdirs.map(function(d) {
return listdir(d, rules, root, filter(d, rules, root, true, included));
}))
.then(function(list) {
list = list.reduce(function(ret, i) {
return ret.concat(i);
}, files);
// include current dir only if at least one of its children is included
if (list.length > 0) {
list.push(dir);
}
return list;
});
});
} | javascript | function listdir(dir, rules, root, included) {
return fs.readdir(dir)
.then(function(files) {
return when.all(files.map(function(f) {
f = path.join(dir, f);
return when(fs.stat(f), function(stat) {
return {
path: f,
isDirectory: stat.isDirectory()
};
});
}));
})
.then(function(arr) {
var files = [];
var subdirs = [];
arr.forEach(function(e) {
if (e.isDirectory) {
subdirs.push(e.path);
} else {
files.push(e.path);
}
});
files = files.filter(function(f) {
return filter(f, rules, root, false, included);
});
return when.all(subdirs.map(function(d) {
return listdir(d, rules, root, filter(d, rules, root, true, included));
}))
.then(function(list) {
list = list.reduce(function(ret, i) {
return ret.concat(i);
}, files);
// include current dir only if at least one of its children is included
if (list.length > 0) {
list.push(dir);
}
return list;
});
});
} | [
"function",
"listdir",
"(",
"dir",
",",
"rules",
",",
"root",
",",
"included",
")",
"{",
"return",
"fs",
".",
"readdir",
"(",
"dir",
")",
".",
"then",
"(",
"function",
"(",
"files",
")",
"{",
"return",
"when",
".",
"all",
"(",
"files",
".",
"map",
"(",
"function",
"(",
"f",
")",
"{",
"f",
"=",
"path",
".",
"join",
"(",
"dir",
",",
"f",
")",
";",
"return",
"when",
"(",
"fs",
".",
"stat",
"(",
"f",
")",
",",
"function",
"(",
"stat",
")",
"{",
"return",
"{",
"path",
":",
"f",
",",
"isDirectory",
":",
"stat",
".",
"isDirectory",
"(",
")",
"}",
";",
"}",
")",
";",
"}",
")",
")",
";",
"}",
")",
".",
"then",
"(",
"function",
"(",
"arr",
")",
"{",
"var",
"files",
"=",
"[",
"]",
";",
"var",
"subdirs",
"=",
"[",
"]",
";",
"arr",
".",
"forEach",
"(",
"function",
"(",
"e",
")",
"{",
"if",
"(",
"e",
".",
"isDirectory",
")",
"{",
"subdirs",
".",
"push",
"(",
"e",
".",
"path",
")",
";",
"}",
"else",
"{",
"files",
".",
"push",
"(",
"e",
".",
"path",
")",
";",
"}",
"}",
")",
";",
"files",
"=",
"files",
".",
"filter",
"(",
"function",
"(",
"f",
")",
"{",
"return",
"filter",
"(",
"f",
",",
"rules",
",",
"root",
",",
"false",
",",
"included",
")",
";",
"}",
")",
";",
"return",
"when",
".",
"all",
"(",
"subdirs",
".",
"map",
"(",
"function",
"(",
"d",
")",
"{",
"return",
"listdir",
"(",
"d",
",",
"rules",
",",
"root",
",",
"filter",
"(",
"d",
",",
"rules",
",",
"root",
",",
"true",
",",
"included",
")",
")",
";",
"}",
")",
")",
".",
"then",
"(",
"function",
"(",
"list",
")",
"{",
"list",
"=",
"list",
".",
"reduce",
"(",
"function",
"(",
"ret",
",",
"i",
")",
"{",
"return",
"ret",
".",
"concat",
"(",
"i",
")",
";",
"}",
",",
"files",
")",
";",
"// include current dir only if at least one of its children is included",
"if",
"(",
"list",
".",
"length",
">",
"0",
")",
"{",
"list",
".",
"push",
"(",
"dir",
")",
";",
"}",
"return",
"list",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | filter a dir based on filter rules
@param {String} dir
@param {Array} rules
@param {Array} root
@param {Boolean} included
@return {Promise} | [
"filter",
"a",
"dir",
"based",
"on",
"filter",
"rules"
] | 5e671fc7745fbf08b373557e40eac6cc74cc65d3 | https://github.com/mozilla-jetpack/jpm/blob/5e671fc7745fbf08b373557e40eac6cc74cc65d3/lib/ignore.js#L95-L135 |
21,461 | mozilla-jetpack/jpm | lib/ignore.js | filter | function filter(p, rules, root, isDirectory, included) {
p = path.relative(root, p);
for (var i in rules) {
var rule = rules[i];
if (isDirectory) {
if (rule.match(p) || rule.match("/" + p) ||
rule.match(p + "/") || rule.match("/" + p + "/")
) {
return rule.negate;
}
} else {
if (rule.match(p) || rule.match("/" + p)) {
return rule.negate;
}
}
}
return included;
} | javascript | function filter(p, rules, root, isDirectory, included) {
p = path.relative(root, p);
for (var i in rules) {
var rule = rules[i];
if (isDirectory) {
if (rule.match(p) || rule.match("/" + p) ||
rule.match(p + "/") || rule.match("/" + p + "/")
) {
return rule.negate;
}
} else {
if (rule.match(p) || rule.match("/" + p)) {
return rule.negate;
}
}
}
return included;
} | [
"function",
"filter",
"(",
"p",
",",
"rules",
",",
"root",
",",
"isDirectory",
",",
"included",
")",
"{",
"p",
"=",
"path",
".",
"relative",
"(",
"root",
",",
"p",
")",
";",
"for",
"(",
"var",
"i",
"in",
"rules",
")",
"{",
"var",
"rule",
"=",
"rules",
"[",
"i",
"]",
";",
"if",
"(",
"isDirectory",
")",
"{",
"if",
"(",
"rule",
".",
"match",
"(",
"p",
")",
"||",
"rule",
".",
"match",
"(",
"\"/\"",
"+",
"p",
")",
"||",
"rule",
".",
"match",
"(",
"p",
"+",
"\"/\"",
")",
"||",
"rule",
".",
"match",
"(",
"\"/\"",
"+",
"p",
"+",
"\"/\"",
")",
")",
"{",
"return",
"rule",
".",
"negate",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"rule",
".",
"match",
"(",
"p",
")",
"||",
"rule",
".",
"match",
"(",
"\"/\"",
"+",
"p",
")",
")",
"{",
"return",
"rule",
".",
"negate",
";",
"}",
"}",
"}",
"return",
"included",
";",
"}"
] | check if a given file or dir should be kept
@param {String} p
@param {Array} rules
@param {String} root
@param {Boolean} isDirectory
@param {Boolean} included
@return {Boolean} | [
"check",
"if",
"a",
"given",
"file",
"or",
"dir",
"should",
"be",
"kept"
] | 5e671fc7745fbf08b373557e40eac6cc74cc65d3 | https://github.com/mozilla-jetpack/jpm/blob/5e671fc7745fbf08b373557e40eac6cc74cc65d3/lib/ignore.js#L147-L164 |
21,462 | mozilla-jetpack/jpm | lib/utils.js | log | function log(type) {
var messages = Array.prototype.slice.call(arguments);
messages.shift();
// Concatenate default strings and first message argument into
// one string so we can use `printf`-like replacement
var first = "JPM [" + type + "] " + (messages.shift() + "");
if (process.env.NODE_ENV !== "test") {
console.log.apply(console, [first].concat(messages)); // eslint-disable-line no-console
}
} | javascript | function log(type) {
var messages = Array.prototype.slice.call(arguments);
messages.shift();
// Concatenate default strings and first message argument into
// one string so we can use `printf`-like replacement
var first = "JPM [" + type + "] " + (messages.shift() + "");
if (process.env.NODE_ENV !== "test") {
console.log.apply(console, [first].concat(messages)); // eslint-disable-line no-console
}
} | [
"function",
"log",
"(",
"type",
")",
"{",
"var",
"messages",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
";",
"messages",
".",
"shift",
"(",
")",
";",
"// Concatenate default strings and first message argument into",
"// one string so we can use `printf`-like replacement",
"var",
"first",
"=",
"\"JPM [\"",
"+",
"type",
"+",
"\"] \"",
"+",
"(",
"messages",
".",
"shift",
"(",
")",
"+",
"\"\"",
")",
";",
"if",
"(",
"process",
".",
"env",
".",
"NODE_ENV",
"!==",
"\"test\"",
")",
"{",
"console",
".",
"log",
".",
"apply",
"(",
"console",
",",
"[",
"first",
"]",
".",
"concat",
"(",
"messages",
")",
")",
";",
"// eslint-disable-line no-console",
"}",
"}"
] | Exports a `console` object that has several methods
similar to a traditional console like `log`, `warn`, `error`,
and `verbose`, which feed through a simple logging messenger.
@param {String} type
@param {String} messages... | [
"Exports",
"a",
"console",
"object",
"that",
"has",
"several",
"methods",
"similar",
"to",
"a",
"traditional",
"console",
"like",
"log",
"warn",
"error",
"and",
"verbose",
"which",
"feed",
"through",
"a",
"simple",
"logging",
"messenger",
"."
] | 5e671fc7745fbf08b373557e40eac6cc74cc65d3 | https://github.com/mozilla-jetpack/jpm/blob/5e671fc7745fbf08b373557e40eac6cc74cc65d3/lib/utils.js#L24-L34 |
21,463 | mozilla-jetpack/jpm | lib/utils.js | getManifest | function getManifest(options) {
options = _.assign({
addonDir: process.cwd(),
xpiPath: null
}, options);
return when.promise(function(resolve, reject) {
if (options.xpiPath) {
return getXpiInfo(options.xpiPath)
.then(function(xpiInfo) {
resolve(xpiInfo.manifest);
})
.catch(reject);
} else {
var json = path.join(options.addonDir, "package.json");
var manifest = {};
try {
manifest = require(json);
} catch (e) {} // eslint-disable-line no-empty
return resolve(manifest);
}
});
} | javascript | function getManifest(options) {
options = _.assign({
addonDir: process.cwd(),
xpiPath: null
}, options);
return when.promise(function(resolve, reject) {
if (options.xpiPath) {
return getXpiInfo(options.xpiPath)
.then(function(xpiInfo) {
resolve(xpiInfo.manifest);
})
.catch(reject);
} else {
var json = path.join(options.addonDir, "package.json");
var manifest = {};
try {
manifest = require(json);
} catch (e) {} // eslint-disable-line no-empty
return resolve(manifest);
}
});
} | [
"function",
"getManifest",
"(",
"options",
")",
"{",
"options",
"=",
"_",
".",
"assign",
"(",
"{",
"addonDir",
":",
"process",
".",
"cwd",
"(",
")",
",",
"xpiPath",
":",
"null",
"}",
",",
"options",
")",
";",
"return",
"when",
".",
"promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"if",
"(",
"options",
".",
"xpiPath",
")",
"{",
"return",
"getXpiInfo",
"(",
"options",
".",
"xpiPath",
")",
".",
"then",
"(",
"function",
"(",
"xpiInfo",
")",
"{",
"resolve",
"(",
"xpiInfo",
".",
"manifest",
")",
";",
"}",
")",
".",
"catch",
"(",
"reject",
")",
";",
"}",
"else",
"{",
"var",
"json",
"=",
"path",
".",
"join",
"(",
"options",
".",
"addonDir",
",",
"\"package.json\"",
")",
";",
"var",
"manifest",
"=",
"{",
"}",
";",
"try",
"{",
"manifest",
"=",
"require",
"(",
"json",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"}",
"// eslint-disable-line no-empty",
"return",
"resolve",
"(",
"manifest",
")",
";",
"}",
"}",
")",
";",
"}"
] | Returns the `package.json` manifest as an object
from the `cwd`, or `null` if not found.
If you pass in an optional XPI filename, the manifest will be returned
from this directory after a temporary XPI extraction.
@param {Object} options
- `addonDir` directory of the add-on source code, defaulting
to the working directory.
- `xpiPath` a path to an XPI file where the manifest resides.
Without this, the current working directory is assumed.
@return {Promise} resolves to a manifest object | [
"Returns",
"the",
"package",
".",
"json",
"manifest",
"as",
"an",
"object",
"from",
"the",
"cwd",
"or",
"null",
"if",
"not",
"found",
".",
"If",
"you",
"pass",
"in",
"an",
"optional",
"XPI",
"filename",
"the",
"manifest",
"will",
"be",
"returned",
"from",
"this",
"directory",
"after",
"a",
"temporary",
"XPI",
"extraction",
"."
] | 5e671fc7745fbf08b373557e40eac6cc74cc65d3 | https://github.com/mozilla-jetpack/jpm/blob/5e671fc7745fbf08b373557e40eac6cc74cc65d3/lib/utils.js#L59-L81 |
21,464 | mozilla-jetpack/jpm | lib/utils.js | getXpiInfo | function getXpiInfo(xpiPath) {
return extractXPI(xpiPath)
.then(function(tmpXPI) {
var getInfo;
var packageFile = path.join(tmpXPI.path, "package.json");
var installRdfFile = path.join(tmpXPI.path, "install.rdf");
if (fileExists(packageFile)) {
getInfo = getXpiInfoFromManifest(require(packageFile));
} else if (fileExists(installRdfFile)) {
getInfo = nodefn.call(fs.readFile, installRdfFile)
.then(function(data) {
return getXpiInfoFromInstallRdf(data);
});
} else {
getInfo = when.reject(
new Error("Cannot get info: no manifest found in this XPI"));
}
return getInfo
.catch(function(err) {
try {
tmpXPI.remove();
} catch (e) {} // eslint-disable-line no-empty
throw err;
})
.then(function(info) {
tmpXPI.remove();
return info;
});
});
} | javascript | function getXpiInfo(xpiPath) {
return extractXPI(xpiPath)
.then(function(tmpXPI) {
var getInfo;
var packageFile = path.join(tmpXPI.path, "package.json");
var installRdfFile = path.join(tmpXPI.path, "install.rdf");
if (fileExists(packageFile)) {
getInfo = getXpiInfoFromManifest(require(packageFile));
} else if (fileExists(installRdfFile)) {
getInfo = nodefn.call(fs.readFile, installRdfFile)
.then(function(data) {
return getXpiInfoFromInstallRdf(data);
});
} else {
getInfo = when.reject(
new Error("Cannot get info: no manifest found in this XPI"));
}
return getInfo
.catch(function(err) {
try {
tmpXPI.remove();
} catch (e) {} // eslint-disable-line no-empty
throw err;
})
.then(function(info) {
tmpXPI.remove();
return info;
});
});
} | [
"function",
"getXpiInfo",
"(",
"xpiPath",
")",
"{",
"return",
"extractXPI",
"(",
"xpiPath",
")",
".",
"then",
"(",
"function",
"(",
"tmpXPI",
")",
"{",
"var",
"getInfo",
";",
"var",
"packageFile",
"=",
"path",
".",
"join",
"(",
"tmpXPI",
".",
"path",
",",
"\"package.json\"",
")",
";",
"var",
"installRdfFile",
"=",
"path",
".",
"join",
"(",
"tmpXPI",
".",
"path",
",",
"\"install.rdf\"",
")",
";",
"if",
"(",
"fileExists",
"(",
"packageFile",
")",
")",
"{",
"getInfo",
"=",
"getXpiInfoFromManifest",
"(",
"require",
"(",
"packageFile",
")",
")",
";",
"}",
"else",
"if",
"(",
"fileExists",
"(",
"installRdfFile",
")",
")",
"{",
"getInfo",
"=",
"nodefn",
".",
"call",
"(",
"fs",
".",
"readFile",
",",
"installRdfFile",
")",
".",
"then",
"(",
"function",
"(",
"data",
")",
"{",
"return",
"getXpiInfoFromInstallRdf",
"(",
"data",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"getInfo",
"=",
"when",
".",
"reject",
"(",
"new",
"Error",
"(",
"\"Cannot get info: no manifest found in this XPI\"",
")",
")",
";",
"}",
"return",
"getInfo",
".",
"catch",
"(",
"function",
"(",
"err",
")",
"{",
"try",
"{",
"tmpXPI",
".",
"remove",
"(",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"}",
"// eslint-disable-line no-empty",
"throw",
"err",
";",
"}",
")",
".",
"then",
"(",
"function",
"(",
"info",
")",
"{",
"tmpXPI",
".",
"remove",
"(",
")",
";",
"return",
"info",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Returns a promise that resolves with an info object about an XPI file.
@param {String} xpiPath - path to the XPI file
@return {Object} xpiInfo
- manifest: manifest object, which might be empty.
- id: GUID of the XPI.
- version: version string for the XPI. | [
"Returns",
"a",
"promise",
"that",
"resolves",
"with",
"an",
"info",
"object",
"about",
"an",
"XPI",
"file",
"."
] | 5e671fc7745fbf08b373557e40eac6cc74cc65d3 | https://github.com/mozilla-jetpack/jpm/blob/5e671fc7745fbf08b373557e40eac6cc74cc65d3/lib/utils.js#L102-L133 |
21,465 | mozilla-jetpack/jpm | lib/profile.js | addPrefs | function addPrefs(profile, options) {
var userPrefs = options.prefs || {};
return when.promise(function(resolve, reject) {
Object.keys(userPrefs).forEach(function(key) {
profile.setPreference(key, userPrefs[key]);
});
profile.updatePreferences();
resolve(profile);
});
} | javascript | function addPrefs(profile, options) {
var userPrefs = options.prefs || {};
return when.promise(function(resolve, reject) {
Object.keys(userPrefs).forEach(function(key) {
profile.setPreference(key, userPrefs[key]);
});
profile.updatePreferences();
resolve(profile);
});
} | [
"function",
"addPrefs",
"(",
"profile",
",",
"options",
")",
"{",
"var",
"userPrefs",
"=",
"options",
".",
"prefs",
"||",
"{",
"}",
";",
"return",
"when",
".",
"promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"Object",
".",
"keys",
"(",
"userPrefs",
")",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"profile",
".",
"setPreference",
"(",
"key",
",",
"userPrefs",
"[",
"key",
"]",
")",
";",
"}",
")",
";",
"profile",
".",
"updatePreferences",
"(",
")",
";",
"resolve",
"(",
"profile",
")",
";",
"}",
")",
";",
"}"
] | Set any of the preferences passed via options. | [
"Set",
"any",
"of",
"the",
"preferences",
"passed",
"via",
"options",
"."
] | 5e671fc7745fbf08b373557e40eac6cc74cc65d3 | https://github.com/mozilla-jetpack/jpm/blob/5e671fc7745fbf08b373557e40eac6cc74cc65d3/lib/profile.js#L39-L49 |
21,466 | tgriesser/checkit | core.js | Checkit | function Checkit(validations, options) {
if (!(this instanceof Checkit)) {
return new Checkit(validations, options);
}
this.conditional = [];
options = _.clone(options || {});
this.labels = options.labels || {};
this.messages = options.messages || {};
this.language = Checkit.i18n[options.language || Checkit.language] || {};
this.labelTransform = options.labelTransform || Checkit.labelTransform
this.validations = prepValidations(validations || {});
} | javascript | function Checkit(validations, options) {
if (!(this instanceof Checkit)) {
return new Checkit(validations, options);
}
this.conditional = [];
options = _.clone(options || {});
this.labels = options.labels || {};
this.messages = options.messages || {};
this.language = Checkit.i18n[options.language || Checkit.language] || {};
this.labelTransform = options.labelTransform || Checkit.labelTransform
this.validations = prepValidations(validations || {});
} | [
"function",
"Checkit",
"(",
"validations",
",",
"options",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Checkit",
")",
")",
"{",
"return",
"new",
"Checkit",
"(",
"validations",
",",
"options",
")",
";",
"}",
"this",
".",
"conditional",
"=",
"[",
"]",
";",
"options",
"=",
"_",
".",
"clone",
"(",
"options",
"||",
"{",
"}",
")",
";",
"this",
".",
"labels",
"=",
"options",
".",
"labels",
"||",
"{",
"}",
";",
"this",
".",
"messages",
"=",
"options",
".",
"messages",
"||",
"{",
"}",
";",
"this",
".",
"language",
"=",
"Checkit",
".",
"i18n",
"[",
"options",
".",
"language",
"||",
"Checkit",
".",
"language",
"]",
"||",
"{",
"}",
";",
"this",
".",
"labelTransform",
"=",
"options",
".",
"labelTransform",
"||",
"Checkit",
".",
"labelTransform",
"this",
".",
"validations",
"=",
"prepValidations",
"(",
"validations",
"||",
"{",
"}",
")",
";",
"}"
] | The top level `Checkit` constructor, accepting the `validations` to be run and any additional `options`. | [
"The",
"top",
"level",
"Checkit",
"constructor",
"accepting",
"the",
"validations",
"to",
"be",
"run",
"and",
"any",
"additional",
"options",
"."
] | 7938418df789653cf9dcdee9c71ca59074dfba3f | https://github.com/tgriesser/checkit/blob/7938418df789653cf9dcdee9c71ca59074dfba3f/core.js#L11-L22 |
21,467 | tgriesser/checkit | core.js | checkSync | function checkSync(validations, input, key) {
var arr = new Checkit(validations).runSync(input);
if (arr[0] === null) return arr;
if (arr[0] instanceof CheckitError) {
return [arr[0].get(key), null]
}
return arr;
} | javascript | function checkSync(validations, input, key) {
var arr = new Checkit(validations).runSync(input);
if (arr[0] === null) return arr;
if (arr[0] instanceof CheckitError) {
return [arr[0].get(key), null]
}
return arr;
} | [
"function",
"checkSync",
"(",
"validations",
",",
"input",
",",
"key",
")",
"{",
"var",
"arr",
"=",
"new",
"Checkit",
"(",
"validations",
")",
".",
"runSync",
"(",
"input",
")",
";",
"if",
"(",
"arr",
"[",
"0",
"]",
"===",
"null",
")",
"return",
"arr",
";",
"if",
"(",
"arr",
"[",
"0",
"]",
"instanceof",
"CheckitError",
")",
"{",
"return",
"[",
"arr",
"[",
"0",
"]",
".",
"get",
"(",
"key",
")",
",",
"null",
"]",
"}",
"return",
"arr",
";",
"}"
] | Synchronously check an individual field against a rule. | [
"Synchronously",
"check",
"an",
"individual",
"field",
"against",
"a",
"rule",
"."
] | 7938418df789653cf9dcdee9c71ca59074dfba3f | https://github.com/tgriesser/checkit/blob/7938418df789653cf9dcdee9c71ca59074dfba3f/core.js#L106-L113 |
21,468 | tgriesser/checkit | core.js | Runner | function Runner(checkit, target, context) {
this.errors = {};
this.checkit = checkit;
this.conditional = checkit.conditional;
this.target = _.clone(target || {})
this.context = _.clone(context || {})
this.validator = new Validator(this.target, checkit.language)
} | javascript | function Runner(checkit, target, context) {
this.errors = {};
this.checkit = checkit;
this.conditional = checkit.conditional;
this.target = _.clone(target || {})
this.context = _.clone(context || {})
this.validator = new Validator(this.target, checkit.language)
} | [
"function",
"Runner",
"(",
"checkit",
",",
"target",
",",
"context",
")",
"{",
"this",
".",
"errors",
"=",
"{",
"}",
";",
"this",
".",
"checkit",
"=",
"checkit",
";",
"this",
".",
"conditional",
"=",
"checkit",
".",
"conditional",
";",
"this",
".",
"target",
"=",
"_",
".",
"clone",
"(",
"target",
"||",
"{",
"}",
")",
"this",
".",
"context",
"=",
"_",
".",
"clone",
"(",
"context",
"||",
"{",
"}",
")",
"this",
".",
"validator",
"=",
"new",
"Validator",
"(",
"this",
".",
"target",
",",
"checkit",
".",
"language",
")",
"}"
] | The validator is the object which is dispatched with the `run` call from the `checkit.run` method. | [
"The",
"validator",
"is",
"the",
"object",
"which",
"is",
"dispatched",
"with",
"the",
"run",
"call",
"from",
"the",
"checkit",
".",
"run",
"method",
"."
] | 7938418df789653cf9dcdee9c71ca59074dfba3f | https://github.com/tgriesser/checkit/blob/7938418df789653cf9dcdee9c71ca59074dfba3f/core.js#L117-L124 |
21,469 | tgriesser/checkit | core.js | addVerifiedConditional | function addVerifiedConditional(validations, conditional) {
_.each(conditional[0], function(val, key) {
validations[key] = validations[key] || [];
validations[key] = validations[key].concat(val);
})
} | javascript | function addVerifiedConditional(validations, conditional) {
_.each(conditional[0], function(val, key) {
validations[key] = validations[key] || [];
validations[key] = validations[key].concat(val);
})
} | [
"function",
"addVerifiedConditional",
"(",
"validations",
",",
"conditional",
")",
"{",
"_",
".",
"each",
"(",
"conditional",
"[",
"0",
"]",
",",
"function",
"(",
"val",
",",
"key",
")",
"{",
"validations",
"[",
"key",
"]",
"=",
"validations",
"[",
"key",
"]",
"||",
"[",
"]",
";",
"validations",
"[",
"key",
"]",
"=",
"validations",
"[",
"key",
"]",
".",
"concat",
"(",
"val",
")",
";",
"}",
")",
"}"
] | Only if we explicitly return `true` do we go ahead and add the validations to the stack for a particular rule. | [
"Only",
"if",
"we",
"explicitly",
"return",
"true",
"do",
"we",
"go",
"ahead",
"and",
"add",
"the",
"validations",
"to",
"the",
"stack",
"for",
"a",
"particular",
"rule",
"."
] | 7938418df789653cf9dcdee9c71ca59074dfba3f | https://github.com/tgriesser/checkit/blob/7938418df789653cf9dcdee9c71ca59074dfba3f/core.js#L166-L171 |
21,470 | tgriesser/checkit | core.js | checkConditional | function checkConditional(runner, conditional) {
try {
return conditional[1].call(runner, runner.target, runner.context);
} catch (e) {}
} | javascript | function checkConditional(runner, conditional) {
try {
return conditional[1].call(runner, runner.target, runner.context);
} catch (e) {}
} | [
"function",
"checkConditional",
"(",
"runner",
",",
"conditional",
")",
"{",
"try",
"{",
"return",
"conditional",
"[",
"1",
"]",
".",
"call",
"(",
"runner",
",",
"runner",
".",
"target",
",",
"runner",
".",
"context",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"}",
"}"
] | Runs through each of the `conditional` validations, and merges them with the other validations if the condition passes; either by returning `true` or a fulfilled promise. | [
"Runs",
"through",
"each",
"of",
"the",
"conditional",
"validations",
"and",
"merges",
"them",
"with",
"the",
"other",
"validations",
"if",
"the",
"condition",
"passes",
";",
"either",
"by",
"returning",
"true",
"or",
"a",
"fulfilled",
"promise",
"."
] | 7938418df789653cf9dcdee9c71ca59074dfba3f | https://github.com/tgriesser/checkit/blob/7938418df789653cf9dcdee9c71ca59074dfba3f/core.js#L176-L180 |
21,471 | tgriesser/checkit | core.js | processItemAsync | function processItemAsync(runner, currentValidation, key, context) {
return Promise.resolve(true).then(function() {
return processItem(runner, currentValidation, key, context)
});
} | javascript | function processItemAsync(runner, currentValidation, key, context) {
return Promise.resolve(true).then(function() {
return processItem(runner, currentValidation, key, context)
});
} | [
"function",
"processItemAsync",
"(",
"runner",
",",
"currentValidation",
",",
"key",
",",
"context",
")",
"{",
"return",
"Promise",
".",
"resolve",
"(",
"true",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"return",
"processItem",
"(",
"runner",
",",
"currentValidation",
",",
"key",
",",
"context",
")",
"}",
")",
";",
"}"
] | Processes an individual item in the validation collection for the current validation object. Returns the value from the completed validation, which will be a boolean, or potentially a promise if the current object is an async validation. | [
"Processes",
"an",
"individual",
"item",
"in",
"the",
"validation",
"collection",
"for",
"the",
"current",
"validation",
"object",
".",
"Returns",
"the",
"value",
"from",
"the",
"completed",
"validation",
"which",
"will",
"be",
"a",
"boolean",
"or",
"potentially",
"a",
"promise",
"if",
"the",
"current",
"object",
"is",
"an",
"async",
"validation",
"."
] | 7938418df789653cf9dcdee9c71ca59074dfba3f | https://github.com/tgriesser/checkit/blob/7938418df789653cf9dcdee9c71ca59074dfba3f/core.js#L214-L218 |
21,472 | tgriesser/checkit | core.js | function(val, item) {
if (_.isString(val)) return val.indexOf(item) !== -1;
if (_.isArray(val)) return _.indexOf(val, item) !== -1;
if (_.isObject(val)) return _.has(val, item);
return false;
} | javascript | function(val, item) {
if (_.isString(val)) return val.indexOf(item) !== -1;
if (_.isArray(val)) return _.indexOf(val, item) !== -1;
if (_.isObject(val)) return _.has(val, item);
return false;
} | [
"function",
"(",
"val",
",",
"item",
")",
"{",
"if",
"(",
"_",
".",
"isString",
"(",
"val",
")",
")",
"return",
"val",
".",
"indexOf",
"(",
"item",
")",
"!==",
"-",
"1",
";",
"if",
"(",
"_",
".",
"isArray",
"(",
"val",
")",
")",
"return",
"_",
".",
"indexOf",
"(",
"val",
",",
"item",
")",
"!==",
"-",
"1",
";",
"if",
"(",
"_",
".",
"isObject",
"(",
"val",
")",
")",
"return",
"_",
".",
"has",
"(",
"val",
",",
"item",
")",
";",
"return",
"false",
";",
"}"
] | Check that an item contains another item, either a string, array, or object. | [
"Check",
"that",
"an",
"item",
"contains",
"another",
"item",
"either",
"a",
"string",
"array",
"or",
"object",
"."
] | 7938418df789653cf9dcdee9c71ca59074dfba3f | https://github.com/tgriesser/checkit/blob/7938418df789653cf9dcdee9c71ca59074dfba3f/core.js#L321-L326 | |
21,473 | tgriesser/checkit | core.js | function(val, param) {
return checkNumber(val) || checkNumber(param) || parseFloat(val) <= parseFloat(param);
} | javascript | function(val, param) {
return checkNumber(val) || checkNumber(param) || parseFloat(val) <= parseFloat(param);
} | [
"function",
"(",
"val",
",",
"param",
")",
"{",
"return",
"checkNumber",
"(",
"val",
")",
"||",
"checkNumber",
"(",
"param",
")",
"||",
"parseFloat",
"(",
"val",
")",
"<=",
"parseFloat",
"(",
"param",
")",
";",
"}"
] | Check if one item is less than or equal to another | [
"Check",
"if",
"one",
"item",
"is",
"less",
"than",
"or",
"equal",
"to",
"another"
] | 7938418df789653cf9dcdee9c71ca59074dfba3f | https://github.com/tgriesser/checkit/blob/7938418df789653cf9dcdee9c71ca59074dfba3f/core.js#L380-L382 | |
21,474 | tgriesser/checkit | core.js | function(flat) {
return this.transform(function(acc, val, key) {
var json = val.toJSON();
acc[key] = flat && _.isArray(json) ? json[0] : json
}, {});
} | javascript | function(flat) {
return this.transform(function(acc, val, key) {
var json = val.toJSON();
acc[key] = flat && _.isArray(json) ? json[0] : json
}, {});
} | [
"function",
"(",
"flat",
")",
"{",
"return",
"this",
".",
"transform",
"(",
"function",
"(",
"acc",
",",
"val",
",",
"key",
")",
"{",
"var",
"json",
"=",
"val",
".",
"toJSON",
"(",
")",
";",
"acc",
"[",
"key",
"]",
"=",
"flat",
"&&",
"_",
".",
"isArray",
"(",
"json",
")",
"?",
"json",
"[",
"0",
"]",
":",
"json",
"}",
",",
"{",
"}",
")",
";",
"}"
] | Creates a JSON object of the validations, if `true` is passed - it will flatten the error into a single value per item. | [
"Creates",
"a",
"JSON",
"object",
"of",
"the",
"validations",
"if",
"true",
"is",
"passed",
"-",
"it",
"will",
"flatten",
"the",
"error",
"into",
"a",
"single",
"value",
"per",
"item",
"."
] | 7938418df789653cf9dcdee9c71ca59074dfba3f | https://github.com/tgriesser/checkit/blob/7938418df789653cf9dcdee9c71ca59074dfba3f/core.js#L498-L503 | |
21,475 | tgriesser/checkit | core.js | prepValidations | function prepValidations(validations) {
validations = _.cloneDeep(validations);
for (var key in validations) {
var validation = validations[key];
if (!_.isArray(validation)) validations[key] = validation = [validation];
for (var i = 0, l = validation.length; i < l; i++) {
validation[i] = assembleValidation(validation[i]);
}
}
return validations;
} | javascript | function prepValidations(validations) {
validations = _.cloneDeep(validations);
for (var key in validations) {
var validation = validations[key];
if (!_.isArray(validation)) validations[key] = validation = [validation];
for (var i = 0, l = validation.length; i < l; i++) {
validation[i] = assembleValidation(validation[i]);
}
}
return validations;
} | [
"function",
"prepValidations",
"(",
"validations",
")",
"{",
"validations",
"=",
"_",
".",
"cloneDeep",
"(",
"validations",
")",
";",
"for",
"(",
"var",
"key",
"in",
"validations",
")",
"{",
"var",
"validation",
"=",
"validations",
"[",
"key",
"]",
";",
"if",
"(",
"!",
"_",
".",
"isArray",
"(",
"validation",
")",
")",
"validations",
"[",
"key",
"]",
"=",
"validation",
"=",
"[",
"validation",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"l",
"=",
"validation",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"validation",
"[",
"i",
"]",
"=",
"assembleValidation",
"(",
"validation",
"[",
"i",
"]",
")",
";",
"}",
"}",
"return",
"validations",
";",
"}"
] | Preps the validations being sent to the `run` block, to standardize the format and allow for maximum flexibility when passing to the validation blocks. | [
"Preps",
"the",
"validations",
"being",
"sent",
"to",
"the",
"run",
"block",
"to",
"standardize",
"the",
"format",
"and",
"allow",
"for",
"maximum",
"flexibility",
"when",
"passing",
"to",
"the",
"validation",
"blocks",
"."
] | 7938418df789653cf9dcdee9c71ca59074dfba3f | https://github.com/tgriesser/checkit/blob/7938418df789653cf9dcdee9c71ca59074dfba3f/core.js#L540-L550 |
21,476 | goldibex/targaryen | lib/database/query.js | mergeQueries | function mergeQueries(query, options) {
if (options == null) {
return query;
}
Object.keys(options).forEach(key => {
let label = key;
let value = options[key];
validateProp(key, value);
switch (key) {
case 'orderByKey':
label = orderedBy;
value = orderByKey;
break;
case 'orderByPriority':
label = orderedBy;
value = orderByPriority;
break;
case 'orderByValue':
label = orderedBy;
value = orderByValue;
break;
case 'orderByChild':
label = orderedBy;
break;
default:
break;
}
query[label] = value;
});
return query;
} | javascript | function mergeQueries(query, options) {
if (options == null) {
return query;
}
Object.keys(options).forEach(key => {
let label = key;
let value = options[key];
validateProp(key, value);
switch (key) {
case 'orderByKey':
label = orderedBy;
value = orderByKey;
break;
case 'orderByPriority':
label = orderedBy;
value = orderByPriority;
break;
case 'orderByValue':
label = orderedBy;
value = orderByValue;
break;
case 'orderByChild':
label = orderedBy;
break;
default:
break;
}
query[label] = value;
});
return query;
} | [
"function",
"mergeQueries",
"(",
"query",
",",
"options",
")",
"{",
"if",
"(",
"options",
"==",
"null",
")",
"{",
"return",
"query",
";",
"}",
"Object",
".",
"keys",
"(",
"options",
")",
".",
"forEach",
"(",
"key",
"=>",
"{",
"let",
"label",
"=",
"key",
";",
"let",
"value",
"=",
"options",
"[",
"key",
"]",
";",
"validateProp",
"(",
"key",
",",
"value",
")",
";",
"switch",
"(",
"key",
")",
"{",
"case",
"'orderByKey'",
":",
"label",
"=",
"orderedBy",
";",
"value",
"=",
"orderByKey",
";",
"break",
";",
"case",
"'orderByPriority'",
":",
"label",
"=",
"orderedBy",
";",
"value",
"=",
"orderByPriority",
";",
"break",
";",
"case",
"'orderByValue'",
":",
"label",
"=",
"orderedBy",
";",
"value",
"=",
"orderByValue",
";",
"break",
";",
"case",
"'orderByChild'",
":",
"label",
"=",
"orderedBy",
";",
"break",
";",
"default",
":",
"break",
";",
"}",
"query",
"[",
"label",
"]",
"=",
"value",
";",
"}",
")",
";",
"return",
"query",
";",
"}"
] | Validate and merge partial query parameters to a query object.
@param {Query} query Query to merges properties to
@param {Partial<Query>} options Partial query parameters
@returns {Query} | [
"Validate",
"and",
"merge",
"partial",
"query",
"parameters",
"to",
"a",
"query",
"object",
"."
] | e4151e75642ea6383e41278c09b1eb02984abadc | https://github.com/goldibex/targaryen/blob/e4151e75642ea6383e41278c09b1eb02984abadc/lib/database/query.js#L96-L135 |
21,477 | goldibex/targaryen | lib/database/query.js | validateProp | function validateProp(key, value) {
const type = typeof value;
switch (key) {
case 'orderByKey':
case 'orderByPriority':
case 'orderByValue':
if (!value) {
throw new Error(`"query.${key}" should not be set to false. Set it off by setting an other order.`);
}
break;
case 'orderByChild':
if (value == null) {
throw new Error('"query.orderByChild" should not be set to null. Set it off by setting an other order.');
}
if (type !== 'string') {
throw new Error('"query.orderByChild" should be a string or null.');
}
break;
case 'startAt':
case 'endAt':
case 'equalTo':
if (
value !== null &&
type !== 'string' &&
type !== 'number' &&
type !== 'boolean'
) {
throw new Error(`query.${key} should be a string, a number, a boolean or null.`);
}
break;
case 'limitToFirst':
case 'limitToLast':
if (value != null && type !== 'number') {
throw new Error(`query.${key} should be a number or null.`);
}
break;
default:
throw new Error(`"${key}" is not a query parameter.`);
}
} | javascript | function validateProp(key, value) {
const type = typeof value;
switch (key) {
case 'orderByKey':
case 'orderByPriority':
case 'orderByValue':
if (!value) {
throw new Error(`"query.${key}" should not be set to false. Set it off by setting an other order.`);
}
break;
case 'orderByChild':
if (value == null) {
throw new Error('"query.orderByChild" should not be set to null. Set it off by setting an other order.');
}
if (type !== 'string') {
throw new Error('"query.orderByChild" should be a string or null.');
}
break;
case 'startAt':
case 'endAt':
case 'equalTo':
if (
value !== null &&
type !== 'string' &&
type !== 'number' &&
type !== 'boolean'
) {
throw new Error(`query.${key} should be a string, a number, a boolean or null.`);
}
break;
case 'limitToFirst':
case 'limitToLast':
if (value != null && type !== 'number') {
throw new Error(`query.${key} should be a number or null.`);
}
break;
default:
throw new Error(`"${key}" is not a query parameter.`);
}
} | [
"function",
"validateProp",
"(",
"key",
",",
"value",
")",
"{",
"const",
"type",
"=",
"typeof",
"value",
";",
"switch",
"(",
"key",
")",
"{",
"case",
"'orderByKey'",
":",
"case",
"'orderByPriority'",
":",
"case",
"'orderByValue'",
":",
"if",
"(",
"!",
"value",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"key",
"}",
"`",
")",
";",
"}",
"break",
";",
"case",
"'orderByChild'",
":",
"if",
"(",
"value",
"==",
"null",
")",
"{",
"throw",
"new",
"Error",
"(",
"'\"query.orderByChild\" should not be set to null. Set it off by setting an other order.'",
")",
";",
"}",
"if",
"(",
"type",
"!==",
"'string'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'\"query.orderByChild\" should be a string or null.'",
")",
";",
"}",
"break",
";",
"case",
"'startAt'",
":",
"case",
"'endAt'",
":",
"case",
"'equalTo'",
":",
"if",
"(",
"value",
"!==",
"null",
"&&",
"type",
"!==",
"'string'",
"&&",
"type",
"!==",
"'number'",
"&&",
"type",
"!==",
"'boolean'",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"key",
"}",
"`",
")",
";",
"}",
"break",
";",
"case",
"'limitToFirst'",
":",
"case",
"'limitToLast'",
":",
"if",
"(",
"value",
"!=",
"null",
"&&",
"type",
"!==",
"'number'",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"key",
"}",
"`",
")",
";",
"}",
"break",
";",
"default",
":",
"throw",
"new",
"Error",
"(",
"`",
"${",
"key",
"}",
"`",
")",
";",
"}",
"}"
] | Validate a query property
@param {string} key Property name
@param {any} value Property value | [
"Validate",
"a",
"query",
"property"
] | e4151e75642ea6383e41278c09b1eb02984abadc | https://github.com/goldibex/targaryen/blob/e4151e75642ea6383e41278c09b1eb02984abadc/lib/database/query.js#L143-L187 |
21,478 | fortunejs/fortune-json-api | lib/helpers.js | setInflectType | function setInflectType (inflect, types) {
// use inflections if set as object else start fresh
const out = typeof inflect === 'boolean' ? {} : inflect
// if inflect is boolean use it for all types,
// else use default for unset types
const setInflect = typeof inflect === 'boolean' ? inflect : inflectTypeDef
// For each Type set inflection, if not set
for (const t of types) {
const plural = inflection.transform(t, typeInflections[1])
if (!(t in out))
out[t] = setInflect
// allow checking on pluralized too
if (!(plural in out))
out[plural] = out[t]
}
return out
} | javascript | function setInflectType (inflect, types) {
// use inflections if set as object else start fresh
const out = typeof inflect === 'boolean' ? {} : inflect
// if inflect is boolean use it for all types,
// else use default for unset types
const setInflect = typeof inflect === 'boolean' ? inflect : inflectTypeDef
// For each Type set inflection, if not set
for (const t of types) {
const plural = inflection.transform(t, typeInflections[1])
if (!(t in out))
out[t] = setInflect
// allow checking on pluralized too
if (!(plural in out))
out[plural] = out[t]
}
return out
} | [
"function",
"setInflectType",
"(",
"inflect",
",",
"types",
")",
"{",
"// use inflections if set as object else start fresh",
"const",
"out",
"=",
"typeof",
"inflect",
"===",
"'boolean'",
"?",
"{",
"}",
":",
"inflect",
"// if inflect is boolean use it for all types,",
"// else use default for unset types",
"const",
"setInflect",
"=",
"typeof",
"inflect",
"===",
"'boolean'",
"?",
"inflect",
":",
"inflectTypeDef",
"// For each Type set inflection, if not set",
"for",
"(",
"const",
"t",
"of",
"types",
")",
"{",
"const",
"plural",
"=",
"inflection",
".",
"transform",
"(",
"t",
",",
"typeInflections",
"[",
"1",
"]",
")",
"if",
"(",
"!",
"(",
"t",
"in",
"out",
")",
")",
"out",
"[",
"t",
"]",
"=",
"setInflect",
"// allow checking on pluralized too",
"if",
"(",
"!",
"(",
"plural",
"in",
"out",
")",
")",
"out",
"[",
"plural",
"]",
"=",
"out",
"[",
"t",
"]",
"}",
"return",
"out",
"}"
] | Generate a list of which types are inflected.
@param {Boolean|Object} inflect setting from defaults or user override
@param {String[]} types array of declared types
@return {Object} | [
"Generate",
"a",
"list",
"of",
"which",
"types",
"are",
"inflected",
"."
] | 1475c5aea69726d3b2eef938f0044e372f940e37 | https://github.com/fortunejs/fortune-json-api/blob/1475c5aea69726d3b2eef938f0044e372f940e37/lib/helpers.js#L495-L515 |
21,479 | rrdelaney/bs-loader | packages/bsb-js/utils.js | processBsbError | function processBsbError(err /*: Error | string */) /*: Error[] */ {
if (typeof err === 'string') {
const errors = errorRegexes
// $FlowIssue: err is definitely a string
.map((r /*: RegExp */) => err.match(r))
.reduce((a, s) => a.concat(s), [])
.filter(x => x)
return (errors.length > 0 ? errors : [err]).map(e => new Error(e))
} else {
return [err]
}
} | javascript | function processBsbError(err /*: Error | string */) /*: Error[] */ {
if (typeof err === 'string') {
const errors = errorRegexes
// $FlowIssue: err is definitely a string
.map((r /*: RegExp */) => err.match(r))
.reduce((a, s) => a.concat(s), [])
.filter(x => x)
return (errors.length > 0 ? errors : [err]).map(e => new Error(e))
} else {
return [err]
}
} | [
"function",
"processBsbError",
"(",
"err",
"/*: Error | string */",
")",
"/*: Error[] */",
"{",
"if",
"(",
"typeof",
"err",
"===",
"'string'",
")",
"{",
"const",
"errors",
"=",
"errorRegexes",
"// $FlowIssue: err is definitely a string",
".",
"map",
"(",
"(",
"r",
"/*: RegExp */",
")",
"=>",
"err",
".",
"match",
"(",
"r",
")",
")",
".",
"reduce",
"(",
"(",
"a",
",",
"s",
")",
"=>",
"a",
".",
"concat",
"(",
"s",
")",
",",
"[",
"]",
")",
".",
"filter",
"(",
"x",
"=>",
"x",
")",
"return",
"(",
"errors",
".",
"length",
">",
"0",
"?",
"errors",
":",
"[",
"err",
"]",
")",
".",
"map",
"(",
"e",
"=>",
"new",
"Error",
"(",
"e",
")",
")",
"}",
"else",
"{",
"return",
"[",
"err",
"]",
"}",
"}"
] | This function is only ever called if an error has been caught. We try to process said error according to known formats, but we default to what we got as an argument if they don't match. This way we always throw an error, thus avoiding successful builds if something has gone wrong. | [
"This",
"function",
"is",
"only",
"ever",
"called",
"if",
"an",
"error",
"has",
"been",
"caught",
".",
"We",
"try",
"to",
"process",
"said",
"error",
"according",
"to",
"known",
"formats",
"but",
"we",
"default",
"to",
"what",
"we",
"got",
"as",
"an",
"argument",
"if",
"they",
"don",
"t",
"match",
".",
"This",
"way",
"we",
"always",
"throw",
"an",
"error",
"thus",
"avoiding",
"successful",
"builds",
"if",
"something",
"has",
"gone",
"wrong",
"."
] | a7e39fc01a25e6345a79a7f0972c8a03f5c59ec1 | https://github.com/rrdelaney/bs-loader/blob/a7e39fc01a25e6345a79a7f0972c8a03f5c59ec1/packages/bsb-js/utils.js#L42-L54 |
21,480 | rrdelaney/bs-loader | packages/bsb-js/index.js | runBuild | function runBuild(cwd /*: string */) /*: Promise<string> */ {
return new Promise((resolve, reject) => {
exec(bsb, {maxBuffer: Infinity, cwd}, (err, stdout, stderr) => {
const output = `${stdout.toString()}\n${stderr.toString()}`
if (err) {
reject(output)
} else {
resolve(output)
}
})
})
} | javascript | function runBuild(cwd /*: string */) /*: Promise<string> */ {
return new Promise((resolve, reject) => {
exec(bsb, {maxBuffer: Infinity, cwd}, (err, stdout, stderr) => {
const output = `${stdout.toString()}\n${stderr.toString()}`
if (err) {
reject(output)
} else {
resolve(output)
}
})
})
} | [
"function",
"runBuild",
"(",
"cwd",
"/*: string */",
")",
"/*: Promise<string> */",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"exec",
"(",
"bsb",
",",
"{",
"maxBuffer",
":",
"Infinity",
",",
"cwd",
"}",
",",
"(",
"err",
",",
"stdout",
",",
"stderr",
")",
"=>",
"{",
"const",
"output",
"=",
"`",
"${",
"stdout",
".",
"toString",
"(",
")",
"}",
"\\n",
"${",
"stderr",
".",
"toString",
"(",
")",
"}",
"`",
"if",
"(",
"err",
")",
"{",
"reject",
"(",
"output",
")",
"}",
"else",
"{",
"resolve",
"(",
"output",
")",
"}",
"}",
")",
"}",
")",
"}"
] | Runs `bsb` async | [
"Runs",
"bsb",
"async"
] | a7e39fc01a25e6345a79a7f0972c8a03f5c59ec1 | https://github.com/rrdelaney/bs-loader/blob/a7e39fc01a25e6345a79a7f0972c8a03f5c59ec1/packages/bsb-js/index.js#L30-L41 |
21,481 | rrdelaney/bs-loader | packages/bsb-js/index.js | compileFile | function compileFile(
buildDir /*: string */,
moduleType /*: BsModuleFormat | 'js' */,
path /*: string */,
id /*: ?string */ = null,
) /*: Promise<Compilation> */ {
if (id && buildRuns[id] !== undefined) {
buildRuns[id] = runBuild(buildDir)
}
const buildProcess = id ? buildRuns[id] : runBuild(buildDir)
return buildProcess
.then(
output =>
new Promise((resolve, reject) => {
readFile(path, (err, res) => {
if (err) {
resolve({
src: undefined,
warnings: [],
errors: [err],
})
} else {
const src = utils.transformSrc(moduleType, res.toString())
resolve({
src,
warnings: utils.processBsbWarnings(output),
errors: [],
})
}
})
}),
)
.catch(err => ({
src: undefined,
warnings: [],
errors: utils.processBsbError(err),
}))
} | javascript | function compileFile(
buildDir /*: string */,
moduleType /*: BsModuleFormat | 'js' */,
path /*: string */,
id /*: ?string */ = null,
) /*: Promise<Compilation> */ {
if (id && buildRuns[id] !== undefined) {
buildRuns[id] = runBuild(buildDir)
}
const buildProcess = id ? buildRuns[id] : runBuild(buildDir)
return buildProcess
.then(
output =>
new Promise((resolve, reject) => {
readFile(path, (err, res) => {
if (err) {
resolve({
src: undefined,
warnings: [],
errors: [err],
})
} else {
const src = utils.transformSrc(moduleType, res.toString())
resolve({
src,
warnings: utils.processBsbWarnings(output),
errors: [],
})
}
})
}),
)
.catch(err => ({
src: undefined,
warnings: [],
errors: utils.processBsbError(err),
}))
} | [
"function",
"compileFile",
"(",
"buildDir",
"/*: string */",
",",
"moduleType",
"/*: BsModuleFormat | 'js' */",
",",
"path",
"/*: string */",
",",
"id",
"/*: ?string */",
"=",
"null",
",",
")",
"/*: Promise<Compilation> */",
"{",
"if",
"(",
"id",
"&&",
"buildRuns",
"[",
"id",
"]",
"!==",
"undefined",
")",
"{",
"buildRuns",
"[",
"id",
"]",
"=",
"runBuild",
"(",
"buildDir",
")",
"}",
"const",
"buildProcess",
"=",
"id",
"?",
"buildRuns",
"[",
"id",
"]",
":",
"runBuild",
"(",
"buildDir",
")",
"return",
"buildProcess",
".",
"then",
"(",
"output",
"=>",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"readFile",
"(",
"path",
",",
"(",
"err",
",",
"res",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"resolve",
"(",
"{",
"src",
":",
"undefined",
",",
"warnings",
":",
"[",
"]",
",",
"errors",
":",
"[",
"err",
"]",
",",
"}",
")",
"}",
"else",
"{",
"const",
"src",
"=",
"utils",
".",
"transformSrc",
"(",
"moduleType",
",",
"res",
".",
"toString",
"(",
")",
")",
"resolve",
"(",
"{",
"src",
",",
"warnings",
":",
"utils",
".",
"processBsbWarnings",
"(",
"output",
")",
",",
"errors",
":",
"[",
"]",
",",
"}",
")",
"}",
"}",
")",
"}",
")",
",",
")",
".",
"catch",
"(",
"err",
"=>",
"(",
"{",
"src",
":",
"undefined",
",",
"warnings",
":",
"[",
"]",
",",
"errors",
":",
"utils",
".",
"processBsbError",
"(",
"err",
")",
",",
"}",
")",
")",
"}"
] | Compiles a Reason file to JS | [
"Compiles",
"a",
"Reason",
"file",
"to",
"JS"
] | a7e39fc01a25e6345a79a7f0972c8a03f5c59ec1 | https://github.com/rrdelaney/bs-loader/blob/a7e39fc01a25e6345a79a7f0972c8a03f5c59ec1/packages/bsb-js/index.js#L61-L101 |
21,482 | rrdelaney/bs-loader | packages/bsb-js/index.js | compileFileSync | function compileFileSync(
buildDir /*: string */,
moduleType /*: BsModuleFormat | 'js' */,
path /*: string */,
) /*: string */ {
try {
runBuildSync(buildDir)
} catch (e) {
throw utils.processBsbError(e.output.toString())
}
const res = readFileSync(path)
return utils.transformSrc(moduleType, res.toString())
} | javascript | function compileFileSync(
buildDir /*: string */,
moduleType /*: BsModuleFormat | 'js' */,
path /*: string */,
) /*: string */ {
try {
runBuildSync(buildDir)
} catch (e) {
throw utils.processBsbError(e.output.toString())
}
const res = readFileSync(path)
return utils.transformSrc(moduleType, res.toString())
} | [
"function",
"compileFileSync",
"(",
"buildDir",
"/*: string */",
",",
"moduleType",
"/*: BsModuleFormat | 'js' */",
",",
"path",
"/*: string */",
",",
")",
"/*: string */",
"{",
"try",
"{",
"runBuildSync",
"(",
"buildDir",
")",
"}",
"catch",
"(",
"e",
")",
"{",
"throw",
"utils",
".",
"processBsbError",
"(",
"e",
".",
"output",
".",
"toString",
"(",
")",
")",
"}",
"const",
"res",
"=",
"readFileSync",
"(",
"path",
")",
"return",
"utils",
".",
"transformSrc",
"(",
"moduleType",
",",
"res",
".",
"toString",
"(",
")",
")",
"}"
] | Compiles a Reason file to JS sync | [
"Compiles",
"a",
"Reason",
"file",
"to",
"JS",
"sync"
] | a7e39fc01a25e6345a79a7f0972c8a03f5c59ec1 | https://github.com/rrdelaney/bs-loader/blob/a7e39fc01a25e6345a79a7f0972c8a03f5c59ec1/packages/bsb-js/index.js#L104-L117 |
21,483 | Swaagie/minimize | lib/helpers.js | compact | function compact(value, keepNewlines) {
var check = keepNewlines ? / +/g : /\s+/g;
return value.replace(check, ' ');
} | javascript | function compact(value, keepNewlines) {
var check = keepNewlines ? / +/g : /\s+/g;
return value.replace(check, ' ');
} | [
"function",
"compact",
"(",
"value",
",",
"keepNewlines",
")",
"{",
"var",
"check",
"=",
"keepNewlines",
"?",
"/",
" +",
"/",
"g",
":",
"/",
"\\s+",
"/",
"g",
";",
"return",
"value",
".",
"replace",
"(",
"check",
",",
"' '",
")",
";",
"}"
] | Compact the value, replace multiple white spaces and newlines
with a single white space.
@param {String} value Value to compact
@param {Boolean} keepNewlines Do not remove newlines
@return {String} Compacted data
@api private | [
"Compact",
"the",
"value",
"replace",
"multiple",
"white",
"spaces",
"and",
"newlines",
"with",
"a",
"single",
"white",
"space",
"."
] | 4689d8e2c1c094b2bcc85ae308c531e0b487763b | https://github.com/Swaagie/minimize/blob/4689d8e2c1c094b2bcc85ae308c531e0b487763b/lib/helpers.js#L37-L40 |
21,484 | Swaagie/minimize | lib/helpers.js | Helpers | function Helpers(options) {
this.config = {};
for (var key in options || {}) {
this.config[key] = options[key];
}
this.ancestor = [];
} | javascript | function Helpers(options) {
this.config = {};
for (var key in options || {}) {
this.config[key] = options[key];
}
this.ancestor = [];
} | [
"function",
"Helpers",
"(",
"options",
")",
"{",
"this",
".",
"config",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"key",
"in",
"options",
"||",
"{",
"}",
")",
"{",
"this",
".",
"config",
"[",
"key",
"]",
"=",
"options",
"[",
"key",
"]",
";",
"}",
"this",
".",
"ancestor",
"=",
"[",
"]",
";",
"}"
] | Helper constructor.
@Constructor
@param {Object} options
@api public | [
"Helper",
"constructor",
"."
] | 4689d8e2c1c094b2bcc85ae308c531e0b487763b | https://github.com/Swaagie/minimize/blob/4689d8e2c1c094b2bcc85ae308c531e0b487763b/lib/helpers.js#L49-L57 |
21,485 | Swaagie/minimize | lib/minimize.js | Minimize | function Minimize(parser, options) {
if ('object' !== typeof options) {
options = parser || {};
options.dom = options.dom || {};
parser = void 0;
}
this.emits = emits;
this.plugins = Object.create(null);
this.helpers = new Helpers(options);
//
// Prepare the parser.
//
this.htmlparser = parser || new html.Parser(
new html.DomHandler(this.emits('read')),
options.dom
);
//
// Register plugins.
//
this.plug(options.plugins);
} | javascript | function Minimize(parser, options) {
if ('object' !== typeof options) {
options = parser || {};
options.dom = options.dom || {};
parser = void 0;
}
this.emits = emits;
this.plugins = Object.create(null);
this.helpers = new Helpers(options);
//
// Prepare the parser.
//
this.htmlparser = parser || new html.Parser(
new html.DomHandler(this.emits('read')),
options.dom
);
//
// Register plugins.
//
this.plug(options.plugins);
} | [
"function",
"Minimize",
"(",
"parser",
",",
"options",
")",
"{",
"if",
"(",
"'object'",
"!==",
"typeof",
"options",
")",
"{",
"options",
"=",
"parser",
"||",
"{",
"}",
";",
"options",
".",
"dom",
"=",
"options",
".",
"dom",
"||",
"{",
"}",
";",
"parser",
"=",
"void",
"0",
";",
"}",
"this",
".",
"emits",
"=",
"emits",
";",
"this",
".",
"plugins",
"=",
"Object",
".",
"create",
"(",
"null",
")",
";",
"this",
".",
"helpers",
"=",
"new",
"Helpers",
"(",
"options",
")",
";",
"//",
"// Prepare the parser.",
"//",
"this",
".",
"htmlparser",
"=",
"parser",
"||",
"new",
"html",
".",
"Parser",
"(",
"new",
"html",
".",
"DomHandler",
"(",
"this",
".",
"emits",
"(",
"'read'",
")",
")",
",",
"options",
".",
"dom",
")",
";",
"//",
"// Register plugins.",
"//",
"this",
".",
"plug",
"(",
"options",
".",
"plugins",
")",
";",
"}"
] | Minimizer constructor.
@Constructor
@param {Function} parser HTMLParser2 instance, i.e. to support SVG if required.
@param {Object} options parsing options, optional
@api public | [
"Minimizer",
"constructor",
"."
] | 4689d8e2c1c094b2bcc85ae308c531e0b487763b | https://github.com/Swaagie/minimize/blob/4689d8e2c1c094b2bcc85ae308c531e0b487763b/lib/minimize.js#L23-L46 |
21,486 | Swaagie/minimize | lib/minimize.js | traverser | function traverser(element, content, next) {
return function () {
return minimize.traverse(element.children, content, sync, step(element, 'close', next))
};
} | javascript | function traverser(element, content, next) {
return function () {
return minimize.traverse(element.children, content, sync, step(element, 'close', next))
};
} | [
"function",
"traverser",
"(",
"element",
",",
"content",
",",
"next",
")",
"{",
"return",
"function",
"(",
")",
"{",
"return",
"minimize",
".",
"traverse",
"(",
"element",
".",
"children",
",",
"content",
",",
"sync",
",",
"step",
"(",
"element",
",",
"'close'",
",",
"next",
")",
")",
"}",
";",
"}"
] | For all children run same iterator.
@param {Object} element Current element
@param {String} content Current minimized HTML, memo.
@param {Function} next Completion callback.
@returns {Function} Runner.
@api private | [
"For",
"all",
"children",
"run",
"same",
"iterator",
"."
] | 4689d8e2c1c094b2bcc85ae308c531e0b487763b | https://github.com/Swaagie/minimize/blob/4689d8e2c1c094b2bcc85ae308c531e0b487763b/lib/minimize.js#L162-L166 |
21,487 | Swaagie/minimize | lib/minimize.js | step | function step(element, type, cb) {
return function generate(error, html) {
html += minimize.helpers[type](element);
return returns(error, html, cb);
}
} | javascript | function step(element, type, cb) {
return function generate(error, html) {
html += minimize.helpers[type](element);
return returns(error, html, cb);
}
} | [
"function",
"step",
"(",
"element",
",",
"type",
",",
"cb",
")",
"{",
"return",
"function",
"generate",
"(",
"error",
",",
"html",
")",
"{",
"html",
"+=",
"minimize",
".",
"helpers",
"[",
"type",
"]",
"(",
"element",
")",
";",
"return",
"returns",
"(",
"error",
",",
"html",
",",
"cb",
")",
";",
"}",
"}"
] | Minimize single level of HTML.
@param {Object} element Properties
@param {String} type Element type
@param {Function} cb Completion callback
@api private | [
"Minimize",
"single",
"level",
"of",
"HTML",
"."
] | 4689d8e2c1c094b2bcc85ae308c531e0b487763b | https://github.com/Swaagie/minimize/blob/4689d8e2c1c094b2bcc85ae308c531e0b487763b/lib/minimize.js#L176-L181 |
21,488 | Swaagie/minimize | lib/minimize.js | run | function run(element, cb) {
return function level(error, content) {
debug('Traversing children of element %s', element.name);
if (sync) {
return traverser(element, content, cb)();
}
setImmediate(traverser(element, content, cb));
}
} | javascript | function run(element, cb) {
return function level(error, content) {
debug('Traversing children of element %s', element.name);
if (sync) {
return traverser(element, content, cb)();
}
setImmediate(traverser(element, content, cb));
}
} | [
"function",
"run",
"(",
"element",
",",
"cb",
")",
"{",
"return",
"function",
"level",
"(",
"error",
",",
"content",
")",
"{",
"debug",
"(",
"'Traversing children of element %s'",
",",
"element",
".",
"name",
")",
";",
"if",
"(",
"sync",
")",
"{",
"return",
"traverser",
"(",
"element",
",",
"content",
",",
"cb",
")",
"(",
")",
";",
"}",
"setImmediate",
"(",
"traverser",
"(",
"element",
",",
"content",
",",
"cb",
")",
")",
";",
"}",
"}"
] | Traverse children of current element.
@param {Object} element Properties
@param {Function} cb Completion callback
@api private | [
"Traverse",
"children",
"of",
"current",
"element",
"."
] | 4689d8e2c1c094b2bcc85ae308c531e0b487763b | https://github.com/Swaagie/minimize/blob/4689d8e2c1c094b2bcc85ae308c531e0b487763b/lib/minimize.js#L190-L200 |
21,489 | Swaagie/minimize | lib/minimize.js | createPlug | function createPlug(element) {
return function plug(plugin, fn) {
fn = fn || minimize.emits('plugin');
debug('Running plugin for element %s', element.name);
minimize.plugins[plugin].element.call(minimize, element, fn);
}
} | javascript | function createPlug(element) {
return function plug(plugin, fn) {
fn = fn || minimize.emits('plugin');
debug('Running plugin for element %s', element.name);
minimize.plugins[plugin].element.call(minimize, element, fn);
}
} | [
"function",
"createPlug",
"(",
"element",
")",
"{",
"return",
"function",
"plug",
"(",
"plugin",
",",
"fn",
")",
"{",
"fn",
"=",
"fn",
"||",
"minimize",
".",
"emits",
"(",
"'plugin'",
")",
";",
"debug",
"(",
"'Running plugin for element %s'",
",",
"element",
".",
"name",
")",
";",
"minimize",
".",
"plugins",
"[",
"plugin",
"]",
".",
"element",
".",
"call",
"(",
"minimize",
",",
"element",
",",
"fn",
")",
";",
"}",
"}"
] | Create plugins for element.
@param {Object} element Properties.
@return {Function} Plugin function to run.
@api private | [
"Create",
"plugins",
"for",
"element",
"."
] | 4689d8e2c1c094b2bcc85ae308c531e0b487763b | https://github.com/Swaagie/minimize/blob/4689d8e2c1c094b2bcc85ae308c531e0b487763b/lib/minimize.js#L222-L229 |
21,490 | Swaagie/minimize | lib/minimize.js | reduce | function reduce(html, element, next) {
//
// Run the registered plugins before the element is processed.
// Note that the plugins are not run in order.
//
if (sync) {
plugins.forEach(createPlug(element));
return open(element, html, run(element, next));
}
async.eachSeries(plugins, createPlug(element), function finished(error) {
if (error) return next(error);
return open(element, html, run(element, next));
});
} | javascript | function reduce(html, element, next) {
//
// Run the registered plugins before the element is processed.
// Note that the plugins are not run in order.
//
if (sync) {
plugins.forEach(createPlug(element));
return open(element, html, run(element, next));
}
async.eachSeries(plugins, createPlug(element), function finished(error) {
if (error) return next(error);
return open(element, html, run(element, next));
});
} | [
"function",
"reduce",
"(",
"html",
",",
"element",
",",
"next",
")",
"{",
"//",
"// Run the registered plugins before the element is processed.",
"// Note that the plugins are not run in order.",
"//",
"if",
"(",
"sync",
")",
"{",
"plugins",
".",
"forEach",
"(",
"createPlug",
"(",
"element",
")",
")",
";",
"return",
"open",
"(",
"element",
",",
"html",
",",
"run",
"(",
"element",
",",
"next",
")",
")",
";",
"}",
"async",
".",
"eachSeries",
"(",
"plugins",
",",
"createPlug",
"(",
"element",
")",
",",
"function",
"finished",
"(",
"error",
")",
"{",
"if",
"(",
"error",
")",
"return",
"next",
"(",
"error",
")",
";",
"return",
"open",
"(",
"element",
",",
"html",
",",
"run",
"(",
"element",
",",
"next",
")",
")",
";",
"}",
")",
";",
"}"
] | Reduce each HTML element and its children.
@param {String} html Current compiled HTML, memo.
@param {Object} element Current element.
@param {Function} step Completion callback
@returns {String} minimized HTML.
@api private | [
"Reduce",
"each",
"HTML",
"element",
"and",
"its",
"children",
"."
] | 4689d8e2c1c094b2bcc85ae308c531e0b487763b | https://github.com/Swaagie/minimize/blob/4689d8e2c1c094b2bcc85ae308c531e0b487763b/lib/minimize.js#L240-L254 |
21,491 | words/lancaster-stemmer | index.js | acceptable | function acceptable(value) {
return vowels.test(value.charAt(0))
? value.length > 1
: value.length > 2 && vowels.test(value)
} | javascript | function acceptable(value) {
return vowels.test(value.charAt(0))
? value.length > 1
: value.length > 2 && vowels.test(value)
} | [
"function",
"acceptable",
"(",
"value",
")",
"{",
"return",
"vowels",
".",
"test",
"(",
"value",
".",
"charAt",
"(",
"0",
")",
")",
"?",
"value",
".",
"length",
">",
"1",
":",
"value",
".",
"length",
">",
"2",
"&&",
"vowels",
".",
"test",
"(",
"value",
")",
"}"
] | Detect if a value is acceptable to return, or should be stemmed further. | [
"Detect",
"if",
"a",
"value",
"is",
"acceptable",
"to",
"return",
"or",
"should",
"be",
"stemmed",
"further",
"."
] | 3f29d76aa887b5ecbe88ea7a8a4eadab9b569c34 | https://github.com/words/lancaster-stemmer/blob/3f29d76aa887b5ecbe88ea7a8a4eadab9b569c34/index.js#L221-L225 |
21,492 | tymondesigns/angular-locker | dist/angular-locker.js | function (value) {
if (! _defined(value)) return defaults;
angular.forEach(value, function (val, key) {
if (defaults.hasOwnProperty(key)) defaults[key] = val;
});
} | javascript | function (value) {
if (! _defined(value)) return defaults;
angular.forEach(value, function (val, key) {
if (defaults.hasOwnProperty(key)) defaults[key] = val;
});
} | [
"function",
"(",
"value",
")",
"{",
"if",
"(",
"!",
"_defined",
"(",
"value",
")",
")",
"return",
"defaults",
";",
"angular",
".",
"forEach",
"(",
"value",
",",
"function",
"(",
"val",
",",
"key",
")",
"{",
"if",
"(",
"defaults",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"defaults",
"[",
"key",
"]",
"=",
"val",
";",
"}",
")",
";",
"}"
] | Allow the defaults to be specified via the `lockerProvider`
@param {Object} value The defaults to override | [
"Allow",
"the",
"defaults",
"to",
"be",
"specified",
"via",
"the",
"lockerProvider"
] | 8e92915a1baddfb07d15676f73a900fdb8417cab | https://github.com/tymondesigns/angular-locker/blob/8e92915a1baddfb07d15676f73a900fdb8417cab/dist/angular-locker.js#L90-L96 | |
21,493 | tymondesigns/angular-locker | dist/angular-locker.js | function (key, value, def) {
if (! this.has(key)) {
this.put(key, value, def);
return true;
}
return false;
} | javascript | function (key, value, def) {
if (! this.has(key)) {
this.put(key, value, def);
return true;
}
return false;
} | [
"function",
"(",
"key",
",",
"value",
",",
"def",
")",
"{",
"if",
"(",
"!",
"this",
".",
"has",
"(",
"key",
")",
")",
"{",
"this",
".",
"put",
"(",
"key",
",",
"value",
",",
"def",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Add an item to storage if it doesn't already exist
@public
@param {Mixed} key The key to add
@param {Mixed} value The value to add
@param {Mixed} def The default to pass to function if doesn't already exist
@return {Boolean} | [
"Add",
"an",
"item",
"to",
"storage",
"if",
"it",
"doesn",
"t",
"already",
"exist"
] | 8e92915a1baddfb07d15676f73a900fdb8417cab | https://github.com/tymondesigns/angular-locker/blob/8e92915a1baddfb07d15676f73a900fdb8417cab/dist/angular-locker.js#L420-L427 | |
21,494 | tymondesigns/angular-locker | dist/angular-locker.js | function (key, def) {
if (angular.isArray(key)) {
var items = {};
angular.forEach(key, function (k) {
if (this.has(k)) items[k] = this._getItem(k);
}, this);
return items;
}
if (! this.has(key)) return arguments.length === 2 ? def : void 0;
return this._getItem(key);
} | javascript | function (key, def) {
if (angular.isArray(key)) {
var items = {};
angular.forEach(key, function (k) {
if (this.has(k)) items[k] = this._getItem(k);
}, this);
return items;
}
if (! this.has(key)) return arguments.length === 2 ? def : void 0;
return this._getItem(key);
} | [
"function",
"(",
"key",
",",
"def",
")",
"{",
"if",
"(",
"angular",
".",
"isArray",
"(",
"key",
")",
")",
"{",
"var",
"items",
"=",
"{",
"}",
";",
"angular",
".",
"forEach",
"(",
"key",
",",
"function",
"(",
"k",
")",
"{",
"if",
"(",
"this",
".",
"has",
"(",
"k",
")",
")",
"items",
"[",
"k",
"]",
"=",
"this",
".",
"_getItem",
"(",
"k",
")",
";",
"}",
",",
"this",
")",
";",
"return",
"items",
";",
"}",
"if",
"(",
"!",
"this",
".",
"has",
"(",
"key",
")",
")",
"return",
"arguments",
".",
"length",
"===",
"2",
"?",
"def",
":",
"void",
"0",
";",
"return",
"this",
".",
"_getItem",
"(",
"key",
")",
";",
"}"
] | Retrieve the specified item from storage
@public
@param {String|Array} key The key to get
@param {Mixed} def The default value if it does not exist
@return {Mixed} | [
"Retrieve",
"the",
"specified",
"item",
"from",
"storage"
] | 8e92915a1baddfb07d15676f73a900fdb8417cab | https://github.com/tymondesigns/angular-locker/blob/8e92915a1baddfb07d15676f73a900fdb8417cab/dist/angular-locker.js#L439-L452 | |
21,495 | STRML/JSXHint | jsxhint.js | transformJSX | function transformJSX(fileStream, fileName, opts, cb){
// Allow omitting filename
if (typeof fileName === "object"){
cb = opts;
opts = fileName;
fileName = fileStream;
}
if (!babel && (opts['--babel'] || opts['--babel-experimental'])) {
throw new Error("Optional babel parser not installed. Please `npm install [-g] babel-core`.");
}
// Allow passing strings into this method e.g. when using it as a lib
if (typeof fileStream === "string"){
fileStream = fs.createReadStream(fileStream, {encoding: "utf8"});
}
return utils.drainStream(fileStream)
.then(function processFile(source) {
var hasExtension = /\.jsx$/.exec(fileName) || fileName === "stdin";
// console.error('has extension', hasExtension);
// console.log(fileName);
if ((opts['--jsx-only'] && hasExtension) || !opts['--jsx-only']) {
try {
return transformSource(source, opts);
} catch(e) {
// Seems that esprima has some problems with some js syntax.
if (opts['--transform-errors'] === 'always' ||
(opts['--transform-errors'] !== 'never' && hasExtension)) {
console.error("Error while transforming file " + fileName + "\n", e.stack);
throw utils.transformError(fileName, e, opts);
}
}
}
return source;
})
.nodeify(cb);
} | javascript | function transformJSX(fileStream, fileName, opts, cb){
// Allow omitting filename
if (typeof fileName === "object"){
cb = opts;
opts = fileName;
fileName = fileStream;
}
if (!babel && (opts['--babel'] || opts['--babel-experimental'])) {
throw new Error("Optional babel parser not installed. Please `npm install [-g] babel-core`.");
}
// Allow passing strings into this method e.g. when using it as a lib
if (typeof fileStream === "string"){
fileStream = fs.createReadStream(fileStream, {encoding: "utf8"});
}
return utils.drainStream(fileStream)
.then(function processFile(source) {
var hasExtension = /\.jsx$/.exec(fileName) || fileName === "stdin";
// console.error('has extension', hasExtension);
// console.log(fileName);
if ((opts['--jsx-only'] && hasExtension) || !opts['--jsx-only']) {
try {
return transformSource(source, opts);
} catch(e) {
// Seems that esprima has some problems with some js syntax.
if (opts['--transform-errors'] === 'always' ||
(opts['--transform-errors'] !== 'never' && hasExtension)) {
console.error("Error while transforming file " + fileName + "\n", e.stack);
throw utils.transformError(fileName, e, opts);
}
}
}
return source;
})
.nodeify(cb);
} | [
"function",
"transformJSX",
"(",
"fileStream",
",",
"fileName",
",",
"opts",
",",
"cb",
")",
"{",
"// Allow omitting filename",
"if",
"(",
"typeof",
"fileName",
"===",
"\"object\"",
")",
"{",
"cb",
"=",
"opts",
";",
"opts",
"=",
"fileName",
";",
"fileName",
"=",
"fileStream",
";",
"}",
"if",
"(",
"!",
"babel",
"&&",
"(",
"opts",
"[",
"'--babel'",
"]",
"||",
"opts",
"[",
"'--babel-experimental'",
"]",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Optional babel parser not installed. Please `npm install [-g] babel-core`.\"",
")",
";",
"}",
"// Allow passing strings into this method e.g. when using it as a lib",
"if",
"(",
"typeof",
"fileStream",
"===",
"\"string\"",
")",
"{",
"fileStream",
"=",
"fs",
".",
"createReadStream",
"(",
"fileStream",
",",
"{",
"encoding",
":",
"\"utf8\"",
"}",
")",
";",
"}",
"return",
"utils",
".",
"drainStream",
"(",
"fileStream",
")",
".",
"then",
"(",
"function",
"processFile",
"(",
"source",
")",
"{",
"var",
"hasExtension",
"=",
"/",
"\\.jsx$",
"/",
".",
"exec",
"(",
"fileName",
")",
"||",
"fileName",
"===",
"\"stdin\"",
";",
"// console.error('has extension', hasExtension);",
"// console.log(fileName);",
"if",
"(",
"(",
"opts",
"[",
"'--jsx-only'",
"]",
"&&",
"hasExtension",
")",
"||",
"!",
"opts",
"[",
"'--jsx-only'",
"]",
")",
"{",
"try",
"{",
"return",
"transformSource",
"(",
"source",
",",
"opts",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"// Seems that esprima has some problems with some js syntax.",
"if",
"(",
"opts",
"[",
"'--transform-errors'",
"]",
"===",
"'always'",
"||",
"(",
"opts",
"[",
"'--transform-errors'",
"]",
"!==",
"'never'",
"&&",
"hasExtension",
")",
")",
"{",
"console",
".",
"error",
"(",
"\"Error while transforming file \"",
"+",
"fileName",
"+",
"\"\\n\"",
",",
"e",
".",
"stack",
")",
";",
"throw",
"utils",
".",
"transformError",
"(",
"fileName",
",",
"e",
",",
"opts",
")",
";",
"}",
"}",
"}",
"return",
"source",
";",
"}",
")",
".",
"nodeify",
"(",
"cb",
")",
";",
"}"
] | Transform a JSX file into a JS file for linting.
@async
@param {String} fileStream Readable stream containing file contents.
@param {String} fileName Name of the file; "stdin" if reading from stdio.
@param {Object} opts Options.
@param {Function} cb The callback to call when it's ready. | [
"Transform",
"a",
"JSX",
"file",
"into",
"a",
"JS",
"file",
"for",
"linting",
"."
] | 52dd5299903a4fc9d733da9c2e568f8de1c10c5d | https://github.com/STRML/JSXHint/blob/52dd5299903a4fc9d733da9c2e568f8de1c10c5d/jsxhint.js#L34-L72 |
21,496 | STRML/JSXHint | cli.js | showHelp | function showHelp(){
var jshint_proc = fork(require.resolve('jshint/bin/jshint'), ['-h'], {silent: true});
var ts = through(function write(chunk){
this.queue(chunk.toString().replace(/(jshint)\b/g, 'jsxhint'));
}, function end() {
// This feels like a hack. There might be a better way to do this.
this.queue('\nThe above options are native to JSHint, which JSXHint extends.\n');
this.queue('\x1b[1m'); // bold
this.queue('\nJSXHint Options:\n');
this.queue('\x1b[0m');
this.queue(' --jsx-only Only transform files with the .jsx extension.\n' +
' Will run somewhat faster.\n');
this.queue(' --babel Use babel (6to5) instead of react esprima.\n' +
' Useful if you are using es6-module, etc. You must \n' +
' install the module `babel` manually with npm.\n');
this.queue(' --babel-experimental Use babel with experimental support for ES7.\n' +
' Useful if you are using es7-async, etc.\n');
this.queue(' --harmony Use react esprima with ES6 transformation support.\n' +
' Useful if you are using both es6-class and react.\n');
this.queue(' --es6module Pass the --es6module flag to react tools.\n');
this.queue(' --non-strict-es6module Pass this flag to react tools.\n');
this.queue(' --transform-errors STRING Whether to fail on transform errors.\n' +
' Valid: always, jsx, never (default: jsx)');
});
jshint_proc.stderr.pipe(ts).pipe(process.stderr);
} | javascript | function showHelp(){
var jshint_proc = fork(require.resolve('jshint/bin/jshint'), ['-h'], {silent: true});
var ts = through(function write(chunk){
this.queue(chunk.toString().replace(/(jshint)\b/g, 'jsxhint'));
}, function end() {
// This feels like a hack. There might be a better way to do this.
this.queue('\nThe above options are native to JSHint, which JSXHint extends.\n');
this.queue('\x1b[1m'); // bold
this.queue('\nJSXHint Options:\n');
this.queue('\x1b[0m');
this.queue(' --jsx-only Only transform files with the .jsx extension.\n' +
' Will run somewhat faster.\n');
this.queue(' --babel Use babel (6to5) instead of react esprima.\n' +
' Useful if you are using es6-module, etc. You must \n' +
' install the module `babel` manually with npm.\n');
this.queue(' --babel-experimental Use babel with experimental support for ES7.\n' +
' Useful if you are using es7-async, etc.\n');
this.queue(' --harmony Use react esprima with ES6 transformation support.\n' +
' Useful if you are using both es6-class and react.\n');
this.queue(' --es6module Pass the --es6module flag to react tools.\n');
this.queue(' --non-strict-es6module Pass this flag to react tools.\n');
this.queue(' --transform-errors STRING Whether to fail on transform errors.\n' +
' Valid: always, jsx, never (default: jsx)');
});
jshint_proc.stderr.pipe(ts).pipe(process.stderr);
} | [
"function",
"showHelp",
"(",
")",
"{",
"var",
"jshint_proc",
"=",
"fork",
"(",
"require",
".",
"resolve",
"(",
"'jshint/bin/jshint'",
")",
",",
"[",
"'-h'",
"]",
",",
"{",
"silent",
":",
"true",
"}",
")",
";",
"var",
"ts",
"=",
"through",
"(",
"function",
"write",
"(",
"chunk",
")",
"{",
"this",
".",
"queue",
"(",
"chunk",
".",
"toString",
"(",
")",
".",
"replace",
"(",
"/",
"(jshint)\\b",
"/",
"g",
",",
"'jsxhint'",
")",
")",
";",
"}",
",",
"function",
"end",
"(",
")",
"{",
"// This feels like a hack. There might be a better way to do this.",
"this",
".",
"queue",
"(",
"'\\nThe above options are native to JSHint, which JSXHint extends.\\n'",
")",
";",
"this",
".",
"queue",
"(",
"'\\x1b[1m'",
")",
";",
"// bold",
"this",
".",
"queue",
"(",
"'\\nJSXHint Options:\\n'",
")",
";",
"this",
".",
"queue",
"(",
"'\\x1b[0m'",
")",
";",
"this",
".",
"queue",
"(",
"' --jsx-only Only transform files with the .jsx extension.\\n'",
"+",
"' Will run somewhat faster.\\n'",
")",
";",
"this",
".",
"queue",
"(",
"' --babel Use babel (6to5) instead of react esprima.\\n'",
"+",
"' Useful if you are using es6-module, etc. You must \\n'",
"+",
"' install the module `babel` manually with npm.\\n'",
")",
";",
"this",
".",
"queue",
"(",
"' --babel-experimental Use babel with experimental support for ES7.\\n'",
"+",
"' Useful if you are using es7-async, etc.\\n'",
")",
";",
"this",
".",
"queue",
"(",
"' --harmony Use react esprima with ES6 transformation support.\\n'",
"+",
"' Useful if you are using both es6-class and react.\\n'",
")",
";",
"this",
".",
"queue",
"(",
"' --es6module Pass the --es6module flag to react tools.\\n'",
")",
";",
"this",
".",
"queue",
"(",
"' --non-strict-es6module Pass this flag to react tools.\\n'",
")",
";",
"this",
".",
"queue",
"(",
"' --transform-errors STRING Whether to fail on transform errors.\\n'",
"+",
"' Valid: always, jsx, never (default: jsx)'",
")",
";",
"}",
")",
";",
"jshint_proc",
".",
"stderr",
".",
"pipe",
"(",
"ts",
")",
".",
"pipe",
"(",
"process",
".",
"stderr",
")",
";",
"}"
] | Intercept -h to show jshint help. | [
"Intercept",
"-",
"h",
"to",
"show",
"jshint",
"help",
"."
] | 52dd5299903a4fc9d733da9c2e568f8de1c10c5d | https://github.com/STRML/JSXHint/blob/52dd5299903a4fc9d733da9c2e568f8de1c10c5d/cli.js#L44-L69 |
21,497 | STRML/JSXHint | cli.js | showVersion | function showVersion(){
var jshint_proc = fork(__dirname + '/node_modules/jshint/bin/jshint', ['-v'], {silent: true});
var ts = through(function write(chunk){
this.queue("JSXHint v" + require('./package.json').version + " (" +
chunk.toString().replace("\n", "") + ")\n");
});
jshint_proc.stderr.pipe(ts).pipe(process.stderr);
} | javascript | function showVersion(){
var jshint_proc = fork(__dirname + '/node_modules/jshint/bin/jshint', ['-v'], {silent: true});
var ts = through(function write(chunk){
this.queue("JSXHint v" + require('./package.json').version + " (" +
chunk.toString().replace("\n", "") + ")\n");
});
jshint_proc.stderr.pipe(ts).pipe(process.stderr);
} | [
"function",
"showVersion",
"(",
")",
"{",
"var",
"jshint_proc",
"=",
"fork",
"(",
"__dirname",
"+",
"'/node_modules/jshint/bin/jshint'",
",",
"[",
"'-v'",
"]",
",",
"{",
"silent",
":",
"true",
"}",
")",
";",
"var",
"ts",
"=",
"through",
"(",
"function",
"write",
"(",
"chunk",
")",
"{",
"this",
".",
"queue",
"(",
"\"JSXHint v\"",
"+",
"require",
"(",
"'./package.json'",
")",
".",
"version",
"+",
"\" (\"",
"+",
"chunk",
".",
"toString",
"(",
")",
".",
"replace",
"(",
"\"\\n\"",
",",
"\"\"",
")",
"+",
"\")\\n\"",
")",
";",
"}",
")",
";",
"jshint_proc",
".",
"stderr",
".",
"pipe",
"(",
"ts",
")",
".",
"pipe",
"(",
"process",
".",
"stderr",
")",
";",
"}"
] | Intercept -v, shows jsxhint and jshint versions. | [
"Intercept",
"-",
"v",
"shows",
"jsxhint",
"and",
"jshint",
"versions",
"."
] | 52dd5299903a4fc9d733da9c2e568f8de1c10c5d | https://github.com/STRML/JSXHint/blob/52dd5299903a4fc9d733da9c2e568f8de1c10c5d/cli.js#L74-L81 |
21,498 | STRML/JSXHint | cli.js | runGlob | function runGlob(args, opts, cb) {
var dotIdx = args.indexOf('.');
if (dotIdx !== -1) {
args.splice(dotIdx, 1);
}
glob(args, opts, function(err, globbed) {
if (Array.isArray(globbed) && dotIdx !== -1) globbed.push('.');
cb(err, globbed);
});
} | javascript | function runGlob(args, opts, cb) {
var dotIdx = args.indexOf('.');
if (dotIdx !== -1) {
args.splice(dotIdx, 1);
}
glob(args, opts, function(err, globbed) {
if (Array.isArray(globbed) && dotIdx !== -1) globbed.push('.');
cb(err, globbed);
});
} | [
"function",
"runGlob",
"(",
"args",
",",
"opts",
",",
"cb",
")",
"{",
"var",
"dotIdx",
"=",
"args",
".",
"indexOf",
"(",
"'.'",
")",
";",
"if",
"(",
"dotIdx",
"!==",
"-",
"1",
")",
"{",
"args",
".",
"splice",
"(",
"dotIdx",
",",
"1",
")",
";",
"}",
"glob",
"(",
"args",
",",
"opts",
",",
"function",
"(",
"err",
",",
"globbed",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"globbed",
")",
"&&",
"dotIdx",
"!==",
"-",
"1",
")",
"globbed",
".",
"push",
"(",
"'.'",
")",
";",
"cb",
"(",
"err",
",",
"globbed",
")",
";",
"}",
")",
";",
"}"
] | Wrapper around globbing function. Ignores '.' which has special meaning in jshint.
@param {Array} args File/glob list.
@param {Object} opts Glob options.
@param {Function} cb Callback. | [
"Wrapper",
"around",
"globbing",
"function",
".",
"Ignores",
".",
"which",
"has",
"special",
"meaning",
"in",
"jshint",
"."
] | 52dd5299903a4fc9d733da9c2e568f8de1c10c5d | https://github.com/STRML/JSXHint/blob/52dd5299903a4fc9d733da9c2e568f8de1c10c5d/cli.js#L89-L98 |
21,499 | STRML/JSXHint | cli.js | run | function run(opts, cb){
opts.extensions = opts.extensions ? opts.extensions + ',.jsx' : '.jsx';
// glob-all fixes windows glob issues and provides array support
// i.e. jsxhint ['jsx/**/*','!scripts/**/*','scripts/outlier.jsx']
runGlob(opts.args, {nodir: true}, function(err, globbed) {
if (err) return cb(err);
// Reassign the globbed files back to opts.args, so it looks like we just
// fed jshint a big list of files.
opts.args = globbed;
var files = jshintcli.gather(opts);
if (opts.useStdin) {
jsxhint.transformStream(process.stdin, jsxhintOptions, opts, cb);
} else {
jsxhint.transformFiles(files, jsxhintOptions, opts, cb);
}
});
} | javascript | function run(opts, cb){
opts.extensions = opts.extensions ? opts.extensions + ',.jsx' : '.jsx';
// glob-all fixes windows glob issues and provides array support
// i.e. jsxhint ['jsx/**/*','!scripts/**/*','scripts/outlier.jsx']
runGlob(opts.args, {nodir: true}, function(err, globbed) {
if (err) return cb(err);
// Reassign the globbed files back to opts.args, so it looks like we just
// fed jshint a big list of files.
opts.args = globbed;
var files = jshintcli.gather(opts);
if (opts.useStdin) {
jsxhint.transformStream(process.stdin, jsxhintOptions, opts, cb);
} else {
jsxhint.transformFiles(files, jsxhintOptions, opts, cb);
}
});
} | [
"function",
"run",
"(",
"opts",
",",
"cb",
")",
"{",
"opts",
".",
"extensions",
"=",
"opts",
".",
"extensions",
"?",
"opts",
".",
"extensions",
"+",
"',.jsx'",
":",
"'.jsx'",
";",
"// glob-all fixes windows glob issues and provides array support",
"// i.e. jsxhint ['jsx/**/*','!scripts/**/*','scripts/outlier.jsx']",
"runGlob",
"(",
"opts",
".",
"args",
",",
"{",
"nodir",
":",
"true",
"}",
",",
"function",
"(",
"err",
",",
"globbed",
")",
"{",
"if",
"(",
"err",
")",
"return",
"cb",
"(",
"err",
")",
";",
"// Reassign the globbed files back to opts.args, so it looks like we just",
"// fed jshint a big list of files.",
"opts",
".",
"args",
"=",
"globbed",
";",
"var",
"files",
"=",
"jshintcli",
".",
"gather",
"(",
"opts",
")",
";",
"if",
"(",
"opts",
".",
"useStdin",
")",
"{",
"jsxhint",
".",
"transformStream",
"(",
"process",
".",
"stdin",
",",
"jsxhintOptions",
",",
"opts",
",",
"cb",
")",
";",
"}",
"else",
"{",
"jsxhint",
".",
"transformFiles",
"(",
"files",
",",
"jsxhintOptions",
",",
"opts",
",",
"cb",
")",
";",
"}",
"}",
")",
";",
"}"
] | Proxy run function. Reaches out to jsxhint to transform
incoming stream or read files & transform.
@param {Object} opts Opts as created by JSHint.
@param {Function} cb Callback. | [
"Proxy",
"run",
"function",
".",
"Reaches",
"out",
"to",
"jsxhint",
"to",
"transform",
"incoming",
"stream",
"or",
"read",
"files",
"&",
"transform",
"."
] | 52dd5299903a4fc9d733da9c2e568f8de1c10c5d | https://github.com/STRML/JSXHint/blob/52dd5299903a4fc9d733da9c2e568f8de1c10c5d/cli.js#L106-L125 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.