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 |
---|---|---|---|---|---|---|---|---|---|---|---|
laurent22/joplin
|
Clipper/joplin-webclipper/content_scripts/JSDOMParser.js
|
function (str) {
var strlen = str.length;
if (this.html.substr(this.currentChar, strlen).toLowerCase() === str.toLowerCase()) {
this.currentChar += strlen;
return true;
}
return false;
}
|
javascript
|
function (str) {
var strlen = str.length;
if (this.html.substr(this.currentChar, strlen).toLowerCase() === str.toLowerCase()) {
this.currentChar += strlen;
return true;
}
return false;
}
|
[
"function",
"(",
"str",
")",
"{",
"var",
"strlen",
"=",
"str",
".",
"length",
";",
"if",
"(",
"this",
".",
"html",
".",
"substr",
"(",
"this",
".",
"currentChar",
",",
"strlen",
")",
".",
"toLowerCase",
"(",
")",
"===",
"str",
".",
"toLowerCase",
"(",
")",
")",
"{",
"this",
".",
"currentChar",
"+=",
"strlen",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
If the current input matches this string, advance the input index;
otherwise, do nothing.
@returns whether input matched string
|
[
"If",
"the",
"current",
"input",
"matches",
"this",
"string",
"advance",
"the",
"input",
"index",
";",
"otherwise",
"do",
"nothing",
"."
] |
beb428b246cecba4630a3ca57b472f43c0933a43
|
https://github.com/laurent22/joplin/blob/beb428b246cecba4630a3ca57b472f43c0933a43/Clipper/joplin-webclipper/content_scripts/JSDOMParser.js#L995-L1002
|
train
|
|
laurent22/joplin
|
Clipper/joplin-webclipper/content_scripts/JSDOMParser.js
|
function (str) {
var index = this.html.indexOf(str, this.currentChar) + str.length;
if (index === -1)
this.currentChar = this.html.length;
this.currentChar = index;
}
|
javascript
|
function (str) {
var index = this.html.indexOf(str, this.currentChar) + str.length;
if (index === -1)
this.currentChar = this.html.length;
this.currentChar = index;
}
|
[
"function",
"(",
"str",
")",
"{",
"var",
"index",
"=",
"this",
".",
"html",
".",
"indexOf",
"(",
"str",
",",
"this",
".",
"currentChar",
")",
"+",
"str",
".",
"length",
";",
"if",
"(",
"index",
"===",
"-",
"1",
")",
"this",
".",
"currentChar",
"=",
"this",
".",
"html",
".",
"length",
";",
"this",
".",
"currentChar",
"=",
"index",
";",
"}"
] |
Searches the input until a string is found and discards all input up to
and including the matched string.
|
[
"Searches",
"the",
"input",
"until",
"a",
"string",
"is",
"found",
"and",
"discards",
"all",
"input",
"up",
"to",
"and",
"including",
"the",
"matched",
"string",
"."
] |
beb428b246cecba4630a3ca57b472f43c0933a43
|
https://github.com/laurent22/joplin/blob/beb428b246cecba4630a3ca57b472f43c0933a43/Clipper/joplin-webclipper/content_scripts/JSDOMParser.js#L1008-L1013
|
train
|
|
laurent22/joplin
|
Clipper/joplin-webclipper/content_scripts/JSDOMParser.js
|
function () {
var c = this.nextChar();
if (c === undefined)
return null;
// Read any text as Text node
if (c !== "<") {
--this.currentChar;
var textNode = new Text();
var n = this.html.indexOf("<", this.currentChar);
if (n === -1) {
textNode.innerHTML = this.html.substring(this.currentChar, this.html.length);
this.currentChar = this.html.length;
} else {
textNode.innerHTML = this.html.substring(this.currentChar, n);
this.currentChar = n;
}
return textNode;
}
c = this.peekNext();
// Read Comment node. Normally, Comment nodes know their inner
// textContent, but we don't really care about Comment nodes (we throw
// them away in readChildren()). So just returning an empty Comment node
// here is sufficient.
if (c === "!" || c === "?") {
// We're still before the ! or ? that is starting this comment:
this.currentChar++;
return this.discardNextComment();
}
// If we're reading a closing tag, return null. This means we've reached
// the end of this set of child nodes.
if (c === "/") {
--this.currentChar;
return null;
}
// Otherwise, we're looking at an Element node
var result = this.makeElementNode(this.retPair);
if (!result)
return null;
var node = this.retPair[0];
var closed = this.retPair[1];
var localName = node.localName;
// If this isn't a void Element, read its child nodes
if (!closed) {
this.readChildren(node);
var closingTag = "</" + localName + ">";
if (!this.match(closingTag)) {
this.error("expected '" + closingTag + "' and got " + this.html.substr(this.currentChar, closingTag.length));
return null;
}
}
// Only use the first title, because SVG might have other
// title elements which we don't care about (medium.com
// does this, at least).
if (localName === "title" && !this.doc.title) {
this.doc.title = node.textContent.trim();
} else if (localName === "head") {
this.doc.head = node;
} else if (localName === "body") {
this.doc.body = node;
} else if (localName === "html") {
this.doc.documentElement = node;
}
return node;
}
|
javascript
|
function () {
var c = this.nextChar();
if (c === undefined)
return null;
// Read any text as Text node
if (c !== "<") {
--this.currentChar;
var textNode = new Text();
var n = this.html.indexOf("<", this.currentChar);
if (n === -1) {
textNode.innerHTML = this.html.substring(this.currentChar, this.html.length);
this.currentChar = this.html.length;
} else {
textNode.innerHTML = this.html.substring(this.currentChar, n);
this.currentChar = n;
}
return textNode;
}
c = this.peekNext();
// Read Comment node. Normally, Comment nodes know their inner
// textContent, but we don't really care about Comment nodes (we throw
// them away in readChildren()). So just returning an empty Comment node
// here is sufficient.
if (c === "!" || c === "?") {
// We're still before the ! or ? that is starting this comment:
this.currentChar++;
return this.discardNextComment();
}
// If we're reading a closing tag, return null. This means we've reached
// the end of this set of child nodes.
if (c === "/") {
--this.currentChar;
return null;
}
// Otherwise, we're looking at an Element node
var result = this.makeElementNode(this.retPair);
if (!result)
return null;
var node = this.retPair[0];
var closed = this.retPair[1];
var localName = node.localName;
// If this isn't a void Element, read its child nodes
if (!closed) {
this.readChildren(node);
var closingTag = "</" + localName + ">";
if (!this.match(closingTag)) {
this.error("expected '" + closingTag + "' and got " + this.html.substr(this.currentChar, closingTag.length));
return null;
}
}
// Only use the first title, because SVG might have other
// title elements which we don't care about (medium.com
// does this, at least).
if (localName === "title" && !this.doc.title) {
this.doc.title = node.textContent.trim();
} else if (localName === "head") {
this.doc.head = node;
} else if (localName === "body") {
this.doc.body = node;
} else if (localName === "html") {
this.doc.documentElement = node;
}
return node;
}
|
[
"function",
"(",
")",
"{",
"var",
"c",
"=",
"this",
".",
"nextChar",
"(",
")",
";",
"if",
"(",
"c",
"===",
"undefined",
")",
"return",
"null",
";",
"if",
"(",
"c",
"!==",
"\"<\"",
")",
"{",
"--",
"this",
".",
"currentChar",
";",
"var",
"textNode",
"=",
"new",
"Text",
"(",
")",
";",
"var",
"n",
"=",
"this",
".",
"html",
".",
"indexOf",
"(",
"\"<\"",
",",
"this",
".",
"currentChar",
")",
";",
"if",
"(",
"n",
"===",
"-",
"1",
")",
"{",
"textNode",
".",
"innerHTML",
"=",
"this",
".",
"html",
".",
"substring",
"(",
"this",
".",
"currentChar",
",",
"this",
".",
"html",
".",
"length",
")",
";",
"this",
".",
"currentChar",
"=",
"this",
".",
"html",
".",
"length",
";",
"}",
"else",
"{",
"textNode",
".",
"innerHTML",
"=",
"this",
".",
"html",
".",
"substring",
"(",
"this",
".",
"currentChar",
",",
"n",
")",
";",
"this",
".",
"currentChar",
"=",
"n",
";",
"}",
"return",
"textNode",
";",
"}",
"c",
"=",
"this",
".",
"peekNext",
"(",
")",
";",
"if",
"(",
"c",
"===",
"\"!\"",
"||",
"c",
"===",
"\"?\"",
")",
"{",
"this",
".",
"currentChar",
"++",
";",
"return",
"this",
".",
"discardNextComment",
"(",
")",
";",
"}",
"if",
"(",
"c",
"===",
"\"/\"",
")",
"{",
"--",
"this",
".",
"currentChar",
";",
"return",
"null",
";",
"}",
"var",
"result",
"=",
"this",
".",
"makeElementNode",
"(",
"this",
".",
"retPair",
")",
";",
"if",
"(",
"!",
"result",
")",
"return",
"null",
";",
"var",
"node",
"=",
"this",
".",
"retPair",
"[",
"0",
"]",
";",
"var",
"closed",
"=",
"this",
".",
"retPair",
"[",
"1",
"]",
";",
"var",
"localName",
"=",
"node",
".",
"localName",
";",
"if",
"(",
"!",
"closed",
")",
"{",
"this",
".",
"readChildren",
"(",
"node",
")",
";",
"var",
"closingTag",
"=",
"\"</\"",
"+",
"localName",
"+",
"\">\"",
";",
"if",
"(",
"!",
"this",
".",
"match",
"(",
"closingTag",
")",
")",
"{",
"this",
".",
"error",
"(",
"\"expected '\"",
"+",
"closingTag",
"+",
"\"' and got \"",
"+",
"this",
".",
"html",
".",
"substr",
"(",
"this",
".",
"currentChar",
",",
"closingTag",
".",
"length",
")",
")",
";",
"return",
"null",
";",
"}",
"}",
"if",
"(",
"localName",
"===",
"\"title\"",
"&&",
"!",
"this",
".",
"doc",
".",
"title",
")",
"{",
"this",
".",
"doc",
".",
"title",
"=",
"node",
".",
"textContent",
".",
"trim",
"(",
")",
";",
"}",
"else",
"if",
"(",
"localName",
"===",
"\"head\"",
")",
"{",
"this",
".",
"doc",
".",
"head",
"=",
"node",
";",
"}",
"else",
"if",
"(",
"localName",
"===",
"\"body\"",
")",
"{",
"this",
".",
"doc",
".",
"body",
"=",
"node",
";",
"}",
"else",
"if",
"(",
"localName",
"===",
"\"html\"",
")",
"{",
"this",
".",
"doc",
".",
"documentElement",
"=",
"node",
";",
"}",
"return",
"node",
";",
"}"
] |
Reads the next child node from the input. If we're reading a closing
tag, or if we've reached the end of input, return null.
@returns the node
|
[
"Reads",
"the",
"next",
"child",
"node",
"from",
"the",
"input",
".",
"If",
"we",
"re",
"reading",
"a",
"closing",
"tag",
"or",
"if",
"we",
"ve",
"reached",
"the",
"end",
"of",
"input",
"return",
"null",
"."
] |
beb428b246cecba4630a3ca57b472f43c0933a43
|
https://github.com/laurent22/joplin/blob/beb428b246cecba4630a3ca57b472f43c0933a43/Clipper/joplin-webclipper/content_scripts/JSDOMParser.js#L1051-L1124
|
train
|
|
laurent22/joplin
|
Clipper/joplin-webclipper/content_scripts/JSDOMParser.js
|
function (html, url) {
this.html = html;
var doc = this.doc = new Document(url);
this.readChildren(doc);
// If this is an HTML document, remove root-level children except for the
// <html> node
if (doc.documentElement) {
for (var i = doc.childNodes.length; --i >= 0;) {
var child = doc.childNodes[i];
if (child !== doc.documentElement) {
doc.removeChild(child);
}
}
}
return doc;
}
|
javascript
|
function (html, url) {
this.html = html;
var doc = this.doc = new Document(url);
this.readChildren(doc);
// If this is an HTML document, remove root-level children except for the
// <html> node
if (doc.documentElement) {
for (var i = doc.childNodes.length; --i >= 0;) {
var child = doc.childNodes[i];
if (child !== doc.documentElement) {
doc.removeChild(child);
}
}
}
return doc;
}
|
[
"function",
"(",
"html",
",",
"url",
")",
"{",
"this",
".",
"html",
"=",
"html",
";",
"var",
"doc",
"=",
"this",
".",
"doc",
"=",
"new",
"Document",
"(",
"url",
")",
";",
"this",
".",
"readChildren",
"(",
"doc",
")",
";",
"if",
"(",
"doc",
".",
"documentElement",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"doc",
".",
"childNodes",
".",
"length",
";",
"--",
"i",
">=",
"0",
";",
")",
"{",
"var",
"child",
"=",
"doc",
".",
"childNodes",
"[",
"i",
"]",
";",
"if",
"(",
"child",
"!==",
"doc",
".",
"documentElement",
")",
"{",
"doc",
".",
"removeChild",
"(",
"child",
")",
";",
"}",
"}",
"}",
"return",
"doc",
";",
"}"
] |
Parses an HTML string and returns a JS implementation of the Document.
|
[
"Parses",
"an",
"HTML",
"string",
"and",
"returns",
"a",
"JS",
"implementation",
"of",
"the",
"Document",
"."
] |
beb428b246cecba4630a3ca57b472f43c0933a43
|
https://github.com/laurent22/joplin/blob/beb428b246cecba4630a3ca57b472f43c0933a43/Clipper/joplin-webclipper/content_scripts/JSDOMParser.js#L1129-L1146
|
train
|
|
laurent22/joplin
|
ElectronClient/app/main.js
|
envFromArgs
|
function envFromArgs(args) {
if (!args) return 'prod';
const envIndex = args.indexOf('--env');
const devIndex = args.indexOf('dev');
if (envIndex === devIndex - 1) return 'dev';
return 'prod';
}
|
javascript
|
function envFromArgs(args) {
if (!args) return 'prod';
const envIndex = args.indexOf('--env');
const devIndex = args.indexOf('dev');
if (envIndex === devIndex - 1) return 'dev';
return 'prod';
}
|
[
"function",
"envFromArgs",
"(",
"args",
")",
"{",
"if",
"(",
"!",
"args",
")",
"return",
"'prod'",
";",
"const",
"envIndex",
"=",
"args",
".",
"indexOf",
"(",
"'--env'",
")",
";",
"const",
"devIndex",
"=",
"args",
".",
"indexOf",
"(",
"'dev'",
")",
";",
"if",
"(",
"envIndex",
"===",
"devIndex",
"-",
"1",
")",
"return",
"'dev'",
";",
"return",
"'prod'",
";",
"}"
] |
Flags are parsed properly in BaseApplication, however it's better to have the env as early as possible to enable debugging capabilities.
|
[
"Flags",
"are",
"parsed",
"properly",
"in",
"BaseApplication",
"however",
"it",
"s",
"better",
"to",
"have",
"the",
"env",
"as",
"early",
"as",
"possible",
"to",
"enable",
"debugging",
"capabilities",
"."
] |
beb428b246cecba4630a3ca57b472f43c0933a43
|
https://github.com/laurent22/joplin/blob/beb428b246cecba4630a3ca57b472f43c0933a43/ElectronClient/app/main.js#L19-L25
|
train
|
laurent22/joplin
|
ElectronClient/app/main.js
|
profileFromArgs
|
function profileFromArgs(args) {
if (!args) return null;
const profileIndex = args.indexOf('--profile');
if (profileIndex <= 0 || profileIndex >= args.length - 1) return null;
const profileValue = args[profileIndex + 1];
return profileValue ? profileValue : null;
}
|
javascript
|
function profileFromArgs(args) {
if (!args) return null;
const profileIndex = args.indexOf('--profile');
if (profileIndex <= 0 || profileIndex >= args.length - 1) return null;
const profileValue = args[profileIndex + 1];
return profileValue ? profileValue : null;
}
|
[
"function",
"profileFromArgs",
"(",
"args",
")",
"{",
"if",
"(",
"!",
"args",
")",
"return",
"null",
";",
"const",
"profileIndex",
"=",
"args",
".",
"indexOf",
"(",
"'--profile'",
")",
";",
"if",
"(",
"profileIndex",
"<=",
"0",
"||",
"profileIndex",
">=",
"args",
".",
"length",
"-",
"1",
")",
"return",
"null",
";",
"const",
"profileValue",
"=",
"args",
"[",
"profileIndex",
"+",
"1",
"]",
";",
"return",
"profileValue",
"?",
"profileValue",
":",
"null",
";",
"}"
] |
Likewise, we want to know if a profile is specified early, in particular to save the window state data.
|
[
"Likewise",
"we",
"want",
"to",
"know",
"if",
"a",
"profile",
"is",
"specified",
"early",
"in",
"particular",
"to",
"save",
"the",
"window",
"state",
"data",
"."
] |
beb428b246cecba4630a3ca57b472f43c0933a43
|
https://github.com/laurent22/joplin/blob/beb428b246cecba4630a3ca57b472f43c0933a43/ElectronClient/app/main.js#L29-L35
|
train
|
laurent22/joplin
|
ReactNativeClient/lib/import-enex-md-gen.js
|
function(lines) {
let output = [];
let newlineCount = 0;
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
if (!line.trim()) {
newlineCount++;
} else {
newlineCount = 0;
}
if (newlineCount >= 2) continue;
output.push(line);
}
return output;
}
|
javascript
|
function(lines) {
let output = [];
let newlineCount = 0;
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
if (!line.trim()) {
newlineCount++;
} else {
newlineCount = 0;
}
if (newlineCount >= 2) continue;
output.push(line);
}
return output;
}
|
[
"function",
"(",
"lines",
")",
"{",
"let",
"output",
"=",
"[",
"]",
";",
"let",
"newlineCount",
"=",
"0",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"lines",
".",
"length",
";",
"i",
"++",
")",
"{",
"const",
"line",
"=",
"lines",
"[",
"i",
"]",
";",
"if",
"(",
"!",
"line",
".",
"trim",
"(",
")",
")",
"{",
"newlineCount",
"++",
";",
"}",
"else",
"{",
"newlineCount",
"=",
"0",
";",
"}",
"if",
"(",
"newlineCount",
">=",
"2",
")",
"continue",
";",
"output",
".",
"push",
"(",
"line",
")",
";",
"}",
"return",
"output",
";",
"}"
] |
To simplify the result, we only allow up to one empty line between blocks of text
|
[
"To",
"simplify",
"the",
"result",
"we",
"only",
"allow",
"up",
"to",
"one",
"empty",
"line",
"between",
"blocks",
"of",
"text"
] |
beb428b246cecba4630a3ca57b472f43c0933a43
|
https://github.com/laurent22/joplin/blob/beb428b246cecba4630a3ca57b472f43c0933a43/ReactNativeClient/lib/import-enex-md-gen.js#L108-L124
|
train
|
|
laurent22/joplin
|
ReactNativeClient/lib/reducer.js
|
handleItemDelete
|
function handleItemDelete(state, action) {
let newState = Object.assign({}, state);
const map = {
'FOLDER_DELETE': ['folders', 'selectedFolderId'],
'NOTE_DELETE': ['notes', 'selectedNoteIds'],
'TAG_DELETE': ['tags', 'selectedTagId'],
'SEARCH_DELETE': ['searches', 'selectedSearchId'],
};
const listKey = map[action.type][0];
const selectedItemKey = map[action.type][1];
let previousIndex = 0;
let newItems = [];
const items = state[listKey];
for (let i = 0; i < items.length; i++) {
let item = items[i];
if (item.id == action.id) {
previousIndex = i;
continue;
}
newItems.push(item);
}
newState = Object.assign({}, state);
newState[listKey] = newItems;
if (previousIndex >= newItems.length) {
previousIndex = newItems.length - 1;
}
const newId = previousIndex >= 0 ? newItems[previousIndex].id : null;
newState[selectedItemKey] = action.type === 'NOTE_DELETE' ? [newId] : newId;
if (!newId && newState.notesParentType !== 'Folder') {
newState.notesParentType = 'Folder';
}
return newState;
}
|
javascript
|
function handleItemDelete(state, action) {
let newState = Object.assign({}, state);
const map = {
'FOLDER_DELETE': ['folders', 'selectedFolderId'],
'NOTE_DELETE': ['notes', 'selectedNoteIds'],
'TAG_DELETE': ['tags', 'selectedTagId'],
'SEARCH_DELETE': ['searches', 'selectedSearchId'],
};
const listKey = map[action.type][0];
const selectedItemKey = map[action.type][1];
let previousIndex = 0;
let newItems = [];
const items = state[listKey];
for (let i = 0; i < items.length; i++) {
let item = items[i];
if (item.id == action.id) {
previousIndex = i;
continue;
}
newItems.push(item);
}
newState = Object.assign({}, state);
newState[listKey] = newItems;
if (previousIndex >= newItems.length) {
previousIndex = newItems.length - 1;
}
const newId = previousIndex >= 0 ? newItems[previousIndex].id : null;
newState[selectedItemKey] = action.type === 'NOTE_DELETE' ? [newId] : newId;
if (!newId && newState.notesParentType !== 'Folder') {
newState.notesParentType = 'Folder';
}
return newState;
}
|
[
"function",
"handleItemDelete",
"(",
"state",
",",
"action",
")",
"{",
"let",
"newState",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"state",
")",
";",
"const",
"map",
"=",
"{",
"'FOLDER_DELETE'",
":",
"[",
"'folders'",
",",
"'selectedFolderId'",
"]",
",",
"'NOTE_DELETE'",
":",
"[",
"'notes'",
",",
"'selectedNoteIds'",
"]",
",",
"'TAG_DELETE'",
":",
"[",
"'tags'",
",",
"'selectedTagId'",
"]",
",",
"'SEARCH_DELETE'",
":",
"[",
"'searches'",
",",
"'selectedSearchId'",
"]",
",",
"}",
";",
"const",
"listKey",
"=",
"map",
"[",
"action",
".",
"type",
"]",
"[",
"0",
"]",
";",
"const",
"selectedItemKey",
"=",
"map",
"[",
"action",
".",
"type",
"]",
"[",
"1",
"]",
";",
"let",
"previousIndex",
"=",
"0",
";",
"let",
"newItems",
"=",
"[",
"]",
";",
"const",
"items",
"=",
"state",
"[",
"listKey",
"]",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"items",
".",
"length",
";",
"i",
"++",
")",
"{",
"let",
"item",
"=",
"items",
"[",
"i",
"]",
";",
"if",
"(",
"item",
".",
"id",
"==",
"action",
".",
"id",
")",
"{",
"previousIndex",
"=",
"i",
";",
"continue",
";",
"}",
"newItems",
".",
"push",
"(",
"item",
")",
";",
"}",
"newState",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"state",
")",
";",
"newState",
"[",
"listKey",
"]",
"=",
"newItems",
";",
"if",
"(",
"previousIndex",
">=",
"newItems",
".",
"length",
")",
"{",
"previousIndex",
"=",
"newItems",
".",
"length",
"-",
"1",
";",
"}",
"const",
"newId",
"=",
"previousIndex",
">=",
"0",
"?",
"newItems",
"[",
"previousIndex",
"]",
".",
"id",
":",
"null",
";",
"newState",
"[",
"selectedItemKey",
"]",
"=",
"action",
".",
"type",
"===",
"'NOTE_DELETE'",
"?",
"[",
"newId",
"]",
":",
"newId",
";",
"if",
"(",
"!",
"newId",
"&&",
"newState",
".",
"notesParentType",
"!==",
"'Folder'",
")",
"{",
"newState",
".",
"notesParentType",
"=",
"'Folder'",
";",
"}",
"return",
"newState",
";",
"}"
] |
When deleting a note, tag or folder
|
[
"When",
"deleting",
"a",
"note",
"tag",
"or",
"folder"
] |
beb428b246cecba4630a3ca57b472f43c0933a43
|
https://github.com/laurent22/joplin/blob/beb428b246cecba4630a3ca57b472f43c0933a43/ReactNativeClient/lib/reducer.js#L119-L159
|
train
|
laurent22/joplin
|
Clipper/joplin-webclipper/content_scripts/Readability.js
|
function(nodeList, filterFn) {
for (var i = nodeList.length - 1; i >= 0; i--) {
var node = nodeList[i];
var parentNode = node.parentNode;
if (parentNode) {
if (!filterFn || filterFn.call(this, node, i, nodeList)) {
parentNode.removeChild(node);
}
}
}
}
|
javascript
|
function(nodeList, filterFn) {
for (var i = nodeList.length - 1; i >= 0; i--) {
var node = nodeList[i];
var parentNode = node.parentNode;
if (parentNode) {
if (!filterFn || filterFn.call(this, node, i, nodeList)) {
parentNode.removeChild(node);
}
}
}
}
|
[
"function",
"(",
"nodeList",
",",
"filterFn",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"nodeList",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"var",
"node",
"=",
"nodeList",
"[",
"i",
"]",
";",
"var",
"parentNode",
"=",
"node",
".",
"parentNode",
";",
"if",
"(",
"parentNode",
")",
"{",
"if",
"(",
"!",
"filterFn",
"||",
"filterFn",
".",
"call",
"(",
"this",
",",
"node",
",",
"i",
",",
"nodeList",
")",
")",
"{",
"parentNode",
".",
"removeChild",
"(",
"node",
")",
";",
"}",
"}",
"}",
"}"
] |
Iterates over a NodeList, calls `filterFn` for each node and removes node
if function returned `true`.
If function is not passed, removes all the nodes in node list.
@param NodeList nodeList The nodes to operate on
@param Function filterFn the function to use as a filter
@return void
|
[
"Iterates",
"over",
"a",
"NodeList",
"calls",
"filterFn",
"for",
"each",
"node",
"and",
"removes",
"node",
"if",
"function",
"returned",
"true",
"."
] |
beb428b246cecba4630a3ca57b472f43c0933a43
|
https://github.com/laurent22/joplin/blob/beb428b246cecba4630a3ca57b472f43c0933a43/Clipper/joplin-webclipper/content_scripts/Readability.js#L175-L185
|
train
|
|
laurent22/joplin
|
Clipper/joplin-webclipper/content_scripts/Readability.js
|
function(nodeList, newTagName) {
for (var i = nodeList.length - 1; i >= 0; i--) {
var node = nodeList[i];
this._setNodeTag(node, newTagName);
}
}
|
javascript
|
function(nodeList, newTagName) {
for (var i = nodeList.length - 1; i >= 0; i--) {
var node = nodeList[i];
this._setNodeTag(node, newTagName);
}
}
|
[
"function",
"(",
"nodeList",
",",
"newTagName",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"nodeList",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"var",
"node",
"=",
"nodeList",
"[",
"i",
"]",
";",
"this",
".",
"_setNodeTag",
"(",
"node",
",",
"newTagName",
")",
";",
"}",
"}"
] |
Iterates over a NodeList, and calls _setNodeTag for each node.
@param NodeList nodeList The nodes to operate on
@param String newTagName the new tag name to use
@return void
|
[
"Iterates",
"over",
"a",
"NodeList",
"and",
"calls",
"_setNodeTag",
"for",
"each",
"node",
"."
] |
beb428b246cecba4630a3ca57b472f43c0933a43
|
https://github.com/laurent22/joplin/blob/beb428b246cecba4630a3ca57b472f43c0933a43/Clipper/joplin-webclipper/content_scripts/Readability.js#L194-L199
|
train
|
|
laurent22/joplin
|
Clipper/joplin-webclipper/content_scripts/Readability.js
|
function() {
var slice = Array.prototype.slice;
var args = slice.call(arguments);
var nodeLists = args.map(function(list) {
return slice.call(list);
});
return Array.prototype.concat.apply([], nodeLists);
}
|
javascript
|
function() {
var slice = Array.prototype.slice;
var args = slice.call(arguments);
var nodeLists = args.map(function(list) {
return slice.call(list);
});
return Array.prototype.concat.apply([], nodeLists);
}
|
[
"function",
"(",
")",
"{",
"var",
"slice",
"=",
"Array",
".",
"prototype",
".",
"slice",
";",
"var",
"args",
"=",
"slice",
".",
"call",
"(",
"arguments",
")",
";",
"var",
"nodeLists",
"=",
"args",
".",
"map",
"(",
"function",
"(",
"list",
")",
"{",
"return",
"slice",
".",
"call",
"(",
"list",
")",
";",
"}",
")",
";",
"return",
"Array",
".",
"prototype",
".",
"concat",
".",
"apply",
"(",
"[",
"]",
",",
"nodeLists",
")",
";",
"}"
] |
Concat all nodelists passed as arguments.
@return ...NodeList
@return Array
|
[
"Concat",
"all",
"nodelists",
"passed",
"as",
"arguments",
"."
] |
beb428b246cecba4630a3ca57b472f43c0933a43
|
https://github.com/laurent22/joplin/blob/beb428b246cecba4630a3ca57b472f43c0933a43/Clipper/joplin-webclipper/content_scripts/Readability.js#L252-L259
|
train
|
|
laurent22/joplin
|
Clipper/joplin-webclipper/content_scripts/Readability.js
|
function(node) {
var classesToPreserve = this._classesToPreserve;
var className = (node.getAttribute("class") || "")
.split(/\s+/)
.filter(function(cls) {
return classesToPreserve.indexOf(cls) != -1;
})
.join(" ");
if (className) {
node.setAttribute("class", className);
} else {
node.removeAttribute("class");
}
for (node = node.firstElementChild; node; node = node.nextElementSibling) {
this._cleanClasses(node);
}
}
|
javascript
|
function(node) {
var classesToPreserve = this._classesToPreserve;
var className = (node.getAttribute("class") || "")
.split(/\s+/)
.filter(function(cls) {
return classesToPreserve.indexOf(cls) != -1;
})
.join(" ");
if (className) {
node.setAttribute("class", className);
} else {
node.removeAttribute("class");
}
for (node = node.firstElementChild; node; node = node.nextElementSibling) {
this._cleanClasses(node);
}
}
|
[
"function",
"(",
"node",
")",
"{",
"var",
"classesToPreserve",
"=",
"this",
".",
"_classesToPreserve",
";",
"var",
"className",
"=",
"(",
"node",
".",
"getAttribute",
"(",
"\"class\"",
")",
"||",
"\"\"",
")",
".",
"split",
"(",
"/",
"\\s+",
"/",
")",
".",
"filter",
"(",
"function",
"(",
"cls",
")",
"{",
"return",
"classesToPreserve",
".",
"indexOf",
"(",
"cls",
")",
"!=",
"-",
"1",
";",
"}",
")",
".",
"join",
"(",
"\" \"",
")",
";",
"if",
"(",
"className",
")",
"{",
"node",
".",
"setAttribute",
"(",
"\"class\"",
",",
"className",
")",
";",
"}",
"else",
"{",
"node",
".",
"removeAttribute",
"(",
"\"class\"",
")",
";",
"}",
"for",
"(",
"node",
"=",
"node",
".",
"firstElementChild",
";",
"node",
";",
"node",
"=",
"node",
".",
"nextElementSibling",
")",
"{",
"this",
".",
"_cleanClasses",
"(",
"node",
")",
";",
"}",
"}"
] |
Removes the class="" attribute from every element in the given
subtree, except those that match CLASSES_TO_PRESERVE and
the classesToPreserve array from the options object.
@param Element
@return void
|
[
"Removes",
"the",
"class",
"=",
"attribute",
"from",
"every",
"element",
"in",
"the",
"given",
"subtree",
"except",
"those",
"that",
"match",
"CLASSES_TO_PRESERVE",
"and",
"the",
"classesToPreserve",
"array",
"from",
"the",
"options",
"object",
"."
] |
beb428b246cecba4630a3ca57b472f43c0933a43
|
https://github.com/laurent22/joplin/blob/beb428b246cecba4630a3ca57b472f43c0933a43/Clipper/joplin-webclipper/content_scripts/Readability.js#L279-L297
|
train
|
|
laurent22/joplin
|
Clipper/joplin-webclipper/content_scripts/Readability.js
|
function() {
var doc = this._doc;
// Remove all style tags in head
this._removeNodes(doc.getElementsByTagName("style"));
if (doc.body) {
this._replaceBrs(doc.body);
}
this._replaceNodeTags(doc.getElementsByTagName("font"), "SPAN");
}
|
javascript
|
function() {
var doc = this._doc;
// Remove all style tags in head
this._removeNodes(doc.getElementsByTagName("style"));
if (doc.body) {
this._replaceBrs(doc.body);
}
this._replaceNodeTags(doc.getElementsByTagName("font"), "SPAN");
}
|
[
"function",
"(",
")",
"{",
"var",
"doc",
"=",
"this",
".",
"_doc",
";",
"this",
".",
"_removeNodes",
"(",
"doc",
".",
"getElementsByTagName",
"(",
"\"style\"",
")",
")",
";",
"if",
"(",
"doc",
".",
"body",
")",
"{",
"this",
".",
"_replaceBrs",
"(",
"doc",
".",
"body",
")",
";",
"}",
"this",
".",
"_replaceNodeTags",
"(",
"doc",
".",
"getElementsByTagName",
"(",
"\"font\"",
")",
",",
"\"SPAN\"",
")",
";",
"}"
] |
Prepare the HTML document for readability to scrape it.
This includes things like stripping javascript, CSS, and handling terrible markup.
@return void
|
[
"Prepare",
"the",
"HTML",
"document",
"for",
"readability",
"to",
"scrape",
"it",
".",
"This",
"includes",
"things",
"like",
"stripping",
"javascript",
"CSS",
"and",
"handling",
"terrible",
"markup",
"."
] |
beb428b246cecba4630a3ca57b472f43c0933a43
|
https://github.com/laurent22/joplin/blob/beb428b246cecba4630a3ca57b472f43c0933a43/Clipper/joplin-webclipper/content_scripts/Readability.js#L431-L442
|
train
|
|
laurent22/joplin
|
Clipper/joplin-webclipper/content_scripts/Readability.js
|
function (node) {
var next = node;
while (next
&& (next.nodeType != this.ELEMENT_NODE)
&& this.REGEXPS.whitespace.test(next.textContent)) {
next = next.nextSibling;
}
return next;
}
|
javascript
|
function (node) {
var next = node;
while (next
&& (next.nodeType != this.ELEMENT_NODE)
&& this.REGEXPS.whitespace.test(next.textContent)) {
next = next.nextSibling;
}
return next;
}
|
[
"function",
"(",
"node",
")",
"{",
"var",
"next",
"=",
"node",
";",
"while",
"(",
"next",
"&&",
"(",
"next",
".",
"nodeType",
"!=",
"this",
".",
"ELEMENT_NODE",
")",
"&&",
"this",
".",
"REGEXPS",
".",
"whitespace",
".",
"test",
"(",
"next",
".",
"textContent",
")",
")",
"{",
"next",
"=",
"next",
".",
"nextSibling",
";",
"}",
"return",
"next",
";",
"}"
] |
Finds the next element, starting from the given node, and ignoring
whitespace in between. If the given node is an element, the same node is
returned.
|
[
"Finds",
"the",
"next",
"element",
"starting",
"from",
"the",
"given",
"node",
"and",
"ignoring",
"whitespace",
"in",
"between",
".",
"If",
"the",
"given",
"node",
"is",
"an",
"element",
"the",
"same",
"node",
"is",
"returned",
"."
] |
beb428b246cecba4630a3ca57b472f43c0933a43
|
https://github.com/laurent22/joplin/blob/beb428b246cecba4630a3ca57b472f43c0933a43/Clipper/joplin-webclipper/content_scripts/Readability.js#L449-L457
|
train
|
|
laurent22/joplin
|
Clipper/joplin-webclipper/content_scripts/Readability.js
|
function(byline) {
if (typeof byline == 'string' || byline instanceof String) {
byline = byline.trim();
return (byline.length > 0) && (byline.length < 100);
}
return false;
}
|
javascript
|
function(byline) {
if (typeof byline == 'string' || byline instanceof String) {
byline = byline.trim();
return (byline.length > 0) && (byline.length < 100);
}
return false;
}
|
[
"function",
"(",
"byline",
")",
"{",
"if",
"(",
"typeof",
"byline",
"==",
"'string'",
"||",
"byline",
"instanceof",
"String",
")",
"{",
"byline",
"=",
"byline",
".",
"trim",
"(",
")",
";",
"return",
"(",
"byline",
".",
"length",
">",
"0",
")",
"&&",
"(",
"byline",
".",
"length",
"<",
"100",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Check whether the input string could be a byline.
This verifies that the input is a string, and that the length
is less than 100 chars.
@param possibleByline {string} - a string to check whether its a byline.
@return Boolean - whether the input string is a byline.
|
[
"Check",
"whether",
"the",
"input",
"string",
"could",
"be",
"a",
"byline",
".",
"This",
"verifies",
"that",
"the",
"input",
"is",
"a",
"string",
"and",
"that",
"the",
"length",
"is",
"less",
"than",
"100",
"chars",
"."
] |
beb428b246cecba4630a3ca57b472f43c0933a43
|
https://github.com/laurent22/joplin/blob/beb428b246cecba4630a3ca57b472f43c0933a43/Clipper/joplin-webclipper/content_scripts/Readability.js#L1186-L1192
|
train
|
|
laurent22/joplin
|
Clipper/joplin-webclipper/content_scripts/Readability.js
|
function() {
var metadata = {};
var values = {};
var metaElements = this._doc.getElementsByTagName("meta");
// Match "description", or Twitter's "twitter:description" (Cards)
// in name attribute.
var namePattern = /^\s*((twitter)\s*:\s*)?(description|title)\s*$/gi;
// Match Facebook's Open Graph title & description properties.
var propertyPattern = /^\s*og\s*:\s*(description|title)\s*$/gi;
// Find description tags.
this._forEachNode(metaElements, function(element) {
var elementName = element.getAttribute("name");
var elementProperty = element.getAttribute("property");
if ([elementName, elementProperty].indexOf("author") !== -1) {
metadata.byline = element.getAttribute("content");
return;
}
var name = null;
if (namePattern.test(elementName)) {
name = elementName;
} else if (propertyPattern.test(elementProperty)) {
name = elementProperty;
}
if (name) {
var content = element.getAttribute("content");
if (content) {
// Convert to lowercase and remove any whitespace
// so we can match below.
name = name.toLowerCase().replace(/\s/g, '');
values[name] = content.trim();
}
}
});
if ("description" in values) {
metadata.excerpt = values["description"];
} else if ("og:description" in values) {
// Use facebook open graph description.
metadata.excerpt = values["og:description"];
} else if ("twitter:description" in values) {
// Use twitter cards description.
metadata.excerpt = values["twitter:description"];
}
metadata.title = this._getArticleTitle();
if (!metadata.title) {
if ("og:title" in values) {
// Use facebook open graph title.
metadata.title = values["og:title"];
} else if ("twitter:title" in values) {
// Use twitter cards title.
metadata.title = values["twitter:title"];
}
}
return metadata;
}
|
javascript
|
function() {
var metadata = {};
var values = {};
var metaElements = this._doc.getElementsByTagName("meta");
// Match "description", or Twitter's "twitter:description" (Cards)
// in name attribute.
var namePattern = /^\s*((twitter)\s*:\s*)?(description|title)\s*$/gi;
// Match Facebook's Open Graph title & description properties.
var propertyPattern = /^\s*og\s*:\s*(description|title)\s*$/gi;
// Find description tags.
this._forEachNode(metaElements, function(element) {
var elementName = element.getAttribute("name");
var elementProperty = element.getAttribute("property");
if ([elementName, elementProperty].indexOf("author") !== -1) {
metadata.byline = element.getAttribute("content");
return;
}
var name = null;
if (namePattern.test(elementName)) {
name = elementName;
} else if (propertyPattern.test(elementProperty)) {
name = elementProperty;
}
if (name) {
var content = element.getAttribute("content");
if (content) {
// Convert to lowercase and remove any whitespace
// so we can match below.
name = name.toLowerCase().replace(/\s/g, '');
values[name] = content.trim();
}
}
});
if ("description" in values) {
metadata.excerpt = values["description"];
} else if ("og:description" in values) {
// Use facebook open graph description.
metadata.excerpt = values["og:description"];
} else if ("twitter:description" in values) {
// Use twitter cards description.
metadata.excerpt = values["twitter:description"];
}
metadata.title = this._getArticleTitle();
if (!metadata.title) {
if ("og:title" in values) {
// Use facebook open graph title.
metadata.title = values["og:title"];
} else if ("twitter:title" in values) {
// Use twitter cards title.
metadata.title = values["twitter:title"];
}
}
return metadata;
}
|
[
"function",
"(",
")",
"{",
"var",
"metadata",
"=",
"{",
"}",
";",
"var",
"values",
"=",
"{",
"}",
";",
"var",
"metaElements",
"=",
"this",
".",
"_doc",
".",
"getElementsByTagName",
"(",
"\"meta\"",
")",
";",
"var",
"namePattern",
"=",
"/",
"^\\s*((twitter)\\s*:\\s*)?(description|title)\\s*$",
"/",
"gi",
";",
"var",
"propertyPattern",
"=",
"/",
"^\\s*og\\s*:\\s*(description|title)\\s*$",
"/",
"gi",
";",
"this",
".",
"_forEachNode",
"(",
"metaElements",
",",
"function",
"(",
"element",
")",
"{",
"var",
"elementName",
"=",
"element",
".",
"getAttribute",
"(",
"\"name\"",
")",
";",
"var",
"elementProperty",
"=",
"element",
".",
"getAttribute",
"(",
"\"property\"",
")",
";",
"if",
"(",
"[",
"elementName",
",",
"elementProperty",
"]",
".",
"indexOf",
"(",
"\"author\"",
")",
"!==",
"-",
"1",
")",
"{",
"metadata",
".",
"byline",
"=",
"element",
".",
"getAttribute",
"(",
"\"content\"",
")",
";",
"return",
";",
"}",
"var",
"name",
"=",
"null",
";",
"if",
"(",
"namePattern",
".",
"test",
"(",
"elementName",
")",
")",
"{",
"name",
"=",
"elementName",
";",
"}",
"else",
"if",
"(",
"propertyPattern",
".",
"test",
"(",
"elementProperty",
")",
")",
"{",
"name",
"=",
"elementProperty",
";",
"}",
"if",
"(",
"name",
")",
"{",
"var",
"content",
"=",
"element",
".",
"getAttribute",
"(",
"\"content\"",
")",
";",
"if",
"(",
"content",
")",
"{",
"name",
"=",
"name",
".",
"toLowerCase",
"(",
")",
".",
"replace",
"(",
"/",
"\\s",
"/",
"g",
",",
"''",
")",
";",
"values",
"[",
"name",
"]",
"=",
"content",
".",
"trim",
"(",
")",
";",
"}",
"}",
"}",
")",
";",
"if",
"(",
"\"description\"",
"in",
"values",
")",
"{",
"metadata",
".",
"excerpt",
"=",
"values",
"[",
"\"description\"",
"]",
";",
"}",
"else",
"if",
"(",
"\"og:description\"",
"in",
"values",
")",
"{",
"metadata",
".",
"excerpt",
"=",
"values",
"[",
"\"og:description\"",
"]",
";",
"}",
"else",
"if",
"(",
"\"twitter:description\"",
"in",
"values",
")",
"{",
"metadata",
".",
"excerpt",
"=",
"values",
"[",
"\"twitter:description\"",
"]",
";",
"}",
"metadata",
".",
"title",
"=",
"this",
".",
"_getArticleTitle",
"(",
")",
";",
"if",
"(",
"!",
"metadata",
".",
"title",
")",
"{",
"if",
"(",
"\"og:title\"",
"in",
"values",
")",
"{",
"metadata",
".",
"title",
"=",
"values",
"[",
"\"og:title\"",
"]",
";",
"}",
"else",
"if",
"(",
"\"twitter:title\"",
"in",
"values",
")",
"{",
"metadata",
".",
"title",
"=",
"values",
"[",
"\"twitter:title\"",
"]",
";",
"}",
"}",
"return",
"metadata",
";",
"}"
] |
Attempts to get excerpt and byline metadata for the article.
@return Object with optional "excerpt" and "byline" properties
|
[
"Attempts",
"to",
"get",
"excerpt",
"and",
"byline",
"metadata",
"for",
"the",
"article",
"."
] |
beb428b246cecba4630a3ca57b472f43c0933a43
|
https://github.com/laurent22/joplin/blob/beb428b246cecba4630a3ca57b472f43c0933a43/Clipper/joplin-webclipper/content_scripts/Readability.js#L1199-L1261
|
train
|
|
laurent22/joplin
|
Clipper/joplin-webclipper/content_scripts/Readability.js
|
function(doc) {
this._removeNodes(doc.getElementsByTagName('script'), function(scriptNode) {
scriptNode.nodeValue = "";
scriptNode.removeAttribute('src');
return true;
});
this._removeNodes(doc.getElementsByTagName('noscript'));
}
|
javascript
|
function(doc) {
this._removeNodes(doc.getElementsByTagName('script'), function(scriptNode) {
scriptNode.nodeValue = "";
scriptNode.removeAttribute('src');
return true;
});
this._removeNodes(doc.getElementsByTagName('noscript'));
}
|
[
"function",
"(",
"doc",
")",
"{",
"this",
".",
"_removeNodes",
"(",
"doc",
".",
"getElementsByTagName",
"(",
"'script'",
")",
",",
"function",
"(",
"scriptNode",
")",
"{",
"scriptNode",
".",
"nodeValue",
"=",
"\"\"",
";",
"scriptNode",
".",
"removeAttribute",
"(",
"'src'",
")",
";",
"return",
"true",
";",
"}",
")",
";",
"this",
".",
"_removeNodes",
"(",
"doc",
".",
"getElementsByTagName",
"(",
"'noscript'",
")",
")",
";",
"}"
] |
Removes script tags from the document.
@param Element
|
[
"Removes",
"script",
"tags",
"from",
"the",
"document",
"."
] |
beb428b246cecba4630a3ca57b472f43c0933a43
|
https://github.com/laurent22/joplin/blob/beb428b246cecba4630a3ca57b472f43c0933a43/Clipper/joplin-webclipper/content_scripts/Readability.js#L1268-L1275
|
train
|
|
laurent22/joplin
|
Clipper/joplin-webclipper/content_scripts/Readability.js
|
function(element) {
// There should be exactly 1 element child which is a P:
if (element.children.length != 1 || element.children[0].tagName !== "P") {
return false;
}
// And there should be no text nodes with real content
return !this._someNode(element.childNodes, function(node) {
return node.nodeType === this.TEXT_NODE &&
this.REGEXPS.hasContent.test(node.textContent);
});
}
|
javascript
|
function(element) {
// There should be exactly 1 element child which is a P:
if (element.children.length != 1 || element.children[0].tagName !== "P") {
return false;
}
// And there should be no text nodes with real content
return !this._someNode(element.childNodes, function(node) {
return node.nodeType === this.TEXT_NODE &&
this.REGEXPS.hasContent.test(node.textContent);
});
}
|
[
"function",
"(",
"element",
")",
"{",
"if",
"(",
"element",
".",
"children",
".",
"length",
"!=",
"1",
"||",
"element",
".",
"children",
"[",
"0",
"]",
".",
"tagName",
"!==",
"\"P\"",
")",
"{",
"return",
"false",
";",
"}",
"return",
"!",
"this",
".",
"_someNode",
"(",
"element",
".",
"childNodes",
",",
"function",
"(",
"node",
")",
"{",
"return",
"node",
".",
"nodeType",
"===",
"this",
".",
"TEXT_NODE",
"&&",
"this",
".",
"REGEXPS",
".",
"hasContent",
".",
"test",
"(",
"node",
".",
"textContent",
")",
";",
"}",
")",
";",
"}"
] |
Check if this node has only whitespace and a single P element
Returns false if the DIV node contains non-empty text nodes
or if it contains no P or more than 1 element.
@param Element
|
[
"Check",
"if",
"this",
"node",
"has",
"only",
"whitespace",
"and",
"a",
"single",
"P",
"element",
"Returns",
"false",
"if",
"the",
"DIV",
"node",
"contains",
"non",
"-",
"empty",
"text",
"nodes",
"or",
"if",
"it",
"contains",
"no",
"P",
"or",
"more",
"than",
"1",
"element",
"."
] |
beb428b246cecba4630a3ca57b472f43c0933a43
|
https://github.com/laurent22/joplin/blob/beb428b246cecba4630a3ca57b472f43c0933a43/Clipper/joplin-webclipper/content_scripts/Readability.js#L1284-L1295
|
train
|
|
laurent22/joplin
|
Clipper/joplin-webclipper/content_scripts/Readability.js
|
function (element) {
return this._someNode(element.childNodes, function(node) {
return this.DIV_TO_P_ELEMS.indexOf(node.tagName) !== -1 ||
this._hasChildBlockElement(node);
});
}
|
javascript
|
function (element) {
return this._someNode(element.childNodes, function(node) {
return this.DIV_TO_P_ELEMS.indexOf(node.tagName) !== -1 ||
this._hasChildBlockElement(node);
});
}
|
[
"function",
"(",
"element",
")",
"{",
"return",
"this",
".",
"_someNode",
"(",
"element",
".",
"childNodes",
",",
"function",
"(",
"node",
")",
"{",
"return",
"this",
".",
"DIV_TO_P_ELEMS",
".",
"indexOf",
"(",
"node",
".",
"tagName",
")",
"!==",
"-",
"1",
"||",
"this",
".",
"_hasChildBlockElement",
"(",
"node",
")",
";",
"}",
")",
";",
"}"
] |
Determine whether element has any children block level elements.
@param Element
|
[
"Determine",
"whether",
"element",
"has",
"any",
"children",
"block",
"level",
"elements",
"."
] |
beb428b246cecba4630a3ca57b472f43c0933a43
|
https://github.com/laurent22/joplin/blob/beb428b246cecba4630a3ca57b472f43c0933a43/Clipper/joplin-webclipper/content_scripts/Readability.js#L1309-L1314
|
train
|
|
laurent22/joplin
|
Clipper/joplin-webclipper/content_scripts/Readability.js
|
function(e, normalizeSpaces) {
normalizeSpaces = (typeof normalizeSpaces === 'undefined') ? true : normalizeSpaces;
var textContent = e.textContent.trim();
if (normalizeSpaces) {
return textContent.replace(this.REGEXPS.normalize, " ");
}
return textContent;
}
|
javascript
|
function(e, normalizeSpaces) {
normalizeSpaces = (typeof normalizeSpaces === 'undefined') ? true : normalizeSpaces;
var textContent = e.textContent.trim();
if (normalizeSpaces) {
return textContent.replace(this.REGEXPS.normalize, " ");
}
return textContent;
}
|
[
"function",
"(",
"e",
",",
"normalizeSpaces",
")",
"{",
"normalizeSpaces",
"=",
"(",
"typeof",
"normalizeSpaces",
"===",
"'undefined'",
")",
"?",
"true",
":",
"normalizeSpaces",
";",
"var",
"textContent",
"=",
"e",
".",
"textContent",
".",
"trim",
"(",
")",
";",
"if",
"(",
"normalizeSpaces",
")",
"{",
"return",
"textContent",
".",
"replace",
"(",
"this",
".",
"REGEXPS",
".",
"normalize",
",",
"\" \"",
")",
";",
"}",
"return",
"textContent",
";",
"}"
] |
Get the inner text of a node - cross browser compatibly.
This also strips out any excess whitespace to be found.
@param Element
@param Boolean normalizeSpaces (default: true)
@return string
|
[
"Get",
"the",
"inner",
"text",
"of",
"a",
"node",
"-",
"cross",
"browser",
"compatibly",
".",
"This",
"also",
"strips",
"out",
"any",
"excess",
"whitespace",
"to",
"be",
"found",
"."
] |
beb428b246cecba4630a3ca57b472f43c0933a43
|
https://github.com/laurent22/joplin/blob/beb428b246cecba4630a3ca57b472f43c0933a43/Clipper/joplin-webclipper/content_scripts/Readability.js#L1339-L1347
|
train
|
|
laurent22/joplin
|
Clipper/joplin-webclipper/content_scripts/Readability.js
|
function(node, tagName, maxDepth, filterFn) {
maxDepth = maxDepth || 3;
tagName = tagName.toUpperCase();
var depth = 0;
while (node.parentNode) {
if (maxDepth > 0 && depth > maxDepth)
return false;
if (node.parentNode.tagName === tagName && (!filterFn || filterFn(node.parentNode)))
return true;
node = node.parentNode;
depth++;
}
return false;
}
|
javascript
|
function(node, tagName, maxDepth, filterFn) {
maxDepth = maxDepth || 3;
tagName = tagName.toUpperCase();
var depth = 0;
while (node.parentNode) {
if (maxDepth > 0 && depth > maxDepth)
return false;
if (node.parentNode.tagName === tagName && (!filterFn || filterFn(node.parentNode)))
return true;
node = node.parentNode;
depth++;
}
return false;
}
|
[
"function",
"(",
"node",
",",
"tagName",
",",
"maxDepth",
",",
"filterFn",
")",
"{",
"maxDepth",
"=",
"maxDepth",
"||",
"3",
";",
"tagName",
"=",
"tagName",
".",
"toUpperCase",
"(",
")",
";",
"var",
"depth",
"=",
"0",
";",
"while",
"(",
"node",
".",
"parentNode",
")",
"{",
"if",
"(",
"maxDepth",
">",
"0",
"&&",
"depth",
">",
"maxDepth",
")",
"return",
"false",
";",
"if",
"(",
"node",
".",
"parentNode",
".",
"tagName",
"===",
"tagName",
"&&",
"(",
"!",
"filterFn",
"||",
"filterFn",
"(",
"node",
".",
"parentNode",
")",
")",
")",
"return",
"true",
";",
"node",
"=",
"node",
".",
"parentNode",
";",
"depth",
"++",
";",
"}",
"return",
"false",
";",
"}"
] |
Check if a given node has one of its ancestor tag name matching the
provided one.
@param HTMLElement node
@param String tagName
@param Number maxDepth
@param Function filterFn a filter to invoke to determine whether this node 'counts'
@return Boolean
|
[
"Check",
"if",
"a",
"given",
"node",
"has",
"one",
"of",
"its",
"ancestor",
"tag",
"name",
"matching",
"the",
"provided",
"one",
"."
] |
beb428b246cecba4630a3ca57b472f43c0933a43
|
https://github.com/laurent22/joplin/blob/beb428b246cecba4630a3ca57b472f43c0933a43/Clipper/joplin-webclipper/content_scripts/Readability.js#L1485-L1498
|
train
|
|
laurent22/joplin
|
Clipper/joplin-webclipper/content_scripts/Readability.js
|
function(table) {
var rows = 0;
var columns = 0;
var trs = table.getElementsByTagName("tr");
for (var i = 0; i < trs.length; i++) {
var rowspan = trs[i].getAttribute("rowspan") || 0;
if (rowspan) {
rowspan = parseInt(rowspan, 10);
}
rows += (rowspan || 1);
// Now look for column-related info
var columnsInThisRow = 0;
var cells = trs[i].getElementsByTagName("td");
for (var j = 0; j < cells.length; j++) {
var colspan = cells[j].getAttribute("colspan") || 0;
if (colspan) {
colspan = parseInt(colspan, 10);
}
columnsInThisRow += (colspan || 1);
}
columns = Math.max(columns, columnsInThisRow);
}
return {rows: rows, columns: columns};
}
|
javascript
|
function(table) {
var rows = 0;
var columns = 0;
var trs = table.getElementsByTagName("tr");
for (var i = 0; i < trs.length; i++) {
var rowspan = trs[i].getAttribute("rowspan") || 0;
if (rowspan) {
rowspan = parseInt(rowspan, 10);
}
rows += (rowspan || 1);
// Now look for column-related info
var columnsInThisRow = 0;
var cells = trs[i].getElementsByTagName("td");
for (var j = 0; j < cells.length; j++) {
var colspan = cells[j].getAttribute("colspan") || 0;
if (colspan) {
colspan = parseInt(colspan, 10);
}
columnsInThisRow += (colspan || 1);
}
columns = Math.max(columns, columnsInThisRow);
}
return {rows: rows, columns: columns};
}
|
[
"function",
"(",
"table",
")",
"{",
"var",
"rows",
"=",
"0",
";",
"var",
"columns",
"=",
"0",
";",
"var",
"trs",
"=",
"table",
".",
"getElementsByTagName",
"(",
"\"tr\"",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"trs",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"rowspan",
"=",
"trs",
"[",
"i",
"]",
".",
"getAttribute",
"(",
"\"rowspan\"",
")",
"||",
"0",
";",
"if",
"(",
"rowspan",
")",
"{",
"rowspan",
"=",
"parseInt",
"(",
"rowspan",
",",
"10",
")",
";",
"}",
"rows",
"+=",
"(",
"rowspan",
"||",
"1",
")",
";",
"var",
"columnsInThisRow",
"=",
"0",
";",
"var",
"cells",
"=",
"trs",
"[",
"i",
"]",
".",
"getElementsByTagName",
"(",
"\"td\"",
")",
";",
"for",
"(",
"var",
"j",
"=",
"0",
";",
"j",
"<",
"cells",
".",
"length",
";",
"j",
"++",
")",
"{",
"var",
"colspan",
"=",
"cells",
"[",
"j",
"]",
".",
"getAttribute",
"(",
"\"colspan\"",
")",
"||",
"0",
";",
"if",
"(",
"colspan",
")",
"{",
"colspan",
"=",
"parseInt",
"(",
"colspan",
",",
"10",
")",
";",
"}",
"columnsInThisRow",
"+=",
"(",
"colspan",
"||",
"1",
")",
";",
"}",
"columns",
"=",
"Math",
".",
"max",
"(",
"columns",
",",
"columnsInThisRow",
")",
";",
"}",
"return",
"{",
"rows",
":",
"rows",
",",
"columns",
":",
"columns",
"}",
";",
"}"
] |
Return an object indicating how many rows and columns this table has.
|
[
"Return",
"an",
"object",
"indicating",
"how",
"many",
"rows",
"and",
"columns",
"this",
"table",
"has",
"."
] |
beb428b246cecba4630a3ca57b472f43c0933a43
|
https://github.com/laurent22/joplin/blob/beb428b246cecba4630a3ca57b472f43c0933a43/Clipper/joplin-webclipper/content_scripts/Readability.js#L1503-L1527
|
train
|
|
laurent22/joplin
|
Clipper/joplin-webclipper/content_scripts/Readability.js
|
function(helperIsVisible) {
var nodes = this._getAllNodesWithTag(this._doc, ["p", "pre"]);
// Get <div> nodes which have <br> node(s) and append them into the `nodes` variable.
// Some articles' DOM structures might look like
// <div>
// Sentences<br>
// <br>
// Sentences<br>
// </div>
var brNodes = this._getAllNodesWithTag(this._doc, ["div > br"]);
if (brNodes.length) {
var set = new Set();
[].forEach.call(brNodes, function(node) {
set.add(node.parentNode);
});
nodes = [].concat.apply(Array.from(set), nodes);
}
// FIXME we should have a fallback for helperIsVisible, but this is
// problematic because of jsdom's elem.style handling - see
// https://github.com/mozilla/readability/pull/186 for context.
var score = 0;
// This is a little cheeky, we use the accumulator 'score' to decide what to return from
// this callback:
return this._someNode(nodes, function(node) {
if (helperIsVisible && !helperIsVisible(node))
return false;
var matchString = node.className + " " + node.id;
if (this.REGEXPS.unlikelyCandidates.test(matchString) &&
!this.REGEXPS.okMaybeItsACandidate.test(matchString)) {
return false;
}
if (node.matches && node.matches("li p")) {
return false;
}
var textContentLength = node.textContent.trim().length;
if (textContentLength < 140) {
return false;
}
score += Math.sqrt(textContentLength - 140);
if (score > 20) {
return true;
}
return false;
});
}
|
javascript
|
function(helperIsVisible) {
var nodes = this._getAllNodesWithTag(this._doc, ["p", "pre"]);
// Get <div> nodes which have <br> node(s) and append them into the `nodes` variable.
// Some articles' DOM structures might look like
// <div>
// Sentences<br>
// <br>
// Sentences<br>
// </div>
var brNodes = this._getAllNodesWithTag(this._doc, ["div > br"]);
if (brNodes.length) {
var set = new Set();
[].forEach.call(brNodes, function(node) {
set.add(node.parentNode);
});
nodes = [].concat.apply(Array.from(set), nodes);
}
// FIXME we should have a fallback for helperIsVisible, but this is
// problematic because of jsdom's elem.style handling - see
// https://github.com/mozilla/readability/pull/186 for context.
var score = 0;
// This is a little cheeky, we use the accumulator 'score' to decide what to return from
// this callback:
return this._someNode(nodes, function(node) {
if (helperIsVisible && !helperIsVisible(node))
return false;
var matchString = node.className + " " + node.id;
if (this.REGEXPS.unlikelyCandidates.test(matchString) &&
!this.REGEXPS.okMaybeItsACandidate.test(matchString)) {
return false;
}
if (node.matches && node.matches("li p")) {
return false;
}
var textContentLength = node.textContent.trim().length;
if (textContentLength < 140) {
return false;
}
score += Math.sqrt(textContentLength - 140);
if (score > 20) {
return true;
}
return false;
});
}
|
[
"function",
"(",
"helperIsVisible",
")",
"{",
"var",
"nodes",
"=",
"this",
".",
"_getAllNodesWithTag",
"(",
"this",
".",
"_doc",
",",
"[",
"\"p\"",
",",
"\"pre\"",
"]",
")",
";",
"var",
"brNodes",
"=",
"this",
".",
"_getAllNodesWithTag",
"(",
"this",
".",
"_doc",
",",
"[",
"\"div > br\"",
"]",
")",
";",
"if",
"(",
"brNodes",
".",
"length",
")",
"{",
"var",
"set",
"=",
"new",
"Set",
"(",
")",
";",
"[",
"]",
".",
"forEach",
".",
"call",
"(",
"brNodes",
",",
"function",
"(",
"node",
")",
"{",
"set",
".",
"add",
"(",
"node",
".",
"parentNode",
")",
";",
"}",
")",
";",
"nodes",
"=",
"[",
"]",
".",
"concat",
".",
"apply",
"(",
"Array",
".",
"from",
"(",
"set",
")",
",",
"nodes",
")",
";",
"}",
"var",
"score",
"=",
"0",
";",
"return",
"this",
".",
"_someNode",
"(",
"nodes",
",",
"function",
"(",
"node",
")",
"{",
"if",
"(",
"helperIsVisible",
"&&",
"!",
"helperIsVisible",
"(",
"node",
")",
")",
"return",
"false",
";",
"var",
"matchString",
"=",
"node",
".",
"className",
"+",
"\" \"",
"+",
"node",
".",
"id",
";",
"if",
"(",
"this",
".",
"REGEXPS",
".",
"unlikelyCandidates",
".",
"test",
"(",
"matchString",
")",
"&&",
"!",
"this",
".",
"REGEXPS",
".",
"okMaybeItsACandidate",
".",
"test",
"(",
"matchString",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"node",
".",
"matches",
"&&",
"node",
".",
"matches",
"(",
"\"li p\"",
")",
")",
"{",
"return",
"false",
";",
"}",
"var",
"textContentLength",
"=",
"node",
".",
"textContent",
".",
"trim",
"(",
")",
".",
"length",
";",
"if",
"(",
"textContentLength",
"<",
"140",
")",
"{",
"return",
"false",
";",
"}",
"score",
"+=",
"Math",
".",
"sqrt",
"(",
"textContentLength",
"-",
"140",
")",
";",
"if",
"(",
"score",
">",
"20",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}",
")",
";",
"}"
] |
Decides whether or not the document is reader-able without parsing the whole thing.
@return boolean Whether or not we suspect parse() will suceeed at returning an article object.
|
[
"Decides",
"whether",
"or",
"not",
"the",
"document",
"is",
"reader",
"-",
"able",
"without",
"parsing",
"the",
"whole",
"thing",
"."
] |
beb428b246cecba4630a3ca57b472f43c0933a43
|
https://github.com/laurent22/joplin/blob/beb428b246cecba4630a3ca57b472f43c0933a43/Clipper/joplin-webclipper/content_scripts/Readability.js#L1702-L1754
|
train
|
|
laurent22/joplin
|
Clipper/joplin-webclipper/content_scripts/Readability.js
|
function () {
// Avoid parsing too large documents, as per configuration option
if (this._maxElemsToParse > 0) {
var numTags = this._doc.getElementsByTagName("*").length;
if (numTags > this._maxElemsToParse) {
throw new Error("Aborting parsing document; " + numTags + " elements found");
}
}
if (typeof this._doc.documentElement.firstElementChild === "undefined") {
this._getNextNode = this._getNextNodeNoElementProperties;
}
// Remove script tags from the document.
this._removeScripts(this._doc);
this._prepDocument();
var metadata = this._getArticleMetadata();
this._articleTitle = metadata.title;
var articleContent = this._grabArticle();
if (!articleContent)
return null;
this.log("Grabbed: " + articleContent.innerHTML);
this._postProcessContent(articleContent);
// If we haven't found an excerpt in the article's metadata, use the article's
// first paragraph as the excerpt. This is used for displaying a preview of
// the article's content.
if (!metadata.excerpt) {
var paragraphs = articleContent.getElementsByTagName("p");
if (paragraphs.length > 0) {
metadata.excerpt = paragraphs[0].textContent.trim();
}
}
var textContent = articleContent.textContent;
return {
title: this._articleTitle,
byline: metadata.byline || this._articleByline,
dir: this._articleDir,
content: articleContent.innerHTML,
textContent: textContent,
length: textContent.length,
excerpt: metadata.excerpt,
};
}
|
javascript
|
function () {
// Avoid parsing too large documents, as per configuration option
if (this._maxElemsToParse > 0) {
var numTags = this._doc.getElementsByTagName("*").length;
if (numTags > this._maxElemsToParse) {
throw new Error("Aborting parsing document; " + numTags + " elements found");
}
}
if (typeof this._doc.documentElement.firstElementChild === "undefined") {
this._getNextNode = this._getNextNodeNoElementProperties;
}
// Remove script tags from the document.
this._removeScripts(this._doc);
this._prepDocument();
var metadata = this._getArticleMetadata();
this._articleTitle = metadata.title;
var articleContent = this._grabArticle();
if (!articleContent)
return null;
this.log("Grabbed: " + articleContent.innerHTML);
this._postProcessContent(articleContent);
// If we haven't found an excerpt in the article's metadata, use the article's
// first paragraph as the excerpt. This is used for displaying a preview of
// the article's content.
if (!metadata.excerpt) {
var paragraphs = articleContent.getElementsByTagName("p");
if (paragraphs.length > 0) {
metadata.excerpt = paragraphs[0].textContent.trim();
}
}
var textContent = articleContent.textContent;
return {
title: this._articleTitle,
byline: metadata.byline || this._articleByline,
dir: this._articleDir,
content: articleContent.innerHTML,
textContent: textContent,
length: textContent.length,
excerpt: metadata.excerpt,
};
}
|
[
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"_maxElemsToParse",
">",
"0",
")",
"{",
"var",
"numTags",
"=",
"this",
".",
"_doc",
".",
"getElementsByTagName",
"(",
"\"*\"",
")",
".",
"length",
";",
"if",
"(",
"numTags",
">",
"this",
".",
"_maxElemsToParse",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Aborting parsing document; \"",
"+",
"numTags",
"+",
"\" elements found\"",
")",
";",
"}",
"}",
"if",
"(",
"typeof",
"this",
".",
"_doc",
".",
"documentElement",
".",
"firstElementChild",
"===",
"\"undefined\"",
")",
"{",
"this",
".",
"_getNextNode",
"=",
"this",
".",
"_getNextNodeNoElementProperties",
";",
"}",
"this",
".",
"_removeScripts",
"(",
"this",
".",
"_doc",
")",
";",
"this",
".",
"_prepDocument",
"(",
")",
";",
"var",
"metadata",
"=",
"this",
".",
"_getArticleMetadata",
"(",
")",
";",
"this",
".",
"_articleTitle",
"=",
"metadata",
".",
"title",
";",
"var",
"articleContent",
"=",
"this",
".",
"_grabArticle",
"(",
")",
";",
"if",
"(",
"!",
"articleContent",
")",
"return",
"null",
";",
"this",
".",
"log",
"(",
"\"Grabbed: \"",
"+",
"articleContent",
".",
"innerHTML",
")",
";",
"this",
".",
"_postProcessContent",
"(",
"articleContent",
")",
";",
"if",
"(",
"!",
"metadata",
".",
"excerpt",
")",
"{",
"var",
"paragraphs",
"=",
"articleContent",
".",
"getElementsByTagName",
"(",
"\"p\"",
")",
";",
"if",
"(",
"paragraphs",
".",
"length",
">",
"0",
")",
"{",
"metadata",
".",
"excerpt",
"=",
"paragraphs",
"[",
"0",
"]",
".",
"textContent",
".",
"trim",
"(",
")",
";",
"}",
"}",
"var",
"textContent",
"=",
"articleContent",
".",
"textContent",
";",
"return",
"{",
"title",
":",
"this",
".",
"_articleTitle",
",",
"byline",
":",
"metadata",
".",
"byline",
"||",
"this",
".",
"_articleByline",
",",
"dir",
":",
"this",
".",
"_articleDir",
",",
"content",
":",
"articleContent",
".",
"innerHTML",
",",
"textContent",
":",
"textContent",
",",
"length",
":",
"textContent",
".",
"length",
",",
"excerpt",
":",
"metadata",
".",
"excerpt",
",",
"}",
";",
"}"
] |
Runs readability.
Workflow:
1. Prep the document by removing script tags, css, etc.
2. Build readability's DOM tree.
3. Grab the article content from the current dom tree.
4. Replace the current DOM tree with the new one.
5. Read peacefully.
@return void
|
[
"Runs",
"readability",
"."
] |
beb428b246cecba4630a3ca57b472f43c0933a43
|
https://github.com/laurent22/joplin/blob/beb428b246cecba4630a3ca57b472f43c0933a43/Clipper/joplin-webclipper/content_scripts/Readability.js#L1768-L1816
|
train
|
|
laurent22/joplin
|
ReactNativeClient/lib/file-api.js
|
basicDelta
|
async function basicDelta(path, getDirStatFn, options) {
const outputLimit = 50;
const itemIds = await options.allItemIdsHandler();
if (!Array.isArray(itemIds)) throw new Error('Delta API not supported - local IDs must be provided');
const context = basicDeltaContextFromOptions_(options);
let newContext = {
timestamp: context.timestamp,
filesAtTimestamp: context.filesAtTimestamp.slice(),
statsCache: context.statsCache,
statIdsCache: context.statIdsCache,
deletedItemsProcessed: context.deletedItemsProcessed,
};
// Stats are cached until all items have been processed (until hasMore is false)
if (newContext.statsCache === null) {
newContext.statsCache = await getDirStatFn(path);
newContext.statsCache.sort(function(a, b) {
return a.updated_time - b.updated_time;
});
newContext.statIdsCache = newContext.statsCache
.filter(item => BaseItem.isSystemPath(item.path))
.map(item => BaseItem.pathToId(item.path));
newContext.statIdsCache.sort(); // Items must be sorted to use binary search below
}
let output = [];
// Find out which files have been changed since the last time. Note that we keep
// both the timestamp of the most recent change, *and* the items that exactly match
// this timestamp. This to handle cases where an item is modified while this delta
// function is running. For example:
// t0: Item 1 is changed
// t0: Sync items - run delta function
// t0: While delta() is running, modify Item 2
// Since item 2 was modified within the same millisecond, it would be skipped in the
// next sync if we relied exclusively on a timestamp.
for (let i = 0; i < newContext.statsCache.length; i++) {
const stat = newContext.statsCache[i];
if (stat.isDir) continue;
if (stat.updated_time < context.timestamp) continue;
// Special case for items that exactly match the timestamp
if (stat.updated_time === context.timestamp) {
if (context.filesAtTimestamp.indexOf(stat.path) >= 0) continue;
}
if (stat.updated_time > newContext.timestamp) {
newContext.timestamp = stat.updated_time;
newContext.filesAtTimestamp = [];
}
newContext.filesAtTimestamp.push(stat.path);
output.push(stat);
if (output.length >= outputLimit) break;
}
if (!newContext.deletedItemsProcessed) {
// Find out which items have been deleted on the sync target by comparing the items
// we have to the items on the target.
// Note that when deleted items are processed it might result in the output having
// more items than outputLimit. This is acceptable since delete operations are cheap.
let deletedItems = [];
for (let i = 0; i < itemIds.length; i++) {
const itemId = itemIds[i];
if (ArrayUtils.binarySearch(newContext.statIdsCache, itemId) < 0) {
deletedItems.push({
path: BaseItem.systemPath(itemId),
isDeleted: true,
});
}
}
output = output.concat(deletedItems);
}
newContext.deletedItemsProcessed = true;
const hasMore = output.length >= outputLimit;
if (!hasMore) {
// Clear temporary info from context. It's especially important to remove deletedItemsProcessed
// so that they are processed again on the next sync.
newContext.statsCache = null;
newContext.statIdsCache = null;
delete newContext.deletedItemsProcessed;
}
return {
hasMore: hasMore,
context: newContext,
items: output,
};
}
|
javascript
|
async function basicDelta(path, getDirStatFn, options) {
const outputLimit = 50;
const itemIds = await options.allItemIdsHandler();
if (!Array.isArray(itemIds)) throw new Error('Delta API not supported - local IDs must be provided');
const context = basicDeltaContextFromOptions_(options);
let newContext = {
timestamp: context.timestamp,
filesAtTimestamp: context.filesAtTimestamp.slice(),
statsCache: context.statsCache,
statIdsCache: context.statIdsCache,
deletedItemsProcessed: context.deletedItemsProcessed,
};
// Stats are cached until all items have been processed (until hasMore is false)
if (newContext.statsCache === null) {
newContext.statsCache = await getDirStatFn(path);
newContext.statsCache.sort(function(a, b) {
return a.updated_time - b.updated_time;
});
newContext.statIdsCache = newContext.statsCache
.filter(item => BaseItem.isSystemPath(item.path))
.map(item => BaseItem.pathToId(item.path));
newContext.statIdsCache.sort(); // Items must be sorted to use binary search below
}
let output = [];
// Find out which files have been changed since the last time. Note that we keep
// both the timestamp of the most recent change, *and* the items that exactly match
// this timestamp. This to handle cases where an item is modified while this delta
// function is running. For example:
// t0: Item 1 is changed
// t0: Sync items - run delta function
// t0: While delta() is running, modify Item 2
// Since item 2 was modified within the same millisecond, it would be skipped in the
// next sync if we relied exclusively on a timestamp.
for (let i = 0; i < newContext.statsCache.length; i++) {
const stat = newContext.statsCache[i];
if (stat.isDir) continue;
if (stat.updated_time < context.timestamp) continue;
// Special case for items that exactly match the timestamp
if (stat.updated_time === context.timestamp) {
if (context.filesAtTimestamp.indexOf(stat.path) >= 0) continue;
}
if (stat.updated_time > newContext.timestamp) {
newContext.timestamp = stat.updated_time;
newContext.filesAtTimestamp = [];
}
newContext.filesAtTimestamp.push(stat.path);
output.push(stat);
if (output.length >= outputLimit) break;
}
if (!newContext.deletedItemsProcessed) {
// Find out which items have been deleted on the sync target by comparing the items
// we have to the items on the target.
// Note that when deleted items are processed it might result in the output having
// more items than outputLimit. This is acceptable since delete operations are cheap.
let deletedItems = [];
for (let i = 0; i < itemIds.length; i++) {
const itemId = itemIds[i];
if (ArrayUtils.binarySearch(newContext.statIdsCache, itemId) < 0) {
deletedItems.push({
path: BaseItem.systemPath(itemId),
isDeleted: true,
});
}
}
output = output.concat(deletedItems);
}
newContext.deletedItemsProcessed = true;
const hasMore = output.length >= outputLimit;
if (!hasMore) {
// Clear temporary info from context. It's especially important to remove deletedItemsProcessed
// so that they are processed again on the next sync.
newContext.statsCache = null;
newContext.statIdsCache = null;
delete newContext.deletedItemsProcessed;
}
return {
hasMore: hasMore,
context: newContext,
items: output,
};
}
|
[
"async",
"function",
"basicDelta",
"(",
"path",
",",
"getDirStatFn",
",",
"options",
")",
"{",
"const",
"outputLimit",
"=",
"50",
";",
"const",
"itemIds",
"=",
"await",
"options",
".",
"allItemIdsHandler",
"(",
")",
";",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"itemIds",
")",
")",
"throw",
"new",
"Error",
"(",
"'Delta API not supported - local IDs must be provided'",
")",
";",
"const",
"context",
"=",
"basicDeltaContextFromOptions_",
"(",
"options",
")",
";",
"let",
"newContext",
"=",
"{",
"timestamp",
":",
"context",
".",
"timestamp",
",",
"filesAtTimestamp",
":",
"context",
".",
"filesAtTimestamp",
".",
"slice",
"(",
")",
",",
"statsCache",
":",
"context",
".",
"statsCache",
",",
"statIdsCache",
":",
"context",
".",
"statIdsCache",
",",
"deletedItemsProcessed",
":",
"context",
".",
"deletedItemsProcessed",
",",
"}",
";",
"if",
"(",
"newContext",
".",
"statsCache",
"===",
"null",
")",
"{",
"newContext",
".",
"statsCache",
"=",
"await",
"getDirStatFn",
"(",
"path",
")",
";",
"newContext",
".",
"statsCache",
".",
"sort",
"(",
"function",
"(",
"a",
",",
"b",
")",
"{",
"return",
"a",
".",
"updated_time",
"-",
"b",
".",
"updated_time",
";",
"}",
")",
";",
"newContext",
".",
"statIdsCache",
"=",
"newContext",
".",
"statsCache",
".",
"filter",
"(",
"item",
"=>",
"BaseItem",
".",
"isSystemPath",
"(",
"item",
".",
"path",
")",
")",
".",
"map",
"(",
"item",
"=>",
"BaseItem",
".",
"pathToId",
"(",
"item",
".",
"path",
")",
")",
";",
"newContext",
".",
"statIdsCache",
".",
"sort",
"(",
")",
";",
"}",
"let",
"output",
"=",
"[",
"]",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"newContext",
".",
"statsCache",
".",
"length",
";",
"i",
"++",
")",
"{",
"const",
"stat",
"=",
"newContext",
".",
"statsCache",
"[",
"i",
"]",
";",
"if",
"(",
"stat",
".",
"isDir",
")",
"continue",
";",
"if",
"(",
"stat",
".",
"updated_time",
"<",
"context",
".",
"timestamp",
")",
"continue",
";",
"if",
"(",
"stat",
".",
"updated_time",
"===",
"context",
".",
"timestamp",
")",
"{",
"if",
"(",
"context",
".",
"filesAtTimestamp",
".",
"indexOf",
"(",
"stat",
".",
"path",
")",
">=",
"0",
")",
"continue",
";",
"}",
"if",
"(",
"stat",
".",
"updated_time",
">",
"newContext",
".",
"timestamp",
")",
"{",
"newContext",
".",
"timestamp",
"=",
"stat",
".",
"updated_time",
";",
"newContext",
".",
"filesAtTimestamp",
"=",
"[",
"]",
";",
"}",
"newContext",
".",
"filesAtTimestamp",
".",
"push",
"(",
"stat",
".",
"path",
")",
";",
"output",
".",
"push",
"(",
"stat",
")",
";",
"if",
"(",
"output",
".",
"length",
">=",
"outputLimit",
")",
"break",
";",
"}",
"if",
"(",
"!",
"newContext",
".",
"deletedItemsProcessed",
")",
"{",
"let",
"deletedItems",
"=",
"[",
"]",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"itemIds",
".",
"length",
";",
"i",
"++",
")",
"{",
"const",
"itemId",
"=",
"itemIds",
"[",
"i",
"]",
";",
"if",
"(",
"ArrayUtils",
".",
"binarySearch",
"(",
"newContext",
".",
"statIdsCache",
",",
"itemId",
")",
"<",
"0",
")",
"{",
"deletedItems",
".",
"push",
"(",
"{",
"path",
":",
"BaseItem",
".",
"systemPath",
"(",
"itemId",
")",
",",
"isDeleted",
":",
"true",
",",
"}",
")",
";",
"}",
"}",
"output",
"=",
"output",
".",
"concat",
"(",
"deletedItems",
")",
";",
"}",
"newContext",
".",
"deletedItemsProcessed",
"=",
"true",
";",
"const",
"hasMore",
"=",
"output",
".",
"length",
">=",
"outputLimit",
";",
"if",
"(",
"!",
"hasMore",
")",
"{",
"newContext",
".",
"statsCache",
"=",
"null",
";",
"newContext",
".",
"statIdsCache",
"=",
"null",
";",
"delete",
"newContext",
".",
"deletedItemsProcessed",
";",
"}",
"return",
"{",
"hasMore",
":",
"hasMore",
",",
"context",
":",
"newContext",
",",
"items",
":",
"output",
",",
"}",
";",
"}"
] |
This is the basic delta algorithm, which can be used in case the cloud service does not have a built-in delta API. OneDrive and Dropbox have one for example, but Nextcloud and obviously the file system do not.
|
[
"This",
"is",
"the",
"basic",
"delta",
"algorithm",
"which",
"can",
"be",
"used",
"in",
"case",
"the",
"cloud",
"service",
"does",
"not",
"have",
"a",
"built",
"-",
"in",
"delta",
"API",
".",
"OneDrive",
"and",
"Dropbox",
"have",
"one",
"for",
"example",
"but",
"Nextcloud",
"and",
"obviously",
"the",
"file",
"system",
"do",
"not",
"."
] |
beb428b246cecba4630a3ca57b472f43c0933a43
|
https://github.com/laurent22/joplin/blob/beb428b246cecba4630a3ca57b472f43c0933a43/ReactNativeClient/lib/file-api.js#L218-L316
|
train
|
BlackrockDigital/startbootstrap-sb-admin-2
|
vendor/chart.js/Chart.js
|
function(target) {
var setFn = function(value, key) {
target[key] = value;
};
for (var i = 1, ilen = arguments.length; i < ilen; ++i) {
helpers.each(arguments[i], setFn);
}
return target;
}
|
javascript
|
function(target) {
var setFn = function(value, key) {
target[key] = value;
};
for (var i = 1, ilen = arguments.length; i < ilen; ++i) {
helpers.each(arguments[i], setFn);
}
return target;
}
|
[
"function",
"(",
"target",
")",
"{",
"var",
"setFn",
"=",
"function",
"(",
"value",
",",
"key",
")",
"{",
"target",
"[",
"key",
"]",
"=",
"value",
";",
"}",
";",
"for",
"(",
"var",
"i",
"=",
"1",
",",
"ilen",
"=",
"arguments",
".",
"length",
";",
"i",
"<",
"ilen",
";",
"++",
"i",
")",
"{",
"helpers",
".",
"each",
"(",
"arguments",
"[",
"i",
"]",
",",
"setFn",
")",
";",
"}",
"return",
"target",
";",
"}"
] |
Applies the contents of two or more objects together into the first object.
@param {object} target - The target object in which all objects are merged into.
@param {object} arg1 - Object containing additional properties to merge in target.
@param {object} argN - Additional objects containing properties to merge in target.
@returns {object} The `target` object.
|
[
"Applies",
"the",
"contents",
"of",
"two",
"or",
"more",
"objects",
"together",
"into",
"the",
"first",
"object",
"."
] |
ddfaceb4a8e65a41f163e2fdc4eab49384b810a1
|
https://github.com/BlackrockDigital/startbootstrap-sb-admin-2/blob/ddfaceb4a8e65a41f163e2fdc4eab49384b810a1/vendor/chart.js/Chart.js#L1955-L1963
|
train
|
|
BlackrockDigital/startbootstrap-sb-admin-2
|
vendor/chart.js/Chart.js
|
function(point, area) {
var epsilon = 1e-6; // 1e-6 is margin in pixels for accumulated error.
return point.x > area.left - epsilon && point.x < area.right + epsilon &&
point.y > area.top - epsilon && point.y < area.bottom + epsilon;
}
|
javascript
|
function(point, area) {
var epsilon = 1e-6; // 1e-6 is margin in pixels for accumulated error.
return point.x > area.left - epsilon && point.x < area.right + epsilon &&
point.y > area.top - epsilon && point.y < area.bottom + epsilon;
}
|
[
"function",
"(",
"point",
",",
"area",
")",
"{",
"var",
"epsilon",
"=",
"1e-6",
";",
"return",
"point",
".",
"x",
">",
"area",
".",
"left",
"-",
"epsilon",
"&&",
"point",
".",
"x",
"<",
"area",
".",
"right",
"+",
"epsilon",
"&&",
"point",
".",
"y",
">",
"area",
".",
"top",
"-",
"epsilon",
"&&",
"point",
".",
"y",
"<",
"area",
".",
"bottom",
"+",
"epsilon",
";",
"}"
] |
Returns true if the point is inside the rectangle
@param {object} point - The point to test
@param {object} area - The rectangle
@returns {boolean}
@private
|
[
"Returns",
"true",
"if",
"the",
"point",
"is",
"inside",
"the",
"rectangle"
] |
ddfaceb4a8e65a41f163e2fdc4eab49384b810a1
|
https://github.com/BlackrockDigital/startbootstrap-sb-admin-2/blob/ddfaceb4a8e65a41f163e2fdc4eab49384b810a1/vendor/chart.js/Chart.js#L2458-L2463
|
train
|
|
BlackrockDigital/startbootstrap-sb-admin-2
|
vendor/chart.js/Chart.js
|
function(options) {
var globalDefaults = core_defaults.global;
var size = valueOrDefault(options.fontSize, globalDefaults.defaultFontSize);
var font = {
family: valueOrDefault(options.fontFamily, globalDefaults.defaultFontFamily),
lineHeight: helpers_core.options.toLineHeight(valueOrDefault(options.lineHeight, globalDefaults.defaultLineHeight), size),
size: size,
style: valueOrDefault(options.fontStyle, globalDefaults.defaultFontStyle),
weight: null,
string: ''
};
font.string = toFontString(font);
return font;
}
|
javascript
|
function(options) {
var globalDefaults = core_defaults.global;
var size = valueOrDefault(options.fontSize, globalDefaults.defaultFontSize);
var font = {
family: valueOrDefault(options.fontFamily, globalDefaults.defaultFontFamily),
lineHeight: helpers_core.options.toLineHeight(valueOrDefault(options.lineHeight, globalDefaults.defaultLineHeight), size),
size: size,
style: valueOrDefault(options.fontStyle, globalDefaults.defaultFontStyle),
weight: null,
string: ''
};
font.string = toFontString(font);
return font;
}
|
[
"function",
"(",
"options",
")",
"{",
"var",
"globalDefaults",
"=",
"core_defaults",
".",
"global",
";",
"var",
"size",
"=",
"valueOrDefault",
"(",
"options",
".",
"fontSize",
",",
"globalDefaults",
".",
"defaultFontSize",
")",
";",
"var",
"font",
"=",
"{",
"family",
":",
"valueOrDefault",
"(",
"options",
".",
"fontFamily",
",",
"globalDefaults",
".",
"defaultFontFamily",
")",
",",
"lineHeight",
":",
"helpers_core",
".",
"options",
".",
"toLineHeight",
"(",
"valueOrDefault",
"(",
"options",
".",
"lineHeight",
",",
"globalDefaults",
".",
"defaultLineHeight",
")",
",",
"size",
")",
",",
"size",
":",
"size",
",",
"style",
":",
"valueOrDefault",
"(",
"options",
".",
"fontStyle",
",",
"globalDefaults",
".",
"defaultFontStyle",
")",
",",
"weight",
":",
"null",
",",
"string",
":",
"''",
"}",
";",
"font",
".",
"string",
"=",
"toFontString",
"(",
"font",
")",
";",
"return",
"font",
";",
"}"
] |
Parses font options and returns the font object.
@param {object} options - A object that contains font options to be parsed.
@return {object} The font object.
@todo Support font.* options and renamed to toFont().
@private
|
[
"Parses",
"font",
"options",
"and",
"returns",
"the",
"font",
"object",
"."
] |
ddfaceb4a8e65a41f163e2fdc4eab49384b810a1
|
https://github.com/BlackrockDigital/startbootstrap-sb-admin-2/blob/ddfaceb4a8e65a41f163e2fdc4eab49384b810a1/vendor/chart.js/Chart.js#L2642-L2656
|
train
|
|
BlackrockDigital/startbootstrap-sb-admin-2
|
vendor/chart.js/Chart.js
|
function(inputs, context, index) {
var i, ilen, value;
for (i = 0, ilen = inputs.length; i < ilen; ++i) {
value = inputs[i];
if (value === undefined) {
continue;
}
if (context !== undefined && typeof value === 'function') {
value = value(context);
}
if (index !== undefined && helpers_core.isArray(value)) {
value = value[index];
}
if (value !== undefined) {
return value;
}
}
}
|
javascript
|
function(inputs, context, index) {
var i, ilen, value;
for (i = 0, ilen = inputs.length; i < ilen; ++i) {
value = inputs[i];
if (value === undefined) {
continue;
}
if (context !== undefined && typeof value === 'function') {
value = value(context);
}
if (index !== undefined && helpers_core.isArray(value)) {
value = value[index];
}
if (value !== undefined) {
return value;
}
}
}
|
[
"function",
"(",
"inputs",
",",
"context",
",",
"index",
")",
"{",
"var",
"i",
",",
"ilen",
",",
"value",
";",
"for",
"(",
"i",
"=",
"0",
",",
"ilen",
"=",
"inputs",
".",
"length",
";",
"i",
"<",
"ilen",
";",
"++",
"i",
")",
"{",
"value",
"=",
"inputs",
"[",
"i",
"]",
";",
"if",
"(",
"value",
"===",
"undefined",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"context",
"!==",
"undefined",
"&&",
"typeof",
"value",
"===",
"'function'",
")",
"{",
"value",
"=",
"value",
"(",
"context",
")",
";",
"}",
"if",
"(",
"index",
"!==",
"undefined",
"&&",
"helpers_core",
".",
"isArray",
"(",
"value",
")",
")",
"{",
"value",
"=",
"value",
"[",
"index",
"]",
";",
"}",
"if",
"(",
"value",
"!==",
"undefined",
")",
"{",
"return",
"value",
";",
"}",
"}",
"}"
] |
Evaluates the given `inputs` sequentially and returns the first defined value.
@param {Array} inputs - An array of values, falling back to the last value.
@param {object} [context] - If defined and the current value is a function, the value
is called with `context` as first argument and the result becomes the new input.
@param {number} [index] - If defined and the current value is an array, the value
at `index` become the new input.
@since 2.7.0
|
[
"Evaluates",
"the",
"given",
"inputs",
"sequentially",
"and",
"returns",
"the",
"first",
"defined",
"value",
"."
] |
ddfaceb4a8e65a41f163e2fdc4eab49384b810a1
|
https://github.com/BlackrockDigital/startbootstrap-sb-admin-2/blob/ddfaceb4a8e65a41f163e2fdc4eab49384b810a1/vendor/chart.js/Chart.js#L2667-L2685
|
train
|
|
BlackrockDigital/startbootstrap-sb-admin-2
|
vendor/chart.js/Chart.js
|
getRelativePosition
|
function getRelativePosition(e, chart) {
if (e.native) {
return {
x: e.x,
y: e.y
};
}
return helpers$1.getRelativePosition(e, chart);
}
|
javascript
|
function getRelativePosition(e, chart) {
if (e.native) {
return {
x: e.x,
y: e.y
};
}
return helpers$1.getRelativePosition(e, chart);
}
|
[
"function",
"getRelativePosition",
"(",
"e",
",",
"chart",
")",
"{",
"if",
"(",
"e",
".",
"native",
")",
"{",
"return",
"{",
"x",
":",
"e",
".",
"x",
",",
"y",
":",
"e",
".",
"y",
"}",
";",
"}",
"return",
"helpers$1",
".",
"getRelativePosition",
"(",
"e",
",",
"chart",
")",
";",
"}"
] |
Helper function to get relative position for an event
@param {Event|IEvent} event - The event to get the position for
@param {Chart} chart - The chart
@returns {object} the event position
|
[
"Helper",
"function",
"to",
"get",
"relative",
"position",
"for",
"an",
"event"
] |
ddfaceb4a8e65a41f163e2fdc4eab49384b810a1
|
https://github.com/BlackrockDigital/startbootstrap-sb-admin-2/blob/ddfaceb4a8e65a41f163e2fdc4eab49384b810a1/vendor/chart.js/Chart.js#L5835-L5844
|
train
|
BlackrockDigital/startbootstrap-sb-admin-2
|
vendor/chart.js/Chart.js
|
fitBox
|
function fitBox(box) {
var minBoxSize = helpers$1.findNextWhere(minBoxSizes, function(minBox) {
return minBox.box === box;
});
if (minBoxSize) {
if (minBoxSize.horizontal) {
var scaleMargin = {
left: Math.max(outerBoxSizes.left, maxPadding.left),
right: Math.max(outerBoxSizes.right, maxPadding.right),
top: 0,
bottom: 0
};
// Don't use min size here because of label rotation. When the labels are rotated, their rotation highly depends
// on the margin. Sometimes they need to increase in size slightly
box.update(box.fullWidth ? chartWidth : maxChartAreaWidth, chartHeight / 2, scaleMargin);
} else {
box.update(minBoxSize.width, maxChartAreaHeight);
}
}
}
|
javascript
|
function fitBox(box) {
var minBoxSize = helpers$1.findNextWhere(minBoxSizes, function(minBox) {
return minBox.box === box;
});
if (minBoxSize) {
if (minBoxSize.horizontal) {
var scaleMargin = {
left: Math.max(outerBoxSizes.left, maxPadding.left),
right: Math.max(outerBoxSizes.right, maxPadding.right),
top: 0,
bottom: 0
};
// Don't use min size here because of label rotation. When the labels are rotated, their rotation highly depends
// on the margin. Sometimes they need to increase in size slightly
box.update(box.fullWidth ? chartWidth : maxChartAreaWidth, chartHeight / 2, scaleMargin);
} else {
box.update(minBoxSize.width, maxChartAreaHeight);
}
}
}
|
[
"function",
"fitBox",
"(",
"box",
")",
"{",
"var",
"minBoxSize",
"=",
"helpers$1",
".",
"findNextWhere",
"(",
"minBoxSizes",
",",
"function",
"(",
"minBox",
")",
"{",
"return",
"minBox",
".",
"box",
"===",
"box",
";",
"}",
")",
";",
"if",
"(",
"minBoxSize",
")",
"{",
"if",
"(",
"minBoxSize",
".",
"horizontal",
")",
"{",
"var",
"scaleMargin",
"=",
"{",
"left",
":",
"Math",
".",
"max",
"(",
"outerBoxSizes",
".",
"left",
",",
"maxPadding",
".",
"left",
")",
",",
"right",
":",
"Math",
".",
"max",
"(",
"outerBoxSizes",
".",
"right",
",",
"maxPadding",
".",
"right",
")",
",",
"top",
":",
"0",
",",
"bottom",
":",
"0",
"}",
";",
"box",
".",
"update",
"(",
"box",
".",
"fullWidth",
"?",
"chartWidth",
":",
"maxChartAreaWidth",
",",
"chartHeight",
"/",
"2",
",",
"scaleMargin",
")",
";",
"}",
"else",
"{",
"box",
".",
"update",
"(",
"minBoxSize",
".",
"width",
",",
"maxChartAreaHeight",
")",
";",
"}",
"}",
"}"
] |
At this point, maxChartAreaHeight and maxChartAreaWidth are the size the chart area could be if the axes are drawn at their minimum sizes. Steps 5 & 6 Function to fit a box
|
[
"At",
"this",
"point",
"maxChartAreaHeight",
"and",
"maxChartAreaWidth",
"are",
"the",
"size",
"the",
"chart",
"area",
"could",
"be",
"if",
"the",
"axes",
"are",
"drawn",
"at",
"their",
"minimum",
"sizes",
".",
"Steps",
"5",
"&",
"6",
"Function",
"to",
"fit",
"a",
"box"
] |
ddfaceb4a8e65a41f163e2fdc4eab49384b810a1
|
https://github.com/BlackrockDigital/startbootstrap-sb-admin-2/blob/ddfaceb4a8e65a41f163e2fdc4eab49384b810a1/vendor/chart.js/Chart.js#L6392-L6413
|
train
|
BlackrockDigital/startbootstrap-sb-admin-2
|
vendor/chart.js/Chart.js
|
mergeConfig
|
function mergeConfig(/* config objects ... */) {
return helpers$1.merge({}, [].slice.call(arguments), {
merger: function(key, target, source, options) {
var tval = target[key] || {};
var sval = source[key];
if (key === 'scales') {
// scale config merging is complex. Add our own function here for that
target[key] = mergeScaleConfig(tval, sval);
} else if (key === 'scale') {
// used in polar area & radar charts since there is only one scale
target[key] = helpers$1.merge(tval, [core_scaleService.getScaleDefaults(sval.type), sval]);
} else {
helpers$1._merger(key, target, source, options);
}
}
});
}
|
javascript
|
function mergeConfig(/* config objects ... */) {
return helpers$1.merge({}, [].slice.call(arguments), {
merger: function(key, target, source, options) {
var tval = target[key] || {};
var sval = source[key];
if (key === 'scales') {
// scale config merging is complex. Add our own function here for that
target[key] = mergeScaleConfig(tval, sval);
} else if (key === 'scale') {
// used in polar area & radar charts since there is only one scale
target[key] = helpers$1.merge(tval, [core_scaleService.getScaleDefaults(sval.type), sval]);
} else {
helpers$1._merger(key, target, source, options);
}
}
});
}
|
[
"function",
"mergeConfig",
"(",
")",
"{",
"return",
"helpers$1",
".",
"merge",
"(",
"{",
"}",
",",
"[",
"]",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
",",
"{",
"merger",
":",
"function",
"(",
"key",
",",
"target",
",",
"source",
",",
"options",
")",
"{",
"var",
"tval",
"=",
"target",
"[",
"key",
"]",
"||",
"{",
"}",
";",
"var",
"sval",
"=",
"source",
"[",
"key",
"]",
";",
"if",
"(",
"key",
"===",
"'scales'",
")",
"{",
"target",
"[",
"key",
"]",
"=",
"mergeScaleConfig",
"(",
"tval",
",",
"sval",
")",
";",
"}",
"else",
"if",
"(",
"key",
"===",
"'scale'",
")",
"{",
"target",
"[",
"key",
"]",
"=",
"helpers$1",
".",
"merge",
"(",
"tval",
",",
"[",
"core_scaleService",
".",
"getScaleDefaults",
"(",
"sval",
".",
"type",
")",
",",
"sval",
"]",
")",
";",
"}",
"else",
"{",
"helpers$1",
".",
"_merger",
"(",
"key",
",",
"target",
",",
"source",
",",
"options",
")",
";",
"}",
"}",
"}",
")",
";",
"}"
] |
Recursively merge the given config objects as the root options by handling
default scale options for the `scales` and `scale` properties, then returns
a deep copy of the result, thus doesn't alter inputs.
|
[
"Recursively",
"merge",
"the",
"given",
"config",
"objects",
"as",
"the",
"root",
"options",
"by",
"handling",
"default",
"scale",
"options",
"for",
"the",
"scales",
"and",
"scale",
"properties",
"then",
"returns",
"a",
"deep",
"copy",
"of",
"the",
"result",
"thus",
"doesn",
"t",
"alter",
"inputs",
"."
] |
ddfaceb4a8e65a41f163e2fdc4eab49384b810a1
|
https://github.com/BlackrockDigital/startbootstrap-sb-admin-2/blob/ddfaceb4a8e65a41f163e2fdc4eab49384b810a1/vendor/chart.js/Chart.js#L8340-L8357
|
train
|
BlackrockDigital/startbootstrap-sb-admin-2
|
vendor/chart.js/Chart.js
|
function() {
var me = this;
helpers$1.each(me.data.datasets, function(dataset, datasetIndex) {
me.getDatasetMeta(datasetIndex).controller.reset();
}, me);
}
|
javascript
|
function() {
var me = this;
helpers$1.each(me.data.datasets, function(dataset, datasetIndex) {
me.getDatasetMeta(datasetIndex).controller.reset();
}, me);
}
|
[
"function",
"(",
")",
"{",
"var",
"me",
"=",
"this",
";",
"helpers$1",
".",
"each",
"(",
"me",
".",
"data",
".",
"datasets",
",",
"function",
"(",
"dataset",
",",
"datasetIndex",
")",
"{",
"me",
".",
"getDatasetMeta",
"(",
"datasetIndex",
")",
".",
"controller",
".",
"reset",
"(",
")",
";",
"}",
",",
"me",
")",
";",
"}"
] |
Reset the elements of all datasets
@private
|
[
"Reset",
"the",
"elements",
"of",
"all",
"datasets"
] |
ddfaceb4a8e65a41f163e2fdc4eab49384b810a1
|
https://github.com/BlackrockDigital/startbootstrap-sb-admin-2/blob/ddfaceb4a8e65a41f163e2fdc4eab49384b810a1/vendor/chart.js/Chart.js#L8686-L8691
|
train
|
|
BlackrockDigital/startbootstrap-sb-admin-2
|
vendor/chart.js/Chart.js
|
function(easingValue) {
var me = this;
var tooltip = me.tooltip;
var args = {
tooltip: tooltip,
easingValue: easingValue
};
if (core_plugins.notify(me, 'beforeTooltipDraw', [args]) === false) {
return;
}
tooltip.draw();
core_plugins.notify(me, 'afterTooltipDraw', [args]);
}
|
javascript
|
function(easingValue) {
var me = this;
var tooltip = me.tooltip;
var args = {
tooltip: tooltip,
easingValue: easingValue
};
if (core_plugins.notify(me, 'beforeTooltipDraw', [args]) === false) {
return;
}
tooltip.draw();
core_plugins.notify(me, 'afterTooltipDraw', [args]);
}
|
[
"function",
"(",
"easingValue",
")",
"{",
"var",
"me",
"=",
"this",
";",
"var",
"tooltip",
"=",
"me",
".",
"tooltip",
";",
"var",
"args",
"=",
"{",
"tooltip",
":",
"tooltip",
",",
"easingValue",
":",
"easingValue",
"}",
";",
"if",
"(",
"core_plugins",
".",
"notify",
"(",
"me",
",",
"'beforeTooltipDraw'",
",",
"[",
"args",
"]",
")",
"===",
"false",
")",
"{",
"return",
";",
"}",
"tooltip",
".",
"draw",
"(",
")",
";",
"core_plugins",
".",
"notify",
"(",
"me",
",",
"'afterTooltipDraw'",
",",
"[",
"args",
"]",
")",
";",
"}"
] |
Draws tooltip unless a plugin returns `false` to the `beforeTooltipDraw`
hook, in which case, plugins will not be called on `afterTooltipDraw`.
@private
|
[
"Draws",
"tooltip",
"unless",
"a",
"plugin",
"returns",
"false",
"to",
"the",
"beforeTooltipDraw",
"hook",
"in",
"which",
"case",
"plugins",
"will",
"not",
"be",
"called",
"on",
"afterTooltipDraw",
"."
] |
ddfaceb4a8e65a41f163e2fdc4eab49384b810a1
|
https://github.com/BlackrockDigital/startbootstrap-sb-admin-2/blob/ddfaceb4a8e65a41f163e2fdc4eab49384b810a1/vendor/chart.js/Chart.js#L8979-L8994
|
train
|
|
BlackrockDigital/startbootstrap-sb-admin-2
|
vendor/chart.js/Chart.js
|
getConstraintDimension
|
function getConstraintDimension(domNode, maxStyle, percentageProperty) {
var view = document.defaultView;
var parentNode = helpers$1._getParentNode(domNode);
var constrainedNode = view.getComputedStyle(domNode)[maxStyle];
var constrainedContainer = view.getComputedStyle(parentNode)[maxStyle];
var hasCNode = isConstrainedValue(constrainedNode);
var hasCContainer = isConstrainedValue(constrainedContainer);
var infinity = Number.POSITIVE_INFINITY;
if (hasCNode || hasCContainer) {
return Math.min(
hasCNode ? parseMaxStyle(constrainedNode, domNode, percentageProperty) : infinity,
hasCContainer ? parseMaxStyle(constrainedContainer, parentNode, percentageProperty) : infinity);
}
return 'none';
}
|
javascript
|
function getConstraintDimension(domNode, maxStyle, percentageProperty) {
var view = document.defaultView;
var parentNode = helpers$1._getParentNode(domNode);
var constrainedNode = view.getComputedStyle(domNode)[maxStyle];
var constrainedContainer = view.getComputedStyle(parentNode)[maxStyle];
var hasCNode = isConstrainedValue(constrainedNode);
var hasCContainer = isConstrainedValue(constrainedContainer);
var infinity = Number.POSITIVE_INFINITY;
if (hasCNode || hasCContainer) {
return Math.min(
hasCNode ? parseMaxStyle(constrainedNode, domNode, percentageProperty) : infinity,
hasCContainer ? parseMaxStyle(constrainedContainer, parentNode, percentageProperty) : infinity);
}
return 'none';
}
|
[
"function",
"getConstraintDimension",
"(",
"domNode",
",",
"maxStyle",
",",
"percentageProperty",
")",
"{",
"var",
"view",
"=",
"document",
".",
"defaultView",
";",
"var",
"parentNode",
"=",
"helpers$1",
".",
"_getParentNode",
"(",
"domNode",
")",
";",
"var",
"constrainedNode",
"=",
"view",
".",
"getComputedStyle",
"(",
"domNode",
")",
"[",
"maxStyle",
"]",
";",
"var",
"constrainedContainer",
"=",
"view",
".",
"getComputedStyle",
"(",
"parentNode",
")",
"[",
"maxStyle",
"]",
";",
"var",
"hasCNode",
"=",
"isConstrainedValue",
"(",
"constrainedNode",
")",
";",
"var",
"hasCContainer",
"=",
"isConstrainedValue",
"(",
"constrainedContainer",
")",
";",
"var",
"infinity",
"=",
"Number",
".",
"POSITIVE_INFINITY",
";",
"if",
"(",
"hasCNode",
"||",
"hasCContainer",
")",
"{",
"return",
"Math",
".",
"min",
"(",
"hasCNode",
"?",
"parseMaxStyle",
"(",
"constrainedNode",
",",
"domNode",
",",
"percentageProperty",
")",
":",
"infinity",
",",
"hasCContainer",
"?",
"parseMaxStyle",
"(",
"constrainedContainer",
",",
"parentNode",
",",
"percentageProperty",
")",
":",
"infinity",
")",
";",
"}",
"return",
"'none'",
";",
"}"
] |
Returns the max width or height of the given DOM node in a cross-browser compatible fashion
@param {HTMLElement} domNode - the node to check the constraint on
@param {string} maxStyle - the style that defines the maximum for the direction we are using ('max-width' / 'max-height')
@param {string} percentageProperty - property of parent to use when calculating width as a percentage
@see {@link https://www.nathanaeljones.com/blog/2013/reading-max-width-cross-browser}
|
[
"Returns",
"the",
"max",
"width",
"or",
"height",
"of",
"the",
"given",
"DOM",
"node",
"in",
"a",
"cross",
"-",
"browser",
"compatible",
"fashion"
] |
ddfaceb4a8e65a41f163e2fdc4eab49384b810a1
|
https://github.com/BlackrockDigital/startbootstrap-sb-admin-2/blob/ddfaceb4a8e65a41f163e2fdc4eab49384b810a1/vendor/chart.js/Chart.js#L9758-L9774
|
train
|
BlackrockDigital/startbootstrap-sb-admin-2
|
vendor/chart.js/Chart.js
|
generateTicks
|
function generateTicks(generationOptions, dataRange) {
var ticks = [];
// To get a "nice" value for the tick spacing, we will use the appropriately named
// "nice number" algorithm. See https://stackoverflow.com/questions/8506881/nice-label-algorithm-for-charts-with-minimum-ticks
// for details.
var MIN_SPACING = 1e-14;
var stepSize = generationOptions.stepSize;
var unit = stepSize || 1;
var maxNumSpaces = generationOptions.maxTicks - 1;
var min = generationOptions.min;
var max = generationOptions.max;
var precision = generationOptions.precision;
var rmin = dataRange.min;
var rmax = dataRange.max;
var spacing = helpers$1.niceNum((rmax - rmin) / maxNumSpaces / unit) * unit;
var factor, niceMin, niceMax, numSpaces;
// Beyond MIN_SPACING floating point numbers being to lose precision
// such that we can't do the math necessary to generate ticks
if (spacing < MIN_SPACING && isNullOrUndef(min) && isNullOrUndef(max)) {
return [rmin, rmax];
}
numSpaces = Math.ceil(rmax / spacing) - Math.floor(rmin / spacing);
if (numSpaces > maxNumSpaces) {
// If the calculated num of spaces exceeds maxNumSpaces, recalculate it
spacing = helpers$1.niceNum(numSpaces * spacing / maxNumSpaces / unit) * unit;
}
if (stepSize || isNullOrUndef(precision)) {
// If a precision is not specified, calculate factor based on spacing
factor = Math.pow(10, helpers$1._decimalPlaces(spacing));
} else {
// If the user specified a precision, round to that number of decimal places
factor = Math.pow(10, precision);
spacing = Math.ceil(spacing * factor) / factor;
}
niceMin = Math.floor(rmin / spacing) * spacing;
niceMax = Math.ceil(rmax / spacing) * spacing;
// If min, max and stepSize is set and they make an evenly spaced scale use it.
if (stepSize) {
// If very close to our whole number, use it.
if (!isNullOrUndef(min) && helpers$1.almostWhole(min / spacing, spacing / 1000)) {
niceMin = min;
}
if (!isNullOrUndef(max) && helpers$1.almostWhole(max / spacing, spacing / 1000)) {
niceMax = max;
}
}
numSpaces = (niceMax - niceMin) / spacing;
// If very close to our rounded value, use it.
if (helpers$1.almostEquals(numSpaces, Math.round(numSpaces), spacing / 1000)) {
numSpaces = Math.round(numSpaces);
} else {
numSpaces = Math.ceil(numSpaces);
}
niceMin = Math.round(niceMin * factor) / factor;
niceMax = Math.round(niceMax * factor) / factor;
ticks.push(isNullOrUndef(min) ? niceMin : min);
for (var j = 1; j < numSpaces; ++j) {
ticks.push(Math.round((niceMin + j * spacing) * factor) / factor);
}
ticks.push(isNullOrUndef(max) ? niceMax : max);
return ticks;
}
|
javascript
|
function generateTicks(generationOptions, dataRange) {
var ticks = [];
// To get a "nice" value for the tick spacing, we will use the appropriately named
// "nice number" algorithm. See https://stackoverflow.com/questions/8506881/nice-label-algorithm-for-charts-with-minimum-ticks
// for details.
var MIN_SPACING = 1e-14;
var stepSize = generationOptions.stepSize;
var unit = stepSize || 1;
var maxNumSpaces = generationOptions.maxTicks - 1;
var min = generationOptions.min;
var max = generationOptions.max;
var precision = generationOptions.precision;
var rmin = dataRange.min;
var rmax = dataRange.max;
var spacing = helpers$1.niceNum((rmax - rmin) / maxNumSpaces / unit) * unit;
var factor, niceMin, niceMax, numSpaces;
// Beyond MIN_SPACING floating point numbers being to lose precision
// such that we can't do the math necessary to generate ticks
if (spacing < MIN_SPACING && isNullOrUndef(min) && isNullOrUndef(max)) {
return [rmin, rmax];
}
numSpaces = Math.ceil(rmax / spacing) - Math.floor(rmin / spacing);
if (numSpaces > maxNumSpaces) {
// If the calculated num of spaces exceeds maxNumSpaces, recalculate it
spacing = helpers$1.niceNum(numSpaces * spacing / maxNumSpaces / unit) * unit;
}
if (stepSize || isNullOrUndef(precision)) {
// If a precision is not specified, calculate factor based on spacing
factor = Math.pow(10, helpers$1._decimalPlaces(spacing));
} else {
// If the user specified a precision, round to that number of decimal places
factor = Math.pow(10, precision);
spacing = Math.ceil(spacing * factor) / factor;
}
niceMin = Math.floor(rmin / spacing) * spacing;
niceMax = Math.ceil(rmax / spacing) * spacing;
// If min, max and stepSize is set and they make an evenly spaced scale use it.
if (stepSize) {
// If very close to our whole number, use it.
if (!isNullOrUndef(min) && helpers$1.almostWhole(min / spacing, spacing / 1000)) {
niceMin = min;
}
if (!isNullOrUndef(max) && helpers$1.almostWhole(max / spacing, spacing / 1000)) {
niceMax = max;
}
}
numSpaces = (niceMax - niceMin) / spacing;
// If very close to our rounded value, use it.
if (helpers$1.almostEquals(numSpaces, Math.round(numSpaces), spacing / 1000)) {
numSpaces = Math.round(numSpaces);
} else {
numSpaces = Math.ceil(numSpaces);
}
niceMin = Math.round(niceMin * factor) / factor;
niceMax = Math.round(niceMax * factor) / factor;
ticks.push(isNullOrUndef(min) ? niceMin : min);
for (var j = 1; j < numSpaces; ++j) {
ticks.push(Math.round((niceMin + j * spacing) * factor) / factor);
}
ticks.push(isNullOrUndef(max) ? niceMax : max);
return ticks;
}
|
[
"function",
"generateTicks",
"(",
"generationOptions",
",",
"dataRange",
")",
"{",
"var",
"ticks",
"=",
"[",
"]",
";",
"var",
"MIN_SPACING",
"=",
"1e-14",
";",
"var",
"stepSize",
"=",
"generationOptions",
".",
"stepSize",
";",
"var",
"unit",
"=",
"stepSize",
"||",
"1",
";",
"var",
"maxNumSpaces",
"=",
"generationOptions",
".",
"maxTicks",
"-",
"1",
";",
"var",
"min",
"=",
"generationOptions",
".",
"min",
";",
"var",
"max",
"=",
"generationOptions",
".",
"max",
";",
"var",
"precision",
"=",
"generationOptions",
".",
"precision",
";",
"var",
"rmin",
"=",
"dataRange",
".",
"min",
";",
"var",
"rmax",
"=",
"dataRange",
".",
"max",
";",
"var",
"spacing",
"=",
"helpers$1",
".",
"niceNum",
"(",
"(",
"rmax",
"-",
"rmin",
")",
"/",
"maxNumSpaces",
"/",
"unit",
")",
"*",
"unit",
";",
"var",
"factor",
",",
"niceMin",
",",
"niceMax",
",",
"numSpaces",
";",
"if",
"(",
"spacing",
"<",
"MIN_SPACING",
"&&",
"isNullOrUndef",
"(",
"min",
")",
"&&",
"isNullOrUndef",
"(",
"max",
")",
")",
"{",
"return",
"[",
"rmin",
",",
"rmax",
"]",
";",
"}",
"numSpaces",
"=",
"Math",
".",
"ceil",
"(",
"rmax",
"/",
"spacing",
")",
"-",
"Math",
".",
"floor",
"(",
"rmin",
"/",
"spacing",
")",
";",
"if",
"(",
"numSpaces",
">",
"maxNumSpaces",
")",
"{",
"spacing",
"=",
"helpers$1",
".",
"niceNum",
"(",
"numSpaces",
"*",
"spacing",
"/",
"maxNumSpaces",
"/",
"unit",
")",
"*",
"unit",
";",
"}",
"if",
"(",
"stepSize",
"||",
"isNullOrUndef",
"(",
"precision",
")",
")",
"{",
"factor",
"=",
"Math",
".",
"pow",
"(",
"10",
",",
"helpers$1",
".",
"_decimalPlaces",
"(",
"spacing",
")",
")",
";",
"}",
"else",
"{",
"factor",
"=",
"Math",
".",
"pow",
"(",
"10",
",",
"precision",
")",
";",
"spacing",
"=",
"Math",
".",
"ceil",
"(",
"spacing",
"*",
"factor",
")",
"/",
"factor",
";",
"}",
"niceMin",
"=",
"Math",
".",
"floor",
"(",
"rmin",
"/",
"spacing",
")",
"*",
"spacing",
";",
"niceMax",
"=",
"Math",
".",
"ceil",
"(",
"rmax",
"/",
"spacing",
")",
"*",
"spacing",
";",
"if",
"(",
"stepSize",
")",
"{",
"if",
"(",
"!",
"isNullOrUndef",
"(",
"min",
")",
"&&",
"helpers$1",
".",
"almostWhole",
"(",
"min",
"/",
"spacing",
",",
"spacing",
"/",
"1000",
")",
")",
"{",
"niceMin",
"=",
"min",
";",
"}",
"if",
"(",
"!",
"isNullOrUndef",
"(",
"max",
")",
"&&",
"helpers$1",
".",
"almostWhole",
"(",
"max",
"/",
"spacing",
",",
"spacing",
"/",
"1000",
")",
")",
"{",
"niceMax",
"=",
"max",
";",
"}",
"}",
"numSpaces",
"=",
"(",
"niceMax",
"-",
"niceMin",
")",
"/",
"spacing",
";",
"if",
"(",
"helpers$1",
".",
"almostEquals",
"(",
"numSpaces",
",",
"Math",
".",
"round",
"(",
"numSpaces",
")",
",",
"spacing",
"/",
"1000",
")",
")",
"{",
"numSpaces",
"=",
"Math",
".",
"round",
"(",
"numSpaces",
")",
";",
"}",
"else",
"{",
"numSpaces",
"=",
"Math",
".",
"ceil",
"(",
"numSpaces",
")",
";",
"}",
"niceMin",
"=",
"Math",
".",
"round",
"(",
"niceMin",
"*",
"factor",
")",
"/",
"factor",
";",
"niceMax",
"=",
"Math",
".",
"round",
"(",
"niceMax",
"*",
"factor",
")",
"/",
"factor",
";",
"ticks",
".",
"push",
"(",
"isNullOrUndef",
"(",
"min",
")",
"?",
"niceMin",
":",
"min",
")",
";",
"for",
"(",
"var",
"j",
"=",
"1",
";",
"j",
"<",
"numSpaces",
";",
"++",
"j",
")",
"{",
"ticks",
".",
"push",
"(",
"Math",
".",
"round",
"(",
"(",
"niceMin",
"+",
"j",
"*",
"spacing",
")",
"*",
"factor",
")",
"/",
"factor",
")",
";",
"}",
"ticks",
".",
"push",
"(",
"isNullOrUndef",
"(",
"max",
")",
"?",
"niceMax",
":",
"max",
")",
";",
"return",
"ticks",
";",
"}"
] |
Generate a set of linear ticks
@param generationOptions the options used to generate the ticks
@param dataRange the range of the data
@returns {number[]} array of tick values
|
[
"Generate",
"a",
"set",
"of",
"linear",
"ticks"
] |
ddfaceb4a8e65a41f163e2fdc4eab49384b810a1
|
https://github.com/BlackrockDigital/startbootstrap-sb-admin-2/blob/ddfaceb4a8e65a41f163e2fdc4eab49384b810a1/vendor/chart.js/Chart.js#L11268-L11338
|
train
|
BlackrockDigital/startbootstrap-sb-admin-2
|
vendor/chart.js/Chart.js
|
function(value) {
var exp = Math.floor(helpers$1.log10(value));
var significand = Math.floor(value / Math.pow(10, exp));
return significand * Math.pow(10, exp);
}
|
javascript
|
function(value) {
var exp = Math.floor(helpers$1.log10(value));
var significand = Math.floor(value / Math.pow(10, exp));
return significand * Math.pow(10, exp);
}
|
[
"function",
"(",
"value",
")",
"{",
"var",
"exp",
"=",
"Math",
".",
"floor",
"(",
"helpers$1",
".",
"log10",
"(",
"value",
")",
")",
";",
"var",
"significand",
"=",
"Math",
".",
"floor",
"(",
"value",
"/",
"Math",
".",
"pow",
"(",
"10",
",",
"exp",
")",
")",
";",
"return",
"significand",
"*",
"Math",
".",
"pow",
"(",
"10",
",",
"exp",
")",
";",
"}"
] |
Returns the value of the first tick.
@param {number} value - The minimum not zero value.
@return {number} The first tick value.
@private
|
[
"Returns",
"the",
"value",
"of",
"the",
"first",
"tick",
"."
] |
ddfaceb4a8e65a41f163e2fdc4eab49384b810a1
|
https://github.com/BlackrockDigital/startbootstrap-sb-admin-2/blob/ddfaceb4a8e65a41f163e2fdc4eab49384b810a1/vendor/chart.js/Chart.js#L11931-L11936
|
train
|
|
BlackrockDigital/startbootstrap-sb-admin-2
|
vendor/fontawesome-free/js/fontawesome.js
|
bindInternal4
|
function bindInternal4(func, thisContext) {
return function (a, b, c, d) {
return func.call(thisContext, a, b, c, d);
};
}
|
javascript
|
function bindInternal4(func, thisContext) {
return function (a, b, c, d) {
return func.call(thisContext, a, b, c, d);
};
}
|
[
"function",
"bindInternal4",
"(",
"func",
",",
"thisContext",
")",
"{",
"return",
"function",
"(",
"a",
",",
"b",
",",
"c",
",",
"d",
")",
"{",
"return",
"func",
".",
"call",
"(",
"thisContext",
",",
"a",
",",
"b",
",",
"c",
",",
"d",
")",
";",
"}",
";",
"}"
] |
Internal helper to bind a function known to have 4 arguments
to a given context.
|
[
"Internal",
"helper",
"to",
"bind",
"a",
"function",
"known",
"to",
"have",
"4",
"arguments",
"to",
"a",
"given",
"context",
"."
] |
ddfaceb4a8e65a41f163e2fdc4eab49384b810a1
|
https://github.com/BlackrockDigital/startbootstrap-sb-admin-2/blob/ddfaceb4a8e65a41f163e2fdc4eab49384b810a1/vendor/fontawesome-free/js/fontawesome.js#L1095-L1099
|
train
|
parcel-bundler/parcel
|
packages/core/parcel-bundler/src/scope-hoisting/mangler.js
|
mangleScope
|
function mangleScope(scope) {
let newNames = new Set();
// Sort bindings so that more frequently referenced bindings get shorter names.
let sortedBindings = Object.keys(scope.bindings).sort(
(a, b) =>
scope.bindings[b].referencePaths.length -
scope.bindings[a].referencePaths.length
);
for (let oldName of sortedBindings) {
let i = 0;
let newName = '';
do {
newName = getIdentifier(i++);
} while (
newNames.has(newName) ||
!canRename(scope, scope.bindings[oldName], newName)
);
rename(scope, oldName, newName);
newNames.add(newName);
}
}
|
javascript
|
function mangleScope(scope) {
let newNames = new Set();
// Sort bindings so that more frequently referenced bindings get shorter names.
let sortedBindings = Object.keys(scope.bindings).sort(
(a, b) =>
scope.bindings[b].referencePaths.length -
scope.bindings[a].referencePaths.length
);
for (let oldName of sortedBindings) {
let i = 0;
let newName = '';
do {
newName = getIdentifier(i++);
} while (
newNames.has(newName) ||
!canRename(scope, scope.bindings[oldName], newName)
);
rename(scope, oldName, newName);
newNames.add(newName);
}
}
|
[
"function",
"mangleScope",
"(",
"scope",
")",
"{",
"let",
"newNames",
"=",
"new",
"Set",
"(",
")",
";",
"let",
"sortedBindings",
"=",
"Object",
".",
"keys",
"(",
"scope",
".",
"bindings",
")",
".",
"sort",
"(",
"(",
"a",
",",
"b",
")",
"=>",
"scope",
".",
"bindings",
"[",
"b",
"]",
".",
"referencePaths",
".",
"length",
"-",
"scope",
".",
"bindings",
"[",
"a",
"]",
".",
"referencePaths",
".",
"length",
")",
";",
"for",
"(",
"let",
"oldName",
"of",
"sortedBindings",
")",
"{",
"let",
"i",
"=",
"0",
";",
"let",
"newName",
"=",
"''",
";",
"do",
"{",
"newName",
"=",
"getIdentifier",
"(",
"i",
"++",
")",
";",
"}",
"while",
"(",
"newNames",
".",
"has",
"(",
"newName",
")",
"||",
"!",
"canRename",
"(",
"scope",
",",
"scope",
".",
"bindings",
"[",
"oldName",
"]",
",",
"newName",
")",
")",
";",
"rename",
"(",
"scope",
",",
"oldName",
",",
"newName",
")",
";",
"newNames",
".",
"add",
"(",
"newName",
")",
";",
"}",
"}"
] |
This is a very specialized mangler designer to mangle only names in the top-level scope.
Mangling of names in other scopes happens at a file level inside workers, but we can't
mangle the top-level scope until scope hoisting is complete in the packager.
Based on code from babel-minify!
https://github.com/babel/minify/blob/master/packages/babel-plugin-minify-mangle-names/src/charset.js
|
[
"This",
"is",
"a",
"very",
"specialized",
"mangler",
"designer",
"to",
"mangle",
"only",
"names",
"in",
"the",
"top",
"-",
"level",
"scope",
".",
"Mangling",
"of",
"names",
"in",
"other",
"scopes",
"happens",
"at",
"a",
"file",
"level",
"inside",
"workers",
"but",
"we",
"can",
"t",
"mangle",
"the",
"top",
"-",
"level",
"scope",
"until",
"scope",
"hoisting",
"is",
"complete",
"in",
"the",
"packager",
"."
] |
84b308511f87d4b69da62bcd352f0ff2f7bd4f1b
|
https://github.com/parcel-bundler/parcel/blob/84b308511f87d4b69da62bcd352f0ff2f7bd4f1b/packages/core/parcel-bundler/src/scope-hoisting/mangler.js#L16-L40
|
train
|
parcel-bundler/parcel
|
packages/core/parcel-bundler/src/assets/StylusAsset.js
|
mergeBlocks
|
function mergeBlocks(blocks) {
let finalBlock;
for (const block of blocks) {
if (!finalBlock) finalBlock = block;
else {
block.nodes.forEach(node => finalBlock.push(node));
}
}
return finalBlock;
}
|
javascript
|
function mergeBlocks(blocks) {
let finalBlock;
for (const block of blocks) {
if (!finalBlock) finalBlock = block;
else {
block.nodes.forEach(node => finalBlock.push(node));
}
}
return finalBlock;
}
|
[
"function",
"mergeBlocks",
"(",
"blocks",
")",
"{",
"let",
"finalBlock",
";",
"for",
"(",
"const",
"block",
"of",
"blocks",
")",
"{",
"if",
"(",
"!",
"finalBlock",
")",
"finalBlock",
"=",
"block",
";",
"else",
"{",
"block",
".",
"nodes",
".",
"forEach",
"(",
"node",
"=>",
"finalBlock",
".",
"push",
"(",
"node",
")",
")",
";",
"}",
"}",
"return",
"finalBlock",
";",
"}"
] |
Puts the content of all given node blocks into the first one, essentially merging them.
|
[
"Puts",
"the",
"content",
"of",
"all",
"given",
"node",
"blocks",
"into",
"the",
"first",
"one",
"essentially",
"merging",
"them",
"."
] |
84b308511f87d4b69da62bcd352f0ff2f7bd4f1b
|
https://github.com/parcel-bundler/parcel/blob/84b308511f87d4b69da62bcd352f0ff2f7bd4f1b/packages/core/parcel-bundler/src/assets/StylusAsset.js#L217-L226
|
train
|
parcel-bundler/parcel
|
packages/core/parcel-bundler/src/visitors/env.js
|
morph
|
function morph(object, newProperties) {
for (let key in object) {
delete object[key];
}
for (let key in newProperties) {
object[key] = newProperties[key];
}
}
|
javascript
|
function morph(object, newProperties) {
for (let key in object) {
delete object[key];
}
for (let key in newProperties) {
object[key] = newProperties[key];
}
}
|
[
"function",
"morph",
"(",
"object",
",",
"newProperties",
")",
"{",
"for",
"(",
"let",
"key",
"in",
"object",
")",
"{",
"delete",
"object",
"[",
"key",
"]",
";",
"}",
"for",
"(",
"let",
"key",
"in",
"newProperties",
")",
"{",
"object",
"[",
"key",
"]",
"=",
"newProperties",
"[",
"key",
"]",
";",
"}",
"}"
] |
replace object properties
|
[
"replace",
"object",
"properties"
] |
84b308511f87d4b69da62bcd352f0ff2f7bd4f1b
|
https://github.com/parcel-bundler/parcel/blob/84b308511f87d4b69da62bcd352f0ff2f7bd4f1b/packages/core/parcel-bundler/src/visitors/env.js#L22-L30
|
train
|
parcel-bundler/parcel
|
packages/core/parcel-bundler/src/transforms/babel/flow.js
|
getFlowConfig
|
function getFlowConfig(asset) {
if (/^(\/{2}|\/\*+) *@flow/.test(asset.contents.substring(0, 20))) {
return {
internal: true,
babelVersion: 7,
config: {
plugins: [[require('@babel/plugin-transform-flow-strip-types')]]
}
};
}
return null;
}
|
javascript
|
function getFlowConfig(asset) {
if (/^(\/{2}|\/\*+) *@flow/.test(asset.contents.substring(0, 20))) {
return {
internal: true,
babelVersion: 7,
config: {
plugins: [[require('@babel/plugin-transform-flow-strip-types')]]
}
};
}
return null;
}
|
[
"function",
"getFlowConfig",
"(",
"asset",
")",
"{",
"if",
"(",
"/",
"^(\\/{2}|\\/\\*+) *@flow",
"/",
".",
"test",
"(",
"asset",
".",
"contents",
".",
"substring",
"(",
"0",
",",
"20",
")",
")",
")",
"{",
"return",
"{",
"internal",
":",
"true",
",",
"babelVersion",
":",
"7",
",",
"config",
":",
"{",
"plugins",
":",
"[",
"[",
"require",
"(",
"'@babel/plugin-transform-flow-strip-types'",
")",
"]",
"]",
"}",
"}",
";",
"}",
"return",
"null",
";",
"}"
] |
Generates a babel config for stripping away Flow types.
|
[
"Generates",
"a",
"babel",
"config",
"for",
"stripping",
"away",
"Flow",
"types",
"."
] |
84b308511f87d4b69da62bcd352f0ff2f7bd4f1b
|
https://github.com/parcel-bundler/parcel/blob/84b308511f87d4b69da62bcd352f0ff2f7bd4f1b/packages/core/parcel-bundler/src/transforms/babel/flow.js#L4-L16
|
train
|
parcel-bundler/parcel
|
packages/core/parcel-bundler/src/utils/syncPromise.js
|
syncPromise
|
function syncPromise(promise) {
let isDone = false;
let res, err;
promise.then(
value => {
res = value;
isDone = true;
},
error => {
err = error;
isDone = true;
}
);
deasync.loopWhile(() => !isDone);
if (err) {
throw err;
}
return res;
}
|
javascript
|
function syncPromise(promise) {
let isDone = false;
let res, err;
promise.then(
value => {
res = value;
isDone = true;
},
error => {
err = error;
isDone = true;
}
);
deasync.loopWhile(() => !isDone);
if (err) {
throw err;
}
return res;
}
|
[
"function",
"syncPromise",
"(",
"promise",
")",
"{",
"let",
"isDone",
"=",
"false",
";",
"let",
"res",
",",
"err",
";",
"promise",
".",
"then",
"(",
"value",
"=>",
"{",
"res",
"=",
"value",
";",
"isDone",
"=",
"true",
";",
"}",
",",
"error",
"=>",
"{",
"err",
"=",
"error",
";",
"isDone",
"=",
"true",
";",
"}",
")",
";",
"deasync",
".",
"loopWhile",
"(",
"(",
")",
"=>",
"!",
"isDone",
")",
";",
"if",
"(",
"err",
")",
"{",
"throw",
"err",
";",
"}",
"return",
"res",
";",
"}"
] |
Synchronously waits for a promise to return by
yielding to the node event loop as needed.
|
[
"Synchronously",
"waits",
"for",
"a",
"promise",
"to",
"return",
"by",
"yielding",
"to",
"the",
"node",
"event",
"loop",
"as",
"needed",
"."
] |
84b308511f87d4b69da62bcd352f0ff2f7bd4f1b
|
https://github.com/parcel-bundler/parcel/blob/84b308511f87d4b69da62bcd352f0ff2f7bd4f1b/packages/core/parcel-bundler/src/utils/syncPromise.js#L7-L29
|
train
|
parcel-bundler/parcel
|
packages/core/parcel-bundler/src/scope-hoisting/shake.js
|
treeShake
|
function treeShake(scope) {
// Keep passing over all bindings in the scope until we don't remove any.
// This handles cases where we remove one binding which had a reference to
// another one. That one will get removed in the next pass if it is now unreferenced.
let removed;
do {
removed = false;
// Recrawl to get all bindings.
scope.crawl();
Object.keys(scope.bindings).forEach(name => {
let binding = getUnusedBinding(scope.path, name);
// If it is not safe to remove the binding don't touch it.
if (!binding) {
return;
}
// Remove the binding and all references to it.
binding.path.remove();
binding.referencePaths.concat(binding.constantViolations).forEach(remove);
scope.removeBinding(name);
removed = true;
});
} while (removed);
}
|
javascript
|
function treeShake(scope) {
// Keep passing over all bindings in the scope until we don't remove any.
// This handles cases where we remove one binding which had a reference to
// another one. That one will get removed in the next pass if it is now unreferenced.
let removed;
do {
removed = false;
// Recrawl to get all bindings.
scope.crawl();
Object.keys(scope.bindings).forEach(name => {
let binding = getUnusedBinding(scope.path, name);
// If it is not safe to remove the binding don't touch it.
if (!binding) {
return;
}
// Remove the binding and all references to it.
binding.path.remove();
binding.referencePaths.concat(binding.constantViolations).forEach(remove);
scope.removeBinding(name);
removed = true;
});
} while (removed);
}
|
[
"function",
"treeShake",
"(",
"scope",
")",
"{",
"let",
"removed",
";",
"do",
"{",
"removed",
"=",
"false",
";",
"scope",
".",
"crawl",
"(",
")",
";",
"Object",
".",
"keys",
"(",
"scope",
".",
"bindings",
")",
".",
"forEach",
"(",
"name",
"=>",
"{",
"let",
"binding",
"=",
"getUnusedBinding",
"(",
"scope",
".",
"path",
",",
"name",
")",
";",
"if",
"(",
"!",
"binding",
")",
"{",
"return",
";",
"}",
"binding",
".",
"path",
".",
"remove",
"(",
")",
";",
"binding",
".",
"referencePaths",
".",
"concat",
"(",
"binding",
".",
"constantViolations",
")",
".",
"forEach",
"(",
"remove",
")",
";",
"scope",
".",
"removeBinding",
"(",
"name",
")",
";",
"removed",
"=",
"true",
";",
"}",
")",
";",
"}",
"while",
"(",
"removed",
")",
";",
"}"
] |
This is a small small implementation of dead code removal specialized to handle
removing unused exports. All other dead code removal happens in workers on each
individual file by babel-minify.
|
[
"This",
"is",
"a",
"small",
"small",
"implementation",
"of",
"dead",
"code",
"removal",
"specialized",
"to",
"handle",
"removing",
"unused",
"exports",
".",
"All",
"other",
"dead",
"code",
"removal",
"happens",
"in",
"workers",
"on",
"each",
"individual",
"file",
"by",
"babel",
"-",
"minify",
"."
] |
84b308511f87d4b69da62bcd352f0ff2f7bd4f1b
|
https://github.com/parcel-bundler/parcel/blob/84b308511f87d4b69da62bcd352f0ff2f7bd4f1b/packages/core/parcel-bundler/src/scope-hoisting/shake.js#L8-L34
|
train
|
parcel-bundler/parcel
|
packages/core/parcel-bundler/src/scope-hoisting/shake.js
|
getUnusedBinding
|
function getUnusedBinding(path, name) {
let binding = path.scope.getBinding(name);
if (!binding) {
return null;
}
let pure = isPure(binding);
if (!binding.referenced && pure) {
return binding;
}
// Is there any references which aren't simple assignments?
let bailout = binding.referencePaths.some(
path => !isExportAssignment(path) && !isUnusedWildcard(path)
);
if (!bailout && pure) {
return binding;
}
return null;
}
|
javascript
|
function getUnusedBinding(path, name) {
let binding = path.scope.getBinding(name);
if (!binding) {
return null;
}
let pure = isPure(binding);
if (!binding.referenced && pure) {
return binding;
}
// Is there any references which aren't simple assignments?
let bailout = binding.referencePaths.some(
path => !isExportAssignment(path) && !isUnusedWildcard(path)
);
if (!bailout && pure) {
return binding;
}
return null;
}
|
[
"function",
"getUnusedBinding",
"(",
"path",
",",
"name",
")",
"{",
"let",
"binding",
"=",
"path",
".",
"scope",
".",
"getBinding",
"(",
"name",
")",
";",
"if",
"(",
"!",
"binding",
")",
"{",
"return",
"null",
";",
"}",
"let",
"pure",
"=",
"isPure",
"(",
"binding",
")",
";",
"if",
"(",
"!",
"binding",
".",
"referenced",
"&&",
"pure",
")",
"{",
"return",
"binding",
";",
"}",
"let",
"bailout",
"=",
"binding",
".",
"referencePaths",
".",
"some",
"(",
"path",
"=>",
"!",
"isExportAssignment",
"(",
"path",
")",
"&&",
"!",
"isUnusedWildcard",
"(",
"path",
")",
")",
";",
"if",
"(",
"!",
"bailout",
"&&",
"pure",
")",
"{",
"return",
"binding",
";",
"}",
"return",
"null",
";",
"}"
] |
Check if a binding is safe to remove and returns it if it is.
|
[
"Check",
"if",
"a",
"binding",
"is",
"safe",
"to",
"remove",
"and",
"returns",
"it",
"if",
"it",
"is",
"."
] |
84b308511f87d4b69da62bcd352f0ff2f7bd4f1b
|
https://github.com/parcel-bundler/parcel/blob/84b308511f87d4b69da62bcd352f0ff2f7bd4f1b/packages/core/parcel-bundler/src/scope-hoisting/shake.js#L39-L60
|
train
|
parcel-bundler/parcel
|
packages/core/logger/src/Logger.js
|
pad
|
function pad(text, length, align = 'left') {
let pad = ' '.repeat(length - stringWidth(text));
if (align === 'right') {
return pad + text;
}
return text + pad;
}
|
javascript
|
function pad(text, length, align = 'left') {
let pad = ' '.repeat(length - stringWidth(text));
if (align === 'right') {
return pad + text;
}
return text + pad;
}
|
[
"function",
"pad",
"(",
"text",
",",
"length",
",",
"align",
"=",
"'left'",
")",
"{",
"let",
"pad",
"=",
"' '",
".",
"repeat",
"(",
"length",
"-",
"stringWidth",
"(",
"text",
")",
")",
";",
"if",
"(",
"align",
"===",
"'right'",
")",
"{",
"return",
"pad",
"+",
"text",
";",
"}",
"return",
"text",
"+",
"pad",
";",
"}"
] |
Pad a string with spaces on either side
|
[
"Pad",
"a",
"string",
"with",
"spaces",
"on",
"either",
"side"
] |
84b308511f87d4b69da62bcd352f0ff2f7bd4f1b
|
https://github.com/parcel-bundler/parcel/blob/84b308511f87d4b69da62bcd352f0ff2f7bd4f1b/packages/core/logger/src/Logger.js#L213-L220
|
train
|
parcel-bundler/parcel
|
packages/core/parcel-bundler/src/assets/SASSAsset.js
|
normalizeError
|
function normalizeError(err) {
let message = 'Unknown error';
if (err) {
if (err instanceof Error) {
return err;
}
message = err.stack || err.message || err;
}
return new Error(message);
}
|
javascript
|
function normalizeError(err) {
let message = 'Unknown error';
if (err) {
if (err instanceof Error) {
return err;
}
message = err.stack || err.message || err;
}
return new Error(message);
}
|
[
"function",
"normalizeError",
"(",
"err",
")",
"{",
"let",
"message",
"=",
"'Unknown error'",
";",
"if",
"(",
"err",
")",
"{",
"if",
"(",
"err",
"instanceof",
"Error",
")",
"{",
"return",
"err",
";",
"}",
"message",
"=",
"err",
".",
"stack",
"||",
"err",
".",
"message",
"||",
"err",
";",
"}",
"return",
"new",
"Error",
"(",
"message",
")",
";",
"}"
] |
Ensures an error inherits from Error
|
[
"Ensures",
"an",
"error",
"inherits",
"from",
"Error"
] |
84b308511f87d4b69da62bcd352f0ff2f7bd4f1b
|
https://github.com/parcel-bundler/parcel/blob/84b308511f87d4b69da62bcd352f0ff2f7bd4f1b/packages/core/parcel-bundler/src/assets/SASSAsset.js#L122-L134
|
train
|
parcel-bundler/parcel
|
packages/core/parcel-bundler/src/transforms/babel/jsx.js
|
getJSXConfig
|
async function getJSXConfig(asset, isSourceModule) {
// Don't enable JSX in node_modules
if (!isSourceModule) {
return null;
}
let pkg = await asset.getPackage();
// Find a dependency that we can map to a JSX pragma
let pragma = null;
for (let dep in JSX_PRAGMA) {
if (
pkg &&
((pkg.dependencies && pkg.dependencies[dep]) ||
(pkg.devDependencies && pkg.devDependencies[dep]))
) {
pragma = JSX_PRAGMA[dep];
break;
}
}
if (!pragma) {
pragma = maybeCreateFallbackPragma(asset);
}
if (pragma || JSX_EXTENSIONS[path.extname(asset.name)]) {
return {
internal: true,
babelVersion: 7,
config: {
plugins: [
[
require('@babel/plugin-transform-react-jsx'),
{
pragma,
pragmaFrag: 'React.Fragment'
}
]
]
}
};
}
}
|
javascript
|
async function getJSXConfig(asset, isSourceModule) {
// Don't enable JSX in node_modules
if (!isSourceModule) {
return null;
}
let pkg = await asset.getPackage();
// Find a dependency that we can map to a JSX pragma
let pragma = null;
for (let dep in JSX_PRAGMA) {
if (
pkg &&
((pkg.dependencies && pkg.dependencies[dep]) ||
(pkg.devDependencies && pkg.devDependencies[dep]))
) {
pragma = JSX_PRAGMA[dep];
break;
}
}
if (!pragma) {
pragma = maybeCreateFallbackPragma(asset);
}
if (pragma || JSX_EXTENSIONS[path.extname(asset.name)]) {
return {
internal: true,
babelVersion: 7,
config: {
plugins: [
[
require('@babel/plugin-transform-react-jsx'),
{
pragma,
pragmaFrag: 'React.Fragment'
}
]
]
}
};
}
}
|
[
"async",
"function",
"getJSXConfig",
"(",
"asset",
",",
"isSourceModule",
")",
"{",
"if",
"(",
"!",
"isSourceModule",
")",
"{",
"return",
"null",
";",
"}",
"let",
"pkg",
"=",
"await",
"asset",
".",
"getPackage",
"(",
")",
";",
"let",
"pragma",
"=",
"null",
";",
"for",
"(",
"let",
"dep",
"in",
"JSX_PRAGMA",
")",
"{",
"if",
"(",
"pkg",
"&&",
"(",
"(",
"pkg",
".",
"dependencies",
"&&",
"pkg",
".",
"dependencies",
"[",
"dep",
"]",
")",
"||",
"(",
"pkg",
".",
"devDependencies",
"&&",
"pkg",
".",
"devDependencies",
"[",
"dep",
"]",
")",
")",
")",
"{",
"pragma",
"=",
"JSX_PRAGMA",
"[",
"dep",
"]",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"pragma",
")",
"{",
"pragma",
"=",
"maybeCreateFallbackPragma",
"(",
"asset",
")",
";",
"}",
"if",
"(",
"pragma",
"||",
"JSX_EXTENSIONS",
"[",
"path",
".",
"extname",
"(",
"asset",
".",
"name",
")",
"]",
")",
"{",
"return",
"{",
"internal",
":",
"true",
",",
"babelVersion",
":",
"7",
",",
"config",
":",
"{",
"plugins",
":",
"[",
"[",
"require",
"(",
"'@babel/plugin-transform-react-jsx'",
")",
",",
"{",
"pragma",
",",
"pragmaFrag",
":",
"'React.Fragment'",
"}",
"]",
"]",
"}",
"}",
";",
"}",
"}"
] |
Generates a babel config for JSX. Attempts to detect react or react-like libraries
and changes the pragma accordingly.
|
[
"Generates",
"a",
"babel",
"config",
"for",
"JSX",
".",
"Attempts",
"to",
"detect",
"react",
"or",
"react",
"-",
"like",
"libraries",
"and",
"changes",
"the",
"pragma",
"accordingly",
"."
] |
84b308511f87d4b69da62bcd352f0ff2f7bd4f1b
|
https://github.com/parcel-bundler/parcel/blob/84b308511f87d4b69da62bcd352f0ff2f7bd4f1b/packages/core/parcel-bundler/src/transforms/babel/jsx.js#L47-L89
|
train
|
aws-amplify/amplify-js
|
docs/amplify-theme/assets/js/scripts.js
|
function() {
this.scrollToCurrent();
window.addEventListener('hashchange', this.scrollToCurrent.bind(this));
document.body.addEventListener('click', this.delegateAnchors.bind(this));
}
|
javascript
|
function() {
this.scrollToCurrent();
window.addEventListener('hashchange', this.scrollToCurrent.bind(this));
document.body.addEventListener('click', this.delegateAnchors.bind(this));
}
|
[
"function",
"(",
")",
"{",
"this",
".",
"scrollToCurrent",
"(",
")",
";",
"window",
".",
"addEventListener",
"(",
"'hashchange'",
",",
"this",
".",
"scrollToCurrent",
".",
"bind",
"(",
"this",
")",
")",
";",
"document",
".",
"body",
".",
"addEventListener",
"(",
"'click'",
",",
"this",
".",
"delegateAnchors",
".",
"bind",
"(",
"this",
")",
")",
";",
"}"
] |
Establish events, and fix initial scroll position if a hash is provided.
|
[
"Establish",
"events",
"and",
"fix",
"initial",
"scroll",
"position",
"if",
"a",
"hash",
"is",
"provided",
"."
] |
db55ff3dff31c64a246180f39eb0a04a89fd16e1
|
https://github.com/aws-amplify/amplify-js/blob/db55ff3dff31c64a246180f39eb0a04a89fd16e1/docs/amplify-theme/assets/js/scripts.js#L15-L19
|
train
|
|
aws-amplify/amplify-js
|
docs/amplify-theme/assets/js/scripts.js
|
function() {
let search_box = document.getElementById("search-input")
search_box.onclick = function() {
document.getElementById("search-image").style.display = "none";
search_box.style.outline = "none";
search_box.placeholder = "Search";
search_box.style.paddingLeft = "2px";
}
}
|
javascript
|
function() {
let search_box = document.getElementById("search-input")
search_box.onclick = function() {
document.getElementById("search-image").style.display = "none";
search_box.style.outline = "none";
search_box.placeholder = "Search";
search_box.style.paddingLeft = "2px";
}
}
|
[
"function",
"(",
")",
"{",
"let",
"search_box",
"=",
"document",
".",
"getElementById",
"(",
"\"search-input\"",
")",
"search_box",
".",
"onclick",
"=",
"function",
"(",
")",
"{",
"document",
".",
"getElementById",
"(",
"\"search-image\"",
")",
".",
"style",
".",
"display",
"=",
"\"none\"",
";",
"search_box",
".",
"style",
".",
"outline",
"=",
"\"none\"",
";",
"search_box",
".",
"placeholder",
"=",
"\"Search\"",
";",
"search_box",
".",
"style",
".",
"paddingLeft",
"=",
"\"2px\"",
";",
"}",
"}"
] |
Hide magnifying glass in search bar
|
[
"Hide",
"magnifying",
"glass",
"in",
"search",
"bar"
] |
db55ff3dff31c64a246180f39eb0a04a89fd16e1
|
https://github.com/aws-amplify/amplify-js/blob/db55ff3dff31c64a246180f39eb0a04a89fd16e1/docs/amplify-theme/assets/js/scripts.js#L358-L366
|
train
|
|
radare/radare2
|
shlr/www/d3/packages.js
|
function(nodes) {
var map = {},
imports = [];
// Compute a map from name to node.
nodes.forEach(function(d) {
map[d.name] = d;
});
// For each import, construct a link from the source to target node.
nodes.forEach(function(d) {
if (d.imports) d.imports.forEach(function(i) {
imports.push({source: map[d.name], target: map[i]});
});
});
return imports;
}
|
javascript
|
function(nodes) {
var map = {},
imports = [];
// Compute a map from name to node.
nodes.forEach(function(d) {
map[d.name] = d;
});
// For each import, construct a link from the source to target node.
nodes.forEach(function(d) {
if (d.imports) d.imports.forEach(function(i) {
imports.push({source: map[d.name], target: map[i]});
});
});
return imports;
}
|
[
"function",
"(",
"nodes",
")",
"{",
"var",
"map",
"=",
"{",
"}",
",",
"imports",
"=",
"[",
"]",
";",
"nodes",
".",
"forEach",
"(",
"function",
"(",
"d",
")",
"{",
"map",
"[",
"d",
".",
"name",
"]",
"=",
"d",
";",
"}",
")",
";",
"nodes",
".",
"forEach",
"(",
"function",
"(",
"d",
")",
"{",
"if",
"(",
"d",
".",
"imports",
")",
"d",
".",
"imports",
".",
"forEach",
"(",
"function",
"(",
"i",
")",
"{",
"imports",
".",
"push",
"(",
"{",
"source",
":",
"map",
"[",
"d",
".",
"name",
"]",
",",
"target",
":",
"map",
"[",
"i",
"]",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"return",
"imports",
";",
"}"
] |
Return a list of imports for the given array of nodes.
|
[
"Return",
"a",
"list",
"of",
"imports",
"for",
"the",
"given",
"array",
"of",
"nodes",
"."
] |
bf5e3028810a0ec7c267c6fe4bfad639b4819e35
|
https://github.com/radare/radare2/blob/bf5e3028810a0ec7c267c6fe4bfad639b4819e35/shlr/www/d3/packages.js#L29-L46
|
train
|
|
radare/radare2
|
shlr/www/graph/js-graph-it.js
|
BlocksToMoveVisitor
|
function BlocksToMoveVisitor() {
this.visit = function(element) {
if (isBlock(element)) {
blocksToMove.push(findBlock(element.id));
return false;
}
return true;
}
}
|
javascript
|
function BlocksToMoveVisitor() {
this.visit = function(element) {
if (isBlock(element)) {
blocksToMove.push(findBlock(element.id));
return false;
}
return true;
}
}
|
[
"function",
"BlocksToMoveVisitor",
"(",
")",
"{",
"this",
".",
"visit",
"=",
"function",
"(",
"element",
")",
"{",
"if",
"(",
"isBlock",
"(",
"element",
")",
")",
"{",
"blocksToMove",
".",
"push",
"(",
"findBlock",
"(",
"element",
".",
"id",
")",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}",
"}"
] |
this visitor is used to find blocks nested in the element being moved.
|
[
"this",
"visitor",
"is",
"used",
"to",
"find",
"blocks",
"nested",
"in",
"the",
"element",
"being",
"moved",
"."
] |
bf5e3028810a0ec7c267c6fe4bfad639b4819e35
|
https://github.com/radare/radare2/blob/bf5e3028810a0ec7c267c6fe4bfad639b4819e35/shlr/www/graph/js-graph-it.js#L69-L77
|
train
|
radare/radare2
|
shlr/www/graph/js-graph-it.js
|
getStyle
|
function getStyle(node, styleProp) {
// if not an element
if( node.nodeType != 1)
return;
var value;
if (node.currentStyle) {
// ie case
styleProp = replaceDashWithCamelNotation(styleProp);
value = node.currentStyle[styleProp];
} else if (window.getComputedStyle) {
// mozilla case
value = document.defaultView.getComputedStyle(node, null).getPropertyValue(styleProp);
}
return value;
}
|
javascript
|
function getStyle(node, styleProp) {
// if not an element
if( node.nodeType != 1)
return;
var value;
if (node.currentStyle) {
// ie case
styleProp = replaceDashWithCamelNotation(styleProp);
value = node.currentStyle[styleProp];
} else if (window.getComputedStyle) {
// mozilla case
value = document.defaultView.getComputedStyle(node, null).getPropertyValue(styleProp);
}
return value;
}
|
[
"function",
"getStyle",
"(",
"node",
",",
"styleProp",
")",
"{",
"if",
"(",
"node",
".",
"nodeType",
"!=",
"1",
")",
"return",
";",
"var",
"value",
";",
"if",
"(",
"node",
".",
"currentStyle",
")",
"{",
"styleProp",
"=",
"replaceDashWithCamelNotation",
"(",
"styleProp",
")",
";",
"value",
"=",
"node",
".",
"currentStyle",
"[",
"styleProp",
"]",
";",
"}",
"else",
"if",
"(",
"window",
".",
"getComputedStyle",
")",
"{",
"value",
"=",
"document",
".",
"defaultView",
".",
"getComputedStyle",
"(",
"node",
",",
"null",
")",
".",
"getPropertyValue",
"(",
"styleProp",
")",
";",
"}",
"return",
"value",
";",
"}"
] |
This function retrieves the actual value of a style property even if it is set via css.
|
[
"This",
"function",
"retrieves",
"the",
"actual",
"value",
"of",
"a",
"style",
"property",
"even",
"if",
"it",
"is",
"set",
"via",
"css",
"."
] |
bf5e3028810a0ec7c267c6fe4bfad639b4819e35
|
https://github.com/radare/radare2/blob/bf5e3028810a0ec7c267c6fe4bfad639b4819e35/shlr/www/graph/js-graph-it.js#L1262-L1278
|
train
|
radare/radare2
|
shlr/www/graph/index.js
|
resizeCanvas
|
function resizeCanvas() {
var divElement = document.getElementById("mainCanvas");
var screenHeight = window.innerHeight || document.body.offsetHeight;
divElement.style.height = (screenHeight - 16) + "px";
}
|
javascript
|
function resizeCanvas() {
var divElement = document.getElementById("mainCanvas");
var screenHeight = window.innerHeight || document.body.offsetHeight;
divElement.style.height = (screenHeight - 16) + "px";
}
|
[
"function",
"resizeCanvas",
"(",
")",
"{",
"var",
"divElement",
"=",
"document",
".",
"getElementById",
"(",
"\"mainCanvas\"",
")",
";",
"var",
"screenHeight",
"=",
"window",
".",
"innerHeight",
"||",
"document",
".",
"body",
".",
"offsetHeight",
";",
"divElement",
".",
"style",
".",
"height",
"=",
"(",
"screenHeight",
"-",
"16",
")",
"+",
"\"px\"",
";",
"}"
] |
Resizes the main canvas to the maximum visible height.
|
[
"Resizes",
"the",
"main",
"canvas",
"to",
"the",
"maximum",
"visible",
"height",
"."
] |
bf5e3028810a0ec7c267c6fe4bfad639b4819e35
|
https://github.com/radare/radare2/blob/bf5e3028810a0ec7c267c6fe4bfad639b4819e35/shlr/www/graph/index.js#L36-L40
|
train
|
radare/radare2
|
shlr/www/graph/index.js
|
setMenu
|
function setMenu() {
var url = document.location.href;
// strip extension
url = stripExtension(url);
var ulElement = document.getElementById("menu");
var links = ulElement.getElementsByTagName("A");
var i;
for(i = 0; i < links.length; i++) {
if(url.indexOf(stripExtension(links[i].href)) == 0) {
links[i].className = "active_menu";
return;
}
}
}
|
javascript
|
function setMenu() {
var url = document.location.href;
// strip extension
url = stripExtension(url);
var ulElement = document.getElementById("menu");
var links = ulElement.getElementsByTagName("A");
var i;
for(i = 0; i < links.length; i++) {
if(url.indexOf(stripExtension(links[i].href)) == 0) {
links[i].className = "active_menu";
return;
}
}
}
|
[
"function",
"setMenu",
"(",
")",
"{",
"var",
"url",
"=",
"document",
".",
"location",
".",
"href",
";",
"url",
"=",
"stripExtension",
"(",
"url",
")",
";",
"var",
"ulElement",
"=",
"document",
".",
"getElementById",
"(",
"\"menu\"",
")",
";",
"var",
"links",
"=",
"ulElement",
".",
"getElementsByTagName",
"(",
"\"A\"",
")",
";",
"var",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"links",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"url",
".",
"indexOf",
"(",
"stripExtension",
"(",
"links",
"[",
"i",
"]",
".",
"href",
")",
")",
"==",
"0",
")",
"{",
"links",
"[",
"i",
"]",
".",
"className",
"=",
"\"active_menu\"",
";",
"return",
";",
"}",
"}",
"}"
] |
sets the active menu scanning for a menu item which url is a prefix
of the one of the current page ignoring file extension.
Nice trick!
|
[
"sets",
"the",
"active",
"menu",
"scanning",
"for",
"a",
"menu",
"item",
"which",
"url",
"is",
"a",
"prefix",
"of",
"the",
"one",
"of",
"the",
"current",
"page",
"ignoring",
"file",
"extension",
".",
"Nice",
"trick!"
] |
bf5e3028810a0ec7c267c6fe4bfad639b4819e35
|
https://github.com/radare/radare2/blob/bf5e3028810a0ec7c267c6fe4bfad639b4819e35/shlr/www/graph/index.js#L47-L61
|
train
|
radare/radare2
|
shlr/www/graph/index.js
|
stripExtension
|
function stripExtension(url) {
var lastDotPos = url.lastIndexOf('.');
return (lastDotPos <= 0)? url:
url.substring (0, lastDotPos - 1);
}
|
javascript
|
function stripExtension(url) {
var lastDotPos = url.lastIndexOf('.');
return (lastDotPos <= 0)? url:
url.substring (0, lastDotPos - 1);
}
|
[
"function",
"stripExtension",
"(",
"url",
")",
"{",
"var",
"lastDotPos",
"=",
"url",
".",
"lastIndexOf",
"(",
"'.'",
")",
";",
"return",
"(",
"lastDotPos",
"<=",
"0",
")",
"?",
"url",
":",
"url",
".",
"substring",
"(",
"0",
",",
"lastDotPos",
"-",
"1",
")",
";",
"}"
] |
Strips the file extension and everything after from a url
|
[
"Strips",
"the",
"file",
"extension",
"and",
"everything",
"after",
"from",
"a",
"url"
] |
bf5e3028810a0ec7c267c6fe4bfad639b4819e35
|
https://github.com/radare/radare2/blob/bf5e3028810a0ec7c267c6fe4bfad639b4819e35/shlr/www/graph/index.js#L66-L70
|
train
|
knsv/mermaid
|
src/diagrams/git/gitGraphRenderer.js
|
getElementCoords
|
function getElementCoords (element, coords) {
coords = coords || element.node().getBBox()
const ctm = element.node().getCTM()
const xn = ctm.e + coords.x * ctm.a
const yn = ctm.f + coords.y * ctm.d
return {
left: xn,
top: yn,
width: coords.width,
height: coords.height
}
}
|
javascript
|
function getElementCoords (element, coords) {
coords = coords || element.node().getBBox()
const ctm = element.node().getCTM()
const xn = ctm.e + coords.x * ctm.a
const yn = ctm.f + coords.y * ctm.d
return {
left: xn,
top: yn,
width: coords.width,
height: coords.height
}
}
|
[
"function",
"getElementCoords",
"(",
"element",
",",
"coords",
")",
"{",
"coords",
"=",
"coords",
"||",
"element",
".",
"node",
"(",
")",
".",
"getBBox",
"(",
")",
"const",
"ctm",
"=",
"element",
".",
"node",
"(",
")",
".",
"getCTM",
"(",
")",
"const",
"xn",
"=",
"ctm",
".",
"e",
"+",
"coords",
".",
"x",
"*",
"ctm",
".",
"a",
"const",
"yn",
"=",
"ctm",
".",
"f",
"+",
"coords",
".",
"y",
"*",
"ctm",
".",
"d",
"return",
"{",
"left",
":",
"xn",
",",
"top",
":",
"yn",
",",
"width",
":",
"coords",
".",
"width",
",",
"height",
":",
"coords",
".",
"height",
"}",
"}"
] |
Pass in the element and its pre-transform coords
|
[
"Pass",
"in",
"the",
"element",
"and",
"its",
"pre",
"-",
"transform",
"coords"
] |
7d3578b31aeea3bc9bbc618dcda57d82574eaffb
|
https://github.com/knsv/mermaid/blob/7d3578b31aeea3bc9bbc618dcda57d82574eaffb/src/diagrams/git/gitGraphRenderer.js#L76-L87
|
train
|
youzan/vant
|
build/build-entry.js
|
buildDocsEntry
|
function buildDocsEntry() {
const output = join('docs/src/docs-entry.js');
const getName = fullPath => fullPath.replace(/\/(en|zh)/, '.$1').split('/').pop().replace('.md', '');
const docs = glob
.sync([
join('docs/**/*.md'),
join('packages/**/*.md'),
'!**/node_modules/**'
])
.map(fullPath => {
const name = getName(fullPath);
return `'${name}': () => import('${path.relative(join('docs/src'), fullPath).replace(/\\/g, '/')}')`;
});
const content = `${tips}
export default {
${docs.join(',\n ')}
};
`;
fs.writeFileSync(output, content);
}
|
javascript
|
function buildDocsEntry() {
const output = join('docs/src/docs-entry.js');
const getName = fullPath => fullPath.replace(/\/(en|zh)/, '.$1').split('/').pop().replace('.md', '');
const docs = glob
.sync([
join('docs/**/*.md'),
join('packages/**/*.md'),
'!**/node_modules/**'
])
.map(fullPath => {
const name = getName(fullPath);
return `'${name}': () => import('${path.relative(join('docs/src'), fullPath).replace(/\\/g, '/')}')`;
});
const content = `${tips}
export default {
${docs.join(',\n ')}
};
`;
fs.writeFileSync(output, content);
}
|
[
"function",
"buildDocsEntry",
"(",
")",
"{",
"const",
"output",
"=",
"join",
"(",
"'docs/src/docs-entry.js'",
")",
";",
"const",
"getName",
"=",
"fullPath",
"=>",
"fullPath",
".",
"replace",
"(",
"/",
"\\/(en|zh)",
"/",
",",
"'.$1'",
")",
".",
"split",
"(",
"'/'",
")",
".",
"pop",
"(",
")",
".",
"replace",
"(",
"'.md'",
",",
"''",
")",
";",
"const",
"docs",
"=",
"glob",
".",
"sync",
"(",
"[",
"join",
"(",
"'docs/**/*.md'",
")",
",",
"join",
"(",
"'packages/**/*.md'",
")",
",",
"'!**/node_modules/**'",
"]",
")",
".",
"map",
"(",
"fullPath",
"=>",
"{",
"const",
"name",
"=",
"getName",
"(",
"fullPath",
")",
";",
"return",
"`",
"${",
"name",
"}",
"${",
"path",
".",
"relative",
"(",
"join",
"(",
"'docs/src'",
")",
",",
"fullPath",
")",
".",
"replace",
"(",
"/",
"\\\\",
"/",
"g",
",",
"'/'",
")",
"}",
"`",
";",
"}",
")",
";",
"const",
"content",
"=",
"`",
"${",
"tips",
"}",
"${",
"docs",
".",
"join",
"(",
"',\\n '",
")",
"}",
"`",
";",
"\\n",
"}"
] |
generate webpack entry file for markdown docs
|
[
"generate",
"webpack",
"entry",
"file",
"for",
"markdown",
"docs"
] |
21589c9b9fd70b750deed1d31226b8d2c74d62c0
|
https://github.com/youzan/vant/blob/21589c9b9fd70b750deed1d31226b8d2c74d62c0/build/build-entry.js#L82-L102
|
train
|
youzan/vant
|
build/build-style-entry.js
|
analyzeDependencies
|
function analyzeDependencies(component) {
const checkList = ['base'];
search(
dependencyTree({
directory: dir,
filename: path.join(dir, component, 'index.js'),
filter: path => !~path.indexOf('node_modules')
}),
component,
checkList
);
if (!whiteList.includes(component)) {
checkList.push(component);
}
return checkList.filter(item => checkComponentHasStyle(item));
}
|
javascript
|
function analyzeDependencies(component) {
const checkList = ['base'];
search(
dependencyTree({
directory: dir,
filename: path.join(dir, component, 'index.js'),
filter: path => !~path.indexOf('node_modules')
}),
component,
checkList
);
if (!whiteList.includes(component)) {
checkList.push(component);
}
return checkList.filter(item => checkComponentHasStyle(item));
}
|
[
"function",
"analyzeDependencies",
"(",
"component",
")",
"{",
"const",
"checkList",
"=",
"[",
"'base'",
"]",
";",
"search",
"(",
"dependencyTree",
"(",
"{",
"directory",
":",
"dir",
",",
"filename",
":",
"path",
".",
"join",
"(",
"dir",
",",
"component",
",",
"'index.js'",
")",
",",
"filter",
":",
"path",
"=>",
"!",
"~",
"path",
".",
"indexOf",
"(",
"'node_modules'",
")",
"}",
")",
",",
"component",
",",
"checkList",
")",
";",
"if",
"(",
"!",
"whiteList",
".",
"includes",
"(",
"component",
")",
")",
"{",
"checkList",
".",
"push",
"(",
"component",
")",
";",
"}",
"return",
"checkList",
".",
"filter",
"(",
"item",
"=>",
"checkComponentHasStyle",
"(",
"item",
")",
")",
";",
"}"
] |
analyze component dependencies
|
[
"analyze",
"component",
"dependencies"
] |
21589c9b9fd70b750deed1d31226b8d2c74d62c0
|
https://github.com/youzan/vant/blob/21589c9b9fd70b750deed1d31226b8d2c74d62c0/build/build-style-entry.js#L42-L60
|
train
|
youzan/vant
|
build/build-style.js
|
compile
|
async function compile() {
let codes;
const paths = await glob(['./es/**/*.less', './lib/**/*.less'], { absolute: true });
codes = await Promise.all(paths.map(path => fs.readFile(path, 'utf-8')));
codes = await compileLess(codes, paths);
codes = await compilePostcss(codes, paths);
codes = await compileCsso(codes);
await dest(codes, paths);
}
|
javascript
|
async function compile() {
let codes;
const paths = await glob(['./es/**/*.less', './lib/**/*.less'], { absolute: true });
codes = await Promise.all(paths.map(path => fs.readFile(path, 'utf-8')));
codes = await compileLess(codes, paths);
codes = await compilePostcss(codes, paths);
codes = await compileCsso(codes);
await dest(codes, paths);
}
|
[
"async",
"function",
"compile",
"(",
")",
"{",
"let",
"codes",
";",
"const",
"paths",
"=",
"await",
"glob",
"(",
"[",
"'./es/**/*.less'",
",",
"'./lib/**/*.less'",
"]",
",",
"{",
"absolute",
":",
"true",
"}",
")",
";",
"codes",
"=",
"await",
"Promise",
".",
"all",
"(",
"paths",
".",
"map",
"(",
"path",
"=>",
"fs",
".",
"readFile",
"(",
"path",
",",
"'utf-8'",
")",
")",
")",
";",
"codes",
"=",
"await",
"compileLess",
"(",
"codes",
",",
"paths",
")",
";",
"codes",
"=",
"await",
"compilePostcss",
"(",
"codes",
",",
"paths",
")",
";",
"codes",
"=",
"await",
"compileCsso",
"(",
"codes",
")",
";",
"await",
"dest",
"(",
"codes",
",",
"paths",
")",
";",
"}"
] |
compile component css
|
[
"compile",
"component",
"css"
] |
21589c9b9fd70b750deed1d31226b8d2c74d62c0
|
https://github.com/youzan/vant/blob/21589c9b9fd70b750deed1d31226b8d2c74d62c0/build/build-style.js#L49-L59
|
train
|
Tonejs/Tone.js
|
Tone/component/Envelope.js
|
invertCurve
|
function invertCurve(curve){
var out = new Array(curve.length);
for (var j = 0; j < curve.length; j++){
out[j] = 1 - curve[j];
}
return out;
}
|
javascript
|
function invertCurve(curve){
var out = new Array(curve.length);
for (var j = 0; j < curve.length; j++){
out[j] = 1 - curve[j];
}
return out;
}
|
[
"function",
"invertCurve",
"(",
"curve",
")",
"{",
"var",
"out",
"=",
"new",
"Array",
"(",
"curve",
".",
"length",
")",
";",
"for",
"(",
"var",
"j",
"=",
"0",
";",
"j",
"<",
"curve",
".",
"length",
";",
"j",
"++",
")",
"{",
"out",
"[",
"j",
"]",
"=",
"1",
"-",
"curve",
"[",
"j",
"]",
";",
"}",
"return",
"out",
";",
"}"
] |
Invert a value curve to make it work for the release
@private
|
[
"Invert",
"a",
"value",
"curve",
"to",
"make",
"it",
"work",
"for",
"the",
"release"
] |
bb67e9c83d5553dfaa3c10babc147600aa14c147
|
https://github.com/Tonejs/Tone.js/blob/bb67e9c83d5553dfaa3c10babc147600aa14c147/Tone/component/Envelope.js#L432-L438
|
train
|
Tonejs/Tone.js
|
Tone/signal/TickSignal.js
|
_wrapScheduleMethods
|
function _wrapScheduleMethods(method){
return function(value, time){
time = this.toSeconds(time);
method.apply(this, arguments);
var event = this._events.get(time);
var previousEvent = this._events.previousEvent(event);
var ticksUntilTime = this._getTicksUntilEvent(previousEvent, time);
event.ticks = Math.max(ticksUntilTime, 0);
return this;
};
}
|
javascript
|
function _wrapScheduleMethods(method){
return function(value, time){
time = this.toSeconds(time);
method.apply(this, arguments);
var event = this._events.get(time);
var previousEvent = this._events.previousEvent(event);
var ticksUntilTime = this._getTicksUntilEvent(previousEvent, time);
event.ticks = Math.max(ticksUntilTime, 0);
return this;
};
}
|
[
"function",
"_wrapScheduleMethods",
"(",
"method",
")",
"{",
"return",
"function",
"(",
"value",
",",
"time",
")",
"{",
"time",
"=",
"this",
".",
"toSeconds",
"(",
"time",
")",
";",
"method",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"var",
"event",
"=",
"this",
".",
"_events",
".",
"get",
"(",
"time",
")",
";",
"var",
"previousEvent",
"=",
"this",
".",
"_events",
".",
"previousEvent",
"(",
"event",
")",
";",
"var",
"ticksUntilTime",
"=",
"this",
".",
"_getTicksUntilEvent",
"(",
"previousEvent",
",",
"time",
")",
";",
"event",
".",
"ticks",
"=",
"Math",
".",
"max",
"(",
"ticksUntilTime",
",",
"0",
")",
";",
"return",
"this",
";",
"}",
";",
"}"
] |
Wraps Tone.Signal methods so that they also
record the ticks.
@param {Function} method
@return {Function}
@private
|
[
"Wraps",
"Tone",
".",
"Signal",
"methods",
"so",
"that",
"they",
"also",
"record",
"the",
"ticks",
"."
] |
bb67e9c83d5553dfaa3c10babc147600aa14c147
|
https://github.com/Tonejs/Tone.js/blob/bb67e9c83d5553dfaa3c10babc147600aa14c147/Tone/signal/TickSignal.js#L46-L56
|
train
|
keplergl/kepler.gl
|
src/reducers/vis-state-updaters.js
|
computeSplitMapLayers
|
function computeSplitMapLayers(layers) {
const mapLayers = layers.reduce(
(newLayers, currentLayer) => ({
...newLayers,
[currentLayer.id]: generateLayerMetaForSplitViews(currentLayer)
}),
{}
);
return [
{
layers: mapLayers
},
{
layers: mapLayers
}
];
}
|
javascript
|
function computeSplitMapLayers(layers) {
const mapLayers = layers.reduce(
(newLayers, currentLayer) => ({
...newLayers,
[currentLayer.id]: generateLayerMetaForSplitViews(currentLayer)
}),
{}
);
return [
{
layers: mapLayers
},
{
layers: mapLayers
}
];
}
|
[
"function",
"computeSplitMapLayers",
"(",
"layers",
")",
"{",
"const",
"mapLayers",
"=",
"layers",
".",
"reduce",
"(",
"(",
"newLayers",
",",
"currentLayer",
")",
"=>",
"(",
"{",
"...",
"newLayers",
",",
"[",
"currentLayer",
".",
"id",
"]",
":",
"generateLayerMetaForSplitViews",
"(",
"currentLayer",
")",
"}",
")",
",",
"{",
"}",
")",
";",
"return",
"[",
"{",
"layers",
":",
"mapLayers",
"}",
",",
"{",
"layers",
":",
"mapLayers",
"}",
"]",
";",
"}"
] |
This method will compute the default maps custom list
based on the current layers status
@param {Array<Object>} layers
@returns {Array<Object>} split map settings
|
[
"This",
"method",
"will",
"compute",
"the",
"default",
"maps",
"custom",
"list",
"based",
"on",
"the",
"current",
"layers",
"status"
] |
779238435707cc54335c2d00001e4b9334b314aa
|
https://github.com/keplergl/kepler.gl/blob/779238435707cc54335c2d00001e4b9334b314aa/src/reducers/vis-state-updaters.js#L1094-L1110
|
train
|
keplergl/kepler.gl
|
src/reducers/vis-state-updaters.js
|
removeLayerFromSplitMaps
|
function removeLayerFromSplitMaps(state, layer) {
return state.splitMaps.map(settings => {
const {layers} = settings;
/* eslint-disable no-unused-vars */
const {[layer.id]: _, ...newLayers} = layers;
/* eslint-enable no-unused-vars */
return {
...settings,
layers: newLayers
};
});
}
|
javascript
|
function removeLayerFromSplitMaps(state, layer) {
return state.splitMaps.map(settings => {
const {layers} = settings;
/* eslint-disable no-unused-vars */
const {[layer.id]: _, ...newLayers} = layers;
/* eslint-enable no-unused-vars */
return {
...settings,
layers: newLayers
};
});
}
|
[
"function",
"removeLayerFromSplitMaps",
"(",
"state",
",",
"layer",
")",
"{",
"return",
"state",
".",
"splitMaps",
".",
"map",
"(",
"settings",
"=>",
"{",
"const",
"{",
"layers",
"}",
"=",
"settings",
";",
"const",
"{",
"[",
"layer",
".",
"id",
"]",
":",
"_",
",",
"...",
"newLayers",
"}",
"=",
"layers",
";",
"return",
"{",
"...",
"settings",
",",
"layers",
":",
"newLayers",
"}",
";",
"}",
")",
";",
"}"
] |
Remove an existing layer from split map settings
@param {Object} state `visState`
@param {Object} layer
@returns {Object} Maps of custom layer objects
|
[
"Remove",
"an",
"existing",
"layer",
"from",
"split",
"map",
"settings"
] |
779238435707cc54335c2d00001e4b9334b314aa
|
https://github.com/keplergl/kepler.gl/blob/779238435707cc54335c2d00001e4b9334b314aa/src/reducers/vis-state-updaters.js#L1118-L1129
|
train
|
keplergl/kepler.gl
|
src/reducers/vis-state-updaters.js
|
addNewLayersToSplitMap
|
function addNewLayersToSplitMap(splitMaps, layers) {
const newLayers = Array.isArray(layers) ? layers : [layers];
if (!splitMaps || !splitMaps.length || !newLayers.length) {
return splitMaps;
}
// add new layer to both maps,
// don't override, if layer.id is already in splitMaps.settings.layers
return splitMaps.map(settings => ({
...settings,
layers: {
...settings.layers,
...newLayers.reduce(
(accu, newLayer) =>
newLayer.config.isVisible
? {
...accu,
[newLayer.id]: settings.layers[newLayer.id]
? settings.layers[newLayer.id]
: generateLayerMetaForSplitViews(newLayer)
}
: accu,
{}
)
}
}));
}
|
javascript
|
function addNewLayersToSplitMap(splitMaps, layers) {
const newLayers = Array.isArray(layers) ? layers : [layers];
if (!splitMaps || !splitMaps.length || !newLayers.length) {
return splitMaps;
}
// add new layer to both maps,
// don't override, if layer.id is already in splitMaps.settings.layers
return splitMaps.map(settings => ({
...settings,
layers: {
...settings.layers,
...newLayers.reduce(
(accu, newLayer) =>
newLayer.config.isVisible
? {
...accu,
[newLayer.id]: settings.layers[newLayer.id]
? settings.layers[newLayer.id]
: generateLayerMetaForSplitViews(newLayer)
}
: accu,
{}
)
}
}));
}
|
[
"function",
"addNewLayersToSplitMap",
"(",
"splitMaps",
",",
"layers",
")",
"{",
"const",
"newLayers",
"=",
"Array",
".",
"isArray",
"(",
"layers",
")",
"?",
"layers",
":",
"[",
"layers",
"]",
";",
"if",
"(",
"!",
"splitMaps",
"||",
"!",
"splitMaps",
".",
"length",
"||",
"!",
"newLayers",
".",
"length",
")",
"{",
"return",
"splitMaps",
";",
"}",
"return",
"splitMaps",
".",
"map",
"(",
"settings",
"=>",
"(",
"{",
"...",
"settings",
",",
"layers",
":",
"{",
"...",
"settings",
".",
"layers",
",",
"...",
"newLayers",
".",
"reduce",
"(",
"(",
"accu",
",",
"newLayer",
")",
"=>",
"newLayer",
".",
"config",
".",
"isVisible",
"?",
"{",
"...",
"accu",
",",
"[",
"newLayer",
".",
"id",
"]",
":",
"settings",
".",
"layers",
"[",
"newLayer",
".",
"id",
"]",
"?",
"settings",
".",
"layers",
"[",
"newLayer",
".",
"id",
"]",
":",
"generateLayerMetaForSplitViews",
"(",
"newLayer",
")",
"}",
":",
"accu",
",",
"{",
"}",
")",
"}",
"}",
")",
")",
";",
"}"
] |
Add new layers to both existing maps
@param {Object} splitMaps
@param {Object|Array<Object>} layers
@returns {Array<Object>} new splitMaps
|
[
"Add",
"new",
"layers",
"to",
"both",
"existing",
"maps"
] |
779238435707cc54335c2d00001e4b9334b314aa
|
https://github.com/keplergl/kepler.gl/blob/779238435707cc54335c2d00001e4b9334b314aa/src/reducers/vis-state-updaters.js#L1137-L1164
|
train
|
keplergl/kepler.gl
|
src/reducers/vis-state-updaters.js
|
toggleLayerFromSplitMaps
|
function toggleLayerFromSplitMaps(state, layer) {
return state.splitMaps.map(settings => {
const {layers} = settings;
const newLayers = {
...layers,
[layer.id]: generateLayerMetaForSplitViews(layer)
};
return {
...settings,
layers: newLayers
};
});
}
|
javascript
|
function toggleLayerFromSplitMaps(state, layer) {
return state.splitMaps.map(settings => {
const {layers} = settings;
const newLayers = {
...layers,
[layer.id]: generateLayerMetaForSplitViews(layer)
};
return {
...settings,
layers: newLayers
};
});
}
|
[
"function",
"toggleLayerFromSplitMaps",
"(",
"state",
",",
"layer",
")",
"{",
"return",
"state",
".",
"splitMaps",
".",
"map",
"(",
"settings",
"=>",
"{",
"const",
"{",
"layers",
"}",
"=",
"settings",
";",
"const",
"newLayers",
"=",
"{",
"...",
"layers",
",",
"[",
"layer",
".",
"id",
"]",
":",
"generateLayerMetaForSplitViews",
"(",
"layer",
")",
"}",
";",
"return",
"{",
"...",
"settings",
",",
"layers",
":",
"newLayers",
"}",
";",
"}",
")",
";",
"}"
] |
Hide an existing layers from custom map layer objects
@param {Object} state
@param {Object} layer
@returns {Object} Maps of custom layer objects
|
[
"Hide",
"an",
"existing",
"layers",
"from",
"custom",
"map",
"layer",
"objects"
] |
779238435707cc54335c2d00001e4b9334b314aa
|
https://github.com/keplergl/kepler.gl/blob/779238435707cc54335c2d00001e4b9334b314aa/src/reducers/vis-state-updaters.js#L1172-L1185
|
train
|
keplergl/kepler.gl
|
examples/demo-app/src/utils/cloud-providers/dropbox.js
|
authLink
|
function authLink(path = 'auth') {
return dropbox.getAuthenticationUrl(
`${window.location.origin}/${path}`,
btoa(JSON.stringify({handler: 'dropbox', origin: window.location.origin}))
)
}
|
javascript
|
function authLink(path = 'auth') {
return dropbox.getAuthenticationUrl(
`${window.location.origin}/${path}`,
btoa(JSON.stringify({handler: 'dropbox', origin: window.location.origin}))
)
}
|
[
"function",
"authLink",
"(",
"path",
"=",
"'auth'",
")",
"{",
"return",
"dropbox",
".",
"getAuthenticationUrl",
"(",
"`",
"${",
"window",
".",
"location",
".",
"origin",
"}",
"${",
"path",
"}",
"`",
",",
"btoa",
"(",
"JSON",
".",
"stringify",
"(",
"{",
"handler",
":",
"'dropbox'",
",",
"origin",
":",
"window",
".",
"location",
".",
"origin",
"}",
")",
")",
")",
"}"
] |
Generate auth link url to open to be used to handle OAuth2
@param {string} path
|
[
"Generate",
"auth",
"link",
"url",
"to",
"open",
"to",
"be",
"used",
"to",
"handle",
"OAuth2"
] |
779238435707cc54335c2d00001e4b9334b314aa
|
https://github.com/keplergl/kepler.gl/blob/779238435707cc54335c2d00001e4b9334b314aa/examples/demo-app/src/utils/cloud-providers/dropbox.js#L49-L54
|
train
|
keplergl/kepler.gl
|
examples/demo-app/src/utils/cloud-providers/dropbox.js
|
shareFile
|
function shareFile(metadata) {
return dropbox.sharingCreateSharedLinkWithSettings({
path: metadata.path_display || metadata.path_lower
}).then(
// Update URL to avoid CORS issue
// Unfortunately this is not the ideal scenario but it will make sure people
// can share dropbox urls with users without the dropbox account (publish on twitter, facebook)
result => ({
...result,
folder_link: KEPLER_DROPBOX_FOLDER_LINK,
url: overrideUrl(result.url)
})
);
}
|
javascript
|
function shareFile(metadata) {
return dropbox.sharingCreateSharedLinkWithSettings({
path: metadata.path_display || metadata.path_lower
}).then(
// Update URL to avoid CORS issue
// Unfortunately this is not the ideal scenario but it will make sure people
// can share dropbox urls with users without the dropbox account (publish on twitter, facebook)
result => ({
...result,
folder_link: KEPLER_DROPBOX_FOLDER_LINK,
url: overrideUrl(result.url)
})
);
}
|
[
"function",
"shareFile",
"(",
"metadata",
")",
"{",
"return",
"dropbox",
".",
"sharingCreateSharedLinkWithSettings",
"(",
"{",
"path",
":",
"metadata",
".",
"path_display",
"||",
"metadata",
".",
"path_lower",
"}",
")",
".",
"then",
"(",
"result",
"=>",
"(",
"{",
"...",
"result",
",",
"folder_link",
":",
"KEPLER_DROPBOX_FOLDER_LINK",
",",
"url",
":",
"overrideUrl",
"(",
"result",
".",
"url",
")",
"}",
")",
")",
";",
"}"
] |
It will set access to file to public
@param {Object} metadata metadata response from uploading the file
@returns {Promise<DropboxTypes.sharing.FileLinkMetadataReference | DropboxTypes.sharing.FolderLinkMetadataReference | DropboxTypes.sharing.SharedLinkMetadataReference>}
|
[
"It",
"will",
"set",
"access",
"to",
"file",
"to",
"public"
] |
779238435707cc54335c2d00001e4b9334b314aa
|
https://github.com/keplergl/kepler.gl/blob/779238435707cc54335c2d00001e4b9334b314aa/examples/demo-app/src/utils/cloud-providers/dropbox.js#L92-L105
|
train
|
keplergl/kepler.gl
|
examples/demo-app/src/utils/cloud-providers/dropbox.js
|
getAccessToken
|
function getAccessToken() {
let token = dropbox.getAccessToken();
if (!token && window.localStorage) {
const jsonString = window.localStorage.getItem('dropbox');
token = jsonString && JSON.parse(jsonString).token;
if (token) {
dropbox.setAccessToken(token);
}
}
return (token || '') !== '' ? token : null;
}
|
javascript
|
function getAccessToken() {
let token = dropbox.getAccessToken();
if (!token && window.localStorage) {
const jsonString = window.localStorage.getItem('dropbox');
token = jsonString && JSON.parse(jsonString).token;
if (token) {
dropbox.setAccessToken(token);
}
}
return (token || '') !== '' ? token : null;
}
|
[
"function",
"getAccessToken",
"(",
")",
"{",
"let",
"token",
"=",
"dropbox",
".",
"getAccessToken",
"(",
")",
";",
"if",
"(",
"!",
"token",
"&&",
"window",
".",
"localStorage",
")",
"{",
"const",
"jsonString",
"=",
"window",
".",
"localStorage",
".",
"getItem",
"(",
"'dropbox'",
")",
";",
"token",
"=",
"jsonString",
"&&",
"JSON",
".",
"parse",
"(",
"jsonString",
")",
".",
"token",
";",
"if",
"(",
"token",
")",
"{",
"dropbox",
".",
"setAccessToken",
"(",
"token",
")",
";",
"}",
"}",
"return",
"(",
"token",
"||",
"''",
")",
"!==",
"''",
"?",
"token",
":",
"null",
";",
"}"
] |
Provides the current dropbox auth token. If stored in localStorage is set onto dropbox handler and returned
@returns {any}
|
[
"Provides",
"the",
"current",
"dropbox",
"auth",
"token",
".",
"If",
"stored",
"in",
"localStorage",
"is",
"set",
"onto",
"dropbox",
"handler",
"and",
"returned"
] |
779238435707cc54335c2d00001e4b9334b314aa
|
https://github.com/keplergl/kepler.gl/blob/779238435707cc54335c2d00001e4b9334b314aa/examples/demo-app/src/utils/cloud-providers/dropbox.js#L150-L161
|
train
|
keplergl/kepler.gl
|
scripts/documentation.js
|
_appendActionToUpdaters
|
function _appendActionToUpdaters(node, actionMap) {
if (node.members && node.members.static.length) {
node.members.static = node.members.static.map(nd => _appendActionToUpdaters(nd, actionMap));
}
const updater = node.name;
const action = Object.values(actionMap)
.find(action => action.updaters.find(up => up.name === updater));
if (!action) {
return node;
}
const actionName = action.name;
const mdContent = `
* __Action__: [${BT}${actionName}${BT}](../actions/actions.md#${actionName.toLowerCase()})
`;
return _appendListToDescription(node, mdContent);
}
|
javascript
|
function _appendActionToUpdaters(node, actionMap) {
if (node.members && node.members.static.length) {
node.members.static = node.members.static.map(nd => _appendActionToUpdaters(nd, actionMap));
}
const updater = node.name;
const action = Object.values(actionMap)
.find(action => action.updaters.find(up => up.name === updater));
if (!action) {
return node;
}
const actionName = action.name;
const mdContent = `
* __Action__: [${BT}${actionName}${BT}](../actions/actions.md#${actionName.toLowerCase()})
`;
return _appendListToDescription(node, mdContent);
}
|
[
"function",
"_appendActionToUpdaters",
"(",
"node",
",",
"actionMap",
")",
"{",
"if",
"(",
"node",
".",
"members",
"&&",
"node",
".",
"members",
".",
"static",
".",
"length",
")",
"{",
"node",
".",
"members",
".",
"static",
"=",
"node",
".",
"members",
".",
"static",
".",
"map",
"(",
"nd",
"=>",
"_appendActionToUpdaters",
"(",
"nd",
",",
"actionMap",
")",
")",
";",
"}",
"const",
"updater",
"=",
"node",
".",
"name",
";",
"const",
"action",
"=",
"Object",
".",
"values",
"(",
"actionMap",
")",
".",
"find",
"(",
"action",
"=>",
"action",
".",
"updaters",
".",
"find",
"(",
"up",
"=>",
"up",
".",
"name",
"===",
"updater",
")",
")",
";",
"if",
"(",
"!",
"action",
")",
"{",
"return",
"node",
";",
"}",
"const",
"actionName",
"=",
"action",
".",
"name",
";",
"const",
"mdContent",
"=",
"`",
"${",
"BT",
"}",
"${",
"actionName",
"}",
"${",
"BT",
"}",
"${",
"actionName",
".",
"toLowerCase",
"(",
")",
"}",
"`",
";",
"return",
"_appendListToDescription",
"(",
"node",
",",
"mdContent",
")",
";",
"}"
] |
Add action to linked updaters
@param {Object} node
@param {Object} actionMap
|
[
"Add",
"action",
"to",
"linked",
"updaters"
] |
779238435707cc54335c2d00001e4b9334b314aa
|
https://github.com/keplergl/kepler.gl/blob/779238435707cc54335c2d00001e4b9334b314aa/scripts/documentation.js#L143-L163
|
train
|
keplergl/kepler.gl
|
scripts/documentation.js
|
_cleanUpTOCChildren
|
function _cleanUpTOCChildren(node) {
if (!Array.isArray(node.children)) {
return node;
}
if (_isExampleOrParameterLink(node)) {
return null;
}
const filteredChildren = node.children.reduce((accu, nd) => {
accu.push(_cleanUpTOCChildren(nd));
return accu;
}, []).filter(n => n);
if (!filteredChildren.length) {
return null;
}
return {
...node,
children: filteredChildren
};
}
|
javascript
|
function _cleanUpTOCChildren(node) {
if (!Array.isArray(node.children)) {
return node;
}
if (_isExampleOrParameterLink(node)) {
return null;
}
const filteredChildren = node.children.reduce((accu, nd) => {
accu.push(_cleanUpTOCChildren(nd));
return accu;
}, []).filter(n => n);
if (!filteredChildren.length) {
return null;
}
return {
...node,
children: filteredChildren
};
}
|
[
"function",
"_cleanUpTOCChildren",
"(",
"node",
")",
"{",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"node",
".",
"children",
")",
")",
"{",
"return",
"node",
";",
"}",
"if",
"(",
"_isExampleOrParameterLink",
"(",
"node",
")",
")",
"{",
"return",
"null",
";",
"}",
"const",
"filteredChildren",
"=",
"node",
".",
"children",
".",
"reduce",
"(",
"(",
"accu",
",",
"nd",
")",
"=>",
"{",
"accu",
".",
"push",
"(",
"_cleanUpTOCChildren",
"(",
"nd",
")",
")",
";",
"return",
"accu",
";",
"}",
",",
"[",
"]",
")",
".",
"filter",
"(",
"n",
"=>",
"n",
")",
";",
"if",
"(",
"!",
"filteredChildren",
".",
"length",
")",
"{",
"return",
"null",
";",
"}",
"return",
"{",
"...",
"node",
",",
"children",
":",
"filteredChildren",
"}",
";",
"}"
] |
Remove example and parameter link from TOC
|
[
"Remove",
"example",
"and",
"parameter",
"link",
"from",
"TOC"
] |
779238435707cc54335c2d00001e4b9334b314aa
|
https://github.com/keplergl/kepler.gl/blob/779238435707cc54335c2d00001e4b9334b314aa/scripts/documentation.js#L204-L227
|
train
|
keplergl/kepler.gl
|
src/schemas/vis-state-schema.js
|
geojsonSizeFieldV0ToV1
|
function geojsonSizeFieldV0ToV1(config) {
const defaultRaiuds = 10;
const defaultRadiusRange = [0, 50];
// if extruded, sizeField is most likely used for height
if (config.visConfig.extruded) {
return 'heightField';
}
// if show stroke enabled, sizeField is most likely used for stroke
if (config.visConfig.stroked) {
return 'sizeField';
}
// if radius changed, or radius Range Changed, sizeField is most likely used for radius
// this is the most unreliable guess, that's why we put it in the end
if (
config.visConfig.radius !== defaultRaiuds ||
config.visConfig.radiusRange.some((d, i) => d !== defaultRadiusRange[i])
) {
return 'radiusField';
}
return 'sizeField';
}
|
javascript
|
function geojsonSizeFieldV0ToV1(config) {
const defaultRaiuds = 10;
const defaultRadiusRange = [0, 50];
// if extruded, sizeField is most likely used for height
if (config.visConfig.extruded) {
return 'heightField';
}
// if show stroke enabled, sizeField is most likely used for stroke
if (config.visConfig.stroked) {
return 'sizeField';
}
// if radius changed, or radius Range Changed, sizeField is most likely used for radius
// this is the most unreliable guess, that's why we put it in the end
if (
config.visConfig.radius !== defaultRaiuds ||
config.visConfig.radiusRange.some((d, i) => d !== defaultRadiusRange[i])
) {
return 'radiusField';
}
return 'sizeField';
}
|
[
"function",
"geojsonSizeFieldV0ToV1",
"(",
"config",
")",
"{",
"const",
"defaultRaiuds",
"=",
"10",
";",
"const",
"defaultRadiusRange",
"=",
"[",
"0",
",",
"50",
"]",
";",
"if",
"(",
"config",
".",
"visConfig",
".",
"extruded",
")",
"{",
"return",
"'heightField'",
";",
"}",
"if",
"(",
"config",
".",
"visConfig",
".",
"stroked",
")",
"{",
"return",
"'sizeField'",
";",
"}",
"if",
"(",
"config",
".",
"visConfig",
".",
"radius",
"!==",
"defaultRaiuds",
"||",
"config",
".",
"visConfig",
".",
"radiusRange",
".",
"some",
"(",
"(",
"d",
",",
"i",
")",
"=>",
"d",
"!==",
"defaultRadiusRange",
"[",
"i",
"]",
")",
")",
"{",
"return",
"'radiusField'",
";",
"}",
"return",
"'sizeField'",
";",
"}"
] |
in v1 geojson stroke base on -> sizeField height based on -> heightField radius based on -> radiusField here we make our wiredst guess on which channel sizeField belongs to
|
[
"in",
"v1",
"geojson",
"stroke",
"base",
"on",
"-",
">",
"sizeField",
"height",
"based",
"on",
"-",
">",
"heightField",
"radius",
"based",
"on",
"-",
">",
"radiusField",
"here",
"we",
"make",
"our",
"wiredst",
"guess",
"on",
"which",
"channel",
"sizeField",
"belongs",
"to"
] |
779238435707cc54335c2d00001e4b9334b314aa
|
https://github.com/keplergl/kepler.gl/blob/779238435707cc54335c2d00001e4b9334b314aa/src/schemas/vis-state-schema.js#L40-L64
|
train
|
keplergl/kepler.gl
|
src/components/kepler-gl.js
|
mergeActions
|
function mergeActions(actions, userActions) {
const overrides = {};
for (const key in userActions) {
if (userActions.hasOwnProperty(key) && actions.hasOwnProperty(key)) {
overrides[key] = userActions[key];
}
}
return {...actions, ...overrides};
}
|
javascript
|
function mergeActions(actions, userActions) {
const overrides = {};
for (const key in userActions) {
if (userActions.hasOwnProperty(key) && actions.hasOwnProperty(key)) {
overrides[key] = userActions[key];
}
}
return {...actions, ...overrides};
}
|
[
"function",
"mergeActions",
"(",
"actions",
",",
"userActions",
")",
"{",
"const",
"overrides",
"=",
"{",
"}",
";",
"for",
"(",
"const",
"key",
"in",
"userActions",
")",
"{",
"if",
"(",
"userActions",
".",
"hasOwnProperty",
"(",
"key",
")",
"&&",
"actions",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"overrides",
"[",
"key",
"]",
"=",
"userActions",
"[",
"key",
"]",
";",
"}",
"}",
"return",
"{",
"...",
"actions",
",",
"...",
"overrides",
"}",
";",
"}"
] |
Override default maps-gl actions with user defined actions using the same key
|
[
"Override",
"default",
"maps",
"-",
"gl",
"actions",
"with",
"user",
"defined",
"actions",
"using",
"the",
"same",
"key"
] |
779238435707cc54335c2d00001e4b9334b314aa
|
https://github.com/keplergl/kepler.gl/blob/779238435707cc54335c2d00001e4b9334b314aa/src/components/kepler-gl.js#L374-L383
|
train
|
keplergl/kepler.gl
|
examples/demo-app/src/actions.js
|
loadRemoteRawData
|
function loadRemoteRawData(url) {
if (!url) {
// TODO: we should return reject with an appropriate error
return Promise.resolve(null)
}
return new Promise((resolve, reject) => {
request(url, (error, result) => {
if (error) {
reject(error);
}
const responseError = detectResponseError(result);
if (responseError) {
reject(responseError);
return;
}
resolve(result.response)
})
});
}
|
javascript
|
function loadRemoteRawData(url) {
if (!url) {
// TODO: we should return reject with an appropriate error
return Promise.resolve(null)
}
return new Promise((resolve, reject) => {
request(url, (error, result) => {
if (error) {
reject(error);
}
const responseError = detectResponseError(result);
if (responseError) {
reject(responseError);
return;
}
resolve(result.response)
})
});
}
|
[
"function",
"loadRemoteRawData",
"(",
"url",
")",
"{",
"if",
"(",
"!",
"url",
")",
"{",
"return",
"Promise",
".",
"resolve",
"(",
"null",
")",
"}",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"request",
"(",
"url",
",",
"(",
"error",
",",
"result",
")",
"=>",
"{",
"if",
"(",
"error",
")",
"{",
"reject",
"(",
"error",
")",
";",
"}",
"const",
"responseError",
"=",
"detectResponseError",
"(",
"result",
")",
";",
"if",
"(",
"responseError",
")",
"{",
"reject",
"(",
"responseError",
")",
";",
"return",
";",
"}",
"resolve",
"(",
"result",
".",
"response",
")",
"}",
")",
"}",
")",
";",
"}"
] |
Load a file from a remote URL
@param url
@returns {Promise<any>}
|
[
"Load",
"a",
"file",
"from",
"a",
"remote",
"URL"
] |
779238435707cc54335c2d00001e4b9334b314aa
|
https://github.com/keplergl/kepler.gl/blob/779238435707cc54335c2d00001e4b9334b314aa/examples/demo-app/src/actions.js#L165-L184
|
train
|
keplergl/kepler.gl
|
examples/demo-app/src/actions.js
|
loadRemoteSampleMap
|
function loadRemoteSampleMap(options) {
return (dispatch) => {
// Load configuration first
const {configUrl, dataUrl} = options;
Promise
.all([loadRemoteConfig(configUrl), loadRemoteData(dataUrl)])
.then(
([config, data]) => {
// TODO: these two actions can be merged
dispatch(loadRemoteResourceSuccess(data, config, options));
dispatch(toggleModal(null));
},
error => {
if (error) {
const {target = {}} = error;
const {status, responseText} = target;
dispatch(loadRemoteResourceError({status, message: `${responseText} - ${LOADING_SAMPLE_ERROR_MESSAGE} ${options.id} (${configUrl})`}, configUrl));
}
}
);
}
}
|
javascript
|
function loadRemoteSampleMap(options) {
return (dispatch) => {
// Load configuration first
const {configUrl, dataUrl} = options;
Promise
.all([loadRemoteConfig(configUrl), loadRemoteData(dataUrl)])
.then(
([config, data]) => {
// TODO: these two actions can be merged
dispatch(loadRemoteResourceSuccess(data, config, options));
dispatch(toggleModal(null));
},
error => {
if (error) {
const {target = {}} = error;
const {status, responseText} = target;
dispatch(loadRemoteResourceError({status, message: `${responseText} - ${LOADING_SAMPLE_ERROR_MESSAGE} ${options.id} (${configUrl})`}, configUrl));
}
}
);
}
}
|
[
"function",
"loadRemoteSampleMap",
"(",
"options",
")",
"{",
"return",
"(",
"dispatch",
")",
"=>",
"{",
"const",
"{",
"configUrl",
",",
"dataUrl",
"}",
"=",
"options",
";",
"Promise",
".",
"all",
"(",
"[",
"loadRemoteConfig",
"(",
"configUrl",
")",
",",
"loadRemoteData",
"(",
"dataUrl",
")",
"]",
")",
".",
"then",
"(",
"(",
"[",
"config",
",",
"data",
"]",
")",
"=>",
"{",
"dispatch",
"(",
"loadRemoteResourceSuccess",
"(",
"data",
",",
"config",
",",
"options",
")",
")",
";",
"dispatch",
"(",
"toggleModal",
"(",
"null",
")",
")",
";",
"}",
",",
"error",
"=>",
"{",
"if",
"(",
"error",
")",
"{",
"const",
"{",
"target",
"=",
"{",
"}",
"}",
"=",
"error",
";",
"const",
"{",
"status",
",",
"responseText",
"}",
"=",
"target",
";",
"dispatch",
"(",
"loadRemoteResourceError",
"(",
"{",
"status",
",",
"message",
":",
"`",
"${",
"responseText",
"}",
"${",
"LOADING_SAMPLE_ERROR_MESSAGE",
"}",
"${",
"options",
".",
"id",
"}",
"${",
"configUrl",
"}",
"`",
"}",
",",
"configUrl",
")",
")",
";",
"}",
"}",
")",
";",
"}",
"}"
] |
Load remote map with config and data
@param options {configUrl, dataUrl}
@returns {Function}
|
[
"Load",
"remote",
"map",
"with",
"config",
"and",
"data"
] |
779238435707cc54335c2d00001e4b9334b314aa
|
https://github.com/keplergl/kepler.gl/blob/779238435707cc54335c2d00001e4b9334b314aa/examples/demo-app/src/actions.js#L223-L245
|
train
|
keplergl/kepler.gl
|
scripts/action-table-maker.js
|
addActionHandler
|
function addActionHandler(path, actionMap, filePath) {
const {init} = path.node;
if (init && Array.isArray(init.properties)) {
init.properties.forEach(property => {
const {key, value} = property;
if (key && value && key.property && value.property) {
const actionType = key.property.name;
const updater = value.name;
actionMap[actionType] = actionMap[actionType] || createActionNode(actionType);
actionMap[actionType].updaters.push({
updater: value.object.name,
name: value.property.name,
path: filePath
});
}
})
}
}
|
javascript
|
function addActionHandler(path, actionMap, filePath) {
const {init} = path.node;
if (init && Array.isArray(init.properties)) {
init.properties.forEach(property => {
const {key, value} = property;
if (key && value && key.property && value.property) {
const actionType = key.property.name;
const updater = value.name;
actionMap[actionType] = actionMap[actionType] || createActionNode(actionType);
actionMap[actionType].updaters.push({
updater: value.object.name,
name: value.property.name,
path: filePath
});
}
})
}
}
|
[
"function",
"addActionHandler",
"(",
"path",
",",
"actionMap",
",",
"filePath",
")",
"{",
"const",
"{",
"init",
"}",
"=",
"path",
".",
"node",
";",
"if",
"(",
"init",
"&&",
"Array",
".",
"isArray",
"(",
"init",
".",
"properties",
")",
")",
"{",
"init",
".",
"properties",
".",
"forEach",
"(",
"property",
"=>",
"{",
"const",
"{",
"key",
",",
"value",
"}",
"=",
"property",
";",
"if",
"(",
"key",
"&&",
"value",
"&&",
"key",
".",
"property",
"&&",
"value",
".",
"property",
")",
"{",
"const",
"actionType",
"=",
"key",
".",
"property",
".",
"name",
";",
"const",
"updater",
"=",
"value",
".",
"name",
";",
"actionMap",
"[",
"actionType",
"]",
"=",
"actionMap",
"[",
"actionType",
"]",
"||",
"createActionNode",
"(",
"actionType",
")",
";",
"actionMap",
"[",
"actionType",
"]",
".",
"updaters",
".",
"push",
"(",
"{",
"updater",
":",
"value",
".",
"object",
".",
"name",
",",
"name",
":",
"value",
".",
"property",
".",
"name",
",",
"path",
":",
"filePath",
"}",
")",
";",
"}",
"}",
")",
"}",
"}"
] |
Parse actionHandler declaration to map updater to action type
@param {Object} path - AST node
@param {Object} actionMap
@param {string} filePath
|
[
"Parse",
"actionHandler",
"declaration",
"to",
"map",
"updater",
"to",
"action",
"type"
] |
779238435707cc54335c2d00001e4b9334b314aa
|
https://github.com/keplergl/kepler.gl/blob/779238435707cc54335c2d00001e4b9334b314aa/scripts/action-table-maker.js#L71-L91
|
train
|
keplergl/kepler.gl
|
scripts/action-table-maker.js
|
addActionCreator
|
function addActionCreator(path, actionMap, filePath) {
const {node, parentPath} = path;
if (node.arguments.length && parentPath.node && parentPath.node.id) {
const action = parentPath.node.id.name;
const firstArg = node.arguments[0];
const actionType = firstArg.property ? firstArg.property.name : firstArg.name;
const {loc} = parentPath.node
actionMap[actionType] = actionMap[actionType] || createActionNode(actionType);
actionMap[actionType].action = {name: action, path: `${filePath}#L${loc.start.line}-L${loc.end.line}`};
}
}
|
javascript
|
function addActionCreator(path, actionMap, filePath) {
const {node, parentPath} = path;
if (node.arguments.length && parentPath.node && parentPath.node.id) {
const action = parentPath.node.id.name;
const firstArg = node.arguments[0];
const actionType = firstArg.property ? firstArg.property.name : firstArg.name;
const {loc} = parentPath.node
actionMap[actionType] = actionMap[actionType] || createActionNode(actionType);
actionMap[actionType].action = {name: action, path: `${filePath}#L${loc.start.line}-L${loc.end.line}`};
}
}
|
[
"function",
"addActionCreator",
"(",
"path",
",",
"actionMap",
",",
"filePath",
")",
"{",
"const",
"{",
"node",
",",
"parentPath",
"}",
"=",
"path",
";",
"if",
"(",
"node",
".",
"arguments",
".",
"length",
"&&",
"parentPath",
".",
"node",
"&&",
"parentPath",
".",
"node",
".",
"id",
")",
"{",
"const",
"action",
"=",
"parentPath",
".",
"node",
".",
"id",
".",
"name",
";",
"const",
"firstArg",
"=",
"node",
".",
"arguments",
"[",
"0",
"]",
";",
"const",
"actionType",
"=",
"firstArg",
".",
"property",
"?",
"firstArg",
".",
"property",
".",
"name",
":",
"firstArg",
".",
"name",
";",
"const",
"{",
"loc",
"}",
"=",
"parentPath",
".",
"node",
"actionMap",
"[",
"actionType",
"]",
"=",
"actionMap",
"[",
"actionType",
"]",
"||",
"createActionNode",
"(",
"actionType",
")",
";",
"actionMap",
"[",
"actionType",
"]",
".",
"action",
"=",
"{",
"name",
":",
"action",
",",
"path",
":",
"`",
"${",
"filePath",
"}",
"${",
"loc",
".",
"start",
".",
"line",
"}",
"${",
"loc",
".",
"end",
".",
"line",
"}",
"`",
"}",
";",
"}",
"}"
] |
Parse createAction function to add action to action type
@param {*} path
@param {*} actionMap
@param {*} filePath
|
[
"Parse",
"createAction",
"function",
"to",
"add",
"action",
"to",
"action",
"type"
] |
779238435707cc54335c2d00001e4b9334b314aa
|
https://github.com/keplergl/kepler.gl/blob/779238435707cc54335c2d00001e4b9334b314aa/scripts/action-table-maker.js#L99-L112
|
train
|
keplergl/kepler.gl
|
src/utils/filter-utils.js
|
getHistogram
|
function getHistogram(domain, mappedValue) {
const histogram = histogramConstruct(domain, mappedValue, histogramBins);
const enlargedHistogram = histogramConstruct(
domain,
mappedValue,
enlargedHistogramBins
);
return {histogram, enlargedHistogram};
}
|
javascript
|
function getHistogram(domain, mappedValue) {
const histogram = histogramConstruct(domain, mappedValue, histogramBins);
const enlargedHistogram = histogramConstruct(
domain,
mappedValue,
enlargedHistogramBins
);
return {histogram, enlargedHistogram};
}
|
[
"function",
"getHistogram",
"(",
"domain",
",",
"mappedValue",
")",
"{",
"const",
"histogram",
"=",
"histogramConstruct",
"(",
"domain",
",",
"mappedValue",
",",
"histogramBins",
")",
";",
"const",
"enlargedHistogram",
"=",
"histogramConstruct",
"(",
"domain",
",",
"mappedValue",
",",
"enlargedHistogramBins",
")",
";",
"return",
"{",
"histogram",
",",
"enlargedHistogram",
"}",
";",
"}"
] |
Calculate histogram from domain and array of values
@param {number[]} domain
@param {Object[]} mappedValue
@returns {Array[]} histogram
|
[
"Calculate",
"histogram",
"from",
"domain",
"and",
"array",
"of",
"values"
] |
779238435707cc54335c2d00001e4b9334b314aa
|
https://github.com/keplergl/kepler.gl/blob/779238435707cc54335c2d00001e4b9334b314aa/src/utils/filter-utils.js#L457-L466
|
train
|
keplergl/kepler.gl
|
src/deckgl-layers/3d-building-layer/3d-building-utils.js
|
classifyRings
|
function classifyRings(rings) {
const len = rings.length;
if (len <= 1) return [rings];
const polygons = [];
let polygon;
let ccw;
for (let i = 0; i < len; i++) {
const area = signedArea(rings[i]);
if (area === 0) {
continue;
}
if (ccw === undefined) {
ccw = area < 0;
}
if (ccw === area < 0) {
if (polygon) {
polygons.push(polygon);
}
polygon = [rings[i]];
} else {
polygon.push(rings[i]);
}
}
if (polygon) {
polygons.push(polygon);
}
return polygons;
}
|
javascript
|
function classifyRings(rings) {
const len = rings.length;
if (len <= 1) return [rings];
const polygons = [];
let polygon;
let ccw;
for (let i = 0; i < len; i++) {
const area = signedArea(rings[i]);
if (area === 0) {
continue;
}
if (ccw === undefined) {
ccw = area < 0;
}
if (ccw === area < 0) {
if (polygon) {
polygons.push(polygon);
}
polygon = [rings[i]];
} else {
polygon.push(rings[i]);
}
}
if (polygon) {
polygons.push(polygon);
}
return polygons;
}
|
[
"function",
"classifyRings",
"(",
"rings",
")",
"{",
"const",
"len",
"=",
"rings",
".",
"length",
";",
"if",
"(",
"len",
"<=",
"1",
")",
"return",
"[",
"rings",
"]",
";",
"const",
"polygons",
"=",
"[",
"]",
";",
"let",
"polygon",
";",
"let",
"ccw",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"const",
"area",
"=",
"signedArea",
"(",
"rings",
"[",
"i",
"]",
")",
";",
"if",
"(",
"area",
"===",
"0",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"ccw",
"===",
"undefined",
")",
"{",
"ccw",
"=",
"area",
"<",
"0",
";",
"}",
"if",
"(",
"ccw",
"===",
"area",
"<",
"0",
")",
"{",
"if",
"(",
"polygon",
")",
"{",
"polygons",
".",
"push",
"(",
"polygon",
")",
";",
"}",
"polygon",
"=",
"[",
"rings",
"[",
"i",
"]",
"]",
";",
"}",
"else",
"{",
"polygon",
".",
"push",
"(",
"rings",
"[",
"i",
"]",
")",
";",
"}",
"}",
"if",
"(",
"polygon",
")",
"{",
"polygons",
".",
"push",
"(",
"polygon",
")",
";",
"}",
"return",
"polygons",
";",
"}"
] |
classifies an array of rings into polygons with outer rings and holes
|
[
"classifies",
"an",
"array",
"of",
"rings",
"into",
"polygons",
"with",
"outer",
"rings",
"and",
"holes"
] |
779238435707cc54335c2d00001e4b9334b314aa
|
https://github.com/keplergl/kepler.gl/blob/779238435707cc54335c2d00001e4b9334b314aa/src/deckgl-layers/3d-building-layer/3d-building-utils.js#L148-L181
|
train
|
keplergl/kepler.gl
|
examples/replace-component/src/components/side-bar.js
|
CustomSidebarFactory
|
function CustomSidebarFactory(CloseButton) {
const SideBar = SidebarFactory(CloseButton);
const CustomSidebar = (props) => (
<StyledSideBarContainer>
<SideBar {...props}/>
</StyledSideBarContainer>
);
return CustomSidebar;
}
|
javascript
|
function CustomSidebarFactory(CloseButton) {
const SideBar = SidebarFactory(CloseButton);
const CustomSidebar = (props) => (
<StyledSideBarContainer>
<SideBar {...props}/>
</StyledSideBarContainer>
);
return CustomSidebar;
}
|
[
"function",
"CustomSidebarFactory",
"(",
"CloseButton",
")",
"{",
"const",
"SideBar",
"=",
"SidebarFactory",
"(",
"CloseButton",
")",
";",
"const",
"CustomSidebar",
"=",
"(",
"props",
")",
"=>",
"(",
"<",
"StyledSideBarContainer",
">",
" ",
"<",
"SideBar",
"{",
"...",
"props",
"}",
"/",
">",
" ",
"<",
"/",
"StyledSideBarContainer",
">",
")",
";",
"return",
"CustomSidebar",
";",
"}"
] |
Custom sidebar will render kepler.gl default side bar adding a wrapper component to edit its style
|
[
"Custom",
"sidebar",
"will",
"render",
"kepler",
".",
"gl",
"default",
"side",
"bar",
"adding",
"a",
"wrapper",
"component",
"to",
"edit",
"its",
"style"
] |
779238435707cc54335c2d00001e4b9334b314aa
|
https://github.com/keplergl/kepler.gl/blob/779238435707cc54335c2d00001e4b9334b314aa/examples/replace-component/src/components/side-bar.js#L72-L80
|
train
|
keplergl/kepler.gl
|
src/processors/data-processor.js
|
cleanUpFalsyCsvValue
|
function cleanUpFalsyCsvValue(rows) {
for (let i = 0; i < rows.length; i++) {
for (let j = 0; j < rows[i].length; j++) {
// analyzer will set any fields to 'string' if there are empty values
// which will be parsed as '' by d3.csv
// here we parse empty data as null
// TODO: create warning when deltect `CSV_NULLS` in the data
if (!rows[i][j] || CSV_NULLS.includes(rows[i][j])) {
rows[i][j] = null;
}
}
}
}
|
javascript
|
function cleanUpFalsyCsvValue(rows) {
for (let i = 0; i < rows.length; i++) {
for (let j = 0; j < rows[i].length; j++) {
// analyzer will set any fields to 'string' if there are empty values
// which will be parsed as '' by d3.csv
// here we parse empty data as null
// TODO: create warning when deltect `CSV_NULLS` in the data
if (!rows[i][j] || CSV_NULLS.includes(rows[i][j])) {
rows[i][j] = null;
}
}
}
}
|
[
"function",
"cleanUpFalsyCsvValue",
"(",
"rows",
")",
"{",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"rows",
".",
"length",
";",
"i",
"++",
")",
"{",
"for",
"(",
"let",
"j",
"=",
"0",
";",
"j",
"<",
"rows",
"[",
"i",
"]",
".",
"length",
";",
"j",
"++",
")",
"{",
"if",
"(",
"!",
"rows",
"[",
"i",
"]",
"[",
"j",
"]",
"||",
"CSV_NULLS",
".",
"includes",
"(",
"rows",
"[",
"i",
"]",
"[",
"j",
"]",
")",
")",
"{",
"rows",
"[",
"i",
"]",
"[",
"j",
"]",
"=",
"null",
";",
"}",
"}",
"}",
"}"
] |
Convert falsy value in csv including `'', 'null', 'NULL', 'Null', 'NaN'` to `null`,
so that type-analyzer won't detect it as string
@param {Array<Array>} rows
|
[
"Convert",
"falsy",
"value",
"in",
"csv",
"including",
"null",
"NULL",
"Null",
"NaN",
"to",
"null",
"so",
"that",
"type",
"-",
"analyzer",
"won",
"t",
"detect",
"it",
"as",
"string"
] |
779238435707cc54335c2d00001e4b9334b314aa
|
https://github.com/keplergl/kepler.gl/blob/779238435707cc54335c2d00001e4b9334b314aa/src/processors/data-processor.js#L138-L150
|
train
|
wix/Detox
|
generation/core/generator.js
|
hasProblematicOverloading
|
function hasProblematicOverloading(instances) {
// Check if there are same lengthed argument sets
const knownLengths = [];
return instances.map(({ args }) => args.length).reduce((carry, item) => {
if (carry || knownLengths.some((l) => l === item)) {
return true;
}
knownLengths.push(item);
return false;
}, false);
}
|
javascript
|
function hasProblematicOverloading(instances) {
// Check if there are same lengthed argument sets
const knownLengths = [];
return instances.map(({ args }) => args.length).reduce((carry, item) => {
if (carry || knownLengths.some((l) => l === item)) {
return true;
}
knownLengths.push(item);
return false;
}, false);
}
|
[
"function",
"hasProblematicOverloading",
"(",
"instances",
")",
"{",
"const",
"knownLengths",
"=",
"[",
"]",
";",
"return",
"instances",
".",
"map",
"(",
"(",
"{",
"args",
"}",
")",
"=>",
"args",
".",
"length",
")",
".",
"reduce",
"(",
"(",
"carry",
",",
"item",
")",
"=>",
"{",
"if",
"(",
"carry",
"||",
"knownLengths",
".",
"some",
"(",
"(",
"l",
")",
"=>",
"l",
"===",
"item",
")",
")",
"{",
"return",
"true",
";",
"}",
"knownLengths",
".",
"push",
"(",
"item",
")",
";",
"return",
"false",
";",
"}",
",",
"false",
")",
";",
"}"
] |
We don't handle same lengthed argument sets right now. In the future we could write the type checks in a way that would allow us to do an either or switch in this case
|
[
"We",
"don",
"t",
"handle",
"same",
"lengthed",
"argument",
"sets",
"right",
"now",
".",
"In",
"the",
"future",
"we",
"could",
"write",
"the",
"type",
"checks",
"in",
"a",
"way",
"that",
"would",
"allow",
"us",
"to",
"do",
"an",
"either",
"or",
"switch",
"in",
"this",
"case"
] |
0ed5e8c7ba279a3a409130b4d4bad3f9a9c2f1f9
|
https://github.com/wix/Detox/blob/0ed5e8c7ba279a3a409130b4d4bad3f9a9c2f1f9/generation/core/generator.js#L159-L170
|
train
|
necolas/react-native-web
|
packages/react-native-web/src/vendor/react-native/isEmpty/index.js
|
isEmpty
|
function isEmpty(obj) {
if (Array.isArray(obj)) {
return obj.length === 0;
} else if (typeof obj === 'object') {
for (var i in obj) {
return false;
}
return true;
} else {
return !obj;
}
}
|
javascript
|
function isEmpty(obj) {
if (Array.isArray(obj)) {
return obj.length === 0;
} else if (typeof obj === 'object') {
for (var i in obj) {
return false;
}
return true;
} else {
return !obj;
}
}
|
[
"function",
"isEmpty",
"(",
"obj",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"obj",
")",
")",
"{",
"return",
"obj",
".",
"length",
"===",
"0",
";",
"}",
"else",
"if",
"(",
"typeof",
"obj",
"===",
"'object'",
")",
"{",
"for",
"(",
"var",
"i",
"in",
"obj",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"!",
"obj",
";",
"}",
"}"
] |
Mimics empty from PHP.
|
[
"Mimics",
"empty",
"from",
"PHP",
"."
] |
801937748b2f3c96284bee1881164ac0c62a9c6d
|
https://github.com/necolas/react-native-web/blob/801937748b2f3c96284bee1881164ac0c62a9c6d/packages/react-native-web/src/vendor/react-native/isEmpty/index.js#L14-L25
|
train
|
jiahaog/nativefier
|
src/build/buildMain.js
|
getAppPath
|
function getAppPath(appPathArray) {
if (appPathArray.length === 0) {
// directory already exists, --overwrite is not set
// exit here
return null;
}
if (appPathArray.length > 1) {
log.warn(
'Warning: This should not be happening, packaged app path contains more than one element:',
appPathArray,
);
}
return appPathArray[0];
}
|
javascript
|
function getAppPath(appPathArray) {
if (appPathArray.length === 0) {
// directory already exists, --overwrite is not set
// exit here
return null;
}
if (appPathArray.length > 1) {
log.warn(
'Warning: This should not be happening, packaged app path contains more than one element:',
appPathArray,
);
}
return appPathArray[0];
}
|
[
"function",
"getAppPath",
"(",
"appPathArray",
")",
"{",
"if",
"(",
"appPathArray",
".",
"length",
"===",
"0",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"appPathArray",
".",
"length",
">",
"1",
")",
"{",
"log",
".",
"warn",
"(",
"'Warning: This should not be happening, packaged app path contains more than one element:'",
",",
"appPathArray",
",",
")",
";",
"}",
"return",
"appPathArray",
"[",
"0",
"]",
";",
"}"
] |
Checks the app path array to determine if the packaging was completed successfully
@param appPathArray Result from electron-packager
@returns {*}
|
[
"Checks",
"the",
"app",
"path",
"array",
"to",
"determine",
"if",
"the",
"packaging",
"was",
"completed",
"successfully"
] |
b959956a38ce51a9dd95d42308f0a6c66489b624
|
https://github.com/jiahaog/nativefier/blob/b959956a38ce51a9dd95d42308f0a6c66489b624/src/build/buildMain.js#L23-L38
|
train
|
jiahaog/nativefier
|
src/build/buildMain.js
|
maybeNoIconOption
|
function maybeNoIconOption(options) {
const packageOptions = JSON.parse(JSON.stringify(options));
if (options.platform === 'win32' && !isWindows()) {
if (!hasBinary.sync('wine')) {
log.warn(
'Wine is required to set the icon for a Windows app when packaging on non-windows platforms',
);
packageOptions.icon = null;
}
}
return packageOptions;
}
|
javascript
|
function maybeNoIconOption(options) {
const packageOptions = JSON.parse(JSON.stringify(options));
if (options.platform === 'win32' && !isWindows()) {
if (!hasBinary.sync('wine')) {
log.warn(
'Wine is required to set the icon for a Windows app when packaging on non-windows platforms',
);
packageOptions.icon = null;
}
}
return packageOptions;
}
|
[
"function",
"maybeNoIconOption",
"(",
"options",
")",
"{",
"const",
"packageOptions",
"=",
"JSON",
".",
"parse",
"(",
"JSON",
".",
"stringify",
"(",
"options",
")",
")",
";",
"if",
"(",
"options",
".",
"platform",
"===",
"'win32'",
"&&",
"!",
"isWindows",
"(",
")",
")",
"{",
"if",
"(",
"!",
"hasBinary",
".",
"sync",
"(",
"'wine'",
")",
")",
"{",
"log",
".",
"warn",
"(",
"'Wine is required to set the icon for a Windows app when packaging on non-windows platforms'",
",",
")",
";",
"packageOptions",
".",
"icon",
"=",
"null",
";",
"}",
"}",
"return",
"packageOptions",
";",
"}"
] |
Removes the `icon` parameter from options if building for Windows while not on Windows
and Wine is not installed
@param options
|
[
"Removes",
"the",
"icon",
"parameter",
"from",
"options",
"if",
"building",
"for",
"Windows",
"while",
"not",
"on",
"Windows",
"and",
"Wine",
"is",
"not",
"installed"
] |
b959956a38ce51a9dd95d42308f0a6c66489b624
|
https://github.com/jiahaog/nativefier/blob/b959956a38ce51a9dd95d42308f0a6c66489b624/src/build/buildMain.js#L45-L56
|
train
|
jiahaog/nativefier
|
src/build/buildMain.js
|
removeInvalidOptions
|
function removeInvalidOptions(options, param) {
const packageOptions = JSON.parse(JSON.stringify(options));
if (options.platform === 'win32' && !isWindows()) {
if (!hasBinary.sync('wine')) {
log.warn(
`Wine is required to use "${param}" option for a Windows app when packaging on non-windows platforms`,
);
packageOptions[param] = null;
}
}
return packageOptions;
}
|
javascript
|
function removeInvalidOptions(options, param) {
const packageOptions = JSON.parse(JSON.stringify(options));
if (options.platform === 'win32' && !isWindows()) {
if (!hasBinary.sync('wine')) {
log.warn(
`Wine is required to use "${param}" option for a Windows app when packaging on non-windows platforms`,
);
packageOptions[param] = null;
}
}
return packageOptions;
}
|
[
"function",
"removeInvalidOptions",
"(",
"options",
",",
"param",
")",
"{",
"const",
"packageOptions",
"=",
"JSON",
".",
"parse",
"(",
"JSON",
".",
"stringify",
"(",
"options",
")",
")",
";",
"if",
"(",
"options",
".",
"platform",
"===",
"'win32'",
"&&",
"!",
"isWindows",
"(",
")",
")",
"{",
"if",
"(",
"!",
"hasBinary",
".",
"sync",
"(",
"'wine'",
")",
")",
"{",
"log",
".",
"warn",
"(",
"`",
"${",
"param",
"}",
"`",
",",
")",
";",
"packageOptions",
"[",
"param",
"]",
"=",
"null",
";",
"}",
"}",
"return",
"packageOptions",
";",
"}"
] |
Removes invalid parameters from options if building for Windows while not on Windows
and Wine is not installed
@param options
|
[
"Removes",
"invalid",
"parameters",
"from",
"options",
"if",
"building",
"for",
"Windows",
"while",
"not",
"on",
"Windows",
"and",
"Wine",
"is",
"not",
"installed"
] |
b959956a38ce51a9dd95d42308f0a6c66489b624
|
https://github.com/jiahaog/nativefier/blob/b959956a38ce51a9dd95d42308f0a6c66489b624/src/build/buildMain.js#L90-L101
|
train
|
jiahaog/nativefier
|
app/src/helpers/inferFlash.js
|
findSync
|
function findSync(pattern, basePath, findDir) {
const matches = [];
(function findSyncRecurse(base) {
let children;
try {
children = fs.readdirSync(base);
} catch (exception) {
if (exception.code === 'ENOENT') {
return;
}
throw exception;
}
children.forEach((child) => {
const childPath = path.join(base, child);
const childIsDirectory = fs.lstatSync(childPath).isDirectory();
const patternMatches = pattern.test(childPath);
if (!patternMatches) {
if (!childIsDirectory) {
return;
}
findSyncRecurse(childPath);
return;
}
if (!findDir) {
matches.push(childPath);
return;
}
if (childIsDirectory) {
matches.push(childPath);
}
});
})(basePath);
return matches;
}
|
javascript
|
function findSync(pattern, basePath, findDir) {
const matches = [];
(function findSyncRecurse(base) {
let children;
try {
children = fs.readdirSync(base);
} catch (exception) {
if (exception.code === 'ENOENT') {
return;
}
throw exception;
}
children.forEach((child) => {
const childPath = path.join(base, child);
const childIsDirectory = fs.lstatSync(childPath).isDirectory();
const patternMatches = pattern.test(childPath);
if (!patternMatches) {
if (!childIsDirectory) {
return;
}
findSyncRecurse(childPath);
return;
}
if (!findDir) {
matches.push(childPath);
return;
}
if (childIsDirectory) {
matches.push(childPath);
}
});
})(basePath);
return matches;
}
|
[
"function",
"findSync",
"(",
"pattern",
",",
"basePath",
",",
"findDir",
")",
"{",
"const",
"matches",
"=",
"[",
"]",
";",
"(",
"function",
"findSyncRecurse",
"(",
"base",
")",
"{",
"let",
"children",
";",
"try",
"{",
"children",
"=",
"fs",
".",
"readdirSync",
"(",
"base",
")",
";",
"}",
"catch",
"(",
"exception",
")",
"{",
"if",
"(",
"exception",
".",
"code",
"===",
"'ENOENT'",
")",
"{",
"return",
";",
"}",
"throw",
"exception",
";",
"}",
"children",
".",
"forEach",
"(",
"(",
"child",
")",
"=>",
"{",
"const",
"childPath",
"=",
"path",
".",
"join",
"(",
"base",
",",
"child",
")",
";",
"const",
"childIsDirectory",
"=",
"fs",
".",
"lstatSync",
"(",
"childPath",
")",
".",
"isDirectory",
"(",
")",
";",
"const",
"patternMatches",
"=",
"pattern",
".",
"test",
"(",
"childPath",
")",
";",
"if",
"(",
"!",
"patternMatches",
")",
"{",
"if",
"(",
"!",
"childIsDirectory",
")",
"{",
"return",
";",
"}",
"findSyncRecurse",
"(",
"childPath",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"findDir",
")",
"{",
"matches",
".",
"push",
"(",
"childPath",
")",
";",
"return",
";",
"}",
"if",
"(",
"childIsDirectory",
")",
"{",
"matches",
".",
"push",
"(",
"childPath",
")",
";",
"}",
"}",
")",
";",
"}",
")",
"(",
"basePath",
")",
";",
"return",
"matches",
";",
"}"
] |
Synchronously find a file or directory
@param {RegExp} pattern regex
@param {string} base path
@param {boolean} [findDir] if true, search results will be limited to only directories
@returns {Array}
|
[
"Synchronously",
"find",
"a",
"file",
"or",
"directory"
] |
b959956a38ce51a9dd95d42308f0a6c66489b624
|
https://github.com/jiahaog/nativefier/blob/b959956a38ce51a9dd95d42308f0a6c66489b624/app/src/helpers/inferFlash.js#L14-L52
|
train
|
jiahaog/nativefier
|
src/options/fields/index.js
|
wrap
|
function wrap(fieldName, promise, args) {
return promise(args).then((result) => ({
[fieldName]: result,
}));
}
|
javascript
|
function wrap(fieldName, promise, args) {
return promise(args).then((result) => ({
[fieldName]: result,
}));
}
|
[
"function",
"wrap",
"(",
"fieldName",
",",
"promise",
",",
"args",
")",
"{",
"return",
"promise",
"(",
"args",
")",
".",
"then",
"(",
"(",
"result",
")",
"=>",
"(",
"{",
"[",
"fieldName",
"]",
":",
"result",
",",
"}",
")",
")",
";",
"}"
] |
Modifies the result of each promise from a scalar value to a object containing its fieldname
|
[
"Modifies",
"the",
"result",
"of",
"each",
"promise",
"from",
"a",
"scalar",
"value",
"to",
"a",
"object",
"containing",
"its",
"fieldname"
] |
b959956a38ce51a9dd95d42308f0a6c66489b624
|
https://github.com/jiahaog/nativefier/blob/b959956a38ce51a9dd95d42308f0a6c66489b624/src/options/fields/index.js#L22-L26
|
train
|
jiahaog/nativefier
|
src/infer/inferIcon.js
|
getMatchingIcons
|
function getMatchingIcons(iconsWithScores, maxScore) {
return iconsWithScores
.filter((item) => item.score === maxScore)
.map((item) => Object.assign({}, item, { ext: path.extname(item.url) }));
}
|
javascript
|
function getMatchingIcons(iconsWithScores, maxScore) {
return iconsWithScores
.filter((item) => item.score === maxScore)
.map((item) => Object.assign({}, item, { ext: path.extname(item.url) }));
}
|
[
"function",
"getMatchingIcons",
"(",
"iconsWithScores",
",",
"maxScore",
")",
"{",
"return",
"iconsWithScores",
".",
"filter",
"(",
"(",
"item",
")",
"=>",
"item",
".",
"score",
"===",
"maxScore",
")",
".",
"map",
"(",
"(",
"item",
")",
"=>",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"item",
",",
"{",
"ext",
":",
"path",
".",
"extname",
"(",
"item",
".",
"url",
")",
"}",
")",
")",
";",
"}"
] |
also maps ext to icon object
|
[
"also",
"maps",
"ext",
"to",
"icon",
"object"
] |
b959956a38ce51a9dd95d42308f0a6c66489b624
|
https://github.com/jiahaog/nativefier/blob/b959956a38ce51a9dd95d42308f0a6c66489b624/src/infer/inferIcon.js#L26-L30
|
train
|
jiahaog/nativefier
|
src/build/buildApp.js
|
selectAppArgs
|
function selectAppArgs(options) {
return {
name: options.name,
targetUrl: options.targetUrl,
counter: options.counter,
bounce: options.bounce,
width: options.width,
height: options.height,
minWidth: options.minWidth,
minHeight: options.minHeight,
maxWidth: options.maxWidth,
maxHeight: options.maxHeight,
x: options.x,
y: options.y,
showMenuBar: options.showMenuBar,
fastQuit: options.fastQuit,
userAgent: options.userAgent,
nativefierVersion: options.nativefierVersion,
ignoreCertificate: options.ignoreCertificate,
disableGpu: options.disableGpu,
ignoreGpuBlacklist: options.ignoreGpuBlacklist,
enableEs3Apis: options.enableEs3Apis,
insecure: options.insecure,
flashPluginDir: options.flashPluginDir,
diskCacheSize: options.diskCacheSize,
fullScreen: options.fullScreen,
hideWindowFrame: options.hideWindowFrame,
maximize: options.maximize,
disableContextMenu: options.disableContextMenu,
disableDevTools: options.disableDevTools,
zoom: options.zoom,
internalUrls: options.internalUrls,
crashReporter: options.crashReporter,
singleInstance: options.singleInstance,
clearCache: options.clearCache,
appCopyright: options.appCopyright,
appVersion: options.appVersion,
buildVersion: options.buildVersion,
win32metadata: options.win32metadata,
versionString: options.versionString,
processEnvs: options.processEnvs,
fileDownloadOptions: options.fileDownloadOptions,
tray: options.tray,
basicAuthUsername: options.basicAuthUsername,
basicAuthPassword: options.basicAuthPassword,
alwaysOnTop: options.alwaysOnTop,
titleBarStyle: options.titleBarStyle,
globalShortcuts: options.globalShortcuts,
};
}
|
javascript
|
function selectAppArgs(options) {
return {
name: options.name,
targetUrl: options.targetUrl,
counter: options.counter,
bounce: options.bounce,
width: options.width,
height: options.height,
minWidth: options.minWidth,
minHeight: options.minHeight,
maxWidth: options.maxWidth,
maxHeight: options.maxHeight,
x: options.x,
y: options.y,
showMenuBar: options.showMenuBar,
fastQuit: options.fastQuit,
userAgent: options.userAgent,
nativefierVersion: options.nativefierVersion,
ignoreCertificate: options.ignoreCertificate,
disableGpu: options.disableGpu,
ignoreGpuBlacklist: options.ignoreGpuBlacklist,
enableEs3Apis: options.enableEs3Apis,
insecure: options.insecure,
flashPluginDir: options.flashPluginDir,
diskCacheSize: options.diskCacheSize,
fullScreen: options.fullScreen,
hideWindowFrame: options.hideWindowFrame,
maximize: options.maximize,
disableContextMenu: options.disableContextMenu,
disableDevTools: options.disableDevTools,
zoom: options.zoom,
internalUrls: options.internalUrls,
crashReporter: options.crashReporter,
singleInstance: options.singleInstance,
clearCache: options.clearCache,
appCopyright: options.appCopyright,
appVersion: options.appVersion,
buildVersion: options.buildVersion,
win32metadata: options.win32metadata,
versionString: options.versionString,
processEnvs: options.processEnvs,
fileDownloadOptions: options.fileDownloadOptions,
tray: options.tray,
basicAuthUsername: options.basicAuthUsername,
basicAuthPassword: options.basicAuthPassword,
alwaysOnTop: options.alwaysOnTop,
titleBarStyle: options.titleBarStyle,
globalShortcuts: options.globalShortcuts,
};
}
|
[
"function",
"selectAppArgs",
"(",
"options",
")",
"{",
"return",
"{",
"name",
":",
"options",
".",
"name",
",",
"targetUrl",
":",
"options",
".",
"targetUrl",
",",
"counter",
":",
"options",
".",
"counter",
",",
"bounce",
":",
"options",
".",
"bounce",
",",
"width",
":",
"options",
".",
"width",
",",
"height",
":",
"options",
".",
"height",
",",
"minWidth",
":",
"options",
".",
"minWidth",
",",
"minHeight",
":",
"options",
".",
"minHeight",
",",
"maxWidth",
":",
"options",
".",
"maxWidth",
",",
"maxHeight",
":",
"options",
".",
"maxHeight",
",",
"x",
":",
"options",
".",
"x",
",",
"y",
":",
"options",
".",
"y",
",",
"showMenuBar",
":",
"options",
".",
"showMenuBar",
",",
"fastQuit",
":",
"options",
".",
"fastQuit",
",",
"userAgent",
":",
"options",
".",
"userAgent",
",",
"nativefierVersion",
":",
"options",
".",
"nativefierVersion",
",",
"ignoreCertificate",
":",
"options",
".",
"ignoreCertificate",
",",
"disableGpu",
":",
"options",
".",
"disableGpu",
",",
"ignoreGpuBlacklist",
":",
"options",
".",
"ignoreGpuBlacklist",
",",
"enableEs3Apis",
":",
"options",
".",
"enableEs3Apis",
",",
"insecure",
":",
"options",
".",
"insecure",
",",
"flashPluginDir",
":",
"options",
".",
"flashPluginDir",
",",
"diskCacheSize",
":",
"options",
".",
"diskCacheSize",
",",
"fullScreen",
":",
"options",
".",
"fullScreen",
",",
"hideWindowFrame",
":",
"options",
".",
"hideWindowFrame",
",",
"maximize",
":",
"options",
".",
"maximize",
",",
"disableContextMenu",
":",
"options",
".",
"disableContextMenu",
",",
"disableDevTools",
":",
"options",
".",
"disableDevTools",
",",
"zoom",
":",
"options",
".",
"zoom",
",",
"internalUrls",
":",
"options",
".",
"internalUrls",
",",
"crashReporter",
":",
"options",
".",
"crashReporter",
",",
"singleInstance",
":",
"options",
".",
"singleInstance",
",",
"clearCache",
":",
"options",
".",
"clearCache",
",",
"appCopyright",
":",
"options",
".",
"appCopyright",
",",
"appVersion",
":",
"options",
".",
"appVersion",
",",
"buildVersion",
":",
"options",
".",
"buildVersion",
",",
"win32metadata",
":",
"options",
".",
"win32metadata",
",",
"versionString",
":",
"options",
".",
"versionString",
",",
"processEnvs",
":",
"options",
".",
"processEnvs",
",",
"fileDownloadOptions",
":",
"options",
".",
"fileDownloadOptions",
",",
"tray",
":",
"options",
".",
"tray",
",",
"basicAuthUsername",
":",
"options",
".",
"basicAuthUsername",
",",
"basicAuthPassword",
":",
"options",
".",
"basicAuthPassword",
",",
"alwaysOnTop",
":",
"options",
".",
"alwaysOnTop",
",",
"titleBarStyle",
":",
"options",
".",
"titleBarStyle",
",",
"globalShortcuts",
":",
"options",
".",
"globalShortcuts",
",",
"}",
";",
"}"
] |
Only picks certain app args to pass to nativefier.json
@param options
|
[
"Only",
"picks",
"certain",
"app",
"args",
"to",
"pass",
"to",
"nativefier",
".",
"json"
] |
b959956a38ce51a9dd95d42308f0a6c66489b624
|
https://github.com/jiahaog/nativefier/blob/b959956a38ce51a9dd95d42308f0a6c66489b624/src/build/buildApp.js#L13-L62
|
train
|
jiahaog/nativefier
|
src/helpers/convertToIcns.js
|
convertToIcnsTmp
|
function convertToIcnsTmp(pngSrc, callback) {
const tempIconDirObj = tmp.dirSync({ unsafeCleanup: true });
const tempIconDirPath = tempIconDirObj.name;
convertToIcns(pngSrc, `${tempIconDirPath}/icon.icns`, callback);
}
|
javascript
|
function convertToIcnsTmp(pngSrc, callback) {
const tempIconDirObj = tmp.dirSync({ unsafeCleanup: true });
const tempIconDirPath = tempIconDirObj.name;
convertToIcns(pngSrc, `${tempIconDirPath}/icon.icns`, callback);
}
|
[
"function",
"convertToIcnsTmp",
"(",
"pngSrc",
",",
"callback",
")",
"{",
"const",
"tempIconDirObj",
"=",
"tmp",
".",
"dirSync",
"(",
"{",
"unsafeCleanup",
":",
"true",
"}",
")",
";",
"const",
"tempIconDirPath",
"=",
"tempIconDirObj",
".",
"name",
";",
"convertToIcns",
"(",
"pngSrc",
",",
"`",
"${",
"tempIconDirPath",
"}",
"`",
",",
"callback",
")",
";",
"}"
] |
Converts the png to a temporary directory which will be cleaned up on process exit
@param {string} pngSrc
@param {pngToIcnsCallback} callback
|
[
"Converts",
"the",
"png",
"to",
"a",
"temporary",
"directory",
"which",
"will",
"be",
"cleaned",
"up",
"on",
"process",
"exit"
] |
b959956a38ce51a9dd95d42308f0a6c66489b624
|
https://github.com/jiahaog/nativefier/blob/b959956a38ce51a9dd95d42308f0a6c66489b624/src/helpers/convertToIcns.js#L59-L63
|
train
|
jiahaog/nativefier
|
app/src/helpers/helpers.js
|
debugLog
|
function debugLog(browserWindow, message) {
// need the timeout as it takes time for the preload javascript to be loaded in the window
setTimeout(() => {
browserWindow.webContents.send('debug', message);
}, 3000);
log.info(message);
}
|
javascript
|
function debugLog(browserWindow, message) {
// need the timeout as it takes time for the preload javascript to be loaded in the window
setTimeout(() => {
browserWindow.webContents.send('debug', message);
}, 3000);
log.info(message);
}
|
[
"function",
"debugLog",
"(",
"browserWindow",
",",
"message",
")",
"{",
"setTimeout",
"(",
"(",
")",
"=>",
"{",
"browserWindow",
".",
"webContents",
".",
"send",
"(",
"'debug'",
",",
"message",
")",
";",
"}",
",",
"3000",
")",
";",
"log",
".",
"info",
"(",
"message",
")",
";",
"}"
] |
Helper method to print debug messages from the main process in the browser window
@param {BrowserWindow} browserWindow
@param message
|
[
"Helper",
"method",
"to",
"print",
"debug",
"messages",
"from",
"the",
"main",
"process",
"in",
"the",
"browser",
"window"
] |
b959956a38ce51a9dd95d42308f0a6c66489b624
|
https://github.com/jiahaog/nativefier/blob/b959956a38ce51a9dd95d42308f0a6c66489b624/app/src/helpers/helpers.js#L54-L60
|
train
|
codemirror/CodeMirror
|
src/display/update_display.js
|
patchDisplay
|
function patchDisplay(cm, updateNumbersFrom, dims) {
let display = cm.display, lineNumbers = cm.options.lineNumbers
let container = display.lineDiv, cur = container.firstChild
function rm(node) {
let next = node.nextSibling
// Works around a throw-scroll bug in OS X Webkit
if (webkit && mac && cm.display.currentWheelTarget == node)
node.style.display = "none"
else
node.parentNode.removeChild(node)
return next
}
let view = display.view, lineN = display.viewFrom
// Loop over the elements in the view, syncing cur (the DOM nodes
// in display.lineDiv) with the view as we go.
for (let i = 0; i < view.length; i++) {
let lineView = view[i]
if (lineView.hidden) {
} else if (!lineView.node || lineView.node.parentNode != container) { // Not drawn yet
let node = buildLineElement(cm, lineView, lineN, dims)
container.insertBefore(node, cur)
} else { // Already drawn
while (cur != lineView.node) cur = rm(cur)
let updateNumber = lineNumbers && updateNumbersFrom != null &&
updateNumbersFrom <= lineN && lineView.lineNumber
if (lineView.changes) {
if (indexOf(lineView.changes, "gutter") > -1) updateNumber = false
updateLineForChanges(cm, lineView, lineN, dims)
}
if (updateNumber) {
removeChildren(lineView.lineNumber)
lineView.lineNumber.appendChild(document.createTextNode(lineNumberFor(cm.options, lineN)))
}
cur = lineView.node.nextSibling
}
lineN += lineView.size
}
while (cur) cur = rm(cur)
}
|
javascript
|
function patchDisplay(cm, updateNumbersFrom, dims) {
let display = cm.display, lineNumbers = cm.options.lineNumbers
let container = display.lineDiv, cur = container.firstChild
function rm(node) {
let next = node.nextSibling
// Works around a throw-scroll bug in OS X Webkit
if (webkit && mac && cm.display.currentWheelTarget == node)
node.style.display = "none"
else
node.parentNode.removeChild(node)
return next
}
let view = display.view, lineN = display.viewFrom
// Loop over the elements in the view, syncing cur (the DOM nodes
// in display.lineDiv) with the view as we go.
for (let i = 0; i < view.length; i++) {
let lineView = view[i]
if (lineView.hidden) {
} else if (!lineView.node || lineView.node.parentNode != container) { // Not drawn yet
let node = buildLineElement(cm, lineView, lineN, dims)
container.insertBefore(node, cur)
} else { // Already drawn
while (cur != lineView.node) cur = rm(cur)
let updateNumber = lineNumbers && updateNumbersFrom != null &&
updateNumbersFrom <= lineN && lineView.lineNumber
if (lineView.changes) {
if (indexOf(lineView.changes, "gutter") > -1) updateNumber = false
updateLineForChanges(cm, lineView, lineN, dims)
}
if (updateNumber) {
removeChildren(lineView.lineNumber)
lineView.lineNumber.appendChild(document.createTextNode(lineNumberFor(cm.options, lineN)))
}
cur = lineView.node.nextSibling
}
lineN += lineView.size
}
while (cur) cur = rm(cur)
}
|
[
"function",
"patchDisplay",
"(",
"cm",
",",
"updateNumbersFrom",
",",
"dims",
")",
"{",
"let",
"display",
"=",
"cm",
".",
"display",
",",
"lineNumbers",
"=",
"cm",
".",
"options",
".",
"lineNumbers",
"let",
"container",
"=",
"display",
".",
"lineDiv",
",",
"cur",
"=",
"container",
".",
"firstChild",
"function",
"rm",
"(",
"node",
")",
"{",
"let",
"next",
"=",
"node",
".",
"nextSibling",
"if",
"(",
"webkit",
"&&",
"mac",
"&&",
"cm",
".",
"display",
".",
"currentWheelTarget",
"==",
"node",
")",
"node",
".",
"style",
".",
"display",
"=",
"\"none\"",
"else",
"node",
".",
"parentNode",
".",
"removeChild",
"(",
"node",
")",
"return",
"next",
"}",
"let",
"view",
"=",
"display",
".",
"view",
",",
"lineN",
"=",
"display",
".",
"viewFrom",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"view",
".",
"length",
";",
"i",
"++",
")",
"{",
"let",
"lineView",
"=",
"view",
"[",
"i",
"]",
"if",
"(",
"lineView",
".",
"hidden",
")",
"{",
"}",
"else",
"if",
"(",
"!",
"lineView",
".",
"node",
"||",
"lineView",
".",
"node",
".",
"parentNode",
"!=",
"container",
")",
"{",
"let",
"node",
"=",
"buildLineElement",
"(",
"cm",
",",
"lineView",
",",
"lineN",
",",
"dims",
")",
"container",
".",
"insertBefore",
"(",
"node",
",",
"cur",
")",
"}",
"else",
"{",
"while",
"(",
"cur",
"!=",
"lineView",
".",
"node",
")",
"cur",
"=",
"rm",
"(",
"cur",
")",
"let",
"updateNumber",
"=",
"lineNumbers",
"&&",
"updateNumbersFrom",
"!=",
"null",
"&&",
"updateNumbersFrom",
"<=",
"lineN",
"&&",
"lineView",
".",
"lineNumber",
"if",
"(",
"lineView",
".",
"changes",
")",
"{",
"if",
"(",
"indexOf",
"(",
"lineView",
".",
"changes",
",",
"\"gutter\"",
")",
">",
"-",
"1",
")",
"updateNumber",
"=",
"false",
"updateLineForChanges",
"(",
"cm",
",",
"lineView",
",",
"lineN",
",",
"dims",
")",
"}",
"if",
"(",
"updateNumber",
")",
"{",
"removeChildren",
"(",
"lineView",
".",
"lineNumber",
")",
"lineView",
".",
"lineNumber",
".",
"appendChild",
"(",
"document",
".",
"createTextNode",
"(",
"lineNumberFor",
"(",
"cm",
".",
"options",
",",
"lineN",
")",
")",
")",
"}",
"cur",
"=",
"lineView",
".",
"node",
".",
"nextSibling",
"}",
"lineN",
"+=",
"lineView",
".",
"size",
"}",
"while",
"(",
"cur",
")",
"cur",
"=",
"rm",
"(",
"cur",
")",
"}"
] |
Sync the actual display DOM structure with display.view, removing nodes for lines that are no longer in view, and creating the ones that are not there yet, and updating the ones that are out of date.
|
[
"Sync",
"the",
"actual",
"display",
"DOM",
"structure",
"with",
"display",
".",
"view",
"removing",
"nodes",
"for",
"lines",
"that",
"are",
"no",
"longer",
"in",
"view",
"and",
"creating",
"the",
"ones",
"that",
"are",
"not",
"there",
"yet",
"and",
"updating",
"the",
"ones",
"that",
"are",
"out",
"of",
"date",
"."
] |
dab6f676107c10ba8d16c654a42f66cae3f27db1
|
https://github.com/codemirror/CodeMirror/blob/dab6f676107c10ba8d16c654a42f66cae3f27db1/src/display/update_display.js#L209-L249
|
train
|
codemirror/CodeMirror
|
src/model/selection_updates.js
|
skipAtomicInSelection
|
function skipAtomicInSelection(doc, sel, bias, mayClear) {
let out
for (let i = 0; i < sel.ranges.length; i++) {
let range = sel.ranges[i]
let old = sel.ranges.length == doc.sel.ranges.length && doc.sel.ranges[i]
let newAnchor = skipAtomic(doc, range.anchor, old && old.anchor, bias, mayClear)
let newHead = skipAtomic(doc, range.head, old && old.head, bias, mayClear)
if (out || newAnchor != range.anchor || newHead != range.head) {
if (!out) out = sel.ranges.slice(0, i)
out[i] = new Range(newAnchor, newHead)
}
}
return out ? normalizeSelection(doc.cm, out, sel.primIndex) : sel
}
|
javascript
|
function skipAtomicInSelection(doc, sel, bias, mayClear) {
let out
for (let i = 0; i < sel.ranges.length; i++) {
let range = sel.ranges[i]
let old = sel.ranges.length == doc.sel.ranges.length && doc.sel.ranges[i]
let newAnchor = skipAtomic(doc, range.anchor, old && old.anchor, bias, mayClear)
let newHead = skipAtomic(doc, range.head, old && old.head, bias, mayClear)
if (out || newAnchor != range.anchor || newHead != range.head) {
if (!out) out = sel.ranges.slice(0, i)
out[i] = new Range(newAnchor, newHead)
}
}
return out ? normalizeSelection(doc.cm, out, sel.primIndex) : sel
}
|
[
"function",
"skipAtomicInSelection",
"(",
"doc",
",",
"sel",
",",
"bias",
",",
"mayClear",
")",
"{",
"let",
"out",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"sel",
".",
"ranges",
".",
"length",
";",
"i",
"++",
")",
"{",
"let",
"range",
"=",
"sel",
".",
"ranges",
"[",
"i",
"]",
"let",
"old",
"=",
"sel",
".",
"ranges",
".",
"length",
"==",
"doc",
".",
"sel",
".",
"ranges",
".",
"length",
"&&",
"doc",
".",
"sel",
".",
"ranges",
"[",
"i",
"]",
"let",
"newAnchor",
"=",
"skipAtomic",
"(",
"doc",
",",
"range",
".",
"anchor",
",",
"old",
"&&",
"old",
".",
"anchor",
",",
"bias",
",",
"mayClear",
")",
"let",
"newHead",
"=",
"skipAtomic",
"(",
"doc",
",",
"range",
".",
"head",
",",
"old",
"&&",
"old",
".",
"head",
",",
"bias",
",",
"mayClear",
")",
"if",
"(",
"out",
"||",
"newAnchor",
"!=",
"range",
".",
"anchor",
"||",
"newHead",
"!=",
"range",
".",
"head",
")",
"{",
"if",
"(",
"!",
"out",
")",
"out",
"=",
"sel",
".",
"ranges",
".",
"slice",
"(",
"0",
",",
"i",
")",
"out",
"[",
"i",
"]",
"=",
"new",
"Range",
"(",
"newAnchor",
",",
"newHead",
")",
"}",
"}",
"return",
"out",
"?",
"normalizeSelection",
"(",
"doc",
".",
"cm",
",",
"out",
",",
"sel",
".",
"primIndex",
")",
":",
"sel",
"}"
] |
Return a selection that does not partially select any atomic ranges.
|
[
"Return",
"a",
"selection",
"that",
"does",
"not",
"partially",
"select",
"any",
"atomic",
"ranges",
"."
] |
dab6f676107c10ba8d16c654a42f66cae3f27db1
|
https://github.com/codemirror/CodeMirror/blob/dab6f676107c10ba8d16c654a42f66cae3f27db1/src/model/selection_updates.js#L134-L147
|
train
|
codemirror/CodeMirror
|
src/model/history.js
|
lastChangeEvent
|
function lastChangeEvent(hist, force) {
if (force) {
clearSelectionEvents(hist.done)
return lst(hist.done)
} else if (hist.done.length && !lst(hist.done).ranges) {
return lst(hist.done)
} else if (hist.done.length > 1 && !hist.done[hist.done.length - 2].ranges) {
hist.done.pop()
return lst(hist.done)
}
}
|
javascript
|
function lastChangeEvent(hist, force) {
if (force) {
clearSelectionEvents(hist.done)
return lst(hist.done)
} else if (hist.done.length && !lst(hist.done).ranges) {
return lst(hist.done)
} else if (hist.done.length > 1 && !hist.done[hist.done.length - 2].ranges) {
hist.done.pop()
return lst(hist.done)
}
}
|
[
"function",
"lastChangeEvent",
"(",
"hist",
",",
"force",
")",
"{",
"if",
"(",
"force",
")",
"{",
"clearSelectionEvents",
"(",
"hist",
".",
"done",
")",
"return",
"lst",
"(",
"hist",
".",
"done",
")",
"}",
"else",
"if",
"(",
"hist",
".",
"done",
".",
"length",
"&&",
"!",
"lst",
"(",
"hist",
".",
"done",
")",
".",
"ranges",
")",
"{",
"return",
"lst",
"(",
"hist",
".",
"done",
")",
"}",
"else",
"if",
"(",
"hist",
".",
"done",
".",
"length",
">",
"1",
"&&",
"!",
"hist",
".",
"done",
"[",
"hist",
".",
"done",
".",
"length",
"-",
"2",
"]",
".",
"ranges",
")",
"{",
"hist",
".",
"done",
".",
"pop",
"(",
")",
"return",
"lst",
"(",
"hist",
".",
"done",
")",
"}",
"}"
] |
Find the top change event in the history. Pop off selection events that are in the way.
|
[
"Find",
"the",
"top",
"change",
"event",
"in",
"the",
"history",
".",
"Pop",
"off",
"selection",
"events",
"that",
"are",
"in",
"the",
"way",
"."
] |
dab6f676107c10ba8d16c654a42f66cae3f27db1
|
https://github.com/codemirror/CodeMirror/blob/dab6f676107c10ba8d16c654a42f66cae3f27db1/src/model/history.js#L47-L57
|
train
|
codemirror/CodeMirror
|
src/model/history.js
|
getOldSpans
|
function getOldSpans(doc, change) {
let found = change["spans_" + doc.id]
if (!found) return null
let nw = []
for (let i = 0; i < change.text.length; ++i)
nw.push(removeClearedSpans(found[i]))
return nw
}
|
javascript
|
function getOldSpans(doc, change) {
let found = change["spans_" + doc.id]
if (!found) return null
let nw = []
for (let i = 0; i < change.text.length; ++i)
nw.push(removeClearedSpans(found[i]))
return nw
}
|
[
"function",
"getOldSpans",
"(",
"doc",
",",
"change",
")",
"{",
"let",
"found",
"=",
"change",
"[",
"\"spans_\"",
"+",
"doc",
".",
"id",
"]",
"if",
"(",
"!",
"found",
")",
"return",
"null",
"let",
"nw",
"=",
"[",
"]",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"change",
".",
"text",
".",
"length",
";",
"++",
"i",
")",
"nw",
".",
"push",
"(",
"removeClearedSpans",
"(",
"found",
"[",
"i",
"]",
")",
")",
"return",
"nw",
"}"
] |
Retrieve and filter the old marked spans stored in a change event.
|
[
"Retrieve",
"and",
"filter",
"the",
"old",
"marked",
"spans",
"stored",
"in",
"a",
"change",
"event",
"."
] |
dab6f676107c10ba8d16c654a42f66cae3f27db1
|
https://github.com/codemirror/CodeMirror/blob/dab6f676107c10ba8d16c654a42f66cae3f27db1/src/model/history.js#L169-L176
|
train
|
codemirror/CodeMirror
|
src/edit/key_events.js
|
handleKeyBinding
|
function handleKeyBinding(cm, e) {
let name = keyName(e, true)
if (!name) return false
if (e.shiftKey && !cm.state.keySeq) {
// First try to resolve full name (including 'Shift-'). Failing
// that, see if there is a cursor-motion command (starting with
// 'go') bound to the keyname without 'Shift-'.
return dispatchKey(cm, "Shift-" + name, e, b => doHandleBinding(cm, b, true))
|| dispatchKey(cm, name, e, b => {
if (typeof b == "string" ? /^go[A-Z]/.test(b) : b.motion)
return doHandleBinding(cm, b)
})
} else {
return dispatchKey(cm, name, e, b => doHandleBinding(cm, b))
}
}
|
javascript
|
function handleKeyBinding(cm, e) {
let name = keyName(e, true)
if (!name) return false
if (e.shiftKey && !cm.state.keySeq) {
// First try to resolve full name (including 'Shift-'). Failing
// that, see if there is a cursor-motion command (starting with
// 'go') bound to the keyname without 'Shift-'.
return dispatchKey(cm, "Shift-" + name, e, b => doHandleBinding(cm, b, true))
|| dispatchKey(cm, name, e, b => {
if (typeof b == "string" ? /^go[A-Z]/.test(b) : b.motion)
return doHandleBinding(cm, b)
})
} else {
return dispatchKey(cm, name, e, b => doHandleBinding(cm, b))
}
}
|
[
"function",
"handleKeyBinding",
"(",
"cm",
",",
"e",
")",
"{",
"let",
"name",
"=",
"keyName",
"(",
"e",
",",
"true",
")",
"if",
"(",
"!",
"name",
")",
"return",
"false",
"if",
"(",
"e",
".",
"shiftKey",
"&&",
"!",
"cm",
".",
"state",
".",
"keySeq",
")",
"{",
"return",
"dispatchKey",
"(",
"cm",
",",
"\"Shift-\"",
"+",
"name",
",",
"e",
",",
"b",
"=>",
"doHandleBinding",
"(",
"cm",
",",
"b",
",",
"true",
")",
")",
"||",
"dispatchKey",
"(",
"cm",
",",
"name",
",",
"e",
",",
"b",
"=>",
"{",
"if",
"(",
"typeof",
"b",
"==",
"\"string\"",
"?",
"/",
"^go[A-Z]",
"/",
".",
"test",
"(",
"b",
")",
":",
"b",
".",
"motion",
")",
"return",
"doHandleBinding",
"(",
"cm",
",",
"b",
")",
"}",
")",
"}",
"else",
"{",
"return",
"dispatchKey",
"(",
"cm",
",",
"name",
",",
"e",
",",
"b",
"=>",
"doHandleBinding",
"(",
"cm",
",",
"b",
")",
")",
"}",
"}"
] |
Handle a key from the keydown event.
|
[
"Handle",
"a",
"key",
"from",
"the",
"keydown",
"event",
"."
] |
dab6f676107c10ba8d16c654a42f66cae3f27db1
|
https://github.com/codemirror/CodeMirror/blob/dab6f676107c10ba8d16c654a42f66cae3f27db1/src/edit/key_events.js#L83-L99
|
train
|
codemirror/CodeMirror
|
src/edit/key_events.js
|
handleCharBinding
|
function handleCharBinding(cm, e, ch) {
return dispatchKey(cm, "'" + ch + "'", e, b => doHandleBinding(cm, b, true))
}
|
javascript
|
function handleCharBinding(cm, e, ch) {
return dispatchKey(cm, "'" + ch + "'", e, b => doHandleBinding(cm, b, true))
}
|
[
"function",
"handleCharBinding",
"(",
"cm",
",",
"e",
",",
"ch",
")",
"{",
"return",
"dispatchKey",
"(",
"cm",
",",
"\"'\"",
"+",
"ch",
"+",
"\"'\"",
",",
"e",
",",
"b",
"=>",
"doHandleBinding",
"(",
"cm",
",",
"b",
",",
"true",
")",
")",
"}"
] |
Handle a key from the keypress event
|
[
"Handle",
"a",
"key",
"from",
"the",
"keypress",
"event"
] |
dab6f676107c10ba8d16c654a42f66cae3f27db1
|
https://github.com/codemirror/CodeMirror/blob/dab6f676107c10ba8d16c654a42f66cae3f27db1/src/edit/key_events.js#L102-L104
|
train
|
codemirror/CodeMirror
|
src/measurement/position_measurement.js
|
boxIsAfter
|
function boxIsAfter(box, x, y, left) {
return box.bottom <= y ? false : box.top > y ? true : (left ? box.left : box.right) > x
}
|
javascript
|
function boxIsAfter(box, x, y, left) {
return box.bottom <= y ? false : box.top > y ? true : (left ? box.left : box.right) > x
}
|
[
"function",
"boxIsAfter",
"(",
"box",
",",
"x",
",",
"y",
",",
"left",
")",
"{",
"return",
"box",
".",
"bottom",
"<=",
"y",
"?",
"false",
":",
"box",
".",
"top",
">",
"y",
"?",
"true",
":",
"(",
"left",
"?",
"box",
".",
"left",
":",
"box",
".",
"right",
")",
">",
"x",
"}"
] |
Returns true if the given side of a box is after the given coordinates, in top-to-bottom, left-to-right order.
|
[
"Returns",
"true",
"if",
"the",
"given",
"side",
"of",
"a",
"box",
"is",
"after",
"the",
"given",
"coordinates",
"in",
"top",
"-",
"to",
"-",
"bottom",
"left",
"-",
"to",
"-",
"right",
"order",
"."
] |
dab6f676107c10ba8d16c654a42f66cae3f27db1
|
https://github.com/codemirror/CodeMirror/blob/dab6f676107c10ba8d16c654a42f66cae3f27db1/src/measurement/position_measurement.js#L457-L459
|
train
|
codemirror/CodeMirror
|
src/line/highlight.js
|
runMode
|
function runMode(cm, text, mode, context, f, lineClasses, forceToEnd) {
let flattenSpans = mode.flattenSpans
if (flattenSpans == null) flattenSpans = cm.options.flattenSpans
let curStart = 0, curStyle = null
let stream = new StringStream(text, cm.options.tabSize, context), style
let inner = cm.options.addModeClass && [null]
if (text == "") extractLineClasses(callBlankLine(mode, context.state), lineClasses)
while (!stream.eol()) {
if (stream.pos > cm.options.maxHighlightLength) {
flattenSpans = false
if (forceToEnd) processLine(cm, text, context, stream.pos)
stream.pos = text.length
style = null
} else {
style = extractLineClasses(readToken(mode, stream, context.state, inner), lineClasses)
}
if (inner) {
let mName = inner[0].name
if (mName) style = "m-" + (style ? mName + " " + style : mName)
}
if (!flattenSpans || curStyle != style) {
while (curStart < stream.start) {
curStart = Math.min(stream.start, curStart + 5000)
f(curStart, curStyle)
}
curStyle = style
}
stream.start = stream.pos
}
while (curStart < stream.pos) {
// Webkit seems to refuse to render text nodes longer than 57444
// characters, and returns inaccurate measurements in nodes
// starting around 5000 chars.
let pos = Math.min(stream.pos, curStart + 5000)
f(pos, curStyle)
curStart = pos
}
}
|
javascript
|
function runMode(cm, text, mode, context, f, lineClasses, forceToEnd) {
let flattenSpans = mode.flattenSpans
if (flattenSpans == null) flattenSpans = cm.options.flattenSpans
let curStart = 0, curStyle = null
let stream = new StringStream(text, cm.options.tabSize, context), style
let inner = cm.options.addModeClass && [null]
if (text == "") extractLineClasses(callBlankLine(mode, context.state), lineClasses)
while (!stream.eol()) {
if (stream.pos > cm.options.maxHighlightLength) {
flattenSpans = false
if (forceToEnd) processLine(cm, text, context, stream.pos)
stream.pos = text.length
style = null
} else {
style = extractLineClasses(readToken(mode, stream, context.state, inner), lineClasses)
}
if (inner) {
let mName = inner[0].name
if (mName) style = "m-" + (style ? mName + " " + style : mName)
}
if (!flattenSpans || curStyle != style) {
while (curStart < stream.start) {
curStart = Math.min(stream.start, curStart + 5000)
f(curStart, curStyle)
}
curStyle = style
}
stream.start = stream.pos
}
while (curStart < stream.pos) {
// Webkit seems to refuse to render text nodes longer than 57444
// characters, and returns inaccurate measurements in nodes
// starting around 5000 chars.
let pos = Math.min(stream.pos, curStart + 5000)
f(pos, curStyle)
curStart = pos
}
}
|
[
"function",
"runMode",
"(",
"cm",
",",
"text",
",",
"mode",
",",
"context",
",",
"f",
",",
"lineClasses",
",",
"forceToEnd",
")",
"{",
"let",
"flattenSpans",
"=",
"mode",
".",
"flattenSpans",
"if",
"(",
"flattenSpans",
"==",
"null",
")",
"flattenSpans",
"=",
"cm",
".",
"options",
".",
"flattenSpans",
"let",
"curStart",
"=",
"0",
",",
"curStyle",
"=",
"null",
"let",
"stream",
"=",
"new",
"StringStream",
"(",
"text",
",",
"cm",
".",
"options",
".",
"tabSize",
",",
"context",
")",
",",
"style",
"let",
"inner",
"=",
"cm",
".",
"options",
".",
"addModeClass",
"&&",
"[",
"null",
"]",
"if",
"(",
"text",
"==",
"\"\"",
")",
"extractLineClasses",
"(",
"callBlankLine",
"(",
"mode",
",",
"context",
".",
"state",
")",
",",
"lineClasses",
")",
"while",
"(",
"!",
"stream",
".",
"eol",
"(",
")",
")",
"{",
"if",
"(",
"stream",
".",
"pos",
">",
"cm",
".",
"options",
".",
"maxHighlightLength",
")",
"{",
"flattenSpans",
"=",
"false",
"if",
"(",
"forceToEnd",
")",
"processLine",
"(",
"cm",
",",
"text",
",",
"context",
",",
"stream",
".",
"pos",
")",
"stream",
".",
"pos",
"=",
"text",
".",
"length",
"style",
"=",
"null",
"}",
"else",
"{",
"style",
"=",
"extractLineClasses",
"(",
"readToken",
"(",
"mode",
",",
"stream",
",",
"context",
".",
"state",
",",
"inner",
")",
",",
"lineClasses",
")",
"}",
"if",
"(",
"inner",
")",
"{",
"let",
"mName",
"=",
"inner",
"[",
"0",
"]",
".",
"name",
"if",
"(",
"mName",
")",
"style",
"=",
"\"m-\"",
"+",
"(",
"style",
"?",
"mName",
"+",
"\" \"",
"+",
"style",
":",
"mName",
")",
"}",
"if",
"(",
"!",
"flattenSpans",
"||",
"curStyle",
"!=",
"style",
")",
"{",
"while",
"(",
"curStart",
"<",
"stream",
".",
"start",
")",
"{",
"curStart",
"=",
"Math",
".",
"min",
"(",
"stream",
".",
"start",
",",
"curStart",
"+",
"5000",
")",
"f",
"(",
"curStart",
",",
"curStyle",
")",
"}",
"curStyle",
"=",
"style",
"}",
"stream",
".",
"start",
"=",
"stream",
".",
"pos",
"}",
"while",
"(",
"curStart",
"<",
"stream",
".",
"pos",
")",
"{",
"let",
"pos",
"=",
"Math",
".",
"min",
"(",
"stream",
".",
"pos",
",",
"curStart",
"+",
"5000",
")",
"f",
"(",
"pos",
",",
"curStyle",
")",
"curStart",
"=",
"pos",
"}",
"}"
] |
Run the given mode's parser over a line, calling f for each token.
|
[
"Run",
"the",
"given",
"mode",
"s",
"parser",
"over",
"a",
"line",
"calling",
"f",
"for",
"each",
"token",
"."
] |
dab6f676107c10ba8d16c654a42f66cae3f27db1
|
https://github.com/codemirror/CodeMirror/blob/dab6f676107c10ba8d16c654a42f66cae3f27db1/src/line/highlight.js#L208-L245
|
train
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.