repo stringlengths 5 67 | path stringlengths 4 116 | func_name stringlengths 0 58 | original_string stringlengths 52 373k | language stringclasses 1
value | code stringlengths 52 373k | code_tokens list | docstring stringlengths 4 11.8k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 86 226 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
eventbrite/britecharts | src/charts/legend.js | fadeLinesBut | function fadeLinesBut(exceptionItemId) {
let classToFade = 'g.legend-entry';
let entryLine = svg.select(`[data-item="${exceptionItemId}"]`);
if (entryLine.nodes().length){
svg.select('.legend-group')
.selectAll(classToFade)
.cl... | javascript | function fadeLinesBut(exceptionItemId) {
let classToFade = 'g.legend-entry';
let entryLine = svg.select(`[data-item="${exceptionItemId}"]`);
if (entryLine.nodes().length){
svg.select('.legend-group')
.selectAll(classToFade)
.cl... | [
"function",
"fadeLinesBut",
"(",
"exceptionItemId",
")",
"{",
"let",
"classToFade",
"=",
"'g.legend-entry'",
";",
"let",
"entryLine",
"=",
"svg",
".",
"select",
"(",
"`",
"${",
"exceptionItemId",
"}",
"`",
")",
";",
"if",
"(",
"entryLine",
".",
"nodes",
"(... | Applies the faded class to all lines but the one that has the given id
@param {number} exceptionItemId Id of the line that needs to stay the same
@private | [
"Applies",
"the",
"faded",
"class",
"to",
"all",
"lines",
"but",
"the",
"one",
"that",
"has",
"the",
"given",
"id"
] | 0767051287e9e7211e610b1b13244da71e8e355e | https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/legend.js#L395-L406 | train |
eventbrite/britecharts | src/charts/legend.js | splitInLines | function splitInLines() {
let legendEntries = svg.selectAll('.legend-entry');
let numberOfEntries = legendEntries.size();
let lineHeight = (chartHeight / 2) * 1.7;
let newLine = svg.select('.legend-group')
.append('g')
.classed('legend-line',... | javascript | function splitInLines() {
let legendEntries = svg.selectAll('.legend-entry');
let numberOfEntries = legendEntries.size();
let lineHeight = (chartHeight / 2) * 1.7;
let newLine = svg.select('.legend-group')
.append('g')
.classed('legend-line',... | [
"function",
"splitInLines",
"(",
")",
"{",
"let",
"legendEntries",
"=",
"svg",
".",
"selectAll",
"(",
"'.legend-entry'",
")",
";",
"let",
"numberOfEntries",
"=",
"legendEntries",
".",
"size",
"(",
")",
";",
"let",
"lineHeight",
"=",
"(",
"chartHeight",
"/",
... | Simple method to move the last item of an overflowing legend into the next line
@return {void}
@private | [
"Simple",
"method",
"to",
"move",
"the",
"last",
"item",
"of",
"an",
"overflowing",
"legend",
"into",
"the",
"next",
"line"
] | 0767051287e9e7211e610b1b13244da71e8e355e | https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/legend.js#L422-L434 | train |
eventbrite/britecharts | src/charts/legend.js | writeEntryValues | function writeEntryValues() {
svg.select('.legend-group')
.selectAll('g.legend-line')
.selectAll('g.legend-entry')
.append('text')
.classed('legend-entry-value', true)
.text(getFormattedQuantity)
.attr('x', chartWi... | javascript | function writeEntryValues() {
svg.select('.legend-group')
.selectAll('g.legend-line')
.selectAll('g.legend-entry')
.append('text')
.classed('legend-entry-value', true)
.text(getFormattedQuantity)
.attr('x', chartWi... | [
"function",
"writeEntryValues",
"(",
")",
"{",
"svg",
".",
"select",
"(",
"'.legend-group'",
")",
".",
"selectAll",
"(",
"'g.legend-line'",
")",
".",
"selectAll",
"(",
"'g.legend-entry'",
")",
".",
"append",
"(",
"'text'",
")",
".",
"classed",
"(",
"'legend-... | Draws the data entry quantities within the legend-entry lines
@return {void}
@private | [
"Draws",
"the",
"data",
"entry",
"quantities",
"within",
"the",
"legend",
"-",
"entry",
"lines"
] | 0767051287e9e7211e610b1b13244da71e8e355e | https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/legend.js#L441-L453 | train |
eventbrite/britecharts | src/charts/line.js | cleanData | function cleanData({dataByTopic, dataByDate, data}) {
if (!dataByTopic && !data) {
throw new Error('Data needs to have a dataByTopic or data property. See more in http://eventbrite.github.io/britecharts/global.html#LineChartData__anchor');
}
// If dataByTopic or data... | javascript | function cleanData({dataByTopic, dataByDate, data}) {
if (!dataByTopic && !data) {
throw new Error('Data needs to have a dataByTopic or data property. See more in http://eventbrite.github.io/britecharts/global.html#LineChartData__anchor');
}
// If dataByTopic or data... | [
"function",
"cleanData",
"(",
"{",
"dataByTopic",
",",
"dataByDate",
",",
"data",
"}",
")",
"{",
"if",
"(",
"!",
"dataByTopic",
"&&",
"!",
"data",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Data needs to have a dataByTopic or data property. See more in http://eventbr... | Parses dates and values into JS Date objects and numbers
@param {obj} dataByTopic Raw data grouped by topic
@return {obj} Parsed data with dataByTopic and dataByDate | [
"Parses",
"dates",
"and",
"values",
"into",
"JS",
"Date",
"objects",
"and",
"numbers"
] | 0767051287e9e7211e610b1b13244da71e8e355e | https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/line.js#L548-L607 | train |
eventbrite/britecharts | src/charts/line.js | drawAxis | function drawAxis(){
svg.select('.x-axis-group .axis.x')
.attr('transform', `translate(0, ${chartHeight})`)
.call(xAxis);
if (xAxisFormat !== 'custom') {
svg.select('.x-axis-group .month-axis')
.attr('transform', `translate(0, ... | javascript | function drawAxis(){
svg.select('.x-axis-group .axis.x')
.attr('transform', `translate(0, ${chartHeight})`)
.call(xAxis);
if (xAxisFormat !== 'custom') {
svg.select('.x-axis-group .month-axis')
.attr('transform', `translate(0, ... | [
"function",
"drawAxis",
"(",
")",
"{",
"svg",
".",
"select",
"(",
"'.x-axis-group .axis.x'",
")",
".",
"attr",
"(",
"'transform'",
",",
"`",
"${",
"chartHeight",
"}",
"`",
")",
".",
"call",
"(",
"xAxis",
")",
";",
"if",
"(",
"xAxisFormat",
"!==",
"'cus... | Draws the x and y axis on the svg object within their
respective groups along with the axis labels if given
@private | [
"Draws",
"the",
"x",
"and",
"y",
"axis",
"on",
"the",
"svg",
"object",
"within",
"their",
"respective",
"groups",
"along",
"with",
"the",
"axis",
"labels",
"if",
"given"
] | 0767051287e9e7211e610b1b13244da71e8e355e | https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/line.js#L646-L695 | train |
eventbrite/britecharts | src/charts/line.js | drawLines | function drawLines(){
let lines,
topicLine;
topicLine = d3Shape.line()
.curve(curveMap[lineCurve])
.x(({date}) => xScale(date))
.y(({value}) => yScale(value));
lines = svg.select('.chart-group').selectAll('.line')
... | javascript | function drawLines(){
let lines,
topicLine;
topicLine = d3Shape.line()
.curve(curveMap[lineCurve])
.x(({date}) => xScale(date))
.y(({value}) => yScale(value));
lines = svg.select('.chart-group').selectAll('.line')
... | [
"function",
"drawLines",
"(",
")",
"{",
"let",
"lines",
",",
"topicLine",
";",
"topicLine",
"=",
"d3Shape",
".",
"line",
"(",
")",
".",
"curve",
"(",
"curveMap",
"[",
"lineCurve",
"]",
")",
".",
"x",
"(",
"(",
"{",
"date",
"}",
")",
"=>",
"xScale",... | Draws the line elements within the chart group
@private | [
"Draws",
"the",
"line",
"elements",
"within",
"the",
"chart",
"group"
] | 0767051287e9e7211e610b1b13244da71e8e355e | https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/line.js#L701-L728 | train |
eventbrite/britecharts | src/charts/line.js | drawAllDataPoints | function drawAllDataPoints() {
svg.select('.chart-group')
.selectAll('.data-points-container')
.remove();
const nodesById = paths.nodes().reduce((acc, node) => {
acc[node.id] = node
return acc;
}, {});
co... | javascript | function drawAllDataPoints() {
svg.select('.chart-group')
.selectAll('.data-points-container')
.remove();
const nodesById = paths.nodes().reduce((acc, node) => {
acc[node.id] = node
return acc;
}, {});
co... | [
"function",
"drawAllDataPoints",
"(",
")",
"{",
"svg",
".",
"select",
"(",
"'.chart-group'",
")",
".",
"selectAll",
"(",
"'.data-points-container'",
")",
".",
"remove",
"(",
")",
";",
"const",
"nodesById",
"=",
"paths",
".",
"nodes",
"(",
")",
".",
"reduce... | Draws all data points of the chart
if shouldShowAllDataPoints is set to true
@private
@return void | [
"Draws",
"all",
"data",
"points",
"of",
"the",
"chart",
"if",
"shouldShowAllDataPoints",
"is",
"set",
"to",
"true"
] | 0767051287e9e7211e610b1b13244da71e8e355e | https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/line.js#L803-L840 | train |
eventbrite/britecharts | src/charts/line.js | findOutNearestDate | function findOutNearestDate(x0, d0, d1){
return (new Date(x0).getTime() - new Date(d0.date).getTime()) > (new Date(d1.date).getTime() - new Date(x0).getTime()) ? d0 : d1;
} | javascript | function findOutNearestDate(x0, d0, d1){
return (new Date(x0).getTime() - new Date(d0.date).getTime()) > (new Date(d1.date).getTime() - new Date(x0).getTime()) ? d0 : d1;
} | [
"function",
"findOutNearestDate",
"(",
"x0",
",",
"d0",
",",
"d1",
")",
"{",
"return",
"(",
"new",
"Date",
"(",
"x0",
")",
".",
"getTime",
"(",
")",
"-",
"new",
"Date",
"(",
"d0",
".",
"date",
")",
".",
"getTime",
"(",
")",
")",
">",
"(",
"new"... | Finds out which datapoint is closer to the given x position
@param {Number} x0 Date value for data point
@param {Object} d0 Previous datapoint
@param {Object} d1 Next datapoint
@return {Object} d0 or d1, the datapoint with closest date to x0 | [
"Finds",
"out",
"which",
"datapoint",
"is",
"closer",
"to",
"the",
"given",
"x",
"position"
] | 0767051287e9e7211e610b1b13244da71e8e355e | https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/line.js#L877-L879 | train |
eventbrite/britecharts | src/charts/line.js | getPathYFromX | function getPathYFromX(x, path, name, error) {
const key = `${name}-${x}`;
if (key in pathYCache) {
return pathYCache[key];
}
error = error || 0.01;
const maxIterations = 100;
let lengthStart = 0;
let lengthEnd = pat... | javascript | function getPathYFromX(x, path, name, error) {
const key = `${name}-${x}`;
if (key in pathYCache) {
return pathYCache[key];
}
error = error || 0.01;
const maxIterations = 100;
let lengthStart = 0;
let lengthEnd = pat... | [
"function",
"getPathYFromX",
"(",
"x",
",",
"path",
",",
"name",
",",
"error",
")",
"{",
"const",
"key",
"=",
"`",
"${",
"name",
"}",
"${",
"x",
"}",
"`",
";",
"if",
"(",
"key",
"in",
"pathYCache",
")",
"{",
"return",
"pathYCache",
"[",
"key",
"]... | Finds the y coordinate of a path given an x coordinate and the line's path node.
@param {number} x The x coordinate
@param {node} path The path node element
@param {*} name - The name identifier of the topic
@param {number} error The margin of error from the actual x coordinate. Default 0.01
@private | [
"Finds",
"the",
"y",
"coordinate",
"of",
"a",
"path",
"given",
"an",
"x",
"coordinate",
"and",
"the",
"line",
"s",
"path",
"node",
"."
] | 0767051287e9e7211e610b1b13244da71e8e355e | https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/line.js#L1033-L1069 | train |
eventbrite/britecharts | src/charts/bullet.js | buildContainerGroups | function buildContainerGroups() {
let container = svg
.append('g')
.classed('container-group', true)
.attr('transform', `translate(${margin.left}, ${margin.top})`);
container
.append('g').classed('grid-lines-group', true);
... | javascript | function buildContainerGroups() {
let container = svg
.append('g')
.classed('container-group', true)
.attr('transform', `translate(${margin.left}, ${margin.top})`);
container
.append('g').classed('grid-lines-group', true);
... | [
"function",
"buildContainerGroups",
"(",
")",
"{",
"let",
"container",
"=",
"svg",
".",
"append",
"(",
"'g'",
")",
".",
"classed",
"(",
"'container-group'",
",",
"true",
")",
".",
"attr",
"(",
"'transform'",
",",
"`",
"${",
"margin",
".",
"left",
"}",
... | Builds containers for the chart, the axis and a wrapper for all of them
Also applies the Margin convention
@return {void}
@private | [
"Builds",
"containers",
"for",
"the",
"chart",
"the",
"axis",
"and",
"a",
"wrapper",
"for",
"all",
"of",
"them",
"Also",
"applies",
"the",
"Margin",
"convention"
] | 0767051287e9e7211e610b1b13244da71e8e355e | https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/bullet.js#L160-L179 | train |
eventbrite/britecharts | src/charts/bullet.js | buildScales | function buildScales() {
const decidedRange = isReverse ? [chartWidth, 0] : [0, chartWidth];
xScale = d3Scale.scaleLinear()
.domain([0, Math.max(ranges[0], markers[0], measures[0])])
.rangeRound(decidedRange)
.nice();
// Derive width ... | javascript | function buildScales() {
const decidedRange = isReverse ? [chartWidth, 0] : [0, chartWidth];
xScale = d3Scale.scaleLinear()
.domain([0, Math.max(ranges[0], markers[0], measures[0])])
.rangeRound(decidedRange)
.nice();
// Derive width ... | [
"function",
"buildScales",
"(",
")",
"{",
"const",
"decidedRange",
"=",
"isReverse",
"?",
"[",
"chartWidth",
",",
"0",
"]",
":",
"[",
"0",
",",
"chartWidth",
"]",
";",
"xScale",
"=",
"d3Scale",
".",
"scaleLinear",
"(",
")",
".",
"domain",
"(",
"[",
"... | Creates the x scales of the chart
@return {void}
@private | [
"Creates",
"the",
"x",
"scales",
"of",
"the",
"chart"
] | 0767051287e9e7211e610b1b13244da71e8e355e | https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/bullet.js#L186-L204 | train |
eventbrite/britecharts | src/charts/bullet.js | buildSVG | function buildSVG(container) {
if (!svg) {
svg = d3Selection.select(container)
.append('svg')
.classed('britechart bullet-chart', true);
buildContainerGroups();
}
svg
.attr('width', width)
... | javascript | function buildSVG(container) {
if (!svg) {
svg = d3Selection.select(container)
.append('svg')
.classed('britechart bullet-chart', true);
buildContainerGroups();
}
svg
.attr('width', width)
... | [
"function",
"buildSVG",
"(",
"container",
")",
"{",
"if",
"(",
"!",
"svg",
")",
"{",
"svg",
"=",
"d3Selection",
".",
"select",
"(",
"container",
")",
".",
"append",
"(",
"'svg'",
")",
".",
"classed",
"(",
"'britechart bullet-chart'",
",",
"true",
")",
... | Builds the SVG element that will contain the chart
@param {HTMLElement} container DOM element that will work as the container of the graph
@return {void}
@private | [
"Builds",
"the",
"SVG",
"element",
"that",
"will",
"contain",
"the",
"chart"
] | 0767051287e9e7211e610b1b13244da71e8e355e | https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/bullet.js#L212-L224 | train |
eventbrite/britecharts | src/charts/bullet.js | bulletWidth | function bulletWidth(x) {
const x0 = x(0);
return function (d) {
return Math.abs(x(d) - x0);
}
} | javascript | function bulletWidth(x) {
const x0 = x(0);
return function (d) {
return Math.abs(x(d) - x0);
}
} | [
"function",
"bulletWidth",
"(",
"x",
")",
"{",
"const",
"x0",
"=",
"x",
"(",
"0",
")",
";",
"return",
"function",
"(",
"d",
")",
"{",
"return",
"Math",
".",
"abs",
"(",
"x",
"(",
"d",
")",
"-",
"x0",
")",
";",
"}",
"}"
] | Calculates width for each bullet using scale
@return {void}
@private | [
"Calculates",
"width",
"for",
"each",
"bullet",
"using",
"scale"
] | 0767051287e9e7211e610b1b13244da71e8e355e | https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/bullet.js#L231-L237 | train |
eventbrite/britecharts | src/charts/bullet.js | drawBullet | function drawBullet() {
if (rangesEl) {
rangesEl.remove();
measuresEl.remove();
markersEl.remove();
}
rangesEl = svg.select('.chart-group')
.selectAll('rect.range')
.data(ranges)
.enter()
... | javascript | function drawBullet() {
if (rangesEl) {
rangesEl.remove();
measuresEl.remove();
markersEl.remove();
}
rangesEl = svg.select('.chart-group')
.selectAll('rect.range')
.data(ranges)
.enter()
... | [
"function",
"drawBullet",
"(",
")",
"{",
"if",
"(",
"rangesEl",
")",
"{",
"rangesEl",
".",
"remove",
"(",
")",
";",
"measuresEl",
".",
"remove",
"(",
")",
";",
"markersEl",
".",
"remove",
"(",
")",
";",
"}",
"rangesEl",
"=",
"svg",
".",
"select",
"... | Draws the measures of the bullet chart
@return {void}
@private | [
"Draws",
"the",
"measures",
"of",
"the",
"bullet",
"chart"
] | 0767051287e9e7211e610b1b13244da71e8e355e | https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/bullet.js#L282-L327 | train |
eventbrite/britecharts | src/charts/bullet.js | drawTitles | function drawTitles() {
if (hasTitle()) {
// either use title provided from the data
// or customTitle provided via API method call
if (legendGroup) {
legendGroup.remove();
}
legendGroup = svg.select('.metad... | javascript | function drawTitles() {
if (hasTitle()) {
// either use title provided from the data
// or customTitle provided via API method call
if (legendGroup) {
legendGroup.remove();
}
legendGroup = svg.select('.metad... | [
"function",
"drawTitles",
"(",
")",
"{",
"if",
"(",
"hasTitle",
"(",
")",
")",
"{",
"// either use title provided from the data",
"// or customTitle provided via API method call",
"if",
"(",
"legendGroup",
")",
"{",
"legendGroup",
".",
"remove",
"(",
")",
";",
"}",
... | Draws the title and subtitle components of chart
@return {void}
@private | [
"Draws",
"the",
"title",
"and",
"subtitle",
"components",
"of",
"chart"
] | 0767051287e9e7211e610b1b13244da71e8e355e | https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/bullet.js#L350-L394 | train |
eventbrite/britecharts | src/charts/bar.js | sortData | function sortData(unorderedData) {
let {data, dataZeroed} = unorderedData;
if (orderingFunction) {
data.sort(orderingFunction);
dataZeroed.sort(orderingFunction)
}
return { data, dataZeroed };
} | javascript | function sortData(unorderedData) {
let {data, dataZeroed} = unorderedData;
if (orderingFunction) {
data.sort(orderingFunction);
dataZeroed.sort(orderingFunction)
}
return { data, dataZeroed };
} | [
"function",
"sortData",
"(",
"unorderedData",
")",
"{",
"let",
"{",
"data",
",",
"dataZeroed",
"}",
"=",
"unorderedData",
";",
"if",
"(",
"orderingFunction",
")",
"{",
"data",
".",
"sort",
"(",
"orderingFunction",
")",
";",
"dataZeroed",
".",
"sort",
"(",
... | Sorts data if orderingFunction is specified
@param {BarChartData} clean unordered data
@return {BarChartData} clean ordered data
@private | [
"Sorts",
"data",
"if",
"orderingFunction",
"is",
"specified"
] | 0767051287e9e7211e610b1b13244da71e8e355e | https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/bar.js#L370-L379 | train |
eventbrite/britecharts | src/charts/bar.js | drawAxisLabels | function drawAxisLabels() {
if (yAxisLabel) {
if (yAxisLabelEl) {
yAxisLabelEl.remove();
}
yAxisLabelEl = svg.select('.y-axis-label')
.append('text')
.classed('y-axis-label-text', true)
... | javascript | function drawAxisLabels() {
if (yAxisLabel) {
if (yAxisLabelEl) {
yAxisLabelEl.remove();
}
yAxisLabelEl = svg.select('.y-axis-label')
.append('text')
.classed('y-axis-label-text', true)
... | [
"function",
"drawAxisLabels",
"(",
")",
"{",
"if",
"(",
"yAxisLabel",
")",
"{",
"if",
"(",
"yAxisLabelEl",
")",
"{",
"yAxisLabelEl",
".",
"remove",
"(",
")",
";",
"}",
"yAxisLabelEl",
"=",
"svg",
".",
"select",
"(",
"'.y-axis-label'",
")",
".",
"append",... | Draws the x and y axis custom labels respective groups
@private | [
"Draws",
"the",
"x",
"and",
"y",
"axis",
"custom",
"labels",
"respective",
"groups"
] | 0767051287e9e7211e610b1b13244da71e8e355e | https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/bar.js#L414-L441 | train |
eventbrite/britecharts | src/charts/bar.js | drawAnimatedHorizontalBars | function drawAnimatedHorizontalBars(bars) {
// Enter + Update
bars.enter()
.append('rect')
.classed('bar', true)
.attr('x', 0)
.attr('y', chartHeight)
.attr('height', yScale.bandwidth())
.attr('width', ... | javascript | function drawAnimatedHorizontalBars(bars) {
// Enter + Update
bars.enter()
.append('rect')
.classed('bar', true)
.attr('x', 0)
.attr('y', chartHeight)
.attr('height', yScale.bandwidth())
.attr('width', ... | [
"function",
"drawAnimatedHorizontalBars",
"(",
"bars",
")",
"{",
"// Enter + Update",
"bars",
".",
"enter",
"(",
")",
".",
"append",
"(",
"'rect'",
")",
".",
"classed",
"(",
"'bar'",
",",
"true",
")",
".",
"attr",
"(",
"'x'",
",",
"0",
")",
".",
"attr"... | Draws and animates the bars along the x axis
@param {D3Selection} bars Selection of bars
@return {void} | [
"Draws",
"and",
"animates",
"the",
"bars",
"along",
"the",
"x",
"axis"
] | 0767051287e9e7211e610b1b13244da71e8e355e | https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/bar.js#L482-L514 | train |
eventbrite/britecharts | src/charts/bar.js | drawVerticalBars | function drawVerticalBars(bars) {
// Enter + Update
bars.enter()
.append('rect')
.classed('bar', true)
.attr('x', chartWidth)
.attr('y', ({value}) => yScale(value))
.attr('width', xScale.bandwidth())
.a... | javascript | function drawVerticalBars(bars) {
// Enter + Update
bars.enter()
.append('rect')
.classed('bar', true)
.attr('x', chartWidth)
.attr('y', ({value}) => yScale(value))
.attr('width', xScale.bandwidth())
.a... | [
"function",
"drawVerticalBars",
"(",
"bars",
")",
"{",
"// Enter + Update",
"bars",
".",
"enter",
"(",
")",
".",
"append",
"(",
"'rect'",
")",
".",
"classed",
"(",
"'bar'",
",",
"true",
")",
".",
"attr",
"(",
"'x'",
",",
"chartWidth",
")",
".",
"attr",... | Draws the bars along the y axis
@param {D3Selection} bars Selection of bars
@return {void} | [
"Draws",
"the",
"bars",
"along",
"the",
"y",
"axis"
] | 0767051287e9e7211e610b1b13244da71e8e355e | https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/bar.js#L559-L586 | train |
eventbrite/britecharts | src/charts/bar.js | drawLabels | function drawLabels() {
let labelXPosition = isHorizontal ? _labelsHorizontalX : _labelsVerticalX;
let labelYPosition = isHorizontal ? _labelsHorizontalY : _labelsVerticalY;
let text = _labelsFormatValue
if (labelEl) {
svg.selectAll('.percentage-label-gro... | javascript | function drawLabels() {
let labelXPosition = isHorizontal ? _labelsHorizontalX : _labelsVerticalX;
let labelYPosition = isHorizontal ? _labelsHorizontalY : _labelsVerticalY;
let text = _labelsFormatValue
if (labelEl) {
svg.selectAll('.percentage-label-gro... | [
"function",
"drawLabels",
"(",
")",
"{",
"let",
"labelXPosition",
"=",
"isHorizontal",
"?",
"_labelsHorizontalX",
":",
"_labelsVerticalX",
";",
"let",
"labelYPosition",
"=",
"isHorizontal",
"?",
"_labelsHorizontalY",
":",
"_labelsVerticalY",
";",
"let",
"text",
"=",... | Draws labels at the end of each bar
@private
@return {void} | [
"Draws",
"labels",
"at",
"the",
"end",
"of",
"each",
"bar"
] | 0767051287e9e7211e610b1b13244da71e8e355e | https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/bar.js#L593-L616 | train |
eventbrite/britecharts | src/charts/bar.js | drawBars | function drawBars() {
let bars;
if (isAnimated) {
bars = svg.select('.chart-group').selectAll('.bar')
.data(dataZeroed);
if (isHorizontal) {
drawHorizontalBars(bars);
} else {
drawVertic... | javascript | function drawBars() {
let bars;
if (isAnimated) {
bars = svg.select('.chart-group').selectAll('.bar')
.data(dataZeroed);
if (isHorizontal) {
drawHorizontalBars(bars);
} else {
drawVertic... | [
"function",
"drawBars",
"(",
")",
"{",
"let",
"bars",
";",
"if",
"(",
"isAnimated",
")",
"{",
"bars",
"=",
"svg",
".",
"select",
"(",
"'.chart-group'",
")",
".",
"selectAll",
"(",
"'.bar'",
")",
".",
"data",
"(",
"dataZeroed",
")",
";",
"if",
"(",
... | Draws the bar elements within the chart group
@private | [
"Draws",
"the",
"bar",
"elements",
"within",
"the",
"chart",
"group"
] | 0767051287e9e7211e610b1b13244da71e8e355e | https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/bar.js#L622-L664 | train |
eventbrite/britecharts | src/charts/bar.js | drawHorizontalGridLines | function drawHorizontalGridLines() {
maskGridLines = svg.select('.grid-lines-group')
.selectAll('line.vertical-grid-line')
.data(xScale.ticks(xTicks).slice(1))
.enter()
.append('line')
.attr('class', 'vertical-grid-line')
... | javascript | function drawHorizontalGridLines() {
maskGridLines = svg.select('.grid-lines-group')
.selectAll('line.vertical-grid-line')
.data(xScale.ticks(xTicks).slice(1))
.enter()
.append('line')
.attr('class', 'vertical-grid-line')
... | [
"function",
"drawHorizontalGridLines",
"(",
")",
"{",
"maskGridLines",
"=",
"svg",
".",
"select",
"(",
"'.grid-lines-group'",
")",
".",
"selectAll",
"(",
"'line.vertical-grid-line'",
")",
".",
"data",
"(",
"xScale",
".",
"ticks",
"(",
"xTicks",
")",
".",
"slic... | Draws the grid lines for an horizontal bar chart
@return {void} | [
"Draws",
"the",
"grid",
"lines",
"for",
"an",
"horizontal",
"bar",
"chart"
] | 0767051287e9e7211e610b1b13244da71e8e355e | https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/bar.js#L686-L699 | train |
eventbrite/britecharts | src/charts/bar.js | drawVerticalExtendedLine | function drawVerticalExtendedLine() {
baseLine = svg.select('.grid-lines-group')
.selectAll('line.extended-y-line')
.data([0])
.enter()
.append('line')
.attr('class', 'extended-y-line')
.attr('y1', (xAx... | javascript | function drawVerticalExtendedLine() {
baseLine = svg.select('.grid-lines-group')
.selectAll('line.extended-y-line')
.data([0])
.enter()
.append('line')
.attr('class', 'extended-y-line')
.attr('y1', (xAx... | [
"function",
"drawVerticalExtendedLine",
"(",
")",
"{",
"baseLine",
"=",
"svg",
".",
"select",
"(",
"'.grid-lines-group'",
")",
".",
"selectAll",
"(",
"'line.extended-y-line'",
")",
".",
"data",
"(",
"[",
"0",
"]",
")",
".",
"enter",
"(",
")",
".",
"append"... | Draws a vertical line to extend y-axis till the edges
@return {void} | [
"Draws",
"a",
"vertical",
"line",
"to",
"extend",
"y",
"-",
"axis",
"till",
"the",
"edges"
] | 0767051287e9e7211e610b1b13244da71e8e355e | https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/bar.js#L705-L716 | train |
eventbrite/britecharts | src/charts/bar.js | drawVerticalGridLines | function drawVerticalGridLines() {
maskGridLines = svg.select('.grid-lines-group')
.selectAll('line.horizontal-grid-line')
.data(yScale.ticks(yTicks).slice(1))
.enter()
.append('line')
.attr('class', 'horizontal-grid-line'... | javascript | function drawVerticalGridLines() {
maskGridLines = svg.select('.grid-lines-group')
.selectAll('line.horizontal-grid-line')
.data(yScale.ticks(yTicks).slice(1))
.enter()
.append('line')
.attr('class', 'horizontal-grid-line'... | [
"function",
"drawVerticalGridLines",
"(",
")",
"{",
"maskGridLines",
"=",
"svg",
".",
"select",
"(",
"'.grid-lines-group'",
")",
".",
"selectAll",
"(",
"'line.horizontal-grid-line'",
")",
".",
"data",
"(",
"yScale",
".",
"ticks",
"(",
"yTicks",
")",
".",
"slic... | Draws the grid lines for a vertical bar chart
@return {void} | [
"Draws",
"the",
"grid",
"lines",
"for",
"a",
"vertical",
"bar",
"chart"
] | 0767051287e9e7211e610b1b13244da71e8e355e | https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/bar.js#L722-L735 | train |
eventbrite/britecharts | src/charts/grouped-bar.js | buildLayers | function buildLayers() {
layers = transformedData.map((item) => {
let ret = {};
groups.forEach((key) => {
ret[key] = item[key];
});
return assign({}, item, ret);
});
} | javascript | function buildLayers() {
layers = transformedData.map((item) => {
let ret = {};
groups.forEach((key) => {
ret[key] = item[key];
});
return assign({}, item, ret);
});
} | [
"function",
"buildLayers",
"(",
")",
"{",
"layers",
"=",
"transformedData",
".",
"map",
"(",
"(",
"item",
")",
"=>",
"{",
"let",
"ret",
"=",
"{",
"}",
";",
"groups",
".",
"forEach",
"(",
"(",
"key",
")",
"=>",
"{",
"ret",
"[",
"key",
"]",
"=",
... | Builds the grouped layers layout
@return {D3Layout} Layout for drawing the chart
@private | [
"Builds",
"the",
"grouped",
"layers",
"layout"
] | 0767051287e9e7211e610b1b13244da71e8e355e | https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/grouped-bar.js#L267-L277 | train |
eventbrite/britecharts | src/charts/grouped-bar.js | cleanData | function cleanData(originalData) {
return originalData.reduce((acc, d) => {
d.value = +d[valueLabel];
d.group = d[groupLabel];
// for tooltip
d.topicName = getGroup(d);
d.name = d[nameLabel];
... | javascript | function cleanData(originalData) {
return originalData.reduce((acc, d) => {
d.value = +d[valueLabel];
d.group = d[groupLabel];
// for tooltip
d.topicName = getGroup(d);
d.name = d[nameLabel];
... | [
"function",
"cleanData",
"(",
"originalData",
")",
"{",
"return",
"originalData",
".",
"reduce",
"(",
"(",
"acc",
",",
"d",
")",
"=>",
"{",
"d",
".",
"value",
"=",
"+",
"d",
"[",
"valueLabel",
"]",
";",
"d",
".",
"group",
"=",
"d",
"[",
"groupLabel... | Cleaning data casting the values, groups, topic names and names to the proper type while keeping
the rest of properties on the data
@param {GroupedBarChartData} originalData Raw data from the container
@return {GroupedBarChartData} Parsed data with values and dates
@private | [
"Cleaning",
"data",
"casting",
"the",
"values",
"groups",
"topic",
"names",
"and",
"names",
"to",
"the",
"proper",
"type",
"while",
"keeping",
"the",
"rest",
"of",
"properties",
"on",
"the",
"data"
] | 0767051287e9e7211e610b1b13244da71e8e355e | https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/grouped-bar.js#L360-L370 | train |
eventbrite/britecharts | src/charts/grouped-bar.js | drawHorizontalBars | function drawHorizontalBars(layersSelection) {
let layerJoin = layersSelection
.data(layers);
layerElements = layerJoin
.enter()
.append('g')
.attr('transform', ({key}) => `translate(0,${yScale(key)})`)
.c... | javascript | function drawHorizontalBars(layersSelection) {
let layerJoin = layersSelection
.data(layers);
layerElements = layerJoin
.enter()
.append('g')
.attr('transform', ({key}) => `translate(0,${yScale(key)})`)
.c... | [
"function",
"drawHorizontalBars",
"(",
"layersSelection",
")",
"{",
"let",
"layerJoin",
"=",
"layersSelection",
".",
"data",
"(",
"layers",
")",
";",
"layerElements",
"=",
"layerJoin",
".",
"enter",
"(",
")",
".",
"append",
"(",
"'g'",
")",
".",
"attr",
"(... | Draws the bars along the x axis
@param {D3Selection} layersSelection Selection of layers
@return {void} | [
"Draws",
"the",
"bars",
"along",
"the",
"x",
"axis"
] | 0767051287e9e7211e610b1b13244da71e8e355e | https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/grouped-bar.js#L496-L530 | train |
eventbrite/britecharts | src/charts/grouped-bar.js | handleBarsMouseOver | function handleBarsMouseOver(e, d) {
d3Selection.select(e)
.attr('fill', () => d3Color.color(categoryColorMap[d.group]).darker());
} | javascript | function handleBarsMouseOver(e, d) {
d3Selection.select(e)
.attr('fill', () => d3Color.color(categoryColorMap[d.group]).darker());
} | [
"function",
"handleBarsMouseOver",
"(",
"e",
",",
"d",
")",
"{",
"d3Selection",
".",
"select",
"(",
"e",
")",
".",
"attr",
"(",
"'fill'",
",",
"(",
")",
"=>",
"d3Color",
".",
"color",
"(",
"categoryColorMap",
"[",
"d",
".",
"group",
"]",
")",
".",
... | Handles a mouseover event on top of a bar
@param {obj} e the fired event
@param {obj} d data of bar
@return {void} | [
"Handles",
"a",
"mouseover",
"event",
"on",
"top",
"of",
"a",
"bar"
] | 0767051287e9e7211e610b1b13244da71e8e355e | https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/grouped-bar.js#L661-L664 | train |
eventbrite/britecharts | src/charts/grouped-bar.js | handleBarsMouseOut | function handleBarsMouseOut(e, d) {
d3Selection.select(e)
.attr('fill', () => categoryColorMap[d.group])
} | javascript | function handleBarsMouseOut(e, d) {
d3Selection.select(e)
.attr('fill', () => categoryColorMap[d.group])
} | [
"function",
"handleBarsMouseOut",
"(",
"e",
",",
"d",
")",
"{",
"d3Selection",
".",
"select",
"(",
"e",
")",
".",
"attr",
"(",
"'fill'",
",",
"(",
")",
"=>",
"categoryColorMap",
"[",
"d",
".",
"group",
"]",
")",
"}"
] | Handles a mouseout event out of a bar
@param {obj} e the fired event
@param {obj} d data of bar
@return {void} | [
"Handles",
"a",
"mouseout",
"event",
"out",
"of",
"a",
"bar"
] | 0767051287e9e7211e610b1b13244da71e8e355e | https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/grouped-bar.js#L672-L675 | train |
eventbrite/britecharts | src/charts/grouped-bar.js | handleCustomClick | function handleCustomClick (e, d) {
let [mouseX, mouseY] = getMousePosition(e);
let dataPoint = isHorizontal ? getNearestDataPoint2(mouseY) : getNearestDataPoint(mouseX);
dispatcher.call('customClick', e, dataPoint, d3Selection.mouse(e));
} | javascript | function handleCustomClick (e, d) {
let [mouseX, mouseY] = getMousePosition(e);
let dataPoint = isHorizontal ? getNearestDataPoint2(mouseY) : getNearestDataPoint(mouseX);
dispatcher.call('customClick', e, dataPoint, d3Selection.mouse(e));
} | [
"function",
"handleCustomClick",
"(",
"e",
",",
"d",
")",
"{",
"let",
"[",
"mouseX",
",",
"mouseY",
"]",
"=",
"getMousePosition",
"(",
"e",
")",
";",
"let",
"dataPoint",
"=",
"isHorizontal",
"?",
"getNearestDataPoint2",
"(",
"mouseY",
")",
":",
"getNearest... | Click handler, shows data that was clicked and passes to the user
@private | [
"Click",
"handler",
"shows",
"data",
"that",
"was",
"clicked",
"and",
"passes",
"to",
"the",
"user"
] | 0767051287e9e7211e610b1b13244da71e8e355e | https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/grouped-bar.js#L709-L714 | train |
eventbrite/britecharts | src/charts/grouped-bar.js | horizontalBarsTween | function horizontalBarsTween(d) {
let node = d3Selection.select(this),
i = d3Interpolate.interpolateRound(0, xScale(getValue(d))),
j = d3Interpolate.interpolateNumber(0, 1);
return function (t) {
node.attr('width', i(t))
.style... | javascript | function horizontalBarsTween(d) {
let node = d3Selection.select(this),
i = d3Interpolate.interpolateRound(0, xScale(getValue(d))),
j = d3Interpolate.interpolateNumber(0, 1);
return function (t) {
node.attr('width', i(t))
.style... | [
"function",
"horizontalBarsTween",
"(",
"d",
")",
"{",
"let",
"node",
"=",
"d3Selection",
".",
"select",
"(",
"this",
")",
",",
"i",
"=",
"d3Interpolate",
".",
"interpolateRound",
"(",
"0",
",",
"xScale",
"(",
"getValue",
"(",
"d",
")",
")",
")",
",",
... | Animation tween of horizontal bars
@param {obj} d data of bar
@return {void} | [
"Animation",
"tween",
"of",
"horizontal",
"bars"
] | 0767051287e9e7211e610b1b13244da71e8e355e | https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/grouped-bar.js#L739-L748 | train |
eventbrite/britecharts | src/charts/grouped-bar.js | prepareData | function prepareData(data) {
groups = uniq(data.map((d) => getGroup(d)));
transformedData = d3Collection.nest()
.key(getName)
.rollup(function (values) {
let ret = {};
values.forEach((entry) => {
if ... | javascript | function prepareData(data) {
groups = uniq(data.map((d) => getGroup(d)));
transformedData = d3Collection.nest()
.key(getName)
.rollup(function (values) {
let ret = {};
values.forEach((entry) => {
if ... | [
"function",
"prepareData",
"(",
"data",
")",
"{",
"groups",
"=",
"uniq",
"(",
"data",
".",
"map",
"(",
"(",
"d",
")",
"=>",
"getGroup",
"(",
"d",
")",
")",
")",
";",
"transformedData",
"=",
"d3Collection",
".",
"nest",
"(",
")",
".",
"key",
"(",
... | Prepare data for create chart.
@private | [
"Prepare",
"data",
"for",
"create",
"chart",
"."
] | 0767051287e9e7211e610b1b13244da71e8e355e | https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/grouped-bar.js#L764-L787 | train |
eventbrite/britecharts | src/charts/grouped-bar.js | verticalBarsTween | function verticalBarsTween(d) {
let node = d3Selection.select(this),
i = d3Interpolate.interpolateRound(0, chartHeight - yScale(getValue(d))),
y = d3Interpolate.interpolateRound(chartHeight, yScale(getValue(d))),
j = d3Interpolate.interpolateNumber(0, 1);
... | javascript | function verticalBarsTween(d) {
let node = d3Selection.select(this),
i = d3Interpolate.interpolateRound(0, chartHeight - yScale(getValue(d))),
y = d3Interpolate.interpolateRound(chartHeight, yScale(getValue(d))),
j = d3Interpolate.interpolateNumber(0, 1);
... | [
"function",
"verticalBarsTween",
"(",
"d",
")",
"{",
"let",
"node",
"=",
"d3Selection",
".",
"select",
"(",
"this",
")",
",",
"i",
"=",
"d3Interpolate",
".",
"interpolateRound",
"(",
"0",
",",
"chartHeight",
"-",
"yScale",
"(",
"getValue",
"(",
"d",
")",... | Animation tween of vertical bars
@param {obj} d data of bar
@return {void} | [
"Animation",
"tween",
"of",
"vertical",
"bars"
] | 0767051287e9e7211e610b1b13244da71e8e355e | https://github.com/eventbrite/britecharts/blob/0767051287e9e7211e610b1b13244da71e8e355e/src/charts/grouped-bar.js#L804-L814 | train |
AllenFang/react-bootstrap-table | examples/js/cell-edit/cell-edit-classname.js | jobNameValidator | function jobNameValidator(value) {
const response = { isValid: true, notification: { type: 'success', msg: '', title: '' } };
if (!value) {
response.isValid = false;
response.notification.type = 'error';
response.notification.msg = 'Value must be inserted';
response.notification.title = 'Requested V... | javascript | function jobNameValidator(value) {
const response = { isValid: true, notification: { type: 'success', msg: '', title: '' } };
if (!value) {
response.isValid = false;
response.notification.type = 'error';
response.notification.msg = 'Value must be inserted';
response.notification.title = 'Requested V... | [
"function",
"jobNameValidator",
"(",
"value",
")",
"{",
"const",
"response",
"=",
"{",
"isValid",
":",
"true",
",",
"notification",
":",
"{",
"type",
":",
"'success'",
",",
"msg",
":",
"''",
",",
"title",
":",
"''",
"}",
"}",
";",
"if",
"(",
"!",
"... | validator function pass the user input value and should return true|false. | [
"validator",
"function",
"pass",
"the",
"user",
"input",
"value",
"and",
"should",
"return",
"true|false",
"."
] | 26d07defab759e4f9bce22d1d568690830b8d9d7 | https://github.com/AllenFang/react-bootstrap-table/blob/26d07defab759e4f9bce22d1d568690830b8d9d7/examples/js/cell-edit/cell-edit-classname.js#L32-L46 | train |
olistic/warriorjs | packages/warriorjs-helper-get-level-score/src/getClearBonus.js | getClearBonus | function getClearBonus(events, warriorScore, timeBonus) {
const lastEvent = getLastEvent(events);
if (!isFloorClear(lastEvent.floorMap)) {
return 0;
}
return Math.round((warriorScore + timeBonus) * 0.2);
} | javascript | function getClearBonus(events, warriorScore, timeBonus) {
const lastEvent = getLastEvent(events);
if (!isFloorClear(lastEvent.floorMap)) {
return 0;
}
return Math.round((warriorScore + timeBonus) * 0.2);
} | [
"function",
"getClearBonus",
"(",
"events",
",",
"warriorScore",
",",
"timeBonus",
")",
"{",
"const",
"lastEvent",
"=",
"getLastEvent",
"(",
"events",
")",
";",
"if",
"(",
"!",
"isFloorClear",
"(",
"lastEvent",
".",
"floorMap",
")",
")",
"{",
"return",
"0"... | Returns the bonus for clearing the level.
@param {Object[][]} events The events that happened during the play.
@param {number} warriorScore The score of the warrior.
@param {number} timeBonus The time bonus.
@returns {number} The clear bonus. | [
"Returns",
"the",
"bonus",
"for",
"clearing",
"the",
"level",
"."
] | ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8 | https://github.com/olistic/warriorjs/blob/ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8/packages/warriorjs-helper-get-level-score/src/getClearBonus.js#L13-L20 | train |
olistic/warriorjs | packages/warriorjs-helper-get-level-config/src/index.js | getLevelConfig | function getLevelConfig(tower, levelNumber, warriorName, epic) {
const level = tower.levels[levelNumber - 1];
if (!level) {
return null;
}
const levelConfig = cloneDeep(level);
const levels = epic ? tower.levels : tower.levels.slice(0, levelNumber);
const warriorAbilities = Object.assign(
{},
... | javascript | function getLevelConfig(tower, levelNumber, warriorName, epic) {
const level = tower.levels[levelNumber - 1];
if (!level) {
return null;
}
const levelConfig = cloneDeep(level);
const levels = epic ? tower.levels : tower.levels.slice(0, levelNumber);
const warriorAbilities = Object.assign(
{},
... | [
"function",
"getLevelConfig",
"(",
"tower",
",",
"levelNumber",
",",
"warriorName",
",",
"epic",
")",
"{",
"const",
"level",
"=",
"tower",
".",
"levels",
"[",
"levelNumber",
"-",
"1",
"]",
";",
"if",
"(",
"!",
"level",
")",
"{",
"return",
"null",
";",
... | Returns the config for the level with the given number.
@param {Object} tower The tower.
@param {number} levelNumber The number of the level.
@param {string} warriorName The name of the warrior.
@param {boolean} epic Whether the level is to be used in epic mode or not.
@returns {Object} The level config. | [
"Returns",
"the",
"config",
"for",
"the",
"level",
"with",
"the",
"given",
"number",
"."
] | ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8 | https://github.com/olistic/warriorjs/blob/ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8/packages/warriorjs-helper-get-level-config/src/index.js#L13-L37 | train |
olistic/warriorjs | packages/warriorjs-cli/src/parseArgs.js | parseArgs | function parseArgs(args) {
return yargs
.usage('Usage: $0 [options]')
.options({
d: {
alias: 'directory',
default: '.',
describe: 'Run under given directory',
type: 'string',
},
l: {
alias: 'level',
coerce: arg => {
const parsed = Num... | javascript | function parseArgs(args) {
return yargs
.usage('Usage: $0 [options]')
.options({
d: {
alias: 'directory',
default: '.',
describe: 'Run under given directory',
type: 'string',
},
l: {
alias: 'level',
coerce: arg => {
const parsed = Num... | [
"function",
"parseArgs",
"(",
"args",
")",
"{",
"return",
"yargs",
".",
"usage",
"(",
"'Usage: $0 [options]'",
")",
".",
"options",
"(",
"{",
"d",
":",
"{",
"alias",
":",
"'directory'",
",",
"default",
":",
"'.'",
",",
"describe",
":",
"'Run under given di... | Parses the provided args.
@param {string[]} args The args no parse.
@returns {Object} The parsed args. | [
"Parses",
"the",
"provided",
"args",
"."
] | ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8 | https://github.com/olistic/warriorjs/blob/ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8/packages/warriorjs-cli/src/parseArgs.js#L10-L64 | train |
olistic/warriorjs | packages/warriorjs-cli/src/ui/printLogMessage.js | printLogMessage | function printLogMessage(unit, message) {
const prompt = chalk.gray.dim('>');
const logMessage = getUnitStyle(unit)(`${unit.name} ${message}`);
printLine(`${prompt} ${logMessage}`);
} | javascript | function printLogMessage(unit, message) {
const prompt = chalk.gray.dim('>');
const logMessage = getUnitStyle(unit)(`${unit.name} ${message}`);
printLine(`${prompt} ${logMessage}`);
} | [
"function",
"printLogMessage",
"(",
"unit",
",",
"message",
")",
"{",
"const",
"prompt",
"=",
"chalk",
".",
"gray",
".",
"dim",
"(",
"'>'",
")",
";",
"const",
"logMessage",
"=",
"getUnitStyle",
"(",
"unit",
")",
"(",
"`",
"${",
"unit",
".",
"name",
"... | Prints a message to the log.
@param {Object} unit The unit the message belongs to.
@param {string} message The message to print. | [
"Prints",
"a",
"message",
"to",
"the",
"log",
"."
] | ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8 | https://github.com/olistic/warriorjs/blob/ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8/packages/warriorjs-cli/src/ui/printLogMessage.js#L12-L16 | train |
olistic/warriorjs | packages/warriorjs-cli/src/ui/printLevelReport.js | printLevelReport | function printLevelReport(
profile,
{ warrior: warriorScore, timeBonus, clearBonus },
totalScore,
grade,
) {
printLine(`Warrior Score: ${warriorScore}`);
printLine(`Time Bonus: ${timeBonus}`);
printLine(`Clear Bonus: ${clearBonus}`);
if (profile.isEpic()) {
printLine(`Level Grade: ${getGradeLetter(... | javascript | function printLevelReport(
profile,
{ warrior: warriorScore, timeBonus, clearBonus },
totalScore,
grade,
) {
printLine(`Warrior Score: ${warriorScore}`);
printLine(`Time Bonus: ${timeBonus}`);
printLine(`Clear Bonus: ${clearBonus}`);
if (profile.isEpic()) {
printLine(`Level Grade: ${getGradeLetter(... | [
"function",
"printLevelReport",
"(",
"profile",
",",
"{",
"warrior",
":",
"warriorScore",
",",
"timeBonus",
",",
"clearBonus",
"}",
",",
"totalScore",
",",
"grade",
",",
")",
"{",
"printLine",
"(",
"`",
"${",
"warriorScore",
"}",
"`",
")",
";",
"printLine"... | Prints the level report.
@param {Profile} profile The profile.
@param {Object} scoreParts The score components.
@param {number} scoreParts.warrior The points earned by the warrior.
@param {number} scoreParts.timeBonus The time bonus.
@param {number} scoreParts.clearBonus The clear bonus.
@param {number} totalScore The... | [
"Prints",
"the",
"level",
"report",
"."
] | ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8 | https://github.com/olistic/warriorjs/blob/ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8/packages/warriorjs-cli/src/ui/printLevelReport.js#L17-L33 | train |
olistic/warriorjs | packages/warriorjs-geography/src/verifyRelativeDirection.js | verifyRelativeDirection | function verifyRelativeDirection(direction) {
if (!RELATIVE_DIRECTIONS.includes(direction)) {
throw new Error(
`Unknown direction: '${direction}'. Should be one of: '${FORWARD}', '${RIGHT}', '${BACKWARD}' or '${LEFT}'.`,
);
}
} | javascript | function verifyRelativeDirection(direction) {
if (!RELATIVE_DIRECTIONS.includes(direction)) {
throw new Error(
`Unknown direction: '${direction}'. Should be one of: '${FORWARD}', '${RIGHT}', '${BACKWARD}' or '${LEFT}'.`,
);
}
} | [
"function",
"verifyRelativeDirection",
"(",
"direction",
")",
"{",
"if",
"(",
"!",
"RELATIVE_DIRECTIONS",
".",
"includes",
"(",
"direction",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"direction",
"}",
"${",
"FORWARD",
"}",
"${",
"RIGHT",
"}",... | Checks if the given direction is a valid relative direction.
@param {string} direction The direction.
@throws Will throw if the direction is not valid. | [
"Checks",
"if",
"the",
"given",
"direction",
"is",
"a",
"valid",
"relative",
"direction",
"."
] | ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8 | https://github.com/olistic/warriorjs/blob/ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8/packages/warriorjs-geography/src/verifyRelativeDirection.js#L16-L22 | train |
olistic/warriorjs | packages/warriorjs-core/src/loadLevel.js | loadAbilities | function loadAbilities(unit, abilities = {}) {
Object.entries(abilities).forEach(([abilityName, abilityCreator]) => {
const ability = abilityCreator(unit);
unit.addAbility(abilityName, ability);
});
} | javascript | function loadAbilities(unit, abilities = {}) {
Object.entries(abilities).forEach(([abilityName, abilityCreator]) => {
const ability = abilityCreator(unit);
unit.addAbility(abilityName, ability);
});
} | [
"function",
"loadAbilities",
"(",
"unit",
",",
"abilities",
"=",
"{",
"}",
")",
"{",
"Object",
".",
"entries",
"(",
"abilities",
")",
".",
"forEach",
"(",
"(",
"[",
"abilityName",
",",
"abilityCreator",
"]",
")",
"=>",
"{",
"const",
"ability",
"=",
"ab... | Loads the abilities onto the unit.
@param {Unit} unit The unit.
@param {Object} abilities The abilities to load. | [
"Loads",
"the",
"abilities",
"onto",
"the",
"unit",
"."
] | ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8 | https://github.com/olistic/warriorjs/blob/ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8/packages/warriorjs-core/src/loadLevel.js#L13-L18 | train |
olistic/warriorjs | packages/warriorjs-core/src/loadLevel.js | loadEffects | function loadEffects(unit, effects = {}) {
Object.entries(effects).forEach(([effectName, effectCreator]) => {
const effect = effectCreator(unit);
unit.addEffect(effectName, effect);
});
} | javascript | function loadEffects(unit, effects = {}) {
Object.entries(effects).forEach(([effectName, effectCreator]) => {
const effect = effectCreator(unit);
unit.addEffect(effectName, effect);
});
} | [
"function",
"loadEffects",
"(",
"unit",
",",
"effects",
"=",
"{",
"}",
")",
"{",
"Object",
".",
"entries",
"(",
"effects",
")",
".",
"forEach",
"(",
"(",
"[",
"effectName",
",",
"effectCreator",
"]",
")",
"=>",
"{",
"const",
"effect",
"=",
"effectCreat... | Loads the effects onto the unit.
@param {Unit} unit The unit.
@param {Object} effects The effects to load. | [
"Loads",
"the",
"effects",
"onto",
"the",
"unit",
"."
] | ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8 | https://github.com/olistic/warriorjs/blob/ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8/packages/warriorjs-core/src/loadLevel.js#L26-L31 | train |
olistic/warriorjs | packages/warriorjs-core/src/loadLevel.js | loadWarrior | function loadWarrior(
{ name, character, color, maxHealth, abilities, effects, position },
floor,
playerCode,
) {
const warrior = new Warrior(name, character, color, maxHealth);
loadAbilities(warrior, abilities);
loadEffects(warrior, effects);
warrior.playTurn = playerCode ? loadPlayer(playerCode) : () =>... | javascript | function loadWarrior(
{ name, character, color, maxHealth, abilities, effects, position },
floor,
playerCode,
) {
const warrior = new Warrior(name, character, color, maxHealth);
loadAbilities(warrior, abilities);
loadEffects(warrior, effects);
warrior.playTurn = playerCode ? loadPlayer(playerCode) : () =>... | [
"function",
"loadWarrior",
"(",
"{",
"name",
",",
"character",
",",
"color",
",",
"maxHealth",
",",
"abilities",
",",
"effects",
",",
"position",
"}",
",",
"floor",
",",
"playerCode",
",",
")",
"{",
"const",
"warrior",
"=",
"new",
"Warrior",
"(",
"name",... | Loads the warrior.
@param {Object} warriorConfig The config of the warrior.
@param {Floor} floor The floor of the level.
@param {string} [playerCode] The code of the player. | [
"Loads",
"the",
"warrior",
"."
] | ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8 | https://github.com/olistic/warriorjs/blob/ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8/packages/warriorjs-core/src/loadLevel.js#L40-L50 | train |
olistic/warriorjs | packages/warriorjs-core/src/loadLevel.js | loadUnit | function loadUnit(
{
name,
character,
color,
maxHealth,
reward,
enemy,
bound,
abilities,
effects,
playTurn,
position,
},
floor,
) {
const unit = new Unit(
name,
character,
color,
maxHealth,
reward,
enemy,
bound,
);
loadAbilities(unit, a... | javascript | function loadUnit(
{
name,
character,
color,
maxHealth,
reward,
enemy,
bound,
abilities,
effects,
playTurn,
position,
},
floor,
) {
const unit = new Unit(
name,
character,
color,
maxHealth,
reward,
enemy,
bound,
);
loadAbilities(unit, a... | [
"function",
"loadUnit",
"(",
"{",
"name",
",",
"character",
",",
"color",
",",
"maxHealth",
",",
"reward",
",",
"enemy",
",",
"bound",
",",
"abilities",
",",
"effects",
",",
"playTurn",
",",
"position",
",",
"}",
",",
"floor",
",",
")",
"{",
"const",
... | Loads a unit.
@param {Object} unitConfig The config of the unit.
@param {Floor} floor The floor of the level. | [
"Loads",
"a",
"unit",
"."
] | ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8 | https://github.com/olistic/warriorjs/blob/ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8/packages/warriorjs-core/src/loadLevel.js#L58-L87 | train |
olistic/warriorjs | packages/warriorjs-core/src/loadLevel.js | loadLevel | function loadLevel(
{
number,
description,
tip,
clue,
floor: { size, stairs, warrior, units = [] },
},
playerCode,
) {
const { width, height } = size;
const stairsLocation = [stairs.x, stairs.y];
const floor = new Floor(width, height, stairsLocation);
loadWarrior(warrior, floor, playe... | javascript | function loadLevel(
{
number,
description,
tip,
clue,
floor: { size, stairs, warrior, units = [] },
},
playerCode,
) {
const { width, height } = size;
const stairsLocation = [stairs.x, stairs.y];
const floor = new Floor(width, height, stairsLocation);
loadWarrior(warrior, floor, playe... | [
"function",
"loadLevel",
"(",
"{",
"number",
",",
"description",
",",
"tip",
",",
"clue",
",",
"floor",
":",
"{",
"size",
",",
"stairs",
",",
"warrior",
",",
"units",
"=",
"[",
"]",
"}",
",",
"}",
",",
"playerCode",
",",
")",
"{",
"const",
"{",
"... | Loads a level from a level config.
@param {Object} levelConfig The config of the level.
@param {string} [playerCode] The code of the player.
@returns {Level} The loaded level. | [
"Loads",
"a",
"level",
"from",
"a",
"level",
"config",
"."
] | ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8 | https://github.com/olistic/warriorjs/blob/ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8/packages/warriorjs-core/src/loadLevel.js#L97-L115 | train |
olistic/warriorjs | packages/warriorjs-cli/src/ui/requestConfirmation.js | requestConfirmation | async function requestConfirmation(message, defaultAnswer = false) {
const answerName = 'requestConfirmation';
const answers = await inquirer.prompt([
{
message,
name: answerName,
type: 'confirm',
default: defaultAnswer,
},
]);
return answers[answerName];
} | javascript | async function requestConfirmation(message, defaultAnswer = false) {
const answerName = 'requestConfirmation';
const answers = await inquirer.prompt([
{
message,
name: answerName,
type: 'confirm',
default: defaultAnswer,
},
]);
return answers[answerName];
} | [
"async",
"function",
"requestConfirmation",
"(",
"message",
",",
"defaultAnswer",
"=",
"false",
")",
"{",
"const",
"answerName",
"=",
"'requestConfirmation'",
";",
"const",
"answers",
"=",
"await",
"inquirer",
".",
"prompt",
"(",
"[",
"{",
"message",
",",
"nam... | Requests confirmation from the user.
@param {string} message The prompt message.
@param {boolean} defaultAnswer The default answer. | [
"Requests",
"confirmation",
"from",
"the",
"user",
"."
] | ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8 | https://github.com/olistic/warriorjs/blob/ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8/packages/warriorjs-cli/src/ui/requestConfirmation.js#L9-L20 | train |
olistic/warriorjs | packages/warriorjs-geography/src/verifyAbsoluteDirection.js | verifyAbsoluteDirection | function verifyAbsoluteDirection(direction) {
if (!ABSOLUTE_DIRECTIONS.includes(direction)) {
throw new Error(
`Unknown direction: '${direction}'. Should be one of: '${NORTH}', '${EAST}', '${SOUTH}' or '${WEST}'.`,
);
}
} | javascript | function verifyAbsoluteDirection(direction) {
if (!ABSOLUTE_DIRECTIONS.includes(direction)) {
throw new Error(
`Unknown direction: '${direction}'. Should be one of: '${NORTH}', '${EAST}', '${SOUTH}' or '${WEST}'.`,
);
}
} | [
"function",
"verifyAbsoluteDirection",
"(",
"direction",
")",
"{",
"if",
"(",
"!",
"ABSOLUTE_DIRECTIONS",
".",
"includes",
"(",
"direction",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"direction",
"}",
"${",
"NORTH",
"}",
"${",
"EAST",
"}",
... | Checks if the given direction is a valid absolute direction.
@param {string} direction The direction.
@throws Will throw if the direction is not valid. | [
"Checks",
"if",
"the",
"given",
"direction",
"is",
"a",
"valid",
"absolute",
"direction",
"."
] | ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8 | https://github.com/olistic/warriorjs/blob/ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8/packages/warriorjs-geography/src/verifyAbsoluteDirection.js#L16-L22 | train |
olistic/warriorjs | packages/warriorjs-cli/src/ui/printTurnHeader.js | printTurnHeader | function printTurnHeader(turnNumber) {
printRow(chalk.gray.dim(` ${String(turnNumber).padStart(3, '0')} `), {
position: 'middle',
padding: chalk.gray.dim('~'),
});
} | javascript | function printTurnHeader(turnNumber) {
printRow(chalk.gray.dim(` ${String(turnNumber).padStart(3, '0')} `), {
position: 'middle',
padding: chalk.gray.dim('~'),
});
} | [
"function",
"printTurnHeader",
"(",
"turnNumber",
")",
"{",
"printRow",
"(",
"chalk",
".",
"gray",
".",
"dim",
"(",
"`",
"${",
"String",
"(",
"turnNumber",
")",
".",
"padStart",
"(",
"3",
",",
"'0'",
")",
"}",
"`",
")",
",",
"{",
"position",
":",
"... | Prints the turn header.
@param {number} turnNumber The turn number. | [
"Prints",
"the",
"turn",
"header",
"."
] | ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8 | https://github.com/olistic/warriorjs/blob/ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8/packages/warriorjs-cli/src/ui/printTurnHeader.js#L10-L15 | train |
olistic/warriorjs | packages/warriorjs-cli/src/ui/printFloorMap.js | printFloorMap | function printFloorMap(floorMap) {
printLine(
floorMap
.map(row =>
row
.map(({ character, unit }) => {
if (unit) {
return getUnitStyle(unit)(character);
}
return character;
})
.join(''),
)
.join('\n'),
);
... | javascript | function printFloorMap(floorMap) {
printLine(
floorMap
.map(row =>
row
.map(({ character, unit }) => {
if (unit) {
return getUnitStyle(unit)(character);
}
return character;
})
.join(''),
)
.join('\n'),
);
... | [
"function",
"printFloorMap",
"(",
"floorMap",
")",
"{",
"printLine",
"(",
"floorMap",
".",
"map",
"(",
"row",
"=>",
"row",
".",
"map",
"(",
"(",
"{",
"character",
",",
"unit",
"}",
")",
"=>",
"{",
"if",
"(",
"unit",
")",
"{",
"return",
"getUnitStyle"... | Prints the floor map.
@param {Object[][]} floorMap The map of the floor. | [
"Prints",
"the",
"floor",
"map",
"."
] | ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8 | https://github.com/olistic/warriorjs/blob/ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8/packages/warriorjs-cli/src/ui/printFloorMap.js#L9-L25 | train |
olistic/warriorjs | packages/warriorjs-core/src/loadPlayer.js | loadPlayer | function loadPlayer(playerCode) {
const sandbox = vm.createContext();
// Do not collect stack frames for errors in the player code.
vm.runInContext('Error.stackTraceLimit = 0;', sandbox);
try {
vm.runInContext(playerCode, sandbox, {
filename: playerCodeFilename,
timeout: playerCodeTimeout,
... | javascript | function loadPlayer(playerCode) {
const sandbox = vm.createContext();
// Do not collect stack frames for errors in the player code.
vm.runInContext('Error.stackTraceLimit = 0;', sandbox);
try {
vm.runInContext(playerCode, sandbox, {
filename: playerCodeFilename,
timeout: playerCodeTimeout,
... | [
"function",
"loadPlayer",
"(",
"playerCode",
")",
"{",
"const",
"sandbox",
"=",
"vm",
".",
"createContext",
"(",
")",
";",
"// Do not collect stack frames for errors in the player code.",
"vm",
".",
"runInContext",
"(",
"'Error.stackTraceLimit = 0;'",
",",
"sandbox",
")... | Loads the player code and returns the playTurn function.
@param {string} playerCode The code of the player.
@returns {Function} The playTurn function. | [
"Loads",
"the",
"player",
"code",
"and",
"returns",
"the",
"playTurn",
"function",
"."
] | ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8 | https://github.com/olistic/warriorjs/blob/ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8/packages/warriorjs-core/src/loadPlayer.js#L14-L61 | train |
olistic/warriorjs | packages/warriorjs-cli/src/ui/printRow.js | printRow | function printRow(message, { position = 'start', padding = ' ' } = {}) {
const [screenWidth] = getScreenSize();
const rowWidth = screenWidth - 1; // Consider line break length.
const messageWidth = stringWidth(message);
const paddingWidth = (rowWidth - messageWidth) / 2;
const startPadding = padding.repeat(Ma... | javascript | function printRow(message, { position = 'start', padding = ' ' } = {}) {
const [screenWidth] = getScreenSize();
const rowWidth = screenWidth - 1; // Consider line break length.
const messageWidth = stringWidth(message);
const paddingWidth = (rowWidth - messageWidth) / 2;
const startPadding = padding.repeat(Ma... | [
"function",
"printRow",
"(",
"message",
",",
"{",
"position",
"=",
"'start'",
",",
"padding",
"=",
"' '",
"}",
"=",
"{",
"}",
")",
"{",
"const",
"[",
"screenWidth",
"]",
"=",
"getScreenSize",
"(",
")",
";",
"const",
"rowWidth",
"=",
"screenWidth",
"-",... | Prints a message and fills the rest of the line with a padding character.
@param {string} message The message to print.
@param {Object} options The options.
@param {string} options.position The position of the message.
@param {string} options.padding The padding character. | [
"Prints",
"a",
"message",
"and",
"fills",
"the",
"rest",
"of",
"the",
"line",
"with",
"a",
"padding",
"character",
"."
] | ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8 | https://github.com/olistic/warriorjs/blob/ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8/packages/warriorjs-cli/src/ui/printRow.js#L14-L28 | train |
olistic/warriorjs | packages/warriorjs-cli/src/ui/printTowerReport.js | printTowerReport | function printTowerReport(profile) {
const averageGrade = profile.calculateAverageGrade();
if (!averageGrade) {
return;
}
const averageGradeLetter = getGradeLetter(averageGrade);
printLine(`Your average grade for this tower is: ${averageGradeLetter}\n`);
Object.keys(profile.currentEpicGrades)
.sor... | javascript | function printTowerReport(profile) {
const averageGrade = profile.calculateAverageGrade();
if (!averageGrade) {
return;
}
const averageGradeLetter = getGradeLetter(averageGrade);
printLine(`Your average grade for this tower is: ${averageGradeLetter}\n`);
Object.keys(profile.currentEpicGrades)
.sor... | [
"function",
"printTowerReport",
"(",
"profile",
")",
"{",
"const",
"averageGrade",
"=",
"profile",
".",
"calculateAverageGrade",
"(",
")",
";",
"if",
"(",
"!",
"averageGrade",
")",
"{",
"return",
";",
"}",
"const",
"averageGradeLetter",
"=",
"getGradeLetter",
... | Prints the tower report.
@param {Profile} profile The profile. | [
"Prints",
"the",
"tower",
"report",
"."
] | ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8 | https://github.com/olistic/warriorjs/blob/ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8/packages/warriorjs-cli/src/ui/printTowerReport.js#L10-L28 | train |
olistic/warriorjs | packages/warriorjs-helper-get-level-score/src/index.js | getLevelScore | function getLevelScore({ passed, events }, { timeBonus }) {
if (!passed) {
return null;
}
const warriorScore = getWarriorScore(events);
const remainingTimeBonus = getRemainingTimeBonus(events, timeBonus);
const clearBonus = getClearBonus(events, warriorScore, remainingTimeBonus);
return {
clearBonu... | javascript | function getLevelScore({ passed, events }, { timeBonus }) {
if (!passed) {
return null;
}
const warriorScore = getWarriorScore(events);
const remainingTimeBonus = getRemainingTimeBonus(events, timeBonus);
const clearBonus = getClearBonus(events, warriorScore, remainingTimeBonus);
return {
clearBonu... | [
"function",
"getLevelScore",
"(",
"{",
"passed",
",",
"events",
"}",
",",
"{",
"timeBonus",
"}",
")",
"{",
"if",
"(",
"!",
"passed",
")",
"{",
"return",
"null",
";",
"}",
"const",
"warriorScore",
"=",
"getWarriorScore",
"(",
"events",
")",
";",
"const"... | Returns the score for the given level.
@param {Object} result The level result.
@param {boolean} result.passed Whether the level was passed or not.
@param {Object[][]} result.events The events of the level.
@param {Object} levelConfig The level config.
@param {number} levelConfig.timeBonus The bonus for passing the le... | [
"Returns",
"the",
"score",
"for",
"the",
"given",
"level",
"."
] | ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8 | https://github.com/olistic/warriorjs/blob/ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8/packages/warriorjs-helper-get-level-score/src/index.js#L16-L29 | train |
olistic/warriorjs | packages/warriorjs-cli/src/loadTowers.js | getExternalTowersInfo | function getExternalTowersInfo() {
const cliDir = findUp.sync('@warriorjs/cli', { cwd: __dirname });
if (!cliDir) {
return [];
}
const cliParentDir = path.resolve(cliDir, '..');
const towerSearchDir = findUp.sync('node_modules', { cwd: cliParentDir });
const towerPackageJsonPaths = globby.sync(
[of... | javascript | function getExternalTowersInfo() {
const cliDir = findUp.sync('@warriorjs/cli', { cwd: __dirname });
if (!cliDir) {
return [];
}
const cliParentDir = path.resolve(cliDir, '..');
const towerSearchDir = findUp.sync('node_modules', { cwd: cliParentDir });
const towerPackageJsonPaths = globby.sync(
[of... | [
"function",
"getExternalTowersInfo",
"(",
")",
"{",
"const",
"cliDir",
"=",
"findUp",
".",
"sync",
"(",
"'@warriorjs/cli'",
",",
"{",
"cwd",
":",
"__dirname",
"}",
")",
";",
"if",
"(",
"!",
"cliDir",
")",
"{",
"return",
"[",
"]",
";",
"}",
"const",
"... | Returns the external towers info.
It searches for official and community towers installed in the nearest
`node_modules` directory that is parent to @warriorjs/cli.
@returns {Object[]} The external towers info. | [
"Returns",
"the",
"external",
"towers",
"info",
"."
] | ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8 | https://github.com/olistic/warriorjs/blob/ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8/packages/warriorjs-cli/src/loadTowers.js#L36-L53 | train |
olistic/warriorjs | packages/warriorjs-cli/src/loadTowers.js | loadTowers | function loadTowers() {
const internalTowersInfo = getInternalTowersInfo();
const externalTowersInfo = getExternalTowersInfo();
return uniqBy(internalTowersInfo.concat(externalTowersInfo), 'id').map(
({ id, requirePath }) => {
const { name, description, levels } = require(requirePath); // eslint-disable... | javascript | function loadTowers() {
const internalTowersInfo = getInternalTowersInfo();
const externalTowersInfo = getExternalTowersInfo();
return uniqBy(internalTowersInfo.concat(externalTowersInfo), 'id').map(
({ id, requirePath }) => {
const { name, description, levels } = require(requirePath); // eslint-disable... | [
"function",
"loadTowers",
"(",
")",
"{",
"const",
"internalTowersInfo",
"=",
"getInternalTowersInfo",
"(",
")",
";",
"const",
"externalTowersInfo",
"=",
"getExternalTowersInfo",
"(",
")",
";",
"return",
"uniqBy",
"(",
"internalTowersInfo",
".",
"concat",
"(",
"ext... | Loads the installed towers.
@returns {Tower[]} The loaded towers. | [
"Loads",
"the",
"installed",
"towers",
"."
] | ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8 | https://github.com/olistic/warriorjs/blob/ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8/packages/warriorjs-cli/src/loadTowers.js#L60-L69 | train |
olistic/warriorjs | packages/warriorjs-geography/src/rotateRelativeOffset.js | rotateRelativeOffset | function rotateRelativeOffset([forward, right], direction) {
verifyRelativeDirection(direction);
if (direction === FORWARD) {
return [forward, right];
}
if (direction === RIGHT) {
return [-right, forward];
}
if (direction === BACKWARD) {
return [-forward, -right];
}
return [right, -forwa... | javascript | function rotateRelativeOffset([forward, right], direction) {
verifyRelativeDirection(direction);
if (direction === FORWARD) {
return [forward, right];
}
if (direction === RIGHT) {
return [-right, forward];
}
if (direction === BACKWARD) {
return [-forward, -right];
}
return [right, -forwa... | [
"function",
"rotateRelativeOffset",
"(",
"[",
"forward",
",",
"right",
"]",
",",
"direction",
")",
"{",
"verifyRelativeDirection",
"(",
"direction",
")",
";",
"if",
"(",
"direction",
"===",
"FORWARD",
")",
"{",
"return",
"[",
"forward",
",",
"right",
"]",
... | Rotates the given relative offset in the given direction.
@param {number[]} offset The relative offset as [forward, right].
@param {string} direction The direction (relative direction).
@returns {number[]} The rotated offset as [forward, right]. | [
"Rotates",
"the",
"given",
"relative",
"offset",
"in",
"the",
"given",
"direction",
"."
] | ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8 | https://github.com/olistic/warriorjs/blob/ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8/packages/warriorjs-geography/src/rotateRelativeOffset.js#L12-L28 | train |
olistic/warriorjs | packages/warriorjs-cli/src/ui/requestChoice.js | requestChoice | async function requestChoice(message, items) {
const answerName = 'requestChoice';
const answers = await inquirer.prompt([
{
message,
name: answerName,
type: 'list',
choices: getChoices(items),
},
]);
return answers[answerName];
} | javascript | async function requestChoice(message, items) {
const answerName = 'requestChoice';
const answers = await inquirer.prompt([
{
message,
name: answerName,
type: 'list',
choices: getChoices(items),
},
]);
return answers[answerName];
} | [
"async",
"function",
"requestChoice",
"(",
"message",
",",
"items",
")",
"{",
"const",
"answerName",
"=",
"'requestChoice'",
";",
"const",
"answers",
"=",
"await",
"inquirer",
".",
"prompt",
"(",
"[",
"{",
"message",
",",
"name",
":",
"answerName",
",",
"t... | Requests a selection of one of the given items from the user.
@param {string} message The prompt message.
@param {any[]} items The items to choose from. | [
"Requests",
"a",
"selection",
"of",
"one",
"of",
"the",
"given",
"items",
"from",
"the",
"user",
"."
] | ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8 | https://github.com/olistic/warriorjs/blob/ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8/packages/warriorjs-cli/src/ui/requestChoice.js#L25-L36 | train |
olistic/warriorjs | packages/warriorjs-cli/src/ui/printBoard.js | printBoard | function printBoard(floorMap, warriorStatus, offset) {
if (offset > 0) {
const floorMapRows = floorMap.length;
print(ansiEscapes.cursorUp(offset + floorMapRows + warriorStatusRows));
}
printWarriorStatus(warriorStatus);
printFloorMap(floorMap);
if (offset > 0) {
print(ansiEscapes.cursorDown(offs... | javascript | function printBoard(floorMap, warriorStatus, offset) {
if (offset > 0) {
const floorMapRows = floorMap.length;
print(ansiEscapes.cursorUp(offset + floorMapRows + warriorStatusRows));
}
printWarriorStatus(warriorStatus);
printFloorMap(floorMap);
if (offset > 0) {
print(ansiEscapes.cursorDown(offs... | [
"function",
"printBoard",
"(",
"floorMap",
",",
"warriorStatus",
",",
"offset",
")",
"{",
"if",
"(",
"offset",
">",
"0",
")",
"{",
"const",
"floorMapRows",
"=",
"floorMap",
".",
"length",
";",
"print",
"(",
"ansiEscapes",
".",
"cursorUp",
"(",
"offset",
... | Prints the game board after moving the cursor up a given number of rows.
@param {Object[][]} floorMap The map of the floor.
@param {Object} warriorStatus The status of the warrior.
@param {number} offset The number of rows. | [
"Prints",
"the",
"game",
"board",
"after",
"moving",
"the",
"cursor",
"up",
"a",
"given",
"number",
"of",
"rows",
"."
] | ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8 | https://github.com/olistic/warriorjs/blob/ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8/packages/warriorjs-cli/src/ui/printBoard.js#L16-L28 | train |
olistic/warriorjs | packages/warriorjs-helper-get-level-score/src/getRemainingTimeBonus.js | getRemainingTimeBonus | function getRemainingTimeBonus(events, timeBonus) {
const turnCount = getTurnCount(events);
const remainingTimeBonus = timeBonus - turnCount;
return Math.max(remainingTimeBonus, 0);
} | javascript | function getRemainingTimeBonus(events, timeBonus) {
const turnCount = getTurnCount(events);
const remainingTimeBonus = timeBonus - turnCount;
return Math.max(remainingTimeBonus, 0);
} | [
"function",
"getRemainingTimeBonus",
"(",
"events",
",",
"timeBonus",
")",
"{",
"const",
"turnCount",
"=",
"getTurnCount",
"(",
"events",
")",
";",
"const",
"remainingTimeBonus",
"=",
"timeBonus",
"-",
"turnCount",
";",
"return",
"Math",
".",
"max",
"(",
"rema... | Returns the remaining time bonus.
@param {Object[][]} events The events that happened during the play.
@param {number} timeBonus The initial time bonus.
@returns {number} The time bonus. | [
"Returns",
"the",
"remaining",
"time",
"bonus",
"."
] | ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8 | https://github.com/olistic/warriorjs/blob/ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8/packages/warriorjs-helper-get-level-score/src/getRemainingTimeBonus.js#L11-L15 | train |
olistic/warriorjs | packages/warriorjs-cli/src/ui/requestInput.js | requestInput | async function requestInput(message, suggestions = []) {
const answerName = 'requestInput';
const answers = await inquirer.prompt([
{
message,
suggestions,
name: answerName,
type: suggestions.length ? 'suggest' : 'input',
},
]);
return answers[answerName];
} | javascript | async function requestInput(message, suggestions = []) {
const answerName = 'requestInput';
const answers = await inquirer.prompt([
{
message,
suggestions,
name: answerName,
type: suggestions.length ? 'suggest' : 'input',
},
]);
return answers[answerName];
} | [
"async",
"function",
"requestInput",
"(",
"message",
",",
"suggestions",
"=",
"[",
"]",
")",
"{",
"const",
"answerName",
"=",
"'requestInput'",
";",
"const",
"answers",
"=",
"await",
"inquirer",
".",
"prompt",
"(",
"[",
"{",
"message",
",",
"suggestions",
... | Requests input from the user.
@param {string} message The prompt message.
@param {string[]} suggestions The input suggestions. | [
"Requests",
"input",
"from",
"the",
"user",
"."
] | ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8 | https://github.com/olistic/warriorjs/blob/ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8/packages/warriorjs-cli/src/ui/requestInput.js#L11-L22 | train |
olistic/warriorjs | packages/warriorjs-core/src/getLevel.js | getLevel | function getLevel(levelConfig) {
const level = loadLevel(levelConfig);
return JSON.parse(JSON.stringify(level));
} | javascript | function getLevel(levelConfig) {
const level = loadLevel(levelConfig);
return JSON.parse(JSON.stringify(level));
} | [
"function",
"getLevel",
"(",
"levelConfig",
")",
"{",
"const",
"level",
"=",
"loadLevel",
"(",
"levelConfig",
")",
";",
"return",
"JSON",
".",
"parse",
"(",
"JSON",
".",
"stringify",
"(",
"level",
")",
")",
";",
"}"
] | Returns the level for the given level config.
@param {Object} levelConfig The config of the level.
@returns {Object} The level. | [
"Returns",
"the",
"level",
"for",
"the",
"given",
"level",
"config",
"."
] | ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8 | https://github.com/olistic/warriorjs/blob/ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8/packages/warriorjs-core/src/getLevel.js#L10-L13 | train |
olistic/warriorjs | packages/warriorjs-cli/src/ui/printTotalScore.js | printTotalScore | function printTotalScore(currentScore, addition) {
if (currentScore === 0) {
printLine(`Total Score: ${addition.toString()}`);
} else {
printLine(
`Total Score: ${currentScore} + ${addition} = ${currentScore + addition}`,
);
}
} | javascript | function printTotalScore(currentScore, addition) {
if (currentScore === 0) {
printLine(`Total Score: ${addition.toString()}`);
} else {
printLine(
`Total Score: ${currentScore} + ${addition} = ${currentScore + addition}`,
);
}
} | [
"function",
"printTotalScore",
"(",
"currentScore",
",",
"addition",
")",
"{",
"if",
"(",
"currentScore",
"===",
"0",
")",
"{",
"printLine",
"(",
"`",
"${",
"addition",
".",
"toString",
"(",
")",
"}",
"`",
")",
";",
"}",
"else",
"{",
"printLine",
"(",
... | Prints the total score as the sum of the current score and the addition.
If the current score is zero, just the addition and not the sum will be
printed.
@param {number} currentScore The current score.
@param {number} addition The score to add to the current score. | [
"Prints",
"the",
"total",
"score",
"as",
"the",
"sum",
"of",
"the",
"current",
"score",
"and",
"the",
"addition",
"."
] | ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8 | https://github.com/olistic/warriorjs/blob/ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8/packages/warriorjs-cli/src/ui/printTotalScore.js#L12-L20 | train |
olistic/warriorjs | packages/warriorjs-cli/src/ui/printPlay.js | printPlay | async function printPlay(events, delay) {
let turnNumber = 0;
let boardOffset = 0;
await sleep(delay);
// eslint-disable-next-line no-restricted-syntax
for (const turnEvents of events) {
turnNumber += 1;
boardOffset = 0;
printTurnHeader(turnNumber);
// eslint-disable-next-line no-restricted... | javascript | async function printPlay(events, delay) {
let turnNumber = 0;
let boardOffset = 0;
await sleep(delay);
// eslint-disable-next-line no-restricted-syntax
for (const turnEvents of events) {
turnNumber += 1;
boardOffset = 0;
printTurnHeader(turnNumber);
// eslint-disable-next-line no-restricted... | [
"async",
"function",
"printPlay",
"(",
"events",
",",
"delay",
")",
"{",
"let",
"turnNumber",
"=",
"0",
";",
"let",
"boardOffset",
"=",
"0",
";",
"await",
"sleep",
"(",
"delay",
")",
";",
"// eslint-disable-next-line no-restricted-syntax",
"for",
"(",
"const",... | Prints a play.
@param {Object[]} events The events that happened during the play.
@param {nunber} delay The delay between each turn in ms. | [
"Prints",
"a",
"play",
"."
] | ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8 | https://github.com/olistic/warriorjs/blob/ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8/packages/warriorjs-cli/src/ui/printPlay.js#L13-L34 | train |
olistic/warriorjs | packages/warriorjs-helper-get-level-score/src/isFloorClear.js | isFloorClear | function isFloorClear(floorMap) {
const spaces = floorMap.reduce((acc, val) => acc.concat(val), []);
const unitCount = spaces.filter(space => !!space.unit).length;
return unitCount <= 1;
} | javascript | function isFloorClear(floorMap) {
const spaces = floorMap.reduce((acc, val) => acc.concat(val), []);
const unitCount = spaces.filter(space => !!space.unit).length;
return unitCount <= 1;
} | [
"function",
"isFloorClear",
"(",
"floorMap",
")",
"{",
"const",
"spaces",
"=",
"floorMap",
".",
"reduce",
"(",
"(",
"acc",
",",
"val",
")",
"=>",
"acc",
".",
"concat",
"(",
"val",
")",
",",
"[",
"]",
")",
";",
"const",
"unitCount",
"=",
"spaces",
"... | Checks if the floor is clear.
The floor is clear when there are no units other than the warrior.
@returns {boolean} Whether the floor is clear or not. | [
"Checks",
"if",
"the",
"floor",
"is",
"clear",
"."
] | ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8 | https://github.com/olistic/warriorjs/blob/ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8/packages/warriorjs-helper-get-level-score/src/isFloorClear.js#L8-L12 | train |
olistic/warriorjs | packages/warriorjs-cli/src/ui/printLevelHeader.js | printLevelHeader | function printLevelHeader(levelNumber) {
printRow(chalk.gray.dim(` level ${levelNumber} `), {
position: 'middle',
padding: chalk.gray.dim('~'),
});
} | javascript | function printLevelHeader(levelNumber) {
printRow(chalk.gray.dim(` level ${levelNumber} `), {
position: 'middle',
padding: chalk.gray.dim('~'),
});
} | [
"function",
"printLevelHeader",
"(",
"levelNumber",
")",
"{",
"printRow",
"(",
"chalk",
".",
"gray",
".",
"dim",
"(",
"`",
"${",
"levelNumber",
"}",
"`",
")",
",",
"{",
"position",
":",
"'middle'",
",",
"padding",
":",
"chalk",
".",
"gray",
".",
"dim",... | Prints the level header.
@param {number} levelNumber The level number. | [
"Prints",
"the",
"level",
"header",
"."
] | ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8 | https://github.com/olistic/warriorjs/blob/ec531b4d4b6b7c3e51e5adbd03f575af56ebebc8/packages/warriorjs-cli/src/ui/printLevelHeader.js#L10-L15 | train |
jsforce/jsforce | lib/query.js | function(err, res) {
if (_.isFunction(callback)) {
try {
res = callback(err, res);
err = null;
} catch(e) {
err = e;
}
}
if (err) {
deferred.reject(err);
} else {
deferred.resolve(res);
}
} | javascript | function(err, res) {
if (_.isFunction(callback)) {
try {
res = callback(err, res);
err = null;
} catch(e) {
err = e;
}
}
if (err) {
deferred.reject(err);
} else {
deferred.resolve(res);
}
} | [
"function",
"(",
"err",
",",
"res",
")",
"{",
"if",
"(",
"_",
".",
"isFunction",
"(",
"callback",
")",
")",
"{",
"try",
"{",
"res",
"=",
"callback",
"(",
"err",
",",
"res",
")",
";",
"err",
"=",
"null",
";",
"}",
"catch",
"(",
"e",
")",
"{",
... | callback and promise resolution; | [
"callback",
"and",
"promise",
"resolution",
";"
] | 3f9e567dd063c0a912594198a187ececf642cfa7 | https://github.com/jsforce/jsforce/blob/3f9e567dd063c0a912594198a187ececf642cfa7/lib/query.js#L334-L348 | train | |
jsforce/jsforce | lib/oauth2.js | function(params) {
params = _.extend({
response_type : "code",
client_id : this.clientId,
redirect_uri : this.redirectUri
}, params || {});
return this.authzServiceUrl +
(this.authzServiceUrl.indexOf('?') >= 0 ? "&" : "?") +
querystring.stringify(params);
} | javascript | function(params) {
params = _.extend({
response_type : "code",
client_id : this.clientId,
redirect_uri : this.redirectUri
}, params || {});
return this.authzServiceUrl +
(this.authzServiceUrl.indexOf('?') >= 0 ? "&" : "?") +
querystring.stringify(params);
} | [
"function",
"(",
"params",
")",
"{",
"params",
"=",
"_",
".",
"extend",
"(",
"{",
"response_type",
":",
"\"code\"",
",",
"client_id",
":",
"this",
".",
"clientId",
",",
"redirect_uri",
":",
"this",
".",
"redirectUri",
"}",
",",
"params",
"||",
"{",
"}"... | Get Salesforce OAuth2 authorization page URL to redirect user agent.
@param {Object} params - Parameters
@param {String} [params.scope] - Scope values in space-separated string
@param {String} [params.state] - State parameter
@param {String} [params.code_challenge] - Code challenge value (RFC 7636 - Proof Key of Code ... | [
"Get",
"Salesforce",
"OAuth2",
"authorization",
"page",
"URL",
"to",
"redirect",
"user",
"agent",
"."
] | 3f9e567dd063c0a912594198a187ececf642cfa7 | https://github.com/jsforce/jsforce/blob/3f9e567dd063c0a912594198a187ececf642cfa7/lib/oauth2.js#L69-L78 | train | |
jsforce/jsforce | lib/oauth2.js | function(token, callback) {
return this._transport.httpRequest({
method : 'POST',
url : this.revokeServiceUrl,
body: querystring.stringify({ token: token }),
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
}).then(function(response) {
if (response.sta... | javascript | function(token, callback) {
return this._transport.httpRequest({
method : 'POST',
url : this.revokeServiceUrl,
body: querystring.stringify({ token: token }),
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
}).then(function(response) {
if (response.sta... | [
"function",
"(",
"token",
",",
"callback",
")",
"{",
"return",
"this",
".",
"_transport",
".",
"httpRequest",
"(",
"{",
"method",
":",
"'POST'",
",",
"url",
":",
"this",
".",
"revokeServiceUrl",
",",
"body",
":",
"querystring",
".",
"stringify",
"(",
"{"... | OAuth2 Revoke Session or API Token
@param {String} token - Access or Refresh token to revoke. Passing in the Access token revokes the session. Passing in the Refresh token revokes API Access.
@param {Callback.<undefined>} [callback] - Callback function
@returns {Promise.<undefined>} | [
"OAuth2",
"Revoke",
"Session",
"or",
"API",
"Token"
] | 3f9e567dd063c0a912594198a187ececf642cfa7 | https://github.com/jsforce/jsforce/blob/3f9e567dd063c0a912594198a187ececf642cfa7/lib/oauth2.js#L159-L178 | train | |
jsforce/jsforce | lib/cache.js | createCacheKey | function createCacheKey(namespace, args) {
args = Array.prototype.slice.apply(args);
return namespace + '(' + _.map(args, function(a){ return JSON.stringify(a); }).join(',') + ')';
} | javascript | function createCacheKey(namespace, args) {
args = Array.prototype.slice.apply(args);
return namespace + '(' + _.map(args, function(a){ return JSON.stringify(a); }).join(',') + ')';
} | [
"function",
"createCacheKey",
"(",
"namespace",
",",
"args",
")",
"{",
"args",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"apply",
"(",
"args",
")",
";",
"return",
"namespace",
"+",
"'('",
"+",
"_",
".",
"map",
"(",
"args",
",",
"function",
"... | create and return cache key from namespace and serialized arguments.
@private | [
"create",
"and",
"return",
"cache",
"key",
"from",
"namespace",
"and",
"serialized",
"arguments",
"."
] | 3f9e567dd063c0a912594198a187ececf642cfa7 | https://github.com/jsforce/jsforce/blob/3f9e567dd063c0a912594198a187ececf642cfa7/lib/cache.js#L104-L107 | train |
jsforce/jsforce | lib/http-api.js | function(conn, options) {
options = options || {};
this._conn = conn;
this.on('resume', function(err) { conn.emit('resume', err); });
this._responseType = options.responseType;
this._transport = options.transport || conn._transport;
this._noContentResponse = options.noContentResponse;
} | javascript | function(conn, options) {
options = options || {};
this._conn = conn;
this.on('resume', function(err) { conn.emit('resume', err); });
this._responseType = options.responseType;
this._transport = options.transport || conn._transport;
this._noContentResponse = options.noContentResponse;
} | [
"function",
"(",
"conn",
",",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"this",
".",
"_conn",
"=",
"conn",
";",
"this",
".",
"on",
"(",
"'resume'",
",",
"function",
"(",
"err",
")",
"{",
"conn",
".",
"emit",
"(",
"'resu... | HTTP based API class with authorization hook
@constructor
@extends events.EventEmitter
@param {Connection} conn - Connection object
@param {Object} [options] - Http API Options
@param {String} [options.responseType] - Overriding content mime-type in response
@param {Transport} [options.transport] - Transport for http ... | [
"HTTP",
"based",
"API",
"class",
"with",
"authorization",
"hook"
] | 3f9e567dd063c0a912594198a187ececf642cfa7 | https://github.com/jsforce/jsforce/blob/3f9e567dd063c0a912594198a187ececf642cfa7/lib/http-api.js#L19-L26 | train | |
jsforce/jsforce | lib/cli/repl.js | injectBefore | function injectBefore(replServer, method, beforeFn) {
var _orig = replServer[method];
replServer[method] = function() {
var args = Array.prototype.slice.call(arguments);
var callback = args.pop();
beforeFn.apply(null, args.concat(function(err, res) {
if (err || res) {
callback(err, res);
... | javascript | function injectBefore(replServer, method, beforeFn) {
var _orig = replServer[method];
replServer[method] = function() {
var args = Array.prototype.slice.call(arguments);
var callback = args.pop();
beforeFn.apply(null, args.concat(function(err, res) {
if (err || res) {
callback(err, res);
... | [
"function",
"injectBefore",
"(",
"replServer",
",",
"method",
",",
"beforeFn",
")",
"{",
"var",
"_orig",
"=",
"replServer",
"[",
"method",
"]",
";",
"replServer",
"[",
"method",
"]",
"=",
"function",
"(",
")",
"{",
"var",
"args",
"=",
"Array",
".",
"pr... | Intercept the evaled value returned from repl evaluator, convert and send back to output.
@private | [
"Intercept",
"the",
"evaled",
"value",
"returned",
"from",
"repl",
"evaluator",
"convert",
"and",
"send",
"back",
"to",
"output",
"."
] | 3f9e567dd063c0a912594198a187ececf642cfa7 | https://github.com/jsforce/jsforce/blob/3f9e567dd063c0a912594198a187ececf642cfa7/lib/cli/repl.js#L21-L35 | train |
jsforce/jsforce | lib/cli/repl.js | promisify | function promisify(err, value, callback) {
if (err) { throw err; }
if (isPromiseLike(value)) {
value.then(function(v) {
callback(null, v);
}, function(err) {
callback(err);
});
} else {
callback(null, value);
}
} | javascript | function promisify(err, value, callback) {
if (err) { throw err; }
if (isPromiseLike(value)) {
value.then(function(v) {
callback(null, v);
}, function(err) {
callback(err);
});
} else {
callback(null, value);
}
} | [
"function",
"promisify",
"(",
"err",
",",
"value",
",",
"callback",
")",
"{",
"if",
"(",
"err",
")",
"{",
"throw",
"err",
";",
"}",
"if",
"(",
"isPromiseLike",
"(",
"value",
")",
")",
"{",
"value",
".",
"then",
"(",
"function",
"(",
"v",
")",
"{"... | When the result was "promise", resolve its value
@private | [
"When",
"the",
"result",
"was",
"promise",
"resolve",
"its",
"value"
] | 3f9e567dd063c0a912594198a187ececf642cfa7 | https://github.com/jsforce/jsforce/blob/3f9e567dd063c0a912594198a187ececf642cfa7/lib/cli/repl.js#L62-L73 | train |
jsforce/jsforce | lib/cli/repl.js | outputToStdout | function outputToStdout(prettyPrint) {
if (prettyPrint && !_.isNumber(prettyPrint)) {
prettyPrint = 4;
}
return function(err, value, callback) {
if (err) {
console.error(err);
} else {
var str = JSON.stringify(value, null, prettyPrint);
console.log(str);
}
callback(err, value... | javascript | function outputToStdout(prettyPrint) {
if (prettyPrint && !_.isNumber(prettyPrint)) {
prettyPrint = 4;
}
return function(err, value, callback) {
if (err) {
console.error(err);
} else {
var str = JSON.stringify(value, null, prettyPrint);
console.log(str);
}
callback(err, value... | [
"function",
"outputToStdout",
"(",
"prettyPrint",
")",
"{",
"if",
"(",
"prettyPrint",
"&&",
"!",
"_",
".",
"isNumber",
"(",
"prettyPrint",
")",
")",
"{",
"prettyPrint",
"=",
"4",
";",
"}",
"return",
"function",
"(",
"err",
",",
"value",
",",
"callback",
... | Output object to stdout in JSON representation
@private | [
"Output",
"object",
"to",
"stdout",
"in",
"JSON",
"representation"
] | 3f9e567dd063c0a912594198a187ececf642cfa7 | https://github.com/jsforce/jsforce/blob/3f9e567dd063c0a912594198a187ececf642cfa7/lib/cli/repl.js#L87-L100 | train |
babel/minify | packages/babel-plugin-minify-simplify/src/index.js | function(path) {
const { node } = path;
if (node.declarations.length < 2) {
return;
}
const inits = [];
const empty = [];
for (const decl of node.declarations) {
if (!decl.init) {
empty.push(decl);
... | javascript | function(path) {
const { node } = path;
if (node.declarations.length < 2) {
return;
}
const inits = [];
const empty = [];
for (const decl of node.declarations) {
if (!decl.init) {
empty.push(decl);
... | [
"function",
"(",
"path",
")",
"{",
"const",
"{",
"node",
"}",
"=",
"path",
";",
"if",
"(",
"node",
".",
"declarations",
".",
"length",
"<",
"2",
")",
"{",
"return",
";",
"}",
"const",
"inits",
"=",
"[",
"]",
";",
"const",
"empty",
"=",
"[",
"]"... | Put vars with no init at the top. | [
"Put",
"vars",
"with",
"no",
"init",
"at",
"the",
"top",
"."
] | 6b8bab6bf5905ebc3a5a9130662a5fef34886de4 | https://github.com/babel/minify/blob/6b8bab6bf5905ebc3a5a9130662a5fef34886de4/packages/babel-plugin-minify-simplify/src/index.js#L278-L303 | train | |
babel/minify | packages/babel-plugin-minify-simplify/src/index.js | function(path) {
const { node } = path;
if (
!path.parentPath.parentPath.isFunction() ||
path.getSibling(path.key + 1).node
) {
return;
}
if (!node.argument) {
path.remove();
return;
... | javascript | function(path) {
const { node } = path;
if (
!path.parentPath.parentPath.isFunction() ||
path.getSibling(path.key + 1).node
) {
return;
}
if (!node.argument) {
path.remove();
return;
... | [
"function",
"(",
"path",
")",
"{",
"const",
"{",
"node",
"}",
"=",
"path",
";",
"if",
"(",
"!",
"path",
".",
"parentPath",
".",
"parentPath",
".",
"isFunction",
"(",
")",
"||",
"path",
".",
"getSibling",
"(",
"path",
".",
"key",
"+",
"1",
")",
".... | Remove return if last statement with no argument. Replace return with `void` argument with argument. | [
"Remove",
"return",
"if",
"last",
"statement",
"with",
"no",
"argument",
".",
"Replace",
"return",
"with",
"void",
"argument",
"with",
"argument",
"."
] | 6b8bab6bf5905ebc3a5a9130662a5fef34886de4 | https://github.com/babel/minify/blob/6b8bab6bf5905ebc3a5a9130662a5fef34886de4/packages/babel-plugin-minify-simplify/src/index.js#L592-L610 | train | |
babel/minify | packages/babel-plugin-minify-simplify/src/index.js | function(path) {
const { node } = path;
// Need to be careful of side-effects.
if (!t.isIdentifier(node.discriminant)) {
return;
}
if (!node.cases.length) {
return;
}
const consTestPairs = [];
... | javascript | function(path) {
const { node } = path;
// Need to be careful of side-effects.
if (!t.isIdentifier(node.discriminant)) {
return;
}
if (!node.cases.length) {
return;
}
const consTestPairs = [];
... | [
"function",
"(",
"path",
")",
"{",
"const",
"{",
"node",
"}",
"=",
"path",
";",
"// Need to be careful of side-effects.",
"if",
"(",
"!",
"t",
".",
"isIdentifier",
"(",
"node",
".",
"discriminant",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"no... | Convert switch statements with all returns in their cases to return conditional. | [
"Convert",
"switch",
"statements",
"with",
"all",
"returns",
"in",
"their",
"cases",
"to",
"return",
"conditional",
"."
] | 6b8bab6bf5905ebc3a5a9130662a5fef34886de4 | https://github.com/babel/minify/blob/6b8bab6bf5905ebc3a5a9130662a5fef34886de4/packages/babel-plugin-minify-simplify/src/index.js#L670-L774 | train | |
babel/minify | packages/babel-plugin-minify-simplify/src/index.js | function(path) {
const { node } = path;
// Need to be careful of side-effects.
if (!t.isIdentifier(node.discriminant)) {
return;
}
if (!node.cases.length) {
return;
}
const exprTestPairs = [];
... | javascript | function(path) {
const { node } = path;
// Need to be careful of side-effects.
if (!t.isIdentifier(node.discriminant)) {
return;
}
if (!node.cases.length) {
return;
}
const exprTestPairs = [];
... | [
"function",
"(",
"path",
")",
"{",
"const",
"{",
"node",
"}",
"=",
"path",
";",
"// Need to be careful of side-effects.",
"if",
"(",
"!",
"t",
".",
"isIdentifier",
"(",
"node",
".",
"discriminant",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"no... | Convert switches into conditionals. | [
"Convert",
"switches",
"into",
"conditionals",
"."
] | 6b8bab6bf5905ebc3a5a9130662a5fef34886de4 | https://github.com/babel/minify/blob/6b8bab6bf5905ebc3a5a9130662a5fef34886de4/packages/babel-plugin-minify-simplify/src/index.js#L777-L856 | train | |
babel/minify | packages/babel-plugin-minify-simplify/src/if-statement.js | toGuardedExpression | function toGuardedExpression(path) {
const { node } = path;
if (
node.consequent &&
!node.alternate &&
node.consequent.type === "ExpressionStatement"
) {
let op = "&&";
if (t.isUnaryExpression(node.test, { operator: "!" })) {
node.test = node.test.argument;
op =... | javascript | function toGuardedExpression(path) {
const { node } = path;
if (
node.consequent &&
!node.alternate &&
node.consequent.type === "ExpressionStatement"
) {
let op = "&&";
if (t.isUnaryExpression(node.test, { operator: "!" })) {
node.test = node.test.argument;
op =... | [
"function",
"toGuardedExpression",
"(",
"path",
")",
"{",
"const",
"{",
"node",
"}",
"=",
"path",
";",
"if",
"(",
"node",
".",
"consequent",
"&&",
"!",
"node",
".",
"alternate",
"&&",
"node",
".",
"consequent",
".",
"type",
"===",
"\"ExpressionStatement\""... | No alternate, make into a guarded expression | [
"No",
"alternate",
"make",
"into",
"a",
"guarded",
"expression"
] | 6b8bab6bf5905ebc3a5a9130662a5fef34886de4 | https://github.com/babel/minify/blob/6b8bab6bf5905ebc3a5a9130662a5fef34886de4/packages/babel-plugin-minify-simplify/src/if-statement.js#L24-L44 | train |
babel/minify | packages/babel-plugin-minify-simplify/src/if-statement.js | toTernary | function toTernary(path) {
const { node } = path;
if (
t.isExpressionStatement(node.consequent) &&
t.isExpressionStatement(node.alternate)
) {
path.replaceWith(
t.conditionalExpression(
node.test,
node.consequent.expression,
node.alternate.expression
... | javascript | function toTernary(path) {
const { node } = path;
if (
t.isExpressionStatement(node.consequent) &&
t.isExpressionStatement(node.alternate)
) {
path.replaceWith(
t.conditionalExpression(
node.test,
node.consequent.expression,
node.alternate.expression
... | [
"function",
"toTernary",
"(",
"path",
")",
"{",
"const",
"{",
"node",
"}",
"=",
"path",
";",
"if",
"(",
"t",
".",
"isExpressionStatement",
"(",
"node",
".",
"consequent",
")",
"&&",
"t",
".",
"isExpressionStatement",
"(",
"node",
".",
"alternate",
")",
... | both consequent and alternate are expressions, turn into ternary | [
"both",
"consequent",
"and",
"alternate",
"are",
"expressions",
"turn",
"into",
"ternary"
] | 6b8bab6bf5905ebc3a5a9130662a5fef34886de4 | https://github.com/babel/minify/blob/6b8bab6bf5905ebc3a5a9130662a5fef34886de4/packages/babel-plugin-minify-simplify/src/if-statement.js#L47-L62 | train |
babel/minify | packages/babel-plugin-minify-simplify/src/if-statement.js | removeUnnecessaryElse | function removeUnnecessaryElse(path) {
const { node } = path;
const consequent = path.get("consequent");
const alternate = path.get("alternate");
if (
consequent.node &&
alternate.node &&
(consequent.isReturnStatement() ||
(consequent.isBlockStatement() &&
t.isReturn... | javascript | function removeUnnecessaryElse(path) {
const { node } = path;
const consequent = path.get("consequent");
const alternate = path.get("alternate");
if (
consequent.node &&
alternate.node &&
(consequent.isReturnStatement() ||
(consequent.isBlockStatement() &&
t.isReturn... | [
"function",
"removeUnnecessaryElse",
"(",
"path",
")",
"{",
"const",
"{",
"node",
"}",
"=",
"path",
";",
"const",
"consequent",
"=",
"path",
".",
"get",
"(",
"\"consequent\"",
")",
";",
"const",
"alternate",
"=",
"path",
".",
"get",
"(",
"\"alternate\"",
... | Remove else for if-return | [
"Remove",
"else",
"for",
"if",
"-",
"return"
] | 6b8bab6bf5905ebc3a5a9130662a5fef34886de4 | https://github.com/babel/minify/blob/6b8bab6bf5905ebc3a5a9130662a5fef34886de4/packages/babel-plugin-minify-simplify/src/if-statement.js#L267-L300 | train |
babel/minify | packages/babel-plugin-minify-simplify/src/if-statement.js | switchConsequent | function switchConsequent(path) {
const { node } = path;
if (!node.alternate) {
return;
}
if (!t.isIfStatement(node.consequent)) {
return;
}
if (t.isIfStatement(node.alternate)) {
return;
}
node.test = t.unaryExpression("!", node.test, true);
[node.alternate, no... | javascript | function switchConsequent(path) {
const { node } = path;
if (!node.alternate) {
return;
}
if (!t.isIfStatement(node.consequent)) {
return;
}
if (t.isIfStatement(node.alternate)) {
return;
}
node.test = t.unaryExpression("!", node.test, true);
[node.alternate, no... | [
"function",
"switchConsequent",
"(",
"path",
")",
"{",
"const",
"{",
"node",
"}",
"=",
"path",
";",
"if",
"(",
"!",
"node",
".",
"alternate",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"t",
".",
"isIfStatement",
"(",
"node",
".",
"consequent",
"... | If the consequent is if and the altenrate is not then switch them out. That way we know we don't have to print a block.x | [
"If",
"the",
"consequent",
"is",
"if",
"and",
"the",
"altenrate",
"is",
"not",
"then",
"switch",
"them",
"out",
".",
"That",
"way",
"we",
"know",
"we",
"don",
"t",
"have",
"to",
"print",
"a",
"block",
".",
"x"
] | 6b8bab6bf5905ebc3a5a9130662a5fef34886de4 | https://github.com/babel/minify/blob/6b8bab6bf5905ebc3a5a9130662a5fef34886de4/packages/babel-plugin-minify-simplify/src/if-statement.js#L325-L342 | train |
babel/minify | packages/babel-plugin-minify-simplify/src/if-statement.js | conditionalReturnToGuards | function conditionalReturnToGuards(path) {
const { node } = path;
if (
!path.inList ||
!path.get("consequent").isBlockStatement() ||
node.alternate
) {
return;
}
let ret;
let test;
const exprs = [];
const statements = node.consequent.body;
for (let i = 0, s... | javascript | function conditionalReturnToGuards(path) {
const { node } = path;
if (
!path.inList ||
!path.get("consequent").isBlockStatement() ||
node.alternate
) {
return;
}
let ret;
let test;
const exprs = [];
const statements = node.consequent.body;
for (let i = 0, s... | [
"function",
"conditionalReturnToGuards",
"(",
"path",
")",
"{",
"const",
"{",
"node",
"}",
"=",
"path",
";",
"if",
"(",
"!",
"path",
".",
"inList",
"||",
"!",
"path",
".",
"get",
"(",
"\"consequent\"",
")",
".",
"isBlockStatement",
"(",
")",
"||",
"nod... | Make if statements with conditional returns in the body into an if statement that guards the rest of the block. | [
"Make",
"if",
"statements",
"with",
"conditional",
"returns",
"in",
"the",
"body",
"into",
"an",
"if",
"statement",
"that",
"guards",
"the",
"rest",
"of",
"the",
"block",
"."
] | 6b8bab6bf5905ebc3a5a9130662a5fef34886de4 | https://github.com/babel/minify/blob/6b8bab6bf5905ebc3a5a9130662a5fef34886de4/packages/babel-plugin-minify-simplify/src/if-statement.js#L346-L394 | train |
babel/minify | utils/unpad/src/unpad.js | unpad | function unpad(str) {
const lines = str.split("\n");
const m = lines[1] && lines[1].match(/^\s+/);
if (!m) {
return str;
}
const spaces = m[0].length;
return lines
.map(line => line.slice(spaces))
.join("\n")
.trim();
} | javascript | function unpad(str) {
const lines = str.split("\n");
const m = lines[1] && lines[1].match(/^\s+/);
if (!m) {
return str;
}
const spaces = m[0].length;
return lines
.map(line => line.slice(spaces))
.join("\n")
.trim();
} | [
"function",
"unpad",
"(",
"str",
")",
"{",
"const",
"lines",
"=",
"str",
".",
"split",
"(",
"\"\\n\"",
")",
";",
"const",
"m",
"=",
"lines",
"[",
"1",
"]",
"&&",
"lines",
"[",
"1",
"]",
".",
"match",
"(",
"/",
"^\\s+",
"/",
")",
";",
"if",
"(... | Remove padding from a string. | [
"Remove",
"padding",
"from",
"a",
"string",
"."
] | 6b8bab6bf5905ebc3a5a9130662a5fef34886de4 | https://github.com/babel/minify/blob/6b8bab6bf5905ebc3a5a9130662a5fef34886de4/utils/unpad/src/unpad.js#L2-L13 | train |
babel/minify | packages/babel-plugin-transform-simplify-comparison-operators/src/index.js | baseTypeStrictlyMatches | function baseTypeStrictlyMatches(left, right) {
let leftTypes, rightTypes;
if (t.isIdentifier(left)) {
leftTypes = customTypeAnnotation(left);
} else if (t.isIdentifier(right)) {
rightTypes = customTypeAnnotation(right);
}
// Early exit
if (t.isAnyTypeAnnotation(leftTypes) || t.isA... | javascript | function baseTypeStrictlyMatches(left, right) {
let leftTypes, rightTypes;
if (t.isIdentifier(left)) {
leftTypes = customTypeAnnotation(left);
} else if (t.isIdentifier(right)) {
rightTypes = customTypeAnnotation(right);
}
// Early exit
if (t.isAnyTypeAnnotation(leftTypes) || t.isA... | [
"function",
"baseTypeStrictlyMatches",
"(",
"left",
",",
"right",
")",
"{",
"let",
"leftTypes",
",",
"rightTypes",
";",
"if",
"(",
"t",
".",
"isIdentifier",
"(",
"left",
")",
")",
"{",
"leftTypes",
"=",
"customTypeAnnotation",
"(",
"left",
")",
";",
"}",
... | Based on the type inference in Babel | [
"Based",
"on",
"the",
"type",
"inference",
"in",
"Babel"
] | 6b8bab6bf5905ebc3a5a9130662a5fef34886de4 | https://github.com/babel/minify/blob/6b8bab6bf5905ebc3a5a9130662a5fef34886de4/packages/babel-plugin-transform-simplify-comparison-operators/src/index.js#L37-L63 | train |
babel/minify | packages/babel-plugin-minify-dead-code-elimination/src/remove-use-strict.js | removeUseStrict | function removeUseStrict(block) {
if (!block.isBlockStatement()) {
throw new Error(
`Received ${block.type}. Expected BlockStatement. ` +
`Please report at ${newIssueUrl}`
);
}
const useStricts = getUseStrictDirectives(block);
// early exit
if (useStricts.length < 1) return;
// only... | javascript | function removeUseStrict(block) {
if (!block.isBlockStatement()) {
throw new Error(
`Received ${block.type}. Expected BlockStatement. ` +
`Please report at ${newIssueUrl}`
);
}
const useStricts = getUseStrictDirectives(block);
// early exit
if (useStricts.length < 1) return;
// only... | [
"function",
"removeUseStrict",
"(",
"block",
")",
"{",
"if",
"(",
"!",
"block",
".",
"isBlockStatement",
"(",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"block",
".",
"type",
"}",
"`",
"+",
"`",
"${",
"newIssueUrl",
"}",
"`",
")",
";",... | Remove redundant use strict
If the parent has a "use strict" directive, it is not required in
the children
@param {NodePath} block BlockStatement | [
"Remove",
"redundant",
"use",
"strict",
"If",
"the",
"parent",
"has",
"a",
"use",
"strict",
"directive",
"it",
"is",
"not",
"required",
"in",
"the",
"children"
] | 6b8bab6bf5905ebc3a5a9130662a5fef34886de4 | https://github.com/babel/minify/blob/6b8bab6bf5905ebc3a5a9130662a5fef34886de4/packages/babel-plugin-minify-dead-code-elimination/src/remove-use-strict.js#L16-L40 | train |
babel/minify | scripts/plugin-contribution.js | tableStyle | function tableStyle() {
return {
chars: {
top: "",
"top-mid": "",
"top-left": "",
"top-right": "",
bottom: "",
"bottom-mid": "",
"bottom-left": "",
"bottom-right": "",
left: "",
"left-mid": "",
mid: "",
"mid-mid": "",
right: "",
"... | javascript | function tableStyle() {
return {
chars: {
top: "",
"top-mid": "",
"top-left": "",
"top-right": "",
bottom: "",
"bottom-mid": "",
"bottom-left": "",
"bottom-right": "",
left: "",
"left-mid": "",
mid: "",
"mid-mid": "",
right: "",
"... | [
"function",
"tableStyle",
"(",
")",
"{",
"return",
"{",
"chars",
":",
"{",
"top",
":",
"\"\"",
",",
"\"top-mid\"",
":",
"\"\"",
",",
"\"top-left\"",
":",
"\"\"",
",",
"\"top-right\"",
":",
"\"\"",
",",
"bottom",
":",
"\"\"",
",",
"\"bottom-mid\"",
":",
... | just to keep it at the bottom | [
"just",
"to",
"keep",
"it",
"at",
"the",
"bottom"
] | 6b8bab6bf5905ebc3a5a9130662a5fef34886de4 | https://github.com/babel/minify/blob/6b8bab6bf5905ebc3a5a9130662a5fef34886de4/scripts/plugin-contribution.js#L143-L168 | train |
babel/minify | packages/babel-minify/src/fs.js | readStdin | async function readStdin() {
let code = "";
const stdin = process.stdin;
return new Promise(resolve => {
stdin.setEncoding("utf8");
stdin.on("readable", () => {
const chunk = process.stdin.read();
if (chunk !== null) code += chunk;
});
stdin.on("end", () => {
resolve(code);
}... | javascript | async function readStdin() {
let code = "";
const stdin = process.stdin;
return new Promise(resolve => {
stdin.setEncoding("utf8");
stdin.on("readable", () => {
const chunk = process.stdin.read();
if (chunk !== null) code += chunk;
});
stdin.on("end", () => {
resolve(code);
}... | [
"async",
"function",
"readStdin",
"(",
")",
"{",
"let",
"code",
"=",
"\"\"",
";",
"const",
"stdin",
"=",
"process",
".",
"stdin",
";",
"return",
"new",
"Promise",
"(",
"resolve",
"=>",
"{",
"stdin",
".",
"setEncoding",
"(",
"\"utf8\"",
")",
";",
"stdin... | the async keyword simply exists to denote we are returning a promise even though we don't use await inside it | [
"the",
"async",
"keyword",
"simply",
"exists",
"to",
"denote",
"we",
"are",
"returning",
"a",
"promise",
"even",
"though",
"we",
"don",
"t",
"use",
"await",
"inside",
"it"
] | 6b8bab6bf5905ebc3a5a9130662a5fef34886de4 | https://github.com/babel/minify/blob/6b8bab6bf5905ebc3a5a9130662a5fef34886de4/packages/babel-minify/src/fs.js#L48-L61 | train |
babel/minify | packages/babel-helper-evaluate-path/src/index.js | shouldDeoptBasedOnScope | function shouldDeoptBasedOnScope(binding, refPath) {
if (binding.scope.path.isProgram() && refPath.scope !== binding.scope) {
return true;
}
return false;
} | javascript | function shouldDeoptBasedOnScope(binding, refPath) {
if (binding.scope.path.isProgram() && refPath.scope !== binding.scope) {
return true;
}
return false;
} | [
"function",
"shouldDeoptBasedOnScope",
"(",
"binding",
",",
"refPath",
")",
"{",
"if",
"(",
"binding",
".",
"scope",
".",
"path",
".",
"isProgram",
"(",
")",
"&&",
"refPath",
".",
"scope",
"!==",
"binding",
".",
"scope",
")",
"{",
"return",
"true",
";",
... | check if referenced in a different fn scope we can't determine if this function is called sync or async if the binding is in program scope all it's references inside a different function should be deopted | [
"check",
"if",
"referenced",
"in",
"a",
"different",
"fn",
"scope",
"we",
"can",
"t",
"determine",
"if",
"this",
"function",
"is",
"called",
"sync",
"or",
"async",
"if",
"the",
"binding",
"is",
"in",
"program",
"scope",
"all",
"it",
"s",
"references",
"i... | 6b8bab6bf5905ebc3a5a9130662a5fef34886de4 | https://github.com/babel/minify/blob/6b8bab6bf5905ebc3a5a9130662a5fef34886de4/packages/babel-helper-evaluate-path/src/index.js#L111-L116 | train |
babel/minify | packages/babel-plugin-minify-builtins/src/index.js | getSegmentedSubPaths | function getSegmentedSubPaths(paths) {
let segments = new Map();
// Get earliest Path in tree where paths intersect
paths[0].getDeepestCommonAncestorFrom(
paths,
(lastCommon, index, ancestries) => {
// found the LCA
if (!lastCommon.isProgram()) {
let fnParent;
... | javascript | function getSegmentedSubPaths(paths) {
let segments = new Map();
// Get earliest Path in tree where paths intersect
paths[0].getDeepestCommonAncestorFrom(
paths,
(lastCommon, index, ancestries) => {
// found the LCA
if (!lastCommon.isProgram()) {
let fnParent;
... | [
"function",
"getSegmentedSubPaths",
"(",
"paths",
")",
"{",
"let",
"segments",
"=",
"new",
"Map",
"(",
")",
";",
"// Get earliest Path in tree where paths intersect",
"paths",
"[",
"0",
"]",
".",
"getDeepestCommonAncestorFrom",
"(",
"paths",
",",
"(",
"lastCommon",
... | Creates a segmented map that contains the earliest common Ancestor as the key and array of subpaths that are descendats of the LCA as value | [
"Creates",
"a",
"segmented",
"map",
"that",
"contains",
"the",
"earliest",
"common",
"Ancestor",
"as",
"the",
"key",
"and",
"array",
"of",
"subpaths",
"that",
"are",
"descendats",
"of",
"the",
"LCA",
"as",
"value"
] | 6b8bab6bf5905ebc3a5a9130662a5fef34886de4 | https://github.com/babel/minify/blob/6b8bab6bf5905ebc3a5a9130662a5fef34886de4/packages/babel-plugin-minify-builtins/src/index.js#L190-L228 | train |
babel/minify | packages/babel-plugin-minify-mangle-names/src/index.js | toObject | function toObject(value) {
if (!Array.isArray(value)) {
return value;
}
const map = {};
for (let i = 0; i < value.length; i++) {
map[value[i]] = true;
}
return map;
} | javascript | function toObject(value) {
if (!Array.isArray(value)) {
return value;
}
const map = {};
for (let i = 0; i < value.length; i++) {
map[value[i]] = true;
}
return map;
} | [
"function",
"toObject",
"(",
"value",
")",
"{",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"value",
")",
")",
"{",
"return",
"value",
";",
"}",
"const",
"map",
"=",
"{",
"}",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"value",
"... | convert value to object | [
"convert",
"value",
"to",
"object"
] | 6b8bab6bf5905ebc3a5a9130662a5fef34886de4 | https://github.com/babel/minify/blob/6b8bab6bf5905ebc3a5a9130662a5fef34886de4/packages/babel-plugin-minify-mangle-names/src/index.js#L553-L563 | train |
babel/minify | packages/babel-plugin-transform-merge-sibling-variables/src/index.js | function(path) {
if (!path.inList) {
return;
}
const { node } = path;
let sibling = path.getSibling(path.key + 1);
let declarations = [];
while (sibling.isVariableDeclaration({ kind: node.kind })) {
declarations = de... | javascript | function(path) {
if (!path.inList) {
return;
}
const { node } = path;
let sibling = path.getSibling(path.key + 1);
let declarations = [];
while (sibling.isVariableDeclaration({ kind: node.kind })) {
declarations = de... | [
"function",
"(",
"path",
")",
"{",
"if",
"(",
"!",
"path",
".",
"inList",
")",
"{",
"return",
";",
"}",
"const",
"{",
"node",
"}",
"=",
"path",
";",
"let",
"sibling",
"=",
"path",
".",
"getSibling",
"(",
"path",
".",
"key",
"+",
"1",
")",
";",
... | concat variables of the same kind with their siblings | [
"concat",
"variables",
"of",
"the",
"same",
"kind",
"with",
"their",
"siblings"
] | 6b8bab6bf5905ebc3a5a9130662a5fef34886de4 | https://github.com/babel/minify/blob/6b8bab6bf5905ebc3a5a9130662a5fef34886de4/packages/babel-plugin-transform-merge-sibling-variables/src/index.js#L51-L78 | train | |
babel/minify | packages/babel-plugin-transform-merge-sibling-variables/src/index.js | function(path) {
if (!path.inList) {
return;
}
const { node } = path;
if (node.kind !== "var") {
return;
}
const next = path.getSibling(path.key + 1);
if (!next.isForStatement()) {
return;
... | javascript | function(path) {
if (!path.inList) {
return;
}
const { node } = path;
if (node.kind !== "var") {
return;
}
const next = path.getSibling(path.key + 1);
if (!next.isForStatement()) {
return;
... | [
"function",
"(",
"path",
")",
"{",
"if",
"(",
"!",
"path",
".",
"inList",
")",
"{",
"return",
";",
"}",
"const",
"{",
"node",
"}",
"=",
"path",
";",
"if",
"(",
"node",
".",
"kind",
"!==",
"\"var\"",
")",
"{",
"return",
";",
"}",
"const",
"next"... | concat `var` declarations next to for loops with it's initialisers. block-scoped `let` and `const` are not moved because the for loop is a different block scope. | [
"concat",
"var",
"declarations",
"next",
"to",
"for",
"loops",
"with",
"it",
"s",
"initialisers",
".",
"block",
"-",
"scoped",
"let",
"and",
"const",
"are",
"not",
"moved",
"because",
"the",
"for",
"loop",
"is",
"a",
"different",
"block",
"scope",
"."
] | 6b8bab6bf5905ebc3a5a9130662a5fef34886de4 | https://github.com/babel/minify/blob/6b8bab6bf5905ebc3a5a9130662a5fef34886de4/packages/babel-plugin-transform-merge-sibling-variables/src/index.js#L83-L111 | train | |
KhaosT/homebridge-camera-ffmpeg | drive.js | authorize | function authorize(credentials, callback) {
var clientSecret = credentials.installed.client_secret;
var clientId = credentials.installed.client_id;
var redirectUrl = credentials.installed.redirect_uris[0];
var auth = new googleAuth();
var oauth2Client = new auth.OAuth2(clientId, clientSecret, redire... | javascript | function authorize(credentials, callback) {
var clientSecret = credentials.installed.client_secret;
var clientId = credentials.installed.client_id;
var redirectUrl = credentials.installed.redirect_uris[0];
var auth = new googleAuth();
var oauth2Client = new auth.OAuth2(clientId, clientSecret, redire... | [
"function",
"authorize",
"(",
"credentials",
",",
"callback",
")",
"{",
"var",
"clientSecret",
"=",
"credentials",
".",
"installed",
".",
"client_secret",
";",
"var",
"clientId",
"=",
"credentials",
".",
"installed",
".",
"client_id",
";",
"var",
"redirectUrl",
... | This is all from the Google Drive Quickstart
Create an OAuth2 client with the given credentials, and then execute the
given callback function.
@param {Object} credentials The authorization client credentials.
@param {function} callback The callback to call with the authorized client. | [
"This",
"is",
"all",
"from",
"the",
"Google",
"Drive",
"Quickstart",
"Create",
"an",
"OAuth2",
"client",
"with",
"the",
"given",
"credentials",
"and",
"then",
"execute",
"the",
"given",
"callback",
"function",
"."
] | cd284406d1a67b88b6488fb455128a0b7a220e12 | https://github.com/KhaosT/homebridge-camera-ffmpeg/blob/cd284406d1a67b88b6488fb455128a0b7a220e12/drive.js#L136-L152 | train |
Serhioromano/bootstrap-calendar | components/jstimezonedetect/jstz.js | function () {
var ambiguity_list = AMBIGUITIES[timezone_name],
length = ambiguity_list.length,
i = 0,
tz = ambiguity_list[0];
for (; i < length; i += 1) {
tz = ambiguity_list[i];
if (jstz.dat... | javascript | function () {
var ambiguity_list = AMBIGUITIES[timezone_name],
length = ambiguity_list.length,
i = 0,
tz = ambiguity_list[0];
for (; i < length; i += 1) {
tz = ambiguity_list[i];
if (jstz.dat... | [
"function",
"(",
")",
"{",
"var",
"ambiguity_list",
"=",
"AMBIGUITIES",
"[",
"timezone_name",
"]",
",",
"length",
"=",
"ambiguity_list",
".",
"length",
",",
"i",
"=",
"0",
",",
"tz",
"=",
"ambiguity_list",
"[",
"0",
"]",
";",
"for",
"(",
";",
"i",
"<... | The keys in this object are timezones that we know may be ambiguous after
a preliminary scan through the olson_tz object.
The array of timezones to compare must be in the order that daylight savings
starts for the regions. | [
"The",
"keys",
"in",
"this",
"object",
"are",
"timezones",
"that",
"we",
"know",
"may",
"be",
"ambiguous",
"after",
"a",
"preliminary",
"scan",
"through",
"the",
"olson_tz",
"object",
"."
] | fd5e6fdb69d7e8afdc655b54ffe7a50b8edfffd1 | https://github.com/Serhioromano/bootstrap-calendar/blob/fd5e6fdb69d7e8afdc655b54ffe7a50b8edfffd1/components/jstimezonedetect/jstz.js#L229-L243 | train | |
OptimalBits/redbird | lib/proxy.js | redirectToHttps | function redirectToHttps(req, res, target, ssl, log) {
req.url = req._url || req.url; // Get the original url since we are going to redirect.
var targetPort = ssl.redirectPort || ssl.port;
var hostname = req.headers.host.split(':')[0] + ( targetPort ? ':' + targetPort : '' );
var url = 'https://' + path.join(h... | javascript | function redirectToHttps(req, res, target, ssl, log) {
req.url = req._url || req.url; // Get the original url since we are going to redirect.
var targetPort = ssl.redirectPort || ssl.port;
var hostname = req.headers.host.split(':')[0] + ( targetPort ? ':' + targetPort : '' );
var url = 'https://' + path.join(h... | [
"function",
"redirectToHttps",
"(",
"req",
",",
"res",
",",
"target",
",",
"ssl",
",",
"log",
")",
"{",
"req",
".",
"url",
"=",
"req",
".",
"_url",
"||",
"req",
".",
"url",
";",
"// Get the original url since we are going to redirect.",
"var",
"targetPort",
... | Redirect to the HTTPS proxy | [
"Redirect",
"to",
"the",
"HTTPS",
"proxy"
] | a8779cccde681f27f78c80b9ee6ca373254c73e5 | https://github.com/OptimalBits/redbird/blob/a8779cccde681f27f78c80b9ee6ca373254c73e5/lib/proxy.js#L702-L715 | train |
timdown/rangy | src/modules/inactive/rangy-commands_new.js | getFurthestAncestor | function getFurthestAncestor(node) {
var root = node;
while (root.parentNode != null) {
root = root.parentNode;
}
return root;
} | javascript | function getFurthestAncestor(node) {
var root = node;
while (root.parentNode != null) {
root = root.parentNode;
}
return root;
} | [
"function",
"getFurthestAncestor",
"(",
"node",
")",
"{",
"var",
"root",
"=",
"node",
";",
"while",
"(",
"root",
".",
"parentNode",
"!=",
"null",
")",
"{",
"root",
"=",
"root",
".",
"parentNode",
";",
"}",
"return",
"root",
";",
"}"
] | Returns the furthest ancestor of a Node as defined by DOM Range. | [
"Returns",
"the",
"furthest",
"ancestor",
"of",
"a",
"Node",
"as",
"defined",
"by",
"DOM",
"Range",
"."
] | 1e55169d2e4d1d9458c2a87119addf47a8265276 | https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/src/modules/inactive/rangy-commands_new.js#L79-L85 | train |
timdown/rangy | src/modules/inactive/rangy-commands_new.js | isCollapsedLineBreak | function isCollapsedLineBreak(br) {
if (!isHtmlElement(br, "br")) {
return false;
}
// Add a zwsp after it and see if that changes the height of the nearest
// non-inline parent. Note: this is not actually reliable, because the
// parent might have a fixed height or... | javascript | function isCollapsedLineBreak(br) {
if (!isHtmlElement(br, "br")) {
return false;
}
// Add a zwsp after it and see if that changes the height of the nearest
// non-inline parent. Note: this is not actually reliable, because the
// parent might have a fixed height or... | [
"function",
"isCollapsedLineBreak",
"(",
"br",
")",
"{",
"if",
"(",
"!",
"isHtmlElement",
"(",
"br",
",",
"\"br\"",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Add a zwsp after it and see if that changes the height of the nearest",
"// non-inline parent. Note: this i... | "A collapsed line break is a br that begins a line box which has nothing else in it, and therefore has zero height." | [
"A",
"collapsed",
"line",
"break",
"is",
"a",
"br",
"that",
"begins",
"a",
"line",
"box",
"which",
"has",
"nothing",
"else",
"in",
"it",
"and",
"therefore",
"has",
"zero",
"height",
"."
] | 1e55169d2e4d1d9458c2a87119addf47a8265276 | https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/src/modules/inactive/rangy-commands_new.js#L299-L336 | train |
timdown/rangy | src/modules/inactive/rangy-commands_new.js | getEffectiveCommandValue | function getEffectiveCommandValue(node, context) {
var isElement = (node.nodeType == 1);
// "If neither node nor its parent is an Element, return null."
if (!isElement && (!node.parentNode || node.parentNode.nodeType != 1)) {
return null;
}
// "If node is not an Ele... | javascript | function getEffectiveCommandValue(node, context) {
var isElement = (node.nodeType == 1);
// "If neither node nor its parent is an Element, return null."
if (!isElement && (!node.parentNode || node.parentNode.nodeType != 1)) {
return null;
}
// "If node is not an Ele... | [
"function",
"getEffectiveCommandValue",
"(",
"node",
",",
"context",
")",
"{",
"var",
"isElement",
"=",
"(",
"node",
".",
"nodeType",
"==",
"1",
")",
";",
"// \"If neither node nor its parent is an Element, return null.\"",
"if",
"(",
"!",
"isElement",
"&&",
"(",
... | "effective value" per edit command spec | [
"effective",
"value",
"per",
"edit",
"command",
"spec"
] | 1e55169d2e4d1d9458c2a87119addf47a8265276 | https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/src/modules/inactive/rangy-commands_new.js#L834-L848 | train |
timdown/rangy | builder/build.js | doSubstituteBuildVars | function doSubstituteBuildVars(file, buildVars) {
var contents = fs.readFileSync(file, FILE_ENCODING);
contents = contents.replace(/%%build:([^%]+)%%/g, function(matched, buildVarName) {
return buildVars[buildVarName];
});
// Now do replacements specified by build dire... | javascript | function doSubstituteBuildVars(file, buildVars) {
var contents = fs.readFileSync(file, FILE_ENCODING);
contents = contents.replace(/%%build:([^%]+)%%/g, function(matched, buildVarName) {
return buildVars[buildVarName];
});
// Now do replacements specified by build dire... | [
"function",
"doSubstituteBuildVars",
"(",
"file",
",",
"buildVars",
")",
"{",
"var",
"contents",
"=",
"fs",
".",
"readFileSync",
"(",
"file",
",",
"FILE_ENCODING",
")",
";",
"contents",
"=",
"contents",
".",
"replace",
"(",
"/",
"%%build:([^%]+)%%",
"/",
"g"... | Substitute build vars in scripts | [
"Substitute",
"build",
"vars",
"in",
"scripts"
] | 1e55169d2e4d1d9458c2a87119addf47a8265276 | https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/builder/build.js#L223-L233 | train |
timdown/rangy | src/modules/inactive/commands/aryeh_implementation.js | isAncestor | function isAncestor(ancestor, descendant) {
return ancestor
&& descendant
&& Boolean(ancestor.compareDocumentPosition(descendant) & Node.DOCUMENT_POSITION_CONTAINED_BY);
} | javascript | function isAncestor(ancestor, descendant) {
return ancestor
&& descendant
&& Boolean(ancestor.compareDocumentPosition(descendant) & Node.DOCUMENT_POSITION_CONTAINED_BY);
} | [
"function",
"isAncestor",
"(",
"ancestor",
",",
"descendant",
")",
"{",
"return",
"ancestor",
"&&",
"descendant",
"&&",
"Boolean",
"(",
"ancestor",
".",
"compareDocumentPosition",
"(",
"descendant",
")",
"&",
"Node",
".",
"DOCUMENT_POSITION_CONTAINED_BY",
")",
";"... | Returns true if ancestor is an ancestor of descendant, false otherwise. | [
"Returns",
"true",
"if",
"ancestor",
"is",
"an",
"ancestor",
"of",
"descendant",
"false",
"otherwise",
"."
] | 1e55169d2e4d1d9458c2a87119addf47a8265276 | https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/src/modules/inactive/commands/aryeh_implementation.js#L55-L59 | train |
Subsets and Splits
SQL Console for semeru/code-text-javascript
Retrieves 20,000 non-null code samples labeled as JavaScript, providing a basic overview of the dataset.