id int32 0 58k | repo stringlengths 5 67 | path stringlengths 4 116 | func_name stringlengths 0 58 | original_string stringlengths 52 373k | language stringclasses 1 value | code stringlengths 52 373k | code_tokens list | docstring stringlengths 4 11.8k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 86 226 |
|---|---|---|---|---|---|---|---|---|---|---|---|
21,500 | STRML/JSXHint | cli.js | interceptReporter | function interceptReporter(reporter, filesMap){
if(!reporter) reporter = require('jshint/src/reporters/default').reporter;
return function(results, data, opts){
if (filesMap) {
results.forEach(function(result){
result.file = filesMap[result.file];
});
}
return reporter(results, data, opts);
};
} | javascript | function interceptReporter(reporter, filesMap){
if(!reporter) reporter = require('jshint/src/reporters/default').reporter;
return function(results, data, opts){
if (filesMap) {
results.forEach(function(result){
result.file = filesMap[result.file];
});
}
return reporter(results, data, opts);
};
} | [
"function",
"interceptReporter",
"(",
"reporter",
",",
"filesMap",
")",
"{",
"if",
"(",
"!",
"reporter",
")",
"reporter",
"=",
"require",
"(",
"'jshint/src/reporters/default'",
")",
".",
"reporter",
";",
"return",
"function",
"(",
"results",
",",
"data",
",",
"opts",
")",
"{",
"if",
"(",
"filesMap",
")",
"{",
"results",
".",
"forEach",
"(",
"function",
"(",
"result",
")",
"{",
"result",
".",
"file",
"=",
"filesMap",
"[",
"result",
".",
"file",
"]",
";",
"}",
")",
";",
"}",
"return",
"reporter",
"(",
"results",
",",
"data",
",",
"opts",
")",
";",
"}",
";",
"}"
] | Intercept configured reporter and change file names so it looks
like nothing happened.
@param {Reporter} reporter JSHint reporter
@param {Object} filesMap Map related transformed files to original file paths.
@return {Function} Wrapper around configured reporter. Same arity as reporter. | [
"Intercept",
"configured",
"reporter",
"and",
"change",
"file",
"names",
"so",
"it",
"looks",
"like",
"nothing",
"happened",
"."
] | 52dd5299903a4fc9d733da9c2e568f8de1c10c5d | https://github.com/STRML/JSXHint/blob/52dd5299903a4fc9d733da9c2e568f8de1c10c5d/cli.js#L134-L144 |
21,501 | roiperlman/ngx-document-scanner | dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js | function (dimensions) {
var _this = this;
return new Promise(function (resolve, reject) {
_this._paneDimensions = dimensions;
_this.paneDimensions.next(dimensions);
resolve();
});
} | javascript | function (dimensions) {
var _this = this;
return new Promise(function (resolve, reject) {
_this._paneDimensions = dimensions;
_this.paneDimensions.next(dimensions);
resolve();
});
} | [
"function",
"(",
"dimensions",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"_this",
".",
"_paneDimensions",
"=",
"dimensions",
";",
"_this",
".",
"paneDimensions",
".",
"next",
"(",
"dimensions",
")",
";",
"resolve",
"(",
")",
";",
"}",
")",
";",
"}"
] | set privew pane dimensions
@param {?} dimensions
@return {?} | [
"set",
"privew",
"pane",
"dimensions"
] | 9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c | https://github.com/roiperlman/ngx-document-scanner/blob/9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c/dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js#L179-L186 | |
21,502 | roiperlman/ngx-document-scanner | dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js | function (positions) {
var _this = this;
this._points = positions;
positions.forEach(function (position) {
_this.positionChange(position);
});
this.repositionEvent.next(positions);
} | javascript | function (positions) {
var _this = this;
this._points = positions;
positions.forEach(function (position) {
_this.positionChange(position);
});
this.repositionEvent.next(positions);
} | [
"function",
"(",
"positions",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"this",
".",
"_points",
"=",
"positions",
";",
"positions",
".",
"forEach",
"(",
"function",
"(",
"position",
")",
"{",
"_this",
".",
"positionChange",
"(",
"position",
")",
";",
"}",
")",
";",
"this",
".",
"repositionEvent",
".",
"next",
"(",
"positions",
")",
";",
"}"
] | repositions points externally
@param {?} positions
@return {?} | [
"repositions",
"points",
"externally"
] | 9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c | https://github.com/roiperlman/ngx-document-scanner/blob/9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c/dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js#L200-L207 | |
21,503 | roiperlman/ngx-document-scanner | dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js | function (positionChangeData) {
var _this = this;
// update positions according to current position change
this.updatePosition(positionChangeData);
// for each direction:
// 1. filter the _points that have a role as the direction's limit
// 2. for top and left find max x | y values, and min for right and bottom
this.limitDirections.forEach(function (direction) {
/** @type {?} */
var relevantPoints = _this._points.filter(function (point) {
return point.roles.includes(direction);
})
.map(function (point) {
return point[_this.getDirectionAxis(direction)];
});
/** @type {?} */
var limit;
if (direction === 'top' || direction === 'left') {
limit = Math.max.apply(Math, __spread(relevantPoints));
}
if (direction === 'right' || direction === 'bottom') {
limit = Math.min.apply(Math, __spread(relevantPoints));
}
_this._limits[direction] = limit;
});
this.limits.next(this._limits);
this.positions.next(Array.from(this._points));
} | javascript | function (positionChangeData) {
var _this = this;
// update positions according to current position change
this.updatePosition(positionChangeData);
// for each direction:
// 1. filter the _points that have a role as the direction's limit
// 2. for top and left find max x | y values, and min for right and bottom
this.limitDirections.forEach(function (direction) {
/** @type {?} */
var relevantPoints = _this._points.filter(function (point) {
return point.roles.includes(direction);
})
.map(function (point) {
return point[_this.getDirectionAxis(direction)];
});
/** @type {?} */
var limit;
if (direction === 'top' || direction === 'left') {
limit = Math.max.apply(Math, __spread(relevantPoints));
}
if (direction === 'right' || direction === 'bottom') {
limit = Math.min.apply(Math, __spread(relevantPoints));
}
_this._limits[direction] = limit;
});
this.limits.next(this._limits);
this.positions.next(Array.from(this._points));
} | [
"function",
"(",
"positionChangeData",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"// update positions according to current position change",
"this",
".",
"updatePosition",
"(",
"positionChangeData",
")",
";",
"// for each direction:",
"// 1. filter the _points that have a role as the direction's limit",
"// 2. for top and left find max x | y values, and min for right and bottom",
"this",
".",
"limitDirections",
".",
"forEach",
"(",
"function",
"(",
"direction",
")",
"{",
"/** @type {?} */",
"var",
"relevantPoints",
"=",
"_this",
".",
"_points",
".",
"filter",
"(",
"function",
"(",
"point",
")",
"{",
"return",
"point",
".",
"roles",
".",
"includes",
"(",
"direction",
")",
";",
"}",
")",
".",
"map",
"(",
"function",
"(",
"point",
")",
"{",
"return",
"point",
"[",
"_this",
".",
"getDirectionAxis",
"(",
"direction",
")",
"]",
";",
"}",
")",
";",
"/** @type {?} */",
"var",
"limit",
";",
"if",
"(",
"direction",
"===",
"'top'",
"||",
"direction",
"===",
"'left'",
")",
"{",
"limit",
"=",
"Math",
".",
"max",
".",
"apply",
"(",
"Math",
",",
"__spread",
"(",
"relevantPoints",
")",
")",
";",
"}",
"if",
"(",
"direction",
"===",
"'right'",
"||",
"direction",
"===",
"'bottom'",
")",
"{",
"limit",
"=",
"Math",
".",
"min",
".",
"apply",
"(",
"Math",
",",
"__spread",
"(",
"relevantPoints",
")",
")",
";",
"}",
"_this",
".",
"_limits",
"[",
"direction",
"]",
"=",
"limit",
";",
"}",
")",
";",
"this",
".",
"limits",
".",
"next",
"(",
"this",
".",
"_limits",
")",
";",
"this",
".",
"positions",
".",
"next",
"(",
"Array",
".",
"from",
"(",
"this",
".",
"_points",
")",
")",
";",
"}"
] | updates limits and point positions and calls next on the observables
@param {?} positionChangeData - position change event data
@return {?} | [
"updates",
"limits",
"and",
"point",
"positions",
"and",
"calls",
"next",
"on",
"the",
"observables"
] | 9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c | https://github.com/roiperlman/ngx-document-scanner/blob/9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c/dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js#L222-L249 | |
21,504 | roiperlman/ngx-document-scanner | dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js | function (positionChange) {
var _this = this;
// finds the current position of the point by it's roles, than splices it for the new position or pushes it if it's not yet in the array
/** @type {?} */
var index = this._points.findIndex(function (point) {
return _this.compareArray(positionChange.roles, point.roles);
});
if (index === -1) {
this._points.push(positionChange);
}
else {
this._points.splice(index, 1, positionChange);
}
} | javascript | function (positionChange) {
var _this = this;
// finds the current position of the point by it's roles, than splices it for the new position or pushes it if it's not yet in the array
/** @type {?} */
var index = this._points.findIndex(function (point) {
return _this.compareArray(positionChange.roles, point.roles);
});
if (index === -1) {
this._points.push(positionChange);
}
else {
this._points.splice(index, 1, positionChange);
}
} | [
"function",
"(",
"positionChange",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"// finds the current position of the point by it's roles, than splices it for the new position or pushes it if it's not yet in the array",
"/** @type {?} */",
"var",
"index",
"=",
"this",
".",
"_points",
".",
"findIndex",
"(",
"function",
"(",
"point",
")",
"{",
"return",
"_this",
".",
"compareArray",
"(",
"positionChange",
".",
"roles",
",",
"point",
".",
"roles",
")",
";",
"}",
")",
";",
"if",
"(",
"index",
"===",
"-",
"1",
")",
"{",
"this",
".",
"_points",
".",
"push",
"(",
"positionChange",
")",
";",
"}",
"else",
"{",
"this",
".",
"_points",
".",
"splice",
"(",
"index",
",",
"1",
",",
"positionChange",
")",
";",
"}",
"}"
] | updates the position of the point
@param {?} positionChange - position change event data
@return {?} | [
"updates",
"the",
"position",
"of",
"the",
"point"
] | 9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c | https://github.com/roiperlman/ngx-document-scanner/blob/9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c/dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js#L264-L277 | |
21,505 | roiperlman/ngx-document-scanner | dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js | function (positionChange) {
var _this = this;
/** @type {?} */
var pointLimits = this.limitDirections.filter(function (direction) {
return !positionChange.roles.includes(direction);
});
/** @type {?} */
var limitException = {
exceeds: false,
resetCoefficients: {
x: 0,
y: 0
},
resetCoordinates: {
x: positionChange.x,
y: positionChange.y
}
};
// limit directions are the opposite sides of the point's roles
pointLimits.forEach(function (direction) {
/** @type {?} */
var directionAxis = _this.getDirectionAxis(direction);
if (direction === 'top' || direction === 'left') {
if (positionChange[directionAxis] < _this._limits[direction]) {
limitException.resetCoefficients[directionAxis] = 1;
limitException.resetCoordinates[directionAxis] = _this._limits[direction];
}
}
else if (direction === 'right' || direction === 'bottom') {
if (positionChange[directionAxis] > _this._limits[direction]) {
limitException.resetCoefficients[directionAxis] = -1;
limitException.resetCoordinates[directionAxis] = _this._limits[direction];
}
}
});
if (limitException.resetCoefficients.x !== 0 || limitException.resetCoefficients.y !== 0) {
limitException.exceeds = true;
}
return limitException;
} | javascript | function (positionChange) {
var _this = this;
/** @type {?} */
var pointLimits = this.limitDirections.filter(function (direction) {
return !positionChange.roles.includes(direction);
});
/** @type {?} */
var limitException = {
exceeds: false,
resetCoefficients: {
x: 0,
y: 0
},
resetCoordinates: {
x: positionChange.x,
y: positionChange.y
}
};
// limit directions are the opposite sides of the point's roles
pointLimits.forEach(function (direction) {
/** @type {?} */
var directionAxis = _this.getDirectionAxis(direction);
if (direction === 'top' || direction === 'left') {
if (positionChange[directionAxis] < _this._limits[direction]) {
limitException.resetCoefficients[directionAxis] = 1;
limitException.resetCoordinates[directionAxis] = _this._limits[direction];
}
}
else if (direction === 'right' || direction === 'bottom') {
if (positionChange[directionAxis] > _this._limits[direction]) {
limitException.resetCoefficients[directionAxis] = -1;
limitException.resetCoordinates[directionAxis] = _this._limits[direction];
}
}
});
if (limitException.resetCoefficients.x !== 0 || limitException.resetCoefficients.y !== 0) {
limitException.exceeds = true;
}
return limitException;
} | [
"function",
"(",
"positionChange",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"/** @type {?} */",
"var",
"pointLimits",
"=",
"this",
".",
"limitDirections",
".",
"filter",
"(",
"function",
"(",
"direction",
")",
"{",
"return",
"!",
"positionChange",
".",
"roles",
".",
"includes",
"(",
"direction",
")",
";",
"}",
")",
";",
"/** @type {?} */",
"var",
"limitException",
"=",
"{",
"exceeds",
":",
"false",
",",
"resetCoefficients",
":",
"{",
"x",
":",
"0",
",",
"y",
":",
"0",
"}",
",",
"resetCoordinates",
":",
"{",
"x",
":",
"positionChange",
".",
"x",
",",
"y",
":",
"positionChange",
".",
"y",
"}",
"}",
";",
"// limit directions are the opposite sides of the point's roles",
"pointLimits",
".",
"forEach",
"(",
"function",
"(",
"direction",
")",
"{",
"/** @type {?} */",
"var",
"directionAxis",
"=",
"_this",
".",
"getDirectionAxis",
"(",
"direction",
")",
";",
"if",
"(",
"direction",
"===",
"'top'",
"||",
"direction",
"===",
"'left'",
")",
"{",
"if",
"(",
"positionChange",
"[",
"directionAxis",
"]",
"<",
"_this",
".",
"_limits",
"[",
"direction",
"]",
")",
"{",
"limitException",
".",
"resetCoefficients",
"[",
"directionAxis",
"]",
"=",
"1",
";",
"limitException",
".",
"resetCoordinates",
"[",
"directionAxis",
"]",
"=",
"_this",
".",
"_limits",
"[",
"direction",
"]",
";",
"}",
"}",
"else",
"if",
"(",
"direction",
"===",
"'right'",
"||",
"direction",
"===",
"'bottom'",
")",
"{",
"if",
"(",
"positionChange",
"[",
"directionAxis",
"]",
">",
"_this",
".",
"_limits",
"[",
"direction",
"]",
")",
"{",
"limitException",
".",
"resetCoefficients",
"[",
"directionAxis",
"]",
"=",
"-",
"1",
";",
"limitException",
".",
"resetCoordinates",
"[",
"directionAxis",
"]",
"=",
"_this",
".",
"_limits",
"[",
"direction",
"]",
";",
"}",
"}",
"}",
")",
";",
"if",
"(",
"limitException",
".",
"resetCoefficients",
".",
"x",
"!==",
"0",
"||",
"limitException",
".",
"resetCoefficients",
".",
"y",
"!==",
"0",
")",
"{",
"limitException",
".",
"exceeds",
"=",
"true",
";",
"}",
"return",
"limitException",
";",
"}"
] | check if a position change event exceeds the limits
@param {?} positionChange - position change event data
@return {?} LimitException0 | [
"check",
"if",
"a",
"position",
"change",
"event",
"exceeds",
"the",
"limits"
] | 9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c | https://github.com/roiperlman/ngx-document-scanner/blob/9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c/dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js#L293-L332 | |
21,506 | roiperlman/ngx-document-scanner | dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js | function (resizeRatios, initialPreviewDimensions, initialPositions) {
var _this = this;
// convert positions to ratio between position to initial pane dimension
initialPositions = initialPositions.map(function (point) {
return new PositionChangeData({
x: point.x / initialPreviewDimensions.width,
y: point.y / initialPreviewDimensions.height,
}, point.roles);
});
this.repositionPoints(initialPositions.map(function (point) {
return _this.rotateCornerClockwise(point);
}));
} | javascript | function (resizeRatios, initialPreviewDimensions, initialPositions) {
var _this = this;
// convert positions to ratio between position to initial pane dimension
initialPositions = initialPositions.map(function (point) {
return new PositionChangeData({
x: point.x / initialPreviewDimensions.width,
y: point.y / initialPreviewDimensions.height,
}, point.roles);
});
this.repositionPoints(initialPositions.map(function (point) {
return _this.rotateCornerClockwise(point);
}));
} | [
"function",
"(",
"resizeRatios",
",",
"initialPreviewDimensions",
",",
"initialPositions",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"// convert positions to ratio between position to initial pane dimension",
"initialPositions",
"=",
"initialPositions",
".",
"map",
"(",
"function",
"(",
"point",
")",
"{",
"return",
"new",
"PositionChangeData",
"(",
"{",
"x",
":",
"point",
".",
"x",
"/",
"initialPreviewDimensions",
".",
"width",
",",
"y",
":",
"point",
".",
"y",
"/",
"initialPreviewDimensions",
".",
"height",
",",
"}",
",",
"point",
".",
"roles",
")",
";",
"}",
")",
";",
"this",
".",
"repositionPoints",
"(",
"initialPositions",
".",
"map",
"(",
"function",
"(",
"point",
")",
"{",
"return",
"_this",
".",
"rotateCornerClockwise",
"(",
"point",
")",
";",
"}",
")",
")",
";",
"}"
] | rotate crop tool points clockwise
@param {?} resizeRatios - ratio between the new dimensions and the previous
@param {?} initialPreviewDimensions - preview pane dimensions before rotation
@param {?} initialPositions - current positions before rotation
@return {?} | [
"rotate",
"crop",
"tool",
"points",
"clockwise"
] | 9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c | https://github.com/roiperlman/ngx-document-scanner/blob/9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c/dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js#L353-L365 | |
21,507 | roiperlman/ngx-document-scanner | dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js | function (corner) {
var _this = this;
/** @type {?} */
var rotated = {
x: this._paneDimensions.width * (1 - corner.y),
y: this._paneDimensions.height * corner.x,
roles: []
};
// rotates corner according to order
/** @type {?} */
var order = [
['bottom', 'left'],
['top', 'left'],
['top', 'right'],
['bottom', 'right'],
['bottom', 'left']
];
rotated.roles = order[order.findIndex(function (roles) {
return _this.compareArray(roles, corner.roles);
}) + 1];
return rotated;
} | javascript | function (corner) {
var _this = this;
/** @type {?} */
var rotated = {
x: this._paneDimensions.width * (1 - corner.y),
y: this._paneDimensions.height * corner.x,
roles: []
};
// rotates corner according to order
/** @type {?} */
var order = [
['bottom', 'left'],
['top', 'left'],
['top', 'right'],
['bottom', 'right'],
['bottom', 'left']
];
rotated.roles = order[order.findIndex(function (roles) {
return _this.compareArray(roles, corner.roles);
}) + 1];
return rotated;
} | [
"function",
"(",
"corner",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"/** @type {?} */",
"var",
"rotated",
"=",
"{",
"x",
":",
"this",
".",
"_paneDimensions",
".",
"width",
"*",
"(",
"1",
"-",
"corner",
".",
"y",
")",
",",
"y",
":",
"this",
".",
"_paneDimensions",
".",
"height",
"*",
"corner",
".",
"x",
",",
"roles",
":",
"[",
"]",
"}",
";",
"// rotates corner according to order",
"/** @type {?} */",
"var",
"order",
"=",
"[",
"[",
"'bottom'",
",",
"'left'",
"]",
",",
"[",
"'top'",
",",
"'left'",
"]",
",",
"[",
"'top'",
",",
"'right'",
"]",
",",
"[",
"'bottom'",
",",
"'right'",
"]",
",",
"[",
"'bottom'",
",",
"'left'",
"]",
"]",
";",
"rotated",
".",
"roles",
"=",
"order",
"[",
"order",
".",
"findIndex",
"(",
"function",
"(",
"roles",
")",
"{",
"return",
"_this",
".",
"compareArray",
"(",
"roles",
",",
"corner",
".",
"roles",
")",
";",
"}",
")",
"+",
"1",
"]",
";",
"return",
"rotated",
";",
"}"
] | returns the corner positions after a 90 degrees clockwise rotation
@private
@param {?} corner
@return {?} | [
"returns",
"the",
"corner",
"positions",
"after",
"a",
"90",
"degrees",
"clockwise",
"rotation"
] | 9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c | https://github.com/roiperlman/ngx-document-scanner/blob/9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c/dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js#L381-L402 | |
21,508 | roiperlman/ngx-document-scanner | dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js | function (array1, array2) {
return array1.every(function (element) {
return array2.includes(element);
}) && array1.length === array2.length;
} | javascript | function (array1, array2) {
return array1.every(function (element) {
return array2.includes(element);
}) && array1.length === array2.length;
} | [
"function",
"(",
"array1",
",",
"array2",
")",
"{",
"return",
"array1",
".",
"every",
"(",
"function",
"(",
"element",
")",
"{",
"return",
"array2",
".",
"includes",
"(",
"element",
")",
";",
"}",
")",
"&&",
"array1",
".",
"length",
"===",
"array2",
".",
"length",
";",
"}"
] | checks if two array contain the same values
@param {?} array1 - array 1
@param {?} array2 - array 2
@return {?} boolean | [
"checks",
"if",
"two",
"array",
"contain",
"the",
"same",
"values"
] | 9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c | https://github.com/roiperlman/ngx-document-scanner/blob/9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c/dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js#L421-L425 | |
21,509 | roiperlman/ngx-document-scanner | dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js | function (position) {
/** @type {?} */
var positionChangeData = new PositionChangeData(position, this.limitRoles);
/** @type {?} */
var limitException = this.limitsService.exceedsLimit(positionChangeData);
if (limitException.exceeds) {
// if exceeds limits, reposition
this.resetPosition = limitException.resetCoordinates;
}
else {
this.limitsService.positionChange(positionChangeData);
this._currentPosition = position;
}
} | javascript | function (position) {
/** @type {?} */
var positionChangeData = new PositionChangeData(position, this.limitRoles);
/** @type {?} */
var limitException = this.limitsService.exceedsLimit(positionChangeData);
if (limitException.exceeds) {
// if exceeds limits, reposition
this.resetPosition = limitException.resetCoordinates;
}
else {
this.limitsService.positionChange(positionChangeData);
this._currentPosition = position;
}
} | [
"function",
"(",
"position",
")",
"{",
"/** @type {?} */",
"var",
"positionChangeData",
"=",
"new",
"PositionChangeData",
"(",
"position",
",",
"this",
".",
"limitRoles",
")",
";",
"/** @type {?} */",
"var",
"limitException",
"=",
"this",
".",
"limitsService",
".",
"exceedsLimit",
"(",
"positionChangeData",
")",
";",
"if",
"(",
"limitException",
".",
"exceeds",
")",
"{",
"// if exceeds limits, reposition",
"this",
".",
"resetPosition",
"=",
"limitException",
".",
"resetCoordinates",
";",
"}",
"else",
"{",
"this",
".",
"limitsService",
".",
"positionChange",
"(",
"positionChangeData",
")",
";",
"this",
".",
"_currentPosition",
"=",
"position",
";",
"}",
"}"
] | registers a position change on the limits service, and adjusts position if necessary
@param {?} position - the current position of the point
@return {?} | [
"registers",
"a",
"position",
"change",
"on",
"the",
"limits",
"service",
"and",
"adjusts",
"position",
"if",
"necessary"
] | 9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c | https://github.com/roiperlman/ngx-document-scanner/blob/9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c/dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js#L543-L556 | |
21,510 | roiperlman/ngx-document-scanner | dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js | function (limitException) {
/** @type {?} */
var newPosition = {
x: 0,
y: 0
};
Object.keys(this.startPosition).forEach(function (axis) {
newPosition[axis] = limitException.resetCoordinates[axis] + limitException.resetCoefficients[axis];
});
this.position = newPosition;
this.limitsService.positionChange(new PositionChangeData(this.position, this.limitRoles));
} | javascript | function (limitException) {
/** @type {?} */
var newPosition = {
x: 0,
y: 0
};
Object.keys(this.startPosition).forEach(function (axis) {
newPosition[axis] = limitException.resetCoordinates[axis] + limitException.resetCoefficients[axis];
});
this.position = newPosition;
this.limitsService.positionChange(new PositionChangeData(this.position, this.limitRoles));
} | [
"function",
"(",
"limitException",
")",
"{",
"/** @type {?} */",
"var",
"newPosition",
"=",
"{",
"x",
":",
"0",
",",
"y",
":",
"0",
"}",
";",
"Object",
".",
"keys",
"(",
"this",
".",
"startPosition",
")",
".",
"forEach",
"(",
"function",
"(",
"axis",
")",
"{",
"newPosition",
"[",
"axis",
"]",
"=",
"limitException",
".",
"resetCoordinates",
"[",
"axis",
"]",
"+",
"limitException",
".",
"resetCoefficients",
"[",
"axis",
"]",
";",
"}",
")",
";",
"this",
".",
"position",
"=",
"newPosition",
";",
"this",
".",
"limitsService",
".",
"positionChange",
"(",
"new",
"PositionChangeData",
"(",
"this",
".",
"position",
",",
"this",
".",
"limitRoles",
")",
")",
";",
"}"
] | adjusts the position of the point after a limit exception
@private
@param {?} limitException
@return {?} | [
"adjusts",
"the",
"position",
"of",
"the",
"point",
"after",
"a",
"limit",
"exception"
] | 9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c | https://github.com/roiperlman/ngx-document-scanner/blob/9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c/dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js#L572-L583 | |
21,511 | roiperlman/ngx-document-scanner | dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js | function (position) {
/** @type {?} */
var positionChangeData = new PositionChangeData(position, this.limitRoles);
/** @type {?} */
var limitException = this.limitsService.exceedsLimit(positionChangeData);
if (limitException.exceeds) {
this.resetPosition = limitException.resetCoordinates;
if (limitException.exceeds) {
this.adjustPosition(limitException);
positionChangeData = new PositionChangeData(this.position, this.limitRoles);
this.limitsService.updatePosition(positionChangeData);
}
}
} | javascript | function (position) {
/** @type {?} */
var positionChangeData = new PositionChangeData(position, this.limitRoles);
/** @type {?} */
var limitException = this.limitsService.exceedsLimit(positionChangeData);
if (limitException.exceeds) {
this.resetPosition = limitException.resetCoordinates;
if (limitException.exceeds) {
this.adjustPosition(limitException);
positionChangeData = new PositionChangeData(this.position, this.limitRoles);
this.limitsService.updatePosition(positionChangeData);
}
}
} | [
"function",
"(",
"position",
")",
"{",
"/** @type {?} */",
"var",
"positionChangeData",
"=",
"new",
"PositionChangeData",
"(",
"position",
",",
"this",
".",
"limitRoles",
")",
";",
"/** @type {?} */",
"var",
"limitException",
"=",
"this",
".",
"limitsService",
".",
"exceedsLimit",
"(",
"positionChangeData",
")",
";",
"if",
"(",
"limitException",
".",
"exceeds",
")",
"{",
"this",
".",
"resetPosition",
"=",
"limitException",
".",
"resetCoordinates",
";",
"if",
"(",
"limitException",
".",
"exceeds",
")",
"{",
"this",
".",
"adjustPosition",
"(",
"limitException",
")",
";",
"positionChangeData",
"=",
"new",
"PositionChangeData",
"(",
"this",
".",
"position",
",",
"this",
".",
"limitRoles",
")",
";",
"this",
".",
"limitsService",
".",
"updatePosition",
"(",
"positionChangeData",
")",
";",
"}",
"}",
"}"
] | called on movement end, checks if last position exceeded the limits ad adjusts
@param {?} position
@return {?} | [
"called",
"on",
"movement",
"end",
"checks",
"if",
"last",
"position",
"exceeded",
"the",
"limits",
"ad",
"adjusts"
] | 9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c | https://github.com/roiperlman/ngx-document-scanner/blob/9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c/dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js#L597-L610 | |
21,512 | roiperlman/ngx-document-scanner | dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js | function (dimensions) {
return {
x: this.limitRoles.includes('left') ? 0 : dimensions.width - this.width / 2,
y: this.limitRoles.includes('top') ? 0 : dimensions.height - this.height / 2
};
} | javascript | function (dimensions) {
return {
x: this.limitRoles.includes('left') ? 0 : dimensions.width - this.width / 2,
y: this.limitRoles.includes('top') ? 0 : dimensions.height - this.height / 2
};
} | [
"function",
"(",
"dimensions",
")",
"{",
"return",
"{",
"x",
":",
"this",
".",
"limitRoles",
".",
"includes",
"(",
"'left'",
")",
"?",
"0",
":",
"dimensions",
".",
"width",
"-",
"this",
".",
"width",
"/",
"2",
",",
"y",
":",
"this",
".",
"limitRoles",
".",
"includes",
"(",
"'top'",
")",
"?",
"0",
":",
"dimensions",
".",
"height",
"-",
"this",
".",
"height",
"/",
"2",
"}",
";",
"}"
] | calculates the initial positions of the point by it's roles
@private
@param {?} dimensions - dimensions of the pane in which the point is located
@return {?} | [
"calculates",
"the",
"initial",
"positions",
"of",
"the",
"point",
"by",
"it",
"s",
"roles"
] | 9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c | https://github.com/roiperlman/ngx-document-scanner/blob/9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c/dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js#L627-L632 | |
21,513 | roiperlman/ngx-document-scanner | dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js | function (position) {
if (this._paneDimensions.width === 0 || this._paneDimensions.height === 0) {
return position;
}
else {
if (position.x > this._paneDimensions.width) {
position.x = this._paneDimensions.width;
}
if (position.x < 0) {
position.x = 1;
}
if (position.y > this._paneDimensions.height) {
position.y = this._paneDimensions.height;
}
if (position.y < 0) {
position.y = 1;
}
}
return position;
} | javascript | function (position) {
if (this._paneDimensions.width === 0 || this._paneDimensions.height === 0) {
return position;
}
else {
if (position.x > this._paneDimensions.width) {
position.x = this._paneDimensions.width;
}
if (position.x < 0) {
position.x = 1;
}
if (position.y > this._paneDimensions.height) {
position.y = this._paneDimensions.height;
}
if (position.y < 0) {
position.y = 1;
}
}
return position;
} | [
"function",
"(",
"position",
")",
"{",
"if",
"(",
"this",
".",
"_paneDimensions",
".",
"width",
"===",
"0",
"||",
"this",
".",
"_paneDimensions",
".",
"height",
"===",
"0",
")",
"{",
"return",
"position",
";",
"}",
"else",
"{",
"if",
"(",
"position",
".",
"x",
">",
"this",
".",
"_paneDimensions",
".",
"width",
")",
"{",
"position",
".",
"x",
"=",
"this",
".",
"_paneDimensions",
".",
"width",
";",
"}",
"if",
"(",
"position",
".",
"x",
"<",
"0",
")",
"{",
"position",
".",
"x",
"=",
"1",
";",
"}",
"if",
"(",
"position",
".",
"y",
">",
"this",
".",
"_paneDimensions",
".",
"height",
")",
"{",
"position",
".",
"y",
"=",
"this",
".",
"_paneDimensions",
".",
"height",
";",
"}",
"if",
"(",
"position",
".",
"y",
"<",
"0",
")",
"{",
"position",
".",
"y",
"=",
"1",
";",
"}",
"}",
"return",
"position",
";",
"}"
] | returns a new point position if the movement exceeded the pane limit
@private
@param {?} position
@return {?} | [
"returns",
"a",
"new",
"point",
"position",
"if",
"the",
"movement",
"exceeded",
"the",
"pane",
"limit"
] | 9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c | https://github.com/roiperlman/ngx-document-scanner/blob/9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c/dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js#L676-L695 | |
21,514 | roiperlman/ngx-document-scanner | dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js | function () {
/** @type {?} */
var canvas = this.canvas.nativeElement;
/** @type {?} */
var ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, this.dimensions.width, this.dimensions.height);
} | javascript | function () {
/** @type {?} */
var canvas = this.canvas.nativeElement;
/** @type {?} */
var ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, this.dimensions.width, this.dimensions.height);
} | [
"function",
"(",
")",
"{",
"/** @type {?} */",
"var",
"canvas",
"=",
"this",
".",
"canvas",
".",
"nativeElement",
";",
"/** @type {?} */",
"var",
"ctx",
"=",
"canvas",
".",
"getContext",
"(",
"'2d'",
")",
";",
"ctx",
".",
"clearRect",
"(",
"0",
",",
"0",
",",
"this",
".",
"dimensions",
".",
"width",
",",
"this",
".",
"dimensions",
".",
"height",
")",
";",
"}"
] | clears the shape canvas
@private
@return {?} | [
"clears",
"the",
"shape",
"canvas"
] | 9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c | https://github.com/roiperlman/ngx-document-scanner/blob/9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c/dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js#L864-L870 | |
21,515 | roiperlman/ngx-document-scanner | dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js | function () {
var _this = this;
/** @type {?} */
var _points = Array.from(this._points);
/** @type {?} */
var sortedPoints = [];
/** @type {?} */
var sortOrder = {
vertical: ['top', 'top', 'bottom', 'bottom'],
horizontal: ['left', 'right', 'right', 'left']
};
var _loop_1 = function (i) {
/** @type {?} */
var roles = Array.from([sortOrder.vertical[i], sortOrder.horizontal[i]]);
sortedPoints.push(_points.filter(function (point) {
return _this.limitsService.compareArray(point.roles, roles);
})[0]);
};
for (var i = 0; i < 4; i++) {
_loop_1(i);
}
this._sortedPoints = sortedPoints;
} | javascript | function () {
var _this = this;
/** @type {?} */
var _points = Array.from(this._points);
/** @type {?} */
var sortedPoints = [];
/** @type {?} */
var sortOrder = {
vertical: ['top', 'top', 'bottom', 'bottom'],
horizontal: ['left', 'right', 'right', 'left']
};
var _loop_1 = function (i) {
/** @type {?} */
var roles = Array.from([sortOrder.vertical[i], sortOrder.horizontal[i]]);
sortedPoints.push(_points.filter(function (point) {
return _this.limitsService.compareArray(point.roles, roles);
})[0]);
};
for (var i = 0; i < 4; i++) {
_loop_1(i);
}
this._sortedPoints = sortedPoints;
} | [
"function",
"(",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"/** @type {?} */",
"var",
"_points",
"=",
"Array",
".",
"from",
"(",
"this",
".",
"_points",
")",
";",
"/** @type {?} */",
"var",
"sortedPoints",
"=",
"[",
"]",
";",
"/** @type {?} */",
"var",
"sortOrder",
"=",
"{",
"vertical",
":",
"[",
"'top'",
",",
"'top'",
",",
"'bottom'",
",",
"'bottom'",
"]",
",",
"horizontal",
":",
"[",
"'left'",
",",
"'right'",
",",
"'right'",
",",
"'left'",
"]",
"}",
";",
"var",
"_loop_1",
"=",
"function",
"(",
"i",
")",
"{",
"/** @type {?} */",
"var",
"roles",
"=",
"Array",
".",
"from",
"(",
"[",
"sortOrder",
".",
"vertical",
"[",
"i",
"]",
",",
"sortOrder",
".",
"horizontal",
"[",
"i",
"]",
"]",
")",
";",
"sortedPoints",
".",
"push",
"(",
"_points",
".",
"filter",
"(",
"function",
"(",
"point",
")",
"{",
"return",
"_this",
".",
"limitsService",
".",
"compareArray",
"(",
"point",
".",
"roles",
",",
"roles",
")",
";",
"}",
")",
"[",
"0",
"]",
")",
";",
"}",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"4",
";",
"i",
"++",
")",
"{",
"_loop_1",
"(",
"i",
")",
";",
"}",
"this",
".",
"_sortedPoints",
"=",
"sortedPoints",
";",
"}"
] | sorts the array of points according to their clockwise alignment
@private
@return {?} | [
"sorts",
"the",
"array",
"of",
"points",
"according",
"to",
"their",
"clockwise",
"alignment"
] | 9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c | https://github.com/roiperlman/ngx-document-scanner/blob/9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c/dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js#L884-L906 | |
21,516 | roiperlman/ngx-document-scanner | dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js | function () {
var _this = this;
/** @type {?} */
var canvas = this.canvas.nativeElement;
/** @type {?} */
var ctx = canvas.getContext('2d');
ctx.lineWidth = this.weight;
ctx.strokeStyle = this.color;
ctx.beginPath();
this._sortedPoints.forEach(function (point, index) {
if (index === 0) {
ctx.moveTo(point.x, point.y);
}
if (index !== _this._sortedPoints.length - 1) {
/** @type {?} */
var nextPoint = _this._sortedPoints[index + 1];
ctx.lineTo(nextPoint.x, nextPoint.y);
}
else {
ctx.closePath();
}
});
ctx.stroke();
} | javascript | function () {
var _this = this;
/** @type {?} */
var canvas = this.canvas.nativeElement;
/** @type {?} */
var ctx = canvas.getContext('2d');
ctx.lineWidth = this.weight;
ctx.strokeStyle = this.color;
ctx.beginPath();
this._sortedPoints.forEach(function (point, index) {
if (index === 0) {
ctx.moveTo(point.x, point.y);
}
if (index !== _this._sortedPoints.length - 1) {
/** @type {?} */
var nextPoint = _this._sortedPoints[index + 1];
ctx.lineTo(nextPoint.x, nextPoint.y);
}
else {
ctx.closePath();
}
});
ctx.stroke();
} | [
"function",
"(",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"/** @type {?} */",
"var",
"canvas",
"=",
"this",
".",
"canvas",
".",
"nativeElement",
";",
"/** @type {?} */",
"var",
"ctx",
"=",
"canvas",
".",
"getContext",
"(",
"'2d'",
")",
";",
"ctx",
".",
"lineWidth",
"=",
"this",
".",
"weight",
";",
"ctx",
".",
"strokeStyle",
"=",
"this",
".",
"color",
";",
"ctx",
".",
"beginPath",
"(",
")",
";",
"this",
".",
"_sortedPoints",
".",
"forEach",
"(",
"function",
"(",
"point",
",",
"index",
")",
"{",
"if",
"(",
"index",
"===",
"0",
")",
"{",
"ctx",
".",
"moveTo",
"(",
"point",
".",
"x",
",",
"point",
".",
"y",
")",
";",
"}",
"if",
"(",
"index",
"!==",
"_this",
".",
"_sortedPoints",
".",
"length",
"-",
"1",
")",
"{",
"/** @type {?} */",
"var",
"nextPoint",
"=",
"_this",
".",
"_sortedPoints",
"[",
"index",
"+",
"1",
"]",
";",
"ctx",
".",
"lineTo",
"(",
"nextPoint",
".",
"x",
",",
"nextPoint",
".",
"y",
")",
";",
"}",
"else",
"{",
"ctx",
".",
"closePath",
"(",
")",
";",
"}",
"}",
")",
";",
"ctx",
".",
"stroke",
"(",
")",
";",
"}"
] | draws a line between the points according to their order
@private
@return {?} | [
"draws",
"a",
"line",
"between",
"the",
"points",
"according",
"to",
"their",
"order"
] | 9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c | https://github.com/roiperlman/ngx-document-scanner/blob/9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c/dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js#L920-L943 | |
21,517 | roiperlman/ngx-document-scanner | dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js | function () {
return __awaiter(this, void 0, void 0, function () {
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.applyFilter(false)];
case 1:
_a.sent();
if (this.options.maxImageDimensions) {
this.resize(this.editedImage)
.then(function (resizeResult) {
resizeResult.toBlob(function (blob) {
_this.editResult.emit(blob);
_this.processing.emit(false);
}, _this.originalImage.type);
});
}
else {
this.editedImage.toBlob(function (blob) {
_this.editResult.emit(blob);
_this.processing.emit(false);
}, this.originalImage.type);
}
return [2 /*return*/];
}
});
});
} | javascript | function () {
return __awaiter(this, void 0, void 0, function () {
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.applyFilter(false)];
case 1:
_a.sent();
if (this.options.maxImageDimensions) {
this.resize(this.editedImage)
.then(function (resizeResult) {
resizeResult.toBlob(function (blob) {
_this.editResult.emit(blob);
_this.processing.emit(false);
}, _this.originalImage.type);
});
}
else {
this.editedImage.toBlob(function (blob) {
_this.editResult.emit(blob);
_this.processing.emit(false);
}, this.originalImage.type);
}
return [2 /*return*/];
}
});
});
} | [
"function",
"(",
")",
"{",
"return",
"__awaiter",
"(",
"this",
",",
"void",
"0",
",",
"void",
"0",
",",
"function",
"(",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"return",
"__generator",
"(",
"this",
",",
"function",
"(",
"_a",
")",
"{",
"switch",
"(",
"_a",
".",
"label",
")",
"{",
"case",
"0",
":",
"return",
"[",
"4",
"/*yield*/",
",",
"this",
".",
"applyFilter",
"(",
"false",
")",
"]",
";",
"case",
"1",
":",
"_a",
".",
"sent",
"(",
")",
";",
"if",
"(",
"this",
".",
"options",
".",
"maxImageDimensions",
")",
"{",
"this",
".",
"resize",
"(",
"this",
".",
"editedImage",
")",
".",
"then",
"(",
"function",
"(",
"resizeResult",
")",
"{",
"resizeResult",
".",
"toBlob",
"(",
"function",
"(",
"blob",
")",
"{",
"_this",
".",
"editResult",
".",
"emit",
"(",
"blob",
")",
";",
"_this",
".",
"processing",
".",
"emit",
"(",
"false",
")",
";",
"}",
",",
"_this",
".",
"originalImage",
".",
"type",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"this",
".",
"editedImage",
".",
"toBlob",
"(",
"function",
"(",
"blob",
")",
"{",
"_this",
".",
"editResult",
".",
"emit",
"(",
"blob",
")",
";",
"_this",
".",
"processing",
".",
"emit",
"(",
"false",
")",
";",
"}",
",",
"this",
".",
"originalImage",
".",
"type",
")",
";",
"}",
"return",
"[",
"2",
"/*return*/",
"]",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}"
] | applies the selected filter, and when done emits the resulted image
@private
@return {?} | [
"applies",
"the",
"selected",
"filter",
"and",
"when",
"done",
"emits",
"the",
"resulted",
"image"
] | 9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c | https://github.com/roiperlman/ngx-document-scanner/blob/9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c/dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js#L1234-L1261 | |
21,518 | roiperlman/ngx-document-scanner | dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js | function () {
var _this = this;
/** @type {?} */
var data = { filter: this.selectedFilter };
/** @type {?} */
var bottomSheetRef = this.bottomSheet.open(NgxFilterMenuComponent, {
data: data
});
bottomSheetRef.afterDismissed().subscribe(function () {
_this.selectedFilter = data.filter;
_this.applyFilter(true);
});
} | javascript | function () {
var _this = this;
/** @type {?} */
var data = { filter: this.selectedFilter };
/** @type {?} */
var bottomSheetRef = this.bottomSheet.open(NgxFilterMenuComponent, {
data: data
});
bottomSheetRef.afterDismissed().subscribe(function () {
_this.selectedFilter = data.filter;
_this.applyFilter(true);
});
} | [
"function",
"(",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"/** @type {?} */",
"var",
"data",
"=",
"{",
"filter",
":",
"this",
".",
"selectedFilter",
"}",
";",
"/** @type {?} */",
"var",
"bottomSheetRef",
"=",
"this",
".",
"bottomSheet",
".",
"open",
"(",
"NgxFilterMenuComponent",
",",
"{",
"data",
":",
"data",
"}",
")",
";",
"bottomSheetRef",
".",
"afterDismissed",
"(",
")",
".",
"subscribe",
"(",
"function",
"(",
")",
"{",
"_this",
".",
"selectedFilter",
"=",
"data",
".",
"filter",
";",
"_this",
".",
"applyFilter",
"(",
"true",
")",
";",
"}",
")",
";",
"}"
] | open the bottom sheet for selecting filters, and applies the selected filter in preview mode
@private
@return {?} | [
"open",
"the",
"bottom",
"sheet",
"for",
"selecting",
"filters",
"and",
"applies",
"the",
"selected",
"filter",
"in",
"preview",
"mode"
] | 9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c | https://github.com/roiperlman/ngx-document-scanner/blob/9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c/dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js#L1275-L1287 | |
21,519 | roiperlman/ngx-document-scanner | dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js | function (file) {
var _this = this;
return new Promise(function (resolve, reject) {
return __awaiter(_this, void 0, void 0, function () {
var imageSrc, err_3, img;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, readFile()];
case 1:
imageSrc = _a.sent();
return [3 /*break*/, 3];
case 2:
err_3 = _a.sent();
reject(err_3);
return [3 /*break*/, 3];
case 3:
img = new Image();
img.onload = function () {
return __awaiter(_this, void 0, void 0, function () {
var ctx, width, _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
// set edited image canvas and dimensions
this.editedImage = ( /** @type {?} */(document.createElement('canvas')));
this.editedImage.width = img.width;
this.editedImage.height = img.height;
ctx = this.editedImage.getContext('2d');
ctx.drawImage(img, 0, 0);
// resize image if larger than max image size
width = img.width > img.height ? img.height : img.width;
if (!(width > this.options.maxImageDimensions.width))
return [3 /*break*/, 2];
_a = this;
return [4 /*yield*/, this.resize(this.editedImage)];
case 1:
_a.editedImage = _b.sent();
_b.label = 2;
case 2:
this.imageDimensions.width = this.editedImage.width;
this.imageDimensions.height = this.editedImage.height;
this.setPreviewPaneDimensions(this.editedImage);
resolve();
return [2 /*return*/];
}
});
});
};
img.src = imageSrc;
return [2 /*return*/];
}
});
});
});
/**
* read file from input field
* @return {?}
*/
function readFile() {
return new Promise(function (resolve, reject) {
/** @type {?} */
var reader = new FileReader();
reader.onload = function (event) {
resolve(reader.result);
};
reader.onerror = function (err) {
reject(err);
};
reader.readAsDataURL(file);
});
}
} | javascript | function (file) {
var _this = this;
return new Promise(function (resolve, reject) {
return __awaiter(_this, void 0, void 0, function () {
var imageSrc, err_3, img;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, readFile()];
case 1:
imageSrc = _a.sent();
return [3 /*break*/, 3];
case 2:
err_3 = _a.sent();
reject(err_3);
return [3 /*break*/, 3];
case 3:
img = new Image();
img.onload = function () {
return __awaiter(_this, void 0, void 0, function () {
var ctx, width, _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
// set edited image canvas and dimensions
this.editedImage = ( /** @type {?} */(document.createElement('canvas')));
this.editedImage.width = img.width;
this.editedImage.height = img.height;
ctx = this.editedImage.getContext('2d');
ctx.drawImage(img, 0, 0);
// resize image if larger than max image size
width = img.width > img.height ? img.height : img.width;
if (!(width > this.options.maxImageDimensions.width))
return [3 /*break*/, 2];
_a = this;
return [4 /*yield*/, this.resize(this.editedImage)];
case 1:
_a.editedImage = _b.sent();
_b.label = 2;
case 2:
this.imageDimensions.width = this.editedImage.width;
this.imageDimensions.height = this.editedImage.height;
this.setPreviewPaneDimensions(this.editedImage);
resolve();
return [2 /*return*/];
}
});
});
};
img.src = imageSrc;
return [2 /*return*/];
}
});
});
});
/**
* read file from input field
* @return {?}
*/
function readFile() {
return new Promise(function (resolve, reject) {
/** @type {?} */
var reader = new FileReader();
reader.onload = function (event) {
resolve(reader.result);
};
reader.onerror = function (err) {
reject(err);
};
reader.readAsDataURL(file);
});
}
} | [
"function",
"(",
"file",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"return",
"__awaiter",
"(",
"_this",
",",
"void",
"0",
",",
"void",
"0",
",",
"function",
"(",
")",
"{",
"var",
"imageSrc",
",",
"err_3",
",",
"img",
";",
"var",
"_this",
"=",
"this",
";",
"return",
"__generator",
"(",
"this",
",",
"function",
"(",
"_a",
")",
"{",
"switch",
"(",
"_a",
".",
"label",
")",
"{",
"case",
"0",
":",
"_a",
".",
"trys",
".",
"push",
"(",
"[",
"0",
",",
"2",
",",
",",
"3",
"]",
")",
";",
"return",
"[",
"4",
"/*yield*/",
",",
"readFile",
"(",
")",
"]",
";",
"case",
"1",
":",
"imageSrc",
"=",
"_a",
".",
"sent",
"(",
")",
";",
"return",
"[",
"3",
"/*break*/",
",",
"3",
"]",
";",
"case",
"2",
":",
"err_3",
"=",
"_a",
".",
"sent",
"(",
")",
";",
"reject",
"(",
"err_3",
")",
";",
"return",
"[",
"3",
"/*break*/",
",",
"3",
"]",
";",
"case",
"3",
":",
"img",
"=",
"new",
"Image",
"(",
")",
";",
"img",
".",
"onload",
"=",
"function",
"(",
")",
"{",
"return",
"__awaiter",
"(",
"_this",
",",
"void",
"0",
",",
"void",
"0",
",",
"function",
"(",
")",
"{",
"var",
"ctx",
",",
"width",
",",
"_a",
";",
"return",
"__generator",
"(",
"this",
",",
"function",
"(",
"_b",
")",
"{",
"switch",
"(",
"_b",
".",
"label",
")",
"{",
"case",
"0",
":",
"// set edited image canvas and dimensions",
"this",
".",
"editedImage",
"=",
"(",
"/** @type {?} */",
"(",
"document",
".",
"createElement",
"(",
"'canvas'",
")",
")",
")",
";",
"this",
".",
"editedImage",
".",
"width",
"=",
"img",
".",
"width",
";",
"this",
".",
"editedImage",
".",
"height",
"=",
"img",
".",
"height",
";",
"ctx",
"=",
"this",
".",
"editedImage",
".",
"getContext",
"(",
"'2d'",
")",
";",
"ctx",
".",
"drawImage",
"(",
"img",
",",
"0",
",",
"0",
")",
";",
"// resize image if larger than max image size",
"width",
"=",
"img",
".",
"width",
">",
"img",
".",
"height",
"?",
"img",
".",
"height",
":",
"img",
".",
"width",
";",
"if",
"(",
"!",
"(",
"width",
">",
"this",
".",
"options",
".",
"maxImageDimensions",
".",
"width",
")",
")",
"return",
"[",
"3",
"/*break*/",
",",
"2",
"]",
";",
"_a",
"=",
"this",
";",
"return",
"[",
"4",
"/*yield*/",
",",
"this",
".",
"resize",
"(",
"this",
".",
"editedImage",
")",
"]",
";",
"case",
"1",
":",
"_a",
".",
"editedImage",
"=",
"_b",
".",
"sent",
"(",
")",
";",
"_b",
".",
"label",
"=",
"2",
";",
"case",
"2",
":",
"this",
".",
"imageDimensions",
".",
"width",
"=",
"this",
".",
"editedImage",
".",
"width",
";",
"this",
".",
"imageDimensions",
".",
"height",
"=",
"this",
".",
"editedImage",
".",
"height",
";",
"this",
".",
"setPreviewPaneDimensions",
"(",
"this",
".",
"editedImage",
")",
";",
"resolve",
"(",
")",
";",
"return",
"[",
"2",
"/*return*/",
"]",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}",
";",
"img",
".",
"src",
"=",
"imageSrc",
";",
"return",
"[",
"2",
"/*return*/",
"]",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"/**\n * read file from input field\n * @return {?}\n */",
"function",
"readFile",
"(",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"/** @type {?} */",
"var",
"reader",
"=",
"new",
"FileReader",
"(",
")",
";",
"reader",
".",
"onload",
"=",
"function",
"(",
"event",
")",
"{",
"resolve",
"(",
"reader",
".",
"result",
")",
";",
"}",
";",
"reader",
".",
"onerror",
"=",
"function",
"(",
"err",
")",
"{",
"reject",
"(",
"err",
")",
";",
"}",
";",
"reader",
".",
"readAsDataURL",
"(",
"file",
")",
";",
"}",
")",
";",
"}",
"}"
] | read image from File object
@private
@param {?} file
@return {?} | [
"read",
"image",
"from",
"File",
"object"
] | 9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c | https://github.com/roiperlman/ngx-document-scanner/blob/9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c/dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js#L1388-L1462 | |
21,520 | roiperlman/ngx-document-scanner | dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js | readFile | function readFile() {
return new Promise(function (resolve, reject) {
/** @type {?} */
var reader = new FileReader();
reader.onload = function (event) {
resolve(reader.result);
};
reader.onerror = function (err) {
reject(err);
};
reader.readAsDataURL(file);
});
} | javascript | function readFile() {
return new Promise(function (resolve, reject) {
/** @type {?} */
var reader = new FileReader();
reader.onload = function (event) {
resolve(reader.result);
};
reader.onerror = function (err) {
reject(err);
};
reader.readAsDataURL(file);
});
} | [
"function",
"readFile",
"(",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"/** @type {?} */",
"var",
"reader",
"=",
"new",
"FileReader",
"(",
")",
";",
"reader",
".",
"onload",
"=",
"function",
"(",
"event",
")",
"{",
"resolve",
"(",
"reader",
".",
"result",
")",
";",
"}",
";",
"reader",
".",
"onerror",
"=",
"function",
"(",
"err",
")",
"{",
"reject",
"(",
"err",
")",
";",
"}",
";",
"reader",
".",
"readAsDataURL",
"(",
"file",
")",
";",
"}",
")",
";",
"}"
] | read file from input field
@return {?} | [
"read",
"file",
"from",
"input",
"field"
] | 9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c | https://github.com/roiperlman/ngx-document-scanner/blob/9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c/dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js#L1449-L1461 |
21,521 | roiperlman/ngx-document-scanner | dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js | function () {
var _this = this;
return new Promise(function (resolve, reject) {
_this.processing.emit(true);
setTimeout(function () {
// load the image and compute the ratio of the old height to the new height, clone it, and resize it
/** @type {?} */
var processingResizeRatio = 0.5;
/** @type {?} */
var dst = cv.imread(_this.editedImage);
/** @type {?} */
var dsize = new cv.Size(dst.rows * processingResizeRatio, dst.cols * processingResizeRatio);
/** @type {?} */
var ksize = new cv.Size(5, 5);
// convert the image to grayscale, blur it, and find edges in the image
cv.cvtColor(dst, dst, cv.COLOR_RGBA2GRAY, 0);
cv.GaussianBlur(dst, dst, ksize, 0, 0, cv.BORDER_DEFAULT);
cv.Canny(dst, dst, 75, 200);
// find contours
cv.threshold(dst, dst, 120, 200, cv.THRESH_BINARY);
/** @type {?} */
var contours = new cv.MatVector();
/** @type {?} */
var hierarchy = new cv.Mat();
cv.findContours(dst, contours, hierarchy, cv.RETR_CCOMP, cv.CHAIN_APPROX_SIMPLE);
/** @type {?} */
var rect = cv.boundingRect(dst);
dst.delete();
hierarchy.delete();
contours.delete();
// transform the rectangle into a set of points
Object.keys(rect).forEach(function (key) {
rect[key] = rect[key] * _this.imageResizeRatio;
});
/** @type {?} */
var contourCoordinates = [
new PositionChangeData({ x: rect.x, y: rect.y }, ['left', 'top']),
new PositionChangeData({ x: rect.x + rect.width, y: rect.y }, ['right', 'top']),
new PositionChangeData({ x: rect.x + rect.width, y: rect.y + rect.height }, ['right', 'bottom']),
new PositionChangeData({ x: rect.x, y: rect.y + rect.height }, ['left', 'bottom']),
];
_this.limitsService.repositionPoints(contourCoordinates);
// this.processing.emit(false);
resolve();
}, 30);
});
} | javascript | function () {
var _this = this;
return new Promise(function (resolve, reject) {
_this.processing.emit(true);
setTimeout(function () {
// load the image and compute the ratio of the old height to the new height, clone it, and resize it
/** @type {?} */
var processingResizeRatio = 0.5;
/** @type {?} */
var dst = cv.imread(_this.editedImage);
/** @type {?} */
var dsize = new cv.Size(dst.rows * processingResizeRatio, dst.cols * processingResizeRatio);
/** @type {?} */
var ksize = new cv.Size(5, 5);
// convert the image to grayscale, blur it, and find edges in the image
cv.cvtColor(dst, dst, cv.COLOR_RGBA2GRAY, 0);
cv.GaussianBlur(dst, dst, ksize, 0, 0, cv.BORDER_DEFAULT);
cv.Canny(dst, dst, 75, 200);
// find contours
cv.threshold(dst, dst, 120, 200, cv.THRESH_BINARY);
/** @type {?} */
var contours = new cv.MatVector();
/** @type {?} */
var hierarchy = new cv.Mat();
cv.findContours(dst, contours, hierarchy, cv.RETR_CCOMP, cv.CHAIN_APPROX_SIMPLE);
/** @type {?} */
var rect = cv.boundingRect(dst);
dst.delete();
hierarchy.delete();
contours.delete();
// transform the rectangle into a set of points
Object.keys(rect).forEach(function (key) {
rect[key] = rect[key] * _this.imageResizeRatio;
});
/** @type {?} */
var contourCoordinates = [
new PositionChangeData({ x: rect.x, y: rect.y }, ['left', 'top']),
new PositionChangeData({ x: rect.x + rect.width, y: rect.y }, ['right', 'top']),
new PositionChangeData({ x: rect.x + rect.width, y: rect.y + rect.height }, ['right', 'bottom']),
new PositionChangeData({ x: rect.x, y: rect.y + rect.height }, ['left', 'bottom']),
];
_this.limitsService.repositionPoints(contourCoordinates);
// this.processing.emit(false);
resolve();
}, 30);
});
} | [
"function",
"(",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"_this",
".",
"processing",
".",
"emit",
"(",
"true",
")",
";",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"// load the image and compute the ratio of the old height to the new height, clone it, and resize it",
"/** @type {?} */",
"var",
"processingResizeRatio",
"=",
"0.5",
";",
"/** @type {?} */",
"var",
"dst",
"=",
"cv",
".",
"imread",
"(",
"_this",
".",
"editedImage",
")",
";",
"/** @type {?} */",
"var",
"dsize",
"=",
"new",
"cv",
".",
"Size",
"(",
"dst",
".",
"rows",
"*",
"processingResizeRatio",
",",
"dst",
".",
"cols",
"*",
"processingResizeRatio",
")",
";",
"/** @type {?} */",
"var",
"ksize",
"=",
"new",
"cv",
".",
"Size",
"(",
"5",
",",
"5",
")",
";",
"// convert the image to grayscale, blur it, and find edges in the image",
"cv",
".",
"cvtColor",
"(",
"dst",
",",
"dst",
",",
"cv",
".",
"COLOR_RGBA2GRAY",
",",
"0",
")",
";",
"cv",
".",
"GaussianBlur",
"(",
"dst",
",",
"dst",
",",
"ksize",
",",
"0",
",",
"0",
",",
"cv",
".",
"BORDER_DEFAULT",
")",
";",
"cv",
".",
"Canny",
"(",
"dst",
",",
"dst",
",",
"75",
",",
"200",
")",
";",
"// find contours",
"cv",
".",
"threshold",
"(",
"dst",
",",
"dst",
",",
"120",
",",
"200",
",",
"cv",
".",
"THRESH_BINARY",
")",
";",
"/** @type {?} */",
"var",
"contours",
"=",
"new",
"cv",
".",
"MatVector",
"(",
")",
";",
"/** @type {?} */",
"var",
"hierarchy",
"=",
"new",
"cv",
".",
"Mat",
"(",
")",
";",
"cv",
".",
"findContours",
"(",
"dst",
",",
"contours",
",",
"hierarchy",
",",
"cv",
".",
"RETR_CCOMP",
",",
"cv",
".",
"CHAIN_APPROX_SIMPLE",
")",
";",
"/** @type {?} */",
"var",
"rect",
"=",
"cv",
".",
"boundingRect",
"(",
"dst",
")",
";",
"dst",
".",
"delete",
"(",
")",
";",
"hierarchy",
".",
"delete",
"(",
")",
";",
"contours",
".",
"delete",
"(",
")",
";",
"// transform the rectangle into a set of points",
"Object",
".",
"keys",
"(",
"rect",
")",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"rect",
"[",
"key",
"]",
"=",
"rect",
"[",
"key",
"]",
"*",
"_this",
".",
"imageResizeRatio",
";",
"}",
")",
";",
"/** @type {?} */",
"var",
"contourCoordinates",
"=",
"[",
"new",
"PositionChangeData",
"(",
"{",
"x",
":",
"rect",
".",
"x",
",",
"y",
":",
"rect",
".",
"y",
"}",
",",
"[",
"'left'",
",",
"'top'",
"]",
")",
",",
"new",
"PositionChangeData",
"(",
"{",
"x",
":",
"rect",
".",
"x",
"+",
"rect",
".",
"width",
",",
"y",
":",
"rect",
".",
"y",
"}",
",",
"[",
"'right'",
",",
"'top'",
"]",
")",
",",
"new",
"PositionChangeData",
"(",
"{",
"x",
":",
"rect",
".",
"x",
"+",
"rect",
".",
"width",
",",
"y",
":",
"rect",
".",
"y",
"+",
"rect",
".",
"height",
"}",
",",
"[",
"'right'",
",",
"'bottom'",
"]",
")",
",",
"new",
"PositionChangeData",
"(",
"{",
"x",
":",
"rect",
".",
"x",
",",
"y",
":",
"rect",
".",
"y",
"+",
"rect",
".",
"height",
"}",
",",
"[",
"'left'",
",",
"'bottom'",
"]",
")",
",",
"]",
";",
"_this",
".",
"limitsService",
".",
"repositionPoints",
"(",
"contourCoordinates",
")",
";",
"// this.processing.emit(false);",
"resolve",
"(",
")",
";",
"}",
",",
"30",
")",
";",
"}",
")",
";",
"}"
] | detects the contours of the document and
@private
@return {?} | [
"detects",
"the",
"contours",
"of",
"the",
"document",
"and"
] | 9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c | https://github.com/roiperlman/ngx-document-scanner/blob/9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c/dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js#L1538-L1584 | |
21,522 | roiperlman/ngx-document-scanner | dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js | function () {
var _this = this;
return new Promise(function (resolve, reject) {
_this.processing.emit(true);
setTimeout(function () {
/** @type {?} */
var dst = cv.imread(_this.editedImage);
// create source coordinates matrix
/** @type {?} */
var sourceCoordinates = [
_this.getPoint(['top', 'left']),
_this.getPoint(['top', 'right']),
_this.getPoint(['bottom', 'right']),
_this.getPoint(['bottom', 'left'])
].map(function (point) {
return [point.x / _this.imageResizeRatio, point.y / _this.imageResizeRatio];
});
// get max width
/** @type {?} */
var bottomWidth = _this.getPoint(['bottom', 'right']).x - _this.getPoint(['bottom', 'left']).x;
/** @type {?} */
var topWidth = _this.getPoint(['top', 'right']).x - _this.getPoint(['top', 'left']).x;
/** @type {?} */
var maxWidth = Math.max(bottomWidth, topWidth) / _this.imageResizeRatio;
// get max height
/** @type {?} */
var leftHeight = _this.getPoint(['bottom', 'left']).y - _this.getPoint(['top', 'left']).y;
/** @type {?} */
var rightHeight = _this.getPoint(['bottom', 'right']).y - _this.getPoint(['top', 'right']).y;
/** @type {?} */
var maxHeight = Math.max(leftHeight, rightHeight) / _this.imageResizeRatio;
// create dest coordinates matrix
/** @type {?} */
var destCoordinates = [
[0, 0],
[maxWidth - 1, 0],
[maxWidth - 1, maxHeight - 1],
[0, maxHeight - 1]
];
// convert to open cv matrix objects
/** @type {?} */
var Ms = cv.matFromArray(4, 1, cv.CV_32FC2, [].concat.apply([], __spread(sourceCoordinates)));
/** @type {?} */
var Md = cv.matFromArray(4, 1, cv.CV_32FC2, [].concat.apply([], __spread(destCoordinates)));
/** @type {?} */
var transformMatrix = cv.getPerspectiveTransform(Ms, Md);
// set new image size
/** @type {?} */
var dsize = new cv.Size(maxWidth, maxHeight);
// perform warp
cv.warpPerspective(dst, dst, transformMatrix, dsize, cv.INTER_LINEAR, cv.BORDER_CONSTANT, new cv.Scalar());
cv.imshow(_this.editedImage, dst);
dst.delete();
Ms.delete();
Md.delete();
transformMatrix.delete();
_this.setPreviewPaneDimensions(_this.editedImage);
_this.showPreview().then(function () {
_this.processing.emit(false);
resolve();
});
}, 30);
});
} | javascript | function () {
var _this = this;
return new Promise(function (resolve, reject) {
_this.processing.emit(true);
setTimeout(function () {
/** @type {?} */
var dst = cv.imread(_this.editedImage);
// create source coordinates matrix
/** @type {?} */
var sourceCoordinates = [
_this.getPoint(['top', 'left']),
_this.getPoint(['top', 'right']),
_this.getPoint(['bottom', 'right']),
_this.getPoint(['bottom', 'left'])
].map(function (point) {
return [point.x / _this.imageResizeRatio, point.y / _this.imageResizeRatio];
});
// get max width
/** @type {?} */
var bottomWidth = _this.getPoint(['bottom', 'right']).x - _this.getPoint(['bottom', 'left']).x;
/** @type {?} */
var topWidth = _this.getPoint(['top', 'right']).x - _this.getPoint(['top', 'left']).x;
/** @type {?} */
var maxWidth = Math.max(bottomWidth, topWidth) / _this.imageResizeRatio;
// get max height
/** @type {?} */
var leftHeight = _this.getPoint(['bottom', 'left']).y - _this.getPoint(['top', 'left']).y;
/** @type {?} */
var rightHeight = _this.getPoint(['bottom', 'right']).y - _this.getPoint(['top', 'right']).y;
/** @type {?} */
var maxHeight = Math.max(leftHeight, rightHeight) / _this.imageResizeRatio;
// create dest coordinates matrix
/** @type {?} */
var destCoordinates = [
[0, 0],
[maxWidth - 1, 0],
[maxWidth - 1, maxHeight - 1],
[0, maxHeight - 1]
];
// convert to open cv matrix objects
/** @type {?} */
var Ms = cv.matFromArray(4, 1, cv.CV_32FC2, [].concat.apply([], __spread(sourceCoordinates)));
/** @type {?} */
var Md = cv.matFromArray(4, 1, cv.CV_32FC2, [].concat.apply([], __spread(destCoordinates)));
/** @type {?} */
var transformMatrix = cv.getPerspectiveTransform(Ms, Md);
// set new image size
/** @type {?} */
var dsize = new cv.Size(maxWidth, maxHeight);
// perform warp
cv.warpPerspective(dst, dst, transformMatrix, dsize, cv.INTER_LINEAR, cv.BORDER_CONSTANT, new cv.Scalar());
cv.imshow(_this.editedImage, dst);
dst.delete();
Ms.delete();
Md.delete();
transformMatrix.delete();
_this.setPreviewPaneDimensions(_this.editedImage);
_this.showPreview().then(function () {
_this.processing.emit(false);
resolve();
});
}, 30);
});
} | [
"function",
"(",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"_this",
".",
"processing",
".",
"emit",
"(",
"true",
")",
";",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"/** @type {?} */",
"var",
"dst",
"=",
"cv",
".",
"imread",
"(",
"_this",
".",
"editedImage",
")",
";",
"// create source coordinates matrix",
"/** @type {?} */",
"var",
"sourceCoordinates",
"=",
"[",
"_this",
".",
"getPoint",
"(",
"[",
"'top'",
",",
"'left'",
"]",
")",
",",
"_this",
".",
"getPoint",
"(",
"[",
"'top'",
",",
"'right'",
"]",
")",
",",
"_this",
".",
"getPoint",
"(",
"[",
"'bottom'",
",",
"'right'",
"]",
")",
",",
"_this",
".",
"getPoint",
"(",
"[",
"'bottom'",
",",
"'left'",
"]",
")",
"]",
".",
"map",
"(",
"function",
"(",
"point",
")",
"{",
"return",
"[",
"point",
".",
"x",
"/",
"_this",
".",
"imageResizeRatio",
",",
"point",
".",
"y",
"/",
"_this",
".",
"imageResizeRatio",
"]",
";",
"}",
")",
";",
"// get max width",
"/** @type {?} */",
"var",
"bottomWidth",
"=",
"_this",
".",
"getPoint",
"(",
"[",
"'bottom'",
",",
"'right'",
"]",
")",
".",
"x",
"-",
"_this",
".",
"getPoint",
"(",
"[",
"'bottom'",
",",
"'left'",
"]",
")",
".",
"x",
";",
"/** @type {?} */",
"var",
"topWidth",
"=",
"_this",
".",
"getPoint",
"(",
"[",
"'top'",
",",
"'right'",
"]",
")",
".",
"x",
"-",
"_this",
".",
"getPoint",
"(",
"[",
"'top'",
",",
"'left'",
"]",
")",
".",
"x",
";",
"/** @type {?} */",
"var",
"maxWidth",
"=",
"Math",
".",
"max",
"(",
"bottomWidth",
",",
"topWidth",
")",
"/",
"_this",
".",
"imageResizeRatio",
";",
"// get max height",
"/** @type {?} */",
"var",
"leftHeight",
"=",
"_this",
".",
"getPoint",
"(",
"[",
"'bottom'",
",",
"'left'",
"]",
")",
".",
"y",
"-",
"_this",
".",
"getPoint",
"(",
"[",
"'top'",
",",
"'left'",
"]",
")",
".",
"y",
";",
"/** @type {?} */",
"var",
"rightHeight",
"=",
"_this",
".",
"getPoint",
"(",
"[",
"'bottom'",
",",
"'right'",
"]",
")",
".",
"y",
"-",
"_this",
".",
"getPoint",
"(",
"[",
"'top'",
",",
"'right'",
"]",
")",
".",
"y",
";",
"/** @type {?} */",
"var",
"maxHeight",
"=",
"Math",
".",
"max",
"(",
"leftHeight",
",",
"rightHeight",
")",
"/",
"_this",
".",
"imageResizeRatio",
";",
"// create dest coordinates matrix",
"/** @type {?} */",
"var",
"destCoordinates",
"=",
"[",
"[",
"0",
",",
"0",
"]",
",",
"[",
"maxWidth",
"-",
"1",
",",
"0",
"]",
",",
"[",
"maxWidth",
"-",
"1",
",",
"maxHeight",
"-",
"1",
"]",
",",
"[",
"0",
",",
"maxHeight",
"-",
"1",
"]",
"]",
";",
"// convert to open cv matrix objects",
"/** @type {?} */",
"var",
"Ms",
"=",
"cv",
".",
"matFromArray",
"(",
"4",
",",
"1",
",",
"cv",
".",
"CV_32FC2",
",",
"[",
"]",
".",
"concat",
".",
"apply",
"(",
"[",
"]",
",",
"__spread",
"(",
"sourceCoordinates",
")",
")",
")",
";",
"/** @type {?} */",
"var",
"Md",
"=",
"cv",
".",
"matFromArray",
"(",
"4",
",",
"1",
",",
"cv",
".",
"CV_32FC2",
",",
"[",
"]",
".",
"concat",
".",
"apply",
"(",
"[",
"]",
",",
"__spread",
"(",
"destCoordinates",
")",
")",
")",
";",
"/** @type {?} */",
"var",
"transformMatrix",
"=",
"cv",
".",
"getPerspectiveTransform",
"(",
"Ms",
",",
"Md",
")",
";",
"// set new image size",
"/** @type {?} */",
"var",
"dsize",
"=",
"new",
"cv",
".",
"Size",
"(",
"maxWidth",
",",
"maxHeight",
")",
";",
"// perform warp",
"cv",
".",
"warpPerspective",
"(",
"dst",
",",
"dst",
",",
"transformMatrix",
",",
"dsize",
",",
"cv",
".",
"INTER_LINEAR",
",",
"cv",
".",
"BORDER_CONSTANT",
",",
"new",
"cv",
".",
"Scalar",
"(",
")",
")",
";",
"cv",
".",
"imshow",
"(",
"_this",
".",
"editedImage",
",",
"dst",
")",
";",
"dst",
".",
"delete",
"(",
")",
";",
"Ms",
".",
"delete",
"(",
")",
";",
"Md",
".",
"delete",
"(",
")",
";",
"transformMatrix",
".",
"delete",
"(",
")",
";",
"_this",
".",
"setPreviewPaneDimensions",
"(",
"_this",
".",
"editedImage",
")",
";",
"_this",
".",
"showPreview",
"(",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"_this",
".",
"processing",
".",
"emit",
"(",
"false",
")",
";",
"resolve",
"(",
")",
";",
"}",
")",
";",
"}",
",",
"30",
")",
";",
"}",
")",
";",
"}"
] | apply perspective transform
@private
@return {?} | [
"apply",
"perspective",
"transform"
] | 9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c | https://github.com/roiperlman/ngx-document-scanner/blob/9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c/dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js#L1598-L1661 | |
21,523 | roiperlman/ngx-document-scanner | dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js | function (image) {
var _this = this;
return new Promise(function (resolve, reject) {
_this.processing.emit(true);
setTimeout(function () {
/** @type {?} */
var src = cv.imread(image);
/** @type {?} */
var currentDimensions = {
width: src.size().width,
height: src.size().height
};
/** @type {?} */
var resizeDimensions = {
width: 0,
height: 0
};
if (currentDimensions.width > _this.options.maxImageDimensions.width) {
resizeDimensions.width = _this.options.maxImageDimensions.width;
resizeDimensions.height = _this.options.maxImageDimensions.width / currentDimensions.width * currentDimensions.height;
if (resizeDimensions.height > _this.options.maxImageDimensions.height) {
resizeDimensions.height = _this.options.maxImageDimensions.height;
resizeDimensions.width = _this.options.maxImageDimensions.height / currentDimensions.height * currentDimensions.width;
}
/** @type {?} */
var dsize = new cv.Size(Math.floor(resizeDimensions.width), Math.floor(resizeDimensions.height));
cv.resize(src, src, dsize, 0, 0, cv.INTER_AREA);
/** @type {?} */
var resizeResult = ( /** @type {?} */(document.createElement('canvas')));
cv.imshow(resizeResult, src);
src.delete();
_this.processing.emit(false);
resolve(resizeResult);
}
else {
_this.processing.emit(false);
resolve(image);
}
}, 30);
});
} | javascript | function (image) {
var _this = this;
return new Promise(function (resolve, reject) {
_this.processing.emit(true);
setTimeout(function () {
/** @type {?} */
var src = cv.imread(image);
/** @type {?} */
var currentDimensions = {
width: src.size().width,
height: src.size().height
};
/** @type {?} */
var resizeDimensions = {
width: 0,
height: 0
};
if (currentDimensions.width > _this.options.maxImageDimensions.width) {
resizeDimensions.width = _this.options.maxImageDimensions.width;
resizeDimensions.height = _this.options.maxImageDimensions.width / currentDimensions.width * currentDimensions.height;
if (resizeDimensions.height > _this.options.maxImageDimensions.height) {
resizeDimensions.height = _this.options.maxImageDimensions.height;
resizeDimensions.width = _this.options.maxImageDimensions.height / currentDimensions.height * currentDimensions.width;
}
/** @type {?} */
var dsize = new cv.Size(Math.floor(resizeDimensions.width), Math.floor(resizeDimensions.height));
cv.resize(src, src, dsize, 0, 0, cv.INTER_AREA);
/** @type {?} */
var resizeResult = ( /** @type {?} */(document.createElement('canvas')));
cv.imshow(resizeResult, src);
src.delete();
_this.processing.emit(false);
resolve(resizeResult);
}
else {
_this.processing.emit(false);
resolve(image);
}
}, 30);
});
} | [
"function",
"(",
"image",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"_this",
".",
"processing",
".",
"emit",
"(",
"true",
")",
";",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"/** @type {?} */",
"var",
"src",
"=",
"cv",
".",
"imread",
"(",
"image",
")",
";",
"/** @type {?} */",
"var",
"currentDimensions",
"=",
"{",
"width",
":",
"src",
".",
"size",
"(",
")",
".",
"width",
",",
"height",
":",
"src",
".",
"size",
"(",
")",
".",
"height",
"}",
";",
"/** @type {?} */",
"var",
"resizeDimensions",
"=",
"{",
"width",
":",
"0",
",",
"height",
":",
"0",
"}",
";",
"if",
"(",
"currentDimensions",
".",
"width",
">",
"_this",
".",
"options",
".",
"maxImageDimensions",
".",
"width",
")",
"{",
"resizeDimensions",
".",
"width",
"=",
"_this",
".",
"options",
".",
"maxImageDimensions",
".",
"width",
";",
"resizeDimensions",
".",
"height",
"=",
"_this",
".",
"options",
".",
"maxImageDimensions",
".",
"width",
"/",
"currentDimensions",
".",
"width",
"*",
"currentDimensions",
".",
"height",
";",
"if",
"(",
"resizeDimensions",
".",
"height",
">",
"_this",
".",
"options",
".",
"maxImageDimensions",
".",
"height",
")",
"{",
"resizeDimensions",
".",
"height",
"=",
"_this",
".",
"options",
".",
"maxImageDimensions",
".",
"height",
";",
"resizeDimensions",
".",
"width",
"=",
"_this",
".",
"options",
".",
"maxImageDimensions",
".",
"height",
"/",
"currentDimensions",
".",
"height",
"*",
"currentDimensions",
".",
"width",
";",
"}",
"/** @type {?} */",
"var",
"dsize",
"=",
"new",
"cv",
".",
"Size",
"(",
"Math",
".",
"floor",
"(",
"resizeDimensions",
".",
"width",
")",
",",
"Math",
".",
"floor",
"(",
"resizeDimensions",
".",
"height",
")",
")",
";",
"cv",
".",
"resize",
"(",
"src",
",",
"src",
",",
"dsize",
",",
"0",
",",
"0",
",",
"cv",
".",
"INTER_AREA",
")",
";",
"/** @type {?} */",
"var",
"resizeResult",
"=",
"(",
"/** @type {?} */",
"(",
"document",
".",
"createElement",
"(",
"'canvas'",
")",
")",
")",
";",
"cv",
".",
"imshow",
"(",
"resizeResult",
",",
"src",
")",
";",
"src",
".",
"delete",
"(",
")",
";",
"_this",
".",
"processing",
".",
"emit",
"(",
"false",
")",
";",
"resolve",
"(",
"resizeResult",
")",
";",
"}",
"else",
"{",
"_this",
".",
"processing",
".",
"emit",
"(",
"false",
")",
";",
"resolve",
"(",
"image",
")",
";",
"}",
"}",
",",
"30",
")",
";",
"}",
")",
";",
"}"
] | resize an image to fit constraints set in options.maxImageDimensions
@private
@param {?} image
@return {?} | [
"resize",
"an",
"image",
"to",
"fit",
"constraints",
"set",
"in",
"options",
".",
"maxImageDimensions"
] | 9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c | https://github.com/roiperlman/ngx-document-scanner/blob/9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c/dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js#L1774-L1814 | |
21,524 | roiperlman/ngx-document-scanner | dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js | function (width, height) {
/** @type {?} */
var ratio = width / height;
/** @type {?} */
var maxWidth = this.screenDimensions.width > this.maxPreviewWidth ?
this.maxPreviewWidth : this.screenDimensions.width - 40;
/** @type {?} */
var maxHeight = this.screenDimensions.height - 240;
/** @type {?} */
var calculated = {
width: maxWidth,
height: Math.round(maxWidth / ratio),
ratio: ratio
};
if (calculated.height > maxHeight) {
calculated.height = maxHeight;
calculated.width = Math.round(maxHeight * ratio);
}
return calculated;
} | javascript | function (width, height) {
/** @type {?} */
var ratio = width / height;
/** @type {?} */
var maxWidth = this.screenDimensions.width > this.maxPreviewWidth ?
this.maxPreviewWidth : this.screenDimensions.width - 40;
/** @type {?} */
var maxHeight = this.screenDimensions.height - 240;
/** @type {?} */
var calculated = {
width: maxWidth,
height: Math.round(maxWidth / ratio),
ratio: ratio
};
if (calculated.height > maxHeight) {
calculated.height = maxHeight;
calculated.width = Math.round(maxHeight * ratio);
}
return calculated;
} | [
"function",
"(",
"width",
",",
"height",
")",
"{",
"/** @type {?} */",
"var",
"ratio",
"=",
"width",
"/",
"height",
";",
"/** @type {?} */",
"var",
"maxWidth",
"=",
"this",
".",
"screenDimensions",
".",
"width",
">",
"this",
".",
"maxPreviewWidth",
"?",
"this",
".",
"maxPreviewWidth",
":",
"this",
".",
"screenDimensions",
".",
"width",
"-",
"40",
";",
"/** @type {?} */",
"var",
"maxHeight",
"=",
"this",
".",
"screenDimensions",
".",
"height",
"-",
"240",
";",
"/** @type {?} */",
"var",
"calculated",
"=",
"{",
"width",
":",
"maxWidth",
",",
"height",
":",
"Math",
".",
"round",
"(",
"maxWidth",
"/",
"ratio",
")",
",",
"ratio",
":",
"ratio",
"}",
";",
"if",
"(",
"calculated",
".",
"height",
">",
"maxHeight",
")",
"{",
"calculated",
".",
"height",
"=",
"maxHeight",
";",
"calculated",
".",
"width",
"=",
"Math",
".",
"round",
"(",
"maxHeight",
"*",
"ratio",
")",
";",
"}",
"return",
"calculated",
";",
"}"
] | calculate dimensions of the preview canvas
@private
@param {?} width
@param {?} height
@return {?} | [
"calculate",
"dimensions",
"of",
"the",
"preview",
"canvas"
] | 9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c | https://github.com/roiperlman/ngx-document-scanner/blob/9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c/dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js#L1908-L1927 | |
21,525 | roiperlman/ngx-document-scanner | dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js | function (roles) {
var _this = this;
return this.points.find(function (point) {
return _this.limitsService.compareArray(point.roles, roles);
});
} | javascript | function (roles) {
var _this = this;
return this.points.find(function (point) {
return _this.limitsService.compareArray(point.roles, roles);
});
} | [
"function",
"(",
"roles",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"return",
"this",
".",
"points",
".",
"find",
"(",
"function",
"(",
"point",
")",
"{",
"return",
"_this",
".",
"limitsService",
".",
"compareArray",
"(",
"point",
".",
"roles",
",",
"roles",
")",
";",
"}",
")",
";",
"}"
] | returns a point by it's roles
@private
@param {?} roles - an array of roles by which the point will be fetched
@return {?} | [
"returns",
"a",
"point",
"by",
"it",
"s",
"roles"
] | 9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c | https://github.com/roiperlman/ngx-document-scanner/blob/9c90358267a8c0cdd3ffcc3e41ee6a059b12d67c/dist/ngx-document-scanner/bundles/ngx-document-scanner.umd.js#L1944-L1949 | |
21,526 | VKCOM/node-vk-call | lib/persistent_longpoll.js | longpollStream | function longpollStream(http, mutable) {
return asyncMapRecover(function(creds) {
return http({
timeout: LONGPOLL_TIMEOUT,
url: makeUrl(assign({}, creds, mutable))
}).then(function(body) {
return JSON.parse(body);
}).catch((error) => {
return Promise.reject({
type: ERROR_TYPE_UNKNOWN,
error: error
});
}).then(function(response) {
switch (response.failed) {
case LP_ERROR_FAIL_TS:
mutable.ts = response.ts;
return Promise.reject({ type: ERROR_TYPE_TS })
case LP_ERROR_FAIL_KEY:
return Promise.reject({ type: ERROR_TYPE_CREDS })
default:
mutable.ts = response.ts;
return response.updates;
}
});
});
} | javascript | function longpollStream(http, mutable) {
return asyncMapRecover(function(creds) {
return http({
timeout: LONGPOLL_TIMEOUT,
url: makeUrl(assign({}, creds, mutable))
}).then(function(body) {
return JSON.parse(body);
}).catch((error) => {
return Promise.reject({
type: ERROR_TYPE_UNKNOWN,
error: error
});
}).then(function(response) {
switch (response.failed) {
case LP_ERROR_FAIL_TS:
mutable.ts = response.ts;
return Promise.reject({ type: ERROR_TYPE_TS })
case LP_ERROR_FAIL_KEY:
return Promise.reject({ type: ERROR_TYPE_CREDS })
default:
mutable.ts = response.ts;
return response.updates;
}
});
});
} | [
"function",
"longpollStream",
"(",
"http",
",",
"mutable",
")",
"{",
"return",
"asyncMapRecover",
"(",
"function",
"(",
"creds",
")",
"{",
"return",
"http",
"(",
"{",
"timeout",
":",
"LONGPOLL_TIMEOUT",
",",
"url",
":",
"makeUrl",
"(",
"assign",
"(",
"{",
"}",
",",
"creds",
",",
"mutable",
")",
")",
"}",
")",
".",
"then",
"(",
"function",
"(",
"body",
")",
"{",
"return",
"JSON",
".",
"parse",
"(",
"body",
")",
";",
"}",
")",
".",
"catch",
"(",
"(",
"error",
")",
"=>",
"{",
"return",
"Promise",
".",
"reject",
"(",
"{",
"type",
":",
"ERROR_TYPE_UNKNOWN",
",",
"error",
":",
"error",
"}",
")",
";",
"}",
")",
".",
"then",
"(",
"function",
"(",
"response",
")",
"{",
"switch",
"(",
"response",
".",
"failed",
")",
"{",
"case",
"LP_ERROR_FAIL_TS",
":",
"mutable",
".",
"ts",
"=",
"response",
".",
"ts",
";",
"return",
"Promise",
".",
"reject",
"(",
"{",
"type",
":",
"ERROR_TYPE_TS",
"}",
")",
"case",
"LP_ERROR_FAIL_KEY",
":",
"return",
"Promise",
".",
"reject",
"(",
"{",
"type",
":",
"ERROR_TYPE_CREDS",
"}",
")",
"default",
":",
"mutable",
".",
"ts",
"=",
"response",
".",
"ts",
";",
"return",
"response",
".",
"updates",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}"
] | Stream that requests longpoll and processes its data. Can throw errors in case
longpoll request returned error, or if failed parameter present in response. | [
"Stream",
"that",
"requests",
"longpoll",
"and",
"processes",
"its",
"data",
".",
"Can",
"throw",
"errors",
"in",
"case",
"longpoll",
"request",
"returned",
"error",
"or",
"if",
"failed",
"parameter",
"present",
"in",
"response",
"."
] | e829dca81c33908025a84e4f954bbddb210dfccc | https://github.com/VKCOM/node-vk-call/blob/e829dca81c33908025a84e4f954bbddb210dfccc/lib/persistent_longpoll.js#L44-L69 |
21,527 | VKCOM/node-vk-call | lib/stream_utils.js | cacher | function cacher() {
let cache = false;
return function(read) {
return function readable(end, cb) {
if (end === null && cache) {
cb(null, cache);
} else {
read(end, function (end, data) {
cache = data;
cb(end, data)
});
}
}
}
} | javascript | function cacher() {
let cache = false;
return function(read) {
return function readable(end, cb) {
if (end === null && cache) {
cb(null, cache);
} else {
read(end, function (end, data) {
cache = data;
cb(end, data)
});
}
}
}
} | [
"function",
"cacher",
"(",
")",
"{",
"let",
"cache",
"=",
"false",
";",
"return",
"function",
"(",
"read",
")",
"{",
"return",
"function",
"readable",
"(",
"end",
",",
"cb",
")",
"{",
"if",
"(",
"end",
"===",
"null",
"&&",
"cache",
")",
"{",
"cb",
"(",
"null",
",",
"cache",
")",
";",
"}",
"else",
"{",
"read",
"(",
"end",
",",
"function",
"(",
"end",
",",
"data",
")",
"{",
"cache",
"=",
"data",
";",
"cb",
"(",
"end",
",",
"data",
")",
"}",
")",
";",
"}",
"}",
"}",
"}"
] | Through stream that remembers first value it got
and repeats it, propagates errors in both ways. | [
"Through",
"stream",
"that",
"remembers",
"first",
"value",
"it",
"got",
"and",
"repeats",
"it",
"propagates",
"errors",
"in",
"both",
"ways",
"."
] | e829dca81c33908025a84e4f954bbddb210dfccc | https://github.com/VKCOM/node-vk-call/blob/e829dca81c33908025a84e4f954bbddb210dfccc/lib/stream_utils.js#L7-L21 |
21,528 | creationix/nstore | lib/file.js | safe3 | function safe3(fn) {
var queue = Queue.new();
var safe = true;
function checkQueue() {
var next = queue.shift();
safe = false;
fn(next[0], next[1], next[2], function (error, result) {
next[3](error, result);
if (queue.length > 0) {
checkQueue();
} else {
safe = true;
}
});
}
return function (arg1, arg2, arg3, callback) {
queue.push(arguments);
if (safe) {
checkQueue();
}
};
} | javascript | function safe3(fn) {
var queue = Queue.new();
var safe = true;
function checkQueue() {
var next = queue.shift();
safe = false;
fn(next[0], next[1], next[2], function (error, result) {
next[3](error, result);
if (queue.length > 0) {
checkQueue();
} else {
safe = true;
}
});
}
return function (arg1, arg2, arg3, callback) {
queue.push(arguments);
if (safe) {
checkQueue();
}
};
} | [
"function",
"safe3",
"(",
"fn",
")",
"{",
"var",
"queue",
"=",
"Queue",
".",
"new",
"(",
")",
";",
"var",
"safe",
"=",
"true",
";",
"function",
"checkQueue",
"(",
")",
"{",
"var",
"next",
"=",
"queue",
".",
"shift",
"(",
")",
";",
"safe",
"=",
"false",
";",
"fn",
"(",
"next",
"[",
"0",
"]",
",",
"next",
"[",
"1",
"]",
",",
"next",
"[",
"2",
"]",
",",
"function",
"(",
"error",
",",
"result",
")",
"{",
"next",
"[",
"3",
"]",
"(",
"error",
",",
"result",
")",
";",
"if",
"(",
"queue",
".",
"length",
">",
"0",
")",
"{",
"checkQueue",
"(",
")",
";",
"}",
"else",
"{",
"safe",
"=",
"true",
";",
"}",
"}",
")",
";",
"}",
"return",
"function",
"(",
"arg1",
",",
"arg2",
",",
"arg3",
",",
"callback",
")",
"{",
"queue",
".",
"push",
"(",
"arguments",
")",
";",
"if",
"(",
"safe",
")",
"{",
"checkQueue",
"(",
")",
";",
"}",
"}",
";",
"}"
] | Makes an async function that takes 3 arguments only execute one at a time. | [
"Makes",
"an",
"async",
"function",
"that",
"takes",
"3",
"arguments",
"only",
"execute",
"one",
"at",
"a",
"time",
"."
] | c5e6a8a2be364e9294bca0f9caf4d46fa5e3c6b1 | https://github.com/creationix/nstore/blob/c5e6a8a2be364e9294bca0f9caf4d46fa5e3c6b1/lib/file.js#L57-L78 |
21,529 | codemix/htmling | lib/optimiser.js | removeNestedBlocks | function removeNestedBlocks (ast) {
var tagged;
while((tagged = findNestedBlocks(ast)).length) {
fast.forEach(tagged, function (item) {
var node = item[0],
parent = item[1],
index = parent.body.indexOf(node);
fast.apply(Array.prototype.splice, parent.body, fast.concat([index, 1], node.body));
});
}
return ast;
} | javascript | function removeNestedBlocks (ast) {
var tagged;
while((tagged = findNestedBlocks(ast)).length) {
fast.forEach(tagged, function (item) {
var node = item[0],
parent = item[1],
index = parent.body.indexOf(node);
fast.apply(Array.prototype.splice, parent.body, fast.concat([index, 1], node.body));
});
}
return ast;
} | [
"function",
"removeNestedBlocks",
"(",
"ast",
")",
"{",
"var",
"tagged",
";",
"while",
"(",
"(",
"tagged",
"=",
"findNestedBlocks",
"(",
"ast",
")",
")",
".",
"length",
")",
"{",
"fast",
".",
"forEach",
"(",
"tagged",
",",
"function",
"(",
"item",
")",
"{",
"var",
"node",
"=",
"item",
"[",
"0",
"]",
",",
"parent",
"=",
"item",
"[",
"1",
"]",
",",
"index",
"=",
"parent",
".",
"body",
".",
"indexOf",
"(",
"node",
")",
";",
"fast",
".",
"apply",
"(",
"Array",
".",
"prototype",
".",
"splice",
",",
"parent",
".",
"body",
",",
"fast",
".",
"concat",
"(",
"[",
"index",
",",
"1",
"]",
",",
"node",
".",
"body",
")",
")",
";",
"}",
")",
";",
"}",
"return",
"ast",
";",
"}"
] | Remove pointless nested BlockStatements that are caused by the compilation process. | [
"Remove",
"pointless",
"nested",
"BlockStatements",
"that",
"are",
"caused",
"by",
"the",
"compilation",
"process",
"."
] | d1448b975f8b595a49aa5f8ea7006d48b7755b4c | https://github.com/codemix/htmling/blob/d1448b975f8b595a49aa5f8ea7006d48b7755b4c/lib/optimiser.js#L28-L39 |
21,530 | codemix/htmling | lib/optimiser.js | findNestedBlocks | function findNestedBlocks (ast) {
var tagged = [];
traverse.traverse(ast, {
enter: function (node, parent) {
if (node.type === 'BlockStatement' && parent && parent.type === 'BlockStatement') {
tagged.push([node, parent]);
}
}
});
return tagged;
} | javascript | function findNestedBlocks (ast) {
var tagged = [];
traverse.traverse(ast, {
enter: function (node, parent) {
if (node.type === 'BlockStatement' && parent && parent.type === 'BlockStatement') {
tagged.push([node, parent]);
}
}
});
return tagged;
} | [
"function",
"findNestedBlocks",
"(",
"ast",
")",
"{",
"var",
"tagged",
"=",
"[",
"]",
";",
"traverse",
".",
"traverse",
"(",
"ast",
",",
"{",
"enter",
":",
"function",
"(",
"node",
",",
"parent",
")",
"{",
"if",
"(",
"node",
".",
"type",
"===",
"'BlockStatement'",
"&&",
"parent",
"&&",
"parent",
".",
"type",
"===",
"'BlockStatement'",
")",
"{",
"tagged",
".",
"push",
"(",
"[",
"node",
",",
"parent",
"]",
")",
";",
"}",
"}",
"}",
")",
";",
"return",
"tagged",
";",
"}"
] | Find BlockStatements which are direct children of BlockStatements. | [
"Find",
"BlockStatements",
"which",
"are",
"direct",
"children",
"of",
"BlockStatements",
"."
] | d1448b975f8b595a49aa5f8ea7006d48b7755b4c | https://github.com/codemix/htmling/blob/d1448b975f8b595a49aa5f8ea7006d48b7755b4c/lib/optimiser.js#L44-L54 |
21,531 | codemix/htmling | lib/optimiser.js | findHoistableFunctionDeclarations | function findHoistableFunctionDeclarations (ast) {
var tagged = [];
traverse.traverse(ast, {
enter: function (node, parent) {
if (node.type === 'FunctionDeclaration' && ~node.id.name.indexOf('$')) {
tagged.push([node, parent]);
}
}
});
return tagged;
} | javascript | function findHoistableFunctionDeclarations (ast) {
var tagged = [];
traverse.traverse(ast, {
enter: function (node, parent) {
if (node.type === 'FunctionDeclaration' && ~node.id.name.indexOf('$')) {
tagged.push([node, parent]);
}
}
});
return tagged;
} | [
"function",
"findHoistableFunctionDeclarations",
"(",
"ast",
")",
"{",
"var",
"tagged",
"=",
"[",
"]",
";",
"traverse",
".",
"traverse",
"(",
"ast",
",",
"{",
"enter",
":",
"function",
"(",
"node",
",",
"parent",
")",
"{",
"if",
"(",
"node",
".",
"type",
"===",
"'FunctionDeclaration'",
"&&",
"~",
"node",
".",
"id",
".",
"name",
".",
"indexOf",
"(",
"'$'",
")",
")",
"{",
"tagged",
".",
"push",
"(",
"[",
"node",
",",
"parent",
"]",
")",
";",
"}",
"}",
"}",
")",
";",
"return",
"tagged",
";",
"}"
] | Find function declarations which can be hoisted, | [
"Find",
"function",
"declarations",
"which",
"can",
"be",
"hoisted"
] | d1448b975f8b595a49aa5f8ea7006d48b7755b4c | https://github.com/codemix/htmling/blob/d1448b975f8b595a49aa5f8ea7006d48b7755b4c/lib/optimiser.js#L74-L85 |
21,532 | codemix/htmling | lib/optimiser.js | combineContiguousOutputStatements | function combineContiguousOutputStatements (ast) {
traverse.traverse(ast, {
enter: function (node, parent) {
if (node.type !== 'BlockStatement') {
return;
}
var prev = false;
node.body = fast.reduce(node.body, function (body, statement) {
if (
!body.length ||
statement.type !== 'ExpressionStatement' ||
statement.expression.type !== 'AssignmentExpression' ||
statement.expression.operator !== '+=' ||
statement.expression.left.type !== 'Identifier' ||
statement.expression.left.name !== 'html'
) {
prev = false;
body.push(statement);
return body;
}
else if (!prev) {
prev = statement;
body.push(statement);
return body;
}
prev.expression.right = {
type: 'BinaryExpression',
operator: '+',
left: prev.expression.right,
right: statement.expression.right
};
return body;
}, []);
}
});
return ast;
} | javascript | function combineContiguousOutputStatements (ast) {
traverse.traverse(ast, {
enter: function (node, parent) {
if (node.type !== 'BlockStatement') {
return;
}
var prev = false;
node.body = fast.reduce(node.body, function (body, statement) {
if (
!body.length ||
statement.type !== 'ExpressionStatement' ||
statement.expression.type !== 'AssignmentExpression' ||
statement.expression.operator !== '+=' ||
statement.expression.left.type !== 'Identifier' ||
statement.expression.left.name !== 'html'
) {
prev = false;
body.push(statement);
return body;
}
else if (!prev) {
prev = statement;
body.push(statement);
return body;
}
prev.expression.right = {
type: 'BinaryExpression',
operator: '+',
left: prev.expression.right,
right: statement.expression.right
};
return body;
}, []);
}
});
return ast;
} | [
"function",
"combineContiguousOutputStatements",
"(",
"ast",
")",
"{",
"traverse",
".",
"traverse",
"(",
"ast",
",",
"{",
"enter",
":",
"function",
"(",
"node",
",",
"parent",
")",
"{",
"if",
"(",
"node",
".",
"type",
"!==",
"'BlockStatement'",
")",
"{",
"return",
";",
"}",
"var",
"prev",
"=",
"false",
";",
"node",
".",
"body",
"=",
"fast",
".",
"reduce",
"(",
"node",
".",
"body",
",",
"function",
"(",
"body",
",",
"statement",
")",
"{",
"if",
"(",
"!",
"body",
".",
"length",
"||",
"statement",
".",
"type",
"!==",
"'ExpressionStatement'",
"||",
"statement",
".",
"expression",
".",
"type",
"!==",
"'AssignmentExpression'",
"||",
"statement",
".",
"expression",
".",
"operator",
"!==",
"'+='",
"||",
"statement",
".",
"expression",
".",
"left",
".",
"type",
"!==",
"'Identifier'",
"||",
"statement",
".",
"expression",
".",
"left",
".",
"name",
"!==",
"'html'",
")",
"{",
"prev",
"=",
"false",
";",
"body",
".",
"push",
"(",
"statement",
")",
";",
"return",
"body",
";",
"}",
"else",
"if",
"(",
"!",
"prev",
")",
"{",
"prev",
"=",
"statement",
";",
"body",
".",
"push",
"(",
"statement",
")",
";",
"return",
"body",
";",
"}",
"prev",
".",
"expression",
".",
"right",
"=",
"{",
"type",
":",
"'BinaryExpression'",
",",
"operator",
":",
"'+'",
",",
"left",
":",
"prev",
".",
"expression",
".",
"right",
",",
"right",
":",
"statement",
".",
"expression",
".",
"right",
"}",
";",
"return",
"body",
";",
"}",
",",
"[",
"]",
")",
";",
"}",
"}",
")",
";",
"return",
"ast",
";",
"}"
] | Turn sequential OutputStatements into one big one. | [
"Turn",
"sequential",
"OutputStatements",
"into",
"one",
"big",
"one",
"."
] | d1448b975f8b595a49aa5f8ea7006d48b7755b4c | https://github.com/codemix/htmling/blob/d1448b975f8b595a49aa5f8ea7006d48b7755b4c/lib/optimiser.js#L132-L169 |
21,533 | codemix/htmling | lib/optimiser.js | removeUnusedAssignmentExpressions | function removeUnusedAssignmentExpressions (ast) {
var unused = findUnusedAssignmentExpressions(ast);
traverse.traverse(ast, {
enter: function (node, parent) {
if (node.type !== 'BlockStatement') {
return;
}
node.body = fast.filter(node.body, function (item) {
return !~fast.indexOf(unused, item);
});
}
});
return ast;
} | javascript | function removeUnusedAssignmentExpressions (ast) {
var unused = findUnusedAssignmentExpressions(ast);
traverse.traverse(ast, {
enter: function (node, parent) {
if (node.type !== 'BlockStatement') {
return;
}
node.body = fast.filter(node.body, function (item) {
return !~fast.indexOf(unused, item);
});
}
});
return ast;
} | [
"function",
"removeUnusedAssignmentExpressions",
"(",
"ast",
")",
"{",
"var",
"unused",
"=",
"findUnusedAssignmentExpressions",
"(",
"ast",
")",
";",
"traverse",
".",
"traverse",
"(",
"ast",
",",
"{",
"enter",
":",
"function",
"(",
"node",
",",
"parent",
")",
"{",
"if",
"(",
"node",
".",
"type",
"!==",
"'BlockStatement'",
")",
"{",
"return",
";",
"}",
"node",
".",
"body",
"=",
"fast",
".",
"filter",
"(",
"node",
".",
"body",
",",
"function",
"(",
"item",
")",
"{",
"return",
"!",
"~",
"fast",
".",
"indexOf",
"(",
"unused",
",",
"item",
")",
";",
"}",
")",
";",
"}",
"}",
")",
";",
"return",
"ast",
";",
"}"
] | If the result of an AssignmentExpression is not used, remove the
expression entirely. | [
"If",
"the",
"result",
"of",
"an",
"AssignmentExpression",
"is",
"not",
"used",
"remove",
"the",
"expression",
"entirely",
"."
] | d1448b975f8b595a49aa5f8ea7006d48b7755b4c | https://github.com/codemix/htmling/blob/d1448b975f8b595a49aa5f8ea7006d48b7755b4c/lib/optimiser.js#L231-L244 |
21,534 | codemix/htmling | lib/optimiser.js | removeUnusedVariableDeclarators | function removeUnusedVariableDeclarators (ast) {
var unused = findUnusedVariableDeclarators(ast);
traverse.traverse(ast, {
enter: function (node, parent) {
if (node.type !== 'VariableDeclaration') {
return;
}
node.declarations = fast.filter(node.declarations, function (item) {
return !~fast.indexOf(unused, item);
});
}
});
return ast;
} | javascript | function removeUnusedVariableDeclarators (ast) {
var unused = findUnusedVariableDeclarators(ast);
traverse.traverse(ast, {
enter: function (node, parent) {
if (node.type !== 'VariableDeclaration') {
return;
}
node.declarations = fast.filter(node.declarations, function (item) {
return !~fast.indexOf(unused, item);
});
}
});
return ast;
} | [
"function",
"removeUnusedVariableDeclarators",
"(",
"ast",
")",
"{",
"var",
"unused",
"=",
"findUnusedVariableDeclarators",
"(",
"ast",
")",
";",
"traverse",
".",
"traverse",
"(",
"ast",
",",
"{",
"enter",
":",
"function",
"(",
"node",
",",
"parent",
")",
"{",
"if",
"(",
"node",
".",
"type",
"!==",
"'VariableDeclaration'",
")",
"{",
"return",
";",
"}",
"node",
".",
"declarations",
"=",
"fast",
".",
"filter",
"(",
"node",
".",
"declarations",
",",
"function",
"(",
"item",
")",
"{",
"return",
"!",
"~",
"fast",
".",
"indexOf",
"(",
"unused",
",",
"item",
")",
";",
"}",
")",
";",
"}",
"}",
")",
";",
"return",
"ast",
";",
"}"
] | If a variable is declared, but not used, remove it. | [
"If",
"a",
"variable",
"is",
"declared",
"but",
"not",
"used",
"remove",
"it",
"."
] | d1448b975f8b595a49aa5f8ea7006d48b7755b4c | https://github.com/codemix/htmling/blob/d1448b975f8b595a49aa5f8ea7006d48b7755b4c/lib/optimiser.js#L277-L290 |
21,535 | codemix/htmling | lib/optimiser.js | findUnusedVariableDeclarators | function findUnusedVariableDeclarators (ast) {
var unused = [];
traverse.traverse(ast, {
enter: function (node, parent) {
var scope, refs;
if (node.type === 'VariableDeclarator' && (scope = findScope(ast, node))) {
refs = fast.filter(findVariableReferences(scope, node.id), function (item) {
return item !== node.id;
});
if (!refs.length) {
unused.push(node);
}
}
}
});
return unused;
} | javascript | function findUnusedVariableDeclarators (ast) {
var unused = [];
traverse.traverse(ast, {
enter: function (node, parent) {
var scope, refs;
if (node.type === 'VariableDeclarator' && (scope = findScope(ast, node))) {
refs = fast.filter(findVariableReferences(scope, node.id), function (item) {
return item !== node.id;
});
if (!refs.length) {
unused.push(node);
}
}
}
});
return unused;
} | [
"function",
"findUnusedVariableDeclarators",
"(",
"ast",
")",
"{",
"var",
"unused",
"=",
"[",
"]",
";",
"traverse",
".",
"traverse",
"(",
"ast",
",",
"{",
"enter",
":",
"function",
"(",
"node",
",",
"parent",
")",
"{",
"var",
"scope",
",",
"refs",
";",
"if",
"(",
"node",
".",
"type",
"===",
"'VariableDeclarator'",
"&&",
"(",
"scope",
"=",
"findScope",
"(",
"ast",
",",
"node",
")",
")",
")",
"{",
"refs",
"=",
"fast",
".",
"filter",
"(",
"findVariableReferences",
"(",
"scope",
",",
"node",
".",
"id",
")",
",",
"function",
"(",
"item",
")",
"{",
"return",
"item",
"!==",
"node",
".",
"id",
";",
"}",
")",
";",
"if",
"(",
"!",
"refs",
".",
"length",
")",
"{",
"unused",
".",
"push",
"(",
"node",
")",
";",
"}",
"}",
"}",
"}",
")",
";",
"return",
"unused",
";",
"}"
] | Find declarators of unused variables. | [
"Find",
"declarators",
"of",
"unused",
"variables",
"."
] | d1448b975f8b595a49aa5f8ea7006d48b7755b4c | https://github.com/codemix/htmling/blob/d1448b975f8b595a49aa5f8ea7006d48b7755b4c/lib/optimiser.js#L295-L312 |
21,536 | codemix/htmling | lib/optimiser.js | findVariableReferences | function findVariableReferences (ast, identifier, skip) {
var references = [];
traverse.traverse(ast, {
enter: function (node, parent) {
if (node === skip) {
this.skip();
}
else if (
node.type === 'Identifier' &&
node.name === identifier.name &&
(parent.type !== 'MemberExpression' || parent.left !== node)
) {
references.push(node);
}
}
});
return references;
} | javascript | function findVariableReferences (ast, identifier, skip) {
var references = [];
traverse.traverse(ast, {
enter: function (node, parent) {
if (node === skip) {
this.skip();
}
else if (
node.type === 'Identifier' &&
node.name === identifier.name &&
(parent.type !== 'MemberExpression' || parent.left !== node)
) {
references.push(node);
}
}
});
return references;
} | [
"function",
"findVariableReferences",
"(",
"ast",
",",
"identifier",
",",
"skip",
")",
"{",
"var",
"references",
"=",
"[",
"]",
";",
"traverse",
".",
"traverse",
"(",
"ast",
",",
"{",
"enter",
":",
"function",
"(",
"node",
",",
"parent",
")",
"{",
"if",
"(",
"node",
"===",
"skip",
")",
"{",
"this",
".",
"skip",
"(",
")",
";",
"}",
"else",
"if",
"(",
"node",
".",
"type",
"===",
"'Identifier'",
"&&",
"node",
".",
"name",
"===",
"identifier",
".",
"name",
"&&",
"(",
"parent",
".",
"type",
"!==",
"'MemberExpression'",
"||",
"parent",
".",
"left",
"!==",
"node",
")",
")",
"{",
"references",
".",
"push",
"(",
"node",
")",
";",
"}",
"}",
"}",
")",
";",
"return",
"references",
";",
"}"
] | Find references to a given identifier | [
"Find",
"references",
"to",
"a",
"given",
"identifier"
] | d1448b975f8b595a49aa5f8ea7006d48b7755b4c | https://github.com/codemix/htmling/blob/d1448b975f8b595a49aa5f8ea7006d48b7755b4c/lib/optimiser.js#L317-L334 |
21,537 | codemix/htmling | lib/optimiser.js | findScope | function findScope (ast, item) {
var scopes = [],
found = false;
traverse.traverse(ast, {
enter: function (node, parent) {
if (node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression') {
scopes.push(node);
}
else if (node === item) {
found = scopes[scopes.length - 1];
this.break();
}
},
leave: function (node, parent) {
if (node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression') {
scopes.pop();
}
}
});
return found ? found.body : false;
} | javascript | function findScope (ast, item) {
var scopes = [],
found = false;
traverse.traverse(ast, {
enter: function (node, parent) {
if (node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression') {
scopes.push(node);
}
else if (node === item) {
found = scopes[scopes.length - 1];
this.break();
}
},
leave: function (node, parent) {
if (node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression') {
scopes.pop();
}
}
});
return found ? found.body : false;
} | [
"function",
"findScope",
"(",
"ast",
",",
"item",
")",
"{",
"var",
"scopes",
"=",
"[",
"]",
",",
"found",
"=",
"false",
";",
"traverse",
".",
"traverse",
"(",
"ast",
",",
"{",
"enter",
":",
"function",
"(",
"node",
",",
"parent",
")",
"{",
"if",
"(",
"node",
".",
"type",
"===",
"'FunctionDeclaration'",
"||",
"node",
".",
"type",
"===",
"'FunctionExpression'",
")",
"{",
"scopes",
".",
"push",
"(",
"node",
")",
";",
"}",
"else",
"if",
"(",
"node",
"===",
"item",
")",
"{",
"found",
"=",
"scopes",
"[",
"scopes",
".",
"length",
"-",
"1",
"]",
";",
"this",
".",
"break",
"(",
")",
";",
"}",
"}",
",",
"leave",
":",
"function",
"(",
"node",
",",
"parent",
")",
"{",
"if",
"(",
"node",
".",
"type",
"===",
"'FunctionDeclaration'",
"||",
"node",
".",
"type",
"===",
"'FunctionExpression'",
")",
"{",
"scopes",
".",
"pop",
"(",
")",
";",
"}",
"}",
"}",
")",
";",
"return",
"found",
"?",
"found",
".",
"body",
":",
"false",
";",
"}"
] | Find the scope for an item in the AST. | [
"Find",
"the",
"scope",
"for",
"an",
"item",
"in",
"the",
"AST",
"."
] | d1448b975f8b595a49aa5f8ea7006d48b7755b4c | https://github.com/codemix/htmling/blob/d1448b975f8b595a49aa5f8ea7006d48b7755b4c/lib/optimiser.js#L339-L359 |
21,538 | Dan503/mq-scss | gulp/tasks/release.js | getBumpType | function getBumpType(){
if (args.patch && args.minor || args.minor && args.major || args.major && args.patch) {
throw '\nYou can not use more than one version bump type at a time\n';
}
if (args.patch){
return 'patch';
} else if (args.minor){
return 'minor';
} else if (args.major) {
return 'major';
} else {
return false;
}
} | javascript | function getBumpType(){
if (args.patch && args.minor || args.minor && args.major || args.major && args.patch) {
throw '\nYou can not use more than one version bump type at a time\n';
}
if (args.patch){
return 'patch';
} else if (args.minor){
return 'minor';
} else if (args.major) {
return 'major';
} else {
return false;
}
} | [
"function",
"getBumpType",
"(",
")",
"{",
"if",
"(",
"args",
".",
"patch",
"&&",
"args",
".",
"minor",
"||",
"args",
".",
"minor",
"&&",
"args",
".",
"major",
"||",
"args",
".",
"major",
"&&",
"args",
".",
"patch",
")",
"{",
"throw",
"'\\nYou can not use more than one version bump type at a time\\n'",
";",
"}",
"if",
"(",
"args",
".",
"patch",
")",
"{",
"return",
"'patch'",
";",
"}",
"else",
"if",
"(",
"args",
".",
"minor",
")",
"{",
"return",
"'minor'",
";",
"}",
"else",
"if",
"(",
"args",
".",
"major",
")",
"{",
"return",
"'major'",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | SIMPLE VERSION BUMPING
Bumping version number and tagging the repository with it.
Please read http://semver.org/
You can use the commands
gulp bump --patch # makes v0.1.0 → v0.1.1
gulp bump --minor # makes v0.1.1 → v0.2.0
gulp bump --major # makes v0.2.1 → v1.0.0
To bump the version numbers accordingly after you did a patch,
introduced a feature or made a backwards-incompatible change.
FULL GIT RELEASES
You can use the commands
gulp release # no version number change
gulp release --patch # makes v0.1.0 → v0.1.1
gulp release --minor # makes v0.1.1 → v0.2.0
gulp release --major # makes v0.2.1 → v1.0.0
To do a full git flow release process automatically.
All changes must be committed to git before running this task | [
"SIMPLE",
"VERSION",
"BUMPING"
] | 4676281b290e1fb7e2d524cc8f79f9acf69bc4cf | https://github.com/Dan503/mq-scss/blob/4676281b290e1fb7e2d524cc8f79f9acf69bc4cf/gulp/tasks/release.js#L47-L61 |
21,539 | Dan503/mq-scss | gulp/tasks/release.js | bumpVersion | function bumpVersion(importance){
return function bump_version (done){
if (!importance) throw new Error(`
An importance must be specified for a version bump to occur.
Valid importances: "--patch", "--minor", "--major"
`);
// get all the files to bump version in
return gulp.src('./package.json')
// bump the version number in those files
.pipe(bump({type: importance}))
// save it back to filesystem
.pipe(gulp.dest('./'))
//commit the changed version number
.pipe(git.commit(`${importance} version bump`))
}
} | javascript | function bumpVersion(importance){
return function bump_version (done){
if (!importance) throw new Error(`
An importance must be specified for a version bump to occur.
Valid importances: "--patch", "--minor", "--major"
`);
// get all the files to bump version in
return gulp.src('./package.json')
// bump the version number in those files
.pipe(bump({type: importance}))
// save it back to filesystem
.pipe(gulp.dest('./'))
//commit the changed version number
.pipe(git.commit(`${importance} version bump`))
}
} | [
"function",
"bumpVersion",
"(",
"importance",
")",
"{",
"return",
"function",
"bump_version",
"(",
"done",
")",
"{",
"if",
"(",
"!",
"importance",
")",
"throw",
"new",
"Error",
"(",
"`",
"`",
")",
";",
"// get all the files to bump version in",
"return",
"gulp",
".",
"src",
"(",
"'./package.json'",
")",
"// bump the version number in those files",
".",
"pipe",
"(",
"bump",
"(",
"{",
"type",
":",
"importance",
"}",
")",
")",
"// save it back to filesystem",
".",
"pipe",
"(",
"gulp",
".",
"dest",
"(",
"'./'",
")",
")",
"//commit the changed version number",
".",
"pipe",
"(",
"git",
".",
"commit",
"(",
"`",
"${",
"importance",
"}",
"`",
")",
")",
"}",
"}"
] | Bump up the current version number | [
"Bump",
"up",
"the",
"current",
"version",
"number"
] | 4676281b290e1fb7e2d524cc8f79f9acf69bc4cf | https://github.com/Dan503/mq-scss/blob/4676281b290e1fb7e2d524cc8f79f9acf69bc4cf/gulp/tasks/release.js#L68-L83 |
21,540 | Dan503/mq-scss | gulp/tasks/release.js | tag_version | function tag_version(){
return new Promise((resolve, reject)=>{
const pkg = reload('../../package.json');
const tag = `v${pkg.version}`;
gutil.log('Tagging as: '+gutil.colors.cyan(tag));
git.tag(tag, `Tagging as ${tag}`, (err)=>{
checkError(err);
resolve(tag);
})
})
} | javascript | function tag_version(){
return new Promise((resolve, reject)=>{
const pkg = reload('../../package.json');
const tag = `v${pkg.version}`;
gutil.log('Tagging as: '+gutil.colors.cyan(tag));
git.tag(tag, `Tagging as ${tag}`, (err)=>{
checkError(err);
resolve(tag);
})
})
} | [
"function",
"tag_version",
"(",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"const",
"pkg",
"=",
"reload",
"(",
"'../../package.json'",
")",
";",
"const",
"tag",
"=",
"`",
"${",
"pkg",
".",
"version",
"}",
"`",
";",
"gutil",
".",
"log",
"(",
"'Tagging as: '",
"+",
"gutil",
".",
"colors",
".",
"cyan",
"(",
"tag",
")",
")",
";",
"git",
".",
"tag",
"(",
"tag",
",",
"`",
"${",
"tag",
"}",
"`",
",",
"(",
"err",
")",
"=>",
"{",
"checkError",
"(",
"err",
")",
";",
"resolve",
"(",
"tag",
")",
";",
"}",
")",
"}",
")",
"}"
] | Tag current version number in git | [
"Tag",
"current",
"version",
"number",
"in",
"git"
] | 4676281b290e1fb7e2d524cc8f79f9acf69bc4cf | https://github.com/Dan503/mq-scss/blob/4676281b290e1fb7e2d524cc8f79f9acf69bc4cf/gulp/tasks/release.js#L86-L96 |
21,541 | Dan503/mq-scss | gulp/tasks/release.js | release | function release(importance) {
const version_bump = done => importance !== false ? gulp.series(bumpVersion(importance))(done) : done();
return done => gulp.series(
() => check_out('develop'),
version_bump,
finish_release
)(done);
} | javascript | function release(importance) {
const version_bump = done => importance !== false ? gulp.series(bumpVersion(importance))(done) : done();
return done => gulp.series(
() => check_out('develop'),
version_bump,
finish_release
)(done);
} | [
"function",
"release",
"(",
"importance",
")",
"{",
"const",
"version_bump",
"=",
"done",
"=>",
"importance",
"!==",
"false",
"?",
"gulp",
".",
"series",
"(",
"bumpVersion",
"(",
"importance",
")",
")",
"(",
"done",
")",
":",
"done",
"(",
")",
";",
"return",
"done",
"=>",
"gulp",
".",
"series",
"(",
"(",
")",
"=>",
"check_out",
"(",
"'develop'",
")",
",",
"version_bump",
",",
"finish_release",
")",
"(",
"done",
")",
";",
"}"
] | Do a full Git Flow release which can optionally include a version bump | [
"Do",
"a",
"full",
"Git",
"Flow",
"release",
"which",
"can",
"optionally",
"include",
"a",
"version",
"bump"
] | 4676281b290e1fb7e2d524cc8f79f9acf69bc4cf | https://github.com/Dan503/mq-scss/blob/4676281b290e1fb7e2d524cc8f79f9acf69bc4cf/gulp/tasks/release.js#L129-L137 |
21,542 | staruml/metadata-json | core/MetaModelManager.js | validateMetaType | function validateMetaType(name, metaType) {
assert(_.isObject(metaType), ERR_METATYPE_OBJECT, { name: name });
assert(metaType.name, ERR_REQUIRE_FIELD, { metaType: metaType, field: "name" });
assert(metaType.kind === "enum" || metaType.kind === "class", ERR_METATYPE_KIND, { metaType: metaType });
// Enum MetaType
if (metaType.kind === "enum") {
var lits = metaType.literals;
assert(Array.isArray(lits) && lits.length > 0, ERR_ENUM_HAS_LITERALS, { metaType: metaType });
// Check duplicated literal
_.each(lits, function (lit1) {
var len = _.filter(lits, function (lit2) { return lit2 === lit1; }).length;
assert(len === 1, ERR_DUPLICATED_LITERAL, { metaType: metaType, literal: lit1 });
});
}
// Class MetaType
if (metaType.kind === "class") {
// Check .super
if (metaType.super) {
assert(metaType.super && _global.meta[metaType.super], ERR_TYPE_NOT_FOUND, { metaType: metaType, type: metaType.super, field: "super" });
}
// Check Attributes
if (metaType.attributes) {
assert(Array.isArray(metaType.attributes), ERR_FIELD_TYPE, { metaType: metaType, field: "attributes", type: "Array" });
_.each(metaType.attributes, function (attribute) {
// check 'name'
assert(attribute.name, ERR_UNNAMED_ATTRIBUTE, { metaType: metaType });
// Check 'kind'
assert(_.contains(["prim", "enum", "var", "ref", "refs", "obj", "objs", "custom"], attribute.kind), ERR_ATTRIBUTE_KIND, { metaType: metaType, attribute: attribute });
// Check 'type'
if (attribute.kind === "prim") {
assert(_.contains(["Integer", "String", "Boolean", "Real"], attribute.type), ERR_ATTRIBUTE_PRIM_TYPE, { metaType: metaType, attribute: attribute });
} else if (attribute.kind !== "custom") {
assert(_global.meta[attribute.type], ERR_TYPE_NOT_FOUND, { metaType: metaType, type: attribute.type, field: attribute.name + ".type" });
}
// Check duplicated attribute in all inherited attributes
var len = _.filter(getMetaAttributes(metaType.name), function (attr) { return attr.name === attribute.name; }).length;
assert(len === 1, ERR_DUPLICATED_ATTRIBUTE, { metaType: metaType, attribute: attribute });
});
}
}
} | javascript | function validateMetaType(name, metaType) {
assert(_.isObject(metaType), ERR_METATYPE_OBJECT, { name: name });
assert(metaType.name, ERR_REQUIRE_FIELD, { metaType: metaType, field: "name" });
assert(metaType.kind === "enum" || metaType.kind === "class", ERR_METATYPE_KIND, { metaType: metaType });
// Enum MetaType
if (metaType.kind === "enum") {
var lits = metaType.literals;
assert(Array.isArray(lits) && lits.length > 0, ERR_ENUM_HAS_LITERALS, { metaType: metaType });
// Check duplicated literal
_.each(lits, function (lit1) {
var len = _.filter(lits, function (lit2) { return lit2 === lit1; }).length;
assert(len === 1, ERR_DUPLICATED_LITERAL, { metaType: metaType, literal: lit1 });
});
}
// Class MetaType
if (metaType.kind === "class") {
// Check .super
if (metaType.super) {
assert(metaType.super && _global.meta[metaType.super], ERR_TYPE_NOT_FOUND, { metaType: metaType, type: metaType.super, field: "super" });
}
// Check Attributes
if (metaType.attributes) {
assert(Array.isArray(metaType.attributes), ERR_FIELD_TYPE, { metaType: metaType, field: "attributes", type: "Array" });
_.each(metaType.attributes, function (attribute) {
// check 'name'
assert(attribute.name, ERR_UNNAMED_ATTRIBUTE, { metaType: metaType });
// Check 'kind'
assert(_.contains(["prim", "enum", "var", "ref", "refs", "obj", "objs", "custom"], attribute.kind), ERR_ATTRIBUTE_KIND, { metaType: metaType, attribute: attribute });
// Check 'type'
if (attribute.kind === "prim") {
assert(_.contains(["Integer", "String", "Boolean", "Real"], attribute.type), ERR_ATTRIBUTE_PRIM_TYPE, { metaType: metaType, attribute: attribute });
} else if (attribute.kind !== "custom") {
assert(_global.meta[attribute.type], ERR_TYPE_NOT_FOUND, { metaType: metaType, type: attribute.type, field: attribute.name + ".type" });
}
// Check duplicated attribute in all inherited attributes
var len = _.filter(getMetaAttributes(metaType.name), function (attr) { return attr.name === attribute.name; }).length;
assert(len === 1, ERR_DUPLICATED_ATTRIBUTE, { metaType: metaType, attribute: attribute });
});
}
}
} | [
"function",
"validateMetaType",
"(",
"name",
",",
"metaType",
")",
"{",
"assert",
"(",
"_",
".",
"isObject",
"(",
"metaType",
")",
",",
"ERR_METATYPE_OBJECT",
",",
"{",
"name",
":",
"name",
"}",
")",
";",
"assert",
"(",
"metaType",
".",
"name",
",",
"ERR_REQUIRE_FIELD",
",",
"{",
"metaType",
":",
"metaType",
",",
"field",
":",
"\"name\"",
"}",
")",
";",
"assert",
"(",
"metaType",
".",
"kind",
"===",
"\"enum\"",
"||",
"metaType",
".",
"kind",
"===",
"\"class\"",
",",
"ERR_METATYPE_KIND",
",",
"{",
"metaType",
":",
"metaType",
"}",
")",
";",
"// Enum MetaType",
"if",
"(",
"metaType",
".",
"kind",
"===",
"\"enum\"",
")",
"{",
"var",
"lits",
"=",
"metaType",
".",
"literals",
";",
"assert",
"(",
"Array",
".",
"isArray",
"(",
"lits",
")",
"&&",
"lits",
".",
"length",
">",
"0",
",",
"ERR_ENUM_HAS_LITERALS",
",",
"{",
"metaType",
":",
"metaType",
"}",
")",
";",
"// Check duplicated literal",
"_",
".",
"each",
"(",
"lits",
",",
"function",
"(",
"lit1",
")",
"{",
"var",
"len",
"=",
"_",
".",
"filter",
"(",
"lits",
",",
"function",
"(",
"lit2",
")",
"{",
"return",
"lit2",
"===",
"lit1",
";",
"}",
")",
".",
"length",
";",
"assert",
"(",
"len",
"===",
"1",
",",
"ERR_DUPLICATED_LITERAL",
",",
"{",
"metaType",
":",
"metaType",
",",
"literal",
":",
"lit1",
"}",
")",
";",
"}",
")",
";",
"}",
"// Class MetaType",
"if",
"(",
"metaType",
".",
"kind",
"===",
"\"class\"",
")",
"{",
"// Check .super",
"if",
"(",
"metaType",
".",
"super",
")",
"{",
"assert",
"(",
"metaType",
".",
"super",
"&&",
"_global",
".",
"meta",
"[",
"metaType",
".",
"super",
"]",
",",
"ERR_TYPE_NOT_FOUND",
",",
"{",
"metaType",
":",
"metaType",
",",
"type",
":",
"metaType",
".",
"super",
",",
"field",
":",
"\"super\"",
"}",
")",
";",
"}",
"// Check Attributes",
"if",
"(",
"metaType",
".",
"attributes",
")",
"{",
"assert",
"(",
"Array",
".",
"isArray",
"(",
"metaType",
".",
"attributes",
")",
",",
"ERR_FIELD_TYPE",
",",
"{",
"metaType",
":",
"metaType",
",",
"field",
":",
"\"attributes\"",
",",
"type",
":",
"\"Array\"",
"}",
")",
";",
"_",
".",
"each",
"(",
"metaType",
".",
"attributes",
",",
"function",
"(",
"attribute",
")",
"{",
"// check 'name'",
"assert",
"(",
"attribute",
".",
"name",
",",
"ERR_UNNAMED_ATTRIBUTE",
",",
"{",
"metaType",
":",
"metaType",
"}",
")",
";",
"// Check 'kind'",
"assert",
"(",
"_",
".",
"contains",
"(",
"[",
"\"prim\"",
",",
"\"enum\"",
",",
"\"var\"",
",",
"\"ref\"",
",",
"\"refs\"",
",",
"\"obj\"",
",",
"\"objs\"",
",",
"\"custom\"",
"]",
",",
"attribute",
".",
"kind",
")",
",",
"ERR_ATTRIBUTE_KIND",
",",
"{",
"metaType",
":",
"metaType",
",",
"attribute",
":",
"attribute",
"}",
")",
";",
"// Check 'type'",
"if",
"(",
"attribute",
".",
"kind",
"===",
"\"prim\"",
")",
"{",
"assert",
"(",
"_",
".",
"contains",
"(",
"[",
"\"Integer\"",
",",
"\"String\"",
",",
"\"Boolean\"",
",",
"\"Real\"",
"]",
",",
"attribute",
".",
"type",
")",
",",
"ERR_ATTRIBUTE_PRIM_TYPE",
",",
"{",
"metaType",
":",
"metaType",
",",
"attribute",
":",
"attribute",
"}",
")",
";",
"}",
"else",
"if",
"(",
"attribute",
".",
"kind",
"!==",
"\"custom\"",
")",
"{",
"assert",
"(",
"_global",
".",
"meta",
"[",
"attribute",
".",
"type",
"]",
",",
"ERR_TYPE_NOT_FOUND",
",",
"{",
"metaType",
":",
"metaType",
",",
"type",
":",
"attribute",
".",
"type",
",",
"field",
":",
"attribute",
".",
"name",
"+",
"\".type\"",
"}",
")",
";",
"}",
"// Check duplicated attribute in all inherited attributes",
"var",
"len",
"=",
"_",
".",
"filter",
"(",
"getMetaAttributes",
"(",
"metaType",
".",
"name",
")",
",",
"function",
"(",
"attr",
")",
"{",
"return",
"attr",
".",
"name",
"===",
"attribute",
".",
"name",
";",
"}",
")",
".",
"length",
";",
"assert",
"(",
"len",
"===",
"1",
",",
"ERR_DUPLICATED_ATTRIBUTE",
",",
"{",
"metaType",
":",
"metaType",
",",
"attribute",
":",
"attribute",
"}",
")",
";",
"}",
")",
";",
"}",
"}",
"}"
] | Validate MetaType Definition
@param {Object} metaType | [
"Validate",
"MetaType",
"Definition"
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/core/MetaModelManager.js#L64-L113 |
21,543 | staruml/metadata-json | core/MetaModelManager.js | register | function register(metamodel) {
var name, metaType;
// Registering MetaTypes to global.meta
for (name in metamodel) {
if (metamodel.hasOwnProperty(name)) {
metaType = metamodel[name];
metaType.name = name;
// Check duplicated MetaType
if (_global.meta[name]) {
delete metamodel[name];
console.error("[MetaModelManager] MetaType '" + name + "' is already exists.");
} else {
_global.meta[name] = metaType;
}
}
}
// Validate MetaTypes
for (name in metamodel) {
if (metamodel.hasOwnProperty(name)) {
metaType = metamodel[name];
try {
validateMetaType(name, metaType);
} catch (err) {
console.error(err);
}
}
}
} | javascript | function register(metamodel) {
var name, metaType;
// Registering MetaTypes to global.meta
for (name in metamodel) {
if (metamodel.hasOwnProperty(name)) {
metaType = metamodel[name];
metaType.name = name;
// Check duplicated MetaType
if (_global.meta[name]) {
delete metamodel[name];
console.error("[MetaModelManager] MetaType '" + name + "' is already exists.");
} else {
_global.meta[name] = metaType;
}
}
}
// Validate MetaTypes
for (name in metamodel) {
if (metamodel.hasOwnProperty(name)) {
metaType = metamodel[name];
try {
validateMetaType(name, metaType);
} catch (err) {
console.error(err);
}
}
}
} | [
"function",
"register",
"(",
"metamodel",
")",
"{",
"var",
"name",
",",
"metaType",
";",
"// Registering MetaTypes to global.meta",
"for",
"(",
"name",
"in",
"metamodel",
")",
"{",
"if",
"(",
"metamodel",
".",
"hasOwnProperty",
"(",
"name",
")",
")",
"{",
"metaType",
"=",
"metamodel",
"[",
"name",
"]",
";",
"metaType",
".",
"name",
"=",
"name",
";",
"// Check duplicated MetaType",
"if",
"(",
"_global",
".",
"meta",
"[",
"name",
"]",
")",
"{",
"delete",
"metamodel",
"[",
"name",
"]",
";",
"console",
".",
"error",
"(",
"\"[MetaModelManager] MetaType '\"",
"+",
"name",
"+",
"\"' is already exists.\"",
")",
";",
"}",
"else",
"{",
"_global",
".",
"meta",
"[",
"name",
"]",
"=",
"metaType",
";",
"}",
"}",
"}",
"// Validate MetaTypes",
"for",
"(",
"name",
"in",
"metamodel",
")",
"{",
"if",
"(",
"metamodel",
".",
"hasOwnProperty",
"(",
"name",
")",
")",
"{",
"metaType",
"=",
"metamodel",
"[",
"name",
"]",
";",
"try",
"{",
"validateMetaType",
"(",
"name",
",",
"metaType",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"err",
")",
";",
"}",
"}",
"}",
"}"
] | Register Metamodel by Object
@param {Object} metamodel | [
"Register",
"Metamodel",
"by",
"Object"
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/core/MetaModelManager.js#L119-L149 |
21,544 | staruml/metadata-json | core/MetaModelManager.js | getMetaAttributes | function getMetaAttributes(typeName) {
var metaClass = _global.meta[typeName],
attrs = [];
if (metaClass.super) {
attrs = getMetaAttributes(metaClass.super);
}
if (metaClass.attributes) {
var i, len, item;
for (i = 0, len = metaClass.attributes.length; i < len; i++) {
item = metaClass.attributes[i];
attrs.push(item);
}
}
return attrs;
} | javascript | function getMetaAttributes(typeName) {
var metaClass = _global.meta[typeName],
attrs = [];
if (metaClass.super) {
attrs = getMetaAttributes(metaClass.super);
}
if (metaClass.attributes) {
var i, len, item;
for (i = 0, len = metaClass.attributes.length; i < len; i++) {
item = metaClass.attributes[i];
attrs.push(item);
}
}
return attrs;
} | [
"function",
"getMetaAttributes",
"(",
"typeName",
")",
"{",
"var",
"metaClass",
"=",
"_global",
".",
"meta",
"[",
"typeName",
"]",
",",
"attrs",
"=",
"[",
"]",
";",
"if",
"(",
"metaClass",
".",
"super",
")",
"{",
"attrs",
"=",
"getMetaAttributes",
"(",
"metaClass",
".",
"super",
")",
";",
"}",
"if",
"(",
"metaClass",
".",
"attributes",
")",
"{",
"var",
"i",
",",
"len",
",",
"item",
";",
"for",
"(",
"i",
"=",
"0",
",",
"len",
"=",
"metaClass",
".",
"attributes",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"item",
"=",
"metaClass",
".",
"attributes",
"[",
"i",
"]",
";",
"attrs",
".",
"push",
"(",
"item",
")",
";",
"}",
"}",
"return",
"attrs",
";",
"}"
] | Return all meta-attributes
@param {string} typeName
@return {Array.<{name:string, kind:string, type:string}>} | [
"Return",
"all",
"meta",
"-",
"attributes"
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/core/MetaModelManager.js#L156-L170 |
21,545 | staruml/metadata-json | core/MetaModelManager.js | getViewTypeOf | function getViewTypeOf(typeName) {
var metaClass = _global.meta[typeName];
if (metaClass) {
return metaClass.view || null;
}
return null;
} | javascript | function getViewTypeOf(typeName) {
var metaClass = _global.meta[typeName];
if (metaClass) {
return metaClass.view || null;
}
return null;
} | [
"function",
"getViewTypeOf",
"(",
"typeName",
")",
"{",
"var",
"metaClass",
"=",
"_global",
".",
"meta",
"[",
"typeName",
"]",
";",
"if",
"(",
"metaClass",
")",
"{",
"return",
"metaClass",
".",
"view",
"||",
"null",
";",
"}",
"return",
"null",
";",
"}"
] | Return a corresponding view type of a given model type.
@param {string} typeName
@return {string} | [
"Return",
"a",
"corresponding",
"view",
"type",
"of",
"a",
"given",
"model",
"type",
"."
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/core/MetaModelManager.js#L194-L200 |
21,546 | staruml/metadata-json | core/MetaModelManager.js | getAvailableViewTypes | function getAvailableViewTypes(diagramTypeName) {
var metaClass = _global.meta[diagramTypeName],
views = [];
if (metaClass.super) {
views = getAvailableViewTypes(metaClass.super);
}
if (metaClass.views) {
var i, len, item;
for (i = 0, len = metaClass.views.length; i < len; i++) {
item = metaClass.views[i];
views.push(item);
}
}
return views;
} | javascript | function getAvailableViewTypes(diagramTypeName) {
var metaClass = _global.meta[diagramTypeName],
views = [];
if (metaClass.super) {
views = getAvailableViewTypes(metaClass.super);
}
if (metaClass.views) {
var i, len, item;
for (i = 0, len = metaClass.views.length; i < len; i++) {
item = metaClass.views[i];
views.push(item);
}
}
return views;
} | [
"function",
"getAvailableViewTypes",
"(",
"diagramTypeName",
")",
"{",
"var",
"metaClass",
"=",
"_global",
".",
"meta",
"[",
"diagramTypeName",
"]",
",",
"views",
"=",
"[",
"]",
";",
"if",
"(",
"metaClass",
".",
"super",
")",
"{",
"views",
"=",
"getAvailableViewTypes",
"(",
"metaClass",
".",
"super",
")",
";",
"}",
"if",
"(",
"metaClass",
".",
"views",
")",
"{",
"var",
"i",
",",
"len",
",",
"item",
";",
"for",
"(",
"i",
"=",
"0",
",",
"len",
"=",
"metaClass",
".",
"views",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"item",
"=",
"metaClass",
".",
"views",
"[",
"i",
"]",
";",
"views",
".",
"push",
"(",
"item",
")",
";",
"}",
"}",
"return",
"views",
";",
"}"
] | Return all available view types of a diagram type.
@param {string} diagramTypeName
@return {Array.<string}>} | [
"Return",
"all",
"available",
"view",
"types",
"of",
"a",
"diagram",
"type",
"."
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/core/MetaModelManager.js#L207-L221 |
21,547 | silexlabs/unifile | lib/unifile-dropbox.js | callAPI | function callAPI(session, path, data, subdomain = 'api', isJson = true, headers = null) {
const authorization = 'Bearer ' + session.token;
const reqOptions = {
url: `https://${subdomain}.dropboxapi.com/2${path}`,
method: 'POST',
headers: {
'Authorization': authorization,
'User-Agent': 'Unifile'
},
json: isJson,
encoding: null
};
if(data && Object.keys(data).length !== 0) reqOptions.body = data;
if(headers) {
for(const header in headers) {
reqOptions.headers[header] = headers[header];
}
}
return new Promise(function(resolve, reject) {
request(reqOptions, function(err, res, body) {
if(err) {
reject(err);
} else if(res.statusCode >= 400) {
let errorMessage = null;
// In case of users/get_current_account, Dropbox return a String with the error
// Since isJson = true, it gets parsed by request
if(Buffer.isBuffer(body)) {
try {
errorMessage = JSON.parse(body.toString()).error_summary;
} catch (e) {
errorMessage = body.toString();
}
} else {
errorMessage = (isJson ? body : JSON.parse(body)).error_summary;
}
// Dropbox only uses 409 for endpoints specific errors
let filename = null;
try {
filename = res.request.headers.hasOwnProperty('Dropbox-API-Arg') ?
JSON.parse(res.request.headers['Dropbox-API-Arg']).path
: JSON.parse(res.request.body).path;
} catch (e) {}
if(errorMessage.includes('/not_found/')) {
reject(new UnifileError(UnifileError.ENOENT, `Not Found: ${filename}`));
} else if(errorMessage.startsWith('path/conflict/')) {
reject(new UnifileError(UnifileError.EINVAL, `Creation failed due to conflict: ${filename}`));
} else if(errorMessage.startsWith('path/not_file/')) {
reject(new UnifileError(UnifileError.EINVAL, `Path is a directory: ${filename}`));
} else if(res.statusCode === 401) {
reject(new UnifileError(UnifileError.EACCES, errorMessage));
} else {
reject(new UnifileError(UnifileError.EIO, errorMessage));
}
} else resolve(body);
});
});
} | javascript | function callAPI(session, path, data, subdomain = 'api', isJson = true, headers = null) {
const authorization = 'Bearer ' + session.token;
const reqOptions = {
url: `https://${subdomain}.dropboxapi.com/2${path}`,
method: 'POST',
headers: {
'Authorization': authorization,
'User-Agent': 'Unifile'
},
json: isJson,
encoding: null
};
if(data && Object.keys(data).length !== 0) reqOptions.body = data;
if(headers) {
for(const header in headers) {
reqOptions.headers[header] = headers[header];
}
}
return new Promise(function(resolve, reject) {
request(reqOptions, function(err, res, body) {
if(err) {
reject(err);
} else if(res.statusCode >= 400) {
let errorMessage = null;
// In case of users/get_current_account, Dropbox return a String with the error
// Since isJson = true, it gets parsed by request
if(Buffer.isBuffer(body)) {
try {
errorMessage = JSON.parse(body.toString()).error_summary;
} catch (e) {
errorMessage = body.toString();
}
} else {
errorMessage = (isJson ? body : JSON.parse(body)).error_summary;
}
// Dropbox only uses 409 for endpoints specific errors
let filename = null;
try {
filename = res.request.headers.hasOwnProperty('Dropbox-API-Arg') ?
JSON.parse(res.request.headers['Dropbox-API-Arg']).path
: JSON.parse(res.request.body).path;
} catch (e) {}
if(errorMessage.includes('/not_found/')) {
reject(new UnifileError(UnifileError.ENOENT, `Not Found: ${filename}`));
} else if(errorMessage.startsWith('path/conflict/')) {
reject(new UnifileError(UnifileError.EINVAL, `Creation failed due to conflict: ${filename}`));
} else if(errorMessage.startsWith('path/not_file/')) {
reject(new UnifileError(UnifileError.EINVAL, `Path is a directory: ${filename}`));
} else if(res.statusCode === 401) {
reject(new UnifileError(UnifileError.EACCES, errorMessage));
} else {
reject(new UnifileError(UnifileError.EIO, errorMessage));
}
} else resolve(body);
});
});
} | [
"function",
"callAPI",
"(",
"session",
",",
"path",
",",
"data",
",",
"subdomain",
"=",
"'api'",
",",
"isJson",
"=",
"true",
",",
"headers",
"=",
"null",
")",
"{",
"const",
"authorization",
"=",
"'Bearer '",
"+",
"session",
".",
"token",
";",
"const",
"reqOptions",
"=",
"{",
"url",
":",
"`",
"${",
"subdomain",
"}",
"${",
"path",
"}",
"`",
",",
"method",
":",
"'POST'",
",",
"headers",
":",
"{",
"'Authorization'",
":",
"authorization",
",",
"'User-Agent'",
":",
"'Unifile'",
"}",
",",
"json",
":",
"isJson",
",",
"encoding",
":",
"null",
"}",
";",
"if",
"(",
"data",
"&&",
"Object",
".",
"keys",
"(",
"data",
")",
".",
"length",
"!==",
"0",
")",
"reqOptions",
".",
"body",
"=",
"data",
";",
"if",
"(",
"headers",
")",
"{",
"for",
"(",
"const",
"header",
"in",
"headers",
")",
"{",
"reqOptions",
".",
"headers",
"[",
"header",
"]",
"=",
"headers",
"[",
"header",
"]",
";",
"}",
"}",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"request",
"(",
"reqOptions",
",",
"function",
"(",
"err",
",",
"res",
",",
"body",
")",
"{",
"if",
"(",
"err",
")",
"{",
"reject",
"(",
"err",
")",
";",
"}",
"else",
"if",
"(",
"res",
".",
"statusCode",
">=",
"400",
")",
"{",
"let",
"errorMessage",
"=",
"null",
";",
"// In case of users/get_current_account, Dropbox return a String with the error",
"// Since isJson = true, it gets parsed by request",
"if",
"(",
"Buffer",
".",
"isBuffer",
"(",
"body",
")",
")",
"{",
"try",
"{",
"errorMessage",
"=",
"JSON",
".",
"parse",
"(",
"body",
".",
"toString",
"(",
")",
")",
".",
"error_summary",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"errorMessage",
"=",
"body",
".",
"toString",
"(",
")",
";",
"}",
"}",
"else",
"{",
"errorMessage",
"=",
"(",
"isJson",
"?",
"body",
":",
"JSON",
".",
"parse",
"(",
"body",
")",
")",
".",
"error_summary",
";",
"}",
"// Dropbox only uses 409 for endpoints specific errors",
"let",
"filename",
"=",
"null",
";",
"try",
"{",
"filename",
"=",
"res",
".",
"request",
".",
"headers",
".",
"hasOwnProperty",
"(",
"'Dropbox-API-Arg'",
")",
"?",
"JSON",
".",
"parse",
"(",
"res",
".",
"request",
".",
"headers",
"[",
"'Dropbox-API-Arg'",
"]",
")",
".",
"path",
":",
"JSON",
".",
"parse",
"(",
"res",
".",
"request",
".",
"body",
")",
".",
"path",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"}",
"if",
"(",
"errorMessage",
".",
"includes",
"(",
"'/not_found/'",
")",
")",
"{",
"reject",
"(",
"new",
"UnifileError",
"(",
"UnifileError",
".",
"ENOENT",
",",
"`",
"${",
"filename",
"}",
"`",
")",
")",
";",
"}",
"else",
"if",
"(",
"errorMessage",
".",
"startsWith",
"(",
"'path/conflict/'",
")",
")",
"{",
"reject",
"(",
"new",
"UnifileError",
"(",
"UnifileError",
".",
"EINVAL",
",",
"`",
"${",
"filename",
"}",
"`",
")",
")",
";",
"}",
"else",
"if",
"(",
"errorMessage",
".",
"startsWith",
"(",
"'path/not_file/'",
")",
")",
"{",
"reject",
"(",
"new",
"UnifileError",
"(",
"UnifileError",
".",
"EINVAL",
",",
"`",
"${",
"filename",
"}",
"`",
")",
")",
";",
"}",
"else",
"if",
"(",
"res",
".",
"statusCode",
"===",
"401",
")",
"{",
"reject",
"(",
"new",
"UnifileError",
"(",
"UnifileError",
".",
"EACCES",
",",
"errorMessage",
")",
")",
";",
"}",
"else",
"{",
"reject",
"(",
"new",
"UnifileError",
"(",
"UnifileError",
".",
"EIO",
",",
"errorMessage",
")",
")",
";",
"}",
"}",
"else",
"resolve",
"(",
"body",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Make a call to the Dropbox API
@param {Object} session - Dropbox session storage
@param {string} path - End point path
@param {Object} data - Data to pass. Convert to querystring if method is GET or to the request body
@param {string} [subdomain=api] - Subdomain of the endpoint to call (api/content)
@param {boolean} [isJson=true] - Whether to stringify the body or not
@param {Object} [headers={}] - Override of addition to the request headers
@return {Promise} a Promise of the result send by server
@private | [
"Make",
"a",
"call",
"to",
"the",
"Dropbox",
"API"
] | bc0750736ccdb3f6cf620ad5063ee851ceeaf445 | https://github.com/silexlabs/unifile/blob/bc0750736ccdb3f6cf620ad5063ee851ceeaf445/lib/unifile-dropbox.js#L27-L87 |
21,548 | silexlabs/unifile | lib/unifile-dropbox.js | safeStringify | function safeStringify(v) {
return JSON.stringify(v).replace(charsToEncode,
function(c) {
return '\\u' + ('000' + c.charCodeAt(0).toString(16)).slice(-4);
}
);
} | javascript | function safeStringify(v) {
return JSON.stringify(v).replace(charsToEncode,
function(c) {
return '\\u' + ('000' + c.charCodeAt(0).toString(16)).slice(-4);
}
);
} | [
"function",
"safeStringify",
"(",
"v",
")",
"{",
"return",
"JSON",
".",
"stringify",
"(",
"v",
")",
".",
"replace",
"(",
"charsToEncode",
",",
"function",
"(",
"c",
")",
"{",
"return",
"'\\\\u'",
"+",
"(",
"'000'",
"+",
"c",
".",
"charCodeAt",
"(",
"0",
")",
".",
"toString",
"(",
"16",
")",
")",
".",
"slice",
"(",
"-",
"4",
")",
";",
"}",
")",
";",
"}"
] | Stringifies a JSON object and make it header-safe by encoding
non-ASCII characters.
@param {Object} v - JSON object to stringify
@returns {String} the stringified object with special chars encoded
@see https://www.dropboxforum.com/t5/API-support/HTTP-header-quot-Dropbox-API-Arg-quot-could-not-decode-input-as/td-p/173822 | [
"Stringifies",
"a",
"JSON",
"object",
"and",
"make",
"it",
"header",
"-",
"safe",
"by",
"encoding",
"non",
"-",
"ASCII",
"characters",
"."
] | bc0750736ccdb3f6cf620ad5063ee851ceeaf445 | https://github.com/silexlabs/unifile/blob/bc0750736ccdb3f6cf620ad5063ee851ceeaf445/lib/unifile-dropbox.js#L163-L169 |
21,549 | staruml/metadata-json | lib/html.js | exportToHTML | function exportToHTML(targetDir, exportDiagram) {
fs.ensureDirSync(targetDir);
fs.ensureDirSync(targetDir + "/contents");
fs.ensureDirSync(targetDir + "/diagrams");
fs.copySync(__dirname + "/../resources/html/assets", targetDir + "/assets");
// Generate html documents
try {
var root = mdjson.getRoot();
mdjson.render(__dirname + "/../resources/html/templates/index.ejs", targetDir + "/index.html", root, { filters: filters });
mdjson.render(__dirname + "/../resources/html/templates/navigation.ejs", targetDir + "/contents/navigation.html", root, { filters: filters });
mdjson.render(__dirname + "/../resources/html/templates/diagrams.ejs", targetDir + "/contents/diagrams.html", root, { filters: filters });
mdjson.render(__dirname + "/../resources/html/templates/element_index.ejs", targetDir + "/contents/element_index.html", root, { filters: filters });
mdjson.renderBulk(__dirname + "/../resources/html/templates/content.ejs", targetDir + "/contents/<%=: element | toFilename %>.html", "@Model", { filters: filters }, function (err, file, elem) {
if (err) {
console.error(err);
}
});
} catch (err) {
console.error(err);
}
// Export diagram images
if (exportDiagram) {
var diagrams = mdjson.Repository.getInstancesOf("Diagram");
_.each(diagrams, function (d) {
mdjson.exportDiagramAsSVG(d, targetDir + "/diagrams/" + toFilename(d) + ".svg");
});
}
} | javascript | function exportToHTML(targetDir, exportDiagram) {
fs.ensureDirSync(targetDir);
fs.ensureDirSync(targetDir + "/contents");
fs.ensureDirSync(targetDir + "/diagrams");
fs.copySync(__dirname + "/../resources/html/assets", targetDir + "/assets");
// Generate html documents
try {
var root = mdjson.getRoot();
mdjson.render(__dirname + "/../resources/html/templates/index.ejs", targetDir + "/index.html", root, { filters: filters });
mdjson.render(__dirname + "/../resources/html/templates/navigation.ejs", targetDir + "/contents/navigation.html", root, { filters: filters });
mdjson.render(__dirname + "/../resources/html/templates/diagrams.ejs", targetDir + "/contents/diagrams.html", root, { filters: filters });
mdjson.render(__dirname + "/../resources/html/templates/element_index.ejs", targetDir + "/contents/element_index.html", root, { filters: filters });
mdjson.renderBulk(__dirname + "/../resources/html/templates/content.ejs", targetDir + "/contents/<%=: element | toFilename %>.html", "@Model", { filters: filters }, function (err, file, elem) {
if (err) {
console.error(err);
}
});
} catch (err) {
console.error(err);
}
// Export diagram images
if (exportDiagram) {
var diagrams = mdjson.Repository.getInstancesOf("Diagram");
_.each(diagrams, function (d) {
mdjson.exportDiagramAsSVG(d, targetDir + "/diagrams/" + toFilename(d) + ".svg");
});
}
} | [
"function",
"exportToHTML",
"(",
"targetDir",
",",
"exportDiagram",
")",
"{",
"fs",
".",
"ensureDirSync",
"(",
"targetDir",
")",
";",
"fs",
".",
"ensureDirSync",
"(",
"targetDir",
"+",
"\"/contents\"",
")",
";",
"fs",
".",
"ensureDirSync",
"(",
"targetDir",
"+",
"\"/diagrams\"",
")",
";",
"fs",
".",
"copySync",
"(",
"__dirname",
"+",
"\"/../resources/html/assets\"",
",",
"targetDir",
"+",
"\"/assets\"",
")",
";",
"// Generate html documents",
"try",
"{",
"var",
"root",
"=",
"mdjson",
".",
"getRoot",
"(",
")",
";",
"mdjson",
".",
"render",
"(",
"__dirname",
"+",
"\"/../resources/html/templates/index.ejs\"",
",",
"targetDir",
"+",
"\"/index.html\"",
",",
"root",
",",
"{",
"filters",
":",
"filters",
"}",
")",
";",
"mdjson",
".",
"render",
"(",
"__dirname",
"+",
"\"/../resources/html/templates/navigation.ejs\"",
",",
"targetDir",
"+",
"\"/contents/navigation.html\"",
",",
"root",
",",
"{",
"filters",
":",
"filters",
"}",
")",
";",
"mdjson",
".",
"render",
"(",
"__dirname",
"+",
"\"/../resources/html/templates/diagrams.ejs\"",
",",
"targetDir",
"+",
"\"/contents/diagrams.html\"",
",",
"root",
",",
"{",
"filters",
":",
"filters",
"}",
")",
";",
"mdjson",
".",
"render",
"(",
"__dirname",
"+",
"\"/../resources/html/templates/element_index.ejs\"",
",",
"targetDir",
"+",
"\"/contents/element_index.html\"",
",",
"root",
",",
"{",
"filters",
":",
"filters",
"}",
")",
";",
"mdjson",
".",
"renderBulk",
"(",
"__dirname",
"+",
"\"/../resources/html/templates/content.ejs\"",
",",
"targetDir",
"+",
"\"/contents/<%=: element | toFilename %>.html\"",
",",
"\"@Model\"",
",",
"{",
"filters",
":",
"filters",
"}",
",",
"function",
"(",
"err",
",",
"file",
",",
"elem",
")",
"{",
"if",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"err",
")",
";",
"}",
"}",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"err",
")",
";",
"}",
"// Export diagram images",
"if",
"(",
"exportDiagram",
")",
"{",
"var",
"diagrams",
"=",
"mdjson",
".",
"Repository",
".",
"getInstancesOf",
"(",
"\"Diagram\"",
")",
";",
"_",
".",
"each",
"(",
"diagrams",
",",
"function",
"(",
"d",
")",
"{",
"mdjson",
".",
"exportDiagramAsSVG",
"(",
"d",
",",
"targetDir",
"+",
"\"/diagrams/\"",
"+",
"toFilename",
"(",
"d",
")",
"+",
"\".svg\"",
")",
";",
"}",
")",
";",
"}",
"}"
] | Export to HTML
@param{string} targetDir Path where generated HTML files to be located
@param{boolean} exportDiagram Indicate whether generate diagram images or not | [
"Export",
"to",
"HTML"
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/lib/html.js#L102-L129 |
21,550 | staruml/metadata-json | core/Validator.js | addRules | function addRules(rules) {
_.each(rules, function (rule) {
_global.rules[rule.id] = rule;
});
} | javascript | function addRules(rules) {
_.each(rules, function (rule) {
_global.rules[rule.id] = rule;
});
} | [
"function",
"addRules",
"(",
"rules",
")",
"{",
"_",
".",
"each",
"(",
"rules",
",",
"function",
"(",
"rule",
")",
"{",
"_global",
".",
"rules",
"[",
"rule",
".",
"id",
"]",
"=",
"rule",
";",
"}",
")",
";",
"}"
] | Add validation rules
@param {Array.<Object>} rules | [
"Add",
"validation",
"rules"
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/core/Validator.js#L38-L42 |
21,551 | staruml/metadata-json | examples/ex_canvas.js | getImageData | function getImageData(diagram, type) {
// Make a new canvas element for making image data
var canvasElement = new Canvas(500, 500, type),
canvas = new mdjson.Graphics.Canvas(canvasElement.getContext("2d")),
boundingBox = diagram.getBoundingBox(canvas),
rectExpand = 10;
// Initialize new canvas
boundingBox.expand(rectExpand);
canvas.origin = new mdjson.Graphics.Point(-boundingBox.x1, -boundingBox.y1);
canvas.zoomFactor = new mdjson.Graphics.ZoomFactor(1, 1);
canvasElement.width = boundingBox.getWidth();
canvasElement.height = boundingBox.getHeight();
// Draw diagram to the new canvas
diagram.drawDiagram(canvas);
return canvasElement.toBuffer();
} | javascript | function getImageData(diagram, type) {
// Make a new canvas element for making image data
var canvasElement = new Canvas(500, 500, type),
canvas = new mdjson.Graphics.Canvas(canvasElement.getContext("2d")),
boundingBox = diagram.getBoundingBox(canvas),
rectExpand = 10;
// Initialize new canvas
boundingBox.expand(rectExpand);
canvas.origin = new mdjson.Graphics.Point(-boundingBox.x1, -boundingBox.y1);
canvas.zoomFactor = new mdjson.Graphics.ZoomFactor(1, 1);
canvasElement.width = boundingBox.getWidth();
canvasElement.height = boundingBox.getHeight();
// Draw diagram to the new canvas
diagram.drawDiagram(canvas);
return canvasElement.toBuffer();
} | [
"function",
"getImageData",
"(",
"diagram",
",",
"type",
")",
"{",
"// Make a new canvas element for making image data",
"var",
"canvasElement",
"=",
"new",
"Canvas",
"(",
"500",
",",
"500",
",",
"type",
")",
",",
"canvas",
"=",
"new",
"mdjson",
".",
"Graphics",
".",
"Canvas",
"(",
"canvasElement",
".",
"getContext",
"(",
"\"2d\"",
")",
")",
",",
"boundingBox",
"=",
"diagram",
".",
"getBoundingBox",
"(",
"canvas",
")",
",",
"rectExpand",
"=",
"10",
";",
"// Initialize new canvas",
"boundingBox",
".",
"expand",
"(",
"rectExpand",
")",
";",
"canvas",
".",
"origin",
"=",
"new",
"mdjson",
".",
"Graphics",
".",
"Point",
"(",
"-",
"boundingBox",
".",
"x1",
",",
"-",
"boundingBox",
".",
"y1",
")",
";",
"canvas",
".",
"zoomFactor",
"=",
"new",
"mdjson",
".",
"Graphics",
".",
"ZoomFactor",
"(",
"1",
",",
"1",
")",
";",
"canvasElement",
".",
"width",
"=",
"boundingBox",
".",
"getWidth",
"(",
")",
";",
"canvasElement",
".",
"height",
"=",
"boundingBox",
".",
"getHeight",
"(",
")",
";",
"// Draw diagram to the new canvas",
"diagram",
".",
"drawDiagram",
"(",
"canvas",
")",
";",
"return",
"canvasElement",
".",
"toBuffer",
"(",
")",
";",
"}"
] | Get image data of diagram
@param {Diagram} diagram
@return {Buffer} | [
"Get",
"image",
"data",
"of",
"diagram"
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/examples/ex_canvas.js#L10-L27 |
21,552 | eeshi/node-scrapy | index.js | ScrapeError | function ScrapeError(msg, response, bodyString) {
Error.call(this, msg);
this.response = response;
this.bodyString = bodyString;
} | javascript | function ScrapeError(msg, response, bodyString) {
Error.call(this, msg);
this.response = response;
this.bodyString = bodyString;
} | [
"function",
"ScrapeError",
"(",
"msg",
",",
"response",
",",
"bodyString",
")",
"{",
"Error",
".",
"call",
"(",
"this",
",",
"msg",
")",
";",
"this",
".",
"response",
"=",
"response",
";",
"this",
".",
"bodyString",
"=",
"bodyString",
";",
"}"
] | Custom Error for node-scrapy | [
"Custom",
"Error",
"for",
"node",
"-",
"scrapy"
] | 071f29ac5cc6eab0e3f4919709002a3bdbfc19ad | https://github.com/eeshi/node-scrapy/blob/071f29ac5cc6eab0e3f4919709002a3bdbfc19ad/index.js#L70-L75 |
21,553 | eeshi/node-scrapy | index.js | scrape | function scrape(url, model, options, cb) {
/**
* Make `options` argument optional
*/
if ('function' === typeof options) {
/**
* Interchange `cb`'s position and fill `options` with nice defaults
*/
cb = options;
options = _.cloneDeep(DEFAULTS);
} else {
/**
* Merge all options from `DEFAULTS` not present in `options`
*/
_.defaultsDeep(options, DEFAULTS);
}
/**
* Set `request`'s Uniform Resource Identifier to provied `url`
* @type {string}
*/
options.requestOptions.uri = url;
/**
* Call `request()` to get the resource
*/
request(options.requestOptions, processResponse);
/**
* Handle `request()`'s result: Chain `err` or proceed to parse the resource.
*/
function processResponse(err, res, body) {
if (err) { return cb(err); }
if (res.statusCode !== 200) {
return cb(new ScrapeError('Not OK response from server.', res, body));
}
parseBody(body, model, options, cb);
}
} | javascript | function scrape(url, model, options, cb) {
/**
* Make `options` argument optional
*/
if ('function' === typeof options) {
/**
* Interchange `cb`'s position and fill `options` with nice defaults
*/
cb = options;
options = _.cloneDeep(DEFAULTS);
} else {
/**
* Merge all options from `DEFAULTS` not present in `options`
*/
_.defaultsDeep(options, DEFAULTS);
}
/**
* Set `request`'s Uniform Resource Identifier to provied `url`
* @type {string}
*/
options.requestOptions.uri = url;
/**
* Call `request()` to get the resource
*/
request(options.requestOptions, processResponse);
/**
* Handle `request()`'s result: Chain `err` or proceed to parse the resource.
*/
function processResponse(err, res, body) {
if (err) { return cb(err); }
if (res.statusCode !== 200) {
return cb(new ScrapeError('Not OK response from server.', res, body));
}
parseBody(body, model, options, cb);
}
} | [
"function",
"scrape",
"(",
"url",
",",
"model",
",",
"options",
",",
"cb",
")",
"{",
"/**\n * Make `options` argument optional\n */",
"if",
"(",
"'function'",
"===",
"typeof",
"options",
")",
"{",
"/**\n * Interchange `cb`'s position and fill `options` with nice defaults\n */",
"cb",
"=",
"options",
";",
"options",
"=",
"_",
".",
"cloneDeep",
"(",
"DEFAULTS",
")",
";",
"}",
"else",
"{",
"/**\n * Merge all options from `DEFAULTS` not present in `options`\n */",
"_",
".",
"defaultsDeep",
"(",
"options",
",",
"DEFAULTS",
")",
";",
"}",
"/**\n * Set `request`'s Uniform Resource Identifier to provied `url`\n * @type {string}\n */",
"options",
".",
"requestOptions",
".",
"uri",
"=",
"url",
";",
"/**\n * Call `request()` to get the resource\n */",
"request",
"(",
"options",
".",
"requestOptions",
",",
"processResponse",
")",
";",
"/**\n * Handle `request()`'s result: Chain `err` or proceed to parse the resource.\n */",
"function",
"processResponse",
"(",
"err",
",",
"res",
",",
"body",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"cb",
"(",
"err",
")",
";",
"}",
"if",
"(",
"res",
".",
"statusCode",
"!==",
"200",
")",
"{",
"return",
"cb",
"(",
"new",
"ScrapeError",
"(",
"'Not OK response from server.'",
",",
"res",
",",
"body",
")",
")",
";",
"}",
"parseBody",
"(",
"body",
",",
"model",
",",
"options",
",",
"cb",
")",
";",
"}",
"}"
] | Scrape a web page
@param {string} url Valid URL to scrape
@param {Object|string} model String or object describing the data to be extracted from the given url
@param {Object} [options={}] Aditional options for request and cheerio
@param {Function} cb Standard nodejs callback
@return {null} | [
"Scrape",
"a",
"web",
"page"
] | 071f29ac5cc6eab0e3f4919709002a3bdbfc19ad | https://github.com/eeshi/node-scrapy/blob/071f29ac5cc6eab0e3f4919709002a3bdbfc19ad/index.js#L89-L142 |
21,554 | eeshi/node-scrapy | index.js | parseBody | function parseBody(bodyString, model, options, cb) {
var result;
var dom;
/**
* Load the HTML and parse it with cheerio to create a DOM
*/
try {
dom = cheerio.load(bodyString, options.cheerioOptions);
} catch (err) {
err.bodyString = bodyString;
return cb(err);
}
result = getItem(dom, model, options.itemOptions);
if (result instanceof Error) {
result.bodyString = bodyString;
return cb(result);
}
return cb(null, result);
} | javascript | function parseBody(bodyString, model, options, cb) {
var result;
var dom;
/**
* Load the HTML and parse it with cheerio to create a DOM
*/
try {
dom = cheerio.load(bodyString, options.cheerioOptions);
} catch (err) {
err.bodyString = bodyString;
return cb(err);
}
result = getItem(dom, model, options.itemOptions);
if (result instanceof Error) {
result.bodyString = bodyString;
return cb(result);
}
return cb(null, result);
} | [
"function",
"parseBody",
"(",
"bodyString",
",",
"model",
",",
"options",
",",
"cb",
")",
"{",
"var",
"result",
";",
"var",
"dom",
";",
"/**\n * Load the HTML and parse it with cheerio to create a DOM\n */",
"try",
"{",
"dom",
"=",
"cheerio",
".",
"load",
"(",
"bodyString",
",",
"options",
".",
"cheerioOptions",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"err",
".",
"bodyString",
"=",
"bodyString",
";",
"return",
"cb",
"(",
"err",
")",
";",
"}",
"result",
"=",
"getItem",
"(",
"dom",
",",
"model",
",",
"options",
".",
"itemOptions",
")",
";",
"if",
"(",
"result",
"instanceof",
"Error",
")",
"{",
"result",
".",
"bodyString",
"=",
"bodyString",
";",
"return",
"cb",
"(",
"result",
")",
";",
"}",
"return",
"cb",
"(",
"null",
",",
"result",
")",
";",
"}"
] | Parse the HTML in search of each item in `model`
@param {string} bodyString HTML content
@param {Object|string} model Data model or string
@param {Object} options Item defaults
@param {Function} cb Callback
@return {null} | [
"Parse",
"the",
"HTML",
"in",
"search",
"of",
"each",
"item",
"in",
"model"
] | 071f29ac5cc6eab0e3f4919709002a3bdbfc19ad | https://github.com/eeshi/node-scrapy/blob/071f29ac5cc6eab0e3f4919709002a3bdbfc19ad/index.js#L153-L178 |
21,555 | eeshi/node-scrapy | index.js | getItem | function getItem(dom, item, defaults) {
var data;
var get;
var trim;
var nodes;
var selector;
/**
* If the `item` itself is a selector, grab it as `selector` and set item to
* a new empty object.
*/
if ('string' === typeof item) {
selector = item;
item = {};
/**
* If not, it should be an object.
* If it has no `selector`, it means it is an embedded document, so resolve it
* recursively.
*/
} else if (!item.selector) {
data = {};
for (var embedded in item) {
data[embedded] = getItem(dom, item[embedded], defaults);
if (data[embedded] instanceof Error) {
return data[embedded];
}
}
return data;
/**
* If it does have a `selector`, use it!
*/
} else { selector = item.selector; }
/**
* Then fulfill the `item` with nice `defaults`.
*/
_.defaultsDeep(item, defaults);
/**
* This is an array of cheerio objects. Always an array.
* @type {Object}
*/
nodes = dom(selector);
/**
* If there are no matches for the given `selector` set the result as `null`
* Ohterwise, proceed to process the result.
*/
if (!nodes.length) {
data = null;
} else {
/**
* Configure the `trim` function based on the item.trim options.
* If `false`, simply return the same value.
*/
switch (item.trim) {
case true:
trim = String.prototype.trim;
break;
case false:
trim = function() { return this; };
break;
case 'left':
trim = String.prototype.trimLeft;
break;
case 'right':
trim = String.prototype.trimRight;
break;
}
/**
* Configure transformation function.
*/
if ('function' === typeof item.transform) {
transform = item.transform;
} else {
transform = function() { return this.toString(); };
}
/**
* The text of a node is what you probably are looking for. Scraping is all
* about content.
* Cheerio has the `.text()` method to get it, this is the default.
* If you are looking for something else, it must be an attribute, like a
* link's `href` or an image/script's `src` or a form's `action`.
* @type {Function}
*/
get = (function(i){
if (i.get === 'text')
return function(node) { return transform.apply(item.prefix + trim.apply(node.text()) + item.suffix); };
else if (i.get === 'html')
return function(node) { return transform.apply(item.prefix + trim.apply(node.html()) + item.suffix); };
else
return function(node) { return transform.apply(item.prefix + trim.apply(node.attr(item.get)) + item.suffix); };
})(item);
/**
* When `unique` is set to `true`, only the first match will be returned, no
* matter how many elements actually matched the `selector`.
* When set to `false`, it will return the results into an array, even when
* only one element matched the `selector`.
* When set to `'auto'`, (scrapy's default) an unwrapped result will be returned
* when a single element matched the `selector`, an array if many.
*/
switch (item.unique) {
case true:
data = get(nodes.eq(0));
break;
case 'auto':
if (nodes.length === 1) {
data = get(nodes.eq(0));
break;
}
case false:
data = [];
for (var i = nodes.length - 1; i >= 0; i--) {
data[i] = get(nodes.eq(i));
}
break;
}
}
/**
* When no element is found for the given `selector` but it was explicitly
* `required`, return an `Error` instead of `data`.
*/
if (!data && item.required) {
return new Error('Item [' + selector + '] set as REQUIRED and NOT found');
}
return data;
} | javascript | function getItem(dom, item, defaults) {
var data;
var get;
var trim;
var nodes;
var selector;
/**
* If the `item` itself is a selector, grab it as `selector` and set item to
* a new empty object.
*/
if ('string' === typeof item) {
selector = item;
item = {};
/**
* If not, it should be an object.
* If it has no `selector`, it means it is an embedded document, so resolve it
* recursively.
*/
} else if (!item.selector) {
data = {};
for (var embedded in item) {
data[embedded] = getItem(dom, item[embedded], defaults);
if (data[embedded] instanceof Error) {
return data[embedded];
}
}
return data;
/**
* If it does have a `selector`, use it!
*/
} else { selector = item.selector; }
/**
* Then fulfill the `item` with nice `defaults`.
*/
_.defaultsDeep(item, defaults);
/**
* This is an array of cheerio objects. Always an array.
* @type {Object}
*/
nodes = dom(selector);
/**
* If there are no matches for the given `selector` set the result as `null`
* Ohterwise, proceed to process the result.
*/
if (!nodes.length) {
data = null;
} else {
/**
* Configure the `trim` function based on the item.trim options.
* If `false`, simply return the same value.
*/
switch (item.trim) {
case true:
trim = String.prototype.trim;
break;
case false:
trim = function() { return this; };
break;
case 'left':
trim = String.prototype.trimLeft;
break;
case 'right':
trim = String.prototype.trimRight;
break;
}
/**
* Configure transformation function.
*/
if ('function' === typeof item.transform) {
transform = item.transform;
} else {
transform = function() { return this.toString(); };
}
/**
* The text of a node is what you probably are looking for. Scraping is all
* about content.
* Cheerio has the `.text()` method to get it, this is the default.
* If you are looking for something else, it must be an attribute, like a
* link's `href` or an image/script's `src` or a form's `action`.
* @type {Function}
*/
get = (function(i){
if (i.get === 'text')
return function(node) { return transform.apply(item.prefix + trim.apply(node.text()) + item.suffix); };
else if (i.get === 'html')
return function(node) { return transform.apply(item.prefix + trim.apply(node.html()) + item.suffix); };
else
return function(node) { return transform.apply(item.prefix + trim.apply(node.attr(item.get)) + item.suffix); };
})(item);
/**
* When `unique` is set to `true`, only the first match will be returned, no
* matter how many elements actually matched the `selector`.
* When set to `false`, it will return the results into an array, even when
* only one element matched the `selector`.
* When set to `'auto'`, (scrapy's default) an unwrapped result will be returned
* when a single element matched the `selector`, an array if many.
*/
switch (item.unique) {
case true:
data = get(nodes.eq(0));
break;
case 'auto':
if (nodes.length === 1) {
data = get(nodes.eq(0));
break;
}
case false:
data = [];
for (var i = nodes.length - 1; i >= 0; i--) {
data[i] = get(nodes.eq(i));
}
break;
}
}
/**
* When no element is found for the given `selector` but it was explicitly
* `required`, return an `Error` instead of `data`.
*/
if (!data && item.required) {
return new Error('Item [' + selector + '] set as REQUIRED and NOT found');
}
return data;
} | [
"function",
"getItem",
"(",
"dom",
",",
"item",
",",
"defaults",
")",
"{",
"var",
"data",
";",
"var",
"get",
";",
"var",
"trim",
";",
"var",
"nodes",
";",
"var",
"selector",
";",
"/**\n * If the `item` itself is a selector, grab it as `selector` and set item to\n * a new empty object.\n */",
"if",
"(",
"'string'",
"===",
"typeof",
"item",
")",
"{",
"selector",
"=",
"item",
";",
"item",
"=",
"{",
"}",
";",
"/**\n * If not, it should be an object.\n * If it has no `selector`, it means it is an embedded document, so resolve it\n * recursively.\n */",
"}",
"else",
"if",
"(",
"!",
"item",
".",
"selector",
")",
"{",
"data",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"embedded",
"in",
"item",
")",
"{",
"data",
"[",
"embedded",
"]",
"=",
"getItem",
"(",
"dom",
",",
"item",
"[",
"embedded",
"]",
",",
"defaults",
")",
";",
"if",
"(",
"data",
"[",
"embedded",
"]",
"instanceof",
"Error",
")",
"{",
"return",
"data",
"[",
"embedded",
"]",
";",
"}",
"}",
"return",
"data",
";",
"/**\n * If it does have a `selector`, use it!\n */",
"}",
"else",
"{",
"selector",
"=",
"item",
".",
"selector",
";",
"}",
"/**\n * Then fulfill the `item` with nice `defaults`.\n */",
"_",
".",
"defaultsDeep",
"(",
"item",
",",
"defaults",
")",
";",
"/**\n * This is an array of cheerio objects. Always an array.\n * @type {Object}\n */",
"nodes",
"=",
"dom",
"(",
"selector",
")",
";",
"/**\n * If there are no matches for the given `selector` set the result as `null`\n * Ohterwise, proceed to process the result.\n */",
"if",
"(",
"!",
"nodes",
".",
"length",
")",
"{",
"data",
"=",
"null",
";",
"}",
"else",
"{",
"/**\n * Configure the `trim` function based on the item.trim options.\n * If `false`, simply return the same value.\n */",
"switch",
"(",
"item",
".",
"trim",
")",
"{",
"case",
"true",
":",
"trim",
"=",
"String",
".",
"prototype",
".",
"trim",
";",
"break",
";",
"case",
"false",
":",
"trim",
"=",
"function",
"(",
")",
"{",
"return",
"this",
";",
"}",
";",
"break",
";",
"case",
"'left'",
":",
"trim",
"=",
"String",
".",
"prototype",
".",
"trimLeft",
";",
"break",
";",
"case",
"'right'",
":",
"trim",
"=",
"String",
".",
"prototype",
".",
"trimRight",
";",
"break",
";",
"}",
"/**\n * Configure transformation function.\n */",
"if",
"(",
"'function'",
"===",
"typeof",
"item",
".",
"transform",
")",
"{",
"transform",
"=",
"item",
".",
"transform",
";",
"}",
"else",
"{",
"transform",
"=",
"function",
"(",
")",
"{",
"return",
"this",
".",
"toString",
"(",
")",
";",
"}",
";",
"}",
"/**\n * The text of a node is what you probably are looking for. Scraping is all\n * about content.\n * Cheerio has the `.text()` method to get it, this is the default.\n * If you are looking for something else, it must be an attribute, like a\n * link's `href` or an image/script's `src` or a form's `action`.\n * @type {Function}\n */",
"get",
"=",
"(",
"function",
"(",
"i",
")",
"{",
"if",
"(",
"i",
".",
"get",
"===",
"'text'",
")",
"return",
"function",
"(",
"node",
")",
"{",
"return",
"transform",
".",
"apply",
"(",
"item",
".",
"prefix",
"+",
"trim",
".",
"apply",
"(",
"node",
".",
"text",
"(",
")",
")",
"+",
"item",
".",
"suffix",
")",
";",
"}",
";",
"else",
"if",
"(",
"i",
".",
"get",
"===",
"'html'",
")",
"return",
"function",
"(",
"node",
")",
"{",
"return",
"transform",
".",
"apply",
"(",
"item",
".",
"prefix",
"+",
"trim",
".",
"apply",
"(",
"node",
".",
"html",
"(",
")",
")",
"+",
"item",
".",
"suffix",
")",
";",
"}",
";",
"else",
"return",
"function",
"(",
"node",
")",
"{",
"return",
"transform",
".",
"apply",
"(",
"item",
".",
"prefix",
"+",
"trim",
".",
"apply",
"(",
"node",
".",
"attr",
"(",
"item",
".",
"get",
")",
")",
"+",
"item",
".",
"suffix",
")",
";",
"}",
";",
"}",
")",
"(",
"item",
")",
";",
"/**\n * When `unique` is set to `true`, only the first match will be returned, no\n * matter how many elements actually matched the `selector`.\n * When set to `false`, it will return the results into an array, even when\n * only one element matched the `selector`.\n * When set to `'auto'`, (scrapy's default) an unwrapped result will be returned\n * when a single element matched the `selector`, an array if many.\n */",
"switch",
"(",
"item",
".",
"unique",
")",
"{",
"case",
"true",
":",
"data",
"=",
"get",
"(",
"nodes",
".",
"eq",
"(",
"0",
")",
")",
";",
"break",
";",
"case",
"'auto'",
":",
"if",
"(",
"nodes",
".",
"length",
"===",
"1",
")",
"{",
"data",
"=",
"get",
"(",
"nodes",
".",
"eq",
"(",
"0",
")",
")",
";",
"break",
";",
"}",
"case",
"false",
":",
"data",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"nodes",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"data",
"[",
"i",
"]",
"=",
"get",
"(",
"nodes",
".",
"eq",
"(",
"i",
")",
")",
";",
"}",
"break",
";",
"}",
"}",
"/**\n * When no element is found for the given `selector` but it was explicitly\n * `required`, return an `Error` instead of `data`.\n */",
"if",
"(",
"!",
"data",
"&&",
"item",
".",
"required",
")",
"{",
"return",
"new",
"Error",
"(",
"'Item ['",
"+",
"selector",
"+",
"'] set as REQUIRED and NOT found'",
")",
";",
"}",
"return",
"data",
";",
"}"
] | Given a `dom`, traverse it to get the desired item
@param {Object} dom cheerio object
@param {(string|Object)} item Can be a string holding the `selector`, an Object with multiple options, including `selector`, or an embedded Object with no `selector`.
@param {Object} defaults Default options to fullfill `item`'s unset options
@return {string|string[]|Error} Returns a string or an array of strings with the result... or Error | [
"Given",
"a",
"dom",
"traverse",
"it",
"to",
"get",
"the",
"desired",
"item"
] | 071f29ac5cc6eab0e3f4919709002a3bdbfc19ad | https://github.com/eeshi/node-scrapy/blob/071f29ac5cc6eab0e3f4919709002a3bdbfc19ad/index.js#L188-L348 |
21,556 | staruml/metadata-json | core/Core.js | getSuperType | function getSuperType(subType) {
if (subType) {
return _global.type[_global.meta[subType.name].super];
} else {
return null;
}
} | javascript | function getSuperType(subType) {
if (subType) {
return _global.type[_global.meta[subType.name].super];
} else {
return null;
}
} | [
"function",
"getSuperType",
"(",
"subType",
")",
"{",
"if",
"(",
"subType",
")",
"{",
"return",
"_global",
".",
"type",
"[",
"_global",
".",
"meta",
"[",
"subType",
".",
"name",
"]",
".",
"super",
"]",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] | Return a super type of a given type.
@param {constructor} subType
@return {constructor} - superType of subType | [
"Return",
"a",
"super",
"type",
"of",
"a",
"given",
"type",
"."
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/core/Core.js#L3725-L3731 |
21,557 | staruml/metadata-json | core/Core.js | getCommonType | function getCommonType(elems) {
if (elems && elems.length > 0) {
var commonType = elems[0].getClass();
while (!_.every(elems, function (e) { return (e instanceof commonType); })) {
commonType = getSuperType(commonType);
}
return commonType;
} else {
return null;
}
} | javascript | function getCommonType(elems) {
if (elems && elems.length > 0) {
var commonType = elems[0].getClass();
while (!_.every(elems, function (e) { return (e instanceof commonType); })) {
commonType = getSuperType(commonType);
}
return commonType;
} else {
return null;
}
} | [
"function",
"getCommonType",
"(",
"elems",
")",
"{",
"if",
"(",
"elems",
"&&",
"elems",
".",
"length",
">",
"0",
")",
"{",
"var",
"commonType",
"=",
"elems",
"[",
"0",
"]",
".",
"getClass",
"(",
")",
";",
"while",
"(",
"!",
"_",
".",
"every",
"(",
"elems",
",",
"function",
"(",
"e",
")",
"{",
"return",
"(",
"e",
"instanceof",
"commonType",
")",
";",
"}",
")",
")",
"{",
"commonType",
"=",
"getSuperType",
"(",
"commonType",
")",
";",
"}",
"return",
"commonType",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] | Return a generalized type of given elements.
@param {Array.<Element>} elems
@return {constructor} | [
"Return",
"a",
"generalized",
"type",
"of",
"given",
"elements",
"."
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/core/Core.js#L3739-L3749 |
21,558 | staruml/metadata-json | core/Core.js | findByName | function findByName(array, name) {
if (array && array.length > 0) {
for (var i = 0, len = array.length; i < len; i++) {
var elem = array[i];
if (elem.name == name) {
return elem;
}
}
}
return null;
} | javascript | function findByName(array, name) {
if (array && array.length > 0) {
for (var i = 0, len = array.length; i < len; i++) {
var elem = array[i];
if (elem.name == name) {
return elem;
}
}
}
return null;
} | [
"function",
"findByName",
"(",
"array",
",",
"name",
")",
"{",
"if",
"(",
"array",
"&&",
"array",
".",
"length",
">",
"0",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"array",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"var",
"elem",
"=",
"array",
"[",
"i",
"]",
";",
"if",
"(",
"elem",
".",
"name",
"==",
"name",
")",
"{",
"return",
"elem",
";",
"}",
"}",
"}",
"return",
"null",
";",
"}"
] | Find element by name in a given array.
@param {Array.<Element>} array
@param {string} name
@return {Element} | [
"Find",
"element",
"by",
"name",
"in",
"a",
"given",
"array",
"."
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/core/Core.js#L3758-L3768 |
21,559 | staruml/metadata-json | core/OperationBuilder.js | _getBase | function _getBase(name) {
var operation = {
id: IdGenerator.generateGuid(),
time: getTimestamp(),
name: name,
bypass: false,
ops: []
};
return operation;
} | javascript | function _getBase(name) {
var operation = {
id: IdGenerator.generateGuid(),
time: getTimestamp(),
name: name,
bypass: false,
ops: []
};
return operation;
} | [
"function",
"_getBase",
"(",
"name",
")",
"{",
"var",
"operation",
"=",
"{",
"id",
":",
"IdGenerator",
".",
"generateGuid",
"(",
")",
",",
"time",
":",
"getTimestamp",
"(",
")",
",",
"name",
":",
"name",
",",
"bypass",
":",
"false",
",",
"ops",
":",
"[",
"]",
"}",
";",
"return",
"operation",
";",
"}"
] | Make and return a base operation object.
@private
@param {string} name Operation name
@return {Object} Base operation object | [
"Make",
"and",
"return",
"a",
"base",
"operation",
"object",
"."
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/core/OperationBuilder.js#L89-L98 |
21,560 | staruml/metadata-json | core/OperationBuilder.js | _getArray | function _getArray(elem, field) {
var f = elem._id + "." + field;
if (!_currentArray[f]) {
_currentArray[f] = _.clone(elem[field]);
}
return _currentArray[f];
} | javascript | function _getArray(elem, field) {
var f = elem._id + "." + field;
if (!_currentArray[f]) {
_currentArray[f] = _.clone(elem[field]);
}
return _currentArray[f];
} | [
"function",
"_getArray",
"(",
"elem",
",",
"field",
")",
"{",
"var",
"f",
"=",
"elem",
".",
"_id",
"+",
"\".\"",
"+",
"field",
";",
"if",
"(",
"!",
"_currentArray",
"[",
"f",
"]",
")",
"{",
"_currentArray",
"[",
"f",
"]",
"=",
"_",
".",
"clone",
"(",
"elem",
"[",
"field",
"]",
")",
";",
"}",
"return",
"_currentArray",
"[",
"f",
"]",
";",
"}"
] | Return a copied array of array field of a particular element.
It could be changed by `fieldInsert`, `fieldRemove`.
The reason why using this is index value maybe incorrect when performing `fieldInsert` multiple times.
@private
@param {Element} elem An element
@param {string} field Array field name
@return {number} | [
"Return",
"a",
"copied",
"array",
"of",
"array",
"field",
"of",
"a",
"particular",
"element",
".",
"It",
"could",
"be",
"changed",
"by",
"fieldInsert",
"fieldRemove",
".",
"The",
"reason",
"why",
"using",
"this",
"is",
"index",
"value",
"maybe",
"incorrect",
"when",
"performing",
"fieldInsert",
"multiple",
"times",
"."
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/core/OperationBuilder.js#L110-L116 |
21,561 | staruml/metadata-json | core/OperationBuilder.js | begin | function begin(name, bypass) {
_currentOperation = _getBase(name);
if (bypass === true) {
_currentOperation.bypass = true;
}
} | javascript | function begin(name, bypass) {
_currentOperation = _getBase(name);
if (bypass === true) {
_currentOperation.bypass = true;
}
} | [
"function",
"begin",
"(",
"name",
",",
"bypass",
")",
"{",
"_currentOperation",
"=",
"_getBase",
"(",
"name",
")",
";",
"if",
"(",
"bypass",
"===",
"true",
")",
"{",
"_currentOperation",
".",
"bypass",
"=",
"true",
";",
"}",
"}"
] | Begin to make an operation.
@param {string} opName Operation name | [
"Begin",
"to",
"make",
"an",
"operation",
"."
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/core/OperationBuilder.js#L123-L128 |
21,562 | staruml/metadata-json | core/OperationBuilder.js | insert | function insert(elem) {
try {
$(exports).triggerHandler('insert', [elem]);
} catch (err) {
console.error(err);
}
var writer = new Writer();
elem.save(writer);
_currentOperation.ops.push({op: OP_INSERT, arg: writer.current});
} | javascript | function insert(elem) {
try {
$(exports).triggerHandler('insert', [elem]);
} catch (err) {
console.error(err);
}
var writer = new Writer();
elem.save(writer);
_currentOperation.ops.push({op: OP_INSERT, arg: writer.current});
} | [
"function",
"insert",
"(",
"elem",
")",
"{",
"try",
"{",
"$",
"(",
"exports",
")",
".",
"triggerHandler",
"(",
"'insert'",
",",
"[",
"elem",
"]",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"err",
")",
";",
"}",
"var",
"writer",
"=",
"new",
"Writer",
"(",
")",
";",
"elem",
".",
"save",
"(",
"writer",
")",
";",
"_currentOperation",
".",
"ops",
".",
"push",
"(",
"{",
"op",
":",
"OP_INSERT",
",",
"arg",
":",
"writer",
".",
"current",
"}",
")",
";",
"}"
] | Insert an element.
@param {Element} elem | [
"Insert",
"an",
"element",
"."
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/core/OperationBuilder.js#L160-L169 |
21,563 | staruml/metadata-json | core/OperationBuilder.js | remove | function remove(elem) {
try {
$(exports).triggerHandler('remove', [elem]);
} catch (err) {
console.error(err);
}
var writer = new Writer();
elem.save(writer);
_currentOperation.ops.push({op: OP_REMOVE, arg: writer.current});
} | javascript | function remove(elem) {
try {
$(exports).triggerHandler('remove', [elem]);
} catch (err) {
console.error(err);
}
var writer = new Writer();
elem.save(writer);
_currentOperation.ops.push({op: OP_REMOVE, arg: writer.current});
} | [
"function",
"remove",
"(",
"elem",
")",
"{",
"try",
"{",
"$",
"(",
"exports",
")",
".",
"triggerHandler",
"(",
"'remove'",
",",
"[",
"elem",
"]",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"err",
")",
";",
"}",
"var",
"writer",
"=",
"new",
"Writer",
"(",
")",
";",
"elem",
".",
"save",
"(",
"writer",
")",
";",
"_currentOperation",
".",
"ops",
".",
"push",
"(",
"{",
"op",
":",
"OP_REMOVE",
",",
"arg",
":",
"writer",
".",
"current",
"}",
")",
";",
"}"
] | Remove an element.
@param {Element} elem | [
"Remove",
"an",
"element",
"."
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/core/OperationBuilder.js#L176-L185 |
21,564 | staruml/metadata-json | core/OperationBuilder.js | fieldAssign | function fieldAssign(elem, field, val) {
try {
$(exports).triggerHandler('fieldAssign', [elem, field, val]);
} catch (err) {
console.error(err);
}
var isCustomField = (elem[field] && elem[field].__read);
var oldVal;
if (isCustomField) {
oldVal = elem[field].__write();
} else {
oldVal = elem[field];
}
_currentOperation.ops.push({
op: OP_FIELD_ASSIGN,
arg: {
_id: elem._id,
f: field,
n: val,
o: oldVal
}
});
} | javascript | function fieldAssign(elem, field, val) {
try {
$(exports).triggerHandler('fieldAssign', [elem, field, val]);
} catch (err) {
console.error(err);
}
var isCustomField = (elem[field] && elem[field].__read);
var oldVal;
if (isCustomField) {
oldVal = elem[field].__write();
} else {
oldVal = elem[field];
}
_currentOperation.ops.push({
op: OP_FIELD_ASSIGN,
arg: {
_id: elem._id,
f: field,
n: val,
o: oldVal
}
});
} | [
"function",
"fieldAssign",
"(",
"elem",
",",
"field",
",",
"val",
")",
"{",
"try",
"{",
"$",
"(",
"exports",
")",
".",
"triggerHandler",
"(",
"'fieldAssign'",
",",
"[",
"elem",
",",
"field",
",",
"val",
"]",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"err",
")",
";",
"}",
"var",
"isCustomField",
"=",
"(",
"elem",
"[",
"field",
"]",
"&&",
"elem",
"[",
"field",
"]",
".",
"__read",
")",
";",
"var",
"oldVal",
";",
"if",
"(",
"isCustomField",
")",
"{",
"oldVal",
"=",
"elem",
"[",
"field",
"]",
".",
"__write",
"(",
")",
";",
"}",
"else",
"{",
"oldVal",
"=",
"elem",
"[",
"field",
"]",
";",
"}",
"_currentOperation",
".",
"ops",
".",
"push",
"(",
"{",
"op",
":",
"OP_FIELD_ASSIGN",
",",
"arg",
":",
"{",
"_id",
":",
"elem",
".",
"_id",
",",
"f",
":",
"field",
",",
"n",
":",
"val",
",",
"o",
":",
"oldVal",
"}",
"}",
")",
";",
"}"
] | Assign value to field.
@param {Element} elem
@param {string} field
@param {?} val | [
"Assign",
"value",
"to",
"field",
"."
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/core/OperationBuilder.js#L194-L216 |
21,565 | staruml/metadata-json | core/OperationBuilder.js | fieldInsert | function fieldInsert(elem, field, val) {
try {
$(exports).triggerHandler('fieldInsert', [elem, field, val]);
} catch (err) {
console.error(err);
}
var array = _getArray(elem, field);
array.push(val);
_currentOperation.ops.push({
op: OP_FIELD_INSERT,
arg: {
_id: elem._id,
f: field,
e: val._id,
i: array.indexOf(val)
}
});
} | javascript | function fieldInsert(elem, field, val) {
try {
$(exports).triggerHandler('fieldInsert', [elem, field, val]);
} catch (err) {
console.error(err);
}
var array = _getArray(elem, field);
array.push(val);
_currentOperation.ops.push({
op: OP_FIELD_INSERT,
arg: {
_id: elem._id,
f: field,
e: val._id,
i: array.indexOf(val)
}
});
} | [
"function",
"fieldInsert",
"(",
"elem",
",",
"field",
",",
"val",
")",
"{",
"try",
"{",
"$",
"(",
"exports",
")",
".",
"triggerHandler",
"(",
"'fieldInsert'",
",",
"[",
"elem",
",",
"field",
",",
"val",
"]",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"err",
")",
";",
"}",
"var",
"array",
"=",
"_getArray",
"(",
"elem",
",",
"field",
")",
";",
"array",
".",
"push",
"(",
"val",
")",
";",
"_currentOperation",
".",
"ops",
".",
"push",
"(",
"{",
"op",
":",
"OP_FIELD_INSERT",
",",
"arg",
":",
"{",
"_id",
":",
"elem",
".",
"_id",
",",
"f",
":",
"field",
",",
"e",
":",
"val",
".",
"_id",
",",
"i",
":",
"array",
".",
"indexOf",
"(",
"val",
")",
"}",
"}",
")",
";",
"}"
] | Insert an element to array field.
@param {Element} elem
@param {string} field
@param {?} val | [
"Insert",
"an",
"element",
"to",
"array",
"field",
"."
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/core/OperationBuilder.js#L225-L242 |
21,566 | staruml/metadata-json | core/OperationBuilder.js | fieldReorder | function fieldReorder(elem, field, val, pos) {
try {
$(exports).triggerHandler('fieldReorder', [elem, field, val, pos]);
} catch (err) {
console.error(err);
}
_currentOperation.ops.push({
op: OP_FIELD_REORDER,
arg: {
_id: elem._id,
f: field,
e: val._id,
i: pos
}
});
} | javascript | function fieldReorder(elem, field, val, pos) {
try {
$(exports).triggerHandler('fieldReorder', [elem, field, val, pos]);
} catch (err) {
console.error(err);
}
_currentOperation.ops.push({
op: OP_FIELD_REORDER,
arg: {
_id: elem._id,
f: field,
e: val._id,
i: pos
}
});
} | [
"function",
"fieldReorder",
"(",
"elem",
",",
"field",
",",
"val",
",",
"pos",
")",
"{",
"try",
"{",
"$",
"(",
"exports",
")",
".",
"triggerHandler",
"(",
"'fieldReorder'",
",",
"[",
"elem",
",",
"field",
",",
"val",
",",
"pos",
"]",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"err",
")",
";",
"}",
"_currentOperation",
".",
"ops",
".",
"push",
"(",
"{",
"op",
":",
"OP_FIELD_REORDER",
",",
"arg",
":",
"{",
"_id",
":",
"elem",
".",
"_id",
",",
"f",
":",
"field",
",",
"e",
":",
"val",
".",
"_id",
",",
"i",
":",
"pos",
"}",
"}",
")",
";",
"}"
] | Change order of a value in array field.
@param {Element} elem
@param {string} field
@param {?} val
@param {number} pos Position to be placed | [
"Change",
"order",
"of",
"a",
"value",
"in",
"array",
"field",
"."
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/core/OperationBuilder.js#L328-L343 |
21,567 | staruml/metadata-json | core/OperationBuilder.js | fieldRelocate | function fieldRelocate(elem, field, oldParent, newParent) {
try {
$(exports).triggerHandler('fieldRelocate', [elem, field, oldParent, newParent]);
} catch (err) {
console.error(err);
}
_currentOperation.ops.push({
op: OP_FIELD_RELOCATE,
arg: {
_id: elem._id,
f: field,
op: oldParent._id,
np: newParent._id
}
});
} | javascript | function fieldRelocate(elem, field, oldParent, newParent) {
try {
$(exports).triggerHandler('fieldRelocate', [elem, field, oldParent, newParent]);
} catch (err) {
console.error(err);
}
_currentOperation.ops.push({
op: OP_FIELD_RELOCATE,
arg: {
_id: elem._id,
f: field,
op: oldParent._id,
np: newParent._id
}
});
} | [
"function",
"fieldRelocate",
"(",
"elem",
",",
"field",
",",
"oldParent",
",",
"newParent",
")",
"{",
"try",
"{",
"$",
"(",
"exports",
")",
".",
"triggerHandler",
"(",
"'fieldRelocate'",
",",
"[",
"elem",
",",
"field",
",",
"oldParent",
",",
"newParent",
"]",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"err",
")",
";",
"}",
"_currentOperation",
".",
"ops",
".",
"push",
"(",
"{",
"op",
":",
"OP_FIELD_RELOCATE",
",",
"arg",
":",
"{",
"_id",
":",
"elem",
".",
"_id",
",",
"f",
":",
"field",
",",
"op",
":",
"oldParent",
".",
"_id",
",",
"np",
":",
"newParent",
".",
"_id",
"}",
"}",
")",
";",
"}"
] | Relocate an element to another parent.
@param {Element} elem Element to be relocated
@param {string} field Field name of parent
@param {number} oldParent Current parent
@param {number} newParent New parent to be located in | [
"Relocate",
"an",
"element",
"to",
"another",
"parent",
"."
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/core/OperationBuilder.js#L353-L368 |
21,568 | silexlabs/unifile | lib/unifile-github.js | paginate | function paginate(reqOptions, link, memo) {
const links = link.split(/,\s*/);
let matches;
links.some(function(link) {
matches = link.trim().match(/<(.+)>;\s*rel="next"/);
return matches !== null;
});
// End of pagination
if(!matches) {
return Promise.resolve(memo);
}
return new Promise(function(resolve, reject) {
reqOptions.url = matches[1];
request(reqOptions, function(err, res, body) {
paginate(reqOptions, res.headers.link, memo.concat(JSON.parse(body))).then(resolve);
});
});
} | javascript | function paginate(reqOptions, link, memo) {
const links = link.split(/,\s*/);
let matches;
links.some(function(link) {
matches = link.trim().match(/<(.+)>;\s*rel="next"/);
return matches !== null;
});
// End of pagination
if(!matches) {
return Promise.resolve(memo);
}
return new Promise(function(resolve, reject) {
reqOptions.url = matches[1];
request(reqOptions, function(err, res, body) {
paginate(reqOptions, res.headers.link, memo.concat(JSON.parse(body))).then(resolve);
});
});
} | [
"function",
"paginate",
"(",
"reqOptions",
",",
"link",
",",
"memo",
")",
"{",
"const",
"links",
"=",
"link",
".",
"split",
"(",
"/",
",\\s*",
"/",
")",
";",
"let",
"matches",
";",
"links",
".",
"some",
"(",
"function",
"(",
"link",
")",
"{",
"matches",
"=",
"link",
".",
"trim",
"(",
")",
".",
"match",
"(",
"/",
"<(.+)>;\\s*rel=\"next\"",
"/",
")",
";",
"return",
"matches",
"!==",
"null",
";",
"}",
")",
";",
"// End of pagination",
"if",
"(",
"!",
"matches",
")",
"{",
"return",
"Promise",
".",
"resolve",
"(",
"memo",
")",
";",
"}",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"reqOptions",
".",
"url",
"=",
"matches",
"[",
"1",
"]",
";",
"request",
"(",
"reqOptions",
",",
"function",
"(",
"err",
",",
"res",
",",
"body",
")",
"{",
"paginate",
"(",
"reqOptions",
",",
"res",
".",
"headers",
".",
"link",
",",
"memo",
".",
"concat",
"(",
"JSON",
".",
"parse",
"(",
"body",
")",
")",
")",
".",
"then",
"(",
"resolve",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Handle GitHub pagination
@param {Object} reqOptions - Options to pass to the request. Url will be overidden
@param {string} link - Link header
@param {Object[]} memo - Aggregator of result
@return {Promise} a Promise of aggregated result
@private | [
"Handle",
"GitHub",
"pagination"
] | bc0750736ccdb3f6cf620ad5063ee851ceeaf445 | https://github.com/silexlabs/unifile/blob/bc0750736ccdb3f6cf620ad5063ee851ceeaf445/lib/unifile-github.js#L37-L54 |
21,569 | silexlabs/unifile | lib/unifile-github.js | move | function move(src, dest, treeRes) {
return treeRes.tree.map(function(file) {
const regex = new RegExp('^' + src + '$|^' + src + '(/)');
// Overrides file path
return Object.assign({}, file, {path: file.path.replace(regex, dest + '$1')});
});
} | javascript | function move(src, dest, treeRes) {
return treeRes.tree.map(function(file) {
const regex = new RegExp('^' + src + '$|^' + src + '(/)');
// Overrides file path
return Object.assign({}, file, {path: file.path.replace(regex, dest + '$1')});
});
} | [
"function",
"move",
"(",
"src",
",",
"dest",
",",
"treeRes",
")",
"{",
"return",
"treeRes",
".",
"tree",
".",
"map",
"(",
"function",
"(",
"file",
")",
"{",
"const",
"regex",
"=",
"new",
"RegExp",
"(",
"'^'",
"+",
"src",
"+",
"'$|^'",
"+",
"src",
"+",
"'(/)'",
")",
";",
"// Overrides file path",
"return",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"file",
",",
"{",
"path",
":",
"file",
".",
"path",
".",
"replace",
"(",
"regex",
",",
"dest",
"+",
"'$1'",
")",
"}",
")",
";",
"}",
")",
";",
"}"
] | Move a folder or a file in a branch by transforming the given tree
@param {string} src - Source path relative to branch root
@param {string} dest - Destination path relative to branch root
@param {Object} treeRes[].tree - Commit tree
@param {string} [branch=master] - Branch containing file/folder
@private | [
"Move",
"a",
"folder",
"or",
"a",
"file",
"in",
"a",
"branch",
"by",
"transforming",
"the",
"given",
"tree"
] | bc0750736ccdb3f6cf620ad5063ee851ceeaf445 | https://github.com/silexlabs/unifile/blob/bc0750736ccdb3f6cf620ad5063ee851ceeaf445/lib/unifile-github.js#L65-L71 |
21,570 | staruml/metadata-json | core/PreferenceManager.js | validate | function validate(schema) {
var key, item;
for (key in schema) {
if (schema.hasOwnProperty(key)) {
item = schema[key];
if (!item.text) {
console.error("[PreferenceManager] missing required field: 'text' of '" + key + "'");
}
if (!item.type) {
console.error("[PreferenceManager] missing required field: 'type' of '" + key + "'");
}
if (item.type !== "Section" && typeof item['default'] === "undefined") {
console.error("[PreferenceManager] missing required field: 'default' of '" + key + "'");
}
if (item.type === "Combo" || item.type === "Dropdown") {
if (item.options && item.options.length > 0) {
var i, len;
for (i = 0, len = item.options.length; i < len; i++) {
if (typeof item.options[i].value === "undefined") {
console.error("[PreferenceManager] missing required field of option item: 'value' of '" + key + "'");
}
if (typeof item.options[i].text === "undefined") {
console.error("[PreferenceManager] missing required field of option item: 'text' of '" + key + "'");
}
}
} else {
console.error("[PreferenceManager] missing required field or no items: 'options' of '" + key + "'");
}
}
}
}
return true;
} | javascript | function validate(schema) {
var key, item;
for (key in schema) {
if (schema.hasOwnProperty(key)) {
item = schema[key];
if (!item.text) {
console.error("[PreferenceManager] missing required field: 'text' of '" + key + "'");
}
if (!item.type) {
console.error("[PreferenceManager] missing required field: 'type' of '" + key + "'");
}
if (item.type !== "Section" && typeof item['default'] === "undefined") {
console.error("[PreferenceManager] missing required field: 'default' of '" + key + "'");
}
if (item.type === "Combo" || item.type === "Dropdown") {
if (item.options && item.options.length > 0) {
var i, len;
for (i = 0, len = item.options.length; i < len; i++) {
if (typeof item.options[i].value === "undefined") {
console.error("[PreferenceManager] missing required field of option item: 'value' of '" + key + "'");
}
if (typeof item.options[i].text === "undefined") {
console.error("[PreferenceManager] missing required field of option item: 'text' of '" + key + "'");
}
}
} else {
console.error("[PreferenceManager] missing required field or no items: 'options' of '" + key + "'");
}
}
}
}
return true;
} | [
"function",
"validate",
"(",
"schema",
")",
"{",
"var",
"key",
",",
"item",
";",
"for",
"(",
"key",
"in",
"schema",
")",
"{",
"if",
"(",
"schema",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"item",
"=",
"schema",
"[",
"key",
"]",
";",
"if",
"(",
"!",
"item",
".",
"text",
")",
"{",
"console",
".",
"error",
"(",
"\"[PreferenceManager] missing required field: 'text' of '\"",
"+",
"key",
"+",
"\"'\"",
")",
";",
"}",
"if",
"(",
"!",
"item",
".",
"type",
")",
"{",
"console",
".",
"error",
"(",
"\"[PreferenceManager] missing required field: 'type' of '\"",
"+",
"key",
"+",
"\"'\"",
")",
";",
"}",
"if",
"(",
"item",
".",
"type",
"!==",
"\"Section\"",
"&&",
"typeof",
"item",
"[",
"'default'",
"]",
"===",
"\"undefined\"",
")",
"{",
"console",
".",
"error",
"(",
"\"[PreferenceManager] missing required field: 'default' of '\"",
"+",
"key",
"+",
"\"'\"",
")",
";",
"}",
"if",
"(",
"item",
".",
"type",
"===",
"\"Combo\"",
"||",
"item",
".",
"type",
"===",
"\"Dropdown\"",
")",
"{",
"if",
"(",
"item",
".",
"options",
"&&",
"item",
".",
"options",
".",
"length",
">",
"0",
")",
"{",
"var",
"i",
",",
"len",
";",
"for",
"(",
"i",
"=",
"0",
",",
"len",
"=",
"item",
".",
"options",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"if",
"(",
"typeof",
"item",
".",
"options",
"[",
"i",
"]",
".",
"value",
"===",
"\"undefined\"",
")",
"{",
"console",
".",
"error",
"(",
"\"[PreferenceManager] missing required field of option item: 'value' of '\"",
"+",
"key",
"+",
"\"'\"",
")",
";",
"}",
"if",
"(",
"typeof",
"item",
".",
"options",
"[",
"i",
"]",
".",
"text",
"===",
"\"undefined\"",
")",
"{",
"console",
".",
"error",
"(",
"\"[PreferenceManager] missing required field of option item: 'text' of '\"",
"+",
"key",
"+",
"\"'\"",
")",
";",
"}",
"}",
"}",
"else",
"{",
"console",
".",
"error",
"(",
"\"[PreferenceManager] missing required field or no items: 'options' of '\"",
"+",
"key",
"+",
"\"'\"",
")",
";",
"}",
"}",
"}",
"}",
"return",
"true",
";",
"}"
] | Validate preference schema
@param {Object} schema
@return {boolean} | [
"Validate",
"preference",
"schema"
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/core/PreferenceManager.js#L69-L101 |
21,571 | staruml/metadata-json | core/PreferenceManager.js | register | function register(id, name, schema) {
if (!id || !name || !schema) {
console.error("register(): missing required parameters: id, name, or schema");
return;
}
if (validate(schema)) {
_schemaMap[id] = {
id: id,
name: name,
schema: schema
};
// Build Preference Item Map
_.each(schema, function (item, key) {
if (item) {
_itemMap[key] = item;
}
});
}
} | javascript | function register(id, name, schema) {
if (!id || !name || !schema) {
console.error("register(): missing required parameters: id, name, or schema");
return;
}
if (validate(schema)) {
_schemaMap[id] = {
id: id,
name: name,
schema: schema
};
// Build Preference Item Map
_.each(schema, function (item, key) {
if (item) {
_itemMap[key] = item;
}
});
}
} | [
"function",
"register",
"(",
"id",
",",
"name",
",",
"schema",
")",
"{",
"if",
"(",
"!",
"id",
"||",
"!",
"name",
"||",
"!",
"schema",
")",
"{",
"console",
".",
"error",
"(",
"\"register(): missing required parameters: id, name, or schema\"",
")",
";",
"return",
";",
"}",
"if",
"(",
"validate",
"(",
"schema",
")",
")",
"{",
"_schemaMap",
"[",
"id",
"]",
"=",
"{",
"id",
":",
"id",
",",
"name",
":",
"name",
",",
"schema",
":",
"schema",
"}",
";",
"// Build Preference Item Map",
"_",
".",
"each",
"(",
"schema",
",",
"function",
"(",
"item",
",",
"key",
")",
"{",
"if",
"(",
"item",
")",
"{",
"_itemMap",
"[",
"key",
"]",
"=",
"item",
";",
"}",
"}",
")",
";",
"}",
"}"
] | Register preference schema
@param {string} id
@param {string} name
@param {Object} schema | [
"Register",
"preference",
"schema"
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/core/PreferenceManager.js#L109-L129 |
21,572 | staruml/metadata-json | core/PreferenceManager.js | get | function get(key, defaultValue) {
defaultValue = typeof defaultValue === "undefined" ? null : defaultValue;
if (global.localStorage) {
var _value = global.localStorage.getItem(key),
value = null;
if (_value) {
try {
value = JSON.parse(_value);
} catch (e) {
console.error("[PreferenceManager] Failed to read preference value of key: " + key);
}
} else {
// if not stored in localStorage, return default value from schema
if (_itemMap[key] && typeof _itemMap[key]['default'] !== "undefined") {
value = _itemMap[key]['default'];
} else {
value = defaultValue;
}
}
return value;
} else {
return defaultValue;
}
} | javascript | function get(key, defaultValue) {
defaultValue = typeof defaultValue === "undefined" ? null : defaultValue;
if (global.localStorage) {
var _value = global.localStorage.getItem(key),
value = null;
if (_value) {
try {
value = JSON.parse(_value);
} catch (e) {
console.error("[PreferenceManager] Failed to read preference value of key: " + key);
}
} else {
// if not stored in localStorage, return default value from schema
if (_itemMap[key] && typeof _itemMap[key]['default'] !== "undefined") {
value = _itemMap[key]['default'];
} else {
value = defaultValue;
}
}
return value;
} else {
return defaultValue;
}
} | [
"function",
"get",
"(",
"key",
",",
"defaultValue",
")",
"{",
"defaultValue",
"=",
"typeof",
"defaultValue",
"===",
"\"undefined\"",
"?",
"null",
":",
"defaultValue",
";",
"if",
"(",
"global",
".",
"localStorage",
")",
"{",
"var",
"_value",
"=",
"global",
".",
"localStorage",
".",
"getItem",
"(",
"key",
")",
",",
"value",
"=",
"null",
";",
"if",
"(",
"_value",
")",
"{",
"try",
"{",
"value",
"=",
"JSON",
".",
"parse",
"(",
"_value",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"console",
".",
"error",
"(",
"\"[PreferenceManager] Failed to read preference value of key: \"",
"+",
"key",
")",
";",
"}",
"}",
"else",
"{",
"// if not stored in localStorage, return default value from schema",
"if",
"(",
"_itemMap",
"[",
"key",
"]",
"&&",
"typeof",
"_itemMap",
"[",
"key",
"]",
"[",
"'default'",
"]",
"!==",
"\"undefined\"",
")",
"{",
"value",
"=",
"_itemMap",
"[",
"key",
"]",
"[",
"'default'",
"]",
";",
"}",
"else",
"{",
"value",
"=",
"defaultValue",
";",
"}",
"}",
"return",
"value",
";",
"}",
"else",
"{",
"return",
"defaultValue",
";",
"}",
"}"
] | Return value of key
@param {string} key
@param {?} defaultValue
@return {?} | [
"Return",
"value",
"of",
"key"
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/core/PreferenceManager.js#L138-L161 |
21,573 | staruml/metadata-json | core/PreferenceManager.js | set | function set(key, value) {
if (global.localStorage) {
var _value;
try {
_value = JSON.stringify(value);
global.localStorage.setItem(key, _value);
$(exports).triggerHandler("change", [key, value]);
} catch (e) {
console.error("[PreferenceManager] Failed to write preference value of key: " + key);
}
}
} | javascript | function set(key, value) {
if (global.localStorage) {
var _value;
try {
_value = JSON.stringify(value);
global.localStorage.setItem(key, _value);
$(exports).triggerHandler("change", [key, value]);
} catch (e) {
console.error("[PreferenceManager] Failed to write preference value of key: " + key);
}
}
} | [
"function",
"set",
"(",
"key",
",",
"value",
")",
"{",
"if",
"(",
"global",
".",
"localStorage",
")",
"{",
"var",
"_value",
";",
"try",
"{",
"_value",
"=",
"JSON",
".",
"stringify",
"(",
"value",
")",
";",
"global",
".",
"localStorage",
".",
"setItem",
"(",
"key",
",",
"_value",
")",
";",
"$",
"(",
"exports",
")",
".",
"triggerHandler",
"(",
"\"change\"",
",",
"[",
"key",
",",
"value",
"]",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"console",
".",
"error",
"(",
"\"[PreferenceManager] Failed to write preference value of key: \"",
"+",
"key",
")",
";",
"}",
"}",
"}"
] | Change value of key
@param {string} key
@param {?} value | [
"Change",
"value",
"of",
"key"
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/core/PreferenceManager.js#L168-L179 |
21,574 | staruml/metadata-json | lib/render.js | render | function render(templatePath, outputPath, element, options) {
var template = fs.readFileSync(templatePath, 'utf8'),
rendered = "",
renderedOutput = "";
element = element || null;
options = options || {};
_.extend(options, {
mdjson : mdjson,
filename : templatePath, // to avoid "include" error
root : mdjson.getRoot(),
element : element
});
// Append predefined filters
if (!options.filters) {
options.filters = {};
}
_.extend(options.filters, filters);
rendered = ejs.render(template, options);
renderedOutput = ejs.render(outputPath, options);
fs.ensureFileSync(renderedOutput);
fs.writeFileSync(renderedOutput, rendered);
} | javascript | function render(templatePath, outputPath, element, options) {
var template = fs.readFileSync(templatePath, 'utf8'),
rendered = "",
renderedOutput = "";
element = element || null;
options = options || {};
_.extend(options, {
mdjson : mdjson,
filename : templatePath, // to avoid "include" error
root : mdjson.getRoot(),
element : element
});
// Append predefined filters
if (!options.filters) {
options.filters = {};
}
_.extend(options.filters, filters);
rendered = ejs.render(template, options);
renderedOutput = ejs.render(outputPath, options);
fs.ensureFileSync(renderedOutput);
fs.writeFileSync(renderedOutput, rendered);
} | [
"function",
"render",
"(",
"templatePath",
",",
"outputPath",
",",
"element",
",",
"options",
")",
"{",
"var",
"template",
"=",
"fs",
".",
"readFileSync",
"(",
"templatePath",
",",
"'utf8'",
")",
",",
"rendered",
"=",
"\"\"",
",",
"renderedOutput",
"=",
"\"\"",
";",
"element",
"=",
"element",
"||",
"null",
";",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"_",
".",
"extend",
"(",
"options",
",",
"{",
"mdjson",
":",
"mdjson",
",",
"filename",
":",
"templatePath",
",",
"// to avoid \"include\" error",
"root",
":",
"mdjson",
".",
"getRoot",
"(",
")",
",",
"element",
":",
"element",
"}",
")",
";",
"// Append predefined filters",
"if",
"(",
"!",
"options",
".",
"filters",
")",
"{",
"options",
".",
"filters",
"=",
"{",
"}",
";",
"}",
"_",
".",
"extend",
"(",
"options",
".",
"filters",
",",
"filters",
")",
";",
"rendered",
"=",
"ejs",
".",
"render",
"(",
"template",
",",
"options",
")",
";",
"renderedOutput",
"=",
"ejs",
".",
"render",
"(",
"outputPath",
",",
"options",
")",
";",
"fs",
".",
"ensureFileSync",
"(",
"renderedOutput",
")",
";",
"fs",
".",
"writeFileSync",
"(",
"renderedOutput",
",",
"rendered",
")",
";",
"}"
] | Render a template file with options and save to an output file
@param{string} templatePath Path for a template file
@param{string} outputPath Path for an output file. You can use ejs expression (e.g. `out/<% element.name %>.java`)
@param{Element} element Element to be rendered
@param{Object} options Options used for ejs rendering | [
"Render",
"a",
"template",
"file",
"with",
"options",
"and",
"save",
"to",
"an",
"output",
"file"
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/lib/render.js#L60-L85 |
21,575 | staruml/metadata-json | lib/render.js | renderBulk | function renderBulk(templatePath, outputPath, elements, options, fn) {
var template = fs.readFileSync(templatePath, 'utf8'),
rendered = "",
renderedOutput = "";
elements = elements || [];
options = options || {};
// if elements parameter is selector expression, retrieve them from Repository.
if (_.isString(elements)) {
elements = mdjson.Repository.select(elements) || [];
}
_.extend(options, {
mdjson : mdjson,
filename : templatePath, // to avoid "include" error
root : mdjson.getRoot()
});
// Append predefined filters
if (!options.filters) {
options.filters = {};
}
_.extend(options.filters, filters);
for (var i = 0, len = elements.length; i < len; i++) {
try {
options.element = elements[i];
rendered = ejs.render(template, options);
renderedOutput = ejs.render(outputPath, options);
fs.ensureFileSync(renderedOutput);
fs.writeFileSync(renderedOutput, rendered);
if (_.isFunction(fn)) {
fn(null, renderedOutput, options.element);
}
} catch (err) {
if (_.isFunction(fn)) {
fn(err);
}
}
}
} | javascript | function renderBulk(templatePath, outputPath, elements, options, fn) {
var template = fs.readFileSync(templatePath, 'utf8'),
rendered = "",
renderedOutput = "";
elements = elements || [];
options = options || {};
// if elements parameter is selector expression, retrieve them from Repository.
if (_.isString(elements)) {
elements = mdjson.Repository.select(elements) || [];
}
_.extend(options, {
mdjson : mdjson,
filename : templatePath, // to avoid "include" error
root : mdjson.getRoot()
});
// Append predefined filters
if (!options.filters) {
options.filters = {};
}
_.extend(options.filters, filters);
for (var i = 0, len = elements.length; i < len; i++) {
try {
options.element = elements[i];
rendered = ejs.render(template, options);
renderedOutput = ejs.render(outputPath, options);
fs.ensureFileSync(renderedOutput);
fs.writeFileSync(renderedOutput, rendered);
if (_.isFunction(fn)) {
fn(null, renderedOutput, options.element);
}
} catch (err) {
if (_.isFunction(fn)) {
fn(err);
}
}
}
} | [
"function",
"renderBulk",
"(",
"templatePath",
",",
"outputPath",
",",
"elements",
",",
"options",
",",
"fn",
")",
"{",
"var",
"template",
"=",
"fs",
".",
"readFileSync",
"(",
"templatePath",
",",
"'utf8'",
")",
",",
"rendered",
"=",
"\"\"",
",",
"renderedOutput",
"=",
"\"\"",
";",
"elements",
"=",
"elements",
"||",
"[",
"]",
";",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"// if elements parameter is selector expression, retrieve them from Repository.",
"if",
"(",
"_",
".",
"isString",
"(",
"elements",
")",
")",
"{",
"elements",
"=",
"mdjson",
".",
"Repository",
".",
"select",
"(",
"elements",
")",
"||",
"[",
"]",
";",
"}",
"_",
".",
"extend",
"(",
"options",
",",
"{",
"mdjson",
":",
"mdjson",
",",
"filename",
":",
"templatePath",
",",
"// to avoid \"include\" error",
"root",
":",
"mdjson",
".",
"getRoot",
"(",
")",
"}",
")",
";",
"// Append predefined filters",
"if",
"(",
"!",
"options",
".",
"filters",
")",
"{",
"options",
".",
"filters",
"=",
"{",
"}",
";",
"}",
"_",
".",
"extend",
"(",
"options",
".",
"filters",
",",
"filters",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"elements",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"try",
"{",
"options",
".",
"element",
"=",
"elements",
"[",
"i",
"]",
";",
"rendered",
"=",
"ejs",
".",
"render",
"(",
"template",
",",
"options",
")",
";",
"renderedOutput",
"=",
"ejs",
".",
"render",
"(",
"outputPath",
",",
"options",
")",
";",
"fs",
".",
"ensureFileSync",
"(",
"renderedOutput",
")",
";",
"fs",
".",
"writeFileSync",
"(",
"renderedOutput",
",",
"rendered",
")",
";",
"if",
"(",
"_",
".",
"isFunction",
"(",
"fn",
")",
")",
"{",
"fn",
"(",
"null",
",",
"renderedOutput",
",",
"options",
".",
"element",
")",
";",
"}",
"}",
"catch",
"(",
"err",
")",
"{",
"if",
"(",
"_",
".",
"isFunction",
"(",
"fn",
")",
")",
"{",
"fn",
"(",
"err",
")",
";",
"}",
"}",
"}",
"}"
] | Render a template file with a set of elements and save to multple output files at once
@param{string} templatePath Path for a template file
@param{string} outputPath Path for output file(s). You can use ejs expression (e.g. `out/<% element.name %>.java`)
@param{Array.<Element> | string} elements Array of elements or selector expression to be rendered
@param{Object} options Options used for ejs rendering
@param{function(err, file, elem)} fn Function to be called for each element is rendered | [
"Render",
"a",
"template",
"file",
"with",
"a",
"set",
"of",
"elements",
"and",
"save",
"to",
"multple",
"output",
"files",
"at",
"once"
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/lib/render.js#L96-L137 |
21,576 | staruml/metadata-json | uml/UML.js | function () {
var tagArray = [];
if (this.tags && this.tags.length > 0) {
var i, len, tag;
for (i = 0, len = this.tags.length; i < len; i++) {
tag = this.tags[i];
switch (tag.kind) {
case Core.TK_STRING:
tagArray.push(tag.name + '="' + tag.value + '"');
break;
case Core.TK_REFERENCE:
if (tag.reference instanceof Core.Model) {
tagArray.push(tag.name + '=' + tag.reference.name);
} else {
tagArray.push(tag.name + '=null');
}
break;
case Core.TK_BOOLEAN:
tagArray.push(tag.name + '=' + tag.checked);
break;
case Core.TK_NUMBER:
tagArray.push(tag.name + '=' + tag.number);
break;
// TK_HIDDEN is not shown in Diagram.
}
}
}
return tagArray;
} | javascript | function () {
var tagArray = [];
if (this.tags && this.tags.length > 0) {
var i, len, tag;
for (i = 0, len = this.tags.length; i < len; i++) {
tag = this.tags[i];
switch (tag.kind) {
case Core.TK_STRING:
tagArray.push(tag.name + '="' + tag.value + '"');
break;
case Core.TK_REFERENCE:
if (tag.reference instanceof Core.Model) {
tagArray.push(tag.name + '=' + tag.reference.name);
} else {
tagArray.push(tag.name + '=null');
}
break;
case Core.TK_BOOLEAN:
tagArray.push(tag.name + '=' + tag.checked);
break;
case Core.TK_NUMBER:
tagArray.push(tag.name + '=' + tag.number);
break;
// TK_HIDDEN is not shown in Diagram.
}
}
}
return tagArray;
} | [
"function",
"(",
")",
"{",
"var",
"tagArray",
"=",
"[",
"]",
";",
"if",
"(",
"this",
".",
"tags",
"&&",
"this",
".",
"tags",
".",
"length",
">",
"0",
")",
"{",
"var",
"i",
",",
"len",
",",
"tag",
";",
"for",
"(",
"i",
"=",
"0",
",",
"len",
"=",
"this",
".",
"tags",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"tag",
"=",
"this",
".",
"tags",
"[",
"i",
"]",
";",
"switch",
"(",
"tag",
".",
"kind",
")",
"{",
"case",
"Core",
".",
"TK_STRING",
":",
"tagArray",
".",
"push",
"(",
"tag",
".",
"name",
"+",
"'=\"'",
"+",
"tag",
".",
"value",
"+",
"'\"'",
")",
";",
"break",
";",
"case",
"Core",
".",
"TK_REFERENCE",
":",
"if",
"(",
"tag",
".",
"reference",
"instanceof",
"Core",
".",
"Model",
")",
"{",
"tagArray",
".",
"push",
"(",
"tag",
".",
"name",
"+",
"'='",
"+",
"tag",
".",
"reference",
".",
"name",
")",
";",
"}",
"else",
"{",
"tagArray",
".",
"push",
"(",
"tag",
".",
"name",
"+",
"'=null'",
")",
";",
"}",
"break",
";",
"case",
"Core",
".",
"TK_BOOLEAN",
":",
"tagArray",
".",
"push",
"(",
"tag",
".",
"name",
"+",
"'='",
"+",
"tag",
".",
"checked",
")",
";",
"break",
";",
"case",
"Core",
".",
"TK_NUMBER",
":",
"tagArray",
".",
"push",
"(",
"tag",
".",
"name",
"+",
"'='",
"+",
"tag",
".",
"number",
")",
";",
"break",
";",
"// TK_HIDDEN is not shown in Diagram.",
"}",
"}",
"}",
"return",
"tagArray",
";",
"}"
] | Return an array of tag strings
@memberof UMLElementMixin
@return {Array.<string>} | [
"Return",
"an",
"array",
"of",
"tag",
"strings"
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/uml/UML.js#L283-L311 | |
21,577 | staruml/metadata-json | lib/pdf.js | registerFont | function registerFont(folder) {
var data = fs.readFileSync(folder + "/font.json", {encoding: "utf8"});
var fontArray = JSON.parse(data);
for (var i = 0, len = fontArray.length; i < len; i++) {
var font = fontArray[i];
font.path = folder;
mdjson.Font.registerFont(font);
}
} | javascript | function registerFont(folder) {
var data = fs.readFileSync(folder + "/font.json", {encoding: "utf8"});
var fontArray = JSON.parse(data);
for (var i = 0, len = fontArray.length; i < len; i++) {
var font = fontArray[i];
font.path = folder;
mdjson.Font.registerFont(font);
}
} | [
"function",
"registerFont",
"(",
"folder",
")",
"{",
"var",
"data",
"=",
"fs",
".",
"readFileSync",
"(",
"folder",
"+",
"\"/font.json\"",
",",
"{",
"encoding",
":",
"\"utf8\"",
"}",
")",
";",
"var",
"fontArray",
"=",
"JSON",
".",
"parse",
"(",
"data",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"fontArray",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"var",
"font",
"=",
"fontArray",
"[",
"i",
"]",
";",
"font",
".",
"path",
"=",
"folder",
";",
"mdjson",
".",
"Font",
".",
"registerFont",
"(",
"font",
")",
";",
"}",
"}"
] | Register a font
@param {string} folder | [
"Register",
"a",
"font"
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/lib/pdf.js#L45-L53 |
21,578 | staruml/metadata-json | lib/pdf.js | exportToPDF | function exportToPDF(diagrams, fullPath, options) {
var doc = new PDFDocument(options);
_.each(mdjson.Font.files, function (path, name) {
doc.registerFont(name, path);
});
doc.pipe(fs.createWriteStream(fullPath));
var canvas = new mdjson.PDFGraphics.Canvas(doc);
var i, len;
for (i = 0, len = diagrams.length; i < len; i++) {
if (i > 0) {
doc.addPage(options);
}
var diagram = diagrams[i],
box = diagram.getBoundingBox(canvas),
w = doc.page.width - PDF_MARGIN * 2,
h = doc.page.height - PDF_MARGIN * 2,
zoom = Math.min(w / box.x2, h / box.y2);
canvas.zoomFactor.numer = Math.min(zoom, PDF_DEFAULT_ZOOM);
canvas.origin.x = PDF_MARGIN;
canvas.origin.y = PDF_MARGIN;
_.each(diagram.ownedViews, function (v) {
v.setup(canvas);
v.update(canvas);
v.size(canvas);
v.arrange(canvas);
});
diagram.drawDiagram(canvas, false);
if (options.showName) {
doc.fontSize(10);
doc.font("Helvetica");
doc.text(diagram.getPathname(), PDF_MARGIN, PDF_MARGIN-10);
}
}
doc.end();
} | javascript | function exportToPDF(diagrams, fullPath, options) {
var doc = new PDFDocument(options);
_.each(mdjson.Font.files, function (path, name) {
doc.registerFont(name, path);
});
doc.pipe(fs.createWriteStream(fullPath));
var canvas = new mdjson.PDFGraphics.Canvas(doc);
var i, len;
for (i = 0, len = diagrams.length; i < len; i++) {
if (i > 0) {
doc.addPage(options);
}
var diagram = diagrams[i],
box = diagram.getBoundingBox(canvas),
w = doc.page.width - PDF_MARGIN * 2,
h = doc.page.height - PDF_MARGIN * 2,
zoom = Math.min(w / box.x2, h / box.y2);
canvas.zoomFactor.numer = Math.min(zoom, PDF_DEFAULT_ZOOM);
canvas.origin.x = PDF_MARGIN;
canvas.origin.y = PDF_MARGIN;
_.each(diagram.ownedViews, function (v) {
v.setup(canvas);
v.update(canvas);
v.size(canvas);
v.arrange(canvas);
});
diagram.drawDiagram(canvas, false);
if (options.showName) {
doc.fontSize(10);
doc.font("Helvetica");
doc.text(diagram.getPathname(), PDF_MARGIN, PDF_MARGIN-10);
}
}
doc.end();
} | [
"function",
"exportToPDF",
"(",
"diagrams",
",",
"fullPath",
",",
"options",
")",
"{",
"var",
"doc",
"=",
"new",
"PDFDocument",
"(",
"options",
")",
";",
"_",
".",
"each",
"(",
"mdjson",
".",
"Font",
".",
"files",
",",
"function",
"(",
"path",
",",
"name",
")",
"{",
"doc",
".",
"registerFont",
"(",
"name",
",",
"path",
")",
";",
"}",
")",
";",
"doc",
".",
"pipe",
"(",
"fs",
".",
"createWriteStream",
"(",
"fullPath",
")",
")",
";",
"var",
"canvas",
"=",
"new",
"mdjson",
".",
"PDFGraphics",
".",
"Canvas",
"(",
"doc",
")",
";",
"var",
"i",
",",
"len",
";",
"for",
"(",
"i",
"=",
"0",
",",
"len",
"=",
"diagrams",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"if",
"(",
"i",
">",
"0",
")",
"{",
"doc",
".",
"addPage",
"(",
"options",
")",
";",
"}",
"var",
"diagram",
"=",
"diagrams",
"[",
"i",
"]",
",",
"box",
"=",
"diagram",
".",
"getBoundingBox",
"(",
"canvas",
")",
",",
"w",
"=",
"doc",
".",
"page",
".",
"width",
"-",
"PDF_MARGIN",
"*",
"2",
",",
"h",
"=",
"doc",
".",
"page",
".",
"height",
"-",
"PDF_MARGIN",
"*",
"2",
",",
"zoom",
"=",
"Math",
".",
"min",
"(",
"w",
"/",
"box",
".",
"x2",
",",
"h",
"/",
"box",
".",
"y2",
")",
";",
"canvas",
".",
"zoomFactor",
".",
"numer",
"=",
"Math",
".",
"min",
"(",
"zoom",
",",
"PDF_DEFAULT_ZOOM",
")",
";",
"canvas",
".",
"origin",
".",
"x",
"=",
"PDF_MARGIN",
";",
"canvas",
".",
"origin",
".",
"y",
"=",
"PDF_MARGIN",
";",
"_",
".",
"each",
"(",
"diagram",
".",
"ownedViews",
",",
"function",
"(",
"v",
")",
"{",
"v",
".",
"setup",
"(",
"canvas",
")",
";",
"v",
".",
"update",
"(",
"canvas",
")",
";",
"v",
".",
"size",
"(",
"canvas",
")",
";",
"v",
".",
"arrange",
"(",
"canvas",
")",
";",
"}",
")",
";",
"diagram",
".",
"drawDiagram",
"(",
"canvas",
",",
"false",
")",
";",
"if",
"(",
"options",
".",
"showName",
")",
"{",
"doc",
".",
"fontSize",
"(",
"10",
")",
";",
"doc",
".",
"font",
"(",
"\"Helvetica\"",
")",
";",
"doc",
".",
"text",
"(",
"diagram",
".",
"getPathname",
"(",
")",
",",
"PDF_MARGIN",
",",
"PDF_MARGIN",
"-",
"10",
")",
";",
"}",
"}",
"doc",
".",
"end",
"(",
")",
";",
"}"
] | Export diagrams to a PDF file
@param{Array.<Diagram>} diagrams
@param{string} fullPath
@param{Object} options | [
"Export",
"diagrams",
"to",
"a",
"PDF",
"file"
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/lib/pdf.js#L61-L99 |
21,579 | staruml/metadata-json | core/Repository.js | writeObject | function writeObject(elem) {
var writer = new Core.Writer();
elem.save(writer);
var data = JSON.stringify(writer.current, null, "\t");
return data;
} | javascript | function writeObject(elem) {
var writer = new Core.Writer();
elem.save(writer);
var data = JSON.stringify(writer.current, null, "\t");
return data;
} | [
"function",
"writeObject",
"(",
"elem",
")",
"{",
"var",
"writer",
"=",
"new",
"Core",
".",
"Writer",
"(",
")",
";",
"elem",
".",
"save",
"(",
"writer",
")",
";",
"var",
"data",
"=",
"JSON",
".",
"stringify",
"(",
"writer",
".",
"current",
",",
"null",
",",
"\"\\t\"",
")",
";",
"return",
"data",
";",
"}"
] | Encode a given element to JSON data.
@private
@param {Core.Element} elem Element to be encoded
@return {string} JSON-encoded data. | [
"Encode",
"a",
"given",
"element",
"to",
"JSON",
"data",
"."
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/core/Repository.js#L653-L658 |
21,580 | staruml/metadata-json | core/Repository.js | extractChanged | function extractChanged(operation) {
var i, len, op, elem, changed = [];
if (operation.ops.length > 0) {
for (i = 0, len = operation.ops.length; i < len; i++) {
op = operation.ops[i];
if (op._elem && op._elem._id) {
elem = get(op._elem._id);
if (elem && !_.contains(changed, elem)) {
changed.push(elem);
}
}
if (op.arg && op.arg._id) {
elem = get(op.arg._id);
if (elem && !_.contains(changed, elem)) {
changed.push(elem);
}
}
}
}
return changed;
} | javascript | function extractChanged(operation) {
var i, len, op, elem, changed = [];
if (operation.ops.length > 0) {
for (i = 0, len = operation.ops.length; i < len; i++) {
op = operation.ops[i];
if (op._elem && op._elem._id) {
elem = get(op._elem._id);
if (elem && !_.contains(changed, elem)) {
changed.push(elem);
}
}
if (op.arg && op.arg._id) {
elem = get(op.arg._id);
if (elem && !_.contains(changed, elem)) {
changed.push(elem);
}
}
}
}
return changed;
} | [
"function",
"extractChanged",
"(",
"operation",
")",
"{",
"var",
"i",
",",
"len",
",",
"op",
",",
"elem",
",",
"changed",
"=",
"[",
"]",
";",
"if",
"(",
"operation",
".",
"ops",
".",
"length",
">",
"0",
")",
"{",
"for",
"(",
"i",
"=",
"0",
",",
"len",
"=",
"operation",
".",
"ops",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"op",
"=",
"operation",
".",
"ops",
"[",
"i",
"]",
";",
"if",
"(",
"op",
".",
"_elem",
"&&",
"op",
".",
"_elem",
".",
"_id",
")",
"{",
"elem",
"=",
"get",
"(",
"op",
".",
"_elem",
".",
"_id",
")",
";",
"if",
"(",
"elem",
"&&",
"!",
"_",
".",
"contains",
"(",
"changed",
",",
"elem",
")",
")",
"{",
"changed",
".",
"push",
"(",
"elem",
")",
";",
"}",
"}",
"if",
"(",
"op",
".",
"arg",
"&&",
"op",
".",
"arg",
".",
"_id",
")",
"{",
"elem",
"=",
"get",
"(",
"op",
".",
"arg",
".",
"_id",
")",
";",
"if",
"(",
"elem",
"&&",
"!",
"_",
".",
"contains",
"(",
"changed",
",",
"elem",
")",
")",
"{",
"changed",
".",
"push",
"(",
"elem",
")",
";",
"}",
"}",
"}",
"}",
"return",
"changed",
";",
"}"
] | Extract changed elements from a given Operation
@param {Operation} operation
@return {Array.<Element>} | [
"Extract",
"changed",
"elements",
"from",
"a",
"given",
"Operation"
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/core/Repository.js#L932-L952 |
21,581 | staruml/metadata-json | core/Repository.js | doOperation | function doOperation(operation) {
if (operation.ops.length > 0) {
try {
$(exports).triggerHandler('beforeExecuteOperation', [operation]);
_applyOperation(operation);
if (operation.bypass !== true) {
_undoStack.push(operation);
_redoStack.clear();
$(exports).triggerHandler('operationExecuted', [operation]);
}
} catch (err) {
console.error(err);
}
}
} | javascript | function doOperation(operation) {
if (operation.ops.length > 0) {
try {
$(exports).triggerHandler('beforeExecuteOperation', [operation]);
_applyOperation(operation);
if (operation.bypass !== true) {
_undoStack.push(operation);
_redoStack.clear();
$(exports).triggerHandler('operationExecuted', [operation]);
}
} catch (err) {
console.error(err);
}
}
} | [
"function",
"doOperation",
"(",
"operation",
")",
"{",
"if",
"(",
"operation",
".",
"ops",
".",
"length",
">",
"0",
")",
"{",
"try",
"{",
"$",
"(",
"exports",
")",
".",
"triggerHandler",
"(",
"'beforeExecuteOperation'",
",",
"[",
"operation",
"]",
")",
";",
"_applyOperation",
"(",
"operation",
")",
";",
"if",
"(",
"operation",
".",
"bypass",
"!==",
"true",
")",
"{",
"_undoStack",
".",
"push",
"(",
"operation",
")",
";",
"_redoStack",
".",
"clear",
"(",
")",
";",
"$",
"(",
"exports",
")",
".",
"triggerHandler",
"(",
"'operationExecuted'",
",",
"[",
"operation",
"]",
")",
";",
"}",
"}",
"catch",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"err",
")",
";",
"}",
"}",
"}"
] | Do an Operation
If operation.bypass == true, the operation will not be pushed to UndoStack.
@param {Operation} operation | [
"Do",
"an",
"Operation",
"If",
"operation",
".",
"bypass",
"==",
"true",
"the",
"operation",
"will",
"not",
"be",
"pushed",
"to",
"UndoStack",
"."
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/core/Repository.js#L959-L973 |
21,582 | staruml/metadata-json | core/Repository.js | select | function select(selector) {
selector = selector || "";
// Parse selector into an array of terms
var interm = selector
.replace(/::/g, "\n::\n")
.replace(/@/g, "\n@")
.replace(/\./g, "\n.")
.replace(/\[/g, "\n[");
var i, len,
sliced = interm.split("\n"),
terms = [];
for (i = 0, len = sliced.length; i < len; i++) {
var item = sliced[i].trim(), arg;
// children selector
if (item === "::") {
terms.push({ op: "::" });
// type selector
} else if (item.charAt(0) === "@") {
arg = item.substring(1, item.length).trim();
if (arg.length === 0) {
throw "[Selector] Type selector requires type name after '@'";
}
terms.push({ op: "@", type: arg });
// field selector
} else if (item.charAt(0) === ".") {
arg = item.substring(1, item.length).trim();
if (arg.length === 0) {
throw "[Selector] Field selector requires field name after '.'";
}
terms.push({ op: ".", field: arg});
// value selector
} else if (item.charAt(0) === "[") {
arg = item.substring(1, item.length - 1);
var fv = arg.split("="), f = fv[0] || "", v = fv[1] || "";
if (!(item.charAt(item.length - 1) === "]" && fv.length === 2 && f.trim().length > 0 && v.trim().length > 0)) {
throw "[Selector] Value selector should be format of '[field=value]'";
}
terms.push({ op: "[]", field: f.trim(), value: v.trim()});
// name selector
} else if (item.length > 0) {
terms.push({ op: "name", name: item });
}
}
// Process terms sequentially
var current = _.values(_idMap),
term,
elems;
for (i = 0, len = terms.length; i < len; i++) {
term = terms[i];
elems = [];
switch (term.op) {
case "::":
current.forEach(function (e) {
elems = _.union(elems, e.getChildren());
});
current = elems;
break;
case "@":
current.forEach(function (e) {
if (type[term.type] && e instanceof type[term.type]) {
elems.push(e);
}
});
current = elems;
break;
case ".":
current.forEach(function (e) {
if (typeof e[term.field] !== "undefined") {
var val = e[term.field];
if (isElement(val)) {
elems.push(val);
}
if (Array.isArray(val)) {
val.forEach(function (e2) {
if (isElement(e2)) {
elems.push(e2);
}
});
}
}
});
current = elems;
break;
case "[]":
current.forEach(function (e) {
if (typeof e[term.field] !== "undefined") {
var val = e[term.field];
if (term.value == val) {
elems.push(e);
}
}
});
current = elems;
break;
case "name":
current.forEach(function (e) {
if (e.name === term.name) {
elems.push(e);
}
});
current = elems;
break;
}
}
return current;
} | javascript | function select(selector) {
selector = selector || "";
// Parse selector into an array of terms
var interm = selector
.replace(/::/g, "\n::\n")
.replace(/@/g, "\n@")
.replace(/\./g, "\n.")
.replace(/\[/g, "\n[");
var i, len,
sliced = interm.split("\n"),
terms = [];
for (i = 0, len = sliced.length; i < len; i++) {
var item = sliced[i].trim(), arg;
// children selector
if (item === "::") {
terms.push({ op: "::" });
// type selector
} else if (item.charAt(0) === "@") {
arg = item.substring(1, item.length).trim();
if (arg.length === 0) {
throw "[Selector] Type selector requires type name after '@'";
}
terms.push({ op: "@", type: arg });
// field selector
} else if (item.charAt(0) === ".") {
arg = item.substring(1, item.length).trim();
if (arg.length === 0) {
throw "[Selector] Field selector requires field name after '.'";
}
terms.push({ op: ".", field: arg});
// value selector
} else if (item.charAt(0) === "[") {
arg = item.substring(1, item.length - 1);
var fv = arg.split("="), f = fv[0] || "", v = fv[1] || "";
if (!(item.charAt(item.length - 1) === "]" && fv.length === 2 && f.trim().length > 0 && v.trim().length > 0)) {
throw "[Selector] Value selector should be format of '[field=value]'";
}
terms.push({ op: "[]", field: f.trim(), value: v.trim()});
// name selector
} else if (item.length > 0) {
terms.push({ op: "name", name: item });
}
}
// Process terms sequentially
var current = _.values(_idMap),
term,
elems;
for (i = 0, len = terms.length; i < len; i++) {
term = terms[i];
elems = [];
switch (term.op) {
case "::":
current.forEach(function (e) {
elems = _.union(elems, e.getChildren());
});
current = elems;
break;
case "@":
current.forEach(function (e) {
if (type[term.type] && e instanceof type[term.type]) {
elems.push(e);
}
});
current = elems;
break;
case ".":
current.forEach(function (e) {
if (typeof e[term.field] !== "undefined") {
var val = e[term.field];
if (isElement(val)) {
elems.push(val);
}
if (Array.isArray(val)) {
val.forEach(function (e2) {
if (isElement(e2)) {
elems.push(e2);
}
});
}
}
});
current = elems;
break;
case "[]":
current.forEach(function (e) {
if (typeof e[term.field] !== "undefined") {
var val = e[term.field];
if (term.value == val) {
elems.push(e);
}
}
});
current = elems;
break;
case "name":
current.forEach(function (e) {
if (e.name === term.name) {
elems.push(e);
}
});
current = elems;
break;
}
}
return current;
} | [
"function",
"select",
"(",
"selector",
")",
"{",
"selector",
"=",
"selector",
"||",
"\"\"",
";",
"// Parse selector into an array of terms",
"var",
"interm",
"=",
"selector",
".",
"replace",
"(",
"/",
"::",
"/",
"g",
",",
"\"\\n::\\n\"",
")",
".",
"replace",
"(",
"/",
"@",
"/",
"g",
",",
"\"\\n@\"",
")",
".",
"replace",
"(",
"/",
"\\.",
"/",
"g",
",",
"\"\\n.\"",
")",
".",
"replace",
"(",
"/",
"\\[",
"/",
"g",
",",
"\"\\n[\"",
")",
";",
"var",
"i",
",",
"len",
",",
"sliced",
"=",
"interm",
".",
"split",
"(",
"\"\\n\"",
")",
",",
"terms",
"=",
"[",
"]",
";",
"for",
"(",
"i",
"=",
"0",
",",
"len",
"=",
"sliced",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"var",
"item",
"=",
"sliced",
"[",
"i",
"]",
".",
"trim",
"(",
")",
",",
"arg",
";",
"// children selector",
"if",
"(",
"item",
"===",
"\"::\"",
")",
"{",
"terms",
".",
"push",
"(",
"{",
"op",
":",
"\"::\"",
"}",
")",
";",
"// type selector",
"}",
"else",
"if",
"(",
"item",
".",
"charAt",
"(",
"0",
")",
"===",
"\"@\"",
")",
"{",
"arg",
"=",
"item",
".",
"substring",
"(",
"1",
",",
"item",
".",
"length",
")",
".",
"trim",
"(",
")",
";",
"if",
"(",
"arg",
".",
"length",
"===",
"0",
")",
"{",
"throw",
"\"[Selector] Type selector requires type name after '@'\"",
";",
"}",
"terms",
".",
"push",
"(",
"{",
"op",
":",
"\"@\"",
",",
"type",
":",
"arg",
"}",
")",
";",
"// field selector",
"}",
"else",
"if",
"(",
"item",
".",
"charAt",
"(",
"0",
")",
"===",
"\".\"",
")",
"{",
"arg",
"=",
"item",
".",
"substring",
"(",
"1",
",",
"item",
".",
"length",
")",
".",
"trim",
"(",
")",
";",
"if",
"(",
"arg",
".",
"length",
"===",
"0",
")",
"{",
"throw",
"\"[Selector] Field selector requires field name after '.'\"",
";",
"}",
"terms",
".",
"push",
"(",
"{",
"op",
":",
"\".\"",
",",
"field",
":",
"arg",
"}",
")",
";",
"// value selector",
"}",
"else",
"if",
"(",
"item",
".",
"charAt",
"(",
"0",
")",
"===",
"\"[\"",
")",
"{",
"arg",
"=",
"item",
".",
"substring",
"(",
"1",
",",
"item",
".",
"length",
"-",
"1",
")",
";",
"var",
"fv",
"=",
"arg",
".",
"split",
"(",
"\"=\"",
")",
",",
"f",
"=",
"fv",
"[",
"0",
"]",
"||",
"\"\"",
",",
"v",
"=",
"fv",
"[",
"1",
"]",
"||",
"\"\"",
";",
"if",
"(",
"!",
"(",
"item",
".",
"charAt",
"(",
"item",
".",
"length",
"-",
"1",
")",
"===",
"\"]\"",
"&&",
"fv",
".",
"length",
"===",
"2",
"&&",
"f",
".",
"trim",
"(",
")",
".",
"length",
">",
"0",
"&&",
"v",
".",
"trim",
"(",
")",
".",
"length",
">",
"0",
")",
")",
"{",
"throw",
"\"[Selector] Value selector should be format of '[field=value]'\"",
";",
"}",
"terms",
".",
"push",
"(",
"{",
"op",
":",
"\"[]\"",
",",
"field",
":",
"f",
".",
"trim",
"(",
")",
",",
"value",
":",
"v",
".",
"trim",
"(",
")",
"}",
")",
";",
"// name selector",
"}",
"else",
"if",
"(",
"item",
".",
"length",
">",
"0",
")",
"{",
"terms",
".",
"push",
"(",
"{",
"op",
":",
"\"name\"",
",",
"name",
":",
"item",
"}",
")",
";",
"}",
"}",
"// Process terms sequentially",
"var",
"current",
"=",
"_",
".",
"values",
"(",
"_idMap",
")",
",",
"term",
",",
"elems",
";",
"for",
"(",
"i",
"=",
"0",
",",
"len",
"=",
"terms",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"term",
"=",
"terms",
"[",
"i",
"]",
";",
"elems",
"=",
"[",
"]",
";",
"switch",
"(",
"term",
".",
"op",
")",
"{",
"case",
"\"::\"",
":",
"current",
".",
"forEach",
"(",
"function",
"(",
"e",
")",
"{",
"elems",
"=",
"_",
".",
"union",
"(",
"elems",
",",
"e",
".",
"getChildren",
"(",
")",
")",
";",
"}",
")",
";",
"current",
"=",
"elems",
";",
"break",
";",
"case",
"\"@\"",
":",
"current",
".",
"forEach",
"(",
"function",
"(",
"e",
")",
"{",
"if",
"(",
"type",
"[",
"term",
".",
"type",
"]",
"&&",
"e",
"instanceof",
"type",
"[",
"term",
".",
"type",
"]",
")",
"{",
"elems",
".",
"push",
"(",
"e",
")",
";",
"}",
"}",
")",
";",
"current",
"=",
"elems",
";",
"break",
";",
"case",
"\".\"",
":",
"current",
".",
"forEach",
"(",
"function",
"(",
"e",
")",
"{",
"if",
"(",
"typeof",
"e",
"[",
"term",
".",
"field",
"]",
"!==",
"\"undefined\"",
")",
"{",
"var",
"val",
"=",
"e",
"[",
"term",
".",
"field",
"]",
";",
"if",
"(",
"isElement",
"(",
"val",
")",
")",
"{",
"elems",
".",
"push",
"(",
"val",
")",
";",
"}",
"if",
"(",
"Array",
".",
"isArray",
"(",
"val",
")",
")",
"{",
"val",
".",
"forEach",
"(",
"function",
"(",
"e2",
")",
"{",
"if",
"(",
"isElement",
"(",
"e2",
")",
")",
"{",
"elems",
".",
"push",
"(",
"e2",
")",
";",
"}",
"}",
")",
";",
"}",
"}",
"}",
")",
";",
"current",
"=",
"elems",
";",
"break",
";",
"case",
"\"[]\"",
":",
"current",
".",
"forEach",
"(",
"function",
"(",
"e",
")",
"{",
"if",
"(",
"typeof",
"e",
"[",
"term",
".",
"field",
"]",
"!==",
"\"undefined\"",
")",
"{",
"var",
"val",
"=",
"e",
"[",
"term",
".",
"field",
"]",
";",
"if",
"(",
"term",
".",
"value",
"==",
"val",
")",
"{",
"elems",
".",
"push",
"(",
"e",
")",
";",
"}",
"}",
"}",
")",
";",
"current",
"=",
"elems",
";",
"break",
";",
"case",
"\"name\"",
":",
"current",
".",
"forEach",
"(",
"function",
"(",
"e",
")",
"{",
"if",
"(",
"e",
".",
"name",
"===",
"term",
".",
"name",
")",
"{",
"elems",
".",
"push",
"(",
"e",
")",
";",
"}",
"}",
")",
";",
"current",
"=",
"elems",
";",
"break",
";",
"}",
"}",
"return",
"current",
";",
"}"
] | Return an array of elements selected by selector expression.
This is a quite heavy operation, so you need to concern about performance.
Selector expression
- Children selector
ex) Package1:: -- all children of Package1
- Type selector: "@<type>"
ex) Package1::@UMLClass
- Field selector: ".<field>"
ex) Class1.attributes, Package1.owendElements
- Value selector: "[field=value]"
ex) Class1.operations[isAbstract=false]
- Name selector: "<name>" (equivalent to "[name=<name>]")
ex) Class1, Class1::Attribute1
Selector examples:
@UMLClass
Package1::Class1.attributes[type=String]
Package1::Model1::@UMLInterface.operations[isAbstract=false]
@param {string} selector
@return {Array.<Element>} | [
"Return",
"an",
"array",
"of",
"elements",
"selected",
"by",
"selector",
"expression",
".",
"This",
"is",
"a",
"quite",
"heavy",
"operation",
"so",
"you",
"need",
"to",
"concern",
"about",
"performance",
"."
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/core/Repository.js#L1083-L1193 |
21,583 | staruml/metadata-json | core/Repository.js | find | function find(predicate) {
var key, elem;
for (key in _idMap) {
if (_idMap.hasOwnProperty(key)) {
elem = _idMap[key];
if (predicate(elem)) {
return elem;
}
}
}
return null;
} | javascript | function find(predicate) {
var key, elem;
for (key in _idMap) {
if (_idMap.hasOwnProperty(key)) {
elem = _idMap[key];
if (predicate(elem)) {
return elem;
}
}
}
return null;
} | [
"function",
"find",
"(",
"predicate",
")",
"{",
"var",
"key",
",",
"elem",
";",
"for",
"(",
"key",
"in",
"_idMap",
")",
"{",
"if",
"(",
"_idMap",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"elem",
"=",
"_idMap",
"[",
"key",
"]",
";",
"if",
"(",
"predicate",
"(",
"elem",
")",
")",
"{",
"return",
"elem",
";",
"}",
"}",
"}",
"return",
"null",
";",
"}"
] | Find the first matched element satisfying the predicate.
@param {function(Element):boolean} predicate A function to filter elements.
@return {Element} A matched element. | [
"Find",
"the",
"first",
"matched",
"element",
"satisfying",
"the",
"predicate",
"."
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/core/Repository.js#L1242-L1253 |
21,584 | staruml/metadata-json | core/Repository.js | findAll | function findAll(predicate) {
var key,
elem,
result = [];
for (key in _idMap) {
if (_idMap.hasOwnProperty(key)) {
elem = _idMap[key];
if (predicate(elem)) {
result.push(elem);
}
}
}
return result;
} | javascript | function findAll(predicate) {
var key,
elem,
result = [];
for (key in _idMap) {
if (_idMap.hasOwnProperty(key)) {
elem = _idMap[key];
if (predicate(elem)) {
result.push(elem);
}
}
}
return result;
} | [
"function",
"findAll",
"(",
"predicate",
")",
"{",
"var",
"key",
",",
"elem",
",",
"result",
"=",
"[",
"]",
";",
"for",
"(",
"key",
"in",
"_idMap",
")",
"{",
"if",
"(",
"_idMap",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"elem",
"=",
"_idMap",
"[",
"key",
"]",
";",
"if",
"(",
"predicate",
"(",
"elem",
")",
")",
"{",
"result",
".",
"push",
"(",
"elem",
")",
";",
"}",
"}",
"}",
"return",
"result",
";",
"}"
] | Find all elements satisfying the predicate.
@param {function(Element):boolean} predicate A function to filter elements.
@return {Array.<Element>} All matched elements. | [
"Find",
"all",
"elements",
"satisfying",
"the",
"predicate",
"."
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/core/Repository.js#L1260-L1273 |
21,585 | staruml/metadata-json | core/Repository.js | search | function search(keyword, typeFilter) {
keyword = keyword.toLowerCase();
typeFilter = typeFilter || type.Element;
var results = findAll(function (elem) {
var name = elem.name ? elem.name.toLowerCase() : "";
return (name.indexOf(keyword) > -1 && elem instanceof typeFilter);
});
return results;
} | javascript | function search(keyword, typeFilter) {
keyword = keyword.toLowerCase();
typeFilter = typeFilter || type.Element;
var results = findAll(function (elem) {
var name = elem.name ? elem.name.toLowerCase() : "";
return (name.indexOf(keyword) > -1 && elem instanceof typeFilter);
});
return results;
} | [
"function",
"search",
"(",
"keyword",
",",
"typeFilter",
")",
"{",
"keyword",
"=",
"keyword",
".",
"toLowerCase",
"(",
")",
";",
"typeFilter",
"=",
"typeFilter",
"||",
"type",
".",
"Element",
";",
"var",
"results",
"=",
"findAll",
"(",
"function",
"(",
"elem",
")",
"{",
"var",
"name",
"=",
"elem",
".",
"name",
"?",
"elem",
".",
"name",
".",
"toLowerCase",
"(",
")",
":",
"\"\"",
";",
"return",
"(",
"name",
".",
"indexOf",
"(",
"keyword",
")",
">",
"-",
"1",
"&&",
"elem",
"instanceof",
"typeFilter",
")",
";",
"}",
")",
";",
"return",
"results",
";",
"}"
] | Search elements by keyword and type
@param {string} keyword
@param {constructor} typeFilter
@return {Array.<Element>} elements | [
"Search",
"elements",
"by",
"keyword",
"and",
"type"
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/core/Repository.js#L1282-L1290 |
21,586 | staruml/metadata-json | core/Repository.js | getRefsTo | function getRefsTo(elem, iterator) {
var id,
ref,
obj,
list = [];
if (elem) {
obj = _refMap[elem._id];
if (obj) {
for (id in obj) {
if (obj.hasOwnProperty(id)) {
ref = _idMap[id];
if (iterator) {
if (iterator(ref)) { list.push(ref); }
} else {
list.push(ref);
}
}
}
}
}
return list;
} | javascript | function getRefsTo(elem, iterator) {
var id,
ref,
obj,
list = [];
if (elem) {
obj = _refMap[elem._id];
if (obj) {
for (id in obj) {
if (obj.hasOwnProperty(id)) {
ref = _idMap[id];
if (iterator) {
if (iterator(ref)) { list.push(ref); }
} else {
list.push(ref);
}
}
}
}
}
return list;
} | [
"function",
"getRefsTo",
"(",
"elem",
",",
"iterator",
")",
"{",
"var",
"id",
",",
"ref",
",",
"obj",
",",
"list",
"=",
"[",
"]",
";",
"if",
"(",
"elem",
")",
"{",
"obj",
"=",
"_refMap",
"[",
"elem",
".",
"_id",
"]",
";",
"if",
"(",
"obj",
")",
"{",
"for",
"(",
"id",
"in",
"obj",
")",
"{",
"if",
"(",
"obj",
".",
"hasOwnProperty",
"(",
"id",
")",
")",
"{",
"ref",
"=",
"_idMap",
"[",
"id",
"]",
";",
"if",
"(",
"iterator",
")",
"{",
"if",
"(",
"iterator",
"(",
"ref",
")",
")",
"{",
"list",
".",
"push",
"(",
"ref",
")",
";",
"}",
"}",
"else",
"{",
"list",
".",
"push",
"(",
"ref",
")",
";",
"}",
"}",
"}",
"}",
"}",
"return",
"list",
";",
"}"
] | Return all elements referencing to the given element.
@param {Core.Element} elem Element. (model element, view element, or diagram)
@param {?function(Element):boolean} iterator if given, returns instances only satisfying iterator function.
@return {Array<Core.Element>} Elements referencing to. | [
"Return",
"all",
"elements",
"referencing",
"to",
"the",
"given",
"element",
"."
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/core/Repository.js#L1316-L1337 |
21,587 | staruml/metadata-json | core/Repository.js | getRelationshipsOf | function getRelationshipsOf(model, iterator) {
var i,
len,
ref,
refs = getRefsTo(model),
results = [];
function _add(rel) {
if (!_.contains(results, rel)) {
results.push(rel);
}
}
for (i = 0, len = refs.length; i < len; i++) {
ref = refs[i];
// for DirectedRelationship
if ((ref instanceof Core.DirectedRelationship) && (ref.source === model || ref.target === model)) {
if (iterator) {
if (iterator(ref)) {
_add(ref);
}
} else {
_add(ref);
}
}
// for UndirectedRelationship
if ((ref instanceof Core.RelationshipEnd) && (ref.reference === model)) {
if (iterator) {
if (iterator(ref._parent)) {
_add(ref._parent);
}
} else {
_add(ref._parent);
}
}
}
return results;
} | javascript | function getRelationshipsOf(model, iterator) {
var i,
len,
ref,
refs = getRefsTo(model),
results = [];
function _add(rel) {
if (!_.contains(results, rel)) {
results.push(rel);
}
}
for (i = 0, len = refs.length; i < len; i++) {
ref = refs[i];
// for DirectedRelationship
if ((ref instanceof Core.DirectedRelationship) && (ref.source === model || ref.target === model)) {
if (iterator) {
if (iterator(ref)) {
_add(ref);
}
} else {
_add(ref);
}
}
// for UndirectedRelationship
if ((ref instanceof Core.RelationshipEnd) && (ref.reference === model)) {
if (iterator) {
if (iterator(ref._parent)) {
_add(ref._parent);
}
} else {
_add(ref._parent);
}
}
}
return results;
} | [
"function",
"getRelationshipsOf",
"(",
"model",
",",
"iterator",
")",
"{",
"var",
"i",
",",
"len",
",",
"ref",
",",
"refs",
"=",
"getRefsTo",
"(",
"model",
")",
",",
"results",
"=",
"[",
"]",
";",
"function",
"_add",
"(",
"rel",
")",
"{",
"if",
"(",
"!",
"_",
".",
"contains",
"(",
"results",
",",
"rel",
")",
")",
"{",
"results",
".",
"push",
"(",
"rel",
")",
";",
"}",
"}",
"for",
"(",
"i",
"=",
"0",
",",
"len",
"=",
"refs",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"ref",
"=",
"refs",
"[",
"i",
"]",
";",
"// for DirectedRelationship",
"if",
"(",
"(",
"ref",
"instanceof",
"Core",
".",
"DirectedRelationship",
")",
"&&",
"(",
"ref",
".",
"source",
"===",
"model",
"||",
"ref",
".",
"target",
"===",
"model",
")",
")",
"{",
"if",
"(",
"iterator",
")",
"{",
"if",
"(",
"iterator",
"(",
"ref",
")",
")",
"{",
"_add",
"(",
"ref",
")",
";",
"}",
"}",
"else",
"{",
"_add",
"(",
"ref",
")",
";",
"}",
"}",
"// for UndirectedRelationship",
"if",
"(",
"(",
"ref",
"instanceof",
"Core",
".",
"RelationshipEnd",
")",
"&&",
"(",
"ref",
".",
"reference",
"===",
"model",
")",
")",
"{",
"if",
"(",
"iterator",
")",
"{",
"if",
"(",
"iterator",
"(",
"ref",
".",
"_parent",
")",
")",
"{",
"_add",
"(",
"ref",
".",
"_parent",
")",
";",
"}",
"}",
"else",
"{",
"_add",
"(",
"ref",
".",
"_parent",
")",
";",
"}",
"}",
"}",
"return",
"results",
";",
"}"
] | Return all instances of Relationship connected to the given model element.
@param {Core.Model} model Model element.
@param {?function(Element):boolean} iterator if given, returns instances only satisfying iterator function.
@return {Array<Core.Model>} Instances of Relationship. | [
"Return",
"all",
"instances",
"of",
"Relationship",
"connected",
"to",
"the",
"given",
"model",
"element",
"."
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/core/Repository.js#L1345-L1384 |
21,588 | staruml/metadata-json | core/Repository.js | getViewsOf | function getViewsOf(model) {
return getRefsTo(model, function (ref) {
return (ref instanceof Core.View) && (ref.model === model);
});
} | javascript | function getViewsOf(model) {
return getRefsTo(model, function (ref) {
return (ref instanceof Core.View) && (ref.model === model);
});
} | [
"function",
"getViewsOf",
"(",
"model",
")",
"{",
"return",
"getRefsTo",
"(",
"model",
",",
"function",
"(",
"ref",
")",
"{",
"return",
"(",
"ref",
"instanceof",
"Core",
".",
"View",
")",
"&&",
"(",
"ref",
".",
"model",
"===",
"model",
")",
";",
"}",
")",
";",
"}"
] | Return all views associated with the given model.
@param {Core.Model} model Model element.
@return {Array<Core.View>} View elements associated with. | [
"Return",
"all",
"views",
"associated",
"with",
"the",
"given",
"model",
"."
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/core/Repository.js#L1391-L1395 |
21,589 | staruml/metadata-json | core/Repository.js | getEdgeViewsOf | function getEdgeViewsOf(view) {
return getRefsTo(view, function (ref) {
return (ref instanceof Core.EdgeView) &&
(ref.head === view || ref.tail === view);
});
} | javascript | function getEdgeViewsOf(view) {
return getRefsTo(view, function (ref) {
return (ref instanceof Core.EdgeView) &&
(ref.head === view || ref.tail === view);
});
} | [
"function",
"getEdgeViewsOf",
"(",
"view",
")",
"{",
"return",
"getRefsTo",
"(",
"view",
",",
"function",
"(",
"ref",
")",
"{",
"return",
"(",
"ref",
"instanceof",
"Core",
".",
"EdgeView",
")",
"&&",
"(",
"ref",
".",
"head",
"===",
"view",
"||",
"ref",
".",
"tail",
"===",
"view",
")",
";",
"}",
")",
";",
"}"
] | Return all instances of EdgeView linked to the given view.
@param {Core.View} view View element. Typically an instance of NodeView.
@return {Array<Core.EdgeView>} Instances of EdgeView linked to. | [
"Return",
"all",
"instances",
"of",
"EdgeView",
"linked",
"to",
"the",
"given",
"view",
"."
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/core/Repository.js#L1402-L1407 |
21,590 | silexlabs/unifile | lib/unifile-ftp.js | getClient | function getClient(credentials) {
return new Promise((resolve, reject) => {
const ftp = new Ftp(credentials);
ftp.once('connect', () => {
resolve(ftp);
});
});
} | javascript | function getClient(credentials) {
return new Promise((resolve, reject) => {
const ftp = new Ftp(credentials);
ftp.once('connect', () => {
resolve(ftp);
});
});
} | [
"function",
"getClient",
"(",
"credentials",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"const",
"ftp",
"=",
"new",
"Ftp",
"(",
"credentials",
")",
";",
"ftp",
".",
"once",
"(",
"'connect'",
",",
"(",
")",
"=>",
"{",
"resolve",
"(",
"ftp",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Initialize a new FTP client
@param {Credentials} credentials - Access info for the FTP server
@return {Promise<Ftp>} a promise for a FTP client | [
"Initialize",
"a",
"new",
"FTP",
"client"
] | bc0750736ccdb3f6cf620ad5063ee851ceeaf445 | https://github.com/silexlabs/unifile/blob/bc0750736ccdb3f6cf620ad5063ee851ceeaf445/lib/unifile-ftp.js#L19-L26 |
21,591 | staruml/metadata-json | lib/image.js | exportDiagramBulk | function exportDiagramBulk(diagrams, filename, format, options, fn) {
diagrams = diagrams || [];
filename = filename || "<%=diagram.name%>.png";
format = format || "png";
options = options || {};
// if elements parameter is selector expression, retrieve them from Repository.
if (_.isString(diagrams)) {
diagrams = mdjson.Repository.select(diagrams) || [];
}
_.extend(options, {
mdjson : mdjson,
root : mdjson.getRoot()
});
// Append predefined filters
if (!options.filters) {
options.filters = {};
}
_.extend(options.filters, filters);
var renderedFilename = "";
for (var i = 0, len = diagrams.length; i < len; i++) {
try {
options.diagram = diagrams[i];
renderedFilename = ejs.render(filename, options);
fs.ensureFileSync(renderedFilename);
if (format === "png") {
exportDiagramAsPNG(options.diagram, renderedFilename);
} else if (format === "svg") {
exportDiagramAsSVG(options.diagram, renderedFilename);
}
if (_.isFunction(fn)) {
fn(null, renderedFilename, options.diagram);
}
} catch (err) {
if (_.isFunction(fn)) {
fn(err);
}
}
}
} | javascript | function exportDiagramBulk(diagrams, filename, format, options, fn) {
diagrams = diagrams || [];
filename = filename || "<%=diagram.name%>.png";
format = format || "png";
options = options || {};
// if elements parameter is selector expression, retrieve them from Repository.
if (_.isString(diagrams)) {
diagrams = mdjson.Repository.select(diagrams) || [];
}
_.extend(options, {
mdjson : mdjson,
root : mdjson.getRoot()
});
// Append predefined filters
if (!options.filters) {
options.filters = {};
}
_.extend(options.filters, filters);
var renderedFilename = "";
for (var i = 0, len = diagrams.length; i < len; i++) {
try {
options.diagram = diagrams[i];
renderedFilename = ejs.render(filename, options);
fs.ensureFileSync(renderedFilename);
if (format === "png") {
exportDiagramAsPNG(options.diagram, renderedFilename);
} else if (format === "svg") {
exportDiagramAsSVG(options.diagram, renderedFilename);
}
if (_.isFunction(fn)) {
fn(null, renderedFilename, options.diagram);
}
} catch (err) {
if (_.isFunction(fn)) {
fn(err);
}
}
}
} | [
"function",
"exportDiagramBulk",
"(",
"diagrams",
",",
"filename",
",",
"format",
",",
"options",
",",
"fn",
")",
"{",
"diagrams",
"=",
"diagrams",
"||",
"[",
"]",
";",
"filename",
"=",
"filename",
"||",
"\"<%=diagram.name%>.png\"",
";",
"format",
"=",
"format",
"||",
"\"png\"",
";",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"// if elements parameter is selector expression, retrieve them from Repository.",
"if",
"(",
"_",
".",
"isString",
"(",
"diagrams",
")",
")",
"{",
"diagrams",
"=",
"mdjson",
".",
"Repository",
".",
"select",
"(",
"diagrams",
")",
"||",
"[",
"]",
";",
"}",
"_",
".",
"extend",
"(",
"options",
",",
"{",
"mdjson",
":",
"mdjson",
",",
"root",
":",
"mdjson",
".",
"getRoot",
"(",
")",
"}",
")",
";",
"// Append predefined filters",
"if",
"(",
"!",
"options",
".",
"filters",
")",
"{",
"options",
".",
"filters",
"=",
"{",
"}",
";",
"}",
"_",
".",
"extend",
"(",
"options",
".",
"filters",
",",
"filters",
")",
";",
"var",
"renderedFilename",
"=",
"\"\"",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"diagrams",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"try",
"{",
"options",
".",
"diagram",
"=",
"diagrams",
"[",
"i",
"]",
";",
"renderedFilename",
"=",
"ejs",
".",
"render",
"(",
"filename",
",",
"options",
")",
";",
"fs",
".",
"ensureFileSync",
"(",
"renderedFilename",
")",
";",
"if",
"(",
"format",
"===",
"\"png\"",
")",
"{",
"exportDiagramAsPNG",
"(",
"options",
".",
"diagram",
",",
"renderedFilename",
")",
";",
"}",
"else",
"if",
"(",
"format",
"===",
"\"svg\"",
")",
"{",
"exportDiagramAsSVG",
"(",
"options",
".",
"diagram",
",",
"renderedFilename",
")",
";",
"}",
"if",
"(",
"_",
".",
"isFunction",
"(",
"fn",
")",
")",
"{",
"fn",
"(",
"null",
",",
"renderedFilename",
",",
"options",
".",
"diagram",
")",
";",
"}",
"}",
"catch",
"(",
"err",
")",
"{",
"if",
"(",
"_",
".",
"isFunction",
"(",
"fn",
")",
")",
"{",
"fn",
"(",
"err",
")",
";",
"}",
"}",
"}",
"}"
] | Export a set of diagrams at once
@param{Array.<Diagram> | string} diagrams Array of diagrams or selector expression to be exported
@param{string} filename File name for output image file(s). You can use ejs expression (Default: `<%=diagram.name%>.png`)
@param{string} format Image format ("png" or "svg").
@param{Object} options Options used for ejs rendering
@param{function(err, file, elem)} fn Function to be called for each diagram is exported | [
"Export",
"a",
"set",
"of",
"diagrams",
"at",
"once"
] | 4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb | https://github.com/staruml/metadata-json/blob/4a6ea9b93dd426cc8e874daa3ca6aef72ac5bcbb/lib/image.js#L109-L151 |
21,592 | ripple/ripple-rest | api/info.js | getFee | function getFee(callback) {
var fee = this.remote.createTransaction()._computeFee();
callback(null, {fee: utils.dropsToXrp(fee)});
} | javascript | function getFee(callback) {
var fee = this.remote.createTransaction()._computeFee();
callback(null, {fee: utils.dropsToXrp(fee)});
} | [
"function",
"getFee",
"(",
"callback",
")",
"{",
"var",
"fee",
"=",
"this",
".",
"remote",
".",
"createTransaction",
"(",
")",
".",
"_computeFee",
"(",
")",
";",
"callback",
"(",
"null",
",",
"{",
"fee",
":",
"utils",
".",
"dropsToXrp",
"(",
"fee",
")",
"}",
")",
";",
"}"
] | Get the current transaction fee | [
"Get",
"the",
"current",
"transaction",
"fee"
] | ff295cd1ea9641813369b02ba75bb3bf5ef4c9b8 | https://github.com/ripple/ripple-rest/blob/ff295cd1ea9641813369b02ba75bb3bf5ef4c9b8/api/info.js#L41-L44 |
21,593 | ripple/ripple-rest | api/lib/server-lib.js | isConnected | function isConnected(remote) {
if (isNaN(remote._ledger_current_index)) {
// Remote is missing the index of last ledger closed. Unprepared to submit
// transactions
return false;
}
var server = remote.getServer();
if (!server) {
return false;
}
if (remote._stand_alone) {
// If rippled is in standalone mode we can assume there will not be a
// ledger close within 30 seconds.
return true;
}
return (Date.now() - server._lastLedgerClose) <= CONNECTION_TIMEOUT;
} | javascript | function isConnected(remote) {
if (isNaN(remote._ledger_current_index)) {
// Remote is missing the index of last ledger closed. Unprepared to submit
// transactions
return false;
}
var server = remote.getServer();
if (!server) {
return false;
}
if (remote._stand_alone) {
// If rippled is in standalone mode we can assume there will not be a
// ledger close within 30 seconds.
return true;
}
return (Date.now() - server._lastLedgerClose) <= CONNECTION_TIMEOUT;
} | [
"function",
"isConnected",
"(",
"remote",
")",
"{",
"if",
"(",
"isNaN",
"(",
"remote",
".",
"_ledger_current_index",
")",
")",
"{",
"// Remote is missing the index of last ledger closed. Unprepared to submit",
"// transactions",
"return",
"false",
";",
"}",
"var",
"server",
"=",
"remote",
".",
"getServer",
"(",
")",
";",
"if",
"(",
"!",
"server",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"remote",
".",
"_stand_alone",
")",
"{",
"// If rippled is in standalone mode we can assume there will not be a",
"// ledger close within 30 seconds.",
"return",
"true",
";",
"}",
"return",
"(",
"Date",
".",
"now",
"(",
")",
"-",
"server",
".",
"_lastLedgerClose",
")",
"<=",
"CONNECTION_TIMEOUT",
";",
"}"
] | Determine if remote is connected based on time of last ledger closed
@param {Server} server
@return {Boolean} | [
"Determine",
"if",
"remote",
"is",
"connected",
"based",
"on",
"time",
"of",
"last",
"ledger",
"closed"
] | ff295cd1ea9641813369b02ba75bb3bf5ef4c9b8 | https://github.com/ripple/ripple-rest/blob/ff295cd1ea9641813369b02ba75bb3bf5ef4c9b8/api/lib/server-lib.js#L16-L35 |
21,594 | ripple/ripple-rest | api/lib/server-lib.js | ensureConnected | function ensureConnected(remote, callback) {
if (remote.getServer()) {
callback(null, isConnected(remote));
} else {
callback(null, false);
}
} | javascript | function ensureConnected(remote, callback) {
if (remote.getServer()) {
callback(null, isConnected(remote));
} else {
callback(null, false);
}
} | [
"function",
"ensureConnected",
"(",
"remote",
",",
"callback",
")",
"{",
"if",
"(",
"remote",
".",
"getServer",
"(",
")",
")",
"{",
"callback",
"(",
"null",
",",
"isConnected",
"(",
"remote",
")",
")",
";",
"}",
"else",
"{",
"callback",
"(",
"null",
",",
"false",
")",
";",
"}",
"}"
] | Check if remote is connected and attempt to reconnect if not
@param {Remote} remote
@param {Function} callback | [
"Check",
"if",
"remote",
"is",
"connected",
"and",
"attempt",
"to",
"reconnect",
"if",
"not"
] | ff295cd1ea9641813369b02ba75bb3bf5ef4c9b8 | https://github.com/ripple/ripple-rest/blob/ff295cd1ea9641813369b02ba75bb3bf5ef4c9b8/api/lib/server-lib.js#L43-L49 |
21,595 | ripple/ripple-rest | server/response-handler.js | success | function success(response, body) {
var content = _.assign(body || {}, {success: true});
send(response, content, StatusCode.ok);
} | javascript | function success(response, body) {
var content = _.assign(body || {}, {success: true});
send(response, content, StatusCode.ok);
} | [
"function",
"success",
"(",
"response",
",",
"body",
")",
"{",
"var",
"content",
"=",
"_",
".",
"assign",
"(",
"body",
"||",
"{",
"}",
",",
"{",
"success",
":",
"true",
"}",
")",
";",
"send",
"(",
"response",
",",
"content",
",",
"StatusCode",
".",
"ok",
")",
";",
"}"
] | Send a success response
@param response - response object
@param body - (optional) body to the response, in addition to the
success property | [
"Send",
"a",
"success",
"response"
] | ff295cd1ea9641813369b02ba75bb3bf5ef4c9b8 | https://github.com/ripple/ripple-rest/blob/ff295cd1ea9641813369b02ba75bb3bf5ef4c9b8/server/response-handler.js#L77-L80 |
21,596 | ripple/ripple-rest | server/response-handler.js | transactionError | function transactionError(response, message, body) {
var content = errorContent(ErrorType.transaction, message, body);
send(response, content, StatusCode.internalServerError);
} | javascript | function transactionError(response, message, body) {
var content = errorContent(ErrorType.transaction, message, body);
send(response, content, StatusCode.internalServerError);
} | [
"function",
"transactionError",
"(",
"response",
",",
"message",
",",
"body",
")",
"{",
"var",
"content",
"=",
"errorContent",
"(",
"ErrorType",
".",
"transaction",
",",
"message",
",",
"body",
")",
";",
"send",
"(",
"response",
",",
"content",
",",
"StatusCode",
".",
"internalServerError",
")",
";",
"}"
] | Send an transaction error response
@param response - response object
@param message - (optional) message to accompany and describe the
invalid response
@param body - (optional) additional body to the response | [
"Send",
"an",
"transaction",
"error",
"response"
] | ff295cd1ea9641813369b02ba75bb3bf5ef4c9b8 | https://github.com/ripple/ripple-rest/blob/ff295cd1ea9641813369b02ba75bb3bf5ef4c9b8/server/response-handler.js#L115-L118 |
21,597 | ripple/ripple-rest | server/response-handler.js | apiError | function apiError(response, error) {
var content = errorContentExt(ErrorType.server, error);
send(response, content, StatusCode.internalServerError);
} | javascript | function apiError(response, error) {
var content = errorContentExt(ErrorType.server, error);
send(response, content, StatusCode.internalServerError);
} | [
"function",
"apiError",
"(",
"response",
",",
"error",
")",
"{",
"var",
"content",
"=",
"errorContentExt",
"(",
"ErrorType",
".",
"server",
",",
"error",
")",
";",
"send",
"(",
"response",
",",
"content",
",",
"StatusCode",
".",
"internalServerError",
")",
";",
"}"
] | Send an api error response
@param response - response object
@param message - (optional) message to accompany and describe the
invalid response
@param body - (optional) additional body to the response | [
"Send",
"an",
"api",
"error",
"response"
] | ff295cd1ea9641813369b02ba75bb3bf5ef4c9b8 | https://github.com/ripple/ripple-rest/blob/ff295cd1ea9641813369b02ba75bb3bf5ef4c9b8/server/response-handler.js#L140-L143 |
21,598 | ripple/ripple-rest | server/response-handler.js | invalidRequestError | function invalidRequestError(response, error) {
var content = errorContentExt(ErrorType.invalidRequest, error);
send(response, content, StatusCode.badRequest);
} | javascript | function invalidRequestError(response, error) {
var content = errorContentExt(ErrorType.invalidRequest, error);
send(response, content, StatusCode.badRequest);
} | [
"function",
"invalidRequestError",
"(",
"response",
",",
"error",
")",
"{",
"var",
"content",
"=",
"errorContentExt",
"(",
"ErrorType",
".",
"invalidRequest",
",",
"error",
")",
";",
"send",
"(",
"response",
",",
"content",
",",
"StatusCode",
".",
"badRequest",
")",
";",
"}"
] | Send an invalid request error response
@param response - response object
@param error - error to send back to the client | [
"Send",
"an",
"invalid",
"request",
"error",
"response"
] | ff295cd1ea9641813369b02ba75bb3bf5ef4c9b8 | https://github.com/ripple/ripple-rest/blob/ff295cd1ea9641813369b02ba75bb3bf5ef4c9b8/server/response-handler.js#L151-L154 |
21,599 | ripple/ripple-rest | server/response-handler.js | internalError | function internalError(response, message, body) {
var content = errorContent(ErrorType.server, message, body);
send(response, content, StatusCode.internalServerError);
} | javascript | function internalError(response, message, body) {
var content = errorContent(ErrorType.server, message, body);
send(response, content, StatusCode.internalServerError);
} | [
"function",
"internalError",
"(",
"response",
",",
"message",
",",
"body",
")",
"{",
"var",
"content",
"=",
"errorContent",
"(",
"ErrorType",
".",
"server",
",",
"message",
",",
"body",
")",
";",
"send",
"(",
"response",
",",
"content",
",",
"StatusCode",
".",
"internalServerError",
")",
";",
"}"
] | Send an internal error response
@param response - response object
@param message - (optional) additional error message
e.g. description for provided error
@param body - (optional) additional body to the response | [
"Send",
"an",
"internal",
"error",
"response"
] | ff295cd1ea9641813369b02ba75bb3bf5ef4c9b8 | https://github.com/ripple/ripple-rest/blob/ff295cd1ea9641813369b02ba75bb3bf5ef4c9b8/server/response-handler.js#L164-L167 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.