id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
list | docstring
stringlengths 4
11.8k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 86
226
|
|---|---|---|---|---|---|---|---|---|---|---|---|
11,600
|
SAP/chevrotain
|
examples/grammars/tinyc/tinyc.js
|
createToken
|
function createToken(options) {
const newToken = chevrotain.createToken(options)
allTokens.push(newToken)
return newToken
}
|
javascript
|
function createToken(options) {
const newToken = chevrotain.createToken(options)
allTokens.push(newToken)
return newToken
}
|
[
"function",
"createToken",
"(",
"options",
")",
"{",
"const",
"newToken",
"=",
"chevrotain",
".",
"createToken",
"(",
"options",
")",
"allTokens",
".",
"push",
"(",
"newToken",
")",
"return",
"newToken",
"}"
] |
Utility to avoid manually building the allTokens array
|
[
"Utility",
"to",
"avoid",
"manually",
"building",
"the",
"allTokens",
"array"
] |
1ffe6c74590af8af037dc638d787602571a10a0e
|
https://github.com/SAP/chevrotain/blob/1ffe6c74590af8af037dc638d787602571a10a0e/examples/grammars/tinyc/tinyc.js#L13-L17
|
11,601
|
SAP/chevrotain
|
examples/tutorial/tutorial_spec.js
|
minimizeCst
|
function minimizeCst(cstElement) {
// tokenType idx is auto generated, can't assert over it
if (cstElement.tokenType) {
delete cstElement.tokenType
}
// CstNode
if (cstElement.children !== undefined) {
cstElement.children = _.omitBy(cstElement.children, _.isEmpty)
_.forEach(cstElement.children, childArr => {
_.forEach(childArr, minimizeCst)
})
}
return cstElement
}
|
javascript
|
function minimizeCst(cstElement) {
// tokenType idx is auto generated, can't assert over it
if (cstElement.tokenType) {
delete cstElement.tokenType
}
// CstNode
if (cstElement.children !== undefined) {
cstElement.children = _.omitBy(cstElement.children, _.isEmpty)
_.forEach(cstElement.children, childArr => {
_.forEach(childArr, minimizeCst)
})
}
return cstElement
}
|
[
"function",
"minimizeCst",
"(",
"cstElement",
")",
"{",
"// tokenType idx is auto generated, can't assert over it",
"if",
"(",
"cstElement",
".",
"tokenType",
")",
"{",
"delete",
"cstElement",
".",
"tokenType",
"}",
"// CstNode",
"if",
"(",
"cstElement",
".",
"children",
"!==",
"undefined",
")",
"{",
"cstElement",
".",
"children",
"=",
"_",
".",
"omitBy",
"(",
"cstElement",
".",
"children",
",",
"_",
".",
"isEmpty",
")",
"_",
".",
"forEach",
"(",
"cstElement",
".",
"children",
",",
"childArr",
"=>",
"{",
"_",
".",
"forEach",
"(",
"childArr",
",",
"minimizeCst",
")",
"}",
")",
"}",
"return",
"cstElement",
"}"
] |
to make it easier to understand the assertions
|
[
"to",
"make",
"it",
"easier",
"to",
"understand",
"the",
"assertions"
] |
1ffe6c74590af8af037dc638d787602571a10a0e
|
https://github.com/SAP/chevrotain/blob/1ffe6c74590af8af037dc638d787602571a10a0e/examples/tutorial/tutorial_spec.js#L115-L130
|
11,602
|
SAP/chevrotain
|
examples/custom_apis/combinator/combinator_api.js
|
toOriginalText
|
function toOriginalText(item) {
if (_.has(item, "tokenName")) {
return item.tokenName
} else if (item instanceof Rule) {
return item.name
} else if (_.isString(item)) {
return item
} else if (_.has(item, "toRule")) {
return item.definition.orgText
} else {
throw Error(`Unexpected Argument type ${item}`)
}
}
|
javascript
|
function toOriginalText(item) {
if (_.has(item, "tokenName")) {
return item.tokenName
} else if (item instanceof Rule) {
return item.name
} else if (_.isString(item)) {
return item
} else if (_.has(item, "toRule")) {
return item.definition.orgText
} else {
throw Error(`Unexpected Argument type ${item}`)
}
}
|
[
"function",
"toOriginalText",
"(",
"item",
")",
"{",
"if",
"(",
"_",
".",
"has",
"(",
"item",
",",
"\"tokenName\"",
")",
")",
"{",
"return",
"item",
".",
"tokenName",
"}",
"else",
"if",
"(",
"item",
"instanceof",
"Rule",
")",
"{",
"return",
"item",
".",
"name",
"}",
"else",
"if",
"(",
"_",
".",
"isString",
"(",
"item",
")",
")",
"{",
"return",
"item",
"}",
"else",
"if",
"(",
"_",
".",
"has",
"(",
"item",
",",
"\"toRule\"",
")",
")",
"{",
"return",
"item",
".",
"definition",
".",
"orgText",
"}",
"else",
"{",
"throw",
"Error",
"(",
"`",
"${",
"item",
"}",
"`",
")",
"}",
"}"
] |
Attempts to reconstruct the original api usage text
for better error message purposes.
|
[
"Attempts",
"to",
"reconstruct",
"the",
"original",
"api",
"usage",
"text",
"for",
"better",
"error",
"message",
"purposes",
"."
] |
1ffe6c74590af8af037dc638d787602571a10a0e
|
https://github.com/SAP/chevrotain/blob/1ffe6c74590af8af037dc638d787602571a10a0e/examples/custom_apis/combinator/combinator_api.js#L150-L162
|
11,603
|
d3/d3-hierarchy
|
src/tree.js
|
nextRight
|
function nextRight(v) {
var children = v.children;
return children ? children[children.length - 1] : v.t;
}
|
javascript
|
function nextRight(v) {
var children = v.children;
return children ? children[children.length - 1] : v.t;
}
|
[
"function",
"nextRight",
"(",
"v",
")",
"{",
"var",
"children",
"=",
"v",
".",
"children",
";",
"return",
"children",
"?",
"children",
"[",
"children",
".",
"length",
"-",
"1",
"]",
":",
"v",
".",
"t",
";",
"}"
] |
This function works analogously to nextLeft.
|
[
"This",
"function",
"works",
"analogously",
"to",
"nextLeft",
"."
] |
7d22381f87ac7e28ff58f725e70f0a40f5b1c625
|
https://github.com/d3/d3-hierarchy/blob/7d22381f87ac7e28ff58f725e70f0a40f5b1c625/src/tree.js#L21-L24
|
11,604
|
d3/d3-hierarchy
|
src/tree.js
|
firstWalk
|
function firstWalk(v) {
var children = v.children,
siblings = v.parent.children,
w = v.i ? siblings[v.i - 1] : null;
if (children) {
executeShifts(v);
var midpoint = (children[0].z + children[children.length - 1].z) / 2;
if (w) {
v.z = w.z + separation(v._, w._);
v.m = v.z - midpoint;
} else {
v.z = midpoint;
}
} else if (w) {
v.z = w.z + separation(v._, w._);
}
v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
}
|
javascript
|
function firstWalk(v) {
var children = v.children,
siblings = v.parent.children,
w = v.i ? siblings[v.i - 1] : null;
if (children) {
executeShifts(v);
var midpoint = (children[0].z + children[children.length - 1].z) / 2;
if (w) {
v.z = w.z + separation(v._, w._);
v.m = v.z - midpoint;
} else {
v.z = midpoint;
}
} else if (w) {
v.z = w.z + separation(v._, w._);
}
v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
}
|
[
"function",
"firstWalk",
"(",
"v",
")",
"{",
"var",
"children",
"=",
"v",
".",
"children",
",",
"siblings",
"=",
"v",
".",
"parent",
".",
"children",
",",
"w",
"=",
"v",
".",
"i",
"?",
"siblings",
"[",
"v",
".",
"i",
"-",
"1",
"]",
":",
"null",
";",
"if",
"(",
"children",
")",
"{",
"executeShifts",
"(",
"v",
")",
";",
"var",
"midpoint",
"=",
"(",
"children",
"[",
"0",
"]",
".",
"z",
"+",
"children",
"[",
"children",
".",
"length",
"-",
"1",
"]",
".",
"z",
")",
"/",
"2",
";",
"if",
"(",
"w",
")",
"{",
"v",
".",
"z",
"=",
"w",
".",
"z",
"+",
"separation",
"(",
"v",
".",
"_",
",",
"w",
".",
"_",
")",
";",
"v",
".",
"m",
"=",
"v",
".",
"z",
"-",
"midpoint",
";",
"}",
"else",
"{",
"v",
".",
"z",
"=",
"midpoint",
";",
"}",
"}",
"else",
"if",
"(",
"w",
")",
"{",
"v",
".",
"z",
"=",
"w",
".",
"z",
"+",
"separation",
"(",
"v",
".",
"_",
",",
"w",
".",
"_",
")",
";",
"}",
"v",
".",
"parent",
".",
"A",
"=",
"apportion",
"(",
"v",
",",
"w",
",",
"v",
".",
"parent",
".",
"A",
"||",
"siblings",
"[",
"0",
"]",
")",
";",
"}"
] |
Computes a preliminary x-coordinate for v. Before that, FIRST WALK is applied recursively to the children of v, as well as the function APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the node v is placed to the midpoint of its outermost children.
|
[
"Computes",
"a",
"preliminary",
"x",
"-",
"coordinate",
"for",
"v",
".",
"Before",
"that",
"FIRST",
"WALK",
"is",
"applied",
"recursively",
"to",
"the",
"children",
"of",
"v",
"as",
"well",
"as",
"the",
"function",
"APPORTION",
".",
"After",
"spacing",
"out",
"the",
"children",
"by",
"calling",
"EXECUTE",
"SHIFTS",
"the",
"node",
"v",
"is",
"placed",
"to",
"the",
"midpoint",
"of",
"its",
"outermost",
"children",
"."
] |
7d22381f87ac7e28ff58f725e70f0a40f5b1c625
|
https://github.com/d3/d3-hierarchy/blob/7d22381f87ac7e28ff58f725e70f0a40f5b1c625/src/tree.js#L144-L161
|
11,605
|
imsky/holder
|
holder.js
|
function(name, theme) {
name != null && theme != null && (App.settings.themes[name] = theme);
delete App.vars.cache.themeKeys;
return this;
}
|
javascript
|
function(name, theme) {
name != null && theme != null && (App.settings.themes[name] = theme);
delete App.vars.cache.themeKeys;
return this;
}
|
[
"function",
"(",
"name",
",",
"theme",
")",
"{",
"name",
"!=",
"null",
"&&",
"theme",
"!=",
"null",
"&&",
"(",
"App",
".",
"settings",
".",
"themes",
"[",
"name",
"]",
"=",
"theme",
")",
";",
"delete",
"App",
".",
"vars",
".",
"cache",
".",
"themeKeys",
";",
"return",
"this",
";",
"}"
] |
Adds a theme to default settings
@param {string} name Theme name
@param {Object} theme Theme object, with foreground, background, size, font, and fontweight properties.
|
[
"Adds",
"a",
"theme",
"to",
"default",
"settings"
] |
220827ebe4097b9a76f150590f8bdf521803aba8
|
https://github.com/imsky/holder/blob/220827ebe4097b9a76f150590f8bdf521803aba8/holder.js#L349-L353
|
|
11,606
|
imsky/holder
|
holder.js
|
function(src, el) {
//todo: use jquery fallback if available for all QSA references
var nodes = DOM.getNodeArray(el);
nodes.forEach(function (node) {
var img = DOM.newEl('img');
var domProps = {};
domProps[App.setup.dataAttr] = src;
DOM.setAttr(img, domProps);
node.appendChild(img);
});
return this;
}
|
javascript
|
function(src, el) {
//todo: use jquery fallback if available for all QSA references
var nodes = DOM.getNodeArray(el);
nodes.forEach(function (node) {
var img = DOM.newEl('img');
var domProps = {};
domProps[App.setup.dataAttr] = src;
DOM.setAttr(img, domProps);
node.appendChild(img);
});
return this;
}
|
[
"function",
"(",
"src",
",",
"el",
")",
"{",
"//todo: use jquery fallback if available for all QSA references",
"var",
"nodes",
"=",
"DOM",
".",
"getNodeArray",
"(",
"el",
")",
";",
"nodes",
".",
"forEach",
"(",
"function",
"(",
"node",
")",
"{",
"var",
"img",
"=",
"DOM",
".",
"newEl",
"(",
"'img'",
")",
";",
"var",
"domProps",
"=",
"{",
"}",
";",
"domProps",
"[",
"App",
".",
"setup",
".",
"dataAttr",
"]",
"=",
"src",
";",
"DOM",
".",
"setAttr",
"(",
"img",
",",
"domProps",
")",
";",
"node",
".",
"appendChild",
"(",
"img",
")",
";",
"}",
")",
";",
"return",
"this",
";",
"}"
] |
Appends a placeholder to an element
@param {string} src Placeholder URL string
@param el A selector or a reference to a DOM node
|
[
"Appends",
"a",
"placeholder",
"to",
"an",
"element"
] |
220827ebe4097b9a76f150590f8bdf521803aba8
|
https://github.com/imsky/holder/blob/220827ebe4097b9a76f150590f8bdf521803aba8/holder.js#L361-L372
|
|
11,607
|
imsky/holder
|
holder.js
|
function(el, value) {
if (el.holderData) {
el.holderData.resizeUpdate = !!value;
if (el.holderData.resizeUpdate) {
updateResizableElements(el);
}
}
}
|
javascript
|
function(el, value) {
if (el.holderData) {
el.holderData.resizeUpdate = !!value;
if (el.holderData.resizeUpdate) {
updateResizableElements(el);
}
}
}
|
[
"function",
"(",
"el",
",",
"value",
")",
"{",
"if",
"(",
"el",
".",
"holderData",
")",
"{",
"el",
".",
"holderData",
".",
"resizeUpdate",
"=",
"!",
"!",
"value",
";",
"if",
"(",
"el",
".",
"holderData",
".",
"resizeUpdate",
")",
"{",
"updateResizableElements",
"(",
"el",
")",
";",
"}",
"}",
"}"
] |
Sets whether or not an image is updated on resize.
If an image is set to be updated, it is immediately rendered.
@param {Object} el Image DOM element
@param {Boolean} value Resizable update flag value
|
[
"Sets",
"whether",
"or",
"not",
"an",
"image",
"is",
"updated",
"on",
"resize",
".",
"If",
"an",
"image",
"is",
"set",
"to",
"be",
"updated",
"it",
"is",
"immediately",
"rendered",
"."
] |
220827ebe4097b9a76f150590f8bdf521803aba8
|
https://github.com/imsky/holder/blob/220827ebe4097b9a76f150590f8bdf521803aba8/holder.js#L381-L388
|
|
11,608
|
imsky/holder
|
holder.js
|
prepareImageElement
|
function prepareImageElement(options, engineSettings, src, el) {
var holderFlags = parseURL(src.substr(src.lastIndexOf(options.domain)), options);
if (holderFlags) {
prepareDOMElement({
mode: null,
el: el,
flags: holderFlags,
engineSettings: engineSettings
});
}
}
|
javascript
|
function prepareImageElement(options, engineSettings, src, el) {
var holderFlags = parseURL(src.substr(src.lastIndexOf(options.domain)), options);
if (holderFlags) {
prepareDOMElement({
mode: null,
el: el,
flags: holderFlags,
engineSettings: engineSettings
});
}
}
|
[
"function",
"prepareImageElement",
"(",
"options",
",",
"engineSettings",
",",
"src",
",",
"el",
")",
"{",
"var",
"holderFlags",
"=",
"parseURL",
"(",
"src",
".",
"substr",
"(",
"src",
".",
"lastIndexOf",
"(",
"options",
".",
"domain",
")",
")",
",",
"options",
")",
";",
"if",
"(",
"holderFlags",
")",
"{",
"prepareDOMElement",
"(",
"{",
"mode",
":",
"null",
",",
"el",
":",
"el",
",",
"flags",
":",
"holderFlags",
",",
"engineSettings",
":",
"engineSettings",
"}",
")",
";",
"}",
"}"
] |
Processes provided source attribute and sets up the appropriate rendering workflow
@private
@param options Instance options from Holder.run
@param renderSettings Instance configuration
@param src Image URL
@param el Image DOM element
|
[
"Processes",
"provided",
"source",
"attribute",
"and",
"sets",
"up",
"the",
"appropriate",
"rendering",
"workflow"
] |
220827ebe4097b9a76f150590f8bdf521803aba8
|
https://github.com/imsky/holder/blob/220827ebe4097b9a76f150590f8bdf521803aba8/holder.js#L576-L586
|
11,609
|
imsky/holder
|
holder.js
|
render
|
function render(renderSettings) {
var image = null;
var mode = renderSettings.mode;
var el = renderSettings.el;
var holderSettings = renderSettings.holderSettings;
var engineSettings = renderSettings.engineSettings;
switch (engineSettings.renderer) {
case 'svg':
if (!App.setup.supportsSVG) return;
break;
case 'canvas':
if (!App.setup.supportsCanvas) return;
break;
default:
return;
}
//todo: move generation of scene up to flag generation to reduce extra object creation
var scene = {
width: holderSettings.dimensions.width,
height: holderSettings.dimensions.height,
theme: holderSettings.theme,
flags: holderSettings.flags
};
var sceneGraph = buildSceneGraph(scene);
function getRenderedImage() {
var image = null;
switch (engineSettings.renderer) {
case 'canvas':
image = sgCanvasRenderer(sceneGraph, renderSettings);
break;
case 'svg':
image = svgRenderer(sceneGraph, renderSettings);
break;
default:
throw 'Holder: invalid renderer: ' + engineSettings.renderer;
}
return image;
}
image = getRenderedImage();
if (image == null) {
throw 'Holder: couldn\'t render placeholder';
}
//todo: add <object> canvas rendering
if (mode == 'background') {
el.style.backgroundImage = 'url(' + image + ')';
if (!engineSettings.noBackgroundSize) {
el.style.backgroundSize = scene.width + 'px ' + scene.height + 'px';
}
} else {
if (el.nodeName.toLowerCase() === 'img') {
DOM.setAttr(el, {
'src': image
});
} else if (el.nodeName.toLowerCase() === 'object') {
DOM.setAttr(el, {
'data': image,
'type': 'image/svg+xml'
});
}
if (engineSettings.reRender) {
global.setTimeout(function () {
var image = getRenderedImage();
if (image == null) {
throw 'Holder: couldn\'t render placeholder';
}
//todo: refactor this code into a function
if (el.nodeName.toLowerCase() === 'img') {
DOM.setAttr(el, {
'src': image
});
} else if (el.nodeName.toLowerCase() === 'object') {
DOM.setAttr(el, {
'data': image,
'type': 'image/svg+xml'
});
}
}, 150);
}
}
//todo: account for re-rendering
DOM.setAttr(el, {
'data-holder-rendered': true
});
}
|
javascript
|
function render(renderSettings) {
var image = null;
var mode = renderSettings.mode;
var el = renderSettings.el;
var holderSettings = renderSettings.holderSettings;
var engineSettings = renderSettings.engineSettings;
switch (engineSettings.renderer) {
case 'svg':
if (!App.setup.supportsSVG) return;
break;
case 'canvas':
if (!App.setup.supportsCanvas) return;
break;
default:
return;
}
//todo: move generation of scene up to flag generation to reduce extra object creation
var scene = {
width: holderSettings.dimensions.width,
height: holderSettings.dimensions.height,
theme: holderSettings.theme,
flags: holderSettings.flags
};
var sceneGraph = buildSceneGraph(scene);
function getRenderedImage() {
var image = null;
switch (engineSettings.renderer) {
case 'canvas':
image = sgCanvasRenderer(sceneGraph, renderSettings);
break;
case 'svg':
image = svgRenderer(sceneGraph, renderSettings);
break;
default:
throw 'Holder: invalid renderer: ' + engineSettings.renderer;
}
return image;
}
image = getRenderedImage();
if (image == null) {
throw 'Holder: couldn\'t render placeholder';
}
//todo: add <object> canvas rendering
if (mode == 'background') {
el.style.backgroundImage = 'url(' + image + ')';
if (!engineSettings.noBackgroundSize) {
el.style.backgroundSize = scene.width + 'px ' + scene.height + 'px';
}
} else {
if (el.nodeName.toLowerCase() === 'img') {
DOM.setAttr(el, {
'src': image
});
} else if (el.nodeName.toLowerCase() === 'object') {
DOM.setAttr(el, {
'data': image,
'type': 'image/svg+xml'
});
}
if (engineSettings.reRender) {
global.setTimeout(function () {
var image = getRenderedImage();
if (image == null) {
throw 'Holder: couldn\'t render placeholder';
}
//todo: refactor this code into a function
if (el.nodeName.toLowerCase() === 'img') {
DOM.setAttr(el, {
'src': image
});
} else if (el.nodeName.toLowerCase() === 'object') {
DOM.setAttr(el, {
'data': image,
'type': 'image/svg+xml'
});
}
}, 150);
}
}
//todo: account for re-rendering
DOM.setAttr(el, {
'data-holder-rendered': true
});
}
|
[
"function",
"render",
"(",
"renderSettings",
")",
"{",
"var",
"image",
"=",
"null",
";",
"var",
"mode",
"=",
"renderSettings",
".",
"mode",
";",
"var",
"el",
"=",
"renderSettings",
".",
"el",
";",
"var",
"holderSettings",
"=",
"renderSettings",
".",
"holderSettings",
";",
"var",
"engineSettings",
"=",
"renderSettings",
".",
"engineSettings",
";",
"switch",
"(",
"engineSettings",
".",
"renderer",
")",
"{",
"case",
"'svg'",
":",
"if",
"(",
"!",
"App",
".",
"setup",
".",
"supportsSVG",
")",
"return",
";",
"break",
";",
"case",
"'canvas'",
":",
"if",
"(",
"!",
"App",
".",
"setup",
".",
"supportsCanvas",
")",
"return",
";",
"break",
";",
"default",
":",
"return",
";",
"}",
"//todo: move generation of scene up to flag generation to reduce extra object creation",
"var",
"scene",
"=",
"{",
"width",
":",
"holderSettings",
".",
"dimensions",
".",
"width",
",",
"height",
":",
"holderSettings",
".",
"dimensions",
".",
"height",
",",
"theme",
":",
"holderSettings",
".",
"theme",
",",
"flags",
":",
"holderSettings",
".",
"flags",
"}",
";",
"var",
"sceneGraph",
"=",
"buildSceneGraph",
"(",
"scene",
")",
";",
"function",
"getRenderedImage",
"(",
")",
"{",
"var",
"image",
"=",
"null",
";",
"switch",
"(",
"engineSettings",
".",
"renderer",
")",
"{",
"case",
"'canvas'",
":",
"image",
"=",
"sgCanvasRenderer",
"(",
"sceneGraph",
",",
"renderSettings",
")",
";",
"break",
";",
"case",
"'svg'",
":",
"image",
"=",
"svgRenderer",
"(",
"sceneGraph",
",",
"renderSettings",
")",
";",
"break",
";",
"default",
":",
"throw",
"'Holder: invalid renderer: '",
"+",
"engineSettings",
".",
"renderer",
";",
"}",
"return",
"image",
";",
"}",
"image",
"=",
"getRenderedImage",
"(",
")",
";",
"if",
"(",
"image",
"==",
"null",
")",
"{",
"throw",
"'Holder: couldn\\'t render placeholder'",
";",
"}",
"//todo: add <object> canvas rendering",
"if",
"(",
"mode",
"==",
"'background'",
")",
"{",
"el",
".",
"style",
".",
"backgroundImage",
"=",
"'url('",
"+",
"image",
"+",
"')'",
";",
"if",
"(",
"!",
"engineSettings",
".",
"noBackgroundSize",
")",
"{",
"el",
".",
"style",
".",
"backgroundSize",
"=",
"scene",
".",
"width",
"+",
"'px '",
"+",
"scene",
".",
"height",
"+",
"'px'",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"el",
".",
"nodeName",
".",
"toLowerCase",
"(",
")",
"===",
"'img'",
")",
"{",
"DOM",
".",
"setAttr",
"(",
"el",
",",
"{",
"'src'",
":",
"image",
"}",
")",
";",
"}",
"else",
"if",
"(",
"el",
".",
"nodeName",
".",
"toLowerCase",
"(",
")",
"===",
"'object'",
")",
"{",
"DOM",
".",
"setAttr",
"(",
"el",
",",
"{",
"'data'",
":",
"image",
",",
"'type'",
":",
"'image/svg+xml'",
"}",
")",
";",
"}",
"if",
"(",
"engineSettings",
".",
"reRender",
")",
"{",
"global",
".",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"var",
"image",
"=",
"getRenderedImage",
"(",
")",
";",
"if",
"(",
"image",
"==",
"null",
")",
"{",
"throw",
"'Holder: couldn\\'t render placeholder'",
";",
"}",
"//todo: refactor this code into a function",
"if",
"(",
"el",
".",
"nodeName",
".",
"toLowerCase",
"(",
")",
"===",
"'img'",
")",
"{",
"DOM",
".",
"setAttr",
"(",
"el",
",",
"{",
"'src'",
":",
"image",
"}",
")",
";",
"}",
"else",
"if",
"(",
"el",
".",
"nodeName",
".",
"toLowerCase",
"(",
")",
"===",
"'object'",
")",
"{",
"DOM",
".",
"setAttr",
"(",
"el",
",",
"{",
"'data'",
":",
"image",
",",
"'type'",
":",
"'image/svg+xml'",
"}",
")",
";",
"}",
"}",
",",
"150",
")",
";",
"}",
"}",
"//todo: account for re-rendering",
"DOM",
".",
"setAttr",
"(",
"el",
",",
"{",
"'data-holder-rendered'",
":",
"true",
"}",
")",
";",
"}"
] |
Core function that takes output from renderers and sets it as the source or background-image of the target element
@private
@param renderSettings Renderer settings
|
[
"Core",
"function",
"that",
"takes",
"output",
"from",
"renderers",
"and",
"sets",
"it",
"as",
"the",
"source",
"or",
"background",
"-",
"image",
"of",
"the",
"target",
"element"
] |
220827ebe4097b9a76f150590f8bdf521803aba8
|
https://github.com/imsky/holder/blob/220827ebe4097b9a76f150590f8bdf521803aba8/holder.js#L862-L954
|
11,610
|
imsky/holder
|
holder.js
|
textSize
|
function textSize(width, height, fontSize, scale) {
var stageWidth = parseInt(width, 10);
var stageHeight = parseInt(height, 10);
var bigSide = Math.max(stageWidth, stageHeight);
var smallSide = Math.min(stageWidth, stageHeight);
var newHeight = 0.8 * Math.min(smallSide, bigSide * scale);
return Math.round(Math.max(fontSize, newHeight));
}
|
javascript
|
function textSize(width, height, fontSize, scale) {
var stageWidth = parseInt(width, 10);
var stageHeight = parseInt(height, 10);
var bigSide = Math.max(stageWidth, stageHeight);
var smallSide = Math.min(stageWidth, stageHeight);
var newHeight = 0.8 * Math.min(smallSide, bigSide * scale);
return Math.round(Math.max(fontSize, newHeight));
}
|
[
"function",
"textSize",
"(",
"width",
",",
"height",
",",
"fontSize",
",",
"scale",
")",
"{",
"var",
"stageWidth",
"=",
"parseInt",
"(",
"width",
",",
"10",
")",
";",
"var",
"stageHeight",
"=",
"parseInt",
"(",
"height",
",",
"10",
")",
";",
"var",
"bigSide",
"=",
"Math",
".",
"max",
"(",
"stageWidth",
",",
"stageHeight",
")",
";",
"var",
"smallSide",
"=",
"Math",
".",
"min",
"(",
"stageWidth",
",",
"stageHeight",
")",
";",
"var",
"newHeight",
"=",
"0.8",
"*",
"Math",
".",
"min",
"(",
"smallSide",
",",
"bigSide",
"*",
"scale",
")",
";",
"return",
"Math",
".",
"round",
"(",
"Math",
".",
"max",
"(",
"fontSize",
",",
"newHeight",
")",
")",
";",
"}"
] |
Adaptive text sizing function
@private
@param width Parent width
@param height Parent height
@param fontSize Requested text size
@param scale Proportional scale of text
|
[
"Adaptive",
"text",
"sizing",
"function"
] |
220827ebe4097b9a76f150590f8bdf521803aba8
|
https://github.com/imsky/holder/blob/220827ebe4097b9a76f150590f8bdf521803aba8/holder.js#L1150-L1159
|
11,611
|
imsky/holder
|
holder.js
|
setInitialDimensions
|
function setInitialDimensions(el) {
if (el.holderData) {
var dimensions = dimensionCheck(el);
if (dimensions) {
var flags = el.holderData.flags;
var fluidConfig = {
fluidHeight: flags.dimensions.height.slice(-1) == '%',
fluidWidth: flags.dimensions.width.slice(-1) == '%',
mode: null,
initialDimensions: dimensions
};
if (fluidConfig.fluidWidth && !fluidConfig.fluidHeight) {
fluidConfig.mode = 'width';
fluidConfig.ratio = fluidConfig.initialDimensions.width / parseFloat(flags.dimensions.height);
} else if (!fluidConfig.fluidWidth && fluidConfig.fluidHeight) {
fluidConfig.mode = 'height';
fluidConfig.ratio = parseFloat(flags.dimensions.width) / fluidConfig.initialDimensions.height;
}
el.holderData.fluidConfig = fluidConfig;
} else {
setInvisible(el);
}
}
}
|
javascript
|
function setInitialDimensions(el) {
if (el.holderData) {
var dimensions = dimensionCheck(el);
if (dimensions) {
var flags = el.holderData.flags;
var fluidConfig = {
fluidHeight: flags.dimensions.height.slice(-1) == '%',
fluidWidth: flags.dimensions.width.slice(-1) == '%',
mode: null,
initialDimensions: dimensions
};
if (fluidConfig.fluidWidth && !fluidConfig.fluidHeight) {
fluidConfig.mode = 'width';
fluidConfig.ratio = fluidConfig.initialDimensions.width / parseFloat(flags.dimensions.height);
} else if (!fluidConfig.fluidWidth && fluidConfig.fluidHeight) {
fluidConfig.mode = 'height';
fluidConfig.ratio = parseFloat(flags.dimensions.width) / fluidConfig.initialDimensions.height;
}
el.holderData.fluidConfig = fluidConfig;
} else {
setInvisible(el);
}
}
}
|
[
"function",
"setInitialDimensions",
"(",
"el",
")",
"{",
"if",
"(",
"el",
".",
"holderData",
")",
"{",
"var",
"dimensions",
"=",
"dimensionCheck",
"(",
"el",
")",
";",
"if",
"(",
"dimensions",
")",
"{",
"var",
"flags",
"=",
"el",
".",
"holderData",
".",
"flags",
";",
"var",
"fluidConfig",
"=",
"{",
"fluidHeight",
":",
"flags",
".",
"dimensions",
".",
"height",
".",
"slice",
"(",
"-",
"1",
")",
"==",
"'%'",
",",
"fluidWidth",
":",
"flags",
".",
"dimensions",
".",
"width",
".",
"slice",
"(",
"-",
"1",
")",
"==",
"'%'",
",",
"mode",
":",
"null",
",",
"initialDimensions",
":",
"dimensions",
"}",
";",
"if",
"(",
"fluidConfig",
".",
"fluidWidth",
"&&",
"!",
"fluidConfig",
".",
"fluidHeight",
")",
"{",
"fluidConfig",
".",
"mode",
"=",
"'width'",
";",
"fluidConfig",
".",
"ratio",
"=",
"fluidConfig",
".",
"initialDimensions",
".",
"width",
"/",
"parseFloat",
"(",
"flags",
".",
"dimensions",
".",
"height",
")",
";",
"}",
"else",
"if",
"(",
"!",
"fluidConfig",
".",
"fluidWidth",
"&&",
"fluidConfig",
".",
"fluidHeight",
")",
"{",
"fluidConfig",
".",
"mode",
"=",
"'height'",
";",
"fluidConfig",
".",
"ratio",
"=",
"parseFloat",
"(",
"flags",
".",
"dimensions",
".",
"width",
")",
"/",
"fluidConfig",
".",
"initialDimensions",
".",
"height",
";",
"}",
"el",
".",
"holderData",
".",
"fluidConfig",
"=",
"fluidConfig",
";",
"}",
"else",
"{",
"setInvisible",
"(",
"el",
")",
";",
"}",
"}",
"}"
] |
Sets up aspect ratio metadata for fluid placeholders, in order to preserve proportions when resizing
@private
@param el Image DOM element
|
[
"Sets",
"up",
"aspect",
"ratio",
"metadata",
"for",
"fluid",
"placeholders",
"in",
"order",
"to",
"preserve",
"proportions",
"when",
"resizing"
] |
220827ebe4097b9a76f150590f8bdf521803aba8
|
https://github.com/imsky/holder/blob/220827ebe4097b9a76f150590f8bdf521803aba8/holder.js#L1226-L1252
|
11,612
|
imsky/holder
|
holder.js
|
visibilityCheck
|
function visibilityCheck() {
var renderableImages = [];
var keys = Object.keys(App.vars.invisibleImages);
var el;
keys.forEach(function (key) {
el = App.vars.invisibleImages[key];
if (dimensionCheck(el) && el.nodeName.toLowerCase() == 'img') {
renderableImages.push(el);
delete App.vars.invisibleImages[key];
}
});
if (renderableImages.length) {
Holder.run({
images: renderableImages
});
}
// Done to prevent 100% CPU usage via aggressive calling of requestAnimationFrame
setTimeout(function () {
global.requestAnimationFrame(visibilityCheck);
}, 10);
}
|
javascript
|
function visibilityCheck() {
var renderableImages = [];
var keys = Object.keys(App.vars.invisibleImages);
var el;
keys.forEach(function (key) {
el = App.vars.invisibleImages[key];
if (dimensionCheck(el) && el.nodeName.toLowerCase() == 'img') {
renderableImages.push(el);
delete App.vars.invisibleImages[key];
}
});
if (renderableImages.length) {
Holder.run({
images: renderableImages
});
}
// Done to prevent 100% CPU usage via aggressive calling of requestAnimationFrame
setTimeout(function () {
global.requestAnimationFrame(visibilityCheck);
}, 10);
}
|
[
"function",
"visibilityCheck",
"(",
")",
"{",
"var",
"renderableImages",
"=",
"[",
"]",
";",
"var",
"keys",
"=",
"Object",
".",
"keys",
"(",
"App",
".",
"vars",
".",
"invisibleImages",
")",
";",
"var",
"el",
";",
"keys",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"el",
"=",
"App",
".",
"vars",
".",
"invisibleImages",
"[",
"key",
"]",
";",
"if",
"(",
"dimensionCheck",
"(",
"el",
")",
"&&",
"el",
".",
"nodeName",
".",
"toLowerCase",
"(",
")",
"==",
"'img'",
")",
"{",
"renderableImages",
".",
"push",
"(",
"el",
")",
";",
"delete",
"App",
".",
"vars",
".",
"invisibleImages",
"[",
"key",
"]",
";",
"}",
"}",
")",
";",
"if",
"(",
"renderableImages",
".",
"length",
")",
"{",
"Holder",
".",
"run",
"(",
"{",
"images",
":",
"renderableImages",
"}",
")",
";",
"}",
"// Done to prevent 100% CPU usage via aggressive calling of requestAnimationFrame",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"global",
".",
"requestAnimationFrame",
"(",
"visibilityCheck",
")",
";",
"}",
",",
"10",
")",
";",
"}"
] |
Iterates through all current invisible images, and if they're visible, renders them and removes them from further checks. Runs every animation frame.
@private
|
[
"Iterates",
"through",
"all",
"current",
"invisible",
"images",
"and",
"if",
"they",
"re",
"visible",
"renders",
"them",
"and",
"removes",
"them",
"from",
"further",
"checks",
".",
"Runs",
"every",
"animation",
"frame",
"."
] |
220827ebe4097b9a76f150590f8bdf521803aba8
|
https://github.com/imsky/holder/blob/220827ebe4097b9a76f150590f8bdf521803aba8/holder.js#L1259-L1282
|
11,613
|
imsky/holder
|
holder.js
|
startVisibilityCheck
|
function startVisibilityCheck() {
if (!App.vars.visibilityCheckStarted) {
global.requestAnimationFrame(visibilityCheck);
App.vars.visibilityCheckStarted = true;
}
}
|
javascript
|
function startVisibilityCheck() {
if (!App.vars.visibilityCheckStarted) {
global.requestAnimationFrame(visibilityCheck);
App.vars.visibilityCheckStarted = true;
}
}
|
[
"function",
"startVisibilityCheck",
"(",
")",
"{",
"if",
"(",
"!",
"App",
".",
"vars",
".",
"visibilityCheckStarted",
")",
"{",
"global",
".",
"requestAnimationFrame",
"(",
"visibilityCheck",
")",
";",
"App",
".",
"vars",
".",
"visibilityCheckStarted",
"=",
"true",
";",
"}",
"}"
] |
Starts checking for invisible placeholders if not doing so yet. Does nothing otherwise.
@private
|
[
"Starts",
"checking",
"for",
"invisible",
"placeholders",
"if",
"not",
"doing",
"so",
"yet",
".",
"Does",
"nothing",
"otherwise",
"."
] |
220827ebe4097b9a76f150590f8bdf521803aba8
|
https://github.com/imsky/holder/blob/220827ebe4097b9a76f150590f8bdf521803aba8/holder.js#L1289-L1294
|
11,614
|
imsky/holder
|
holder.js
|
setInvisible
|
function setInvisible(el) {
if (!el.holderData.invisibleId) {
App.vars.invisibleId += 1;
App.vars.invisibleImages['i' + App.vars.invisibleId] = el;
el.holderData.invisibleId = App.vars.invisibleId;
}
}
|
javascript
|
function setInvisible(el) {
if (!el.holderData.invisibleId) {
App.vars.invisibleId += 1;
App.vars.invisibleImages['i' + App.vars.invisibleId] = el;
el.holderData.invisibleId = App.vars.invisibleId;
}
}
|
[
"function",
"setInvisible",
"(",
"el",
")",
"{",
"if",
"(",
"!",
"el",
".",
"holderData",
".",
"invisibleId",
")",
"{",
"App",
".",
"vars",
".",
"invisibleId",
"+=",
"1",
";",
"App",
".",
"vars",
".",
"invisibleImages",
"[",
"'i'",
"+",
"App",
".",
"vars",
".",
"invisibleId",
"]",
"=",
"el",
";",
"el",
".",
"holderData",
".",
"invisibleId",
"=",
"App",
".",
"vars",
".",
"invisibleId",
";",
"}",
"}"
] |
Sets a unique ID for an image detected to be invisible and adds it to the map of invisible images checked by visibilityCheck
@private
@param el Invisible DOM element
|
[
"Sets",
"a",
"unique",
"ID",
"for",
"an",
"image",
"detected",
"to",
"be",
"invisible",
"and",
"adds",
"it",
"to",
"the",
"map",
"of",
"invisible",
"images",
"checked",
"by",
"visibilityCheck"
] |
220827ebe4097b9a76f150590f8bdf521803aba8
|
https://github.com/imsky/holder/blob/220827ebe4097b9a76f150590f8bdf521803aba8/holder.js#L1302-L1308
|
11,615
|
imsky/holder
|
holder.js
|
debounce
|
function debounce(fn) {
if (!App.vars.debounceTimer) fn.call(this);
if (App.vars.debounceTimer) global.clearTimeout(App.vars.debounceTimer);
App.vars.debounceTimer = global.setTimeout(function() {
App.vars.debounceTimer = null;
fn.call(this);
}, App.setup.debounce);
}
|
javascript
|
function debounce(fn) {
if (!App.vars.debounceTimer) fn.call(this);
if (App.vars.debounceTimer) global.clearTimeout(App.vars.debounceTimer);
App.vars.debounceTimer = global.setTimeout(function() {
App.vars.debounceTimer = null;
fn.call(this);
}, App.setup.debounce);
}
|
[
"function",
"debounce",
"(",
"fn",
")",
"{",
"if",
"(",
"!",
"App",
".",
"vars",
".",
"debounceTimer",
")",
"fn",
".",
"call",
"(",
"this",
")",
";",
"if",
"(",
"App",
".",
"vars",
".",
"debounceTimer",
")",
"global",
".",
"clearTimeout",
"(",
"App",
".",
"vars",
".",
"debounceTimer",
")",
";",
"App",
".",
"vars",
".",
"debounceTimer",
"=",
"global",
".",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"App",
".",
"vars",
".",
"debounceTimer",
"=",
"null",
";",
"fn",
".",
"call",
"(",
"this",
")",
";",
"}",
",",
"App",
".",
"setup",
".",
"debounce",
")",
";",
"}"
] |
Helpers
Prevents a function from being called too often, waits until a timer elapses to call it again
@param fn Function to call
|
[
"Helpers",
"Prevents",
"a",
"function",
"from",
"being",
"called",
"too",
"often",
"waits",
"until",
"a",
"timer",
"elapses",
"to",
"call",
"it",
"again"
] |
220827ebe4097b9a76f150590f8bdf521803aba8
|
https://github.com/imsky/holder/blob/220827ebe4097b9a76f150590f8bdf521803aba8/holder.js#L1419-L1426
|
11,616
|
imsky/holder
|
holder.js
|
completed
|
function completed( event ) {
// readyState === "complete" is good enough for us to call the dom ready in oldIE
if ( w3c || event.type === LOAD || doc[READYSTATE] === COMPLETE ) {
detach();
ready();
}
}
|
javascript
|
function completed( event ) {
// readyState === "complete" is good enough for us to call the dom ready in oldIE
if ( w3c || event.type === LOAD || doc[READYSTATE] === COMPLETE ) {
detach();
ready();
}
}
|
[
"function",
"completed",
"(",
"event",
")",
"{",
"// readyState === \"complete\" is good enough for us to call the dom ready in oldIE",
"if",
"(",
"w3c",
"||",
"event",
".",
"type",
"===",
"LOAD",
"||",
"doc",
"[",
"READYSTATE",
"]",
"===",
"COMPLETE",
")",
"{",
"detach",
"(",
")",
";",
"ready",
"(",
")",
";",
"}",
"}"
] |
The ready event handler
|
[
"The",
"ready",
"event",
"handler"
] |
220827ebe4097b9a76f150590f8bdf521803aba8
|
https://github.com/imsky/holder/blob/220827ebe4097b9a76f150590f8bdf521803aba8/holder.js#L1582-L1588
|
11,617
|
imsky/holder
|
holder.js
|
detach
|
function detach() {
if ( w3c ) {
doc[REMOVEEVENTLISTENER]( DOMCONTENTLOADED, completed, FALSE );
win[REMOVEEVENTLISTENER]( LOAD, completed, FALSE );
} else {
doc[DETACHEVENT]( ONREADYSTATECHANGE, completed );
win[DETACHEVENT]( ONLOAD, completed );
}
}
|
javascript
|
function detach() {
if ( w3c ) {
doc[REMOVEEVENTLISTENER]( DOMCONTENTLOADED, completed, FALSE );
win[REMOVEEVENTLISTENER]( LOAD, completed, FALSE );
} else {
doc[DETACHEVENT]( ONREADYSTATECHANGE, completed );
win[DETACHEVENT]( ONLOAD, completed );
}
}
|
[
"function",
"detach",
"(",
")",
"{",
"if",
"(",
"w3c",
")",
"{",
"doc",
"[",
"REMOVEEVENTLISTENER",
"]",
"(",
"DOMCONTENTLOADED",
",",
"completed",
",",
"FALSE",
")",
";",
"win",
"[",
"REMOVEEVENTLISTENER",
"]",
"(",
"LOAD",
",",
"completed",
",",
"FALSE",
")",
";",
"}",
"else",
"{",
"doc",
"[",
"DETACHEVENT",
"]",
"(",
"ONREADYSTATECHANGE",
",",
"completed",
")",
";",
"win",
"[",
"DETACHEVENT",
"]",
"(",
"ONLOAD",
",",
"completed",
")",
";",
"}",
"}"
] |
Clean-up method for dom ready events
|
[
"Clean",
"-",
"up",
"method",
"for",
"dom",
"ready",
"events"
] |
220827ebe4097b9a76f150590f8bdf521803aba8
|
https://github.com/imsky/holder/blob/220827ebe4097b9a76f150590f8bdf521803aba8/holder.js#L1591-L1599
|
11,618
|
wix/react-templates
|
src/utils.js
|
usesScopeName
|
function usesScopeName(scopeNames, node) {
function usesScope(root) {
return usesScopeName(scopeNames, root)
}
if (_.isEmpty(scopeNames)) {
return false
}
// rt-if="x"
if (node.type === 'Identifier') {
return _.includes(scopeNames, node.name)
}
// rt-if="e({key1: value1})"
if (node.type === 'Property') {
return usesScope(node.value)
}
// rt-if="e.x" or rt-if="e1[e2]"
if (node.type === 'MemberExpression') {
return node.computed ? usesScope(node.object) || usesScope(node.property) : usesScope(node.object)
}
// rt-if="!e"
if (node.type === 'UnaryExpression') {
return usesScope(node.argument)
}
// rt-if="e1 || e2" or rt-if="e1 | e2"
if (node.type === 'LogicalExpression' || node.type === 'BinaryExpression') {
return usesScope(node.left) || usesScope(node.right)
}
// rt-if="e1(e2, ... eN)"
if (node.type === 'CallExpression') {
return usesScope(node.callee) || _.some(node.arguments, usesScope)
}
// rt-if="f({e1: e2})"
if (node.type === 'ObjectExpression') {
return _.some(node.properties, usesScope)
}
// rt-if="e1[e2]"
if (node.type === 'ArrayExpression') {
return _.some(node.elements, usesScope)
}
return false
}
|
javascript
|
function usesScopeName(scopeNames, node) {
function usesScope(root) {
return usesScopeName(scopeNames, root)
}
if (_.isEmpty(scopeNames)) {
return false
}
// rt-if="x"
if (node.type === 'Identifier') {
return _.includes(scopeNames, node.name)
}
// rt-if="e({key1: value1})"
if (node.type === 'Property') {
return usesScope(node.value)
}
// rt-if="e.x" or rt-if="e1[e2]"
if (node.type === 'MemberExpression') {
return node.computed ? usesScope(node.object) || usesScope(node.property) : usesScope(node.object)
}
// rt-if="!e"
if (node.type === 'UnaryExpression') {
return usesScope(node.argument)
}
// rt-if="e1 || e2" or rt-if="e1 | e2"
if (node.type === 'LogicalExpression' || node.type === 'BinaryExpression') {
return usesScope(node.left) || usesScope(node.right)
}
// rt-if="e1(e2, ... eN)"
if (node.type === 'CallExpression') {
return usesScope(node.callee) || _.some(node.arguments, usesScope)
}
// rt-if="f({e1: e2})"
if (node.type === 'ObjectExpression') {
return _.some(node.properties, usesScope)
}
// rt-if="e1[e2]"
if (node.type === 'ArrayExpression') {
return _.some(node.elements, usesScope)
}
return false
}
|
[
"function",
"usesScopeName",
"(",
"scopeNames",
",",
"node",
")",
"{",
"function",
"usesScope",
"(",
"root",
")",
"{",
"return",
"usesScopeName",
"(",
"scopeNames",
",",
"root",
")",
"}",
"if",
"(",
"_",
".",
"isEmpty",
"(",
"scopeNames",
")",
")",
"{",
"return",
"false",
"}",
"// rt-if=\"x\"",
"if",
"(",
"node",
".",
"type",
"===",
"'Identifier'",
")",
"{",
"return",
"_",
".",
"includes",
"(",
"scopeNames",
",",
"node",
".",
"name",
")",
"}",
"// rt-if=\"e({key1: value1})\"",
"if",
"(",
"node",
".",
"type",
"===",
"'Property'",
")",
"{",
"return",
"usesScope",
"(",
"node",
".",
"value",
")",
"}",
"// rt-if=\"e.x\" or rt-if=\"e1[e2]\"",
"if",
"(",
"node",
".",
"type",
"===",
"'MemberExpression'",
")",
"{",
"return",
"node",
".",
"computed",
"?",
"usesScope",
"(",
"node",
".",
"object",
")",
"||",
"usesScope",
"(",
"node",
".",
"property",
")",
":",
"usesScope",
"(",
"node",
".",
"object",
")",
"}",
"// rt-if=\"!e\"",
"if",
"(",
"node",
".",
"type",
"===",
"'UnaryExpression'",
")",
"{",
"return",
"usesScope",
"(",
"node",
".",
"argument",
")",
"}",
"// rt-if=\"e1 || e2\" or rt-if=\"e1 | e2\"",
"if",
"(",
"node",
".",
"type",
"===",
"'LogicalExpression'",
"||",
"node",
".",
"type",
"===",
"'BinaryExpression'",
")",
"{",
"return",
"usesScope",
"(",
"node",
".",
"left",
")",
"||",
"usesScope",
"(",
"node",
".",
"right",
")",
"}",
"// rt-if=\"e1(e2, ... eN)\"",
"if",
"(",
"node",
".",
"type",
"===",
"'CallExpression'",
")",
"{",
"return",
"usesScope",
"(",
"node",
".",
"callee",
")",
"||",
"_",
".",
"some",
"(",
"node",
".",
"arguments",
",",
"usesScope",
")",
"}",
"// rt-if=\"f({e1: e2})\"",
"if",
"(",
"node",
".",
"type",
"===",
"'ObjectExpression'",
")",
"{",
"return",
"_",
".",
"some",
"(",
"node",
".",
"properties",
",",
"usesScope",
")",
"}",
"// rt-if=\"e1[e2]\"",
"if",
"(",
"node",
".",
"type",
"===",
"'ArrayExpression'",
")",
"{",
"return",
"_",
".",
"some",
"(",
"node",
".",
"elements",
",",
"usesScope",
")",
"}",
"return",
"false",
"}"
] |
return true if any node in the given tree uses a scope name from the given set, false - otherwise.
@param scopeNames a set of scope names to find
@param node root of a syntax tree generated from an ExpressionStatement or one of its children.
|
[
"return",
"true",
"if",
"any",
"node",
"in",
"the",
"given",
"tree",
"uses",
"a",
"scope",
"name",
"from",
"the",
"given",
"set",
"false",
"-",
"otherwise",
"."
] |
becfc2b789c412c9189c35dc900ab6185713cdae
|
https://github.com/wix/react-templates/blob/becfc2b789c412c9189c35dc900ab6185713cdae/src/utils.js#L91-L131
|
11,619
|
wix/react-templates
|
src/reactTemplates.js
|
parseScopeSyntax
|
function parseScopeSyntax(text) {
// the regex below was built using the following pseudo-code:
// double_quoted_string = `"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"`
// single_quoted_string = `'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'`
// text_out_of_quotes = `[^"']*?`
// expr_parts = double_quoted_string + "|" + single_quoted_string + "|" + text_out_of_quotes
// expression = zeroOrMore(nonCapture(expr_parts)) + "?"
// id = "[$_a-zA-Z]+[$_a-zA-Z0-9]*"
// as = " as" + OneOrMore(" ")
// optional_spaces = zeroOrMore(" ")
// semicolon = nonCapture(or(text(";"), "$"))
//
// regex = capture(expression) + as + capture(id) + optional_spaces + semicolon + optional_spaces
const regex = RegExp("((?:(?:\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\"|'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'|[^\"']*?))*?) as(?: )+([$_a-zA-Z]+[$_a-zA-Z0-9]*)(?: )*(?:;|$)(?: )*", 'g')
const res = []
do {
const idx = regex.lastIndex
const match = regex.exec(text)
if (regex.lastIndex === idx || match === null) {
throw text.substr(idx)
}
if (match.index === regex.lastIndex) {
regex.lastIndex++
}
res.push({expression: match[1].trim(), identifier: match[2]})
} while (regex.lastIndex < text.length)
return res
}
|
javascript
|
function parseScopeSyntax(text) {
// the regex below was built using the following pseudo-code:
// double_quoted_string = `"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"`
// single_quoted_string = `'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'`
// text_out_of_quotes = `[^"']*?`
// expr_parts = double_quoted_string + "|" + single_quoted_string + "|" + text_out_of_quotes
// expression = zeroOrMore(nonCapture(expr_parts)) + "?"
// id = "[$_a-zA-Z]+[$_a-zA-Z0-9]*"
// as = " as" + OneOrMore(" ")
// optional_spaces = zeroOrMore(" ")
// semicolon = nonCapture(or(text(";"), "$"))
//
// regex = capture(expression) + as + capture(id) + optional_spaces + semicolon + optional_spaces
const regex = RegExp("((?:(?:\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\"|'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'|[^\"']*?))*?) as(?: )+([$_a-zA-Z]+[$_a-zA-Z0-9]*)(?: )*(?:;|$)(?: )*", 'g')
const res = []
do {
const idx = regex.lastIndex
const match = regex.exec(text)
if (regex.lastIndex === idx || match === null) {
throw text.substr(idx)
}
if (match.index === regex.lastIndex) {
regex.lastIndex++
}
res.push({expression: match[1].trim(), identifier: match[2]})
} while (regex.lastIndex < text.length)
return res
}
|
[
"function",
"parseScopeSyntax",
"(",
"text",
")",
"{",
"// the regex below was built using the following pseudo-code:",
"// double_quoted_string = `\"[^\"\\\\\\\\]*(?:\\\\\\\\.[^\"\\\\\\\\]*)*\"`",
"// single_quoted_string = `'[^'\\\\\\\\]*(?:\\\\\\\\.[^'\\\\\\\\]*)*'`",
"// text_out_of_quotes = `[^\"']*?`",
"// expr_parts = double_quoted_string + \"|\" + single_quoted_string + \"|\" + text_out_of_quotes",
"// expression = zeroOrMore(nonCapture(expr_parts)) + \"?\"",
"// id = \"[$_a-zA-Z]+[$_a-zA-Z0-9]*\"",
"// as = \" as\" + OneOrMore(\" \")",
"// optional_spaces = zeroOrMore(\" \")",
"// semicolon = nonCapture(or(text(\";\"), \"$\"))",
"//",
"// regex = capture(expression) + as + capture(id) + optional_spaces + semicolon + optional_spaces",
"const",
"regex",
"=",
"RegExp",
"(",
"\"((?:(?:\\\"[^\\\"\\\\\\\\]*(?:\\\\\\\\.[^\\\"\\\\\\\\]*)*\\\"|'[^'\\\\\\\\]*(?:\\\\\\\\.[^'\\\\\\\\]*)*'|[^\\\"']*?))*?) as(?: )+([$_a-zA-Z]+[$_a-zA-Z0-9]*)(?: )*(?:;|$)(?: )*\"",
",",
"'g'",
")",
"const",
"res",
"=",
"[",
"]",
"do",
"{",
"const",
"idx",
"=",
"regex",
".",
"lastIndex",
"const",
"match",
"=",
"regex",
".",
"exec",
"(",
"text",
")",
"if",
"(",
"regex",
".",
"lastIndex",
"===",
"idx",
"||",
"match",
"===",
"null",
")",
"{",
"throw",
"text",
".",
"substr",
"(",
"idx",
")",
"}",
"if",
"(",
"match",
".",
"index",
"===",
"regex",
".",
"lastIndex",
")",
"{",
"regex",
".",
"lastIndex",
"++",
"}",
"res",
".",
"push",
"(",
"{",
"expression",
":",
"match",
"[",
"1",
"]",
".",
"trim",
"(",
")",
",",
"identifier",
":",
"match",
"[",
"2",
"]",
"}",
")",
"}",
"while",
"(",
"regex",
".",
"lastIndex",
"<",
"text",
".",
"length",
")",
"return",
"res",
"}"
] |
Parses the rt-scope attribute returning an array of parsed sections
@param {String} scope The scope attribute to parse
@returns {Array} an array of {expression,identifier}
@throws {String} the part of the string that failed to parse
|
[
"Parses",
"the",
"rt",
"-",
"scope",
"attribute",
"returning",
"an",
"array",
"of",
"parsed",
"sections"
] |
becfc2b789c412c9189c35dc900ab6185713cdae
|
https://github.com/wix/react-templates/blob/becfc2b789c412c9189c35dc900ab6185713cdae/src/reactTemplates.js#L479-L508
|
11,620
|
wix/react-templates
|
src/cli.js
|
execute
|
function execute(args) {
try {
const currentOptions = options.parse(args)
return executeOptions(currentOptions)
} catch (error) {
console.error(error.message)
return 1
}
}
|
javascript
|
function execute(args) {
try {
const currentOptions = options.parse(args)
return executeOptions(currentOptions)
} catch (error) {
console.error(error.message)
return 1
}
}
|
[
"function",
"execute",
"(",
"args",
")",
"{",
"try",
"{",
"const",
"currentOptions",
"=",
"options",
".",
"parse",
"(",
"args",
")",
"return",
"executeOptions",
"(",
"currentOptions",
")",
"}",
"catch",
"(",
"error",
")",
"{",
"console",
".",
"error",
"(",
"error",
".",
"message",
")",
"return",
"1",
"}",
"}"
] |
Executes the CLI based on an array of arguments that is passed in.
@param {string|Array|Object} args The arguments to process.
@returns {int} The exit code for the operation.
|
[
"Executes",
"the",
"CLI",
"based",
"on",
"an",
"array",
"of",
"arguments",
"that",
"is",
"passed",
"in",
"."
] |
becfc2b789c412c9189c35dc900ab6185713cdae
|
https://github.com/wix/react-templates/blob/becfc2b789c412c9189c35dc900ab6185713cdae/src/cli.js#L95-L103
|
11,621
|
AnalyticalGraphicsInc/obj2gltf
|
lib/getJsonBufferPadded.js
|
getJsonBufferPadded
|
function getJsonBufferPadded(json) {
let string = JSON.stringify(json);
const boundary = 4;
const byteLength = Buffer.byteLength(string);
const remainder = byteLength % boundary;
const padding = (remainder === 0) ? 0 : boundary - remainder;
let whitespace = '';
for (let i = 0; i < padding; ++i) {
whitespace += ' ';
}
string += whitespace;
return Buffer.from(string);
}
|
javascript
|
function getJsonBufferPadded(json) {
let string = JSON.stringify(json);
const boundary = 4;
const byteLength = Buffer.byteLength(string);
const remainder = byteLength % boundary;
const padding = (remainder === 0) ? 0 : boundary - remainder;
let whitespace = '';
for (let i = 0; i < padding; ++i) {
whitespace += ' ';
}
string += whitespace;
return Buffer.from(string);
}
|
[
"function",
"getJsonBufferPadded",
"(",
"json",
")",
"{",
"let",
"string",
"=",
"JSON",
".",
"stringify",
"(",
"json",
")",
";",
"const",
"boundary",
"=",
"4",
";",
"const",
"byteLength",
"=",
"Buffer",
".",
"byteLength",
"(",
"string",
")",
";",
"const",
"remainder",
"=",
"byteLength",
"%",
"boundary",
";",
"const",
"padding",
"=",
"(",
"remainder",
"===",
"0",
")",
"?",
"0",
":",
"boundary",
"-",
"remainder",
";",
"let",
"whitespace",
"=",
"''",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"padding",
";",
"++",
"i",
")",
"{",
"whitespace",
"+=",
"' '",
";",
"}",
"string",
"+=",
"whitespace",
";",
"return",
"Buffer",
".",
"from",
"(",
"string",
")",
";",
"}"
] |
Convert the JSON object to a padded buffer.
Pad the JSON with extra whitespace to fit the next 4-byte boundary. This ensures proper alignment
for the section that follows.
@param {Object} [json] The JSON object.
@returns {Buffer} The padded JSON buffer.
@private
|
[
"Convert",
"the",
"JSON",
"object",
"to",
"a",
"padded",
"buffer",
"."
] |
67b95daa8cd99dd64324115675c968ef9f1c195c
|
https://github.com/AnalyticalGraphicsInc/obj2gltf/blob/67b95daa8cd99dd64324115675c968ef9f1c195c/lib/getJsonBufferPadded.js#L15-L29
|
11,622
|
AnalyticalGraphicsInc/obj2gltf
|
lib/readLines.js
|
readLines
|
function readLines(path, callback) {
return new Promise(function(resolve, reject) {
const stream = fsExtra.createReadStream(path);
stream.on('error', reject);
stream.on('end', resolve);
const lineReader = readline.createInterface({
input : stream
});
lineReader.on('line', callback);
});
}
|
javascript
|
function readLines(path, callback) {
return new Promise(function(resolve, reject) {
const stream = fsExtra.createReadStream(path);
stream.on('error', reject);
stream.on('end', resolve);
const lineReader = readline.createInterface({
input : stream
});
lineReader.on('line', callback);
});
}
|
[
"function",
"readLines",
"(",
"path",
",",
"callback",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"const",
"stream",
"=",
"fsExtra",
".",
"createReadStream",
"(",
"path",
")",
";",
"stream",
".",
"on",
"(",
"'error'",
",",
"reject",
")",
";",
"stream",
".",
"on",
"(",
"'end'",
",",
"resolve",
")",
";",
"const",
"lineReader",
"=",
"readline",
".",
"createInterface",
"(",
"{",
"input",
":",
"stream",
"}",
")",
";",
"lineReader",
".",
"on",
"(",
"'line'",
",",
"callback",
")",
";",
"}",
")",
";",
"}"
] |
Read a file line-by-line.
@param {String} path Path to the file.
@param {Function} callback Function to call when reading each line.
@returns {Promise} A promise when the reader is finished.
@private
|
[
"Read",
"a",
"file",
"line",
"-",
"by",
"-",
"line",
"."
] |
67b95daa8cd99dd64324115675c968ef9f1c195c
|
https://github.com/AnalyticalGraphicsInc/obj2gltf/blob/67b95daa8cd99dd64324115675c968ef9f1c195c/lib/readLines.js#L17-L28
|
11,623
|
AnalyticalGraphicsInc/obj2gltf
|
lib/gltfToGlb.js
|
gltfToGlb
|
function gltfToGlb(gltf, binaryBuffer) {
const buffer = gltf.buffers[0];
if (defined(buffer.uri)) {
binaryBuffer = Buffer.alloc(0);
}
// Create padded binary scene string
const jsonBuffer = getJsonBufferPadded(gltf);
// Allocate buffer (Global header) + (JSON chunk header) + (JSON chunk) + (Binary chunk header) + (Binary chunk)
const glbLength = 12 + 8 + jsonBuffer.length + 8 + binaryBuffer.length;
const glb = Buffer.alloc(glbLength);
// Write binary glTF header (magic, version, length)
let byteOffset = 0;
glb.writeUInt32LE(0x46546C67, byteOffset);
byteOffset += 4;
glb.writeUInt32LE(2, byteOffset);
byteOffset += 4;
glb.writeUInt32LE(glbLength, byteOffset);
byteOffset += 4;
// Write JSON Chunk header (length, type)
glb.writeUInt32LE(jsonBuffer.length, byteOffset);
byteOffset += 4;
glb.writeUInt32LE(0x4E4F534A, byteOffset); // JSON
byteOffset += 4;
// Write JSON Chunk
jsonBuffer.copy(glb, byteOffset);
byteOffset += jsonBuffer.length;
// Write Binary Chunk header (length, type)
glb.writeUInt32LE(binaryBuffer.length, byteOffset);
byteOffset += 4;
glb.writeUInt32LE(0x004E4942, byteOffset); // BIN
byteOffset += 4;
// Write Binary Chunk
binaryBuffer.copy(glb, byteOffset);
return glb;
}
|
javascript
|
function gltfToGlb(gltf, binaryBuffer) {
const buffer = gltf.buffers[0];
if (defined(buffer.uri)) {
binaryBuffer = Buffer.alloc(0);
}
// Create padded binary scene string
const jsonBuffer = getJsonBufferPadded(gltf);
// Allocate buffer (Global header) + (JSON chunk header) + (JSON chunk) + (Binary chunk header) + (Binary chunk)
const glbLength = 12 + 8 + jsonBuffer.length + 8 + binaryBuffer.length;
const glb = Buffer.alloc(glbLength);
// Write binary glTF header (magic, version, length)
let byteOffset = 0;
glb.writeUInt32LE(0x46546C67, byteOffset);
byteOffset += 4;
glb.writeUInt32LE(2, byteOffset);
byteOffset += 4;
glb.writeUInt32LE(glbLength, byteOffset);
byteOffset += 4;
// Write JSON Chunk header (length, type)
glb.writeUInt32LE(jsonBuffer.length, byteOffset);
byteOffset += 4;
glb.writeUInt32LE(0x4E4F534A, byteOffset); // JSON
byteOffset += 4;
// Write JSON Chunk
jsonBuffer.copy(glb, byteOffset);
byteOffset += jsonBuffer.length;
// Write Binary Chunk header (length, type)
glb.writeUInt32LE(binaryBuffer.length, byteOffset);
byteOffset += 4;
glb.writeUInt32LE(0x004E4942, byteOffset); // BIN
byteOffset += 4;
// Write Binary Chunk
binaryBuffer.copy(glb, byteOffset);
return glb;
}
|
[
"function",
"gltfToGlb",
"(",
"gltf",
",",
"binaryBuffer",
")",
"{",
"const",
"buffer",
"=",
"gltf",
".",
"buffers",
"[",
"0",
"]",
";",
"if",
"(",
"defined",
"(",
"buffer",
".",
"uri",
")",
")",
"{",
"binaryBuffer",
"=",
"Buffer",
".",
"alloc",
"(",
"0",
")",
";",
"}",
"// Create padded binary scene string",
"const",
"jsonBuffer",
"=",
"getJsonBufferPadded",
"(",
"gltf",
")",
";",
"// Allocate buffer (Global header) + (JSON chunk header) + (JSON chunk) + (Binary chunk header) + (Binary chunk)",
"const",
"glbLength",
"=",
"12",
"+",
"8",
"+",
"jsonBuffer",
".",
"length",
"+",
"8",
"+",
"binaryBuffer",
".",
"length",
";",
"const",
"glb",
"=",
"Buffer",
".",
"alloc",
"(",
"glbLength",
")",
";",
"// Write binary glTF header (magic, version, length)",
"let",
"byteOffset",
"=",
"0",
";",
"glb",
".",
"writeUInt32LE",
"(",
"0x46546C67",
",",
"byteOffset",
")",
";",
"byteOffset",
"+=",
"4",
";",
"glb",
".",
"writeUInt32LE",
"(",
"2",
",",
"byteOffset",
")",
";",
"byteOffset",
"+=",
"4",
";",
"glb",
".",
"writeUInt32LE",
"(",
"glbLength",
",",
"byteOffset",
")",
";",
"byteOffset",
"+=",
"4",
";",
"// Write JSON Chunk header (length, type)",
"glb",
".",
"writeUInt32LE",
"(",
"jsonBuffer",
".",
"length",
",",
"byteOffset",
")",
";",
"byteOffset",
"+=",
"4",
";",
"glb",
".",
"writeUInt32LE",
"(",
"0x4E4F534A",
",",
"byteOffset",
")",
";",
"// JSON",
"byteOffset",
"+=",
"4",
";",
"// Write JSON Chunk",
"jsonBuffer",
".",
"copy",
"(",
"glb",
",",
"byteOffset",
")",
";",
"byteOffset",
"+=",
"jsonBuffer",
".",
"length",
";",
"// Write Binary Chunk header (length, type)",
"glb",
".",
"writeUInt32LE",
"(",
"binaryBuffer",
".",
"length",
",",
"byteOffset",
")",
";",
"byteOffset",
"+=",
"4",
";",
"glb",
".",
"writeUInt32LE",
"(",
"0x004E4942",
",",
"byteOffset",
")",
";",
"// BIN",
"byteOffset",
"+=",
"4",
";",
"// Write Binary Chunk",
"binaryBuffer",
".",
"copy",
"(",
"glb",
",",
"byteOffset",
")",
";",
"return",
"glb",
";",
"}"
] |
Convert a glTF to binary glTF.
The glTF is expected to have a single buffer and all embedded resources stored in bufferViews.
@param {Object} gltf The glTF asset.
@param {Buffer} binaryBuffer The binary buffer.
@returns {Buffer} The glb buffer.
@private
|
[
"Convert",
"a",
"glTF",
"to",
"binary",
"glTF",
"."
] |
67b95daa8cd99dd64324115675c968ef9f1c195c
|
https://github.com/AnalyticalGraphicsInc/obj2gltf/blob/67b95daa8cd99dd64324115675c968ef9f1c195c/lib/gltfToGlb.js#L20-L61
|
11,624
|
AnalyticalGraphicsInc/obj2gltf
|
lib/obj2gltf.js
|
obj2gltf
|
function obj2gltf(objPath, options) {
const defaults = obj2gltf.defaults;
options = defaultValue(options, {});
options.binary = defaultValue(options.binary, defaults.binary);
options.separate = defaultValue(options.separate, defaults.separate);
options.separateTextures = defaultValue(options.separateTextures, defaults.separateTextures) || options.separate;
options.checkTransparency = defaultValue(options.checkTransparency, defaults.checkTransparency);
options.secure = defaultValue(options.secure, defaults.secure);
options.packOcclusion = defaultValue(options.packOcclusion, defaults.packOcclusion);
options.metallicRoughness = defaultValue(options.metallicRoughness, defaults.metallicRoughness);
options.specularGlossiness = defaultValue(options.specularGlossiness, defaults.specularGlossiness);
options.unlit = defaultValue(options.unlit, defaults.unlit);
options.overridingTextures = defaultValue(options.overridingTextures, defaultValue.EMPTY_OBJECT);
options.logger = defaultValue(options.logger, getDefaultLogger());
options.writer = defaultValue(options.writer, getDefaultWriter(options.outputDirectory));
if (!defined(objPath)) {
throw new DeveloperError('objPath is required');
}
if (options.separateTextures && !defined(options.writer)) {
throw new DeveloperError('Either options.writer or options.outputDirectory must be defined when writing separate resources.');
}
if (options.metallicRoughness + options.specularGlossiness + options.unlit > 1) {
throw new DeveloperError('Only one material type may be set from [metallicRoughness, specularGlossiness, unlit].');
}
if (defined(options.overridingTextures.metallicRoughnessOcclusionTexture) && defined(options.overridingTextures.specularGlossinessTexture)) {
throw new DeveloperError('metallicRoughnessOcclusionTexture and specularGlossinessTexture cannot both be defined.');
}
if (defined(options.overridingTextures.metallicRoughnessOcclusionTexture)) {
options.metallicRoughness = true;
options.specularGlossiness = false;
options.packOcclusion = true;
}
if (defined(options.overridingTextures.specularGlossinessTexture)) {
options.metallicRoughness = false;
options.specularGlossiness = true;
}
return loadObj(objPath, options)
.then(function(objData) {
return createGltf(objData, options);
})
.then(function(gltf) {
return writeGltf(gltf, options);
});
}
|
javascript
|
function obj2gltf(objPath, options) {
const defaults = obj2gltf.defaults;
options = defaultValue(options, {});
options.binary = defaultValue(options.binary, defaults.binary);
options.separate = defaultValue(options.separate, defaults.separate);
options.separateTextures = defaultValue(options.separateTextures, defaults.separateTextures) || options.separate;
options.checkTransparency = defaultValue(options.checkTransparency, defaults.checkTransparency);
options.secure = defaultValue(options.secure, defaults.secure);
options.packOcclusion = defaultValue(options.packOcclusion, defaults.packOcclusion);
options.metallicRoughness = defaultValue(options.metallicRoughness, defaults.metallicRoughness);
options.specularGlossiness = defaultValue(options.specularGlossiness, defaults.specularGlossiness);
options.unlit = defaultValue(options.unlit, defaults.unlit);
options.overridingTextures = defaultValue(options.overridingTextures, defaultValue.EMPTY_OBJECT);
options.logger = defaultValue(options.logger, getDefaultLogger());
options.writer = defaultValue(options.writer, getDefaultWriter(options.outputDirectory));
if (!defined(objPath)) {
throw new DeveloperError('objPath is required');
}
if (options.separateTextures && !defined(options.writer)) {
throw new DeveloperError('Either options.writer or options.outputDirectory must be defined when writing separate resources.');
}
if (options.metallicRoughness + options.specularGlossiness + options.unlit > 1) {
throw new DeveloperError('Only one material type may be set from [metallicRoughness, specularGlossiness, unlit].');
}
if (defined(options.overridingTextures.metallicRoughnessOcclusionTexture) && defined(options.overridingTextures.specularGlossinessTexture)) {
throw new DeveloperError('metallicRoughnessOcclusionTexture and specularGlossinessTexture cannot both be defined.');
}
if (defined(options.overridingTextures.metallicRoughnessOcclusionTexture)) {
options.metallicRoughness = true;
options.specularGlossiness = false;
options.packOcclusion = true;
}
if (defined(options.overridingTextures.specularGlossinessTexture)) {
options.metallicRoughness = false;
options.specularGlossiness = true;
}
return loadObj(objPath, options)
.then(function(objData) {
return createGltf(objData, options);
})
.then(function(gltf) {
return writeGltf(gltf, options);
});
}
|
[
"function",
"obj2gltf",
"(",
"objPath",
",",
"options",
")",
"{",
"const",
"defaults",
"=",
"obj2gltf",
".",
"defaults",
";",
"options",
"=",
"defaultValue",
"(",
"options",
",",
"{",
"}",
")",
";",
"options",
".",
"binary",
"=",
"defaultValue",
"(",
"options",
".",
"binary",
",",
"defaults",
".",
"binary",
")",
";",
"options",
".",
"separate",
"=",
"defaultValue",
"(",
"options",
".",
"separate",
",",
"defaults",
".",
"separate",
")",
";",
"options",
".",
"separateTextures",
"=",
"defaultValue",
"(",
"options",
".",
"separateTextures",
",",
"defaults",
".",
"separateTextures",
")",
"||",
"options",
".",
"separate",
";",
"options",
".",
"checkTransparency",
"=",
"defaultValue",
"(",
"options",
".",
"checkTransparency",
",",
"defaults",
".",
"checkTransparency",
")",
";",
"options",
".",
"secure",
"=",
"defaultValue",
"(",
"options",
".",
"secure",
",",
"defaults",
".",
"secure",
")",
";",
"options",
".",
"packOcclusion",
"=",
"defaultValue",
"(",
"options",
".",
"packOcclusion",
",",
"defaults",
".",
"packOcclusion",
")",
";",
"options",
".",
"metallicRoughness",
"=",
"defaultValue",
"(",
"options",
".",
"metallicRoughness",
",",
"defaults",
".",
"metallicRoughness",
")",
";",
"options",
".",
"specularGlossiness",
"=",
"defaultValue",
"(",
"options",
".",
"specularGlossiness",
",",
"defaults",
".",
"specularGlossiness",
")",
";",
"options",
".",
"unlit",
"=",
"defaultValue",
"(",
"options",
".",
"unlit",
",",
"defaults",
".",
"unlit",
")",
";",
"options",
".",
"overridingTextures",
"=",
"defaultValue",
"(",
"options",
".",
"overridingTextures",
",",
"defaultValue",
".",
"EMPTY_OBJECT",
")",
";",
"options",
".",
"logger",
"=",
"defaultValue",
"(",
"options",
".",
"logger",
",",
"getDefaultLogger",
"(",
")",
")",
";",
"options",
".",
"writer",
"=",
"defaultValue",
"(",
"options",
".",
"writer",
",",
"getDefaultWriter",
"(",
"options",
".",
"outputDirectory",
")",
")",
";",
"if",
"(",
"!",
"defined",
"(",
"objPath",
")",
")",
"{",
"throw",
"new",
"DeveloperError",
"(",
"'objPath is required'",
")",
";",
"}",
"if",
"(",
"options",
".",
"separateTextures",
"&&",
"!",
"defined",
"(",
"options",
".",
"writer",
")",
")",
"{",
"throw",
"new",
"DeveloperError",
"(",
"'Either options.writer or options.outputDirectory must be defined when writing separate resources.'",
")",
";",
"}",
"if",
"(",
"options",
".",
"metallicRoughness",
"+",
"options",
".",
"specularGlossiness",
"+",
"options",
".",
"unlit",
">",
"1",
")",
"{",
"throw",
"new",
"DeveloperError",
"(",
"'Only one material type may be set from [metallicRoughness, specularGlossiness, unlit].'",
")",
";",
"}",
"if",
"(",
"defined",
"(",
"options",
".",
"overridingTextures",
".",
"metallicRoughnessOcclusionTexture",
")",
"&&",
"defined",
"(",
"options",
".",
"overridingTextures",
".",
"specularGlossinessTexture",
")",
")",
"{",
"throw",
"new",
"DeveloperError",
"(",
"'metallicRoughnessOcclusionTexture and specularGlossinessTexture cannot both be defined.'",
")",
";",
"}",
"if",
"(",
"defined",
"(",
"options",
".",
"overridingTextures",
".",
"metallicRoughnessOcclusionTexture",
")",
")",
"{",
"options",
".",
"metallicRoughness",
"=",
"true",
";",
"options",
".",
"specularGlossiness",
"=",
"false",
";",
"options",
".",
"packOcclusion",
"=",
"true",
";",
"}",
"if",
"(",
"defined",
"(",
"options",
".",
"overridingTextures",
".",
"specularGlossinessTexture",
")",
")",
"{",
"options",
".",
"metallicRoughness",
"=",
"false",
";",
"options",
".",
"specularGlossiness",
"=",
"true",
";",
"}",
"return",
"loadObj",
"(",
"objPath",
",",
"options",
")",
".",
"then",
"(",
"function",
"(",
"objData",
")",
"{",
"return",
"createGltf",
"(",
"objData",
",",
"options",
")",
";",
"}",
")",
".",
"then",
"(",
"function",
"(",
"gltf",
")",
"{",
"return",
"writeGltf",
"(",
"gltf",
",",
"options",
")",
";",
"}",
")",
";",
"}"
] |
Converts an obj file to a glTF or glb.
@param {String} objPath Path to the obj file.
@param {Object} [options] An object with the following properties:
@param {Boolean} [options.binary=false] Convert to binary glTF.
@param {Boolean} [options.separate=false] Write out separate buffer files and textures instead of embedding them in the glTF.
@param {Boolean} [options.separateTextures=false] Write out separate textures only.
@param {Boolean} [options.checkTransparency=false] Do a more exhaustive check for texture transparency by looking at the alpha channel of each pixel.
@param {Boolean} [options.secure=false] Prevent the converter from reading textures or mtl files outside of the input obj directory.
@param {Boolean} [options.packOcclusion=false] Pack the occlusion texture in the red channel of the metallic-roughness texture.
@param {Boolean} [options.metallicRoughness=false] The values in the mtl file are already metallic-roughness PBR values and no conversion step should be applied. Metallic is stored in the Ks and map_Ks slots and roughness is stored in the Ns and map_Ns slots.
@param {Boolean} [options.specularGlossiness=false] The values in the mtl file are already specular-glossiness PBR values and no conversion step should be applied. Specular is stored in the Ks and map_Ks slots and glossiness is stored in the Ns and map_Ns slots. The glTF will be saved with the KHR_materials_pbrSpecularGlossiness extension.
@param {Boolean} [options.unlit=false] The glTF will be saved with the KHR_materials_unlit extension.
@param {Object} [options.overridingTextures] An object containing texture paths that override textures defined in the .mtl file. This is often convenient in workflows where the .mtl does not exist or is not set up to use PBR materials. Intended for models with a single material.
@param {String} [options.overridingTextures.metallicRoughnessOcclusionTexture] Path to the metallic-roughness-occlusion texture, where occlusion is stored in the red channel, roughness is stored in the green channel, and metallic is stored in the blue channel. The model will be saved with a pbrMetallicRoughness material.
@param {String} [options.overridingTextures.specularGlossinessTexture] Path to the specular-glossiness texture, where specular color is stored in the red, green, and blue channels and specular glossiness is stored in the alpha channel. The model will be saved with a material using the KHR_materials_pbrSpecularGlossiness extension.
@param {String} [options.overridingTextures.occlusionTexture] Path to the occlusion texture. Ignored if metallicRoughnessOcclusionTexture is also set.
@param {String} [options.overridingTextures.normalTexture] Path to the normal texture.
@param {String} [options.overridingTextures.baseColorTexture] Path to the baseColor/diffuse texture.
@param {String} [options.overridingTextures.emissiveTexture] Path to the emissive texture.
@param {String} [options.overridingTextures.alphaTexture] Path to the alpha texture.
@param {Logger} [options.logger] A callback function for handling logged messages. Defaults to console.log.
@param {Writer} [options.writer] A callback function that writes files that are saved as separate resources.
@param {String} [options.outputDirectory] Output directory for writing separate resources when options.writer is not defined.
@return {Promise} A promise that resolves to the glTF JSON or glb buffer.
|
[
"Converts",
"an",
"obj",
"file",
"to",
"a",
"glTF",
"or",
"glb",
"."
] |
67b95daa8cd99dd64324115675c968ef9f1c195c
|
https://github.com/AnalyticalGraphicsInc/obj2gltf/blob/67b95daa8cd99dd64324115675c968ef9f1c195c/lib/obj2gltf.js#L42-L92
|
11,625
|
AnalyticalGraphicsInc/obj2gltf
|
lib/loadTexture.js
|
loadTexture
|
function loadTexture(texturePath, options) {
options = defaultValue(options, {});
options.checkTransparency = defaultValue(options.checkTransparency, false);
options.decode = defaultValue(options.decode, false);
return fsExtra.readFile(texturePath)
.then(function(source) {
const name = path.basename(texturePath, path.extname(texturePath));
const extension = path.extname(texturePath).toLowerCase();
const texture = new Texture();
texture.source = source;
texture.name = name;
texture.extension = extension;
texture.path = texturePath;
let decodePromise;
if (extension === '.png') {
decodePromise = decodePng(texture, options);
} else if (extension === '.jpg' || extension === '.jpeg') {
decodePromise = decodeJpeg(texture, options);
}
if (defined(decodePromise)) {
return decodePromise.thenReturn(texture);
}
return texture;
});
}
|
javascript
|
function loadTexture(texturePath, options) {
options = defaultValue(options, {});
options.checkTransparency = defaultValue(options.checkTransparency, false);
options.decode = defaultValue(options.decode, false);
return fsExtra.readFile(texturePath)
.then(function(source) {
const name = path.basename(texturePath, path.extname(texturePath));
const extension = path.extname(texturePath).toLowerCase();
const texture = new Texture();
texture.source = source;
texture.name = name;
texture.extension = extension;
texture.path = texturePath;
let decodePromise;
if (extension === '.png') {
decodePromise = decodePng(texture, options);
} else if (extension === '.jpg' || extension === '.jpeg') {
decodePromise = decodeJpeg(texture, options);
}
if (defined(decodePromise)) {
return decodePromise.thenReturn(texture);
}
return texture;
});
}
|
[
"function",
"loadTexture",
"(",
"texturePath",
",",
"options",
")",
"{",
"options",
"=",
"defaultValue",
"(",
"options",
",",
"{",
"}",
")",
";",
"options",
".",
"checkTransparency",
"=",
"defaultValue",
"(",
"options",
".",
"checkTransparency",
",",
"false",
")",
";",
"options",
".",
"decode",
"=",
"defaultValue",
"(",
"options",
".",
"decode",
",",
"false",
")",
";",
"return",
"fsExtra",
".",
"readFile",
"(",
"texturePath",
")",
".",
"then",
"(",
"function",
"(",
"source",
")",
"{",
"const",
"name",
"=",
"path",
".",
"basename",
"(",
"texturePath",
",",
"path",
".",
"extname",
"(",
"texturePath",
")",
")",
";",
"const",
"extension",
"=",
"path",
".",
"extname",
"(",
"texturePath",
")",
".",
"toLowerCase",
"(",
")",
";",
"const",
"texture",
"=",
"new",
"Texture",
"(",
")",
";",
"texture",
".",
"source",
"=",
"source",
";",
"texture",
".",
"name",
"=",
"name",
";",
"texture",
".",
"extension",
"=",
"extension",
";",
"texture",
".",
"path",
"=",
"texturePath",
";",
"let",
"decodePromise",
";",
"if",
"(",
"extension",
"===",
"'.png'",
")",
"{",
"decodePromise",
"=",
"decodePng",
"(",
"texture",
",",
"options",
")",
";",
"}",
"else",
"if",
"(",
"extension",
"===",
"'.jpg'",
"||",
"extension",
"===",
"'.jpeg'",
")",
"{",
"decodePromise",
"=",
"decodeJpeg",
"(",
"texture",
",",
"options",
")",
";",
"}",
"if",
"(",
"defined",
"(",
"decodePromise",
")",
")",
"{",
"return",
"decodePromise",
".",
"thenReturn",
"(",
"texture",
")",
";",
"}",
"return",
"texture",
";",
"}",
")",
";",
"}"
] |
Load a texture file.
@param {String} texturePath Path to the texture file.
@param {Object} [options] An object with the following properties:
@param {Boolean} [options.checkTransparency=false] Do a more exhaustive check for texture transparency by looking at the alpha channel of each pixel.
@param {Boolean} [options.decode=false] Whether to decode the texture.
@returns {Promise} A promise resolving to a Texture object.
@private
|
[
"Load",
"a",
"texture",
"file",
"."
] |
67b95daa8cd99dd64324115675c968ef9f1c195c
|
https://github.com/AnalyticalGraphicsInc/obj2gltf/blob/67b95daa8cd99dd64324115675c968ef9f1c195c/lib/loadTexture.js#L26-L54
|
11,626
|
AnalyticalGraphicsInc/obj2gltf
|
lib/Texture.js
|
Texture
|
function Texture() {
this.transparent = false;
this.source = undefined;
this.name = undefined;
this.extension = undefined;
this.path = undefined;
this.pixels = undefined;
this.width = undefined;
this.height = undefined;
}
|
javascript
|
function Texture() {
this.transparent = false;
this.source = undefined;
this.name = undefined;
this.extension = undefined;
this.path = undefined;
this.pixels = undefined;
this.width = undefined;
this.height = undefined;
}
|
[
"function",
"Texture",
"(",
")",
"{",
"this",
".",
"transparent",
"=",
"false",
";",
"this",
".",
"source",
"=",
"undefined",
";",
"this",
".",
"name",
"=",
"undefined",
";",
"this",
".",
"extension",
"=",
"undefined",
";",
"this",
".",
"path",
"=",
"undefined",
";",
"this",
".",
"pixels",
"=",
"undefined",
";",
"this",
".",
"width",
"=",
"undefined",
";",
"this",
".",
"height",
"=",
"undefined",
";",
"}"
] |
An object containing information about a texture.
@private
|
[
"An",
"object",
"containing",
"information",
"about",
"a",
"texture",
"."
] |
67b95daa8cd99dd64324115675c968ef9f1c195c
|
https://github.com/AnalyticalGraphicsInc/obj2gltf/blob/67b95daa8cd99dd64324115675c968ef9f1c195c/lib/Texture.js#L10-L19
|
11,627
|
AnalyticalGraphicsInc/obj2gltf
|
lib/getBufferPadded.js
|
getBufferPadded
|
function getBufferPadded(buffer) {
const boundary = 4;
const byteLength = buffer.length;
const remainder = byteLength % boundary;
if (remainder === 0) {
return buffer;
}
const padding = (remainder === 0) ? 0 : boundary - remainder;
const emptyBuffer = Buffer.alloc(padding);
return Buffer.concat([buffer, emptyBuffer]);
}
|
javascript
|
function getBufferPadded(buffer) {
const boundary = 4;
const byteLength = buffer.length;
const remainder = byteLength % boundary;
if (remainder === 0) {
return buffer;
}
const padding = (remainder === 0) ? 0 : boundary - remainder;
const emptyBuffer = Buffer.alloc(padding);
return Buffer.concat([buffer, emptyBuffer]);
}
|
[
"function",
"getBufferPadded",
"(",
"buffer",
")",
"{",
"const",
"boundary",
"=",
"4",
";",
"const",
"byteLength",
"=",
"buffer",
".",
"length",
";",
"const",
"remainder",
"=",
"byteLength",
"%",
"boundary",
";",
"if",
"(",
"remainder",
"===",
"0",
")",
"{",
"return",
"buffer",
";",
"}",
"const",
"padding",
"=",
"(",
"remainder",
"===",
"0",
")",
"?",
"0",
":",
"boundary",
"-",
"remainder",
";",
"const",
"emptyBuffer",
"=",
"Buffer",
".",
"alloc",
"(",
"padding",
")",
";",
"return",
"Buffer",
".",
"concat",
"(",
"[",
"buffer",
",",
"emptyBuffer",
"]",
")",
";",
"}"
] |
Pad the buffer to the next 4-byte boundary to ensure proper alignment for the section that follows.
@param {Buffer} buffer The buffer.
@returns {Buffer} The padded buffer.
@private
|
[
"Pad",
"the",
"buffer",
"to",
"the",
"next",
"4",
"-",
"byte",
"boundary",
"to",
"ensure",
"proper",
"alignment",
"for",
"the",
"section",
"that",
"follows",
"."
] |
67b95daa8cd99dd64324115675c968ef9f1c195c
|
https://github.com/AnalyticalGraphicsInc/obj2gltf/blob/67b95daa8cd99dd64324115675c968ef9f1c195c/lib/getBufferPadded.js#L12-L22
|
11,628
|
AnalyticalGraphicsInc/obj2gltf
|
lib/createGltf.js
|
createGltf
|
function createGltf(objData, options) {
const nodes = objData.nodes;
let materials = objData.materials;
const name = objData.name;
// Split materials used by primitives with different types of attributes
materials = splitIncompatibleMaterials(nodes, materials, options);
const gltf = {
accessors : [],
asset : {},
buffers : [],
bufferViews : [],
extensionsUsed : [],
extensionsRequired : [],
images : [],
materials : [],
meshes : [],
nodes : [],
samplers : [],
scene : 0,
scenes : [],
textures : []
};
gltf.asset = {
generator : 'obj2gltf',
version: '2.0'
};
gltf.scenes.push({
nodes : []
});
const bufferState = {
positionBuffers : [],
normalBuffers : [],
uvBuffers : [],
indexBuffers : [],
positionAccessors : [],
normalAccessors : [],
uvAccessors : [],
indexAccessors : []
};
const uint32Indices = requiresUint32Indices(nodes);
const nodesLength = nodes.length;
for (let i = 0; i < nodesLength; ++i) {
const node = nodes[i];
const meshes = node.meshes;
const meshesLength = meshes.length;
if (meshesLength === 1) {
const meshIndex = addMesh(gltf, materials, bufferState, uint32Indices, meshes[0], options);
addNode(gltf, node.name, meshIndex, undefined);
} else {
// Add meshes as child nodes
const parentIndex = addNode(gltf, node.name);
for (let j = 0; j < meshesLength; ++j) {
const mesh = meshes[j];
const meshIndex = addMesh(gltf, materials, bufferState, uint32Indices, mesh, options);
addNode(gltf, mesh.name, meshIndex, parentIndex);
}
}
}
if (gltf.images.length > 0) {
gltf.samplers.push({
magFilter : WebGLConstants.LINEAR,
minFilter : WebGLConstants.NEAREST_MIPMAP_LINEAR,
wrapS : WebGLConstants.REPEAT,
wrapT : WebGLConstants.REPEAT
});
}
addBuffers(gltf, bufferState, name, options.separate);
if (options.specularGlossiness) {
gltf.extensionsUsed.push('KHR_materials_pbrSpecularGlossiness');
gltf.extensionsRequired.push('KHR_materials_pbrSpecularGlossiness');
}
if (options.unlit) {
gltf.extensionsUsed.push('KHR_materials_unlit');
gltf.extensionsRequired.push('KHR_materials_unlit');
}
return gltf;
}
|
javascript
|
function createGltf(objData, options) {
const nodes = objData.nodes;
let materials = objData.materials;
const name = objData.name;
// Split materials used by primitives with different types of attributes
materials = splitIncompatibleMaterials(nodes, materials, options);
const gltf = {
accessors : [],
asset : {},
buffers : [],
bufferViews : [],
extensionsUsed : [],
extensionsRequired : [],
images : [],
materials : [],
meshes : [],
nodes : [],
samplers : [],
scene : 0,
scenes : [],
textures : []
};
gltf.asset = {
generator : 'obj2gltf',
version: '2.0'
};
gltf.scenes.push({
nodes : []
});
const bufferState = {
positionBuffers : [],
normalBuffers : [],
uvBuffers : [],
indexBuffers : [],
positionAccessors : [],
normalAccessors : [],
uvAccessors : [],
indexAccessors : []
};
const uint32Indices = requiresUint32Indices(nodes);
const nodesLength = nodes.length;
for (let i = 0; i < nodesLength; ++i) {
const node = nodes[i];
const meshes = node.meshes;
const meshesLength = meshes.length;
if (meshesLength === 1) {
const meshIndex = addMesh(gltf, materials, bufferState, uint32Indices, meshes[0], options);
addNode(gltf, node.name, meshIndex, undefined);
} else {
// Add meshes as child nodes
const parentIndex = addNode(gltf, node.name);
for (let j = 0; j < meshesLength; ++j) {
const mesh = meshes[j];
const meshIndex = addMesh(gltf, materials, bufferState, uint32Indices, mesh, options);
addNode(gltf, mesh.name, meshIndex, parentIndex);
}
}
}
if (gltf.images.length > 0) {
gltf.samplers.push({
magFilter : WebGLConstants.LINEAR,
minFilter : WebGLConstants.NEAREST_MIPMAP_LINEAR,
wrapS : WebGLConstants.REPEAT,
wrapT : WebGLConstants.REPEAT
});
}
addBuffers(gltf, bufferState, name, options.separate);
if (options.specularGlossiness) {
gltf.extensionsUsed.push('KHR_materials_pbrSpecularGlossiness');
gltf.extensionsRequired.push('KHR_materials_pbrSpecularGlossiness');
}
if (options.unlit) {
gltf.extensionsUsed.push('KHR_materials_unlit');
gltf.extensionsRequired.push('KHR_materials_unlit');
}
return gltf;
}
|
[
"function",
"createGltf",
"(",
"objData",
",",
"options",
")",
"{",
"const",
"nodes",
"=",
"objData",
".",
"nodes",
";",
"let",
"materials",
"=",
"objData",
".",
"materials",
";",
"const",
"name",
"=",
"objData",
".",
"name",
";",
"// Split materials used by primitives with different types of attributes",
"materials",
"=",
"splitIncompatibleMaterials",
"(",
"nodes",
",",
"materials",
",",
"options",
")",
";",
"const",
"gltf",
"=",
"{",
"accessors",
":",
"[",
"]",
",",
"asset",
":",
"{",
"}",
",",
"buffers",
":",
"[",
"]",
",",
"bufferViews",
":",
"[",
"]",
",",
"extensionsUsed",
":",
"[",
"]",
",",
"extensionsRequired",
":",
"[",
"]",
",",
"images",
":",
"[",
"]",
",",
"materials",
":",
"[",
"]",
",",
"meshes",
":",
"[",
"]",
",",
"nodes",
":",
"[",
"]",
",",
"samplers",
":",
"[",
"]",
",",
"scene",
":",
"0",
",",
"scenes",
":",
"[",
"]",
",",
"textures",
":",
"[",
"]",
"}",
";",
"gltf",
".",
"asset",
"=",
"{",
"generator",
":",
"'obj2gltf'",
",",
"version",
":",
"'2.0'",
"}",
";",
"gltf",
".",
"scenes",
".",
"push",
"(",
"{",
"nodes",
":",
"[",
"]",
"}",
")",
";",
"const",
"bufferState",
"=",
"{",
"positionBuffers",
":",
"[",
"]",
",",
"normalBuffers",
":",
"[",
"]",
",",
"uvBuffers",
":",
"[",
"]",
",",
"indexBuffers",
":",
"[",
"]",
",",
"positionAccessors",
":",
"[",
"]",
",",
"normalAccessors",
":",
"[",
"]",
",",
"uvAccessors",
":",
"[",
"]",
",",
"indexAccessors",
":",
"[",
"]",
"}",
";",
"const",
"uint32Indices",
"=",
"requiresUint32Indices",
"(",
"nodes",
")",
";",
"const",
"nodesLength",
"=",
"nodes",
".",
"length",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"nodesLength",
";",
"++",
"i",
")",
"{",
"const",
"node",
"=",
"nodes",
"[",
"i",
"]",
";",
"const",
"meshes",
"=",
"node",
".",
"meshes",
";",
"const",
"meshesLength",
"=",
"meshes",
".",
"length",
";",
"if",
"(",
"meshesLength",
"===",
"1",
")",
"{",
"const",
"meshIndex",
"=",
"addMesh",
"(",
"gltf",
",",
"materials",
",",
"bufferState",
",",
"uint32Indices",
",",
"meshes",
"[",
"0",
"]",
",",
"options",
")",
";",
"addNode",
"(",
"gltf",
",",
"node",
".",
"name",
",",
"meshIndex",
",",
"undefined",
")",
";",
"}",
"else",
"{",
"// Add meshes as child nodes",
"const",
"parentIndex",
"=",
"addNode",
"(",
"gltf",
",",
"node",
".",
"name",
")",
";",
"for",
"(",
"let",
"j",
"=",
"0",
";",
"j",
"<",
"meshesLength",
";",
"++",
"j",
")",
"{",
"const",
"mesh",
"=",
"meshes",
"[",
"j",
"]",
";",
"const",
"meshIndex",
"=",
"addMesh",
"(",
"gltf",
",",
"materials",
",",
"bufferState",
",",
"uint32Indices",
",",
"mesh",
",",
"options",
")",
";",
"addNode",
"(",
"gltf",
",",
"mesh",
".",
"name",
",",
"meshIndex",
",",
"parentIndex",
")",
";",
"}",
"}",
"}",
"if",
"(",
"gltf",
".",
"images",
".",
"length",
">",
"0",
")",
"{",
"gltf",
".",
"samplers",
".",
"push",
"(",
"{",
"magFilter",
":",
"WebGLConstants",
".",
"LINEAR",
",",
"minFilter",
":",
"WebGLConstants",
".",
"NEAREST_MIPMAP_LINEAR",
",",
"wrapS",
":",
"WebGLConstants",
".",
"REPEAT",
",",
"wrapT",
":",
"WebGLConstants",
".",
"REPEAT",
"}",
")",
";",
"}",
"addBuffers",
"(",
"gltf",
",",
"bufferState",
",",
"name",
",",
"options",
".",
"separate",
")",
";",
"if",
"(",
"options",
".",
"specularGlossiness",
")",
"{",
"gltf",
".",
"extensionsUsed",
".",
"push",
"(",
"'KHR_materials_pbrSpecularGlossiness'",
")",
";",
"gltf",
".",
"extensionsRequired",
".",
"push",
"(",
"'KHR_materials_pbrSpecularGlossiness'",
")",
";",
"}",
"if",
"(",
"options",
".",
"unlit",
")",
"{",
"gltf",
".",
"extensionsUsed",
".",
"push",
"(",
"'KHR_materials_unlit'",
")",
";",
"gltf",
".",
"extensionsRequired",
".",
"push",
"(",
"'KHR_materials_unlit'",
")",
";",
"}",
"return",
"gltf",
";",
"}"
] |
Create a glTF from obj data.
@param {Object} objData An object containing an array of nodes containing geometry information and an array of materials.
@param {Object} options The options object passed along from lib/obj2gltf.js
@returns {Object} A glTF asset.
@private
|
[
"Create",
"a",
"glTF",
"from",
"obj",
"data",
"."
] |
67b95daa8cd99dd64324115675c968ef9f1c195c
|
https://github.com/AnalyticalGraphicsInc/obj2gltf/blob/67b95daa8cd99dd64324115675c968ef9f1c195c/lib/createGltf.js#L23-L112
|
11,629
|
AnalyticalGraphicsInc/obj2gltf
|
lib/writeGltf.js
|
writeGltf
|
function writeGltf(gltf, options) {
return encodeTextures(gltf)
.then(function() {
const binary = options.binary;
const separate = options.separate;
const separateTextures = options.separateTextures;
const promises = [];
if (separateTextures) {
promises.push(writeSeparateTextures(gltf, options));
} else {
writeEmbeddedTextures(gltf);
}
if (separate) {
promises.push(writeSeparateBuffers(gltf, options));
} else if (!binary) {
writeEmbeddedBuffer(gltf);
}
const binaryBuffer = gltf.buffers[0].extras._obj2gltf.source;
return Promise.all(promises)
.then(function() {
deleteExtras(gltf);
removeEmpty(gltf);
if (binary) {
return gltfToGlb(gltf, binaryBuffer);
}
return gltf;
});
});
}
|
javascript
|
function writeGltf(gltf, options) {
return encodeTextures(gltf)
.then(function() {
const binary = options.binary;
const separate = options.separate;
const separateTextures = options.separateTextures;
const promises = [];
if (separateTextures) {
promises.push(writeSeparateTextures(gltf, options));
} else {
writeEmbeddedTextures(gltf);
}
if (separate) {
promises.push(writeSeparateBuffers(gltf, options));
} else if (!binary) {
writeEmbeddedBuffer(gltf);
}
const binaryBuffer = gltf.buffers[0].extras._obj2gltf.source;
return Promise.all(promises)
.then(function() {
deleteExtras(gltf);
removeEmpty(gltf);
if (binary) {
return gltfToGlb(gltf, binaryBuffer);
}
return gltf;
});
});
}
|
[
"function",
"writeGltf",
"(",
"gltf",
",",
"options",
")",
"{",
"return",
"encodeTextures",
"(",
"gltf",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"const",
"binary",
"=",
"options",
".",
"binary",
";",
"const",
"separate",
"=",
"options",
".",
"separate",
";",
"const",
"separateTextures",
"=",
"options",
".",
"separateTextures",
";",
"const",
"promises",
"=",
"[",
"]",
";",
"if",
"(",
"separateTextures",
")",
"{",
"promises",
".",
"push",
"(",
"writeSeparateTextures",
"(",
"gltf",
",",
"options",
")",
")",
";",
"}",
"else",
"{",
"writeEmbeddedTextures",
"(",
"gltf",
")",
";",
"}",
"if",
"(",
"separate",
")",
"{",
"promises",
".",
"push",
"(",
"writeSeparateBuffers",
"(",
"gltf",
",",
"options",
")",
")",
";",
"}",
"else",
"if",
"(",
"!",
"binary",
")",
"{",
"writeEmbeddedBuffer",
"(",
"gltf",
")",
";",
"}",
"const",
"binaryBuffer",
"=",
"gltf",
".",
"buffers",
"[",
"0",
"]",
".",
"extras",
".",
"_obj2gltf",
".",
"source",
";",
"return",
"Promise",
".",
"all",
"(",
"promises",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"deleteExtras",
"(",
"gltf",
")",
";",
"removeEmpty",
"(",
"gltf",
")",
";",
"if",
"(",
"binary",
")",
"{",
"return",
"gltfToGlb",
"(",
"gltf",
",",
"binaryBuffer",
")",
";",
"}",
"return",
"gltf",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Write glTF resources as embedded data uris or external files.
@param {Object} gltf The glTF asset.
@param {Object} options The options object passed along from lib/obj2gltf.js
@returns {Promise} A promise that resolves to the glTF JSON or glb buffer.
@private
|
[
"Write",
"glTF",
"resources",
"as",
"embedded",
"data",
"uris",
"or",
"external",
"files",
"."
] |
67b95daa8cd99dd64324115675c968ef9f1c195c
|
https://github.com/AnalyticalGraphicsInc/obj2gltf/blob/67b95daa8cd99dd64324115675c968ef9f1c195c/lib/writeGltf.js#L23-L55
|
11,630
|
Netflix/unleash
|
lib/ls.js
|
ls
|
function ls (onEnd) {
const FN = require('fstream-npm')
const color = require('chalk')
const glob = require('glob')
const exclude = require('lodash.difference')
const included = [ ]
const all = glob.sync('**/**', { ignore : [ 'node_modules/**/**' ], nodir : true })
FN({ path: process.cwd() })
.on('child', function (e) {
included.push(e._path.replace(e.root.path + '/', ''))
})
.on('end', function () {
const excluded = exclude(all, included)
console.info(color.magenta('\n\nWILL BE PUBLISHED\n'))
console.info(color.green(included.join('\n')))
console.info(color.magenta('\n\nWON\'T BE PUBLISHED\n'))
console.info(color.red(excluded.join('\n')))
console.info('\n\nYou can use .npmignore and the "files" field of package.json to manage these files.')
console.info('See https://docs.npmjs.com/misc/developers#keeping-files-out-of-your-package\n')
if (typeof onEnd === 'function') {
onEnd({
included : included,
excluded : excluded
})
}
})
}
|
javascript
|
function ls (onEnd) {
const FN = require('fstream-npm')
const color = require('chalk')
const glob = require('glob')
const exclude = require('lodash.difference')
const included = [ ]
const all = glob.sync('**/**', { ignore : [ 'node_modules/**/**' ], nodir : true })
FN({ path: process.cwd() })
.on('child', function (e) {
included.push(e._path.replace(e.root.path + '/', ''))
})
.on('end', function () {
const excluded = exclude(all, included)
console.info(color.magenta('\n\nWILL BE PUBLISHED\n'))
console.info(color.green(included.join('\n')))
console.info(color.magenta('\n\nWON\'T BE PUBLISHED\n'))
console.info(color.red(excluded.join('\n')))
console.info('\n\nYou can use .npmignore and the "files" field of package.json to manage these files.')
console.info('See https://docs.npmjs.com/misc/developers#keeping-files-out-of-your-package\n')
if (typeof onEnd === 'function') {
onEnd({
included : included,
excluded : excluded
})
}
})
}
|
[
"function",
"ls",
"(",
"onEnd",
")",
"{",
"const",
"FN",
"=",
"require",
"(",
"'fstream-npm'",
")",
"const",
"color",
"=",
"require",
"(",
"'chalk'",
")",
"const",
"glob",
"=",
"require",
"(",
"'glob'",
")",
"const",
"exclude",
"=",
"require",
"(",
"'lodash.difference'",
")",
"const",
"included",
"=",
"[",
"]",
"const",
"all",
"=",
"glob",
".",
"sync",
"(",
"'**/**'",
",",
"{",
"ignore",
":",
"[",
"'node_modules/**/**'",
"]",
",",
"nodir",
":",
"true",
"}",
")",
"FN",
"(",
"{",
"path",
":",
"process",
".",
"cwd",
"(",
")",
"}",
")",
".",
"on",
"(",
"'child'",
",",
"function",
"(",
"e",
")",
"{",
"included",
".",
"push",
"(",
"e",
".",
"_path",
".",
"replace",
"(",
"e",
".",
"root",
".",
"path",
"+",
"'/'",
",",
"''",
")",
")",
"}",
")",
".",
"on",
"(",
"'end'",
",",
"function",
"(",
")",
"{",
"const",
"excluded",
"=",
"exclude",
"(",
"all",
",",
"included",
")",
"console",
".",
"info",
"(",
"color",
".",
"magenta",
"(",
"'\\n\\nWILL BE PUBLISHED\\n'",
")",
")",
"console",
".",
"info",
"(",
"color",
".",
"green",
"(",
"included",
".",
"join",
"(",
"'\\n'",
")",
")",
")",
"console",
".",
"info",
"(",
"color",
".",
"magenta",
"(",
"'\\n\\nWON\\'T BE PUBLISHED\\n'",
")",
")",
"console",
".",
"info",
"(",
"color",
".",
"red",
"(",
"excluded",
".",
"join",
"(",
"'\\n'",
")",
")",
")",
"console",
".",
"info",
"(",
"'\\n\\nYou can use .npmignore and the \"files\" field of package.json to manage these files.'",
")",
"console",
".",
"info",
"(",
"'See https://docs.npmjs.com/misc/developers#keeping-files-out-of-your-package\\n'",
")",
"if",
"(",
"typeof",
"onEnd",
"===",
"'function'",
")",
"{",
"onEnd",
"(",
"{",
"included",
":",
"included",
",",
"excluded",
":",
"excluded",
"}",
")",
"}",
"}",
")",
"}"
] |
ls module.
@module lib/ls
|
[
"ls",
"module",
"."
] |
0414ab9938d20b36c99587d84fbc0b52533085ee
|
https://github.com/Netflix/unleash/blob/0414ab9938d20b36c99587d84fbc0b52533085ee/lib/ls.js#L8-L39
|
11,631
|
Netflix/unleash
|
lib/changelog.js
|
createBitbucketEnterpriseCommitLink
|
function createBitbucketEnterpriseCommitLink () {
const pkg = require(process.cwd() + '/package')
const repository = pkg.repository.url
return function (commit) {
const commitStr = commit.substring(0,8)
return repository ?
`[${commitStr}](${repository}/commits/${commitStr})` :
commitStr
}
}
|
javascript
|
function createBitbucketEnterpriseCommitLink () {
const pkg = require(process.cwd() + '/package')
const repository = pkg.repository.url
return function (commit) {
const commitStr = commit.substring(0,8)
return repository ?
`[${commitStr}](${repository}/commits/${commitStr})` :
commitStr
}
}
|
[
"function",
"createBitbucketEnterpriseCommitLink",
"(",
")",
"{",
"const",
"pkg",
"=",
"require",
"(",
"process",
".",
"cwd",
"(",
")",
"+",
"'/package'",
")",
"const",
"repository",
"=",
"pkg",
".",
"repository",
".",
"url",
"return",
"function",
"(",
"commit",
")",
"{",
"const",
"commitStr",
"=",
"commit",
".",
"substring",
"(",
"0",
",",
"8",
")",
"return",
"repository",
"?",
"`",
"${",
"commitStr",
"}",
"${",
"repository",
"}",
"${",
"commitStr",
"}",
"`",
":",
"commitStr",
"}",
"}"
] |
changelog module.
@module lib/changelog
|
[
"changelog",
"module",
"."
] |
0414ab9938d20b36c99587d84fbc0b52533085ee
|
https://github.com/Netflix/unleash/blob/0414ab9938d20b36c99587d84fbc0b52533085ee/lib/changelog.js#L10-L20
|
11,632
|
Netflix/unleash
|
lib/changelog.js
|
writeChangelog
|
function writeChangelog (options, done) {
options.repoType = options.repoType || 'github'
log('Using repo type: ', colors.magenta(options.repoType))
const pkg = require(process.cwd() + '/package')
const opts = {
log: log,
repository: pkg.repository.url,
version: options.version
}
// Github uses "commit", Bitbucket Enterprise uses "commits"
if (options.repoType === 'bitbucket') {
opts.commitLink = createBitbucketEnterpriseCommitLink()
}
return require('nf-conventional-changelog')(opts, function (err, clog) {
if (err) {
throw new Error(err)
} else {
require('fs').writeFileSync(process.cwd() + '/CHANGELOG.md', clog)
return done && typeof done === 'function' && done()
}
})
}
|
javascript
|
function writeChangelog (options, done) {
options.repoType = options.repoType || 'github'
log('Using repo type: ', colors.magenta(options.repoType))
const pkg = require(process.cwd() + '/package')
const opts = {
log: log,
repository: pkg.repository.url,
version: options.version
}
// Github uses "commit", Bitbucket Enterprise uses "commits"
if (options.repoType === 'bitbucket') {
opts.commitLink = createBitbucketEnterpriseCommitLink()
}
return require('nf-conventional-changelog')(opts, function (err, clog) {
if (err) {
throw new Error(err)
} else {
require('fs').writeFileSync(process.cwd() + '/CHANGELOG.md', clog)
return done && typeof done === 'function' && done()
}
})
}
|
[
"function",
"writeChangelog",
"(",
"options",
",",
"done",
")",
"{",
"options",
".",
"repoType",
"=",
"options",
".",
"repoType",
"||",
"'github'",
"log",
"(",
"'Using repo type: '",
",",
"colors",
".",
"magenta",
"(",
"options",
".",
"repoType",
")",
")",
"const",
"pkg",
"=",
"require",
"(",
"process",
".",
"cwd",
"(",
")",
"+",
"'/package'",
")",
"const",
"opts",
"=",
"{",
"log",
":",
"log",
",",
"repository",
":",
"pkg",
".",
"repository",
".",
"url",
",",
"version",
":",
"options",
".",
"version",
"}",
"// Github uses \"commit\", Bitbucket Enterprise uses \"commits\"",
"if",
"(",
"options",
".",
"repoType",
"===",
"'bitbucket'",
")",
"{",
"opts",
".",
"commitLink",
"=",
"createBitbucketEnterpriseCommitLink",
"(",
")",
"}",
"return",
"require",
"(",
"'nf-conventional-changelog'",
")",
"(",
"opts",
",",
"function",
"(",
"err",
",",
"clog",
")",
"{",
"if",
"(",
"err",
")",
"{",
"throw",
"new",
"Error",
"(",
"err",
")",
"}",
"else",
"{",
"require",
"(",
"'fs'",
")",
".",
"writeFileSync",
"(",
"process",
".",
"cwd",
"(",
")",
"+",
"'/CHANGELOG.md'",
",",
"clog",
")",
"return",
"done",
"&&",
"typeof",
"done",
"===",
"'function'",
"&&",
"done",
"(",
")",
"}",
"}",
")",
"}"
] |
Output change information from git commits to CHANGELOG.md
@param options - {Object} that contains all the options of the changelog writer
- repoType: The {String} repo type (github or bitbucket) of the project (default to `"github"`),
- version: The {String} semantic version to add a change log for
@param done - {Function} that gets called when the changelog write task has completed
@return `Function`.
|
[
"Output",
"change",
"information",
"from",
"git",
"commits",
"to",
"CHANGELOG",
".",
"md"
] |
0414ab9938d20b36c99587d84fbc0b52533085ee
|
https://github.com/Netflix/unleash/blob/0414ab9938d20b36c99587d84fbc0b52533085ee/lib/changelog.js#L32-L58
|
11,633
|
Netflix/unleash
|
lib/git.js
|
caller
|
function caller() {
const returnedArgs = Array.prototype.slice.call(arguments)
const fn = returnedArgs.shift()
const self = this
return wrapPromise(function (resolve, reject) {
returnedArgs.push(function (err, args) {
if (err) {
reject(err)
return
}
resolve(args)
})
fn.apply(self, returnedArgs)
})
}
|
javascript
|
function caller() {
const returnedArgs = Array.prototype.slice.call(arguments)
const fn = returnedArgs.shift()
const self = this
return wrapPromise(function (resolve, reject) {
returnedArgs.push(function (err, args) {
if (err) {
reject(err)
return
}
resolve(args)
})
fn.apply(self, returnedArgs)
})
}
|
[
"function",
"caller",
"(",
")",
"{",
"const",
"returnedArgs",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
"const",
"fn",
"=",
"returnedArgs",
".",
"shift",
"(",
")",
"const",
"self",
"=",
"this",
"return",
"wrapPromise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"returnedArgs",
".",
"push",
"(",
"function",
"(",
"err",
",",
"args",
")",
"{",
"if",
"(",
"err",
")",
"{",
"reject",
"(",
"err",
")",
"return",
"}",
"resolve",
"(",
"args",
")",
"}",
")",
"fn",
".",
"apply",
"(",
"self",
",",
"returnedArgs",
")",
"}",
")",
"}"
] |
Caller abstract method
for promisifying traditional callback methods
|
[
"Caller",
"abstract",
"method",
"for",
"promisifying",
"traditional",
"callback",
"methods"
] |
0414ab9938d20b36c99587d84fbc0b52533085ee
|
https://github.com/Netflix/unleash/blob/0414ab9938d20b36c99587d84fbc0b52533085ee/lib/git.js#L29-L46
|
11,634
|
twilio/twilio-node
|
lib/jwt/taskrouter/util.js
|
defaultWorkerPolicies
|
function defaultWorkerPolicies(version, workspaceSid, workerSid) {
var activities = new Policy({
url: _.join([TASKROUTER_BASE_URL, version, 'Workspaces', workspaceSid, 'Activities'], '/'),
method: 'GET',
allow: true
});
var tasks = new Policy({
url: _.join([TASKROUTER_BASE_URL, version, 'Workspaces', workspaceSid, 'Tasks', '**'], '/'),
method: 'GET',
allow: true
});
var reservations = new Policy({
url: _.join(
[TASKROUTER_BASE_URL, version, 'Workspaces', workspaceSid, 'Workers', workerSid, 'Reservations', '**'],
'/'
),
method: 'GET',
allow: true
});
var workerFetch = new Policy({
url: _.join([TASKROUTER_BASE_URL, version, 'Workspaces', workspaceSid, 'Workers', workerSid], '/'),
method: 'GET',
allow: true
});
return [activities, tasks, reservations, workerFetch];
}
|
javascript
|
function defaultWorkerPolicies(version, workspaceSid, workerSid) {
var activities = new Policy({
url: _.join([TASKROUTER_BASE_URL, version, 'Workspaces', workspaceSid, 'Activities'], '/'),
method: 'GET',
allow: true
});
var tasks = new Policy({
url: _.join([TASKROUTER_BASE_URL, version, 'Workspaces', workspaceSid, 'Tasks', '**'], '/'),
method: 'GET',
allow: true
});
var reservations = new Policy({
url: _.join(
[TASKROUTER_BASE_URL, version, 'Workspaces', workspaceSid, 'Workers', workerSid, 'Reservations', '**'],
'/'
),
method: 'GET',
allow: true
});
var workerFetch = new Policy({
url: _.join([TASKROUTER_BASE_URL, version, 'Workspaces', workspaceSid, 'Workers', workerSid], '/'),
method: 'GET',
allow: true
});
return [activities, tasks, reservations, workerFetch];
}
|
[
"function",
"defaultWorkerPolicies",
"(",
"version",
",",
"workspaceSid",
",",
"workerSid",
")",
"{",
"var",
"activities",
"=",
"new",
"Policy",
"(",
"{",
"url",
":",
"_",
".",
"join",
"(",
"[",
"TASKROUTER_BASE_URL",
",",
"version",
",",
"'Workspaces'",
",",
"workspaceSid",
",",
"'Activities'",
"]",
",",
"'/'",
")",
",",
"method",
":",
"'GET'",
",",
"allow",
":",
"true",
"}",
")",
";",
"var",
"tasks",
"=",
"new",
"Policy",
"(",
"{",
"url",
":",
"_",
".",
"join",
"(",
"[",
"TASKROUTER_BASE_URL",
",",
"version",
",",
"'Workspaces'",
",",
"workspaceSid",
",",
"'Tasks'",
",",
"'**'",
"]",
",",
"'/'",
")",
",",
"method",
":",
"'GET'",
",",
"allow",
":",
"true",
"}",
")",
";",
"var",
"reservations",
"=",
"new",
"Policy",
"(",
"{",
"url",
":",
"_",
".",
"join",
"(",
"[",
"TASKROUTER_BASE_URL",
",",
"version",
",",
"'Workspaces'",
",",
"workspaceSid",
",",
"'Workers'",
",",
"workerSid",
",",
"'Reservations'",
",",
"'**'",
"]",
",",
"'/'",
")",
",",
"method",
":",
"'GET'",
",",
"allow",
":",
"true",
"}",
")",
";",
"var",
"workerFetch",
"=",
"new",
"Policy",
"(",
"{",
"url",
":",
"_",
".",
"join",
"(",
"[",
"TASKROUTER_BASE_URL",
",",
"version",
",",
"'Workspaces'",
",",
"workspaceSid",
",",
"'Workers'",
",",
"workerSid",
"]",
",",
"'/'",
")",
",",
"method",
":",
"'GET'",
",",
"allow",
":",
"true",
"}",
")",
";",
"return",
"[",
"activities",
",",
"tasks",
",",
"reservations",
",",
"workerFetch",
"]",
";",
"}"
] |
Build the default Policies for a worker
@param {string} version TaskRouter version
@param {string} workspaceSid workspace sid
@param {string} workerSid worker sid
@returns {Array<Policy>} list of Policies
|
[
"Build",
"the",
"default",
"Policies",
"for",
"a",
"worker"
] |
61c56f8345c49ed7fa73fbfc1cdf943b6c324542
|
https://github.com/twilio/twilio-node/blob/61c56f8345c49ed7fa73fbfc1cdf943b6c324542/lib/jwt/taskrouter/util.js#L18-L44
|
11,635
|
twilio/twilio-node
|
lib/jwt/taskrouter/util.js
|
defaultEventBridgePolicies
|
function defaultEventBridgePolicies(accountSid, channelId) {
var url = _.join([EVENT_URL_BASE, accountSid, channelId], '/');
return [
new Policy({
url: url,
method: 'GET',
allow: true
}),
new Policy({
url: url,
method: 'POST',
allow: true
})
];
}
|
javascript
|
function defaultEventBridgePolicies(accountSid, channelId) {
var url = _.join([EVENT_URL_BASE, accountSid, channelId], '/');
return [
new Policy({
url: url,
method: 'GET',
allow: true
}),
new Policy({
url: url,
method: 'POST',
allow: true
})
];
}
|
[
"function",
"defaultEventBridgePolicies",
"(",
"accountSid",
",",
"channelId",
")",
"{",
"var",
"url",
"=",
"_",
".",
"join",
"(",
"[",
"EVENT_URL_BASE",
",",
"accountSid",
",",
"channelId",
"]",
",",
"'/'",
")",
";",
"return",
"[",
"new",
"Policy",
"(",
"{",
"url",
":",
"url",
",",
"method",
":",
"'GET'",
",",
"allow",
":",
"true",
"}",
")",
",",
"new",
"Policy",
"(",
"{",
"url",
":",
"url",
",",
"method",
":",
"'POST'",
",",
"allow",
":",
"true",
"}",
")",
"]",
";",
"}"
] |
Build the default Event Bridge Policies
@param {string} accountSid account sid
@param {string} channelId channel id
@returns {Array<Policy>} list of Policies
|
[
"Build",
"the",
"default",
"Event",
"Bridge",
"Policies"
] |
61c56f8345c49ed7fa73fbfc1cdf943b6c324542
|
https://github.com/twilio/twilio-node/blob/61c56f8345c49ed7fa73fbfc1cdf943b6c324542/lib/jwt/taskrouter/util.js#L53-L67
|
11,636
|
twilio/twilio-node
|
lib/jwt/taskrouter/util.js
|
workspacesUrl
|
function workspacesUrl(workspaceSid) {
return _.join(
_.filter([TASKROUTER_BASE_URL, TASKROUTER_VERSION, 'Workspaces', workspaceSid], _.isString),
'/'
);
}
|
javascript
|
function workspacesUrl(workspaceSid) {
return _.join(
_.filter([TASKROUTER_BASE_URL, TASKROUTER_VERSION, 'Workspaces', workspaceSid], _.isString),
'/'
);
}
|
[
"function",
"workspacesUrl",
"(",
"workspaceSid",
")",
"{",
"return",
"_",
".",
"join",
"(",
"_",
".",
"filter",
"(",
"[",
"TASKROUTER_BASE_URL",
",",
"TASKROUTER_VERSION",
",",
"'Workspaces'",
",",
"workspaceSid",
"]",
",",
"_",
".",
"isString",
")",
",",
"'/'",
")",
";",
"}"
] |
Generate TaskRouter workspace url
@param {string} [workspaceSid] workspace sid or '**' for all workspaces
@return {string} generated url
|
[
"Generate",
"TaskRouter",
"workspace",
"url"
] |
61c56f8345c49ed7fa73fbfc1cdf943b6c324542
|
https://github.com/twilio/twilio-node/blob/61c56f8345c49ed7fa73fbfc1cdf943b6c324542/lib/jwt/taskrouter/util.js#L75-L80
|
11,637
|
twilio/twilio-node
|
lib/jwt/taskrouter/util.js
|
taskQueuesUrl
|
function taskQueuesUrl(workspaceSid, taskQueueSid) {
return _.join(
_.filter([workspacesUrl(workspaceSid), 'TaskQueues', taskQueueSid], _.isString),
'/'
);
}
|
javascript
|
function taskQueuesUrl(workspaceSid, taskQueueSid) {
return _.join(
_.filter([workspacesUrl(workspaceSid), 'TaskQueues', taskQueueSid], _.isString),
'/'
);
}
|
[
"function",
"taskQueuesUrl",
"(",
"workspaceSid",
",",
"taskQueueSid",
")",
"{",
"return",
"_",
".",
"join",
"(",
"_",
".",
"filter",
"(",
"[",
"workspacesUrl",
"(",
"workspaceSid",
")",
",",
"'TaskQueues'",
",",
"taskQueueSid",
"]",
",",
"_",
".",
"isString",
")",
",",
"'/'",
")",
";",
"}"
] |
Generate TaskRouter task queue url
@param {string} workspaceSid workspace sid
@param {string} [taskQueueSid] task queue sid or '**' for all task queues
@return {string} generated url
|
[
"Generate",
"TaskRouter",
"task",
"queue",
"url"
] |
61c56f8345c49ed7fa73fbfc1cdf943b6c324542
|
https://github.com/twilio/twilio-node/blob/61c56f8345c49ed7fa73fbfc1cdf943b6c324542/lib/jwt/taskrouter/util.js#L89-L94
|
11,638
|
twilio/twilio-node
|
lib/jwt/taskrouter/util.js
|
tasksUrl
|
function tasksUrl(workspaceSid, taskSid) {
return _.join(
_.filter([workspacesUrl(workspaceSid), 'Tasks', taskSid], _.isString),
'/'
);
}
|
javascript
|
function tasksUrl(workspaceSid, taskSid) {
return _.join(
_.filter([workspacesUrl(workspaceSid), 'Tasks', taskSid], _.isString),
'/'
);
}
|
[
"function",
"tasksUrl",
"(",
"workspaceSid",
",",
"taskSid",
")",
"{",
"return",
"_",
".",
"join",
"(",
"_",
".",
"filter",
"(",
"[",
"workspacesUrl",
"(",
"workspaceSid",
")",
",",
"'Tasks'",
",",
"taskSid",
"]",
",",
"_",
".",
"isString",
")",
",",
"'/'",
")",
";",
"}"
] |
Generate TaskRouter task url
@param {string} workspaceSid workspace sid
@param {string} [taskSid] task sid or '**' for all tasks
@returns {string} generated url
|
[
"Generate",
"TaskRouter",
"task",
"url"
] |
61c56f8345c49ed7fa73fbfc1cdf943b6c324542
|
https://github.com/twilio/twilio-node/blob/61c56f8345c49ed7fa73fbfc1cdf943b6c324542/lib/jwt/taskrouter/util.js#L103-L108
|
11,639
|
twilio/twilio-node
|
lib/jwt/taskrouter/util.js
|
activitiesUrl
|
function activitiesUrl(workspaceSid, activitySid) {
return _.join(
_.filter([workspacesUrl(workspaceSid), 'Activities', activitySid], _.isString),
'/'
);
}
|
javascript
|
function activitiesUrl(workspaceSid, activitySid) {
return _.join(
_.filter([workspacesUrl(workspaceSid), 'Activities', activitySid], _.isString),
'/'
);
}
|
[
"function",
"activitiesUrl",
"(",
"workspaceSid",
",",
"activitySid",
")",
"{",
"return",
"_",
".",
"join",
"(",
"_",
".",
"filter",
"(",
"[",
"workspacesUrl",
"(",
"workspaceSid",
")",
",",
"'Activities'",
",",
"activitySid",
"]",
",",
"_",
".",
"isString",
")",
",",
"'/'",
")",
";",
"}"
] |
Generate TaskRouter activity url
@param {string} workspaceSid workspace sid
@param {string} [activitySid] activity sid or '**' for all activities
@returns {string} generated url
|
[
"Generate",
"TaskRouter",
"activity",
"url"
] |
61c56f8345c49ed7fa73fbfc1cdf943b6c324542
|
https://github.com/twilio/twilio-node/blob/61c56f8345c49ed7fa73fbfc1cdf943b6c324542/lib/jwt/taskrouter/util.js#L117-L122
|
11,640
|
twilio/twilio-node
|
lib/jwt/taskrouter/util.js
|
workersUrl
|
function workersUrl(workspaceSid, workerSid) {
return _.join(
_.filter([workspacesUrl(workspaceSid), 'Workers', workerSid], _.isString),
'/'
);
}
|
javascript
|
function workersUrl(workspaceSid, workerSid) {
return _.join(
_.filter([workspacesUrl(workspaceSid), 'Workers', workerSid], _.isString),
'/'
);
}
|
[
"function",
"workersUrl",
"(",
"workspaceSid",
",",
"workerSid",
")",
"{",
"return",
"_",
".",
"join",
"(",
"_",
".",
"filter",
"(",
"[",
"workspacesUrl",
"(",
"workspaceSid",
")",
",",
"'Workers'",
",",
"workerSid",
"]",
",",
"_",
".",
"isString",
")",
",",
"'/'",
")",
";",
"}"
] |
Generate TaskRouter worker url
@param {string} workspaceSid workspace sid
@param {string} [workerSid] worker sid or '**' for all workers
@returns {string} generated url
|
[
"Generate",
"TaskRouter",
"worker",
"url"
] |
61c56f8345c49ed7fa73fbfc1cdf943b6c324542
|
https://github.com/twilio/twilio-node/blob/61c56f8345c49ed7fa73fbfc1cdf943b6c324542/lib/jwt/taskrouter/util.js#L131-L136
|
11,641
|
twilio/twilio-node
|
lib/jwt/taskrouter/util.js
|
reservationsUrl
|
function reservationsUrl(workspaceSid, workerSid, reservationSid) {
return _.join(
_.filter([workersUrl(workspaceSid, workerSid), 'Reservations', reservationSid], _.isString),
'/'
);
}
|
javascript
|
function reservationsUrl(workspaceSid, workerSid, reservationSid) {
return _.join(
_.filter([workersUrl(workspaceSid, workerSid), 'Reservations', reservationSid], _.isString),
'/'
);
}
|
[
"function",
"reservationsUrl",
"(",
"workspaceSid",
",",
"workerSid",
",",
"reservationSid",
")",
"{",
"return",
"_",
".",
"join",
"(",
"_",
".",
"filter",
"(",
"[",
"workersUrl",
"(",
"workspaceSid",
",",
"workerSid",
")",
",",
"'Reservations'",
",",
"reservationSid",
"]",
",",
"_",
".",
"isString",
")",
",",
"'/'",
")",
";",
"}"
] |
Generate TaskRouter worker reservation url
@param {string} workspaceSid workspace sid
@param {string} workerSid worker sid
@param {string} [reservationSid] reservation sid or '**' for all reservations
@returns {string} generated url
|
[
"Generate",
"TaskRouter",
"worker",
"reservation",
"url"
] |
61c56f8345c49ed7fa73fbfc1cdf943b6c324542
|
https://github.com/twilio/twilio-node/blob/61c56f8345c49ed7fa73fbfc1cdf943b6c324542/lib/jwt/taskrouter/util.js#L146-L151
|
11,642
|
twilio/twilio-node
|
lib/jwt/taskrouter/TaskRouterCapability.js
|
Policy
|
function Policy(options) {
options = options || {};
this.url = options.url;
this.method = options.method || 'GET';
this.queryFilter = options.queryFilter || {};
this.postFilter = options.postFilter || {};
this.allow = options.allow || true;
}
|
javascript
|
function Policy(options) {
options = options || {};
this.url = options.url;
this.method = options.method || 'GET';
this.queryFilter = options.queryFilter || {};
this.postFilter = options.postFilter || {};
this.allow = options.allow || true;
}
|
[
"function",
"Policy",
"(",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"this",
".",
"url",
"=",
"options",
".",
"url",
";",
"this",
".",
"method",
"=",
"options",
".",
"method",
"||",
"'GET'",
";",
"this",
".",
"queryFilter",
"=",
"options",
".",
"queryFilter",
"||",
"{",
"}",
";",
"this",
".",
"postFilter",
"=",
"options",
".",
"postFilter",
"||",
"{",
"}",
";",
"this",
".",
"allow",
"=",
"options",
".",
"allow",
"||",
"true",
";",
"}"
] |
Create a new Policy
@constructor
@param {object} options - ...
@param {string} [options.url] - Policy URL
@param {string} [options.method] - HTTP Method
@param {object} [options.queryFilter] - Request query filter allowances
@param {object} [options.postFilter] - Request post filter allowances
@param {boolean} [options.allowed] - Allow the policy
|
[
"Create",
"a",
"new",
"Policy"
] |
61c56f8345c49ed7fa73fbfc1cdf943b6c324542
|
https://github.com/twilio/twilio-node/blob/61c56f8345c49ed7fa73fbfc1cdf943b6c324542/lib/jwt/taskrouter/TaskRouterCapability.js#L17-L24
|
11,643
|
twilio/twilio-node
|
lib/webhooks/webhooks.js
|
getExpectedTwilioSignature
|
function getExpectedTwilioSignature(authToken, url, params) {
if (url.indexOf('bodySHA256') != -1) params = {};
var data = Object.keys(params)
.sort()
.reduce((acc, key) => acc + key + params[key], url);
return crypto
.createHmac('sha1', authToken)
.update(Buffer.from(data, 'utf-8'))
.digest('base64');
}
|
javascript
|
function getExpectedTwilioSignature(authToken, url, params) {
if (url.indexOf('bodySHA256') != -1) params = {};
var data = Object.keys(params)
.sort()
.reduce((acc, key) => acc + key + params[key], url);
return crypto
.createHmac('sha1', authToken)
.update(Buffer.from(data, 'utf-8'))
.digest('base64');
}
|
[
"function",
"getExpectedTwilioSignature",
"(",
"authToken",
",",
"url",
",",
"params",
")",
"{",
"if",
"(",
"url",
".",
"indexOf",
"(",
"'bodySHA256'",
")",
"!=",
"-",
"1",
")",
"params",
"=",
"{",
"}",
";",
"var",
"data",
"=",
"Object",
".",
"keys",
"(",
"params",
")",
".",
"sort",
"(",
")",
".",
"reduce",
"(",
"(",
"acc",
",",
"key",
")",
"=>",
"acc",
"+",
"key",
"+",
"params",
"[",
"key",
"]",
",",
"url",
")",
";",
"return",
"crypto",
".",
"createHmac",
"(",
"'sha1'",
",",
"authToken",
")",
".",
"update",
"(",
"Buffer",
".",
"from",
"(",
"data",
",",
"'utf-8'",
")",
")",
".",
"digest",
"(",
"'base64'",
")",
";",
"}"
] |
Utility function to get the expected signature for a given request
@param {string} authToken - The auth token, as seen in the Twilio portal
@param {string} url - The full URL (with query string) you configured to handle this request
@param {object} params - the parameters sent with this request
@returns {string} - signature
|
[
"Utility",
"function",
"to",
"get",
"the",
"expected",
"signature",
"for",
"a",
"given",
"request"
] |
61c56f8345c49ed7fa73fbfc1cdf943b6c324542
|
https://github.com/twilio/twilio-node/blob/61c56f8345c49ed7fa73fbfc1cdf943b6c324542/lib/webhooks/webhooks.js#L16-L26
|
11,644
|
twilio/twilio-node
|
lib/webhooks/webhooks.js
|
validateRequest
|
function validateRequest(authToken, twilioHeader, url, params) {
var expectedSignature = getExpectedTwilioSignature(authToken, url, params);
return scmp(Buffer.from(twilioHeader), Buffer.from(expectedSignature));
}
|
javascript
|
function validateRequest(authToken, twilioHeader, url, params) {
var expectedSignature = getExpectedTwilioSignature(authToken, url, params);
return scmp(Buffer.from(twilioHeader), Buffer.from(expectedSignature));
}
|
[
"function",
"validateRequest",
"(",
"authToken",
",",
"twilioHeader",
",",
"url",
",",
"params",
")",
"{",
"var",
"expectedSignature",
"=",
"getExpectedTwilioSignature",
"(",
"authToken",
",",
"url",
",",
"params",
")",
";",
"return",
"scmp",
"(",
"Buffer",
".",
"from",
"(",
"twilioHeader",
")",
",",
"Buffer",
".",
"from",
"(",
"expectedSignature",
")",
")",
";",
"}"
] |
Utility function to validate an incoming request is indeed from Twilio
@param {string} authToken - The auth token, as seen in the Twilio portal
@param {string} twilioHeader - The value of the X-Twilio-Signature header from the request
@param {string} url - The full URL (with query string) you configured to handle this request
@param {object} params - the parameters sent with this request
@returns {boolean} - valid
|
[
"Utility",
"function",
"to",
"validate",
"an",
"incoming",
"request",
"is",
"indeed",
"from",
"Twilio"
] |
61c56f8345c49ed7fa73fbfc1cdf943b6c324542
|
https://github.com/twilio/twilio-node/blob/61c56f8345c49ed7fa73fbfc1cdf943b6c324542/lib/webhooks/webhooks.js#L49-L52
|
11,645
|
twilio/twilio-node
|
lib/webhooks/webhooks.js
|
validateRequestWithBody
|
function validateRequestWithBody(authToken, twilioHeader, requestUrl, body) {
var urlObject = new url.URL(requestUrl);
return validateRequest(authToken, twilioHeader, requestUrl, {}) && validateBody(body, urlObject.searchParams.get('bodySHA256'));
}
|
javascript
|
function validateRequestWithBody(authToken, twilioHeader, requestUrl, body) {
var urlObject = new url.URL(requestUrl);
return validateRequest(authToken, twilioHeader, requestUrl, {}) && validateBody(body, urlObject.searchParams.get('bodySHA256'));
}
|
[
"function",
"validateRequestWithBody",
"(",
"authToken",
",",
"twilioHeader",
",",
"requestUrl",
",",
"body",
")",
"{",
"var",
"urlObject",
"=",
"new",
"url",
".",
"URL",
"(",
"requestUrl",
")",
";",
"return",
"validateRequest",
"(",
"authToken",
",",
"twilioHeader",
",",
"requestUrl",
",",
"{",
"}",
")",
"&&",
"validateBody",
"(",
"body",
",",
"urlObject",
".",
"searchParams",
".",
"get",
"(",
"'bodySHA256'",
")",
")",
";",
"}"
] |
Utility function to validate an incoming request is indeed from Twilio. This also validates
the request body against the bodySHA256 post parameter.
@param {string} authToken - The auth token, as seen in the Twilio portal
@param {string} twilioHeader - The value of the X-Twilio-Signature header from the request
@param {string} requestUrl - The full URL (with query string) you configured to handle this request
@param {string} body - The body of the request
@returns {boolean} - valid
|
[
"Utility",
"function",
"to",
"validate",
"an",
"incoming",
"request",
"is",
"indeed",
"from",
"Twilio",
".",
"This",
"also",
"validates",
"the",
"request",
"body",
"against",
"the",
"bodySHA256",
"post",
"parameter",
"."
] |
61c56f8345c49ed7fa73fbfc1cdf943b6c324542
|
https://github.com/twilio/twilio-node/blob/61c56f8345c49ed7fa73fbfc1cdf943b6c324542/lib/webhooks/webhooks.js#L64-L67
|
11,646
|
ericgio/react-bootstrap-typeahead
|
src/utils/getTruncatedOptions.js
|
getTruncatedOptions
|
function getTruncatedOptions(options, maxResults) {
if (!maxResults || maxResults >= options.length) {
return options;
}
return options.slice(0, maxResults);
}
|
javascript
|
function getTruncatedOptions(options, maxResults) {
if (!maxResults || maxResults >= options.length) {
return options;
}
return options.slice(0, maxResults);
}
|
[
"function",
"getTruncatedOptions",
"(",
"options",
",",
"maxResults",
")",
"{",
"if",
"(",
"!",
"maxResults",
"||",
"maxResults",
">=",
"options",
".",
"length",
")",
"{",
"return",
"options",
";",
"}",
"return",
"options",
".",
"slice",
"(",
"0",
",",
"maxResults",
")",
";",
"}"
] |
Truncates the result set based on `maxResults` and returns the new set.
|
[
"Truncates",
"the",
"result",
"set",
"based",
"on",
"maxResults",
"and",
"returns",
"the",
"new",
"set",
"."
] |
528cc8081b634bfd58727f6d95939fb515ab3cb1
|
https://github.com/ericgio/react-bootstrap-typeahead/blob/528cc8081b634bfd58727f6d95939fb515ab3cb1/src/utils/getTruncatedOptions.js#L4-L10
|
11,647
|
cronvel/terminal-kit
|
lib/termconfig/linux.js
|
gpmMouse
|
function gpmMouse( mode ) {
var self = this ;
if ( this.root.gpmHandler ) {
this.root.gpmHandler.close() ;
this.root.gpmHandler = undefined ;
}
if ( ! mode ) {
//console.log( '>>>>> off <<<<<' ) ;
return ;
}
this.root.gpmHandler = gpm.createHandler( { stdin: this.root.stdin , raw: false , mode: mode } ) ;
//console.log( '>>>>>' , mode , '<<<<<' ) ;
// Simply re-emit event
this.root.gpmHandler.on( 'mouse' , ( name , data ) => {
self.root.emit( 'mouse' , name , data ) ;
} ) ;
this.root.gpmHandler.on( 'error' , ( /* error */ ) => {
//console.log( 'mouseDrag error:' , error ) ;
} ) ;
}
|
javascript
|
function gpmMouse( mode ) {
var self = this ;
if ( this.root.gpmHandler ) {
this.root.gpmHandler.close() ;
this.root.gpmHandler = undefined ;
}
if ( ! mode ) {
//console.log( '>>>>> off <<<<<' ) ;
return ;
}
this.root.gpmHandler = gpm.createHandler( { stdin: this.root.stdin , raw: false , mode: mode } ) ;
//console.log( '>>>>>' , mode , '<<<<<' ) ;
// Simply re-emit event
this.root.gpmHandler.on( 'mouse' , ( name , data ) => {
self.root.emit( 'mouse' , name , data ) ;
} ) ;
this.root.gpmHandler.on( 'error' , ( /* error */ ) => {
//console.log( 'mouseDrag error:' , error ) ;
} ) ;
}
|
[
"function",
"gpmMouse",
"(",
"mode",
")",
"{",
"var",
"self",
"=",
"this",
";",
"if",
"(",
"this",
".",
"root",
".",
"gpmHandler",
")",
"{",
"this",
".",
"root",
".",
"gpmHandler",
".",
"close",
"(",
")",
";",
"this",
".",
"root",
".",
"gpmHandler",
"=",
"undefined",
";",
"}",
"if",
"(",
"!",
"mode",
")",
"{",
"//console.log( '>>>>> off <<<<<' ) ;",
"return",
";",
"}",
"this",
".",
"root",
".",
"gpmHandler",
"=",
"gpm",
".",
"createHandler",
"(",
"{",
"stdin",
":",
"this",
".",
"root",
".",
"stdin",
",",
"raw",
":",
"false",
",",
"mode",
":",
"mode",
"}",
")",
";",
"//console.log( '>>>>>' , mode , '<<<<<' ) ;",
"// Simply re-emit event",
"this",
".",
"root",
".",
"gpmHandler",
".",
"on",
"(",
"'mouse'",
",",
"(",
"name",
",",
"data",
")",
"=>",
"{",
"self",
".",
"root",
".",
"emit",
"(",
"'mouse'",
",",
"name",
",",
"data",
")",
";",
"}",
")",
";",
"this",
".",
"root",
".",
"gpmHandler",
".",
"on",
"(",
"'error'",
",",
"(",
"/* error */",
")",
"=>",
"{",
"//console.log( 'mouseDrag error:' , error ) ;",
"}",
")",
";",
"}"
] |
This is the code that handle GPM
|
[
"This",
"is",
"the",
"code",
"that",
"handle",
"GPM"
] |
e0a3ff6cd7dac62cc222e9ac10a5d95d9eee1d73
|
https://github.com/cronvel/terminal-kit/blob/e0a3ff6cd7dac62cc222e9ac10a5d95d9eee1d73/lib/termconfig/linux.js#L268-L293
|
11,648
|
cronvel/terminal-kit
|
lib/TextBuffer.js
|
TextBuffer
|
function TextBuffer( options = {} ) {
this.ScreenBuffer = options.ScreenBuffer || ( options.dst && options.dst.constructor ) || termkit.ScreenBuffer ;
// a screenBuffer
this.dst = options.dst ;
// virtually infinity by default
this.width = options.width || Infinity ;
this.height = options.height || Infinity ;
this.x = options.x !== undefined ? options.x : 0 ;
this.y = options.y !== undefined ? options.y : 0 ;
this.cx = 0 ;
this.cy = 0 ;
this.emptyCellAttr = this.ScreenBuffer.prototype.DEFAULT_ATTR ;
this.hidden = false ;
this.tabWidth = options.tabWidth || 4 ;
this.forceInBound = !! options.forceInBound ;
this.wrap = !! options.wrap ;
this.lineWrapping = options.lineWrapping || false ;
this.buffer = [ [] ] ;
this.stateMachine = options.stateMachine || null ;
if ( options.hidden ) { this.setHidden( options.hidden ) ; }
}
|
javascript
|
function TextBuffer( options = {} ) {
this.ScreenBuffer = options.ScreenBuffer || ( options.dst && options.dst.constructor ) || termkit.ScreenBuffer ;
// a screenBuffer
this.dst = options.dst ;
// virtually infinity by default
this.width = options.width || Infinity ;
this.height = options.height || Infinity ;
this.x = options.x !== undefined ? options.x : 0 ;
this.y = options.y !== undefined ? options.y : 0 ;
this.cx = 0 ;
this.cy = 0 ;
this.emptyCellAttr = this.ScreenBuffer.prototype.DEFAULT_ATTR ;
this.hidden = false ;
this.tabWidth = options.tabWidth || 4 ;
this.forceInBound = !! options.forceInBound ;
this.wrap = !! options.wrap ;
this.lineWrapping = options.lineWrapping || false ;
this.buffer = [ [] ] ;
this.stateMachine = options.stateMachine || null ;
if ( options.hidden ) { this.setHidden( options.hidden ) ; }
}
|
[
"function",
"TextBuffer",
"(",
"options",
"=",
"{",
"}",
")",
"{",
"this",
".",
"ScreenBuffer",
"=",
"options",
".",
"ScreenBuffer",
"||",
"(",
"options",
".",
"dst",
"&&",
"options",
".",
"dst",
".",
"constructor",
")",
"||",
"termkit",
".",
"ScreenBuffer",
";",
"// a screenBuffer",
"this",
".",
"dst",
"=",
"options",
".",
"dst",
";",
"// virtually infinity by default",
"this",
".",
"width",
"=",
"options",
".",
"width",
"||",
"Infinity",
";",
"this",
".",
"height",
"=",
"options",
".",
"height",
"||",
"Infinity",
";",
"this",
".",
"x",
"=",
"options",
".",
"x",
"!==",
"undefined",
"?",
"options",
".",
"x",
":",
"0",
";",
"this",
".",
"y",
"=",
"options",
".",
"y",
"!==",
"undefined",
"?",
"options",
".",
"y",
":",
"0",
";",
"this",
".",
"cx",
"=",
"0",
";",
"this",
".",
"cy",
"=",
"0",
";",
"this",
".",
"emptyCellAttr",
"=",
"this",
".",
"ScreenBuffer",
".",
"prototype",
".",
"DEFAULT_ATTR",
";",
"this",
".",
"hidden",
"=",
"false",
";",
"this",
".",
"tabWidth",
"=",
"options",
".",
"tabWidth",
"||",
"4",
";",
"this",
".",
"forceInBound",
"=",
"!",
"!",
"options",
".",
"forceInBound",
";",
"this",
".",
"wrap",
"=",
"!",
"!",
"options",
".",
"wrap",
";",
"this",
".",
"lineWrapping",
"=",
"options",
".",
"lineWrapping",
"||",
"false",
";",
"this",
".",
"buffer",
"=",
"[",
"[",
"]",
"]",
";",
"this",
".",
"stateMachine",
"=",
"options",
".",
"stateMachine",
"||",
"null",
";",
"if",
"(",
"options",
".",
"hidden",
")",
"{",
"this",
".",
"setHidden",
"(",
"options",
".",
"hidden",
")",
";",
"}",
"}"
] |
A buffer suitable for text editor
|
[
"A",
"buffer",
"suitable",
"for",
"text",
"editor"
] |
e0a3ff6cd7dac62cc222e9ac10a5d95d9eee1d73
|
https://github.com/cronvel/terminal-kit/blob/e0a3ff6cd7dac62cc222e9ac10a5d95d9eee1d73/lib/TextBuffer.js#L40-L68
|
11,649
|
cronvel/terminal-kit
|
lib/Terminal.js
|
onResize
|
function onResize() {
if ( this.stdout.columns && this.stdout.rows ) {
this.width = this.stdout.columns ;
this.height = this.stdout.rows ;
}
this.emit( 'resize' , this.width , this.height ) ;
}
|
javascript
|
function onResize() {
if ( this.stdout.columns && this.stdout.rows ) {
this.width = this.stdout.columns ;
this.height = this.stdout.rows ;
}
this.emit( 'resize' , this.width , this.height ) ;
}
|
[
"function",
"onResize",
"(",
")",
"{",
"if",
"(",
"this",
".",
"stdout",
".",
"columns",
"&&",
"this",
".",
"stdout",
".",
"rows",
")",
"{",
"this",
".",
"width",
"=",
"this",
".",
"stdout",
".",
"columns",
";",
"this",
".",
"height",
"=",
"this",
".",
"stdout",
".",
"rows",
";",
"}",
"this",
".",
"emit",
"(",
"'resize'",
",",
"this",
".",
"width",
",",
"this",
".",
"height",
")",
";",
"}"
] |
Called by either SIGWINCH signal or stdout's 'resize' event. It is not meant to be used by end-user.
|
[
"Called",
"by",
"either",
"SIGWINCH",
"signal",
"or",
"stdout",
"s",
"resize",
"event",
".",
"It",
"is",
"not",
"meant",
"to",
"be",
"used",
"by",
"end",
"-",
"user",
"."
] |
e0a3ff6cd7dac62cc222e9ac10a5d95d9eee1d73
|
https://github.com/cronvel/terminal-kit/blob/e0a3ff6cd7dac62cc222e9ac10a5d95d9eee1d73/lib/Terminal.js#L932-L939
|
11,650
|
catamphetamine/read-excel-file
|
source/convertToJson.js
|
parseValueOfType
|
function parseValueOfType(value, type, options) {
switch (type) {
case String:
return { value }
case Number:
case 'Integer':
case Integer:
// The global isFinite() function determines
// whether the passed value is a finite number.
// If needed, the parameter is first converted to a number.
if (!isFinite(value)) {
return { error: 'invalid' }
}
if (type === Integer && !isInteger(value)) {
return { error: 'invalid' }
}
// Convert strings to numbers.
// Just an additional feature.
// Won't happen when called from `readXlsx()`.
if (typeof value === 'string') {
value = parseFloat(value)
}
return { value }
case 'URL':
case URL:
if (!isURL(value)) {
return { error: 'invalid' }
}
return { value }
case 'Email':
case Email:
if (!isEmail(value)) {
return { error: 'invalid' }
}
return { value }
case Date:
// XLSX has no specific format for dates.
// Sometimes a date can be heuristically detected.
// https://github.com/catamphetamine/read-excel-file/issues/3#issuecomment-395770777
if (value instanceof Date) {
return { value }
}
if (typeof value === 'number') {
if (!isFinite(value)) {
return { error: 'invalid' }
}
value = parseInt(value)
const date = parseDate(value, options.properties)
if (!date) {
return { error: 'invalid' }
}
return { value: date }
}
return { error: 'invalid' }
case Boolean:
if (typeof value === 'boolean') {
return { value }
}
return { error: 'invalid' }
default:
throw new Error(`Unknown schema type: ${type && type.name || type}`)
}
}
|
javascript
|
function parseValueOfType(value, type, options) {
switch (type) {
case String:
return { value }
case Number:
case 'Integer':
case Integer:
// The global isFinite() function determines
// whether the passed value is a finite number.
// If needed, the parameter is first converted to a number.
if (!isFinite(value)) {
return { error: 'invalid' }
}
if (type === Integer && !isInteger(value)) {
return { error: 'invalid' }
}
// Convert strings to numbers.
// Just an additional feature.
// Won't happen when called from `readXlsx()`.
if (typeof value === 'string') {
value = parseFloat(value)
}
return { value }
case 'URL':
case URL:
if (!isURL(value)) {
return { error: 'invalid' }
}
return { value }
case 'Email':
case Email:
if (!isEmail(value)) {
return { error: 'invalid' }
}
return { value }
case Date:
// XLSX has no specific format for dates.
// Sometimes a date can be heuristically detected.
// https://github.com/catamphetamine/read-excel-file/issues/3#issuecomment-395770777
if (value instanceof Date) {
return { value }
}
if (typeof value === 'number') {
if (!isFinite(value)) {
return { error: 'invalid' }
}
value = parseInt(value)
const date = parseDate(value, options.properties)
if (!date) {
return { error: 'invalid' }
}
return { value: date }
}
return { error: 'invalid' }
case Boolean:
if (typeof value === 'boolean') {
return { value }
}
return { error: 'invalid' }
default:
throw new Error(`Unknown schema type: ${type && type.name || type}`)
}
}
|
[
"function",
"parseValueOfType",
"(",
"value",
",",
"type",
",",
"options",
")",
"{",
"switch",
"(",
"type",
")",
"{",
"case",
"String",
":",
"return",
"{",
"value",
"}",
"case",
"Number",
":",
"case",
"'Integer'",
":",
"case",
"Integer",
":",
"// The global isFinite() function determines",
"// whether the passed value is a finite number.",
"// If needed, the parameter is first converted to a number.",
"if",
"(",
"!",
"isFinite",
"(",
"value",
")",
")",
"{",
"return",
"{",
"error",
":",
"'invalid'",
"}",
"}",
"if",
"(",
"type",
"===",
"Integer",
"&&",
"!",
"isInteger",
"(",
"value",
")",
")",
"{",
"return",
"{",
"error",
":",
"'invalid'",
"}",
"}",
"// Convert strings to numbers.",
"// Just an additional feature.",
"// Won't happen when called from `readXlsx()`.",
"if",
"(",
"typeof",
"value",
"===",
"'string'",
")",
"{",
"value",
"=",
"parseFloat",
"(",
"value",
")",
"}",
"return",
"{",
"value",
"}",
"case",
"'URL'",
":",
"case",
"URL",
":",
"if",
"(",
"!",
"isURL",
"(",
"value",
")",
")",
"{",
"return",
"{",
"error",
":",
"'invalid'",
"}",
"}",
"return",
"{",
"value",
"}",
"case",
"'Email'",
":",
"case",
"Email",
":",
"if",
"(",
"!",
"isEmail",
"(",
"value",
")",
")",
"{",
"return",
"{",
"error",
":",
"'invalid'",
"}",
"}",
"return",
"{",
"value",
"}",
"case",
"Date",
":",
"// XLSX has no specific format for dates.",
"// Sometimes a date can be heuristically detected.",
"// https://github.com/catamphetamine/read-excel-file/issues/3#issuecomment-395770777",
"if",
"(",
"value",
"instanceof",
"Date",
")",
"{",
"return",
"{",
"value",
"}",
"}",
"if",
"(",
"typeof",
"value",
"===",
"'number'",
")",
"{",
"if",
"(",
"!",
"isFinite",
"(",
"value",
")",
")",
"{",
"return",
"{",
"error",
":",
"'invalid'",
"}",
"}",
"value",
"=",
"parseInt",
"(",
"value",
")",
"const",
"date",
"=",
"parseDate",
"(",
"value",
",",
"options",
".",
"properties",
")",
"if",
"(",
"!",
"date",
")",
"{",
"return",
"{",
"error",
":",
"'invalid'",
"}",
"}",
"return",
"{",
"value",
":",
"date",
"}",
"}",
"return",
"{",
"error",
":",
"'invalid'",
"}",
"case",
"Boolean",
":",
"if",
"(",
"typeof",
"value",
"===",
"'boolean'",
")",
"{",
"return",
"{",
"value",
"}",
"}",
"return",
"{",
"error",
":",
"'invalid'",
"}",
"default",
":",
"throw",
"new",
"Error",
"(",
"`",
"${",
"type",
"&&",
"type",
".",
"name",
"||",
"type",
"}",
"`",
")",
"}",
"}"
] |
Converts textual value to a javascript typed value.
@param {string} value
@param {} type
@return {{ value: (string|number|Date|boolean), error: string }}
|
[
"Converts",
"textual",
"value",
"to",
"a",
"javascript",
"typed",
"value",
"."
] |
78b3a47bdf01788c12d6674b3a1f42fd7cc92510
|
https://github.com/catamphetamine/read-excel-file/blob/78b3a47bdf01788c12d6674b3a1f42fd7cc92510/source/convertToJson.js#L183-L251
|
11,651
|
FaridSafi/react-native-gifted-listview
|
GiftedListView.js
|
MergeRowsWithHeaders
|
function MergeRowsWithHeaders(obj1, obj2) {
for(var p in obj2){
if(obj1[p] instanceof Array && obj1[p] instanceof Array){
obj1[p] = obj1[p].concat(obj2[p])
} else {
obj1[p] = obj2[p]
}
}
return obj1;
}
|
javascript
|
function MergeRowsWithHeaders(obj1, obj2) {
for(var p in obj2){
if(obj1[p] instanceof Array && obj1[p] instanceof Array){
obj1[p] = obj1[p].concat(obj2[p])
} else {
obj1[p] = obj2[p]
}
}
return obj1;
}
|
[
"function",
"MergeRowsWithHeaders",
"(",
"obj1",
",",
"obj2",
")",
"{",
"for",
"(",
"var",
"p",
"in",
"obj2",
")",
"{",
"if",
"(",
"obj1",
"[",
"p",
"]",
"instanceof",
"Array",
"&&",
"obj1",
"[",
"p",
"]",
"instanceof",
"Array",
")",
"{",
"obj1",
"[",
"p",
"]",
"=",
"obj1",
"[",
"p",
"]",
".",
"concat",
"(",
"obj2",
"[",
"p",
"]",
")",
"}",
"else",
"{",
"obj1",
"[",
"p",
"]",
"=",
"obj2",
"[",
"p",
"]",
"}",
"}",
"return",
"obj1",
";",
"}"
] |
small helper function which merged two objects into one
|
[
"small",
"helper",
"function",
"which",
"merged",
"two",
"objects",
"into",
"one"
] |
1415f0f4656245c139c94195073a44243e1c4c8c
|
https://github.com/FaridSafi/react-native-gifted-listview/blob/1415f0f4656245c139c94195073a44243e1c4c8c/GiftedListView.js#L17-L26
|
11,652
|
remarkjs/remark
|
packages/remark-parse/lib/parse.js
|
parse
|
function parse() {
var self = this
var value = String(self.file)
var start = {line: 1, column: 1, offset: 0}
var content = xtend(start)
var node
// Clean non-unix newlines: `\r\n` and `\r` are all changed to `\n`.
// This should not affect positional information.
value = value.replace(lineBreaksExpression, lineFeed)
// BOM.
if (value.charCodeAt(0) === 0xfeff) {
value = value.slice(1)
content.column++
content.offset++
}
node = {
type: 'root',
children: self.tokenizeBlock(value, content),
position: {start: start, end: self.eof || xtend(start)}
}
if (!self.options.position) {
removePosition(node, true)
}
return node
}
|
javascript
|
function parse() {
var self = this
var value = String(self.file)
var start = {line: 1, column: 1, offset: 0}
var content = xtend(start)
var node
// Clean non-unix newlines: `\r\n` and `\r` are all changed to `\n`.
// This should not affect positional information.
value = value.replace(lineBreaksExpression, lineFeed)
// BOM.
if (value.charCodeAt(0) === 0xfeff) {
value = value.slice(1)
content.column++
content.offset++
}
node = {
type: 'root',
children: self.tokenizeBlock(value, content),
position: {start: start, end: self.eof || xtend(start)}
}
if (!self.options.position) {
removePosition(node, true)
}
return node
}
|
[
"function",
"parse",
"(",
")",
"{",
"var",
"self",
"=",
"this",
"var",
"value",
"=",
"String",
"(",
"self",
".",
"file",
")",
"var",
"start",
"=",
"{",
"line",
":",
"1",
",",
"column",
":",
"1",
",",
"offset",
":",
"0",
"}",
"var",
"content",
"=",
"xtend",
"(",
"start",
")",
"var",
"node",
"// Clean non-unix newlines: `\\r\\n` and `\\r` are all changed to `\\n`.",
"// This should not affect positional information.",
"value",
"=",
"value",
".",
"replace",
"(",
"lineBreaksExpression",
",",
"lineFeed",
")",
"// BOM.",
"if",
"(",
"value",
".",
"charCodeAt",
"(",
"0",
")",
"===",
"0xfeff",
")",
"{",
"value",
"=",
"value",
".",
"slice",
"(",
"1",
")",
"content",
".",
"column",
"++",
"content",
".",
"offset",
"++",
"}",
"node",
"=",
"{",
"type",
":",
"'root'",
",",
"children",
":",
"self",
".",
"tokenizeBlock",
"(",
"value",
",",
"content",
")",
",",
"position",
":",
"{",
"start",
":",
"start",
",",
"end",
":",
"self",
".",
"eof",
"||",
"xtend",
"(",
"start",
")",
"}",
"}",
"if",
"(",
"!",
"self",
".",
"options",
".",
"position",
")",
"{",
"removePosition",
"(",
"node",
",",
"true",
")",
"}",
"return",
"node",
"}"
] |
Parse the bound file.
|
[
"Parse",
"the",
"bound",
"file",
"."
] |
cca8385746c2f3489b2d491e91ab8c581901ae8a
|
https://github.com/remarkjs/remark/blob/cca8385746c2f3489b2d491e91ab8c581901ae8a/packages/remark-parse/lib/parse.js#L12-L42
|
11,653
|
remarkjs/remark
|
packages/remark-stringify/lib/escape.js
|
alignment
|
function alignment(value, index) {
var start = value.lastIndexOf(lineFeed, index)
var end = value.indexOf(lineFeed, index)
var char
end = end === -1 ? value.length : end
while (++start < end) {
char = value.charAt(start)
if (
char !== colon &&
char !== dash &&
char !== space &&
char !== verticalBar
) {
return false
}
}
return true
}
|
javascript
|
function alignment(value, index) {
var start = value.lastIndexOf(lineFeed, index)
var end = value.indexOf(lineFeed, index)
var char
end = end === -1 ? value.length : end
while (++start < end) {
char = value.charAt(start)
if (
char !== colon &&
char !== dash &&
char !== space &&
char !== verticalBar
) {
return false
}
}
return true
}
|
[
"function",
"alignment",
"(",
"value",
",",
"index",
")",
"{",
"var",
"start",
"=",
"value",
".",
"lastIndexOf",
"(",
"lineFeed",
",",
"index",
")",
"var",
"end",
"=",
"value",
".",
"indexOf",
"(",
"lineFeed",
",",
"index",
")",
"var",
"char",
"end",
"=",
"end",
"===",
"-",
"1",
"?",
"value",
".",
"length",
":",
"end",
"while",
"(",
"++",
"start",
"<",
"end",
")",
"{",
"char",
"=",
"value",
".",
"charAt",
"(",
"start",
")",
"if",
"(",
"char",
"!==",
"colon",
"&&",
"char",
"!==",
"dash",
"&&",
"char",
"!==",
"space",
"&&",
"char",
"!==",
"verticalBar",
")",
"{",
"return",
"false",
"}",
"}",
"return",
"true",
"}"
] |
Check if `index` in `value` is inside an alignment row.
|
[
"Check",
"if",
"index",
"in",
"value",
"is",
"inside",
"an",
"alignment",
"row",
"."
] |
cca8385746c2f3489b2d491e91ab8c581901ae8a
|
https://github.com/remarkjs/remark/blob/cca8385746c2f3489b2d491e91ab8c581901ae8a/packages/remark-stringify/lib/escape.js#L267-L288
|
11,654
|
remarkjs/remark
|
packages/remark-stringify/lib/escape.js
|
protocol
|
function protocol(value) {
var val = value.slice(-6).toLowerCase()
return val === mailto || val.slice(-5) === https || val.slice(-4) === http
}
|
javascript
|
function protocol(value) {
var val = value.slice(-6).toLowerCase()
return val === mailto || val.slice(-5) === https || val.slice(-4) === http
}
|
[
"function",
"protocol",
"(",
"value",
")",
"{",
"var",
"val",
"=",
"value",
".",
"slice",
"(",
"-",
"6",
")",
".",
"toLowerCase",
"(",
")",
"return",
"val",
"===",
"mailto",
"||",
"val",
".",
"slice",
"(",
"-",
"5",
")",
"===",
"https",
"||",
"val",
".",
"slice",
"(",
"-",
"4",
")",
"===",
"http",
"}"
] |
Check if `value` ends in a protocol.
|
[
"Check",
"if",
"value",
"ends",
"in",
"a",
"protocol",
"."
] |
cca8385746c2f3489b2d491e91ab8c581901ae8a
|
https://github.com/remarkjs/remark/blob/cca8385746c2f3489b2d491e91ab8c581901ae8a/packages/remark-stringify/lib/escape.js#L296-L299
|
11,655
|
remarkjs/remark
|
packages/remark-stringify/lib/compiler.js
|
Compiler
|
function Compiler(tree, file) {
this.inLink = false
this.inTable = false
this.tree = tree
this.file = file
this.options = xtend(this.options)
this.setOptions({})
}
|
javascript
|
function Compiler(tree, file) {
this.inLink = false
this.inTable = false
this.tree = tree
this.file = file
this.options = xtend(this.options)
this.setOptions({})
}
|
[
"function",
"Compiler",
"(",
"tree",
",",
"file",
")",
"{",
"this",
".",
"inLink",
"=",
"false",
"this",
".",
"inTable",
"=",
"false",
"this",
".",
"tree",
"=",
"tree",
"this",
".",
"file",
"=",
"file",
"this",
".",
"options",
"=",
"xtend",
"(",
"this",
".",
"options",
")",
"this",
".",
"setOptions",
"(",
"{",
"}",
")",
"}"
] |
Construct a new compiler.
|
[
"Construct",
"a",
"new",
"compiler",
"."
] |
cca8385746c2f3489b2d491e91ab8c581901ae8a
|
https://github.com/remarkjs/remark/blob/cca8385746c2f3489b2d491e91ab8c581901ae8a/packages/remark-stringify/lib/compiler.js#L9-L16
|
11,656
|
remarkjs/remark
|
packages/remark-parse/lib/tokenize/list.js
|
pedanticListItem
|
function pedanticListItem(ctx, value, position) {
var offsets = ctx.offset
var line = position.line
// Remove the list-item’s bullet.
value = value.replace(pedanticBulletExpression, replacer)
// The initial line was also matched by the below, so we reset the `line`.
line = position.line
return value.replace(initialIndentExpression, replacer)
// A simple replacer which removed all matches, and adds their length to
// `offset`.
function replacer($0) {
offsets[line] = (offsets[line] || 0) + $0.length
line++
return ''
}
}
|
javascript
|
function pedanticListItem(ctx, value, position) {
var offsets = ctx.offset
var line = position.line
// Remove the list-item’s bullet.
value = value.replace(pedanticBulletExpression, replacer)
// The initial line was also matched by the below, so we reset the `line`.
line = position.line
return value.replace(initialIndentExpression, replacer)
// A simple replacer which removed all matches, and adds their length to
// `offset`.
function replacer($0) {
offsets[line] = (offsets[line] || 0) + $0.length
line++
return ''
}
}
|
[
"function",
"pedanticListItem",
"(",
"ctx",
",",
"value",
",",
"position",
")",
"{",
"var",
"offsets",
"=",
"ctx",
".",
"offset",
"var",
"line",
"=",
"position",
".",
"line",
"// Remove the list-item’s bullet.",
"value",
"=",
"value",
".",
"replace",
"(",
"pedanticBulletExpression",
",",
"replacer",
")",
"// The initial line was also matched by the below, so we reset the `line`.",
"line",
"=",
"position",
".",
"line",
"return",
"value",
".",
"replace",
"(",
"initialIndentExpression",
",",
"replacer",
")",
"// A simple replacer which removed all matches, and adds their length to",
"// `offset`.",
"function",
"replacer",
"(",
"$0",
")",
"{",
"offsets",
"[",
"line",
"]",
"=",
"(",
"offsets",
"[",
"line",
"]",
"||",
"0",
")",
"+",
"$0",
".",
"length",
"line",
"++",
"return",
"''",
"}",
"}"
] |
Create a list-item using overly simple mechanics.
|
[
"Create",
"a",
"list",
"-",
"item",
"using",
"overly",
"simple",
"mechanics",
"."
] |
cca8385746c2f3489b2d491e91ab8c581901ae8a
|
https://github.com/remarkjs/remark/blob/cca8385746c2f3489b2d491e91ab8c581901ae8a/packages/remark-parse/lib/tokenize/list.js#L376-L396
|
11,657
|
remarkjs/remark
|
packages/remark-parse/lib/tokenize/list.js
|
normalListItem
|
function normalListItem(ctx, value, position) {
var offsets = ctx.offset
var line = position.line
var max
var bullet
var rest
var lines
var trimmedLines
var index
var length
// Remove the list-item’s bullet.
value = value.replace(bulletExpression, replacer)
lines = value.split(lineFeed)
trimmedLines = removeIndent(value, getIndent(max).indent).split(lineFeed)
// We replaced the initial bullet with something else above, which was used
// to trick `removeIndentation` into removing some more characters when
// possible. However, that could result in the initial line to be stripped
// more than it should be.
trimmedLines[0] = rest
offsets[line] = (offsets[line] || 0) + bullet.length
line++
index = 0
length = lines.length
while (++index < length) {
offsets[line] =
(offsets[line] || 0) + lines[index].length - trimmedLines[index].length
line++
}
return trimmedLines.join(lineFeed)
function replacer($0, $1, $2, $3, $4) {
bullet = $1 + $2 + $3
rest = $4
// Make sure that the first nine numbered list items can indent with an
// extra space. That is, when the bullet did not receive an extra final
// space.
if (Number($2) < 10 && bullet.length % 2 === 1) {
$2 = space + $2
}
max = $1 + repeat(space, $2.length) + $3
return max + rest
}
}
|
javascript
|
function normalListItem(ctx, value, position) {
var offsets = ctx.offset
var line = position.line
var max
var bullet
var rest
var lines
var trimmedLines
var index
var length
// Remove the list-item’s bullet.
value = value.replace(bulletExpression, replacer)
lines = value.split(lineFeed)
trimmedLines = removeIndent(value, getIndent(max).indent).split(lineFeed)
// We replaced the initial bullet with something else above, which was used
// to trick `removeIndentation` into removing some more characters when
// possible. However, that could result in the initial line to be stripped
// more than it should be.
trimmedLines[0] = rest
offsets[line] = (offsets[line] || 0) + bullet.length
line++
index = 0
length = lines.length
while (++index < length) {
offsets[line] =
(offsets[line] || 0) + lines[index].length - trimmedLines[index].length
line++
}
return trimmedLines.join(lineFeed)
function replacer($0, $1, $2, $3, $4) {
bullet = $1 + $2 + $3
rest = $4
// Make sure that the first nine numbered list items can indent with an
// extra space. That is, when the bullet did not receive an extra final
// space.
if (Number($2) < 10 && bullet.length % 2 === 1) {
$2 = space + $2
}
max = $1 + repeat(space, $2.length) + $3
return max + rest
}
}
|
[
"function",
"normalListItem",
"(",
"ctx",
",",
"value",
",",
"position",
")",
"{",
"var",
"offsets",
"=",
"ctx",
".",
"offset",
"var",
"line",
"=",
"position",
".",
"line",
"var",
"max",
"var",
"bullet",
"var",
"rest",
"var",
"lines",
"var",
"trimmedLines",
"var",
"index",
"var",
"length",
"// Remove the list-item’s bullet.",
"value",
"=",
"value",
".",
"replace",
"(",
"bulletExpression",
",",
"replacer",
")",
"lines",
"=",
"value",
".",
"split",
"(",
"lineFeed",
")",
"trimmedLines",
"=",
"removeIndent",
"(",
"value",
",",
"getIndent",
"(",
"max",
")",
".",
"indent",
")",
".",
"split",
"(",
"lineFeed",
")",
"// We replaced the initial bullet with something else above, which was used",
"// to trick `removeIndentation` into removing some more characters when",
"// possible. However, that could result in the initial line to be stripped",
"// more than it should be.",
"trimmedLines",
"[",
"0",
"]",
"=",
"rest",
"offsets",
"[",
"line",
"]",
"=",
"(",
"offsets",
"[",
"line",
"]",
"||",
"0",
")",
"+",
"bullet",
".",
"length",
"line",
"++",
"index",
"=",
"0",
"length",
"=",
"lines",
".",
"length",
"while",
"(",
"++",
"index",
"<",
"length",
")",
"{",
"offsets",
"[",
"line",
"]",
"=",
"(",
"offsets",
"[",
"line",
"]",
"||",
"0",
")",
"+",
"lines",
"[",
"index",
"]",
".",
"length",
"-",
"trimmedLines",
"[",
"index",
"]",
".",
"length",
"line",
"++",
"}",
"return",
"trimmedLines",
".",
"join",
"(",
"lineFeed",
")",
"function",
"replacer",
"(",
"$0",
",",
"$1",
",",
"$2",
",",
"$3",
",",
"$4",
")",
"{",
"bullet",
"=",
"$1",
"+",
"$2",
"+",
"$3",
"rest",
"=",
"$4",
"// Make sure that the first nine numbered list items can indent with an",
"// extra space. That is, when the bullet did not receive an extra final",
"// space.",
"if",
"(",
"Number",
"(",
"$2",
")",
"<",
"10",
"&&",
"bullet",
".",
"length",
"%",
"2",
"===",
"1",
")",
"{",
"$2",
"=",
"space",
"+",
"$2",
"}",
"max",
"=",
"$1",
"+",
"repeat",
"(",
"space",
",",
"$2",
".",
"length",
")",
"+",
"$3",
"return",
"max",
"+",
"rest",
"}",
"}"
] |
Create a list-item using sane mechanics.
|
[
"Create",
"a",
"list",
"-",
"item",
"using",
"sane",
"mechanics",
"."
] |
cca8385746c2f3489b2d491e91ab8c581901ae8a
|
https://github.com/remarkjs/remark/blob/cca8385746c2f3489b2d491e91ab8c581901ae8a/packages/remark-parse/lib/tokenize/list.js#L399-L452
|
11,658
|
remarkjs/remark
|
packages/remark-parse/lib/util/get-indentation.js
|
indentation
|
function indentation(value) {
var index = 0
var indent = 0
var character = value.charAt(index)
var stops = {}
var size
while (character === tab || character === space) {
size = character === tab ? tabSize : spaceSize
indent += size
if (size > 1) {
indent = Math.floor(indent / size) * size
}
stops[indent] = index
character = value.charAt(++index)
}
return {indent: indent, stops: stops}
}
|
javascript
|
function indentation(value) {
var index = 0
var indent = 0
var character = value.charAt(index)
var stops = {}
var size
while (character === tab || character === space) {
size = character === tab ? tabSize : spaceSize
indent += size
if (size > 1) {
indent = Math.floor(indent / size) * size
}
stops[indent] = index
character = value.charAt(++index)
}
return {indent: indent, stops: stops}
}
|
[
"function",
"indentation",
"(",
"value",
")",
"{",
"var",
"index",
"=",
"0",
"var",
"indent",
"=",
"0",
"var",
"character",
"=",
"value",
".",
"charAt",
"(",
"index",
")",
"var",
"stops",
"=",
"{",
"}",
"var",
"size",
"while",
"(",
"character",
"===",
"tab",
"||",
"character",
"===",
"space",
")",
"{",
"size",
"=",
"character",
"===",
"tab",
"?",
"tabSize",
":",
"spaceSize",
"indent",
"+=",
"size",
"if",
"(",
"size",
">",
"1",
")",
"{",
"indent",
"=",
"Math",
".",
"floor",
"(",
"indent",
"/",
"size",
")",
"*",
"size",
"}",
"stops",
"[",
"indent",
"]",
"=",
"index",
"character",
"=",
"value",
".",
"charAt",
"(",
"++",
"index",
")",
"}",
"return",
"{",
"indent",
":",
"indent",
",",
"stops",
":",
"stops",
"}",
"}"
] |
Gets indentation information for a line.
|
[
"Gets",
"indentation",
"information",
"for",
"a",
"line",
"."
] |
cca8385746c2f3489b2d491e91ab8c581901ae8a
|
https://github.com/remarkjs/remark/blob/cca8385746c2f3489b2d491e91ab8c581901ae8a/packages/remark-parse/lib/util/get-indentation.js#L12-L33
|
11,659
|
remarkjs/remark
|
packages/remark-stringify/lib/macro/all.js
|
all
|
function all(parent) {
var self = this
var children = parent.children
var length = children.length
var results = []
var index = -1
while (++index < length) {
results[index] = self.visit(children[index], parent)
}
return results
}
|
javascript
|
function all(parent) {
var self = this
var children = parent.children
var length = children.length
var results = []
var index = -1
while (++index < length) {
results[index] = self.visit(children[index], parent)
}
return results
}
|
[
"function",
"all",
"(",
"parent",
")",
"{",
"var",
"self",
"=",
"this",
"var",
"children",
"=",
"parent",
".",
"children",
"var",
"length",
"=",
"children",
".",
"length",
"var",
"results",
"=",
"[",
"]",
"var",
"index",
"=",
"-",
"1",
"while",
"(",
"++",
"index",
"<",
"length",
")",
"{",
"results",
"[",
"index",
"]",
"=",
"self",
".",
"visit",
"(",
"children",
"[",
"index",
"]",
",",
"parent",
")",
"}",
"return",
"results",
"}"
] |
Visit all children of `parent`.
|
[
"Visit",
"all",
"children",
"of",
"parent",
"."
] |
cca8385746c2f3489b2d491e91ab8c581901ae8a
|
https://github.com/remarkjs/remark/blob/cca8385746c2f3489b2d491e91ab8c581901ae8a/packages/remark-stringify/lib/macro/all.js#L6-L18
|
11,660
|
remarkjs/remark
|
packages/remark-parse/lib/unescape.js
|
factory
|
function factory(ctx, key) {
return unescape
// De-escape a string using the expression at `key` in `ctx`.
function unescape(value) {
var prev = 0
var index = value.indexOf(backslash)
var escape = ctx[key]
var queue = []
var character
while (index !== -1) {
queue.push(value.slice(prev, index))
prev = index + 1
character = value.charAt(prev)
// If the following character is not a valid escape, add the slash.
if (!character || escape.indexOf(character) === -1) {
queue.push(backslash)
}
index = value.indexOf(backslash, prev + 1)
}
queue.push(value.slice(prev))
return queue.join('')
}
}
|
javascript
|
function factory(ctx, key) {
return unescape
// De-escape a string using the expression at `key` in `ctx`.
function unescape(value) {
var prev = 0
var index = value.indexOf(backslash)
var escape = ctx[key]
var queue = []
var character
while (index !== -1) {
queue.push(value.slice(prev, index))
prev = index + 1
character = value.charAt(prev)
// If the following character is not a valid escape, add the slash.
if (!character || escape.indexOf(character) === -1) {
queue.push(backslash)
}
index = value.indexOf(backslash, prev + 1)
}
queue.push(value.slice(prev))
return queue.join('')
}
}
|
[
"function",
"factory",
"(",
"ctx",
",",
"key",
")",
"{",
"return",
"unescape",
"// De-escape a string using the expression at `key` in `ctx`.",
"function",
"unescape",
"(",
"value",
")",
"{",
"var",
"prev",
"=",
"0",
"var",
"index",
"=",
"value",
".",
"indexOf",
"(",
"backslash",
")",
"var",
"escape",
"=",
"ctx",
"[",
"key",
"]",
"var",
"queue",
"=",
"[",
"]",
"var",
"character",
"while",
"(",
"index",
"!==",
"-",
"1",
")",
"{",
"queue",
".",
"push",
"(",
"value",
".",
"slice",
"(",
"prev",
",",
"index",
")",
")",
"prev",
"=",
"index",
"+",
"1",
"character",
"=",
"value",
".",
"charAt",
"(",
"prev",
")",
"// If the following character is not a valid escape, add the slash.",
"if",
"(",
"!",
"character",
"||",
"escape",
".",
"indexOf",
"(",
"character",
")",
"===",
"-",
"1",
")",
"{",
"queue",
".",
"push",
"(",
"backslash",
")",
"}",
"index",
"=",
"value",
".",
"indexOf",
"(",
"backslash",
",",
"prev",
"+",
"1",
")",
"}",
"queue",
".",
"push",
"(",
"value",
".",
"slice",
"(",
"prev",
")",
")",
"return",
"queue",
".",
"join",
"(",
"''",
")",
"}",
"}"
] |
Factory to de-escape a value, based on a list at `key` in `ctx`.
|
[
"Factory",
"to",
"de",
"-",
"escape",
"a",
"value",
"based",
"on",
"a",
"list",
"at",
"key",
"in",
"ctx",
"."
] |
cca8385746c2f3489b2d491e91ab8c581901ae8a
|
https://github.com/remarkjs/remark/blob/cca8385746c2f3489b2d491e91ab8c581901ae8a/packages/remark-parse/lib/unescape.js#L8-L36
|
11,661
|
remarkjs/remark
|
packages/remark-parse/lib/tokenize/paragraph.js
|
paragraph
|
function paragraph(eat, value, silent) {
var self = this
var settings = self.options
var commonmark = settings.commonmark
var gfm = settings.gfm
var tokenizers = self.blockTokenizers
var interruptors = self.interruptParagraph
var index = value.indexOf(lineFeed)
var length = value.length
var position
var subvalue
var character
var size
var now
while (index < length) {
// Eat everything if there’s no following newline.
if (index === -1) {
index = length
break
}
// Stop if the next character is NEWLINE.
if (value.charAt(index + 1) === lineFeed) {
break
}
// In commonmark-mode, following indented lines are part of the paragraph.
if (commonmark) {
size = 0
position = index + 1
while (position < length) {
character = value.charAt(position)
if (character === tab) {
size = tabSize
break
} else if (character === space) {
size++
} else {
break
}
position++
}
if (size >= tabSize && character !== lineFeed) {
index = value.indexOf(lineFeed, index + 1)
continue
}
}
subvalue = value.slice(index + 1)
// Check if the following code contains a possible block.
if (interrupt(interruptors, tokenizers, self, [eat, subvalue, true])) {
break
}
// Break if the following line starts a list, when already in a list, or
// when in commonmark, or when in gfm mode and the bullet is *not* numeric.
if (
tokenizers.list.call(self, eat, subvalue, true) &&
(self.inList ||
commonmark ||
(gfm && !decimal(trim.left(subvalue).charAt(0))))
) {
break
}
position = index
index = value.indexOf(lineFeed, index + 1)
if (index !== -1 && trim(value.slice(position, index)) === '') {
index = position
break
}
}
subvalue = value.slice(0, index)
if (trim(subvalue) === '') {
eat(subvalue)
return null
}
/* istanbul ignore if - never used (yet) */
if (silent) {
return true
}
now = eat.now()
subvalue = trimTrailingLines(subvalue)
return eat(subvalue)({
type: 'paragraph',
children: self.tokenizeInline(subvalue, now)
})
}
|
javascript
|
function paragraph(eat, value, silent) {
var self = this
var settings = self.options
var commonmark = settings.commonmark
var gfm = settings.gfm
var tokenizers = self.blockTokenizers
var interruptors = self.interruptParagraph
var index = value.indexOf(lineFeed)
var length = value.length
var position
var subvalue
var character
var size
var now
while (index < length) {
// Eat everything if there’s no following newline.
if (index === -1) {
index = length
break
}
// Stop if the next character is NEWLINE.
if (value.charAt(index + 1) === lineFeed) {
break
}
// In commonmark-mode, following indented lines are part of the paragraph.
if (commonmark) {
size = 0
position = index + 1
while (position < length) {
character = value.charAt(position)
if (character === tab) {
size = tabSize
break
} else if (character === space) {
size++
} else {
break
}
position++
}
if (size >= tabSize && character !== lineFeed) {
index = value.indexOf(lineFeed, index + 1)
continue
}
}
subvalue = value.slice(index + 1)
// Check if the following code contains a possible block.
if (interrupt(interruptors, tokenizers, self, [eat, subvalue, true])) {
break
}
// Break if the following line starts a list, when already in a list, or
// when in commonmark, or when in gfm mode and the bullet is *not* numeric.
if (
tokenizers.list.call(self, eat, subvalue, true) &&
(self.inList ||
commonmark ||
(gfm && !decimal(trim.left(subvalue).charAt(0))))
) {
break
}
position = index
index = value.indexOf(lineFeed, index + 1)
if (index !== -1 && trim(value.slice(position, index)) === '') {
index = position
break
}
}
subvalue = value.slice(0, index)
if (trim(subvalue) === '') {
eat(subvalue)
return null
}
/* istanbul ignore if - never used (yet) */
if (silent) {
return true
}
now = eat.now()
subvalue = trimTrailingLines(subvalue)
return eat(subvalue)({
type: 'paragraph',
children: self.tokenizeInline(subvalue, now)
})
}
|
[
"function",
"paragraph",
"(",
"eat",
",",
"value",
",",
"silent",
")",
"{",
"var",
"self",
"=",
"this",
"var",
"settings",
"=",
"self",
".",
"options",
"var",
"commonmark",
"=",
"settings",
".",
"commonmark",
"var",
"gfm",
"=",
"settings",
".",
"gfm",
"var",
"tokenizers",
"=",
"self",
".",
"blockTokenizers",
"var",
"interruptors",
"=",
"self",
".",
"interruptParagraph",
"var",
"index",
"=",
"value",
".",
"indexOf",
"(",
"lineFeed",
")",
"var",
"length",
"=",
"value",
".",
"length",
"var",
"position",
"var",
"subvalue",
"var",
"character",
"var",
"size",
"var",
"now",
"while",
"(",
"index",
"<",
"length",
")",
"{",
"// Eat everything if there’s no following newline.",
"if",
"(",
"index",
"===",
"-",
"1",
")",
"{",
"index",
"=",
"length",
"break",
"}",
"// Stop if the next character is NEWLINE.",
"if",
"(",
"value",
".",
"charAt",
"(",
"index",
"+",
"1",
")",
"===",
"lineFeed",
")",
"{",
"break",
"}",
"// In commonmark-mode, following indented lines are part of the paragraph.",
"if",
"(",
"commonmark",
")",
"{",
"size",
"=",
"0",
"position",
"=",
"index",
"+",
"1",
"while",
"(",
"position",
"<",
"length",
")",
"{",
"character",
"=",
"value",
".",
"charAt",
"(",
"position",
")",
"if",
"(",
"character",
"===",
"tab",
")",
"{",
"size",
"=",
"tabSize",
"break",
"}",
"else",
"if",
"(",
"character",
"===",
"space",
")",
"{",
"size",
"++",
"}",
"else",
"{",
"break",
"}",
"position",
"++",
"}",
"if",
"(",
"size",
">=",
"tabSize",
"&&",
"character",
"!==",
"lineFeed",
")",
"{",
"index",
"=",
"value",
".",
"indexOf",
"(",
"lineFeed",
",",
"index",
"+",
"1",
")",
"continue",
"}",
"}",
"subvalue",
"=",
"value",
".",
"slice",
"(",
"index",
"+",
"1",
")",
"// Check if the following code contains a possible block.",
"if",
"(",
"interrupt",
"(",
"interruptors",
",",
"tokenizers",
",",
"self",
",",
"[",
"eat",
",",
"subvalue",
",",
"true",
"]",
")",
")",
"{",
"break",
"}",
"// Break if the following line starts a list, when already in a list, or",
"// when in commonmark, or when in gfm mode and the bullet is *not* numeric.",
"if",
"(",
"tokenizers",
".",
"list",
".",
"call",
"(",
"self",
",",
"eat",
",",
"subvalue",
",",
"true",
")",
"&&",
"(",
"self",
".",
"inList",
"||",
"commonmark",
"||",
"(",
"gfm",
"&&",
"!",
"decimal",
"(",
"trim",
".",
"left",
"(",
"subvalue",
")",
".",
"charAt",
"(",
"0",
")",
")",
")",
")",
")",
"{",
"break",
"}",
"position",
"=",
"index",
"index",
"=",
"value",
".",
"indexOf",
"(",
"lineFeed",
",",
"index",
"+",
"1",
")",
"if",
"(",
"index",
"!==",
"-",
"1",
"&&",
"trim",
"(",
"value",
".",
"slice",
"(",
"position",
",",
"index",
")",
")",
"===",
"''",
")",
"{",
"index",
"=",
"position",
"break",
"}",
"}",
"subvalue",
"=",
"value",
".",
"slice",
"(",
"0",
",",
"index",
")",
"if",
"(",
"trim",
"(",
"subvalue",
")",
"===",
"''",
")",
"{",
"eat",
"(",
"subvalue",
")",
"return",
"null",
"}",
"/* istanbul ignore if - never used (yet) */",
"if",
"(",
"silent",
")",
"{",
"return",
"true",
"}",
"now",
"=",
"eat",
".",
"now",
"(",
")",
"subvalue",
"=",
"trimTrailingLines",
"(",
"subvalue",
")",
"return",
"eat",
"(",
"subvalue",
")",
"(",
"{",
"type",
":",
"'paragraph'",
",",
"children",
":",
"self",
".",
"tokenizeInline",
"(",
"subvalue",
",",
"now",
")",
"}",
")",
"}"
] |
Tokenise paragraph.
|
[
"Tokenise",
"paragraph",
"."
] |
cca8385746c2f3489b2d491e91ab8c581901ae8a
|
https://github.com/remarkjs/remark/blob/cca8385746c2f3489b2d491e91ab8c581901ae8a/packages/remark-parse/lib/tokenize/paragraph.js#L17-L117
|
11,662
|
remarkjs/remark
|
packages/remark-parse/lib/parser.js
|
keys
|
function keys(value) {
var result = []
var key
for (key in value) {
result.push(key)
}
return result
}
|
javascript
|
function keys(value) {
var result = []
var key
for (key in value) {
result.push(key)
}
return result
}
|
[
"function",
"keys",
"(",
"value",
")",
"{",
"var",
"result",
"=",
"[",
"]",
"var",
"key",
"for",
"(",
"key",
"in",
"value",
")",
"{",
"result",
".",
"push",
"(",
"key",
")",
"}",
"return",
"result",
"}"
] |
Get all keys in `value`.
|
[
"Get",
"all",
"keys",
"in",
"value",
"."
] |
cca8385746c2f3489b2d491e91ab8c581901ae8a
|
https://github.com/remarkjs/remark/blob/cca8385746c2f3489b2d491e91ab8c581901ae8a/packages/remark-parse/lib/parser.js#L140-L149
|
11,663
|
remarkjs/remark
|
packages/remark-parse/lib/tokenizer.js
|
updatePosition
|
function updatePosition(subvalue) {
var lastIndex = -1
var index = subvalue.indexOf('\n')
while (index !== -1) {
line++
lastIndex = index
index = subvalue.indexOf('\n', index + 1)
}
if (lastIndex === -1) {
column += subvalue.length
} else {
column = subvalue.length - lastIndex
}
if (line in offset) {
if (lastIndex !== -1) {
column += offset[line]
} else if (column <= offset[line]) {
column = offset[line] + 1
}
}
}
|
javascript
|
function updatePosition(subvalue) {
var lastIndex = -1
var index = subvalue.indexOf('\n')
while (index !== -1) {
line++
lastIndex = index
index = subvalue.indexOf('\n', index + 1)
}
if (lastIndex === -1) {
column += subvalue.length
} else {
column = subvalue.length - lastIndex
}
if (line in offset) {
if (lastIndex !== -1) {
column += offset[line]
} else if (column <= offset[line]) {
column = offset[line] + 1
}
}
}
|
[
"function",
"updatePosition",
"(",
"subvalue",
")",
"{",
"var",
"lastIndex",
"=",
"-",
"1",
"var",
"index",
"=",
"subvalue",
".",
"indexOf",
"(",
"'\\n'",
")",
"while",
"(",
"index",
"!==",
"-",
"1",
")",
"{",
"line",
"++",
"lastIndex",
"=",
"index",
"index",
"=",
"subvalue",
".",
"indexOf",
"(",
"'\\n'",
",",
"index",
"+",
"1",
")",
"}",
"if",
"(",
"lastIndex",
"===",
"-",
"1",
")",
"{",
"column",
"+=",
"subvalue",
".",
"length",
"}",
"else",
"{",
"column",
"=",
"subvalue",
".",
"length",
"-",
"lastIndex",
"}",
"if",
"(",
"line",
"in",
"offset",
")",
"{",
"if",
"(",
"lastIndex",
"!==",
"-",
"1",
")",
"{",
"column",
"+=",
"offset",
"[",
"line",
"]",
"}",
"else",
"if",
"(",
"column",
"<=",
"offset",
"[",
"line",
"]",
")",
"{",
"column",
"=",
"offset",
"[",
"line",
"]",
"+",
"1",
"}",
"}",
"}"
] |
Update line, column, and offset based on `value`.
|
[
"Update",
"line",
"column",
"and",
"offset",
"based",
"on",
"value",
"."
] |
cca8385746c2f3489b2d491e91ab8c581901ae8a
|
https://github.com/remarkjs/remark/blob/cca8385746c2f3489b2d491e91ab8c581901ae8a/packages/remark-parse/lib/tokenizer.js#L79-L102
|
11,664
|
remarkjs/remark
|
packages/remark-parse/lib/tokenizer.js
|
now
|
function now() {
var pos = {line: line, column: column}
pos.offset = self.toOffset(pos)
return pos
}
|
javascript
|
function now() {
var pos = {line: line, column: column}
pos.offset = self.toOffset(pos)
return pos
}
|
[
"function",
"now",
"(",
")",
"{",
"var",
"pos",
"=",
"{",
"line",
":",
"line",
",",
"column",
":",
"column",
"}",
"pos",
".",
"offset",
"=",
"self",
".",
"toOffset",
"(",
"pos",
")",
"return",
"pos",
"}"
] |
Get the current position.
|
[
"Get",
"the",
"current",
"position",
"."
] |
cca8385746c2f3489b2d491e91ab8c581901ae8a
|
https://github.com/remarkjs/remark/blob/cca8385746c2f3489b2d491e91ab8c581901ae8a/packages/remark-parse/lib/tokenizer.js#L126-L132
|
11,665
|
remarkjs/remark
|
packages/remark-parse/lib/tokenizer.js
|
add
|
function add(node, parent) {
var children = parent ? parent.children : tokens
var prev = children[children.length - 1]
var fn
if (
prev &&
node.type === prev.type &&
(node.type === 'text' || node.type === 'blockquote') &&
mergeable(prev) &&
mergeable(node)
) {
fn = node.type === 'text' ? mergeText : mergeBlockquote
node = fn.call(self, prev, node)
}
if (node !== prev) {
children.push(node)
}
if (self.atStart && tokens.length !== 0) {
self.exitStart()
}
return node
}
|
javascript
|
function add(node, parent) {
var children = parent ? parent.children : tokens
var prev = children[children.length - 1]
var fn
if (
prev &&
node.type === prev.type &&
(node.type === 'text' || node.type === 'blockquote') &&
mergeable(prev) &&
mergeable(node)
) {
fn = node.type === 'text' ? mergeText : mergeBlockquote
node = fn.call(self, prev, node)
}
if (node !== prev) {
children.push(node)
}
if (self.atStart && tokens.length !== 0) {
self.exitStart()
}
return node
}
|
[
"function",
"add",
"(",
"node",
",",
"parent",
")",
"{",
"var",
"children",
"=",
"parent",
"?",
"parent",
".",
"children",
":",
"tokens",
"var",
"prev",
"=",
"children",
"[",
"children",
".",
"length",
"-",
"1",
"]",
"var",
"fn",
"if",
"(",
"prev",
"&&",
"node",
".",
"type",
"===",
"prev",
".",
"type",
"&&",
"(",
"node",
".",
"type",
"===",
"'text'",
"||",
"node",
".",
"type",
"===",
"'blockquote'",
")",
"&&",
"mergeable",
"(",
"prev",
")",
"&&",
"mergeable",
"(",
"node",
")",
")",
"{",
"fn",
"=",
"node",
".",
"type",
"===",
"'text'",
"?",
"mergeText",
":",
"mergeBlockquote",
"node",
"=",
"fn",
".",
"call",
"(",
"self",
",",
"prev",
",",
"node",
")",
"}",
"if",
"(",
"node",
"!==",
"prev",
")",
"{",
"children",
".",
"push",
"(",
"node",
")",
"}",
"if",
"(",
"self",
".",
"atStart",
"&&",
"tokens",
".",
"length",
"!==",
"0",
")",
"{",
"self",
".",
"exitStart",
"(",
")",
"}",
"return",
"node",
"}"
] |
Add `node` to `parent`s children or to `tokens`. Performs merges where possible.
|
[
"Add",
"node",
"to",
"parent",
"s",
"children",
"or",
"to",
"tokens",
".",
"Performs",
"merges",
"where",
"possible",
"."
] |
cca8385746c2f3489b2d491e91ab8c581901ae8a
|
https://github.com/remarkjs/remark/blob/cca8385746c2f3489b2d491e91ab8c581901ae8a/packages/remark-parse/lib/tokenizer.js#L198-L223
|
11,666
|
remarkjs/remark
|
packages/remark-parse/lib/tokenizer.js
|
eat
|
function eat(subvalue) {
var indent = getOffset()
var pos = position()
var current = now()
validateEat(subvalue)
apply.reset = reset
reset.test = test
apply.test = test
value = value.substring(subvalue.length)
updatePosition(subvalue)
indent = indent()
return apply
// Add the given arguments, add `position` to the returned node, and
// return the node.
function apply(node, parent) {
return pos(add(pos(node), parent), indent)
}
// Functions just like apply, but resets the content: the line and
// column are reversed, and the eaten value is re-added. This is
// useful for nodes with a single type of content, such as lists and
// tables. See `apply` above for what parameters are expected.
function reset() {
var node = apply.apply(null, arguments)
line = current.line
column = current.column
value = subvalue + value
return node
}
// Test the position, after eating, and reverse to a not-eaten state.
function test() {
var result = pos({})
line = current.line
column = current.column
value = subvalue + value
return result.position
}
}
|
javascript
|
function eat(subvalue) {
var indent = getOffset()
var pos = position()
var current = now()
validateEat(subvalue)
apply.reset = reset
reset.test = test
apply.test = test
value = value.substring(subvalue.length)
updatePosition(subvalue)
indent = indent()
return apply
// Add the given arguments, add `position` to the returned node, and
// return the node.
function apply(node, parent) {
return pos(add(pos(node), parent), indent)
}
// Functions just like apply, but resets the content: the line and
// column are reversed, and the eaten value is re-added. This is
// useful for nodes with a single type of content, such as lists and
// tables. See `apply` above for what parameters are expected.
function reset() {
var node = apply.apply(null, arguments)
line = current.line
column = current.column
value = subvalue + value
return node
}
// Test the position, after eating, and reverse to a not-eaten state.
function test() {
var result = pos({})
line = current.line
column = current.column
value = subvalue + value
return result.position
}
}
|
[
"function",
"eat",
"(",
"subvalue",
")",
"{",
"var",
"indent",
"=",
"getOffset",
"(",
")",
"var",
"pos",
"=",
"position",
"(",
")",
"var",
"current",
"=",
"now",
"(",
")",
"validateEat",
"(",
"subvalue",
")",
"apply",
".",
"reset",
"=",
"reset",
"reset",
".",
"test",
"=",
"test",
"apply",
".",
"test",
"=",
"test",
"value",
"=",
"value",
".",
"substring",
"(",
"subvalue",
".",
"length",
")",
"updatePosition",
"(",
"subvalue",
")",
"indent",
"=",
"indent",
"(",
")",
"return",
"apply",
"// Add the given arguments, add `position` to the returned node, and",
"// return the node.",
"function",
"apply",
"(",
"node",
",",
"parent",
")",
"{",
"return",
"pos",
"(",
"add",
"(",
"pos",
"(",
"node",
")",
",",
"parent",
")",
",",
"indent",
")",
"}",
"// Functions just like apply, but resets the content: the line and",
"// column are reversed, and the eaten value is re-added. This is",
"// useful for nodes with a single type of content, such as lists and",
"// tables. See `apply` above for what parameters are expected.",
"function",
"reset",
"(",
")",
"{",
"var",
"node",
"=",
"apply",
".",
"apply",
"(",
"null",
",",
"arguments",
")",
"line",
"=",
"current",
".",
"line",
"column",
"=",
"current",
".",
"column",
"value",
"=",
"subvalue",
"+",
"value",
"return",
"node",
"}",
"// Test the position, after eating, and reverse to a not-eaten state.",
"function",
"test",
"(",
")",
"{",
"var",
"result",
"=",
"pos",
"(",
"{",
"}",
")",
"line",
"=",
"current",
".",
"line",
"column",
"=",
"current",
".",
"column",
"value",
"=",
"subvalue",
"+",
"value",
"return",
"result",
".",
"position",
"}",
"}"
] |
Remove `subvalue` from `value`. `subvalue` must be at the start of `value`.
|
[
"Remove",
"subvalue",
"from",
"value",
".",
"subvalue",
"must",
"be",
"at",
"the",
"start",
"of",
"value",
"."
] |
cca8385746c2f3489b2d491e91ab8c581901ae8a
|
https://github.com/remarkjs/remark/blob/cca8385746c2f3489b2d491e91ab8c581901ae8a/packages/remark-parse/lib/tokenizer.js#L227-L276
|
11,667
|
remarkjs/remark
|
packages/remark-parse/lib/tokenizer.js
|
mergeable
|
function mergeable(node) {
var start
var end
if (node.type !== 'text' || !node.position) {
return true
}
start = node.position.start
end = node.position.end
// Only merge nodes which occupy the same size as their `value`.
return (
start.line !== end.line || end.column - start.column === node.value.length
)
}
|
javascript
|
function mergeable(node) {
var start
var end
if (node.type !== 'text' || !node.position) {
return true
}
start = node.position.start
end = node.position.end
// Only merge nodes which occupy the same size as their `value`.
return (
start.line !== end.line || end.column - start.column === node.value.length
)
}
|
[
"function",
"mergeable",
"(",
"node",
")",
"{",
"var",
"start",
"var",
"end",
"if",
"(",
"node",
".",
"type",
"!==",
"'text'",
"||",
"!",
"node",
".",
"position",
")",
"{",
"return",
"true",
"}",
"start",
"=",
"node",
".",
"position",
".",
"start",
"end",
"=",
"node",
".",
"position",
".",
"end",
"// Only merge nodes which occupy the same size as their `value`.",
"return",
"(",
"start",
".",
"line",
"!==",
"end",
".",
"line",
"||",
"end",
".",
"column",
"-",
"start",
".",
"column",
"===",
"node",
".",
"value",
".",
"length",
")",
"}"
] |
Check whether a node is mergeable with adjacent nodes.
|
[
"Check",
"whether",
"a",
"node",
"is",
"mergeable",
"with",
"adjacent",
"nodes",
"."
] |
cca8385746c2f3489b2d491e91ab8c581901ae8a
|
https://github.com/remarkjs/remark/blob/cca8385746c2f3489b2d491e91ab8c581901ae8a/packages/remark-parse/lib/tokenizer.js#L281-L296
|
11,668
|
remarkjs/remark
|
packages/remark-parse/lib/decode.js
|
factory
|
function factory(ctx) {
decoder.raw = decodeRaw
return decoder
// Normalize `position` to add an `indent`.
function normalize(position) {
var offsets = ctx.offset
var line = position.line
var result = []
while (++line) {
if (!(line in offsets)) {
break
}
result.push((offsets[line] || 0) + 1)
}
return {start: position, indent: result}
}
// Decode `value` (at `position`) into text-nodes.
function decoder(value, position, handler) {
entities(value, {
position: normalize(position),
warning: handleWarning,
text: handler,
reference: handler,
textContext: ctx,
referenceContext: ctx
})
}
// Decode `value` (at `position`) into a string.
function decodeRaw(value, position, options) {
return entities(
value,
xtend(options, {position: normalize(position), warning: handleWarning})
)
}
// Handle a warning.
// See <https://github.com/wooorm/parse-entities> for the warnings.
function handleWarning(reason, position, code) {
if (code !== 3) {
ctx.file.message(reason, position)
}
}
}
|
javascript
|
function factory(ctx) {
decoder.raw = decodeRaw
return decoder
// Normalize `position` to add an `indent`.
function normalize(position) {
var offsets = ctx.offset
var line = position.line
var result = []
while (++line) {
if (!(line in offsets)) {
break
}
result.push((offsets[line] || 0) + 1)
}
return {start: position, indent: result}
}
// Decode `value` (at `position`) into text-nodes.
function decoder(value, position, handler) {
entities(value, {
position: normalize(position),
warning: handleWarning,
text: handler,
reference: handler,
textContext: ctx,
referenceContext: ctx
})
}
// Decode `value` (at `position`) into a string.
function decodeRaw(value, position, options) {
return entities(
value,
xtend(options, {position: normalize(position), warning: handleWarning})
)
}
// Handle a warning.
// See <https://github.com/wooorm/parse-entities> for the warnings.
function handleWarning(reason, position, code) {
if (code !== 3) {
ctx.file.message(reason, position)
}
}
}
|
[
"function",
"factory",
"(",
"ctx",
")",
"{",
"decoder",
".",
"raw",
"=",
"decodeRaw",
"return",
"decoder",
"// Normalize `position` to add an `indent`.",
"function",
"normalize",
"(",
"position",
")",
"{",
"var",
"offsets",
"=",
"ctx",
".",
"offset",
"var",
"line",
"=",
"position",
".",
"line",
"var",
"result",
"=",
"[",
"]",
"while",
"(",
"++",
"line",
")",
"{",
"if",
"(",
"!",
"(",
"line",
"in",
"offsets",
")",
")",
"{",
"break",
"}",
"result",
".",
"push",
"(",
"(",
"offsets",
"[",
"line",
"]",
"||",
"0",
")",
"+",
"1",
")",
"}",
"return",
"{",
"start",
":",
"position",
",",
"indent",
":",
"result",
"}",
"}",
"// Decode `value` (at `position`) into text-nodes.",
"function",
"decoder",
"(",
"value",
",",
"position",
",",
"handler",
")",
"{",
"entities",
"(",
"value",
",",
"{",
"position",
":",
"normalize",
"(",
"position",
")",
",",
"warning",
":",
"handleWarning",
",",
"text",
":",
"handler",
",",
"reference",
":",
"handler",
",",
"textContext",
":",
"ctx",
",",
"referenceContext",
":",
"ctx",
"}",
")",
"}",
"// Decode `value` (at `position`) into a string.",
"function",
"decodeRaw",
"(",
"value",
",",
"position",
",",
"options",
")",
"{",
"return",
"entities",
"(",
"value",
",",
"xtend",
"(",
"options",
",",
"{",
"position",
":",
"normalize",
"(",
"position",
")",
",",
"warning",
":",
"handleWarning",
"}",
")",
")",
"}",
"// Handle a warning.",
"// See <https://github.com/wooorm/parse-entities> for the warnings.",
"function",
"handleWarning",
"(",
"reason",
",",
"position",
",",
"code",
")",
"{",
"if",
"(",
"code",
"!==",
"3",
")",
"{",
"ctx",
".",
"file",
".",
"message",
"(",
"reason",
",",
"position",
")",
"}",
"}",
"}"
] |
Factory to create an entity decoder.
|
[
"Factory",
"to",
"create",
"an",
"entity",
"decoder",
"."
] |
cca8385746c2f3489b2d491e91ab8c581901ae8a
|
https://github.com/remarkjs/remark/blob/cca8385746c2f3489b2d491e91ab8c581901ae8a/packages/remark-parse/lib/decode.js#L9-L58
|
11,669
|
remarkjs/remark
|
packages/remark-parse/lib/decode.js
|
normalize
|
function normalize(position) {
var offsets = ctx.offset
var line = position.line
var result = []
while (++line) {
if (!(line in offsets)) {
break
}
result.push((offsets[line] || 0) + 1)
}
return {start: position, indent: result}
}
|
javascript
|
function normalize(position) {
var offsets = ctx.offset
var line = position.line
var result = []
while (++line) {
if (!(line in offsets)) {
break
}
result.push((offsets[line] || 0) + 1)
}
return {start: position, indent: result}
}
|
[
"function",
"normalize",
"(",
"position",
")",
"{",
"var",
"offsets",
"=",
"ctx",
".",
"offset",
"var",
"line",
"=",
"position",
".",
"line",
"var",
"result",
"=",
"[",
"]",
"while",
"(",
"++",
"line",
")",
"{",
"if",
"(",
"!",
"(",
"line",
"in",
"offsets",
")",
")",
"{",
"break",
"}",
"result",
".",
"push",
"(",
"(",
"offsets",
"[",
"line",
"]",
"||",
"0",
")",
"+",
"1",
")",
"}",
"return",
"{",
"start",
":",
"position",
",",
"indent",
":",
"result",
"}",
"}"
] |
Normalize `position` to add an `indent`.
|
[
"Normalize",
"position",
"to",
"add",
"an",
"indent",
"."
] |
cca8385746c2f3489b2d491e91ab8c581901ae8a
|
https://github.com/remarkjs/remark/blob/cca8385746c2f3489b2d491e91ab8c581901ae8a/packages/remark-parse/lib/decode.js#L15-L29
|
11,670
|
remarkjs/remark
|
packages/remark-stringify/lib/set-options.js
|
setOptions
|
function setOptions(options) {
var self = this
var current = self.options
var ruleRepetition
var key
if (options == null) {
options = {}
} else if (typeof options === 'object') {
options = xtend(options)
} else {
throw new Error('Invalid value `' + options + '` for setting `options`')
}
for (key in defaults) {
validate[typeof defaults[key]](options, key, current[key], maps[key])
}
ruleRepetition = options.ruleRepetition
if (ruleRepetition && ruleRepetition < 3) {
raise(ruleRepetition, 'options.ruleRepetition')
}
self.encode = encodeFactory(String(options.entities))
self.escape = escapeFactory(options)
self.options = options
return self
}
|
javascript
|
function setOptions(options) {
var self = this
var current = self.options
var ruleRepetition
var key
if (options == null) {
options = {}
} else if (typeof options === 'object') {
options = xtend(options)
} else {
throw new Error('Invalid value `' + options + '` for setting `options`')
}
for (key in defaults) {
validate[typeof defaults[key]](options, key, current[key], maps[key])
}
ruleRepetition = options.ruleRepetition
if (ruleRepetition && ruleRepetition < 3) {
raise(ruleRepetition, 'options.ruleRepetition')
}
self.encode = encodeFactory(String(options.entities))
self.escape = escapeFactory(options)
self.options = options
return self
}
|
[
"function",
"setOptions",
"(",
"options",
")",
"{",
"var",
"self",
"=",
"this",
"var",
"current",
"=",
"self",
".",
"options",
"var",
"ruleRepetition",
"var",
"key",
"if",
"(",
"options",
"==",
"null",
")",
"{",
"options",
"=",
"{",
"}",
"}",
"else",
"if",
"(",
"typeof",
"options",
"===",
"'object'",
")",
"{",
"options",
"=",
"xtend",
"(",
"options",
")",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"'Invalid value `'",
"+",
"options",
"+",
"'` for setting `options`'",
")",
"}",
"for",
"(",
"key",
"in",
"defaults",
")",
"{",
"validate",
"[",
"typeof",
"defaults",
"[",
"key",
"]",
"]",
"(",
"options",
",",
"key",
",",
"current",
"[",
"key",
"]",
",",
"maps",
"[",
"key",
"]",
")",
"}",
"ruleRepetition",
"=",
"options",
".",
"ruleRepetition",
"if",
"(",
"ruleRepetition",
"&&",
"ruleRepetition",
"<",
"3",
")",
"{",
"raise",
"(",
"ruleRepetition",
",",
"'options.ruleRepetition'",
")",
"}",
"self",
".",
"encode",
"=",
"encodeFactory",
"(",
"String",
"(",
"options",
".",
"entities",
")",
")",
"self",
".",
"escape",
"=",
"escapeFactory",
"(",
"options",
")",
"self",
".",
"options",
"=",
"options",
"return",
"self",
"}"
] |
Set options. Does not overwrite previously set options.
|
[
"Set",
"options",
".",
"Does",
"not",
"overwrite",
"previously",
"set",
"options",
"."
] |
cca8385746c2f3489b2d491e91ab8c581901ae8a
|
https://github.com/remarkjs/remark/blob/cca8385746c2f3489b2d491e91ab8c581901ae8a/packages/remark-stringify/lib/set-options.js#L31-L61
|
11,671
|
remarkjs/remark
|
packages/remark-stringify/lib/set-options.js
|
encodeFactory
|
function encodeFactory(type) {
var options = {}
if (type === 'false') {
return identity
}
if (type === 'true') {
options.useNamedReferences = true
}
if (type === 'escape') {
options.escapeOnly = true
options.useNamedReferences = true
}
return wrapped
// Encode HTML entities using the bound options.
function wrapped(value) {
return encode(value, options)
}
}
|
javascript
|
function encodeFactory(type) {
var options = {}
if (type === 'false') {
return identity
}
if (type === 'true') {
options.useNamedReferences = true
}
if (type === 'escape') {
options.escapeOnly = true
options.useNamedReferences = true
}
return wrapped
// Encode HTML entities using the bound options.
function wrapped(value) {
return encode(value, options)
}
}
|
[
"function",
"encodeFactory",
"(",
"type",
")",
"{",
"var",
"options",
"=",
"{",
"}",
"if",
"(",
"type",
"===",
"'false'",
")",
"{",
"return",
"identity",
"}",
"if",
"(",
"type",
"===",
"'true'",
")",
"{",
"options",
".",
"useNamedReferences",
"=",
"true",
"}",
"if",
"(",
"type",
"===",
"'escape'",
")",
"{",
"options",
".",
"escapeOnly",
"=",
"true",
"options",
".",
"useNamedReferences",
"=",
"true",
"}",
"return",
"wrapped",
"// Encode HTML entities using the bound options.",
"function",
"wrapped",
"(",
"value",
")",
"{",
"return",
"encode",
"(",
"value",
",",
"options",
")",
"}",
"}"
] |
Factory to encode HTML entities. Creates a no-operation function when `type` is `'false'`, a function which encodes using named references when `type` is `'true'`, and a function which encodes using numbered references when `type` is `'numbers'`.
|
[
"Factory",
"to",
"encode",
"HTML",
"entities",
".",
"Creates",
"a",
"no",
"-",
"operation",
"function",
"when",
"type",
"is",
"false",
"a",
"function",
"which",
"encodes",
"using",
"named",
"references",
"when",
"type",
"is",
"true",
"and",
"a",
"function",
"which",
"encodes",
"using",
"numbered",
"references",
"when",
"type",
"is",
"numbers",
"."
] |
cca8385746c2f3489b2d491e91ab8c581901ae8a
|
https://github.com/remarkjs/remark/blob/cca8385746c2f3489b2d491e91ab8c581901ae8a/packages/remark-stringify/lib/set-options.js#L133-L155
|
11,672
|
CuppaLabs/angular2-multiselect-dropdown
|
docs/vendor.js
|
getLocaleDateTimeFormat
|
function getLocaleDateTimeFormat(locale, width) {
var data = findLocaleData(locale);
var dateTimeFormatData = data[12 /* DateTimeFormat */];
return getLastDefinedValue(dateTimeFormatData, width);
}
|
javascript
|
function getLocaleDateTimeFormat(locale, width) {
var data = findLocaleData(locale);
var dateTimeFormatData = data[12 /* DateTimeFormat */];
return getLastDefinedValue(dateTimeFormatData, width);
}
|
[
"function",
"getLocaleDateTimeFormat",
"(",
"locale",
",",
"width",
")",
"{",
"var",
"data",
"=",
"findLocaleData",
"(",
"locale",
")",
";",
"var",
"dateTimeFormatData",
"=",
"data",
"[",
"12",
"/* DateTimeFormat */",
"]",
";",
"return",
"getLastDefinedValue",
"(",
"dateTimeFormatData",
",",
"width",
")",
";",
"}"
] |
Date-time format that depends on the locale.
The date-time pattern shows how to combine separate patterns for date (represented by {1})
and time (represented by {0}) into a single pattern. It usually doesn't need to be changed.
What you want to pay attention to are:
- possibly removing a space for languages that don't use it, such as many East Asian languages
- possibly adding a comma, other punctuation, or a combining word
For example:
- English uses `{1} 'at' {0}` or `{1}, {0}` (depending on date style), while Japanese uses
`{1}{0}`.
- An English formatted date-time using the combining pattern `{1}, {0}` could be
`Dec 10, 2010, 3:59:49 PM`. Notice the comma and space between the date portion and the time
portion.
There are four formats (`full`, `long`, `medium`, `short`); the determination of which to use
is normally based on the date style. For example, if the date has a full month and weekday
name, the full combining pattern will be used to combine that with a time. If the date has
numeric month, the short version of the combining pattern will be used to combine that with a
time. English uses `{1} 'at' {0}` for full and long styles, and `{1}, {0}` for medium and short
styles.
@experimental i18n support is experimental.
|
[
"Date",
"-",
"time",
"format",
"that",
"depends",
"on",
"the",
"locale",
"."
] |
cb94eb9af46de79c69d61b4fd37a800009fb70d3
|
https://github.com/CuppaLabs/angular2-multiselect-dropdown/blob/cb94eb9af46de79c69d61b4fd37a800009fb70d3/docs/vendor.js#L1057-L1061
|
11,673
|
CuppaLabs/angular2-multiselect-dropdown
|
docs/vendor.js
|
getLastDefinedValue
|
function getLastDefinedValue(data, index) {
for (var i = index; i > -1; i--) {
if (typeof data[i] !== 'undefined') {
return data[i];
}
}
throw new Error('Locale data API: locale data undefined');
}
|
javascript
|
function getLastDefinedValue(data, index) {
for (var i = index; i > -1; i--) {
if (typeof data[i] !== 'undefined') {
return data[i];
}
}
throw new Error('Locale data API: locale data undefined');
}
|
[
"function",
"getLastDefinedValue",
"(",
"data",
",",
"index",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"index",
";",
"i",
">",
"-",
"1",
";",
"i",
"--",
")",
"{",
"if",
"(",
"typeof",
"data",
"[",
"i",
"]",
"!==",
"'undefined'",
")",
"{",
"return",
"data",
"[",
"i",
"]",
";",
"}",
"}",
"throw",
"new",
"Error",
"(",
"'Locale data API: locale data undefined'",
")",
";",
"}"
] |
Returns the first value that is defined in an array, going backwards.
To avoid repeating the same data (e.g. when "format" and "standalone" are the same) we only
add the first one to the locale data arrays, the other ones are only defined when different.
We use this function to retrieve the first defined value.
@experimental i18n support is experimental.
|
[
"Returns",
"the",
"first",
"value",
"that",
"is",
"defined",
"in",
"an",
"array",
"going",
"backwards",
"."
] |
cb94eb9af46de79c69d61b4fd37a800009fb70d3
|
https://github.com/CuppaLabs/angular2-multiselect-dropdown/blob/cb94eb9af46de79c69d61b4fd37a800009fb70d3/docs/vendor.js#L1218-L1225
|
11,674
|
CuppaLabs/angular2-multiselect-dropdown
|
docs/vendor.js
|
findLocaleData
|
function findLocaleData(locale) {
var normalizedLocale = locale.toLowerCase().replace(/_/g, '-');
var match = LOCALE_DATA[normalizedLocale];
if (match) {
return match;
}
// let's try to find a parent locale
var parentLocale = normalizedLocale.split('-')[0];
match = LOCALE_DATA[parentLocale];
if (match) {
return match;
}
if (parentLocale === 'en') {
return localeEn;
}
throw new Error("Missing locale data for the locale \"" + locale + "\".");
}
|
javascript
|
function findLocaleData(locale) {
var normalizedLocale = locale.toLowerCase().replace(/_/g, '-');
var match = LOCALE_DATA[normalizedLocale];
if (match) {
return match;
}
// let's try to find a parent locale
var parentLocale = normalizedLocale.split('-')[0];
match = LOCALE_DATA[parentLocale];
if (match) {
return match;
}
if (parentLocale === 'en') {
return localeEn;
}
throw new Error("Missing locale data for the locale \"" + locale + "\".");
}
|
[
"function",
"findLocaleData",
"(",
"locale",
")",
"{",
"var",
"normalizedLocale",
"=",
"locale",
".",
"toLowerCase",
"(",
")",
".",
"replace",
"(",
"/",
"_",
"/",
"g",
",",
"'-'",
")",
";",
"var",
"match",
"=",
"LOCALE_DATA",
"[",
"normalizedLocale",
"]",
";",
"if",
"(",
"match",
")",
"{",
"return",
"match",
";",
"}",
"// let's try to find a parent locale",
"var",
"parentLocale",
"=",
"normalizedLocale",
".",
"split",
"(",
"'-'",
")",
"[",
"0",
"]",
";",
"match",
"=",
"LOCALE_DATA",
"[",
"parentLocale",
"]",
";",
"if",
"(",
"match",
")",
"{",
"return",
"match",
";",
"}",
"if",
"(",
"parentLocale",
"===",
"'en'",
")",
"{",
"return",
"localeEn",
";",
"}",
"throw",
"new",
"Error",
"(",
"\"Missing locale data for the locale \\\"\"",
"+",
"locale",
"+",
"\"\\\".\"",
")",
";",
"}"
] |
Finds the locale data for a locale id
@experimental i18n support is experimental.
|
[
"Finds",
"the",
"locale",
"data",
"for",
"a",
"locale",
"id"
] |
cb94eb9af46de79c69d61b4fd37a800009fb70d3
|
https://github.com/CuppaLabs/angular2-multiselect-dropdown/blob/cb94eb9af46de79c69d61b4fd37a800009fb70d3/docs/vendor.js#L1238-L1254
|
11,675
|
CuppaLabs/angular2-multiselect-dropdown
|
docs/vendor.js
|
getNumberOfCurrencyDigits
|
function getNumberOfCurrencyDigits(code) {
var digits;
var currency = CURRENCIES_EN[code];
if (currency) {
digits = currency[2 /* NbOfDigits */];
}
return typeof digits === 'number' ? digits : DEFAULT_NB_OF_CURRENCY_DIGITS;
}
|
javascript
|
function getNumberOfCurrencyDigits(code) {
var digits;
var currency = CURRENCIES_EN[code];
if (currency) {
digits = currency[2 /* NbOfDigits */];
}
return typeof digits === 'number' ? digits : DEFAULT_NB_OF_CURRENCY_DIGITS;
}
|
[
"function",
"getNumberOfCurrencyDigits",
"(",
"code",
")",
"{",
"var",
"digits",
";",
"var",
"currency",
"=",
"CURRENCIES_EN",
"[",
"code",
"]",
";",
"if",
"(",
"currency",
")",
"{",
"digits",
"=",
"currency",
"[",
"2",
"/* NbOfDigits */",
"]",
";",
"}",
"return",
"typeof",
"digits",
"===",
"'number'",
"?",
"digits",
":",
"DEFAULT_NB_OF_CURRENCY_DIGITS",
";",
"}"
] |
Returns the number of decimal digits for the given currency.
Its value depends upon the presence of cents in that particular currency.
@experimental i18n support is experimental.
|
[
"Returns",
"the",
"number",
"of",
"decimal",
"digits",
"for",
"the",
"given",
"currency",
".",
"Its",
"value",
"depends",
"upon",
"the",
"presence",
"of",
"cents",
"in",
"that",
"particular",
"currency",
"."
] |
cb94eb9af46de79c69d61b4fd37a800009fb70d3
|
https://github.com/CuppaLabs/angular2-multiselect-dropdown/blob/cb94eb9af46de79c69d61b4fd37a800009fb70d3/docs/vendor.js#L1279-L1286
|
11,676
|
CuppaLabs/angular2-multiselect-dropdown
|
docs/vendor.js
|
dateStrGetter
|
function dateStrGetter(name, width, form, extended) {
if (form === void 0) { form = FormStyle.Format; }
if (extended === void 0) { extended = false; }
return function (date, locale) {
return getDateTranslation(date, locale, name, width, form, extended);
};
}
|
javascript
|
function dateStrGetter(name, width, form, extended) {
if (form === void 0) { form = FormStyle.Format; }
if (extended === void 0) { extended = false; }
return function (date, locale) {
return getDateTranslation(date, locale, name, width, form, extended);
};
}
|
[
"function",
"dateStrGetter",
"(",
"name",
",",
"width",
",",
"form",
",",
"extended",
")",
"{",
"if",
"(",
"form",
"===",
"void",
"0",
")",
"{",
"form",
"=",
"FormStyle",
".",
"Format",
";",
"}",
"if",
"(",
"extended",
"===",
"void",
"0",
")",
"{",
"extended",
"=",
"false",
";",
"}",
"return",
"function",
"(",
"date",
",",
"locale",
")",
"{",
"return",
"getDateTranslation",
"(",
"date",
",",
"locale",
",",
"name",
",",
"width",
",",
"form",
",",
"extended",
")",
";",
"}",
";",
"}"
] |
Returns a date formatter that transforms a date into its locale string representation
|
[
"Returns",
"a",
"date",
"formatter",
"that",
"transforms",
"a",
"date",
"into",
"its",
"locale",
"string",
"representation"
] |
cb94eb9af46de79c69d61b4fd37a800009fb70d3
|
https://github.com/CuppaLabs/angular2-multiselect-dropdown/blob/cb94eb9af46de79c69d61b4fd37a800009fb70d3/docs/vendor.js#L1519-L1525
|
11,677
|
CuppaLabs/angular2-multiselect-dropdown
|
docs/vendor.js
|
toDate
|
function toDate(value) {
if (isDate(value)) {
return value;
}
if (typeof value === 'number' && !isNaN(value)) {
return new Date(value);
}
if (typeof value === 'string') {
value = value.trim();
var parsedNb = parseFloat(value);
// any string that only contains numbers, like "1234" but not like "1234hello"
if (!isNaN(value - parsedNb)) {
return new Date(parsedNb);
}
if (/^(\d{4}-\d{1,2}-\d{1,2})$/.test(value)) {
/* For ISO Strings without time the day, month and year must be extracted from the ISO String
before Date creation to avoid time offset and errors in the new Date.
If we only replace '-' with ',' in the ISO String ("2015,01,01"), and try to create a new
date, some browsers (e.g. IE 9) will throw an invalid Date error.
If we leave the '-' ("2015-01-01") and try to create a new Date("2015-01-01") the timeoffset
is applied.
Note: ISO months are 0 for January, 1 for February, ... */
var _a = Object(tslib__WEBPACK_IMPORTED_MODULE_1__["__read"])(value.split('-').map(function (val) { return +val; }), 3), y = _a[0], m = _a[1], d = _a[2];
return new Date(y, m - 1, d);
}
var match = void 0;
if (match = value.match(ISO8601_DATE_REGEX)) {
return isoStringToDate(match);
}
}
var date = new Date(value);
if (!isDate(date)) {
throw new Error("Unable to convert \"" + value + "\" into a date");
}
return date;
}
|
javascript
|
function toDate(value) {
if (isDate(value)) {
return value;
}
if (typeof value === 'number' && !isNaN(value)) {
return new Date(value);
}
if (typeof value === 'string') {
value = value.trim();
var parsedNb = parseFloat(value);
// any string that only contains numbers, like "1234" but not like "1234hello"
if (!isNaN(value - parsedNb)) {
return new Date(parsedNb);
}
if (/^(\d{4}-\d{1,2}-\d{1,2})$/.test(value)) {
/* For ISO Strings without time the day, month and year must be extracted from the ISO String
before Date creation to avoid time offset and errors in the new Date.
If we only replace '-' with ',' in the ISO String ("2015,01,01"), and try to create a new
date, some browsers (e.g. IE 9) will throw an invalid Date error.
If we leave the '-' ("2015-01-01") and try to create a new Date("2015-01-01") the timeoffset
is applied.
Note: ISO months are 0 for January, 1 for February, ... */
var _a = Object(tslib__WEBPACK_IMPORTED_MODULE_1__["__read"])(value.split('-').map(function (val) { return +val; }), 3), y = _a[0], m = _a[1], d = _a[2];
return new Date(y, m - 1, d);
}
var match = void 0;
if (match = value.match(ISO8601_DATE_REGEX)) {
return isoStringToDate(match);
}
}
var date = new Date(value);
if (!isDate(date)) {
throw new Error("Unable to convert \"" + value + "\" into a date");
}
return date;
}
|
[
"function",
"toDate",
"(",
"value",
")",
"{",
"if",
"(",
"isDate",
"(",
"value",
")",
")",
"{",
"return",
"value",
";",
"}",
"if",
"(",
"typeof",
"value",
"===",
"'number'",
"&&",
"!",
"isNaN",
"(",
"value",
")",
")",
"{",
"return",
"new",
"Date",
"(",
"value",
")",
";",
"}",
"if",
"(",
"typeof",
"value",
"===",
"'string'",
")",
"{",
"value",
"=",
"value",
".",
"trim",
"(",
")",
";",
"var",
"parsedNb",
"=",
"parseFloat",
"(",
"value",
")",
";",
"// any string that only contains numbers, like \"1234\" but not like \"1234hello\"",
"if",
"(",
"!",
"isNaN",
"(",
"value",
"-",
"parsedNb",
")",
")",
"{",
"return",
"new",
"Date",
"(",
"parsedNb",
")",
";",
"}",
"if",
"(",
"/",
"^(\\d{4}-\\d{1,2}-\\d{1,2})$",
"/",
".",
"test",
"(",
"value",
")",
")",
"{",
"/* For ISO Strings without time the day, month and year must be extracted from the ISO String\n before Date creation to avoid time offset and errors in the new Date.\n If we only replace '-' with ',' in the ISO String (\"2015,01,01\"), and try to create a new\n date, some browsers (e.g. IE 9) will throw an invalid Date error.\n If we leave the '-' (\"2015-01-01\") and try to create a new Date(\"2015-01-01\") the timeoffset\n is applied.\n Note: ISO months are 0 for January, 1 for February, ... */",
"var",
"_a",
"=",
"Object",
"(",
"tslib__WEBPACK_IMPORTED_MODULE_1__",
"[",
"\"__read\"",
"]",
")",
"(",
"value",
".",
"split",
"(",
"'-'",
")",
".",
"map",
"(",
"function",
"(",
"val",
")",
"{",
"return",
"+",
"val",
";",
"}",
")",
",",
"3",
")",
",",
"y",
"=",
"_a",
"[",
"0",
"]",
",",
"m",
"=",
"_a",
"[",
"1",
"]",
",",
"d",
"=",
"_a",
"[",
"2",
"]",
";",
"return",
"new",
"Date",
"(",
"y",
",",
"m",
"-",
"1",
",",
"d",
")",
";",
"}",
"var",
"match",
"=",
"void",
"0",
";",
"if",
"(",
"match",
"=",
"value",
".",
"match",
"(",
"ISO8601_DATE_REGEX",
")",
")",
"{",
"return",
"isoStringToDate",
"(",
"match",
")",
";",
"}",
"}",
"var",
"date",
"=",
"new",
"Date",
"(",
"value",
")",
";",
"if",
"(",
"!",
"isDate",
"(",
"date",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Unable to convert \\\"\"",
"+",
"value",
"+",
"\"\\\" into a date\"",
")",
";",
"}",
"return",
"date",
";",
"}"
] |
Converts a value to date.
Supported input formats:
- `Date`
- number: timestamp
- string: numeric (e.g. "1234"), ISO and date strings in a format supported by
[Date.parse()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse).
Note: ISO strings without time return a date without timeoffset.
Throws if unable to convert to a date.
|
[
"Converts",
"a",
"value",
"to",
"date",
"."
] |
cb94eb9af46de79c69d61b4fd37a800009fb70d3
|
https://github.com/CuppaLabs/angular2-multiselect-dropdown/blob/cb94eb9af46de79c69d61b4fd37a800009fb70d3/docs/vendor.js#L1879-L1914
|
11,678
|
CuppaLabs/angular2-multiselect-dropdown
|
docs/vendor.js
|
toPercent
|
function toPercent(parsedNumber) {
// if the number is 0, don't do anything
if (parsedNumber.digits[0] === 0) {
return parsedNumber;
}
// Getting the current number of decimals
var fractionLen = parsedNumber.digits.length - parsedNumber.integerLen;
if (parsedNumber.exponent) {
parsedNumber.exponent += 2;
}
else {
if (fractionLen === 0) {
parsedNumber.digits.push(0, 0);
}
else if (fractionLen === 1) {
parsedNumber.digits.push(0);
}
parsedNumber.integerLen += 2;
}
return parsedNumber;
}
|
javascript
|
function toPercent(parsedNumber) {
// if the number is 0, don't do anything
if (parsedNumber.digits[0] === 0) {
return parsedNumber;
}
// Getting the current number of decimals
var fractionLen = parsedNumber.digits.length - parsedNumber.integerLen;
if (parsedNumber.exponent) {
parsedNumber.exponent += 2;
}
else {
if (fractionLen === 0) {
parsedNumber.digits.push(0, 0);
}
else if (fractionLen === 1) {
parsedNumber.digits.push(0);
}
parsedNumber.integerLen += 2;
}
return parsedNumber;
}
|
[
"function",
"toPercent",
"(",
"parsedNumber",
")",
"{",
"// if the number is 0, don't do anything",
"if",
"(",
"parsedNumber",
".",
"digits",
"[",
"0",
"]",
"===",
"0",
")",
"{",
"return",
"parsedNumber",
";",
"}",
"// Getting the current number of decimals",
"var",
"fractionLen",
"=",
"parsedNumber",
".",
"digits",
".",
"length",
"-",
"parsedNumber",
".",
"integerLen",
";",
"if",
"(",
"parsedNumber",
".",
"exponent",
")",
"{",
"parsedNumber",
".",
"exponent",
"+=",
"2",
";",
"}",
"else",
"{",
"if",
"(",
"fractionLen",
"===",
"0",
")",
"{",
"parsedNumber",
".",
"digits",
".",
"push",
"(",
"0",
",",
"0",
")",
";",
"}",
"else",
"if",
"(",
"fractionLen",
"===",
"1",
")",
"{",
"parsedNumber",
".",
"digits",
".",
"push",
"(",
"0",
")",
";",
"}",
"parsedNumber",
".",
"integerLen",
"+=",
"2",
";",
"}",
"return",
"parsedNumber",
";",
"}"
] |
Transforms a parsed number into a percentage by multiplying it by 100
|
[
"Transforms",
"a",
"parsed",
"number",
"into",
"a",
"percentage",
"by",
"multiplying",
"it",
"by",
"100"
] |
cb94eb9af46de79c69d61b4fd37a800009fb70d3
|
https://github.com/CuppaLabs/angular2-multiselect-dropdown/blob/cb94eb9af46de79c69d61b4fd37a800009fb70d3/docs/vendor.js#L2165-L2185
|
11,679
|
CuppaLabs/angular2-multiselect-dropdown
|
docs/vendor.js
|
HttpHeaderResponse
|
function HttpHeaderResponse(init) {
if (init === void 0) { init = {}; }
var _this = _super.call(this, init) || this;
_this.type = HttpEventType.ResponseHeader;
return _this;
}
|
javascript
|
function HttpHeaderResponse(init) {
if (init === void 0) { init = {}; }
var _this = _super.call(this, init) || this;
_this.type = HttpEventType.ResponseHeader;
return _this;
}
|
[
"function",
"HttpHeaderResponse",
"(",
"init",
")",
"{",
"if",
"(",
"init",
"===",
"void",
"0",
")",
"{",
"init",
"=",
"{",
"}",
";",
"}",
"var",
"_this",
"=",
"_super",
".",
"call",
"(",
"this",
",",
"init",
")",
"||",
"this",
";",
"_this",
".",
"type",
"=",
"HttpEventType",
".",
"ResponseHeader",
";",
"return",
"_this",
";",
"}"
] |
Create a new `HttpHeaderResponse` with the given parameters.
|
[
"Create",
"a",
"new",
"HttpHeaderResponse",
"with",
"the",
"given",
"parameters",
"."
] |
cb94eb9af46de79c69d61b4fd37a800009fb70d3
|
https://github.com/CuppaLabs/angular2-multiselect-dropdown/blob/cb94eb9af46de79c69d61b4fd37a800009fb70d3/docs/vendor.js#L6709-L6714
|
11,680
|
CuppaLabs/angular2-multiselect-dropdown
|
docs/vendor.js
|
HttpResponse
|
function HttpResponse(init) {
if (init === void 0) { init = {}; }
var _this = _super.call(this, init) || this;
_this.type = HttpEventType.Response;
_this.body = init.body !== undefined ? init.body : null;
return _this;
}
|
javascript
|
function HttpResponse(init) {
if (init === void 0) { init = {}; }
var _this = _super.call(this, init) || this;
_this.type = HttpEventType.Response;
_this.body = init.body !== undefined ? init.body : null;
return _this;
}
|
[
"function",
"HttpResponse",
"(",
"init",
")",
"{",
"if",
"(",
"init",
"===",
"void",
"0",
")",
"{",
"init",
"=",
"{",
"}",
";",
"}",
"var",
"_this",
"=",
"_super",
".",
"call",
"(",
"this",
",",
"init",
")",
"||",
"this",
";",
"_this",
".",
"type",
"=",
"HttpEventType",
".",
"Response",
";",
"_this",
".",
"body",
"=",
"init",
".",
"body",
"!==",
"undefined",
"?",
"init",
".",
"body",
":",
"null",
";",
"return",
"_this",
";",
"}"
] |
Construct a new `HttpResponse`.
|
[
"Construct",
"a",
"new",
"HttpResponse",
"."
] |
cb94eb9af46de79c69d61b4fd37a800009fb70d3
|
https://github.com/CuppaLabs/angular2-multiselect-dropdown/blob/cb94eb9af46de79c69d61b4fd37a800009fb70d3/docs/vendor.js#L6746-L6752
|
11,681
|
CuppaLabs/angular2-multiselect-dropdown
|
docs/vendor.js
|
getResponseUrl
|
function getResponseUrl(xhr) {
if ('responseURL' in xhr && xhr.responseURL) {
return xhr.responseURL;
}
if (/^X-Request-URL:/m.test(xhr.getAllResponseHeaders())) {
return xhr.getResponseHeader('X-Request-URL');
}
return null;
}
|
javascript
|
function getResponseUrl(xhr) {
if ('responseURL' in xhr && xhr.responseURL) {
return xhr.responseURL;
}
if (/^X-Request-URL:/m.test(xhr.getAllResponseHeaders())) {
return xhr.getResponseHeader('X-Request-URL');
}
return null;
}
|
[
"function",
"getResponseUrl",
"(",
"xhr",
")",
"{",
"if",
"(",
"'responseURL'",
"in",
"xhr",
"&&",
"xhr",
".",
"responseURL",
")",
"{",
"return",
"xhr",
".",
"responseURL",
";",
"}",
"if",
"(",
"/",
"^X-Request-URL:",
"/",
"m",
".",
"test",
"(",
"xhr",
".",
"getAllResponseHeaders",
"(",
")",
")",
")",
"{",
"return",
"xhr",
".",
"getResponseHeader",
"(",
"'X-Request-URL'",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Determine an appropriate URL for the response, by checking either
XMLHttpRequest.responseURL or the X-Request-URL header.
|
[
"Determine",
"an",
"appropriate",
"URL",
"for",
"the",
"response",
"by",
"checking",
"either",
"XMLHttpRequest",
".",
"responseURL",
"or",
"the",
"X",
"-",
"Request",
"-",
"URL",
"header",
"."
] |
cb94eb9af46de79c69d61b4fd37a800009fb70d3
|
https://github.com/CuppaLabs/angular2-multiselect-dropdown/blob/cb94eb9af46de79c69d61b4fd37a800009fb70d3/docs/vendor.js#L7315-L7323
|
11,682
|
CuppaLabs/angular2-multiselect-dropdown
|
docs/vendor.js
|
function () {
if (headerResponse !== null) {
return headerResponse;
}
// Read status and normalize an IE9 bug (http://bugs.jquery.com/ticket/1450).
var status = xhr.status === 1223 ? 204 : xhr.status;
var statusText = xhr.statusText || 'OK';
// Parse headers from XMLHttpRequest - this step is lazy.
var headers = new HttpHeaders(xhr.getAllResponseHeaders());
// Read the response URL from the XMLHttpResponse instance and fall back on the
// request URL.
var url = getResponseUrl(xhr) || req.url;
// Construct the HttpHeaderResponse and memoize it.
headerResponse = new HttpHeaderResponse({ headers: headers, status: status, statusText: statusText, url: url });
return headerResponse;
}
|
javascript
|
function () {
if (headerResponse !== null) {
return headerResponse;
}
// Read status and normalize an IE9 bug (http://bugs.jquery.com/ticket/1450).
var status = xhr.status === 1223 ? 204 : xhr.status;
var statusText = xhr.statusText || 'OK';
// Parse headers from XMLHttpRequest - this step is lazy.
var headers = new HttpHeaders(xhr.getAllResponseHeaders());
// Read the response URL from the XMLHttpResponse instance and fall back on the
// request URL.
var url = getResponseUrl(xhr) || req.url;
// Construct the HttpHeaderResponse and memoize it.
headerResponse = new HttpHeaderResponse({ headers: headers, status: status, statusText: statusText, url: url });
return headerResponse;
}
|
[
"function",
"(",
")",
"{",
"if",
"(",
"headerResponse",
"!==",
"null",
")",
"{",
"return",
"headerResponse",
";",
"}",
"// Read status and normalize an IE9 bug (http://bugs.jquery.com/ticket/1450).",
"var",
"status",
"=",
"xhr",
".",
"status",
"===",
"1223",
"?",
"204",
":",
"xhr",
".",
"status",
";",
"var",
"statusText",
"=",
"xhr",
".",
"statusText",
"||",
"'OK'",
";",
"// Parse headers from XMLHttpRequest - this step is lazy.",
"var",
"headers",
"=",
"new",
"HttpHeaders",
"(",
"xhr",
".",
"getAllResponseHeaders",
"(",
")",
")",
";",
"// Read the response URL from the XMLHttpResponse instance and fall back on the",
"// request URL.",
"var",
"url",
"=",
"getResponseUrl",
"(",
"xhr",
")",
"||",
"req",
".",
"url",
";",
"// Construct the HttpHeaderResponse and memoize it.",
"headerResponse",
"=",
"new",
"HttpHeaderResponse",
"(",
"{",
"headers",
":",
"headers",
",",
"status",
":",
"status",
",",
"statusText",
":",
"statusText",
",",
"url",
":",
"url",
"}",
")",
";",
"return",
"headerResponse",
";",
"}"
] |
partialFromXhr extracts the HttpHeaderResponse from the current XMLHttpRequest state, and memoizes it into headerResponse.
|
[
"partialFromXhr",
"extracts",
"the",
"HttpHeaderResponse",
"from",
"the",
"current",
"XMLHttpRequest",
"state",
"and",
"memoizes",
"it",
"into",
"headerResponse",
"."
] |
cb94eb9af46de79c69d61b4fd37a800009fb70d3
|
https://github.com/CuppaLabs/angular2-multiselect-dropdown/blob/cb94eb9af46de79c69d61b4fd37a800009fb70d3/docs/vendor.js#L7412-L7427
|
|
11,683
|
CuppaLabs/angular2-multiselect-dropdown
|
docs/vendor.js
|
function () {
// Read response state from the memoized partial data.
var _a = partialFromXhr(), headers = _a.headers, status = _a.status, statusText = _a.statusText, url = _a.url;
// The body will be read out if present.
var body = null;
if (status !== 204) {
// Use XMLHttpRequest.response if set, responseText otherwise.
body = (typeof xhr.response === 'undefined') ? xhr.responseText : xhr.response;
}
// Normalize another potential bug (this one comes from CORS).
if (status === 0) {
status = !!body ? 200 : 0;
}
// ok determines whether the response will be transmitted on the event or
// error channel. Unsuccessful status codes (not 2xx) will always be errors,
// but a successful status code can still result in an error if the user
// asked for JSON data and the body cannot be parsed as such.
var ok = status >= 200 && status < 300;
// Check whether the body needs to be parsed as JSON (in many cases the browser
// will have done that already).
if (req.responseType === 'json' && typeof body === 'string') {
// Save the original body, before attempting XSSI prefix stripping.
var originalBody = body;
body = body.replace(XSSI_PREFIX, '');
try {
// Attempt the parse. If it fails, a parse error should be delivered to the user.
body = body !== '' ? JSON.parse(body) : null;
}
catch (error) {
// Since the JSON.parse failed, it's reasonable to assume this might not have been a
// JSON response. Restore the original body (including any XSSI prefix) to deliver
// a better error response.
body = originalBody;
// If this was an error request to begin with, leave it as a string, it probably
// just isn't JSON. Otherwise, deliver the parsing error to the user.
if (ok) {
// Even though the response status was 2xx, this is still an error.
ok = false;
// The parse error contains the text of the body that failed to parse.
body = { error: error, text: body };
}
}
}
if (ok) {
// A successful response is delivered on the event stream.
observer.next(new HttpResponse({
body: body,
headers: headers,
status: status,
statusText: statusText,
url: url || undefined,
}));
// The full body has been received and delivered, no further events
// are possible. This request is complete.
observer.complete();
}
else {
// An unsuccessful request is delivered on the error channel.
observer.error(new HttpErrorResponse({
// The error in this case is the response body (error from the server).
error: body,
headers: headers,
status: status,
statusText: statusText,
url: url || undefined,
}));
}
}
|
javascript
|
function () {
// Read response state from the memoized partial data.
var _a = partialFromXhr(), headers = _a.headers, status = _a.status, statusText = _a.statusText, url = _a.url;
// The body will be read out if present.
var body = null;
if (status !== 204) {
// Use XMLHttpRequest.response if set, responseText otherwise.
body = (typeof xhr.response === 'undefined') ? xhr.responseText : xhr.response;
}
// Normalize another potential bug (this one comes from CORS).
if (status === 0) {
status = !!body ? 200 : 0;
}
// ok determines whether the response will be transmitted on the event or
// error channel. Unsuccessful status codes (not 2xx) will always be errors,
// but a successful status code can still result in an error if the user
// asked for JSON data and the body cannot be parsed as such.
var ok = status >= 200 && status < 300;
// Check whether the body needs to be parsed as JSON (in many cases the browser
// will have done that already).
if (req.responseType === 'json' && typeof body === 'string') {
// Save the original body, before attempting XSSI prefix stripping.
var originalBody = body;
body = body.replace(XSSI_PREFIX, '');
try {
// Attempt the parse. If it fails, a parse error should be delivered to the user.
body = body !== '' ? JSON.parse(body) : null;
}
catch (error) {
// Since the JSON.parse failed, it's reasonable to assume this might not have been a
// JSON response. Restore the original body (including any XSSI prefix) to deliver
// a better error response.
body = originalBody;
// If this was an error request to begin with, leave it as a string, it probably
// just isn't JSON. Otherwise, deliver the parsing error to the user.
if (ok) {
// Even though the response status was 2xx, this is still an error.
ok = false;
// The parse error contains the text of the body that failed to parse.
body = { error: error, text: body };
}
}
}
if (ok) {
// A successful response is delivered on the event stream.
observer.next(new HttpResponse({
body: body,
headers: headers,
status: status,
statusText: statusText,
url: url || undefined,
}));
// The full body has been received and delivered, no further events
// are possible. This request is complete.
observer.complete();
}
else {
// An unsuccessful request is delivered on the error channel.
observer.error(new HttpErrorResponse({
// The error in this case is the response body (error from the server).
error: body,
headers: headers,
status: status,
statusText: statusText,
url: url || undefined,
}));
}
}
|
[
"function",
"(",
")",
"{",
"// Read response state from the memoized partial data.",
"var",
"_a",
"=",
"partialFromXhr",
"(",
")",
",",
"headers",
"=",
"_a",
".",
"headers",
",",
"status",
"=",
"_a",
".",
"status",
",",
"statusText",
"=",
"_a",
".",
"statusText",
",",
"url",
"=",
"_a",
".",
"url",
";",
"// The body will be read out if present.",
"var",
"body",
"=",
"null",
";",
"if",
"(",
"status",
"!==",
"204",
")",
"{",
"// Use XMLHttpRequest.response if set, responseText otherwise.",
"body",
"=",
"(",
"typeof",
"xhr",
".",
"response",
"===",
"'undefined'",
")",
"?",
"xhr",
".",
"responseText",
":",
"xhr",
".",
"response",
";",
"}",
"// Normalize another potential bug (this one comes from CORS).",
"if",
"(",
"status",
"===",
"0",
")",
"{",
"status",
"=",
"!",
"!",
"body",
"?",
"200",
":",
"0",
";",
"}",
"// ok determines whether the response will be transmitted on the event or",
"// error channel. Unsuccessful status codes (not 2xx) will always be errors,",
"// but a successful status code can still result in an error if the user",
"// asked for JSON data and the body cannot be parsed as such.",
"var",
"ok",
"=",
"status",
">=",
"200",
"&&",
"status",
"<",
"300",
";",
"// Check whether the body needs to be parsed as JSON (in many cases the browser",
"// will have done that already).",
"if",
"(",
"req",
".",
"responseType",
"===",
"'json'",
"&&",
"typeof",
"body",
"===",
"'string'",
")",
"{",
"// Save the original body, before attempting XSSI prefix stripping.",
"var",
"originalBody",
"=",
"body",
";",
"body",
"=",
"body",
".",
"replace",
"(",
"XSSI_PREFIX",
",",
"''",
")",
";",
"try",
"{",
"// Attempt the parse. If it fails, a parse error should be delivered to the user.",
"body",
"=",
"body",
"!==",
"''",
"?",
"JSON",
".",
"parse",
"(",
"body",
")",
":",
"null",
";",
"}",
"catch",
"(",
"error",
")",
"{",
"// Since the JSON.parse failed, it's reasonable to assume this might not have been a",
"// JSON response. Restore the original body (including any XSSI prefix) to deliver",
"// a better error response.",
"body",
"=",
"originalBody",
";",
"// If this was an error request to begin with, leave it as a string, it probably",
"// just isn't JSON. Otherwise, deliver the parsing error to the user.",
"if",
"(",
"ok",
")",
"{",
"// Even though the response status was 2xx, this is still an error.",
"ok",
"=",
"false",
";",
"// The parse error contains the text of the body that failed to parse.",
"body",
"=",
"{",
"error",
":",
"error",
",",
"text",
":",
"body",
"}",
";",
"}",
"}",
"}",
"if",
"(",
"ok",
")",
"{",
"// A successful response is delivered on the event stream.",
"observer",
".",
"next",
"(",
"new",
"HttpResponse",
"(",
"{",
"body",
":",
"body",
",",
"headers",
":",
"headers",
",",
"status",
":",
"status",
",",
"statusText",
":",
"statusText",
",",
"url",
":",
"url",
"||",
"undefined",
",",
"}",
")",
")",
";",
"// The full body has been received and delivered, no further events",
"// are possible. This request is complete.",
"observer",
".",
"complete",
"(",
")",
";",
"}",
"else",
"{",
"// An unsuccessful request is delivered on the error channel.",
"observer",
".",
"error",
"(",
"new",
"HttpErrorResponse",
"(",
"{",
"// The error in this case is the response body (error from the server).",
"error",
":",
"body",
",",
"headers",
":",
"headers",
",",
"status",
":",
"status",
",",
"statusText",
":",
"statusText",
",",
"url",
":",
"url",
"||",
"undefined",
",",
"}",
")",
")",
";",
"}",
"}"
] |
Next, a few closures are defined for the various events which XMLHttpRequest can emit. This allows them to be unregistered as event listeners later. First up is the load event, which represents a response being fully available.
|
[
"Next",
"a",
"few",
"closures",
"are",
"defined",
"for",
"the",
"various",
"events",
"which",
"XMLHttpRequest",
"can",
"emit",
".",
"This",
"allows",
"them",
"to",
"be",
"unregistered",
"as",
"event",
"listeners",
"later",
".",
"First",
"up",
"is",
"the",
"load",
"event",
"which",
"represents",
"a",
"response",
"being",
"fully",
"available",
"."
] |
cb94eb9af46de79c69d61b4fd37a800009fb70d3
|
https://github.com/CuppaLabs/angular2-multiselect-dropdown/blob/cb94eb9af46de79c69d61b4fd37a800009fb70d3/docs/vendor.js#L7431-L7498
|
|
11,684
|
CuppaLabs/angular2-multiselect-dropdown
|
docs/vendor.js
|
function (error) {
var res = new HttpErrorResponse({
error: error,
status: xhr.status || 0,
statusText: xhr.statusText || 'Unknown Error',
});
observer.error(res);
}
|
javascript
|
function (error) {
var res = new HttpErrorResponse({
error: error,
status: xhr.status || 0,
statusText: xhr.statusText || 'Unknown Error',
});
observer.error(res);
}
|
[
"function",
"(",
"error",
")",
"{",
"var",
"res",
"=",
"new",
"HttpErrorResponse",
"(",
"{",
"error",
":",
"error",
",",
"status",
":",
"xhr",
".",
"status",
"||",
"0",
",",
"statusText",
":",
"xhr",
".",
"statusText",
"||",
"'Unknown Error'",
",",
"}",
")",
";",
"observer",
".",
"error",
"(",
"res",
")",
";",
"}"
] |
The onError callback is called when something goes wrong at the network level. Connection timeout, DNS error, offline, etc. These are actual errors, and are transmitted on the error channel.
|
[
"The",
"onError",
"callback",
"is",
"called",
"when",
"something",
"goes",
"wrong",
"at",
"the",
"network",
"level",
".",
"Connection",
"timeout",
"DNS",
"error",
"offline",
"etc",
".",
"These",
"are",
"actual",
"errors",
"and",
"are",
"transmitted",
"on",
"the",
"error",
"channel",
"."
] |
cb94eb9af46de79c69d61b4fd37a800009fb70d3
|
https://github.com/CuppaLabs/angular2-multiselect-dropdown/blob/cb94eb9af46de79c69d61b4fd37a800009fb70d3/docs/vendor.js#L7502-L7509
|
|
11,685
|
CuppaLabs/angular2-multiselect-dropdown
|
docs/vendor.js
|
function (event) {
// Send the HttpResponseHeaders event if it hasn't been sent already.
if (!sentHeaders) {
observer.next(partialFromXhr());
sentHeaders = true;
}
// Start building the download progress event to deliver on the response
// event stream.
var progressEvent = {
type: HttpEventType.DownloadProgress,
loaded: event.loaded,
};
// Set the total number of bytes in the event if it's available.
if (event.lengthComputable) {
progressEvent.total = event.total;
}
// If the request was for text content and a partial response is
// available on XMLHttpRequest, include it in the progress event
// to allow for streaming reads.
if (req.responseType === 'text' && !!xhr.responseText) {
progressEvent.partialText = xhr.responseText;
}
// Finally, fire the event.
observer.next(progressEvent);
}
|
javascript
|
function (event) {
// Send the HttpResponseHeaders event if it hasn't been sent already.
if (!sentHeaders) {
observer.next(partialFromXhr());
sentHeaders = true;
}
// Start building the download progress event to deliver on the response
// event stream.
var progressEvent = {
type: HttpEventType.DownloadProgress,
loaded: event.loaded,
};
// Set the total number of bytes in the event if it's available.
if (event.lengthComputable) {
progressEvent.total = event.total;
}
// If the request was for text content and a partial response is
// available on XMLHttpRequest, include it in the progress event
// to allow for streaming reads.
if (req.responseType === 'text' && !!xhr.responseText) {
progressEvent.partialText = xhr.responseText;
}
// Finally, fire the event.
observer.next(progressEvent);
}
|
[
"function",
"(",
"event",
")",
"{",
"// Send the HttpResponseHeaders event if it hasn't been sent already.",
"if",
"(",
"!",
"sentHeaders",
")",
"{",
"observer",
".",
"next",
"(",
"partialFromXhr",
"(",
")",
")",
";",
"sentHeaders",
"=",
"true",
";",
"}",
"// Start building the download progress event to deliver on the response",
"// event stream.",
"var",
"progressEvent",
"=",
"{",
"type",
":",
"HttpEventType",
".",
"DownloadProgress",
",",
"loaded",
":",
"event",
".",
"loaded",
",",
"}",
";",
"// Set the total number of bytes in the event if it's available.",
"if",
"(",
"event",
".",
"lengthComputable",
")",
"{",
"progressEvent",
".",
"total",
"=",
"event",
".",
"total",
";",
"}",
"// If the request was for text content and a partial response is",
"// available on XMLHttpRequest, include it in the progress event",
"// to allow for streaming reads.",
"if",
"(",
"req",
".",
"responseType",
"===",
"'text'",
"&&",
"!",
"!",
"xhr",
".",
"responseText",
")",
"{",
"progressEvent",
".",
"partialText",
"=",
"xhr",
".",
"responseText",
";",
"}",
"// Finally, fire the event.",
"observer",
".",
"next",
"(",
"progressEvent",
")",
";",
"}"
] |
The download progress event handler, which is only registered if progress events are enabled.
|
[
"The",
"download",
"progress",
"event",
"handler",
"which",
"is",
"only",
"registered",
"if",
"progress",
"events",
"are",
"enabled",
"."
] |
cb94eb9af46de79c69d61b4fd37a800009fb70d3
|
https://github.com/CuppaLabs/angular2-multiselect-dropdown/blob/cb94eb9af46de79c69d61b4fd37a800009fb70d3/docs/vendor.js#L7517-L7541
|
|
11,686
|
CuppaLabs/angular2-multiselect-dropdown
|
docs/vendor.js
|
function (event) {
// Upload progress events are simpler. Begin building the progress
// event.
var progress = {
type: HttpEventType.UploadProgress,
loaded: event.loaded,
};
// If the total number of bytes being uploaded is available, include
// it.
if (event.lengthComputable) {
progress.total = event.total;
}
// Send the event.
observer.next(progress);
}
|
javascript
|
function (event) {
// Upload progress events are simpler. Begin building the progress
// event.
var progress = {
type: HttpEventType.UploadProgress,
loaded: event.loaded,
};
// If the total number of bytes being uploaded is available, include
// it.
if (event.lengthComputable) {
progress.total = event.total;
}
// Send the event.
observer.next(progress);
}
|
[
"function",
"(",
"event",
")",
"{",
"// Upload progress events are simpler. Begin building the progress",
"// event.",
"var",
"progress",
"=",
"{",
"type",
":",
"HttpEventType",
".",
"UploadProgress",
",",
"loaded",
":",
"event",
".",
"loaded",
",",
"}",
";",
"// If the total number of bytes being uploaded is available, include",
"// it.",
"if",
"(",
"event",
".",
"lengthComputable",
")",
"{",
"progress",
".",
"total",
"=",
"event",
".",
"total",
";",
"}",
"// Send the event.",
"observer",
".",
"next",
"(",
"progress",
")",
";",
"}"
] |
The upload progress event handler, which is only registered if progress events are enabled.
|
[
"The",
"upload",
"progress",
"event",
"handler",
"which",
"is",
"only",
"registered",
"if",
"progress",
"events",
"are",
"enabled",
"."
] |
cb94eb9af46de79c69d61b4fd37a800009fb70d3
|
https://github.com/CuppaLabs/angular2-multiselect-dropdown/blob/cb94eb9af46de79c69d61b4fd37a800009fb70d3/docs/vendor.js#L7544-L7558
|
|
11,687
|
CuppaLabs/angular2-multiselect-dropdown
|
docs/vendor.js
|
defineInjector
|
function defineInjector(options) {
return {
factory: options.factory, providers: options.providers || [], imports: options.imports || [],
};
}
|
javascript
|
function defineInjector(options) {
return {
factory: options.factory, providers: options.providers || [], imports: options.imports || [],
};
}
|
[
"function",
"defineInjector",
"(",
"options",
")",
"{",
"return",
"{",
"factory",
":",
"options",
".",
"factory",
",",
"providers",
":",
"options",
".",
"providers",
"||",
"[",
"]",
",",
"imports",
":",
"options",
".",
"imports",
"||",
"[",
"]",
",",
"}",
";",
"}"
] |
Construct an `InjectorDef` which configures an injector.
This should be assigned to a static `ngInjectorDef` field on a type, which will then be an
`InjectorType`.
Options:
* `factory`: an `InjectorType` is an instantiable type, so a zero argument `factory` function to
create the type must be provided. If that factory function needs to inject arguments, it can
use the `inject` function.
* `providers`: an optional array of providers to add to the injector. Each provider must
either have a factory or point to a type which has an `ngInjectableDef` static property (the
type must be an `InjectableType`).
* `imports`: an optional array of imports of other `InjectorType`s or `InjectorTypeWithModule`s
whose providers will also be added to the injector. Locally provided types will override
providers from imports.
@experimental
|
[
"Construct",
"an",
"InjectorDef",
"which",
"configures",
"an",
"injector",
"."
] |
cb94eb9af46de79c69d61b4fd37a800009fb70d3
|
https://github.com/CuppaLabs/angular2-multiselect-dropdown/blob/cb94eb9af46de79c69d61b4fd37a800009fb70d3/docs/vendor.js#L8248-L8252
|
11,688
|
CuppaLabs/angular2-multiselect-dropdown
|
docs/vendor.js
|
resolveForwardRef
|
function resolveForwardRef(type) {
if (typeof type === 'function' && type.hasOwnProperty('__forward_ref__') &&
type.__forward_ref__ === forwardRef) {
return type();
}
else {
return type;
}
}
|
javascript
|
function resolveForwardRef(type) {
if (typeof type === 'function' && type.hasOwnProperty('__forward_ref__') &&
type.__forward_ref__ === forwardRef) {
return type();
}
else {
return type;
}
}
|
[
"function",
"resolveForwardRef",
"(",
"type",
")",
"{",
"if",
"(",
"typeof",
"type",
"===",
"'function'",
"&&",
"type",
".",
"hasOwnProperty",
"(",
"'__forward_ref__'",
")",
"&&",
"type",
".",
"__forward_ref__",
"===",
"forwardRef",
")",
"{",
"return",
"type",
"(",
")",
";",
"}",
"else",
"{",
"return",
"type",
";",
"}",
"}"
] |
Lazily retrieves the reference value from a forwardRef.
Acts as the identity function when given a non-forward-ref value.
@usageNotes
### Example
{@example core/di/ts/forward_ref/forward_ref_spec.ts region='resolve_forward_ref'}
@see `forwardRef`
@experimental
|
[
"Lazily",
"retrieves",
"the",
"reference",
"value",
"from",
"a",
"forwardRef",
"."
] |
cb94eb9af46de79c69d61b4fd37a800009fb70d3
|
https://github.com/CuppaLabs/angular2-multiselect-dropdown/blob/cb94eb9af46de79c69d61b4fd37a800009fb70d3/docs/vendor.js#L9174-L9182
|
11,689
|
CuppaLabs/angular2-multiselect-dropdown
|
docs/vendor.js
|
resolveReflectiveProvider
|
function resolveReflectiveProvider(provider) {
return new ResolvedReflectiveProvider_(ReflectiveKey.get(provider.provide), [resolveReflectiveFactory(provider)], provider.multi || false);
}
|
javascript
|
function resolveReflectiveProvider(provider) {
return new ResolvedReflectiveProvider_(ReflectiveKey.get(provider.provide), [resolveReflectiveFactory(provider)], provider.multi || false);
}
|
[
"function",
"resolveReflectiveProvider",
"(",
"provider",
")",
"{",
"return",
"new",
"ResolvedReflectiveProvider_",
"(",
"ReflectiveKey",
".",
"get",
"(",
"provider",
".",
"provide",
")",
",",
"[",
"resolveReflectiveFactory",
"(",
"provider",
")",
"]",
",",
"provider",
".",
"multi",
"||",
"false",
")",
";",
"}"
] |
Converts the `Provider` into `ResolvedProvider`.
`Injector` internally only uses `ResolvedProvider`, `Provider` contains convenience provider
syntax.
|
[
"Converts",
"the",
"Provider",
"into",
"ResolvedProvider",
"."
] |
cb94eb9af46de79c69d61b4fd37a800009fb70d3
|
https://github.com/CuppaLabs/angular2-multiselect-dropdown/blob/cb94eb9af46de79c69d61b4fd37a800009fb70d3/docs/vendor.js#L10368-L10370
|
11,690
|
CuppaLabs/angular2-multiselect-dropdown
|
docs/vendor.js
|
EventEmitter
|
function EventEmitter(isAsync) {
if (isAsync === void 0) { isAsync = false; }
var _this = _super.call(this) || this;
_this.__isAsync = isAsync;
return _this;
}
|
javascript
|
function EventEmitter(isAsync) {
if (isAsync === void 0) { isAsync = false; }
var _this = _super.call(this) || this;
_this.__isAsync = isAsync;
return _this;
}
|
[
"function",
"EventEmitter",
"(",
"isAsync",
")",
"{",
"if",
"(",
"isAsync",
"===",
"void",
"0",
")",
"{",
"isAsync",
"=",
"false",
";",
"}",
"var",
"_this",
"=",
"_super",
".",
"call",
"(",
"this",
")",
"||",
"this",
";",
"_this",
".",
"__isAsync",
"=",
"isAsync",
";",
"return",
"_this",
";",
"}"
] |
Creates an instance of this class that can
deliver events synchronously or asynchronously.
@param isAsync When true, deliver events asynchronously.
|
[
"Creates",
"an",
"instance",
"of",
"this",
"class",
"that",
"can",
"deliver",
"events",
"synchronously",
"or",
"asynchronously",
"."
] |
cb94eb9af46de79c69d61b4fd37a800009fb70d3
|
https://github.com/CuppaLabs/angular2-multiselect-dropdown/blob/cb94eb9af46de79c69d61b4fd37a800009fb70d3/docs/vendor.js#L11714-L11719
|
11,691
|
CuppaLabs/angular2-multiselect-dropdown
|
docs/vendor.js
|
registerModuleFactory
|
function registerModuleFactory(id, factory) {
var existing = moduleFactories.get(id);
if (existing) {
throw new Error("Duplicate module registered for " + id + " - " + existing.moduleType.name + " vs " + factory.moduleType.name);
}
moduleFactories.set(id, factory);
}
|
javascript
|
function registerModuleFactory(id, factory) {
var existing = moduleFactories.get(id);
if (existing) {
throw new Error("Duplicate module registered for " + id + " - " + existing.moduleType.name + " vs " + factory.moduleType.name);
}
moduleFactories.set(id, factory);
}
|
[
"function",
"registerModuleFactory",
"(",
"id",
",",
"factory",
")",
"{",
"var",
"existing",
"=",
"moduleFactories",
".",
"get",
"(",
"id",
")",
";",
"if",
"(",
"existing",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Duplicate module registered for \"",
"+",
"id",
"+",
"\" - \"",
"+",
"existing",
".",
"moduleType",
".",
"name",
"+",
"\" vs \"",
"+",
"factory",
".",
"moduleType",
".",
"name",
")",
";",
"}",
"moduleFactories",
".",
"set",
"(",
"id",
",",
"factory",
")",
";",
"}"
] |
Registers a loaded module. Should only be called from generated NgModuleFactory code.
@experimental
|
[
"Registers",
"a",
"loaded",
"module",
".",
"Should",
"only",
"be",
"called",
"from",
"generated",
"NgModuleFactory",
"code",
"."
] |
cb94eb9af46de79c69d61b4fd37a800009fb70d3
|
https://github.com/CuppaLabs/angular2-multiselect-dropdown/blob/cb94eb9af46de79c69d61b4fd37a800009fb70d3/docs/vendor.js#L13005-L13011
|
11,692
|
CuppaLabs/angular2-multiselect-dropdown
|
docs/vendor.js
|
shouldCallLifecycleInitHook
|
function shouldCallLifecycleInitHook(view, initState, index) {
if ((view.state & 1792 /* InitState_Mask */) === initState && view.initIndex <= index) {
view.initIndex = index + 1;
return true;
}
return false;
}
|
javascript
|
function shouldCallLifecycleInitHook(view, initState, index) {
if ((view.state & 1792 /* InitState_Mask */) === initState && view.initIndex <= index) {
view.initIndex = index + 1;
return true;
}
return false;
}
|
[
"function",
"shouldCallLifecycleInitHook",
"(",
"view",
",",
"initState",
",",
"index",
")",
"{",
"if",
"(",
"(",
"view",
".",
"state",
"&",
"1792",
"/* InitState_Mask */",
")",
"===",
"initState",
"&&",
"view",
".",
"initIndex",
"<=",
"index",
")",
"{",
"view",
".",
"initIndex",
"=",
"index",
"+",
"1",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Returns true if the lifecycle init method should be called for the node with the given init index.
|
[
"Returns",
"true",
"if",
"the",
"lifecycle",
"init",
"method",
"should",
"be",
"called",
"for",
"the",
"node",
"with",
"the",
"given",
"init",
"index",
"."
] |
cb94eb9af46de79c69d61b4fd37a800009fb70d3
|
https://github.com/CuppaLabs/angular2-multiselect-dropdown/blob/cb94eb9af46de79c69d61b4fd37a800009fb70d3/docs/vendor.js#L15691-L15697
|
11,693
|
CuppaLabs/angular2-multiselect-dropdown
|
docs/vendor.js
|
viewParentEl
|
function viewParentEl(view) {
var parentView = view.parent;
if (parentView) {
return view.parentNodeDef.parent;
}
else {
return null;
}
}
|
javascript
|
function viewParentEl(view) {
var parentView = view.parent;
if (parentView) {
return view.parentNodeDef.parent;
}
else {
return null;
}
}
|
[
"function",
"viewParentEl",
"(",
"view",
")",
"{",
"var",
"parentView",
"=",
"view",
".",
"parent",
";",
"if",
"(",
"parentView",
")",
"{",
"return",
"view",
".",
"parentNodeDef",
".",
"parent",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] |
for component views, this is the host element.
for embedded views, this is the index of the parent node
that contains the view container.
|
[
"for",
"component",
"views",
"this",
"is",
"the",
"host",
"element",
".",
"for",
"embedded",
"views",
"this",
"is",
"the",
"index",
"of",
"the",
"parent",
"node",
"that",
"contains",
"the",
"view",
"container",
"."
] |
cb94eb9af46de79c69d61b4fd37a800009fb70d3
|
https://github.com/CuppaLabs/angular2-multiselect-dropdown/blob/cb94eb9af46de79c69d61b4fd37a800009fb70d3/docs/vendor.js#L15918-L15926
|
11,694
|
CuppaLabs/angular2-multiselect-dropdown
|
docs/vendor.js
|
queueLifecycleHooks
|
function queueLifecycleHooks(flags, tView) {
if (tView.firstTemplatePass) {
var start = flags >> 14 /* DirectiveStartingIndexShift */;
var count = flags & 4095 /* DirectiveCountMask */;
var end = start + count;
// It's necessary to loop through the directives at elementEnd() (rather than processing in
// directiveCreate) so we can preserve the current hook order. Content, view, and destroy
// hooks for projected components and directives must be called *before* their hosts.
for (var i = start; i < end; i++) {
var def = tView.directives[i];
queueContentHooks(def, tView, i);
queueViewHooks(def, tView, i);
queueDestroyHooks(def, tView, i);
}
}
}
|
javascript
|
function queueLifecycleHooks(flags, tView) {
if (tView.firstTemplatePass) {
var start = flags >> 14 /* DirectiveStartingIndexShift */;
var count = flags & 4095 /* DirectiveCountMask */;
var end = start + count;
// It's necessary to loop through the directives at elementEnd() (rather than processing in
// directiveCreate) so we can preserve the current hook order. Content, view, and destroy
// hooks for projected components and directives must be called *before* their hosts.
for (var i = start; i < end; i++) {
var def = tView.directives[i];
queueContentHooks(def, tView, i);
queueViewHooks(def, tView, i);
queueDestroyHooks(def, tView, i);
}
}
}
|
[
"function",
"queueLifecycleHooks",
"(",
"flags",
",",
"tView",
")",
"{",
"if",
"(",
"tView",
".",
"firstTemplatePass",
")",
"{",
"var",
"start",
"=",
"flags",
">>",
"14",
"/* DirectiveStartingIndexShift */",
";",
"var",
"count",
"=",
"flags",
"&",
"4095",
"/* DirectiveCountMask */",
";",
"var",
"end",
"=",
"start",
"+",
"count",
";",
"// It's necessary to loop through the directives at elementEnd() (rather than processing in",
"// directiveCreate) so we can preserve the current hook order. Content, view, and destroy",
"// hooks for projected components and directives must be called *before* their hosts.",
"for",
"(",
"var",
"i",
"=",
"start",
";",
"i",
"<",
"end",
";",
"i",
"++",
")",
"{",
"var",
"def",
"=",
"tView",
".",
"directives",
"[",
"i",
"]",
";",
"queueContentHooks",
"(",
"def",
",",
"tView",
",",
"i",
")",
";",
"queueViewHooks",
"(",
"def",
",",
"tView",
",",
"i",
")",
";",
"queueDestroyHooks",
"(",
"def",
",",
"tView",
",",
"i",
")",
";",
"}",
"}",
"}"
] |
Loops through the directives on a node and queues all their hooks except ngOnInit
and ngDoCheck, which are queued separately in directiveCreate.
|
[
"Loops",
"through",
"the",
"directives",
"on",
"a",
"node",
"and",
"queues",
"all",
"their",
"hooks",
"except",
"ngOnInit",
"and",
"ngDoCheck",
"which",
"are",
"queued",
"separately",
"in",
"directiveCreate",
"."
] |
cb94eb9af46de79c69d61b4fd37a800009fb70d3
|
https://github.com/CuppaLabs/angular2-multiselect-dropdown/blob/cb94eb9af46de79c69d61b4fd37a800009fb70d3/docs/vendor.js#L19898-L19913
|
11,695
|
CuppaLabs/angular2-multiselect-dropdown
|
docs/vendor.js
|
queueContentHooks
|
function queueContentHooks(def, tView, i) {
if (def.afterContentInit) {
(tView.contentHooks || (tView.contentHooks = [])).push(i, def.afterContentInit);
}
if (def.afterContentChecked) {
(tView.contentHooks || (tView.contentHooks = [])).push(i, def.afterContentChecked);
(tView.contentCheckHooks || (tView.contentCheckHooks = [])).push(i, def.afterContentChecked);
}
}
|
javascript
|
function queueContentHooks(def, tView, i) {
if (def.afterContentInit) {
(tView.contentHooks || (tView.contentHooks = [])).push(i, def.afterContentInit);
}
if (def.afterContentChecked) {
(tView.contentHooks || (tView.contentHooks = [])).push(i, def.afterContentChecked);
(tView.contentCheckHooks || (tView.contentCheckHooks = [])).push(i, def.afterContentChecked);
}
}
|
[
"function",
"queueContentHooks",
"(",
"def",
",",
"tView",
",",
"i",
")",
"{",
"if",
"(",
"def",
".",
"afterContentInit",
")",
"{",
"(",
"tView",
".",
"contentHooks",
"||",
"(",
"tView",
".",
"contentHooks",
"=",
"[",
"]",
")",
")",
".",
"push",
"(",
"i",
",",
"def",
".",
"afterContentInit",
")",
";",
"}",
"if",
"(",
"def",
".",
"afterContentChecked",
")",
"{",
"(",
"tView",
".",
"contentHooks",
"||",
"(",
"tView",
".",
"contentHooks",
"=",
"[",
"]",
")",
")",
".",
"push",
"(",
"i",
",",
"def",
".",
"afterContentChecked",
")",
";",
"(",
"tView",
".",
"contentCheckHooks",
"||",
"(",
"tView",
".",
"contentCheckHooks",
"=",
"[",
"]",
")",
")",
".",
"push",
"(",
"i",
",",
"def",
".",
"afterContentChecked",
")",
";",
"}",
"}"
] |
Queues afterContentInit and afterContentChecked hooks on TView
|
[
"Queues",
"afterContentInit",
"and",
"afterContentChecked",
"hooks",
"on",
"TView"
] |
cb94eb9af46de79c69d61b4fd37a800009fb70d3
|
https://github.com/CuppaLabs/angular2-multiselect-dropdown/blob/cb94eb9af46de79c69d61b4fd37a800009fb70d3/docs/vendor.js#L19915-L19923
|
11,696
|
CuppaLabs/angular2-multiselect-dropdown
|
docs/vendor.js
|
queueViewHooks
|
function queueViewHooks(def, tView, i) {
if (def.afterViewInit) {
(tView.viewHooks || (tView.viewHooks = [])).push(i, def.afterViewInit);
}
if (def.afterViewChecked) {
(tView.viewHooks || (tView.viewHooks = [])).push(i, def.afterViewChecked);
(tView.viewCheckHooks || (tView.viewCheckHooks = [])).push(i, def.afterViewChecked);
}
}
|
javascript
|
function queueViewHooks(def, tView, i) {
if (def.afterViewInit) {
(tView.viewHooks || (tView.viewHooks = [])).push(i, def.afterViewInit);
}
if (def.afterViewChecked) {
(tView.viewHooks || (tView.viewHooks = [])).push(i, def.afterViewChecked);
(tView.viewCheckHooks || (tView.viewCheckHooks = [])).push(i, def.afterViewChecked);
}
}
|
[
"function",
"queueViewHooks",
"(",
"def",
",",
"tView",
",",
"i",
")",
"{",
"if",
"(",
"def",
".",
"afterViewInit",
")",
"{",
"(",
"tView",
".",
"viewHooks",
"||",
"(",
"tView",
".",
"viewHooks",
"=",
"[",
"]",
")",
")",
".",
"push",
"(",
"i",
",",
"def",
".",
"afterViewInit",
")",
";",
"}",
"if",
"(",
"def",
".",
"afterViewChecked",
")",
"{",
"(",
"tView",
".",
"viewHooks",
"||",
"(",
"tView",
".",
"viewHooks",
"=",
"[",
"]",
")",
")",
".",
"push",
"(",
"i",
",",
"def",
".",
"afterViewChecked",
")",
";",
"(",
"tView",
".",
"viewCheckHooks",
"||",
"(",
"tView",
".",
"viewCheckHooks",
"=",
"[",
"]",
")",
")",
".",
"push",
"(",
"i",
",",
"def",
".",
"afterViewChecked",
")",
";",
"}",
"}"
] |
Queues afterViewInit and afterViewChecked hooks on TView
|
[
"Queues",
"afterViewInit",
"and",
"afterViewChecked",
"hooks",
"on",
"TView"
] |
cb94eb9af46de79c69d61b4fd37a800009fb70d3
|
https://github.com/CuppaLabs/angular2-multiselect-dropdown/blob/cb94eb9af46de79c69d61b4fd37a800009fb70d3/docs/vendor.js#L19925-L19933
|
11,697
|
CuppaLabs/angular2-multiselect-dropdown
|
docs/vendor.js
|
queueDestroyHooks
|
function queueDestroyHooks(def, tView, i) {
if (def.onDestroy != null) {
(tView.destroyHooks || (tView.destroyHooks = [])).push(i, def.onDestroy);
}
}
|
javascript
|
function queueDestroyHooks(def, tView, i) {
if (def.onDestroy != null) {
(tView.destroyHooks || (tView.destroyHooks = [])).push(i, def.onDestroy);
}
}
|
[
"function",
"queueDestroyHooks",
"(",
"def",
",",
"tView",
",",
"i",
")",
"{",
"if",
"(",
"def",
".",
"onDestroy",
"!=",
"null",
")",
"{",
"(",
"tView",
".",
"destroyHooks",
"||",
"(",
"tView",
".",
"destroyHooks",
"=",
"[",
"]",
")",
")",
".",
"push",
"(",
"i",
",",
"def",
".",
"onDestroy",
")",
";",
"}",
"}"
] |
Queues onDestroy hooks on TView
|
[
"Queues",
"onDestroy",
"hooks",
"on",
"TView"
] |
cb94eb9af46de79c69d61b4fd37a800009fb70d3
|
https://github.com/CuppaLabs/angular2-multiselect-dropdown/blob/cb94eb9af46de79c69d61b4fd37a800009fb70d3/docs/vendor.js#L19935-L19939
|
11,698
|
CuppaLabs/angular2-multiselect-dropdown
|
docs/vendor.js
|
executeInitHooks
|
function executeInitHooks(currentView, tView, creationMode) {
if (currentView[FLAGS] & 16 /* RunInit */) {
executeHooks(currentView[DIRECTIVES], tView.initHooks, tView.checkHooks, creationMode);
currentView[FLAGS] &= ~16 /* RunInit */;
}
}
|
javascript
|
function executeInitHooks(currentView, tView, creationMode) {
if (currentView[FLAGS] & 16 /* RunInit */) {
executeHooks(currentView[DIRECTIVES], tView.initHooks, tView.checkHooks, creationMode);
currentView[FLAGS] &= ~16 /* RunInit */;
}
}
|
[
"function",
"executeInitHooks",
"(",
"currentView",
",",
"tView",
",",
"creationMode",
")",
"{",
"if",
"(",
"currentView",
"[",
"FLAGS",
"]",
"&",
"16",
"/* RunInit */",
")",
"{",
"executeHooks",
"(",
"currentView",
"[",
"DIRECTIVES",
"]",
",",
"tView",
".",
"initHooks",
",",
"tView",
".",
"checkHooks",
",",
"creationMode",
")",
";",
"currentView",
"[",
"FLAGS",
"]",
"&=",
"~",
"16",
"/* RunInit */",
";",
"}",
"}"
] |
Calls onInit and doCheck calls if they haven't already been called.
@param currentView The current view
|
[
"Calls",
"onInit",
"and",
"doCheck",
"calls",
"if",
"they",
"haven",
"t",
"already",
"been",
"called",
"."
] |
cb94eb9af46de79c69d61b4fd37a800009fb70d3
|
https://github.com/CuppaLabs/angular2-multiselect-dropdown/blob/cb94eb9af46de79c69d61b4fd37a800009fb70d3/docs/vendor.js#L19945-L19950
|
11,699
|
CuppaLabs/angular2-multiselect-dropdown
|
docs/vendor.js
|
executeHooks
|
function executeHooks(data, allHooks, checkHooks, creationMode) {
var hooksToCall = creationMode ? allHooks : checkHooks;
if (hooksToCall) {
callHooks(data, hooksToCall);
}
}
|
javascript
|
function executeHooks(data, allHooks, checkHooks, creationMode) {
var hooksToCall = creationMode ? allHooks : checkHooks;
if (hooksToCall) {
callHooks(data, hooksToCall);
}
}
|
[
"function",
"executeHooks",
"(",
"data",
",",
"allHooks",
",",
"checkHooks",
",",
"creationMode",
")",
"{",
"var",
"hooksToCall",
"=",
"creationMode",
"?",
"allHooks",
":",
"checkHooks",
";",
"if",
"(",
"hooksToCall",
")",
"{",
"callHooks",
"(",
"data",
",",
"hooksToCall",
")",
";",
"}",
"}"
] |
Iterates over afterViewInit and afterViewChecked functions and calls them.
@param currentView The current view
|
[
"Iterates",
"over",
"afterViewInit",
"and",
"afterViewChecked",
"functions",
"and",
"calls",
"them",
"."
] |
cb94eb9af46de79c69d61b4fd37a800009fb70d3
|
https://github.com/CuppaLabs/angular2-multiselect-dropdown/blob/cb94eb9af46de79c69d61b4fd37a800009fb70d3/docs/vendor.js#L19956-L19961
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.