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
sequence | docstring
stringlengths 4
11.8k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
6,300 | maptalks/maptalks.js | src/geometry/ext/Geometry.Events.js | function (e) {
const map = this.getMap();
const eventParam = {
'domEvent': e
};
const actual = e.touches && e.touches.length > 0 ? e.touches[0] : e.changedTouches && e.changedTouches.length > 0 ? e.changedTouches[0] : e;
if (actual) {
const containerPoint = getEventContainerPoint(actual, map._containerDOM);
eventParam['coordinate'] = map.containerPointToCoordinate(containerPoint);
eventParam['containerPoint'] = containerPoint;
eventParam['viewPoint'] = map.containerPointToViewPoint(containerPoint);
eventParam['pont2d'] = map._containerPointToPoint(containerPoint);
}
return eventParam;
} | javascript | function (e) {
const map = this.getMap();
const eventParam = {
'domEvent': e
};
const actual = e.touches && e.touches.length > 0 ? e.touches[0] : e.changedTouches && e.changedTouches.length > 0 ? e.changedTouches[0] : e;
if (actual) {
const containerPoint = getEventContainerPoint(actual, map._containerDOM);
eventParam['coordinate'] = map.containerPointToCoordinate(containerPoint);
eventParam['containerPoint'] = containerPoint;
eventParam['viewPoint'] = map.containerPointToViewPoint(containerPoint);
eventParam['pont2d'] = map._containerPointToPoint(containerPoint);
}
return eventParam;
} | [
"function",
"(",
"e",
")",
"{",
"const",
"map",
"=",
"this",
".",
"getMap",
"(",
")",
";",
"const",
"eventParam",
"=",
"{",
"'domEvent'",
":",
"e",
"}",
";",
"const",
"actual",
"=",
"e",
".",
"touches",
"&&",
"e",
".",
"touches",
".",
"length",
">",
"0",
"?",
"e",
".",
"touches",
"[",
"0",
"]",
":",
"e",
".",
"changedTouches",
"&&",
"e",
".",
"changedTouches",
".",
"length",
">",
"0",
"?",
"e",
".",
"changedTouches",
"[",
"0",
"]",
":",
"e",
";",
"if",
"(",
"actual",
")",
"{",
"const",
"containerPoint",
"=",
"getEventContainerPoint",
"(",
"actual",
",",
"map",
".",
"_containerDOM",
")",
";",
"eventParam",
"[",
"'coordinate'",
"]",
"=",
"map",
".",
"containerPointToCoordinate",
"(",
"containerPoint",
")",
";",
"eventParam",
"[",
"'containerPoint'",
"]",
"=",
"containerPoint",
";",
"eventParam",
"[",
"'viewPoint'",
"]",
"=",
"map",
".",
"containerPointToViewPoint",
"(",
"containerPoint",
")",
";",
"eventParam",
"[",
"'pont2d'",
"]",
"=",
"map",
".",
"_containerPointToPoint",
"(",
"containerPoint",
")",
";",
"}",
"return",
"eventParam",
";",
"}"
] | Generate event parameters
@param {Event} event - dom event
@return {Object}
@private | [
"Generate",
"event",
"parameters"
] | 8ee32cb20c5ea79dd687e1076c1310a288955792 | https://github.com/maptalks/maptalks.js/blob/8ee32cb20c5ea79dd687e1076c1310a288955792/src/geometry/ext/Geometry.Events.js#L40-L54 |
|
6,301 | maptalks/maptalks.js | src/map/Map.Topo.js | function (coord1, coord2) {
if (!this.getProjection()) {
return null;
}
const p1 = new Coordinate(coord1),
p2 = new Coordinate(coord2);
if (p1.equals(p2)) {
return 0;
}
return this.getProjection().measureLength(p1, p2);
} | javascript | function (coord1, coord2) {
if (!this.getProjection()) {
return null;
}
const p1 = new Coordinate(coord1),
p2 = new Coordinate(coord2);
if (p1.equals(p2)) {
return 0;
}
return this.getProjection().measureLength(p1, p2);
} | [
"function",
"(",
"coord1",
",",
"coord2",
")",
"{",
"if",
"(",
"!",
"this",
".",
"getProjection",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"const",
"p1",
"=",
"new",
"Coordinate",
"(",
"coord1",
")",
",",
"p2",
"=",
"new",
"Coordinate",
"(",
"coord2",
")",
";",
"if",
"(",
"p1",
".",
"equals",
"(",
"p2",
")",
")",
"{",
"return",
"0",
";",
"}",
"return",
"this",
".",
"getProjection",
"(",
")",
".",
"measureLength",
"(",
"p1",
",",
"p2",
")",
";",
"}"
] | Caculate distance of two coordinates.
@param {Number[]|Coordinate} coord1 - coordinate 1
@param {Number[]|Coordinate} coord2 - coordinate 2
@return {Number} distance, unit is meter
@example
var distance = map.computeLength([0, 0], [0, 20]); | [
"Caculate",
"distance",
"of",
"two",
"coordinates",
"."
] | 8ee32cb20c5ea79dd687e1076c1310a288955792 | https://github.com/maptalks/maptalks.js/blob/8ee32cb20c5ea79dd687e1076c1310a288955792/src/map/Map.Topo.js#L18-L28 |
|
6,302 | maptalks/maptalks.js | src/map/Map.Topo.js | function (opts, callback) {
if (!opts) {
return this;
}
const reqLayers = opts['layers'];
if (!isArrayHasData(reqLayers)) {
return this;
}
const layers = [];
for (let i = 0, len = reqLayers.length; i < len; i++) {
if (isString(reqLayers[i])) {
layers.push(this.getLayer(reqLayers[i]));
} else {
layers.push(reqLayers[i]);
}
}
const coordinate = new Coordinate(opts['coordinate']);
const options = extend({}, opts);
const hits = [];
for (let i = layers.length - 1; i >= 0; i--) {
if (opts['count'] && hits.length >= opts['count']) {
break;
}
const layer = layers[i];
if (!layer || !layer.getMap() || (!opts['includeInvisible'] && !layer.isVisible()) || (!opts['includeInternals'] && layer.getId().indexOf(INTERNAL_LAYER_PREFIX) >= 0)) {
continue;
}
const layerHits = layer.identify(coordinate, options);
if (layerHits) {
if (Array.isArray(layerHits)) {
pushIn(hits, layerHits);
} else {
hits.push(layerHits);
}
}
}
callback.call(this, hits);
return this;
} | javascript | function (opts, callback) {
if (!opts) {
return this;
}
const reqLayers = opts['layers'];
if (!isArrayHasData(reqLayers)) {
return this;
}
const layers = [];
for (let i = 0, len = reqLayers.length; i < len; i++) {
if (isString(reqLayers[i])) {
layers.push(this.getLayer(reqLayers[i]));
} else {
layers.push(reqLayers[i]);
}
}
const coordinate = new Coordinate(opts['coordinate']);
const options = extend({}, opts);
const hits = [];
for (let i = layers.length - 1; i >= 0; i--) {
if (opts['count'] && hits.length >= opts['count']) {
break;
}
const layer = layers[i];
if (!layer || !layer.getMap() || (!opts['includeInvisible'] && !layer.isVisible()) || (!opts['includeInternals'] && layer.getId().indexOf(INTERNAL_LAYER_PREFIX) >= 0)) {
continue;
}
const layerHits = layer.identify(coordinate, options);
if (layerHits) {
if (Array.isArray(layerHits)) {
pushIn(hits, layerHits);
} else {
hits.push(layerHits);
}
}
}
callback.call(this, hits);
return this;
} | [
"function",
"(",
"opts",
",",
"callback",
")",
"{",
"if",
"(",
"!",
"opts",
")",
"{",
"return",
"this",
";",
"}",
"const",
"reqLayers",
"=",
"opts",
"[",
"'layers'",
"]",
";",
"if",
"(",
"!",
"isArrayHasData",
"(",
"reqLayers",
")",
")",
"{",
"return",
"this",
";",
"}",
"const",
"layers",
"=",
"[",
"]",
";",
"for",
"(",
"let",
"i",
"=",
"0",
",",
"len",
"=",
"reqLayers",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"if",
"(",
"isString",
"(",
"reqLayers",
"[",
"i",
"]",
")",
")",
"{",
"layers",
".",
"push",
"(",
"this",
".",
"getLayer",
"(",
"reqLayers",
"[",
"i",
"]",
")",
")",
";",
"}",
"else",
"{",
"layers",
".",
"push",
"(",
"reqLayers",
"[",
"i",
"]",
")",
";",
"}",
"}",
"const",
"coordinate",
"=",
"new",
"Coordinate",
"(",
"opts",
"[",
"'coordinate'",
"]",
")",
";",
"const",
"options",
"=",
"extend",
"(",
"{",
"}",
",",
"opts",
")",
";",
"const",
"hits",
"=",
"[",
"]",
";",
"for",
"(",
"let",
"i",
"=",
"layers",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"if",
"(",
"opts",
"[",
"'count'",
"]",
"&&",
"hits",
".",
"length",
">=",
"opts",
"[",
"'count'",
"]",
")",
"{",
"break",
";",
"}",
"const",
"layer",
"=",
"layers",
"[",
"i",
"]",
";",
"if",
"(",
"!",
"layer",
"||",
"!",
"layer",
".",
"getMap",
"(",
")",
"||",
"(",
"!",
"opts",
"[",
"'includeInvisible'",
"]",
"&&",
"!",
"layer",
".",
"isVisible",
"(",
")",
")",
"||",
"(",
"!",
"opts",
"[",
"'includeInternals'",
"]",
"&&",
"layer",
".",
"getId",
"(",
")",
".",
"indexOf",
"(",
"INTERNAL_LAYER_PREFIX",
")",
">=",
"0",
")",
")",
"{",
"continue",
";",
"}",
"const",
"layerHits",
"=",
"layer",
".",
"identify",
"(",
"coordinate",
",",
"options",
")",
";",
"if",
"(",
"layerHits",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"layerHits",
")",
")",
"{",
"pushIn",
"(",
"hits",
",",
"layerHits",
")",
";",
"}",
"else",
"{",
"hits",
".",
"push",
"(",
"layerHits",
")",
";",
"}",
"}",
"}",
"callback",
".",
"call",
"(",
"this",
",",
"hits",
")",
";",
"return",
"this",
";",
"}"
] | Identify the geometries on the given coordinate.
@param {Object} opts - the identify options
@param {Coordinate} opts.coordinate - coordinate to identify
@param {Object} opts.layers - the layers to perform identify on.
@param {Function} [opts.filter=null] - filter function of the result geometries, return false to exclude.
@param {Number} [opts.count=null] - limit of the result count.
@param {Number} [opts.tolerance=0] - identify tolerance in pixel.
@param {Boolean} [opts.includeInternals=false] - whether to identify internal layers.
@param {Boolean} [opts.includeInvisible=false] - whether to identify invisible layers.
@param {Function} callback - the callback function using the result geometries as the parameter.
@return {Map} this
@example
map.identify({
coordinate: [0, 0],
layers: [layer]
},
geos => {
console.log(geos);
}); | [
"Identify",
"the",
"geometries",
"on",
"the",
"given",
"coordinate",
"."
] | 8ee32cb20c5ea79dd687e1076c1310a288955792 | https://github.com/maptalks/maptalks.js/blob/8ee32cb20c5ea79dd687e1076c1310a288955792/src/map/Map.Topo.js#L69-L107 |
|
6,303 | maptalks/maptalks.js | src/geometry/ext/Geometry.Animation.js | function (styles, options, step) {
if (this._animPlayer) {
this._animPlayer.finish();
}
if (isFunction(options)) {
step = options;
}
if (!options) {
options = {};
}
const map = this.getMap(),
projection = this._getProjection(),
symbol = this.getSymbol() || {},
stylesToAnimate = this._prepareAnimationStyles(styles);
let preTranslate;
const isFocusing = options['focus'];
delete this._animationStarted;
// geometry.animate can be called without map
if (map) {
// merge geometry animation framing into map's frame loop
const renderer = map._getRenderer();
const framer = function (fn) {
renderer.callInNextFrame(fn);
};
options['framer'] = framer;
}
const player = Animation.animate(stylesToAnimate, options, frame => {
if (map && map.isRemoved()) {
player.finish();
return;
}
if (map && !this._animationStarted && isFocusing) {
map.onMoveStart();
}
const styles = frame.styles;
for (const p in styles) {
if (p !== 'symbol' && p !== 'translate' && styles.hasOwnProperty(p)) {
const fnName = 'set' + p[0].toUpperCase() + p.slice(1);
this[fnName](styles[p]);
}
}
const translate = styles['translate'];
if (translate) {
let toTranslate = translate;
if (preTranslate) {
toTranslate = translate.sub(preTranslate);
}
preTranslate = translate;
this.translate(toTranslate);
}
const dSymbol = styles['symbol'];
if (dSymbol) {
this.setSymbol(extendSymbol(symbol, dSymbol));
}
if (map && isFocusing) {
const pcenter = projection.project(this.getCenter());
map._setPrjCenter(pcenter);
const e = map._parseEventFromCoord(projection.unproject(pcenter));
if (player.playState !== 'running') {
map.onMoveEnd(e);
} else {
map.onMoving(e);
}
}
this._fireAnimateEvent(player.playState);
if (step) {
step(frame);
}
});
this._animPlayer = player;
return this._animPlayer.play();
} | javascript | function (styles, options, step) {
if (this._animPlayer) {
this._animPlayer.finish();
}
if (isFunction(options)) {
step = options;
}
if (!options) {
options = {};
}
const map = this.getMap(),
projection = this._getProjection(),
symbol = this.getSymbol() || {},
stylesToAnimate = this._prepareAnimationStyles(styles);
let preTranslate;
const isFocusing = options['focus'];
delete this._animationStarted;
// geometry.animate can be called without map
if (map) {
// merge geometry animation framing into map's frame loop
const renderer = map._getRenderer();
const framer = function (fn) {
renderer.callInNextFrame(fn);
};
options['framer'] = framer;
}
const player = Animation.animate(stylesToAnimate, options, frame => {
if (map && map.isRemoved()) {
player.finish();
return;
}
if (map && !this._animationStarted && isFocusing) {
map.onMoveStart();
}
const styles = frame.styles;
for (const p in styles) {
if (p !== 'symbol' && p !== 'translate' && styles.hasOwnProperty(p)) {
const fnName = 'set' + p[0].toUpperCase() + p.slice(1);
this[fnName](styles[p]);
}
}
const translate = styles['translate'];
if (translate) {
let toTranslate = translate;
if (preTranslate) {
toTranslate = translate.sub(preTranslate);
}
preTranslate = translate;
this.translate(toTranslate);
}
const dSymbol = styles['symbol'];
if (dSymbol) {
this.setSymbol(extendSymbol(symbol, dSymbol));
}
if (map && isFocusing) {
const pcenter = projection.project(this.getCenter());
map._setPrjCenter(pcenter);
const e = map._parseEventFromCoord(projection.unproject(pcenter));
if (player.playState !== 'running') {
map.onMoveEnd(e);
} else {
map.onMoving(e);
}
}
this._fireAnimateEvent(player.playState);
if (step) {
step(frame);
}
});
this._animPlayer = player;
return this._animPlayer.play();
} | [
"function",
"(",
"styles",
",",
"options",
",",
"step",
")",
"{",
"if",
"(",
"this",
".",
"_animPlayer",
")",
"{",
"this",
".",
"_animPlayer",
".",
"finish",
"(",
")",
";",
"}",
"if",
"(",
"isFunction",
"(",
"options",
")",
")",
"{",
"step",
"=",
"options",
";",
"}",
"if",
"(",
"!",
"options",
")",
"{",
"options",
"=",
"{",
"}",
";",
"}",
"const",
"map",
"=",
"this",
".",
"getMap",
"(",
")",
",",
"projection",
"=",
"this",
".",
"_getProjection",
"(",
")",
",",
"symbol",
"=",
"this",
".",
"getSymbol",
"(",
")",
"||",
"{",
"}",
",",
"stylesToAnimate",
"=",
"this",
".",
"_prepareAnimationStyles",
"(",
"styles",
")",
";",
"let",
"preTranslate",
";",
"const",
"isFocusing",
"=",
"options",
"[",
"'focus'",
"]",
";",
"delete",
"this",
".",
"_animationStarted",
";",
"// geometry.animate can be called without map",
"if",
"(",
"map",
")",
"{",
"// merge geometry animation framing into map's frame loop",
"const",
"renderer",
"=",
"map",
".",
"_getRenderer",
"(",
")",
";",
"const",
"framer",
"=",
"function",
"(",
"fn",
")",
"{",
"renderer",
".",
"callInNextFrame",
"(",
"fn",
")",
";",
"}",
";",
"options",
"[",
"'framer'",
"]",
"=",
"framer",
";",
"}",
"const",
"player",
"=",
"Animation",
".",
"animate",
"(",
"stylesToAnimate",
",",
"options",
",",
"frame",
"=>",
"{",
"if",
"(",
"map",
"&&",
"map",
".",
"isRemoved",
"(",
")",
")",
"{",
"player",
".",
"finish",
"(",
")",
";",
"return",
";",
"}",
"if",
"(",
"map",
"&&",
"!",
"this",
".",
"_animationStarted",
"&&",
"isFocusing",
")",
"{",
"map",
".",
"onMoveStart",
"(",
")",
";",
"}",
"const",
"styles",
"=",
"frame",
".",
"styles",
";",
"for",
"(",
"const",
"p",
"in",
"styles",
")",
"{",
"if",
"(",
"p",
"!==",
"'symbol'",
"&&",
"p",
"!==",
"'translate'",
"&&",
"styles",
".",
"hasOwnProperty",
"(",
"p",
")",
")",
"{",
"const",
"fnName",
"=",
"'set'",
"+",
"p",
"[",
"0",
"]",
".",
"toUpperCase",
"(",
")",
"+",
"p",
".",
"slice",
"(",
"1",
")",
";",
"this",
"[",
"fnName",
"]",
"(",
"styles",
"[",
"p",
"]",
")",
";",
"}",
"}",
"const",
"translate",
"=",
"styles",
"[",
"'translate'",
"]",
";",
"if",
"(",
"translate",
")",
"{",
"let",
"toTranslate",
"=",
"translate",
";",
"if",
"(",
"preTranslate",
")",
"{",
"toTranslate",
"=",
"translate",
".",
"sub",
"(",
"preTranslate",
")",
";",
"}",
"preTranslate",
"=",
"translate",
";",
"this",
".",
"translate",
"(",
"toTranslate",
")",
";",
"}",
"const",
"dSymbol",
"=",
"styles",
"[",
"'symbol'",
"]",
";",
"if",
"(",
"dSymbol",
")",
"{",
"this",
".",
"setSymbol",
"(",
"extendSymbol",
"(",
"symbol",
",",
"dSymbol",
")",
")",
";",
"}",
"if",
"(",
"map",
"&&",
"isFocusing",
")",
"{",
"const",
"pcenter",
"=",
"projection",
".",
"project",
"(",
"this",
".",
"getCenter",
"(",
")",
")",
";",
"map",
".",
"_setPrjCenter",
"(",
"pcenter",
")",
";",
"const",
"e",
"=",
"map",
".",
"_parseEventFromCoord",
"(",
"projection",
".",
"unproject",
"(",
"pcenter",
")",
")",
";",
"if",
"(",
"player",
".",
"playState",
"!==",
"'running'",
")",
"{",
"map",
".",
"onMoveEnd",
"(",
"e",
")",
";",
"}",
"else",
"{",
"map",
".",
"onMoving",
"(",
"e",
")",
";",
"}",
"}",
"this",
".",
"_fireAnimateEvent",
"(",
"player",
".",
"playState",
")",
";",
"if",
"(",
"step",
")",
"{",
"step",
"(",
"frame",
")",
";",
"}",
"}",
")",
";",
"this",
".",
"_animPlayer",
"=",
"player",
";",
"return",
"this",
".",
"_animPlayer",
".",
"play",
"(",
")",
";",
"}"
] | Animate the geometry
@param {Object} styles - styles to animate
@param {Object} [options=null] - animation options
@param {NUmber} [options.duration=1000] - duration
@param {Number} [options.startTime=null] - time to start animation in ms
@param {String} [options.easing=linear] - animation easing: in, out, inAndOut, linear, upAndDown
@param {Boolean} [options.repeat=false] - repeat animation
@param {Function} [step=null] - step function during animation, animation frame as the parameter
@return {animation.Player} animation player
@example
var player = marker.animate({
'symbol': {
'markerHeight': 82
}
}, {
'duration': 2000
}, function (frame) {
if (frame.state.playState === 'finished') {
console.log('animation finished');
}
});
player.pause(); | [
"Animate",
"the",
"geometry"
] | 8ee32cb20c5ea79dd687e1076c1310a288955792 | https://github.com/maptalks/maptalks.js/blob/8ee32cb20c5ea79dd687e1076c1310a288955792/src/geometry/ext/Geometry.Animation.js#L33-L106 |
|
6,304 | maptalks/maptalks.js | src/geometry/ext/Geometry.Animation.js | function (styles) {
const symbol = this._getInternalSymbol();
const stylesToAnimate = {};
for (const p in styles) {
if (styles.hasOwnProperty(p)) {
const v = styles[p];
if (p !== 'translate' && p !== 'symbol') {
//this.getRadius() / this.getWidth(), etc.
const fnName = 'get' + p[0].toUpperCase() + p.substring(1);
const current = this[fnName]();
stylesToAnimate[p] = [current, v];
} else if (p === 'symbol') {
let symbolToAnimate;
if (Array.isArray(styles['symbol'])) {
if (!Array.isArray(symbol)) {
throw new Error('geometry\'symbol isn\'t a composite symbol, while the symbol in styles is.');
}
symbolToAnimate = [];
const symbolInStyles = styles['symbol'];
for (let i = 0; i < symbolInStyles.length; i++) {
if (!symbolInStyles[i]) {
symbolToAnimate.push(null);
continue;
}
const a = {};
for (const sp in symbolInStyles[i]) {
if (symbolInStyles[i].hasOwnProperty(sp)) {
a[sp] = [symbol[i][sp], symbolInStyles[i][sp]];
}
}
symbolToAnimate.push(a);
}
} else {
if (Array.isArray(symbol)) {
throw new Error('geometry\'symbol is a composite symbol, while the symbol in styles isn\'t.');
}
symbolToAnimate = {};
for (const sp in v) {
if (v.hasOwnProperty(sp)) {
symbolToAnimate[sp] = [symbol[sp], v[sp]];
}
}
}
stylesToAnimate['symbol'] = symbolToAnimate;
} else if (p === 'translate') {
stylesToAnimate['translate'] = new Coordinate(v);
}
}
}
return stylesToAnimate;
} | javascript | function (styles) {
const symbol = this._getInternalSymbol();
const stylesToAnimate = {};
for (const p in styles) {
if (styles.hasOwnProperty(p)) {
const v = styles[p];
if (p !== 'translate' && p !== 'symbol') {
//this.getRadius() / this.getWidth(), etc.
const fnName = 'get' + p[0].toUpperCase() + p.substring(1);
const current = this[fnName]();
stylesToAnimate[p] = [current, v];
} else if (p === 'symbol') {
let symbolToAnimate;
if (Array.isArray(styles['symbol'])) {
if (!Array.isArray(symbol)) {
throw new Error('geometry\'symbol isn\'t a composite symbol, while the symbol in styles is.');
}
symbolToAnimate = [];
const symbolInStyles = styles['symbol'];
for (let i = 0; i < symbolInStyles.length; i++) {
if (!symbolInStyles[i]) {
symbolToAnimate.push(null);
continue;
}
const a = {};
for (const sp in symbolInStyles[i]) {
if (symbolInStyles[i].hasOwnProperty(sp)) {
a[sp] = [symbol[i][sp], symbolInStyles[i][sp]];
}
}
symbolToAnimate.push(a);
}
} else {
if (Array.isArray(symbol)) {
throw new Error('geometry\'symbol is a composite symbol, while the symbol in styles isn\'t.');
}
symbolToAnimate = {};
for (const sp in v) {
if (v.hasOwnProperty(sp)) {
symbolToAnimate[sp] = [symbol[sp], v[sp]];
}
}
}
stylesToAnimate['symbol'] = symbolToAnimate;
} else if (p === 'translate') {
stylesToAnimate['translate'] = new Coordinate(v);
}
}
}
return stylesToAnimate;
} | [
"function",
"(",
"styles",
")",
"{",
"const",
"symbol",
"=",
"this",
".",
"_getInternalSymbol",
"(",
")",
";",
"const",
"stylesToAnimate",
"=",
"{",
"}",
";",
"for",
"(",
"const",
"p",
"in",
"styles",
")",
"{",
"if",
"(",
"styles",
".",
"hasOwnProperty",
"(",
"p",
")",
")",
"{",
"const",
"v",
"=",
"styles",
"[",
"p",
"]",
";",
"if",
"(",
"p",
"!==",
"'translate'",
"&&",
"p",
"!==",
"'symbol'",
")",
"{",
"//this.getRadius() / this.getWidth(), etc.",
"const",
"fnName",
"=",
"'get'",
"+",
"p",
"[",
"0",
"]",
".",
"toUpperCase",
"(",
")",
"+",
"p",
".",
"substring",
"(",
"1",
")",
";",
"const",
"current",
"=",
"this",
"[",
"fnName",
"]",
"(",
")",
";",
"stylesToAnimate",
"[",
"p",
"]",
"=",
"[",
"current",
",",
"v",
"]",
";",
"}",
"else",
"if",
"(",
"p",
"===",
"'symbol'",
")",
"{",
"let",
"symbolToAnimate",
";",
"if",
"(",
"Array",
".",
"isArray",
"(",
"styles",
"[",
"'symbol'",
"]",
")",
")",
"{",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"symbol",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'geometry\\'symbol isn\\'t a composite symbol, while the symbol in styles is.'",
")",
";",
"}",
"symbolToAnimate",
"=",
"[",
"]",
";",
"const",
"symbolInStyles",
"=",
"styles",
"[",
"'symbol'",
"]",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"symbolInStyles",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"symbolInStyles",
"[",
"i",
"]",
")",
"{",
"symbolToAnimate",
".",
"push",
"(",
"null",
")",
";",
"continue",
";",
"}",
"const",
"a",
"=",
"{",
"}",
";",
"for",
"(",
"const",
"sp",
"in",
"symbolInStyles",
"[",
"i",
"]",
")",
"{",
"if",
"(",
"symbolInStyles",
"[",
"i",
"]",
".",
"hasOwnProperty",
"(",
"sp",
")",
")",
"{",
"a",
"[",
"sp",
"]",
"=",
"[",
"symbol",
"[",
"i",
"]",
"[",
"sp",
"]",
",",
"symbolInStyles",
"[",
"i",
"]",
"[",
"sp",
"]",
"]",
";",
"}",
"}",
"symbolToAnimate",
".",
"push",
"(",
"a",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"symbol",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'geometry\\'symbol is a composite symbol, while the symbol in styles isn\\'t.'",
")",
";",
"}",
"symbolToAnimate",
"=",
"{",
"}",
";",
"for",
"(",
"const",
"sp",
"in",
"v",
")",
"{",
"if",
"(",
"v",
".",
"hasOwnProperty",
"(",
"sp",
")",
")",
"{",
"symbolToAnimate",
"[",
"sp",
"]",
"=",
"[",
"symbol",
"[",
"sp",
"]",
",",
"v",
"[",
"sp",
"]",
"]",
";",
"}",
"}",
"}",
"stylesToAnimate",
"[",
"'symbol'",
"]",
"=",
"symbolToAnimate",
";",
"}",
"else",
"if",
"(",
"p",
"===",
"'translate'",
")",
"{",
"stylesToAnimate",
"[",
"'translate'",
"]",
"=",
"new",
"Coordinate",
"(",
"v",
")",
";",
"}",
"}",
"}",
"return",
"stylesToAnimate",
";",
"}"
] | Prepare styles for animation
@return {Object} styles
@private | [
"Prepare",
"styles",
"for",
"animation"
] | 8ee32cb20c5ea79dd687e1076c1310a288955792 | https://github.com/maptalks/maptalks.js/blob/8ee32cb20c5ea79dd687e1076c1310a288955792/src/geometry/ext/Geometry.Animation.js#L112-L162 |
|
6,305 | maptalks/maptalks.js | src/core/Ajax.js | function (url, options, cb) {
if (isFunction(options)) {
const t = cb;
cb = options;
options = t;
}
if (IS_NODE && Ajax.get.node) {
return Ajax.get.node(url, cb, options);
}
const client = Ajax._getClient(cb);
client.open('GET', url, true);
if (options) {
for (const k in options.headers) {
client.setRequestHeader(k, options.headers[k]);
}
client.withCredentials = options.credentials === 'include';
if (options['responseType']) {
client.responseType = options['responseType'];
}
}
client.send(null);
return client;
} | javascript | function (url, options, cb) {
if (isFunction(options)) {
const t = cb;
cb = options;
options = t;
}
if (IS_NODE && Ajax.get.node) {
return Ajax.get.node(url, cb, options);
}
const client = Ajax._getClient(cb);
client.open('GET', url, true);
if (options) {
for (const k in options.headers) {
client.setRequestHeader(k, options.headers[k]);
}
client.withCredentials = options.credentials === 'include';
if (options['responseType']) {
client.responseType = options['responseType'];
}
}
client.send(null);
return client;
} | [
"function",
"(",
"url",
",",
"options",
",",
"cb",
")",
"{",
"if",
"(",
"isFunction",
"(",
"options",
")",
")",
"{",
"const",
"t",
"=",
"cb",
";",
"cb",
"=",
"options",
";",
"options",
"=",
"t",
";",
"}",
"if",
"(",
"IS_NODE",
"&&",
"Ajax",
".",
"get",
".",
"node",
")",
"{",
"return",
"Ajax",
".",
"get",
".",
"node",
"(",
"url",
",",
"cb",
",",
"options",
")",
";",
"}",
"const",
"client",
"=",
"Ajax",
".",
"_getClient",
"(",
"cb",
")",
";",
"client",
".",
"open",
"(",
"'GET'",
",",
"url",
",",
"true",
")",
";",
"if",
"(",
"options",
")",
"{",
"for",
"(",
"const",
"k",
"in",
"options",
".",
"headers",
")",
"{",
"client",
".",
"setRequestHeader",
"(",
"k",
",",
"options",
".",
"headers",
"[",
"k",
"]",
")",
";",
"}",
"client",
".",
"withCredentials",
"=",
"options",
".",
"credentials",
"===",
"'include'",
";",
"if",
"(",
"options",
"[",
"'responseType'",
"]",
")",
"{",
"client",
".",
"responseType",
"=",
"options",
"[",
"'responseType'",
"]",
";",
"}",
"}",
"client",
".",
"send",
"(",
"null",
")",
";",
"return",
"client",
";",
"}"
] | Fetch remote resource by HTTP "GET" method
@param {String} url - resource url
@param {Object} [options=null] - request options
@param {Object} [options.headers=null] - HTTP headers
@param {String} [options.responseType=null] - responseType
@param {String} [options.credentials=null] - if with credentials, set it to "include"
@param {Function} cb - callback function when completed
@return {Ajax} Ajax
@example
maptalks.Ajax.get(
'url/to/resource',
(err, data) => {
if (err) {
throw new Error(err);
}
// do things with data
}
); | [
"Fetch",
"remote",
"resource",
"by",
"HTTP",
"GET",
"method"
] | 8ee32cb20c5ea79dd687e1076c1310a288955792 | https://github.com/maptalks/maptalks.js/blob/8ee32cb20c5ea79dd687e1076c1310a288955792/src/core/Ajax.js#L62-L84 |
|
6,306 | maptalks/maptalks.js | src/core/Ajax.js | function (url, options, cb) {
let postData;
if (!isString(url)) {
//for compatible
//options, postData, cb
const t = cb;
postData = options;
options = url;
url = options.url;
cb = t;
} else {
if (isFunction(options)) {
const t = cb;
cb = options;
options = t;
}
options = options || {};
postData = options.postData;
}
if (IS_NODE && Ajax.post.node) {
options.url = url;
return Ajax.post.node(options, postData, cb);
}
const client = Ajax._getClient(cb);
client.open('POST', options.url, true);
if (!options.headers) {
options.headers = {};
}
if (!options.headers['Content-Type']) {
options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
}
if ('setRequestHeader' in client) {
for (const p in options.headers) {
if (options.headers.hasOwnProperty(p)) {
client.setRequestHeader(p, options.headers[p]);
}
}
}
if (!isString(postData)) {
postData = JSON.stringify(postData);
}
client.send(postData);
return client;
} | javascript | function (url, options, cb) {
let postData;
if (!isString(url)) {
//for compatible
//options, postData, cb
const t = cb;
postData = options;
options = url;
url = options.url;
cb = t;
} else {
if (isFunction(options)) {
const t = cb;
cb = options;
options = t;
}
options = options || {};
postData = options.postData;
}
if (IS_NODE && Ajax.post.node) {
options.url = url;
return Ajax.post.node(options, postData, cb);
}
const client = Ajax._getClient(cb);
client.open('POST', options.url, true);
if (!options.headers) {
options.headers = {};
}
if (!options.headers['Content-Type']) {
options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
}
if ('setRequestHeader' in client) {
for (const p in options.headers) {
if (options.headers.hasOwnProperty(p)) {
client.setRequestHeader(p, options.headers[p]);
}
}
}
if (!isString(postData)) {
postData = JSON.stringify(postData);
}
client.send(postData);
return client;
} | [
"function",
"(",
"url",
",",
"options",
",",
"cb",
")",
"{",
"let",
"postData",
";",
"if",
"(",
"!",
"isString",
"(",
"url",
")",
")",
"{",
"//for compatible",
"//options, postData, cb",
"const",
"t",
"=",
"cb",
";",
"postData",
"=",
"options",
";",
"options",
"=",
"url",
";",
"url",
"=",
"options",
".",
"url",
";",
"cb",
"=",
"t",
";",
"}",
"else",
"{",
"if",
"(",
"isFunction",
"(",
"options",
")",
")",
"{",
"const",
"t",
"=",
"cb",
";",
"cb",
"=",
"options",
";",
"options",
"=",
"t",
";",
"}",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"postData",
"=",
"options",
".",
"postData",
";",
"}",
"if",
"(",
"IS_NODE",
"&&",
"Ajax",
".",
"post",
".",
"node",
")",
"{",
"options",
".",
"url",
"=",
"url",
";",
"return",
"Ajax",
".",
"post",
".",
"node",
"(",
"options",
",",
"postData",
",",
"cb",
")",
";",
"}",
"const",
"client",
"=",
"Ajax",
".",
"_getClient",
"(",
"cb",
")",
";",
"client",
".",
"open",
"(",
"'POST'",
",",
"options",
".",
"url",
",",
"true",
")",
";",
"if",
"(",
"!",
"options",
".",
"headers",
")",
"{",
"options",
".",
"headers",
"=",
"{",
"}",
";",
"}",
"if",
"(",
"!",
"options",
".",
"headers",
"[",
"'Content-Type'",
"]",
")",
"{",
"options",
".",
"headers",
"[",
"'Content-Type'",
"]",
"=",
"'application/x-www-form-urlencoded'",
";",
"}",
"if",
"(",
"'setRequestHeader'",
"in",
"client",
")",
"{",
"for",
"(",
"const",
"p",
"in",
"options",
".",
"headers",
")",
"{",
"if",
"(",
"options",
".",
"headers",
".",
"hasOwnProperty",
"(",
"p",
")",
")",
"{",
"client",
".",
"setRequestHeader",
"(",
"p",
",",
"options",
".",
"headers",
"[",
"p",
"]",
")",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"isString",
"(",
"postData",
")",
")",
"{",
"postData",
"=",
"JSON",
".",
"stringify",
"(",
"postData",
")",
";",
"}",
"client",
".",
"send",
"(",
"postData",
")",
";",
"return",
"client",
";",
"}"
] | Fetch remote resource by HTTP "POST" method
@param {String} url - resource url
@param {Object} options - request options
@param {String|Object} options.postData - post data
@param {Object} [options.headers=null] - HTTP headers
@param {Function} cb - callback function when completed
@return {Ajax} Ajax
@example
maptalks.Ajax.post(
'url/to/post',
{
postData : {
'param0' : 'val0',
'param1' : 1
}
},
(err, data) => {
if (err) {
throw new Error(err);
}
// do things with data
}
); | [
"Fetch",
"remote",
"resource",
"by",
"HTTP",
"POST",
"method"
] | 8ee32cb20c5ea79dd687e1076c1310a288955792 | https://github.com/maptalks/maptalks.js/blob/8ee32cb20c5ea79dd687e1076c1310a288955792/src/core/Ajax.js#L111-L154 |
|
6,307 | maptalks/maptalks.js | src/map/Map.Pan.js | function (coordinate, options = {}, step) {
if (!coordinate) {
return this;
}
if (isFunction(options)) {
step = options;
options = {};
}
coordinate = new Coordinate(coordinate);
if (typeof (options['animation']) === 'undefined' || options['animation']) {
return this._panAnimation(coordinate, options['duration'], step);
} else {
this.setCenter(coordinate);
return this;
}
} | javascript | function (coordinate, options = {}, step) {
if (!coordinate) {
return this;
}
if (isFunction(options)) {
step = options;
options = {};
}
coordinate = new Coordinate(coordinate);
if (typeof (options['animation']) === 'undefined' || options['animation']) {
return this._panAnimation(coordinate, options['duration'], step);
} else {
this.setCenter(coordinate);
return this;
}
} | [
"function",
"(",
"coordinate",
",",
"options",
"=",
"{",
"}",
",",
"step",
")",
"{",
"if",
"(",
"!",
"coordinate",
")",
"{",
"return",
"this",
";",
"}",
"if",
"(",
"isFunction",
"(",
"options",
")",
")",
"{",
"step",
"=",
"options",
";",
"options",
"=",
"{",
"}",
";",
"}",
"coordinate",
"=",
"new",
"Coordinate",
"(",
"coordinate",
")",
";",
"if",
"(",
"typeof",
"(",
"options",
"[",
"'animation'",
"]",
")",
"===",
"'undefined'",
"||",
"options",
"[",
"'animation'",
"]",
")",
"{",
"return",
"this",
".",
"_panAnimation",
"(",
"coordinate",
",",
"options",
"[",
"'duration'",
"]",
",",
"step",
")",
";",
"}",
"else",
"{",
"this",
".",
"setCenter",
"(",
"coordinate",
")",
";",
"return",
"this",
";",
"}",
"}"
] | Pan to the given coordinate
@param {Coordinate} coordinate - coordinate to pan to
@param {Object} [options=null] - pan options
@param {Boolean} [options.animation=null] - whether pan with animation
@param {Boolean} [options.duration=600] - pan animation duration
@return {Map} this | [
"Pan",
"to",
"the",
"given",
"coordinate"
] | 8ee32cb20c5ea79dd687e1076c1310a288955792 | https://github.com/maptalks/maptalks.js/blob/8ee32cb20c5ea79dd687e1076c1310a288955792/src/map/Map.Pan.js#L16-L31 |
|
6,308 | maptalks/maptalks.js | src/map/Map.Pan.js | function (offset, options = {}, step) {
if (!offset) {
return this;
}
if (isFunction(options)) {
step = options;
options = {};
}
offset = new Point(offset);
this.onMoveStart();
if (typeof (options['animation']) === 'undefined' || options['animation']) {
offset = offset.multi(-1);
const target = this.locateByPoint(this.getCenter(), offset.x, offset.y);
this._panAnimation(target, options['duration'], step);
} else {
this._offsetCenterByPixel(offset);
this.onMoveEnd(this._parseEventFromCoord(this.getCenter()));
}
return this;
} | javascript | function (offset, options = {}, step) {
if (!offset) {
return this;
}
if (isFunction(options)) {
step = options;
options = {};
}
offset = new Point(offset);
this.onMoveStart();
if (typeof (options['animation']) === 'undefined' || options['animation']) {
offset = offset.multi(-1);
const target = this.locateByPoint(this.getCenter(), offset.x, offset.y);
this._panAnimation(target, options['duration'], step);
} else {
this._offsetCenterByPixel(offset);
this.onMoveEnd(this._parseEventFromCoord(this.getCenter()));
}
return this;
} | [
"function",
"(",
"offset",
",",
"options",
"=",
"{",
"}",
",",
"step",
")",
"{",
"if",
"(",
"!",
"offset",
")",
"{",
"return",
"this",
";",
"}",
"if",
"(",
"isFunction",
"(",
"options",
")",
")",
"{",
"step",
"=",
"options",
";",
"options",
"=",
"{",
"}",
";",
"}",
"offset",
"=",
"new",
"Point",
"(",
"offset",
")",
";",
"this",
".",
"onMoveStart",
"(",
")",
";",
"if",
"(",
"typeof",
"(",
"options",
"[",
"'animation'",
"]",
")",
"===",
"'undefined'",
"||",
"options",
"[",
"'animation'",
"]",
")",
"{",
"offset",
"=",
"offset",
".",
"multi",
"(",
"-",
"1",
")",
";",
"const",
"target",
"=",
"this",
".",
"locateByPoint",
"(",
"this",
".",
"getCenter",
"(",
")",
",",
"offset",
".",
"x",
",",
"offset",
".",
"y",
")",
";",
"this",
".",
"_panAnimation",
"(",
"target",
",",
"options",
"[",
"'duration'",
"]",
",",
"step",
")",
";",
"}",
"else",
"{",
"this",
".",
"_offsetCenterByPixel",
"(",
"offset",
")",
";",
"this",
".",
"onMoveEnd",
"(",
"this",
".",
"_parseEventFromCoord",
"(",
"this",
".",
"getCenter",
"(",
")",
")",
")",
";",
"}",
"return",
"this",
";",
"}"
] | Pan the map by the give point
@param {Point} point - distance to pan, in pixel
@param {Object} [options=null] - pan options
@param {Boolean} [options.animation=null] - whether pan with animation
@param {Boolean} [options.duration=600] - pan animation duration
@return {Map} this | [
"Pan",
"the",
"map",
"by",
"the",
"give",
"point"
] | 8ee32cb20c5ea79dd687e1076c1310a288955792 | https://github.com/maptalks/maptalks.js/blob/8ee32cb20c5ea79dd687e1076c1310a288955792/src/map/Map.Pan.js#L41-L60 |
|
6,309 | maptalks/maptalks.js | src/geo/measurer/Sphere.js | rhumbBearing | function rhumbBearing(start, end, options = {}) {
let bear360;
if (options.final) bear360 = calculateRhumbBearing(end, start);
else bear360 = calculateRhumbBearing(start, end);
const bear180 = (bear360 > 180) ? -(360 - bear360) : bear360;
return bear180;
} | javascript | function rhumbBearing(start, end, options = {}) {
let bear360;
if (options.final) bear360 = calculateRhumbBearing(end, start);
else bear360 = calculateRhumbBearing(start, end);
const bear180 = (bear360 > 180) ? -(360 - bear360) : bear360;
return bear180;
} | [
"function",
"rhumbBearing",
"(",
"start",
",",
"end",
",",
"options",
"=",
"{",
"}",
")",
"{",
"let",
"bear360",
";",
"if",
"(",
"options",
".",
"final",
")",
"bear360",
"=",
"calculateRhumbBearing",
"(",
"end",
",",
"start",
")",
";",
"else",
"bear360",
"=",
"calculateRhumbBearing",
"(",
"start",
",",
"end",
")",
";",
"const",
"bear180",
"=",
"(",
"bear360",
">",
"180",
")",
"?",
"-",
"(",
"360",
"-",
"bear360",
")",
":",
"bear360",
";",
"return",
"bear180",
";",
"}"
] | from turf.js | [
"from",
"turf",
".",
"js"
] | 8ee32cb20c5ea79dd687e1076c1310a288955792 | https://github.com/maptalks/maptalks.js/blob/8ee32cb20c5ea79dd687e1076c1310a288955792/src/geo/measurer/Sphere.js#L117-L125 |
6,310 | CreateJS/TweenJS | build/updates/builder.js | function (helpers) {
Y.log('Importing helpers: ' + helpers, 'info', 'builder');
helpers.forEach(function (imp) {
if (!Y.Files.exists(imp) || Y.Files.exists(path.join(process.cwd(), imp))) {
imp = path.join(process.cwd(), imp);
}
var h = require(imp);
Object.keys(h).forEach(function (name) {
Y.Handlebars.registerHelper(name, h[name]);
});
});
} | javascript | function (helpers) {
Y.log('Importing helpers: ' + helpers, 'info', 'builder');
helpers.forEach(function (imp) {
if (!Y.Files.exists(imp) || Y.Files.exists(path.join(process.cwd(), imp))) {
imp = path.join(process.cwd(), imp);
}
var h = require(imp);
Object.keys(h).forEach(function (name) {
Y.Handlebars.registerHelper(name, h[name]);
});
});
} | [
"function",
"(",
"helpers",
")",
"{",
"Y",
".",
"log",
"(",
"'Importing helpers: '",
"+",
"helpers",
",",
"'info'",
",",
"'builder'",
")",
";",
"helpers",
".",
"forEach",
"(",
"function",
"(",
"imp",
")",
"{",
"if",
"(",
"!",
"Y",
".",
"Files",
".",
"exists",
"(",
"imp",
")",
"||",
"Y",
".",
"Files",
".",
"exists",
"(",
"path",
".",
"join",
"(",
"process",
".",
"cwd",
"(",
")",
",",
"imp",
")",
")",
")",
"{",
"imp",
"=",
"path",
".",
"join",
"(",
"process",
".",
"cwd",
"(",
")",
",",
"imp",
")",
";",
"}",
"var",
"h",
"=",
"require",
"(",
"imp",
")",
";",
"Object",
".",
"keys",
"(",
"h",
")",
".",
"forEach",
"(",
"function",
"(",
"name",
")",
"{",
"Y",
".",
"Handlebars",
".",
"registerHelper",
"(",
"name",
",",
"h",
"[",
"name",
"]",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Register a `Y.Handlebars` helper method
@method _addHelpers
@param {Object} helpers Object containing a hash of names and functions | [
"Register",
"a",
"Y",
".",
"Handlebars",
"helper",
"method"
] | 5678f99ce876a62b2b7f7ad686d0e5b2531def3a | https://github.com/CreateJS/TweenJS/blob/5678f99ce876a62b2b7f7ad686d0e5b2531def3a/build/updates/builder.js#L125-L136 |
|
6,311 | CreateJS/TweenJS | build/updates/builder.js | function (md) {
var html = marked(md, this.options.markdown);
//Only reprocess if helpers were asked for
if (this.options.helpers || (html.indexOf('{{#crossLink') > -1)) {
//console.log('MD: ', html);
try {
// marked auto-escapes quotation marks (and unfortunately
// does not expose the escaping function)
html = html.replace(/"/g, "\"");
html = (Y.Handlebars.compile(html))({});
} catch (hError) {
//Remove all the extra escapes
html = html.replace(/\\{/g, '{').replace(/\\}/g, '}');
Y.log('Failed to parse Handlebars, probably an unknown helper, skipping..', 'warn', 'builder');
}
//console.log('HB: ', html);
}
return html;
} | javascript | function (md) {
var html = marked(md, this.options.markdown);
//Only reprocess if helpers were asked for
if (this.options.helpers || (html.indexOf('{{#crossLink') > -1)) {
//console.log('MD: ', html);
try {
// marked auto-escapes quotation marks (and unfortunately
// does not expose the escaping function)
html = html.replace(/"/g, "\"");
html = (Y.Handlebars.compile(html))({});
} catch (hError) {
//Remove all the extra escapes
html = html.replace(/\\{/g, '{').replace(/\\}/g, '}');
Y.log('Failed to parse Handlebars, probably an unknown helper, skipping..', 'warn', 'builder');
}
//console.log('HB: ', html);
}
return html;
} | [
"function",
"(",
"md",
")",
"{",
"var",
"html",
"=",
"marked",
"(",
"md",
",",
"this",
".",
"options",
".",
"markdown",
")",
";",
"//Only reprocess if helpers were asked for",
"if",
"(",
"this",
".",
"options",
".",
"helpers",
"||",
"(",
"html",
".",
"indexOf",
"(",
"'{{#crossLink'",
")",
">",
"-",
"1",
")",
")",
"{",
"//console.log('MD: ', html);",
"try",
"{",
"// marked auto-escapes quotation marks (and unfortunately",
"// does not expose the escaping function)",
"html",
"=",
"html",
".",
"replace",
"(",
"/",
""",
"/",
"g",
",",
"\"\\\"\"",
")",
";",
"html",
"=",
"(",
"Y",
".",
"Handlebars",
".",
"compile",
"(",
"html",
")",
")",
"(",
"{",
"}",
")",
";",
"}",
"catch",
"(",
"hError",
")",
"{",
"//Remove all the extra escapes",
"html",
"=",
"html",
".",
"replace",
"(",
"/",
"\\\\{",
"/",
"g",
",",
"'{'",
")",
".",
"replace",
"(",
"/",
"\\\\}",
"/",
"g",
",",
"'}'",
")",
";",
"Y",
".",
"log",
"(",
"'Failed to parse Handlebars, probably an unknown helper, skipping..'",
",",
"'warn'",
",",
"'builder'",
")",
";",
"}",
"//console.log('HB: ', html);",
"}",
"return",
"html",
";",
"}"
] | Wrapper around the Markdown parser so it can be normalized or even side stepped
@method markdown
@private
@param {String} md The Markdown string to parse
@return {HTML} The rendered HTML | [
"Wrapper",
"around",
"the",
"Markdown",
"parser",
"so",
"it",
"can",
"be",
"normalized",
"or",
"even",
"side",
"stepped"
] | 5678f99ce876a62b2b7f7ad686d0e5b2531def3a | https://github.com/CreateJS/TweenJS/blob/5678f99ce876a62b2b7f7ad686d0e5b2531def3a/build/updates/builder.js#L144-L162 |
|
6,312 | CreateJS/TweenJS | build/updates/builder.js | function () {
var self = this;
Y.log('External data received, mixing', 'info', 'builder');
self.options.externalData.forEach(function (exData) {
['files', 'classes', 'modules'].forEach(function (k) {
Y.each(exData[k], function (item, key) {
item.external = true;
var file = item.name;
if (!item.file) {
file = self.filterFileName(item.name);
}
if (item.type) {
item.type = fixType(item.type);
}
item.path = exData.base + path.join(k, file + '.html');
self.data[k][key] = item;
});
});
Y.each(exData.classitems, function (item) {
item.external = true;
item.path = exData.base + path.join('files', self.filterFileName(item.file) + '.html');
if (item.type) {
item.type = fixType(item.type);
}
if (item.params) {
item.params.forEach(function (p) {
if (p.type) {
p.type = fixType(p.type);
}
});
}
if (item["return"]) {
item["return"].type = fixType(item["return"].type);
}
self.data.classitems.push(item);
});
});
} | javascript | function () {
var self = this;
Y.log('External data received, mixing', 'info', 'builder');
self.options.externalData.forEach(function (exData) {
['files', 'classes', 'modules'].forEach(function (k) {
Y.each(exData[k], function (item, key) {
item.external = true;
var file = item.name;
if (!item.file) {
file = self.filterFileName(item.name);
}
if (item.type) {
item.type = fixType(item.type);
}
item.path = exData.base + path.join(k, file + '.html');
self.data[k][key] = item;
});
});
Y.each(exData.classitems, function (item) {
item.external = true;
item.path = exData.base + path.join('files', self.filterFileName(item.file) + '.html');
if (item.type) {
item.type = fixType(item.type);
}
if (item.params) {
item.params.forEach(function (p) {
if (p.type) {
p.type = fixType(p.type);
}
});
}
if (item["return"]) {
item["return"].type = fixType(item["return"].type);
}
self.data.classitems.push(item);
});
});
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"Y",
".",
"log",
"(",
"'External data received, mixing'",
",",
"'info'",
",",
"'builder'",
")",
";",
"self",
".",
"options",
".",
"externalData",
".",
"forEach",
"(",
"function",
"(",
"exData",
")",
"{",
"[",
"'files'",
",",
"'classes'",
",",
"'modules'",
"]",
".",
"forEach",
"(",
"function",
"(",
"k",
")",
"{",
"Y",
".",
"each",
"(",
"exData",
"[",
"k",
"]",
",",
"function",
"(",
"item",
",",
"key",
")",
"{",
"item",
".",
"external",
"=",
"true",
";",
"var",
"file",
"=",
"item",
".",
"name",
";",
"if",
"(",
"!",
"item",
".",
"file",
")",
"{",
"file",
"=",
"self",
".",
"filterFileName",
"(",
"item",
".",
"name",
")",
";",
"}",
"if",
"(",
"item",
".",
"type",
")",
"{",
"item",
".",
"type",
"=",
"fixType",
"(",
"item",
".",
"type",
")",
";",
"}",
"item",
".",
"path",
"=",
"exData",
".",
"base",
"+",
"path",
".",
"join",
"(",
"k",
",",
"file",
"+",
"'.html'",
")",
";",
"self",
".",
"data",
"[",
"k",
"]",
"[",
"key",
"]",
"=",
"item",
";",
"}",
")",
";",
"}",
")",
";",
"Y",
".",
"each",
"(",
"exData",
".",
"classitems",
",",
"function",
"(",
"item",
")",
"{",
"item",
".",
"external",
"=",
"true",
";",
"item",
".",
"path",
"=",
"exData",
".",
"base",
"+",
"path",
".",
"join",
"(",
"'files'",
",",
"self",
".",
"filterFileName",
"(",
"item",
".",
"file",
")",
"+",
"'.html'",
")",
";",
"if",
"(",
"item",
".",
"type",
")",
"{",
"item",
".",
"type",
"=",
"fixType",
"(",
"item",
".",
"type",
")",
";",
"}",
"if",
"(",
"item",
".",
"params",
")",
"{",
"item",
".",
"params",
".",
"forEach",
"(",
"function",
"(",
"p",
")",
"{",
"if",
"(",
"p",
".",
"type",
")",
"{",
"p",
".",
"type",
"=",
"fixType",
"(",
"p",
".",
"type",
")",
";",
"}",
"}",
")",
";",
"}",
"if",
"(",
"item",
"[",
"\"return\"",
"]",
")",
"{",
"item",
"[",
"\"return\"",
"]",
".",
"type",
"=",
"fixType",
"(",
"item",
"[",
"\"return\"",
"]",
".",
"type",
")",
";",
"}",
"self",
".",
"data",
".",
"classitems",
".",
"push",
"(",
"item",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Mixes the various external data soures together into the local data, augmenting
it with flags.
@method _mixExternal
@private | [
"Mixes",
"the",
"various",
"external",
"data",
"soures",
"together",
"into",
"the",
"local",
"data",
"augmenting",
"it",
"with",
"flags",
"."
] | 5678f99ce876a62b2b7f7ad686d0e5b2531def3a | https://github.com/CreateJS/TweenJS/blob/5678f99ce876a62b2b7f7ad686d0e5b2531def3a/build/updates/builder.js#L330-L371 |
|
6,313 | CreateJS/TweenJS | build/updates/builder.js | function (cb) {
var self = this,
info = self.options.external;
if (!info) {
cb();
return;
}
if (!info.merge) {
info.merge = 'mix';
}
if (!info.data) {
Y.log('External config found but no data path defined, skipping import.', 'warn', 'builder');
cb();
return;
}
if (!Y.Lang.isArray(info.data)) {
info.data = [info.data];
}
Y.log('Importing external documentation data.', 'info', 'builder');
var stack = new Y.Parallel();
info.data.forEach(function (i) {
var base;
if (i.match(/^https?:\/\//)) {
base = i.replace('data.json', '');
Y.use('io-base', stack.add(function () {
Y.log('Fetching: ' + i, 'info', 'builder');
Y.io(i, {
on: {
complete: stack.add(function (id, e) {
Y.log('Received: ' + i, 'info', 'builder');
var data = JSON.parse(e.responseText);
data.base = base;
//self.options.externalData = Y.mix(self.options.externalData || {}, data);
if (!self.options.externalData) {
self.options.externalData = [];
}
self.options.externalData.push(data);
})
}
});
}));
} else {
base = path.dirname(path.resolve(i));
var data = Y.Files.getJSON(i);
data.base = base;
//self.options.externalData = Y.mix(self.options.externalData || {}, data);
if (!self.options.externalData) {
self.options.externalData = [];
}
self.options.externalData.push(data);
}
});
stack.done(function () {
Y.log('Finished fetching remote data', 'info', 'builder');
self._mixExternal();
cb();
});
} | javascript | function (cb) {
var self = this,
info = self.options.external;
if (!info) {
cb();
return;
}
if (!info.merge) {
info.merge = 'mix';
}
if (!info.data) {
Y.log('External config found but no data path defined, skipping import.', 'warn', 'builder');
cb();
return;
}
if (!Y.Lang.isArray(info.data)) {
info.data = [info.data];
}
Y.log('Importing external documentation data.', 'info', 'builder');
var stack = new Y.Parallel();
info.data.forEach(function (i) {
var base;
if (i.match(/^https?:\/\//)) {
base = i.replace('data.json', '');
Y.use('io-base', stack.add(function () {
Y.log('Fetching: ' + i, 'info', 'builder');
Y.io(i, {
on: {
complete: stack.add(function (id, e) {
Y.log('Received: ' + i, 'info', 'builder');
var data = JSON.parse(e.responseText);
data.base = base;
//self.options.externalData = Y.mix(self.options.externalData || {}, data);
if (!self.options.externalData) {
self.options.externalData = [];
}
self.options.externalData.push(data);
})
}
});
}));
} else {
base = path.dirname(path.resolve(i));
var data = Y.Files.getJSON(i);
data.base = base;
//self.options.externalData = Y.mix(self.options.externalData || {}, data);
if (!self.options.externalData) {
self.options.externalData = [];
}
self.options.externalData.push(data);
}
});
stack.done(function () {
Y.log('Finished fetching remote data', 'info', 'builder');
self._mixExternal();
cb();
});
} | [
"function",
"(",
"cb",
")",
"{",
"var",
"self",
"=",
"this",
",",
"info",
"=",
"self",
".",
"options",
".",
"external",
";",
"if",
"(",
"!",
"info",
")",
"{",
"cb",
"(",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"info",
".",
"merge",
")",
"{",
"info",
".",
"merge",
"=",
"'mix'",
";",
"}",
"if",
"(",
"!",
"info",
".",
"data",
")",
"{",
"Y",
".",
"log",
"(",
"'External config found but no data path defined, skipping import.'",
",",
"'warn'",
",",
"'builder'",
")",
";",
"cb",
"(",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"Y",
".",
"Lang",
".",
"isArray",
"(",
"info",
".",
"data",
")",
")",
"{",
"info",
".",
"data",
"=",
"[",
"info",
".",
"data",
"]",
";",
"}",
"Y",
".",
"log",
"(",
"'Importing external documentation data.'",
",",
"'info'",
",",
"'builder'",
")",
";",
"var",
"stack",
"=",
"new",
"Y",
".",
"Parallel",
"(",
")",
";",
"info",
".",
"data",
".",
"forEach",
"(",
"function",
"(",
"i",
")",
"{",
"var",
"base",
";",
"if",
"(",
"i",
".",
"match",
"(",
"/",
"^https?:\\/\\/",
"/",
")",
")",
"{",
"base",
"=",
"i",
".",
"replace",
"(",
"'data.json'",
",",
"''",
")",
";",
"Y",
".",
"use",
"(",
"'io-base'",
",",
"stack",
".",
"add",
"(",
"function",
"(",
")",
"{",
"Y",
".",
"log",
"(",
"'Fetching: '",
"+",
"i",
",",
"'info'",
",",
"'builder'",
")",
";",
"Y",
".",
"io",
"(",
"i",
",",
"{",
"on",
":",
"{",
"complete",
":",
"stack",
".",
"add",
"(",
"function",
"(",
"id",
",",
"e",
")",
"{",
"Y",
".",
"log",
"(",
"'Received: '",
"+",
"i",
",",
"'info'",
",",
"'builder'",
")",
";",
"var",
"data",
"=",
"JSON",
".",
"parse",
"(",
"e",
".",
"responseText",
")",
";",
"data",
".",
"base",
"=",
"base",
";",
"//self.options.externalData = Y.mix(self.options.externalData || {}, data);",
"if",
"(",
"!",
"self",
".",
"options",
".",
"externalData",
")",
"{",
"self",
".",
"options",
".",
"externalData",
"=",
"[",
"]",
";",
"}",
"self",
".",
"options",
".",
"externalData",
".",
"push",
"(",
"data",
")",
";",
"}",
")",
"}",
"}",
")",
";",
"}",
")",
")",
";",
"}",
"else",
"{",
"base",
"=",
"path",
".",
"dirname",
"(",
"path",
".",
"resolve",
"(",
"i",
")",
")",
";",
"var",
"data",
"=",
"Y",
".",
"Files",
".",
"getJSON",
"(",
"i",
")",
";",
"data",
".",
"base",
"=",
"base",
";",
"//self.options.externalData = Y.mix(self.options.externalData || {}, data);",
"if",
"(",
"!",
"self",
".",
"options",
".",
"externalData",
")",
"{",
"self",
".",
"options",
".",
"externalData",
"=",
"[",
"]",
";",
"}",
"self",
".",
"options",
".",
"externalData",
".",
"push",
"(",
"data",
")",
";",
"}",
"}",
")",
";",
"stack",
".",
"done",
"(",
"function",
"(",
")",
"{",
"Y",
".",
"log",
"(",
"'Finished fetching remote data'",
",",
"'info'",
",",
"'builder'",
")",
";",
"self",
".",
"_mixExternal",
"(",
")",
";",
"cb",
"(",
")",
";",
"}",
")",
";",
"}"
] | Fetches the remote data and fires the callback when it's all complete
@method mixExternal
@param {Callback} cb The callback to execute when complete
@async | [
"Fetches",
"the",
"remote",
"data",
"and",
"fires",
"the",
"callback",
"when",
"it",
"s",
"all",
"complete"
] | 5678f99ce876a62b2b7f7ad686d0e5b2531def3a | https://github.com/CreateJS/TweenJS/blob/5678f99ce876a62b2b7f7ad686d0e5b2531def3a/build/updates/builder.js#L378-L438 |
|
6,314 | CreateJS/TweenJS | build/updates/builder.js | function () {
var obj = {
meta: {
yuiSeedUrl: 'http://yui.yahooapis.com/3.5.0/build/yui/yui-min.js',
yuiGridsUrl: 'http://yui.yahooapis.com/3.5.0/build/cssgrids/cssgrids-min.css'
}
};
if (!this._meta) {
try {
var meta,
theme = path.join(themeDir, 'theme.json');
if (Y.Files.exists(theme)) {
Y.log('Loading theme from ' + theme, 'info', 'builder');
meta = Y.Files.getJSON(theme);
} else if (DEFAULT_THEME !== themeDir) {
theme = path.join(DEFAULT_THEME, 'theme.json');
if (Y.Files.exists(theme)) {
Y.log('Loading theme from ' + theme, 'info', 'builder');
meta = Y.Files.getJSON(theme);
}
}
if (meta) {
obj.meta = meta;
this._meta = meta;
}
} catch (e) {
console.error('Error', e);
}
} else {
obj.meta = this._meta;
}
Y.each(this.data.project, function (v, k) {
var key = k.substring(0, 1).toUpperCase() + k.substring(1, k.length);
obj.meta['project' + key] = v;
});
return obj;
} | javascript | function () {
var obj = {
meta: {
yuiSeedUrl: 'http://yui.yahooapis.com/3.5.0/build/yui/yui-min.js',
yuiGridsUrl: 'http://yui.yahooapis.com/3.5.0/build/cssgrids/cssgrids-min.css'
}
};
if (!this._meta) {
try {
var meta,
theme = path.join(themeDir, 'theme.json');
if (Y.Files.exists(theme)) {
Y.log('Loading theme from ' + theme, 'info', 'builder');
meta = Y.Files.getJSON(theme);
} else if (DEFAULT_THEME !== themeDir) {
theme = path.join(DEFAULT_THEME, 'theme.json');
if (Y.Files.exists(theme)) {
Y.log('Loading theme from ' + theme, 'info', 'builder');
meta = Y.Files.getJSON(theme);
}
}
if (meta) {
obj.meta = meta;
this._meta = meta;
}
} catch (e) {
console.error('Error', e);
}
} else {
obj.meta = this._meta;
}
Y.each(this.data.project, function (v, k) {
var key = k.substring(0, 1).toUpperCase() + k.substring(1, k.length);
obj.meta['project' + key] = v;
});
return obj;
} | [
"function",
"(",
")",
"{",
"var",
"obj",
"=",
"{",
"meta",
":",
"{",
"yuiSeedUrl",
":",
"'http://yui.yahooapis.com/3.5.0/build/yui/yui-min.js'",
",",
"yuiGridsUrl",
":",
"'http://yui.yahooapis.com/3.5.0/build/cssgrids/cssgrids-min.css'",
"}",
"}",
";",
"if",
"(",
"!",
"this",
".",
"_meta",
")",
"{",
"try",
"{",
"var",
"meta",
",",
"theme",
"=",
"path",
".",
"join",
"(",
"themeDir",
",",
"'theme.json'",
")",
";",
"if",
"(",
"Y",
".",
"Files",
".",
"exists",
"(",
"theme",
")",
")",
"{",
"Y",
".",
"log",
"(",
"'Loading theme from '",
"+",
"theme",
",",
"'info'",
",",
"'builder'",
")",
";",
"meta",
"=",
"Y",
".",
"Files",
".",
"getJSON",
"(",
"theme",
")",
";",
"}",
"else",
"if",
"(",
"DEFAULT_THEME",
"!==",
"themeDir",
")",
"{",
"theme",
"=",
"path",
".",
"join",
"(",
"DEFAULT_THEME",
",",
"'theme.json'",
")",
";",
"if",
"(",
"Y",
".",
"Files",
".",
"exists",
"(",
"theme",
")",
")",
"{",
"Y",
".",
"log",
"(",
"'Loading theme from '",
"+",
"theme",
",",
"'info'",
",",
"'builder'",
")",
";",
"meta",
"=",
"Y",
".",
"Files",
".",
"getJSON",
"(",
"theme",
")",
";",
"}",
"}",
"if",
"(",
"meta",
")",
"{",
"obj",
".",
"meta",
"=",
"meta",
";",
"this",
".",
"_meta",
"=",
"meta",
";",
"}",
"}",
"catch",
"(",
"e",
")",
"{",
"console",
".",
"error",
"(",
"'Error'",
",",
"e",
")",
";",
"}",
"}",
"else",
"{",
"obj",
".",
"meta",
"=",
"this",
".",
"_meta",
";",
"}",
"Y",
".",
"each",
"(",
"this",
".",
"data",
".",
"project",
",",
"function",
"(",
"v",
",",
"k",
")",
"{",
"var",
"key",
"=",
"k",
".",
"substring",
"(",
"0",
",",
"1",
")",
".",
"toUpperCase",
"(",
")",
"+",
"k",
".",
"substring",
"(",
"1",
",",
"k",
".",
"length",
")",
";",
"obj",
".",
"meta",
"[",
"'project'",
"+",
"key",
"]",
"=",
"v",
";",
"}",
")",
";",
"return",
"obj",
";",
"}"
] | Prep the meta data to be fed to Selleck
@method getProjectMeta
@return {Object} The project metadata | [
"Prep",
"the",
"meta",
"data",
"to",
"be",
"fed",
"to",
"Selleck"
] | 5678f99ce876a62b2b7f7ad686d0e5b2531def3a | https://github.com/CreateJS/TweenJS/blob/5678f99ce876a62b2b7f7ad686d0e5b2531def3a/build/updates/builder.js#L457-L494 |
|
6,315 | CreateJS/TweenJS | build/updates/builder.js | function (opts) {
opts.meta.classes = [];
Y.each(this.data.classes, function (v) {
if (v.external) {
return;
}
opts.meta.classes.push({
displayName: v.name,
name: v.name,
namespace: v.namespace,
module: v.module,
description: v.description,
access: v.access || 'public'
});
});
opts.meta.classes.sort(this.nameSort);
return opts;
} | javascript | function (opts) {
opts.meta.classes = [];
Y.each(this.data.classes, function (v) {
if (v.external) {
return;
}
opts.meta.classes.push({
displayName: v.name,
name: v.name,
namespace: v.namespace,
module: v.module,
description: v.description,
access: v.access || 'public'
});
});
opts.meta.classes.sort(this.nameSort);
return opts;
} | [
"function",
"(",
"opts",
")",
"{",
"opts",
".",
"meta",
".",
"classes",
"=",
"[",
"]",
";",
"Y",
".",
"each",
"(",
"this",
".",
"data",
".",
"classes",
",",
"function",
"(",
"v",
")",
"{",
"if",
"(",
"v",
".",
"external",
")",
"{",
"return",
";",
"}",
"opts",
".",
"meta",
".",
"classes",
".",
"push",
"(",
"{",
"displayName",
":",
"v",
".",
"name",
",",
"name",
":",
"v",
".",
"name",
",",
"namespace",
":",
"v",
".",
"namespace",
",",
"module",
":",
"v",
".",
"module",
",",
"description",
":",
"v",
".",
"description",
",",
"access",
":",
"v",
".",
"access",
"||",
"'public'",
"}",
")",
";",
"}",
")",
";",
"opts",
".",
"meta",
".",
"classes",
".",
"sort",
"(",
"this",
".",
"nameSort",
")",
";",
"return",
"opts",
";",
"}"
] | Populate the meta data for classes
@method populateClasses
@param {Object} opts The original options
@return {Object} The modified options | [
"Populate",
"the",
"meta",
"data",
"for",
"classes"
] | 5678f99ce876a62b2b7f7ad686d0e5b2531def3a | https://github.com/CreateJS/TweenJS/blob/5678f99ce876a62b2b7f7ad686d0e5b2531def3a/build/updates/builder.js#L501-L518 |
|
6,316 | CreateJS/TweenJS | build/updates/builder.js | function (opts) {
var self = this;
opts.meta.modules = [];
opts.meta.allModules = [];
Y.each(this.data.modules, function (v) {
if (v.external) {
return;
}
opts.meta.allModules.push({
displayName: v.displayName || v.name,
name: self.filterFileName(v.name),
description: v.description
});
if (!v.is_submodule) {
var o = {
displayName: v.displayName || v.name,
name: self.filterFileName(v.name)
};
if (v.submodules) {
o.submodules = [];
Y.each(v.submodules, function (i, k) {
var moddef = self.data.modules[k];
if (moddef) {
o.submodules.push({
displayName: k,
description: moddef.description
});
// } else {
// Y.log('Submodule data missing: ' + k + ' for ' + v.name, 'warn', 'builder');
}
});
o.submodules.sort(self.nameSort);
}
opts.meta.modules.push(o);
}
});
opts.meta.modules.sort(this.nameSort);
opts.meta.allModules.sort(this.nameSort);
return opts;
} | javascript | function (opts) {
var self = this;
opts.meta.modules = [];
opts.meta.allModules = [];
Y.each(this.data.modules, function (v) {
if (v.external) {
return;
}
opts.meta.allModules.push({
displayName: v.displayName || v.name,
name: self.filterFileName(v.name),
description: v.description
});
if (!v.is_submodule) {
var o = {
displayName: v.displayName || v.name,
name: self.filterFileName(v.name)
};
if (v.submodules) {
o.submodules = [];
Y.each(v.submodules, function (i, k) {
var moddef = self.data.modules[k];
if (moddef) {
o.submodules.push({
displayName: k,
description: moddef.description
});
// } else {
// Y.log('Submodule data missing: ' + k + ' for ' + v.name, 'warn', 'builder');
}
});
o.submodules.sort(self.nameSort);
}
opts.meta.modules.push(o);
}
});
opts.meta.modules.sort(this.nameSort);
opts.meta.allModules.sort(this.nameSort);
return opts;
} | [
"function",
"(",
"opts",
")",
"{",
"var",
"self",
"=",
"this",
";",
"opts",
".",
"meta",
".",
"modules",
"=",
"[",
"]",
";",
"opts",
".",
"meta",
".",
"allModules",
"=",
"[",
"]",
";",
"Y",
".",
"each",
"(",
"this",
".",
"data",
".",
"modules",
",",
"function",
"(",
"v",
")",
"{",
"if",
"(",
"v",
".",
"external",
")",
"{",
"return",
";",
"}",
"opts",
".",
"meta",
".",
"allModules",
".",
"push",
"(",
"{",
"displayName",
":",
"v",
".",
"displayName",
"||",
"v",
".",
"name",
",",
"name",
":",
"self",
".",
"filterFileName",
"(",
"v",
".",
"name",
")",
",",
"description",
":",
"v",
".",
"description",
"}",
")",
";",
"if",
"(",
"!",
"v",
".",
"is_submodule",
")",
"{",
"var",
"o",
"=",
"{",
"displayName",
":",
"v",
".",
"displayName",
"||",
"v",
".",
"name",
",",
"name",
":",
"self",
".",
"filterFileName",
"(",
"v",
".",
"name",
")",
"}",
";",
"if",
"(",
"v",
".",
"submodules",
")",
"{",
"o",
".",
"submodules",
"=",
"[",
"]",
";",
"Y",
".",
"each",
"(",
"v",
".",
"submodules",
",",
"function",
"(",
"i",
",",
"k",
")",
"{",
"var",
"moddef",
"=",
"self",
".",
"data",
".",
"modules",
"[",
"k",
"]",
";",
"if",
"(",
"moddef",
")",
"{",
"o",
".",
"submodules",
".",
"push",
"(",
"{",
"displayName",
":",
"k",
",",
"description",
":",
"moddef",
".",
"description",
"}",
")",
";",
"// } else {",
"// Y.log('Submodule data missing: ' + k + ' for ' + v.name, 'warn', 'builder');",
"}",
"}",
")",
";",
"o",
".",
"submodules",
".",
"sort",
"(",
"self",
".",
"nameSort",
")",
";",
"}",
"opts",
".",
"meta",
".",
"modules",
".",
"push",
"(",
"o",
")",
";",
"}",
"}",
")",
";",
"opts",
".",
"meta",
".",
"modules",
".",
"sort",
"(",
"this",
".",
"nameSort",
")",
";",
"opts",
".",
"meta",
".",
"allModules",
".",
"sort",
"(",
"this",
".",
"nameSort",
")",
";",
"return",
"opts",
";",
"}"
] | Populate the meta data for modules
@method populateModules
@param {Object} opts The original options
@return {Object} The modified options | [
"Populate",
"the",
"meta",
"data",
"for",
"modules"
] | 5678f99ce876a62b2b7f7ad686d0e5b2531def3a | https://github.com/CreateJS/TweenJS/blob/5678f99ce876a62b2b7f7ad686d0e5b2531def3a/build/updates/builder.js#L525-L564 |
|
6,317 | CreateJS/TweenJS | build/updates/builder.js | function (opts) {
var self = this;
opts.meta.files = [];
Y.each(this.data.files, function (v) {
if (v.external) {
return;
}
opts.meta.files.push({
displayName: v.name,
name: self.filterFileName(v.name),
path: v.path || v.name
});
});
var tree = {};
var files = [];
Y.each(this.data.files, function (v) {
if (v.external) {
return;
}
files.push(v.name);
});
files.sort();
Y.each(files, function (v) {
var p = v.split('/'),
par;
p.forEach(function (i, k) {
if (!par) {
if (!tree[i]) {
tree[i] = {};
}
par = tree[i];
} else {
if (!par[i]) {
par[i] = {};
}
if (k + 1 === p.length) {
par[i] = {
path: v,
name: self.filterFileName(v)
};
}
par = par[i];
}
});
});
opts.meta.fileTree = tree;
return opts;
} | javascript | function (opts) {
var self = this;
opts.meta.files = [];
Y.each(this.data.files, function (v) {
if (v.external) {
return;
}
opts.meta.files.push({
displayName: v.name,
name: self.filterFileName(v.name),
path: v.path || v.name
});
});
var tree = {};
var files = [];
Y.each(this.data.files, function (v) {
if (v.external) {
return;
}
files.push(v.name);
});
files.sort();
Y.each(files, function (v) {
var p = v.split('/'),
par;
p.forEach(function (i, k) {
if (!par) {
if (!tree[i]) {
tree[i] = {};
}
par = tree[i];
} else {
if (!par[i]) {
par[i] = {};
}
if (k + 1 === p.length) {
par[i] = {
path: v,
name: self.filterFileName(v)
};
}
par = par[i];
}
});
});
opts.meta.fileTree = tree;
return opts;
} | [
"function",
"(",
"opts",
")",
"{",
"var",
"self",
"=",
"this",
";",
"opts",
".",
"meta",
".",
"files",
"=",
"[",
"]",
";",
"Y",
".",
"each",
"(",
"this",
".",
"data",
".",
"files",
",",
"function",
"(",
"v",
")",
"{",
"if",
"(",
"v",
".",
"external",
")",
"{",
"return",
";",
"}",
"opts",
".",
"meta",
".",
"files",
".",
"push",
"(",
"{",
"displayName",
":",
"v",
".",
"name",
",",
"name",
":",
"self",
".",
"filterFileName",
"(",
"v",
".",
"name",
")",
",",
"path",
":",
"v",
".",
"path",
"||",
"v",
".",
"name",
"}",
")",
";",
"}",
")",
";",
"var",
"tree",
"=",
"{",
"}",
";",
"var",
"files",
"=",
"[",
"]",
";",
"Y",
".",
"each",
"(",
"this",
".",
"data",
".",
"files",
",",
"function",
"(",
"v",
")",
"{",
"if",
"(",
"v",
".",
"external",
")",
"{",
"return",
";",
"}",
"files",
".",
"push",
"(",
"v",
".",
"name",
")",
";",
"}",
")",
";",
"files",
".",
"sort",
"(",
")",
";",
"Y",
".",
"each",
"(",
"files",
",",
"function",
"(",
"v",
")",
"{",
"var",
"p",
"=",
"v",
".",
"split",
"(",
"'/'",
")",
",",
"par",
";",
"p",
".",
"forEach",
"(",
"function",
"(",
"i",
",",
"k",
")",
"{",
"if",
"(",
"!",
"par",
")",
"{",
"if",
"(",
"!",
"tree",
"[",
"i",
"]",
")",
"{",
"tree",
"[",
"i",
"]",
"=",
"{",
"}",
";",
"}",
"par",
"=",
"tree",
"[",
"i",
"]",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"par",
"[",
"i",
"]",
")",
"{",
"par",
"[",
"i",
"]",
"=",
"{",
"}",
";",
"}",
"if",
"(",
"k",
"+",
"1",
"===",
"p",
".",
"length",
")",
"{",
"par",
"[",
"i",
"]",
"=",
"{",
"path",
":",
"v",
",",
"name",
":",
"self",
".",
"filterFileName",
"(",
"v",
")",
"}",
";",
"}",
"par",
"=",
"par",
"[",
"i",
"]",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"opts",
".",
"meta",
".",
"fileTree",
"=",
"tree",
";",
"return",
"opts",
";",
"}"
] | Populate the meta data for files
@method populateFiles
@param {Object} opts The original options
@return {Object} The modified options | [
"Populate",
"the",
"meta",
"data",
"for",
"files"
] | 5678f99ce876a62b2b7f7ad686d0e5b2531def3a | https://github.com/CreateJS/TweenJS/blob/5678f99ce876a62b2b7f7ad686d0e5b2531def3a/build/updates/builder.js#L571-L621 |
|
6,318 | CreateJS/TweenJS | build/updates/builder.js | function (a) {
var self = this;
if (a.file && a.line && !self.options.nocode) {
a.foundAt = '../files/' + self.filterFileName(a.file) + '.html#l' + a.line;
if (a.path) {
a.foundAt = a.path + '#l' + a.line;
}
}
return a;
} | javascript | function (a) {
var self = this;
if (a.file && a.line && !self.options.nocode) {
a.foundAt = '../files/' + self.filterFileName(a.file) + '.html#l' + a.line;
if (a.path) {
a.foundAt = a.path + '#l' + a.line;
}
}
return a;
} | [
"function",
"(",
"a",
")",
"{",
"var",
"self",
"=",
"this",
";",
"if",
"(",
"a",
".",
"file",
"&&",
"a",
".",
"line",
"&&",
"!",
"self",
".",
"options",
".",
"nocode",
")",
"{",
"a",
".",
"foundAt",
"=",
"'../files/'",
"+",
"self",
".",
"filterFileName",
"(",
"a",
".",
"file",
")",
"+",
"'.html#l'",
"+",
"a",
".",
"line",
";",
"if",
"(",
"a",
".",
"path",
")",
"{",
"a",
".",
"foundAt",
"=",
"a",
".",
"path",
"+",
"'#l'",
"+",
"a",
".",
"line",
";",
"}",
"}",
"return",
"a",
";",
"}"
] | Parses file and line number from an item object and build's an HREF
@method addFoundAt
@param {Object} a The item to parse
@return {String} The parsed HREF | [
"Parses",
"file",
"and",
"line",
"number",
"from",
"an",
"item",
"object",
"and",
"build",
"s",
"an",
"HREF"
] | 5678f99ce876a62b2b7f7ad686d0e5b2531def3a | https://github.com/CreateJS/TweenJS/blob/5678f99ce876a62b2b7f7ad686d0e5b2531def3a/build/updates/builder.js#L628-L637 |
|
6,319 | CreateJS/TweenJS | build/updates/builder.js | function (cb) {
var self = this;
var dirs = ['classes', 'modules', 'files'];
if (self.options.dumpview) {
dirs.push('json');
}
var writeRedirect = function (dir, file, cb) {
Y.Files.exists(file, function (x) {
if (x) {
var out = path.join(dir, 'index.html');
fs.createReadStream(file).pipe(fs.createWriteStream(out));
}
cb();
});
};
var defaultIndex = path.join(themeDir, 'assets', 'index.html');
var stack = new Y.Parallel();
Y.log('Making default directories: ' + dirs.join(','), 'info', 'builder');
dirs.forEach(function (d) {
var dir = path.join(self.options.outdir, d);
Y.Files.exists(dir, stack.add(function (x) {
if (!x) {
fs.mkdir(dir, 0777, stack.add(function () {
writeRedirect(dir, defaultIndex, stack.add(noop));
}));
} else {
writeRedirect(dir, defaultIndex, stack.add(noop));
}
}));
});
stack.done(function () {
if (cb) {
cb();
}
});
} | javascript | function (cb) {
var self = this;
var dirs = ['classes', 'modules', 'files'];
if (self.options.dumpview) {
dirs.push('json');
}
var writeRedirect = function (dir, file, cb) {
Y.Files.exists(file, function (x) {
if (x) {
var out = path.join(dir, 'index.html');
fs.createReadStream(file).pipe(fs.createWriteStream(out));
}
cb();
});
};
var defaultIndex = path.join(themeDir, 'assets', 'index.html');
var stack = new Y.Parallel();
Y.log('Making default directories: ' + dirs.join(','), 'info', 'builder');
dirs.forEach(function (d) {
var dir = path.join(self.options.outdir, d);
Y.Files.exists(dir, stack.add(function (x) {
if (!x) {
fs.mkdir(dir, 0777, stack.add(function () {
writeRedirect(dir, defaultIndex, stack.add(noop));
}));
} else {
writeRedirect(dir, defaultIndex, stack.add(noop));
}
}));
});
stack.done(function () {
if (cb) {
cb();
}
});
} | [
"function",
"(",
"cb",
")",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"dirs",
"=",
"[",
"'classes'",
",",
"'modules'",
",",
"'files'",
"]",
";",
"if",
"(",
"self",
".",
"options",
".",
"dumpview",
")",
"{",
"dirs",
".",
"push",
"(",
"'json'",
")",
";",
"}",
"var",
"writeRedirect",
"=",
"function",
"(",
"dir",
",",
"file",
",",
"cb",
")",
"{",
"Y",
".",
"Files",
".",
"exists",
"(",
"file",
",",
"function",
"(",
"x",
")",
"{",
"if",
"(",
"x",
")",
"{",
"var",
"out",
"=",
"path",
".",
"join",
"(",
"dir",
",",
"'index.html'",
")",
";",
"fs",
".",
"createReadStream",
"(",
"file",
")",
".",
"pipe",
"(",
"fs",
".",
"createWriteStream",
"(",
"out",
")",
")",
";",
"}",
"cb",
"(",
")",
";",
"}",
")",
";",
"}",
";",
"var",
"defaultIndex",
"=",
"path",
".",
"join",
"(",
"themeDir",
",",
"'assets'",
",",
"'index.html'",
")",
";",
"var",
"stack",
"=",
"new",
"Y",
".",
"Parallel",
"(",
")",
";",
"Y",
".",
"log",
"(",
"'Making default directories: '",
"+",
"dirs",
".",
"join",
"(",
"','",
")",
",",
"'info'",
",",
"'builder'",
")",
";",
"dirs",
".",
"forEach",
"(",
"function",
"(",
"d",
")",
"{",
"var",
"dir",
"=",
"path",
".",
"join",
"(",
"self",
".",
"options",
".",
"outdir",
",",
"d",
")",
";",
"Y",
".",
"Files",
".",
"exists",
"(",
"dir",
",",
"stack",
".",
"add",
"(",
"function",
"(",
"x",
")",
"{",
"if",
"(",
"!",
"x",
")",
"{",
"fs",
".",
"mkdir",
"(",
"dir",
",",
"0777",
",",
"stack",
".",
"add",
"(",
"function",
"(",
")",
"{",
"writeRedirect",
"(",
"dir",
",",
"defaultIndex",
",",
"stack",
".",
"add",
"(",
"noop",
")",
")",
";",
"}",
")",
")",
";",
"}",
"else",
"{",
"writeRedirect",
"(",
"dir",
",",
"defaultIndex",
",",
"stack",
".",
"add",
"(",
"noop",
")",
")",
";",
"}",
"}",
")",
")",
";",
"}",
")",
";",
"stack",
".",
"done",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"cb",
")",
"{",
"cb",
"(",
")",
";",
"}",
"}",
")",
";",
"}"
] | Makes the default directories needed
@method makeDirs
@param {Callback} cb The callback to execute after it's completed | [
"Makes",
"the",
"default",
"directories",
"needed"
] | 5678f99ce876a62b2b7f7ad686d0e5b2531def3a | https://github.com/CreateJS/TweenJS/blob/5678f99ce876a62b2b7f7ad686d0e5b2531def3a/build/updates/builder.js#L709-L744 |
|
6,320 | CreateJS/TweenJS | build/updates/builder.js | function (cb) {
var self = this;
Y.prepare([DEFAULT_THEME, themeDir], self.getProjectMeta(), function (err, opts) {
opts.meta.title = self.data.project.name;
opts.meta.projectRoot = './';
opts.meta.projectAssets = './assets';
opts.meta.projectLogo = self._resolveUrl(self.data.project.logo, opts);
opts = self.populateClasses(opts);
opts = self.populateModules(opts);
var view = new Y.DocView(opts.meta);
self.render('{{>index}}', view, opts.layouts.main, opts.partials, function (err, html) {
self.files++;
cb(html, view);
});
});
} | javascript | function (cb) {
var self = this;
Y.prepare([DEFAULT_THEME, themeDir], self.getProjectMeta(), function (err, opts) {
opts.meta.title = self.data.project.name;
opts.meta.projectRoot = './';
opts.meta.projectAssets = './assets';
opts.meta.projectLogo = self._resolveUrl(self.data.project.logo, opts);
opts = self.populateClasses(opts);
opts = self.populateModules(opts);
var view = new Y.DocView(opts.meta);
self.render('{{>index}}', view, opts.layouts.main, opts.partials, function (err, html) {
self.files++;
cb(html, view);
});
});
} | [
"function",
"(",
"cb",
")",
"{",
"var",
"self",
"=",
"this",
";",
"Y",
".",
"prepare",
"(",
"[",
"DEFAULT_THEME",
",",
"themeDir",
"]",
",",
"self",
".",
"getProjectMeta",
"(",
")",
",",
"function",
"(",
"err",
",",
"opts",
")",
"{",
"opts",
".",
"meta",
".",
"title",
"=",
"self",
".",
"data",
".",
"project",
".",
"name",
";",
"opts",
".",
"meta",
".",
"projectRoot",
"=",
"'./'",
";",
"opts",
".",
"meta",
".",
"projectAssets",
"=",
"'./assets'",
";",
"opts",
".",
"meta",
".",
"projectLogo",
"=",
"self",
".",
"_resolveUrl",
"(",
"self",
".",
"data",
".",
"project",
".",
"logo",
",",
"opts",
")",
";",
"opts",
"=",
"self",
".",
"populateClasses",
"(",
"opts",
")",
";",
"opts",
"=",
"self",
".",
"populateModules",
"(",
"opts",
")",
";",
"var",
"view",
"=",
"new",
"Y",
".",
"DocView",
"(",
"opts",
".",
"meta",
")",
";",
"self",
".",
"render",
"(",
"'{{>index}}'",
",",
"view",
",",
"opts",
".",
"layouts",
".",
"main",
",",
"opts",
".",
"partials",
",",
"function",
"(",
"err",
",",
"html",
")",
"{",
"self",
".",
"files",
"++",
";",
"cb",
"(",
"html",
",",
"view",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Render the index file
@method renderIndex
@param {Function} cb The callback fired when complete
@param {String} cb.html The HTML to render this view
@param {Object} cv.view The View Data | [
"Render",
"the",
"index",
"file"
] | 5678f99ce876a62b2b7f7ad686d0e5b2531def3a | https://github.com/CreateJS/TweenJS/blob/5678f99ce876a62b2b7f7ad686d0e5b2531def3a/build/updates/builder.js#L852-L869 |
|
6,321 | CreateJS/TweenJS | build/updates/builder.js | function (cb) {
var self = this,
stack = new Y.Parallel();
Y.log('Preparing index.html', 'info', 'builder');
self.renderIndex(stack.add(function (html, view) {
stack.html = html;
stack.view = view;
if (self.options.dumpview) {
Y.Files.writeFile(path.join(self.options.outdir, 'json', 'index.json'), JSON.stringify(view), stack.add(noop));
}
Y.Files.writeFile(path.join(self.options.outdir, 'index.html'), html, stack.add(noop));
}));
stack.done(function ( /* html, view */ ) {
Y.log('Writing index.html', 'info', 'builder');
cb(stack.html, stack.view);
});
} | javascript | function (cb) {
var self = this,
stack = new Y.Parallel();
Y.log('Preparing index.html', 'info', 'builder');
self.renderIndex(stack.add(function (html, view) {
stack.html = html;
stack.view = view;
if (self.options.dumpview) {
Y.Files.writeFile(path.join(self.options.outdir, 'json', 'index.json'), JSON.stringify(view), stack.add(noop));
}
Y.Files.writeFile(path.join(self.options.outdir, 'index.html'), html, stack.add(noop));
}));
stack.done(function ( /* html, view */ ) {
Y.log('Writing index.html', 'info', 'builder');
cb(stack.html, stack.view);
});
} | [
"function",
"(",
"cb",
")",
"{",
"var",
"self",
"=",
"this",
",",
"stack",
"=",
"new",
"Y",
".",
"Parallel",
"(",
")",
";",
"Y",
".",
"log",
"(",
"'Preparing index.html'",
",",
"'info'",
",",
"'builder'",
")",
";",
"self",
".",
"renderIndex",
"(",
"stack",
".",
"add",
"(",
"function",
"(",
"html",
",",
"view",
")",
"{",
"stack",
".",
"html",
"=",
"html",
";",
"stack",
".",
"view",
"=",
"view",
";",
"if",
"(",
"self",
".",
"options",
".",
"dumpview",
")",
"{",
"Y",
".",
"Files",
".",
"writeFile",
"(",
"path",
".",
"join",
"(",
"self",
".",
"options",
".",
"outdir",
",",
"'json'",
",",
"'index.json'",
")",
",",
"JSON",
".",
"stringify",
"(",
"view",
")",
",",
"stack",
".",
"add",
"(",
"noop",
")",
")",
";",
"}",
"Y",
".",
"Files",
".",
"writeFile",
"(",
"path",
".",
"join",
"(",
"self",
".",
"options",
".",
"outdir",
",",
"'index.html'",
")",
",",
"html",
",",
"stack",
".",
"add",
"(",
"noop",
")",
")",
";",
"}",
")",
")",
";",
"stack",
".",
"done",
"(",
"function",
"(",
"/* html, view */",
")",
"{",
"Y",
".",
"log",
"(",
"'Writing index.html'",
",",
"'info'",
",",
"'builder'",
")",
";",
"cb",
"(",
"stack",
".",
"html",
",",
"stack",
".",
"view",
")",
";",
"}",
")",
";",
"}"
] | Generates the index.html file
@method writeIndex
@param {Callback} cb The callback to execute after it's completed | [
"Generates",
"the",
"index",
".",
"html",
"file"
] | 5678f99ce876a62b2b7f7ad686d0e5b2531def3a | https://github.com/CreateJS/TweenJS/blob/5678f99ce876a62b2b7f7ad686d0e5b2531def3a/build/updates/builder.js#L875-L893 |
|
6,322 | CreateJS/TweenJS | build/updates/builder.js | function (info, classItems, first) {
var self = this;
self._mergeCounter = (first) ? 0 : (self._mergeCounter + 1);
if (self._mergeCounter === 100) {
throw ('YUIDoc detected a loop extending class ' + info.name);
}
if (info.extends || info.uses) {
var hasItems = {};
hasItems[info.extends] = 1;
if (info.uses) {
info.uses.forEach(function (v) {
hasItems[v] = 1;
});
}
self.data.classitems.forEach(function (v) {
//console.error(v.class, '==', info.extends);
if (hasItems[v.class]) {
if (!v.static) {
var q,
override = self.hasProperty(classItems, v);
if (override === false) {
//This method was extended from the parent class but not over written
//console.error('Merging extends from', v.class, 'onto', info.name);
q = Y.merge({}, v);
q.extended_from = v.class;
classItems.push(q);
} else {
//This method was extended from the parent and overwritten in this class
q = Y.merge({}, v);
q = self.augmentData(q);
classItems[override].overwritten_from = q;
}
}
}
});
if (self.data.classes[info.extends]) {
if (self.data.classes[info.extends].extends || self.data.classes[info.extends].uses) {
//console.error('Stepping down to:', self.data.classes[info.extends]);
classItems = self.mergeExtends(self.data.classes[info.extends], classItems);
}
}
}
return classItems;
} | javascript | function (info, classItems, first) {
var self = this;
self._mergeCounter = (first) ? 0 : (self._mergeCounter + 1);
if (self._mergeCounter === 100) {
throw ('YUIDoc detected a loop extending class ' + info.name);
}
if (info.extends || info.uses) {
var hasItems = {};
hasItems[info.extends] = 1;
if (info.uses) {
info.uses.forEach(function (v) {
hasItems[v] = 1;
});
}
self.data.classitems.forEach(function (v) {
//console.error(v.class, '==', info.extends);
if (hasItems[v.class]) {
if (!v.static) {
var q,
override = self.hasProperty(classItems, v);
if (override === false) {
//This method was extended from the parent class but not over written
//console.error('Merging extends from', v.class, 'onto', info.name);
q = Y.merge({}, v);
q.extended_from = v.class;
classItems.push(q);
} else {
//This method was extended from the parent and overwritten in this class
q = Y.merge({}, v);
q = self.augmentData(q);
classItems[override].overwritten_from = q;
}
}
}
});
if (self.data.classes[info.extends]) {
if (self.data.classes[info.extends].extends || self.data.classes[info.extends].uses) {
//console.error('Stepping down to:', self.data.classes[info.extends]);
classItems = self.mergeExtends(self.data.classes[info.extends], classItems);
}
}
}
return classItems;
} | [
"function",
"(",
"info",
",",
"classItems",
",",
"first",
")",
"{",
"var",
"self",
"=",
"this",
";",
"self",
".",
"_mergeCounter",
"=",
"(",
"first",
")",
"?",
"0",
":",
"(",
"self",
".",
"_mergeCounter",
"+",
"1",
")",
";",
"if",
"(",
"self",
".",
"_mergeCounter",
"===",
"100",
")",
"{",
"throw",
"(",
"'YUIDoc detected a loop extending class '",
"+",
"info",
".",
"name",
")",
";",
"}",
"if",
"(",
"info",
".",
"extends",
"||",
"info",
".",
"uses",
")",
"{",
"var",
"hasItems",
"=",
"{",
"}",
";",
"hasItems",
"[",
"info",
".",
"extends",
"]",
"=",
"1",
";",
"if",
"(",
"info",
".",
"uses",
")",
"{",
"info",
".",
"uses",
".",
"forEach",
"(",
"function",
"(",
"v",
")",
"{",
"hasItems",
"[",
"v",
"]",
"=",
"1",
";",
"}",
")",
";",
"}",
"self",
".",
"data",
".",
"classitems",
".",
"forEach",
"(",
"function",
"(",
"v",
")",
"{",
"//console.error(v.class, '==', info.extends);",
"if",
"(",
"hasItems",
"[",
"v",
".",
"class",
"]",
")",
"{",
"if",
"(",
"!",
"v",
".",
"static",
")",
"{",
"var",
"q",
",",
"override",
"=",
"self",
".",
"hasProperty",
"(",
"classItems",
",",
"v",
")",
";",
"if",
"(",
"override",
"===",
"false",
")",
"{",
"//This method was extended from the parent class but not over written",
"//console.error('Merging extends from', v.class, 'onto', info.name);",
"q",
"=",
"Y",
".",
"merge",
"(",
"{",
"}",
",",
"v",
")",
";",
"q",
".",
"extended_from",
"=",
"v",
".",
"class",
";",
"classItems",
".",
"push",
"(",
"q",
")",
";",
"}",
"else",
"{",
"//This method was extended from the parent and overwritten in this class",
"q",
"=",
"Y",
".",
"merge",
"(",
"{",
"}",
",",
"v",
")",
";",
"q",
"=",
"self",
".",
"augmentData",
"(",
"q",
")",
";",
"classItems",
"[",
"override",
"]",
".",
"overwritten_from",
"=",
"q",
";",
"}",
"}",
"}",
"}",
")",
";",
"if",
"(",
"self",
".",
"data",
".",
"classes",
"[",
"info",
".",
"extends",
"]",
")",
"{",
"if",
"(",
"self",
".",
"data",
".",
"classes",
"[",
"info",
".",
"extends",
"]",
".",
"extends",
"||",
"self",
".",
"data",
".",
"classes",
"[",
"info",
".",
"extends",
"]",
".",
"uses",
")",
"{",
"//console.error('Stepping down to:', self.data.classes[info.extends]);",
"classItems",
"=",
"self",
".",
"mergeExtends",
"(",
"self",
".",
"data",
".",
"classes",
"[",
"info",
".",
"extends",
"]",
",",
"classItems",
")",
";",
"}",
"}",
"}",
"return",
"classItems",
";",
"}"
] | Merge superclass data into a child class
@method mergeExtends
@param {Object} info The item to extend
@param {Array} classItems The list of items to merge in
@param {Boolean} first Set for the first call | [
"Merge",
"superclass",
"data",
"into",
"a",
"child",
"class"
] | 5678f99ce876a62b2b7f7ad686d0e5b2531def3a | https://github.com/CreateJS/TweenJS/blob/5678f99ce876a62b2b7f7ad686d0e5b2531def3a/build/updates/builder.js#L1050-L1094 |
|
6,323 | CreateJS/TweenJS | build/updates/builder.js | function (cb, data, layout) {
var self = this;
Y.prepare([DEFAULT_THEME, themeDir], self.getProjectMeta(), function (err, opts) {
if (err) {
console.log(err);
}
if (!data.name) {
return;
}
opts.meta = Y.merge(opts.meta, data);
opts.meta.title = self.data.project.name;
opts.meta.moduleName = data.name;
opts.meta.projectRoot = '../';
opts.meta.projectAssets = '../assets';
opts.meta.projectLogo = self._resolveUrl(self.data.project.logo, opts);
opts = self.populateClasses(opts);
opts = self.populateModules(opts);
opts = self.populateFiles(opts);
opts.meta.fileName = data.name;
fs.readFile(opts.meta.fileName, Y.charset, Y.rbind(function (err, str, opts, data) {
if (err) {
Y.log(err, 'error', 'builder');
cb(err);
return;
}
if (typeof self.options.tabspace === 'string') {
str = str.replace(/\t/g, self.options.tabspace);
}
opts.meta.fileData = str;
var view = new Y.DocView(opts.meta, 'index');
var mainLayout = opts.layouts[layout];
self.render('{{>files}}', view, mainLayout, opts.partials, function (err, html) {
self.files++;
cb(html, view, data);
});
}, this, opts, data));
});
} | javascript | function (cb, data, layout) {
var self = this;
Y.prepare([DEFAULT_THEME, themeDir], self.getProjectMeta(), function (err, opts) {
if (err) {
console.log(err);
}
if (!data.name) {
return;
}
opts.meta = Y.merge(opts.meta, data);
opts.meta.title = self.data.project.name;
opts.meta.moduleName = data.name;
opts.meta.projectRoot = '../';
opts.meta.projectAssets = '../assets';
opts.meta.projectLogo = self._resolveUrl(self.data.project.logo, opts);
opts = self.populateClasses(opts);
opts = self.populateModules(opts);
opts = self.populateFiles(opts);
opts.meta.fileName = data.name;
fs.readFile(opts.meta.fileName, Y.charset, Y.rbind(function (err, str, opts, data) {
if (err) {
Y.log(err, 'error', 'builder');
cb(err);
return;
}
if (typeof self.options.tabspace === 'string') {
str = str.replace(/\t/g, self.options.tabspace);
}
opts.meta.fileData = str;
var view = new Y.DocView(opts.meta, 'index');
var mainLayout = opts.layouts[layout];
self.render('{{>files}}', view, mainLayout, opts.partials, function (err, html) {
self.files++;
cb(html, view, data);
});
}, this, opts, data));
});
} | [
"function",
"(",
"cb",
",",
"data",
",",
"layout",
")",
"{",
"var",
"self",
"=",
"this",
";",
"Y",
".",
"prepare",
"(",
"[",
"DEFAULT_THEME",
",",
"themeDir",
"]",
",",
"self",
".",
"getProjectMeta",
"(",
")",
",",
"function",
"(",
"err",
",",
"opts",
")",
"{",
"if",
"(",
"err",
")",
"{",
"console",
".",
"log",
"(",
"err",
")",
";",
"}",
"if",
"(",
"!",
"data",
".",
"name",
")",
"{",
"return",
";",
"}",
"opts",
".",
"meta",
"=",
"Y",
".",
"merge",
"(",
"opts",
".",
"meta",
",",
"data",
")",
";",
"opts",
".",
"meta",
".",
"title",
"=",
"self",
".",
"data",
".",
"project",
".",
"name",
";",
"opts",
".",
"meta",
".",
"moduleName",
"=",
"data",
".",
"name",
";",
"opts",
".",
"meta",
".",
"projectRoot",
"=",
"'../'",
";",
"opts",
".",
"meta",
".",
"projectAssets",
"=",
"'../assets'",
";",
"opts",
".",
"meta",
".",
"projectLogo",
"=",
"self",
".",
"_resolveUrl",
"(",
"self",
".",
"data",
".",
"project",
".",
"logo",
",",
"opts",
")",
";",
"opts",
"=",
"self",
".",
"populateClasses",
"(",
"opts",
")",
";",
"opts",
"=",
"self",
".",
"populateModules",
"(",
"opts",
")",
";",
"opts",
"=",
"self",
".",
"populateFiles",
"(",
"opts",
")",
";",
"opts",
".",
"meta",
".",
"fileName",
"=",
"data",
".",
"name",
";",
"fs",
".",
"readFile",
"(",
"opts",
".",
"meta",
".",
"fileName",
",",
"Y",
".",
"charset",
",",
"Y",
".",
"rbind",
"(",
"function",
"(",
"err",
",",
"str",
",",
"opts",
",",
"data",
")",
"{",
"if",
"(",
"err",
")",
"{",
"Y",
".",
"log",
"(",
"err",
",",
"'error'",
",",
"'builder'",
")",
";",
"cb",
"(",
"err",
")",
";",
"return",
";",
"}",
"if",
"(",
"typeof",
"self",
".",
"options",
".",
"tabspace",
"===",
"'string'",
")",
"{",
"str",
"=",
"str",
".",
"replace",
"(",
"/",
"\\t",
"/",
"g",
",",
"self",
".",
"options",
".",
"tabspace",
")",
";",
"}",
"opts",
".",
"meta",
".",
"fileData",
"=",
"str",
";",
"var",
"view",
"=",
"new",
"Y",
".",
"DocView",
"(",
"opts",
".",
"meta",
",",
"'index'",
")",
";",
"var",
"mainLayout",
"=",
"opts",
".",
"layouts",
"[",
"layout",
"]",
";",
"self",
".",
"render",
"(",
"'{{>files}}'",
",",
"view",
",",
"mainLayout",
",",
"opts",
".",
"partials",
",",
"function",
"(",
"err",
",",
"html",
")",
"{",
"self",
".",
"files",
"++",
";",
"cb",
"(",
"html",
",",
"view",
",",
"data",
")",
";",
"}",
")",
";",
"}",
",",
"this",
",",
"opts",
",",
"data",
")",
")",
";",
"}",
")",
";",
"}"
] | Render the source file
@method renderFile
@param {Function} cb The callback fired when complete
@param {String} cb.html The HTML to render this view
@param {Object} cv.view The View Data | [
"Render",
"the",
"source",
"file"
] | 5678f99ce876a62b2b7f7ad686d0e5b2531def3a | https://github.com/CreateJS/TweenJS/blob/5678f99ce876a62b2b7f7ad686d0e5b2531def3a/build/updates/builder.js#L1503-L1549 |
|
6,324 | CreateJS/TweenJS | build/updates/builder.js | function (cb) {
Y.log('Writing API Meta Data', 'info', 'builder');
var self = this;
this.renderAPIMeta(function (js) {
fs.writeFile(path.join(self.options.outdir, 'api.js'), js, Y.charset, cb);
});
} | javascript | function (cb) {
Y.log('Writing API Meta Data', 'info', 'builder');
var self = this;
this.renderAPIMeta(function (js) {
fs.writeFile(path.join(self.options.outdir, 'api.js'), js, Y.charset, cb);
});
} | [
"function",
"(",
"cb",
")",
"{",
"Y",
".",
"log",
"(",
"'Writing API Meta Data'",
",",
"'info'",
",",
"'builder'",
")",
";",
"var",
"self",
"=",
"this",
";",
"this",
".",
"renderAPIMeta",
"(",
"function",
"(",
"js",
")",
"{",
"fs",
".",
"writeFile",
"(",
"path",
".",
"join",
"(",
"self",
".",
"options",
".",
"outdir",
",",
"'api.js'",
")",
",",
"js",
",",
"Y",
".",
"charset",
",",
"cb",
")",
";",
"}",
")",
";",
"}"
] | Write the API meta data used for the AutoComplete widget
@method writeAPIMeta
@param {Callback} cb The callback to execute when complete
@async | [
"Write",
"the",
"API",
"meta",
"data",
"used",
"for",
"the",
"AutoComplete",
"widget"
] | 5678f99ce876a62b2b7f7ad686d0e5b2531def3a | https://github.com/CreateJS/TweenJS/blob/5678f99ce876a62b2b7f7ad686d0e5b2531def3a/build/updates/builder.js#L1556-L1562 |
|
6,325 | CreateJS/TweenJS | build/updates/builder.js | function (cb) {
var opts = {
meta: {}
};
opts = this.populateClasses(opts);
opts = this.populateModules(opts);
['classes', 'modules'].forEach(function (id) {
opts.meta[id].forEach(function (v, k) {
opts.meta[id][k] = v.name;
if (v.submodules) {
v.submodules.forEach(function (s) {
opts.meta[id].push(s.displayName);
});
}
});
opts.meta[id].sort();
});
var apijs = 'YUI.add("yuidoc-meta", function(Y) {\n' +
' Y.YUIDoc = { meta: ' + JSON.stringify(opts.meta, null, 4) + ' };\n' +
'});';
cb(apijs);
} | javascript | function (cb) {
var opts = {
meta: {}
};
opts = this.populateClasses(opts);
opts = this.populateModules(opts);
['classes', 'modules'].forEach(function (id) {
opts.meta[id].forEach(function (v, k) {
opts.meta[id][k] = v.name;
if (v.submodules) {
v.submodules.forEach(function (s) {
opts.meta[id].push(s.displayName);
});
}
});
opts.meta[id].sort();
});
var apijs = 'YUI.add("yuidoc-meta", function(Y) {\n' +
' Y.YUIDoc = { meta: ' + JSON.stringify(opts.meta, null, 4) + ' };\n' +
'});';
cb(apijs);
} | [
"function",
"(",
"cb",
")",
"{",
"var",
"opts",
"=",
"{",
"meta",
":",
"{",
"}",
"}",
";",
"opts",
"=",
"this",
".",
"populateClasses",
"(",
"opts",
")",
";",
"opts",
"=",
"this",
".",
"populateModules",
"(",
"opts",
")",
";",
"[",
"'classes'",
",",
"'modules'",
"]",
".",
"forEach",
"(",
"function",
"(",
"id",
")",
"{",
"opts",
".",
"meta",
"[",
"id",
"]",
".",
"forEach",
"(",
"function",
"(",
"v",
",",
"k",
")",
"{",
"opts",
".",
"meta",
"[",
"id",
"]",
"[",
"k",
"]",
"=",
"v",
".",
"name",
";",
"if",
"(",
"v",
".",
"submodules",
")",
"{",
"v",
".",
"submodules",
".",
"forEach",
"(",
"function",
"(",
"s",
")",
"{",
"opts",
".",
"meta",
"[",
"id",
"]",
".",
"push",
"(",
"s",
".",
"displayName",
")",
";",
"}",
")",
";",
"}",
"}",
")",
";",
"opts",
".",
"meta",
"[",
"id",
"]",
".",
"sort",
"(",
")",
";",
"}",
")",
";",
"var",
"apijs",
"=",
"'YUI.add(\"yuidoc-meta\", function(Y) {\\n'",
"+",
"' Y.YUIDoc = { meta: '",
"+",
"JSON",
".",
"stringify",
"(",
"opts",
".",
"meta",
",",
"null",
",",
"4",
")",
"+",
"' };\\n'",
"+",
"'});'",
";",
"cb",
"(",
"apijs",
")",
";",
"}"
] | Render the API meta and return the Javascript
@method renderAPIMeta
@param {Callback} cb The callback
@async | [
"Render",
"the",
"API",
"meta",
"and",
"return",
"the",
"Javascript"
] | 5678f99ce876a62b2b7f7ad686d0e5b2531def3a | https://github.com/CreateJS/TweenJS/blob/5678f99ce876a62b2b7f7ad686d0e5b2531def3a/build/updates/builder.js#L1569-L1594 |
|
6,326 | CreateJS/TweenJS | build/updates/builder.js | function (cb) {
var self = this;
var starttime = (new Date()).getTime();
Y.log('Compiling Templates', 'info', 'builder');
this.mixExternal(function () {
self.makeDirs(function () {
Y.log('Copying Assets', 'info', 'builder');
if (!Y.Files.isDirectory(path.join(self.options.outdir, 'assets'))) {
fs.mkdirSync(path.join(self.options.outdir, 'assets'), 0777);
}
Y.Files.copyAssets([
path.join(DEFAULT_THEME, 'assets'),
path.join(themeDir, 'assets')
],
path.join(self.options.outdir, 'assets'),
false,
function () {
var cstack = new Y.Parallel();
self.writeModules(cstack.add(function () {
self.writeClasses(cstack.add(function () {
if (!self.options.nocode) {
self.writeFiles(cstack.add(noop));
}
}));
}));
/*
self.writeModules(cstack.add(noop));
self.writeClasses(cstack.add(noop));
if (!self.options.nocode) {
self.writeFiles(cstack.add(noop));
}
*/
self.writeIndex(cstack.add(noop));
self.writeAPIMeta(cstack.add(noop));
cstack.done(function () {
var endtime = (new Date()).getTime();
var timer = ((endtime - starttime) / 1000) + ' seconds';
Y.log('Finished writing ' + self.files + ' files in ' + timer, 'info', 'builder');
if (cb) {
cb();
}
});
});
});
});
} | javascript | function (cb) {
var self = this;
var starttime = (new Date()).getTime();
Y.log('Compiling Templates', 'info', 'builder');
this.mixExternal(function () {
self.makeDirs(function () {
Y.log('Copying Assets', 'info', 'builder');
if (!Y.Files.isDirectory(path.join(self.options.outdir, 'assets'))) {
fs.mkdirSync(path.join(self.options.outdir, 'assets'), 0777);
}
Y.Files.copyAssets([
path.join(DEFAULT_THEME, 'assets'),
path.join(themeDir, 'assets')
],
path.join(self.options.outdir, 'assets'),
false,
function () {
var cstack = new Y.Parallel();
self.writeModules(cstack.add(function () {
self.writeClasses(cstack.add(function () {
if (!self.options.nocode) {
self.writeFiles(cstack.add(noop));
}
}));
}));
/*
self.writeModules(cstack.add(noop));
self.writeClasses(cstack.add(noop));
if (!self.options.nocode) {
self.writeFiles(cstack.add(noop));
}
*/
self.writeIndex(cstack.add(noop));
self.writeAPIMeta(cstack.add(noop));
cstack.done(function () {
var endtime = (new Date()).getTime();
var timer = ((endtime - starttime) / 1000) + ' seconds';
Y.log('Finished writing ' + self.files + ' files in ' + timer, 'info', 'builder');
if (cb) {
cb();
}
});
});
});
});
} | [
"function",
"(",
"cb",
")",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"starttime",
"=",
"(",
"new",
"Date",
"(",
")",
")",
".",
"getTime",
"(",
")",
";",
"Y",
".",
"log",
"(",
"'Compiling Templates'",
",",
"'info'",
",",
"'builder'",
")",
";",
"this",
".",
"mixExternal",
"(",
"function",
"(",
")",
"{",
"self",
".",
"makeDirs",
"(",
"function",
"(",
")",
"{",
"Y",
".",
"log",
"(",
"'Copying Assets'",
",",
"'info'",
",",
"'builder'",
")",
";",
"if",
"(",
"!",
"Y",
".",
"Files",
".",
"isDirectory",
"(",
"path",
".",
"join",
"(",
"self",
".",
"options",
".",
"outdir",
",",
"'assets'",
")",
")",
")",
"{",
"fs",
".",
"mkdirSync",
"(",
"path",
".",
"join",
"(",
"self",
".",
"options",
".",
"outdir",
",",
"'assets'",
")",
",",
"0777",
")",
";",
"}",
"Y",
".",
"Files",
".",
"copyAssets",
"(",
"[",
"path",
".",
"join",
"(",
"DEFAULT_THEME",
",",
"'assets'",
")",
",",
"path",
".",
"join",
"(",
"themeDir",
",",
"'assets'",
")",
"]",
",",
"path",
".",
"join",
"(",
"self",
".",
"options",
".",
"outdir",
",",
"'assets'",
")",
",",
"false",
",",
"function",
"(",
")",
"{",
"var",
"cstack",
"=",
"new",
"Y",
".",
"Parallel",
"(",
")",
";",
"self",
".",
"writeModules",
"(",
"cstack",
".",
"add",
"(",
"function",
"(",
")",
"{",
"self",
".",
"writeClasses",
"(",
"cstack",
".",
"add",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"!",
"self",
".",
"options",
".",
"nocode",
")",
"{",
"self",
".",
"writeFiles",
"(",
"cstack",
".",
"add",
"(",
"noop",
")",
")",
";",
"}",
"}",
")",
")",
";",
"}",
")",
")",
";",
"/*\n self.writeModules(cstack.add(noop));\n self.writeClasses(cstack.add(noop));\n if (!self.options.nocode) {\n self.writeFiles(cstack.add(noop));\n }\n */",
"self",
".",
"writeIndex",
"(",
"cstack",
".",
"add",
"(",
"noop",
")",
")",
";",
"self",
".",
"writeAPIMeta",
"(",
"cstack",
".",
"add",
"(",
"noop",
")",
")",
";",
"cstack",
".",
"done",
"(",
"function",
"(",
")",
"{",
"var",
"endtime",
"=",
"(",
"new",
"Date",
"(",
")",
")",
".",
"getTime",
"(",
")",
";",
"var",
"timer",
"=",
"(",
"(",
"endtime",
"-",
"starttime",
")",
"/",
"1000",
")",
"+",
"' seconds'",
";",
"Y",
".",
"log",
"(",
"'Finished writing '",
"+",
"self",
".",
"files",
"+",
"' files in '",
"+",
"timer",
",",
"'info'",
",",
"'builder'",
")",
";",
"if",
"(",
"cb",
")",
"{",
"cb",
"(",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Compiles the templates from the meta-data provided by DocParser
@method compile
@param {Callback} cb The callback to execute after it's completed | [
"Compiles",
"the",
"templates",
"from",
"the",
"meta",
"-",
"data",
"provided",
"by",
"DocParser"
] | 5678f99ce876a62b2b7f7ad686d0e5b2531def3a | https://github.com/CreateJS/TweenJS/blob/5678f99ce876a62b2b7f7ad686d0e5b2531def3a/build/updates/builder.js#L1613-L1661 |
|
6,327 | CreateJS/TweenJS | src/tweenjs/plugins/CSSPlugin.js | parseMulti | function parseMulti(str, compare, arr) {
// TODO: add logic to deal with "0" values? Troublesome because the browser automatically appends a unit for some 0 values.
do {
// pull out the next value (ex. "20px", "12.4rad"):
var result = s.TRANSFORM_VALUE_RE.exec(str);
if (!result) { return arr; }
if (!arr) { arr = []; }
arr.push(+result[1], result[2]);
// check that the units match (ex. "px" vs "em"):
if (compare && (compare[arr.length-1] !== result[2])) { console.log("transform units don't match: ",arr[0], compare[arr.length-1], result[2]); compare=null; } // unit doesn't match
} while(true);
} | javascript | function parseMulti(str, compare, arr) {
// TODO: add logic to deal with "0" values? Troublesome because the browser automatically appends a unit for some 0 values.
do {
// pull out the next value (ex. "20px", "12.4rad"):
var result = s.TRANSFORM_VALUE_RE.exec(str);
if (!result) { return arr; }
if (!arr) { arr = []; }
arr.push(+result[1], result[2]);
// check that the units match (ex. "px" vs "em"):
if (compare && (compare[arr.length-1] !== result[2])) { console.log("transform units don't match: ",arr[0], compare[arr.length-1], result[2]); compare=null; } // unit doesn't match
} while(true);
} | [
"function",
"parseMulti",
"(",
"str",
",",
"compare",
",",
"arr",
")",
"{",
"// TODO: add logic to deal with \"0\" values? Troublesome because the browser automatically appends a unit for some 0 values.",
"do",
"{",
"// pull out the next value (ex. \"20px\", \"12.4rad\"):",
"var",
"result",
"=",
"s",
".",
"TRANSFORM_VALUE_RE",
".",
"exec",
"(",
"str",
")",
";",
"if",
"(",
"!",
"result",
")",
"{",
"return",
"arr",
";",
"}",
"if",
"(",
"!",
"arr",
")",
"{",
"arr",
"=",
"[",
"]",
";",
"}",
"arr",
".",
"push",
"(",
"+",
"result",
"[",
"1",
"]",
",",
"result",
"[",
"2",
"]",
")",
";",
"// check that the units match (ex. \"px\" vs \"em\"):",
"if",
"(",
"compare",
"&&",
"(",
"compare",
"[",
"arr",
".",
"length",
"-",
"1",
"]",
"!==",
"result",
"[",
"2",
"]",
")",
")",
"{",
"console",
".",
"log",
"(",
"\"transform units don't match: \"",
",",
"arr",
"[",
"0",
"]",
",",
"compare",
"[",
"arr",
".",
"length",
"-",
"1",
"]",
",",
"result",
"[",
"2",
"]",
")",
";",
"compare",
"=",
"null",
";",
"}",
"// unit doesn't match",
"}",
"while",
"(",
"true",
")",
";",
"}"
] | this was separated so that it can be used for other multi element styles in the future ex. transform-origin, border, etc. | [
"this",
"was",
"separated",
"so",
"that",
"it",
"can",
"be",
"used",
"for",
"other",
"multi",
"element",
"styles",
"in",
"the",
"future",
"ex",
".",
"transform",
"-",
"origin",
"border",
"etc",
"."
] | 5678f99ce876a62b2b7f7ad686d0e5b2531def3a | https://github.com/CreateJS/TweenJS/blob/5678f99ce876a62b2b7f7ad686d0e5b2531def3a/src/tweenjs/plugins/CSSPlugin.js#L267-L279 |
6,328 | CreateJS/TweenJS | lib/tweenjs-NEXT.js | TweenGroup | function TweenGroup(paused, timeScale) {
this._tweens = [];
this.paused = paused;
this.timeScale = timeScale;
this.__onComplete = this._onComplete.bind(this);
} | javascript | function TweenGroup(paused, timeScale) {
this._tweens = [];
this.paused = paused;
this.timeScale = timeScale;
this.__onComplete = this._onComplete.bind(this);
} | [
"function",
"TweenGroup",
"(",
"paused",
",",
"timeScale",
")",
"{",
"this",
".",
"_tweens",
"=",
"[",
"]",
";",
"this",
".",
"paused",
"=",
"paused",
";",
"this",
".",
"timeScale",
"=",
"timeScale",
";",
"this",
".",
"__onComplete",
"=",
"this",
".",
"_onComplete",
".",
"bind",
"(",
"this",
")",
";",
"}"
] | TweenGroup allows you to pause and time scale a collection of tweens or timelines. For example, this could be
used to stop all tweens associated with a view when leaving that view.
myView.tweens = new createjs.TweenGroup();
myView.tweens.get(spinner, {loop: -1}).to({rotation:360}, 500);
myView.tweens.get(image).to({alpha: 1}, 5000);
// ... make all tweens in this view run in slow motion:
myView.tweens.timeScale = 0.1;
// ... pause all this view's active tweens:
myView.tweens.paused = true; // stop all tweens.
You can add a group to another group to nest it.
viewTweenGroup.add(buttonTweenGroup);
Tweens are automatically removed from the group when they complete (ie. when the `complete` event fires).
@class TweenGroup
@param {Boolean} [paused] The initial paused property value for this group.
@param {Number} [timeScale] The intiial timeScale property value for this group.
@constructor | [
"TweenGroup",
"allows",
"you",
"to",
"pause",
"and",
"time",
"scale",
"a",
"collection",
"of",
"tweens",
"or",
"timelines",
".",
"For",
"example",
"this",
"could",
"be",
"used",
"to",
"stop",
"all",
"tweens",
"associated",
"with",
"a",
"view",
"when",
"leaving",
"that",
"view",
"."
] | 5678f99ce876a62b2b7f7ad686d0e5b2531def3a | https://github.com/CreateJS/TweenJS/blob/5678f99ce876a62b2b7f7ad686d0e5b2531def3a/lib/tweenjs-NEXT.js#L3872-L3877 |
6,329 | ampproject/amp-toolbox | packages/cors/lib/cors.js | extractOriginHeaders_ | function extractOriginHeaders_(headers) {
const result = {
isSameOrigin: false,
};
for (const key in headers) {
if (headers.hasOwnProperty(key)) {
const normalizedKey = key.toLowerCase();
// for same-origin requests where the Origin header is missing, AMP sets the amp-same-origin header
if (normalizedKey === 'amp-same-origin') {
result.isSameOrigin = true;
return result;
}
// use the origin header otherwise
if (normalizedKey === 'origin') {
result.origin = headers[key];
return result;
}
}
}
return null;
} | javascript | function extractOriginHeaders_(headers) {
const result = {
isSameOrigin: false,
};
for (const key in headers) {
if (headers.hasOwnProperty(key)) {
const normalizedKey = key.toLowerCase();
// for same-origin requests where the Origin header is missing, AMP sets the amp-same-origin header
if (normalizedKey === 'amp-same-origin') {
result.isSameOrigin = true;
return result;
}
// use the origin header otherwise
if (normalizedKey === 'origin') {
result.origin = headers[key];
return result;
}
}
}
return null;
} | [
"function",
"extractOriginHeaders_",
"(",
"headers",
")",
"{",
"const",
"result",
"=",
"{",
"isSameOrigin",
":",
"false",
",",
"}",
";",
"for",
"(",
"const",
"key",
"in",
"headers",
")",
"{",
"if",
"(",
"headers",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"const",
"normalizedKey",
"=",
"key",
".",
"toLowerCase",
"(",
")",
";",
"// for same-origin requests where the Origin header is missing, AMP sets the amp-same-origin header",
"if",
"(",
"normalizedKey",
"===",
"'amp-same-origin'",
")",
"{",
"result",
".",
"isSameOrigin",
"=",
"true",
";",
"return",
"result",
";",
"}",
"// use the origin header otherwise",
"if",
"(",
"normalizedKey",
"===",
"'origin'",
")",
"{",
"result",
".",
"origin",
"=",
"headers",
"[",
"key",
"]",
";",
"return",
"result",
";",
"}",
"}",
"}",
"return",
"null",
";",
"}"
] | Extracts the `AMP-Same-Origin` and `Origin` header values.
@param {Object} headers
@returns {Object} object containing the origin or isSameOrigin value
@private | [
"Extracts",
"the",
"AMP",
"-",
"Same",
"-",
"Origin",
"and",
"Origin",
"header",
"values",
"."
] | 9d6243974ac2023a466656aa9790e47e1219a624 | https://github.com/ampproject/amp-toolbox/blob/9d6243974ac2023a466656aa9790e47e1219a624/packages/cors/lib/cors.js#L100-L120 |
6,330 | ampproject/amp-toolbox | packages/cors/lib/cors.js | isValidOrigin | async function isValidOrigin(origin, sourceOrigin) {
// This will fetch the caches from https://cdn.ampproject.org/caches.json the first time it's
// called. Subsequent calls will receive a cached version.
const officialCacheList = await caches.list();
// Calculate the cache specific origin
const cacheSubdomain = `https://${await createCacheSubdomain(sourceOrigin)}.`;
// Check all caches listed on ampproject.org
for (const cache of officialCacheList) {
const cachedOrigin = cacheSubdomain + cache.cacheDomain;
if (origin === cachedOrigin) {
return true;
}
}
return false;
} | javascript | async function isValidOrigin(origin, sourceOrigin) {
// This will fetch the caches from https://cdn.ampproject.org/caches.json the first time it's
// called. Subsequent calls will receive a cached version.
const officialCacheList = await caches.list();
// Calculate the cache specific origin
const cacheSubdomain = `https://${await createCacheSubdomain(sourceOrigin)}.`;
// Check all caches listed on ampproject.org
for (const cache of officialCacheList) {
const cachedOrigin = cacheSubdomain + cache.cacheDomain;
if (origin === cachedOrigin) {
return true;
}
}
return false;
} | [
"async",
"function",
"isValidOrigin",
"(",
"origin",
",",
"sourceOrigin",
")",
"{",
"// This will fetch the caches from https://cdn.ampproject.org/caches.json the first time it's",
"// called. Subsequent calls will receive a cached version.",
"const",
"officialCacheList",
"=",
"await",
"caches",
".",
"list",
"(",
")",
";",
"// Calculate the cache specific origin",
"const",
"cacheSubdomain",
"=",
"`",
"${",
"await",
"createCacheSubdomain",
"(",
"sourceOrigin",
")",
"}",
"`",
";",
"// Check all caches listed on ampproject.org",
"for",
"(",
"const",
"cache",
"of",
"officialCacheList",
")",
"{",
"const",
"cachedOrigin",
"=",
"cacheSubdomain",
"+",
"cache",
".",
"cacheDomain",
";",
"if",
"(",
"origin",
"===",
"cachedOrigin",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Checks whether the given origin is a valid AMP cache.
@param {String} origin
@return {boolean} true if origin is valid
@private | [
"Checks",
"whether",
"the",
"given",
"origin",
"is",
"a",
"valid",
"AMP",
"cache",
"."
] | 9d6243974ac2023a466656aa9790e47e1219a624 | https://github.com/ampproject/amp-toolbox/blob/9d6243974ac2023a466656aa9790e47e1219a624/packages/cors/lib/cors.js#L129-L143 |
6,331 | ampproject/amp-toolbox | packages/optimizer/lib/HtmlDomHelper.js | findMetaViewport | function findMetaViewport(head) {
for (let node = head.firstChild; node !== null; node = node.nextSibling) {
if (node.tagName === 'meta' && node.attribs.name === 'viewport') {
return node;
}
}
return null;
} | javascript | function findMetaViewport(head) {
for (let node = head.firstChild; node !== null; node = node.nextSibling) {
if (node.tagName === 'meta' && node.attribs.name === 'viewport') {
return node;
}
}
return null;
} | [
"function",
"findMetaViewport",
"(",
"head",
")",
"{",
"for",
"(",
"let",
"node",
"=",
"head",
".",
"firstChild",
";",
"node",
"!==",
"null",
";",
"node",
"=",
"node",
".",
"nextSibling",
")",
"{",
"if",
"(",
"node",
".",
"tagName",
"===",
"'meta'",
"&&",
"node",
".",
"attribs",
".",
"name",
"===",
"'viewport'",
")",
"{",
"return",
"node",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Finds and returns the first 'meta charset' element in the head.
@param {Node} head the section to search for the meta charset node.
@returns {Node} the '<meta charset>' node or null. | [
"Finds",
"and",
"returns",
"the",
"first",
"meta",
"charset",
"element",
"in",
"the",
"head",
"."
] | 9d6243974ac2023a466656aa9790e47e1219a624 | https://github.com/ampproject/amp-toolbox/blob/9d6243974ac2023a466656aa9790e47e1219a624/packages/optimizer/lib/HtmlDomHelper.js#L25-L32 |
6,332 | ampproject/amp-toolbox | packages/core/lib/oneBehindFetch.js | oneBehindFetch | async function oneBehindFetch(input, init) {
let cachedResponse = cache.get(input);
if (!cachedResponse) {
cachedResponse = {
maxAge: Promise.resolve(MaxAge.zero()),
};
cache.set(input, cachedResponse);
}
const maxAge = await cachedResponse.maxAge;
if (!maxAge.isExpired()) {
// we have to clone the response to enable multiple reads
const response = await cachedResponse.responsePromise;
return response.clone();
}
const staleResponsePromise = cachedResponse.responsePromise;
const newResponsePromise = fetch(input, init);
cachedResponse = {
responsePromise: newResponsePromise,
maxAge: newResponsePromise.then(
(response) => MaxAge.parse(response.headers.get('cache-control'))
),
};
cache.set(input, cachedResponse);
const result = staleResponsePromise || newResponsePromise;
// we have to clone the response to enable multiple reads
const response = await result;
return response.clone();
} | javascript | async function oneBehindFetch(input, init) {
let cachedResponse = cache.get(input);
if (!cachedResponse) {
cachedResponse = {
maxAge: Promise.resolve(MaxAge.zero()),
};
cache.set(input, cachedResponse);
}
const maxAge = await cachedResponse.maxAge;
if (!maxAge.isExpired()) {
// we have to clone the response to enable multiple reads
const response = await cachedResponse.responsePromise;
return response.clone();
}
const staleResponsePromise = cachedResponse.responsePromise;
const newResponsePromise = fetch(input, init);
cachedResponse = {
responsePromise: newResponsePromise,
maxAge: newResponsePromise.then(
(response) => MaxAge.parse(response.headers.get('cache-control'))
),
};
cache.set(input, cachedResponse);
const result = staleResponsePromise || newResponsePromise;
// we have to clone the response to enable multiple reads
const response = await result;
return response.clone();
} | [
"async",
"function",
"oneBehindFetch",
"(",
"input",
",",
"init",
")",
"{",
"let",
"cachedResponse",
"=",
"cache",
".",
"get",
"(",
"input",
")",
";",
"if",
"(",
"!",
"cachedResponse",
")",
"{",
"cachedResponse",
"=",
"{",
"maxAge",
":",
"Promise",
".",
"resolve",
"(",
"MaxAge",
".",
"zero",
"(",
")",
")",
",",
"}",
";",
"cache",
".",
"set",
"(",
"input",
",",
"cachedResponse",
")",
";",
"}",
"const",
"maxAge",
"=",
"await",
"cachedResponse",
".",
"maxAge",
";",
"if",
"(",
"!",
"maxAge",
".",
"isExpired",
"(",
")",
")",
"{",
"// we have to clone the response to enable multiple reads",
"const",
"response",
"=",
"await",
"cachedResponse",
".",
"responsePromise",
";",
"return",
"response",
".",
"clone",
"(",
")",
";",
"}",
"const",
"staleResponsePromise",
"=",
"cachedResponse",
".",
"responsePromise",
";",
"const",
"newResponsePromise",
"=",
"fetch",
"(",
"input",
",",
"init",
")",
";",
"cachedResponse",
"=",
"{",
"responsePromise",
":",
"newResponsePromise",
",",
"maxAge",
":",
"newResponsePromise",
".",
"then",
"(",
"(",
"response",
")",
"=>",
"MaxAge",
".",
"parse",
"(",
"response",
".",
"headers",
".",
"get",
"(",
"'cache-control'",
")",
")",
")",
",",
"}",
";",
"cache",
".",
"set",
"(",
"input",
",",
"cachedResponse",
")",
";",
"const",
"result",
"=",
"staleResponsePromise",
"||",
"newResponsePromise",
";",
"// we have to clone the response to enable multiple reads",
"const",
"response",
"=",
"await",
"result",
";",
"return",
"response",
".",
"clone",
"(",
")",
";",
"}"
] | Implements fetch with a one-behind-caching strategy.
@param {String|Request} input - path or Request instance
@param {Object} init - fetch options
@return Promise<Response> | [
"Implements",
"fetch",
"with",
"a",
"one",
"-",
"behind",
"-",
"caching",
"strategy",
"."
] | 9d6243974ac2023a466656aa9790e47e1219a624 | https://github.com/ampproject/amp-toolbox/blob/9d6243974ac2023a466656aa9790e47e1219a624/packages/core/lib/oneBehindFetch.js#L30-L57 |
6,333 | ampproject/amp-toolbox | packages/optimizer/demo/simple/index.js | copyAndTransform | async function copyAndTransform(file, ampRuntimeVersion) {
const originalHtml = await readFile(file);
const ampFile = file.substring(1, file.length)
.replace('.html', '.amp.html');
const allTransformationsFile = file.substring(1, file.length)
.replace('.html', '.all.html');
const validTransformationsFile = file.substring(1, file.length)
.replace('.html', '.valid.html');
// Transform into valid optimized AMP
ampOptimizer.setConfig({
validAmp: true,
verbose: true,
});
const validOptimizedHtml = await ampOptimizer.transformHtml(originalHtml);
// Run all optimizations including versioned AMP runtime URLs
ampOptimizer.setConfig({
validAmp: false,
verbose: true,
});
// The transformer needs the path to the original AMP document
// to correctly setup AMP to canonical linking
const optimizedHtml = await ampOptimizer.transformHtml(originalHtml, {
ampUrl: ampFile,
ampRuntimeVersion: ampRuntimeVersion,
});
writeFile(allTransformationsFile, optimizedHtml);
writeFile(validTransformationsFile, validOptimizedHtml);
// We change the path of the original AMP file to match the new
// amphtml link and make the canonical link point to the transformed version.
writeFile(ampFile, originalHtml);
} | javascript | async function copyAndTransform(file, ampRuntimeVersion) {
const originalHtml = await readFile(file);
const ampFile = file.substring(1, file.length)
.replace('.html', '.amp.html');
const allTransformationsFile = file.substring(1, file.length)
.replace('.html', '.all.html');
const validTransformationsFile = file.substring(1, file.length)
.replace('.html', '.valid.html');
// Transform into valid optimized AMP
ampOptimizer.setConfig({
validAmp: true,
verbose: true,
});
const validOptimizedHtml = await ampOptimizer.transformHtml(originalHtml);
// Run all optimizations including versioned AMP runtime URLs
ampOptimizer.setConfig({
validAmp: false,
verbose: true,
});
// The transformer needs the path to the original AMP document
// to correctly setup AMP to canonical linking
const optimizedHtml = await ampOptimizer.transformHtml(originalHtml, {
ampUrl: ampFile,
ampRuntimeVersion: ampRuntimeVersion,
});
writeFile(allTransformationsFile, optimizedHtml);
writeFile(validTransformationsFile, validOptimizedHtml);
// We change the path of the original AMP file to match the new
// amphtml link and make the canonical link point to the transformed version.
writeFile(ampFile, originalHtml);
} | [
"async",
"function",
"copyAndTransform",
"(",
"file",
",",
"ampRuntimeVersion",
")",
"{",
"const",
"originalHtml",
"=",
"await",
"readFile",
"(",
"file",
")",
";",
"const",
"ampFile",
"=",
"file",
".",
"substring",
"(",
"1",
",",
"file",
".",
"length",
")",
".",
"replace",
"(",
"'.html'",
",",
"'.amp.html'",
")",
";",
"const",
"allTransformationsFile",
"=",
"file",
".",
"substring",
"(",
"1",
",",
"file",
".",
"length",
")",
".",
"replace",
"(",
"'.html'",
",",
"'.all.html'",
")",
";",
"const",
"validTransformationsFile",
"=",
"file",
".",
"substring",
"(",
"1",
",",
"file",
".",
"length",
")",
".",
"replace",
"(",
"'.html'",
",",
"'.valid.html'",
")",
";",
"// Transform into valid optimized AMP",
"ampOptimizer",
".",
"setConfig",
"(",
"{",
"validAmp",
":",
"true",
",",
"verbose",
":",
"true",
",",
"}",
")",
";",
"const",
"validOptimizedHtml",
"=",
"await",
"ampOptimizer",
".",
"transformHtml",
"(",
"originalHtml",
")",
";",
"// Run all optimizations including versioned AMP runtime URLs",
"ampOptimizer",
".",
"setConfig",
"(",
"{",
"validAmp",
":",
"false",
",",
"verbose",
":",
"true",
",",
"}",
")",
";",
"// The transformer needs the path to the original AMP document",
"// to correctly setup AMP to canonical linking",
"const",
"optimizedHtml",
"=",
"await",
"ampOptimizer",
".",
"transformHtml",
"(",
"originalHtml",
",",
"{",
"ampUrl",
":",
"ampFile",
",",
"ampRuntimeVersion",
":",
"ampRuntimeVersion",
",",
"}",
")",
";",
"writeFile",
"(",
"allTransformationsFile",
",",
"optimizedHtml",
")",
";",
"writeFile",
"(",
"validTransformationsFile",
",",
"validOptimizedHtml",
")",
";",
"// We change the path of the original AMP file to match the new",
"// amphtml link and make the canonical link point to the transformed version.",
"writeFile",
"(",
"ampFile",
",",
"originalHtml",
")",
";",
"}"
] | Copy original and transformed AMP file into the dist dir. | [
"Copy",
"original",
"and",
"transformed",
"AMP",
"file",
"into",
"the",
"dist",
"dir",
"."
] | 9d6243974ac2023a466656aa9790e47e1219a624 | https://github.com/ampproject/amp-toolbox/blob/9d6243974ac2023a466656aa9790e47e1219a624/packages/optimizer/demo/simple/index.js#L42-L74 |
6,334 | ampproject/amp-toolbox | packages/optimizer/demo/simple/index.js | collectInputFiles | function collectInputFiles(pattern) {
return new Promise((resolve, reject) => {
glob(pattern, {root: SRC_DIR, nomount: true}, (err, files) => {
if (err) {
return reject(err);
}
resolve(files);
});
});
} | javascript | function collectInputFiles(pattern) {
return new Promise((resolve, reject) => {
glob(pattern, {root: SRC_DIR, nomount: true}, (err, files) => {
if (err) {
return reject(err);
}
resolve(files);
});
});
} | [
"function",
"collectInputFiles",
"(",
"pattern",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"glob",
"(",
"pattern",
",",
"{",
"root",
":",
"SRC_DIR",
",",
"nomount",
":",
"true",
"}",
",",
"(",
"err",
",",
"files",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"reject",
"(",
"err",
")",
";",
"}",
"resolve",
"(",
"files",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Collect all files in the src dir. | [
"Collect",
"all",
"files",
"in",
"the",
"src",
"dir",
"."
] | 9d6243974ac2023a466656aa9790e47e1219a624 | https://github.com/ampproject/amp-toolbox/blob/9d6243974ac2023a466656aa9790e47e1219a624/packages/optimizer/demo/simple/index.js#L78-L87 |
6,335 | paulmillr/chokidar | lib/fsevents-handler.js | setFSEventsListener | function setFSEventsListener(path, realPath, listener, rawEmitter) {
let watchPath = sysPath.extname(path) ? sysPath.dirname(path) : path;
const parentPath = sysPath.dirname(watchPath);
let cont = FSEventsWatchers.get(watchPath);
// If we've accumulated a substantial number of paths that
// could have been consolidated by watching one directory
// above the current one, create a watcher on the parent
// path instead, so that we do consolidate going forward.
if (couldConsolidate(parentPath)) {
watchPath = parentPath;
}
const resolvedPath = sysPath.resolve(path);
const hasSymlink = resolvedPath !== realPath;
const filteredListener = (fullPath, flags, info) => {
if (hasSymlink) fullPath = fullPath.replace(realPath, resolvedPath);
if (
fullPath === resolvedPath ||
!fullPath.indexOf(resolvedPath + sysPath.sep)
) listener(fullPath, flags, info);
};
// check if there is already a watcher on a parent path
// modifies `watchPath` to the parent path when it finds a match
const watchedParent = () => {
for (const watchedPath of FSEventsWatchers.keys()) {
if (realPath.indexOf(sysPath.resolve(watchedPath) + sysPath.sep) === 0) {
watchPath = watchedPath;
cont = FSEventsWatchers.get(watchPath);
return true;
}
}
};
if (cont || watchedParent()) {
cont.listeners.add(filteredListener);
} else {
cont = {
listeners: new Set([filteredListener]),
rawEmitter: rawEmitter,
watcher: createFSEventsInstance(watchPath, (fullPath, flags) => {
const info = fsevents.getInfo(fullPath, flags);
cont.listeners.forEach(list => {
list(fullPath, flags, info);
});
cont.rawEmitter(info.event, fullPath, info);
})
};
FSEventsWatchers.set(watchPath, cont);
}
// removes this instance's listeners and closes the underlying fsevents
// instance if there are no more listeners left
return () => {
const wl = cont.listeners;
wl.delete(filteredListener);
if (!wl.size) {
FSEventsWatchers.delete(watchPath);
cont.watcher.stop();
cont.rawEmitter = cont.watcher = null;
Object.freeze(cont);
Object.freeze(cont.listeners);
}
};
} | javascript | function setFSEventsListener(path, realPath, listener, rawEmitter) {
let watchPath = sysPath.extname(path) ? sysPath.dirname(path) : path;
const parentPath = sysPath.dirname(watchPath);
let cont = FSEventsWatchers.get(watchPath);
// If we've accumulated a substantial number of paths that
// could have been consolidated by watching one directory
// above the current one, create a watcher on the parent
// path instead, so that we do consolidate going forward.
if (couldConsolidate(parentPath)) {
watchPath = parentPath;
}
const resolvedPath = sysPath.resolve(path);
const hasSymlink = resolvedPath !== realPath;
const filteredListener = (fullPath, flags, info) => {
if (hasSymlink) fullPath = fullPath.replace(realPath, resolvedPath);
if (
fullPath === resolvedPath ||
!fullPath.indexOf(resolvedPath + sysPath.sep)
) listener(fullPath, flags, info);
};
// check if there is already a watcher on a parent path
// modifies `watchPath` to the parent path when it finds a match
const watchedParent = () => {
for (const watchedPath of FSEventsWatchers.keys()) {
if (realPath.indexOf(sysPath.resolve(watchedPath) + sysPath.sep) === 0) {
watchPath = watchedPath;
cont = FSEventsWatchers.get(watchPath);
return true;
}
}
};
if (cont || watchedParent()) {
cont.listeners.add(filteredListener);
} else {
cont = {
listeners: new Set([filteredListener]),
rawEmitter: rawEmitter,
watcher: createFSEventsInstance(watchPath, (fullPath, flags) => {
const info = fsevents.getInfo(fullPath, flags);
cont.listeners.forEach(list => {
list(fullPath, flags, info);
});
cont.rawEmitter(info.event, fullPath, info);
})
};
FSEventsWatchers.set(watchPath, cont);
}
// removes this instance's listeners and closes the underlying fsevents
// instance if there are no more listeners left
return () => {
const wl = cont.listeners;
wl.delete(filteredListener);
if (!wl.size) {
FSEventsWatchers.delete(watchPath);
cont.watcher.stop();
cont.rawEmitter = cont.watcher = null;
Object.freeze(cont);
Object.freeze(cont.listeners);
}
};
} | [
"function",
"setFSEventsListener",
"(",
"path",
",",
"realPath",
",",
"listener",
",",
"rawEmitter",
")",
"{",
"let",
"watchPath",
"=",
"sysPath",
".",
"extname",
"(",
"path",
")",
"?",
"sysPath",
".",
"dirname",
"(",
"path",
")",
":",
"path",
";",
"const",
"parentPath",
"=",
"sysPath",
".",
"dirname",
"(",
"watchPath",
")",
";",
"let",
"cont",
"=",
"FSEventsWatchers",
".",
"get",
"(",
"watchPath",
")",
";",
"// If we've accumulated a substantial number of paths that",
"// could have been consolidated by watching one directory",
"// above the current one, create a watcher on the parent",
"// path instead, so that we do consolidate going forward.",
"if",
"(",
"couldConsolidate",
"(",
"parentPath",
")",
")",
"{",
"watchPath",
"=",
"parentPath",
";",
"}",
"const",
"resolvedPath",
"=",
"sysPath",
".",
"resolve",
"(",
"path",
")",
";",
"const",
"hasSymlink",
"=",
"resolvedPath",
"!==",
"realPath",
";",
"const",
"filteredListener",
"=",
"(",
"fullPath",
",",
"flags",
",",
"info",
")",
"=>",
"{",
"if",
"(",
"hasSymlink",
")",
"fullPath",
"=",
"fullPath",
".",
"replace",
"(",
"realPath",
",",
"resolvedPath",
")",
";",
"if",
"(",
"fullPath",
"===",
"resolvedPath",
"||",
"!",
"fullPath",
".",
"indexOf",
"(",
"resolvedPath",
"+",
"sysPath",
".",
"sep",
")",
")",
"listener",
"(",
"fullPath",
",",
"flags",
",",
"info",
")",
";",
"}",
";",
"// check if there is already a watcher on a parent path",
"// modifies `watchPath` to the parent path when it finds a match",
"const",
"watchedParent",
"=",
"(",
")",
"=>",
"{",
"for",
"(",
"const",
"watchedPath",
"of",
"FSEventsWatchers",
".",
"keys",
"(",
")",
")",
"{",
"if",
"(",
"realPath",
".",
"indexOf",
"(",
"sysPath",
".",
"resolve",
"(",
"watchedPath",
")",
"+",
"sysPath",
".",
"sep",
")",
"===",
"0",
")",
"{",
"watchPath",
"=",
"watchedPath",
";",
"cont",
"=",
"FSEventsWatchers",
".",
"get",
"(",
"watchPath",
")",
";",
"return",
"true",
";",
"}",
"}",
"}",
";",
"if",
"(",
"cont",
"||",
"watchedParent",
"(",
")",
")",
"{",
"cont",
".",
"listeners",
".",
"add",
"(",
"filteredListener",
")",
";",
"}",
"else",
"{",
"cont",
"=",
"{",
"listeners",
":",
"new",
"Set",
"(",
"[",
"filteredListener",
"]",
")",
",",
"rawEmitter",
":",
"rawEmitter",
",",
"watcher",
":",
"createFSEventsInstance",
"(",
"watchPath",
",",
"(",
"fullPath",
",",
"flags",
")",
"=>",
"{",
"const",
"info",
"=",
"fsevents",
".",
"getInfo",
"(",
"fullPath",
",",
"flags",
")",
";",
"cont",
".",
"listeners",
".",
"forEach",
"(",
"list",
"=>",
"{",
"list",
"(",
"fullPath",
",",
"flags",
",",
"info",
")",
";",
"}",
")",
";",
"cont",
".",
"rawEmitter",
"(",
"info",
".",
"event",
",",
"fullPath",
",",
"info",
")",
";",
"}",
")",
"}",
";",
"FSEventsWatchers",
".",
"set",
"(",
"watchPath",
",",
"cont",
")",
";",
"}",
"// removes this instance's listeners and closes the underlying fsevents",
"// instance if there are no more listeners left",
"return",
"(",
")",
"=>",
"{",
"const",
"wl",
"=",
"cont",
".",
"listeners",
";",
"wl",
".",
"delete",
"(",
"filteredListener",
")",
";",
"if",
"(",
"!",
"wl",
".",
"size",
")",
"{",
"FSEventsWatchers",
".",
"delete",
"(",
"watchPath",
")",
";",
"cont",
".",
"watcher",
".",
"stop",
"(",
")",
";",
"cont",
".",
"rawEmitter",
"=",
"cont",
".",
"watcher",
"=",
"null",
";",
"Object",
".",
"freeze",
"(",
"cont",
")",
";",
"Object",
".",
"freeze",
"(",
"cont",
".",
"listeners",
")",
";",
"}",
"}",
";",
"}"
] | Instantiates the fsevents interface or binds listeners to an existing one covering
the same file tree.
@param {Path} path - to be watched
@param {Path} realPath - real path for symlinks
@param {Function} listener - called when fsevents emits events
@param {Function} rawEmitter - passes data to listeners of the 'raw' event
@returns {Function} closer | [
"Instantiates",
"the",
"fsevents",
"interface",
"or",
"binds",
"listeners",
"to",
"an",
"existing",
"one",
"covering",
"the",
"same",
"file",
"tree",
"."
] | 3e576468febfb46ac47045293fdbcbd6885b0ff9 | https://github.com/paulmillr/chokidar/blob/3e576468febfb46ac47045293fdbcbd6885b0ff9/lib/fsevents-handler.js#L72-L140 |
6,336 | paulmillr/chokidar | lib/nodefs-handler.js | createFsWatchInstance | function createFsWatchInstance(path, options, listener, errHandler, emitRaw) {
const handleEvent = (rawEvent, evPath) => {
listener(path);
emitRaw(rawEvent, evPath, {watchedPath: path});
// emit based on events occurring for files from a directory's watcher in
// case the file's watcher misses it (and rely on throttling to de-dupe)
if (evPath && path !== evPath) {
fsWatchBroadcast(
sysPath.resolve(path, evPath), 'listeners', sysPath.join(path, evPath)
);
}
};
try {
return fs.watch(path, options, handleEvent);
} catch (error) {
errHandler(error);
}
} | javascript | function createFsWatchInstance(path, options, listener, errHandler, emitRaw) {
const handleEvent = (rawEvent, evPath) => {
listener(path);
emitRaw(rawEvent, evPath, {watchedPath: path});
// emit based on events occurring for files from a directory's watcher in
// case the file's watcher misses it (and rely on throttling to de-dupe)
if (evPath && path !== evPath) {
fsWatchBroadcast(
sysPath.resolve(path, evPath), 'listeners', sysPath.join(path, evPath)
);
}
};
try {
return fs.watch(path, options, handleEvent);
} catch (error) {
errHandler(error);
}
} | [
"function",
"createFsWatchInstance",
"(",
"path",
",",
"options",
",",
"listener",
",",
"errHandler",
",",
"emitRaw",
")",
"{",
"const",
"handleEvent",
"=",
"(",
"rawEvent",
",",
"evPath",
")",
"=>",
"{",
"listener",
"(",
"path",
")",
";",
"emitRaw",
"(",
"rawEvent",
",",
"evPath",
",",
"{",
"watchedPath",
":",
"path",
"}",
")",
";",
"// emit based on events occurring for files from a directory's watcher in",
"// case the file's watcher misses it (and rely on throttling to de-dupe)",
"if",
"(",
"evPath",
"&&",
"path",
"!==",
"evPath",
")",
"{",
"fsWatchBroadcast",
"(",
"sysPath",
".",
"resolve",
"(",
"path",
",",
"evPath",
")",
",",
"'listeners'",
",",
"sysPath",
".",
"join",
"(",
"path",
",",
"evPath",
")",
")",
";",
"}",
"}",
";",
"try",
"{",
"return",
"fs",
".",
"watch",
"(",
"path",
",",
"options",
",",
"handleEvent",
")",
";",
"}",
"catch",
"(",
"error",
")",
"{",
"errHandler",
"(",
"error",
")",
";",
"}",
"}"
] | Instantiates the fs_watch interface
@param {String} path to be watched
@param {Object} options to be passed to fs_watch
@param {Function} listener main event handler
@param {Function} errHandler emits info about errors
@param {Function} emitRaw emits raw event data
@returns {fs.FSWatcher} new fsevents instance | [
"Instantiates",
"the",
"fs_watch",
"interface"
] | 3e576468febfb46ac47045293fdbcbd6885b0ff9 | https://github.com/paulmillr/chokidar/blob/3e576468febfb46ac47045293fdbcbd6885b0ff9/lib/nodefs-handler.js#L40-L58 |
6,337 | sitespeedio/sitespeed.io | lib/plugins/text/textBuilder.js | abbr | function abbr(str) {
if (/total|overall/i.test(str)) return str.trim();
return str.replace(/\w+\s?/g, a => a[0]);
} | javascript | function abbr(str) {
if (/total|overall/i.test(str)) return str.trim();
return str.replace(/\w+\s?/g, a => a[0]);
} | [
"function",
"abbr",
"(",
"str",
")",
"{",
"if",
"(",
"/",
"total|overall",
"/",
"i",
".",
"test",
"(",
"str",
")",
")",
"return",
"str",
".",
"trim",
"(",
")",
";",
"return",
"str",
".",
"replace",
"(",
"/",
"\\w+\\s?",
"/",
"g",
",",
"a",
"=>",
"a",
"[",
"0",
"]",
")",
";",
"}"
] | foo bar -> fb | [
"foo",
"bar",
"-",
">",
"fb"
] | 8ebb751e35667e13db458bcac9a4bf6b412281b6 | https://github.com/sitespeedio/sitespeed.io/blob/8ebb751e35667e13db458bcac9a4bf6b412281b6/lib/plugins/text/textBuilder.js#L43-L46 |
6,338 | sitespeedio/sitespeed.io | lib/core/queueHandler.js | validateMessageFormat | function validateMessageFormat(message) {
function validateTypeStructure(message) {
const typeParts = message.type.split('.'),
baseType = typeParts[0],
typeDepth = typeParts.length;
if (typeDepth > 2)
throw new Error(
'Message type has too many dot separated sections: ' + message.type
);
const previousDepth = messageTypeDepths[baseType];
if (previousDepth && previousDepth !== typeDepth) {
throw new Error(
`All messages of type ${baseType} must have the same structure. ` +
`${
message.type
} has ${typeDepth} part(s), but earlier messages had ${previousDepth} part(s).`
);
}
messageTypeDepths[baseType] = typeDepth;
}
function validatePageSummary(message) {
const type = message.type;
if (!type.endsWith('.pageSummary')) return;
if (!message.url)
throw new Error(`Page summary message (${type}) didn't specify a url`);
if (!message.group)
throw new Error(`Page summary message (${type}) didn't specify a group.`);
}
function validateSummaryMessage(message) {
const type = message.type;
if (!type.endsWith('.summary')) return;
if (message.url)
throw new Error(
`Summary message (${type}) shouldn't be url specific, use .pageSummary instead.`
);
if (!message.group)
throw new Error(`Summary message (${type}) didn't specify a group.`);
const groups = groupsPerSummaryType[type] || [];
if (groups.includes(message.group)) {
throw new Error(
`Multiple summary messages of type ${type} and group ${message.group}`
);
}
groupsPerSummaryType[type] = groups.concat(message.group);
}
validateTypeStructure(message);
validatePageSummary(message);
validateSummaryMessage(message);
} | javascript | function validateMessageFormat(message) {
function validateTypeStructure(message) {
const typeParts = message.type.split('.'),
baseType = typeParts[0],
typeDepth = typeParts.length;
if (typeDepth > 2)
throw new Error(
'Message type has too many dot separated sections: ' + message.type
);
const previousDepth = messageTypeDepths[baseType];
if (previousDepth && previousDepth !== typeDepth) {
throw new Error(
`All messages of type ${baseType} must have the same structure. ` +
`${
message.type
} has ${typeDepth} part(s), but earlier messages had ${previousDepth} part(s).`
);
}
messageTypeDepths[baseType] = typeDepth;
}
function validatePageSummary(message) {
const type = message.type;
if (!type.endsWith('.pageSummary')) return;
if (!message.url)
throw new Error(`Page summary message (${type}) didn't specify a url`);
if (!message.group)
throw new Error(`Page summary message (${type}) didn't specify a group.`);
}
function validateSummaryMessage(message) {
const type = message.type;
if (!type.endsWith('.summary')) return;
if (message.url)
throw new Error(
`Summary message (${type}) shouldn't be url specific, use .pageSummary instead.`
);
if (!message.group)
throw new Error(`Summary message (${type}) didn't specify a group.`);
const groups = groupsPerSummaryType[type] || [];
if (groups.includes(message.group)) {
throw new Error(
`Multiple summary messages of type ${type} and group ${message.group}`
);
}
groupsPerSummaryType[type] = groups.concat(message.group);
}
validateTypeStructure(message);
validatePageSummary(message);
validateSummaryMessage(message);
} | [
"function",
"validateMessageFormat",
"(",
"message",
")",
"{",
"function",
"validateTypeStructure",
"(",
"message",
")",
"{",
"const",
"typeParts",
"=",
"message",
".",
"type",
".",
"split",
"(",
"'.'",
")",
",",
"baseType",
"=",
"typeParts",
"[",
"0",
"]",
",",
"typeDepth",
"=",
"typeParts",
".",
"length",
";",
"if",
"(",
"typeDepth",
">",
"2",
")",
"throw",
"new",
"Error",
"(",
"'Message type has too many dot separated sections: '",
"+",
"message",
".",
"type",
")",
";",
"const",
"previousDepth",
"=",
"messageTypeDepths",
"[",
"baseType",
"]",
";",
"if",
"(",
"previousDepth",
"&&",
"previousDepth",
"!==",
"typeDepth",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"baseType",
"}",
"`",
"+",
"`",
"${",
"message",
".",
"type",
"}",
"${",
"typeDepth",
"}",
"${",
"previousDepth",
"}",
"`",
")",
";",
"}",
"messageTypeDepths",
"[",
"baseType",
"]",
"=",
"typeDepth",
";",
"}",
"function",
"validatePageSummary",
"(",
"message",
")",
"{",
"const",
"type",
"=",
"message",
".",
"type",
";",
"if",
"(",
"!",
"type",
".",
"endsWith",
"(",
"'.pageSummary'",
")",
")",
"return",
";",
"if",
"(",
"!",
"message",
".",
"url",
")",
"throw",
"new",
"Error",
"(",
"`",
"${",
"type",
"}",
"`",
")",
";",
"if",
"(",
"!",
"message",
".",
"group",
")",
"throw",
"new",
"Error",
"(",
"`",
"${",
"type",
"}",
"`",
")",
";",
"}",
"function",
"validateSummaryMessage",
"(",
"message",
")",
"{",
"const",
"type",
"=",
"message",
".",
"type",
";",
"if",
"(",
"!",
"type",
".",
"endsWith",
"(",
"'.summary'",
")",
")",
"return",
";",
"if",
"(",
"message",
".",
"url",
")",
"throw",
"new",
"Error",
"(",
"`",
"${",
"type",
"}",
"`",
")",
";",
"if",
"(",
"!",
"message",
".",
"group",
")",
"throw",
"new",
"Error",
"(",
"`",
"${",
"type",
"}",
"`",
")",
";",
"const",
"groups",
"=",
"groupsPerSummaryType",
"[",
"type",
"]",
"||",
"[",
"]",
";",
"if",
"(",
"groups",
".",
"includes",
"(",
"message",
".",
"group",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"type",
"}",
"${",
"message",
".",
"group",
"}",
"`",
")",
";",
"}",
"groupsPerSummaryType",
"[",
"type",
"]",
"=",
"groups",
".",
"concat",
"(",
"message",
".",
"group",
")",
";",
"}",
"validateTypeStructure",
"(",
"message",
")",
";",
"validatePageSummary",
"(",
"message",
")",
";",
"validateSummaryMessage",
"(",
"message",
")",
";",
"}"
] | Check some message format best practices that applies to sitespeed.io.
Throws an error if message doesn't follow the rules.
@param message the message to check | [
"Check",
"some",
"message",
"format",
"best",
"practices",
"that",
"applies",
"to",
"sitespeed",
".",
"io",
".",
"Throws",
"an",
"error",
"if",
"message",
"doesn",
"t",
"follow",
"the",
"rules",
"."
] | 8ebb751e35667e13db458bcac9a4bf6b412281b6 | https://github.com/sitespeedio/sitespeed.io/blob/8ebb751e35667e13db458bcac9a4bf6b412281b6/lib/core/queueHandler.js#L27-L87 |
6,339 | zeit/ncc | examples/programmatic/scripts/build.js | write | function write(file, data) {
writeFileSync(file, data);
console.log(
`✓ ${relative(__dirname + "/../", file)} (${bytes(statSync(file).size)})`
);
} | javascript | function write(file, data) {
writeFileSync(file, data);
console.log(
`✓ ${relative(__dirname + "/../", file)} (${bytes(statSync(file).size)})`
);
} | [
"function",
"write",
"(",
"file",
",",
"data",
")",
"{",
"writeFileSync",
"(",
"file",
",",
"data",
")",
";",
"console",
".",
"log",
"(",
"`",
"re",
"lative(_",
"_",
"dirname +",
"\"",
"../\", ",
"f",
"le)}",
" ",
"(",
"by",
"tes(s",
"t",
"atSync(f",
"i",
"le).",
"s",
"i",
"ze)}",
")",
"`",
"",
")",
";",
"}"
] | write file to disk and print final size | [
"write",
"file",
"to",
"disk",
"and",
"print",
"final",
"size"
] | c86f124c11a64a65e4e96235260d98bb84ee8230 | https://github.com/zeit/ncc/blob/c86f124c11a64a65e4e96235260d98bb84ee8230/examples/programmatic/scripts/build.js#L26-L32 |
6,340 | zeit/ncc | examples/programmatic/scripts/build.js | build | async function build(file) {
const { code, map, assets } = await ncc(file, options);
if (Object.keys(assets).length)
console.error("New unexpected assets are being emitted for", file);
const name = basename(file, ".js");
await mkdirp(resolve(DIST_DIR, name));
write(resolve(DIST_DIR, name, "index.js"), code);
write(resolve(DIST_DIR, name, "index.map.js"), map);
} | javascript | async function build(file) {
const { code, map, assets } = await ncc(file, options);
if (Object.keys(assets).length)
console.error("New unexpected assets are being emitted for", file);
const name = basename(file, ".js");
await mkdirp(resolve(DIST_DIR, name));
write(resolve(DIST_DIR, name, "index.js"), code);
write(resolve(DIST_DIR, name, "index.map.js"), map);
} | [
"async",
"function",
"build",
"(",
"file",
")",
"{",
"const",
"{",
"code",
",",
"map",
",",
"assets",
"}",
"=",
"await",
"ncc",
"(",
"file",
",",
"options",
")",
";",
"if",
"(",
"Object",
".",
"keys",
"(",
"assets",
")",
".",
"length",
")",
"console",
".",
"error",
"(",
"\"New unexpected assets are being emitted for\"",
",",
"file",
")",
";",
"const",
"name",
"=",
"basename",
"(",
"file",
",",
"\".js\"",
")",
";",
"await",
"mkdirp",
"(",
"resolve",
"(",
"DIST_DIR",
",",
"name",
")",
")",
";",
"write",
"(",
"resolve",
"(",
"DIST_DIR",
",",
"name",
",",
"\"index.js\"",
")",
",",
"code",
")",
";",
"write",
"(",
"resolve",
"(",
"DIST_DIR",
",",
"name",
",",
"\"index.map.js\"",
")",
",",
"map",
")",
";",
"}"
] | build file with its dependencies using ncc | [
"build",
"file",
"with",
"its",
"dependencies",
"using",
"ncc"
] | c86f124c11a64a65e4e96235260d98bb84ee8230 | https://github.com/zeit/ncc/blob/c86f124c11a64a65e4e96235260d98bb84ee8230/examples/programmatic/scripts/build.js#L35-L45 |
6,341 | googleapis/nodejs-dialogflow | samples/quickstart.js | runSample | async function runSample(projectId = 'your-project-id') {
// A unique identifier for the given session
const sessionId = uuid.v4();
// Create a new session
const sessionClient = new dialogflow.SessionsClient();
const sessionPath = sessionClient.sessionPath(projectId, sessionId);
// The text query request.
const request = {
session: sessionPath,
queryInput: {
text: {
// The query to send to the dialogflow agent
text: 'hello',
// The language used by the client (en-US)
languageCode: 'en-US',
},
},
};
// Send request and log result
const responses = await sessionClient.detectIntent(request);
console.log('Detected intent');
const result = responses[0].queryResult;
console.log(` Query: ${result.queryText}`);
console.log(` Response: ${result.fulfillmentText}`);
if (result.intent) {
console.log(` Intent: ${result.intent.displayName}`);
} else {
console.log(` No intent matched.`);
}
} | javascript | async function runSample(projectId = 'your-project-id') {
// A unique identifier for the given session
const sessionId = uuid.v4();
// Create a new session
const sessionClient = new dialogflow.SessionsClient();
const sessionPath = sessionClient.sessionPath(projectId, sessionId);
// The text query request.
const request = {
session: sessionPath,
queryInput: {
text: {
// The query to send to the dialogflow agent
text: 'hello',
// The language used by the client (en-US)
languageCode: 'en-US',
},
},
};
// Send request and log result
const responses = await sessionClient.detectIntent(request);
console.log('Detected intent');
const result = responses[0].queryResult;
console.log(` Query: ${result.queryText}`);
console.log(` Response: ${result.fulfillmentText}`);
if (result.intent) {
console.log(` Intent: ${result.intent.displayName}`);
} else {
console.log(` No intent matched.`);
}
} | [
"async",
"function",
"runSample",
"(",
"projectId",
"=",
"'your-project-id'",
")",
"{",
"// A unique identifier for the given session",
"const",
"sessionId",
"=",
"uuid",
".",
"v4",
"(",
")",
";",
"// Create a new session",
"const",
"sessionClient",
"=",
"new",
"dialogflow",
".",
"SessionsClient",
"(",
")",
";",
"const",
"sessionPath",
"=",
"sessionClient",
".",
"sessionPath",
"(",
"projectId",
",",
"sessionId",
")",
";",
"// The text query request.",
"const",
"request",
"=",
"{",
"session",
":",
"sessionPath",
",",
"queryInput",
":",
"{",
"text",
":",
"{",
"// The query to send to the dialogflow agent",
"text",
":",
"'hello'",
",",
"// The language used by the client (en-US)",
"languageCode",
":",
"'en-US'",
",",
"}",
",",
"}",
",",
"}",
";",
"// Send request and log result",
"const",
"responses",
"=",
"await",
"sessionClient",
".",
"detectIntent",
"(",
"request",
")",
";",
"console",
".",
"log",
"(",
"'Detected intent'",
")",
";",
"const",
"result",
"=",
"responses",
"[",
"0",
"]",
".",
"queryResult",
";",
"console",
".",
"log",
"(",
"`",
"${",
"result",
".",
"queryText",
"}",
"`",
")",
";",
"console",
".",
"log",
"(",
"`",
"${",
"result",
".",
"fulfillmentText",
"}",
"`",
")",
";",
"if",
"(",
"result",
".",
"intent",
")",
"{",
"console",
".",
"log",
"(",
"`",
"${",
"result",
".",
"intent",
".",
"displayName",
"}",
"`",
")",
";",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"`",
"`",
")",
";",
"}",
"}"
] | Send a query to the dialogflow agent, and return the query result.
@param {string} projectId The project to be used | [
"Send",
"a",
"query",
"to",
"the",
"dialogflow",
"agent",
"and",
"return",
"the",
"query",
"result",
"."
] | 871070f4b1514448bbe442dee71b5bb8e6a77064 | https://github.com/googleapis/nodejs-dialogflow/blob/871070f4b1514448bbe442dee71b5bb8e6a77064/samples/quickstart.js#L27-L59 |
6,342 | bootstrap-tagsinput/bootstrap-tagsinput | dist/bootstrap-tagsinput.js | function() {
var self = this,
val = $.map(self.items(), function(item) {
return self.options.itemValue(item).toString();
});
self.$element.val(val, true);
if (self.options.triggerChange)
self.$element.trigger('change');
} | javascript | function() {
var self = this,
val = $.map(self.items(), function(item) {
return self.options.itemValue(item).toString();
});
self.$element.val(val, true);
if (self.options.triggerChange)
self.$element.trigger('change');
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
",",
"val",
"=",
"$",
".",
"map",
"(",
"self",
".",
"items",
"(",
")",
",",
"function",
"(",
"item",
")",
"{",
"return",
"self",
".",
"options",
".",
"itemValue",
"(",
"item",
")",
".",
"toString",
"(",
")",
";",
"}",
")",
";",
"self",
".",
"$element",
".",
"val",
"(",
"val",
",",
"true",
")",
";",
"if",
"(",
"self",
".",
"options",
".",
"triggerChange",
")",
"self",
".",
"$element",
".",
"trigger",
"(",
"'change'",
")",
";",
"}"
] | Assembly value by retrieving the value of each item, and set it on the
element. | [
"Assembly",
"value",
"by",
"retrieving",
"the",
"value",
"of",
"each",
"item",
"and",
"set",
"it",
"on",
"the",
"element",
"."
] | 41fe4aa2201c4af4cfc4293fa3fc8260ad60bf35 | https://github.com/bootstrap-tagsinput/bootstrap-tagsinput/blob/41fe4aa2201c4af4cfc4293fa3fc8260ad60bf35/dist/bootstrap-tagsinput.js#L272-L282 |
|
6,343 | bootstrap-tagsinput/bootstrap-tagsinput | dist/bootstrap-tagsinput.js | makeOptionItemFunction | function makeOptionItemFunction(options, key) {
if (typeof options[key] !== 'function') {
var propertyName = options[key];
options[key] = function(item) { return item[propertyName]; };
}
} | javascript | function makeOptionItemFunction(options, key) {
if (typeof options[key] !== 'function') {
var propertyName = options[key];
options[key] = function(item) { return item[propertyName]; };
}
} | [
"function",
"makeOptionItemFunction",
"(",
"options",
",",
"key",
")",
"{",
"if",
"(",
"typeof",
"options",
"[",
"key",
"]",
"!==",
"'function'",
")",
"{",
"var",
"propertyName",
"=",
"options",
"[",
"key",
"]",
";",
"options",
"[",
"key",
"]",
"=",
"function",
"(",
"item",
")",
"{",
"return",
"item",
"[",
"propertyName",
"]",
";",
"}",
";",
"}",
"}"
] | Most options support both a string or number as well as a function as
option value. This function makes sure that the option with the given
key in the given options is wrapped in a function | [
"Most",
"options",
"support",
"both",
"a",
"string",
"or",
"number",
"as",
"well",
"as",
"a",
"function",
"as",
"option",
"value",
".",
"This",
"function",
"makes",
"sure",
"that",
"the",
"option",
"with",
"the",
"given",
"key",
"in",
"the",
"given",
"options",
"is",
"wrapped",
"in",
"a",
"function"
] | 41fe4aa2201c4af4cfc4293fa3fc8260ad60bf35 | https://github.com/bootstrap-tagsinput/bootstrap-tagsinput/blob/41fe4aa2201c4af4cfc4293fa3fc8260ad60bf35/dist/bootstrap-tagsinput.js#L600-L605 |
6,344 | bootstrap-tagsinput/bootstrap-tagsinput | dist/bootstrap-tagsinput.js | keyCombinationInList | function keyCombinationInList(keyPressEvent, lookupList) {
var found = false;
$.each(lookupList, function (index, keyCombination) {
if (typeof (keyCombination) === 'number' && keyPressEvent.which === keyCombination) {
found = true;
return false;
}
if (keyPressEvent.which === keyCombination.which) {
var alt = !keyCombination.hasOwnProperty('altKey') || keyPressEvent.altKey === keyCombination.altKey,
shift = !keyCombination.hasOwnProperty('shiftKey') || keyPressEvent.shiftKey === keyCombination.shiftKey,
ctrl = !keyCombination.hasOwnProperty('ctrlKey') || keyPressEvent.ctrlKey === keyCombination.ctrlKey;
if (alt && shift && ctrl) {
found = true;
return false;
}
}
});
return found;
} | javascript | function keyCombinationInList(keyPressEvent, lookupList) {
var found = false;
$.each(lookupList, function (index, keyCombination) {
if (typeof (keyCombination) === 'number' && keyPressEvent.which === keyCombination) {
found = true;
return false;
}
if (keyPressEvent.which === keyCombination.which) {
var alt = !keyCombination.hasOwnProperty('altKey') || keyPressEvent.altKey === keyCombination.altKey,
shift = !keyCombination.hasOwnProperty('shiftKey') || keyPressEvent.shiftKey === keyCombination.shiftKey,
ctrl = !keyCombination.hasOwnProperty('ctrlKey') || keyPressEvent.ctrlKey === keyCombination.ctrlKey;
if (alt && shift && ctrl) {
found = true;
return false;
}
}
});
return found;
} | [
"function",
"keyCombinationInList",
"(",
"keyPressEvent",
",",
"lookupList",
")",
"{",
"var",
"found",
"=",
"false",
";",
"$",
".",
"each",
"(",
"lookupList",
",",
"function",
"(",
"index",
",",
"keyCombination",
")",
"{",
"if",
"(",
"typeof",
"(",
"keyCombination",
")",
"===",
"'number'",
"&&",
"keyPressEvent",
".",
"which",
"===",
"keyCombination",
")",
"{",
"found",
"=",
"true",
";",
"return",
"false",
";",
"}",
"if",
"(",
"keyPressEvent",
".",
"which",
"===",
"keyCombination",
".",
"which",
")",
"{",
"var",
"alt",
"=",
"!",
"keyCombination",
".",
"hasOwnProperty",
"(",
"'altKey'",
")",
"||",
"keyPressEvent",
".",
"altKey",
"===",
"keyCombination",
".",
"altKey",
",",
"shift",
"=",
"!",
"keyCombination",
".",
"hasOwnProperty",
"(",
"'shiftKey'",
")",
"||",
"keyPressEvent",
".",
"shiftKey",
"===",
"keyCombination",
".",
"shiftKey",
",",
"ctrl",
"=",
"!",
"keyCombination",
".",
"hasOwnProperty",
"(",
"'ctrlKey'",
")",
"||",
"keyPressEvent",
".",
"ctrlKey",
"===",
"keyCombination",
".",
"ctrlKey",
";",
"if",
"(",
"alt",
"&&",
"shift",
"&&",
"ctrl",
")",
"{",
"found",
"=",
"true",
";",
"return",
"false",
";",
"}",
"}",
"}",
")",
";",
"return",
"found",
";",
"}"
] | Returns boolean indicates whether user has pressed an expected key combination.
@param object keyPressEvent: JavaScript event object, refer
http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html
@param object lookupList: expected key combinations, as in:
[13, {which: 188, shiftKey: true}] | [
"Returns",
"boolean",
"indicates",
"whether",
"user",
"has",
"pressed",
"an",
"expected",
"key",
"combination",
"."
] | 41fe4aa2201c4af4cfc4293fa3fc8260ad60bf35 | https://github.com/bootstrap-tagsinput/bootstrap-tagsinput/blob/41fe4aa2201c4af4cfc4293fa3fc8260ad60bf35/dist/bootstrap-tagsinput.js#L648-L668 |
6,345 | maicki/why-did-you-update | lib/index.js | createClassComponent | function createClassComponent(ctor, displayName, opts) {
var cdu = createComponentDidUpdate(displayName, opts);
// the wrapper class extends the original class,
// and overwrites its `componentDidUpdate` method,
// to allow why-did-you-update to listen for updates.
// If the component had its own `componentDidUpdate`,
// we call it afterwards.`
var WDYUClassComponent = function (_ctor) {
_inherits(WDYUClassComponent, _ctor);
function WDYUClassComponent() {
_classCallCheck(this, WDYUClassComponent);
return _possibleConstructorReturn(this, _ctor.apply(this, arguments));
}
WDYUClassComponent.prototype.componentDidUpdate = function componentDidUpdate(prevProps, prevState, snapshot) {
cdu.call(this, prevProps, prevState);
if (typeof ctor.prototype.componentDidUpdate === 'function') {
ctor.prototype.componentDidUpdate.call(this, prevProps, prevState, snapshot);
}
};
return WDYUClassComponent;
}(ctor);
// our wrapper component needs an explicit display name
// based on the original constructor.
WDYUClassComponent.displayName = displayName;
return WDYUClassComponent;
} | javascript | function createClassComponent(ctor, displayName, opts) {
var cdu = createComponentDidUpdate(displayName, opts);
// the wrapper class extends the original class,
// and overwrites its `componentDidUpdate` method,
// to allow why-did-you-update to listen for updates.
// If the component had its own `componentDidUpdate`,
// we call it afterwards.`
var WDYUClassComponent = function (_ctor) {
_inherits(WDYUClassComponent, _ctor);
function WDYUClassComponent() {
_classCallCheck(this, WDYUClassComponent);
return _possibleConstructorReturn(this, _ctor.apply(this, arguments));
}
WDYUClassComponent.prototype.componentDidUpdate = function componentDidUpdate(prevProps, prevState, snapshot) {
cdu.call(this, prevProps, prevState);
if (typeof ctor.prototype.componentDidUpdate === 'function') {
ctor.prototype.componentDidUpdate.call(this, prevProps, prevState, snapshot);
}
};
return WDYUClassComponent;
}(ctor);
// our wrapper component needs an explicit display name
// based on the original constructor.
WDYUClassComponent.displayName = displayName;
return WDYUClassComponent;
} | [
"function",
"createClassComponent",
"(",
"ctor",
",",
"displayName",
",",
"opts",
")",
"{",
"var",
"cdu",
"=",
"createComponentDidUpdate",
"(",
"displayName",
",",
"opts",
")",
";",
"// the wrapper class extends the original class,",
"// and overwrites its `componentDidUpdate` method,",
"// to allow why-did-you-update to listen for updates.",
"// If the component had its own `componentDidUpdate`,",
"// we call it afterwards.`",
"var",
"WDYUClassComponent",
"=",
"function",
"(",
"_ctor",
")",
"{",
"_inherits",
"(",
"WDYUClassComponent",
",",
"_ctor",
")",
";",
"function",
"WDYUClassComponent",
"(",
")",
"{",
"_classCallCheck",
"(",
"this",
",",
"WDYUClassComponent",
")",
";",
"return",
"_possibleConstructorReturn",
"(",
"this",
",",
"_ctor",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
")",
";",
"}",
"WDYUClassComponent",
".",
"prototype",
".",
"componentDidUpdate",
"=",
"function",
"componentDidUpdate",
"(",
"prevProps",
",",
"prevState",
",",
"snapshot",
")",
"{",
"cdu",
".",
"call",
"(",
"this",
",",
"prevProps",
",",
"prevState",
")",
";",
"if",
"(",
"typeof",
"ctor",
".",
"prototype",
".",
"componentDidUpdate",
"===",
"'function'",
")",
"{",
"ctor",
".",
"prototype",
".",
"componentDidUpdate",
".",
"call",
"(",
"this",
",",
"prevProps",
",",
"prevState",
",",
"snapshot",
")",
";",
"}",
"}",
";",
"return",
"WDYUClassComponent",
";",
"}",
"(",
"ctor",
")",
";",
"// our wrapper component needs an explicit display name",
"// based on the original constructor.",
"WDYUClassComponent",
".",
"displayName",
"=",
"displayName",
";",
"return",
"WDYUClassComponent",
";",
"}"
] | Creates a wrapper for a React class component | [
"Creates",
"a",
"wrapper",
"for",
"a",
"React",
"class",
"component"
] | 8c8c25c87bc65f737b5ab12c07de69f1d237433c | https://github.com/maicki/why-did-you-update/blob/8c8c25c87bc65f737b5ab12c07de69f1d237433c/lib/index.js#L49-L79 |
6,346 | maicki/why-did-you-update | lib/index.js | createFunctionalComponent | function createFunctionalComponent(ctor, displayName, opts, ReactComponent) {
var cdu = createComponentDidUpdate(displayName, opts);
// We call the original function in the render() method,
// and implement `componentDidUpdate` for `why-did-you-update`
var WDYUFunctionalComponent = function (_ReactComponent) {
_inherits(WDYUFunctionalComponent, _ReactComponent);
function WDYUFunctionalComponent() {
_classCallCheck(this, WDYUFunctionalComponent);
return _possibleConstructorReturn(this, _ReactComponent.apply(this, arguments));
}
WDYUFunctionalComponent.prototype.render = function render() {
return ctor(this.props, this.context);
};
WDYUFunctionalComponent.prototype.componentDidUpdate = function componentDidUpdate(prevProps, prevState, snapshot) {
cdu.call(this, prevProps, prevState, snapshot);
};
return WDYUFunctionalComponent;
}(ReactComponent);
// copy all statics from the functional component to the class
// to support proptypes and context apis
Object.assign(WDYUFunctionalComponent, ctor, {
// our wrapper component needs an explicit display name
// based on the original constructor.
displayName: displayName
});
return WDYUFunctionalComponent;
} | javascript | function createFunctionalComponent(ctor, displayName, opts, ReactComponent) {
var cdu = createComponentDidUpdate(displayName, opts);
// We call the original function in the render() method,
// and implement `componentDidUpdate` for `why-did-you-update`
var WDYUFunctionalComponent = function (_ReactComponent) {
_inherits(WDYUFunctionalComponent, _ReactComponent);
function WDYUFunctionalComponent() {
_classCallCheck(this, WDYUFunctionalComponent);
return _possibleConstructorReturn(this, _ReactComponent.apply(this, arguments));
}
WDYUFunctionalComponent.prototype.render = function render() {
return ctor(this.props, this.context);
};
WDYUFunctionalComponent.prototype.componentDidUpdate = function componentDidUpdate(prevProps, prevState, snapshot) {
cdu.call(this, prevProps, prevState, snapshot);
};
return WDYUFunctionalComponent;
}(ReactComponent);
// copy all statics from the functional component to the class
// to support proptypes and context apis
Object.assign(WDYUFunctionalComponent, ctor, {
// our wrapper component needs an explicit display name
// based on the original constructor.
displayName: displayName
});
return WDYUFunctionalComponent;
} | [
"function",
"createFunctionalComponent",
"(",
"ctor",
",",
"displayName",
",",
"opts",
",",
"ReactComponent",
")",
"{",
"var",
"cdu",
"=",
"createComponentDidUpdate",
"(",
"displayName",
",",
"opts",
")",
";",
"// We call the original function in the render() method,",
"// and implement `componentDidUpdate` for `why-did-you-update`",
"var",
"WDYUFunctionalComponent",
"=",
"function",
"(",
"_ReactComponent",
")",
"{",
"_inherits",
"(",
"WDYUFunctionalComponent",
",",
"_ReactComponent",
")",
";",
"function",
"WDYUFunctionalComponent",
"(",
")",
"{",
"_classCallCheck",
"(",
"this",
",",
"WDYUFunctionalComponent",
")",
";",
"return",
"_possibleConstructorReturn",
"(",
"this",
",",
"_ReactComponent",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
")",
";",
"}",
"WDYUFunctionalComponent",
".",
"prototype",
".",
"render",
"=",
"function",
"render",
"(",
")",
"{",
"return",
"ctor",
"(",
"this",
".",
"props",
",",
"this",
".",
"context",
")",
";",
"}",
";",
"WDYUFunctionalComponent",
".",
"prototype",
".",
"componentDidUpdate",
"=",
"function",
"componentDidUpdate",
"(",
"prevProps",
",",
"prevState",
",",
"snapshot",
")",
"{",
"cdu",
".",
"call",
"(",
"this",
",",
"prevProps",
",",
"prevState",
",",
"snapshot",
")",
";",
"}",
";",
"return",
"WDYUFunctionalComponent",
";",
"}",
"(",
"ReactComponent",
")",
";",
"// copy all statics from the functional component to the class",
"// to support proptypes and context apis",
"Object",
".",
"assign",
"(",
"WDYUFunctionalComponent",
",",
"ctor",
",",
"{",
"// our wrapper component needs an explicit display name",
"// based on the original constructor.",
"displayName",
":",
"displayName",
"}",
")",
";",
"return",
"WDYUFunctionalComponent",
";",
"}"
] | Creates a wrapper for a React functional component | [
"Creates",
"a",
"wrapper",
"for",
"a",
"React",
"functional",
"component"
] | 8c8c25c87bc65f737b5ab12c07de69f1d237433c | https://github.com/maicki/why-did-you-update/blob/8c8c25c87bc65f737b5ab12c07de69f1d237433c/lib/index.js#L82-L116 |
6,347 | wux-weapp/wux-weapp | dist/helpers/relationsBehavior.js | bindFunc | function bindFunc(obj, method, observer) {
const oldFn = obj[method]
obj[method] = function(target) {
if (observer) {
observer.call(this, target, {
[method]: true,
})
}
if (oldFn) {
oldFn.call(this, target)
}
}
} | javascript | function bindFunc(obj, method, observer) {
const oldFn = obj[method]
obj[method] = function(target) {
if (observer) {
observer.call(this, target, {
[method]: true,
})
}
if (oldFn) {
oldFn.call(this, target)
}
}
} | [
"function",
"bindFunc",
"(",
"obj",
",",
"method",
",",
"observer",
")",
"{",
"const",
"oldFn",
"=",
"obj",
"[",
"method",
"]",
"obj",
"[",
"method",
"]",
"=",
"function",
"(",
"target",
")",
"{",
"if",
"(",
"observer",
")",
"{",
"observer",
".",
"call",
"(",
"this",
",",
"target",
",",
"{",
"[",
"method",
"]",
":",
"true",
",",
"}",
")",
"}",
"if",
"(",
"oldFn",
")",
"{",
"oldFn",
".",
"call",
"(",
"this",
",",
"target",
")",
"}",
"}",
"}"
] | bind func to obj | [
"bind",
"func",
"to",
"obj"
] | 7e472f5e7080bde7e6da2411dded3bf94fcd02f0 | https://github.com/wux-weapp/wux-weapp/blob/7e472f5e7080bde7e6da2411dded3bf94fcd02f0/dist/helpers/relationsBehavior.js#L7-L19 |
6,348 | snapappointments/bootstrap-select | docs/custom_theme/js/base.js | search | function search (query) {
if (!allowSearch) {
console.error('Assets for search still loading');
return;
}
var resultDocuments = [];
var results = index.search(query + '~2'); // fuzzy
for (var i=0; i < results.length; i++){
var result = results[i];
doc = documents[result.ref];
doc.summary = doc.text.substring(0, 200);
resultDocuments.push(doc);
}
return resultDocuments;
} | javascript | function search (query) {
if (!allowSearch) {
console.error('Assets for search still loading');
return;
}
var resultDocuments = [];
var results = index.search(query + '~2'); // fuzzy
for (var i=0; i < results.length; i++){
var result = results[i];
doc = documents[result.ref];
doc.summary = doc.text.substring(0, 200);
resultDocuments.push(doc);
}
return resultDocuments;
} | [
"function",
"search",
"(",
"query",
")",
"{",
"if",
"(",
"!",
"allowSearch",
")",
"{",
"console",
".",
"error",
"(",
"'Assets for search still loading'",
")",
";",
"return",
";",
"}",
"var",
"resultDocuments",
"=",
"[",
"]",
";",
"var",
"results",
"=",
"index",
".",
"search",
"(",
"query",
"+",
"'~2'",
")",
";",
"// fuzzy",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"results",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"result",
"=",
"results",
"[",
"i",
"]",
";",
"doc",
"=",
"documents",
"[",
"result",
".",
"ref",
"]",
";",
"doc",
".",
"summary",
"=",
"doc",
".",
"text",
".",
"substring",
"(",
"0",
",",
"200",
")",
";",
"resultDocuments",
".",
"push",
"(",
"doc",
")",
";",
"}",
"return",
"resultDocuments",
";",
"}"
] | enable fuzzy searching | [
"enable",
"fuzzy",
"searching"
] | b6135994a96269c7920169ae18d42852c62a6c1b | https://github.com/snapappointments/bootstrap-select/blob/b6135994a96269c7920169ae18d42852c62a6c1b/docs/custom_theme/js/base.js#L81-L96 |
6,349 | snapappointments/bootstrap-select | js/bootstrap-select.js | isEqual | function isEqual (array1, array2) {
return array1.length === array2.length && array1.every(function (element, index) {
return element === array2[index];
});
} | javascript | function isEqual (array1, array2) {
return array1.length === array2.length && array1.every(function (element, index) {
return element === array2[index];
});
} | [
"function",
"isEqual",
"(",
"array1",
",",
"array2",
")",
"{",
"return",
"array1",
".",
"length",
"===",
"array2",
".",
"length",
"&&",
"array1",
".",
"every",
"(",
"function",
"(",
"element",
",",
"index",
")",
"{",
"return",
"element",
"===",
"array2",
"[",
"index",
"]",
";",
"}",
")",
";",
"}"
] | shallow array comparison | [
"shallow",
"array",
"comparison"
] | b6135994a96269c7920169ae18d42852c62a6c1b | https://github.com/snapappointments/bootstrap-select/blob/b6135994a96269c7920169ae18d42852c62a6c1b/js/bootstrap-select.js#L215-L219 |
6,350 | ExpressGateway/express-gateway | lib/policies/proxy/proxy.js | readCertificateDataFromFile | function readCertificateDataFromFile ({ keyFile, certFile, caFile }) {
let key, cert, ca;
if (keyFile) {
key = fs.readFileSync(keyFile);
}
if (certFile) {
cert = fs.readFileSync(certFile);
}
if (caFile) {
ca = fs.readFileSync(caFile);
}
return { key, cert, ca };
} | javascript | function readCertificateDataFromFile ({ keyFile, certFile, caFile }) {
let key, cert, ca;
if (keyFile) {
key = fs.readFileSync(keyFile);
}
if (certFile) {
cert = fs.readFileSync(certFile);
}
if (caFile) {
ca = fs.readFileSync(caFile);
}
return { key, cert, ca };
} | [
"function",
"readCertificateDataFromFile",
"(",
"{",
"keyFile",
",",
"certFile",
",",
"caFile",
"}",
")",
"{",
"let",
"key",
",",
"cert",
",",
"ca",
";",
"if",
"(",
"keyFile",
")",
"{",
"key",
"=",
"fs",
".",
"readFileSync",
"(",
"keyFile",
")",
";",
"}",
"if",
"(",
"certFile",
")",
"{",
"cert",
"=",
"fs",
".",
"readFileSync",
"(",
"certFile",
")",
";",
"}",
"if",
"(",
"caFile",
")",
"{",
"ca",
"=",
"fs",
".",
"readFileSync",
"(",
"caFile",
")",
";",
"}",
"return",
"{",
"key",
",",
"cert",
",",
"ca",
"}",
";",
"}"
] | Parse endpoint URL if single URL is provided. Extend proxy options by allowing and parsing keyFile, certFile and caFile. | [
"Parse",
"endpoint",
"URL",
"if",
"single",
"URL",
"is",
"provided",
".",
"Extend",
"proxy",
"options",
"by",
"allowing",
"and",
"parsing",
"keyFile",
"certFile",
"and",
"caFile",
"."
] | fc77679e66278a117389a94a1cdb01122603d59b | https://github.com/ExpressGateway/express-gateway/blob/fc77679e66278a117389a94a1cdb01122603d59b/lib/policies/proxy/proxy.js#L104-L120 |
6,351 | finos/perspective | packages/perspective-viewer-highcharts/src/js/highcharts/externals.js | walk | function walk(arr, key, fn) {
var l = arr.length,
children;
while (l--) {
children = arr[l][key];
if (children) {
walk(children, key, fn);
}
fn(arr[l]);
}
} | javascript | function walk(arr, key, fn) {
var l = arr.length,
children;
while (l--) {
children = arr[l][key];
if (children) {
walk(children, key, fn);
}
fn(arr[l]);
}
} | [
"function",
"walk",
"(",
"arr",
",",
"key",
",",
"fn",
")",
"{",
"var",
"l",
"=",
"arr",
".",
"length",
",",
"children",
";",
"while",
"(",
"l",
"--",
")",
"{",
"children",
"=",
"arr",
"[",
"l",
"]",
"[",
"key",
"]",
";",
"if",
"(",
"children",
")",
"{",
"walk",
"(",
"children",
",",
"key",
",",
"fn",
")",
";",
"}",
"fn",
"(",
"arr",
"[",
"l",
"]",
")",
";",
"}",
"}"
] | Pushes part of grid to path | [
"Pushes",
"part",
"of",
"grid",
"to",
"path"
] | 6adfed1360e2d20e673930785e3bc4c19ba6d857 | https://github.com/finos/perspective/blob/6adfed1360e2d20e673930785e3bc4c19ba6d857/packages/perspective-viewer-highcharts/src/js/highcharts/externals.js#L138-L150 |
6,352 | finos/perspective | packages/perspective/bench/js/browser_runtime.js | run_table_cases | async function* run_table_cases(worker, data, test) {
console.log(`Benchmarking \`${test}\``);
try {
for (let x = 0; x < ITERATIONS + TOSS_ITERATIONS; x++) {
const start = performance.now();
const table = worker.table(data.slice ? data.slice() : data);
await table.size();
if (x >= TOSS_ITERATIONS) {
yield {
test,
time: performance.now() - start,
method: test,
row_pivots: "n/a",
column_pivots: "n/a",
aggregate: "n/a"
};
}
await table.delete();
}
} catch (e) {
console.error(`Benchmark ${test} failed`, e);
}
} | javascript | async function* run_table_cases(worker, data, test) {
console.log(`Benchmarking \`${test}\``);
try {
for (let x = 0; x < ITERATIONS + TOSS_ITERATIONS; x++) {
const start = performance.now();
const table = worker.table(data.slice ? data.slice() : data);
await table.size();
if (x >= TOSS_ITERATIONS) {
yield {
test,
time: performance.now() - start,
method: test,
row_pivots: "n/a",
column_pivots: "n/a",
aggregate: "n/a"
};
}
await table.delete();
}
} catch (e) {
console.error(`Benchmark ${test} failed`, e);
}
} | [
"async",
"function",
"*",
"run_table_cases",
"(",
"worker",
",",
"data",
",",
"test",
")",
"{",
"console",
".",
"log",
"(",
"`",
"\\`",
"${",
"test",
"}",
"\\`",
"`",
")",
";",
"try",
"{",
"for",
"(",
"let",
"x",
"=",
"0",
";",
"x",
"<",
"ITERATIONS",
"+",
"TOSS_ITERATIONS",
";",
"x",
"++",
")",
"{",
"const",
"start",
"=",
"performance",
".",
"now",
"(",
")",
";",
"const",
"table",
"=",
"worker",
".",
"table",
"(",
"data",
".",
"slice",
"?",
"data",
".",
"slice",
"(",
")",
":",
"data",
")",
";",
"await",
"table",
".",
"size",
"(",
")",
";",
"if",
"(",
"x",
">=",
"TOSS_ITERATIONS",
")",
"{",
"yield",
"{",
"test",
",",
"time",
":",
"performance",
".",
"now",
"(",
")",
"-",
"start",
",",
"method",
":",
"test",
",",
"row_pivots",
":",
"\"n/a\"",
",",
"column_pivots",
":",
"\"n/a\"",
",",
"aggregate",
":",
"\"n/a\"",
"}",
";",
"}",
"await",
"table",
".",
"delete",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"e",
")",
"{",
"console",
".",
"error",
"(",
"`",
"${",
"test",
"}",
"`",
",",
"e",
")",
";",
"}",
"}"
] | Define benchmark cases | [
"Define",
"benchmark",
"cases"
] | 6adfed1360e2d20e673930785e3bc4c19ba6d857 | https://github.com/finos/perspective/blob/6adfed1360e2d20e673930785e3bc4c19ba6d857/packages/perspective/bench/js/browser_runtime.js#L59-L81 |
6,353 | finos/perspective | packages/perspective-cli/src/js/index.js | convert | async function convert(filename, options) {
let file;
if (filename) {
file = fs.readFileSync(filename).toString();
} else {
file = await read_stdin();
}
try {
file = JSON.parse(file);
} catch {}
let tbl = table(file);
let view = tbl.view();
let out;
options.format = options.format || "arrow";
if (options.format === "csv") {
out = await view.to_csv();
} else if (options.format === "columns") {
out = JSON.stringify(await view.to_columns());
} else if (options.format === "json") {
out = JSON.stringify(await view.to_json());
} else {
out = await view.to_arrow();
}
if (options.format === "arrow") {
if (options.output) {
fs.writeFileSync(options.output, new Buffer(out), "binary");
} else {
console.log(new Buffer(out).toString());
}
} else {
if (options.output) {
fs.writeFileSync(options.output, out);
} else {
console.log(out);
}
}
view.delete();
tbl.delete();
} | javascript | async function convert(filename, options) {
let file;
if (filename) {
file = fs.readFileSync(filename).toString();
} else {
file = await read_stdin();
}
try {
file = JSON.parse(file);
} catch {}
let tbl = table(file);
let view = tbl.view();
let out;
options.format = options.format || "arrow";
if (options.format === "csv") {
out = await view.to_csv();
} else if (options.format === "columns") {
out = JSON.stringify(await view.to_columns());
} else if (options.format === "json") {
out = JSON.stringify(await view.to_json());
} else {
out = await view.to_arrow();
}
if (options.format === "arrow") {
if (options.output) {
fs.writeFileSync(options.output, new Buffer(out), "binary");
} else {
console.log(new Buffer(out).toString());
}
} else {
if (options.output) {
fs.writeFileSync(options.output, out);
} else {
console.log(out);
}
}
view.delete();
tbl.delete();
} | [
"async",
"function",
"convert",
"(",
"filename",
",",
"options",
")",
"{",
"let",
"file",
";",
"if",
"(",
"filename",
")",
"{",
"file",
"=",
"fs",
".",
"readFileSync",
"(",
"filename",
")",
".",
"toString",
"(",
")",
";",
"}",
"else",
"{",
"file",
"=",
"await",
"read_stdin",
"(",
")",
";",
"}",
"try",
"{",
"file",
"=",
"JSON",
".",
"parse",
"(",
"file",
")",
";",
"}",
"catch",
"{",
"}",
"let",
"tbl",
"=",
"table",
"(",
"file",
")",
";",
"let",
"view",
"=",
"tbl",
".",
"view",
"(",
")",
";",
"let",
"out",
";",
"options",
".",
"format",
"=",
"options",
".",
"format",
"||",
"\"arrow\"",
";",
"if",
"(",
"options",
".",
"format",
"===",
"\"csv\"",
")",
"{",
"out",
"=",
"await",
"view",
".",
"to_csv",
"(",
")",
";",
"}",
"else",
"if",
"(",
"options",
".",
"format",
"===",
"\"columns\"",
")",
"{",
"out",
"=",
"JSON",
".",
"stringify",
"(",
"await",
"view",
".",
"to_columns",
"(",
")",
")",
";",
"}",
"else",
"if",
"(",
"options",
".",
"format",
"===",
"\"json\"",
")",
"{",
"out",
"=",
"JSON",
".",
"stringify",
"(",
"await",
"view",
".",
"to_json",
"(",
")",
")",
";",
"}",
"else",
"{",
"out",
"=",
"await",
"view",
".",
"to_arrow",
"(",
")",
";",
"}",
"if",
"(",
"options",
".",
"format",
"===",
"\"arrow\"",
")",
"{",
"if",
"(",
"options",
".",
"output",
")",
"{",
"fs",
".",
"writeFileSync",
"(",
"options",
".",
"output",
",",
"new",
"Buffer",
"(",
"out",
")",
",",
"\"binary\"",
")",
";",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"new",
"Buffer",
"(",
"out",
")",
".",
"toString",
"(",
")",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"options",
".",
"output",
")",
"{",
"fs",
".",
"writeFileSync",
"(",
"options",
".",
"output",
",",
"out",
")",
";",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"out",
")",
";",
"}",
"}",
"view",
".",
"delete",
"(",
")",
";",
"tbl",
".",
"delete",
"(",
")",
";",
"}"
] | Convert data from one format to another.
@param {*} filename
@param {*} options | [
"Convert",
"data",
"from",
"one",
"format",
"to",
"another",
"."
] | 6adfed1360e2d20e673930785e3bc4c19ba6d857 | https://github.com/finos/perspective/blob/6adfed1360e2d20e673930785e3bc4c19ba6d857/packages/perspective-cli/src/js/index.js#L22-L60 |
6,354 | finos/perspective | packages/perspective-cli/src/js/index.js | host | async function host(filename, options) {
let files = [path.join(__dirname, "html")];
if (options.assets) {
files = [options.assets, ...files];
}
const server = new WebSocketHost({assets: files, port: options.port});
let file;
if (filename) {
file = fs.readFileSync(filename).toString();
} else {
file = await read_stdin();
}
server.host_table("data_source_one", table(file));
if (options.open) {
open_browser(options.port);
}
} | javascript | async function host(filename, options) {
let files = [path.join(__dirname, "html")];
if (options.assets) {
files = [options.assets, ...files];
}
const server = new WebSocketHost({assets: files, port: options.port});
let file;
if (filename) {
file = fs.readFileSync(filename).toString();
} else {
file = await read_stdin();
}
server.host_table("data_source_one", table(file));
if (options.open) {
open_browser(options.port);
}
} | [
"async",
"function",
"host",
"(",
"filename",
",",
"options",
")",
"{",
"let",
"files",
"=",
"[",
"path",
".",
"join",
"(",
"__dirname",
",",
"\"html\"",
")",
"]",
";",
"if",
"(",
"options",
".",
"assets",
")",
"{",
"files",
"=",
"[",
"options",
".",
"assets",
",",
"...",
"files",
"]",
";",
"}",
"const",
"server",
"=",
"new",
"WebSocketHost",
"(",
"{",
"assets",
":",
"files",
",",
"port",
":",
"options",
".",
"port",
"}",
")",
";",
"let",
"file",
";",
"if",
"(",
"filename",
")",
"{",
"file",
"=",
"fs",
".",
"readFileSync",
"(",
"filename",
")",
".",
"toString",
"(",
")",
";",
"}",
"else",
"{",
"file",
"=",
"await",
"read_stdin",
"(",
")",
";",
"}",
"server",
".",
"host_table",
"(",
"\"data_source_one\"",
",",
"table",
"(",
"file",
")",
")",
";",
"if",
"(",
"options",
".",
"open",
")",
"{",
"open_browser",
"(",
"options",
".",
"port",
")",
";",
"}",
"}"
] | Host a Perspective on a web server.
@param {*} filename
@param {*} options | [
"Host",
"a",
"Perspective",
"on",
"a",
"web",
"server",
"."
] | 6adfed1360e2d20e673930785e3bc4c19ba6d857 | https://github.com/finos/perspective/blob/6adfed1360e2d20e673930785e3bc4c19ba6d857/packages/perspective-cli/src/js/index.js#L68-L84 |
6,355 | finos/perspective | packages/perspective-viewer-hypergrid/src/js/PerspectiveDataModel.js | async function(row, col, event) {
if (this.isTreeCol(col)) {
let isShift = false;
if (event.primitiveEvent.detail.primitiveEvent) {
isShift = !!event.primitiveEvent.detail.primitiveEvent.shiftKey; // typecast to boolean
}
let is_expanded = await this._view.get_row_expanded(row);
if (isShift) {
if (is_expanded) {
if (this.data[row][col].rowPath.length === 1) {
this._view.collapse(row);
} else {
this._view.set_depth(this.data[row][col].rowPath.length - 2);
}
} else {
this._view.set_depth(this.data[row][col].rowPath.length - 1);
}
} else {
if (is_expanded) {
this._view.collapse(row);
} else {
this._view.expand(row);
}
}
let nrows = await this._view.num_rows();
this.setDirty(nrows);
this.grid.canvas.paintNow();
}
} | javascript | async function(row, col, event) {
if (this.isTreeCol(col)) {
let isShift = false;
if (event.primitiveEvent.detail.primitiveEvent) {
isShift = !!event.primitiveEvent.detail.primitiveEvent.shiftKey; // typecast to boolean
}
let is_expanded = await this._view.get_row_expanded(row);
if (isShift) {
if (is_expanded) {
if (this.data[row][col].rowPath.length === 1) {
this._view.collapse(row);
} else {
this._view.set_depth(this.data[row][col].rowPath.length - 2);
}
} else {
this._view.set_depth(this.data[row][col].rowPath.length - 1);
}
} else {
if (is_expanded) {
this._view.collapse(row);
} else {
this._view.expand(row);
}
}
let nrows = await this._view.num_rows();
this.setDirty(nrows);
this.grid.canvas.paintNow();
}
} | [
"async",
"function",
"(",
"row",
",",
"col",
",",
"event",
")",
"{",
"if",
"(",
"this",
".",
"isTreeCol",
"(",
"col",
")",
")",
"{",
"let",
"isShift",
"=",
"false",
";",
"if",
"(",
"event",
".",
"primitiveEvent",
".",
"detail",
".",
"primitiveEvent",
")",
"{",
"isShift",
"=",
"!",
"!",
"event",
".",
"primitiveEvent",
".",
"detail",
".",
"primitiveEvent",
".",
"shiftKey",
";",
"// typecast to boolean",
"}",
"let",
"is_expanded",
"=",
"await",
"this",
".",
"_view",
".",
"get_row_expanded",
"(",
"row",
")",
";",
"if",
"(",
"isShift",
")",
"{",
"if",
"(",
"is_expanded",
")",
"{",
"if",
"(",
"this",
".",
"data",
"[",
"row",
"]",
"[",
"col",
"]",
".",
"rowPath",
".",
"length",
"===",
"1",
")",
"{",
"this",
".",
"_view",
".",
"collapse",
"(",
"row",
")",
";",
"}",
"else",
"{",
"this",
".",
"_view",
".",
"set_depth",
"(",
"this",
".",
"data",
"[",
"row",
"]",
"[",
"col",
"]",
".",
"rowPath",
".",
"length",
"-",
"2",
")",
";",
"}",
"}",
"else",
"{",
"this",
".",
"_view",
".",
"set_depth",
"(",
"this",
".",
"data",
"[",
"row",
"]",
"[",
"col",
"]",
".",
"rowPath",
".",
"length",
"-",
"1",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"is_expanded",
")",
"{",
"this",
".",
"_view",
".",
"collapse",
"(",
"row",
")",
";",
"}",
"else",
"{",
"this",
".",
"_view",
".",
"expand",
"(",
"row",
")",
";",
"}",
"}",
"let",
"nrows",
"=",
"await",
"this",
".",
"_view",
".",
"num_rows",
"(",
")",
";",
"this",
".",
"setDirty",
"(",
"nrows",
")",
";",
"this",
".",
"grid",
".",
"canvas",
".",
"paintNow",
"(",
")",
";",
"}",
"}"
] | Called when clicking on a row group expand | [
"Called",
"when",
"clicking",
"on",
"a",
"row",
"group",
"expand"
] | 6adfed1360e2d20e673930785e3bc4c19ba6d857 | https://github.com/finos/perspective/blob/6adfed1360e2d20e673930785e3bc4c19ba6d857/packages/perspective-viewer-hypergrid/src/js/PerspectiveDataModel.js#L65-L93 |
|
6,356 | jasonday/printThis | printThis.js | copyValues | function copyValues(origin, clone, elementSelector) {
var $originalElements = origin.find(elementSelector);
clone.find(elementSelector).each(function(index, item) {
$(item).val($originalElements.eq(index).val());
});
} | javascript | function copyValues(origin, clone, elementSelector) {
var $originalElements = origin.find(elementSelector);
clone.find(elementSelector).each(function(index, item) {
$(item).val($originalElements.eq(index).val());
});
} | [
"function",
"copyValues",
"(",
"origin",
",",
"clone",
",",
"elementSelector",
")",
"{",
"var",
"$originalElements",
"=",
"origin",
".",
"find",
"(",
"elementSelector",
")",
";",
"clone",
".",
"find",
"(",
"elementSelector",
")",
".",
"each",
"(",
"function",
"(",
"index",
",",
"item",
")",
"{",
"$",
"(",
"item",
")",
".",
"val",
"(",
"$originalElements",
".",
"eq",
"(",
"index",
")",
".",
"val",
"(",
")",
")",
";",
"}",
")",
";",
"}"
] | Copies values from origin to clone for passed in elementSelector | [
"Copies",
"values",
"from",
"origin",
"to",
"clone",
"for",
"passed",
"in",
"elementSelector"
] | edc43df38e745fddf4823e227316250068a898db | https://github.com/jasonday/printThis/blob/edc43df38e745fddf4823e227316250068a898db/printThis.js#L81-L87 |
6,357 | jasonday/printThis | printThis.js | setDocType | function setDocType($iframe, doctype){
var win, doc;
win = $iframe.get(0);
win = win.contentWindow || win.contentDocument || win;
doc = win.document || win.contentDocument || win;
doc.open();
doc.write(doctype);
doc.close();
} | javascript | function setDocType($iframe, doctype){
var win, doc;
win = $iframe.get(0);
win = win.contentWindow || win.contentDocument || win;
doc = win.document || win.contentDocument || win;
doc.open();
doc.write(doctype);
doc.close();
} | [
"function",
"setDocType",
"(",
"$iframe",
",",
"doctype",
")",
"{",
"var",
"win",
",",
"doc",
";",
"win",
"=",
"$iframe",
".",
"get",
"(",
"0",
")",
";",
"win",
"=",
"win",
".",
"contentWindow",
"||",
"win",
".",
"contentDocument",
"||",
"win",
";",
"doc",
"=",
"win",
".",
"document",
"||",
"win",
".",
"contentDocument",
"||",
"win",
";",
"doc",
".",
"open",
"(",
")",
";",
"doc",
".",
"write",
"(",
"doctype",
")",
";",
"doc",
".",
"close",
"(",
")",
";",
"}"
] | Add doctype to fix the style difference between printing and render | [
"Add",
"doctype",
"to",
"fix",
"the",
"style",
"difference",
"between",
"printing",
"and",
"render"
] | edc43df38e745fddf4823e227316250068a898db | https://github.com/jasonday/printThis/blob/edc43df38e745fddf4823e227316250068a898db/printThis.js#L133-L141 |
6,358 | jasonday/printThis | printThis.js | attachOnBeforePrintEvent | function attachOnBeforePrintEvent($iframe, beforePrintHandler) {
var win = $iframe.get(0);
win = win.contentWindow || win.contentDocument || win;
if (typeof beforePrintHandler === "function") {
if ('matchMedia' in win) {
win.matchMedia('print').addListener(function(mql) {
if(mql.matches) beforePrintHandler();
});
} else {
win.onbeforeprint = beforePrintHandler;
}
}
} | javascript | function attachOnBeforePrintEvent($iframe, beforePrintHandler) {
var win = $iframe.get(0);
win = win.contentWindow || win.contentDocument || win;
if (typeof beforePrintHandler === "function") {
if ('matchMedia' in win) {
win.matchMedia('print').addListener(function(mql) {
if(mql.matches) beforePrintHandler();
});
} else {
win.onbeforeprint = beforePrintHandler;
}
}
} | [
"function",
"attachOnBeforePrintEvent",
"(",
"$iframe",
",",
"beforePrintHandler",
")",
"{",
"var",
"win",
"=",
"$iframe",
".",
"get",
"(",
"0",
")",
";",
"win",
"=",
"win",
".",
"contentWindow",
"||",
"win",
".",
"contentDocument",
"||",
"win",
";",
"if",
"(",
"typeof",
"beforePrintHandler",
"===",
"\"function\"",
")",
"{",
"if",
"(",
"'matchMedia'",
"in",
"win",
")",
"{",
"win",
".",
"matchMedia",
"(",
"'print'",
")",
".",
"addListener",
"(",
"function",
"(",
"mql",
")",
"{",
"if",
"(",
"mql",
".",
"matches",
")",
"beforePrintHandler",
"(",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"win",
".",
"onbeforeprint",
"=",
"beforePrintHandler",
";",
"}",
"}",
"}"
] | attach event handler function to beforePrint event | [
"attach",
"event",
"handler",
"function",
"to",
"beforePrint",
"event"
] | edc43df38e745fddf4823e227316250068a898db | https://github.com/jasonday/printThis/blob/edc43df38e745fddf4823e227316250068a898db/printThis.js#L261-L274 |
6,359 | npm/node-semver | semver.js | isSatisfiable | function isSatisfiable (comparators, options) {
var result = true
var remainingComparators = comparators.slice()
var testComparator = remainingComparators.pop()
while (result && remainingComparators.length) {
result = remainingComparators.every(function (otherComparator) {
return testComparator.intersects(otherComparator, options)
})
testComparator = remainingComparators.pop()
}
return result
} | javascript | function isSatisfiable (comparators, options) {
var result = true
var remainingComparators = comparators.slice()
var testComparator = remainingComparators.pop()
while (result && remainingComparators.length) {
result = remainingComparators.every(function (otherComparator) {
return testComparator.intersects(otherComparator, options)
})
testComparator = remainingComparators.pop()
}
return result
} | [
"function",
"isSatisfiable",
"(",
"comparators",
",",
"options",
")",
"{",
"var",
"result",
"=",
"true",
"var",
"remainingComparators",
"=",
"comparators",
".",
"slice",
"(",
")",
"var",
"testComparator",
"=",
"remainingComparators",
".",
"pop",
"(",
")",
"while",
"(",
"result",
"&&",
"remainingComparators",
".",
"length",
")",
"{",
"result",
"=",
"remainingComparators",
".",
"every",
"(",
"function",
"(",
"otherComparator",
")",
"{",
"return",
"testComparator",
".",
"intersects",
"(",
"otherComparator",
",",
"options",
")",
"}",
")",
"testComparator",
"=",
"remainingComparators",
".",
"pop",
"(",
")",
"}",
"return",
"result",
"}"
] | take a set of comparators and determine whether there exists a version which can satisfy it | [
"take",
"a",
"set",
"of",
"comparators",
"and",
"determine",
"whether",
"there",
"exists",
"a",
"version",
"which",
"can",
"satisfy",
"it"
] | 5fb517b2906a0763518e1941a3f4a163956a81d3 | https://github.com/npm/node-semver/blob/5fb517b2906a0763518e1941a3f4a163956a81d3/semver.js#L955-L969 |
6,360 | apache/cordova-plugin-camera | src/windows/CameraProxy.js | resizeImageBase64 | function resizeImageBase64 (successCallback, errorCallback, file, targetWidth, targetHeight) {
fileIO.readBufferAsync(file).done(function (buffer) {
var strBase64 = encodeToBase64String(buffer);
var imageData = 'data:' + file.contentType + ';base64,' + strBase64;
var image = new Image(); /* eslint no-undef : 0 */
image.src = imageData;
image.onload = function () {
var ratio = Math.min(targetWidth / this.width, targetHeight / this.height);
var imageWidth = ratio * this.width;
var imageHeight = ratio * this.height;
var canvas = document.createElement('canvas');
canvas.width = imageWidth;
canvas.height = imageHeight;
var ctx = canvas.getContext('2d');
ctx.drawImage(this, 0, 0, imageWidth, imageHeight);
// The resized file ready for upload
var finalFile = canvas.toDataURL(file.contentType);
// Remove the prefix such as "data:" + contentType + ";base64," , in order to meet the Cordova API.
var arr = finalFile.split(',');
var newStr = finalFile.substr(arr[0].length + 1);
successCallback(newStr);
};
}, function (err) { errorCallback(err); });
} | javascript | function resizeImageBase64 (successCallback, errorCallback, file, targetWidth, targetHeight) {
fileIO.readBufferAsync(file).done(function (buffer) {
var strBase64 = encodeToBase64String(buffer);
var imageData = 'data:' + file.contentType + ';base64,' + strBase64;
var image = new Image(); /* eslint no-undef : 0 */
image.src = imageData;
image.onload = function () {
var ratio = Math.min(targetWidth / this.width, targetHeight / this.height);
var imageWidth = ratio * this.width;
var imageHeight = ratio * this.height;
var canvas = document.createElement('canvas');
canvas.width = imageWidth;
canvas.height = imageHeight;
var ctx = canvas.getContext('2d');
ctx.drawImage(this, 0, 0, imageWidth, imageHeight);
// The resized file ready for upload
var finalFile = canvas.toDataURL(file.contentType);
// Remove the prefix such as "data:" + contentType + ";base64," , in order to meet the Cordova API.
var arr = finalFile.split(',');
var newStr = finalFile.substr(arr[0].length + 1);
successCallback(newStr);
};
}, function (err) { errorCallback(err); });
} | [
"function",
"resizeImageBase64",
"(",
"successCallback",
",",
"errorCallback",
",",
"file",
",",
"targetWidth",
",",
"targetHeight",
")",
"{",
"fileIO",
".",
"readBufferAsync",
"(",
"file",
")",
".",
"done",
"(",
"function",
"(",
"buffer",
")",
"{",
"var",
"strBase64",
"=",
"encodeToBase64String",
"(",
"buffer",
")",
";",
"var",
"imageData",
"=",
"'data:'",
"+",
"file",
".",
"contentType",
"+",
"';base64,'",
"+",
"strBase64",
";",
"var",
"image",
"=",
"new",
"Image",
"(",
")",
";",
"/* eslint no-undef : 0 */",
"image",
".",
"src",
"=",
"imageData",
";",
"image",
".",
"onload",
"=",
"function",
"(",
")",
"{",
"var",
"ratio",
"=",
"Math",
".",
"min",
"(",
"targetWidth",
"/",
"this",
".",
"width",
",",
"targetHeight",
"/",
"this",
".",
"height",
")",
";",
"var",
"imageWidth",
"=",
"ratio",
"*",
"this",
".",
"width",
";",
"var",
"imageHeight",
"=",
"ratio",
"*",
"this",
".",
"height",
";",
"var",
"canvas",
"=",
"document",
".",
"createElement",
"(",
"'canvas'",
")",
";",
"canvas",
".",
"width",
"=",
"imageWidth",
";",
"canvas",
".",
"height",
"=",
"imageHeight",
";",
"var",
"ctx",
"=",
"canvas",
".",
"getContext",
"(",
"'2d'",
")",
";",
"ctx",
".",
"drawImage",
"(",
"this",
",",
"0",
",",
"0",
",",
"imageWidth",
",",
"imageHeight",
")",
";",
"// The resized file ready for upload",
"var",
"finalFile",
"=",
"canvas",
".",
"toDataURL",
"(",
"file",
".",
"contentType",
")",
";",
"// Remove the prefix such as \"data:\" + contentType + \";base64,\" , in order to meet the Cordova API.",
"var",
"arr",
"=",
"finalFile",
".",
"split",
"(",
"','",
")",
";",
"var",
"newStr",
"=",
"finalFile",
".",
"substr",
"(",
"arr",
"[",
"0",
"]",
".",
"length",
"+",
"1",
")",
";",
"successCallback",
"(",
"newStr",
")",
";",
"}",
";",
"}",
",",
"function",
"(",
"err",
")",
"{",
"errorCallback",
"(",
"err",
")",
";",
"}",
")",
";",
"}"
] | Because of asynchronous method, so let the successCallback be called in it. | [
"Because",
"of",
"asynchronous",
"method",
"so",
"let",
"the",
"successCallback",
"be",
"called",
"in",
"it",
"."
] | 295e928784e2a9785982fbf15b05215a317774df | https://github.com/apache/cordova-plugin-camera/blob/295e928784e2a9785982fbf15b05215a317774df/src/windows/CameraProxy.js#L133-L162 |
6,361 | apache/cordova-plugin-camera | src/windows/CameraProxy.js | orientationToRotation | function orientationToRotation (orientation) {
// VideoRotation enumerable and BitmapRotation enumerable have the same values
// https://msdn.microsoft.com/en-us/library/windows/apps/windows.media.capture.videorotation.aspx
// https://msdn.microsoft.com/en-us/library/windows/apps/windows.graphics.imaging.bitmaprotation.aspx
switch (orientation) {
// portrait
case Windows.Devices.Sensors.SimpleOrientation.notRotated:
return Windows.Media.Capture.VideoRotation.clockwise90Degrees;
// landscape
case Windows.Devices.Sensors.SimpleOrientation.rotated90DegreesCounterclockwise:
return Windows.Media.Capture.VideoRotation.none;
// portrait-flipped (not supported by WinPhone Apps)
case Windows.Devices.Sensors.SimpleOrientation.rotated180DegreesCounterclockwise:
// Falling back to portrait default
return Windows.Media.Capture.VideoRotation.clockwise90Degrees;
// landscape-flipped
case Windows.Devices.Sensors.SimpleOrientation.rotated270DegreesCounterclockwise:
return Windows.Media.Capture.VideoRotation.clockwise180Degrees;
// faceup & facedown
default:
// Falling back to portrait default
return Windows.Media.Capture.VideoRotation.clockwise90Degrees;
}
} | javascript | function orientationToRotation (orientation) {
// VideoRotation enumerable and BitmapRotation enumerable have the same values
// https://msdn.microsoft.com/en-us/library/windows/apps/windows.media.capture.videorotation.aspx
// https://msdn.microsoft.com/en-us/library/windows/apps/windows.graphics.imaging.bitmaprotation.aspx
switch (orientation) {
// portrait
case Windows.Devices.Sensors.SimpleOrientation.notRotated:
return Windows.Media.Capture.VideoRotation.clockwise90Degrees;
// landscape
case Windows.Devices.Sensors.SimpleOrientation.rotated90DegreesCounterclockwise:
return Windows.Media.Capture.VideoRotation.none;
// portrait-flipped (not supported by WinPhone Apps)
case Windows.Devices.Sensors.SimpleOrientation.rotated180DegreesCounterclockwise:
// Falling back to portrait default
return Windows.Media.Capture.VideoRotation.clockwise90Degrees;
// landscape-flipped
case Windows.Devices.Sensors.SimpleOrientation.rotated270DegreesCounterclockwise:
return Windows.Media.Capture.VideoRotation.clockwise180Degrees;
// faceup & facedown
default:
// Falling back to portrait default
return Windows.Media.Capture.VideoRotation.clockwise90Degrees;
}
} | [
"function",
"orientationToRotation",
"(",
"orientation",
")",
"{",
"// VideoRotation enumerable and BitmapRotation enumerable have the same values",
"// https://msdn.microsoft.com/en-us/library/windows/apps/windows.media.capture.videorotation.aspx",
"// https://msdn.microsoft.com/en-us/library/windows/apps/windows.graphics.imaging.bitmaprotation.aspx",
"switch",
"(",
"orientation",
")",
"{",
"// portrait",
"case",
"Windows",
".",
"Devices",
".",
"Sensors",
".",
"SimpleOrientation",
".",
"notRotated",
":",
"return",
"Windows",
".",
"Media",
".",
"Capture",
".",
"VideoRotation",
".",
"clockwise90Degrees",
";",
"// landscape",
"case",
"Windows",
".",
"Devices",
".",
"Sensors",
".",
"SimpleOrientation",
".",
"rotated90DegreesCounterclockwise",
":",
"return",
"Windows",
".",
"Media",
".",
"Capture",
".",
"VideoRotation",
".",
"none",
";",
"// portrait-flipped (not supported by WinPhone Apps)",
"case",
"Windows",
".",
"Devices",
".",
"Sensors",
".",
"SimpleOrientation",
".",
"rotated180DegreesCounterclockwise",
":",
"// Falling back to portrait default",
"return",
"Windows",
".",
"Media",
".",
"Capture",
".",
"VideoRotation",
".",
"clockwise90Degrees",
";",
"// landscape-flipped",
"case",
"Windows",
".",
"Devices",
".",
"Sensors",
".",
"SimpleOrientation",
".",
"rotated270DegreesCounterclockwise",
":",
"return",
"Windows",
".",
"Media",
".",
"Capture",
".",
"VideoRotation",
".",
"clockwise180Degrees",
";",
"// faceup & facedown",
"default",
":",
"// Falling back to portrait default",
"return",
"Windows",
".",
"Media",
".",
"Capture",
".",
"VideoRotation",
".",
"clockwise90Degrees",
";",
"}",
"}"
] | Converts SimpleOrientation to a VideoRotation to remove difference between camera sensor orientation
and video orientation
@param {number} orientation - Windows.Devices.Sensors.SimpleOrientation
@return {number} - Windows.Media.Capture.VideoRotation | [
"Converts",
"SimpleOrientation",
"to",
"a",
"VideoRotation",
"to",
"remove",
"difference",
"between",
"camera",
"sensor",
"orientation",
"and",
"video",
"orientation"
] | 295e928784e2a9785982fbf15b05215a317774df | https://github.com/apache/cordova-plugin-camera/blob/295e928784e2a9785982fbf15b05215a317774df/src/windows/CameraProxy.js#L651-L675 |
6,362 | apache/cordova-plugin-camera | src/windows/CameraProxy.js | function (picture) {
if (options.destinationType === Camera.DestinationType.FILE_URI || options.destinationType === Camera.DestinationType.NATIVE_URI) {
if (options.targetHeight > 0 && options.targetWidth > 0) {
resizeImage(successCallback, errorCallback, picture, options.targetWidth, options.targetHeight, options.encodingType);
} else {
// CB-11714: check if target content-type is PNG to just rename as *.jpg since camera is captured as JPEG
if (options.encodingType === Camera.EncodingType.PNG) {
picture.name = picture.name.replace(/\.png$/, '.jpg');
}
picture.copyAsync(getAppData().localFolder, picture.name, OptUnique).done(function (copiedFile) {
successCallback('ms-appdata:///local/' + copiedFile.name);
}, errorCallback);
}
} else {
if (options.targetHeight > 0 && options.targetWidth > 0) {
resizeImageBase64(successCallback, errorCallback, picture, options.targetWidth, options.targetHeight);
} else {
fileIO.readBufferAsync(picture).done(function (buffer) {
var strBase64 = encodeToBase64String(buffer);
picture.deleteAsync().done(function () {
successCallback(strBase64);
}, function (err) {
errorCallback(err);
});
}, errorCallback);
}
}
} | javascript | function (picture) {
if (options.destinationType === Camera.DestinationType.FILE_URI || options.destinationType === Camera.DestinationType.NATIVE_URI) {
if (options.targetHeight > 0 && options.targetWidth > 0) {
resizeImage(successCallback, errorCallback, picture, options.targetWidth, options.targetHeight, options.encodingType);
} else {
// CB-11714: check if target content-type is PNG to just rename as *.jpg since camera is captured as JPEG
if (options.encodingType === Camera.EncodingType.PNG) {
picture.name = picture.name.replace(/\.png$/, '.jpg');
}
picture.copyAsync(getAppData().localFolder, picture.name, OptUnique).done(function (copiedFile) {
successCallback('ms-appdata:///local/' + copiedFile.name);
}, errorCallback);
}
} else {
if (options.targetHeight > 0 && options.targetWidth > 0) {
resizeImageBase64(successCallback, errorCallback, picture, options.targetWidth, options.targetHeight);
} else {
fileIO.readBufferAsync(picture).done(function (buffer) {
var strBase64 = encodeToBase64String(buffer);
picture.deleteAsync().done(function () {
successCallback(strBase64);
}, function (err) {
errorCallback(err);
});
}, errorCallback);
}
}
} | [
"function",
"(",
"picture",
")",
"{",
"if",
"(",
"options",
".",
"destinationType",
"===",
"Camera",
".",
"DestinationType",
".",
"FILE_URI",
"||",
"options",
".",
"destinationType",
"===",
"Camera",
".",
"DestinationType",
".",
"NATIVE_URI",
")",
"{",
"if",
"(",
"options",
".",
"targetHeight",
">",
"0",
"&&",
"options",
".",
"targetWidth",
">",
"0",
")",
"{",
"resizeImage",
"(",
"successCallback",
",",
"errorCallback",
",",
"picture",
",",
"options",
".",
"targetWidth",
",",
"options",
".",
"targetHeight",
",",
"options",
".",
"encodingType",
")",
";",
"}",
"else",
"{",
"// CB-11714: check if target content-type is PNG to just rename as *.jpg since camera is captured as JPEG",
"if",
"(",
"options",
".",
"encodingType",
"===",
"Camera",
".",
"EncodingType",
".",
"PNG",
")",
"{",
"picture",
".",
"name",
"=",
"picture",
".",
"name",
".",
"replace",
"(",
"/",
"\\.png$",
"/",
",",
"'.jpg'",
")",
";",
"}",
"picture",
".",
"copyAsync",
"(",
"getAppData",
"(",
")",
".",
"localFolder",
",",
"picture",
".",
"name",
",",
"OptUnique",
")",
".",
"done",
"(",
"function",
"(",
"copiedFile",
")",
"{",
"successCallback",
"(",
"'ms-appdata:///local/'",
"+",
"copiedFile",
".",
"name",
")",
";",
"}",
",",
"errorCallback",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"options",
".",
"targetHeight",
">",
"0",
"&&",
"options",
".",
"targetWidth",
">",
"0",
")",
"{",
"resizeImageBase64",
"(",
"successCallback",
",",
"errorCallback",
",",
"picture",
",",
"options",
".",
"targetWidth",
",",
"options",
".",
"targetHeight",
")",
";",
"}",
"else",
"{",
"fileIO",
".",
"readBufferAsync",
"(",
"picture",
")",
".",
"done",
"(",
"function",
"(",
"buffer",
")",
"{",
"var",
"strBase64",
"=",
"encodeToBase64String",
"(",
"buffer",
")",
";",
"picture",
".",
"deleteAsync",
"(",
")",
".",
"done",
"(",
"function",
"(",
")",
"{",
"successCallback",
"(",
"strBase64",
")",
";",
"}",
",",
"function",
"(",
"err",
")",
"{",
"errorCallback",
"(",
"err",
")",
";",
"}",
")",
";",
"}",
",",
"errorCallback",
")",
";",
"}",
"}",
"}"
] | success callback for capture operation | [
"success",
"callback",
"for",
"capture",
"operation"
] | 295e928784e2a9785982fbf15b05215a317774df | https://github.com/apache/cordova-plugin-camera/blob/295e928784e2a9785982fbf15b05215a317774df/src/windows/CameraProxy.js#L783-L811 |
|
6,363 | firefox-devtools/debugger | packages/devtools-reps/src/reps/grip.js | getProps | function getProps(componentProps, properties, indexes, suppressQuotes) {
// Make indexes ordered by ascending.
indexes.sort(function(a, b) {
return a - b;
});
const propertiesKeys = Object.keys(properties);
return indexes.map(i => {
const name = propertiesKeys[i];
const value = getPropValue(properties[name]);
return PropRep({
...componentProps,
mode: MODE.TINY,
name,
object: value,
equal: ": ",
defaultRep: Grip,
title: null,
suppressQuotes
});
});
} | javascript | function getProps(componentProps, properties, indexes, suppressQuotes) {
// Make indexes ordered by ascending.
indexes.sort(function(a, b) {
return a - b;
});
const propertiesKeys = Object.keys(properties);
return indexes.map(i => {
const name = propertiesKeys[i];
const value = getPropValue(properties[name]);
return PropRep({
...componentProps,
mode: MODE.TINY,
name,
object: value,
equal: ": ",
defaultRep: Grip,
title: null,
suppressQuotes
});
});
} | [
"function",
"getProps",
"(",
"componentProps",
",",
"properties",
",",
"indexes",
",",
"suppressQuotes",
")",
"{",
"// Make indexes ordered by ascending.",
"indexes",
".",
"sort",
"(",
"function",
"(",
"a",
",",
"b",
")",
"{",
"return",
"a",
"-",
"b",
";",
"}",
")",
";",
"const",
"propertiesKeys",
"=",
"Object",
".",
"keys",
"(",
"properties",
")",
";",
"return",
"indexes",
".",
"map",
"(",
"i",
"=>",
"{",
"const",
"name",
"=",
"propertiesKeys",
"[",
"i",
"]",
";",
"const",
"value",
"=",
"getPropValue",
"(",
"properties",
"[",
"name",
"]",
")",
";",
"return",
"PropRep",
"(",
"{",
"...",
"componentProps",
",",
"mode",
":",
"MODE",
".",
"TINY",
",",
"name",
",",
"object",
":",
"value",
",",
"equal",
":",
"\": \"",
",",
"defaultRep",
":",
"Grip",
",",
"title",
":",
"null",
",",
"suppressQuotes",
"}",
")",
";",
"}",
")",
";",
"}"
] | Get props ordered by index.
@param {Object} componentProps Grip Component props.
@param {Object} properties Properties of the object the Grip describes.
@param {Array} indexes Indexes of properties.
@param {Boolean} suppressQuotes true if we should suppress quotes
on property names.
@return {Array} Props. | [
"Get",
"props",
"ordered",
"by",
"index",
"."
] | a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f | https://github.com/firefox-devtools/debugger/blob/a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f/packages/devtools-reps/src/reps/grip.js#L244-L266 |
6,364 | firefox-devtools/debugger | packages/devtools-reps/src/reps/grip.js | getPropIndexes | function getPropIndexes(properties, max, filter) {
const indexes = [];
try {
let i = 0;
for (const name in properties) {
if (indexes.length >= max) {
return indexes;
}
// Type is specified in grip's "class" field and for primitive
// values use typeof.
const value = getPropValue(properties[name]);
let type = value.class || typeof value;
type = type.toLowerCase();
if (filter(type, value, name)) {
indexes.push(i);
}
i++;
}
} catch (err) {
console.error(err);
}
return indexes;
} | javascript | function getPropIndexes(properties, max, filter) {
const indexes = [];
try {
let i = 0;
for (const name in properties) {
if (indexes.length >= max) {
return indexes;
}
// Type is specified in grip's "class" field and for primitive
// values use typeof.
const value = getPropValue(properties[name]);
let type = value.class || typeof value;
type = type.toLowerCase();
if (filter(type, value, name)) {
indexes.push(i);
}
i++;
}
} catch (err) {
console.error(err);
}
return indexes;
} | [
"function",
"getPropIndexes",
"(",
"properties",
",",
"max",
",",
"filter",
")",
"{",
"const",
"indexes",
"=",
"[",
"]",
";",
"try",
"{",
"let",
"i",
"=",
"0",
";",
"for",
"(",
"const",
"name",
"in",
"properties",
")",
"{",
"if",
"(",
"indexes",
".",
"length",
">=",
"max",
")",
"{",
"return",
"indexes",
";",
"}",
"// Type is specified in grip's \"class\" field and for primitive",
"// values use typeof.",
"const",
"value",
"=",
"getPropValue",
"(",
"properties",
"[",
"name",
"]",
")",
";",
"let",
"type",
"=",
"value",
".",
"class",
"||",
"typeof",
"value",
";",
"type",
"=",
"type",
".",
"toLowerCase",
"(",
")",
";",
"if",
"(",
"filter",
"(",
"type",
",",
"value",
",",
"name",
")",
")",
"{",
"indexes",
".",
"push",
"(",
"i",
")",
";",
"}",
"i",
"++",
";",
"}",
"}",
"catch",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"err",
")",
";",
"}",
"return",
"indexes",
";",
"}"
] | Get the indexes of props in the object.
@param {Object} properties Props object.
@param {Number} max The maximum length of indexes array.
@param {Function} filter Filter the props you want.
@return {Array} Indexes of interesting props in the object. | [
"Get",
"the",
"indexes",
"of",
"props",
"in",
"the",
"object",
"."
] | a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f | https://github.com/firefox-devtools/debugger/blob/a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f/packages/devtools-reps/src/reps/grip.js#L276-L301 |
6,365 | firefox-devtools/debugger | packages/devtools-reps/src/reps/grip.js | getPropValue | function getPropValue(property) {
let value = property;
if (typeof property === "object") {
const keys = Object.keys(property);
if (keys.includes("value")) {
value = property.value;
} else if (keys.includes("getterValue")) {
value = property.getterValue;
}
}
return value;
} | javascript | function getPropValue(property) {
let value = property;
if (typeof property === "object") {
const keys = Object.keys(property);
if (keys.includes("value")) {
value = property.value;
} else if (keys.includes("getterValue")) {
value = property.getterValue;
}
}
return value;
} | [
"function",
"getPropValue",
"(",
"property",
")",
"{",
"let",
"value",
"=",
"property",
";",
"if",
"(",
"typeof",
"property",
"===",
"\"object\"",
")",
"{",
"const",
"keys",
"=",
"Object",
".",
"keys",
"(",
"property",
")",
";",
"if",
"(",
"keys",
".",
"includes",
"(",
"\"value\"",
")",
")",
"{",
"value",
"=",
"property",
".",
"value",
";",
"}",
"else",
"if",
"(",
"keys",
".",
"includes",
"(",
"\"getterValue\"",
")",
")",
"{",
"value",
"=",
"property",
".",
"getterValue",
";",
"}",
"}",
"return",
"value",
";",
"}"
] | Get the actual value of a property.
@param {Object} property
@return {Object} Value of the property. | [
"Get",
"the",
"actual",
"value",
"of",
"a",
"property",
"."
] | a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f | https://github.com/firefox-devtools/debugger/blob/a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f/packages/devtools-reps/src/reps/grip.js#L309-L320 |
6,366 | firefox-devtools/debugger | packages/devtools-components/src/tree.js | oncePerAnimationFrame | function oncePerAnimationFrame(fn) {
let animationId = null;
let argsToPass = null;
return function(...args) {
argsToPass = args;
if (animationId !== null) {
return;
}
animationId = requestAnimationFrame(() => {
fn.call(this, ...argsToPass);
animationId = null;
argsToPass = null;
});
};
} | javascript | function oncePerAnimationFrame(fn) {
let animationId = null;
let argsToPass = null;
return function(...args) {
argsToPass = args;
if (animationId !== null) {
return;
}
animationId = requestAnimationFrame(() => {
fn.call(this, ...argsToPass);
animationId = null;
argsToPass = null;
});
};
} | [
"function",
"oncePerAnimationFrame",
"(",
"fn",
")",
"{",
"let",
"animationId",
"=",
"null",
";",
"let",
"argsToPass",
"=",
"null",
";",
"return",
"function",
"(",
"...",
"args",
")",
"{",
"argsToPass",
"=",
"args",
";",
"if",
"(",
"animationId",
"!==",
"null",
")",
"{",
"return",
";",
"}",
"animationId",
"=",
"requestAnimationFrame",
"(",
"(",
")",
"=>",
"{",
"fn",
".",
"call",
"(",
"this",
",",
"...",
"argsToPass",
")",
";",
"animationId",
"=",
"null",
";",
"argsToPass",
"=",
"null",
";",
"}",
")",
";",
"}",
";",
"}"
] | Create a function that calls the given function `fn` only once per animation
frame.
@param {Function} fn
@returns {Function} | [
"Create",
"a",
"function",
"that",
"calls",
"the",
"given",
"function",
"fn",
"only",
"once",
"per",
"animation",
"frame",
"."
] | a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f | https://github.com/firefox-devtools/debugger/blob/a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f/packages/devtools-components/src/tree.js#L227-L242 |
6,367 | firefox-devtools/debugger | packages/devtools-reps/src/reps/rep-utils.js | escapeString | function escapeString(str, escapeWhitespace) {
return `"${str.replace(escapeRegexp, (match, offset) => {
const c = match.charCodeAt(0);
if (c in escapeMap) {
if (!escapeWhitespace && (c === 9 || c === 0xa || c === 0xd)) {
return match[0];
}
return escapeMap[c];
}
if (c >= 0xd800 && c <= 0xdfff) {
// Find the full code point containing the surrogate, with a
// special case for a trailing surrogate at the start of the
// string.
if (c >= 0xdc00 && offset > 0) {
--offset;
}
const codePoint = str.codePointAt(offset);
if (codePoint >= 0xd800 && codePoint <= 0xdfff) {
// Unpaired surrogate.
return `\\u${codePoint.toString(16)}`;
} else if (codePoint >= 0xf0000 && codePoint <= 0x10fffd) {
// Private use area. Because we visit each pair of a such a
// character, return the empty string for one half and the
// real result for the other, to avoid duplication.
if (c <= 0xdbff) {
return `\\u{${codePoint.toString(16)}}`;
}
return "";
}
// Other surrogate characters are passed through.
return match;
}
return `\\u${`0000${c.toString(16)}`.substr(-4)}`;
})}"`;
} | javascript | function escapeString(str, escapeWhitespace) {
return `"${str.replace(escapeRegexp, (match, offset) => {
const c = match.charCodeAt(0);
if (c in escapeMap) {
if (!escapeWhitespace && (c === 9 || c === 0xa || c === 0xd)) {
return match[0];
}
return escapeMap[c];
}
if (c >= 0xd800 && c <= 0xdfff) {
// Find the full code point containing the surrogate, with a
// special case for a trailing surrogate at the start of the
// string.
if (c >= 0xdc00 && offset > 0) {
--offset;
}
const codePoint = str.codePointAt(offset);
if (codePoint >= 0xd800 && codePoint <= 0xdfff) {
// Unpaired surrogate.
return `\\u${codePoint.toString(16)}`;
} else if (codePoint >= 0xf0000 && codePoint <= 0x10fffd) {
// Private use area. Because we visit each pair of a such a
// character, return the empty string for one half and the
// real result for the other, to avoid duplication.
if (c <= 0xdbff) {
return `\\u{${codePoint.toString(16)}}`;
}
return "";
}
// Other surrogate characters are passed through.
return match;
}
return `\\u${`0000${c.toString(16)}`.substr(-4)}`;
})}"`;
} | [
"function",
"escapeString",
"(",
"str",
",",
"escapeWhitespace",
")",
"{",
"return",
"`",
"${",
"str",
".",
"replace",
"(",
"escapeRegexp",
",",
"(",
"match",
",",
"offset",
")",
"=>",
"{",
"const",
"c",
"=",
"match",
".",
"charCodeAt",
"(",
"0",
")",
";",
"if",
"(",
"c",
"in",
"escapeMap",
")",
"{",
"if",
"(",
"!",
"escapeWhitespace",
"&&",
"(",
"c",
"===",
"9",
"||",
"c",
"===",
"0xa",
"||",
"c",
"===",
"0xd",
")",
")",
"{",
"return",
"match",
"[",
"0",
"]",
";",
"}",
"return",
"escapeMap",
"[",
"c",
"]",
";",
"}",
"if",
"(",
"c",
">=",
"0xd800",
"&&",
"c",
"<=",
"0xdfff",
")",
"{",
"// Find the full code point containing the surrogate, with a",
"// special case for a trailing surrogate at the start of the",
"// string.",
"if",
"(",
"c",
">=",
"0xdc00",
"&&",
"offset",
">",
"0",
")",
"{",
"--",
"offset",
";",
"}",
"const",
"codePoint",
"=",
"str",
".",
"codePointAt",
"(",
"offset",
")",
";",
"if",
"(",
"codePoint",
">=",
"0xd800",
"&&",
"codePoint",
"<=",
"0xdfff",
")",
"{",
"// Unpaired surrogate.",
"return",
"`",
"\\\\",
"${",
"codePoint",
".",
"toString",
"(",
"16",
")",
"}",
"`",
";",
"}",
"else",
"if",
"(",
"codePoint",
">=",
"0xf0000",
"&&",
"codePoint",
"<=",
"0x10fffd",
")",
"{",
"// Private use area. Because we visit each pair of a such a",
"// character, return the empty string for one half and the",
"// real result for the other, to avoid duplication.",
"if",
"(",
"c",
"<=",
"0xdbff",
")",
"{",
"return",
"`",
"\\\\",
"${",
"codePoint",
".",
"toString",
"(",
"16",
")",
"}",
"`",
";",
"}",
"return",
"\"\"",
";",
"}",
"// Other surrogate characters are passed through.",
"return",
"match",
";",
"}",
"return",
"`",
"\\\\",
"${",
"`",
"${",
"c",
".",
"toString",
"(",
"16",
")",
"}",
"`",
".",
"substr",
"(",
"-",
"4",
")",
"}",
"`",
";",
"}",
")",
"}",
"`",
";",
"}"
] | Escape a string so that the result is viewable and valid JS.
Control characters, other invisibles, invalid characters,
backslash, and double quotes are escaped. The resulting string is
surrounded by double quotes.
@param {String} str
the input
@param {Boolean} escapeWhitespace
if true, TAB, CR, and NL characters will be escaped
@return {String} the escaped string | [
"Escape",
"a",
"string",
"so",
"that",
"the",
"result",
"is",
"viewable",
"and",
"valid",
"JS",
".",
"Control",
"characters",
"other",
"invisibles",
"invalid",
"characters",
"backslash",
"and",
"double",
"quotes",
"are",
"escaped",
".",
"The",
"resulting",
"string",
"is",
"surrounded",
"by",
"double",
"quotes",
"."
] | a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f | https://github.com/firefox-devtools/debugger/blob/a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f/packages/devtools-reps/src/reps/rep-utils.js#L137-L171 |
6,368 | firefox-devtools/debugger | packages/devtools-reps/src/reps/rep-utils.js | getGripPreviewItems | function getGripPreviewItems(grip) {
if (!grip) {
return [];
}
// Promise resolved value Grip
if (grip.promiseState && grip.promiseState.value) {
return [grip.promiseState.value];
}
// Array Grip
if (grip.preview && grip.preview.items) {
return grip.preview.items;
}
// Node Grip
if (grip.preview && grip.preview.childNodes) {
return grip.preview.childNodes;
}
// Set or Map Grip
if (grip.preview && grip.preview.entries) {
return grip.preview.entries.reduce((res, entry) => res.concat(entry), []);
}
// Event Grip
if (grip.preview && grip.preview.target) {
const keys = Object.keys(grip.preview.properties);
const values = Object.values(grip.preview.properties);
return [grip.preview.target, ...keys, ...values];
}
// RegEx Grip
if (grip.displayString) {
return [grip.displayString];
}
// Generic Grip
if (grip.preview && grip.preview.ownProperties) {
let propertiesValues = Object.values(grip.preview.ownProperties).map(
property => property.value || property
);
const propertyKeys = Object.keys(grip.preview.ownProperties);
propertiesValues = propertiesValues.concat(propertyKeys);
// ArrayBuffer Grip
if (grip.preview.safeGetterValues) {
propertiesValues = propertiesValues.concat(
Object.values(grip.preview.safeGetterValues).map(
property => property.getterValue || property
)
);
}
return propertiesValues;
}
return [];
} | javascript | function getGripPreviewItems(grip) {
if (!grip) {
return [];
}
// Promise resolved value Grip
if (grip.promiseState && grip.promiseState.value) {
return [grip.promiseState.value];
}
// Array Grip
if (grip.preview && grip.preview.items) {
return grip.preview.items;
}
// Node Grip
if (grip.preview && grip.preview.childNodes) {
return grip.preview.childNodes;
}
// Set or Map Grip
if (grip.preview && grip.preview.entries) {
return grip.preview.entries.reduce((res, entry) => res.concat(entry), []);
}
// Event Grip
if (grip.preview && grip.preview.target) {
const keys = Object.keys(grip.preview.properties);
const values = Object.values(grip.preview.properties);
return [grip.preview.target, ...keys, ...values];
}
// RegEx Grip
if (grip.displayString) {
return [grip.displayString];
}
// Generic Grip
if (grip.preview && grip.preview.ownProperties) {
let propertiesValues = Object.values(grip.preview.ownProperties).map(
property => property.value || property
);
const propertyKeys = Object.keys(grip.preview.ownProperties);
propertiesValues = propertiesValues.concat(propertyKeys);
// ArrayBuffer Grip
if (grip.preview.safeGetterValues) {
propertiesValues = propertiesValues.concat(
Object.values(grip.preview.safeGetterValues).map(
property => property.getterValue || property
)
);
}
return propertiesValues;
}
return [];
} | [
"function",
"getGripPreviewItems",
"(",
"grip",
")",
"{",
"if",
"(",
"!",
"grip",
")",
"{",
"return",
"[",
"]",
";",
"}",
"// Promise resolved value Grip",
"if",
"(",
"grip",
".",
"promiseState",
"&&",
"grip",
".",
"promiseState",
".",
"value",
")",
"{",
"return",
"[",
"grip",
".",
"promiseState",
".",
"value",
"]",
";",
"}",
"// Array Grip",
"if",
"(",
"grip",
".",
"preview",
"&&",
"grip",
".",
"preview",
".",
"items",
")",
"{",
"return",
"grip",
".",
"preview",
".",
"items",
";",
"}",
"// Node Grip",
"if",
"(",
"grip",
".",
"preview",
"&&",
"grip",
".",
"preview",
".",
"childNodes",
")",
"{",
"return",
"grip",
".",
"preview",
".",
"childNodes",
";",
"}",
"// Set or Map Grip",
"if",
"(",
"grip",
".",
"preview",
"&&",
"grip",
".",
"preview",
".",
"entries",
")",
"{",
"return",
"grip",
".",
"preview",
".",
"entries",
".",
"reduce",
"(",
"(",
"res",
",",
"entry",
")",
"=>",
"res",
".",
"concat",
"(",
"entry",
")",
",",
"[",
"]",
")",
";",
"}",
"// Event Grip",
"if",
"(",
"grip",
".",
"preview",
"&&",
"grip",
".",
"preview",
".",
"target",
")",
"{",
"const",
"keys",
"=",
"Object",
".",
"keys",
"(",
"grip",
".",
"preview",
".",
"properties",
")",
";",
"const",
"values",
"=",
"Object",
".",
"values",
"(",
"grip",
".",
"preview",
".",
"properties",
")",
";",
"return",
"[",
"grip",
".",
"preview",
".",
"target",
",",
"...",
"keys",
",",
"...",
"values",
"]",
";",
"}",
"// RegEx Grip",
"if",
"(",
"grip",
".",
"displayString",
")",
"{",
"return",
"[",
"grip",
".",
"displayString",
"]",
";",
"}",
"// Generic Grip",
"if",
"(",
"grip",
".",
"preview",
"&&",
"grip",
".",
"preview",
".",
"ownProperties",
")",
"{",
"let",
"propertiesValues",
"=",
"Object",
".",
"values",
"(",
"grip",
".",
"preview",
".",
"ownProperties",
")",
".",
"map",
"(",
"property",
"=>",
"property",
".",
"value",
"||",
"property",
")",
";",
"const",
"propertyKeys",
"=",
"Object",
".",
"keys",
"(",
"grip",
".",
"preview",
".",
"ownProperties",
")",
";",
"propertiesValues",
"=",
"propertiesValues",
".",
"concat",
"(",
"propertyKeys",
")",
";",
"// ArrayBuffer Grip",
"if",
"(",
"grip",
".",
"preview",
".",
"safeGetterValues",
")",
"{",
"propertiesValues",
"=",
"propertiesValues",
".",
"concat",
"(",
"Object",
".",
"values",
"(",
"grip",
".",
"preview",
".",
"safeGetterValues",
")",
".",
"map",
"(",
"property",
"=>",
"property",
".",
"getterValue",
"||",
"property",
")",
")",
";",
"}",
"return",
"propertiesValues",
";",
"}",
"return",
"[",
"]",
";",
"}"
] | Get preview items from a Grip.
@param {Object} Grip from which we want the preview items
@return {Array} Array of the preview items of the grip, or an empty array
if the grip does not have preview items | [
"Get",
"preview",
"items",
"from",
"a",
"Grip",
"."
] | a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f | https://github.com/firefox-devtools/debugger/blob/a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f/packages/devtools-reps/src/reps/rep-utils.js#L340-L399 |
6,369 | firefox-devtools/debugger | packages/devtools-reps/src/reps/rep-utils.js | getGripType | function getGripType(object, noGrip) {
if (noGrip || Object(object) !== object) {
return typeof object;
}
if (object.type === "object") {
return object.class;
}
return object.type;
} | javascript | function getGripType(object, noGrip) {
if (noGrip || Object(object) !== object) {
return typeof object;
}
if (object.type === "object") {
return object.class;
}
return object.type;
} | [
"function",
"getGripType",
"(",
"object",
",",
"noGrip",
")",
"{",
"if",
"(",
"noGrip",
"||",
"Object",
"(",
"object",
")",
"!==",
"object",
")",
"{",
"return",
"typeof",
"object",
";",
"}",
"if",
"(",
"object",
".",
"type",
"===",
"\"object\"",
")",
"{",
"return",
"object",
".",
"class",
";",
"}",
"return",
"object",
".",
"type",
";",
"}"
] | Get the type of an object.
@param {Object} Grip from which we want the type.
@param {boolean} noGrip true if the object is not a grip.
@return {boolean} | [
"Get",
"the",
"type",
"of",
"an",
"object",
"."
] | a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f | https://github.com/firefox-devtools/debugger/blob/a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f/packages/devtools-reps/src/reps/rep-utils.js#L408-L416 |
6,370 | firefox-devtools/debugger | packages/devtools-reps/src/reps/rep-utils.js | isURL | function isURL(token) {
try {
if (!validProtocols.test(token)) {
return false;
}
new URL(token);
return true;
} catch (e) {
return false;
}
} | javascript | function isURL(token) {
try {
if (!validProtocols.test(token)) {
return false;
}
new URL(token);
return true;
} catch (e) {
return false;
}
} | [
"function",
"isURL",
"(",
"token",
")",
"{",
"try",
"{",
"if",
"(",
"!",
"validProtocols",
".",
"test",
"(",
"token",
")",
")",
"{",
"return",
"false",
";",
"}",
"new",
"URL",
"(",
"token",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"return",
"false",
";",
"}",
"}"
] | Determines whether a string token is a valid URL.
@param string token
The token.
@return boolean
Whether the token is a URL. | [
"Determines",
"whether",
"a",
"string",
"token",
"is",
"a",
"valid",
"URL",
"."
] | a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f | https://github.com/firefox-devtools/debugger/blob/a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f/packages/devtools-reps/src/reps/rep-utils.js#L443-L453 |
6,371 | firefox-devtools/debugger | packages/devtools-reps/src/reps/rep-utils.js | interleave | function interleave(items, char) {
return items.reduce((res, item, index) => {
if (index !== items.length - 1) {
return res.concat(item, char);
}
return res.concat(item);
}, []);
} | javascript | function interleave(items, char) {
return items.reduce((res, item, index) => {
if (index !== items.length - 1) {
return res.concat(item, char);
}
return res.concat(item);
}, []);
} | [
"function",
"interleave",
"(",
"items",
",",
"char",
")",
"{",
"return",
"items",
".",
"reduce",
"(",
"(",
"res",
",",
"item",
",",
"index",
")",
"=>",
"{",
"if",
"(",
"index",
"!==",
"items",
".",
"length",
"-",
"1",
")",
"{",
"return",
"res",
".",
"concat",
"(",
"item",
",",
"char",
")",
";",
"}",
"return",
"res",
".",
"concat",
"(",
"item",
")",
";",
"}",
",",
"[",
"]",
")",
";",
"}"
] | Returns new array in which `char` are interleaved between the original items.
@param {Array} items
@param {String} char
@returns Array | [
"Returns",
"new",
"array",
"in",
"which",
"char",
"are",
"interleaved",
"between",
"the",
"original",
"items",
"."
] | a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f | https://github.com/firefox-devtools/debugger/blob/a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f/packages/devtools-reps/src/reps/rep-utils.js#L462-L469 |
6,372 | firefox-devtools/debugger | src/utils/pause/frames/annotateFrames.js | getBabelFrameIndexes | function getBabelFrameIndexes(frames) {
const startIndexes = frames.reduce((accumulator, frame, index) => {
if (
getFrameUrl(frame).match(/regenerator-runtime/i) &&
frame.displayName === "tryCatch"
) {
return [...accumulator, index];
}
return accumulator;
}, []);
const endIndexes = frames.reduce((accumulator, frame, index) => {
if (
getFrameUrl(frame).match(/_microtask/i) &&
frame.displayName === "flush"
) {
return [...accumulator, index];
}
if (frame.displayName === "_asyncToGenerator/<") {
return [...accumulator, index + 1];
}
return accumulator;
}, []);
if (startIndexes.length != endIndexes.length || startIndexes.length === 0) {
return frames;
}
// Receives an array of start and end index tuples and returns
// an array of async call stack index ranges.
// e.g. [[1,3], [5,7]] => [[1,2,3], [5,6,7]]
// $FlowIgnore
return flatMap(zip(startIndexes, endIndexes), ([startIndex, endIndex]) =>
range(startIndex, endIndex + 1)
);
} | javascript | function getBabelFrameIndexes(frames) {
const startIndexes = frames.reduce((accumulator, frame, index) => {
if (
getFrameUrl(frame).match(/regenerator-runtime/i) &&
frame.displayName === "tryCatch"
) {
return [...accumulator, index];
}
return accumulator;
}, []);
const endIndexes = frames.reduce((accumulator, frame, index) => {
if (
getFrameUrl(frame).match(/_microtask/i) &&
frame.displayName === "flush"
) {
return [...accumulator, index];
}
if (frame.displayName === "_asyncToGenerator/<") {
return [...accumulator, index + 1];
}
return accumulator;
}, []);
if (startIndexes.length != endIndexes.length || startIndexes.length === 0) {
return frames;
}
// Receives an array of start and end index tuples and returns
// an array of async call stack index ranges.
// e.g. [[1,3], [5,7]] => [[1,2,3], [5,6,7]]
// $FlowIgnore
return flatMap(zip(startIndexes, endIndexes), ([startIndex, endIndex]) =>
range(startIndex, endIndex + 1)
);
} | [
"function",
"getBabelFrameIndexes",
"(",
"frames",
")",
"{",
"const",
"startIndexes",
"=",
"frames",
".",
"reduce",
"(",
"(",
"accumulator",
",",
"frame",
",",
"index",
")",
"=>",
"{",
"if",
"(",
"getFrameUrl",
"(",
"frame",
")",
".",
"match",
"(",
"/",
"regenerator-runtime",
"/",
"i",
")",
"&&",
"frame",
".",
"displayName",
"===",
"\"tryCatch\"",
")",
"{",
"return",
"[",
"...",
"accumulator",
",",
"index",
"]",
";",
"}",
"return",
"accumulator",
";",
"}",
",",
"[",
"]",
")",
";",
"const",
"endIndexes",
"=",
"frames",
".",
"reduce",
"(",
"(",
"accumulator",
",",
"frame",
",",
"index",
")",
"=>",
"{",
"if",
"(",
"getFrameUrl",
"(",
"frame",
")",
".",
"match",
"(",
"/",
"_microtask",
"/",
"i",
")",
"&&",
"frame",
".",
"displayName",
"===",
"\"flush\"",
")",
"{",
"return",
"[",
"...",
"accumulator",
",",
"index",
"]",
";",
"}",
"if",
"(",
"frame",
".",
"displayName",
"===",
"\"_asyncToGenerator/<\"",
")",
"{",
"return",
"[",
"...",
"accumulator",
",",
"index",
"+",
"1",
"]",
";",
"}",
"return",
"accumulator",
";",
"}",
",",
"[",
"]",
")",
";",
"if",
"(",
"startIndexes",
".",
"length",
"!=",
"endIndexes",
".",
"length",
"||",
"startIndexes",
".",
"length",
"===",
"0",
")",
"{",
"return",
"frames",
";",
"}",
"// Receives an array of start and end index tuples and returns",
"// an array of async call stack index ranges.",
"// e.g. [[1,3], [5,7]] => [[1,2,3], [5,6,7]]",
"// $FlowIgnore",
"return",
"flatMap",
"(",
"zip",
"(",
"startIndexes",
",",
"endIndexes",
")",
",",
"(",
"[",
"startIndex",
",",
"endIndex",
"]",
")",
"=>",
"range",
"(",
"startIndex",
",",
"endIndex",
"+",
"1",
")",
")",
";",
"}"
] | Receives an array of frames and looks for babel async call stack groups. | [
"Receives",
"an",
"array",
"of",
"frames",
"and",
"looks",
"for",
"babel",
"async",
"call",
"stack",
"groups",
"."
] | a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f | https://github.com/firefox-devtools/debugger/blob/a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f/src/utils/pause/frames/annotateFrames.js#L46-L81 |
6,373 | firefox-devtools/debugger | packages/devtools-reps/src/reps/error.js | parseStackString | function parseStackString(stack) {
const res = [];
if (!stack) {
return res;
}
const isStacktraceALongString = isLongString(stack);
const stackString = isStacktraceALongString ? stack.initial : stack;
stackString.split("\n").forEach((frame, index, frames) => {
if (!frame) {
// Skip any blank lines
return;
}
// If the stacktrace is a longString, don't include the last frame in the
// array, since it is certainly incomplete.
// Can be removed when https://bugzilla.mozilla.org/show_bug.cgi?id=1448833
// is fixed.
if (isStacktraceALongString && index === frames.length - 1) {
return;
}
let functionName;
let location;
// Given the input: "functionName@scriptLocation:2:100"
// Result: [
// "functionName@scriptLocation:2:100",
// "functionName",
// "scriptLocation:2:100"
// ]
const result = frame.match(/^(.*)@(.*)$/);
if (result && result.length === 3) {
functionName = result[1];
// If the resource was loaded by base-loader.js, the location looks like:
// resource://devtools/shared/base-loader.js -> resource://path/to/file.js .
// What's needed is only the last part after " -> ".
location = result[2].split(" -> ").pop();
}
if (!functionName) {
functionName = "<anonymous>";
}
// Given the input: "scriptLocation:2:100"
// Result:
// ["scriptLocation:2:100", "scriptLocation", "2", "100"]
const locationParts = location.match(/^(.*):(\d+):(\d+)$/);
if (location && locationParts) {
const [, filename, line, column] = locationParts;
res.push({
filename,
functionName,
location,
columnNumber: Number(column),
lineNumber: Number(line)
});
}
});
return res;
} | javascript | function parseStackString(stack) {
const res = [];
if (!stack) {
return res;
}
const isStacktraceALongString = isLongString(stack);
const stackString = isStacktraceALongString ? stack.initial : stack;
stackString.split("\n").forEach((frame, index, frames) => {
if (!frame) {
// Skip any blank lines
return;
}
// If the stacktrace is a longString, don't include the last frame in the
// array, since it is certainly incomplete.
// Can be removed when https://bugzilla.mozilla.org/show_bug.cgi?id=1448833
// is fixed.
if (isStacktraceALongString && index === frames.length - 1) {
return;
}
let functionName;
let location;
// Given the input: "functionName@scriptLocation:2:100"
// Result: [
// "functionName@scriptLocation:2:100",
// "functionName",
// "scriptLocation:2:100"
// ]
const result = frame.match(/^(.*)@(.*)$/);
if (result && result.length === 3) {
functionName = result[1];
// If the resource was loaded by base-loader.js, the location looks like:
// resource://devtools/shared/base-loader.js -> resource://path/to/file.js .
// What's needed is only the last part after " -> ".
location = result[2].split(" -> ").pop();
}
if (!functionName) {
functionName = "<anonymous>";
}
// Given the input: "scriptLocation:2:100"
// Result:
// ["scriptLocation:2:100", "scriptLocation", "2", "100"]
const locationParts = location.match(/^(.*):(\d+):(\d+)$/);
if (location && locationParts) {
const [, filename, line, column] = locationParts;
res.push({
filename,
functionName,
location,
columnNumber: Number(column),
lineNumber: Number(line)
});
}
});
return res;
} | [
"function",
"parseStackString",
"(",
"stack",
")",
"{",
"const",
"res",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"stack",
")",
"{",
"return",
"res",
";",
"}",
"const",
"isStacktraceALongString",
"=",
"isLongString",
"(",
"stack",
")",
";",
"const",
"stackString",
"=",
"isStacktraceALongString",
"?",
"stack",
".",
"initial",
":",
"stack",
";",
"stackString",
".",
"split",
"(",
"\"\\n\"",
")",
".",
"forEach",
"(",
"(",
"frame",
",",
"index",
",",
"frames",
")",
"=>",
"{",
"if",
"(",
"!",
"frame",
")",
"{",
"// Skip any blank lines",
"return",
";",
"}",
"// If the stacktrace is a longString, don't include the last frame in the",
"// array, since it is certainly incomplete.",
"// Can be removed when https://bugzilla.mozilla.org/show_bug.cgi?id=1448833",
"// is fixed.",
"if",
"(",
"isStacktraceALongString",
"&&",
"index",
"===",
"frames",
".",
"length",
"-",
"1",
")",
"{",
"return",
";",
"}",
"let",
"functionName",
";",
"let",
"location",
";",
"// Given the input: \"functionName@scriptLocation:2:100\"",
"// Result: [",
"// \"functionName@scriptLocation:2:100\",",
"// \"functionName\",",
"// \"scriptLocation:2:100\"",
"// ]",
"const",
"result",
"=",
"frame",
".",
"match",
"(",
"/",
"^(.*)@(.*)$",
"/",
")",
";",
"if",
"(",
"result",
"&&",
"result",
".",
"length",
"===",
"3",
")",
"{",
"functionName",
"=",
"result",
"[",
"1",
"]",
";",
"// If the resource was loaded by base-loader.js, the location looks like:",
"// resource://devtools/shared/base-loader.js -> resource://path/to/file.js .",
"// What's needed is only the last part after \" -> \".",
"location",
"=",
"result",
"[",
"2",
"]",
".",
"split",
"(",
"\" -> \"",
")",
".",
"pop",
"(",
")",
";",
"}",
"if",
"(",
"!",
"functionName",
")",
"{",
"functionName",
"=",
"\"<anonymous>\"",
";",
"}",
"// Given the input: \"scriptLocation:2:100\"",
"// Result:",
"// [\"scriptLocation:2:100\", \"scriptLocation\", \"2\", \"100\"]",
"const",
"locationParts",
"=",
"location",
".",
"match",
"(",
"/",
"^(.*):(\\d+):(\\d+)$",
"/",
")",
";",
"if",
"(",
"location",
"&&",
"locationParts",
")",
"{",
"const",
"[",
",",
"filename",
",",
"line",
",",
"column",
"]",
"=",
"locationParts",
";",
"res",
".",
"push",
"(",
"{",
"filename",
",",
"functionName",
",",
"location",
",",
"columnNumber",
":",
"Number",
"(",
"column",
")",
",",
"lineNumber",
":",
"Number",
"(",
"line",
")",
"}",
")",
";",
"}",
"}",
")",
";",
"return",
"res",
";",
"}"
] | Parse a string that should represent a stack trace and returns an array of
the frames. The shape of the frames are extremely important as they can then
be processed here or in the toolbox by other components.
@param {String} stack
@returns {Array} Array of frames, which are object with the following shape:
- {String} filename
- {String} functionName
- {String} location
- {Number} columnNumber
- {Number} lineNumber | [
"Parse",
"a",
"string",
"that",
"should",
"represent",
"a",
"stack",
"trace",
"and",
"returns",
"an",
"array",
"of",
"the",
"frames",
".",
"The",
"shape",
"of",
"the",
"frames",
"are",
"extremely",
"important",
"as",
"they",
"can",
"then",
"be",
"processed",
"here",
"or",
"in",
"the",
"toolbox",
"by",
"other",
"components",
"."
] | a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f | https://github.com/firefox-devtools/debugger/blob/a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f/packages/devtools-reps/src/reps/error.js#L165-L229 |
6,374 | firefox-devtools/debugger | src/utils/fromJS.js | hasOwnProperty | function hasOwnProperty(value, key) {
if (value.hasOwnProperty && isFunction(value.hasOwnProperty)) {
return value.hasOwnProperty(key);
}
if (value.prototype && value.prototype.hasOwnProperty) {
return value.prototype.hasOwnProperty(key);
}
return false;
} | javascript | function hasOwnProperty(value, key) {
if (value.hasOwnProperty && isFunction(value.hasOwnProperty)) {
return value.hasOwnProperty(key);
}
if (value.prototype && value.prototype.hasOwnProperty) {
return value.prototype.hasOwnProperty(key);
}
return false;
} | [
"function",
"hasOwnProperty",
"(",
"value",
",",
"key",
")",
"{",
"if",
"(",
"value",
".",
"hasOwnProperty",
"&&",
"isFunction",
"(",
"value",
".",
"hasOwnProperty",
")",
")",
"{",
"return",
"value",
".",
"hasOwnProperty",
"(",
"key",
")",
";",
"}",
"if",
"(",
"value",
".",
"prototype",
"&&",
"value",
".",
"prototype",
".",
"hasOwnProperty",
")",
"{",
"return",
"value",
".",
"prototype",
".",
"hasOwnProperty",
"(",
"key",
")",
";",
"}",
"return",
"false",
";",
"}"
] | hasOwnProperty is defensive because it is possible that the object that we're creating a map for has a `hasOwnProperty` field | [
"hasOwnProperty",
"is",
"defensive",
"because",
"it",
"is",
"possible",
"that",
"the",
"object",
"that",
"we",
"re",
"creating",
"a",
"map",
"for",
"has",
"a",
"hasOwnProperty",
"field"
] | a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f | https://github.com/firefox-devtools/debugger/blob/a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f/src/utils/fromJS.js#L18-L28 |
6,375 | firefox-devtools/debugger | src/utils/pause/frames/collapseFrames.js | addGroupToList | function addGroupToList(group, list) {
if (!group) {
return list;
}
if (group.length > 1) {
list.push(group);
} else {
list = list.concat(group);
}
return list;
} | javascript | function addGroupToList(group, list) {
if (!group) {
return list;
}
if (group.length > 1) {
list.push(group);
} else {
list = list.concat(group);
}
return list;
} | [
"function",
"addGroupToList",
"(",
"group",
",",
"list",
")",
"{",
"if",
"(",
"!",
"group",
")",
"{",
"return",
"list",
";",
"}",
"if",
"(",
"group",
".",
"length",
">",
"1",
")",
"{",
"list",
".",
"push",
"(",
"group",
")",
";",
"}",
"else",
"{",
"list",
"=",
"list",
".",
"concat",
"(",
"group",
")",
";",
"}",
"return",
"list",
";",
"}"
] | We collapse groups of one so that user frames are not in a group of one | [
"We",
"collapse",
"groups",
"of",
"one",
"so",
"that",
"user",
"frames",
"are",
"not",
"in",
"a",
"group",
"of",
"one"
] | a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f | https://github.com/firefox-devtools/debugger/blob/a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f/src/utils/pause/frames/collapseFrames.js#L33-L45 |
6,376 | firefox-devtools/debugger | packages/devtools-reps/src/reps/grip-map.js | getEntries | function getEntries(props, entries, indexes) {
const { onDOMNodeMouseOver, onDOMNodeMouseOut, onInspectIconClick } = props;
// Make indexes ordered by ascending.
indexes.sort(function(a, b) {
return a - b;
});
return indexes.map((index, i) => {
const [key, entryValue] = entries[index];
const value =
entryValue.value !== undefined ? entryValue.value : entryValue;
return PropRep({
name: key,
equal: " \u2192 ",
object: value,
mode: MODE.TINY,
onDOMNodeMouseOver,
onDOMNodeMouseOut,
onInspectIconClick
});
});
} | javascript | function getEntries(props, entries, indexes) {
const { onDOMNodeMouseOver, onDOMNodeMouseOut, onInspectIconClick } = props;
// Make indexes ordered by ascending.
indexes.sort(function(a, b) {
return a - b;
});
return indexes.map((index, i) => {
const [key, entryValue] = entries[index];
const value =
entryValue.value !== undefined ? entryValue.value : entryValue;
return PropRep({
name: key,
equal: " \u2192 ",
object: value,
mode: MODE.TINY,
onDOMNodeMouseOver,
onDOMNodeMouseOut,
onInspectIconClick
});
});
} | [
"function",
"getEntries",
"(",
"props",
",",
"entries",
",",
"indexes",
")",
"{",
"const",
"{",
"onDOMNodeMouseOver",
",",
"onDOMNodeMouseOut",
",",
"onInspectIconClick",
"}",
"=",
"props",
";",
"// Make indexes ordered by ascending.",
"indexes",
".",
"sort",
"(",
"function",
"(",
"a",
",",
"b",
")",
"{",
"return",
"a",
"-",
"b",
";",
"}",
")",
";",
"return",
"indexes",
".",
"map",
"(",
"(",
"index",
",",
"i",
")",
"=>",
"{",
"const",
"[",
"key",
",",
"entryValue",
"]",
"=",
"entries",
"[",
"index",
"]",
";",
"const",
"value",
"=",
"entryValue",
".",
"value",
"!==",
"undefined",
"?",
"entryValue",
".",
"value",
":",
"entryValue",
";",
"return",
"PropRep",
"(",
"{",
"name",
":",
"key",
",",
"equal",
":",
"\" \\u2192 \"",
",",
"object",
":",
"value",
",",
"mode",
":",
"MODE",
".",
"TINY",
",",
"onDOMNodeMouseOver",
",",
"onDOMNodeMouseOut",
",",
"onInspectIconClick",
"}",
")",
";",
"}",
")",
";",
"}"
] | Get entries ordered by index.
@param {Object} props Component props.
@param {Array} entries Entries array.
@param {Array} indexes Indexes of entries.
@return {Array} Array of PropRep. | [
"Get",
"entries",
"ordered",
"by",
"index",
"."
] | a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f | https://github.com/firefox-devtools/debugger/blob/a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f/packages/devtools-reps/src/reps/grip-map.js#L141-L164 |
6,377 | firefox-devtools/debugger | packages/devtools-reps/src/reps/grip-map.js | getEntriesIndexes | function getEntriesIndexes(entries, max, filter) {
return entries.reduce((indexes, [key, entry], i) => {
if (indexes.length < max) {
const value = entry && entry.value !== undefined ? entry.value : entry;
// Type is specified in grip's "class" field and for primitive
// values use typeof.
const type = (value && value.class
? value.class
: typeof value
).toLowerCase();
if (filter(type, value, key)) {
indexes.push(i);
}
}
return indexes;
}, []);
} | javascript | function getEntriesIndexes(entries, max, filter) {
return entries.reduce((indexes, [key, entry], i) => {
if (indexes.length < max) {
const value = entry && entry.value !== undefined ? entry.value : entry;
// Type is specified in grip's "class" field and for primitive
// values use typeof.
const type = (value && value.class
? value.class
: typeof value
).toLowerCase();
if (filter(type, value, key)) {
indexes.push(i);
}
}
return indexes;
}, []);
} | [
"function",
"getEntriesIndexes",
"(",
"entries",
",",
"max",
",",
"filter",
")",
"{",
"return",
"entries",
".",
"reduce",
"(",
"(",
"indexes",
",",
"[",
"key",
",",
"entry",
"]",
",",
"i",
")",
"=>",
"{",
"if",
"(",
"indexes",
".",
"length",
"<",
"max",
")",
"{",
"const",
"value",
"=",
"entry",
"&&",
"entry",
".",
"value",
"!==",
"undefined",
"?",
"entry",
".",
"value",
":",
"entry",
";",
"// Type is specified in grip's \"class\" field and for primitive",
"// values use typeof.",
"const",
"type",
"=",
"(",
"value",
"&&",
"value",
".",
"class",
"?",
"value",
".",
"class",
":",
"typeof",
"value",
")",
".",
"toLowerCase",
"(",
")",
";",
"if",
"(",
"filter",
"(",
"type",
",",
"value",
",",
"key",
")",
")",
"{",
"indexes",
".",
"push",
"(",
"i",
")",
";",
"}",
"}",
"return",
"indexes",
";",
"}",
",",
"[",
"]",
")",
";",
"}"
] | Get the indexes of entries in the map.
@param {Array} entries Entries array.
@param {Number} max The maximum length of indexes array.
@param {Function} filter Filter the entry you want.
@return {Array} Indexes of filtered entries in the map. | [
"Get",
"the",
"indexes",
"of",
"entries",
"in",
"the",
"map",
"."
] | a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f | https://github.com/firefox-devtools/debugger/blob/a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f/packages/devtools-reps/src/reps/grip-map.js#L174-L192 |
6,378 | firefox-devtools/debugger | bin/copy-modules.js | createMozBuildFiles | function createMozBuildFiles() {
const builds = {};
getFiles()
.filter(file => file.match(/.js$/))
.filter(file => {
if (file.match(/\/workers\.js/)) {
return true;
}
// We exclude worker files because they are bundled and we include
// worker/index.js files because are required by the debugger app in order
// to communicate with the worker.
if (file.match(/\/workers/)) {
return file.match(/workers\/(\w|-)*\/index.js/);
}
return !file.match(/(test|types|packages)/)
})
.forEach(file => {
// console.log(file)
let dir = path.dirname(file);
builds[dir] = builds[dir] || { files: [], dirs: [] };
// Add the current file to its parent dir moz.build
builds[dir].files.push(path.basename(file));
// There should be a moz.build in every folder between the root and this
// file. Climb up the folder hierarchy and make sure a each folder of the
// chain is listing in its parent dir moz.build.
while (path.dirname(dir) != ".") {
const parentDir = path.dirname(dir);
const dirName = path.basename(dir);
builds[parentDir] = builds[parentDir] || { files: [], dirs: [] };
if (!builds[parentDir].dirs.includes(dirName)) {
builds[parentDir].dirs.push(dirName);
}
dir = parentDir;
}
});
Object.keys(builds).forEach(build => {
const { files, dirs } = builds[build];
const buildPath = path.join(mcDebuggerPath, build);
shell.mkdir("-p", buildPath);
// Files and folders should be alphabetically sorted in moz.build
const fileStr = files
.sort((a, b) => (a.toLowerCase() < b.toLowerCase() ? -1 : 1))
.map(file => ` '${file}',`)
.join("\n");
const dirStr = dirs
.sort((a, b) => (a.toLowerCase() < b.toLowerCase() ? -1 : 1))
.map(dir => ` '${dir}',`)
.join("\n");
const src = MOZ_BUILD_TEMPLATE.replace("__DIRS__", dirStr).replace(
"__FILES__",
fileStr
);
fs.writeFileSync(path.join(buildPath, "moz.build"), src);
});
} | javascript | function createMozBuildFiles() {
const builds = {};
getFiles()
.filter(file => file.match(/.js$/))
.filter(file => {
if (file.match(/\/workers\.js/)) {
return true;
}
// We exclude worker files because they are bundled and we include
// worker/index.js files because are required by the debugger app in order
// to communicate with the worker.
if (file.match(/\/workers/)) {
return file.match(/workers\/(\w|-)*\/index.js/);
}
return !file.match(/(test|types|packages)/)
})
.forEach(file => {
// console.log(file)
let dir = path.dirname(file);
builds[dir] = builds[dir] || { files: [], dirs: [] };
// Add the current file to its parent dir moz.build
builds[dir].files.push(path.basename(file));
// There should be a moz.build in every folder between the root and this
// file. Climb up the folder hierarchy and make sure a each folder of the
// chain is listing in its parent dir moz.build.
while (path.dirname(dir) != ".") {
const parentDir = path.dirname(dir);
const dirName = path.basename(dir);
builds[parentDir] = builds[parentDir] || { files: [], dirs: [] };
if (!builds[parentDir].dirs.includes(dirName)) {
builds[parentDir].dirs.push(dirName);
}
dir = parentDir;
}
});
Object.keys(builds).forEach(build => {
const { files, dirs } = builds[build];
const buildPath = path.join(mcDebuggerPath, build);
shell.mkdir("-p", buildPath);
// Files and folders should be alphabetically sorted in moz.build
const fileStr = files
.sort((a, b) => (a.toLowerCase() < b.toLowerCase() ? -1 : 1))
.map(file => ` '${file}',`)
.join("\n");
const dirStr = dirs
.sort((a, b) => (a.toLowerCase() < b.toLowerCase() ? -1 : 1))
.map(dir => ` '${dir}',`)
.join("\n");
const src = MOZ_BUILD_TEMPLATE.replace("__DIRS__", dirStr).replace(
"__FILES__",
fileStr
);
fs.writeFileSync(path.join(buildPath, "moz.build"), src);
});
} | [
"function",
"createMozBuildFiles",
"(",
")",
"{",
"const",
"builds",
"=",
"{",
"}",
";",
"getFiles",
"(",
")",
".",
"filter",
"(",
"file",
"=>",
"file",
".",
"match",
"(",
"/",
".js$",
"/",
")",
")",
".",
"filter",
"(",
"file",
"=>",
"{",
"if",
"(",
"file",
".",
"match",
"(",
"/",
"\\/workers\\.js",
"/",
")",
")",
"{",
"return",
"true",
";",
"}",
"// We exclude worker files because they are bundled and we include",
"// worker/index.js files because are required by the debugger app in order",
"// to communicate with the worker.",
"if",
"(",
"file",
".",
"match",
"(",
"/",
"\\/workers",
"/",
")",
")",
"{",
"return",
"file",
".",
"match",
"(",
"/",
"workers\\/(\\w|-)*\\/index.js",
"/",
")",
";",
"}",
"return",
"!",
"file",
".",
"match",
"(",
"/",
"(test|types|packages)",
"/",
")",
"}",
")",
".",
"forEach",
"(",
"file",
"=>",
"{",
"// console.log(file)",
"let",
"dir",
"=",
"path",
".",
"dirname",
"(",
"file",
")",
";",
"builds",
"[",
"dir",
"]",
"=",
"builds",
"[",
"dir",
"]",
"||",
"{",
"files",
":",
"[",
"]",
",",
"dirs",
":",
"[",
"]",
"}",
";",
"// Add the current file to its parent dir moz.build",
"builds",
"[",
"dir",
"]",
".",
"files",
".",
"push",
"(",
"path",
".",
"basename",
"(",
"file",
")",
")",
";",
"// There should be a moz.build in every folder between the root and this",
"// file. Climb up the folder hierarchy and make sure a each folder of the",
"// chain is listing in its parent dir moz.build.",
"while",
"(",
"path",
".",
"dirname",
"(",
"dir",
")",
"!=",
"\".\"",
")",
"{",
"const",
"parentDir",
"=",
"path",
".",
"dirname",
"(",
"dir",
")",
";",
"const",
"dirName",
"=",
"path",
".",
"basename",
"(",
"dir",
")",
";",
"builds",
"[",
"parentDir",
"]",
"=",
"builds",
"[",
"parentDir",
"]",
"||",
"{",
"files",
":",
"[",
"]",
",",
"dirs",
":",
"[",
"]",
"}",
";",
"if",
"(",
"!",
"builds",
"[",
"parentDir",
"]",
".",
"dirs",
".",
"includes",
"(",
"dirName",
")",
")",
"{",
"builds",
"[",
"parentDir",
"]",
".",
"dirs",
".",
"push",
"(",
"dirName",
")",
";",
"}",
"dir",
"=",
"parentDir",
";",
"}",
"}",
")",
";",
"Object",
".",
"keys",
"(",
"builds",
")",
".",
"forEach",
"(",
"build",
"=>",
"{",
"const",
"{",
"files",
",",
"dirs",
"}",
"=",
"builds",
"[",
"build",
"]",
";",
"const",
"buildPath",
"=",
"path",
".",
"join",
"(",
"mcDebuggerPath",
",",
"build",
")",
";",
"shell",
".",
"mkdir",
"(",
"\"-p\"",
",",
"buildPath",
")",
";",
"// Files and folders should be alphabetically sorted in moz.build",
"const",
"fileStr",
"=",
"files",
".",
"sort",
"(",
"(",
"a",
",",
"b",
")",
"=>",
"(",
"a",
".",
"toLowerCase",
"(",
")",
"<",
"b",
".",
"toLowerCase",
"(",
")",
"?",
"-",
"1",
":",
"1",
")",
")",
".",
"map",
"(",
"file",
"=>",
"`",
"${",
"file",
"}",
"`",
")",
".",
"join",
"(",
"\"\\n\"",
")",
";",
"const",
"dirStr",
"=",
"dirs",
".",
"sort",
"(",
"(",
"a",
",",
"b",
")",
"=>",
"(",
"a",
".",
"toLowerCase",
"(",
")",
"<",
"b",
".",
"toLowerCase",
"(",
")",
"?",
"-",
"1",
":",
"1",
")",
")",
".",
"map",
"(",
"dir",
"=>",
"`",
"${",
"dir",
"}",
"`",
")",
".",
"join",
"(",
"\"\\n\"",
")",
";",
"const",
"src",
"=",
"MOZ_BUILD_TEMPLATE",
".",
"replace",
"(",
"\"__DIRS__\"",
",",
"dirStr",
")",
".",
"replace",
"(",
"\"__FILES__\"",
",",
"fileStr",
")",
";",
"fs",
".",
"writeFileSync",
"(",
"path",
".",
"join",
"(",
"buildPath",
",",
"\"moz.build\"",
")",
",",
"src",
")",
";",
"}",
")",
";",
"}"
] | Create the mandatory manifest file that should exist in each folder to
list files and subfolders that should be packaged in Firefox. | [
"Create",
"the",
"mandatory",
"manifest",
"file",
"that",
"should",
"exist",
"in",
"each",
"folder",
"to",
"list",
"files",
"and",
"subfolders",
"that",
"should",
"be",
"packaged",
"in",
"Firefox",
"."
] | a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f | https://github.com/firefox-devtools/debugger/blob/a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f/bin/copy-modules.js#L66-L133 |
6,379 | firefox-devtools/debugger | packages/devtools-reps/src/reps/string.js | getLinkifiedElements | function getLinkifiedElements(text, cropLimit, openLink, isInContentPage) {
const halfLimit = Math.ceil((cropLimit - ELLIPSIS.length) / 2);
const startCropIndex = cropLimit ? halfLimit : null;
const endCropIndex = cropLimit ? text.length - halfLimit : null;
const items = [];
let currentIndex = 0;
let contentStart;
while (true) {
const url = urlRegex.exec(text);
// Pick the regexp with the earlier content; index will always be zero.
if (!url) {
break;
}
contentStart = url.index + url[1].length;
if (contentStart > 0) {
const nonUrlText = text.substring(0, contentStart);
items.push(
getCroppedString(nonUrlText, currentIndex, startCropIndex, endCropIndex)
);
}
// There are some final characters for a URL that are much more likely
// to have been part of the enclosing text rather than the end of the
// URL.
let useUrl = url[2];
const uneat = uneatLastUrlCharsRegex.exec(useUrl);
if (uneat) {
useUrl = useUrl.substring(0, uneat.index);
}
currentIndex = currentIndex + contentStart;
const linkText = getCroppedString(
useUrl,
currentIndex,
startCropIndex,
endCropIndex
);
if (linkText) {
items.push(
a(
{
className: "url",
title: useUrl,
draggable: false,
// Because we don't want the link to be open in the current
// panel's frame, we only render the href attribute if `openLink`
// exists (so we can preventDefault) or if the reps will be
// displayed in content page (e.g. in the JSONViewer).
href: openLink || isInContentPage ? useUrl : null,
onClick: openLink
? e => {
e.preventDefault();
openLink(useUrl, e);
}
: null
},
linkText
)
);
}
currentIndex = currentIndex + useUrl.length;
text = text.substring(url.index + url[1].length + useUrl.length);
}
// Clean up any non-URL text at the end of the source string,
// i.e. not handled in the loop.
if (text.length > 0) {
if (currentIndex < endCropIndex) {
text = getCroppedString(text, currentIndex, startCropIndex, endCropIndex);
}
items.push(text);
}
return items;
} | javascript | function getLinkifiedElements(text, cropLimit, openLink, isInContentPage) {
const halfLimit = Math.ceil((cropLimit - ELLIPSIS.length) / 2);
const startCropIndex = cropLimit ? halfLimit : null;
const endCropIndex = cropLimit ? text.length - halfLimit : null;
const items = [];
let currentIndex = 0;
let contentStart;
while (true) {
const url = urlRegex.exec(text);
// Pick the regexp with the earlier content; index will always be zero.
if (!url) {
break;
}
contentStart = url.index + url[1].length;
if (contentStart > 0) {
const nonUrlText = text.substring(0, contentStart);
items.push(
getCroppedString(nonUrlText, currentIndex, startCropIndex, endCropIndex)
);
}
// There are some final characters for a URL that are much more likely
// to have been part of the enclosing text rather than the end of the
// URL.
let useUrl = url[2];
const uneat = uneatLastUrlCharsRegex.exec(useUrl);
if (uneat) {
useUrl = useUrl.substring(0, uneat.index);
}
currentIndex = currentIndex + contentStart;
const linkText = getCroppedString(
useUrl,
currentIndex,
startCropIndex,
endCropIndex
);
if (linkText) {
items.push(
a(
{
className: "url",
title: useUrl,
draggable: false,
// Because we don't want the link to be open in the current
// panel's frame, we only render the href attribute if `openLink`
// exists (so we can preventDefault) or if the reps will be
// displayed in content page (e.g. in the JSONViewer).
href: openLink || isInContentPage ? useUrl : null,
onClick: openLink
? e => {
e.preventDefault();
openLink(useUrl, e);
}
: null
},
linkText
)
);
}
currentIndex = currentIndex + useUrl.length;
text = text.substring(url.index + url[1].length + useUrl.length);
}
// Clean up any non-URL text at the end of the source string,
// i.e. not handled in the loop.
if (text.length > 0) {
if (currentIndex < endCropIndex) {
text = getCroppedString(text, currentIndex, startCropIndex, endCropIndex);
}
items.push(text);
}
return items;
} | [
"function",
"getLinkifiedElements",
"(",
"text",
",",
"cropLimit",
",",
"openLink",
",",
"isInContentPage",
")",
"{",
"const",
"halfLimit",
"=",
"Math",
".",
"ceil",
"(",
"(",
"cropLimit",
"-",
"ELLIPSIS",
".",
"length",
")",
"/",
"2",
")",
";",
"const",
"startCropIndex",
"=",
"cropLimit",
"?",
"halfLimit",
":",
"null",
";",
"const",
"endCropIndex",
"=",
"cropLimit",
"?",
"text",
".",
"length",
"-",
"halfLimit",
":",
"null",
";",
"const",
"items",
"=",
"[",
"]",
";",
"let",
"currentIndex",
"=",
"0",
";",
"let",
"contentStart",
";",
"while",
"(",
"true",
")",
"{",
"const",
"url",
"=",
"urlRegex",
".",
"exec",
"(",
"text",
")",
";",
"// Pick the regexp with the earlier content; index will always be zero.",
"if",
"(",
"!",
"url",
")",
"{",
"break",
";",
"}",
"contentStart",
"=",
"url",
".",
"index",
"+",
"url",
"[",
"1",
"]",
".",
"length",
";",
"if",
"(",
"contentStart",
">",
"0",
")",
"{",
"const",
"nonUrlText",
"=",
"text",
".",
"substring",
"(",
"0",
",",
"contentStart",
")",
";",
"items",
".",
"push",
"(",
"getCroppedString",
"(",
"nonUrlText",
",",
"currentIndex",
",",
"startCropIndex",
",",
"endCropIndex",
")",
")",
";",
"}",
"// There are some final characters for a URL that are much more likely",
"// to have been part of the enclosing text rather than the end of the",
"// URL.",
"let",
"useUrl",
"=",
"url",
"[",
"2",
"]",
";",
"const",
"uneat",
"=",
"uneatLastUrlCharsRegex",
".",
"exec",
"(",
"useUrl",
")",
";",
"if",
"(",
"uneat",
")",
"{",
"useUrl",
"=",
"useUrl",
".",
"substring",
"(",
"0",
",",
"uneat",
".",
"index",
")",
";",
"}",
"currentIndex",
"=",
"currentIndex",
"+",
"contentStart",
";",
"const",
"linkText",
"=",
"getCroppedString",
"(",
"useUrl",
",",
"currentIndex",
",",
"startCropIndex",
",",
"endCropIndex",
")",
";",
"if",
"(",
"linkText",
")",
"{",
"items",
".",
"push",
"(",
"a",
"(",
"{",
"className",
":",
"\"url\"",
",",
"title",
":",
"useUrl",
",",
"draggable",
":",
"false",
",",
"// Because we don't want the link to be open in the current",
"// panel's frame, we only render the href attribute if `openLink`",
"// exists (so we can preventDefault) or if the reps will be",
"// displayed in content page (e.g. in the JSONViewer).",
"href",
":",
"openLink",
"||",
"isInContentPage",
"?",
"useUrl",
":",
"null",
",",
"onClick",
":",
"openLink",
"?",
"e",
"=>",
"{",
"e",
".",
"preventDefault",
"(",
")",
";",
"openLink",
"(",
"useUrl",
",",
"e",
")",
";",
"}",
":",
"null",
"}",
",",
"linkText",
")",
")",
";",
"}",
"currentIndex",
"=",
"currentIndex",
"+",
"useUrl",
".",
"length",
";",
"text",
"=",
"text",
".",
"substring",
"(",
"url",
".",
"index",
"+",
"url",
"[",
"1",
"]",
".",
"length",
"+",
"useUrl",
".",
"length",
")",
";",
"}",
"// Clean up any non-URL text at the end of the source string,",
"// i.e. not handled in the loop.",
"if",
"(",
"text",
".",
"length",
">",
"0",
")",
"{",
"if",
"(",
"currentIndex",
"<",
"endCropIndex",
")",
"{",
"text",
"=",
"getCroppedString",
"(",
"text",
",",
"currentIndex",
",",
"startCropIndex",
",",
"endCropIndex",
")",
";",
"}",
"items",
".",
"push",
"(",
"text",
")",
";",
"}",
"return",
"items",
";",
"}"
] | Get an array of the elements representing the string, cropped if needed,
with actual links.
@param {String} text: The actual string to linkify.
@param {Integer | null} cropLimit
@param {Function} openLink: Function handling the link opening.
@param {Boolean} isInContentPage: pass true if the reps is rendered in
the content page (e.g. in JSONViewer).
@returns {Array<String|ReactElement>} | [
"Get",
"an",
"array",
"of",
"the",
"elements",
"representing",
"the",
"string",
"cropped",
"if",
"needed",
"with",
"actual",
"links",
"."
] | a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f | https://github.com/firefox-devtools/debugger/blob/a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f/packages/devtools-reps/src/reps/string.js#L182-L259 |
6,380 | firefox-devtools/debugger | packages/devtools-reps/src/reps/string.js | getCroppedString | function getCroppedString(text, offset = 0, startCropIndex, endCropIndex) {
if (!startCropIndex) {
return text;
}
const start = offset;
const end = offset + text.length;
const shouldBeVisible = !(start >= startCropIndex && end <= endCropIndex);
if (!shouldBeVisible) {
return null;
}
const shouldCropEnd = start < startCropIndex && end > startCropIndex;
const shouldCropStart = start < endCropIndex && end > endCropIndex;
if (shouldCropEnd) {
const cutIndex = startCropIndex - start;
return (
text.substring(0, cutIndex) +
ELLIPSIS +
(shouldCropStart ? text.substring(endCropIndex - start) : "")
);
}
if (shouldCropStart) {
// The string should be cropped at the beginning.
const cutIndex = endCropIndex - start;
return text.substring(cutIndex);
}
return text;
} | javascript | function getCroppedString(text, offset = 0, startCropIndex, endCropIndex) {
if (!startCropIndex) {
return text;
}
const start = offset;
const end = offset + text.length;
const shouldBeVisible = !(start >= startCropIndex && end <= endCropIndex);
if (!shouldBeVisible) {
return null;
}
const shouldCropEnd = start < startCropIndex && end > startCropIndex;
const shouldCropStart = start < endCropIndex && end > endCropIndex;
if (shouldCropEnd) {
const cutIndex = startCropIndex - start;
return (
text.substring(0, cutIndex) +
ELLIPSIS +
(shouldCropStart ? text.substring(endCropIndex - start) : "")
);
}
if (shouldCropStart) {
// The string should be cropped at the beginning.
const cutIndex = endCropIndex - start;
return text.substring(cutIndex);
}
return text;
} | [
"function",
"getCroppedString",
"(",
"text",
",",
"offset",
"=",
"0",
",",
"startCropIndex",
",",
"endCropIndex",
")",
"{",
"if",
"(",
"!",
"startCropIndex",
")",
"{",
"return",
"text",
";",
"}",
"const",
"start",
"=",
"offset",
";",
"const",
"end",
"=",
"offset",
"+",
"text",
".",
"length",
";",
"const",
"shouldBeVisible",
"=",
"!",
"(",
"start",
">=",
"startCropIndex",
"&&",
"end",
"<=",
"endCropIndex",
")",
";",
"if",
"(",
"!",
"shouldBeVisible",
")",
"{",
"return",
"null",
";",
"}",
"const",
"shouldCropEnd",
"=",
"start",
"<",
"startCropIndex",
"&&",
"end",
">",
"startCropIndex",
";",
"const",
"shouldCropStart",
"=",
"start",
"<",
"endCropIndex",
"&&",
"end",
">",
"endCropIndex",
";",
"if",
"(",
"shouldCropEnd",
")",
"{",
"const",
"cutIndex",
"=",
"startCropIndex",
"-",
"start",
";",
"return",
"(",
"text",
".",
"substring",
"(",
"0",
",",
"cutIndex",
")",
"+",
"ELLIPSIS",
"+",
"(",
"shouldCropStart",
"?",
"text",
".",
"substring",
"(",
"endCropIndex",
"-",
"start",
")",
":",
"\"\"",
")",
")",
";",
"}",
"if",
"(",
"shouldCropStart",
")",
"{",
"// The string should be cropped at the beginning.",
"const",
"cutIndex",
"=",
"endCropIndex",
"-",
"start",
";",
"return",
"text",
".",
"substring",
"(",
"cutIndex",
")",
";",
"}",
"return",
"text",
";",
"}"
] | Returns a cropped substring given an offset, start and end crop indices in a
parent string.
@param {String} text: The substring to crop.
@param {Integer} offset: The offset corresponding to the index at which
the substring is in the parent string.
@param {Integer|null} startCropIndex: the index where the start of the crop
should happen in the parent string.
@param {Integer|null} endCropIndex: the index where the end of the crop
should happen in the parent string
@returns {String|null} The cropped substring, or null if the text is
completly cropped. | [
"Returns",
"a",
"cropped",
"substring",
"given",
"an",
"offset",
"start",
"and",
"end",
"crop",
"indices",
"in",
"a",
"parent",
"string",
"."
] | a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f | https://github.com/firefox-devtools/debugger/blob/a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f/packages/devtools-reps/src/reps/string.js#L275-L306 |
6,381 | firefox-devtools/debugger | src/workers/parser/mapBindings.js | globalizeDeclaration | function globalizeDeclaration(node, bindings) {
return node.declarations.map(declaration =>
t.expressionStatement(
t.assignmentExpression(
"=",
getAssignmentTarget(declaration.id, bindings),
declaration.init || t.unaryExpression("void", t.numericLiteral(0))
)
)
);
} | javascript | function globalizeDeclaration(node, bindings) {
return node.declarations.map(declaration =>
t.expressionStatement(
t.assignmentExpression(
"=",
getAssignmentTarget(declaration.id, bindings),
declaration.init || t.unaryExpression("void", t.numericLiteral(0))
)
)
);
} | [
"function",
"globalizeDeclaration",
"(",
"node",
",",
"bindings",
")",
"{",
"return",
"node",
".",
"declarations",
".",
"map",
"(",
"declaration",
"=>",
"t",
".",
"expressionStatement",
"(",
"t",
".",
"assignmentExpression",
"(",
"\"=\"",
",",
"getAssignmentTarget",
"(",
"declaration",
".",
"id",
",",
"bindings",
")",
",",
"declaration",
".",
"init",
"||",
"t",
".",
"unaryExpression",
"(",
"\"void\"",
",",
"t",
".",
"numericLiteral",
"(",
"0",
")",
")",
")",
")",
")",
";",
"}"
] | translates new bindings `var a = 3` into `self.a = 3` and existing bindings `var a = 3` into `a = 3` for re-assignments | [
"translates",
"new",
"bindings",
"var",
"a",
"=",
"3",
"into",
"self",
".",
"a",
"=",
"3",
"and",
"existing",
"bindings",
"var",
"a",
"=",
"3",
"into",
"a",
"=",
"3",
"for",
"re",
"-",
"assignments"
] | a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f | https://github.com/firefox-devtools/debugger/blob/a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f/src/workers/parser/mapBindings.js#L57-L67 |
6,382 | firefox-devtools/debugger | src/workers/parser/mapBindings.js | globalizeAssignment | function globalizeAssignment(node, bindings) {
return t.assignmentExpression(
node.operator,
getAssignmentTarget(node.left, bindings),
node.right
);
} | javascript | function globalizeAssignment(node, bindings) {
return t.assignmentExpression(
node.operator,
getAssignmentTarget(node.left, bindings),
node.right
);
} | [
"function",
"globalizeAssignment",
"(",
"node",
",",
"bindings",
")",
"{",
"return",
"t",
".",
"assignmentExpression",
"(",
"node",
".",
"operator",
",",
"getAssignmentTarget",
"(",
"node",
".",
"left",
",",
"bindings",
")",
",",
"node",
".",
"right",
")",
";",
"}"
] | translates new bindings `a = 3` into `self.a = 3` and keeps assignments the same for existing bindings. | [
"translates",
"new",
"bindings",
"a",
"=",
"3",
"into",
"self",
".",
"a",
"=",
"3",
"and",
"keeps",
"assignments",
"the",
"same",
"for",
"existing",
"bindings",
"."
] | a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f | https://github.com/firefox-devtools/debugger/blob/a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f/src/workers/parser/mapBindings.js#L71-L77 |
6,383 | firefox-devtools/debugger | src/actions/breakpoints/syncBreakpoint.js | findExistingBreakpoint | function findExistingBreakpoint(state, generatedLocation) {
const breakpoints = getBreakpointsList(state);
return breakpoints.find(bp => {
return (
bp.generatedLocation.sourceUrl == generatedLocation.sourceUrl &&
bp.generatedLocation.line == generatedLocation.line &&
bp.generatedLocation.column == generatedLocation.column
);
});
} | javascript | function findExistingBreakpoint(state, generatedLocation) {
const breakpoints = getBreakpointsList(state);
return breakpoints.find(bp => {
return (
bp.generatedLocation.sourceUrl == generatedLocation.sourceUrl &&
bp.generatedLocation.line == generatedLocation.line &&
bp.generatedLocation.column == generatedLocation.column
);
});
} | [
"function",
"findExistingBreakpoint",
"(",
"state",
",",
"generatedLocation",
")",
"{",
"const",
"breakpoints",
"=",
"getBreakpointsList",
"(",
"state",
")",
";",
"return",
"breakpoints",
".",
"find",
"(",
"bp",
"=>",
"{",
"return",
"(",
"bp",
".",
"generatedLocation",
".",
"sourceUrl",
"==",
"generatedLocation",
".",
"sourceUrl",
"&&",
"bp",
".",
"generatedLocation",
".",
"line",
"==",
"generatedLocation",
".",
"line",
"&&",
"bp",
".",
"generatedLocation",
".",
"column",
"==",
"generatedLocation",
".",
"column",
")",
";",
"}",
")",
";",
"}"
] | Look for an existing breakpoint at the specified generated location. | [
"Look",
"for",
"an",
"existing",
"breakpoint",
"at",
"the",
"specified",
"generated",
"location",
"."
] | a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f | https://github.com/firefox-devtools/debugger/blob/a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f/src/actions/breakpoints/syncBreakpoint.js#L92-L102 |
6,384 | firefox-devtools/debugger | packages/devtools-reps/src/reps/function.js | getFunctionName | function getFunctionName(grip, props = {}) {
let { functionName } = props;
let name;
if (functionName) {
const end = functionName.length - 1;
functionName =
functionName.startsWith('"') && functionName.endsWith('"')
? functionName.substring(1, end)
: functionName;
}
if (
grip.displayName != undefined &&
functionName != undefined &&
grip.displayName != functionName
) {
name = `${functionName}:${grip.displayName}`;
} else {
name = cleanFunctionName(
grip.userDisplayName ||
grip.displayName ||
grip.name ||
props.functionName ||
""
);
}
return cropString(name, 100);
} | javascript | function getFunctionName(grip, props = {}) {
let { functionName } = props;
let name;
if (functionName) {
const end = functionName.length - 1;
functionName =
functionName.startsWith('"') && functionName.endsWith('"')
? functionName.substring(1, end)
: functionName;
}
if (
grip.displayName != undefined &&
functionName != undefined &&
grip.displayName != functionName
) {
name = `${functionName}:${grip.displayName}`;
} else {
name = cleanFunctionName(
grip.userDisplayName ||
grip.displayName ||
grip.name ||
props.functionName ||
""
);
}
return cropString(name, 100);
} | [
"function",
"getFunctionName",
"(",
"grip",
",",
"props",
"=",
"{",
"}",
")",
"{",
"let",
"{",
"functionName",
"}",
"=",
"props",
";",
"let",
"name",
";",
"if",
"(",
"functionName",
")",
"{",
"const",
"end",
"=",
"functionName",
".",
"length",
"-",
"1",
";",
"functionName",
"=",
"functionName",
".",
"startsWith",
"(",
"'\"'",
")",
"&&",
"functionName",
".",
"endsWith",
"(",
"'\"'",
")",
"?",
"functionName",
".",
"substring",
"(",
"1",
",",
"end",
")",
":",
"functionName",
";",
"}",
"if",
"(",
"grip",
".",
"displayName",
"!=",
"undefined",
"&&",
"functionName",
"!=",
"undefined",
"&&",
"grip",
".",
"displayName",
"!=",
"functionName",
")",
"{",
"name",
"=",
"`",
"${",
"functionName",
"}",
"${",
"grip",
".",
"displayName",
"}",
"`",
";",
"}",
"else",
"{",
"name",
"=",
"cleanFunctionName",
"(",
"grip",
".",
"userDisplayName",
"||",
"grip",
".",
"displayName",
"||",
"grip",
".",
"name",
"||",
"props",
".",
"functionName",
"||",
"\"\"",
")",
";",
"}",
"return",
"cropString",
"(",
"name",
",",
"100",
")",
";",
"}"
] | Returns a ReactElement representing the function name.
@param {Object} grip : Function grip
@param {Object} props: Function rep props | [
"Returns",
"a",
"ReactElement",
"representing",
"the",
"function",
"name",
"."
] | a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f | https://github.com/firefox-devtools/debugger/blob/a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f/packages/devtools-reps/src/reps/function.js#L100-L129 |
6,385 | firefox-devtools/debugger | src/workers/parser/findOutOfScopeLocations.js | getLocation | function getLocation(func) {
const location = { ...func.location };
// if the function has an identifier, start the block after it so the
// identifier is included in the "scope" of its parent
const identifierEnd = get(func, "identifier.loc.end");
if (identifierEnd) {
location.start = identifierEnd;
}
return location;
} | javascript | function getLocation(func) {
const location = { ...func.location };
// if the function has an identifier, start the block after it so the
// identifier is included in the "scope" of its parent
const identifierEnd = get(func, "identifier.loc.end");
if (identifierEnd) {
location.start = identifierEnd;
}
return location;
} | [
"function",
"getLocation",
"(",
"func",
")",
"{",
"const",
"location",
"=",
"{",
"...",
"func",
".",
"location",
"}",
";",
"// if the function has an identifier, start the block after it so the",
"// identifier is included in the \"scope\" of its parent",
"const",
"identifierEnd",
"=",
"get",
"(",
"func",
",",
"\"identifier.loc.end\"",
")",
";",
"if",
"(",
"identifierEnd",
")",
"{",
"location",
".",
"start",
"=",
"identifierEnd",
";",
"}",
"return",
"location",
";",
"}"
] | Returns the location for a given function path. If the path represents a
function declaration, the location will begin after the function identifier
but before the function parameters. | [
"Returns",
"the",
"location",
"for",
"a",
"given",
"function",
"path",
".",
"If",
"the",
"path",
"represents",
"a",
"function",
"declaration",
"the",
"location",
"will",
"begin",
"after",
"the",
"function",
"identifier",
"but",
"before",
"the",
"function",
"parameters",
"."
] | a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f | https://github.com/firefox-devtools/debugger/blob/a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f/src/workers/parser/findOutOfScopeLocations.js#L28-L39 |
6,386 | firefox-devtools/debugger | packages/devtools-reps/src/reps/rep.js | function(props) {
const { object, defaultRep } = props;
const rep = getRep(object, defaultRep, props.noGrip);
return rep(props);
} | javascript | function(props) {
const { object, defaultRep } = props;
const rep = getRep(object, defaultRep, props.noGrip);
return rep(props);
} | [
"function",
"(",
"props",
")",
"{",
"const",
"{",
"object",
",",
"defaultRep",
"}",
"=",
"props",
";",
"const",
"rep",
"=",
"getRep",
"(",
"object",
",",
"defaultRep",
",",
"props",
".",
"noGrip",
")",
";",
"return",
"rep",
"(",
"props",
")",
";",
"}"
] | Generic rep that is used for rendering native JS types or an object.
The right template used for rendering is picked automatically according
to the current value type. The value must be passed in as the 'object'
property. | [
"Generic",
"rep",
"that",
"is",
"used",
"for",
"rendering",
"native",
"JS",
"types",
"or",
"an",
"object",
".",
"The",
"right",
"template",
"used",
"for",
"rendering",
"is",
"picked",
"automatically",
"according",
"to",
"the",
"current",
"value",
"type",
".",
"The",
"value",
"must",
"be",
"passed",
"in",
"as",
"the",
"object",
"property",
"."
] | a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f | https://github.com/firefox-devtools/debugger/blob/a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f/packages/devtools-reps/src/reps/rep.js#L87-L91 |
|
6,387 | firefox-devtools/debugger | packages/devtools-reps/src/reps/rep.js | getRep | function getRep(object, defaultRep = Grip, noGrip = false) {
for (let i = 0; i < reps.length; i++) {
const rep = reps[i];
try {
// supportsObject could return weight (not only true/false
// but a number), which would allow to priorities templates and
// support better extensibility.
if (rep.supportsObject(object, noGrip)) {
return rep.rep;
}
} catch (err) {
console.error(err);
}
}
return defaultRep.rep;
} | javascript | function getRep(object, defaultRep = Grip, noGrip = false) {
for (let i = 0; i < reps.length; i++) {
const rep = reps[i];
try {
// supportsObject could return weight (not only true/false
// but a number), which would allow to priorities templates and
// support better extensibility.
if (rep.supportsObject(object, noGrip)) {
return rep.rep;
}
} catch (err) {
console.error(err);
}
}
return defaultRep.rep;
} | [
"function",
"getRep",
"(",
"object",
",",
"defaultRep",
"=",
"Grip",
",",
"noGrip",
"=",
"false",
")",
"{",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"reps",
".",
"length",
";",
"i",
"++",
")",
"{",
"const",
"rep",
"=",
"reps",
"[",
"i",
"]",
";",
"try",
"{",
"// supportsObject could return weight (not only true/false",
"// but a number), which would allow to priorities templates and",
"// support better extensibility.",
"if",
"(",
"rep",
".",
"supportsObject",
"(",
"object",
",",
"noGrip",
")",
")",
"{",
"return",
"rep",
".",
"rep",
";",
"}",
"}",
"catch",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"err",
")",
";",
"}",
"}",
"return",
"defaultRep",
".",
"rep",
";",
"}"
] | Helpers
Return a rep object that is responsible for rendering given
object.
@param object {Object} Object to be rendered in the UI. This
can be generic JS object as well as a grip (handle to a remote
debuggee object).
@param defaultRep {React.Component} The default template
that should be used to render given object if none is found.
@param noGrip {Boolean} If true, will only check reps not made for remote
objects. | [
"Helpers",
"Return",
"a",
"rep",
"object",
"that",
"is",
"responsible",
"for",
"rendering",
"given",
"object",
"."
] | a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f | https://github.com/firefox-devtools/debugger/blob/a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f/packages/devtools-reps/src/reps/rep.js#L109-L125 |
6,388 | firefox-devtools/debugger | bin/copy-assets.js | lastRelease | function lastRelease() {
const {stdout: branches} = exec(`git branch -a | grep 'origin/release'`)
const releases = branches.
split("\n")
.map(b => b.replace(/remotes\/origin\//, '').trim())
.filter(b => b.match(/^release-(\d+)$/))
const ordered = sortBy(releases, r => parseInt(/\d+/.exec(r)[0], 10) )
return ordered[ordered.length -1];
} | javascript | function lastRelease() {
const {stdout: branches} = exec(`git branch -a | grep 'origin/release'`)
const releases = branches.
split("\n")
.map(b => b.replace(/remotes\/origin\//, '').trim())
.filter(b => b.match(/^release-(\d+)$/))
const ordered = sortBy(releases, r => parseInt(/\d+/.exec(r)[0], 10) )
return ordered[ordered.length -1];
} | [
"function",
"lastRelease",
"(",
")",
"{",
"const",
"{",
"stdout",
":",
"branches",
"}",
"=",
"exec",
"(",
"`",
"`",
")",
"const",
"releases",
"=",
"branches",
".",
"split",
"(",
"\"\\n\"",
")",
".",
"map",
"(",
"b",
"=>",
"b",
".",
"replace",
"(",
"/",
"remotes\\/origin\\/",
"/",
",",
"''",
")",
".",
"trim",
"(",
")",
")",
".",
"filter",
"(",
"b",
"=>",
"b",
".",
"match",
"(",
"/",
"^release-(\\d+)$",
"/",
")",
")",
"const",
"ordered",
"=",
"sortBy",
"(",
"releases",
",",
"r",
"=>",
"parseInt",
"(",
"/",
"\\d+",
"/",
".",
"exec",
"(",
"r",
")",
"[",
"0",
"]",
",",
"10",
")",
")",
"return",
"ordered",
"[",
"ordered",
".",
"length",
"-",
"1",
"]",
";",
"}"
] | searches the git branches for the last release branch | [
"searches",
"the",
"git",
"branches",
"for",
"the",
"last",
"release",
"branch"
] | a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f | https://github.com/firefox-devtools/debugger/blob/a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f/bin/copy-assets.js#L187-L196 |
6,389 | firefox-devtools/debugger | bin/copy-assets.js | updateManifest | function updateManifest() {
const {stdout: branch} = exec(`git rev-parse --abbrev-ref HEAD`)
if (!branch.includes("release")) {
return;
}
console.log("[copy-assets] update assets manifest");
const last = lastRelease();
exec(`git cat-file -p ${last}:assets/module-manifest.json > assets/module-manifest.json`);
} | javascript | function updateManifest() {
const {stdout: branch} = exec(`git rev-parse --abbrev-ref HEAD`)
if (!branch.includes("release")) {
return;
}
console.log("[copy-assets] update assets manifest");
const last = lastRelease();
exec(`git cat-file -p ${last}:assets/module-manifest.json > assets/module-manifest.json`);
} | [
"function",
"updateManifest",
"(",
")",
"{",
"const",
"{",
"stdout",
":",
"branch",
"}",
"=",
"exec",
"(",
"`",
"`",
")",
"if",
"(",
"!",
"branch",
".",
"includes",
"(",
"\"release\"",
")",
")",
"{",
"return",
";",
"}",
"console",
".",
"log",
"(",
"\"[copy-assets] update assets manifest\"",
")",
";",
"const",
"last",
"=",
"lastRelease",
"(",
")",
";",
"exec",
"(",
"`",
"${",
"last",
"}",
"`",
")",
";",
"}"
] | updates the assets manifest with the latest release manifest so that webpack bundles remain largely the same | [
"updates",
"the",
"assets",
"manifest",
"with",
"the",
"latest",
"release",
"manifest",
"so",
"that",
"webpack",
"bundles",
"remain",
"largely",
"the",
"same"
] | a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f | https://github.com/firefox-devtools/debugger/blob/a1cb80a1c9f9b1d9aae463ec188fdc58ea4f8d2f/bin/copy-assets.js#L200-L211 |
6,390 | deepstreamIO/deepstream.io | src/permission/rule-application.js | getRecordUpdateData | function getRecordUpdateData (msg) {
let data
try {
data = JSON.parse(msg.data[2])
} catch (error) {
return error
}
return data
} | javascript | function getRecordUpdateData (msg) {
let data
try {
data = JSON.parse(msg.data[2])
} catch (error) {
return error
}
return data
} | [
"function",
"getRecordUpdateData",
"(",
"msg",
")",
"{",
"let",
"data",
"try",
"{",
"data",
"=",
"JSON",
".",
"parse",
"(",
"msg",
".",
"data",
"[",
"2",
"]",
")",
"}",
"catch",
"(",
"error",
")",
"{",
"return",
"error",
"}",
"return",
"data",
"}"
] | Extracts the data from record update messages
@param {Object} msg a deepstream message
@private
@returns {Object} recordData | [
"Extracts",
"the",
"data",
"from",
"record",
"update",
"messages"
] | 247aea5e49a94f57f72fbac8e2f4dc0cdbbded18 | https://github.com/deepstreamIO/deepstream.io/blob/247aea5e49a94f57f72fbac8e2f4dc0cdbbded18/src/permission/rule-application.js#L428-L438 |
6,391 | deepstreamIO/deepstream.io | src/config/js-yaml-loader.js | setGlobalConfigDirectory | function setGlobalConfigDirectory (argv, filePath) {
const customConfigPath =
argv.c ||
argv.config ||
filePath ||
process.env.DEEPSTREAM_CONFIG_DIRECTORY
const configPath = customConfigPath
? verifyCustomConfigPath(customConfigPath)
: getDefaultConfigPath()
global.deepstreamConfDir = path.dirname(configPath)
return configPath
} | javascript | function setGlobalConfigDirectory (argv, filePath) {
const customConfigPath =
argv.c ||
argv.config ||
filePath ||
process.env.DEEPSTREAM_CONFIG_DIRECTORY
const configPath = customConfigPath
? verifyCustomConfigPath(customConfigPath)
: getDefaultConfigPath()
global.deepstreamConfDir = path.dirname(configPath)
return configPath
} | [
"function",
"setGlobalConfigDirectory",
"(",
"argv",
",",
"filePath",
")",
"{",
"const",
"customConfigPath",
"=",
"argv",
".",
"c",
"||",
"argv",
".",
"config",
"||",
"filePath",
"||",
"process",
".",
"env",
".",
"DEEPSTREAM_CONFIG_DIRECTORY",
"const",
"configPath",
"=",
"customConfigPath",
"?",
"verifyCustomConfigPath",
"(",
"customConfigPath",
")",
":",
"getDefaultConfigPath",
"(",
")",
"global",
".",
"deepstreamConfDir",
"=",
"path",
".",
"dirname",
"(",
"configPath",
")",
"return",
"configPath",
"}"
] | Set the globalConfig prefix that will be used as the directory for ssl, permissions and auth
relative files within the config file | [
"Set",
"the",
"globalConfig",
"prefix",
"that",
"will",
"be",
"used",
"as",
"the",
"directory",
"for",
"ssl",
"permissions",
"and",
"auth",
"relative",
"files",
"within",
"the",
"config",
"file"
] | 247aea5e49a94f57f72fbac8e2f4dc0cdbbded18 | https://github.com/deepstreamIO/deepstream.io/blob/247aea5e49a94f57f72fbac8e2f4dc0cdbbded18/src/config/js-yaml-loader.js#L127-L138 |
6,392 | deepstreamIO/deepstream.io | src/config/js-yaml-loader.js | setGlobalLibDirectory | function setGlobalLibDirectory (argv, config) {
const libDir =
argv.l ||
argv.libDir ||
(config.libDir && fileUtils.lookupConfRequirePath(config.libDir)) ||
process.env.DEEPSTREAM_LIBRARY_DIRECTORY
global.deepstreamLibDir = libDir
} | javascript | function setGlobalLibDirectory (argv, config) {
const libDir =
argv.l ||
argv.libDir ||
(config.libDir && fileUtils.lookupConfRequirePath(config.libDir)) ||
process.env.DEEPSTREAM_LIBRARY_DIRECTORY
global.deepstreamLibDir = libDir
} | [
"function",
"setGlobalLibDirectory",
"(",
"argv",
",",
"config",
")",
"{",
"const",
"libDir",
"=",
"argv",
".",
"l",
"||",
"argv",
".",
"libDir",
"||",
"(",
"config",
".",
"libDir",
"&&",
"fileUtils",
".",
"lookupConfRequirePath",
"(",
"config",
".",
"libDir",
")",
")",
"||",
"process",
".",
"env",
".",
"DEEPSTREAM_LIBRARY_DIRECTORY",
"global",
".",
"deepstreamLibDir",
"=",
"libDir",
"}"
] | Set the globalLib prefix that will be used as the directory for the logger
and plugins within the config file | [
"Set",
"the",
"globalLib",
"prefix",
"that",
"will",
"be",
"used",
"as",
"the",
"directory",
"for",
"the",
"logger",
"and",
"plugins",
"within",
"the",
"config",
"file"
] | 247aea5e49a94f57f72fbac8e2f4dc0cdbbded18 | https://github.com/deepstreamIO/deepstream.io/blob/247aea5e49a94f57f72fbac8e2f4dc0cdbbded18/src/config/js-yaml-loader.js#L144-L151 |
6,393 | deepstreamIO/deepstream.io | src/config/js-yaml-loader.js | extendConfig | function extendConfig (config, argv) {
const cliArgs = {}
let key
for (key in defaultOptions.get()) {
cliArgs[key] = argv[key]
}
if (argv.port) {
overrideEndpointOption('port', argv.port, 'websocket', config)
}
if (argv.host) {
overrideEndpointOption('host', argv.host, 'websocket', config)
}
if (argv.httpPort) {
overrideEndpointOption('port', argv.httpPort, 'http', config)
}
if (argv.httpHost) {
overrideEndpointOption('host', argv.httpHost, 'http', config)
}
return utils.merge({ plugins: {} }, defaultOptions.get(), config, cliArgs)
} | javascript | function extendConfig (config, argv) {
const cliArgs = {}
let key
for (key in defaultOptions.get()) {
cliArgs[key] = argv[key]
}
if (argv.port) {
overrideEndpointOption('port', argv.port, 'websocket', config)
}
if (argv.host) {
overrideEndpointOption('host', argv.host, 'websocket', config)
}
if (argv.httpPort) {
overrideEndpointOption('port', argv.httpPort, 'http', config)
}
if (argv.httpHost) {
overrideEndpointOption('host', argv.httpHost, 'http', config)
}
return utils.merge({ plugins: {} }, defaultOptions.get(), config, cliArgs)
} | [
"function",
"extendConfig",
"(",
"config",
",",
"argv",
")",
"{",
"const",
"cliArgs",
"=",
"{",
"}",
"let",
"key",
"for",
"(",
"key",
"in",
"defaultOptions",
".",
"get",
"(",
")",
")",
"{",
"cliArgs",
"[",
"key",
"]",
"=",
"argv",
"[",
"key",
"]",
"}",
"if",
"(",
"argv",
".",
"port",
")",
"{",
"overrideEndpointOption",
"(",
"'port'",
",",
"argv",
".",
"port",
",",
"'websocket'",
",",
"config",
")",
"}",
"if",
"(",
"argv",
".",
"host",
")",
"{",
"overrideEndpointOption",
"(",
"'host'",
",",
"argv",
".",
"host",
",",
"'websocket'",
",",
"config",
")",
"}",
"if",
"(",
"argv",
".",
"httpPort",
")",
"{",
"overrideEndpointOption",
"(",
"'port'",
",",
"argv",
".",
"httpPort",
",",
"'http'",
",",
"config",
")",
"}",
"if",
"(",
"argv",
".",
"httpHost",
")",
"{",
"overrideEndpointOption",
"(",
"'host'",
",",
"argv",
".",
"httpHost",
",",
"'http'",
",",
"config",
")",
"}",
"return",
"utils",
".",
"merge",
"(",
"{",
"plugins",
":",
"{",
"}",
"}",
",",
"defaultOptions",
".",
"get",
"(",
")",
",",
"config",
",",
"cliArgs",
")",
"}"
] | Augments the basic configuration with command line parameters
and normalizes paths within it
@param {Object} config configuration
@param {Object} argv command line arguments
@param {String} configDir config directory
@private
@returns {Object} extended config | [
"Augments",
"the",
"basic",
"configuration",
"with",
"command",
"line",
"parameters",
"and",
"normalizes",
"paths",
"within",
"it"
] | 247aea5e49a94f57f72fbac8e2f4dc0cdbbded18 | https://github.com/deepstreamIO/deepstream.io/blob/247aea5e49a94f57f72fbac8e2f4dc0cdbbded18/src/config/js-yaml-loader.js#L164-L185 |
6,394 | deepstreamIO/deepstream.io | src/config/js-yaml-loader.js | getDefaultConfigPath | function getDefaultConfigPath () {
let filePath
let i
let k
for (k = 0; k < DEFAULT_CONFIG_DIRS.length; k++) {
for (i = 0; i < SUPPORTED_EXTENSIONS.length; i++) {
filePath = DEFAULT_CONFIG_DIRS[k] + SUPPORTED_EXTENSIONS[i]
if (fileUtils.fileExistsSync(filePath)) {
return filePath
}
}
}
throw new Error('No config file found')
} | javascript | function getDefaultConfigPath () {
let filePath
let i
let k
for (k = 0; k < DEFAULT_CONFIG_DIRS.length; k++) {
for (i = 0; i < SUPPORTED_EXTENSIONS.length; i++) {
filePath = DEFAULT_CONFIG_DIRS[k] + SUPPORTED_EXTENSIONS[i]
if (fileUtils.fileExistsSync(filePath)) {
return filePath
}
}
}
throw new Error('No config file found')
} | [
"function",
"getDefaultConfigPath",
"(",
")",
"{",
"let",
"filePath",
"let",
"i",
"let",
"k",
"for",
"(",
"k",
"=",
"0",
";",
"k",
"<",
"DEFAULT_CONFIG_DIRS",
".",
"length",
";",
"k",
"++",
")",
"{",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"SUPPORTED_EXTENSIONS",
".",
"length",
";",
"i",
"++",
")",
"{",
"filePath",
"=",
"DEFAULT_CONFIG_DIRS",
"[",
"k",
"]",
"+",
"SUPPORTED_EXTENSIONS",
"[",
"i",
"]",
"if",
"(",
"fileUtils",
".",
"fileExistsSync",
"(",
"filePath",
")",
")",
"{",
"return",
"filePath",
"}",
"}",
"}",
"throw",
"new",
"Error",
"(",
"'No config file found'",
")",
"}"
] | Fallback if no config path is specified. Will attempt to load the file from the default directory
@private
@returns {String} filePath | [
"Fallback",
"if",
"no",
"config",
"path",
"is",
"specified",
".",
"Will",
"attempt",
"to",
"load",
"the",
"file",
"from",
"the",
"default",
"directory"
] | 247aea5e49a94f57f72fbac8e2f4dc0cdbbded18 | https://github.com/deepstreamIO/deepstream.io/blob/247aea5e49a94f57f72fbac8e2f4dc0cdbbded18/src/config/js-yaml-loader.js#L220-L235 |
6,395 | deepstreamIO/deepstream.io | src/config/js-yaml-loader.js | replaceEnvironmentVariables | function replaceEnvironmentVariables (fileContent) {
const environmentVariable = new RegExp(/\${([^}]+)}/g)
// eslint-disable-next-line
fileContent = fileContent.replace(environmentVariable, (a, b) => process.env[b] || '')
return fileContent
} | javascript | function replaceEnvironmentVariables (fileContent) {
const environmentVariable = new RegExp(/\${([^}]+)}/g)
// eslint-disable-next-line
fileContent = fileContent.replace(environmentVariable, (a, b) => process.env[b] || '')
return fileContent
} | [
"function",
"replaceEnvironmentVariables",
"(",
"fileContent",
")",
"{",
"const",
"environmentVariable",
"=",
"new",
"RegExp",
"(",
"/",
"\\${([^}]+)}",
"/",
"g",
")",
"// eslint-disable-next-line",
"fileContent",
"=",
"fileContent",
".",
"replace",
"(",
"environmentVariable",
",",
"(",
"a",
",",
"b",
")",
"=>",
"process",
".",
"env",
"[",
"b",
"]",
"||",
"''",
")",
"return",
"fileContent",
"}"
] | Handle the introduction of global enviroment variables within
the yml file, allowing value substitution.
For example:
```
host: $HOST_NAME
port: $HOST_PORT
```
@param {String} fileContent The loaded yml file
@private
@returns {void} | [
"Handle",
"the",
"introduction",
"of",
"global",
"enviroment",
"variables",
"within",
"the",
"yml",
"file",
"allowing",
"value",
"substitution",
"."
] | 247aea5e49a94f57f72fbac8e2f4dc0cdbbded18 | https://github.com/deepstreamIO/deepstream.io/blob/247aea5e49a94f57f72fbac8e2f4dc0cdbbded18/src/config/js-yaml-loader.js#L252-L257 |
6,396 | deepstreamIO/deepstream.io | bin/deepstream-start.js | parseLogLevel | function parseLogLevel (logLevel) {
if (!/debug|info|warn|error|off/i.test(logLevel)) {
console.error('Log level must be one of the following (debug|info|warn|error|off)')
process.exit(1)
}
return logLevel.toUpperCase()
} | javascript | function parseLogLevel (logLevel) {
if (!/debug|info|warn|error|off/i.test(logLevel)) {
console.error('Log level must be one of the following (debug|info|warn|error|off)')
process.exit(1)
}
return logLevel.toUpperCase()
} | [
"function",
"parseLogLevel",
"(",
"logLevel",
")",
"{",
"if",
"(",
"!",
"/",
"debug|info|warn|error|off",
"/",
"i",
".",
"test",
"(",
"logLevel",
")",
")",
"{",
"console",
".",
"error",
"(",
"'Log level must be one of the following (debug|info|warn|error|off)'",
")",
"process",
".",
"exit",
"(",
"1",
")",
"}",
"return",
"logLevel",
".",
"toUpperCase",
"(",
")",
"}"
] | Used by commander to parse the log level and fails if invalid
value is passed in
@private | [
"Used",
"by",
"commander",
"to",
"parse",
"the",
"log",
"level",
"and",
"fails",
"if",
"invalid",
"value",
"is",
"passed",
"in"
] | 247aea5e49a94f57f72fbac8e2f4dc0cdbbded18 | https://github.com/deepstreamIO/deepstream.io/blob/247aea5e49a94f57f72fbac8e2f4dc0cdbbded18/bin/deepstream-start.js#L54-L60 |
6,397 | deepstreamIO/deepstream.io | bin/deepstream-start.js | parseInteger | function parseInteger (name, port) {
const portNumber = Number(port)
if (!portNumber) {
console.error(`Provided ${name} must be an integer`)
process.exit(1)
}
return portNumber
} | javascript | function parseInteger (name, port) {
const portNumber = Number(port)
if (!portNumber) {
console.error(`Provided ${name} must be an integer`)
process.exit(1)
}
return portNumber
} | [
"function",
"parseInteger",
"(",
"name",
",",
"port",
")",
"{",
"const",
"portNumber",
"=",
"Number",
"(",
"port",
")",
"if",
"(",
"!",
"portNumber",
")",
"{",
"console",
".",
"error",
"(",
"`",
"${",
"name",
"}",
"`",
")",
"process",
".",
"exit",
"(",
"1",
")",
"}",
"return",
"portNumber",
"}"
] | Used by commander to parse numbers and fails if invalid
value is passed in
@private | [
"Used",
"by",
"commander",
"to",
"parse",
"numbers",
"and",
"fails",
"if",
"invalid",
"value",
"is",
"passed",
"in"
] | 247aea5e49a94f57f72fbac8e2f4dc0cdbbded18 | https://github.com/deepstreamIO/deepstream.io/blob/247aea5e49a94f57f72fbac8e2f4dc0cdbbded18/bin/deepstream-start.js#L67-L74 |
6,398 | deepstreamIO/deepstream.io | bin/deepstream-start.js | parseBoolean | function parseBoolean (name, enabled) {
let isEnabled
if (typeof enabled === 'undefined' || enabled === 'true') {
isEnabled = true
} else if (typeof enabled !== 'undefined' && enabled === 'false') {
isEnabled = false
} else {
console.error(`Invalid argument for ${name}, please provide true or false`)
process.exit(1)
}
return isEnabled
} | javascript | function parseBoolean (name, enabled) {
let isEnabled
if (typeof enabled === 'undefined' || enabled === 'true') {
isEnabled = true
} else if (typeof enabled !== 'undefined' && enabled === 'false') {
isEnabled = false
} else {
console.error(`Invalid argument for ${name}, please provide true or false`)
process.exit(1)
}
return isEnabled
} | [
"function",
"parseBoolean",
"(",
"name",
",",
"enabled",
")",
"{",
"let",
"isEnabled",
"if",
"(",
"typeof",
"enabled",
"===",
"'undefined'",
"||",
"enabled",
"===",
"'true'",
")",
"{",
"isEnabled",
"=",
"true",
"}",
"else",
"if",
"(",
"typeof",
"enabled",
"!==",
"'undefined'",
"&&",
"enabled",
"===",
"'false'",
")",
"{",
"isEnabled",
"=",
"false",
"}",
"else",
"{",
"console",
".",
"error",
"(",
"`",
"${",
"name",
"}",
"`",
")",
"process",
".",
"exit",
"(",
"1",
")",
"}",
"return",
"isEnabled",
"}"
] | Used by commander to parse boolean and fails if invalid
value is passed in
@private | [
"Used",
"by",
"commander",
"to",
"parse",
"boolean",
"and",
"fails",
"if",
"invalid",
"value",
"is",
"passed",
"in"
] | 247aea5e49a94f57f72fbac8e2f4dc0cdbbded18 | https://github.com/deepstreamIO/deepstream.io/blob/247aea5e49a94f57f72fbac8e2f4dc0cdbbded18/bin/deepstream-start.js#L81-L92 |
6,399 | deepstreamIO/deepstream.io | src/record/record-handler.js | handleForceWriteAcknowledgement | function handleForceWriteAcknowledgement (
socketWrapper, message, cacheResponse, storageResponse, error
) {
if (storageResponse && cacheResponse) {
socketWrapper.sendMessage(RECORD, C.ACTIONS.WRITE_ACKNOWLEDGEMENT, [
message.data[0],
[message.data[1]],
messageBuilder.typed(error)
], true)
}
} | javascript | function handleForceWriteAcknowledgement (
socketWrapper, message, cacheResponse, storageResponse, error
) {
if (storageResponse && cacheResponse) {
socketWrapper.sendMessage(RECORD, C.ACTIONS.WRITE_ACKNOWLEDGEMENT, [
message.data[0],
[message.data[1]],
messageBuilder.typed(error)
], true)
}
} | [
"function",
"handleForceWriteAcknowledgement",
"(",
"socketWrapper",
",",
"message",
",",
"cacheResponse",
",",
"storageResponse",
",",
"error",
")",
"{",
"if",
"(",
"storageResponse",
"&&",
"cacheResponse",
")",
"{",
"socketWrapper",
".",
"sendMessage",
"(",
"RECORD",
",",
"C",
".",
"ACTIONS",
".",
"WRITE_ACKNOWLEDGEMENT",
",",
"[",
"message",
".",
"data",
"[",
"0",
"]",
",",
"[",
"message",
".",
"data",
"[",
"1",
"]",
"]",
",",
"messageBuilder",
".",
"typed",
"(",
"error",
")",
"]",
",",
"true",
")",
"}",
"}"
] | Handles write acknowledgements during a force write.
@param {SocketWrapper} socketWrapper the socket that sent the request
@param {Object} message the update message
@param {Boolean} cacheResponse flag indicating whether the cache has been set
@param {Boolean} storageResponse flag indicating whether the storage layer
has been set
@param {String} error any errors that occurred during writing to cache
and storage
@private
@returns {void} | [
"Handles",
"write",
"acknowledgements",
"during",
"a",
"force",
"write",
"."
] | 247aea5e49a94f57f72fbac8e2f4dc0cdbbded18 | https://github.com/deepstreamIO/deepstream.io/blob/247aea5e49a94f57f72fbac8e2f4dc0cdbbded18/src/record/record-handler.js#L29-L39 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.