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
|
---|---|---|---|---|---|---|---|---|---|---|---|
39,800 | Maciek416/weather-forecast | weather-forecast.js | function($, times, N) {
N = typeof N === 'undefined' ? 24 : N;
return _.chain(times).map(function(time){
// map to back to cheerio'fied object so we can read attr()
return $(time);
}).filter(function(time){
// filter by instantaneous forecasts only
return time.attr("from") == time.attr("to");
}).sortBy(function(time){
// sort by closest to most distant time
var from = new Date(time.attr("from"));
return Math.abs((new Date()).getTime() - from.getTime());
}).first(N).value();
} | javascript | function($, times, N) {
N = typeof N === 'undefined' ? 24 : N;
return _.chain(times).map(function(time){
// map to back to cheerio'fied object so we can read attr()
return $(time);
}).filter(function(time){
// filter by instantaneous forecasts only
return time.attr("from") == time.attr("to");
}).sortBy(function(time){
// sort by closest to most distant time
var from = new Date(time.attr("from"));
return Math.abs((new Date()).getTime() - from.getTime());
}).first(N).value();
} | [
"function",
"(",
"$",
",",
"times",
",",
"N",
")",
"{",
"N",
"=",
"typeof",
"N",
"===",
"'undefined'",
"?",
"24",
":",
"N",
";",
"return",
"_",
".",
"chain",
"(",
"times",
")",
".",
"map",
"(",
"function",
"(",
"time",
")",
"{",
"// map to back to cheerio'fied object so we can read attr()",
"return",
"$",
"(",
"time",
")",
";",
"}",
")",
".",
"filter",
"(",
"function",
"(",
"time",
")",
"{",
"// filter by instantaneous forecasts only",
"return",
"time",
".",
"attr",
"(",
"\"from\"",
")",
"==",
"time",
".",
"attr",
"(",
"\"to\"",
")",
";",
"}",
")",
".",
"sortBy",
"(",
"function",
"(",
"time",
")",
"{",
"// sort by closest to most distant time",
"var",
"from",
"=",
"new",
"Date",
"(",
"time",
".",
"attr",
"(",
"\"from\"",
")",
")",
";",
"return",
"Math",
".",
"abs",
"(",
"(",
"new",
"Date",
"(",
")",
")",
".",
"getTime",
"(",
")",
"-",
"from",
".",
"getTime",
"(",
")",
")",
";",
"}",
")",
".",
"first",
"(",
"N",
")",
".",
"value",
"(",
")",
";",
"}"
]
| return the closest N forecasts in the future to current time with the smallest time range | [
"return",
"the",
"closest",
"N",
"forecasts",
"in",
"the",
"future",
"to",
"current",
"time",
"with",
"the",
"smallest",
"time",
"range"
]
| 634b75545eb0dd4b166b678d7d84b27960622fd5 | https://github.com/Maciek416/weather-forecast/blob/634b75545eb0dd4b166b678d7d84b27960622fd5/weather-forecast.js#L9-L23 |
|
39,801 | Maciek416/weather-forecast | weather-forecast.js | function(time){
var tempC = parseFloat(time.find('temperature').eq(0).attr('value'));
return {
hoursFromNow: Math.ceil(((new Date(time.attr("from"))).getTime() - (new Date()).getTime()) / 1000 / 60 / 60),
// Celcius is kept decimal since met.no returns a pleasant formatted value.
// Fahrenheit is rounded for reasons of laziness.
// TODO: format Fahrenheit value.
tempC: tempC,
tempF: Math.round((9 / 5 * tempC) + 32)
};
} | javascript | function(time){
var tempC = parseFloat(time.find('temperature').eq(0).attr('value'));
return {
hoursFromNow: Math.ceil(((new Date(time.attr("from"))).getTime() - (new Date()).getTime()) / 1000 / 60 / 60),
// Celcius is kept decimal since met.no returns a pleasant formatted value.
// Fahrenheit is rounded for reasons of laziness.
// TODO: format Fahrenheit value.
tempC: tempC,
tempF: Math.round((9 / 5 * tempC) + 32)
};
} | [
"function",
"(",
"time",
")",
"{",
"var",
"tempC",
"=",
"parseFloat",
"(",
"time",
".",
"find",
"(",
"'temperature'",
")",
".",
"eq",
"(",
"0",
")",
".",
"attr",
"(",
"'value'",
")",
")",
";",
"return",
"{",
"hoursFromNow",
":",
"Math",
".",
"ceil",
"(",
"(",
"(",
"new",
"Date",
"(",
"time",
".",
"attr",
"(",
"\"from\"",
")",
")",
")",
".",
"getTime",
"(",
")",
"-",
"(",
"new",
"Date",
"(",
")",
")",
".",
"getTime",
"(",
")",
")",
"/",
"1000",
"/",
"60",
"/",
"60",
")",
",",
"// Celcius is kept decimal since met.no returns a pleasant formatted value. ",
"// Fahrenheit is rounded for reasons of laziness. ",
"// TODO: format Fahrenheit value.",
"tempC",
":",
"tempC",
",",
"tempF",
":",
"Math",
".",
"round",
"(",
"(",
"9",
"/",
"5",
"*",
"tempC",
")",
"+",
"32",
")",
"}",
";",
"}"
]
| return an object with temperature in C and F and a relative ETA in hours for that temperature. | [
"return",
"an",
"object",
"with",
"temperature",
"in",
"C",
"and",
"F",
"and",
"a",
"relative",
"ETA",
"in",
"hours",
"for",
"that",
"temperature",
"."
]
| 634b75545eb0dd4b166b678d7d84b27960622fd5 | https://github.com/Maciek416/weather-forecast/blob/634b75545eb0dd4b166b678d7d84b27960622fd5/weather-forecast.js#L26-L37 |
|
39,802 | Maciek416/weather-forecast | weather-forecast.js | function(lat, lon, done){
var url = "http://api.met.no/weatherapi/locationforecast/1.8/?lat=" + lat + ";lon=" + lon;
request(url, function(error, response, body) {
if (!error && response.statusCode < 400) {
var $ = cheerio.load(body);
var nearbyForecasts = closestInstantForecasts($, $("product time"), FORECASTS_COUNT);
done(nearbyForecasts.map(createForecastItem));
} else {
console.error("error requesting met.no forecast");
done();
}
});
} | javascript | function(lat, lon, done){
var url = "http://api.met.no/weatherapi/locationforecast/1.8/?lat=" + lat + ";lon=" + lon;
request(url, function(error, response, body) {
if (!error && response.statusCode < 400) {
var $ = cheerio.load(body);
var nearbyForecasts = closestInstantForecasts($, $("product time"), FORECASTS_COUNT);
done(nearbyForecasts.map(createForecastItem));
} else {
console.error("error requesting met.no forecast");
done();
}
});
} | [
"function",
"(",
"lat",
",",
"lon",
",",
"done",
")",
"{",
"var",
"url",
"=",
"\"http://api.met.no/weatherapi/locationforecast/1.8/?lat=\"",
"+",
"lat",
"+",
"\";lon=\"",
"+",
"lon",
";",
"request",
"(",
"url",
",",
"function",
"(",
"error",
",",
"response",
",",
"body",
")",
"{",
"if",
"(",
"!",
"error",
"&&",
"response",
".",
"statusCode",
"<",
"400",
")",
"{",
"var",
"$",
"=",
"cheerio",
".",
"load",
"(",
"body",
")",
";",
"var",
"nearbyForecasts",
"=",
"closestInstantForecasts",
"(",
"$",
",",
"$",
"(",
"\"product time\"",
")",
",",
"FORECASTS_COUNT",
")",
";",
"done",
"(",
"nearbyForecasts",
".",
"map",
"(",
"createForecastItem",
")",
")",
";",
"}",
"else",
"{",
"console",
".",
"error",
"(",
"\"error requesting met.no forecast\"",
")",
";",
"done",
"(",
")",
";",
"}",
"}",
")",
";",
"}"
]
| call done with weather forecast results for GPS location lat, lon | [
"call",
"done",
"with",
"weather",
"forecast",
"results",
"for",
"GPS",
"location",
"lat",
"lon"
]
| 634b75545eb0dd4b166b678d7d84b27960622fd5 | https://github.com/Maciek416/weather-forecast/blob/634b75545eb0dd4b166b678d7d84b27960622fd5/weather-forecast.js#L42-L60 |
|
39,803 | Infomaker/cropjs | dist/js/cropjs.js | function(visible) {
var e = document.getElementById('imc_loading');
if (typeof visible == 'undefined') {
return e.classList.contains('loading');
}
if (visible) {
e.classList.add('loading');
}
else {
e.classList.remove('loading');
}
return visible;
} | javascript | function(visible) {
var e = document.getElementById('imc_loading');
if (typeof visible == 'undefined') {
return e.classList.contains('loading');
}
if (visible) {
e.classList.add('loading');
}
else {
e.classList.remove('loading');
}
return visible;
} | [
"function",
"(",
"visible",
")",
"{",
"var",
"e",
"=",
"document",
".",
"getElementById",
"(",
"'imc_loading'",
")",
";",
"if",
"(",
"typeof",
"visible",
"==",
"'undefined'",
")",
"{",
"return",
"e",
".",
"classList",
".",
"contains",
"(",
"'loading'",
")",
";",
"}",
"if",
"(",
"visible",
")",
"{",
"e",
".",
"classList",
".",
"add",
"(",
"'loading'",
")",
";",
"}",
"else",
"{",
"e",
".",
"classList",
".",
"remove",
"(",
"'loading'",
")",
";",
"}",
"return",
"visible",
";",
"}"
]
| Toggle loading spinning indicator | [
"Toggle",
"loading",
"spinning",
"indicator"
]
| 10a84e6d83d07b327cbed3714e42b5ba3bd506b5 | https://github.com/Infomaker/cropjs/blob/10a84e6d83d07b327cbed3714e42b5ba3bd506b5/dist/js/cropjs.js#L477-L492 |
|
39,804 | Infomaker/cropjs | dist/js/cropjs.js | function (crop, setAsCurrent) {
var _this = this;
// Create image container element
var pvDivOuter = document.createElement('div');
pvDivOuter.id = this._image.id + '_' + crop.id;
pvDivOuter.classList.add('imc_preview_image_container');
if (setAsCurrent) {
pvDivOuter.classList.add('active');
}
pvDivOuter.addEventListener(
'click',
function () {
_this.setActiveCrop(crop);
}
);
// Create inner container element
var pvDivInner = document.createElement('div');
pvDivInner.classList.add('imc_preview_image');
var previewHeight = 90; // Dummy default, will be overriden in _renderUpdatedPreview
var previewWidth = IMSoftcrop.Ratio.width(previewHeight, crop.ratio.f);
pvDivInner.style.width = IMSoftcrop.Ratio.width(previewHeight, crop.ratio.f) + 'px';
// Create span (title) element, including warning element
var pvSpan = document.createElement('span');
var pvSpanEm = document.createElement('em');
var pvWarning = document.createElement('i');
pvWarning.className = 'fa fa-warning';
var pvUsed = document.createElement('b');
var pvUsedCrop = crop;
pvUsed.className = 'fa fa-check';
pvUsed.addEventListener(
'click',
function(e) {
_this.toggleCropUsable(pvUsedCrop)
e.preventDefault();
e.stopPropagation();
return false;
}
)
pvSpanEm.appendChild(document.createTextNode(crop.id))
pvSpan.appendChild(pvUsed);
pvSpan.appendChild(pvSpanEm);
pvSpan.appendChild(pvWarning);
// Create image element
var pvImg = document.createElement('img');
pvImg.src = this._image.src;
// Put it together
pvDivInner.appendChild(pvImg);
pvDivInner.appendChild(pvSpan);
pvDivOuter.appendChild(pvDivInner);
this._previewContainer.appendChild(pvDivOuter);
// Render update
this._renderUpdatedPreview(crop);
} | javascript | function (crop, setAsCurrent) {
var _this = this;
// Create image container element
var pvDivOuter = document.createElement('div');
pvDivOuter.id = this._image.id + '_' + crop.id;
pvDivOuter.classList.add('imc_preview_image_container');
if (setAsCurrent) {
pvDivOuter.classList.add('active');
}
pvDivOuter.addEventListener(
'click',
function () {
_this.setActiveCrop(crop);
}
);
// Create inner container element
var pvDivInner = document.createElement('div');
pvDivInner.classList.add('imc_preview_image');
var previewHeight = 90; // Dummy default, will be overriden in _renderUpdatedPreview
var previewWidth = IMSoftcrop.Ratio.width(previewHeight, crop.ratio.f);
pvDivInner.style.width = IMSoftcrop.Ratio.width(previewHeight, crop.ratio.f) + 'px';
// Create span (title) element, including warning element
var pvSpan = document.createElement('span');
var pvSpanEm = document.createElement('em');
var pvWarning = document.createElement('i');
pvWarning.className = 'fa fa-warning';
var pvUsed = document.createElement('b');
var pvUsedCrop = crop;
pvUsed.className = 'fa fa-check';
pvUsed.addEventListener(
'click',
function(e) {
_this.toggleCropUsable(pvUsedCrop)
e.preventDefault();
e.stopPropagation();
return false;
}
)
pvSpanEm.appendChild(document.createTextNode(crop.id))
pvSpan.appendChild(pvUsed);
pvSpan.appendChild(pvSpanEm);
pvSpan.appendChild(pvWarning);
// Create image element
var pvImg = document.createElement('img');
pvImg.src = this._image.src;
// Put it together
pvDivInner.appendChild(pvImg);
pvDivInner.appendChild(pvSpan);
pvDivOuter.appendChild(pvDivInner);
this._previewContainer.appendChild(pvDivOuter);
// Render update
this._renderUpdatedPreview(crop);
} | [
"function",
"(",
"crop",
",",
"setAsCurrent",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"// Create image container element",
"var",
"pvDivOuter",
"=",
"document",
".",
"createElement",
"(",
"'div'",
")",
";",
"pvDivOuter",
".",
"id",
"=",
"this",
".",
"_image",
".",
"id",
"+",
"'_'",
"+",
"crop",
".",
"id",
";",
"pvDivOuter",
".",
"classList",
".",
"add",
"(",
"'imc_preview_image_container'",
")",
";",
"if",
"(",
"setAsCurrent",
")",
"{",
"pvDivOuter",
".",
"classList",
".",
"add",
"(",
"'active'",
")",
";",
"}",
"pvDivOuter",
".",
"addEventListener",
"(",
"'click'",
",",
"function",
"(",
")",
"{",
"_this",
".",
"setActiveCrop",
"(",
"crop",
")",
";",
"}",
")",
";",
"// Create inner container element",
"var",
"pvDivInner",
"=",
"document",
".",
"createElement",
"(",
"'div'",
")",
";",
"pvDivInner",
".",
"classList",
".",
"add",
"(",
"'imc_preview_image'",
")",
";",
"var",
"previewHeight",
"=",
"90",
";",
"// Dummy default, will be overriden in _renderUpdatedPreview",
"var",
"previewWidth",
"=",
"IMSoftcrop",
".",
"Ratio",
".",
"width",
"(",
"previewHeight",
",",
"crop",
".",
"ratio",
".",
"f",
")",
";",
"pvDivInner",
".",
"style",
".",
"width",
"=",
"IMSoftcrop",
".",
"Ratio",
".",
"width",
"(",
"previewHeight",
",",
"crop",
".",
"ratio",
".",
"f",
")",
"+",
"'px'",
";",
"// Create span (title) element, including warning element",
"var",
"pvSpan",
"=",
"document",
".",
"createElement",
"(",
"'span'",
")",
";",
"var",
"pvSpanEm",
"=",
"document",
".",
"createElement",
"(",
"'em'",
")",
";",
"var",
"pvWarning",
"=",
"document",
".",
"createElement",
"(",
"'i'",
")",
";",
"pvWarning",
".",
"className",
"=",
"'fa fa-warning'",
";",
"var",
"pvUsed",
"=",
"document",
".",
"createElement",
"(",
"'b'",
")",
";",
"var",
"pvUsedCrop",
"=",
"crop",
";",
"pvUsed",
".",
"className",
"=",
"'fa fa-check'",
";",
"pvUsed",
".",
"addEventListener",
"(",
"'click'",
",",
"function",
"(",
"e",
")",
"{",
"_this",
".",
"toggleCropUsable",
"(",
"pvUsedCrop",
")",
"e",
".",
"preventDefault",
"(",
")",
";",
"e",
".",
"stopPropagation",
"(",
")",
";",
"return",
"false",
";",
"}",
")",
"pvSpanEm",
".",
"appendChild",
"(",
"document",
".",
"createTextNode",
"(",
"crop",
".",
"id",
")",
")",
"pvSpan",
".",
"appendChild",
"(",
"pvUsed",
")",
";",
"pvSpan",
".",
"appendChild",
"(",
"pvSpanEm",
")",
";",
"pvSpan",
".",
"appendChild",
"(",
"pvWarning",
")",
";",
"// Create image element",
"var",
"pvImg",
"=",
"document",
".",
"createElement",
"(",
"'img'",
")",
";",
"pvImg",
".",
"src",
"=",
"this",
".",
"_image",
".",
"src",
";",
"// Put it together",
"pvDivInner",
".",
"appendChild",
"(",
"pvImg",
")",
";",
"pvDivInner",
".",
"appendChild",
"(",
"pvSpan",
")",
";",
"pvDivOuter",
".",
"appendChild",
"(",
"pvDivInner",
")",
";",
"this",
".",
"_previewContainer",
".",
"appendChild",
"(",
"pvDivOuter",
")",
";",
"// Render update",
"this",
".",
"_renderUpdatedPreview",
"(",
"crop",
")",
";",
"}"
]
| Add and render specific crop preview
@param crop
@param setAsCurrent
@private | [
"Add",
"and",
"render",
"specific",
"crop",
"preview"
]
| 10a84e6d83d07b327cbed3714e42b5ba3bd506b5 | https://github.com/Infomaker/cropjs/blob/10a84e6d83d07b327cbed3714e42b5ba3bd506b5/dist/js/cropjs.js#L501-L566 |
|
39,805 | Infomaker/cropjs | dist/js/cropjs.js | function (crop) {
var pvDiv = document.getElementById(this._image.id + '_' + crop.id);
if (pvDiv == null || typeof pvDiv != 'object') {
return;
}
var pvDivInner = pvDiv.getElementsByTagName('DIV')[0]
var pvImg = pvDiv.getElementsByTagName('IMG')[0];
var previewHeight = window.getComputedStyle(pvDivInner).height.slice(0, -2)
var imgDim = this._image.getDimensions();
var previewWidth = IMSoftcrop.Ratio.width(previewHeight, crop.ratio.f);
pvDivInner.style.width = previewWidth + 'px';
var cropDim = crop.getDimensions();
var cropRatio = previewWidth / cropDim.w;
pvImg.style.height = imgDim.h * cropRatio + 'px';
pvImg.style.marginTop = '-' + cropDim.y * cropRatio + 'px';
pvImg.style.marginLeft = '-' + cropDim.x * cropRatio + 'px';
if (crop.autoCropWarning == true) {
pvDiv.classList.add('warning');
}
else {
pvDiv.classList.remove('warning');
}
if (crop.usable == true) {
pvDiv.classList.add('usable');
pvDiv.classList.remove('unusable');
}
else {
pvDiv.classList.add('unusable');
pvDiv.classList.remove('usable');
}
} | javascript | function (crop) {
var pvDiv = document.getElementById(this._image.id + '_' + crop.id);
if (pvDiv == null || typeof pvDiv != 'object') {
return;
}
var pvDivInner = pvDiv.getElementsByTagName('DIV')[0]
var pvImg = pvDiv.getElementsByTagName('IMG')[0];
var previewHeight = window.getComputedStyle(pvDivInner).height.slice(0, -2)
var imgDim = this._image.getDimensions();
var previewWidth = IMSoftcrop.Ratio.width(previewHeight, crop.ratio.f);
pvDivInner.style.width = previewWidth + 'px';
var cropDim = crop.getDimensions();
var cropRatio = previewWidth / cropDim.w;
pvImg.style.height = imgDim.h * cropRatio + 'px';
pvImg.style.marginTop = '-' + cropDim.y * cropRatio + 'px';
pvImg.style.marginLeft = '-' + cropDim.x * cropRatio + 'px';
if (crop.autoCropWarning == true) {
pvDiv.classList.add('warning');
}
else {
pvDiv.classList.remove('warning');
}
if (crop.usable == true) {
pvDiv.classList.add('usable');
pvDiv.classList.remove('unusable');
}
else {
pvDiv.classList.add('unusable');
pvDiv.classList.remove('usable');
}
} | [
"function",
"(",
"crop",
")",
"{",
"var",
"pvDiv",
"=",
"document",
".",
"getElementById",
"(",
"this",
".",
"_image",
".",
"id",
"+",
"'_'",
"+",
"crop",
".",
"id",
")",
";",
"if",
"(",
"pvDiv",
"==",
"null",
"||",
"typeof",
"pvDiv",
"!=",
"'object'",
")",
"{",
"return",
";",
"}",
"var",
"pvDivInner",
"=",
"pvDiv",
".",
"getElementsByTagName",
"(",
"'DIV'",
")",
"[",
"0",
"]",
"var",
"pvImg",
"=",
"pvDiv",
".",
"getElementsByTagName",
"(",
"'IMG'",
")",
"[",
"0",
"]",
";",
"var",
"previewHeight",
"=",
"window",
".",
"getComputedStyle",
"(",
"pvDivInner",
")",
".",
"height",
".",
"slice",
"(",
"0",
",",
"-",
"2",
")",
"var",
"imgDim",
"=",
"this",
".",
"_image",
".",
"getDimensions",
"(",
")",
";",
"var",
"previewWidth",
"=",
"IMSoftcrop",
".",
"Ratio",
".",
"width",
"(",
"previewHeight",
",",
"crop",
".",
"ratio",
".",
"f",
")",
";",
"pvDivInner",
".",
"style",
".",
"width",
"=",
"previewWidth",
"+",
"'px'",
";",
"var",
"cropDim",
"=",
"crop",
".",
"getDimensions",
"(",
")",
";",
"var",
"cropRatio",
"=",
"previewWidth",
"/",
"cropDim",
".",
"w",
";",
"pvImg",
".",
"style",
".",
"height",
"=",
"imgDim",
".",
"h",
"*",
"cropRatio",
"+",
"'px'",
";",
"pvImg",
".",
"style",
".",
"marginTop",
"=",
"'-'",
"+",
"cropDim",
".",
"y",
"*",
"cropRatio",
"+",
"'px'",
";",
"pvImg",
".",
"style",
".",
"marginLeft",
"=",
"'-'",
"+",
"cropDim",
".",
"x",
"*",
"cropRatio",
"+",
"'px'",
";",
"if",
"(",
"crop",
".",
"autoCropWarning",
"==",
"true",
")",
"{",
"pvDiv",
".",
"classList",
".",
"add",
"(",
"'warning'",
")",
";",
"}",
"else",
"{",
"pvDiv",
".",
"classList",
".",
"remove",
"(",
"'warning'",
")",
";",
"}",
"if",
"(",
"crop",
".",
"usable",
"==",
"true",
")",
"{",
"pvDiv",
".",
"classList",
".",
"add",
"(",
"'usable'",
")",
";",
"pvDiv",
".",
"classList",
".",
"remove",
"(",
"'unusable'",
")",
";",
"}",
"else",
"{",
"pvDiv",
".",
"classList",
".",
"add",
"(",
"'unusable'",
")",
";",
"pvDiv",
".",
"classList",
".",
"remove",
"(",
"'usable'",
")",
";",
"}",
"}"
]
| Update rendering of current crop preview
@param crop
@private | [
"Update",
"rendering",
"of",
"current",
"crop",
"preview"
]
| 10a84e6d83d07b327cbed3714e42b5ba3bd506b5 | https://github.com/Infomaker/cropjs/blob/10a84e6d83d07b327cbed3714e42b5ba3bd506b5/dist/js/cropjs.js#L574-L610 |
|
39,806 | Infomaker/cropjs | dist/js/cropjs.js | function (canvas) {
var c = canvas || this._canvas;
var ctx = c.getContext('2d');
var devicePixelRatio = window.devicePixelRatio || 1;
var backingStoreRatio =
ctx.webkitBackingStorePixelRatio ||
ctx.mozBackingStorePixelRatio ||
ctx.msBackingStorePixelRatio ||
ctx.oBackingStorePixelRatio ||
ctx.backingStorePixelRatio || 1;
var ratio = devicePixelRatio / backingStoreRatio;
if (devicePixelRatio !== backingStoreRatio) {
var oldWidth = this._container.clientWidth;
var oldHeight = this._container.clientHeight;
c.width = oldWidth * ratio;
c.height = oldHeight * ratio;
c.style.width = oldWidth + 'px';
c.style.height = oldHeight + 'px';
// now scale the context to counter the fact that we've
// manually scaled our canvas element
ctx.scale(ratio, ratio);
this._scale = ratio;
}
else {
c.width = this._container.clientWidth;
c.height = this._container.clientHeight;
}
} | javascript | function (canvas) {
var c = canvas || this._canvas;
var ctx = c.getContext('2d');
var devicePixelRatio = window.devicePixelRatio || 1;
var backingStoreRatio =
ctx.webkitBackingStorePixelRatio ||
ctx.mozBackingStorePixelRatio ||
ctx.msBackingStorePixelRatio ||
ctx.oBackingStorePixelRatio ||
ctx.backingStorePixelRatio || 1;
var ratio = devicePixelRatio / backingStoreRatio;
if (devicePixelRatio !== backingStoreRatio) {
var oldWidth = this._container.clientWidth;
var oldHeight = this._container.clientHeight;
c.width = oldWidth * ratio;
c.height = oldHeight * ratio;
c.style.width = oldWidth + 'px';
c.style.height = oldHeight + 'px';
// now scale the context to counter the fact that we've
// manually scaled our canvas element
ctx.scale(ratio, ratio);
this._scale = ratio;
}
else {
c.width = this._container.clientWidth;
c.height = this._container.clientHeight;
}
} | [
"function",
"(",
"canvas",
")",
"{",
"var",
"c",
"=",
"canvas",
"||",
"this",
".",
"_canvas",
";",
"var",
"ctx",
"=",
"c",
".",
"getContext",
"(",
"'2d'",
")",
";",
"var",
"devicePixelRatio",
"=",
"window",
".",
"devicePixelRatio",
"||",
"1",
";",
"var",
"backingStoreRatio",
"=",
"ctx",
".",
"webkitBackingStorePixelRatio",
"||",
"ctx",
".",
"mozBackingStorePixelRatio",
"||",
"ctx",
".",
"msBackingStorePixelRatio",
"||",
"ctx",
".",
"oBackingStorePixelRatio",
"||",
"ctx",
".",
"backingStorePixelRatio",
"||",
"1",
";",
"var",
"ratio",
"=",
"devicePixelRatio",
"/",
"backingStoreRatio",
";",
"if",
"(",
"devicePixelRatio",
"!==",
"backingStoreRatio",
")",
"{",
"var",
"oldWidth",
"=",
"this",
".",
"_container",
".",
"clientWidth",
";",
"var",
"oldHeight",
"=",
"this",
".",
"_container",
".",
"clientHeight",
";",
"c",
".",
"width",
"=",
"oldWidth",
"*",
"ratio",
";",
"c",
".",
"height",
"=",
"oldHeight",
"*",
"ratio",
";",
"c",
".",
"style",
".",
"width",
"=",
"oldWidth",
"+",
"'px'",
";",
"c",
".",
"style",
".",
"height",
"=",
"oldHeight",
"+",
"'px'",
";",
"// now scale the context to counter the fact that we've",
"// manually scaled our canvas element",
"ctx",
".",
"scale",
"(",
"ratio",
",",
"ratio",
")",
";",
"this",
".",
"_scale",
"=",
"ratio",
";",
"}",
"else",
"{",
"c",
".",
"width",
"=",
"this",
".",
"_container",
".",
"clientWidth",
";",
"c",
".",
"height",
"=",
"this",
".",
"_container",
".",
"clientHeight",
";",
"}",
"}"
]
| Adjust canvas for pixel ratio
@param canvas | [
"Adjust",
"canvas",
"for",
"pixel",
"ratio"
]
| 10a84e6d83d07b327cbed3714e42b5ba3bd506b5 | https://github.com/Infomaker/cropjs/blob/10a84e6d83d07b327cbed3714e42b5ba3bd506b5/dist/js/cropjs.js#L670-L701 |
|
39,807 | Infomaker/cropjs | dist/js/cropjs.js | function (url, onImageReady, applyAutocrop) {
var _this = this;
this.toggleLoadingImage(true);
this.clear();
this._applyAutocrop = (applyAutocrop !== false);
this._image = new IMSoftcrop.Image(
IMSoftcrop.Ratio.hashFnv32a(url),
this
);
this._image.load(
url,
function () {
_this.setZoomToImage(false);
_this.centerImage(false);
_this.updateImageInfo(false);
if (_this._autocrop) {
_this.detectDetails();
_this.detectFaces();
}
else {
_this.toggleLoadingImage(false);
}
_this.applySoftcrops();
_this.redraw();
if (typeof onImageReady === 'function') {
onImageReady.call(_this, _this._image);
}
}
);
} | javascript | function (url, onImageReady, applyAutocrop) {
var _this = this;
this.toggleLoadingImage(true);
this.clear();
this._applyAutocrop = (applyAutocrop !== false);
this._image = new IMSoftcrop.Image(
IMSoftcrop.Ratio.hashFnv32a(url),
this
);
this._image.load(
url,
function () {
_this.setZoomToImage(false);
_this.centerImage(false);
_this.updateImageInfo(false);
if (_this._autocrop) {
_this.detectDetails();
_this.detectFaces();
}
else {
_this.toggleLoadingImage(false);
}
_this.applySoftcrops();
_this.redraw();
if (typeof onImageReady === 'function') {
onImageReady.call(_this, _this._image);
}
}
);
} | [
"function",
"(",
"url",
",",
"onImageReady",
",",
"applyAutocrop",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"this",
".",
"toggleLoadingImage",
"(",
"true",
")",
";",
"this",
".",
"clear",
"(",
")",
";",
"this",
".",
"_applyAutocrop",
"=",
"(",
"applyAutocrop",
"!==",
"false",
")",
";",
"this",
".",
"_image",
"=",
"new",
"IMSoftcrop",
".",
"Image",
"(",
"IMSoftcrop",
".",
"Ratio",
".",
"hashFnv32a",
"(",
"url",
")",
",",
"this",
")",
";",
"this",
".",
"_image",
".",
"load",
"(",
"url",
",",
"function",
"(",
")",
"{",
"_this",
".",
"setZoomToImage",
"(",
"false",
")",
";",
"_this",
".",
"centerImage",
"(",
"false",
")",
";",
"_this",
".",
"updateImageInfo",
"(",
"false",
")",
";",
"if",
"(",
"_this",
".",
"_autocrop",
")",
"{",
"_this",
".",
"detectDetails",
"(",
")",
";",
"_this",
".",
"detectFaces",
"(",
")",
";",
"}",
"else",
"{",
"_this",
".",
"toggleLoadingImage",
"(",
"false",
")",
";",
"}",
"_this",
".",
"applySoftcrops",
"(",
")",
";",
"_this",
".",
"redraw",
"(",
")",
";",
"if",
"(",
"typeof",
"onImageReady",
"===",
"'function'",
")",
"{",
"onImageReady",
".",
"call",
"(",
"_this",
",",
"_this",
".",
"_image",
")",
";",
"}",
"}",
")",
";",
"}"
]
| Load image from url
@param url
@param onImageReady Callback after image has been loaded
@param autocropImage Optional, default true, if autocrops should be applied | [
"Load",
"image",
"from",
"url"
]
| 10a84e6d83d07b327cbed3714e42b5ba3bd506b5 | https://github.com/Infomaker/cropjs/blob/10a84e6d83d07b327cbed3714e42b5ba3bd506b5/dist/js/cropjs.js#L710-L745 |
|
39,808 | Infomaker/cropjs | dist/js/cropjs.js | function() {
var data = {
src: this._image.src,
width: this._image.w,
height: this._image.h,
crops: []
};
for(var n = 0; n < this._image.crops.length; n++) {
data.crops.push({
id: this._image.crops[n].id,
x: Math.round(this._image.crops[n].x),
y: Math.round(this._image.crops[n].y),
width: Math.round(this._image.crops[n].w),
height: Math.round(this._image.crops[n].h),
usable: this._image.crops[n].usable
});
}
return data;
} | javascript | function() {
var data = {
src: this._image.src,
width: this._image.w,
height: this._image.h,
crops: []
};
for(var n = 0; n < this._image.crops.length; n++) {
data.crops.push({
id: this._image.crops[n].id,
x: Math.round(this._image.crops[n].x),
y: Math.round(this._image.crops[n].y),
width: Math.round(this._image.crops[n].w),
height: Math.round(this._image.crops[n].h),
usable: this._image.crops[n].usable
});
}
return data;
} | [
"function",
"(",
")",
"{",
"var",
"data",
"=",
"{",
"src",
":",
"this",
".",
"_image",
".",
"src",
",",
"width",
":",
"this",
".",
"_image",
".",
"w",
",",
"height",
":",
"this",
".",
"_image",
".",
"h",
",",
"crops",
":",
"[",
"]",
"}",
";",
"for",
"(",
"var",
"n",
"=",
"0",
";",
"n",
"<",
"this",
".",
"_image",
".",
"crops",
".",
"length",
";",
"n",
"++",
")",
"{",
"data",
".",
"crops",
".",
"push",
"(",
"{",
"id",
":",
"this",
".",
"_image",
".",
"crops",
"[",
"n",
"]",
".",
"id",
",",
"x",
":",
"Math",
".",
"round",
"(",
"this",
".",
"_image",
".",
"crops",
"[",
"n",
"]",
".",
"x",
")",
",",
"y",
":",
"Math",
".",
"round",
"(",
"this",
".",
"_image",
".",
"crops",
"[",
"n",
"]",
".",
"y",
")",
",",
"width",
":",
"Math",
".",
"round",
"(",
"this",
".",
"_image",
".",
"crops",
"[",
"n",
"]",
".",
"w",
")",
",",
"height",
":",
"Math",
".",
"round",
"(",
"this",
".",
"_image",
".",
"crops",
"[",
"n",
"]",
".",
"h",
")",
",",
"usable",
":",
"this",
".",
"_image",
".",
"crops",
"[",
"n",
"]",
".",
"usable",
"}",
")",
";",
"}",
"return",
"data",
";",
"}"
]
| Get soft crop data for image | [
"Get",
"soft",
"crop",
"data",
"for",
"image"
]
| 10a84e6d83d07b327cbed3714e42b5ba3bd506b5 | https://github.com/Infomaker/cropjs/blob/10a84e6d83d07b327cbed3714e42b5ba3bd506b5/dist/js/cropjs.js#L801-L821 |
|
39,809 | Infomaker/cropjs | dist/js/cropjs.js | function() {
if (this._image instanceof IMSoftcrop.Image == false || !this._image.ready) {
return;
}
// Always make sure all crops are added
for(var n = 0; n < this._crops.length; n++) {
var crop = this._image.getSoftcrop(this._crops[n].id);
if (crop == null) {
var crop = this._image.addSoftcrop(
this._crops[n].id,
this._crops[n].setAsCurrent,
this._crops[n].hRatio,
this._crops[n].vRatio,
this._crops[n].x,
this._crops[n].y,
this._crops[n].exact,
this._crops[n].usable
);
if (this._autocrop) {
this._image.autocrop();
}
this._renderNewCropPreview(crop, this._crops[n].setAsCurrent);
}
if (this._crops[n].setAsCurrent) {
this.setActiveCrop(crop);
}
}
} | javascript | function() {
if (this._image instanceof IMSoftcrop.Image == false || !this._image.ready) {
return;
}
// Always make sure all crops are added
for(var n = 0; n < this._crops.length; n++) {
var crop = this._image.getSoftcrop(this._crops[n].id);
if (crop == null) {
var crop = this._image.addSoftcrop(
this._crops[n].id,
this._crops[n].setAsCurrent,
this._crops[n].hRatio,
this._crops[n].vRatio,
this._crops[n].x,
this._crops[n].y,
this._crops[n].exact,
this._crops[n].usable
);
if (this._autocrop) {
this._image.autocrop();
}
this._renderNewCropPreview(crop, this._crops[n].setAsCurrent);
}
if (this._crops[n].setAsCurrent) {
this.setActiveCrop(crop);
}
}
} | [
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"_image",
"instanceof",
"IMSoftcrop",
".",
"Image",
"==",
"false",
"||",
"!",
"this",
".",
"_image",
".",
"ready",
")",
"{",
"return",
";",
"}",
"// Always make sure all crops are added",
"for",
"(",
"var",
"n",
"=",
"0",
";",
"n",
"<",
"this",
".",
"_crops",
".",
"length",
";",
"n",
"++",
")",
"{",
"var",
"crop",
"=",
"this",
".",
"_image",
".",
"getSoftcrop",
"(",
"this",
".",
"_crops",
"[",
"n",
"]",
".",
"id",
")",
";",
"if",
"(",
"crop",
"==",
"null",
")",
"{",
"var",
"crop",
"=",
"this",
".",
"_image",
".",
"addSoftcrop",
"(",
"this",
".",
"_crops",
"[",
"n",
"]",
".",
"id",
",",
"this",
".",
"_crops",
"[",
"n",
"]",
".",
"setAsCurrent",
",",
"this",
".",
"_crops",
"[",
"n",
"]",
".",
"hRatio",
",",
"this",
".",
"_crops",
"[",
"n",
"]",
".",
"vRatio",
",",
"this",
".",
"_crops",
"[",
"n",
"]",
".",
"x",
",",
"this",
".",
"_crops",
"[",
"n",
"]",
".",
"y",
",",
"this",
".",
"_crops",
"[",
"n",
"]",
".",
"exact",
",",
"this",
".",
"_crops",
"[",
"n",
"]",
".",
"usable",
")",
";",
"if",
"(",
"this",
".",
"_autocrop",
")",
"{",
"this",
".",
"_image",
".",
"autocrop",
"(",
")",
";",
"}",
"this",
".",
"_renderNewCropPreview",
"(",
"crop",
",",
"this",
".",
"_crops",
"[",
"n",
"]",
".",
"setAsCurrent",
")",
";",
"}",
"if",
"(",
"this",
".",
"_crops",
"[",
"n",
"]",
".",
"setAsCurrent",
")",
"{",
"this",
".",
"setActiveCrop",
"(",
"crop",
")",
";",
"}",
"}",
"}"
]
| Apply all soft crops to image | [
"Apply",
"all",
"soft",
"crops",
"to",
"image"
]
| 10a84e6d83d07b327cbed3714e42b5ba3bd506b5 | https://github.com/Infomaker/cropjs/blob/10a84e6d83d07b327cbed3714e42b5ba3bd506b5/dist/js/cropjs.js#L826-L859 |
|
39,810 | Infomaker/cropjs | dist/js/cropjs.js | function (crop) {
if (crop instanceof IMSoftcrop.Softcrop !== true) {
return;
}
var div = document.getElementById(this._image.id + '_' + crop.id);
var divs = this._previewContainer.getElementsByClassName('imc_preview_image_container');
for (var n = 0; n < divs.length; n++) {
divs[n].classList.remove('active');
}
div.classList.add('active');
this._crop = crop;
this._image.setActiveCrop(crop);
this._cropLockedToggle.on = crop.locked;
this._cropUsableToggle.on = crop.usable;
this.redraw();
this.updateImageInfo(true);
} | javascript | function (crop) {
if (crop instanceof IMSoftcrop.Softcrop !== true) {
return;
}
var div = document.getElementById(this._image.id + '_' + crop.id);
var divs = this._previewContainer.getElementsByClassName('imc_preview_image_container');
for (var n = 0; n < divs.length; n++) {
divs[n].classList.remove('active');
}
div.classList.add('active');
this._crop = crop;
this._image.setActiveCrop(crop);
this._cropLockedToggle.on = crop.locked;
this._cropUsableToggle.on = crop.usable;
this.redraw();
this.updateImageInfo(true);
} | [
"function",
"(",
"crop",
")",
"{",
"if",
"(",
"crop",
"instanceof",
"IMSoftcrop",
".",
"Softcrop",
"!==",
"true",
")",
"{",
"return",
";",
"}",
"var",
"div",
"=",
"document",
".",
"getElementById",
"(",
"this",
".",
"_image",
".",
"id",
"+",
"'_'",
"+",
"crop",
".",
"id",
")",
";",
"var",
"divs",
"=",
"this",
".",
"_previewContainer",
".",
"getElementsByClassName",
"(",
"'imc_preview_image_container'",
")",
";",
"for",
"(",
"var",
"n",
"=",
"0",
";",
"n",
"<",
"divs",
".",
"length",
";",
"n",
"++",
")",
"{",
"divs",
"[",
"n",
"]",
".",
"classList",
".",
"remove",
"(",
"'active'",
")",
";",
"}",
"div",
".",
"classList",
".",
"add",
"(",
"'active'",
")",
";",
"this",
".",
"_crop",
"=",
"crop",
";",
"this",
".",
"_image",
".",
"setActiveCrop",
"(",
"crop",
")",
";",
"this",
".",
"_cropLockedToggle",
".",
"on",
"=",
"crop",
".",
"locked",
";",
"this",
".",
"_cropUsableToggle",
".",
"on",
"=",
"crop",
".",
"usable",
";",
"this",
".",
"redraw",
"(",
")",
";",
"this",
".",
"updateImageInfo",
"(",
"true",
")",
";",
"}"
]
| Set active crop
@param crop | [
"Set",
"active",
"crop"
]
| 10a84e6d83d07b327cbed3714e42b5ba3bd506b5 | https://github.com/Infomaker/cropjs/blob/10a84e6d83d07b327cbed3714e42b5ba3bd506b5/dist/js/cropjs.js#L865-L884 |
|
39,811 | Infomaker/cropjs | dist/js/cropjs.js | function(crop) {
if(typeof crop === 'undefined') {
crop = this._crop;
}
crop.usable = !crop.usable;
this._renderUpdatedPreview(crop);
if (crop.id === this._crop.id) {
this._cropUsableToggle.on = crop.usable;
}
} | javascript | function(crop) {
if(typeof crop === 'undefined') {
crop = this._crop;
}
crop.usable = !crop.usable;
this._renderUpdatedPreview(crop);
if (crop.id === this._crop.id) {
this._cropUsableToggle.on = crop.usable;
}
} | [
"function",
"(",
"crop",
")",
"{",
"if",
"(",
"typeof",
"crop",
"===",
"'undefined'",
")",
"{",
"crop",
"=",
"this",
".",
"_crop",
";",
"}",
"crop",
".",
"usable",
"=",
"!",
"crop",
".",
"usable",
";",
"this",
".",
"_renderUpdatedPreview",
"(",
"crop",
")",
";",
"if",
"(",
"crop",
".",
"id",
"===",
"this",
".",
"_crop",
".",
"id",
")",
"{",
"this",
".",
"_cropUsableToggle",
".",
"on",
"=",
"crop",
".",
"usable",
";",
"}",
"}"
]
| Toggle a specified crops usable field, or the current crop if left out
@param crop | [
"Toggle",
"a",
"specified",
"crops",
"usable",
"field",
"or",
"the",
"current",
"crop",
"if",
"left",
"out"
]
| 10a84e6d83d07b327cbed3714e42b5ba3bd506b5 | https://github.com/Infomaker/cropjs/blob/10a84e6d83d07b327cbed3714e42b5ba3bd506b5/dist/js/cropjs.js#L890-L900 |
|
39,812 | Infomaker/cropjs | dist/js/cropjs.js | function() {
if (this._image instanceof IMSoftcrop.Image == false) {
return;
}
this._image.clear();
this._crops = [];
this._crop = undefined;
this._image = undefined;
this._previewContainer.innerHTML = '';
this.redraw();
} | javascript | function() {
if (this._image instanceof IMSoftcrop.Image == false) {
return;
}
this._image.clear();
this._crops = [];
this._crop = undefined;
this._image = undefined;
this._previewContainer.innerHTML = '';
this.redraw();
} | [
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"_image",
"instanceof",
"IMSoftcrop",
".",
"Image",
"==",
"false",
")",
"{",
"return",
";",
"}",
"this",
".",
"_image",
".",
"clear",
"(",
")",
";",
"this",
".",
"_crops",
"=",
"[",
"]",
";",
"this",
".",
"_crop",
"=",
"undefined",
";",
"this",
".",
"_image",
"=",
"undefined",
";",
"this",
".",
"_previewContainer",
".",
"innerHTML",
"=",
"''",
";",
"this",
".",
"redraw",
"(",
")",
";",
"}"
]
| Clear image and all image crops | [
"Clear",
"image",
"and",
"all",
"image",
"crops"
]
| 10a84e6d83d07b327cbed3714e42b5ba3bd506b5 | https://github.com/Infomaker/cropjs/blob/10a84e6d83d07b327cbed3714e42b5ba3bd506b5/dist/js/cropjs.js#L905-L916 |
|
39,813 | Infomaker/cropjs | dist/js/cropjs.js | function() {
if (this._autocrop && this._applyAutocrop) {
if (!this.toggleLoadingImage()) {
this.toggleLoadingImage(true)
}
if (this._image.autocrop()) {
this.redraw();
}
}
if (this._waitForWorkers == 0) {
this.toggleLoadingImage(false);
}
} | javascript | function() {
if (this._autocrop && this._applyAutocrop) {
if (!this.toggleLoadingImage()) {
this.toggleLoadingImage(true)
}
if (this._image.autocrop()) {
this.redraw();
}
}
if (this._waitForWorkers == 0) {
this.toggleLoadingImage(false);
}
} | [
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"_autocrop",
"&&",
"this",
".",
"_applyAutocrop",
")",
"{",
"if",
"(",
"!",
"this",
".",
"toggleLoadingImage",
"(",
")",
")",
"{",
"this",
".",
"toggleLoadingImage",
"(",
"true",
")",
"}",
"if",
"(",
"this",
".",
"_image",
".",
"autocrop",
"(",
")",
")",
"{",
"this",
".",
"redraw",
"(",
")",
";",
"}",
"}",
"if",
"(",
"this",
".",
"_waitForWorkers",
"==",
"0",
")",
"{",
"this",
".",
"toggleLoadingImage",
"(",
"false",
")",
";",
"}",
"}"
]
| Auto crop images | [
"Auto",
"crop",
"images"
]
| 10a84e6d83d07b327cbed3714e42b5ba3bd506b5 | https://github.com/Infomaker/cropjs/blob/10a84e6d83d07b327cbed3714e42b5ba3bd506b5/dist/js/cropjs.js#L922-L936 |
|
39,814 | Infomaker/cropjs | dist/js/cropjs.js | function() {
if (!this._image instanceof IMSoftcrop.Image || !this._image.ready) {
return;
}
var body = document.getElementsByTagName('body');
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
canvas.style.display = 'none';
body[0].appendChild(canvas);
canvas.width = this._image.w;
canvas.height = this._image.h;
canvas.style.width = this._image.w + 'px';
canvas.style.height = this._image.h + 'px';
ctx.drawImage(
this._image.image,
0, 0,
this._image.w, this._image.h
);
var imageData = ctx.getImageData(0, 0, this._image.w, this._image.h);
// Cleanup references
ctx = null;
body[0].removeChild(canvas);
canvas = null;
body[0] = null;
body = null;
return imageData;
} | javascript | function() {
if (!this._image instanceof IMSoftcrop.Image || !this._image.ready) {
return;
}
var body = document.getElementsByTagName('body');
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
canvas.style.display = 'none';
body[0].appendChild(canvas);
canvas.width = this._image.w;
canvas.height = this._image.h;
canvas.style.width = this._image.w + 'px';
canvas.style.height = this._image.h + 'px';
ctx.drawImage(
this._image.image,
0, 0,
this._image.w, this._image.h
);
var imageData = ctx.getImageData(0, 0, this._image.w, this._image.h);
// Cleanup references
ctx = null;
body[0].removeChild(canvas);
canvas = null;
body[0] = null;
body = null;
return imageData;
} | [
"function",
"(",
")",
"{",
"if",
"(",
"!",
"this",
".",
"_image",
"instanceof",
"IMSoftcrop",
".",
"Image",
"||",
"!",
"this",
".",
"_image",
".",
"ready",
")",
"{",
"return",
";",
"}",
"var",
"body",
"=",
"document",
".",
"getElementsByTagName",
"(",
"'body'",
")",
";",
"var",
"canvas",
"=",
"document",
".",
"createElement",
"(",
"'canvas'",
")",
";",
"var",
"ctx",
"=",
"canvas",
".",
"getContext",
"(",
"'2d'",
")",
";",
"canvas",
".",
"style",
".",
"display",
"=",
"'none'",
";",
"body",
"[",
"0",
"]",
".",
"appendChild",
"(",
"canvas",
")",
";",
"canvas",
".",
"width",
"=",
"this",
".",
"_image",
".",
"w",
";",
"canvas",
".",
"height",
"=",
"this",
".",
"_image",
".",
"h",
";",
"canvas",
".",
"style",
".",
"width",
"=",
"this",
".",
"_image",
".",
"w",
"+",
"'px'",
";",
"canvas",
".",
"style",
".",
"height",
"=",
"this",
".",
"_image",
".",
"h",
"+",
"'px'",
";",
"ctx",
".",
"drawImage",
"(",
"this",
".",
"_image",
".",
"image",
",",
"0",
",",
"0",
",",
"this",
".",
"_image",
".",
"w",
",",
"this",
".",
"_image",
".",
"h",
")",
";",
"var",
"imageData",
"=",
"ctx",
".",
"getImageData",
"(",
"0",
",",
"0",
",",
"this",
".",
"_image",
".",
"w",
",",
"this",
".",
"_image",
".",
"h",
")",
";",
"// Cleanup references",
"ctx",
"=",
"null",
";",
"body",
"[",
"0",
"]",
".",
"removeChild",
"(",
"canvas",
")",
";",
"canvas",
"=",
"null",
";",
"body",
"[",
"0",
"]",
"=",
"null",
";",
"body",
"=",
"null",
";",
"return",
"imageData",
";",
"}"
]
| Create temporary canvas in image size and extract image data
@returns {ImageData} | [
"Create",
"temporary",
"canvas",
"in",
"image",
"size",
"and",
"extract",
"image",
"data"
]
| 10a84e6d83d07b327cbed3714e42b5ba3bd506b5 | https://github.com/Infomaker/cropjs/blob/10a84e6d83d07b327cbed3714e42b5ba3bd506b5/dist/js/cropjs.js#L942-L975 |
|
39,815 | Infomaker/cropjs | dist/js/cropjs.js | function() {
if (!this._image instanceof IMSoftcrop.Image || !this._image.ready) {
return;
}
var _this = this,
imageData = this.getImageData();
this._waitForWorkers++;
if (window.Worker) {
// If workers are available, thread detection of faces
var detectWorker = new Worker(this._detectWorkerUrl);
detectWorker.postMessage([
'details',
imageData,
this._image.w,
this._image.h,
this._detectThreshold
]);
detectWorker.onmessage = function(e) {
_this.addDetectedDetails(e.data);
_this._waitForWorkers--;
_this.autocropImages();
};
}
else {
// Fallback to non threaded
var data = tracking.Fast.findCorners(
tracking.Image.grayscale(
imageData.data,
this._image.w,
this._image.h
),
this._image.w,
this._image.h,
this._detectThreshold
);
this.addDetectedDetails(data);
this._waitForWorkers--;
this.autocropImages();
}
} | javascript | function() {
if (!this._image instanceof IMSoftcrop.Image || !this._image.ready) {
return;
}
var _this = this,
imageData = this.getImageData();
this._waitForWorkers++;
if (window.Worker) {
// If workers are available, thread detection of faces
var detectWorker = new Worker(this._detectWorkerUrl);
detectWorker.postMessage([
'details',
imageData,
this._image.w,
this._image.h,
this._detectThreshold
]);
detectWorker.onmessage = function(e) {
_this.addDetectedDetails(e.data);
_this._waitForWorkers--;
_this.autocropImages();
};
}
else {
// Fallback to non threaded
var data = tracking.Fast.findCorners(
tracking.Image.grayscale(
imageData.data,
this._image.w,
this._image.h
),
this._image.w,
this._image.h,
this._detectThreshold
);
this.addDetectedDetails(data);
this._waitForWorkers--;
this.autocropImages();
}
} | [
"function",
"(",
")",
"{",
"if",
"(",
"!",
"this",
".",
"_image",
"instanceof",
"IMSoftcrop",
".",
"Image",
"||",
"!",
"this",
".",
"_image",
".",
"ready",
")",
"{",
"return",
";",
"}",
"var",
"_this",
"=",
"this",
",",
"imageData",
"=",
"this",
".",
"getImageData",
"(",
")",
";",
"this",
".",
"_waitForWorkers",
"++",
";",
"if",
"(",
"window",
".",
"Worker",
")",
"{",
"// If workers are available, thread detection of faces",
"var",
"detectWorker",
"=",
"new",
"Worker",
"(",
"this",
".",
"_detectWorkerUrl",
")",
";",
"detectWorker",
".",
"postMessage",
"(",
"[",
"'details'",
",",
"imageData",
",",
"this",
".",
"_image",
".",
"w",
",",
"this",
".",
"_image",
".",
"h",
",",
"this",
".",
"_detectThreshold",
"]",
")",
";",
"detectWorker",
".",
"onmessage",
"=",
"function",
"(",
"e",
")",
"{",
"_this",
".",
"addDetectedDetails",
"(",
"e",
".",
"data",
")",
";",
"_this",
".",
"_waitForWorkers",
"--",
";",
"_this",
".",
"autocropImages",
"(",
")",
";",
"}",
";",
"}",
"else",
"{",
"// Fallback to non threaded",
"var",
"data",
"=",
"tracking",
".",
"Fast",
".",
"findCorners",
"(",
"tracking",
".",
"Image",
".",
"grayscale",
"(",
"imageData",
".",
"data",
",",
"this",
".",
"_image",
".",
"w",
",",
"this",
".",
"_image",
".",
"h",
")",
",",
"this",
".",
"_image",
".",
"w",
",",
"this",
".",
"_image",
".",
"h",
",",
"this",
".",
"_detectThreshold",
")",
";",
"this",
".",
"addDetectedDetails",
"(",
"data",
")",
";",
"this",
".",
"_waitForWorkers",
"--",
";",
"this",
".",
"autocropImages",
"(",
")",
";",
"}",
"}"
]
| Detect features in image | [
"Detect",
"features",
"in",
"image"
]
| 10a84e6d83d07b327cbed3714e42b5ba3bd506b5 | https://github.com/Infomaker/cropjs/blob/10a84e6d83d07b327cbed3714e42b5ba3bd506b5/dist/js/cropjs.js#L981-L1026 |
|
39,816 | Infomaker/cropjs | dist/js/cropjs.js | function(data) {
var corners = [];
for (var i = 0; i < data.length; i += 2) {
corners.push({
x: data[i],
y: data[i + 1]
});
}
this._image.addDetailData(corners);
} | javascript | function(data) {
var corners = [];
for (var i = 0; i < data.length; i += 2) {
corners.push({
x: data[i],
y: data[i + 1]
});
}
this._image.addDetailData(corners);
} | [
"function",
"(",
"data",
")",
"{",
"var",
"corners",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"data",
".",
"length",
";",
"i",
"+=",
"2",
")",
"{",
"corners",
".",
"push",
"(",
"{",
"x",
":",
"data",
"[",
"i",
"]",
",",
"y",
":",
"data",
"[",
"i",
"+",
"1",
"]",
"}",
")",
";",
"}",
"this",
".",
"_image",
".",
"addDetailData",
"(",
"corners",
")",
";",
"}"
]
| Add detected details to current image
@param data | [
"Add",
"detected",
"details",
"to",
"current",
"image"
]
| 10a84e6d83d07b327cbed3714e42b5ba3bd506b5 | https://github.com/Infomaker/cropjs/blob/10a84e6d83d07b327cbed3714e42b5ba3bd506b5/dist/js/cropjs.js#L1032-L1042 |
|
39,817 | Infomaker/cropjs | dist/js/cropjs.js | function () {
if (!this._image instanceof IMSoftcrop.Image || !this._image.ready) {
return;
}
this._waitForWorkers++;
var _this = this;
if (window.Worker) {
// If workers are available, thread it
var featureWorker = new Worker(this._detectWorkerUrl);
featureWorker.postMessage([
'features',
this.getImageData(),
this._image.w,
this._image.h,
this._detectStepSize
]);
featureWorker.onmessage = function(e) {
for(var n = 0; n < e.data.length; n++) {
_this.addDetectedFeature(e.data[n]);
}
_this._waitForWorkers--;
_this.autocropImages();
};
}
else {
//
// Add function to tracking.js in order to track corners directly
// on image data so that we do not need to access ui.
//
tracking.trackData = function(tracker, imageData, width, height) {
var task = new tracking.TrackerTask(tracker);
task.on('run', function() {
tracker.track(imageData.data, width, height);
});
return task.run();
};
var tracker = new tracking.ObjectTracker(['face']);
tracker.setStepSize(this._detectStepSize);
tracker.on('track', function (event) {
event.data.forEach(function (rect) {
_this.addDetectedFeature(rect);
});
_this._waitForWorkers--;
_this.autocropImages();
});
tracking.trackData(tracker, this.getImageData(), this._image.w, this._image.h);
}
} | javascript | function () {
if (!this._image instanceof IMSoftcrop.Image || !this._image.ready) {
return;
}
this._waitForWorkers++;
var _this = this;
if (window.Worker) {
// If workers are available, thread it
var featureWorker = new Worker(this._detectWorkerUrl);
featureWorker.postMessage([
'features',
this.getImageData(),
this._image.w,
this._image.h,
this._detectStepSize
]);
featureWorker.onmessage = function(e) {
for(var n = 0; n < e.data.length; n++) {
_this.addDetectedFeature(e.data[n]);
}
_this._waitForWorkers--;
_this.autocropImages();
};
}
else {
//
// Add function to tracking.js in order to track corners directly
// on image data so that we do not need to access ui.
//
tracking.trackData = function(tracker, imageData, width, height) {
var task = new tracking.TrackerTask(tracker);
task.on('run', function() {
tracker.track(imageData.data, width, height);
});
return task.run();
};
var tracker = new tracking.ObjectTracker(['face']);
tracker.setStepSize(this._detectStepSize);
tracker.on('track', function (event) {
event.data.forEach(function (rect) {
_this.addDetectedFeature(rect);
});
_this._waitForWorkers--;
_this.autocropImages();
});
tracking.trackData(tracker, this.getImageData(), this._image.w, this._image.h);
}
} | [
"function",
"(",
")",
"{",
"if",
"(",
"!",
"this",
".",
"_image",
"instanceof",
"IMSoftcrop",
".",
"Image",
"||",
"!",
"this",
".",
"_image",
".",
"ready",
")",
"{",
"return",
";",
"}",
"this",
".",
"_waitForWorkers",
"++",
";",
"var",
"_this",
"=",
"this",
";",
"if",
"(",
"window",
".",
"Worker",
")",
"{",
"// If workers are available, thread it",
"var",
"featureWorker",
"=",
"new",
"Worker",
"(",
"this",
".",
"_detectWorkerUrl",
")",
";",
"featureWorker",
".",
"postMessage",
"(",
"[",
"'features'",
",",
"this",
".",
"getImageData",
"(",
")",
",",
"this",
".",
"_image",
".",
"w",
",",
"this",
".",
"_image",
".",
"h",
",",
"this",
".",
"_detectStepSize",
"]",
")",
";",
"featureWorker",
".",
"onmessage",
"=",
"function",
"(",
"e",
")",
"{",
"for",
"(",
"var",
"n",
"=",
"0",
";",
"n",
"<",
"e",
".",
"data",
".",
"length",
";",
"n",
"++",
")",
"{",
"_this",
".",
"addDetectedFeature",
"(",
"e",
".",
"data",
"[",
"n",
"]",
")",
";",
"}",
"_this",
".",
"_waitForWorkers",
"--",
";",
"_this",
".",
"autocropImages",
"(",
")",
";",
"}",
";",
"}",
"else",
"{",
"//",
"// Add function to tracking.js in order to track corners directly",
"// on image data so that we do not need to access ui.",
"//",
"tracking",
".",
"trackData",
"=",
"function",
"(",
"tracker",
",",
"imageData",
",",
"width",
",",
"height",
")",
"{",
"var",
"task",
"=",
"new",
"tracking",
".",
"TrackerTask",
"(",
"tracker",
")",
";",
"task",
".",
"on",
"(",
"'run'",
",",
"function",
"(",
")",
"{",
"tracker",
".",
"track",
"(",
"imageData",
".",
"data",
",",
"width",
",",
"height",
")",
";",
"}",
")",
";",
"return",
"task",
".",
"run",
"(",
")",
";",
"}",
";",
"var",
"tracker",
"=",
"new",
"tracking",
".",
"ObjectTracker",
"(",
"[",
"'face'",
"]",
")",
";",
"tracker",
".",
"setStepSize",
"(",
"this",
".",
"_detectStepSize",
")",
";",
"tracker",
".",
"on",
"(",
"'track'",
",",
"function",
"(",
"event",
")",
"{",
"event",
".",
"data",
".",
"forEach",
"(",
"function",
"(",
"rect",
")",
"{",
"_this",
".",
"addDetectedFeature",
"(",
"rect",
")",
";",
"}",
")",
";",
"_this",
".",
"_waitForWorkers",
"--",
";",
"_this",
".",
"autocropImages",
"(",
")",
";",
"}",
")",
";",
"tracking",
".",
"trackData",
"(",
"tracker",
",",
"this",
".",
"getImageData",
"(",
")",
",",
"this",
".",
"_image",
".",
"w",
",",
"this",
".",
"_image",
".",
"h",
")",
";",
"}",
"}"
]
| Detect faces in image | [
"Detect",
"faces",
"in",
"image"
]
| 10a84e6d83d07b327cbed3714e42b5ba3bd506b5 | https://github.com/Infomaker/cropjs/blob/10a84e6d83d07b327cbed3714e42b5ba3bd506b5/dist/js/cropjs.js#L1048-L1101 |
|
39,818 | Infomaker/cropjs | dist/js/cropjs.js | function(rect) {
var imageRadius = 0,
imagePoint = {
x: rect.x,
y: rect.y
};
if (rect.width / this._image.w > 0.45) {
// Feature point (face) takes up a large portion of the image
rect.height *= 1.2;
imagePoint.x += rect.width / 2;
imagePoint.y += rect.height / 2;
if (rect.height > rect.width) {
imageRadius = rect.height / 2;
}
else {
imageRadius = rect.width / 2;
}
}
else {
// Feature point (face) takes up less of the image
rect.height *= 1.4;
imagePoint.x += rect.width / 2;
imagePoint.y += rect.height / 4;
if (rect.height > rect.width) {
imageRadius = rect.height / 2;
}
else {
imageRadius = rect.width / 2;
}
}
this._image.addFocusPoint(imagePoint, imageRadius);
} | javascript | function(rect) {
var imageRadius = 0,
imagePoint = {
x: rect.x,
y: rect.y
};
if (rect.width / this._image.w > 0.45) {
// Feature point (face) takes up a large portion of the image
rect.height *= 1.2;
imagePoint.x += rect.width / 2;
imagePoint.y += rect.height / 2;
if (rect.height > rect.width) {
imageRadius = rect.height / 2;
}
else {
imageRadius = rect.width / 2;
}
}
else {
// Feature point (face) takes up less of the image
rect.height *= 1.4;
imagePoint.x += rect.width / 2;
imagePoint.y += rect.height / 4;
if (rect.height > rect.width) {
imageRadius = rect.height / 2;
}
else {
imageRadius = rect.width / 2;
}
}
this._image.addFocusPoint(imagePoint, imageRadius);
} | [
"function",
"(",
"rect",
")",
"{",
"var",
"imageRadius",
"=",
"0",
",",
"imagePoint",
"=",
"{",
"x",
":",
"rect",
".",
"x",
",",
"y",
":",
"rect",
".",
"y",
"}",
";",
"if",
"(",
"rect",
".",
"width",
"/",
"this",
".",
"_image",
".",
"w",
">",
"0.45",
")",
"{",
"// Feature point (face) takes up a large portion of the image",
"rect",
".",
"height",
"*=",
"1.2",
";",
"imagePoint",
".",
"x",
"+=",
"rect",
".",
"width",
"/",
"2",
";",
"imagePoint",
".",
"y",
"+=",
"rect",
".",
"height",
"/",
"2",
";",
"if",
"(",
"rect",
".",
"height",
">",
"rect",
".",
"width",
")",
"{",
"imageRadius",
"=",
"rect",
".",
"height",
"/",
"2",
";",
"}",
"else",
"{",
"imageRadius",
"=",
"rect",
".",
"width",
"/",
"2",
";",
"}",
"}",
"else",
"{",
"// Feature point (face) takes up less of the image",
"rect",
".",
"height",
"*=",
"1.4",
";",
"imagePoint",
".",
"x",
"+=",
"rect",
".",
"width",
"/",
"2",
";",
"imagePoint",
".",
"y",
"+=",
"rect",
".",
"height",
"/",
"4",
";",
"if",
"(",
"rect",
".",
"height",
">",
"rect",
".",
"width",
")",
"{",
"imageRadius",
"=",
"rect",
".",
"height",
"/",
"2",
";",
"}",
"else",
"{",
"imageRadius",
"=",
"rect",
".",
"width",
"/",
"2",
";",
"}",
"}",
"this",
".",
"_image",
".",
"addFocusPoint",
"(",
"imagePoint",
",",
"imageRadius",
")",
";",
"}"
]
| Add a feature point with radius.
Heads are important and therefore we naïvely assume features to be faces. Heads
are larger so we need to increase rect height about 40% and then move the y point
so that the forehead can be covered by the full focus point.
Then again. If the face covers more than a certain percent of the image (closeup)
we do not want to enlarge the feature point radius that much.
@param rect | [
"Add",
"a",
"feature",
"point",
"with",
"radius",
"."
]
| 10a84e6d83d07b327cbed3714e42b5ba3bd506b5 | https://github.com/Infomaker/cropjs/blob/10a84e6d83d07b327cbed3714e42b5ba3bd506b5/dist/js/cropjs.js#L1114-L1151 |
|
39,819 | Infomaker/cropjs | dist/js/cropjs.js | function (redraw) {
var cx, cy;
this._keepCenter = true;
cx = this._container.clientWidth / 2;
cy = this._container.clientHeight / 2;
var ix = ((this._image.w * this._zoomLevel) / 2) + (this._image.x * this._zoomLevel) + this._margin;
var iy = ((this._image.h * this._zoomLevel) / 2) + (this._image.y * this._zoomLevel) + this._margin;
var x = (cx == ix) ? 0 : (cx - ix) / this._zoomLevel;
var y = (cy == iy) ? 0 : (cy - iy) / this._zoomLevel;
this._image.move({x: x, y: y});
if (redraw === true) {
this.redraw();
}
} | javascript | function (redraw) {
var cx, cy;
this._keepCenter = true;
cx = this._container.clientWidth / 2;
cy = this._container.clientHeight / 2;
var ix = ((this._image.w * this._zoomLevel) / 2) + (this._image.x * this._zoomLevel) + this._margin;
var iy = ((this._image.h * this._zoomLevel) / 2) + (this._image.y * this._zoomLevel) + this._margin;
var x = (cx == ix) ? 0 : (cx - ix) / this._zoomLevel;
var y = (cy == iy) ? 0 : (cy - iy) / this._zoomLevel;
this._image.move({x: x, y: y});
if (redraw === true) {
this.redraw();
}
} | [
"function",
"(",
"redraw",
")",
"{",
"var",
"cx",
",",
"cy",
";",
"this",
".",
"_keepCenter",
"=",
"true",
";",
"cx",
"=",
"this",
".",
"_container",
".",
"clientWidth",
"/",
"2",
";",
"cy",
"=",
"this",
".",
"_container",
".",
"clientHeight",
"/",
"2",
";",
"var",
"ix",
"=",
"(",
"(",
"this",
".",
"_image",
".",
"w",
"*",
"this",
".",
"_zoomLevel",
")",
"/",
"2",
")",
"+",
"(",
"this",
".",
"_image",
".",
"x",
"*",
"this",
".",
"_zoomLevel",
")",
"+",
"this",
".",
"_margin",
";",
"var",
"iy",
"=",
"(",
"(",
"this",
".",
"_image",
".",
"h",
"*",
"this",
".",
"_zoomLevel",
")",
"/",
"2",
")",
"+",
"(",
"this",
".",
"_image",
".",
"y",
"*",
"this",
".",
"_zoomLevel",
")",
"+",
"this",
".",
"_margin",
";",
"var",
"x",
"=",
"(",
"cx",
"==",
"ix",
")",
"?",
"0",
":",
"(",
"cx",
"-",
"ix",
")",
"/",
"this",
".",
"_zoomLevel",
";",
"var",
"y",
"=",
"(",
"cy",
"==",
"iy",
")",
"?",
"0",
":",
"(",
"cy",
"-",
"iy",
")",
"/",
"this",
".",
"_zoomLevel",
";",
"this",
".",
"_image",
".",
"move",
"(",
"{",
"x",
":",
"x",
",",
"y",
":",
"y",
"}",
")",
";",
"if",
"(",
"redraw",
"===",
"true",
")",
"{",
"this",
".",
"redraw",
"(",
")",
";",
"}",
"}"
]
| Center image around the middle point of the drawing area
@param redraw | [
"Center",
"image",
"around",
"the",
"middle",
"point",
"of",
"the",
"drawing",
"area"
]
| 10a84e6d83d07b327cbed3714e42b5ba3bd506b5 | https://github.com/Infomaker/cropjs/blob/10a84e6d83d07b327cbed3714e42b5ba3bd506b5/dist/js/cropjs.js#L1179-L1197 |
|
39,820 | Infomaker/cropjs | dist/js/cropjs.js | function (zoomLevel, redraw) {
this._zoomLevel = zoomLevel / 100;
if (this._keepCenter) {
this.centerImage(false);
}
if (redraw === true) {
this.redraw();
}
} | javascript | function (zoomLevel, redraw) {
this._zoomLevel = zoomLevel / 100;
if (this._keepCenter) {
this.centerImage(false);
}
if (redraw === true) {
this.redraw();
}
} | [
"function",
"(",
"zoomLevel",
",",
"redraw",
")",
"{",
"this",
".",
"_zoomLevel",
"=",
"zoomLevel",
"/",
"100",
";",
"if",
"(",
"this",
".",
"_keepCenter",
")",
"{",
"this",
".",
"centerImage",
"(",
"false",
")",
";",
"}",
"if",
"(",
"redraw",
"===",
"true",
")",
"{",
"this",
".",
"redraw",
"(",
")",
";",
"}",
"}"
]
| Set zoom by percent
@param zoomLevel
@param redraw | [
"Set",
"zoom",
"by",
"percent"
]
| 10a84e6d83d07b327cbed3714e42b5ba3bd506b5 | https://github.com/Infomaker/cropjs/blob/10a84e6d83d07b327cbed3714e42b5ba3bd506b5/dist/js/cropjs.js#L1215-L1225 |
|
39,821 | Infomaker/cropjs | dist/js/cropjs.js | function (redraw) {
var imgDim = this._image.getDimensions();
var vFactor = (this._container.clientHeight - this._margin * 2) / imgDim.h;
var hFactor = (this._container.clientWidth - this._margin * 2) / imgDim.w;
// Set correct zoom level
if (vFactor < hFactor && vFactor < 1 && this._zoomLevel > vFactor) {
// Fill vertical
this._zoomLevel = vFactor;
this.centerImage(false);
}
else if (hFactor < 1 && this._zoomLevel > hFactor) {
// Fill horizontal
this._zoomLevel = hFactor;
this.centerImage(false);
}
else {
// No need to redraw
return;
}
if (redraw === true) {
this.redraw();
}
} | javascript | function (redraw) {
var imgDim = this._image.getDimensions();
var vFactor = (this._container.clientHeight - this._margin * 2) / imgDim.h;
var hFactor = (this._container.clientWidth - this._margin * 2) / imgDim.w;
// Set correct zoom level
if (vFactor < hFactor && vFactor < 1 && this._zoomLevel > vFactor) {
// Fill vertical
this._zoomLevel = vFactor;
this.centerImage(false);
}
else if (hFactor < 1 && this._zoomLevel > hFactor) {
// Fill horizontal
this._zoomLevel = hFactor;
this.centerImage(false);
}
else {
// No need to redraw
return;
}
if (redraw === true) {
this.redraw();
}
} | [
"function",
"(",
"redraw",
")",
"{",
"var",
"imgDim",
"=",
"this",
".",
"_image",
".",
"getDimensions",
"(",
")",
";",
"var",
"vFactor",
"=",
"(",
"this",
".",
"_container",
".",
"clientHeight",
"-",
"this",
".",
"_margin",
"*",
"2",
")",
"/",
"imgDim",
".",
"h",
";",
"var",
"hFactor",
"=",
"(",
"this",
".",
"_container",
".",
"clientWidth",
"-",
"this",
".",
"_margin",
"*",
"2",
")",
"/",
"imgDim",
".",
"w",
";",
"// Set correct zoom level",
"if",
"(",
"vFactor",
"<",
"hFactor",
"&&",
"vFactor",
"<",
"1",
"&&",
"this",
".",
"_zoomLevel",
">",
"vFactor",
")",
"{",
"// Fill vertical",
"this",
".",
"_zoomLevel",
"=",
"vFactor",
";",
"this",
".",
"centerImage",
"(",
"false",
")",
";",
"}",
"else",
"if",
"(",
"hFactor",
"<",
"1",
"&&",
"this",
".",
"_zoomLevel",
">",
"hFactor",
")",
"{",
"// Fill horizontal",
"this",
".",
"_zoomLevel",
"=",
"hFactor",
";",
"this",
".",
"centerImage",
"(",
"false",
")",
";",
"}",
"else",
"{",
"// No need to redraw",
"return",
";",
"}",
"if",
"(",
"redraw",
"===",
"true",
")",
"{",
"this",
".",
"redraw",
"(",
")",
";",
"}",
"}"
]
| Fill drawing area with image as best as possible
@param redraw | [
"Fill",
"drawing",
"area",
"with",
"image",
"as",
"best",
"as",
"possible"
]
| 10a84e6d83d07b327cbed3714e42b5ba3bd506b5 | https://github.com/Infomaker/cropjs/blob/10a84e6d83d07b327cbed3714e42b5ba3bd506b5/dist/js/cropjs.js#L1231-L1255 |
|
39,822 | Infomaker/cropjs | dist/js/cropjs.js | function () {
var _this = this;
window.addEventListener(
'resize',
function () {
_this.onResize(event);
},
false
);
this._canvas.addEventListener(
'dblclick',
function(event) {
return _this.onDoubleClick(event);
}
);
this._canvas.addEventListener(
'mousedown',
function (event) {
_this.onMouseDown(event);
}
);
this._canvas.addEventListener(
'mouseup',
function (event) {
_this.onMouseUp(event);
}
);
window.addEventListener(
'mouseup',
function (event) {
_this.onMouseUp(event);
}
);
this._canvas.addEventListener(
'mousemove',
function (event) {
_this.onMouseMove(event);
}
);
this._canvas.addEventListener(
'mousewheel',
function (event) {
event.stopPropagation();
event.preventDefault();
_this.onMouseWheel(event);
return false;
},
false
);
document.addEventListener(
'keydown',
function (e) {
var keyCode = e.keyCode || e.which;
// Handle escape key
if (keyCode === 13) {
_this._onSave(
_this.getSoftcropData()
);
e.preventDefault();
e.stopPropagation();
return false;
}
if (keyCode === 27) {
_this._onCancel();
e.preventDefault();
e.stopPropagation();
return false;
}
// Handle tab key
if (keyCode === 9) {
var crops = _this._image.getSoftCrops();
var current;
for (var n = 0; n < crops.length; n++) {
if (_this._crop === crops[n]) {
current = n;
break;
}
}
if (typeof current != 'undefined') {
n += (!e.shiftKey) ? 1 : -1;
if (n < 0) {
n = crops.length - 1;
}
else if (n + 1 > crops.length) {
n = 0;
}
_this.setActiveCrop(crops[n]);
}
e.preventDefault();
e.stopPropagation();
return false;
}
},
false
);
} | javascript | function () {
var _this = this;
window.addEventListener(
'resize',
function () {
_this.onResize(event);
},
false
);
this._canvas.addEventListener(
'dblclick',
function(event) {
return _this.onDoubleClick(event);
}
);
this._canvas.addEventListener(
'mousedown',
function (event) {
_this.onMouseDown(event);
}
);
this._canvas.addEventListener(
'mouseup',
function (event) {
_this.onMouseUp(event);
}
);
window.addEventListener(
'mouseup',
function (event) {
_this.onMouseUp(event);
}
);
this._canvas.addEventListener(
'mousemove',
function (event) {
_this.onMouseMove(event);
}
);
this._canvas.addEventListener(
'mousewheel',
function (event) {
event.stopPropagation();
event.preventDefault();
_this.onMouseWheel(event);
return false;
},
false
);
document.addEventListener(
'keydown',
function (e) {
var keyCode = e.keyCode || e.which;
// Handle escape key
if (keyCode === 13) {
_this._onSave(
_this.getSoftcropData()
);
e.preventDefault();
e.stopPropagation();
return false;
}
if (keyCode === 27) {
_this._onCancel();
e.preventDefault();
e.stopPropagation();
return false;
}
// Handle tab key
if (keyCode === 9) {
var crops = _this._image.getSoftCrops();
var current;
for (var n = 0; n < crops.length; n++) {
if (_this._crop === crops[n]) {
current = n;
break;
}
}
if (typeof current != 'undefined') {
n += (!e.shiftKey) ? 1 : -1;
if (n < 0) {
n = crops.length - 1;
}
else if (n + 1 > crops.length) {
n = 0;
}
_this.setActiveCrop(crops[n]);
}
e.preventDefault();
e.stopPropagation();
return false;
}
},
false
);
} | [
"function",
"(",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"window",
".",
"addEventListener",
"(",
"'resize'",
",",
"function",
"(",
")",
"{",
"_this",
".",
"onResize",
"(",
"event",
")",
";",
"}",
",",
"false",
")",
";",
"this",
".",
"_canvas",
".",
"addEventListener",
"(",
"'dblclick'",
",",
"function",
"(",
"event",
")",
"{",
"return",
"_this",
".",
"onDoubleClick",
"(",
"event",
")",
";",
"}",
")",
";",
"this",
".",
"_canvas",
".",
"addEventListener",
"(",
"'mousedown'",
",",
"function",
"(",
"event",
")",
"{",
"_this",
".",
"onMouseDown",
"(",
"event",
")",
";",
"}",
")",
";",
"this",
".",
"_canvas",
".",
"addEventListener",
"(",
"'mouseup'",
",",
"function",
"(",
"event",
")",
"{",
"_this",
".",
"onMouseUp",
"(",
"event",
")",
";",
"}",
")",
";",
"window",
".",
"addEventListener",
"(",
"'mouseup'",
",",
"function",
"(",
"event",
")",
"{",
"_this",
".",
"onMouseUp",
"(",
"event",
")",
";",
"}",
")",
";",
"this",
".",
"_canvas",
".",
"addEventListener",
"(",
"'mousemove'",
",",
"function",
"(",
"event",
")",
"{",
"_this",
".",
"onMouseMove",
"(",
"event",
")",
";",
"}",
")",
";",
"this",
".",
"_canvas",
".",
"addEventListener",
"(",
"'mousewheel'",
",",
"function",
"(",
"event",
")",
"{",
"event",
".",
"stopPropagation",
"(",
")",
";",
"event",
".",
"preventDefault",
"(",
")",
";",
"_this",
".",
"onMouseWheel",
"(",
"event",
")",
";",
"return",
"false",
";",
"}",
",",
"false",
")",
";",
"document",
".",
"addEventListener",
"(",
"'keydown'",
",",
"function",
"(",
"e",
")",
"{",
"var",
"keyCode",
"=",
"e",
".",
"keyCode",
"||",
"e",
".",
"which",
";",
"// Handle escape key",
"if",
"(",
"keyCode",
"===",
"13",
")",
"{",
"_this",
".",
"_onSave",
"(",
"_this",
".",
"getSoftcropData",
"(",
")",
")",
";",
"e",
".",
"preventDefault",
"(",
")",
";",
"e",
".",
"stopPropagation",
"(",
")",
";",
"return",
"false",
";",
"}",
"if",
"(",
"keyCode",
"===",
"27",
")",
"{",
"_this",
".",
"_onCancel",
"(",
")",
";",
"e",
".",
"preventDefault",
"(",
")",
";",
"e",
".",
"stopPropagation",
"(",
")",
";",
"return",
"false",
";",
"}",
"// Handle tab key",
"if",
"(",
"keyCode",
"===",
"9",
")",
"{",
"var",
"crops",
"=",
"_this",
".",
"_image",
".",
"getSoftCrops",
"(",
")",
";",
"var",
"current",
";",
"for",
"(",
"var",
"n",
"=",
"0",
";",
"n",
"<",
"crops",
".",
"length",
";",
"n",
"++",
")",
"{",
"if",
"(",
"_this",
".",
"_crop",
"===",
"crops",
"[",
"n",
"]",
")",
"{",
"current",
"=",
"n",
";",
"break",
";",
"}",
"}",
"if",
"(",
"typeof",
"current",
"!=",
"'undefined'",
")",
"{",
"n",
"+=",
"(",
"!",
"e",
".",
"shiftKey",
")",
"?",
"1",
":",
"-",
"1",
";",
"if",
"(",
"n",
"<",
"0",
")",
"{",
"n",
"=",
"crops",
".",
"length",
"-",
"1",
";",
"}",
"else",
"if",
"(",
"n",
"+",
"1",
">",
"crops",
".",
"length",
")",
"{",
"n",
"=",
"0",
";",
"}",
"_this",
".",
"setActiveCrop",
"(",
"crops",
"[",
"n",
"]",
")",
";",
"}",
"e",
".",
"preventDefault",
"(",
")",
";",
"e",
".",
"stopPropagation",
"(",
")",
";",
"return",
"false",
";",
"}",
"}",
",",
"false",
")",
";",
"}"
]
| Add all event listeners required for drawing and dragging | [
"Add",
"all",
"event",
"listeners",
"required",
"for",
"drawing",
"and",
"dragging"
]
| 10a84e6d83d07b327cbed3714e42b5ba3bd506b5 | https://github.com/Infomaker/cropjs/blob/10a84e6d83d07b327cbed3714e42b5ba3bd506b5/dist/js/cropjs.js#L1261-L1370 |
|
39,823 | Infomaker/cropjs | dist/js/cropjs.js | function(event) {
event.preventDefault();
event.stopPropagation();
if (typeof this._image == 'undefined') {
return false;
}
this.toggleLoadingImage(true);
var point = this.getMousePoint(event);
this._image.addFocusPoint(
this.canvasPointInImage(point.x, point.y),
40
);
if (this._image.autocrop()) {
this.redraw();
this.toggleLoadingImage(false);
}
return false;
} | javascript | function(event) {
event.preventDefault();
event.stopPropagation();
if (typeof this._image == 'undefined') {
return false;
}
this.toggleLoadingImage(true);
var point = this.getMousePoint(event);
this._image.addFocusPoint(
this.canvasPointInImage(point.x, point.y),
40
);
if (this._image.autocrop()) {
this.redraw();
this.toggleLoadingImage(false);
}
return false;
} | [
"function",
"(",
"event",
")",
"{",
"event",
".",
"preventDefault",
"(",
")",
";",
"event",
".",
"stopPropagation",
"(",
")",
";",
"if",
"(",
"typeof",
"this",
".",
"_image",
"==",
"'undefined'",
")",
"{",
"return",
"false",
";",
"}",
"this",
".",
"toggleLoadingImage",
"(",
"true",
")",
";",
"var",
"point",
"=",
"this",
".",
"getMousePoint",
"(",
"event",
")",
";",
"this",
".",
"_image",
".",
"addFocusPoint",
"(",
"this",
".",
"canvasPointInImage",
"(",
"point",
".",
"x",
",",
"point",
".",
"y",
")",
",",
"40",
")",
";",
"if",
"(",
"this",
".",
"_image",
".",
"autocrop",
"(",
")",
")",
"{",
"this",
".",
"redraw",
"(",
")",
";",
"this",
".",
"toggleLoadingImage",
"(",
"false",
")",
";",
"}",
"return",
"false",
";",
"}"
]
| Add focus point
@param event | [
"Add",
"focus",
"point"
]
| 10a84e6d83d07b327cbed3714e42b5ba3bd506b5 | https://github.com/Infomaker/cropjs/blob/10a84e6d83d07b327cbed3714e42b5ba3bd506b5/dist/js/cropjs.js#L1413-L1435 |
|
39,824 | Infomaker/cropjs | dist/js/cropjs.js | function (event) {
var point = this.getMousePoint(event);
if (this._crop instanceof IMSoftcrop.Softcrop && typeof this.handle === 'string') {
this.updateImageInfo(true);
this._dragPoint = point;
this._dragObject = this.handle;
}
else if (this._crop instanceof IMSoftcrop.Softcrop && this._crop.inArea(point)) {
this.updateImageInfo(true);
this._dragObject = this._crop;
this._dragPoint = point;
}
else if (this._image instanceof IMSoftcrop.Image && this._image.inArea(point)) {
this.updateImageInfo(false);
this._dragObject = this._image;
this._dragPoint = point;
}
} | javascript | function (event) {
var point = this.getMousePoint(event);
if (this._crop instanceof IMSoftcrop.Softcrop && typeof this.handle === 'string') {
this.updateImageInfo(true);
this._dragPoint = point;
this._dragObject = this.handle;
}
else if (this._crop instanceof IMSoftcrop.Softcrop && this._crop.inArea(point)) {
this.updateImageInfo(true);
this._dragObject = this._crop;
this._dragPoint = point;
}
else if (this._image instanceof IMSoftcrop.Image && this._image.inArea(point)) {
this.updateImageInfo(false);
this._dragObject = this._image;
this._dragPoint = point;
}
} | [
"function",
"(",
"event",
")",
"{",
"var",
"point",
"=",
"this",
".",
"getMousePoint",
"(",
"event",
")",
";",
"if",
"(",
"this",
".",
"_crop",
"instanceof",
"IMSoftcrop",
".",
"Softcrop",
"&&",
"typeof",
"this",
".",
"handle",
"===",
"'string'",
")",
"{",
"this",
".",
"updateImageInfo",
"(",
"true",
")",
";",
"this",
".",
"_dragPoint",
"=",
"point",
";",
"this",
".",
"_dragObject",
"=",
"this",
".",
"handle",
";",
"}",
"else",
"if",
"(",
"this",
".",
"_crop",
"instanceof",
"IMSoftcrop",
".",
"Softcrop",
"&&",
"this",
".",
"_crop",
".",
"inArea",
"(",
"point",
")",
")",
"{",
"this",
".",
"updateImageInfo",
"(",
"true",
")",
";",
"this",
".",
"_dragObject",
"=",
"this",
".",
"_crop",
";",
"this",
".",
"_dragPoint",
"=",
"point",
";",
"}",
"else",
"if",
"(",
"this",
".",
"_image",
"instanceof",
"IMSoftcrop",
".",
"Image",
"&&",
"this",
".",
"_image",
".",
"inArea",
"(",
"point",
")",
")",
"{",
"this",
".",
"updateImageInfo",
"(",
"false",
")",
";",
"this",
".",
"_dragObject",
"=",
"this",
".",
"_image",
";",
"this",
".",
"_dragPoint",
"=",
"point",
";",
"}",
"}"
]
| On mouse down event handler
@param event | [
"On",
"mouse",
"down",
"event",
"handler"
]
| 10a84e6d83d07b327cbed3714e42b5ba3bd506b5 | https://github.com/Infomaker/cropjs/blob/10a84e6d83d07b327cbed3714e42b5ba3bd506b5/dist/js/cropjs.js#L1442-L1460 |
|
39,825 | Infomaker/cropjs | dist/js/cropjs.js | function (event) {
var delta = Math.max(-1, Math.min(1, (event.wheelDelta || -event.detail)));
var zoom = 0;
if (delta < 0 && this._zoomLevel < this._zoomMax) {
// Zoom in
zoom = this._zoomLevel < 1 ? 0.01 : 0.03;
}
else if (delta > 0 && this._zoomLevel > this._zoomMin) {
// Zoom out
zoom = this._zoomLevel < 1 ? -0.01 : -0.03;
}
else {
return;
}
// Calculate middle point change for zoom change
var x = ((this._image.w / 2) + this._image.x) * zoom;
var y = ((this._image.h / 2) + this._image.y) * zoom;
// Adjust zoom
this._zoomLevel += zoom;
// Then move back to old middle point
this._image.move({
x: -x / this._zoomLevel,
y: -y / this._zoomLevel
});
this.redraw();
} | javascript | function (event) {
var delta = Math.max(-1, Math.min(1, (event.wheelDelta || -event.detail)));
var zoom = 0;
if (delta < 0 && this._zoomLevel < this._zoomMax) {
// Zoom in
zoom = this._zoomLevel < 1 ? 0.01 : 0.03;
}
else if (delta > 0 && this._zoomLevel > this._zoomMin) {
// Zoom out
zoom = this._zoomLevel < 1 ? -0.01 : -0.03;
}
else {
return;
}
// Calculate middle point change for zoom change
var x = ((this._image.w / 2) + this._image.x) * zoom;
var y = ((this._image.h / 2) + this._image.y) * zoom;
// Adjust zoom
this._zoomLevel += zoom;
// Then move back to old middle point
this._image.move({
x: -x / this._zoomLevel,
y: -y / this._zoomLevel
});
this.redraw();
} | [
"function",
"(",
"event",
")",
"{",
"var",
"delta",
"=",
"Math",
".",
"max",
"(",
"-",
"1",
",",
"Math",
".",
"min",
"(",
"1",
",",
"(",
"event",
".",
"wheelDelta",
"||",
"-",
"event",
".",
"detail",
")",
")",
")",
";",
"var",
"zoom",
"=",
"0",
";",
"if",
"(",
"delta",
"<",
"0",
"&&",
"this",
".",
"_zoomLevel",
"<",
"this",
".",
"_zoomMax",
")",
"{",
"// Zoom in",
"zoom",
"=",
"this",
".",
"_zoomLevel",
"<",
"1",
"?",
"0.01",
":",
"0.03",
";",
"}",
"else",
"if",
"(",
"delta",
">",
"0",
"&&",
"this",
".",
"_zoomLevel",
">",
"this",
".",
"_zoomMin",
")",
"{",
"// Zoom out",
"zoom",
"=",
"this",
".",
"_zoomLevel",
"<",
"1",
"?",
"-",
"0.01",
":",
"-",
"0.03",
";",
"}",
"else",
"{",
"return",
";",
"}",
"// Calculate middle point change for zoom change",
"var",
"x",
"=",
"(",
"(",
"this",
".",
"_image",
".",
"w",
"/",
"2",
")",
"+",
"this",
".",
"_image",
".",
"x",
")",
"*",
"zoom",
";",
"var",
"y",
"=",
"(",
"(",
"this",
".",
"_image",
".",
"h",
"/",
"2",
")",
"+",
"this",
".",
"_image",
".",
"y",
")",
"*",
"zoom",
";",
"// Adjust zoom",
"this",
".",
"_zoomLevel",
"+=",
"zoom",
";",
"// Then move back to old middle point",
"this",
".",
"_image",
".",
"move",
"(",
"{",
"x",
":",
"-",
"x",
"/",
"this",
".",
"_zoomLevel",
",",
"y",
":",
"-",
"y",
"/",
"this",
".",
"_zoomLevel",
"}",
")",
";",
"this",
".",
"redraw",
"(",
")",
";",
"}"
]
| On mouse wheel event handler.
@fixme Fix code for calculating offsets based on current mouse point
@param event | [
"On",
"mouse",
"wheel",
"event",
"handler",
"."
]
| 10a84e6d83d07b327cbed3714e42b5ba3bd506b5 | https://github.com/Infomaker/cropjs/blob/10a84e6d83d07b327cbed3714e42b5ba3bd506b5/dist/js/cropjs.js#L1565-L1595 |
|
39,826 | Infomaker/cropjs | dist/js/cropjs.js | function (event) {
return {
x: event.pageX - this._position.x,
y: event.pageY - this._position.y
};
} | javascript | function (event) {
return {
x: event.pageX - this._position.x,
y: event.pageY - this._position.y
};
} | [
"function",
"(",
"event",
")",
"{",
"return",
"{",
"x",
":",
"event",
".",
"pageX",
"-",
"this",
".",
"_position",
".",
"x",
",",
"y",
":",
"event",
".",
"pageY",
"-",
"this",
".",
"_position",
".",
"y",
"}",
";",
"}"
]
| Get mouse coordinates
@param event
@returns {{x: number, y: number}} | [
"Get",
"mouse",
"coordinates"
]
| 10a84e6d83d07b327cbed3714e42b5ba3bd506b5 | https://github.com/Infomaker/cropjs/blob/10a84e6d83d07b327cbed3714e42b5ba3bd506b5/dist/js/cropjs.js#L1603-L1608 |
|
39,827 | Infomaker/cropjs | dist/js/cropjs.js | function() {
var offset = IMSoftcrop.Ratio.getElementPosition(this._canvas);
this._position.x = offset.x;
this._position.y = offset.y;
} | javascript | function() {
var offset = IMSoftcrop.Ratio.getElementPosition(this._canvas);
this._position.x = offset.x;
this._position.y = offset.y;
} | [
"function",
"(",
")",
"{",
"var",
"offset",
"=",
"IMSoftcrop",
".",
"Ratio",
".",
"getElementPosition",
"(",
"this",
".",
"_canvas",
")",
";",
"this",
".",
"_position",
".",
"x",
"=",
"offset",
".",
"x",
";",
"this",
".",
"_position",
".",
"y",
"=",
"offset",
".",
"y",
";",
"}"
]
| Calculate true x,y offset of canvas, including the border and margin
@returns {{x: number, y: number}} | [
"Calculate",
"true",
"x",
"y",
"offset",
"of",
"canvas",
"including",
"the",
"border",
"and",
"margin"
]
| 10a84e6d83d07b327cbed3714e42b5ba3bd506b5 | https://github.com/Infomaker/cropjs/blob/10a84e6d83d07b327cbed3714e42b5ba3bd506b5/dist/js/cropjs.js#L1624-L1629 |
|
39,828 | Infomaker/cropjs | dist/js/cropjs.js | function () {
this._drawCross(
'red',
{
x: this._container.clientWidth / 2,
y: this._container.clientHeight / 2
}
);
this._drawCross(
'green',
{
x: ((this._image.w * this._zoomLevel) / 2) + (this._image.x * this._zoomLevel) + this._margin,
y: ((this._image.h * this._zoomLevel) / 2) + (this._image.y * this._zoomLevel) + this._margin
}
);
if (typeof this._debugContainer != 'undefined') {
var str = '<pre>';
str += 'Zoom level: ' + this._zoomLevel + "\n";
if (typeof this._image != 'undefined') {
str += 'Image w: ' + this._image.w + "\n";
str += ' h: ' + this._image.h + "\n";
str += "\n";
if (typeof this._image.crop != 'undefined') {
str += 'Crop x: ' + this._image.crop.x + "\n";
str += ' y: ' + this._image.crop.y + "\n";
str += ' w: ' + this._image.crop.w + "\n";
str += ' h: ' + this._image.crop.h + "\n";
}
}
str += '</pre>';
this._debugContainer.innerHTML = str;
}
} | javascript | function () {
this._drawCross(
'red',
{
x: this._container.clientWidth / 2,
y: this._container.clientHeight / 2
}
);
this._drawCross(
'green',
{
x: ((this._image.w * this._zoomLevel) / 2) + (this._image.x * this._zoomLevel) + this._margin,
y: ((this._image.h * this._zoomLevel) / 2) + (this._image.y * this._zoomLevel) + this._margin
}
);
if (typeof this._debugContainer != 'undefined') {
var str = '<pre>';
str += 'Zoom level: ' + this._zoomLevel + "\n";
if (typeof this._image != 'undefined') {
str += 'Image w: ' + this._image.w + "\n";
str += ' h: ' + this._image.h + "\n";
str += "\n";
if (typeof this._image.crop != 'undefined') {
str += 'Crop x: ' + this._image.crop.x + "\n";
str += ' y: ' + this._image.crop.y + "\n";
str += ' w: ' + this._image.crop.w + "\n";
str += ' h: ' + this._image.crop.h + "\n";
}
}
str += '</pre>';
this._debugContainer.innerHTML = str;
}
} | [
"function",
"(",
")",
"{",
"this",
".",
"_drawCross",
"(",
"'red'",
",",
"{",
"x",
":",
"this",
".",
"_container",
".",
"clientWidth",
"/",
"2",
",",
"y",
":",
"this",
".",
"_container",
".",
"clientHeight",
"/",
"2",
"}",
")",
";",
"this",
".",
"_drawCross",
"(",
"'green'",
",",
"{",
"x",
":",
"(",
"(",
"this",
".",
"_image",
".",
"w",
"*",
"this",
".",
"_zoomLevel",
")",
"/",
"2",
")",
"+",
"(",
"this",
".",
"_image",
".",
"x",
"*",
"this",
".",
"_zoomLevel",
")",
"+",
"this",
".",
"_margin",
",",
"y",
":",
"(",
"(",
"this",
".",
"_image",
".",
"h",
"*",
"this",
".",
"_zoomLevel",
")",
"/",
"2",
")",
"+",
"(",
"this",
".",
"_image",
".",
"y",
"*",
"this",
".",
"_zoomLevel",
")",
"+",
"this",
".",
"_margin",
"}",
")",
";",
"if",
"(",
"typeof",
"this",
".",
"_debugContainer",
"!=",
"'undefined'",
")",
"{",
"var",
"str",
"=",
"'<pre>'",
";",
"str",
"+=",
"'Zoom level: '",
"+",
"this",
".",
"_zoomLevel",
"+",
"\"\\n\"",
";",
"if",
"(",
"typeof",
"this",
".",
"_image",
"!=",
"'undefined'",
")",
"{",
"str",
"+=",
"'Image w: '",
"+",
"this",
".",
"_image",
".",
"w",
"+",
"\"\\n\"",
";",
"str",
"+=",
"' h: '",
"+",
"this",
".",
"_image",
".",
"h",
"+",
"\"\\n\"",
";",
"str",
"+=",
"\"\\n\"",
";",
"if",
"(",
"typeof",
"this",
".",
"_image",
".",
"crop",
"!=",
"'undefined'",
")",
"{",
"str",
"+=",
"'Crop x: '",
"+",
"this",
".",
"_image",
".",
"crop",
".",
"x",
"+",
"\"\\n\"",
";",
"str",
"+=",
"' y: '",
"+",
"this",
".",
"_image",
".",
"crop",
".",
"y",
"+",
"\"\\n\"",
";",
"str",
"+=",
"' w: '",
"+",
"this",
".",
"_image",
".",
"crop",
".",
"w",
"+",
"\"\\n\"",
";",
"str",
"+=",
"' h: '",
"+",
"this",
".",
"_image",
".",
"crop",
".",
"h",
"+",
"\"\\n\"",
";",
"}",
"}",
"str",
"+=",
"'</pre>'",
";",
"this",
".",
"_debugContainer",
".",
"innerHTML",
"=",
"str",
";",
"}",
"}"
]
| Render and output debug position and dimensions
@private | [
"Render",
"and",
"output",
"debug",
"position",
"and",
"dimensions"
]
| 10a84e6d83d07b327cbed3714e42b5ba3bd506b5 | https://github.com/Infomaker/cropjs/blob/10a84e6d83d07b327cbed3714e42b5ba3bd506b5/dist/js/cropjs.js#L1636-L1672 |
|
39,829 | Infomaker/cropjs | dist/js/cropjs.js | function (color, point) {
var ctx = this._canvas.getContext('2d');
ctx.beginPath();
ctx.fillStyle = color;
ctx.strokeStyle = color;
ctx.lineWidth = 0.5;
ctx.arc(point.x, point.y, 5, 0, 2 * Math.PI, false);
ctx.fill();
ctx.beginPath();
ctx.moveTo(point.x - 50, point.y);
ctx.lineTo(point.x + 50, point.y);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(point.x, point.y - 50);
ctx.lineTo(point.x, point.y + 50);
ctx.stroke();
} | javascript | function (color, point) {
var ctx = this._canvas.getContext('2d');
ctx.beginPath();
ctx.fillStyle = color;
ctx.strokeStyle = color;
ctx.lineWidth = 0.5;
ctx.arc(point.x, point.y, 5, 0, 2 * Math.PI, false);
ctx.fill();
ctx.beginPath();
ctx.moveTo(point.x - 50, point.y);
ctx.lineTo(point.x + 50, point.y);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(point.x, point.y - 50);
ctx.lineTo(point.x, point.y + 50);
ctx.stroke();
} | [
"function",
"(",
"color",
",",
"point",
")",
"{",
"var",
"ctx",
"=",
"this",
".",
"_canvas",
".",
"getContext",
"(",
"'2d'",
")",
";",
"ctx",
".",
"beginPath",
"(",
")",
";",
"ctx",
".",
"fillStyle",
"=",
"color",
";",
"ctx",
".",
"strokeStyle",
"=",
"color",
";",
"ctx",
".",
"lineWidth",
"=",
"0.5",
";",
"ctx",
".",
"arc",
"(",
"point",
".",
"x",
",",
"point",
".",
"y",
",",
"5",
",",
"0",
",",
"2",
"*",
"Math",
".",
"PI",
",",
"false",
")",
";",
"ctx",
".",
"fill",
"(",
")",
";",
"ctx",
".",
"beginPath",
"(",
")",
";",
"ctx",
".",
"moveTo",
"(",
"point",
".",
"x",
"-",
"50",
",",
"point",
".",
"y",
")",
";",
"ctx",
".",
"lineTo",
"(",
"point",
".",
"x",
"+",
"50",
",",
"point",
".",
"y",
")",
";",
"ctx",
".",
"stroke",
"(",
")",
";",
"ctx",
".",
"beginPath",
"(",
")",
";",
"ctx",
".",
"moveTo",
"(",
"point",
".",
"x",
",",
"point",
".",
"y",
"-",
"50",
")",
";",
"ctx",
".",
"lineTo",
"(",
"point",
".",
"x",
",",
"point",
".",
"y",
"+",
"50",
")",
";",
"ctx",
".",
"stroke",
"(",
")",
";",
"}"
]
| Helper function for drawing a cross mark
@param color
@param point | [
"Helper",
"function",
"for",
"drawing",
"a",
"cross",
"mark"
]
| 10a84e6d83d07b327cbed3714e42b5ba3bd506b5 | https://github.com/Infomaker/cropjs/blob/10a84e6d83d07b327cbed3714e42b5ba3bd506b5/dist/js/cropjs.js#L1680-L1700 |
|
39,830 | SewanDevs/ceiba-router | packages/path-matcher/src/compileTree.js | globsToRegExpStr | function globsToRegExpStr(str) {
return str.split(STRING_TESTS.GLOBSTAR)
// => [ theWholeTextIfThereIsNoGlobstar, "**", everythingAfter ]
.map((v, i) =>
(i + 1) % 2 === 0 ? // (**) part
// Replace unescaped '**' glob
v.replace(STRING_TESTS.GLOBSTAR, (_match, _p1, p2) =>
`([^\\/]+\/+)*${p2 ? `[^\\/]*${p2}` : ''}`)
: (i + 1) % 3 === 0 ? // (everythingElse) part
(v ? `[^\\/]*${v}` : '')
: // Else
// Replace unescaped '*' glob
v.replace(STRING_TESTS.STAR, '$1([^\\/]*)'))
.join('');
} | javascript | function globsToRegExpStr(str) {
return str.split(STRING_TESTS.GLOBSTAR)
// => [ theWholeTextIfThereIsNoGlobstar, "**", everythingAfter ]
.map((v, i) =>
(i + 1) % 2 === 0 ? // (**) part
// Replace unescaped '**' glob
v.replace(STRING_TESTS.GLOBSTAR, (_match, _p1, p2) =>
`([^\\/]+\/+)*${p2 ? `[^\\/]*${p2}` : ''}`)
: (i + 1) % 3 === 0 ? // (everythingElse) part
(v ? `[^\\/]*${v}` : '')
: // Else
// Replace unescaped '*' glob
v.replace(STRING_TESTS.STAR, '$1([^\\/]*)'))
.join('');
} | [
"function",
"globsToRegExpStr",
"(",
"str",
")",
"{",
"return",
"str",
".",
"split",
"(",
"STRING_TESTS",
".",
"GLOBSTAR",
")",
"// => [ theWholeTextIfThereIsNoGlobstar, \"**\", everythingAfter ]",
".",
"map",
"(",
"(",
"v",
",",
"i",
")",
"=>",
"(",
"i",
"+",
"1",
")",
"%",
"2",
"===",
"0",
"?",
"// (**) part",
"// Replace unescaped '**' glob",
"v",
".",
"replace",
"(",
"STRING_TESTS",
".",
"GLOBSTAR",
",",
"(",
"_match",
",",
"_p1",
",",
"p2",
")",
"=>",
"`",
"\\\\",
"\\/",
"${",
"p2",
"?",
"`",
"\\\\",
"${",
"p2",
"}",
"`",
":",
"''",
"}",
"`",
")",
":",
"(",
"i",
"+",
"1",
")",
"%",
"3",
"===",
"0",
"?",
"// (everythingElse) part",
"(",
"v",
"?",
"`",
"\\\\",
"${",
"v",
"}",
"`",
":",
"''",
")",
":",
"// Else",
"// Replace unescaped '*' glob",
"v",
".",
"replace",
"(",
"STRING_TESTS",
".",
"STAR",
",",
"'$1([^\\\\/]*)'",
")",
")",
".",
"join",
"(",
"''",
")",
";",
"}"
]
| Transform globs into RegExp string | [
"Transform",
"globs",
"into",
"RegExp",
"string"
]
| d92478426b3d246ffd04d8943349b75bc20049b3 | https://github.com/SewanDevs/ceiba-router/blob/d92478426b3d246ffd04d8943349b75bc20049b3/packages/path-matcher/src/compileTree.js#L47-L61 |
39,831 | SewanDevs/ceiba-router | packages/path-matcher/src/compileTree.js | preparePatternStringSegment | function preparePatternStringSegment(str) {
if (STRING_TESTS.ARRAY.test(str)) {
const els = str.replace(/([^\\]),/g, "$1$1,")
.split(/[^\\],/);
return arrayToORRegExpStr(els.map(_transformSegment))
} else {
return _transformSegment(str);
}
} | javascript | function preparePatternStringSegment(str) {
if (STRING_TESTS.ARRAY.test(str)) {
const els = str.replace(/([^\\]),/g, "$1$1,")
.split(/[^\\],/);
return arrayToORRegExpStr(els.map(_transformSegment))
} else {
return _transformSegment(str);
}
} | [
"function",
"preparePatternStringSegment",
"(",
"str",
")",
"{",
"if",
"(",
"STRING_TESTS",
".",
"ARRAY",
".",
"test",
"(",
"str",
")",
")",
"{",
"const",
"els",
"=",
"str",
".",
"replace",
"(",
"/",
"([^\\\\]),",
"/",
"g",
",",
"\"$1$1,\"",
")",
".",
"split",
"(",
"/",
"[^\\\\],",
"/",
")",
";",
"return",
"arrayToORRegExpStr",
"(",
"els",
".",
"map",
"(",
"_transformSegment",
")",
")",
"}",
"else",
"{",
"return",
"_transformSegment",
"(",
"str",
")",
";",
"}",
"}"
]
| Prepare string to be passed through RegExp constructor while transforming
glob patterns. | [
"Prepare",
"string",
"to",
"be",
"passed",
"through",
"RegExp",
"constructor",
"while",
"transforming",
"glob",
"patterns",
"."
]
| d92478426b3d246ffd04d8943349b75bc20049b3 | https://github.com/SewanDevs/ceiba-router/blob/d92478426b3d246ffd04d8943349b75bc20049b3/packages/path-matcher/src/compileTree.js#L71-L79 |
39,832 | blaise-io/gcc-rest | gcc-rest.js | function(setting, value) {
if (-1 === this._supportedPostParams.indexOf(setting)) {
this.console.error('Parameter unsupported, may cause error:', setting);
}
this._reqParam[setting] = value;
return this;
} | javascript | function(setting, value) {
if (-1 === this._supportedPostParams.indexOf(setting)) {
this.console.error('Parameter unsupported, may cause error:', setting);
}
this._reqParam[setting] = value;
return this;
} | [
"function",
"(",
"setting",
",",
"value",
")",
"{",
"if",
"(",
"-",
"1",
"===",
"this",
".",
"_supportedPostParams",
".",
"indexOf",
"(",
"setting",
")",
")",
"{",
"this",
".",
"console",
".",
"error",
"(",
"'Parameter unsupported, may cause error:'",
",",
"setting",
")",
";",
"}",
"this",
".",
"_reqParam",
"[",
"setting",
"]",
"=",
"value",
";",
"return",
"this",
";",
"}"
]
| Set a Google Closure Compiler request parameter.
@param {string} setting
@param {string|Array} value
@return {GccRest} | [
"Set",
"a",
"Google",
"Closure",
"Compiler",
"request",
"parameter",
"."
]
| 680b6a2f18f24fcbce8c71fad6393f7963129d9e | https://github.com/blaise-io/gcc-rest/blob/680b6a2f18f24fcbce8c71fad6393f7963129d9e/gcc-rest.js#L57-L63 |
|
39,833 | blaise-io/gcc-rest | gcc-rest.js | function(settings) {
for (var k in settings) {
if (settings.hasOwnProperty(k)) {
this.param(k, settings[k]);
}
}
return this;
} | javascript | function(settings) {
for (var k in settings) {
if (settings.hasOwnProperty(k)) {
this.param(k, settings[k]);
}
}
return this;
} | [
"function",
"(",
"settings",
")",
"{",
"for",
"(",
"var",
"k",
"in",
"settings",
")",
"{",
"if",
"(",
"settings",
".",
"hasOwnProperty",
"(",
"k",
")",
")",
"{",
"this",
".",
"param",
"(",
"k",
",",
"settings",
"[",
"k",
"]",
")",
";",
"}",
"}",
"return",
"this",
";",
"}"
]
| Set multiple Google Closure Compiler request parameters.
@param {Object} settings
@return {GccRest} | [
"Set",
"multiple",
"Google",
"Closure",
"Compiler",
"request",
"parameters",
"."
]
| 680b6a2f18f24fcbce8c71fad6393f7963129d9e | https://github.com/blaise-io/gcc-rest/blob/680b6a2f18f24fcbce8c71fad6393f7963129d9e/gcc-rest.js#L70-L77 |
|
39,834 | blaise-io/gcc-rest | gcc-rest.js | function(varArgs) {
for (var i = 0, m = arguments.length; i < m; i++) {
this.addFile(arguments[i]);
}
return this;
} | javascript | function(varArgs) {
for (var i = 0, m = arguments.length; i < m; i++) {
this.addFile(arguments[i]);
}
return this;
} | [
"function",
"(",
"varArgs",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"m",
"=",
"arguments",
".",
"length",
";",
"i",
"<",
"m",
";",
"i",
"++",
")",
"{",
"this",
".",
"addFile",
"(",
"arguments",
"[",
"i",
"]",
")",
";",
"}",
"return",
"this",
";",
"}"
]
| Add multiple files to the list of files to be compiled.
@param {...string} varArgs
@return {GccRest} | [
"Add",
"multiple",
"files",
"to",
"the",
"list",
"of",
"files",
"to",
"be",
"compiled",
"."
]
| 680b6a2f18f24fcbce8c71fad6393f7963129d9e | https://github.com/blaise-io/gcc-rest/blob/680b6a2f18f24fcbce8c71fad6393f7963129d9e/gcc-rest.js#L122-L127 |
|
39,835 | blaise-io/gcc-rest | gcc-rest.js | function(config) {
var data, request;
data = querystring.stringify(config);
request = http.request(this._closureEndpoint, this._handleResponse.bind(this));
request.on('error', function(e) {
this.console.error('Request error', e);
this._errCallback('http_request_error', e);
}.bind(this));
request.end(data);
// For ease of use, GccRest exports an instance. Node.js caches exports.
// We flush the cache here to prevent GccRest from returning a polluted
// instance, in case GccRest is called multiple times.
try {
delete require.cache[__filename];
} catch(err){}
} | javascript | function(config) {
var data, request;
data = querystring.stringify(config);
request = http.request(this._closureEndpoint, this._handleResponse.bind(this));
request.on('error', function(e) {
this.console.error('Request error', e);
this._errCallback('http_request_error', e);
}.bind(this));
request.end(data);
// For ease of use, GccRest exports an instance. Node.js caches exports.
// We flush the cache here to prevent GccRest from returning a polluted
// instance, in case GccRest is called multiple times.
try {
delete require.cache[__filename];
} catch(err){}
} | [
"function",
"(",
"config",
")",
"{",
"var",
"data",
",",
"request",
";",
"data",
"=",
"querystring",
".",
"stringify",
"(",
"config",
")",
";",
"request",
"=",
"http",
".",
"request",
"(",
"this",
".",
"_closureEndpoint",
",",
"this",
".",
"_handleResponse",
".",
"bind",
"(",
"this",
")",
")",
";",
"request",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"e",
")",
"{",
"this",
".",
"console",
".",
"error",
"(",
"'Request error'",
",",
"e",
")",
";",
"this",
".",
"_errCallback",
"(",
"'http_request_error'",
",",
"e",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
")",
";",
"request",
".",
"end",
"(",
"data",
")",
";",
"// For ease of use, GccRest exports an instance. Node.js caches exports.",
"// We flush the cache here to prevent GccRest from returning a polluted",
"// instance, in case GccRest is called multiple times.",
"try",
"{",
"delete",
"require",
".",
"cache",
"[",
"__filename",
"]",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"}",
"}"
]
| Compile source HTTP request.
@param {Object} config
@private | [
"Compile",
"source",
"HTTP",
"request",
"."
]
| 680b6a2f18f24fcbce8c71fad6393f7963129d9e | https://github.com/blaise-io/gcc-rest/blob/680b6a2f18f24fcbce8c71fad6393f7963129d9e/gcc-rest.js#L189-L207 |
|
39,836 | blaise-io/gcc-rest | gcc-rest.js | function(response) {
var chunks = [];
response.on('data', function(chunk) {
chunks.push(chunk);
});
response.on('end', function() {
var json = JSON.parse(chunks.join(''));
this._showOutputInfo(json);
this._handleOutput(json);
}.bind(this));
} | javascript | function(response) {
var chunks = [];
response.on('data', function(chunk) {
chunks.push(chunk);
});
response.on('end', function() {
var json = JSON.parse(chunks.join(''));
this._showOutputInfo(json);
this._handleOutput(json);
}.bind(this));
} | [
"function",
"(",
"response",
")",
"{",
"var",
"chunks",
"=",
"[",
"]",
";",
"response",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"chunk",
")",
"{",
"chunks",
".",
"push",
"(",
"chunk",
")",
";",
"}",
")",
";",
"response",
".",
"on",
"(",
"'end'",
",",
"function",
"(",
")",
"{",
"var",
"json",
"=",
"JSON",
".",
"parse",
"(",
"chunks",
".",
"join",
"(",
"''",
")",
")",
";",
"this",
".",
"_showOutputInfo",
"(",
"json",
")",
";",
"this",
".",
"_handleOutput",
"(",
"json",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
")",
";",
"}"
]
| Handle a succesful compile request response.
@param {ServerResponse} response
@private | [
"Handle",
"a",
"succesful",
"compile",
"request",
"response",
"."
]
| 680b6a2f18f24fcbce8c71fad6393f7963129d9e | https://github.com/blaise-io/gcc-rest/blob/680b6a2f18f24fcbce8c71fad6393f7963129d9e/gcc-rest.js#L228-L240 |
|
39,837 | blaise-io/gcc-rest | gcc-rest.js | function(json) {
if (json.serverErrors) {
this._handleNoCompiledCode(json.serverErrors);
} else {
json.compiledCode = this._header + json.compiledCode;
if (this.file) {
this._writeOutputTofile(json.compiledCode);
}
if (this.callback) {
this.callback((this._passJson) ? json : json.compiledCode);
}
if (!this.file && !this.callback) {
this.console.info('Code:', json.compiledCode);
}
}
} | javascript | function(json) {
if (json.serverErrors) {
this._handleNoCompiledCode(json.serverErrors);
} else {
json.compiledCode = this._header + json.compiledCode;
if (this.file) {
this._writeOutputTofile(json.compiledCode);
}
if (this.callback) {
this.callback((this._passJson) ? json : json.compiledCode);
}
if (!this.file && !this.callback) {
this.console.info('Code:', json.compiledCode);
}
}
} | [
"function",
"(",
"json",
")",
"{",
"if",
"(",
"json",
".",
"serverErrors",
")",
"{",
"this",
".",
"_handleNoCompiledCode",
"(",
"json",
".",
"serverErrors",
")",
";",
"}",
"else",
"{",
"json",
".",
"compiledCode",
"=",
"this",
".",
"_header",
"+",
"json",
".",
"compiledCode",
";",
"if",
"(",
"this",
".",
"file",
")",
"{",
"this",
".",
"_writeOutputTofile",
"(",
"json",
".",
"compiledCode",
")",
";",
"}",
"if",
"(",
"this",
".",
"callback",
")",
"{",
"this",
".",
"callback",
"(",
"(",
"this",
".",
"_passJson",
")",
"?",
"json",
":",
"json",
".",
"compiledCode",
")",
";",
"}",
"if",
"(",
"!",
"this",
".",
"file",
"&&",
"!",
"this",
".",
"callback",
")",
"{",
"this",
".",
"console",
".",
"info",
"(",
"'Code:'",
",",
"json",
".",
"compiledCode",
")",
";",
"}",
"}",
"}"
]
| Handle output JSON object
@param {Object} json
@private | [
"Handle",
"output",
"JSON",
"object"
]
| 680b6a2f18f24fcbce8c71fad6393f7963129d9e | https://github.com/blaise-io/gcc-rest/blob/680b6a2f18f24fcbce8c71fad6393f7963129d9e/gcc-rest.js#L247-L265 |
|
39,838 | blaise-io/gcc-rest | gcc-rest.js | function(response) {
this.console.error('Server responded with error:');
this.console.error('Status', response.statusCode);
this.console.error('Headers', response.headers);
response.on('data', function(chunk) {
this.console.info('Body', chunk);
}.bind(this));
this._errCallback('server_error', response);
} | javascript | function(response) {
this.console.error('Server responded with error:');
this.console.error('Status', response.statusCode);
this.console.error('Headers', response.headers);
response.on('data', function(chunk) {
this.console.info('Body', chunk);
}.bind(this));
this._errCallback('server_error', response);
} | [
"function",
"(",
"response",
")",
"{",
"this",
".",
"console",
".",
"error",
"(",
"'Server responded with error:'",
")",
";",
"this",
".",
"console",
".",
"error",
"(",
"'Status'",
",",
"response",
".",
"statusCode",
")",
";",
"this",
".",
"console",
".",
"error",
"(",
"'Headers'",
",",
"response",
".",
"headers",
")",
";",
"response",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"chunk",
")",
"{",
"this",
".",
"console",
".",
"info",
"(",
"'Body'",
",",
"chunk",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
")",
";",
"this",
".",
"_errCallback",
"(",
"'server_error'",
",",
"response",
")",
";",
"}"
]
| Handle a failed compile request response.
@param {ServerResponse} response
@private | [
"Handle",
"a",
"failed",
"compile",
"request",
"response",
"."
]
| 680b6a2f18f24fcbce8c71fad6393f7963129d9e | https://github.com/blaise-io/gcc-rest/blob/680b6a2f18f24fcbce8c71fad6393f7963129d9e/gcc-rest.js#L284-L292 |
|
39,839 | blaise-io/gcc-rest | gcc-rest.js | function(err) {
var file = fs.realpathSync(this.file);
if (!err) {
this.console.info('Compiled code saved to', file);
} else {
this.console.info('Saving code failed to', file);
}
} | javascript | function(err) {
var file = fs.realpathSync(this.file);
if (!err) {
this.console.info('Compiled code saved to', file);
} else {
this.console.info('Saving code failed to', file);
}
} | [
"function",
"(",
"err",
")",
"{",
"var",
"file",
"=",
"fs",
".",
"realpathSync",
"(",
"this",
".",
"file",
")",
";",
"if",
"(",
"!",
"err",
")",
"{",
"this",
".",
"console",
".",
"info",
"(",
"'Compiled code saved to'",
",",
"file",
")",
";",
"}",
"else",
"{",
"this",
".",
"console",
".",
"info",
"(",
"'Saving code failed to'",
",",
"file",
")",
";",
"}",
"}"
]
| Report result of writing compiled code to file.
@param {string} err
@private | [
"Report",
"result",
"of",
"writing",
"compiled",
"code",
"to",
"file",
"."
]
| 680b6a2f18f24fcbce8c71fad6393f7963129d9e | https://github.com/blaise-io/gcc-rest/blob/680b6a2f18f24fcbce8c71fad6393f7963129d9e/gcc-rest.js#L355-L362 |
|
39,840 | dreampiggy/functional.js | Retroactive/lib/data_structures/heap.js | MinHeap | function MinHeap(compareFn) {
this._elements = [null];
this._comparator = new Comparator(compareFn);
Object.defineProperty(this, 'n', {
get: function () {
return this._elements.length - 1;
}.bind(this)
});
} | javascript | function MinHeap(compareFn) {
this._elements = [null];
this._comparator = new Comparator(compareFn);
Object.defineProperty(this, 'n', {
get: function () {
return this._elements.length - 1;
}.bind(this)
});
} | [
"function",
"MinHeap",
"(",
"compareFn",
")",
"{",
"this",
".",
"_elements",
"=",
"[",
"null",
"]",
";",
"this",
".",
"_comparator",
"=",
"new",
"Comparator",
"(",
"compareFn",
")",
";",
"Object",
".",
"defineProperty",
"(",
"this",
",",
"'n'",
",",
"{",
"get",
":",
"function",
"(",
")",
"{",
"return",
"this",
".",
"_elements",
".",
"length",
"-",
"1",
";",
"}",
".",
"bind",
"(",
"this",
")",
"}",
")",
";",
"}"
]
| Basic Heap structure | [
"Basic",
"Heap",
"structure"
]
| ec7b7213de7965659a8a1e8fa61438e3ae564260 | https://github.com/dreampiggy/functional.js/blob/ec7b7213de7965659a8a1e8fa61438e3ae564260/Retroactive/lib/data_structures/heap.js#L7-L16 |
39,841 | skerit/protoblast | lib/init.js | parseUseragent | function parseUseragent(ua) {
if (!ua) {
return null;
}
let platform,
webview = false,
version,
engine,
result,
major,
minor,
patch,
float,
index,
name,
temp,
os;
ua = ua.toLowerCase();
if (~ua.indexOf('mobile')) {
platform = 'mobile';
} else if (~ua.indexOf('tablet')) {
platform = 'tablet';
} else {
platform = 'desktop';
}
if (~(index = ua.indexOf('msie'))) {
name = 'internet explorer';
platform = 'desktop';
} else if (~(index = ua.indexOf('trident/'))) {
name = 'internet explorer';
platform = 'desktop';
index += 13;
} else if (~(index = ua.indexOf('edge/'))) {
name = 'edge';
engine = 'edgehtml';
} else if (~(index = ua.indexOf('chrome/'))) {
name = 'chrome';
} else if (~(index = ua.indexOf('firefox/'))) {
name = 'firefox';
engine = 'gecko';
} else if (~(index = ua.indexOf('safari/'))) {
name = 'safari';
index = ua.indexOf('version/');
engine = 'webkit';
}
if (~index) {
version = version_rx.exec(ua.slice(index));
if (version) {
float = parseFloat(version[0]);
major = +version[1];
minor = +version[2];
patch = version[3] || '';
}
}
if (!engine) {
switch (name) {
case 'internet explorer':
engine = 'trident';
break;
case 'chrome':
if (major < 28) {
engine = 'webkit';
} else {
engine = 'blink';
}
break;
}
}
if (platform != 'desktop') {
if (~ua.indexOf('iphone') || ~ua.indexOf('ipad') || ~ua.indexOf('ipod')) {
os = 'ios';
if (ua.indexOf('safari') == -1) {
webview = true;
}
} else if (~ua.indexOf('; wv')) {
webview = true;
}
}
result = {
family : name,
version : {
major : major,
minor : minor,
patch : patch,
float : float
},
platform : platform,
engine : engine,
webview : webview,
os : os
};
return result;
} | javascript | function parseUseragent(ua) {
if (!ua) {
return null;
}
let platform,
webview = false,
version,
engine,
result,
major,
minor,
patch,
float,
index,
name,
temp,
os;
ua = ua.toLowerCase();
if (~ua.indexOf('mobile')) {
platform = 'mobile';
} else if (~ua.indexOf('tablet')) {
platform = 'tablet';
} else {
platform = 'desktop';
}
if (~(index = ua.indexOf('msie'))) {
name = 'internet explorer';
platform = 'desktop';
} else if (~(index = ua.indexOf('trident/'))) {
name = 'internet explorer';
platform = 'desktop';
index += 13;
} else if (~(index = ua.indexOf('edge/'))) {
name = 'edge';
engine = 'edgehtml';
} else if (~(index = ua.indexOf('chrome/'))) {
name = 'chrome';
} else if (~(index = ua.indexOf('firefox/'))) {
name = 'firefox';
engine = 'gecko';
} else if (~(index = ua.indexOf('safari/'))) {
name = 'safari';
index = ua.indexOf('version/');
engine = 'webkit';
}
if (~index) {
version = version_rx.exec(ua.slice(index));
if (version) {
float = parseFloat(version[0]);
major = +version[1];
minor = +version[2];
patch = version[3] || '';
}
}
if (!engine) {
switch (name) {
case 'internet explorer':
engine = 'trident';
break;
case 'chrome':
if (major < 28) {
engine = 'webkit';
} else {
engine = 'blink';
}
break;
}
}
if (platform != 'desktop') {
if (~ua.indexOf('iphone') || ~ua.indexOf('ipad') || ~ua.indexOf('ipod')) {
os = 'ios';
if (ua.indexOf('safari') == -1) {
webview = true;
}
} else if (~ua.indexOf('; wv')) {
webview = true;
}
}
result = {
family : name,
version : {
major : major,
minor : minor,
patch : patch,
float : float
},
platform : platform,
engine : engine,
webview : webview,
os : os
};
return result;
} | [
"function",
"parseUseragent",
"(",
"ua",
")",
"{",
"if",
"(",
"!",
"ua",
")",
"{",
"return",
"null",
";",
"}",
"let",
"platform",
",",
"webview",
"=",
"false",
",",
"version",
",",
"engine",
",",
"result",
",",
"major",
",",
"minor",
",",
"patch",
",",
"float",
",",
"index",
",",
"name",
",",
"temp",
",",
"os",
";",
"ua",
"=",
"ua",
".",
"toLowerCase",
"(",
")",
";",
"if",
"(",
"~",
"ua",
".",
"indexOf",
"(",
"'mobile'",
")",
")",
"{",
"platform",
"=",
"'mobile'",
";",
"}",
"else",
"if",
"(",
"~",
"ua",
".",
"indexOf",
"(",
"'tablet'",
")",
")",
"{",
"platform",
"=",
"'tablet'",
";",
"}",
"else",
"{",
"platform",
"=",
"'desktop'",
";",
"}",
"if",
"(",
"~",
"(",
"index",
"=",
"ua",
".",
"indexOf",
"(",
"'msie'",
")",
")",
")",
"{",
"name",
"=",
"'internet explorer'",
";",
"platform",
"=",
"'desktop'",
";",
"}",
"else",
"if",
"(",
"~",
"(",
"index",
"=",
"ua",
".",
"indexOf",
"(",
"'trident/'",
")",
")",
")",
"{",
"name",
"=",
"'internet explorer'",
";",
"platform",
"=",
"'desktop'",
";",
"index",
"+=",
"13",
";",
"}",
"else",
"if",
"(",
"~",
"(",
"index",
"=",
"ua",
".",
"indexOf",
"(",
"'edge/'",
")",
")",
")",
"{",
"name",
"=",
"'edge'",
";",
"engine",
"=",
"'edgehtml'",
";",
"}",
"else",
"if",
"(",
"~",
"(",
"index",
"=",
"ua",
".",
"indexOf",
"(",
"'chrome/'",
")",
")",
")",
"{",
"name",
"=",
"'chrome'",
";",
"}",
"else",
"if",
"(",
"~",
"(",
"index",
"=",
"ua",
".",
"indexOf",
"(",
"'firefox/'",
")",
")",
")",
"{",
"name",
"=",
"'firefox'",
";",
"engine",
"=",
"'gecko'",
";",
"}",
"else",
"if",
"(",
"~",
"(",
"index",
"=",
"ua",
".",
"indexOf",
"(",
"'safari/'",
")",
")",
")",
"{",
"name",
"=",
"'safari'",
";",
"index",
"=",
"ua",
".",
"indexOf",
"(",
"'version/'",
")",
";",
"engine",
"=",
"'webkit'",
";",
"}",
"if",
"(",
"~",
"index",
")",
"{",
"version",
"=",
"version_rx",
".",
"exec",
"(",
"ua",
".",
"slice",
"(",
"index",
")",
")",
";",
"if",
"(",
"version",
")",
"{",
"float",
"=",
"parseFloat",
"(",
"version",
"[",
"0",
"]",
")",
";",
"major",
"=",
"+",
"version",
"[",
"1",
"]",
";",
"minor",
"=",
"+",
"version",
"[",
"2",
"]",
";",
"patch",
"=",
"version",
"[",
"3",
"]",
"||",
"''",
";",
"}",
"}",
"if",
"(",
"!",
"engine",
")",
"{",
"switch",
"(",
"name",
")",
"{",
"case",
"'internet explorer'",
":",
"engine",
"=",
"'trident'",
";",
"break",
";",
"case",
"'chrome'",
":",
"if",
"(",
"major",
"<",
"28",
")",
"{",
"engine",
"=",
"'webkit'",
";",
"}",
"else",
"{",
"engine",
"=",
"'blink'",
";",
"}",
"break",
";",
"}",
"}",
"if",
"(",
"platform",
"!=",
"'desktop'",
")",
"{",
"if",
"(",
"~",
"ua",
".",
"indexOf",
"(",
"'iphone'",
")",
"||",
"~",
"ua",
".",
"indexOf",
"(",
"'ipad'",
")",
"||",
"~",
"ua",
".",
"indexOf",
"(",
"'ipod'",
")",
")",
"{",
"os",
"=",
"'ios'",
";",
"if",
"(",
"ua",
".",
"indexOf",
"(",
"'safari'",
")",
"==",
"-",
"1",
")",
"{",
"webview",
"=",
"true",
";",
"}",
"}",
"else",
"if",
"(",
"~",
"ua",
".",
"indexOf",
"(",
"'; wv'",
")",
")",
"{",
"webview",
"=",
"true",
";",
"}",
"}",
"result",
"=",
"{",
"family",
":",
"name",
",",
"version",
":",
"{",
"major",
":",
"major",
",",
"minor",
":",
"minor",
",",
"patch",
":",
"patch",
",",
"float",
":",
"float",
"}",
",",
"platform",
":",
"platform",
",",
"engine",
":",
"engine",
",",
"webview",
":",
"webview",
",",
"os",
":",
"os",
"}",
";",
"return",
"result",
";",
"}"
]
| Parse a useragent string
@author Jelle De Loecker <[email protected]>
@since 0.6.6
@version 0.6.6
@param {String} useragent
@return {Object} | [
"Parse",
"a",
"useragent",
"string"
]
| 22f35b05611bd507d380782023179a3f6ec383ae | https://github.com/skerit/protoblast/blob/22f35b05611bd507d380782023179a3f6ec383ae/lib/init.js#L44-L149 |
39,842 | skerit/protoblast | lib/init.js | clearAndDoTasks | function clearAndDoTasks(arr) {
var tasks = arr.slice(0),
i;
// Clear the original array
arr.length = 0;
for (i = 0; i < tasks.length; i++) {
tasks[i]();
}
} | javascript | function clearAndDoTasks(arr) {
var tasks = arr.slice(0),
i;
// Clear the original array
arr.length = 0;
for (i = 0; i < tasks.length; i++) {
tasks[i]();
}
} | [
"function",
"clearAndDoTasks",
"(",
"arr",
")",
"{",
"var",
"tasks",
"=",
"arr",
".",
"slice",
"(",
"0",
")",
",",
"i",
";",
"// Clear the original array",
"arr",
".",
"length",
"=",
"0",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"tasks",
".",
"length",
";",
"i",
"++",
")",
"{",
"tasks",
"[",
"i",
"]",
"(",
")",
";",
"}",
"}"
]
| Do the tasks in an array
@author Jelle De Loecker <[email protected]>
@since 0.6.5
@version 0.6.5 | [
"Do",
"the",
"tasks",
"in",
"an",
"array"
]
| 22f35b05611bd507d380782023179a3f6ec383ae | https://github.com/skerit/protoblast/blob/22f35b05611bd507d380782023179a3f6ec383ae/lib/init.js#L1175-L1186 |
39,843 | skerit/protoblast | lib/init.js | checkNextRequire | function checkNextRequire(options) {
if (!modulep) {
return;
}
if (options.strict === false) {
return;
}
// Overwrite the original wrap method
modulep.wrap = function wrap(script) {
var head;
// Restore the original functions
modulep.wrap = modulep.original_wrap;
modulep._resolveFilename = modulep.original_resolve;
if (options.add_wrapper !== false) {
if (options.add_wrapper || script.slice(0, 14) != 'module.exports') {
if (script.indexOf('__cov_') > -1 && script.indexOf('module.exports=function ') > 7) {
// We're in coverage mode, just ignore
} else {
// Yes: "added_wrapper", as in "done"
options.added_wrapper = true;
head = 'module.exports = function(';
if (options.arguments) {
head += Blast.getArgumentConfiguration(options.arguments).names.join(',');
} else {
head += 'Blast, Collection, Bound, Obj';
}
head += ') {';
script = head + script + '\n};';
}
}
}
// Add the strict wrapper for this requirement
return modulep.strict_wrapper + script + modulep.wrapper[1];
};
// Overwrite the original _resolveFilename method
modulep._resolveFilename = function _resolveFilename(request, parent, is_main) {
try {
return modulep.original_resolve(request, parent, is_main);
} catch (err) {
modulep.wrap = modulep.original_wrap;
modulep._resolveFilename = modulep.original_resolve;
throw err;
}
};
} | javascript | function checkNextRequire(options) {
if (!modulep) {
return;
}
if (options.strict === false) {
return;
}
// Overwrite the original wrap method
modulep.wrap = function wrap(script) {
var head;
// Restore the original functions
modulep.wrap = modulep.original_wrap;
modulep._resolveFilename = modulep.original_resolve;
if (options.add_wrapper !== false) {
if (options.add_wrapper || script.slice(0, 14) != 'module.exports') {
if (script.indexOf('__cov_') > -1 && script.indexOf('module.exports=function ') > 7) {
// We're in coverage mode, just ignore
} else {
// Yes: "added_wrapper", as in "done"
options.added_wrapper = true;
head = 'module.exports = function(';
if (options.arguments) {
head += Blast.getArgumentConfiguration(options.arguments).names.join(',');
} else {
head += 'Blast, Collection, Bound, Obj';
}
head += ') {';
script = head + script + '\n};';
}
}
}
// Add the strict wrapper for this requirement
return modulep.strict_wrapper + script + modulep.wrapper[1];
};
// Overwrite the original _resolveFilename method
modulep._resolveFilename = function _resolveFilename(request, parent, is_main) {
try {
return modulep.original_resolve(request, parent, is_main);
} catch (err) {
modulep.wrap = modulep.original_wrap;
modulep._resolveFilename = modulep.original_resolve;
throw err;
}
};
} | [
"function",
"checkNextRequire",
"(",
"options",
")",
"{",
"if",
"(",
"!",
"modulep",
")",
"{",
"return",
";",
"}",
"if",
"(",
"options",
".",
"strict",
"===",
"false",
")",
"{",
"return",
";",
"}",
"// Overwrite the original wrap method",
"modulep",
".",
"wrap",
"=",
"function",
"wrap",
"(",
"script",
")",
"{",
"var",
"head",
";",
"// Restore the original functions",
"modulep",
".",
"wrap",
"=",
"modulep",
".",
"original_wrap",
";",
"modulep",
".",
"_resolveFilename",
"=",
"modulep",
".",
"original_resolve",
";",
"if",
"(",
"options",
".",
"add_wrapper",
"!==",
"false",
")",
"{",
"if",
"(",
"options",
".",
"add_wrapper",
"||",
"script",
".",
"slice",
"(",
"0",
",",
"14",
")",
"!=",
"'module.exports'",
")",
"{",
"if",
"(",
"script",
".",
"indexOf",
"(",
"'__cov_'",
")",
">",
"-",
"1",
"&&",
"script",
".",
"indexOf",
"(",
"'module.exports=function '",
")",
">",
"7",
")",
"{",
"// We're in coverage mode, just ignore",
"}",
"else",
"{",
"// Yes: \"added_wrapper\", as in \"done\"",
"options",
".",
"added_wrapper",
"=",
"true",
";",
"head",
"=",
"'module.exports = function('",
";",
"if",
"(",
"options",
".",
"arguments",
")",
"{",
"head",
"+=",
"Blast",
".",
"getArgumentConfiguration",
"(",
"options",
".",
"arguments",
")",
".",
"names",
".",
"join",
"(",
"','",
")",
";",
"}",
"else",
"{",
"head",
"+=",
"'Blast, Collection, Bound, Obj'",
";",
"}",
"head",
"+=",
"') {'",
";",
"script",
"=",
"head",
"+",
"script",
"+",
"'\\n};'",
";",
"}",
"}",
"}",
"// Add the strict wrapper for this requirement",
"return",
"modulep",
".",
"strict_wrapper",
"+",
"script",
"+",
"modulep",
".",
"wrapper",
"[",
"1",
"]",
";",
"}",
";",
"// Overwrite the original _resolveFilename method",
"modulep",
".",
"_resolveFilename",
"=",
"function",
"_resolveFilename",
"(",
"request",
",",
"parent",
",",
"is_main",
")",
"{",
"try",
"{",
"return",
"modulep",
".",
"original_resolve",
"(",
"request",
",",
"parent",
",",
"is_main",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"modulep",
".",
"wrap",
"=",
"modulep",
".",
"original_wrap",
";",
"modulep",
".",
"_resolveFilename",
"=",
"modulep",
".",
"original_resolve",
";",
"throw",
"err",
";",
"}",
"}",
";",
"}"
]
| PROTOBLAST START CUT
Check require call
@author Jelle De Loecker <[email protected]>
@version 0.6.6
@param {Object} options | [
"PROTOBLAST",
"START",
"CUT",
"Check",
"require",
"call"
]
| 22f35b05611bd507d380782023179a3f6ec383ae | https://github.com/skerit/protoblast/blob/22f35b05611bd507d380782023179a3f6ec383ae/lib/init.js#L1348-L1405 |
39,844 | jprichardson/node-dq | lib/dq.js | Queue | function Queue (name, redisClient) {
this.hasQuit = false
this._name = name
this.redisClient = redisClient
this._key = Queue.PREFIX + this.name
} | javascript | function Queue (name, redisClient) {
this.hasQuit = false
this._name = name
this.redisClient = redisClient
this._key = Queue.PREFIX + this.name
} | [
"function",
"Queue",
"(",
"name",
",",
"redisClient",
")",
"{",
"this",
".",
"hasQuit",
"=",
"false",
"this",
".",
"_name",
"=",
"name",
"this",
".",
"redisClient",
"=",
"redisClient",
"this",
".",
"_key",
"=",
"Queue",
".",
"PREFIX",
"+",
"this",
".",
"name",
"}"
]
| redis.debug_mode = true | [
"redis",
".",
"debug_mode",
"=",
"true"
]
| 1e8fe3cd14ae54b05d2cdf1bc8d56c1fccdb2f3d | https://github.com/jprichardson/node-dq/blob/1e8fe3cd14ae54b05d2cdf1bc8d56c1fccdb2f3d/lib/dq.js#L5-L10 |
39,845 | EikosPartners/scalejs | dist/scalejs.base.array.js | removeOne | function removeOne(array, item) {
var found = array.indexOf(item);
if (found > -1) {
array.splice(found, 1);
}
} | javascript | function removeOne(array, item) {
var found = array.indexOf(item);
if (found > -1) {
array.splice(found, 1);
}
} | [
"function",
"removeOne",
"(",
"array",
",",
"item",
")",
"{",
"var",
"found",
"=",
"array",
".",
"indexOf",
"(",
"item",
")",
";",
"if",
"(",
"found",
">",
"-",
"1",
")",
"{",
"array",
".",
"splice",
"(",
"found",
",",
"1",
")",
";",
"}",
"}"
]
| Removes the first occurrance of the passed item from the passed array
@param {Array} array list remove the item from
@param {Any} item item to be removed from the list
@memberOf array | [
"Removes",
"the",
"first",
"occurrance",
"of",
"the",
"passed",
"item",
"from",
"the",
"passed",
"array"
]
| 115d0eac1a90aebb54f50485ed92de25165f9c30 | https://github.com/EikosPartners/scalejs/blob/115d0eac1a90aebb54f50485ed92de25165f9c30/dist/scalejs.base.array.js#L42-L47 |
39,846 | EikosPartners/scalejs | dist/scalejs.base.array.js | copy | function copy(array, first, count) {
first = valueOrDefault(first, 0);
count = valueOrDefault(count, array.length);
return Array.prototype.slice.call(array, first, count);
} | javascript | function copy(array, first, count) {
first = valueOrDefault(first, 0);
count = valueOrDefault(count, array.length);
return Array.prototype.slice.call(array, first, count);
} | [
"function",
"copy",
"(",
"array",
",",
"first",
",",
"count",
")",
"{",
"first",
"=",
"valueOrDefault",
"(",
"first",
",",
"0",
")",
";",
"count",
"=",
"valueOrDefault",
"(",
"count",
",",
"array",
".",
"length",
")",
";",
"return",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"array",
",",
"first",
",",
"count",
")",
";",
"}"
]
| Copy the items from the array into a new one
@param {Array} array list to copy from
@param {Number} [first] starting index to copy from (defult:0)
@param {Number} [count] number of items to copy (default:array.length)
@memberOf array
@return {Array} copied list | [
"Copy",
"the",
"items",
"from",
"the",
"array",
"into",
"a",
"new",
"one"
]
| 115d0eac1a90aebb54f50485ed92de25165f9c30 | https://github.com/EikosPartners/scalejs/blob/115d0eac1a90aebb54f50485ed92de25165f9c30/dist/scalejs.base.array.js#L68-L72 |
39,847 | EikosPartners/scalejs | dist/scalejs.base.array.js | find | function find(array, f, context) {
var i, // iterative variable
l; // array length variable
for (i = 0, l = array.length; i < l; i += 1) {
if (array.hasOwnProperty(i) && f.call(context, array[i], i, array)) {
return array[i];
}
}
return null;
} | javascript | function find(array, f, context) {
var i, // iterative variable
l; // array length variable
for (i = 0, l = array.length; i < l; i += 1) {
if (array.hasOwnProperty(i) && f.call(context, array[i], i, array)) {
return array[i];
}
}
return null;
} | [
"function",
"find",
"(",
"array",
",",
"f",
",",
"context",
")",
"{",
"var",
"i",
",",
"// iterative variable",
"l",
";",
"// array length variable",
"for",
"(",
"i",
"=",
"0",
",",
"l",
"=",
"array",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"+=",
"1",
")",
"{",
"if",
"(",
"array",
".",
"hasOwnProperty",
"(",
"i",
")",
"&&",
"f",
".",
"call",
"(",
"context",
",",
"array",
"[",
"i",
"]",
",",
"i",
",",
"array",
")",
")",
"{",
"return",
"array",
"[",
"i",
"]",
";",
"}",
"}",
"return",
"null",
";",
"}"
]
| Finds the passed item in the array
@param {Array} array list in which to search
@param {Function} f function to seach with
@param {Any} content context on which to call the function
@memberOf array
@return {Any|Object} item if found, null if not | [
"Finds",
"the",
"passed",
"item",
"in",
"the",
"array"
]
| 115d0eac1a90aebb54f50485ed92de25165f9c30 | https://github.com/EikosPartners/scalejs/blob/115d0eac1a90aebb54f50485ed92de25165f9c30/dist/scalejs.base.array.js#L83-L94 |
39,848 | stezu/node-stream | lib/modifiers/batch.js | batch | function batch(options) {
var validationError = validateOptions(options);
var settings = _.extend({
time: 0,
count: 0
}, options);
var cache = [];
var lastWrite = 0;
var timeout;
/**
* @private
* @description
* Writes all the collected data to the stream.
*
* @param {Stream} stream - The stream to write to.
* @returns {undefined}
*/
function flushCache(stream) {
lastWrite = Date.now();
if (timeout) {
clearTimeout(timeout);
timeout = null;
}
stream.push(cache.splice(0, settings.count || cache.length));
}
/**
* @private
* @description
* Flushes the cache using the defined timeout.
*
* @param {Stream} stream - The stream to write to.
* @param {Function} onFlush - The function to call when
* the cache is flushed.
* @returns {undefined}
*/
function flushCacheTimed(stream, onFlush) {
var nextWrite = lastWrite + settings.time;
var now = Date.now();
// we are overdue for a write, so write now
if (now >= nextWrite) {
flushCache(stream);
onFlush();
return;
}
// write after the remainder between now and when
// the next write should be according to milliseconds
// and the previous write
timeout = setTimeout(function () {
flushCache(stream);
onFlush();
}, nextWrite - now);
}
/**
* @private
* @description
* Flushes the cache if it is appropriate to do so.
*
* @param {Stream} stream - The stream to write to.
* @returns {undefined}
*/
function writeIfPossible(stream) {
if (
// we don't have a count or a time set,
(!settings.count && !settings.time) ||
// the count has been met
(settings.count && cache.length === settings.count)
) {
flushCache(stream);
return;
}
if (settings.time && !timeout) {
flushCacheTimed(stream, _.noop);
}
}
return through.obj(function Transform(data, enc, cb) {
var self = this;
if (validationError) {
cb(validationError);
return;
}
// initialize now if it is not yet initialized, so that we
// start time batching from now on
if (!lastWrite) {
lastWrite = Date.now();
}
cache.push(data);
writeIfPossible(self);
cb();
}, function Flush(cb) {
var self = this;
if (timeout) {
clearTimeout(timeout);
}
if (cache.length === 0) {
return cb();
}
return flushCacheTimed(self, cb);
});
} | javascript | function batch(options) {
var validationError = validateOptions(options);
var settings = _.extend({
time: 0,
count: 0
}, options);
var cache = [];
var lastWrite = 0;
var timeout;
/**
* @private
* @description
* Writes all the collected data to the stream.
*
* @param {Stream} stream - The stream to write to.
* @returns {undefined}
*/
function flushCache(stream) {
lastWrite = Date.now();
if (timeout) {
clearTimeout(timeout);
timeout = null;
}
stream.push(cache.splice(0, settings.count || cache.length));
}
/**
* @private
* @description
* Flushes the cache using the defined timeout.
*
* @param {Stream} stream - The stream to write to.
* @param {Function} onFlush - The function to call when
* the cache is flushed.
* @returns {undefined}
*/
function flushCacheTimed(stream, onFlush) {
var nextWrite = lastWrite + settings.time;
var now = Date.now();
// we are overdue for a write, so write now
if (now >= nextWrite) {
flushCache(stream);
onFlush();
return;
}
// write after the remainder between now and when
// the next write should be according to milliseconds
// and the previous write
timeout = setTimeout(function () {
flushCache(stream);
onFlush();
}, nextWrite - now);
}
/**
* @private
* @description
* Flushes the cache if it is appropriate to do so.
*
* @param {Stream} stream - The stream to write to.
* @returns {undefined}
*/
function writeIfPossible(stream) {
if (
// we don't have a count or a time set,
(!settings.count && !settings.time) ||
// the count has been met
(settings.count && cache.length === settings.count)
) {
flushCache(stream);
return;
}
if (settings.time && !timeout) {
flushCacheTimed(stream, _.noop);
}
}
return through.obj(function Transform(data, enc, cb) {
var self = this;
if (validationError) {
cb(validationError);
return;
}
// initialize now if it is not yet initialized, so that we
// start time batching from now on
if (!lastWrite) {
lastWrite = Date.now();
}
cache.push(data);
writeIfPossible(self);
cb();
}, function Flush(cb) {
var self = this;
if (timeout) {
clearTimeout(timeout);
}
if (cache.length === 0) {
return cb();
}
return flushCacheTimed(self, cb);
});
} | [
"function",
"batch",
"(",
"options",
")",
"{",
"var",
"validationError",
"=",
"validateOptions",
"(",
"options",
")",
";",
"var",
"settings",
"=",
"_",
".",
"extend",
"(",
"{",
"time",
":",
"0",
",",
"count",
":",
"0",
"}",
",",
"options",
")",
";",
"var",
"cache",
"=",
"[",
"]",
";",
"var",
"lastWrite",
"=",
"0",
";",
"var",
"timeout",
";",
"/**\n * @private\n * @description\n * Writes all the collected data to the stream.\n *\n * @param {Stream} stream - The stream to write to.\n * @returns {undefined}\n */",
"function",
"flushCache",
"(",
"stream",
")",
"{",
"lastWrite",
"=",
"Date",
".",
"now",
"(",
")",
";",
"if",
"(",
"timeout",
")",
"{",
"clearTimeout",
"(",
"timeout",
")",
";",
"timeout",
"=",
"null",
";",
"}",
"stream",
".",
"push",
"(",
"cache",
".",
"splice",
"(",
"0",
",",
"settings",
".",
"count",
"||",
"cache",
".",
"length",
")",
")",
";",
"}",
"/**\n * @private\n * @description\n * Flushes the cache using the defined timeout.\n *\n * @param {Stream} stream - The stream to write to.\n * @param {Function} onFlush - The function to call when\n * the cache is flushed.\n * @returns {undefined}\n */",
"function",
"flushCacheTimed",
"(",
"stream",
",",
"onFlush",
")",
"{",
"var",
"nextWrite",
"=",
"lastWrite",
"+",
"settings",
".",
"time",
";",
"var",
"now",
"=",
"Date",
".",
"now",
"(",
")",
";",
"// we are overdue for a write, so write now",
"if",
"(",
"now",
">=",
"nextWrite",
")",
"{",
"flushCache",
"(",
"stream",
")",
";",
"onFlush",
"(",
")",
";",
"return",
";",
"}",
"// write after the remainder between now and when",
"// the next write should be according to milliseconds",
"// and the previous write",
"timeout",
"=",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"flushCache",
"(",
"stream",
")",
";",
"onFlush",
"(",
")",
";",
"}",
",",
"nextWrite",
"-",
"now",
")",
";",
"}",
"/**\n * @private\n * @description\n * Flushes the cache if it is appropriate to do so.\n *\n * @param {Stream} stream - The stream to write to.\n * @returns {undefined}\n */",
"function",
"writeIfPossible",
"(",
"stream",
")",
"{",
"if",
"(",
"// we don't have a count or a time set,",
"(",
"!",
"settings",
".",
"count",
"&&",
"!",
"settings",
".",
"time",
")",
"||",
"// the count has been met",
"(",
"settings",
".",
"count",
"&&",
"cache",
".",
"length",
"===",
"settings",
".",
"count",
")",
")",
"{",
"flushCache",
"(",
"stream",
")",
";",
"return",
";",
"}",
"if",
"(",
"settings",
".",
"time",
"&&",
"!",
"timeout",
")",
"{",
"flushCacheTimed",
"(",
"stream",
",",
"_",
".",
"noop",
")",
";",
"}",
"}",
"return",
"through",
".",
"obj",
"(",
"function",
"Transform",
"(",
"data",
",",
"enc",
",",
"cb",
")",
"{",
"var",
"self",
"=",
"this",
";",
"if",
"(",
"validationError",
")",
"{",
"cb",
"(",
"validationError",
")",
";",
"return",
";",
"}",
"// initialize now if it is not yet initialized, so that we",
"// start time batching from now on",
"if",
"(",
"!",
"lastWrite",
")",
"{",
"lastWrite",
"=",
"Date",
".",
"now",
"(",
")",
";",
"}",
"cache",
".",
"push",
"(",
"data",
")",
";",
"writeIfPossible",
"(",
"self",
")",
";",
"cb",
"(",
")",
";",
"}",
",",
"function",
"Flush",
"(",
"cb",
")",
"{",
"var",
"self",
"=",
"this",
";",
"if",
"(",
"timeout",
")",
"{",
"clearTimeout",
"(",
"timeout",
")",
";",
"}",
"if",
"(",
"cache",
".",
"length",
"===",
"0",
")",
"{",
"return",
"cb",
"(",
")",
";",
"}",
"return",
"flushCacheTimed",
"(",
"self",
",",
"cb",
")",
";",
"}",
")",
";",
"}"
]
| Returns a new stream that batches writes based on a specific interval, count of items, or both.
All items read on the stream and will be re-emitted as part of an array of one or more items
based on the criteria defined in the options.
@method
@static
@since 1.5.0
@category Modifiers
@param {Object} [options] - Define how items will be batched and written to the
the stream. Note that when both `time` and `count` are
defined, items will be written to the stream whenever
either one of the conditions is met.
@param {Number} [options.time=0] - The interval, in milliseconds, to limit writes to.
During that time, all items read on the stream will
be collected and written as an array at the set
interval.
@param {Number} [options.count=1] - The number of items to buffer before writing all
of them in an array.
@returns {Stream.Transform} - Transform stream.
@example
const input = nodeStream.through.obj();
input.pipe(nodeStream.batch({ time: 100 }));
input.write(1);
setTimeout(function() {
input.write(2);
input.write(3);
}, 100);
setTimeout(function() {
input.write(4);
input.write(5);
}, 200);
// => [[1], [2, 3], [4, 5]]
@example
const input = nodeStream.through.obj();
input.pipe(nodeStream.batch({ count: 2 }));
input.write(1);
input.write(2);
input.write(3);
input.write(4);
input.write(5);
// => [[1, 2], [3, 4], [5]] | [
"Returns",
"a",
"new",
"stream",
"that",
"batches",
"writes",
"based",
"on",
"a",
"specific",
"interval",
"count",
"of",
"items",
"or",
"both",
".",
"All",
"items",
"read",
"on",
"the",
"stream",
"and",
"will",
"be",
"re",
"-",
"emitted",
"as",
"part",
"of",
"an",
"array",
"of",
"one",
"or",
"more",
"items",
"based",
"on",
"the",
"criteria",
"defined",
"in",
"the",
"options",
"."
]
| f70c03351746c958865a854f614932f1df441b9b | https://github.com/stezu/node-stream/blob/f70c03351746c958865a854f614932f1df441b9b/lib/modifiers/batch.js#L112-L232 |
39,849 | noderaider/repackage | jspm_packages/npm/[email protected]/lib/generation/generators/expressions.js | ConditionalExpression | function ConditionalExpression(node, print) {
print.plain(node.test);
this.space();
this.push("?");
this.space();
print.plain(node.consequent);
this.space();
this.push(":");
this.space();
print.plain(node.alternate);
} | javascript | function ConditionalExpression(node, print) {
print.plain(node.test);
this.space();
this.push("?");
this.space();
print.plain(node.consequent);
this.space();
this.push(":");
this.space();
print.plain(node.alternate);
} | [
"function",
"ConditionalExpression",
"(",
"node",
",",
"print",
")",
"{",
"print",
".",
"plain",
"(",
"node",
".",
"test",
")",
";",
"this",
".",
"space",
"(",
")",
";",
"this",
".",
"push",
"(",
"\"?\"",
")",
";",
"this",
".",
"space",
"(",
")",
";",
"print",
".",
"plain",
"(",
"node",
".",
"consequent",
")",
";",
"this",
".",
"space",
"(",
")",
";",
"this",
".",
"push",
"(",
"\":\"",
")",
";",
"this",
".",
"space",
"(",
")",
";",
"print",
".",
"plain",
"(",
"node",
".",
"alternate",
")",
";",
"}"
]
| Prints ConditionalExpression, prints test, consequent, and alternate. | [
"Prints",
"ConditionalExpression",
"prints",
"test",
"consequent",
"and",
"alternate",
"."
]
| 9f14246db3327abb0c4a5d7a3d55bd7816ebbd40 | https://github.com/noderaider/repackage/blob/9f14246db3327abb0c4a5d7a3d55bd7816ebbd40/jspm_packages/npm/[email protected]/lib/generation/generators/expressions.js#L121-L131 |
39,850 | noderaider/repackage | jspm_packages/npm/[email protected]/lib/generation/generators/expressions.js | AssignmentPattern | function AssignmentPattern(node, print) {
print.plain(node.left);
this.push(" = ");
print.plain(node.right);
} | javascript | function AssignmentPattern(node, print) {
print.plain(node.left);
this.push(" = ");
print.plain(node.right);
} | [
"function",
"AssignmentPattern",
"(",
"node",
",",
"print",
")",
"{",
"print",
".",
"plain",
"(",
"node",
".",
"left",
")",
";",
"this",
".",
"push",
"(",
"\" = \"",
")",
";",
"print",
".",
"plain",
"(",
"node",
".",
"right",
")",
";",
"}"
]
| Prints AssignmentPattern, prints left and right. | [
"Prints",
"AssignmentPattern",
"prints",
"left",
"and",
"right",
"."
]
| 9f14246db3327abb0c4a5d7a3d55bd7816ebbd40 | https://github.com/noderaider/repackage/blob/9f14246db3327abb0c4a5d7a3d55bd7816ebbd40/jspm_packages/npm/[email protected]/lib/generation/generators/expressions.js#L259-L263 |
39,851 | noderaider/repackage | jspm_packages/npm/[email protected]/lib/generation/generators/expressions.js | AssignmentExpression | function AssignmentExpression(node, print, parent) {
// Somewhere inside a for statement `init` node but doesn't usually
// needs a paren except for `in` expressions: `for (a in b ? a : b;;)`
var parens = this._inForStatementInit && node.operator === "in" && !_node2["default"].needsParens(node, parent);
if (parens) {
this.push("(");
}
// todo: add cases where the spaces can be dropped when in compact mode
print.plain(node.left);
var spaces = node.operator === "in" || node.operator === "instanceof";
spaces = true; // todo: https://github.com/babel/babel/issues/1835
this.space(spaces);
this.push(node.operator);
if (!spaces) {
// space is mandatory to avoid outputting <!--
// http://javascript.spec.whatwg.org/#comment-syntax
spaces = node.operator === "<" && t.isUnaryExpression(node.right, { prefix: true, operator: "!" }) && t.isUnaryExpression(node.right.argument, { prefix: true, operator: "--" });
}
this.space(spaces);
print.plain(node.right);
if (parens) {
this.push(")");
}
} | javascript | function AssignmentExpression(node, print, parent) {
// Somewhere inside a for statement `init` node but doesn't usually
// needs a paren except for `in` expressions: `for (a in b ? a : b;;)`
var parens = this._inForStatementInit && node.operator === "in" && !_node2["default"].needsParens(node, parent);
if (parens) {
this.push("(");
}
// todo: add cases where the spaces can be dropped when in compact mode
print.plain(node.left);
var spaces = node.operator === "in" || node.operator === "instanceof";
spaces = true; // todo: https://github.com/babel/babel/issues/1835
this.space(spaces);
this.push(node.operator);
if (!spaces) {
// space is mandatory to avoid outputting <!--
// http://javascript.spec.whatwg.org/#comment-syntax
spaces = node.operator === "<" && t.isUnaryExpression(node.right, { prefix: true, operator: "!" }) && t.isUnaryExpression(node.right.argument, { prefix: true, operator: "--" });
}
this.space(spaces);
print.plain(node.right);
if (parens) {
this.push(")");
}
} | [
"function",
"AssignmentExpression",
"(",
"node",
",",
"print",
",",
"parent",
")",
"{",
"// Somewhere inside a for statement `init` node but doesn't usually",
"// needs a paren except for `in` expressions: `for (a in b ? a : b;;)`",
"var",
"parens",
"=",
"this",
".",
"_inForStatementInit",
"&&",
"node",
".",
"operator",
"===",
"\"in\"",
"&&",
"!",
"_node2",
"[",
"\"default\"",
"]",
".",
"needsParens",
"(",
"node",
",",
"parent",
")",
";",
"if",
"(",
"parens",
")",
"{",
"this",
".",
"push",
"(",
"\"(\"",
")",
";",
"}",
"// todo: add cases where the spaces can be dropped when in compact mode",
"print",
".",
"plain",
"(",
"node",
".",
"left",
")",
";",
"var",
"spaces",
"=",
"node",
".",
"operator",
"===",
"\"in\"",
"||",
"node",
".",
"operator",
"===",
"\"instanceof\"",
";",
"spaces",
"=",
"true",
";",
"// todo: https://github.com/babel/babel/issues/1835",
"this",
".",
"space",
"(",
"spaces",
")",
";",
"this",
".",
"push",
"(",
"node",
".",
"operator",
")",
";",
"if",
"(",
"!",
"spaces",
")",
"{",
"// space is mandatory to avoid outputting <!--",
"// http://javascript.spec.whatwg.org/#comment-syntax",
"spaces",
"=",
"node",
".",
"operator",
"===",
"\"<\"",
"&&",
"t",
".",
"isUnaryExpression",
"(",
"node",
".",
"right",
",",
"{",
"prefix",
":",
"true",
",",
"operator",
":",
"\"!\"",
"}",
")",
"&&",
"t",
".",
"isUnaryExpression",
"(",
"node",
".",
"right",
".",
"argument",
",",
"{",
"prefix",
":",
"true",
",",
"operator",
":",
"\"--\"",
"}",
")",
";",
"}",
"this",
".",
"space",
"(",
"spaces",
")",
";",
"print",
".",
"plain",
"(",
"node",
".",
"right",
")",
";",
"if",
"(",
"parens",
")",
"{",
"this",
".",
"push",
"(",
"\")\"",
")",
";",
"}",
"}"
]
| Prints AssignmentExpression, prints left, operator, and right. | [
"Prints",
"AssignmentExpression",
"prints",
"left",
"operator",
"and",
"right",
"."
]
| 9f14246db3327abb0c4a5d7a3d55bd7816ebbd40 | https://github.com/noderaider/repackage/blob/9f14246db3327abb0c4a5d7a3d55bd7816ebbd40/jspm_packages/npm/[email protected]/lib/generation/generators/expressions.js#L269-L300 |
39,852 | noderaider/repackage | jspm_packages/npm/[email protected]/lib/generation/generators/expressions.js | BindExpression | function BindExpression(node, print) {
print.plain(node.object);
this.push("::");
print.plain(node.callee);
} | javascript | function BindExpression(node, print) {
print.plain(node.object);
this.push("::");
print.plain(node.callee);
} | [
"function",
"BindExpression",
"(",
"node",
",",
"print",
")",
"{",
"print",
".",
"plain",
"(",
"node",
".",
"object",
")",
";",
"this",
".",
"push",
"(",
"\"::\"",
")",
";",
"print",
".",
"plain",
"(",
"node",
".",
"callee",
")",
";",
"}"
]
| Prints BindExpression, prints object and callee. | [
"Prints",
"BindExpression",
"prints",
"object",
"and",
"callee",
"."
]
| 9f14246db3327abb0c4a5d7a3d55bd7816ebbd40 | https://github.com/noderaider/repackage/blob/9f14246db3327abb0c4a5d7a3d55bd7816ebbd40/jspm_packages/npm/[email protected]/lib/generation/generators/expressions.js#L306-L310 |
39,853 | dreampiggy/functional.js | Retroactive/lib/data_structures/linked_list.js | LinkedList | function LinkedList() {
this._length = 0;
this.head = null;
this.tail = null;
// Read-only length property
Object.defineProperty(this, 'length', {
get: function () {
return this._length;
}.bind(this)
});
} | javascript | function LinkedList() {
this._length = 0;
this.head = null;
this.tail = null;
// Read-only length property
Object.defineProperty(this, 'length', {
get: function () {
return this._length;
}.bind(this)
});
} | [
"function",
"LinkedList",
"(",
")",
"{",
"this",
".",
"_length",
"=",
"0",
";",
"this",
".",
"head",
"=",
"null",
";",
"this",
".",
"tail",
"=",
"null",
";",
"// Read-only length property",
"Object",
".",
"defineProperty",
"(",
"this",
",",
"'length'",
",",
"{",
"get",
":",
"function",
"(",
")",
"{",
"return",
"this",
".",
"_length",
";",
"}",
".",
"bind",
"(",
"this",
")",
"}",
")",
";",
"}"
]
| Doubly-linked list | [
"Doubly",
"-",
"linked",
"list"
]
| ec7b7213de7965659a8a1e8fa61438e3ae564260 | https://github.com/dreampiggy/functional.js/blob/ec7b7213de7965659a8a1e8fa61438e3ae564260/Retroactive/lib/data_structures/linked_list.js#L6-L18 |
39,854 | aplib/processor.js | processor.js | function(object, __type, parameters, args) {
if (parameters) {
object.id = parameters.id || (parameters.id = (processor.id_generator++).toString(16)); // set per session uid
object.name = parameters.name;
// default prime binds
if ('' in args) {
var prime = args[''];
if (prime instanceof DataArray || prime instanceof DataObject)
this.bind(prime);
}
object.parameters = parameters;
} else {
object.parameters = {id:(object.id = (parameters.id = (processor.id_generator++).toString(16)))}; // set per session uid
}
if (!__type)
throw new TypeError('Invalid node type!');
object.__type = (__type.indexOf('.') < 0) ? ('default.' + __type) : __type;
object.arguments = args || {};
object.state = Number.MIN_VALUE; // State id
object.childs = []; // Child nodes collection
object.onparent_reflected = 0; // On parent reflected state
object.in = [];
object.in_reflected = [];
object.out = [];
object.out_reflected = [];
return object;
} | javascript | function(object, __type, parameters, args) {
if (parameters) {
object.id = parameters.id || (parameters.id = (processor.id_generator++).toString(16)); // set per session uid
object.name = parameters.name;
// default prime binds
if ('' in args) {
var prime = args[''];
if (prime instanceof DataArray || prime instanceof DataObject)
this.bind(prime);
}
object.parameters = parameters;
} else {
object.parameters = {id:(object.id = (parameters.id = (processor.id_generator++).toString(16)))}; // set per session uid
}
if (!__type)
throw new TypeError('Invalid node type!');
object.__type = (__type.indexOf('.') < 0) ? ('default.' + __type) : __type;
object.arguments = args || {};
object.state = Number.MIN_VALUE; // State id
object.childs = []; // Child nodes collection
object.onparent_reflected = 0; // On parent reflected state
object.in = [];
object.in_reflected = [];
object.out = [];
object.out_reflected = [];
return object;
} | [
"function",
"(",
"object",
",",
"__type",
",",
"parameters",
",",
"args",
")",
"{",
"if",
"(",
"parameters",
")",
"{",
"object",
".",
"id",
"=",
"parameters",
".",
"id",
"||",
"(",
"parameters",
".",
"id",
"=",
"(",
"processor",
".",
"id_generator",
"++",
")",
".",
"toString",
"(",
"16",
")",
")",
";",
"// set per session uid",
"object",
".",
"name",
"=",
"parameters",
".",
"name",
";",
"// default prime binds",
"if",
"(",
"''",
"in",
"args",
")",
"{",
"var",
"prime",
"=",
"args",
"[",
"''",
"]",
";",
"if",
"(",
"prime",
"instanceof",
"DataArray",
"||",
"prime",
"instanceof",
"DataObject",
")",
"this",
".",
"bind",
"(",
"prime",
")",
";",
"}",
"object",
".",
"parameters",
"=",
"parameters",
";",
"}",
"else",
"{",
"object",
".",
"parameters",
"=",
"{",
"id",
":",
"(",
"object",
".",
"id",
"=",
"(",
"parameters",
".",
"id",
"=",
"(",
"processor",
".",
"id_generator",
"++",
")",
".",
"toString",
"(",
"16",
")",
")",
")",
"}",
";",
"// set per session uid",
"}",
"if",
"(",
"!",
"__type",
")",
"throw",
"new",
"TypeError",
"(",
"'Invalid node type!'",
")",
";",
"object",
".",
"__type",
"=",
"(",
"__type",
".",
"indexOf",
"(",
"'.'",
")",
"<",
"0",
")",
"?",
"(",
"'default.'",
"+",
"__type",
")",
":",
"__type",
";",
"object",
".",
"arguments",
"=",
"args",
"||",
"{",
"}",
";",
"object",
".",
"state",
"=",
"Number",
".",
"MIN_VALUE",
";",
"// State id",
"object",
".",
"childs",
"=",
"[",
"]",
";",
"// Child nodes collection",
"object",
".",
"onparent_reflected",
"=",
"0",
";",
"// On parent reflected state",
"object",
".",
"in",
"=",
"[",
"]",
";",
"object",
".",
"in_reflected",
"=",
"[",
"]",
";",
"object",
".",
"out",
"=",
"[",
"]",
";",
"object",
".",
"out_reflected",
"=",
"[",
"]",
";",
"return",
"object",
";",
"}"
]
| Registered subtypes
Component initialization. Initialize component attributes ```parameters, arguments, parent, childs``` etc. Normally called from the constructor function of the component.
@param {object} object Object to be initialized.
@param {string} __type Base type of the component. This value is assigned to the attribute __type of the component.
@param {object} parameters Hash object contains parsed parameters of the component.
@param {object} args Hash object contains arguments of the component.
@returns {object} Returns this. | [
"Registered",
"subtypes",
"Component",
"initialization",
".",
"Initialize",
"component",
"attributes",
"parameters",
"arguments",
"parent",
"childs",
"etc",
".",
"Normally",
"called",
"from",
"the",
"constructor",
"function",
"of",
"the",
"component",
"."
]
| a0accdded562e8d91ba89f0551b63cb396baa39f | https://github.com/aplib/processor.js/blob/a0accdded562e8d91ba89f0551b63cb396baa39f/processor.js#L25-L56 |
|
39,855 | aplib/processor.js | processor.js | function(type, factory) {
var key_parameters = {},
__type = parse_type(type, key_parameters) .toLowerCase();
// normalize prop name, remove lead '/'
for(var prop in key_parameters)
if (prop[0] === '/') {
key_parameters[prop.slice(1)] = key_parameters[prop];
delete key_parameters[prop];
}
if (__type.length < type.length || Object.keys(key_parameters).length) {
// type is subtype with parameters, register to processor.subtypes
key_parameters.__ctr = factory;
var subtypes_array = this.subtypes[__type] || (this.subtypes[__type] = []);
subtypes_array.push(key_parameters);
} else {
// register as standalone type
// check name conflict
if (this[__type])
throw new TypeError('Type ' + type + ' already registered!');
this[__type] = factory;
}
} | javascript | function(type, factory) {
var key_parameters = {},
__type = parse_type(type, key_parameters) .toLowerCase();
// normalize prop name, remove lead '/'
for(var prop in key_parameters)
if (prop[0] === '/') {
key_parameters[prop.slice(1)] = key_parameters[prop];
delete key_parameters[prop];
}
if (__type.length < type.length || Object.keys(key_parameters).length) {
// type is subtype with parameters, register to processor.subtypes
key_parameters.__ctr = factory;
var subtypes_array = this.subtypes[__type] || (this.subtypes[__type] = []);
subtypes_array.push(key_parameters);
} else {
// register as standalone type
// check name conflict
if (this[__type])
throw new TypeError('Type ' + type + ' already registered!');
this[__type] = factory;
}
} | [
"function",
"(",
"type",
",",
"factory",
")",
"{",
"var",
"key_parameters",
"=",
"{",
"}",
",",
"__type",
"=",
"parse_type",
"(",
"type",
",",
"key_parameters",
")",
".",
"toLowerCase",
"(",
")",
";",
"// normalize prop name, remove lead '/'",
"for",
"(",
"var",
"prop",
"in",
"key_parameters",
")",
"if",
"(",
"prop",
"[",
"0",
"]",
"===",
"'/'",
")",
"{",
"key_parameters",
"[",
"prop",
".",
"slice",
"(",
"1",
")",
"]",
"=",
"key_parameters",
"[",
"prop",
"]",
";",
"delete",
"key_parameters",
"[",
"prop",
"]",
";",
"}",
"if",
"(",
"__type",
".",
"length",
"<",
"type",
".",
"length",
"||",
"Object",
".",
"keys",
"(",
"key_parameters",
")",
".",
"length",
")",
"{",
"// type is subtype with parameters, register to processor.subtypes",
"key_parameters",
".",
"__ctr",
"=",
"factory",
";",
"var",
"subtypes_array",
"=",
"this",
".",
"subtypes",
"[",
"__type",
"]",
"||",
"(",
"this",
".",
"subtypes",
"[",
"__type",
"]",
"=",
"[",
"]",
")",
";",
"subtypes_array",
".",
"push",
"(",
"key_parameters",
")",
";",
"}",
"else",
"{",
"// register as standalone type",
"// check name conflict",
"if",
"(",
"this",
"[",
"__type",
"]",
")",
"throw",
"new",
"TypeError",
"(",
"'Type '",
"+",
"type",
"+",
"' already registered!'",
")",
";",
"this",
"[",
"__type",
"]",
"=",
"factory",
";",
"}",
"}"
]
| Register factory function in the processor library
@param {string} type Type string can include namespace, type and optional parameters.
@param {function} factory Object or value factory function
@returns {undefined} no returns value | [
"Register",
"factory",
"function",
"in",
"the",
"processor",
"library"
]
| a0accdded562e8d91ba89f0551b63cb396baa39f | https://github.com/aplib/processor.js/blob/a0accdded562e8d91ba89f0551b63cb396baa39f/processor.js#L77-L101 |
|
39,856 | aplib/processor.js | processor.js | function(alias, type) {
var parameters = {},
__type = parse_type(type, parameters) .toLowerCase(),
constructor = resolve_ctr(__type, parameters);
if (!constructor)
throw new TypeError('Type ' + __type + ' not registered!');
this[alias.toLowerCase()] = { __type: __type, parameters: parameters, isAlias: true };
} | javascript | function(alias, type) {
var parameters = {},
__type = parse_type(type, parameters) .toLowerCase(),
constructor = resolve_ctr(__type, parameters);
if (!constructor)
throw new TypeError('Type ' + __type + ' not registered!');
this[alias.toLowerCase()] = { __type: __type, parameters: parameters, isAlias: true };
} | [
"function",
"(",
"alias",
",",
"type",
")",
"{",
"var",
"parameters",
"=",
"{",
"}",
",",
"__type",
"=",
"parse_type",
"(",
"type",
",",
"parameters",
")",
".",
"toLowerCase",
"(",
")",
",",
"constructor",
"=",
"resolve_ctr",
"(",
"__type",
",",
"parameters",
")",
";",
"if",
"(",
"!",
"constructor",
")",
"throw",
"new",
"TypeError",
"(",
"'Type '",
"+",
"__type",
"+",
"' not registered!'",
")",
";",
"this",
"[",
"alias",
".",
"toLowerCase",
"(",
")",
"]",
"=",
"{",
"__type",
":",
"__type",
",",
"parameters",
":",
"parameters",
",",
"isAlias",
":",
"true",
"}",
";",
"}"
]
| Register existing parameterized type as a standalone type
@param {string} alias New alias that will be registered, in format namespace.task
@param {string} type Existing base type + additional #parameters, in format existingtype#parameters
@returns {undefined} | [
"Register",
"existing",
"parameterized",
"type",
"as",
"a",
"standalone",
"type"
]
| a0accdded562e8d91ba89f0551b63cb396baa39f | https://github.com/aplib/processor.js/blob/a0accdded562e8d91ba89f0551b63cb396baa39f/processor.js#L110-L118 |
|
39,857 | aplib/processor.js | processor.js | function(type, parameters, args) {
parameters = parameters || {};
args = args || {};
var __type = parse_type(type, parameters, args),
constructor = resolve_ctr(__type, parameters);
if (!constructor)
throw new TypeError('Type ' + __type + ' not registered!');
for(var prop in parameters)
if (parameters.hasOwnProperty(prop) && prop[0] === '$')
args[prop.substr(1)] = parameters[prop];
// create object
var new_control = (constructor.is_constructor) // constructor or factory method ?
? new constructor(parameters, args)
: constructor(parameters, args);
// reflect after creation if control only
if (typeof new_control === 'object' && '__type' in new_control)
new_control.raise('type');
return new_control;
} | javascript | function(type, parameters, args) {
parameters = parameters || {};
args = args || {};
var __type = parse_type(type, parameters, args),
constructor = resolve_ctr(__type, parameters);
if (!constructor)
throw new TypeError('Type ' + __type + ' not registered!');
for(var prop in parameters)
if (parameters.hasOwnProperty(prop) && prop[0] === '$')
args[prop.substr(1)] = parameters[prop];
// create object
var new_control = (constructor.is_constructor) // constructor or factory method ?
? new constructor(parameters, args)
: constructor(parameters, args);
// reflect after creation if control only
if (typeof new_control === 'object' && '__type' in new_control)
new_control.raise('type');
return new_control;
} | [
"function",
"(",
"type",
",",
"parameters",
",",
"args",
")",
"{",
"parameters",
"=",
"parameters",
"||",
"{",
"}",
";",
"args",
"=",
"args",
"||",
"{",
"}",
";",
"var",
"__type",
"=",
"parse_type",
"(",
"type",
",",
"parameters",
",",
"args",
")",
",",
"constructor",
"=",
"resolve_ctr",
"(",
"__type",
",",
"parameters",
")",
";",
"if",
"(",
"!",
"constructor",
")",
"throw",
"new",
"TypeError",
"(",
"'Type '",
"+",
"__type",
"+",
"' not registered!'",
")",
";",
"for",
"(",
"var",
"prop",
"in",
"parameters",
")",
"if",
"(",
"parameters",
".",
"hasOwnProperty",
"(",
"prop",
")",
"&&",
"prop",
"[",
"0",
"]",
"===",
"'$'",
")",
"args",
"[",
"prop",
".",
"substr",
"(",
"1",
")",
"]",
"=",
"parameters",
"[",
"prop",
"]",
";",
"// create object",
"var",
"new_control",
"=",
"(",
"constructor",
".",
"is_constructor",
")",
"// constructor or factory method ?",
"?",
"new",
"constructor",
"(",
"parameters",
",",
"args",
")",
":",
"constructor",
"(",
"parameters",
",",
"args",
")",
";",
"// reflect after creation if control only",
"if",
"(",
"typeof",
"new_control",
"===",
"'object'",
"&&",
"'__type'",
"in",
"new_control",
")",
"new_control",
".",
"raise",
"(",
"'type'",
")",
";",
"return",
"new_control",
";",
"}"
]
| Create from parsed parameters and arguments.
@param {string} type base type [and parameters].
@param {object} parameters Parsed parameters.
@param {object} args Parsed arguments.
@returns {object} Returns newly created component object. | [
"Create",
"from",
"parsed",
"parameters",
"and",
"arguments",
"."
]
| a0accdded562e8d91ba89f0551b63cb396baa39f | https://github.com/aplib/processor.js/blob/a0accdded562e8d91ba89f0551b63cb396baa39f/processor.js#L128-L154 |
|
39,858 | aplib/processor.js | processor.js | function(com) {
var root_nodes = this.root_nodes;
if (typeof com === 'string') {
if (com in processor) {
var object = processor[com];
if (typeof object === 'object' && '__type' in object) {
delete processor[name];
var index = root_nodes.indexOf(object);
if (index >= 0)
root_nodes.splice(index, 1);
}
}
} else {
var index = root_nodes.indexOf(com),
name = com.name;
if (index >= 0)
root_nodes.splice(index, 1);
if (processor[name] === com)
delete processor[name];
}
return this;
} | javascript | function(com) {
var root_nodes = this.root_nodes;
if (typeof com === 'string') {
if (com in processor) {
var object = processor[com];
if (typeof object === 'object' && '__type' in object) {
delete processor[name];
var index = root_nodes.indexOf(object);
if (index >= 0)
root_nodes.splice(index, 1);
}
}
} else {
var index = root_nodes.indexOf(com),
name = com.name;
if (index >= 0)
root_nodes.splice(index, 1);
if (processor[name] === com)
delete processor[name];
}
return this;
} | [
"function",
"(",
"com",
")",
"{",
"var",
"root_nodes",
"=",
"this",
".",
"root_nodes",
";",
"if",
"(",
"typeof",
"com",
"===",
"'string'",
")",
"{",
"if",
"(",
"com",
"in",
"processor",
")",
"{",
"var",
"object",
"=",
"processor",
"[",
"com",
"]",
";",
"if",
"(",
"typeof",
"object",
"===",
"'object'",
"&&",
"'__type'",
"in",
"object",
")",
"{",
"delete",
"processor",
"[",
"name",
"]",
";",
"var",
"index",
"=",
"root_nodes",
".",
"indexOf",
"(",
"object",
")",
";",
"if",
"(",
"index",
">=",
"0",
")",
"root_nodes",
".",
"splice",
"(",
"index",
",",
"1",
")",
";",
"}",
"}",
"}",
"else",
"{",
"var",
"index",
"=",
"root_nodes",
".",
"indexOf",
"(",
"com",
")",
",",
"name",
"=",
"com",
".",
"name",
";",
"if",
"(",
"index",
">=",
"0",
")",
"root_nodes",
".",
"splice",
"(",
"index",
",",
"1",
")",
";",
"if",
"(",
"processor",
"[",
"name",
"]",
"===",
"com",
")",
"delete",
"processor",
"[",
"name",
"]",
";",
"}",
"return",
"this",
";",
"}"
]
| Remove the specified root node.
@param {object|string} com Node object to be removed or root node name.
@returns Returns this. | [
"Remove",
"the",
"specified",
"root",
"node",
"."
]
| a0accdded562e8d91ba89f0551b63cb396baa39f | https://github.com/aplib/processor.js/blob/a0accdded562e8d91ba89f0551b63cb396baa39f/processor.js#L280-L301 |
|
39,859 | aplib/processor.js | processor.js | function(name, value) {
var parameters = this.parameters;
if (arguments.length < 1)
return parameters[name] || parameters['/' + name];
if (value !== parameters[name]) {
parameters[name] = value;
}
} | javascript | function(name, value) {
var parameters = this.parameters;
if (arguments.length < 1)
return parameters[name] || parameters['/' + name];
if (value !== parameters[name]) {
parameters[name] = value;
}
} | [
"function",
"(",
"name",
",",
"value",
")",
"{",
"var",
"parameters",
"=",
"this",
".",
"parameters",
";",
"if",
"(",
"arguments",
".",
"length",
"<",
"1",
")",
"return",
"parameters",
"[",
"name",
"]",
"||",
"parameters",
"[",
"'/'",
"+",
"name",
"]",
";",
"if",
"(",
"value",
"!==",
"parameters",
"[",
"name",
"]",
")",
"{",
"parameters",
"[",
"name",
"]",
"=",
"value",
";",
"}",
"}"
]
| Get or set parameter value.
@param {string} name Parameter name.
@param [value] value Parameter value.
@returns Returns parameter value or this. | [
"Get",
"or",
"set",
"parameter",
"value",
"."
]
| a0accdded562e8d91ba89f0551b63cb396baa39f | https://github.com/aplib/processor.js/blob/a0accdded562e8d91ba89f0551b63cb396baa39f/processor.js#L709-L718 |
|
39,860 | aplib/processor.js | processor.js | function(index, type, /*optional*/ $prime, /*optional*/ args, /*optional*/ callback, /*optional*/ this_arg) {
if (!type)
return;
// normalize arguments
if (typeof $prime === 'function') {
this_arg = args;
callback = $prime;
$prime = undefined;
args = undefined;
} else {
if (typeof $prime === 'object' && !Array.isArray($prime)) {
this_arg = callback;
callback = args;
args = $prime;
$prime = undefined;
}
if (typeof args === 'function') {
this_arg = callback;
callback = args;
args = undefined;
}
}
if (Array.isArray(type)) {
// collection detected
var result;
for(var i = index, c = index + type.length; i < c; i++)
result = this.insert(i, type[i], $prime, args, callback, this_arg);
return result;
}
if (typeof type === 'object') {
// it is a control?
var add_task = type;
if (add_task.hasOwnProperty('__type'))
setParent.call(type, this, index);
return add_task;
}
if (Array.isArray(args))
args = {'': args};
else if (!args)
args = {};
var parameters = {};
// transfer inheritable parameters to the created object
var this_parameters = this.parameters;
for(var prop in this_parameters)
if (this_parameters.hasOwnProperty(prop) && prop[0] === '/')
parameters[prop] = this_parameters[prop];
// resolve constructor
var __type = parse_type(type, parameters, args),
constructor = resolve_ctr(__type, parameters);
if ($prime !== undefined)
args[''] = $prime;
// load required components
if (!constructor) {
var parts = __type.split('.'),
mod_path = './modules/' + parts[0] + '/' + parts[1];
console.log(__type + ' not loaded, try to load ' + mod_path);
require(mod_path);
constructor = resolve_ctr(__type, parameters);
}
if (!constructor)
throw new TypeError('Type ' + __type + ' not registered!');
// move $parameters to attributes (unsafe)
for(var prop in parameters)
if (parameters.hasOwnProperty(prop) && prop[0] === '$')
args[prop.substr(1)] = parameters[prop];
// create control
var new_control = new constructor(parameters, args);
// reflect after creation
new_control.raise('type');
// set parent property
setParent.call(new_control, this, index);
// callback
if (callback)
callback.call(this_arg || this, new_control);
return new_control;
} | javascript | function(index, type, /*optional*/ $prime, /*optional*/ args, /*optional*/ callback, /*optional*/ this_arg) {
if (!type)
return;
// normalize arguments
if (typeof $prime === 'function') {
this_arg = args;
callback = $prime;
$prime = undefined;
args = undefined;
} else {
if (typeof $prime === 'object' && !Array.isArray($prime)) {
this_arg = callback;
callback = args;
args = $prime;
$prime = undefined;
}
if (typeof args === 'function') {
this_arg = callback;
callback = args;
args = undefined;
}
}
if (Array.isArray(type)) {
// collection detected
var result;
for(var i = index, c = index + type.length; i < c; i++)
result = this.insert(i, type[i], $prime, args, callback, this_arg);
return result;
}
if (typeof type === 'object') {
// it is a control?
var add_task = type;
if (add_task.hasOwnProperty('__type'))
setParent.call(type, this, index);
return add_task;
}
if (Array.isArray(args))
args = {'': args};
else if (!args)
args = {};
var parameters = {};
// transfer inheritable parameters to the created object
var this_parameters = this.parameters;
for(var prop in this_parameters)
if (this_parameters.hasOwnProperty(prop) && prop[0] === '/')
parameters[prop] = this_parameters[prop];
// resolve constructor
var __type = parse_type(type, parameters, args),
constructor = resolve_ctr(__type, parameters);
if ($prime !== undefined)
args[''] = $prime;
// load required components
if (!constructor) {
var parts = __type.split('.'),
mod_path = './modules/' + parts[0] + '/' + parts[1];
console.log(__type + ' not loaded, try to load ' + mod_path);
require(mod_path);
constructor = resolve_ctr(__type, parameters);
}
if (!constructor)
throw new TypeError('Type ' + __type + ' not registered!');
// move $parameters to attributes (unsafe)
for(var prop in parameters)
if (parameters.hasOwnProperty(prop) && prop[0] === '$')
args[prop.substr(1)] = parameters[prop];
// create control
var new_control = new constructor(parameters, args);
// reflect after creation
new_control.raise('type');
// set parent property
setParent.call(new_control, this, index);
// callback
if (callback)
callback.call(this_arg || this, new_control);
return new_control;
} | [
"function",
"(",
"index",
",",
"type",
",",
"/*optional*/",
"$prime",
",",
"/*optional*/",
"args",
",",
"/*optional*/",
"callback",
",",
"/*optional*/",
"this_arg",
")",
"{",
"if",
"(",
"!",
"type",
")",
"return",
";",
"// normalize arguments",
"if",
"(",
"typeof",
"$prime",
"===",
"'function'",
")",
"{",
"this_arg",
"=",
"args",
";",
"callback",
"=",
"$prime",
";",
"$prime",
"=",
"undefined",
";",
"args",
"=",
"undefined",
";",
"}",
"else",
"{",
"if",
"(",
"typeof",
"$prime",
"===",
"'object'",
"&&",
"!",
"Array",
".",
"isArray",
"(",
"$prime",
")",
")",
"{",
"this_arg",
"=",
"callback",
";",
"callback",
"=",
"args",
";",
"args",
"=",
"$prime",
";",
"$prime",
"=",
"undefined",
";",
"}",
"if",
"(",
"typeof",
"args",
"===",
"'function'",
")",
"{",
"this_arg",
"=",
"callback",
";",
"callback",
"=",
"args",
";",
"args",
"=",
"undefined",
";",
"}",
"}",
"if",
"(",
"Array",
".",
"isArray",
"(",
"type",
")",
")",
"{",
"// collection detected",
"var",
"result",
";",
"for",
"(",
"var",
"i",
"=",
"index",
",",
"c",
"=",
"index",
"+",
"type",
".",
"length",
";",
"i",
"<",
"c",
";",
"i",
"++",
")",
"result",
"=",
"this",
".",
"insert",
"(",
"i",
",",
"type",
"[",
"i",
"]",
",",
"$prime",
",",
"args",
",",
"callback",
",",
"this_arg",
")",
";",
"return",
"result",
";",
"}",
"if",
"(",
"typeof",
"type",
"===",
"'object'",
")",
"{",
"// it is a control?",
"var",
"add_task",
"=",
"type",
";",
"if",
"(",
"add_task",
".",
"hasOwnProperty",
"(",
"'__type'",
")",
")",
"setParent",
".",
"call",
"(",
"type",
",",
"this",
",",
"index",
")",
";",
"return",
"add_task",
";",
"}",
"if",
"(",
"Array",
".",
"isArray",
"(",
"args",
")",
")",
"args",
"=",
"{",
"''",
":",
"args",
"}",
";",
"else",
"if",
"(",
"!",
"args",
")",
"args",
"=",
"{",
"}",
";",
"var",
"parameters",
"=",
"{",
"}",
";",
"// transfer inheritable parameters to the created object",
"var",
"this_parameters",
"=",
"this",
".",
"parameters",
";",
"for",
"(",
"var",
"prop",
"in",
"this_parameters",
")",
"if",
"(",
"this_parameters",
".",
"hasOwnProperty",
"(",
"prop",
")",
"&&",
"prop",
"[",
"0",
"]",
"===",
"'/'",
")",
"parameters",
"[",
"prop",
"]",
"=",
"this_parameters",
"[",
"prop",
"]",
";",
"// resolve constructor",
"var",
"__type",
"=",
"parse_type",
"(",
"type",
",",
"parameters",
",",
"args",
")",
",",
"constructor",
"=",
"resolve_ctr",
"(",
"__type",
",",
"parameters",
")",
";",
"if",
"(",
"$prime",
"!==",
"undefined",
")",
"args",
"[",
"''",
"]",
"=",
"$prime",
";",
"// load required components",
"if",
"(",
"!",
"constructor",
")",
"{",
"var",
"parts",
"=",
"__type",
".",
"split",
"(",
"'.'",
")",
",",
"mod_path",
"=",
"'./modules/'",
"+",
"parts",
"[",
"0",
"]",
"+",
"'/'",
"+",
"parts",
"[",
"1",
"]",
";",
"console",
".",
"log",
"(",
"__type",
"+",
"' not loaded, try to load '",
"+",
"mod_path",
")",
";",
"require",
"(",
"mod_path",
")",
";",
"constructor",
"=",
"resolve_ctr",
"(",
"__type",
",",
"parameters",
")",
";",
"}",
"if",
"(",
"!",
"constructor",
")",
"throw",
"new",
"TypeError",
"(",
"'Type '",
"+",
"__type",
"+",
"' not registered!'",
")",
";",
"// move $parameters to attributes (unsafe)",
"for",
"(",
"var",
"prop",
"in",
"parameters",
")",
"if",
"(",
"parameters",
".",
"hasOwnProperty",
"(",
"prop",
")",
"&&",
"prop",
"[",
"0",
"]",
"===",
"'$'",
")",
"args",
"[",
"prop",
".",
"substr",
"(",
"1",
")",
"]",
"=",
"parameters",
"[",
"prop",
"]",
";",
"// create control",
"var",
"new_control",
"=",
"new",
"constructor",
"(",
"parameters",
",",
"args",
")",
";",
"// reflect after creation",
"new_control",
".",
"raise",
"(",
"'type'",
")",
";",
"// set parent property",
"setParent",
".",
"call",
"(",
"new_control",
",",
"this",
",",
"index",
")",
";",
"// callback",
"if",
"(",
"callback",
")",
"callback",
".",
"call",
"(",
"this_arg",
"||",
"this",
",",
"new_control",
")",
";",
"return",
"new_control",
";",
"}"
]
| Create a new component and insert to the component.childs collection at the specified index.
@param {number} index Index in .childs collection.
@param {string} type Type and parameters.
@param [$prime] Prime value is a responsibility of the component. This parameter value can be of simple type or be derived from DataObject DataArray.
@param {object} [args] Arguments hash object to be passed to the component.
@param {function} [callback] The callback will be called each time after the creation of a new component.
@param {object} [this_arg] The value to be passed as the this parameter to the target function when the callback function is called.
@returns {object} Returns newly created component object. | [
"Create",
"a",
"new",
"component",
"and",
"insert",
"to",
"the",
"component",
".",
"childs",
"collection",
"at",
"the",
"specified",
"index",
"."
]
| a0accdded562e8d91ba89f0551b63cb396baa39f | https://github.com/aplib/processor.js/blob/a0accdded562e8d91ba89f0551b63cb396baa39f/processor.js#L743-L835 |
|
39,861 | McNull/gulp-angular | lib/vendor.js | getIncludeFiles | function getIncludeFiles(glob) {
var folders = settings.folders;
var options = {
read: false,
cwd: path.resolve(folders.dest + '/' + folders.vendor)
};
return gulp.src(glob, options);
} | javascript | function getIncludeFiles(glob) {
var folders = settings.folders;
var options = {
read: false,
cwd: path.resolve(folders.dest + '/' + folders.vendor)
};
return gulp.src(glob, options);
} | [
"function",
"getIncludeFiles",
"(",
"glob",
")",
"{",
"var",
"folders",
"=",
"settings",
".",
"folders",
";",
"var",
"options",
"=",
"{",
"read",
":",
"false",
",",
"cwd",
":",
"path",
".",
"resolve",
"(",
"folders",
".",
"dest",
"+",
"'/'",
"+",
"folders",
".",
"vendor",
")",
"}",
";",
"return",
"gulp",
".",
"src",
"(",
"glob",
",",
"options",
")",
";",
"}"
]
| - - - - 8-< - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | [
"-",
"-",
"-",
"-",
"8",
"-",
"<",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-"
]
| e41b659a4b4ee5ff6e8eecda8395e2e88829162f | https://github.com/McNull/gulp-angular/blob/e41b659a4b4ee5ff6e8eecda8395e2e88829162f/lib/vendor.js#L40-L51 |
39,862 | noderaider/repackage | jspm_packages/npm/[email protected]/lib/generation/node/parentheses.js | ObjectExpression | function ObjectExpression(node, parent) {
if (t.isExpressionStatement(parent)) {
// ({ foo: "bar" });
return true;
}
if (t.isMemberExpression(parent) && parent.object === node) {
// ({ foo: "bar" }).foo
return true;
}
return false;
} | javascript | function ObjectExpression(node, parent) {
if (t.isExpressionStatement(parent)) {
// ({ foo: "bar" });
return true;
}
if (t.isMemberExpression(parent) && parent.object === node) {
// ({ foo: "bar" }).foo
return true;
}
return false;
} | [
"function",
"ObjectExpression",
"(",
"node",
",",
"parent",
")",
"{",
"if",
"(",
"t",
".",
"isExpressionStatement",
"(",
"parent",
")",
")",
"{",
"// ({ foo: \"bar\" });",
"return",
"true",
";",
"}",
"if",
"(",
"t",
".",
"isMemberExpression",
"(",
"parent",
")",
"&&",
"parent",
".",
"object",
"===",
"node",
")",
"{",
"// ({ foo: \"bar\" }).foo",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
]
| Test if ObjectExpression needs parentheses. | [
"Test",
"if",
"ObjectExpression",
"needs",
"parentheses",
"."
]
| 9f14246db3327abb0c4a5d7a3d55bd7816ebbd40 | https://github.com/noderaider/repackage/blob/9f14246db3327abb0c4a5d7a3d55bd7816ebbd40/jspm_packages/npm/[email protected]/lib/generation/node/parentheses.js#L77-L89 |
39,863 | stadt-bielefeld/mapfile2js | src/build/determineTabs.js | determineTabs | function determineTabs(line, tab){
let tabs = '';
for (let i = 0; i < line.depth; i++) {
tabs += tab;
}
return tabs;
} | javascript | function determineTabs(line, tab){
let tabs = '';
for (let i = 0; i < line.depth; i++) {
tabs += tab;
}
return tabs;
} | [
"function",
"determineTabs",
"(",
"line",
",",
"tab",
")",
"{",
"let",
"tabs",
"=",
"''",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"line",
".",
"depth",
";",
"i",
"++",
")",
"{",
"tabs",
"+=",
"tab",
";",
"}",
"return",
"tabs",
";",
"}"
]
| Determines spaces for a line
@param {object} line Line object
@param {string} tab A tab in spaces
@returns {string} Returns a string of spaces | [
"Determines",
"spaces",
"for",
"a",
"line"
]
| 08497189503e8823d1c9f26b74ce4ad1025e59dd | https://github.com/stadt-bielefeld/mapfile2js/blob/08497189503e8823d1c9f26b74ce4ad1025e59dd/src/build/determineTabs.js#L8-L16 |
39,864 | JsCommunity/exec-promise | index.spec.js | function (fn) {
var origError = console.error
var origExit = process.exit
var origLog = console.log
console.error = error = jest.fn()
console.log = print = jest.fn()
process.exit = exit = jest.fn()
return execPromise(fn).then(
function (value) {
console.error = origError
console.log = origLog
process.exit = origExit
return value
},
function (reason) {
console.error = origError
console.log = origLog
process.exit = origExit
throw reason
}
)
} | javascript | function (fn) {
var origError = console.error
var origExit = process.exit
var origLog = console.log
console.error = error = jest.fn()
console.log = print = jest.fn()
process.exit = exit = jest.fn()
return execPromise(fn).then(
function (value) {
console.error = origError
console.log = origLog
process.exit = origExit
return value
},
function (reason) {
console.error = origError
console.log = origLog
process.exit = origExit
throw reason
}
)
} | [
"function",
"(",
"fn",
")",
"{",
"var",
"origError",
"=",
"console",
".",
"error",
"var",
"origExit",
"=",
"process",
".",
"exit",
"var",
"origLog",
"=",
"console",
".",
"log",
"console",
".",
"error",
"=",
"error",
"=",
"jest",
".",
"fn",
"(",
")",
"console",
".",
"log",
"=",
"print",
"=",
"jest",
".",
"fn",
"(",
")",
"process",
".",
"exit",
"=",
"exit",
"=",
"jest",
".",
"fn",
"(",
")",
"return",
"execPromise",
"(",
"fn",
")",
".",
"then",
"(",
"function",
"(",
"value",
")",
"{",
"console",
".",
"error",
"=",
"origError",
"console",
".",
"log",
"=",
"origLog",
"process",
".",
"exit",
"=",
"origExit",
"return",
"value",
"}",
",",
"function",
"(",
"reason",
")",
"{",
"console",
".",
"error",
"=",
"origError",
"console",
".",
"log",
"=",
"origLog",
"process",
".",
"exit",
"=",
"origExit",
"throw",
"reason",
"}",
")",
"}"
]
| Helper which runs execPromise with spies. | [
"Helper",
"which",
"runs",
"execPromise",
"with",
"spies",
"."
]
| ba2f5ed4ac0b591e19bb7d99bc4f8462b9183f70 | https://github.com/JsCommunity/exec-promise/blob/ba2f5ed4ac0b591e19bb7d99bc4f8462b9183f70/index.spec.js#L21-L46 |
|
39,865 | Minivera/mithril-hobbit | packages/hobbit-navigator/umd/hobbit-navigator.js | History | function History() {
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
classCallCheck(this, History);
this.configuration = Object.assign({}, baseConfig, config);
this.supported = checkSupport(window);
var _configuration = this.configuration,
hashbanged = _configuration.hashbanged,
hashbangPrefix = _configuration.hashbangPrefix,
location = _configuration.location;
//Check if a location object in the configuration.
if (location) {
//If yes, build the location from that config depending on its type,
//but do not redirect.
this.location = (typeof location === 'undefined' ? 'undefined' : _typeof(location)) === 'object' ? location : {
path: location,
url: '' + (hashbanged ? hashbangPrefix : '') + location,
pattern: location,
params: {},
sender: ''
};
} else {
//If not, build the first location from the URL.
this.setLocationFromHref();
}
//Add an event listener to reset the location on hashbanged
if (hashbanged) {
window.addEventListener('hashchange', this.setLocationFromHref.bind(this));
}
} | javascript | function History() {
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
classCallCheck(this, History);
this.configuration = Object.assign({}, baseConfig, config);
this.supported = checkSupport(window);
var _configuration = this.configuration,
hashbanged = _configuration.hashbanged,
hashbangPrefix = _configuration.hashbangPrefix,
location = _configuration.location;
//Check if a location object in the configuration.
if (location) {
//If yes, build the location from that config depending on its type,
//but do not redirect.
this.location = (typeof location === 'undefined' ? 'undefined' : _typeof(location)) === 'object' ? location : {
path: location,
url: '' + (hashbanged ? hashbangPrefix : '') + location,
pattern: location,
params: {},
sender: ''
};
} else {
//If not, build the first location from the URL.
this.setLocationFromHref();
}
//Add an event listener to reset the location on hashbanged
if (hashbanged) {
window.addEventListener('hashchange', this.setLocationFromHref.bind(this));
}
} | [
"function",
"History",
"(",
")",
"{",
"var",
"config",
"=",
"arguments",
".",
"length",
">",
"0",
"&&",
"arguments",
"[",
"0",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"0",
"]",
":",
"{",
"}",
";",
"classCallCheck",
"(",
"this",
",",
"History",
")",
";",
"this",
".",
"configuration",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"baseConfig",
",",
"config",
")",
";",
"this",
".",
"supported",
"=",
"checkSupport",
"(",
"window",
")",
";",
"var",
"_configuration",
"=",
"this",
".",
"configuration",
",",
"hashbanged",
"=",
"_configuration",
".",
"hashbanged",
",",
"hashbangPrefix",
"=",
"_configuration",
".",
"hashbangPrefix",
",",
"location",
"=",
"_configuration",
".",
"location",
";",
"//Check if a location object in the configuration.",
"if",
"(",
"location",
")",
"{",
"//If yes, build the location from that config depending on its type,",
"//but do not redirect.",
"this",
".",
"location",
"=",
"(",
"typeof",
"location",
"===",
"'undefined'",
"?",
"'undefined'",
":",
"_typeof",
"(",
"location",
")",
")",
"===",
"'object'",
"?",
"location",
":",
"{",
"path",
":",
"location",
",",
"url",
":",
"''",
"+",
"(",
"hashbanged",
"?",
"hashbangPrefix",
":",
"''",
")",
"+",
"location",
",",
"pattern",
":",
"location",
",",
"params",
":",
"{",
"}",
",",
"sender",
":",
"''",
"}",
";",
"}",
"else",
"{",
"//If not, build the first location from the URL.",
"this",
".",
"setLocationFromHref",
"(",
")",
";",
"}",
"//Add an event listener to reset the location on hashbanged",
"if",
"(",
"hashbanged",
")",
"{",
"window",
".",
"addEventListener",
"(",
"'hashchange'",
",",
"this",
".",
"setLocationFromHref",
".",
"bind",
"(",
"this",
")",
")",
";",
"}",
"}"
]
| Constructor for the history manager that sets the configuration from
the parameter and the base configuration available in the module.
@param {Object} [config={}] - Configuration that may overwrite the
default configuration of the module.
@param {boolean} [config.hashbanged=false] - Sets whether the router
should set the browser url with a hashbang or not.
@param {string|Object} [config.location=null] - Sets the initial
route inside the route. Can either be a valid location object or a route.
Will not change the location in the browser.
@param {string} [config.hashbangPrefix=#!] - Sets the prefix for
routes when using the hashbanged option. | [
"Constructor",
"for",
"the",
"history",
"manager",
"that",
"sets",
"the",
"configuration",
"from",
"the",
"parameter",
"and",
"the",
"base",
"configuration",
"available",
"in",
"the",
"module",
"."
]
| b3a192e6eadf8ac2e3788492d44114b1799cd34a | https://github.com/Minivera/mithril-hobbit/blob/b3a192e6eadf8ac2e3788492d44114b1799cd34a/packages/hobbit-navigator/umd/hobbit-navigator.js#L116-L146 |
39,866 | webgme/ui-replay | src/routers/UIRecorder/UIRecorder.js | start | function start(callback) {
var dbDeferred = Q.defer();
config = defaultConfig;
if (typeof gmeConfig.rest.components[CONFIG_ID] === 'object' &&
gmeConfig.rest.components[CONFIG_ID].options) {
config = gmeConfig.rest.components[CONFIG_ID].options;
}
mongodb.MongoClient.connect(config.mongo.uri, config.mongo.options, function (err, db) {
if (err) {
dbDeferred.reject(err);
} else {
dbConn = db;
dbDeferred.resolve();
}
});
return dbDeferred.promise.nodeify(callback);
} | javascript | function start(callback) {
var dbDeferred = Q.defer();
config = defaultConfig;
if (typeof gmeConfig.rest.components[CONFIG_ID] === 'object' &&
gmeConfig.rest.components[CONFIG_ID].options) {
config = gmeConfig.rest.components[CONFIG_ID].options;
}
mongodb.MongoClient.connect(config.mongo.uri, config.mongo.options, function (err, db) {
if (err) {
dbDeferred.reject(err);
} else {
dbConn = db;
dbDeferred.resolve();
}
});
return dbDeferred.promise.nodeify(callback);
} | [
"function",
"start",
"(",
"callback",
")",
"{",
"var",
"dbDeferred",
"=",
"Q",
".",
"defer",
"(",
")",
";",
"config",
"=",
"defaultConfig",
";",
"if",
"(",
"typeof",
"gmeConfig",
".",
"rest",
".",
"components",
"[",
"CONFIG_ID",
"]",
"===",
"'object'",
"&&",
"gmeConfig",
".",
"rest",
".",
"components",
"[",
"CONFIG_ID",
"]",
".",
"options",
")",
"{",
"config",
"=",
"gmeConfig",
".",
"rest",
".",
"components",
"[",
"CONFIG_ID",
"]",
".",
"options",
";",
"}",
"mongodb",
".",
"MongoClient",
".",
"connect",
"(",
"config",
".",
"mongo",
".",
"uri",
",",
"config",
".",
"mongo",
".",
"options",
",",
"function",
"(",
"err",
",",
"db",
")",
"{",
"if",
"(",
"err",
")",
"{",
"dbDeferred",
".",
"reject",
"(",
"err",
")",
";",
"}",
"else",
"{",
"dbConn",
"=",
"db",
";",
"dbDeferred",
".",
"resolve",
"(",
")",
";",
"}",
"}",
")",
";",
"return",
"dbDeferred",
".",
"promise",
".",
"nodeify",
"(",
"callback",
")",
";",
"}"
]
| Called before the server starts listening.
@param {function} callback | [
"Called",
"before",
"the",
"server",
"starts",
"listening",
"."
]
| 0e0ad90b044d92cd508af03246ce0e9cbc382097 | https://github.com/webgme/ui-replay/blob/0e0ad90b044d92cd508af03246ce0e9cbc382097/src/routers/UIRecorder/UIRecorder.js#L245-L265 |
39,867 | florianmaxim/Meta | src/Space/Meta/Graphics/loaders/GLTFLoader.js | GLTFTextureDDSExtension | function GLTFTextureDDSExtension() {
if ( ! THREE.DDSLoader ) {
throw new Error( 'THREE.GLTFLoader: Attempting to load .dds texture without importing THREE.DDSLoader' );
}
this.name = EXTENSIONS.MSFT_TEXTURE_DDS;
this.ddsLoader = new THREE.DDSLoader();
} | javascript | function GLTFTextureDDSExtension() {
if ( ! THREE.DDSLoader ) {
throw new Error( 'THREE.GLTFLoader: Attempting to load .dds texture without importing THREE.DDSLoader' );
}
this.name = EXTENSIONS.MSFT_TEXTURE_DDS;
this.ddsLoader = new THREE.DDSLoader();
} | [
"function",
"GLTFTextureDDSExtension",
"(",
")",
"{",
"if",
"(",
"!",
"THREE",
".",
"DDSLoader",
")",
"{",
"throw",
"new",
"Error",
"(",
"'THREE.GLTFLoader: Attempting to load .dds texture without importing THREE.DDSLoader'",
")",
";",
"}",
"this",
".",
"name",
"=",
"EXTENSIONS",
".",
"MSFT_TEXTURE_DDS",
";",
"this",
".",
"ddsLoader",
"=",
"new",
"THREE",
".",
"DDSLoader",
"(",
")",
";",
"}"
]
| DDS Texture Extension
Specification:
https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_texture_dds | [
"DDS",
"Texture",
"Extension"
]
| 917e0b138f9751f02563efd812884577bc1ae8a2 | https://github.com/florianmaxim/Meta/blob/917e0b138f9751f02563efd812884577bc1ae8a2/src/Space/Meta/Graphics/loaders/GLTFLoader.js#L257-L268 |
39,868 | apostle/apostle.js | lib/index.js | send | function send(payload, promise) {
if (typeof apostle.domainKey == 'undefined'){
promise.reject('invalid', [{error: 'No domain key defined. Please set a domain key with `apostle.domainKey = "abc123"`'}])
return;
}
(request || superagent)
.post(apostle.deliveryEndpoint)
.type('json')
.send(payload)
.set('Authorization', 'Bearer ' + apostle.domainKey)
.set('Apostle-Client', 'JavaScript/v0.1.1')
.end(function(err, res){
if(res.ok){
promise.fulfill()
}else{
promise.reject('error', res)
}
})
} | javascript | function send(payload, promise) {
if (typeof apostle.domainKey == 'undefined'){
promise.reject('invalid', [{error: 'No domain key defined. Please set a domain key with `apostle.domainKey = "abc123"`'}])
return;
}
(request || superagent)
.post(apostle.deliveryEndpoint)
.type('json')
.send(payload)
.set('Authorization', 'Bearer ' + apostle.domainKey)
.set('Apostle-Client', 'JavaScript/v0.1.1')
.end(function(err, res){
if(res.ok){
promise.fulfill()
}else{
promise.reject('error', res)
}
})
} | [
"function",
"send",
"(",
"payload",
",",
"promise",
")",
"{",
"if",
"(",
"typeof",
"apostle",
".",
"domainKey",
"==",
"'undefined'",
")",
"{",
"promise",
".",
"reject",
"(",
"'invalid'",
",",
"[",
"{",
"error",
":",
"'No domain key defined. Please set a domain key with `apostle.domainKey = \"abc123\"`'",
"}",
"]",
")",
"return",
";",
"}",
"(",
"request",
"||",
"superagent",
")",
".",
"post",
"(",
"apostle",
".",
"deliveryEndpoint",
")",
".",
"type",
"(",
"'json'",
")",
".",
"send",
"(",
"payload",
")",
".",
"set",
"(",
"'Authorization'",
",",
"'Bearer '",
"+",
"apostle",
".",
"domainKey",
")",
".",
"set",
"(",
"'Apostle-Client'",
",",
"'JavaScript/v0.1.1'",
")",
".",
"end",
"(",
"function",
"(",
"err",
",",
"res",
")",
"{",
"if",
"(",
"res",
".",
"ok",
")",
"{",
"promise",
".",
"fulfill",
"(",
")",
"}",
"else",
"{",
"promise",
".",
"reject",
"(",
"'error'",
",",
"res",
")",
"}",
"}",
")",
"}"
]
| Delivery the JSON payload to the delivery endpoint via Request.
@param {object} Recipient Payload
- recipients {object} Email => data object of recipient information
@param {promise} Deferred promise object
@return {null} | [
"Delivery",
"the",
"JSON",
"payload",
"to",
"the",
"delivery",
"endpoint",
"via",
"Request",
"."
]
| 17130d88b073ec365bdd14ba920809d6867b0243 | https://github.com/apostle/apostle.js/blob/17130d88b073ec365bdd14ba920809d6867b0243/lib/index.js#L25-L43 |
39,869 | apostle/apostle.js | lib/index.js | function(template, options) {
queue = apostle.createQueue();
queue.push(template, options);
return queue.deliver();
} | javascript | function(template, options) {
queue = apostle.createQueue();
queue.push(template, options);
return queue.deliver();
} | [
"function",
"(",
"template",
",",
"options",
")",
"{",
"queue",
"=",
"apostle",
".",
"createQueue",
"(",
")",
";",
"queue",
".",
"push",
"(",
"template",
",",
"options",
")",
";",
"return",
"queue",
".",
"deliver",
"(",
")",
";",
"}"
]
| Delivers a single email.
@param {string} template id
@param {object} payload data, including email address
@param {function} callback
@return {null} | [
"Delivers",
"a",
"single",
"email",
"."
]
| 17130d88b073ec365bdd14ba920809d6867b0243 | https://github.com/apostle/apostle.js/blob/17130d88b073ec365bdd14ba920809d6867b0243/lib/index.js#L55-L59 |
|
39,870 | apostle/apostle.js | lib/index.js | function(template, options){
var payload = { data: {}, template_id: template };
// Add root attributes to the payload root
for(var attr in rootAttributes){
if(!rootAttributes.hasOwnProperty(attr)){
continue;
}
if(typeof options[attr] === 'undefined'){
continue;
}
var key = rootAttributes[attr],
val = options[attr];
payload[key] = val;
delete options[attr];
}
// Add any left over attribtues to the data object
for(attr in options){
if(!options.hasOwnProperty(attr)){
continue;
}
payload.data[attr] = options[attr]
}
// Add to the list of emails
this.mails.push(payload);
} | javascript | function(template, options){
var payload = { data: {}, template_id: template };
// Add root attributes to the payload root
for(var attr in rootAttributes){
if(!rootAttributes.hasOwnProperty(attr)){
continue;
}
if(typeof options[attr] === 'undefined'){
continue;
}
var key = rootAttributes[attr],
val = options[attr];
payload[key] = val;
delete options[attr];
}
// Add any left over attribtues to the data object
for(attr in options){
if(!options.hasOwnProperty(attr)){
continue;
}
payload.data[attr] = options[attr]
}
// Add to the list of emails
this.mails.push(payload);
} | [
"function",
"(",
"template",
",",
"options",
")",
"{",
"var",
"payload",
"=",
"{",
"data",
":",
"{",
"}",
",",
"template_id",
":",
"template",
"}",
";",
"// Add root attributes to the payload root",
"for",
"(",
"var",
"attr",
"in",
"rootAttributes",
")",
"{",
"if",
"(",
"!",
"rootAttributes",
".",
"hasOwnProperty",
"(",
"attr",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"typeof",
"options",
"[",
"attr",
"]",
"===",
"'undefined'",
")",
"{",
"continue",
";",
"}",
"var",
"key",
"=",
"rootAttributes",
"[",
"attr",
"]",
",",
"val",
"=",
"options",
"[",
"attr",
"]",
";",
"payload",
"[",
"key",
"]",
"=",
"val",
";",
"delete",
"options",
"[",
"attr",
"]",
";",
"}",
"// Add any left over attribtues to the data object",
"for",
"(",
"attr",
"in",
"options",
")",
"{",
"if",
"(",
"!",
"options",
".",
"hasOwnProperty",
"(",
"attr",
")",
")",
"{",
"continue",
";",
"}",
"payload",
".",
"data",
"[",
"attr",
"]",
"=",
"options",
"[",
"attr",
"]",
"}",
"// Add to the list of emails",
"this",
".",
"mails",
".",
"push",
"(",
"payload",
")",
";",
"}"
]
| Adds a single email to the queue.
@param {string} template id
@param {object} payload data, including email address
@return {null} | [
"Adds",
"a",
"single",
"email",
"to",
"the",
"queue",
"."
]
| 17130d88b073ec365bdd14ba920809d6867b0243 | https://github.com/apostle/apostle.js/blob/17130d88b073ec365bdd14ba920809d6867b0243/lib/index.js#L136-L163 |
|
39,871 | apostle/apostle.js | lib/index.js | function(){
var payload = { recipients: {} },
invalid = [],
promise = new Promise();
for(var i=0, j=this.mails.length; i < j; i++){
var data = this.mails[i],
email = data.email;
if(!data.template_id){
invalid.push(data)
data.error = "No template provided"
continue;
}
if(typeof data.email === 'undefined'){
invalid.push(data)
data.error = "No email provided"
continue;
}
delete data['email'];
payload.recipients[email] = data
}
if(invalid.length > 0){
promise.reject('invalid', invalid);
}else{
apostle.send(payload, promise);
}
return promise;
} | javascript | function(){
var payload = { recipients: {} },
invalid = [],
promise = new Promise();
for(var i=0, j=this.mails.length; i < j; i++){
var data = this.mails[i],
email = data.email;
if(!data.template_id){
invalid.push(data)
data.error = "No template provided"
continue;
}
if(typeof data.email === 'undefined'){
invalid.push(data)
data.error = "No email provided"
continue;
}
delete data['email'];
payload.recipients[email] = data
}
if(invalid.length > 0){
promise.reject('invalid', invalid);
}else{
apostle.send(payload, promise);
}
return promise;
} | [
"function",
"(",
")",
"{",
"var",
"payload",
"=",
"{",
"recipients",
":",
"{",
"}",
"}",
",",
"invalid",
"=",
"[",
"]",
",",
"promise",
"=",
"new",
"Promise",
"(",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"j",
"=",
"this",
".",
"mails",
".",
"length",
";",
"i",
"<",
"j",
";",
"i",
"++",
")",
"{",
"var",
"data",
"=",
"this",
".",
"mails",
"[",
"i",
"]",
",",
"email",
"=",
"data",
".",
"email",
";",
"if",
"(",
"!",
"data",
".",
"template_id",
")",
"{",
"invalid",
".",
"push",
"(",
"data",
")",
"data",
".",
"error",
"=",
"\"No template provided\"",
"continue",
";",
"}",
"if",
"(",
"typeof",
"data",
".",
"email",
"===",
"'undefined'",
")",
"{",
"invalid",
".",
"push",
"(",
"data",
")",
"data",
".",
"error",
"=",
"\"No email provided\"",
"continue",
";",
"}",
"delete",
"data",
"[",
"'email'",
"]",
";",
"payload",
".",
"recipients",
"[",
"email",
"]",
"=",
"data",
"}",
"if",
"(",
"invalid",
".",
"length",
">",
"0",
")",
"{",
"promise",
".",
"reject",
"(",
"'invalid'",
",",
"invalid",
")",
";",
"}",
"else",
"{",
"apostle",
".",
"send",
"(",
"payload",
",",
"promise",
")",
";",
"}",
"return",
"promise",
";",
"}"
]
| Delivers all the emails on the queue.
@return {promise} An promise object | [
"Delivers",
"all",
"the",
"emails",
"on",
"the",
"queue",
"."
]
| 17130d88b073ec365bdd14ba920809d6867b0243 | https://github.com/apostle/apostle.js/blob/17130d88b073ec365bdd14ba920809d6867b0243/lib/index.js#L170-L201 |
|
39,872 | noderaider/repackage | jspm_packages/npm/[email protected]/lib/generation/generators/flow.js | DeclareModule | function DeclareModule(node, print) {
this.push("declare module ");
print.plain(node.id);
this.space();
print.plain(node.body);
} | javascript | function DeclareModule(node, print) {
this.push("declare module ");
print.plain(node.id);
this.space();
print.plain(node.body);
} | [
"function",
"DeclareModule",
"(",
"node",
",",
"print",
")",
"{",
"this",
".",
"push",
"(",
"\"declare module \"",
")",
";",
"print",
".",
"plain",
"(",
"node",
".",
"id",
")",
";",
"this",
".",
"space",
"(",
")",
";",
"print",
".",
"plain",
"(",
"node",
".",
"body",
")",
";",
"}"
]
| Prints DeclareModule, prints id and body. | [
"Prints",
"DeclareModule",
"prints",
"id",
"and",
"body",
"."
]
| 9f14246db3327abb0c4a5d7a3d55bd7816ebbd40 | https://github.com/noderaider/repackage/blob/9f14246db3327abb0c4a5d7a3d55bd7816ebbd40/jspm_packages/npm/[email protected]/lib/generation/generators/flow.js#L117-L122 |
39,873 | noderaider/repackage | jspm_packages/npm/[email protected]/lib/generation/generators/flow.js | _interfaceish | function _interfaceish(node, print) {
print.plain(node.id);
print.plain(node.typeParameters);
if (node["extends"].length) {
this.push(" extends ");
print.join(node["extends"], { separator: ", " });
}
if (node.mixins && node.mixins.length) {
this.push(" mixins ");
print.join(node.mixins, { separator: ", " });
}
this.space();
print.plain(node.body);
} | javascript | function _interfaceish(node, print) {
print.plain(node.id);
print.plain(node.typeParameters);
if (node["extends"].length) {
this.push(" extends ");
print.join(node["extends"], { separator: ", " });
}
if (node.mixins && node.mixins.length) {
this.push(" mixins ");
print.join(node.mixins, { separator: ", " });
}
this.space();
print.plain(node.body);
} | [
"function",
"_interfaceish",
"(",
"node",
",",
"print",
")",
"{",
"print",
".",
"plain",
"(",
"node",
".",
"id",
")",
";",
"print",
".",
"plain",
"(",
"node",
".",
"typeParameters",
")",
";",
"if",
"(",
"node",
"[",
"\"extends\"",
"]",
".",
"length",
")",
"{",
"this",
".",
"push",
"(",
"\" extends \"",
")",
";",
"print",
".",
"join",
"(",
"node",
"[",
"\"extends\"",
"]",
",",
"{",
"separator",
":",
"\", \"",
"}",
")",
";",
"}",
"if",
"(",
"node",
".",
"mixins",
"&&",
"node",
".",
"mixins",
".",
"length",
")",
"{",
"this",
".",
"push",
"(",
"\" mixins \"",
")",
";",
"print",
".",
"join",
"(",
"node",
".",
"mixins",
",",
"{",
"separator",
":",
"\", \"",
"}",
")",
";",
"}",
"this",
".",
"space",
"(",
")",
";",
"print",
".",
"plain",
"(",
"node",
".",
"body",
")",
";",
"}"
]
| Prints interface-like node, prints id, typeParameters, extends, and body. | [
"Prints",
"interface",
"-",
"like",
"node",
"prints",
"id",
"typeParameters",
"extends",
"and",
"body",
"."
]
| 9f14246db3327abb0c4a5d7a3d55bd7816ebbd40 | https://github.com/noderaider/repackage/blob/9f14246db3327abb0c4a5d7a3d55bd7816ebbd40/jspm_packages/npm/[email protected]/lib/generation/generators/flow.js#L209-L222 |
39,874 | noderaider/repackage | jspm_packages/npm/[email protected]/lib/generation/generators/flow.js | TupleTypeAnnotation | function TupleTypeAnnotation(node, print) {
this.push("[");
print.join(node.types, { separator: ", " });
this.push("]");
} | javascript | function TupleTypeAnnotation(node, print) {
this.push("[");
print.join(node.types, { separator: ", " });
this.push("]");
} | [
"function",
"TupleTypeAnnotation",
"(",
"node",
",",
"print",
")",
"{",
"this",
".",
"push",
"(",
"\"[\"",
")",
";",
"print",
".",
"join",
"(",
"node",
".",
"types",
",",
"{",
"separator",
":",
"\", \"",
"}",
")",
";",
"this",
".",
"push",
"(",
"\"]\"",
")",
";",
"}"
]
| Prints TupleTypeAnnotation, prints types. | [
"Prints",
"TupleTypeAnnotation",
"prints",
"types",
"."
]
| 9f14246db3327abb0c4a5d7a3d55bd7816ebbd40 | https://github.com/noderaider/repackage/blob/9f14246db3327abb0c4a5d7a3d55bd7816ebbd40/jspm_packages/npm/[email protected]/lib/generation/generators/flow.js#L310-L314 |
39,875 | noderaider/repackage | jspm_packages/npm/[email protected]/lib/generation/generators/flow.js | TypeAlias | function TypeAlias(node, print) {
this.push("type ");
print.plain(node.id);
print.plain(node.typeParameters);
this.space();
this.push("=");
this.space();
print.plain(node.right);
this.semicolon();
} | javascript | function TypeAlias(node, print) {
this.push("type ");
print.plain(node.id);
print.plain(node.typeParameters);
this.space();
this.push("=");
this.space();
print.plain(node.right);
this.semicolon();
} | [
"function",
"TypeAlias",
"(",
"node",
",",
"print",
")",
"{",
"this",
".",
"push",
"(",
"\"type \"",
")",
";",
"print",
".",
"plain",
"(",
"node",
".",
"id",
")",
";",
"print",
".",
"plain",
"(",
"node",
".",
"typeParameters",
")",
";",
"this",
".",
"space",
"(",
")",
";",
"this",
".",
"push",
"(",
"\"=\"",
")",
";",
"this",
".",
"space",
"(",
")",
";",
"print",
".",
"plain",
"(",
"node",
".",
"right",
")",
";",
"this",
".",
"semicolon",
"(",
")",
";",
"}"
]
| Prints TypeAlias, prints id, typeParameters, and right. | [
"Prints",
"TypeAlias",
"prints",
"id",
"typeParameters",
"and",
"right",
"."
]
| 9f14246db3327abb0c4a5d7a3d55bd7816ebbd40 | https://github.com/noderaider/repackage/blob/9f14246db3327abb0c4a5d7a3d55bd7816ebbd40/jspm_packages/npm/[email protected]/lib/generation/generators/flow.js#L329-L338 |
39,876 | noderaider/repackage | jspm_packages/npm/[email protected]/lib/generation/generators/flow.js | ObjectTypeIndexer | function ObjectTypeIndexer(node, print) {
if (node["static"]) this.push("static ");
this.push("[");
print.plain(node.id);
this.push(":");
this.space();
print.plain(node.key);
this.push("]");
this.push(":");
this.space();
print.plain(node.value);
} | javascript | function ObjectTypeIndexer(node, print) {
if (node["static"]) this.push("static ");
this.push("[");
print.plain(node.id);
this.push(":");
this.space();
print.plain(node.key);
this.push("]");
this.push(":");
this.space();
print.plain(node.value);
} | [
"function",
"ObjectTypeIndexer",
"(",
"node",
",",
"print",
")",
"{",
"if",
"(",
"node",
"[",
"\"static\"",
"]",
")",
"this",
".",
"push",
"(",
"\"static \"",
")",
";",
"this",
".",
"push",
"(",
"\"[\"",
")",
";",
"print",
".",
"plain",
"(",
"node",
".",
"id",
")",
";",
"this",
".",
"push",
"(",
"\":\"",
")",
";",
"this",
".",
"space",
"(",
")",
";",
"print",
".",
"plain",
"(",
"node",
".",
"key",
")",
";",
"this",
".",
"push",
"(",
"\"]\"",
")",
";",
"this",
".",
"push",
"(",
"\":\"",
")",
";",
"this",
".",
"space",
"(",
")",
";",
"print",
".",
"plain",
"(",
"node",
".",
"value",
")",
";",
"}"
]
| Prints ObjectTypeIndexer, prints id, key, and value, handles static. | [
"Prints",
"ObjectTypeIndexer",
"prints",
"id",
"key",
"and",
"value",
"handles",
"static",
"."
]
| 9f14246db3327abb0c4a5d7a3d55bd7816ebbd40 | https://github.com/noderaider/repackage/blob/9f14246db3327abb0c4a5d7a3d55bd7816ebbd40/jspm_packages/npm/[email protected]/lib/generation/generators/flow.js#L417-L428 |
39,877 | noderaider/repackage | jspm_packages/npm/[email protected]/lib/generation/generators/flow.js | ObjectTypeProperty | function ObjectTypeProperty(node, print) {
if (node["static"]) this.push("static ");
print.plain(node.key);
if (node.optional) this.push("?");
if (!t.isFunctionTypeAnnotation(node.value)) {
this.push(":");
this.space();
}
print.plain(node.value);
} | javascript | function ObjectTypeProperty(node, print) {
if (node["static"]) this.push("static ");
print.plain(node.key);
if (node.optional) this.push("?");
if (!t.isFunctionTypeAnnotation(node.value)) {
this.push(":");
this.space();
}
print.plain(node.value);
} | [
"function",
"ObjectTypeProperty",
"(",
"node",
",",
"print",
")",
"{",
"if",
"(",
"node",
"[",
"\"static\"",
"]",
")",
"this",
".",
"push",
"(",
"\"static \"",
")",
";",
"print",
".",
"plain",
"(",
"node",
".",
"key",
")",
";",
"if",
"(",
"node",
".",
"optional",
")",
"this",
".",
"push",
"(",
"\"?\"",
")",
";",
"if",
"(",
"!",
"t",
".",
"isFunctionTypeAnnotation",
"(",
"node",
".",
"value",
")",
")",
"{",
"this",
".",
"push",
"(",
"\":\"",
")",
";",
"this",
".",
"space",
"(",
")",
";",
"}",
"print",
".",
"plain",
"(",
"node",
".",
"value",
")",
";",
"}"
]
| Prints ObjectTypeProperty, prints static, key, and value. | [
"Prints",
"ObjectTypeProperty",
"prints",
"static",
"key",
"and",
"value",
"."
]
| 9f14246db3327abb0c4a5d7a3d55bd7816ebbd40 | https://github.com/noderaider/repackage/blob/9f14246db3327abb0c4a5d7a3d55bd7816ebbd40/jspm_packages/npm/[email protected]/lib/generation/generators/flow.js#L434-L443 |
39,878 | caplinked/caplinked-api-node | src/caplinked-utils.js | responseErrorBuilder | function responseErrorBuilder(err, res) {
if (res && res.body && _.isObject(res.body) && res.body.error) {
// pass through error obj from API
return res.body;
} else {
// build custom error
return {
error: {
code: err.status || CL_CONSTANTS.RES_UNKNOWN,
message: (res ? res.text : null) || err.toString(),
}
};
}
} | javascript | function responseErrorBuilder(err, res) {
if (res && res.body && _.isObject(res.body) && res.body.error) {
// pass through error obj from API
return res.body;
} else {
// build custom error
return {
error: {
code: err.status || CL_CONSTANTS.RES_UNKNOWN,
message: (res ? res.text : null) || err.toString(),
}
};
}
} | [
"function",
"responseErrorBuilder",
"(",
"err",
",",
"res",
")",
"{",
"if",
"(",
"res",
"&&",
"res",
".",
"body",
"&&",
"_",
".",
"isObject",
"(",
"res",
".",
"body",
")",
"&&",
"res",
".",
"body",
".",
"error",
")",
"{",
"// pass through error obj from API",
"return",
"res",
".",
"body",
";",
"}",
"else",
"{",
"// build custom error",
"return",
"{",
"error",
":",
"{",
"code",
":",
"err",
".",
"status",
"||",
"CL_CONSTANTS",
".",
"RES_UNKNOWN",
",",
"message",
":",
"(",
"res",
"?",
"res",
".",
"text",
":",
"null",
")",
"||",
"err",
".",
"toString",
"(",
")",
",",
"}",
"}",
";",
"}",
"}"
]
| Return an Error Object | [
"Return",
"an",
"Error",
"Object"
]
| 944bbb6e2f315407f1aac4b9e8a463e9213d3631 | https://github.com/caplinked/caplinked-api-node/blob/944bbb6e2f315407f1aac4b9e8a463e9213d3631/src/caplinked-utils.js#L22-L35 |
39,879 | caplinked/caplinked-api-node | src/caplinked-utils.js | signedRequestHeaders | function signedRequestHeaders(apiKey, apiSecretKey, apiUserToken, options) {
if (!apiKey || !apiSecretKey || !apiUserToken) {
return false;
}
var apiExpDate = Math.floor(Date.now() / 1000) + 600;
var payload = apiKey + apiUserToken + apiExpDate;
var hash = CryptoJS.HmacSHA256(payload, apiSecretKey);
var headers = {
'x-api-key': apiKey,
'x-api-user-token': apiUserToken,
'x-api-signature': 'Method=HMAC-SHA256 Signature=' + hash,
'x-api-exp-date': apiExpDate,
};
return headers;
} | javascript | function signedRequestHeaders(apiKey, apiSecretKey, apiUserToken, options) {
if (!apiKey || !apiSecretKey || !apiUserToken) {
return false;
}
var apiExpDate = Math.floor(Date.now() / 1000) + 600;
var payload = apiKey + apiUserToken + apiExpDate;
var hash = CryptoJS.HmacSHA256(payload, apiSecretKey);
var headers = {
'x-api-key': apiKey,
'x-api-user-token': apiUserToken,
'x-api-signature': 'Method=HMAC-SHA256 Signature=' + hash,
'x-api-exp-date': apiExpDate,
};
return headers;
} | [
"function",
"signedRequestHeaders",
"(",
"apiKey",
",",
"apiSecretKey",
",",
"apiUserToken",
",",
"options",
")",
"{",
"if",
"(",
"!",
"apiKey",
"||",
"!",
"apiSecretKey",
"||",
"!",
"apiUserToken",
")",
"{",
"return",
"false",
";",
"}",
"var",
"apiExpDate",
"=",
"Math",
".",
"floor",
"(",
"Date",
".",
"now",
"(",
")",
"/",
"1000",
")",
"+",
"600",
";",
"var",
"payload",
"=",
"apiKey",
"+",
"apiUserToken",
"+",
"apiExpDate",
";",
"var",
"hash",
"=",
"CryptoJS",
".",
"HmacSHA256",
"(",
"payload",
",",
"apiSecretKey",
")",
";",
"var",
"headers",
"=",
"{",
"'x-api-key'",
":",
"apiKey",
",",
"'x-api-user-token'",
":",
"apiUserToken",
",",
"'x-api-signature'",
":",
"'Method=HMAC-SHA256 Signature='",
"+",
"hash",
",",
"'x-api-exp-date'",
":",
"apiExpDate",
",",
"}",
";",
"return",
"headers",
";",
"}"
]
| Return an Object of headers to attach to a request | [
"Return",
"an",
"Object",
"of",
"headers",
"to",
"attach",
"to",
"a",
"request"
]
| 944bbb6e2f315407f1aac4b9e8a463e9213d3631 | https://github.com/caplinked/caplinked-api-node/blob/944bbb6e2f315407f1aac4b9e8a463e9213d3631/src/caplinked-utils.js#L38-L52 |
39,880 | jsBoot/gulp-docco | lib/backend.js | function(config){
// Do parse
this.process = function(vinyl){
var data = vinyl.contents.toString('utf8');
// Parse
var sections = parse(vinyl.path, data, config);
// Format
format(vinyl.path, sections, config);
// Compute new title
var first = marked.lexer(sections[0].docsText)[0];
var hasTitle = first && first.type === 'heading' && first.depth === 1;
var title = hasTitle ? first.text : path.basename(vinyl.path);
// Change extension
vinyl.path = vinyl.path.replace(/([.][^.]+)?$/, '.html');
// Generate html from template
var relativeIt = path.relative(path.dirname(vinyl.relative), '.')
var relativeCss = path.join(relativeIt, path.basename(config.css));
var html = config.template({
sources: []/*config.sources*/,
css: relativeCss,
title: title,
hasTitle: hasTitle,
sections: sections,
path: path/*,
destination: vinyl.relative//.path*/
});
// Replace normalize bogus links: public/stylesheets/normalize.css
html = html.replace(/(public\/stylesheets\/normalize\.css)/, path.join(relativeIt, "$1"));
// Spoof it back in
vinyl.contents = new Buffer(html);
};
} | javascript | function(config){
// Do parse
this.process = function(vinyl){
var data = vinyl.contents.toString('utf8');
// Parse
var sections = parse(vinyl.path, data, config);
// Format
format(vinyl.path, sections, config);
// Compute new title
var first = marked.lexer(sections[0].docsText)[0];
var hasTitle = first && first.type === 'heading' && first.depth === 1;
var title = hasTitle ? first.text : path.basename(vinyl.path);
// Change extension
vinyl.path = vinyl.path.replace(/([.][^.]+)?$/, '.html');
// Generate html from template
var relativeIt = path.relative(path.dirname(vinyl.relative), '.')
var relativeCss = path.join(relativeIt, path.basename(config.css));
var html = config.template({
sources: []/*config.sources*/,
css: relativeCss,
title: title,
hasTitle: hasTitle,
sections: sections,
path: path/*,
destination: vinyl.relative//.path*/
});
// Replace normalize bogus links: public/stylesheets/normalize.css
html = html.replace(/(public\/stylesheets\/normalize\.css)/, path.join(relativeIt, "$1"));
// Spoof it back in
vinyl.contents = new Buffer(html);
};
} | [
"function",
"(",
"config",
")",
"{",
"// Do parse",
"this",
".",
"process",
"=",
"function",
"(",
"vinyl",
")",
"{",
"var",
"data",
"=",
"vinyl",
".",
"contents",
".",
"toString",
"(",
"'utf8'",
")",
";",
"// Parse",
"var",
"sections",
"=",
"parse",
"(",
"vinyl",
".",
"path",
",",
"data",
",",
"config",
")",
";",
"// Format",
"format",
"(",
"vinyl",
".",
"path",
",",
"sections",
",",
"config",
")",
";",
"// Compute new title",
"var",
"first",
"=",
"marked",
".",
"lexer",
"(",
"sections",
"[",
"0",
"]",
".",
"docsText",
")",
"[",
"0",
"]",
";",
"var",
"hasTitle",
"=",
"first",
"&&",
"first",
".",
"type",
"===",
"'heading'",
"&&",
"first",
".",
"depth",
"===",
"1",
";",
"var",
"title",
"=",
"hasTitle",
"?",
"first",
".",
"text",
":",
"path",
".",
"basename",
"(",
"vinyl",
".",
"path",
")",
";",
"// Change extension",
"vinyl",
".",
"path",
"=",
"vinyl",
".",
"path",
".",
"replace",
"(",
"/",
"([.][^.]+)?$",
"/",
",",
"'.html'",
")",
";",
"// Generate html from template",
"var",
"relativeIt",
"=",
"path",
".",
"relative",
"(",
"path",
".",
"dirname",
"(",
"vinyl",
".",
"relative",
")",
",",
"'.'",
")",
"var",
"relativeCss",
"=",
"path",
".",
"join",
"(",
"relativeIt",
",",
"path",
".",
"basename",
"(",
"config",
".",
"css",
")",
")",
";",
"var",
"html",
"=",
"config",
".",
"template",
"(",
"{",
"sources",
":",
"[",
"]",
"/*config.sources*/",
",",
"css",
":",
"relativeCss",
",",
"title",
":",
"title",
",",
"hasTitle",
":",
"hasTitle",
",",
"sections",
":",
"sections",
",",
"path",
":",
"path",
"/*,\n destination: vinyl.relative//.path*/",
"}",
")",
";",
"// Replace normalize bogus links: public/stylesheets/normalize.css",
"html",
"=",
"html",
".",
"replace",
"(",
"/",
"(public\\/stylesheets\\/normalize\\.css)",
"/",
",",
"path",
".",
"join",
"(",
"relativeIt",
",",
"\"$1\"",
")",
")",
";",
"// Spoof it back in",
"vinyl",
".",
"contents",
"=",
"new",
"Buffer",
"(",
"html",
")",
";",
"}",
";",
"}"
]
| Just require extension and languages as far as config is concerned | [
"Just",
"require",
"extension",
"and",
"languages",
"as",
"far",
"as",
"config",
"is",
"concerned"
]
| 05ab1bcf76952a5bc8e16713a31d6dd7f3d75517 | https://github.com/jsBoot/gulp-docco/blob/05ab1bcf76952a5bc8e16713a31d6dd7f3d75517/lib/backend.js#L24-L63 |
|
39,881 | codius-deprecated/codius-engine | lib/contractrunner.js | ContractRunner | function ContractRunner(config, data) {
events.EventEmitter.call(this);
var self = this;
self.config = config;
if (typeof data !== 'object' ||
typeof data.manifest !== 'object') {
throw new Error('ApiHandler must be instantiated with the manifest');
}
self._manifest = data.manifest;
self._apis = {};
self._manifest_hash = data.manifest_hash;
self._instance_id = data.instance_id;
self._additional_libs = data.additional_libs || '';
self._env = data.env;
self._nextFreeFileDescriptor = 4;
// Add the manifest_hash to the manifest object so it will
// be passed to the API modules when they are called
self._manifest.manifest_hash = data.manifest_hash;
// Setup sandbox instance
self._sandbox = new Sandbox({
enableGdb: self.config.enableGdb,
enableValgrind: self.config.enableValgrind,
disableNacl: self.config.disableNacl
});
self._sandbox.on('exit', self.handleExit.bind(self));
} | javascript | function ContractRunner(config, data) {
events.EventEmitter.call(this);
var self = this;
self.config = config;
if (typeof data !== 'object' ||
typeof data.manifest !== 'object') {
throw new Error('ApiHandler must be instantiated with the manifest');
}
self._manifest = data.manifest;
self._apis = {};
self._manifest_hash = data.manifest_hash;
self._instance_id = data.instance_id;
self._additional_libs = data.additional_libs || '';
self._env = data.env;
self._nextFreeFileDescriptor = 4;
// Add the manifest_hash to the manifest object so it will
// be passed to the API modules when they are called
self._manifest.manifest_hash = data.manifest_hash;
// Setup sandbox instance
self._sandbox = new Sandbox({
enableGdb: self.config.enableGdb,
enableValgrind: self.config.enableValgrind,
disableNacl: self.config.disableNacl
});
self._sandbox.on('exit', self.handleExit.bind(self));
} | [
"function",
"ContractRunner",
"(",
"config",
",",
"data",
")",
"{",
"events",
".",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"var",
"self",
"=",
"this",
";",
"self",
".",
"config",
"=",
"config",
";",
"if",
"(",
"typeof",
"data",
"!==",
"'object'",
"||",
"typeof",
"data",
".",
"manifest",
"!==",
"'object'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'ApiHandler must be instantiated with the manifest'",
")",
";",
"}",
"self",
".",
"_manifest",
"=",
"data",
".",
"manifest",
";",
"self",
".",
"_apis",
"=",
"{",
"}",
";",
"self",
".",
"_manifest_hash",
"=",
"data",
".",
"manifest_hash",
";",
"self",
".",
"_instance_id",
"=",
"data",
".",
"instance_id",
";",
"self",
".",
"_additional_libs",
"=",
"data",
".",
"additional_libs",
"||",
"''",
";",
"self",
".",
"_env",
"=",
"data",
".",
"env",
";",
"self",
".",
"_nextFreeFileDescriptor",
"=",
"4",
";",
"// Add the manifest_hash to the manifest object so it will",
"// be passed to the API modules when they are called",
"self",
".",
"_manifest",
".",
"manifest_hash",
"=",
"data",
".",
"manifest_hash",
";",
"// Setup sandbox instance",
"self",
".",
"_sandbox",
"=",
"new",
"Sandbox",
"(",
"{",
"enableGdb",
":",
"self",
".",
"config",
".",
"enableGdb",
",",
"enableValgrind",
":",
"self",
".",
"config",
".",
"enableValgrind",
",",
"disableNacl",
":",
"self",
".",
"config",
".",
"disableNacl",
"}",
")",
";",
"self",
".",
"_sandbox",
".",
"on",
"(",
"'exit'",
",",
"self",
".",
"handleExit",
".",
"bind",
"(",
"self",
")",
")",
";",
"}"
]
| Class to run contracts.
@param {Object} data.manifest
@param {Object} data.apis
@param {String} data.manifest_hash | [
"Class",
"to",
"run",
"contracts",
"."
]
| 48aaea3d1a0dd2cf755a1905ff040e1667e8d131 | https://github.com/codius-deprecated/codius-engine/blob/48aaea3d1a0dd2cf755a1905ff040e1667e8d131/lib/contractrunner.js#L33-L66 |
39,882 | preceptorjs/taxi | lib/scripts/screenshot.js | function (needsStitching) {
var initData = {
viewPort: {},
document: {},
bodyTransform: {}
},
de = document.documentElement,
el = document.createElement('div'),
body = document.body;
// Get current scroll-position
initData.viewPort.x = window.pageXOffset || body.scrollLeft || de.scrollLeft;
initData.viewPort.y = window.pageYOffset || body.scrollTop || de.scrollTop;
// Get current view-port size
el.style.position = "fixed";
el.style.top = 0;
el.style.left = 0;
el.style.bottom = 0;
el.style.right = 0;
de.insertBefore(el, de.firstChild);
initData.viewPort.width = el.offsetWidth;
initData.viewPort.height = el.offsetHeight;
de.removeChild(el);
//initData.viewPort.width = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
//initData.viewPort.height = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
// Get document size & state of scrollbar styles
initData.document.width = Math.max(body.scrollWidth, body.offsetWidth, de.clientWidth, de.scrollWidth, de.offsetWidth);
initData.document.height = Math.max(body.scrollHeight, body.offsetHeight, de.clientHeight, de.scrollHeight, de.offsetHeight);
initData.document.cssHeight = body.style.height;
initData.document.overflow = body.style.overflow;
// See which transformation property to use and what value it has
// Needed for scroll-translation without the page actually knowing about it
if (body.style.webkitTransform !== undefined) {
initData.bodyTransform.property = 'webkitTransform';
} else if (body.style.mozTransform !== undefined) {
initData.bodyTransform.property = 'mozTransform';
} else if (body.style.msTransform !== undefined) {
initData.bodyTransform.property = 'msTransform';
} else if (body.style.oTransform !== undefined) {
initData.bodyTransform.property = 'oTransform';
} else {
initData.bodyTransform.property = 'transform';
}
initData.bodyTransform.value = body.style[initData.bodyTransform.property];
initData.needsStitching = needsStitching;
// Change document
// Reset scrolling through translate
if (needsStitching) {
body.style[initData.bodyTransform.property] = 'translate(' + initData.viewPort.x + 'px, ' + initData.viewPort.y + 'px)';
}
return JSON.stringify(initData);
} | javascript | function (needsStitching) {
var initData = {
viewPort: {},
document: {},
bodyTransform: {}
},
de = document.documentElement,
el = document.createElement('div'),
body = document.body;
// Get current scroll-position
initData.viewPort.x = window.pageXOffset || body.scrollLeft || de.scrollLeft;
initData.viewPort.y = window.pageYOffset || body.scrollTop || de.scrollTop;
// Get current view-port size
el.style.position = "fixed";
el.style.top = 0;
el.style.left = 0;
el.style.bottom = 0;
el.style.right = 0;
de.insertBefore(el, de.firstChild);
initData.viewPort.width = el.offsetWidth;
initData.viewPort.height = el.offsetHeight;
de.removeChild(el);
//initData.viewPort.width = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
//initData.viewPort.height = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
// Get document size & state of scrollbar styles
initData.document.width = Math.max(body.scrollWidth, body.offsetWidth, de.clientWidth, de.scrollWidth, de.offsetWidth);
initData.document.height = Math.max(body.scrollHeight, body.offsetHeight, de.clientHeight, de.scrollHeight, de.offsetHeight);
initData.document.cssHeight = body.style.height;
initData.document.overflow = body.style.overflow;
// See which transformation property to use and what value it has
// Needed for scroll-translation without the page actually knowing about it
if (body.style.webkitTransform !== undefined) {
initData.bodyTransform.property = 'webkitTransform';
} else if (body.style.mozTransform !== undefined) {
initData.bodyTransform.property = 'mozTransform';
} else if (body.style.msTransform !== undefined) {
initData.bodyTransform.property = 'msTransform';
} else if (body.style.oTransform !== undefined) {
initData.bodyTransform.property = 'oTransform';
} else {
initData.bodyTransform.property = 'transform';
}
initData.bodyTransform.value = body.style[initData.bodyTransform.property];
initData.needsStitching = needsStitching;
// Change document
// Reset scrolling through translate
if (needsStitching) {
body.style[initData.bodyTransform.property] = 'translate(' + initData.viewPort.x + 'px, ' + initData.viewPort.y + 'px)';
}
return JSON.stringify(initData);
} | [
"function",
"(",
"needsStitching",
")",
"{",
"var",
"initData",
"=",
"{",
"viewPort",
":",
"{",
"}",
",",
"document",
":",
"{",
"}",
",",
"bodyTransform",
":",
"{",
"}",
"}",
",",
"de",
"=",
"document",
".",
"documentElement",
",",
"el",
"=",
"document",
".",
"createElement",
"(",
"'div'",
")",
",",
"body",
"=",
"document",
".",
"body",
";",
"// Get current scroll-position",
"initData",
".",
"viewPort",
".",
"x",
"=",
"window",
".",
"pageXOffset",
"||",
"body",
".",
"scrollLeft",
"||",
"de",
".",
"scrollLeft",
";",
"initData",
".",
"viewPort",
".",
"y",
"=",
"window",
".",
"pageYOffset",
"||",
"body",
".",
"scrollTop",
"||",
"de",
".",
"scrollTop",
";",
"// Get current view-port size",
"el",
".",
"style",
".",
"position",
"=",
"\"fixed\"",
";",
"el",
".",
"style",
".",
"top",
"=",
"0",
";",
"el",
".",
"style",
".",
"left",
"=",
"0",
";",
"el",
".",
"style",
".",
"bottom",
"=",
"0",
";",
"el",
".",
"style",
".",
"right",
"=",
"0",
";",
"de",
".",
"insertBefore",
"(",
"el",
",",
"de",
".",
"firstChild",
")",
";",
"initData",
".",
"viewPort",
".",
"width",
"=",
"el",
".",
"offsetWidth",
";",
"initData",
".",
"viewPort",
".",
"height",
"=",
"el",
".",
"offsetHeight",
";",
"de",
".",
"removeChild",
"(",
"el",
")",
";",
"//initData.viewPort.width = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);",
"//initData.viewPort.height = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);",
"// Get document size & state of scrollbar styles",
"initData",
".",
"document",
".",
"width",
"=",
"Math",
".",
"max",
"(",
"body",
".",
"scrollWidth",
",",
"body",
".",
"offsetWidth",
",",
"de",
".",
"clientWidth",
",",
"de",
".",
"scrollWidth",
",",
"de",
".",
"offsetWidth",
")",
";",
"initData",
".",
"document",
".",
"height",
"=",
"Math",
".",
"max",
"(",
"body",
".",
"scrollHeight",
",",
"body",
".",
"offsetHeight",
",",
"de",
".",
"clientHeight",
",",
"de",
".",
"scrollHeight",
",",
"de",
".",
"offsetHeight",
")",
";",
"initData",
".",
"document",
".",
"cssHeight",
"=",
"body",
".",
"style",
".",
"height",
";",
"initData",
".",
"document",
".",
"overflow",
"=",
"body",
".",
"style",
".",
"overflow",
";",
"// See which transformation property to use and what value it has",
"// Needed for scroll-translation without the page actually knowing about it",
"if",
"(",
"body",
".",
"style",
".",
"webkitTransform",
"!==",
"undefined",
")",
"{",
"initData",
".",
"bodyTransform",
".",
"property",
"=",
"'webkitTransform'",
";",
"}",
"else",
"if",
"(",
"body",
".",
"style",
".",
"mozTransform",
"!==",
"undefined",
")",
"{",
"initData",
".",
"bodyTransform",
".",
"property",
"=",
"'mozTransform'",
";",
"}",
"else",
"if",
"(",
"body",
".",
"style",
".",
"msTransform",
"!==",
"undefined",
")",
"{",
"initData",
".",
"bodyTransform",
".",
"property",
"=",
"'msTransform'",
";",
"}",
"else",
"if",
"(",
"body",
".",
"style",
".",
"oTransform",
"!==",
"undefined",
")",
"{",
"initData",
".",
"bodyTransform",
".",
"property",
"=",
"'oTransform'",
";",
"}",
"else",
"{",
"initData",
".",
"bodyTransform",
".",
"property",
"=",
"'transform'",
";",
"}",
"initData",
".",
"bodyTransform",
".",
"value",
"=",
"body",
".",
"style",
"[",
"initData",
".",
"bodyTransform",
".",
"property",
"]",
";",
"initData",
".",
"needsStitching",
"=",
"needsStitching",
";",
"// Change document",
"// Reset scrolling through translate",
"if",
"(",
"needsStitching",
")",
"{",
"body",
".",
"style",
"[",
"initData",
".",
"bodyTransform",
".",
"property",
"]",
"=",
"'translate('",
"+",
"initData",
".",
"viewPort",
".",
"x",
"+",
"'px, '",
"+",
"initData",
".",
"viewPort",
".",
"y",
"+",
"'px)'",
";",
"}",
"return",
"JSON",
".",
"stringify",
"(",
"initData",
")",
";",
"}"
]
| Initializes screenshots and gathers data to revert changes.
This function will also gather information required for
screenshots like dimensions of document and view-port.
@method init
@param {boolean} needsStitching | [
"Initializes",
"screenshots",
"and",
"gathers",
"data",
"to",
"revert",
"changes",
".",
"This",
"function",
"will",
"also",
"gather",
"information",
"required",
"for",
"screenshots",
"like",
"dimensions",
"of",
"document",
"and",
"view",
"-",
"port",
"."
]
| 96ab5a5c5fa9dc50f325ba4de52dd90009073ca3 | https://github.com/preceptorjs/taxi/blob/96ab5a5c5fa9dc50f325ba4de52dd90009073ca3/lib/scripts/screenshot.js#L11-L70 |
|
39,883 | preceptorjs/taxi | lib/scripts/screenshot.js | function (initData) {
var body = document.body;
// Reset document height (if changed at all)
body.style.height = initData.document.cssHeight;
// Reset document offset
if (initData.needsStitching) {
body.style[initData.bodyTransform.property] = initData.bodyTransform.value;
}
} | javascript | function (initData) {
var body = document.body;
// Reset document height (if changed at all)
body.style.height = initData.document.cssHeight;
// Reset document offset
if (initData.needsStitching) {
body.style[initData.bodyTransform.property] = initData.bodyTransform.value;
}
} | [
"function",
"(",
"initData",
")",
"{",
"var",
"body",
"=",
"document",
".",
"body",
";",
"// Reset document height (if changed at all)",
"body",
".",
"style",
".",
"height",
"=",
"initData",
".",
"document",
".",
"cssHeight",
";",
"// Reset document offset",
"if",
"(",
"initData",
".",
"needsStitching",
")",
"{",
"body",
".",
"style",
"[",
"initData",
".",
"bodyTransform",
".",
"property",
"]",
"=",
"initData",
".",
"bodyTransform",
".",
"value",
";",
"}",
"}"
]
| Reverts changes done to the document during the screenshot process
@method revert
@param {object} initData Data gathered during init-phase | [
"Reverts",
"changes",
"done",
"to",
"the",
"document",
"during",
"the",
"screenshot",
"process"
]
| 96ab5a5c5fa9dc50f325ba4de52dd90009073ca3 | https://github.com/preceptorjs/taxi/blob/96ab5a5c5fa9dc50f325ba4de52dd90009073ca3/lib/scripts/screenshot.js#L78-L88 |
|
39,884 | noderaider/repackage | jspm_packages/npm/[email protected]/lib/api/register/node.js | compile | function compile(filename) {
var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var result;
opts.filename = filename;
var optsManager = new _transformationFileOptionsOptionManager2["default"]();
optsManager.mergeOptions(transformOpts);
opts = optsManager.init(opts);
var cacheKey = JSON.stringify(opts) + ":" + babel.version;
var env = process.env.BABEL_ENV || process.env.NODE_ENV;
if (env) cacheKey += ":" + env;
if (cache) {
var cached = cache[cacheKey];
if (cached && cached.mtime === mtime(filename)) {
result = cached;
}
}
if (!result) {
result = babel.transformFileSync(filename, _lodashObjectExtend2["default"](opts, {
sourceMap: "both",
ast: false
}));
}
if (cache) {
result.mtime = mtime(filename);
cache[cacheKey] = result;
}
maps[filename] = result.map;
return result.code;
} | javascript | function compile(filename) {
var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var result;
opts.filename = filename;
var optsManager = new _transformationFileOptionsOptionManager2["default"]();
optsManager.mergeOptions(transformOpts);
opts = optsManager.init(opts);
var cacheKey = JSON.stringify(opts) + ":" + babel.version;
var env = process.env.BABEL_ENV || process.env.NODE_ENV;
if (env) cacheKey += ":" + env;
if (cache) {
var cached = cache[cacheKey];
if (cached && cached.mtime === mtime(filename)) {
result = cached;
}
}
if (!result) {
result = babel.transformFileSync(filename, _lodashObjectExtend2["default"](opts, {
sourceMap: "both",
ast: false
}));
}
if (cache) {
result.mtime = mtime(filename);
cache[cacheKey] = result;
}
maps[filename] = result.map;
return result.code;
} | [
"function",
"compile",
"(",
"filename",
")",
"{",
"var",
"opts",
"=",
"arguments",
".",
"length",
"<=",
"1",
"||",
"arguments",
"[",
"1",
"]",
"===",
"undefined",
"?",
"{",
"}",
":",
"arguments",
"[",
"1",
"]",
";",
"var",
"result",
";",
"opts",
".",
"filename",
"=",
"filename",
";",
"var",
"optsManager",
"=",
"new",
"_transformationFileOptionsOptionManager2",
"[",
"\"default\"",
"]",
"(",
")",
";",
"optsManager",
".",
"mergeOptions",
"(",
"transformOpts",
")",
";",
"opts",
"=",
"optsManager",
".",
"init",
"(",
"opts",
")",
";",
"var",
"cacheKey",
"=",
"JSON",
".",
"stringify",
"(",
"opts",
")",
"+",
"\":\"",
"+",
"babel",
".",
"version",
";",
"var",
"env",
"=",
"process",
".",
"env",
".",
"BABEL_ENV",
"||",
"process",
".",
"env",
".",
"NODE_ENV",
";",
"if",
"(",
"env",
")",
"cacheKey",
"+=",
"\":\"",
"+",
"env",
";",
"if",
"(",
"cache",
")",
"{",
"var",
"cached",
"=",
"cache",
"[",
"cacheKey",
"]",
";",
"if",
"(",
"cached",
"&&",
"cached",
".",
"mtime",
"===",
"mtime",
"(",
"filename",
")",
")",
"{",
"result",
"=",
"cached",
";",
"}",
"}",
"if",
"(",
"!",
"result",
")",
"{",
"result",
"=",
"babel",
".",
"transformFileSync",
"(",
"filename",
",",
"_lodashObjectExtend2",
"[",
"\"default\"",
"]",
"(",
"opts",
",",
"{",
"sourceMap",
":",
"\"both\"",
",",
"ast",
":",
"false",
"}",
")",
")",
";",
"}",
"if",
"(",
"cache",
")",
"{",
"result",
".",
"mtime",
"=",
"mtime",
"(",
"filename",
")",
";",
"cache",
"[",
"cacheKey",
"]",
"=",
"result",
";",
"}",
"maps",
"[",
"filename",
"]",
"=",
"result",
".",
"map",
";",
"return",
"result",
".",
"code",
";",
"}"
]
| Compile a `filename` with optional `opts`. | [
"Compile",
"a",
"filename",
"with",
"optional",
"opts",
"."
]
| 9f14246db3327abb0c4a5d7a3d55bd7816ebbd40 | https://github.com/noderaider/repackage/blob/9f14246db3327abb0c4a5d7a3d55bd7816ebbd40/jspm_packages/npm/[email protected]/lib/api/register/node.js#L110-L148 |
39,885 | noderaider/repackage | jspm_packages/npm/[email protected]/lib/api/register/node.js | shouldIgnore | function shouldIgnore(filename) {
if (!ignore && !only) {
return getRelativePath(filename).split(_path2["default"].sep).indexOf("node_modules") >= 0;
} else {
return util.shouldIgnore(filename, ignore || [], only);
}
} | javascript | function shouldIgnore(filename) {
if (!ignore && !only) {
return getRelativePath(filename).split(_path2["default"].sep).indexOf("node_modules") >= 0;
} else {
return util.shouldIgnore(filename, ignore || [], only);
}
} | [
"function",
"shouldIgnore",
"(",
"filename",
")",
"{",
"if",
"(",
"!",
"ignore",
"&&",
"!",
"only",
")",
"{",
"return",
"getRelativePath",
"(",
"filename",
")",
".",
"split",
"(",
"_path2",
"[",
"\"default\"",
"]",
".",
"sep",
")",
".",
"indexOf",
"(",
"\"node_modules\"",
")",
">=",
"0",
";",
"}",
"else",
"{",
"return",
"util",
".",
"shouldIgnore",
"(",
"filename",
",",
"ignore",
"||",
"[",
"]",
",",
"only",
")",
";",
"}",
"}"
]
| Test if a `filename` should be ignored by Babel. | [
"Test",
"if",
"a",
"filename",
"should",
"be",
"ignored",
"by",
"Babel",
"."
]
| 9f14246db3327abb0c4a5d7a3d55bd7816ebbd40 | https://github.com/noderaider/repackage/blob/9f14246db3327abb0c4a5d7a3d55bd7816ebbd40/jspm_packages/npm/[email protected]/lib/api/register/node.js#L154-L160 |
39,886 | noderaider/repackage | jspm_packages/npm/[email protected]/lib/api/register/node.js | istanbulLoader | function istanbulLoader(m, filename, old) {
istanbulMonkey[filename] = true;
old(m, filename);
} | javascript | function istanbulLoader(m, filename, old) {
istanbulMonkey[filename] = true;
old(m, filename);
} | [
"function",
"istanbulLoader",
"(",
"m",
",",
"filename",
",",
"old",
")",
"{",
"istanbulMonkey",
"[",
"filename",
"]",
"=",
"true",
";",
"old",
"(",
"m",
",",
"filename",
")",
";",
"}"
]
| Replacement for the loader for istanbul. | [
"Replacement",
"for",
"the",
"loader",
"for",
"istanbul",
"."
]
| 9f14246db3327abb0c4a5d7a3d55bd7816ebbd40 | https://github.com/noderaider/repackage/blob/9f14246db3327abb0c4a5d7a3d55bd7816ebbd40/jspm_packages/npm/[email protected]/lib/api/register/node.js#L191-L194 |
39,887 | noderaider/repackage | jspm_packages/npm/[email protected]/lib/api/register/node.js | registerExtension | function registerExtension(ext) {
var old = oldHandlers[ext] || oldHandlers[".js"] || require.extensions[".js"];
var loader = normalLoader;
if (process.env.running_under_istanbul) loader = istanbulLoader;
require.extensions[ext] = function (m, filename) {
if (shouldIgnore(filename)) {
old(m, filename);
} else {
loader(m, filename, old);
}
};
} | javascript | function registerExtension(ext) {
var old = oldHandlers[ext] || oldHandlers[".js"] || require.extensions[".js"];
var loader = normalLoader;
if (process.env.running_under_istanbul) loader = istanbulLoader;
require.extensions[ext] = function (m, filename) {
if (shouldIgnore(filename)) {
old(m, filename);
} else {
loader(m, filename, old);
}
};
} | [
"function",
"registerExtension",
"(",
"ext",
")",
"{",
"var",
"old",
"=",
"oldHandlers",
"[",
"ext",
"]",
"||",
"oldHandlers",
"[",
"\".js\"",
"]",
"||",
"require",
".",
"extensions",
"[",
"\".js\"",
"]",
";",
"var",
"loader",
"=",
"normalLoader",
";",
"if",
"(",
"process",
".",
"env",
".",
"running_under_istanbul",
")",
"loader",
"=",
"istanbulLoader",
";",
"require",
".",
"extensions",
"[",
"ext",
"]",
"=",
"function",
"(",
"m",
",",
"filename",
")",
"{",
"if",
"(",
"shouldIgnore",
"(",
"filename",
")",
")",
"{",
"old",
"(",
"m",
",",
"filename",
")",
";",
"}",
"else",
"{",
"loader",
"(",
"m",
",",
"filename",
",",
"old",
")",
";",
"}",
"}",
";",
"}"
]
| Register a loader for an extension. | [
"Register",
"a",
"loader",
"for",
"an",
"extension",
"."
]
| 9f14246db3327abb0c4a5d7a3d55bd7816ebbd40 | https://github.com/noderaider/repackage/blob/9f14246db3327abb0c4a5d7a3d55bd7816ebbd40/jspm_packages/npm/[email protected]/lib/api/register/node.js#L208-L221 |
39,888 | noderaider/repackage | jspm_packages/npm/[email protected]/lib/api/register/node.js | hookExtensions | function hookExtensions(_exts) {
_lodashCollectionEach2["default"](oldHandlers, function (old, ext) {
if (old === undefined) {
delete require.extensions[ext];
} else {
require.extensions[ext] = old;
}
});
oldHandlers = {};
_lodashCollectionEach2["default"](_exts, function (ext) {
oldHandlers[ext] = require.extensions[ext];
registerExtension(ext);
});
} | javascript | function hookExtensions(_exts) {
_lodashCollectionEach2["default"](oldHandlers, function (old, ext) {
if (old === undefined) {
delete require.extensions[ext];
} else {
require.extensions[ext] = old;
}
});
oldHandlers = {};
_lodashCollectionEach2["default"](_exts, function (ext) {
oldHandlers[ext] = require.extensions[ext];
registerExtension(ext);
});
} | [
"function",
"hookExtensions",
"(",
"_exts",
")",
"{",
"_lodashCollectionEach2",
"[",
"\"default\"",
"]",
"(",
"oldHandlers",
",",
"function",
"(",
"old",
",",
"ext",
")",
"{",
"if",
"(",
"old",
"===",
"undefined",
")",
"{",
"delete",
"require",
".",
"extensions",
"[",
"ext",
"]",
";",
"}",
"else",
"{",
"require",
".",
"extensions",
"[",
"ext",
"]",
"=",
"old",
";",
"}",
"}",
")",
";",
"oldHandlers",
"=",
"{",
"}",
";",
"_lodashCollectionEach2",
"[",
"\"default\"",
"]",
"(",
"_exts",
",",
"function",
"(",
"ext",
")",
"{",
"oldHandlers",
"[",
"ext",
"]",
"=",
"require",
".",
"extensions",
"[",
"ext",
"]",
";",
"registerExtension",
"(",
"ext",
")",
";",
"}",
")",
";",
"}"
]
| Register loader for given extensions. | [
"Register",
"loader",
"for",
"given",
"extensions",
"."
]
| 9f14246db3327abb0c4a5d7a3d55bd7816ebbd40 | https://github.com/noderaider/repackage/blob/9f14246db3327abb0c4a5d7a3d55bd7816ebbd40/jspm_packages/npm/[email protected]/lib/api/register/node.js#L227-L242 |
39,889 | datagovsg/datagovsg-plottable-charts | src/helpers.js | monthConfigs | function monthConfigs () {
return [
[{
interval: Plottable.TimeInterval.month,
step: 1,
// full month name
formatter: Plottable.Formatters.time('%B')
}, {
interval: Plottable.TimeInterval.year,
step: 1,
formatter: Plottable.Formatters.time('%Y')
}],
[{
interval: Plottable.TimeInterval.month,
step: 1,
// short month name
formatter: Plottable.Formatters.time('%b')
}, {
interval: Plottable.TimeInterval.year,
step: 1,
formatter: Plottable.Formatters.time('%Y')
}],
[{
interval: Plottable.TimeInterval.month,
step: 1,
// month in numbers
formatter: Plottable.Formatters.time('%m')
}, {
interval: Plottable.TimeInterval.year,
step: 1,
formatter: Plottable.Formatters.time('%Y')
}],
[{
interval: Plottable.TimeInterval.month,
step: 1,
// month in numbers
formatter: Plottable.Formatters.time('%-m')
}, {
interval: Plottable.TimeInterval.year,
step: 1,
formatter: Plottable.Formatters.time('%Y')
}]
]
} | javascript | function monthConfigs () {
return [
[{
interval: Plottable.TimeInterval.month,
step: 1,
// full month name
formatter: Plottable.Formatters.time('%B')
}, {
interval: Plottable.TimeInterval.year,
step: 1,
formatter: Plottable.Formatters.time('%Y')
}],
[{
interval: Plottable.TimeInterval.month,
step: 1,
// short month name
formatter: Plottable.Formatters.time('%b')
}, {
interval: Plottable.TimeInterval.year,
step: 1,
formatter: Plottable.Formatters.time('%Y')
}],
[{
interval: Plottable.TimeInterval.month,
step: 1,
// month in numbers
formatter: Plottable.Formatters.time('%m')
}, {
interval: Plottable.TimeInterval.year,
step: 1,
formatter: Plottable.Formatters.time('%Y')
}],
[{
interval: Plottable.TimeInterval.month,
step: 1,
// month in numbers
formatter: Plottable.Formatters.time('%-m')
}, {
interval: Plottable.TimeInterval.year,
step: 1,
formatter: Plottable.Formatters.time('%Y')
}]
]
} | [
"function",
"monthConfigs",
"(",
")",
"{",
"return",
"[",
"[",
"{",
"interval",
":",
"Plottable",
".",
"TimeInterval",
".",
"month",
",",
"step",
":",
"1",
",",
"// full month name",
"formatter",
":",
"Plottable",
".",
"Formatters",
".",
"time",
"(",
"'%B'",
")",
"}",
",",
"{",
"interval",
":",
"Plottable",
".",
"TimeInterval",
".",
"year",
",",
"step",
":",
"1",
",",
"formatter",
":",
"Plottable",
".",
"Formatters",
".",
"time",
"(",
"'%Y'",
")",
"}",
"]",
",",
"[",
"{",
"interval",
":",
"Plottable",
".",
"TimeInterval",
".",
"month",
",",
"step",
":",
"1",
",",
"// short month name",
"formatter",
":",
"Plottable",
".",
"Formatters",
".",
"time",
"(",
"'%b'",
")",
"}",
",",
"{",
"interval",
":",
"Plottable",
".",
"TimeInterval",
".",
"year",
",",
"step",
":",
"1",
",",
"formatter",
":",
"Plottable",
".",
"Formatters",
".",
"time",
"(",
"'%Y'",
")",
"}",
"]",
",",
"[",
"{",
"interval",
":",
"Plottable",
".",
"TimeInterval",
".",
"month",
",",
"step",
":",
"1",
",",
"// month in numbers",
"formatter",
":",
"Plottable",
".",
"Formatters",
".",
"time",
"(",
"'%m'",
")",
"}",
",",
"{",
"interval",
":",
"Plottable",
".",
"TimeInterval",
".",
"year",
",",
"step",
":",
"1",
",",
"formatter",
":",
"Plottable",
".",
"Formatters",
".",
"time",
"(",
"'%Y'",
")",
"}",
"]",
",",
"[",
"{",
"interval",
":",
"Plottable",
".",
"TimeInterval",
".",
"month",
",",
"step",
":",
"1",
",",
"// month in numbers",
"formatter",
":",
"Plottable",
".",
"Formatters",
".",
"time",
"(",
"'%-m'",
")",
"}",
",",
"{",
"interval",
":",
"Plottable",
".",
"TimeInterval",
".",
"year",
",",
"step",
":",
"1",
",",
"formatter",
":",
"Plottable",
".",
"Formatters",
".",
"time",
"(",
"'%Y'",
")",
"}",
"]",
"]",
"}"
]
| use the month steps in the orginal plottable library | [
"use",
"the",
"month",
"steps",
"in",
"the",
"orginal",
"plottable",
"library"
]
| f08c65c50f4be32dacb984ba5fd916e23d11e9d2 | https://github.com/datagovsg/datagovsg-plottable-charts/blob/f08c65c50f4be32dacb984ba5fd916e23d11e9d2/src/helpers.js#L154-L197 |
39,890 | oscarr-reyes/node-diet-cross-origin | lib/helper.js | parseHeader | function parseHeader(value, name){
// Throw error if value is not array or string
if(value && (!utils.isArray(value) && !utils.isString(value))){
throw new Error(`Default Header for "${name}" must be Array or String`);
}
// In case when no error was threw, check if value is array
// Set all values to UpperCase and join the values into a string
else if(utils.isArray(value)){
// Capitalize each string in the array
value.forEach((element, index) => {
var stringParts = element.split("-");
var arr = [];
stringParts.forEach((e, i) => {
arr.push(firstUpperCase(e));
});
value[index] = arr.join("-");
});
value = value.join(", ");
}
return value;
} | javascript | function parseHeader(value, name){
// Throw error if value is not array or string
if(value && (!utils.isArray(value) && !utils.isString(value))){
throw new Error(`Default Header for "${name}" must be Array or String`);
}
// In case when no error was threw, check if value is array
// Set all values to UpperCase and join the values into a string
else if(utils.isArray(value)){
// Capitalize each string in the array
value.forEach((element, index) => {
var stringParts = element.split("-");
var arr = [];
stringParts.forEach((e, i) => {
arr.push(firstUpperCase(e));
});
value[index] = arr.join("-");
});
value = value.join(", ");
}
return value;
} | [
"function",
"parseHeader",
"(",
"value",
",",
"name",
")",
"{",
"// Throw error if value is not array or string",
"if",
"(",
"value",
"&&",
"(",
"!",
"utils",
".",
"isArray",
"(",
"value",
")",
"&&",
"!",
"utils",
".",
"isString",
"(",
"value",
")",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"name",
"}",
"`",
")",
";",
"}",
"// In case when no error was threw, check if value is array",
"// Set all values to UpperCase and join the values into a string",
"else",
"if",
"(",
"utils",
".",
"isArray",
"(",
"value",
")",
")",
"{",
"// Capitalize each string in the array",
"value",
".",
"forEach",
"(",
"(",
"element",
",",
"index",
")",
"=>",
"{",
"var",
"stringParts",
"=",
"element",
".",
"split",
"(",
"\"-\"",
")",
";",
"var",
"arr",
"=",
"[",
"]",
";",
"stringParts",
".",
"forEach",
"(",
"(",
"e",
",",
"i",
")",
"=>",
"{",
"arr",
".",
"push",
"(",
"firstUpperCase",
"(",
"e",
")",
")",
";",
"}",
")",
";",
"value",
"[",
"index",
"]",
"=",
"arr",
".",
"join",
"(",
"\"-\"",
")",
";",
"}",
")",
";",
"value",
"=",
"value",
".",
"join",
"(",
"\", \"",
")",
";",
"}",
"return",
"value",
";",
"}"
]
| Parses the value for header data in response
@param {String|Array} value The value of the data to be parsed for the header
@param {String} name The name of the header that is going to be parsed
@return {String} The parsed value for the header | [
"Parses",
"the",
"value",
"for",
"header",
"data",
"in",
"response"
]
| 3fb5a16a39b740607f4898f1d75d115c4ecfa16d | https://github.com/oscarr-reyes/node-diet-cross-origin/blob/3fb5a16a39b740607f4898f1d75d115c4ecfa16d/lib/helper.js#L65-L90 |
39,891 | myelements/myelements.jquery | lib/elements-event-handler.js | ElementsEventHandler | function ElementsEventHandler(socket) {
var _this = this;
//Call EventEmmiter _contructor_
events.EventEmitter.call(this);
this.socket = socket;
// On every message event received by socket we get
// an message event object like {event:, data:}
// we emit a local event through an EventEmitter interface
// with .event as event type and .data as
// event data;
this.socket.on('message', function(message, callback) {
debug("Forwarding frontend message '%s', with data %j", message.event, message.data);
if (message.event !== undefined) {
_this.emit(message.event, message.data);
if (typeof callback === 'function') {
callback();
}
}
if (message.event === "userinput" && message.scope !== undefined) {
debug("userinput received: %s", JSON.stringify(message));
_this.emit(message.scope, message.data);
}
});
this.socket.on("disconnect", function() {
delete(this.socket);
_this.emit("disconnect");
});
} | javascript | function ElementsEventHandler(socket) {
var _this = this;
//Call EventEmmiter _contructor_
events.EventEmitter.call(this);
this.socket = socket;
// On every message event received by socket we get
// an message event object like {event:, data:}
// we emit a local event through an EventEmitter interface
// with .event as event type and .data as
// event data;
this.socket.on('message', function(message, callback) {
debug("Forwarding frontend message '%s', with data %j", message.event, message.data);
if (message.event !== undefined) {
_this.emit(message.event, message.data);
if (typeof callback === 'function') {
callback();
}
}
if (message.event === "userinput" && message.scope !== undefined) {
debug("userinput received: %s", JSON.stringify(message));
_this.emit(message.scope, message.data);
}
});
this.socket.on("disconnect", function() {
delete(this.socket);
_this.emit("disconnect");
});
} | [
"function",
"ElementsEventHandler",
"(",
"socket",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"//Call EventEmmiter _contructor_",
"events",
".",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"socket",
"=",
"socket",
";",
"// On every message event received by socket we get",
"// an message event object like {event:, data:} ",
"// we emit a local event through an EventEmitter interface",
"// with .event as event type and .data as",
"// event data;",
"this",
".",
"socket",
".",
"on",
"(",
"'message'",
",",
"function",
"(",
"message",
",",
"callback",
")",
"{",
"debug",
"(",
"\"Forwarding frontend message '%s', with data %j\"",
",",
"message",
".",
"event",
",",
"message",
".",
"data",
")",
";",
"if",
"(",
"message",
".",
"event",
"!==",
"undefined",
")",
"{",
"_this",
".",
"emit",
"(",
"message",
".",
"event",
",",
"message",
".",
"data",
")",
";",
"if",
"(",
"typeof",
"callback",
"===",
"'function'",
")",
"{",
"callback",
"(",
")",
";",
"}",
"}",
"if",
"(",
"message",
".",
"event",
"===",
"\"userinput\"",
"&&",
"message",
".",
"scope",
"!==",
"undefined",
")",
"{",
"debug",
"(",
"\"userinput received: %s\"",
",",
"JSON",
".",
"stringify",
"(",
"message",
")",
")",
";",
"_this",
".",
"emit",
"(",
"message",
".",
"scope",
",",
"message",
".",
"data",
")",
";",
"}",
"}",
")",
";",
"this",
".",
"socket",
".",
"on",
"(",
"\"disconnect\"",
",",
"function",
"(",
")",
"{",
"delete",
"(",
"this",
".",
"socket",
")",
";",
"_this",
".",
"emit",
"(",
"\"disconnect\"",
")",
";",
"}",
")",
";",
"}"
]
| Creates an event emitter and forwards every event triggered to client
@param {io.Client} socket A socket.io client instance on which to send messages. | [
"Creates",
"an",
"event",
"emitter",
"and",
"forwards",
"every",
"event",
"triggered",
"to",
"client"
]
| 0123edec30fc70ea494611695b5b2593e4f23745 | https://github.com/myelements/myelements.jquery/blob/0123edec30fc70ea494611695b5b2593e4f23745/lib/elements-event-handler.js#L15-L43 |
39,892 | lethexa/lethexa-geo | lethexa-geo.js | function (m, u) {
return [
m[0][0] * u[0] + m[0][1] * u[1] + m[0][2] * u[2],
m[1][0] * u[0] + m[1][1] * u[1] + m[1][2] * u[2],
m[2][0] * u[0] + m[2][1] * u[1] + m[2][2] * u[2]
];
} | javascript | function (m, u) {
return [
m[0][0] * u[0] + m[0][1] * u[1] + m[0][2] * u[2],
m[1][0] * u[0] + m[1][1] * u[1] + m[1][2] * u[2],
m[2][0] * u[0] + m[2][1] * u[1] + m[2][2] * u[2]
];
} | [
"function",
"(",
"m",
",",
"u",
")",
"{",
"return",
"[",
"m",
"[",
"0",
"]",
"[",
"0",
"]",
"*",
"u",
"[",
"0",
"]",
"+",
"m",
"[",
"0",
"]",
"[",
"1",
"]",
"*",
"u",
"[",
"1",
"]",
"+",
"m",
"[",
"0",
"]",
"[",
"2",
"]",
"*",
"u",
"[",
"2",
"]",
",",
"m",
"[",
"1",
"]",
"[",
"0",
"]",
"*",
"u",
"[",
"0",
"]",
"+",
"m",
"[",
"1",
"]",
"[",
"1",
"]",
"*",
"u",
"[",
"1",
"]",
"+",
"m",
"[",
"1",
"]",
"[",
"2",
"]",
"*",
"u",
"[",
"2",
"]",
",",
"m",
"[",
"2",
"]",
"[",
"0",
"]",
"*",
"u",
"[",
"0",
"]",
"+",
"m",
"[",
"2",
"]",
"[",
"1",
"]",
"*",
"u",
"[",
"1",
"]",
"+",
"m",
"[",
"2",
"]",
"[",
"2",
"]",
"*",
"u",
"[",
"2",
"]",
"]",
";",
"}"
]
| Multiplies with a matrix with a vector.
@method mulMatrixVector
@param m {Matrix} A matrix
@param u {Vector} A vector
@return The resulting vector | [
"Multiplies",
"with",
"a",
"matrix",
"with",
"a",
"vector",
"."
]
| e3b7628d6243aee13e5de8b0cab6dea7aa5937a1 | https://github.com/lethexa/lethexa-geo/blob/e3b7628d6243aee13e5de8b0cab6dea7aa5937a1/lethexa-geo.js#L95-L101 |
|
39,893 | lethexa/lethexa-geo | lethexa-geo.js | function (px, py, radius) {
var cx = 0;
var cy = 0;
var dx = cx - px;
var dy = cy - py;
var dd = Math.sqrt(dx * dx + dy * dy);
var a = Math.asin(radius / dd);
var b = Math.atan2(dy, dx);
var t1 = b - a;
var t2 = b + a;
return {
p1: [radius * Math.sin(t1), radius * -Math.cos(t1)],
p2: [radius * -Math.sin(t2), radius * Math.cos(t2)],
center: [-radius * Math.cos(b), radius * -Math.sin(b)],
arclength: 2 * a
};
} | javascript | function (px, py, radius) {
var cx = 0;
var cy = 0;
var dx = cx - px;
var dy = cy - py;
var dd = Math.sqrt(dx * dx + dy * dy);
var a = Math.asin(radius / dd);
var b = Math.atan2(dy, dx);
var t1 = b - a;
var t2 = b + a;
return {
p1: [radius * Math.sin(t1), radius * -Math.cos(t1)],
p2: [radius * -Math.sin(t2), radius * Math.cos(t2)],
center: [-radius * Math.cos(b), radius * -Math.sin(b)],
arclength: 2 * a
};
} | [
"function",
"(",
"px",
",",
"py",
",",
"radius",
")",
"{",
"var",
"cx",
"=",
"0",
";",
"var",
"cy",
"=",
"0",
";",
"var",
"dx",
"=",
"cx",
"-",
"px",
";",
"var",
"dy",
"=",
"cy",
"-",
"py",
";",
"var",
"dd",
"=",
"Math",
".",
"sqrt",
"(",
"dx",
"*",
"dx",
"+",
"dy",
"*",
"dy",
")",
";",
"var",
"a",
"=",
"Math",
".",
"asin",
"(",
"radius",
"/",
"dd",
")",
";",
"var",
"b",
"=",
"Math",
".",
"atan2",
"(",
"dy",
",",
"dx",
")",
";",
"var",
"t1",
"=",
"b",
"-",
"a",
";",
"var",
"t2",
"=",
"b",
"+",
"a",
";",
"return",
"{",
"p1",
":",
"[",
"radius",
"*",
"Math",
".",
"sin",
"(",
"t1",
")",
",",
"radius",
"*",
"-",
"Math",
".",
"cos",
"(",
"t1",
")",
"]",
",",
"p2",
":",
"[",
"radius",
"*",
"-",
"Math",
".",
"sin",
"(",
"t2",
")",
",",
"radius",
"*",
"Math",
".",
"cos",
"(",
"t2",
")",
"]",
",",
"center",
":",
"[",
"-",
"radius",
"*",
"Math",
".",
"cos",
"(",
"b",
")",
",",
"radius",
"*",
"-",
"Math",
".",
"sin",
"(",
"b",
")",
"]",
",",
"arclength",
":",
"2",
"*",
"a",
"}",
";",
"}"
]
| Calculates the tangent from a point to a circle. | [
"Calculates",
"the",
"tangent",
"from",
"a",
"point",
"to",
"a",
"circle",
"."
]
| e3b7628d6243aee13e5de8b0cab6dea7aa5937a1 | https://github.com/lethexa/lethexa-geo/blob/e3b7628d6243aee13e5de8b0cab6dea7aa5937a1/lethexa-geo.js#L105-L121 |
|
39,894 | Happy0/ssb-embedded-chat | index.js | getChatboxElement | function getChatboxElement() {
var content = h('div', {
});
var keyPressHandler = (e) => {
if (e.charCode === 13) {
var messageText = e.srcElement.value;
if (messageText.length > 0) {
e.srcElement.value = "";
sendMessage(messageText);
}
}
}
var sendMessageBox = h('input', {
onkeypress: keyPressHandler,
className: 'ssb-embedded-chat-input-box',
disabled: !chatboxEnabled
});
var scroller = h('div', {
style: {
'overflow-y': 'auto',
'overflow-x': 'hidden'
},
className: 'ssb-embedded-chat-messages'
}, content);
pull(
messagesSource(),
aborter,
pull.asyncMap(getNameAndChatMessage),
Scroller(scroller,
content,
(details) =>
renderChatMessage(details.message, details.displayName, details.isOld), false, true)
);
var chatBox = h('div', {
className: 'ssb-embedded-chat',
}, scroller, sendMessageBox)
return chatBox;
} | javascript | function getChatboxElement() {
var content = h('div', {
});
var keyPressHandler = (e) => {
if (e.charCode === 13) {
var messageText = e.srcElement.value;
if (messageText.length > 0) {
e.srcElement.value = "";
sendMessage(messageText);
}
}
}
var sendMessageBox = h('input', {
onkeypress: keyPressHandler,
className: 'ssb-embedded-chat-input-box',
disabled: !chatboxEnabled
});
var scroller = h('div', {
style: {
'overflow-y': 'auto',
'overflow-x': 'hidden'
},
className: 'ssb-embedded-chat-messages'
}, content);
pull(
messagesSource(),
aborter,
pull.asyncMap(getNameAndChatMessage),
Scroller(scroller,
content,
(details) =>
renderChatMessage(details.message, details.displayName, details.isOld), false, true)
);
var chatBox = h('div', {
className: 'ssb-embedded-chat',
}, scroller, sendMessageBox)
return chatBox;
} | [
"function",
"getChatboxElement",
"(",
")",
"{",
"var",
"content",
"=",
"h",
"(",
"'div'",
",",
"{",
"}",
")",
";",
"var",
"keyPressHandler",
"=",
"(",
"e",
")",
"=>",
"{",
"if",
"(",
"e",
".",
"charCode",
"===",
"13",
")",
"{",
"var",
"messageText",
"=",
"e",
".",
"srcElement",
".",
"value",
";",
"if",
"(",
"messageText",
".",
"length",
">",
"0",
")",
"{",
"e",
".",
"srcElement",
".",
"value",
"=",
"\"\"",
";",
"sendMessage",
"(",
"messageText",
")",
";",
"}",
"}",
"}",
"var",
"sendMessageBox",
"=",
"h",
"(",
"'input'",
",",
"{",
"onkeypress",
":",
"keyPressHandler",
",",
"className",
":",
"'ssb-embedded-chat-input-box'",
",",
"disabled",
":",
"!",
"chatboxEnabled",
"}",
")",
";",
"var",
"scroller",
"=",
"h",
"(",
"'div'",
",",
"{",
"style",
":",
"{",
"'overflow-y'",
":",
"'auto'",
",",
"'overflow-x'",
":",
"'hidden'",
"}",
",",
"className",
":",
"'ssb-embedded-chat-messages'",
"}",
",",
"content",
")",
";",
"pull",
"(",
"messagesSource",
"(",
")",
",",
"aborter",
",",
"pull",
".",
"asyncMap",
"(",
"getNameAndChatMessage",
")",
",",
"Scroller",
"(",
"scroller",
",",
"content",
",",
"(",
"details",
")",
"=>",
"renderChatMessage",
"(",
"details",
".",
"message",
",",
"details",
".",
"displayName",
",",
"details",
".",
"isOld",
")",
",",
"false",
",",
"true",
")",
")",
";",
"var",
"chatBox",
"=",
"h",
"(",
"'div'",
",",
"{",
"className",
":",
"'ssb-embedded-chat'",
",",
"}",
",",
"scroller",
",",
"sendMessageBox",
")",
"return",
"chatBox",
";",
"}"
]
| Return the scroller HTML DOM element that the consuming code
can attach to the DOM somewhere. | [
"Return",
"the",
"scroller",
"HTML",
"DOM",
"element",
"that",
"the",
"consuming",
"code",
"can",
"attach",
"to",
"the",
"DOM",
"somewhere",
"."
]
| 1504df2b132c7667dac61167168185f8c3fa1246 | https://github.com/Happy0/ssb-embedded-chat/blob/1504df2b132c7667dac61167168185f8c3fa1246/index.js#L111-L157 |
39,895 | preceptorjs/taxi | lib/driver.js | setupDebug | function setupDebug (driver, options) {
var indentation = 0;
function stringFill (filler, length) {
var buffer = new Buffer(length);
buffer.fill(filler);
return buffer.toString();
}
function getIndentation (add) {
return stringFill(' ', (indentation + add) * 2);
}
if (options.debug) {
if (options.httpDebug) {
driver.on('request', function (req) {
console.log(getIndentation(1) + "Request: ", JSON.stringify(req).substr(0, 5000));
});
driver.on('response', function (res) {
console.log(getIndentation(1) + "Response: ", JSON.stringify(res).substr(0, 5000));
});
}
driver.on('method-call', function (event) {
var msg = event.target;
indentation = event.indentation;
if (event.selector) {
msg += '(' + util.inspect(event.selector, {colors: true}) + ')';
}
msg += '.' + event.name;
msg += '(' + event.args.map(function (a) {
return util.inspect(a, {colors: true});
}).join(', ') + ')';
if (event.result && typeof event.result !== 'object') {
msg += ' => ' + util.inspect(event.result, {colors: true});
}
console.log(getIndentation(0) + '[' + (event.state + stringFill(' ', 5)).substr(0, 5) + '] ' + msg);
if (event.state.toLowerCase() !== 'start') {
console.log(getIndentation(0) + stringFill('-', 50));
}
});
}
} | javascript | function setupDebug (driver, options) {
var indentation = 0;
function stringFill (filler, length) {
var buffer = new Buffer(length);
buffer.fill(filler);
return buffer.toString();
}
function getIndentation (add) {
return stringFill(' ', (indentation + add) * 2);
}
if (options.debug) {
if (options.httpDebug) {
driver.on('request', function (req) {
console.log(getIndentation(1) + "Request: ", JSON.stringify(req).substr(0, 5000));
});
driver.on('response', function (res) {
console.log(getIndentation(1) + "Response: ", JSON.stringify(res).substr(0, 5000));
});
}
driver.on('method-call', function (event) {
var msg = event.target;
indentation = event.indentation;
if (event.selector) {
msg += '(' + util.inspect(event.selector, {colors: true}) + ')';
}
msg += '.' + event.name;
msg += '(' + event.args.map(function (a) {
return util.inspect(a, {colors: true});
}).join(', ') + ')';
if (event.result && typeof event.result !== 'object') {
msg += ' => ' + util.inspect(event.result, {colors: true});
}
console.log(getIndentation(0) + '[' + (event.state + stringFill(' ', 5)).substr(0, 5) + '] ' + msg);
if (event.state.toLowerCase() !== 'start') {
console.log(getIndentation(0) + stringFill('-', 50));
}
});
}
} | [
"function",
"setupDebug",
"(",
"driver",
",",
"options",
")",
"{",
"var",
"indentation",
"=",
"0",
";",
"function",
"stringFill",
"(",
"filler",
",",
"length",
")",
"{",
"var",
"buffer",
"=",
"new",
"Buffer",
"(",
"length",
")",
";",
"buffer",
".",
"fill",
"(",
"filler",
")",
";",
"return",
"buffer",
".",
"toString",
"(",
")",
";",
"}",
"function",
"getIndentation",
"(",
"add",
")",
"{",
"return",
"stringFill",
"(",
"' '",
",",
"(",
"indentation",
"+",
"add",
")",
"*",
"2",
")",
";",
"}",
"if",
"(",
"options",
".",
"debug",
")",
"{",
"if",
"(",
"options",
".",
"httpDebug",
")",
"{",
"driver",
".",
"on",
"(",
"'request'",
",",
"function",
"(",
"req",
")",
"{",
"console",
".",
"log",
"(",
"getIndentation",
"(",
"1",
")",
"+",
"\"Request: \"",
",",
"JSON",
".",
"stringify",
"(",
"req",
")",
".",
"substr",
"(",
"0",
",",
"5000",
")",
")",
";",
"}",
")",
";",
"driver",
".",
"on",
"(",
"'response'",
",",
"function",
"(",
"res",
")",
"{",
"console",
".",
"log",
"(",
"getIndentation",
"(",
"1",
")",
"+",
"\"Response: \"",
",",
"JSON",
".",
"stringify",
"(",
"res",
")",
".",
"substr",
"(",
"0",
",",
"5000",
")",
")",
";",
"}",
")",
";",
"}",
"driver",
".",
"on",
"(",
"'method-call'",
",",
"function",
"(",
"event",
")",
"{",
"var",
"msg",
"=",
"event",
".",
"target",
";",
"indentation",
"=",
"event",
".",
"indentation",
";",
"if",
"(",
"event",
".",
"selector",
")",
"{",
"msg",
"+=",
"'('",
"+",
"util",
".",
"inspect",
"(",
"event",
".",
"selector",
",",
"{",
"colors",
":",
"true",
"}",
")",
"+",
"')'",
";",
"}",
"msg",
"+=",
"'.'",
"+",
"event",
".",
"name",
";",
"msg",
"+=",
"'('",
"+",
"event",
".",
"args",
".",
"map",
"(",
"function",
"(",
"a",
")",
"{",
"return",
"util",
".",
"inspect",
"(",
"a",
",",
"{",
"colors",
":",
"true",
"}",
")",
";",
"}",
")",
".",
"join",
"(",
"', '",
")",
"+",
"')'",
";",
"if",
"(",
"event",
".",
"result",
"&&",
"typeof",
"event",
".",
"result",
"!==",
"'object'",
")",
"{",
"msg",
"+=",
"' => '",
"+",
"util",
".",
"inspect",
"(",
"event",
".",
"result",
",",
"{",
"colors",
":",
"true",
"}",
")",
";",
"}",
"console",
".",
"log",
"(",
"getIndentation",
"(",
"0",
")",
"+",
"'['",
"+",
"(",
"event",
".",
"state",
"+",
"stringFill",
"(",
"' '",
",",
"5",
")",
")",
".",
"substr",
"(",
"0",
",",
"5",
")",
"+",
"'] '",
"+",
"msg",
")",
";",
"if",
"(",
"event",
".",
"state",
".",
"toLowerCase",
"(",
")",
"!==",
"'start'",
")",
"{",
"console",
".",
"log",
"(",
"getIndentation",
"(",
"0",
")",
"+",
"stringFill",
"(",
"'-'",
",",
"50",
")",
")",
";",
"}",
"}",
")",
";",
"}",
"}"
]
| Setup debug output
@param {Driver} driver
@param {object} options | [
"Setup",
"debug",
"output"
]
| 96ab5a5c5fa9dc50f325ba4de52dd90009073ca3 | https://github.com/preceptorjs/taxi/blob/96ab5a5c5fa9dc50f325ba4de52dd90009073ca3/lib/driver.js#L737-L778 |
39,896 | kevoree/kevoree-js | libraries/node/javascript/lib/AdaptationEngine.js | AdaptationEngine | function AdaptationEngine(node) {
this.node = node;
this.modelObjMapper = new ModelObjectMapper();
const factory = new kevoree.factory.DefaultKevoreeFactory();
this.compare = factory.createModelCompare();
this.alreadyProcessedTraces = {};
this.targetModel = null;
} | javascript | function AdaptationEngine(node) {
this.node = node;
this.modelObjMapper = new ModelObjectMapper();
const factory = new kevoree.factory.DefaultKevoreeFactory();
this.compare = factory.createModelCompare();
this.alreadyProcessedTraces = {};
this.targetModel = null;
} | [
"function",
"AdaptationEngine",
"(",
"node",
")",
"{",
"this",
".",
"node",
"=",
"node",
";",
"this",
".",
"modelObjMapper",
"=",
"new",
"ModelObjectMapper",
"(",
")",
";",
"const",
"factory",
"=",
"new",
"kevoree",
".",
"factory",
".",
"DefaultKevoreeFactory",
"(",
")",
";",
"this",
".",
"compare",
"=",
"factory",
".",
"createModelCompare",
"(",
")",
";",
"this",
".",
"alreadyProcessedTraces",
"=",
"{",
"}",
";",
"this",
".",
"targetModel",
"=",
"null",
";",
"}"
]
| AdaptationEngine knows each AdaptationPrimitive command available
for JavascriptNode.
Plus, it handles model - object mapping
@type {AdaptationEngine} | [
"AdaptationEngine",
"knows",
"each",
"AdaptationPrimitive",
"command",
"available",
"for",
"JavascriptNode",
".",
"Plus",
"it",
"handles",
"model",
"-",
"object",
"mapping"
]
| 7eb62201a3bdf50ab0a6eb7f85424eecb44dbfcd | https://github.com/kevoree/kevoree-js/blob/7eb62201a3bdf50ab0a6eb7f85424eecb44dbfcd/libraries/node/javascript/lib/AdaptationEngine.js#L58-L65 |
39,897 | codius-deprecated/codius-engine | apis/secrets/index.js | SecretGenerator | function SecretGenerator(manifest, instance_id, secrets) {
ApiModule.call(this);
var self = this;
self._manifest = manifest;
self._secrets = secrets;
self._instance_id = instance_id;
} | javascript | function SecretGenerator(manifest, instance_id, secrets) {
ApiModule.call(this);
var self = this;
self._manifest = manifest;
self._secrets = secrets;
self._instance_id = instance_id;
} | [
"function",
"SecretGenerator",
"(",
"manifest",
",",
"instance_id",
",",
"secrets",
")",
"{",
"ApiModule",
".",
"call",
"(",
"this",
")",
";",
"var",
"self",
"=",
"this",
";",
"self",
".",
"_manifest",
"=",
"manifest",
";",
"self",
".",
"_secrets",
"=",
"secrets",
";",
"self",
".",
"_instance_id",
"=",
"instance_id",
";",
"}"
]
| Class used to deterministically generate unique contract secrets | [
"Class",
"used",
"to",
"deterministically",
"generate",
"unique",
"contract",
"secrets"
]
| 48aaea3d1a0dd2cf755a1905ff040e1667e8d131 | https://github.com/codius-deprecated/codius-engine/blob/48aaea3d1a0dd2cf755a1905ff040e1667e8d131/apis/secrets/index.js#L35-L43 |
39,898 | berkeleybop/bbop-graph-noctua | lib/edit.js | _get_annotations_by_filter | function _get_annotations_by_filter(filter){
var anchor = this;
var ret = [];
each(anchor._annotations, function(ann){
var res = filter(ann);
if( res && res === true ){
ret.push(ann);
}
});
return ret;
} | javascript | function _get_annotations_by_filter(filter){
var anchor = this;
var ret = [];
each(anchor._annotations, function(ann){
var res = filter(ann);
if( res && res === true ){
ret.push(ann);
}
});
return ret;
} | [
"function",
"_get_annotations_by_filter",
"(",
"filter",
")",
"{",
"var",
"anchor",
"=",
"this",
";",
"var",
"ret",
"=",
"[",
"]",
";",
"each",
"(",
"anchor",
".",
"_annotations",
",",
"function",
"(",
"ann",
")",
"{",
"var",
"res",
"=",
"filter",
"(",
"ann",
")",
";",
"if",
"(",
"res",
"&&",
"res",
"===",
"true",
")",
"{",
"ret",
".",
"push",
"(",
"ann",
")",
";",
"}",
"}",
")",
";",
"return",
"ret",
";",
"}"
]
| Get a sublist of annotation using the filter function. The filter
function take a single annotation as an argument, and adds to the
return list if it evaluates to true.
@name get_annotations_by_filter
@function
@param {Function} filter - function described above
@returns {Array} list of passing annotations | [
"Get",
"a",
"sublist",
"of",
"annotation",
"using",
"the",
"filter",
"function",
".",
"The",
"filter",
"function",
"take",
"a",
"single",
"annotation",
"as",
"an",
"argument",
"and",
"adds",
"to",
"the",
"return",
"list",
"if",
"it",
"evaluates",
"to",
"true",
"."
]
| 14ec0e6c9f93ece0ff7ee80a736596ddbe601cd3 | https://github.com/berkeleybop/bbop-graph-noctua/blob/14ec0e6c9f93ece0ff7ee80a736596ddbe601cd3/lib/edit.js#L266-L277 |
39,899 | berkeleybop/bbop-graph-noctua | lib/edit.js | _get_annotations_by_key | function _get_annotations_by_key(key){
var anchor = this;
var ret = [];
each(anchor._annotations, function(ann){
if( ann.key() === key ){
ret.push(ann);
}
});
return ret;
} | javascript | function _get_annotations_by_key(key){
var anchor = this;
var ret = [];
each(anchor._annotations, function(ann){
if( ann.key() === key ){
ret.push(ann);
}
});
return ret;
} | [
"function",
"_get_annotations_by_key",
"(",
"key",
")",
"{",
"var",
"anchor",
"=",
"this",
";",
"var",
"ret",
"=",
"[",
"]",
";",
"each",
"(",
"anchor",
".",
"_annotations",
",",
"function",
"(",
"ann",
")",
"{",
"if",
"(",
"ann",
".",
"key",
"(",
")",
"===",
"key",
")",
"{",
"ret",
".",
"push",
"(",
"ann",
")",
";",
"}",
"}",
")",
";",
"return",
"ret",
";",
"}"
]
| Get sublist of annotations with a certain key.
@name get_annotations_by_key
@function
@param {String} key - key to look for.
@returns {Array} list of list of annotations with that key | [
"Get",
"sublist",
"of",
"annotations",
"with",
"a",
"certain",
"key",
"."
]
| 14ec0e6c9f93ece0ff7ee80a736596ddbe601cd3 | https://github.com/berkeleybop/bbop-graph-noctua/blob/14ec0e6c9f93ece0ff7ee80a736596ddbe601cd3/lib/edit.js#L287-L298 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.