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
|
---|---|---|---|---|---|---|---|---|---|---|---|
46,100 | clns/node-http-range | lib/content-range.js | ContentRange | function ContentRange(unit, range, length) {
this.unit = unit;
this.range = range;
this.length = length;
if (this.range.high && this.length && this.length <= this.range.high) {
throw new Error('Length is less than or equal to the range');
}
} | javascript | function ContentRange(unit, range, length) {
this.unit = unit;
this.range = range;
this.length = length;
if (this.range.high && this.length && this.length <= this.range.high) {
throw new Error('Length is less than or equal to the range');
}
} | [
"function",
"ContentRange",
"(",
"unit",
",",
"range",
",",
"length",
")",
"{",
"this",
".",
"unit",
"=",
"unit",
";",
"this",
".",
"range",
"=",
"range",
";",
"this",
".",
"length",
"=",
"length",
";",
"if",
"(",
"this",
".",
"range",
".",
"high",
"&&",
"this",
".",
"length",
"&&",
"this",
".",
"length",
"<=",
"this",
".",
"range",
".",
"high",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Length is less than or equal to the range'",
")",
";",
"}",
"}"
]
| Content-Range HTTP Header class.
@param {String} unit Usually "bytes", but can be any token; http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.12
@param {RangeSpec|String|'*'} range A RangeSpec instance, a string like '0-49' or '*' if unknown
@param {Number|'*'} length The total length of the full entity-body or '*' if this length is unknown or difficult to determine
@constructor
@throws Error
@see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.16 | [
"Content",
"-",
"Range",
"HTTP",
"Header",
"class",
"."
]
| 0a16a5cdcc7d30ea14712054e683852c524d51de | https://github.com/clns/node-http-range/blob/0a16a5cdcc7d30ea14712054e683852c524d51de/lib/content-range.js#L13-L20 |
46,101 | wojtkowiak/meteor-desktop-localstorage | plugins/localstorage/localstorage.js | load | function load() {
Desktop.fetch('localStorage', 'getAll').then((storage) => {
Meteor._localStorage.storage = storage;
}).catch(() => {
retries += 1;
if (retries < 5) {
load();
} else {
console.error('failed to load localStorage contents');
}
});
} | javascript | function load() {
Desktop.fetch('localStorage', 'getAll').then((storage) => {
Meteor._localStorage.storage = storage;
}).catch(() => {
retries += 1;
if (retries < 5) {
load();
} else {
console.error('failed to load localStorage contents');
}
});
} | [
"function",
"load",
"(",
")",
"{",
"Desktop",
".",
"fetch",
"(",
"'localStorage'",
",",
"'getAll'",
")",
".",
"then",
"(",
"(",
"storage",
")",
"=>",
"{",
"Meteor",
".",
"_localStorage",
".",
"storage",
"=",
"storage",
";",
"}",
")",
".",
"catch",
"(",
"(",
")",
"=>",
"{",
"retries",
"+=",
"1",
";",
"if",
"(",
"retries",
"<",
"5",
")",
"{",
"load",
"(",
")",
";",
"}",
"else",
"{",
"console",
".",
"error",
"(",
"'failed to load localStorage contents'",
")",
";",
"}",
"}",
")",
";",
"}"
]
| Fetches local storage data from the meteor-desktop-localstorage plugin.
Retries 5 times, then fails. | [
"Fetches",
"local",
"storage",
"data",
"from",
"the",
"meteor",
"-",
"desktop",
"-",
"localstorage",
"plugin",
".",
"Retries",
"5",
"times",
"then",
"fails",
"."
]
| 1a4ffb47aca5ae302ebf47ec1e060b5c1a8066e1 | https://github.com/wojtkowiak/meteor-desktop-localstorage/blob/1a4ffb47aca5ae302ebf47ec1e060b5c1a8066e1/plugins/localstorage/localstorage.js#L8-L19 |
46,102 | THEjoezack/BoxPusher | public/js-roguelike-skeleton/src/lighting-rot.js | LightingROT | function LightingROT(game, settings) {
settings = settings || {};
this.game = game;
this.lightingMap = new RL.Array2d();
this.lightingMap.set = this.lightingMap.set.bind(this.lightingMap);
this.checkVisible = this.checkVisible.bind(this);
this._fov = new ROT.FOV.PreciseShadowcasting(this.checkVisible);
settings = RL.Util.mergeDefaults({
range: 5,
passes: 2,
emissionThreshold: 100,
}, settings);
this.getTileReflectivity = this.getTileReflectivity.bind(this);
this._lighting = new ROT.Lighting(this.getTileReflectivity, settings);
this._lighting.setFOV(this._fov);
// copy instance
this.ambientLight = this.ambientLight.slice();
} | javascript | function LightingROT(game, settings) {
settings = settings || {};
this.game = game;
this.lightingMap = new RL.Array2d();
this.lightingMap.set = this.lightingMap.set.bind(this.lightingMap);
this.checkVisible = this.checkVisible.bind(this);
this._fov = new ROT.FOV.PreciseShadowcasting(this.checkVisible);
settings = RL.Util.mergeDefaults({
range: 5,
passes: 2,
emissionThreshold: 100,
}, settings);
this.getTileReflectivity = this.getTileReflectivity.bind(this);
this._lighting = new ROT.Lighting(this.getTileReflectivity, settings);
this._lighting.setFOV(this._fov);
// copy instance
this.ambientLight = this.ambientLight.slice();
} | [
"function",
"LightingROT",
"(",
"game",
",",
"settings",
")",
"{",
"settings",
"=",
"settings",
"||",
"{",
"}",
";",
"this",
".",
"game",
"=",
"game",
";",
"this",
".",
"lightingMap",
"=",
"new",
"RL",
".",
"Array2d",
"(",
")",
";",
"this",
".",
"lightingMap",
".",
"set",
"=",
"this",
".",
"lightingMap",
".",
"set",
".",
"bind",
"(",
"this",
".",
"lightingMap",
")",
";",
"this",
".",
"checkVisible",
"=",
"this",
".",
"checkVisible",
".",
"bind",
"(",
"this",
")",
";",
"this",
".",
"_fov",
"=",
"new",
"ROT",
".",
"FOV",
".",
"PreciseShadowcasting",
"(",
"this",
".",
"checkVisible",
")",
";",
"settings",
"=",
"RL",
".",
"Util",
".",
"mergeDefaults",
"(",
"{",
"range",
":",
"5",
",",
"passes",
":",
"2",
",",
"emissionThreshold",
":",
"100",
",",
"}",
",",
"settings",
")",
";",
"this",
".",
"getTileReflectivity",
"=",
"this",
".",
"getTileReflectivity",
".",
"bind",
"(",
"this",
")",
";",
"this",
".",
"_lighting",
"=",
"new",
"ROT",
".",
"Lighting",
"(",
"this",
".",
"getTileReflectivity",
",",
"settings",
")",
";",
"this",
".",
"_lighting",
".",
"setFOV",
"(",
"this",
".",
"_fov",
")",
";",
"// copy instance",
"this",
".",
"ambientLight",
"=",
"this",
".",
"ambientLight",
".",
"slice",
"(",
")",
";",
"}"
]
| Represents lighting in the game map. requires ROT.js
Manages position of lights.
Calculates illumination of map tiles.
@class LightingROT
@constructor
@param {Game} game - Game instance this obj is attached to.
@param {Object} [settings] - LightingROT settings object.
@param {Number} [settings.range] - Maximum range for the most powerful light source.
@param {Number} [settings.passes] - Number of computation passes (1: no reflectivity used, 2: reflectivity used)
@param {Number} [settings.emissionThreshold] - Minimal amount of light at a cell to be re-emited (only for passes>1). | [
"Represents",
"lighting",
"in",
"the",
"game",
"map",
".",
"requires",
"ROT",
".",
"js",
"Manages",
"position",
"of",
"lights",
".",
"Calculates",
"illumination",
"of",
"map",
"tiles",
"."
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/js-roguelike-skeleton/src/lighting-rot.js#L16-L37 |
46,103 | THEjoezack/BoxPusher | public/js-roguelike-skeleton/src/lighting-rot.js | function(x, y, tileData){
var light = this.ambientLight;
var lighting = this.get(x, y);
var overlay = function(c1, c2){
var out = c1.slice();
for (var i = 0; i < 3; i++) {
var a = c1[i],
b = c2[i];
if(b < 128){
out[i] = Math.round(2 * a * b / 255);
} else {
out[i] = Math.round(255 - 2 * (255 - a) * (255 - b) / 255);
}
}
return out;
};
if(lighting){
light = ROT.Color.add(this.ambientLight, lighting);
}
if(tileData.color){
var color = ROT.Color.fromString(tileData.color);
color = overlay(light, color);
tileData.color = ROT.Color.toRGB(color);
}
if(tileData.bgColor){
var bgColor = ROT.Color.fromString(tileData.bgColor);
bgColor = overlay(light, bgColor);
tileData.bgColor = ROT.Color.toRGB(bgColor);
}
return tileData;
} | javascript | function(x, y, tileData){
var light = this.ambientLight;
var lighting = this.get(x, y);
var overlay = function(c1, c2){
var out = c1.slice();
for (var i = 0; i < 3; i++) {
var a = c1[i],
b = c2[i];
if(b < 128){
out[i] = Math.round(2 * a * b / 255);
} else {
out[i] = Math.round(255 - 2 * (255 - a) * (255 - b) / 255);
}
}
return out;
};
if(lighting){
light = ROT.Color.add(this.ambientLight, lighting);
}
if(tileData.color){
var color = ROT.Color.fromString(tileData.color);
color = overlay(light, color);
tileData.color = ROT.Color.toRGB(color);
}
if(tileData.bgColor){
var bgColor = ROT.Color.fromString(tileData.bgColor);
bgColor = overlay(light, bgColor);
tileData.bgColor = ROT.Color.toRGB(bgColor);
}
return tileData;
} | [
"function",
"(",
"x",
",",
"y",
",",
"tileData",
")",
"{",
"var",
"light",
"=",
"this",
".",
"ambientLight",
";",
"var",
"lighting",
"=",
"this",
".",
"get",
"(",
"x",
",",
"y",
")",
";",
"var",
"overlay",
"=",
"function",
"(",
"c1",
",",
"c2",
")",
"{",
"var",
"out",
"=",
"c1",
".",
"slice",
"(",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"3",
";",
"i",
"++",
")",
"{",
"var",
"a",
"=",
"c1",
"[",
"i",
"]",
",",
"b",
"=",
"c2",
"[",
"i",
"]",
";",
"if",
"(",
"b",
"<",
"128",
")",
"{",
"out",
"[",
"i",
"]",
"=",
"Math",
".",
"round",
"(",
"2",
"*",
"a",
"*",
"b",
"/",
"255",
")",
";",
"}",
"else",
"{",
"out",
"[",
"i",
"]",
"=",
"Math",
".",
"round",
"(",
"255",
"-",
"2",
"*",
"(",
"255",
"-",
"a",
")",
"*",
"(",
"255",
"-",
"b",
")",
"/",
"255",
")",
";",
"}",
"}",
"return",
"out",
";",
"}",
";",
"if",
"(",
"lighting",
")",
"{",
"light",
"=",
"ROT",
".",
"Color",
".",
"add",
"(",
"this",
".",
"ambientLight",
",",
"lighting",
")",
";",
"}",
"if",
"(",
"tileData",
".",
"color",
")",
"{",
"var",
"color",
"=",
"ROT",
".",
"Color",
".",
"fromString",
"(",
"tileData",
".",
"color",
")",
";",
"color",
"=",
"overlay",
"(",
"light",
",",
"color",
")",
";",
"tileData",
".",
"color",
"=",
"ROT",
".",
"Color",
".",
"toRGB",
"(",
"color",
")",
";",
"}",
"if",
"(",
"tileData",
".",
"bgColor",
")",
"{",
"var",
"bgColor",
"=",
"ROT",
".",
"Color",
".",
"fromString",
"(",
"tileData",
".",
"bgColor",
")",
";",
"bgColor",
"=",
"overlay",
"(",
"light",
",",
"bgColor",
")",
";",
"tileData",
".",
"bgColor",
"=",
"ROT",
".",
"Color",
".",
"toRGB",
"(",
"bgColor",
")",
";",
"}",
"return",
"tileData",
";",
"}"
]
| Shades tileData using lighting.
@method shadeTile
@param {Number} x - The x map coordinate to shade.
@param {Number} y - The y map coordinate to shade.
@param {TileData} tileData - The `TileData` object to shade.
@return {TileData} | [
"Shades",
"tileData",
"using",
"lighting",
"."
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/js-roguelike-skeleton/src/lighting-rot.js#L121-L155 |
|
46,104 | THEjoezack/BoxPusher | public/js-roguelike-skeleton/src/lighting-rot.js | function(x, y, r, g, b){
this._lighting.setLight(x, y, [r, g, b]);
this._dirty = true;
} | javascript | function(x, y, r, g, b){
this._lighting.setLight(x, y, [r, g, b]);
this._dirty = true;
} | [
"function",
"(",
"x",
",",
"y",
",",
"r",
",",
"g",
",",
"b",
")",
"{",
"this",
".",
"_lighting",
".",
"setLight",
"(",
"x",
",",
"y",
",",
"[",
"r",
",",
"g",
",",
"b",
"]",
")",
";",
"this",
".",
"_dirty",
"=",
"true",
";",
"}"
]
| Set a light position and color
@method set
@param {Number} x - The map coordinate position to set lightin on the x axis.
@param {Number} y - The map coordinate position to set lightin on the y axis.
@param {Number} r - Red.
@param {Number} g - Green.
@param {Number} b - Blue. | [
"Set",
"a",
"light",
"position",
"and",
"color"
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/js-roguelike-skeleton/src/lighting-rot.js#L176-L179 |
|
46,105 | THEjoezack/BoxPusher | public/js-roguelike-skeleton/src/lighting-rot.js | function(x, y){
var tile = this.game.map.get(x, y);
if(!tile){
return 0;
}
if(tile.lightingReflectivity){
return tile.lightingReflectivity;
}
if(tile.blocksLos){
return this.defaultWallReflectivity;
} else {
return this.defaultFloorReflectivity;
}
} | javascript | function(x, y){
var tile = this.game.map.get(x, y);
if(!tile){
return 0;
}
if(tile.lightingReflectivity){
return tile.lightingReflectivity;
}
if(tile.blocksLos){
return this.defaultWallReflectivity;
} else {
return this.defaultFloorReflectivity;
}
} | [
"function",
"(",
"x",
",",
"y",
")",
"{",
"var",
"tile",
"=",
"this",
".",
"game",
".",
"map",
".",
"get",
"(",
"x",
",",
"y",
")",
";",
"if",
"(",
"!",
"tile",
")",
"{",
"return",
"0",
";",
"}",
"if",
"(",
"tile",
".",
"lightingReflectivity",
")",
"{",
"return",
"tile",
".",
"lightingReflectivity",
";",
"}",
"if",
"(",
"tile",
".",
"blocksLos",
")",
"{",
"return",
"this",
".",
"defaultWallReflectivity",
";",
"}",
"else",
"{",
"return",
"this",
".",
"defaultFloorReflectivity",
";",
"}",
"}"
]
| Returns the reflectivity value of a tile
@method getTileReflectivity
@param {Number} x - Map tile x coord.
@param {Number} y - Map tile y coord. | [
"Returns",
"the",
"reflectivity",
"value",
"of",
"a",
"tile"
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/js-roguelike-skeleton/src/lighting-rot.js#L197-L213 |
|
46,106 | danieldkim/charlotte | lib/charlotte.js | function(next) {
if (!inNativeApp) return next(null, false, null, null, null);
if (resourceIsBinary(filePath)) {
var fullPath = shared.removeUrlMultislashes(fileFullPathRoot + '/' + filePath),
xhr;
xhr = new XMLHttpRequest();
xhr.open("GET", cacheUrl, true);
xhr.responseType = "blob";
xhr.onload = function(e) {
next(null, true, fullPath, xhr.response, null);
};
xhr.onerror = function(e) {
next(null, false)
}
xhr.send(null);
} else {
ajax(cacheUrl, null, compileData, function(err, data, compiled) {
next(null, !err, null, data, compiled);
});
}
} | javascript | function(next) {
if (!inNativeApp) return next(null, false, null, null, null);
if (resourceIsBinary(filePath)) {
var fullPath = shared.removeUrlMultislashes(fileFullPathRoot + '/' + filePath),
xhr;
xhr = new XMLHttpRequest();
xhr.open("GET", cacheUrl, true);
xhr.responseType = "blob";
xhr.onload = function(e) {
next(null, true, fullPath, xhr.response, null);
};
xhr.onerror = function(e) {
next(null, false)
}
xhr.send(null);
} else {
ajax(cacheUrl, null, compileData, function(err, data, compiled) {
next(null, !err, null, data, compiled);
});
}
} | [
"function",
"(",
"next",
")",
"{",
"if",
"(",
"!",
"inNativeApp",
")",
"return",
"next",
"(",
"null",
",",
"false",
",",
"null",
",",
"null",
",",
"null",
")",
";",
"if",
"(",
"resourceIsBinary",
"(",
"filePath",
")",
")",
"{",
"var",
"fullPath",
"=",
"shared",
".",
"removeUrlMultislashes",
"(",
"fileFullPathRoot",
"+",
"'/'",
"+",
"filePath",
")",
",",
"xhr",
";",
"xhr",
"=",
"new",
"XMLHttpRequest",
"(",
")",
";",
"xhr",
".",
"open",
"(",
"\"GET\"",
",",
"cacheUrl",
",",
"true",
")",
";",
"xhr",
".",
"responseType",
"=",
"\"blob\"",
";",
"xhr",
".",
"onload",
"=",
"function",
"(",
"e",
")",
"{",
"next",
"(",
"null",
",",
"true",
",",
"fullPath",
",",
"xhr",
".",
"response",
",",
"null",
")",
";",
"}",
";",
"xhr",
".",
"onerror",
"=",
"function",
"(",
"e",
")",
"{",
"next",
"(",
"null",
",",
"false",
")",
"}",
"xhr",
".",
"send",
"(",
"null",
")",
";",
"}",
"else",
"{",
"ajax",
"(",
"cacheUrl",
",",
"null",
",",
"compileData",
",",
"function",
"(",
"err",
",",
"data",
",",
"compiled",
")",
"{",
"next",
"(",
"null",
",",
"!",
"err",
",",
"null",
",",
"data",
",",
"compiled",
")",
";",
"}",
")",
";",
"}",
"}"
]
| try to retrieve from cache seed | [
"try",
"to",
"retrieve",
"from",
"cache",
"seed"
]
| b4f0afddd6660194b09026513aeeb1c851913044 | https://github.com/danieldkim/charlotte/blob/b4f0afddd6660194b09026513aeeb1c851913044/lib/charlotte.js#L543-L563 |
|
46,107 | danieldkim/charlotte | lib/charlotte.js | function(foundInCacheSeed, fullPath, data, compiled, next) {
if (foundInCacheSeed) {
debugLog("Found resource in cache seed: " + cacheUrl)
if (data) {
async.waterfall([
function(next) {
if (url.match(/\.css$/)) {
processStylesheet(rootUrl, version, url, data, timeout,
onCacheMiss, next);
} else {
next(null, data);
}
},
], function(err, data) {
if (err) return next(err);
writeToFile(filePath, data, function(err, fullPath) {
next(err, fullPath, data, compiled, null);
});
});
} else {
next(null, fullPath, data, compiled, null);
}
} else {
getServerResource(next);
}
} | javascript | function(foundInCacheSeed, fullPath, data, compiled, next) {
if (foundInCacheSeed) {
debugLog("Found resource in cache seed: " + cacheUrl)
if (data) {
async.waterfall([
function(next) {
if (url.match(/\.css$/)) {
processStylesheet(rootUrl, version, url, data, timeout,
onCacheMiss, next);
} else {
next(null, data);
}
},
], function(err, data) {
if (err) return next(err);
writeToFile(filePath, data, function(err, fullPath) {
next(err, fullPath, data, compiled, null);
});
});
} else {
next(null, fullPath, data, compiled, null);
}
} else {
getServerResource(next);
}
} | [
"function",
"(",
"foundInCacheSeed",
",",
"fullPath",
",",
"data",
",",
"compiled",
",",
"next",
")",
"{",
"if",
"(",
"foundInCacheSeed",
")",
"{",
"debugLog",
"(",
"\"Found resource in cache seed: \"",
"+",
"cacheUrl",
")",
"if",
"(",
"data",
")",
"{",
"async",
".",
"waterfall",
"(",
"[",
"function",
"(",
"next",
")",
"{",
"if",
"(",
"url",
".",
"match",
"(",
"/",
"\\.css$",
"/",
")",
")",
"{",
"processStylesheet",
"(",
"rootUrl",
",",
"version",
",",
"url",
",",
"data",
",",
"timeout",
",",
"onCacheMiss",
",",
"next",
")",
";",
"}",
"else",
"{",
"next",
"(",
"null",
",",
"data",
")",
";",
"}",
"}",
",",
"]",
",",
"function",
"(",
"err",
",",
"data",
")",
"{",
"if",
"(",
"err",
")",
"return",
"next",
"(",
"err",
")",
";",
"writeToFile",
"(",
"filePath",
",",
"data",
",",
"function",
"(",
"err",
",",
"fullPath",
")",
"{",
"next",
"(",
"err",
",",
"fullPath",
",",
"data",
",",
"compiled",
",",
"null",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"next",
"(",
"null",
",",
"fullPath",
",",
"data",
",",
"compiled",
",",
"null",
")",
";",
"}",
"}",
"else",
"{",
"getServerResource",
"(",
"next",
")",
";",
"}",
"}"
]
| get from server or write to cache if necessary | [
"get",
"from",
"server",
"or",
"write",
"to",
"cache",
"if",
"necessary"
]
| b4f0afddd6660194b09026513aeeb1c851913044 | https://github.com/danieldkim/charlotte/blob/b4f0afddd6660194b09026513aeeb1c851913044/lib/charlotte.js#L566-L591 |
|
46,108 | flowgrammable/uint-js | uint.js | UInt | function UInt(args) {
// Assign default valus
this._value = null;
this._bytes = null;
this._bits = null;
this._isHex = false;
// Set constraints if present
if(args && (isNatural(args.bits) || isNatural(args.bytes))) {
// Set the size if either is used
this._bits = args.bits || 0;
this._bytes = args.bytes || 0;
// Normalize the byte/bit counts
this._bytes += Math.floor(this._bits / 8);
this._bits = this._bits % 8;
}
// Set the value and check if present
if(args && (_(args.value).isNumber() || _(args.value).isString() ||
_(args.value).isArray())) {
var result = normalize(args.value);
this._value = result.value;
// Set the sizes or validate if present
if(_(this._bytes).isNull() && _(this._bits).isNull()) {
this._bytes = result.bytes;
this._bits = result.bits;
} else if(this._bytes < result.bytes ||
(this._bytes === result.bytes && this._bits < result.bits)) {
throw 'Value is larger than size constraints: ' + args.value + ' ' +
this._bytes + ':' + this._bits;
}
// Insert any necessary leading zeros
if(_(this._value).isArray()) {
_(this._bytes - this._value.length).times(function() {
this._value.splice(0, 0, 0);
}, this);
// Handle the case of user supplied array boundary but small value
} else if(this._bytes > 4) {
var tmp = [];
_(this._bytes).times(function(i) {
if(i < 4) {
tmp.splice(0, 0, this._value % 256);
this._value = Math.floor(this._value / 256);
} else {
tmp.splice(0, 0, 0);
}
}, this);
this._value = tmp;
}
}
//Set isHex if string starts with 0x
if(args && _(args.value).isString()){
var arr = args.value.match(/^0x/i);
if(arr !== null){
this._isHex = true;
}
else{
this._isHex = false;
}
}
} | javascript | function UInt(args) {
// Assign default valus
this._value = null;
this._bytes = null;
this._bits = null;
this._isHex = false;
// Set constraints if present
if(args && (isNatural(args.bits) || isNatural(args.bytes))) {
// Set the size if either is used
this._bits = args.bits || 0;
this._bytes = args.bytes || 0;
// Normalize the byte/bit counts
this._bytes += Math.floor(this._bits / 8);
this._bits = this._bits % 8;
}
// Set the value and check if present
if(args && (_(args.value).isNumber() || _(args.value).isString() ||
_(args.value).isArray())) {
var result = normalize(args.value);
this._value = result.value;
// Set the sizes or validate if present
if(_(this._bytes).isNull() && _(this._bits).isNull()) {
this._bytes = result.bytes;
this._bits = result.bits;
} else if(this._bytes < result.bytes ||
(this._bytes === result.bytes && this._bits < result.bits)) {
throw 'Value is larger than size constraints: ' + args.value + ' ' +
this._bytes + ':' + this._bits;
}
// Insert any necessary leading zeros
if(_(this._value).isArray()) {
_(this._bytes - this._value.length).times(function() {
this._value.splice(0, 0, 0);
}, this);
// Handle the case of user supplied array boundary but small value
} else if(this._bytes > 4) {
var tmp = [];
_(this._bytes).times(function(i) {
if(i < 4) {
tmp.splice(0, 0, this._value % 256);
this._value = Math.floor(this._value / 256);
} else {
tmp.splice(0, 0, 0);
}
}, this);
this._value = tmp;
}
}
//Set isHex if string starts with 0x
if(args && _(args.value).isString()){
var arr = args.value.match(/^0x/i);
if(arr !== null){
this._isHex = true;
}
else{
this._isHex = false;
}
}
} | [
"function",
"UInt",
"(",
"args",
")",
"{",
"// Assign default valus\r",
"this",
".",
"_value",
"=",
"null",
";",
"this",
".",
"_bytes",
"=",
"null",
";",
"this",
".",
"_bits",
"=",
"null",
";",
"this",
".",
"_isHex",
"=",
"false",
";",
"// Set constraints if present\r",
"if",
"(",
"args",
"&&",
"(",
"isNatural",
"(",
"args",
".",
"bits",
")",
"||",
"isNatural",
"(",
"args",
".",
"bytes",
")",
")",
")",
"{",
"// Set the size if either is used\r",
"this",
".",
"_bits",
"=",
"args",
".",
"bits",
"||",
"0",
";",
"this",
".",
"_bytes",
"=",
"args",
".",
"bytes",
"||",
"0",
";",
"// Normalize the byte/bit counts\r",
"this",
".",
"_bytes",
"+=",
"Math",
".",
"floor",
"(",
"this",
".",
"_bits",
"/",
"8",
")",
";",
"this",
".",
"_bits",
"=",
"this",
".",
"_bits",
"%",
"8",
";",
"}",
"// Set the value and check if present\r",
"if",
"(",
"args",
"&&",
"(",
"_",
"(",
"args",
".",
"value",
")",
".",
"isNumber",
"(",
")",
"||",
"_",
"(",
"args",
".",
"value",
")",
".",
"isString",
"(",
")",
"||",
"_",
"(",
"args",
".",
"value",
")",
".",
"isArray",
"(",
")",
")",
")",
"{",
"var",
"result",
"=",
"normalize",
"(",
"args",
".",
"value",
")",
";",
"this",
".",
"_value",
"=",
"result",
".",
"value",
";",
"// Set the sizes or validate if present\r",
"if",
"(",
"_",
"(",
"this",
".",
"_bytes",
")",
".",
"isNull",
"(",
")",
"&&",
"_",
"(",
"this",
".",
"_bits",
")",
".",
"isNull",
"(",
")",
")",
"{",
"this",
".",
"_bytes",
"=",
"result",
".",
"bytes",
";",
"this",
".",
"_bits",
"=",
"result",
".",
"bits",
";",
"}",
"else",
"if",
"(",
"this",
".",
"_bytes",
"<",
"result",
".",
"bytes",
"||",
"(",
"this",
".",
"_bytes",
"===",
"result",
".",
"bytes",
"&&",
"this",
".",
"_bits",
"<",
"result",
".",
"bits",
")",
")",
"{",
"throw",
"'Value is larger than size constraints: '",
"+",
"args",
".",
"value",
"+",
"' '",
"+",
"this",
".",
"_bytes",
"+",
"':'",
"+",
"this",
".",
"_bits",
";",
"}",
"// Insert any necessary leading zeros\r",
"if",
"(",
"_",
"(",
"this",
".",
"_value",
")",
".",
"isArray",
"(",
")",
")",
"{",
"_",
"(",
"this",
".",
"_bytes",
"-",
"this",
".",
"_value",
".",
"length",
")",
".",
"times",
"(",
"function",
"(",
")",
"{",
"this",
".",
"_value",
".",
"splice",
"(",
"0",
",",
"0",
",",
"0",
")",
";",
"}",
",",
"this",
")",
";",
"// Handle the case of user supplied array boundary but small value\r",
"}",
"else",
"if",
"(",
"this",
".",
"_bytes",
">",
"4",
")",
"{",
"var",
"tmp",
"=",
"[",
"]",
";",
"_",
"(",
"this",
".",
"_bytes",
")",
".",
"times",
"(",
"function",
"(",
"i",
")",
"{",
"if",
"(",
"i",
"<",
"4",
")",
"{",
"tmp",
".",
"splice",
"(",
"0",
",",
"0",
",",
"this",
".",
"_value",
"%",
"256",
")",
";",
"this",
".",
"_value",
"=",
"Math",
".",
"floor",
"(",
"this",
".",
"_value",
"/",
"256",
")",
";",
"}",
"else",
"{",
"tmp",
".",
"splice",
"(",
"0",
",",
"0",
",",
"0",
")",
";",
"}",
"}",
",",
"this",
")",
";",
"this",
".",
"_value",
"=",
"tmp",
";",
"}",
"}",
"//Set isHex if string starts with 0x\r",
"if",
"(",
"args",
"&&",
"_",
"(",
"args",
".",
"value",
")",
".",
"isString",
"(",
")",
")",
"{",
"var",
"arr",
"=",
"args",
".",
"value",
".",
"match",
"(",
"/",
"^0x",
"/",
"i",
")",
";",
"if",
"(",
"arr",
"!==",
"null",
")",
"{",
"this",
".",
"_isHex",
"=",
"true",
";",
"}",
"else",
"{",
"this",
".",
"_isHex",
"=",
"false",
";",
"}",
"}",
"}"
]
| FIXME old version memoizes 'HEX' if used to set | [
"FIXME",
"old",
"version",
"memoizes",
"HEX",
"if",
"used",
"to",
"set"
]
| f9e13967708f47cdd0c3389c2d3c8bc04a98d5dc | https://github.com/flowgrammable/uint-js/blob/f9e13967708f47cdd0c3389c2d3c8bc04a98d5dc/uint.js#L183-L243 |
46,109 | kmalakoff/backbone-modelref | vendor/optional/lodash-0.3.2.js | reduceRight | function reduceRight(collection, callback, accumulator, thisArg) {
if (!collection) {
return accumulator;
}
var length = collection.length,
noaccum = arguments.length < 3;
if(thisArg) {
callback = iteratorBind(callback, thisArg);
}
if (length === length >>> 0) {
if (length && noaccum) {
accumulator = collection[--length];
}
while (length--) {
accumulator = callback(accumulator, collection[length], length, collection);
}
return accumulator;
}
var prop,
props = keys(collection);
length = props.length;
if (length && noaccum) {
accumulator = collection[props[--length]];
}
while (length--) {
prop = props[length];
accumulator = callback(accumulator, collection[prop], prop, collection);
}
return accumulator;
} | javascript | function reduceRight(collection, callback, accumulator, thisArg) {
if (!collection) {
return accumulator;
}
var length = collection.length,
noaccum = arguments.length < 3;
if(thisArg) {
callback = iteratorBind(callback, thisArg);
}
if (length === length >>> 0) {
if (length && noaccum) {
accumulator = collection[--length];
}
while (length--) {
accumulator = callback(accumulator, collection[length], length, collection);
}
return accumulator;
}
var prop,
props = keys(collection);
length = props.length;
if (length && noaccum) {
accumulator = collection[props[--length]];
}
while (length--) {
prop = props[length];
accumulator = callback(accumulator, collection[prop], prop, collection);
}
return accumulator;
} | [
"function",
"reduceRight",
"(",
"collection",
",",
"callback",
",",
"accumulator",
",",
"thisArg",
")",
"{",
"if",
"(",
"!",
"collection",
")",
"{",
"return",
"accumulator",
";",
"}",
"var",
"length",
"=",
"collection",
".",
"length",
",",
"noaccum",
"=",
"arguments",
".",
"length",
"<",
"3",
";",
"if",
"(",
"thisArg",
")",
"{",
"callback",
"=",
"iteratorBind",
"(",
"callback",
",",
"thisArg",
")",
";",
"}",
"if",
"(",
"length",
"===",
"length",
">>>",
"0",
")",
"{",
"if",
"(",
"length",
"&&",
"noaccum",
")",
"{",
"accumulator",
"=",
"collection",
"[",
"--",
"length",
"]",
";",
"}",
"while",
"(",
"length",
"--",
")",
"{",
"accumulator",
"=",
"callback",
"(",
"accumulator",
",",
"collection",
"[",
"length",
"]",
",",
"length",
",",
"collection",
")",
";",
"}",
"return",
"accumulator",
";",
"}",
"var",
"prop",
",",
"props",
"=",
"keys",
"(",
"collection",
")",
";",
"length",
"=",
"props",
".",
"length",
";",
"if",
"(",
"length",
"&&",
"noaccum",
")",
"{",
"accumulator",
"=",
"collection",
"[",
"props",
"[",
"--",
"length",
"]",
"]",
";",
"}",
"while",
"(",
"length",
"--",
")",
"{",
"prop",
"=",
"props",
"[",
"length",
"]",
";",
"accumulator",
"=",
"callback",
"(",
"accumulator",
",",
"collection",
"[",
"prop",
"]",
",",
"prop",
",",
"collection",
")",
";",
"}",
"return",
"accumulator",
";",
"}"
]
| The right-associative version of `_.reduce`.
@static
@memberOf _
@alias foldr
@category Collections
@param {Array|Object} collection The collection to iterate over.
@param {Function} callback The function called per iteration.
@param {Mixed} [accumulator] Initial value of the accumulator.
@param {Mixed} [thisArg] The `this` binding for the callback.
@returns {Mixed} Returns the accumulated value.
@example
var list = [[0, 1], [2, 3], [4, 5]];
var flat = _.reduceRight(list, function(a, b) { return a.concat(b); }, []);
// => [4, 5, 2, 3, 0, 1] | [
"The",
"right",
"-",
"associative",
"version",
"of",
"_",
".",
"reduce",
"."
]
| efdd402c676554991ff1d4cdc10818fca8f87187 | https://github.com/kmalakoff/backbone-modelref/blob/efdd402c676554991ff1d4cdc10818fca8f87187/vendor/optional/lodash-0.3.2.js#L839-L872 |
46,110 | kmalakoff/backbone-modelref | vendor/optional/lodash-0.3.2.js | toArray | function toArray(collection) {
if (!collection) {
return [];
}
if (toString.call(collection.toArray) == funcClass) {
return collection.toArray();
}
var length = collection.length;
if (length === length >>> 0) {
return slice.call(collection);
}
return values(collection);
} | javascript | function toArray(collection) {
if (!collection) {
return [];
}
if (toString.call(collection.toArray) == funcClass) {
return collection.toArray();
}
var length = collection.length;
if (length === length >>> 0) {
return slice.call(collection);
}
return values(collection);
} | [
"function",
"toArray",
"(",
"collection",
")",
"{",
"if",
"(",
"!",
"collection",
")",
"{",
"return",
"[",
"]",
";",
"}",
"if",
"(",
"toString",
".",
"call",
"(",
"collection",
".",
"toArray",
")",
"==",
"funcClass",
")",
"{",
"return",
"collection",
".",
"toArray",
"(",
")",
";",
"}",
"var",
"length",
"=",
"collection",
".",
"length",
";",
"if",
"(",
"length",
"===",
"length",
">>>",
"0",
")",
"{",
"return",
"slice",
".",
"call",
"(",
"collection",
")",
";",
"}",
"return",
"values",
"(",
"collection",
")",
";",
"}"
]
| Converts the `collection`, into an array. Useful for converting the
`arguments` object.
@static
@memberOf _
@category Collections
@param {Array|Object} collection The collection to convert.
@returns {Array} Returns the new converted array.
@example
(function() { return _.toArray(arguments).slice(1); })(1, 2, 3, 4);
// => [2, 3, 4] | [
"Converts",
"the",
"collection",
"into",
"an",
"array",
".",
"Useful",
"for",
"converting",
"the",
"arguments",
"object",
"."
]
| efdd402c676554991ff1d4cdc10818fca8f87187 | https://github.com/kmalakoff/backbone-modelref/blob/efdd402c676554991ff1d4cdc10818fca8f87187/vendor/optional/lodash-0.3.2.js#L933-L945 |
46,111 | kmalakoff/backbone-modelref | vendor/optional/lodash-0.3.2.js | initial | function initial(array, n, guard) {
if (!array) {
return [];
}
return slice.call(array, 0, -((n == undefined || guard) ? 1 : n));
} | javascript | function initial(array, n, guard) {
if (!array) {
return [];
}
return slice.call(array, 0, -((n == undefined || guard) ? 1 : n));
} | [
"function",
"initial",
"(",
"array",
",",
"n",
",",
"guard",
")",
"{",
"if",
"(",
"!",
"array",
")",
"{",
"return",
"[",
"]",
";",
"}",
"return",
"slice",
".",
"call",
"(",
"array",
",",
"0",
",",
"-",
"(",
"(",
"n",
"==",
"undefined",
"||",
"guard",
")",
"?",
"1",
":",
"n",
")",
")",
";",
"}"
]
| Gets all but the last value of `array`. Pass `n` to exclude the last `n`
values from the result.
@static
@memberOf _
@category Arrays
@param {Array} array The array to query.
@param {Number} [n] The number of elements to return.
@param {Object} [guard] Internally used to allow this method to work with
others like `_.map` without using their callback `index` argument for `n`.
@returns {Array} Returns all but the last value or `n` values of `array`.
@example
_.initial([3, 2, 1]);
// => [3, 2] | [
"Gets",
"all",
"but",
"the",
"last",
"value",
"of",
"array",
".",
"Pass",
"n",
"to",
"exclude",
"the",
"last",
"n",
"values",
"from",
"the",
"result",
"."
]
| efdd402c676554991ff1d4cdc10818fca8f87187 | https://github.com/kmalakoff/backbone-modelref/blob/efdd402c676554991ff1d4cdc10818fca8f87187/vendor/optional/lodash-0.3.2.js#L1186-L1191 |
46,112 | kmalakoff/backbone-modelref | vendor/optional/lodash-0.3.2.js | intersection | function intersection(array) {
var result = [];
if (!array) {
return result;
}
var value,
index = -1,
length = array.length,
others = slice.call(arguments, 1);
while (++index < length) {
value = array[index];
if (indexOf(result, value) < 0 &&
every(others, function(other) { return indexOf(other, value) > -1; })) {
result.push(value);
}
}
return result;
} | javascript | function intersection(array) {
var result = [];
if (!array) {
return result;
}
var value,
index = -1,
length = array.length,
others = slice.call(arguments, 1);
while (++index < length) {
value = array[index];
if (indexOf(result, value) < 0 &&
every(others, function(other) { return indexOf(other, value) > -1; })) {
result.push(value);
}
}
return result;
} | [
"function",
"intersection",
"(",
"array",
")",
"{",
"var",
"result",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"array",
")",
"{",
"return",
"result",
";",
"}",
"var",
"value",
",",
"index",
"=",
"-",
"1",
",",
"length",
"=",
"array",
".",
"length",
",",
"others",
"=",
"slice",
".",
"call",
"(",
"arguments",
",",
"1",
")",
";",
"while",
"(",
"++",
"index",
"<",
"length",
")",
"{",
"value",
"=",
"array",
"[",
"index",
"]",
";",
"if",
"(",
"indexOf",
"(",
"result",
",",
"value",
")",
"<",
"0",
"&&",
"every",
"(",
"others",
",",
"function",
"(",
"other",
")",
"{",
"return",
"indexOf",
"(",
"other",
",",
"value",
")",
">",
"-",
"1",
";",
"}",
")",
")",
"{",
"result",
".",
"push",
"(",
"value",
")",
";",
"}",
"}",
"return",
"result",
";",
"}"
]
| Computes the intersection of all the passed-in arrays.
@static
@memberOf _
@category Arrays
@param {Array} [array1, array2, ...] Arrays to process.
@returns {Array} Returns a new array of unique values, in order, that are
present in **all** of the arrays.
@example
_.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]);
// => [1, 2] | [
"Computes",
"the",
"intersection",
"of",
"all",
"the",
"passed",
"-",
"in",
"arrays",
"."
]
| efdd402c676554991ff1d4cdc10818fca8f87187 | https://github.com/kmalakoff/backbone-modelref/blob/efdd402c676554991ff1d4cdc10818fca8f87187/vendor/optional/lodash-0.3.2.js#L1207-L1225 |
46,113 | kmalakoff/backbone-modelref | vendor/optional/lodash-0.3.2.js | last | function last(array, n, guard) {
if (array) {
var length = array.length;
return (n == undefined || guard) ? array[length - 1] : slice.call(array, -n || length);
}
} | javascript | function last(array, n, guard) {
if (array) {
var length = array.length;
return (n == undefined || guard) ? array[length - 1] : slice.call(array, -n || length);
}
} | [
"function",
"last",
"(",
"array",
",",
"n",
",",
"guard",
")",
"{",
"if",
"(",
"array",
")",
"{",
"var",
"length",
"=",
"array",
".",
"length",
";",
"return",
"(",
"n",
"==",
"undefined",
"||",
"guard",
")",
"?",
"array",
"[",
"length",
"-",
"1",
"]",
":",
"slice",
".",
"call",
"(",
"array",
",",
"-",
"n",
"||",
"length",
")",
";",
"}",
"}"
]
| Gets the last value of the `array`. Pass `n` to return the lasy `n` values
of the `array`.
@static
@memberOf _
@category Arrays
@param {Array} array The array to query.
@param {Number} [n] The number of elements to return.
@param {Object} [guard] Internally used to allow this method to work with
others like `_.map` without using their callback `index` argument for `n`.
@returns {Mixed} Returns the last value or an array of the last `n` values
of `array`.
@example
_.last([3, 2, 1]);
// => 1 | [
"Gets",
"the",
"last",
"value",
"of",
"the",
"array",
".",
"Pass",
"n",
"to",
"return",
"the",
"lasy",
"n",
"values",
"of",
"the",
"array",
"."
]
| efdd402c676554991ff1d4cdc10818fca8f87187 | https://github.com/kmalakoff/backbone-modelref/blob/efdd402c676554991ff1d4cdc10818fca8f87187/vendor/optional/lodash-0.3.2.js#L1245-L1250 |
46,114 | kmalakoff/backbone-modelref | vendor/optional/lodash-0.3.2.js | union | function union() {
var index = -1,
result = [],
flattened = concat.apply(result, arguments),
length = flattened.length;
while (++index < length) {
if (indexOf(result, flattened[index]) < 0) {
result.push(flattened[index]);
}
}
return result;
} | javascript | function union() {
var index = -1,
result = [],
flattened = concat.apply(result, arguments),
length = flattened.length;
while (++index < length) {
if (indexOf(result, flattened[index]) < 0) {
result.push(flattened[index]);
}
}
return result;
} | [
"function",
"union",
"(",
")",
"{",
"var",
"index",
"=",
"-",
"1",
",",
"result",
"=",
"[",
"]",
",",
"flattened",
"=",
"concat",
".",
"apply",
"(",
"result",
",",
"arguments",
")",
",",
"length",
"=",
"flattened",
".",
"length",
";",
"while",
"(",
"++",
"index",
"<",
"length",
")",
"{",
"if",
"(",
"indexOf",
"(",
"result",
",",
"flattened",
"[",
"index",
"]",
")",
"<",
"0",
")",
"{",
"result",
".",
"push",
"(",
"flattened",
"[",
"index",
"]",
")",
";",
"}",
"}",
"return",
"result",
";",
"}"
]
| Computes the union of the passed-in arrays.
@static
@memberOf _
@category Arrays
@param {Array} [array1, array2, ...] Arrays to process.
@returns {Array} Returns a new array of unique values, in order, that are
present in one or more of the arrays.
@example
_.union([1, 2, 3], [101, 2, 1, 10], [2, 1]);
// => [1, 2, 3, 101, 10] | [
"Computes",
"the",
"union",
"of",
"the",
"passed",
"-",
"in",
"arrays",
"."
]
| efdd402c676554991ff1d4cdc10818fca8f87187 | https://github.com/kmalakoff/backbone-modelref/blob/efdd402c676554991ff1d4cdc10818fca8f87187/vendor/optional/lodash-0.3.2.js#L1635-L1647 |
46,115 | kmalakoff/backbone-modelref | vendor/optional/lodash-0.3.2.js | bind | function bind(func, thisArg) {
var methodName,
isFunc = toString.call(func) == funcClass;
// juggle arguments
if (!isFunc) {
methodName = thisArg;
thisArg = func;
}
// use if `Function#bind` is faster
else if (nativeBind) {
return nativeBind.call.apply(nativeBind, arguments);
}
var partialArgs = slice.call(arguments, 2);
function bound() {
// `Function#bind` spec
// http://es5.github.com/#x15.3.4.5
var args = arguments,
thisBinding = thisArg;
if (!isFunc) {
func = thisArg[methodName];
}
if (partialArgs.length) {
args = args.length
? concat.apply(partialArgs, args)
: partialArgs;
}
if (this instanceof bound) {
// get `func` instance if `bound` is invoked in a `new` expression
noop.prototype = func.prototype;
thisBinding = new noop;
// mimic the constructor's `return` behavior
// http://es5.github.com/#x13.2.2
var result = func.apply(thisBinding, args);
return valueTypes[typeof result] && result !== null
? result
: thisBinding
}
return func.apply(thisBinding, args);
}
return bound;
} | javascript | function bind(func, thisArg) {
var methodName,
isFunc = toString.call(func) == funcClass;
// juggle arguments
if (!isFunc) {
methodName = thisArg;
thisArg = func;
}
// use if `Function#bind` is faster
else if (nativeBind) {
return nativeBind.call.apply(nativeBind, arguments);
}
var partialArgs = slice.call(arguments, 2);
function bound() {
// `Function#bind` spec
// http://es5.github.com/#x15.3.4.5
var args = arguments,
thisBinding = thisArg;
if (!isFunc) {
func = thisArg[methodName];
}
if (partialArgs.length) {
args = args.length
? concat.apply(partialArgs, args)
: partialArgs;
}
if (this instanceof bound) {
// get `func` instance if `bound` is invoked in a `new` expression
noop.prototype = func.prototype;
thisBinding = new noop;
// mimic the constructor's `return` behavior
// http://es5.github.com/#x13.2.2
var result = func.apply(thisBinding, args);
return valueTypes[typeof result] && result !== null
? result
: thisBinding
}
return func.apply(thisBinding, args);
}
return bound;
} | [
"function",
"bind",
"(",
"func",
",",
"thisArg",
")",
"{",
"var",
"methodName",
",",
"isFunc",
"=",
"toString",
".",
"call",
"(",
"func",
")",
"==",
"funcClass",
";",
"// juggle arguments",
"if",
"(",
"!",
"isFunc",
")",
"{",
"methodName",
"=",
"thisArg",
";",
"thisArg",
"=",
"func",
";",
"}",
"// use if `Function#bind` is faster",
"else",
"if",
"(",
"nativeBind",
")",
"{",
"return",
"nativeBind",
".",
"call",
".",
"apply",
"(",
"nativeBind",
",",
"arguments",
")",
";",
"}",
"var",
"partialArgs",
"=",
"slice",
".",
"call",
"(",
"arguments",
",",
"2",
")",
";",
"function",
"bound",
"(",
")",
"{",
"// `Function#bind` spec",
"// http://es5.github.com/#x15.3.4.5",
"var",
"args",
"=",
"arguments",
",",
"thisBinding",
"=",
"thisArg",
";",
"if",
"(",
"!",
"isFunc",
")",
"{",
"func",
"=",
"thisArg",
"[",
"methodName",
"]",
";",
"}",
"if",
"(",
"partialArgs",
".",
"length",
")",
"{",
"args",
"=",
"args",
".",
"length",
"?",
"concat",
".",
"apply",
"(",
"partialArgs",
",",
"args",
")",
":",
"partialArgs",
";",
"}",
"if",
"(",
"this",
"instanceof",
"bound",
")",
"{",
"// get `func` instance if `bound` is invoked in a `new` expression",
"noop",
".",
"prototype",
"=",
"func",
".",
"prototype",
";",
"thisBinding",
"=",
"new",
"noop",
";",
"// mimic the constructor's `return` behavior",
"// http://es5.github.com/#x13.2.2",
"var",
"result",
"=",
"func",
".",
"apply",
"(",
"thisBinding",
",",
"args",
")",
";",
"return",
"valueTypes",
"[",
"typeof",
"result",
"]",
"&&",
"result",
"!==",
"null",
"?",
"result",
":",
"thisBinding",
"}",
"return",
"func",
".",
"apply",
"(",
"thisBinding",
",",
"args",
")",
";",
"}",
"return",
"bound",
";",
"}"
]
| Creates a new function that, when called, invokes `func` with the `this`
binding of `thisArg` and prepends any additional `bind` arguments to those
passed to the bound function. Lazy defined methods may be bound by passing
the object they are bound to as `func` and the method name as `thisArg`.
@static
@memberOf _
@category Functions
@param {Function|Object} func The function to bind or the object the method belongs to.
@param {Mixed} [thisArg] The `this` binding of `func` or the method name.
@param {Mixed} [arg1, arg2, ...] Arguments to be partially applied.
@returns {Function} Returns the new bound function.
@example
// basic bind
var func = function(greeting) {
return greeting + ': ' + this.name;
};
func = _.bind(func, { 'name': 'moe' }, 'hi');
func();
// => 'hi: moe'
// lazy bind
var object = {
'name': 'moe',
'greet': function(greeting) {
return greeting + ': ' + this.name;
}
};
var func = _.bind(object, 'greet', 'hi');
func();
// => 'hi: moe'
object.greet = function(greeting) {
return greeting + ', ' + this.name + '!';
};
func();
// => 'hi, moe!' | [
"Creates",
"a",
"new",
"function",
"that",
"when",
"called",
"invokes",
"func",
"with",
"the",
"this",
"binding",
"of",
"thisArg",
"and",
"prepends",
"any",
"additional",
"bind",
"arguments",
"to",
"those",
"passed",
"to",
"the",
"bound",
"function",
".",
"Lazy",
"defined",
"methods",
"may",
"be",
"bound",
"by",
"passing",
"the",
"object",
"they",
"are",
"bound",
"to",
"as",
"func",
"and",
"the",
"method",
"name",
"as",
"thisArg",
"."
]
| efdd402c676554991ff1d4cdc10818fca8f87187 | https://github.com/kmalakoff/backbone-modelref/blob/efdd402c676554991ff1d4cdc10818fca8f87187/vendor/optional/lodash-0.3.2.js#L1851-L1897 |
46,116 | kmalakoff/backbone-modelref | vendor/optional/lodash-0.3.2.js | bindAll | function bindAll(object) {
var funcs = arguments,
index = 1;
if (funcs.length == 1) {
index = 0;
funcs = functions(object);
}
for (var length = funcs.length; index < length; index++) {
object[funcs[index]] = bind(object[funcs[index]], object);
}
return object;
} | javascript | function bindAll(object) {
var funcs = arguments,
index = 1;
if (funcs.length == 1) {
index = 0;
funcs = functions(object);
}
for (var length = funcs.length; index < length; index++) {
object[funcs[index]] = bind(object[funcs[index]], object);
}
return object;
} | [
"function",
"bindAll",
"(",
"object",
")",
"{",
"var",
"funcs",
"=",
"arguments",
",",
"index",
"=",
"1",
";",
"if",
"(",
"funcs",
".",
"length",
"==",
"1",
")",
"{",
"index",
"=",
"0",
";",
"funcs",
"=",
"functions",
"(",
"object",
")",
";",
"}",
"for",
"(",
"var",
"length",
"=",
"funcs",
".",
"length",
";",
"index",
"<",
"length",
";",
"index",
"++",
")",
"{",
"object",
"[",
"funcs",
"[",
"index",
"]",
"]",
"=",
"bind",
"(",
"object",
"[",
"funcs",
"[",
"index",
"]",
"]",
",",
"object",
")",
";",
"}",
"return",
"object",
";",
"}"
]
| Binds methods on `object` to `object`, overwriting the existing method.
If no method names are provided, all the function properties of `object`
will be bound.
@static
@memberOf _
@category Functions
@param {Object} object The object to bind and assign the bound methods to.
@param {String} [methodName1, methodName2, ...] Method names on the object to bind.
@returns {Object} Returns the `object`.
@example
var buttonView = {
'label': 'lodash',
'onClick': function() { alert('clicked: ' + this.label); },
'onHover': function() { console.log('hovering: ' + this.label); }
};
_.bindAll(buttonView);
jQuery('#lodash_button').on('click', buttonView.onClick);
// => When the button is clicked, `this.label` will have the correct value | [
"Binds",
"methods",
"on",
"object",
"to",
"object",
"overwriting",
"the",
"existing",
"method",
".",
"If",
"no",
"method",
"names",
"are",
"provided",
"all",
"the",
"function",
"properties",
"of",
"object",
"will",
"be",
"bound",
"."
]
| efdd402c676554991ff1d4cdc10818fca8f87187 | https://github.com/kmalakoff/backbone-modelref/blob/efdd402c676554991ff1d4cdc10818fca8f87187/vendor/optional/lodash-0.3.2.js#L1922-L1934 |
46,117 | kmalakoff/backbone-modelref | vendor/optional/lodash-0.3.2.js | debounce | function debounce(func, wait, immediate) {
var args,
result,
thisArg,
timeoutId;
function delayed() {
timeoutId = undefined;
if (!immediate) {
func.apply(thisArg, args);
}
}
return function() {
var isImmediate = immediate && !timeoutId;
args = arguments;
thisArg = this;
clearTimeout(timeoutId);
timeoutId = setTimeout(delayed, wait);
if (isImmediate) {
result = func.apply(thisArg, args);
}
return result;
};
} | javascript | function debounce(func, wait, immediate) {
var args,
result,
thisArg,
timeoutId;
function delayed() {
timeoutId = undefined;
if (!immediate) {
func.apply(thisArg, args);
}
}
return function() {
var isImmediate = immediate && !timeoutId;
args = arguments;
thisArg = this;
clearTimeout(timeoutId);
timeoutId = setTimeout(delayed, wait);
if (isImmediate) {
result = func.apply(thisArg, args);
}
return result;
};
} | [
"function",
"debounce",
"(",
"func",
",",
"wait",
",",
"immediate",
")",
"{",
"var",
"args",
",",
"result",
",",
"thisArg",
",",
"timeoutId",
";",
"function",
"delayed",
"(",
")",
"{",
"timeoutId",
"=",
"undefined",
";",
"if",
"(",
"!",
"immediate",
")",
"{",
"func",
".",
"apply",
"(",
"thisArg",
",",
"args",
")",
";",
"}",
"}",
"return",
"function",
"(",
")",
"{",
"var",
"isImmediate",
"=",
"immediate",
"&&",
"!",
"timeoutId",
";",
"args",
"=",
"arguments",
";",
"thisArg",
"=",
"this",
";",
"clearTimeout",
"(",
"timeoutId",
")",
";",
"timeoutId",
"=",
"setTimeout",
"(",
"delayed",
",",
"wait",
")",
";",
"if",
"(",
"isImmediate",
")",
"{",
"result",
"=",
"func",
".",
"apply",
"(",
"thisArg",
",",
"args",
")",
";",
"}",
"return",
"result",
";",
"}",
";",
"}"
]
| Creates a new function that will delay the execution of `func` until after
`wait` milliseconds have elapsed since the last time it was invoked. Pass
`true` for `immediate` to cause debounce to invoke `func` on the leading,
instead of the trailing, edge of the `wait` timeout. Subsequent calls to
the debounced function will return the result of the last `func` call.
@static
@memberOf _
@category Functions
@param {Function} func The function to debounce.
@param {Number} wait The number of milliseconds to delay.
@param {Boolean} immediate A flag to indicate execution is on the leading
edge of the timeout.
@returns {Function} Returns the new debounced function.
@example
var lazyLayout = _.debounce(calculateLayout, 300);
jQuery(window).on('resize', lazyLayout); | [
"Creates",
"a",
"new",
"function",
"that",
"will",
"delay",
"the",
"execution",
"of",
"func",
"until",
"after",
"wait",
"milliseconds",
"have",
"elapsed",
"since",
"the",
"last",
"time",
"it",
"was",
"invoked",
".",
"Pass",
"true",
"for",
"immediate",
"to",
"cause",
"debounce",
"to",
"invoke",
"func",
"on",
"the",
"leading",
"instead",
"of",
"the",
"trailing",
"edge",
"of",
"the",
"wait",
"timeout",
".",
"Subsequent",
"calls",
"to",
"the",
"debounced",
"function",
"will",
"return",
"the",
"result",
"of",
"the",
"last",
"func",
"call",
"."
]
| efdd402c676554991ff1d4cdc10818fca8f87187 | https://github.com/kmalakoff/backbone-modelref/blob/efdd402c676554991ff1d4cdc10818fca8f87187/vendor/optional/lodash-0.3.2.js#L1987-L2013 |
46,118 | kmalakoff/backbone-modelref | vendor/optional/lodash-0.3.2.js | memoize | function memoize(func, resolver) {
var cache = {};
return function() {
var prop = resolver ? resolver.apply(this, arguments) : arguments[0];
return hasOwnProperty.call(cache, prop)
? cache[prop]
: (cache[prop] = func.apply(this, arguments));
};
} | javascript | function memoize(func, resolver) {
var cache = {};
return function() {
var prop = resolver ? resolver.apply(this, arguments) : arguments[0];
return hasOwnProperty.call(cache, prop)
? cache[prop]
: (cache[prop] = func.apply(this, arguments));
};
} | [
"function",
"memoize",
"(",
"func",
",",
"resolver",
")",
"{",
"var",
"cache",
"=",
"{",
"}",
";",
"return",
"function",
"(",
")",
"{",
"var",
"prop",
"=",
"resolver",
"?",
"resolver",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
":",
"arguments",
"[",
"0",
"]",
";",
"return",
"hasOwnProperty",
".",
"call",
"(",
"cache",
",",
"prop",
")",
"?",
"cache",
"[",
"prop",
"]",
":",
"(",
"cache",
"[",
"prop",
"]",
"=",
"func",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
")",
";",
"}",
";",
"}"
]
| Creates a new function that memoizes the result of `func`. If `resolver` is
passed, it will be used to determine the cache key for storing the result
based on the arguments passed to the memoized function. By default, the first
argument passed to the memoized function is used as the cache key.
@static
@memberOf _
@category Functions
@param {Function} func The function to have its output memoized.
@param {Function} [resolver] A function used to resolve the cache key.
@returns {Function} Returns the new memoizing function.
@example
var fibonacci = _.memoize(function(n) {
return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2);
}); | [
"Creates",
"a",
"new",
"function",
"that",
"memoizes",
"the",
"result",
"of",
"func",
".",
"If",
"resolver",
"is",
"passed",
"it",
"will",
"be",
"used",
"to",
"determine",
"the",
"cache",
"key",
"for",
"storing",
"the",
"result",
"based",
"on",
"the",
"arguments",
"passed",
"to",
"the",
"memoized",
"function",
".",
"By",
"default",
"the",
"first",
"argument",
"passed",
"to",
"the",
"memoized",
"function",
"is",
"used",
"as",
"the",
"cache",
"key",
"."
]
| efdd402c676554991ff1d4cdc10818fca8f87187 | https://github.com/kmalakoff/backbone-modelref/blob/efdd402c676554991ff1d4cdc10818fca8f87187/vendor/optional/lodash-0.3.2.js#L2075-L2083 |
46,119 | kmalakoff/backbone-modelref | vendor/optional/lodash-0.3.2.js | once | function once(func) {
var result,
ran = false;
return function() {
if (ran) {
return result;
}
ran = true;
result = func.apply(this, arguments);
return result;
};
} | javascript | function once(func) {
var result,
ran = false;
return function() {
if (ran) {
return result;
}
ran = true;
result = func.apply(this, arguments);
return result;
};
} | [
"function",
"once",
"(",
"func",
")",
"{",
"var",
"result",
",",
"ran",
"=",
"false",
";",
"return",
"function",
"(",
")",
"{",
"if",
"(",
"ran",
")",
"{",
"return",
"result",
";",
"}",
"ran",
"=",
"true",
";",
"result",
"=",
"func",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"return",
"result",
";",
"}",
";",
"}"
]
| Creates a new function that is restricted to one execution. Repeat calls to
the function will return the value of the first call.
@static
@memberOf _
@category Functions
@param {Function} func The function to restrict.
@returns {Function} Returns the new restricted function.
@example
var initialize = _.once(createApplication);
initialize();
initialize();
// Application is only created once. | [
"Creates",
"a",
"new",
"function",
"that",
"is",
"restricted",
"to",
"one",
"execution",
".",
"Repeat",
"calls",
"to",
"the",
"function",
"will",
"return",
"the",
"value",
"of",
"the",
"first",
"call",
"."
]
| efdd402c676554991ff1d4cdc10818fca8f87187 | https://github.com/kmalakoff/backbone-modelref/blob/efdd402c676554991ff1d4cdc10818fca8f87187/vendor/optional/lodash-0.3.2.js#L2101-L2113 |
46,120 | kmalakoff/backbone-modelref | vendor/optional/lodash-0.3.2.js | throttle | function throttle(func, wait) {
var args,
result,
thisArg,
timeoutId,
lastCalled = 0;
function trailingCall() {
lastCalled = new Date;
timeoutId = undefined;
func.apply(thisArg, args);
}
return function() {
var now = new Date,
remain = wait - (now - lastCalled);
args = arguments;
thisArg = this;
if (remain <= 0) {
lastCalled = now;
result = func.apply(thisArg, args);
}
else if (!timeoutId) {
timeoutId = setTimeout(trailingCall, remain);
}
return result;
};
} | javascript | function throttle(func, wait) {
var args,
result,
thisArg,
timeoutId,
lastCalled = 0;
function trailingCall() {
lastCalled = new Date;
timeoutId = undefined;
func.apply(thisArg, args);
}
return function() {
var now = new Date,
remain = wait - (now - lastCalled);
args = arguments;
thisArg = this;
if (remain <= 0) {
lastCalled = now;
result = func.apply(thisArg, args);
}
else if (!timeoutId) {
timeoutId = setTimeout(trailingCall, remain);
}
return result;
};
} | [
"function",
"throttle",
"(",
"func",
",",
"wait",
")",
"{",
"var",
"args",
",",
"result",
",",
"thisArg",
",",
"timeoutId",
",",
"lastCalled",
"=",
"0",
";",
"function",
"trailingCall",
"(",
")",
"{",
"lastCalled",
"=",
"new",
"Date",
";",
"timeoutId",
"=",
"undefined",
";",
"func",
".",
"apply",
"(",
"thisArg",
",",
"args",
")",
";",
"}",
"return",
"function",
"(",
")",
"{",
"var",
"now",
"=",
"new",
"Date",
",",
"remain",
"=",
"wait",
"-",
"(",
"now",
"-",
"lastCalled",
")",
";",
"args",
"=",
"arguments",
";",
"thisArg",
"=",
"this",
";",
"if",
"(",
"remain",
"<=",
"0",
")",
"{",
"lastCalled",
"=",
"now",
";",
"result",
"=",
"func",
".",
"apply",
"(",
"thisArg",
",",
"args",
")",
";",
"}",
"else",
"if",
"(",
"!",
"timeoutId",
")",
"{",
"timeoutId",
"=",
"setTimeout",
"(",
"trailingCall",
",",
"remain",
")",
";",
"}",
"return",
"result",
";",
"}",
";",
"}"
]
| Creates a new function that, when executed, will only call the `func`
function at most once per every `wait` milliseconds. If the throttled
function is invoked more than once during the `wait` timeout, `func` will
also be called on the trailing edge of the timeout. Subsequent calls to the
throttled function will return the result of the last `func` call.
@static
@memberOf _
@category Functions
@param {Function} func The function to throttle.
@param {Number} wait The number of milliseconds to throttle executions to.
@returns {Function} Returns the new throttled function.
@example
var throttled = _.throttle(updatePosition, 100);
jQuery(window).on('scroll', throttled); | [
"Creates",
"a",
"new",
"function",
"that",
"when",
"executed",
"will",
"only",
"call",
"the",
"func",
"function",
"at",
"most",
"once",
"per",
"every",
"wait",
"milliseconds",
".",
"If",
"the",
"throttled",
"function",
"is",
"invoked",
"more",
"than",
"once",
"during",
"the",
"wait",
"timeout",
"func",
"will",
"also",
"be",
"called",
"on",
"the",
"trailing",
"edge",
"of",
"the",
"timeout",
".",
"Subsequent",
"calls",
"to",
"the",
"throttled",
"function",
"will",
"return",
"the",
"result",
"of",
"the",
"last",
"func",
"call",
"."
]
| efdd402c676554991ff1d4cdc10818fca8f87187 | https://github.com/kmalakoff/backbone-modelref/blob/efdd402c676554991ff1d4cdc10818fca8f87187/vendor/optional/lodash-0.3.2.js#L2170-L2199 |
46,121 | kmalakoff/backbone-modelref | vendor/optional/lodash-0.3.2.js | wrap | function wrap(func, wrapper) {
return function() {
var args = [func];
if (arguments.length) {
push.apply(args, arguments);
}
return wrapper.apply(this, args);
};
} | javascript | function wrap(func, wrapper) {
return function() {
var args = [func];
if (arguments.length) {
push.apply(args, arguments);
}
return wrapper.apply(this, args);
};
} | [
"function",
"wrap",
"(",
"func",
",",
"wrapper",
")",
"{",
"return",
"function",
"(",
")",
"{",
"var",
"args",
"=",
"[",
"func",
"]",
";",
"if",
"(",
"arguments",
".",
"length",
")",
"{",
"push",
".",
"apply",
"(",
"args",
",",
"arguments",
")",
";",
"}",
"return",
"wrapper",
".",
"apply",
"(",
"this",
",",
"args",
")",
";",
"}",
";",
"}"
]
| Create a new function that passes the `func` function to the `wrapper`
function as its first argument. Additional arguments are appended to those
passed to the `wrapper` function.
@static
@memberOf _
@category Functions
@param {Function} func The function to wrap.
@param {Function} wrapper The wrapper function.
@param {Mixed} [arg1, arg2, ...] Arguments to append to those passed to the wrapper.
@returns {Function} Returns the new function.
@example
var hello = function(name) { return 'hello: ' + name; };
hello = _.wrap(hello, function(func) {
return 'before, ' + func('moe') + ', after';
});
hello();
// => 'before, hello: moe, after' | [
"Create",
"a",
"new",
"function",
"that",
"passes",
"the",
"func",
"function",
"to",
"the",
"wrapper",
"function",
"as",
"its",
"first",
"argument",
".",
"Additional",
"arguments",
"are",
"appended",
"to",
"those",
"passed",
"to",
"the",
"wrapper",
"function",
"."
]
| efdd402c676554991ff1d4cdc10818fca8f87187 | https://github.com/kmalakoff/backbone-modelref/blob/efdd402c676554991ff1d4cdc10818fca8f87187/vendor/optional/lodash-0.3.2.js#L2222-L2230 |
46,122 | kmalakoff/backbone-modelref | vendor/optional/lodash-0.3.2.js | pick | function pick(object) {
var prop,
index = 0,
props = concat.apply(ArrayProto, arguments),
length = props.length,
result = {};
// start `index` at `1` to skip `object`
while (++index < length) {
prop = props[index];
if (prop in object) {
result[prop] = object[prop];
}
}
return result;
} | javascript | function pick(object) {
var prop,
index = 0,
props = concat.apply(ArrayProto, arguments),
length = props.length,
result = {};
// start `index` at `1` to skip `object`
while (++index < length) {
prop = props[index];
if (prop in object) {
result[prop] = object[prop];
}
}
return result;
} | [
"function",
"pick",
"(",
"object",
")",
"{",
"var",
"prop",
",",
"index",
"=",
"0",
",",
"props",
"=",
"concat",
".",
"apply",
"(",
"ArrayProto",
",",
"arguments",
")",
",",
"length",
"=",
"props",
".",
"length",
",",
"result",
"=",
"{",
"}",
";",
"// start `index` at `1` to skip `object`",
"while",
"(",
"++",
"index",
"<",
"length",
")",
"{",
"prop",
"=",
"props",
"[",
"index",
"]",
";",
"if",
"(",
"prop",
"in",
"object",
")",
"{",
"result",
"[",
"prop",
"]",
"=",
"object",
"[",
"prop",
"]",
";",
"}",
"}",
"return",
"result",
";",
"}"
]
| Creates an object composed of the specified properties. Property names may
be specified as individual arguments or as arrays of property names.
@static
@memberOf _
@category Objects
@param {Object} object The object to pluck.
@param {Object} [prop1, prop2, ...] The properties to pick.
@returns {Object} Returns an object composed of the picked properties.
@example
_.pick({ 'name': 'moe', 'age': 40, 'userid': 'moe1' }, 'name', 'age');
// => { 'name': 'moe', 'age': 40 } | [
"Creates",
"an",
"object",
"composed",
"of",
"the",
"specified",
"properties",
".",
"Property",
"names",
"may",
"be",
"specified",
"as",
"individual",
"arguments",
"or",
"as",
"arrays",
"of",
"property",
"names",
"."
]
| efdd402c676554991ff1d4cdc10818fca8f87187 | https://github.com/kmalakoff/backbone-modelref/blob/efdd402c676554991ff1d4cdc10818fca8f87187/vendor/optional/lodash-0.3.2.js#L2895-L2910 |
46,123 | kmalakoff/backbone-modelref | vendor/optional/lodash-0.3.2.js | size | function size(value) {
var className = toString.call(value);
return className == arrayClass || className == stringClass
? value.length
: keys(value).length;
} | javascript | function size(value) {
var className = toString.call(value);
return className == arrayClass || className == stringClass
? value.length
: keys(value).length;
} | [
"function",
"size",
"(",
"value",
")",
"{",
"var",
"className",
"=",
"toString",
".",
"call",
"(",
"value",
")",
";",
"return",
"className",
"==",
"arrayClass",
"||",
"className",
"==",
"stringClass",
"?",
"value",
".",
"length",
":",
"keys",
"(",
"value",
")",
".",
"length",
";",
"}"
]
| Gets the size of `value` by returning `value.length` if `value` is a string
or array, or the number of own enumerable properties if `value` is an object.
@deprecated
@static
@memberOf _
@category Objects
@param {Array|Object|String} value The value to inspect.
@returns {Number} Returns `value.length` if `value` is a string or array,
or the number of own enumerable properties if `value` is an object.
@example
_.size([1, 2]);
// => 2
_.size({ 'one': 1, 'two': 2, 'three': 3 });
// => 3
_.size('curly');
// => 5 | [
"Gets",
"the",
"size",
"of",
"value",
"by",
"returning",
"value",
".",
"length",
"if",
"value",
"is",
"a",
"string",
"or",
"array",
"or",
"the",
"number",
"of",
"own",
"enumerable",
"properties",
"if",
"value",
"is",
"an",
"object",
"."
]
| efdd402c676554991ff1d4cdc10818fca8f87187 | https://github.com/kmalakoff/backbone-modelref/blob/efdd402c676554991ff1d4cdc10818fca8f87187/vendor/optional/lodash-0.3.2.js#L2934-L2939 |
46,124 | kmalakoff/backbone-modelref | vendor/optional/lodash-0.3.2.js | result | function result(object, property) {
// based on Backbone's private `getValue` function
// https://github.com/documentcloud/backbone/blob/0.9.9/backbone.js#L1419-1424
if (!object) {
return null;
}
var value = object[property];
return toString.call(value) == funcClass ? object[property]() : value;
} | javascript | function result(object, property) {
// based on Backbone's private `getValue` function
// https://github.com/documentcloud/backbone/blob/0.9.9/backbone.js#L1419-1424
if (!object) {
return null;
}
var value = object[property];
return toString.call(value) == funcClass ? object[property]() : value;
} | [
"function",
"result",
"(",
"object",
",",
"property",
")",
"{",
"// based on Backbone's private `getValue` function",
"// https://github.com/documentcloud/backbone/blob/0.9.9/backbone.js#L1419-1424",
"if",
"(",
"!",
"object",
")",
"{",
"return",
"null",
";",
"}",
"var",
"value",
"=",
"object",
"[",
"property",
"]",
";",
"return",
"toString",
".",
"call",
"(",
"value",
")",
"==",
"funcClass",
"?",
"object",
"[",
"property",
"]",
"(",
")",
":",
"value",
";",
"}"
]
| Resolves the value of `property` on `object`. If `property` is a function
it will be invoked and its result returned, else the property value is
returned. If `object` is falsey, then `null` is returned.
@deprecated
@static
@memberOf _
@category Utilities
@param {Object} object The object to inspect.
@param {String} property The property to get the result of.
@returns {Mixed} Returns the resolved value.
@example
var object = {
'cheese': 'crumpets',
'stuff': function() {
return 'nonsense';
}
};
_.result(object, 'cheese');
// => 'crumpets'
_.result(object, 'stuff');
// => 'nonsense' | [
"Resolves",
"the",
"value",
"of",
"property",
"on",
"object",
".",
"If",
"property",
"is",
"a",
"function",
"it",
"will",
"be",
"invoked",
"and",
"its",
"result",
"returned",
"else",
"the",
"property",
"value",
"is",
"returned",
".",
"If",
"object",
"is",
"falsey",
"then",
"null",
"is",
"returned",
"."
]
| efdd402c676554991ff1d4cdc10818fca8f87187 | https://github.com/kmalakoff/backbone-modelref/blob/efdd402c676554991ff1d4cdc10818fca8f87187/vendor/optional/lodash-0.3.2.js#L3084-L3092 |
46,125 | kmalakoff/backbone-modelref | vendor/optional/lodash-0.3.2.js | template | function template(text, data, options) {
options || (options = {});
var result,
defaults = lodash.templateSettings,
escapeDelimiter = options.escape,
evaluateDelimiter = options.evaluate,
interpolateDelimiter = options.interpolate,
variable = options.variable;
// use template defaults if no option is provided
if (escapeDelimiter == null) {
escapeDelimiter = defaults.escape;
}
if (evaluateDelimiter == null) {
evaluateDelimiter = defaults.evaluate;
}
if (interpolateDelimiter == null) {
interpolateDelimiter = defaults.interpolate;
}
// tokenize delimiters to avoid escaping them
if (escapeDelimiter) {
text = text.replace(escapeDelimiter, tokenizeEscape);
}
if (interpolateDelimiter) {
text = text.replace(interpolateDelimiter, tokenizeInterpolate);
}
if (evaluateDelimiter) {
text = text.replace(evaluateDelimiter, tokenizeEvaluate);
}
// escape characters that cannot be included in string literals and
// detokenize delimiter code snippets
text = "__p='" + text
.replace(reUnescapedString, escapeStringChar)
.replace(reToken, detokenize) + "';\n";
// clear stored code snippets
tokenized.length = 0;
// if `options.variable` is not specified, add `data` to the top of the scope chain
if (!variable) {
variable = defaults.variable;
text = 'with (' + variable + ' || {}) {\n' + text + '\n}\n';
}
text = 'function(' + variable + ') {\n' +
'var __p, __t, __j = Array.prototype.join;\n' +
'function print() { __p += __j.call(arguments, \'\') }\n' +
text +
'return __p\n}';
// add a sourceURL for easier debugging
// http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl
if (useSourceURL) {
text += '\n//@ sourceURL=/lodash/template/source[' + (templateCounter++) + ']';
}
result = Function('_', 'return ' + text)(lodash);
if (data) {
return result(data);
}
// provide the compiled function's source via its `toString()` method, in
// supported environments, or the `source` property as a convenience for
// build time precompilation
result.source = text;
return result;
} | javascript | function template(text, data, options) {
options || (options = {});
var result,
defaults = lodash.templateSettings,
escapeDelimiter = options.escape,
evaluateDelimiter = options.evaluate,
interpolateDelimiter = options.interpolate,
variable = options.variable;
// use template defaults if no option is provided
if (escapeDelimiter == null) {
escapeDelimiter = defaults.escape;
}
if (evaluateDelimiter == null) {
evaluateDelimiter = defaults.evaluate;
}
if (interpolateDelimiter == null) {
interpolateDelimiter = defaults.interpolate;
}
// tokenize delimiters to avoid escaping them
if (escapeDelimiter) {
text = text.replace(escapeDelimiter, tokenizeEscape);
}
if (interpolateDelimiter) {
text = text.replace(interpolateDelimiter, tokenizeInterpolate);
}
if (evaluateDelimiter) {
text = text.replace(evaluateDelimiter, tokenizeEvaluate);
}
// escape characters that cannot be included in string literals and
// detokenize delimiter code snippets
text = "__p='" + text
.replace(reUnescapedString, escapeStringChar)
.replace(reToken, detokenize) + "';\n";
// clear stored code snippets
tokenized.length = 0;
// if `options.variable` is not specified, add `data` to the top of the scope chain
if (!variable) {
variable = defaults.variable;
text = 'with (' + variable + ' || {}) {\n' + text + '\n}\n';
}
text = 'function(' + variable + ') {\n' +
'var __p, __t, __j = Array.prototype.join;\n' +
'function print() { __p += __j.call(arguments, \'\') }\n' +
text +
'return __p\n}';
// add a sourceURL for easier debugging
// http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl
if (useSourceURL) {
text += '\n//@ sourceURL=/lodash/template/source[' + (templateCounter++) + ']';
}
result = Function('_', 'return ' + text)(lodash);
if (data) {
return result(data);
}
// provide the compiled function's source via its `toString()` method, in
// supported environments, or the `source` property as a convenience for
// build time precompilation
result.source = text;
return result;
} | [
"function",
"template",
"(",
"text",
",",
"data",
",",
"options",
")",
"{",
"options",
"||",
"(",
"options",
"=",
"{",
"}",
")",
";",
"var",
"result",
",",
"defaults",
"=",
"lodash",
".",
"templateSettings",
",",
"escapeDelimiter",
"=",
"options",
".",
"escape",
",",
"evaluateDelimiter",
"=",
"options",
".",
"evaluate",
",",
"interpolateDelimiter",
"=",
"options",
".",
"interpolate",
",",
"variable",
"=",
"options",
".",
"variable",
";",
"// use template defaults if no option is provided",
"if",
"(",
"escapeDelimiter",
"==",
"null",
")",
"{",
"escapeDelimiter",
"=",
"defaults",
".",
"escape",
";",
"}",
"if",
"(",
"evaluateDelimiter",
"==",
"null",
")",
"{",
"evaluateDelimiter",
"=",
"defaults",
".",
"evaluate",
";",
"}",
"if",
"(",
"interpolateDelimiter",
"==",
"null",
")",
"{",
"interpolateDelimiter",
"=",
"defaults",
".",
"interpolate",
";",
"}",
"// tokenize delimiters to avoid escaping them",
"if",
"(",
"escapeDelimiter",
")",
"{",
"text",
"=",
"text",
".",
"replace",
"(",
"escapeDelimiter",
",",
"tokenizeEscape",
")",
";",
"}",
"if",
"(",
"interpolateDelimiter",
")",
"{",
"text",
"=",
"text",
".",
"replace",
"(",
"interpolateDelimiter",
",",
"tokenizeInterpolate",
")",
";",
"}",
"if",
"(",
"evaluateDelimiter",
")",
"{",
"text",
"=",
"text",
".",
"replace",
"(",
"evaluateDelimiter",
",",
"tokenizeEvaluate",
")",
";",
"}",
"// escape characters that cannot be included in string literals and",
"// detokenize delimiter code snippets",
"text",
"=",
"\"__p='\"",
"+",
"text",
".",
"replace",
"(",
"reUnescapedString",
",",
"escapeStringChar",
")",
".",
"replace",
"(",
"reToken",
",",
"detokenize",
")",
"+",
"\"';\\n\"",
";",
"// clear stored code snippets",
"tokenized",
".",
"length",
"=",
"0",
";",
"// if `options.variable` is not specified, add `data` to the top of the scope chain",
"if",
"(",
"!",
"variable",
")",
"{",
"variable",
"=",
"defaults",
".",
"variable",
";",
"text",
"=",
"'with ('",
"+",
"variable",
"+",
"' || {}) {\\n'",
"+",
"text",
"+",
"'\\n}\\n'",
";",
"}",
"text",
"=",
"'function('",
"+",
"variable",
"+",
"') {\\n'",
"+",
"'var __p, __t, __j = Array.prototype.join;\\n'",
"+",
"'function print() { __p += __j.call(arguments, \\'\\') }\\n'",
"+",
"text",
"+",
"'return __p\\n}'",
";",
"// add a sourceURL for easier debugging",
"// http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl",
"if",
"(",
"useSourceURL",
")",
"{",
"text",
"+=",
"'\\n//@ sourceURL=/lodash/template/source['",
"+",
"(",
"templateCounter",
"++",
")",
"+",
"']'",
";",
"}",
"result",
"=",
"Function",
"(",
"'_'",
",",
"'return '",
"+",
"text",
")",
"(",
"lodash",
")",
";",
"if",
"(",
"data",
")",
"{",
"return",
"result",
"(",
"data",
")",
";",
"}",
"// provide the compiled function's source via its `toString()` method, in",
"// supported environments, or the `source` property as a convenience for",
"// build time precompilation",
"result",
".",
"source",
"=",
"text",
";",
"return",
"result",
";",
"}"
]
| A micro-templating method, similar to John Resig's implementation.
Lo-Dash templating handles arbitrary delimiters, preserves whitespace, and
correctly escapes quotes within interpolated code.
@static
@memberOf _
@category Utilities
@param {String} text The template text.
@param {Obect} data The data object used to populate the text.
@param {Object} options The options object.
@returns {Function|String} Returns a compiled function when no `data` object
is given, else it returns the interpolated text.
@example
// using compiled template
var compiled = _.template('hello: <%= name %>');
compiled({ 'name': 'moe' });
// => 'hello: moe'
var list = '<% _.forEach(people, function(name) { %> <li><%= name %></li> <% }); %>';
_.template(list, { 'people': ['moe', 'curly', 'larry'] });
// => '<li>moe</li><li>curly</li><li>larry</li>'
var template = _.template('<b><%- value %></b>');
template({ 'value': '<script>' });
// => '<b><script></b>'
// using `print`
var compiled = _.template('<% print("Hello " + epithet); %>');
compiled({ 'epithet': 'stooge' });
// => 'Hello stooge.'
// using custom template settings
_.templateSettings = {
'interpolate': /\{\{(.+?)\}\}/g
};
var template = _.template('Hello {{ name }}!');
template({ 'name': 'Mustache' });
// => 'Hello Mustache!'
// using the `variable` option
_.template('<%= data.hasWith %>', { 'hasWith': 'no' }, { 'variable': 'data' });
// => 'no'
// using the `source` property
<script>
JST.project = <%= _.template(jstText).source %>;
</script> | [
"A",
"micro",
"-",
"templating",
"method",
"similar",
"to",
"John",
"Resig",
"s",
"implementation",
".",
"Lo",
"-",
"Dash",
"templating",
"handles",
"arbitrary",
"delimiters",
"preserves",
"whitespace",
"and",
"correctly",
"escapes",
"quotes",
"within",
"interpolated",
"code",
"."
]
| efdd402c676554991ff1d4cdc10818fca8f87187 | https://github.com/kmalakoff/backbone-modelref/blob/efdd402c676554991ff1d4cdc10818fca8f87187/vendor/optional/lodash-0.3.2.js#L3145-L3214 |
46,126 | Mithgol/FGHI-URL | index.js | FidonetURL | function FidonetURL(initialString){
if(!( this instanceof FidonetURL )){
return new FidonetURL(initialString);
}
parseFundamentalSections.call(this, initialString);
parseOptionalPart.call(this);
parseRequiredPart.call(this);
} | javascript | function FidonetURL(initialString){
if(!( this instanceof FidonetURL )){
return new FidonetURL(initialString);
}
parseFundamentalSections.call(this, initialString);
parseOptionalPart.call(this);
parseRequiredPart.call(this);
} | [
"function",
"FidonetURL",
"(",
"initialString",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"FidonetURL",
")",
")",
"{",
"return",
"new",
"FidonetURL",
"(",
"initialString",
")",
";",
"}",
"parseFundamentalSections",
".",
"call",
"(",
"this",
",",
"initialString",
")",
";",
"parseOptionalPart",
".",
"call",
"(",
"this",
")",
";",
"parseRequiredPart",
".",
"call",
"(",
"this",
")",
";",
"}"
]
| The FGHI URL object's constructor takes a string | [
"The",
"FGHI",
"URL",
"object",
"s",
"constructor",
"takes",
"a",
"string"
]
| 8a4d2dbb4efb5ed26c0a3e25170746b90932ccae | https://github.com/Mithgol/FGHI-URL/blob/8a4d2dbb4efb5ed26c0a3e25170746b90932ccae/index.js#L333-L341 |
46,127 | glenjamin/checkers | mocha.js | checking | function checking(desc, args, body, n, options) {
if (typeof n === 'undefined') {
n = 1000;
options = {};
}
if (typeof options === 'undefined' && typeof n !== 'number') {
options = n;
n = 1000;
}
it(desc, function() {
checkers.forAll(args, body).check(n, options);
});
} | javascript | function checking(desc, args, body, n, options) {
if (typeof n === 'undefined') {
n = 1000;
options = {};
}
if (typeof options === 'undefined' && typeof n !== 'number') {
options = n;
n = 1000;
}
it(desc, function() {
checkers.forAll(args, body).check(n, options);
});
} | [
"function",
"checking",
"(",
"desc",
",",
"args",
",",
"body",
",",
"n",
",",
"options",
")",
"{",
"if",
"(",
"typeof",
"n",
"===",
"'undefined'",
")",
"{",
"n",
"=",
"1000",
";",
"options",
"=",
"{",
"}",
";",
"}",
"if",
"(",
"typeof",
"options",
"===",
"'undefined'",
"&&",
"typeof",
"n",
"!==",
"'number'",
")",
"{",
"options",
"=",
"n",
";",
"n",
"=",
"1000",
";",
"}",
"it",
"(",
"desc",
",",
"function",
"(",
")",
"{",
"checkers",
".",
"forAll",
"(",
"args",
",",
"body",
")",
".",
"check",
"(",
"n",
",",
"options",
")",
";",
"}",
")",
";",
"}"
]
| Generate a mocha example
@param {string} desc The example description
@param {array} args List of generators to pass to body
@param {function} body Function to check, should return true or false
@param {number} n The number of iterations to check (optional)
@param {object} options Additional options for check (optional) | [
"Generate",
"a",
"mocha",
"example"
]
| fdbe549ae138564343f139ae35c0602d83674fd0 | https://github.com/glenjamin/checkers/blob/fdbe549ae138564343f139ae35c0602d83674fd0/mocha.js#L19-L31 |
46,128 | THEjoezack/BoxPusher | public/rot.js/rot.js | function(str, maxWidth) {
var result = [];
/* first tokenization pass - split texts and color formatting commands */
var offset = 0;
str.replace(this.RE_COLORS, function(match, type, name, index) {
/* string before */
var part = str.substring(offset, index);
if (part.length) {
result.push({
type: ROT.Text.TYPE_TEXT,
value: part
});
}
/* color command */
result.push({
type: (type == "c" ? ROT.Text.TYPE_FG : ROT.Text.TYPE_BG),
value: name.trim()
});
offset = index + match.length;
return "";
});
/* last remaining part */
var part = str.substring(offset);
if (part.length) {
result.push({
type: ROT.Text.TYPE_TEXT,
value: part
});
}
return this._breakLines(result, maxWidth);
} | javascript | function(str, maxWidth) {
var result = [];
/* first tokenization pass - split texts and color formatting commands */
var offset = 0;
str.replace(this.RE_COLORS, function(match, type, name, index) {
/* string before */
var part = str.substring(offset, index);
if (part.length) {
result.push({
type: ROT.Text.TYPE_TEXT,
value: part
});
}
/* color command */
result.push({
type: (type == "c" ? ROT.Text.TYPE_FG : ROT.Text.TYPE_BG),
value: name.trim()
});
offset = index + match.length;
return "";
});
/* last remaining part */
var part = str.substring(offset);
if (part.length) {
result.push({
type: ROT.Text.TYPE_TEXT,
value: part
});
}
return this._breakLines(result, maxWidth);
} | [
"function",
"(",
"str",
",",
"maxWidth",
")",
"{",
"var",
"result",
"=",
"[",
"]",
";",
"/* first tokenization pass - split texts and color formatting commands */",
"var",
"offset",
"=",
"0",
";",
"str",
".",
"replace",
"(",
"this",
".",
"RE_COLORS",
",",
"function",
"(",
"match",
",",
"type",
",",
"name",
",",
"index",
")",
"{",
"/* string before */",
"var",
"part",
"=",
"str",
".",
"substring",
"(",
"offset",
",",
"index",
")",
";",
"if",
"(",
"part",
".",
"length",
")",
"{",
"result",
".",
"push",
"(",
"{",
"type",
":",
"ROT",
".",
"Text",
".",
"TYPE_TEXT",
",",
"value",
":",
"part",
"}",
")",
";",
"}",
"/* color command */",
"result",
".",
"push",
"(",
"{",
"type",
":",
"(",
"type",
"==",
"\"c\"",
"?",
"ROT",
".",
"Text",
".",
"TYPE_FG",
":",
"ROT",
".",
"Text",
".",
"TYPE_BG",
")",
",",
"value",
":",
"name",
".",
"trim",
"(",
")",
"}",
")",
";",
"offset",
"=",
"index",
"+",
"match",
".",
"length",
";",
"return",
"\"\"",
";",
"}",
")",
";",
"/* last remaining part */",
"var",
"part",
"=",
"str",
".",
"substring",
"(",
"offset",
")",
";",
"if",
"(",
"part",
".",
"length",
")",
"{",
"result",
".",
"push",
"(",
"{",
"type",
":",
"ROT",
".",
"Text",
".",
"TYPE_TEXT",
",",
"value",
":",
"part",
"}",
")",
";",
"}",
"return",
"this",
".",
"_breakLines",
"(",
"result",
",",
"maxWidth",
")",
";",
"}"
]
| Convert string to a series of a formatting commands | [
"Convert",
"string",
"to",
"a",
"series",
"of",
"a",
"formatting",
"commands"
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/rot.js/rot.js#L401-L436 |
|
46,129 | THEjoezack/BoxPusher | public/rot.js/rot.js | function(color1, color2) {
var result = color1.slice();
for (var i=0;i<3;i++) {
for (var j=1;j<arguments.length;j++) {
result[i] += arguments[j][i];
}
}
return result;
} | javascript | function(color1, color2) {
var result = color1.slice();
for (var i=0;i<3;i++) {
for (var j=1;j<arguments.length;j++) {
result[i] += arguments[j][i];
}
}
return result;
} | [
"function",
"(",
"color1",
",",
"color2",
")",
"{",
"var",
"result",
"=",
"color1",
".",
"slice",
"(",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"3",
";",
"i",
"++",
")",
"{",
"for",
"(",
"var",
"j",
"=",
"1",
";",
"j",
"<",
"arguments",
".",
"length",
";",
"j",
"++",
")",
"{",
"result",
"[",
"i",
"]",
"+=",
"arguments",
"[",
"j",
"]",
"[",
"i",
"]",
";",
"}",
"}",
"return",
"result",
";",
"}"
]
| Add two or more colors
@param {number[]} color1
@param {number[]} color2
@returns {number[]} | [
"Add",
"two",
"or",
"more",
"colors"
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/rot.js/rot.js#L4483-L4491 |
|
46,130 | THEjoezack/BoxPusher | public/rot.js/rot.js | function(color1, color2) {
for (var i=0;i<3;i++) {
for (var j=1;j<arguments.length;j++) {
color1[i] += arguments[j][i];
}
}
return color1;
} | javascript | function(color1, color2) {
for (var i=0;i<3;i++) {
for (var j=1;j<arguments.length;j++) {
color1[i] += arguments[j][i];
}
}
return color1;
} | [
"function",
"(",
"color1",
",",
"color2",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"3",
";",
"i",
"++",
")",
"{",
"for",
"(",
"var",
"j",
"=",
"1",
";",
"j",
"<",
"arguments",
".",
"length",
";",
"j",
"++",
")",
"{",
"color1",
"[",
"i",
"]",
"+=",
"arguments",
"[",
"j",
"]",
"[",
"i",
"]",
";",
"}",
"}",
"return",
"color1",
";",
"}"
]
| Add two or more colors, MODIFIES FIRST ARGUMENT
@param {number[]} color1
@param {number[]} color2
@returns {number[]} | [
"Add",
"two",
"or",
"more",
"colors",
"MODIFIES",
"FIRST",
"ARGUMENT"
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/rot.js/rot.js#L4499-L4506 |
|
46,131 | THEjoezack/BoxPusher | public/rot.js/rot.js | function(color, diff) {
if (!(diff instanceof Array)) { diff = ROT.RNG.getNormal(0, diff); }
var result = color.slice();
for (var i=0;i<3;i++) {
result[i] += (diff instanceof Array ? Math.round(ROT.RNG.getNormal(0, diff[i])) : diff);
}
return result;
} | javascript | function(color, diff) {
if (!(diff instanceof Array)) { diff = ROT.RNG.getNormal(0, diff); }
var result = color.slice();
for (var i=0;i<3;i++) {
result[i] += (diff instanceof Array ? Math.round(ROT.RNG.getNormal(0, diff[i])) : diff);
}
return result;
} | [
"function",
"(",
"color",
",",
"diff",
")",
"{",
"if",
"(",
"!",
"(",
"diff",
"instanceof",
"Array",
")",
")",
"{",
"diff",
"=",
"ROT",
".",
"RNG",
".",
"getNormal",
"(",
"0",
",",
"diff",
")",
";",
"}",
"var",
"result",
"=",
"color",
".",
"slice",
"(",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"3",
";",
"i",
"++",
")",
"{",
"result",
"[",
"i",
"]",
"+=",
"(",
"diff",
"instanceof",
"Array",
"?",
"Math",
".",
"round",
"(",
"ROT",
".",
"RNG",
".",
"getNormal",
"(",
"0",
",",
"diff",
"[",
"i",
"]",
")",
")",
":",
"diff",
")",
";",
"}",
"return",
"result",
";",
"}"
]
| Create a new random color based on this one
@param {number[]} color
@param {number[]} diff Set of standard deviations
@returns {number[]} | [
"Create",
"a",
"new",
"random",
"color",
"based",
"on",
"this",
"one"
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/rot.js/rot.js#L4580-L4587 |
|
46,132 | THEjoezack/BoxPusher | public/rot.js/rot.js | function(color) {
var l = color[2];
if (color[1] == 0) {
l = Math.round(l*255);
return [l, l, l];
} else {
function hue2rgb(p, q, t) {
if (t < 0) t += 1;
if (t > 1) t -= 1;
if (t < 1/6) return p + (q - p) * 6 * t;
if (t < 1/2) return q;
if (t < 2/3) return p + (q - p) * (2/3 - t) * 6;
return p;
}
var s = color[1];
var q = (l < 0.5 ? l * (1 + s) : l + s - l * s);
var p = 2 * l - q;
var r = hue2rgb(p, q, color[0] + 1/3);
var g = hue2rgb(p, q, color[0]);
var b = hue2rgb(p, q, color[0] - 1/3);
return [Math.round(r*255), Math.round(g*255), Math.round(b*255)];
}
} | javascript | function(color) {
var l = color[2];
if (color[1] == 0) {
l = Math.round(l*255);
return [l, l, l];
} else {
function hue2rgb(p, q, t) {
if (t < 0) t += 1;
if (t > 1) t -= 1;
if (t < 1/6) return p + (q - p) * 6 * t;
if (t < 1/2) return q;
if (t < 2/3) return p + (q - p) * (2/3 - t) * 6;
return p;
}
var s = color[1];
var q = (l < 0.5 ? l * (1 + s) : l + s - l * s);
var p = 2 * l - q;
var r = hue2rgb(p, q, color[0] + 1/3);
var g = hue2rgb(p, q, color[0]);
var b = hue2rgb(p, q, color[0] - 1/3);
return [Math.round(r*255), Math.round(g*255), Math.round(b*255)];
}
} | [
"function",
"(",
"color",
")",
"{",
"var",
"l",
"=",
"color",
"[",
"2",
"]",
";",
"if",
"(",
"color",
"[",
"1",
"]",
"==",
"0",
")",
"{",
"l",
"=",
"Math",
".",
"round",
"(",
"l",
"*",
"255",
")",
";",
"return",
"[",
"l",
",",
"l",
",",
"l",
"]",
";",
"}",
"else",
"{",
"function",
"hue2rgb",
"(",
"p",
",",
"q",
",",
"t",
")",
"{",
"if",
"(",
"t",
"<",
"0",
")",
"t",
"+=",
"1",
";",
"if",
"(",
"t",
">",
"1",
")",
"t",
"-=",
"1",
";",
"if",
"(",
"t",
"<",
"1",
"/",
"6",
")",
"return",
"p",
"+",
"(",
"q",
"-",
"p",
")",
"*",
"6",
"*",
"t",
";",
"if",
"(",
"t",
"<",
"1",
"/",
"2",
")",
"return",
"q",
";",
"if",
"(",
"t",
"<",
"2",
"/",
"3",
")",
"return",
"p",
"+",
"(",
"q",
"-",
"p",
")",
"*",
"(",
"2",
"/",
"3",
"-",
"t",
")",
"*",
"6",
";",
"return",
"p",
";",
"}",
"var",
"s",
"=",
"color",
"[",
"1",
"]",
";",
"var",
"q",
"=",
"(",
"l",
"<",
"0.5",
"?",
"l",
"*",
"(",
"1",
"+",
"s",
")",
":",
"l",
"+",
"s",
"-",
"l",
"*",
"s",
")",
";",
"var",
"p",
"=",
"2",
"*",
"l",
"-",
"q",
";",
"var",
"r",
"=",
"hue2rgb",
"(",
"p",
",",
"q",
",",
"color",
"[",
"0",
"]",
"+",
"1",
"/",
"3",
")",
";",
"var",
"g",
"=",
"hue2rgb",
"(",
"p",
",",
"q",
",",
"color",
"[",
"0",
"]",
")",
";",
"var",
"b",
"=",
"hue2rgb",
"(",
"p",
",",
"q",
",",
"color",
"[",
"0",
"]",
"-",
"1",
"/",
"3",
")",
";",
"return",
"[",
"Math",
".",
"round",
"(",
"r",
"*",
"255",
")",
",",
"Math",
".",
"round",
"(",
"g",
"*",
"255",
")",
",",
"Math",
".",
"round",
"(",
"b",
"*",
"255",
")",
"]",
";",
"}",
"}"
]
| Converts an HSL color value to RGB. Expects 0..1 inputs, produces 0..255 outputs.
@param {number[]} color
@returns {number[]} | [
"Converts",
"an",
"HSL",
"color",
"value",
"to",
"RGB",
".",
"Expects",
"0",
"..",
"1",
"inputs",
"produces",
"0",
"..",
"255",
"outputs",
"."
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/rot.js/rot.js#L4623-L4647 |
|
46,133 | io-monad/misspellings | src/misspellings.js | dict | function dict(options = {}) {
if (options.lowerCase) {
return dictCache[0] || (dictCache[0] = require("../dict/lc-dictionary.json"));
} else {
return dictCache[1] || (dictCache[1] = require("../dict/dictionary.json"));
}
} | javascript | function dict(options = {}) {
if (options.lowerCase) {
return dictCache[0] || (dictCache[0] = require("../dict/lc-dictionary.json"));
} else {
return dictCache[1] || (dictCache[1] = require("../dict/dictionary.json"));
}
} | [
"function",
"dict",
"(",
"options",
"=",
"{",
"}",
")",
"{",
"if",
"(",
"options",
".",
"lowerCase",
")",
"{",
"return",
"dictCache",
"[",
"0",
"]",
"||",
"(",
"dictCache",
"[",
"0",
"]",
"=",
"require",
"(",
"\"../dict/lc-dictionary.json\"",
")",
")",
";",
"}",
"else",
"{",
"return",
"dictCache",
"[",
"1",
"]",
"||",
"(",
"dictCache",
"[",
"1",
"]",
"=",
"require",
"(",
"\"../dict/dictionary.json\"",
")",
")",
";",
"}",
"}"
]
| Getter for the dictionary of misspellings.
This getter lazy-loads the dictionary file and caches it internally.
@param {Object} [options] Options.
@param {Boolean} [options.lowerCase=false]
If `true`, returns a dictionary with all keys in lower-case.
@return {Object} Dictionary object.
The key is misspelled word, and the value is a string of comma-separated
list of correct words. | [
"Getter",
"for",
"the",
"dictionary",
"of",
"misspellings",
"."
]
| 9281c7400348f69ba86af0567571d210253e246a | https://github.com/io-monad/misspellings/blob/9281c7400348f69ba86af0567571d210253e246a/src/misspellings.js#L45-L51 |
46,134 | io-monad/misspellings | src/misspellings.js | correctWordsFor | function correctWordsFor(word, options = {}) {
word = String(word || "");
const found = (options.caseSensitive ?
dict()[word] :
dict({ lowerCase: true })[word.toLowerCase()]
);
return found ? found.split(",") : [];
} | javascript | function correctWordsFor(word, options = {}) {
word = String(word || "");
const found = (options.caseSensitive ?
dict()[word] :
dict({ lowerCase: true })[word.toLowerCase()]
);
return found ? found.split(",") : [];
} | [
"function",
"correctWordsFor",
"(",
"word",
",",
"options",
"=",
"{",
"}",
")",
"{",
"word",
"=",
"String",
"(",
"word",
"||",
"\"\"",
")",
";",
"const",
"found",
"=",
"(",
"options",
".",
"caseSensitive",
"?",
"dict",
"(",
")",
"[",
"word",
"]",
":",
"dict",
"(",
"{",
"lowerCase",
":",
"true",
"}",
")",
"[",
"word",
".",
"toLowerCase",
"(",
")",
"]",
")",
";",
"return",
"found",
"?",
"found",
".",
"split",
"(",
"\",\"",
")",
":",
"[",
"]",
";",
"}"
]
| Get correct words from misspelling.
It is case-insensitive by default.
Set `caseSensitive` to `true` if you need.
@param {string} word Misspelled word.
@param {Object} options Options.
@param {Boolean} [options.caseSensitive=false]
If `true`, do case-sensitive search.
@return {string[]} An array of correct words.
If there are no correct words for `word`, returns an empty array. | [
"Get",
"correct",
"words",
"from",
"misspelling",
"."
]
| 9281c7400348f69ba86af0567571d210253e246a | https://github.com/io-monad/misspellings/blob/9281c7400348f69ba86af0567571d210253e246a/src/misspellings.js#L91-L98 |
46,135 | io-monad/misspellings | src/misspellings.js | correct | function correct(str, options, callback) {
if (typeof options === "function") {
callback = options;
options = {};
}
const {caseSensitive, overrideCases} = options || {};
str = String(str || "");
const dic = dict({ lowerCase: true });
const re = regexp(caseSensitive ? "g" : "ig");
return str.replace(re, (misspell) => {
const csv = dic[misspell.toLowerCase()];
if (!csv) return misspell;
const corrects = csv.split(",");
let corrected;
if (callback) {
corrected = callback(misspell, corrects);
if (typeof corrected === "undefined" || corrected === null) return misspell;
corrected = String(corrected);
} else {
corrected = corrects[0];
}
if (!overrideCases) {
corrected = mapCases(misspell, corrected);
}
return corrected;
});
} | javascript | function correct(str, options, callback) {
if (typeof options === "function") {
callback = options;
options = {};
}
const {caseSensitive, overrideCases} = options || {};
str = String(str || "");
const dic = dict({ lowerCase: true });
const re = regexp(caseSensitive ? "g" : "ig");
return str.replace(re, (misspell) => {
const csv = dic[misspell.toLowerCase()];
if (!csv) return misspell;
const corrects = csv.split(",");
let corrected;
if (callback) {
corrected = callback(misspell, corrects);
if (typeof corrected === "undefined" || corrected === null) return misspell;
corrected = String(corrected);
} else {
corrected = corrects[0];
}
if (!overrideCases) {
corrected = mapCases(misspell, corrected);
}
return corrected;
});
} | [
"function",
"correct",
"(",
"str",
",",
"options",
",",
"callback",
")",
"{",
"if",
"(",
"typeof",
"options",
"===",
"\"function\"",
")",
"{",
"callback",
"=",
"options",
";",
"options",
"=",
"{",
"}",
";",
"}",
"const",
"{",
"caseSensitive",
",",
"overrideCases",
"}",
"=",
"options",
"||",
"{",
"}",
";",
"str",
"=",
"String",
"(",
"str",
"||",
"\"\"",
")",
";",
"const",
"dic",
"=",
"dict",
"(",
"{",
"lowerCase",
":",
"true",
"}",
")",
";",
"const",
"re",
"=",
"regexp",
"(",
"caseSensitive",
"?",
"\"g\"",
":",
"\"ig\"",
")",
";",
"return",
"str",
".",
"replace",
"(",
"re",
",",
"(",
"misspell",
")",
"=>",
"{",
"const",
"csv",
"=",
"dic",
"[",
"misspell",
".",
"toLowerCase",
"(",
")",
"]",
";",
"if",
"(",
"!",
"csv",
")",
"return",
"misspell",
";",
"const",
"corrects",
"=",
"csv",
".",
"split",
"(",
"\",\"",
")",
";",
"let",
"corrected",
";",
"if",
"(",
"callback",
")",
"{",
"corrected",
"=",
"callback",
"(",
"misspell",
",",
"corrects",
")",
";",
"if",
"(",
"typeof",
"corrected",
"===",
"\"undefined\"",
"||",
"corrected",
"===",
"null",
")",
"return",
"misspell",
";",
"corrected",
"=",
"String",
"(",
"corrected",
")",
";",
"}",
"else",
"{",
"corrected",
"=",
"corrects",
"[",
"0",
"]",
";",
"}",
"if",
"(",
"!",
"overrideCases",
")",
"{",
"corrected",
"=",
"mapCases",
"(",
"misspell",
",",
"corrected",
")",
";",
"}",
"return",
"corrected",
";",
"}",
")",
";",
"}"
]
| Correct all misspellings in a string.
It is case-insensitive by default, but it tries to keep cases
(upper to upper, lower to lower) after misspellings corrected.
You can skip options and call in `correct(str, callback)` form.
@param {string} str A target string.
@param {Object} [options] Options.
@param {Boolean} [options.caseSensitive=false]
If `true`, do case-sensitive search for misspellings.
@param {Boolean} [options.overrideCases=false]
If `true`, skip mapping cases and always use an exact word
in the dictionary.
@param {correct~correctCallback} [callback]
A callback function to be called each time misspellings found.
@return {string}
Corrected string | [
"Correct",
"all",
"misspellings",
"in",
"a",
"string",
"."
]
| 9281c7400348f69ba86af0567571d210253e246a | https://github.com/io-monad/misspellings/blob/9281c7400348f69ba86af0567571d210253e246a/src/misspellings.js#L120-L150 |
46,136 | THEjoezack/BoxPusher | public/js-roguelike-skeleton/src/renderer.js | Renderer | function Renderer(game, width, height, tileSize, canvasClassName) {
this.layers = [];
this.game = game;
this.canvas = document.createElement('canvas');
this.ctx = this.canvas.getContext('2d');
this.canvas.className = canvasClassName || 'renderer';
this.buffer = this.canvas.cloneNode();
this.bufferCtx = this.buffer.getContext('2d');
this.tileSize = tileSize || this.tileSize;
this.resize(width, height);
} | javascript | function Renderer(game, width, height, tileSize, canvasClassName) {
this.layers = [];
this.game = game;
this.canvas = document.createElement('canvas');
this.ctx = this.canvas.getContext('2d');
this.canvas.className = canvasClassName || 'renderer';
this.buffer = this.canvas.cloneNode();
this.bufferCtx = this.buffer.getContext('2d');
this.tileSize = tileSize || this.tileSize;
this.resize(width, height);
} | [
"function",
"Renderer",
"(",
"game",
",",
"width",
",",
"height",
",",
"tileSize",
",",
"canvasClassName",
")",
"{",
"this",
".",
"layers",
"=",
"[",
"]",
";",
"this",
".",
"game",
"=",
"game",
";",
"this",
".",
"canvas",
"=",
"document",
".",
"createElement",
"(",
"'canvas'",
")",
";",
"this",
".",
"ctx",
"=",
"this",
".",
"canvas",
".",
"getContext",
"(",
"'2d'",
")",
";",
"this",
".",
"canvas",
".",
"className",
"=",
"canvasClassName",
"||",
"'renderer'",
";",
"this",
".",
"buffer",
"=",
"this",
".",
"canvas",
".",
"cloneNode",
"(",
")",
";",
"this",
".",
"bufferCtx",
"=",
"this",
".",
"buffer",
".",
"getContext",
"(",
"'2d'",
")",
";",
"this",
".",
"tileSize",
"=",
"tileSize",
"||",
"this",
".",
"tileSize",
";",
"this",
".",
"resize",
"(",
"width",
",",
"height",
")",
";",
"}"
]
| Renders the current game state using html5 canvas.
@class Renderer
@constructor
@param {Game} game - Game instance this obj is attached to.
@param {Number} width - Width of the map view in tiles.
@param {Number} height - Height of the map view in tiles.
@param {Number} tileSize - Width and height of tiles when drawn.
@param {String} [canvasClassName='renderer'] - Css class name for the canvas element. | [
"Renders",
"the",
"current",
"game",
"state",
"using",
"html5",
"canvas",
"."
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/js-roguelike-skeleton/src/renderer.js#L14-L25 |
46,137 | THEjoezack/BoxPusher | public/js-roguelike-skeleton/src/renderer.js | function(x, y, tileData, ctx) {
ctx = ctx || this.bufferCtx;
var originalX = x,
originalY = y;
x -= this.originX;
y -= this.originY;
if(tileData.bgColor){
ctx.fillStyle = tileData.bgColor;
ctx.fillRect(
x * this.tileSize,
y * this.tileSize,
this.tileSize,
this.tileSize
);
}
if(tileData.before !== void 0){
this.drawTileToCanvas(originalX, originalY, tileData.before, ctx);
}
if(tileData.char && tileData.color){
if(tileData.mask){
ctx.save();
ctx.beginPath();
ctx.rect(
x * this.tileSize,
y * this.tileSize,
this.tileSize,
this.tileSize
);
ctx.clip();
ctx.closePath();
}
var fontSize = tileData.fontSize || this.tileSize;
var textX = x * (this.tileSize) + (this.tileSize * 0.5) + (tileData.offsetX || 0);
var textY = y * (this.tileSize) + (this.tileSize * 0.5) + (tileData.offsetY || 0);
ctx.fillStyle = tileData.color;
ctx.textAlign = tileData.textAlign || 'center';
ctx.textBaseline = tileData.textBaseline || 'middle';
ctx.font = fontSize + 'px ' + (tileData.font || this.font);
if(tileData.charStrokeColor){
ctx.strokeStyle = tileData.charStrokeColor;
ctx.lineWidth = tileData.charStrokeWidth || 1;
ctx.strokeText(
tileData.char,
textX,
textY
);
ctx.strokeText(
tileData.char,
textX,
textY+1
);
}
ctx.fillText(
tileData.char,
textX,
textY
);
if(tileData.mask){
ctx.restore();
}
}
if(tileData.after !== void 0){
this.drawTileToCanvas(originalX, originalY, tileData.after, ctx);
}
if(tileData.borderColor){
var borderWidth = tileData.borderWidth || 1;
var borderOffset = Math.floor(borderWidth * 0.5);
var borderRectSize = this.tileSize - borderWidth;
if(borderWidth % 2 !== 0){
borderOffset += 0.5;
}
ctx.lineWidth = borderWidth;
ctx.strokeStyle = tileData.borderColor;
var bx = x * this.tileSize + borderOffset;
var by = y * this.tileSize + borderOffset;
ctx.strokeRect(bx, by, borderRectSize, borderRectSize);
}
} | javascript | function(x, y, tileData, ctx) {
ctx = ctx || this.bufferCtx;
var originalX = x,
originalY = y;
x -= this.originX;
y -= this.originY;
if(tileData.bgColor){
ctx.fillStyle = tileData.bgColor;
ctx.fillRect(
x * this.tileSize,
y * this.tileSize,
this.tileSize,
this.tileSize
);
}
if(tileData.before !== void 0){
this.drawTileToCanvas(originalX, originalY, tileData.before, ctx);
}
if(tileData.char && tileData.color){
if(tileData.mask){
ctx.save();
ctx.beginPath();
ctx.rect(
x * this.tileSize,
y * this.tileSize,
this.tileSize,
this.tileSize
);
ctx.clip();
ctx.closePath();
}
var fontSize = tileData.fontSize || this.tileSize;
var textX = x * (this.tileSize) + (this.tileSize * 0.5) + (tileData.offsetX || 0);
var textY = y * (this.tileSize) + (this.tileSize * 0.5) + (tileData.offsetY || 0);
ctx.fillStyle = tileData.color;
ctx.textAlign = tileData.textAlign || 'center';
ctx.textBaseline = tileData.textBaseline || 'middle';
ctx.font = fontSize + 'px ' + (tileData.font || this.font);
if(tileData.charStrokeColor){
ctx.strokeStyle = tileData.charStrokeColor;
ctx.lineWidth = tileData.charStrokeWidth || 1;
ctx.strokeText(
tileData.char,
textX,
textY
);
ctx.strokeText(
tileData.char,
textX,
textY+1
);
}
ctx.fillText(
tileData.char,
textX,
textY
);
if(tileData.mask){
ctx.restore();
}
}
if(tileData.after !== void 0){
this.drawTileToCanvas(originalX, originalY, tileData.after, ctx);
}
if(tileData.borderColor){
var borderWidth = tileData.borderWidth || 1;
var borderOffset = Math.floor(borderWidth * 0.5);
var borderRectSize = this.tileSize - borderWidth;
if(borderWidth % 2 !== 0){
borderOffset += 0.5;
}
ctx.lineWidth = borderWidth;
ctx.strokeStyle = tileData.borderColor;
var bx = x * this.tileSize + borderOffset;
var by = y * this.tileSize + borderOffset;
ctx.strokeRect(bx, by, borderRectSize, borderRectSize);
}
} | [
"function",
"(",
"x",
",",
"y",
",",
"tileData",
",",
"ctx",
")",
"{",
"ctx",
"=",
"ctx",
"||",
"this",
".",
"bufferCtx",
";",
"var",
"originalX",
"=",
"x",
",",
"originalY",
"=",
"y",
";",
"x",
"-=",
"this",
".",
"originX",
";",
"y",
"-=",
"this",
".",
"originY",
";",
"if",
"(",
"tileData",
".",
"bgColor",
")",
"{",
"ctx",
".",
"fillStyle",
"=",
"tileData",
".",
"bgColor",
";",
"ctx",
".",
"fillRect",
"(",
"x",
"*",
"this",
".",
"tileSize",
",",
"y",
"*",
"this",
".",
"tileSize",
",",
"this",
".",
"tileSize",
",",
"this",
".",
"tileSize",
")",
";",
"}",
"if",
"(",
"tileData",
".",
"before",
"!==",
"void",
"0",
")",
"{",
"this",
".",
"drawTileToCanvas",
"(",
"originalX",
",",
"originalY",
",",
"tileData",
".",
"before",
",",
"ctx",
")",
";",
"}",
"if",
"(",
"tileData",
".",
"char",
"&&",
"tileData",
".",
"color",
")",
"{",
"if",
"(",
"tileData",
".",
"mask",
")",
"{",
"ctx",
".",
"save",
"(",
")",
";",
"ctx",
".",
"beginPath",
"(",
")",
";",
"ctx",
".",
"rect",
"(",
"x",
"*",
"this",
".",
"tileSize",
",",
"y",
"*",
"this",
".",
"tileSize",
",",
"this",
".",
"tileSize",
",",
"this",
".",
"tileSize",
")",
";",
"ctx",
".",
"clip",
"(",
")",
";",
"ctx",
".",
"closePath",
"(",
")",
";",
"}",
"var",
"fontSize",
"=",
"tileData",
".",
"fontSize",
"||",
"this",
".",
"tileSize",
";",
"var",
"textX",
"=",
"x",
"*",
"(",
"this",
".",
"tileSize",
")",
"+",
"(",
"this",
".",
"tileSize",
"*",
"0.5",
")",
"+",
"(",
"tileData",
".",
"offsetX",
"||",
"0",
")",
";",
"var",
"textY",
"=",
"y",
"*",
"(",
"this",
".",
"tileSize",
")",
"+",
"(",
"this",
".",
"tileSize",
"*",
"0.5",
")",
"+",
"(",
"tileData",
".",
"offsetY",
"||",
"0",
")",
";",
"ctx",
".",
"fillStyle",
"=",
"tileData",
".",
"color",
";",
"ctx",
".",
"textAlign",
"=",
"tileData",
".",
"textAlign",
"||",
"'center'",
";",
"ctx",
".",
"textBaseline",
"=",
"tileData",
".",
"textBaseline",
"||",
"'middle'",
";",
"ctx",
".",
"font",
"=",
"fontSize",
"+",
"'px '",
"+",
"(",
"tileData",
".",
"font",
"||",
"this",
".",
"font",
")",
";",
"if",
"(",
"tileData",
".",
"charStrokeColor",
")",
"{",
"ctx",
".",
"strokeStyle",
"=",
"tileData",
".",
"charStrokeColor",
";",
"ctx",
".",
"lineWidth",
"=",
"tileData",
".",
"charStrokeWidth",
"||",
"1",
";",
"ctx",
".",
"strokeText",
"(",
"tileData",
".",
"char",
",",
"textX",
",",
"textY",
")",
";",
"ctx",
".",
"strokeText",
"(",
"tileData",
".",
"char",
",",
"textX",
",",
"textY",
"+",
"1",
")",
";",
"}",
"ctx",
".",
"fillText",
"(",
"tileData",
".",
"char",
",",
"textX",
",",
"textY",
")",
";",
"if",
"(",
"tileData",
".",
"mask",
")",
"{",
"ctx",
".",
"restore",
"(",
")",
";",
"}",
"}",
"if",
"(",
"tileData",
".",
"after",
"!==",
"void",
"0",
")",
"{",
"this",
".",
"drawTileToCanvas",
"(",
"originalX",
",",
"originalY",
",",
"tileData",
".",
"after",
",",
"ctx",
")",
";",
"}",
"if",
"(",
"tileData",
".",
"borderColor",
")",
"{",
"var",
"borderWidth",
"=",
"tileData",
".",
"borderWidth",
"||",
"1",
";",
"var",
"borderOffset",
"=",
"Math",
".",
"floor",
"(",
"borderWidth",
"*",
"0.5",
")",
";",
"var",
"borderRectSize",
"=",
"this",
".",
"tileSize",
"-",
"borderWidth",
";",
"if",
"(",
"borderWidth",
"%",
"2",
"!==",
"0",
")",
"{",
"borderOffset",
"+=",
"0.5",
";",
"}",
"ctx",
".",
"lineWidth",
"=",
"borderWidth",
";",
"ctx",
".",
"strokeStyle",
"=",
"tileData",
".",
"borderColor",
";",
"var",
"bx",
"=",
"x",
"*",
"this",
".",
"tileSize",
"+",
"borderOffset",
";",
"var",
"by",
"=",
"y",
"*",
"this",
".",
"tileSize",
"+",
"borderOffset",
";",
"ctx",
".",
"strokeRect",
"(",
"bx",
",",
"by",
",",
"borderRectSize",
",",
"borderRectSize",
")",
";",
"}",
"}"
]
| Draws a single tile to the map view.
@method drawTileToCanvas
@param {Number} x - Map tile coord on the x axis.
@param {Number} y - Map tile coord on the y axis.
@param {Object} tileData - Object containing tile draw settings.
@param {Object} [tileData.char] - The character to draw.
@param {Object} [tileData.color] - The color of the character displayed.
@param {Object} [tileData.bgColor] - The background color of the tile.
@param {Object} [tileData.borderColor] - The border color of the tile.
@param {Object} [tileData.borderWidth=1] - The border width of the tile.
@param {CanvasRenderingContext2D} [ctx=this.bufferCtx] - The canvas context to draw to. | [
"Draws",
"a",
"single",
"tile",
"to",
"the",
"map",
"view",
"."
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/js-roguelike-skeleton/src/renderer.js#L274-L366 |
|
46,138 | THEjoezack/BoxPusher | public/js-roguelike-skeleton/src/renderer.js | function(x, y){
var pos = this.canvas.getBoundingClientRect(),
mx = x - pos.left,
my = y - pos.top;
return this.pixelToTileCoords(mx, my);
} | javascript | function(x, y){
var pos = this.canvas.getBoundingClientRect(),
mx = x - pos.left,
my = y - pos.top;
return this.pixelToTileCoords(mx, my);
} | [
"function",
"(",
"x",
",",
"y",
")",
"{",
"var",
"pos",
"=",
"this",
".",
"canvas",
".",
"getBoundingClientRect",
"(",
")",
",",
"mx",
"=",
"x",
"-",
"pos",
".",
"left",
",",
"my",
"=",
"y",
"-",
"pos",
".",
"top",
";",
"return",
"this",
".",
"pixelToTileCoords",
"(",
"mx",
",",
"my",
")",
";",
"}"
]
| Converts mouse pixel coords to map tile coords. Mouse pixel coords must be relative to the current window.
@method mouseToTileCoords
@param {Number} x - Mouse pixel x coord.
@param {Number} y - Mouse pixel y coord.
@return {Object|False} {x: 0, y: 0} | [
"Converts",
"mouse",
"pixel",
"coords",
"to",
"map",
"tile",
"coords",
".",
"Mouse",
"pixel",
"coords",
"must",
"be",
"relative",
"to",
"the",
"current",
"window",
"."
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/js-roguelike-skeleton/src/renderer.js#L375-L380 |
|
46,139 | THEjoezack/BoxPusher | public/js-roguelike-skeleton/src/renderer.js | function(x, y){
return {
x: Math.floor(x / this.tileSize) + this.originX,
y: Math.floor(y / this.tileSize) + this.originY
};
} | javascript | function(x, y){
return {
x: Math.floor(x / this.tileSize) + this.originX,
y: Math.floor(y / this.tileSize) + this.originY
};
} | [
"function",
"(",
"x",
",",
"y",
")",
"{",
"return",
"{",
"x",
":",
"Math",
".",
"floor",
"(",
"x",
"/",
"this",
".",
"tileSize",
")",
"+",
"this",
".",
"originX",
",",
"y",
":",
"Math",
".",
"floor",
"(",
"y",
"/",
"this",
".",
"tileSize",
")",
"+",
"this",
".",
"originY",
"}",
";",
"}"
]
| Converts map view pixel coords to map tile coords. Map view pixel coords are relative to the top left of the canvas element.
@method pixelToTileCoords
@param {Number} x - Map view pixel x coord.
@param {Number} y - Map view pixel y coord.
@return {Object|False} {x: 0, y: 0} | [
"Converts",
"map",
"view",
"pixel",
"coords",
"to",
"map",
"tile",
"coords",
".",
"Map",
"view",
"pixel",
"coords",
"are",
"relative",
"to",
"the",
"top",
"left",
"of",
"the",
"canvas",
"element",
"."
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/js-roguelike-skeleton/src/renderer.js#L389-L394 |
|
46,140 | THEjoezack/BoxPusher | public/js-roguelike-skeleton/src/renderer.js | function(color, ctx){
ctx = ctx || this.bufferCtx;
ctx.fillStyle = color || this.bgColor;
ctx.fillRect(
0,
0,
this.canvas.width,
this.canvas.height
);
} | javascript | function(color, ctx){
ctx = ctx || this.bufferCtx;
ctx.fillStyle = color || this.bgColor;
ctx.fillRect(
0,
0,
this.canvas.width,
this.canvas.height
);
} | [
"function",
"(",
"color",
",",
"ctx",
")",
"{",
"ctx",
"=",
"ctx",
"||",
"this",
".",
"bufferCtx",
";",
"ctx",
".",
"fillStyle",
"=",
"color",
"||",
"this",
".",
"bgColor",
";",
"ctx",
".",
"fillRect",
"(",
"0",
",",
"0",
",",
"this",
".",
"canvas",
".",
"width",
",",
"this",
".",
"canvas",
".",
"height",
")",
";",
"}"
]
| Fills the canvas with a given color.
@method fillBg
@param {String} [color=this.bgColor]
@param {CanvasRenderingContext2D} [ctx=this.bufferCtx] | [
"Fills",
"the",
"canvas",
"with",
"a",
"given",
"color",
"."
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/js-roguelike-skeleton/src/renderer.js#L414-L423 |
|
46,141 | THEjoezack/BoxPusher | public/js-roguelike-skeleton/src/array-2d.js | function(width, height) {
this.width = width;
this.height = height;
for (var i = 0; i < this.width; i++) {
if(!this.data){
this.data = [];
}
if(this.data[i] === void 0){
this.data[i] = [];
}
}
} | javascript | function(width, height) {
this.width = width;
this.height = height;
for (var i = 0; i < this.width; i++) {
if(!this.data){
this.data = [];
}
if(this.data[i] === void 0){
this.data[i] = [];
}
}
} | [
"function",
"(",
"width",
",",
"height",
")",
"{",
"this",
".",
"width",
"=",
"width",
";",
"this",
".",
"height",
"=",
"height",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"width",
";",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"this",
".",
"data",
")",
"{",
"this",
".",
"data",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"this",
".",
"data",
"[",
"i",
"]",
"===",
"void",
"0",
")",
"{",
"this",
".",
"data",
"[",
"i",
"]",
"=",
"[",
"]",
";",
"}",
"}",
"}"
]
| Updates the size of this Array2d without destroying data.
@method setSize
@param {Number} width - The new width.
@param {Number} height - The new height. | [
"Updates",
"the",
"size",
"of",
"this",
"Array2d",
"without",
"destroying",
"data",
"."
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/js-roguelike-skeleton/src/array-2d.js#L61-L73 |
|
46,142 | THEjoezack/BoxPusher | public/js-roguelike-skeleton/src/array-2d.js | function(x, y, settings) {
settings = settings || {};
var filter = settings.filter !== void 0 ? settings.filter : false,
withCoords = settings.withCoords !== void 0 ? settings.withCoords : false,
withDiagonals = settings.withDiagonals !== void 0 ? settings.withDiagonals : true;
var _this = this,
out = [],
ax, ay;
var add = function(x, y) {
var val = _this.get(x, y);
if (filter === false || (filter(val, x, y))) {
if (withCoords) {
out.push({
x: x,
y: y,
value: val
});
} else {
out.push(val);
}
}
};
// top
ax = x;
ay = y - 1;
add(ax, ay);
// bottom
ax = x;
ay = y + 1;
add(ax, ay);
// left
ax = x - 1;
ay = y;
add(ax, ay);
// right
ax = x + 1;
ay = y;
add(ax, ay);
if(withDiagonals){
// top left
ax = x - 1;
ay = y - 1;
add(ax, ay);
// top right
ax = x + 1;
ay = y - 1;
add(ax, ay);
// bottom left
ax = x - 1;
ay = y + 1;
add(ax, ay);
// bottom right
ax = x + 1;
ay = y + 1;
add(ax, ay);
}
return out;
} | javascript | function(x, y, settings) {
settings = settings || {};
var filter = settings.filter !== void 0 ? settings.filter : false,
withCoords = settings.withCoords !== void 0 ? settings.withCoords : false,
withDiagonals = settings.withDiagonals !== void 0 ? settings.withDiagonals : true;
var _this = this,
out = [],
ax, ay;
var add = function(x, y) {
var val = _this.get(x, y);
if (filter === false || (filter(val, x, y))) {
if (withCoords) {
out.push({
x: x,
y: y,
value: val
});
} else {
out.push(val);
}
}
};
// top
ax = x;
ay = y - 1;
add(ax, ay);
// bottom
ax = x;
ay = y + 1;
add(ax, ay);
// left
ax = x - 1;
ay = y;
add(ax, ay);
// right
ax = x + 1;
ay = y;
add(ax, ay);
if(withDiagonals){
// top left
ax = x - 1;
ay = y - 1;
add(ax, ay);
// top right
ax = x + 1;
ay = y - 1;
add(ax, ay);
// bottom left
ax = x - 1;
ay = y + 1;
add(ax, ay);
// bottom right
ax = x + 1;
ay = y + 1;
add(ax, ay);
}
return out;
} | [
"function",
"(",
"x",
",",
"y",
",",
"settings",
")",
"{",
"settings",
"=",
"settings",
"||",
"{",
"}",
";",
"var",
"filter",
"=",
"settings",
".",
"filter",
"!==",
"void",
"0",
"?",
"settings",
".",
"filter",
":",
"false",
",",
"withCoords",
"=",
"settings",
".",
"withCoords",
"!==",
"void",
"0",
"?",
"settings",
".",
"withCoords",
":",
"false",
",",
"withDiagonals",
"=",
"settings",
".",
"withDiagonals",
"!==",
"void",
"0",
"?",
"settings",
".",
"withDiagonals",
":",
"true",
";",
"var",
"_this",
"=",
"this",
",",
"out",
"=",
"[",
"]",
",",
"ax",
",",
"ay",
";",
"var",
"add",
"=",
"function",
"(",
"x",
",",
"y",
")",
"{",
"var",
"val",
"=",
"_this",
".",
"get",
"(",
"x",
",",
"y",
")",
";",
"if",
"(",
"filter",
"===",
"false",
"||",
"(",
"filter",
"(",
"val",
",",
"x",
",",
"y",
")",
")",
")",
"{",
"if",
"(",
"withCoords",
")",
"{",
"out",
".",
"push",
"(",
"{",
"x",
":",
"x",
",",
"y",
":",
"y",
",",
"value",
":",
"val",
"}",
")",
";",
"}",
"else",
"{",
"out",
".",
"push",
"(",
"val",
")",
";",
"}",
"}",
"}",
";",
"// top",
"ax",
"=",
"x",
";",
"ay",
"=",
"y",
"-",
"1",
";",
"add",
"(",
"ax",
",",
"ay",
")",
";",
"// bottom",
"ax",
"=",
"x",
";",
"ay",
"=",
"y",
"+",
"1",
";",
"add",
"(",
"ax",
",",
"ay",
")",
";",
"// left",
"ax",
"=",
"x",
"-",
"1",
";",
"ay",
"=",
"y",
";",
"add",
"(",
"ax",
",",
"ay",
")",
";",
"// right",
"ax",
"=",
"x",
"+",
"1",
";",
"ay",
"=",
"y",
";",
"add",
"(",
"ax",
",",
"ay",
")",
";",
"if",
"(",
"withDiagonals",
")",
"{",
"// top left",
"ax",
"=",
"x",
"-",
"1",
";",
"ay",
"=",
"y",
"-",
"1",
";",
"add",
"(",
"ax",
",",
"ay",
")",
";",
"// top right",
"ax",
"=",
"x",
"+",
"1",
";",
"ay",
"=",
"y",
"-",
"1",
";",
"add",
"(",
"ax",
",",
"ay",
")",
";",
"// bottom left",
"ax",
"=",
"x",
"-",
"1",
";",
"ay",
"=",
"y",
"+",
"1",
";",
"add",
"(",
"ax",
",",
"ay",
")",
";",
"// bottom right",
"ax",
"=",
"x",
"+",
"1",
";",
"ay",
"=",
"y",
"+",
"1",
";",
"add",
"(",
"ax",
",",
"ay",
")",
";",
"}",
"return",
"out",
";",
"}"
]
| Retrieves an array of values of adjacent coords.
@method getAdjacent
@param {Number} x - Map tile x coord to get adjacent values of.
@param {Number} y - Map tile y coord to get adjacent values of.
@param {Object} [settings] -
@param {Bool} [settings.withCoords=false] - If true the returned array will include the coords of each value ([{x: 0, y: 0, value: 1}, ...])
@param {Bool} [settings.withDiagonals=true] - If true diagonals will be included.
@param {Function} [settings.filter=false] - A function to filter the values returned (function(value, x, y){ return true;})
@return {Array} An array of adjacent coord values. | [
"Retrieves",
"an",
"array",
"of",
"values",
"of",
"adjacent",
"coords",
"."
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/js-roguelike-skeleton/src/array-2d.js#L124-L192 |
|
46,143 | THEjoezack/BoxPusher | public/js-roguelike-skeleton/src/array-2d.js | function(x, y, settings) {
settings = settings || {};
var radius = settings.radius || 1,
filter = settings.filter || false,
withCoords = settings.withCoords || false,
includeTarget = settings.includeTarget || false;
var tileX = x,
tileY = y;
var minX = tileX - radius,
maxX = tileX + radius,
minY = tileY - radius,
maxY = tileY + radius,
output = [],
val;
if (minX < 0) {
minX = 0;
}
if (minY < 0) {
minY = 0;
}
if (maxX > this.width - 1) {
maxX = this.width - 1;
}
if (maxY > this.height - 1) {
maxY = this.height - 1;
}
for (x = minX; x <= maxX; x++) {
for (y = minY; y <= maxY; y++) {
if (!includeTarget && tileX === x && tileY === y) {
continue;
}
val = this.data[x][y];
if (filter === false || filter(val, x, y)) {
if (withCoords) {
output.push({
x: x,
y: y,
value: val
});
} else {
output.push(val);
}
}
}
}
return output;
} | javascript | function(x, y, settings) {
settings = settings || {};
var radius = settings.radius || 1,
filter = settings.filter || false,
withCoords = settings.withCoords || false,
includeTarget = settings.includeTarget || false;
var tileX = x,
tileY = y;
var minX = tileX - radius,
maxX = tileX + radius,
minY = tileY - radius,
maxY = tileY + radius,
output = [],
val;
if (minX < 0) {
minX = 0;
}
if (minY < 0) {
minY = 0;
}
if (maxX > this.width - 1) {
maxX = this.width - 1;
}
if (maxY > this.height - 1) {
maxY = this.height - 1;
}
for (x = minX; x <= maxX; x++) {
for (y = minY; y <= maxY; y++) {
if (!includeTarget && tileX === x && tileY === y) {
continue;
}
val = this.data[x][y];
if (filter === false || filter(val, x, y)) {
if (withCoords) {
output.push({
x: x,
y: y,
value: val
});
} else {
output.push(val);
}
}
}
}
return output;
} | [
"function",
"(",
"x",
",",
"y",
",",
"settings",
")",
"{",
"settings",
"=",
"settings",
"||",
"{",
"}",
";",
"var",
"radius",
"=",
"settings",
".",
"radius",
"||",
"1",
",",
"filter",
"=",
"settings",
".",
"filter",
"||",
"false",
",",
"withCoords",
"=",
"settings",
".",
"withCoords",
"||",
"false",
",",
"includeTarget",
"=",
"settings",
".",
"includeTarget",
"||",
"false",
";",
"var",
"tileX",
"=",
"x",
",",
"tileY",
"=",
"y",
";",
"var",
"minX",
"=",
"tileX",
"-",
"radius",
",",
"maxX",
"=",
"tileX",
"+",
"radius",
",",
"minY",
"=",
"tileY",
"-",
"radius",
",",
"maxY",
"=",
"tileY",
"+",
"radius",
",",
"output",
"=",
"[",
"]",
",",
"val",
";",
"if",
"(",
"minX",
"<",
"0",
")",
"{",
"minX",
"=",
"0",
";",
"}",
"if",
"(",
"minY",
"<",
"0",
")",
"{",
"minY",
"=",
"0",
";",
"}",
"if",
"(",
"maxX",
">",
"this",
".",
"width",
"-",
"1",
")",
"{",
"maxX",
"=",
"this",
".",
"width",
"-",
"1",
";",
"}",
"if",
"(",
"maxY",
">",
"this",
".",
"height",
"-",
"1",
")",
"{",
"maxY",
"=",
"this",
".",
"height",
"-",
"1",
";",
"}",
"for",
"(",
"x",
"=",
"minX",
";",
"x",
"<=",
"maxX",
";",
"x",
"++",
")",
"{",
"for",
"(",
"y",
"=",
"minY",
";",
"y",
"<=",
"maxY",
";",
"y",
"++",
")",
"{",
"if",
"(",
"!",
"includeTarget",
"&&",
"tileX",
"===",
"x",
"&&",
"tileY",
"===",
"y",
")",
"{",
"continue",
";",
"}",
"val",
"=",
"this",
".",
"data",
"[",
"x",
"]",
"[",
"y",
"]",
";",
"if",
"(",
"filter",
"===",
"false",
"||",
"filter",
"(",
"val",
",",
"x",
",",
"y",
")",
")",
"{",
"if",
"(",
"withCoords",
")",
"{",
"output",
".",
"push",
"(",
"{",
"x",
":",
"x",
",",
"y",
":",
"y",
",",
"value",
":",
"val",
"}",
")",
";",
"}",
"else",
"{",
"output",
".",
"push",
"(",
"val",
")",
";",
"}",
"}",
"}",
"}",
"return",
"output",
";",
"}"
]
| Retrieves an array of values of coords within a given radius.
@method getWithinSquareRadius
@param {Number} x - Map tile x coord at the center of the radius.
@param {Number} y - Map tile x coord at the center of the radius.
@param {Object} [settings] -
@param {Number} [settings.radius=1] - Radius of the area to retrieve tiles from.
@param {Function} [settings.filter=false] - A function to filter the values returned (function(value, x, y){ return true;})
@param {Bool} [settings.withCoords=false] - If true the returned array will include the coords of each value ([{x: 0, y: 0, value: 1}, ...])
@param {Bool} [settings.includeTarget=false] - If true the value of the coordinates given will be included in the returned array.
@return {Array} An array of coord values within a square radius of the given coords. | [
"Retrieves",
"an",
"array",
"of",
"values",
"of",
"coords",
"within",
"a",
"given",
"radius",
"."
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/js-roguelike-skeleton/src/array-2d.js#L206-L256 |
|
46,144 | THEjoezack/BoxPusher | public/js-roguelike-skeleton/src/array-2d.js | function(x0, y0, x1, y1, condition, withCoords) {
withCoords = withCoords || false;
condition = condition || false;
var output = [],
dx = Math.abs(x1 - x0),
dy = Math.abs(y1 - y0),
sx = (x0 < x1) ? 1 : -1,
sy = (y0 < y1) ? 1 : -1,
err = dx - dy,
e2, val;
while (true) {
if (x0 < 0 || x0 >= this.width || y0 < 0 || y0 >= this.height) {
break;
}
val = this.get(x0, y0);
if (withCoords) {
output.push({
x: x0,
y: y0,
value: val
});
} else {
output.push(val);
}
if (condition !== false && condition(val, x0, y0)) {
break;
}
e2 = 2 * err;
if (e2 > -dy) {
err -= dy;
x0 += sx;
}
if (e2 < dx) {
err += dx;
y0 += sy;
}
}
return output;
} | javascript | function(x0, y0, x1, y1, condition, withCoords) {
withCoords = withCoords || false;
condition = condition || false;
var output = [],
dx = Math.abs(x1 - x0),
dy = Math.abs(y1 - y0),
sx = (x0 < x1) ? 1 : -1,
sy = (y0 < y1) ? 1 : -1,
err = dx - dy,
e2, val;
while (true) {
if (x0 < 0 || x0 >= this.width || y0 < 0 || y0 >= this.height) {
break;
}
val = this.get(x0, y0);
if (withCoords) {
output.push({
x: x0,
y: y0,
value: val
});
} else {
output.push(val);
}
if (condition !== false && condition(val, x0, y0)) {
break;
}
e2 = 2 * err;
if (e2 > -dy) {
err -= dy;
x0 += sx;
}
if (e2 < dx) {
err += dx;
y0 += sy;
}
}
return output;
} | [
"function",
"(",
"x0",
",",
"y0",
",",
"x1",
",",
"y1",
",",
"condition",
",",
"withCoords",
")",
"{",
"withCoords",
"=",
"withCoords",
"||",
"false",
";",
"condition",
"=",
"condition",
"||",
"false",
";",
"var",
"output",
"=",
"[",
"]",
",",
"dx",
"=",
"Math",
".",
"abs",
"(",
"x1",
"-",
"x0",
")",
",",
"dy",
"=",
"Math",
".",
"abs",
"(",
"y1",
"-",
"y0",
")",
",",
"sx",
"=",
"(",
"x0",
"<",
"x1",
")",
"?",
"1",
":",
"-",
"1",
",",
"sy",
"=",
"(",
"y0",
"<",
"y1",
")",
"?",
"1",
":",
"-",
"1",
",",
"err",
"=",
"dx",
"-",
"dy",
",",
"e2",
",",
"val",
";",
"while",
"(",
"true",
")",
"{",
"if",
"(",
"x0",
"<",
"0",
"||",
"x0",
">=",
"this",
".",
"width",
"||",
"y0",
"<",
"0",
"||",
"y0",
">=",
"this",
".",
"height",
")",
"{",
"break",
";",
"}",
"val",
"=",
"this",
".",
"get",
"(",
"x0",
",",
"y0",
")",
";",
"if",
"(",
"withCoords",
")",
"{",
"output",
".",
"push",
"(",
"{",
"x",
":",
"x0",
",",
"y",
":",
"y0",
",",
"value",
":",
"val",
"}",
")",
";",
"}",
"else",
"{",
"output",
".",
"push",
"(",
"val",
")",
";",
"}",
"if",
"(",
"condition",
"!==",
"false",
"&&",
"condition",
"(",
"val",
",",
"x0",
",",
"y0",
")",
")",
"{",
"break",
";",
"}",
"e2",
"=",
"2",
"*",
"err",
";",
"if",
"(",
"e2",
">",
"-",
"dy",
")",
"{",
"err",
"-=",
"dy",
";",
"x0",
"+=",
"sx",
";",
"}",
"if",
"(",
"e2",
"<",
"dx",
")",
"{",
"err",
"+=",
"dx",
";",
"y0",
"+=",
"sy",
";",
"}",
"}",
"return",
"output",
";",
"}"
]
| Retrieves an array of values of coords along a line starting at point 0 and crossing point 1 until it hits the edge of the 2d array or a coord value returning true when passed to the condtion function.
@method getLineThrough
@param {Number} x0 - Map tile x coord of start.
@param {Number} y0 - Map tile y coord of start.
@param {Number} x1 - Map tile x coord of crossing.
@param {Number} y1 - Map tile y coord of crossing.
@param {Function} [condition=false] - A function to determine when to end the line. A coord value returning true when passed to the function will end the line. (function(value, x, y){ return true;})
@param {Bool} [withCoords=false] - If true the returned array will include the coords of each value ([{x: 0, y: 0, value: 1}, ...])
@return {Array} An array of coord values. | [
"Retrieves",
"an",
"array",
"of",
"values",
"of",
"coords",
"along",
"a",
"line",
"starting",
"at",
"point",
"0",
"and",
"crossing",
"point",
"1",
"until",
"it",
"hits",
"the",
"edge",
"of",
"the",
"2d",
"array",
"or",
"a",
"coord",
"value",
"returning",
"true",
"when",
"passed",
"to",
"the",
"condtion",
"function",
"."
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/js-roguelike-skeleton/src/array-2d.js#L269-L311 |
|
46,145 | THEjoezack/BoxPusher | public/js-roguelike-skeleton/src/array-2d.js | function(startX, startY, settings) {
settings = settings || {};
var maxRadius = settings.maxRadius || 1,
filter = settings.filter || false,
withCoords = settings.withCoords || false;
var currentDistance = 1,
results = [],
x, y;
var checkVal = function(val, x, y) {
var result;
if ((filter && filter(val, x, y)) || (!filter && val)) {
if (withCoords) {
results.push({
x: x,
y: y,
value: val
});
} else {
return results.push(val);
}
}
};
while (currentDistance <= maxRadius) {
var minX = startX - currentDistance,
maxX = startX + currentDistance,
minY = startY - currentDistance,
maxY = startY + currentDistance,
len = currentDistance * 2 + 1;
for (var i = len - 1; i >= 0; i--) {
var val;
// top and bottom edges skip first and last coords to prevent double checking
if (i < len - 1 && i > 0) {
// top edge
if (minY >= 0) {
x = minX + i;
y = minY;
val = this.get(x, y);
checkVal(val, x, y);
}
if (maxY < this.height) {
// bottom edge
x = minX + i;
y = maxY;
val = this.get(x, y);
checkVal(val, x, y);
}
}
if (minX >= 0) {
// left edge
x = minX;
y = minY + i;
val = this.get(x, y);
checkVal(val, x, y);
}
if (maxX < this.width) {
// right edge
x = maxX;
y = minY + i;
val = this.get(x, y);
checkVal(val, x, y);
}
}
if (results.length) {
return results;
}
currentDistance++;
}
return false;
} | javascript | function(startX, startY, settings) {
settings = settings || {};
var maxRadius = settings.maxRadius || 1,
filter = settings.filter || false,
withCoords = settings.withCoords || false;
var currentDistance = 1,
results = [],
x, y;
var checkVal = function(val, x, y) {
var result;
if ((filter && filter(val, x, y)) || (!filter && val)) {
if (withCoords) {
results.push({
x: x,
y: y,
value: val
});
} else {
return results.push(val);
}
}
};
while (currentDistance <= maxRadius) {
var minX = startX - currentDistance,
maxX = startX + currentDistance,
minY = startY - currentDistance,
maxY = startY + currentDistance,
len = currentDistance * 2 + 1;
for (var i = len - 1; i >= 0; i--) {
var val;
// top and bottom edges skip first and last coords to prevent double checking
if (i < len - 1 && i > 0) {
// top edge
if (minY >= 0) {
x = minX + i;
y = minY;
val = this.get(x, y);
checkVal(val, x, y);
}
if (maxY < this.height) {
// bottom edge
x = minX + i;
y = maxY;
val = this.get(x, y);
checkVal(val, x, y);
}
}
if (minX >= 0) {
// left edge
x = minX;
y = minY + i;
val = this.get(x, y);
checkVal(val, x, y);
}
if (maxX < this.width) {
// right edge
x = maxX;
y = minY + i;
val = this.get(x, y);
checkVal(val, x, y);
}
}
if (results.length) {
return results;
}
currentDistance++;
}
return false;
} | [
"function",
"(",
"startX",
",",
"startY",
",",
"settings",
")",
"{",
"settings",
"=",
"settings",
"||",
"{",
"}",
";",
"var",
"maxRadius",
"=",
"settings",
".",
"maxRadius",
"||",
"1",
",",
"filter",
"=",
"settings",
".",
"filter",
"||",
"false",
",",
"withCoords",
"=",
"settings",
".",
"withCoords",
"||",
"false",
";",
"var",
"currentDistance",
"=",
"1",
",",
"results",
"=",
"[",
"]",
",",
"x",
",",
"y",
";",
"var",
"checkVal",
"=",
"function",
"(",
"val",
",",
"x",
",",
"y",
")",
"{",
"var",
"result",
";",
"if",
"(",
"(",
"filter",
"&&",
"filter",
"(",
"val",
",",
"x",
",",
"y",
")",
")",
"||",
"(",
"!",
"filter",
"&&",
"val",
")",
")",
"{",
"if",
"(",
"withCoords",
")",
"{",
"results",
".",
"push",
"(",
"{",
"x",
":",
"x",
",",
"y",
":",
"y",
",",
"value",
":",
"val",
"}",
")",
";",
"}",
"else",
"{",
"return",
"results",
".",
"push",
"(",
"val",
")",
";",
"}",
"}",
"}",
";",
"while",
"(",
"currentDistance",
"<=",
"maxRadius",
")",
"{",
"var",
"minX",
"=",
"startX",
"-",
"currentDistance",
",",
"maxX",
"=",
"startX",
"+",
"currentDistance",
",",
"minY",
"=",
"startY",
"-",
"currentDistance",
",",
"maxY",
"=",
"startY",
"+",
"currentDistance",
",",
"len",
"=",
"currentDistance",
"*",
"2",
"+",
"1",
";",
"for",
"(",
"var",
"i",
"=",
"len",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"var",
"val",
";",
"// top and bottom edges skip first and last coords to prevent double checking",
"if",
"(",
"i",
"<",
"len",
"-",
"1",
"&&",
"i",
">",
"0",
")",
"{",
"// top edge",
"if",
"(",
"minY",
">=",
"0",
")",
"{",
"x",
"=",
"minX",
"+",
"i",
";",
"y",
"=",
"minY",
";",
"val",
"=",
"this",
".",
"get",
"(",
"x",
",",
"y",
")",
";",
"checkVal",
"(",
"val",
",",
"x",
",",
"y",
")",
";",
"}",
"if",
"(",
"maxY",
"<",
"this",
".",
"height",
")",
"{",
"// bottom edge",
"x",
"=",
"minX",
"+",
"i",
";",
"y",
"=",
"maxY",
";",
"val",
"=",
"this",
".",
"get",
"(",
"x",
",",
"y",
")",
";",
"checkVal",
"(",
"val",
",",
"x",
",",
"y",
")",
";",
"}",
"}",
"if",
"(",
"minX",
">=",
"0",
")",
"{",
"// left edge",
"x",
"=",
"minX",
";",
"y",
"=",
"minY",
"+",
"i",
";",
"val",
"=",
"this",
".",
"get",
"(",
"x",
",",
"y",
")",
";",
"checkVal",
"(",
"val",
",",
"x",
",",
"y",
")",
";",
"}",
"if",
"(",
"maxX",
"<",
"this",
".",
"width",
")",
"{",
"// right edge",
"x",
"=",
"maxX",
";",
"y",
"=",
"minY",
"+",
"i",
";",
"val",
"=",
"this",
".",
"get",
"(",
"x",
",",
"y",
")",
";",
"checkVal",
"(",
"val",
",",
"x",
",",
"y",
")",
";",
"}",
"}",
"if",
"(",
"results",
".",
"length",
")",
"{",
"return",
"results",
";",
"}",
"currentDistance",
"++",
";",
"}",
"return",
"false",
";",
"}"
]
| Retrieves an array of the nearest coord values meeting checked requirements. If multiple coord values were matched at the same nearest distance, the returned array will contain multiple matched coord values.
Used for projecting path of ranged attacks, pushed entities, ect.
@method getNearest
@param {Number} tileX - Map tile x coord of the center of the radius.
@param {Number} tileY - Map tile x coord of the center of the radius.
@param {Object} [settings] -
@param {Number} [settings.maxRadius=1] - Maxium search radius from given coord.
@param {Function} [settings.filter=false] - A function to determine when the desired coord value is matched. A coord value returning true when passed to the function would be added to the list of results. (function(value, x, y){ return true;}) If no check function is provided any tile with a truthy value will be matched.
@param {Bool} [settings.withCoords=false] - If true the returned array will include the coords of each value ([{x: 0, y: 0, value: 1}, ...])
@return {Array} An array of coord values within a square radius of the given coords. | [
"Retrieves",
"an",
"array",
"of",
"the",
"nearest",
"coord",
"values",
"meeting",
"checked",
"requirements",
".",
"If",
"multiple",
"coord",
"values",
"were",
"matched",
"at",
"the",
"same",
"nearest",
"distance",
"the",
"returned",
"array",
"will",
"contain",
"multiple",
"matched",
"coord",
"values",
".",
"Used",
"for",
"projecting",
"path",
"of",
"ranged",
"attacks",
"pushed",
"entities",
"ect",
"."
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/js-roguelike-skeleton/src/array-2d.js#L325-L406 |
|
46,146 | THEjoezack/BoxPusher | public/js-roguelike-skeleton/src/array-2d.js | function(filter, withCoords){
withCoords = withCoords || false;
var output = [];
for (var x = 0; x < this.width; x++) {
for (var y = 0; y < this.height; y++) {
var val = this.get(x, y);
if(filter(val, x, y)){
if (withCoords) {
output.push({
x: x,
y: y,
value: val
});
} else {
output.push(val);
}
}
}
}
return output;
} | javascript | function(filter, withCoords){
withCoords = withCoords || false;
var output = [];
for (var x = 0; x < this.width; x++) {
for (var y = 0; y < this.height; y++) {
var val = this.get(x, y);
if(filter(val, x, y)){
if (withCoords) {
output.push({
x: x,
y: y,
value: val
});
} else {
output.push(val);
}
}
}
}
return output;
} | [
"function",
"(",
"filter",
",",
"withCoords",
")",
"{",
"withCoords",
"=",
"withCoords",
"||",
"false",
";",
"var",
"output",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"x",
"=",
"0",
";",
"x",
"<",
"this",
".",
"width",
";",
"x",
"++",
")",
"{",
"for",
"(",
"var",
"y",
"=",
"0",
";",
"y",
"<",
"this",
".",
"height",
";",
"y",
"++",
")",
"{",
"var",
"val",
"=",
"this",
".",
"get",
"(",
"x",
",",
"y",
")",
";",
"if",
"(",
"filter",
"(",
"val",
",",
"x",
",",
"y",
")",
")",
"{",
"if",
"(",
"withCoords",
")",
"{",
"output",
".",
"push",
"(",
"{",
"x",
":",
"x",
",",
"y",
":",
"y",
",",
"value",
":",
"val",
"}",
")",
";",
"}",
"else",
"{",
"output",
".",
"push",
"(",
"val",
")",
";",
"}",
"}",
"}",
"}",
"return",
"output",
";",
"}"
]
| Retrieves an array of the filtered values.
@method filter
@param {Function} filter - A function to determine if a value is to be included in results (returns true). (function(value, x, y){ return true;})
@param {Bool} [withCoords=false] - If true the returned array will include the coords of each value ([{x: 0, y: 0, value: 1}, ...])
@return {Array} An array of coord values matched by the filter function. | [
"Retrieves",
"an",
"array",
"of",
"the",
"filtered",
"values",
"."
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/js-roguelike-skeleton/src/array-2d.js#L415-L435 |
|
46,147 | THEjoezack/BoxPusher | public/js-roguelike-skeleton/src/array-2d.js | function(){
var newArray = new Array2d(this.width, this.height);
for(var x = this.width - 1; x >= 0; x--){
for(var y = this.height - 1; y >= 0; y--){
var val = this.get(x, y);
if(val !== void 0){
newArray.set(x, y, val);
}
}
}
return newArray;
} | javascript | function(){
var newArray = new Array2d(this.width, this.height);
for(var x = this.width - 1; x >= 0; x--){
for(var y = this.height - 1; y >= 0; y--){
var val = this.get(x, y);
if(val !== void 0){
newArray.set(x, y, val);
}
}
}
return newArray;
} | [
"function",
"(",
")",
"{",
"var",
"newArray",
"=",
"new",
"Array2d",
"(",
"this",
".",
"width",
",",
"this",
".",
"height",
")",
";",
"for",
"(",
"var",
"x",
"=",
"this",
".",
"width",
"-",
"1",
";",
"x",
">=",
"0",
";",
"x",
"--",
")",
"{",
"for",
"(",
"var",
"y",
"=",
"this",
".",
"height",
"-",
"1",
";",
"y",
">=",
"0",
";",
"y",
"--",
")",
"{",
"var",
"val",
"=",
"this",
".",
"get",
"(",
"x",
",",
"y",
")",
";",
"if",
"(",
"val",
"!==",
"void",
"0",
")",
"{",
"newArray",
".",
"set",
"(",
"x",
",",
"y",
",",
"val",
")",
";",
"}",
"}",
"}",
"return",
"newArray",
";",
"}"
]
| Creates a copy of this Array2d. Shallow copies values.
@method copy
@return {Array2d} | [
"Creates",
"a",
"copy",
"of",
"this",
"Array2d",
".",
"Shallow",
"copies",
"values",
"."
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/js-roguelike-skeleton/src/array-2d.js#L442-L453 |
|
46,148 | THEjoezack/BoxPusher | public/js-roguelike-skeleton/src/array-2d.js | function(func, context){
for(var x = this.width - 1; x >= 0; x--){
for(var y = this.height - 1; y >= 0; y--){
var val = this.get(x, y);
if(context){
func.call(context, val, x, y);
} else {
func(val, x, y);
}
}
}
} | javascript | function(func, context){
for(var x = this.width - 1; x >= 0; x--){
for(var y = this.height - 1; y >= 0; y--){
var val = this.get(x, y);
if(context){
func.call(context, val, x, y);
} else {
func(val, x, y);
}
}
}
} | [
"function",
"(",
"func",
",",
"context",
")",
"{",
"for",
"(",
"var",
"x",
"=",
"this",
".",
"width",
"-",
"1",
";",
"x",
">=",
"0",
";",
"x",
"--",
")",
"{",
"for",
"(",
"var",
"y",
"=",
"this",
".",
"height",
"-",
"1",
";",
"y",
">=",
"0",
";",
"y",
"--",
")",
"{",
"var",
"val",
"=",
"this",
".",
"get",
"(",
"x",
",",
"y",
")",
";",
"if",
"(",
"context",
")",
"{",
"func",
".",
"call",
"(",
"context",
",",
"val",
",",
"x",
",",
"y",
")",
";",
"}",
"else",
"{",
"func",
"(",
"val",
",",
"x",
",",
"y",
")",
";",
"}",
"}",
"}",
"}"
]
| Loops over each coord value.
@method each
@param {Function} func - A function to call on each coord value. (function(value, x, y){})
@param {Object} [context] - Context to call the function with (func.call(context, val, x, y))
@return {Array2d} | [
"Loops",
"over",
"each",
"coord",
"value",
"."
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/js-roguelike-skeleton/src/array-2d.js#L462-L473 |
|
46,149 | SilentCicero/solidity-to-abi | src/index.js | buildInputsArray | function buildInputsArray(rawInputsString) {
let returnArray = []; // eslint-disable-line
const rawMethodInputs = rawInputsString.split(',');
// no inputs
if (typeof rawMethodInputs === 'undefined' || rawMethodInputs.length === 0) {
return [];
}
rawMethodInputs.forEach((rawMethodInput) => {
const inputData = rawMethodInput.trim().split(' ');
const type = inputData[0];
const name = inputData[1] || '';
// if type exists
if (type !== '' && typeof type !== 'undefined') {
returnArray.push({
type,
name,
});
}
});
return returnArray;
} | javascript | function buildInputsArray(rawInputsString) {
let returnArray = []; // eslint-disable-line
const rawMethodInputs = rawInputsString.split(',');
// no inputs
if (typeof rawMethodInputs === 'undefined' || rawMethodInputs.length === 0) {
return [];
}
rawMethodInputs.forEach((rawMethodInput) => {
const inputData = rawMethodInput.trim().split(' ');
const type = inputData[0];
const name = inputData[1] || '';
// if type exists
if (type !== '' && typeof type !== 'undefined') {
returnArray.push({
type,
name,
});
}
});
return returnArray;
} | [
"function",
"buildInputsArray",
"(",
"rawInputsString",
")",
"{",
"let",
"returnArray",
"=",
"[",
"]",
";",
"// eslint-disable-line",
"const",
"rawMethodInputs",
"=",
"rawInputsString",
".",
"split",
"(",
"','",
")",
";",
"// no inputs",
"if",
"(",
"typeof",
"rawMethodInputs",
"===",
"'undefined'",
"||",
"rawMethodInputs",
".",
"length",
"===",
"0",
")",
"{",
"return",
"[",
"]",
";",
"}",
"rawMethodInputs",
".",
"forEach",
"(",
"(",
"rawMethodInput",
")",
"=>",
"{",
"const",
"inputData",
"=",
"rawMethodInput",
".",
"trim",
"(",
")",
".",
"split",
"(",
"' '",
")",
";",
"const",
"type",
"=",
"inputData",
"[",
"0",
"]",
";",
"const",
"name",
"=",
"inputData",
"[",
"1",
"]",
"||",
"''",
";",
"// if type exists",
"if",
"(",
"type",
"!==",
"''",
"&&",
"typeof",
"type",
"!==",
"'undefined'",
")",
"{",
"returnArray",
".",
"push",
"(",
"{",
"type",
",",
"name",
",",
"}",
")",
";",
"}",
"}",
")",
";",
"return",
"returnArray",
";",
"}"
]
| build inputs or outputs array from raw inputs string | [
"build",
"inputs",
"or",
"outputs",
"array",
"from",
"raw",
"inputs",
"string"
]
| 2d97d2c53a90f670ced1e010684897d9d46eb9d2 | https://github.com/SilentCicero/solidity-to-abi/blob/2d97d2c53a90f670ced1e010684897d9d46eb9d2/src/index.js#L2-L26 |
46,150 | SilentCicero/solidity-to-abi | src/index.js | solidityToABI | function solidityToABI(methodInterface) {
// count open and clsoed
const methodABIObject = {};
// not a string
if (typeof methodInterface !== 'string') {
throw new Error(`Method interface must be a string, currently ${typeof methodInterface}`);
}
// empty string
if (methodInterface.length === 0) {
throw new Error(`Solidity method interface must have a length greater than zero, currently ${methodInterface.length}`);
}
// count open brackets, closed brackets, colon count, outpouts and invalid characters
const openBrackets = (methodInterface.match(/\(/g) || []).length;
const closedBrackets = (methodInterface.match(/\)/g) || []).length;
const colonCount = (methodInterface.match(/:/g) || []).length;
const hasOutputs = openBrackets === 2 && closedBrackets === 2 && colonCount === 1;
const hasInvalidCharacters = methodInterface.replace(/([A-Za-z0-9\_\s\,\:(\)]+)/g, '').trim().length > 0; // eslint-disable-line
// invalid characters
if (hasInvalidCharacters) {
throw new Error('Invalid Solidity method interface, your method interface contains invalid chars. Only letters, numbers, spaces, commas, underscores, brackets and colons.');
}
// method ABI object assembly
methodABIObject.name = methodInterface.slice(0, methodInterface.indexOf('('));
methodABIObject.type = 'function';
methodABIObject.constant = false;
const methodInputsString = methodInterface.slice(methodInterface.indexOf('(') + 1, methodInterface.indexOf(')')).trim();
const methodOutputString = (hasOutputs && methodInterface.slice(methodInterface.lastIndexOf('(') + 1, methodInterface.lastIndexOf(')')) || '').trim();
methodABIObject.inputs = buildInputsArray(methodInputsString);
methodABIObject.outputs = buildInputsArray(methodOutputString);
// check open brackets
if (methodABIObject.name === '' || typeof methodABIObject.name === 'undefined') {
throw new Error('Invalid Solidity method interface, no method name');
}
// check open brackets
if (openBrackets !== 1 && openBrackets !== 2) {
throw new Error(`Invalid Solidity method interface, too many or too little open brackets in solidity interface, currenlty only ${openBrackets} open brackets!`);
}
// check open brackets
if (openBrackets !== 1 && openBrackets !== 2) {
throw new Error('Invalid Solidity method interface, too many or too little open brackets in solidity interface!');
}
// check closed brackets
if (closedBrackets !== 1 && closedBrackets !== 2) {
throw new Error('Invalid Solidity method interface, too many or too little closed brackets in solidity interface!');
}
// check colon count
if (colonCount !== 0 && colonCount !== 1) {
throw new Error('Invalid Solidity method interface, to many or too little colons.');
}
// return method abi object
return methodABIObject;
} | javascript | function solidityToABI(methodInterface) {
// count open and clsoed
const methodABIObject = {};
// not a string
if (typeof methodInterface !== 'string') {
throw new Error(`Method interface must be a string, currently ${typeof methodInterface}`);
}
// empty string
if (methodInterface.length === 0) {
throw new Error(`Solidity method interface must have a length greater than zero, currently ${methodInterface.length}`);
}
// count open brackets, closed brackets, colon count, outpouts and invalid characters
const openBrackets = (methodInterface.match(/\(/g) || []).length;
const closedBrackets = (methodInterface.match(/\)/g) || []).length;
const colonCount = (methodInterface.match(/:/g) || []).length;
const hasOutputs = openBrackets === 2 && closedBrackets === 2 && colonCount === 1;
const hasInvalidCharacters = methodInterface.replace(/([A-Za-z0-9\_\s\,\:(\)]+)/g, '').trim().length > 0; // eslint-disable-line
// invalid characters
if (hasInvalidCharacters) {
throw new Error('Invalid Solidity method interface, your method interface contains invalid chars. Only letters, numbers, spaces, commas, underscores, brackets and colons.');
}
// method ABI object assembly
methodABIObject.name = methodInterface.slice(0, methodInterface.indexOf('('));
methodABIObject.type = 'function';
methodABIObject.constant = false;
const methodInputsString = methodInterface.slice(methodInterface.indexOf('(') + 1, methodInterface.indexOf(')')).trim();
const methodOutputString = (hasOutputs && methodInterface.slice(methodInterface.lastIndexOf('(') + 1, methodInterface.lastIndexOf(')')) || '').trim();
methodABIObject.inputs = buildInputsArray(methodInputsString);
methodABIObject.outputs = buildInputsArray(methodOutputString);
// check open brackets
if (methodABIObject.name === '' || typeof methodABIObject.name === 'undefined') {
throw new Error('Invalid Solidity method interface, no method name');
}
// check open brackets
if (openBrackets !== 1 && openBrackets !== 2) {
throw new Error(`Invalid Solidity method interface, too many or too little open brackets in solidity interface, currenlty only ${openBrackets} open brackets!`);
}
// check open brackets
if (openBrackets !== 1 && openBrackets !== 2) {
throw new Error('Invalid Solidity method interface, too many or too little open brackets in solidity interface!');
}
// check closed brackets
if (closedBrackets !== 1 && closedBrackets !== 2) {
throw new Error('Invalid Solidity method interface, too many or too little closed brackets in solidity interface!');
}
// check colon count
if (colonCount !== 0 && colonCount !== 1) {
throw new Error('Invalid Solidity method interface, to many or too little colons.');
}
// return method abi object
return methodABIObject;
} | [
"function",
"solidityToABI",
"(",
"methodInterface",
")",
"{",
"// count open and clsoed",
"const",
"methodABIObject",
"=",
"{",
"}",
";",
"// not a string",
"if",
"(",
"typeof",
"methodInterface",
"!==",
"'string'",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"typeof",
"methodInterface",
"}",
"`",
")",
";",
"}",
"// empty string",
"if",
"(",
"methodInterface",
".",
"length",
"===",
"0",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"methodInterface",
".",
"length",
"}",
"`",
")",
";",
"}",
"// count open brackets, closed brackets, colon count, outpouts and invalid characters",
"const",
"openBrackets",
"=",
"(",
"methodInterface",
".",
"match",
"(",
"/",
"\\(",
"/",
"g",
")",
"||",
"[",
"]",
")",
".",
"length",
";",
"const",
"closedBrackets",
"=",
"(",
"methodInterface",
".",
"match",
"(",
"/",
"\\)",
"/",
"g",
")",
"||",
"[",
"]",
")",
".",
"length",
";",
"const",
"colonCount",
"=",
"(",
"methodInterface",
".",
"match",
"(",
"/",
":",
"/",
"g",
")",
"||",
"[",
"]",
")",
".",
"length",
";",
"const",
"hasOutputs",
"=",
"openBrackets",
"===",
"2",
"&&",
"closedBrackets",
"===",
"2",
"&&",
"colonCount",
"===",
"1",
";",
"const",
"hasInvalidCharacters",
"=",
"methodInterface",
".",
"replace",
"(",
"/",
"([A-Za-z0-9\\_\\s\\,\\:(\\)]+)",
"/",
"g",
",",
"''",
")",
".",
"trim",
"(",
")",
".",
"length",
">",
"0",
";",
"// eslint-disable-line",
"// invalid characters",
"if",
"(",
"hasInvalidCharacters",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Invalid Solidity method interface, your method interface contains invalid chars. Only letters, numbers, spaces, commas, underscores, brackets and colons.'",
")",
";",
"}",
"// method ABI object assembly",
"methodABIObject",
".",
"name",
"=",
"methodInterface",
".",
"slice",
"(",
"0",
",",
"methodInterface",
".",
"indexOf",
"(",
"'('",
")",
")",
";",
"methodABIObject",
".",
"type",
"=",
"'function'",
";",
"methodABIObject",
".",
"constant",
"=",
"false",
";",
"const",
"methodInputsString",
"=",
"methodInterface",
".",
"slice",
"(",
"methodInterface",
".",
"indexOf",
"(",
"'('",
")",
"+",
"1",
",",
"methodInterface",
".",
"indexOf",
"(",
"')'",
")",
")",
".",
"trim",
"(",
")",
";",
"const",
"methodOutputString",
"=",
"(",
"hasOutputs",
"&&",
"methodInterface",
".",
"slice",
"(",
"methodInterface",
".",
"lastIndexOf",
"(",
"'('",
")",
"+",
"1",
",",
"methodInterface",
".",
"lastIndexOf",
"(",
"')'",
")",
")",
"||",
"''",
")",
".",
"trim",
"(",
")",
";",
"methodABIObject",
".",
"inputs",
"=",
"buildInputsArray",
"(",
"methodInputsString",
")",
";",
"methodABIObject",
".",
"outputs",
"=",
"buildInputsArray",
"(",
"methodOutputString",
")",
";",
"// check open brackets",
"if",
"(",
"methodABIObject",
".",
"name",
"===",
"''",
"||",
"typeof",
"methodABIObject",
".",
"name",
"===",
"'undefined'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Invalid Solidity method interface, no method name'",
")",
";",
"}",
"// check open brackets",
"if",
"(",
"openBrackets",
"!==",
"1",
"&&",
"openBrackets",
"!==",
"2",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"openBrackets",
"}",
"`",
")",
";",
"}",
"// check open brackets",
"if",
"(",
"openBrackets",
"!==",
"1",
"&&",
"openBrackets",
"!==",
"2",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Invalid Solidity method interface, too many or too little open brackets in solidity interface!'",
")",
";",
"}",
"// check closed brackets",
"if",
"(",
"closedBrackets",
"!==",
"1",
"&&",
"closedBrackets",
"!==",
"2",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Invalid Solidity method interface, too many or too little closed brackets in solidity interface!'",
")",
";",
"}",
"// check colon count",
"if",
"(",
"colonCount",
"!==",
"0",
"&&",
"colonCount",
"!==",
"1",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Invalid Solidity method interface, to many or too little colons.'",
")",
";",
"}",
"// return method abi object",
"return",
"methodABIObject",
";",
"}"
]
| parse a solidity method interface | [
"parse",
"a",
"solidity",
"method",
"interface"
]
| 2d97d2c53a90f670ced1e010684897d9d46eb9d2 | https://github.com/SilentCicero/solidity-to-abi/blob/2d97d2c53a90f670ced1e010684897d9d46eb9d2/src/index.js#L29-L91 |
46,151 | paglias/KnockoutApp | build/knockout.app.js | function(obj){
if(ko.isWriteableObservable(obj)) return ko.observable(obj());
if(obj === null || typeof obj !== 'object') return obj;
var temp = obj.constructor();
for (var key in obj) {
temp[key] = Utils.cloneObjKnockout(obj[key]);
}
return temp;
} | javascript | function(obj){
if(ko.isWriteableObservable(obj)) return ko.observable(obj());
if(obj === null || typeof obj !== 'object') return obj;
var temp = obj.constructor();
for (var key in obj) {
temp[key] = Utils.cloneObjKnockout(obj[key]);
}
return temp;
} | [
"function",
"(",
"obj",
")",
"{",
"if",
"(",
"ko",
".",
"isWriteableObservable",
"(",
"obj",
")",
")",
"return",
"ko",
".",
"observable",
"(",
"obj",
"(",
")",
")",
";",
"if",
"(",
"obj",
"===",
"null",
"||",
"typeof",
"obj",
"!==",
"'object'",
")",
"return",
"obj",
";",
"var",
"temp",
"=",
"obj",
".",
"constructor",
"(",
")",
";",
"for",
"(",
"var",
"key",
"in",
"obj",
")",
"{",
"temp",
"[",
"key",
"]",
"=",
"Utils",
".",
"cloneObjKnockout",
"(",
"obj",
"[",
"key",
"]",
")",
";",
"}",
"return",
"temp",
";",
"}"
]
| Used to clone an object with Knockout observable properties | [
"Used",
"to",
"clone",
"an",
"object",
"with",
"Knockout",
"observable",
"properties"
]
| 7010bc4508c2ec05154c966519325a3f61add3e5 | https://github.com/paglias/KnockoutApp/blob/7010bc4508c2ec05154c966519325a3f61add3e5/build/knockout.app.js#L76-L86 |
|
46,152 | paglias/KnockoutApp | build/knockout.app.js | function(_options){
var self = this, //model
options = _options || {},
success = options.success; //custom success function passed in _options
options.success = function(data){
delete data[self.idAttribute];
var defaults = Utils.cloneObjKnockout(self.defaults);
self.attributes = Utils.extendObjKnockout(defaults, data);
if(success) success(self, data);
};
return this.sync.call(this, 'fetch', this, options);
} | javascript | function(_options){
var self = this, //model
options = _options || {},
success = options.success; //custom success function passed in _options
options.success = function(data){
delete data[self.idAttribute];
var defaults = Utils.cloneObjKnockout(self.defaults);
self.attributes = Utils.extendObjKnockout(defaults, data);
if(success) success(self, data);
};
return this.sync.call(this, 'fetch', this, options);
} | [
"function",
"(",
"_options",
")",
"{",
"var",
"self",
"=",
"this",
",",
"//model",
"options",
"=",
"_options",
"||",
"{",
"}",
",",
"success",
"=",
"options",
".",
"success",
";",
"//custom success function passed in _options",
"options",
".",
"success",
"=",
"function",
"(",
"data",
")",
"{",
"delete",
"data",
"[",
"self",
".",
"idAttribute",
"]",
";",
"var",
"defaults",
"=",
"Utils",
".",
"cloneObjKnockout",
"(",
"self",
".",
"defaults",
")",
";",
"self",
".",
"attributes",
"=",
"Utils",
".",
"extendObjKnockout",
"(",
"defaults",
",",
"data",
")",
";",
"if",
"(",
"success",
")",
"success",
"(",
"self",
",",
"data",
")",
";",
"}",
";",
"return",
"this",
".",
"sync",
".",
"call",
"(",
"this",
",",
"'fetch'",
",",
"this",
",",
"options",
")",
";",
"}"
]
| Fetch the model on the server and replace its attributes with the one fetched Options for the sync method can be passed as an object | [
"Fetch",
"the",
"model",
"on",
"the",
"server",
"and",
"replace",
"its",
"attributes",
"with",
"the",
"one",
"fetched",
"Options",
"for",
"the",
"sync",
"method",
"can",
"be",
"passed",
"as",
"an",
"object"
]
| 7010bc4508c2ec05154c966519325a3f61add3e5 | https://github.com/paglias/KnockoutApp/blob/7010bc4508c2ec05154c966519325a3f61add3e5/build/knockout.app.js#L204-L217 |
|
46,153 | paglias/KnockoutApp | build/knockout.app.js | function(model_s, create, options){
var toAdd = model_s instanceof Array ? model_s : [model_s],
self = this;
ko.utils.arrayForEach(toAdd, function(attributes){
var model;
if(attributes instanceof Model){
model = attributes;
model.collection = self;
}else{
model = new self.model(attributes, {collection: self});
}
self.models.push(model);
if(create) model.save(options);
});
} | javascript | function(model_s, create, options){
var toAdd = model_s instanceof Array ? model_s : [model_s],
self = this;
ko.utils.arrayForEach(toAdd, function(attributes){
var model;
if(attributes instanceof Model){
model = attributes;
model.collection = self;
}else{
model = new self.model(attributes, {collection: self});
}
self.models.push(model);
if(create) model.save(options);
});
} | [
"function",
"(",
"model_s",
",",
"create",
",",
"options",
")",
"{",
"var",
"toAdd",
"=",
"model_s",
"instanceof",
"Array",
"?",
"model_s",
":",
"[",
"model_s",
"]",
",",
"self",
"=",
"this",
";",
"ko",
".",
"utils",
".",
"arrayForEach",
"(",
"toAdd",
",",
"function",
"(",
"attributes",
")",
"{",
"var",
"model",
";",
"if",
"(",
"attributes",
"instanceof",
"Model",
")",
"{",
"model",
"=",
"attributes",
";",
"model",
".",
"collection",
"=",
"self",
";",
"}",
"else",
"{",
"model",
"=",
"new",
"self",
".",
"model",
"(",
"attributes",
",",
"{",
"collection",
":",
"self",
"}",
")",
";",
"}",
"self",
".",
"models",
".",
"push",
"(",
"model",
")",
";",
"if",
"(",
"create",
")",
"model",
".",
"save",
"(",
"options",
")",
";",
"}",
")",
";",
"}"
]
| Add one or more models to collection and optionally create them on the server setting the 'create' parameter to 'true' It will also add a reference to the collection on each model | [
"Add",
"one",
"or",
"more",
"models",
"to",
"collection",
"and",
"optionally",
"create",
"them",
"on",
"the",
"server",
"setting",
"the",
"create",
"parameter",
"to",
"true",
"It",
"will",
"also",
"add",
"a",
"reference",
"to",
"the",
"collection",
"on",
"each",
"model"
]
| 7010bc4508c2ec05154c966519325a3f61add3e5 | https://github.com/paglias/KnockoutApp/blob/7010bc4508c2ec05154c966519325a3f61add3e5/build/knockout.app.js#L304-L319 |
|
46,154 | paglias/KnockoutApp | build/knockout.app.js | function(_options){
var self = this, //collection
options = _options || {},
success = options.success; //custom success function passed in _options
options.success = function(data){
var toAdd = [];
for(var model in data){
toAdd.push(data[model]);
}
self.reset(); //reset the collection
if(toAdd.length > 0) self.add(toAdd);
if(success) success(self, data);
};
return this.sync.call(this, 'fetch', this, options);
} | javascript | function(_options){
var self = this, //collection
options = _options || {},
success = options.success; //custom success function passed in _options
options.success = function(data){
var toAdd = [];
for(var model in data){
toAdd.push(data[model]);
}
self.reset(); //reset the collection
if(toAdd.length > 0) self.add(toAdd);
if(success) success(self, data);
};
return this.sync.call(this, 'fetch', this, options);
} | [
"function",
"(",
"_options",
")",
"{",
"var",
"self",
"=",
"this",
",",
"//collection",
"options",
"=",
"_options",
"||",
"{",
"}",
",",
"success",
"=",
"options",
".",
"success",
";",
"//custom success function passed in _options",
"options",
".",
"success",
"=",
"function",
"(",
"data",
")",
"{",
"var",
"toAdd",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"model",
"in",
"data",
")",
"{",
"toAdd",
".",
"push",
"(",
"data",
"[",
"model",
"]",
")",
";",
"}",
"self",
".",
"reset",
"(",
")",
";",
"//reset the collection",
"if",
"(",
"toAdd",
".",
"length",
">",
"0",
")",
"self",
".",
"add",
"(",
"toAdd",
")",
";",
"if",
"(",
"success",
")",
"success",
"(",
"self",
",",
"data",
")",
";",
"}",
";",
"return",
"this",
".",
"sync",
".",
"call",
"(",
"this",
",",
"'fetch'",
",",
"this",
",",
"options",
")",
";",
"}"
]
| Fetch models from server and add them to the collection. Options for the sync method can be passed as an object | [
"Fetch",
"models",
"from",
"server",
"and",
"add",
"them",
"to",
"the",
"collection",
".",
"Options",
"for",
"the",
"sync",
"method",
"can",
"be",
"passed",
"as",
"an",
"object"
]
| 7010bc4508c2ec05154c966519325a3f61add3e5 | https://github.com/paglias/KnockoutApp/blob/7010bc4508c2ec05154c966519325a3f61add3e5/build/knockout.app.js#L332-L350 |
|
46,155 | THEjoezack/BoxPusher | public/js-roguelike-skeleton/src/tile.js | Tile | function Tile(game, type, x, y) {
this.game = game;
this.x = x;
this.y = y;
this.type = type;
var typeData = Tile.Types[type];
RL.Util.merge(this, typeData);
this.id = tileId++;
if(this.init){
this.init(game, type, x, y);
}
} | javascript | function Tile(game, type, x, y) {
this.game = game;
this.x = x;
this.y = y;
this.type = type;
var typeData = Tile.Types[type];
RL.Util.merge(this, typeData);
this.id = tileId++;
if(this.init){
this.init(game, type, x, y);
}
} | [
"function",
"Tile",
"(",
"game",
",",
"type",
",",
"x",
",",
"y",
")",
"{",
"this",
".",
"game",
"=",
"game",
";",
"this",
".",
"x",
"=",
"x",
";",
"this",
".",
"y",
"=",
"y",
";",
"this",
".",
"type",
"=",
"type",
";",
"var",
"typeData",
"=",
"Tile",
".",
"Types",
"[",
"type",
"]",
";",
"RL",
".",
"Util",
".",
"merge",
"(",
"this",
",",
"typeData",
")",
";",
"this",
".",
"id",
"=",
"tileId",
"++",
";",
"if",
"(",
"this",
".",
"init",
")",
"{",
"this",
".",
"init",
"(",
"game",
",",
"type",
",",
"x",
",",
"y",
")",
";",
"}",
"}"
]
| Represents a tile in the game map.
@class Tile
@constructor
@uses TileDraw
@param {Object} game - Game instance this obj is attached to.
@param {String} type - Type of tile. When created this object is merged with the value of Tile.Types[type].
@param {Number} x - The map tile coordinate position of this tile on the x axis.
@param {Number} y - The map tile coordinate position of this tile on the y axis. | [
"Represents",
"a",
"tile",
"in",
"the",
"game",
"map",
"."
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/js-roguelike-skeleton/src/tile.js#L16-L30 |
46,156 | jlmorgan/lodash-transpose | src/transpose.js | baseTranspose | function baseTranspose(matrix) {
return map(head(matrix), function (column, index) {
return map(matrix, function (row) {
return row[index];
});
});
} | javascript | function baseTranspose(matrix) {
return map(head(matrix), function (column, index) {
return map(matrix, function (row) {
return row[index];
});
});
} | [
"function",
"baseTranspose",
"(",
"matrix",
")",
"{",
"return",
"map",
"(",
"head",
"(",
"matrix",
")",
",",
"function",
"(",
"column",
",",
"index",
")",
"{",
"return",
"map",
"(",
"matrix",
",",
"function",
"(",
"row",
")",
"{",
"return",
"row",
"[",
"index",
"]",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| Base matrix transpose. Turns an n by m matrix into m by n.
@private
@param {Array} matrix - Two-dimensional array (n by m).
@returns {Array} Returns m by n matrix. | [
"Base",
"matrix",
"transpose",
".",
"Turns",
"an",
"n",
"by",
"m",
"matrix",
"into",
"m",
"by",
"n",
"."
]
| 2cb7573293431f109796cf2c3f619bd83545b1a3 | https://github.com/jlmorgan/lodash-transpose/blob/2cb7573293431f109796cf2c3f619bd83545b1a3/src/transpose.js#L16-L22 |
46,157 | THEjoezack/BoxPusher | public/js-roguelike-skeleton/src/valid-targets.js | function(game, targets, settings){
this.game = game;
settings = settings || {};
this.typeSortPriority = settings.typeSortPriority || [].concat(this.typeSortPriority);
var width = settings.mapWidth || this.game.map.width;
var height = settings.mapWidth || this.game.map.width;
this.map = new RL.MultiObjectManager(this.game, null, width, height);
this.setTargets(targets);
if(!settings.skipSort){
this.sort();
}
} | javascript | function(game, targets, settings){
this.game = game;
settings = settings || {};
this.typeSortPriority = settings.typeSortPriority || [].concat(this.typeSortPriority);
var width = settings.mapWidth || this.game.map.width;
var height = settings.mapWidth || this.game.map.width;
this.map = new RL.MultiObjectManager(this.game, null, width, height);
this.setTargets(targets);
if(!settings.skipSort){
this.sort();
}
} | [
"function",
"(",
"game",
",",
"targets",
",",
"settings",
")",
"{",
"this",
".",
"game",
"=",
"game",
";",
"settings",
"=",
"settings",
"||",
"{",
"}",
";",
"this",
".",
"typeSortPriority",
"=",
"settings",
".",
"typeSortPriority",
"||",
"[",
"]",
".",
"concat",
"(",
"this",
".",
"typeSortPriority",
")",
";",
"var",
"width",
"=",
"settings",
".",
"mapWidth",
"||",
"this",
".",
"game",
".",
"map",
".",
"width",
";",
"var",
"height",
"=",
"settings",
".",
"mapWidth",
"||",
"this",
".",
"game",
".",
"map",
".",
"width",
";",
"this",
".",
"map",
"=",
"new",
"RL",
".",
"MultiObjectManager",
"(",
"this",
".",
"game",
",",
"null",
",",
"width",
",",
"height",
")",
";",
"this",
".",
"setTargets",
"(",
"targets",
")",
";",
"if",
"(",
"!",
"settings",
".",
"skipSort",
")",
"{",
"this",
".",
"sort",
"(",
")",
";",
"}",
"}"
]
| Manages a list of valid targets and which is currently selected.
@class ValidTargets
@constructor
@param {Game} game - Game instance this obj is attached to.
@param {Array} [targets=Array] An Array of valid target objects to select from (intended to be in the format `validTargetsFinder.getValidTargets()` returns).
@param {Object} settings
@param {Array} [settings.typeSortPriority=this.typeSortPriority] - Array of types in order of their sort priority.
@param {Bool} [settings.mapWidth=game.map.width] - Width of `this.map`.
@param {Bool} [settings.mapHeight=game.map.height] - Height of `this.map`.
@param {Bool} [settings.skipSort=false] - If true initial sort is skipped. | [
"Manages",
"a",
"list",
"of",
"valid",
"targets",
"and",
"which",
"is",
"currently",
"selected",
"."
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/js-roguelike-skeleton/src/valid-targets.js#L16-L30 |
|
46,158 | THEjoezack/BoxPusher | public/js-roguelike-skeleton/src/valid-targets.js | function(targets){
targets = targets || [];
this.targets = targets;
this.map.reset();
for(var i = targets.length - 1; i >= 0; i--){
var target = targets[i];
this.map.add(target.x, target.y, target);
}
} | javascript | function(targets){
targets = targets || [];
this.targets = targets;
this.map.reset();
for(var i = targets.length - 1; i >= 0; i--){
var target = targets[i];
this.map.add(target.x, target.y, target);
}
} | [
"function",
"(",
"targets",
")",
"{",
"targets",
"=",
"targets",
"||",
"[",
"]",
";",
"this",
".",
"targets",
"=",
"targets",
";",
"this",
".",
"map",
".",
"reset",
"(",
")",
";",
"for",
"(",
"var",
"i",
"=",
"targets",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"var",
"target",
"=",
"targets",
"[",
"i",
"]",
";",
"this",
".",
"map",
".",
"add",
"(",
"target",
".",
"x",
",",
"target",
".",
"y",
",",
"target",
")",
";",
"}",
"}"
]
| Sets the targets, replacing currently set ones.
@method setTargets
@param {Array} targets | [
"Sets",
"the",
"targets",
"replacing",
"currently",
"set",
"ones",
"."
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/js-roguelike-skeleton/src/valid-targets.js#L78-L86 |
|
46,159 | THEjoezack/BoxPusher | public/js-roguelike-skeleton/src/valid-targets.js | function(target){
var index = this.targets.indexOf(target);
if(index !== -1){
this.current = target;
return true;
}
return false;
} | javascript | function(target){
var index = this.targets.indexOf(target);
if(index !== -1){
this.current = target;
return true;
}
return false;
} | [
"function",
"(",
"target",
")",
"{",
"var",
"index",
"=",
"this",
".",
"targets",
".",
"indexOf",
"(",
"target",
")",
";",
"if",
"(",
"index",
"!==",
"-",
"1",
")",
"{",
"this",
".",
"current",
"=",
"target",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
]
| Sets the currently selected target object.
@method setCurrent
@param {Object} target
@return {Bool} If target was found in `this.targets`. (only set if found). | [
"Sets",
"the",
"currently",
"selected",
"target",
"object",
"."
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/js-roguelike-skeleton/src/valid-targets.js#L94-L101 |
|
46,160 | THEjoezack/BoxPusher | public/js-roguelike-skeleton/src/valid-targets.js | function(autoset){
autoset = autoset !== void 0 ? autoset : true;
if(autoset && !this.current && this.targets.length){
this.sort();
this.setCurrent(this.targets[0]);
}
return this.current;
} | javascript | function(autoset){
autoset = autoset !== void 0 ? autoset : true;
if(autoset && !this.current && this.targets.length){
this.sort();
this.setCurrent(this.targets[0]);
}
return this.current;
} | [
"function",
"(",
"autoset",
")",
"{",
"autoset",
"=",
"autoset",
"!==",
"void",
"0",
"?",
"autoset",
":",
"true",
";",
"if",
"(",
"autoset",
"&&",
"!",
"this",
".",
"current",
"&&",
"this",
".",
"targets",
".",
"length",
")",
"{",
"this",
".",
"sort",
"(",
")",
";",
"this",
".",
"setCurrent",
"(",
"this",
".",
"targets",
"[",
"0",
"]",
")",
";",
"}",
"return",
"this",
".",
"current",
";",
"}"
]
| Gets the currently selected target object.
@method getCurrent
@param {Bool} [autoset=true] - If no target is set to current autoset the first.
@return {Object} | [
"Gets",
"the",
"currently",
"selected",
"target",
"object",
"."
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/js-roguelike-skeleton/src/valid-targets.js#L109-L117 |
|
46,161 | THEjoezack/BoxPusher | public/js-roguelike-skeleton/src/valid-targets.js | function(){
if(!this.current){
return this.getCurrent();
}
var index = this.targets.indexOf(this.current);
if(index === 0){
index = this.targets.length - 1;
} else {
index--;
}
this.setCurrent(this.targets[index]);
return this.current;
} | javascript | function(){
if(!this.current){
return this.getCurrent();
}
var index = this.targets.indexOf(this.current);
if(index === 0){
index = this.targets.length - 1;
} else {
index--;
}
this.setCurrent(this.targets[index]);
return this.current;
} | [
"function",
"(",
")",
"{",
"if",
"(",
"!",
"this",
".",
"current",
")",
"{",
"return",
"this",
".",
"getCurrent",
"(",
")",
";",
"}",
"var",
"index",
"=",
"this",
".",
"targets",
".",
"indexOf",
"(",
"this",
".",
"current",
")",
";",
"if",
"(",
"index",
"===",
"0",
")",
"{",
"index",
"=",
"this",
".",
"targets",
".",
"length",
"-",
"1",
";",
"}",
"else",
"{",
"index",
"--",
";",
"}",
"this",
".",
"setCurrent",
"(",
"this",
".",
"targets",
"[",
"index",
"]",
")",
";",
"return",
"this",
".",
"current",
";",
"}"
]
| Sets the object before the currently selected object to be the selected object.
@method prev
@return {Object} The new currently selected object. | [
"Sets",
"the",
"object",
"before",
"the",
"currently",
"selected",
"object",
"to",
"be",
"the",
"selected",
"object",
"."
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/js-roguelike-skeleton/src/valid-targets.js#L144-L158 |
|
46,162 | THEjoezack/BoxPusher | public/js-roguelike-skeleton/src/valid-targets.js | function(obj){
for(var i = this.typeSortPriority.length - 1; i >= 0; i--){
var type = this.typeSortPriority[i];
if(obj instanceof type){
return i;
}
}
} | javascript | function(obj){
for(var i = this.typeSortPriority.length - 1; i >= 0; i--){
var type = this.typeSortPriority[i];
if(obj instanceof type){
return i;
}
}
} | [
"function",
"(",
"obj",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"this",
".",
"typeSortPriority",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"var",
"type",
"=",
"this",
".",
"typeSortPriority",
"[",
"i",
"]",
";",
"if",
"(",
"obj",
"instanceof",
"type",
")",
"{",
"return",
"i",
";",
"}",
"}",
"}"
]
| Gets the sort priority of an object based on its type using 'this.typeSortPriority'.
@method getTypeSortPriority
@param {Object} obj
@return {Number} | [
"Gets",
"the",
"sort",
"priority",
"of",
"an",
"object",
"based",
"on",
"its",
"type",
"using",
"this",
".",
"typeSortPriority",
"."
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/js-roguelike-skeleton/src/valid-targets.js#L166-L173 |
|
46,163 | THEjoezack/BoxPusher | public/js-roguelike-skeleton/src/valid-targets.js | function(){
var _this = this;
this.targets.sort(function(a, b){
var aTypeSortPriority = _this.getTypeSortPriority(a.value);
var bTypeSortPriority = _this.getTypeSortPriority(b.value);
if(aTypeSortPriority === bTypeSortPriority){
return a.range - b.range;
}
if(aTypeSortPriority > bTypeSortPriority){
return 1;
}
if(aTypeSortPriority < bTypeSortPriority){
return -1;
}
});
} | javascript | function(){
var _this = this;
this.targets.sort(function(a, b){
var aTypeSortPriority = _this.getTypeSortPriority(a.value);
var bTypeSortPriority = _this.getTypeSortPriority(b.value);
if(aTypeSortPriority === bTypeSortPriority){
return a.range - b.range;
}
if(aTypeSortPriority > bTypeSortPriority){
return 1;
}
if(aTypeSortPriority < bTypeSortPriority){
return -1;
}
});
} | [
"function",
"(",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"this",
".",
"targets",
".",
"sort",
"(",
"function",
"(",
"a",
",",
"b",
")",
"{",
"var",
"aTypeSortPriority",
"=",
"_this",
".",
"getTypeSortPriority",
"(",
"a",
".",
"value",
")",
";",
"var",
"bTypeSortPriority",
"=",
"_this",
".",
"getTypeSortPriority",
"(",
"b",
".",
"value",
")",
";",
"if",
"(",
"aTypeSortPriority",
"===",
"bTypeSortPriority",
")",
"{",
"return",
"a",
".",
"range",
"-",
"b",
".",
"range",
";",
"}",
"if",
"(",
"aTypeSortPriority",
">",
"bTypeSortPriority",
")",
"{",
"return",
"1",
";",
"}",
"if",
"(",
"aTypeSortPriority",
"<",
"bTypeSortPriority",
")",
"{",
"return",
"-",
"1",
";",
"}",
"}",
")",
";",
"}"
]
| Sorts `this.targets` by `this.typeSortPriority` then by range.
@method sort
@return {Number} | [
"Sorts",
"this",
".",
"targets",
"by",
"this",
".",
"typeSortPriority",
"then",
"by",
"range",
"."
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/js-roguelike-skeleton/src/valid-targets.js#L179-L196 |
|
46,164 | THEjoezack/BoxPusher | public/js-roguelike-skeleton/src/valid-targets.js | function(value){
for(var i = this.targets.length - 1; i >= 0; i--){
var target = this.targets[i];
if(target.value === value){
return target;
}
}
} | javascript | function(value){
for(var i = this.targets.length - 1; i >= 0; i--){
var target = this.targets[i];
if(target.value === value){
return target;
}
}
} | [
"function",
"(",
"value",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"this",
".",
"targets",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"var",
"target",
"=",
"this",
".",
"targets",
"[",
"i",
"]",
";",
"if",
"(",
"target",
".",
"value",
"===",
"value",
")",
"{",
"return",
"target",
";",
"}",
"}",
"}"
]
| Finds a target object by its value.
@method getTargetByValue
@param {Object} value
@return {Object} | [
"Finds",
"a",
"target",
"object",
"by",
"its",
"value",
"."
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/js-roguelike-skeleton/src/valid-targets.js#L204-L211 |
|
46,165 | djett41/node-feedjett | lib/parser.js | parseTitle | function parseTitle (node, nodeType, feedType) {
return utils.stripHtml(utils.get(node.title));
} | javascript | function parseTitle (node, nodeType, feedType) {
return utils.stripHtml(utils.get(node.title));
} | [
"function",
"parseTitle",
"(",
"node",
",",
"nodeType",
",",
"feedType",
")",
"{",
"return",
"utils",
".",
"stripHtml",
"(",
"utils",
".",
"get",
"(",
"node",
".",
"title",
")",
")",
";",
"}"
]
| Parses the title of a meta or item node and strips HTML
@param node
@param nodeType
@param feedType
@returns {string} | [
"Parses",
"the",
"title",
"of",
"a",
"meta",
"or",
"item",
"node",
"and",
"strips",
"HTML"
]
| b205aca7a4f72ee04e6ebbe0591fc8eb9078e073 | https://github.com/djett41/node-feedjett/blob/b205aca7a4f72ee04e6ebbe0591fc8eb9078e073/lib/parser.js#L86-L88 |
46,166 | djett41/node-feedjett | lib/parser.js | parseDescription | function parseDescription (node, nodeType, feedType) {
var propOrder = nodeType === 'item' ?
['description', 'summary', 'itunes:summary', 'content:encoded', 'content'] :
['description', 'subtitle', 'itunes:summary'];
return utils.stripHtml(utils.getFirstFoundPropValue(node, propOrder));
} | javascript | function parseDescription (node, nodeType, feedType) {
var propOrder = nodeType === 'item' ?
['description', 'summary', 'itunes:summary', 'content:encoded', 'content'] :
['description', 'subtitle', 'itunes:summary'];
return utils.stripHtml(utils.getFirstFoundPropValue(node, propOrder));
} | [
"function",
"parseDescription",
"(",
"node",
",",
"nodeType",
",",
"feedType",
")",
"{",
"var",
"propOrder",
"=",
"nodeType",
"===",
"'item'",
"?",
"[",
"'description'",
",",
"'summary'",
",",
"'itunes:summary'",
",",
"'content:encoded'",
",",
"'content'",
"]",
":",
"[",
"'description'",
",",
"'subtitle'",
",",
"'itunes:summary'",
"]",
";",
"return",
"utils",
".",
"stripHtml",
"(",
"utils",
".",
"getFirstFoundPropValue",
"(",
"node",
",",
"propOrder",
")",
")",
";",
"}"
]
| Parses the description of a meta or item node and strips HTML
- description
- highest priority and quantity in RSS feeds for both meta and item nodes.
- rarely found in ATOM feeds, commonly found in RSS feeds
- subtitle
- highest priority and quantity in ATOM feeds for meta nodes
- rarely found in RSS feeds
- summary
- highest priority in ATOM feeds for item nodes.
- rarely found in RSS feeds if ever, almost always found in ATOM feeds
- Item nodes that contain summary will sometimes include content.
- itunes:summary
- next best priority in RSS feeds after description
- rarely found in ATOM feeds if ever, sometimes found in RSS feeds.
- content:encoded
- least priority for item nodes
- more commonly found in RSS feeds and rarely found in ATOM feeds if ever
- content
- least priority for item nodes
- more commonly found in ATOM feeds and sometimes found in RSS feeds
@param node
@param nodeType
@param feedType
@returns {string} | [
"Parses",
"the",
"description",
"of",
"a",
"meta",
"or",
"item",
"node",
"and",
"strips",
"HTML"
]
| b205aca7a4f72ee04e6ebbe0591fc8eb9078e073 | https://github.com/djett41/node-feedjett/blob/b205aca7a4f72ee04e6ebbe0591fc8eb9078e073/lib/parser.js#L119-L125 |
46,167 | djett41/node-feedjett | lib/parser.js | parseXmlUrl | function parseXmlUrl (node, nodeType, feedType) {
var getLink = function (linkNode) {
var link;
utils.parse(linkNode, function (linkEl) {
var linkAttr = linkEl['@'];
if (linkAttr.href && linkAttr.rel === 'self') {
link = linkAttr.href;
return;
}
}, this, true);
return link;
};
return getLink(node.link) || getLink(node['atom:link']) || getLink(node['atom10:link']);
} | javascript | function parseXmlUrl (node, nodeType, feedType) {
var getLink = function (linkNode) {
var link;
utils.parse(linkNode, function (linkEl) {
var linkAttr = linkEl['@'];
if (linkAttr.href && linkAttr.rel === 'self') {
link = linkAttr.href;
return;
}
}, this, true);
return link;
};
return getLink(node.link) || getLink(node['atom:link']) || getLink(node['atom10:link']);
} | [
"function",
"parseXmlUrl",
"(",
"node",
",",
"nodeType",
",",
"feedType",
")",
"{",
"var",
"getLink",
"=",
"function",
"(",
"linkNode",
")",
"{",
"var",
"link",
";",
"utils",
".",
"parse",
"(",
"linkNode",
",",
"function",
"(",
"linkEl",
")",
"{",
"var",
"linkAttr",
"=",
"linkEl",
"[",
"'@'",
"]",
";",
"if",
"(",
"linkAttr",
".",
"href",
"&&",
"linkAttr",
".",
"rel",
"===",
"'self'",
")",
"{",
"link",
"=",
"linkAttr",
".",
"href",
";",
"return",
";",
"}",
"}",
",",
"this",
",",
"true",
")",
";",
"return",
"link",
";",
"}",
";",
"return",
"getLink",
"(",
"node",
".",
"link",
")",
"||",
"getLink",
"(",
"node",
"[",
"'atom:link'",
"]",
")",
"||",
"getLink",
"(",
"node",
"[",
"'atom10:link'",
"]",
")",
";",
"}"
]
| Parses the xmlUrl of a meta node.
- link
- highest priority and quantity in RSS and ATOM feeds for both meta and item nodes.
- atom:link
- next highest priority and quantity in RSS feeds for meta nodes.
- rarely found in ATOM feeds or item nodes if ever.
- atom10:link
- next highest priority in RSS feeds for meta nodes.
- rarely found in ATOM feeds or item nodes if ever.
@param node
@param nodeType
@param feedType
@returns {string} | [
"Parses",
"the",
"xmlUrl",
"of",
"a",
"meta",
"node",
"."
]
| b205aca7a4f72ee04e6ebbe0591fc8eb9078e073 | https://github.com/djett41/node-feedjett/blob/b205aca7a4f72ee04e6ebbe0591fc8eb9078e073/lib/parser.js#L205-L222 |
46,168 | djett41/node-feedjett | lib/parser.js | parseOrigLink | function parseOrigLink (node, nodeType, feedType) {
var origLink;
if (origLink = utils.getFirstFoundPropValue(node, ['feedburner:origlink', 'pheedo:origlink'])) {
return origLink;
} else {
utils.parse(node.link, function (linkEl) {
var linkAttr = linkEl['@'];
if (linkAttr.href && linkAttr.rel === 'canonical') {
origLink = linkAttr.href;
return true;
}
}, this, true);
}
return origLink;
} | javascript | function parseOrigLink (node, nodeType, feedType) {
var origLink;
if (origLink = utils.getFirstFoundPropValue(node, ['feedburner:origlink', 'pheedo:origlink'])) {
return origLink;
} else {
utils.parse(node.link, function (linkEl) {
var linkAttr = linkEl['@'];
if (linkAttr.href && linkAttr.rel === 'canonical') {
origLink = linkAttr.href;
return true;
}
}, this, true);
}
return origLink;
} | [
"function",
"parseOrigLink",
"(",
"node",
",",
"nodeType",
",",
"feedType",
")",
"{",
"var",
"origLink",
";",
"if",
"(",
"origLink",
"=",
"utils",
".",
"getFirstFoundPropValue",
"(",
"node",
",",
"[",
"'feedburner:origlink'",
",",
"'pheedo:origlink'",
"]",
")",
")",
"{",
"return",
"origLink",
";",
"}",
"else",
"{",
"utils",
".",
"parse",
"(",
"node",
".",
"link",
",",
"function",
"(",
"linkEl",
")",
"{",
"var",
"linkAttr",
"=",
"linkEl",
"[",
"'@'",
"]",
";",
"if",
"(",
"linkAttr",
".",
"href",
"&&",
"linkAttr",
".",
"rel",
"===",
"'canonical'",
")",
"{",
"origLink",
"=",
"linkAttr",
".",
"href",
";",
"return",
"true",
";",
"}",
"}",
",",
"this",
",",
"true",
")",
";",
"}",
"return",
"origLink",
";",
"}"
]
| Parses the origLink for item nodes.
@param node
@param nodeType
@param feedType | [
"Parses",
"the",
"origLink",
"for",
"item",
"nodes",
"."
]
| b205aca7a4f72ee04e6ebbe0591fc8eb9078e073 | https://github.com/djett41/node-feedjett/blob/b205aca7a4f72ee04e6ebbe0591fc8eb9078e073/lib/parser.js#L232-L249 |
46,169 | djett41/node-feedjett | lib/parser.js | parseAuthor | function parseAuthor (node, nodeType, feedType) {
var authorNode = node.author,
author;
//Both meta and item have author property as top priority and share parsing logic.
if (authorNode && (author = utils.get(authorNode))) {
author = addressparser(author)[0];
return author.name || author.address;
}
else if (authorNode && (author = utils.get(authorNode.name) || utils.get(authorNode.email))) {
return author;
}
// use addressparser to parse managingeditor or webmaster properties for meta nodes
else if (nodeType === 'meta' && (author = utils.get(node.managingeditor) || utils.get(node.webmaster))) {
author = addressparser(author)[0];
return author.name || author.address;
}
//parse the next properties in order
else if (author = utils.getFirstFoundPropValue(node, ['dc:creator', 'itunes:author', 'dc:publisher'])) {
return author;
}
else if (node['itunes:owner'] && (author = utils.get(node['itunes:owner']['itunes:name']) || utils.get(node['itunes:owner']['itunes:email']))) {
return author;
}
return null;
} | javascript | function parseAuthor (node, nodeType, feedType) {
var authorNode = node.author,
author;
//Both meta and item have author property as top priority and share parsing logic.
if (authorNode && (author = utils.get(authorNode))) {
author = addressparser(author)[0];
return author.name || author.address;
}
else if (authorNode && (author = utils.get(authorNode.name) || utils.get(authorNode.email))) {
return author;
}
// use addressparser to parse managingeditor or webmaster properties for meta nodes
else if (nodeType === 'meta' && (author = utils.get(node.managingeditor) || utils.get(node.webmaster))) {
author = addressparser(author)[0];
return author.name || author.address;
}
//parse the next properties in order
else if (author = utils.getFirstFoundPropValue(node, ['dc:creator', 'itunes:author', 'dc:publisher'])) {
return author;
}
else if (node['itunes:owner'] && (author = utils.get(node['itunes:owner']['itunes:name']) || utils.get(node['itunes:owner']['itunes:email']))) {
return author;
}
return null;
} | [
"function",
"parseAuthor",
"(",
"node",
",",
"nodeType",
",",
"feedType",
")",
"{",
"var",
"authorNode",
"=",
"node",
".",
"author",
",",
"author",
";",
"//Both meta and item have author property as top priority and share parsing logic.",
"if",
"(",
"authorNode",
"&&",
"(",
"author",
"=",
"utils",
".",
"get",
"(",
"authorNode",
")",
")",
")",
"{",
"author",
"=",
"addressparser",
"(",
"author",
")",
"[",
"0",
"]",
";",
"return",
"author",
".",
"name",
"||",
"author",
".",
"address",
";",
"}",
"else",
"if",
"(",
"authorNode",
"&&",
"(",
"author",
"=",
"utils",
".",
"get",
"(",
"authorNode",
".",
"name",
")",
"||",
"utils",
".",
"get",
"(",
"authorNode",
".",
"email",
")",
")",
")",
"{",
"return",
"author",
";",
"}",
"// use addressparser to parse managingeditor or webmaster properties for meta nodes",
"else",
"if",
"(",
"nodeType",
"===",
"'meta'",
"&&",
"(",
"author",
"=",
"utils",
".",
"get",
"(",
"node",
".",
"managingeditor",
")",
"||",
"utils",
".",
"get",
"(",
"node",
".",
"webmaster",
")",
")",
")",
"{",
"author",
"=",
"addressparser",
"(",
"author",
")",
"[",
"0",
"]",
";",
"return",
"author",
".",
"name",
"||",
"author",
".",
"address",
";",
"}",
"//parse the next properties in order",
"else",
"if",
"(",
"author",
"=",
"utils",
".",
"getFirstFoundPropValue",
"(",
"node",
",",
"[",
"'dc:creator'",
",",
"'itunes:author'",
",",
"'dc:publisher'",
"]",
")",
")",
"{",
"return",
"author",
";",
"}",
"else",
"if",
"(",
"node",
"[",
"'itunes:owner'",
"]",
"&&",
"(",
"author",
"=",
"utils",
".",
"get",
"(",
"node",
"[",
"'itunes:owner'",
"]",
"[",
"'itunes:name'",
"]",
")",
"||",
"utils",
".",
"get",
"(",
"node",
"[",
"'itunes:owner'",
"]",
"[",
"'itunes:email'",
"]",
")",
")",
")",
"{",
"return",
"author",
";",
"}",
"return",
"null",
";",
"}"
]
| Parses the author for meta and item nodes
- author
- highest priority in ATOM and RSS feeds for both meta and item nodes
- more commonly found in ATOM feeds than RSS feeds
- managingeditor
- next highest priority for RSS feeds in meta nodes
- more commonly found in RSS feeds and rarely found in ATOM feeds if ever
- generally more specific than webmaster
- webmaster
- next highest priority for RSS feeds in meta nodes
- more commonly found in RSS feeds and rarely found in ATOM feeds if ever
- generally less specific than managingeditor
- dc:creator
- next highest priority for meta and item nodes in RSS feeds, and item nodes in ATOM feeds
- rarely found in meta nodes for ATOM feeds if ever
- can include an author, email, or entity name
- itunes:author
- next highest priority for meta and item nodes in RSS feeds
- sometimes found in RSS feeds, rarely found in ATOM feeds if ever
- can include an author, email, or entity name
- dc:publisher
- next highest priority for meta and item nodes in RSS feeds
- sometimes found in RSS feeds, rarely found in ATOM feeds if ever
- can include an author, email, or entity name
- itunes:owner
- least priority for meta nodes in RSS feeds
- rarely found in item nodes for RSS feeds, or meta and item nodes for ATOM feeds if ever
- can include an author, email, or entity name
@param node
@param nodeType
@param feedType
@returns {string} | [
"Parses",
"the",
"author",
"for",
"meta",
"and",
"item",
"nodes"
]
| b205aca7a4f72ee04e6ebbe0591fc8eb9078e073 | https://github.com/djett41/node-feedjett/blob/b205aca7a4f72ee04e6ebbe0591fc8eb9078e073/lib/parser.js#L288-L314 |
46,170 | djett41/node-feedjett | lib/parser.js | parseLanguage | function parseLanguage (node, nodeType, feedType) {
return utils.get(node.language) || utils.getAttr(node, 'xml:lang') || utils.get(node['dc:language']);
} | javascript | function parseLanguage (node, nodeType, feedType) {
return utils.get(node.language) || utils.getAttr(node, 'xml:lang') || utils.get(node['dc:language']);
} | [
"function",
"parseLanguage",
"(",
"node",
",",
"nodeType",
",",
"feedType",
")",
"{",
"return",
"utils",
".",
"get",
"(",
"node",
".",
"language",
")",
"||",
"utils",
".",
"getAttr",
"(",
"node",
",",
"'xml:lang'",
")",
"||",
"utils",
".",
"get",
"(",
"node",
"[",
"'dc:language'",
"]",
")",
";",
"}"
]
| Parses the language for meta nodes
- language
- highest priority for RSS feeds
- commonly found in RSS feeds and rarely in ATOM feeds if ever
- xml:lang
- highest priority for ATOM feeds
- more commonly found in ATOM feeds and rarely found in RSS feeds if ever
- dc:language
- next highest priority for RSS feeds
- more commonly found in RSS feeds and rarely found in ATOM feeds if ever
@param node
@param nodeType
@param feedType
@returns {*} | [
"Parses",
"the",
"language",
"for",
"meta",
"nodes"
]
| b205aca7a4f72ee04e6ebbe0591fc8eb9078e073 | https://github.com/djett41/node-feedjett/blob/b205aca7a4f72ee04e6ebbe0591fc8eb9078e073/lib/parser.js#L335-L337 |
46,171 | djett41/node-feedjett | lib/parser.js | parseUpdateInfo | function parseUpdateInfo (node, nodeType, feedType) {
var updateInfo = {}, temp;
if (temp = utils.get(node['sy:updatefrequency'])) {
updateInfo.frequency = temp;
}
if (temp = utils.get(node['sy:updateperiod'])) {
updateInfo.period = temp;
}
if (temp = utils.get(node['sy:updatebase'])) {
updateInfo.base = temp;
}
if (temp = utils.get(node.ttl)) {
updateInfo.ttl = temp;
}
return Object.keys(updateInfo).length ? updateInfo : null;
} | javascript | function parseUpdateInfo (node, nodeType, feedType) {
var updateInfo = {}, temp;
if (temp = utils.get(node['sy:updatefrequency'])) {
updateInfo.frequency = temp;
}
if (temp = utils.get(node['sy:updateperiod'])) {
updateInfo.period = temp;
}
if (temp = utils.get(node['sy:updatebase'])) {
updateInfo.base = temp;
}
if (temp = utils.get(node.ttl)) {
updateInfo.ttl = temp;
}
return Object.keys(updateInfo).length ? updateInfo : null;
} | [
"function",
"parseUpdateInfo",
"(",
"node",
",",
"nodeType",
",",
"feedType",
")",
"{",
"var",
"updateInfo",
"=",
"{",
"}",
",",
"temp",
";",
"if",
"(",
"temp",
"=",
"utils",
".",
"get",
"(",
"node",
"[",
"'sy:updatefrequency'",
"]",
")",
")",
"{",
"updateInfo",
".",
"frequency",
"=",
"temp",
";",
"}",
"if",
"(",
"temp",
"=",
"utils",
".",
"get",
"(",
"node",
"[",
"'sy:updateperiod'",
"]",
")",
")",
"{",
"updateInfo",
".",
"period",
"=",
"temp",
";",
"}",
"if",
"(",
"temp",
"=",
"utils",
".",
"get",
"(",
"node",
"[",
"'sy:updatebase'",
"]",
")",
")",
"{",
"updateInfo",
".",
"base",
"=",
"temp",
";",
"}",
"if",
"(",
"temp",
"=",
"utils",
".",
"get",
"(",
"node",
".",
"ttl",
")",
")",
"{",
"updateInfo",
".",
"ttl",
"=",
"temp",
";",
"}",
"return",
"Object",
".",
"keys",
"(",
"updateInfo",
")",
".",
"length",
"?",
"updateInfo",
":",
"null",
";",
"}"
]
| Parses the common meta properties used to determine when to update or get a new feed
@param node
@param nodeType
@param feedType
@returns {{}} | [
"Parses",
"the",
"common",
"meta",
"properties",
"used",
"to",
"determine",
"when",
"to",
"update",
"or",
"get",
"a",
"new",
"feed"
]
| b205aca7a4f72ee04e6ebbe0591fc8eb9078e073 | https://github.com/djett41/node-feedjett/blob/b205aca7a4f72ee04e6ebbe0591fc8eb9078e073/lib/parser.js#L391-L408 |
46,172 | djett41/node-feedjett | lib/parser.js | parseImage | function parseImage (node, nodeType, feedType) {
var image, mediaGroup, mediaContent;
if (node.image && (image = utils.get(utils.get(node.image, 'url') || node.image))) {
return image;
} else if (nodeType === 'meta') {
return utils.getAttr(node['itunes:image'], 'href') || utils.getAttr(node['media:thumbnail'], 'url') || utils.get(node.logo);
}
else if (nodeType === 'item') {
mediaGroup = node['media:group'];
mediaContent = node['media:content'];
//search for media:thumbnail url in the following order:. node, node['media:content'], node['media:group'], node['media:group']['media:content']
if (image = utils.getAttr(node['media:thumbnail'] || utils.get(mediaContent || mediaGroup, 'media:thumbnail') ||
utils.get(mediaGroup && mediaGroup['media:content'], 'media:thumbnail'), 'url')) {
return image;
}
//search for itunes:image href
else if (image = utils.getAttr(node['itunes:image'], 'href')) {
return image;
}
//fall back on node['media:content'] or node['media:group']['media:content'] url
else if (image = utils.getAttr(mediaContent || (mediaGroup && mediaGroup['media:content']))) {
if (image.url && (image.medium === 'image' || (image.type && image.type.indexOf('image') === 0) || /\.(jpg|jpeg|png|gif)/.test(image.url))) {
return image.url;
}
}
}
} | javascript | function parseImage (node, nodeType, feedType) {
var image, mediaGroup, mediaContent;
if (node.image && (image = utils.get(utils.get(node.image, 'url') || node.image))) {
return image;
} else if (nodeType === 'meta') {
return utils.getAttr(node['itunes:image'], 'href') || utils.getAttr(node['media:thumbnail'], 'url') || utils.get(node.logo);
}
else if (nodeType === 'item') {
mediaGroup = node['media:group'];
mediaContent = node['media:content'];
//search for media:thumbnail url in the following order:. node, node['media:content'], node['media:group'], node['media:group']['media:content']
if (image = utils.getAttr(node['media:thumbnail'] || utils.get(mediaContent || mediaGroup, 'media:thumbnail') ||
utils.get(mediaGroup && mediaGroup['media:content'], 'media:thumbnail'), 'url')) {
return image;
}
//search for itunes:image href
else if (image = utils.getAttr(node['itunes:image'], 'href')) {
return image;
}
//fall back on node['media:content'] or node['media:group']['media:content'] url
else if (image = utils.getAttr(mediaContent || (mediaGroup && mediaGroup['media:content']))) {
if (image.url && (image.medium === 'image' || (image.type && image.type.indexOf('image') === 0) || /\.(jpg|jpeg|png|gif)/.test(image.url))) {
return image.url;
}
}
}
} | [
"function",
"parseImage",
"(",
"node",
",",
"nodeType",
",",
"feedType",
")",
"{",
"var",
"image",
",",
"mediaGroup",
",",
"mediaContent",
";",
"if",
"(",
"node",
".",
"image",
"&&",
"(",
"image",
"=",
"utils",
".",
"get",
"(",
"utils",
".",
"get",
"(",
"node",
".",
"image",
",",
"'url'",
")",
"||",
"node",
".",
"image",
")",
")",
")",
"{",
"return",
"image",
";",
"}",
"else",
"if",
"(",
"nodeType",
"===",
"'meta'",
")",
"{",
"return",
"utils",
".",
"getAttr",
"(",
"node",
"[",
"'itunes:image'",
"]",
",",
"'href'",
")",
"||",
"utils",
".",
"getAttr",
"(",
"node",
"[",
"'media:thumbnail'",
"]",
",",
"'url'",
")",
"||",
"utils",
".",
"get",
"(",
"node",
".",
"logo",
")",
";",
"}",
"else",
"if",
"(",
"nodeType",
"===",
"'item'",
")",
"{",
"mediaGroup",
"=",
"node",
"[",
"'media:group'",
"]",
";",
"mediaContent",
"=",
"node",
"[",
"'media:content'",
"]",
";",
"//search for media:thumbnail url in the following order:. node, node['media:content'], node['media:group'], node['media:group']['media:content']",
"if",
"(",
"image",
"=",
"utils",
".",
"getAttr",
"(",
"node",
"[",
"'media:thumbnail'",
"]",
"||",
"utils",
".",
"get",
"(",
"mediaContent",
"||",
"mediaGroup",
",",
"'media:thumbnail'",
")",
"||",
"utils",
".",
"get",
"(",
"mediaGroup",
"&&",
"mediaGroup",
"[",
"'media:content'",
"]",
",",
"'media:thumbnail'",
")",
",",
"'url'",
")",
")",
"{",
"return",
"image",
";",
"}",
"//search for itunes:image href",
"else",
"if",
"(",
"image",
"=",
"utils",
".",
"getAttr",
"(",
"node",
"[",
"'itunes:image'",
"]",
",",
"'href'",
")",
")",
"{",
"return",
"image",
";",
"}",
"//fall back on node['media:content'] or node['media:group']['media:content'] url",
"else",
"if",
"(",
"image",
"=",
"utils",
".",
"getAttr",
"(",
"mediaContent",
"||",
"(",
"mediaGroup",
"&&",
"mediaGroup",
"[",
"'media:content'",
"]",
")",
")",
")",
"{",
"if",
"(",
"image",
".",
"url",
"&&",
"(",
"image",
".",
"medium",
"===",
"'image'",
"||",
"(",
"image",
".",
"type",
"&&",
"image",
".",
"type",
".",
"indexOf",
"(",
"'image'",
")",
"===",
"0",
")",
"||",
"/",
"\\.(jpg|jpeg|png|gif)",
"/",
".",
"test",
"(",
"image",
".",
"url",
")",
")",
")",
"{",
"return",
"image",
".",
"url",
";",
"}",
"}",
"}",
"}"
]
| Parses the image of a meta or item node.
- image
- highest priority for RSS feeds in both meta nd item nodes
- most frequent in meta nodes, less frequent in item nodes
- itunes:image
- second most frequent in RSS feeds for meta nodes
- less frequent and lesser priority than media:thumbnail in RSS feeds for item nodes
- media:thumbnail
- second highest priority for item nodes for RSS and ATOM feeds
- third most frequent in meta nodes for RSS and ATOM feeds
- for item nodes, the media:thumbnail is searched for in the main node, node['media:content'],
node['media:group'], and node['media:group']['media:content'] respectively
- media:content
- url attr is used as a fallback if media:thumbnail is not available. Since medi:content can also contain non
images such as videos, extra logic must be performed to guarantee an image
- logo
- very infrequent but sometimes found in ATOM feeds for meta nodes
@param node
@param nodeType
@param feedType
@returns {*} | [
"Parses",
"the",
"image",
"of",
"a",
"meta",
"or",
"item",
"node",
"."
]
| b205aca7a4f72ee04e6ebbe0591fc8eb9078e073 | https://github.com/djett41/node-feedjett/blob/b205aca7a4f72ee04e6ebbe0591fc8eb9078e073/lib/parser.js#L472-L500 |
46,173 | djett41/node-feedjett | lib/parser.js | parseCloud | function parseCloud (node, nodeType, feedType) {
var cloud,
temp = utils.getAttr(node.cloud) || {};
if (Object.keys(temp).length) {
cloud = temp;
cloud.type = 'rsscloud';
} else {
utils.parse(node.link, function (link) {
var attr = utils.getAttr(link);
if (attr && attr.href && attr.rel === 'hub') {
cloud = {type: 'hub', href: attr.href};
return true;
}
}, this, true);
}
return cloud;
} | javascript | function parseCloud (node, nodeType, feedType) {
var cloud,
temp = utils.getAttr(node.cloud) || {};
if (Object.keys(temp).length) {
cloud = temp;
cloud.type = 'rsscloud';
} else {
utils.parse(node.link, function (link) {
var attr = utils.getAttr(link);
if (attr && attr.href && attr.rel === 'hub') {
cloud = {type: 'hub', href: attr.href};
return true;
}
}, this, true);
}
return cloud;
} | [
"function",
"parseCloud",
"(",
"node",
",",
"nodeType",
",",
"feedType",
")",
"{",
"var",
"cloud",
",",
"temp",
"=",
"utils",
".",
"getAttr",
"(",
"node",
".",
"cloud",
")",
"||",
"{",
"}",
";",
"if",
"(",
"Object",
".",
"keys",
"(",
"temp",
")",
".",
"length",
")",
"{",
"cloud",
"=",
"temp",
";",
"cloud",
".",
"type",
"=",
"'rsscloud'",
";",
"}",
"else",
"{",
"utils",
".",
"parse",
"(",
"node",
".",
"link",
",",
"function",
"(",
"link",
")",
"{",
"var",
"attr",
"=",
"utils",
".",
"getAttr",
"(",
"link",
")",
";",
"if",
"(",
"attr",
"&&",
"attr",
".",
"href",
"&&",
"attr",
".",
"rel",
"===",
"'hub'",
")",
"{",
"cloud",
"=",
"{",
"type",
":",
"'hub'",
",",
"href",
":",
"attr",
".",
"href",
"}",
";",
"return",
"true",
";",
"}",
"}",
",",
"this",
",",
"true",
")",
";",
"}",
"return",
"cloud",
";",
"}"
]
| Parses the cloud of a meta node.
- cloud
- highest priority for RSS feeds
- rarely found in ATOM feeds if ever
- link (rel=hub)
- mostly found in ATOM feeds and rarely in RSS
@param node
@param nodeType
@param feedType | [
"Parses",
"the",
"cloud",
"of",
"a",
"meta",
"node",
"."
]
| b205aca7a4f72ee04e6ebbe0591fc8eb9078e073 | https://github.com/djett41/node-feedjett/blob/b205aca7a4f72ee04e6ebbe0591fc8eb9078e073/lib/parser.js#L516-L534 |
46,174 | djett41/node-feedjett | lib/parser.js | parseCategories | function parseCategories (node, nodeType, feedType) {
var categoryMap = {};
var setCategory = function (category, attrProp) {
if (!category) {
return;
} else if (attrProp) {
category = utils.getAttr(category, attrProp);
}
if (!categoryMap[category]) {
categoryMap[category] = true;
}
};
var splitAndSetCategory = function (category, delimiter) {
category && category.split(delimiter).forEach(function (cat) {
setCategory(cat);
});
};
['category', 'dc:subject', 'itunes:category', 'media:category'].forEach(function (key) {
if (!node[key]) {
return;
}
utils.parse(node[key], function (category) {
if (key === 'category') {
setCategory.apply(null, (feedType === 'atom' ? [category, 'term'] : [utils.get(category)]));
} else if (key === 'dc:subject') {
splitAndSetCategory(utils.get(category), ' ');
} else if (key === 'itunes:category') {
//sometimes itunes:category has it's own itunes:category property
setCategory(category, 'text');
utils.parse(category[key] || category, function (cat) {
setCategory(cat, 'text');
});
} else if (key === 'media:category') {
splitAndSetCategory(utils.get(category), '/');
}
});
});
var categories = Object.keys(categoryMap);
return categories.length && categories.map(function (key) {
return key;
});
} | javascript | function parseCategories (node, nodeType, feedType) {
var categoryMap = {};
var setCategory = function (category, attrProp) {
if (!category) {
return;
} else if (attrProp) {
category = utils.getAttr(category, attrProp);
}
if (!categoryMap[category]) {
categoryMap[category] = true;
}
};
var splitAndSetCategory = function (category, delimiter) {
category && category.split(delimiter).forEach(function (cat) {
setCategory(cat);
});
};
['category', 'dc:subject', 'itunes:category', 'media:category'].forEach(function (key) {
if (!node[key]) {
return;
}
utils.parse(node[key], function (category) {
if (key === 'category') {
setCategory.apply(null, (feedType === 'atom' ? [category, 'term'] : [utils.get(category)]));
} else if (key === 'dc:subject') {
splitAndSetCategory(utils.get(category), ' ');
} else if (key === 'itunes:category') {
//sometimes itunes:category has it's own itunes:category property
setCategory(category, 'text');
utils.parse(category[key] || category, function (cat) {
setCategory(cat, 'text');
});
} else if (key === 'media:category') {
splitAndSetCategory(utils.get(category), '/');
}
});
});
var categories = Object.keys(categoryMap);
return categories.length && categories.map(function (key) {
return key;
});
} | [
"function",
"parseCategories",
"(",
"node",
",",
"nodeType",
",",
"feedType",
")",
"{",
"var",
"categoryMap",
"=",
"{",
"}",
";",
"var",
"setCategory",
"=",
"function",
"(",
"category",
",",
"attrProp",
")",
"{",
"if",
"(",
"!",
"category",
")",
"{",
"return",
";",
"}",
"else",
"if",
"(",
"attrProp",
")",
"{",
"category",
"=",
"utils",
".",
"getAttr",
"(",
"category",
",",
"attrProp",
")",
";",
"}",
"if",
"(",
"!",
"categoryMap",
"[",
"category",
"]",
")",
"{",
"categoryMap",
"[",
"category",
"]",
"=",
"true",
";",
"}",
"}",
";",
"var",
"splitAndSetCategory",
"=",
"function",
"(",
"category",
",",
"delimiter",
")",
"{",
"category",
"&&",
"category",
".",
"split",
"(",
"delimiter",
")",
".",
"forEach",
"(",
"function",
"(",
"cat",
")",
"{",
"setCategory",
"(",
"cat",
")",
";",
"}",
")",
";",
"}",
";",
"[",
"'category'",
",",
"'dc:subject'",
",",
"'itunes:category'",
",",
"'media:category'",
"]",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"if",
"(",
"!",
"node",
"[",
"key",
"]",
")",
"{",
"return",
";",
"}",
"utils",
".",
"parse",
"(",
"node",
"[",
"key",
"]",
",",
"function",
"(",
"category",
")",
"{",
"if",
"(",
"key",
"===",
"'category'",
")",
"{",
"setCategory",
".",
"apply",
"(",
"null",
",",
"(",
"feedType",
"===",
"'atom'",
"?",
"[",
"category",
",",
"'term'",
"]",
":",
"[",
"utils",
".",
"get",
"(",
"category",
")",
"]",
")",
")",
";",
"}",
"else",
"if",
"(",
"key",
"===",
"'dc:subject'",
")",
"{",
"splitAndSetCategory",
"(",
"utils",
".",
"get",
"(",
"category",
")",
",",
"' '",
")",
";",
"}",
"else",
"if",
"(",
"key",
"===",
"'itunes:category'",
")",
"{",
"//sometimes itunes:category has it's own itunes:category property",
"setCategory",
"(",
"category",
",",
"'text'",
")",
";",
"utils",
".",
"parse",
"(",
"category",
"[",
"key",
"]",
"||",
"category",
",",
"function",
"(",
"cat",
")",
"{",
"setCategory",
"(",
"cat",
",",
"'text'",
")",
";",
"}",
")",
";",
"}",
"else",
"if",
"(",
"key",
"===",
"'media:category'",
")",
"{",
"splitAndSetCategory",
"(",
"utils",
".",
"get",
"(",
"category",
")",
",",
"'/'",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"var",
"categories",
"=",
"Object",
".",
"keys",
"(",
"categoryMap",
")",
";",
"return",
"categories",
".",
"length",
"&&",
"categories",
".",
"map",
"(",
"function",
"(",
"key",
")",
"{",
"return",
"key",
";",
"}",
")",
";",
"}"
]
| Parses and aggregates an Array of categories for an item or meta node. The following node properties are parsed in
order of most frequently available. Categories for a specific node are uniquely identified and cached by value,
then mapped to an array of categories
category, dc:subject, link, itunes:category, media:category
@param node
@param nodeType
@param feedType
@returns {Array} | [
"Parses",
"and",
"aggregates",
"an",
"Array",
"of",
"categories",
"for",
"an",
"item",
"or",
"meta",
"node",
".",
"The",
"following",
"node",
"properties",
"are",
"parsed",
"in",
"order",
"of",
"most",
"frequently",
"available",
".",
"Categories",
"for",
"a",
"specific",
"node",
"are",
"uniquely",
"identified",
"and",
"cached",
"by",
"value",
"then",
"mapped",
"to",
"an",
"array",
"of",
"categories"
]
| b205aca7a4f72ee04e6ebbe0591fc8eb9078e073 | https://github.com/djett41/node-feedjett/blob/b205aca7a4f72ee04e6ebbe0591fc8eb9078e073/lib/parser.js#L549-L597 |
46,175 | djett41/node-feedjett | lib/parser.js | parseComments | function parseComments (node, nodeType, feedType) {
var comments = utils.get(node.comments);
if (!comments && feedType === 'atom') {
utils.parse(node.link, function (link) {
var linkAttr = link['@'];
if (linkAttr && linkAttr.rel === 'replies' && linkAttr.href) {
comments = linkAttr.href;
//if comments are text/html then break out of loop
if (linkAttr.type === 'text/html') {
return true;
}
}
}, this, true);
}
return comments;
} | javascript | function parseComments (node, nodeType, feedType) {
var comments = utils.get(node.comments);
if (!comments && feedType === 'atom') {
utils.parse(node.link, function (link) {
var linkAttr = link['@'];
if (linkAttr && linkAttr.rel === 'replies' && linkAttr.href) {
comments = linkAttr.href;
//if comments are text/html then break out of loop
if (linkAttr.type === 'text/html') {
return true;
}
}
}, this, true);
}
return comments;
} | [
"function",
"parseComments",
"(",
"node",
",",
"nodeType",
",",
"feedType",
")",
"{",
"var",
"comments",
"=",
"utils",
".",
"get",
"(",
"node",
".",
"comments",
")",
";",
"if",
"(",
"!",
"comments",
"&&",
"feedType",
"===",
"'atom'",
")",
"{",
"utils",
".",
"parse",
"(",
"node",
".",
"link",
",",
"function",
"(",
"link",
")",
"{",
"var",
"linkAttr",
"=",
"link",
"[",
"'@'",
"]",
";",
"if",
"(",
"linkAttr",
"&&",
"linkAttr",
".",
"rel",
"===",
"'replies'",
"&&",
"linkAttr",
".",
"href",
")",
"{",
"comments",
"=",
"linkAttr",
".",
"href",
";",
"//if comments are text/html then break out of loop",
"if",
"(",
"linkAttr",
".",
"type",
"===",
"'text/html'",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
",",
"this",
",",
"true",
")",
";",
"}",
"return",
"comments",
";",
"}"
]
| Parses comments for item nodes
- comments
- highest priority for RSS and ATOM feeds
- link (rel=replies)
- fallback for comments sometimes found in ATOM feeds
@param node
@param nodeType
@param feedType
@returns {*} | [
"Parses",
"comments",
"for",
"item",
"nodes"
]
| b205aca7a4f72ee04e6ebbe0591fc8eb9078e073 | https://github.com/djett41/node-feedjett/blob/b205aca7a4f72ee04e6ebbe0591fc8eb9078e073/lib/parser.js#L613-L631 |
46,176 | djett41/node-feedjett | lib/parser.js | parseEnclosures | function parseEnclosures (node, nodeType, feedType) {
var enclosuresMap = {};
['media:content', 'enclosure', 'link', 'enc:enclosure'].forEach(function (key) {
if (!node[key]) {
return;
}
utils.parse(node[key], function (enc) {
var enclosure,
encAttr = enc['@'];
if (!encAttr) {
return;
}
switch(key) {
case('media:content'):
enclosure = createEnclosure(encAttr.url, encAttr.type || encAttr.medium, encAttr.filesize);
break;
case('enclosure'):
enclosure = createEnclosure(encAttr.url, encAttr.type, encAttr.length);
break;
case('link'):
if (encAttr.rel === 'enclosure' && encAttr.href) {
enclosure = createEnclosure(encAttr.href, encAttr.type, encAttr.length);
}
break;
case('enc:enclosure'):
enclosure = createEnclosure(encAttr.url || encAttr['rdf:resource'], encAttr.type, encAttr.length);
break;
}
if (enclosure) {
enclosuresMap[enclosure.url] = enclosure;
}
});
});
var enclosures = Object.keys(enclosuresMap);
return enclosures.length && enclosures.map(function (key) {
return enclosuresMap[key];
});
} | javascript | function parseEnclosures (node, nodeType, feedType) {
var enclosuresMap = {};
['media:content', 'enclosure', 'link', 'enc:enclosure'].forEach(function (key) {
if (!node[key]) {
return;
}
utils.parse(node[key], function (enc) {
var enclosure,
encAttr = enc['@'];
if (!encAttr) {
return;
}
switch(key) {
case('media:content'):
enclosure = createEnclosure(encAttr.url, encAttr.type || encAttr.medium, encAttr.filesize);
break;
case('enclosure'):
enclosure = createEnclosure(encAttr.url, encAttr.type, encAttr.length);
break;
case('link'):
if (encAttr.rel === 'enclosure' && encAttr.href) {
enclosure = createEnclosure(encAttr.href, encAttr.type, encAttr.length);
}
break;
case('enc:enclosure'):
enclosure = createEnclosure(encAttr.url || encAttr['rdf:resource'], encAttr.type, encAttr.length);
break;
}
if (enclosure) {
enclosuresMap[enclosure.url] = enclosure;
}
});
});
var enclosures = Object.keys(enclosuresMap);
return enclosures.length && enclosures.map(function (key) {
return enclosuresMap[key];
});
} | [
"function",
"parseEnclosures",
"(",
"node",
",",
"nodeType",
",",
"feedType",
")",
"{",
"var",
"enclosuresMap",
"=",
"{",
"}",
";",
"[",
"'media:content'",
",",
"'enclosure'",
",",
"'link'",
",",
"'enc:enclosure'",
"]",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"if",
"(",
"!",
"node",
"[",
"key",
"]",
")",
"{",
"return",
";",
"}",
"utils",
".",
"parse",
"(",
"node",
"[",
"key",
"]",
",",
"function",
"(",
"enc",
")",
"{",
"var",
"enclosure",
",",
"encAttr",
"=",
"enc",
"[",
"'@'",
"]",
";",
"if",
"(",
"!",
"encAttr",
")",
"{",
"return",
";",
"}",
"switch",
"(",
"key",
")",
"{",
"case",
"(",
"'media:content'",
")",
":",
"enclosure",
"=",
"createEnclosure",
"(",
"encAttr",
".",
"url",
",",
"encAttr",
".",
"type",
"||",
"encAttr",
".",
"medium",
",",
"encAttr",
".",
"filesize",
")",
";",
"break",
";",
"case",
"(",
"'enclosure'",
")",
":",
"enclosure",
"=",
"createEnclosure",
"(",
"encAttr",
".",
"url",
",",
"encAttr",
".",
"type",
",",
"encAttr",
".",
"length",
")",
";",
"break",
";",
"case",
"(",
"'link'",
")",
":",
"if",
"(",
"encAttr",
".",
"rel",
"===",
"'enclosure'",
"&&",
"encAttr",
".",
"href",
")",
"{",
"enclosure",
"=",
"createEnclosure",
"(",
"encAttr",
".",
"href",
",",
"encAttr",
".",
"type",
",",
"encAttr",
".",
"length",
")",
";",
"}",
"break",
";",
"case",
"(",
"'enc:enclosure'",
")",
":",
"enclosure",
"=",
"createEnclosure",
"(",
"encAttr",
".",
"url",
"||",
"encAttr",
"[",
"'rdf:resource'",
"]",
",",
"encAttr",
".",
"type",
",",
"encAttr",
".",
"length",
")",
";",
"break",
";",
"}",
"if",
"(",
"enclosure",
")",
"{",
"enclosuresMap",
"[",
"enclosure",
".",
"url",
"]",
"=",
"enclosure",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"var",
"enclosures",
"=",
"Object",
".",
"keys",
"(",
"enclosuresMap",
")",
";",
"return",
"enclosures",
".",
"length",
"&&",
"enclosures",
".",
"map",
"(",
"function",
"(",
"key",
")",
"{",
"return",
"enclosuresMap",
"[",
"key",
"]",
";",
"}",
")",
";",
"}"
]
| Parses and aggregates an Array of enclosures for an item node. The following node properties are parsed in
order of most frequently available. enclosures for a specific node are uniquely identified and cached by url,
then mapped to an array of enclosures
media:content, enclosure, link, enc:enclosure
@param node
@param nodeType
@param feedType
@returns {Array} | [
"Parses",
"and",
"aggregates",
"an",
"Array",
"of",
"enclosures",
"for",
"an",
"item",
"node",
".",
"The",
"following",
"node",
"properties",
"are",
"parsed",
"in",
"order",
"of",
"most",
"frequently",
"available",
".",
"enclosures",
"for",
"a",
"specific",
"node",
"are",
"uniquely",
"identified",
"and",
"cached",
"by",
"url",
"then",
"mapped",
"to",
"an",
"array",
"of",
"enclosures"
]
| b205aca7a4f72ee04e6ebbe0591fc8eb9078e073 | https://github.com/djett41/node-feedjett/blob/b205aca7a4f72ee04e6ebbe0591fc8eb9078e073/lib/parser.js#L683-L727 |
46,177 | djett41/node-feedjett | lib/parser.js | parseSource | function parseSource (node, nodeType, feedType) {
var source = {},
sourceNode = node.source,
temp;
if (!sourceNode) {
return;
}
if (temp = (feedType === 'atom' && utils.get(sourceNode.title)) || utils.get(sourceNode)) {
source.title = temp;
}
if (temp = (feedType === 'atom' && utils.getAttr(sourceNode.link, 'href')) || utils.getAttr(sourceNode, 'url')) {
source.url = temp;
}
return Object.keys(source).length && source;
} | javascript | function parseSource (node, nodeType, feedType) {
var source = {},
sourceNode = node.source,
temp;
if (!sourceNode) {
return;
}
if (temp = (feedType === 'atom' && utils.get(sourceNode.title)) || utils.get(sourceNode)) {
source.title = temp;
}
if (temp = (feedType === 'atom' && utils.getAttr(sourceNode.link, 'href')) || utils.getAttr(sourceNode, 'url')) {
source.url = temp;
}
return Object.keys(source).length && source;
} | [
"function",
"parseSource",
"(",
"node",
",",
"nodeType",
",",
"feedType",
")",
"{",
"var",
"source",
"=",
"{",
"}",
",",
"sourceNode",
"=",
"node",
".",
"source",
",",
"temp",
";",
"if",
"(",
"!",
"sourceNode",
")",
"{",
"return",
";",
"}",
"if",
"(",
"temp",
"=",
"(",
"feedType",
"===",
"'atom'",
"&&",
"utils",
".",
"get",
"(",
"sourceNode",
".",
"title",
")",
")",
"||",
"utils",
".",
"get",
"(",
"sourceNode",
")",
")",
"{",
"source",
".",
"title",
"=",
"temp",
";",
"}",
"if",
"(",
"temp",
"=",
"(",
"feedType",
"===",
"'atom'",
"&&",
"utils",
".",
"getAttr",
"(",
"sourceNode",
".",
"link",
",",
"'href'",
")",
")",
"||",
"utils",
".",
"getAttr",
"(",
"sourceNode",
",",
"'url'",
")",
")",
"{",
"source",
".",
"url",
"=",
"temp",
";",
"}",
"return",
"Object",
".",
"keys",
"(",
"source",
")",
".",
"length",
"&&",
"source",
";",
"}"
]
| Parse the source of an item node
@param node
@param nodeType
@param feedType | [
"Parse",
"the",
"source",
"of",
"an",
"item",
"node"
]
| b205aca7a4f72ee04e6ebbe0591fc8eb9078e073 | https://github.com/djett41/node-feedjett/blob/b205aca7a4f72ee04e6ebbe0591fc8eb9078e073/lib/parser.js#L756-L773 |
46,178 | djett41/node-feedjett | lib/utils.js | get | function get(obj, subkey) {
if (!obj) { return; }
if (Array.isArray(obj)) {
obj = obj[0];
}
return obj[subkey || '#'];
} | javascript | function get(obj, subkey) {
if (!obj) { return; }
if (Array.isArray(obj)) {
obj = obj[0];
}
return obj[subkey || '#'];
} | [
"function",
"get",
"(",
"obj",
",",
"subkey",
")",
"{",
"if",
"(",
"!",
"obj",
")",
"{",
"return",
";",
"}",
"if",
"(",
"Array",
".",
"isArray",
"(",
"obj",
")",
")",
"{",
"obj",
"=",
"obj",
"[",
"0",
"]",
";",
"}",
"return",
"obj",
"[",
"subkey",
"||",
"'#'",
"]",
";",
"}"
]
| Utility function to test for and extract a subkey.
var obj = { '#': 'foo', 'bar': 'baz' };
get(obj);
// => 'foo'
get(obj, 'bar');
// => 'baz'
@param {Object} obj
@param {String} [subkey="#"] By default, use the '#' key, but you may pass any key you like
@return {*} Returns the value of the selected key or 'null' if undefined. | [
"Utility",
"function",
"to",
"test",
"for",
"and",
"extract",
"a",
"subkey",
"."
]
| b205aca7a4f72ee04e6ebbe0591fc8eb9078e073 | https://github.com/djett41/node-feedjett/blob/b205aca7a4f72ee04e6ebbe0591fc8eb9078e073/lib/utils.js#L38-L45 |
46,179 | djett41/node-feedjett | lib/utils.js | getAttr | function getAttr(obj, attr) {
if (!obj) { return; }
if (Array.isArray(obj)) {
obj = obj[0];
}
return (attr && obj['@']) ? obj['@'][attr] : obj['@'];
} | javascript | function getAttr(obj, attr) {
if (!obj) { return; }
if (Array.isArray(obj)) {
obj = obj[0];
}
return (attr && obj['@']) ? obj['@'][attr] : obj['@'];
} | [
"function",
"getAttr",
"(",
"obj",
",",
"attr",
")",
"{",
"if",
"(",
"!",
"obj",
")",
"{",
"return",
";",
"}",
"if",
"(",
"Array",
".",
"isArray",
"(",
"obj",
")",
")",
"{",
"obj",
"=",
"obj",
"[",
"0",
"]",
";",
"}",
"return",
"(",
"attr",
"&&",
"obj",
"[",
"'@'",
"]",
")",
"?",
"obj",
"[",
"'@'",
"]",
"[",
"attr",
"]",
":",
"obj",
"[",
"'@'",
"]",
";",
"}"
]
| Fetches a specific attribute or the whole attribute for an object
@param obj
@param attr
@returns {*} | [
"Fetches",
"a",
"specific",
"attribute",
"or",
"the",
"whole",
"attribute",
"for",
"an",
"object"
]
| b205aca7a4f72ee04e6ebbe0591fc8eb9078e073 | https://github.com/djett41/node-feedjett/blob/b205aca7a4f72ee04e6ebbe0591fc8eb9078e073/lib/utils.js#L56-L64 |
46,180 | djett41/node-feedjett | lib/utils.js | parse | function parse (el, parseFn, context, canBreak) {
if (!el) { return; }
if (!Array.isArray(el)) {
parseFn.call(context, el);
} else if (canBreak) {
el.some(parseFn, context);
} else {
el.forEach(parseFn, context);
}
} | javascript | function parse (el, parseFn, context, canBreak) {
if (!el) { return; }
if (!Array.isArray(el)) {
parseFn.call(context, el);
} else if (canBreak) {
el.some(parseFn, context);
} else {
el.forEach(parseFn, context);
}
} | [
"function",
"parse",
"(",
"el",
",",
"parseFn",
",",
"context",
",",
"canBreak",
")",
"{",
"if",
"(",
"!",
"el",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"el",
")",
")",
"{",
"parseFn",
".",
"call",
"(",
"context",
",",
"el",
")",
";",
"}",
"else",
"if",
"(",
"canBreak",
")",
"{",
"el",
".",
"some",
"(",
"parseFn",
",",
"context",
")",
";",
"}",
"else",
"{",
"el",
".",
"forEach",
"(",
"parseFn",
",",
"context",
")",
";",
"}",
"}"
]
| Invokes a callback with a specified context.
If the el is an array, the callback will be called for each item in the array
@param el
@param parseFn
@param context | [
"Invokes",
"a",
"callback",
"with",
"a",
"specified",
"context",
".",
"If",
"the",
"el",
"is",
"an",
"array",
"the",
"callback",
"will",
"be",
"called",
"for",
"each",
"item",
"in",
"the",
"array"
]
| b205aca7a4f72ee04e6ebbe0591fc8eb9078e073 | https://github.com/djett41/node-feedjett/blob/b205aca7a4f72ee04e6ebbe0591fc8eb9078e073/lib/utils.js#L124-L134 |
46,181 | djett41/node-feedjett | lib/utils.js | strArrayToObj | function strArrayToObj (array) {
return array && array.reduce(function(o, v) {
o[v] = true;
return o;
}, {});
} | javascript | function strArrayToObj (array) {
return array && array.reduce(function(o, v) {
o[v] = true;
return o;
}, {});
} | [
"function",
"strArrayToObj",
"(",
"array",
")",
"{",
"return",
"array",
"&&",
"array",
".",
"reduce",
"(",
"function",
"(",
"o",
",",
"v",
")",
"{",
"o",
"[",
"v",
"]",
"=",
"true",
";",
"return",
"o",
";",
"}",
",",
"{",
"}",
")",
";",
"}"
]
| Converts a String array to object. Used for whitelisting and blacklisting feed properties
@param array
@returns {*} | [
"Converts",
"a",
"String",
"array",
"to",
"object",
".",
"Used",
"for",
"whitelisting",
"and",
"blacklisting",
"feed",
"properties"
]
| b205aca7a4f72ee04e6ebbe0591fc8eb9078e073 | https://github.com/djett41/node-feedjett/blob/b205aca7a4f72ee04e6ebbe0591fc8eb9078e073/lib/utils.js#L144-L149 |
46,182 | djett41/node-feedjett | lib/utils.js | createOpenTag | function createOpenTag (tagName, attrs) {
var attrString = Object.keys(attrs).map(function (key) {
return ' ' + key + '="' + attrs[key] + '"';
}).join('');
return '<' + tagName + attrString + '>';
} | javascript | function createOpenTag (tagName, attrs) {
var attrString = Object.keys(attrs).map(function (key) {
return ' ' + key + '="' + attrs[key] + '"';
}).join('');
return '<' + tagName + attrString + '>';
} | [
"function",
"createOpenTag",
"(",
"tagName",
",",
"attrs",
")",
"{",
"var",
"attrString",
"=",
"Object",
".",
"keys",
"(",
"attrs",
")",
".",
"map",
"(",
"function",
"(",
"key",
")",
"{",
"return",
"' '",
"+",
"key",
"+",
"'=\"'",
"+",
"attrs",
"[",
"key",
"]",
"+",
"'\"'",
";",
"}",
")",
".",
"join",
"(",
"''",
")",
";",
"return",
"'<'",
"+",
"tagName",
"+",
"attrString",
"+",
"'>'",
";",
"}"
]
| Creates an opening XML tag based on tagName and attributes
@param tagName
@param attrs
@returns {string} | [
"Creates",
"an",
"opening",
"XML",
"tag",
"based",
"on",
"tagName",
"and",
"attributes"
]
| b205aca7a4f72ee04e6ebbe0591fc8eb9078e073 | https://github.com/djett41/node-feedjett/blob/b205aca7a4f72ee04e6ebbe0591fc8eb9078e073/lib/utils.js#L194-L200 |
46,183 | djett41/node-feedjett | lib/utils.js | getStandardTimeOffset | function getStandardTimeOffset(date) {
var jan = new Date(date.getFullYear(), 0, 1);
var jul = new Date(date.getFullYear(), 6, 1);
return Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
} | javascript | function getStandardTimeOffset(date) {
var jan = new Date(date.getFullYear(), 0, 1);
var jul = new Date(date.getFullYear(), 6, 1);
return Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
} | [
"function",
"getStandardTimeOffset",
"(",
"date",
")",
"{",
"var",
"jan",
"=",
"new",
"Date",
"(",
"date",
".",
"getFullYear",
"(",
")",
",",
"0",
",",
"1",
")",
";",
"var",
"jul",
"=",
"new",
"Date",
"(",
"date",
".",
"getFullYear",
"(",
")",
",",
"6",
",",
"1",
")",
";",
"return",
"Math",
".",
"max",
"(",
"jan",
".",
"getTimezoneOffset",
"(",
")",
",",
"jul",
".",
"getTimezoneOffset",
"(",
")",
")",
";",
"}"
]
| Returns the standard time timezone offset regardless of whether the current time is on standard or daylight saving time.
@param node
@param nodeType
@param feedType | [
"Returns",
"the",
"standard",
"time",
"timezone",
"offset",
"regardless",
"of",
"whether",
"the",
"current",
"time",
"is",
"on",
"standard",
"or",
"daylight",
"saving",
"time",
"."
]
| b205aca7a4f72ee04e6ebbe0591fc8eb9078e073 | https://github.com/djett41/node-feedjett/blob/b205aca7a4f72ee04e6ebbe0591fc8eb9078e073/lib/utils.js#L222-L226 |
46,184 | djett41/node-feedjett | lib/utils.js | fixInvalidDate | function fixInvalidDate(dateString) {
if (!dateString) {
return;
}
//Convert invalid dates' timezones to GMT using timezoneMap
dateString = dateString.replace(/BST?/i, function (match) {
return timezoneMap[match];
});
//Some dates come in as ET, CT etc.. and some don't have the correct offset.
//Matches /ET/EDT/EST/CT/CDT/CST/MT/MDT/MST/PT/PDT/PST if found at the end of a date string
var newDateString = dateString.replace(/(E|C|M|P)[DS+]?T$/i, function (match) {
var firstChar = match.charAt(0);
return isDaylightSavingsTime() ? (firstChar + 'DT') : (firstChar + 'ST');
});
return new Date(newDateString);
} | javascript | function fixInvalidDate(dateString) {
if (!dateString) {
return;
}
//Convert invalid dates' timezones to GMT using timezoneMap
dateString = dateString.replace(/BST?/i, function (match) {
return timezoneMap[match];
});
//Some dates come in as ET, CT etc.. and some don't have the correct offset.
//Matches /ET/EDT/EST/CT/CDT/CST/MT/MDT/MST/PT/PDT/PST if found at the end of a date string
var newDateString = dateString.replace(/(E|C|M|P)[DS+]?T$/i, function (match) {
var firstChar = match.charAt(0);
return isDaylightSavingsTime() ? (firstChar + 'DT') : (firstChar + 'ST');
});
return new Date(newDateString);
} | [
"function",
"fixInvalidDate",
"(",
"dateString",
")",
"{",
"if",
"(",
"!",
"dateString",
")",
"{",
"return",
";",
"}",
"//Convert invalid dates' timezones to GMT using timezoneMap",
"dateString",
"=",
"dateString",
".",
"replace",
"(",
"/",
"BST?",
"/",
"i",
",",
"function",
"(",
"match",
")",
"{",
"return",
"timezoneMap",
"[",
"match",
"]",
";",
"}",
")",
";",
"//Some dates come in as ET, CT etc.. and some don't have the correct offset.",
"//Matches /ET/EDT/EST/CT/CDT/CST/MT/MDT/MST/PT/PDT/PST if found at the end of a date string",
"var",
"newDateString",
"=",
"dateString",
".",
"replace",
"(",
"/",
"(E|C|M|P)[DS+]?T$",
"/",
"i",
",",
"function",
"(",
"match",
")",
"{",
"var",
"firstChar",
"=",
"match",
".",
"charAt",
"(",
"0",
")",
";",
"return",
"isDaylightSavingsTime",
"(",
")",
"?",
"(",
"firstChar",
"+",
"'DT'",
")",
":",
"(",
"firstChar",
"+",
"'ST'",
")",
";",
"}",
")",
";",
"return",
"new",
"Date",
"(",
"newDateString",
")",
";",
"}"
]
| Attempts to fix invalid dates coming in from different feeds
@param dateString
@returns {Date} | [
"Attempts",
"to",
"fix",
"invalid",
"dates",
"coming",
"in",
"from",
"different",
"feeds"
]
| b205aca7a4f72ee04e6ebbe0591fc8eb9078e073 | https://github.com/djett41/node-feedjett/blob/b205aca7a4f72ee04e6ebbe0591fc8eb9078e073/lib/utils.js#L246-L264 |
46,185 | djett41/node-feedjett | lib/utils.js | getDate | function getDate (dateString) {
var date = new Date(dateString);
if (Object.prototype.toString.call(date) === '[object Date]' && !isNaN(date.getTime())) {
return date;
}
//try to fix invalid date
date = fixInvalidDate(dateString);
//if date still isn't valid there's not more we can do..
if (!isNaN(date.getTime())) {
return date;
}
} | javascript | function getDate (dateString) {
var date = new Date(dateString);
if (Object.prototype.toString.call(date) === '[object Date]' && !isNaN(date.getTime())) {
return date;
}
//try to fix invalid date
date = fixInvalidDate(dateString);
//if date still isn't valid there's not more we can do..
if (!isNaN(date.getTime())) {
return date;
}
} | [
"function",
"getDate",
"(",
"dateString",
")",
"{",
"var",
"date",
"=",
"new",
"Date",
"(",
"dateString",
")",
";",
"if",
"(",
"Object",
".",
"prototype",
".",
"toString",
".",
"call",
"(",
"date",
")",
"===",
"'[object Date]'",
"&&",
"!",
"isNaN",
"(",
"date",
".",
"getTime",
"(",
")",
")",
")",
"{",
"return",
"date",
";",
"}",
"//try to fix invalid date",
"date",
"=",
"fixInvalidDate",
"(",
"dateString",
")",
";",
"//if date still isn't valid there's not more we can do..",
"if",
"(",
"!",
"isNaN",
"(",
"date",
".",
"getTime",
"(",
")",
")",
")",
"{",
"return",
"date",
";",
"}",
"}"
]
| Parses a date string to a date
@param dateString | [
"Parses",
"a",
"date",
"string",
"to",
"a",
"date"
]
| b205aca7a4f72ee04e6ebbe0591fc8eb9078e073 | https://github.com/djett41/node-feedjett/blob/b205aca7a4f72ee04e6ebbe0591fc8eb9078e073/lib/utils.js#L272-L286 |
46,186 | sergeyt/fetch-stream | src/parser.js | makeConcat | function makeConcat(chunkType) {
switch (chunkType) {
case BUFFER:
return (a, b) => Buffer.concat([a, b]);
default:
return (a, b) => {
// console.log('[%d, %d]', a.length, b.length);
const t = new Uint8Array(a.length + b.length);
t.set(a);
t.set(b, a.length);
// console.log('%d: %s', t.length, new Buffer(t).toString('utf8'));
return t;
};
}
} | javascript | function makeConcat(chunkType) {
switch (chunkType) {
case BUFFER:
return (a, b) => Buffer.concat([a, b]);
default:
return (a, b) => {
// console.log('[%d, %d]', a.length, b.length);
const t = new Uint8Array(a.length + b.length);
t.set(a);
t.set(b, a.length);
// console.log('%d: %s', t.length, new Buffer(t).toString('utf8'));
return t;
};
}
} | [
"function",
"makeConcat",
"(",
"chunkType",
")",
"{",
"switch",
"(",
"chunkType",
")",
"{",
"case",
"BUFFER",
":",
"return",
"(",
"a",
",",
"b",
")",
"=>",
"Buffer",
".",
"concat",
"(",
"[",
"a",
",",
"b",
"]",
")",
";",
"default",
":",
"return",
"(",
"a",
",",
"b",
")",
"=>",
"{",
"// console.log('[%d, %d]', a.length, b.length);",
"const",
"t",
"=",
"new",
"Uint8Array",
"(",
"a",
".",
"length",
"+",
"b",
".",
"length",
")",
";",
"t",
".",
"set",
"(",
"a",
")",
";",
"t",
".",
"set",
"(",
"b",
",",
"a",
".",
"length",
")",
";",
"// console.log('%d: %s', t.length, new Buffer(t).toString('utf8'));",
"return",
"t",
";",
"}",
";",
"}",
"}"
]
| Makes function to concat two byte chunks.
@param {Boolean} [chunkType] Specifies type of input chunks.
@return {Function} The function to concat two byte chunks. | [
"Makes",
"function",
"to",
"concat",
"two",
"byte",
"chunks",
"."
]
| eab91c059ce3b1d172fd44890769c761bb4b7aa3 | https://github.com/sergeyt/fetch-stream/blob/eab91c059ce3b1d172fd44890769c761bb4b7aa3/src/parser.js#L47-L61 |
46,187 | jlengstorf/responsive-lazyload.js | source/scripts/responsive-lazyload.js | isElementVisible | function isElementVisible(el) {
/*
* Checks if element (or an ancestor) is hidden via style properties.
* See https://stackoverflow.com/a/21696585/463471
*/
const isCurrentlyVisible = el.offsetParent !== null;
// Check if any part of the element is vertically within the viewport.
const position = el.getBoundingClientRect();
const wH =
window.innerHeight ||
/* istanbul ignore next */ document.documentElement.clientHeight;
const isWithinViewport =
(position.top >= 0 && position.top <= wH) ||
(position.bottom >= 0 && position.bottom <= wH);
return isCurrentlyVisible && isWithinViewport;
} | javascript | function isElementVisible(el) {
/*
* Checks if element (or an ancestor) is hidden via style properties.
* See https://stackoverflow.com/a/21696585/463471
*/
const isCurrentlyVisible = el.offsetParent !== null;
// Check if any part of the element is vertically within the viewport.
const position = el.getBoundingClientRect();
const wH =
window.innerHeight ||
/* istanbul ignore next */ document.documentElement.clientHeight;
const isWithinViewport =
(position.top >= 0 && position.top <= wH) ||
(position.bottom >= 0 && position.bottom <= wH);
return isCurrentlyVisible && isWithinViewport;
} | [
"function",
"isElementVisible",
"(",
"el",
")",
"{",
"/*\n * Checks if element (or an ancestor) is hidden via style properties.\n * See https://stackoverflow.com/a/21696585/463471\n */",
"const",
"isCurrentlyVisible",
"=",
"el",
".",
"offsetParent",
"!==",
"null",
";",
"// Check if any part of the element is vertically within the viewport.",
"const",
"position",
"=",
"el",
".",
"getBoundingClientRect",
"(",
")",
";",
"const",
"wH",
"=",
"window",
".",
"innerHeight",
"||",
"/* istanbul ignore next */",
"document",
".",
"documentElement",
".",
"clientHeight",
";",
"const",
"isWithinViewport",
"=",
"(",
"position",
".",
"top",
">=",
"0",
"&&",
"position",
".",
"top",
"<=",
"wH",
")",
"||",
"(",
"position",
".",
"bottom",
">=",
"0",
"&&",
"position",
".",
"bottom",
"<=",
"wH",
")",
";",
"return",
"isCurrentlyVisible",
"&&",
"isWithinViewport",
";",
"}"
]
| Check if an element is visible at all in the viewport.
It would be cool to use an IntersectionObserver here, but browser support
isn’t there yet: http://caniuse.com/#feat=intersectionobserver
@param {Element} el the element to check
@return {Boolean} `true` if the element is visible at all; `false` if not | [
"Check",
"if",
"an",
"element",
"is",
"visible",
"at",
"all",
"in",
"the",
"viewport",
"."
]
| d375eedd6bf48b1cfa54b301fd77f59198c2ab73 | https://github.com/jlengstorf/responsive-lazyload.js/blob/d375eedd6bf48b1cfa54b301fd77f59198c2ab73/source/scripts/responsive-lazyload.js#L10-L27 |
46,188 | Lanfei/websocket-lib | lib/frame.js | Receiver | function Receiver() {
stream.Duplex.call(this, {
readableObjectMode: true
});
this._buffer = null;
this._frame = new Frame();
this._state = WAITING_FOR_HEADER;
} | javascript | function Receiver() {
stream.Duplex.call(this, {
readableObjectMode: true
});
this._buffer = null;
this._frame = new Frame();
this._state = WAITING_FOR_HEADER;
} | [
"function",
"Receiver",
"(",
")",
"{",
"stream",
".",
"Duplex",
".",
"call",
"(",
"this",
",",
"{",
"readableObjectMode",
":",
"true",
"}",
")",
";",
"this",
".",
"_buffer",
"=",
"null",
";",
"this",
".",
"_frame",
"=",
"new",
"Frame",
"(",
")",
";",
"this",
".",
"_state",
"=",
"WAITING_FOR_HEADER",
";",
"}"
]
| WebSocket Frame Receiver
@constructor
@extends stream.Duplex | [
"WebSocket",
"Frame",
"Receiver"
]
| d39f704490fb91b1e2897712b280c0e5ac79e123 | https://github.com/Lanfei/websocket-lib/blob/d39f704490fb91b1e2897712b280c0e5ac79e123/lib/frame.js#L174-L182 |
46,189 | THEjoezack/BoxPusher | public/js-roguelike-skeleton/src/mouse.js | function(e){
if(e.type === 'mousemove' && this.onHover){
this.onHover(e.clientX, e.clientY);
}
else if(e.type === 'mouseenter' && this.onHover){
this.onHover(e.clientX, e.clientY);
}
else if(e.type === 'mouseleave' && this.onHover){
this.onHover(false);
}
else if(e.type === 'click' && this.onClick){
this.onClick(e.clientX, e.clientY);
}
} | javascript | function(e){
if(e.type === 'mousemove' && this.onHover){
this.onHover(e.clientX, e.clientY);
}
else if(e.type === 'mouseenter' && this.onHover){
this.onHover(e.clientX, e.clientY);
}
else if(e.type === 'mouseleave' && this.onHover){
this.onHover(false);
}
else if(e.type === 'click' && this.onClick){
this.onClick(e.clientX, e.clientY);
}
} | [
"function",
"(",
"e",
")",
"{",
"if",
"(",
"e",
".",
"type",
"===",
"'mousemove'",
"&&",
"this",
".",
"onHover",
")",
"{",
"this",
".",
"onHover",
"(",
"e",
".",
"clientX",
",",
"e",
".",
"clientY",
")",
";",
"}",
"else",
"if",
"(",
"e",
".",
"type",
"===",
"'mouseenter'",
"&&",
"this",
".",
"onHover",
")",
"{",
"this",
".",
"onHover",
"(",
"e",
".",
"clientX",
",",
"e",
".",
"clientY",
")",
";",
"}",
"else",
"if",
"(",
"e",
".",
"type",
"===",
"'mouseleave'",
"&&",
"this",
".",
"onHover",
")",
"{",
"this",
".",
"onHover",
"(",
"false",
")",
";",
"}",
"else",
"if",
"(",
"e",
".",
"type",
"===",
"'click'",
"&&",
"this",
".",
"onClick",
")",
"{",
"this",
".",
"onClick",
"(",
"e",
".",
"clientX",
",",
"e",
".",
"clientY",
")",
";",
"}",
"}"
]
| Hander for mouse events
@method handleEvent
@param {Event} e - mouse event | [
"Hander",
"for",
"mouse",
"events"
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/js-roguelike-skeleton/src/mouse.js#L48-L61 |
|
46,190 | THEjoezack/BoxPusher | public/js-roguelike-skeleton/src/mouse.js | function(e) {
if(this.onHover){
var coords = this.game.renderer.mouseToTileCoords(e.clientX, e.clientY);
this.onHover(coords);
}
} | javascript | function(e) {
if(this.onHover){
var coords = this.game.renderer.mouseToTileCoords(e.clientX, e.clientY);
this.onHover(coords);
}
} | [
"function",
"(",
"e",
")",
"{",
"if",
"(",
"this",
".",
"onHover",
")",
"{",
"var",
"coords",
"=",
"this",
".",
"game",
".",
"renderer",
".",
"mouseToTileCoords",
"(",
"e",
".",
"clientX",
",",
"e",
".",
"clientY",
")",
";",
"this",
".",
"onHover",
"(",
"coords",
")",
";",
"}",
"}"
]
| Hander for mouse move events
@method mouseMove
@param {Event} e - mouse event | [
"Hander",
"for",
"mouse",
"move",
"events"
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/js-roguelike-skeleton/src/mouse.js#L68-L73 |
|
46,191 | THEjoezack/BoxPusher | public/js-roguelike-skeleton/src/mouse.js | function(element){
if(this._boundElement){
this.stopListening();
}
element.addEventListener('mousemove', this);
element.addEventListener('mouseenter', this);
element.addEventListener('mouseleave', this);
element.addEventListener('click', this);
this._boundElement = element;
} | javascript | function(element){
if(this._boundElement){
this.stopListening();
}
element.addEventListener('mousemove', this);
element.addEventListener('mouseenter', this);
element.addEventListener('mouseleave', this);
element.addEventListener('click', this);
this._boundElement = element;
} | [
"function",
"(",
"element",
")",
"{",
"if",
"(",
"this",
".",
"_boundElement",
")",
"{",
"this",
".",
"stopListening",
"(",
")",
";",
"}",
"element",
".",
"addEventListener",
"(",
"'mousemove'",
",",
"this",
")",
";",
"element",
".",
"addEventListener",
"(",
"'mouseenter'",
",",
"this",
")",
";",
"element",
".",
"addEventListener",
"(",
"'mouseleave'",
",",
"this",
")",
";",
"element",
".",
"addEventListener",
"(",
"'click'",
",",
"this",
")",
";",
"this",
".",
"_boundElement",
"=",
"element",
";",
"}"
]
| Binds event listener for mouse events.
@method startListening
@param {HTMLElement} element - The dom element being rendered to. | [
"Binds",
"event",
"listener",
"for",
"mouse",
"events",
"."
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/js-roguelike-skeleton/src/mouse.js#L80-L91 |
|
46,192 | THEjoezack/BoxPusher | public/js-roguelike-skeleton/src/mouse.js | function(){
if(!this._boundElement){
return false;
}
var el = this._boundElement;
el.removeEventListener('mousemove', this);
el.removeEventListener('mouseenter', this);
el.removeEventListener('mouseleave', this);
el.removeEventListener('click', this);
} | javascript | function(){
if(!this._boundElement){
return false;
}
var el = this._boundElement;
el.removeEventListener('mousemove', this);
el.removeEventListener('mouseenter', this);
el.removeEventListener('mouseleave', this);
el.removeEventListener('click', this);
} | [
"function",
"(",
")",
"{",
"if",
"(",
"!",
"this",
".",
"_boundElement",
")",
"{",
"return",
"false",
";",
"}",
"var",
"el",
"=",
"this",
".",
"_boundElement",
";",
"el",
".",
"removeEventListener",
"(",
"'mousemove'",
",",
"this",
")",
";",
"el",
".",
"removeEventListener",
"(",
"'mouseenter'",
",",
"this",
")",
";",
"el",
".",
"removeEventListener",
"(",
"'mouseleave'",
",",
"this",
")",
";",
"el",
".",
"removeEventListener",
"(",
"'click'",
",",
"this",
")",
";",
"}"
]
| Unbinds event listener for mouse events.
@method stopListening | [
"Unbinds",
"event",
"listener",
"for",
"mouse",
"events",
"."
]
| ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5 | https://github.com/THEjoezack/BoxPusher/blob/ebd506f7e61d10e4d493cf1cad1fbd4b43be28d5/public/js-roguelike-skeleton/src/mouse.js#L97-L106 |
|
46,193 | bjorg/jDoc | src/jdoc.js | function(array, json) {
var i;
if (typeof json === 'object' && typeof json.length === 'number') {
for (i = 0; i < json.length; ++i) {
array.push(json[i]);
}
} else {
array.push(json);
}
} | javascript | function(array, json) {
var i;
if (typeof json === 'object' && typeof json.length === 'number') {
for (i = 0; i < json.length; ++i) {
array.push(json[i]);
}
} else {
array.push(json);
}
} | [
"function",
"(",
"array",
",",
"json",
")",
"{",
"var",
"i",
";",
"if",
"(",
"typeof",
"json",
"===",
"'object'",
"&&",
"typeof",
"json",
".",
"length",
"===",
"'number'",
")",
"{",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"json",
".",
"length",
";",
"++",
"i",
")",
"{",
"array",
".",
"push",
"(",
"json",
"[",
"i",
"]",
")",
";",
"}",
"}",
"else",
"{",
"array",
".",
"push",
"(",
"json",
")",
";",
"}",
"}"
]
| private jDoc functions | [
"private",
"jDoc",
"functions"
]
| 14ace8ae07320e180a1445f25881d31b0c477540 | https://github.com/bjorg/jDoc/blob/14ace8ae07320e180a1445f25881d31b0c477540/src/jdoc.js#L87-L96 |
|
46,194 | jonjomckay/jjgraph | javascript/examples/grapheditor/www/js/Editor.js | function(sender, evt)
{
var cand = graph.getSelectionCellsForChanges(evt.getProperty('edit').changes);
var model = graph.getModel();
var cells = [];
for (var i = 0; i < cand.length; i++)
{
if ((model.isVertex(cand[i]) || model.isEdge(cand[i])) && graph.view.getState(cand[i]) != null)
{
cells.push(cand[i]);
}
}
graph.setSelectionCells(cells);
} | javascript | function(sender, evt)
{
var cand = graph.getSelectionCellsForChanges(evt.getProperty('edit').changes);
var model = graph.getModel();
var cells = [];
for (var i = 0; i < cand.length; i++)
{
if ((model.isVertex(cand[i]) || model.isEdge(cand[i])) && graph.view.getState(cand[i]) != null)
{
cells.push(cand[i]);
}
}
graph.setSelectionCells(cells);
} | [
"function",
"(",
"sender",
",",
"evt",
")",
"{",
"var",
"cand",
"=",
"graph",
".",
"getSelectionCellsForChanges",
"(",
"evt",
".",
"getProperty",
"(",
"'edit'",
")",
".",
"changes",
")",
";",
"var",
"model",
"=",
"graph",
".",
"getModel",
"(",
")",
";",
"var",
"cells",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"cand",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"(",
"model",
".",
"isVertex",
"(",
"cand",
"[",
"i",
"]",
")",
"||",
"model",
".",
"isEdge",
"(",
"cand",
"[",
"i",
"]",
")",
")",
"&&",
"graph",
".",
"view",
".",
"getState",
"(",
"cand",
"[",
"i",
"]",
")",
"!=",
"null",
")",
"{",
"cells",
".",
"push",
"(",
"cand",
"[",
"i",
"]",
")",
";",
"}",
"}",
"graph",
".",
"setSelectionCells",
"(",
"cells",
")",
";",
"}"
]
| Keeps the selection in sync with the history | [
"Keeps",
"the",
"selection",
"in",
"sync",
"with",
"the",
"history"
]
| f041596ea8cb33e7a47e8c029008f13b31a92469 | https://github.com/jonjomckay/jjgraph/blob/f041596ea8cb33e7a47e8c029008f13b31a92469/javascript/examples/grapheditor/www/js/Editor.js#L596-L611 |
|
46,195 | sethvincent/read-directory | transform.js | end | function end (next) {
filenames(dir, obj).forEach(function (filename) {
sm.emit('file', filename)
})
next()
} | javascript | function end (next) {
filenames(dir, obj).forEach(function (filename) {
sm.emit('file', filename)
})
next()
} | [
"function",
"end",
"(",
"next",
")",
"{",
"filenames",
"(",
"dir",
",",
"obj",
")",
".",
"forEach",
"(",
"function",
"(",
"filename",
")",
"{",
"sm",
".",
"emit",
"(",
"'file'",
",",
"filename",
")",
"}",
")",
"next",
"(",
")",
"}"
]
| Make sure all files are watched | [
"Make",
"sure",
"all",
"files",
"are",
"watched"
]
| e154975071f1dd68ecd4ccb4b329aa00dc1b056e | https://github.com/sethvincent/read-directory/blob/e154975071f1dd68ecd4ccb4b329aa00dc1b056e/transform.js#L33-L38 |
46,196 | nickzuber/needle | src/BitArray/bitArray.js | function(n){
if(typeof n === 'number'){
return n;
}
if(typeof n !== 'string'){
n = JSON.stringify(n)
}
var res = 0;
n.split("").map(function(bit){
res += bit.charCodeAt(0);
});
return res;
} | javascript | function(n){
if(typeof n === 'number'){
return n;
}
if(typeof n !== 'string'){
n = JSON.stringify(n)
}
var res = 0;
n.split("").map(function(bit){
res += bit.charCodeAt(0);
});
return res;
} | [
"function",
"(",
"n",
")",
"{",
"if",
"(",
"typeof",
"n",
"===",
"'number'",
")",
"{",
"return",
"n",
";",
"}",
"if",
"(",
"typeof",
"n",
"!==",
"'string'",
")",
"{",
"n",
"=",
"JSON",
".",
"stringify",
"(",
"n",
")",
"}",
"var",
"res",
"=",
"0",
";",
"n",
".",
"split",
"(",
"\"\"",
")",
".",
"map",
"(",
"function",
"(",
"bit",
")",
"{",
"res",
"+=",
"bit",
".",
"charCodeAt",
"(",
"0",
")",
";",
"}",
")",
";",
"return",
"res",
";",
"}"
]
| Transforms input into a number.
@param {*} input to become a number
@return {number} number version of input | [
"Transforms",
"input",
"into",
"a",
"number",
"."
]
| 9565b3c193b93d67ffed39d430eba395a7bb5531 | https://github.com/nickzuber/needle/blob/9565b3c193b93d67ffed39d430eba395a7bb5531/src/BitArray/bitArray.js#L26-L38 |
|
46,197 | nickzuber/needle | src/BitArray/bitArray.js | function(size){
this.data = [];
if(typeof size === 'undefined'){
return; // Empty instance of a bit array
}
if(typeof size !== 'number'){
size = shred(size);
}
for(var i=0; i<Math.ceil(size/INTEGER_SIZE); ++i){
this.data.push(0);
}
} | javascript | function(size){
this.data = [];
if(typeof size === 'undefined'){
return; // Empty instance of a bit array
}
if(typeof size !== 'number'){
size = shred(size);
}
for(var i=0; i<Math.ceil(size/INTEGER_SIZE); ++i){
this.data.push(0);
}
} | [
"function",
"(",
"size",
")",
"{",
"this",
".",
"data",
"=",
"[",
"]",
";",
"if",
"(",
"typeof",
"size",
"===",
"'undefined'",
")",
"{",
"return",
";",
"// Empty instance of a bit array",
"}",
"if",
"(",
"typeof",
"size",
"!==",
"'number'",
")",
"{",
"size",
"=",
"shred",
"(",
"size",
")",
";",
"}",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"Math",
".",
"ceil",
"(",
"size",
"/",
"INTEGER_SIZE",
")",
";",
"++",
"i",
")",
"{",
"this",
".",
"data",
".",
"push",
"(",
"0",
")",
";",
"}",
"}"
]
| Instantiates a bit array with given size.
@param {number} [size = 0] the size of the bit array
@return {void} | [
"Instantiates",
"a",
"bit",
"array",
"with",
"given",
"size",
"."
]
| 9565b3c193b93d67ffed39d430eba395a7bb5531 | https://github.com/nickzuber/needle/blob/9565b3c193b93d67ffed39d430eba395a7bb5531/src/BitArray/bitArray.js#L50-L61 |
|
46,198 | juttle/juttle-elastic-adapter | lib/query.js | bridge_fetch | function bridge_fetch(size) {
var bridge_time = new JuttleMoment(last_seen_timestamp);
var time_filter = {term: {}};
time_filter.term[timeField] = bridge_time.valueOf();
var body = make_body(filter, null, null, direction, time_filter, size, timeField);
body.from = bridge_offset;
if (bridge_offset > deep_paging_limit) {
return Promise.reject(new Error('Cannot fetch more than ' + deep_paging_limit + ' points with the same timestamp'));
}
return common.search(client, indices, type, body)
.then(function(result) {
var processed = points_and_eof_from_es_result(result, body);
bridge_offset += body.size;
if (processed.eof) {
// end of the bridge fetch, not necessarily end of the query
// (if it really is the end of the query then the non-brige-path
// will fetch one more empty batch and return eof)
should_execute_bridge_fetch = false;
query_start = bridge_time.add(JuttleMoment.duration(1, 'milliseconds'));
processed.eof = false;
}
return processed;
});
} | javascript | function bridge_fetch(size) {
var bridge_time = new JuttleMoment(last_seen_timestamp);
var time_filter = {term: {}};
time_filter.term[timeField] = bridge_time.valueOf();
var body = make_body(filter, null, null, direction, time_filter, size, timeField);
body.from = bridge_offset;
if (bridge_offset > deep_paging_limit) {
return Promise.reject(new Error('Cannot fetch more than ' + deep_paging_limit + ' points with the same timestamp'));
}
return common.search(client, indices, type, body)
.then(function(result) {
var processed = points_and_eof_from_es_result(result, body);
bridge_offset += body.size;
if (processed.eof) {
// end of the bridge fetch, not necessarily end of the query
// (if it really is the end of the query then the non-brige-path
// will fetch one more empty batch and return eof)
should_execute_bridge_fetch = false;
query_start = bridge_time.add(JuttleMoment.duration(1, 'milliseconds'));
processed.eof = false;
}
return processed;
});
} | [
"function",
"bridge_fetch",
"(",
"size",
")",
"{",
"var",
"bridge_time",
"=",
"new",
"JuttleMoment",
"(",
"last_seen_timestamp",
")",
";",
"var",
"time_filter",
"=",
"{",
"term",
":",
"{",
"}",
"}",
";",
"time_filter",
".",
"term",
"[",
"timeField",
"]",
"=",
"bridge_time",
".",
"valueOf",
"(",
")",
";",
"var",
"body",
"=",
"make_body",
"(",
"filter",
",",
"null",
",",
"null",
",",
"direction",
",",
"time_filter",
",",
"size",
",",
"timeField",
")",
";",
"body",
".",
"from",
"=",
"bridge_offset",
";",
"if",
"(",
"bridge_offset",
">",
"deep_paging_limit",
")",
"{",
"return",
"Promise",
".",
"reject",
"(",
"new",
"Error",
"(",
"'Cannot fetch more than '",
"+",
"deep_paging_limit",
"+",
"' points with the same timestamp'",
")",
")",
";",
"}",
"return",
"common",
".",
"search",
"(",
"client",
",",
"indices",
",",
"type",
",",
"body",
")",
".",
"then",
"(",
"function",
"(",
"result",
")",
"{",
"var",
"processed",
"=",
"points_and_eof_from_es_result",
"(",
"result",
",",
"body",
")",
";",
"bridge_offset",
"+=",
"body",
".",
"size",
";",
"if",
"(",
"processed",
".",
"eof",
")",
"{",
"// end of the bridge fetch, not necessarily end of the query",
"// (if it really is the end of the query then the non-brige-path",
"// will fetch one more empty batch and return eof)",
"should_execute_bridge_fetch",
"=",
"false",
";",
"query_start",
"=",
"bridge_time",
".",
"add",
"(",
"JuttleMoment",
".",
"duration",
"(",
"1",
",",
"'milliseconds'",
")",
")",
";",
"processed",
".",
"eof",
"=",
"false",
";",
"}",
"return",
"processed",
";",
"}",
")",
";",
"}"
]
| if more than fetchSize events have the same timestamp, we do a "bridge fetch" which pages through all the points with that timestamp | [
"if",
"more",
"than",
"fetchSize",
"events",
"have",
"the",
"same",
"timestamp",
"we",
"do",
"a",
"bridge",
"fetch",
"which",
"pages",
"through",
"all",
"the",
"points",
"with",
"that",
"timestamp"
]
| 7b3b1c46943381230bc7dde33874a738a0a50cbe | https://github.com/juttle/juttle-elastic-adapter/blob/7b3b1c46943381230bc7dde33874a738a0a50cbe/lib/query.js#L109-L137 |
46,199 | juttle/juttle-elastic-adapter | lib/query.js | drop_last_time_stamp_and_maybe_bridge_fetch | function drop_last_time_stamp_and_maybe_bridge_fetch(processed, size) {
if (processed.eof) { return processed; }
var last = _.last(processed.points);
last_seen_timestamp = last && last.time;
var non_simultaneous_points = processed.points.filter(function(pt) {
return pt.time !== last_seen_timestamp;
});
if (non_simultaneous_points.length === 0 && processed.points.length !== 0) {
should_execute_bridge_fetch = true;
bridge_offset = 0;
return bridge_fetch(size);
} else {
query_start = new JuttleMoment(last_seen_timestamp);
processed.points = non_simultaneous_points;
return processed;
}
} | javascript | function drop_last_time_stamp_and_maybe_bridge_fetch(processed, size) {
if (processed.eof) { return processed; }
var last = _.last(processed.points);
last_seen_timestamp = last && last.time;
var non_simultaneous_points = processed.points.filter(function(pt) {
return pt.time !== last_seen_timestamp;
});
if (non_simultaneous_points.length === 0 && processed.points.length !== 0) {
should_execute_bridge_fetch = true;
bridge_offset = 0;
return bridge_fetch(size);
} else {
query_start = new JuttleMoment(last_seen_timestamp);
processed.points = non_simultaneous_points;
return processed;
}
} | [
"function",
"drop_last_time_stamp_and_maybe_bridge_fetch",
"(",
"processed",
",",
"size",
")",
"{",
"if",
"(",
"processed",
".",
"eof",
")",
"{",
"return",
"processed",
";",
"}",
"var",
"last",
"=",
"_",
".",
"last",
"(",
"processed",
".",
"points",
")",
";",
"last_seen_timestamp",
"=",
"last",
"&&",
"last",
".",
"time",
";",
"var",
"non_simultaneous_points",
"=",
"processed",
".",
"points",
".",
"filter",
"(",
"function",
"(",
"pt",
")",
"{",
"return",
"pt",
".",
"time",
"!==",
"last_seen_timestamp",
";",
"}",
")",
";",
"if",
"(",
"non_simultaneous_points",
".",
"length",
"===",
"0",
"&&",
"processed",
".",
"points",
".",
"length",
"!==",
"0",
")",
"{",
"should_execute_bridge_fetch",
"=",
"true",
";",
"bridge_offset",
"=",
"0",
";",
"return",
"bridge_fetch",
"(",
"size",
")",
";",
"}",
"else",
"{",
"query_start",
"=",
"new",
"JuttleMoment",
"(",
"last_seen_timestamp",
")",
";",
"processed",
".",
"points",
"=",
"non_simultaneous_points",
";",
"return",
"processed",
";",
"}",
"}"
]
| takes the output of points_and_eof_from_es_result and removes the points with the last timestamp, triggering a bridge fetch if all the points are simultaneous. This makes sure the next query, which starts at the last timestamp, won't return any duplicates | [
"takes",
"the",
"output",
"of",
"points_and_eof_from_es_result",
"and",
"removes",
"the",
"points",
"with",
"the",
"last",
"timestamp",
"triggering",
"a",
"bridge",
"fetch",
"if",
"all",
"the",
"points",
"are",
"simultaneous",
".",
"This",
"makes",
"sure",
"the",
"next",
"query",
"which",
"starts",
"at",
"the",
"last",
"timestamp",
"won",
"t",
"return",
"any",
"duplicates"
]
| 7b3b1c46943381230bc7dde33874a738a0a50cbe | https://github.com/juttle/juttle-elastic-adapter/blob/7b3b1c46943381230bc7dde33874a738a0a50cbe/lib/query.js#L143-L162 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.