repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
list | docstring
stringlengths 4
11.8k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 86
226
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
moay/afterglow
|
vendor/videojs/video.js
|
ErrorDisplay
|
function ErrorDisplay(player, options) {
_classCallCheck(this, ErrorDisplay);
var _this = _possibleConstructorReturn(this, _ModalDialog.call(this, player, options));
_this.on(player, 'error', _this.open);
return _this;
}
|
javascript
|
function ErrorDisplay(player, options) {
_classCallCheck(this, ErrorDisplay);
var _this = _possibleConstructorReturn(this, _ModalDialog.call(this, player, options));
_this.on(player, 'error', _this.open);
return _this;
}
|
[
"function",
"ErrorDisplay",
"(",
"player",
",",
"options",
")",
"{",
"_classCallCheck",
"(",
"this",
",",
"ErrorDisplay",
")",
";",
"var",
"_this",
"=",
"_possibleConstructorReturn",
"(",
"this",
",",
"_ModalDialog",
".",
"call",
"(",
"this",
",",
"player",
",",
"options",
")",
")",
";",
"_this",
".",
"on",
"(",
"player",
",",
"'error'",
",",
"_this",
".",
"open",
")",
";",
"return",
"_this",
";",
"}"
] |
Constructor for error display modal.
@param {Player} player
@param {Object} [options]
|
[
"Constructor",
"for",
"error",
"display",
"modal",
"."
] |
a7fbc889a18188147fcd8418c5d3bb801608b9a7
|
https://github.com/moay/afterglow/blob/a7fbc889a18188147fcd8418c5d3bb801608b9a7/vendor/videojs/video.js#L6060-L6067
|
train
|
moay/afterglow
|
vendor/videojs/video.js
|
ModalDialog
|
function ModalDialog(player, options) {
_classCallCheck(this, ModalDialog);
var _this = _possibleConstructorReturn(this, _Component.call(this, player, options));
_this.opened_ = _this.hasBeenOpened_ = _this.hasBeenFilled_ = false;
_this.closeable(!_this.options_.uncloseable);
_this.content(_this.options_.content);
// Make sure the contentEl is defined AFTER any children are initialized
// because we only want the contents of the modal in the contentEl
// (not the UI elements like the close button).
_this.contentEl_ = Dom.createEl('div', {
className: MODAL_CLASS_NAME + '-content'
}, {
role: 'document'
});
_this.descEl_ = Dom.createEl('p', {
className: MODAL_CLASS_NAME + '-description vjs-offscreen',
id: _this.el().getAttribute('aria-describedby')
});
Dom.textContent(_this.descEl_, _this.description());
_this.el_.appendChild(_this.descEl_);
_this.el_.appendChild(_this.contentEl_);
return _this;
}
|
javascript
|
function ModalDialog(player, options) {
_classCallCheck(this, ModalDialog);
var _this = _possibleConstructorReturn(this, _Component.call(this, player, options));
_this.opened_ = _this.hasBeenOpened_ = _this.hasBeenFilled_ = false;
_this.closeable(!_this.options_.uncloseable);
_this.content(_this.options_.content);
// Make sure the contentEl is defined AFTER any children are initialized
// because we only want the contents of the modal in the contentEl
// (not the UI elements like the close button).
_this.contentEl_ = Dom.createEl('div', {
className: MODAL_CLASS_NAME + '-content'
}, {
role: 'document'
});
_this.descEl_ = Dom.createEl('p', {
className: MODAL_CLASS_NAME + '-description vjs-offscreen',
id: _this.el().getAttribute('aria-describedby')
});
Dom.textContent(_this.descEl_, _this.description());
_this.el_.appendChild(_this.descEl_);
_this.el_.appendChild(_this.contentEl_);
return _this;
}
|
[
"function",
"ModalDialog",
"(",
"player",
",",
"options",
")",
"{",
"_classCallCheck",
"(",
"this",
",",
"ModalDialog",
")",
";",
"var",
"_this",
"=",
"_possibleConstructorReturn",
"(",
"this",
",",
"_Component",
".",
"call",
"(",
"this",
",",
"player",
",",
"options",
")",
")",
";",
"_this",
".",
"opened_",
"=",
"_this",
".",
"hasBeenOpened_",
"=",
"_this",
".",
"hasBeenFilled_",
"=",
"false",
";",
"_this",
".",
"closeable",
"(",
"!",
"_this",
".",
"options_",
".",
"uncloseable",
")",
";",
"_this",
".",
"content",
"(",
"_this",
".",
"options_",
".",
"content",
")",
";",
"// Make sure the contentEl is defined AFTER any children are initialized",
"// because we only want the contents of the modal in the contentEl",
"// (not the UI elements like the close button).",
"_this",
".",
"contentEl_",
"=",
"Dom",
".",
"createEl",
"(",
"'div'",
",",
"{",
"className",
":",
"MODAL_CLASS_NAME",
"+",
"'-content'",
"}",
",",
"{",
"role",
":",
"'document'",
"}",
")",
";",
"_this",
".",
"descEl_",
"=",
"Dom",
".",
"createEl",
"(",
"'p'",
",",
"{",
"className",
":",
"MODAL_CLASS_NAME",
"+",
"'-description vjs-offscreen'",
",",
"id",
":",
"_this",
".",
"el",
"(",
")",
".",
"getAttribute",
"(",
"'aria-describedby'",
")",
"}",
")",
";",
"Dom",
".",
"textContent",
"(",
"_this",
".",
"descEl_",
",",
"_this",
".",
"description",
"(",
")",
")",
";",
"_this",
".",
"el_",
".",
"appendChild",
"(",
"_this",
".",
"descEl_",
")",
";",
"_this",
".",
"el_",
".",
"appendChild",
"(",
"_this",
".",
"contentEl_",
")",
";",
"return",
"_this",
";",
"}"
] |
Constructor for modals.
@param {Player} player
@param {Object} [options]
@param {Mixed} [options.content=undefined]
Provide customized content for this modal.
@param {String} [options.description]
A text description for the modal, primarily for accessibility.
@param {Boolean} [options.fillAlways=false]
Normally, modals are automatically filled only the first time
they open. This tells the modal to refresh its content
every time it opens.
@param {String} [options.label]
A text label for the modal, primarily for accessibility.
@param {Boolean} [options.temporary=true]
If `true`, the modal can only be opened once; it will be
disposed as soon as it's closed.
@param {Boolean} [options.uncloseable=false]
If `true`, the user will not be able to close the modal
through the UI in the normal ways. Programmatic closing is
still possible.
|
[
"Constructor",
"for",
"modals",
"."
] |
a7fbc889a18188147fcd8418c5d3bb801608b9a7
|
https://github.com/moay/afterglow/blob/a7fbc889a18188147fcd8418c5d3bb801608b9a7/vendor/videojs/video.js#L7208-L7236
|
train
|
moay/afterglow
|
vendor/videojs/video.js
|
loadTrack
|
function loadTrack(src, track) {
var opts = {
uri: src
};
var crossOrigin = (0, _url.isCrossOrigin)(src);
if (crossOrigin) {
opts.cors = crossOrigin;
}
(0, _xhr2['default'])(opts, Fn.bind(this, function (err, response, responseBody) {
if (err) {
return _log2['default'].error(err, response);
}
track.loaded_ = true;
// Make sure that vttjs has loaded, otherwise, wait till it finished loading
// NOTE: this is only used for the alt/video.novtt.js build
if (typeof _window2['default'].WebVTT !== 'function') {
if (track.tech_) {
(function () {
var loadHandler = function loadHandler() {
return parseCues(responseBody, track);
};
track.tech_.on('vttjsloaded', loadHandler);
track.tech_.on('vttjserror', function () {
_log2['default'].error('vttjs failed to load, stopping trying to process ' + track.src);
track.tech_.off('vttjsloaded', loadHandler);
});
})();
}
} else {
parseCues(responseBody, track);
}
}));
}
|
javascript
|
function loadTrack(src, track) {
var opts = {
uri: src
};
var crossOrigin = (0, _url.isCrossOrigin)(src);
if (crossOrigin) {
opts.cors = crossOrigin;
}
(0, _xhr2['default'])(opts, Fn.bind(this, function (err, response, responseBody) {
if (err) {
return _log2['default'].error(err, response);
}
track.loaded_ = true;
// Make sure that vttjs has loaded, otherwise, wait till it finished loading
// NOTE: this is only used for the alt/video.novtt.js build
if (typeof _window2['default'].WebVTT !== 'function') {
if (track.tech_) {
(function () {
var loadHandler = function loadHandler() {
return parseCues(responseBody, track);
};
track.tech_.on('vttjsloaded', loadHandler);
track.tech_.on('vttjserror', function () {
_log2['default'].error('vttjs failed to load, stopping trying to process ' + track.src);
track.tech_.off('vttjsloaded', loadHandler);
});
})();
}
} else {
parseCues(responseBody, track);
}
}));
}
|
[
"function",
"loadTrack",
"(",
"src",
",",
"track",
")",
"{",
"var",
"opts",
"=",
"{",
"uri",
":",
"src",
"}",
";",
"var",
"crossOrigin",
"=",
"(",
"0",
",",
"_url",
".",
"isCrossOrigin",
")",
"(",
"src",
")",
";",
"if",
"(",
"crossOrigin",
")",
"{",
"opts",
".",
"cors",
"=",
"crossOrigin",
";",
"}",
"(",
"0",
",",
"_xhr2",
"[",
"'default'",
"]",
")",
"(",
"opts",
",",
"Fn",
".",
"bind",
"(",
"this",
",",
"function",
"(",
"err",
",",
"response",
",",
"responseBody",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"_log2",
"[",
"'default'",
"]",
".",
"error",
"(",
"err",
",",
"response",
")",
";",
"}",
"track",
".",
"loaded_",
"=",
"true",
";",
"// Make sure that vttjs has loaded, otherwise, wait till it finished loading",
"// NOTE: this is only used for the alt/video.novtt.js build",
"if",
"(",
"typeof",
"_window2",
"[",
"'default'",
"]",
".",
"WebVTT",
"!==",
"'function'",
")",
"{",
"if",
"(",
"track",
".",
"tech_",
")",
"{",
"(",
"function",
"(",
")",
"{",
"var",
"loadHandler",
"=",
"function",
"loadHandler",
"(",
")",
"{",
"return",
"parseCues",
"(",
"responseBody",
",",
"track",
")",
";",
"}",
";",
"track",
".",
"tech_",
".",
"on",
"(",
"'vttjsloaded'",
",",
"loadHandler",
")",
";",
"track",
".",
"tech_",
".",
"on",
"(",
"'vttjserror'",
",",
"function",
"(",
")",
"{",
"_log2",
"[",
"'default'",
"]",
".",
"error",
"(",
"'vttjs failed to load, stopping trying to process '",
"+",
"track",
".",
"src",
")",
";",
"track",
".",
"tech_",
".",
"off",
"(",
"'vttjsloaded'",
",",
"loadHandler",
")",
";",
"}",
")",
";",
"}",
")",
"(",
")",
";",
"}",
"}",
"else",
"{",
"parseCues",
"(",
"responseBody",
",",
"track",
")",
";",
"}",
"}",
")",
")",
";",
"}"
] |
load a track from a specifed url
@param {String} src url to load track from
@param {Track} track track to addcues to
|
[
"load",
"a",
"track",
"from",
"a",
"specifed",
"url"
] |
a7fbc889a18188147fcd8418c5d3bb801608b9a7
|
https://github.com/moay/afterglow/blob/a7fbc889a18188147fcd8418c5d3bb801608b9a7/vendor/videojs/video.js#L16462-L16499
|
train
|
moay/afterglow
|
vendor/videojs/video.js
|
bufferedPercent
|
function bufferedPercent(buffered, duration) {
var bufferedDuration = 0;
var start = void 0;
var end = void 0;
if (!duration) {
return 0;
}
if (!buffered || !buffered.length) {
buffered = (0, _timeRanges.createTimeRange)(0, 0);
}
for (var i = 0; i < buffered.length; i++) {
start = buffered.start(i);
end = buffered.end(i);
// buffered end can be bigger than duration by a very small fraction
if (end > duration) {
end = duration;
}
bufferedDuration += end - start;
}
return bufferedDuration / duration;
}
|
javascript
|
function bufferedPercent(buffered, duration) {
var bufferedDuration = 0;
var start = void 0;
var end = void 0;
if (!duration) {
return 0;
}
if (!buffered || !buffered.length) {
buffered = (0, _timeRanges.createTimeRange)(0, 0);
}
for (var i = 0; i < buffered.length; i++) {
start = buffered.start(i);
end = buffered.end(i);
// buffered end can be bigger than duration by a very small fraction
if (end > duration) {
end = duration;
}
bufferedDuration += end - start;
}
return bufferedDuration / duration;
}
|
[
"function",
"bufferedPercent",
"(",
"buffered",
",",
"duration",
")",
"{",
"var",
"bufferedDuration",
"=",
"0",
";",
"var",
"start",
"=",
"void",
"0",
";",
"var",
"end",
"=",
"void",
"0",
";",
"if",
"(",
"!",
"duration",
")",
"{",
"return",
"0",
";",
"}",
"if",
"(",
"!",
"buffered",
"||",
"!",
"buffered",
".",
"length",
")",
"{",
"buffered",
"=",
"(",
"0",
",",
"_timeRanges",
".",
"createTimeRange",
")",
"(",
"0",
",",
"0",
")",
";",
"}",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"buffered",
".",
"length",
";",
"i",
"++",
")",
"{",
"start",
"=",
"buffered",
".",
"start",
"(",
"i",
")",
";",
"end",
"=",
"buffered",
".",
"end",
"(",
"i",
")",
";",
"// buffered end can be bigger than duration by a very small fraction",
"if",
"(",
"end",
">",
"duration",
")",
"{",
"end",
"=",
"duration",
";",
"}",
"bufferedDuration",
"+=",
"end",
"-",
"start",
";",
"}",
"return",
"bufferedDuration",
"/",
"duration",
";",
"}"
] |
Compute how much your video has been buffered
@param {Object} Buffered object
@param {Number} Total duration
@return {Number} Percent buffered of the total duration
@private
@function bufferedPercent
|
[
"Compute",
"how",
"much",
"your",
"video",
"has",
"been",
"buffered"
] |
a7fbc889a18188147fcd8418c5d3bb801608b9a7
|
https://github.com/moay/afterglow/blob/a7fbc889a18188147fcd8418c5d3bb801608b9a7/vendor/videojs/video.js#L17469-L17495
|
train
|
moay/afterglow
|
vendor/videojs/video.js
|
createEl
|
function createEl() {
var tagName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'div';
var properties = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var attributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var el = _document2['default'].createElement(tagName);
Object.getOwnPropertyNames(properties).forEach(function (propName) {
var val = properties[propName];
// See #2176
// We originally were accepting both properties and attributes in the
// same object, but that doesn't work so well.
if (propName.indexOf('aria-') !== -1 || propName === 'role' || propName === 'type') {
_log2['default'].warn((0, _tsml2['default'])(_templateObject, propName, val));
el.setAttribute(propName, val);
} else {
el[propName] = val;
}
});
Object.getOwnPropertyNames(attributes).forEach(function (attrName) {
el.setAttribute(attrName, attributes[attrName]);
});
return el;
}
|
javascript
|
function createEl() {
var tagName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'div';
var properties = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var attributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var el = _document2['default'].createElement(tagName);
Object.getOwnPropertyNames(properties).forEach(function (propName) {
var val = properties[propName];
// See #2176
// We originally were accepting both properties and attributes in the
// same object, but that doesn't work so well.
if (propName.indexOf('aria-') !== -1 || propName === 'role' || propName === 'type') {
_log2['default'].warn((0, _tsml2['default'])(_templateObject, propName, val));
el.setAttribute(propName, val);
} else {
el[propName] = val;
}
});
Object.getOwnPropertyNames(attributes).forEach(function (attrName) {
el.setAttribute(attrName, attributes[attrName]);
});
return el;
}
|
[
"function",
"createEl",
"(",
")",
"{",
"var",
"tagName",
"=",
"arguments",
".",
"length",
">",
"0",
"&&",
"arguments",
"[",
"0",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"0",
"]",
":",
"'div'",
";",
"var",
"properties",
"=",
"arguments",
".",
"length",
">",
"1",
"&&",
"arguments",
"[",
"1",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"1",
"]",
":",
"{",
"}",
";",
"var",
"attributes",
"=",
"arguments",
".",
"length",
">",
"2",
"&&",
"arguments",
"[",
"2",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"2",
"]",
":",
"{",
"}",
";",
"var",
"el",
"=",
"_document2",
"[",
"'default'",
"]",
".",
"createElement",
"(",
"tagName",
")",
";",
"Object",
".",
"getOwnPropertyNames",
"(",
"properties",
")",
".",
"forEach",
"(",
"function",
"(",
"propName",
")",
"{",
"var",
"val",
"=",
"properties",
"[",
"propName",
"]",
";",
"// See #2176",
"// We originally were accepting both properties and attributes in the",
"// same object, but that doesn't work so well.",
"if",
"(",
"propName",
".",
"indexOf",
"(",
"'aria-'",
")",
"!==",
"-",
"1",
"||",
"propName",
"===",
"'role'",
"||",
"propName",
"===",
"'type'",
")",
"{",
"_log2",
"[",
"'default'",
"]",
".",
"warn",
"(",
"(",
"0",
",",
"_tsml2",
"[",
"'default'",
"]",
")",
"(",
"_templateObject",
",",
"propName",
",",
"val",
")",
")",
";",
"el",
".",
"setAttribute",
"(",
"propName",
",",
"val",
")",
";",
"}",
"else",
"{",
"el",
"[",
"propName",
"]",
"=",
"val",
";",
"}",
"}",
")",
";",
"Object",
".",
"getOwnPropertyNames",
"(",
"attributes",
")",
".",
"forEach",
"(",
"function",
"(",
"attrName",
")",
"{",
"el",
".",
"setAttribute",
"(",
"attrName",
",",
"attributes",
"[",
"attrName",
"]",
")",
";",
"}",
")",
";",
"return",
"el",
";",
"}"
] |
Creates an element and applies properties.
@param {String} [tagName='div'] Name of tag to be created.
@param {Object} [properties={}] Element properties to be applied.
@param {Object} [attributes={}] Element attributes to be applied.
@return {Element}
@function createEl
|
[
"Creates",
"an",
"element",
"and",
"applies",
"properties",
"."
] |
a7fbc889a18188147fcd8418c5d3bb801608b9a7
|
https://github.com/moay/afterglow/blob/a7fbc889a18188147fcd8418c5d3bb801608b9a7/vendor/videojs/video.js#L17654-L17680
|
train
|
moay/afterglow
|
vendor/videojs/video.js
|
textContent
|
function textContent(el, text) {
if (typeof el.textContent === 'undefined') {
el.innerText = text;
} else {
el.textContent = text;
}
}
|
javascript
|
function textContent(el, text) {
if (typeof el.textContent === 'undefined') {
el.innerText = text;
} else {
el.textContent = text;
}
}
|
[
"function",
"textContent",
"(",
"el",
",",
"text",
")",
"{",
"if",
"(",
"typeof",
"el",
".",
"textContent",
"===",
"'undefined'",
")",
"{",
"el",
".",
"innerText",
"=",
"text",
";",
"}",
"else",
"{",
"el",
".",
"textContent",
"=",
"text",
";",
"}",
"}"
] |
Injects text into an element, replacing any existing contents entirely.
@param {Element} el
@param {String} text
@return {Element}
@function textContent
|
[
"Injects",
"text",
"into",
"an",
"element",
"replacing",
"any",
"existing",
"contents",
"entirely",
"."
] |
a7fbc889a18188147fcd8418c5d3bb801608b9a7
|
https://github.com/moay/afterglow/blob/a7fbc889a18188147fcd8418c5d3bb801608b9a7/vendor/videojs/video.js#L17690-L17696
|
train
|
moay/afterglow
|
vendor/videojs/video.js
|
insertElFirst
|
function insertElFirst(child, parent) {
if (parent.firstChild) {
parent.insertBefore(child, parent.firstChild);
} else {
parent.appendChild(child);
}
}
|
javascript
|
function insertElFirst(child, parent) {
if (parent.firstChild) {
parent.insertBefore(child, parent.firstChild);
} else {
parent.appendChild(child);
}
}
|
[
"function",
"insertElFirst",
"(",
"child",
",",
"parent",
")",
"{",
"if",
"(",
"parent",
".",
"firstChild",
")",
"{",
"parent",
".",
"insertBefore",
"(",
"child",
",",
"parent",
".",
"firstChild",
")",
";",
"}",
"else",
"{",
"parent",
".",
"appendChild",
"(",
"child",
")",
";",
"}",
"}"
] |
Insert an element as the first child node of another
@param {Element} child Element to insert
@param {Element} parent Element to insert child into
@private
@function insertElFirst
|
[
"Insert",
"an",
"element",
"as",
"the",
"first",
"child",
"node",
"of",
"another"
] |
a7fbc889a18188147fcd8418c5d3bb801608b9a7
|
https://github.com/moay/afterglow/blob/a7fbc889a18188147fcd8418c5d3bb801608b9a7/vendor/videojs/video.js#L17706-L17712
|
train
|
moay/afterglow
|
vendor/videojs/video.js
|
getElData
|
function getElData(el) {
var id = el[elIdAttr];
if (!id) {
id = el[elIdAttr] = Guid.newGUID();
}
if (!elData[id]) {
elData[id] = {};
}
return elData[id];
}
|
javascript
|
function getElData(el) {
var id = el[elIdAttr];
if (!id) {
id = el[elIdAttr] = Guid.newGUID();
}
if (!elData[id]) {
elData[id] = {};
}
return elData[id];
}
|
[
"function",
"getElData",
"(",
"el",
")",
"{",
"var",
"id",
"=",
"el",
"[",
"elIdAttr",
"]",
";",
"if",
"(",
"!",
"id",
")",
"{",
"id",
"=",
"el",
"[",
"elIdAttr",
"]",
"=",
"Guid",
".",
"newGUID",
"(",
")",
";",
"}",
"if",
"(",
"!",
"elData",
"[",
"id",
"]",
")",
"{",
"elData",
"[",
"id",
"]",
"=",
"{",
"}",
";",
"}",
"return",
"elData",
"[",
"id",
"]",
";",
"}"
] |
Returns the cache object where data for an element is stored
@param {Element} el Element to store data for.
@return {Object}
@function getElData
|
[
"Returns",
"the",
"cache",
"object",
"where",
"data",
"for",
"an",
"element",
"is",
"stored"
] |
a7fbc889a18188147fcd8418c5d3bb801608b9a7
|
https://github.com/moay/afterglow/blob/a7fbc889a18188147fcd8418c5d3bb801608b9a7/vendor/videojs/video.js#L17740-L17752
|
train
|
moay/afterglow
|
vendor/videojs/video.js
|
removeElData
|
function removeElData(el) {
var id = el[elIdAttr];
if (!id) {
return;
}
// Remove all stored data
delete elData[id];
// Remove the elIdAttr property from the DOM node
try {
delete el[elIdAttr];
} catch (e) {
if (el.removeAttribute) {
el.removeAttribute(elIdAttr);
} else {
// IE doesn't appear to support removeAttribute on the document element
el[elIdAttr] = null;
}
}
}
|
javascript
|
function removeElData(el) {
var id = el[elIdAttr];
if (!id) {
return;
}
// Remove all stored data
delete elData[id];
// Remove the elIdAttr property from the DOM node
try {
delete el[elIdAttr];
} catch (e) {
if (el.removeAttribute) {
el.removeAttribute(elIdAttr);
} else {
// IE doesn't appear to support removeAttribute on the document element
el[elIdAttr] = null;
}
}
}
|
[
"function",
"removeElData",
"(",
"el",
")",
"{",
"var",
"id",
"=",
"el",
"[",
"elIdAttr",
"]",
";",
"if",
"(",
"!",
"id",
")",
"{",
"return",
";",
"}",
"// Remove all stored data",
"delete",
"elData",
"[",
"id",
"]",
";",
"// Remove the elIdAttr property from the DOM node",
"try",
"{",
"delete",
"el",
"[",
"elIdAttr",
"]",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"if",
"(",
"el",
".",
"removeAttribute",
")",
"{",
"el",
".",
"removeAttribute",
"(",
"elIdAttr",
")",
";",
"}",
"else",
"{",
"// IE doesn't appear to support removeAttribute on the document element",
"el",
"[",
"elIdAttr",
"]",
"=",
"null",
";",
"}",
"}",
"}"
] |
Delete data for the element from the cache and the guid attr from getElementById
@param {Element} el Remove data for an element
@private
@function removeElData
|
[
"Delete",
"data",
"for",
"the",
"element",
"from",
"the",
"cache",
"and",
"the",
"guid",
"attr",
"from",
"getElementById"
] |
a7fbc889a18188147fcd8418c5d3bb801608b9a7
|
https://github.com/moay/afterglow/blob/a7fbc889a18188147fcd8418c5d3bb801608b9a7/vendor/videojs/video.js#L17779-L17800
|
train
|
moay/afterglow
|
vendor/videojs/video.js
|
hasElClass
|
function hasElClass(element, classToCheck) {
throwIfWhitespace(classToCheck);
if (element.classList) {
return element.classList.contains(classToCheck);
}
return classRegExp(classToCheck).test(element.className);
}
|
javascript
|
function hasElClass(element, classToCheck) {
throwIfWhitespace(classToCheck);
if (element.classList) {
return element.classList.contains(classToCheck);
}
return classRegExp(classToCheck).test(element.className);
}
|
[
"function",
"hasElClass",
"(",
"element",
",",
"classToCheck",
")",
"{",
"throwIfWhitespace",
"(",
"classToCheck",
")",
";",
"if",
"(",
"element",
".",
"classList",
")",
"{",
"return",
"element",
".",
"classList",
".",
"contains",
"(",
"classToCheck",
")",
";",
"}",
"return",
"classRegExp",
"(",
"classToCheck",
")",
".",
"test",
"(",
"element",
".",
"className",
")",
";",
"}"
] |
Check if an element has a CSS class
@function hasElClass
@param {Element} element Element to check
@param {String} classToCheck Classname to check
|
[
"Check",
"if",
"an",
"element",
"has",
"a",
"CSS",
"class"
] |
a7fbc889a18188147fcd8418c5d3bb801608b9a7
|
https://github.com/moay/afterglow/blob/a7fbc889a18188147fcd8418c5d3bb801608b9a7/vendor/videojs/video.js#L17809-L17815
|
train
|
moay/afterglow
|
vendor/videojs/video.js
|
addElClass
|
function addElClass(element, classToAdd) {
if (element.classList) {
element.classList.add(classToAdd);
// Don't need to `throwIfWhitespace` here because `hasElClass` will do it
// in the case of classList not being supported.
} else if (!hasElClass(element, classToAdd)) {
element.className = (element.className + ' ' + classToAdd).trim();
}
return element;
}
|
javascript
|
function addElClass(element, classToAdd) {
if (element.classList) {
element.classList.add(classToAdd);
// Don't need to `throwIfWhitespace` here because `hasElClass` will do it
// in the case of classList not being supported.
} else if (!hasElClass(element, classToAdd)) {
element.className = (element.className + ' ' + classToAdd).trim();
}
return element;
}
|
[
"function",
"addElClass",
"(",
"element",
",",
"classToAdd",
")",
"{",
"if",
"(",
"element",
".",
"classList",
")",
"{",
"element",
".",
"classList",
".",
"add",
"(",
"classToAdd",
")",
";",
"// Don't need to `throwIfWhitespace` here because `hasElClass` will do it",
"// in the case of classList not being supported.",
"}",
"else",
"if",
"(",
"!",
"hasElClass",
"(",
"element",
",",
"classToAdd",
")",
")",
"{",
"element",
".",
"className",
"=",
"(",
"element",
".",
"className",
"+",
"' '",
"+",
"classToAdd",
")",
".",
"trim",
"(",
")",
";",
"}",
"return",
"element",
";",
"}"
] |
Add a CSS class name to an element
@function addElClass
@param {Element} element Element to add class name to
@param {String} classToAdd Classname to add
|
[
"Add",
"a",
"CSS",
"class",
"name",
"to",
"an",
"element"
] |
a7fbc889a18188147fcd8418c5d3bb801608b9a7
|
https://github.com/moay/afterglow/blob/a7fbc889a18188147fcd8418c5d3bb801608b9a7/vendor/videojs/video.js#L17824-L17835
|
train
|
moay/afterglow
|
vendor/videojs/video.js
|
removeElClass
|
function removeElClass(element, classToRemove) {
if (element.classList) {
element.classList.remove(classToRemove);
} else {
throwIfWhitespace(classToRemove);
element.className = element.className.split(/\s+/).filter(function (c) {
return c !== classToRemove;
}).join(' ');
}
return element;
}
|
javascript
|
function removeElClass(element, classToRemove) {
if (element.classList) {
element.classList.remove(classToRemove);
} else {
throwIfWhitespace(classToRemove);
element.className = element.className.split(/\s+/).filter(function (c) {
return c !== classToRemove;
}).join(' ');
}
return element;
}
|
[
"function",
"removeElClass",
"(",
"element",
",",
"classToRemove",
")",
"{",
"if",
"(",
"element",
".",
"classList",
")",
"{",
"element",
".",
"classList",
".",
"remove",
"(",
"classToRemove",
")",
";",
"}",
"else",
"{",
"throwIfWhitespace",
"(",
"classToRemove",
")",
";",
"element",
".",
"className",
"=",
"element",
".",
"className",
".",
"split",
"(",
"/",
"\\s+",
"/",
")",
".",
"filter",
"(",
"function",
"(",
"c",
")",
"{",
"return",
"c",
"!==",
"classToRemove",
";",
"}",
")",
".",
"join",
"(",
"' '",
")",
";",
"}",
"return",
"element",
";",
"}"
] |
Remove a CSS class name from an element
@function removeElClass
@param {Element} element Element to remove from class name
@param {String} classToRemove Classname to remove
|
[
"Remove",
"a",
"CSS",
"class",
"name",
"from",
"an",
"element"
] |
a7fbc889a18188147fcd8418c5d3bb801608b9a7
|
https://github.com/moay/afterglow/blob/a7fbc889a18188147fcd8418c5d3bb801608b9a7/vendor/videojs/video.js#L17844-L17855
|
train
|
moay/afterglow
|
vendor/videojs/video.js
|
setElAttributes
|
function setElAttributes(el, attributes) {
Object.getOwnPropertyNames(attributes).forEach(function (attrName) {
var attrValue = attributes[attrName];
if (attrValue === null || typeof attrValue === 'undefined' || attrValue === false) {
el.removeAttribute(attrName);
} else {
el.setAttribute(attrName, attrValue === true ? '' : attrValue);
}
});
}
|
javascript
|
function setElAttributes(el, attributes) {
Object.getOwnPropertyNames(attributes).forEach(function (attrName) {
var attrValue = attributes[attrName];
if (attrValue === null || typeof attrValue === 'undefined' || attrValue === false) {
el.removeAttribute(attrName);
} else {
el.setAttribute(attrName, attrValue === true ? '' : attrValue);
}
});
}
|
[
"function",
"setElAttributes",
"(",
"el",
",",
"attributes",
")",
"{",
"Object",
".",
"getOwnPropertyNames",
"(",
"attributes",
")",
".",
"forEach",
"(",
"function",
"(",
"attrName",
")",
"{",
"var",
"attrValue",
"=",
"attributes",
"[",
"attrName",
"]",
";",
"if",
"(",
"attrValue",
"===",
"null",
"||",
"typeof",
"attrValue",
"===",
"'undefined'",
"||",
"attrValue",
"===",
"false",
")",
"{",
"el",
".",
"removeAttribute",
"(",
"attrName",
")",
";",
"}",
"else",
"{",
"el",
".",
"setAttribute",
"(",
"attrName",
",",
"attrValue",
"===",
"true",
"?",
"''",
":",
"attrValue",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Apply attributes to an HTML element.
@param {Element} el Target element.
@param {Object=} attributes Element attributes to be applied.
@private
@function setElAttributes
|
[
"Apply",
"attributes",
"to",
"an",
"HTML",
"element",
"."
] |
a7fbc889a18188147fcd8418c5d3bb801608b9a7
|
https://github.com/moay/afterglow/blob/a7fbc889a18188147fcd8418c5d3bb801608b9a7/vendor/videojs/video.js#L17907-L17917
|
train
|
moay/afterglow
|
vendor/videojs/video.js
|
normalizeContent
|
function normalizeContent(content) {
// First, invoke content if it is a function. If it produces an array,
// that needs to happen before normalization.
if (typeof content === 'function') {
content = content();
}
// Next up, normalize to an array, so one or many items can be normalized,
// filtered, and returned.
return (Array.isArray(content) ? content : [content]).map(function (value) {
// First, invoke value if it is a function to produce a new value,
// which will be subsequently normalized to a Node of some kind.
if (typeof value === 'function') {
value = value();
}
if (isEl(value) || isTextNode(value)) {
return value;
}
if (typeof value === 'string' && /\S/.test(value)) {
return _document2['default'].createTextNode(value);
}
}).filter(function (value) {
return value;
});
}
|
javascript
|
function normalizeContent(content) {
// First, invoke content if it is a function. If it produces an array,
// that needs to happen before normalization.
if (typeof content === 'function') {
content = content();
}
// Next up, normalize to an array, so one or many items can be normalized,
// filtered, and returned.
return (Array.isArray(content) ? content : [content]).map(function (value) {
// First, invoke value if it is a function to produce a new value,
// which will be subsequently normalized to a Node of some kind.
if (typeof value === 'function') {
value = value();
}
if (isEl(value) || isTextNode(value)) {
return value;
}
if (typeof value === 'string' && /\S/.test(value)) {
return _document2['default'].createTextNode(value);
}
}).filter(function (value) {
return value;
});
}
|
[
"function",
"normalizeContent",
"(",
"content",
")",
"{",
"// First, invoke content if it is a function. If it produces an array,",
"// that needs to happen before normalization.",
"if",
"(",
"typeof",
"content",
"===",
"'function'",
")",
"{",
"content",
"=",
"content",
"(",
")",
";",
"}",
"// Next up, normalize to an array, so one or many items can be normalized,",
"// filtered, and returned.",
"return",
"(",
"Array",
".",
"isArray",
"(",
"content",
")",
"?",
"content",
":",
"[",
"content",
"]",
")",
".",
"map",
"(",
"function",
"(",
"value",
")",
"{",
"// First, invoke value if it is a function to produce a new value,",
"// which will be subsequently normalized to a Node of some kind.",
"if",
"(",
"typeof",
"value",
"===",
"'function'",
")",
"{",
"value",
"=",
"value",
"(",
")",
";",
"}",
"if",
"(",
"isEl",
"(",
"value",
")",
"||",
"isTextNode",
"(",
"value",
")",
")",
"{",
"return",
"value",
";",
"}",
"if",
"(",
"typeof",
"value",
"===",
"'string'",
"&&",
"/",
"\\S",
"/",
".",
"test",
"(",
"value",
")",
")",
"{",
"return",
"_document2",
"[",
"'default'",
"]",
".",
"createTextNode",
"(",
"value",
")",
";",
"}",
"}",
")",
".",
"filter",
"(",
"function",
"(",
"value",
")",
"{",
"return",
"value",
";",
"}",
")",
";",
"}"
] |
Normalizes content for eventual insertion into the DOM.
This allows a wide range of content definition methods, but protects
from falling into the trap of simply writing to `innerHTML`, which is
an XSS concern.
The content for an element can be passed in multiple types and
combinations, whose behavior is as follows:
- String
Normalized into a text node.
- Element, TextNode
Passed through.
- Array
A one-dimensional array of strings, elements, nodes, or functions (which
return single strings, elements, or nodes).
- Function
If the sole argument, is expected to produce a string, element,
node, or array.
@function normalizeContent
@param {String|Element|TextNode|Array|Function} content
@return {Array}
|
[
"Normalizes",
"content",
"for",
"eventual",
"insertion",
"into",
"the",
"DOM",
"."
] |
a7fbc889a18188147fcd8418c5d3bb801608b9a7
|
https://github.com/moay/afterglow/blob/a7fbc889a18188147fcd8418c5d3bb801608b9a7/vendor/videojs/video.js#L18111-L18139
|
train
|
moay/afterglow
|
vendor/videojs/video.js
|
_cleanUpEvents
|
function _cleanUpEvents(elem, type) {
var data = Dom.getElData(elem);
// Remove the events of a particular type if there are none left
if (data.handlers[type].length === 0) {
delete data.handlers[type];
// data.handlers[type] = null;
// Setting to null was causing an error with data.handlers
// Remove the meta-handler from the element
if (elem.removeEventListener) {
elem.removeEventListener(type, data.dispatcher, false);
} else if (elem.detachEvent) {
elem.detachEvent('on' + type, data.dispatcher);
}
}
// Remove the events object if there are no types left
if (Object.getOwnPropertyNames(data.handlers).length <= 0) {
delete data.handlers;
delete data.dispatcher;
delete data.disabled;
}
// Finally remove the element data if there is no data left
if (Object.getOwnPropertyNames(data).length === 0) {
Dom.removeElData(elem);
}
}
|
javascript
|
function _cleanUpEvents(elem, type) {
var data = Dom.getElData(elem);
// Remove the events of a particular type if there are none left
if (data.handlers[type].length === 0) {
delete data.handlers[type];
// data.handlers[type] = null;
// Setting to null was causing an error with data.handlers
// Remove the meta-handler from the element
if (elem.removeEventListener) {
elem.removeEventListener(type, data.dispatcher, false);
} else if (elem.detachEvent) {
elem.detachEvent('on' + type, data.dispatcher);
}
}
// Remove the events object if there are no types left
if (Object.getOwnPropertyNames(data.handlers).length <= 0) {
delete data.handlers;
delete data.dispatcher;
delete data.disabled;
}
// Finally remove the element data if there is no data left
if (Object.getOwnPropertyNames(data).length === 0) {
Dom.removeElData(elem);
}
}
|
[
"function",
"_cleanUpEvents",
"(",
"elem",
",",
"type",
")",
"{",
"var",
"data",
"=",
"Dom",
".",
"getElData",
"(",
"elem",
")",
";",
"// Remove the events of a particular type if there are none left",
"if",
"(",
"data",
".",
"handlers",
"[",
"type",
"]",
".",
"length",
"===",
"0",
")",
"{",
"delete",
"data",
".",
"handlers",
"[",
"type",
"]",
";",
"// data.handlers[type] = null;",
"// Setting to null was causing an error with data.handlers",
"// Remove the meta-handler from the element",
"if",
"(",
"elem",
".",
"removeEventListener",
")",
"{",
"elem",
".",
"removeEventListener",
"(",
"type",
",",
"data",
".",
"dispatcher",
",",
"false",
")",
";",
"}",
"else",
"if",
"(",
"elem",
".",
"detachEvent",
")",
"{",
"elem",
".",
"detachEvent",
"(",
"'on'",
"+",
"type",
",",
"data",
".",
"dispatcher",
")",
";",
"}",
"}",
"// Remove the events object if there are no types left",
"if",
"(",
"Object",
".",
"getOwnPropertyNames",
"(",
"data",
".",
"handlers",
")",
".",
"length",
"<=",
"0",
")",
"{",
"delete",
"data",
".",
"handlers",
";",
"delete",
"data",
".",
"dispatcher",
";",
"delete",
"data",
".",
"disabled",
";",
"}",
"// Finally remove the element data if there is no data left",
"if",
"(",
"Object",
".",
"getOwnPropertyNames",
"(",
"data",
")",
".",
"length",
"===",
"0",
")",
"{",
"Dom",
".",
"removeElData",
"(",
"elem",
")",
";",
"}",
"}"
] |
Clean up the listener cache and dispatchers
@param {Element|Object} elem Element to clean up
@param {String} type Type of event to clean up
@private
@method _cleanUpEvents
|
[
"Clean",
"up",
"the",
"listener",
"cache",
"and",
"dispatchers"
] |
a7fbc889a18188147fcd8418c5d3bb801608b9a7
|
https://github.com/moay/afterglow/blob/a7fbc889a18188147fcd8418c5d3bb801608b9a7/vendor/videojs/video.js#L18249-L18277
|
train
|
moay/afterglow
|
vendor/videojs/video.js
|
off
|
function off(elem, type, fn) {
// Don't want to add a cache object through getElData if not needed
if (!Dom.hasElData(elem)) {
return;
}
var data = Dom.getElData(elem);
// If no events exist, nothing to unbind
if (!data.handlers) {
return;
}
if (Array.isArray(type)) {
return _handleMultipleEvents(off, elem, type, fn);
}
// Utility function
var removeType = function removeType(t) {
data.handlers[t] = [];
_cleanUpEvents(elem, t);
};
// Are we removing all bound events?
if (!type) {
for (var t in data.handlers) {
removeType(t);
}
return;
}
var handlers = data.handlers[type];
// If no handlers exist, nothing to unbind
if (!handlers) {
return;
}
// If no listener was provided, remove all listeners for type
if (!fn) {
removeType(type);
return;
}
// We're only removing a single handler
if (fn.guid) {
for (var n = 0; n < handlers.length; n++) {
if (handlers[n].guid === fn.guid) {
handlers.splice(n--, 1);
}
}
}
_cleanUpEvents(elem, type);
}
|
javascript
|
function off(elem, type, fn) {
// Don't want to add a cache object through getElData if not needed
if (!Dom.hasElData(elem)) {
return;
}
var data = Dom.getElData(elem);
// If no events exist, nothing to unbind
if (!data.handlers) {
return;
}
if (Array.isArray(type)) {
return _handleMultipleEvents(off, elem, type, fn);
}
// Utility function
var removeType = function removeType(t) {
data.handlers[t] = [];
_cleanUpEvents(elem, t);
};
// Are we removing all bound events?
if (!type) {
for (var t in data.handlers) {
removeType(t);
}
return;
}
var handlers = data.handlers[type];
// If no handlers exist, nothing to unbind
if (!handlers) {
return;
}
// If no listener was provided, remove all listeners for type
if (!fn) {
removeType(type);
return;
}
// We're only removing a single handler
if (fn.guid) {
for (var n = 0; n < handlers.length; n++) {
if (handlers[n].guid === fn.guid) {
handlers.splice(n--, 1);
}
}
}
_cleanUpEvents(elem, type);
}
|
[
"function",
"off",
"(",
"elem",
",",
"type",
",",
"fn",
")",
"{",
"// Don't want to add a cache object through getElData if not needed",
"if",
"(",
"!",
"Dom",
".",
"hasElData",
"(",
"elem",
")",
")",
"{",
"return",
";",
"}",
"var",
"data",
"=",
"Dom",
".",
"getElData",
"(",
"elem",
")",
";",
"// If no events exist, nothing to unbind",
"if",
"(",
"!",
"data",
".",
"handlers",
")",
"{",
"return",
";",
"}",
"if",
"(",
"Array",
".",
"isArray",
"(",
"type",
")",
")",
"{",
"return",
"_handleMultipleEvents",
"(",
"off",
",",
"elem",
",",
"type",
",",
"fn",
")",
";",
"}",
"// Utility function",
"var",
"removeType",
"=",
"function",
"removeType",
"(",
"t",
")",
"{",
"data",
".",
"handlers",
"[",
"t",
"]",
"=",
"[",
"]",
";",
"_cleanUpEvents",
"(",
"elem",
",",
"t",
")",
";",
"}",
";",
"// Are we removing all bound events?",
"if",
"(",
"!",
"type",
")",
"{",
"for",
"(",
"var",
"t",
"in",
"data",
".",
"handlers",
")",
"{",
"removeType",
"(",
"t",
")",
";",
"}",
"return",
";",
"}",
"var",
"handlers",
"=",
"data",
".",
"handlers",
"[",
"type",
"]",
";",
"// If no handlers exist, nothing to unbind",
"if",
"(",
"!",
"handlers",
")",
"{",
"return",
";",
"}",
"// If no listener was provided, remove all listeners for type",
"if",
"(",
"!",
"fn",
")",
"{",
"removeType",
"(",
"type",
")",
";",
"return",
";",
"}",
"// We're only removing a single handler",
"if",
"(",
"fn",
".",
"guid",
")",
"{",
"for",
"(",
"var",
"n",
"=",
"0",
";",
"n",
"<",
"handlers",
".",
"length",
";",
"n",
"++",
")",
"{",
"if",
"(",
"handlers",
"[",
"n",
"]",
".",
"guid",
"===",
"fn",
".",
"guid",
")",
"{",
"handlers",
".",
"splice",
"(",
"n",
"--",
",",
"1",
")",
";",
"}",
"}",
"}",
"_cleanUpEvents",
"(",
"elem",
",",
"type",
")",
";",
"}"
] |
Removes event listeners from an element
@param {Element|Object} elem Object to remove listeners from
@param {String|Array=} type Type of listener to remove. Don't include to remove all events from element.
@param {Function} fn Specific listener to remove. Don't include to remove listeners for an event type.
@method off
|
[
"Removes",
"event",
"listeners",
"from",
"an",
"element"
] |
a7fbc889a18188147fcd8418c5d3bb801608b9a7
|
https://github.com/moay/afterglow/blob/a7fbc889a18188147fcd8418c5d3bb801608b9a7/vendor/videojs/video.js#L18507-L18561
|
train
|
moay/afterglow
|
vendor/videojs/video.js
|
trigger
|
function trigger(elem, event, hash) {
// Fetches element data and a reference to the parent (for bubbling).
// Don't want to add a data object to cache for every parent,
// so checking hasElData first.
var elemData = Dom.hasElData(elem) ? Dom.getElData(elem) : {};
var parent = elem.parentNode || elem.ownerDocument;
// type = event.type || event,
// handler;
// If an event name was passed as a string, creates an event out of it
if (typeof event === 'string') {
event = { type: event, target: elem };
}
// Normalizes the event properties.
event = fixEvent(event);
// If the passed element has a dispatcher, executes the established handlers.
if (elemData.dispatcher) {
elemData.dispatcher.call(elem, event, hash);
}
// Unless explicitly stopped or the event does not bubble (e.g. media events)
// recursively calls this function to bubble the event up the DOM.
if (parent && !event.isPropagationStopped() && event.bubbles === true) {
trigger.call(null, parent, event, hash);
// If at the top of the DOM, triggers the default action unless disabled.
} else if (!parent && !event.defaultPrevented) {
var targetData = Dom.getElData(event.target);
// Checks if the target has a default action for this event.
if (event.target[event.type]) {
// Temporarily disables event dispatching on the target as we have already executed the handler.
targetData.disabled = true;
// Executes the default action.
if (typeof event.target[event.type] === 'function') {
event.target[event.type]();
}
// Re-enables event dispatching.
targetData.disabled = false;
}
}
// Inform the triggerer if the default was prevented by returning false
return !event.defaultPrevented;
}
|
javascript
|
function trigger(elem, event, hash) {
// Fetches element data and a reference to the parent (for bubbling).
// Don't want to add a data object to cache for every parent,
// so checking hasElData first.
var elemData = Dom.hasElData(elem) ? Dom.getElData(elem) : {};
var parent = elem.parentNode || elem.ownerDocument;
// type = event.type || event,
// handler;
// If an event name was passed as a string, creates an event out of it
if (typeof event === 'string') {
event = { type: event, target: elem };
}
// Normalizes the event properties.
event = fixEvent(event);
// If the passed element has a dispatcher, executes the established handlers.
if (elemData.dispatcher) {
elemData.dispatcher.call(elem, event, hash);
}
// Unless explicitly stopped or the event does not bubble (e.g. media events)
// recursively calls this function to bubble the event up the DOM.
if (parent && !event.isPropagationStopped() && event.bubbles === true) {
trigger.call(null, parent, event, hash);
// If at the top of the DOM, triggers the default action unless disabled.
} else if (!parent && !event.defaultPrevented) {
var targetData = Dom.getElData(event.target);
// Checks if the target has a default action for this event.
if (event.target[event.type]) {
// Temporarily disables event dispatching on the target as we have already executed the handler.
targetData.disabled = true;
// Executes the default action.
if (typeof event.target[event.type] === 'function') {
event.target[event.type]();
}
// Re-enables event dispatching.
targetData.disabled = false;
}
}
// Inform the triggerer if the default was prevented by returning false
return !event.defaultPrevented;
}
|
[
"function",
"trigger",
"(",
"elem",
",",
"event",
",",
"hash",
")",
"{",
"// Fetches element data and a reference to the parent (for bubbling).",
"// Don't want to add a data object to cache for every parent,",
"// so checking hasElData first.",
"var",
"elemData",
"=",
"Dom",
".",
"hasElData",
"(",
"elem",
")",
"?",
"Dom",
".",
"getElData",
"(",
"elem",
")",
":",
"{",
"}",
";",
"var",
"parent",
"=",
"elem",
".",
"parentNode",
"||",
"elem",
".",
"ownerDocument",
";",
"// type = event.type || event,",
"// handler;",
"// If an event name was passed as a string, creates an event out of it",
"if",
"(",
"typeof",
"event",
"===",
"'string'",
")",
"{",
"event",
"=",
"{",
"type",
":",
"event",
",",
"target",
":",
"elem",
"}",
";",
"}",
"// Normalizes the event properties.",
"event",
"=",
"fixEvent",
"(",
"event",
")",
";",
"// If the passed element has a dispatcher, executes the established handlers.",
"if",
"(",
"elemData",
".",
"dispatcher",
")",
"{",
"elemData",
".",
"dispatcher",
".",
"call",
"(",
"elem",
",",
"event",
",",
"hash",
")",
";",
"}",
"// Unless explicitly stopped or the event does not bubble (e.g. media events)",
"// recursively calls this function to bubble the event up the DOM.",
"if",
"(",
"parent",
"&&",
"!",
"event",
".",
"isPropagationStopped",
"(",
")",
"&&",
"event",
".",
"bubbles",
"===",
"true",
")",
"{",
"trigger",
".",
"call",
"(",
"null",
",",
"parent",
",",
"event",
",",
"hash",
")",
";",
"// If at the top of the DOM, triggers the default action unless disabled.",
"}",
"else",
"if",
"(",
"!",
"parent",
"&&",
"!",
"event",
".",
"defaultPrevented",
")",
"{",
"var",
"targetData",
"=",
"Dom",
".",
"getElData",
"(",
"event",
".",
"target",
")",
";",
"// Checks if the target has a default action for this event.",
"if",
"(",
"event",
".",
"target",
"[",
"event",
".",
"type",
"]",
")",
"{",
"// Temporarily disables event dispatching on the target as we have already executed the handler.",
"targetData",
".",
"disabled",
"=",
"true",
";",
"// Executes the default action.",
"if",
"(",
"typeof",
"event",
".",
"target",
"[",
"event",
".",
"type",
"]",
"===",
"'function'",
")",
"{",
"event",
".",
"target",
"[",
"event",
".",
"type",
"]",
"(",
")",
";",
"}",
"// Re-enables event dispatching.",
"targetData",
".",
"disabled",
"=",
"false",
";",
"}",
"}",
"// Inform the triggerer if the default was prevented by returning false",
"return",
"!",
"event",
".",
"defaultPrevented",
";",
"}"
] |
Trigger an event for an element
@param {Element|Object} elem Element to trigger an event on
@param {Event|Object|String} event A string (the type) or an event object with a type attribute
@param {Object} [hash] data hash to pass along with the event
@return {Boolean=} Returned only if default was prevented
@method trigger
|
[
"Trigger",
"an",
"event",
"for",
"an",
"element"
] |
a7fbc889a18188147fcd8418c5d3bb801608b9a7
|
https://github.com/moay/afterglow/blob/a7fbc889a18188147fcd8418c5d3bb801608b9a7/vendor/videojs/video.js#L18572-L18617
|
train
|
moay/afterglow
|
vendor/videojs/video.js
|
ParsingError
|
function ParsingError(errorData, message) {
this.name = "ParsingError";
this.code = errorData.code;
this.message = message || errorData.message;
}
|
javascript
|
function ParsingError(errorData, message) {
this.name = "ParsingError";
this.code = errorData.code;
this.message = message || errorData.message;
}
|
[
"function",
"ParsingError",
"(",
"errorData",
",",
"message",
")",
"{",
"this",
".",
"name",
"=",
"\"ParsingError\"",
";",
"this",
".",
"code",
"=",
"errorData",
".",
"code",
";",
"this",
".",
"message",
"=",
"message",
"||",
"errorData",
".",
"message",
";",
"}"
] |
Creates a new ParserError object from an errorData object. The errorData object should have default code and message properties. The default message property can be overriden by passing in a message parameter. See ParsingError.Errors below for acceptable errors.
|
[
"Creates",
"a",
"new",
"ParserError",
"object",
"from",
"an",
"errorData",
"object",
".",
"The",
"errorData",
"object",
"should",
"have",
"default",
"code",
"and",
"message",
"properties",
".",
"The",
"default",
"message",
"property",
"can",
"be",
"overriden",
"by",
"passing",
"in",
"a",
"message",
"parameter",
".",
"See",
"ParsingError",
".",
"Errors",
"below",
"for",
"acceptable",
"errors",
"."
] |
a7fbc889a18188147fcd8418c5d3bb801608b9a7
|
https://github.com/moay/afterglow/blob/a7fbc889a18188147fcd8418c5d3bb801608b9a7/vendor/videojs/video.js#L23182-L23186
|
train
|
moay/afterglow
|
vendor/videojs/video.js
|
parseTimeStamp
|
function parseTimeStamp(input) {
function computeSeconds(h, m, s, f) {
return (h | 0) * 3600 + (m | 0) * 60 + (s | 0) + (f | 0) / 1000;
}
var m = input.match(/^(\d+):(\d{2})(:\d{2})?\.(\d{3})/);
if (!m) {
return null;
}
if (m[3]) {
// Timestamp takes the form of [hours]:[minutes]:[seconds].[milliseconds]
return computeSeconds(m[1], m[2], m[3].replace(":", ""), m[4]);
} else if (m[1] > 59) {
// Timestamp takes the form of [hours]:[minutes].[milliseconds]
// First position is hours as it's over 59.
return computeSeconds(m[1], m[2], 0, m[4]);
} else {
// Timestamp takes the form of [minutes]:[seconds].[milliseconds]
return computeSeconds(0, m[1], m[2], m[4]);
}
}
|
javascript
|
function parseTimeStamp(input) {
function computeSeconds(h, m, s, f) {
return (h | 0) * 3600 + (m | 0) * 60 + (s | 0) + (f | 0) / 1000;
}
var m = input.match(/^(\d+):(\d{2})(:\d{2})?\.(\d{3})/);
if (!m) {
return null;
}
if (m[3]) {
// Timestamp takes the form of [hours]:[minutes]:[seconds].[milliseconds]
return computeSeconds(m[1], m[2], m[3].replace(":", ""), m[4]);
} else if (m[1] > 59) {
// Timestamp takes the form of [hours]:[minutes].[milliseconds]
// First position is hours as it's over 59.
return computeSeconds(m[1], m[2], 0, m[4]);
} else {
// Timestamp takes the form of [minutes]:[seconds].[milliseconds]
return computeSeconds(0, m[1], m[2], m[4]);
}
}
|
[
"function",
"parseTimeStamp",
"(",
"input",
")",
"{",
"function",
"computeSeconds",
"(",
"h",
",",
"m",
",",
"s",
",",
"f",
")",
"{",
"return",
"(",
"h",
"|",
"0",
")",
"*",
"3600",
"+",
"(",
"m",
"|",
"0",
")",
"*",
"60",
"+",
"(",
"s",
"|",
"0",
")",
"+",
"(",
"f",
"|",
"0",
")",
"/",
"1000",
";",
"}",
"var",
"m",
"=",
"input",
".",
"match",
"(",
"/",
"^(\\d+):(\\d{2})(:\\d{2})?\\.(\\d{3})",
"/",
")",
";",
"if",
"(",
"!",
"m",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"m",
"[",
"3",
"]",
")",
"{",
"// Timestamp takes the form of [hours]:[minutes]:[seconds].[milliseconds]",
"return",
"computeSeconds",
"(",
"m",
"[",
"1",
"]",
",",
"m",
"[",
"2",
"]",
",",
"m",
"[",
"3",
"]",
".",
"replace",
"(",
"\":\"",
",",
"\"\"",
")",
",",
"m",
"[",
"4",
"]",
")",
";",
"}",
"else",
"if",
"(",
"m",
"[",
"1",
"]",
">",
"59",
")",
"{",
"// Timestamp takes the form of [hours]:[minutes].[milliseconds]",
"// First position is hours as it's over 59.",
"return",
"computeSeconds",
"(",
"m",
"[",
"1",
"]",
",",
"m",
"[",
"2",
"]",
",",
"0",
",",
"m",
"[",
"4",
"]",
")",
";",
"}",
"else",
"{",
"// Timestamp takes the form of [minutes]:[seconds].[milliseconds]",
"return",
"computeSeconds",
"(",
"0",
",",
"m",
"[",
"1",
"]",
",",
"m",
"[",
"2",
"]",
",",
"m",
"[",
"4",
"]",
")",
";",
"}",
"}"
] |
Try to parse input as a time stamp.
|
[
"Try",
"to",
"parse",
"input",
"as",
"a",
"time",
"stamp",
"."
] |
a7fbc889a18188147fcd8418c5d3bb801608b9a7
|
https://github.com/moay/afterglow/blob/a7fbc889a18188147fcd8418c5d3bb801608b9a7/vendor/videojs/video.js#L23203-L23225
|
train
|
moay/afterglow
|
vendor/videojs/video.js
|
function(k, dflt, defaultKey) {
if (defaultKey) {
return this.has(k) ? this.values[k] : dflt[defaultKey];
}
return this.has(k) ? this.values[k] : dflt;
}
|
javascript
|
function(k, dflt, defaultKey) {
if (defaultKey) {
return this.has(k) ? this.values[k] : dflt[defaultKey];
}
return this.has(k) ? this.values[k] : dflt;
}
|
[
"function",
"(",
"k",
",",
"dflt",
",",
"defaultKey",
")",
"{",
"if",
"(",
"defaultKey",
")",
"{",
"return",
"this",
".",
"has",
"(",
"k",
")",
"?",
"this",
".",
"values",
"[",
"k",
"]",
":",
"dflt",
"[",
"defaultKey",
"]",
";",
"}",
"return",
"this",
".",
"has",
"(",
"k",
")",
"?",
"this",
".",
"values",
"[",
"k",
"]",
":",
"dflt",
";",
"}"
] |
Return the value for a key, or a default value. If 'defaultKey' is passed then 'dflt' is assumed to be an object with a number of possible default values as properties where 'defaultKey' is the key of the property that will be chosen; otherwise it's assumed to be a single value.
|
[
"Return",
"the",
"value",
"for",
"a",
"key",
"or",
"a",
"default",
"value",
".",
"If",
"defaultKey",
"is",
"passed",
"then",
"dflt",
"is",
"assumed",
"to",
"be",
"an",
"object",
"with",
"a",
"number",
"of",
"possible",
"default",
"values",
"as",
"properties",
"where",
"defaultKey",
"is",
"the",
"key",
"of",
"the",
"property",
"that",
"will",
"be",
"chosen",
";",
"otherwise",
"it",
"s",
"assumed",
"to",
"be",
"a",
"single",
"value",
"."
] |
a7fbc889a18188147fcd8418c5d3bb801608b9a7
|
https://github.com/moay/afterglow/blob/a7fbc889a18188147fcd8418c5d3bb801608b9a7/vendor/videojs/video.js#L23245-L23250
|
train
|
|
moay/afterglow
|
vendor/videojs/video.js
|
function(k, v, a) {
for (var n = 0; n < a.length; ++n) {
if (v === a[n]) {
this.set(k, v);
break;
}
}
}
|
javascript
|
function(k, v, a) {
for (var n = 0; n < a.length; ++n) {
if (v === a[n]) {
this.set(k, v);
break;
}
}
}
|
[
"function",
"(",
"k",
",",
"v",
",",
"a",
")",
"{",
"for",
"(",
"var",
"n",
"=",
"0",
";",
"n",
"<",
"a",
".",
"length",
";",
"++",
"n",
")",
"{",
"if",
"(",
"v",
"===",
"a",
"[",
"n",
"]",
")",
"{",
"this",
".",
"set",
"(",
"k",
",",
"v",
")",
";",
"break",
";",
"}",
"}",
"}"
] |
Accept a setting if its one of the given alternatives.
|
[
"Accept",
"a",
"setting",
"if",
"its",
"one",
"of",
"the",
"given",
"alternatives",
"."
] |
a7fbc889a18188147fcd8418c5d3bb801608b9a7
|
https://github.com/moay/afterglow/blob/a7fbc889a18188147fcd8418c5d3bb801608b9a7/vendor/videojs/video.js#L23256-L23263
|
train
|
|
moay/afterglow
|
vendor/videojs/video.js
|
function(k, v) {
var m;
if ((m = v.match(/^([\d]{1,3})(\.[\d]*)?%$/))) {
v = parseFloat(v);
if (v >= 0 && v <= 100) {
this.set(k, v);
return true;
}
}
return false;
}
|
javascript
|
function(k, v) {
var m;
if ((m = v.match(/^([\d]{1,3})(\.[\d]*)?%$/))) {
v = parseFloat(v);
if (v >= 0 && v <= 100) {
this.set(k, v);
return true;
}
}
return false;
}
|
[
"function",
"(",
"k",
",",
"v",
")",
"{",
"var",
"m",
";",
"if",
"(",
"(",
"m",
"=",
"v",
".",
"match",
"(",
"/",
"^([\\d]{1,3})(\\.[\\d]*)?%$",
"/",
")",
")",
")",
"{",
"v",
"=",
"parseFloat",
"(",
"v",
")",
";",
"if",
"(",
"v",
">=",
"0",
"&&",
"v",
"<=",
"100",
")",
"{",
"this",
".",
"set",
"(",
"k",
",",
"v",
")",
";",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Accept a setting if its a valid percentage.
|
[
"Accept",
"a",
"setting",
"if",
"its",
"a",
"valid",
"percentage",
"."
] |
a7fbc889a18188147fcd8418c5d3bb801608b9a7
|
https://github.com/moay/afterglow/blob/a7fbc889a18188147fcd8418c5d3bb801608b9a7/vendor/videojs/video.js#L23271-L23281
|
train
|
|
moay/afterglow
|
vendor/videojs/video.js
|
consumeTimeStamp
|
function consumeTimeStamp() {
var ts = parseTimeStamp(input);
if (ts === null) {
throw new ParsingError(ParsingError.Errors.BadTimeStamp,
"Malformed timestamp: " + oInput);
}
// Remove time stamp from input.
input = input.replace(/^[^\sa-zA-Z-]+/, "");
return ts;
}
|
javascript
|
function consumeTimeStamp() {
var ts = parseTimeStamp(input);
if (ts === null) {
throw new ParsingError(ParsingError.Errors.BadTimeStamp,
"Malformed timestamp: " + oInput);
}
// Remove time stamp from input.
input = input.replace(/^[^\sa-zA-Z-]+/, "");
return ts;
}
|
[
"function",
"consumeTimeStamp",
"(",
")",
"{",
"var",
"ts",
"=",
"parseTimeStamp",
"(",
"input",
")",
";",
"if",
"(",
"ts",
"===",
"null",
")",
"{",
"throw",
"new",
"ParsingError",
"(",
"ParsingError",
".",
"Errors",
".",
"BadTimeStamp",
",",
"\"Malformed timestamp: \"",
"+",
"oInput",
")",
";",
"}",
"// Remove time stamp from input.",
"input",
"=",
"input",
".",
"replace",
"(",
"/",
"^[^\\sa-zA-Z-]+",
"/",
",",
"\"\"",
")",
";",
"return",
"ts",
";",
"}"
] |
4.1 WebVTT timestamp
|
[
"4",
".",
"1",
"WebVTT",
"timestamp"
] |
a7fbc889a18188147fcd8418c5d3bb801608b9a7
|
https://github.com/moay/afterglow/blob/a7fbc889a18188147fcd8418c5d3bb801608b9a7/vendor/videojs/video.js#L23306-L23315
|
train
|
moay/afterglow
|
vendor/videojs/video.js
|
consumeCueSettings
|
function consumeCueSettings(input, cue) {
var settings = new Settings();
parseOptions(input, function (k, v) {
switch (k) {
case "region":
// Find the last region we parsed with the same region id.
for (var i = regionList.length - 1; i >= 0; i--) {
if (regionList[i].id === v) {
settings.set(k, regionList[i].region);
break;
}
}
break;
case "vertical":
settings.alt(k, v, ["rl", "lr"]);
break;
case "line":
var vals = v.split(","),
vals0 = vals[0];
settings.integer(k, vals0);
settings.percent(k, vals0) ? settings.set("snapToLines", false) : null;
settings.alt(k, vals0, ["auto"]);
if (vals.length === 2) {
settings.alt("lineAlign", vals[1], ["start", "middle", "end"]);
}
break;
case "position":
vals = v.split(",");
settings.percent(k, vals[0]);
if (vals.length === 2) {
settings.alt("positionAlign", vals[1], ["start", "middle", "end"]);
}
break;
case "size":
settings.percent(k, v);
break;
case "align":
settings.alt(k, v, ["start", "middle", "end", "left", "right"]);
break;
}
}, /:/, /\s/);
// Apply default values for any missing fields.
cue.region = settings.get("region", null);
cue.vertical = settings.get("vertical", "");
cue.line = settings.get("line", "auto");
cue.lineAlign = settings.get("lineAlign", "start");
cue.snapToLines = settings.get("snapToLines", true);
cue.size = settings.get("size", 100);
cue.align = settings.get("align", "middle");
cue.position = settings.get("position", {
start: 0,
left: 0,
middle: 50,
end: 100,
right: 100
}, cue.align);
cue.positionAlign = settings.get("positionAlign", {
start: "start",
left: "start",
middle: "middle",
end: "end",
right: "end"
}, cue.align);
}
|
javascript
|
function consumeCueSettings(input, cue) {
var settings = new Settings();
parseOptions(input, function (k, v) {
switch (k) {
case "region":
// Find the last region we parsed with the same region id.
for (var i = regionList.length - 1; i >= 0; i--) {
if (regionList[i].id === v) {
settings.set(k, regionList[i].region);
break;
}
}
break;
case "vertical":
settings.alt(k, v, ["rl", "lr"]);
break;
case "line":
var vals = v.split(","),
vals0 = vals[0];
settings.integer(k, vals0);
settings.percent(k, vals0) ? settings.set("snapToLines", false) : null;
settings.alt(k, vals0, ["auto"]);
if (vals.length === 2) {
settings.alt("lineAlign", vals[1], ["start", "middle", "end"]);
}
break;
case "position":
vals = v.split(",");
settings.percent(k, vals[0]);
if (vals.length === 2) {
settings.alt("positionAlign", vals[1], ["start", "middle", "end"]);
}
break;
case "size":
settings.percent(k, v);
break;
case "align":
settings.alt(k, v, ["start", "middle", "end", "left", "right"]);
break;
}
}, /:/, /\s/);
// Apply default values for any missing fields.
cue.region = settings.get("region", null);
cue.vertical = settings.get("vertical", "");
cue.line = settings.get("line", "auto");
cue.lineAlign = settings.get("lineAlign", "start");
cue.snapToLines = settings.get("snapToLines", true);
cue.size = settings.get("size", 100);
cue.align = settings.get("align", "middle");
cue.position = settings.get("position", {
start: 0,
left: 0,
middle: 50,
end: 100,
right: 100
}, cue.align);
cue.positionAlign = settings.get("positionAlign", {
start: "start",
left: "start",
middle: "middle",
end: "end",
right: "end"
}, cue.align);
}
|
[
"function",
"consumeCueSettings",
"(",
"input",
",",
"cue",
")",
"{",
"var",
"settings",
"=",
"new",
"Settings",
"(",
")",
";",
"parseOptions",
"(",
"input",
",",
"function",
"(",
"k",
",",
"v",
")",
"{",
"switch",
"(",
"k",
")",
"{",
"case",
"\"region\"",
":",
"// Find the last region we parsed with the same region id.",
"for",
"(",
"var",
"i",
"=",
"regionList",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"if",
"(",
"regionList",
"[",
"i",
"]",
".",
"id",
"===",
"v",
")",
"{",
"settings",
".",
"set",
"(",
"k",
",",
"regionList",
"[",
"i",
"]",
".",
"region",
")",
";",
"break",
";",
"}",
"}",
"break",
";",
"case",
"\"vertical\"",
":",
"settings",
".",
"alt",
"(",
"k",
",",
"v",
",",
"[",
"\"rl\"",
",",
"\"lr\"",
"]",
")",
";",
"break",
";",
"case",
"\"line\"",
":",
"var",
"vals",
"=",
"v",
".",
"split",
"(",
"\",\"",
")",
",",
"vals0",
"=",
"vals",
"[",
"0",
"]",
";",
"settings",
".",
"integer",
"(",
"k",
",",
"vals0",
")",
";",
"settings",
".",
"percent",
"(",
"k",
",",
"vals0",
")",
"?",
"settings",
".",
"set",
"(",
"\"snapToLines\"",
",",
"false",
")",
":",
"null",
";",
"settings",
".",
"alt",
"(",
"k",
",",
"vals0",
",",
"[",
"\"auto\"",
"]",
")",
";",
"if",
"(",
"vals",
".",
"length",
"===",
"2",
")",
"{",
"settings",
".",
"alt",
"(",
"\"lineAlign\"",
",",
"vals",
"[",
"1",
"]",
",",
"[",
"\"start\"",
",",
"\"middle\"",
",",
"\"end\"",
"]",
")",
";",
"}",
"break",
";",
"case",
"\"position\"",
":",
"vals",
"=",
"v",
".",
"split",
"(",
"\",\"",
")",
";",
"settings",
".",
"percent",
"(",
"k",
",",
"vals",
"[",
"0",
"]",
")",
";",
"if",
"(",
"vals",
".",
"length",
"===",
"2",
")",
"{",
"settings",
".",
"alt",
"(",
"\"positionAlign\"",
",",
"vals",
"[",
"1",
"]",
",",
"[",
"\"start\"",
",",
"\"middle\"",
",",
"\"end\"",
"]",
")",
";",
"}",
"break",
";",
"case",
"\"size\"",
":",
"settings",
".",
"percent",
"(",
"k",
",",
"v",
")",
";",
"break",
";",
"case",
"\"align\"",
":",
"settings",
".",
"alt",
"(",
"k",
",",
"v",
",",
"[",
"\"start\"",
",",
"\"middle\"",
",",
"\"end\"",
",",
"\"left\"",
",",
"\"right\"",
"]",
")",
";",
"break",
";",
"}",
"}",
",",
"/",
":",
"/",
",",
"/",
"\\s",
"/",
")",
";",
"// Apply default values for any missing fields.",
"cue",
".",
"region",
"=",
"settings",
".",
"get",
"(",
"\"region\"",
",",
"null",
")",
";",
"cue",
".",
"vertical",
"=",
"settings",
".",
"get",
"(",
"\"vertical\"",
",",
"\"\"",
")",
";",
"cue",
".",
"line",
"=",
"settings",
".",
"get",
"(",
"\"line\"",
",",
"\"auto\"",
")",
";",
"cue",
".",
"lineAlign",
"=",
"settings",
".",
"get",
"(",
"\"lineAlign\"",
",",
"\"start\"",
")",
";",
"cue",
".",
"snapToLines",
"=",
"settings",
".",
"get",
"(",
"\"snapToLines\"",
",",
"true",
")",
";",
"cue",
".",
"size",
"=",
"settings",
".",
"get",
"(",
"\"size\"",
",",
"100",
")",
";",
"cue",
".",
"align",
"=",
"settings",
".",
"get",
"(",
"\"align\"",
",",
"\"middle\"",
")",
";",
"cue",
".",
"position",
"=",
"settings",
".",
"get",
"(",
"\"position\"",
",",
"{",
"start",
":",
"0",
",",
"left",
":",
"0",
",",
"middle",
":",
"50",
",",
"end",
":",
"100",
",",
"right",
":",
"100",
"}",
",",
"cue",
".",
"align",
")",
";",
"cue",
".",
"positionAlign",
"=",
"settings",
".",
"get",
"(",
"\"positionAlign\"",
",",
"{",
"start",
":",
"\"start\"",
",",
"left",
":",
"\"start\"",
",",
"middle",
":",
"\"middle\"",
",",
"end",
":",
"\"end\"",
",",
"right",
":",
"\"end\"",
"}",
",",
"cue",
".",
"align",
")",
";",
"}"
] |
4.4.2 WebVTT cue settings
|
[
"4",
".",
"4",
".",
"2",
"WebVTT",
"cue",
"settings"
] |
a7fbc889a18188147fcd8418c5d3bb801608b9a7
|
https://github.com/moay/afterglow/blob/a7fbc889a18188147fcd8418c5d3bb801608b9a7/vendor/videojs/video.js#L23318-L23383
|
train
|
moay/afterglow
|
vendor/videojs/video.js
|
createElement
|
function createElement(type, annotation) {
var tagName = TAG_NAME[type];
if (!tagName) {
return null;
}
var element = window.document.createElement(tagName);
element.localName = tagName;
var name = TAG_ANNOTATION[type];
if (name && annotation) {
element[name] = annotation.trim();
}
return element;
}
|
javascript
|
function createElement(type, annotation) {
var tagName = TAG_NAME[type];
if (!tagName) {
return null;
}
var element = window.document.createElement(tagName);
element.localName = tagName;
var name = TAG_ANNOTATION[type];
if (name && annotation) {
element[name] = annotation.trim();
}
return element;
}
|
[
"function",
"createElement",
"(",
"type",
",",
"annotation",
")",
"{",
"var",
"tagName",
"=",
"TAG_NAME",
"[",
"type",
"]",
";",
"if",
"(",
"!",
"tagName",
")",
"{",
"return",
"null",
";",
"}",
"var",
"element",
"=",
"window",
".",
"document",
".",
"createElement",
"(",
"tagName",
")",
";",
"element",
".",
"localName",
"=",
"tagName",
";",
"var",
"name",
"=",
"TAG_ANNOTATION",
"[",
"type",
"]",
";",
"if",
"(",
"name",
"&&",
"annotation",
")",
"{",
"element",
"[",
"name",
"]",
"=",
"annotation",
".",
"trim",
"(",
")",
";",
"}",
"return",
"element",
";",
"}"
] |
Create an element for this tag.
|
[
"Create",
"an",
"element",
"for",
"this",
"tag",
"."
] |
a7fbc889a18188147fcd8418c5d3bb801608b9a7
|
https://github.com/moay/afterglow/blob/a7fbc889a18188147fcd8418c5d3bb801608b9a7/vendor/videojs/video.js#L23473-L23485
|
train
|
moay/afterglow
|
vendor/videojs/video.js
|
BoxPosition
|
function BoxPosition(obj) {
var isIE8 = (/MSIE\s8\.0/).test(navigator.userAgent);
// Either a BoxPosition was passed in and we need to copy it, or a StyleBox
// was passed in and we need to copy the results of 'getBoundingClientRect'
// as the object returned is readonly. All co-ordinate values are in reference
// to the viewport origin (top left).
var lh, height, width, top;
if (obj.div) {
height = obj.div.offsetHeight;
width = obj.div.offsetWidth;
top = obj.div.offsetTop;
var rects = (rects = obj.div.childNodes) && (rects = rects[0]) &&
rects.getClientRects && rects.getClientRects();
obj = obj.div.getBoundingClientRect();
// In certain cases the outter div will be slightly larger then the sum of
// the inner div's lines. This could be due to bold text, etc, on some platforms.
// In this case we should get the average line height and use that. This will
// result in the desired behaviour.
lh = rects ? Math.max((rects[0] && rects[0].height) || 0, obj.height / rects.length)
: 0;
}
this.left = obj.left;
this.right = obj.right;
this.top = obj.top || top;
this.height = obj.height || height;
this.bottom = obj.bottom || (top + (obj.height || height));
this.width = obj.width || width;
this.lineHeight = lh !== undefined ? lh : obj.lineHeight;
if (isIE8 && !this.lineHeight) {
this.lineHeight = 13;
}
}
|
javascript
|
function BoxPosition(obj) {
var isIE8 = (/MSIE\s8\.0/).test(navigator.userAgent);
// Either a BoxPosition was passed in and we need to copy it, or a StyleBox
// was passed in and we need to copy the results of 'getBoundingClientRect'
// as the object returned is readonly. All co-ordinate values are in reference
// to the viewport origin (top left).
var lh, height, width, top;
if (obj.div) {
height = obj.div.offsetHeight;
width = obj.div.offsetWidth;
top = obj.div.offsetTop;
var rects = (rects = obj.div.childNodes) && (rects = rects[0]) &&
rects.getClientRects && rects.getClientRects();
obj = obj.div.getBoundingClientRect();
// In certain cases the outter div will be slightly larger then the sum of
// the inner div's lines. This could be due to bold text, etc, on some platforms.
// In this case we should get the average line height and use that. This will
// result in the desired behaviour.
lh = rects ? Math.max((rects[0] && rects[0].height) || 0, obj.height / rects.length)
: 0;
}
this.left = obj.left;
this.right = obj.right;
this.top = obj.top || top;
this.height = obj.height || height;
this.bottom = obj.bottom || (top + (obj.height || height));
this.width = obj.width || width;
this.lineHeight = lh !== undefined ? lh : obj.lineHeight;
if (isIE8 && !this.lineHeight) {
this.lineHeight = 13;
}
}
|
[
"function",
"BoxPosition",
"(",
"obj",
")",
"{",
"var",
"isIE8",
"=",
"(",
"/",
"MSIE\\s8\\.0",
"/",
")",
".",
"test",
"(",
"navigator",
".",
"userAgent",
")",
";",
"// Either a BoxPosition was passed in and we need to copy it, or a StyleBox",
"// was passed in and we need to copy the results of 'getBoundingClientRect'",
"// as the object returned is readonly. All co-ordinate values are in reference",
"// to the viewport origin (top left).",
"var",
"lh",
",",
"height",
",",
"width",
",",
"top",
";",
"if",
"(",
"obj",
".",
"div",
")",
"{",
"height",
"=",
"obj",
".",
"div",
".",
"offsetHeight",
";",
"width",
"=",
"obj",
".",
"div",
".",
"offsetWidth",
";",
"top",
"=",
"obj",
".",
"div",
".",
"offsetTop",
";",
"var",
"rects",
"=",
"(",
"rects",
"=",
"obj",
".",
"div",
".",
"childNodes",
")",
"&&",
"(",
"rects",
"=",
"rects",
"[",
"0",
"]",
")",
"&&",
"rects",
".",
"getClientRects",
"&&",
"rects",
".",
"getClientRects",
"(",
")",
";",
"obj",
"=",
"obj",
".",
"div",
".",
"getBoundingClientRect",
"(",
")",
";",
"// In certain cases the outter div will be slightly larger then the sum of",
"// the inner div's lines. This could be due to bold text, etc, on some platforms.",
"// In this case we should get the average line height and use that. This will",
"// result in the desired behaviour.",
"lh",
"=",
"rects",
"?",
"Math",
".",
"max",
"(",
"(",
"rects",
"[",
"0",
"]",
"&&",
"rects",
"[",
"0",
"]",
".",
"height",
")",
"||",
"0",
",",
"obj",
".",
"height",
"/",
"rects",
".",
"length",
")",
":",
"0",
";",
"}",
"this",
".",
"left",
"=",
"obj",
".",
"left",
";",
"this",
".",
"right",
"=",
"obj",
".",
"right",
";",
"this",
".",
"top",
"=",
"obj",
".",
"top",
"||",
"top",
";",
"this",
".",
"height",
"=",
"obj",
".",
"height",
"||",
"height",
";",
"this",
".",
"bottom",
"=",
"obj",
".",
"bottom",
"||",
"(",
"top",
"+",
"(",
"obj",
".",
"height",
"||",
"height",
")",
")",
";",
"this",
".",
"width",
"=",
"obj",
".",
"width",
"||",
"width",
";",
"this",
".",
"lineHeight",
"=",
"lh",
"!==",
"undefined",
"?",
"lh",
":",
"obj",
".",
"lineHeight",
";",
"if",
"(",
"isIE8",
"&&",
"!",
"this",
".",
"lineHeight",
")",
"{",
"this",
".",
"lineHeight",
"=",
"13",
";",
"}",
"}"
] |
Represents the co-ordinates of an Element in a way that we can easily compute things with such as if it overlaps or intersects with another Element. Can initialize it with either a StyleBox or another BoxPosition.
|
[
"Represents",
"the",
"co",
"-",
"ordinates",
"of",
"an",
"Element",
"in",
"a",
"way",
"that",
"we",
"can",
"easily",
"compute",
"things",
"with",
"such",
"as",
"if",
"it",
"overlaps",
"or",
"intersects",
"with",
"another",
"Element",
".",
"Can",
"initialize",
"it",
"with",
"either",
"a",
"StyleBox",
"or",
"another",
"BoxPosition",
"."
] |
a7fbc889a18188147fcd8418c5d3bb801608b9a7
|
https://github.com/moay/afterglow/blob/a7fbc889a18188147fcd8418c5d3bb801608b9a7/vendor/videojs/video.js#L23972-L24007
|
train
|
moay/afterglow
|
vendor/videojs/video.js
|
shouldCompute
|
function shouldCompute(cues) {
for (var i = 0; i < cues.length; i++) {
if (cues[i].hasBeenReset || !cues[i].displayState) {
return true;
}
}
return false;
}
|
javascript
|
function shouldCompute(cues) {
for (var i = 0; i < cues.length; i++) {
if (cues[i].hasBeenReset || !cues[i].displayState) {
return true;
}
}
return false;
}
|
[
"function",
"shouldCompute",
"(",
"cues",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"cues",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"cues",
"[",
"i",
"]",
".",
"hasBeenReset",
"||",
"!",
"cues",
"[",
"i",
"]",
".",
"displayState",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Determine if we need to compute the display states of the cues. This could be the case if a cue's state has been changed since the last computation or if it has not been computed yet.
|
[
"Determine",
"if",
"we",
"need",
"to",
"compute",
"the",
"display",
"states",
"of",
"the",
"cues",
".",
"This",
"could",
"be",
"the",
"case",
"if",
"a",
"cue",
"s",
"state",
"has",
"been",
"changed",
"since",
"the",
"last",
"computation",
"or",
"if",
"it",
"has",
"not",
"been",
"computed",
"yet",
"."
] |
a7fbc889a18188147fcd8418c5d3bb801608b9a7
|
https://github.com/moay/afterglow/blob/a7fbc889a18188147fcd8418c5d3bb801608b9a7/vendor/videojs/video.js#L24306-L24313
|
train
|
moay/afterglow
|
vendor/videojs/video.js
|
parseRegion
|
function parseRegion(input) {
var settings = new Settings();
parseOptions(input, function (k, v) {
switch (k) {
case "id":
settings.set(k, v);
break;
case "width":
settings.percent(k, v);
break;
case "lines":
settings.integer(k, v);
break;
case "regionanchor":
case "viewportanchor":
var xy = v.split(',');
if (xy.length !== 2) {
break;
}
// We have to make sure both x and y parse, so use a temporary
// settings object here.
var anchor = new Settings();
anchor.percent("x", xy[0]);
anchor.percent("y", xy[1]);
if (!anchor.has("x") || !anchor.has("y")) {
break;
}
settings.set(k + "X", anchor.get("x"));
settings.set(k + "Y", anchor.get("y"));
break;
case "scroll":
settings.alt(k, v, ["up"]);
break;
}
}, /=/, /\s/);
// Create the region, using default values for any values that were not
// specified.
if (settings.has("id")) {
var region = new (self.vttjs.VTTRegion || self.window.VTTRegion)();
region.width = settings.get("width", 100);
region.lines = settings.get("lines", 3);
region.regionAnchorX = settings.get("regionanchorX", 0);
region.regionAnchorY = settings.get("regionanchorY", 100);
region.viewportAnchorX = settings.get("viewportanchorX", 0);
region.viewportAnchorY = settings.get("viewportanchorY", 100);
region.scroll = settings.get("scroll", "");
// Register the region.
self.onregion && self.onregion(region);
// Remember the VTTRegion for later in case we parse any VTTCues that
// reference it.
self.regionList.push({
id: settings.get("id"),
region: region
});
}
}
|
javascript
|
function parseRegion(input) {
var settings = new Settings();
parseOptions(input, function (k, v) {
switch (k) {
case "id":
settings.set(k, v);
break;
case "width":
settings.percent(k, v);
break;
case "lines":
settings.integer(k, v);
break;
case "regionanchor":
case "viewportanchor":
var xy = v.split(',');
if (xy.length !== 2) {
break;
}
// We have to make sure both x and y parse, so use a temporary
// settings object here.
var anchor = new Settings();
anchor.percent("x", xy[0]);
anchor.percent("y", xy[1]);
if (!anchor.has("x") || !anchor.has("y")) {
break;
}
settings.set(k + "X", anchor.get("x"));
settings.set(k + "Y", anchor.get("y"));
break;
case "scroll":
settings.alt(k, v, ["up"]);
break;
}
}, /=/, /\s/);
// Create the region, using default values for any values that were not
// specified.
if (settings.has("id")) {
var region = new (self.vttjs.VTTRegion || self.window.VTTRegion)();
region.width = settings.get("width", 100);
region.lines = settings.get("lines", 3);
region.regionAnchorX = settings.get("regionanchorX", 0);
region.regionAnchorY = settings.get("regionanchorY", 100);
region.viewportAnchorX = settings.get("viewportanchorX", 0);
region.viewportAnchorY = settings.get("viewportanchorY", 100);
region.scroll = settings.get("scroll", "");
// Register the region.
self.onregion && self.onregion(region);
// Remember the VTTRegion for later in case we parse any VTTCues that
// reference it.
self.regionList.push({
id: settings.get("id"),
region: region
});
}
}
|
[
"function",
"parseRegion",
"(",
"input",
")",
"{",
"var",
"settings",
"=",
"new",
"Settings",
"(",
")",
";",
"parseOptions",
"(",
"input",
",",
"function",
"(",
"k",
",",
"v",
")",
"{",
"switch",
"(",
"k",
")",
"{",
"case",
"\"id\"",
":",
"settings",
".",
"set",
"(",
"k",
",",
"v",
")",
";",
"break",
";",
"case",
"\"width\"",
":",
"settings",
".",
"percent",
"(",
"k",
",",
"v",
")",
";",
"break",
";",
"case",
"\"lines\"",
":",
"settings",
".",
"integer",
"(",
"k",
",",
"v",
")",
";",
"break",
";",
"case",
"\"regionanchor\"",
":",
"case",
"\"viewportanchor\"",
":",
"var",
"xy",
"=",
"v",
".",
"split",
"(",
"','",
")",
";",
"if",
"(",
"xy",
".",
"length",
"!==",
"2",
")",
"{",
"break",
";",
"}",
"// We have to make sure both x and y parse, so use a temporary",
"// settings object here.",
"var",
"anchor",
"=",
"new",
"Settings",
"(",
")",
";",
"anchor",
".",
"percent",
"(",
"\"x\"",
",",
"xy",
"[",
"0",
"]",
")",
";",
"anchor",
".",
"percent",
"(",
"\"y\"",
",",
"xy",
"[",
"1",
"]",
")",
";",
"if",
"(",
"!",
"anchor",
".",
"has",
"(",
"\"x\"",
")",
"||",
"!",
"anchor",
".",
"has",
"(",
"\"y\"",
")",
")",
"{",
"break",
";",
"}",
"settings",
".",
"set",
"(",
"k",
"+",
"\"X\"",
",",
"anchor",
".",
"get",
"(",
"\"x\"",
")",
")",
";",
"settings",
".",
"set",
"(",
"k",
"+",
"\"Y\"",
",",
"anchor",
".",
"get",
"(",
"\"y\"",
")",
")",
";",
"break",
";",
"case",
"\"scroll\"",
":",
"settings",
".",
"alt",
"(",
"k",
",",
"v",
",",
"[",
"\"up\"",
"]",
")",
";",
"break",
";",
"}",
"}",
",",
"/",
"=",
"/",
",",
"/",
"\\s",
"/",
")",
";",
"// Create the region, using default values for any values that were not",
"// specified.",
"if",
"(",
"settings",
".",
"has",
"(",
"\"id\"",
")",
")",
"{",
"var",
"region",
"=",
"new",
"(",
"self",
".",
"vttjs",
".",
"VTTRegion",
"||",
"self",
".",
"window",
".",
"VTTRegion",
")",
"(",
")",
";",
"region",
".",
"width",
"=",
"settings",
".",
"get",
"(",
"\"width\"",
",",
"100",
")",
";",
"region",
".",
"lines",
"=",
"settings",
".",
"get",
"(",
"\"lines\"",
",",
"3",
")",
";",
"region",
".",
"regionAnchorX",
"=",
"settings",
".",
"get",
"(",
"\"regionanchorX\"",
",",
"0",
")",
";",
"region",
".",
"regionAnchorY",
"=",
"settings",
".",
"get",
"(",
"\"regionanchorY\"",
",",
"100",
")",
";",
"region",
".",
"viewportAnchorX",
"=",
"settings",
".",
"get",
"(",
"\"viewportanchorX\"",
",",
"0",
")",
";",
"region",
".",
"viewportAnchorY",
"=",
"settings",
".",
"get",
"(",
"\"viewportanchorY\"",
",",
"100",
")",
";",
"region",
".",
"scroll",
"=",
"settings",
".",
"get",
"(",
"\"scroll\"",
",",
"\"\"",
")",
";",
"// Register the region.",
"self",
".",
"onregion",
"&&",
"self",
".",
"onregion",
"(",
"region",
")",
";",
"// Remember the VTTRegion for later in case we parse any VTTCues that",
"// reference it.",
"self",
".",
"regionList",
".",
"push",
"(",
"{",
"id",
":",
"settings",
".",
"get",
"(",
"\"id\"",
")",
",",
"region",
":",
"region",
"}",
")",
";",
"}",
"}"
] |
3.4 WebVTT region and WebVTT region settings syntax
|
[
"3",
".",
"4",
"WebVTT",
"region",
"and",
"WebVTT",
"region",
"settings",
"syntax"
] |
a7fbc889a18188147fcd8418c5d3bb801608b9a7
|
https://github.com/moay/afterglow/blob/a7fbc889a18188147fcd8418c5d3bb801608b9a7/vendor/videojs/video.js#L24409-L24466
|
train
|
smbolton/dagre-d3v4
|
gulpfile.js
|
prettifyJson
|
function prettifyJson(str) {
var json = JSON.parse(str);
return JSON.stringify(json, null, 2);
}
|
javascript
|
function prettifyJson(str) {
var json = JSON.parse(str);
return JSON.stringify(json, null, 2);
}
|
[
"function",
"prettifyJson",
"(",
"str",
")",
"{",
"var",
"json",
"=",
"JSON",
".",
"parse",
"(",
"str",
")",
";",
"return",
"JSON",
".",
"stringify",
"(",
"json",
",",
"null",
",",
"2",
")",
";",
"}"
] |
Given a JSON string return a prettified version of the string.
|
[
"Given",
"a",
"JSON",
"string",
"return",
"a",
"prettified",
"version",
"of",
"the",
"string",
"."
] |
78f537785332005b618e087e4226c0267c069ec6
|
https://github.com/smbolton/dagre-d3v4/blob/78f537785332005b618e087e4226c0267c069ec6/gulpfile.js#L224-L227
|
train
|
APIs-guru/raml-to-swagger
|
src/index.js
|
unwrapItems
|
function unwrapItems(schema) {
if (_.isEmpty(schema.items))
schema.items = {};
else {
assert(_.isPlainObject(schema.items[0]));
schema.items = schema.items[0];
}
return schema;
}
|
javascript
|
function unwrapItems(schema) {
if (_.isEmpty(schema.items))
schema.items = {};
else {
assert(_.isPlainObject(schema.items[0]));
schema.items = schema.items[0];
}
return schema;
}
|
[
"function",
"unwrapItems",
"(",
"schema",
")",
"{",
"if",
"(",
"_",
".",
"isEmpty",
"(",
"schema",
".",
"items",
")",
")",
"schema",
".",
"items",
"=",
"{",
"}",
";",
"else",
"{",
"assert",
"(",
"_",
".",
"isPlainObject",
"(",
"schema",
".",
"items",
"[",
"0",
"]",
")",
")",
";",
"schema",
".",
"items",
"=",
"schema",
".",
"items",
"[",
"0",
"]",
";",
"}",
"return",
"schema",
";",
"}"
] |
Fix case then 'items' value is empty or single element array.
|
[
"Fix",
"case",
"then",
"items",
"value",
"is",
"empty",
"or",
"single",
"element",
"array",
"."
] |
7311d4dd8895eaeeacaa642405b65f86dd779d2a
|
https://github.com/APIs-guru/raml-to-swagger/blob/7311d4dd8895eaeeacaa642405b65f86dd779d2a/src/index.js#L484-L493
|
train
|
cerner/canadarm
|
lib/core.js
|
init
|
function init(settings) {
var opts = settings || {},
i;
if (opts.onError !== false) {
Canadarm.setUpOnErrorHandler();
}
if (opts.wrapEvents !== false) {
Canadarm.setUpEventListening();
}
if (opts.appenders) {
for (i = 0; i < opts.appenders.length; i++) {
Canadarm.addAppender(opts.appenders[i]);
}
}
if (opts.handlers) {
for (i = 0; i < opts.handlers.length; i++) {
Canadarm.addHandler(opts.handlers[i]);
}
}
if (opts.logLevel) {
Canadarm.loggingLevel = opts.logLevel;
}
}
|
javascript
|
function init(settings) {
var opts = settings || {},
i;
if (opts.onError !== false) {
Canadarm.setUpOnErrorHandler();
}
if (opts.wrapEvents !== false) {
Canadarm.setUpEventListening();
}
if (opts.appenders) {
for (i = 0; i < opts.appenders.length; i++) {
Canadarm.addAppender(opts.appenders[i]);
}
}
if (opts.handlers) {
for (i = 0; i < opts.handlers.length; i++) {
Canadarm.addHandler(opts.handlers[i]);
}
}
if (opts.logLevel) {
Canadarm.loggingLevel = opts.logLevel;
}
}
|
[
"function",
"init",
"(",
"settings",
")",
"{",
"var",
"opts",
"=",
"settings",
"||",
"{",
"}",
",",
"i",
";",
"if",
"(",
"opts",
".",
"onError",
"!==",
"false",
")",
"{",
"Canadarm",
".",
"setUpOnErrorHandler",
"(",
")",
";",
"}",
"if",
"(",
"opts",
".",
"wrapEvents",
"!==",
"false",
")",
"{",
"Canadarm",
".",
"setUpEventListening",
"(",
")",
";",
"}",
"if",
"(",
"opts",
".",
"appenders",
")",
"{",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"opts",
".",
"appenders",
".",
"length",
";",
"i",
"++",
")",
"{",
"Canadarm",
".",
"addAppender",
"(",
"opts",
".",
"appenders",
"[",
"i",
"]",
")",
";",
"}",
"}",
"if",
"(",
"opts",
".",
"handlers",
")",
"{",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"opts",
".",
"handlers",
".",
"length",
";",
"i",
"++",
")",
"{",
"Canadarm",
".",
"addHandler",
"(",
"opts",
".",
"handlers",
"[",
"i",
"]",
")",
";",
"}",
"}",
"if",
"(",
"opts",
".",
"logLevel",
")",
"{",
"Canadarm",
".",
"loggingLevel",
"=",
"opts",
".",
"logLevel",
";",
"}",
"}"
] |
Used to setup Canadarm for consumers. The properties below are for the settings
object passed to the init function.
@example
Canadarm.init({
onError: true, // Set to false if you do not want window.onerror set.
wrapEvents: true, // Set to false if you do not want all event handlers to be logged for errors
logLevel: Canadarm.level.WARN, // Will only send logs for level of WARN and above.
appenders: [
Canadarm.Appender.standardLogAppender
],
handlers: [
Canadarm.Handler.beaconLogHandler('http://example.com/beacon.gif'),
Canadarm.Handler.consoleLogHandler
]
})
@function init
@param {object} settings - options for setting up canadarm.
@property settings[onError] {boolean} - True, Canadarm will set onerror. Defaults to true.
@property settings[wrapEvents] {boolean} - True, Canadarm will wrap event binding. Defaults to true.
@property settings[appenders] {Array} - Array of Appenders for Canadarm to use. Defaults to empty.
@property settings[handlers] {Array} - Array of Handlers for Canadarm to use. Defaults to empty.
@property settings[logLevel] {String} - The log level to log at. Defaults to Canadarm.level.DEBUG.
|
[
"Used",
"to",
"setup",
"Canadarm",
"for",
"consumers",
".",
"The",
"properties",
"below",
"are",
"for",
"the",
"settings",
"object",
"passed",
"to",
"the",
"init",
"function",
"."
] |
6ea144d18ada46e0e6668dc86034d1d73130002e
|
https://github.com/cerner/canadarm/blob/6ea144d18ada46e0e6668dc86034d1d73130002e/lib/core.js#L56-L83
|
train
|
cerner/canadarm
|
lib/core.js
|
gatherErrors
|
function gatherErrors(level, exception, message, data, appenders) {
var logAttributes = {},
localAppenders = appenders || errorAppenders,
errorAppender, attributeName, attributes, i, key;
// Go over every log appender and add it's attributes so we can log them.
for (i = 0; i < localAppenders.length; i++) {
errorAppender = localAppenders[i];
attributes = errorAppender(level, exception, message, data);
for (key in attributes) {
if (!attributes.hasOwnProperty(key)) {
continue;
}
logAttributes[key] = attributes[key];
}
}
return logAttributes;
}
|
javascript
|
function gatherErrors(level, exception, message, data, appenders) {
var logAttributes = {},
localAppenders = appenders || errorAppenders,
errorAppender, attributeName, attributes, i, key;
// Go over every log appender and add it's attributes so we can log them.
for (i = 0; i < localAppenders.length; i++) {
errorAppender = localAppenders[i];
attributes = errorAppender(level, exception, message, data);
for (key in attributes) {
if (!attributes.hasOwnProperty(key)) {
continue;
}
logAttributes[key] = attributes[key];
}
}
return logAttributes;
}
|
[
"function",
"gatherErrors",
"(",
"level",
",",
"exception",
",",
"message",
",",
"data",
",",
"appenders",
")",
"{",
"var",
"logAttributes",
"=",
"{",
"}",
",",
"localAppenders",
"=",
"appenders",
"||",
"errorAppenders",
",",
"errorAppender",
",",
"attributeName",
",",
"attributes",
",",
"i",
",",
"key",
";",
"// Go over every log appender and add it's attributes so we can log them.",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"localAppenders",
".",
"length",
";",
"i",
"++",
")",
"{",
"errorAppender",
"=",
"localAppenders",
"[",
"i",
"]",
";",
"attributes",
"=",
"errorAppender",
"(",
"level",
",",
"exception",
",",
"message",
",",
"data",
")",
";",
"for",
"(",
"key",
"in",
"attributes",
")",
"{",
"if",
"(",
"!",
"attributes",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"continue",
";",
"}",
"logAttributes",
"[",
"key",
"]",
"=",
"attributes",
"[",
"key",
"]",
";",
"}",
"}",
"return",
"logAttributes",
";",
"}"
] |
Used to gather the errors that have occurred. This function loops over the existing
logAppenders and creates the attributes that will be logged to the errors. Returns
an object of errors to log.
@function gatherErrors
@private
@param {string} level - Log level of the exception. (e.g. ERROR, FATAL)
@param {error} exception - JavaScript Error object.
@param {string} message - Message of the error.
@param {object} data - Key/Value pairing of additional properties to log.
@param {array} appenders - If passed will override existing appenders and be used.
|
[
"Used",
"to",
"gather",
"the",
"errors",
"that",
"have",
"occurred",
".",
"This",
"function",
"loops",
"over",
"the",
"existing",
"logAppenders",
"and",
"creates",
"the",
"attributes",
"that",
"will",
"be",
"logged",
"to",
"the",
"errors",
".",
"Returns",
"an",
"object",
"of",
"errors",
"to",
"log",
"."
] |
6ea144d18ada46e0e6668dc86034d1d73130002e
|
https://github.com/cerner/canadarm/blob/6ea144d18ada46e0e6668dc86034d1d73130002e/lib/core.js#L128-L147
|
train
|
cerner/canadarm
|
lib/core.js
|
pushErrors
|
function pushErrors(logAttributes, handlers) {
var localHandlers = handlers || errorHandlers,
errorHandler, i;
// Go over every log handler so we can actually create logs.
for (i = 0; i < localHandlers.length; i++) {
errorHandler = localHandlers[i];
errorHandler(logAttributes);
}
}
|
javascript
|
function pushErrors(logAttributes, handlers) {
var localHandlers = handlers || errorHandlers,
errorHandler, i;
// Go over every log handler so we can actually create logs.
for (i = 0; i < localHandlers.length; i++) {
errorHandler = localHandlers[i];
errorHandler(logAttributes);
}
}
|
[
"function",
"pushErrors",
"(",
"logAttributes",
",",
"handlers",
")",
"{",
"var",
"localHandlers",
"=",
"handlers",
"||",
"errorHandlers",
",",
"errorHandler",
",",
"i",
";",
"// Go over every log handler so we can actually create logs.",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"localHandlers",
".",
"length",
";",
"i",
"++",
")",
"{",
"errorHandler",
"=",
"localHandlers",
"[",
"i",
"]",
";",
"errorHandler",
"(",
"logAttributes",
")",
";",
"}",
"}"
] |
Sends the errors passed in `logAttributes` for each logHandler.
@method pushErrors
@private
@param {object} logAttributes -- A key/value pairing of the attributes to log.
@param {array} handlers -- If passed will override existing handlers and be used.
|
[
"Sends",
"the",
"errors",
"passed",
"in",
"logAttributes",
"for",
"each",
"logHandler",
"."
] |
6ea144d18ada46e0e6668dc86034d1d73130002e
|
https://github.com/cerner/canadarm/blob/6ea144d18ada46e0e6668dc86034d1d73130002e/lib/core.js#L158-L167
|
train
|
cerner/canadarm
|
lib/core.js
|
customLogEvent
|
function customLogEvent(level) {
// options should contain the appenders and handlers to override the
// global ones defined in errorAppenders, and errorHandlers.
// Used by Canadarm.localWatch to wrap local appender calls.
return function (message, exception, data, settings) {
// If we are are below the current Canadarm.loggingLevel we
// should not do anything with the passed information. Return
// as if nothing happened.
if (Canadarm.levelOrder.indexOf(level) < Canadarm.levelOrder.indexOf(Canadarm.loggingLevel)) {
return;
}
var options = settings || {},
attrs = gatherErrors(level, exception, message, data, options.appenders);
pushErrors(attrs, options.handlers);
};
}
|
javascript
|
function customLogEvent(level) {
// options should contain the appenders and handlers to override the
// global ones defined in errorAppenders, and errorHandlers.
// Used by Canadarm.localWatch to wrap local appender calls.
return function (message, exception, data, settings) {
// If we are are below the current Canadarm.loggingLevel we
// should not do anything with the passed information. Return
// as if nothing happened.
if (Canadarm.levelOrder.indexOf(level) < Canadarm.levelOrder.indexOf(Canadarm.loggingLevel)) {
return;
}
var options = settings || {},
attrs = gatherErrors(level, exception, message, data, options.appenders);
pushErrors(attrs, options.handlers);
};
}
|
[
"function",
"customLogEvent",
"(",
"level",
")",
"{",
"// options should contain the appenders and handlers to override the",
"// global ones defined in errorAppenders, and errorHandlers.",
"// Used by Canadarm.localWatch to wrap local appender calls.",
"return",
"function",
"(",
"message",
",",
"exception",
",",
"data",
",",
"settings",
")",
"{",
"// If we are are below the current Canadarm.loggingLevel we",
"// should not do anything with the passed information. Return",
"// as if nothing happened.",
"if",
"(",
"Canadarm",
".",
"levelOrder",
".",
"indexOf",
"(",
"level",
")",
"<",
"Canadarm",
".",
"levelOrder",
".",
"indexOf",
"(",
"Canadarm",
".",
"loggingLevel",
")",
")",
"{",
"return",
";",
"}",
"var",
"options",
"=",
"settings",
"||",
"{",
"}",
",",
"attrs",
"=",
"gatherErrors",
"(",
"level",
",",
"exception",
",",
"message",
",",
"data",
",",
"options",
".",
"appenders",
")",
";",
"pushErrors",
"(",
"attrs",
",",
"options",
".",
"handlers",
")",
";",
"}",
";",
"}"
] |
Used to generate our custom loggers.
@function customLogEvent
@private
@param {string} level - The level to log the events.
@returns a function that logs what is passed. Signature is: message, exception, data, settings.
|
[
"Used",
"to",
"generate",
"our",
"custom",
"loggers",
"."
] |
6ea144d18ada46e0e6668dc86034d1d73130002e
|
https://github.com/cerner/canadarm/blob/6ea144d18ada46e0e6668dc86034d1d73130002e/lib/core.js#L180-L198
|
train
|
cerner/canadarm
|
lib/handler/console.js
|
consoleLogHandler
|
function consoleLogHandler(logAttributes) {
var logValues = '', key;
if (console) {
// detect IE
if (window.attachEvent) {
// Put attributes into a format that are easy for IE 8 to read.
for (key in logAttributes) {
if (!logAttributes.hasOwnProperty(key)) {
continue;
}
logValues += key + '=' + logAttributes[key] + '\n';
}
console.error(logValues);
} else if (typeof logAttributes.msg !== 'undefined') {
console.error(logAttributes.msg, logAttributes);
} else {
console.error(logAttributes);
}
}
}
|
javascript
|
function consoleLogHandler(logAttributes) {
var logValues = '', key;
if (console) {
// detect IE
if (window.attachEvent) {
// Put attributes into a format that are easy for IE 8 to read.
for (key in logAttributes) {
if (!logAttributes.hasOwnProperty(key)) {
continue;
}
logValues += key + '=' + logAttributes[key] + '\n';
}
console.error(logValues);
} else if (typeof logAttributes.msg !== 'undefined') {
console.error(logAttributes.msg, logAttributes);
} else {
console.error(logAttributes);
}
}
}
|
[
"function",
"consoleLogHandler",
"(",
"logAttributes",
")",
"{",
"var",
"logValues",
"=",
"''",
",",
"key",
";",
"if",
"(",
"console",
")",
"{",
"// detect IE",
"if",
"(",
"window",
".",
"attachEvent",
")",
"{",
"// Put attributes into a format that are easy for IE 8 to read.",
"for",
"(",
"key",
"in",
"logAttributes",
")",
"{",
"if",
"(",
"!",
"logAttributes",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"continue",
";",
"}",
"logValues",
"+=",
"key",
"+",
"'='",
"+",
"logAttributes",
"[",
"key",
"]",
"+",
"'\\n'",
";",
"}",
"console",
".",
"error",
"(",
"logValues",
")",
";",
"}",
"else",
"if",
"(",
"typeof",
"logAttributes",
".",
"msg",
"!==",
"'undefined'",
")",
"{",
"console",
".",
"error",
"(",
"logAttributes",
".",
"msg",
",",
"logAttributes",
")",
";",
"}",
"else",
"{",
"console",
".",
"error",
"(",
"logAttributes",
")",
";",
"}",
"}",
"}"
] |
Console log handler. Outputs logs to console.
@memberof Canadarm.Handler
@function consoleLogHandler
@example
Canadarm.addHandler(Canadarm.Handler.consoleLogHandler);
// In Chrome the output looks similar to:
[ERROR]: two is not defined
characterSet: "windows-1252"
columnNumber: "17"
language: "en-US"
lineNumber: "17"
logDate: "2015-04-22T21:35:40.389Z"
msg: "[ERROR]: two is not defined"
pageURL: "http://localhost:8000/html/"
scriptURL: "http://localhost:8000/js/broken.js"
stack: "ReferenceError: two is not defined↵
at broken_watched_function (http://localhost:8000/js/broken.js:17:17)↵
at wrapper (http://localhost:8000/js/canadarm.js:616:17)↵
at http://localhost:8000/js/broken.js:60:40
"type: "jserror"
@param {object} logAttributes - the attributes to log, key/value pairs, no nesting.
|
[
"Console",
"log",
"handler",
".",
"Outputs",
"logs",
"to",
"console",
"."
] |
6ea144d18ada46e0e6668dc86034d1d73130002e
|
https://github.com/cerner/canadarm/blob/6ea144d18ada46e0e6668dc86034d1d73130002e/lib/handler/console.js#L28-L49
|
train
|
cerner/canadarm
|
lib/instrument/global.js
|
_onError
|
function _onError(errorMessage, url, lineNumber, columnNumber, exception) {
var onErrorReturn;
// Execute the original window.onerror handler, if any
if (_oldOnError && typeof _oldOnError === 'function') {
onErrorReturn = _oldOnError.apply(this, arguments);
}
Canadarm.fatal(errorMessage, exception, {
url: url,
lineNumber: lineNumber,
columnNumber: columnNumber
});
return onErrorReturn;
}
|
javascript
|
function _onError(errorMessage, url, lineNumber, columnNumber, exception) {
var onErrorReturn;
// Execute the original window.onerror handler, if any
if (_oldOnError && typeof _oldOnError === 'function') {
onErrorReturn = _oldOnError.apply(this, arguments);
}
Canadarm.fatal(errorMessage, exception, {
url: url,
lineNumber: lineNumber,
columnNumber: columnNumber
});
return onErrorReturn;
}
|
[
"function",
"_onError",
"(",
"errorMessage",
",",
"url",
",",
"lineNumber",
",",
"columnNumber",
",",
"exception",
")",
"{",
"var",
"onErrorReturn",
";",
"// Execute the original window.onerror handler, if any",
"if",
"(",
"_oldOnError",
"&&",
"typeof",
"_oldOnError",
"===",
"'function'",
")",
"{",
"onErrorReturn",
"=",
"_oldOnError",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"}",
"Canadarm",
".",
"fatal",
"(",
"errorMessage",
",",
"exception",
",",
"{",
"url",
":",
"url",
",",
"lineNumber",
":",
"lineNumber",
",",
"columnNumber",
":",
"columnNumber",
"}",
")",
";",
"return",
"onErrorReturn",
";",
"}"
] |
Logs the errors that have occurred. Its signature matches that of `window.onerror`.
Will replace the `window.onerror`. It will still call the original `window.onerror`
as well if it existed.
@function _onError
@private
|
[
"Logs",
"the",
"errors",
"that",
"have",
"occurred",
".",
"Its",
"signature",
"matches",
"that",
"of",
"window",
".",
"onerror",
".",
"Will",
"replace",
"the",
"window",
".",
"onerror",
".",
"It",
"will",
"still",
"call",
"the",
"original",
"window",
".",
"onerror",
"as",
"well",
"if",
"it",
"existed",
"."
] |
6ea144d18ada46e0e6668dc86034d1d73130002e
|
https://github.com/cerner/canadarm/blob/6ea144d18ada46e0e6668dc86034d1d73130002e/lib/instrument/global.js#L21-L36
|
train
|
cerner/canadarm
|
build/canadarm.js
|
findStackData
|
function findStackData(stack) {
// If the stack is not in the error we cannot get any information and
// should return immediately.
if (stack === undefined || stack === null) {
return {
'url': Canadarm.constant.UNKNOWN_LOG,
'lineNumber': Canadarm.constant.UNKNOWN_LOG,
'columnNumber': Canadarm.constant.UNKNOWN_LOG
};
}
// Remove the newlines from all browsers so we can regex this easier
var stackBits = stack.replace(/(\r\n|\n|\r)/gm,'').match(STACK_SCRIPT_COLUMN_LINE_FINDER),
newStack, stackData = [],
stackHasBits = (stackBits !== null && stackBits !== undefined);
while (stackHasBits) {
stackBits = stackBits[1].match(STACK_SCRIPT_COLUMN_LINE_FINDER);
newStack = stackBits !== null ? stackBits[1] : null;
stackData = stackBits !== null ? stackBits : stackData;
stackHasBits = (stackBits !== null && stackBits !== undefined);
}
return {
'url': stackData.length >= 1 ? stackData[1] : Canadarm.constant.UNKNOWN_LOG,
'lineNumber': stackData.length >= 1 ? stackData[2] : Canadarm.constant.UNKNOWN_LOG,
'columnNumber': stackData.length >= 1 ? stackData[3] : Canadarm.constant.UNKNOWN_LOG
};
}
|
javascript
|
function findStackData(stack) {
// If the stack is not in the error we cannot get any information and
// should return immediately.
if (stack === undefined || stack === null) {
return {
'url': Canadarm.constant.UNKNOWN_LOG,
'lineNumber': Canadarm.constant.UNKNOWN_LOG,
'columnNumber': Canadarm.constant.UNKNOWN_LOG
};
}
// Remove the newlines from all browsers so we can regex this easier
var stackBits = stack.replace(/(\r\n|\n|\r)/gm,'').match(STACK_SCRIPT_COLUMN_LINE_FINDER),
newStack, stackData = [],
stackHasBits = (stackBits !== null && stackBits !== undefined);
while (stackHasBits) {
stackBits = stackBits[1].match(STACK_SCRIPT_COLUMN_LINE_FINDER);
newStack = stackBits !== null ? stackBits[1] : null;
stackData = stackBits !== null ? stackBits : stackData;
stackHasBits = (stackBits !== null && stackBits !== undefined);
}
return {
'url': stackData.length >= 1 ? stackData[1] : Canadarm.constant.UNKNOWN_LOG,
'lineNumber': stackData.length >= 1 ? stackData[2] : Canadarm.constant.UNKNOWN_LOG,
'columnNumber': stackData.length >= 1 ? stackData[3] : Canadarm.constant.UNKNOWN_LOG
};
}
|
[
"function",
"findStackData",
"(",
"stack",
")",
"{",
"// If the stack is not in the error we cannot get any information and",
"// should return immediately.",
"if",
"(",
"stack",
"===",
"undefined",
"||",
"stack",
"===",
"null",
")",
"{",
"return",
"{",
"'url'",
":",
"Canadarm",
".",
"constant",
".",
"UNKNOWN_LOG",
",",
"'lineNumber'",
":",
"Canadarm",
".",
"constant",
".",
"UNKNOWN_LOG",
",",
"'columnNumber'",
":",
"Canadarm",
".",
"constant",
".",
"UNKNOWN_LOG",
"}",
";",
"}",
"// Remove the newlines from all browsers so we can regex this easier",
"var",
"stackBits",
"=",
"stack",
".",
"replace",
"(",
"/",
"(\\r\\n|\\n|\\r)",
"/",
"gm",
",",
"''",
")",
".",
"match",
"(",
"STACK_SCRIPT_COLUMN_LINE_FINDER",
")",
",",
"newStack",
",",
"stackData",
"=",
"[",
"]",
",",
"stackHasBits",
"=",
"(",
"stackBits",
"!==",
"null",
"&&",
"stackBits",
"!==",
"undefined",
")",
";",
"while",
"(",
"stackHasBits",
")",
"{",
"stackBits",
"=",
"stackBits",
"[",
"1",
"]",
".",
"match",
"(",
"STACK_SCRIPT_COLUMN_LINE_FINDER",
")",
";",
"newStack",
"=",
"stackBits",
"!==",
"null",
"?",
"stackBits",
"[",
"1",
"]",
":",
"null",
";",
"stackData",
"=",
"stackBits",
"!==",
"null",
"?",
"stackBits",
":",
"stackData",
";",
"stackHasBits",
"=",
"(",
"stackBits",
"!==",
"null",
"&&",
"stackBits",
"!==",
"undefined",
")",
";",
"}",
"return",
"{",
"'url'",
":",
"stackData",
".",
"length",
">=",
"1",
"?",
"stackData",
"[",
"1",
"]",
":",
"Canadarm",
".",
"constant",
".",
"UNKNOWN_LOG",
",",
"'lineNumber'",
":",
"stackData",
".",
"length",
">=",
"1",
"?",
"stackData",
"[",
"2",
"]",
":",
"Canadarm",
".",
"constant",
".",
"UNKNOWN_LOG",
",",
"'columnNumber'",
":",
"stackData",
".",
"length",
">=",
"1",
"?",
"stackData",
"[",
"3",
"]",
":",
"Canadarm",
".",
"constant",
".",
"UNKNOWN_LOG",
"}",
";",
"}"
] |
Generates the url, lineNumber, and Column number of the error.
|
[
"Generates",
"the",
"url",
"lineNumber",
"and",
"Column",
"number",
"of",
"the",
"error",
"."
] |
6ea144d18ada46e0e6668dc86034d1d73130002e
|
https://github.com/cerner/canadarm/blob/6ea144d18ada46e0e6668dc86034d1d73130002e/build/canadarm.js#L414-L442
|
train
|
vowstar/gitbook-plugin-uml
|
index.js
|
function() {
// NOTE: This fixed issue #7
// https://github.com/vowstar/gitbook-plugin-uml/issues/7
// HTML will load after this operation
// Copy images to output folder every time
var book = this;
var output = book.output;
var rootPath = output.root();
if (fs.existsSync(ASSET_PATH)) {
fs.mkdirs(path.join(rootPath, ASSET_PATH));
fs.copySync(ASSET_PATH, path.join(rootPath, ASSET_PATH));
}
}
|
javascript
|
function() {
// NOTE: This fixed issue #7
// https://github.com/vowstar/gitbook-plugin-uml/issues/7
// HTML will load after this operation
// Copy images to output folder every time
var book = this;
var output = book.output;
var rootPath = output.root();
if (fs.existsSync(ASSET_PATH)) {
fs.mkdirs(path.join(rootPath, ASSET_PATH));
fs.copySync(ASSET_PATH, path.join(rootPath, ASSET_PATH));
}
}
|
[
"function",
"(",
")",
"{",
"// NOTE: This fixed issue #7",
"// https://github.com/vowstar/gitbook-plugin-uml/issues/7",
"// HTML will load after this operation",
"// Copy images to output folder every time",
"var",
"book",
"=",
"this",
";",
"var",
"output",
"=",
"book",
".",
"output",
";",
"var",
"rootPath",
"=",
"output",
".",
"root",
"(",
")",
";",
"if",
"(",
"fs",
".",
"existsSync",
"(",
"ASSET_PATH",
")",
")",
"{",
"fs",
".",
"mkdirs",
"(",
"path",
".",
"join",
"(",
"rootPath",
",",
"ASSET_PATH",
")",
")",
";",
"fs",
".",
"copySync",
"(",
"ASSET_PATH",
",",
"path",
".",
"join",
"(",
"rootPath",
",",
"ASSET_PATH",
")",
")",
";",
"}",
"}"
] |
Before the end of book generation
|
[
"Before",
"the",
"end",
"of",
"book",
"generation"
] |
4cf519c265b4207a71ffc6cd280df9a506201755
|
https://github.com/vowstar/gitbook-plugin-uml/blob/4cf519c265b4207a71ffc6cd280df9a506201755/index.js#L119-L131
|
train
|
|
alexgorbatchev/gulp-changed-in-place
|
index.js
|
processFileByModifiedTime
|
function processFileByModifiedTime(stream, firstPass, basePath, file, cache) {
var newTime = file.stat && file.stat.mtime;
var filePath = basePath ? path.relative(basePath, file.path) : file.path;
var oldTime = cache[filePath];
cache[filePath] = newTime.getTime();
if ((!oldTime && firstPass) || (oldTime && oldTime !== newTime.getTime())) {
stream.push(file);
}
}
|
javascript
|
function processFileByModifiedTime(stream, firstPass, basePath, file, cache) {
var newTime = file.stat && file.stat.mtime;
var filePath = basePath ? path.relative(basePath, file.path) : file.path;
var oldTime = cache[filePath];
cache[filePath] = newTime.getTime();
if ((!oldTime && firstPass) || (oldTime && oldTime !== newTime.getTime())) {
stream.push(file);
}
}
|
[
"function",
"processFileByModifiedTime",
"(",
"stream",
",",
"firstPass",
",",
"basePath",
",",
"file",
",",
"cache",
")",
"{",
"var",
"newTime",
"=",
"file",
".",
"stat",
"&&",
"file",
".",
"stat",
".",
"mtime",
";",
"var",
"filePath",
"=",
"basePath",
"?",
"path",
".",
"relative",
"(",
"basePath",
",",
"file",
".",
"path",
")",
":",
"file",
".",
"path",
";",
"var",
"oldTime",
"=",
"cache",
"[",
"filePath",
"]",
";",
"cache",
"[",
"filePath",
"]",
"=",
"newTime",
".",
"getTime",
"(",
")",
";",
"if",
"(",
"(",
"!",
"oldTime",
"&&",
"firstPass",
")",
"||",
"(",
"oldTime",
"&&",
"oldTime",
"!==",
"newTime",
".",
"getTime",
"(",
")",
")",
")",
"{",
"stream",
".",
"push",
"(",
"file",
")",
";",
"}",
"}"
] |
look for changes by mtime
|
[
"look",
"for",
"changes",
"by",
"mtime"
] |
31a97e9a77e467b9e57f91148e1058fc742c7496
|
https://github.com/alexgorbatchev/gulp-changed-in-place/blob/31a97e9a77e467b9e57f91148e1058fc742c7496/index.js#L8-L18
|
train
|
alexgorbatchev/gulp-changed-in-place
|
index.js
|
processFileBySha1Hash
|
function processFileBySha1Hash(stream, firstPass, basePath, file, cache) {
// null cannot be hashed
if (file.contents === null) {
// if element is really a file, something weird happened, but it's safer
// to assume it was changed (because we cannot said that it wasn't)
// if it's not a file, we don't care, do we? does anybody transform directories?
if (file.stat.isFile()) {
stream.push(file);
}
} else {
var newHash = crypto.createHash('sha1').update(file.contents).digest('hex');
var filePath = basePath ? path.relative(basePath, file.path) : file.path;
var currentHash = cache[filePath];
cache[filePath] = newHash;
if ((!currentHash && firstPass) || (currentHash && currentHash !== newHash)) {
stream.push(file);
}
}
}
|
javascript
|
function processFileBySha1Hash(stream, firstPass, basePath, file, cache) {
// null cannot be hashed
if (file.contents === null) {
// if element is really a file, something weird happened, but it's safer
// to assume it was changed (because we cannot said that it wasn't)
// if it's not a file, we don't care, do we? does anybody transform directories?
if (file.stat.isFile()) {
stream.push(file);
}
} else {
var newHash = crypto.createHash('sha1').update(file.contents).digest('hex');
var filePath = basePath ? path.relative(basePath, file.path) : file.path;
var currentHash = cache[filePath];
cache[filePath] = newHash;
if ((!currentHash && firstPass) || (currentHash && currentHash !== newHash)) {
stream.push(file);
}
}
}
|
[
"function",
"processFileBySha1Hash",
"(",
"stream",
",",
"firstPass",
",",
"basePath",
",",
"file",
",",
"cache",
")",
"{",
"// null cannot be hashed",
"if",
"(",
"file",
".",
"contents",
"===",
"null",
")",
"{",
"// if element is really a file, something weird happened, but it's safer",
"// to assume it was changed (because we cannot said that it wasn't)",
"// if it's not a file, we don't care, do we? does anybody transform directories?",
"if",
"(",
"file",
".",
"stat",
".",
"isFile",
"(",
")",
")",
"{",
"stream",
".",
"push",
"(",
"file",
")",
";",
"}",
"}",
"else",
"{",
"var",
"newHash",
"=",
"crypto",
".",
"createHash",
"(",
"'sha1'",
")",
".",
"update",
"(",
"file",
".",
"contents",
")",
".",
"digest",
"(",
"'hex'",
")",
";",
"var",
"filePath",
"=",
"basePath",
"?",
"path",
".",
"relative",
"(",
"basePath",
",",
"file",
".",
"path",
")",
":",
"file",
".",
"path",
";",
"var",
"currentHash",
"=",
"cache",
"[",
"filePath",
"]",
";",
"cache",
"[",
"filePath",
"]",
"=",
"newHash",
";",
"if",
"(",
"(",
"!",
"currentHash",
"&&",
"firstPass",
")",
"||",
"(",
"currentHash",
"&&",
"currentHash",
"!==",
"newHash",
")",
")",
"{",
"stream",
".",
"push",
"(",
"file",
")",
";",
"}",
"}",
"}"
] |
look for changes by sha1 hash
|
[
"look",
"for",
"changes",
"by",
"sha1",
"hash"
] |
31a97e9a77e467b9e57f91148e1058fc742c7496
|
https://github.com/alexgorbatchev/gulp-changed-in-place/blob/31a97e9a77e467b9e57f91148e1058fc742c7496/index.js#L21-L41
|
train
|
DekodeInteraktiv/heisenberg
|
packages/heisenberg-scripts/scripts/build.js
|
build
|
async function build( previousFileSizes ) {
console.log( 'Creating an optimized production build...' );
const filenames = await getFilenames( FILENAMES );
const webpackConfig = await createWebpackConfig( config( filenames ) );
const compiler = webpack( webpackConfig );
return new Promise( ( resolve, reject ) => {
compiler.run( ( err, stats ) => {
if ( err ) {
return reject( err );
}
const messages = formatWebpackMessages(
stats.toJson( { all: false, warnings: true, errors: true } )
);
if ( messages.errors.length ) {
// Only keep the first error. Others are often indicative
// of the same problem, but confuse the reader with noise.
if ( messages.errors.length > 1 ) {
messages.errors.length = 1;
}
return reject( new Error( messages.errors.join( '\n\n' ) ) );
}
if ( process.env.CI && ( typeof process.env.CI !== 'string' || process.env.CI.toLowerCase() !== 'false') && messages.warnings.length ) {
console.log(
chalk.yellow( '\nTreating warnings as errors because process.env.CI = true.\nMost CI servers set it automatically.\n' )
);
return reject( new Error( messages.warnings.join( '\n\n' ) ) );
}
resolve( {
previousFileSizes,
stats,
warnings: messages.warnings,
} );
} );
} );
}
|
javascript
|
async function build( previousFileSizes ) {
console.log( 'Creating an optimized production build...' );
const filenames = await getFilenames( FILENAMES );
const webpackConfig = await createWebpackConfig( config( filenames ) );
const compiler = webpack( webpackConfig );
return new Promise( ( resolve, reject ) => {
compiler.run( ( err, stats ) => {
if ( err ) {
return reject( err );
}
const messages = formatWebpackMessages(
stats.toJson( { all: false, warnings: true, errors: true } )
);
if ( messages.errors.length ) {
// Only keep the first error. Others are often indicative
// of the same problem, but confuse the reader with noise.
if ( messages.errors.length > 1 ) {
messages.errors.length = 1;
}
return reject( new Error( messages.errors.join( '\n\n' ) ) );
}
if ( process.env.CI && ( typeof process.env.CI !== 'string' || process.env.CI.toLowerCase() !== 'false') && messages.warnings.length ) {
console.log(
chalk.yellow( '\nTreating warnings as errors because process.env.CI = true.\nMost CI servers set it automatically.\n' )
);
return reject( new Error( messages.warnings.join( '\n\n' ) ) );
}
resolve( {
previousFileSizes,
stats,
warnings: messages.warnings,
} );
} );
} );
}
|
[
"async",
"function",
"build",
"(",
"previousFileSizes",
")",
"{",
"console",
".",
"log",
"(",
"'Creating an optimized production build...'",
")",
";",
"const",
"filenames",
"=",
"await",
"getFilenames",
"(",
"FILENAMES",
")",
";",
"const",
"webpackConfig",
"=",
"await",
"createWebpackConfig",
"(",
"config",
"(",
"filenames",
")",
")",
";",
"const",
"compiler",
"=",
"webpack",
"(",
"webpackConfig",
")",
";",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"compiler",
".",
"run",
"(",
"(",
"err",
",",
"stats",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"reject",
"(",
"err",
")",
";",
"}",
"const",
"messages",
"=",
"formatWebpackMessages",
"(",
"stats",
".",
"toJson",
"(",
"{",
"all",
":",
"false",
",",
"warnings",
":",
"true",
",",
"errors",
":",
"true",
"}",
")",
")",
";",
"if",
"(",
"messages",
".",
"errors",
".",
"length",
")",
"{",
"// Only keep the first error. Others are often indicative",
"// of the same problem, but confuse the reader with noise.",
"if",
"(",
"messages",
".",
"errors",
".",
"length",
">",
"1",
")",
"{",
"messages",
".",
"errors",
".",
"length",
"=",
"1",
";",
"}",
"return",
"reject",
"(",
"new",
"Error",
"(",
"messages",
".",
"errors",
".",
"join",
"(",
"'\\n\\n'",
")",
")",
")",
";",
"}",
"if",
"(",
"process",
".",
"env",
".",
"CI",
"&&",
"(",
"typeof",
"process",
".",
"env",
".",
"CI",
"!==",
"'string'",
"||",
"process",
".",
"env",
".",
"CI",
".",
"toLowerCase",
"(",
")",
"!==",
"'false'",
")",
"&&",
"messages",
".",
"warnings",
".",
"length",
")",
"{",
"console",
".",
"log",
"(",
"chalk",
".",
"yellow",
"(",
"'\\nTreating warnings as errors because process.env.CI = true.\\nMost CI servers set it automatically.\\n'",
")",
")",
";",
"return",
"reject",
"(",
"new",
"Error",
"(",
"messages",
".",
"warnings",
".",
"join",
"(",
"'\\n\\n'",
")",
")",
")",
";",
"}",
"resolve",
"(",
"{",
"previousFileSizes",
",",
"stats",
",",
"warnings",
":",
"messages",
".",
"warnings",
",",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Build script.
|
[
"Build",
"script",
"."
] |
7e307243d727a9489bbc980608f7bb8db74a5d28
|
https://github.com/DekodeInteraktiv/heisenberg/blob/7e307243d727a9489bbc980608f7bb8db74a5d28/packages/heisenberg-scripts/scripts/build.js#L41-L83
|
train
|
standardhealth/shr-models
|
lib/export/formatters/commons.js
|
constructCode
|
function constructCode(code, system, display) {
const codeObj = new models.Concept(system, code, display);
return codeObj;
}
|
javascript
|
function constructCode(code, system, display) {
const codeObj = new models.Concept(system, code, display);
return codeObj;
}
|
[
"function",
"constructCode",
"(",
"code",
",",
"system",
",",
"display",
")",
"{",
"const",
"codeObj",
"=",
"new",
"models",
".",
"Concept",
"(",
"system",
",",
"code",
",",
"display",
")",
";",
"return",
"codeObj",
";",
"}"
] |
Concept from components
Constructs a Concept object from component details.
@param {string} code - the code component of a Concept Code
@param {uri} system - the code system component of a Concept Code
@param {string} display - descriptive display text to show alongside the Concept Code
@returns {Concept} A Concept object that matches the input components.
|
[
"Concept",
"from",
"components"
] |
ae43390c92834950299e06b627a9bdc0e155e6fe
|
https://github.com/standardhealth/shr-models/blob/ae43390c92834950299e06b627a9bdc0e155e6fe/lib/export/formatters/commons.js#L114-L117
|
train
|
standardhealth/shr-models
|
lib/export/formatters/commons.js
|
shorthandFromCodesystem
|
function shorthandFromCodesystem(cs) {
if (!cs) {
return '';
}
if (shorthands[cs]) {
return shorthands[cs];
} else if (cs.match(/http:\/\/standardhealthrecord.org\/shr\/[A-Za-z]*\/cs\/(#[A-Za-z]*CS)/)) {
return '';
} else {
return cs;
}
}
|
javascript
|
function shorthandFromCodesystem(cs) {
if (!cs) {
return '';
}
if (shorthands[cs]) {
return shorthands[cs];
} else if (cs.match(/http:\/\/standardhealthrecord.org\/shr\/[A-Za-z]*\/cs\/(#[A-Za-z]*CS)/)) {
return '';
} else {
return cs;
}
}
|
[
"function",
"shorthandFromCodesystem",
"(",
"cs",
")",
"{",
"if",
"(",
"!",
"cs",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"shorthands",
"[",
"cs",
"]",
")",
"{",
"return",
"shorthands",
"[",
"cs",
"]",
";",
"}",
"else",
"if",
"(",
"cs",
".",
"match",
"(",
"/",
"http:\\/\\/standardhealthrecord.org\\/shr\\/[A-Za-z]*\\/cs\\/(#[A-Za-z]*CS)",
"/",
")",
")",
"{",
"return",
"''",
";",
"}",
"else",
"{",
"return",
"cs",
";",
"}",
"}"
] |
Converts a code system URI to a shorthand symbol.
This contains popularly used shorthands. For other code systems,
it will generate a generic shorthand.
For URI's that match the project's URL, we omit a shorthand as
that is unnecessary in CIMPL 5.
@todo Aggregate generic shorthands
@todo Convert shr.org to config project URL
@param {uri} cs - the code system's URI
@returns {string} Shorthand symbol for code system URI
|
[
"Converts",
"a",
"code",
"system",
"URI",
"to",
"a",
"shorthand",
"symbol",
"."
] |
ae43390c92834950299e06b627a9bdc0e155e6fe
|
https://github.com/standardhealth/shr-models/blob/ae43390c92834950299e06b627a9bdc0e155e6fe/lib/export/formatters/commons.js#L134-L146
|
train
|
standardhealth/shr-models
|
lib/export/formatters/commons.js
|
formattedCodeFromConcept
|
function formattedCodeFromConcept(concept) {
var formattedConceptCode = `${shorthandFromCodesystem(concept.system)}#${concept.code}`;
if (concept.display) {
formattedConceptCode = `${formattedConceptCode} "${concept.display}"`;
} else if (concept.description) {
formattedConceptCode = `${formattedConceptCode} "${concept.description}"`;
}
return formattedConceptCode;
}
|
javascript
|
function formattedCodeFromConcept(concept) {
var formattedConceptCode = `${shorthandFromCodesystem(concept.system)}#${concept.code}`;
if (concept.display) {
formattedConceptCode = `${formattedConceptCode} "${concept.display}"`;
} else if (concept.description) {
formattedConceptCode = `${formattedConceptCode} "${concept.description}"`;
}
return formattedConceptCode;
}
|
[
"function",
"formattedCodeFromConcept",
"(",
"concept",
")",
"{",
"var",
"formattedConceptCode",
"=",
"`",
"${",
"shorthandFromCodesystem",
"(",
"concept",
".",
"system",
")",
"}",
"${",
"concept",
".",
"code",
"}",
"`",
";",
"if",
"(",
"concept",
".",
"display",
")",
"{",
"formattedConceptCode",
"=",
"`",
"${",
"formattedConceptCode",
"}",
"${",
"concept",
".",
"display",
"}",
"`",
";",
"}",
"else",
"if",
"(",
"concept",
".",
"description",
")",
"{",
"formattedConceptCode",
"=",
"`",
"${",
"formattedConceptCode",
"}",
"${",
"concept",
".",
"description",
"}",
"`",
";",
"}",
"return",
"formattedConceptCode",
";",
"}"
] |
Outputs concept code text fragment
@param {Concept} concept
@returns {string} - formatted concept code text fragment
|
[
"Outputs",
"concept",
"code",
"text",
"fragment"
] |
ae43390c92834950299e06b627a9bdc0e155e6fe
|
https://github.com/standardhealth/shr-models/blob/ae43390c92834950299e06b627a9bdc0e155e6fe/lib/export/formatters/commons.js#L154-L163
|
train
|
nelsonomuto/angular-ui-form-validation
|
dist/bower_components/jquery/src/attributes.js
|
function( elem, name, isXML ) {
var ret;
return isXML ?
undefined :
(ret = elem.getAttributeNode( name )) && ret.value !== "" ?
ret.value :
null;
}
|
javascript
|
function( elem, name, isXML ) {
var ret;
return isXML ?
undefined :
(ret = elem.getAttributeNode( name )) && ret.value !== "" ?
ret.value :
null;
}
|
[
"function",
"(",
"elem",
",",
"name",
",",
"isXML",
")",
"{",
"var",
"ret",
";",
"return",
"isXML",
"?",
"undefined",
":",
"(",
"ret",
"=",
"elem",
".",
"getAttributeNode",
"(",
"name",
")",
")",
"&&",
"ret",
".",
"value",
"!==",
"\"\"",
"?",
"ret",
".",
"value",
":",
"null",
";",
"}"
] |
Some attributes are constructed with empty-string values when not defined
|
[
"Some",
"attributes",
"are",
"constructed",
"with",
"empty",
"-",
"string",
"values",
"when",
"not",
"defined"
] |
5ab88160fe3512e0a7abbb369aaf0af652753766
|
https://github.com/nelsonomuto/angular-ui-form-validation/blob/5ab88160fe3512e0a7abbb369aaf0af652753766/dist/bower_components/jquery/src/attributes.js#L535-L542
|
train
|
|
nelsonomuto/angular-ui-form-validation
|
dist/bower_components/jquery/Gruntfile.js
|
function( flag, needsFlag ) {
// optIn defaults implicit behavior to weak exclusion
if ( optIn && !modules[ flag ] && !modules[ "+" + flag ] ) {
excluded[ flag ] = false;
}
// explicit or inherited strong exclusion
if ( excluded[ needsFlag ] || modules[ "-" + flag ] ) {
excluded[ flag ] = true;
// explicit inclusion overrides weak exclusion
} else if ( excluded[ needsFlag ] === false &&
( modules[ flag ] || modules[ "+" + flag ] ) ) {
delete excluded[ needsFlag ];
// ...all the way down
if ( deps[ needsFlag ] ) {
deps[ needsFlag ].forEach(function( subDep ) {
modules[ needsFlag ] = true;
excluder( needsFlag, subDep );
});
}
}
}
|
javascript
|
function( flag, needsFlag ) {
// optIn defaults implicit behavior to weak exclusion
if ( optIn && !modules[ flag ] && !modules[ "+" + flag ] ) {
excluded[ flag ] = false;
}
// explicit or inherited strong exclusion
if ( excluded[ needsFlag ] || modules[ "-" + flag ] ) {
excluded[ flag ] = true;
// explicit inclusion overrides weak exclusion
} else if ( excluded[ needsFlag ] === false &&
( modules[ flag ] || modules[ "+" + flag ] ) ) {
delete excluded[ needsFlag ];
// ...all the way down
if ( deps[ needsFlag ] ) {
deps[ needsFlag ].forEach(function( subDep ) {
modules[ needsFlag ] = true;
excluder( needsFlag, subDep );
});
}
}
}
|
[
"function",
"(",
"flag",
",",
"needsFlag",
")",
"{",
"// optIn defaults implicit behavior to weak exclusion",
"if",
"(",
"optIn",
"&&",
"!",
"modules",
"[",
"flag",
"]",
"&&",
"!",
"modules",
"[",
"\"+\"",
"+",
"flag",
"]",
")",
"{",
"excluded",
"[",
"flag",
"]",
"=",
"false",
";",
"}",
"// explicit or inherited strong exclusion",
"if",
"(",
"excluded",
"[",
"needsFlag",
"]",
"||",
"modules",
"[",
"\"-\"",
"+",
"flag",
"]",
")",
"{",
"excluded",
"[",
"flag",
"]",
"=",
"true",
";",
"// explicit inclusion overrides weak exclusion",
"}",
"else",
"if",
"(",
"excluded",
"[",
"needsFlag",
"]",
"===",
"false",
"&&",
"(",
"modules",
"[",
"flag",
"]",
"||",
"modules",
"[",
"\"+\"",
"+",
"flag",
"]",
")",
")",
"{",
"delete",
"excluded",
"[",
"needsFlag",
"]",
";",
"// ...all the way down",
"if",
"(",
"deps",
"[",
"needsFlag",
"]",
")",
"{",
"deps",
"[",
"needsFlag",
"]",
".",
"forEach",
"(",
"function",
"(",
"subDep",
")",
"{",
"modules",
"[",
"needsFlag",
"]",
"=",
"true",
";",
"excluder",
"(",
"needsFlag",
",",
"subDep",
")",
";",
"}",
")",
";",
"}",
"}",
"}"
] |
Concat specified files.
|
[
"Concat",
"specified",
"files",
"."
] |
5ab88160fe3512e0a7abbb369aaf0af652753766
|
https://github.com/nelsonomuto/angular-ui-form-validation/blob/5ab88160fe3512e0a7abbb369aaf0af652753766/dist/bower_components/jquery/Gruntfile.js#L312-L336
|
train
|
|
nelsonomuto/angular-ui-form-validation
|
dist/bower_components/lazy.js/lazy.js
|
getEachForSource
|
function getEachForSource(source) {
if (source.length < 40) {
return UniqueArrayWrapper.prototype.eachNoCache;
} else if (source.length < 100) {
return UniqueArrayWrapper.prototype.eachArrayCache;
} else {
return UniqueArrayWrapper.prototype.eachSetCache;
}
}
|
javascript
|
function getEachForSource(source) {
if (source.length < 40) {
return UniqueArrayWrapper.prototype.eachNoCache;
} else if (source.length < 100) {
return UniqueArrayWrapper.prototype.eachArrayCache;
} else {
return UniqueArrayWrapper.prototype.eachSetCache;
}
}
|
[
"function",
"getEachForSource",
"(",
"source",
")",
"{",
"if",
"(",
"source",
".",
"length",
"<",
"40",
")",
"{",
"return",
"UniqueArrayWrapper",
".",
"prototype",
".",
"eachNoCache",
";",
"}",
"else",
"if",
"(",
"source",
".",
"length",
"<",
"100",
")",
"{",
"return",
"UniqueArrayWrapper",
".",
"prototype",
".",
"eachArrayCache",
";",
"}",
"else",
"{",
"return",
"UniqueArrayWrapper",
".",
"prototype",
".",
"eachSetCache",
";",
"}",
"}"
] |
My latest findings here...
So I hadn't really given the set-based approach enough credit. The main issue
was that my Set implementation was totally not optimized at all. After pretty
heavily optimizing it (just take a look; it's a monstrosity now!), it now
becomes the fastest option for much smaller values of N.
|
[
"My",
"latest",
"findings",
"here",
"..."
] |
5ab88160fe3512e0a7abbb369aaf0af652753766
|
https://github.com/nelsonomuto/angular-ui-form-validation/blob/5ab88160fe3512e0a7abbb369aaf0af652753766/dist/bower_components/lazy.js/lazy.js#L3164-L3172
|
train
|
nelsonomuto/angular-ui-form-validation
|
dist/bower_components/lazy.js/lazy.js
|
createCallback
|
function createCallback(callback, defaultValue) {
switch (typeof callback) {
case "function":
return callback;
case "string":
return function(e) {
return e[callback];
};
case "object":
return function(e) {
return Lazy(callback).all(function(value, key) {
return e[key] === value;
});
};
case "undefined":
return defaultValue ?
function() { return defaultValue; } :
Lazy.identity;
default:
throw "Don't know how to make a callback from a " + typeof callback + "!";
}
}
|
javascript
|
function createCallback(callback, defaultValue) {
switch (typeof callback) {
case "function":
return callback;
case "string":
return function(e) {
return e[callback];
};
case "object":
return function(e) {
return Lazy(callback).all(function(value, key) {
return e[key] === value;
});
};
case "undefined":
return defaultValue ?
function() { return defaultValue; } :
Lazy.identity;
default:
throw "Don't know how to make a callback from a " + typeof callback + "!";
}
}
|
[
"function",
"createCallback",
"(",
"callback",
",",
"defaultValue",
")",
"{",
"switch",
"(",
"typeof",
"callback",
")",
"{",
"case",
"\"function\"",
":",
"return",
"callback",
";",
"case",
"\"string\"",
":",
"return",
"function",
"(",
"e",
")",
"{",
"return",
"e",
"[",
"callback",
"]",
";",
"}",
";",
"case",
"\"object\"",
":",
"return",
"function",
"(",
"e",
")",
"{",
"return",
"Lazy",
"(",
"callback",
")",
".",
"all",
"(",
"function",
"(",
"value",
",",
"key",
")",
"{",
"return",
"e",
"[",
"key",
"]",
"===",
"value",
";",
"}",
")",
";",
"}",
";",
"case",
"\"undefined\"",
":",
"return",
"defaultValue",
"?",
"function",
"(",
")",
"{",
"return",
"defaultValue",
";",
"}",
":",
"Lazy",
".",
"identity",
";",
"default",
":",
"throw",
"\"Don't know how to make a callback from a \"",
"+",
"typeof",
"callback",
"+",
"\"!\"",
";",
"}",
"}"
] |
Creates a callback... you know, Lo-Dash style.
- for functions, just returns the function
- for strings, returns a pluck-style callback
- for objects, returns a where-style callback
@private
@param {Function|string|Object} callback A function, string, or object to
convert to a callback.
@param {*} defaultReturn If the callback is undefined, a default return
value to use for the function.
@returns {Function} The callback function.
@examples
createCallback(function() {}) // instanceof Function
createCallback('foo') // instanceof Function
createCallback('foo')({ foo: 'bar'}) // => 'bar'
createCallback({ foo: 'bar' })({ foo: 'bar' }) // => true
createCallback({ foo: 'bar' })({ foo: 'baz' }) // => false
|
[
"Creates",
"a",
"callback",
"...",
"you",
"know",
"Lo",
"-",
"Dash",
"style",
"."
] |
5ab88160fe3512e0a7abbb369aaf0af652753766
|
https://github.com/nelsonomuto/angular-ui-form-validation/blob/5ab88160fe3512e0a7abbb369aaf0af652753766/dist/bower_components/lazy.js/lazy.js#L5288-L5313
|
train
|
nelsonomuto/angular-ui-form-validation
|
dist/bower_components/lazy.js/lazy.js
|
createSet
|
function createSet(values) {
var set = new Set();
Lazy(values || []).flatten().each(function(e) {
set.add(e);
});
return set;
}
|
javascript
|
function createSet(values) {
var set = new Set();
Lazy(values || []).flatten().each(function(e) {
set.add(e);
});
return set;
}
|
[
"function",
"createSet",
"(",
"values",
")",
"{",
"var",
"set",
"=",
"new",
"Set",
"(",
")",
";",
"Lazy",
"(",
"values",
"||",
"[",
"]",
")",
".",
"flatten",
"(",
")",
".",
"each",
"(",
"function",
"(",
"e",
")",
"{",
"set",
".",
"add",
"(",
"e",
")",
";",
"}",
")",
";",
"return",
"set",
";",
"}"
] |
Creates a Set containing the specified values.
@param {...Array} values One or more array(s) of values used to populate the
set.
@returns {Set} A new set containing the values passed in.
|
[
"Creates",
"a",
"Set",
"containing",
"the",
"specified",
"values",
"."
] |
5ab88160fe3512e0a7abbb369aaf0af652753766
|
https://github.com/nelsonomuto/angular-ui-form-validation/blob/5ab88160fe3512e0a7abbb369aaf0af652753766/dist/bower_components/lazy.js/lazy.js#L5322-L5328
|
train
|
nelsonomuto/angular-ui-form-validation
|
dist/bower_components/lazy.js/lazy.js
|
compare
|
function compare(x, y, fn) {
if (typeof fn === "function") {
return compare(fn(x), fn(y));
}
if (x === y) {
return 0;
}
return x > y ? 1 : -1;
}
|
javascript
|
function compare(x, y, fn) {
if (typeof fn === "function") {
return compare(fn(x), fn(y));
}
if (x === y) {
return 0;
}
return x > y ? 1 : -1;
}
|
[
"function",
"compare",
"(",
"x",
",",
"y",
",",
"fn",
")",
"{",
"if",
"(",
"typeof",
"fn",
"===",
"\"function\"",
")",
"{",
"return",
"compare",
"(",
"fn",
"(",
"x",
")",
",",
"fn",
"(",
"y",
")",
")",
";",
"}",
"if",
"(",
"x",
"===",
"y",
")",
"{",
"return",
"0",
";",
"}",
"return",
"x",
">",
"y",
"?",
"1",
":",
"-",
"1",
";",
"}"
] |
Compares two elements for sorting purposes.
@private
@param {*} x The left element to compare.
@param {*} y The right element to compare.
@param {Function=} fn An optional function to call on each element, to get
the values to compare.
@returns {number} 1 if x > y, -1 if x < y, or 0 if x and y are equal.
@examples
compare(1, 2) // => -1
compare(1, 1) // => 0
compare(2, 1) // => 1
compare('a', 'b') // => -1
|
[
"Compares",
"two",
"elements",
"for",
"sorting",
"purposes",
"."
] |
5ab88160fe3512e0a7abbb369aaf0af652753766
|
https://github.com/nelsonomuto/angular-ui-form-validation/blob/5ab88160fe3512e0a7abbb369aaf0af652753766/dist/bower_components/lazy.js/lazy.js#L5346-L5356
|
train
|
nelsonomuto/angular-ui-form-validation
|
dist/bower_components/lazy.js/lazy.js
|
forEach
|
function forEach(array, fn) {
var i = -1,
len = array.length;
while (++i < len) {
if (fn(array[i], i) === false) {
return false;
}
}
return true;
}
|
javascript
|
function forEach(array, fn) {
var i = -1,
len = array.length;
while (++i < len) {
if (fn(array[i], i) === false) {
return false;
}
}
return true;
}
|
[
"function",
"forEach",
"(",
"array",
",",
"fn",
")",
"{",
"var",
"i",
"=",
"-",
"1",
",",
"len",
"=",
"array",
".",
"length",
";",
"while",
"(",
"++",
"i",
"<",
"len",
")",
"{",
"if",
"(",
"fn",
"(",
"array",
"[",
"i",
"]",
",",
"i",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] |
Iterates over every element in an array.
@param {Array} array The array.
@param {Function} fn The function to call on every element, which can return
false to stop the iteration early.
@returns {boolean} True if every element in the entire sequence was iterated,
otherwise false.
|
[
"Iterates",
"over",
"every",
"element",
"in",
"an",
"array",
"."
] |
5ab88160fe3512e0a7abbb369aaf0af652753766
|
https://github.com/nelsonomuto/angular-ui-form-validation/blob/5ab88160fe3512e0a7abbb369aaf0af652753766/dist/bower_components/lazy.js/lazy.js#L5367-L5378
|
train
|
nelsonomuto/angular-ui-form-validation
|
dist/bower_components/lazy.js/lazy.js
|
arrayContains
|
function arrayContains(array, element) {
var i = -1,
length = array.length;
// Special handling for NaN
if (element !== element) {
while (++i < length) {
if (array[i] !== array[i]) {
return true;
}
}
return false;
}
while (++i < length) {
if (array[i] === element) {
return true;
}
}
return false;
}
|
javascript
|
function arrayContains(array, element) {
var i = -1,
length = array.length;
// Special handling for NaN
if (element !== element) {
while (++i < length) {
if (array[i] !== array[i]) {
return true;
}
}
return false;
}
while (++i < length) {
if (array[i] === element) {
return true;
}
}
return false;
}
|
[
"function",
"arrayContains",
"(",
"array",
",",
"element",
")",
"{",
"var",
"i",
"=",
"-",
"1",
",",
"length",
"=",
"array",
".",
"length",
";",
"// Special handling for NaN",
"if",
"(",
"element",
"!==",
"element",
")",
"{",
"while",
"(",
"++",
"i",
"<",
"length",
")",
"{",
"if",
"(",
"array",
"[",
"i",
"]",
"!==",
"array",
"[",
"i",
"]",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}",
"while",
"(",
"++",
"i",
"<",
"length",
")",
"{",
"if",
"(",
"array",
"[",
"i",
"]",
"===",
"element",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Checks if an element exists in an array.
@private
@param {Array} array
@param {*} element
@returns {boolean} Whether or not the element exists in the array.
@examples
arrayContains([1, 2], 2) // => true
arrayContains([1, 2], 3) // => false
arrayContains([undefined], undefined) // => true
arrayContains([NaN], NaN) // => true
|
[
"Checks",
"if",
"an",
"element",
"exists",
"in",
"an",
"array",
"."
] |
5ab88160fe3512e0a7abbb369aaf0af652753766
|
https://github.com/nelsonomuto/angular-ui-form-validation/blob/5ab88160fe3512e0a7abbb369aaf0af652753766/dist/bower_components/lazy.js/lazy.js#L5403-L5423
|
train
|
nelsonomuto/angular-ui-form-validation
|
dist/bower_components/lazy.js/lazy.js
|
arrayContainsBefore
|
function arrayContainsBefore(array, element, index, keyFn) {
var i = -1;
if (keyFn) {
keyFn = createCallback(keyFn);
while (++i < index) {
if (keyFn(array[i]) === keyFn(element)) {
return true;
}
}
} else {
while (++i < index) {
if (array[i] === element) {
return true;
}
}
}
return false;
}
|
javascript
|
function arrayContainsBefore(array, element, index, keyFn) {
var i = -1;
if (keyFn) {
keyFn = createCallback(keyFn);
while (++i < index) {
if (keyFn(array[i]) === keyFn(element)) {
return true;
}
}
} else {
while (++i < index) {
if (array[i] === element) {
return true;
}
}
}
return false;
}
|
[
"function",
"arrayContainsBefore",
"(",
"array",
",",
"element",
",",
"index",
",",
"keyFn",
")",
"{",
"var",
"i",
"=",
"-",
"1",
";",
"if",
"(",
"keyFn",
")",
"{",
"keyFn",
"=",
"createCallback",
"(",
"keyFn",
")",
";",
"while",
"(",
"++",
"i",
"<",
"index",
")",
"{",
"if",
"(",
"keyFn",
"(",
"array",
"[",
"i",
"]",
")",
"===",
"keyFn",
"(",
"element",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"else",
"{",
"while",
"(",
"++",
"i",
"<",
"index",
")",
"{",
"if",
"(",
"array",
"[",
"i",
"]",
"===",
"element",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] |
Checks if an element exists in an array before a given index.
@private
@param {Array} array
@param {*} element
@param {number} index
@param {Function} keyFn
@returns {boolean}
@examples
arrayContainsBefore([1, 2, 3], 3, 2) // => false
arrayContainsBefore([1, 2, 3], 3, 3) // => true
|
[
"Checks",
"if",
"an",
"element",
"exists",
"in",
"an",
"array",
"before",
"a",
"given",
"index",
"."
] |
5ab88160fe3512e0a7abbb369aaf0af652753766
|
https://github.com/nelsonomuto/angular-ui-form-validation/blob/5ab88160fe3512e0a7abbb369aaf0af652753766/dist/bower_components/lazy.js/lazy.js#L5439-L5459
|
train
|
nelsonomuto/angular-ui-form-validation
|
dist/bower_components/lazy.js/lazy.js
|
swap
|
function swap(array, i, j) {
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
|
javascript
|
function swap(array, i, j) {
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
|
[
"function",
"swap",
"(",
"array",
",",
"i",
",",
"j",
")",
"{",
"var",
"temp",
"=",
"array",
"[",
"i",
"]",
";",
"array",
"[",
"i",
"]",
"=",
"array",
"[",
"j",
"]",
";",
"array",
"[",
"j",
"]",
"=",
"temp",
";",
"}"
] |
Swaps the elements at two specified positions of an array.
@private
@param {Array} array
@param {number} i
@param {number} j
@examples
var array = [1, 2, 3, 4, 5];
swap(array, 2, 3) // array == [1, 2, 4, 3, 5]
|
[
"Swaps",
"the",
"elements",
"at",
"two",
"specified",
"positions",
"of",
"an",
"array",
"."
] |
5ab88160fe3512e0a7abbb369aaf0af652753766
|
https://github.com/nelsonomuto/angular-ui-form-validation/blob/5ab88160fe3512e0a7abbb369aaf0af652753766/dist/bower_components/lazy.js/lazy.js#L5474-L5478
|
train
|
nelsonomuto/angular-ui-form-validation
|
dist/bower_components/lazy.js/lazy.js
|
defineSequenceType
|
function defineSequenceType(base, name, overrides) {
/** @constructor */
var ctor = function ctor() {};
// Make this type inherit from the specified base.
ctor.prototype = new base();
// Attach overrides to the new sequence type's prototype.
for (var override in overrides) {
ctor.prototype[override] = overrides[override];
}
// Define a factory method that sets the new sequence's parent to the caller
// and (optionally) applies any additional initialization logic.
// Expose this as a chainable method so that we can do:
// Lazy(...).map(...).filter(...).blah(...);
var factory = function factory() {
var sequence = new ctor();
// Every sequence needs a reference to its parent in order to work.
sequence.parent = this;
// If a custom init function was supplied, call it now.
if (sequence.init) {
sequence.init.apply(sequence, arguments);
}
return sequence;
};
var methodNames = typeof name === 'string' ? [name] : name;
for (var i = 0; i < methodNames.length; ++i) {
base.prototype[methodNames[i]] = factory;
}
return ctor;
}
|
javascript
|
function defineSequenceType(base, name, overrides) {
/** @constructor */
var ctor = function ctor() {};
// Make this type inherit from the specified base.
ctor.prototype = new base();
// Attach overrides to the new sequence type's prototype.
for (var override in overrides) {
ctor.prototype[override] = overrides[override];
}
// Define a factory method that sets the new sequence's parent to the caller
// and (optionally) applies any additional initialization logic.
// Expose this as a chainable method so that we can do:
// Lazy(...).map(...).filter(...).blah(...);
var factory = function factory() {
var sequence = new ctor();
// Every sequence needs a reference to its parent in order to work.
sequence.parent = this;
// If a custom init function was supplied, call it now.
if (sequence.init) {
sequence.init.apply(sequence, arguments);
}
return sequence;
};
var methodNames = typeof name === 'string' ? [name] : name;
for (var i = 0; i < methodNames.length; ++i) {
base.prototype[methodNames[i]] = factory;
}
return ctor;
}
|
[
"function",
"defineSequenceType",
"(",
"base",
",",
"name",
",",
"overrides",
")",
"{",
"/** @constructor */",
"var",
"ctor",
"=",
"function",
"ctor",
"(",
")",
"{",
"}",
";",
"// Make this type inherit from the specified base.",
"ctor",
".",
"prototype",
"=",
"new",
"base",
"(",
")",
";",
"// Attach overrides to the new sequence type's prototype.",
"for",
"(",
"var",
"override",
"in",
"overrides",
")",
"{",
"ctor",
".",
"prototype",
"[",
"override",
"]",
"=",
"overrides",
"[",
"override",
"]",
";",
"}",
"// Define a factory method that sets the new sequence's parent to the caller",
"// and (optionally) applies any additional initialization logic.",
"// Expose this as a chainable method so that we can do:",
"// Lazy(...).map(...).filter(...).blah(...);",
"var",
"factory",
"=",
"function",
"factory",
"(",
")",
"{",
"var",
"sequence",
"=",
"new",
"ctor",
"(",
")",
";",
"// Every sequence needs a reference to its parent in order to work.",
"sequence",
".",
"parent",
"=",
"this",
";",
"// If a custom init function was supplied, call it now.",
"if",
"(",
"sequence",
".",
"init",
")",
"{",
"sequence",
".",
"init",
".",
"apply",
"(",
"sequence",
",",
"arguments",
")",
";",
"}",
"return",
"sequence",
";",
"}",
";",
"var",
"methodNames",
"=",
"typeof",
"name",
"===",
"'string'",
"?",
"[",
"name",
"]",
":",
"name",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"methodNames",
".",
"length",
";",
"++",
"i",
")",
"{",
"base",
".",
"prototype",
"[",
"methodNames",
"[",
"i",
"]",
"]",
"=",
"factory",
";",
"}",
"return",
"ctor",
";",
"}"
] |
Shared base method for defining new sequence types.
|
[
"Shared",
"base",
"method",
"for",
"defining",
"new",
"sequence",
"types",
"."
] |
5ab88160fe3512e0a7abbb369aaf0af652753766
|
https://github.com/nelsonomuto/angular-ui-form-validation/blob/5ab88160fe3512e0a7abbb369aaf0af652753766/dist/bower_components/lazy.js/lazy.js#L5750-L5786
|
train
|
nelsonomuto/angular-ui-form-validation
|
dist/bower_components/log4js/log4js-site/xdocs/skins/common/scripts/breadcrumbs.js
|
getDirectoriesInURL
|
function getDirectoriesInURL()
{
var trail = document.location.pathname.split( PATH_SEPARATOR );
// check whether last section is a file or a directory
var lastcrumb = trail[trail.length-1];
for( var i = 0; i < FILE_EXTENSIONS.length; i++ )
{
if( lastcrumb.indexOf( FILE_EXTENSIONS[i] ) )
{
// it is, remove it and send results
return trail.slice( 1, trail.length-1 );
}
}
// it's not; send the trail unmodified
return trail.slice( 1, trail.length );
}
|
javascript
|
function getDirectoriesInURL()
{
var trail = document.location.pathname.split( PATH_SEPARATOR );
// check whether last section is a file or a directory
var lastcrumb = trail[trail.length-1];
for( var i = 0; i < FILE_EXTENSIONS.length; i++ )
{
if( lastcrumb.indexOf( FILE_EXTENSIONS[i] ) )
{
// it is, remove it and send results
return trail.slice( 1, trail.length-1 );
}
}
// it's not; send the trail unmodified
return trail.slice( 1, trail.length );
}
|
[
"function",
"getDirectoriesInURL",
"(",
")",
"{",
"var",
"trail",
"=",
"document",
".",
"location",
".",
"pathname",
".",
"split",
"(",
"PATH_SEPARATOR",
")",
";",
"// check whether last section is a file or a directory",
"var",
"lastcrumb",
"=",
"trail",
"[",
"trail",
".",
"length",
"-",
"1",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"FILE_EXTENSIONS",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"lastcrumb",
".",
"indexOf",
"(",
"FILE_EXTENSIONS",
"[",
"i",
"]",
")",
")",
"{",
"// it is, remove it and send results",
"return",
"trail",
".",
"slice",
"(",
"1",
",",
"trail",
".",
"length",
"-",
"1",
")",
";",
"}",
"}",
"// it's not; send the trail unmodified",
"return",
"trail",
".",
"slice",
"(",
"1",
",",
"trail",
".",
"length",
")",
";",
"}"
] |
Returns an array containing the names of all the directories in the
current document URL
|
[
"Returns",
"an",
"array",
"containing",
"the",
"names",
"of",
"all",
"the",
"directories",
"in",
"the",
"current",
"document",
"URL"
] |
5ab88160fe3512e0a7abbb369aaf0af652753766
|
https://github.com/nelsonomuto/angular-ui-form-validation/blob/5ab88160fe3512e0a7abbb369aaf0af652753766/dist/bower_components/log4js/log4js-site/xdocs/skins/common/scripts/breadcrumbs.js#L124-L141
|
train
|
nelsonomuto/angular-ui-form-validation
|
dist/bower_components/log4js/log4js-site/xdocs/skins/common/scripts/breadcrumbs.js
|
getCrumbTrail
|
function getCrumbTrail( crumbs )
{
var xhtml = DISPLAY_PREPREND;
for( var i = 0; i < crumbs.length; i++ )
{
xhtml += '<a href="' + crumbs[i][1] + '" >';
xhtml += unescape( crumbs[i][0] ) + '</a>';
if( i != (crumbs.length-1) )
{
xhtml += DISPLAY_SEPARATOR;
}
}
xhtml += DISPLAY_POSTPREND;
return xhtml;
}
|
javascript
|
function getCrumbTrail( crumbs )
{
var xhtml = DISPLAY_PREPREND;
for( var i = 0; i < crumbs.length; i++ )
{
xhtml += '<a href="' + crumbs[i][1] + '" >';
xhtml += unescape( crumbs[i][0] ) + '</a>';
if( i != (crumbs.length-1) )
{
xhtml += DISPLAY_SEPARATOR;
}
}
xhtml += DISPLAY_POSTPREND;
return xhtml;
}
|
[
"function",
"getCrumbTrail",
"(",
"crumbs",
")",
"{",
"var",
"xhtml",
"=",
"DISPLAY_PREPREND",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"crumbs",
".",
"length",
";",
"i",
"++",
")",
"{",
"xhtml",
"+=",
"'<a href=\"'",
"+",
"crumbs",
"[",
"i",
"]",
"[",
"1",
"]",
"+",
"'\" >'",
";",
"xhtml",
"+=",
"unescape",
"(",
"crumbs",
"[",
"i",
"]",
"[",
"0",
"]",
")",
"+",
"'</a>'",
";",
"if",
"(",
"i",
"!=",
"(",
"crumbs",
".",
"length",
"-",
"1",
")",
")",
"{",
"xhtml",
"+=",
"DISPLAY_SEPARATOR",
";",
"}",
"}",
"xhtml",
"+=",
"DISPLAY_POSTPREND",
";",
"return",
"xhtml",
";",
"}"
] |
Return a string containing a simple text breadcrumb trail based on the
two-dimensional array passed in.
|
[
"Return",
"a",
"string",
"containing",
"a",
"simple",
"text",
"breadcrumb",
"trail",
"based",
"on",
"the",
"two",
"-",
"dimensional",
"array",
"passed",
"in",
"."
] |
5ab88160fe3512e0a7abbb369aaf0af652753766
|
https://github.com/nelsonomuto/angular-ui-form-validation/blob/5ab88160fe3512e0a7abbb369aaf0af652753766/dist/bower_components/log4js/log4js-site/xdocs/skins/common/scripts/breadcrumbs.js#L180-L197
|
train
|
nelsonomuto/angular-ui-form-validation
|
dist/bower_components/log4js/log4js-site/xdocs/skins/common/scripts/breadcrumbs.js
|
getCrumbTrailXHTML
|
function getCrumbTrailXHTML( crumbs )
{
var xhtml = '<span class="' + CSS_CLASS_TRAIL + '">';
xhtml += DISPLAY_PREPREND;
for( var i = 0; i < crumbs.length; i++ )
{
xhtml += '<a href="' + crumbs[i][1] + '" class="' + CSS_CLASS_CRUMB + '">';
xhtml += unescape( crumbs[i][0] ) + '</a>';
if( i != (crumbs.length-1) )
{
xhtml += '<span class="' + CSS_CLASS_SEPARATOR + '">' + DISPLAY_SEPARATOR + '</span>';
}
}
xhtml += DISPLAY_POSTPREND;
xhtml += '</span>';
return xhtml;
}
|
javascript
|
function getCrumbTrailXHTML( crumbs )
{
var xhtml = '<span class="' + CSS_CLASS_TRAIL + '">';
xhtml += DISPLAY_PREPREND;
for( var i = 0; i < crumbs.length; i++ )
{
xhtml += '<a href="' + crumbs[i][1] + '" class="' + CSS_CLASS_CRUMB + '">';
xhtml += unescape( crumbs[i][0] ) + '</a>';
if( i != (crumbs.length-1) )
{
xhtml += '<span class="' + CSS_CLASS_SEPARATOR + '">' + DISPLAY_SEPARATOR + '</span>';
}
}
xhtml += DISPLAY_POSTPREND;
xhtml += '</span>';
return xhtml;
}
|
[
"function",
"getCrumbTrailXHTML",
"(",
"crumbs",
")",
"{",
"var",
"xhtml",
"=",
"'<span class=\"'",
"+",
"CSS_CLASS_TRAIL",
"+",
"'\">'",
";",
"xhtml",
"+=",
"DISPLAY_PREPREND",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"crumbs",
".",
"length",
";",
"i",
"++",
")",
"{",
"xhtml",
"+=",
"'<a href=\"'",
"+",
"crumbs",
"[",
"i",
"]",
"[",
"1",
"]",
"+",
"'\" class=\"'",
"+",
"CSS_CLASS_CRUMB",
"+",
"'\">'",
";",
"xhtml",
"+=",
"unescape",
"(",
"crumbs",
"[",
"i",
"]",
"[",
"0",
"]",
")",
"+",
"'</a>'",
";",
"if",
"(",
"i",
"!=",
"(",
"crumbs",
".",
"length",
"-",
"1",
")",
")",
"{",
"xhtml",
"+=",
"'<span class=\"'",
"+",
"CSS_CLASS_SEPARATOR",
"+",
"'\">'",
"+",
"DISPLAY_SEPARATOR",
"+",
"'</span>'",
";",
"}",
"}",
"xhtml",
"+=",
"DISPLAY_POSTPREND",
";",
"xhtml",
"+=",
"'</span>'",
";",
"return",
"xhtml",
";",
"}"
] |
Return a string containing an XHTML breadcrumb trail based on the
two-dimensional array passed in.
|
[
"Return",
"a",
"string",
"containing",
"an",
"XHTML",
"breadcrumb",
"trail",
"based",
"on",
"the",
"two",
"-",
"dimensional",
"array",
"passed",
"in",
"."
] |
5ab88160fe3512e0a7abbb369aaf0af652753766
|
https://github.com/nelsonomuto/angular-ui-form-validation/blob/5ab88160fe3512e0a7abbb369aaf0af652753766/dist/bower_components/log4js/log4js-site/xdocs/skins/common/scripts/breadcrumbs.js#L203-L222
|
train
|
nelsonomuto/angular-ui-form-validation
|
dist/bower_components/log4js/log4js/src/main/js/log4js.js
|
function(categoryName) {
// Use default logger if categoryName is not specified or invalid
if (!(typeof categoryName == "string")) {
categoryName = "[default]";
}
if (!Log4js.loggers[categoryName]) {
// Create the logger for this name if it doesn't already exist
Log4js.loggers[categoryName] = new Log4js.Logger(categoryName);
}
return Log4js.loggers[categoryName];
}
|
javascript
|
function(categoryName) {
// Use default logger if categoryName is not specified or invalid
if (!(typeof categoryName == "string")) {
categoryName = "[default]";
}
if (!Log4js.loggers[categoryName]) {
// Create the logger for this name if it doesn't already exist
Log4js.loggers[categoryName] = new Log4js.Logger(categoryName);
}
return Log4js.loggers[categoryName];
}
|
[
"function",
"(",
"categoryName",
")",
"{",
"// Use default logger if categoryName is not specified or invalid",
"if",
"(",
"!",
"(",
"typeof",
"categoryName",
"==",
"\"string\"",
")",
")",
"{",
"categoryName",
"=",
"\"[default]\"",
";",
"}",
"if",
"(",
"!",
"Log4js",
".",
"loggers",
"[",
"categoryName",
"]",
")",
"{",
"// Create the logger for this name if it doesn't already exist",
"Log4js",
".",
"loggers",
"[",
"categoryName",
"]",
"=",
"new",
"Log4js",
".",
"Logger",
"(",
"categoryName",
")",
";",
"}",
"return",
"Log4js",
".",
"loggers",
"[",
"categoryName",
"]",
";",
"}"
] |
Get a logger instance. Instance is cached on categoryName level.
@param {String} categoryName name of category to log to.
@return {Logger} instance of logger for the category
@static
|
[
"Get",
"a",
"logger",
"instance",
".",
"Instance",
"is",
"cached",
"on",
"categoryName",
"level",
"."
] |
5ab88160fe3512e0a7abbb369aaf0af652753766
|
https://github.com/nelsonomuto/angular-ui-form-validation/blob/5ab88160fe3512e0a7abbb369aaf0af652753766/dist/bower_components/log4js/log4js/src/main/js/log4js.js#L76-L89
|
train
|
|
nelsonomuto/angular-ui-form-validation
|
dist/bower_components/log4js/log4js/src/main/js/log4js.js
|
function (element, name, observer) {
if (element.addEventListener) { //DOM event model
element.addEventListener(name, observer, false);
} else if (element.attachEvent) { //M$ event model
element.attachEvent('on' + name, observer);
}
}
|
javascript
|
function (element, name, observer) {
if (element.addEventListener) { //DOM event model
element.addEventListener(name, observer, false);
} else if (element.attachEvent) { //M$ event model
element.attachEvent('on' + name, observer);
}
}
|
[
"function",
"(",
"element",
",",
"name",
",",
"observer",
")",
"{",
"if",
"(",
"element",
".",
"addEventListener",
")",
"{",
"//DOM event model",
"element",
".",
"addEventListener",
"(",
"name",
",",
"observer",
",",
"false",
")",
";",
"}",
"else",
"if",
"(",
"element",
".",
"attachEvent",
")",
"{",
"//M$ event model",
"element",
".",
"attachEvent",
"(",
"'on'",
"+",
"name",
",",
"observer",
")",
";",
"}",
"}"
] |
Atatch an observer function to an elements event browser independent.
@param element element to attach event
@param name name of event
@param observer observer method to be called
@private
|
[
"Atatch",
"an",
"observer",
"function",
"to",
"an",
"elements",
"event",
"browser",
"independent",
"."
] |
5ab88160fe3512e0a7abbb369aaf0af652753766
|
https://github.com/nelsonomuto/angular-ui-form-validation/blob/5ab88160fe3512e0a7abbb369aaf0af652753766/dist/bower_components/log4js/log4js/src/main/js/log4js.js#L108-L114
|
train
|
|
nelsonomuto/angular-ui-form-validation
|
dist/bower_components/log4js/log4js/src/main/js/log4js.js
|
function(sArg, defaultLevel) {
if(sArg === null) {
return defaultLevel;
}
if(typeof sArg == "string") {
var s = sArg.toUpperCase();
if(s == "ALL") {return Log4js.Level.ALL;}
if(s == "DEBUG") {return Log4js.Level.DEBUG;}
if(s == "INFO") {return Log4js.Level.INFO;}
if(s == "WARN") {return Log4js.Level.WARN;}
if(s == "ERROR") {return Log4js.Level.ERROR;}
if(s == "FATAL") {return Log4js.Level.FATAL;}
if(s == "OFF") {return Log4js.Level.OFF;}
if(s == "TRACE") {return Log4js.Level.TRACE;}
return defaultLevel;
} else if(typeof sArg == "number") {
switch(sArg) {
case ALL_INT: return Log4js.Level.ALL;
case DEBUG_INT: return Log4js.Level.DEBUG;
case INFO_INT: return Log4js.Level.INFO;
case WARN_INT: return Log4js.Level.WARN;
case ERROR_INT: return Log4js.Level.ERROR;
case FATAL_INT: return Log4js.Level.FATAL;
case OFF_INT: return Log4js.Level.OFF;
case TRACE_INT: return Log4js.Level.TRACE;
default: return defaultLevel;
}
} else {
return defaultLevel;
}
}
|
javascript
|
function(sArg, defaultLevel) {
if(sArg === null) {
return defaultLevel;
}
if(typeof sArg == "string") {
var s = sArg.toUpperCase();
if(s == "ALL") {return Log4js.Level.ALL;}
if(s == "DEBUG") {return Log4js.Level.DEBUG;}
if(s == "INFO") {return Log4js.Level.INFO;}
if(s == "WARN") {return Log4js.Level.WARN;}
if(s == "ERROR") {return Log4js.Level.ERROR;}
if(s == "FATAL") {return Log4js.Level.FATAL;}
if(s == "OFF") {return Log4js.Level.OFF;}
if(s == "TRACE") {return Log4js.Level.TRACE;}
return defaultLevel;
} else if(typeof sArg == "number") {
switch(sArg) {
case ALL_INT: return Log4js.Level.ALL;
case DEBUG_INT: return Log4js.Level.DEBUG;
case INFO_INT: return Log4js.Level.INFO;
case WARN_INT: return Log4js.Level.WARN;
case ERROR_INT: return Log4js.Level.ERROR;
case FATAL_INT: return Log4js.Level.FATAL;
case OFF_INT: return Log4js.Level.OFF;
case TRACE_INT: return Log4js.Level.TRACE;
default: return defaultLevel;
}
} else {
return defaultLevel;
}
}
|
[
"function",
"(",
"sArg",
",",
"defaultLevel",
")",
"{",
"if",
"(",
"sArg",
"===",
"null",
")",
"{",
"return",
"defaultLevel",
";",
"}",
"if",
"(",
"typeof",
"sArg",
"==",
"\"string\"",
")",
"{",
"var",
"s",
"=",
"sArg",
".",
"toUpperCase",
"(",
")",
";",
"if",
"(",
"s",
"==",
"\"ALL\"",
")",
"{",
"return",
"Log4js",
".",
"Level",
".",
"ALL",
";",
"}",
"if",
"(",
"s",
"==",
"\"DEBUG\"",
")",
"{",
"return",
"Log4js",
".",
"Level",
".",
"DEBUG",
";",
"}",
"if",
"(",
"s",
"==",
"\"INFO\"",
")",
"{",
"return",
"Log4js",
".",
"Level",
".",
"INFO",
";",
"}",
"if",
"(",
"s",
"==",
"\"WARN\"",
")",
"{",
"return",
"Log4js",
".",
"Level",
".",
"WARN",
";",
"}",
"if",
"(",
"s",
"==",
"\"ERROR\"",
")",
"{",
"return",
"Log4js",
".",
"Level",
".",
"ERROR",
";",
"}",
"if",
"(",
"s",
"==",
"\"FATAL\"",
")",
"{",
"return",
"Log4js",
".",
"Level",
".",
"FATAL",
";",
"}",
"if",
"(",
"s",
"==",
"\"OFF\"",
")",
"{",
"return",
"Log4js",
".",
"Level",
".",
"OFF",
";",
"}",
"if",
"(",
"s",
"==",
"\"TRACE\"",
")",
"{",
"return",
"Log4js",
".",
"Level",
".",
"TRACE",
";",
"}",
"return",
"defaultLevel",
";",
"}",
"else",
"if",
"(",
"typeof",
"sArg",
"==",
"\"number\"",
")",
"{",
"switch",
"(",
"sArg",
")",
"{",
"case",
"ALL_INT",
":",
"return",
"Log4js",
".",
"Level",
".",
"ALL",
";",
"case",
"DEBUG_INT",
":",
"return",
"Log4js",
".",
"Level",
".",
"DEBUG",
";",
"case",
"INFO_INT",
":",
"return",
"Log4js",
".",
"Level",
".",
"INFO",
";",
"case",
"WARN_INT",
":",
"return",
"Log4js",
".",
"Level",
".",
"WARN",
";",
"case",
"ERROR_INT",
":",
"return",
"Log4js",
".",
"Level",
".",
"ERROR",
";",
"case",
"FATAL_INT",
":",
"return",
"Log4js",
".",
"Level",
".",
"FATAL",
";",
"case",
"OFF_INT",
":",
"return",
"Log4js",
".",
"Level",
".",
"OFF",
";",
"case",
"TRACE_INT",
":",
"return",
"Log4js",
".",
"Level",
".",
"TRACE",
";",
"default",
":",
"return",
"defaultLevel",
";",
"}",
"}",
"else",
"{",
"return",
"defaultLevel",
";",
"}",
"}"
] |
converts given String to corresponding Level
@param {String} sArg String value of Level
@param {Log4js.Level} defaultLevel default Level, if no String representation
@return Level object
@type Log4js.Level
|
[
"converts",
"given",
"String",
"to",
"corresponding",
"Level"
] |
5ab88160fe3512e0a7abbb369aaf0af652753766
|
https://github.com/nelsonomuto/angular-ui-form-validation/blob/5ab88160fe3512e0a7abbb369aaf0af652753766/dist/bower_components/log4js/log4js/src/main/js/log4js.js#L191-L223
|
train
|
|
nelsonomuto/angular-ui-form-validation
|
dist/bower_components/log4js/log4js/src/main/js/log4js.js
|
function(appender) {
if (appender instanceof Log4js.Appender) {
appender.setLogger(this);
this.appenders.push(appender);
} else {
throw "Not instance of an Appender: " + appender;
}
}
|
javascript
|
function(appender) {
if (appender instanceof Log4js.Appender) {
appender.setLogger(this);
this.appenders.push(appender);
} else {
throw "Not instance of an Appender: " + appender;
}
}
|
[
"function",
"(",
"appender",
")",
"{",
"if",
"(",
"appender",
"instanceof",
"Log4js",
".",
"Appender",
")",
"{",
"appender",
".",
"setLogger",
"(",
"this",
")",
";",
"this",
".",
"appenders",
".",
"push",
"(",
"appender",
")",
";",
"}",
"else",
"{",
"throw",
"\"Not instance of an Appender: \"",
"+",
"appender",
";",
"}",
"}"
] |
add additional appender. DefaultAppender always is there.
@param appender additional wanted appender
|
[
"add",
"additional",
"appender",
".",
"DefaultAppender",
"always",
"is",
"there",
"."
] |
5ab88160fe3512e0a7abbb369aaf0af652753766
|
https://github.com/nelsonomuto/angular-ui-form-validation/blob/5ab88160fe3512e0a7abbb369aaf0af652753766/dist/bower_components/log4js/log4js/src/main/js/log4js.js#L489-L496
|
train
|
|
nelsonomuto/angular-ui-form-validation
|
dist/bower_components/log4js/log4js/src/main/js/log4js.js
|
function(appenders) {
//clear first all existing appenders
for(var i = 0; i < this.appenders.length; i++) {
this.appenders[i].doClear();
}
this.appenders = appenders;
for(var j = 0; j < this.appenders.length; j++) {
this.appenders[j].setLogger(this);
}
}
|
javascript
|
function(appenders) {
//clear first all existing appenders
for(var i = 0; i < this.appenders.length; i++) {
this.appenders[i].doClear();
}
this.appenders = appenders;
for(var j = 0; j < this.appenders.length; j++) {
this.appenders[j].setLogger(this);
}
}
|
[
"function",
"(",
"appenders",
")",
"{",
"//clear first all existing appenders",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"appenders",
".",
"length",
";",
"i",
"++",
")",
"{",
"this",
".",
"appenders",
"[",
"i",
"]",
".",
"doClear",
"(",
")",
";",
"}",
"this",
".",
"appenders",
"=",
"appenders",
";",
"for",
"(",
"var",
"j",
"=",
"0",
";",
"j",
"<",
"this",
".",
"appenders",
".",
"length",
";",
"j",
"++",
")",
"{",
"this",
".",
"appenders",
"[",
"j",
"]",
".",
"setLogger",
"(",
"this",
")",
";",
"}",
"}"
] |
set Array of appenders. Previous Appenders are cleared and removed.
@param {Array} appenders Array of Appenders
|
[
"set",
"Array",
"of",
"appenders",
".",
"Previous",
"Appenders",
"are",
"cleared",
"and",
"removed",
"."
] |
5ab88160fe3512e0a7abbb369aaf0af652753766
|
https://github.com/nelsonomuto/angular-ui-form-validation/blob/5ab88160fe3512e0a7abbb369aaf0af652753766/dist/bower_components/log4js/log4js/src/main/js/log4js.js#L502-L513
|
train
|
|
nelsonomuto/angular-ui-form-validation
|
dist/bower_components/log4js/log4js/src/main/js/log4js.js
|
function(logLevel, message, exception) {
var loggingEvent = new Log4js.LoggingEvent(this.category, logLevel,
message, exception, this);
this.loggingEvents.push(loggingEvent);
this.onlog.dispatch(loggingEvent);
}
|
javascript
|
function(logLevel, message, exception) {
var loggingEvent = new Log4js.LoggingEvent(this.category, logLevel,
message, exception, this);
this.loggingEvents.push(loggingEvent);
this.onlog.dispatch(loggingEvent);
}
|
[
"function",
"(",
"logLevel",
",",
"message",
",",
"exception",
")",
"{",
"var",
"loggingEvent",
"=",
"new",
"Log4js",
".",
"LoggingEvent",
"(",
"this",
".",
"category",
",",
"logLevel",
",",
"message",
",",
"exception",
",",
"this",
")",
";",
"this",
".",
"loggingEvents",
".",
"push",
"(",
"loggingEvent",
")",
";",
"this",
".",
"onlog",
".",
"dispatch",
"(",
"loggingEvent",
")",
";",
"}"
] |
main log method logging to all available appenders
@private
|
[
"main",
"log",
"method",
"logging",
"to",
"all",
"available",
"appenders"
] |
5ab88160fe3512e0a7abbb369aaf0af652753766
|
https://github.com/nelsonomuto/angular-ui-form-validation/blob/5ab88160fe3512e0a7abbb369aaf0af652753766/dist/bower_components/log4js/log4js/src/main/js/log4js.js#L527-L532
|
train
|
|
nelsonomuto/angular-ui-form-validation
|
dist/bower_components/log4js/log4js/src/main/js/log4js.js
|
function(msg, url, line){
var message = "Error in (" + (url || window.location) + ") on line "+ line +" with message (" + msg + ")";
this.log(Log4js.Level.FATAL, message, null);
}
|
javascript
|
function(msg, url, line){
var message = "Error in (" + (url || window.location) + ") on line "+ line +" with message (" + msg + ")";
this.log(Log4js.Level.FATAL, message, null);
}
|
[
"function",
"(",
"msg",
",",
"url",
",",
"line",
")",
"{",
"var",
"message",
"=",
"\"Error in (\"",
"+",
"(",
"url",
"||",
"window",
".",
"location",
")",
"+",
"\") on line \"",
"+",
"line",
"+",
"\" with message (\"",
"+",
"msg",
"+",
"\")\"",
";",
"this",
".",
"log",
"(",
"Log4js",
".",
"Level",
".",
"FATAL",
",",
"message",
",",
"null",
")",
";",
"}"
] |
Capture main window errors and log as fatal.
@private
|
[
"Capture",
"main",
"window",
"errors",
"and",
"log",
"as",
"fatal",
"."
] |
5ab88160fe3512e0a7abbb369aaf0af652753766
|
https://github.com/nelsonomuto/angular-ui-form-validation/blob/5ab88160fe3512e0a7abbb369aaf0af652753766/dist/bower_components/log4js/log4js/src/main/js/log4js.js#L671-L674
|
train
|
|
nelsonomuto/angular-ui-form-validation
|
dist/bower_components/log4js/log4js/src/main/js/log4js.js
|
function(logger){
// add listener to the logger methods
logger.onlog.addListener(Log4js.bind(this.doAppend, this));
logger.onclear.addListener(Log4js.bind(this.doClear, this));
this.logger = logger;
}
|
javascript
|
function(logger){
// add listener to the logger methods
logger.onlog.addListener(Log4js.bind(this.doAppend, this));
logger.onclear.addListener(Log4js.bind(this.doClear, this));
this.logger = logger;
}
|
[
"function",
"(",
"logger",
")",
"{",
"// add listener to the logger methods",
"logger",
".",
"onlog",
".",
"addListener",
"(",
"Log4js",
".",
"bind",
"(",
"this",
".",
"doAppend",
",",
"this",
")",
")",
";",
"logger",
".",
"onclear",
".",
"addListener",
"(",
"Log4js",
".",
"bind",
"(",
"this",
".",
"doClear",
",",
"this",
")",
")",
";",
"this",
".",
"logger",
"=",
"logger",
";",
"}"
] |
Set reference to the logger.
@param {Log4js.Logger} the invoking logger
|
[
"Set",
"reference",
"to",
"the",
"logger",
"."
] |
5ab88160fe3512e0a7abbb369aaf0af652753766
|
https://github.com/nelsonomuto/angular-ui-form-validation/blob/5ab88160fe3512e0a7abbb369aaf0af652753766/dist/bower_components/log4js/log4js/src/main/js/log4js.js#L747-L753
|
train
|
|
nelsonomuto/angular-ui-form-validation
|
dist/bower_components/log4js/log4js/src/main/js/log4js.js
|
function(loggingEvent) {
log4jsLogger.trace("> AjaxAppender.append");
if (this.loggingEventMap.length() <= this.threshold || this.isInProgress === true) {
this.loggingEventMap.push(loggingEvent);
}
if(this.loggingEventMap.length() >= this.threshold && this.isInProgress === false) {
//if threshold is reached send the events and reset current threshold
this.send();
}
log4jsLogger.trace("< AjaxAppender.append");
}
|
javascript
|
function(loggingEvent) {
log4jsLogger.trace("> AjaxAppender.append");
if (this.loggingEventMap.length() <= this.threshold || this.isInProgress === true) {
this.loggingEventMap.push(loggingEvent);
}
if(this.loggingEventMap.length() >= this.threshold && this.isInProgress === false) {
//if threshold is reached send the events and reset current threshold
this.send();
}
log4jsLogger.trace("< AjaxAppender.append");
}
|
[
"function",
"(",
"loggingEvent",
")",
"{",
"log4jsLogger",
".",
"trace",
"(",
"\"> AjaxAppender.append\"",
")",
";",
"if",
"(",
"this",
".",
"loggingEventMap",
".",
"length",
"(",
")",
"<=",
"this",
".",
"threshold",
"||",
"this",
".",
"isInProgress",
"===",
"true",
")",
"{",
"this",
".",
"loggingEventMap",
".",
"push",
"(",
"loggingEvent",
")",
";",
"}",
"if",
"(",
"this",
".",
"loggingEventMap",
".",
"length",
"(",
")",
">=",
"this",
".",
"threshold",
"&&",
"this",
".",
"isInProgress",
"===",
"false",
")",
"{",
"//if threshold is reached send the events and reset current threshold",
"this",
".",
"send",
"(",
")",
";",
"}",
"log4jsLogger",
".",
"trace",
"(",
"\"< AjaxAppender.append\"",
")",
";",
"}"
] |
sends the logs to the server
@param loggingEvent event to be logged
@see Log4js.Appender#doAppend
|
[
"sends",
"the",
"logs",
"to",
"the",
"server"
] |
5ab88160fe3512e0a7abbb369aaf0af652753766
|
https://github.com/nelsonomuto/angular-ui-form-validation/blob/5ab88160fe3512e0a7abbb369aaf0af652753766/dist/bower_components/log4js/log4js/src/main/js/log4js.js#L1329-L1342
|
train
|
|
nelsonomuto/angular-ui-form-validation
|
dist/bower_components/log4js/log4js/src/main/js/log4js.js
|
function() {
if(this.loggingEventMap.length() >0) {
log4jsLogger.trace("> AjaxAppender.send");
this.isInProgress = true;
var a = [];
for(var i = 0; i < this.loggingEventMap.length() && i < this.threshold; i++) {
a.push(this.layout.format(this.loggingEventMap.pull()));
}
var content = this.layout.getHeader();
content += a.join(this.layout.getSeparator());
content += this.layout.getFooter();
var appender = this;
if(this.httpRequest === null){
this.httpRequest = this.getXmlHttpRequest();
}
this.httpRequest.onreadystatechange = function() {
appender.onReadyStateChanged.call(appender);
};
this.httpRequest.open("POST", this.loggingUrl, true);
// set the request headers.
this.httpRequest.setRequestHeader("Content-type", this.layout.getContentType());
this.httpRequest.send( content );
appender = this;
try {
window.setTimeout(function(){
log4jsLogger.trace("> AjaxAppender.timeout");
appender.httpRequest.onreadystatechange = function(){return;};
appender.httpRequest.abort();
//this.httpRequest = null;
appender.isInProgress = false;
if(appender.loggingEventMap.length() > 0) {
appender.send();
}
log4jsLogger.trace("< AjaxAppender.timeout");
}, this.timeout);
} catch (e) {
log4jsLogger.fatal(e);
}
log4jsLogger.trace("> AjaxAppender.send");
}
}
|
javascript
|
function() {
if(this.loggingEventMap.length() >0) {
log4jsLogger.trace("> AjaxAppender.send");
this.isInProgress = true;
var a = [];
for(var i = 0; i < this.loggingEventMap.length() && i < this.threshold; i++) {
a.push(this.layout.format(this.loggingEventMap.pull()));
}
var content = this.layout.getHeader();
content += a.join(this.layout.getSeparator());
content += this.layout.getFooter();
var appender = this;
if(this.httpRequest === null){
this.httpRequest = this.getXmlHttpRequest();
}
this.httpRequest.onreadystatechange = function() {
appender.onReadyStateChanged.call(appender);
};
this.httpRequest.open("POST", this.loggingUrl, true);
// set the request headers.
this.httpRequest.setRequestHeader("Content-type", this.layout.getContentType());
this.httpRequest.send( content );
appender = this;
try {
window.setTimeout(function(){
log4jsLogger.trace("> AjaxAppender.timeout");
appender.httpRequest.onreadystatechange = function(){return;};
appender.httpRequest.abort();
//this.httpRequest = null;
appender.isInProgress = false;
if(appender.loggingEventMap.length() > 0) {
appender.send();
}
log4jsLogger.trace("< AjaxAppender.timeout");
}, this.timeout);
} catch (e) {
log4jsLogger.fatal(e);
}
log4jsLogger.trace("> AjaxAppender.send");
}
}
|
[
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"loggingEventMap",
".",
"length",
"(",
")",
">",
"0",
")",
"{",
"log4jsLogger",
".",
"trace",
"(",
"\"> AjaxAppender.send\"",
")",
";",
"this",
".",
"isInProgress",
"=",
"true",
";",
"var",
"a",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"loggingEventMap",
".",
"length",
"(",
")",
"&&",
"i",
"<",
"this",
".",
"threshold",
";",
"i",
"++",
")",
"{",
"a",
".",
"push",
"(",
"this",
".",
"layout",
".",
"format",
"(",
"this",
".",
"loggingEventMap",
".",
"pull",
"(",
")",
")",
")",
";",
"}",
"var",
"content",
"=",
"this",
".",
"layout",
".",
"getHeader",
"(",
")",
";",
"content",
"+=",
"a",
".",
"join",
"(",
"this",
".",
"layout",
".",
"getSeparator",
"(",
")",
")",
";",
"content",
"+=",
"this",
".",
"layout",
".",
"getFooter",
"(",
")",
";",
"var",
"appender",
"=",
"this",
";",
"if",
"(",
"this",
".",
"httpRequest",
"===",
"null",
")",
"{",
"this",
".",
"httpRequest",
"=",
"this",
".",
"getXmlHttpRequest",
"(",
")",
";",
"}",
"this",
".",
"httpRequest",
".",
"onreadystatechange",
"=",
"function",
"(",
")",
"{",
"appender",
".",
"onReadyStateChanged",
".",
"call",
"(",
"appender",
")",
";",
"}",
";",
"this",
".",
"httpRequest",
".",
"open",
"(",
"\"POST\"",
",",
"this",
".",
"loggingUrl",
",",
"true",
")",
";",
"// set the request headers.",
"this",
".",
"httpRequest",
".",
"setRequestHeader",
"(",
"\"Content-type\"",
",",
"this",
".",
"layout",
".",
"getContentType",
"(",
")",
")",
";",
"this",
".",
"httpRequest",
".",
"send",
"(",
"content",
")",
";",
"appender",
"=",
"this",
";",
"try",
"{",
"window",
".",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"log4jsLogger",
".",
"trace",
"(",
"\"> AjaxAppender.timeout\"",
")",
";",
"appender",
".",
"httpRequest",
".",
"onreadystatechange",
"=",
"function",
"(",
")",
"{",
"return",
";",
"}",
";",
"appender",
".",
"httpRequest",
".",
"abort",
"(",
")",
";",
"//this.httpRequest = null;",
"appender",
".",
"isInProgress",
"=",
"false",
";",
"if",
"(",
"appender",
".",
"loggingEventMap",
".",
"length",
"(",
")",
">",
"0",
")",
"{",
"appender",
".",
"send",
"(",
")",
";",
"}",
"log4jsLogger",
".",
"trace",
"(",
"\"< AjaxAppender.timeout\"",
")",
";",
"}",
",",
"this",
".",
"timeout",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"log4jsLogger",
".",
"fatal",
"(",
"e",
")",
";",
"}",
"log4jsLogger",
".",
"trace",
"(",
"\"> AjaxAppender.send\"",
")",
";",
"}",
"}"
] |
send the request.
|
[
"send",
"the",
"request",
"."
] |
5ab88160fe3512e0a7abbb369aaf0af652753766
|
https://github.com/nelsonomuto/angular-ui-form-validation/blob/5ab88160fe3512e0a7abbb369aaf0af652753766/dist/bower_components/log4js/log4js/src/main/js/log4js.js#L1375-L1425
|
train
|
|
nelsonomuto/angular-ui-form-validation
|
dist/bower_components/log4js/log4js/src/main/js/log4js.js
|
function() {
log4jsLogger.trace("> AjaxAppender.getXmlHttpRequest");
var httpRequest = false;
try {
if (window.XMLHttpRequest) { // Mozilla, Safari, IE7...
httpRequest = new XMLHttpRequest();
if (httpRequest.overrideMimeType) {
httpRequest.overrideMimeType(this.layout.getContentType());
}
} else if (window.ActiveXObject) { // IE
try {
httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
}
} catch (e) {
httpRequest = false;
}
if (!httpRequest) {
log4jsLogger.fatal("Unfortunatelly your browser does not support AjaxAppender for log4js!");
}
log4jsLogger.trace("< AjaxAppender.getXmlHttpRequest");
return httpRequest;
}
|
javascript
|
function() {
log4jsLogger.trace("> AjaxAppender.getXmlHttpRequest");
var httpRequest = false;
try {
if (window.XMLHttpRequest) { // Mozilla, Safari, IE7...
httpRequest = new XMLHttpRequest();
if (httpRequest.overrideMimeType) {
httpRequest.overrideMimeType(this.layout.getContentType());
}
} else if (window.ActiveXObject) { // IE
try {
httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
}
} catch (e) {
httpRequest = false;
}
if (!httpRequest) {
log4jsLogger.fatal("Unfortunatelly your browser does not support AjaxAppender for log4js!");
}
log4jsLogger.trace("< AjaxAppender.getXmlHttpRequest");
return httpRequest;
}
|
[
"function",
"(",
")",
"{",
"log4jsLogger",
".",
"trace",
"(",
"\"> AjaxAppender.getXmlHttpRequest\"",
")",
";",
"var",
"httpRequest",
"=",
"false",
";",
"try",
"{",
"if",
"(",
"window",
".",
"XMLHttpRequest",
")",
"{",
"// Mozilla, Safari, IE7...",
"httpRequest",
"=",
"new",
"XMLHttpRequest",
"(",
")",
";",
"if",
"(",
"httpRequest",
".",
"overrideMimeType",
")",
"{",
"httpRequest",
".",
"overrideMimeType",
"(",
"this",
".",
"layout",
".",
"getContentType",
"(",
")",
")",
";",
"}",
"}",
"else",
"if",
"(",
"window",
".",
"ActiveXObject",
")",
"{",
"// IE",
"try",
"{",
"httpRequest",
"=",
"new",
"ActiveXObject",
"(",
"\"Msxml2.XMLHTTP\"",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"httpRequest",
"=",
"new",
"ActiveXObject",
"(",
"\"Microsoft.XMLHTTP\"",
")",
";",
"}",
"}",
"}",
"catch",
"(",
"e",
")",
"{",
"httpRequest",
"=",
"false",
";",
"}",
"if",
"(",
"!",
"httpRequest",
")",
"{",
"log4jsLogger",
".",
"fatal",
"(",
"\"Unfortunatelly your browser does not support AjaxAppender for log4js!\"",
")",
";",
"}",
"log4jsLogger",
".",
"trace",
"(",
"\"< AjaxAppender.getXmlHttpRequest\"",
")",
";",
"return",
"httpRequest",
";",
"}"
] |
Get the XMLHttpRequest object independent of browser.
@private
|
[
"Get",
"the",
"XMLHttpRequest",
"object",
"independent",
"of",
"browser",
"."
] |
5ab88160fe3512e0a7abbb369aaf0af652753766
|
https://github.com/nelsonomuto/angular-ui-form-validation/blob/5ab88160fe3512e0a7abbb369aaf0af652753766/dist/bower_components/log4js/log4js/src/main/js/log4js.js#L1457-L1485
|
train
|
|
nelsonomuto/angular-ui-form-validation
|
dist/bower_components/log4js/log4js/src/main/js/log4js.js
|
function(ex) {
if (ex) {
var exStr = "\t<log4js:throwable>";
if (ex.message) {
exStr += "\t\t<log4js:message><![CDATA[" + this.escapeCdata(ex.message) + "]]></log4js:message>\n";
}
if (ex.description) {
exStr += "\t\t<log4js:description><![CDATA[" + this.escapeCdata(ex.description) + "]]></log4js:description>\n";
}
exStr += "\t\t<log4js:stacktrace>";
exStr += "\t\t\t<log4js:location fileName=\""+ex.fileName+"\" lineNumber=\""+ex.lineNumber+"\" />";
exStr += "\t\t</log4js:stacktrace>";
exStr = "\t</log4js:throwable>";
return exStr;
}
return null;
}
|
javascript
|
function(ex) {
if (ex) {
var exStr = "\t<log4js:throwable>";
if (ex.message) {
exStr += "\t\t<log4js:message><![CDATA[" + this.escapeCdata(ex.message) + "]]></log4js:message>\n";
}
if (ex.description) {
exStr += "\t\t<log4js:description><![CDATA[" + this.escapeCdata(ex.description) + "]]></log4js:description>\n";
}
exStr += "\t\t<log4js:stacktrace>";
exStr += "\t\t\t<log4js:location fileName=\""+ex.fileName+"\" lineNumber=\""+ex.lineNumber+"\" />";
exStr += "\t\t</log4js:stacktrace>";
exStr = "\t</log4js:throwable>";
return exStr;
}
return null;
}
|
[
"function",
"(",
"ex",
")",
"{",
"if",
"(",
"ex",
")",
"{",
"var",
"exStr",
"=",
"\"\\t<log4js:throwable>\"",
";",
"if",
"(",
"ex",
".",
"message",
")",
"{",
"exStr",
"+=",
"\"\\t\\t<log4js:message><![CDATA[\"",
"+",
"this",
".",
"escapeCdata",
"(",
"ex",
".",
"message",
")",
"+",
"\"]]></log4js:message>\\n\"",
";",
"}",
"if",
"(",
"ex",
".",
"description",
")",
"{",
"exStr",
"+=",
"\"\\t\\t<log4js:description><![CDATA[\"",
"+",
"this",
".",
"escapeCdata",
"(",
"ex",
".",
"description",
")",
"+",
"\"]]></log4js:description>\\n\"",
";",
"}",
"exStr",
"+=",
"\"\\t\\t<log4js:stacktrace>\"",
";",
"exStr",
"+=",
"\"\\t\\t\\t<log4js:location fileName=\\\"\"",
"+",
"ex",
".",
"fileName",
"+",
"\"\\\" lineNumber=\\\"\"",
"+",
"ex",
".",
"lineNumber",
"+",
"\"\\\" />\"",
";",
"exStr",
"+=",
"\"\\t\\t</log4js:stacktrace>\"",
";",
"exStr",
"=",
"\"\\t</log4js:throwable>\"",
";",
"return",
"exStr",
";",
"}",
"return",
"null",
";",
"}"
] |
better readable formatted Exceptions.
@param ex {Exception} the exception to be formatted.
@return {String} the formatted String representation of the exception.
@private
|
[
"better",
"readable",
"formatted",
"Exceptions",
"."
] |
5ab88160fe3512e0a7abbb369aaf0af652753766
|
https://github.com/nelsonomuto/angular-ui-form-validation/blob/5ab88160fe3512e0a7abbb369aaf0af652753766/dist/bower_components/log4js/log4js/src/main/js/log4js.js#L2115-L2132
|
train
|
|
localytics/lambda-slack-router
|
index.js
|
SlackBot
|
function SlackBot(config) {
this.config = config || {};
this.commands = {};
this.aliases = {};
if (!this.config.structureResponse) {
this.config.structureResponse = function (response) {
return response;
};
}
}
|
javascript
|
function SlackBot(config) {
this.config = config || {};
this.commands = {};
this.aliases = {};
if (!this.config.structureResponse) {
this.config.structureResponse = function (response) {
return response;
};
}
}
|
[
"function",
"SlackBot",
"(",
"config",
")",
"{",
"this",
".",
"config",
"=",
"config",
"||",
"{",
"}",
";",
"this",
".",
"commands",
"=",
"{",
"}",
";",
"this",
".",
"aliases",
"=",
"{",
"}",
";",
"if",
"(",
"!",
"this",
".",
"config",
".",
"structureResponse",
")",
"{",
"this",
".",
"config",
".",
"structureResponse",
"=",
"function",
"(",
"response",
")",
"{",
"return",
"response",
";",
"}",
";",
"}",
"}"
] |
wraps logic around routing
|
[
"wraps",
"logic",
"around",
"routing"
] |
824e864080188a5146c08cb426c986ff1defdbcc
|
https://github.com/localytics/lambda-slack-router/blob/824e864080188a5146c08cb426c986ff1defdbcc/index.js#L7-L17
|
train
|
donejs/autorender
|
src/init.js
|
translate
|
function translate(load){
var filename;
//!steal-remove-start
filename = getFilename(load.name);
//!steal-remove-end
var result = parse(load.source, this, zoneOpts);
// Add any import specifiers to the load.
addImportSpecifiers(load, result);
load.metadata.originalSource = load.source;
// Register dynamic imports for the slim loader config
var localLoader = loader.localLoader || loader;
if (localLoader.slimConfig) {
localLoader.slimConfig.needsDynamicLoader = true;
var toMap = localLoader.slimConfig.toMap;
Array.prototype.push.apply(toMap, result.rawImports);
Array.prototype.push.apply(toMap, result.dynamicImports);
}
// For live-reload, determine if we should reload the viewModel
hasDynamicImports = result.dynamicImports.length > 0;
return Promise.all([
addBundles(result.dynamicImports, load.name),
Promise.all(result.imports)
]).then(function(pResults){
var exportedValuesDef = Object.keys(result.ases)
.map(function(name){
return "\"" + name + "\": {\n" +
"\t\t\tenumerable: true,\n" +
"\t\t\tconfigurable: true,\n" +
"\t\t\twritable: true,\n" +
"\t\t\tvalue: " + name + "['default'] || " + name + "\n" +
"\t\t}";
}).join(",\n");
var output = template({
imports: JSON.stringify(pResults[1]),
isDevelopment: isDevelopment || false,
routeData: result.viewModel.routeData || "",
args: result.args.join(", "),
zoneOpts: JSON.stringify(zoneOpts),
intermediate: JSON.stringify(result.intermediate),
ases: exportedValuesDef ? exportedValuesDef + "," : "",
filename: filename
});
return output;
});
}
|
javascript
|
function translate(load){
var filename;
//!steal-remove-start
filename = getFilename(load.name);
//!steal-remove-end
var result = parse(load.source, this, zoneOpts);
// Add any import specifiers to the load.
addImportSpecifiers(load, result);
load.metadata.originalSource = load.source;
// Register dynamic imports for the slim loader config
var localLoader = loader.localLoader || loader;
if (localLoader.slimConfig) {
localLoader.slimConfig.needsDynamicLoader = true;
var toMap = localLoader.slimConfig.toMap;
Array.prototype.push.apply(toMap, result.rawImports);
Array.prototype.push.apply(toMap, result.dynamicImports);
}
// For live-reload, determine if we should reload the viewModel
hasDynamicImports = result.dynamicImports.length > 0;
return Promise.all([
addBundles(result.dynamicImports, load.name),
Promise.all(result.imports)
]).then(function(pResults){
var exportedValuesDef = Object.keys(result.ases)
.map(function(name){
return "\"" + name + "\": {\n" +
"\t\t\tenumerable: true,\n" +
"\t\t\tconfigurable: true,\n" +
"\t\t\twritable: true,\n" +
"\t\t\tvalue: " + name + "['default'] || " + name + "\n" +
"\t\t}";
}).join(",\n");
var output = template({
imports: JSON.stringify(pResults[1]),
isDevelopment: isDevelopment || false,
routeData: result.viewModel.routeData || "",
args: result.args.join(", "),
zoneOpts: JSON.stringify(zoneOpts),
intermediate: JSON.stringify(result.intermediate),
ases: exportedValuesDef ? exportedValuesDef + "," : "",
filename: filename
});
return output;
});
}
|
[
"function",
"translate",
"(",
"load",
")",
"{",
"var",
"filename",
";",
"//!steal-remove-start",
"filename",
"=",
"getFilename",
"(",
"load",
".",
"name",
")",
";",
"//!steal-remove-end",
"var",
"result",
"=",
"parse",
"(",
"load",
".",
"source",
",",
"this",
",",
"zoneOpts",
")",
";",
"// Add any import specifiers to the load.",
"addImportSpecifiers",
"(",
"load",
",",
"result",
")",
";",
"load",
".",
"metadata",
".",
"originalSource",
"=",
"load",
".",
"source",
";",
"// Register dynamic imports for the slim loader config",
"var",
"localLoader",
"=",
"loader",
".",
"localLoader",
"||",
"loader",
";",
"if",
"(",
"localLoader",
".",
"slimConfig",
")",
"{",
"localLoader",
".",
"slimConfig",
".",
"needsDynamicLoader",
"=",
"true",
";",
"var",
"toMap",
"=",
"localLoader",
".",
"slimConfig",
".",
"toMap",
";",
"Array",
".",
"prototype",
".",
"push",
".",
"apply",
"(",
"toMap",
",",
"result",
".",
"rawImports",
")",
";",
"Array",
".",
"prototype",
".",
"push",
".",
"apply",
"(",
"toMap",
",",
"result",
".",
"dynamicImports",
")",
";",
"}",
"// For live-reload, determine if we should reload the viewModel",
"hasDynamicImports",
"=",
"result",
".",
"dynamicImports",
".",
"length",
">",
"0",
";",
"return",
"Promise",
".",
"all",
"(",
"[",
"addBundles",
"(",
"result",
".",
"dynamicImports",
",",
"load",
".",
"name",
")",
",",
"Promise",
".",
"all",
"(",
"result",
".",
"imports",
")",
"]",
")",
".",
"then",
"(",
"function",
"(",
"pResults",
")",
"{",
"var",
"exportedValuesDef",
"=",
"Object",
".",
"keys",
"(",
"result",
".",
"ases",
")",
".",
"map",
"(",
"function",
"(",
"name",
")",
"{",
"return",
"\"\\\"\"",
"+",
"name",
"+",
"\"\\\": {\\n\"",
"+",
"\"\\t\\t\\tenumerable: true,\\n\"",
"+",
"\"\\t\\t\\tconfigurable: true,\\n\"",
"+",
"\"\\t\\t\\twritable: true,\\n\"",
"+",
"\"\\t\\t\\tvalue: \"",
"+",
"name",
"+",
"\"['default'] || \"",
"+",
"name",
"+",
"\"\\n\"",
"+",
"\"\\t\\t}\"",
";",
"}",
")",
".",
"join",
"(",
"\",\\n\"",
")",
";",
"var",
"output",
"=",
"template",
"(",
"{",
"imports",
":",
"JSON",
".",
"stringify",
"(",
"pResults",
"[",
"1",
"]",
")",
",",
"isDevelopment",
":",
"isDevelopment",
"||",
"false",
",",
"routeData",
":",
"result",
".",
"viewModel",
".",
"routeData",
"||",
"\"\"",
",",
"args",
":",
"result",
".",
"args",
".",
"join",
"(",
"\", \"",
")",
",",
"zoneOpts",
":",
"JSON",
".",
"stringify",
"(",
"zoneOpts",
")",
",",
"intermediate",
":",
"JSON",
".",
"stringify",
"(",
"result",
".",
"intermediate",
")",
",",
"ases",
":",
"exportedValuesDef",
"?",
"exportedValuesDef",
"+",
"\",\"",
":",
"\"\"",
",",
"filename",
":",
"filename",
"}",
")",
";",
"return",
"output",
";",
"}",
")",
";",
"}"
] |
!steal-remove-end Takes the stache template and translates it to JS.
|
[
"!steal",
"-",
"remove",
"-",
"end",
"Takes",
"the",
"stache",
"template",
"and",
"translates",
"it",
"to",
"JS",
"."
] |
f3434239969b23181c4a456f784bfb84ea955efb
|
https://github.com/donejs/autorender/blob/f3434239969b23181c4a456f784bfb84ea955efb/src/init.js#L72-L124
|
train
|
hakib/MassAutocomplete
|
massautocomplete.js
|
ensure_element_id
|
function ensure_element_id(element) {
if (!element.id || element.id === '') {
element.id = config.generate_random_id('ac_element');
return true;
}
return false;
}
|
javascript
|
function ensure_element_id(element) {
if (!element.id || element.id === '') {
element.id = config.generate_random_id('ac_element');
return true;
}
return false;
}
|
[
"function",
"ensure_element_id",
"(",
"element",
")",
"{",
"if",
"(",
"!",
"element",
".",
"id",
"||",
"element",
".",
"id",
"===",
"''",
")",
"{",
"element",
".",
"id",
"=",
"config",
".",
"generate_random_id",
"(",
"'ac_element'",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Make sure an element has id. Return true if id was generated.
|
[
"Make",
"sure",
"an",
"element",
"has",
"id",
".",
"Return",
"true",
"if",
"id",
"was",
"generated",
"."
] |
6bb50c86f246589aa1a573cb489cd13c1b2ad4e9
|
https://github.com/hakib/MassAutocomplete/blob/6bb50c86f246589aa1a573cb489cd13c1b2ad4e9/massautocomplete.js#L150-L156
|
train
|
hakib/MassAutocomplete
|
massautocomplete.js
|
_attach
|
function _attach(ngmodel, target_element, options) {
// Element is already attached.
if (current_element === target_element) {
return;
}
// Safe: clear previously attached elements.
if (current_element) {
that.detach();
}
// The element is still the active element.
if (target_element[0] !== $document[0].activeElement) {
return;
}
if (options.on_attach) {
options.on_attach();
}
current_element = target_element;
current_model = ngmodel;
current_options = options;
previous_value = ngmodel.$viewValue;
current_element_random_id_set = ensure_element_id(target_element);
$scope.container[0].setAttribute('aria-labelledby', current_element.id);
$scope.results = [];
$scope.selected_index = -1;
bind_element();
value_watch = $scope.$watch(
function() {
return ngmodel.$modelValue;
},
function(nv) {
// Prevent suggestion cycle when the value is the last value selected.
// When selecting from the menu the ng-model is updated and this watch
// is triggered. This causes another suggestion cycle that will provide as
// suggestion the value that is currently selected - this is unnecessary.
if (nv === last_selected_value) {
return;
}
_position_autocomplete();
suggest(nv, current_element);
}
);
}
|
javascript
|
function _attach(ngmodel, target_element, options) {
// Element is already attached.
if (current_element === target_element) {
return;
}
// Safe: clear previously attached elements.
if (current_element) {
that.detach();
}
// The element is still the active element.
if (target_element[0] !== $document[0].activeElement) {
return;
}
if (options.on_attach) {
options.on_attach();
}
current_element = target_element;
current_model = ngmodel;
current_options = options;
previous_value = ngmodel.$viewValue;
current_element_random_id_set = ensure_element_id(target_element);
$scope.container[0].setAttribute('aria-labelledby', current_element.id);
$scope.results = [];
$scope.selected_index = -1;
bind_element();
value_watch = $scope.$watch(
function() {
return ngmodel.$modelValue;
},
function(nv) {
// Prevent suggestion cycle when the value is the last value selected.
// When selecting from the menu the ng-model is updated and this watch
// is triggered. This causes another suggestion cycle that will provide as
// suggestion the value that is currently selected - this is unnecessary.
if (nv === last_selected_value) {
return;
}
_position_autocomplete();
suggest(nv, current_element);
}
);
}
|
[
"function",
"_attach",
"(",
"ngmodel",
",",
"target_element",
",",
"options",
")",
"{",
"// Element is already attached.",
"if",
"(",
"current_element",
"===",
"target_element",
")",
"{",
"return",
";",
"}",
"// Safe: clear previously attached elements.",
"if",
"(",
"current_element",
")",
"{",
"that",
".",
"detach",
"(",
")",
";",
"}",
"// The element is still the active element.",
"if",
"(",
"target_element",
"[",
"0",
"]",
"!==",
"$document",
"[",
"0",
"]",
".",
"activeElement",
")",
"{",
"return",
";",
"}",
"if",
"(",
"options",
".",
"on_attach",
")",
"{",
"options",
".",
"on_attach",
"(",
")",
";",
"}",
"current_element",
"=",
"target_element",
";",
"current_model",
"=",
"ngmodel",
";",
"current_options",
"=",
"options",
";",
"previous_value",
"=",
"ngmodel",
".",
"$viewValue",
";",
"current_element_random_id_set",
"=",
"ensure_element_id",
"(",
"target_element",
")",
";",
"$scope",
".",
"container",
"[",
"0",
"]",
".",
"setAttribute",
"(",
"'aria-labelledby'",
",",
"current_element",
".",
"id",
")",
";",
"$scope",
".",
"results",
"=",
"[",
"]",
";",
"$scope",
".",
"selected_index",
"=",
"-",
"1",
";",
"bind_element",
"(",
")",
";",
"value_watch",
"=",
"$scope",
".",
"$watch",
"(",
"function",
"(",
")",
"{",
"return",
"ngmodel",
".",
"$modelValue",
";",
"}",
",",
"function",
"(",
"nv",
")",
"{",
"// Prevent suggestion cycle when the value is the last value selected.",
"// When selecting from the menu the ng-model is updated and this watch",
"// is triggered. This causes another suggestion cycle that will provide as",
"// suggestion the value that is currently selected - this is unnecessary.",
"if",
"(",
"nv",
"===",
"last_selected_value",
")",
"{",
"return",
";",
"}",
"_position_autocomplete",
"(",
")",
";",
"suggest",
"(",
"nv",
",",
"current_element",
")",
";",
"}",
")",
";",
"}"
] |
Attach autocomplete behavior to an input element.
|
[
"Attach",
"autocomplete",
"behavior",
"to",
"an",
"input",
"element",
"."
] |
6bb50c86f246589aa1a573cb489cd13c1b2ad4e9
|
https://github.com/hakib/MassAutocomplete/blob/6bb50c86f246589aa1a573cb489cd13c1b2ad4e9/massautocomplete.js#L215-L263
|
train
|
hakib/MassAutocomplete
|
massautocomplete.js
|
set_selection
|
function set_selection(i) {
// We use value instead of setting the model's view value
// because we watch the model value and setting it will trigger
// a new suggestion cycle.
var selected = $scope.results[i];
current_element.val(selected.value);
$scope.selected_index = i;
$scope.container[0].setAttribute('aria-activedescendant', selected.id);
return selected;
}
|
javascript
|
function set_selection(i) {
// We use value instead of setting the model's view value
// because we watch the model value and setting it will trigger
// a new suggestion cycle.
var selected = $scope.results[i];
current_element.val(selected.value);
$scope.selected_index = i;
$scope.container[0].setAttribute('aria-activedescendant', selected.id);
return selected;
}
|
[
"function",
"set_selection",
"(",
"i",
")",
"{",
"// We use value instead of setting the model's view value",
"// because we watch the model value and setting it will trigger",
"// a new suggestion cycle.",
"var",
"selected",
"=",
"$scope",
".",
"results",
"[",
"i",
"]",
";",
"current_element",
".",
"val",
"(",
"selected",
".",
"value",
")",
";",
"$scope",
".",
"selected_index",
"=",
"i",
";",
"$scope",
".",
"container",
"[",
"0",
"]",
".",
"setAttribute",
"(",
"'aria-activedescendant'",
",",
"selected",
".",
"id",
")",
";",
"return",
"selected",
";",
"}"
] |
Set the current selection while navigating through the menu.
|
[
"Set",
"the",
"current",
"selection",
"while",
"navigating",
"through",
"the",
"menu",
"."
] |
6bb50c86f246589aa1a573cb489cd13c1b2ad4e9
|
https://github.com/hakib/MassAutocomplete/blob/6bb50c86f246589aa1a573cb489cd13c1b2ad4e9/massautocomplete.js#L310-L319
|
train
|
react-component/rn-packager
|
react-native/local-cli/templates/HelloNavigation/lib/Backend.js
|
fetchChatList
|
async function fetchChatList() {
return _makeSimulatedNetworkRequest((resolve, reject) => {
resolve(backendStateForLoggedInPerson.chats.map(chat => chat.name));
});
}
|
javascript
|
async function fetchChatList() {
return _makeSimulatedNetworkRequest((resolve, reject) => {
resolve(backendStateForLoggedInPerson.chats.map(chat => chat.name));
});
}
|
[
"async",
"function",
"fetchChatList",
"(",
")",
"{",
"return",
"_makeSimulatedNetworkRequest",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"resolve",
"(",
"backendStateForLoggedInPerson",
".",
"chats",
".",
"map",
"(",
"chat",
"=>",
"chat",
".",
"name",
")",
")",
";",
"}",
")",
";",
"}"
] |
Fetch a list of all chats for the logged in person.
|
[
"Fetch",
"a",
"list",
"of",
"all",
"chats",
"for",
"the",
"logged",
"in",
"person",
"."
] |
8fbf4066ff791bc18155fc929d76b6e51be40515
|
https://github.com/react-component/rn-packager/blob/8fbf4066ff791bc18155fc929d76b6e51be40515/react-native/local-cli/templates/HelloNavigation/lib/Backend.js#L62-L66
|
train
|
react-component/rn-packager
|
react-native/local-cli/templates/HelloNavigation/lib/Backend.js
|
fetchChat
|
async function fetchChat(name) {
return _makeSimulatedNetworkRequest((resolve, reject) => {
resolve(
backendStateForLoggedInPerson.chats.find(
chat => chat.name === name
)
);
});
}
|
javascript
|
async function fetchChat(name) {
return _makeSimulatedNetworkRequest((resolve, reject) => {
resolve(
backendStateForLoggedInPerson.chats.find(
chat => chat.name === name
)
);
});
}
|
[
"async",
"function",
"fetchChat",
"(",
"name",
")",
"{",
"return",
"_makeSimulatedNetworkRequest",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"resolve",
"(",
"backendStateForLoggedInPerson",
".",
"chats",
".",
"find",
"(",
"chat",
"=>",
"chat",
".",
"name",
"===",
"name",
")",
")",
";",
"}",
")",
";",
"}"
] |
Fetch a single chat.
|
[
"Fetch",
"a",
"single",
"chat",
"."
] |
8fbf4066ff791bc18155fc929d76b6e51be40515
|
https://github.com/react-component/rn-packager/blob/8fbf4066ff791bc18155fc929d76b6e51be40515/react-native/local-cli/templates/HelloNavigation/lib/Backend.js#L71-L79
|
train
|
react-component/rn-packager
|
react-native/local-cli/templates/HelloNavigation/lib/Backend.js
|
sendMessage
|
async function sendMessage({name, message}) {
return _makeSimulatedNetworkRequest((resolve, reject) => {
const chatForName = backendStateForLoggedInPerson.chats.find(
chat => chat.name === name
);
if (chatForName) {
chatForName.messages.push({
name: 'Me',
text: message,
});
resolve();
} else {
reject(new Error('Uknown person: ' + name));
}
});
}
|
javascript
|
async function sendMessage({name, message}) {
return _makeSimulatedNetworkRequest((resolve, reject) => {
const chatForName = backendStateForLoggedInPerson.chats.find(
chat => chat.name === name
);
if (chatForName) {
chatForName.messages.push({
name: 'Me',
text: message,
});
resolve();
} else {
reject(new Error('Uknown person: ' + name));
}
});
}
|
[
"async",
"function",
"sendMessage",
"(",
"{",
"name",
",",
"message",
"}",
")",
"{",
"return",
"_makeSimulatedNetworkRequest",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"const",
"chatForName",
"=",
"backendStateForLoggedInPerson",
".",
"chats",
".",
"find",
"(",
"chat",
"=>",
"chat",
".",
"name",
"===",
"name",
")",
";",
"if",
"(",
"chatForName",
")",
"{",
"chatForName",
".",
"messages",
".",
"push",
"(",
"{",
"name",
":",
"'Me'",
",",
"text",
":",
"message",
",",
"}",
")",
";",
"resolve",
"(",
")",
";",
"}",
"else",
"{",
"reject",
"(",
"new",
"Error",
"(",
"'Uknown person: '",
"+",
"name",
")",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Send given message to given person.
|
[
"Send",
"given",
"message",
"to",
"given",
"person",
"."
] |
8fbf4066ff791bc18155fc929d76b6e51be40515
|
https://github.com/react-component/rn-packager/blob/8fbf4066ff791bc18155fc929d76b6e51be40515/react-native/local-cli/templates/HelloNavigation/lib/Backend.js#L84-L99
|
train
|
react-component/rn-packager
|
react-native/packager/src/node-haste/lib/getInverseDependencies.js
|
getInverseDependencies
|
function getInverseDependencies(resolutionResponse) {
const cache = new Map();
resolutionResponse.dependencies.forEach(module => {
resolveModuleRequires(resolutionResponse, module).forEach(dependency => {
getModuleDependents(cache, dependency).add(module);
});
});
return cache;
}
|
javascript
|
function getInverseDependencies(resolutionResponse) {
const cache = new Map();
resolutionResponse.dependencies.forEach(module => {
resolveModuleRequires(resolutionResponse, module).forEach(dependency => {
getModuleDependents(cache, dependency).add(module);
});
});
return cache;
}
|
[
"function",
"getInverseDependencies",
"(",
"resolutionResponse",
")",
"{",
"const",
"cache",
"=",
"new",
"Map",
"(",
")",
";",
"resolutionResponse",
".",
"dependencies",
".",
"forEach",
"(",
"module",
"=>",
"{",
"resolveModuleRequires",
"(",
"resolutionResponse",
",",
"module",
")",
".",
"forEach",
"(",
"dependency",
"=>",
"{",
"getModuleDependents",
"(",
"cache",
",",
"dependency",
")",
".",
"add",
"(",
"module",
")",
";",
"}",
")",
";",
"}",
")",
";",
"return",
"cache",
";",
"}"
] |
Returns an object that indicates in which module each module is required.
|
[
"Returns",
"an",
"object",
"that",
"indicates",
"in",
"which",
"module",
"each",
"module",
"is",
"required",
"."
] |
8fbf4066ff791bc18155fc929d76b6e51be40515
|
https://github.com/react-component/rn-packager/blob/8fbf4066ff791bc18155fc929d76b6e51be40515/react-native/packager/src/node-haste/lib/getInverseDependencies.js#L30-L40
|
train
|
react-component/rn-packager
|
react-native/local-cli/server/util/copyToClipBoard.js
|
copyToClipBoard
|
function copyToClipBoard(content) {
switch (process.platform) {
case 'darwin':
var child = spawn('pbcopy', []);
child.stdin.end(new Buffer(content, 'utf8'));
return true;
case 'win32':
var child = spawn('clip', []);
child.stdin.end(new Buffer(content, 'utf8'));
return true;
default:
return false;
}
}
|
javascript
|
function copyToClipBoard(content) {
switch (process.platform) {
case 'darwin':
var child = spawn('pbcopy', []);
child.stdin.end(new Buffer(content, 'utf8'));
return true;
case 'win32':
var child = spawn('clip', []);
child.stdin.end(new Buffer(content, 'utf8'));
return true;
default:
return false;
}
}
|
[
"function",
"copyToClipBoard",
"(",
"content",
")",
"{",
"switch",
"(",
"process",
".",
"platform",
")",
"{",
"case",
"'darwin'",
":",
"var",
"child",
"=",
"spawn",
"(",
"'pbcopy'",
",",
"[",
"]",
")",
";",
"child",
".",
"stdin",
".",
"end",
"(",
"new",
"Buffer",
"(",
"content",
",",
"'utf8'",
")",
")",
";",
"return",
"true",
";",
"case",
"'win32'",
":",
"var",
"child",
"=",
"spawn",
"(",
"'clip'",
",",
"[",
"]",
")",
";",
"child",
".",
"stdin",
".",
"end",
"(",
"new",
"Buffer",
"(",
"content",
",",
"'utf8'",
")",
")",
";",
"return",
"true",
";",
"default",
":",
"return",
"false",
";",
"}",
"}"
] |
Copy the content to host system clipboard.
This is only supported on Mac and Windows for now.
|
[
"Copy",
"the",
"content",
"to",
"host",
"system",
"clipboard",
".",
"This",
"is",
"only",
"supported",
"on",
"Mac",
"and",
"Windows",
"for",
"now",
"."
] |
8fbf4066ff791bc18155fc929d76b6e51be40515
|
https://github.com/react-component/rn-packager/blob/8fbf4066ff791bc18155fc929d76b6e51be40515/react-native/local-cli/server/util/copyToClipBoard.js#L18-L31
|
train
|
ssbc/muxrpc
|
api.js
|
recurse
|
function recurse (obj, manifest, path, remoteCall) {
for(var name in manifest) (function (name, type) {
var _path = path ? path.concat(name) : [name]
obj[name] =
isObject(type)
? recurse({}, type, _path, remoteCall)
: function () {
return remoteCall(type, _path, [].slice.call(arguments))
}
})(name, manifest[name])
return obj
}
|
javascript
|
function recurse (obj, manifest, path, remoteCall) {
for(var name in manifest) (function (name, type) {
var _path = path ? path.concat(name) : [name]
obj[name] =
isObject(type)
? recurse({}, type, _path, remoteCall)
: function () {
return remoteCall(type, _path, [].slice.call(arguments))
}
})(name, manifest[name])
return obj
}
|
[
"function",
"recurse",
"(",
"obj",
",",
"manifest",
",",
"path",
",",
"remoteCall",
")",
"{",
"for",
"(",
"var",
"name",
"in",
"manifest",
")",
"(",
"function",
"(",
"name",
",",
"type",
")",
"{",
"var",
"_path",
"=",
"path",
"?",
"path",
".",
"concat",
"(",
"name",
")",
":",
"[",
"name",
"]",
"obj",
"[",
"name",
"]",
"=",
"isObject",
"(",
"type",
")",
"?",
"recurse",
"(",
"{",
"}",
",",
"type",
",",
"_path",
",",
"remoteCall",
")",
":",
"function",
"(",
")",
"{",
"return",
"remoteCall",
"(",
"type",
",",
"_path",
",",
"[",
"]",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
")",
"}",
"}",
")",
"(",
"name",
",",
"manifest",
"[",
"name",
"]",
")",
"return",
"obj",
"}"
] |
add all the api methods to the emitter recursively
|
[
"add",
"all",
"the",
"api",
"methods",
"to",
"the",
"emitter",
"recursively"
] |
49a360ae898bb6f3d0f5c4a13098042e02ba5a57
|
https://github.com/ssbc/muxrpc/blob/49a360ae898bb6f3d0f5c4a13098042e02ba5a57/api.js#L18-L29
|
train
|
react-component/rn-packager
|
react-native/packager/transformer.js
|
buildBabelConfig
|
function buildBabelConfig(filename, options) {
const babelRC = getBabelRC(options.projectRoots);
const extraConfig = {
code: false,
filename,
};
let config = Object.assign({}, babelRC, extraConfig);
// Add extra plugins
const extraPlugins = [externalHelpersPlugin];
var inlineRequires = options.inlineRequires;
var blacklist = inlineRequires && inlineRequires.blacklist;
if (inlineRequires && !(blacklist && filename in blacklist)) {
extraPlugins.push(inlineRequiresPlugin);
}
config.plugins = extraPlugins.concat(config.plugins);
if (options.hot) {
const hmrConfig = makeHMRConfig(options, filename);
config = Object.assign({}, config, hmrConfig);
}
return Object.assign({}, babelRC, config);
}
|
javascript
|
function buildBabelConfig(filename, options) {
const babelRC = getBabelRC(options.projectRoots);
const extraConfig = {
code: false,
filename,
};
let config = Object.assign({}, babelRC, extraConfig);
// Add extra plugins
const extraPlugins = [externalHelpersPlugin];
var inlineRequires = options.inlineRequires;
var blacklist = inlineRequires && inlineRequires.blacklist;
if (inlineRequires && !(blacklist && filename in blacklist)) {
extraPlugins.push(inlineRequiresPlugin);
}
config.plugins = extraPlugins.concat(config.plugins);
if (options.hot) {
const hmrConfig = makeHMRConfig(options, filename);
config = Object.assign({}, config, hmrConfig);
}
return Object.assign({}, babelRC, config);
}
|
[
"function",
"buildBabelConfig",
"(",
"filename",
",",
"options",
")",
"{",
"const",
"babelRC",
"=",
"getBabelRC",
"(",
"options",
".",
"projectRoots",
")",
";",
"const",
"extraConfig",
"=",
"{",
"code",
":",
"false",
",",
"filename",
",",
"}",
";",
"let",
"config",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"babelRC",
",",
"extraConfig",
")",
";",
"// Add extra plugins",
"const",
"extraPlugins",
"=",
"[",
"externalHelpersPlugin",
"]",
";",
"var",
"inlineRequires",
"=",
"options",
".",
"inlineRequires",
";",
"var",
"blacklist",
"=",
"inlineRequires",
"&&",
"inlineRequires",
".",
"blacklist",
";",
"if",
"(",
"inlineRequires",
"&&",
"!",
"(",
"blacklist",
"&&",
"filename",
"in",
"blacklist",
")",
")",
"{",
"extraPlugins",
".",
"push",
"(",
"inlineRequiresPlugin",
")",
";",
"}",
"config",
".",
"plugins",
"=",
"extraPlugins",
".",
"concat",
"(",
"config",
".",
"plugins",
")",
";",
"if",
"(",
"options",
".",
"hot",
")",
"{",
"const",
"hmrConfig",
"=",
"makeHMRConfig",
"(",
"options",
",",
"filename",
")",
";",
"config",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"config",
",",
"hmrConfig",
")",
";",
"}",
"return",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"babelRC",
",",
"config",
")",
";",
"}"
] |
Given a filename and options, build a Babel
config object with the appropriate plugins.
|
[
"Given",
"a",
"filename",
"and",
"options",
"build",
"a",
"Babel",
"config",
"object",
"with",
"the",
"appropriate",
"plugins",
"."
] |
8fbf4066ff791bc18155fc929d76b6e51be40515
|
https://github.com/react-component/rn-packager/blob/8fbf4066ff791bc18155fc929d76b6e51be40515/react-native/packager/transformer.js#L72-L99
|
train
|
ssbc/muxrpc
|
pull-weird.js
|
once
|
function once (fn) {
var done = false
return function (err, val) {
if(done) return
done = true
fn(err, val)
}
}
|
javascript
|
function once (fn) {
var done = false
return function (err, val) {
if(done) return
done = true
fn(err, val)
}
}
|
[
"function",
"once",
"(",
"fn",
")",
"{",
"var",
"done",
"=",
"false",
"return",
"function",
"(",
"err",
",",
"val",
")",
"{",
"if",
"(",
"done",
")",
"return",
"done",
"=",
"true",
"fn",
"(",
"err",
",",
"val",
")",
"}",
"}"
] |
wrap pull streams around packet-stream's weird streams.
|
[
"wrap",
"pull",
"streams",
"around",
"packet",
"-",
"stream",
"s",
"weird",
"streams",
"."
] |
49a360ae898bb6f3d0f5c4a13098042e02ba5a57
|
https://github.com/ssbc/muxrpc/blob/49a360ae898bb6f3d0f5c4a13098042e02ba5a57/pull-weird.js#L5-L12
|
train
|
react-component/rn-packager
|
react-native/local-cli/library/library.js
|
library
|
function library(argv, config, args) {
if (!isValidPackageName(args.name)) {
return Promise.reject(
args.name + ' is not a valid name for a project. Please use a valid ' +
'identifier name (alphanumeric).'
);
}
const root = process.cwd();
const libraries = path.resolve(root, 'Libraries');
const libraryDest = path.resolve(libraries, args.name);
const source = path.resolve('node_modules', 'react-native', 'Libraries', 'Sample');
if (!fs.existsSync(libraries)) {
fs.mkdir(libraries);
}
if (fs.existsSync(libraryDest)) {
return Promise.reject(`Library already exists in ${libraryDest}`);
}
walk(source).forEach(f => {
if (f.indexOf('project.xcworkspace') !== -1 ||
f.indexOf('.xcodeproj/xcuserdata') !== -1) {
return;
}
const dest = f.replace(/Sample/g, args.name).replace(/^_/, '.');
copyAndReplace(
path.resolve(source, f),
path.resolve(libraryDest, dest),
{'Sample': args.name}
);
});
console.log('Created library in', libraryDest);
console.log('Next Steps:');
console.log(' Link your library in Xcode:');
console.log(
' https://facebook.github.io/react-native/docs/' +
'linking-libraries-ios.html#content\n'
);
}
|
javascript
|
function library(argv, config, args) {
if (!isValidPackageName(args.name)) {
return Promise.reject(
args.name + ' is not a valid name for a project. Please use a valid ' +
'identifier name (alphanumeric).'
);
}
const root = process.cwd();
const libraries = path.resolve(root, 'Libraries');
const libraryDest = path.resolve(libraries, args.name);
const source = path.resolve('node_modules', 'react-native', 'Libraries', 'Sample');
if (!fs.existsSync(libraries)) {
fs.mkdir(libraries);
}
if (fs.existsSync(libraryDest)) {
return Promise.reject(`Library already exists in ${libraryDest}`);
}
walk(source).forEach(f => {
if (f.indexOf('project.xcworkspace') !== -1 ||
f.indexOf('.xcodeproj/xcuserdata') !== -1) {
return;
}
const dest = f.replace(/Sample/g, args.name).replace(/^_/, '.');
copyAndReplace(
path.resolve(source, f),
path.resolve(libraryDest, dest),
{'Sample': args.name}
);
});
console.log('Created library in', libraryDest);
console.log('Next Steps:');
console.log(' Link your library in Xcode:');
console.log(
' https://facebook.github.io/react-native/docs/' +
'linking-libraries-ios.html#content\n'
);
}
|
[
"function",
"library",
"(",
"argv",
",",
"config",
",",
"args",
")",
"{",
"if",
"(",
"!",
"isValidPackageName",
"(",
"args",
".",
"name",
")",
")",
"{",
"return",
"Promise",
".",
"reject",
"(",
"args",
".",
"name",
"+",
"' is not a valid name for a project. Please use a valid '",
"+",
"'identifier name (alphanumeric).'",
")",
";",
"}",
"const",
"root",
"=",
"process",
".",
"cwd",
"(",
")",
";",
"const",
"libraries",
"=",
"path",
".",
"resolve",
"(",
"root",
",",
"'Libraries'",
")",
";",
"const",
"libraryDest",
"=",
"path",
".",
"resolve",
"(",
"libraries",
",",
"args",
".",
"name",
")",
";",
"const",
"source",
"=",
"path",
".",
"resolve",
"(",
"'node_modules'",
",",
"'react-native'",
",",
"'Libraries'",
",",
"'Sample'",
")",
";",
"if",
"(",
"!",
"fs",
".",
"existsSync",
"(",
"libraries",
")",
")",
"{",
"fs",
".",
"mkdir",
"(",
"libraries",
")",
";",
"}",
"if",
"(",
"fs",
".",
"existsSync",
"(",
"libraryDest",
")",
")",
"{",
"return",
"Promise",
".",
"reject",
"(",
"`",
"${",
"libraryDest",
"}",
"`",
")",
";",
"}",
"walk",
"(",
"source",
")",
".",
"forEach",
"(",
"f",
"=>",
"{",
"if",
"(",
"f",
".",
"indexOf",
"(",
"'project.xcworkspace'",
")",
"!==",
"-",
"1",
"||",
"f",
".",
"indexOf",
"(",
"'.xcodeproj/xcuserdata'",
")",
"!==",
"-",
"1",
")",
"{",
"return",
";",
"}",
"const",
"dest",
"=",
"f",
".",
"replace",
"(",
"/",
"Sample",
"/",
"g",
",",
"args",
".",
"name",
")",
".",
"replace",
"(",
"/",
"^_",
"/",
",",
"'.'",
")",
";",
"copyAndReplace",
"(",
"path",
".",
"resolve",
"(",
"source",
",",
"f",
")",
",",
"path",
".",
"resolve",
"(",
"libraryDest",
",",
"dest",
")",
",",
"{",
"'Sample'",
":",
"args",
".",
"name",
"}",
")",
";",
"}",
")",
";",
"console",
".",
"log",
"(",
"'Created library in'",
",",
"libraryDest",
")",
";",
"console",
".",
"log",
"(",
"'Next Steps:'",
")",
";",
"console",
".",
"log",
"(",
"' Link your library in Xcode:'",
")",
";",
"console",
".",
"log",
"(",
"' https://facebook.github.io/react-native/docs/'",
"+",
"'linking-libraries-ios.html#content\\n'",
")",
";",
"}"
] |
Creates a new native library with the given name
|
[
"Creates",
"a",
"new",
"native",
"library",
"with",
"the",
"given",
"name"
] |
8fbf4066ff791bc18155fc929d76b6e51be40515
|
https://github.com/react-component/rn-packager/blob/8fbf4066ff791bc18155fc929d76b6e51be40515/react-native/local-cli/library/library.js#L20-L62
|
train
|
react-component/rn-packager
|
react-native/local-cli/eject/eject.js
|
eject
|
function eject() {
const doesIOSExist = fs.existsSync(path.resolve('ios'));
const doesAndroidExist = fs.existsSync(path.resolve('android'));
if (doesIOSExist && doesAndroidExist) {
console.error(
'Both the iOS and Android folders already exist! Please delete `ios` and/or `android` ' +
'before ejecting.'
);
process.exit(1);
}
let appConfig = null;
try {
appConfig = require(path.resolve('app.json'));
} catch(e) {
console.error(
`Eject requires an \`app.json\` config file to be located at ` +
`${path.resolve('app.json')}, and it must at least specify a \`name\` for the project ` +
`name, and a \`displayName\` for the app's home screen label.`
);
process.exit(1);
}
const appName = appConfig.name;
if (!appName) {
console.error(
`App \`name\` must be defined in the \`app.json\` config file to define the project name. `+
`It must not contain any spaces or dashes.`
);
process.exit(1);
}
const displayName = appConfig.displayName;
if (!displayName) {
console.error(
`App \`displayName\` must be defined in the \`app.json\` config file, to define the label ` +
`of the app on the home screen.`
);
process.exit(1);
}
const templateOptions = { displayName };
if (!doesIOSExist) {
console.log('Generating the iOS folder.');
copyProjectTemplateAndReplace(
path.resolve('node_modules', 'react-native', 'local-cli', 'templates', 'HelloWorld', 'ios'),
path.resolve('ios'),
appName,
templateOptions
);
}
if (!doesAndroidExist) {
console.log('Generating the Android folder.');
copyProjectTemplateAndReplace(
path.resolve('node_modules', 'react-native', 'local-cli', 'templates', 'HelloWorld', 'android'),
path.resolve('android'),
appName,
templateOptions
);
}
}
|
javascript
|
function eject() {
const doesIOSExist = fs.existsSync(path.resolve('ios'));
const doesAndroidExist = fs.existsSync(path.resolve('android'));
if (doesIOSExist && doesAndroidExist) {
console.error(
'Both the iOS and Android folders already exist! Please delete `ios` and/or `android` ' +
'before ejecting.'
);
process.exit(1);
}
let appConfig = null;
try {
appConfig = require(path.resolve('app.json'));
} catch(e) {
console.error(
`Eject requires an \`app.json\` config file to be located at ` +
`${path.resolve('app.json')}, and it must at least specify a \`name\` for the project ` +
`name, and a \`displayName\` for the app's home screen label.`
);
process.exit(1);
}
const appName = appConfig.name;
if (!appName) {
console.error(
`App \`name\` must be defined in the \`app.json\` config file to define the project name. `+
`It must not contain any spaces or dashes.`
);
process.exit(1);
}
const displayName = appConfig.displayName;
if (!displayName) {
console.error(
`App \`displayName\` must be defined in the \`app.json\` config file, to define the label ` +
`of the app on the home screen.`
);
process.exit(1);
}
const templateOptions = { displayName };
if (!doesIOSExist) {
console.log('Generating the iOS folder.');
copyProjectTemplateAndReplace(
path.resolve('node_modules', 'react-native', 'local-cli', 'templates', 'HelloWorld', 'ios'),
path.resolve('ios'),
appName,
templateOptions
);
}
if (!doesAndroidExist) {
console.log('Generating the Android folder.');
copyProjectTemplateAndReplace(
path.resolve('node_modules', 'react-native', 'local-cli', 'templates', 'HelloWorld', 'android'),
path.resolve('android'),
appName,
templateOptions
);
}
}
|
[
"function",
"eject",
"(",
")",
"{",
"const",
"doesIOSExist",
"=",
"fs",
".",
"existsSync",
"(",
"path",
".",
"resolve",
"(",
"'ios'",
")",
")",
";",
"const",
"doesAndroidExist",
"=",
"fs",
".",
"existsSync",
"(",
"path",
".",
"resolve",
"(",
"'android'",
")",
")",
";",
"if",
"(",
"doesIOSExist",
"&&",
"doesAndroidExist",
")",
"{",
"console",
".",
"error",
"(",
"'Both the iOS and Android folders already exist! Please delete `ios` and/or `android` '",
"+",
"'before ejecting.'",
")",
";",
"process",
".",
"exit",
"(",
"1",
")",
";",
"}",
"let",
"appConfig",
"=",
"null",
";",
"try",
"{",
"appConfig",
"=",
"require",
"(",
"path",
".",
"resolve",
"(",
"'app.json'",
")",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"console",
".",
"error",
"(",
"`",
"\\`",
"\\`",
"`",
"+",
"`",
"${",
"path",
".",
"resolve",
"(",
"'app.json'",
")",
"}",
"\\`",
"\\`",
"`",
"+",
"`",
"\\`",
"\\`",
"`",
")",
";",
"process",
".",
"exit",
"(",
"1",
")",
";",
"}",
"const",
"appName",
"=",
"appConfig",
".",
"name",
";",
"if",
"(",
"!",
"appName",
")",
"{",
"console",
".",
"error",
"(",
"`",
"\\`",
"\\`",
"\\`",
"\\`",
"`",
"+",
"`",
"`",
")",
";",
"process",
".",
"exit",
"(",
"1",
")",
";",
"}",
"const",
"displayName",
"=",
"appConfig",
".",
"displayName",
";",
"if",
"(",
"!",
"displayName",
")",
"{",
"console",
".",
"error",
"(",
"`",
"\\`",
"\\`",
"\\`",
"\\`",
"`",
"+",
"`",
"`",
")",
";",
"process",
".",
"exit",
"(",
"1",
")",
";",
"}",
"const",
"templateOptions",
"=",
"{",
"displayName",
"}",
";",
"if",
"(",
"!",
"doesIOSExist",
")",
"{",
"console",
".",
"log",
"(",
"'Generating the iOS folder.'",
")",
";",
"copyProjectTemplateAndReplace",
"(",
"path",
".",
"resolve",
"(",
"'node_modules'",
",",
"'react-native'",
",",
"'local-cli'",
",",
"'templates'",
",",
"'HelloWorld'",
",",
"'ios'",
")",
",",
"path",
".",
"resolve",
"(",
"'ios'",
")",
",",
"appName",
",",
"templateOptions",
")",
";",
"}",
"if",
"(",
"!",
"doesAndroidExist",
")",
"{",
"console",
".",
"log",
"(",
"'Generating the Android folder.'",
")",
";",
"copyProjectTemplateAndReplace",
"(",
"path",
".",
"resolve",
"(",
"'node_modules'",
",",
"'react-native'",
",",
"'local-cli'",
",",
"'templates'",
",",
"'HelloWorld'",
",",
"'android'",
")",
",",
"path",
".",
"resolve",
"(",
"'android'",
")",
",",
"appName",
",",
"templateOptions",
")",
";",
"}",
"}"
] |
The eject command re-creates the `android` and `ios` native folders. Because native code can be
difficult to maintain, this new script allows an `app.json` to be defined for the project, which
is used to configure the native app.
The `app.json` config may contain the following keys:
- `name` - The short name used for the project, should be TitleCase
- `displayName` - The app's name on the home screen
|
[
"The",
"eject",
"command",
"re",
"-",
"creates",
"the",
"android",
"and",
"ios",
"native",
"folders",
".",
"Because",
"native",
"code",
"can",
"be",
"difficult",
"to",
"maintain",
"this",
"new",
"script",
"allows",
"an",
"app",
".",
"json",
"to",
"be",
"defined",
"for",
"the",
"project",
"which",
"is",
"used",
"to",
"configure",
"the",
"native",
"app",
"."
] |
8fbf4066ff791bc18155fc929d76b6e51be40515
|
https://github.com/react-component/rn-packager/blob/8fbf4066ff791bc18155fc929d76b6e51be40515/react-native/local-cli/eject/eject.js#L26-L89
|
train
|
react-component/rn-packager
|
react-native/local-cli/util/copyAndReplace.js
|
copyAndReplace
|
function copyAndReplace(srcPath, destPath, replacements, contentChangedCallback) {
if (fs.lstatSync(srcPath).isDirectory()) {
if (!fs.existsSync(destPath)) {
fs.mkdirSync(destPath);
}
// Not recursive
return;
}
const extension = path.extname(srcPath);
if (binaryExtensions.indexOf(extension) !== -1) {
// Binary file
let shouldOverwrite = 'overwrite';
if (contentChangedCallback) {
const newContentBuffer = fs.readFileSync(srcPath);
let contentChanged = 'identical';
try {
const origContentBuffer = fs.readFileSync(destPath);
if (Buffer.compare(origContentBuffer, newContentBuffer) !== 0) {
contentChanged = 'changed';
}
} catch (err) {
if (err.code === 'ENOENT') {
contentChanged = 'new';
} else {
throw err;
}
}
shouldOverwrite = contentChangedCallback(destPath, contentChanged);
}
if (shouldOverwrite === 'overwrite') {
copyBinaryFile(srcPath, destPath, (err) => {
if (err) { throw err; }
});
}
} else {
// Text file
const srcPermissions = fs.statSync(srcPath).mode;
let content = fs.readFileSync(srcPath, 'utf8');
Object.keys(replacements).forEach(regex =>
content = content.replace(new RegExp(regex, 'g'), replacements[regex])
);
let shouldOverwrite = 'overwrite';
if (contentChangedCallback) {
// Check if contents changed and ask to overwrite
let contentChanged = 'identical';
try {
const origContent = fs.readFileSync(destPath, 'utf8');
if (content !== origContent) {
//console.log('Content changed: ' + destPath);
contentChanged = 'changed';
}
} catch (err) {
if (err.code === 'ENOENT') {
contentChanged = 'new';
} else {
throw err;
}
}
shouldOverwrite = contentChangedCallback(destPath, contentChanged);
}
if (shouldOverwrite === 'overwrite') {
fs.writeFileSync(destPath, content, {
encoding: 'utf8',
mode: srcPermissions,
});
}
}
}
|
javascript
|
function copyAndReplace(srcPath, destPath, replacements, contentChangedCallback) {
if (fs.lstatSync(srcPath).isDirectory()) {
if (!fs.existsSync(destPath)) {
fs.mkdirSync(destPath);
}
// Not recursive
return;
}
const extension = path.extname(srcPath);
if (binaryExtensions.indexOf(extension) !== -1) {
// Binary file
let shouldOverwrite = 'overwrite';
if (contentChangedCallback) {
const newContentBuffer = fs.readFileSync(srcPath);
let contentChanged = 'identical';
try {
const origContentBuffer = fs.readFileSync(destPath);
if (Buffer.compare(origContentBuffer, newContentBuffer) !== 0) {
contentChanged = 'changed';
}
} catch (err) {
if (err.code === 'ENOENT') {
contentChanged = 'new';
} else {
throw err;
}
}
shouldOverwrite = contentChangedCallback(destPath, contentChanged);
}
if (shouldOverwrite === 'overwrite') {
copyBinaryFile(srcPath, destPath, (err) => {
if (err) { throw err; }
});
}
} else {
// Text file
const srcPermissions = fs.statSync(srcPath).mode;
let content = fs.readFileSync(srcPath, 'utf8');
Object.keys(replacements).forEach(regex =>
content = content.replace(new RegExp(regex, 'g'), replacements[regex])
);
let shouldOverwrite = 'overwrite';
if (contentChangedCallback) {
// Check if contents changed and ask to overwrite
let contentChanged = 'identical';
try {
const origContent = fs.readFileSync(destPath, 'utf8');
if (content !== origContent) {
//console.log('Content changed: ' + destPath);
contentChanged = 'changed';
}
} catch (err) {
if (err.code === 'ENOENT') {
contentChanged = 'new';
} else {
throw err;
}
}
shouldOverwrite = contentChangedCallback(destPath, contentChanged);
}
if (shouldOverwrite === 'overwrite') {
fs.writeFileSync(destPath, content, {
encoding: 'utf8',
mode: srcPermissions,
});
}
}
}
|
[
"function",
"copyAndReplace",
"(",
"srcPath",
",",
"destPath",
",",
"replacements",
",",
"contentChangedCallback",
")",
"{",
"if",
"(",
"fs",
".",
"lstatSync",
"(",
"srcPath",
")",
".",
"isDirectory",
"(",
")",
")",
"{",
"if",
"(",
"!",
"fs",
".",
"existsSync",
"(",
"destPath",
")",
")",
"{",
"fs",
".",
"mkdirSync",
"(",
"destPath",
")",
";",
"}",
"// Not recursive",
"return",
";",
"}",
"const",
"extension",
"=",
"path",
".",
"extname",
"(",
"srcPath",
")",
";",
"if",
"(",
"binaryExtensions",
".",
"indexOf",
"(",
"extension",
")",
"!==",
"-",
"1",
")",
"{",
"// Binary file",
"let",
"shouldOverwrite",
"=",
"'overwrite'",
";",
"if",
"(",
"contentChangedCallback",
")",
"{",
"const",
"newContentBuffer",
"=",
"fs",
".",
"readFileSync",
"(",
"srcPath",
")",
";",
"let",
"contentChanged",
"=",
"'identical'",
";",
"try",
"{",
"const",
"origContentBuffer",
"=",
"fs",
".",
"readFileSync",
"(",
"destPath",
")",
";",
"if",
"(",
"Buffer",
".",
"compare",
"(",
"origContentBuffer",
",",
"newContentBuffer",
")",
"!==",
"0",
")",
"{",
"contentChanged",
"=",
"'changed'",
";",
"}",
"}",
"catch",
"(",
"err",
")",
"{",
"if",
"(",
"err",
".",
"code",
"===",
"'ENOENT'",
")",
"{",
"contentChanged",
"=",
"'new'",
";",
"}",
"else",
"{",
"throw",
"err",
";",
"}",
"}",
"shouldOverwrite",
"=",
"contentChangedCallback",
"(",
"destPath",
",",
"contentChanged",
")",
";",
"}",
"if",
"(",
"shouldOverwrite",
"===",
"'overwrite'",
")",
"{",
"copyBinaryFile",
"(",
"srcPath",
",",
"destPath",
",",
"(",
"err",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"throw",
"err",
";",
"}",
"}",
")",
";",
"}",
"}",
"else",
"{",
"// Text file",
"const",
"srcPermissions",
"=",
"fs",
".",
"statSync",
"(",
"srcPath",
")",
".",
"mode",
";",
"let",
"content",
"=",
"fs",
".",
"readFileSync",
"(",
"srcPath",
",",
"'utf8'",
")",
";",
"Object",
".",
"keys",
"(",
"replacements",
")",
".",
"forEach",
"(",
"regex",
"=>",
"content",
"=",
"content",
".",
"replace",
"(",
"new",
"RegExp",
"(",
"regex",
",",
"'g'",
")",
",",
"replacements",
"[",
"regex",
"]",
")",
")",
";",
"let",
"shouldOverwrite",
"=",
"'overwrite'",
";",
"if",
"(",
"contentChangedCallback",
")",
"{",
"// Check if contents changed and ask to overwrite",
"let",
"contentChanged",
"=",
"'identical'",
";",
"try",
"{",
"const",
"origContent",
"=",
"fs",
".",
"readFileSync",
"(",
"destPath",
",",
"'utf8'",
")",
";",
"if",
"(",
"content",
"!==",
"origContent",
")",
"{",
"//console.log('Content changed: ' + destPath);",
"contentChanged",
"=",
"'changed'",
";",
"}",
"}",
"catch",
"(",
"err",
")",
"{",
"if",
"(",
"err",
".",
"code",
"===",
"'ENOENT'",
")",
"{",
"contentChanged",
"=",
"'new'",
";",
"}",
"else",
"{",
"throw",
"err",
";",
"}",
"}",
"shouldOverwrite",
"=",
"contentChangedCallback",
"(",
"destPath",
",",
"contentChanged",
")",
";",
"}",
"if",
"(",
"shouldOverwrite",
"===",
"'overwrite'",
")",
"{",
"fs",
".",
"writeFileSync",
"(",
"destPath",
",",
"content",
",",
"{",
"encoding",
":",
"'utf8'",
",",
"mode",
":",
"srcPermissions",
",",
"}",
")",
";",
"}",
"}",
"}"
] |
Copy a file to given destination, replacing parts of its contents.
@param srcPath Path to a file to be copied.
@param destPath Destination path.
@param replacements: e.g. {'TextToBeReplaced': 'Replacement'}
@param contentChangedCallback
Used when upgrading projects. Based on if file contents would change
when being replaced, allows the caller to specify whether the file
should be replaced or not.
If null, files will be overwritten.
Function(path, 'identical' | 'changed' | 'new') => 'keep' | 'overwrite'
|
[
"Copy",
"a",
"file",
"to",
"given",
"destination",
"replacing",
"parts",
"of",
"its",
"contents",
"."
] |
8fbf4066ff791bc18155fc929d76b6e51be40515
|
https://github.com/react-component/rn-packager/blob/8fbf4066ff791bc18155fc929d76b6e51be40515/react-native/local-cli/util/copyAndReplace.js#L29-L98
|
train
|
datalanche/json-bignum
|
lib/bignumber.js
|
BigNumber
|
function BigNumber(number) {
this.numberStr = number.toString();
// not a number
if (isNaN(parseFloat(this.numberStr)) === true
|| isFinite(this.numberStr) === false) {
throw new Error(number + ' is not a number');
}
}
|
javascript
|
function BigNumber(number) {
this.numberStr = number.toString();
// not a number
if (isNaN(parseFloat(this.numberStr)) === true
|| isFinite(this.numberStr) === false) {
throw new Error(number + ' is not a number');
}
}
|
[
"function",
"BigNumber",
"(",
"number",
")",
"{",
"this",
".",
"numberStr",
"=",
"number",
".",
"toString",
"(",
")",
";",
"// not a number",
"if",
"(",
"isNaN",
"(",
"parseFloat",
"(",
"this",
".",
"numberStr",
")",
")",
"===",
"true",
"||",
"isFinite",
"(",
"this",
".",
"numberStr",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"Error",
"(",
"number",
"+",
"' is not a number'",
")",
";",
"}",
"}"
] |
wraps a large number, does not support arithmetic
|
[
"wraps",
"a",
"large",
"number",
"does",
"not",
"support",
"arithmetic"
] |
68f270db0ec25f6b19260103e5127a2f9424405e
|
https://github.com/datalanche/json-bignum/blob/68f270db0ec25f6b19260103e5127a2f9424405e/lib/bignumber.js#L5-L13
|
train
|
react-component/rn-packager
|
react-native/local-cli/util/PackageManager.js
|
callYarnOrNpm
|
function callYarnOrNpm(yarnCommand, npmCommand) {
let command;
if (isYarnAvailable) {
command = yarnCommand;
} else {
command = npmCommand;
}
const args = command.split(' ');
const cmd = args.shift();
const res = spawnSync(cmd, args, spawnOpts);
return res;
}
|
javascript
|
function callYarnOrNpm(yarnCommand, npmCommand) {
let command;
if (isYarnAvailable) {
command = yarnCommand;
} else {
command = npmCommand;
}
const args = command.split(' ');
const cmd = args.shift();
const res = spawnSync(cmd, args, spawnOpts);
return res;
}
|
[
"function",
"callYarnOrNpm",
"(",
"yarnCommand",
",",
"npmCommand",
")",
"{",
"let",
"command",
";",
"if",
"(",
"isYarnAvailable",
")",
"{",
"command",
"=",
"yarnCommand",
";",
"}",
"else",
"{",
"command",
"=",
"npmCommand",
";",
"}",
"const",
"args",
"=",
"command",
".",
"split",
"(",
"' '",
")",
";",
"const",
"cmd",
"=",
"args",
".",
"shift",
"(",
")",
";",
"const",
"res",
"=",
"spawnSync",
"(",
"cmd",
",",
"args",
",",
"spawnOpts",
")",
";",
"return",
"res",
";",
"}"
] |
Execute npm or yarn command
@param {String} yarnCommand Yarn command to be executed eg. yarn add package
@param {String} npmCommand Npm command to be executed eg. npm install package
@return {object} spawnSync's result object
|
[
"Execute",
"npm",
"or",
"yarn",
"command"
] |
8fbf4066ff791bc18155fc929d76b6e51be40515
|
https://github.com/react-component/rn-packager/blob/8fbf4066ff791bc18155fc929d76b6e51be40515/react-native/local-cli/util/PackageManager.js#L30-L45
|
train
|
react-component/rn-packager
|
react-native/local-cli/link/link.js
|
link
|
function link(args, config) {
var project;
try {
project = config.getProjectConfig();
} catch (err) {
log.error(
'ERRPACKAGEJSON',
'No package found. Are you sure it\'s a React Native project?'
);
return Promise.reject(err);
}
let packageName = args[0];
// Check if install package by specific version (eg. package@latest)
if (packageName !== undefined) {
packageName = packageName.split('@')[0];
}
const dependencies = getDependencyConfig(
config,
packageName ? [packageName] : getProjectDependencies()
);
const assets = dedupeAssets(dependencies.reduce(
(assets, dependency) => assets.concat(dependency.config.assets),
project.assets
));
const tasks = flatten(dependencies.map(dependency => [
() => promisify(dependency.config.commands.prelink || commandStub),
() => linkDependencyAndroid(project.android, dependency),
() => linkDependencyIOS(project.ios, dependency),
() => linkDependencyWindows(project.windows, dependency),
() => promisify(dependency.config.commands.postlink || commandStub),
]));
tasks.push(() => linkAssets(project, assets));
return promiseWaterfall(tasks).catch(err => {
log.error(
`It seems something went wrong while linking. Error: ${err.message} \n`
+ 'Please file an issue here: https://github.com/facebook/react-native/issues'
);
throw err;
});
}
|
javascript
|
function link(args, config) {
var project;
try {
project = config.getProjectConfig();
} catch (err) {
log.error(
'ERRPACKAGEJSON',
'No package found. Are you sure it\'s a React Native project?'
);
return Promise.reject(err);
}
let packageName = args[0];
// Check if install package by specific version (eg. package@latest)
if (packageName !== undefined) {
packageName = packageName.split('@')[0];
}
const dependencies = getDependencyConfig(
config,
packageName ? [packageName] : getProjectDependencies()
);
const assets = dedupeAssets(dependencies.reduce(
(assets, dependency) => assets.concat(dependency.config.assets),
project.assets
));
const tasks = flatten(dependencies.map(dependency => [
() => promisify(dependency.config.commands.prelink || commandStub),
() => linkDependencyAndroid(project.android, dependency),
() => linkDependencyIOS(project.ios, dependency),
() => linkDependencyWindows(project.windows, dependency),
() => promisify(dependency.config.commands.postlink || commandStub),
]));
tasks.push(() => linkAssets(project, assets));
return promiseWaterfall(tasks).catch(err => {
log.error(
`It seems something went wrong while linking. Error: ${err.message} \n`
+ 'Please file an issue here: https://github.com/facebook/react-native/issues'
);
throw err;
});
}
|
[
"function",
"link",
"(",
"args",
",",
"config",
")",
"{",
"var",
"project",
";",
"try",
"{",
"project",
"=",
"config",
".",
"getProjectConfig",
"(",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"log",
".",
"error",
"(",
"'ERRPACKAGEJSON'",
",",
"'No package found. Are you sure it\\'s a React Native project?'",
")",
";",
"return",
"Promise",
".",
"reject",
"(",
"err",
")",
";",
"}",
"let",
"packageName",
"=",
"args",
"[",
"0",
"]",
";",
"// Check if install package by specific version (eg. package@latest)",
"if",
"(",
"packageName",
"!==",
"undefined",
")",
"{",
"packageName",
"=",
"packageName",
".",
"split",
"(",
"'@'",
")",
"[",
"0",
"]",
";",
"}",
"const",
"dependencies",
"=",
"getDependencyConfig",
"(",
"config",
",",
"packageName",
"?",
"[",
"packageName",
"]",
":",
"getProjectDependencies",
"(",
")",
")",
";",
"const",
"assets",
"=",
"dedupeAssets",
"(",
"dependencies",
".",
"reduce",
"(",
"(",
"assets",
",",
"dependency",
")",
"=>",
"assets",
".",
"concat",
"(",
"dependency",
".",
"config",
".",
"assets",
")",
",",
"project",
".",
"assets",
")",
")",
";",
"const",
"tasks",
"=",
"flatten",
"(",
"dependencies",
".",
"map",
"(",
"dependency",
"=>",
"[",
"(",
")",
"=>",
"promisify",
"(",
"dependency",
".",
"config",
".",
"commands",
".",
"prelink",
"||",
"commandStub",
")",
",",
"(",
")",
"=>",
"linkDependencyAndroid",
"(",
"project",
".",
"android",
",",
"dependency",
")",
",",
"(",
")",
"=>",
"linkDependencyIOS",
"(",
"project",
".",
"ios",
",",
"dependency",
")",
",",
"(",
")",
"=>",
"linkDependencyWindows",
"(",
"project",
".",
"windows",
",",
"dependency",
")",
",",
"(",
")",
"=>",
"promisify",
"(",
"dependency",
".",
"config",
".",
"commands",
".",
"postlink",
"||",
"commandStub",
")",
",",
"]",
")",
")",
";",
"tasks",
".",
"push",
"(",
"(",
")",
"=>",
"linkAssets",
"(",
"project",
",",
"assets",
")",
")",
";",
"return",
"promiseWaterfall",
"(",
"tasks",
")",
".",
"catch",
"(",
"err",
"=>",
"{",
"log",
".",
"error",
"(",
"`",
"${",
"err",
".",
"message",
"}",
"\\n",
"`",
"+",
"'Please file an issue here: https://github.com/facebook/react-native/issues'",
")",
";",
"throw",
"err",
";",
"}",
")",
";",
"}"
] |
Updates project and links all dependencies to it
If optional argument [packageName] is provided, it's the only one that's checked
|
[
"Updates",
"project",
"and",
"links",
"all",
"dependencies",
"to",
"it"
] |
8fbf4066ff791bc18155fc929d76b6e51be40515
|
https://github.com/react-component/rn-packager/blob/8fbf4066ff791bc18155fc929d76b6e51be40515/react-native/local-cli/link/link.js#L132-L177
|
train
|
react-component/rn-packager
|
react-native/local-cli/init/init.js
|
addJestToPackageJson
|
function addJestToPackageJson(destinationRoot) {
var packageJSONPath = path.join(destinationRoot, 'package.json');
var packageJSON = JSON.parse(fs.readFileSync(packageJSONPath));
packageJSON.scripts.test = 'jest';
packageJSON.jest = {
preset: 'react-native'
};
fs.writeFileSync(packageJSONPath, JSON.stringify(packageJSON, null, '\t'));
}
|
javascript
|
function addJestToPackageJson(destinationRoot) {
var packageJSONPath = path.join(destinationRoot, 'package.json');
var packageJSON = JSON.parse(fs.readFileSync(packageJSONPath));
packageJSON.scripts.test = 'jest';
packageJSON.jest = {
preset: 'react-native'
};
fs.writeFileSync(packageJSONPath, JSON.stringify(packageJSON, null, '\t'));
}
|
[
"function",
"addJestToPackageJson",
"(",
"destinationRoot",
")",
"{",
"var",
"packageJSONPath",
"=",
"path",
".",
"join",
"(",
"destinationRoot",
",",
"'package.json'",
")",
";",
"var",
"packageJSON",
"=",
"JSON",
".",
"parse",
"(",
"fs",
".",
"readFileSync",
"(",
"packageJSONPath",
")",
")",
";",
"packageJSON",
".",
"scripts",
".",
"test",
"=",
"'jest'",
";",
"packageJSON",
".",
"jest",
"=",
"{",
"preset",
":",
"'react-native'",
"}",
";",
"fs",
".",
"writeFileSync",
"(",
"packageJSONPath",
",",
"JSON",
".",
"stringify",
"(",
"packageJSON",
",",
"null",
",",
"'\\t'",
")",
")",
";",
"}"
] |
Add Jest-related stuff to package.json, which was created by the react-native-cli.
|
[
"Add",
"Jest",
"-",
"related",
"stuff",
"to",
"package",
".",
"json",
"which",
"was",
"created",
"by",
"the",
"react",
"-",
"native",
"-",
"cli",
"."
] |
8fbf4066ff791bc18155fc929d76b6e51be40515
|
https://github.com/react-component/rn-packager/blob/8fbf4066ff791bc18155fc929d76b6e51be40515/react-native/local-cli/init/init.js#L108-L117
|
train
|
groupon/gofer
|
lib/fetch.browser.js
|
isValidBody
|
function isValidBody(body) {
return (
body === undefined ||
typeof body === 'string' ||
(typeof FormData !== 'undefined' && body instanceof FormData) ||
(typeof URLSearchParams !== 'undefined' && body instanceof URLSearchParams)
);
}
|
javascript
|
function isValidBody(body) {
return (
body === undefined ||
typeof body === 'string' ||
(typeof FormData !== 'undefined' && body instanceof FormData) ||
(typeof URLSearchParams !== 'undefined' && body instanceof URLSearchParams)
);
}
|
[
"function",
"isValidBody",
"(",
"body",
")",
"{",
"return",
"(",
"body",
"===",
"undefined",
"||",
"typeof",
"body",
"===",
"'string'",
"||",
"(",
"typeof",
"FormData",
"!==",
"'undefined'",
"&&",
"body",
"instanceof",
"FormData",
")",
"||",
"(",
"typeof",
"URLSearchParams",
"!==",
"'undefined'",
"&&",
"body",
"instanceof",
"URLSearchParams",
")",
")",
";",
"}"
] |
Blob or BufferSource or FormData or URLSearchParams or USVString
|
[
"Blob",
"or",
"BufferSource",
"or",
"FormData",
"or",
"URLSearchParams",
"or",
"USVString"
] |
b21b894ae00ddd8a836370cd905e259fc13791c5
|
https://github.com/groupon/gofer/blob/b21b894ae00ddd8a836370cd905e259fc13791c5/lib/fetch.browser.js#L80-L87
|
train
|
fpirsch/twin-bcrypt
|
src/twin-bcrypt.js
|
string2utf8Bytes
|
function string2utf8Bytes(s) {
var utf8 = unescape(encodeURIComponent(s)),
len = utf8.length,
bytes = new Array(len);
for (var i = 0; i < len; i++) {
bytes[i] = utf8.charCodeAt(i);
}
return bytes;
}
|
javascript
|
function string2utf8Bytes(s) {
var utf8 = unescape(encodeURIComponent(s)),
len = utf8.length,
bytes = new Array(len);
for (var i = 0; i < len; i++) {
bytes[i] = utf8.charCodeAt(i);
}
return bytes;
}
|
[
"function",
"string2utf8Bytes",
"(",
"s",
")",
"{",
"var",
"utf8",
"=",
"unescape",
"(",
"encodeURIComponent",
"(",
"s",
")",
")",
",",
"len",
"=",
"utf8",
".",
"length",
",",
"bytes",
"=",
"new",
"Array",
"(",
"len",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"bytes",
"[",
"i",
"]",
"=",
"utf8",
".",
"charCodeAt",
"(",
"i",
")",
";",
"}",
"return",
"bytes",
";",
"}"
] |
utf-8 conversion for browsers and Node.
|
[
"utf",
"-",
"8",
"conversion",
"for",
"browsers",
"and",
"Node",
"."
] |
fd61025973f4764382b03bd98343e87f5cbdec3f
|
https://github.com/fpirsch/twin-bcrypt/blob/fd61025973f4764382b03bd98343e87f5cbdec3f/src/twin-bcrypt.js#L33-L41
|
train
|
sergeysova/telegram-typings
|
lib/parser.js
|
findPrev
|
function findPrev(type/*: string*/, element/*: Cheerio*/) {
let tries = 5
let prev = element
do {
if (prev.is(type)) {
return prev
}
prev = prev.prev()
}
while (--tries)
return prev
}
|
javascript
|
function findPrev(type/*: string*/, element/*: Cheerio*/) {
let tries = 5
let prev = element
do {
if (prev.is(type)) {
return prev
}
prev = prev.prev()
}
while (--tries)
return prev
}
|
[
"function",
"findPrev",
"(",
"type",
"/*: string*/",
",",
"element",
"/*: Cheerio*/",
")",
"{",
"let",
"tries",
"=",
"5",
"let",
"prev",
"=",
"element",
"do",
"{",
"if",
"(",
"prev",
".",
"is",
"(",
"type",
")",
")",
"{",
"return",
"prev",
"}",
"prev",
"=",
"prev",
".",
"prev",
"(",
")",
"}",
"while",
"(",
"--",
"tries",
")",
"return",
"prev",
"}"
] |
Find previous special typed element in siblings
|
[
"Find",
"previous",
"special",
"typed",
"element",
"in",
"siblings"
] |
786b2438721b5eb6fc8a3c6be2a82b4aea891529
|
https://github.com/sergeysova/telegram-typings/blob/786b2438721b5eb6fc8a3c6be2a82b4aea891529/lib/parser.js#L17-L31
|
train
|
sergeysova/telegram-typings
|
lib/parser.js
|
findNext
|
function findNext(type, element) {
let tries = 5
let next = element
do {
if (next.is(type)) {
return next
}
next = next.next()
}
while (--tries)
return next
}
|
javascript
|
function findNext(type, element) {
let tries = 5
let next = element
do {
if (next.is(type)) {
return next
}
next = next.next()
}
while (--tries)
return next
}
|
[
"function",
"findNext",
"(",
"type",
",",
"element",
")",
"{",
"let",
"tries",
"=",
"5",
"let",
"next",
"=",
"element",
"do",
"{",
"if",
"(",
"next",
".",
"is",
"(",
"type",
")",
")",
"{",
"return",
"next",
"}",
"next",
"=",
"next",
".",
"next",
"(",
")",
"}",
"while",
"(",
"--",
"tries",
")",
"return",
"next",
"}"
] |
Find next special typed element in siblings
@param {string} type
@param {Cheerio} element
|
[
"Find",
"next",
"special",
"typed",
"element",
"in",
"siblings"
] |
786b2438721b5eb6fc8a3c6be2a82b4aea891529
|
https://github.com/sergeysova/telegram-typings/blob/786b2438721b5eb6fc8a3c6be2a82b4aea891529/lib/parser.js#L38-L52
|
train
|
sergeysova/telegram-typings
|
lib/builders/base.js
|
smartComment
|
function smartComment(description/*:string*/ = '', links/*: string[]*/ = []) {
const descriptionLines = description.replace(/(.{1,72}\s)\s*?/g, '\n * $1')
const linksLines = links.reduce((acc, link) => (
`${acc} * @see ${link}\n`
), '')
return commentBlock(`*${descriptionLines}\n${linksLines} `)
}
|
javascript
|
function smartComment(description/*:string*/ = '', links/*: string[]*/ = []) {
const descriptionLines = description.replace(/(.{1,72}\s)\s*?/g, '\n * $1')
const linksLines = links.reduce((acc, link) => (
`${acc} * @see ${link}\n`
), '')
return commentBlock(`*${descriptionLines}\n${linksLines} `)
}
|
[
"function",
"smartComment",
"(",
"description",
"/*:string*/",
"=",
"''",
",",
"links",
"/*: string[]*/",
"=",
"[",
"]",
")",
"{",
"const",
"descriptionLines",
"=",
"description",
".",
"replace",
"(",
"/",
"(.{1,72}\\s)\\s*?",
"/",
"g",
",",
"'\\n * $1'",
")",
"const",
"linksLines",
"=",
"links",
".",
"reduce",
"(",
"(",
"acc",
",",
"link",
")",
"=>",
"(",
"`",
"${",
"acc",
"}",
"${",
"link",
"}",
"\\n",
"`",
")",
",",
"''",
")",
"return",
"commentBlock",
"(",
"`",
"${",
"descriptionLines",
"}",
"\\n",
"${",
"linksLines",
"}",
"`",
")",
"}"
] |
Split description to lines add return AST node
|
[
"Split",
"description",
"to",
"lines",
"add",
"return",
"AST",
"node"
] |
786b2438721b5eb6fc8a3c6be2a82b4aea891529
|
https://github.com/sergeysova/telegram-typings/blob/786b2438721b5eb6fc8a3c6be2a82b4aea891529/lib/builders/base.js#L219-L226
|
train
|
gulpjs/vinyl-sourcemap
|
lib/helpers.js
|
fixImportedSourceMap
|
function fixImportedSourceMap(file, state, callback) {
if (!state.map) {
return callback();
}
state.map.sourcesContent = state.map.sourcesContent || [];
nal.map(state.map.sources, normalizeSourcesAndContent, callback);
function assignSourcesContent(sourceContent, idx) {
state.map.sourcesContent[idx] = sourceContent;
}
function normalizeSourcesAndContent(sourcePath, idx, cb) {
var sourceRoot = state.map.sourceRoot || '';
var sourceContent = state.map.sourcesContent[idx] || null;
if (isRemoteSource(sourcePath)) {
assignSourcesContent(sourceContent, idx);
return cb();
}
if (state.map.sourcesContent[idx]) {
return cb();
}
if (sourceRoot && isRemoteSource(sourceRoot)) {
assignSourcesContent(sourceContent, idx);
return cb();
}
var basePath = path.resolve(file.base, sourceRoot);
var absPath = path.resolve(state.path, sourceRoot, sourcePath);
var relPath = path.relative(basePath, absPath);
var unixRelPath = normalizePath(relPath);
state.map.sources[idx] = unixRelPath;
if (absPath !== file.path) {
// Load content from file async
return fs.readFile(absPath, onRead);
}
// If current file: use content
assignSourcesContent(state.content, idx);
cb();
function onRead(err, data) {
if (err) {
assignSourcesContent(null, idx);
return cb();
}
assignSourcesContent(removeBOM(data).toString('utf8'), idx);
cb();
}
}
}
|
javascript
|
function fixImportedSourceMap(file, state, callback) {
if (!state.map) {
return callback();
}
state.map.sourcesContent = state.map.sourcesContent || [];
nal.map(state.map.sources, normalizeSourcesAndContent, callback);
function assignSourcesContent(sourceContent, idx) {
state.map.sourcesContent[idx] = sourceContent;
}
function normalizeSourcesAndContent(sourcePath, idx, cb) {
var sourceRoot = state.map.sourceRoot || '';
var sourceContent = state.map.sourcesContent[idx] || null;
if (isRemoteSource(sourcePath)) {
assignSourcesContent(sourceContent, idx);
return cb();
}
if (state.map.sourcesContent[idx]) {
return cb();
}
if (sourceRoot && isRemoteSource(sourceRoot)) {
assignSourcesContent(sourceContent, idx);
return cb();
}
var basePath = path.resolve(file.base, sourceRoot);
var absPath = path.resolve(state.path, sourceRoot, sourcePath);
var relPath = path.relative(basePath, absPath);
var unixRelPath = normalizePath(relPath);
state.map.sources[idx] = unixRelPath;
if (absPath !== file.path) {
// Load content from file async
return fs.readFile(absPath, onRead);
}
// If current file: use content
assignSourcesContent(state.content, idx);
cb();
function onRead(err, data) {
if (err) {
assignSourcesContent(null, idx);
return cb();
}
assignSourcesContent(removeBOM(data).toString('utf8'), idx);
cb();
}
}
}
|
[
"function",
"fixImportedSourceMap",
"(",
"file",
",",
"state",
",",
"callback",
")",
"{",
"if",
"(",
"!",
"state",
".",
"map",
")",
"{",
"return",
"callback",
"(",
")",
";",
"}",
"state",
".",
"map",
".",
"sourcesContent",
"=",
"state",
".",
"map",
".",
"sourcesContent",
"||",
"[",
"]",
";",
"nal",
".",
"map",
"(",
"state",
".",
"map",
".",
"sources",
",",
"normalizeSourcesAndContent",
",",
"callback",
")",
";",
"function",
"assignSourcesContent",
"(",
"sourceContent",
",",
"idx",
")",
"{",
"state",
".",
"map",
".",
"sourcesContent",
"[",
"idx",
"]",
"=",
"sourceContent",
";",
"}",
"function",
"normalizeSourcesAndContent",
"(",
"sourcePath",
",",
"idx",
",",
"cb",
")",
"{",
"var",
"sourceRoot",
"=",
"state",
".",
"map",
".",
"sourceRoot",
"||",
"''",
";",
"var",
"sourceContent",
"=",
"state",
".",
"map",
".",
"sourcesContent",
"[",
"idx",
"]",
"||",
"null",
";",
"if",
"(",
"isRemoteSource",
"(",
"sourcePath",
")",
")",
"{",
"assignSourcesContent",
"(",
"sourceContent",
",",
"idx",
")",
";",
"return",
"cb",
"(",
")",
";",
"}",
"if",
"(",
"state",
".",
"map",
".",
"sourcesContent",
"[",
"idx",
"]",
")",
"{",
"return",
"cb",
"(",
")",
";",
"}",
"if",
"(",
"sourceRoot",
"&&",
"isRemoteSource",
"(",
"sourceRoot",
")",
")",
"{",
"assignSourcesContent",
"(",
"sourceContent",
",",
"idx",
")",
";",
"return",
"cb",
"(",
")",
";",
"}",
"var",
"basePath",
"=",
"path",
".",
"resolve",
"(",
"file",
".",
"base",
",",
"sourceRoot",
")",
";",
"var",
"absPath",
"=",
"path",
".",
"resolve",
"(",
"state",
".",
"path",
",",
"sourceRoot",
",",
"sourcePath",
")",
";",
"var",
"relPath",
"=",
"path",
".",
"relative",
"(",
"basePath",
",",
"absPath",
")",
";",
"var",
"unixRelPath",
"=",
"normalizePath",
"(",
"relPath",
")",
";",
"state",
".",
"map",
".",
"sources",
"[",
"idx",
"]",
"=",
"unixRelPath",
";",
"if",
"(",
"absPath",
"!==",
"file",
".",
"path",
")",
"{",
"// Load content from file async",
"return",
"fs",
".",
"readFile",
"(",
"absPath",
",",
"onRead",
")",
";",
"}",
"// If current file: use content",
"assignSourcesContent",
"(",
"state",
".",
"content",
",",
"idx",
")",
";",
"cb",
"(",
")",
";",
"function",
"onRead",
"(",
"err",
",",
"data",
")",
"{",
"if",
"(",
"err",
")",
"{",
"assignSourcesContent",
"(",
"null",
",",
"idx",
")",
";",
"return",
"cb",
"(",
")",
";",
"}",
"assignSourcesContent",
"(",
"removeBOM",
"(",
"data",
")",
".",
"toString",
"(",
"'utf8'",
")",
",",
"idx",
")",
";",
"cb",
"(",
")",
";",
"}",
"}",
"}"
] |
Fix source paths and sourceContent for imported source map
|
[
"Fix",
"source",
"paths",
"and",
"sourceContent",
"for",
"imported",
"source",
"map"
] |
c86582cd9a0973a2ac9aa18fce5feb7d80ab1e3b
|
https://github.com/gulpjs/vinyl-sourcemap/blob/c86582cd9a0973a2ac9aa18fce5feb7d80ab1e3b/lib/helpers.js#L70-L126
|
train
|
contra/holla
|
holla.js
|
FlashWS
|
function FlashWS (options) {
WS.call(this, options);
this.flashPath = options.flashPath;
this.policyPort = options.policyPort;
}
|
javascript
|
function FlashWS (options) {
WS.call(this, options);
this.flashPath = options.flashPath;
this.policyPort = options.policyPort;
}
|
[
"function",
"FlashWS",
"(",
"options",
")",
"{",
"WS",
".",
"call",
"(",
"this",
",",
"options",
")",
";",
"this",
".",
"flashPath",
"=",
"options",
".",
"flashPath",
";",
"this",
".",
"policyPort",
"=",
"options",
".",
"policyPort",
";",
"}"
] |
FlashWS constructor.
@api public
|
[
"FlashWS",
"constructor",
"."
] |
18f1018b50192793a56e2196119d3fa192578524
|
https://github.com/contra/holla/blob/18f1018b50192793a56e2196119d3fa192578524/holla.js#L2644-L2648
|
train
|
contra/holla
|
holla.js
|
log
|
function log (type) {
return function(){
var str = Array.prototype.join.call(arguments, ' ');
debug('[websocketjs %s] %s', type, str);
};
}
|
javascript
|
function log (type) {
return function(){
var str = Array.prototype.join.call(arguments, ' ');
debug('[websocketjs %s] %s', type, str);
};
}
|
[
"function",
"log",
"(",
"type",
")",
"{",
"return",
"function",
"(",
")",
"{",
"var",
"str",
"=",
"Array",
".",
"prototype",
".",
"join",
".",
"call",
"(",
"arguments",
",",
"' '",
")",
";",
"debug",
"(",
"'[websocketjs %s] %s'",
",",
"type",
",",
"str",
")",
";",
"}",
";",
"}"
] |
instrument websocketjs logging
|
[
"instrument",
"websocketjs",
"logging"
] |
18f1018b50192793a56e2196119d3fa192578524
|
https://github.com/contra/holla/blob/18f1018b50192793a56e2196119d3fa192578524/holla.js#L2677-L2682
|
train
|
contra/holla
|
holla.js
|
load
|
function load (arr, fn) {
function process (i) {
if (!arr[i]) return fn();
create(arr[i], function () {
process(++i);
});
};
process(0);
}
|
javascript
|
function load (arr, fn) {
function process (i) {
if (!arr[i]) return fn();
create(arr[i], function () {
process(++i);
});
};
process(0);
}
|
[
"function",
"load",
"(",
"arr",
",",
"fn",
")",
"{",
"function",
"process",
"(",
"i",
")",
"{",
"if",
"(",
"!",
"arr",
"[",
"i",
"]",
")",
"return",
"fn",
"(",
")",
";",
"create",
"(",
"arr",
"[",
"i",
"]",
",",
"function",
"(",
")",
"{",
"process",
"(",
"++",
"i",
")",
";",
"}",
")",
";",
"}",
";",
"process",
"(",
"0",
")",
";",
"}"
] |
Loads scripts and fires a callback.
@param {Array} paths
@param {Function} callback
|
[
"Loads",
"scripts",
"and",
"fires",
"a",
"callback",
"."
] |
18f1018b50192793a56e2196119d3fa192578524
|
https://github.com/contra/holla/blob/18f1018b50192793a56e2196119d3fa192578524/holla.js#L2861-L2870
|
train
|
anicollection/anicollection
|
config/grunt/tasks/generate_db.js
|
saveCategoryList
|
function saveCategoryList(categoryObject){
var destinationPath = config.dest + 'db_category_list.json';
grunt.file.write(destinationPath, JSON.stringify(categoryObject, null, 4));
grunt.log.writeln('Prefixed file "' + destinationPath + '" created.');
}
|
javascript
|
function saveCategoryList(categoryObject){
var destinationPath = config.dest + 'db_category_list.json';
grunt.file.write(destinationPath, JSON.stringify(categoryObject, null, 4));
grunt.log.writeln('Prefixed file "' + destinationPath + '" created.');
}
|
[
"function",
"saveCategoryList",
"(",
"categoryObject",
")",
"{",
"var",
"destinationPath",
"=",
"config",
".",
"dest",
"+",
"'db_category_list.json'",
";",
"grunt",
".",
"file",
".",
"write",
"(",
"destinationPath",
",",
"JSON",
".",
"stringify",
"(",
"categoryObject",
",",
"null",
",",
"4",
")",
")",
";",
"grunt",
".",
"log",
".",
"writeln",
"(",
"'Prefixed file \"'",
"+",
"destinationPath",
"+",
"'\" created.'",
")",
";",
"}"
] |
Save the category List as json file
@author Dariel Noel <darielnoel@gmail.com>
@since 2015-03-10
@param {[type]} categoryObject [description]
@return {[type]} [description]
|
[
"Save",
"the",
"category",
"List",
"as",
"json",
"file"
] |
f998306f29ae1d130eebcd4c64a9c9737a7613e9
|
https://github.com/anicollection/anicollection/blob/f998306f29ae1d130eebcd4c64a9c9737a7613e9/config/grunt/tasks/generate_db.js#L81-L85
|
train
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.